-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathtab.c
More file actions
3476 lines (2922 loc) · 97.1 KB
/
Copy pathtab.c
File metadata and controls
3476 lines (2922 loc) · 97.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
/*
* Tab control
*
* Copyright 1998 Anders Carlsson
* Copyright 1999 Alex Priem <alexp@sci.kun.nl>
* Copyright 1999 Francis Beaudet
* Copyright 2003 Vitaliy Margolen
*
* 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 May. 20, 2005, by James Hawkins.
*
* 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:
*
* Styles:
* TCS_MULTISELECT - implement for VK_SPACE selection
* TCS_RIGHT
* TCS_RIGHTJUSTIFY
* TCS_SCROLLOPPOSITE
* TCS_SINGLELINE
* TCIF_RTLREADING
*
* Extended Styles:
* TCS_EX_REGISTERDROP
*
* Notifications:
* NM_RELEASEDCAPTURE
* TCN_FOCUSCHANGE
* TCN_GETOBJECT
*
* Macros:
* TabCtrl_AdjustRect
*
*/
#include <assert.h>
#include <stdarg.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "commctrl.h"
#include "comctl32.h"
#include "uxtheme.h"
#include "vssym32.h"
#include "wine/debug.h"
#include <math.h>
WINE_DEFAULT_DEBUG_CHANNEL(tab);
typedef struct
{
DWORD dwState;
LPWSTR pszText;
INT iImage;
RECT rect; /* bounding rectangle of the item relative to the
* leftmost item (the leftmost item, 0, would have a
* "left" member of 0 in this rectangle)
*
* additionally the top member holds the row number
* and bottom is unused and should be 0 */
BYTE extra[1]; /* Space for caller supplied info, variable size */
} TAB_ITEM;
/* The size of a tab item depends on how much extra data is requested.
TCM_INSERTITEM always stores at least LPARAM sized data. */
#define EXTRA_ITEM_SIZE(infoPtr) (max((infoPtr)->cbInfo, sizeof(LPARAM)))
#define TAB_ITEM_SIZE(infoPtr) FIELD_OFFSET(TAB_ITEM, extra[EXTRA_ITEM_SIZE(infoPtr)])
typedef struct
{
HWND hwnd; /* Tab control window */
HWND hwndNotify; /* notification window (parent) */
UINT uNumItem; /* number of tab items */
UINT uNumRows; /* number of tab rows */
INT tabHeight; /* height of the tab row */
INT tabWidth; /* width of tabs */
INT tabMinWidth; /* minimum width of items */
USHORT uHItemPadding; /* amount of horizontal padding, in pixels */
USHORT uVItemPadding; /* amount of vertical padding, in pixels */
USHORT uHItemPadding_s; /* Set amount of horizontal padding, in pixels */
USHORT uVItemPadding_s; /* Set amount of vertical padding, in pixels */
HFONT hFont; /* handle to the current font */
HCURSOR hcurArrow; /* handle to the current cursor */
HIMAGELIST himl; /* handle to an image list (may be 0) */
HWND hwndToolTip; /* handle to tab's tooltip */
INT leftmostVisible; /* Used for scrolling, this member contains
* the index of the first visible item */
INT iSelected; /* the currently selected item */
INT iHotTracked; /* the highlighted item under the mouse */
INT uFocus; /* item which has the focus */
BOOL DoRedraw; /* flag for redrawing when tab contents is changed*/
BOOL needsScrolling; /* TRUE if the size of the tabs is greater than
* the size of the control */
BOOL fHeightSet; /* was the height of the tabs explicitly set? */
BOOL bUnicode; /* Unicode control? */
HWND hwndUpDown; /* Updown control used for scrolling */
INT cbInfo; /* Number of bytes of caller supplied info per tab */
DWORD exStyle; /* Extended style used, currently:
TCS_EX_FLATSEPARATORS, TCS_EX_REGISTERDROP */
DWORD dwStyle; /* the cached window GWL_STYLE */
HDPA items; /* dynamic array of TAB_ITEM* pointers */
} TAB_INFO;
/******************************************************************************
* Positioning constants
*/
#define SELECTED_TAB_OFFSET 2
#define ROUND_CORNER_SIZE 2
#define DISPLAY_AREA_PADDINGX 2
#define DISPLAY_AREA_PADDINGY 2
#define CONTROL_BORDER_SIZEX 2
#define CONTROL_BORDER_SIZEY 2
#define BUTTON_SPACINGX 3
#define BUTTON_SPACINGY 3
#define FLAT_BTN_SPACINGX 8
#define DEFAULT_PADDING_X 6
#define EXTRA_ICON_PADDING 3
#define MIN_CHAR_LENGTH 6
#define TAB_GetInfoPtr(hwnd) ((TAB_INFO *)GetWindowLongPtrW(hwnd,0))
/******************************************************************************
* Hot-tracking timer constants
*/
#define TAB_HOTTRACK_TIMER 1
#define TAB_HOTTRACK_TIMER_INTERVAL 100 /* milliseconds */
static const WCHAR themeClass[] = L"Tab";
static inline TAB_ITEM* TAB_GetItem(const TAB_INFO *infoPtr, INT i)
{
assert(i >= 0 && i < infoPtr->uNumItem);
return DPA_GetPtr(infoPtr->items, i);
}
/******************************************************************************
* Prototypes
*/
static void TAB_InvalidateTabArea(const TAB_INFO *);
static void TAB_EnsureSelectionVisible(TAB_INFO *);
static void TAB_DrawItemInterior(const TAB_INFO *, HDC, INT, RECT*);
static LRESULT TAB_DeselectAll(TAB_INFO *, BOOL);
static BOOL TAB_InternalGetItemRect(const TAB_INFO *, INT, RECT*, RECT*);
static BOOL
TAB_SendSimpleNotify (const TAB_INFO *infoPtr, UINT code)
{
NMHDR nmhdr;
nmhdr.hwndFrom = infoPtr->hwnd;
nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwnd, GWLP_ID);
nmhdr.code = code;
return (BOOL) SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
nmhdr.idFrom, (LPARAM) &nmhdr);
}
static void
TAB_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
MSG msg;
msg.hwnd = hwndMsg;
msg.message = uMsg;
msg.wParam = wParam;
msg.lParam = lParam;
msg.time = GetMessageTime ();
msg.pt.x = (short)LOWORD(GetMessagePos ());
msg.pt.y = (short)HIWORD(GetMessagePos ());
SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
}
static void
TAB_DumpItemExternalT(const TCITEMW *pti, UINT iItem, BOOL isW)
{
if (TRACE_ON(tab)) {
TRACE("external tab %d, mask=0x%08x, dwState %#lx, dwStateMask %#lx, cchTextMax=0x%08x\n",
iItem, pti->mask, pti->dwState, pti->dwStateMask, pti->cchTextMax);
TRACE("external tab %d, iImage=%d, lParam %Ix, pszTextW=%s\n",
iItem, pti->iImage, pti->lParam, isW ? debugstr_w(pti->pszText) : debugstr_a((LPSTR)pti->pszText));
}
}
static void
TAB_DumpItemInternal(const TAB_INFO *infoPtr, UINT iItem)
{
if (TRACE_ON(tab)) {
TAB_ITEM *ti = TAB_GetItem(infoPtr, iItem);
TRACE("tab %d, dwState %#lx, pszText %s, iImage %d\n", iItem, ti->dwState, debugstr_w(ti->pszText), ti->iImage);
TRACE("tab %d, rect.left=%ld, rect.top(row)=%ld\n", iItem, ti->rect.left, ti->rect.top);
}
}
/* RETURNS
* the index of the selected tab, or -1 if no tab is selected. */
static inline LRESULT TAB_GetCurSel (const TAB_INFO *infoPtr)
{
TRACE("(%p)\n", infoPtr);
return infoPtr->iSelected;
}
/* RETURNS
* the index of the tab item that has the focus. */
static inline LRESULT
TAB_GetCurFocus (const TAB_INFO *infoPtr)
{
TRACE("(%p)\n", infoPtr);
return infoPtr->uFocus;
}
static inline LRESULT TAB_GetToolTips (const TAB_INFO *infoPtr)
{
TRACE("(%p)\n", infoPtr);
return (LRESULT)infoPtr->hwndToolTip;
}
static inline LRESULT TAB_SetCurSel (TAB_INFO *infoPtr, INT iItem)
{
INT prevItem = infoPtr->iSelected;
TRACE("(%p %d)\n", infoPtr, iItem);
if (iItem >= (INT)infoPtr->uNumItem)
return -1;
if (prevItem != iItem) {
if (prevItem != -1)
TAB_GetItem(infoPtr, prevItem)->dwState &= ~TCIS_BUTTONPRESSED;
if (iItem >= 0)
{
TAB_GetItem(infoPtr, iItem)->dwState |= TCIS_BUTTONPRESSED;
infoPtr->iSelected = iItem;
infoPtr->uFocus = iItem;
}
else
{
infoPtr->iSelected = -1;
infoPtr->uFocus = -1;
}
TAB_EnsureSelectionVisible(infoPtr);
TAB_InvalidateTabArea(infoPtr);
NotifyWinEvent(EVENT_OBJECT_SELECTION, infoPtr->hwnd, OBJID_CLIENT, infoPtr->iSelected + 1);
}
return prevItem;
}
static LRESULT TAB_SetCurFocus (TAB_INFO *infoPtr, INT iItem)
{
TRACE("(%p %d)\n", infoPtr, iItem);
if (iItem < 0) {
infoPtr->uFocus = -1;
if (infoPtr->iSelected != -1) {
infoPtr->iSelected = -1;
TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGE);
TAB_InvalidateTabArea(infoPtr);
if (!(infoPtr->dwStyle & TCS_BUTTONS))
NotifyWinEvent(EVENT_OBJECT_SELECTION, infoPtr->hwnd, OBJID_CLIENT, 0);
}
}
else if (iItem < infoPtr->uNumItem) {
if (infoPtr->dwStyle & TCS_BUTTONS) {
/* set focus to new item, leave selection as is */
if (infoPtr->uFocus != iItem) {
INT prev_focus = infoPtr->uFocus;
RECT r;
infoPtr->uFocus = iItem;
if (prev_focus != infoPtr->iSelected) {
if (TAB_InternalGetItemRect(infoPtr, prev_focus, &r, NULL))
InvalidateRect(infoPtr->hwnd, &r, FALSE);
}
if (TAB_InternalGetItemRect(infoPtr, iItem, &r, NULL))
InvalidateRect(infoPtr->hwnd, &r, FALSE);
TAB_SendSimpleNotify(infoPtr, TCN_FOCUSCHANGE);
NotifyWinEvent(EVENT_OBJECT_FOCUS, infoPtr->hwnd, OBJID_CLIENT, iItem + 1);
}
} else {
INT oldFocus = infoPtr->uFocus;
if (infoPtr->iSelected != iItem || oldFocus == -1 ) {
infoPtr->uFocus = iItem;
if (oldFocus != -1) {
if (!TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGING)) {
infoPtr->iSelected = iItem;
TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGE);
}
else
infoPtr->iSelected = iItem;
TAB_EnsureSelectionVisible(infoPtr);
TAB_InvalidateTabArea(infoPtr);
NotifyWinEvent(EVENT_OBJECT_SELECTION, infoPtr->hwnd, OBJID_CLIENT, iItem + 1);
}
}
}
}
return 0;
}
static inline LRESULT
TAB_SetToolTips (TAB_INFO *infoPtr, HWND hwndToolTip)
{
TRACE("%p %p\n", infoPtr, hwndToolTip);
infoPtr->hwndToolTip = hwndToolTip;
return 0;
}
static inline LRESULT
TAB_SetPadding (TAB_INFO *infoPtr, LPARAM lParam)
{
TRACE("(%p %d %d)\n", infoPtr, LOWORD(lParam), HIWORD(lParam));
infoPtr->uHItemPadding_s = LOWORD(lParam);
infoPtr->uVItemPadding_s = HIWORD(lParam);
return 0;
}
/******************************************************************************
* TAB_InternalGetItemRect
*
* This method will calculate the rectangle representing a given tab item in
* client coordinates. This method takes scrolling into account.
*
* This method returns TRUE if the item is visible in the window and FALSE
* if it is completely outside the client area.
*/
static BOOL TAB_InternalGetItemRect(
const TAB_INFO* infoPtr,
INT itemIndex,
RECT* itemRect,
RECT* selectedRect)
{
RECT tmpItemRect,clientRect;
/* Perform a sanity check and a trivial visibility check. */
if ( (infoPtr->uNumItem <= 0) ||
(itemIndex >= infoPtr->uNumItem) ||
(!(((infoPtr->dwStyle & TCS_MULTILINE) || (infoPtr->dwStyle & TCS_VERTICAL))) &&
(itemIndex < infoPtr->leftmostVisible)))
{
TRACE("Not Visible\n");
SetRect(itemRect, 0, 0, 0, infoPtr->tabHeight);
SetRectEmpty(selectedRect);
return FALSE;
}
/*
* Avoid special cases in this procedure by assigning the "out"
* parameters if the caller didn't supply them
*/
if (itemRect == NULL)
itemRect = &tmpItemRect;
/* Retrieve the unmodified item rect. */
*itemRect = TAB_GetItem(infoPtr,itemIndex)->rect;
/* calculate the times bottom and top based on the row */
GetClientRect(infoPtr->hwnd, &clientRect);
if ((infoPtr->dwStyle & TCS_BOTTOM) && (infoPtr->dwStyle & TCS_VERTICAL))
{
itemRect->right = clientRect.right - SELECTED_TAB_OFFSET - itemRect->left * infoPtr->tabHeight -
((infoPtr->dwStyle & TCS_BUTTONS) ? itemRect->left * BUTTON_SPACINGX : 0);
itemRect->left = itemRect->right - infoPtr->tabHeight;
}
else if (infoPtr->dwStyle & TCS_VERTICAL)
{
itemRect->left = clientRect.left + SELECTED_TAB_OFFSET + itemRect->left * infoPtr->tabHeight +
((infoPtr->dwStyle & TCS_BUTTONS) ? itemRect->left * BUTTON_SPACINGX : 0);
itemRect->right = itemRect->left + infoPtr->tabHeight;
}
else if (infoPtr->dwStyle & TCS_BOTTOM)
{
itemRect->bottom = clientRect.bottom - itemRect->top * infoPtr->tabHeight -
((infoPtr->dwStyle & TCS_BUTTONS) ? itemRect->top * BUTTON_SPACINGY : SELECTED_TAB_OFFSET);
itemRect->top = itemRect->bottom - infoPtr->tabHeight;
}
else /* not TCS_BOTTOM and not TCS_VERTICAL */
{
itemRect->top = clientRect.top + itemRect->top * infoPtr->tabHeight +
((infoPtr->dwStyle & TCS_BUTTONS) ? itemRect->top * BUTTON_SPACINGY : SELECTED_TAB_OFFSET);
itemRect->bottom = itemRect->top + infoPtr->tabHeight;
}
/*
* "scroll" it to make sure the item at the very left of the
* tab control is the leftmost visible tab.
*/
if(infoPtr->dwStyle & TCS_VERTICAL)
{
OffsetRect(itemRect,
0,
-TAB_GetItem(infoPtr, infoPtr->leftmostVisible)->rect.top);
/*
* Move the rectangle so the first item is slightly offset from
* the bottom of the tab control.
*/
OffsetRect(itemRect,
0,
SELECTED_TAB_OFFSET);
} else
{
OffsetRect(itemRect,
-TAB_GetItem(infoPtr, infoPtr->leftmostVisible)->rect.left,
0);
/*
* Move the rectangle so the first item is slightly offset from
* the left of the tab control.
*/
OffsetRect(itemRect,
SELECTED_TAB_OFFSET,
0);
}
TRACE("item %d tab h=%d, rect=(%s)\n",
itemIndex, infoPtr->tabHeight, wine_dbgstr_rect(itemRect));
/* Now, calculate the position of the item as if it were selected. */
if (selectedRect!=NULL)
{
*selectedRect = *itemRect;
/* The rectangle of a selected item is a bit wider. */
if(infoPtr->dwStyle & TCS_VERTICAL)
InflateRect(selectedRect, 0, SELECTED_TAB_OFFSET);
else
InflateRect(selectedRect, SELECTED_TAB_OFFSET, 0);
/* If it also a bit higher. */
if ((infoPtr->dwStyle & TCS_BOTTOM) && (infoPtr->dwStyle & TCS_VERTICAL))
{
selectedRect->left -= 2; /* the border is thicker on the right */
selectedRect->right += SELECTED_TAB_OFFSET;
}
else if (infoPtr->dwStyle & TCS_VERTICAL)
{
selectedRect->left -= SELECTED_TAB_OFFSET;
selectedRect->right += 1;
}
else if (infoPtr->dwStyle & TCS_BOTTOM)
{
selectedRect->bottom += SELECTED_TAB_OFFSET;
}
else /* not TCS_BOTTOM and not TCS_VERTICAL */
{
selectedRect->top -= SELECTED_TAB_OFFSET;
selectedRect->bottom -= 1;
}
}
/* Check for visibility */
if (infoPtr->dwStyle & TCS_VERTICAL)
return (itemRect->top < clientRect.bottom) && (itemRect->bottom > clientRect.top);
else
return (itemRect->left < clientRect.right) && (itemRect->right > clientRect.left);
}
static inline BOOL
TAB_GetItemRect(const TAB_INFO *infoPtr, INT item, RECT *rect)
{
TRACE("(%p, %d, %p)\n", infoPtr, item, rect);
return TAB_InternalGetItemRect(infoPtr, item, rect, NULL);
}
/******************************************************************************
* TAB_KeyDown
*
* This method is called to handle keyboard input
*/
static LRESULT TAB_KeyDown(TAB_INFO* infoPtr, WPARAM keyCode, LPARAM lParam)
{
INT newItem = -1;
NMTCKEYDOWN nm;
/* TCN_KEYDOWN notification sent always */
nm.hdr.hwndFrom = infoPtr->hwnd;
nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->hwnd, GWLP_ID);
nm.hdr.code = TCN_KEYDOWN;
nm.wVKey = keyCode;
nm.flags = lParam;
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm);
switch (keyCode)
{
case VK_LEFT:
newItem = infoPtr->uFocus - 1;
break;
case VK_RIGHT:
newItem = infoPtr->uFocus + 1;
break;
}
/* If we changed to a valid item, change focused item */
if (newItem >= 0 && newItem < infoPtr->uNumItem && infoPtr->uFocus != newItem)
TAB_SetCurFocus(infoPtr, newItem);
return 0;
}
/*
* WM_KILLFOCUS handler
*/
static void TAB_KillFocus(TAB_INFO *infoPtr)
{
/* clear current focused item back to selected for TCS_BUTTONS */
if ((infoPtr->dwStyle & TCS_BUTTONS) && (infoPtr->uFocus != infoPtr->iSelected))
{
RECT r;
if (TAB_InternalGetItemRect(infoPtr, infoPtr->uFocus, &r, NULL))
InvalidateRect(infoPtr->hwnd, &r, FALSE);
infoPtr->uFocus = infoPtr->iSelected;
}
}
/******************************************************************************
* TAB_FocusChanging
*
* This method is called whenever the focus goes in or out of this control
* it is used to update the visual state of the control.
*/
static void TAB_FocusChanging(const TAB_INFO *infoPtr)
{
RECT selectedRect;
BOOL isVisible;
/*
* Get the rectangle for the item.
*/
isVisible = TAB_InternalGetItemRect(infoPtr,
infoPtr->uFocus,
NULL,
&selectedRect);
/*
* If the rectangle is not completely invisible, invalidate that
* portion of the window.
*/
if (isVisible)
{
TRACE("invalidate (%s)\n", wine_dbgstr_rect(&selectedRect));
InvalidateRect(infoPtr->hwnd, &selectedRect, TRUE);
}
}
static INT TAB_InternalHitTest (const TAB_INFO *infoPtr, POINT pt, UINT *flags)
{
RECT rect;
INT iCount;
for (iCount = 0; iCount < infoPtr->uNumItem; iCount++)
{
TAB_InternalGetItemRect(infoPtr, iCount, &rect, NULL);
if (PtInRect(&rect, pt))
{
*flags = TCHT_ONITEM;
return iCount;
}
}
*flags = TCHT_NOWHERE;
return -1;
}
static inline LRESULT
TAB_HitTest (const TAB_INFO *infoPtr, LPTCHITTESTINFO lptest)
{
TRACE("(%p, %p)\n", infoPtr, lptest);
return TAB_InternalHitTest (infoPtr, lptest->pt, &lptest->flags);
}
/******************************************************************************
* TAB_NCHitTest
*
* Napster v2b5 has a tab control for its main navigation which has a client
* area that covers the whole area of the dialog pages.
* That's why it receives all msgs for that area and the underlying dialog ctrls
* are dead.
* So I decided that we should handle WM_NCHITTEST here and return
* HTTRANSPARENT if we don't hit the tab control buttons.
* FIXME: WM_NCHITTEST handling correct ? Fix it if you know that Windows
* doesn't do it that way. Maybe depends on tab control styles ?
*/
static inline LRESULT
TAB_NCHitTest (const TAB_INFO *infoPtr, LPARAM lParam)
{
POINT pt;
UINT dummyflag;
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
ScreenToClient(infoPtr->hwnd, &pt);
if (TAB_InternalHitTest(infoPtr, pt, &dummyflag) == -1)
return HTTRANSPARENT;
else
return HTCLIENT;
}
static LRESULT
TAB_LButtonDown (TAB_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
POINT pt;
INT newItem;
UINT dummy;
if (infoPtr->hwndToolTip)
TAB_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwnd,
WM_LBUTTONDOWN, wParam, lParam);
if (!(infoPtr->dwStyle & TCS_FOCUSNEVER)) {
SetFocus (infoPtr->hwnd);
}
if (infoPtr->hwndToolTip)
TAB_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwnd,
WM_LBUTTONDOWN, wParam, lParam);
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
newItem = TAB_InternalHitTest (infoPtr, pt, &dummy);
TRACE("On Tab, item %d\n", newItem);
if ((newItem != -1) && (infoPtr->iSelected != newItem))
{
if ((infoPtr->dwStyle & TCS_BUTTONS) && (infoPtr->dwStyle & TCS_MULTISELECT) &&
(wParam & MK_CONTROL))
{
RECT r;
/* toggle multiselection */
TAB_GetItem(infoPtr, newItem)->dwState ^= TCIS_BUTTONPRESSED;
if (TAB_InternalGetItemRect (infoPtr, newItem, &r, NULL))
InvalidateRect (infoPtr->hwnd, &r, TRUE);
}
else
{
INT i;
BOOL pressed = FALSE;
/* any button pressed ? */
for (i = 0; i < infoPtr->uNumItem; i++)
if ((TAB_GetItem (infoPtr, i)->dwState & TCIS_BUTTONPRESSED) &&
(infoPtr->iSelected != i))
{
pressed = TRUE;
break;
}
if (TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGING))
return 0;
if (pressed)
TAB_DeselectAll (infoPtr, FALSE);
else
TAB_SetCurSel(infoPtr, newItem);
TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGE);
}
}
return 0;
}
static inline LRESULT
TAB_LButtonUp (const TAB_INFO *infoPtr)
{
TAB_SendSimpleNotify(infoPtr, NM_CLICK);
return 0;
}
static inline void
TAB_RButtonUp (const TAB_INFO *infoPtr)
{
TAB_SendSimpleNotify(infoPtr, NM_RCLICK);
}
/******************************************************************************
* TAB_DrawLoneItemInterior
*
* This calls TAB_DrawItemInterior. However, TAB_DrawItemInterior is normally
* called by TAB_DrawItem which is normally called by TAB_Refresh which sets
* up the device context and font. This routine does the same setup but
* only calls TAB_DrawItemInterior for the single specified item.
*/
static void
TAB_DrawLoneItemInterior(const TAB_INFO* infoPtr, int iItem)
{
HDC hdc = GetDC(infoPtr->hwnd);
RECT r, rC;
/* Clip UpDown control to not draw over it */
if (infoPtr->needsScrolling)
{
GetWindowRect(infoPtr->hwnd, &rC);
GetWindowRect(infoPtr->hwndUpDown, &r);
ExcludeClipRect(hdc, r.left - rC.left, r.top - rC.top, r.right - rC.left, r.bottom - rC.top);
}
TAB_DrawItemInterior(infoPtr, hdc, iItem, NULL);
ReleaseDC(infoPtr->hwnd, hdc);
}
/* update a tab after hottracking - invalidate it or just redraw the interior,
* based on whether theming is used or not */
static inline void hottrack_refresh(const TAB_INFO *infoPtr, int tabIndex)
{
if (tabIndex == -1) return;
if (GetWindowTheme (infoPtr->hwnd))
{
RECT rect;
TAB_InternalGetItemRect(infoPtr, tabIndex, &rect, NULL);
InvalidateRect (infoPtr->hwnd, &rect, FALSE);
}
else
TAB_DrawLoneItemInterior(infoPtr, tabIndex);
}
/******************************************************************************
* TAB_HotTrackTimerProc
*
* When a mouse-move event causes a tab to be highlighted (hot-tracking), a
* timer is setup so we can check if the mouse is moved out of our window.
* (We don't get an event when the mouse leaves, the mouse-move events just
* stop being delivered to our window and just start being delivered to
* another window.) This function is called when the timer triggers so
* we can check if the mouse has left our window. If so, we un-highlight
* the hot-tracked tab.
*/
static void CALLBACK
TAB_HotTrackTimerProc
(
HWND hwnd, /* handle of window for timer messages */
UINT uMsg, /* WM_TIMER message */
UINT_PTR idEvent, /* timer identifier */
DWORD dwTime /* current system time */
)
{
TAB_INFO* infoPtr = TAB_GetInfoPtr(hwnd);
if (infoPtr != NULL && infoPtr->iHotTracked >= 0)
{
POINT pt;
/*
** If we can't get the cursor position, or if the cursor is outside our
** window, we un-highlight the hot-tracked tab. Note that the cursor is
** "outside" even if it is within our bounding rect if another window
** overlaps. Note also that the case where the cursor stayed within our
** window but has moved off the hot-tracked tab will be handled by the
** WM_MOUSEMOVE event.
*/
if (!GetCursorPos(&pt) || WindowFromPoint(pt) != hwnd)
{
/* Redraw iHotTracked to look normal */
INT iRedraw = infoPtr->iHotTracked;
infoPtr->iHotTracked = -1;
hottrack_refresh (infoPtr, iRedraw);
/* Kill this timer */
KillTimer(hwnd, TAB_HOTTRACK_TIMER);
}
}
}
/******************************************************************************
* TAB_RecalcHotTrack
*
* If a tab control has the TCS_HOTTRACK style, then the tab under the mouse
* should be highlighted. This function determines which tab in a tab control,
* if any, is under the mouse and records that information. The caller may
* supply output parameters to receive the item number of the tab item which
* was highlighted but isn't any longer and of the tab item which is now
* highlighted but wasn't previously. The caller can use this information to
* selectively redraw those tab items.
*
* If the caller has a mouse position, it can supply it through the pos
* parameter. For example, TAB_MouseMove does this. Otherwise, the caller
* supplies NULL and this function determines the current mouse position
* itself.
*/
static void
TAB_RecalcHotTrack
(
TAB_INFO* infoPtr,
const LPARAM* pos,
int* out_redrawLeave,
int* out_redrawEnter
)
{
int item = -1;
if (out_redrawLeave != NULL)
*out_redrawLeave = -1;
if (out_redrawEnter != NULL)
*out_redrawEnter = -1;
if ((infoPtr->dwStyle & TCS_HOTTRACK) || GetWindowTheme(infoPtr->hwnd))
{
POINT pt;
UINT flags;
if (pos == NULL)
{
GetCursorPos(&pt);
ScreenToClient(infoPtr->hwnd, &pt);
}
else
{
pt.x = (short)LOWORD(*pos);
pt.y = (short)HIWORD(*pos);
}
item = TAB_InternalHitTest(infoPtr, pt, &flags);
}
if (item != infoPtr->iHotTracked)
{
if (infoPtr->iHotTracked >= 0)
{
/* Mark currently hot-tracked to be redrawn to look normal */
if (out_redrawLeave != NULL)
*out_redrawLeave = infoPtr->iHotTracked;
if (item < 0)
{
/* Kill timer which forces recheck of mouse pos */
KillTimer(infoPtr->hwnd, TAB_HOTTRACK_TIMER);
}
}
else
{
/* Start timer so we recheck mouse pos */
UINT timerID = SetTimer
(
infoPtr->hwnd,
TAB_HOTTRACK_TIMER,
TAB_HOTTRACK_TIMER_INTERVAL,
TAB_HotTrackTimerProc
);
if (timerID == 0)
return; /* Hot tracking not available */
}
infoPtr->iHotTracked = item;
if (item >= 0)
{
/* Mark new hot-tracked to be redrawn to look highlighted */
if (out_redrawEnter != NULL)
*out_redrawEnter = item;
}
}
}
/******************************************************************************
* TAB_MouseMove
*
* Handles the mouse-move event. Updates tooltips. Updates hot-tracking.
*/
static LRESULT
TAB_MouseMove (TAB_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
int redrawLeave;
int redrawEnter;
if (infoPtr->hwndToolTip)
TAB_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwnd,
WM_LBUTTONDOWN, wParam, lParam);
/* Determine which tab to highlight. Redraw tabs which change highlight
** status. */
TAB_RecalcHotTrack(infoPtr, &lParam, &redrawLeave, &redrawEnter);
hottrack_refresh (infoPtr, redrawLeave);
hottrack_refresh (infoPtr, redrawEnter);
return 0;
}
/******************************************************************************
* TAB_AdjustRect
*
* Calculates the tab control's display area given the window rectangle or
* the window rectangle given the requested display rectangle.
*/
static LRESULT TAB_AdjustRect(const TAB_INFO *infoPtr, WPARAM fLarger, LPRECT prc)
{
LONG *iRightBottom, *iLeftTop;
TRACE("hwnd %p, fLarger %Id, (%s)\n", infoPtr->hwnd, fLarger, wine_dbgstr_rect(prc));
if (!prc) return -1;
if(infoPtr->dwStyle & TCS_VERTICAL)
{
iRightBottom = &(prc->right);
iLeftTop = &(prc->left);
}
else
{
iRightBottom = &(prc->bottom);
iLeftTop = &(prc->top);
}
if (fLarger) /* Go from display rectangle */
{
/* Add the height of the tabs. */
if (infoPtr->dwStyle & TCS_BOTTOM)
*iRightBottom += infoPtr->tabHeight * infoPtr->uNumRows;
else
*iLeftTop -= infoPtr->tabHeight * infoPtr->uNumRows +
((infoPtr->dwStyle & TCS_BUTTONS)? 3 * (infoPtr->uNumRows - 1) : 0);
/* Inflate the rectangle for the padding */
InflateRect(prc, DISPLAY_AREA_PADDINGX, DISPLAY_AREA_PADDINGY);
/* Inflate for the border */
InflateRect(prc, CONTROL_BORDER_SIZEX, CONTROL_BORDER_SIZEY);
}
else /* Go from window rectangle. */
{
/* Deflate the rectangle for the border */
InflateRect(prc, -CONTROL_BORDER_SIZEX, -CONTROL_BORDER_SIZEY);
/* Deflate the rectangle for the padding */
InflateRect(prc, -DISPLAY_AREA_PADDINGX, -DISPLAY_AREA_PADDINGY);
/* Remove the height of the tabs. */
if (infoPtr->dwStyle & TCS_BOTTOM)
*iRightBottom -= infoPtr->tabHeight * infoPtr->uNumRows;
else
*iLeftTop += (infoPtr->tabHeight) * infoPtr->uNumRows +
((infoPtr->dwStyle & TCS_BUTTONS)? 3 * (infoPtr->uNumRows - 1) : 0);
}
return 0;
}
/******************************************************************************
* TAB_OnHScroll
*
* This method will handle the notification from the scroll control and
* perform the scrolling operation on the tab control.
*/
static LRESULT TAB_OnHScroll(TAB_INFO *infoPtr, int nScrollCode, int nPos)
{
if(nScrollCode == SB_THUMBPOSITION && nPos != infoPtr->leftmostVisible)
{
if(nPos < infoPtr->leftmostVisible)
infoPtr->leftmostVisible--;
else
infoPtr->leftmostVisible++;
TAB_RecalcHotTrack(infoPtr, NULL, NULL, NULL);
TAB_InvalidateTabArea(infoPtr);
SendMessageW(infoPtr->hwndUpDown, UDM_SETPOS, 0,
MAKELONG(infoPtr->leftmostVisible, 0));