-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtooltips.cpp
More file actions
1727 lines (1520 loc) · 40.1 KB
/
Copy pathtooltips.cpp
File metadata and controls
1727 lines (1520 loc) · 40.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define ISOLATION_AWARE_ENABLED 1
#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <commctrl.h>
#include <shlwapi.h>
#include "tooltips.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <Uxtheme.h>
#include <vsstyle.h>
//defines
#define LITEHTML_TOOLTIPS_WINDOW L"LITEHTML_TOOLTIPS_WINDOW"
#define TIMER_HIDE_TIP 2
litehtml::tooltips::tooltips(HINSTANCE hInst, litehtml::context* html_context, int radius)
{
registerClass(hInst);
m_hWnd = NULL;
m_html_context = html_context;
m_max_width = 300;
m_show_time = 500;
m_hide_time = 0;
m_callback = NULL;
m_style = tips_style_square;
m_over_tool = 0;
m_disabled = false;
m_alpha = 255;
m_cr = NULL;
m_surface = NULL;
m_last_shown_tool = 0;
m_cached_tool = 0;
m_mouse_hover_on = false;
m_radius = radius;
m_hide_time_int = 2000;
m_hide_timer_active = false;
m_max_height = 0;
init_def_font();
}
litehtml::tooltips::~tooltips(void)
{
DestroyWindow(m_hWnd);
RemoveWindowSubclass(m_hWndParent, SubclassProc, (DWORD_PTR) this);
if(m_surface) cairo_surface_destroy(m_surface);
if(m_cr) cairo_destroy(m_cr);
}
void litehtml::tooltips::make_url( LPCWSTR url, LPCWSTR basepath, std::wstring& out )
{
out.clear();
if(basepath)
{
out = basepath;
}
out += url;
}
CTxDIB* litehtml::tooltips::get_image( LPCWSTR url, bool redraw_on_ready )
{
if(m_callback)
{
return m_callback->ttcb_get_image(m_show_tool, url, redraw_on_ready);
}
return NULL;
}
void litehtml::tooltips::set_caption( const wchar_t* caption )
{
}
void litehtml::tooltips::set_base_url( const wchar_t* base_url )
{
}
void litehtml::tooltips::link( litehtml::document* doc, litehtml::element::ptr el )
{
}
void litehtml::tooltips::import_css( std::wstring& text, const std::wstring& url, std::wstring& baseurl )
{
}
void litehtml::tooltips::on_anchor_click( const wchar_t* url, litehtml::element::ptr el )
{
if(url)
{
m_anchor = url;
}
}
void litehtml::tooltips::set_cursor( const wchar_t* cursor )
{
m_cursor = cursor ? cursor : L"";
}
LRESULT CALLBACK litehtml::tooltips::WndProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam )
{
tooltips* pThis = NULL;
if(IsWindow(hWnd))
{
pThis = (tooltips*)GetProp(hWnd, TEXT("tooltips_this"));
if(pThis && pThis->m_hWnd != hWnd)
{
pThis = NULL;
}
}
if(pThis || uMessage == WM_CREATE)
{
switch (uMessage)
{
case WM_CREATE:
{
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
pThis = (tooltips*)(lpcs->lpCreateParams);
SetProp(hWnd, TEXT("tooltips_this"), (HANDLE) pThis);
pThis->m_hWnd = hWnd;
}
break;
case WM_DESTROY:
{
LRESULT ret = pThis->OnMessage(hWnd, uMessage, wParam, lParam);
RemoveProp(hWnd, TEXT("tooltips_this"));
pThis->m_hWnd = NULL;
return ret;
}
break;
}
return pThis->OnMessage(hWnd, uMessage, wParam, lParam);
}
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
void litehtml::tooltips::registerClass( HINSTANCE hInstance )
{
m_hInst = hInstance;
WNDCLASSEX wc;
if(!GetClassInfoEx(hInstance, LITEHTML_TOOLTIPS_WINDOW, &wc))
{
ZeroMemory(&wc, sizeof(wc));
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = (WNDPROC) tooltips::WndProc;
wc.hInstance = hInstance;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = LITEHTML_TOOLTIPS_WINDOW;
RegisterClassEx(&wc);
}
}
LRESULT litehtml::tooltips::OnMessage( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam )
{
switch(uMessage)
{
case WM_MOUSEACTIVATE:
return MA_NOACTIVATE;
case WM_TIMER:
switch(wParam)
{
case TIMER_HIDE_TIP:
stop_timers();
hide();
break;
}
break;
case WM_UPDATE_TIP:
update((unsigned int) wParam, lParam ? true : false);
return 0;
case WM_REDRAW_TIP:
if((unsigned int) wParam == m_show_tool && IsWindowVisible(m_hWnd))
{
draw_window(NULL);
}
return 0;
case WM_MOUSELEAVE:
if(is_tool_interactive(m_show_tool))
{
TRACKMOUSEEVENT tm = {0};
tm.cbSize = sizeof(TRACKMOUSEEVENT);
tm.dwFlags = TME_QUERY;
TrackMouseEvent(&tm);
if(tm.dwFlags & TME_LEAVE)
{
tm.dwFlags = TME_LEAVE | TME_CANCEL;
tm.hwndTrack = m_hWnd;
TrackMouseEvent(&tm);
}
if(m_html)
{
litehtml::position::vector redraw_boxes;
if(m_html->on_mouse_leave(redraw_boxes))
{
draw_window(TRUE);
}
}
hide_current_tool();
}
break;
case WM_SETCURSOR:
update_cursor();
break;
case WM_MOUSEMOVE:
if(!is_tool_interactive(m_show_tool))
{
hide();
} else if(m_html)
{
if(m_hide_timer_active)
{
KillTimer(m_hWnd, TIMER_HIDE_TIP);
m_hide_timer_active = false;
}
TRACKMOUSEEVENT tm = {0};
tm.cbSize = sizeof(TRACKMOUSEEVENT);
tm.dwFlags = TME_QUERY;
TrackMouseEvent(&tm);
if(!(tm.dwFlags & TME_LEAVE))
{
tm.dwFlags = TME_LEAVE;
tm.hwndTrack = m_hWnd;
TrackMouseEvent(&tm);
}
if(m_html)
{
litehtml::position::vector redraw_boxes;
if(m_html->on_mouse_over( GET_X_LPARAM(lParam) - m_layout.content_x,
GET_Y_LPARAM(lParam) - m_layout.content_y + m_top,
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
redraw_boxes) )
{
draw_window(TRUE);
}
}
update_cursor();
}
break;
case WM_LBUTTONDOWN:
if(is_tool_interactive(m_show_tool))
{
if(m_html)
{
litehtml::position::vector redraw_boxes;
if(m_html->on_lbutton_down( GET_X_LPARAM(lParam) - m_layout.content_x,
GET_Y_LPARAM(lParam) - m_layout.content_y + m_top,
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
redraw_boxes) )
{
draw_window(TRUE);
}
}
update_cursor();
}
break;
case WM_LBUTTONUP:
if(is_tool_interactive(m_show_tool))
{
if(m_html)
{
m_anchor = L"";
litehtml::position::vector redraw_boxes;
if(m_html->on_lbutton_up( GET_X_LPARAM(lParam) - m_layout.content_x,
GET_Y_LPARAM(lParam) - m_layout.content_y + m_top,
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
redraw_boxes) )
{
draw_window(TRUE);
}
}
update_cursor();
if(!m_anchor.empty())
{
if(m_callback)
{
if(m_callback->ttcb_on_anchor_click(m_show_tool, m_anchor))
{
hide();
}
}
}
}
break;
case WM_MOUSEWHEEL:
if(can_scroll())
{
if(scroll(-GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA * m_def_font_size * 5))
{
draw_window(TRUE);
}
return 0;
}
break;
}
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
void litehtml::tooltips::add_tool( unsigned int id, const wchar_t* text, HWND ctl, LPCRECT rc_tool, UINT options )
{
m_tools[id] = tool(text, ctl, rc_tool, options);
}
void litehtml::tooltips::clear()
{
m_tools.clear();
}
void litehtml::tooltips::get_client_rect( litehtml::position& client )
{
client.x = m_layout.content_x;
client.y = m_layout.content_y;
client.width = m_layout.content_width;
client.height = m_layout.content_height;
}
void litehtml::tooltips::create( HWND parent )
{
m_hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE /*WS_EX_TRANSPARENT*/, LITEHTML_TOOLTIPS_WINDOW, L"", WS_POPUP, 0, 0, 0, 0, NULL, NULL, m_hInst, (LPVOID) this);
if(parent)
{
m_hWndParent = parent;
SetWindowSubclass(parent, SubclassProc, (UINT_PTR) this, (DWORD_PTR) this);
}
}
void litehtml::tooltips::show( unsigned int id, int top, bool is_update, bool re_render )
{
tool::map::iterator ti = m_tools.find(id);
if(ti != m_tools.end())
{
if(!is_update && m_cached_tool != id)
{
clear_images();
}
m_show_tool = id;
m_last_shown_tool = id;
if(!re_render && m_html || !m_html)
{
if(m_html)
{
m_html = NULL;
}
if(ti->second.options & tool_opt_ask_text)
{
if(m_callback)
{
std::wstring text;
std::wstring css_text;
m_callback->ttcb_get_text(ti->first, text, css_text);
litehtml::css user_style;
if(!css_text.empty())
{
user_style.parse_stylesheet(css_text.c_str(), L"{tip-style}", 0, litehtml::media_query_list::ptr());
}
if(!text.empty())
{
m_html = litehtml::document::createFromString(text.c_str(), this, m_html_context, &user_style);
}
} else
{
return;
}
} else
{
if(!ti->second.text.empty())
{
m_html = litehtml::document::createFromString(ti->second.text.c_str(), this, m_html_context);
}
}
}
if(!m_html)
{
return;
}
m_cached_tool = id;
int w = m_html->render(m_max_width, litehtml::render_no_fixed);
if(w < m_max_width)
{
m_html->render(w, litehtml::render_no_fixed);
}
calc_layout(&ti->second, &m_layout);
create_dib(m_layout.width, m_layout.height);
m_html->render(w, litehtml::render_fixed_only);
m_top = top;
if(m_top)
{
scroll(0);
}
draw_window();
ShowWindow(m_hWnd, SW_SHOWNA);
if(ti->second.options)
if(m_hide_time)
{
SetTimer(m_hWnd, TIMER_HIDE_TIP, m_hide_time, NULL);
}
}
}
void litehtml::tooltips::hide()
{
if(m_show_tool)
{
m_show_tool = 0;
ShowWindow(m_hWnd, SW_HIDE);
}
stop_timers();
}
LRESULT CALLBACK litehtml::tooltips::SubclassProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData )
{
tooltips* pThis = (tooltips*) dwRefData;
switch(uMsg)
{
case WM_MOUSEWHEEL:
if(pThis->can_scroll())
{
if(pThis->scroll(-GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA * pThis->m_def_font_size * 5))
{
pThis->draw_window(TRUE);
}
return 0;
}
break;
case WM_MOUSELEAVE:
pThis->m_last_shown_tool = 0;
pThis->hide_current_tool();
pThis->start_hover_tracking(false);
break;
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDOWN:
case WM_MBUTTONDBLCLK:
case WM_NCLBUTTONDOWN:
case WM_NCLBUTTONDBLCLK:
case WM_NCRBUTTONDOWN:
case WM_NCRBUTTONDBLCLK:
case WM_NCMBUTTONDOWN:
case WM_NCMBUTTONDBLCLK:
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KILLFOCUS:
case WM_CLOSE:
pThis->hide();
break;
case WM_MOUSEHOVER:
pThis->on_mouse_hover_tool(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
break;
case WM_MOUSEMOVE:
pThis->on_mouse_over_tool(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
break;
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
void litehtml::tooltips::draw_background( litehtml::uint_ptr hdc, const litehtml::background_paint& bg )
{
if(bg.is_root)
{
cairo_t* cr = (cairo_t*) hdc;
cairo_save(cr);
cairo_reset_clip(cr);
m_bg_cache.create_tip_path(cr, 0);
cairo_clip(cr);
litehtml::background_paint new_bg(bg);
new_bg.clip_box.x = 0;
new_bg.clip_box.y = 0;
new_bg.clip_box.width = m_dib.width();
new_bg.clip_box.height = m_dib.height();
new_bg.border_box = new_bg.clip_box;
new_bg.border_radius = litehtml::css_border_radius();
cairo_container::draw_background(hdc, new_bg);
cairo_restore(cr);
} else
{
cairo_container::draw_background(hdc, bg);
}
}
int litehtml::tooltips::tip_width()
{
int width = m_html->width();
switch(m_style)
{
case tips_style_square:
width += 8;
break;
case tips_style_rounded:
width += 16;
break;
case tips_style_baloon:
width += 16;
break;
}
return width;
}
int litehtml::tooltips::tip_height()
{
int height = m_html->height();
switch(m_style)
{
case tips_style_square:
height += 4;
break;
case tips_style_rounded:
height += 24;
break;
case tips_style_baloon:
height += 24;
break;
}
return height;
}
void litehtml::tooltips::content_point( LPPOINT pt )
{
pt->x = 0;
pt->y = 0;
switch(m_style)
{
case tips_style_square:
pt->x = 4;
pt->y = 2;
break;
case tips_style_rounded:
pt->x = 12;
pt->y = 12;
break;
case tips_style_baloon:
pt->x = 12;
pt->y = 12;
break;
}
}
void litehtml::tooltips::rounded_rect( cairo_t* cr, int x, int y, int width, int height, int radius, int line_width )
{
double xx = x;
double yy = y;
double w = width;
double h = height;
double r = radius;
if(line_width != 0)
{
xx += line_width / 2.0;
yy += line_width / 2.0;
w -= line_width;
h -= line_width;
}
cairo_new_path(cr);
cairo_move_to (cr, xx + r, yy);
cairo_arc (cr, xx + w - r, yy + r, r, M_PI + M_PI / 2, M_PI * 2 );
cairo_arc (cr, xx + w - r, yy + h - r, r, 0, M_PI / 2 );
cairo_arc (cr, xx + r, yy + h - r, r, M_PI/2, M_PI );
cairo_arc (cr, xx + r, yy + r, r, M_PI, 270 * M_PI / 180);
cairo_close_path(cr);
}
void litehtml::tooltips::stop_timers()
{
KillTimer(m_hWnd, TIMER_HIDE_TIP);
m_hide_timer_active = false;
}
unsigned int litehtml::tooltips::find_tool( int x, int y )
{
POINT pt = {x, y};
for(tool::map::iterator t = m_tools.begin(); t != m_tools.end(); t++)
{
if(PtInRect(&t->second.rc_tool, pt))
{
return t->first;
}
}
return 0;
}
void litehtml::tooltips::calc_layout( tool* t, tip_layout* layout )
{
layout->style = m_style;
layout->width = m_html->width();
layout->height = m_html->height();
layout->content_width = m_html->width();
layout->content_height = m_html->height();
layout->radius = m_radius;
switch(m_style)
{
case tips_style_square:
layout->width += 8;
layout->height += 4;
layout->content_x = 4;
layout->content_y = 2;
break;
case tips_style_rounded:
if(layout->radius > 4)
{
layout->width += layout->radius * 2;
layout->height += layout->radius * 2;
layout->content_x = layout->radius;
layout->content_y = layout->radius;
} else
{
layout->width += 8;
layout->height += max(2, layout->radius) * 2;
layout->content_x = 4;
layout->content_y = max(2, layout->radius);
}
break;
case tips_style_baloon:
layout->width += 24;
if(layout->width < 32) layout->width = 32;
layout->height += 24;
if(layout->height < 32) layout->height = 32;
break;
}
RECT rcDesktop;
GetDesktopRect(&rcDesktop, m_hWndParent);
int max_height = (rcDesktop.bottom - rcDesktop.top);
if(m_max_height >= 300)
{
max_height = min(rcDesktop.bottom - rcDesktop.top, m_max_height);
}
if(layout->height > max_height)
{
layout->width += 7;
}
RECT rc_tool = t->rc_tool;
MapWindowPoints(m_hWndParent, NULL, (LPPOINT) &rc_tool, 2);
calc_position(t->options & tool_opt_align_mask, &rc_tool, layout);
if(layout->y + layout->height > rcDesktop.bottom)
{
int margin = layout->height - m_html->height();
layout->height = rcDesktop.bottom - layout->y;
layout->content_height = layout->height - margin;
}
switch(layout->align)
{
case tool_opt_align_top:
layout->anchor_x = rc_tool.left + (rc_tool.right - rc_tool.left) / 2;
layout->anchor_y = rc_tool.top;
if(layout->y + layout->height > rc_tool.top)
{
layout->content_height -= (layout->y + layout->height) - rc_tool.top;
layout->height -= layout->y + layout->height - rc_tool.top;
layout->y = rc_tool.top - layout->height;
}
break;
case tool_opt_align_bottom:
layout->anchor_x = rc_tool.left + (rc_tool.right - rc_tool.left) / 2;
layout->anchor_y = rc_tool.bottom;
if(rc_tool.bottom > layout->y)
{
layout->content_height -= rc_tool.bottom - layout->y;
layout->height -= rc_tool.bottom - layout->y;
layout->y = rc_tool.bottom;
}
break;
case tool_opt_align_left:
layout->anchor_y = rc_tool.top + (rc_tool.bottom - rc_tool.top) / 2;
layout->anchor_x = rc_tool.left;
break;
case tool_opt_align_right:
layout->anchor_y = rc_tool.top + (rc_tool.bottom - rc_tool.top) / 2;
layout->anchor_x = rc_tool.right;
break;
}
if(m_style == tips_style_baloon)
{
switch(layout->align)
{
case tool_opt_align_top:
layout->content_x = 8;
layout->content_y = 8;
if(layout->width - 8 >= 32)
{
layout->width -= 8;
} else
{
layout->width = 32;
}
break;
case tool_opt_align_left:
layout->content_x = 8;
layout->content_y = 8;
if(layout->height - 8 >= 32)
{
layout->height -= 8;
} else
{
layout->height = 32;
}
break;
case tool_opt_align_bottom:
layout->content_x = 8;
layout->content_y = 16;
if(layout->width - 8 >= 32)
{
layout->width -= 8;
} else
{
layout->width = 32;
}
break;
case tool_opt_align_right:
layout->content_x = 16;
layout->content_y = 8;
if(layout->height - 8 >= 32)
{
layout->height -= 8;
} else
{
layout->height = 32;
}
break;
}
}
// add 5px shadow
layout->width += 5;
layout->height += 5;
}
void litehtml::tooltips::GetDesktopRect(RECT* rcDsk, HWND hWnd)
{
int nMonitors = GetSystemMetrics(80);
if(!nMonitors) nMonitors = 1;
if(nMonitors == 1)
{
oneMonitor:
HWND dskWnd = GetDesktopWindow();
GetClientRect(dskWnd, rcDsk);
} else
{
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
if(!hMonitor)
{
goto oneMonitor;
}
MONITORINFO mInf;
mInf.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(hMonitor, &mInf);
*rcDsk = mInf.rcMonitor;
}
}
void litehtml::tooltips::calc_position( UINT align, LPRECT rc_tool, tip_layout* layout, bool second )
{
RECT rcDesktop;
GetDesktopRect(&rcDesktop, m_hWndParent);
int shift = 0;
if(m_style != tips_style_baloon)
{
shift = 8;
}
switch(align)
{
case tool_opt_align_top:
layout->align = tool_opt_align_top;
layout->x = rc_tool->left + (rc_tool->right - rc_tool->left) / 2 - layout->width /2;
layout->y = rc_tool->top - layout->height - shift;
if(layout->x + layout->width > rcDesktop.right)
{
layout->x = rcDesktop.right - layout->width;
}
if(layout->x < rcDesktop.left)
{
layout->x = rcDesktop.left;
}
if(layout->y < rcDesktop.top)
{
if(!second)
{
if(rcDesktop.bottom - rc_tool->bottom >= layout->height + shift)
{
calc_position(tool_opt_align_bottom, rc_tool, layout, true);
} else
{
if(rc_tool->left - rcDesktop.left > rcDesktop.right - rc_tool->right)
{
calc_position(tool_opt_align_left, rc_tool, layout, true);
} else
{
calc_position(tool_opt_align_right, rc_tool, layout, true);
}
}
} else
{
layout->y = rcDesktop.top;
}
}
break;
case tool_opt_align_bottom:
layout->align = tool_opt_align_bottom;
layout->x = rc_tool->left + (rc_tool->right - rc_tool->left) / 2 - layout->width /2;
layout->y = rc_tool->bottom + shift;
if(layout->x + layout->width > rcDesktop.right)
{
layout->x = rcDesktop.right - layout->width;
}
if(layout->x < rcDesktop.left)
{
layout->x = rcDesktop.left;
}
if(layout->y + layout->height > rcDesktop.bottom)
{
if(!second)
{
if(rc_tool->top - rcDesktop.top >= layout->height + shift)
{
calc_position(tool_opt_align_top, rc_tool, layout, true);
} else
{
if(rc_tool->left - rcDesktop.left > rcDesktop.right - rc_tool->right)
{
calc_position(tool_opt_align_left, rc_tool, layout, true);
} else
{
calc_position(tool_opt_align_right, rc_tool, layout, true);
}
}
} else
{
layout->y = rcDesktop.top;
}
}
break;
case tool_opt_align_left:
layout->align = tool_opt_align_left;
layout->y = rc_tool->top + (rc_tool->bottom - rc_tool->top) / 2 - layout->height /2;
layout->x = rc_tool->left - layout->width - shift;
if(layout->y + layout->height > rcDesktop.bottom)
{
layout->y = rcDesktop.bottom - layout->height;
}
if(layout->y < rcDesktop.top)
{
layout->y = rcDesktop.top;
}
if(layout->x < rcDesktop.left)
{
if(!second)
{
if(rcDesktop.right - rc_tool->right >= layout->width + shift)
{
calc_position(tool_opt_align_right, rc_tool, layout, true);
} else
{
if(rc_tool->top - rcDesktop.top > rcDesktop.bottom - rc_tool->bottom)
{
calc_position(tool_opt_align_top, rc_tool, layout, true);
} else
{
calc_position(tool_opt_align_bottom, rc_tool, layout, true);
}
}
} else
{
layout->x = rcDesktop.left;
}
}
break;
case tool_opt_align_right:
layout->align = tool_opt_align_right;
layout->y = rc_tool->top + (rc_tool->bottom - rc_tool->top) / 2 - layout->height /2;
layout->x = rc_tool->right + shift;
if(layout->y + layout->height > rcDesktop.bottom)
{
layout->y = rcDesktop.bottom - layout->height;
}
if(layout->y < rcDesktop.top)
{
layout->y = rcDesktop.top;
}
if(layout->x + layout->width > rcDesktop.right)
{
if(!second)
{
if(rc_tool->left - rcDesktop.left >= layout->width + shift)
{
calc_position(tool_opt_align_left, rc_tool, layout, true);
} else
{
if(rc_tool->top - rcDesktop.top > rcDesktop.bottom - rc_tool->bottom)
{
calc_position(tool_opt_align_top, rc_tool, layout, true);
} else
{
calc_position(tool_opt_align_bottom, rc_tool, layout, true);
}
}
} else
{
layout->x = rcDesktop.left;
}
}
break;
}
}
void litehtml::tooltips::baloon( cairo_t* cr, int x, int y, int width, int height, int ax, int ay, UINT align, int radius, int line_width )
{
double xx = x;
double yy = y;
double w = width;
double h = height;
double r = radius;
double axx = ax;
double ayy = ay;
if(line_width != 0)
{
xx += line_width / 2.0;
yy += line_width / 2.0;
w -= line_width;
h -= line_width;
}
cairo_new_path(cr);
switch(align)
{
case tool_opt_align_top:
h -= 8;
if(axx - 8 < xx + 8) axx = xx + 16;
if(axx + 8 > xx + w - 8) axx = xx + w - 16;
cairo_move_to (cr, xx + r, yy);
cairo_arc (cr, xx + w - r, yy + r, r, M_PI + M_PI / 2, M_PI * 2 );
cairo_arc (cr, xx + w - r, yy + h - r, r, 0, M_PI / 2 );
cairo_line_to (cr, axx + 8.0, yy + h);
cairo_line_to (cr, axx, ayy);
cairo_line_to (cr, axx - 8.0, yy + h);
cairo_arc (cr, xx + r, yy + h - r, r, M_PI/2, M_PI );
cairo_arc (cr, xx + r, yy + r, r, M_PI, 270 * M_PI / 180);
break;
case tool_opt_align_bottom:
h -= 8;
yy += 8;
if(axx - 8 < xx + 8) axx = xx + 16;
if(axx + 8 > xx + w - 8) axx = xx + w - 16;
cairo_move_to (cr, xx + r, yy);
cairo_line_to (cr, axx - 8.0, yy);
cairo_line_to (cr, axx, ayy);
cairo_line_to (cr, axx + 8.0, yy);
cairo_arc (cr, xx + w - r, yy + r, r, M_PI + M_PI / 2, M_PI * 2 );
cairo_arc (cr, xx + w - r, yy + h - r, r, 0, M_PI / 2 );
cairo_arc (cr, xx + r, yy + h - r, r, M_PI/2, M_PI );
cairo_arc (cr, xx + r, yy + r, r, M_PI, 270 * M_PI / 180);
break;
case tool_opt_align_left:
w -= 8;
if(ayy - 8 < yy + 8) ayy = yy + 16;