Changed xxx(VOID) to xxx(void).
[wine.git] / dlls / comctl32 / rebar.c
blob3692b8020b7158fd3861c54979ebeb70f54b6303
1 /*
2 * Rebar control
4 * Copyright 1998, 1999 Eric Kohl
6 * NOTES
7 * An author is needed! Any volunteers?
8 * I will only improve this control once in a while.
9 * Eric <ekohl@abo.rhein-zeitung.de>
11 * TODO:
12 * - vertical placement
13 * - ComboBox and ComboBoxEx placement
14 * - center image
15 * - Layout code.
16 * - Display code.
17 * - Some messages.
18 * - All notifications.
21 #include <string.h>
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "commctrl.h"
26 #include "rebar.h"
27 #include "debug.h"
29 DEFAULT_DEBUG_CHANNEL(rebar)
32 /* fDraw flags */
33 #define DRAW_GRIPPER 1
34 #define DRAW_IMAGE 2
35 #define DRAW_TEXT 4
36 #define DRAW_CHILD 8
38 #define GRIPPER_WIDTH 13
41 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongA (hwnd, 0))
44 static VOID
45 REBAR_DrawBand (HDC hdc, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
48 DrawEdge (hdc, &lpBand->rcBand, BDR_RAISEDINNER, BF_MIDDLE);
50 /* draw background */
52 /* draw gripper */
53 if (lpBand->fDraw & DRAW_GRIPPER)
54 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
56 /* draw caption image */
57 if (lpBand->fDraw & DRAW_IMAGE) {
58 /* FIXME: center image */
59 POINT pt;
61 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
62 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
64 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
65 /* lpBand->rcCapImage.left, lpBand->rcCapImage.top, */
66 pt.x, pt.y,
67 ILD_TRANSPARENT);
70 /* draw caption text */
71 if (lpBand->fDraw & DRAW_TEXT) {
72 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
73 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
74 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
75 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
76 if (oldBkMode != TRANSPARENT)
77 SetBkMode (hdc, oldBkMode);
78 SelectObject (hdc, hOldFont);
83 static VOID
84 REBAR_Refresh (HWND hwnd, HDC hdc)
86 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
87 REBAR_BAND *lpBand;
88 UINT i;
90 for (i = 0; i < infoPtr->uNumBands; i++) {
91 lpBand = &infoPtr->bands[i];
93 if ((lpBand->fStyle & RBBS_HIDDEN) ||
94 ((GetWindowLongA (hwnd, GWL_STYLE) & CCS_VERT) &&
95 (lpBand->fStyle & RBBS_NOVERT)))
96 continue;
98 REBAR_DrawBand (hdc, infoPtr, lpBand);
104 static VOID
105 REBAR_CalcHorzBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
107 lpBand->fDraw = 0;
109 /* set initial caption image rectangle */
110 SetRect (&lpBand->rcCapImage, 0, 0, 0, 0);
112 /* image is visible */
113 if ((lpBand->iImage > -1) && (infoPtr->himl)) {
114 lpBand->fDraw |= DRAW_IMAGE;
116 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
117 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
119 /* update band height */
120 if (lpBand->uMinHeight < infoPtr->imageSize.cy + 2) {
121 lpBand->uMinHeight = infoPtr->imageSize.cy + 2;
122 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->uMinHeight;
126 /* set initial caption text rectangle */
127 lpBand->rcCapText.left = lpBand->rcCapImage.right;
128 lpBand->rcCapText.top = lpBand->rcBand.top + 1;
129 lpBand->rcCapText.right = lpBand->rcCapText.left;
130 lpBand->rcCapText.bottom = lpBand->rcBand.bottom - 1;
132 /* text is visible */
133 if (lpBand->lpText) {
134 HDC hdc = GetDC (0);
135 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
136 SIZE size;
138 lpBand->fDraw |= DRAW_TEXT;
139 GetTextExtentPoint32W (hdc, lpBand->lpText,
140 lstrlenW (lpBand->lpText), &size);
141 lpBand->rcCapText.right += size.cx;
143 SelectObject (hdc, hOldFont);
144 ReleaseDC (0, hdc);
147 /* set initial child window rectangle */
148 if (lpBand->fStyle & RBBS_FIXEDSIZE) {
149 lpBand->rcChild.left = lpBand->rcCapText.right;
150 lpBand->rcChild.top = lpBand->rcBand.top;
151 lpBand->rcChild.right = lpBand->rcBand.right;
152 lpBand->rcChild.bottom = lpBand->rcBand.bottom;
154 else {
155 lpBand->rcChild.left = lpBand->rcCapText.right + 4;
156 lpBand->rcChild.top = lpBand->rcBand.top + 2;
157 lpBand->rcChild.right = lpBand->rcBand.right - 4;
158 lpBand->rcChild.bottom = lpBand->rcBand.bottom - 2;
161 /* calculate gripper rectangle */
162 if ((!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
163 (!(lpBand->fStyle & RBBS_FIXEDSIZE)) &&
164 ((lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
165 (infoPtr->uNumBands > 1))) {
166 lpBand->fDraw |= DRAW_GRIPPER;
167 lpBand->rcGripper.left = lpBand->rcBand.left + 3;
168 lpBand->rcGripper.right = lpBand->rcGripper.left + 3;
169 lpBand->rcGripper.top = lpBand->rcBand.top + 3;
170 lpBand->rcGripper.bottom = lpBand->rcBand.bottom - 3;
172 /* move caption rectangles */
173 OffsetRect (&lpBand->rcCapImage, GRIPPER_WIDTH, 0);
174 OffsetRect (&lpBand->rcCapText, GRIPPER_WIDTH, 0);
176 /* adjust child rectangle */
177 lpBand->rcChild.left += GRIPPER_WIDTH;
184 static VOID
185 REBAR_CalcVertBand (HWND hwnd, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
187 lpBand->fDraw = 0;
189 /* set initial caption image rectangle */
190 SetRect (&lpBand->rcCapImage, 0, 0, 0, 0);
192 /* image is visible */
193 if ((lpBand->iImage > -1) && (infoPtr->himl)) {
194 lpBand->fDraw |= DRAW_IMAGE;
196 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
197 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
199 /* update band width */
200 if (lpBand->uMinHeight < infoPtr->imageSize.cx + 2) {
201 lpBand->uMinHeight = infoPtr->imageSize.cx + 2;
202 lpBand->rcBand.right = lpBand->rcBand.left + lpBand->uMinHeight;
206 /* set initial caption text rectangle */
207 lpBand->rcCapText.left = lpBand->rcBand.left + 1;
208 lpBand->rcCapText.top = lpBand->rcCapImage.bottom;
209 lpBand->rcCapText.right = lpBand->rcBand.right - 1;
210 lpBand->rcCapText.bottom = lpBand->rcCapText.top;
212 /* text is visible */
213 if (lpBand->lpText) {
214 HDC hdc = GetDC (0);
215 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
216 SIZE size;
218 lpBand->fDraw |= DRAW_TEXT;
219 GetTextExtentPoint32W (hdc, lpBand->lpText,
220 lstrlenW (lpBand->lpText), &size);
221 /* lpBand->rcCapText.right += size.cx; */
222 lpBand->rcCapText.bottom += size.cy;
224 SelectObject (hdc, hOldFont);
225 ReleaseDC (0, hdc);
228 /* set initial child window rectangle */
229 if (lpBand->fStyle & RBBS_FIXEDSIZE) {
230 lpBand->rcChild.left = lpBand->rcBand.left;
231 lpBand->rcChild.top = lpBand->rcCapText.bottom;
232 lpBand->rcChild.right = lpBand->rcBand.right;
233 lpBand->rcChild.bottom = lpBand->rcBand.bottom;
235 else {
236 lpBand->rcChild.left = lpBand->rcBand.left + 2;
237 lpBand->rcChild.top = lpBand->rcCapText.bottom + 4;
238 lpBand->rcChild.right = lpBand->rcBand.right - 2;
239 lpBand->rcChild.bottom = lpBand->rcBand.bottom - 4;
242 /* calculate gripper rectangle */
243 if ((!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
244 (!(lpBand->fStyle & RBBS_FIXEDSIZE)) &&
245 ((lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
246 (infoPtr->uNumBands > 1))) {
247 lpBand->fDraw |= DRAW_GRIPPER;
249 if (GetWindowLongA (hwnd, GWL_STYLE) & RBS_VERTICALGRIPPER) {
250 /* adjust band width */
251 lpBand->rcBand.right += GRIPPER_WIDTH;
252 lpBand->uMinHeight += GRIPPER_WIDTH;
254 lpBand->rcGripper.left = lpBand->rcBand.left + 3;
255 lpBand->rcGripper.right = lpBand->rcGripper.left + 3;
256 lpBand->rcGripper.top = lpBand->rcBand.top + 3;
257 lpBand->rcGripper.bottom = lpBand->rcBand.bottom - 3;
259 /* move caption rectangles */
260 OffsetRect (&lpBand->rcCapImage, GRIPPER_WIDTH, 0);
261 OffsetRect (&lpBand->rcCapText, GRIPPER_WIDTH, 0);
263 /* adjust child rectangle */
264 lpBand->rcChild.left += GRIPPER_WIDTH;
266 else {
267 lpBand->rcGripper.left = lpBand->rcBand.left + 3;
268 lpBand->rcGripper.right = lpBand->rcBand.right - 3;
269 lpBand->rcGripper.top = lpBand->rcBand.top + 3;
270 lpBand->rcGripper.bottom = lpBand->rcGripper.top + 3;
272 /* move caption rectangles */
273 OffsetRect (&lpBand->rcCapImage, 0, GRIPPER_WIDTH);
274 OffsetRect (&lpBand->rcCapText, 0, GRIPPER_WIDTH);
276 /* adjust child rectangle */
277 lpBand->rcChild.top += GRIPPER_WIDTH;
283 static VOID
284 REBAR_Layout (HWND hwnd, LPRECT lpRect)
286 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
287 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
288 REBAR_BAND *lpBand;
289 RECT rcClient;
290 INT x, y, cx, cy;
291 UINT i;
293 if (lpRect)
294 rcClient = *lpRect;
295 else
296 GetClientRect (hwnd, &rcClient);
298 x = 0;
299 y = 0;
301 if (dwStyle & CCS_VERT) {
302 cx = 20; /* FIXME: fixed height */
303 cy = rcClient.bottom - rcClient.top;
305 else {
306 cx = rcClient.right - rcClient.left;
307 cy = 20; /* FIXME: fixed height */
310 for (i = 0; i < infoPtr->uNumBands; i++) {
311 lpBand = &infoPtr->bands[i];
313 if ((lpBand->fStyle & RBBS_HIDDEN) ||
314 ((dwStyle & CCS_VERT) && (lpBand->fStyle & RBBS_NOVERT)))
315 continue;
318 if (dwStyle & CCS_VERT) {
319 if (lpBand->fStyle & RBBS_VARIABLEHEIGHT)
320 cx = lpBand->cyMaxChild;
321 else if (lpBand->fStyle & RBBIM_CHILDSIZE)
322 cx = lpBand->cyMinChild;
323 else
324 cx = 20; /* FIXME */
326 lpBand->rcBand.left = x;
327 lpBand->rcBand.right = x + cx;
328 lpBand->rcBand.top = y;
329 lpBand->rcBand.bottom = y + cy;
330 lpBand->uMinHeight = cx;
332 else {
333 if (lpBand->fStyle & RBBS_VARIABLEHEIGHT)
334 cy = lpBand->cyMaxChild;
335 else if (lpBand->fStyle & RBBIM_CHILDSIZE)
336 cy = lpBand->cyMinChild;
337 else
338 cy = 20; /* FIXME */
340 lpBand->rcBand.left = x;
341 lpBand->rcBand.right = x + cx;
342 lpBand->rcBand.top = y;
343 lpBand->rcBand.bottom = y + cy;
344 lpBand->uMinHeight = cy;
347 if (dwStyle & CCS_VERT) {
348 REBAR_CalcVertBand (hwnd, infoPtr, lpBand);
349 x += lpBand->uMinHeight;
351 else {
352 REBAR_CalcHorzBand (infoPtr, lpBand);
353 y += lpBand->uMinHeight;
357 if (dwStyle & CCS_VERT) {
358 infoPtr->calcSize.cx = x;
359 infoPtr->calcSize.cy = rcClient.bottom - rcClient.top;
361 else {
362 infoPtr->calcSize.cx = rcClient.right - rcClient.left;
363 infoPtr->calcSize.cy = y;
368 static VOID
369 REBAR_ForceResize (HWND hwnd)
371 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
372 RECT rc;
374 TRACE (rebar, " to [%d x %d]!\n",
375 infoPtr->calcSize.cx, infoPtr->calcSize.cy);
377 infoPtr->bAutoResize = TRUE;
379 rc.left = 0;
380 rc.top = 0;
381 rc.right = infoPtr->calcSize.cx;
382 rc.bottom = infoPtr->calcSize.cy;
384 if (GetWindowLongA (hwnd, GWL_STYLE) & WS_BORDER) {
385 InflateRect (&rc, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
388 SetWindowPos (hwnd, 0, 0, 0,
389 rc.right - rc.left, rc.bottom - rc.top,
390 SWP_NOMOVE | SWP_NOZORDER | SWP_SHOWWINDOW);
394 static VOID
395 REBAR_MoveChildWindows (HWND hwnd)
397 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
398 REBAR_BAND *lpBand;
399 CHAR szClassName[40];
400 UINT i;
402 for (i = 0; i < infoPtr->uNumBands; i++) {
403 lpBand = &infoPtr->bands[i];
405 if (lpBand->fStyle & RBBS_HIDDEN)
406 continue;
407 if (lpBand->hwndChild) {
408 TRACE (rebar, "hwndChild = %x\n", lpBand->hwndChild);
410 GetClassNameA (lpBand->hwndChild, szClassName, 40);
411 if (!lstrcmpA (szClassName, "ComboBox")) {
412 INT nEditHeight, yPos;
413 RECT rc;
415 /* special placement code for combo box */
418 /* get size of edit line */
419 GetWindowRect (lpBand->hwndChild, &rc);
420 nEditHeight = rc.bottom - rc.top;
421 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
423 /* center combo box inside child area */
424 SetWindowPos (lpBand->hwndChild, HWND_TOP,
425 lpBand->rcChild.left, /*lpBand->rcChild.top*/ yPos,
426 lpBand->rcChild.right - lpBand->rcChild.left,
427 nEditHeight,
428 SWP_SHOWWINDOW);
430 #if 0
431 else if (!lstrcmpA (szClassName, WC_COMBOBOXEXA)) {
432 /* special placement code for extended combo box */
436 #endif
437 else {
438 SetWindowPos (lpBand->hwndChild, HWND_TOP,
439 lpBand->rcChild.left, lpBand->rcChild.top,
440 lpBand->rcChild.right - lpBand->rcChild.left,
441 lpBand->rcChild.bottom - lpBand->rcChild.top,
442 SWP_SHOWWINDOW);
449 static void
450 REBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pBand)
452 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
453 REBAR_BAND *lpBand;
454 RECT rect;
455 INT iCount;
457 GetClientRect (hwnd, &rect);
459 *pFlags = RBHT_NOWHERE;
460 if (PtInRect (&rect, *lpPt))
462 if (infoPtr->uNumBands == 0) {
463 *pFlags = RBHT_NOWHERE;
464 if (pBand)
465 *pBand = -1;
466 TRACE (rebar, "NOWHERE\n");
467 return;
469 else {
470 /* somewhere inside */
471 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
472 lpBand = &infoPtr->bands[iCount];
473 if (PtInRect (&lpBand->rcBand, *lpPt)) {
474 if (pBand)
475 *pBand = iCount;
476 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
477 *pFlags = RBHT_GRABBER;
478 TRACE (rebar, "ON GRABBER %d\n", iCount);
479 return;
481 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
482 *pFlags = RBHT_CAPTION;
483 TRACE (rebar, "ON CAPTION %d\n", iCount);
484 return;
486 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
487 *pFlags = RBHT_CAPTION;
488 TRACE (rebar, "ON CAPTION %d\n", iCount);
489 return;
491 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
492 *pFlags = RBHT_CLIENT;
493 TRACE (rebar, "ON CLIENT %d\n", iCount);
494 return;
496 else {
497 *pFlags = RBHT_NOWHERE;
498 TRACE (rebar, "NOWHERE %d\n", iCount);
499 return;
504 *pFlags = RBHT_NOWHERE;
505 if (pBand)
506 *pBand = -1;
508 TRACE (rebar, "NOWHERE\n");
509 return;
512 else {
513 *pFlags = RBHT_NOWHERE;
514 if (pBand)
515 *pBand = -1;
516 TRACE (rebar, "NOWHERE\n");
517 return;
520 TRACE (rebar, "flags=0x%X\n", *pFlags);
521 return;
526 /* << REBAR_BeginDrag >> */
529 static LRESULT
530 REBAR_DeleteBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
532 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
533 UINT uBand = (UINT)wParam;
535 if (uBand >= infoPtr->uNumBands)
536 return FALSE;
538 TRACE (rebar, "deleting band %u!\n", uBand);
540 if (infoPtr->uNumBands == 1) {
541 TRACE (rebar, " simple delete!\n");
542 COMCTL32_Free (infoPtr->bands);
543 infoPtr->bands = NULL;
544 infoPtr->uNumBands = 0;
546 else {
547 REBAR_BAND *oldBands = infoPtr->bands;
548 TRACE(rebar, "complex delete! [uBand=%u]\n", uBand);
550 infoPtr->uNumBands--;
551 infoPtr->bands = COMCTL32_Alloc (sizeof (REBAR_BAND) * infoPtr->uNumBands);
552 if (uBand > 0) {
553 memcpy (&infoPtr->bands[0], &oldBands[0],
554 uBand * sizeof(REBAR_BAND));
557 if (uBand < infoPtr->uNumBands) {
558 memcpy (&infoPtr->bands[uBand], &oldBands[uBand+1],
559 (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
562 COMCTL32_Free (oldBands);
565 REBAR_Layout (hwnd, NULL);
566 REBAR_ForceResize (hwnd);
567 REBAR_MoveChildWindows (hwnd);
569 return TRUE;
573 /* << REBAR_DragMove >> */
574 /* << REBAR_EndDrag >> */
577 static LRESULT
578 REBAR_GetBandBorders (HWND hwnd, WPARAM wParam, LPARAM lParam)
580 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
581 /* LPRECT32 lpRect = (LPRECT32)lParam; */
582 REBAR_BAND *lpBand;
584 if (!lParam)
585 return 0;
586 if ((UINT)wParam >= infoPtr->uNumBands)
587 return 0;
589 lpBand = &infoPtr->bands[(UINT)wParam];
590 if (GetWindowLongA (hwnd, GWL_STYLE) & RBS_BANDBORDERS) {
593 else {
597 return 0;
601 inline static LRESULT
602 REBAR_GetBandCount (HWND hwnd)
604 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
606 TRACE (rebar, "band count %u!\n", infoPtr->uNumBands);
608 return infoPtr->uNumBands;
612 static LRESULT
613 REBAR_GetBandInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
615 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
616 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
617 REBAR_BAND *lpBand;
619 if (lprbbi == NULL)
620 return FALSE;
621 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
622 return FALSE;
623 if ((UINT)wParam >= infoPtr->uNumBands)
624 return FALSE;
626 TRACE (rebar, "index %u\n", (UINT)wParam);
628 /* copy band information */
629 lpBand = &infoPtr->bands[(UINT)wParam];
631 if (lprbbi->fMask & RBBIM_STYLE)
632 lprbbi->fStyle = lpBand->fStyle;
634 if (lprbbi->fMask & RBBIM_COLORS) {
635 lprbbi->clrFore = lpBand->clrFore;
636 lprbbi->clrBack = lpBand->clrBack;
639 if ((lprbbi->fMask & RBBIM_TEXT) &&
640 (lprbbi->lpText) && (lpBand->lpText)) {
641 lstrcpynWtoA (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
644 if (lprbbi->fMask & RBBIM_IMAGE)
645 lprbbi->iImage = lpBand->iImage;
647 if (lprbbi->fMask & RBBIM_CHILD)
648 lprbbi->hwndChild = lpBand->hwndChild;
650 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
651 lprbbi->cxMinChild = lpBand->cxMinChild;
652 lprbbi->cyMinChild = lpBand->cyMinChild;
653 lprbbi->cyMaxChild = lpBand->cyMaxChild;
654 lprbbi->cyChild = lpBand->cyChild;
655 lprbbi->cyIntegral = lpBand->cyIntegral;
658 if (lprbbi->fMask & RBBIM_SIZE)
659 lprbbi->cx = lpBand->cx;
661 if (lprbbi->fMask & RBBIM_BACKGROUND)
662 lprbbi->hbmBack = lpBand->hbmBack;
664 if (lprbbi->fMask & RBBIM_ID)
665 lprbbi->wID = lpBand->wID;
667 /* check for additional data */
668 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
669 if (lprbbi->fMask & RBBIM_IDEALSIZE)
670 lprbbi->cxIdeal = lpBand->cxIdeal;
672 if (lprbbi->fMask & RBBIM_LPARAM)
673 lprbbi->lParam = lpBand->lParam;
675 if (lprbbi->fMask & RBBIM_HEADERSIZE)
676 lprbbi->cxHeader = lpBand->cxHeader;
679 return TRUE;
683 static LRESULT
684 REBAR_GetBandInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
686 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
687 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
688 REBAR_BAND *lpBand;
690 if (lprbbi == NULL)
691 return FALSE;
692 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
693 return FALSE;
694 if ((UINT)wParam >= infoPtr->uNumBands)
695 return FALSE;
697 TRACE (rebar, "index %u\n", (UINT)wParam);
699 /* copy band information */
700 lpBand = &infoPtr->bands[(UINT)wParam];
702 if (lprbbi->fMask & RBBIM_STYLE)
703 lprbbi->fStyle = lpBand->fStyle;
705 if (lprbbi->fMask & RBBIM_COLORS) {
706 lprbbi->clrFore = lpBand->clrFore;
707 lprbbi->clrBack = lpBand->clrBack;
710 if ((lprbbi->fMask & RBBIM_TEXT) &&
711 (lprbbi->lpText) && (lpBand->lpText)) {
712 lstrcpynW (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
715 if (lprbbi->fMask & RBBIM_IMAGE)
716 lprbbi->iImage = lpBand->iImage;
718 if (lprbbi->fMask & RBBIM_CHILD)
719 lprbbi->hwndChild = lpBand->hwndChild;
721 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
722 lprbbi->cxMinChild = lpBand->cxMinChild;
723 lprbbi->cyMinChild = lpBand->cyMinChild;
724 lprbbi->cyMaxChild = lpBand->cyMaxChild;
725 lprbbi->cyChild = lpBand->cyChild;
726 lprbbi->cyIntegral = lpBand->cyIntegral;
729 if (lprbbi->fMask & RBBIM_SIZE)
730 lprbbi->cx = lpBand->cx;
732 if (lprbbi->fMask & RBBIM_BACKGROUND)
733 lprbbi->hbmBack = lpBand->hbmBack;
735 if (lprbbi->fMask & RBBIM_ID)
736 lprbbi->wID = lpBand->wID;
738 /* check for additional data */
739 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
740 if (lprbbi->fMask & RBBIM_IDEALSIZE)
741 lprbbi->cxIdeal = lpBand->cxIdeal;
743 if (lprbbi->fMask & RBBIM_LPARAM)
744 lprbbi->lParam = lpBand->lParam;
746 if (lprbbi->fMask & RBBIM_HEADERSIZE)
747 lprbbi->cxHeader = lpBand->cxHeader;
750 return TRUE;
754 static LRESULT
755 REBAR_GetBarHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
757 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
758 INT nHeight;
760 REBAR_Layout (hwnd, NULL);
761 nHeight = infoPtr->calcSize.cy;
763 if (GetWindowLongA (hwnd, GWL_STYLE) & WS_BORDER)
764 nHeight += (2 * GetSystemMetrics(SM_CYEDGE));
767 FIXME (rebar, "height = %d\n", nHeight);
769 return nHeight;
773 static LRESULT
774 REBAR_GetBarInfo (HWND hwnd, WPARAM wParam, LPARAM lParam)
776 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
777 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
779 if (lpInfo == NULL)
780 return FALSE;
782 if (lpInfo->cbSize < sizeof (REBARINFO))
783 return FALSE;
785 TRACE (rebar, "getting bar info!\n");
787 if (infoPtr->himl) {
788 lpInfo->himl = infoPtr->himl;
789 lpInfo->fMask |= RBIM_IMAGELIST;
792 return TRUE;
796 inline static LRESULT
797 REBAR_GetBkColor (HWND hwnd)
799 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
801 TRACE (rebar, "background color 0x%06lx!\n", infoPtr->clrBk);
803 return infoPtr->clrBk;
807 /* << REBAR_GetColorScheme >> */
808 /* << REBAR_GetDropTarget >> */
811 static LRESULT
812 REBAR_GetPalette (HWND hwnd, WPARAM wParam, LPARAM lParam)
814 FIXME (rebar, "empty stub!\n");
816 return 0;
820 static LRESULT
821 REBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
823 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
824 INT iBand = (INT)wParam;
825 LPRECT lprc = (LPRECT)lParam;
826 REBAR_BAND *lpBand;
828 if ((iBand < 0) && ((UINT)iBand >= infoPtr->uNumBands))
829 return FALSE;
830 if (!lprc)
831 return FALSE;
833 TRACE (rebar, "band %d\n", iBand);
835 lpBand = &infoPtr->bands[iBand];
836 CopyRect (lprc, &lpBand->rcBand);
838 lprc->left = lpBand->rcBand.left;
839 lprc->top = lpBand->rcBand.top;
840 lprc->right = lpBand->rcBand.right;
841 lprc->bottom = lpBand->rcBand.bottom;
844 return TRUE;
848 inline static LRESULT
849 REBAR_GetRowCount (HWND hwnd)
851 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
853 FIXME (rebar, "%u : semi stub!\n", infoPtr->uNumBands);
855 return infoPtr->uNumBands;
859 static LRESULT
860 REBAR_GetRowHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
862 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
864 FIXME (rebar, "-- height = 20: semi stub!\n");
866 return 20;
870 inline static LRESULT
871 REBAR_GetTextColor (HWND hwnd)
873 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
875 TRACE (rebar, "text color 0x%06lx!\n", infoPtr->clrText);
877 return infoPtr->clrText;
881 inline static LRESULT
882 REBAR_GetToolTips (HWND hwnd)
884 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
885 return infoPtr->hwndToolTip;
889 inline static LRESULT
890 REBAR_GetUnicodeFormat (HWND hwnd)
892 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
893 return infoPtr->bUnicode;
897 static LRESULT
898 REBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
900 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
901 LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
903 if (!lprbht)
904 return -1;
906 REBAR_InternalHitTest (hwnd, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
908 return lprbht->iBand;
912 static LRESULT
913 REBAR_IdToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
915 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
916 UINT i;
918 if (infoPtr == NULL)
919 return -1;
921 if (infoPtr->uNumBands < 1)
922 return -1;
924 TRACE (rebar, "id %u\n", (UINT)wParam);
926 for (i = 0; i < infoPtr->uNumBands; i++) {
927 if (infoPtr->bands[i].wID == (UINT)wParam) {
928 TRACE (rebar, "band %u found!\n", i);
929 return i;
933 TRACE (rebar, "no band found!\n");
934 return -1;
938 static LRESULT
939 REBAR_InsertBandA (HWND hwnd, WPARAM wParam, LPARAM lParam)
941 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
942 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
943 UINT uIndex = (UINT)wParam;
944 REBAR_BAND *lpBand;
946 if (infoPtr == NULL)
947 return FALSE;
948 if (lprbbi == NULL)
949 return FALSE;
950 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
951 return FALSE;
953 TRACE (rebar, "insert band at %u!\n", uIndex);
955 if (infoPtr->uNumBands == 0) {
956 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
957 uIndex = 0;
959 else {
960 REBAR_BAND *oldBands = infoPtr->bands;
961 infoPtr->bands =
962 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
963 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
964 uIndex = infoPtr->uNumBands;
966 /* pre insert copy */
967 if (uIndex > 0) {
968 memcpy (&infoPtr->bands[0], &oldBands[0],
969 uIndex * sizeof(REBAR_BAND));
972 /* post copy */
973 if (uIndex < infoPtr->uNumBands - 1) {
974 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
975 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
978 COMCTL32_Free (oldBands);
981 infoPtr->uNumBands++;
983 TRACE (rebar, "index %u!\n", uIndex);
985 /* initialize band (infoPtr->bands[uIndex])*/
986 lpBand = &infoPtr->bands[uIndex];
988 if (lprbbi->fMask & RBBIM_STYLE)
989 lpBand->fStyle = lprbbi->fStyle;
991 if (lprbbi->fMask & RBBIM_COLORS) {
992 lpBand->clrFore = lprbbi->clrFore;
993 lpBand->clrBack = lprbbi->clrBack;
995 else {
996 lpBand->clrFore = CLR_NONE;
997 lpBand->clrBack = CLR_NONE;
1000 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
1001 INT len = lstrlenA (lprbbi->lpText);
1002 if (len > 0) {
1003 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1004 lstrcpyAtoW (lpBand->lpText, lprbbi->lpText);
1008 if (lprbbi->fMask & RBBIM_IMAGE)
1009 lpBand->iImage = lprbbi->iImage;
1010 else
1011 lpBand->iImage = -1;
1013 if (lprbbi->fMask & RBBIM_CHILD) {
1014 TRACE (rebar, "hwndChild = %x\n", lprbbi->hwndChild);
1015 lpBand->hwndChild = lprbbi->hwndChild;
1016 lpBand->hwndPrevParent =
1017 SetParent (lpBand->hwndChild, hwnd);
1020 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
1021 lpBand->cxMinChild = lprbbi->cxMinChild;
1022 lpBand->cyMinChild = lprbbi->cyMinChild;
1023 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1024 lpBand->cyChild = lprbbi->cyChild;
1025 lpBand->cyIntegral = lprbbi->cyIntegral;
1027 else {
1028 lpBand->cxMinChild = -1;
1029 lpBand->cyMinChild = -1;
1030 lpBand->cyMaxChild = -1;
1031 lpBand->cyChild = -1;
1032 lpBand->cyIntegral = -1;
1035 if (lprbbi->fMask & RBBIM_SIZE)
1036 lpBand->cx = lprbbi->cx;
1037 else
1038 lpBand->cx = -1;
1040 if (lprbbi->fMask & RBBIM_BACKGROUND)
1041 lpBand->hbmBack = lprbbi->hbmBack;
1043 if (lprbbi->fMask & RBBIM_ID)
1044 lpBand->wID = lprbbi->wID;
1046 /* check for additional data */
1047 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
1048 if (lprbbi->fMask & RBBIM_IDEALSIZE)
1049 lpBand->cxIdeal = lprbbi->cxIdeal;
1051 if (lprbbi->fMask & RBBIM_LPARAM)
1052 lpBand->lParam = lprbbi->lParam;
1054 if (lprbbi->fMask & RBBIM_HEADERSIZE)
1055 lpBand->cxHeader = lprbbi->cxHeader;
1059 REBAR_Layout (hwnd, NULL);
1060 REBAR_ForceResize (hwnd);
1061 REBAR_MoveChildWindows (hwnd);
1063 return TRUE;
1067 static LRESULT
1068 REBAR_InsertBandW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1070 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1071 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
1072 UINT uIndex = (UINT)wParam;
1073 REBAR_BAND *lpBand;
1075 if (infoPtr == NULL)
1076 return FALSE;
1077 if (lprbbi == NULL)
1078 return FALSE;
1079 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
1080 return FALSE;
1082 TRACE (rebar, "insert band at %u!\n", uIndex);
1084 if (infoPtr->uNumBands == 0) {
1085 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
1086 uIndex = 0;
1088 else {
1089 REBAR_BAND *oldBands = infoPtr->bands;
1090 infoPtr->bands =
1091 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
1092 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
1093 uIndex = infoPtr->uNumBands;
1095 /* pre insert copy */
1096 if (uIndex > 0) {
1097 memcpy (&infoPtr->bands[0], &oldBands[0],
1098 uIndex * sizeof(REBAR_BAND));
1101 /* post copy */
1102 if (uIndex < infoPtr->uNumBands - 1) {
1103 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
1104 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
1107 COMCTL32_Free (oldBands);
1110 infoPtr->uNumBands++;
1112 TRACE (rebar, "index %u!\n", uIndex);
1114 /* initialize band (infoPtr->bands[uIndex])*/
1115 lpBand = &infoPtr->bands[uIndex];
1117 if (lprbbi->fMask & RBBIM_STYLE)
1118 lpBand->fStyle = lprbbi->fStyle;
1120 if (lprbbi->fMask & RBBIM_COLORS) {
1121 lpBand->clrFore = lprbbi->clrFore;
1122 lpBand->clrBack = lprbbi->clrBack;
1124 else {
1125 lpBand->clrFore = CLR_NONE;
1126 lpBand->clrBack = CLR_NONE;
1129 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
1130 INT len = lstrlenW (lprbbi->lpText);
1131 if (len > 0) {
1132 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1133 lstrcpyW (lpBand->lpText, lprbbi->lpText);
1137 if (lprbbi->fMask & RBBIM_IMAGE)
1138 lpBand->iImage = lprbbi->iImage;
1139 else
1140 lpBand->iImage = -1;
1142 if (lprbbi->fMask & RBBIM_CHILD) {
1143 TRACE (rebar, "hwndChild = %x\n", lprbbi->hwndChild);
1144 lpBand->hwndChild = lprbbi->hwndChild;
1145 lpBand->hwndPrevParent =
1146 SetParent (lpBand->hwndChild, hwnd);
1149 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
1150 lpBand->cxMinChild = lprbbi->cxMinChild;
1151 lpBand->cyMinChild = lprbbi->cyMinChild;
1152 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1153 lpBand->cyChild = lprbbi->cyChild;
1154 lpBand->cyIntegral = lprbbi->cyIntegral;
1156 else {
1157 lpBand->cxMinChild = -1;
1158 lpBand->cyMinChild = -1;
1159 lpBand->cyMaxChild = -1;
1160 lpBand->cyChild = -1;
1161 lpBand->cyIntegral = -1;
1164 if (lprbbi->fMask & RBBIM_SIZE)
1165 lpBand->cx = lprbbi->cx;
1166 else
1167 lpBand->cx = -1;
1169 if (lprbbi->fMask & RBBIM_BACKGROUND)
1170 lpBand->hbmBack = lprbbi->hbmBack;
1172 if (lprbbi->fMask & RBBIM_ID)
1173 lpBand->wID = lprbbi->wID;
1175 /* check for additional data */
1176 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
1177 if (lprbbi->fMask & RBBIM_IDEALSIZE)
1178 lpBand->cxIdeal = lprbbi->cxIdeal;
1180 if (lprbbi->fMask & RBBIM_LPARAM)
1181 lpBand->lParam = lprbbi->lParam;
1183 if (lprbbi->fMask & RBBIM_HEADERSIZE)
1184 lpBand->cxHeader = lprbbi->cxHeader;
1188 REBAR_Layout (hwnd, NULL);
1189 REBAR_ForceResize (hwnd);
1190 REBAR_MoveChildWindows (hwnd);
1192 return TRUE;
1196 static LRESULT
1197 REBAR_MaximizeBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
1199 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
1201 FIXME (rebar, "(uBand = %u fIdeal = %s)\n",
1202 (UINT)wParam, lParam ? "TRUE" : "FALSE");
1205 return 0;
1209 static LRESULT
1210 REBAR_MinimizeBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
1212 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
1214 FIXME (rebar, "(uBand = %u)\n", (UINT)wParam);
1217 return 0;
1221 static LRESULT
1222 REBAR_MoveBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
1224 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
1226 FIXME (rebar, "(iFrom = %u iTof = %u)\n",
1227 (UINT)wParam, (UINT)lParam);
1230 return FALSE;
1234 static LRESULT
1235 REBAR_SetBandInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1237 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1238 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
1239 REBAR_BAND *lpBand;
1241 if (lprbbi == NULL)
1242 return FALSE;
1243 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
1244 return FALSE;
1245 if ((UINT)wParam >= infoPtr->uNumBands)
1246 return FALSE;
1248 TRACE (rebar, "index %u\n", (UINT)wParam);
1250 /* set band information */
1251 lpBand = &infoPtr->bands[(UINT)wParam];
1253 if (lprbbi->fMask & RBBIM_STYLE)
1254 lpBand->fStyle = lprbbi->fStyle;
1256 if (lprbbi->fMask & RBBIM_COLORS) {
1257 lpBand->clrFore = lprbbi->clrFore;
1258 lpBand->clrBack = lprbbi->clrBack;
1261 if (lprbbi->fMask & RBBIM_TEXT) {
1262 if (lpBand->lpText) {
1263 COMCTL32_Free (lpBand->lpText);
1264 lpBand->lpText = NULL;
1266 if (lprbbi->lpText) {
1267 INT len = lstrlenA (lprbbi->lpText);
1268 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1269 lstrcpyAtoW (lpBand->lpText, lprbbi->lpText);
1273 if (lprbbi->fMask & RBBIM_IMAGE)
1274 lpBand->iImage = lprbbi->iImage;
1276 if (lprbbi->fMask & RBBIM_CHILD) {
1277 if (lprbbi->hwndChild) {
1278 lpBand->hwndChild = lprbbi->hwndChild;
1279 lpBand->hwndPrevParent =
1280 SetParent (lpBand->hwndChild, hwnd);
1282 else {
1283 TRACE (rebar, "child: 0x%x prev parent: 0x%x\n",
1284 lpBand->hwndChild, lpBand->hwndPrevParent);
1285 lpBand->hwndChild = 0;
1286 lpBand->hwndPrevParent = 0;
1290 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
1291 lpBand->cxMinChild = lprbbi->cxMinChild;
1292 lpBand->cyMinChild = lprbbi->cyMinChild;
1293 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1294 lpBand->cyChild = lprbbi->cyChild;
1295 lpBand->cyIntegral = lprbbi->cyIntegral;
1298 if (lprbbi->fMask & RBBIM_SIZE)
1299 lpBand->cx = lprbbi->cx;
1301 if (lprbbi->fMask & RBBIM_BACKGROUND)
1302 lpBand->hbmBack = lprbbi->hbmBack;
1304 if (lprbbi->fMask & RBBIM_ID)
1305 lpBand->wID = lprbbi->wID;
1307 /* check for additional data */
1308 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
1309 if (lprbbi->fMask & RBBIM_IDEALSIZE)
1310 lpBand->cxIdeal = lprbbi->cxIdeal;
1312 if (lprbbi->fMask & RBBIM_LPARAM)
1313 lpBand->lParam = lprbbi->lParam;
1315 if (lprbbi->fMask & RBBIM_HEADERSIZE)
1316 lpBand->cxHeader = lprbbi->cxHeader;
1319 REBAR_Layout (hwnd, NULL);
1320 REBAR_ForceResize (hwnd);
1321 REBAR_MoveChildWindows (hwnd);
1323 return TRUE;
1327 static LRESULT
1328 REBAR_SetBandInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1330 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1331 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
1332 REBAR_BAND *lpBand;
1334 if (lprbbi == NULL)
1335 return FALSE;
1336 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
1337 return FALSE;
1338 if ((UINT)wParam >= infoPtr->uNumBands)
1339 return FALSE;
1341 TRACE (rebar, "index %u\n", (UINT)wParam);
1343 /* set band information */
1344 lpBand = &infoPtr->bands[(UINT)wParam];
1346 if (lprbbi->fMask & RBBIM_STYLE)
1347 lpBand->fStyle = lprbbi->fStyle;
1349 if (lprbbi->fMask & RBBIM_COLORS) {
1350 lpBand->clrFore = lprbbi->clrFore;
1351 lpBand->clrBack = lprbbi->clrBack;
1354 if (lprbbi->fMask & RBBIM_TEXT) {
1355 if (lpBand->lpText) {
1356 COMCTL32_Free (lpBand->lpText);
1357 lpBand->lpText = NULL;
1359 if (lprbbi->lpText) {
1360 INT len = lstrlenW (lprbbi->lpText);
1361 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1362 lstrcpyW (lpBand->lpText, lprbbi->lpText);
1366 if (lprbbi->fMask & RBBIM_IMAGE)
1367 lpBand->iImage = lprbbi->iImage;
1369 if (lprbbi->fMask & RBBIM_CHILD) {
1370 if (lprbbi->hwndChild) {
1371 lpBand->hwndChild = lprbbi->hwndChild;
1372 lpBand->hwndPrevParent =
1373 SetParent (lpBand->hwndChild, hwnd);
1375 else {
1376 TRACE (rebar, "child: 0x%x prev parent: 0x%x\n",
1377 lpBand->hwndChild, lpBand->hwndPrevParent);
1378 lpBand->hwndChild = 0;
1379 lpBand->hwndPrevParent = 0;
1383 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
1384 lpBand->cxMinChild = lprbbi->cxMinChild;
1385 lpBand->cyMinChild = lprbbi->cyMinChild;
1386 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1387 lpBand->cyChild = lprbbi->cyChild;
1388 lpBand->cyIntegral = lprbbi->cyIntegral;
1391 if (lprbbi->fMask & RBBIM_SIZE)
1392 lpBand->cx = lprbbi->cx;
1394 if (lprbbi->fMask & RBBIM_BACKGROUND)
1395 lpBand->hbmBack = lprbbi->hbmBack;
1397 if (lprbbi->fMask & RBBIM_ID)
1398 lpBand->wID = lprbbi->wID;
1400 /* check for additional data */
1401 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
1402 if (lprbbi->fMask & RBBIM_IDEALSIZE)
1403 lpBand->cxIdeal = lprbbi->cxIdeal;
1405 if (lprbbi->fMask & RBBIM_LPARAM)
1406 lpBand->lParam = lprbbi->lParam;
1408 if (lprbbi->fMask & RBBIM_HEADERSIZE)
1409 lpBand->cxHeader = lprbbi->cxHeader;
1412 REBAR_Layout (hwnd, NULL);
1413 REBAR_ForceResize (hwnd);
1414 REBAR_MoveChildWindows (hwnd);
1416 return TRUE;
1420 static LRESULT
1421 REBAR_SetBarInfo (HWND hwnd, WPARAM wParam, LPARAM lParam)
1423 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1424 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
1426 if (lpInfo == NULL)
1427 return FALSE;
1429 if (lpInfo->cbSize < sizeof (REBARINFO))
1430 return FALSE;
1432 TRACE (rebar, "setting bar info!\n");
1434 if (lpInfo->fMask & RBIM_IMAGELIST) {
1435 infoPtr->himl = lpInfo->himl;
1436 if (infoPtr->himl) {
1437 ImageList_GetIconSize (infoPtr->himl, &infoPtr->imageSize.cx,
1438 &infoPtr->imageSize.cy);
1440 else {
1441 infoPtr->imageSize.cx = 0;
1442 infoPtr->imageSize.cy = 0;
1446 return TRUE;
1450 static LRESULT
1451 REBAR_SetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1453 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1454 COLORREF clrTemp;
1456 clrTemp = infoPtr->clrBk;
1457 infoPtr->clrBk = (COLORREF)lParam;
1459 TRACE (rebar, "background color 0x%06lx!\n", infoPtr->clrBk);
1461 return clrTemp;
1465 /* << REBAR_SetColorScheme >> */
1466 /* << REBAR_SetPalette >> */
1469 static LRESULT
1470 REBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1472 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1473 HWND hwndTemp = infoPtr->hwndNotify;
1475 infoPtr->hwndNotify = (HWND)wParam;
1477 return (LRESULT)hwndTemp;
1481 static LRESULT
1482 REBAR_SetTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1484 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1485 COLORREF clrTemp;
1487 clrTemp = infoPtr->clrText;
1488 infoPtr->clrText = (COLORREF)lParam;
1490 TRACE (rebar, "text color 0x%06lx!\n", infoPtr->clrText);
1492 return clrTemp;
1496 /* << REBAR_SetTooltips >> */
1499 inline static LRESULT
1500 REBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1502 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1503 BOOL bTemp = infoPtr->bUnicode;
1504 infoPtr->bUnicode = (BOOL)wParam;
1505 return bTemp;
1509 static LRESULT
1510 REBAR_ShowBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
1512 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1513 REBAR_BAND *lpBand;
1515 if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
1516 return FALSE;
1518 lpBand = &infoPtr->bands[(INT)wParam];
1520 if ((BOOL)lParam) {
1521 TRACE (rebar, "show band %d\n", (INT)wParam);
1522 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
1523 if (IsWindow (lpBand->hwndChild))
1524 ShowWindow (lpBand->hwndChild, SW_SHOW);
1526 else {
1527 TRACE (rebar, "hide band %d\n", (INT)wParam);
1528 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
1529 if (IsWindow (lpBand->hwndChild))
1530 ShowWindow (lpBand->hwndChild, SW_SHOW);
1533 REBAR_Layout (hwnd, NULL);
1534 REBAR_ForceResize (hwnd);
1535 REBAR_MoveChildWindows (hwnd);
1537 return TRUE;
1541 static LRESULT
1542 REBAR_SizeToRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1544 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1545 LPRECT lpRect = (LPRECT)lParam;
1547 if (lpRect == NULL)
1548 return FALSE;
1550 FIXME (rebar, "layout change not implemented!\n");
1551 FIXME (rebar, "[%d %d %d %d]\n",
1552 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
1554 #if 0
1555 SetWindowPos (hwnd, 0, lpRect->left, lpRect->top,
1556 lpRect->right - lpRect->left, lpRect->bottom - lpRect->top,
1557 SWP_NOZORDER);
1558 #endif
1560 infoPtr->calcSize.cx = lpRect->right - lpRect->left;
1561 infoPtr->calcSize.cy = lpRect->bottom - lpRect->top;
1563 REBAR_ForceResize (hwnd);
1564 return TRUE;
1569 static LRESULT
1570 REBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1572 REBAR_INFO *infoPtr;
1574 /* allocate memory for info structure */
1575 infoPtr = (REBAR_INFO *)COMCTL32_Alloc (sizeof(REBAR_INFO));
1576 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1578 /* initialize info structure */
1579 infoPtr->clrBk = CLR_NONE;
1580 infoPtr->clrText = RGB(0, 0, 0);
1582 infoPtr->bAutoResize = FALSE;
1583 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1584 infoPtr->hcurHorz = LoadCursorA (0, IDC_SIZEWEA);
1585 infoPtr->hcurVert = LoadCursorA (0, IDC_SIZENSA);
1586 infoPtr->hcurDrag = LoadCursorA (0, IDC_SIZEA);
1588 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1590 if (GetWindowLongA (hwnd, GWL_STYLE) & RBS_AUTOSIZE)
1591 FIXME (rebar, "style RBS_AUTOSIZE set!\n");
1593 #if 0
1594 SendMessageA (hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1595 #endif
1597 TRACE (rebar, "created!\n");
1598 return 0;
1602 static LRESULT
1603 REBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1605 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1606 REBAR_BAND *lpBand;
1607 INT i;
1610 /* free rebar bands */
1611 if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
1612 /* clean up each band */
1613 for (i = 0; i < infoPtr->uNumBands; i++) {
1614 lpBand = &infoPtr->bands[i];
1616 /* delete text strings */
1617 if (lpBand->lpText) {
1618 COMCTL32_Free (lpBand->lpText);
1619 lpBand->lpText = NULL;
1621 /* destroy child window */
1622 DestroyWindow (lpBand->hwndChild);
1625 /* free band array */
1626 COMCTL32_Free (infoPtr->bands);
1627 infoPtr->bands = NULL;
1633 DeleteObject (infoPtr->hcurArrow);
1634 DeleteObject (infoPtr->hcurHorz);
1635 DeleteObject (infoPtr->hcurVert);
1636 DeleteObject (infoPtr->hcurDrag);
1641 /* free rebar info data */
1642 COMCTL32_Free (infoPtr);
1644 TRACE (rebar, "destroyed!\n");
1645 return 0;
1649 static LRESULT
1650 REBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1652 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1654 return (LRESULT)infoPtr->hFont;
1658 #if 0
1659 static LRESULT
1660 REBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1662 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1664 return 0;
1666 #endif
1669 inline static LRESULT
1670 REBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1672 if (GetWindowLongA (hwnd, GWL_STYLE) & WS_BORDER) {
1673 ((LPRECT)lParam)->left += GetSystemMetrics(SM_CXEDGE);
1674 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
1675 ((LPRECT)lParam)->right -= GetSystemMetrics(SM_CXEDGE);
1676 ((LPRECT)lParam)->bottom -= GetSystemMetrics(SM_CYEDGE);
1679 return 0;
1683 static LRESULT
1684 REBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
1686 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1687 RECT rcWindow;
1688 HDC hdc;
1690 if (dwStyle & WS_MINIMIZE)
1691 return 0; /* Nothing to do */
1693 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
1695 if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW )))
1696 return 0;
1698 if (dwStyle & WS_BORDER) {
1699 GetWindowRect (hwnd, &rcWindow);
1700 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
1701 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
1704 ReleaseDC( hwnd, hdc );
1706 return 0;
1710 static LRESULT
1711 REBAR_Paint (HWND hwnd, WPARAM wParam)
1713 HDC hdc;
1714 PAINTSTRUCT ps;
1716 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1717 REBAR_Refresh (hwnd, hdc);
1718 if (!wParam)
1719 EndPaint (hwnd, &ps);
1720 return 0;
1724 static LRESULT
1725 REBAR_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1727 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1728 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1729 POINT pt;
1730 UINT flags;
1732 TRACE (rebar, "code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1734 GetCursorPos (&pt);
1735 ScreenToClient (hwnd, &pt);
1737 REBAR_InternalHitTest (hwnd, &pt, &flags, NULL);
1739 if (flags == RBHT_GRABBER) {
1740 if ((dwStyle & CCS_VERT) &&
1741 !(dwStyle & RBS_VERTICALGRIPPER))
1742 SetCursor (infoPtr->hcurVert);
1743 else
1744 SetCursor (infoPtr->hcurHorz);
1746 else if (flags != RBHT_CLIENT)
1747 SetCursor (infoPtr->hcurArrow);
1749 return 0;
1753 static LRESULT
1754 REBAR_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1756 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1758 /* TEXTMETRIC32A tm; */
1759 HFONT hFont /*, hOldFont */;
1760 /* HDC32 hdc; */
1762 infoPtr->hFont = (HFONT)wParam;
1764 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1766 hdc = GetDC32 (0);
1767 hOldFont = SelectObject32 (hdc, hFont);
1768 GetTextMetrics32A (hdc, &tm);
1769 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1770 SelectObject32 (hdc, hOldFont);
1771 ReleaseDC32 (0, hdc);
1773 if (lParam) {
1775 REBAR_Layout (hwnd);
1776 hdc = GetDC32 (hwnd);
1777 REBAR_Refresh (hwnd, hdc);
1778 ReleaseDC32 (hwnd, hdc);
1782 return 0;
1785 static LRESULT
1786 REBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1788 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1789 /* DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); */
1790 RECT rcParent;
1791 /* INT32 x, y, cx, cy; */
1793 /* auto resize deadlock check */
1794 if (infoPtr->bAutoResize) {
1795 infoPtr->bAutoResize = FALSE;
1796 return 0;
1799 TRACE (rebar, "sizing rebar!\n");
1801 /* get parent rectangle */
1802 GetClientRect (GetParent (hwnd), &rcParent);
1804 REBAR_Layout (hwnd, &rcParent);
1806 if (dwStyle & CCS_VERT) {
1807 if (dwStyle & CCS_LEFT == CCS_LEFT) {
1808 x = rcParent.left;
1809 y = rcParent.top;
1810 cx = infoPtr->calcSize.cx;
1811 cy = infoPtr->calcSize.cy;
1813 else {
1814 x = rcParent.right - infoPtr->calcSize.cx;
1815 y = rcParent.top;
1816 cx = infoPtr->calcSize.cx;
1817 cy = infoPtr->calcSize.cy;
1820 else {
1821 if (dwStyle & CCS_TOP) {
1822 x = rcParent.left;
1823 y = rcParent.top;
1824 cx = infoPtr->calcSize.cx;
1825 cy = infoPtr->calcSize.cy;
1827 else {
1828 x = rcParent.left;
1829 y = rcParent.bottom - infoPtr->calcSize.cy;
1830 cx = infoPtr->calcSize.cx;
1831 cy = infoPtr->calcSize.cy;
1835 SetWindowPos32 (hwnd, 0, x, y, cx, cy,
1836 SWP_NOZORDER | SWP_SHOWWINDOW);
1838 REBAR_Layout (hwnd, NULL);
1839 REBAR_ForceResize (hwnd);
1840 REBAR_MoveChildWindows (hwnd);
1842 return 0;
1846 LRESULT WINAPI
1847 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1849 switch (uMsg)
1851 /* case RB_BEGINDRAG: */
1853 case RB_DELETEBAND:
1854 return REBAR_DeleteBand (hwnd, wParam, lParam);
1856 /* case RB_DRAGMOVE: */
1857 /* case RB_ENDDRAG: */
1859 case RB_GETBANDBORDERS:
1860 return REBAR_GetBandBorders (hwnd, wParam, lParam);
1862 case RB_GETBANDCOUNT:
1863 return REBAR_GetBandCount (hwnd);
1865 /* case RB_GETBANDINFO32: */ /* outdated, just for compatibility */
1867 case RB_GETBANDINFOA:
1868 return REBAR_GetBandInfoA (hwnd, wParam, lParam);
1870 case RB_GETBANDINFOW:
1871 return REBAR_GetBandInfoW (hwnd, wParam, lParam);
1873 case RB_GETBARHEIGHT:
1874 return REBAR_GetBarHeight (hwnd, wParam, lParam);
1876 case RB_GETBARINFO:
1877 return REBAR_GetBarInfo (hwnd, wParam, lParam);
1879 case RB_GETBKCOLOR:
1880 return REBAR_GetBkColor (hwnd);
1882 /* case RB_GETCOLORSCHEME: */
1883 /* case RB_GETDROPTARGET: */
1885 case RB_GETPALETTE:
1886 return REBAR_GetPalette (hwnd, wParam, lParam);
1888 case RB_GETRECT:
1889 return REBAR_GetRect (hwnd, wParam, lParam);
1891 case RB_GETROWCOUNT:
1892 return REBAR_GetRowCount (hwnd);
1894 case RB_GETROWHEIGHT:
1895 return REBAR_GetRowHeight (hwnd, wParam, lParam);
1897 case RB_GETTEXTCOLOR:
1898 return REBAR_GetTextColor (hwnd);
1900 case RB_GETTOOLTIPS:
1901 return REBAR_GetToolTips (hwnd);
1903 case RB_GETUNICODEFORMAT:
1904 return REBAR_GetUnicodeFormat (hwnd);
1906 case RB_HITTEST:
1907 return REBAR_HitTest (hwnd, wParam, lParam);
1909 case RB_IDTOINDEX:
1910 return REBAR_IdToIndex (hwnd, wParam, lParam);
1912 case RB_INSERTBANDA:
1913 return REBAR_InsertBandA (hwnd, wParam, lParam);
1915 case RB_INSERTBANDW:
1916 return REBAR_InsertBandW (hwnd, wParam, lParam);
1918 case RB_MAXIMIZEBAND:
1919 return REBAR_MaximizeBand (hwnd, wParam, lParam);
1921 case RB_MINIMIZEBAND:
1922 return REBAR_MinimizeBand (hwnd, wParam, lParam);
1924 case RB_MOVEBAND:
1925 return REBAR_MoveBand (hwnd, wParam, lParam);
1927 case RB_SETBANDINFOA:
1928 return REBAR_SetBandInfoA (hwnd, wParam, lParam);
1930 case RB_SETBANDINFOW:
1931 return REBAR_SetBandInfoW (hwnd, wParam, lParam);
1933 case RB_SETBARINFO:
1934 return REBAR_SetBarInfo (hwnd, wParam, lParam);
1936 case RB_SETBKCOLOR:
1937 return REBAR_SetBkColor (hwnd, wParam, lParam);
1939 /* case RB_SETCOLORSCHEME: */
1940 /* case RB_SETPALETTE: */
1941 /* return REBAR_GetPalette (hwnd, wParam, lParam); */
1943 case RB_SETPARENT:
1944 return REBAR_SetParent (hwnd, wParam, lParam);
1946 case RB_SETTEXTCOLOR:
1947 return REBAR_SetTextColor (hwnd, wParam, lParam);
1949 /* case RB_SETTOOLTIPS: */
1951 case RB_SETUNICODEFORMAT:
1952 return REBAR_SetUnicodeFormat (hwnd, wParam);
1954 case RB_SHOWBAND:
1955 return REBAR_ShowBand (hwnd, wParam, lParam);
1957 case RB_SIZETORECT:
1958 return REBAR_SizeToRect (hwnd, wParam, lParam);
1961 case WM_COMMAND:
1962 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
1964 case WM_CREATE:
1965 return REBAR_Create (hwnd, wParam, lParam);
1967 case WM_DESTROY:
1968 return REBAR_Destroy (hwnd, wParam, lParam);
1970 case WM_GETFONT:
1971 return REBAR_GetFont (hwnd, wParam, lParam);
1973 /* case WM_MOUSEMOVE: */
1974 /* return REBAR_MouseMove (hwnd, wParam, lParam); */
1976 case WM_NCCALCSIZE:
1977 return REBAR_NCCalcSize (hwnd, wParam, lParam);
1979 case WM_NCPAINT:
1980 return REBAR_NCPaint (hwnd, wParam, lParam);
1982 case WM_NOTIFY:
1983 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
1985 case WM_PAINT:
1986 return REBAR_Paint (hwnd, wParam);
1988 case WM_SETCURSOR:
1989 return REBAR_SetCursor (hwnd, wParam, lParam);
1991 case WM_SETFONT:
1992 return REBAR_SetFont (hwnd, wParam, lParam);
1994 case WM_SIZE:
1995 return REBAR_Size (hwnd, wParam, lParam);
1997 /* case WM_TIMER: */
1999 /* case WM_WININICHANGE: */
2001 default:
2002 if (uMsg >= WM_USER)
2003 ERR (rebar, "unknown msg %04x wp=%08x lp=%08lx\n",
2004 uMsg, wParam, lParam);
2005 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2007 return 0;
2011 VOID
2012 REBAR_Register (void)
2014 WNDCLASSA wndClass;
2016 if (GlobalFindAtomA (REBARCLASSNAMEA)) return;
2018 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2019 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
2020 wndClass.lpfnWndProc = (WNDPROC)REBAR_WindowProc;
2021 wndClass.cbClsExtra = 0;
2022 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
2023 wndClass.hCursor = 0;
2024 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2025 wndClass.lpszClassName = REBARCLASSNAMEA;
2027 RegisterClassA (&wndClass);
2031 VOID
2032 REBAR_Unregister (void)
2034 if (GlobalFindAtomA (REBARCLASSNAMEA))
2035 UnregisterClassA (REBARCLASSNAMEA, (HINSTANCE)NULL);