push b00f9bcd3487b4cb0fef1c9e26a0e57bdeabe83d
[wine/hacks.git] / dlls / comctl32 / tab.c
bloba7e925f3d9b2a50ff0c30cfab18b2be7c4ed666e
1 /*
2 * Tab control
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
23 * NOTES
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.
32 * TODO:
34 * Styles:
35 * TCS_MULTISELECT - implement for VK_SPACE selection
36 * TCS_RIGHT
37 * TCS_RIGHTJUSTIFY
38 * TCS_SCROLLOPPOSITE
39 * TCS_SINGLELINE
40 * TCIF_RTLREADING
42 * Extended Styles:
43 * TCS_EX_REGISTERDROP
45 * Notifications:
46 * NM_RELEASEDCAPTURE
47 * TCN_FOCUSCHANGE
48 * TCN_GETOBJECT
49 * TCN_KEYDOWN
51 * Macros:
52 * TabCtrl_AdjustRect
56 #include <stdarg.h>
57 #include <string.h>
59 #include "windef.h"
60 #include "winbase.h"
61 #include "wingdi.h"
62 #include "winuser.h"
63 #include "winnls.h"
64 #include "commctrl.h"
65 #include "comctl32.h"
66 #include "uxtheme.h"
67 #include "tmschema.h"
68 #include "wine/debug.h"
69 #include <math.h>
71 WINE_DEFAULT_DEBUG_CHANNEL(tab);
73 typedef struct
75 DWORD dwState;
76 LPWSTR pszText;
77 INT iImage;
78 RECT rect; /* bounding rectangle of the item relative to the
79 * leftmost item (the leftmost item, 0, would have a
80 * "left" member of 0 in this rectangle)
82 * additionally the top member holds the row number
83 * and bottom is unused and should be 0 */
84 BYTE extra[1]; /* Space for caller supplied info, variable size */
85 } TAB_ITEM;
87 /* The size of a tab item depends on how much extra data is requested */
88 #define TAB_ITEM_SIZE(infoPtr) (FIELD_OFFSET(TAB_ITEM, extra[(infoPtr)->cbInfo]))
90 typedef struct
92 HWND hwnd; /* Tab control window */
93 HWND hwndNotify; /* notification window (parent) */
94 UINT uNumItem; /* number of tab items */
95 UINT uNumRows; /* number of tab rows */
96 INT tabHeight; /* height of the tab row */
97 INT tabWidth; /* width of tabs */
98 INT tabMinWidth; /* minimum width of items */
99 USHORT uHItemPadding; /* amount of horizontal padding, in pixels */
100 USHORT uVItemPadding; /* amount of vertical padding, in pixels */
101 USHORT uHItemPadding_s; /* Set amount of horizontal padding, in pixels */
102 USHORT uVItemPadding_s; /* Set amount of vertical padding, in pixels */
103 HFONT hFont; /* handle to the current font */
104 HCURSOR hcurArrow; /* handle to the current cursor */
105 HIMAGELIST himl; /* handle to an image list (may be 0) */
106 HWND hwndToolTip; /* handle to tab's tooltip */
107 INT leftmostVisible; /* Used for scrolling, this member contains
108 * the index of the first visible item */
109 INT iSelected; /* the currently selected item */
110 INT iHotTracked; /* the highlighted item under the mouse */
111 INT uFocus; /* item which has the focus */
112 TAB_ITEM* items; /* pointer to an array of TAB_ITEM's */
113 BOOL DoRedraw; /* flag for redrawing when tab contents is changed*/
114 BOOL needsScrolling; /* TRUE if the size of the tabs is greater than
115 * the size of the control */
116 BOOL fHeightSet; /* was the height of the tabs explicitly set? */
117 BOOL bUnicode; /* Unicode control? */
118 HWND hwndUpDown; /* Updown control used for scrolling */
119 INT cbInfo; /* Number of bytes of caller supplied info per tab */
121 DWORD exStyle; /* Extended style used, currently:
122 TCS_EX_FLATSEPARATORS, TCS_EX_REGISTERDROP */
123 } TAB_INFO;
125 /******************************************************************************
126 * Positioning constants
128 #define SELECTED_TAB_OFFSET 2
129 #define ROUND_CORNER_SIZE 2
130 #define DISPLAY_AREA_PADDINGX 2
131 #define DISPLAY_AREA_PADDINGY 2
132 #define CONTROL_BORDER_SIZEX 2
133 #define CONTROL_BORDER_SIZEY 2
134 #define BUTTON_SPACINGX 3
135 #define BUTTON_SPACINGY 3
136 #define FLAT_BTN_SPACINGX 8
137 #define DEFAULT_MIN_TAB_WIDTH 54
138 #define DEFAULT_PADDING_X 6
139 #define EXTRA_ICON_PADDING 3
141 #define TAB_GetInfoPtr(hwnd) ((TAB_INFO *)GetWindowLongPtrW(hwnd,0))
142 /* Since items are variable sized, cannot directly access them */
143 #define TAB_GetItem(info,i) \
144 ((TAB_ITEM*)((LPBYTE)info->items + (i) * TAB_ITEM_SIZE(info)))
146 #define GET_DEFAULT_MIN_TAB_WIDTH(infoPtr) (DEFAULT_MIN_TAB_WIDTH - (DEFAULT_PADDING_X - (infoPtr)->uHItemPadding) * 2)
148 /******************************************************************************
149 * Hot-tracking timer constants
151 #define TAB_HOTTRACK_TIMER 1
152 #define TAB_HOTTRACK_TIMER_INTERVAL 100 /* milliseconds */
154 static const WCHAR themeClass[] = { 'T','a','b',0 };
156 /******************************************************************************
157 * Prototypes
159 static void TAB_InvalidateTabArea(const TAB_INFO *);
160 static void TAB_EnsureSelectionVisible(TAB_INFO *);
161 static void TAB_DrawItemInterior(const TAB_INFO *, HDC, INT, RECT*);
162 static LRESULT TAB_DeselectAll(TAB_INFO *, BOOL);
164 static BOOL
165 TAB_SendSimpleNotify (const TAB_INFO *infoPtr, UINT code)
167 NMHDR nmhdr;
169 nmhdr.hwndFrom = infoPtr->hwnd;
170 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwnd, GWLP_ID);
171 nmhdr.code = code;
173 return (BOOL) SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
174 nmhdr.idFrom, (LPARAM) &nmhdr);
177 static void
178 TAB_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
179 WPARAM wParam, LPARAM lParam)
181 MSG msg;
183 msg.hwnd = hwndMsg;
184 msg.message = uMsg;
185 msg.wParam = wParam;
186 msg.lParam = lParam;
187 msg.time = GetMessageTime ();
188 msg.pt.x = (short)LOWORD(GetMessagePos ());
189 msg.pt.y = (short)HIWORD(GetMessagePos ());
191 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
194 static void
195 TAB_DumpItemExternalT(const TCITEMW *pti, UINT iItem, BOOL isW)
197 if (TRACE_ON(tab)) {
198 TRACE("external tab %d, mask=0x%08x, dwState=0x%08x, dwStateMask=0x%08x, cchTextMax=0x%08x\n",
199 iItem, pti->mask, pti->dwState, pti->dwStateMask, pti->cchTextMax);
200 TRACE("external tab %d, iImage=%d, lParam=0x%08lx, pszTextW=%s\n",
201 iItem, pti->iImage, pti->lParam, isW ? debugstr_w(pti->pszText) : debugstr_a((LPSTR)pti->pszText));
205 static void
206 TAB_DumpItemInternal(const TAB_INFO *infoPtr, UINT iItem)
208 if (TRACE_ON(tab)) {
209 TAB_ITEM *ti;
211 ti = TAB_GetItem(infoPtr, iItem);
212 TRACE("tab %d, dwState=0x%08x, pszText=%s, iImage=%d\n",
213 iItem, ti->dwState, debugstr_w(ti->pszText), ti->iImage);
214 TRACE("tab %d, rect.left=%d, rect.top(row)=%d\n",
215 iItem, ti->rect.left, ti->rect.top);
219 /* RETURNS
220 * the index of the selected tab, or -1 if no tab is selected. */
221 static inline LRESULT TAB_GetCurSel (const TAB_INFO *infoPtr)
223 return infoPtr->iSelected;
226 /* RETURNS
227 * the index of the tab item that has the focus. */
228 static inline LRESULT
229 TAB_GetCurFocus (const TAB_INFO *infoPtr)
231 return infoPtr->uFocus;
234 static inline LRESULT TAB_GetToolTips (const TAB_INFO *infoPtr)
236 if (infoPtr == NULL) return 0;
237 return (LRESULT)infoPtr->hwndToolTip;
240 static inline LRESULT TAB_SetCurSel (TAB_INFO *infoPtr, INT iItem)
242 INT prevItem = infoPtr->iSelected;
244 if (iItem < 0)
245 infoPtr->iSelected=-1;
246 else if (iItem >= infoPtr->uNumItem)
247 return -1;
248 else {
249 if (infoPtr->iSelected != iItem) {
250 TAB_GetItem(infoPtr, prevItem)->dwState &= ~TCIS_BUTTONPRESSED;
251 TAB_GetItem(infoPtr, iItem)->dwState |= TCIS_BUTTONPRESSED;
253 infoPtr->iSelected=iItem;
254 infoPtr->uFocus=iItem;
255 TAB_EnsureSelectionVisible(infoPtr);
256 TAB_InvalidateTabArea(infoPtr);
259 return prevItem;
262 static LRESULT TAB_SetCurFocus (TAB_INFO *infoPtr, INT iItem)
264 if (iItem < 0)
265 infoPtr->uFocus = -1;
266 else if (iItem < infoPtr->uNumItem) {
267 if (GetWindowLongW(infoPtr->hwnd, GWL_STYLE) & TCS_BUTTONS) {
268 FIXME("Should set input focus\n");
269 } else {
270 int oldFocus = infoPtr->uFocus;
271 if (infoPtr->iSelected != iItem || oldFocus == -1 ) {
272 infoPtr->uFocus = iItem;
273 if (oldFocus != -1) {
274 if (!TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGING)) {
275 infoPtr->iSelected = iItem;
276 TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGE);
278 else
279 infoPtr->iSelected = iItem;
280 TAB_EnsureSelectionVisible(infoPtr);
281 TAB_InvalidateTabArea(infoPtr);
286 return 0;
289 static inline LRESULT
290 TAB_SetToolTips (TAB_INFO *infoPtr, HWND hwndToolTip)
292 if (infoPtr)
293 infoPtr->hwndToolTip = hwndToolTip;
294 return 0;
297 static inline LRESULT
298 TAB_SetPadding (TAB_INFO *infoPtr, LPARAM lParam)
300 if (infoPtr)
302 infoPtr->uHItemPadding_s=LOWORD(lParam);
303 infoPtr->uVItemPadding_s=HIWORD(lParam);
305 return 0;
308 /******************************************************************************
309 * TAB_InternalGetItemRect
311 * This method will calculate the rectangle representing a given tab item in
312 * client coordinates. This method takes scrolling into account.
314 * This method returns TRUE if the item is visible in the window and FALSE
315 * if it is completely outside the client area.
317 static BOOL TAB_InternalGetItemRect(
318 const TAB_INFO* infoPtr,
319 INT itemIndex,
320 RECT* itemRect,
321 RECT* selectedRect)
323 RECT tmpItemRect,clientRect;
324 LONG lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
326 /* Perform a sanity check and a trivial visibility check. */
327 if ( (infoPtr->uNumItem <= 0) ||
328 (itemIndex >= infoPtr->uNumItem) ||
329 (!((lStyle & TCS_MULTILINE) || (lStyle & TCS_VERTICAL)) && (itemIndex < infoPtr->leftmostVisible)) )
331 TRACE("Not Visible\n");
332 /* need to initialize these to empty rects */
333 if (itemRect)
335 memset(itemRect,0,sizeof(RECT));
336 itemRect->bottom = infoPtr->tabHeight;
338 if (selectedRect)
339 memset(selectedRect,0,sizeof(RECT));
340 return FALSE;
344 * Avoid special cases in this procedure by assigning the "out"
345 * parameters if the caller didn't supply them
347 if (itemRect == NULL)
348 itemRect = &tmpItemRect;
350 /* Retrieve the unmodified item rect. */
351 *itemRect = TAB_GetItem(infoPtr,itemIndex)->rect;
353 /* calculate the times bottom and top based on the row */
354 GetClientRect(infoPtr->hwnd, &clientRect);
356 if ((lStyle & TCS_BOTTOM) && (lStyle & TCS_VERTICAL))
358 itemRect->right = clientRect.right - SELECTED_TAB_OFFSET - itemRect->left * infoPtr->tabHeight -
359 ((lStyle & TCS_BUTTONS) ? itemRect->left * BUTTON_SPACINGX : 0);
360 itemRect->left = itemRect->right - infoPtr->tabHeight;
362 else if (lStyle & TCS_VERTICAL)
364 itemRect->left = clientRect.left + SELECTED_TAB_OFFSET + itemRect->left * infoPtr->tabHeight +
365 ((lStyle & TCS_BUTTONS) ? itemRect->left * BUTTON_SPACINGX : 0);
366 itemRect->right = itemRect->left + infoPtr->tabHeight;
368 else if (lStyle & TCS_BOTTOM)
370 itemRect->bottom = clientRect.bottom - itemRect->top * infoPtr->tabHeight -
371 ((lStyle & TCS_BUTTONS) ? itemRect->top * BUTTON_SPACINGY : SELECTED_TAB_OFFSET);
372 itemRect->top = itemRect->bottom - infoPtr->tabHeight;
374 else /* not TCS_BOTTOM and not TCS_VERTICAL */
376 itemRect->top = clientRect.top + itemRect->top * infoPtr->tabHeight +
377 ((lStyle & TCS_BUTTONS) ? itemRect->top * BUTTON_SPACINGY : SELECTED_TAB_OFFSET);
378 itemRect->bottom = itemRect->top + infoPtr->tabHeight;
382 * "scroll" it to make sure the item at the very left of the
383 * tab control is the leftmost visible tab.
385 if(lStyle & TCS_VERTICAL)
387 OffsetRect(itemRect,
389 -TAB_GetItem(infoPtr, infoPtr->leftmostVisible)->rect.top);
392 * Move the rectangle so the first item is slightly offset from
393 * the bottom of the tab control.
395 OffsetRect(itemRect,
397 SELECTED_TAB_OFFSET);
399 } else
401 OffsetRect(itemRect,
402 -TAB_GetItem(infoPtr, infoPtr->leftmostVisible)->rect.left,
406 * Move the rectangle so the first item is slightly offset from
407 * the left of the tab control.
409 OffsetRect(itemRect,
410 SELECTED_TAB_OFFSET,
413 TRACE("item %d tab h=%d, rect=(%s)\n",
414 itemIndex, infoPtr->tabHeight, wine_dbgstr_rect(itemRect));
416 /* Now, calculate the position of the item as if it were selected. */
417 if (selectedRect!=NULL)
419 CopyRect(selectedRect, itemRect);
421 /* The rectangle of a selected item is a bit wider. */
422 if(lStyle & TCS_VERTICAL)
423 InflateRect(selectedRect, 0, SELECTED_TAB_OFFSET);
424 else
425 InflateRect(selectedRect, SELECTED_TAB_OFFSET, 0);
427 /* If it also a bit higher. */
428 if ((lStyle & TCS_BOTTOM) && (lStyle & TCS_VERTICAL))
430 selectedRect->left -= 2; /* the border is thicker on the right */
431 selectedRect->right += SELECTED_TAB_OFFSET;
433 else if (lStyle & TCS_VERTICAL)
435 selectedRect->left -= SELECTED_TAB_OFFSET;
436 selectedRect->right += 1;
438 else if (lStyle & TCS_BOTTOM)
440 selectedRect->bottom += SELECTED_TAB_OFFSET;
442 else /* not TCS_BOTTOM and not TCS_VERTICAL */
444 selectedRect->top -= SELECTED_TAB_OFFSET;
445 selectedRect->bottom -= 1;
449 /* Check for visibility */
450 if (lStyle & TCS_VERTICAL)
451 return (itemRect->top < clientRect.bottom) && (itemRect->bottom > clientRect.top);
452 else
453 return (itemRect->left < clientRect.right) && (itemRect->right > clientRect.left);
456 static inline BOOL
457 TAB_GetItemRect(const TAB_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
459 return TAB_InternalGetItemRect(infoPtr, wParam, (LPRECT)lParam, NULL);
462 /******************************************************************************
463 * TAB_KeyUp
465 * This method is called to handle keyboard input
467 static LRESULT TAB_KeyUp(TAB_INFO* infoPtr, WPARAM keyCode)
469 int newItem = -1;
471 switch (keyCode)
473 case VK_LEFT:
474 newItem = infoPtr->uFocus - 1;
475 break;
476 case VK_RIGHT:
477 newItem = infoPtr->uFocus + 1;
478 break;
482 * If we changed to a valid item, change the selection
484 if (newItem >= 0 &&
485 newItem < infoPtr->uNumItem &&
486 infoPtr->uFocus != newItem)
488 if (!TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGING))
490 TAB_SetCurSel(infoPtr, newItem);
491 TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGE);
495 return 0;
498 /******************************************************************************
499 * TAB_FocusChanging
501 * This method is called whenever the focus goes in or out of this control
502 * it is used to update the visual state of the control.
504 static void TAB_FocusChanging(const TAB_INFO *infoPtr)
506 RECT selectedRect;
507 BOOL isVisible;
510 * Get the rectangle for the item.
512 isVisible = TAB_InternalGetItemRect(infoPtr,
513 infoPtr->uFocus,
514 NULL,
515 &selectedRect);
518 * If the rectangle is not completely invisible, invalidate that
519 * portion of the window.
521 if (isVisible)
523 TRACE("invalidate (%s)\n", wine_dbgstr_rect(&selectedRect));
524 InvalidateRect(infoPtr->hwnd, &selectedRect, TRUE);
528 static INT TAB_InternalHitTest (const TAB_INFO *infoPtr, POINT pt, UINT *flags)
530 RECT rect;
531 INT iCount;
533 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++)
535 TAB_InternalGetItemRect(infoPtr, iCount, &rect, NULL);
537 if (PtInRect(&rect, pt))
539 *flags = TCHT_ONITEM;
540 return iCount;
544 *flags = TCHT_NOWHERE;
545 return -1;
548 static inline LRESULT
549 TAB_HitTest (const TAB_INFO *infoPtr, LPTCHITTESTINFO lptest)
551 return TAB_InternalHitTest (infoPtr, lptest->pt, &lptest->flags);
554 /******************************************************************************
555 * TAB_NCHitTest
557 * Napster v2b5 has a tab control for its main navigation which has a client
558 * area that covers the whole area of the dialog pages.
559 * That's why it receives all msgs for that area and the underlying dialog ctrls
560 * are dead.
561 * So I decided that we should handle WM_NCHITTEST here and return
562 * HTTRANSPARENT if we don't hit the tab control buttons.
563 * FIXME: WM_NCHITTEST handling correct ? Fix it if you know that Windows
564 * doesn't do it that way. Maybe depends on tab control styles ?
566 static inline LRESULT
567 TAB_NCHitTest (const TAB_INFO *infoPtr, LPARAM lParam)
569 POINT pt;
570 UINT dummyflag;
572 pt.x = (short)LOWORD(lParam);
573 pt.y = (short)HIWORD(lParam);
574 ScreenToClient(infoPtr->hwnd, &pt);
576 if (TAB_InternalHitTest(infoPtr, pt, &dummyflag) == -1)
577 return HTTRANSPARENT;
578 else
579 return HTCLIENT;
582 static LRESULT
583 TAB_LButtonDown (TAB_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
585 POINT pt;
586 INT newItem;
587 UINT dummy;
588 LONG lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
590 if (infoPtr->hwndToolTip)
591 TAB_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwnd,
592 WM_LBUTTONDOWN, wParam, lParam);
594 if (GetWindowLongW(infoPtr->hwnd, GWL_STYLE) & TCS_FOCUSONBUTTONDOWN ) {
595 SetFocus (infoPtr->hwnd);
598 if (infoPtr->hwndToolTip)
599 TAB_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwnd,
600 WM_LBUTTONDOWN, wParam, lParam);
602 pt.x = (short)LOWORD(lParam);
603 pt.y = (short)HIWORD(lParam);
605 newItem = TAB_InternalHitTest (infoPtr, pt, &dummy);
607 TRACE("On Tab, item %d\n", newItem);
609 if ((newItem != -1) && (infoPtr->iSelected != newItem))
611 if ((lStyle & TCS_BUTTONS) && (lStyle & TCS_MULTISELECT) &&
612 (wParam & MK_CONTROL))
614 RECT r;
616 /* toggle multiselection */
617 TAB_GetItem(infoPtr, newItem)->dwState ^= TCIS_BUTTONPRESSED;
618 if (TAB_InternalGetItemRect (infoPtr, newItem, &r, NULL))
619 InvalidateRect (infoPtr->hwnd, &r, TRUE);
621 else
623 INT i;
624 BOOL pressed = FALSE;
626 /* any button pressed ? */
627 for (i = 0; i < infoPtr->uNumItem; i++)
628 if ((TAB_GetItem (infoPtr, i)->dwState & TCIS_BUTTONPRESSED) &&
629 (infoPtr->iSelected != i))
631 pressed = TRUE;
632 break;
635 TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGING);
637 if (pressed)
638 TAB_DeselectAll (infoPtr, FALSE);
639 else
640 TAB_SetCurSel(infoPtr, newItem);
642 TAB_SendSimpleNotify(infoPtr, TCN_SELCHANGE);
646 return 0;
649 static inline LRESULT
650 TAB_LButtonUp (const TAB_INFO *infoPtr)
652 TAB_SendSimpleNotify(infoPtr, NM_CLICK);
654 return 0;
657 static inline LRESULT
658 TAB_RButtonDown (const TAB_INFO *infoPtr)
660 TAB_SendSimpleNotify(infoPtr, NM_RCLICK);
661 return 0;
664 /******************************************************************************
665 * TAB_DrawLoneItemInterior
667 * This calls TAB_DrawItemInterior. However, TAB_DrawItemInterior is normally
668 * called by TAB_DrawItem which is normally called by TAB_Refresh which sets
669 * up the device context and font. This routine does the same setup but
670 * only calls TAB_DrawItemInterior for the single specified item.
672 static void
673 TAB_DrawLoneItemInterior(const TAB_INFO* infoPtr, int iItem)
675 HDC hdc = GetDC(infoPtr->hwnd);
676 RECT r, rC;
678 /* Clip UpDown control to not draw over it */
679 if (infoPtr->needsScrolling)
681 GetWindowRect(infoPtr->hwnd, &rC);
682 GetWindowRect(infoPtr->hwndUpDown, &r);
683 ExcludeClipRect(hdc, r.left - rC.left, r.top - rC.top, r.right - rC.left, r.bottom - rC.top);
685 TAB_DrawItemInterior(infoPtr, hdc, iItem, NULL);
686 ReleaseDC(infoPtr->hwnd, hdc);
689 /* update a tab after hottracking - invalidate it or just redraw the interior,
690 * based on whether theming is used or not */
691 static inline void hottrack_refresh(const TAB_INFO *infoPtr, int tabIndex)
693 if (tabIndex == -1) return;
695 if (GetWindowTheme (infoPtr->hwnd))
697 RECT rect;
698 TAB_InternalGetItemRect(infoPtr, tabIndex, &rect, NULL);
699 InvalidateRect (infoPtr->hwnd, &rect, FALSE);
701 else
702 TAB_DrawLoneItemInterior(infoPtr, tabIndex);
705 /******************************************************************************
706 * TAB_HotTrackTimerProc
708 * When a mouse-move event causes a tab to be highlighted (hot-tracking), a
709 * timer is setup so we can check if the mouse is moved out of our window.
710 * (We don't get an event when the mouse leaves, the mouse-move events just
711 * stop being delivered to our window and just start being delivered to
712 * another window.) This function is called when the timer triggers so
713 * we can check if the mouse has left our window. If so, we un-highlight
714 * the hot-tracked tab.
716 static void CALLBACK
717 TAB_HotTrackTimerProc
719 HWND hwnd, /* handle of window for timer messages */
720 UINT uMsg, /* WM_TIMER message */
721 UINT_PTR idEvent, /* timer identifier */
722 DWORD dwTime /* current system time */
725 TAB_INFO* infoPtr = TAB_GetInfoPtr(hwnd);
727 if (infoPtr != NULL && infoPtr->iHotTracked >= 0)
729 POINT pt;
732 ** If we can't get the cursor position, or if the cursor is outside our
733 ** window, we un-highlight the hot-tracked tab. Note that the cursor is
734 ** "outside" even if it is within our bounding rect if another window
735 ** overlaps. Note also that the case where the cursor stayed within our
736 ** window but has moved off the hot-tracked tab will be handled by the
737 ** WM_MOUSEMOVE event.
739 if (!GetCursorPos(&pt) || WindowFromPoint(pt) != hwnd)
741 /* Redraw iHotTracked to look normal */
742 INT iRedraw = infoPtr->iHotTracked;
743 infoPtr->iHotTracked = -1;
744 hottrack_refresh (infoPtr, iRedraw);
746 /* Kill this timer */
747 KillTimer(hwnd, TAB_HOTTRACK_TIMER);
752 /******************************************************************************
753 * TAB_RecalcHotTrack
755 * If a tab control has the TCS_HOTTRACK style, then the tab under the mouse
756 * should be highlighted. This function determines which tab in a tab control,
757 * if any, is under the mouse and records that information. The caller may
758 * supply output parameters to receive the item number of the tab item which
759 * was highlighted but isn't any longer and of the tab item which is now
760 * highlighted but wasn't previously. The caller can use this information to
761 * selectively redraw those tab items.
763 * If the caller has a mouse position, it can supply it through the pos
764 * parameter. For example, TAB_MouseMove does this. Otherwise, the caller
765 * supplies NULL and this function determines the current mouse position
766 * itself.
768 static void
769 TAB_RecalcHotTrack
771 TAB_INFO* infoPtr,
772 const LPARAM* pos,
773 int* out_redrawLeave,
774 int* out_redrawEnter
777 int item = -1;
780 if (out_redrawLeave != NULL)
781 *out_redrawLeave = -1;
782 if (out_redrawEnter != NULL)
783 *out_redrawEnter = -1;
785 if ((GetWindowLongW(infoPtr->hwnd, GWL_STYLE) & TCS_HOTTRACK)
786 || GetWindowTheme (infoPtr->hwnd))
788 POINT pt;
789 UINT flags;
791 if (pos == NULL)
793 GetCursorPos(&pt);
794 ScreenToClient(infoPtr->hwnd, &pt);
796 else
798 pt.x = (short)LOWORD(*pos);
799 pt.y = (short)HIWORD(*pos);
802 item = TAB_InternalHitTest(infoPtr, pt, &flags);
805 if (item != infoPtr->iHotTracked)
807 if (infoPtr->iHotTracked >= 0)
809 /* Mark currently hot-tracked to be redrawn to look normal */
810 if (out_redrawLeave != NULL)
811 *out_redrawLeave = infoPtr->iHotTracked;
813 if (item < 0)
815 /* Kill timer which forces recheck of mouse pos */
816 KillTimer(infoPtr->hwnd, TAB_HOTTRACK_TIMER);
819 else
821 /* Start timer so we recheck mouse pos */
822 UINT timerID = SetTimer
824 infoPtr->hwnd,
825 TAB_HOTTRACK_TIMER,
826 TAB_HOTTRACK_TIMER_INTERVAL,
827 TAB_HotTrackTimerProc
830 if (timerID == 0)
831 return; /* Hot tracking not available */
834 infoPtr->iHotTracked = item;
836 if (item >= 0)
838 /* Mark new hot-tracked to be redrawn to look highlighted */
839 if (out_redrawEnter != NULL)
840 *out_redrawEnter = item;
845 /******************************************************************************
846 * TAB_MouseMove
848 * Handles the mouse-move event. Updates tooltips. Updates hot-tracking.
850 static LRESULT
851 TAB_MouseMove (TAB_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
853 int redrawLeave;
854 int redrawEnter;
856 if (infoPtr->hwndToolTip)
857 TAB_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwnd,
858 WM_LBUTTONDOWN, wParam, lParam);
860 /* Determine which tab to highlight. Redraw tabs which change highlight
861 ** status. */
862 TAB_RecalcHotTrack(infoPtr, &lParam, &redrawLeave, &redrawEnter);
864 hottrack_refresh (infoPtr, redrawLeave);
865 hottrack_refresh (infoPtr, redrawEnter);
867 return 0;
870 /******************************************************************************
871 * TAB_AdjustRect
873 * Calculates the tab control's display area given the window rectangle or
874 * the window rectangle given the requested display rectangle.
876 static LRESULT TAB_AdjustRect(const TAB_INFO *infoPtr, WPARAM fLarger, LPRECT prc)
878 DWORD lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
879 LONG *iRightBottom, *iLeftTop;
881 TRACE ("hwnd=%p fLarger=%ld (%s)\n", infoPtr->hwnd, fLarger,
882 wine_dbgstr_rect(prc));
884 if (!prc) return -1;
886 if(lStyle & TCS_VERTICAL)
888 iRightBottom = &(prc->right);
889 iLeftTop = &(prc->left);
891 else
893 iRightBottom = &(prc->bottom);
894 iLeftTop = &(prc->top);
897 if (fLarger) /* Go from display rectangle */
899 /* Add the height of the tabs. */
900 if (lStyle & TCS_BOTTOM)
901 *iRightBottom += infoPtr->tabHeight * infoPtr->uNumRows;
902 else
903 *iLeftTop -= infoPtr->tabHeight * infoPtr->uNumRows +
904 ((lStyle & TCS_BUTTONS)? 3 * (infoPtr->uNumRows - 1) : 0);
906 /* Inflate the rectangle for the padding */
907 InflateRect(prc, DISPLAY_AREA_PADDINGX, DISPLAY_AREA_PADDINGY);
909 /* Inflate for the border */
910 InflateRect(prc, CONTROL_BORDER_SIZEX, CONTROL_BORDER_SIZEY);
912 else /* Go from window rectangle. */
914 /* Deflate the rectangle for the border */
915 InflateRect(prc, -CONTROL_BORDER_SIZEX, -CONTROL_BORDER_SIZEY);
917 /* Deflate the rectangle for the padding */
918 InflateRect(prc, -DISPLAY_AREA_PADDINGX, -DISPLAY_AREA_PADDINGY);
920 /* Remove the height of the tabs. */
921 if (lStyle & TCS_BOTTOM)
922 *iRightBottom -= infoPtr->tabHeight * infoPtr->uNumRows;
923 else
924 *iLeftTop += (infoPtr->tabHeight) * infoPtr->uNumRows +
925 ((lStyle & TCS_BUTTONS)? 3 * (infoPtr->uNumRows - 1) : 0);
928 return 0;
931 /******************************************************************************
932 * TAB_OnHScroll
934 * This method will handle the notification from the scroll control and
935 * perform the scrolling operation on the tab control.
937 static LRESULT TAB_OnHScroll(TAB_INFO *infoPtr, int nScrollCode, int nPos)
939 if(nScrollCode == SB_THUMBPOSITION && nPos != infoPtr->leftmostVisible)
941 if(nPos < infoPtr->leftmostVisible)
942 infoPtr->leftmostVisible--;
943 else
944 infoPtr->leftmostVisible++;
946 TAB_RecalcHotTrack(infoPtr, NULL, NULL, NULL);
947 TAB_InvalidateTabArea(infoPtr);
948 SendMessageW(infoPtr->hwndUpDown, UDM_SETPOS, 0,
949 MAKELONG(infoPtr->leftmostVisible, 0));
952 return 0;
955 /******************************************************************************
956 * TAB_SetupScrolling
958 * This method will check the current scrolling state and make sure the
959 * scrolling control is displayed (or not).
961 static void TAB_SetupScrolling(
962 HWND hwnd,
963 TAB_INFO* infoPtr,
964 const RECT* clientRect)
966 static const WCHAR msctls_updown32W[] = { 'm','s','c','t','l','s','_','u','p','d','o','w','n','3','2',0 };
967 static const WCHAR emptyW[] = { 0 };
968 INT maxRange = 0;
969 DWORD lStyle = GetWindowLongW(hwnd, GWL_STYLE);
971 if (infoPtr->needsScrolling)
973 RECT controlPos;
974 INT vsize, tabwidth;
977 * Calculate the position of the scroll control.
979 if(lStyle & TCS_VERTICAL)
981 controlPos.right = clientRect->right;
982 controlPos.left = controlPos.right - 2 * GetSystemMetrics(SM_CXHSCROLL);
984 if (lStyle & TCS_BOTTOM)
986 controlPos.top = clientRect->bottom - infoPtr->tabHeight;
987 controlPos.bottom = controlPos.top + GetSystemMetrics(SM_CYHSCROLL);
989 else
991 controlPos.bottom = clientRect->top + infoPtr->tabHeight;
992 controlPos.top = controlPos.bottom - GetSystemMetrics(SM_CYHSCROLL);
995 else
997 controlPos.right = clientRect->right;
998 controlPos.left = controlPos.right - 2 * GetSystemMetrics(SM_CXHSCROLL);
1000 if (lStyle & TCS_BOTTOM)
1002 controlPos.top = clientRect->bottom - infoPtr->tabHeight;
1003 controlPos.bottom = controlPos.top + GetSystemMetrics(SM_CYHSCROLL);
1005 else
1007 controlPos.bottom = clientRect->top + infoPtr->tabHeight;
1008 controlPos.top = controlPos.bottom - GetSystemMetrics(SM_CYHSCROLL);
1013 * If we don't have a scroll control yet, we want to create one.
1014 * If we have one, we want to make sure it's positioned properly.
1016 if (infoPtr->hwndUpDown==0)
1018 infoPtr->hwndUpDown = CreateWindowW(msctls_updown32W, emptyW,
1019 WS_VISIBLE | WS_CHILD | UDS_HORZ,
1020 controlPos.left, controlPos.top,
1021 controlPos.right - controlPos.left,
1022 controlPos.bottom - controlPos.top,
1023 hwnd, NULL, NULL, NULL);
1025 else
1027 SetWindowPos(infoPtr->hwndUpDown,
1028 NULL,
1029 controlPos.left, controlPos.top,
1030 controlPos.right - controlPos.left,
1031 controlPos.bottom - controlPos.top,
1032 SWP_SHOWWINDOW | SWP_NOZORDER);
1035 /* Now calculate upper limit of the updown control range.
1036 * We do this by calculating how many tabs will be offscreen when the
1037 * last tab is visible.
1039 if(infoPtr->uNumItem)
1041 vsize = clientRect->right - (controlPos.right - controlPos.left + 1);
1042 maxRange = infoPtr->uNumItem;
1043 tabwidth = TAB_GetItem(infoPtr, infoPtr->uNumItem - 1)->rect.right;
1045 for(; maxRange > 0; maxRange--)
1047 if(tabwidth - TAB_GetItem(infoPtr,maxRange - 1)->rect.left > vsize)
1048 break;
1051 if(maxRange == infoPtr->uNumItem)
1052 maxRange--;
1055 else
1057 /* If we once had a scroll control... hide it */
1058 if (infoPtr->hwndUpDown!=0)
1059 ShowWindow(infoPtr->hwndUpDown, SW_HIDE);
1061 if (infoPtr->hwndUpDown)
1062 SendMessageW(infoPtr->hwndUpDown, UDM_SETRANGE32, 0, maxRange);
1065 /******************************************************************************
1066 * TAB_SetItemBounds
1068 * This method will calculate the position rectangles of all the items in the
1069 * control. The rectangle calculated starts at 0 for the first item in the
1070 * list and ignores scrolling and selection.
1071 * It also uses the current font to determine the height of the tab row and
1072 * it checks if all the tabs fit in the client area of the window. If they
1073 * don't, a scrolling control is added.
1075 static void TAB_SetItemBounds (TAB_INFO *infoPtr)
1077 LONG lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
1078 TEXTMETRICW fontMetrics;
1079 UINT curItem;
1080 INT curItemLeftPos;
1081 INT curItemRowCount;
1082 HFONT hFont, hOldFont;
1083 HDC hdc;
1084 RECT clientRect;
1085 INT iTemp;
1086 RECT* rcItem;
1087 INT iIndex;
1088 INT icon_width = 0;
1091 * We need to get text information so we need a DC and we need to select
1092 * a font.
1094 hdc = GetDC(infoPtr->hwnd);
1096 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1097 hOldFont = SelectObject (hdc, hFont);
1100 * We will base the rectangle calculations on the client rectangle
1101 * of the control.
1103 GetClientRect(infoPtr->hwnd, &clientRect);
1105 /* if TCS_VERTICAL then swap the height and width so this code places the
1106 tabs along the top of the rectangle and we can just rotate them after
1107 rather than duplicate all of the below code */
1108 if(lStyle & TCS_VERTICAL)
1110 iTemp = clientRect.bottom;
1111 clientRect.bottom = clientRect.right;
1112 clientRect.right = iTemp;
1115 /* Now use hPadding and vPadding */
1116 infoPtr->uHItemPadding = infoPtr->uHItemPadding_s;
1117 infoPtr->uVItemPadding = infoPtr->uVItemPadding_s;
1119 /* The leftmost item will be "0" aligned */
1120 curItemLeftPos = 0;
1121 curItemRowCount = infoPtr->uNumItem ? 1 : 0;
1123 if (!(infoPtr->fHeightSet))
1125 int item_height;
1126 int icon_height = 0;
1128 /* Use the current font to determine the height of a tab. */
1129 GetTextMetricsW(hdc, &fontMetrics);
1131 /* Get the icon height */
1132 if (infoPtr->himl)
1133 ImageList_GetIconSize(infoPtr->himl, 0, &icon_height);
1135 /* Take the highest between font or icon */
1136 if (fontMetrics.tmHeight > icon_height)
1137 item_height = fontMetrics.tmHeight + 2;
1138 else
1139 item_height = icon_height;
1142 * Make sure there is enough space for the letters + icon + growing the
1143 * selected item + extra space for the selected item.
1145 infoPtr->tabHeight = item_height +
1146 ((lStyle & TCS_BUTTONS) ? 2 : 1) *
1147 infoPtr->uVItemPadding;
1149 TRACE("tabH=%d, tmH=%d, iconh=%d\n",
1150 infoPtr->tabHeight, fontMetrics.tmHeight, icon_height);
1153 TRACE("client right=%d\n", clientRect.right);
1155 /* Get the icon width */
1156 if (infoPtr->himl)
1158 ImageList_GetIconSize(infoPtr->himl, &icon_width, 0);
1160 if (lStyle & TCS_FIXEDWIDTH)
1161 icon_width += 4;
1162 else
1163 /* Add padding if icon is present */
1164 icon_width += infoPtr->uHItemPadding;
1167 for (curItem = 0; curItem < infoPtr->uNumItem; curItem++)
1169 TAB_ITEM *curr = TAB_GetItem(infoPtr, curItem);
1171 /* Set the leftmost position of the tab. */
1172 curr->rect.left = curItemLeftPos;
1174 if (lStyle & TCS_FIXEDWIDTH)
1176 curr->rect.right = curr->rect.left +
1177 max(infoPtr->tabWidth, icon_width);
1179 else if (!curr->pszText)
1181 /* If no text use minimum tab width including padding. */
1182 if (infoPtr->tabMinWidth < 0)
1183 curr->rect.right = curr->rect.left + GET_DEFAULT_MIN_TAB_WIDTH(infoPtr);
1184 else
1186 curr->rect.right = curr->rect.left + infoPtr->tabMinWidth;
1188 /* Add extra padding if icon is present */
1189 if (infoPtr->himl && infoPtr->tabMinWidth > 0 && infoPtr->tabMinWidth < DEFAULT_MIN_TAB_WIDTH
1190 && infoPtr->uHItemPadding > 1)
1191 curr->rect.right += EXTRA_ICON_PADDING * (infoPtr->uHItemPadding-1);
1194 else
1196 int tabwidth;
1197 SIZE size;
1198 /* Calculate how wide the tab is depending on the text it contains */
1199 GetTextExtentPoint32W(hdc, curr->pszText,
1200 lstrlenW(curr->pszText), &size);
1202 tabwidth = size.cx + icon_width + 2 * infoPtr->uHItemPadding;
1204 if (infoPtr->tabMinWidth < 0)
1205 tabwidth = max(tabwidth, GET_DEFAULT_MIN_TAB_WIDTH(infoPtr));
1206 else
1207 tabwidth = max(tabwidth, infoPtr->tabMinWidth);
1209 curr->rect.right = curr->rect.left + tabwidth;
1210 TRACE("for <%s>, l,r=%d,%d\n",
1211 debugstr_w(curr->pszText), curr->rect.left, curr->rect.right);
1215 * Check if this is a multiline tab control and if so
1216 * check to see if we should wrap the tabs
1218 * Wrap all these tabs. We will arrange them evenly later.
1222 if (((lStyle & TCS_MULTILINE) || (lStyle & TCS_VERTICAL)) &&
1223 (curr->rect.right >
1224 (clientRect.right - CONTROL_BORDER_SIZEX - DISPLAY_AREA_PADDINGX)))
1226 curr->rect.right -= curr->rect.left;
1228 curr->rect.left = 0;
1229 curItemRowCount++;
1230 TRACE("wrapping <%s>, l,r=%d,%d\n", debugstr_w(curr->pszText),
1231 curr->rect.left, curr->rect.right);
1234 curr->rect.bottom = 0;
1235 curr->rect.top = curItemRowCount - 1;
1237 TRACE("Rect: %s\n", wine_dbgstr_rect(&curr->rect));
1240 * The leftmost position of the next item is the rightmost position
1241 * of this one.
1243 if (lStyle & TCS_BUTTONS)
1245 curItemLeftPos = curr->rect.right + BUTTON_SPACINGX;
1246 if (lStyle & TCS_FLATBUTTONS)
1247 curItemLeftPos += FLAT_BTN_SPACINGX;
1249 else
1250 curItemLeftPos = curr->rect.right;
1253 if (!((lStyle & TCS_MULTILINE) || (lStyle & TCS_VERTICAL)))
1256 * Check if we need a scrolling control.
1258 infoPtr->needsScrolling = (curItemLeftPos + (2 * SELECTED_TAB_OFFSET) >
1259 clientRect.right);
1261 /* Don't need scrolling, then update infoPtr->leftmostVisible */
1262 if(!infoPtr->needsScrolling)
1263 infoPtr->leftmostVisible = 0;
1265 else
1268 * No scrolling in Multiline or Vertical styles.
1270 infoPtr->needsScrolling = FALSE;
1271 infoPtr->leftmostVisible = 0;
1273 TAB_SetupScrolling(infoPtr->hwnd, infoPtr, &clientRect);
1275 /* Set the number of rows */
1276 infoPtr->uNumRows = curItemRowCount;
1278 /* Arrange all tabs evenly if style says so */
1279 if (!(lStyle & TCS_RAGGEDRIGHT) &&
1280 ((lStyle & TCS_MULTILINE) || (lStyle & TCS_VERTICAL)) &&
1281 (infoPtr->uNumItem > 0) &&
1282 (infoPtr->uNumRows > 1))
1284 INT tabPerRow,remTab,iRow;
1285 UINT iItm;
1286 INT iCount=0;
1289 * Ok windows tries to even out the rows. place the same
1290 * number of tabs in each row. So lets give that a shot
1293 tabPerRow = infoPtr->uNumItem / (infoPtr->uNumRows);
1294 remTab = infoPtr->uNumItem % (infoPtr->uNumRows);
1296 for (iItm=0,iRow=0,iCount=0,curItemLeftPos=0;
1297 iItm<infoPtr->uNumItem;
1298 iItm++,iCount++)
1300 /* normalize the current rect */
1301 TAB_ITEM *curr = TAB_GetItem(infoPtr, iItm);
1303 /* shift the item to the left side of the clientRect */
1304 curr->rect.right -= curr->rect.left;
1305 curr->rect.left = 0;
1307 TRACE("r=%d, cl=%d, cl.r=%d, iCount=%d, iRow=%d, uNumRows=%d, remTab=%d, tabPerRow=%d\n",
1308 curr->rect.right, curItemLeftPos, clientRect.right,
1309 iCount, iRow, infoPtr->uNumRows, remTab, tabPerRow);
1311 /* if we have reached the maximum number of tabs on this row */
1312 /* move to the next row, reset our current item left position and */
1313 /* the count of items on this row */
1315 if (lStyle & TCS_VERTICAL) {
1316 /* Vert: Add the remaining tabs in the *last* remainder rows */
1317 if (iCount >= ((iRow>=(INT)infoPtr->uNumRows - remTab)?tabPerRow + 1:tabPerRow)) {
1318 iRow++;
1319 curItemLeftPos = 0;
1320 iCount = 0;
1322 } else {
1323 /* Horz: Add the remaining tabs in the *first* remainder rows */
1324 if (iCount >= ((iRow<remTab)?tabPerRow + 1:tabPerRow)) {
1325 iRow++;
1326 curItemLeftPos = 0;
1327 iCount = 0;
1331 /* shift the item to the right to place it as the next item in this row */
1332 curr->rect.left += curItemLeftPos;
1333 curr->rect.right += curItemLeftPos;
1334 curr->rect.top = iRow;
1335 if (lStyle & TCS_BUTTONS)
1337 curItemLeftPos = curr->rect.right + 1;
1338 if (lStyle & TCS_FLATBUTTONS)
1339 curItemLeftPos += FLAT_BTN_SPACINGX;
1341 else
1342 curItemLeftPos = curr->rect.right;
1344 TRACE("arranging <%s>, l,r=%d,%d, row=%d\n",
1345 debugstr_w(curr->pszText), curr->rect.left,
1346 curr->rect.right, curr->rect.top);
1350 * Justify the rows
1353 INT widthDiff, iIndexStart=0, iIndexEnd=0;
1354 INT remainder;
1355 INT iCount=0;
1357 while(iIndexStart < infoPtr->uNumItem)
1359 TAB_ITEM *start = TAB_GetItem(infoPtr, iIndexStart);
1362 * find the index of the row
1364 /* find the first item on the next row */
1365 for (iIndexEnd=iIndexStart;
1366 (iIndexEnd < infoPtr->uNumItem) &&
1367 (TAB_GetItem(infoPtr, iIndexEnd)->rect.top ==
1368 start->rect.top) ;
1369 iIndexEnd++)
1370 /* intentionally blank */;
1373 * we need to justify these tabs so they fill the whole given
1374 * client area
1377 /* find the amount of space remaining on this row */
1378 widthDiff = clientRect.right - (2 * SELECTED_TAB_OFFSET) -
1379 TAB_GetItem(infoPtr, iIndexEnd - 1)->rect.right;
1381 /* iCount is the number of tab items on this row */
1382 iCount = iIndexEnd - iIndexStart;
1384 if (iCount > 1)
1386 remainder = widthDiff % iCount;
1387 widthDiff = widthDiff / iCount;
1388 /* add widthDiff/iCount, or extra space/items on row, to each item on this row */
1389 for (iIndex=iIndexStart, iCount=0; iIndex < iIndexEnd; iIndex++, iCount++)
1391 TAB_ITEM *item = TAB_GetItem(infoPtr, iIndex);
1393 item->rect.left += iCount * widthDiff;
1394 item->rect.right += (iCount + 1) * widthDiff;
1396 TRACE("adjusting 1 <%s>, l,r=%d,%d\n",
1397 debugstr_w(item->pszText),
1398 item->rect.left, item->rect.right);
1401 TAB_GetItem(infoPtr, iIndex - 1)->rect.right += remainder;
1403 else /* we have only one item on this row, make it take up the entire row */
1405 start->rect.left = clientRect.left;
1406 start->rect.right = clientRect.right - 4;
1408 TRACE("adjusting 2 <%s>, l,r=%d,%d\n",
1409 debugstr_w(start->pszText),
1410 start->rect.left, start->rect.right);
1415 iIndexStart = iIndexEnd;
1420 /* if TCS_VERTICAL rotate the tabs so they are along the side of the clientRect */
1421 if(lStyle & TCS_VERTICAL)
1423 RECT rcOriginal;
1424 for(iIndex = 0; iIndex < infoPtr->uNumItem; iIndex++)
1426 rcItem = &TAB_GetItem(infoPtr, iIndex)->rect;
1428 rcOriginal = *rcItem;
1430 /* this is rotating the items by 90 degrees clockwise around the center of the control */
1431 rcItem->top = (rcOriginal.left - clientRect.left);
1432 rcItem->bottom = rcItem->top + (rcOriginal.right - rcOriginal.left);
1433 rcItem->left = rcOriginal.top;
1434 rcItem->right = rcOriginal.bottom;
1438 TAB_EnsureSelectionVisible(infoPtr);
1439 TAB_RecalcHotTrack(infoPtr, NULL, NULL, NULL);
1441 /* Cleanup */
1442 SelectObject (hdc, hOldFont);
1443 ReleaseDC (infoPtr->hwnd, hdc);
1447 static void
1448 TAB_EraseTabInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect)
1450 LONG lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
1451 HBRUSH hbr = CreateSolidBrush (comctl32_color.clrBtnFace);
1452 BOOL deleteBrush = TRUE;
1453 RECT rTemp = *drawRect;
1455 if (lStyle & TCS_BUTTONS)
1457 if (iItem == infoPtr->iSelected)
1459 /* Background color */
1460 if (!(lStyle & TCS_OWNERDRAWFIXED))
1462 DeleteObject(hbr);
1463 hbr = GetSysColorBrush(COLOR_SCROLLBAR);
1465 SetTextColor(hdc, comctl32_color.clr3dFace);
1466 SetBkColor(hdc, comctl32_color.clr3dHilight);
1468 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1469 * we better use 0x55aa bitmap brush to make scrollbar's background
1470 * look different from the window background.
1472 if (comctl32_color.clr3dHilight == comctl32_color.clrWindow)
1473 hbr = COMCTL32_hPattern55AABrush;
1475 deleteBrush = FALSE;
1477 FillRect(hdc, &rTemp, hbr);
1479 else /* ! selected */
1481 if (lStyle & TCS_FLATBUTTONS)
1483 FillRect(hdc, drawRect, hbr);
1484 if (iItem == infoPtr->iHotTracked)
1486 DrawEdge(hdc, drawRect, EDGE_RAISED, BF_SOFT|BF_TOPLEFT);
1487 DrawEdge(hdc, drawRect, EDGE_RAISED, BF_FLAT|BF_BOTTOMRIGHT);
1490 else
1491 FillRect(hdc, &rTemp, hbr);
1495 else /* !TCS_BUTTONS */
1497 InflateRect(&rTemp, -2, -2);
1498 if (!GetWindowTheme (infoPtr->hwnd))
1499 FillRect(hdc, &rTemp, hbr);
1502 /* highlighting is drawn on top of previous fills */
1503 if (TAB_GetItem(infoPtr, iItem)->dwState & TCIS_HIGHLIGHTED)
1505 if (deleteBrush)
1507 DeleteObject(hbr);
1508 deleteBrush = FALSE;
1510 hbr = GetSysColorBrush(COLOR_HIGHLIGHT);
1511 FillRect(hdc, &rTemp, hbr);
1514 /* Cleanup */
1515 if (deleteBrush) DeleteObject(hbr);
1518 /******************************************************************************
1519 * TAB_DrawItemInterior
1521 * This method is used to draw the interior (text and icon) of a single tab
1522 * into the tab control.
1524 static void
1525 TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect)
1527 LONG lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
1529 RECT localRect;
1531 HPEN htextPen;
1532 HPEN holdPen;
1533 INT oldBkMode;
1534 HFONT hOldFont;
1536 /* if (drawRect == NULL) */
1538 BOOL isVisible;
1539 RECT itemRect;
1540 RECT selectedRect;
1543 * Get the rectangle for the item.
1545 isVisible = TAB_InternalGetItemRect(infoPtr, iItem, &itemRect, &selectedRect);
1546 if (!isVisible)
1547 return;
1550 * Make sure drawRect points to something valid; simplifies code.
1552 drawRect = &localRect;
1555 * This logic copied from the part of TAB_DrawItem which draws
1556 * the tab background. It's important to keep it in sync. I
1557 * would have liked to avoid code duplication, but couldn't figure
1558 * out how without making spaghetti of TAB_DrawItem.
1560 if (iItem == infoPtr->iSelected)
1561 *drawRect = selectedRect;
1562 else
1563 *drawRect = itemRect;
1565 if (lStyle & TCS_BUTTONS)
1567 if (iItem == infoPtr->iSelected)
1569 drawRect->left += 4;
1570 drawRect->top += 4;
1571 drawRect->right -= 4;
1572 drawRect->bottom -= 1;
1574 else
1576 drawRect->left += 2;
1577 drawRect->top += 2;
1578 drawRect->right -= 2;
1579 drawRect->bottom -= 2;
1582 else
1584 if ((lStyle & TCS_VERTICAL) && (lStyle & TCS_BOTTOM))
1586 if (iItem != infoPtr->iSelected)
1588 drawRect->left += 2;
1589 drawRect->top += 2;
1590 drawRect->bottom -= 2;
1593 else if (lStyle & TCS_VERTICAL)
1595 if (iItem == infoPtr->iSelected)
1597 drawRect->right += 1;
1599 else
1601 drawRect->top += 2;
1602 drawRect->right -= 2;
1603 drawRect->bottom -= 2;
1606 else if (lStyle & TCS_BOTTOM)
1608 if (iItem == infoPtr->iSelected)
1610 drawRect->top -= 2;
1612 else
1614 InflateRect(drawRect, -2, -2);
1615 drawRect->bottom += 2;
1618 else
1620 if (iItem == infoPtr->iSelected)
1622 drawRect->bottom += 3;
1624 else
1626 drawRect->bottom -= 2;
1627 InflateRect(drawRect, -2, 0);
1632 TRACE("drawRect=(%s)\n", wine_dbgstr_rect(drawRect));
1634 /* Clear interior */
1635 TAB_EraseTabInterior (infoPtr, hdc, iItem, drawRect);
1637 /* Draw the focus rectangle */
1638 if (!(lStyle & TCS_FOCUSNEVER) &&
1639 (GetFocus() == infoPtr->hwnd) &&
1640 (iItem == infoPtr->uFocus) )
1642 RECT rFocus = *drawRect;
1643 InflateRect(&rFocus, -3, -3);
1644 if (lStyle & TCS_BOTTOM && !(lStyle & TCS_VERTICAL))
1645 rFocus.top -= 3;
1646 if (lStyle & TCS_BUTTONS)
1648 rFocus.left -= 3;
1649 rFocus.top -= 3;
1652 DrawFocusRect(hdc, &rFocus);
1656 * Text pen
1658 htextPen = CreatePen( PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT) );
1659 holdPen = SelectObject(hdc, htextPen);
1660 hOldFont = SelectObject(hdc, infoPtr->hFont);
1663 * Setup for text output
1665 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1666 if (!GetWindowTheme (infoPtr->hwnd) || (lStyle & TCS_BUTTONS))
1668 if ((lStyle & TCS_HOTTRACK) && (iItem == infoPtr->iHotTracked) &&
1669 !(lStyle & TCS_FLATBUTTONS))
1670 SetTextColor(hdc, comctl32_color.clrHighlight);
1671 else if (TAB_GetItem(infoPtr, iItem)->dwState & TCIS_HIGHLIGHTED)
1672 SetTextColor(hdc, comctl32_color.clrHighlightText);
1673 else
1674 SetTextColor(hdc, comctl32_color.clrBtnText);
1678 * if owner draw, tell the owner to draw
1680 if ((lStyle & TCS_OWNERDRAWFIXED) && GetParent(infoPtr->hwnd))
1682 DRAWITEMSTRUCT dis;
1683 UINT id;
1685 drawRect->top += 2;
1686 drawRect->right -= 1;
1687 if ( iItem == infoPtr->iSelected )
1689 drawRect->right -= 1;
1690 drawRect->left += 1;
1694 * get the control id
1696 id = (UINT)GetWindowLongPtrW( infoPtr->hwnd, GWLP_ID );
1699 * put together the DRAWITEMSTRUCT
1701 dis.CtlType = ODT_TAB;
1702 dis.CtlID = id;
1703 dis.itemID = iItem;
1704 dis.itemAction = ODA_DRAWENTIRE;
1705 dis.itemState = 0;
1706 if ( iItem == infoPtr->iSelected )
1707 dis.itemState |= ODS_SELECTED;
1708 if (infoPtr->uFocus == iItem)
1709 dis.itemState |= ODS_FOCUS;
1710 dis.hwndItem = infoPtr->hwnd;
1711 dis.hDC = hdc;
1712 CopyRect(&dis.rcItem,drawRect);
1713 dis.itemData = (ULONG_PTR)TAB_GetItem(infoPtr, iItem)->extra;
1716 * send the draw message
1718 SendMessageW( infoPtr->hwndNotify, WM_DRAWITEM, (WPARAM)id, (LPARAM)&dis );
1720 else
1722 TAB_ITEM *item = TAB_GetItem(infoPtr, iItem);
1723 RECT rcTemp;
1724 RECT rcImage;
1726 /* used to center the icon and text in the tab */
1727 RECT rcText;
1728 INT center_offset_h, center_offset_v;
1730 /* set rcImage to drawRect, we will use top & left in our ImageList_Draw call */
1731 rcImage = *drawRect;
1733 rcTemp = *drawRect;
1735 rcText.left = rcText.top = rcText.right = rcText.bottom = 0;
1737 /* get the rectangle that the text fits in */
1738 if (item->pszText)
1740 DrawTextW(hdc, item->pszText, -1, &rcText, DT_CALCRECT);
1743 * If not owner draw, then do the drawing ourselves.
1745 * Draw the icon.
1747 if (infoPtr->himl && item->iImage != -1)
1749 INT cx;
1750 INT cy;
1752 ImageList_GetIconSize(infoPtr->himl, &cx, &cy);
1754 if(lStyle & TCS_VERTICAL)
1756 center_offset_h = ((drawRect->bottom - drawRect->top) - (cy + infoPtr->uHItemPadding + (rcText.right - rcText.left))) / 2;
1757 center_offset_v = ((drawRect->right - drawRect->left) - cx) / 2;
1759 else
1761 center_offset_h = ((drawRect->right - drawRect->left) - (cx + infoPtr->uHItemPadding + (rcText.right - rcText.left))) / 2;
1762 center_offset_v = ((drawRect->bottom - drawRect->top) - cy) / 2;
1765 /* if an item is selected, the icon is shifted up instead of down */
1766 if (iItem == infoPtr->iSelected)
1767 center_offset_v -= infoPtr->uVItemPadding / 2;
1768 else
1769 center_offset_v += infoPtr->uVItemPadding / 2;
1771 if (lStyle & TCS_FIXEDWIDTH && lStyle & (TCS_FORCELABELLEFT | TCS_FORCEICONLEFT))
1772 center_offset_h = infoPtr->uHItemPadding;
1774 if (center_offset_h < 2)
1775 center_offset_h = 2;
1777 if (center_offset_v < 0)
1778 center_offset_v = 0;
1780 TRACE("for <%s>, c_o_h=%d, c_o_v=%d, draw=(%s), textlen=%d\n",
1781 debugstr_w(item->pszText), center_offset_h, center_offset_v,
1782 wine_dbgstr_rect(drawRect), (rcText.right-rcText.left));
1784 if((lStyle & TCS_VERTICAL) && (lStyle & TCS_BOTTOM))
1786 rcImage.top = drawRect->top + center_offset_h;
1787 /* if tab is TCS_VERTICAL and TCS_BOTTOM, the text is drawn from the */
1788 /* right side of the tab, but the image still uses the left as its x position */
1789 /* this keeps the image always drawn off of the same side of the tab */
1790 rcImage.left = drawRect->right - cx - center_offset_v;
1791 drawRect->top += cy + infoPtr->uHItemPadding;
1793 else if(lStyle & TCS_VERTICAL)
1795 rcImage.top = drawRect->bottom - cy - center_offset_h;
1796 rcImage.left = drawRect->left + center_offset_v;
1797 drawRect->bottom -= cy + infoPtr->uHItemPadding;
1799 else /* normal style, whether TCS_BOTTOM or not */
1801 rcImage.left = drawRect->left + center_offset_h;
1802 rcImage.top = drawRect->top + center_offset_v;
1803 drawRect->left += cx + infoPtr->uHItemPadding;
1806 TRACE("drawing image=%d, left=%d, top=%d\n",
1807 item->iImage, rcImage.left, rcImage.top-1);
1808 ImageList_Draw
1810 infoPtr->himl,
1811 item->iImage,
1812 hdc,
1813 rcImage.left,
1814 rcImage.top,
1815 ILD_NORMAL
1819 /* Now position text */
1820 if (lStyle & TCS_FIXEDWIDTH && lStyle & TCS_FORCELABELLEFT)
1821 center_offset_h = infoPtr->uHItemPadding;
1822 else
1823 if(lStyle & TCS_VERTICAL)
1824 center_offset_h = ((drawRect->bottom - drawRect->top) - (rcText.right - rcText.left)) / 2;
1825 else
1826 center_offset_h = ((drawRect->right - drawRect->left) - (rcText.right - rcText.left)) / 2;
1828 if(lStyle & TCS_VERTICAL)
1830 if(lStyle & TCS_BOTTOM)
1831 drawRect->top+=center_offset_h;
1832 else
1833 drawRect->bottom-=center_offset_h;
1835 center_offset_v = ((drawRect->right - drawRect->left) - (rcText.bottom - rcText.top)) / 2;
1837 else
1839 drawRect->left += center_offset_h;
1840 center_offset_v = ((drawRect->bottom - drawRect->top) - (rcText.bottom - rcText.top)) / 2;
1843 /* if an item is selected, the text is shifted up instead of down */
1844 if (iItem == infoPtr->iSelected)
1845 center_offset_v -= infoPtr->uVItemPadding / 2;
1846 else
1847 center_offset_v += infoPtr->uVItemPadding / 2;
1849 if (center_offset_v < 0)
1850 center_offset_v = 0;
1852 if(lStyle & TCS_VERTICAL)
1853 drawRect->left += center_offset_v;
1854 else
1855 drawRect->top += center_offset_v;
1857 /* Draw the text */
1858 if(lStyle & TCS_VERTICAL) /* if we are vertical rotate the text and each character */
1860 static const WCHAR ArialW[] = { 'A','r','i','a','l',0 };
1861 LOGFONTW logfont;
1862 HFONT hFont = 0;
1863 INT nEscapement = 900;
1864 INT nOrientation = 900;
1866 if(lStyle & TCS_BOTTOM)
1868 nEscapement = -900;
1869 nOrientation = -900;
1872 /* to get a font with the escapement and orientation we are looking for, we need to */
1873 /* call CreateFontIndirectA, which requires us to set the values of the logfont we pass in */
1874 if (!GetObjectW((infoPtr->hFont) ?
1875 infoPtr->hFont : GetStockObject(SYSTEM_FONT),
1876 sizeof(LOGFONTW),&logfont))
1878 INT iPointSize = 9;
1880 lstrcpyW(logfont.lfFaceName, ArialW);
1881 logfont.lfHeight = -MulDiv(iPointSize, GetDeviceCaps(hdc, LOGPIXELSY),
1882 72);
1883 logfont.lfWeight = FW_NORMAL;
1884 logfont.lfItalic = 0;
1885 logfont.lfUnderline = 0;
1886 logfont.lfStrikeOut = 0;
1889 logfont.lfEscapement = nEscapement;
1890 logfont.lfOrientation = nOrientation;
1891 hFont = CreateFontIndirectW(&logfont);
1892 SelectObject(hdc, hFont);
1894 if (item->pszText)
1896 ExtTextOutW(hdc,
1897 (lStyle & TCS_BOTTOM) ? drawRect->right : drawRect->left,
1898 (!(lStyle & TCS_BOTTOM)) ? drawRect->bottom : drawRect->top,
1899 ETO_CLIPPED,
1900 drawRect,
1901 item->pszText,
1902 lstrlenW(item->pszText),
1906 DeleteObject(hFont);
1908 else
1910 TRACE("for <%s>, c_o_h=%d, c_o_v=%d, draw=(%s), textlen=%d\n",
1911 debugstr_w(item->pszText), center_offset_h, center_offset_v,
1912 wine_dbgstr_rect(drawRect), (rcText.right-rcText.left));
1913 if (item->pszText)
1915 DrawTextW
1917 hdc,
1918 item->pszText,
1919 lstrlenW(item->pszText),
1920 drawRect,
1921 DT_LEFT | DT_SINGLELINE
1926 *drawRect = rcTemp; /* restore drawRect */
1930 * Cleanup
1932 SelectObject(hdc, hOldFont);
1933 SetBkMode(hdc, oldBkMode);
1934 SelectObject(hdc, holdPen);
1935 DeleteObject( htextPen );
1938 /******************************************************************************
1939 * TAB_DrawItem
1941 * This method is used to draw a single tab into the tab control.
1943 static void TAB_DrawItem(const TAB_INFO *infoPtr, HDC hdc, INT iItem)
1945 LONG lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
1946 RECT itemRect;
1947 RECT selectedRect;
1948 BOOL isVisible;
1949 RECT r, fillRect, r1;
1950 INT clRight = 0;
1951 INT clBottom = 0;
1952 COLORREF bkgnd, corner;
1953 HTHEME theme;
1956 * Get the rectangle for the item.
1958 isVisible = TAB_InternalGetItemRect(infoPtr,
1959 iItem,
1960 &itemRect,
1961 &selectedRect);
1963 if (isVisible)
1965 RECT rUD, rC;
1967 /* Clip UpDown control to not draw over it */
1968 if (infoPtr->needsScrolling)
1970 GetWindowRect(infoPtr->hwnd, &rC);
1971 GetWindowRect(infoPtr->hwndUpDown, &rUD);
1972 ExcludeClipRect(hdc, rUD.left - rC.left, rUD.top - rC.top, rUD.right - rC.left, rUD.bottom - rC.top);
1975 /* If you need to see what the control is doing,
1976 * then override these variables. They will change what
1977 * fill colors are used for filling the tabs, and the
1978 * corners when drawing the edge.
1980 bkgnd = comctl32_color.clrBtnFace;
1981 corner = comctl32_color.clrBtnFace;
1983 if (lStyle & TCS_BUTTONS)
1985 /* Get item rectangle */
1986 r = itemRect;
1988 /* Separators between flat buttons */
1989 if ((lStyle & TCS_FLATBUTTONS) && (infoPtr->exStyle & TCS_EX_FLATSEPARATORS))
1991 r1 = r;
1992 r1.right += (FLAT_BTN_SPACINGX -2);
1993 DrawEdge(hdc, &r1, EDGE_ETCHED, BF_RIGHT);
1996 if (iItem == infoPtr->iSelected)
1998 DrawEdge(hdc, &r, EDGE_SUNKEN, BF_SOFT|BF_RECT);
2000 OffsetRect(&r, 1, 1);
2002 else /* ! selected */
2004 DWORD state = TAB_GetItem(infoPtr, iItem)->dwState;
2006 if (state & TCIS_BUTTONPRESSED)
2007 DrawEdge(hdc, &r, EDGE_SUNKEN, BF_SOFT|BF_RECT);
2008 else
2009 if (!(lStyle & TCS_FLATBUTTONS))
2010 DrawEdge(hdc, &r, EDGE_RAISED, BF_SOFT|BF_RECT);
2013 else /* !TCS_BUTTONS */
2015 /* We draw a rectangle of different sizes depending on the selection
2016 * state. */
2017 if (iItem == infoPtr->iSelected) {
2018 RECT rect;
2019 GetClientRect (infoPtr->hwnd, &rect);
2020 clRight = rect.right;
2021 clBottom = rect.bottom;
2022 r = selectedRect;
2024 else
2025 r = itemRect;
2028 * Erase the background. (Delay it but setup rectangle.)
2029 * This is necessary when drawing the selected item since it is larger
2030 * than the others, it might overlap with stuff already drawn by the
2031 * other tabs
2033 fillRect = r;
2035 /* Draw themed tabs - but only if they are at the top.
2036 * Windows draws even side or bottom tabs themed, with wacky results.
2037 * However, since in Wine apps may get themed that did not opt in via
2038 * a manifest avoid theming when we know the result will be wrong */
2039 if ((theme = GetWindowTheme (infoPtr->hwnd))
2040 && ((lStyle & (TCS_VERTICAL | TCS_BOTTOM)) == 0))
2042 static const int partIds[8] = {
2043 /* Normal item */
2044 TABP_TABITEM,
2045 TABP_TABITEMLEFTEDGE,
2046 TABP_TABITEMRIGHTEDGE,
2047 TABP_TABITEMBOTHEDGE,
2048 /* Selected tab */
2049 TABP_TOPTABITEM,
2050 TABP_TOPTABITEMLEFTEDGE,
2051 TABP_TOPTABITEMRIGHTEDGE,
2052 TABP_TOPTABITEMBOTHEDGE,
2054 int partIndex = 0;
2055 int stateId = TIS_NORMAL;
2057 /* selected and unselected tabs have different parts */
2058 if (iItem == infoPtr->iSelected)
2059 partIndex += 4;
2060 /* The part also differs on the position of a tab on a line.
2061 * "Visually" determining the position works well enough. */
2062 if(selectedRect.left == 0)
2063 partIndex += 1;
2064 if(selectedRect.right == clRight)
2065 partIndex += 2;
2067 if (iItem == infoPtr->iSelected)
2068 stateId = TIS_SELECTED;
2069 else if (iItem == infoPtr->iHotTracked)
2070 stateId = TIS_HOT;
2071 else if (iItem == infoPtr->uFocus)
2072 stateId = TIS_FOCUSED;
2074 /* Adjust rectangle for bottommost row */
2075 if (TAB_GetItem(infoPtr, iItem)->rect.top == infoPtr->uNumRows-1)
2076 r.bottom += 3;
2078 DrawThemeBackground (theme, hdc, partIds[partIndex], stateId, &r, NULL);
2079 GetThemeBackgroundContentRect (theme, hdc, partIds[partIndex], stateId, &r, &r);
2081 else if(lStyle & TCS_VERTICAL)
2083 /* These are for adjusting the drawing of a Selected tab */
2084 /* The initial values are for the normal case of non-Selected */
2085 int ZZ = 1; /* Do not stretch if selected */
2086 if (iItem == infoPtr->iSelected) {
2087 ZZ = 0;
2089 /* if leftmost draw the line longer */
2090 if(selectedRect.top == 0)
2091 fillRect.top += CONTROL_BORDER_SIZEY;
2092 /* if rightmost draw the line longer */
2093 if(selectedRect.bottom == clBottom)
2094 fillRect.bottom -= CONTROL_BORDER_SIZEY;
2097 if (lStyle & TCS_BOTTOM)
2099 /* Adjust both rectangles to match native */
2100 r.left += (1-ZZ);
2102 TRACE("<right> item=%d, fill=(%s), edge=(%s)\n",
2103 iItem, wine_dbgstr_rect(&fillRect), wine_dbgstr_rect(&r));
2105 /* Clear interior */
2106 SetBkColor(hdc, bkgnd);
2107 ExtTextOutW(hdc, 0, 0, 2, &fillRect, NULL, 0, 0);
2109 /* Draw rectangular edge around tab */
2110 DrawEdge(hdc, &r, EDGE_RAISED, BF_SOFT|BF_RIGHT|BF_TOP|BF_BOTTOM);
2112 /* Now erase the top corner and draw diagonal edge */
2113 SetBkColor(hdc, corner);
2114 r1.left = r.right - ROUND_CORNER_SIZE - 1;
2115 r1.top = r.top;
2116 r1.right = r.right;
2117 r1.bottom = r1.top + ROUND_CORNER_SIZE;
2118 ExtTextOutW(hdc, 0, 0, 2, &r1, NULL, 0, 0);
2119 r1.right--;
2120 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_DIAGONAL_ENDTOPLEFT);
2122 /* Now erase the bottom corner and draw diagonal edge */
2123 r1.left = r.right - ROUND_CORNER_SIZE - 1;
2124 r1.bottom = r.bottom;
2125 r1.right = r.right;
2126 r1.top = r1.bottom - ROUND_CORNER_SIZE;
2127 ExtTextOutW(hdc, 0, 0, 2, &r1, NULL, 0, 0);
2128 r1.right--;
2129 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_DIAGONAL_ENDBOTTOMLEFT);
2131 if ((iItem == infoPtr->iSelected) && (selectedRect.top == 0)) {
2132 r1 = r;
2133 r1.right = r1.left;
2134 r1.left--;
2135 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_TOP);
2139 else
2141 TRACE("<left> item=%d, fill=(%s), edge=(%s)\n",
2142 iItem, wine_dbgstr_rect(&fillRect), wine_dbgstr_rect(&r));
2144 /* Clear interior */
2145 SetBkColor(hdc, bkgnd);
2146 ExtTextOutW(hdc, 0, 0, 2, &fillRect, NULL, 0, 0);
2148 /* Draw rectangular edge around tab */
2149 DrawEdge(hdc, &r, EDGE_RAISED, BF_SOFT|BF_LEFT|BF_TOP|BF_BOTTOM);
2151 /* Now erase the top corner and draw diagonal edge */
2152 SetBkColor(hdc, corner);
2153 r1.left = r.left;
2154 r1.top = r.top;
2155 r1.right = r1.left + ROUND_CORNER_SIZE + 1;
2156 r1.bottom = r1.top + ROUND_CORNER_SIZE;
2157 ExtTextOutW(hdc, 0, 0, 2, &r1, NULL, 0, 0);
2158 r1.left++;
2159 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_DIAGONAL_ENDTOPRIGHT);
2161 /* Now erase the bottom corner and draw diagonal edge */
2162 r1.left = r.left;
2163 r1.bottom = r.bottom;
2164 r1.right = r1.left + ROUND_CORNER_SIZE + 1;
2165 r1.top = r1.bottom - ROUND_CORNER_SIZE;
2166 ExtTextOutW(hdc, 0, 0, 2, &r1, NULL, 0, 0);
2167 r1.left++;
2168 DrawEdge(hdc, &r1, EDGE_SUNKEN, BF_DIAGONAL_ENDTOPLEFT);
2171 else /* ! TCS_VERTICAL */
2173 /* These are for adjusting the drawing of a Selected tab */
2174 /* The initial values are for the normal case of non-Selected */
2175 if (iItem == infoPtr->iSelected) {
2176 /* if leftmost draw the line longer */
2177 if(selectedRect.left == 0)
2178 fillRect.left += CONTROL_BORDER_SIZEX;
2179 /* if rightmost draw the line longer */
2180 if(selectedRect.right == clRight)
2181 fillRect.right -= CONTROL_BORDER_SIZEX;
2184 if (lStyle & TCS_BOTTOM)
2186 /* Adjust both rectangles for topmost row */
2187 if (TAB_GetItem(infoPtr, iItem)->rect.top == infoPtr->uNumRows-1)
2189 fillRect.top -= 2;
2190 r.top -= 1;
2193 TRACE("<bottom> item=%d, fill=(%s), edge=(%s)\n",
2194 iItem, wine_dbgstr_rect(&fillRect), wine_dbgstr_rect(&r));
2196 /* Clear interior */
2197 SetBkColor(hdc, bkgnd);
2198 ExtTextOutW(hdc, 0, 0, 2, &fillRect, NULL, 0, 0);
2200 /* Draw rectangular edge around tab */
2201 DrawEdge(hdc, &r, EDGE_RAISED, BF_SOFT|BF_LEFT|BF_BOTTOM|BF_RIGHT);
2203 /* Now erase the righthand corner and draw diagonal edge */
2204 SetBkColor(hdc, corner);
2205 r1.left = r.right - ROUND_CORNER_SIZE;
2206 r1.bottom = r.bottom;
2207 r1.right = r.right;
2208 r1.top = r1.bottom - ROUND_CORNER_SIZE - 1;
2209 ExtTextOutW(hdc, 0, 0, 2, &r1, NULL, 0, 0);
2210 r1.bottom--;
2211 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_DIAGONAL_ENDBOTTOMLEFT);
2213 /* Now erase the lefthand corner and draw diagonal edge */
2214 r1.left = r.left;
2215 r1.bottom = r.bottom;
2216 r1.right = r1.left + ROUND_CORNER_SIZE;
2217 r1.top = r1.bottom - ROUND_CORNER_SIZE - 1;
2218 ExtTextOutW(hdc, 0, 0, 2, &r1, NULL, 0, 0);
2219 r1.bottom--;
2220 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_DIAGONAL_ENDTOPLEFT);
2222 if (iItem == infoPtr->iSelected)
2224 r.top += 2;
2225 r.left += 1;
2226 if (selectedRect.left == 0)
2228 r1 = r;
2229 r1.bottom = r1.top;
2230 r1.top--;
2231 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_LEFT);
2236 else
2238 /* Adjust both rectangles for bottommost row */
2239 if (TAB_GetItem(infoPtr, iItem)->rect.top == infoPtr->uNumRows-1)
2241 fillRect.bottom += 3;
2242 r.bottom += 2;
2245 TRACE("<top> item=%d, fill=(%s), edge=(%s)\n",
2246 iItem, wine_dbgstr_rect(&fillRect), wine_dbgstr_rect(&r));
2248 /* Clear interior */
2249 SetBkColor(hdc, bkgnd);
2250 ExtTextOutW(hdc, 0, 0, 2, &fillRect, NULL, 0, 0);
2252 /* Draw rectangular edge around tab */
2253 DrawEdge(hdc, &r, EDGE_RAISED, BF_SOFT|BF_LEFT|BF_TOP|BF_RIGHT);
2255 /* Now erase the righthand corner and draw diagonal edge */
2256 SetBkColor(hdc, corner);
2257 r1.left = r.right - ROUND_CORNER_SIZE;
2258 r1.top = r.top;
2259 r1.right = r.right;
2260 r1.bottom = r1.top + ROUND_CORNER_SIZE + 1;
2261 ExtTextOutW(hdc, 0, 0, 2, &r1, NULL, 0, 0);
2262 r1.top++;
2263 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_DIAGONAL_ENDBOTTOMRIGHT);
2265 /* Now erase the lefthand corner and draw diagonal edge */
2266 r1.left = r.left;
2267 r1.top = r.top;
2268 r1.right = r1.left + ROUND_CORNER_SIZE;
2269 r1.bottom = r1.top + ROUND_CORNER_SIZE + 1;
2270 ExtTextOutW(hdc, 0, 0, 2, &r1, NULL, 0, 0);
2271 r1.top++;
2272 DrawEdge(hdc, &r1, EDGE_RAISED, BF_SOFT|BF_DIAGONAL_ENDTOPRIGHT);
2277 TAB_DumpItemInternal(infoPtr, iItem);
2279 /* This modifies r to be the text rectangle. */
2280 TAB_DrawItemInterior(infoPtr, hdc, iItem, &r);
2284 /******************************************************************************
2285 * TAB_DrawBorder
2287 * This method is used to draw the raised border around the tab control
2288 * "content" area.
2290 static void TAB_DrawBorder(const TAB_INFO *infoPtr, HDC hdc)
2292 RECT rect;
2293 DWORD lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
2294 HTHEME theme = GetWindowTheme (infoPtr->hwnd);
2296 GetClientRect (infoPtr->hwnd, &rect);
2299 * Adjust for the style
2302 if (infoPtr->uNumItem)
2304 if ((lStyle & TCS_BOTTOM) && !(lStyle & TCS_VERTICAL))
2305 rect.bottom -= infoPtr->tabHeight * infoPtr->uNumRows + CONTROL_BORDER_SIZEX;
2306 else if((lStyle & TCS_BOTTOM) && (lStyle & TCS_VERTICAL))
2307 rect.right -= infoPtr->tabHeight * infoPtr->uNumRows + CONTROL_BORDER_SIZEX;
2308 else if(lStyle & TCS_VERTICAL)
2309 rect.left += infoPtr->tabHeight * infoPtr->uNumRows + CONTROL_BORDER_SIZEX;
2310 else /* not TCS_VERTICAL and not TCS_BOTTOM */
2311 rect.top += infoPtr->tabHeight * infoPtr->uNumRows + CONTROL_BORDER_SIZEX;
2314 TRACE("border=(%s)\n", wine_dbgstr_rect(&rect));
2316 if (theme)
2317 DrawThemeBackground (theme, hdc, TABP_PANE, 0, &rect, NULL);
2318 else
2319 DrawEdge(hdc, &rect, EDGE_RAISED, BF_SOFT|BF_RECT);
2322 /******************************************************************************
2323 * TAB_Refresh
2325 * This method repaints the tab control..
2327 static void TAB_Refresh (TAB_INFO *infoPtr, HDC hdc)
2329 HFONT hOldFont;
2330 INT i;
2332 if (!infoPtr->DoRedraw)
2333 return;
2335 hOldFont = SelectObject (hdc, infoPtr->hFont);
2337 if (GetWindowLongW(infoPtr->hwnd, GWL_STYLE) & TCS_BUTTONS)
2339 for (i = 0; i < infoPtr->uNumItem; i++)
2340 TAB_DrawItem (infoPtr, hdc, i);
2342 else
2344 /* Draw all the non selected item first */
2345 for (i = 0; i < infoPtr->uNumItem; i++)
2347 if (i != infoPtr->iSelected)
2348 TAB_DrawItem (infoPtr, hdc, i);
2351 /* Now, draw the border, draw it before the selected item
2352 * since the selected item overwrites part of the border. */
2353 TAB_DrawBorder (infoPtr, hdc);
2355 /* Then, draw the selected item */
2356 TAB_DrawItem (infoPtr, hdc, infoPtr->iSelected);
2359 SelectObject (hdc, hOldFont);
2362 static inline DWORD TAB_GetRowCount (const TAB_INFO *infoPtr)
2364 return infoPtr->uNumRows;
2367 static inline LRESULT TAB_SetRedraw (TAB_INFO *infoPtr, BOOL doRedraw)
2369 infoPtr->DoRedraw = doRedraw;
2370 return 0;
2373 /******************************************************************************
2374 * TAB_EnsureSelectionVisible
2376 * This method will make sure that the current selection is completely
2377 * visible by scrolling until it is.
2379 static void TAB_EnsureSelectionVisible(
2380 TAB_INFO* infoPtr)
2382 INT iSelected = infoPtr->iSelected;
2383 LONG lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
2384 INT iOrigLeftmostVisible = infoPtr->leftmostVisible;
2386 /* set the items row to the bottommost row or topmost row depending on
2387 * style */
2388 if ((infoPtr->uNumRows > 1) && !(lStyle & TCS_BUTTONS))
2390 TAB_ITEM *selected = TAB_GetItem(infoPtr, iSelected);
2391 INT newselected;
2392 INT iTargetRow;
2394 if(lStyle & TCS_VERTICAL)
2395 newselected = selected->rect.left;
2396 else
2397 newselected = selected->rect.top;
2399 /* the target row is always (number of rows - 1)
2400 as row 0 is furthest from the clientRect */
2401 iTargetRow = infoPtr->uNumRows - 1;
2403 if (newselected != iTargetRow)
2405 UINT i;
2406 if(lStyle & TCS_VERTICAL)
2408 for (i=0; i < infoPtr->uNumItem; i++)
2410 /* move everything in the row of the selected item to the iTargetRow */
2411 TAB_ITEM *item = TAB_GetItem(infoPtr, i);
2413 if (item->rect.left == newselected )
2414 item->rect.left = iTargetRow;
2415 else
2417 if (item->rect.left > newselected)
2418 item->rect.left-=1;
2422 else
2424 for (i=0; i < infoPtr->uNumItem; i++)
2426 TAB_ITEM *item = TAB_GetItem(infoPtr, i);
2428 if (item->rect.top == newselected )
2429 item->rect.top = iTargetRow;
2430 else
2432 if (item->rect.top > newselected)
2433 item->rect.top-=1;
2437 TAB_RecalcHotTrack(infoPtr, NULL, NULL, NULL);
2442 * Do the trivial cases first.
2444 if ( (!infoPtr->needsScrolling) ||
2445 (infoPtr->hwndUpDown==0) || (lStyle & TCS_VERTICAL))
2446 return;
2448 if (infoPtr->leftmostVisible >= iSelected)
2450 infoPtr->leftmostVisible = iSelected;
2452 else
2454 TAB_ITEM *selected = TAB_GetItem(infoPtr, iSelected);
2455 RECT r;
2456 INT width;
2457 UINT i;
2459 /* Calculate the part of the client area that is visible */
2460 GetClientRect(infoPtr->hwnd, &r);
2461 width = r.right;
2463 GetClientRect(infoPtr->hwndUpDown, &r);
2464 width -= r.right;
2466 if ((selected->rect.right -
2467 selected->rect.left) >= width )
2469 /* Special case: width of selected item is greater than visible
2470 * part of control.
2472 infoPtr->leftmostVisible = iSelected;
2474 else
2476 for (i = infoPtr->leftmostVisible; i < infoPtr->uNumItem; i++)
2478 if ((selected->rect.right - TAB_GetItem(infoPtr, i)->rect.left) < width)
2479 break;
2481 infoPtr->leftmostVisible = i;
2485 if (infoPtr->leftmostVisible != iOrigLeftmostVisible)
2486 TAB_RecalcHotTrack(infoPtr, NULL, NULL, NULL);
2488 SendMessageW(infoPtr->hwndUpDown, UDM_SETPOS, 0,
2489 MAKELONG(infoPtr->leftmostVisible, 0));
2492 /******************************************************************************
2493 * TAB_InvalidateTabArea
2495 * This method will invalidate the portion of the control that contains the
2496 * tabs. It is called when the state of the control changes and needs
2497 * to be redisplayed
2499 static void TAB_InvalidateTabArea(const TAB_INFO *infoPtr)
2501 RECT clientRect, rInvalidate, rAdjClient;
2502 DWORD lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
2503 INT lastRow = infoPtr->uNumRows - 1;
2504 RECT rect;
2506 if (lastRow < 0) return;
2508 GetClientRect(infoPtr->hwnd, &clientRect);
2509 rInvalidate = clientRect;
2510 rAdjClient = clientRect;
2512 TAB_AdjustRect(infoPtr, 0, &rAdjClient);
2514 TAB_InternalGetItemRect(infoPtr, infoPtr->uNumItem-1 , &rect, NULL);
2515 if ((lStyle & TCS_BOTTOM) && (lStyle & TCS_VERTICAL))
2517 rInvalidate.left = rAdjClient.right;
2518 if (infoPtr->uNumRows == 1)
2519 rInvalidate.bottom = clientRect.top + rect.bottom + 2 * SELECTED_TAB_OFFSET;
2521 else if(lStyle & TCS_VERTICAL)
2523 rInvalidate.right = rAdjClient.left;
2524 if (infoPtr->uNumRows == 1)
2525 rInvalidate.bottom = clientRect.top + rect.bottom + 2 * SELECTED_TAB_OFFSET;
2527 else if (lStyle & TCS_BOTTOM)
2529 rInvalidate.top = rAdjClient.bottom;
2530 if (infoPtr->uNumRows == 1)
2531 rInvalidate.right = clientRect.left + rect.right + 2 * SELECTED_TAB_OFFSET;
2533 else
2535 rInvalidate.bottom = rAdjClient.top;
2536 if (infoPtr->uNumRows == 1)
2537 rInvalidate.right = clientRect.left + rect.right + 2 * SELECTED_TAB_OFFSET;
2540 /* Punch out the updown control */
2541 if (infoPtr->needsScrolling && (rInvalidate.right > 0)) {
2542 RECT r;
2543 GetClientRect(infoPtr->hwndUpDown, &r);
2544 if (rInvalidate.right > clientRect.right - r.left)
2545 rInvalidate.right = rInvalidate.right - (r.right - r.left);
2546 else
2547 rInvalidate.right = clientRect.right - r.left;
2550 TRACE("invalidate (%s)\n", wine_dbgstr_rect(&rInvalidate));
2552 InvalidateRect(infoPtr->hwnd, &rInvalidate, TRUE);
2555 static inline LRESULT TAB_Paint (TAB_INFO *infoPtr, HDC hdcPaint)
2557 HDC hdc;
2558 PAINTSTRUCT ps;
2560 if (hdcPaint)
2561 hdc = hdcPaint;
2562 else
2564 hdc = BeginPaint (infoPtr->hwnd, &ps);
2565 TRACE("erase %d, rect=(%s)\n", ps.fErase, wine_dbgstr_rect(&ps.rcPaint));
2568 TAB_Refresh (infoPtr, hdc);
2570 if (!hdcPaint)
2571 EndPaint (infoPtr->hwnd, &ps);
2573 return 0;
2576 static LRESULT
2577 TAB_InsertItemT (TAB_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
2579 TAB_ITEM *item;
2580 TCITEMW *pti;
2581 INT iItem;
2582 RECT rect;
2584 GetClientRect (infoPtr->hwnd, &rect);
2585 TRACE("Rect: %p %s\n", infoPtr->hwnd, wine_dbgstr_rect(&rect));
2587 pti = (TCITEMW *)lParam;
2588 iItem = (INT)wParam;
2590 if (iItem < 0) return -1;
2591 if (iItem > infoPtr->uNumItem)
2592 iItem = infoPtr->uNumItem;
2594 TAB_DumpItemExternalT(pti, iItem, bUnicode);
2597 if (infoPtr->uNumItem == 0) {
2598 infoPtr->items = Alloc (TAB_ITEM_SIZE(infoPtr));
2599 infoPtr->uNumItem++;
2600 infoPtr->iSelected = 0;
2602 else {
2603 LPBYTE oldItems = (LPBYTE)infoPtr->items;
2605 infoPtr->uNumItem++;
2606 infoPtr->items = Alloc (TAB_ITEM_SIZE(infoPtr) * infoPtr->uNumItem);
2608 /* pre insert copy */
2609 if (iItem > 0) {
2610 memcpy (infoPtr->items, oldItems,
2611 iItem * TAB_ITEM_SIZE(infoPtr));
2614 /* post insert copy */
2615 if (iItem < infoPtr->uNumItem - 1) {
2616 memcpy (TAB_GetItem(infoPtr, iItem + 1),
2617 oldItems + iItem * TAB_ITEM_SIZE(infoPtr),
2618 (infoPtr->uNumItem - iItem - 1) * TAB_ITEM_SIZE(infoPtr));
2622 if (iItem <= infoPtr->iSelected)
2623 infoPtr->iSelected++;
2625 Free (oldItems);
2628 item = TAB_GetItem(infoPtr, iItem);
2630 item->pszText = NULL;
2632 if (pti->mask & TCIF_TEXT)
2634 if (bUnicode)
2635 Str_SetPtrW (&item->pszText, pti->pszText);
2636 else
2637 Str_SetPtrAtoW (&item->pszText, (LPSTR)pti->pszText);
2640 if (pti->mask & TCIF_IMAGE)
2641 item->iImage = pti->iImage;
2642 else
2643 item->iImage = -1;
2645 if (pti->mask & TCIF_PARAM)
2646 memcpy(item->extra, &pti->lParam, infoPtr->cbInfo);
2647 else
2648 memset(item->extra, 0, infoPtr->cbInfo);
2650 TAB_SetItemBounds(infoPtr);
2651 if (infoPtr->uNumItem > 1)
2652 TAB_InvalidateTabArea(infoPtr);
2653 else
2654 InvalidateRect(infoPtr->hwnd, NULL, TRUE);
2656 TRACE("[%p]: added item %d %s\n",
2657 infoPtr->hwnd, iItem, debugstr_w(item->pszText));
2659 /* If we haven't set the current focus yet, set it now. */
2660 if (infoPtr->uFocus == -1)
2661 TAB_SetCurFocus(infoPtr, iItem);
2663 return iItem;
2666 static LRESULT
2667 TAB_SetItemSize (TAB_INFO *infoPtr, LPARAM lParam)
2669 LONG lStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
2670 LONG lResult = 0;
2671 BOOL bNeedPaint = FALSE;
2673 lResult = MAKELONG(infoPtr->tabWidth, infoPtr->tabHeight);
2675 /* UNDOCUMENTED: If requested Width or Height is 0 this means that program wants to use auto size. */
2676 if (lStyle & TCS_FIXEDWIDTH && (infoPtr->tabWidth != (INT)LOWORD(lParam)))
2678 infoPtr->tabWidth = (INT)LOWORD(lParam);
2679 bNeedPaint = TRUE;
2682 if (infoPtr->tabHeight != (INT)HIWORD(lParam))
2684 if ((infoPtr->fHeightSet = ((INT)HIWORD(lParam) != 0)))
2685 infoPtr->tabHeight = (INT)HIWORD(lParam);
2687 bNeedPaint = TRUE;
2689 TRACE("was h=%d,w=%d, now h=%d,w=%d\n",
2690 HIWORD(lResult), LOWORD(lResult),
2691 infoPtr->tabHeight, infoPtr->tabWidth);
2693 if (bNeedPaint)
2695 TAB_SetItemBounds(infoPtr);
2696 RedrawWindow(infoPtr->hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
2699 return lResult;
2702 static inline LRESULT TAB_SetMinTabWidth (TAB_INFO *infoPtr, INT cx)
2704 INT oldcx = 0;
2706 TRACE("(%p,%d)\n", infoPtr, cx);
2708 if (infoPtr->tabMinWidth < 0)
2709 oldcx = DEFAULT_MIN_TAB_WIDTH;
2710 else
2711 oldcx = infoPtr->tabMinWidth;
2712 infoPtr->tabMinWidth = cx;
2713 TAB_SetItemBounds(infoPtr);
2714 return oldcx;
2717 static inline LRESULT
2718 TAB_HighlightItem (TAB_INFO *infoPtr, INT iItem, BOOL fHighlight)
2720 LPDWORD lpState;
2721 DWORD oldState;
2722 RECT r;
2724 TRACE("(%p,%d,%s)\n", infoPtr, iItem, fHighlight ? "true" : "false");
2726 if (!infoPtr || iItem < 0 || iItem >= infoPtr->uNumItem)
2727 return FALSE;
2729 lpState = &TAB_GetItem(infoPtr, iItem)->dwState;
2730 oldState = *lpState;
2732 if (fHighlight)
2733 *lpState |= TCIS_HIGHLIGHTED;
2734 else
2735 *lpState &= ~TCIS_HIGHLIGHTED;
2737 if ((oldState != *lpState) && TAB_InternalGetItemRect (infoPtr, iItem, &r, NULL))
2738 InvalidateRect (infoPtr->hwnd, &r, TRUE);
2740 return TRUE;
2743 static LRESULT
2744 TAB_SetItemT (TAB_INFO *infoPtr, INT iItem, LPTCITEMW tabItem, BOOL bUnicode)
2746 TAB_ITEM *wineItem;
2748 TRACE("(%p,%d,%p,%s)\n", infoPtr, iItem, tabItem, bUnicode ? "true" : "false");
2750 if (iItem < 0 || iItem >= infoPtr->uNumItem)
2751 return FALSE;
2753 TAB_DumpItemExternalT(tabItem, iItem, bUnicode);
2755 wineItem = TAB_GetItem(infoPtr, iItem);
2757 if (tabItem->mask & TCIF_IMAGE)
2758 wineItem->iImage = tabItem->iImage;
2760 if (tabItem->mask & TCIF_PARAM)
2761 memcpy(wineItem->extra, &tabItem->lParam, infoPtr->cbInfo);
2763 if (tabItem->mask & TCIF_RTLREADING)
2764 FIXME("TCIF_RTLREADING\n");
2766 if (tabItem->mask & TCIF_STATE)
2767 wineItem->dwState = (wineItem->dwState & ~tabItem->dwStateMask) |
2768 ( tabItem->dwState & tabItem->dwStateMask);
2770 if (tabItem->mask & TCIF_TEXT)
2772 Free(wineItem->pszText);
2773 wineItem->pszText = NULL;
2774 if (bUnicode)
2775 Str_SetPtrW(&wineItem->pszText, tabItem->pszText);
2776 else
2777 Str_SetPtrAtoW(&wineItem->pszText, (LPSTR)tabItem->pszText);
2780 /* Update and repaint tabs */
2781 TAB_SetItemBounds(infoPtr);
2782 TAB_InvalidateTabArea(infoPtr);
2784 return TRUE;
2787 static inline LRESULT TAB_GetItemCount (const TAB_INFO *infoPtr)
2789 return infoPtr->uNumItem;
2793 static LRESULT
2794 TAB_GetItemT (TAB_INFO *infoPtr, INT iItem, LPTCITEMW tabItem, BOOL bUnicode)
2796 TAB_ITEM *wineItem;
2798 TRACE("(%p,%d,%p,%s)\n", infoPtr, iItem, tabItem, bUnicode ? "true" : "false");
2800 if (iItem < 0 || iItem >= infoPtr->uNumItem)
2801 return FALSE;
2803 wineItem = TAB_GetItem(infoPtr, iItem);
2805 if (tabItem->mask & TCIF_IMAGE)
2806 tabItem->iImage = wineItem->iImage;
2808 if (tabItem->mask & TCIF_PARAM)
2809 memcpy(&tabItem->lParam, wineItem->extra, infoPtr->cbInfo);
2811 if (tabItem->mask & TCIF_RTLREADING)
2812 FIXME("TCIF_RTLREADING\n");
2814 if (tabItem->mask & TCIF_STATE)
2815 tabItem->dwState = wineItem->dwState & tabItem->dwStateMask;
2817 if (tabItem->mask & TCIF_TEXT)
2819 if (bUnicode)
2820 Str_GetPtrW (wineItem->pszText, tabItem->pszText, tabItem->cchTextMax);
2821 else
2822 Str_GetPtrWtoA (wineItem->pszText, (LPSTR)tabItem->pszText, tabItem->cchTextMax);
2825 TAB_DumpItemExternalT(tabItem, iItem, bUnicode);
2827 return TRUE;
2831 static LRESULT TAB_DeleteItem (TAB_INFO *infoPtr, INT iItem)
2833 BOOL bResult = FALSE;
2835 TRACE("(%p, %d)\n", infoPtr, iItem);
2837 if ((iItem >= 0) && (iItem < infoPtr->uNumItem))
2839 TAB_ITEM *item = TAB_GetItem(infoPtr, iItem);
2840 LPBYTE oldItems = (LPBYTE)infoPtr->items;
2842 TAB_InvalidateTabArea(infoPtr);
2843 Free(item->pszText);
2844 infoPtr->uNumItem--;
2846 if (!infoPtr->uNumItem)
2848 infoPtr->items = NULL;
2849 if (infoPtr->iHotTracked >= 0)
2851 KillTimer(infoPtr->hwnd, TAB_HOTTRACK_TIMER);
2852 infoPtr->iHotTracked = -1;
2855 else
2857 infoPtr->items = Alloc(TAB_ITEM_SIZE(infoPtr) * infoPtr->uNumItem);
2859 if (iItem > 0)
2860 memcpy(infoPtr->items, oldItems, iItem * TAB_ITEM_SIZE(infoPtr));
2862 if (iItem < infoPtr->uNumItem)
2863 memcpy(TAB_GetItem(infoPtr, iItem),
2864 oldItems + (iItem + 1) * TAB_ITEM_SIZE(infoPtr),
2865 (infoPtr->uNumItem - iItem) * TAB_ITEM_SIZE(infoPtr));
2867 if (iItem <= infoPtr->iHotTracked)
2869 /* When tabs move left/up, the hot track item may change */
2870 FIXME("Recalc hot track\n");
2873 Free(oldItems);
2875 /* Readjust the selected index */
2876 if ((iItem == infoPtr->iSelected) && (iItem > 0))
2877 infoPtr->iSelected--;
2879 if (iItem < infoPtr->iSelected)
2880 infoPtr->iSelected--;
2882 if (infoPtr->uNumItem == 0)
2883 infoPtr->iSelected = -1;
2885 /* Reposition and repaint tabs */
2886 TAB_SetItemBounds(infoPtr);
2888 bResult = TRUE;
2891 return bResult;
2894 static inline LRESULT TAB_DeleteAllItems (TAB_INFO *infoPtr)
2896 TRACE("(%p)\n", infoPtr);
2897 while (infoPtr->uNumItem)
2898 TAB_DeleteItem (infoPtr, 0);
2899 return TRUE;
2903 static inline LRESULT TAB_GetFont (const TAB_INFO *infoPtr)
2905 TRACE("(%p) returning %p\n", infoPtr, infoPtr->hFont);
2906 return (LRESULT)infoPtr->hFont;
2909 static inline LRESULT TAB_SetFont (TAB_INFO *infoPtr, HFONT hNewFont)
2911 TRACE("(%p,%p)\n", infoPtr, hNewFont);
2913 infoPtr->hFont = hNewFont;
2915 TAB_SetItemBounds(infoPtr);
2917 TAB_InvalidateTabArea(infoPtr);
2919 return 0;
2923 static inline LRESULT TAB_GetImageList (const TAB_INFO *infoPtr)
2925 TRACE("\n");
2926 return (LRESULT)infoPtr->himl;
2929 static inline LRESULT TAB_SetImageList (TAB_INFO *infoPtr, HIMAGELIST himlNew)
2931 HIMAGELIST himlPrev = infoPtr->himl;
2932 TRACE("\n");
2933 infoPtr->himl = himlNew;
2934 TAB_SetItemBounds(infoPtr);
2935 InvalidateRect(infoPtr->hwnd, NULL, TRUE);
2936 return (LRESULT)himlPrev;
2939 static inline LRESULT TAB_GetUnicodeFormat (const TAB_INFO *infoPtr)
2941 return infoPtr->bUnicode;
2944 static inline LRESULT TAB_SetUnicodeFormat (TAB_INFO *infoPtr, BOOL bUnicode)
2946 BOOL bTemp = infoPtr->bUnicode;
2948 infoPtr->bUnicode = bUnicode;
2950 return bTemp;
2953 static inline LRESULT TAB_Size (TAB_INFO *infoPtr)
2955 /* I'm not really sure what the following code was meant to do.
2956 This is what it is doing:
2957 When WM_SIZE is sent with SIZE_RESTORED, the control
2958 gets positioned in the top left corner.
2960 RECT parent_rect;
2961 HWND parent;
2962 UINT uPosFlags,cx,cy;
2964 uPosFlags=0;
2965 if (!wParam) {
2966 parent = GetParent (hwnd);
2967 GetClientRect(parent, &parent_rect);
2968 cx=LOWORD (lParam);
2969 cy=HIWORD (lParam);
2970 if (GetWindowLongW(hwnd, GWL_STYLE) & CCS_NORESIZE)
2971 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2973 SetWindowPos (hwnd, 0, parent_rect.left, parent_rect.top,
2974 cx, cy, uPosFlags | SWP_NOZORDER);
2975 } else {
2976 FIXME("WM_SIZE flag %x %lx not handled\n", wParam, lParam);
2977 } */
2979 /* Recompute the size/position of the tabs. */
2980 TAB_SetItemBounds (infoPtr);
2982 /* Force a repaint of the control. */
2983 InvalidateRect(infoPtr->hwnd, NULL, TRUE);
2985 return 0;
2989 static LRESULT TAB_Create (HWND hwnd, LPARAM lParam)
2991 TAB_INFO *infoPtr;
2992 TEXTMETRICW fontMetrics;
2993 HDC hdc;
2994 HFONT hOldFont;
2995 DWORD dwStyle;
2997 infoPtr = Alloc (sizeof(TAB_INFO));
2999 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
3001 infoPtr->hwnd = hwnd;
3002 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
3003 infoPtr->uNumItem = 0;
3004 infoPtr->uNumRows = 0;
3005 infoPtr->uHItemPadding = 6;
3006 infoPtr->uVItemPadding = 3;
3007 infoPtr->uHItemPadding_s = 6;
3008 infoPtr->uVItemPadding_s = 3;
3009 infoPtr->hFont = 0;
3010 infoPtr->items = 0;
3011 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3012 infoPtr->iSelected = -1;
3013 infoPtr->iHotTracked = -1;
3014 infoPtr->uFocus = -1;
3015 infoPtr->hwndToolTip = 0;
3016 infoPtr->DoRedraw = TRUE;
3017 infoPtr->needsScrolling = FALSE;
3018 infoPtr->hwndUpDown = 0;
3019 infoPtr->leftmostVisible = 0;
3020 infoPtr->fHeightSet = FALSE;
3021 infoPtr->bUnicode = IsWindowUnicode (hwnd);
3022 infoPtr->cbInfo = sizeof(LPARAM);
3024 TRACE("Created tab control, hwnd [%p]\n", hwnd);
3026 /* The tab control always has the WS_CLIPSIBLINGS style. Even
3027 if you don't specify it in CreateWindow. This is necessary in
3028 order for paint to work correctly. This follows windows behaviour. */
3029 dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
3030 SetWindowLongW(hwnd, GWL_STYLE, dwStyle|WS_CLIPSIBLINGS);
3032 infoPtr->exStyle = (dwStyle & TCS_FLATBUTTONS) ? TCS_EX_FLATSEPARATORS : 0;
3034 if (dwStyle & TCS_TOOLTIPS) {
3035 /* Create tooltip control */
3036 infoPtr->hwndToolTip =
3037 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
3038 CW_USEDEFAULT, CW_USEDEFAULT,
3039 CW_USEDEFAULT, CW_USEDEFAULT,
3040 hwnd, 0, 0, 0);
3042 /* Send NM_TOOLTIPSCREATED notification */
3043 if (infoPtr->hwndToolTip) {
3044 NMTOOLTIPSCREATED nmttc;
3046 nmttc.hdr.hwndFrom = hwnd;
3047 nmttc.hdr.idFrom = GetWindowLongPtrW(hwnd, GWLP_ID);
3048 nmttc.hdr.code = NM_TOOLTIPSCREATED;
3049 nmttc.hwndToolTips = infoPtr->hwndToolTip;
3051 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
3052 (WPARAM)GetWindowLongPtrW(hwnd, GWLP_ID), (LPARAM)&nmttc);
3056 OpenThemeData (infoPtr->hwnd, themeClass);
3059 * We need to get text information so we need a DC and we need to select
3060 * a font.
3062 hdc = GetDC(hwnd);
3063 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
3065 /* Use the system font to determine the initial height of a tab. */
3066 GetTextMetricsW(hdc, &fontMetrics);
3069 * Make sure there is enough space for the letters + growing the
3070 * selected item + extra space for the selected item.
3072 infoPtr->tabHeight = fontMetrics.tmHeight + SELECTED_TAB_OFFSET +
3073 ((dwStyle & TCS_BUTTONS) ? 2 : 1) *
3074 infoPtr->uVItemPadding;
3076 /* Initialize the width of a tab. */
3077 if (dwStyle & TCS_FIXEDWIDTH)
3078 infoPtr->tabWidth = GetDeviceCaps(hdc, LOGPIXELSX);
3080 infoPtr->tabMinWidth = -1;
3082 TRACE("tabH=%d, tabW=%d\n", infoPtr->tabHeight, infoPtr->tabWidth);
3084 SelectObject (hdc, hOldFont);
3085 ReleaseDC(hwnd, hdc);
3087 return 0;
3090 static LRESULT
3091 TAB_Destroy (TAB_INFO *infoPtr)
3093 UINT iItem;
3095 if (!infoPtr)
3096 return 0;
3098 SetWindowLongPtrW(infoPtr->hwnd, 0, 0);
3100 if (infoPtr->items) {
3101 for (iItem = 0; iItem < infoPtr->uNumItem; iItem++) {
3102 Free (TAB_GetItem(infoPtr, iItem)->pszText);
3104 Free (infoPtr->items);
3107 if (infoPtr->hwndToolTip)
3108 DestroyWindow (infoPtr->hwndToolTip);
3110 if (infoPtr->hwndUpDown)
3111 DestroyWindow(infoPtr->hwndUpDown);
3113 if (infoPtr->iHotTracked >= 0)
3114 KillTimer(infoPtr->hwnd, TAB_HOTTRACK_TIMER);
3116 CloseThemeData (GetWindowTheme (infoPtr->hwnd));
3118 Free (infoPtr);
3119 return 0;
3122 /* update theme after a WM_THEMECHANGED message */
3123 static LRESULT theme_changed(const TAB_INFO *infoPtr)
3125 HTHEME theme = GetWindowTheme (infoPtr->hwnd);
3126 CloseThemeData (theme);
3127 OpenThemeData (infoPtr->hwnd, themeClass);
3128 return 0;
3131 static LRESULT TAB_NCCalcSize(WPARAM wParam)
3133 if (!wParam)
3134 return 0;
3135 return WVR_ALIGNTOP;
3138 static inline LRESULT
3139 TAB_SetItemExtra (TAB_INFO *infoPtr, INT cbInfo)
3141 if (!infoPtr || cbInfo <= 0)
3142 return FALSE;
3144 if (infoPtr->uNumItem)
3146 /* FIXME: MSDN says this is not allowed, but this hasn't been verified */
3147 return FALSE;
3150 infoPtr->cbInfo = cbInfo;
3151 return TRUE;
3154 static LRESULT TAB_RemoveImage (TAB_INFO *infoPtr, INT image)
3156 if (!infoPtr)
3157 return 0;
3159 if (ImageList_Remove (infoPtr->himl, image))
3161 INT i, *idx;
3162 RECT r;
3164 /* shift indices, repaint items if needed */
3165 for (i = 0; i < infoPtr->uNumItem; i++)
3167 idx = &TAB_GetItem(infoPtr, i)->iImage;
3168 if (*idx >= image)
3170 if (*idx == image)
3171 *idx = -1;
3172 else
3173 (*idx)--;
3175 /* repaint item */
3176 if (TAB_InternalGetItemRect (infoPtr, i, &r, NULL))
3177 InvalidateRect (infoPtr->hwnd, &r, TRUE);
3182 return 0;
3185 static LRESULT
3186 TAB_SetExtendedStyle (TAB_INFO *infoPtr, DWORD exMask, DWORD exStyle)
3188 DWORD prevstyle = infoPtr->exStyle;
3190 /* zero mask means all styles */
3191 if (exMask == 0) exMask = ~0;
3193 if (exMask & TCS_EX_REGISTERDROP)
3195 FIXME("TCS_EX_REGISTERDROP style unimplemented\n");
3196 exMask &= ~TCS_EX_REGISTERDROP;
3197 exStyle &= ~TCS_EX_REGISTERDROP;
3200 if (exMask & TCS_EX_FLATSEPARATORS)
3202 if ((prevstyle ^ exStyle) & TCS_EX_FLATSEPARATORS)
3204 infoPtr->exStyle ^= TCS_EX_FLATSEPARATORS;
3205 TAB_InvalidateTabArea(infoPtr);
3209 return prevstyle;
3212 static inline LRESULT
3213 TAB_GetExtendedStyle (TAB_INFO *infoPtr)
3215 return infoPtr->exStyle;
3218 static LRESULT
3219 TAB_DeselectAll (TAB_INFO *infoPtr, BOOL excludesel)
3221 LONG style = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
3222 BOOL paint = FALSE;
3223 INT i, selected = infoPtr->iSelected;
3225 if (!(style & TCS_BUTTONS))
3226 return 0;
3228 for (i = 0; i < infoPtr->uNumItem; i++)
3230 if ((TAB_GetItem(infoPtr, i)->dwState & TCIS_BUTTONPRESSED) &&
3231 (selected != i))
3233 TAB_GetItem(infoPtr, i)->dwState &= ~TCIS_BUTTONPRESSED;
3234 paint = TRUE;
3238 if (!excludesel && (selected != -1))
3240 TAB_GetItem(infoPtr, selected)->dwState &= ~TCIS_BUTTONPRESSED;
3241 infoPtr->iSelected = -1;
3242 paint = TRUE;
3245 if (paint)
3246 TAB_InvalidateTabArea (infoPtr);
3248 return 0;
3251 static LRESULT WINAPI
3252 TAB_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3254 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
3256 TRACE("hwnd=%p msg=%x wParam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
3257 if (!infoPtr && (uMsg != WM_CREATE))
3258 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3260 switch (uMsg)
3262 case TCM_GETIMAGELIST:
3263 return TAB_GetImageList (infoPtr);
3265 case TCM_SETIMAGELIST:
3266 return TAB_SetImageList (infoPtr, (HIMAGELIST)lParam);
3268 case TCM_GETITEMCOUNT:
3269 return TAB_GetItemCount (infoPtr);
3271 case TCM_GETITEMA:
3272 case TCM_GETITEMW:
3273 return TAB_GetItemT (infoPtr, (INT)wParam, (LPTCITEMW)lParam, uMsg == TCM_GETITEMW);
3275 case TCM_SETITEMA:
3276 case TCM_SETITEMW:
3277 return TAB_SetItemT (infoPtr, (INT)wParam, (LPTCITEMW)lParam, uMsg == TCM_SETITEMW);
3279 case TCM_DELETEITEM:
3280 return TAB_DeleteItem (infoPtr, (INT)wParam);
3282 case TCM_DELETEALLITEMS:
3283 return TAB_DeleteAllItems (infoPtr);
3285 case TCM_GETITEMRECT:
3286 return TAB_GetItemRect (infoPtr, wParam, lParam);
3288 case TCM_GETCURSEL:
3289 return TAB_GetCurSel (infoPtr);
3291 case TCM_HITTEST:
3292 return TAB_HitTest (infoPtr, (LPTCHITTESTINFO)lParam);
3294 case TCM_SETCURSEL:
3295 return TAB_SetCurSel (infoPtr, (INT)wParam);
3297 case TCM_INSERTITEMA:
3298 case TCM_INSERTITEMW:
3299 return TAB_InsertItemT (infoPtr, wParam, lParam, uMsg == TCM_INSERTITEMW);
3301 case TCM_SETITEMEXTRA:
3302 return TAB_SetItemExtra (infoPtr, (int)wParam);
3304 case TCM_ADJUSTRECT:
3305 return TAB_AdjustRect (infoPtr, (BOOL)wParam, (LPRECT)lParam);
3307 case TCM_SETITEMSIZE:
3308 return TAB_SetItemSize (infoPtr, lParam);
3310 case TCM_REMOVEIMAGE:
3311 return TAB_RemoveImage (infoPtr, wParam);
3313 case TCM_SETPADDING:
3314 return TAB_SetPadding (infoPtr, lParam);
3316 case TCM_GETROWCOUNT:
3317 return TAB_GetRowCount(infoPtr);
3319 case TCM_GETUNICODEFORMAT:
3320 return TAB_GetUnicodeFormat (infoPtr);
3322 case TCM_SETUNICODEFORMAT:
3323 return TAB_SetUnicodeFormat (infoPtr, (BOOL)wParam);
3325 case TCM_HIGHLIGHTITEM:
3326 return TAB_HighlightItem (infoPtr, (INT)wParam, (BOOL)LOWORD(lParam));
3328 case TCM_GETTOOLTIPS:
3329 return TAB_GetToolTips (infoPtr);
3331 case TCM_SETTOOLTIPS:
3332 return TAB_SetToolTips (infoPtr, (HWND)wParam);
3334 case TCM_GETCURFOCUS:
3335 return TAB_GetCurFocus (infoPtr);
3337 case TCM_SETCURFOCUS:
3338 return TAB_SetCurFocus (infoPtr, (INT)wParam);
3340 case TCM_SETMINTABWIDTH:
3341 return TAB_SetMinTabWidth(infoPtr, (INT)lParam);
3343 case TCM_DESELECTALL:
3344 return TAB_DeselectAll (infoPtr, (BOOL)wParam);
3346 case TCM_GETEXTENDEDSTYLE:
3347 return TAB_GetExtendedStyle (infoPtr);
3349 case TCM_SETEXTENDEDSTYLE:
3350 return TAB_SetExtendedStyle (infoPtr, wParam, lParam);
3352 case WM_GETFONT:
3353 return TAB_GetFont (infoPtr);
3355 case WM_SETFONT:
3356 return TAB_SetFont (infoPtr, (HFONT)wParam);
3358 case WM_CREATE:
3359 return TAB_Create (hwnd, lParam);
3361 case WM_NCDESTROY:
3362 return TAB_Destroy (infoPtr);
3364 case WM_GETDLGCODE:
3365 return DLGC_WANTARROWS | DLGC_WANTCHARS;
3367 case WM_LBUTTONDOWN:
3368 return TAB_LButtonDown (infoPtr, wParam, lParam);
3370 case WM_LBUTTONUP:
3371 return TAB_LButtonUp (infoPtr);
3373 case WM_NOTIFY:
3374 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
3376 case WM_RBUTTONDOWN:
3377 return TAB_RButtonDown (infoPtr);
3379 case WM_MOUSEMOVE:
3380 return TAB_MouseMove (infoPtr, wParam, lParam);
3382 case WM_PRINTCLIENT:
3383 case WM_PAINT:
3384 return TAB_Paint (infoPtr, (HDC)wParam);
3386 case WM_SIZE:
3387 return TAB_Size (infoPtr);
3389 case WM_SETREDRAW:
3390 return TAB_SetRedraw (infoPtr, (BOOL)wParam);
3392 case WM_HSCROLL:
3393 return TAB_OnHScroll(infoPtr, (int)LOWORD(wParam), (int)HIWORD(wParam));
3395 case WM_STYLECHANGED:
3396 TAB_SetItemBounds (infoPtr);
3397 InvalidateRect(hwnd, NULL, TRUE);
3398 return 0;
3400 case WM_SYSCOLORCHANGE:
3401 COMCTL32_RefreshSysColors();
3402 return 0;
3404 case WM_THEMECHANGED:
3405 return theme_changed (infoPtr);
3407 case WM_KILLFOCUS:
3408 case WM_SETFOCUS:
3409 TAB_FocusChanging(infoPtr);
3410 break; /* Don't disturb normal focus behavior */
3412 case WM_KEYUP:
3413 return TAB_KeyUp(infoPtr, wParam);
3414 case WM_NCHITTEST:
3415 return TAB_NCHitTest(infoPtr, lParam);
3417 case WM_NCCALCSIZE:
3418 return TAB_NCCalcSize(wParam);
3420 default:
3421 if (uMsg >= WM_USER && uMsg < WM_APP && !COMCTL32_IsReflectedMessage(uMsg))
3422 WARN("unknown msg %04x wp=%08lx lp=%08lx\n",
3423 uMsg, wParam, lParam);
3424 break;
3426 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
3430 void
3431 TAB_Register (void)
3433 WNDCLASSW wndClass;
3435 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
3436 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
3437 wndClass.lpfnWndProc = TAB_WindowProc;
3438 wndClass.cbClsExtra = 0;
3439 wndClass.cbWndExtra = sizeof(TAB_INFO *);
3440 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3441 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
3442 wndClass.lpszClassName = WC_TABCONTROLW;
3444 RegisterClassW (&wndClass);
3448 void
3449 TAB_Unregister (void)
3451 UnregisterClassW (WC_TABCONTROLW, NULL);