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

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

Unicode and other extensions

File size: 47.9 KB
Line 
1/* $Id: tab.c,v 1.8 1999-07-04 21:05:59 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 */
15
16#include <string.h>
17
18#include "winbase.h"
19#include "commctrl.h"
20#include "tab.h"
21#include "comctl32.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 GetTextExtentPoint32W(hdc, infoPtr->items[curItem].pszText,
712 lstrlenW(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 DrawTextW(hdc,
937 infoPtr->items[iItem].pszText,
938 lstrlenW(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 TAB_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1241{
1242 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1243 TCITEMA *pti;
1244 INT iItem, len;
1245 RECT rect;
1246
1247 GetClientRect (hwnd, &rect);
1248// TRACE(tab, "Rect: %x T %i, L %i, B %i, R %i\n", hwnd,
1249// rect.top, rect.left, rect.bottom, rect.right);
1250
1251 pti = (TCITEMA *)lParam;
1252 iItem = (INT)wParam;
1253
1254 if (iItem < 0) return -1;
1255 if (iItem > infoPtr->uNumItem)
1256 iItem = infoPtr->uNumItem;
1257
1258 if (infoPtr->uNumItem == 0) {
1259 infoPtr->items = COMCTL32_Alloc (sizeof (TAB_ITEM));
1260 infoPtr->uNumItem++;
1261 }
1262 else {
1263 TAB_ITEM *oldItems = infoPtr->items;
1264
1265 infoPtr->uNumItem++;
1266 infoPtr->items = COMCTL32_Alloc (sizeof (TAB_ITEM) * infoPtr->uNumItem);
1267
1268 /* pre insert copy */
1269 if (iItem > 0) {
1270 memcpy (&infoPtr->items[0], &oldItems[0],
1271 iItem * sizeof(TAB_ITEM));
1272 }
1273
1274 /* post insert copy */
1275 if (iItem < infoPtr->uNumItem - 1) {
1276 memcpy (&infoPtr->items[iItem+1], &oldItems[iItem],
1277 (infoPtr->uNumItem - iItem - 1) * sizeof(TAB_ITEM));
1278
1279 }
1280
1281 COMCTL32_Free (oldItems);
1282 }
1283
1284 infoPtr->items[iItem].mask = pti->mask;
1285 if (pti->mask & TCIF_TEXT) {
1286 len = lstrlenA (pti->pszText);
1287 infoPtr->items[iItem].pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1288 lstrcpyAtoW (infoPtr->items[iItem].pszText, pti->pszText);
1289 infoPtr->items[iItem].cchTextMax = pti->cchTextMax;
1290 }
1291
1292 if (pti->mask & TCIF_IMAGE)
1293 infoPtr->items[iItem].iImage = pti->iImage;
1294
1295 if (pti->mask & TCIF_PARAM)
1296 infoPtr->items[iItem].lParam = pti->lParam;
1297
1298 TAB_InvalidateTabArea(hwnd, infoPtr);
1299
1300// TRACE(tab, "[%04x]: added item %d '%s'\n",
1301// hwnd, iItem, infoPtr->items[iItem].pszText);
1302
1303 TAB_SetItemBounds(hwnd);
1304 return iItem;
1305}
1306
1307static LRESULT TAB_InsertItemW(HWND hwnd, WPARAM wParam, LPARAM lParam)
1308{
1309 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1310 TCITEMW *pti;
1311 INT iItem, len;
1312 RECT rect;
1313
1314 GetClientRect (hwnd, &rect);
1315// TRACE(tab, "Rect: %x T %i, L %i, B %i, R %i\n", hwnd,
1316// rect.top, rect.left, rect.bottom, rect.right);
1317
1318 pti = (TCITEMW*)lParam;
1319 iItem = (INT)wParam;
1320
1321 if (iItem < 0) return -1;
1322 if (iItem > infoPtr->uNumItem)
1323 iItem = infoPtr->uNumItem;
1324
1325 if (infoPtr->uNumItem == 0) {
1326 infoPtr->items = COMCTL32_Alloc (sizeof (TAB_ITEM));
1327 infoPtr->uNumItem++;
1328 }
1329 else {
1330 TAB_ITEM *oldItems = infoPtr->items;
1331
1332 infoPtr->uNumItem++;
1333 infoPtr->items = COMCTL32_Alloc (sizeof (TAB_ITEM) * infoPtr->uNumItem);
1334
1335 /* pre insert copy */
1336 if (iItem > 0) {
1337 memcpy (&infoPtr->items[0], &oldItems[0],
1338 iItem * sizeof(TAB_ITEM));
1339 }
1340
1341 /* post insert copy */
1342 if (iItem < infoPtr->uNumItem - 1) {
1343 memcpy (&infoPtr->items[iItem+1], &oldItems[iItem],
1344 (infoPtr->uNumItem - iItem - 1) * sizeof(TAB_ITEM));
1345
1346 }
1347
1348 COMCTL32_Free (oldItems);
1349 }
1350
1351 infoPtr->items[iItem].mask = pti->mask;
1352 if (pti->mask & TCIF_TEXT) {
1353 len = lstrlenW (pti->pszText);
1354 infoPtr->items[iItem].pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1355 lstrcpyW (infoPtr->items[iItem].pszText, pti->pszText);
1356 infoPtr->items[iItem].cchTextMax = pti->cchTextMax;
1357 }
1358
1359 if (pti->mask & TCIF_IMAGE)
1360 infoPtr->items[iItem].iImage = pti->iImage;
1361
1362 if (pti->mask & TCIF_PARAM)
1363 infoPtr->items[iItem].lParam = pti->lParam;
1364
1365 TAB_InvalidateTabArea(hwnd, infoPtr);
1366
1367// TRACE(tab, "[%04x]: added item %d '%s'\n",
1368// hwnd, iItem, infoPtr->items[iItem].pszText);
1369
1370 TAB_SetItemBounds(hwnd);
1371 return iItem;
1372}
1373
1374static LRESULT
1375TAB_SetItemSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1376{
1377 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1378 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
1379 LONG lResult = 0;
1380
1381 if ((lStyle & TCS_FIXEDWIDTH) || (lStyle & TCS_OWNERDRAWFIXED))
1382 {
1383 lResult = MAKELONG(infoPtr->tabWidth, infoPtr->tabHeight);
1384 infoPtr->tabWidth = (INT)LOWORD(lParam);
1385 infoPtr->tabHeight = (INT)HIWORD(lParam);
1386 }
1387
1388 return lResult;
1389}
1390
1391static LRESULT
1392TAB_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1393{
1394 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1395 TCITEMA *tabItem;
1396 TAB_ITEM *wineItem;
1397 INT iItem,len;
1398
1399 iItem=(INT) wParam;
1400 tabItem=(LPTCITEMA ) lParam;
1401// TRACE (tab,"%d %p\n",iItem, tabItem);
1402 if ((iItem<0) || (iItem>infoPtr->uNumItem)) return FALSE;
1403
1404 wineItem=& infoPtr->items[iItem];
1405
1406 if (tabItem->mask & TCIF_IMAGE)
1407 wineItem->iImage=tabItem->iImage;
1408
1409 if (tabItem->mask & TCIF_PARAM)
1410 wineItem->lParam=tabItem->lParam;
1411
1412// if (tabItem->mask & TCIF_RTLREADING)
1413// FIXME (tab,"TCIF_RTLREADING\n");
1414
1415 if (tabItem->mask & TCIF_STATE)
1416 wineItem->dwState=tabItem->dwState;
1417
1418 if (tabItem->mask & TCIF_TEXT) {
1419 len = lstrlenA (tabItem->pszText);
1420 if (len>wineItem->cchTextMax)
1421 wineItem->pszText = COMCTL32_ReAlloc (wineItem->pszText, (len+1)*sizeof(WCHAR));
1422 lstrcpynAtoW (wineItem->pszText, tabItem->pszText, len+1);
1423 }
1424
1425 return TRUE;
1426}
1427
1428static LRESULT TAB_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1429{
1430 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1431 TCITEMW *tabItem;
1432 TAB_ITEM *wineItem;
1433 INT iItem,len;
1434
1435 iItem=(INT) wParam;
1436 tabItem=(LPTCITEMW) lParam;
1437// TRACE (tab,"%d %p\n",iItem, tabItem);
1438 if ((iItem<0) || (iItem>infoPtr->uNumItem)) return FALSE;
1439
1440 wineItem=& infoPtr->items[iItem];
1441
1442 if (tabItem->mask & TCIF_IMAGE)
1443 wineItem->iImage=tabItem->iImage;
1444
1445 if (tabItem->mask & TCIF_PARAM)
1446 wineItem->lParam=tabItem->lParam;
1447
1448// if (tabItem->mask & TCIF_RTLREADING)
1449// FIXME (tab,"TCIF_RTLREADING\n");
1450
1451 if (tabItem->mask & TCIF_STATE)
1452 wineItem->dwState=tabItem->dwState;
1453
1454 if (tabItem->mask & TCIF_TEXT) {
1455 len = lstrlenW (tabItem->pszText);
1456 if (len>wineItem->cchTextMax)
1457 wineItem->pszText = COMCTL32_ReAlloc (wineItem->pszText, (len+1)*sizeof(WCHAR));
1458 lstrcpynW (wineItem->pszText, tabItem->pszText, len+1);
1459 }
1460
1461 return TRUE;
1462}
1463
1464static LRESULT
1465TAB_GetItemCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1466{
1467 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1468
1469 return infoPtr->uNumItem;
1470}
1471
1472
1473static LRESULT
1474TAB_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1475{
1476 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1477 TCITEMA *tabItem;
1478 TAB_ITEM *wineItem;
1479 INT iItem;
1480
1481 iItem=(INT) wParam;
1482 tabItem=(LPTCITEMA) lParam;
1483// TRACE (tab,"\n");
1484 if ((iItem<0) || (iItem>infoPtr->uNumItem)) return FALSE;
1485
1486 wineItem=& infoPtr->items[iItem];
1487
1488 if (tabItem->mask & TCIF_IMAGE)
1489 tabItem->iImage=wineItem->iImage;
1490
1491 if (tabItem->mask & TCIF_PARAM)
1492 tabItem->lParam=wineItem->lParam;
1493
1494// if (tabItem->mask & TCIF_RTLREADING)
1495// FIXME (tab, "TCIF_RTLREADING\n");
1496
1497 if (tabItem->mask & TCIF_STATE)
1498 tabItem->dwState=wineItem->dwState;
1499
1500 if (tabItem->mask & TCIF_TEXT)
1501 lstrcpynWtoA (tabItem->pszText, wineItem->pszText, tabItem->cchTextMax);
1502
1503 return TRUE;
1504}
1505
1506static LRESULT TAB_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1507{
1508 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1509 TCITEMW *tabItem;
1510 TAB_ITEM *wineItem;
1511 INT iItem;
1512
1513 iItem=(INT) wParam;
1514 tabItem=(LPTCITEMW) lParam;
1515// TRACE (tab,"\n");
1516 if ((iItem<0) || (iItem>infoPtr->uNumItem)) return FALSE;
1517
1518 wineItem=& infoPtr->items[iItem];
1519
1520 if (tabItem->mask & TCIF_IMAGE)
1521 tabItem->iImage=wineItem->iImage;
1522
1523 if (tabItem->mask & TCIF_PARAM)
1524 tabItem->lParam=wineItem->lParam;
1525
1526// if (tabItem->mask & TCIF_RTLREADING)
1527// FIXME (tab, "TCIF_RTLREADING\n");
1528
1529 if (tabItem->mask & TCIF_STATE)
1530 tabItem->dwState=wineItem->dwState;
1531
1532 if (tabItem->mask & TCIF_TEXT)
1533 lstrcpynW (tabItem->pszText, wineItem->pszText, tabItem->cchTextMax);
1534
1535 return TRUE;
1536}
1537
1538static LRESULT
1539TAB_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1540{
1541 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1542 INT iItem = (INT) wParam;
1543 BOOL bResult = FALSE;
1544
1545 if ((iItem >= 0) && (iItem < infoPtr->uNumItem))
1546 {
1547 TAB_ITEM *oldItems = infoPtr->items;
1548
1549 infoPtr->uNumItem--;
1550 infoPtr->items = COMCTL32_Alloc(sizeof (TAB_ITEM) * infoPtr->uNumItem);
1551
1552 if (iItem > 0)
1553 memcpy(&infoPtr->items[0], &oldItems[0], iItem * sizeof(TAB_ITEM));
1554
1555 if (iItem < infoPtr->uNumItem)
1556 memcpy(&infoPtr->items[iItem], &oldItems[iItem + 1],
1557 (infoPtr->uNumItem - iItem) * sizeof(TAB_ITEM));
1558
1559 COMCTL32_Free (oldItems);
1560
1561 /*
1562 * Readjust the selected index.
1563 */
1564 if ((iItem == infoPtr->iSelected) && (iItem > 0))
1565 infoPtr->iSelected--;
1566
1567 if (iItem < infoPtr->iSelected)
1568 infoPtr->iSelected--;
1569
1570 /*
1571 * Reposition and repaint tabs.
1572 */
1573 TAB_SetItemBounds(hwnd);
1574 TAB_InvalidateTabArea(hwnd,infoPtr);
1575
1576 bResult = TRUE;
1577 }
1578
1579 return bResult;
1580}
1581
1582static LRESULT
1583TAB_DeleteAllItems (HWND hwnd, WPARAM wParam, LPARAM lParam)
1584{
1585 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1586
1587 COMCTL32_Free (infoPtr->items);
1588 infoPtr->uNumItem=0;
1589
1590 return TRUE;
1591}
1592
1593
1594static LRESULT
1595TAB_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1596{
1597 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1598
1599// TRACE (tab,"\n");
1600 return (LRESULT)infoPtr->hFont;
1601}
1602
1603static LRESULT
1604TAB_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1605
1606{
1607 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1608
1609// TRACE (tab,"%x %lx\n",wParam, lParam);
1610
1611 infoPtr->hFont = (HFONT)wParam;
1612
1613 TAB_SetItemBounds(hwnd);
1614
1615 TAB_InvalidateTabArea(hwnd, infoPtr);
1616
1617 return 0;
1618}
1619
1620
1621static LRESULT
1622TAB_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1623{
1624 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1625
1626// TRACE (tab,"\n");
1627 return (LRESULT)infoPtr->himl;
1628}
1629
1630static LRESULT
1631TAB_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1632{
1633 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1634 HIMAGELIST himlPrev;
1635
1636// TRACE (tab,"\n");
1637 himlPrev = infoPtr->himl;
1638 infoPtr->himl= (HIMAGELIST)lParam;
1639 return (LRESULT)himlPrev;
1640}
1641
1642
1643static LRESULT
1644TAB_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1645
1646{
1647/* I'm not really sure what the following code was meant to do.
1648 This is what it is doing:
1649 When WM_SIZE is sent with SIZE_RESTORED, the control
1650 gets positioned in the top left corner.
1651
1652 RECT parent_rect;
1653 HWND parent;
1654 UINT uPosFlags,cx,cy;
1655
1656 uPosFlags=0;
1657 if (!wParam) {
1658 parent = GetParent (hwnd);
1659 GetClientRect(parent, &parent_rect);
1660 cx=LOWORD (lParam);
1661 cy=HIWORD (lParam);
1662 if (GetWindowLongA(hwnd, GWL_STYLE) & CCS_NORESIZE)
1663 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
1664
1665 SetWindowPos (hwnd, 0, parent_rect.left, parent_rect.top,
1666 cx, cy, uPosFlags | SWP_NOZORDER);
1667 } else {
1668// FIXME (tab,"WM_SIZE flag %x %lx not handled\n", wParam, lParam);
1669 } */
1670
1671 /*
1672 * Recompute the size/position of the tabs.
1673 */
1674 TAB_SetItemBounds (hwnd);
1675
1676 /*
1677 * Force a repaint of the control.
1678 */
1679 InvalidateRect(hwnd, NULL, TRUE);
1680
1681 return 0;
1682}
1683
1684
1685static LRESULT
1686TAB_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1687{
1688 TAB_INFO *infoPtr;
1689 TEXTMETRICA fontMetrics;
1690 HDC hdc;
1691 HFONT hOldFont;
1692
1693 infoPtr = (TAB_INFO *)COMCTL32_Alloc (sizeof(TAB_INFO));
1694
1695 SetWindowLongA(hwnd, 0, (DWORD)infoPtr);
1696
1697 infoPtr->uNumItem = 0;
1698 infoPtr->hFont = 0;
1699 infoPtr->items = 0;
1700 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1701 infoPtr->iSelected = 0;
1702 infoPtr->uFocus = 0;
1703 infoPtr->hwndToolTip = 0;
1704 infoPtr->DoRedraw = TRUE;
1705 infoPtr->needsScrolling = FALSE;
1706 infoPtr->hwndUpDown = 0;
1707 infoPtr->leftmostVisible = 0;
1708
1709// TRACE(tab, "Created tab control, hwnd [%04x]\n", hwnd);
1710 if (GetWindowLongA(hwnd, GWL_STYLE) & TCS_TOOLTIPS) {
1711 /* Create tooltip control */
1712 infoPtr->hwndToolTip =
1713 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
1714 CW_USEDEFAULT, CW_USEDEFAULT,
1715 CW_USEDEFAULT, CW_USEDEFAULT,
1716 hwnd, 0, 0, 0);
1717
1718 /* Send NM_TOOLTIPSCREATED notification */
1719 if (infoPtr->hwndToolTip) {
1720 NMTOOLTIPSCREATED nmttc;
1721
1722 nmttc.hdr.hwndFrom = hwnd;
1723 nmttc.hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1724 nmttc.hdr.code = NM_TOOLTIPSCREATED;
1725 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1726
1727 SendMessageA (GetParent (hwnd), WM_NOTIFY,
1728 (WPARAM)GetWindowLongA(hwnd, GWL_ID), (LPARAM)&nmttc);
1729 }
1730 }
1731
1732 /*
1733 * We need to get text information so we need a DC and we need to select
1734 * a font.
1735 */
1736 hdc = GetDC(hwnd);
1737 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1738
1739 /*
1740 * Use the system font to determine the initial height of a tab.
1741 */
1742 GetTextMetricsA(hdc, &fontMetrics);
1743
1744 /*
1745 * Make sure there is enough space for the letters + growing the
1746 * selected item + extra space for the selected item.
1747 */
1748 infoPtr->tabHeight = fontMetrics.tmHeight + 2*VERTICAL_ITEM_PADDING +
1749 SELECTED_TAB_OFFSET;
1750
1751 /*
1752 * Initialize the width of a tab.
1753 */
1754 infoPtr->tabWidth = DEFAULT_TAB_WIDTH;
1755
1756 SelectObject (hdc, hOldFont);
1757 ReleaseDC(hwnd, hdc);
1758
1759 return 0;
1760}
1761
1762static LRESULT
1763TAB_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1764{
1765 TAB_INFO *infoPtr = TAB_GetInfoPtr(hwnd);
1766 INT iItem;
1767
1768 if (infoPtr->items) {
1769 for (iItem = 0; iItem < infoPtr->uNumItem; iItem++) {
1770 if (infoPtr->items[iItem].pszText)
1771 COMCTL32_Free (infoPtr->items[iItem].pszText);
1772 }
1773 COMCTL32_Free (infoPtr->items);
1774 }
1775
1776 if (infoPtr->hwndToolTip)
1777 DestroyWindow (infoPtr->hwndToolTip);
1778
1779 if (infoPtr->hwndUpDown)
1780 DestroyWindow(infoPtr->hwndUpDown);
1781
1782 COMCTL32_Free (infoPtr);
1783 return 0;
1784}
1785
1786LRESULT WINAPI
1787TAB_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1788{
1789 switch (uMsg)
1790 {
1791 case TCM_GETIMAGELIST:
1792 return TAB_GetImageList (hwnd, wParam, lParam);
1793
1794 case TCM_SETIMAGELIST:
1795 return TAB_SetImageList (hwnd, wParam, lParam);
1796
1797 case TCM_GETITEMCOUNT:
1798 return TAB_GetItemCount (hwnd, wParam, lParam);
1799
1800 case TCM_GETITEMA:
1801 return TAB_GetItemA (hwnd, wParam, lParam);
1802
1803 case TCM_GETITEMW:
1804 return TAB_GetItemW(hwnd,wParam,lParam);
1805
1806 case TCM_SETITEMA:
1807 return TAB_SetItemA (hwnd, wParam, lParam);
1808
1809 case TCM_SETITEMW:
1810 return TAB_SetItemW(hwnd,wParam,lParam);
1811
1812 case TCM_DELETEITEM:
1813 return TAB_DeleteItem (hwnd, wParam, lParam);
1814
1815 case TCM_DELETEALLITEMS:
1816 return TAB_DeleteAllItems (hwnd, wParam, lParam);
1817
1818 case TCM_GETITEMRECT:
1819 return TAB_GetItemRect (hwnd, wParam, lParam);
1820
1821 case TCM_GETCURSEL:
1822 return TAB_GetCurSel (hwnd);
1823
1824 case TCM_HITTEST:
1825 return TAB_HitTest (hwnd, wParam, lParam);
1826
1827 case TCM_SETCURSEL:
1828 return TAB_SetCurSel (hwnd, wParam);
1829
1830 case TCM_INSERTITEMA:
1831 return TAB_InsertItemA(hwnd,wParam,lParam);
1832
1833 case TCM_INSERTITEMW:
1834 return TAB_InsertItemW(hwnd,wParam,lParam);
1835
1836 case TCM_SETITEMEXTRA:
1837// FIXME (tab, "Unimplemented msg TCM_SETITEMEXTRA\n");
1838 return 0;
1839
1840 case TCM_ADJUSTRECT:
1841 return TAB_AdjustRect (hwnd, (BOOL)wParam, (LPRECT)lParam);
1842
1843 case TCM_SETITEMSIZE:
1844 return TAB_SetItemSize (hwnd, wParam, lParam);
1845
1846 case TCM_REMOVEIMAGE:
1847// FIXME (tab, "Unimplemented msg TCM_REMOVEIMAGE\n");
1848 return 0;
1849
1850 case TCM_SETPADDING:
1851// FIXME (tab, "Unimplemented msg TCM_SETPADDING\n");
1852 return 0;
1853
1854 case TCM_GETROWCOUNT:
1855// FIXME (tab, "Unimplemented msg TCM_GETROWCOUNT\n");
1856 return 0;
1857
1858 case TCM_GETUNICODEFORMAT:
1859// FIXME (tab, "Unimplemented msg TCM_GETUNICODEFORMAT\n");
1860 return 0;
1861
1862 case TCM_SETUNICODEFORMAT:
1863// FIXME (tab, "Unimplemented msg TCM_SETUNICODEFORMAT\n");
1864 return 0;
1865
1866 case TCM_HIGHLIGHTITEM:
1867// FIXME (tab, "Unimplemented msg TCM_HIGHLIGHTITEM\n");
1868 return 0;
1869
1870 case TCM_GETTOOLTIPS:
1871 return TAB_GetToolTips (hwnd, wParam, lParam);
1872
1873 case TCM_SETTOOLTIPS:
1874 return TAB_SetToolTips (hwnd, wParam, lParam);
1875
1876 case TCM_GETCURFOCUS:
1877 return TAB_GetCurFocus (hwnd);
1878
1879 case TCM_SETCURFOCUS:
1880 return TAB_SetCurFocus (hwnd, wParam);
1881
1882 case TCM_SETMINTTABWIDTH:
1883// FIXME (tab, "Unimplemented msg TCM_SETMINTTABWIDTH\n");
1884 return 0;
1885
1886 case TCM_DESELECTALL:
1887// FIXME (tab, "Unimplemented msg TCM_DESELECTALL\n");
1888 return 0;
1889
1890 case TCM_GETEXTENDEDSTYLE:
1891// FIXME (tab, "Unimplemented msg TCM_GETEXTENDEDSTYLE\n");
1892 return 0;
1893
1894 case TCM_SETEXTENDEDSTYLE:
1895// FIXME (tab, "Unimplemented msg TCM_SETEXTENDEDSTYLE\n");
1896 return 0;
1897
1898 case WM_GETFONT:
1899 return TAB_GetFont (hwnd, wParam, lParam);
1900
1901 case WM_SETFONT:
1902 return TAB_SetFont (hwnd, wParam, lParam);
1903
1904 case WM_CREATE:
1905 return TAB_Create (hwnd, wParam, lParam);
1906
1907 case WM_NCDESTROY:
1908 return TAB_Destroy (hwnd, wParam, lParam);
1909
1910 case WM_GETDLGCODE:
1911 return DLGC_WANTARROWS | DLGC_WANTCHARS;
1912
1913 case WM_LBUTTONDOWN:
1914 return TAB_LButtonDown (hwnd, wParam, lParam);
1915
1916 case WM_LBUTTONUP:
1917 return TAB_LButtonUp (hwnd, wParam, lParam);
1918
1919 case WM_RBUTTONDOWN:
1920 return TAB_RButtonDown (hwnd, wParam, lParam);
1921
1922 case WM_MOUSEMOVE:
1923 return TAB_MouseMove (hwnd, wParam, lParam);
1924
1925 case WM_ERASEBKGND:
1926 return TAB_EraseBackground (hwnd, (HDC)wParam);
1927
1928 case WM_PAINT:
1929 return TAB_Paint (hwnd, wParam);
1930
1931 case WM_SIZE:
1932 return TAB_Size (hwnd, wParam, lParam);
1933
1934 case WM_SETREDRAW:
1935 return TAB_SetRedraw (hwnd, wParam);
1936
1937 case WM_HSCROLL:
1938 return TAB_OnHScroll(hwnd, (int)LOWORD(wParam), (int)HIWORD(wParam), (HWND)lParam);
1939
1940 case WM_KILLFOCUS:
1941 case WM_SETFOCUS:
1942 return TAB_FocusChanging(hwnd, uMsg, wParam, lParam);
1943
1944 case WM_KEYUP:
1945 return TAB_KeyUp(hwnd, wParam);
1946
1947 default:
1948// if (uMsg >= WM_USER)
1949// ERR (tab, "unknown msg %04x wp=%08x lp=%08lx\n",
1950// uMsg, wParam, lParam);
1951 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1952 }
1953
1954 return 0;
1955}
1956
1957
1958VOID
1959TAB_Register (VOID)
1960{
1961 WNDCLASSA wndClass;
1962
1963 if (GlobalFindAtomA (WC_TABCONTROLA)) return;
1964
1965 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1966 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
1967 wndClass.lpfnWndProc = (WNDPROC)TAB_WindowProc;
1968 wndClass.cbClsExtra = 0;
1969 wndClass.cbWndExtra = sizeof(TAB_INFO *);
1970 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1971 wndClass.hbrBackground = (HBRUSH)NULL;
1972 wndClass.lpszClassName = WC_TABCONTROLA;
1973
1974 RegisterClassA (&wndClass);
1975}
1976
1977
1978VOID
1979TAB_Unregister (VOID)
1980{
1981 if (GlobalFindAtomA (WC_TABCONTROLA))
1982 UnregisterClassA (WC_TABCONTROLA, (HINSTANCE)NULL);
1983}
1984
Note: See TracBrowser for help on using the repository browser.