comctl32: rebar: An implementation of RB_SIZETORECT.
[wine.git] / dlls / comctl32 / rebar.c
blobcd2861c4c64d3355f8ef5f2a938552afb7713cbc
1 /*
2 * Rebar control
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2007, 2008 Mikolaj Zalewski
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 19, 2004, by Robert Shearman.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features or bugs please note them below.
30 * TODO
31 * Styles:
32 * - RBS_DBLCLKTOGGLE
33 * - RBS_FIXEDORDER
34 * - RBS_REGISTERDROP
35 * - RBS_TOOLTIPS
36 * - RBS_AUTOSIZE
37 * Messages:
38 * - RB_BEGINDRAG
39 * - RB_DRAGMOVE
40 * - RB_ENDDRAG
41 * - RB_GETBANDMARGINS
42 * - RB_GETCOLORSCHEME
43 * - RB_GETDROPTARGET
44 * - RB_GETPALETTE
45 * - RB_SETCOLORSCHEME
46 * - RB_SETPALETTE
47 * - RB_SETTOOLTIPS
48 * - WM_CHARTOITEM
49 * - WM_LBUTTONDBLCLK
50 * - WM_MEASUREITEM
51 * - WM_PALETTECHANGED
52 * - WM_QUERYNEWPALETTE
53 * - WM_RBUTTONDOWN
54 * - WM_RBUTTONUP
55 * - WM_SYSCOLORCHANGE
56 * - WM_VKEYTOITEM
57 * - WM_WININICHANGE
58 * Notifications:
59 * - NM_HCHITTEST
60 * - NM_RELEASEDCAPTURE
61 * - RBN_AUTOBREAK
62 * - RBN_GETOBJECT
63 * - RBN_MINMAX
64 * Band styles:
65 * - RBBS_FIXEDBMP
66 * Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
67 * to set the size of the separator width (the value SEP_WIDTH_SIZE
68 * in here). Should be fixed!!
72 * Testing: set to 1 to make background brush *always* green
74 #define GLATESTING 0
77 * 3. REBAR_MoveChildWindows should have a loop because more than
78 * one pass (together with the RBN_CHILDSIZEs) is made on
79 * at least RB_INSERTBAND
82 #include <stdarg.h>
83 #include <stdlib.h>
84 #include <string.h>
86 #include "windef.h"
87 #include "winbase.h"
88 #include "wingdi.h"
89 #include "wine/unicode.h"
90 #include "winuser.h"
91 #include "winnls.h"
92 #include "commctrl.h"
93 #include "comctl32.h"
94 #include "uxtheme.h"
95 #include "tmschema.h"
96 #include "wine/debug.h"
98 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
100 typedef struct
102 UINT fStyle;
103 UINT fMask;
104 COLORREF clrFore;
105 COLORREF clrBack;
106 INT iImage;
107 HWND hwndChild;
108 UINT cxMinChild; /* valid if _CHILDSIZE */
109 UINT cyMinChild; /* valid if _CHILDSIZE */
110 UINT cx; /* valid if _SIZE */
111 HBITMAP hbmBack;
112 UINT wID;
113 UINT cyChild; /* valid if _CHILDSIZE */
114 UINT cyMaxChild; /* valid if _CHILDSIZE */
115 UINT cyIntegral; /* valid if _CHILDSIZE */
116 UINT cxIdeal;
117 LPARAM lParam;
118 UINT cxHeader;
120 INT cxEffective; /* current cx for band */
121 UINT cyHeader; /* the height of the header */
122 UINT lcx; /* minimum cx for band */
123 UINT lcy; /* minimum cy for band */
125 UINT cyRowSoFar; /* for RBS_VARHEIGHT - the height of the row if it would break on this band (set by _Layout) */
126 INT iRow; /* zero-based index of the row this band assigned to */
127 UINT fStatus; /* status flags, reset only by _Validate */
128 UINT fDraw; /* drawing flags, reset only by _Layout */
129 UINT uCDret; /* last return from NM_CUSTOMDRAW */
130 RECT rcBand; /* calculated band rectangle - coordinates swapped for CCS_VERT */
131 RECT rcGripper; /* calculated gripper rectangle */
132 RECT rcCapImage; /* calculated caption image rectangle */
133 RECT rcCapText; /* calculated caption text rectangle */
134 RECT rcChild; /* calculated child rectangle */
135 RECT rcChevron; /* calculated chevron rectangle */
137 LPWSTR lpText;
138 HWND hwndPrevParent;
139 } REBAR_BAND;
141 /* fStatus flags */
142 #define HAS_GRIPPER 0x00000001
143 #define HAS_IMAGE 0x00000002
144 #define HAS_TEXT 0x00000004
146 /* fDraw flags */
147 #define DRAW_GRIPPER 0x00000001
148 #define DRAW_IMAGE 0x00000002
149 #define DRAW_TEXT 0x00000004
150 #define DRAW_CHEVRONHOT 0x00000040
151 #define DRAW_CHEVRONPUSHED 0x00000080
152 #define NTF_INVALIDATE 0x01000000
154 typedef struct
156 COLORREF clrBk; /* background color */
157 COLORREF clrText; /* text color */
158 COLORREF clrBtnText; /* system color for BTNTEXT */
159 COLORREF clrBtnFace; /* system color for BTNFACE */
160 HIMAGELIST himl; /* handle to imagelist */
161 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
162 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
163 HWND hwndSelf; /* handle of REBAR window itself */
164 HWND hwndToolTip; /* handle to the tool tip control */
165 HWND hwndNotify; /* notification window (parent) */
166 HFONT hDefaultFont;
167 HFONT hFont; /* handle to the rebar's font */
168 SIZE imageSize; /* image size (image list) */
169 DWORD dwStyle; /* window style */
170 DWORD orgStyle; /* original style (dwStyle may change) */
171 SIZE calcSize; /* calculated rebar size - coordinates swapped for CCS_VERT */
172 BOOL bUnicode; /* TRUE if parent wants notify in W format */
173 BOOL DoRedraw; /* TRUE to actually draw bands */
174 UINT fStatus; /* Status flags (see below) */
175 HCURSOR hcurArrow; /* handle to the arrow cursor */
176 HCURSOR hcurHorz; /* handle to the EW cursor */
177 HCURSOR hcurVert; /* handle to the NS cursor */
178 HCURSOR hcurDrag; /* handle to the drag cursor */
179 INT iVersion; /* version number */
180 POINT dragStart; /* x,y of button down */
181 POINT dragNow; /* x,y of this MouseMove */
182 INT iOldBand; /* last band that had the mouse cursor over it */
183 INT ihitoffset; /* offset of hotspot from gripper.left */
184 INT ichevronhotBand; /* last band that had a hot chevron */
185 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
187 REBAR_BAND *bands; /* pointer to the array of rebar bands */
188 } REBAR_INFO;
190 /* fStatus flags */
191 #define BEGIN_DRAG_ISSUED 0x00000001
192 #define AUTO_RESIZE 0x00000002
193 #define BAND_NEEDS_REDRAW 0x00000020
195 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
196 #define RBBS_UNDOC_FIXEDHEADER 0x40000000
198 /* ---- REBAR layout constants. Mostly determined by ---- */
199 /* ---- experiment on WIN 98. ---- */
201 /* Width (or height) of separators between bands (either horz. or */
202 /* vert.). True only if RBS_BANDBORDERS is set */
203 #define SEP_WIDTH_SIZE 2
204 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
206 /* Blank (background color) space between Gripper (if present) */
207 /* and next item (image, text, or window). Always present */
208 #define REBAR_ALWAYS_SPACE 4
210 /* Blank (background color) space after Image (if present). */
211 #define REBAR_POST_IMAGE 2
213 /* Blank (background color) space after Text (if present). */
214 #define REBAR_POST_TEXT 4
216 /* Height of vertical gripper in a CCS_VERT rebar. */
217 #define GRIPPER_HEIGHT 16
219 /* Blank (background color) space before Gripper (if present). */
220 #define REBAR_PRE_GRIPPER 2
222 /* Width (of normal vertical gripper) or height (of horz. gripper) */
223 /* if present. */
224 #define GRIPPER_WIDTH 3
226 /* Width of the chevron button if present */
227 #define CHEVRON_WIDTH 10
229 /* the gap between the child and the next band */
230 #define REBAR_POST_CHILD 4
232 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
233 /* either top or bottom */
234 #define REBAR_DIVIDER 2
236 /* height of a rebar without a child */
237 #define REBAR_NO_CHILD_HEIGHT 4
239 /* minimum vertical height of a normal bar */
240 /* or minimum width of a CCS_VERT bar - from experiment on Win2k */
241 #define REBAR_MINSIZE 23
243 /* This is the increment that is used over the band height */
244 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
246 /* ---- End of REBAR layout constants. ---- */
248 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
250 /* The following define determines if a given band is hidden */
251 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
252 ((infoPtr->dwStyle & CCS_VERT) && \
253 ((a)->fStyle & RBBS_NOVERT)))
255 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
257 static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
260 /* "constant values" retrieved when DLL was initialized */
261 /* FIXME we do this when the classes are registered. */
262 static UINT mindragx = 0;
263 static UINT mindragy = 0;
265 static const char * const band_stylename[] = {
266 "RBBS_BREAK", /* 0001 */
267 "RBBS_FIXEDSIZE", /* 0002 */
268 "RBBS_CHILDEDGE", /* 0004 */
269 "RBBS_HIDDEN", /* 0008 */
270 "RBBS_NOVERT", /* 0010 */
271 "RBBS_FIXEDBMP", /* 0020 */
272 "RBBS_VARIABLEHEIGHT", /* 0040 */
273 "RBBS_GRIPPERALWAYS", /* 0080 */
274 "RBBS_NOGRIPPER", /* 0100 */
275 NULL };
277 static const char * const band_maskname[] = {
278 "RBBIM_STYLE", /* 0x00000001 */
279 "RBBIM_COLORS", /* 0x00000002 */
280 "RBBIM_TEXT", /* 0x00000004 */
281 "RBBIM_IMAGE", /* 0x00000008 */
282 "RBBIM_CHILD", /* 0x00000010 */
283 "RBBIM_CHILDSIZE", /* 0x00000020 */
284 "RBBIM_SIZE", /* 0x00000040 */
285 "RBBIM_BACKGROUND", /* 0x00000080 */
286 "RBBIM_ID", /* 0x00000100 */
287 "RBBIM_IDEALSIZE", /* 0x00000200 */
288 "RBBIM_LPARAM", /* 0x00000400 */
289 "RBBIM_HEADERSIZE", /* 0x00000800 */
290 NULL };
293 static CHAR line[200];
295 static const WCHAR themeClass[] = { 'R','e','b','a','r',0 };
297 static CHAR *
298 REBAR_FmtStyle( UINT style)
300 INT i = 0;
302 *line = 0;
303 while (band_stylename[i]) {
304 if (style & (1<<i)) {
305 if (*line != 0) strcat(line, " | ");
306 strcat(line, band_stylename[i]);
308 i++;
310 return line;
314 static CHAR *
315 REBAR_FmtMask( UINT mask)
317 INT i = 0;
319 *line = 0;
320 while (band_maskname[i]) {
321 if (mask & (1<<i)) {
322 if (*line != 0) strcat(line, " | ");
323 strcat(line, band_maskname[i]);
325 i++;
327 return line;
331 static VOID
332 REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
334 if( !TRACE_ON(rebar) ) return;
335 TRACE("band info: ");
336 if (pB->fMask & RBBIM_ID)
337 TRACE("ID=%u, ", pB->wID);
338 TRACE("size=%u, child=%p", pB->cbSize, pB->hwndChild);
339 if (pB->fMask & RBBIM_COLORS)
340 TRACE(", clrF=0x%06x, clrB=0x%06x", pB->clrFore, pB->clrBack);
341 TRACE("\n");
343 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
344 if (pB->fMask & RBBIM_STYLE)
345 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
346 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
347 TRACE("band info:");
348 if (pB->fMask & RBBIM_SIZE)
349 TRACE(" cx=%u", pB->cx);
350 if (pB->fMask & RBBIM_IDEALSIZE)
351 TRACE(" xIdeal=%u", pB->cxIdeal);
352 if (pB->fMask & RBBIM_HEADERSIZE)
353 TRACE(" xHeader=%u", pB->cxHeader);
354 if (pB->fMask & RBBIM_LPARAM)
355 TRACE(" lParam=0x%08lx", pB->lParam);
356 TRACE("\n");
358 if (pB->fMask & RBBIM_CHILDSIZE)
359 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
360 pB->cxMinChild,
361 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
364 static VOID
365 REBAR_DumpBand (const REBAR_INFO *iP)
367 REBAR_BAND *pB;
368 UINT i;
370 if(! TRACE_ON(rebar) ) return;
372 TRACE("hwnd=%p: color=%08x/%08x, bands=%u, rows=%u, cSize=%d,%d\n",
373 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
374 iP->calcSize.cx, iP->calcSize.cy);
375 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
376 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
377 iP->dragNow.x, iP->dragNow.y,
378 iP->iGrabbedBand);
379 TRACE("hwnd=%p: style=%08x, notify in Unicode=%s, redraw=%s\n",
380 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
381 (iP->DoRedraw)?"TRUE":"FALSE");
382 for (i = 0; i < iP->uNumBands; i++) {
383 pB = &iP->bands[i];
384 TRACE("band # %u:", i);
385 if (pB->fMask & RBBIM_ID)
386 TRACE(" ID=%u", pB->wID);
387 if (pB->fMask & RBBIM_CHILD)
388 TRACE(" child=%p", pB->hwndChild);
389 if (pB->fMask & RBBIM_COLORS)
390 TRACE(" clrF=0x%06x clrB=0x%06x", pB->clrFore, pB->clrBack);
391 TRACE("\n");
392 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
393 if (pB->fMask & RBBIM_STYLE)
394 TRACE("band # %u: style=0x%08x (%s)\n",
395 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
396 TRACE("band # %u: xHeader=%u",
397 i, pB->cxHeader);
398 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
399 if (pB->fMask & RBBIM_SIZE)
400 TRACE(" cx=%u", pB->cx);
401 if (pB->fMask & RBBIM_IDEALSIZE)
402 TRACE(" xIdeal=%u", pB->cxIdeal);
403 if (pB->fMask & RBBIM_LPARAM)
404 TRACE(" lParam=0x%08lx", pB->lParam);
406 TRACE("\n");
407 if (RBBIM_CHILDSIZE)
408 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
409 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
410 if (pB->fMask & RBBIM_TEXT)
411 TRACE("band # %u: text=%s\n",
412 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
413 TRACE("band # %u: lcx=%u, cxEffective=%u, lcy=%u\n",
414 i, pB->lcx, pB->cxEffective, pB->lcy);
415 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
416 i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
417 wine_dbgstr_rect(&pB->rcGripper));
418 TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
419 i, wine_dbgstr_rect(&pB->rcCapImage),
420 wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
425 /* dest can be equal to src */
426 static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
428 if (infoPtr->dwStyle & CCS_VERT) {
429 int tmp;
430 tmp = src->left;
431 dest->left = src->top;
432 dest->top = tmp;
434 tmp = src->right;
435 dest->right = src->bottom;
436 dest->bottom = tmp;
437 } else {
438 *dest = *src;
442 static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
444 if (infoPtr->dwStyle & CCS_VERT)
445 return lpRect->bottom - lpRect->top;
446 return lpRect->right - lpRect->left;
449 static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
451 if (infoPtr->dwStyle & CCS_VERT)
452 return lpRect->right - lpRect->left;
453 return lpRect->bottom - lpRect->top;
456 static int round_child_height(REBAR_BAND *lpBand, int cyHeight)
458 int cy = 0;
459 if (lpBand->cyIntegral == 0)
460 return cyHeight;
461 cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
462 cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
463 cy = min(cy, lpBand->cyMaxChild);
464 return cy;
467 static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
469 lpBand->lcy = max(lpBand->cyHeader,
470 (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
473 static void
474 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
476 INT x, y;
477 HPEN hPen, hOldPen;
479 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
480 hOldPen = SelectObject ( hdc, hPen );
481 x = left + 2;
482 y = top;
483 MoveToEx (hdc, x, y, NULL);
484 LineTo (hdc, x+5, y++); x++;
485 MoveToEx (hdc, x, y, NULL);
486 LineTo (hdc, x+3, y++); x++;
487 MoveToEx (hdc, x, y, NULL);
488 LineTo (hdc, x+1, y++);
489 SelectObject( hdc, hOldPen );
490 DeleteObject( hPen );
493 static HWND
494 REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
496 HWND parent, owner;
498 parent = infoPtr->hwndNotify;
499 if (!parent) {
500 parent = GetParent (infoPtr->hwndSelf);
501 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
502 if (owner) parent = owner;
504 return parent;
508 static INT
509 REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
511 HWND parent;
513 parent = REBAR_GetNotifyParent (infoPtr);
514 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
515 nmhdr->hwndFrom = infoPtr->hwndSelf;
516 nmhdr->code = code;
518 TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
520 return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
523 static INT
524 REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
526 NMREBAR notify_rebar;
527 REBAR_BAND *lpBand;
529 notify_rebar.dwMask = 0;
530 if (uBand!=-1) {
531 lpBand = &infoPtr->bands[uBand];
532 if (lpBand->fMask & RBBIM_ID) {
533 notify_rebar.dwMask |= RBNM_ID;
534 notify_rebar.wID = lpBand->wID;
536 if (lpBand->fMask & RBBIM_LPARAM) {
537 notify_rebar.dwMask |= RBNM_LPARAM;
538 notify_rebar.lParam = lpBand->lParam;
540 if (lpBand->fMask & RBBIM_STYLE) {
541 notify_rebar.dwMask |= RBNM_STYLE;
542 notify_rebar.fStyle = lpBand->fStyle;
545 notify_rebar.uBand = uBand;
546 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
549 static VOID
550 REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
552 HFONT hOldFont = 0;
553 INT oldBkMode = 0;
554 NMCUSTOMDRAW nmcd;
555 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
556 RECT rcBand;
558 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
560 if (lpBand->fDraw & DRAW_TEXT) {
561 hOldFont = SelectObject (hdc, infoPtr->hFont);
562 oldBkMode = SetBkMode (hdc, TRANSPARENT);
565 /* should test for CDRF_NOTIFYITEMDRAW here */
566 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
567 nmcd.hdc = hdc;
568 nmcd.rc = rcBand;
569 nmcd.rc.right = lpBand->rcCapText.right;
570 nmcd.rc.bottom = lpBand->rcCapText.bottom;
571 nmcd.dwItemSpec = lpBand->wID;
572 nmcd.uItemState = 0;
573 nmcd.lItemlParam = lpBand->lParam;
574 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
575 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
576 if (oldBkMode != TRANSPARENT)
577 SetBkMode (hdc, oldBkMode);
578 SelectObject (hdc, hOldFont);
579 return;
582 /* draw gripper */
583 if (lpBand->fDraw & DRAW_GRIPPER)
585 if (theme)
587 RECT rcGripper = lpBand->rcGripper;
588 int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
589 GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
590 OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
591 lpBand->rcGripper.top - rcGripper.top);
592 DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
594 else
595 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
598 /* draw caption image */
599 if (lpBand->fDraw & DRAW_IMAGE) {
600 POINT pt;
602 /* center image */
603 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
604 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
606 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
607 pt.x, pt.y,
608 ILD_TRANSPARENT);
611 /* draw caption text */
612 if (lpBand->fDraw & DRAW_TEXT) {
613 /* need to handle CDRF_NEWFONT here */
614 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
615 COLORREF oldcolor = CLR_NONE;
616 COLORREF new;
617 if (lpBand->clrFore != CLR_NONE) {
618 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
619 lpBand->clrFore;
620 oldcolor = SetTextColor (hdc, new);
622 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
623 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
624 if (oldBkMode != TRANSPARENT)
625 SetBkMode (hdc, oldBkMode);
626 if (lpBand->clrFore != CLR_NONE)
627 SetTextColor (hdc, oldcolor);
628 SelectObject (hdc, hOldFont);
631 if (!IsRectEmpty(&lpBand->rcChevron))
633 if (theme)
635 int stateId;
636 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
637 stateId = CHEVS_PRESSED;
638 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
639 stateId = CHEVS_HOT;
640 else
641 stateId = CHEVS_NORMAL;
642 DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
644 else
646 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
648 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
649 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
651 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
653 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
654 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
656 else
657 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
661 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
662 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
663 nmcd.hdc = hdc;
664 nmcd.rc = rcBand;
665 nmcd.rc.right = lpBand->rcCapText.right;
666 nmcd.rc.bottom = lpBand->rcCapText.bottom;
667 nmcd.dwItemSpec = lpBand->wID;
668 nmcd.uItemState = 0;
669 nmcd.lItemlParam = lpBand->lParam;
670 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
675 static VOID
676 REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
678 REBAR_BAND *lpBand;
679 UINT i;
681 if (!infoPtr->DoRedraw) return;
683 for (i = 0; i < infoPtr->uNumBands; i++) {
684 lpBand = &infoPtr->bands[i];
686 if (HIDDENBAND(lpBand)) continue;
688 /* now draw the band */
689 TRACE("[%p] drawing band %i, flags=%08x\n",
690 infoPtr->hwndSelf, i, lpBand->fDraw);
691 REBAR_DrawBand (hdc, infoPtr, lpBand);
697 static void
698 REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
699 /* Function: this routine initializes all the rectangles in */
700 /* each band in a row to fit in the adjusted rcBand rect. */
701 /* *** Supports only Horizontal bars. *** */
703 REBAR_BAND *lpBand;
704 UINT i, xoff, yoff;
705 RECT work;
707 for(i=rstart; i<rend; i++){
708 lpBand = &infoPtr->bands[i];
709 if (HIDDENBAND(lpBand)) {
710 SetRect (&lpBand->rcChild,
711 lpBand->rcBand.right, lpBand->rcBand.top,
712 lpBand->rcBand.right, lpBand->rcBand.bottom);
713 continue;
716 /* set initial gripper rectangle */
717 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
718 lpBand->rcBand.left, lpBand->rcBand.bottom);
720 /* calculate gripper rectangle */
721 if ( lpBand->fStatus & HAS_GRIPPER) {
722 lpBand->fDraw |= DRAW_GRIPPER;
723 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
724 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
725 lpBand->rcGripper.top += 2;
726 lpBand->rcGripper.bottom -= 2;
728 SetRect (&lpBand->rcCapImage,
729 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
730 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
732 else { /* no gripper will be drawn */
733 xoff = 0;
734 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
735 /* if no gripper but either image or text, then leave space */
736 xoff = REBAR_ALWAYS_SPACE;
737 SetRect (&lpBand->rcCapImage,
738 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
739 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
742 /* image is visible */
743 if (lpBand->fStatus & HAS_IMAGE) {
744 lpBand->fDraw |= DRAW_IMAGE;
745 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
746 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
748 /* set initial caption text rectangle */
749 SetRect (&lpBand->rcCapText,
750 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
751 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
753 else {
754 /* set initial caption text rectangle */
755 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
756 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
759 /* text is visible */
760 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
761 lpBand->fDraw |= DRAW_TEXT;
762 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
763 lpBand->rcCapText.right-REBAR_POST_TEXT);
766 /* set initial child window rectangle if there is a child */
767 if (lpBand->hwndChild != NULL) {
768 int cyBand = lpBand->rcBand.bottom - lpBand->rcBand.top;
769 yoff = (cyBand - lpBand->cyChild) / 2;
770 SetRect (&lpBand->rcChild,
771 lpBand->rcBand.left + lpBand->cxHeader, lpBand->rcBand.top + yoff,
772 lpBand->rcBand.right - REBAR_POST_CHILD, lpBand->rcBand.top + yoff + lpBand->cyChild);
773 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
775 lpBand->rcChild.right -= CHEVRON_WIDTH;
776 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
777 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
778 lpBand->rcChild.bottom);
781 else {
782 SetRect (&lpBand->rcChild,
783 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
784 lpBand->rcBand.right, lpBand->rcBand.bottom);
787 /* flag if notify required and invalidate rectangle */
788 if (lpBand->fDraw & NTF_INVALIDATE) {
789 TRACE("invalidating (%d,%d)-(%d,%d)\n",
790 lpBand->rcBand.left,
791 lpBand->rcBand.top,
792 lpBand->rcBand.right + SEP_WIDTH,
793 lpBand->rcBand.bottom + SEP_WIDTH);
794 lpBand->fDraw &= ~NTF_INVALIDATE;
795 work = lpBand->rcBand;
796 work.right += SEP_WIDTH;
797 work.bottom += SEP_WIDTH;
798 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
806 static VOID
807 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
808 /* Function: this routine initializes all the rectangles in */
809 /* each band in a row to fit in the adjusted rcBand rect. */
810 /* *** Supports only Vertical bars. *** */
812 REBAR_BAND *lpBand;
813 UINT i, xoff;
814 RECT work;
816 for(i=rstart; i<rend; i++){
817 RECT rcBand;
818 lpBand = &infoPtr->bands[i];
819 if (HIDDENBAND(lpBand)) continue;
821 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
823 /* set initial gripper rectangle */
824 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
826 /* calculate gripper rectangle */
827 if (lpBand->fStatus & HAS_GRIPPER) {
828 lpBand->fDraw |= DRAW_GRIPPER;
830 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
831 /* vertical gripper */
832 lpBand->rcGripper.left += 3;
833 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
834 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
835 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
837 /* initialize Caption image rectangle */
838 SetRect (&lpBand->rcCapImage, rcBand.left,
839 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
840 rcBand.right,
841 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
843 else {
844 /* horizontal gripper */
845 lpBand->rcGripper.left += 2;
846 lpBand->rcGripper.right -= 2;
847 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
848 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
850 /* initialize Caption image rectangle */
851 SetRect (&lpBand->rcCapImage, rcBand.left,
852 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
853 rcBand.right,
854 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
857 else { /* no gripper will be drawn */
858 xoff = 0;
859 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
860 /* if no gripper but either image or text, then leave space */
861 xoff = REBAR_ALWAYS_SPACE;
862 /* initialize Caption image rectangle */
863 SetRect (&lpBand->rcCapImage,
864 rcBand.left, rcBand.top+xoff,
865 rcBand.right, rcBand.top+xoff);
868 /* image is visible */
869 if (lpBand->fStatus & HAS_IMAGE) {
870 lpBand->fDraw |= DRAW_IMAGE;
872 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
873 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
875 /* set initial caption text rectangle */
876 SetRect (&lpBand->rcCapText,
877 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
878 rcBand.right, rcBand.top+lpBand->cxHeader);
880 else {
881 /* set initial caption text rectangle */
882 SetRect (&lpBand->rcCapText,
883 rcBand.left, lpBand->rcCapImage.bottom,
884 rcBand.right, rcBand.top+lpBand->cxHeader);
887 /* text is visible */
888 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
889 lpBand->fDraw |= DRAW_TEXT;
890 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
891 lpBand->rcCapText.bottom);
894 /* set initial child window rectangle if there is a child */
895 if (lpBand->hwndChild != NULL) {
896 int cxBand = rcBand.right - rcBand.left;
897 xoff = (cxBand - lpBand->cyChild) / 2;
898 SetRect (&lpBand->rcChild,
899 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
900 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
902 else {
903 SetRect (&lpBand->rcChild,
904 rcBand.left, rcBand.top+lpBand->cxHeader,
905 rcBand.right, rcBand.bottom);
908 if (lpBand->fDraw & NTF_INVALIDATE) {
909 TRACE("invalidating (%d,%d)-(%d,%d)\n",
910 rcBand.left,
911 rcBand.top,
912 rcBand.right + SEP_WIDTH,
913 rcBand.bottom + SEP_WIDTH);
914 lpBand->fDraw &= ~NTF_INVALIDATE;
915 work = rcBand;
916 work.bottom += SEP_WIDTH;
917 work.right += SEP_WIDTH;
918 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
925 static VOID
926 REBAR_ForceResize (REBAR_INFO *infoPtr)
927 /* Function: This changes the size of the REBAR window to that */
928 /* calculated by REBAR_Layout. */
930 INT x, y, width, height;
931 INT xedge = 0, yedge = 0;
932 RECT rcSelf;
934 TRACE("new size [%d x %d]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
936 if (infoPtr->dwStyle & CCS_NORESIZE)
937 return;
939 if (infoPtr->dwStyle & WS_BORDER)
941 xedge = GetSystemMetrics(SM_CXEDGE);
942 yedge = GetSystemMetrics(SM_CYEDGE);
943 /* swap for CCS_VERT? */
946 /* compute rebar window rect in parent client coordinates */
947 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
948 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
949 translate_rect(infoPtr, &rcSelf, &rcSelf);
951 height = infoPtr->calcSize.cy + 2*yedge;
952 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
953 RECT rcParent;
955 x = -xedge;
956 width = infoPtr->calcSize.cx + 2*xedge;
957 y = 0; /* quiet compiler warning */
958 switch ( infoPtr->dwStyle & CCS_LAYOUT_MASK) {
959 case 0: /* shouldn't happen - see NCCreate */
960 case CCS_TOP:
961 y = ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER) - yedge;
962 break;
963 case CCS_NOMOVEY:
964 y = rcSelf.top;
965 break;
966 case CCS_BOTTOM:
967 GetClientRect(GetParent(infoPtr->hwndSelf), &rcParent);
968 translate_rect(infoPtr, &rcParent, &rcParent);
969 y = rcParent.bottom - infoPtr->calcSize.cy - yedge;
970 break;
973 else {
974 x = rcSelf.left;
975 /* As on Windows if the CCS_NODIVIDER is not present the control will move
976 * 2 pixel down after every layout */
977 y = rcSelf.top + ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
978 width = rcSelf.right - rcSelf.left;
981 TRACE("hwnd %p, style=%08x, setting at (%d,%d) for (%d,%d)\n",
982 infoPtr->hwndSelf, infoPtr->dwStyle, x, y, width, height);
984 /* Set flag to ignore next WM_SIZE message and resize the window */
985 infoPtr->fStatus |= AUTO_RESIZE;
986 if ((infoPtr->dwStyle & CCS_VERT) == 0)
987 SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
988 else
989 SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
990 infoPtr->fStatus &= ~AUTO_RESIZE;
994 static VOID
995 REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
997 static const WCHAR strComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
998 REBAR_BAND *lpBand;
999 WCHAR szClassName[40];
1000 UINT i;
1001 NMREBARCHILDSIZE rbcz;
1002 HDWP deferpos;
1004 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1005 ERR("BeginDeferWindowPos returned NULL\n");
1007 for (i = start; i < endplus; i++) {
1008 lpBand = &infoPtr->bands[i];
1010 if (HIDDENBAND(lpBand)) continue;
1011 if (lpBand->hwndChild) {
1012 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1014 /* Always generate the RBN_CHILDSIZE even if child
1015 did not change */
1016 rbcz.uBand = i;
1017 rbcz.wID = lpBand->wID;
1018 rbcz.rcChild = lpBand->rcChild;
1019 translate_rect(infoPtr, &rbcz.rcBand, &lpBand->rcBand);
1020 if (infoPtr->dwStyle & CCS_VERT)
1021 rbcz.rcBand.top += lpBand->cxHeader;
1022 else
1023 rbcz.rcBand.left += lpBand->cxHeader;
1024 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1025 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1026 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1027 TRACE(" from (%s) to (%s)\n",
1028 wine_dbgstr_rect(&lpBand->rcChild),
1029 wine_dbgstr_rect(&rbcz.rcChild));
1030 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1033 /* native (IE4 in "Favorites" frame **1) does:
1034 * SetRect (&rc, -1, -1, -1, -1)
1035 * EqualRect (&rc,band->rc???)
1036 * if ret==0
1037 * CopyRect (band->rc????, &rc)
1038 * set flag outside of loop
1041 GetClassNameW (lpBand->hwndChild, szClassName, sizeof(szClassName)/sizeof(szClassName[0]));
1042 if (!lstrcmpW (szClassName, strComboBox) ||
1043 !lstrcmpW (szClassName, WC_COMBOBOXEXW)) {
1044 INT nEditHeight, yPos;
1045 RECT rc;
1047 /* special placement code for combo or comboex box */
1050 /* get size of edit line */
1051 GetWindowRect (lpBand->hwndChild, &rc);
1052 nEditHeight = rc.bottom - rc.top;
1053 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1055 /* center combo box inside child area */
1056 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1057 lpBand->hwndChild,
1058 lpBand->rcChild.left, yPos,
1059 lpBand->rcChild.right - lpBand->rcChild.left,
1060 nEditHeight);
1061 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1062 lpBand->rcChild.left,
1063 /*lpBand->rcChild.top*/ yPos,
1064 lpBand->rcChild.right - lpBand->rcChild.left,
1065 nEditHeight,
1066 SWP_NOZORDER);
1067 if (!deferpos)
1068 ERR("DeferWindowPos returned NULL\n");
1070 else {
1071 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1072 lpBand->hwndChild,
1073 lpBand->rcChild.left, lpBand->rcChild.top,
1074 lpBand->rcChild.right - lpBand->rcChild.left,
1075 lpBand->rcChild.bottom - lpBand->rcChild.top);
1076 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1077 lpBand->rcChild.left,
1078 lpBand->rcChild.top,
1079 lpBand->rcChild.right - lpBand->rcChild.left,
1080 lpBand->rcChild.bottom - lpBand->rcChild.top,
1081 SWP_NOZORDER);
1082 if (!deferpos)
1083 ERR("DeferWindowPos returned NULL\n");
1087 if (!EndDeferWindowPos(deferpos))
1088 ERR("EndDeferWindowPos returned NULL\n");
1090 if (infoPtr->DoRedraw)
1091 UpdateWindow (infoPtr->hwndSelf);
1093 /* native (from **1 above) does:
1094 * UpdateWindow(rebar)
1095 * REBAR_ForceResize
1096 * RBN_HEIGHTCHANGE if necessary
1097 * if ret from any EqualRect was 0
1098 * Goto "BeginDeferWindowPos"
1103 static int next_band(const REBAR_INFO *infoPtr, int i)
1105 int n;
1106 for (n = i + 1; n < infoPtr->uNumBands; n++)
1107 if (!HIDDENBAND(&infoPtr->bands[n]))
1108 break;
1109 return n;
1112 static int prev_band(const REBAR_INFO *infoPtr, int i)
1114 int n;
1115 for (n = i - 1; n >= 0; n--)
1116 if (!HIDDENBAND(&infoPtr->bands[n]))
1117 break;
1118 return n;
1121 static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
1123 int iLastBand = iBand;
1124 int iRow = infoPtr->bands[iBand].iRow;
1125 while ((iBand = prev_band(infoPtr, iBand)) >= 0) {
1126 if (infoPtr->bands[iBand].iRow != iRow)
1127 break;
1128 else
1129 iLastBand = iBand;
1131 return iLastBand;
1134 static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
1136 int iRow = infoPtr->bands[iBand].iRow;
1137 while ((iBand = next_band(infoPtr, iBand)) < infoPtr->uNumBands)
1138 if (infoPtr->bands[iBand].iRow != iRow)
1139 break;
1140 return iBand;
1143 static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1145 int xPos = 0, i;
1146 for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
1148 REBAR_BAND *lpBand = &infoPtr->bands[i];
1150 lpBand = &infoPtr->bands[i];
1151 if (lpBand->rcBand.left != xPos || lpBand->rcBand.right != xPos + lpBand->cxEffective) {
1152 lpBand->fDraw |= NTF_INVALIDATE;
1153 TRACE("Setting rect %d to %d,%d\n", i, xPos, xPos + lpBand->cxEffective);
1154 lpBand->rcBand.left = xPos;
1155 lpBand->rcBand.right = xPos + lpBand->cxEffective;
1157 xPos += lpBand->cxEffective + SEP_WIDTH;
1161 /* The rationale of this function is probably as follows: if we have some space
1162 * to distribute we want to add it to a band on the right. However we don't want
1163 * to unminimize a minimized band so we search for a band that is big enough.
1164 * For some reason "big enough" is defined as bigger than the minimum size of the
1165 * first band in the row
1167 static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1169 INT iLcx = 0, i;
1171 iLcx = infoPtr->bands[iBeginBand].lcx;
1173 for (i = prev_band(infoPtr, iEndBand); i >= iBeginBand; i = prev_band(infoPtr, i))
1174 if (infoPtr->bands[i].cxEffective > iLcx && !(infoPtr->bands[i].fStyle&RBBS_FIXEDSIZE))
1175 break;
1177 if (i < iBeginBand)
1178 for (i = prev_band(infoPtr, iEndBand); i >= iBeginBand; i = prev_band(infoPtr, i))
1179 if (infoPtr->bands[i].lcx == iLcx)
1180 break;
1182 TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
1183 return &infoPtr->bands[i];
1186 static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1188 REBAR_BAND *lpBand;
1189 INT width, i;
1191 TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
1192 for (i = prev_band(infoPtr, iEndBand); i >= iBeginBand; i = prev_band(infoPtr, i))
1194 lpBand = &infoPtr->bands[i];
1196 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->lcx);
1197 cxShrink -= lpBand->cxEffective - width;
1198 lpBand->cxEffective = width;
1199 if (bEnforce && lpBand->cx > lpBand->cxEffective)
1200 lpBand->cx = lpBand->cxEffective;
1201 if (cxShrink == 0)
1202 break;
1204 return cxShrink;
1208 static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1210 REBAR_BAND *lpBand;
1211 INT width, i;
1213 TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
1214 for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
1216 lpBand = &infoPtr->bands[i];
1218 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->lcx);
1219 cxShrink -= lpBand->cxEffective - width;
1220 lpBand->cxEffective = width;
1221 if (bEnforce)
1222 lpBand->cx = lpBand->cxEffective;
1223 if (cxShrink == 0)
1224 break;
1226 return cxShrink;
1229 static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
1231 REBAR_BAND *lpBand;
1232 int yMaxHeight = 0;
1233 int yPos = yStart;
1234 int row = infoPtr->bands[iBeginBand].iRow;
1235 int i;
1236 for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
1238 lpBand = &infoPtr->bands[i];
1239 lpBand->cyRowSoFar = yMaxHeight;
1240 yMaxHeight = max(yMaxHeight, lpBand->lcy);
1242 TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
1244 for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
1246 lpBand = &infoPtr->bands[i];
1247 /* we may be called for multiple rows if RBS_VARHEIGHT not set */
1248 if (lpBand->iRow != row) {
1249 yPos += yMaxHeight + SEP_WIDTH;
1250 row = lpBand->iRow;
1253 if (lpBand->rcBand.top != yPos || lpBand->rcBand.bottom != yPos + yMaxHeight) {
1254 lpBand->fDraw |= NTF_INVALIDATE;
1255 lpBand->rcBand.top = yPos;
1256 lpBand->rcBand.bottom = yPos + yMaxHeight;
1257 TRACE("Band %d: %s\n", i, wine_dbgstr_rect(&lpBand->rcBand));
1260 return yPos + yMaxHeight;
1263 static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
1265 REBAR_BAND *lpBand;
1266 int i, extra;
1267 int width = 0;
1269 TRACE("Adjusting row [%d;%d). Width: %d\n", iBeginBand, iEndBand, cx);
1270 for (i = iBeginBand; i < iEndBand; i++)
1271 infoPtr->bands[i].iRow = *piRow;
1273 /* compute the extra space */
1274 for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
1276 lpBand = &infoPtr->bands[i];
1277 if (i > iBeginBand)
1278 width += SEP_WIDTH;
1279 lpBand->cxEffective = max(lpBand->lcx, lpBand->cx);
1280 width += lpBand->cxEffective;
1283 extra = cx - width;
1284 TRACE("Extra space: %d\n", extra);
1285 if (extra < 0) {
1286 int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
1287 if (ret > 0 && next_band(infoPtr, iBeginBand) != iEndBand) /* one band may be longer than expected... */
1288 ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
1289 } else
1290 if (extra > 0) {
1291 lpBand = REBAR_FindBandToGrow(infoPtr, iBeginBand, iEndBand);
1292 lpBand->cxEffective += extra;
1295 REBAR_SetRowRectsX(infoPtr, iBeginBand, iEndBand);
1296 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1298 if (*piRow > 0)
1299 *pyPos += SEP_WIDTH;
1300 *pyPos = REBAR_SetBandsHeight(infoPtr, iBeginBand, iEndBand, *pyPos);
1302 (*piRow)++;
1305 static VOID
1306 REBAR_Layout(REBAR_INFO *infoPtr, const RECT *lpRect)
1308 REBAR_BAND *lpBand;
1309 RECT rcAdj;
1310 SIZE oldSize;
1311 INT adjcx, adjcy, i;
1312 INT rowstart = 0;
1313 INT row = 0;
1314 INT xMin, yPos;
1315 INT cyTarget;
1316 const INT yInit = 0;
1318 cyTarget = 0;
1319 if (lpRect) {
1320 rcAdj = *lpRect;
1321 cyTarget = get_rect_cy(infoPtr, lpRect);
1322 } else if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
1323 GetClientRect(infoPtr->hwndSelf, &rcAdj);
1324 else
1325 GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
1326 TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
1328 adjcx = get_rect_cx(infoPtr, &rcAdj);
1329 adjcy = get_rect_cy(infoPtr, &rcAdj);
1331 if (infoPtr->uNumBands == 0) {
1332 TRACE("No bands - setting size to (0,%d), vert: %lx\n", adjcx, infoPtr->dwStyle & CCS_VERT);
1333 infoPtr->calcSize.cx = adjcx;
1334 /* the calcSize.cy won't change for a 0 band rebar */
1335 infoPtr->uNumRows = 0;
1336 REBAR_ForceResize(infoPtr);
1337 return;
1340 yPos = yInit;
1341 xMin = 0;
1342 /* divide rows */
1343 i = 0;
1344 for (i = 0; i < infoPtr->uNumBands; i++)
1346 lpBand = &infoPtr->bands[i];
1347 if (HIDDENBAND(lpBand)) continue;
1349 if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->lcx > adjcx)) {
1350 TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
1351 REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
1352 rowstart = i;
1353 xMin = 0;
1355 else
1356 xMin += SEP_WIDTH;
1358 xMin += lpBand->lcx;
1360 REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
1362 if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
1363 yPos = REBAR_SetBandsHeight(infoPtr, 0, infoPtr->uNumBands, yInit);
1365 infoPtr->uNumRows = row;
1367 if (infoPtr->dwStyle & CCS_VERT)
1368 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1369 else
1370 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1371 /* now compute size of Rebar itself */
1372 oldSize = infoPtr->calcSize;
1374 infoPtr->calcSize.cx = adjcx;
1375 infoPtr->calcSize.cy = yPos;
1376 TRACE("calcsize size=(%d, %d), origheight=(%d,%d)\n",
1377 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1378 oldSize.cx, oldSize.cy);
1380 REBAR_DumpBand (infoPtr);
1381 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1382 REBAR_ForceResize (infoPtr);
1384 /* note: after a RBN_HEIGHTCHANGE native sends once again all the RBN_CHILDSIZE
1385 * and does another ForceResize */
1386 if (oldSize.cy != infoPtr->calcSize.cy)
1388 NMHDR heightchange;
1389 REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1393 static int
1394 REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
1396 int cyBandsOld;
1397 int cyBandsNew = 0;
1398 int i;
1400 TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
1402 cyBandsOld = infoPtr->bands[iBeginBand].rcBand.bottom - infoPtr->bands[iBeginBand].rcBand.top;
1403 for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
1405 REBAR_BAND *lpBand = &infoPtr->bands[i];
1406 int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
1407 int cyChild = round_child_height(lpBand, cyMaxChild);
1409 if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
1411 TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
1412 *fChanged = TRUE;
1413 lpBand->cyChild = cyChild;
1414 lpBand->fDraw |= NTF_INVALIDATE;
1415 update_min_band_height(infoPtr, lpBand);
1417 cyBandsNew = max(cyBandsNew, lpBand->lcy);
1419 return cyBandsNew - cyBandsOld;
1422 /* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
1423 static VOID
1424 REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
1426 int extra = height - infoPtr->calcSize.cy; /* may be negative */
1427 BOOL fChanged = FALSE;
1428 UINT uNumRows = infoPtr->uNumRows;
1429 int i;
1431 /* That's not exactly what Windows does but should be similar */
1433 /* Pass one: break-up/glue rows */
1434 if (extra > 0)
1436 for (i = prev_band(infoPtr, infoPtr->uNumBands); i > 0; i = prev_band(infoPtr, i))
1438 REBAR_BAND *lpBand = &infoPtr->bands[i];
1439 int height = lpBand->rcBand.bottom - lpBand->rcBand.top;
1440 int cyBreakExtra; /* additional cy for the rebar after a RBBS_BREAK on this band */
1442 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1443 cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
1444 else
1445 cyBreakExtra = height; /* 'height' => 'height' + 'height'*/
1446 cyBreakExtra += SEP_WIDTH;
1448 if (extra <= cyBreakExtra / 2)
1449 break;
1451 if (!(lpBand->fStyle & RBBS_BREAK))
1453 TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
1454 lpBand->fStyle |= RBBS_BREAK;
1455 lpBand->fDraw |= NTF_INVALIDATE;
1456 fChanged = TRUE;
1457 extra -= cyBreakExtra;
1458 uNumRows++;
1459 /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
1460 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1461 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->lcy;
1465 /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
1467 /* Pass two: increase/decrease control height */
1468 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1470 int i = 0;
1471 int iRow = 0;
1472 while (i < infoPtr->uNumBands)
1474 REBAR_BAND *lpBand = &infoPtr->bands[i];
1475 int extraForRow = extra / (int)(uNumRows - iRow);
1476 int rowEnd;
1478 /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
1479 for (rowEnd = next_band(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_band(infoPtr, rowEnd))
1480 if (infoPtr->bands[rowEnd].iRow != lpBand->iRow || (infoPtr->bands[rowEnd].fStyle & RBBS_BREAK))
1481 break;
1483 extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
1484 TRACE("extra = %d\n", extra);
1485 i = rowEnd;
1486 iRow++;
1489 else
1490 extra -= REBAR_SizeChildrenToHeight(infoPtr, 0, infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
1492 if (fChanged)
1493 REBAR_Layout(infoPtr, NULL);
1497 static VOID
1498 REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1499 /* Function: This routine evaluates the band specs supplied */
1500 /* by the user and updates the following 5 fields in */
1501 /* the internal band structure: cxHeader, lcx, lcy, hcx, hcy*/
1503 UINT header=0;
1504 UINT textheight=0;
1505 UINT i, nonfixed;
1506 REBAR_BAND *tBand;
1508 lpBand->fStatus = 0;
1509 lpBand->lcx = 0;
1510 lpBand->lcy = 0;
1512 /* Data coming in from users into the cx... and cy... fields */
1513 /* may be bad, just garbage, because the user never clears */
1514 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1515 /* along if the fields exist in the input area. Here we must */
1516 /* determine if the data is valid. I have no idea how MS does */
1517 /* the validation, but it does because the RB_GETBANDINFO */
1518 /* returns a 0 when I know the sample program passed in an */
1519 /* address. Here I will use the algorithm that if the value */
1520 /* is greater than 65535 then it is bad and replace it with */
1521 /* a zero. Feel free to improve the algorithm. - GA 12/2000 */
1522 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1523 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1524 if (lpBand->cx > 65535) lpBand->cx = 0;
1525 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1526 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1527 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1528 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1530 /* TODO : we could try return to the caller if a value changed so that */
1531 /* a REBAR_Layout is needed. Till now the caller should call it */
1532 /* it always (we should also check what native does) */
1534 /* Header is where the image, text and gripper exist */
1535 /* in the band and precede the child window. */
1537 /* count number of non-FIXEDSIZE and non-Hidden bands */
1538 nonfixed = 0;
1539 for (i=0; i<infoPtr->uNumBands; i++){
1540 tBand = &infoPtr->bands[i];
1541 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1542 nonfixed++;
1545 /* calculate gripper rectangle */
1546 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1547 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1548 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1550 lpBand->fStatus |= HAS_GRIPPER;
1551 if (infoPtr->dwStyle & CCS_VERT)
1552 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1553 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1554 else
1555 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1556 else
1557 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1558 /* Always have 4 pixels before anything else */
1559 header += REBAR_ALWAYS_SPACE;
1562 /* image is visible */
1563 if ((lpBand->fMask & RBBIM_IMAGE) && (infoPtr->himl)) {
1564 lpBand->fStatus |= HAS_IMAGE;
1565 if (infoPtr->dwStyle & CCS_VERT) {
1566 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1567 lpBand->lcy = infoPtr->imageSize.cx + 2;
1569 else {
1570 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1571 lpBand->lcy = infoPtr->imageSize.cy + 2;
1575 /* text is visible */
1576 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
1577 !(lpBand->fStyle & RBBS_HIDETITLE)) {
1578 HDC hdc = GetDC (0);
1579 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1580 SIZE size;
1582 lpBand->fStatus |= HAS_TEXT;
1583 GetTextExtentPoint32W (hdc, lpBand->lpText,
1584 lstrlenW (lpBand->lpText), &size);
1585 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1586 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1588 SelectObject (hdc, hOldFont);
1589 ReleaseDC (0, hdc);
1592 /* if no gripper but either image or text, then leave space */
1593 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1594 !(lpBand->fStatus & HAS_GRIPPER)) {
1595 header += REBAR_ALWAYS_SPACE;
1598 /* check if user overrode the header value */
1599 if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
1600 lpBand->cxHeader = header;
1601 lpBand->cyHeader = textheight;
1603 /* Now compute minimum size of child window */
1604 update_min_band_height(infoPtr, lpBand); /* update lpBand->lcy from cyHeader and cyChild*/
1606 lpBand->lcx = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
1607 if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
1608 lpBand->lcx += CHEVRON_WIDTH;
1611 static BOOL
1612 REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
1613 /* Function: This routine copies the supplied values from */
1614 /* user input (lprbbi) to the internal band structure. */
1615 /* It returns true if something changed and false if not. */
1617 BOOL bChanged = FALSE;
1619 lpBand->fMask |= lprbbi->fMask;
1621 if( (lprbbi->fMask & RBBIM_STYLE) &&
1622 (lpBand->fStyle != lprbbi->fStyle ) )
1624 lpBand->fStyle = lprbbi->fStyle;
1625 bChanged = TRUE;
1628 if( (lprbbi->fMask & RBBIM_COLORS) &&
1629 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
1630 ( lpBand->clrBack != lprbbi->clrBack ) ) )
1632 lpBand->clrFore = lprbbi->clrFore;
1633 lpBand->clrBack = lprbbi->clrBack;
1634 bChanged = TRUE;
1637 if( (lprbbi->fMask & RBBIM_IMAGE) &&
1638 ( lpBand->iImage != lprbbi->iImage ) )
1640 lpBand->iImage = lprbbi->iImage;
1641 bChanged = TRUE;
1644 if( (lprbbi->fMask & RBBIM_CHILD) &&
1645 (lprbbi->hwndChild != lpBand->hwndChild ) )
1647 if (lprbbi->hwndChild) {
1648 lpBand->hwndChild = lprbbi->hwndChild;
1649 lpBand->hwndPrevParent =
1650 SetParent (lpBand->hwndChild, hwnd);
1651 /* below in trace from WinRAR */
1652 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
1653 /* above in trace from WinRAR */
1655 else {
1656 TRACE("child: %p prev parent: %p\n",
1657 lpBand->hwndChild, lpBand->hwndPrevParent);
1658 lpBand->hwndChild = 0;
1659 lpBand->hwndPrevParent = 0;
1661 bChanged = TRUE;
1664 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
1665 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
1666 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
1667 ( (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) &&
1668 ( (lpBand->cyChild != lprbbi->cyChild ) ||
1669 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
1670 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
1671 ( (lprbbi->cbSize < sizeof (REBARBANDINFOA)) &&
1672 ( (lpBand->cyChild ||
1673 lpBand->cyMaxChild ||
1674 lpBand->cyIntegral ) ) ) ) )
1676 lpBand->cxMinChild = lprbbi->cxMinChild;
1677 lpBand->cyMinChild = lprbbi->cyMinChild;
1678 /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
1679 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA) && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
1680 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1681 lpBand->cyIntegral = lprbbi->cyIntegral;
1683 lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild); /* make (cyChild - cyMinChild) a multiple of cyIntergral */
1685 else {
1686 lpBand->cyChild = lpBand->cyMinChild;
1687 lpBand->cyMaxChild = 0x7fffffff;
1688 lpBand->cyIntegral = 0;
1690 bChanged = TRUE;
1693 if( (lprbbi->fMask & RBBIM_SIZE) &&
1694 (lpBand->cx != lprbbi->cx ) )
1696 lpBand->cx = lprbbi->cx;
1697 bChanged = TRUE;
1700 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
1701 ( lpBand->hbmBack != lprbbi->hbmBack ) )
1703 lpBand->hbmBack = lprbbi->hbmBack;
1704 bChanged = TRUE;
1707 if( (lprbbi->fMask & RBBIM_ID) &&
1708 (lpBand->wID != lprbbi->wID ) )
1710 lpBand->wID = lprbbi->wID;
1711 bChanged = TRUE;
1714 /* check for additional data */
1715 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
1716 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
1717 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
1719 lpBand->cxIdeal = lprbbi->cxIdeal;
1720 bChanged = TRUE;
1723 if( (lprbbi->fMask & RBBIM_LPARAM) &&
1724 (lpBand->lParam != lprbbi->lParam ) )
1726 lpBand->lParam = lprbbi->lParam;
1727 bChanged = TRUE;
1730 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
1731 (lpBand->cxHeader != lprbbi->cxHeader ) )
1733 lpBand->cxHeader = lprbbi->cxHeader;
1734 lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
1735 bChanged = TRUE;
1739 return bChanged;
1742 static LRESULT
1743 REBAR_InternalEraseBkGnd (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, const RECT *clip)
1744 /* Function: This erases the background rectangle by drawing */
1745 /* each band with its background color (or the default) and */
1746 /* draws each bands right separator if necessary. The row */
1747 /* separators are drawn on the first band of the next row. */
1749 REBAR_BAND *lpBand;
1750 UINT i;
1751 INT oldrow;
1752 HDC hdc = (HDC)wParam;
1753 RECT cr;
1754 COLORREF old = CLR_NONE, new;
1755 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1757 GetClientRect (infoPtr->hwndSelf, &cr);
1759 oldrow = -1;
1760 for(i=0; i<infoPtr->uNumBands; i++) {
1761 RECT rcBand;
1762 lpBand = &infoPtr->bands[i];
1763 if (HIDDENBAND(lpBand)) continue;
1764 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1766 /* draw band separator between rows */
1767 if (lpBand->iRow != oldrow) {
1768 oldrow = lpBand->iRow;
1769 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1770 RECT rcRowSep;
1771 rcRowSep = rcBand;
1772 if (infoPtr->dwStyle & CCS_VERT) {
1773 rcRowSep.right += SEP_WIDTH_SIZE;
1774 rcRowSep.bottom = infoPtr->calcSize.cx;
1775 if (theme)
1776 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_RIGHT, NULL);
1777 else
1778 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
1780 else {
1781 rcRowSep.bottom += SEP_WIDTH_SIZE;
1782 rcRowSep.right = infoPtr->calcSize.cx;
1783 if (theme)
1784 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1785 else
1786 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
1788 TRACE ("drawing band separator bottom (%s)\n",
1789 wine_dbgstr_rect(&rcRowSep));
1793 /* draw band separator between bands in a row */
1794 if (infoPtr->dwStyle & RBS_BANDBORDERS && lpBand->rcBand.left > 0) {
1795 RECT rcSep;
1796 rcSep = rcBand;
1797 if (infoPtr->dwStyle & CCS_VERT) {
1798 rcSep.bottom = rcSep.top;
1799 rcSep.top -= SEP_WIDTH_SIZE;
1800 if (theme)
1801 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1802 else
1803 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
1805 else {
1806 rcSep.right = rcSep.left;
1807 rcSep.left -= SEP_WIDTH_SIZE;
1808 if (theme)
1809 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_RIGHT, NULL);
1810 else
1811 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
1813 TRACE("drawing band separator right (%s)\n",
1814 wine_dbgstr_rect(&rcSep));
1817 /* draw the actual background */
1818 if (lpBand->clrBack != CLR_NONE) {
1819 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
1820 lpBand->clrBack;
1821 #if GLATESTING
1822 /* testing only - make background green to see it */
1823 new = RGB(0,128,0);
1824 #endif
1826 else {
1827 /* In the absence of documentation for Rebar vs. CLR_NONE,
1828 * we will use the default BtnFace color. Note documentation
1829 * exists for Listview and Imagelist.
1831 new = infoPtr->clrBtnFace;
1832 #if GLATESTING
1833 /* testing only - make background green to see it */
1834 new = RGB(0,128,0);
1835 #endif
1838 if (theme)
1840 /* When themed, the background color is ignored (but not a
1841 * background bitmap */
1842 DrawThemeBackground (theme, hdc, 0, 0, &cr, &rcBand);
1844 else
1846 old = SetBkColor (hdc, new);
1847 TRACE("%s background color=0x%06x, band (%d,%d)-(%d,%d), clip (%d,%d)-(%d,%d)\n",
1848 (lpBand->clrBack == CLR_NONE) ? "none" :
1849 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
1850 GetBkColor(hdc),
1851 rcBand.left,rcBand.top,
1852 rcBand.right,rcBand.bottom,
1853 clip->left, clip->top,
1854 clip->right, clip->bottom);
1855 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &rcBand, NULL, 0, 0);
1856 if (lpBand->clrBack != CLR_NONE)
1857 SetBkColor (hdc, old);
1860 return TRUE;
1863 static void
1864 REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
1866 REBAR_BAND *lpBand;
1867 RECT rect;
1868 UINT iCount;
1870 GetClientRect (infoPtr->hwndSelf, &rect);
1872 *pFlags = RBHT_NOWHERE;
1873 if (PtInRect (&rect, *lpPt))
1875 if (infoPtr->uNumBands == 0) {
1876 *pFlags = RBHT_NOWHERE;
1877 if (pBand)
1878 *pBand = -1;
1879 TRACE("NOWHERE\n");
1880 return;
1882 else {
1883 /* somewhere inside */
1884 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
1885 RECT rcBand;
1886 lpBand = &infoPtr->bands[iCount];
1887 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1888 if (HIDDENBAND(lpBand)) continue;
1889 if (PtInRect (&rcBand, *lpPt)) {
1890 if (pBand)
1891 *pBand = iCount;
1892 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
1893 *pFlags = RBHT_GRABBER;
1894 TRACE("ON GRABBER %d\n", iCount);
1895 return;
1897 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
1898 *pFlags = RBHT_CAPTION;
1899 TRACE("ON CAPTION %d\n", iCount);
1900 return;
1902 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
1903 *pFlags = RBHT_CAPTION;
1904 TRACE("ON CAPTION %d\n", iCount);
1905 return;
1907 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
1908 *pFlags = RBHT_CLIENT;
1909 TRACE("ON CLIENT %d\n", iCount);
1910 return;
1912 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
1913 *pFlags = RBHT_CHEVRON;
1914 TRACE("ON CHEVRON %d\n", iCount);
1915 return;
1917 else {
1918 *pFlags = RBHT_NOWHERE;
1919 TRACE("NOWHERE %d\n", iCount);
1920 return;
1925 *pFlags = RBHT_NOWHERE;
1926 if (pBand)
1927 *pBand = -1;
1929 TRACE("NOWHERE\n");
1930 return;
1933 else {
1934 *pFlags = RBHT_NOWHERE;
1935 if (pBand)
1936 *pBand = -1;
1937 TRACE("NOWHERE\n");
1938 return;
1942 static void
1943 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
1944 /* Function: This will implement the functionality of a */
1945 /* Gripper drag within a row. It will not implement "out- */
1946 /* of-row" drags. (They are detected and handled in */
1947 /* REBAR_MouseMove.) */
1948 /* **** FIXME Switching order of bands in a row not **** */
1949 /* **** yet implemented. **** */
1951 REBAR_BAND *hitBand;
1952 INT iHitBand, iRowBegin, iRowEnd;
1953 INT movement, xBand;
1955 /* on first significant mouse movement, issue notify */
1956 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
1957 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
1958 /* Notify returned TRUE - abort drag */
1959 infoPtr->dragStart.x = 0;
1960 infoPtr->dragStart.y = 0;
1961 infoPtr->dragNow = infoPtr->dragStart;
1962 infoPtr->iGrabbedBand = -1;
1963 ReleaseCapture ();
1964 return ;
1966 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
1969 iHitBand = infoPtr->iGrabbedBand;
1970 iRowBegin = get_row_begin_for_band(infoPtr, iHitBand);
1971 iRowEnd = get_row_end_for_band(infoPtr, iHitBand);
1972 hitBand = &infoPtr->bands[iHitBand];
1974 xBand = hitBand->rcBand.left;
1975 movement = (infoPtr->dwStyle&CCS_VERT ? ptsmove->y : ptsmove->x)
1976 - (xBand + REBAR_PRE_GRIPPER - infoPtr->ihitoffset);
1978 if (movement < 0) {
1979 int cxLeft = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iHitBand, -movement, TRUE);
1980 hitBand->cxEffective += -movement - cxLeft;
1981 hitBand->cx = hitBand->cxEffective;
1982 } else if (movement > 0) {
1983 int cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
1984 REBAR_BAND *lpPrev = &infoPtr->bands[prev_band(infoPtr, iHitBand)];
1985 lpPrev->cxEffective += movement - cxLeft;
1986 lpPrev->cx = lpPrev->cxEffective;
1989 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
1990 if (infoPtr->dwStyle & CCS_VERT)
1991 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1992 else
1993 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1994 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
1999 /* << REBAR_BeginDrag >> */
2002 static LRESULT
2003 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2005 UINT uBand = (UINT)wParam;
2006 REBAR_BAND *lpBand;
2008 if (uBand >= infoPtr->uNumBands)
2009 return FALSE;
2011 TRACE("deleting band %u!\n", uBand);
2012 lpBand = &infoPtr->bands[uBand];
2013 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2014 /* TODO: a return of 1 should probably cancel the deletion */
2016 if (lpBand->hwndChild)
2017 ShowWindow(lpBand->hwndChild, SW_HIDE);
2018 Free(lpBand->lpText);
2020 infoPtr->uNumBands--;
2021 memmove(&infoPtr->bands[uBand], &infoPtr->bands[uBand+1],
2022 (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
2023 infoPtr->bands = ReAlloc(infoPtr->bands, infoPtr->uNumBands * sizeof(REBAR_BAND));
2025 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2027 /* if only 1 band left the re-validate to possible eliminate gripper */
2028 if (infoPtr->uNumBands == 1)
2029 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2031 REBAR_Layout(infoPtr, NULL);
2033 return TRUE;
2037 /* << REBAR_DragMove >> */
2038 /* << REBAR_EndDrag >> */
2041 static LRESULT
2042 REBAR_GetBandBorders (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2044 LPRECT lpRect = (LPRECT)lParam;
2045 REBAR_BAND *lpBand;
2047 if (!lParam)
2048 return 0;
2049 if ((UINT)wParam >= infoPtr->uNumBands)
2050 return 0;
2052 lpBand = &infoPtr->bands[(UINT)wParam];
2054 /* FIXME - the following values were determined by experimentation */
2055 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2056 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2057 /* difference in size of the control area with and without the */
2058 /* style. - GA */
2059 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2060 if (infoPtr->dwStyle & CCS_VERT) {
2061 lpRect->left = 1;
2062 lpRect->top = lpBand->cxHeader + 4;
2063 lpRect->right = 1;
2064 lpRect->bottom = 0;
2066 else {
2067 lpRect->left = lpBand->cxHeader + 4;
2068 lpRect->top = 1;
2069 lpRect->right = 0;
2070 lpRect->bottom = 1;
2073 else {
2074 lpRect->left = lpBand->cxHeader;
2076 return 0;
2080 static inline LRESULT
2081 REBAR_GetBandCount (const REBAR_INFO *infoPtr)
2083 TRACE("band count %u!\n", infoPtr->uNumBands);
2085 return infoPtr->uNumBands;
2089 static LRESULT
2090 REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
2092 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2093 REBAR_BAND *lpBand;
2095 if (lprbbi == NULL)
2096 return FALSE;
2097 if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2098 return FALSE;
2099 if ((UINT)wParam >= infoPtr->uNumBands)
2100 return FALSE;
2102 TRACE("index %u (bUnicode=%d)\n", (UINT)wParam, bUnicode);
2104 /* copy band information */
2105 lpBand = &infoPtr->bands[(UINT)wParam];
2107 if (lprbbi->fMask & RBBIM_STYLE)
2108 lprbbi->fStyle = lpBand->fStyle;
2110 if (lprbbi->fMask & RBBIM_COLORS) {
2111 lprbbi->clrFore = lpBand->clrFore;
2112 lprbbi->clrBack = lpBand->clrBack;
2113 if (lprbbi->clrBack == CLR_DEFAULT)
2114 lprbbi->clrBack = infoPtr->clrBtnFace;
2117 if (lprbbi->fMask & RBBIM_TEXT) {
2118 if (bUnicode)
2119 Str_GetPtrW(lpBand->lpText, lprbbi->lpText, lprbbi->cch);
2120 else
2121 Str_GetPtrWtoA(lpBand->lpText, (LPSTR)lprbbi->lpText, lprbbi->cch);
2124 if (lprbbi->fMask & RBBIM_IMAGE)
2125 lprbbi->iImage = lpBand->iImage;
2127 if (lprbbi->fMask & RBBIM_CHILD)
2128 lprbbi->hwndChild = lpBand->hwndChild;
2130 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2131 lprbbi->cxMinChild = lpBand->cxMinChild;
2132 lprbbi->cyMinChild = lpBand->cyMinChild;
2133 /* to make tests pass we follow Windows behaviour and allow to read these fields only
2134 * for RBBS_VARIABLEHEIGHTS bands */
2135 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA) && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2136 lprbbi->cyChild = lpBand->cyChild;
2137 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2138 lprbbi->cyIntegral = lpBand->cyIntegral;
2142 if (lprbbi->fMask & RBBIM_SIZE)
2143 lprbbi->cx = lpBand->cx;
2145 if (lprbbi->fMask & RBBIM_BACKGROUND)
2146 lprbbi->hbmBack = lpBand->hbmBack;
2148 if (lprbbi->fMask & RBBIM_ID)
2149 lprbbi->wID = lpBand->wID;
2151 /* check for additional data */
2152 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2153 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2154 lprbbi->cxIdeal = lpBand->cxIdeal;
2156 if (lprbbi->fMask & RBBIM_LPARAM)
2157 lprbbi->lParam = lpBand->lParam;
2159 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2160 lprbbi->cxHeader = lpBand->cxHeader;
2163 REBAR_DumpBandInfo(lprbbi);
2165 return TRUE;
2169 static LRESULT
2170 REBAR_GetBarHeight (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2172 INT nHeight;
2174 nHeight = infoPtr->calcSize.cy;
2176 TRACE("height = %d\n", nHeight);
2178 return nHeight;
2182 static LRESULT
2183 REBAR_GetBarInfo (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2185 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
2187 if (lpInfo == NULL)
2188 return FALSE;
2190 if (lpInfo->cbSize < sizeof (REBARINFO))
2191 return FALSE;
2193 TRACE("getting bar info!\n");
2195 if (infoPtr->himl) {
2196 lpInfo->himl = infoPtr->himl;
2197 lpInfo->fMask |= RBIM_IMAGELIST;
2200 return TRUE;
2204 static inline LRESULT
2205 REBAR_GetBkColor (const REBAR_INFO *infoPtr)
2207 COLORREF clr = infoPtr->clrBk;
2209 if (clr == CLR_DEFAULT)
2210 clr = infoPtr->clrBtnFace;
2212 TRACE("background color 0x%06x!\n", clr);
2214 return clr;
2218 /* << REBAR_GetColorScheme >> */
2219 /* << REBAR_GetDropTarget >> */
2222 static LRESULT
2223 REBAR_GetPalette (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2225 FIXME("empty stub!\n");
2227 return 0;
2231 static LRESULT
2232 REBAR_GetRect (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2234 INT iBand = (INT)wParam;
2235 LPRECT lprc = (LPRECT)lParam;
2236 REBAR_BAND *lpBand;
2238 if ((iBand < 0) || ((UINT)iBand >= infoPtr->uNumBands))
2239 return FALSE;
2240 if (!lprc)
2241 return FALSE;
2243 lpBand = &infoPtr->bands[iBand];
2244 /* For CCS_VERT the coordinates will be swapped - like on Windows */
2245 CopyRect (lprc, &lpBand->rcBand);
2247 TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
2249 return TRUE;
2253 static inline LRESULT
2254 REBAR_GetRowCount (const REBAR_INFO *infoPtr)
2256 TRACE("%u\n", infoPtr->uNumRows);
2258 return infoPtr->uNumRows;
2262 static LRESULT
2263 REBAR_GetRowHeight (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2265 INT iRow = (INT)wParam;
2266 int j = 0, ret = 0;
2267 UINT i;
2268 REBAR_BAND *lpBand;
2270 for (i=0; i<infoPtr->uNumBands; i++) {
2271 lpBand = &infoPtr->bands[i];
2272 if (HIDDENBAND(lpBand)) continue;
2273 if (lpBand->iRow != iRow) continue;
2274 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2275 if (j > ret) ret = j;
2278 TRACE("row %d, height %d\n", iRow, ret);
2280 return ret;
2284 static inline LRESULT
2285 REBAR_GetTextColor (const REBAR_INFO *infoPtr)
2287 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2289 return infoPtr->clrText;
2293 static inline LRESULT
2294 REBAR_GetToolTips (const REBAR_INFO *infoPtr)
2296 return (LRESULT)infoPtr->hwndToolTip;
2300 static inline LRESULT
2301 REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
2303 TRACE("%s hwnd=%p\n",
2304 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2306 return infoPtr->bUnicode;
2310 static inline LRESULT
2311 REBAR_GetVersion (const REBAR_INFO *infoPtr)
2313 TRACE("version %d\n", infoPtr->iVersion);
2314 return infoPtr->iVersion;
2318 static LRESULT
2319 REBAR_HitTest (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2321 LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
2323 if (!lprbht)
2324 return -1;
2326 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2328 return lprbht->iBand;
2332 static LRESULT
2333 REBAR_IdToIndex (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2335 UINT i;
2337 if (infoPtr == NULL)
2338 return -1;
2340 if (infoPtr->uNumBands < 1)
2341 return -1;
2343 for (i = 0; i < infoPtr->uNumBands; i++) {
2344 if (infoPtr->bands[i].wID == (UINT)wParam) {
2345 TRACE("id %u is band %u found!\n", (UINT)wParam, i);
2346 return i;
2350 TRACE("id %u is not found\n", (UINT)wParam);
2351 return -1;
2355 static LRESULT
2356 REBAR_InsertBandT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
2358 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2359 UINT uIndex = (UINT)wParam;
2360 REBAR_BAND *lpBand;
2362 if (infoPtr == NULL)
2363 return FALSE;
2364 if (lprbbi == NULL)
2365 return FALSE;
2366 if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2367 return FALSE;
2369 /* trace the index as signed to see the -1 */
2370 TRACE("insert band at %d (bUnicode=%d)!\n", (INT)uIndex, bUnicode);
2371 REBAR_DumpBandInfo(lprbbi);
2373 infoPtr->bands = ReAlloc(infoPtr->bands, (infoPtr->uNumBands+1) * sizeof(REBAR_BAND));
2374 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
2375 uIndex = infoPtr->uNumBands;
2376 memmove(&infoPtr->bands[uIndex+1], &infoPtr->bands[uIndex],
2377 sizeof(REBAR_BAND) * (infoPtr->uNumBands - uIndex));
2378 infoPtr->uNumBands++;
2380 TRACE("index %u!\n", uIndex);
2382 /* initialize band (infoPtr->bands[uIndex])*/
2383 lpBand = &infoPtr->bands[uIndex];
2384 ZeroMemory(lpBand, sizeof(*lpBand));
2385 lpBand->clrFore = infoPtr->clrText;
2386 lpBand->clrBack = infoPtr->clrBk;
2387 lpBand->iImage = -1;
2389 REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
2390 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2391 if (bUnicode)
2392 Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
2393 else
2394 Str_SetPtrAtoW(&lpBand->lpText, (LPSTR)lprbbi->lpText);
2397 REBAR_ValidateBand (infoPtr, lpBand);
2398 /* On insert of second band, revalidate band 1 to possible add gripper */
2399 if (infoPtr->uNumBands == 2)
2400 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2402 REBAR_DumpBand (infoPtr);
2404 REBAR_Layout(infoPtr, NULL);
2405 InvalidateRect(infoPtr->hwndSelf, 0, TRUE);
2407 return TRUE;
2411 static LRESULT
2412 REBAR_MaximizeBand (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2414 REBAR_BAND *lpBand;
2415 UINT uBand = (UINT) wParam;
2416 int iRowBegin, iRowEnd;
2417 int cxDesired, extra, extraOrig;
2418 int cxIdealBand;
2420 /* Validate */
2421 if ((infoPtr->uNumBands == 0) ||
2422 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
2423 /* error !!! */
2424 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
2425 (INT)uBand, infoPtr->uNumBands);
2426 return FALSE;
2429 lpBand = &infoPtr->bands[uBand];
2431 cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
2432 if (lParam && (lpBand->cxEffective < cxIdealBand))
2433 cxDesired = cxIdealBand;
2434 else
2435 cxDesired = infoPtr->calcSize.cx;
2437 iRowBegin = get_row_begin_for_band(infoPtr, uBand);
2438 iRowEnd = get_row_end_for_band(infoPtr, uBand);
2439 extraOrig = extra = cxDesired - lpBand->cxEffective;
2440 if (extra > 0)
2441 extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, uBand, extra, TRUE);
2442 if (extra > 0)
2443 extra = REBAR_ShrinkBandsLTR(infoPtr, next_band(infoPtr, uBand), iRowEnd, extra, TRUE);
2444 lpBand->cxEffective += extraOrig - extra;
2445 lpBand->cx = lpBand->cxEffective;
2446 TRACE("(%ld, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", wParam, lParam, cxDesired, lpBand->cx, extraOrig, extra);
2447 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2449 if (infoPtr->dwStyle & CCS_VERT)
2450 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2451 else
2452 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2453 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2454 return TRUE;
2459 static LRESULT
2460 REBAR_MinimizeBand (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2462 REBAR_BAND *lpBand;
2463 UINT uBand = (UINT) wParam;
2464 int iPrev, iRowBegin, iRowEnd;
2466 /* A "minimize" band is equivalent to "dragging" the gripper
2467 * of than band to the right till the band is only the size
2468 * of the cxHeader.
2471 /* Validate */
2472 if ((infoPtr->uNumBands == 0) ||
2473 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
2474 /* error !!! */
2475 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
2476 (INT)uBand, infoPtr->uNumBands);
2477 return FALSE;
2480 /* compute amount of movement and validate */
2481 lpBand = &infoPtr->bands[uBand];
2482 iPrev = prev_band(infoPtr, uBand);
2483 /* if first band in row */
2484 if (iPrev < 0 || infoPtr->bands[iPrev].iRow != lpBand->iRow) {
2485 int iNext = next_band(infoPtr, uBand);
2486 if (iNext < infoPtr->uNumBands && infoPtr->bands[iNext].iRow == lpBand->iRow) {
2487 TRACE("(%ld): Minimizing the first band in row is by maximizing the second\n", wParam);
2488 REBAR_MaximizeBand(infoPtr, iNext, FALSE);
2490 else
2491 TRACE("(%ld): Only one band in row - nothing to do\n", wParam);
2492 return TRUE;
2495 infoPtr->bands[iPrev].cxEffective += lpBand->cxEffective - lpBand->lcx;
2496 infoPtr->bands[iPrev].cx = infoPtr->bands[iPrev].cxEffective;
2497 lpBand->cx = lpBand->cxEffective = lpBand->lcx;
2499 iRowBegin = get_row_begin_for_band(infoPtr, uBand);
2500 iRowEnd = get_row_end_for_band(infoPtr, uBand);
2501 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2503 if (infoPtr->dwStyle & CCS_VERT)
2504 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2505 else
2506 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2507 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2508 return FALSE;
2512 static LRESULT
2513 REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2515 REBAR_BAND *oldBands = infoPtr->bands;
2516 REBAR_BAND holder;
2517 UINT uFrom = (UINT)wParam;
2518 UINT uTo = (UINT)lParam;
2520 /* Validate */
2521 if ((infoPtr->uNumBands == 0) ||
2522 ((INT)uFrom < 0) || (uFrom >= infoPtr->uNumBands) ||
2523 ((INT)uTo < 0) || (uTo >= infoPtr->uNumBands)) {
2524 /* error !!! */
2525 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
2526 (INT)uFrom, (INT)uTo, infoPtr->uNumBands);
2527 return FALSE;
2530 /* save one to be moved */
2531 holder = oldBands[uFrom];
2533 /* close up rest of bands (pseudo delete) */
2534 if (uFrom < infoPtr->uNumBands - 1) {
2535 memcpy (&oldBands[uFrom], &oldBands[uFrom+1],
2536 (infoPtr->uNumBands - uFrom - 1) * sizeof(REBAR_BAND));
2539 /* allocate new space and copy rest of bands into it */
2540 infoPtr->bands =
2541 (REBAR_BAND *)Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
2543 /* pre insert copy */
2544 if (uTo > 0) {
2545 memcpy (&infoPtr->bands[0], &oldBands[0],
2546 uTo * sizeof(REBAR_BAND));
2549 /* set moved band */
2550 infoPtr->bands[uTo] = holder;
2552 /* post copy */
2553 if (uTo < infoPtr->uNumBands - 1) {
2554 memcpy (&infoPtr->bands[uTo+1], &oldBands[uTo],
2555 (infoPtr->uNumBands - uTo - 1) * sizeof(REBAR_BAND));
2558 Free (oldBands);
2560 TRACE("moved band %d to index %d\n", uFrom, uTo);
2561 REBAR_DumpBand (infoPtr);
2563 /* **************************************************** */
2564 /* */
2565 /* We do not do a REBAR_Layout here because the native */
2566 /* control does not do that. The actual layout and */
2567 /* repaint is done by the *next* real action, ex.: */
2568 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
2569 /* */
2570 /* **************************************************** */
2572 return TRUE;
2576 /* return TRUE if two strings are different */
2577 static BOOL
2578 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
2580 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
2583 static LRESULT
2584 REBAR_SetBandInfoT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
2586 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2587 REBAR_BAND *lpBand;
2588 BOOL bChanged;
2590 if (lprbbi == NULL)
2591 return FALSE;
2592 if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2593 return FALSE;
2594 if ((UINT)wParam >= infoPtr->uNumBands)
2595 return FALSE;
2597 TRACE("index %u\n", (UINT)wParam);
2598 REBAR_DumpBandInfo (lprbbi);
2600 /* set band information */
2601 lpBand = &infoPtr->bands[(UINT)wParam];
2603 bChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2604 if (lprbbi->fMask & RBBIM_TEXT) {
2605 LPWSTR wstr = NULL;
2606 if (bUnicode)
2607 Str_SetPtrW(&wstr, lprbbi->lpText);
2608 else
2609 Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
2611 if (REBAR_strdifW(wstr, lpBand->lpText)) {
2612 Free(lpBand->lpText);
2613 lpBand->lpText = wstr;
2614 bChanged = TRUE;
2616 else
2617 Free(wstr);
2620 REBAR_ValidateBand (infoPtr, lpBand);
2622 REBAR_DumpBand (infoPtr);
2624 if (bChanged && (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE))) {
2625 REBAR_Layout(infoPtr, NULL);
2626 InvalidateRect(infoPtr->hwndSelf, 0, 1);
2629 return TRUE;
2633 static LRESULT
2634 REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2636 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
2637 REBAR_BAND *lpBand;
2638 UINT i;
2640 if (lpInfo == NULL)
2641 return FALSE;
2643 if (lpInfo->cbSize < sizeof (REBARINFO))
2644 return FALSE;
2646 TRACE("setting bar info!\n");
2648 if (lpInfo->fMask & RBIM_IMAGELIST) {
2649 infoPtr->himl = lpInfo->himl;
2650 if (infoPtr->himl) {
2651 INT cx, cy;
2652 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
2653 infoPtr->imageSize.cx = cx;
2654 infoPtr->imageSize.cy = cy;
2656 else {
2657 infoPtr->imageSize.cx = 0;
2658 infoPtr->imageSize.cy = 0;
2660 TRACE("new image cx=%d, cy=%d\n", infoPtr->imageSize.cx,
2661 infoPtr->imageSize.cy);
2664 /* revalidate all bands to reset flags for images in headers of bands */
2665 for (i=0; i<infoPtr->uNumBands; i++) {
2666 lpBand = &infoPtr->bands[i];
2667 REBAR_ValidateBand (infoPtr, lpBand);
2670 return TRUE;
2674 static LRESULT
2675 REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2677 COLORREF clrTemp;
2679 clrTemp = infoPtr->clrBk;
2680 infoPtr->clrBk = (COLORREF)lParam;
2682 TRACE("background color 0x%06x!\n", infoPtr->clrBk);
2684 return clrTemp;
2688 /* << REBAR_SetColorScheme >> */
2689 /* << REBAR_SetPalette >> */
2692 static LRESULT
2693 REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2695 HWND hwndTemp = infoPtr->hwndNotify;
2697 infoPtr->hwndNotify = (HWND)wParam;
2699 return (LRESULT)hwndTemp;
2703 static LRESULT
2704 REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2706 COLORREF clrTemp;
2708 clrTemp = infoPtr->clrText;
2709 infoPtr->clrText = (COLORREF)lParam;
2711 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2713 return clrTemp;
2717 /* << REBAR_SetTooltips >> */
2720 static inline LRESULT
2721 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, WPARAM wParam)
2723 BOOL bTemp = infoPtr->bUnicode;
2725 TRACE("to %s hwnd=%p, was %s\n",
2726 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf,
2727 (bTemp) ? "TRUE" : "FALSE");
2729 infoPtr->bUnicode = (BOOL)wParam;
2731 return bTemp;
2735 static LRESULT
2736 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
2738 INT iOldVersion = infoPtr->iVersion;
2740 if (iVersion > COMCTL32_VERSION)
2741 return -1;
2743 infoPtr->iVersion = iVersion;
2745 TRACE("new version %d\n", iVersion);
2747 return iOldVersion;
2751 static LRESULT
2752 REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2754 REBAR_BAND *lpBand;
2756 if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
2757 return FALSE;
2759 lpBand = &infoPtr->bands[(INT)wParam];
2761 if ((BOOL)lParam) {
2762 TRACE("show band %d\n", (INT)wParam);
2763 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
2764 if (IsWindow (lpBand->hwndChild))
2765 ShowWindow (lpBand->hwndChild, SW_SHOW);
2767 else {
2768 TRACE("hide band %d\n", (INT)wParam);
2769 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
2770 if (IsWindow (lpBand->hwndChild))
2771 ShowWindow (lpBand->hwndChild, SW_HIDE);
2774 REBAR_Layout(infoPtr, NULL);
2775 InvalidateRect(infoPtr->hwndSelf, 0, 1);
2777 return TRUE;
2781 static LRESULT
2782 REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2784 LPRECT lpRect = (LPRECT)lParam;
2786 if (lpRect == NULL)
2787 return FALSE;
2789 TRACE("[%s]\n", wine_dbgstr_rect(lpRect));
2790 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, lpRect));
2791 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
2792 return TRUE;
2797 static LRESULT
2798 REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2800 LPCREATESTRUCTW cs = (LPCREATESTRUCTW) lParam;
2801 RECT wnrc1, clrc1;
2802 HTHEME theme;
2804 if (TRACE_ON(rebar)) {
2805 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
2806 GetClientRect(infoPtr->hwndSelf, &clrc1);
2807 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
2808 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
2809 cs->x, cs->y, cs->cx, cs->cy);
2812 TRACE("created!\n");
2814 if ((theme = OpenThemeData (infoPtr->hwndSelf, themeClass)))
2816 /* native seems to clear WS_BORDER when themed */
2817 infoPtr->dwStyle &= ~WS_BORDER;
2820 return 0;
2824 static LRESULT
2825 REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2827 REBAR_BAND *lpBand;
2828 UINT i;
2831 /* free rebar bands */
2832 if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
2833 /* clean up each band */
2834 for (i = 0; i < infoPtr->uNumBands; i++) {
2835 lpBand = &infoPtr->bands[i];
2837 /* delete text strings */
2838 Free (lpBand->lpText);
2839 lpBand->lpText = NULL;
2840 /* destroy child window */
2841 DestroyWindow (lpBand->hwndChild);
2844 /* free band array */
2845 Free (infoPtr->bands);
2846 infoPtr->bands = NULL;
2849 DestroyCursor (infoPtr->hcurArrow);
2850 DestroyCursor (infoPtr->hcurHorz);
2851 DestroyCursor (infoPtr->hcurVert);
2852 DestroyCursor (infoPtr->hcurDrag);
2853 if(infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
2854 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
2856 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2858 /* free rebar info data */
2859 Free (infoPtr);
2860 TRACE("destroyed!\n");
2861 return 0;
2865 static LRESULT
2866 REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2868 RECT cliprect;
2870 if (GetClipBox ( (HDC)wParam, &cliprect))
2871 return REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &cliprect);
2872 return 0;
2876 static LRESULT
2877 REBAR_GetFont (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2879 return (LRESULT)infoPtr->hFont;
2882 static LRESULT
2883 REBAR_PushChevron(const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2885 if ((UINT)wParam < infoPtr->uNumBands)
2887 NMREBARCHEVRON nmrbc;
2888 REBAR_BAND *lpBand = &infoPtr->bands[wParam];
2890 TRACE("Pressed chevron on band %ld\n", wParam);
2892 /* redraw chevron in pushed state */
2893 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
2894 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
2895 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
2897 /* notify app so it can display a popup menu or whatever */
2898 nmrbc.uBand = wParam;
2899 nmrbc.wID = lpBand->wID;
2900 nmrbc.lParam = lpBand->lParam;
2901 nmrbc.rc = lpBand->rcChevron;
2902 nmrbc.lParamNM = lParam;
2903 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
2905 /* redraw chevron in previous state */
2906 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
2907 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
2909 return TRUE;
2911 return FALSE;
2914 static LRESULT
2915 REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2917 REBAR_BAND *lpBand;
2918 UINT htFlags;
2919 INT iHitBand;
2920 POINT ptMouseDown;
2921 ptMouseDown.x = (short)LOWORD(lParam);
2922 ptMouseDown.y = (short)HIWORD(lParam);
2924 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
2925 lpBand = &infoPtr->bands[iHitBand];
2927 if (htFlags == RBHT_CHEVRON)
2929 REBAR_PushChevron(infoPtr, iHitBand, 0);
2931 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
2933 TRACE("Starting drag\n");
2935 SetCapture (infoPtr->hwndSelf);
2936 infoPtr->iGrabbedBand = iHitBand;
2938 /* save off the LOWORD and HIWORD of lParam as initial x,y */
2939 infoPtr->dragStart.x = (short)LOWORD(lParam);
2940 infoPtr->dragStart.y = (short)HIWORD(lParam);
2941 infoPtr->dragNow = infoPtr->dragStart;
2942 if (infoPtr->dwStyle & CCS_VERT)
2943 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
2944 else
2945 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
2947 return 0;
2950 static LRESULT
2951 REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2953 if (infoPtr->iGrabbedBand >= 0)
2955 NMHDR layout;
2956 RECT rect;
2958 infoPtr->dragStart.x = 0;
2959 infoPtr->dragStart.y = 0;
2960 infoPtr->dragNow = infoPtr->dragStart;
2962 ReleaseCapture ();
2964 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
2965 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
2966 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
2967 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
2970 infoPtr->iGrabbedBand = -1;
2972 GetClientRect(infoPtr->hwndSelf, &rect);
2973 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2976 return 0;
2979 static LRESULT
2980 REBAR_MouseLeave (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2982 if (infoPtr->ichevronhotBand >= 0)
2984 REBAR_BAND *lpChevronBand = &infoPtr->bands[infoPtr->ichevronhotBand];
2985 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
2987 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
2988 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
2991 infoPtr->iOldBand = -1;
2992 infoPtr->ichevronhotBand = -2;
2994 return TRUE;
2997 static LRESULT
2998 REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3000 REBAR_BAND *lpChevronBand;
3001 POINT ptMove;
3003 ptMove.x = (short)LOWORD(lParam);
3004 ptMove.y = (short)HIWORD(lParam);
3006 /* if we are currently dragging a band */
3007 if (infoPtr->iGrabbedBand >= 0)
3009 REBAR_BAND *band1, *band2;
3010 int yPtMove = (infoPtr->dwStyle & CCS_VERT ? ptMove.x : ptMove.y);
3012 if (GetCapture() != infoPtr->hwndSelf)
3013 ERR("We are dragging but haven't got capture?!?\n");
3015 band1 = &infoPtr->bands[infoPtr->iGrabbedBand-1];
3016 band2 = &infoPtr->bands[infoPtr->iGrabbedBand];
3018 /* if mouse did not move much, exit */
3019 if ((abs(ptMove.x - infoPtr->dragNow.x) <= mindragx) &&
3020 (abs(ptMove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3022 /* Test for valid drag case - must not be first band in row */
3023 if ((yPtMove < band2->rcBand.top) ||
3024 (yPtMove > band2->rcBand.bottom) ||
3025 ((infoPtr->iGrabbedBand > 0) && (band1->iRow != band2->iRow))) {
3026 FIXME("Cannot drag to other rows yet!!\n");
3028 else {
3029 REBAR_HandleLRDrag (infoPtr, &ptMove);
3032 else
3034 INT iHitBand;
3035 UINT htFlags;
3036 TRACKMOUSEEVENT trackinfo;
3038 REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
3040 if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
3042 lpChevronBand = &infoPtr->bands[infoPtr->ichevronhotBand];
3043 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3045 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3046 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3048 infoPtr->ichevronhotBand = -2;
3051 if (htFlags == RBHT_CHEVRON)
3053 /* fill in the TRACKMOUSEEVENT struct */
3054 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
3055 trackinfo.dwFlags = TME_QUERY;
3056 trackinfo.hwndTrack = infoPtr->hwndSelf;
3057 trackinfo.dwHoverTime = 0;
3059 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
3060 _TrackMouseEvent(&trackinfo);
3062 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
3063 if(!(trackinfo.dwFlags & TME_LEAVE))
3065 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
3067 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
3068 /* and can properly deactivate the hot chevron */
3069 _TrackMouseEvent(&trackinfo);
3072 lpChevronBand = &infoPtr->bands[iHitBand];
3073 if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
3075 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
3076 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3077 infoPtr->ichevronhotBand = iHitBand;
3080 infoPtr->iOldBand = iHitBand;
3083 return 0;
3087 static inline LRESULT
3088 REBAR_NCCalcSize (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3090 HTHEME theme;
3091 RECT *rect = (RECT *)lParam;
3093 if (infoPtr->dwStyle & WS_BORDER) {
3094 rect->left = min(rect->left + GetSystemMetrics(SM_CXEDGE), rect->right);
3095 rect->right = max(rect->right - GetSystemMetrics(SM_CXEDGE), rect->left);
3096 rect->top = min(rect->top + GetSystemMetrics(SM_CYEDGE), rect->bottom);
3097 rect->bottom = max(rect->bottom - GetSystemMetrics(SM_CYEDGE), rect->top);
3099 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3101 /* FIXME: should use GetThemeInt */
3102 rect->top = min(rect->top + 1, rect->bottom);
3104 TRACE("new client=(%s)\n", wine_dbgstr_rect(rect));
3105 return 0;
3109 static LRESULT
3110 REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3112 LPCREATESTRUCTW cs = (LPCREATESTRUCTW) lParam;
3113 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3114 RECT wnrc1, clrc1;
3115 NONCLIENTMETRICSW ncm;
3116 HFONT tfont;
3118 if (infoPtr != NULL) {
3119 ERR("Strange info structure pointer *not* NULL\n");
3120 return FALSE;
3123 if (TRACE_ON(rebar)) {
3124 GetWindowRect(hwnd, &wnrc1);
3125 GetClientRect(hwnd, &clrc1);
3126 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
3127 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
3128 cs->x, cs->y, cs->cx, cs->cy);
3131 /* allocate memory for info structure */
3132 infoPtr = (REBAR_INFO *)Alloc (sizeof(REBAR_INFO));
3133 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
3135 /* initialize info structure - initial values are 0 */
3136 infoPtr->clrBk = CLR_NONE;
3137 infoPtr->clrText = CLR_NONE;
3138 infoPtr->clrBtnText = GetSysColor (COLOR_BTNTEXT);
3139 infoPtr->clrBtnFace = GetSysColor (COLOR_BTNFACE);
3140 infoPtr->iOldBand = -1;
3141 infoPtr->ichevronhotBand = -2;
3142 infoPtr->iGrabbedBand = -1;
3143 infoPtr->hwndSelf = hwnd;
3144 infoPtr->DoRedraw = TRUE;
3145 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3146 infoPtr->hcurHorz = LoadCursorW (0, (LPWSTR)IDC_SIZEWE);
3147 infoPtr->hcurVert = LoadCursorW (0, (LPWSTR)IDC_SIZENS);
3148 infoPtr->hcurDrag = LoadCursorW (0, (LPWSTR)IDC_SIZE);
3149 infoPtr->fStatus = 0;
3150 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3152 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3153 REBAR_NotifyFormat(infoPtr, 0, NF_REQUERY);
3155 /* Stow away the original style */
3156 infoPtr->orgStyle = cs->style;
3157 /* add necessary styles to the requested styles */
3158 infoPtr->dwStyle = cs->style | WS_VISIBLE;
3159 if ((infoPtr->dwStyle & CCS_LAYOUT_MASK) == 0)
3160 infoPtr->dwStyle |= CCS_TOP;
3161 SetWindowLongW (hwnd, GWL_STYLE, infoPtr->dwStyle);
3163 /* get font handle for Caption Font */
3164 ncm.cbSize = sizeof(ncm);
3165 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
3166 /* if the font is bold, set to normal */
3167 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3168 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3170 tfont = CreateFontIndirectW (&ncm.lfCaptionFont);
3171 if (tfont) {
3172 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3175 /* native does:
3176 GetSysColor (numerous);
3177 GetSysColorBrush (numerous) (see WM_SYSCOLORCHANGE);
3178 *GetStockObject (SYSTEM_FONT);
3179 *SetWindowLong (hwnd, 0, info ptr);
3180 *WM_NOTIFYFORMAT;
3181 *SetWindowLong (hwnd, GWL_STYLE, style+0x10000001);
3182 WS_VISIBLE = 0x10000000;
3183 CCS_TOP = 0x00000001;
3184 *SystemParametersInfo (SPI_GETNONCLIENTMETRICS...);
3185 *CreateFontIndirect (lfCaptionFont from above);
3186 GetDC ();
3187 SelectObject (hdc, fontabove);
3188 GetTextMetrics (hdc, ); guessing is tmHeight
3189 SelectObject (hdc, oldfont);
3190 ReleaseDC ();
3191 GetWindowRect ();
3192 MapWindowPoints (0, parent, rectabove, 2);
3193 GetWindowRect ();
3194 GetClientRect ();
3195 ClientToScreen (clientrect);
3196 SetWindowPos (hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER);
3198 return TRUE;
3202 static LRESULT
3203 REBAR_NCHitTest (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3205 NMMOUSE nmmouse;
3206 POINT clpt;
3207 INT i;
3208 UINT scrap;
3209 LRESULT ret = HTCLIENT;
3212 * Differences from doc at MSDN (as observed with version 4.71 of
3213 * comctl32.dll
3214 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3215 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3216 * 3. native always seems to return HTCLIENT if notify return is 0.
3219 clpt.x = (short)LOWORD(lParam);
3220 clpt.y = (short)HIWORD(lParam);
3221 ScreenToClient (infoPtr->hwndSelf, &clpt);
3222 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3223 (INT *)&nmmouse.dwItemSpec);
3224 nmmouse.dwItemData = 0;
3225 nmmouse.pt = clpt;
3226 nmmouse.dwHitInfo = 0;
3227 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3228 TRACE("notify changed return value from %ld to %d\n",
3229 ret, i);
3230 ret = (LRESULT) i;
3232 TRACE("returning %ld, client point (%d,%d)\n", ret, clpt.x, clpt.y);
3233 return ret;
3237 static LRESULT
3238 REBAR_NCPaint (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3240 RECT rcWindow;
3241 HDC hdc;
3242 HTHEME theme;
3244 if (infoPtr->dwStyle & WS_MINIMIZE)
3245 return 0; /* Nothing to do */
3247 if (infoPtr->dwStyle & WS_BORDER) {
3249 /* adjust rectangle and draw the necessary edge */
3250 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3251 return 0;
3252 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3253 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3254 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3255 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3256 ReleaseDC( infoPtr->hwndSelf, hdc );
3258 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3260 /* adjust rectangle and draw the necessary edge */
3261 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3262 return 0;
3263 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3264 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3265 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3266 DrawThemeEdge (theme, hdc, 0, 0, &rcWindow, BDR_RAISEDINNER, BF_TOP, NULL);
3267 ReleaseDC( infoPtr->hwndSelf, hdc );
3270 return 0;
3274 static LRESULT
3275 REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3277 INT i;
3279 if (lParam == NF_REQUERY) {
3280 i = SendMessageW(REBAR_GetNotifyParent (infoPtr),
3281 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
3282 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
3283 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
3284 i = NFR_ANSI;
3286 infoPtr->bUnicode = (i == NFR_UNICODE) ? 1 : 0;
3287 return (LRESULT)i;
3289 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3293 static LRESULT
3294 REBAR_Paint (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3296 HDC hdc = (HDC)wParam;
3298 if (hdc) {
3299 TRACE("painting\n");
3300 REBAR_Refresh (infoPtr, hdc);
3301 } else {
3302 PAINTSTRUCT ps;
3303 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
3304 TRACE("painting (%s)\n", wine_dbgstr_rect(&ps.rcPaint));
3305 if (ps.fErase) {
3306 /* Erase area of paint if requested */
3307 REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &ps.rcPaint);
3309 REBAR_Refresh (infoPtr, hdc);
3310 EndPaint (infoPtr->hwndSelf, &ps);
3313 return 0;
3317 static LRESULT
3318 REBAR_SetCursor (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3320 POINT pt;
3321 UINT flags;
3323 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
3325 GetCursorPos (&pt);
3326 ScreenToClient (infoPtr->hwndSelf, &pt);
3328 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
3330 if (flags == RBHT_GRABBER) {
3331 if ((infoPtr->dwStyle & CCS_VERT) &&
3332 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
3333 SetCursor (infoPtr->hcurVert);
3334 else
3335 SetCursor (infoPtr->hcurHorz);
3337 else if (flags != RBHT_CLIENT)
3338 SetCursor (infoPtr->hcurArrow);
3340 return 0;
3344 static LRESULT
3345 REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3347 REBAR_BAND *lpBand;
3348 UINT i;
3350 infoPtr->hFont = (HFONT)wParam;
3352 /* revalidate all bands to change sizes of text in headers of bands */
3353 for (i=0; i<infoPtr->uNumBands; i++) {
3354 lpBand = &infoPtr->bands[i];
3355 REBAR_ValidateBand (infoPtr, lpBand);
3358 REBAR_Layout(infoPtr, NULL);
3359 return 0;
3363 static inline LRESULT
3364 REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3365 /*****************************************************
3367 * Function;
3368 * Handles the WM_SETREDRAW message.
3370 * Documentation:
3371 * According to testing V4.71 of COMCTL32 returns the
3372 * *previous* status of the redraw flag (either 0 or -1)
3373 * instead of the MSDN documented value of 0 if handled
3375 *****************************************************/
3377 BOOL oldredraw = infoPtr->DoRedraw;
3379 TRACE("set to %s, fStatus=%08x\n",
3380 (wParam) ? "TRUE" : "FALSE", infoPtr->fStatus);
3381 infoPtr->DoRedraw = (BOOL) wParam;
3382 if (wParam) {
3383 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
3384 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
3385 REBAR_ForceResize (infoPtr);
3386 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
3388 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
3390 return (oldredraw) ? -1 : 0;
3394 static LRESULT
3395 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3397 TRACE("wParam=%lx, lParam=%lx\n", wParam, lParam);
3399 /* avoid auto resize infinite recursion */
3400 if (infoPtr->fStatus & AUTO_RESIZE) {
3401 infoPtr->fStatus &= ~AUTO_RESIZE;
3402 TRACE("AUTO_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
3403 infoPtr->fStatus, lParam);
3404 return 0;
3407 /* FIXME: wrong */
3408 if (infoPtr->dwStyle & RBS_AUTOSIZE) {
3409 NMRBAUTOSIZE autosize;
3411 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
3412 autosize.fChanged = 0; /* ??? */
3413 autosize.rcActual = autosize.rcTarget; /* ??? */
3414 REBAR_Notify((NMHDR *) &autosize, infoPtr, RBN_AUTOSIZE);
3415 TRACE("RBN_AUTOSIZE client=(%d,%d), lp=%08lx\n",
3416 autosize.rcTarget.right, autosize.rcTarget.bottom, lParam);
3419 REBAR_Layout(infoPtr, NULL);
3421 return 0;
3425 static LRESULT
3426 REBAR_StyleChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3428 STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
3430 TRACE("current style=%08x, styleOld=%08x, style being set to=%08x\n",
3431 infoPtr->dwStyle, ss->styleOld, ss->styleNew);
3432 infoPtr->orgStyle = infoPtr->dwStyle = ss->styleNew;
3433 if (GetWindowTheme (infoPtr->hwndSelf))
3434 infoPtr->dwStyle &= ~WS_BORDER;
3435 /* maybe it should be COMMON_STYLES like in toolbar */
3436 if ((ss->styleNew ^ ss->styleOld) & CCS_VERT)
3437 REBAR_Layout(infoPtr, NULL);
3439 return FALSE;
3442 /* update theme after a WM_THEMECHANGED message */
3443 static LRESULT theme_changed (REBAR_INFO* infoPtr)
3445 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
3446 CloseThemeData (theme);
3447 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
3448 /* WS_BORDER disappears when theming is enabled and reappears when
3449 * disabled... */
3450 infoPtr->dwStyle &= ~WS_BORDER;
3451 infoPtr->dwStyle |= theme ? 0 : (infoPtr->orgStyle & WS_BORDER);
3452 return 0;
3455 static LRESULT
3456 REBAR_WindowPosChanged (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3458 LRESULT ret;
3459 RECT rc;
3461 ret = DefWindowProcW(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
3462 wParam, lParam);
3463 GetWindowRect(infoPtr->hwndSelf, &rc);
3464 TRACE("hwnd %p new pos (%s)\n", infoPtr->hwndSelf, wine_dbgstr_rect(&rc));
3465 return ret;
3469 static LRESULT WINAPI
3470 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3472 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3474 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
3475 hwnd, uMsg, wParam, lParam);
3476 if (!infoPtr && (uMsg != WM_NCCREATE))
3477 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3478 switch (uMsg)
3480 /* case RB_BEGINDRAG: */
3482 case RB_DELETEBAND:
3483 return REBAR_DeleteBand (infoPtr, wParam, lParam);
3485 /* case RB_DRAGMOVE: */
3486 /* case RB_ENDDRAG: */
3488 case RB_GETBANDBORDERS:
3489 return REBAR_GetBandBorders (infoPtr, wParam, lParam);
3491 case RB_GETBANDCOUNT:
3492 return REBAR_GetBandCount (infoPtr);
3494 case RB_GETBANDINFO_OLD:
3495 case RB_GETBANDINFOA:
3496 return REBAR_GetBandInfoT(infoPtr, wParam, lParam, FALSE);
3498 case RB_GETBANDINFOW:
3499 return REBAR_GetBandInfoT(infoPtr, wParam, lParam, TRUE);
3501 case RB_GETBARHEIGHT:
3502 return REBAR_GetBarHeight (infoPtr, wParam, lParam);
3504 case RB_GETBARINFO:
3505 return REBAR_GetBarInfo (infoPtr, wParam, lParam);
3507 case RB_GETBKCOLOR:
3508 return REBAR_GetBkColor (infoPtr);
3510 /* case RB_GETCOLORSCHEME: */
3511 /* case RB_GETDROPTARGET: */
3513 case RB_GETPALETTE:
3514 return REBAR_GetPalette (infoPtr, wParam, lParam);
3516 case RB_GETRECT:
3517 return REBAR_GetRect (infoPtr, wParam, lParam);
3519 case RB_GETROWCOUNT:
3520 return REBAR_GetRowCount (infoPtr);
3522 case RB_GETROWHEIGHT:
3523 return REBAR_GetRowHeight (infoPtr, wParam, lParam);
3525 case RB_GETTEXTCOLOR:
3526 return REBAR_GetTextColor (infoPtr);
3528 case RB_GETTOOLTIPS:
3529 return REBAR_GetToolTips (infoPtr);
3531 case RB_GETUNICODEFORMAT:
3532 return REBAR_GetUnicodeFormat (infoPtr);
3534 case CCM_GETVERSION:
3535 return REBAR_GetVersion (infoPtr);
3537 case RB_HITTEST:
3538 return REBAR_HitTest (infoPtr, wParam, lParam);
3540 case RB_IDTOINDEX:
3541 return REBAR_IdToIndex (infoPtr, wParam, lParam);
3543 case RB_INSERTBANDA:
3544 return REBAR_InsertBandT(infoPtr, wParam, lParam, FALSE);
3546 case RB_INSERTBANDW:
3547 return REBAR_InsertBandT(infoPtr, wParam, lParam, TRUE);
3549 case RB_MAXIMIZEBAND:
3550 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
3552 case RB_MINIMIZEBAND:
3553 return REBAR_MinimizeBand (infoPtr, wParam, lParam);
3555 case RB_MOVEBAND:
3556 return REBAR_MoveBand (infoPtr, wParam, lParam);
3558 case RB_PUSHCHEVRON:
3559 return REBAR_PushChevron (infoPtr, wParam, lParam);
3561 case RB_SETBANDINFOA:
3562 return REBAR_SetBandInfoT(infoPtr, wParam, lParam, FALSE);
3564 case RB_SETBANDINFOW:
3565 return REBAR_SetBandInfoT(infoPtr, wParam, lParam, TRUE);
3567 case RB_SETBARINFO:
3568 return REBAR_SetBarInfo (infoPtr, wParam, lParam);
3570 case RB_SETBKCOLOR:
3571 return REBAR_SetBkColor (infoPtr, wParam, lParam);
3573 /* case RB_SETCOLORSCHEME: */
3574 /* case RB_SETPALETTE: */
3575 /* return REBAR_GetPalette (infoPtr, wParam, lParam); */
3577 case RB_SETPARENT:
3578 return REBAR_SetParent (infoPtr, wParam, lParam);
3580 case RB_SETTEXTCOLOR:
3581 return REBAR_SetTextColor (infoPtr, wParam, lParam);
3583 /* case RB_SETTOOLTIPS: */
3585 case RB_SETUNICODEFORMAT:
3586 return REBAR_SetUnicodeFormat (infoPtr, wParam);
3588 case CCM_SETVERSION:
3589 return REBAR_SetVersion (infoPtr, (INT)wParam);
3591 case RB_SHOWBAND:
3592 return REBAR_ShowBand (infoPtr, wParam, lParam);
3594 case RB_SIZETORECT:
3595 return REBAR_SizeToRect (infoPtr, wParam, lParam);
3598 /* Messages passed to parent */
3599 case WM_COMMAND:
3600 case WM_DRAWITEM:
3601 case WM_NOTIFY:
3602 return SendMessageW(REBAR_GetNotifyParent (infoPtr), uMsg, wParam, lParam);
3605 /* case WM_CHARTOITEM: supported according to ControlSpy */
3607 case WM_CREATE:
3608 return REBAR_Create (infoPtr, wParam, lParam);
3610 case WM_DESTROY:
3611 return REBAR_Destroy (infoPtr, wParam, lParam);
3613 case WM_ERASEBKGND:
3614 return REBAR_EraseBkGnd (infoPtr, wParam, lParam);
3616 case WM_GETFONT:
3617 return REBAR_GetFont (infoPtr, wParam, lParam);
3619 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
3621 case WM_LBUTTONDOWN:
3622 return REBAR_LButtonDown (infoPtr, wParam, lParam);
3624 case WM_LBUTTONUP:
3625 return REBAR_LButtonUp (infoPtr, wParam, lParam);
3627 /* case WM_MEASUREITEM: supported according to ControlSpy */
3629 case WM_MOUSEMOVE:
3630 return REBAR_MouseMove (infoPtr, wParam, lParam);
3632 case WM_MOUSELEAVE:
3633 return REBAR_MouseLeave (infoPtr, wParam, lParam);
3635 case WM_NCCALCSIZE:
3636 return REBAR_NCCalcSize (infoPtr, wParam, lParam);
3638 case WM_NCCREATE:
3639 return REBAR_NCCreate (hwnd, wParam, lParam);
3641 case WM_NCHITTEST:
3642 return REBAR_NCHitTest (infoPtr, wParam, lParam);
3644 case WM_NCPAINT:
3645 return REBAR_NCPaint (infoPtr, wParam, lParam);
3647 case WM_NOTIFYFORMAT:
3648 return REBAR_NotifyFormat (infoPtr, wParam, lParam);
3650 case WM_PRINTCLIENT:
3651 case WM_PAINT:
3652 return REBAR_Paint (infoPtr, wParam, lParam);
3654 /* case WM_PALETTECHANGED: supported according to ControlSpy */
3655 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
3656 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
3657 /* case WM_RBUTTONUP: supported according to ControlSpy */
3659 case WM_SETCURSOR:
3660 return REBAR_SetCursor (infoPtr, wParam, lParam);
3662 case WM_SETFONT:
3663 return REBAR_SetFont (infoPtr, wParam, lParam);
3665 case WM_SETREDRAW:
3666 return REBAR_SetRedraw (infoPtr, wParam, lParam);
3668 case WM_SIZE:
3669 return REBAR_Size (infoPtr, wParam, lParam);
3671 case WM_STYLECHANGED:
3672 return REBAR_StyleChanged (infoPtr, wParam, lParam);
3674 case WM_THEMECHANGED:
3675 return theme_changed (infoPtr);
3677 /* case WM_SYSCOLORCHANGE: supported according to ControlSpy */
3678 /* "Applications that have brushes using the existing system colors
3679 should delete those brushes and recreate them using the new
3680 system colors." per MSDN */
3682 /* case WM_VKEYTOITEM: supported according to ControlSpy */
3683 /* case WM_WININICHANGE: */
3685 case WM_WINDOWPOSCHANGED:
3686 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
3688 default:
3689 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
3690 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
3691 uMsg, wParam, lParam);
3692 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3697 VOID
3698 REBAR_Register (void)
3700 WNDCLASSW wndClass;
3702 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
3703 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
3704 wndClass.lpfnWndProc = REBAR_WindowProc;
3705 wndClass.cbClsExtra = 0;
3706 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
3707 wndClass.hCursor = 0;
3708 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
3709 #if GLATESTING
3710 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
3711 #endif
3712 wndClass.lpszClassName = REBARCLASSNAMEW;
3714 RegisterClassW (&wndClass);
3716 mindragx = GetSystemMetrics (SM_CXDRAG);
3717 mindragy = GetSystemMetrics (SM_CYDRAG);
3722 VOID
3723 REBAR_Unregister (void)
3725 UnregisterClassW (REBARCLASSNAMEW, NULL);