4 * Copyright 1998 Anders Carlsson
5 * Copyright 1999 Alex Priem <alexp@sci.kun.nl>
6 * Copyright 1999 Francis Beaudet
7 * Copyright 2003 Vitaliy Margolen
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
43 * TCS_EX_FLATSEPARATORS
58 * TCM_GETEXTENDEDSTYLE
59 * TCM_SETEXTENDEDSTYLE
78 #include "wine/debug.h"
81 WINE_DEFAULT_DEBUG_CHANNEL(tab
);
88 RECT rect
; /* bounding rectangle of the item relative to the
89 * leftmost item (the leftmost item, 0, would have a
90 * "left" member of 0 in this rectangle)
92 * additionally the top member holds the row number
93 * and bottom is unused and should be 0 */
94 BYTE extra
[1]; /* Space for caller supplied info, variable size */
97 /* The size of a tab item depends on how much extra data is requested */
98 #define TAB_ITEM_SIZE(infoPtr) (FIELD_OFFSET(TAB_ITEM, extra[(infoPtr)->cbInfo]))
102 HWND hwnd
; /* Tab control window */
103 HWND hwndNotify
; /* notification window (parent) */
104 UINT uNumItem
; /* number of tab items */
105 UINT uNumRows
; /* number of tab rows */
106 INT tabHeight
; /* height of the tab row */
107 INT tabWidth
; /* width of tabs */
108 INT tabMinWidth
; /* minimum width of items */
109 USHORT uHItemPadding
; /* amount of horizontal padding, in pixels */
110 USHORT uVItemPadding
; /* amount of vertical padding, in pixels */
111 USHORT uHItemPadding_s
; /* Set amount of horizontal padding, in pixels */
112 USHORT uVItemPadding_s
; /* Set amount of vertical padding, in pixels */
113 HFONT hFont
; /* handle to the current font */
114 HCURSOR hcurArrow
; /* handle to the current cursor */
115 HIMAGELIST himl
; /* handle to an image list (may be 0) */
116 HWND hwndToolTip
; /* handle to tab's tooltip */
117 INT leftmostVisible
; /* Used for scrolling, this member contains
118 * the index of the first visible item */
119 INT iSelected
; /* the currently selected item */
120 INT iHotTracked
; /* the highlighted item under the mouse */
121 INT uFocus
; /* item which has the focus */
122 TAB_ITEM
* items
; /* pointer to an array of TAB_ITEM's */
123 BOOL DoRedraw
; /* flag for redrawing when tab contents is changed*/
124 BOOL needsScrolling
; /* TRUE if the size of the tabs is greater than
125 * the size of the control */
126 BOOL fHeightSet
; /* was the height of the tabs explicitly set? */
127 BOOL bUnicode
; /* Unicode control? */
128 HWND hwndUpDown
; /* Updown control used for scrolling */
129 INT cbInfo
; /* Number of bytes of caller supplied info per tab */
132 /******************************************************************************
133 * Positioning constants
135 #define SELECTED_TAB_OFFSET 2
136 #define ROUND_CORNER_SIZE 2
137 #define DISPLAY_AREA_PADDINGX 2
138 #define DISPLAY_AREA_PADDINGY 2
139 #define CONTROL_BORDER_SIZEX 2
140 #define CONTROL_BORDER_SIZEY 2
141 #define BUTTON_SPACINGX 3
142 #define BUTTON_SPACINGY 3
143 #define FLAT_BTN_SPACINGX 8
144 #define DEFAULT_MIN_TAB_WIDTH 54
145 #define DEFAULT_PADDING_X 6
146 #define EXTRA_ICON_PADDING 3
148 #define TAB_GetInfoPtr(hwnd) ((TAB_INFO *)GetWindowLongPtrW(hwnd,0))
149 /* Since items are variable sized, cannot directly access them */
150 #define TAB_GetItem(info,i) \
151 ((TAB_ITEM*)((LPBYTE)info->items + (i) * TAB_ITEM_SIZE(info)))
153 #define GET_DEFAULT_MIN_TAB_WIDTH(infoPtr) (DEFAULT_MIN_TAB_WIDTH - (DEFAULT_PADDING_X - (infoPtr)->uHItemPadding) * 2)
155 /******************************************************************************
156 * Hot-tracking timer constants
158 #define TAB_HOTTRACK_TIMER 1
159 #define TAB_HOTTRACK_TIMER_INTERVAL 100 /* milliseconds */
161 static const WCHAR themeClass
[] = { 'T','a','b',0 };
163 /******************************************************************************
166 static void TAB_InvalidateTabArea(const TAB_INFO
*);
167 static void TAB_EnsureSelectionVisible(TAB_INFO
*);
168 static void TAB_DrawItemInterior(const TAB_INFO
*, HDC
, INT
, RECT
*);
171 TAB_SendSimpleNotify (const TAB_INFO
*infoPtr
, UINT code
)
175 nmhdr
.hwndFrom
= infoPtr
->hwnd
;
176 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwnd
, GWLP_ID
);
179 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
180 nmhdr
.idFrom
, (LPARAM
) &nmhdr
);
184 TAB_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
185 WPARAM wParam
, LPARAM lParam
)
193 msg
.time
= GetMessageTime ();
194 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
195 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
197 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
201 TAB_DumpItemExternalT(const TCITEMW
*pti
, UINT iItem
, BOOL isW
)
204 TRACE("external tab %d, mask=0x%08x, dwState=0x%08x, dwStateMask=0x%08x, cchTextMax=0x%08x\n",
205 iItem
, pti
->mask
, pti
->dwState
, pti
->dwStateMask
, pti
->cchTextMax
);
206 TRACE("external tab %d, iImage=%d, lParam=0x%08lx, pszTextW=%s\n",
207 iItem
, pti
->iImage
, pti
->lParam
, isW
? debugstr_w(pti
->pszText
) : debugstr_a((LPSTR
)pti
->pszText
));
212 TAB_DumpItemInternal(const TAB_INFO
*infoPtr
, UINT iItem
)
217 ti
= TAB_GetItem(infoPtr
, iItem
);
218 TRACE("tab %d, dwState=0x%08x, pszText=%s, iImage=%d\n",
219 iItem
, ti
->dwState
, debugstr_w(ti
->pszText
), ti
->iImage
);
220 TRACE("tab %d, rect.left=%d, rect.top(row)=%d\n",
221 iItem
, ti
->rect
.left
, ti
->rect
.top
);
226 * the index of the selected tab, or -1 if no tab is selected. */
227 static inline LRESULT
TAB_GetCurSel (const TAB_INFO
*infoPtr
)
229 return infoPtr
->iSelected
;
233 * the index of the tab item that has the focus. */
234 static inline LRESULT
235 TAB_GetCurFocus (const TAB_INFO
*infoPtr
)
237 return infoPtr
->uFocus
;
240 static inline LRESULT
TAB_GetToolTips (const TAB_INFO
*infoPtr
)
242 if (infoPtr
== NULL
) return 0;
243 return (LRESULT
)infoPtr
->hwndToolTip
;
246 static inline LRESULT
TAB_SetCurSel (TAB_INFO
*infoPtr
, INT iItem
)
248 INT prevItem
= infoPtr
->iSelected
;
251 infoPtr
->iSelected
=-1;
252 else if (iItem
>= infoPtr
->uNumItem
)
255 if (infoPtr
->iSelected
!= iItem
) {
256 infoPtr
->iSelected
=iItem
;
257 infoPtr
->uFocus
=iItem
;
258 TAB_EnsureSelectionVisible(infoPtr
);
259 TAB_InvalidateTabArea(infoPtr
);
265 static LRESULT
TAB_SetCurFocus (TAB_INFO
*infoPtr
, INT iItem
)
268 infoPtr
->uFocus
= -1;
269 else if (iItem
< infoPtr
->uNumItem
) {
270 if (GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
) & TCS_BUTTONS
) {
271 FIXME("Should set input focus\n");
273 int oldFocus
= infoPtr
->uFocus
;
274 if (infoPtr
->iSelected
!= iItem
|| oldFocus
== -1 ) {
275 infoPtr
->uFocus
= iItem
;
276 if (oldFocus
!= -1) {
277 if (!TAB_SendSimpleNotify(infoPtr
, TCN_SELCHANGING
)) {
278 infoPtr
->iSelected
= iItem
;
279 TAB_SendSimpleNotify(infoPtr
, TCN_SELCHANGE
);
282 infoPtr
->iSelected
= iItem
;
283 TAB_EnsureSelectionVisible(infoPtr
);
284 TAB_InvalidateTabArea(infoPtr
);
292 static inline LRESULT
293 TAB_SetToolTips (TAB_INFO
*infoPtr
, HWND hwndToolTip
)
296 infoPtr
->hwndToolTip
= hwndToolTip
;
300 static inline LRESULT
301 TAB_SetPadding (TAB_INFO
*infoPtr
, LPARAM lParam
)
305 infoPtr
->uHItemPadding_s
=LOWORD(lParam
);
306 infoPtr
->uVItemPadding_s
=HIWORD(lParam
);
311 /******************************************************************************
312 * TAB_InternalGetItemRect
314 * This method will calculate the rectangle representing a given tab item in
315 * client coordinates. This method takes scrolling into account.
317 * This method returns TRUE if the item is visible in the window and FALSE
318 * if it is completely outside the client area.
320 static BOOL
TAB_InternalGetItemRect(
321 const TAB_INFO
* infoPtr
,
326 RECT tmpItemRect
,clientRect
;
327 LONG lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
329 /* Perform a sanity check and a trivial visibility check. */
330 if ( (infoPtr
->uNumItem
<= 0) ||
331 (itemIndex
>= infoPtr
->uNumItem
) ||
332 (!((lStyle
& TCS_MULTILINE
) || (lStyle
& TCS_VERTICAL
)) && (itemIndex
< infoPtr
->leftmostVisible
)) )
334 TRACE("Not Visible\n");
335 /* need to initialize these to empty rects */
338 memset(itemRect
,0,sizeof(RECT
));
339 itemRect
->bottom
= infoPtr
->tabHeight
;
342 memset(selectedRect
,0,sizeof(RECT
));
347 * Avoid special cases in this procedure by assigning the "out"
348 * parameters if the caller didn't supply them
350 if (itemRect
== NULL
)
351 itemRect
= &tmpItemRect
;
353 /* Retrieve the unmodified item rect. */
354 *itemRect
= TAB_GetItem(infoPtr
,itemIndex
)->rect
;
356 /* calculate the times bottom and top based on the row */
357 GetClientRect(infoPtr
->hwnd
, &clientRect
);
359 if ((lStyle
& TCS_BOTTOM
) && (lStyle
& TCS_VERTICAL
))
361 itemRect
->right
= clientRect
.right
- SELECTED_TAB_OFFSET
- itemRect
->left
* infoPtr
->tabHeight
-
362 ((lStyle
& TCS_BUTTONS
) ? itemRect
->left
* BUTTON_SPACINGX
: 0);
363 itemRect
->left
= itemRect
->right
- infoPtr
->tabHeight
;
365 else if (lStyle
& TCS_VERTICAL
)
367 itemRect
->left
= clientRect
.left
+ SELECTED_TAB_OFFSET
+ itemRect
->left
* infoPtr
->tabHeight
+
368 ((lStyle
& TCS_BUTTONS
) ? itemRect
->left
* BUTTON_SPACINGX
: 0);
369 itemRect
->right
= itemRect
->left
+ infoPtr
->tabHeight
;
371 else if (lStyle
& TCS_BOTTOM
)
373 itemRect
->bottom
= clientRect
.bottom
- itemRect
->top
* infoPtr
->tabHeight
-
374 ((lStyle
& TCS_BUTTONS
) ? itemRect
->top
* BUTTON_SPACINGY
: SELECTED_TAB_OFFSET
);
375 itemRect
->top
= itemRect
->bottom
- infoPtr
->tabHeight
;
377 else /* not TCS_BOTTOM and not TCS_VERTICAL */
379 itemRect
->top
= clientRect
.top
+ itemRect
->top
* infoPtr
->tabHeight
+
380 ((lStyle
& TCS_BUTTONS
) ? itemRect
->top
* BUTTON_SPACINGY
: SELECTED_TAB_OFFSET
);
381 itemRect
->bottom
= itemRect
->top
+ infoPtr
->tabHeight
;
385 * "scroll" it to make sure the item at the very left of the
386 * tab control is the leftmost visible tab.
388 if(lStyle
& TCS_VERTICAL
)
392 -TAB_GetItem(infoPtr
, infoPtr
->leftmostVisible
)->rect
.top
);
395 * Move the rectangle so the first item is slightly offset from
396 * the bottom of the tab control.
400 SELECTED_TAB_OFFSET
);
405 -TAB_GetItem(infoPtr
, infoPtr
->leftmostVisible
)->rect
.left
,
409 * Move the rectangle so the first item is slightly offset from
410 * the left of the tab control.
416 TRACE("item %d tab h=%d, rect=(%s)\n",
417 itemIndex
, infoPtr
->tabHeight
, wine_dbgstr_rect(itemRect
));
419 /* Now, calculate the position of the item as if it were selected. */
420 if (selectedRect
!=NULL
)
422 CopyRect(selectedRect
, itemRect
);
424 /* The rectangle of a selected item is a bit wider. */
425 if(lStyle
& TCS_VERTICAL
)
426 InflateRect(selectedRect
, 0, SELECTED_TAB_OFFSET
);
428 InflateRect(selectedRect
, SELECTED_TAB_OFFSET
, 0);
430 /* If it also a bit higher. */
431 if ((lStyle
& TCS_BOTTOM
) && (lStyle
& TCS_VERTICAL
))
433 selectedRect
->left
-= 2; /* the border is thicker on the right */
434 selectedRect
->right
+= SELECTED_TAB_OFFSET
;
436 else if (lStyle
& TCS_VERTICAL
)
438 selectedRect
->left
-= SELECTED_TAB_OFFSET
;
439 selectedRect
->right
+= 1;
441 else if (lStyle
& TCS_BOTTOM
)
443 selectedRect
->bottom
+= SELECTED_TAB_OFFSET
;
445 else /* not TCS_BOTTOM and not TCS_VERTICAL */
447 selectedRect
->top
-= SELECTED_TAB_OFFSET
;
448 selectedRect
->bottom
-= 1;
452 /* Check for visibility */
453 if (lStyle
& TCS_VERTICAL
)
454 return (itemRect
->top
< clientRect
.bottom
) && (itemRect
->bottom
> clientRect
.top
);
456 return (itemRect
->left
< clientRect
.right
) && (itemRect
->right
> clientRect
.left
);
460 TAB_GetItemRect(const TAB_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
462 return TAB_InternalGetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
, (LPRECT
)NULL
);
465 /******************************************************************************
468 * This method is called to handle keyboard input
470 static LRESULT
TAB_KeyUp(TAB_INFO
* infoPtr
, WPARAM keyCode
)
477 newItem
= infoPtr
->uFocus
- 1;
480 newItem
= infoPtr
->uFocus
+ 1;
485 * If we changed to a valid item, change the selection
488 newItem
< infoPtr
->uNumItem
&&
489 infoPtr
->uFocus
!= newItem
)
491 if (!TAB_SendSimpleNotify(infoPtr
, TCN_SELCHANGING
))
493 infoPtr
->iSelected
= newItem
;
494 infoPtr
->uFocus
= newItem
;
495 TAB_SendSimpleNotify(infoPtr
, TCN_SELCHANGE
);
497 TAB_EnsureSelectionVisible(infoPtr
);
498 TAB_InvalidateTabArea(infoPtr
);
505 /******************************************************************************
508 * This method is called whenever the focus goes in or out of this control
509 * it is used to update the visual state of the control.
511 static void TAB_FocusChanging(const TAB_INFO
*infoPtr
)
517 * Get the rectangle for the item.
519 isVisible
= TAB_InternalGetItemRect(infoPtr
,
525 * If the rectangle is not completely invisible, invalidate that
526 * portion of the window.
530 TRACE("invalidate (%s)\n", wine_dbgstr_rect(&selectedRect
));
531 InvalidateRect(infoPtr
->hwnd
, &selectedRect
, TRUE
);
535 static INT
TAB_InternalHitTest (const TAB_INFO
*infoPtr
, POINT pt
, UINT
*flags
)
540 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++)
542 TAB_InternalGetItemRect(infoPtr
, iCount
, &rect
, NULL
);
544 if (PtInRect(&rect
, pt
))
546 *flags
= TCHT_ONITEM
;
551 *flags
= TCHT_NOWHERE
;
555 static inline LRESULT
556 TAB_HitTest (const TAB_INFO
*infoPtr
, LPTCHITTESTINFO lptest
)
558 return TAB_InternalHitTest (infoPtr
, lptest
->pt
, &lptest
->flags
);
561 /******************************************************************************
564 * Napster v2b5 has a tab control for its main navigation which has a client
565 * area that covers the whole area of the dialog pages.
566 * That's why it receives all msgs for that area and the underlying dialog ctrls
568 * So I decided that we should handle WM_NCHITTEST here and return
569 * HTTRANSPARENT if we don't hit the tab control buttons.
570 * FIXME: WM_NCHITTEST handling correct ? Fix it if you know that Windows
571 * doesn't do it that way. Maybe depends on tab control styles ?
573 static inline LRESULT
574 TAB_NCHitTest (const TAB_INFO
*infoPtr
, LPARAM lParam
)
579 pt
.x
= (short)LOWORD(lParam
);
580 pt
.y
= (short)HIWORD(lParam
);
581 ScreenToClient(infoPtr
->hwnd
, &pt
);
583 if (TAB_InternalHitTest(infoPtr
, pt
, &dummyflag
) == -1)
584 return HTTRANSPARENT
;
590 TAB_LButtonDown (TAB_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
596 if (infoPtr
->hwndToolTip
)
597 TAB_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwnd
,
598 WM_LBUTTONDOWN
, wParam
, lParam
);
600 if (GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
) & TCS_FOCUSONBUTTONDOWN
) {
601 SetFocus (infoPtr
->hwnd
);
604 if (infoPtr
->hwndToolTip
)
605 TAB_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwnd
,
606 WM_LBUTTONDOWN
, wParam
, lParam
);
608 pt
.x
= (short)LOWORD(lParam
);
609 pt
.y
= (short)HIWORD(lParam
);
611 newItem
= TAB_InternalHitTest (infoPtr
, pt
, &dummy
);
613 TRACE("On Tab, item %d\n", newItem
);
615 if (newItem
!= -1 && infoPtr
->iSelected
!= newItem
)
617 if (!TAB_SendSimpleNotify(infoPtr
, TCN_SELCHANGING
))
619 infoPtr
->iSelected
= newItem
;
620 infoPtr
->uFocus
= newItem
;
621 TAB_SendSimpleNotify(infoPtr
, TCN_SELCHANGE
);
623 TAB_EnsureSelectionVisible(infoPtr
);
625 TAB_InvalidateTabArea(infoPtr
);
631 static inline LRESULT
632 TAB_LButtonUp (const TAB_INFO
*infoPtr
)
634 TAB_SendSimpleNotify(infoPtr
, NM_CLICK
);
639 static inline LRESULT
640 TAB_RButtonDown (const TAB_INFO
*infoPtr
)
642 TAB_SendSimpleNotify(infoPtr
, NM_RCLICK
);
646 /******************************************************************************
647 * TAB_DrawLoneItemInterior
649 * This calls TAB_DrawItemInterior. However, TAB_DrawItemInterior is normally
650 * called by TAB_DrawItem which is normally called by TAB_Refresh which sets
651 * up the device context and font. This routine does the same setup but
652 * only calls TAB_DrawItemInterior for the single specified item.
655 TAB_DrawLoneItemInterior(const TAB_INFO
* infoPtr
, int iItem
)
657 HDC hdc
= GetDC(infoPtr
->hwnd
);
660 /* Clip UpDown control to not draw over it */
661 if (infoPtr
->needsScrolling
)
663 GetWindowRect(infoPtr
->hwnd
, &rC
);
664 GetWindowRect(infoPtr
->hwndUpDown
, &r
);
665 ExcludeClipRect(hdc
, r
.left
- rC
.left
, r
.top
- rC
.top
, r
.right
- rC
.left
, r
.bottom
- rC
.top
);
667 TAB_DrawItemInterior(infoPtr
, hdc
, iItem
, NULL
);
668 ReleaseDC(infoPtr
->hwnd
, hdc
);
671 /* update a tab after hottracking - invalidate it or just redraw the interior,
672 * based on whether theming is used or not */
673 static inline void hottrack_refresh(const TAB_INFO
*infoPtr
, int tabIndex
)
675 if (tabIndex
== -1) return;
677 if (GetWindowTheme (infoPtr
->hwnd
))
680 TAB_InternalGetItemRect(infoPtr
, tabIndex
, &rect
, NULL
);
681 InvalidateRect (infoPtr
->hwnd
, &rect
, FALSE
);
684 TAB_DrawLoneItemInterior(infoPtr
, tabIndex
);
687 /******************************************************************************
688 * TAB_HotTrackTimerProc
690 * When a mouse-move event causes a tab to be highlighted (hot-tracking), a
691 * timer is setup so we can check if the mouse is moved out of our window.
692 * (We don't get an event when the mouse leaves, the mouse-move events just
693 * stop being delivered to our window and just start being delivered to
694 * another window.) This function is called when the timer triggers so
695 * we can check if the mouse has left our window. If so, we un-highlight
696 * the hot-tracked tab.
699 TAB_HotTrackTimerProc
701 HWND hwnd
, /* handle of window for timer messages */
702 UINT uMsg
, /* WM_TIMER message */
703 UINT_PTR idEvent
, /* timer identifier */
704 DWORD dwTime
/* current system time */
707 TAB_INFO
* infoPtr
= TAB_GetInfoPtr(hwnd
);
709 if (infoPtr
!= NULL
&& infoPtr
->iHotTracked
>= 0)
714 ** If we can't get the cursor position, or if the cursor is outside our
715 ** window, we un-highlight the hot-tracked tab. Note that the cursor is
716 ** "outside" even if it is within our bounding rect if another window
717 ** overlaps. Note also that the case where the cursor stayed within our
718 ** window but has moved off the hot-tracked tab will be handled by the
719 ** WM_MOUSEMOVE event.
721 if (!GetCursorPos(&pt
) || WindowFromPoint(pt
) != hwnd
)
723 /* Redraw iHotTracked to look normal */
724 INT iRedraw
= infoPtr
->iHotTracked
;
725 infoPtr
->iHotTracked
= -1;
726 hottrack_refresh (infoPtr
, iRedraw
);
728 /* Kill this timer */
729 KillTimer(hwnd
, TAB_HOTTRACK_TIMER
);
734 /******************************************************************************
737 * If a tab control has the TCS_HOTTRACK style, then the tab under the mouse
738 * should be highlighted. This function determines which tab in a tab control,
739 * if any, is under the mouse and records that information. The caller may
740 * supply output parameters to receive the item number of the tab item which
741 * was highlighted but isn't any longer and of the tab item which is now
742 * highlighted but wasn't previously. The caller can use this information to
743 * selectively redraw those tab items.
745 * If the caller has a mouse position, it can supply it through the pos
746 * parameter. For example, TAB_MouseMove does this. Otherwise, the caller
747 * supplies NULL and this function determines the current mouse position
755 int* out_redrawLeave
,
762 if (out_redrawLeave
!= NULL
)
763 *out_redrawLeave
= -1;
764 if (out_redrawEnter
!= NULL
)
765 *out_redrawEnter
= -1;
767 if ((GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
) & TCS_HOTTRACK
)
768 || GetWindowTheme (infoPtr
->hwnd
))
776 ScreenToClient(infoPtr
->hwnd
, &pt
);
780 pt
.x
= (short)LOWORD(*pos
);
781 pt
.y
= (short)HIWORD(*pos
);
784 item
= TAB_InternalHitTest(infoPtr
, pt
, &flags
);
787 if (item
!= infoPtr
->iHotTracked
)
789 if (infoPtr
->iHotTracked
>= 0)
791 /* Mark currently hot-tracked to be redrawn to look normal */
792 if (out_redrawLeave
!= NULL
)
793 *out_redrawLeave
= infoPtr
->iHotTracked
;
797 /* Kill timer which forces recheck of mouse pos */
798 KillTimer(infoPtr
->hwnd
, TAB_HOTTRACK_TIMER
);
803 /* Start timer so we recheck mouse pos */
804 UINT timerID
= SetTimer
808 TAB_HOTTRACK_TIMER_INTERVAL
,
809 TAB_HotTrackTimerProc
813 return; /* Hot tracking not available */
816 infoPtr
->iHotTracked
= item
;
820 /* Mark new hot-tracked to be redrawn to look highlighted */
821 if (out_redrawEnter
!= NULL
)
822 *out_redrawEnter
= item
;
827 /******************************************************************************
830 * Handles the mouse-move event. Updates tooltips. Updates hot-tracking.
833 TAB_MouseMove (TAB_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
838 if (infoPtr
->hwndToolTip
)
839 TAB_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwnd
,
840 WM_LBUTTONDOWN
, wParam
, lParam
);
842 /* Determine which tab to highlight. Redraw tabs which change highlight
844 TAB_RecalcHotTrack(infoPtr
, &lParam
, &redrawLeave
, &redrawEnter
);
846 hottrack_refresh (infoPtr
, redrawLeave
);
847 hottrack_refresh (infoPtr
, redrawEnter
);
852 /******************************************************************************
855 * Calculates the tab control's display area given the window rectangle or
856 * the window rectangle given the requested display rectangle.
858 static LRESULT
TAB_AdjustRect(const TAB_INFO
*infoPtr
, WPARAM fLarger
, LPRECT prc
)
860 DWORD lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
861 LONG
*iRightBottom
, *iLeftTop
;
863 TRACE ("hwnd=%p fLarger=%ld (%s)\n", infoPtr
->hwnd
, fLarger
,
864 wine_dbgstr_rect(prc
));
866 if(lStyle
& TCS_VERTICAL
)
868 iRightBottom
= &(prc
->right
);
869 iLeftTop
= &(prc
->left
);
873 iRightBottom
= &(prc
->bottom
);
874 iLeftTop
= &(prc
->top
);
877 if (fLarger
) /* Go from display rectangle */
879 /* Add the height of the tabs. */
880 if (lStyle
& TCS_BOTTOM
)
881 *iRightBottom
+= infoPtr
->tabHeight
* infoPtr
->uNumRows
;
883 *iLeftTop
-= infoPtr
->tabHeight
* infoPtr
->uNumRows
+
884 ((lStyle
& TCS_BUTTONS
)? 3 * (infoPtr
->uNumRows
- 1) : 0);
886 /* Inflate the rectangle for the padding */
887 InflateRect(prc
, DISPLAY_AREA_PADDINGX
, DISPLAY_AREA_PADDINGY
);
889 /* Inflate for the border */
890 InflateRect(prc
, CONTROL_BORDER_SIZEX
, CONTROL_BORDER_SIZEY
);
892 else /* Go from window rectangle. */
894 /* Deflate the rectangle for the border */
895 InflateRect(prc
, -CONTROL_BORDER_SIZEX
, -CONTROL_BORDER_SIZEY
);
897 /* Deflate the rectangle for the padding */
898 InflateRect(prc
, -DISPLAY_AREA_PADDINGX
, -DISPLAY_AREA_PADDINGY
);
900 /* Remove the height of the tabs. */
901 if (lStyle
& TCS_BOTTOM
)
902 *iRightBottom
-= infoPtr
->tabHeight
* infoPtr
->uNumRows
;
904 *iLeftTop
+= (infoPtr
->tabHeight
) * infoPtr
->uNumRows
+
905 ((lStyle
& TCS_BUTTONS
)? 3 * (infoPtr
->uNumRows
- 1) : 0);
911 /******************************************************************************
914 * This method will handle the notification from the scroll control and
915 * perform the scrolling operation on the tab control.
917 static LRESULT
TAB_OnHScroll(TAB_INFO
*infoPtr
, int nScrollCode
, int nPos
, HWND hwndScroll
)
919 if(nScrollCode
== SB_THUMBPOSITION
&& nPos
!= infoPtr
->leftmostVisible
)
921 if(nPos
< infoPtr
->leftmostVisible
)
922 infoPtr
->leftmostVisible
--;
924 infoPtr
->leftmostVisible
++;
926 TAB_RecalcHotTrack(infoPtr
, NULL
, NULL
, NULL
);
927 TAB_InvalidateTabArea(infoPtr
);
928 SendMessageW(infoPtr
->hwndUpDown
, UDM_SETPOS
, 0,
929 MAKELONG(infoPtr
->leftmostVisible
, 0));
935 /******************************************************************************
938 * This method will check the current scrolling state and make sure the
939 * scrolling control is displayed (or not).
941 static void TAB_SetupScrolling(
944 const RECT
* clientRect
)
946 static const WCHAR msctls_updown32W
[] = { 'm','s','c','t','l','s','_','u','p','d','o','w','n','3','2',0 };
947 static const WCHAR emptyW
[] = { 0 };
949 DWORD lStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
951 if (infoPtr
->needsScrolling
)
957 * Calculate the position of the scroll control.
959 if(lStyle
& TCS_VERTICAL
)
961 controlPos
.right
= clientRect
->right
;
962 controlPos
.left
= controlPos
.right
- 2 * GetSystemMetrics(SM_CXHSCROLL
);
964 if (lStyle
& TCS_BOTTOM
)
966 controlPos
.top
= clientRect
->bottom
- infoPtr
->tabHeight
;
967 controlPos
.bottom
= controlPos
.top
+ GetSystemMetrics(SM_CYHSCROLL
);
971 controlPos
.bottom
= clientRect
->top
+ infoPtr
->tabHeight
;
972 controlPos
.top
= controlPos
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
977 controlPos
.right
= clientRect
->right
;
978 controlPos
.left
= controlPos
.right
- 2 * GetSystemMetrics(SM_CXHSCROLL
);
980 if (lStyle
& TCS_BOTTOM
)
982 controlPos
.top
= clientRect
->bottom
- infoPtr
->tabHeight
;
983 controlPos
.bottom
= controlPos
.top
+ GetSystemMetrics(SM_CYHSCROLL
);
987 controlPos
.bottom
= clientRect
->top
+ infoPtr
->tabHeight
;
988 controlPos
.top
= controlPos
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
993 * If we don't have a scroll control yet, we want to create one.
994 * If we have one, we want to make sure it's positioned properly.
996 if (infoPtr
->hwndUpDown
==0)
998 infoPtr
->hwndUpDown
= CreateWindowW(msctls_updown32W
, emptyW
,
999 WS_VISIBLE
| WS_CHILD
| UDS_HORZ
,
1000 controlPos
.left
, controlPos
.top
,
1001 controlPos
.right
- controlPos
.left
,
1002 controlPos
.bottom
- controlPos
.top
,
1003 hwnd
, NULL
, NULL
, NULL
);
1007 SetWindowPos(infoPtr
->hwndUpDown
,
1009 controlPos
.left
, controlPos
.top
,
1010 controlPos
.right
- controlPos
.left
,
1011 controlPos
.bottom
- controlPos
.top
,
1012 SWP_SHOWWINDOW
| SWP_NOZORDER
);
1015 /* Now calculate upper limit of the updown control range.
1016 * We do this by calculating how many tabs will be offscreen when the
1017 * last tab is visible.
1019 if(infoPtr
->uNumItem
)
1021 vsize
= clientRect
->right
- (controlPos
.right
- controlPos
.left
+ 1);
1022 maxRange
= infoPtr
->uNumItem
;
1023 tabwidth
= TAB_GetItem(infoPtr
, infoPtr
->uNumItem
- 1)->rect
.right
;
1025 for(; maxRange
> 0; maxRange
--)
1027 if(tabwidth
- TAB_GetItem(infoPtr
,maxRange
- 1)->rect
.left
> vsize
)
1031 if(maxRange
== infoPtr
->uNumItem
)
1037 /* If we once had a scroll control... hide it */
1038 if (infoPtr
->hwndUpDown
!=0)
1039 ShowWindow(infoPtr
->hwndUpDown
, SW_HIDE
);
1041 if (infoPtr
->hwndUpDown
)
1042 SendMessageW(infoPtr
->hwndUpDown
, UDM_SETRANGE32
, 0, maxRange
);
1045 /******************************************************************************
1048 * This method will calculate the position rectangles of all the items in the
1049 * control. The rectangle calculated starts at 0 for the first item in the
1050 * list and ignores scrolling and selection.
1051 * It also uses the current font to determine the height of the tab row and
1052 * it checks if all the tabs fit in the client area of the window. If they
1053 * don't, a scrolling control is added.
1055 static void TAB_SetItemBounds (TAB_INFO
*infoPtr
)
1057 LONG lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
1058 TEXTMETRICW fontMetrics
;
1061 INT curItemRowCount
;
1062 HFONT hFont
, hOldFont
;
1071 * We need to get text information so we need a DC and we need to select
1074 hdc
= GetDC(infoPtr
->hwnd
);
1076 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
1077 hOldFont
= SelectObject (hdc
, hFont
);
1080 * We will base the rectangle calculations on the client rectangle
1083 GetClientRect(infoPtr
->hwnd
, &clientRect
);
1085 /* if TCS_VERTICAL then swap the height and width so this code places the
1086 tabs along the top of the rectangle and we can just rotate them after
1087 rather than duplicate all of the below code */
1088 if(lStyle
& TCS_VERTICAL
)
1090 iTemp
= clientRect
.bottom
;
1091 clientRect
.bottom
= clientRect
.right
;
1092 clientRect
.right
= iTemp
;
1095 /* Now use hPadding and vPadding */
1096 infoPtr
->uHItemPadding
= infoPtr
->uHItemPadding_s
;
1097 infoPtr
->uVItemPadding
= infoPtr
->uVItemPadding_s
;
1099 /* The leftmost item will be "0" aligned */
1101 curItemRowCount
= infoPtr
->uNumItem
? 1 : 0;
1103 if (!(infoPtr
->fHeightSet
))
1106 int icon_height
= 0;
1108 /* Use the current font to determine the height of a tab. */
1109 GetTextMetricsW(hdc
, &fontMetrics
);
1111 /* Get the icon height */
1113 ImageList_GetIconSize(infoPtr
->himl
, 0, &icon_height
);
1115 /* Take the highest between font or icon */
1116 if (fontMetrics
.tmHeight
> icon_height
)
1117 item_height
= fontMetrics
.tmHeight
+ 2;
1119 item_height
= icon_height
;
1122 * Make sure there is enough space for the letters + icon + growing the
1123 * selected item + extra space for the selected item.
1125 infoPtr
->tabHeight
= item_height
+
1126 ((lStyle
& TCS_BUTTONS
) ? 2 : 1) *
1127 infoPtr
->uVItemPadding
;
1129 TRACE("tabH=%d, tmH=%d, iconh=%d\n",
1130 infoPtr
->tabHeight
, fontMetrics
.tmHeight
, icon_height
);
1133 TRACE("client right=%d\n", clientRect
.right
);
1135 /* Get the icon width */
1138 ImageList_GetIconSize(infoPtr
->himl
, &icon_width
, 0);
1140 if (lStyle
& TCS_FIXEDWIDTH
)
1143 /* Add padding if icon is present */
1144 icon_width
+= infoPtr
->uHItemPadding
;
1147 for (curItem
= 0; curItem
< infoPtr
->uNumItem
; curItem
++)
1149 TAB_ITEM
*curr
= TAB_GetItem(infoPtr
, curItem
);
1151 /* Set the leftmost position of the tab. */
1152 curr
->rect
.left
= curItemLeftPos
;
1154 if (lStyle
& TCS_FIXEDWIDTH
)
1156 curr
->rect
.right
= curr
->rect
.left
+
1157 max(infoPtr
->tabWidth
, icon_width
);
1159 else if (!curr
->pszText
)
1161 /* If no text use minimum tab width including padding. */
1162 if (infoPtr
->tabMinWidth
< 0)
1163 curr
->rect
.right
= curr
->rect
.left
+ GET_DEFAULT_MIN_TAB_WIDTH(infoPtr
);
1166 curr
->rect
.right
= curr
->rect
.left
+ infoPtr
->tabMinWidth
;
1168 /* Add extra padding if icon is present */
1169 if (infoPtr
->himl
&& infoPtr
->tabMinWidth
> 0 && infoPtr
->tabMinWidth
< DEFAULT_MIN_TAB_WIDTH
1170 && infoPtr
->uHItemPadding
> 1)
1171 curr
->rect
.right
+= EXTRA_ICON_PADDING
* (infoPtr
->uHItemPadding
-1);
1178 /* Calculate how wide the tab is depending on the text it contains */
1179 GetTextExtentPoint32W(hdc
, curr
->pszText
,
1180 lstrlenW(curr
->pszText
), &size
);
1182 tabwidth
= size
.cx
+ icon_width
+ 2 * infoPtr
->uHItemPadding
;
1184 if (infoPtr
->tabMinWidth
< 0)
1185 tabwidth
= max(tabwidth
, GET_DEFAULT_MIN_TAB_WIDTH(infoPtr
));
1187 tabwidth
= max(tabwidth
, infoPtr
->tabMinWidth
);
1189 curr
->rect
.right
= curr
->rect
.left
+ tabwidth
;
1190 TRACE("for <%s>, l,r=%d,%d\n",
1191 debugstr_w(curr
->pszText
), curr
->rect
.left
, curr
->rect
.right
);
1195 * Check if this is a multiline tab control and if so
1196 * check to see if we should wrap the tabs
1198 * Wrap all these tabs. We will arrange them evenly later.
1202 if (((lStyle
& TCS_MULTILINE
) || (lStyle
& TCS_VERTICAL
)) &&
1204 (clientRect
.right
- CONTROL_BORDER_SIZEX
- DISPLAY_AREA_PADDINGX
)))
1206 curr
->rect
.right
-= curr
->rect
.left
;
1208 curr
->rect
.left
= 0;
1210 TRACE("wrapping <%s>, l,r=%d,%d\n", debugstr_w(curr
->pszText
),
1211 curr
->rect
.left
, curr
->rect
.right
);
1214 curr
->rect
.bottom
= 0;
1215 curr
->rect
.top
= curItemRowCount
- 1;
1217 TRACE("Rect: %s\n", wine_dbgstr_rect(&curr
->rect
));
1220 * The leftmost position of the next item is the rightmost position
1223 if (lStyle
& TCS_BUTTONS
)
1225 curItemLeftPos
= curr
->rect
.right
+ BUTTON_SPACINGX
;
1226 if (lStyle
& TCS_FLATBUTTONS
)
1227 curItemLeftPos
+= FLAT_BTN_SPACINGX
;
1230 curItemLeftPos
= curr
->rect
.right
;
1233 if (!((lStyle
& TCS_MULTILINE
) || (lStyle
& TCS_VERTICAL
)))
1236 * Check if we need a scrolling control.
1238 infoPtr
->needsScrolling
= (curItemLeftPos
+ (2 * SELECTED_TAB_OFFSET
) >
1241 /* Don't need scrolling, then update infoPtr->leftmostVisible */
1242 if(!infoPtr
->needsScrolling
)
1243 infoPtr
->leftmostVisible
= 0;
1248 * No scrolling in Multiline or Vertical styles.
1250 infoPtr
->needsScrolling
= FALSE
;
1251 infoPtr
->leftmostVisible
= 0;
1253 TAB_SetupScrolling(infoPtr
->hwnd
, infoPtr
, &clientRect
);
1255 /* Set the number of rows */
1256 infoPtr
->uNumRows
= curItemRowCount
;
1258 /* Arrange all tabs evenly if style says so */
1259 if (!(lStyle
& TCS_RAGGEDRIGHT
) &&
1260 ((lStyle
& TCS_MULTILINE
) || (lStyle
& TCS_VERTICAL
)) &&
1261 (infoPtr
->uNumItem
> 0) &&
1262 (infoPtr
->uNumRows
> 1))
1264 INT tabPerRow
,remTab
,iRow
;
1269 * Ok windows tries to even out the rows. place the same
1270 * number of tabs in each row. So lets give that a shot
1273 tabPerRow
= infoPtr
->uNumItem
/ (infoPtr
->uNumRows
);
1274 remTab
= infoPtr
->uNumItem
% (infoPtr
->uNumRows
);
1276 for (iItm
=0,iRow
=0,iCount
=0,curItemLeftPos
=0;
1277 iItm
<infoPtr
->uNumItem
;
1280 /* normalize the current rect */
1281 TAB_ITEM
*curr
= TAB_GetItem(infoPtr
, iItm
);
1283 /* shift the item to the left side of the clientRect */
1284 curr
->rect
.right
-= curr
->rect
.left
;
1285 curr
->rect
.left
= 0;
1287 TRACE("r=%d, cl=%d, cl.r=%d, iCount=%d, iRow=%d, uNumRows=%d, remTab=%d, tabPerRow=%d\n",
1288 curr
->rect
.right
, curItemLeftPos
, clientRect
.right
,
1289 iCount
, iRow
, infoPtr
->uNumRows
, remTab
, tabPerRow
);
1291 /* if we have reached the maximum number of tabs on this row */
1292 /* move to the next row, reset our current item left position and */
1293 /* the count of items on this row */
1295 if (lStyle
& TCS_VERTICAL
) {
1296 /* Vert: Add the remaining tabs in the *last* remainder rows */
1297 if (iCount
>= ((iRow
>=(INT
)infoPtr
->uNumRows
- remTab
)?tabPerRow
+ 1:tabPerRow
)) {
1303 /* Horz: Add the remaining tabs in the *first* remainder rows */
1304 if (iCount
>= ((iRow
<remTab
)?tabPerRow
+ 1:tabPerRow
)) {
1311 /* shift the item to the right to place it as the next item in this row */
1312 curr
->rect
.left
+= curItemLeftPos
;
1313 curr
->rect
.right
+= curItemLeftPos
;
1314 curr
->rect
.top
= iRow
;
1315 if (lStyle
& TCS_BUTTONS
)
1317 curItemLeftPos
= curr
->rect
.right
+ 1;
1318 if (lStyle
& TCS_FLATBUTTONS
)
1319 curItemLeftPos
+= FLAT_BTN_SPACINGX
;
1322 curItemLeftPos
= curr
->rect
.right
;
1324 TRACE("arranging <%s>, l,r=%d,%d, row=%d\n",
1325 debugstr_w(curr
->pszText
), curr
->rect
.left
,
1326 curr
->rect
.right
, curr
->rect
.top
);
1333 INT widthDiff
, iIndexStart
=0, iIndexEnd
=0;
1337 while(iIndexStart
< infoPtr
->uNumItem
)
1339 TAB_ITEM
*start
= TAB_GetItem(infoPtr
, iIndexStart
);
1342 * find the index of the row
1344 /* find the first item on the next row */
1345 for (iIndexEnd
=iIndexStart
;
1346 (iIndexEnd
< infoPtr
->uNumItem
) &&
1347 (TAB_GetItem(infoPtr
, iIndexEnd
)->rect
.top
==
1350 /* intentionally blank */;
1353 * we need to justify these tabs so they fill the whole given
1357 /* find the amount of space remaining on this row */
1358 widthDiff
= clientRect
.right
- (2 * SELECTED_TAB_OFFSET
) -
1359 TAB_GetItem(infoPtr
, iIndexEnd
- 1)->rect
.right
;
1361 /* iCount is the number of tab items on this row */
1362 iCount
= iIndexEnd
- iIndexStart
;
1366 remainder
= widthDiff
% iCount
;
1367 widthDiff
= widthDiff
/ iCount
;
1368 /* add widthDiff/iCount, or extra space/items on row, to each item on this row */
1369 for (iIndex
=iIndexStart
, iCount
=0; iIndex
< iIndexEnd
; iIndex
++, iCount
++)
1371 TAB_ITEM
*item
= TAB_GetItem(infoPtr
, iIndex
);
1373 item
->rect
.left
+= iCount
* widthDiff
;
1374 item
->rect
.right
+= (iCount
+ 1) * widthDiff
;
1376 TRACE("adjusting 1 <%s>, l,r=%d,%d\n",
1377 debugstr_w(item
->pszText
),
1378 item
->rect
.left
, item
->rect
.right
);
1381 TAB_GetItem(infoPtr
, iIndex
- 1)->rect
.right
+= remainder
;
1383 else /* we have only one item on this row, make it take up the entire row */
1385 start
->rect
.left
= clientRect
.left
;
1386 start
->rect
.right
= clientRect
.right
- 4;
1388 TRACE("adjusting 2 <%s>, l,r=%d,%d\n",
1389 debugstr_w(start
->pszText
),
1390 start
->rect
.left
, start
->rect
.right
);
1395 iIndexStart
= iIndexEnd
;
1400 /* if TCS_VERTICAL rotate the tabs so they are along the side of the clientRect */
1401 if(lStyle
& TCS_VERTICAL
)
1404 for(iIndex
= 0; iIndex
< infoPtr
->uNumItem
; iIndex
++)
1406 rcItem
= &TAB_GetItem(infoPtr
, iIndex
)->rect
;
1408 rcOriginal
= *rcItem
;
1410 /* this is rotating the items by 90 degrees clockwise around the center of the control */
1411 rcItem
->top
= (rcOriginal
.left
- clientRect
.left
);
1412 rcItem
->bottom
= rcItem
->top
+ (rcOriginal
.right
- rcOriginal
.left
);
1413 rcItem
->left
= rcOriginal
.top
;
1414 rcItem
->right
= rcOriginal
.bottom
;
1418 TAB_EnsureSelectionVisible(infoPtr
);
1419 TAB_RecalcHotTrack(infoPtr
, NULL
, NULL
, NULL
);
1422 SelectObject (hdc
, hOldFont
);
1423 ReleaseDC (infoPtr
->hwnd
, hdc
);
1428 TAB_EraseTabInterior(const TAB_INFO
*infoPtr
, HDC hdc
, INT iItem
, RECT
*drawRect
)
1430 LONG lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
1431 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrBtnFace
);
1432 BOOL deleteBrush
= TRUE
;
1433 RECT rTemp
= *drawRect
;
1435 InflateRect(&rTemp
, -2, -2);
1436 if (lStyle
& TCS_BUTTONS
)
1438 if (iItem
== infoPtr
->iSelected
)
1440 /* Background color */
1441 if (!(lStyle
& TCS_OWNERDRAWFIXED
))
1444 hbr
= GetSysColorBrush(COLOR_SCROLLBAR
);
1446 SetTextColor(hdc
, comctl32_color
.clr3dFace
);
1447 SetBkColor(hdc
, comctl32_color
.clr3dHilight
);
1449 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1450 * we better use 0x55aa bitmap brush to make scrollbar's background
1451 * look different from the window background.
1453 if (comctl32_color
.clr3dHilight
== comctl32_color
.clrWindow
)
1454 hbr
= COMCTL32_hPattern55AABrush
;
1456 deleteBrush
= FALSE
;
1458 FillRect(hdc
, &rTemp
, hbr
);
1460 else /* ! selected */
1462 if (lStyle
& TCS_FLATBUTTONS
)
1464 FillRect(hdc
, drawRect
, hbr
);
1465 if (iItem
== infoPtr
->iHotTracked
)
1466 DrawEdge(hdc
, drawRect
, EDGE_RAISED
, BF_SOFT
|BF_RECT
);
1469 FillRect(hdc
, &rTemp
, hbr
);
1473 else /* !TCS_BUTTONS */
1475 if (!GetWindowTheme (infoPtr
->hwnd
))
1476 FillRect(hdc
, &rTemp
, hbr
);
1480 if (deleteBrush
) DeleteObject(hbr
);
1483 /******************************************************************************
1484 * TAB_DrawItemInterior
1486 * This method is used to draw the interior (text and icon) of a single tab
1487 * into the tab control.
1490 TAB_DrawItemInterior(const TAB_INFO
*infoPtr
, HDC hdc
, INT iItem
, RECT
*drawRect
)
1492 LONG lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
1501 /* if (drawRect == NULL) */
1508 * Get the rectangle for the item.
1510 isVisible
= TAB_InternalGetItemRect(infoPtr
, iItem
, &itemRect
, &selectedRect
);
1515 * Make sure drawRect points to something valid; simplifies code.
1517 drawRect
= &localRect
;
1520 * This logic copied from the part of TAB_DrawItem which draws
1521 * the tab background. It's important to keep it in sync. I
1522 * would have liked to avoid code duplication, but couldn't figure
1523 * out how without making spaghetti of TAB_DrawItem.
1525 if (iItem
== infoPtr
->iSelected
)
1526 *drawRect
= selectedRect
;
1528 *drawRect
= itemRect
;
1530 if (lStyle
& TCS_BUTTONS
)
1532 if (iItem
== infoPtr
->iSelected
)
1534 drawRect
->left
+= 4;
1536 drawRect
->right
-= 4;
1537 drawRect
->bottom
-= 1;
1541 drawRect
->left
+= 2;
1543 drawRect
->right
-= 2;
1544 drawRect
->bottom
-= 2;
1549 if ((lStyle
& TCS_VERTICAL
) && (lStyle
& TCS_BOTTOM
))
1551 if (iItem
!= infoPtr
->iSelected
)
1553 drawRect
->left
+= 2;
1555 drawRect
->bottom
-= 2;
1558 else if (lStyle
& TCS_VERTICAL
)
1560 if (iItem
== infoPtr
->iSelected
)
1562 drawRect
->right
+= 1;
1567 drawRect
->right
-= 2;
1568 drawRect
->bottom
-= 2;
1571 else if (lStyle
& TCS_BOTTOM
)
1573 if (iItem
== infoPtr
->iSelected
)
1579 InflateRect(drawRect
, -2, -2);
1580 drawRect
->bottom
+= 2;
1585 if (iItem
== infoPtr
->iSelected
)
1587 drawRect
->bottom
+= 3;
1591 drawRect
->bottom
-= 2;
1592 InflateRect(drawRect
, -2, 0);
1597 TRACE("drawRect=(%s)\n", wine_dbgstr_rect(drawRect
));
1599 /* Clear interior */
1600 TAB_EraseTabInterior (infoPtr
, hdc
, iItem
, drawRect
);
1602 /* Draw the focus rectangle */
1603 if (!(lStyle
& TCS_FOCUSNEVER
) &&
1604 (GetFocus() == infoPtr
->hwnd
) &&
1605 (iItem
== infoPtr
->uFocus
) )
1607 RECT rFocus
= *drawRect
;
1608 InflateRect(&rFocus
, -3, -3);
1609 if (lStyle
& TCS_BOTTOM
&& !(lStyle
& TCS_VERTICAL
))
1611 if (lStyle
& TCS_BUTTONS
)
1617 DrawFocusRect(hdc
, &rFocus
);
1623 htextPen
= CreatePen( PS_SOLID
, 1, GetSysColor(COLOR_BTNTEXT
) );
1624 holdPen
= SelectObject(hdc
, htextPen
);
1625 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1628 * Setup for text output
1630 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1631 if (!GetWindowTheme (infoPtr
->hwnd
) || (lStyle
& TCS_BUTTONS
))
1632 SetTextColor(hdc
, (((lStyle
& TCS_HOTTRACK
) && (iItem
== infoPtr
->iHotTracked
)
1633 && !(lStyle
& TCS_FLATBUTTONS
))
1634 | (TAB_GetItem(infoPtr
, iItem
)->dwState
& TCIS_HIGHLIGHTED
)) ?
1635 comctl32_color
.clrHighlight
: comctl32_color
.clrBtnText
);
1638 * if owner draw, tell the owner to draw
1640 if ((lStyle
& TCS_OWNERDRAWFIXED
) && GetParent(infoPtr
->hwnd
))
1646 drawRect
->right
-= 1;
1647 if ( iItem
== infoPtr
->iSelected
)
1649 drawRect
->right
-= 1;
1650 drawRect
->left
+= 1;
1654 * get the control id
1656 id
= (UINT
)GetWindowLongPtrW( infoPtr
->hwnd
, GWLP_ID
);
1659 * put together the DRAWITEMSTRUCT
1661 dis
.CtlType
= ODT_TAB
;
1664 dis
.itemAction
= ODA_DRAWENTIRE
;
1666 if ( iItem
== infoPtr
->iSelected
)
1667 dis
.itemState
|= ODS_SELECTED
;
1668 if (infoPtr
->uFocus
== iItem
)
1669 dis
.itemState
|= ODS_FOCUS
;
1670 dis
.hwndItem
= infoPtr
->hwnd
;
1672 CopyRect(&dis
.rcItem
,drawRect
);
1673 dis
.itemData
= (ULONG_PTR
)TAB_GetItem(infoPtr
, iItem
)->extra
;
1676 * send the draw message
1678 SendMessageW( infoPtr
->hwndNotify
, WM_DRAWITEM
, (WPARAM
)id
, (LPARAM
)&dis
);
1682 TAB_ITEM
*item
= TAB_GetItem(infoPtr
, iItem
);
1686 /* used to center the icon and text in the tab */
1688 INT center_offset_h
, center_offset_v
;
1690 /* set rcImage to drawRect, we will use top & left in our ImageList_Draw call */
1691 rcImage
= *drawRect
;
1695 rcText
.left
= rcText
.top
= rcText
.right
= rcText
.bottom
= 0;
1697 /* get the rectangle that the text fits in */
1700 DrawTextW(hdc
, item
->pszText
, -1, &rcText
, DT_CALCRECT
);
1703 * If not owner draw, then do the drawing ourselves.
1707 if (infoPtr
->himl
&& item
->iImage
!= -1)
1712 ImageList_GetIconSize(infoPtr
->himl
, &cx
, &cy
);
1714 if(lStyle
& TCS_VERTICAL
)
1716 center_offset_h
= ((drawRect
->bottom
- drawRect
->top
) - (cy
+ infoPtr
->uHItemPadding
+ (rcText
.right
- rcText
.left
))) / 2;
1717 center_offset_v
= ((drawRect
->right
- drawRect
->left
) - cx
) / 2;
1721 center_offset_h
= ((drawRect
->right
- drawRect
->left
) - (cx
+ infoPtr
->uHItemPadding
+ (rcText
.right
- rcText
.left
))) / 2;
1722 center_offset_v
= ((drawRect
->bottom
- drawRect
->top
) - cy
) / 2;
1725 /* if an item is selected, the icon is shifted up instead of down */
1726 if (iItem
== infoPtr
->iSelected
)
1727 center_offset_v
-= infoPtr
->uVItemPadding
/ 2;
1729 center_offset_v
+= infoPtr
->uVItemPadding
/ 2;
1731 if (lStyle
& TCS_FIXEDWIDTH
&& lStyle
& (TCS_FORCELABELLEFT
| TCS_FORCEICONLEFT
))
1732 center_offset_h
= infoPtr
->uHItemPadding
;
1734 if (center_offset_h
< 2)
1735 center_offset_h
= 2;
1737 if (center_offset_v
< 0)
1738 center_offset_v
= 0;
1740 TRACE("for <%s>, c_o_h=%d, c_o_v=%d, draw=(%s), textlen=%d\n",
1741 debugstr_w(item
->pszText
), center_offset_h
, center_offset_v
,
1742 wine_dbgstr_rect(drawRect
), (rcText
.right
-rcText
.left
));
1744 if((lStyle
& TCS_VERTICAL
) && (lStyle
& TCS_BOTTOM
))
1746 rcImage
.top
= drawRect
->top
+ center_offset_h
;
1747 /* if tab is TCS_VERTICAL and TCS_BOTTOM, the text is drawn from the */
1748 /* right side of the tab, but the image still uses the left as its x position */
1749 /* this keeps the image always drawn off of the same side of the tab */
1750 rcImage
.left
= drawRect
->right
- cx
- center_offset_v
;
1751 drawRect
->top
+= cy
+ infoPtr
->uHItemPadding
;
1753 else if(lStyle
& TCS_VERTICAL
)
1755 rcImage
.top
= drawRect
->bottom
- cy
- center_offset_h
;
1756 rcImage
.left
= drawRect
->left
+ center_offset_v
;
1757 drawRect
->bottom
-= cy
+ infoPtr
->uHItemPadding
;
1759 else /* normal style, whether TCS_BOTTOM or not */
1761 rcImage
.left
= drawRect
->left
+ center_offset_h
;
1762 rcImage
.top
= drawRect
->top
+ center_offset_v
;
1763 drawRect
->left
+= cx
+ infoPtr
->uHItemPadding
;
1766 TRACE("drawing image=%d, left=%d, top=%d\n",
1767 item
->iImage
, rcImage
.left
, rcImage
.top
-1);
1779 /* Now position text */
1780 if (lStyle
& TCS_FIXEDWIDTH
&& lStyle
& TCS_FORCELABELLEFT
)
1781 center_offset_h
= infoPtr
->uHItemPadding
;
1783 if(lStyle
& TCS_VERTICAL
)
1784 center_offset_h
= ((drawRect
->bottom
- drawRect
->top
) - (rcText
.right
- rcText
.left
)) / 2;
1786 center_offset_h
= ((drawRect
->right
- drawRect
->left
) - (rcText
.right
- rcText
.left
)) / 2;
1788 if(lStyle
& TCS_VERTICAL
)
1790 if(lStyle
& TCS_BOTTOM
)
1791 drawRect
->top
+=center_offset_h
;
1793 drawRect
->bottom
-=center_offset_h
;
1795 center_offset_v
= ((drawRect
->right
- drawRect
->left
) - (rcText
.bottom
- rcText
.top
)) / 2;
1799 drawRect
->left
+= center_offset_h
;
1800 center_offset_v
= ((drawRect
->bottom
- drawRect
->top
) - (rcText
.bottom
- rcText
.top
)) / 2;
1803 /* if an item is selected, the text is shifted up instead of down */
1804 if (iItem
== infoPtr
->iSelected
)
1805 center_offset_v
-= infoPtr
->uVItemPadding
/ 2;
1807 center_offset_v
+= infoPtr
->uVItemPadding
/ 2;
1809 if (center_offset_v
< 0)
1810 center_offset_v
= 0;
1812 if(lStyle
& TCS_VERTICAL
)
1813 drawRect
->left
+= center_offset_v
;
1815 drawRect
->top
+= center_offset_v
;
1818 if(lStyle
& TCS_VERTICAL
) /* if we are vertical rotate the text and each character */
1820 static const WCHAR ArialW
[] = { 'A','r','i','a','l',0 };
1823 INT nEscapement
= 900;
1824 INT nOrientation
= 900;
1826 if(lStyle
& TCS_BOTTOM
)
1829 nOrientation
= -900;
1832 /* to get a font with the escapement and orientation we are looking for, we need to */
1833 /* call CreateFontIndirectA, which requires us to set the values of the logfont we pass in */
1834 if (!GetObjectW((infoPtr
->hFont
) ?
1835 infoPtr
->hFont
: GetStockObject(SYSTEM_FONT
),
1836 sizeof(LOGFONTW
),&logfont
))
1840 lstrcpyW(logfont
.lfFaceName
, ArialW
);
1841 logfont
.lfHeight
= -MulDiv(iPointSize
, GetDeviceCaps(hdc
, LOGPIXELSY
),
1843 logfont
.lfWeight
= FW_NORMAL
;
1844 logfont
.lfItalic
= 0;
1845 logfont
.lfUnderline
= 0;
1846 logfont
.lfStrikeOut
= 0;
1849 logfont
.lfEscapement
= nEscapement
;
1850 logfont
.lfOrientation
= nOrientation
;
1851 hFont
= CreateFontIndirectW(&logfont
);
1852 SelectObject(hdc
, hFont
);
1857 (lStyle
& TCS_BOTTOM
) ? drawRect
->right
: drawRect
->left
,
1858 (!(lStyle
& TCS_BOTTOM
)) ? drawRect
->bottom
: drawRect
->top
,
1862 lstrlenW(item
->pszText
),
1866 DeleteObject(hFont
);
1870 TRACE("for <%s>, c_o_h=%d, c_o_v=%d, draw=(%s), textlen=%d\n",
1871 debugstr_w(item
->pszText
), center_offset_h
, center_offset_v
,
1872 wine_dbgstr_rect(drawRect
), (rcText
.right
-rcText
.left
));
1879 lstrlenW(item
->pszText
),
1881 DT_LEFT
| DT_SINGLELINE
1886 *drawRect
= rcTemp
; /* restore drawRect */
1892 SelectObject(hdc
, hOldFont
);
1893 SetBkMode(hdc
, oldBkMode
);
1894 SelectObject(hdc
, holdPen
);
1895 DeleteObject( htextPen
);
1898 /******************************************************************************
1901 * This method is used to draw a single tab into the tab control.
1903 static void TAB_DrawItem(const TAB_INFO
*infoPtr
, HDC hdc
, INT iItem
)
1905 LONG lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
1909 RECT r
, fillRect
, r1
;
1912 COLORREF bkgnd
, corner
;
1916 * Get the rectangle for the item.
1918 isVisible
= TAB_InternalGetItemRect(infoPtr
,
1927 /* Clip UpDown control to not draw over it */
1928 if (infoPtr
->needsScrolling
)
1930 GetWindowRect(infoPtr
->hwnd
, &rC
);
1931 GetWindowRect(infoPtr
->hwndUpDown
, &rUD
);
1932 ExcludeClipRect(hdc
, rUD
.left
- rC
.left
, rUD
.top
- rC
.top
, rUD
.right
- rC
.left
, rUD
.bottom
- rC
.top
);
1935 /* If you need to see what the control is doing,
1936 * then override these variables. They will change what
1937 * fill colors are used for filling the tabs, and the
1938 * corners when drawing the edge.
1940 bkgnd
= comctl32_color
.clrBtnFace
;
1941 corner
= comctl32_color
.clrBtnFace
;
1943 if (lStyle
& TCS_BUTTONS
)
1945 /* Get item rectangle */
1948 /* Separators between flat buttons */
1949 if (lStyle
& TCS_FLATBUTTONS
)
1952 r1
.right
+= (FLAT_BTN_SPACINGX
-2);
1953 DrawEdge(hdc
, &r1
, EDGE_ETCHED
, BF_RIGHT
);
1956 if (iItem
== infoPtr
->iSelected
)
1958 DrawEdge(hdc
, &r
, EDGE_SUNKEN
, BF_SOFT
|BF_RECT
);
1960 OffsetRect(&r
, 1, 1);
1962 else /* ! selected */
1964 if (!(lStyle
& TCS_FLATBUTTONS
))
1965 DrawEdge(hdc
, &r
, EDGE_RAISED
, BF_SOFT
|BF_RECT
);
1968 else /* !TCS_BUTTONS */
1970 /* We draw a rectangle of different sizes depending on the selection
1972 if (iItem
== infoPtr
->iSelected
) {
1974 GetClientRect (infoPtr
->hwnd
, &rect
);
1975 clRight
= rect
.right
;
1976 clBottom
= rect
.bottom
;
1983 * Erase the background. (Delay it but setup rectangle.)
1984 * This is necessary when drawing the selected item since it is larger
1985 * than the others, it might overlap with stuff already drawn by the
1990 /* Draw themed tabs - but only if they are at the top.
1991 * Windows draws even side or bottom tabs themed, with wacky results.
1992 * However, since in Wine apps may get themed that did not opt in via
1993 * a manifest avoid theming when we know the result will be wrong */
1994 if ((theme
= GetWindowTheme (infoPtr
->hwnd
))
1995 && ((lStyle
& (TCS_VERTICAL
| TCS_BOTTOM
)) == 0))
1997 static const int partIds
[8] = {
2000 TABP_TABITEMLEFTEDGE
,
2001 TABP_TABITEMRIGHTEDGE
,
2002 TABP_TABITEMBOTHEDGE
,
2005 TABP_TOPTABITEMLEFTEDGE
,
2006 TABP_TOPTABITEMRIGHTEDGE
,
2007 TABP_TOPTABITEMBOTHEDGE
,
2010 int stateId
= TIS_NORMAL
;
2012 /* selected and unselected tabs have different parts */
2013 if (iItem
== infoPtr
->iSelected
)
2015 /* The part also differs on the position of a tab on a line.
2016 * "Visually" determining the position works well enough. */
2017 if(selectedRect
.left
== 0)
2019 if(selectedRect
.right
== clRight
)
2022 if (iItem
== infoPtr
->iSelected
)
2023 stateId
= TIS_SELECTED
;
2024 else if (iItem
== infoPtr
->iHotTracked
)
2026 else if (iItem
== infoPtr
->uFocus
)
2027 stateId
= TIS_FOCUSED
;
2029 /* Adjust rectangle for bottommost row */
2030 if (TAB_GetItem(infoPtr
, iItem
)->rect
.top
== infoPtr
->uNumRows
-1)
2033 DrawThemeBackground (theme
, hdc
, partIds
[partIndex
], stateId
, &r
, NULL
);
2034 GetThemeBackgroundContentRect (theme
, hdc
, partIds
[partIndex
], stateId
, &r
, &r
);
2036 else if(lStyle
& TCS_VERTICAL
)
2038 /* These are for adjusting the drawing of a Selected tab */
2039 /* The initial values are for the normal case of non-Selected */
2040 int ZZ
= 1; /* Do not stretch if selected */
2041 if (iItem
== infoPtr
->iSelected
) {
2044 /* if leftmost draw the line longer */
2045 if(selectedRect
.top
== 0)
2046 fillRect
.top
+= CONTROL_BORDER_SIZEY
;
2047 /* if rightmost draw the line longer */
2048 if(selectedRect
.bottom
== clBottom
)
2049 fillRect
.bottom
-= CONTROL_BORDER_SIZEY
;
2052 if (lStyle
& TCS_BOTTOM
)
2054 /* Adjust both rectangles to match native */
2057 TRACE("<right> item=%d, fill=(%s), edge=(%s)\n",
2058 iItem
, wine_dbgstr_rect(&fillRect
), wine_dbgstr_rect(&r
));
2060 /* Clear interior */
2061 SetBkColor(hdc
, bkgnd
);
2062 ExtTextOutW(hdc
, 0, 0, 2, &fillRect
, NULL
, 0, 0);
2064 /* Draw rectangular edge around tab */
2065 DrawEdge(hdc
, &r
, EDGE_RAISED
, BF_SOFT
|BF_RIGHT
|BF_TOP
|BF_BOTTOM
);
2067 /* Now erase the top corner and draw diagonal edge */
2068 SetBkColor(hdc
, corner
);
2069 r1
.left
= r
.right
- ROUND_CORNER_SIZE
- 1;
2072 r1
.bottom
= r1
.top
+ ROUND_CORNER_SIZE
;
2073 ExtTextOutW(hdc
, 0, 0, 2, &r1
, NULL
, 0, 0);
2075 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_DIAGONAL_ENDTOPLEFT
);
2077 /* Now erase the bottom corner and draw diagonal edge */
2078 r1
.left
= r
.right
- ROUND_CORNER_SIZE
- 1;
2079 r1
.bottom
= r
.bottom
;
2081 r1
.top
= r1
.bottom
- ROUND_CORNER_SIZE
;
2082 ExtTextOutW(hdc
, 0, 0, 2, &r1
, NULL
, 0, 0);
2084 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_DIAGONAL_ENDBOTTOMLEFT
);
2086 if ((iItem
== infoPtr
->iSelected
) && (selectedRect
.top
== 0)) {
2090 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_TOP
);
2096 TRACE("<left> item=%d, fill=(%s), edge=(%s)\n",
2097 iItem
, wine_dbgstr_rect(&fillRect
), wine_dbgstr_rect(&r
));
2099 /* Clear interior */
2100 SetBkColor(hdc
, bkgnd
);
2101 ExtTextOutW(hdc
, 0, 0, 2, &fillRect
, NULL
, 0, 0);
2103 /* Draw rectangular edge around tab */
2104 DrawEdge(hdc
, &r
, EDGE_RAISED
, BF_SOFT
|BF_LEFT
|BF_TOP
|BF_BOTTOM
);
2106 /* Now erase the top corner and draw diagonal edge */
2107 SetBkColor(hdc
, corner
);
2110 r1
.right
= r1
.left
+ ROUND_CORNER_SIZE
+ 1;
2111 r1
.bottom
= r1
.top
+ ROUND_CORNER_SIZE
;
2112 ExtTextOutW(hdc
, 0, 0, 2, &r1
, NULL
, 0, 0);
2114 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_DIAGONAL_ENDTOPRIGHT
);
2116 /* Now erase the bottom corner and draw diagonal edge */
2118 r1
.bottom
= r
.bottom
;
2119 r1
.right
= r1
.left
+ ROUND_CORNER_SIZE
+ 1;
2120 r1
.top
= r1
.bottom
- ROUND_CORNER_SIZE
;
2121 ExtTextOutW(hdc
, 0, 0, 2, &r1
, NULL
, 0, 0);
2123 DrawEdge(hdc
, &r1
, EDGE_SUNKEN
, BF_DIAGONAL_ENDTOPLEFT
);
2126 else /* ! TCS_VERTICAL */
2128 /* These are for adjusting the drawing of a Selected tab */
2129 /* The initial values are for the normal case of non-Selected */
2130 if (iItem
== infoPtr
->iSelected
) {
2131 /* if leftmost draw the line longer */
2132 if(selectedRect
.left
== 0)
2133 fillRect
.left
+= CONTROL_BORDER_SIZEX
;
2134 /* if rightmost draw the line longer */
2135 if(selectedRect
.right
== clRight
)
2136 fillRect
.right
-= CONTROL_BORDER_SIZEX
;
2139 if (lStyle
& TCS_BOTTOM
)
2141 /* Adjust both rectangles for topmost row */
2142 if (TAB_GetItem(infoPtr
, iItem
)->rect
.top
== infoPtr
->uNumRows
-1)
2148 TRACE("<bottom> item=%d, fill=(%s), edge=(%s)\n",
2149 iItem
, wine_dbgstr_rect(&fillRect
), wine_dbgstr_rect(&r
));
2151 /* Clear interior */
2152 SetBkColor(hdc
, bkgnd
);
2153 ExtTextOutW(hdc
, 0, 0, 2, &fillRect
, NULL
, 0, 0);
2155 /* Draw rectangular edge around tab */
2156 DrawEdge(hdc
, &r
, EDGE_RAISED
, BF_SOFT
|BF_LEFT
|BF_BOTTOM
|BF_RIGHT
);
2158 /* Now erase the righthand corner and draw diagonal edge */
2159 SetBkColor(hdc
, corner
);
2160 r1
.left
= r
.right
- ROUND_CORNER_SIZE
;
2161 r1
.bottom
= r
.bottom
;
2163 r1
.top
= r1
.bottom
- ROUND_CORNER_SIZE
- 1;
2164 ExtTextOutW(hdc
, 0, 0, 2, &r1
, NULL
, 0, 0);
2166 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_DIAGONAL_ENDBOTTOMLEFT
);
2168 /* Now erase the lefthand corner and draw diagonal edge */
2170 r1
.bottom
= r
.bottom
;
2171 r1
.right
= r1
.left
+ ROUND_CORNER_SIZE
;
2172 r1
.top
= r1
.bottom
- ROUND_CORNER_SIZE
- 1;
2173 ExtTextOutW(hdc
, 0, 0, 2, &r1
, NULL
, 0, 0);
2175 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_DIAGONAL_ENDTOPLEFT
);
2177 if (iItem
== infoPtr
->iSelected
)
2181 if (selectedRect
.left
== 0)
2186 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_LEFT
);
2193 /* Adjust both rectangles for bottommost row */
2194 if (TAB_GetItem(infoPtr
, iItem
)->rect
.top
== infoPtr
->uNumRows
-1)
2196 fillRect
.bottom
+= 3;
2200 TRACE("<top> item=%d, fill=(%s), edge=(%s)\n",
2201 iItem
, wine_dbgstr_rect(&fillRect
), wine_dbgstr_rect(&r
));
2203 /* Clear interior */
2204 SetBkColor(hdc
, bkgnd
);
2205 ExtTextOutW(hdc
, 0, 0, 2, &fillRect
, NULL
, 0, 0);
2207 /* Draw rectangular edge around tab */
2208 DrawEdge(hdc
, &r
, EDGE_RAISED
, BF_SOFT
|BF_LEFT
|BF_TOP
|BF_RIGHT
);
2210 /* Now erase the righthand corner and draw diagonal edge */
2211 SetBkColor(hdc
, corner
);
2212 r1
.left
= r
.right
- ROUND_CORNER_SIZE
;
2215 r1
.bottom
= r1
.top
+ ROUND_CORNER_SIZE
+ 1;
2216 ExtTextOutW(hdc
, 0, 0, 2, &r1
, NULL
, 0, 0);
2218 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_DIAGONAL_ENDBOTTOMRIGHT
);
2220 /* Now erase the lefthand corner and draw diagonal edge */
2223 r1
.right
= r1
.left
+ ROUND_CORNER_SIZE
;
2224 r1
.bottom
= r1
.top
+ ROUND_CORNER_SIZE
+ 1;
2225 ExtTextOutW(hdc
, 0, 0, 2, &r1
, NULL
, 0, 0);
2227 DrawEdge(hdc
, &r1
, EDGE_RAISED
, BF_SOFT
|BF_DIAGONAL_ENDTOPRIGHT
);
2232 TAB_DumpItemInternal(infoPtr
, iItem
);
2234 /* This modifies r to be the text rectangle. */
2235 TAB_DrawItemInterior(infoPtr
, hdc
, iItem
, &r
);
2239 /******************************************************************************
2242 * This method is used to draw the raised border around the tab control
2245 static void TAB_DrawBorder(const TAB_INFO
*infoPtr
, HDC hdc
)
2248 DWORD lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
2249 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
2251 GetClientRect (infoPtr
->hwnd
, &rect
);
2254 * Adjust for the style
2257 if (infoPtr
->uNumItem
)
2259 if ((lStyle
& TCS_BOTTOM
) && !(lStyle
& TCS_VERTICAL
))
2260 rect
.bottom
-= infoPtr
->tabHeight
* infoPtr
->uNumRows
+ CONTROL_BORDER_SIZEX
;
2261 else if((lStyle
& TCS_BOTTOM
) && (lStyle
& TCS_VERTICAL
))
2262 rect
.right
-= infoPtr
->tabHeight
* infoPtr
->uNumRows
+ CONTROL_BORDER_SIZEX
;
2263 else if(lStyle
& TCS_VERTICAL
)
2264 rect
.left
+= infoPtr
->tabHeight
* infoPtr
->uNumRows
+ CONTROL_BORDER_SIZEX
;
2265 else /* not TCS_VERTICAL and not TCS_BOTTOM */
2266 rect
.top
+= infoPtr
->tabHeight
* infoPtr
->uNumRows
+ CONTROL_BORDER_SIZEX
;
2269 TRACE("border=(%s)\n", wine_dbgstr_rect(&rect
));
2272 DrawThemeBackground (theme
, hdc
, TABP_PANE
, 0, &rect
, NULL
);
2274 DrawEdge(hdc
, &rect
, EDGE_RAISED
, BF_SOFT
|BF_RECT
);
2277 /******************************************************************************
2280 * This method repaints the tab control..
2282 static void TAB_Refresh (TAB_INFO
*infoPtr
, HDC hdc
)
2287 if (!infoPtr
->DoRedraw
)
2290 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
2292 if (GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
) & TCS_BUTTONS
)
2294 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
2295 TAB_DrawItem (infoPtr
, hdc
, i
);
2299 /* Draw all the non selected item first */
2300 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
2302 if (i
!= infoPtr
->iSelected
)
2303 TAB_DrawItem (infoPtr
, hdc
, i
);
2306 /* Now, draw the border, draw it before the selected item
2307 * since the selected item overwrites part of the border. */
2308 TAB_DrawBorder (infoPtr
, hdc
);
2310 /* Then, draw the selected item */
2311 TAB_DrawItem (infoPtr
, hdc
, infoPtr
->iSelected
);
2314 SelectObject (hdc
, hOldFont
);
2317 static inline DWORD
TAB_GetRowCount (const TAB_INFO
*infoPtr
)
2319 return infoPtr
->uNumRows
;
2322 static inline LRESULT
TAB_SetRedraw (TAB_INFO
*infoPtr
, BOOL doRedraw
)
2324 infoPtr
->DoRedraw
= doRedraw
;
2328 /******************************************************************************
2329 * TAB_EnsureSelectionVisible
2331 * This method will make sure that the current selection is completely
2332 * visible by scrolling until it is.
2334 static void TAB_EnsureSelectionVisible(
2337 INT iSelected
= infoPtr
->iSelected
;
2338 LONG lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
2339 INT iOrigLeftmostVisible
= infoPtr
->leftmostVisible
;
2341 /* set the items row to the bottommost row or topmost row depending on
2343 if ((infoPtr
->uNumRows
> 1) && !(lStyle
& TCS_BUTTONS
))
2345 TAB_ITEM
*selected
= TAB_GetItem(infoPtr
, iSelected
);
2349 if(lStyle
& TCS_VERTICAL
)
2350 newselected
= selected
->rect
.left
;
2352 newselected
= selected
->rect
.top
;
2354 /* the target row is always (number of rows - 1)
2355 as row 0 is furthest from the clientRect */
2356 iTargetRow
= infoPtr
->uNumRows
- 1;
2358 if (newselected
!= iTargetRow
)
2361 if(lStyle
& TCS_VERTICAL
)
2363 for (i
=0; i
< infoPtr
->uNumItem
; i
++)
2365 /* move everything in the row of the selected item to the iTargetRow */
2366 TAB_ITEM
*item
= TAB_GetItem(infoPtr
, i
);
2368 if (item
->rect
.left
== newselected
)
2369 item
->rect
.left
= iTargetRow
;
2372 if (item
->rect
.left
> newselected
)
2379 for (i
=0; i
< infoPtr
->uNumItem
; i
++)
2381 TAB_ITEM
*item
= TAB_GetItem(infoPtr
, i
);
2383 if (item
->rect
.top
== newselected
)
2384 item
->rect
.top
= iTargetRow
;
2387 if (item
->rect
.top
> newselected
)
2392 TAB_RecalcHotTrack(infoPtr
, NULL
, NULL
, NULL
);
2397 * Do the trivial cases first.
2399 if ( (!infoPtr
->needsScrolling
) ||
2400 (infoPtr
->hwndUpDown
==0) || (lStyle
& TCS_VERTICAL
))
2403 if (infoPtr
->leftmostVisible
>= iSelected
)
2405 infoPtr
->leftmostVisible
= iSelected
;
2409 TAB_ITEM
*selected
= TAB_GetItem(infoPtr
, iSelected
);
2414 /* Calculate the part of the client area that is visible */
2415 GetClientRect(infoPtr
->hwnd
, &r
);
2418 GetClientRect(infoPtr
->hwndUpDown
, &r
);
2421 if ((selected
->rect
.right
-
2422 selected
->rect
.left
) >= width
)
2424 /* Special case: width of selected item is greater than visible
2427 infoPtr
->leftmostVisible
= iSelected
;
2431 for (i
= infoPtr
->leftmostVisible
; i
< infoPtr
->uNumItem
; i
++)
2433 if ((selected
->rect
.right
- TAB_GetItem(infoPtr
, i
)->rect
.left
) < width
)
2436 infoPtr
->leftmostVisible
= i
;
2440 if (infoPtr
->leftmostVisible
!= iOrigLeftmostVisible
)
2441 TAB_RecalcHotTrack(infoPtr
, NULL
, NULL
, NULL
);
2443 SendMessageW(infoPtr
->hwndUpDown
, UDM_SETPOS
, 0,
2444 MAKELONG(infoPtr
->leftmostVisible
, 0));
2447 /******************************************************************************
2448 * TAB_InvalidateTabArea
2450 * This method will invalidate the portion of the control that contains the
2451 * tabs. It is called when the state of the control changes and needs
2454 static void TAB_InvalidateTabArea(const TAB_INFO
*infoPtr
)
2456 RECT clientRect
, rInvalidate
, rAdjClient
;
2457 DWORD lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
2458 INT lastRow
= infoPtr
->uNumRows
- 1;
2461 if (lastRow
< 0) return;
2463 GetClientRect(infoPtr
->hwnd
, &clientRect
);
2464 rInvalidate
= clientRect
;
2465 rAdjClient
= clientRect
;
2467 TAB_AdjustRect(infoPtr
, 0, &rAdjClient
);
2469 TAB_InternalGetItemRect(infoPtr
, infoPtr
->uNumItem
-1 , &rect
, NULL
);
2470 if ((lStyle
& TCS_BOTTOM
) && (lStyle
& TCS_VERTICAL
))
2472 rInvalidate
.left
= rAdjClient
.right
;
2473 if (infoPtr
->uNumRows
== 1)
2474 rInvalidate
.bottom
= clientRect
.top
+ rect
.bottom
+ 2 * SELECTED_TAB_OFFSET
;
2476 else if(lStyle
& TCS_VERTICAL
)
2478 rInvalidate
.right
= rAdjClient
.left
;
2479 if (infoPtr
->uNumRows
== 1)
2480 rInvalidate
.bottom
= clientRect
.top
+ rect
.bottom
+ 2 * SELECTED_TAB_OFFSET
;
2482 else if (lStyle
& TCS_BOTTOM
)
2484 rInvalidate
.top
= rAdjClient
.bottom
;
2485 if (infoPtr
->uNumRows
== 1)
2486 rInvalidate
.right
= clientRect
.left
+ rect
.right
+ 2 * SELECTED_TAB_OFFSET
;
2490 rInvalidate
.bottom
= rAdjClient
.top
;
2491 if (infoPtr
->uNumRows
== 1)
2492 rInvalidate
.right
= clientRect
.left
+ rect
.right
+ 2 * SELECTED_TAB_OFFSET
;
2495 /* Punch out the updown control */
2496 if (infoPtr
->needsScrolling
&& (rInvalidate
.right
> 0)) {
2498 GetClientRect(infoPtr
->hwndUpDown
, &r
);
2499 if (rInvalidate
.right
> clientRect
.right
- r
.left
)
2500 rInvalidate
.right
= rInvalidate
.right
- (r
.right
- r
.left
);
2502 rInvalidate
.right
= clientRect
.right
- r
.left
;
2505 TRACE("invalidate (%s)\n", wine_dbgstr_rect(&rInvalidate
));
2507 InvalidateRect(infoPtr
->hwnd
, &rInvalidate
, TRUE
);
2510 static inline LRESULT
TAB_Paint (TAB_INFO
*infoPtr
, HDC hdcPaint
)
2519 hdc
= BeginPaint (infoPtr
->hwnd
, &ps
);
2520 TRACE("erase %d, rect=(%s)\n", ps
.fErase
, wine_dbgstr_rect(&ps
.rcPaint
));
2523 TAB_Refresh (infoPtr
, hdc
);
2526 EndPaint (infoPtr
->hwnd
, &ps
);
2532 TAB_InsertItemT (TAB_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
, BOOL bUnicode
)
2539 GetClientRect (infoPtr
->hwnd
, &rect
);
2540 TRACE("Rect: %p %s\n", infoPtr
->hwnd
, wine_dbgstr_rect(&rect
));
2542 pti
= (TCITEMW
*)lParam
;
2543 iItem
= (INT
)wParam
;
2545 if (iItem
< 0) return -1;
2546 if (iItem
> infoPtr
->uNumItem
)
2547 iItem
= infoPtr
->uNumItem
;
2549 TAB_DumpItemExternalT(pti
, iItem
, bUnicode
);
2552 if (infoPtr
->uNumItem
== 0) {
2553 infoPtr
->items
= Alloc (TAB_ITEM_SIZE(infoPtr
));
2554 infoPtr
->uNumItem
++;
2555 infoPtr
->iSelected
= 0;
2558 LPBYTE oldItems
= (LPBYTE
)infoPtr
->items
;
2560 infoPtr
->uNumItem
++;
2561 infoPtr
->items
= Alloc (TAB_ITEM_SIZE(infoPtr
) * infoPtr
->uNumItem
);
2563 /* pre insert copy */
2565 memcpy (infoPtr
->items
, oldItems
,
2566 iItem
* TAB_ITEM_SIZE(infoPtr
));
2569 /* post insert copy */
2570 if (iItem
< infoPtr
->uNumItem
- 1) {
2571 memcpy (TAB_GetItem(infoPtr
, iItem
+ 1),
2572 oldItems
+ iItem
* TAB_ITEM_SIZE(infoPtr
),
2573 (infoPtr
->uNumItem
- iItem
- 1) * TAB_ITEM_SIZE(infoPtr
));
2577 if (iItem
<= infoPtr
->iSelected
)
2578 infoPtr
->iSelected
++;
2583 item
= TAB_GetItem(infoPtr
, iItem
);
2585 item
->pszText
= NULL
;
2587 if (pti
->mask
& TCIF_TEXT
)
2590 Str_SetPtrW (&item
->pszText
, pti
->pszText
);
2592 Str_SetPtrAtoW (&item
->pszText
, (LPSTR
)pti
->pszText
);
2595 if (pti
->mask
& TCIF_IMAGE
)
2596 item
->iImage
= pti
->iImage
;
2600 if (pti
->mask
& TCIF_PARAM
)
2601 memcpy(item
->extra
, &pti
->lParam
, infoPtr
->cbInfo
);
2603 memset(item
->extra
, 0, infoPtr
->cbInfo
);
2605 TAB_SetItemBounds(infoPtr
);
2606 if (infoPtr
->uNumItem
> 1)
2607 TAB_InvalidateTabArea(infoPtr
);
2609 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2611 TRACE("[%p]: added item %d %s\n",
2612 infoPtr
->hwnd
, iItem
, debugstr_w(item
->pszText
));
2614 /* If we haven't set the current focus yet, set it now. */
2615 if (infoPtr
->uFocus
== -1)
2616 TAB_SetCurFocus(infoPtr
, iItem
);
2622 TAB_SetItemSize (TAB_INFO
*infoPtr
, LPARAM lParam
)
2624 LONG lStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
2626 BOOL bNeedPaint
= FALSE
;
2628 lResult
= MAKELONG(infoPtr
->tabWidth
, infoPtr
->tabHeight
);
2630 /* UNDOCUMENTED: If requested Width or Height is 0 this means that program wants to use auto size. */
2631 if (lStyle
& TCS_FIXEDWIDTH
&& (infoPtr
->tabWidth
!= (INT
)LOWORD(lParam
)))
2633 infoPtr
->tabWidth
= (INT
)LOWORD(lParam
);
2637 if (infoPtr
->tabHeight
!= (INT
)HIWORD(lParam
))
2639 if ((infoPtr
->fHeightSet
= ((INT
)HIWORD(lParam
) != 0)))
2640 infoPtr
->tabHeight
= (INT
)HIWORD(lParam
);
2644 TRACE("was h=%d,w=%d, now h=%d,w=%d\n",
2645 HIWORD(lResult
), LOWORD(lResult
),
2646 infoPtr
->tabHeight
, infoPtr
->tabWidth
);
2650 TAB_SetItemBounds(infoPtr
);
2651 RedrawWindow(infoPtr
->hwnd
, NULL
, NULL
, RDW_ERASE
| RDW_INVALIDATE
| RDW_UPDATENOW
);
2657 static inline LRESULT
TAB_SetMinTabWidth (TAB_INFO
*infoPtr
, INT cx
)
2661 TRACE("(%p,%d)\n", infoPtr
, cx
);
2663 oldcx
= infoPtr
->tabMinWidth
;
2664 infoPtr
->tabMinWidth
= cx
;
2665 TAB_SetItemBounds(infoPtr
);
2669 static inline LRESULT
2670 TAB_HighlightItem (TAB_INFO
*infoPtr
, INT iItem
, BOOL fHighlight
)
2674 TRACE("(%p,%d,%s)\n", infoPtr
, iItem
, fHighlight
? "true" : "false");
2676 if (!infoPtr
|| iItem
< 0 || iItem
>= infoPtr
->uNumItem
)
2679 lpState
= &TAB_GetItem(infoPtr
, iItem
)->dwState
;
2682 *lpState
|= TCIS_HIGHLIGHTED
;
2684 *lpState
&= ~TCIS_HIGHLIGHTED
;
2690 TAB_SetItemT (TAB_INFO
*infoPtr
, INT iItem
, LPTCITEMW tabItem
, BOOL bUnicode
)
2694 TRACE("(%p,%d,%p,%s)\n", infoPtr
, iItem
, tabItem
, bUnicode
? "true" : "false");
2696 if (iItem
< 0 || iItem
>= infoPtr
->uNumItem
)
2699 TAB_DumpItemExternalT(tabItem
, iItem
, bUnicode
);
2701 wineItem
= TAB_GetItem(infoPtr
, iItem
);
2703 if (tabItem
->mask
& TCIF_IMAGE
)
2704 wineItem
->iImage
= tabItem
->iImage
;
2706 if (tabItem
->mask
& TCIF_PARAM
)
2707 memcpy(wineItem
->extra
, &tabItem
->lParam
, infoPtr
->cbInfo
);
2709 if (tabItem
->mask
& TCIF_RTLREADING
)
2710 FIXME("TCIF_RTLREADING\n");
2712 if (tabItem
->mask
& TCIF_STATE
)
2713 wineItem
->dwState
= tabItem
->dwState
;
2715 if (tabItem
->mask
& TCIF_TEXT
)
2717 Free(wineItem
->pszText
);
2718 wineItem
->pszText
= NULL
;
2720 Str_SetPtrW(&wineItem
->pszText
, tabItem
->pszText
);
2722 Str_SetPtrAtoW(&wineItem
->pszText
, (LPSTR
)tabItem
->pszText
);
2725 /* Update and repaint tabs */
2726 TAB_SetItemBounds(infoPtr
);
2727 TAB_InvalidateTabArea(infoPtr
);
2732 static inline LRESULT
TAB_GetItemCount (const TAB_INFO
*infoPtr
)
2734 return infoPtr
->uNumItem
;
2739 TAB_GetItemT (TAB_INFO
*infoPtr
, INT iItem
, LPTCITEMW tabItem
, BOOL bUnicode
)
2743 TRACE("(%p,%d,%p,%s)\n", infoPtr
, iItem
, tabItem
, bUnicode
? "true" : "false");
2745 if (iItem
< 0 || iItem
>= infoPtr
->uNumItem
)
2748 wineItem
= TAB_GetItem(infoPtr
, iItem
);
2750 if (tabItem
->mask
& TCIF_IMAGE
)
2751 tabItem
->iImage
= wineItem
->iImage
;
2753 if (tabItem
->mask
& TCIF_PARAM
)
2754 memcpy(&tabItem
->lParam
, wineItem
->extra
, infoPtr
->cbInfo
);
2756 if (tabItem
->mask
& TCIF_RTLREADING
)
2757 FIXME("TCIF_RTLREADING\n");
2759 if (tabItem
->mask
& TCIF_STATE
)
2760 tabItem
->dwState
= wineItem
->dwState
;
2762 if (tabItem
->mask
& TCIF_TEXT
)
2765 Str_GetPtrW (wineItem
->pszText
, tabItem
->pszText
, tabItem
->cchTextMax
);
2767 Str_GetPtrWtoA (wineItem
->pszText
, (LPSTR
)tabItem
->pszText
, tabItem
->cchTextMax
);
2770 TAB_DumpItemExternalT(tabItem
, iItem
, bUnicode
);
2776 static LRESULT
TAB_DeleteItem (TAB_INFO
*infoPtr
, INT iItem
)
2778 BOOL bResult
= FALSE
;
2780 TRACE("(%p, %d)\n", infoPtr
, iItem
);
2782 if ((iItem
>= 0) && (iItem
< infoPtr
->uNumItem
))
2784 TAB_ITEM
*item
= TAB_GetItem(infoPtr
, iItem
);
2785 LPBYTE oldItems
= (LPBYTE
)infoPtr
->items
;
2787 TAB_InvalidateTabArea(infoPtr
);
2788 Free(item
->pszText
);
2789 infoPtr
->uNumItem
--;
2791 if (!infoPtr
->uNumItem
)
2793 infoPtr
->items
= NULL
;
2794 if (infoPtr
->iHotTracked
>= 0)
2796 KillTimer(infoPtr
->hwnd
, TAB_HOTTRACK_TIMER
);
2797 infoPtr
->iHotTracked
= -1;
2802 infoPtr
->items
= Alloc(TAB_ITEM_SIZE(infoPtr
) * infoPtr
->uNumItem
);
2805 memcpy(infoPtr
->items
, oldItems
, iItem
* TAB_ITEM_SIZE(infoPtr
));
2807 if (iItem
< infoPtr
->uNumItem
)
2808 memcpy(TAB_GetItem(infoPtr
, iItem
),
2809 oldItems
+ (iItem
+ 1) * TAB_ITEM_SIZE(infoPtr
),
2810 (infoPtr
->uNumItem
- iItem
) * TAB_ITEM_SIZE(infoPtr
));
2812 if (iItem
<= infoPtr
->iHotTracked
)
2814 /* When tabs move left/up, the hot track item may change */
2815 FIXME("Recalc hot track\n");
2820 /* Readjust the selected index */
2821 if ((iItem
== infoPtr
->iSelected
) && (iItem
> 0))
2822 infoPtr
->iSelected
--;
2824 if (iItem
< infoPtr
->iSelected
)
2825 infoPtr
->iSelected
--;
2827 if (infoPtr
->uNumItem
== 0)
2828 infoPtr
->iSelected
= -1;
2830 /* Reposition and repaint tabs */
2831 TAB_SetItemBounds(infoPtr
);
2839 static inline LRESULT
TAB_DeleteAllItems (TAB_INFO
*infoPtr
)
2841 TRACE("(%p)\n", infoPtr
);
2842 while (infoPtr
->uNumItem
)
2843 TAB_DeleteItem (infoPtr
, 0);
2848 static inline LRESULT
TAB_GetFont (const TAB_INFO
*infoPtr
)
2850 TRACE("(%p) returning %p\n", infoPtr
, infoPtr
->hFont
);
2851 return (LRESULT
)infoPtr
->hFont
;
2854 static inline LRESULT
TAB_SetFont (TAB_INFO
*infoPtr
, HFONT hNewFont
)
2856 TRACE("(%p,%p)\n", infoPtr
, hNewFont
);
2858 infoPtr
->hFont
= hNewFont
;
2860 TAB_SetItemBounds(infoPtr
);
2862 TAB_InvalidateTabArea(infoPtr
);
2868 static inline LRESULT
TAB_GetImageList (const TAB_INFO
*infoPtr
)
2871 return (LRESULT
)infoPtr
->himl
;
2874 static inline LRESULT
TAB_SetImageList (TAB_INFO
*infoPtr
, HIMAGELIST himlNew
)
2876 HIMAGELIST himlPrev
= infoPtr
->himl
;
2878 infoPtr
->himl
= himlNew
;
2879 TAB_SetItemBounds(infoPtr
);
2880 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2881 return (LRESULT
)himlPrev
;
2884 static inline LRESULT
TAB_GetUnicodeFormat (const TAB_INFO
*infoPtr
)
2886 return infoPtr
->bUnicode
;
2889 static inline LRESULT
TAB_SetUnicodeFormat (TAB_INFO
*infoPtr
, BOOL bUnicode
)
2891 BOOL bTemp
= infoPtr
->bUnicode
;
2893 infoPtr
->bUnicode
= bUnicode
;
2898 static inline LRESULT
TAB_Size (TAB_INFO
*infoPtr
)
2900 /* I'm not really sure what the following code was meant to do.
2901 This is what it is doing:
2902 When WM_SIZE is sent with SIZE_RESTORED, the control
2903 gets positioned in the top left corner.
2907 UINT uPosFlags,cx,cy;
2911 parent = GetParent (hwnd);
2912 GetClientRect(parent, &parent_rect);
2915 if (GetWindowLongW(hwnd, GWL_STYLE) & CCS_NORESIZE)
2916 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2918 SetWindowPos (hwnd, 0, parent_rect.left, parent_rect.top,
2919 cx, cy, uPosFlags | SWP_NOZORDER);
2921 FIXME("WM_SIZE flag %x %lx not handled\n", wParam, lParam);
2924 /* Recompute the size/position of the tabs. */
2925 TAB_SetItemBounds (infoPtr
);
2927 /* Force a repaint of the control. */
2928 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2934 static LRESULT
TAB_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2937 TEXTMETRICW fontMetrics
;
2942 infoPtr
= Alloc (sizeof(TAB_INFO
));
2944 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
2946 infoPtr
->hwnd
= hwnd
;
2947 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
2948 infoPtr
->uNumItem
= 0;
2949 infoPtr
->uNumRows
= 0;
2950 infoPtr
->uHItemPadding
= 6;
2951 infoPtr
->uVItemPadding
= 3;
2952 infoPtr
->uHItemPadding_s
= 6;
2953 infoPtr
->uVItemPadding_s
= 3;
2956 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2957 infoPtr
->iSelected
= -1;
2958 infoPtr
->iHotTracked
= -1;
2959 infoPtr
->uFocus
= -1;
2960 infoPtr
->hwndToolTip
= 0;
2961 infoPtr
->DoRedraw
= TRUE
;
2962 infoPtr
->needsScrolling
= FALSE
;
2963 infoPtr
->hwndUpDown
= 0;
2964 infoPtr
->leftmostVisible
= 0;
2965 infoPtr
->fHeightSet
= FALSE
;
2966 infoPtr
->bUnicode
= IsWindowUnicode (hwnd
);
2967 infoPtr
->cbInfo
= sizeof(LPARAM
);
2969 TRACE("Created tab control, hwnd [%p]\n", hwnd
);
2971 /* The tab control always has the WS_CLIPSIBLINGS style. Even
2972 if you don't specify it in CreateWindow. This is necessary in
2973 order for paint to work correctly. This follows windows behaviour. */
2974 dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
2975 SetWindowLongW(hwnd
, GWL_STYLE
, dwStyle
|WS_CLIPSIBLINGS
);
2977 if (dwStyle
& TCS_TOOLTIPS
) {
2978 /* Create tooltip control */
2979 infoPtr
->hwndToolTip
=
2980 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2981 CW_USEDEFAULT
, CW_USEDEFAULT
,
2982 CW_USEDEFAULT
, CW_USEDEFAULT
,
2985 /* Send NM_TOOLTIPSCREATED notification */
2986 if (infoPtr
->hwndToolTip
) {
2987 NMTOOLTIPSCREATED nmttc
;
2989 nmttc
.hdr
.hwndFrom
= hwnd
;
2990 nmttc
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
2991 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
2992 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2994 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
2995 (WPARAM
)GetWindowLongPtrW(hwnd
, GWLP_ID
), (LPARAM
)&nmttc
);
2999 OpenThemeData (infoPtr
->hwnd
, themeClass
);
3002 * We need to get text information so we need a DC and we need to select
3006 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
3008 /* Use the system font to determine the initial height of a tab. */
3009 GetTextMetricsW(hdc
, &fontMetrics
);
3012 * Make sure there is enough space for the letters + growing the
3013 * selected item + extra space for the selected item.
3015 infoPtr
->tabHeight
= fontMetrics
.tmHeight
+ SELECTED_TAB_OFFSET
+
3016 ((dwStyle
& TCS_BUTTONS
) ? 2 : 1) *
3017 infoPtr
->uVItemPadding
;
3019 /* Initialize the width of a tab. */
3020 if (dwStyle
& TCS_FIXEDWIDTH
)
3021 infoPtr
->tabWidth
= GetDeviceCaps(hdc
, LOGPIXELSX
);
3023 infoPtr
->tabMinWidth
= -1;
3025 TRACE("tabH=%d, tabW=%d\n", infoPtr
->tabHeight
, infoPtr
->tabWidth
);
3027 SelectObject (hdc
, hOldFont
);
3028 ReleaseDC(hwnd
, hdc
);
3034 TAB_Destroy (TAB_INFO
*infoPtr
)
3041 SetWindowLongPtrW(infoPtr
->hwnd
, 0, 0);
3043 if (infoPtr
->items
) {
3044 for (iItem
= 0; iItem
< infoPtr
->uNumItem
; iItem
++) {
3045 Free (TAB_GetItem(infoPtr
, iItem
)->pszText
);
3047 Free (infoPtr
->items
);
3050 if (infoPtr
->hwndToolTip
)
3051 DestroyWindow (infoPtr
->hwndToolTip
);
3053 if (infoPtr
->hwndUpDown
)
3054 DestroyWindow(infoPtr
->hwndUpDown
);
3056 if (infoPtr
->iHotTracked
>= 0)
3057 KillTimer(infoPtr
->hwnd
, TAB_HOTTRACK_TIMER
);
3059 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
3065 /* update theme after a WM_THEMECHANGED message */
3066 static LRESULT
theme_changed(const TAB_INFO
*infoPtr
)
3068 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
3069 CloseThemeData (theme
);
3070 OpenThemeData (infoPtr
->hwnd
, themeClass
);
3074 static LRESULT
TAB_NCCalcSize(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3078 return WVR_ALIGNTOP
;
3081 static inline LRESULT
3082 TAB_SetItemExtra (TAB_INFO
*infoPtr
, INT cbInfo
)
3084 if (!infoPtr
|| cbInfo
<= 0)
3087 if (infoPtr
->uNumItem
)
3089 /* FIXME: MSDN says this is not allowed, but this hasn't been verified */
3093 infoPtr
->cbInfo
= cbInfo
;
3097 static LRESULT WINAPI
3098 TAB_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3100 TAB_INFO
*infoPtr
= TAB_GetInfoPtr(hwnd
);
3102 TRACE("hwnd=%p msg=%x wParam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
3103 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
3104 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
3108 case TCM_GETIMAGELIST
:
3109 return TAB_GetImageList (infoPtr
);
3111 case TCM_SETIMAGELIST
:
3112 return TAB_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
3114 case TCM_GETITEMCOUNT
:
3115 return TAB_GetItemCount (infoPtr
);
3119 return TAB_GetItemT (infoPtr
, (INT
)wParam
, (LPTCITEMW
)lParam
, uMsg
== TCM_GETITEMW
);
3123 return TAB_SetItemT (infoPtr
, (INT
)wParam
, (LPTCITEMW
)lParam
, uMsg
== TCM_SETITEMW
);
3125 case TCM_DELETEITEM
:
3126 return TAB_DeleteItem (infoPtr
, (INT
)wParam
);
3128 case TCM_DELETEALLITEMS
:
3129 return TAB_DeleteAllItems (infoPtr
);
3131 case TCM_GETITEMRECT
:
3132 return TAB_GetItemRect (infoPtr
, wParam
, lParam
);
3135 return TAB_GetCurSel (infoPtr
);
3138 return TAB_HitTest (infoPtr
, (LPTCHITTESTINFO
)lParam
);
3141 return TAB_SetCurSel (infoPtr
, (INT
)wParam
);
3143 case TCM_INSERTITEMA
:
3144 case TCM_INSERTITEMW
:
3145 return TAB_InsertItemT (infoPtr
, wParam
, lParam
, uMsg
== TCM_INSERTITEMW
);
3147 case TCM_SETITEMEXTRA
:
3148 return TAB_SetItemExtra (infoPtr
, (int)wParam
);
3150 case TCM_ADJUSTRECT
:
3151 return TAB_AdjustRect (infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
3153 case TCM_SETITEMSIZE
:
3154 return TAB_SetItemSize (infoPtr
, lParam
);
3156 case TCM_REMOVEIMAGE
:
3157 FIXME("Unimplemented msg TCM_REMOVEIMAGE\n");
3160 case TCM_SETPADDING
:
3161 return TAB_SetPadding (infoPtr
, lParam
);
3163 case TCM_GETROWCOUNT
:
3164 return TAB_GetRowCount(infoPtr
);
3166 case TCM_GETUNICODEFORMAT
:
3167 return TAB_GetUnicodeFormat (infoPtr
);
3169 case TCM_SETUNICODEFORMAT
:
3170 return TAB_SetUnicodeFormat (infoPtr
, (BOOL
)wParam
);
3172 case TCM_HIGHLIGHTITEM
:
3173 return TAB_HighlightItem (infoPtr
, (INT
)wParam
, (BOOL
)LOWORD(lParam
));
3175 case TCM_GETTOOLTIPS
:
3176 return TAB_GetToolTips (infoPtr
);
3178 case TCM_SETTOOLTIPS
:
3179 return TAB_SetToolTips (infoPtr
, (HWND
)wParam
);
3181 case TCM_GETCURFOCUS
:
3182 return TAB_GetCurFocus (infoPtr
);
3184 case TCM_SETCURFOCUS
:
3185 return TAB_SetCurFocus (infoPtr
, (INT
)wParam
);
3187 case TCM_SETMINTABWIDTH
:
3188 return TAB_SetMinTabWidth(infoPtr
, (INT
)lParam
);
3190 case TCM_DESELECTALL
:
3191 FIXME("Unimplemented msg TCM_DESELECTALL\n");
3194 case TCM_GETEXTENDEDSTYLE
:
3195 FIXME("Unimplemented msg TCM_GETEXTENDEDSTYLE\n");
3198 case TCM_SETEXTENDEDSTYLE
:
3199 FIXME("Unimplemented msg TCM_SETEXTENDEDSTYLE\n");
3203 return TAB_GetFont (infoPtr
);
3206 return TAB_SetFont (infoPtr
, (HFONT
)wParam
);
3209 return TAB_Create (hwnd
, wParam
, lParam
);
3212 return TAB_Destroy (infoPtr
);
3215 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
3217 case WM_LBUTTONDOWN
:
3218 return TAB_LButtonDown (infoPtr
, wParam
, lParam
);
3221 return TAB_LButtonUp (infoPtr
);
3224 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, wParam
, lParam
);
3226 case WM_RBUTTONDOWN
:
3227 return TAB_RButtonDown (infoPtr
);
3230 return TAB_MouseMove (infoPtr
, wParam
, lParam
);
3232 case WM_PRINTCLIENT
:
3234 return TAB_Paint (infoPtr
, (HDC
)wParam
);
3237 return TAB_Size (infoPtr
);
3240 return TAB_SetRedraw (infoPtr
, (BOOL
)wParam
);
3243 return TAB_OnHScroll(infoPtr
, (int)LOWORD(wParam
), (int)HIWORD(wParam
), (HWND
)lParam
);
3245 case WM_STYLECHANGED
:
3246 TAB_SetItemBounds (infoPtr
);
3247 InvalidateRect(hwnd
, NULL
, TRUE
);
3250 case WM_SYSCOLORCHANGE
:
3251 COMCTL32_RefreshSysColors();
3254 case WM_THEMECHANGED
:
3255 return theme_changed (infoPtr
);
3259 TAB_FocusChanging(infoPtr
);
3260 break; /* Don't disturb normal focus behavior */
3263 return TAB_KeyUp(infoPtr
, wParam
);
3265 return TAB_NCHitTest(infoPtr
, lParam
);
3268 return TAB_NCCalcSize(hwnd
, wParam
, lParam
);
3271 if (uMsg
>= WM_USER
&& uMsg
< WM_APP
&& !COMCTL32_IsReflectedMessage(uMsg
))
3272 WARN("unknown msg %04x wp=%08lx lp=%08lx\n",
3273 uMsg
, wParam
, lParam
);
3276 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
3285 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
3286 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
;
3287 wndClass
.lpfnWndProc
= TAB_WindowProc
;
3288 wndClass
.cbClsExtra
= 0;
3289 wndClass
.cbWndExtra
= sizeof(TAB_INFO
*);
3290 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
3291 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+1);
3292 wndClass
.lpszClassName
= WC_TABCONTROLW
;
3294 RegisterClassW (&wndClass
);
3299 TAB_Unregister (void)
3301 UnregisterClassW (WC_TABCONTROLW
, NULL
);