wow64: Add thunks for the event syscalls.
[wine.git] / dlls / comctl32 / rebar.c
blobaf35008b692a1ff7ea773000ff04eb7b0fe4ae09
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 * Messages:
37 * - RB_BEGINDRAG
38 * - RB_DRAGMOVE
39 * - RB_ENDDRAG
40 * - RB_GETBANDMARGINS
41 * - RB_GETCOLORSCHEME
42 * - RB_GETDROPTARGET
43 * - RB_GETPALETTE
44 * - RB_SETCOLORSCHEME
45 * - RB_SETPALETTE
46 * - RB_SETTOOLTIPS
47 * - WM_CHARTOITEM
48 * - WM_LBUTTONDBLCLK
49 * - WM_PALETTECHANGED
50 * - WM_QUERYNEWPALETTE
51 * - WM_RBUTTONDOWN
52 * - WM_RBUTTONUP
53 * - WM_SYSCOLORCHANGE
54 * - WM_VKEYTOITEM
55 * - WM_WININICHANGE
56 * Notifications:
57 * - NM_HCHITTEST
58 * - NM_RELEASEDCAPTURE
59 * - RBN_AUTOBREAK
60 * - RBN_GETOBJECT
61 * - RBN_MINMAX
62 * Band styles:
63 * - RBBS_FIXEDBMP
64 * Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
65 * to set the size of the separator width (the value SEP_WIDTH_SIZE
66 * in here). Should be fixed!!
70 * Testing: set to 1 to make background brush *always* green
72 #define GLATESTING 0
75 * 3. REBAR_MoveChildWindows should have a loop because more than
76 * one pass (together with the RBN_CHILDSIZEs) is made on
77 * at least RB_INSERTBAND
80 #include <assert.h>
81 #include <stdarg.h>
82 #include <stdlib.h>
83 #include <string.h>
85 #include "windef.h"
86 #include "winbase.h"
87 #include "wingdi.h"
88 #include "winuser.h"
89 #include "winnls.h"
90 #include "commctrl.h"
91 #include "comctl32.h"
92 #include "uxtheme.h"
93 #include "vssym32.h"
94 #include "wine/debug.h"
96 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
98 typedef struct
100 UINT fStyle;
101 UINT fMask;
102 COLORREF clrFore;
103 COLORREF clrBack;
104 INT iImage;
105 HWND hwndChild;
106 UINT cxMinChild; /* valid if _CHILDSIZE */
107 UINT cyMinChild; /* valid if _CHILDSIZE */
108 UINT cx; /* valid if _SIZE */
109 HBITMAP hbmBack;
110 UINT wID;
111 UINT cyChild; /* valid if _CHILDSIZE */
112 UINT cyMaxChild; /* valid if _CHILDSIZE */
113 UINT cyIntegral; /* valid if _CHILDSIZE */
114 UINT cxIdeal;
115 LPARAM lParam;
116 UINT cxHeader;
118 INT cxEffective; /* current cx for band */
119 UINT cyHeader; /* the height of the header */
120 UINT cxMinBand; /* minimum cx for band */
121 UINT cyMinBand; /* minimum cy for band */
123 UINT cyRowSoFar; /* for RBS_VARHEIGHT - the height of the row if it would break on this band (set by _Layout) */
124 INT iRow; /* zero-based index of the row this band assigned to */
125 UINT fStatus; /* status flags, reset only by _Validate */
126 UINT fDraw; /* drawing flags, reset only by _Layout */
127 UINT uCDret; /* last return from NM_CUSTOMDRAW */
128 RECT rcBand; /* calculated band rectangle - coordinates swapped for CCS_VERT */
129 RECT rcGripper; /* calculated gripper rectangle */
130 RECT rcCapImage; /* calculated caption image rectangle */
131 RECT rcCapText; /* calculated caption text rectangle */
132 RECT rcChild; /* calculated child rectangle */
133 RECT rcChevron; /* calculated chevron rectangle */
135 LPWSTR lpText;
136 HWND hwndPrevParent;
137 } REBAR_BAND;
139 /* has a value of: 0, CCS_TOP, CCS_NOMOVEY, CCS_BOTTOM */
140 #define CCS_LAYOUT_MASK 0x3
142 /* fStatus flags */
143 #define HAS_GRIPPER 0x00000001
144 #define HAS_IMAGE 0x00000002
145 #define HAS_TEXT 0x00000004
147 /* fDraw flags */
148 #define DRAW_GRIPPER 0x00000001
149 #define DRAW_IMAGE 0x00000002
150 #define DRAW_TEXT 0x00000004
151 #define DRAW_CHEVRONHOT 0x00000040
152 #define DRAW_CHEVRONPUSHED 0x00000080
153 #define NTF_INVALIDATE 0x01000000
155 typedef struct
157 COLORREF clrBk; /* background color */
158 COLORREF clrText; /* text color */
159 COLORREF clrBtnText; /* system color for BTNTEXT */
160 COLORREF clrBtnFace; /* system color for BTNFACE */
161 HIMAGELIST himl; /* handle to imagelist */
162 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
163 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
164 HWND hwndSelf; /* handle of REBAR window itself */
165 HWND hwndToolTip; /* handle to the tool tip control */
166 HWND hwndNotify; /* notification window (parent) */
167 HFONT hDefaultFont;
168 HFONT hFont; /* handle to the rebar's font */
169 SIZE imageSize; /* image size (image list) */
170 DWORD dwStyle; /* window style */
171 DWORD orgStyle; /* original style (dwStyle may change) */
172 SIZE calcSize; /* calculated rebar size - coordinates swapped for CCS_VERT */
173 BOOL bUnicode; /* TRUE if parent wants notify in W format */
174 BOOL DoRedraw; /* TRUE to actually draw bands */
175 UINT fStatus; /* Status flags (see below) */
176 HCURSOR hcurArrow; /* handle to the arrow cursor */
177 HCURSOR hcurHorz; /* handle to the EW cursor */
178 HCURSOR hcurVert; /* handle to the NS cursor */
179 HCURSOR hcurDrag; /* handle to the drag cursor */
180 INT iVersion; /* version number */
181 POINT dragStart; /* x,y of button down */
182 POINT dragNow; /* x,y of this MouseMove */
183 INT iOldBand; /* last band that had the mouse cursor over it */
184 INT ihitoffset; /* offset of hotspot from gripper.left */
185 INT ichevronhotBand; /* last band that had a hot chevron */
186 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
188 HDPA bands; /* pointer to the array of rebar bands */
189 } REBAR_INFO;
191 /* fStatus flags */
192 #define BEGIN_DRAG_ISSUED 0x00000001
193 #define SELF_RESIZE 0x00000002
194 #define BAND_NEEDS_REDRAW 0x00000020
196 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
197 #define RBBS_UNDOC_FIXEDHEADER 0x40000000
199 /* ---- REBAR layout constants. Mostly determined by ---- */
200 /* ---- experiment on WIN 98. ---- */
202 /* Width (or height) of separators between bands (either horz. or */
203 /* vert.). True only if RBS_BANDBORDERS is set */
204 #define SEP_WIDTH_SIZE 2
205 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
207 /* Blank (background color) space between Gripper (if present) */
208 /* and next item (image, text, or window). Always present */
209 #define REBAR_ALWAYS_SPACE 4
211 /* Blank (background color) space after Image (if present). */
212 #define REBAR_POST_IMAGE 2
214 /* Blank (background color) space after Text (if present). */
215 #define REBAR_POST_TEXT 4
217 /* Height of vertical gripper in a CCS_VERT rebar. */
218 #define GRIPPER_HEIGHT 16
220 /* Blank (background color) space before Gripper (if present). */
221 #define REBAR_PRE_GRIPPER 2
223 /* Width (of normal vertical gripper) or height (of horz. gripper) */
224 /* if present. */
225 #define GRIPPER_WIDTH 3
227 /* Width of the chevron button if present */
228 #define CHEVRON_WIDTH 10
230 /* the gap between the child and the next band */
231 #define REBAR_POST_CHILD 4
233 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
234 /* either top or bottom */
235 #define REBAR_DIVIDER 2
237 /* height of a rebar without a child */
238 #define REBAR_NO_CHILD_HEIGHT 4
240 /* minimum vertical height of a normal bar */
241 /* or minimum width of a CCS_VERT bar - from experiment on Win2k */
242 #define REBAR_MINSIZE 23
244 /* This is the increment that is used over the band height */
245 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
247 /* ---- End of REBAR layout constants. ---- */
249 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
251 /* The following define determines if a given band is hidden */
252 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
253 ((infoPtr->dwStyle & CCS_VERT) && \
254 ((a)->fStyle & RBBS_NOVERT)))
256 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
258 static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, LPARAM lParam);
259 static void REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout);
261 /* no index check here */
262 static inline REBAR_BAND* REBAR_GetBand(const REBAR_INFO *infoPtr, INT i)
264 assert(i >= 0 && i < infoPtr->uNumBands);
265 return DPA_GetPtr(infoPtr->bands, i);
268 /* "constant values" retrieved when DLL was initialized */
269 /* FIXME we do this when the classes are registered. */
270 static UINT mindragx = 0;
271 static UINT mindragy = 0;
273 static const char * const band_stylename[] = {
274 "RBBS_BREAK", /* 0001 */
275 "RBBS_FIXEDSIZE", /* 0002 */
276 "RBBS_CHILDEDGE", /* 0004 */
277 "RBBS_HIDDEN", /* 0008 */
278 "RBBS_NOVERT", /* 0010 */
279 "RBBS_FIXEDBMP", /* 0020 */
280 "RBBS_VARIABLEHEIGHT", /* 0040 */
281 "RBBS_GRIPPERALWAYS", /* 0080 */
282 "RBBS_NOGRIPPER", /* 0100 */
283 "RBBS_USECHEVRON", /* 0200 */
284 "RBBS_HIDETITLE", /* 0400 */
285 "RBBS_TOPALIGN", /* 0800 */
286 NULL };
288 static const char * const band_maskname[] = {
289 "RBBIM_STYLE", /* 0x00000001 */
290 "RBBIM_COLORS", /* 0x00000002 */
291 "RBBIM_TEXT", /* 0x00000004 */
292 "RBBIM_IMAGE", /* 0x00000008 */
293 "RBBIM_CHILD", /* 0x00000010 */
294 "RBBIM_CHILDSIZE", /* 0x00000020 */
295 "RBBIM_SIZE", /* 0x00000040 */
296 "RBBIM_BACKGROUND", /* 0x00000080 */
297 "RBBIM_ID", /* 0x00000100 */
298 "RBBIM_IDEALSIZE", /* 0x00000200 */
299 "RBBIM_LPARAM", /* 0x00000400 */
300 "RBBIM_HEADERSIZE", /* 0x00000800 */
301 "RBBIM_CHEVRONLOCATION", /* 0x00001000 */
302 "RBBIM_CHEVRONSTATE", /* 0x00002000 */
303 NULL };
305 static const WCHAR themeClass[] = L"Rebar";
307 static CHAR *
308 REBAR_FmtStyle(char *buffer, UINT style)
310 INT i = 0;
312 *buffer = 0;
313 while (band_stylename[i]) {
314 if (style & (1<<i)) {
315 if (*buffer) strcat(buffer, " | ");
316 strcat(buffer, band_stylename[i]);
318 i++;
320 return buffer;
324 static CHAR *
325 REBAR_FmtMask(char *buffer, UINT mask)
327 INT i = 0;
329 *buffer = 0;
330 while (band_maskname[i]) {
331 if (mask & (1<<i)) {
332 if (*buffer) strcat(buffer, " | ");
333 strcat(buffer, band_maskname[i]);
335 i++;
337 return buffer;
341 static VOID
342 REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
344 char buff[300];
346 if( !TRACE_ON(rebar) ) return;
347 TRACE("band info: ");
348 if (pB->fMask & RBBIM_ID)
349 TRACE("ID=%u, ", pB->wID);
350 TRACE("size=%u, child=%p", pB->cbSize, pB->hwndChild);
351 if (pB->fMask & RBBIM_COLORS)
352 TRACE(", clrF=0x%06x, clrB=0x%06x", pB->clrFore, pB->clrBack);
353 TRACE("\n");
355 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(buff, pB->fMask));
356 if (pB->fMask & RBBIM_STYLE)
357 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(buff, pB->fStyle));
358 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
359 TRACE("band info:");
360 if (pB->fMask & RBBIM_SIZE)
361 TRACE(" cx=%u", pB->cx);
362 if (pB->fMask & RBBIM_IDEALSIZE)
363 TRACE(" xIdeal=%u", pB->cxIdeal);
364 if (pB->fMask & RBBIM_HEADERSIZE)
365 TRACE(" xHeader=%u", pB->cxHeader);
366 if (pB->fMask & RBBIM_LPARAM)
367 TRACE(" lParam=0x%08lx", pB->lParam);
368 TRACE("\n");
370 if (pB->fMask & RBBIM_CHILDSIZE)
371 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
372 pB->cxMinChild,
373 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
376 static VOID
377 REBAR_DumpBand (const REBAR_INFO *iP)
379 char buff[300];
380 REBAR_BAND *pB;
381 UINT i;
383 if(! TRACE_ON(rebar) ) return;
385 TRACE("hwnd=%p: color=%08x/%08x, bands=%u, rows=%u, cSize=%d,%d\n",
386 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
387 iP->calcSize.cx, iP->calcSize.cy);
388 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
389 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
390 iP->dragNow.x, iP->dragNow.y,
391 iP->iGrabbedBand);
392 TRACE("hwnd=%p: style=%08x, notify in Unicode=%s, redraw=%s\n",
393 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
394 (iP->DoRedraw)?"TRUE":"FALSE");
395 for (i = 0; i < iP->uNumBands; i++) {
396 pB = REBAR_GetBand(iP, i);
397 TRACE("band # %u:", i);
398 if (pB->fMask & RBBIM_ID)
399 TRACE(" ID=%u", pB->wID);
400 if (pB->fMask & RBBIM_CHILD)
401 TRACE(" child=%p", pB->hwndChild);
402 if (pB->fMask & RBBIM_COLORS)
403 TRACE(" clrF=0x%06x clrB=0x%06x", pB->clrFore, pB->clrBack);
404 TRACE("\n");
405 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(buff, pB->fMask));
406 if (pB->fMask & RBBIM_STYLE)
407 TRACE("band # %u: style=0x%08x (%s)\n", i, pB->fStyle, REBAR_FmtStyle(buff, pB->fStyle));
408 TRACE("band # %u: xHeader=%u",
409 i, pB->cxHeader);
410 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
411 if (pB->fMask & RBBIM_SIZE)
412 TRACE(" cx=%u", pB->cx);
413 if (pB->fMask & RBBIM_IDEALSIZE)
414 TRACE(" xIdeal=%u", pB->cxIdeal);
415 if (pB->fMask & RBBIM_LPARAM)
416 TRACE(" lParam=0x%08lx", pB->lParam);
418 TRACE("\n");
419 if (RBBIM_CHILDSIZE)
420 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
421 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
422 if (pB->fMask & RBBIM_TEXT)
423 TRACE("band # %u: text=%s\n",
424 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
425 TRACE("band # %u: cxMinBand=%u, cxEffective=%u, cyMinBand=%u\n",
426 i, pB->cxMinBand, pB->cxEffective, pB->cyMinBand);
427 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
428 i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
429 wine_dbgstr_rect(&pB->rcGripper));
430 TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
431 i, wine_dbgstr_rect(&pB->rcCapImage),
432 wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
437 /* dest can be equal to src */
438 static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
440 if (infoPtr->dwStyle & CCS_VERT) {
441 int tmp;
442 tmp = src->left;
443 dest->left = src->top;
444 dest->top = tmp;
446 tmp = src->right;
447 dest->right = src->bottom;
448 dest->bottom = tmp;
449 } else {
450 *dest = *src;
454 static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
456 if (infoPtr->dwStyle & CCS_VERT)
457 return lpRect->bottom - lpRect->top;
458 return lpRect->right - lpRect->left;
461 static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
463 if (infoPtr->dwStyle & CCS_VERT)
464 return lpRect->right - lpRect->left;
465 return lpRect->bottom - lpRect->top;
468 static int round_child_height(const REBAR_BAND *lpBand, int cyHeight)
470 int cy = 0;
471 if (lpBand->cyIntegral == 0)
472 return cyHeight;
473 cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
474 cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
475 cy = min(cy, lpBand->cyMaxChild);
476 return cy;
479 static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
481 lpBand->cyMinBand = max(lpBand->cyHeader,
482 (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
485 static void
486 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
488 INT x, y;
489 HPEN hPen, hOldPen;
491 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
492 hOldPen = SelectObject ( hdc, hPen );
493 x = left + 2;
494 y = top;
495 MoveToEx (hdc, x, y, NULL);
496 LineTo (hdc, x+5, y++); x++;
497 MoveToEx (hdc, x, y, NULL);
498 LineTo (hdc, x+3, y++); x++;
499 MoveToEx (hdc, x, y, NULL);
500 LineTo (hdc, x+1, y);
501 SelectObject( hdc, hOldPen );
502 DeleteObject( hPen );
505 static HWND
506 REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
508 HWND parent, owner;
510 parent = infoPtr->hwndNotify;
511 if (!parent) {
512 parent = GetParent (infoPtr->hwndSelf);
513 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
514 if (owner) parent = owner;
516 return parent;
520 static INT
521 REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
523 HWND parent;
525 parent = REBAR_GetNotifyParent (infoPtr);
526 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
527 nmhdr->hwndFrom = infoPtr->hwndSelf;
528 nmhdr->code = code;
530 TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
532 return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
535 static INT
536 REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
538 NMREBAR notify_rebar;
540 notify_rebar.dwMask = 0;
541 if (uBand != -1) {
542 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
544 if (lpBand->fMask & RBBIM_ID) {
545 notify_rebar.dwMask |= RBNM_ID;
546 notify_rebar.wID = lpBand->wID;
548 if (lpBand->fMask & RBBIM_LPARAM) {
549 notify_rebar.dwMask |= RBNM_LPARAM;
550 notify_rebar.lParam = lpBand->lParam;
552 if (lpBand->fMask & RBBIM_STYLE) {
553 notify_rebar.dwMask |= RBNM_STYLE;
554 notify_rebar.fStyle = lpBand->fStyle;
557 notify_rebar.uBand = uBand;
558 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
561 static VOID
562 REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
564 HFONT hOldFont = 0;
565 INT oldBkMode = 0;
566 NMCUSTOMDRAW nmcd;
567 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
568 RECT rcBand;
570 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
572 if (lpBand->fDraw & DRAW_TEXT) {
573 hOldFont = SelectObject (hdc, infoPtr->hFont);
574 oldBkMode = SetBkMode (hdc, TRANSPARENT);
577 /* should test for CDRF_NOTIFYITEMDRAW here */
578 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
579 nmcd.hdc = hdc;
580 nmcd.rc = rcBand;
581 nmcd.rc.right = lpBand->rcCapText.right;
582 nmcd.rc.bottom = lpBand->rcCapText.bottom;
583 nmcd.dwItemSpec = lpBand->wID;
584 nmcd.uItemState = 0;
585 nmcd.lItemlParam = lpBand->lParam;
586 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
587 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
588 if (oldBkMode != TRANSPARENT)
589 SetBkMode (hdc, oldBkMode);
590 SelectObject (hdc, hOldFont);
591 return;
594 /* draw gripper */
595 if (lpBand->fDraw & DRAW_GRIPPER)
597 if (theme)
599 RECT rcGripper = lpBand->rcGripper;
600 int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
601 GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
602 OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
603 lpBand->rcGripper.top - rcGripper.top);
604 DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
606 else
607 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
610 /* draw caption image */
611 if (lpBand->fDraw & DRAW_IMAGE) {
612 POINT pt;
614 /* center image */
615 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
616 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
618 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
619 pt.x, pt.y,
620 ILD_TRANSPARENT);
623 /* draw caption text */
624 if (lpBand->fDraw & DRAW_TEXT) {
625 /* need to handle CDRF_NEWFONT here */
626 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
627 COLORREF oldcolor = CLR_NONE;
628 COLORREF new;
629 if (lpBand->clrFore != CLR_NONE) {
630 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
631 lpBand->clrFore;
632 oldcolor = SetTextColor (hdc, new);
634 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
635 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
636 if (oldBkMode != TRANSPARENT)
637 SetBkMode (hdc, oldBkMode);
638 if (lpBand->clrFore != CLR_NONE)
639 SetTextColor (hdc, oldcolor);
640 SelectObject (hdc, hOldFont);
643 if (!IsRectEmpty(&lpBand->rcChevron))
645 if (theme)
647 int stateId;
648 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
649 stateId = CHEVS_PRESSED;
650 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
651 stateId = CHEVS_HOT;
652 else
653 stateId = CHEVS_NORMAL;
654 DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
656 else
658 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
660 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
661 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
663 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
665 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
666 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
668 else
669 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
673 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
674 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
675 nmcd.hdc = hdc;
676 nmcd.rc = rcBand;
677 nmcd.rc.right = lpBand->rcCapText.right;
678 nmcd.rc.bottom = lpBand->rcCapText.bottom;
679 nmcd.dwItemSpec = lpBand->wID;
680 nmcd.uItemState = 0;
681 nmcd.lItemlParam = lpBand->lParam;
682 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
687 static VOID
688 REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
690 REBAR_BAND *lpBand;
691 UINT i;
693 if (!infoPtr->DoRedraw) return;
695 for (i = 0; i < infoPtr->uNumBands; i++) {
696 lpBand = REBAR_GetBand(infoPtr, i);
698 if (HIDDENBAND(lpBand)) continue;
700 /* now draw the band */
701 TRACE("[%p] drawing band %i, flags=%08x\n",
702 infoPtr->hwndSelf, i, lpBand->fDraw);
703 REBAR_DrawBand (hdc, infoPtr, lpBand);
708 static void
709 REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
710 /* Function: this routine initializes all the rectangles in */
711 /* each band in a row to fit in the adjusted rcBand rect. */
712 /* *** Supports only Horizontal bars. *** */
714 REBAR_BAND *lpBand;
715 UINT i, xoff;
716 RECT work;
718 for(i=rstart; i<rend; i++){
719 lpBand = REBAR_GetBand(infoPtr, i);
720 if (HIDDENBAND(lpBand)) {
721 SetRect (&lpBand->rcChild,
722 lpBand->rcBand.right, lpBand->rcBand.top,
723 lpBand->rcBand.right, lpBand->rcBand.bottom);
724 continue;
727 /* set initial gripper rectangle */
728 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
729 lpBand->rcBand.left, lpBand->rcBand.bottom);
731 /* calculate gripper rectangle */
732 if ( lpBand->fStatus & HAS_GRIPPER) {
733 lpBand->fDraw |= DRAW_GRIPPER;
734 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
735 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
736 InflateRect(&lpBand->rcGripper, 0, -2);
738 SetRect (&lpBand->rcCapImage,
739 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
740 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
742 else { /* no gripper will be drawn */
743 xoff = 0;
744 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
745 /* if no gripper but either image or text, then leave space */
746 xoff = REBAR_ALWAYS_SPACE;
747 SetRect (&lpBand->rcCapImage,
748 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
749 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
752 /* image is visible */
753 if (lpBand->fStatus & HAS_IMAGE) {
754 lpBand->fDraw |= DRAW_IMAGE;
755 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
756 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
758 /* set initial caption text rectangle */
759 SetRect (&lpBand->rcCapText,
760 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
761 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
763 else {
764 /* set initial caption text rectangle */
765 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
766 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
769 /* text is visible */
770 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
771 lpBand->fDraw |= DRAW_TEXT;
772 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
773 lpBand->rcCapText.right-REBAR_POST_TEXT);
776 /* set initial child window rectangle if there is a child */
777 if (lpBand->hwndChild) {
779 lpBand->rcChild.left = lpBand->rcBand.left + lpBand->cxHeader;
780 lpBand->rcChild.right = lpBand->rcBand.right - REBAR_POST_CHILD;
782 if (lpBand->cyChild > 0) {
784 UINT yoff = (lpBand->rcBand.bottom - lpBand->rcBand.top - lpBand->cyChild) / 2;
786 /* center child if height is known */
787 lpBand->rcChild.top = lpBand->rcBand.top + yoff;
788 lpBand->rcChild.bottom = lpBand->rcBand.top + yoff + lpBand->cyChild;
790 else {
791 lpBand->rcChild.top = lpBand->rcBand.top;
792 lpBand->rcChild.bottom = lpBand->rcBand.bottom;
795 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
797 lpBand->rcChild.right -= CHEVRON_WIDTH;
798 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
799 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
800 lpBand->rcChild.bottom);
803 else {
804 SetRect (&lpBand->rcChild,
805 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
806 lpBand->rcBand.right, lpBand->rcBand.bottom);
809 /* flag if notify required and invalidate rectangle */
810 if (lpBand->fDraw & NTF_INVALIDATE) {
811 lpBand->fDraw &= ~NTF_INVALIDATE;
812 work = lpBand->rcBand;
813 work.right += SEP_WIDTH;
814 work.bottom += SEP_WIDTH;
815 TRACE("invalidating %s\n", wine_dbgstr_rect(&work));
816 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
817 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
825 static VOID
826 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
827 /* Function: this routine initializes all the rectangles in */
828 /* each band in a row to fit in the adjusted rcBand rect. */
829 /* *** Supports only Vertical bars. *** */
831 REBAR_BAND *lpBand;
832 UINT i, xoff;
833 RECT work;
835 for(i=rstart; i<rend; i++){
836 RECT rcBand;
837 lpBand = REBAR_GetBand(infoPtr, i);
838 if (HIDDENBAND(lpBand)) continue;
840 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
842 /* set initial gripper rectangle */
843 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
845 /* calculate gripper rectangle */
846 if (lpBand->fStatus & HAS_GRIPPER) {
847 lpBand->fDraw |= DRAW_GRIPPER;
849 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
850 /* vertical gripper */
851 lpBand->rcGripper.left += 3;
852 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
853 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
854 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
856 /* initialize Caption image rectangle */
857 SetRect (&lpBand->rcCapImage, rcBand.left,
858 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
859 rcBand.right,
860 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
862 else {
863 /* horizontal gripper */
864 InflateRect(&lpBand->rcGripper, -2, 0);
865 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
866 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
868 /* initialize Caption image rectangle */
869 SetRect (&lpBand->rcCapImage, rcBand.left,
870 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
871 rcBand.right,
872 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
875 else { /* no gripper will be drawn */
876 xoff = 0;
877 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
878 /* if no gripper but either image or text, then leave space */
879 xoff = REBAR_ALWAYS_SPACE;
880 /* initialize Caption image rectangle */
881 SetRect (&lpBand->rcCapImage,
882 rcBand.left, rcBand.top+xoff,
883 rcBand.right, rcBand.top+xoff);
886 /* image is visible */
887 if (lpBand->fStatus & HAS_IMAGE) {
888 lpBand->fDraw |= DRAW_IMAGE;
890 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
891 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
893 /* set initial caption text rectangle */
894 SetRect (&lpBand->rcCapText,
895 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
896 rcBand.right, rcBand.top+lpBand->cxHeader);
898 else {
899 /* set initial caption text rectangle */
900 SetRect (&lpBand->rcCapText,
901 rcBand.left, lpBand->rcCapImage.bottom,
902 rcBand.right, rcBand.top+lpBand->cxHeader);
905 /* text is visible */
906 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
907 lpBand->fDraw |= DRAW_TEXT;
908 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
909 lpBand->rcCapText.bottom);
912 /* set initial child window rectangle if there is a child */
913 if (lpBand->hwndChild) {
914 int cxBand = rcBand.right - rcBand.left;
915 xoff = (cxBand - lpBand->cyChild) / 2;
916 SetRect (&lpBand->rcChild,
917 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
918 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
920 else {
921 SetRect (&lpBand->rcChild,
922 rcBand.left, rcBand.top+lpBand->cxHeader,
923 rcBand.right, rcBand.bottom);
926 if (lpBand->fDraw & NTF_INVALIDATE) {
927 lpBand->fDraw &= ~NTF_INVALIDATE;
928 work = rcBand;
929 work.bottom += SEP_WIDTH;
930 work.right += SEP_WIDTH;
931 TRACE("invalidating %s\n", wine_dbgstr_rect(&work));
932 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
933 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
940 static VOID
941 REBAR_ForceResize (REBAR_INFO *infoPtr)
942 /* Function: This changes the size of the REBAR window to that */
943 /* calculated by REBAR_Layout. */
945 INT x, y, width, height;
946 INT xedge = 0, yedge = 0;
947 RECT rcSelf;
949 TRACE("new size [%d x %d]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
951 if (infoPtr->dwStyle & CCS_NORESIZE)
952 return;
954 if (infoPtr->dwStyle & WS_BORDER)
956 xedge = GetSystemMetrics(SM_CXEDGE);
957 yedge = GetSystemMetrics(SM_CYEDGE);
958 /* swap for CCS_VERT? */
961 /* compute rebar window rect in parent client coordinates */
962 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
963 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
964 translate_rect(infoPtr, &rcSelf, &rcSelf);
966 height = infoPtr->calcSize.cy + 2*yedge;
967 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
968 RECT rcParent;
970 x = -xedge;
971 width = infoPtr->calcSize.cx + 2*xedge;
972 y = 0; /* quiet compiler warning */
973 switch ( infoPtr->dwStyle & CCS_LAYOUT_MASK) {
974 case 0: /* shouldn't happen - see NCCreate */
975 case CCS_TOP:
976 y = ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER) - yedge;
977 break;
978 case CCS_NOMOVEY:
979 y = rcSelf.top;
980 break;
981 case CCS_BOTTOM:
982 GetClientRect(GetParent(infoPtr->hwndSelf), &rcParent);
983 translate_rect(infoPtr, &rcParent, &rcParent);
984 y = rcParent.bottom - infoPtr->calcSize.cy - yedge;
985 break;
988 else {
989 x = rcSelf.left;
990 /* As on Windows if the CCS_NODIVIDER is not present the control will move
991 * 2 pixel down after every layout */
992 y = rcSelf.top + ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
993 width = rcSelf.right - rcSelf.left;
996 TRACE("hwnd %p, style=%08x, setting at (%d,%d) for (%d,%d)\n",
997 infoPtr->hwndSelf, infoPtr->dwStyle, x, y, width, height);
999 /* Set flag to ignore next WM_SIZE message and resize the window */
1000 infoPtr->fStatus |= SELF_RESIZE;
1001 if ((infoPtr->dwStyle & CCS_VERT) == 0)
1002 SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
1003 else
1004 SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
1005 infoPtr->fStatus &= ~SELF_RESIZE;
1009 static VOID
1010 REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
1012 REBAR_BAND *lpBand;
1013 WCHAR szClassName[40];
1014 UINT i;
1015 NMREBARCHILDSIZE rbcz;
1016 HDWP deferpos;
1018 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1019 ERR("BeginDeferWindowPos returned NULL\n");
1021 for (i = start; i < endplus; i++) {
1022 lpBand = REBAR_GetBand(infoPtr, i);
1024 if (HIDDENBAND(lpBand)) continue;
1025 if (lpBand->hwndChild) {
1026 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1028 /* Always generate the RBN_CHILDSIZE even if child
1029 did not change */
1030 rbcz.uBand = i;
1031 rbcz.wID = lpBand->wID;
1032 rbcz.rcChild = lpBand->rcChild;
1033 translate_rect(infoPtr, &rbcz.rcBand, &lpBand->rcBand);
1034 if (infoPtr->dwStyle & CCS_VERT)
1035 rbcz.rcBand.top += lpBand->cxHeader;
1036 else
1037 rbcz.rcBand.left += lpBand->cxHeader;
1038 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1039 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1040 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1041 TRACE(" from (%s) to (%s)\n",
1042 wine_dbgstr_rect(&lpBand->rcChild),
1043 wine_dbgstr_rect(&rbcz.rcChild));
1044 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1047 GetClassNameW (lpBand->hwndChild, szClassName, ARRAY_SIZE(szClassName));
1048 if (!lstrcmpW (szClassName, WC_COMBOBOXW) ||
1049 !lstrcmpW (szClassName, WC_COMBOBOXEXW)) {
1050 INT nEditHeight, yPos;
1051 RECT rc;
1053 /* special placement code for combo or comboex box */
1056 /* get size of edit line */
1057 GetWindowRect (lpBand->hwndChild, &rc);
1058 nEditHeight = rc.bottom - rc.top;
1059 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1061 /* center combo box inside child area */
1062 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1063 lpBand->hwndChild,
1064 lpBand->rcChild.left, yPos,
1065 lpBand->rcChild.right - lpBand->rcChild.left,
1066 nEditHeight);
1067 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1068 lpBand->rcChild.left,
1069 /*lpBand->rcChild.top*/ yPos,
1070 lpBand->rcChild.right - lpBand->rcChild.left,
1071 nEditHeight,
1072 SWP_NOZORDER);
1073 if (!deferpos)
1074 ERR("DeferWindowPos returned NULL\n");
1076 else {
1077 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1078 lpBand->hwndChild,
1079 lpBand->rcChild.left, lpBand->rcChild.top,
1080 lpBand->rcChild.right - lpBand->rcChild.left,
1081 lpBand->rcChild.bottom - lpBand->rcChild.top);
1082 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1083 lpBand->rcChild.left,
1084 lpBand->rcChild.top,
1085 lpBand->rcChild.right - lpBand->rcChild.left,
1086 lpBand->rcChild.bottom - lpBand->rcChild.top,
1087 SWP_NOZORDER);
1088 if (!deferpos)
1089 ERR("DeferWindowPos returned NULL\n");
1093 if (!EndDeferWindowPos(deferpos))
1094 ERR("EndDeferWindowPos returned NULL\n");
1096 if (infoPtr->DoRedraw)
1097 UpdateWindow (infoPtr->hwndSelf);
1100 /* Returns the next visible band (the first visible band in [i+1; infoPtr->uNumBands) )
1101 * or infoPtr->uNumBands if none */
1102 static int next_visible(const REBAR_INFO *infoPtr, int i)
1104 unsigned int n;
1105 for (n = i + 1; n < infoPtr->uNumBands; n++)
1106 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1107 break;
1108 return n;
1111 /* Returns the previous visible band (the last visible band in [0; i) )
1112 * or -1 if none */
1113 static int prev_visible(const REBAR_INFO *infoPtr, int i)
1115 int n;
1116 for (n = i - 1; n >= 0; n--)
1117 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1118 break;
1119 return n;
1122 /* Returns the first visible band or infoPtr->uNumBands if none */
1123 static int first_visible(const REBAR_INFO *infoPtr)
1125 return next_visible(infoPtr, -1); /* this works*/
1128 /* Returns the first visible band for the given row (or iBand if none) */
1129 static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
1131 int iLastBand = iBand;
1132 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1133 while ((iBand = prev_visible(infoPtr, iBand)) >= 0) {
1134 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1135 break;
1136 else
1137 iLastBand = iBand;
1139 return iLastBand;
1142 /* Returns the first visible band for the next row (or infoPtr->uNumBands if none) */
1143 static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
1145 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1146 while ((iBand = next_visible(infoPtr, iBand)) < infoPtr->uNumBands)
1147 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1148 break;
1149 return iBand;
1152 /* Compute the rcBand.{left,right} from the cxEffective bands widths computed earlier.
1153 * iBeginBand must be visible */
1154 static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1156 int xPos = 0, i;
1157 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1159 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1160 if (lpBand->rcBand.left != xPos || lpBand->rcBand.right != xPos + lpBand->cxEffective) {
1161 lpBand->fDraw |= NTF_INVALIDATE;
1162 TRACE("Setting rect %d to %d,%d\n", i, xPos, xPos + lpBand->cxEffective);
1163 lpBand->rcBand.left = xPos;
1164 lpBand->rcBand.right = xPos + lpBand->cxEffective;
1166 xPos += lpBand->cxEffective + SEP_WIDTH;
1170 /* The rationale of this function is probably as follows: if we have some space
1171 * to distribute we want to add it to a band on the right. However we don't want
1172 * to unminimize a minimized band so we search for a band that is big enough.
1173 * For some reason "big enough" is defined as bigger than the minimum size of the
1174 * first band in the row
1176 static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1178 INT cxMinFirstBand = 0, i;
1180 cxMinFirstBand = REBAR_GetBand(infoPtr, iBeginBand)->cxMinBand;
1182 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1183 if (REBAR_GetBand(infoPtr, i)->cxEffective > cxMinFirstBand &&
1184 !(REBAR_GetBand(infoPtr, i)->fStyle & RBBS_FIXEDSIZE))
1185 break;
1187 if (i < iBeginBand)
1188 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1189 if (REBAR_GetBand(infoPtr, i)->cxMinBand == cxMinFirstBand)
1190 break;
1192 TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
1193 return REBAR_GetBand(infoPtr, i);
1196 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the right */
1197 static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1199 REBAR_BAND *lpBand;
1200 INT width, i;
1202 TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
1203 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1205 lpBand = REBAR_GetBand(infoPtr, i);
1207 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1208 cxShrink -= lpBand->cxEffective - width;
1209 lpBand->cxEffective = width;
1210 if (bEnforce && lpBand->cx > lpBand->cxEffective)
1211 lpBand->cx = lpBand->cxEffective;
1212 if (cxShrink == 0)
1213 break;
1215 return cxShrink;
1219 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the left.
1220 * iBeginBand must be visible */
1221 static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1223 REBAR_BAND *lpBand;
1224 INT width, i;
1226 TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
1227 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1229 lpBand = REBAR_GetBand(infoPtr, i);
1231 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1232 cxShrink -= lpBand->cxEffective - width;
1233 lpBand->cxEffective = width;
1234 if (bEnforce)
1235 lpBand->cx = lpBand->cxEffective;
1236 if (cxShrink == 0)
1237 break;
1239 return cxShrink;
1242 /* Tries to move a band to a given offset within a row. */
1243 static int REBAR_MoveBandToRowOffset(REBAR_INFO *infoPtr, INT iBand, INT iFirstBand,
1244 INT iLastBand, INT xOff, BOOL reorder)
1246 REBAR_BAND *insertBand = REBAR_GetBand(infoPtr, iBand);
1247 int xPos = 0, i;
1248 const BOOL setBreak = REBAR_GetBand(infoPtr, iFirstBand)->fStyle & RBBS_BREAK;
1250 /* Find the band's new position */
1251 if(reorder)
1253 /* Used during an LR band reorder drag */
1254 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1256 if(xPos > xOff)
1257 break;
1258 xPos += REBAR_GetBand(infoPtr, i)->cxEffective + SEP_WIDTH;
1261 else
1263 /* Used during a UD band insertion drag */
1264 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1266 const REBAR_BAND *band = REBAR_GetBand(infoPtr, i);
1267 if(xPos + band->cxMinBand / 2 > xOff)
1268 break;
1269 xPos += band->cxEffective + SEP_WIDTH;
1273 /* Move the band to its new position */
1274 DPA_DeletePtr(infoPtr->bands, iBand);
1275 if(i > iBand)
1276 i--;
1277 DPA_InsertPtr(infoPtr->bands, i, insertBand);
1279 /* Ensure only the last band has the RBBS_BREAK flag set */
1280 insertBand->fStyle &= ~RBBS_BREAK;
1281 if(setBreak)
1282 REBAR_GetBand(infoPtr, iFirstBand)->fStyle |= RBBS_BREAK;
1284 /* Return the currently grabbed band */
1285 if(infoPtr->iGrabbedBand == iBand)
1287 infoPtr->iGrabbedBand = i;
1288 return i;
1290 else return -1;
1293 /* Set the heights of the visible bands in [iBeginBand; iEndBand) to the max height. iBeginBand must be visible */
1294 static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
1296 REBAR_BAND *lpBand;
1297 int yMaxHeight = 0;
1298 int yPos = yStart;
1299 int row, i;
1301 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1303 lpBand = REBAR_GetBand(infoPtr, i);
1304 lpBand->cyRowSoFar = yMaxHeight;
1305 yMaxHeight = max(yMaxHeight, lpBand->cyMinBand);
1307 TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
1309 row = iBeginBand < iEndBand ? REBAR_GetBand(infoPtr, iBeginBand)->iRow : 0;
1311 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1313 lpBand = REBAR_GetBand(infoPtr, i);
1314 /* we may be called for multiple rows if RBS_VARHEIGHT not set */
1315 if (lpBand->iRow != row) {
1316 yPos += yMaxHeight + SEP_WIDTH;
1317 row = lpBand->iRow;
1320 if (lpBand->rcBand.top != yPos || lpBand->rcBand.bottom != yPos + yMaxHeight) {
1321 lpBand->fDraw |= NTF_INVALIDATE;
1322 lpBand->rcBand.top = yPos;
1323 lpBand->rcBand.bottom = yPos + yMaxHeight;
1324 TRACE("Band %d: %s\n", i, wine_dbgstr_rect(&lpBand->rcBand));
1327 return yPos + yMaxHeight;
1330 /* Layout the row [iBeginBand; iEndBand). iBeginBand must be visible */
1331 static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
1333 REBAR_BAND *lpBand;
1334 int i, extra;
1335 int width = 0;
1337 TRACE("Adjusting row [%d;%d). Width: %d\n", iBeginBand, iEndBand, cx);
1338 for (i = iBeginBand; i < iEndBand; i++)
1339 REBAR_GetBand(infoPtr, i)->iRow = *piRow;
1341 /* compute the extra space */
1342 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1344 lpBand = REBAR_GetBand(infoPtr, i);
1345 if (i > iBeginBand)
1346 width += SEP_WIDTH;
1347 lpBand->cxEffective = max(lpBand->cxMinBand, lpBand->cx);
1348 width += lpBand->cxEffective;
1351 extra = cx - width;
1352 TRACE("Extra space: %d\n", extra);
1353 if (extra < 0) {
1354 int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
1355 if (ret > 0 && next_visible(infoPtr, iBeginBand) != iEndBand) /* one band may be longer than expected... */
1356 ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
1357 } else
1358 if (extra > 0) {
1359 lpBand = REBAR_FindBandToGrow(infoPtr, iBeginBand, iEndBand);
1360 lpBand->cxEffective += extra;
1363 REBAR_SetRowRectsX(infoPtr, iBeginBand, iEndBand);
1364 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1366 if (*piRow > 0)
1367 *pyPos += SEP_WIDTH;
1368 *pyPos = REBAR_SetBandsHeight(infoPtr, iBeginBand, iEndBand, *pyPos);
1370 (*piRow)++;
1373 static VOID
1374 REBAR_Layout(REBAR_INFO *infoPtr)
1376 REBAR_BAND *lpBand;
1377 RECT rcAdj;
1378 SIZE oldSize;
1379 INT adjcx, i;
1380 INT rowstart;
1381 INT row = 0;
1382 INT xMin, yPos;
1384 if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
1385 GetClientRect(infoPtr->hwndSelf, &rcAdj);
1386 else
1387 GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
1388 TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
1390 adjcx = get_rect_cx(infoPtr, &rcAdj);
1392 if (infoPtr->uNumBands == 0) {
1393 TRACE("No bands - setting size to (0,%d), style: %x\n", adjcx, infoPtr->dwStyle);
1394 infoPtr->calcSize.cx = adjcx;
1395 /* the calcSize.cy won't change for a 0 band rebar */
1396 infoPtr->uNumRows = 0;
1397 REBAR_ForceResize(infoPtr);
1398 return;
1401 yPos = 0;
1402 xMin = 0;
1403 rowstart = first_visible(infoPtr);
1404 /* divide rows */
1405 for (i = rowstart; i < infoPtr->uNumBands; i = next_visible(infoPtr, i))
1407 lpBand = REBAR_GetBand(infoPtr, i);
1409 if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->cxMinBand > adjcx)) {
1410 TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
1411 REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
1412 rowstart = i;
1413 xMin = 0;
1415 else
1416 xMin += SEP_WIDTH;
1418 xMin += lpBand->cxMinBand;
1420 if (rowstart < infoPtr->uNumBands)
1421 REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
1423 if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
1424 yPos = REBAR_SetBandsHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, 0);
1426 infoPtr->uNumRows = row;
1428 if (infoPtr->dwStyle & CCS_VERT)
1429 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1430 else
1431 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1432 /* now compute size of Rebar itself */
1433 oldSize = infoPtr->calcSize;
1435 infoPtr->calcSize.cx = adjcx;
1436 infoPtr->calcSize.cy = yPos;
1437 TRACE("calcsize size=(%d, %d), origheight=(%d,%d)\n",
1438 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1439 oldSize.cx, oldSize.cy);
1441 REBAR_DumpBand (infoPtr);
1442 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1443 REBAR_ForceResize (infoPtr);
1445 /* note: after a RBN_HEIGHTCHANGE native sends once again all the RBN_CHILDSIZE
1446 * and does another ForceResize */
1447 if (oldSize.cy != infoPtr->calcSize.cy)
1449 NMHDR heightchange;
1450 REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1451 REBAR_AutoSize(infoPtr, FALSE);
1455 /* iBeginBand must be visible */
1456 static int
1457 REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
1459 int cyBandsOld;
1460 int cyBandsNew = 0;
1461 int i;
1463 TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
1465 cyBandsOld = REBAR_GetBand(infoPtr, iBeginBand)->rcBand.bottom -
1466 REBAR_GetBand(infoPtr, iBeginBand)->rcBand.top;
1467 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1469 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1470 int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
1471 int cyChild = round_child_height(lpBand, cyMaxChild);
1473 if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
1475 TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
1476 *fChanged = TRUE;
1477 lpBand->cyChild = cyChild;
1478 lpBand->fDraw |= NTF_INVALIDATE;
1479 update_min_band_height(infoPtr, lpBand);
1481 cyBandsNew = max(cyBandsNew, lpBand->cyMinBand);
1483 return cyBandsNew - cyBandsOld;
1486 /* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
1487 static VOID
1488 REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
1490 int extra = height - infoPtr->calcSize.cy; /* may be negative */
1491 BOOL fChanged = FALSE;
1492 UINT uNumRows = infoPtr->uNumRows;
1493 int i;
1495 if (uNumRows == 0) /* avoid division by 0 */
1496 return;
1498 /* That's not exactly what Windows does but should be similar */
1500 /* Pass one: break-up/glue rows */
1501 if (extra > 0)
1503 for (i = prev_visible(infoPtr, infoPtr->uNumBands); i > 0; i = prev_visible(infoPtr, i))
1505 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1506 int cyBreakExtra; /* additional cy for the rebar after a RBBS_BREAK on this band */
1508 height = lpBand->rcBand.bottom - lpBand->rcBand.top;
1510 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1511 cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
1512 else
1513 cyBreakExtra = height; /* 'height' => 'height' + 'height'*/
1514 cyBreakExtra += SEP_WIDTH;
1516 if (extra <= cyBreakExtra / 2)
1517 break;
1519 if (!(lpBand->fStyle & RBBS_BREAK))
1521 TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
1522 lpBand->fStyle |= RBBS_BREAK;
1523 lpBand->fDraw |= NTF_INVALIDATE;
1524 fChanged = TRUE;
1525 extra -= cyBreakExtra;
1526 uNumRows++;
1527 /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
1528 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1529 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->cyMinBand;
1533 /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
1535 /* Pass two: increase/decrease control height */
1536 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1538 int i = first_visible(infoPtr);
1539 int iRow = 0;
1540 while (i < infoPtr->uNumBands)
1542 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1543 int extraForRow = extra / (int)(uNumRows - iRow);
1544 int rowEnd;
1546 /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
1547 for (rowEnd = next_visible(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_visible(infoPtr, rowEnd))
1548 if (REBAR_GetBand(infoPtr, rowEnd)->iRow != lpBand->iRow ||
1549 REBAR_GetBand(infoPtr, rowEnd)->fStyle & RBBS_BREAK)
1550 break;
1552 extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
1553 TRACE("extra = %d\n", extra);
1554 i = rowEnd;
1555 iRow++;
1558 else
1559 REBAR_SizeChildrenToHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
1561 if (fChanged)
1562 REBAR_Layout(infoPtr);
1565 static VOID
1566 REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout)
1568 RECT rc, rcNew;
1569 NMRBAUTOSIZE autosize;
1571 if (needsLayout)
1572 REBAR_Layout(infoPtr);
1573 GetClientRect(infoPtr->hwndSelf, &rc);
1574 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, &rc));
1575 GetClientRect(infoPtr->hwndSelf, &rcNew);
1577 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
1578 autosize.fChanged = EqualRect(&rc, &rcNew);
1579 autosize.rcTarget = rc;
1580 autosize.rcActual = rcNew;
1581 REBAR_Notify((NMHDR *)&autosize, infoPtr, RBN_AUTOSIZE);
1584 static VOID
1585 REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1586 /* Function: This routine evaluates the band specs supplied */
1587 /* by the user and updates the following 5 fields in */
1588 /* the internal band structure: cxHeader, cyHeader, cxMinBand, cyMinBand, fStatus */
1590 UINT header=0;
1591 UINT textheight=0, imageheight = 0;
1592 UINT i, nonfixed;
1593 REBAR_BAND *tBand;
1595 lpBand->fStatus = 0;
1596 lpBand->cxMinBand = 0;
1597 lpBand->cyMinBand = 0;
1599 /* Data coming in from users into the cx... and cy... fields */
1600 /* may be bad, just garbage, because the user never clears */
1601 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1602 /* along if the fields exist in the input area. Here we must */
1603 /* determine if the data is valid. I have no idea how MS does */
1604 /* the validation, but it does because the RB_GETBANDINFO */
1605 /* returns a 0 when I know the sample program passed in an */
1606 /* address. Here I will use the algorithm that if the value */
1607 /* is greater than 65535 then it is bad and replace it with */
1608 /* a zero. Feel free to improve the algorithm. - GA 12/2000 */
1609 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1610 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1611 if (lpBand->cx > 65535) lpBand->cx = 0;
1612 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1613 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1614 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1615 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1617 /* TODO : we could try return to the caller if a value changed so that */
1618 /* a REBAR_Layout is needed. Till now the caller should call it */
1619 /* it always (we should also check what native does) */
1621 /* Header is where the image, text and gripper exist */
1622 /* in the band and precede the child window. */
1624 /* count number of non-FIXEDSIZE and non-Hidden bands */
1625 nonfixed = 0;
1626 for (i=0; i<infoPtr->uNumBands; i++){
1627 tBand = REBAR_GetBand(infoPtr, i);
1628 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1629 nonfixed++;
1632 /* calculate gripper rectangle */
1633 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1634 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1635 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1637 lpBand->fStatus |= HAS_GRIPPER;
1638 if (infoPtr->dwStyle & CCS_VERT)
1639 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1640 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1641 else
1642 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1643 else
1644 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1645 /* Always have 4 pixels before anything else */
1646 header += REBAR_ALWAYS_SPACE;
1649 /* image is visible */
1650 if (lpBand->iImage != -1 && (infoPtr->himl)) {
1651 lpBand->fStatus |= HAS_IMAGE;
1652 if (infoPtr->dwStyle & CCS_VERT) {
1653 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1654 imageheight = infoPtr->imageSize.cx + 4;
1656 else {
1657 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1658 imageheight = infoPtr->imageSize.cy + 4;
1662 /* text is visible */
1663 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
1664 !(lpBand->fStyle & RBBS_HIDETITLE)) {
1665 HDC hdc = GetDC (0);
1666 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1667 SIZE size;
1669 lpBand->fStatus |= HAS_TEXT;
1670 GetTextExtentPoint32W (hdc, lpBand->lpText,
1671 lstrlenW (lpBand->lpText), &size);
1672 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1673 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1675 SelectObject (hdc, hOldFont);
1676 ReleaseDC (0, hdc);
1679 /* if no gripper but either image or text, then leave space */
1680 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1681 !(lpBand->fStatus & HAS_GRIPPER)) {
1682 header += REBAR_ALWAYS_SPACE;
1685 /* check if user overrode the header value */
1686 if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
1687 lpBand->cxHeader = header;
1688 lpBand->cyHeader = max(textheight, imageheight);
1690 /* Now compute minimum size of child window */
1691 update_min_band_height(infoPtr, lpBand); /* update lpBand->cyMinBand from cyHeader and cyChild*/
1693 lpBand->cxMinBand = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
1694 if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
1695 lpBand->cxMinBand += CHEVRON_WIDTH;
1698 static UINT
1699 REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
1700 /* Function: This routine copies the supplied values from */
1701 /* user input (lprbbi) to the internal band structure. */
1702 /* It returns the mask of what changed. */
1704 UINT uChanged = 0x0;
1706 lpBand->fMask |= lprbbi->fMask;
1708 if( (lprbbi->fMask & RBBIM_STYLE) &&
1709 (lpBand->fStyle != lprbbi->fStyle ) )
1711 lpBand->fStyle = lprbbi->fStyle;
1712 uChanged |= RBBIM_STYLE;
1715 if( (lprbbi->fMask & RBBIM_COLORS) &&
1716 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
1717 ( lpBand->clrBack != lprbbi->clrBack ) ) )
1719 lpBand->clrFore = lprbbi->clrFore;
1720 lpBand->clrBack = lprbbi->clrBack;
1721 uChanged |= RBBIM_COLORS;
1724 if( (lprbbi->fMask & RBBIM_IMAGE) &&
1725 ( lpBand->iImage != lprbbi->iImage ) )
1727 lpBand->iImage = lprbbi->iImage;
1728 uChanged |= RBBIM_IMAGE;
1731 if( (lprbbi->fMask & RBBIM_CHILD) &&
1732 (lprbbi->hwndChild != lpBand->hwndChild ) )
1734 if (lprbbi->hwndChild) {
1735 lpBand->hwndChild = lprbbi->hwndChild;
1736 lpBand->hwndPrevParent =
1737 SetParent (lpBand->hwndChild, hwnd);
1738 /* below in trace from WinRAR */
1739 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
1740 /* above in trace from WinRAR */
1742 else {
1743 TRACE("child: %p prev parent: %p\n",
1744 lpBand->hwndChild, lpBand->hwndPrevParent);
1745 lpBand->hwndChild = 0;
1746 lpBand->hwndPrevParent = 0;
1748 uChanged |= RBBIM_CHILD;
1751 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
1752 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
1753 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
1754 ( (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) &&
1755 ( (lpBand->cyChild != lprbbi->cyChild ) ||
1756 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
1757 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
1758 ( (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE) &&
1759 ( (lpBand->cyChild ||
1760 lpBand->cyMaxChild ||
1761 lpBand->cyIntegral ) ) ) ) )
1763 lpBand->cxMinChild = lprbbi->cxMinChild;
1764 lpBand->cyMinChild = lprbbi->cyMinChild;
1765 /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
1766 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
1767 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1768 lpBand->cyIntegral = lprbbi->cyIntegral;
1770 lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild); /* make (cyChild - cyMinChild) a multiple of cyIntergral */
1772 else {
1773 lpBand->cyChild = lpBand->cyMinChild;
1774 lpBand->cyMaxChild = 0x7fffffff;
1775 lpBand->cyIntegral = 0;
1777 uChanged |= RBBIM_CHILDSIZE;
1780 if( (lprbbi->fMask & RBBIM_SIZE) &&
1781 (lpBand->cx != lprbbi->cx ) )
1783 lpBand->cx = lprbbi->cx;
1784 uChanged |= RBBIM_SIZE;
1787 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
1788 ( lpBand->hbmBack != lprbbi->hbmBack ) )
1790 lpBand->hbmBack = lprbbi->hbmBack;
1791 uChanged |= RBBIM_BACKGROUND;
1794 if( (lprbbi->fMask & RBBIM_ID) &&
1795 (lpBand->wID != lprbbi->wID ) )
1797 lpBand->wID = lprbbi->wID;
1798 uChanged |= RBBIM_ID;
1801 /* check for additional data */
1802 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE) {
1803 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
1804 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
1806 lpBand->cxIdeal = lprbbi->cxIdeal;
1807 uChanged |= RBBIM_IDEALSIZE;
1810 if( (lprbbi->fMask & RBBIM_LPARAM) &&
1811 (lpBand->lParam != lprbbi->lParam ) )
1813 lpBand->lParam = lprbbi->lParam;
1814 uChanged |= RBBIM_LPARAM;
1817 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
1818 (lpBand->cxHeader != lprbbi->cxHeader ) )
1820 lpBand->cxHeader = lprbbi->cxHeader;
1821 lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
1822 uChanged |= RBBIM_HEADERSIZE;
1826 return uChanged;
1829 static LRESULT REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, HDC hdc)
1830 /* Function: This erases the background rectangle by drawing */
1831 /* each band with its background color (or the default) and */
1832 /* draws each bands right separator if necessary. The row */
1833 /* separators are drawn on the first band of the next row. */
1835 REBAR_BAND *lpBand;
1836 UINT i;
1837 INT oldrow;
1838 RECT cr;
1839 COLORREF old = CLR_NONE, new;
1840 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1842 GetClientRect (infoPtr->hwndSelf, &cr);
1844 oldrow = -1;
1845 for(i=0; i<infoPtr->uNumBands; i++) {
1846 RECT rcBand;
1847 lpBand = REBAR_GetBand(infoPtr, i);
1848 if (HIDDENBAND(lpBand)) continue;
1849 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1851 /* draw band separator between rows */
1852 if (lpBand->iRow != oldrow) {
1853 oldrow = lpBand->iRow;
1854 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1855 RECT rcRowSep;
1856 rcRowSep = rcBand;
1857 if (infoPtr->dwStyle & CCS_VERT) {
1858 rcRowSep.right += SEP_WIDTH_SIZE;
1859 rcRowSep.bottom = infoPtr->calcSize.cx;
1860 if (theme)
1861 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_RIGHT, NULL);
1862 else
1863 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
1865 else {
1866 rcRowSep.bottom += SEP_WIDTH_SIZE;
1867 rcRowSep.right = infoPtr->calcSize.cx;
1868 if (theme)
1869 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1870 else
1871 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
1873 TRACE ("drawing band separator bottom (%s)\n",
1874 wine_dbgstr_rect(&rcRowSep));
1878 /* draw band separator between bands in a row */
1879 if (infoPtr->dwStyle & RBS_BANDBORDERS && lpBand->rcBand.left > 0) {
1880 RECT rcSep;
1881 rcSep = rcBand;
1882 if (infoPtr->dwStyle & CCS_VERT) {
1883 rcSep.bottom = rcSep.top;
1884 rcSep.top -= SEP_WIDTH_SIZE;
1885 if (theme)
1886 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1887 else
1888 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
1890 else {
1891 rcSep.right = rcSep.left;
1892 rcSep.left -= SEP_WIDTH_SIZE;
1893 if (theme)
1894 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_RIGHT, NULL);
1895 else
1896 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
1898 TRACE("drawing band separator right (%s)\n",
1899 wine_dbgstr_rect(&rcSep));
1902 /* draw the actual background */
1903 if (lpBand->clrBack != CLR_NONE) {
1904 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
1905 lpBand->clrBack;
1906 #if GLATESTING
1907 /* testing only - make background green to see it */
1908 new = RGB(0,128,0);
1909 #endif
1911 else {
1912 /* In the absence of documentation for Rebar vs. CLR_NONE,
1913 * we will use the default BtnFace color. Note documentation
1914 * exists for Listview and Imagelist.
1916 new = infoPtr->clrBtnFace;
1917 #if GLATESTING
1918 /* testing only - make background green to see it */
1919 new = RGB(0,128,0);
1920 #endif
1923 if (theme)
1925 /* When themed, the background color is ignored (but not a
1926 * background bitmap */
1927 DrawThemeBackground (theme, hdc, 0, 0, &cr, &rcBand);
1929 else
1931 old = SetBkColor (hdc, new);
1932 TRACE("%s background color=0x%06x, band %s\n",
1933 (lpBand->clrBack == CLR_NONE) ? "none" :
1934 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
1935 GetBkColor(hdc), wine_dbgstr_rect(&rcBand));
1936 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &rcBand, NULL, 0, 0);
1937 if (lpBand->clrBack != CLR_NONE)
1938 SetBkColor (hdc, old);
1941 return TRUE;
1944 static void
1945 REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
1947 REBAR_BAND *lpBand;
1948 RECT rect;
1949 UINT iCount;
1951 GetClientRect (infoPtr->hwndSelf, &rect);
1953 *pFlags = RBHT_NOWHERE;
1954 if (PtInRect (&rect, *lpPt))
1956 if (infoPtr->uNumBands == 0) {
1957 *pFlags = RBHT_NOWHERE;
1958 if (pBand)
1959 *pBand = -1;
1960 TRACE("NOWHERE\n");
1961 return;
1963 else {
1964 /* somewhere inside */
1965 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
1966 RECT rcBand;
1967 lpBand = REBAR_GetBand(infoPtr, iCount);
1968 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1969 if (HIDDENBAND(lpBand)) continue;
1970 if (PtInRect (&rcBand, *lpPt)) {
1971 if (pBand)
1972 *pBand = iCount;
1973 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
1974 *pFlags = RBHT_GRABBER;
1975 TRACE("ON GRABBER %d\n", iCount);
1976 return;
1978 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
1979 *pFlags = RBHT_CAPTION;
1980 TRACE("ON CAPTION %d\n", iCount);
1981 return;
1983 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
1984 *pFlags = RBHT_CAPTION;
1985 TRACE("ON CAPTION %d\n", iCount);
1986 return;
1988 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
1989 *pFlags = RBHT_CLIENT;
1990 TRACE("ON CLIENT %d\n", iCount);
1991 return;
1993 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
1994 *pFlags = RBHT_CHEVRON;
1995 TRACE("ON CHEVRON %d\n", iCount);
1996 return;
1998 else {
1999 *pFlags = RBHT_NOWHERE;
2000 TRACE("NOWHERE %d\n", iCount);
2001 return;
2006 *pFlags = RBHT_NOWHERE;
2007 if (pBand)
2008 *pBand = -1;
2010 TRACE("NOWHERE\n");
2011 return;
2014 else {
2015 *pFlags = RBHT_NOWHERE;
2016 if (pBand)
2017 *pBand = -1;
2018 TRACE("NOWHERE\n");
2019 return;
2023 static void
2024 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2025 /* Function: This will implement the functionality of a */
2026 /* Gripper drag within a row. It will not implement "out- */
2027 /* of-row" drags. (They are detected and handled in */
2028 /* REBAR_MouseMove.) */
2030 REBAR_BAND *hitBand;
2031 INT iHitBand, iRowBegin, iRowEnd;
2032 INT movement, xBand, cxLeft = 0;
2033 BOOL shrunkBands = FALSE;
2035 iHitBand = infoPtr->iGrabbedBand;
2036 iRowBegin = get_row_begin_for_band(infoPtr, iHitBand);
2037 iRowEnd = get_row_end_for_band(infoPtr, iHitBand);
2038 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2040 xBand = hitBand->rcBand.left;
2041 movement = (infoPtr->dwStyle&CCS_VERT ? ptsmove->y : ptsmove->x)
2042 - (xBand + REBAR_PRE_GRIPPER - infoPtr->ihitoffset);
2044 /* Dragging the first band in a row cannot cause shrinking */
2045 if(iHitBand != iRowBegin)
2047 if (movement < 0) {
2048 cxLeft = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iHitBand, -movement, TRUE);
2050 if(cxLeft < -movement)
2052 hitBand->cxEffective += -movement - cxLeft;
2053 hitBand->cx = hitBand->cxEffective;
2054 shrunkBands = TRUE;
2057 } else if (movement > 0) {
2059 cxLeft = movement;
2060 if (prev_visible(infoPtr, iHitBand) >= 0)
2061 cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
2063 if(cxLeft < movement)
2065 REBAR_BAND *lpPrev = REBAR_GetBand(infoPtr, prev_visible(infoPtr, iHitBand));
2066 lpPrev->cxEffective += movement - cxLeft;
2067 lpPrev->cx = hitBand->cxEffective;
2068 shrunkBands = TRUE;
2074 if(!shrunkBands)
2076 /* It was not possible to move the band by shrinking bands.
2077 * Try relocating the band instead. */
2078 REBAR_MoveBandToRowOffset(infoPtr, iHitBand, iRowBegin,
2079 iRowEnd, xBand + movement, TRUE);
2082 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2083 if (infoPtr->dwStyle & CCS_VERT)
2084 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
2085 else
2086 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
2087 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2090 static void
2091 REBAR_HandleUDDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2093 INT yOff = (infoPtr->dwStyle & CCS_VERT) ? ptsmove->x : ptsmove->y;
2094 INT iHitBand, iRowBegin, iNextRowBegin;
2095 REBAR_BAND *hitBand, *rowBeginBand;
2097 if(infoPtr->uNumBands <= 0)
2098 ERR("There are no bands in this rebar\n");
2100 /* Up/down dragging can only occur when there is more than one
2101 * band in the rebar */
2102 if(infoPtr->uNumBands <= 1)
2103 return;
2105 iHitBand = infoPtr->iGrabbedBand;
2106 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2108 /* If we're taking a band that has the RBBS_BREAK style set, this
2109 * style needs to be reapplied to the band that is going to become
2110 * the new start of the row. */
2111 if((hitBand->fStyle & RBBS_BREAK) &&
2112 (iHitBand < infoPtr->uNumBands - 1))
2113 REBAR_GetBand(infoPtr, iHitBand + 1)->fStyle |= RBBS_BREAK;
2115 if(yOff < 0)
2117 /* Place the band above the current top row */
2118 if(iHitBand==0 && (infoPtr->uNumBands==1 || REBAR_GetBand(infoPtr, 1)->fStyle&RBBS_BREAK))
2119 return;
2120 DPA_DeletePtr(infoPtr->bands, iHitBand);
2121 hitBand->fStyle &= ~RBBS_BREAK;
2122 REBAR_GetBand(infoPtr, 0)->fStyle |= RBBS_BREAK;
2123 infoPtr->iGrabbedBand = DPA_InsertPtr(
2124 infoPtr->bands, 0, hitBand);
2126 else if(yOff > REBAR_GetBand(infoPtr, infoPtr->uNumBands - 1)->rcBand.bottom)
2128 /* Place the band below the current bottom row */
2129 if(iHitBand == infoPtr->uNumBands-1 && hitBand->fStyle&RBBS_BREAK)
2130 return;
2131 DPA_DeletePtr(infoPtr->bands, iHitBand);
2132 hitBand->fStyle |= RBBS_BREAK;
2133 infoPtr->iGrabbedBand = DPA_InsertPtr(
2134 infoPtr->bands, infoPtr->uNumBands - 1, hitBand);
2136 else
2138 /* Place the band in the preexisting row the mouse is hovering over */
2139 iRowBegin = first_visible(infoPtr);
2140 while(iRowBegin < infoPtr->uNumBands)
2142 iNextRowBegin = get_row_end_for_band(infoPtr, iRowBegin);
2143 rowBeginBand = REBAR_GetBand(infoPtr, iRowBegin);
2144 if(rowBeginBand->rcBand.bottom > yOff)
2146 REBAR_MoveBandToRowOffset(
2147 infoPtr, iHitBand, iRowBegin, iNextRowBegin,
2148 ((infoPtr->dwStyle & CCS_VERT) ? ptsmove->y : ptsmove->x)
2149 - REBAR_PRE_GRIPPER - infoPtr->ihitoffset, FALSE);
2150 break;
2153 iRowBegin = iNextRowBegin;
2157 REBAR_Layout(infoPtr);
2161 /* << REBAR_BeginDrag >> */
2164 static LRESULT
2165 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam)
2167 UINT uBand = (UINT)wParam;
2168 REBAR_BAND *lpBand;
2170 if (uBand >= infoPtr->uNumBands)
2171 return FALSE;
2173 TRACE("deleting band %u!\n", uBand);
2174 lpBand = REBAR_GetBand(infoPtr, uBand);
2175 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2176 /* TODO: a return of 1 should probably cancel the deletion */
2178 if (lpBand->hwndChild)
2179 ShowWindow(lpBand->hwndChild, SW_HIDE);
2180 Free(lpBand->lpText);
2181 Free(lpBand);
2183 infoPtr->uNumBands--;
2184 DPA_DeletePtr(infoPtr->bands, uBand);
2186 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2188 /* if only 1 band left the re-validate to possible eliminate gripper */
2189 if (infoPtr->uNumBands == 1)
2190 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2192 REBAR_Layout(infoPtr);
2194 return TRUE;
2198 /* << REBAR_DragMove >> */
2199 /* << REBAR_EndDrag >> */
2202 static LRESULT
2203 REBAR_GetBandBorders (const REBAR_INFO *infoPtr, UINT uBand, RECT *lpRect)
2205 REBAR_BAND *lpBand;
2207 if (!lpRect)
2208 return 0;
2209 if (uBand >= infoPtr->uNumBands)
2210 return 0;
2212 lpBand = REBAR_GetBand(infoPtr, uBand);
2214 /* FIXME - the following values were determined by experimentation */
2215 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2216 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2217 /* difference in size of the control area with and without the */
2218 /* style. - GA */
2219 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2220 if (infoPtr->dwStyle & CCS_VERT) {
2221 lpRect->left = 1;
2222 lpRect->top = lpBand->cxHeader + 4;
2223 lpRect->right = 1;
2224 lpRect->bottom = 0;
2226 else {
2227 lpRect->left = lpBand->cxHeader + 4;
2228 lpRect->top = 1;
2229 lpRect->right = 0;
2230 lpRect->bottom = 1;
2233 else {
2234 lpRect->left = lpBand->cxHeader;
2236 return 0;
2240 static inline LRESULT
2241 REBAR_GetBandCount (const REBAR_INFO *infoPtr)
2243 TRACE("band count %u!\n", infoPtr->uNumBands);
2245 return infoPtr->uNumBands;
2249 static LRESULT
2250 REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, UINT uIndex, LPREBARBANDINFOW lprbbi, BOOL bUnicode)
2252 REBAR_BAND *lpBand;
2254 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2255 return FALSE;
2257 if (uIndex >= infoPtr->uNumBands)
2258 return FALSE;
2260 TRACE("index %u (bUnicode=%d)\n", uIndex, bUnicode);
2262 /* copy band information */
2263 lpBand = REBAR_GetBand(infoPtr, uIndex);
2265 if (lprbbi->fMask & RBBIM_STYLE)
2266 lprbbi->fStyle = lpBand->fStyle;
2268 if (lprbbi->fMask & RBBIM_COLORS) {
2269 lprbbi->clrFore = lpBand->clrFore;
2270 lprbbi->clrBack = lpBand->clrBack;
2271 if (lprbbi->clrBack == CLR_DEFAULT)
2272 lprbbi->clrBack = infoPtr->clrBtnFace;
2275 if (lprbbi->fMask & RBBIM_TEXT) {
2276 if (bUnicode)
2277 Str_GetPtrW(lpBand->lpText, lprbbi->lpText, lprbbi->cch);
2278 else
2279 Str_GetPtrWtoA(lpBand->lpText, (LPSTR)lprbbi->lpText, lprbbi->cch);
2282 if (lprbbi->fMask & RBBIM_IMAGE)
2283 lprbbi->iImage = lpBand->iImage;
2285 if (lprbbi->fMask & RBBIM_CHILD)
2286 lprbbi->hwndChild = lpBand->hwndChild;
2288 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2289 lprbbi->cxMinChild = lpBand->cxMinChild;
2290 lprbbi->cyMinChild = lpBand->cyMinChild;
2291 /* to make tests pass we follow Windows' behaviour and allow reading these fields only
2292 * for RBBS_VARIABLEHEIGHTS bands */
2293 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2294 lprbbi->cyChild = lpBand->cyChild;
2295 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2296 lprbbi->cyIntegral = lpBand->cyIntegral;
2300 if (lprbbi->fMask & RBBIM_SIZE)
2301 lprbbi->cx = lpBand->cx;
2303 if (lprbbi->fMask & RBBIM_BACKGROUND)
2304 lprbbi->hbmBack = lpBand->hbmBack;
2306 if (lprbbi->fMask & RBBIM_ID)
2307 lprbbi->wID = lpBand->wID;
2309 /* check for additional data */
2310 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE) {
2311 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2312 lprbbi->cxIdeal = lpBand->cxIdeal;
2314 if (lprbbi->fMask & RBBIM_LPARAM)
2315 lprbbi->lParam = lpBand->lParam;
2317 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2318 lprbbi->cxHeader = lpBand->cxHeader;
2321 REBAR_DumpBandInfo(lprbbi);
2323 return TRUE;
2327 static LRESULT
2328 REBAR_GetBarHeight (const REBAR_INFO *infoPtr)
2330 INT nHeight;
2332 nHeight = infoPtr->calcSize.cy;
2334 TRACE("height = %d\n", nHeight);
2336 return nHeight;
2340 static LRESULT
2341 REBAR_GetBarInfo (const REBAR_INFO *infoPtr, LPREBARINFO lpInfo)
2343 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2344 return FALSE;
2346 TRACE("getting bar info!\n");
2348 if (infoPtr->himl) {
2349 lpInfo->himl = infoPtr->himl;
2350 lpInfo->fMask |= RBIM_IMAGELIST;
2353 return TRUE;
2357 static inline LRESULT
2358 REBAR_GetBkColor (const REBAR_INFO *infoPtr)
2360 COLORREF clr = infoPtr->clrBk;
2362 if (clr == CLR_DEFAULT)
2363 clr = infoPtr->clrBtnFace;
2365 TRACE("background color 0x%06x!\n", clr);
2367 return clr;
2371 /* << REBAR_GetColorScheme >> */
2372 /* << REBAR_GetDropTarget >> */
2375 static LRESULT
2376 REBAR_GetPalette (const REBAR_INFO *infoPtr)
2378 FIXME("empty stub!\n");
2380 return 0;
2384 static LRESULT
2385 REBAR_GetRect (const REBAR_INFO *infoPtr, INT iBand, RECT *lprc)
2387 REBAR_BAND *lpBand;
2389 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2390 return FALSE;
2391 if (!lprc)
2392 return FALSE;
2394 lpBand = REBAR_GetBand(infoPtr, iBand);
2395 /* For CCS_VERT the coordinates will be swapped - like on Windows */
2396 *lprc = lpBand->rcBand;
2398 TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
2400 return TRUE;
2404 static inline LRESULT
2405 REBAR_GetRowCount (const REBAR_INFO *infoPtr)
2407 TRACE("%u\n", infoPtr->uNumRows);
2409 return infoPtr->uNumRows;
2413 static LRESULT
2414 REBAR_GetRowHeight (const REBAR_INFO *infoPtr, INT iRow)
2416 int j = 0, ret = 0;
2417 UINT i;
2418 REBAR_BAND *lpBand;
2420 for (i=0; i<infoPtr->uNumBands; i++) {
2421 lpBand = REBAR_GetBand(infoPtr, i);
2422 if (HIDDENBAND(lpBand)) continue;
2423 if (lpBand->iRow != iRow) continue;
2424 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2425 if (j > ret) ret = j;
2428 TRACE("row %d, height %d\n", iRow, ret);
2430 return ret;
2434 static inline LRESULT
2435 REBAR_GetTextColor (const REBAR_INFO *infoPtr)
2437 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2439 return infoPtr->clrText;
2443 static inline LRESULT
2444 REBAR_GetToolTips (const REBAR_INFO *infoPtr)
2446 return (LRESULT)infoPtr->hwndToolTip;
2450 static inline LRESULT
2451 REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
2453 TRACE("%s hwnd=%p\n",
2454 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2456 return infoPtr->bUnicode;
2460 static inline LRESULT
2461 REBAR_GetVersion (const REBAR_INFO *infoPtr)
2463 TRACE("version %d\n", infoPtr->iVersion);
2464 return infoPtr->iVersion;
2468 static LRESULT
2469 REBAR_HitTest (const REBAR_INFO *infoPtr, LPRBHITTESTINFO lprbht)
2471 if (!lprbht)
2472 return -1;
2474 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2476 return lprbht->iBand;
2480 static LRESULT
2481 REBAR_IdToIndex (const REBAR_INFO *infoPtr, UINT uId)
2483 UINT i;
2485 if (infoPtr->uNumBands < 1)
2486 return -1;
2488 for (i = 0; i < infoPtr->uNumBands; i++) {
2489 if (REBAR_GetBand(infoPtr, i)->wID == uId) {
2490 TRACE("id %u is band %u found!\n", uId, i);
2491 return i;
2495 TRACE("id %u is not found\n", uId);
2496 return -1;
2500 static LRESULT
2501 REBAR_InsertBandT(REBAR_INFO *infoPtr, INT iIndex, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2503 REBAR_BAND *lpBand;
2505 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2506 return FALSE;
2508 /* trace the index as signed to see the -1 */
2509 TRACE("insert band at %d (bUnicode=%d)!\n", iIndex, bUnicode);
2510 REBAR_DumpBandInfo(lprbbi);
2512 if (!(lpBand = Alloc(sizeof(REBAR_BAND)))) return FALSE;
2513 if ((iIndex == -1) || (iIndex > infoPtr->uNumBands))
2514 iIndex = infoPtr->uNumBands;
2515 if (DPA_InsertPtr(infoPtr->bands, iIndex, lpBand) == -1)
2517 Free(lpBand);
2518 return FALSE;
2520 infoPtr->uNumBands++;
2522 TRACE("index %d!\n", iIndex);
2524 /* initialize band */
2525 memset(lpBand, 0, sizeof(*lpBand));
2526 lpBand->clrFore = infoPtr->clrText == CLR_NONE ? infoPtr->clrBtnText :
2527 infoPtr->clrText;
2528 lpBand->clrBack = infoPtr->clrBk == CLR_NONE ? infoPtr->clrBtnFace :
2529 infoPtr->clrBk;
2530 lpBand->iImage = -1;
2532 REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
2534 /* Make sure the defaults for these are correct */
2535 if (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE || !(lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2536 lpBand->cyChild = lpBand->cyMinChild;
2537 lpBand->cyMaxChild = 0x7fffffff;
2538 lpBand->cyIntegral = 0;
2541 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2542 if (bUnicode)
2543 Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
2544 else
2545 Str_SetPtrAtoW(&lpBand->lpText, (LPSTR)lprbbi->lpText);
2548 REBAR_ValidateBand (infoPtr, lpBand);
2549 /* On insert of second band, revalidate band 1 to possible add gripper */
2550 if (infoPtr->uNumBands == 2)
2551 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2553 REBAR_DumpBand (infoPtr);
2555 REBAR_Layout(infoPtr);
2556 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2558 return TRUE;
2562 static LRESULT
2563 REBAR_MaximizeBand (const REBAR_INFO *infoPtr, INT iBand, LPARAM lParam)
2565 REBAR_BAND *lpBand;
2566 int iRowBegin, iRowEnd;
2567 int cxDesired, extra, extraOrig;
2568 int cxIdealBand;
2570 /* Validate */
2571 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2572 /* error !!! */
2573 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
2574 iBand, infoPtr->uNumBands);
2575 return FALSE;
2578 lpBand = REBAR_GetBand(infoPtr, iBand);
2580 if (lpBand->fStyle & RBBS_HIDDEN)
2582 /* Windows is buggy and creates a hole */
2583 WARN("Ignoring maximize request on a hidden band (%d)\n", iBand);
2584 return FALSE;
2587 cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
2588 if (lParam && (lpBand->cxEffective < cxIdealBand))
2589 cxDesired = cxIdealBand;
2590 else
2591 cxDesired = infoPtr->calcSize.cx;
2593 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2594 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2595 extraOrig = extra = cxDesired - lpBand->cxEffective;
2596 if (extra > 0)
2597 extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iBand, extra, TRUE);
2598 if (extra > 0)
2599 extra = REBAR_ShrinkBandsLTR(infoPtr, next_visible(infoPtr, iBand), iRowEnd, extra, TRUE);
2600 lpBand->cxEffective += extraOrig - extra;
2601 lpBand->cx = lpBand->cxEffective;
2602 TRACE("(%d, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", iBand, lParam, cxDesired, lpBand->cx, extraOrig, extra);
2603 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2605 if (infoPtr->dwStyle & CCS_VERT)
2606 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2607 else
2608 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2609 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2610 return TRUE;
2615 static LRESULT
2616 REBAR_MinimizeBand (const REBAR_INFO *infoPtr, INT iBand)
2618 REBAR_BAND *lpBand;
2619 int iPrev, iRowBegin, iRowEnd;
2621 /* A "minimize" band is equivalent to "dragging" the gripper
2622 * of than band to the right till the band is only the size
2623 * of the cxHeader.
2626 /* Validate */
2627 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2628 /* error !!! */
2629 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
2630 iBand, infoPtr->uNumBands);
2631 return FALSE;
2634 /* compute amount of movement and validate */
2635 lpBand = REBAR_GetBand(infoPtr, iBand);
2637 if (lpBand->fStyle & RBBS_HIDDEN)
2639 /* Windows is buggy and creates a hole/overlap */
2640 WARN("Ignoring minimize request on a hidden band (%d)\n", iBand);
2641 return FALSE;
2644 iPrev = prev_visible(infoPtr, iBand);
2645 /* if first band in row */
2646 if (iPrev < 0 || REBAR_GetBand(infoPtr, iPrev)->iRow != lpBand->iRow) {
2647 int iNext = next_visible(infoPtr, iBand);
2648 if (iNext < infoPtr->uNumBands && REBAR_GetBand(infoPtr, iNext)->iRow == lpBand->iRow) {
2649 TRACE("(%d): Minimizing the first band in row is by maximizing the second\n", iBand);
2650 REBAR_MaximizeBand(infoPtr, iNext, FALSE);
2652 else
2653 TRACE("(%d): Only one band in row - nothing to do\n", iBand);
2654 return TRUE;
2657 REBAR_GetBand(infoPtr, iPrev)->cxEffective += lpBand->cxEffective - lpBand->cxMinBand;
2658 REBAR_GetBand(infoPtr, iPrev)->cx = REBAR_GetBand(infoPtr, iPrev)->cxEffective;
2659 lpBand->cx = lpBand->cxEffective = lpBand->cxMinBand;
2661 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2662 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2663 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2665 if (infoPtr->dwStyle & CCS_VERT)
2666 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2667 else
2668 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2669 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2670 return FALSE;
2674 static LRESULT
2675 REBAR_MoveBand (REBAR_INFO *infoPtr, INT iFrom, INT iTo)
2677 REBAR_BAND *lpBand;
2679 /* Validate */
2680 if ((infoPtr->uNumBands == 0) ||
2681 (iFrom < 0) || iFrom >= infoPtr->uNumBands ||
2682 (iTo < 0) || iTo >= infoPtr->uNumBands) {
2683 /* error !!! */
2684 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
2685 iFrom, iTo, infoPtr->uNumBands);
2686 return FALSE;
2689 lpBand = REBAR_GetBand(infoPtr, iFrom);
2690 DPA_DeletePtr(infoPtr->bands, iFrom);
2691 DPA_InsertPtr(infoPtr->bands, iTo, lpBand);
2693 TRACE("moved band %d to index %d\n", iFrom, iTo);
2694 REBAR_DumpBand (infoPtr);
2696 /* **************************************************** */
2697 /* */
2698 /* We do not do a REBAR_Layout here because the native */
2699 /* control does not do that. The actual layout and */
2700 /* repaint is done by the *next* real action, ex.: */
2701 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
2702 /* */
2703 /* **************************************************** */
2705 return TRUE;
2709 /* return TRUE if two strings are different */
2710 static BOOL
2711 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
2713 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
2716 static LRESULT
2717 REBAR_SetBandInfoT(REBAR_INFO *infoPtr, INT iBand, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2719 REBAR_BAND *lpBand;
2720 UINT uChanged;
2722 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2723 return FALSE;
2725 if (iBand >= infoPtr->uNumBands)
2726 return FALSE;
2728 TRACE("index %d\n", iBand);
2729 REBAR_DumpBandInfo (lprbbi);
2731 /* set band information */
2732 lpBand = REBAR_GetBand(infoPtr, iBand);
2734 uChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2735 if (lprbbi->fMask & RBBIM_TEXT) {
2736 LPWSTR wstr = NULL;
2737 if (bUnicode)
2738 Str_SetPtrW(&wstr, lprbbi->lpText);
2739 else
2740 Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
2742 if (REBAR_strdifW(wstr, lpBand->lpText)) {
2743 Free(lpBand->lpText);
2744 lpBand->lpText = wstr;
2745 uChanged |= RBBIM_TEXT;
2747 else
2748 Free(wstr);
2751 REBAR_ValidateBand (infoPtr, lpBand);
2753 REBAR_DumpBand (infoPtr);
2755 if (uChanged & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IMAGE)) {
2756 REBAR_Layout(infoPtr);
2757 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2760 return TRUE;
2764 static LRESULT
2765 REBAR_SetBarInfo (REBAR_INFO *infoPtr, const REBARINFO *lpInfo)
2767 REBAR_BAND *lpBand;
2768 UINT i;
2770 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2771 return FALSE;
2773 TRACE("setting bar info!\n");
2775 if (lpInfo->fMask & RBIM_IMAGELIST) {
2776 infoPtr->himl = lpInfo->himl;
2777 if (infoPtr->himl) {
2778 INT cx, cy;
2779 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
2780 infoPtr->imageSize.cx = cx;
2781 infoPtr->imageSize.cy = cy;
2783 else {
2784 infoPtr->imageSize.cx = 0;
2785 infoPtr->imageSize.cy = 0;
2787 TRACE("new image cx=%d, cy=%d\n", infoPtr->imageSize.cx,
2788 infoPtr->imageSize.cy);
2791 /* revalidate all bands to reset flags for images in headers of bands */
2792 for (i=0; i<infoPtr->uNumBands; i++) {
2793 lpBand = REBAR_GetBand(infoPtr, i);
2794 REBAR_ValidateBand (infoPtr, lpBand);
2797 return TRUE;
2801 static LRESULT
2802 REBAR_SetBkColor (REBAR_INFO *infoPtr, COLORREF clr)
2804 COLORREF clrTemp;
2806 clrTemp = infoPtr->clrBk;
2807 infoPtr->clrBk = clr;
2809 TRACE("background color 0x%06x!\n", infoPtr->clrBk);
2811 return clrTemp;
2815 /* << REBAR_SetColorScheme >> */
2816 /* << REBAR_SetPalette >> */
2819 static LRESULT
2820 REBAR_SetParent (REBAR_INFO *infoPtr, HWND parent)
2822 HWND hwndTemp = infoPtr->hwndNotify;
2824 infoPtr->hwndNotify = parent;
2826 return (LRESULT)hwndTemp;
2830 static LRESULT
2831 REBAR_SetTextColor (REBAR_INFO *infoPtr, COLORREF clr)
2833 COLORREF clrTemp;
2835 clrTemp = infoPtr->clrText;
2836 infoPtr->clrText = clr;
2838 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2840 return clrTemp;
2844 /* << REBAR_SetTooltips >> */
2847 static inline LRESULT
2848 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, BOOL unicode)
2850 BOOL bTemp = infoPtr->bUnicode;
2852 TRACE("to %s hwnd=%p, was %s\n",
2853 unicode ? "TRUE" : "FALSE", infoPtr->hwndSelf,
2854 (bTemp) ? "TRUE" : "FALSE");
2856 infoPtr->bUnicode = unicode;
2858 return bTemp;
2862 static LRESULT
2863 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
2865 INT iOldVersion = infoPtr->iVersion;
2867 if (iVersion > COMCTL32_VERSION)
2868 return -1;
2870 infoPtr->iVersion = iVersion;
2872 TRACE("new version %d\n", iVersion);
2874 return iOldVersion;
2878 static LRESULT
2879 REBAR_ShowBand (REBAR_INFO *infoPtr, INT iBand, BOOL show)
2881 REBAR_BAND *lpBand;
2883 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2884 return FALSE;
2886 lpBand = REBAR_GetBand(infoPtr, iBand);
2888 if (show) {
2889 TRACE("show band %d\n", iBand);
2890 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
2891 if (IsWindow (lpBand->hwndChild))
2892 ShowWindow (lpBand->hwndChild, SW_SHOW);
2894 else {
2895 TRACE("hide band %d\n", iBand);
2896 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
2897 if (IsWindow (lpBand->hwndChild))
2898 ShowWindow (lpBand->hwndChild, SW_HIDE);
2901 REBAR_Layout(infoPtr);
2902 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2904 return TRUE;
2908 static LRESULT
2909 REBAR_SizeToRect (REBAR_INFO *infoPtr, const RECT *lpRect)
2911 if (!lpRect) return FALSE;
2913 TRACE("[%s]\n", wine_dbgstr_rect(lpRect));
2914 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, lpRect));
2915 return TRUE;
2920 static LRESULT
2921 REBAR_Create (REBAR_INFO *infoPtr, LPCREATESTRUCTW cs)
2923 RECT wnrc1, clrc1;
2925 if (TRACE_ON(rebar)) {
2926 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
2927 GetClientRect(infoPtr->hwndSelf, &clrc1);
2928 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
2929 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
2930 cs->x, cs->y, cs->cx, cs->cy);
2933 TRACE("created!\n");
2935 if (OpenThemeData (infoPtr->hwndSelf, themeClass))
2937 /* native seems to clear WS_BORDER when themed */
2938 infoPtr->dwStyle &= ~WS_BORDER;
2941 return 0;
2945 static LRESULT
2946 REBAR_Destroy (REBAR_INFO *infoPtr)
2948 REBAR_BAND *lpBand;
2949 UINT i;
2951 /* clean up each band */
2952 for (i = 0; i < infoPtr->uNumBands; i++) {
2953 lpBand = REBAR_GetBand(infoPtr, i);
2955 /* delete text strings */
2956 Free (lpBand->lpText);
2957 lpBand->lpText = NULL;
2958 /* destroy child window */
2959 DestroyWindow (lpBand->hwndChild);
2960 Free (lpBand);
2963 /* free band array */
2964 DPA_Destroy (infoPtr->bands);
2965 infoPtr->bands = NULL;
2967 DestroyCursor (infoPtr->hcurArrow);
2968 DestroyCursor (infoPtr->hcurHorz);
2969 DestroyCursor (infoPtr->hcurVert);
2970 DestroyCursor (infoPtr->hcurDrag);
2971 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
2972 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
2974 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2976 /* free rebar info data */
2977 Free (infoPtr);
2978 TRACE("destroyed!\n");
2979 return 0;
2982 static LRESULT
2983 REBAR_GetFont (const REBAR_INFO *infoPtr)
2985 return (LRESULT)infoPtr->hFont;
2988 static LRESULT
2989 REBAR_PushChevron(const REBAR_INFO *infoPtr, UINT uBand, LPARAM lParam)
2991 if (uBand < infoPtr->uNumBands)
2993 NMREBARCHEVRON nmrbc;
2994 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
2996 TRACE("Pressed chevron on band %u\n", uBand);
2998 /* redraw chevron in pushed state */
2999 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
3000 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
3001 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3003 /* notify app so it can display a popup menu or whatever */
3004 nmrbc.uBand = uBand;
3005 nmrbc.wID = lpBand->wID;
3006 nmrbc.lParam = lpBand->lParam;
3007 nmrbc.rc = lpBand->rcChevron;
3008 nmrbc.lParamNM = lParam;
3009 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3011 /* redraw chevron in previous state */
3012 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3013 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3015 return TRUE;
3017 return FALSE;
3020 static LRESULT
3021 REBAR_LButtonDown (REBAR_INFO *infoPtr, LPARAM lParam)
3023 UINT htFlags;
3024 INT iHitBand;
3025 POINT ptMouseDown;
3026 ptMouseDown.x = (short)LOWORD(lParam);
3027 ptMouseDown.y = (short)HIWORD(lParam);
3029 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3031 if (htFlags == RBHT_CHEVRON)
3033 REBAR_PushChevron(infoPtr, iHitBand, 0);
3035 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3037 REBAR_BAND *lpBand;
3039 TRACE("Starting drag\n");
3041 lpBand = REBAR_GetBand(infoPtr, iHitBand);
3043 SetCapture (infoPtr->hwndSelf);
3044 infoPtr->iGrabbedBand = iHitBand;
3046 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3047 infoPtr->dragStart.x = (short)LOWORD(lParam);
3048 infoPtr->dragStart.y = (short)HIWORD(lParam);
3049 infoPtr->dragNow = infoPtr->dragStart;
3050 if (infoPtr->dwStyle & CCS_VERT)
3051 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3052 else
3053 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3055 return 0;
3058 static LRESULT
3059 REBAR_LButtonUp (REBAR_INFO *infoPtr)
3061 if (infoPtr->iGrabbedBand >= 0)
3063 NMHDR layout;
3064 RECT rect;
3066 infoPtr->dragStart.x = 0;
3067 infoPtr->dragStart.y = 0;
3068 infoPtr->dragNow = infoPtr->dragStart;
3070 ReleaseCapture ();
3072 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3073 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3074 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3075 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3078 infoPtr->iGrabbedBand = -1;
3080 GetClientRect(infoPtr->hwndSelf, &rect);
3081 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3084 return 0;
3087 static LRESULT
3088 REBAR_MouseLeave (REBAR_INFO *infoPtr)
3090 if (infoPtr->ichevronhotBand >= 0)
3092 REBAR_BAND *lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3093 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3095 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3096 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3099 infoPtr->iOldBand = -1;
3100 infoPtr->ichevronhotBand = -2;
3102 return TRUE;
3105 static LRESULT
3106 REBAR_MouseMove (REBAR_INFO *infoPtr, LPARAM lParam)
3108 REBAR_BAND *lpChevronBand;
3109 POINT ptMove;
3111 ptMove.x = (short)LOWORD(lParam);
3112 ptMove.y = (short)HIWORD(lParam);
3114 /* if we are currently dragging a band */
3115 if (infoPtr->iGrabbedBand >= 0)
3117 REBAR_BAND *band;
3118 int yPtMove = (infoPtr->dwStyle & CCS_VERT ? ptMove.x : ptMove.y);
3120 if (GetCapture() != infoPtr->hwndSelf)
3121 ERR("We are dragging but haven't got capture?!?\n");
3123 band = REBAR_GetBand(infoPtr, infoPtr->iGrabbedBand);
3125 /* if mouse did not move much, exit */
3126 if ((abs(ptMove.x - infoPtr->dragNow.x) <= mindragx) &&
3127 (abs(ptMove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3129 /* on first significant mouse movement, issue notify */
3130 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
3131 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
3132 /* Notify returned TRUE - abort drag */
3133 infoPtr->dragStart.x = 0;
3134 infoPtr->dragStart.y = 0;
3135 infoPtr->dragNow = infoPtr->dragStart;
3136 infoPtr->iGrabbedBand = -1;
3137 ReleaseCapture ();
3138 return 0;
3140 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
3143 /* Test for valid drag case - must not be first band in row */
3144 if ((yPtMove < band->rcBand.top) ||
3145 (yPtMove > band->rcBand.bottom)) {
3146 REBAR_HandleUDDrag (infoPtr, &ptMove);
3148 else {
3149 REBAR_HandleLRDrag (infoPtr, &ptMove);
3152 else
3154 INT iHitBand;
3155 UINT htFlags;
3156 TRACKMOUSEEVENT trackinfo;
3158 REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
3160 if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
3162 lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3163 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3165 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3166 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3168 infoPtr->ichevronhotBand = -2;
3171 if (htFlags == RBHT_CHEVRON)
3173 /* fill in the TRACKMOUSEEVENT struct */
3174 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
3175 trackinfo.dwFlags = TME_QUERY;
3176 trackinfo.hwndTrack = infoPtr->hwndSelf;
3177 trackinfo.dwHoverTime = 0;
3179 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
3180 _TrackMouseEvent(&trackinfo);
3182 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
3183 if(!(trackinfo.dwFlags & TME_LEAVE))
3185 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
3187 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
3188 /* and can properly deactivate the hot chevron */
3189 _TrackMouseEvent(&trackinfo);
3192 lpChevronBand = REBAR_GetBand(infoPtr, iHitBand);
3193 if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
3195 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
3196 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3197 infoPtr->ichevronhotBand = iHitBand;
3200 infoPtr->iOldBand = iHitBand;
3203 return 0;
3207 static inline LRESULT
3208 REBAR_NCCalcSize (const REBAR_INFO *infoPtr, RECT *rect)
3210 HTHEME theme;
3212 if (infoPtr->dwStyle & WS_BORDER) {
3213 rect->left = min(rect->left + GetSystemMetrics(SM_CXEDGE), rect->right);
3214 rect->right = max(rect->right - GetSystemMetrics(SM_CXEDGE), rect->left);
3215 rect->top = min(rect->top + GetSystemMetrics(SM_CYEDGE), rect->bottom);
3216 rect->bottom = max(rect->bottom - GetSystemMetrics(SM_CYEDGE), rect->top);
3218 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3220 /* FIXME: should use GetThemeInt */
3221 rect->top = min(rect->top + 1, rect->bottom);
3223 TRACE("new client=(%s)\n", wine_dbgstr_rect(rect));
3224 return 0;
3228 static LRESULT
3229 REBAR_NCCreate (HWND hwnd, const CREATESTRUCTW *cs)
3231 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3232 RECT wnrc1, clrc1;
3233 NONCLIENTMETRICSW ncm;
3234 HFONT tfont;
3236 if (infoPtr) {
3237 ERR("Strange info structure pointer *not* NULL\n");
3238 return FALSE;
3241 if (TRACE_ON(rebar)) {
3242 GetWindowRect(hwnd, &wnrc1);
3243 GetClientRect(hwnd, &clrc1);
3244 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
3245 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
3246 cs->x, cs->y, cs->cx, cs->cy);
3249 /* allocate memory for info structure */
3250 infoPtr = Alloc (sizeof(REBAR_INFO));
3251 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
3253 /* initialize info structure - initial values are 0 */
3254 infoPtr->clrBk = CLR_NONE;
3255 infoPtr->clrText = CLR_NONE;
3256 infoPtr->clrBtnText = comctl32_color.clrBtnText;
3257 infoPtr->clrBtnFace = comctl32_color.clrBtnFace;
3258 infoPtr->iOldBand = -1;
3259 infoPtr->ichevronhotBand = -2;
3260 infoPtr->iGrabbedBand = -1;
3261 infoPtr->hwndSelf = hwnd;
3262 infoPtr->DoRedraw = TRUE;
3263 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3264 infoPtr->hcurHorz = LoadCursorW (0, (LPWSTR)IDC_SIZEWE);
3265 infoPtr->hcurVert = LoadCursorW (0, (LPWSTR)IDC_SIZENS);
3266 infoPtr->hcurDrag = LoadCursorW (0, (LPWSTR)IDC_SIZE);
3267 infoPtr->fStatus = 0;
3268 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3269 infoPtr->bands = DPA_Create(8);
3271 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3272 REBAR_NotifyFormat(infoPtr, NF_REQUERY);
3274 /* Stow away the original style */
3275 infoPtr->orgStyle = cs->style;
3276 /* add necessary styles to the requested styles */
3277 infoPtr->dwStyle = cs->style | WS_VISIBLE;
3278 if ((infoPtr->dwStyle & CCS_LAYOUT_MASK) == 0)
3279 infoPtr->dwStyle |= CCS_TOP;
3280 SetWindowLongW (hwnd, GWL_STYLE, infoPtr->dwStyle);
3282 /* get font handle for Caption Font */
3283 ncm.cbSize = sizeof(ncm);
3284 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
3285 /* if the font is bold, set to normal */
3286 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3287 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3289 tfont = CreateFontIndirectW (&ncm.lfCaptionFont);
3290 if (tfont) {
3291 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3294 return TRUE;
3298 static LRESULT
3299 REBAR_NCHitTest (const REBAR_INFO *infoPtr, LPARAM lParam)
3301 NMMOUSE nmmouse;
3302 POINT clpt;
3303 INT i;
3304 UINT scrap;
3305 LRESULT ret = HTCLIENT;
3308 * Differences from doc at MSDN (as observed with version 4.71 of
3309 * comctl32.dll
3310 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3311 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3312 * 3. native always seems to return HTCLIENT if notify return is 0.
3315 clpt.x = (short)LOWORD(lParam);
3316 clpt.y = (short)HIWORD(lParam);
3317 ScreenToClient (infoPtr->hwndSelf, &clpt);
3318 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3319 (INT *)&nmmouse.dwItemSpec);
3320 nmmouse.dwItemData = 0;
3321 nmmouse.pt = clpt;
3322 nmmouse.dwHitInfo = 0;
3323 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3324 TRACE("notify changed return value from %ld to %d\n",
3325 ret, i);
3326 ret = (LRESULT) i;
3328 TRACE("returning %ld, client point %s\n", ret, wine_dbgstr_point(&clpt));
3329 return ret;
3333 static LRESULT
3334 REBAR_NCPaint (const REBAR_INFO *infoPtr)
3336 RECT rcWindow;
3337 HDC hdc;
3338 HTHEME theme;
3340 if (infoPtr->dwStyle & WS_MINIMIZE)
3341 return 0; /* Nothing to do */
3343 if (infoPtr->dwStyle & WS_BORDER) {
3345 /* adjust rectangle and draw the necessary edge */
3346 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3347 return 0;
3348 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3349 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3350 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3351 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3352 ReleaseDC( infoPtr->hwndSelf, hdc );
3354 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3356 /* adjust rectangle and draw the necessary edge */
3357 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3358 return 0;
3359 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3360 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3361 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3362 DrawThemeEdge (theme, hdc, 0, 0, &rcWindow, BDR_RAISEDINNER, BF_TOP, NULL);
3363 ReleaseDC( infoPtr->hwndSelf, hdc );
3366 return 0;
3370 static LRESULT
3371 REBAR_NotifyFormat (REBAR_INFO *infoPtr, LPARAM cmd)
3373 INT i;
3375 if (cmd == NF_REQUERY) {
3376 i = SendMessageW(REBAR_GetNotifyParent (infoPtr),
3377 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
3378 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
3379 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
3380 i = NFR_ANSI;
3382 infoPtr->bUnicode = (i == NFR_UNICODE);
3383 return (LRESULT)i;
3385 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3389 static LRESULT
3390 REBAR_Paint (const REBAR_INFO *infoPtr, HDC hdc)
3392 if (hdc) {
3393 TRACE("painting\n");
3394 REBAR_Refresh (infoPtr, hdc);
3395 } else {
3396 PAINTSTRUCT ps;
3397 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
3398 TRACE("painting (%s)\n", wine_dbgstr_rect(&ps.rcPaint));
3399 if (ps.fErase) {
3400 /* Erase area of paint if requested */
3401 REBAR_EraseBkGnd (infoPtr, hdc);
3403 REBAR_Refresh (infoPtr, hdc);
3404 EndPaint (infoPtr->hwndSelf, &ps);
3407 return 0;
3411 static LRESULT
3412 REBAR_SetCursor (const REBAR_INFO *infoPtr, LPARAM lParam)
3414 POINT pt;
3415 UINT flags;
3417 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
3419 GetCursorPos (&pt);
3420 ScreenToClient (infoPtr->hwndSelf, &pt);
3422 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
3424 if (flags == RBHT_GRABBER) {
3425 if ((infoPtr->dwStyle & CCS_VERT) &&
3426 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
3427 SetCursor (infoPtr->hcurVert);
3428 else
3429 SetCursor (infoPtr->hcurHorz);
3431 else if (flags != RBHT_CLIENT)
3432 SetCursor (infoPtr->hcurArrow);
3434 return 0;
3438 static LRESULT
3439 REBAR_SetFont (REBAR_INFO *infoPtr, HFONT font)
3441 REBAR_BAND *lpBand;
3442 UINT i;
3444 infoPtr->hFont = font;
3446 /* revalidate all bands to change sizes of text in headers of bands */
3447 for (i=0; i<infoPtr->uNumBands; i++) {
3448 lpBand = REBAR_GetBand(infoPtr, i);
3449 REBAR_ValidateBand (infoPtr, lpBand);
3452 REBAR_Layout(infoPtr);
3453 return 0;
3457 /*****************************************************
3459 * Handles the WM_SETREDRAW message.
3461 * Documentation:
3462 * According to testing V4.71 of COMCTL32 returns the
3463 * *previous* status of the redraw flag (either 0 or -1)
3464 * instead of the MSDN documented value of 0 if handled
3466 *****************************************************/
3467 static inline LRESULT
3468 REBAR_SetRedraw (REBAR_INFO *infoPtr, BOOL redraw)
3470 BOOL oldredraw = infoPtr->DoRedraw;
3472 TRACE("set to %s, fStatus=%08x\n",
3473 (redraw) ? "TRUE" : "FALSE", infoPtr->fStatus);
3474 infoPtr->DoRedraw = redraw;
3475 if (redraw) {
3476 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
3477 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
3478 REBAR_ForceResize (infoPtr);
3479 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3481 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
3483 return (oldredraw) ? -1 : 0;
3487 static LRESULT
3488 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3490 TRACE("wParam=%lx, lParam=%lx\n", wParam, lParam);
3492 /* avoid _Layout resize recursion (but it shouldn't be infinite and it seems Windows does recurse) */
3493 if (infoPtr->fStatus & SELF_RESIZE) {
3494 infoPtr->fStatus &= ~SELF_RESIZE;
3495 TRACE("SELF_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
3496 infoPtr->fStatus, lParam);
3497 return 0;
3500 if (infoPtr->dwStyle & RBS_AUTOSIZE)
3501 REBAR_AutoSize(infoPtr, TRUE);
3502 else
3503 REBAR_Layout(infoPtr);
3505 return 0;
3509 static LRESULT
3510 REBAR_StyleChanged (REBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
3512 TRACE("current style=%08x, styleOld=%08x, style being set to=%08x\n",
3513 infoPtr->dwStyle, lpStyle->styleOld, lpStyle->styleNew);
3514 if (nType == GWL_STYLE)
3516 infoPtr->orgStyle = infoPtr->dwStyle = lpStyle->styleNew;
3517 if (GetWindowTheme (infoPtr->hwndSelf))
3518 infoPtr->dwStyle &= ~WS_BORDER;
3519 /* maybe it should be COMMON_STYLES like in toolbar */
3520 if ((lpStyle->styleNew ^ lpStyle->styleOld) & CCS_VERT)
3521 REBAR_Layout(infoPtr);
3523 return FALSE;
3526 /* update theme after a WM_THEMECHANGED message */
3527 static LRESULT theme_changed (REBAR_INFO* infoPtr)
3529 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
3530 CloseThemeData (theme);
3531 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
3532 /* WS_BORDER disappears when theming is enabled and reappears when
3533 * disabled... */
3534 infoPtr->dwStyle &= ~WS_BORDER;
3535 infoPtr->dwStyle |= theme ? 0 : (infoPtr->orgStyle & WS_BORDER);
3536 return 0;
3539 static LRESULT
3540 REBAR_WindowPosChanged (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3542 LRESULT ret;
3543 RECT rc;
3545 ret = DefWindowProcW(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
3546 wParam, lParam);
3547 GetWindowRect(infoPtr->hwndSelf, &rc);
3548 TRACE("hwnd %p new pos (%s)\n", infoPtr->hwndSelf, wine_dbgstr_rect(&rc));
3549 return ret;
3553 static LRESULT WINAPI
3554 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3556 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3558 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
3559 hwnd, uMsg, wParam, lParam);
3560 if (!infoPtr && (uMsg != WM_NCCREATE))
3561 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3562 switch (uMsg)
3564 /* case RB_BEGINDRAG: */
3566 case RB_DELETEBAND:
3567 return REBAR_DeleteBand (infoPtr, wParam);
3569 /* case RB_DRAGMOVE: */
3570 /* case RB_ENDDRAG: */
3572 case RB_GETBANDBORDERS:
3573 return REBAR_GetBandBorders (infoPtr, wParam, (LPRECT)lParam);
3575 case RB_GETBANDCOUNT:
3576 return REBAR_GetBandCount (infoPtr);
3578 case RB_GETBANDINFO_OLD:
3579 case RB_GETBANDINFOA:
3580 case RB_GETBANDINFOW:
3581 return REBAR_GetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3582 uMsg == RB_GETBANDINFOW);
3583 case RB_GETBARHEIGHT:
3584 return REBAR_GetBarHeight (infoPtr);
3586 case RB_GETBARINFO:
3587 return REBAR_GetBarInfo (infoPtr, (LPREBARINFO)lParam);
3589 case RB_GETBKCOLOR:
3590 return REBAR_GetBkColor (infoPtr);
3592 /* case RB_GETCOLORSCHEME: */
3593 /* case RB_GETDROPTARGET: */
3595 case RB_GETPALETTE:
3596 return REBAR_GetPalette (infoPtr);
3598 case RB_GETRECT:
3599 return REBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
3601 case RB_GETROWCOUNT:
3602 return REBAR_GetRowCount (infoPtr);
3604 case RB_GETROWHEIGHT:
3605 return REBAR_GetRowHeight (infoPtr, wParam);
3607 case RB_GETTEXTCOLOR:
3608 return REBAR_GetTextColor (infoPtr);
3610 case RB_GETTOOLTIPS:
3611 return REBAR_GetToolTips (infoPtr);
3613 case RB_GETUNICODEFORMAT:
3614 return REBAR_GetUnicodeFormat (infoPtr);
3616 case CCM_GETVERSION:
3617 return REBAR_GetVersion (infoPtr);
3619 case RB_HITTEST:
3620 return REBAR_HitTest (infoPtr, (LPRBHITTESTINFO)lParam);
3622 case RB_IDTOINDEX:
3623 return REBAR_IdToIndex (infoPtr, wParam);
3625 case RB_INSERTBANDA:
3626 case RB_INSERTBANDW:
3627 return REBAR_InsertBandT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3628 uMsg == RB_INSERTBANDW);
3629 case RB_MAXIMIZEBAND:
3630 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
3632 case RB_MINIMIZEBAND:
3633 return REBAR_MinimizeBand (infoPtr, wParam);
3635 case RB_MOVEBAND:
3636 return REBAR_MoveBand (infoPtr, wParam, lParam);
3638 case RB_PUSHCHEVRON:
3639 return REBAR_PushChevron (infoPtr, wParam, lParam);
3641 case RB_SETBANDINFOA:
3642 case RB_SETBANDINFOW:
3643 return REBAR_SetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3644 uMsg == RB_SETBANDINFOW);
3645 case RB_SETBARINFO:
3646 return REBAR_SetBarInfo (infoPtr, (LPREBARINFO)lParam);
3648 case RB_SETBKCOLOR:
3649 return REBAR_SetBkColor (infoPtr, lParam);
3651 /* case RB_SETCOLORSCHEME: */
3652 /* case RB_SETPALETTE: */
3654 case RB_SETPARENT:
3655 return REBAR_SetParent (infoPtr, (HWND)wParam);
3657 case RB_SETTEXTCOLOR:
3658 return REBAR_SetTextColor (infoPtr, lParam);
3660 /* case RB_SETTOOLTIPS: */
3662 case RB_SETUNICODEFORMAT:
3663 return REBAR_SetUnicodeFormat (infoPtr, wParam);
3665 case CCM_SETVERSION:
3666 return REBAR_SetVersion (infoPtr, (INT)wParam);
3668 case RB_SHOWBAND:
3669 return REBAR_ShowBand (infoPtr, wParam, lParam);
3671 case RB_SIZETORECT:
3672 return REBAR_SizeToRect (infoPtr, (LPCRECT)lParam);
3675 /* Messages passed to parent */
3676 case WM_COMMAND:
3677 case WM_DRAWITEM:
3678 case WM_NOTIFY:
3679 case WM_MEASUREITEM:
3680 return SendMessageW(REBAR_GetNotifyParent (infoPtr), uMsg, wParam, lParam);
3683 /* case WM_CHARTOITEM: supported according to ControlSpy */
3685 case WM_CREATE:
3686 return REBAR_Create (infoPtr, (LPCREATESTRUCTW)lParam);
3688 case WM_DESTROY:
3689 return REBAR_Destroy (infoPtr);
3691 case WM_ERASEBKGND:
3692 return REBAR_EraseBkGnd (infoPtr, (HDC)wParam);
3694 case WM_GETFONT:
3695 return REBAR_GetFont (infoPtr);
3697 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
3699 case WM_LBUTTONDOWN:
3700 return REBAR_LButtonDown (infoPtr, lParam);
3702 case WM_LBUTTONUP:
3703 return REBAR_LButtonUp (infoPtr);
3705 case WM_MOUSEMOVE:
3706 return REBAR_MouseMove (infoPtr, lParam);
3708 case WM_MOUSELEAVE:
3709 return REBAR_MouseLeave (infoPtr);
3711 case WM_NCCALCSIZE:
3712 return REBAR_NCCalcSize (infoPtr, (RECT*)lParam);
3714 case WM_NCCREATE:
3715 return REBAR_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
3717 case WM_NCHITTEST:
3718 return REBAR_NCHitTest (infoPtr, lParam);
3720 case WM_NCPAINT:
3721 return REBAR_NCPaint (infoPtr);
3723 case WM_NOTIFYFORMAT:
3724 return REBAR_NotifyFormat (infoPtr, lParam);
3726 case WM_PRINTCLIENT:
3727 case WM_PAINT:
3728 return REBAR_Paint (infoPtr, (HDC)wParam);
3730 /* case WM_PALETTECHANGED: supported according to ControlSpy */
3731 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
3732 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
3733 /* case WM_RBUTTONUP: supported according to ControlSpy */
3735 case WM_SETCURSOR:
3736 return REBAR_SetCursor (infoPtr, lParam);
3738 case WM_SETFONT:
3739 return REBAR_SetFont (infoPtr, (HFONT)wParam);
3741 case WM_SETREDRAW:
3742 return REBAR_SetRedraw (infoPtr, wParam);
3744 case WM_SIZE:
3745 return REBAR_Size (infoPtr, wParam, lParam);
3747 case WM_STYLECHANGED:
3748 return REBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
3750 case WM_THEMECHANGED:
3751 return theme_changed (infoPtr);
3753 case WM_SYSCOLORCHANGE:
3754 COMCTL32_RefreshSysColors();
3755 return 0;
3757 /* case WM_VKEYTOITEM: supported according to ControlSpy */
3758 /* case WM_WININICHANGE: */
3760 case WM_WINDOWPOSCHANGED:
3761 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
3763 default:
3764 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
3765 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
3766 uMsg, wParam, lParam);
3767 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3772 VOID
3773 REBAR_Register (void)
3775 WNDCLASSW wndClass;
3777 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
3778 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
3779 wndClass.lpfnWndProc = REBAR_WindowProc;
3780 wndClass.cbClsExtra = 0;
3781 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
3782 wndClass.hCursor = 0;
3783 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
3784 #if GLATESTING
3785 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
3786 #endif
3787 wndClass.lpszClassName = REBARCLASSNAMEW;
3789 RegisterClassW (&wndClass);
3791 mindragx = GetSystemMetrics (SM_CXDRAG);
3792 mindragy = GetSystemMetrics (SM_CYDRAG);
3797 VOID
3798 REBAR_Unregister (void)
3800 UnregisterClassW (REBARCLASSNAMEW, NULL);