source: trunk/src/comctl32/tab.c@ 236

Last change on this file since 236 was 236, checked in by cbratschi, 26 years ago

bug fixes (unicode) and improvements

File size: 44.5 KB
Line 
1/* $Id: tab.c,v 1.6 1999-06-28 15:46:26 cbratschi Exp $ */
2/*
3 * Tab control
4 *
5 * Copyright 1998 Anders Carlsson
6 * Copyright 1999 Alex Priem <alexp@sci.kun.nl>
7 * Copyright 1999 Francis Beaudet
8 * Copyright 1999 Achim Hasenmueller
9 * Copyright 1999 Christoph Bratschi
10 *
11 * TODO:
12 * Image list support
13 * Multiline support
14 * Unicode support
15 */
16
17#include <string.h>
18
19#include "winbase.h"
20#include "commctrl.h"
21#include "tab.h"
22
23
24/******************************************************************************
25 * Positioning constants
26 */
27#define SELECTED_TAB_OFFSET 2
28#define HORIZONTAL_ITEM_PADDING 5
29#define VERTICAL_ITEM_PADDING 3
30#define ROUND_CORNER_SIZE 2
31#define FOCUS_RECT_HOFFSET 2
32#define FOCUS_RECT_VOFFSET 1
33#define DISPLAY_AREA_PADDINGX 5
34#define DISPLAY_AREA_PADDINGY 5
35#define CONTROL_BORDER_SIZEX 2
36#define CONTROL_BORDER_SIZEY 2
37#define BUTTON_SPACINGX 10
38#define DEFAULT_TAB_WIDTH 96
39
40#define TAB_GetInfoPtr(hwnd) ((TAB_INFO *)GetWindowLongA(hwnd,0))
41
42/******************************************************************************
43 * Prototypes
44 */
45static void TAB_Refresh (HWND hwnd, HDC hdc);
46static void TAB_InvalidateTabArea(HWND hwnd, TAB_INFO* infoPtr);
47static void TAB_EnsureSelectionVisible(HWND hwnd, TAB_INFO* infoPtr);
48
49static BOOL
50TAB_SendSimpleNotify (HWND hwnd, UINT code)
51{
52 NMHDR nmhdr;
53
54 nmhdr.hwndFrom = hwnd;
55 nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
56 nmhdr.code = code;
57
58 return (BOOL) SendMessageA (GetParent (hwnd), WM_NOTIFY,
59 (WPARAM) nmhdr.idFrom, (LPARAM) &nmhdr);
60}
61
62
63static VOID
64TAB_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
65 WPARAM wParam, LPARAM lParam)
66{
67 MSG msg;
68
69 msg.hwnd = hwndMsg;
70 msg.message = uMsg;
71 msg.wParam = wParam;
72 msg.lParam = lParam;
73 msg.time = GetMessageTime ();
74 msg.pt.x = LOWORD(GetMessagePos ());
75 msg.pt.y = HIWORD(GetMessagePos ());
76
77 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
78}
79
80
81
82static LRESULT
83TAB_GetCurSel (HWND hwnd)
84{
85 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
86
87 return infoPtr->iSelected;
88}
89
90static LRESULT
91TAB_GetCurFocus (HWND hwnd)
92{
93 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
94
95 return infoPtr->uFocus;
96}
97
98static LRESULT
99TAB_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
100{
101 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
102
103 if (infoPtr == NULL) return 0;
104 return infoPtr->hwndToolTip;
105}
106
107
108static LRESULT
109TAB_SetCurSel (HWND hwnd,WPARAM wParam)
110{
111 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
112 INT iItem=(INT) wParam;
113 INT prevItem;
114
115 prevItem=-1;
116 if ((iItem >= 0) && (iItem < infoPtr->uNumItem)) {
117 prevItem=infoPtr->iSelected;
118 infoPtr->iSelected=iItem;
119 }
120 return prevItem;
121}
122
123static LRESULT
124TAB_SetCurFocus (HWND hwnd,WPARAM wParam)
125{
126 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
127 INT iItem=(INT) wParam;
128
129 if ((iItem < 0) || (iItem > infoPtr->uNumItem)) return 0;
130
131 infoPtr->uFocus=iItem;
132 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_BUTTONS) {
133// FIXME (tab,"Should set input focus\n");
134 } else {
135 if (infoPtr->iSelected != iItem) {
136 if (TAB_SendSimpleNotify(hwnd, TCN_SELCHANGING)!=TRUE) {
137 infoPtr->iSelected = iItem;
138 TAB_SendSimpleNotify(hwnd, TCN_SELCHANGE);
139
140 TAB_EnsureSelectionVisible(hwnd, infoPtr);
141 TAB_InvalidateTabArea(hwnd, infoPtr);
142 }
143 }
144 }
145 return 0;
146}
147
148static LRESULT
149TAB_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
150{
151 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
152
153 if (infoPtr == NULL) return 0;
154 infoPtr->hwndToolTip = (HWND)wParam;
155 return 0;
156}
157
158/******************************************************************************
159 * TAB_InternalGetItemRect
160 *
161 * This method will calculate the rectangle representing a given tab item in
162 * client coordinates. This method takes scrolling into account.
163 *
164 * This method returns TRUE if the item is visible in the window and FALSE
165 * if it is completely outside the client area.
166 */
167static BOOL TAB_InternalGetItemRect(
168 HWND hwnd,
169 TAB_INFO* infoPtr,
170 INT itemIndex,
171 RECT* itemRect,
172 RECT* selectedRect)
173{
174 RECT tmpItemRect;
175
176 /*
177 * Perform a sanity check and a trivial visibility check.
178 */
179 if ( (infoPtr->uNumItem == 0) ||
180 (itemIndex >= infoPtr->uNumItem) ||
181 (itemIndex < infoPtr->leftmostVisible) )
182 return FALSE;
183
184 /*
185 * Avoid special cases in this procedure by assigning the "out"
186 * parameters if the caller didn't supply them
187 */
188 if (itemRect==NULL)
189 itemRect = &tmpItemRect;
190
191 /*
192 * Retrieve the unmodified item rect.
193 */
194 *itemRect = infoPtr->items[itemIndex].rect;
195
196 /*
197 * "scroll" it to make sure the item at the very left of the
198 * tab control is the leftmost visible tab.
199 */
200 OffsetRect(itemRect,
201 -infoPtr->items[infoPtr->leftmostVisible].rect.left,
202 0);
203
204 /*
205 * Move the rectangle so the first item is slightly offset from
206 * the left of the tab control.
207 */
208 OffsetRect(itemRect,
209 SELECTED_TAB_OFFSET,
210 0);
211
212
213 /*
214 * Now, calculate the position of the item as if it were selected.
215 */
216 if (selectedRect!=NULL)
217 {
218 CopyRect(selectedRect, itemRect);
219
220 /*
221 * The rectangle of a selected item is a bit wider.
222 */
223 InflateRect(selectedRect, SELECTED_TAB_OFFSET, 0);
224
225 /*
226 * If it also a bit higher.
227 */
228 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_BOTTOM)
229 {
230 selectedRect->top -=2; /* the border is thicker on the bottom */
231 selectedRect->bottom +=SELECTED_TAB_OFFSET;
232 }
233 else
234 {
235 selectedRect->top -=SELECTED_TAB_OFFSET;
236 selectedRect->bottom+=1;
237 }
238 }
239
240 return TRUE;
241}
242
243static BOOL TAB_GetItemRect(HWND hwnd, WPARAM wParam, LPARAM lParam)
244{
245 return TAB_InternalGetItemRect(hwnd, TAB_GetInfoPtr(hwnd), (INT)wParam,
246 (LPRECT)lParam, (LPRECT)NULL);
247}
248
249/******************************************************************************
250 * TAB_KeyUp
251 *
252 * This method is called to handle keyboard input
253 */
254static LRESULT TAB_KeyUp(
255 HWND hwnd,
256 WPARAM keyCode)
257{
258 TAB_INFO* infoPtr = TAB_GetInfoPtr(hwnd);
259 int newItem = -1;
260
261 switch (keyCode)
262 {
263 case VK_LEFT:
264 newItem = infoPtr->uFocus-1;
265 break;
266 case VK_RIGHT:
267 newItem = infoPtr->uFocus+1;
268 break;
269 }
270
271 /*
272 * If we changed to a valid item, change the selection
273 */
274 if ( (newItem >= 0) &&
275 (newItem < infoPtr->uNumItem) &&
276 (infoPtr->uFocus != newItem) )
277 {
278 if (!TAB_SendSimpleNotify(hwnd, TCN_SELCHANGING))
279 {
280 infoPtr->iSelected = newItem;
281 infoPtr->uFocus = newItem;
282 TAB_SendSimpleNotify(hwnd, TCN_SELCHANGE);
283
284 TAB_EnsureSelectionVisible(hwnd, infoPtr);
285 TAB_InvalidateTabArea(hwnd, infoPtr);
286 }
287 }
288
289 return 0;
290}
291
292/******************************************************************************
293 * TAB_FocusChanging
294 *
295 * This method is called whenever the focus goes in or out of this control
296 * it is used to update the visual state of the control.
297 */
298static LRESULT TAB_FocusChanging(
299 HWND hwnd,
300 UINT uMsg,
301 WPARAM wParam,
302 LPARAM lParam)
303{
304 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
305 RECT selectedRect;
306 BOOL isVisible;
307
308 /*
309 * Get the rectangle for the item.
310 */
311 isVisible = TAB_InternalGetItemRect(hwnd,
312 infoPtr,
313 infoPtr->uFocus,
314 NULL,
315 &selectedRect);
316
317 /*
318 * If the rectangle is not completely invisible, invalidate that
319 * portion of the window.
320 */
321 if (isVisible)
322 {
323 InvalidateRect(hwnd, &selectedRect, TRUE);
324 }
325
326 /*
327 * Don't otherwise disturb normal behavior.
328 */
329 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
330}
331
332static HWND TAB_InternalHitTest (
333 HWND hwnd,
334 TAB_INFO* infoPtr,
335 POINT pt,
336 UINT* flags)
337
338{
339 RECT rect;
340 int iCount;
341
342 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++)
343 {
344 TAB_InternalGetItemRect(hwnd,
345 infoPtr,
346 iCount,
347 &rect,
348 NULL);
349
350 if (PtInRect (&rect, pt))
351 {
352 *flags = TCHT_ONITEM;
353 return iCount;
354 }
355 }
356
357 *flags=TCHT_NOWHERE;
358 return -1;
359}
360
361static LRESULT
362TAB_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
363{
364 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
365 LPTCHITTESTINFO lptest=(LPTCHITTESTINFO) lParam;
366
367 return TAB_InternalHitTest (hwnd, infoPtr,lptest->pt,&lptest->flags);
368}
369
370
371static LRESULT
372TAB_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
373{
374 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
375
376 if (infoPtr->hwndToolTip)
377 TAB_RelayEvent (infoPtr->hwndToolTip, hwnd,
378 WM_LBUTTONDOWN, wParam, lParam);
379
380 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_FOCUSONBUTTONDOWN ) {
381 SetFocus (hwnd);
382 }
383 return 0;
384}
385
386static LRESULT
387TAB_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
388{
389 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
390 POINT pt;
391 INT newItem,dummy;
392
393 if (infoPtr->hwndToolTip)
394 TAB_RelayEvent (infoPtr->hwndToolTip, hwnd,
395 WM_LBUTTONDOWN, wParam, lParam);
396
397 pt.x = (INT)LOWORD(lParam);
398 pt.y = (INT)HIWORD(lParam);
399
400 newItem=TAB_InternalHitTest (hwnd, infoPtr,pt,(unsigned int*)&dummy);
401
402// TRACE(tab, "On Tab, item %d\n", newItem);
403
404 if ( (newItem!=-1) &&
405 (infoPtr->iSelected != newItem) )
406 {
407 if (TAB_SendSimpleNotify(hwnd, TCN_SELCHANGING)!=TRUE)
408 {
409 infoPtr->iSelected = newItem;
410 infoPtr->uFocus = newItem;
411 TAB_SendSimpleNotify(hwnd, TCN_SELCHANGE);
412
413 TAB_EnsureSelectionVisible(hwnd, infoPtr);
414
415 TAB_InvalidateTabArea(hwnd, infoPtr);
416 }
417 }
418 TAB_SendSimpleNotify(hwnd, NM_CLICK);
419
420 return 0;
421}
422
423static LRESULT
424TAB_RButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
425{
426 TAB_SendSimpleNotify(hwnd, NM_RCLICK);
427 return 0;
428}
429
430static LRESULT
431TAB_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
432{
433 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
434
435 if (infoPtr->hwndToolTip)
436 TAB_RelayEvent (infoPtr->hwndToolTip, hwnd,
437 WM_LBUTTONDOWN, wParam, lParam);
438 return 0;
439}
440
441/******************************************************************************
442 * TAB_AdjustRect
443 *
444 * Calculates the tab control's display area given the windows rectangle or
445 * the window rectangle given the requested display rectangle.
446 */
447static LRESULT TAB_AdjustRect(
448 HWND hwnd,
449 WPARAM fLarger,
450 LPRECT prc)
451{
452 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
453
454 if (fLarger)
455 {
456 /*
457 * Go from display rectangle
458 */
459
460 /*
461 * Add the height of the tabs.
462 */
463 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_BOTTOM)
464 prc->bottom += infoPtr->tabHeight;
465 else
466 prc->top -= infoPtr->tabHeight;
467
468 /*
469 * Inflate the rectangle for the padding
470 */
471 InflateRect(prc, DISPLAY_AREA_PADDINGX, DISPLAY_AREA_PADDINGY);
472
473 /*
474 * Inflate for the border
475 */
476 InflateRect(prc, CONTROL_BORDER_SIZEX, CONTROL_BORDER_SIZEX);
477 }
478 else
479 {
480 /*
481 * Go from window rectangle.
482 */
483
484 /*
485 * Deflate the rectangle for the border
486 */
487 InflateRect(prc, -CONTROL_BORDER_SIZEX, -CONTROL_BORDER_SIZEX);
488
489 /*
490 * Deflate the rectangle for the padding
491 */
492 InflateRect(prc, -DISPLAY_AREA_PADDINGX, -DISPLAY_AREA_PADDINGY);
493
494 /*
495 * Remove the height of the tabs.
496 */
497 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_BOTTOM)
498 prc->bottom -= infoPtr->tabHeight;
499 else
500 prc->top += infoPtr->tabHeight;
501
502 }
503
504 return 0;
505}
506
507/******************************************************************************
508 * TAB_OnHScroll
509 *
510 * This method will handle the notification from the scroll control and
511 * perform the scrolling operation on the tab control.
512 */
513static LRESULT TAB_OnHScroll(
514 HWND hwnd,
515 int nScrollCode,
516 int nPos,
517 HWND hwndScroll)
518{
519 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
520
521 if (nScrollCode == SB_LINELEFT)
522 {
523 if (infoPtr->leftmostVisible>0)
524 {
525 infoPtr->leftmostVisible--;
526
527 TAB_InvalidateTabArea(hwnd, infoPtr);
528 }
529 }
530 else if (nScrollCode == SB_LINERIGHT)
531 {
532 if (infoPtr->leftmostVisible< (infoPtr->uNumItem-1))
533 {
534 infoPtr->leftmostVisible++;
535
536 TAB_InvalidateTabArea(hwnd, infoPtr);
537 }
538 }
539
540 return 0;
541}
542
543/******************************************************************************
544 * TAB_SetupScroling
545 *
546 * This method will check the current scrolling state and make sure the
547 * scrolling control is displayed (or not).
548 */
549static void TAB_SetupScrolling(
550 HWND hwnd,
551 TAB_INFO* infoPtr,
552 const RECT* clientRect)
553{
554 if (infoPtr->needsScrolling)
555 {
556 RECT controlPos;
557
558 /*
559 * Calculate the position of the scroll control.
560 */
561 controlPos.right = clientRect->right;
562 controlPos.left = controlPos.right - 2*GetSystemMetrics(SM_CXHSCROLL);
563
564 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_BOTTOM)
565 {
566 controlPos.top = clientRect->bottom - infoPtr->tabHeight;
567 controlPos.bottom = controlPos.top + GetSystemMetrics(SM_CYHSCROLL);
568 }
569 else
570 {
571 controlPos.bottom = clientRect->top + infoPtr->tabHeight;
572 controlPos.top = controlPos.bottom - GetSystemMetrics(SM_CYHSCROLL);
573 }
574
575 /*
576 * If we don't have a scroll control yet, we want to create one.
577 * If we have one, we want to make sure it's positioned right.
578 */
579 if (infoPtr->hwndUpDown==0)
580 {
581 /*
582 * I use a scrollbar since it seems to be more stable than the Updown
583 * control.
584 */
585 infoPtr->hwndUpDown = CreateWindowA("ScrollBar",
586 "",
587 WS_VISIBLE | WS_CHILD | WS_OVERLAPPED | SBS_HORZ,
588 controlPos.left, controlPos.top,
589 controlPos.right - controlPos.left,
590 controlPos.bottom - controlPos.top,
591 hwnd,
592 (HMENU)NULL,
593 (HINSTANCE)NULL,
594 NULL);
595 }
596 else
597 {
598 SetWindowPos(infoPtr->hwndUpDown,
599 (HWND)NULL,
600 controlPos.left, controlPos.top,
601 controlPos.right - controlPos.left,
602 controlPos.bottom - controlPos.top,
603 SWP_SHOWWINDOW | SWP_NOZORDER);
604 }
605 }
606 else
607 {
608 /*
609 * If we once had a scroll control... hide it.
610 */
611 if (infoPtr->hwndUpDown!=0)
612 {
613 ShowWindow(infoPtr->hwndUpDown, SW_HIDE);
614 }
615 }
616}
617
618/******************************************************************************
619 * TAB_SetItemBounds
620 *
621 * This method will calculate the position rectangles of all the items in the
622 * control. The rectangle calculated starts at 0 for the first item in the
623 * list and ignores scrolling and selection.
624 * It also uses the current font to determine the height of the tab row and
625 * it checks if all the tabs fit in the client area of the window. If they
626 * dont, a scrolling control is added.
627 */
628static void TAB_SetItemBounds (HWND hwnd)
629{
630 TAB_INFO* infoPtr = TAB_GetInfoPtr(hwnd);
631 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
632 TEXTMETRICA fontMetrics;
633 INT curItem;
634 INT curItemLeftPos;
635 HFONT hFont, hOldFont;
636 HDC hdc;
637 RECT clientRect;
638 SIZE size;
639
640 /*
641 * We need to get text information so we need a DC and we need to select
642 * a font.
643 */
644 hdc = GetDC(hwnd);
645
646 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
647 hOldFont = SelectObject (hdc, hFont);
648
649 /*
650 * We will base the rectangle calculations on the client rectangle
651 * of the control.
652 */
653 GetClientRect(hwnd, &clientRect);
654
655 /*
656 * The leftmost item will be "0" aligned
657 */
658 curItemLeftPos = 0;
659
660 if (!((lStyle & TCS_FIXEDWIDTH) || (lStyle & TCS_OWNERDRAWFIXED)))
661 {
662 /*
663 * Use the current font to determine the height of a tab.
664 */
665 GetTextMetricsA(hdc, &fontMetrics);
666
667 /*
668 * Make sure there is enough space for the letters + growing the
669 * selected item + extra space for the selected item.
670 */
671 infoPtr->tabHeight = fontMetrics.tmHeight + 2*VERTICAL_ITEM_PADDING +
672 SELECTED_TAB_OFFSET;
673 }
674
675 for (curItem = 0; curItem < infoPtr->uNumItem; curItem++)
676 {
677 /*
678 * Calculate the vertical position of the tab
679 */
680 if (lStyle & TCS_BOTTOM)
681 {
682 infoPtr->items[curItem].rect.bottom = clientRect.bottom -
683 SELECTED_TAB_OFFSET;
684 infoPtr->items[curItem].rect.top = clientRect.bottom -
685 infoPtr->tabHeight;
686 }
687 else
688 {
689 infoPtr->items[curItem].rect.top = clientRect.top +
690 SELECTED_TAB_OFFSET;
691 infoPtr->items[curItem].rect.bottom = clientRect.top +
692 infoPtr->tabHeight;
693 }
694
695 /*
696 * Set the leftmost position of the tab.
697 */
698 infoPtr->items[curItem].rect.left = curItemLeftPos;
699
700 if ((lStyle & TCS_FIXEDWIDTH) || (lStyle & TCS_OWNERDRAWFIXED))
701 {
702 infoPtr->items[curItem].rect.right = infoPtr->items[curItem].rect.left +
703 infoPtr->tabWidth +
704 2*HORIZONTAL_ITEM_PADDING;
705 }
706 else
707 {
708 /*
709 * Calculate how wide the tab is depending on the text it contains
710 */
711 GetTextExtentPoint32A(hdc, infoPtr->items[curItem].pszText,
712 lstrlenA(infoPtr->items[curItem].pszText), &size);
713
714 infoPtr->items[curItem].rect.right = infoPtr->items[curItem].rect.left +
715 size.cx + 2*HORIZONTAL_ITEM_PADDING;
716 }
717
718// TRACE(tab, "TextSize: %i\n ", size.cx);
719// TRACE(tab, "Rect: T %i, L %i, B %i, R %i\n",
720// infoPtr->items[curItem].rect.top,
721// infoPtr->items[curItem].rect.left,
722// infoPtr->items[curItem].rect.bottom,
723// infoPtr->items[curItem].rect.right);
724
725 /*
726 * The leftmost position of the next item is the rightmost position
727 * of this one.
728 */
729 if (lStyle & TCS_BUTTONS)
730 curItemLeftPos = infoPtr->items[curItem].rect.right + BUTTON_SPACINGX;
731 else
732 curItemLeftPos = infoPtr->items[curItem].rect.right;
733 }
734
735 /*
736 * Check if we need a scrolling control.
737 */
738 infoPtr->needsScrolling = (curItemLeftPos + (2*SELECTED_TAB_OFFSET) >
739 clientRect.right);
740
741 TAB_SetupScrolling(hwnd, infoPtr, &clientRect);
742
743 /*
744 * Cleanup
745 */
746 SelectObject (hdc, hOldFont);
747 ReleaseDC (hwnd, hdc);
748}
749
750/******************************************************************************
751 * TAB_DrawItem
752 *
753 * This method is used to draw a single tab into the tab control.
754 */
755static void TAB_DrawItem(
756 HWND hwnd,
757 HDC hdc,
758 INT iItem)
759{
760 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
761 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
762 RECT itemRect;
763 RECT selectedRect;
764 BOOL isVisible;
765 RECT r;
766
767 /*
768 * Get the rectangle for the item.
769 */
770 isVisible = TAB_InternalGetItemRect(hwnd,
771 infoPtr,
772 iItem,
773 &itemRect,
774 &selectedRect);
775
776 if (isVisible)
777 {
778 HBRUSH hbr = CreateSolidBrush (GetSysColor(COLOR_BTNFACE));
779 HPEN hwPen = GetSysColorPen (COLOR_3DHILIGHT);
780 HPEN hbPen = GetSysColorPen (COLOR_BTNSHADOW);
781 HPEN hsdPen = GetSysColorPen (COLOR_BTNTEXT);
782 HPEN hfocusPen = CreatePen(PS_DOT, 1, GetSysColor(COLOR_BTNTEXT));
783 HPEN holdPen;
784 INT oldBkMode;
785 INT cx,cy;
786
787 if (lStyle & TCS_BUTTONS)
788 {
789 /*
790 * Get item rectangle.
791 */
792 r = itemRect;
793
794 holdPen = SelectObject (hdc, hwPen);
795
796 if (iItem == infoPtr->iSelected)
797 {
798 /*
799 * Background color.
800 */
801 if (!(lStyle & TCS_OWNERDRAWFIXED))
802 hbr = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
803
804 /*
805 * Erase the background.
806 */
807 FillRect(hdc, &r, hbr);
808
809 /*
810 * Draw the tab now.
811 * The rectangles calculated exclude the right and bottom
812 * borders of the rectangle. To simply the following code, those
813 * borders are shaved-off beforehand.
814 */
815 r.right--;
816 r.bottom--;
817
818 /* highlight */
819 MoveToEx (hdc, r.left, r.bottom, NULL);
820 LineTo (hdc, r.right, r.bottom);
821 LineTo (hdc, r.right, r.top);
822
823 /* shadow */
824 SelectObject(hdc, hbPen);
825 LineTo (hdc, r.left, r.top);
826 LineTo (hdc, r.left, r.bottom);
827 }
828 else
829 {
830 /*
831 * Erase the background.
832 */
833 FillRect(hdc, &r, hbr);
834
835 /* highlight */
836 MoveToEx (hdc, r.left, r.bottom, NULL);
837 LineTo (hdc, r.left, r.top);
838 LineTo (hdc, r.right, r.top);
839
840 /* shadow */
841 SelectObject(hdc, hbPen);
842 LineTo (hdc, r.right, r.bottom);
843 LineTo (hdc, r.left, r.bottom);
844 }
845 }
846 else
847 {
848 /*
849 * Background color.
850 */
851 hbr = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
852
853 /*
854 * We draw a rectangle of different sizes depending on the selection
855 * state.
856 */
857 if (iItem == infoPtr->iSelected)
858 r = selectedRect;
859 else
860 r = itemRect;
861
862 /*
863 * Erase the background.
864 * This is necessary when drawing the selected item since it is larger
865 * than the others, it might overlap with stuff already drawn by the
866 * other tabs
867 */
868 FillRect(hdc, &r, hbr);
869
870 /*
871 * Draw the tab now.
872 * The rectangles calculated exclude the right and bottom
873 * borders of the rectangle. To simply the following code, those
874 * borders are shaved-off beforehand.
875 */
876 r.right--;
877 r.bottom--;
878
879 holdPen = SelectObject (hdc, hwPen);
880
881 if (lStyle & TCS_BOTTOM)
882 {
883 /* highlight */
884 MoveToEx (hdc, r.left, r.top, NULL);
885 LineTo (hdc, r.left, r.bottom - ROUND_CORNER_SIZE);
886 LineTo (hdc, r.left + ROUND_CORNER_SIZE, r.bottom);
887
888 /* shadow */
889 SelectObject(hdc, hbPen);
890 LineTo (hdc, r.right - ROUND_CORNER_SIZE, r.bottom);
891 LineTo (hdc, r.right, r.bottom - ROUND_CORNER_SIZE);
892 LineTo (hdc, r.right, r.top);
893 }
894 else
895 {
896 /* highlight */
897 MoveToEx (hdc, r.left, r.bottom, NULL);
898 LineTo (hdc, r.left, r.top + ROUND_CORNER_SIZE);
899 LineTo (hdc, r.left + ROUND_CORNER_SIZE, r.top);
900 LineTo (hdc, r.right - ROUND_CORNER_SIZE, r.top);
901
902 /* shadow */
903 SelectObject(hdc, hbPen);
904 LineTo (hdc, r.right, r.top + ROUND_CORNER_SIZE);
905 LineTo (hdc, r.right, r.bottom);
906 }
907 }
908
909 /*
910 * Text pen
911 */
912 SelectObject(hdc, hsdPen);
913
914 oldBkMode = SetBkMode(hdc, TRANSPARENT);
915 SetTextColor (hdc, COLOR_BTNTEXT);
916
917 /*
918 * Deflate the rectangle to acount for the padding
919 */
920 InflateRect(&r, -HORIZONTAL_ITEM_PADDING, -VERTICAL_ITEM_PADDING);
921
922 /*
923 * Draw the icon.
924 */
925 if (infoPtr->himl)
926 {
927 ImageList_Draw (infoPtr->himl, iItem, hdc,
928 r.left, r.top+1, ILD_NORMAL);
929 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
930 r.left+=cx;
931 }
932
933 /*
934 * Draw the text;
935 */
936 DrawTextA(hdc,
937 infoPtr->items[iItem].pszText,
938 lstrlenA(infoPtr->items[iItem].pszText),
939 &r,
940 DT_LEFT|DT_SINGLELINE|DT_VCENTER);
941
942 /*
943 * Draw the focus rectangle
944 */
945 if (((lStyle & TCS_FOCUSNEVER) == 0) &&
946 (GetFocus() == hwnd) &&
947 (iItem == infoPtr->uFocus) )
948 {
949 InflateRect(&r, FOCUS_RECT_HOFFSET, FOCUS_RECT_VOFFSET);
950
951 SelectObject(hdc, hfocusPen);
952
953 MoveToEx (hdc, r.left, r.top, NULL);
954 LineTo (hdc, r.right-1, r.top);
955 LineTo (hdc, r.right-1, r.bottom -1);
956 LineTo (hdc, r.left, r.bottom -1);
957 LineTo (hdc, r.left, r.top);
958 }
959
960 /*
961 * Cleanup
962 */
963 SetBkMode(hdc, oldBkMode);
964 SelectObject(hdc, holdPen);
965 }
966}
967
968/******************************************************************************
969 * TAB_DrawBorder
970 *
971 * This method is used to draw the raised border around the tab control
972 * "content" area.
973 */
974static void TAB_DrawBorder (HWND hwnd, HDC hdc)
975{
976 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
977 HPEN htmPen;
978 HPEN hwPen = GetSysColorPen (COLOR_3DHILIGHT);
979 HPEN hbPen = GetSysColorPen (COLOR_3DDKSHADOW);
980 HPEN hShade = GetSysColorPen (COLOR_BTNSHADOW);
981 RECT rect;
982
983 GetClientRect (hwnd, &rect);
984
985 /*
986 * Adjust for the style
987 */
988 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_BOTTOM)
989 {
990 rect.bottom -= infoPtr->tabHeight;
991 }
992 else
993 {
994 rect.top += infoPtr->tabHeight;
995 }
996
997 /*
998 * Shave-off the right and bottom margins (exluded in the
999 * rect)
1000 */
1001 rect.right--;
1002 rect.bottom--;
1003
1004 /* highlight */
1005 htmPen = SelectObject (hdc, hwPen);
1006
1007 MoveToEx (hdc, rect.left, rect.bottom, NULL);
1008 LineTo (hdc, rect.left, rect.top);
1009 LineTo (hdc, rect.right, rect.top);
1010
1011 /* Dark Shadow */
1012 SelectObject (hdc, hbPen);
1013 LineTo (hdc, rect.right, rect.bottom );
1014 LineTo (hdc, rect.left, rect.bottom);
1015
1016 /* shade */
1017 SelectObject (hdc, hShade );
1018 MoveToEx (hdc, rect.right-1, rect.top, NULL);
1019 LineTo (hdc, rect.right-1, rect.bottom-1);
1020 LineTo (hdc, rect.left, rect.bottom-1);
1021
1022 SelectObject(hdc, htmPen);
1023}
1024
1025/******************************************************************************
1026 * TAB_Refresh
1027 *
1028 * This method repaints the tab control..
1029 */
1030static void TAB_Refresh (HWND hwnd, HDC hdc)
1031{
1032 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1033 HFONT hOldFont;
1034 INT i;
1035
1036 if (!infoPtr->DoRedraw)
1037 return;
1038
1039 hOldFont = SelectObject (hdc, infoPtr->hFont);
1040
1041 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_BUTTONS)
1042 {
1043 for (i = 0; i < infoPtr->uNumItem; i++)
1044 {
1045 TAB_DrawItem (hwnd, hdc, i);
1046 }
1047 }
1048 else
1049 {
1050 /*
1051 * Draw all the non selected item first.
1052 */
1053 for (i = 0; i < infoPtr->uNumItem; i++)
1054 {
1055 if (i != infoPtr->iSelected)
1056 TAB_DrawItem (hwnd, hdc, i);
1057 }
1058
1059 /*
1060 * Now, draw the border, draw it before the selected item
1061 * since the selected item overwrites part of the border.
1062 */
1063 TAB_DrawBorder (hwnd, hdc);
1064
1065 /*
1066 * Then, draw the selected item
1067 */
1068 TAB_DrawItem (hwnd, hdc, infoPtr->iSelected);
1069 }
1070
1071 SelectObject (hdc, hOldFont);
1072}
1073
1074static LRESULT
1075TAB_SetRedraw (HWND hwnd, WPARAM wParam)
1076{
1077 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1078
1079 infoPtr->DoRedraw=(BOOL) wParam;
1080 return 0;
1081}
1082
1083static LRESULT TAB_EraseBackground(
1084 HWND hwnd,
1085 HDC givenDC)
1086{
1087 HDC hdc;
1088 RECT clientRect;
1089
1090 HBRUSH brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
1091
1092 hdc = givenDC ? givenDC : GetDC(hwnd);
1093
1094 GetClientRect(hwnd, &clientRect);
1095
1096 FillRect(hdc, &clientRect, brush);
1097
1098 if (givenDC==0)
1099 ReleaseDC(hwnd, hdc);
1100
1101 return 0;
1102}
1103
1104/******************************************************************************
1105 * TAB_EnsureSelectionVisible
1106 *
1107 * This method will make sure that the current selection is completely
1108 * visible by scrolling until it is.
1109 */
1110static void TAB_EnsureSelectionVisible(
1111 HWND hwnd,
1112 TAB_INFO* infoPtr)
1113{
1114 RECT selectedRect;
1115 RECT visibleRect;
1116 RECT scrollerRect;
1117 BOOL isVisible;
1118
1119 /*
1120 * Do the trivial cases first.
1121 */
1122 if ( (!infoPtr->needsScrolling) ||
1123 (infoPtr->hwndUpDown==0) )
1124 return;
1125
1126 if (infoPtr->leftmostVisible > infoPtr->iSelected)
1127 {
1128 infoPtr->leftmostVisible = infoPtr->iSelected;
1129 return;
1130 }
1131
1132 /*
1133 * Calculate the part of the client area that is visible.
1134 */
1135 GetClientRect(hwnd, &visibleRect);
1136 GetClientRect(infoPtr->hwndUpDown, &scrollerRect);
1137 visibleRect.right -= scrollerRect.right;
1138
1139 /*
1140 * Get the rectangle for the item
1141 */
1142 isVisible = TAB_InternalGetItemRect(hwnd,
1143 infoPtr,
1144 infoPtr->iSelected,
1145 NULL,
1146 &selectedRect);
1147
1148 /*
1149 * If this function can't say it's completely invisible, maybe it
1150 * is partially visible. Let's check.
1151 */
1152 if (isVisible)
1153 {
1154 POINT pt1;
1155 POINT pt2;
1156
1157 pt1.x = selectedRect.left;
1158 pt1.y = selectedRect.top;
1159 pt2.x = selectedRect.right - 1;
1160 pt2.y = selectedRect.bottom - 1;
1161
1162 isVisible = PtInRect(&visibleRect, pt1) && PtInRect(&visibleRect, pt2);
1163 }
1164
1165 while ( (infoPtr->leftmostVisible < infoPtr->iSelected) &&
1166 !isVisible)
1167 {
1168 infoPtr->leftmostVisible++;
1169
1170 /*
1171 * Get the rectangle for the item
1172 */
1173 isVisible = TAB_InternalGetItemRect(hwnd,
1174 infoPtr,
1175 infoPtr->iSelected,
1176 NULL,
1177 &selectedRect);
1178
1179 /*
1180 * If this function can't say it's completely invisible, maybe it
1181 * is partially visible. Let's check.
1182 */
1183 if (isVisible)
1184 {
1185 POINT pt1;
1186 POINT pt2;
1187
1188 pt1.x = selectedRect.left;
1189 pt1.y = selectedRect.top;
1190 pt2.x = selectedRect.right - 1;
1191 pt2.y = selectedRect.bottom - 1;
1192
1193 isVisible = PtInRect(&visibleRect, pt1) && PtInRect(&visibleRect, pt2);
1194 }
1195 }
1196}
1197
1198/******************************************************************************
1199 * TAB_InvalidateTabArea
1200 *
1201 * This method will invalidate the portion of the control that contains the
1202 * tabs. It is called when the state of the control changes and needs
1203 * to be redisplayed
1204 */
1205static void TAB_InvalidateTabArea(
1206 HWND hwnd,
1207 TAB_INFO* infoPtr)
1208{
1209 RECT clientRect;
1210
1211 GetClientRect(hwnd, &clientRect);
1212
1213 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_BOTTOM)
1214 {
1215 clientRect.top = clientRect.bottom - (infoPtr->tabHeight + 1);
1216 }
1217 else
1218 {
1219 clientRect.bottom = clientRect.top + (infoPtr->tabHeight + 1);
1220 }
1221
1222 InvalidateRect(hwnd, &clientRect, TRUE);
1223}
1224
1225static LRESULT
1226TAB_Paint (HWND hwnd, WPARAM wParam)
1227{
1228 HDC hdc;
1229 PAINTSTRUCT ps;
1230
1231 hdc = wParam== 0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1232 TAB_Refresh (hwnd, hdc);
1233
1234 if(!wParam)
1235 EndPaint (hwnd, &ps);
1236
1237 return 0;
1238}
1239
1240static LRESULT
1241TAB_InsertItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1242{
1243 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1244 TCITEMA *pti;
1245 INT iItem, len;
1246 RECT rect;
1247
1248 GetClientRect (hwnd, &rect);
1249// TRACE(tab, "Rect: %x T %i, L %i, B %i, R %i\n", hwnd,
1250// rect.top, rect.left, rect.bottom, rect.right);
1251
1252 pti = (TCITEMA *)lParam;
1253 iItem = (INT)wParam;
1254
1255 if (iItem < 0) return -1;
1256 if (iItem > infoPtr->uNumItem)
1257 iItem = infoPtr->uNumItem;
1258
1259 if (infoPtr->uNumItem == 0) {
1260 infoPtr->items = COMCTL32_Alloc (sizeof (TAB_ITEM));
1261 infoPtr->uNumItem++;
1262 }
1263 else {
1264 TAB_ITEM *oldItems = infoPtr->items;
1265
1266 infoPtr->uNumItem++;
1267 infoPtr->items = COMCTL32_Alloc (sizeof (TAB_ITEM) * infoPtr->uNumItem);
1268
1269 /* pre insert copy */
1270 if (iItem > 0) {
1271 memcpy (&infoPtr->items[0], &oldItems[0],
1272 iItem * sizeof(TAB_ITEM));
1273 }
1274
1275 /* post insert copy */
1276 if (iItem < infoPtr->uNumItem - 1) {
1277 memcpy (&infoPtr->items[iItem+1], &oldItems[iItem],
1278 (infoPtr->uNumItem - iItem - 1) * sizeof(TAB_ITEM));
1279
1280 }
1281
1282 COMCTL32_Free (oldItems);
1283 }
1284
1285 infoPtr->items[iItem].mask = pti->mask;
1286 if (pti->mask & TCIF_TEXT) {
1287 len = lstrlenA (pti->pszText);
1288 infoPtr->items[iItem].pszText = COMCTL32_Alloc (len+1);
1289 lstrcpyA (infoPtr->items[iItem].pszText, pti->pszText);
1290 infoPtr->items[iItem].cchTextMax = pti->cchTextMax;
1291 }
1292
1293 if (pti->mask & TCIF_IMAGE)
1294 infoPtr->items[iItem].iImage = pti->iImage;
1295
1296 if (pti->mask & TCIF_PARAM)
1297 infoPtr->items[iItem].lParam = pti->lParam;
1298
1299 TAB_InvalidateTabArea(hwnd, infoPtr);
1300
1301// TRACE(tab, "[%04x]: added item %d '%s'\n",
1302// hwnd, iItem, infoPtr->items[iItem].pszText);
1303
1304 TAB_SetItemBounds(hwnd);
1305 return iItem;
1306}
1307
1308static LRESULT
1309TAB_SetItemSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1310{
1311 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1312 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
1313 LONG lResult = 0;
1314
1315 if ((lStyle & TCS_FIXEDWIDTH) || (lStyle & TCS_OWNERDRAWFIXED))
1316 {
1317 lResult = MAKELONG(infoPtr->tabWidth, infoPtr->tabHeight);
1318 infoPtr->tabWidth = (INT)LOWORD(lParam);
1319 infoPtr->tabHeight = (INT)HIWORD(lParam);
1320 }
1321
1322 return lResult;
1323}
1324
1325static LRESULT
1326TAB_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1327{
1328 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1329 TCITEMA *tabItem;
1330 TAB_ITEM *wineItem;
1331 INT iItem,len;
1332
1333 iItem=(INT) wParam;
1334 tabItem=(LPTCITEMA ) lParam;
1335// TRACE (tab,"%d %p\n",iItem, tabItem);
1336 if ((iItem<0) || (iItem>infoPtr->uNumItem)) return FALSE;
1337
1338 wineItem=& infoPtr->items[iItem];
1339
1340 if (tabItem->mask & TCIF_IMAGE)
1341 wineItem->iImage=tabItem->iImage;
1342
1343 if (tabItem->mask & TCIF_PARAM)
1344 wineItem->lParam=tabItem->lParam;
1345
1346// if (tabItem->mask & TCIF_RTLREADING)
1347// FIXME (tab,"TCIF_RTLREADING\n");
1348
1349 if (tabItem->mask & TCIF_STATE)
1350 wineItem->dwState=tabItem->dwState;
1351
1352 if (tabItem->mask & TCIF_TEXT) {
1353 len = lstrlenA (tabItem->pszText);
1354 if (len>wineItem->cchTextMax)
1355 wineItem->pszText = COMCTL32_ReAlloc (wineItem->pszText, len+1);
1356 lstrcpynA (wineItem->pszText, tabItem->pszText, len);
1357 }
1358
1359 return TRUE;
1360}
1361
1362static LRESULT
1363TAB_GetItemCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1364{
1365 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1366
1367 return infoPtr->uNumItem;
1368}
1369
1370
1371static LRESULT
1372TAB_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1373{
1374 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1375 TCITEMA *tabItem;
1376 TAB_ITEM *wineItem;
1377 INT iItem;
1378
1379 iItem=(INT) wParam;
1380 tabItem=(LPTCITEMA) lParam;
1381// TRACE (tab,"\n");
1382 if ((iItem<0) || (iItem>infoPtr->uNumItem)) return FALSE;
1383
1384 wineItem=& infoPtr->items[iItem];
1385
1386 if (tabItem->mask & TCIF_IMAGE)
1387 tabItem->iImage=wineItem->iImage;
1388
1389 if (tabItem->mask & TCIF_PARAM)
1390 tabItem->lParam=wineItem->lParam;
1391
1392// if (tabItem->mask & TCIF_RTLREADING)
1393// FIXME (tab, "TCIF_RTLREADING\n");
1394
1395 if (tabItem->mask & TCIF_STATE)
1396 tabItem->dwState=wineItem->dwState;
1397
1398 if (tabItem->mask & TCIF_TEXT)
1399 lstrcpynA (tabItem->pszText, wineItem->pszText, tabItem->cchTextMax);
1400
1401 return TRUE;
1402}
1403
1404static LRESULT
1405TAB_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1406{
1407 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1408 INT iItem = (INT) wParam;
1409 BOOL bResult = FALSE;
1410
1411 if ((iItem >= 0) && (iItem < infoPtr->uNumItem))
1412 {
1413 TAB_ITEM *oldItems = infoPtr->items;
1414
1415 infoPtr->uNumItem--;
1416 infoPtr->items = COMCTL32_Alloc(sizeof (TAB_ITEM) * infoPtr->uNumItem);
1417
1418 if (iItem > 0)
1419 memcpy(&infoPtr->items[0], &oldItems[0], iItem * sizeof(TAB_ITEM));
1420
1421 if (iItem < infoPtr->uNumItem)
1422 memcpy(&infoPtr->items[iItem], &oldItems[iItem + 1],
1423 (infoPtr->uNumItem - iItem) * sizeof(TAB_ITEM));
1424
1425 COMCTL32_Free (oldItems);
1426
1427 /*
1428 * Readjust the selected index.
1429 */
1430 if ((iItem == infoPtr->iSelected) && (iItem > 0))
1431 infoPtr->iSelected--;
1432
1433 if (iItem < infoPtr->iSelected)
1434 infoPtr->iSelected--;
1435
1436 /*
1437 * Reposition and repaint tabs.
1438 */
1439 TAB_SetItemBounds(hwnd);
1440 TAB_InvalidateTabArea(hwnd,infoPtr);
1441
1442 bResult = TRUE;
1443 }
1444
1445 return bResult;
1446}
1447
1448static LRESULT
1449TAB_DeleteAllItems (HWND hwnd, WPARAM wParam, LPARAM lParam)
1450{
1451 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1452
1453 COMCTL32_Free (infoPtr->items);
1454 infoPtr->uNumItem=0;
1455
1456 return TRUE;
1457}
1458
1459
1460static LRESULT
1461TAB_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1462{
1463 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1464
1465// TRACE (tab,"\n");
1466 return (LRESULT)infoPtr->hFont;
1467}
1468
1469static LRESULT
1470TAB_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1471
1472{
1473 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1474
1475// TRACE (tab,"%x %lx\n",wParam, lParam);
1476
1477 infoPtr->hFont = (HFONT)wParam;
1478
1479 TAB_SetItemBounds(hwnd);
1480
1481 TAB_InvalidateTabArea(hwnd, infoPtr);
1482
1483 return 0;
1484}
1485
1486
1487static LRESULT
1488TAB_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1489{
1490 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1491
1492// TRACE (tab,"\n");
1493 return (LRESULT)infoPtr->himl;
1494}
1495
1496static LRESULT
1497TAB_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1498{
1499 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1500 HIMAGELIST himlPrev;
1501
1502// TRACE (tab,"\n");
1503 himlPrev = infoPtr->himl;
1504 infoPtr->himl= (HIMAGELIST)lParam;
1505 return (LRESULT)himlPrev;
1506}
1507
1508
1509static LRESULT
1510TAB_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1511
1512{
1513/* I'm not really sure what the following code was meant to do.
1514 This is what it is doing:
1515 When WM_SIZE is sent with SIZE_RESTORED, the control
1516 gets positioned in the top left corner.
1517
1518 RECT parent_rect;
1519 HWND parent;
1520 UINT uPosFlags,cx,cy;
1521
1522 uPosFlags=0;
1523 if (!wParam) {
1524 parent = GetParent (hwnd);
1525 GetClientRect(parent, &parent_rect);
1526 cx=LOWORD (lParam);
1527 cy=HIWORD (lParam);
1528 if (GetWindowLongA(hwnd, GWL_STYLE) & CCS_NORESIZE)
1529 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
1530
1531 SetWindowPos (hwnd, 0, parent_rect.left, parent_rect.top,
1532 cx, cy, uPosFlags | SWP_NOZORDER);
1533 } else {
1534// FIXME (tab,"WM_SIZE flag %x %lx not handled\n", wParam, lParam);
1535 } */
1536
1537 /*
1538 * Recompute the size/position of the tabs.
1539 */
1540 TAB_SetItemBounds (hwnd);
1541
1542 /*
1543 * Force a repaint of the control.
1544 */
1545 InvalidateRect(hwnd, NULL, TRUE);
1546
1547 return 0;
1548}
1549
1550
1551static LRESULT
1552TAB_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1553{
1554 TAB_INFO *infoPtr;
1555 TEXTMETRICA fontMetrics;
1556 HDC hdc;
1557 HFONT hOldFont;
1558
1559 infoPtr = (TAB_INFO *)COMCTL32_Alloc (sizeof(TAB_INFO));
1560
1561 SetWindowLongA(hwnd, 0, (DWORD)infoPtr);
1562
1563 infoPtr->uNumItem = 0;
1564 infoPtr->hFont = 0;
1565 infoPtr->items = 0;
1566 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1567 infoPtr->iSelected = 0;
1568 infoPtr->uFocus = 0;
1569 infoPtr->hwndToolTip = 0;
1570 infoPtr->DoRedraw = TRUE;
1571 infoPtr->needsScrolling = FALSE;
1572 infoPtr->hwndUpDown = 0;
1573 infoPtr->leftmostVisible = 0;
1574
1575// TRACE(tab, "Created tab control, hwnd [%04x]\n", hwnd);
1576 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_TOOLTIPS) {
1577 /* Create tooltip control */
1578 infoPtr->hwndToolTip =
1579 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
1580 CW_USEDEFAULT, CW_USEDEFAULT,
1581 CW_USEDEFAULT, CW_USEDEFAULT,
1582 hwnd, 0, 0, 0);
1583
1584 /* Send NM_TOOLTIPSCREATED notification */
1585 if (infoPtr->hwndToolTip) {
1586 NMTOOLTIPSCREATED nmttc;
1587
1588 nmttc.hdr.hwndFrom = hwnd;
1589 nmttc.hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1590 nmttc.hdr.code = NM_TOOLTIPSCREATED;
1591 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1592
1593 SendMessageA (GetParent (hwnd), WM_NOTIFY,
1594 (WPARAM)GetWindowLongA(hwnd, GWL_ID), (LPARAM)&nmttc);
1595 }
1596 }
1597
1598 /*
1599 * We need to get text information so we need a DC and we need to select
1600 * a font.
1601 */
1602 hdc = GetDC(hwnd);
1603 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1604
1605 /*
1606 * Use the system font to determine the initial height of a tab.
1607 */
1608 GetTextMetricsA(hdc, &fontMetrics);
1609
1610 /*
1611 * Make sure there is enough space for the letters + growing the
1612 * selected item + extra space for the selected item.
1613 */
1614 infoPtr->tabHeight = fontMetrics.tmHeight + 2*VERTICAL_ITEM_PADDING +
1615 SELECTED_TAB_OFFSET;
1616
1617 /*
1618 * Initialize the width of a tab.
1619 */
1620 infoPtr->tabWidth = DEFAULT_TAB_WIDTH;
1621
1622 SelectObject (hdc, hOldFont);
1623 ReleaseDC(hwnd, hdc);
1624
1625 return 0;
1626}
1627
1628static LRESULT
1629TAB_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1630{
1631 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1632 INT iItem;
1633
1634 if (infoPtr->items) {
1635 for (iItem = 0; iItem < infoPtr->uNumItem; iItem++) {
1636 if (infoPtr->items[iItem].pszText)
1637 COMCTL32_Free (infoPtr->items[iItem].pszText);
1638 }
1639 COMCTL32_Free (infoPtr->items);
1640 }
1641
1642 if (infoPtr->hwndToolTip)
1643 DestroyWindow (infoPtr->hwndToolTip);
1644
1645 if (infoPtr->hwndUpDown)
1646 DestroyWindow(infoPtr->hwndUpDown);
1647
1648 COMCTL32_Free (infoPtr);
1649 return 0;
1650}
1651
1652LRESULT WINAPI
1653TAB_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1654{
1655 switch (uMsg)
1656 {
1657 case TCM_GETIMAGELIST:
1658 return TAB_GetImageList (hwnd, wParam, lParam);
1659
1660 case TCM_SETIMAGELIST:
1661 return TAB_SetImageList (hwnd, wParam, lParam);
1662
1663 case TCM_GETITEMCOUNT:
1664 return TAB_GetItemCount (hwnd, wParam, lParam);
1665
1666 case TCM_GETITEMA:
1667 return TAB_GetItemA (hwnd, wParam, lParam);
1668
1669 case TCM_GETITEMW:
1670// FIXME (tab, "Unimplemented msg TCM_GETITEMW\n");
1671 return 0;
1672
1673 case TCM_SETITEMA:
1674 return TAB_SetItemA (hwnd, wParam, lParam);
1675
1676 case TCM_SETITEMW:
1677// FIXME (tab, "Unimplemented msg TCM_SETITEMW\n");
1678 return 0;
1679
1680 case TCM_DELETEITEM:
1681 return TAB_DeleteItem (hwnd, wParam, lParam);
1682
1683 case TCM_DELETEALLITEMS:
1684 return TAB_DeleteAllItems (hwnd, wParam, lParam);
1685
1686 case TCM_GETITEMRECT:
1687 return TAB_GetItemRect (hwnd, wParam, lParam);
1688
1689 case TCM_GETCURSEL:
1690 return TAB_GetCurSel (hwnd);
1691
1692 case TCM_HITTEST:
1693 return TAB_HitTest (hwnd, wParam, lParam);
1694
1695 case TCM_SETCURSEL:
1696 return TAB_SetCurSel (hwnd, wParam);
1697
1698 case TCM_INSERTITEMA:
1699 return TAB_InsertItem (hwnd, wParam, lParam);
1700
1701 case TCM_INSERTITEMW:
1702// FIXME (tab, "Unimplemented msg TCM_INSERTITEM32W\n");
1703 return 0;
1704
1705 case TCM_SETITEMEXTRA:
1706// FIXME (tab, "Unimplemented msg TCM_SETITEMEXTRA\n");
1707 return 0;
1708
1709 case TCM_ADJUSTRECT:
1710 return TAB_AdjustRect (hwnd, (BOOL)wParam, (LPRECT)lParam);
1711
1712 case TCM_SETITEMSIZE:
1713 return TAB_SetItemSize (hwnd, wParam, lParam);
1714
1715 case TCM_REMOVEIMAGE:
1716// FIXME (tab, "Unimplemented msg TCM_REMOVEIMAGE\n");
1717 return 0;
1718
1719 case TCM_SETPADDING:
1720// FIXME (tab, "Unimplemented msg TCM_SETPADDING\n");
1721 return 0;
1722
1723 case TCM_GETROWCOUNT:
1724// FIXME (tab, "Unimplemented msg TCM_GETROWCOUNT\n");
1725 return 0;
1726
1727 case TCM_GETUNICODEFORMAT:
1728// FIXME (tab, "Unimplemented msg TCM_GETUNICODEFORMAT\n");
1729 return 0;
1730
1731 case TCM_SETUNICODEFORMAT:
1732// FIXME (tab, "Unimplemented msg TCM_SETUNICODEFORMAT\n");
1733 return 0;
1734
1735 case TCM_HIGHLIGHTITEM:
1736// FIXME (tab, "Unimplemented msg TCM_HIGHLIGHTITEM\n");
1737 return 0;
1738
1739 case TCM_GETTOOLTIPS:
1740 return TAB_GetToolTips (hwnd, wParam, lParam);
1741
1742 case TCM_SETTOOLTIPS:
1743 return TAB_SetToolTips (hwnd, wParam, lParam);
1744
1745 case TCM_GETCURFOCUS:
1746 return TAB_GetCurFocus (hwnd);
1747
1748 case TCM_SETCURFOCUS:
1749 return TAB_SetCurFocus (hwnd, wParam);
1750
1751 case TCM_SETMINTTABWIDTH:
1752// FIXME (tab, "Unimplemented msg TCM_SETMINTTABWIDTH\n");
1753 return 0;
1754
1755 case TCM_DESELECTALL:
1756// FIXME (tab, "Unimplemented msg TCM_DESELECTALL\n");
1757 return 0;
1758
1759 case TCM_GETEXTENDEDSTYLE:
1760// FIXME (tab, "Unimplemented msg TCM_GETEXTENDEDSTYLE\n");
1761 return 0;
1762
1763 case TCM_SETEXTENDEDSTYLE:
1764// FIXME (tab, "Unimplemented msg TCM_SETEXTENDEDSTYLE\n");
1765 return 0;
1766
1767 case WM_GETFONT:
1768 return TAB_GetFont (hwnd, wParam, lParam);
1769
1770 case WM_SETFONT:
1771 return TAB_SetFont (hwnd, wParam, lParam);
1772
1773 case WM_CREATE:
1774 return TAB_Create (hwnd, wParam, lParam);
1775
1776 case WM_NCDESTROY:
1777 return TAB_Destroy (hwnd, wParam, lParam);
1778
1779 case WM_GETDLGCODE:
1780 return DLGC_WANTARROWS | DLGC_WANTCHARS;
1781
1782 case WM_LBUTTONDOWN:
1783 return TAB_LButtonDown (hwnd, wParam, lParam);
1784
1785 case WM_LBUTTONUP:
1786 return TAB_LButtonUp (hwnd, wParam, lParam);
1787
1788 case WM_RBUTTONDOWN:
1789 return TAB_RButtonDown (hwnd, wParam, lParam);
1790
1791 case WM_MOUSEMOVE:
1792 return TAB_MouseMove (hwnd, wParam, lParam);
1793
1794 case WM_ERASEBKGND:
1795 return TAB_EraseBackground (hwnd, (HDC)wParam);
1796
1797 case WM_PAINT:
1798 return TAB_Paint (hwnd, wParam);
1799
1800 case WM_SIZE:
1801 return TAB_Size (hwnd, wParam, lParam);
1802
1803 case WM_SETREDRAW:
1804 return TAB_SetRedraw (hwnd, wParam);
1805
1806 case WM_HSCROLL:
1807 return TAB_OnHScroll(hwnd, (int)LOWORD(wParam), (int)HIWORD(wParam), (HWND)lParam);
1808
1809 case WM_KILLFOCUS:
1810 case WM_SETFOCUS:
1811 return TAB_FocusChanging(hwnd, uMsg, wParam, lParam);
1812
1813 case WM_KEYUP:
1814 return TAB_KeyUp(hwnd, wParam);
1815
1816 default:
1817// if (uMsg >= WM_USER)
1818// ERR (tab, "unknown msg %04x wp=%08x lp=%08lx\n",
1819// uMsg, wParam, lParam);
1820 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1821 }
1822
1823 return 0;
1824}
1825
1826
1827VOID
1828TAB_Register (VOID)
1829{
1830 WNDCLASSA wndClass;
1831
1832 if (GlobalFindAtomA (WC_TABCONTROLA)) return;
1833
1834 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1835 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
1836 wndClass.lpfnWndProc = (WNDPROC)TAB_WindowProc;
1837 wndClass.cbClsExtra = 0;
1838 wndClass.cbWndExtra = sizeof(TAB_INFO *);
1839 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1840 wndClass.hbrBackground = (HBRUSH)NULL;
1841 wndClass.lpszClassName = WC_TABCONTROLA;
1842
1843 RegisterClassA (&wndClass);
1844}
1845
1846
1847VOID
1848TAB_Unregister (VOID)
1849{
1850 if (GlobalFindAtomA (WC_TABCONTROLA))
1851 UnregisterClassA (WC_TABCONTROLA, (HINSTANCE)NULL);
1852}
1853
Note: See TracBrowser for help on using the repository browser.