forked from wine-mirror/wine
/
tooltips.c
2394 lines (1946 loc) · 64.4 KB
/
tooltips.c
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
/*
* Tool tip control
*
* Copyright 1998, 1999 Eric Kohl
* Copyright 2004 Robert Shearman
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* NOTES
*
* This code was audited for completeness against the documented features
* of Comctl32.dll version 6.0 on Sep. 08, 2004, by Robert Shearman.
*
* Unless otherwise noted, we believe this code to be complete, as per
* the specification mentioned above.
* If you discover missing features or bugs please note them below.
*
* TODO:
* - Custom draw support.
* - Animation.
* - Links.
* - Messages:
* o TTM_ADJUSTRECT
* o TTM_GETTITLEA
* o TTM_GETTTILEW
* o TTM_POPUP
* - Styles:
* o TTS_NOANIMATE
* o TTS_NOFADE
* o TTS_CLOSE
*
* Testing:
* - Run tests using Waite Group Windows95 API Bible Volume 2.
* The second cdrom (chapter 3) contains executables activate.exe,
* curtool.exe, deltool.exe, enumtools.exe, getinfo.exe, getiptxt.exe,
* hittest.exe, needtext.exe, newrect.exe, updtext.exe and winfrpt.exe.
*
* Timer logic.
*
* One important point to remember is that tools don't necessarily get
* a WM_MOUSEMOVE once the cursor leaves the tool, an example is when
* a tool sets TTF_IDISHWND (i.e. an entire window is a tool) because
* here WM_MOUSEMOVEs only get sent when the cursor is inside the
* client area. Therefore the only reliable way to know that the
* cursor has left a tool is to keep a timer running and check the
* position every time it expires. This is the role of timer
* ID_TIMERLEAVE.
*
*
* On entering a tool (detected in a relayed WM_MOUSEMOVE) we start
* ID_TIMERSHOW, if this times out and we're still in the tool we show
* the tip. On showing a tip we start both ID_TIMERPOP and
* ID_TIMERLEAVE. On hiding a tooltip we kill ID_TIMERPOP.
* ID_TIMERPOP is restarted on every relayed WM_MOUSEMOVE. If
* ID_TIMERPOP expires the tool is hidden and ID_TIMERPOP is killed.
* ID_TIMERLEAVE remains running - this is important as we need to
* determine when the cursor leaves the tool.
*
* When ID_TIMERLEAVE expires or on a relayed WM_MOUSEMOVE if we're
* still in the tool do nothing (apart from restart ID_TIMERPOP if
* this is a WM_MOUSEMOVE) (ID_TIMERLEAVE remains running). If we've
* left the tool and entered another one then hide the tip and start
* ID_TIMERSHOW with time ReshowTime and kill ID_TIMERLEAVE. If we're
* outside all tools hide the tip and kill ID_TIMERLEAVE. On Relayed
* mouse button messages hide the tip but leave ID_TIMERLEAVE running,
* this again will let us keep track of when the cursor leaves the
* tool.
*
*
* infoPtr->nTool is the tool the mouse was on on the last relayed MM
* or timer expiry or -1 if the mouse was not on a tool.
*
* infoPtr->nCurrentTool is the tool for which the tip is currently
* displaying text for or -1 if the tip is not shown. Actually this
* will only ever be infoPtr-nTool or -1, so it could be changed to a
* BOOL.
*
*/
#include <stdarg.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "wine/unicode.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "commctrl.h"
#include "comctl32.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(tooltips);
static HICON hTooltipIcons[TTI_ERROR+1];
typedef struct
{
UINT uFlags;
UINT uInternalFlags;
HWND hwnd;
BOOL bNotifyUnicode;
UINT_PTR uId;
RECT rect;
HINSTANCE hinst;
LPWSTR lpszText;
LPARAM lParam;
} TTTOOL_INFO;
typedef struct
{
HWND hwndSelf;
WCHAR szTipText[INFOTIPSIZE];
BOOL bActive;
BOOL bTrackActive;
UINT uNumTools;
COLORREF clrBk;
COLORREF clrText;
HFONT hFont;
HFONT hTitleFont;
INT xTrackPos;
INT yTrackPos;
INT nMaxTipWidth;
INT nTool; /* tool that mouse was on on last relayed mouse move */
INT nCurrentTool;
INT nTrackTool;
INT nReshowTime;
INT nAutoPopTime;
INT nInitialTime;
RECT rcMargin;
BOOL bToolBelow;
LPWSTR pszTitle;
HICON hTitleIcon;
TTTOOL_INFO *tools;
} TOOLTIPS_INFO;
#define ID_TIMERSHOW 1 /* show delay timer */
#define ID_TIMERPOP 2 /* auto pop timer */
#define ID_TIMERLEAVE 3 /* tool leave timer */
#define TOOLTIPS_GetInfoPtr(hWindow) ((TOOLTIPS_INFO *)GetWindowLongPtrW (hWindow, 0))
/* offsets from window edge to start of text */
#define NORMAL_TEXT_MARGIN 2
#define BALLOON_TEXT_MARGIN (NORMAL_TEXT_MARGIN+8)
/* value used for CreateRoundRectRgn that specifies how much
* each corner is curved */
#define BALLOON_ROUNDEDNESS 20
#define BALLOON_STEMHEIGHT 13
#define BALLOON_STEMWIDTH 10
#define BALLOON_STEMINDENT 20
#define BALLOON_ICON_TITLE_SPACING 8 /* horizontal spacing between icon and title */
#define BALLOON_TITLE_TEXT_SPACING 8 /* vertical spacing between icon/title and main text */
#define ICON_HEIGHT 16
#define ICON_WIDTH 16
#define MAX_TEXT_SIZE_A 80 /* maximum retrieving text size by ANSI message */
static LRESULT CALLBACK
TOOLTIPS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uId, DWORD_PTR dwRef);
static inline BOOL TOOLTIPS_IsCallbackString(LPCWSTR str, BOOL isW)
{
if (isW)
return str == LPSTR_TEXTCALLBACKW;
else
return (LPCSTR)str == LPSTR_TEXTCALLBACKA;
}
static inline UINT_PTR
TOOLTIPS_GetTitleIconIndex(HICON hIcon)
{
UINT i;
for (i = 0; i <= TTI_ERROR; i++)
if (hTooltipIcons[i] == hIcon)
return i;
return (UINT_PTR)hIcon;
}
static void
TOOLTIPS_InitSystemSettings (TOOLTIPS_INFO *infoPtr)
{
NONCLIENTMETRICSW nclm;
infoPtr->clrBk = comctl32_color.clrInfoBk;
infoPtr->clrText = comctl32_color.clrInfoText;
DeleteObject (infoPtr->hFont);
nclm.cbSize = sizeof(nclm);
SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
infoPtr->hFont = CreateFontIndirectW (&nclm.lfStatusFont);
DeleteObject (infoPtr->hTitleFont);
nclm.lfStatusFont.lfWeight = FW_BOLD;
infoPtr->hTitleFont = CreateFontIndirectW (&nclm.lfStatusFont);
}
/* Custom draw routines */
static void
TOOLTIPS_customdraw_fill(const TOOLTIPS_INFO *infoPtr, NMTTCUSTOMDRAW *lpnmttcd,
HDC hdc, const RECT *rcBounds, UINT uFlags)
{
ZeroMemory(lpnmttcd, sizeof(NMTTCUSTOMDRAW));
lpnmttcd->uDrawFlags = uFlags;
lpnmttcd->nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
lpnmttcd->nmcd.hdr.code = NM_CUSTOMDRAW;
if (infoPtr->nCurrentTool != -1) {
TTTOOL_INFO *toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
lpnmttcd->nmcd.hdr.idFrom = toolPtr->uId;
}
lpnmttcd->nmcd.hdc = hdc;
lpnmttcd->nmcd.rc = *rcBounds;
/* FIXME - dwItemSpec, uItemState, lItemlParam */
}
static inline DWORD
TOOLTIPS_notify_customdraw (DWORD dwDrawStage, NMTTCUSTOMDRAW *lpnmttcd)
{
LRESULT result;
lpnmttcd->nmcd.dwDrawStage = dwDrawStage;
TRACE("Notifying stage %d, flags %x, id %x\n", lpnmttcd->nmcd.dwDrawStage,
lpnmttcd->uDrawFlags, lpnmttcd->nmcd.hdr.code);
result = SendMessageW(GetParent(lpnmttcd->nmcd.hdr.hwndFrom), WM_NOTIFY,
0, (LPARAM)lpnmttcd);
TRACE("Notify result %x\n", (unsigned int)result);
return result;
}
static void
TOOLTIPS_Refresh (const TOOLTIPS_INFO *infoPtr, HDC hdc)
{
RECT rc;
INT oldBkMode;
HFONT hOldFont;
HBRUSH hBrush;
UINT uFlags = DT_EXTERNALLEADING;
HRGN hRgn = NULL;
DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
NMTTCUSTOMDRAW nmttcd;
DWORD cdmode;
if (infoPtr->nMaxTipWidth > -1)
uFlags |= DT_WORDBREAK;
if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)
uFlags |= DT_NOPREFIX;
GetClientRect (infoPtr->hwndSelf, &rc);
hBrush = CreateSolidBrush(infoPtr->clrBk);
oldBkMode = SetBkMode (hdc, TRANSPARENT);
SetTextColor (hdc, infoPtr->clrText);
hOldFont = SelectObject (hdc, infoPtr->hFont);
/* Custom draw - Call PrePaint once initial properties set up */
/* Note: Contrary to MSDN, CDRF_SKIPDEFAULT still draws a tooltip */
TOOLTIPS_customdraw_fill(infoPtr, &nmttcd, hdc, &rc, uFlags);
cdmode = TOOLTIPS_notify_customdraw(CDDS_PREPAINT, &nmttcd);
uFlags = nmttcd.uDrawFlags;
if (dwStyle & TTS_BALLOON)
{
/* create a region to store result into */
hRgn = CreateRectRgn(0, 0, 0, 0);
GetWindowRgn(infoPtr->hwndSelf, hRgn);
/* fill the background */
FillRgn(hdc, hRgn, hBrush);
DeleteObject(hBrush);
hBrush = NULL;
}
else
{
/* fill the background */
FillRect(hdc, &rc, hBrush);
DeleteObject(hBrush);
hBrush = NULL;
}
if ((dwStyle & TTS_BALLOON) || infoPtr->pszTitle)
{
/* calculate text rectangle */
rc.left += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.left);
rc.top += (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.top);
rc.right -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.right);
rc.bottom -= (BALLOON_TEXT_MARGIN + infoPtr->rcMargin.bottom);
if(infoPtr->bToolBelow) rc.top += BALLOON_STEMHEIGHT;
if (infoPtr->pszTitle)
{
RECT rcTitle = {rc.left, rc.top, rc.right, rc.bottom};
int height;
BOOL icon_present;
HFONT prevFont;
/* draw icon */
icon_present = infoPtr->hTitleIcon &&
DrawIconEx(hdc, rc.left, rc.top, infoPtr->hTitleIcon,
ICON_WIDTH, ICON_HEIGHT, 0, NULL, DI_NORMAL);
if (icon_present)
rcTitle.left += ICON_WIDTH + BALLOON_ICON_TITLE_SPACING;
rcTitle.bottom = rc.top + ICON_HEIGHT;
/* draw title text */
prevFont = SelectObject (hdc, infoPtr->hTitleFont);
height = DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
SelectObject (hdc, prevFont);
rc.top += height + BALLOON_TITLE_TEXT_SPACING;
}
}
else
{
/* calculate text rectangle */
rc.left += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.left);
rc.top += (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.top);
rc.right -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.right);
rc.bottom -= (NORMAL_TEXT_MARGIN + infoPtr->rcMargin.bottom);
}
/* draw text */
DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
/* Custom draw - Call PostPaint after drawing */
if (cdmode & CDRF_NOTIFYPOSTPAINT) {
TOOLTIPS_notify_customdraw(CDDS_POSTPAINT, &nmttcd);
}
/* be polite and reset the things we changed in the dc */
SelectObject (hdc, hOldFont);
SetBkMode (hdc, oldBkMode);
if (dwStyle & TTS_BALLOON)
{
/* frame region because default window proc doesn't do it */
INT width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
INT height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
hBrush = GetSysColorBrush(COLOR_WINDOWFRAME);
FrameRgn(hdc, hRgn, hBrush, width, height);
}
if (hRgn)
DeleteObject(hRgn);
}
static void TOOLTIPS_GetDispInfoA(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
{
NMTTDISPINFOA ttnmdi;
/* fill NMHDR struct */
ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOA));
ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
ttnmdi.hdr.idFrom = toolPtr->uId;
ttnmdi.hdr.code = TTN_GETDISPINFOA; /* == TTN_NEEDTEXTA */
ttnmdi.lpszText = ttnmdi.szText;
ttnmdi.uFlags = toolPtr->uFlags;
ttnmdi.lParam = toolPtr->lParam;
TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
if (IS_INTRESOURCE(ttnmdi.lpszText)) {
LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
buffer, INFOTIPSIZE);
if (ttnmdi.uFlags & TTF_DI_SETITEM) {
toolPtr->hinst = ttnmdi.hinst;
toolPtr->lpszText = (LPWSTR)ttnmdi.lpszText;
}
}
else if (ttnmdi.lpszText == 0) {
buffer[0] = '\0';
}
else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
if (ttnmdi.uFlags & TTF_DI_SETITEM) {
toolPtr->hinst = 0;
toolPtr->lpszText = NULL;
Str_SetPtrW(&toolPtr->lpszText, buffer);
}
}
else {
ERR("recursive text callback!\n");
buffer[0] = '\0';
}
/* no text available - try calling parent instead as per native */
/* FIXME: Unsure if SETITEM should save the value or not */
if (buffer[0] == 0x00) {
SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
if (IS_INTRESOURCE(ttnmdi.lpszText)) {
LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
buffer, INFOTIPSIZE);
} else if (ttnmdi.lpszText &&
ttnmdi.lpszText != LPSTR_TEXTCALLBACKA) {
Str_GetPtrAtoW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
}
}
}
static void TOOLTIPS_GetDispInfoW(const TOOLTIPS_INFO *infoPtr, TTTOOL_INFO *toolPtr, WCHAR *buffer)
{
NMTTDISPINFOW ttnmdi;
/* fill NMHDR struct */
ZeroMemory (&ttnmdi, sizeof(NMTTDISPINFOW));
ttnmdi.hdr.hwndFrom = infoPtr->hwndSelf;
ttnmdi.hdr.idFrom = toolPtr->uId;
ttnmdi.hdr.code = TTN_GETDISPINFOW; /* == TTN_NEEDTEXTW */
ttnmdi.lpszText = ttnmdi.szText;
ttnmdi.uFlags = toolPtr->uFlags;
ttnmdi.lParam = toolPtr->lParam;
TRACE("hdr.idFrom = %lx\n", ttnmdi.hdr.idFrom);
SendMessageW(toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
if (IS_INTRESOURCE(ttnmdi.lpszText)) {
LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
buffer, INFOTIPSIZE);
if (ttnmdi.uFlags & TTF_DI_SETITEM) {
toolPtr->hinst = ttnmdi.hinst;
toolPtr->lpszText = ttnmdi.lpszText;
}
}
else if (ttnmdi.lpszText == 0) {
buffer[0] = '\0';
}
else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
if (ttnmdi.uFlags & TTF_DI_SETITEM) {
toolPtr->hinst = 0;
toolPtr->lpszText = NULL;
Str_SetPtrW(&toolPtr->lpszText, buffer);
}
}
else {
ERR("recursive text callback!\n");
buffer[0] = '\0';
}
/* no text available - try calling parent instead as per native */
/* FIXME: Unsure if SETITEM should save the value or not */
if (buffer[0] == 0x00) {
SendMessageW(GetParent(toolPtr->hwnd), WM_NOTIFY, toolPtr->uId, (LPARAM)&ttnmdi);
if (IS_INTRESOURCE(ttnmdi.lpszText)) {
LoadStringW(ttnmdi.hinst, LOWORD(ttnmdi.lpszText),
buffer, INFOTIPSIZE);
} else if (ttnmdi.lpszText &&
ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) {
Str_GetPtrW(ttnmdi.lpszText, buffer, INFOTIPSIZE);
}
}
}
static void
TOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer)
{
TTTOOL_INFO *toolPtr = &infoPtr->tools[nTool];
if (IS_INTRESOURCE(toolPtr->lpszText)) {
/* load a resource */
TRACE("load res string %p %x\n",
toolPtr->hinst, LOWORD(toolPtr->lpszText));
if (!LoadStringW (toolPtr->hinst, LOWORD(toolPtr->lpszText), buffer, INFOTIPSIZE))
buffer[0] = '\0';
}
else if (toolPtr->lpszText) {
if (toolPtr->lpszText == LPSTR_TEXTCALLBACKW) {
if (toolPtr->bNotifyUnicode)
TOOLTIPS_GetDispInfoW(infoPtr, toolPtr, buffer);
else
TOOLTIPS_GetDispInfoA(infoPtr, toolPtr, buffer);
}
else {
/* the item is a usual (unicode) text */
lstrcpynW (buffer, toolPtr->lpszText, INFOTIPSIZE);
}
}
else {
/* no text available */
buffer[0] = '\0';
}
if (!(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)) {
WCHAR *ptrW;
if ((ptrW = strchrW(buffer, '\t')))
*ptrW = 0;
}
TRACE("%s\n", debugstr_w(buffer));
}
static void
TOOLTIPS_CalcTipSize (const TOOLTIPS_INFO *infoPtr, LPSIZE lpSize)
{
HDC hdc;
HFONT hOldFont;
DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
RECT rc = {0, 0, 0, 0};
SIZE title = {0, 0};
if (infoPtr->nMaxTipWidth > -1) {
rc.right = infoPtr->nMaxTipWidth;
uFlags |= DT_WORDBREAK;
}
if (style & TTS_NOPREFIX)
uFlags |= DT_NOPREFIX;
TRACE("%s\n", debugstr_w(infoPtr->szTipText));
hdc = GetDC (infoPtr->hwndSelf);
if (infoPtr->pszTitle)
{
RECT rcTitle = {0, 0, 0, 0};
TRACE("title %s\n", debugstr_w(infoPtr->pszTitle));
if (infoPtr->hTitleIcon)
{
title.cx = ICON_WIDTH;
title.cy = ICON_HEIGHT;
}
if (title.cx != 0) title.cx += BALLOON_ICON_TITLE_SPACING;
hOldFont = SelectObject (hdc, infoPtr->hTitleFont);
DrawTextW(hdc, infoPtr->pszTitle, -1, &rcTitle, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
SelectObject (hdc, hOldFont);
title.cy = max(title.cy, rcTitle.bottom - rcTitle.top) + BALLOON_TITLE_TEXT_SPACING;
title.cx += (rcTitle.right - rcTitle.left);
}
hOldFont = SelectObject (hdc, infoPtr->hFont);
DrawTextW (hdc, infoPtr->szTipText, -1, &rc, uFlags);
SelectObject (hdc, hOldFont);
ReleaseDC (infoPtr->hwndSelf, hdc);
if ((style & TTS_BALLOON) || infoPtr->pszTitle)
{
lpSize->cx = max(rc.right - rc.left, title.cx) + 2*BALLOON_TEXT_MARGIN +
infoPtr->rcMargin.left + infoPtr->rcMargin.right;
lpSize->cy = title.cy + rc.bottom - rc.top + 2*BALLOON_TEXT_MARGIN +
infoPtr->rcMargin.bottom + infoPtr->rcMargin.top +
BALLOON_STEMHEIGHT;
}
else
{
lpSize->cx = rc.right - rc.left + 2*NORMAL_TEXT_MARGIN +
infoPtr->rcMargin.left + infoPtr->rcMargin.right;
lpSize->cy = rc.bottom - rc.top + 2*NORMAL_TEXT_MARGIN +
infoPtr->rcMargin.bottom + infoPtr->rcMargin.top;
}
}
static void
TOOLTIPS_Show (TOOLTIPS_INFO *infoPtr, BOOL track_activate)
{
TTTOOL_INFO *toolPtr;
HMONITOR monitor;
MONITORINFO mon_info;
RECT rect;
SIZE size;
NMHDR hdr;
int ptfx = 0;
DWORD style = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
INT nTool;
if (track_activate)
{
if (infoPtr->nTrackTool == -1)
{
TRACE("invalid tracking tool (-1)!\n");
return;
}
nTool = infoPtr->nTrackTool;
}
else
{
if (infoPtr->nTool == -1)
{
TRACE("invalid tool (-1)!\n");
return;
}
nTool = infoPtr->nTool;
}
TRACE("Show tooltip pre %d! (%p)\n", nTool, infoPtr->hwndSelf);
TOOLTIPS_GetTipText (infoPtr, nTool, infoPtr->szTipText);
if (infoPtr->szTipText[0] == '\0')
return;
toolPtr = &infoPtr->tools[nTool];
if (!track_activate)
infoPtr->nCurrentTool = infoPtr->nTool;
TRACE("Show tooltip %d!\n", nTool);
hdr.hwndFrom = infoPtr->hwndSelf;
hdr.idFrom = toolPtr->uId;
hdr.code = TTN_SHOW;
SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
TRACE("%s\n", debugstr_w(infoPtr->szTipText));
TOOLTIPS_CalcTipSize (infoPtr, &size);
TRACE("size %d x %d\n", size.cx, size.cy);
if (track_activate && (toolPtr->uFlags & TTF_TRACK))
{
rect.left = infoPtr->xTrackPos;
rect.top = infoPtr->yTrackPos;
ptfx = rect.left;
if (toolPtr->uFlags & TTF_CENTERTIP)
{
rect.left -= (size.cx / 2);
if (!(style & TTS_BALLOON))
rect.top -= (size.cy / 2);
}
if (!(infoPtr->bToolBelow = (infoPtr->yTrackPos + size.cy <= GetSystemMetrics(SM_CYSCREEN))))
rect.top -= size.cy;
if (!(toolPtr->uFlags & TTF_ABSOLUTE))
{
if (style & TTS_BALLOON)
rect.left -= BALLOON_STEMINDENT;
else
{
RECT rcTool;
if (toolPtr->uFlags & TTF_IDISHWND)
GetWindowRect ((HWND)toolPtr->uId, &rcTool);
else
{
rcTool = toolPtr->rect;
MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rcTool, 2);
}
/* smart placement */
if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
(rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
rect.left = rcTool.right;
}
}
}
else
{
if (toolPtr->uFlags & TTF_CENTERTIP)
{
RECT rc;
if (toolPtr->uFlags & TTF_IDISHWND)
GetWindowRect ((HWND)toolPtr->uId, &rc);
else {
rc = toolPtr->rect;
MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
}
rect.left = (rc.left + rc.right - size.cx) / 2;
if (style & TTS_BALLOON)
{
ptfx = rc.left + ((rc.right - rc.left) / 2);
/* CENTERTIP ballon tooltips default to below the field
* if they fit on the screen */
if (rc.bottom + size.cy > GetSystemMetrics(SM_CYSCREEN))
{
rect.top = rc.top - size.cy;
infoPtr->bToolBelow = FALSE;
}
else
{
infoPtr->bToolBelow = TRUE;
rect.top = rc.bottom;
}
rect.left = max(0, rect.left - BALLOON_STEMINDENT);
}
else
{
rect.top = rc.bottom + 2;
infoPtr->bToolBelow = TRUE;
}
}
else
{
GetCursorPos ((LPPOINT)&rect);
if (style & TTS_BALLOON)
{
ptfx = rect.left;
if(rect.top - size.cy >= 0)
{
rect.top -= size.cy;
infoPtr->bToolBelow = FALSE;
}
else
{
infoPtr->bToolBelow = TRUE;
rect.top += 20;
}
rect.left = max(0, rect.left - BALLOON_STEMINDENT);
}
else
{
rect.top += 20;
infoPtr->bToolBelow = TRUE;
}
}
}
TRACE("pos %d - %d\n", rect.left, rect.top);
rect.right = rect.left + size.cx;
rect.bottom = rect.top + size.cy;
/* check position */
monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
mon_info.cbSize = sizeof(mon_info);
GetMonitorInfoW( monitor, &mon_info );
if( rect.right > mon_info.rcWork.right ) {
rect.left -= rect.right - mon_info.rcWork.right + 2;
rect.right = mon_info.rcWork.right - 2;
}
if (rect.left < mon_info.rcWork.left) rect.left = mon_info.rcWork.left;
if( rect.bottom > mon_info.rcWork.bottom ) {
RECT rc;
if (toolPtr->uFlags & TTF_IDISHWND)
GetWindowRect ((HWND)toolPtr->uId, &rc);
else {
rc = toolPtr->rect;
MapWindowPoints (toolPtr->hwnd, NULL, (LPPOINT)&rc, 2);
}
rect.bottom = rc.top - 2;
rect.top = rect.bottom - size.cy;
}
AdjustWindowRectEx (&rect, GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE),
FALSE, GetWindowLongW (infoPtr->hwndSelf, GWL_EXSTYLE));
if (style & TTS_BALLOON)
{
HRGN hRgn;
HRGN hrStem;
POINT pts[3];
ptfx -= rect.left;
if(infoPtr->bToolBelow)
{
pts[0].x = ptfx;
pts[0].y = 0;
pts[1].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
pts[1].y = BALLOON_STEMHEIGHT;
pts[2].x = pts[1].x + BALLOON_STEMWIDTH;
pts[2].y = pts[1].y;
if(pts[2].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
{
pts[2].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
pts[1].x = pts[2].x - BALLOON_STEMWIDTH;
}
}
else
{
pts[0].x = max(BALLOON_STEMINDENT, ptfx - (BALLOON_STEMWIDTH / 2));
pts[0].y = (rect.bottom - rect.top) - BALLOON_STEMHEIGHT;
pts[1].x = pts[0].x + BALLOON_STEMWIDTH;
pts[1].y = pts[0].y;
pts[2].x = ptfx;
pts[2].y = (rect.bottom - rect.top);
if(pts[1].x > (rect.right - rect.left) - BALLOON_STEMINDENT)
{
pts[1].x = (rect.right - rect.left) - BALLOON_STEMINDENT;
pts[0].x = pts[1].x - BALLOON_STEMWIDTH;
}
}
hrStem = CreatePolygonRgn(pts, sizeof(pts) / sizeof(pts[0]), ALTERNATE);
hRgn = CreateRoundRectRgn(0,
(infoPtr->bToolBelow ? BALLOON_STEMHEIGHT : 0),
rect.right - rect.left,
(infoPtr->bToolBelow ? rect.bottom - rect.top : rect.bottom - rect.top - BALLOON_STEMHEIGHT),
BALLOON_ROUNDEDNESS, BALLOON_ROUNDEDNESS);
CombineRgn(hRgn, hRgn, hrStem, RGN_OR);
DeleteObject(hrStem);
SetWindowRgn(infoPtr->hwndSelf, hRgn, FALSE);
/* we don't free the region handle as the system deletes it when
* it is no longer needed */
}
SetWindowPos (infoPtr->hwndSelf, HWND_TOPMOST, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top,
SWP_SHOWWINDOW | SWP_NOACTIVATE);
/* repaint the tooltip */
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
UpdateWindow(infoPtr->hwndSelf);
if (!track_activate)
{
SetTimer (infoPtr->hwndSelf, ID_TIMERPOP, infoPtr->nAutoPopTime, 0);
TRACE("timer 2 started!\n");
SetTimer (infoPtr->hwndSelf, ID_TIMERLEAVE, infoPtr->nReshowTime, 0);
TRACE("timer 3 started!\n");
}
}
static void
TOOLTIPS_Hide (TOOLTIPS_INFO *infoPtr)
{
TTTOOL_INFO *toolPtr;
NMHDR hdr;
TRACE("Hide tooltip %d! (%p)\n", infoPtr->nCurrentTool, infoPtr->hwndSelf);
if (infoPtr->nCurrentTool == -1)
return;
toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
KillTimer (infoPtr->hwndSelf, ID_TIMERPOP);
hdr.hwndFrom = infoPtr->hwndSelf;
hdr.idFrom = toolPtr->uId;
hdr.code = TTN_POP;
SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
infoPtr->nCurrentTool = -1;
SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
}
static void
TOOLTIPS_TrackShow (TOOLTIPS_INFO *infoPtr)
{
TOOLTIPS_Show(infoPtr, TRUE);
}
static void
TOOLTIPS_TrackHide (const TOOLTIPS_INFO *infoPtr)
{
TTTOOL_INFO *toolPtr;
NMHDR hdr;
TRACE("hide tracking tooltip %d\n", infoPtr->nTrackTool);
if (infoPtr->nTrackTool == -1)
return;
toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
hdr.hwndFrom = infoPtr->hwndSelf;
hdr.idFrom = toolPtr->uId;
hdr.code = TTN_POP;
SendMessageW (toolPtr->hwnd, WM_NOTIFY, toolPtr->uId, (LPARAM)&hdr);
SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
}
/* Structure layout is the same for TTTOOLINFOW and TTTOOLINFOA,
this helper is used in both cases. */
static INT
TOOLTIPS_GetToolFromInfoT (const TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
{
TTTOOL_INFO *toolPtr;
UINT nTool;
for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
toolPtr = &infoPtr->tools[nTool];
if (!(toolPtr->uFlags & TTF_IDISHWND) &&
(lpToolInfo->hwnd == toolPtr->hwnd) &&
(lpToolInfo->uId == toolPtr->uId))
return nTool;
}
for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
toolPtr = &infoPtr->tools[nTool];
if ((toolPtr->uFlags & TTF_IDISHWND) &&
(lpToolInfo->uId == toolPtr->uId))
return nTool;
}
return -1;
}
static INT
TOOLTIPS_GetToolFromPoint (const TOOLTIPS_INFO *infoPtr, HWND hwnd, const POINT *lpPt)
{
TTTOOL_INFO *toolPtr;
UINT nTool;
for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
toolPtr = &infoPtr->tools[nTool];
if (!(toolPtr->uFlags & TTF_IDISHWND)) {
if (hwnd != toolPtr->hwnd)
continue;
if (!PtInRect (&toolPtr->rect, *lpPt))
continue;
return nTool;
}
}
for (nTool = 0; nTool < infoPtr->uNumTools; nTool++) {
toolPtr = &infoPtr->tools[nTool];
if (toolPtr->uFlags & TTF_IDISHWND) {
if ((HWND)toolPtr->uId == hwnd)
return nTool;
}
}
return -1;
}
static inline void
TOOLTIPS_CopyInfoT (const TTTOOL_INFO *toolPtr, TTTOOLINFOW *ti, BOOL isW)
{
if (ti->lpszText) {
if (toolPtr->lpszText == NULL ||
IS_INTRESOURCE(toolPtr->lpszText) ||
toolPtr->lpszText == LPSTR_TEXTCALLBACKW)
ti->lpszText = toolPtr->lpszText;
else if (isW)
strcpyW (ti->lpszText, toolPtr->lpszText);
else
/* ANSI version, the buffer is maximum 80 bytes without null. */
WideCharToMultiByte(CP_ACP, 0, toolPtr->lpszText, -1,
(LPSTR)ti->lpszText, MAX_TEXT_SIZE_A, NULL, NULL);
}
}
static BOOL
TOOLTIPS_IsWindowActive (HWND hwnd)
{
HWND hwndActive = GetActiveWindow ();
if (!hwndActive)
return FALSE;
if (hwndActive == hwnd)
return TRUE;
return IsChild (hwndActive, hwnd);
}
static INT
TOOLTIPS_CheckTool (const TOOLTIPS_INFO *infoPtr, BOOL bShowTest)
{
POINT pt;
HWND hwndTool;
INT nTool;
GetCursorPos (&pt);
hwndTool = (HWND)SendMessageW (infoPtr->hwndSelf, TTM_WINDOWFROMPOINT, 0, (LPARAM)&pt);
if (hwndTool == 0)
return -1;
ScreenToClient (hwndTool, &pt);
nTool = TOOLTIPS_GetToolFromPoint (infoPtr, hwndTool, &pt);
if (nTool == -1)
return -1;