Fixed hash function.
[wine/dcerpc.git] / dlls / comctl32 / rebar.c
blob3bf29a8b6475bf011d985b3a023096786291af75
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 "debugtools.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(" 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("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 INT nEditHeight, yPos;
433 RECT rc;
434 HWND hwndEdit;
436 /* special placement code for extended combo box */
438 /* get size of edit line */
439 hwndEdit = SendMessageA (lpBand->hwndChild, CBEM_GETEDITCONTROL, 0, 0);
440 GetWindowRect (hwndEdit, &rc);
441 nEditHeight = rc.bottom - rc.top;
442 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
444 /* center combo box inside child area */
445 SetWindowPos (lpBand->hwndChild, HWND_TOP,
446 lpBand->rcChild.left, /*lpBand->rcChild.top*/ yPos,
447 lpBand->rcChild.right - lpBand->rcChild.left,
448 nEditHeight,
449 SWP_SHOWWINDOW);
452 #endif
453 else {
454 SetWindowPos (lpBand->hwndChild, HWND_TOP,
455 lpBand->rcChild.left, lpBand->rcChild.top,
456 lpBand->rcChild.right - lpBand->rcChild.left,
457 lpBand->rcChild.bottom - lpBand->rcChild.top,
458 SWP_SHOWWINDOW);
465 static void
466 REBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pBand)
468 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
469 REBAR_BAND *lpBand;
470 RECT rect;
471 INT iCount;
473 GetClientRect (hwnd, &rect);
475 *pFlags = RBHT_NOWHERE;
476 if (PtInRect (&rect, *lpPt))
478 if (infoPtr->uNumBands == 0) {
479 *pFlags = RBHT_NOWHERE;
480 if (pBand)
481 *pBand = -1;
482 TRACE("NOWHERE\n");
483 return;
485 else {
486 /* somewhere inside */
487 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
488 lpBand = &infoPtr->bands[iCount];
489 if (PtInRect (&lpBand->rcBand, *lpPt)) {
490 if (pBand)
491 *pBand = iCount;
492 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
493 *pFlags = RBHT_GRABBER;
494 TRACE("ON GRABBER %d\n", iCount);
495 return;
497 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
498 *pFlags = RBHT_CAPTION;
499 TRACE("ON CAPTION %d\n", iCount);
500 return;
502 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
503 *pFlags = RBHT_CAPTION;
504 TRACE("ON CAPTION %d\n", iCount);
505 return;
507 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
508 *pFlags = RBHT_CLIENT;
509 TRACE("ON CLIENT %d\n", iCount);
510 return;
512 else {
513 *pFlags = RBHT_NOWHERE;
514 TRACE("NOWHERE %d\n", iCount);
515 return;
520 *pFlags = RBHT_NOWHERE;
521 if (pBand)
522 *pBand = -1;
524 TRACE("NOWHERE\n");
525 return;
528 else {
529 *pFlags = RBHT_NOWHERE;
530 if (pBand)
531 *pBand = -1;
532 TRACE("NOWHERE\n");
533 return;
536 TRACE("flags=0x%X\n", *pFlags);
537 return;
542 /* << REBAR_BeginDrag >> */
545 static LRESULT
546 REBAR_DeleteBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
548 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
549 UINT uBand = (UINT)wParam;
551 if (uBand >= infoPtr->uNumBands)
552 return FALSE;
554 TRACE("deleting band %u!\n", uBand);
556 if (infoPtr->uNumBands == 1) {
557 TRACE(" simple delete!\n");
558 COMCTL32_Free (infoPtr->bands);
559 infoPtr->bands = NULL;
560 infoPtr->uNumBands = 0;
562 else {
563 REBAR_BAND *oldBands = infoPtr->bands;
564 TRACE("complex delete! [uBand=%u]\n", uBand);
566 infoPtr->uNumBands--;
567 infoPtr->bands = COMCTL32_Alloc (sizeof (REBAR_BAND) * infoPtr->uNumBands);
568 if (uBand > 0) {
569 memcpy (&infoPtr->bands[0], &oldBands[0],
570 uBand * sizeof(REBAR_BAND));
573 if (uBand < infoPtr->uNumBands) {
574 memcpy (&infoPtr->bands[uBand], &oldBands[uBand+1],
575 (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
578 COMCTL32_Free (oldBands);
581 REBAR_Layout (hwnd, NULL);
582 REBAR_ForceResize (hwnd);
583 REBAR_MoveChildWindows (hwnd);
585 return TRUE;
589 /* << REBAR_DragMove >> */
590 /* << REBAR_EndDrag >> */
593 static LRESULT
594 REBAR_GetBandBorders (HWND hwnd, WPARAM wParam, LPARAM lParam)
596 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
597 /* LPRECT32 lpRect = (LPRECT32)lParam; */
598 REBAR_BAND *lpBand;
600 if (!lParam)
601 return 0;
602 if ((UINT)wParam >= infoPtr->uNumBands)
603 return 0;
605 lpBand = &infoPtr->bands[(UINT)wParam];
606 if (GetWindowLongA (hwnd, GWL_STYLE) & RBS_BANDBORDERS) {
609 else {
613 return 0;
617 inline static LRESULT
618 REBAR_GetBandCount (HWND hwnd)
620 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
622 TRACE("band count %u!\n", infoPtr->uNumBands);
624 return infoPtr->uNumBands;
628 static LRESULT
629 REBAR_GetBandInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
631 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
632 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
633 REBAR_BAND *lpBand;
635 if (lprbbi == NULL)
636 return FALSE;
637 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
638 return FALSE;
639 if ((UINT)wParam >= infoPtr->uNumBands)
640 return FALSE;
642 TRACE("index %u\n", (UINT)wParam);
644 /* copy band information */
645 lpBand = &infoPtr->bands[(UINT)wParam];
647 if (lprbbi->fMask & RBBIM_STYLE)
648 lprbbi->fStyle = lpBand->fStyle;
650 if (lprbbi->fMask & RBBIM_COLORS) {
651 lprbbi->clrFore = lpBand->clrFore;
652 lprbbi->clrBack = lpBand->clrBack;
655 if ((lprbbi->fMask & RBBIM_TEXT) &&
656 (lprbbi->lpText) && (lpBand->lpText)) {
657 lstrcpynWtoA (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
660 if (lprbbi->fMask & RBBIM_IMAGE)
661 lprbbi->iImage = lpBand->iImage;
663 if (lprbbi->fMask & RBBIM_CHILD)
664 lprbbi->hwndChild = lpBand->hwndChild;
666 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
667 lprbbi->cxMinChild = lpBand->cxMinChild;
668 lprbbi->cyMinChild = lpBand->cyMinChild;
669 lprbbi->cyMaxChild = lpBand->cyMaxChild;
670 lprbbi->cyChild = lpBand->cyChild;
671 lprbbi->cyIntegral = lpBand->cyIntegral;
674 if (lprbbi->fMask & RBBIM_SIZE)
675 lprbbi->cx = lpBand->cx;
677 if (lprbbi->fMask & RBBIM_BACKGROUND)
678 lprbbi->hbmBack = lpBand->hbmBack;
680 if (lprbbi->fMask & RBBIM_ID)
681 lprbbi->wID = lpBand->wID;
683 /* check for additional data */
684 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
685 if (lprbbi->fMask & RBBIM_IDEALSIZE)
686 lprbbi->cxIdeal = lpBand->cxIdeal;
688 if (lprbbi->fMask & RBBIM_LPARAM)
689 lprbbi->lParam = lpBand->lParam;
691 if (lprbbi->fMask & RBBIM_HEADERSIZE)
692 lprbbi->cxHeader = lpBand->cxHeader;
695 return TRUE;
699 static LRESULT
700 REBAR_GetBandInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
702 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
703 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
704 REBAR_BAND *lpBand;
706 if (lprbbi == NULL)
707 return FALSE;
708 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
709 return FALSE;
710 if ((UINT)wParam >= infoPtr->uNumBands)
711 return FALSE;
713 TRACE("index %u\n", (UINT)wParam);
715 /* copy band information */
716 lpBand = &infoPtr->bands[(UINT)wParam];
718 if (lprbbi->fMask & RBBIM_STYLE)
719 lprbbi->fStyle = lpBand->fStyle;
721 if (lprbbi->fMask & RBBIM_COLORS) {
722 lprbbi->clrFore = lpBand->clrFore;
723 lprbbi->clrBack = lpBand->clrBack;
726 if ((lprbbi->fMask & RBBIM_TEXT) &&
727 (lprbbi->lpText) && (lpBand->lpText)) {
728 lstrcpynW (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
731 if (lprbbi->fMask & RBBIM_IMAGE)
732 lprbbi->iImage = lpBand->iImage;
734 if (lprbbi->fMask & RBBIM_CHILD)
735 lprbbi->hwndChild = lpBand->hwndChild;
737 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
738 lprbbi->cxMinChild = lpBand->cxMinChild;
739 lprbbi->cyMinChild = lpBand->cyMinChild;
740 lprbbi->cyMaxChild = lpBand->cyMaxChild;
741 lprbbi->cyChild = lpBand->cyChild;
742 lprbbi->cyIntegral = lpBand->cyIntegral;
745 if (lprbbi->fMask & RBBIM_SIZE)
746 lprbbi->cx = lpBand->cx;
748 if (lprbbi->fMask & RBBIM_BACKGROUND)
749 lprbbi->hbmBack = lpBand->hbmBack;
751 if (lprbbi->fMask & RBBIM_ID)
752 lprbbi->wID = lpBand->wID;
754 /* check for additional data */
755 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
756 if (lprbbi->fMask & RBBIM_IDEALSIZE)
757 lprbbi->cxIdeal = lpBand->cxIdeal;
759 if (lprbbi->fMask & RBBIM_LPARAM)
760 lprbbi->lParam = lpBand->lParam;
762 if (lprbbi->fMask & RBBIM_HEADERSIZE)
763 lprbbi->cxHeader = lpBand->cxHeader;
766 return TRUE;
770 static LRESULT
771 REBAR_GetBarHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
773 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
774 INT nHeight;
776 REBAR_Layout (hwnd, NULL);
777 nHeight = infoPtr->calcSize.cy;
779 if (GetWindowLongA (hwnd, GWL_STYLE) & WS_BORDER)
780 nHeight += (2 * GetSystemMetrics(SM_CYEDGE));
783 FIXME("height = %d\n", nHeight);
785 return nHeight;
789 static LRESULT
790 REBAR_GetBarInfo (HWND hwnd, WPARAM wParam, LPARAM lParam)
792 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
793 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
795 if (lpInfo == NULL)
796 return FALSE;
798 if (lpInfo->cbSize < sizeof (REBARINFO))
799 return FALSE;
801 TRACE("getting bar info!\n");
803 if (infoPtr->himl) {
804 lpInfo->himl = infoPtr->himl;
805 lpInfo->fMask |= RBIM_IMAGELIST;
808 return TRUE;
812 inline static LRESULT
813 REBAR_GetBkColor (HWND hwnd)
815 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
817 TRACE("background color 0x%06lx!\n", infoPtr->clrBk);
819 return infoPtr->clrBk;
823 /* << REBAR_GetColorScheme >> */
824 /* << REBAR_GetDropTarget >> */
827 static LRESULT
828 REBAR_GetPalette (HWND hwnd, WPARAM wParam, LPARAM lParam)
830 FIXME("empty stub!\n");
832 return 0;
836 static LRESULT
837 REBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
839 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
840 INT iBand = (INT)wParam;
841 LPRECT lprc = (LPRECT)lParam;
842 REBAR_BAND *lpBand;
844 if ((iBand < 0) && ((UINT)iBand >= infoPtr->uNumBands))
845 return FALSE;
846 if (!lprc)
847 return FALSE;
849 TRACE("band %d\n", iBand);
851 lpBand = &infoPtr->bands[iBand];
852 CopyRect (lprc, &lpBand->rcBand);
854 lprc->left = lpBand->rcBand.left;
855 lprc->top = lpBand->rcBand.top;
856 lprc->right = lpBand->rcBand.right;
857 lprc->bottom = lpBand->rcBand.bottom;
860 return TRUE;
864 inline static LRESULT
865 REBAR_GetRowCount (HWND hwnd)
867 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
869 FIXME("%u : semi stub!\n", infoPtr->uNumBands);
871 return infoPtr->uNumBands;
875 static LRESULT
876 REBAR_GetRowHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
878 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
880 FIXME("-- height = 20: semi stub!\n");
882 return 20;
886 inline static LRESULT
887 REBAR_GetTextColor (HWND hwnd)
889 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
891 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
893 return infoPtr->clrText;
897 inline static LRESULT
898 REBAR_GetToolTips (HWND hwnd)
900 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
901 return infoPtr->hwndToolTip;
905 inline static LRESULT
906 REBAR_GetUnicodeFormat (HWND hwnd)
908 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
909 return infoPtr->bUnicode;
913 static LRESULT
914 REBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
916 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
917 LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
919 if (!lprbht)
920 return -1;
922 REBAR_InternalHitTest (hwnd, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
924 return lprbht->iBand;
928 static LRESULT
929 REBAR_IdToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
931 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
932 UINT i;
934 if (infoPtr == NULL)
935 return -1;
937 if (infoPtr->uNumBands < 1)
938 return -1;
940 TRACE("id %u\n", (UINT)wParam);
942 for (i = 0; i < infoPtr->uNumBands; i++) {
943 if (infoPtr->bands[i].wID == (UINT)wParam) {
944 TRACE("band %u found!\n", i);
945 return i;
949 TRACE("no band found!\n");
950 return -1;
954 static LRESULT
955 REBAR_InsertBandA (HWND hwnd, WPARAM wParam, LPARAM lParam)
957 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
958 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
959 UINT uIndex = (UINT)wParam;
960 REBAR_BAND *lpBand;
962 if (infoPtr == NULL)
963 return FALSE;
964 if (lprbbi == NULL)
965 return FALSE;
966 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
967 return FALSE;
969 TRACE("insert band at %u!\n", uIndex);
971 if (infoPtr->uNumBands == 0) {
972 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
973 uIndex = 0;
975 else {
976 REBAR_BAND *oldBands = infoPtr->bands;
977 infoPtr->bands =
978 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
979 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
980 uIndex = infoPtr->uNumBands;
982 /* pre insert copy */
983 if (uIndex > 0) {
984 memcpy (&infoPtr->bands[0], &oldBands[0],
985 uIndex * sizeof(REBAR_BAND));
988 /* post copy */
989 if (uIndex < infoPtr->uNumBands - 1) {
990 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
991 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
994 COMCTL32_Free (oldBands);
997 infoPtr->uNumBands++;
999 TRACE("index %u!\n", uIndex);
1001 /* initialize band (infoPtr->bands[uIndex])*/
1002 lpBand = &infoPtr->bands[uIndex];
1004 if (lprbbi->fMask & RBBIM_STYLE)
1005 lpBand->fStyle = lprbbi->fStyle;
1007 if (lprbbi->fMask & RBBIM_COLORS) {
1008 lpBand->clrFore = lprbbi->clrFore;
1009 lpBand->clrBack = lprbbi->clrBack;
1011 else {
1012 lpBand->clrFore = CLR_NONE;
1013 lpBand->clrBack = CLR_NONE;
1016 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
1017 INT len = lstrlenA (lprbbi->lpText);
1018 if (len > 0) {
1019 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1020 lstrcpyAtoW (lpBand->lpText, lprbbi->lpText);
1024 if (lprbbi->fMask & RBBIM_IMAGE)
1025 lpBand->iImage = lprbbi->iImage;
1026 else
1027 lpBand->iImage = -1;
1029 if (lprbbi->fMask & RBBIM_CHILD) {
1030 TRACE("hwndChild = %x\n", lprbbi->hwndChild);
1031 lpBand->hwndChild = lprbbi->hwndChild;
1032 lpBand->hwndPrevParent =
1033 SetParent (lpBand->hwndChild, hwnd);
1036 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
1037 lpBand->cxMinChild = lprbbi->cxMinChild;
1038 lpBand->cyMinChild = lprbbi->cyMinChild;
1039 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1040 lpBand->cyChild = lprbbi->cyChild;
1041 lpBand->cyIntegral = lprbbi->cyIntegral;
1043 else {
1044 lpBand->cxMinChild = -1;
1045 lpBand->cyMinChild = -1;
1046 lpBand->cyMaxChild = -1;
1047 lpBand->cyChild = -1;
1048 lpBand->cyIntegral = -1;
1051 if (lprbbi->fMask & RBBIM_SIZE)
1052 lpBand->cx = lprbbi->cx;
1053 else
1054 lpBand->cx = -1;
1056 if (lprbbi->fMask & RBBIM_BACKGROUND)
1057 lpBand->hbmBack = lprbbi->hbmBack;
1059 if (lprbbi->fMask & RBBIM_ID)
1060 lpBand->wID = lprbbi->wID;
1062 /* check for additional data */
1063 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
1064 if (lprbbi->fMask & RBBIM_IDEALSIZE)
1065 lpBand->cxIdeal = lprbbi->cxIdeal;
1067 if (lprbbi->fMask & RBBIM_LPARAM)
1068 lpBand->lParam = lprbbi->lParam;
1070 if (lprbbi->fMask & RBBIM_HEADERSIZE)
1071 lpBand->cxHeader = lprbbi->cxHeader;
1075 REBAR_Layout (hwnd, NULL);
1076 REBAR_ForceResize (hwnd);
1077 REBAR_MoveChildWindows (hwnd);
1079 return TRUE;
1083 static LRESULT
1084 REBAR_InsertBandW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1086 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1087 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
1088 UINT uIndex = (UINT)wParam;
1089 REBAR_BAND *lpBand;
1091 if (infoPtr == NULL)
1092 return FALSE;
1093 if (lprbbi == NULL)
1094 return FALSE;
1095 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
1096 return FALSE;
1098 TRACE("insert band at %u!\n", uIndex);
1100 if (infoPtr->uNumBands == 0) {
1101 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
1102 uIndex = 0;
1104 else {
1105 REBAR_BAND *oldBands = infoPtr->bands;
1106 infoPtr->bands =
1107 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
1108 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
1109 uIndex = infoPtr->uNumBands;
1111 /* pre insert copy */
1112 if (uIndex > 0) {
1113 memcpy (&infoPtr->bands[0], &oldBands[0],
1114 uIndex * sizeof(REBAR_BAND));
1117 /* post copy */
1118 if (uIndex < infoPtr->uNumBands - 1) {
1119 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
1120 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
1123 COMCTL32_Free (oldBands);
1126 infoPtr->uNumBands++;
1128 TRACE("index %u!\n", uIndex);
1130 /* initialize band (infoPtr->bands[uIndex])*/
1131 lpBand = &infoPtr->bands[uIndex];
1133 if (lprbbi->fMask & RBBIM_STYLE)
1134 lpBand->fStyle = lprbbi->fStyle;
1136 if (lprbbi->fMask & RBBIM_COLORS) {
1137 lpBand->clrFore = lprbbi->clrFore;
1138 lpBand->clrBack = lprbbi->clrBack;
1140 else {
1141 lpBand->clrFore = CLR_NONE;
1142 lpBand->clrBack = CLR_NONE;
1145 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
1146 INT len = lstrlenW (lprbbi->lpText);
1147 if (len > 0) {
1148 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1149 lstrcpyW (lpBand->lpText, lprbbi->lpText);
1153 if (lprbbi->fMask & RBBIM_IMAGE)
1154 lpBand->iImage = lprbbi->iImage;
1155 else
1156 lpBand->iImage = -1;
1158 if (lprbbi->fMask & RBBIM_CHILD) {
1159 TRACE("hwndChild = %x\n", lprbbi->hwndChild);
1160 lpBand->hwndChild = lprbbi->hwndChild;
1161 lpBand->hwndPrevParent =
1162 SetParent (lpBand->hwndChild, hwnd);
1165 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
1166 lpBand->cxMinChild = lprbbi->cxMinChild;
1167 lpBand->cyMinChild = lprbbi->cyMinChild;
1168 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1169 lpBand->cyChild = lprbbi->cyChild;
1170 lpBand->cyIntegral = lprbbi->cyIntegral;
1172 else {
1173 lpBand->cxMinChild = -1;
1174 lpBand->cyMinChild = -1;
1175 lpBand->cyMaxChild = -1;
1176 lpBand->cyChild = -1;
1177 lpBand->cyIntegral = -1;
1180 if (lprbbi->fMask & RBBIM_SIZE)
1181 lpBand->cx = lprbbi->cx;
1182 else
1183 lpBand->cx = -1;
1185 if (lprbbi->fMask & RBBIM_BACKGROUND)
1186 lpBand->hbmBack = lprbbi->hbmBack;
1188 if (lprbbi->fMask & RBBIM_ID)
1189 lpBand->wID = lprbbi->wID;
1191 /* check for additional data */
1192 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
1193 if (lprbbi->fMask & RBBIM_IDEALSIZE)
1194 lpBand->cxIdeal = lprbbi->cxIdeal;
1196 if (lprbbi->fMask & RBBIM_LPARAM)
1197 lpBand->lParam = lprbbi->lParam;
1199 if (lprbbi->fMask & RBBIM_HEADERSIZE)
1200 lpBand->cxHeader = lprbbi->cxHeader;
1204 REBAR_Layout (hwnd, NULL);
1205 REBAR_ForceResize (hwnd);
1206 REBAR_MoveChildWindows (hwnd);
1208 return TRUE;
1212 static LRESULT
1213 REBAR_MaximizeBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
1215 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
1217 FIXME("(uBand = %u fIdeal = %s)\n",
1218 (UINT)wParam, lParam ? "TRUE" : "FALSE");
1221 return 0;
1225 static LRESULT
1226 REBAR_MinimizeBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
1228 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
1230 FIXME("(uBand = %u)\n", (UINT)wParam);
1233 return 0;
1237 static LRESULT
1238 REBAR_MoveBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
1240 /* REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd); */
1242 FIXME("(iFrom = %u iTof = %u)\n",
1243 (UINT)wParam, (UINT)lParam);
1246 return FALSE;
1250 static LRESULT
1251 REBAR_SetBandInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1253 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1254 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
1255 REBAR_BAND *lpBand;
1257 if (lprbbi == NULL)
1258 return FALSE;
1259 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
1260 return FALSE;
1261 if ((UINT)wParam >= infoPtr->uNumBands)
1262 return FALSE;
1264 TRACE("index %u\n", (UINT)wParam);
1266 /* set band information */
1267 lpBand = &infoPtr->bands[(UINT)wParam];
1269 if (lprbbi->fMask & RBBIM_STYLE)
1270 lpBand->fStyle = lprbbi->fStyle;
1272 if (lprbbi->fMask & RBBIM_COLORS) {
1273 lpBand->clrFore = lprbbi->clrFore;
1274 lpBand->clrBack = lprbbi->clrBack;
1277 if (lprbbi->fMask & RBBIM_TEXT) {
1278 if (lpBand->lpText) {
1279 COMCTL32_Free (lpBand->lpText);
1280 lpBand->lpText = NULL;
1282 if (lprbbi->lpText) {
1283 INT len = lstrlenA (lprbbi->lpText);
1284 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1285 lstrcpyAtoW (lpBand->lpText, lprbbi->lpText);
1289 if (lprbbi->fMask & RBBIM_IMAGE)
1290 lpBand->iImage = lprbbi->iImage;
1292 if (lprbbi->fMask & RBBIM_CHILD) {
1293 if (lprbbi->hwndChild) {
1294 lpBand->hwndChild = lprbbi->hwndChild;
1295 lpBand->hwndPrevParent =
1296 SetParent (lpBand->hwndChild, hwnd);
1298 else {
1299 TRACE("child: 0x%x prev parent: 0x%x\n",
1300 lpBand->hwndChild, lpBand->hwndPrevParent);
1301 lpBand->hwndChild = 0;
1302 lpBand->hwndPrevParent = 0;
1306 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
1307 lpBand->cxMinChild = lprbbi->cxMinChild;
1308 lpBand->cyMinChild = lprbbi->cyMinChild;
1309 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1310 lpBand->cyChild = lprbbi->cyChild;
1311 lpBand->cyIntegral = lprbbi->cyIntegral;
1314 if (lprbbi->fMask & RBBIM_SIZE)
1315 lpBand->cx = lprbbi->cx;
1317 if (lprbbi->fMask & RBBIM_BACKGROUND)
1318 lpBand->hbmBack = lprbbi->hbmBack;
1320 if (lprbbi->fMask & RBBIM_ID)
1321 lpBand->wID = lprbbi->wID;
1323 /* check for additional data */
1324 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
1325 if (lprbbi->fMask & RBBIM_IDEALSIZE)
1326 lpBand->cxIdeal = lprbbi->cxIdeal;
1328 if (lprbbi->fMask & RBBIM_LPARAM)
1329 lpBand->lParam = lprbbi->lParam;
1331 if (lprbbi->fMask & RBBIM_HEADERSIZE)
1332 lpBand->cxHeader = lprbbi->cxHeader;
1335 REBAR_Layout (hwnd, NULL);
1336 REBAR_ForceResize (hwnd);
1337 REBAR_MoveChildWindows (hwnd);
1339 return TRUE;
1343 static LRESULT
1344 REBAR_SetBandInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1346 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1347 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
1348 REBAR_BAND *lpBand;
1350 if (lprbbi == NULL)
1351 return FALSE;
1352 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
1353 return FALSE;
1354 if ((UINT)wParam >= infoPtr->uNumBands)
1355 return FALSE;
1357 TRACE("index %u\n", (UINT)wParam);
1359 /* set band information */
1360 lpBand = &infoPtr->bands[(UINT)wParam];
1362 if (lprbbi->fMask & RBBIM_STYLE)
1363 lpBand->fStyle = lprbbi->fStyle;
1365 if (lprbbi->fMask & RBBIM_COLORS) {
1366 lpBand->clrFore = lprbbi->clrFore;
1367 lpBand->clrBack = lprbbi->clrBack;
1370 if (lprbbi->fMask & RBBIM_TEXT) {
1371 if (lpBand->lpText) {
1372 COMCTL32_Free (lpBand->lpText);
1373 lpBand->lpText = NULL;
1375 if (lprbbi->lpText) {
1376 INT len = lstrlenW (lprbbi->lpText);
1377 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1378 lstrcpyW (lpBand->lpText, lprbbi->lpText);
1382 if (lprbbi->fMask & RBBIM_IMAGE)
1383 lpBand->iImage = lprbbi->iImage;
1385 if (lprbbi->fMask & RBBIM_CHILD) {
1386 if (lprbbi->hwndChild) {
1387 lpBand->hwndChild = lprbbi->hwndChild;
1388 lpBand->hwndPrevParent =
1389 SetParent (lpBand->hwndChild, hwnd);
1391 else {
1392 TRACE("child: 0x%x prev parent: 0x%x\n",
1393 lpBand->hwndChild, lpBand->hwndPrevParent);
1394 lpBand->hwndChild = 0;
1395 lpBand->hwndPrevParent = 0;
1399 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
1400 lpBand->cxMinChild = lprbbi->cxMinChild;
1401 lpBand->cyMinChild = lprbbi->cyMinChild;
1402 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1403 lpBand->cyChild = lprbbi->cyChild;
1404 lpBand->cyIntegral = lprbbi->cyIntegral;
1407 if (lprbbi->fMask & RBBIM_SIZE)
1408 lpBand->cx = lprbbi->cx;
1410 if (lprbbi->fMask & RBBIM_BACKGROUND)
1411 lpBand->hbmBack = lprbbi->hbmBack;
1413 if (lprbbi->fMask & RBBIM_ID)
1414 lpBand->wID = lprbbi->wID;
1416 /* check for additional data */
1417 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
1418 if (lprbbi->fMask & RBBIM_IDEALSIZE)
1419 lpBand->cxIdeal = lprbbi->cxIdeal;
1421 if (lprbbi->fMask & RBBIM_LPARAM)
1422 lpBand->lParam = lprbbi->lParam;
1424 if (lprbbi->fMask & RBBIM_HEADERSIZE)
1425 lpBand->cxHeader = lprbbi->cxHeader;
1428 REBAR_Layout (hwnd, NULL);
1429 REBAR_ForceResize (hwnd);
1430 REBAR_MoveChildWindows (hwnd);
1432 return TRUE;
1436 static LRESULT
1437 REBAR_SetBarInfo (HWND hwnd, WPARAM wParam, LPARAM lParam)
1439 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1440 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
1442 if (lpInfo == NULL)
1443 return FALSE;
1445 if (lpInfo->cbSize < sizeof (REBARINFO))
1446 return FALSE;
1448 TRACE("setting bar info!\n");
1450 if (lpInfo->fMask & RBIM_IMAGELIST) {
1451 infoPtr->himl = lpInfo->himl;
1452 if (infoPtr->himl) {
1453 ImageList_GetIconSize (infoPtr->himl, &infoPtr->imageSize.cx,
1454 &infoPtr->imageSize.cy);
1456 else {
1457 infoPtr->imageSize.cx = 0;
1458 infoPtr->imageSize.cy = 0;
1462 return TRUE;
1466 static LRESULT
1467 REBAR_SetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1469 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1470 COLORREF clrTemp;
1472 clrTemp = infoPtr->clrBk;
1473 infoPtr->clrBk = (COLORREF)lParam;
1475 TRACE("background color 0x%06lx!\n", infoPtr->clrBk);
1477 return clrTemp;
1481 /* << REBAR_SetColorScheme >> */
1482 /* << REBAR_SetPalette >> */
1485 static LRESULT
1486 REBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1488 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1489 HWND hwndTemp = infoPtr->hwndNotify;
1491 infoPtr->hwndNotify = (HWND)wParam;
1493 return (LRESULT)hwndTemp;
1497 static LRESULT
1498 REBAR_SetTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1500 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1501 COLORREF clrTemp;
1503 clrTemp = infoPtr->clrText;
1504 infoPtr->clrText = (COLORREF)lParam;
1506 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
1508 return clrTemp;
1512 /* << REBAR_SetTooltips >> */
1515 inline static LRESULT
1516 REBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1518 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1519 BOOL bTemp = infoPtr->bUnicode;
1520 infoPtr->bUnicode = (BOOL)wParam;
1521 return bTemp;
1525 static LRESULT
1526 REBAR_ShowBand (HWND hwnd, WPARAM wParam, LPARAM lParam)
1528 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1529 REBAR_BAND *lpBand;
1531 if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
1532 return FALSE;
1534 lpBand = &infoPtr->bands[(INT)wParam];
1536 if ((BOOL)lParam) {
1537 TRACE("show band %d\n", (INT)wParam);
1538 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
1539 if (IsWindow (lpBand->hwndChild))
1540 ShowWindow (lpBand->hwndChild, SW_SHOW);
1542 else {
1543 TRACE("hide band %d\n", (INT)wParam);
1544 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
1545 if (IsWindow (lpBand->hwndChild))
1546 ShowWindow (lpBand->hwndChild, SW_SHOW);
1549 REBAR_Layout (hwnd, NULL);
1550 REBAR_ForceResize (hwnd);
1551 REBAR_MoveChildWindows (hwnd);
1553 return TRUE;
1557 static LRESULT
1558 REBAR_SizeToRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1560 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1561 LPRECT lpRect = (LPRECT)lParam;
1563 if (lpRect == NULL)
1564 return FALSE;
1566 FIXME("layout change not implemented!\n");
1567 FIXME("[%d %d %d %d]\n",
1568 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
1570 #if 0
1571 SetWindowPos (hwnd, 0, lpRect->left, lpRect->top,
1572 lpRect->right - lpRect->left, lpRect->bottom - lpRect->top,
1573 SWP_NOZORDER);
1574 #endif
1576 infoPtr->calcSize.cx = lpRect->right - lpRect->left;
1577 infoPtr->calcSize.cy = lpRect->bottom - lpRect->top;
1579 REBAR_ForceResize (hwnd);
1580 return TRUE;
1585 static LRESULT
1586 REBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1588 REBAR_INFO *infoPtr;
1590 /* allocate memory for info structure */
1591 infoPtr = (REBAR_INFO *)COMCTL32_Alloc (sizeof(REBAR_INFO));
1592 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1594 /* initialize info structure */
1595 infoPtr->clrBk = CLR_NONE;
1596 infoPtr->clrText = RGB(0, 0, 0);
1598 infoPtr->bAutoResize = FALSE;
1599 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1600 infoPtr->hcurHorz = LoadCursorA (0, IDC_SIZEWEA);
1601 infoPtr->hcurVert = LoadCursorA (0, IDC_SIZENSA);
1602 infoPtr->hcurDrag = LoadCursorA (0, IDC_SIZEA);
1604 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1606 if (GetWindowLongA (hwnd, GWL_STYLE) & RBS_AUTOSIZE)
1607 FIXME("style RBS_AUTOSIZE set!\n");
1609 #if 0
1610 SendMessageA (hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1611 #endif
1613 TRACE("created!\n");
1614 return 0;
1618 static LRESULT
1619 REBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1621 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1622 REBAR_BAND *lpBand;
1623 INT i;
1626 /* free rebar bands */
1627 if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
1628 /* clean up each band */
1629 for (i = 0; i < infoPtr->uNumBands; i++) {
1630 lpBand = &infoPtr->bands[i];
1632 /* delete text strings */
1633 if (lpBand->lpText) {
1634 COMCTL32_Free (lpBand->lpText);
1635 lpBand->lpText = NULL;
1637 /* destroy child window */
1638 DestroyWindow (lpBand->hwndChild);
1641 /* free band array */
1642 COMCTL32_Free (infoPtr->bands);
1643 infoPtr->bands = NULL;
1649 DeleteObject (infoPtr->hcurArrow);
1650 DeleteObject (infoPtr->hcurHorz);
1651 DeleteObject (infoPtr->hcurVert);
1652 DeleteObject (infoPtr->hcurDrag);
1657 /* free rebar info data */
1658 COMCTL32_Free (infoPtr);
1660 TRACE("destroyed!\n");
1661 return 0;
1665 static LRESULT
1666 REBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1668 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1670 return (LRESULT)infoPtr->hFont;
1674 #if 0
1675 static LRESULT
1676 REBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1678 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1680 return 0;
1682 #endif
1685 inline static LRESULT
1686 REBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1688 if (GetWindowLongA (hwnd, GWL_STYLE) & WS_BORDER) {
1689 ((LPRECT)lParam)->left += GetSystemMetrics(SM_CXEDGE);
1690 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
1691 ((LPRECT)lParam)->right -= GetSystemMetrics(SM_CXEDGE);
1692 ((LPRECT)lParam)->bottom -= GetSystemMetrics(SM_CYEDGE);
1695 return 0;
1699 static LRESULT
1700 REBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
1702 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1703 RECT rcWindow;
1704 HDC hdc;
1706 if (dwStyle & WS_MINIMIZE)
1707 return 0; /* Nothing to do */
1709 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
1711 if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW )))
1712 return 0;
1714 if (dwStyle & WS_BORDER) {
1715 GetWindowRect (hwnd, &rcWindow);
1716 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
1717 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
1720 ReleaseDC( hwnd, hdc );
1722 return 0;
1726 static LRESULT
1727 REBAR_Paint (HWND hwnd, WPARAM wParam)
1729 HDC hdc;
1730 PAINTSTRUCT ps;
1732 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1733 REBAR_Refresh (hwnd, hdc);
1734 if (!wParam)
1735 EndPaint (hwnd, &ps);
1736 return 0;
1740 static LRESULT
1741 REBAR_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1743 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1744 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1745 POINT pt;
1746 UINT flags;
1748 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1750 GetCursorPos (&pt);
1751 ScreenToClient (hwnd, &pt);
1753 REBAR_InternalHitTest (hwnd, &pt, &flags, NULL);
1755 if (flags == RBHT_GRABBER) {
1756 if ((dwStyle & CCS_VERT) &&
1757 !(dwStyle & RBS_VERTICALGRIPPER))
1758 SetCursor (infoPtr->hcurVert);
1759 else
1760 SetCursor (infoPtr->hcurHorz);
1762 else if (flags != RBHT_CLIENT)
1763 SetCursor (infoPtr->hcurArrow);
1765 return 0;
1769 static LRESULT
1770 REBAR_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1772 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1774 /* TEXTMETRIC32A tm; */
1775 HFONT hFont /*, hOldFont */;
1776 /* HDC32 hdc; */
1778 infoPtr->hFont = (HFONT)wParam;
1780 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1782 hdc = GetDC32 (0);
1783 hOldFont = SelectObject32 (hdc, hFont);
1784 GetTextMetrics32A (hdc, &tm);
1785 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1786 SelectObject32 (hdc, hOldFont);
1787 ReleaseDC32 (0, hdc);
1789 if (lParam) {
1791 REBAR_Layout (hwnd);
1792 hdc = GetDC32 (hwnd);
1793 REBAR_Refresh (hwnd, hdc);
1794 ReleaseDC32 (hwnd, hdc);
1798 return 0;
1801 static LRESULT
1802 REBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1804 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
1805 /* DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); */
1806 RECT rcParent;
1807 /* INT32 x, y, cx, cy; */
1809 /* auto resize deadlock check */
1810 if (infoPtr->bAutoResize) {
1811 infoPtr->bAutoResize = FALSE;
1812 return 0;
1815 TRACE("sizing rebar!\n");
1817 /* get parent rectangle */
1818 GetClientRect (GetParent (hwnd), &rcParent);
1820 REBAR_Layout (hwnd, &rcParent);
1822 if (dwStyle & CCS_VERT) {
1823 if (dwStyle & CCS_LEFT == CCS_LEFT) {
1824 x = rcParent.left;
1825 y = rcParent.top;
1826 cx = infoPtr->calcSize.cx;
1827 cy = infoPtr->calcSize.cy;
1829 else {
1830 x = rcParent.right - infoPtr->calcSize.cx;
1831 y = rcParent.top;
1832 cx = infoPtr->calcSize.cx;
1833 cy = infoPtr->calcSize.cy;
1836 else {
1837 if (dwStyle & CCS_TOP) {
1838 x = rcParent.left;
1839 y = rcParent.top;
1840 cx = infoPtr->calcSize.cx;
1841 cy = infoPtr->calcSize.cy;
1843 else {
1844 x = rcParent.left;
1845 y = rcParent.bottom - infoPtr->calcSize.cy;
1846 cx = infoPtr->calcSize.cx;
1847 cy = infoPtr->calcSize.cy;
1851 SetWindowPos32 (hwnd, 0, x, y, cx, cy,
1852 SWP_NOZORDER | SWP_SHOWWINDOW);
1854 REBAR_Layout (hwnd, NULL);
1855 REBAR_ForceResize (hwnd);
1856 REBAR_MoveChildWindows (hwnd);
1858 return 0;
1862 static LRESULT WINAPI
1863 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1865 switch (uMsg)
1867 /* case RB_BEGINDRAG: */
1869 case RB_DELETEBAND:
1870 return REBAR_DeleteBand (hwnd, wParam, lParam);
1872 /* case RB_DRAGMOVE: */
1873 /* case RB_ENDDRAG: */
1875 case RB_GETBANDBORDERS:
1876 return REBAR_GetBandBorders (hwnd, wParam, lParam);
1878 case RB_GETBANDCOUNT:
1879 return REBAR_GetBandCount (hwnd);
1881 /* case RB_GETBANDINFO32: */ /* outdated, just for compatibility */
1883 case RB_GETBANDINFOA:
1884 return REBAR_GetBandInfoA (hwnd, wParam, lParam);
1886 case RB_GETBANDINFOW:
1887 return REBAR_GetBandInfoW (hwnd, wParam, lParam);
1889 case RB_GETBARHEIGHT:
1890 return REBAR_GetBarHeight (hwnd, wParam, lParam);
1892 case RB_GETBARINFO:
1893 return REBAR_GetBarInfo (hwnd, wParam, lParam);
1895 case RB_GETBKCOLOR:
1896 return REBAR_GetBkColor (hwnd);
1898 /* case RB_GETCOLORSCHEME: */
1899 /* case RB_GETDROPTARGET: */
1901 case RB_GETPALETTE:
1902 return REBAR_GetPalette (hwnd, wParam, lParam);
1904 case RB_GETRECT:
1905 return REBAR_GetRect (hwnd, wParam, lParam);
1907 case RB_GETROWCOUNT:
1908 return REBAR_GetRowCount (hwnd);
1910 case RB_GETROWHEIGHT:
1911 return REBAR_GetRowHeight (hwnd, wParam, lParam);
1913 case RB_GETTEXTCOLOR:
1914 return REBAR_GetTextColor (hwnd);
1916 case RB_GETTOOLTIPS:
1917 return REBAR_GetToolTips (hwnd);
1919 case RB_GETUNICODEFORMAT:
1920 return REBAR_GetUnicodeFormat (hwnd);
1922 case RB_HITTEST:
1923 return REBAR_HitTest (hwnd, wParam, lParam);
1925 case RB_IDTOINDEX:
1926 return REBAR_IdToIndex (hwnd, wParam, lParam);
1928 case RB_INSERTBANDA:
1929 return REBAR_InsertBandA (hwnd, wParam, lParam);
1931 case RB_INSERTBANDW:
1932 return REBAR_InsertBandW (hwnd, wParam, lParam);
1934 case RB_MAXIMIZEBAND:
1935 return REBAR_MaximizeBand (hwnd, wParam, lParam);
1937 case RB_MINIMIZEBAND:
1938 return REBAR_MinimizeBand (hwnd, wParam, lParam);
1940 case RB_MOVEBAND:
1941 return REBAR_MoveBand (hwnd, wParam, lParam);
1943 case RB_SETBANDINFOA:
1944 return REBAR_SetBandInfoA (hwnd, wParam, lParam);
1946 case RB_SETBANDINFOW:
1947 return REBAR_SetBandInfoW (hwnd, wParam, lParam);
1949 case RB_SETBARINFO:
1950 return REBAR_SetBarInfo (hwnd, wParam, lParam);
1952 case RB_SETBKCOLOR:
1953 return REBAR_SetBkColor (hwnd, wParam, lParam);
1955 /* case RB_SETCOLORSCHEME: */
1956 /* case RB_SETPALETTE: */
1957 /* return REBAR_GetPalette (hwnd, wParam, lParam); */
1959 case RB_SETPARENT:
1960 return REBAR_SetParent (hwnd, wParam, lParam);
1962 case RB_SETTEXTCOLOR:
1963 return REBAR_SetTextColor (hwnd, wParam, lParam);
1965 /* case RB_SETTOOLTIPS: */
1967 case RB_SETUNICODEFORMAT:
1968 return REBAR_SetUnicodeFormat (hwnd, wParam);
1970 case RB_SHOWBAND:
1971 return REBAR_ShowBand (hwnd, wParam, lParam);
1973 case RB_SIZETORECT:
1974 return REBAR_SizeToRect (hwnd, wParam, lParam);
1977 case WM_COMMAND:
1978 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
1980 case WM_CREATE:
1981 return REBAR_Create (hwnd, wParam, lParam);
1983 case WM_DESTROY:
1984 return REBAR_Destroy (hwnd, wParam, lParam);
1986 case WM_GETFONT:
1987 return REBAR_GetFont (hwnd, wParam, lParam);
1989 /* case WM_MOUSEMOVE: */
1990 /* return REBAR_MouseMove (hwnd, wParam, lParam); */
1992 case WM_NCCALCSIZE:
1993 return REBAR_NCCalcSize (hwnd, wParam, lParam);
1995 case WM_NCPAINT:
1996 return REBAR_NCPaint (hwnd, wParam, lParam);
1998 case WM_NOTIFY:
1999 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
2001 case WM_PAINT:
2002 return REBAR_Paint (hwnd, wParam);
2004 case WM_SETCURSOR:
2005 return REBAR_SetCursor (hwnd, wParam, lParam);
2007 case WM_SETFONT:
2008 return REBAR_SetFont (hwnd, wParam, lParam);
2010 case WM_SIZE:
2011 return REBAR_Size (hwnd, wParam, lParam);
2013 /* case WM_TIMER: */
2015 /* case WM_WININICHANGE: */
2017 default:
2018 if (uMsg >= WM_USER)
2019 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2020 uMsg, wParam, lParam);
2021 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2023 return 0;
2027 VOID
2028 REBAR_Register (void)
2030 WNDCLASSA wndClass;
2032 if (GlobalFindAtomA (REBARCLASSNAMEA)) return;
2034 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2035 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
2036 wndClass.lpfnWndProc = (WNDPROC)REBAR_WindowProc;
2037 wndClass.cbClsExtra = 0;
2038 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
2039 wndClass.hCursor = 0;
2040 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2041 wndClass.lpszClassName = REBARCLASSNAMEA;
2043 RegisterClassA (&wndClass);
2047 VOID
2048 REBAR_Unregister (void)
2050 if (GlobalFindAtomA (REBARCLASSNAMEA))
2051 UnregisterClassA (REBARCLASSNAMEA, (HINSTANCE)NULL);