oledb32: Implement DataConvert DBTYPE_R4->DBTYPE_VARIANT.
[wine/multimedia.git] / dlls / comctl32 / rebar.c
blob461dc3460f96a1f6635d0ee04918d3ee5e98f45e
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 "wine/unicode.h"
89 #include "winuser.h"
90 #include "winnls.h"
91 #include "commctrl.h"
92 #include "comctl32.h"
93 #include "uxtheme.h"
94 #include "vssym32.h"
95 #include "wine/debug.h"
97 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
99 typedef struct
101 UINT fStyle;
102 UINT fMask;
103 COLORREF clrFore;
104 COLORREF clrBack;
105 INT iImage;
106 HWND hwndChild;
107 UINT cxMinChild; /* valid if _CHILDSIZE */
108 UINT cyMinChild; /* valid if _CHILDSIZE */
109 UINT cx; /* valid if _SIZE */
110 HBITMAP hbmBack;
111 UINT wID;
112 UINT cyChild; /* valid if _CHILDSIZE */
113 UINT cyMaxChild; /* valid if _CHILDSIZE */
114 UINT cyIntegral; /* valid if _CHILDSIZE */
115 UINT cxIdeal;
116 LPARAM lParam;
117 UINT cxHeader;
119 INT cxEffective; /* current cx for band */
120 UINT cyHeader; /* the height of the header */
121 UINT cxMinBand; /* minimum cx for band */
122 UINT cyMinBand; /* minimum cy for band */
124 UINT cyRowSoFar; /* for RBS_VARHEIGHT - the height of the row if it would break on this band (set by _Layout) */
125 INT iRow; /* zero-based index of the row this band assigned to */
126 UINT fStatus; /* status flags, reset only by _Validate */
127 UINT fDraw; /* drawing flags, reset only by _Layout */
128 UINT uCDret; /* last return from NM_CUSTOMDRAW */
129 RECT rcBand; /* calculated band rectangle - coordinates swapped for CCS_VERT */
130 RECT rcGripper; /* calculated gripper rectangle */
131 RECT rcCapImage; /* calculated caption image rectangle */
132 RECT rcCapText; /* calculated caption text rectangle */
133 RECT rcChild; /* calculated child rectangle */
134 RECT rcChevron; /* calculated chevron rectangle */
136 LPWSTR lpText;
137 HWND hwndPrevParent;
138 } REBAR_BAND;
140 /* has a value of: 0, CCS_TOP, CCS_NOMOVEY, CCS_BOTTOM */
141 #define CCS_LAYOUT_MASK 0x3
143 /* fStatus flags */
144 #define HAS_GRIPPER 0x00000001
145 #define HAS_IMAGE 0x00000002
146 #define HAS_TEXT 0x00000004
148 /* fDraw flags */
149 #define DRAW_GRIPPER 0x00000001
150 #define DRAW_IMAGE 0x00000002
151 #define DRAW_TEXT 0x00000004
152 #define DRAW_CHEVRONHOT 0x00000040
153 #define DRAW_CHEVRONPUSHED 0x00000080
154 #define NTF_INVALIDATE 0x01000000
156 typedef struct
158 COLORREF clrBk; /* background color */
159 COLORREF clrText; /* text color */
160 COLORREF clrBtnText; /* system color for BTNTEXT */
161 COLORREF clrBtnFace; /* system color for BTNFACE */
162 HIMAGELIST himl; /* handle to imagelist */
163 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
164 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
165 HWND hwndSelf; /* handle of REBAR window itself */
166 HWND hwndToolTip; /* handle to the tool tip control */
167 HWND hwndNotify; /* notification window (parent) */
168 HFONT hDefaultFont;
169 HFONT hFont; /* handle to the rebar's font */
170 SIZE imageSize; /* image size (image list) */
171 DWORD dwStyle; /* window style */
172 DWORD orgStyle; /* original style (dwStyle may change) */
173 SIZE calcSize; /* calculated rebar size - coordinates swapped for CCS_VERT */
174 BOOL bUnicode; /* TRUE if parent wants notify in W format */
175 BOOL DoRedraw; /* TRUE to actually draw bands */
176 UINT fStatus; /* Status flags (see below) */
177 HCURSOR hcurArrow; /* handle to the arrow cursor */
178 HCURSOR hcurHorz; /* handle to the EW cursor */
179 HCURSOR hcurVert; /* handle to the NS cursor */
180 HCURSOR hcurDrag; /* handle to the drag cursor */
181 INT iVersion; /* version number */
182 POINT dragStart; /* x,y of button down */
183 POINT dragNow; /* x,y of this MouseMove */
184 INT iOldBand; /* last band that had the mouse cursor over it */
185 INT ihitoffset; /* offset of hotspot from gripper.left */
186 INT ichevronhotBand; /* last band that had a hot chevron */
187 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
189 HDPA bands; /* pointer to the array of rebar bands */
190 } REBAR_INFO;
192 /* fStatus flags */
193 #define BEGIN_DRAG_ISSUED 0x00000001
194 #define SELF_RESIZE 0x00000002
195 #define BAND_NEEDS_REDRAW 0x00000020
197 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
198 #define RBBS_UNDOC_FIXEDHEADER 0x40000000
200 /* ---- REBAR layout constants. Mostly determined by ---- */
201 /* ---- experiment on WIN 98. ---- */
203 /* Width (or height) of separators between bands (either horz. or */
204 /* vert.). True only if RBS_BANDBORDERS is set */
205 #define SEP_WIDTH_SIZE 2
206 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
208 /* Blank (background color) space between Gripper (if present) */
209 /* and next item (image, text, or window). Always present */
210 #define REBAR_ALWAYS_SPACE 4
212 /* Blank (background color) space after Image (if present). */
213 #define REBAR_POST_IMAGE 2
215 /* Blank (background color) space after Text (if present). */
216 #define REBAR_POST_TEXT 4
218 /* Height of vertical gripper in a CCS_VERT rebar. */
219 #define GRIPPER_HEIGHT 16
221 /* Blank (background color) space before Gripper (if present). */
222 #define REBAR_PRE_GRIPPER 2
224 /* Width (of normal vertical gripper) or height (of horz. gripper) */
225 /* if present. */
226 #define GRIPPER_WIDTH 3
228 /* Width of the chevron button if present */
229 #define CHEVRON_WIDTH 10
231 /* the gap between the child and the next band */
232 #define REBAR_POST_CHILD 4
234 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
235 /* either top or bottom */
236 #define REBAR_DIVIDER 2
238 /* height of a rebar without a child */
239 #define REBAR_NO_CHILD_HEIGHT 4
241 /* minimum vertical height of a normal bar */
242 /* or minimum width of a CCS_VERT bar - from experiment on Win2k */
243 #define REBAR_MINSIZE 23
245 /* This is the increment that is used over the band height */
246 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
248 /* ---- End of REBAR layout constants. ---- */
250 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
252 /* The following define determines if a given band is hidden */
253 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
254 ((infoPtr->dwStyle & CCS_VERT) && \
255 ((a)->fStyle & RBBS_NOVERT)))
257 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
259 static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, LPARAM lParam);
260 static void REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout);
262 /* no index check here */
263 static inline REBAR_BAND* REBAR_GetBand(const REBAR_INFO *infoPtr, INT i)
265 assert(i >= 0 && i < infoPtr->uNumBands);
266 return DPA_GetPtr(infoPtr->bands, i);
269 /* "constant values" retrieved when DLL was initialized */
270 /* FIXME we do this when the classes are registered. */
271 static UINT mindragx = 0;
272 static UINT mindragy = 0;
274 static const char * const band_stylename[] = {
275 "RBBS_BREAK", /* 0001 */
276 "RBBS_FIXEDSIZE", /* 0002 */
277 "RBBS_CHILDEDGE", /* 0004 */
278 "RBBS_HIDDEN", /* 0008 */
279 "RBBS_NOVERT", /* 0010 */
280 "RBBS_FIXEDBMP", /* 0020 */
281 "RBBS_VARIABLEHEIGHT", /* 0040 */
282 "RBBS_GRIPPERALWAYS", /* 0080 */
283 "RBBS_NOGRIPPER", /* 0100 */
284 NULL };
286 static const char * const band_maskname[] = {
287 "RBBIM_STYLE", /* 0x00000001 */
288 "RBBIM_COLORS", /* 0x00000002 */
289 "RBBIM_TEXT", /* 0x00000004 */
290 "RBBIM_IMAGE", /* 0x00000008 */
291 "RBBIM_CHILD", /* 0x00000010 */
292 "RBBIM_CHILDSIZE", /* 0x00000020 */
293 "RBBIM_SIZE", /* 0x00000040 */
294 "RBBIM_BACKGROUND", /* 0x00000080 */
295 "RBBIM_ID", /* 0x00000100 */
296 "RBBIM_IDEALSIZE", /* 0x00000200 */
297 "RBBIM_LPARAM", /* 0x00000400 */
298 "RBBIM_HEADERSIZE", /* 0x00000800 */
299 NULL };
302 static CHAR line[200];
304 static const WCHAR themeClass[] = { 'R','e','b','a','r',0 };
306 static CHAR *
307 REBAR_FmtStyle( UINT style)
309 INT i = 0;
311 *line = 0;
312 while (band_stylename[i]) {
313 if (style & (1<<i)) {
314 if (*line != 0) strcat(line, " | ");
315 strcat(line, band_stylename[i]);
317 i++;
319 return line;
323 static CHAR *
324 REBAR_FmtMask( UINT mask)
326 INT i = 0;
328 *line = 0;
329 while (band_maskname[i]) {
330 if (mask & (1<<i)) {
331 if (*line != 0) strcat(line, " | ");
332 strcat(line, band_maskname[i]);
334 i++;
336 return line;
340 static VOID
341 REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
343 if( !TRACE_ON(rebar) ) return;
344 TRACE("band info: ");
345 if (pB->fMask & RBBIM_ID)
346 TRACE("ID=%u, ", pB->wID);
347 TRACE("size=%u, child=%p", pB->cbSize, pB->hwndChild);
348 if (pB->fMask & RBBIM_COLORS)
349 TRACE(", clrF=0x%06x, clrB=0x%06x", pB->clrFore, pB->clrBack);
350 TRACE("\n");
352 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
353 if (pB->fMask & RBBIM_STYLE)
354 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
355 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
356 TRACE("band info:");
357 if (pB->fMask & RBBIM_SIZE)
358 TRACE(" cx=%u", pB->cx);
359 if (pB->fMask & RBBIM_IDEALSIZE)
360 TRACE(" xIdeal=%u", pB->cxIdeal);
361 if (pB->fMask & RBBIM_HEADERSIZE)
362 TRACE(" xHeader=%u", pB->cxHeader);
363 if (pB->fMask & RBBIM_LPARAM)
364 TRACE(" lParam=0x%08lx", pB->lParam);
365 TRACE("\n");
367 if (pB->fMask & RBBIM_CHILDSIZE)
368 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
369 pB->cxMinChild,
370 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
373 static VOID
374 REBAR_DumpBand (const REBAR_INFO *iP)
376 REBAR_BAND *pB;
377 UINT i;
379 if(! TRACE_ON(rebar) ) return;
381 TRACE("hwnd=%p: color=%08x/%08x, bands=%u, rows=%u, cSize=%d,%d\n",
382 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
383 iP->calcSize.cx, iP->calcSize.cy);
384 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
385 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
386 iP->dragNow.x, iP->dragNow.y,
387 iP->iGrabbedBand);
388 TRACE("hwnd=%p: style=%08x, notify in Unicode=%s, redraw=%s\n",
389 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
390 (iP->DoRedraw)?"TRUE":"FALSE");
391 for (i = 0; i < iP->uNumBands; i++) {
392 pB = REBAR_GetBand(iP, i);
393 TRACE("band # %u:", i);
394 if (pB->fMask & RBBIM_ID)
395 TRACE(" ID=%u", pB->wID);
396 if (pB->fMask & RBBIM_CHILD)
397 TRACE(" child=%p", pB->hwndChild);
398 if (pB->fMask & RBBIM_COLORS)
399 TRACE(" clrF=0x%06x clrB=0x%06x", pB->clrFore, pB->clrBack);
400 TRACE("\n");
401 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
402 if (pB->fMask & RBBIM_STYLE)
403 TRACE("band # %u: style=0x%08x (%s)\n",
404 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
405 TRACE("band # %u: xHeader=%u",
406 i, pB->cxHeader);
407 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
408 if (pB->fMask & RBBIM_SIZE)
409 TRACE(" cx=%u", pB->cx);
410 if (pB->fMask & RBBIM_IDEALSIZE)
411 TRACE(" xIdeal=%u", pB->cxIdeal);
412 if (pB->fMask & RBBIM_LPARAM)
413 TRACE(" lParam=0x%08lx", pB->lParam);
415 TRACE("\n");
416 if (RBBIM_CHILDSIZE)
417 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
418 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
419 if (pB->fMask & RBBIM_TEXT)
420 TRACE("band # %u: text=%s\n",
421 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
422 TRACE("band # %u: cxMinBand=%u, cxEffective=%u, cyMinBand=%u\n",
423 i, pB->cxMinBand, pB->cxEffective, pB->cyMinBand);
424 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
425 i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
426 wine_dbgstr_rect(&pB->rcGripper));
427 TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
428 i, wine_dbgstr_rect(&pB->rcCapImage),
429 wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
434 /* dest can be equal to src */
435 static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
437 if (infoPtr->dwStyle & CCS_VERT) {
438 int tmp;
439 tmp = src->left;
440 dest->left = src->top;
441 dest->top = tmp;
443 tmp = src->right;
444 dest->right = src->bottom;
445 dest->bottom = tmp;
446 } else {
447 *dest = *src;
451 static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
453 if (infoPtr->dwStyle & CCS_VERT)
454 return lpRect->bottom - lpRect->top;
455 return lpRect->right - lpRect->left;
458 static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
460 if (infoPtr->dwStyle & CCS_VERT)
461 return lpRect->right - lpRect->left;
462 return lpRect->bottom - lpRect->top;
465 static int round_child_height(const REBAR_BAND *lpBand, int cyHeight)
467 int cy = 0;
468 if (lpBand->cyIntegral == 0)
469 return cyHeight;
470 cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
471 cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
472 cy = min(cy, lpBand->cyMaxChild);
473 return cy;
476 static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
478 lpBand->cyMinBand = max(lpBand->cyHeader,
479 (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
482 static void
483 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
485 INT x, y;
486 HPEN hPen, hOldPen;
488 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
489 hOldPen = SelectObject ( hdc, hPen );
490 x = left + 2;
491 y = top;
492 MoveToEx (hdc, x, y, NULL);
493 LineTo (hdc, x+5, y++); x++;
494 MoveToEx (hdc, x, y, NULL);
495 LineTo (hdc, x+3, y++); x++;
496 MoveToEx (hdc, x, y, NULL);
497 LineTo (hdc, x+1, y);
498 SelectObject( hdc, hOldPen );
499 DeleteObject( hPen );
502 static HWND
503 REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
505 HWND parent, owner;
507 parent = infoPtr->hwndNotify;
508 if (!parent) {
509 parent = GetParent (infoPtr->hwndSelf);
510 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
511 if (owner) parent = owner;
513 return parent;
517 static INT
518 REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
520 HWND parent;
522 parent = REBAR_GetNotifyParent (infoPtr);
523 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
524 nmhdr->hwndFrom = infoPtr->hwndSelf;
525 nmhdr->code = code;
527 TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
529 return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
532 static INT
533 REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
535 NMREBAR notify_rebar;
537 notify_rebar.dwMask = 0;
538 if (uBand != -1) {
539 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
541 if (lpBand->fMask & RBBIM_ID) {
542 notify_rebar.dwMask |= RBNM_ID;
543 notify_rebar.wID = lpBand->wID;
545 if (lpBand->fMask & RBBIM_LPARAM) {
546 notify_rebar.dwMask |= RBNM_LPARAM;
547 notify_rebar.lParam = lpBand->lParam;
549 if (lpBand->fMask & RBBIM_STYLE) {
550 notify_rebar.dwMask |= RBNM_STYLE;
551 notify_rebar.fStyle = lpBand->fStyle;
554 notify_rebar.uBand = uBand;
555 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
558 static VOID
559 REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
561 HFONT hOldFont = 0;
562 INT oldBkMode = 0;
563 NMCUSTOMDRAW nmcd;
564 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
565 RECT rcBand;
567 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
569 if (lpBand->fDraw & DRAW_TEXT) {
570 hOldFont = SelectObject (hdc, infoPtr->hFont);
571 oldBkMode = SetBkMode (hdc, TRANSPARENT);
574 /* should test for CDRF_NOTIFYITEMDRAW here */
575 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
576 nmcd.hdc = hdc;
577 nmcd.rc = rcBand;
578 nmcd.rc.right = lpBand->rcCapText.right;
579 nmcd.rc.bottom = lpBand->rcCapText.bottom;
580 nmcd.dwItemSpec = lpBand->wID;
581 nmcd.uItemState = 0;
582 nmcd.lItemlParam = lpBand->lParam;
583 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
584 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
585 if (oldBkMode != TRANSPARENT)
586 SetBkMode (hdc, oldBkMode);
587 SelectObject (hdc, hOldFont);
588 return;
591 /* draw gripper */
592 if (lpBand->fDraw & DRAW_GRIPPER)
594 if (theme)
596 RECT rcGripper = lpBand->rcGripper;
597 int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
598 GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
599 OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
600 lpBand->rcGripper.top - rcGripper.top);
601 DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
603 else
604 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
607 /* draw caption image */
608 if (lpBand->fDraw & DRAW_IMAGE) {
609 POINT pt;
611 /* center image */
612 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
613 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
615 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
616 pt.x, pt.y,
617 ILD_TRANSPARENT);
620 /* draw caption text */
621 if (lpBand->fDraw & DRAW_TEXT) {
622 /* need to handle CDRF_NEWFONT here */
623 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
624 COLORREF oldcolor = CLR_NONE;
625 COLORREF new;
626 if (lpBand->clrFore != CLR_NONE) {
627 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
628 lpBand->clrFore;
629 oldcolor = SetTextColor (hdc, new);
631 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
632 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
633 if (oldBkMode != TRANSPARENT)
634 SetBkMode (hdc, oldBkMode);
635 if (lpBand->clrFore != CLR_NONE)
636 SetTextColor (hdc, oldcolor);
637 SelectObject (hdc, hOldFont);
640 if (!IsRectEmpty(&lpBand->rcChevron))
642 if (theme)
644 int stateId;
645 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
646 stateId = CHEVS_PRESSED;
647 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
648 stateId = CHEVS_HOT;
649 else
650 stateId = CHEVS_NORMAL;
651 DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
653 else
655 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
657 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
658 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
660 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
662 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
663 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
665 else
666 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
670 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
671 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
672 nmcd.hdc = hdc;
673 nmcd.rc = rcBand;
674 nmcd.rc.right = lpBand->rcCapText.right;
675 nmcd.rc.bottom = lpBand->rcCapText.bottom;
676 nmcd.dwItemSpec = lpBand->wID;
677 nmcd.uItemState = 0;
678 nmcd.lItemlParam = lpBand->lParam;
679 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
684 static VOID
685 REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
687 REBAR_BAND *lpBand;
688 UINT i;
690 if (!infoPtr->DoRedraw) return;
692 for (i = 0; i < infoPtr->uNumBands; i++) {
693 lpBand = REBAR_GetBand(infoPtr, i);
695 if (HIDDENBAND(lpBand)) continue;
697 /* now draw the band */
698 TRACE("[%p] drawing band %i, flags=%08x\n",
699 infoPtr->hwndSelf, i, lpBand->fDraw);
700 REBAR_DrawBand (hdc, infoPtr, lpBand);
705 static void
706 REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
707 /* Function: this routine initializes all the rectangles in */
708 /* each band in a row to fit in the adjusted rcBand rect. */
709 /* *** Supports only Horizontal bars. *** */
711 REBAR_BAND *lpBand;
712 UINT i, xoff;
713 RECT work;
715 for(i=rstart; i<rend; i++){
716 lpBand = REBAR_GetBand(infoPtr, i);
717 if (HIDDENBAND(lpBand)) {
718 SetRect (&lpBand->rcChild,
719 lpBand->rcBand.right, lpBand->rcBand.top,
720 lpBand->rcBand.right, lpBand->rcBand.bottom);
721 continue;
724 /* set initial gripper rectangle */
725 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
726 lpBand->rcBand.left, lpBand->rcBand.bottom);
728 /* calculate gripper rectangle */
729 if ( lpBand->fStatus & HAS_GRIPPER) {
730 lpBand->fDraw |= DRAW_GRIPPER;
731 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
732 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
733 lpBand->rcGripper.top += 2;
734 lpBand->rcGripper.bottom -= 2;
736 SetRect (&lpBand->rcCapImage,
737 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
738 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
740 else { /* no gripper will be drawn */
741 xoff = 0;
742 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
743 /* if no gripper but either image or text, then leave space */
744 xoff = REBAR_ALWAYS_SPACE;
745 SetRect (&lpBand->rcCapImage,
746 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
747 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
750 /* image is visible */
751 if (lpBand->fStatus & HAS_IMAGE) {
752 lpBand->fDraw |= DRAW_IMAGE;
753 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
754 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
756 /* set initial caption text rectangle */
757 SetRect (&lpBand->rcCapText,
758 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
759 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
761 else {
762 /* set initial caption text rectangle */
763 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
764 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
767 /* text is visible */
768 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
769 lpBand->fDraw |= DRAW_TEXT;
770 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
771 lpBand->rcCapText.right-REBAR_POST_TEXT);
774 /* set initial child window rectangle if there is a child */
775 if (lpBand->hwndChild) {
777 lpBand->rcChild.left = lpBand->rcBand.left + lpBand->cxHeader;
778 lpBand->rcChild.right = lpBand->rcBand.right - REBAR_POST_CHILD;
780 if (lpBand->cyChild > 0) {
782 UINT yoff = (lpBand->rcBand.bottom - lpBand->rcBand.top - lpBand->cyChild) / 2;
784 /* center child if height is known */
785 lpBand->rcChild.top = lpBand->rcBand.top + yoff;
786 lpBand->rcChild.bottom = lpBand->rcBand.top + yoff + lpBand->cyChild;
788 else {
789 lpBand->rcChild.top = lpBand->rcBand.top;
790 lpBand->rcChild.bottom = lpBand->rcBand.bottom;
793 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
795 lpBand->rcChild.right -= CHEVRON_WIDTH;
796 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
797 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
798 lpBand->rcChild.bottom);
801 else {
802 SetRect (&lpBand->rcChild,
803 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
804 lpBand->rcBand.right, lpBand->rcBand.bottom);
807 /* flag if notify required and invalidate rectangle */
808 if (lpBand->fDraw & NTF_INVALIDATE) {
809 TRACE("invalidating (%d,%d)-(%d,%d)\n",
810 lpBand->rcBand.left,
811 lpBand->rcBand.top,
812 lpBand->rcBand.right + SEP_WIDTH,
813 lpBand->rcBand.bottom + SEP_WIDTH);
814 lpBand->fDraw &= ~NTF_INVALIDATE;
815 work = lpBand->rcBand;
816 work.right += SEP_WIDTH;
817 work.bottom += SEP_WIDTH;
818 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
819 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
827 static VOID
828 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
829 /* Function: this routine initializes all the rectangles in */
830 /* each band in a row to fit in the adjusted rcBand rect. */
831 /* *** Supports only Vertical bars. *** */
833 REBAR_BAND *lpBand;
834 UINT i, xoff;
835 RECT work;
837 for(i=rstart; i<rend; i++){
838 RECT rcBand;
839 lpBand = REBAR_GetBand(infoPtr, i);
840 if (HIDDENBAND(lpBand)) continue;
842 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
844 /* set initial gripper rectangle */
845 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
847 /* calculate gripper rectangle */
848 if (lpBand->fStatus & HAS_GRIPPER) {
849 lpBand->fDraw |= DRAW_GRIPPER;
851 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
852 /* vertical gripper */
853 lpBand->rcGripper.left += 3;
854 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
855 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
856 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
858 /* initialize Caption image rectangle */
859 SetRect (&lpBand->rcCapImage, rcBand.left,
860 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
861 rcBand.right,
862 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
864 else {
865 /* horizontal gripper */
866 lpBand->rcGripper.left += 2;
867 lpBand->rcGripper.right -= 2;
868 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
869 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
871 /* initialize Caption image rectangle */
872 SetRect (&lpBand->rcCapImage, rcBand.left,
873 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
874 rcBand.right,
875 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
878 else { /* no gripper will be drawn */
879 xoff = 0;
880 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
881 /* if no gripper but either image or text, then leave space */
882 xoff = REBAR_ALWAYS_SPACE;
883 /* initialize Caption image rectangle */
884 SetRect (&lpBand->rcCapImage,
885 rcBand.left, rcBand.top+xoff,
886 rcBand.right, rcBand.top+xoff);
889 /* image is visible */
890 if (lpBand->fStatus & HAS_IMAGE) {
891 lpBand->fDraw |= DRAW_IMAGE;
893 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
894 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
896 /* set initial caption text rectangle */
897 SetRect (&lpBand->rcCapText,
898 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
899 rcBand.right, rcBand.top+lpBand->cxHeader);
901 else {
902 /* set initial caption text rectangle */
903 SetRect (&lpBand->rcCapText,
904 rcBand.left, lpBand->rcCapImage.bottom,
905 rcBand.right, rcBand.top+lpBand->cxHeader);
908 /* text is visible */
909 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
910 lpBand->fDraw |= DRAW_TEXT;
911 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
912 lpBand->rcCapText.bottom);
915 /* set initial child window rectangle if there is a child */
916 if (lpBand->hwndChild) {
917 int cxBand = rcBand.right - rcBand.left;
918 xoff = (cxBand - lpBand->cyChild) / 2;
919 SetRect (&lpBand->rcChild,
920 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
921 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
923 else {
924 SetRect (&lpBand->rcChild,
925 rcBand.left, rcBand.top+lpBand->cxHeader,
926 rcBand.right, rcBand.bottom);
929 if (lpBand->fDraw & NTF_INVALIDATE) {
930 TRACE("invalidating (%d,%d)-(%d,%d)\n",
931 rcBand.left,
932 rcBand.top,
933 rcBand.right + SEP_WIDTH,
934 rcBand.bottom + SEP_WIDTH);
935 lpBand->fDraw &= ~NTF_INVALIDATE;
936 work = rcBand;
937 work.bottom += SEP_WIDTH;
938 work.right += SEP_WIDTH;
939 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
940 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
947 static VOID
948 REBAR_ForceResize (REBAR_INFO *infoPtr)
949 /* Function: This changes the size of the REBAR window to that */
950 /* calculated by REBAR_Layout. */
952 INT x, y, width, height;
953 INT xedge = 0, yedge = 0;
954 RECT rcSelf;
956 TRACE("new size [%d x %d]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
958 if (infoPtr->dwStyle & CCS_NORESIZE)
959 return;
961 if (infoPtr->dwStyle & WS_BORDER)
963 xedge = GetSystemMetrics(SM_CXEDGE);
964 yedge = GetSystemMetrics(SM_CYEDGE);
965 /* swap for CCS_VERT? */
968 /* compute rebar window rect in parent client coordinates */
969 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
970 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
971 translate_rect(infoPtr, &rcSelf, &rcSelf);
973 height = infoPtr->calcSize.cy + 2*yedge;
974 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
975 RECT rcParent;
977 x = -xedge;
978 width = infoPtr->calcSize.cx + 2*xedge;
979 y = 0; /* quiet compiler warning */
980 switch ( infoPtr->dwStyle & CCS_LAYOUT_MASK) {
981 case 0: /* shouldn't happen - see NCCreate */
982 case CCS_TOP:
983 y = ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER) - yedge;
984 break;
985 case CCS_NOMOVEY:
986 y = rcSelf.top;
987 break;
988 case CCS_BOTTOM:
989 GetClientRect(GetParent(infoPtr->hwndSelf), &rcParent);
990 translate_rect(infoPtr, &rcParent, &rcParent);
991 y = rcParent.bottom - infoPtr->calcSize.cy - yedge;
992 break;
995 else {
996 x = rcSelf.left;
997 /* As on Windows if the CCS_NODIVIDER is not present the control will move
998 * 2 pixel down after every layout */
999 y = rcSelf.top + ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1000 width = rcSelf.right - rcSelf.left;
1003 TRACE("hwnd %p, style=%08x, setting at (%d,%d) for (%d,%d)\n",
1004 infoPtr->hwndSelf, infoPtr->dwStyle, x, y, width, height);
1006 /* Set flag to ignore next WM_SIZE message and resize the window */
1007 infoPtr->fStatus |= SELF_RESIZE;
1008 if ((infoPtr->dwStyle & CCS_VERT) == 0)
1009 SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
1010 else
1011 SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
1012 infoPtr->fStatus &= ~SELF_RESIZE;
1016 static VOID
1017 REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
1019 static const WCHAR strComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
1020 REBAR_BAND *lpBand;
1021 WCHAR szClassName[40];
1022 UINT i;
1023 NMREBARCHILDSIZE rbcz;
1024 HDWP deferpos;
1026 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1027 ERR("BeginDeferWindowPos returned NULL\n");
1029 for (i = start; i < endplus; i++) {
1030 lpBand = REBAR_GetBand(infoPtr, i);
1032 if (HIDDENBAND(lpBand)) continue;
1033 if (lpBand->hwndChild) {
1034 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1036 /* Always generate the RBN_CHILDSIZE even if child
1037 did not change */
1038 rbcz.uBand = i;
1039 rbcz.wID = lpBand->wID;
1040 rbcz.rcChild = lpBand->rcChild;
1041 translate_rect(infoPtr, &rbcz.rcBand, &lpBand->rcBand);
1042 if (infoPtr->dwStyle & CCS_VERT)
1043 rbcz.rcBand.top += lpBand->cxHeader;
1044 else
1045 rbcz.rcBand.left += lpBand->cxHeader;
1046 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1047 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1048 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1049 TRACE(" from (%s) to (%s)\n",
1050 wine_dbgstr_rect(&lpBand->rcChild),
1051 wine_dbgstr_rect(&rbcz.rcChild));
1052 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1055 /* native (IE4 in "Favorites" frame **1) does:
1056 * SetRect (&rc, -1, -1, -1, -1)
1057 * EqualRect (&rc,band->rc???)
1058 * if ret==0
1059 * CopyRect (band->rc????, &rc)
1060 * set flag outside of loop
1063 GetClassNameW (lpBand->hwndChild, szClassName, sizeof(szClassName)/sizeof(szClassName[0]));
1064 if (!lstrcmpW (szClassName, strComboBox) ||
1065 !lstrcmpW (szClassName, WC_COMBOBOXEXW)) {
1066 INT nEditHeight, yPos;
1067 RECT rc;
1069 /* special placement code for combo or comboex box */
1072 /* get size of edit line */
1073 GetWindowRect (lpBand->hwndChild, &rc);
1074 nEditHeight = rc.bottom - rc.top;
1075 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1077 /* center combo box inside child area */
1078 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1079 lpBand->hwndChild,
1080 lpBand->rcChild.left, yPos,
1081 lpBand->rcChild.right - lpBand->rcChild.left,
1082 nEditHeight);
1083 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1084 lpBand->rcChild.left,
1085 /*lpBand->rcChild.top*/ yPos,
1086 lpBand->rcChild.right - lpBand->rcChild.left,
1087 nEditHeight,
1088 SWP_NOZORDER);
1089 if (!deferpos)
1090 ERR("DeferWindowPos returned NULL\n");
1092 else {
1093 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1094 lpBand->hwndChild,
1095 lpBand->rcChild.left, lpBand->rcChild.top,
1096 lpBand->rcChild.right - lpBand->rcChild.left,
1097 lpBand->rcChild.bottom - lpBand->rcChild.top);
1098 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1099 lpBand->rcChild.left,
1100 lpBand->rcChild.top,
1101 lpBand->rcChild.right - lpBand->rcChild.left,
1102 lpBand->rcChild.bottom - lpBand->rcChild.top,
1103 SWP_NOZORDER);
1104 if (!deferpos)
1105 ERR("DeferWindowPos returned NULL\n");
1109 if (!EndDeferWindowPos(deferpos))
1110 ERR("EndDeferWindowPos returned NULL\n");
1112 if (infoPtr->DoRedraw)
1113 UpdateWindow (infoPtr->hwndSelf);
1115 /* native (from **1 above) does:
1116 * UpdateWindow(rebar)
1117 * REBAR_ForceResize
1118 * RBN_HEIGHTCHANGE if necessary
1119 * if ret from any EqualRect was 0
1120 * Goto "BeginDeferWindowPos"
1125 /* Returns the next visible band (the first visible band in [i+1; infoPtr->uNumBands) )
1126 * or infoPtr->uNumBands if none */
1127 static int next_visible(const REBAR_INFO *infoPtr, int i)
1129 unsigned int n;
1130 for (n = i + 1; n < infoPtr->uNumBands; n++)
1131 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1132 break;
1133 return n;
1136 /* Returns the previous visible band (the last visible band in [0; i) )
1137 * or -1 if none */
1138 static int prev_visible(const REBAR_INFO *infoPtr, int i)
1140 int n;
1141 for (n = i - 1; n >= 0; n--)
1142 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1143 break;
1144 return n;
1147 /* Returns the first visible band or infoPtr->uNumBands if none */
1148 static int first_visible(const REBAR_INFO *infoPtr)
1150 return next_visible(infoPtr, -1); /* this works*/
1153 /* Returns the first visible band for the given row (or iBand if none) */
1154 static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
1156 int iLastBand = iBand;
1157 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1158 while ((iBand = prev_visible(infoPtr, iBand)) >= 0) {
1159 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1160 break;
1161 else
1162 iLastBand = iBand;
1164 return iLastBand;
1167 /* Returns the first visible band for the next row (or infoPtr->uNumBands if none) */
1168 static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
1170 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1171 while ((iBand = next_visible(infoPtr, iBand)) < infoPtr->uNumBands)
1172 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1173 break;
1174 return iBand;
1177 /* Compute the rcBand.{left,right} from the cxEffective bands widths computed earlier.
1178 * iBeginBand must be visible */
1179 static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1181 int xPos = 0, i;
1182 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1184 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1185 if (lpBand->rcBand.left != xPos || lpBand->rcBand.right != xPos + lpBand->cxEffective) {
1186 lpBand->fDraw |= NTF_INVALIDATE;
1187 TRACE("Setting rect %d to %d,%d\n", i, xPos, xPos + lpBand->cxEffective);
1188 lpBand->rcBand.left = xPos;
1189 lpBand->rcBand.right = xPos + lpBand->cxEffective;
1191 xPos += lpBand->cxEffective + SEP_WIDTH;
1195 /* The rationale of this function is probably as follows: if we have some space
1196 * to distribute we want to add it to a band on the right. However we don't want
1197 * to unminimize a minimized band so we search for a band that is big enough.
1198 * For some reason "big enough" is defined as bigger than the minimum size of the
1199 * first band in the row
1201 static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1203 INT cxMinFirstBand = 0, i;
1205 cxMinFirstBand = REBAR_GetBand(infoPtr, iBeginBand)->cxMinBand;
1207 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1208 if (REBAR_GetBand(infoPtr, i)->cxEffective > cxMinFirstBand &&
1209 !(REBAR_GetBand(infoPtr, i)->fStyle & RBBS_FIXEDSIZE))
1210 break;
1212 if (i < iBeginBand)
1213 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1214 if (REBAR_GetBand(infoPtr, i)->cxMinBand == cxMinFirstBand)
1215 break;
1217 TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
1218 return REBAR_GetBand(infoPtr, i);
1221 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the right */
1222 static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1224 REBAR_BAND *lpBand;
1225 INT width, i;
1227 TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
1228 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1230 lpBand = REBAR_GetBand(infoPtr, i);
1232 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1233 cxShrink -= lpBand->cxEffective - width;
1234 lpBand->cxEffective = width;
1235 if (bEnforce && lpBand->cx > lpBand->cxEffective)
1236 lpBand->cx = lpBand->cxEffective;
1237 if (cxShrink == 0)
1238 break;
1240 return cxShrink;
1244 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the left.
1245 * iBeginBand must be visible */
1246 static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1248 REBAR_BAND *lpBand;
1249 INT width, i;
1251 TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
1252 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1254 lpBand = REBAR_GetBand(infoPtr, i);
1256 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1257 cxShrink -= lpBand->cxEffective - width;
1258 lpBand->cxEffective = width;
1259 if (bEnforce)
1260 lpBand->cx = lpBand->cxEffective;
1261 if (cxShrink == 0)
1262 break;
1264 return cxShrink;
1267 /* Tries to move a band to a given offset within a row. */
1268 static int REBAR_MoveBandToRowOffset(REBAR_INFO *infoPtr, INT iBand, INT iFirstBand,
1269 INT iLastBand, INT xOff, BOOL reorder)
1271 REBAR_BAND *insertBand = REBAR_GetBand(infoPtr, iBand);
1272 int xPos = 0, i;
1273 const BOOL setBreak = REBAR_GetBand(infoPtr, iFirstBand)->fStyle & RBBS_BREAK;
1275 /* Find the band's new position */
1276 if(reorder)
1278 /* Used during an LR band reorder drag */
1279 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1281 if(xPos > xOff)
1282 break;
1283 xPos += REBAR_GetBand(infoPtr, i)->cxEffective + SEP_WIDTH;
1286 else
1288 /* Used during a UD band insertion drag */
1289 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1291 const REBAR_BAND *band = REBAR_GetBand(infoPtr, i);
1292 if(xPos + band->cxMinBand / 2 > xOff)
1293 break;
1294 xPos += band->cxEffective + SEP_WIDTH;
1298 /* Move the band to its new position */
1299 DPA_DeletePtr(infoPtr->bands, iBand);
1300 if(i > iBand)
1301 i--;
1302 DPA_InsertPtr(infoPtr->bands, i, insertBand);
1304 /* Ensure only the last band has the RBBS_BREAK flag set */
1305 insertBand->fStyle &= ~RBBS_BREAK;
1306 if(setBreak)
1307 REBAR_GetBand(infoPtr, iFirstBand)->fStyle |= RBBS_BREAK;
1309 /* Return the currently grabbed band */
1310 if(infoPtr->iGrabbedBand == iBand)
1312 infoPtr->iGrabbedBand = i;
1313 return i;
1315 else return -1;
1318 /* Set the heights of the visible bands in [iBeginBand; iEndBand) to the max height. iBeginBand must be visible */
1319 static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
1321 REBAR_BAND *lpBand;
1322 int yMaxHeight = 0;
1323 int yPos = yStart;
1324 int row = REBAR_GetBand(infoPtr, iBeginBand)->iRow;
1325 int i;
1326 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1328 lpBand = REBAR_GetBand(infoPtr, i);
1329 lpBand->cyRowSoFar = yMaxHeight;
1330 yMaxHeight = max(yMaxHeight, lpBand->cyMinBand);
1332 TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
1334 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1336 lpBand = REBAR_GetBand(infoPtr, i);
1337 /* we may be called for multiple rows if RBS_VARHEIGHT not set */
1338 if (lpBand->iRow != row) {
1339 yPos += yMaxHeight + SEP_WIDTH;
1340 row = lpBand->iRow;
1343 if (lpBand->rcBand.top != yPos || lpBand->rcBand.bottom != yPos + yMaxHeight) {
1344 lpBand->fDraw |= NTF_INVALIDATE;
1345 lpBand->rcBand.top = yPos;
1346 lpBand->rcBand.bottom = yPos + yMaxHeight;
1347 TRACE("Band %d: %s\n", i, wine_dbgstr_rect(&lpBand->rcBand));
1350 return yPos + yMaxHeight;
1353 /* Layout the row [iBeginBand; iEndBand). iBeginBand must be visible */
1354 static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
1356 REBAR_BAND *lpBand;
1357 int i, extra;
1358 int width = 0;
1360 TRACE("Adjusting row [%d;%d). Width: %d\n", iBeginBand, iEndBand, cx);
1361 for (i = iBeginBand; i < iEndBand; i++)
1362 REBAR_GetBand(infoPtr, i)->iRow = *piRow;
1364 /* compute the extra space */
1365 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1367 lpBand = REBAR_GetBand(infoPtr, i);
1368 if (i > iBeginBand)
1369 width += SEP_WIDTH;
1370 lpBand->cxEffective = max(lpBand->cxMinBand, lpBand->cx);
1371 width += lpBand->cxEffective;
1374 extra = cx - width;
1375 TRACE("Extra space: %d\n", extra);
1376 if (extra < 0) {
1377 int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
1378 if (ret > 0 && next_visible(infoPtr, iBeginBand) != iEndBand) /* one band may be longer than expected... */
1379 ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
1380 } else
1381 if (extra > 0) {
1382 lpBand = REBAR_FindBandToGrow(infoPtr, iBeginBand, iEndBand);
1383 lpBand->cxEffective += extra;
1386 REBAR_SetRowRectsX(infoPtr, iBeginBand, iEndBand);
1387 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1389 if (*piRow > 0)
1390 *pyPos += SEP_WIDTH;
1391 *pyPos = REBAR_SetBandsHeight(infoPtr, iBeginBand, iEndBand, *pyPos);
1393 (*piRow)++;
1396 static VOID
1397 REBAR_Layout(REBAR_INFO *infoPtr)
1399 REBAR_BAND *lpBand;
1400 RECT rcAdj;
1401 SIZE oldSize;
1402 INT adjcx, i;
1403 INT rowstart;
1404 INT row = 0;
1405 INT xMin, yPos;
1407 if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
1408 GetClientRect(infoPtr->hwndSelf, &rcAdj);
1409 else
1410 GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
1411 TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
1413 adjcx = get_rect_cx(infoPtr, &rcAdj);
1415 if (infoPtr->uNumBands == 0) {
1416 TRACE("No bands - setting size to (0,%d), vert: %x\n", adjcx, infoPtr->dwStyle & CCS_VERT);
1417 infoPtr->calcSize.cx = adjcx;
1418 /* the calcSize.cy won't change for a 0 band rebar */
1419 infoPtr->uNumRows = 0;
1420 REBAR_ForceResize(infoPtr);
1421 return;
1424 yPos = 0;
1425 xMin = 0;
1426 rowstart = first_visible(infoPtr);
1427 /* divide rows */
1428 for (i = rowstart; i < infoPtr->uNumBands; i = next_visible(infoPtr, i))
1430 lpBand = REBAR_GetBand(infoPtr, i);
1432 if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->cxMinBand > adjcx)) {
1433 TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
1434 REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
1435 rowstart = i;
1436 xMin = 0;
1438 else
1439 xMin += SEP_WIDTH;
1441 xMin += lpBand->cxMinBand;
1443 if (rowstart < infoPtr->uNumBands)
1444 REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
1446 if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
1447 yPos = REBAR_SetBandsHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, 0);
1449 infoPtr->uNumRows = row;
1451 if (infoPtr->dwStyle & CCS_VERT)
1452 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1453 else
1454 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1455 /* now compute size of Rebar itself */
1456 oldSize = infoPtr->calcSize;
1458 infoPtr->calcSize.cx = adjcx;
1459 infoPtr->calcSize.cy = yPos;
1460 TRACE("calcsize size=(%d, %d), origheight=(%d,%d)\n",
1461 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1462 oldSize.cx, oldSize.cy);
1464 REBAR_DumpBand (infoPtr);
1465 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1466 REBAR_ForceResize (infoPtr);
1468 /* note: after a RBN_HEIGHTCHANGE native sends once again all the RBN_CHILDSIZE
1469 * and does another ForceResize */
1470 if (oldSize.cy != infoPtr->calcSize.cy)
1472 NMHDR heightchange;
1473 REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1474 REBAR_AutoSize(infoPtr, FALSE);
1478 /* iBeginBand must be visible */
1479 static int
1480 REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
1482 int cyBandsOld;
1483 int cyBandsNew = 0;
1484 int i;
1486 TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
1488 cyBandsOld = REBAR_GetBand(infoPtr, iBeginBand)->rcBand.bottom -
1489 REBAR_GetBand(infoPtr, iBeginBand)->rcBand.top;
1490 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1492 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1493 int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
1494 int cyChild = round_child_height(lpBand, cyMaxChild);
1496 if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
1498 TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
1499 *fChanged = TRUE;
1500 lpBand->cyChild = cyChild;
1501 lpBand->fDraw |= NTF_INVALIDATE;
1502 update_min_band_height(infoPtr, lpBand);
1504 cyBandsNew = max(cyBandsNew, lpBand->cyMinBand);
1506 return cyBandsNew - cyBandsOld;
1509 /* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
1510 static VOID
1511 REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
1513 int extra = height - infoPtr->calcSize.cy; /* may be negative */
1514 BOOL fChanged = FALSE;
1515 UINT uNumRows = infoPtr->uNumRows;
1516 int i;
1518 if (uNumRows == 0) /* avoid division by 0 */
1519 return;
1521 /* That's not exactly what Windows does but should be similar */
1523 /* Pass one: break-up/glue rows */
1524 if (extra > 0)
1526 for (i = prev_visible(infoPtr, infoPtr->uNumBands); i > 0; i = prev_visible(infoPtr, i))
1528 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1529 int cyBreakExtra; /* additional cy for the rebar after a RBBS_BREAK on this band */
1531 height = lpBand->rcBand.bottom - lpBand->rcBand.top;
1533 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1534 cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
1535 else
1536 cyBreakExtra = height; /* 'height' => 'height' + 'height'*/
1537 cyBreakExtra += SEP_WIDTH;
1539 if (extra <= cyBreakExtra / 2)
1540 break;
1542 if (!(lpBand->fStyle & RBBS_BREAK))
1544 TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
1545 lpBand->fStyle |= RBBS_BREAK;
1546 lpBand->fDraw |= NTF_INVALIDATE;
1547 fChanged = TRUE;
1548 extra -= cyBreakExtra;
1549 uNumRows++;
1550 /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
1551 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1552 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->cyMinBand;
1556 /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
1558 /* Pass two: increase/decrease control height */
1559 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1561 int i = first_visible(infoPtr);
1562 int iRow = 0;
1563 while (i < infoPtr->uNumBands)
1565 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1566 int extraForRow = extra / (int)(uNumRows - iRow);
1567 int rowEnd;
1569 /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
1570 for (rowEnd = next_visible(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_visible(infoPtr, rowEnd))
1571 if (REBAR_GetBand(infoPtr, rowEnd)->iRow != lpBand->iRow ||
1572 REBAR_GetBand(infoPtr, rowEnd)->fStyle & RBBS_BREAK)
1573 break;
1575 extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
1576 TRACE("extra = %d\n", extra);
1577 i = rowEnd;
1578 iRow++;
1581 else
1582 REBAR_SizeChildrenToHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
1584 if (fChanged)
1585 REBAR_Layout(infoPtr);
1588 static VOID
1589 REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout)
1591 RECT rc, rcNew;
1592 NMRBAUTOSIZE autosize;
1594 if (needsLayout)
1595 REBAR_Layout(infoPtr);
1596 GetClientRect(infoPtr->hwndSelf, &rc);
1597 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, &rc));
1598 GetClientRect(infoPtr->hwndSelf, &rcNew);
1600 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
1601 autosize.fChanged = (memcmp(&rc, &rcNew, sizeof(RECT)) == 0);
1602 autosize.rcTarget = rc;
1603 autosize.rcActual = rcNew;
1604 REBAR_Notify((NMHDR *)&autosize, infoPtr, RBN_AUTOSIZE);
1607 static VOID
1608 REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1609 /* Function: This routine evaluates the band specs supplied */
1610 /* by the user and updates the following 5 fields in */
1611 /* the internal band structure: cxHeader, cyHeader, cxMinBand, cyMinBand, fStatus */
1613 UINT header=0;
1614 UINT textheight=0, imageheight = 0;
1615 UINT i, nonfixed;
1616 REBAR_BAND *tBand;
1618 lpBand->fStatus = 0;
1619 lpBand->cxMinBand = 0;
1620 lpBand->cyMinBand = 0;
1622 /* Data coming in from users into the cx... and cy... fields */
1623 /* may be bad, just garbage, because the user never clears */
1624 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1625 /* along if the fields exist in the input area. Here we must */
1626 /* determine if the data is valid. I have no idea how MS does */
1627 /* the validation, but it does because the RB_GETBANDINFO */
1628 /* returns a 0 when I know the sample program passed in an */
1629 /* address. Here I will use the algorithm that if the value */
1630 /* is greater than 65535 then it is bad and replace it with */
1631 /* a zero. Feel free to improve the algorithm. - GA 12/2000 */
1632 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1633 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1634 if (lpBand->cx > 65535) lpBand->cx = 0;
1635 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1636 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1637 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1638 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1640 /* TODO : we could try return to the caller if a value changed so that */
1641 /* a REBAR_Layout is needed. Till now the caller should call it */
1642 /* it always (we should also check what native does) */
1644 /* Header is where the image, text and gripper exist */
1645 /* in the band and precede the child window. */
1647 /* count number of non-FIXEDSIZE and non-Hidden bands */
1648 nonfixed = 0;
1649 for (i=0; i<infoPtr->uNumBands; i++){
1650 tBand = REBAR_GetBand(infoPtr, i);
1651 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1652 nonfixed++;
1655 /* calculate gripper rectangle */
1656 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1657 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1658 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1660 lpBand->fStatus |= HAS_GRIPPER;
1661 if (infoPtr->dwStyle & CCS_VERT)
1662 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1663 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1664 else
1665 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1666 else
1667 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1668 /* Always have 4 pixels before anything else */
1669 header += REBAR_ALWAYS_SPACE;
1672 /* image is visible */
1673 if (lpBand->iImage != -1 && (infoPtr->himl)) {
1674 lpBand->fStatus |= HAS_IMAGE;
1675 if (infoPtr->dwStyle & CCS_VERT) {
1676 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1677 imageheight = infoPtr->imageSize.cx + 4;
1679 else {
1680 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1681 imageheight = infoPtr->imageSize.cy + 4;
1685 /* text is visible */
1686 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
1687 !(lpBand->fStyle & RBBS_HIDETITLE)) {
1688 HDC hdc = GetDC (0);
1689 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1690 SIZE size;
1692 lpBand->fStatus |= HAS_TEXT;
1693 GetTextExtentPoint32W (hdc, lpBand->lpText,
1694 lstrlenW (lpBand->lpText), &size);
1695 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1696 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1698 SelectObject (hdc, hOldFont);
1699 ReleaseDC (0, hdc);
1702 /* if no gripper but either image or text, then leave space */
1703 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1704 !(lpBand->fStatus & HAS_GRIPPER)) {
1705 header += REBAR_ALWAYS_SPACE;
1708 /* check if user overrode the header value */
1709 if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
1710 lpBand->cxHeader = header;
1711 lpBand->cyHeader = max(textheight, imageheight);
1713 /* Now compute minimum size of child window */
1714 update_min_band_height(infoPtr, lpBand); /* update lpBand->cyMinBand from cyHeader and cyChild*/
1716 lpBand->cxMinBand = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
1717 if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
1718 lpBand->cxMinBand += CHEVRON_WIDTH;
1721 static UINT
1722 REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
1723 /* Function: This routine copies the supplied values from */
1724 /* user input (lprbbi) to the internal band structure. */
1725 /* It returns the mask of what changed. */
1727 UINT uChanged = 0x0;
1729 lpBand->fMask |= lprbbi->fMask;
1731 if( (lprbbi->fMask & RBBIM_STYLE) &&
1732 (lpBand->fStyle != lprbbi->fStyle ) )
1734 lpBand->fStyle = lprbbi->fStyle;
1735 uChanged |= RBBIM_STYLE;
1738 if( (lprbbi->fMask & RBBIM_COLORS) &&
1739 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
1740 ( lpBand->clrBack != lprbbi->clrBack ) ) )
1742 lpBand->clrFore = lprbbi->clrFore;
1743 lpBand->clrBack = lprbbi->clrBack;
1744 uChanged |= RBBIM_COLORS;
1747 if( (lprbbi->fMask & RBBIM_IMAGE) &&
1748 ( lpBand->iImage != lprbbi->iImage ) )
1750 lpBand->iImage = lprbbi->iImage;
1751 uChanged |= RBBIM_IMAGE;
1754 if( (lprbbi->fMask & RBBIM_CHILD) &&
1755 (lprbbi->hwndChild != lpBand->hwndChild ) )
1757 if (lprbbi->hwndChild) {
1758 lpBand->hwndChild = lprbbi->hwndChild;
1759 lpBand->hwndPrevParent =
1760 SetParent (lpBand->hwndChild, hwnd);
1761 /* below in trace from WinRAR */
1762 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
1763 /* above in trace from WinRAR */
1765 else {
1766 TRACE("child: %p prev parent: %p\n",
1767 lpBand->hwndChild, lpBand->hwndPrevParent);
1768 lpBand->hwndChild = 0;
1769 lpBand->hwndPrevParent = 0;
1771 uChanged |= RBBIM_CHILD;
1774 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
1775 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
1776 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
1777 ( (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) &&
1778 ( (lpBand->cyChild != lprbbi->cyChild ) ||
1779 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
1780 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
1781 ( (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE) &&
1782 ( (lpBand->cyChild ||
1783 lpBand->cyMaxChild ||
1784 lpBand->cyIntegral ) ) ) ) )
1786 lpBand->cxMinChild = lprbbi->cxMinChild;
1787 lpBand->cyMinChild = lprbbi->cyMinChild;
1788 /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
1789 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
1790 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1791 lpBand->cyIntegral = lprbbi->cyIntegral;
1793 lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild); /* make (cyChild - cyMinChild) a multiple of cyIntergral */
1795 else {
1796 lpBand->cyChild = lpBand->cyMinChild;
1797 lpBand->cyMaxChild = 0x7fffffff;
1798 lpBand->cyIntegral = 0;
1800 uChanged |= RBBIM_CHILDSIZE;
1803 if( (lprbbi->fMask & RBBIM_SIZE) &&
1804 (lpBand->cx != lprbbi->cx ) )
1806 lpBand->cx = lprbbi->cx;
1807 uChanged |= RBBIM_SIZE;
1810 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
1811 ( lpBand->hbmBack != lprbbi->hbmBack ) )
1813 lpBand->hbmBack = lprbbi->hbmBack;
1814 uChanged |= RBBIM_BACKGROUND;
1817 if( (lprbbi->fMask & RBBIM_ID) &&
1818 (lpBand->wID != lprbbi->wID ) )
1820 lpBand->wID = lprbbi->wID;
1821 uChanged |= RBBIM_ID;
1824 /* check for additional data */
1825 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE) {
1826 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
1827 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
1829 lpBand->cxIdeal = lprbbi->cxIdeal;
1830 uChanged |= RBBIM_IDEALSIZE;
1833 if( (lprbbi->fMask & RBBIM_LPARAM) &&
1834 (lpBand->lParam != lprbbi->lParam ) )
1836 lpBand->lParam = lprbbi->lParam;
1837 uChanged |= RBBIM_LPARAM;
1840 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
1841 (lpBand->cxHeader != lprbbi->cxHeader ) )
1843 lpBand->cxHeader = lprbbi->cxHeader;
1844 lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
1845 uChanged |= RBBIM_HEADERSIZE;
1849 return uChanged;
1852 static LRESULT REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, HDC hdc)
1853 /* Function: This erases the background rectangle by drawing */
1854 /* each band with its background color (or the default) and */
1855 /* draws each bands right separator if necessary. The row */
1856 /* separators are drawn on the first band of the next row. */
1858 REBAR_BAND *lpBand;
1859 UINT i;
1860 INT oldrow;
1861 RECT cr;
1862 COLORREF old = CLR_NONE, new;
1863 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1865 GetClientRect (infoPtr->hwndSelf, &cr);
1867 oldrow = -1;
1868 for(i=0; i<infoPtr->uNumBands; i++) {
1869 RECT rcBand;
1870 lpBand = REBAR_GetBand(infoPtr, i);
1871 if (HIDDENBAND(lpBand)) continue;
1872 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1874 /* draw band separator between rows */
1875 if (lpBand->iRow != oldrow) {
1876 oldrow = lpBand->iRow;
1877 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1878 RECT rcRowSep;
1879 rcRowSep = rcBand;
1880 if (infoPtr->dwStyle & CCS_VERT) {
1881 rcRowSep.right += SEP_WIDTH_SIZE;
1882 rcRowSep.bottom = infoPtr->calcSize.cx;
1883 if (theme)
1884 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_RIGHT, NULL);
1885 else
1886 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
1888 else {
1889 rcRowSep.bottom += SEP_WIDTH_SIZE;
1890 rcRowSep.right = infoPtr->calcSize.cx;
1891 if (theme)
1892 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1893 else
1894 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
1896 TRACE ("drawing band separator bottom (%s)\n",
1897 wine_dbgstr_rect(&rcRowSep));
1901 /* draw band separator between bands in a row */
1902 if (infoPtr->dwStyle & RBS_BANDBORDERS && lpBand->rcBand.left > 0) {
1903 RECT rcSep;
1904 rcSep = rcBand;
1905 if (infoPtr->dwStyle & CCS_VERT) {
1906 rcSep.bottom = rcSep.top;
1907 rcSep.top -= SEP_WIDTH_SIZE;
1908 if (theme)
1909 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1910 else
1911 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
1913 else {
1914 rcSep.right = rcSep.left;
1915 rcSep.left -= SEP_WIDTH_SIZE;
1916 if (theme)
1917 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_RIGHT, NULL);
1918 else
1919 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
1921 TRACE("drawing band separator right (%s)\n",
1922 wine_dbgstr_rect(&rcSep));
1925 /* draw the actual background */
1926 if (lpBand->clrBack != CLR_NONE) {
1927 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
1928 lpBand->clrBack;
1929 #if GLATESTING
1930 /* testing only - make background green to see it */
1931 new = RGB(0,128,0);
1932 #endif
1934 else {
1935 /* In the absence of documentation for Rebar vs. CLR_NONE,
1936 * we will use the default BtnFace color. Note documentation
1937 * exists for Listview and Imagelist.
1939 new = infoPtr->clrBtnFace;
1940 #if GLATESTING
1941 /* testing only - make background green to see it */
1942 new = RGB(0,128,0);
1943 #endif
1946 if (theme)
1948 /* When themed, the background color is ignored (but not a
1949 * background bitmap */
1950 DrawThemeBackground (theme, hdc, 0, 0, &cr, &rcBand);
1952 else
1954 old = SetBkColor (hdc, new);
1955 TRACE("%s background color=0x%06x, band %s\n",
1956 (lpBand->clrBack == CLR_NONE) ? "none" :
1957 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
1958 GetBkColor(hdc), wine_dbgstr_rect(&rcBand));
1959 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &rcBand, NULL, 0, 0);
1960 if (lpBand->clrBack != CLR_NONE)
1961 SetBkColor (hdc, old);
1964 return TRUE;
1967 static void
1968 REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
1970 REBAR_BAND *lpBand;
1971 RECT rect;
1972 UINT iCount;
1974 GetClientRect (infoPtr->hwndSelf, &rect);
1976 *pFlags = RBHT_NOWHERE;
1977 if (PtInRect (&rect, *lpPt))
1979 if (infoPtr->uNumBands == 0) {
1980 *pFlags = RBHT_NOWHERE;
1981 if (pBand)
1982 *pBand = -1;
1983 TRACE("NOWHERE\n");
1984 return;
1986 else {
1987 /* somewhere inside */
1988 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
1989 RECT rcBand;
1990 lpBand = REBAR_GetBand(infoPtr, iCount);
1991 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1992 if (HIDDENBAND(lpBand)) continue;
1993 if (PtInRect (&rcBand, *lpPt)) {
1994 if (pBand)
1995 *pBand = iCount;
1996 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
1997 *pFlags = RBHT_GRABBER;
1998 TRACE("ON GRABBER %d\n", iCount);
1999 return;
2001 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
2002 *pFlags = RBHT_CAPTION;
2003 TRACE("ON CAPTION %d\n", iCount);
2004 return;
2006 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2007 *pFlags = RBHT_CAPTION;
2008 TRACE("ON CAPTION %d\n", iCount);
2009 return;
2011 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2012 *pFlags = RBHT_CLIENT;
2013 TRACE("ON CLIENT %d\n", iCount);
2014 return;
2016 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
2017 *pFlags = RBHT_CHEVRON;
2018 TRACE("ON CHEVRON %d\n", iCount);
2019 return;
2021 else {
2022 *pFlags = RBHT_NOWHERE;
2023 TRACE("NOWHERE %d\n", iCount);
2024 return;
2029 *pFlags = RBHT_NOWHERE;
2030 if (pBand)
2031 *pBand = -1;
2033 TRACE("NOWHERE\n");
2034 return;
2037 else {
2038 *pFlags = RBHT_NOWHERE;
2039 if (pBand)
2040 *pBand = -1;
2041 TRACE("NOWHERE\n");
2042 return;
2046 static void
2047 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2048 /* Function: This will implement the functionality of a */
2049 /* Gripper drag within a row. It will not implement "out- */
2050 /* of-row" drags. (They are detected and handled in */
2051 /* REBAR_MouseMove.) */
2053 REBAR_BAND *hitBand;
2054 INT iHitBand, iRowBegin, iRowEnd;
2055 INT movement, xBand, cxLeft = 0;
2056 BOOL shrunkBands = FALSE;
2058 iHitBand = infoPtr->iGrabbedBand;
2059 iRowBegin = get_row_begin_for_band(infoPtr, iHitBand);
2060 iRowEnd = get_row_end_for_band(infoPtr, iHitBand);
2061 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2063 xBand = hitBand->rcBand.left;
2064 movement = (infoPtr->dwStyle&CCS_VERT ? ptsmove->y : ptsmove->x)
2065 - (xBand + REBAR_PRE_GRIPPER - infoPtr->ihitoffset);
2067 /* Dragging the first band in a row cannot cause shrinking */
2068 if(iHitBand != iRowBegin)
2070 if (movement < 0) {
2071 cxLeft = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iHitBand, -movement, TRUE);
2073 if(cxLeft < -movement)
2075 hitBand->cxEffective += -movement - cxLeft;
2076 hitBand->cx = hitBand->cxEffective;
2077 shrunkBands = TRUE;
2080 } else if (movement > 0) {
2082 cxLeft = movement;
2083 if (prev_visible(infoPtr, iHitBand) >= 0)
2084 cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
2086 if(cxLeft < movement)
2088 REBAR_BAND *lpPrev = REBAR_GetBand(infoPtr, prev_visible(infoPtr, iHitBand));
2089 lpPrev->cxEffective += movement - cxLeft;
2090 lpPrev->cx = hitBand->cxEffective;
2091 shrunkBands = TRUE;
2097 if(!shrunkBands)
2099 /* It was not possible to move the band by shrinking bands.
2100 * Try relocating the band instead. */
2101 REBAR_MoveBandToRowOffset(infoPtr, iHitBand, iRowBegin,
2102 iRowEnd, xBand + movement, TRUE);
2105 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2106 if (infoPtr->dwStyle & CCS_VERT)
2107 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
2108 else
2109 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
2110 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2113 static void
2114 REBAR_HandleUDDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2116 INT yOff = (infoPtr->dwStyle & CCS_VERT) ? ptsmove->x : ptsmove->y;
2117 INT iHitBand, iRowBegin, iNextRowBegin;
2118 REBAR_BAND *hitBand, *rowBeginBand;
2120 if(infoPtr->uNumBands <= 0)
2121 ERR("There are no bands in this rebar\n");
2123 /* Up/down dragging can only occur when there is more than one
2124 * band in the rebar */
2125 if(infoPtr->uNumBands <= 1)
2126 return;
2128 iHitBand = infoPtr->iGrabbedBand;
2129 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2131 /* If we're taking a band that has the RBBS_BREAK style set, this
2132 * style needs to be reapplied to the band that is going to become
2133 * the new start of the row. */
2134 if((hitBand->fStyle & RBBS_BREAK) &&
2135 (iHitBand < infoPtr->uNumBands - 1))
2136 REBAR_GetBand(infoPtr, iHitBand + 1)->fStyle |= RBBS_BREAK;
2138 if(yOff < 0)
2140 /* Place the band above the current top row */
2141 if(iHitBand==0 && (infoPtr->uNumBands==1 || REBAR_GetBand(infoPtr, 1)->fStyle&RBBS_BREAK))
2142 return;
2143 DPA_DeletePtr(infoPtr->bands, iHitBand);
2144 hitBand->fStyle &= ~RBBS_BREAK;
2145 REBAR_GetBand(infoPtr, 0)->fStyle |= RBBS_BREAK;
2146 infoPtr->iGrabbedBand = DPA_InsertPtr(
2147 infoPtr->bands, 0, hitBand);
2149 else if(yOff > REBAR_GetBand(infoPtr, infoPtr->uNumBands - 1)->rcBand.bottom)
2151 /* Place the band below the current bottom row */
2152 if(iHitBand == infoPtr->uNumBands-1 && hitBand->fStyle&RBBS_BREAK)
2153 return;
2154 DPA_DeletePtr(infoPtr->bands, iHitBand);
2155 hitBand->fStyle |= RBBS_BREAK;
2156 infoPtr->iGrabbedBand = DPA_InsertPtr(
2157 infoPtr->bands, infoPtr->uNumBands - 1, hitBand);
2159 else
2161 /* Place the band in the prexisting row the mouse is hovering over */
2162 iRowBegin = first_visible(infoPtr);
2163 while(iRowBegin < infoPtr->uNumBands)
2165 iNextRowBegin = get_row_end_for_band(infoPtr, iRowBegin);
2166 rowBeginBand = REBAR_GetBand(infoPtr, iRowBegin);
2167 if(rowBeginBand->rcBand.bottom > yOff)
2169 REBAR_MoveBandToRowOffset(
2170 infoPtr, iHitBand, iRowBegin, iNextRowBegin,
2171 ((infoPtr->dwStyle & CCS_VERT) ? ptsmove->y : ptsmove->x)
2172 - REBAR_PRE_GRIPPER - infoPtr->ihitoffset, FALSE);
2173 break;
2176 iRowBegin = iNextRowBegin;
2180 REBAR_Layout(infoPtr);
2184 /* << REBAR_BeginDrag >> */
2187 static LRESULT
2188 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam)
2190 UINT uBand = (UINT)wParam;
2191 REBAR_BAND *lpBand;
2193 if (uBand >= infoPtr->uNumBands)
2194 return FALSE;
2196 TRACE("deleting band %u!\n", uBand);
2197 lpBand = REBAR_GetBand(infoPtr, uBand);
2198 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2199 /* TODO: a return of 1 should probably cancel the deletion */
2201 if (lpBand->hwndChild)
2202 ShowWindow(lpBand->hwndChild, SW_HIDE);
2203 Free(lpBand->lpText);
2204 Free(lpBand);
2206 infoPtr->uNumBands--;
2207 DPA_DeletePtr(infoPtr->bands, uBand);
2209 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2211 /* if only 1 band left the re-validate to possible eliminate gripper */
2212 if (infoPtr->uNumBands == 1)
2213 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2215 REBAR_Layout(infoPtr);
2217 return TRUE;
2221 /* << REBAR_DragMove >> */
2222 /* << REBAR_EndDrag >> */
2225 static LRESULT
2226 REBAR_GetBandBorders (const REBAR_INFO *infoPtr, UINT uBand, RECT *lpRect)
2228 REBAR_BAND *lpBand;
2230 if (!lpRect)
2231 return 0;
2232 if (uBand >= infoPtr->uNumBands)
2233 return 0;
2235 lpBand = REBAR_GetBand(infoPtr, uBand);
2237 /* FIXME - the following values were determined by experimentation */
2238 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2239 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2240 /* difference in size of the control area with and without the */
2241 /* style. - GA */
2242 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2243 if (infoPtr->dwStyle & CCS_VERT) {
2244 lpRect->left = 1;
2245 lpRect->top = lpBand->cxHeader + 4;
2246 lpRect->right = 1;
2247 lpRect->bottom = 0;
2249 else {
2250 lpRect->left = lpBand->cxHeader + 4;
2251 lpRect->top = 1;
2252 lpRect->right = 0;
2253 lpRect->bottom = 1;
2256 else {
2257 lpRect->left = lpBand->cxHeader;
2259 return 0;
2263 static inline LRESULT
2264 REBAR_GetBandCount (const REBAR_INFO *infoPtr)
2266 TRACE("band count %u!\n", infoPtr->uNumBands);
2268 return infoPtr->uNumBands;
2272 static LRESULT
2273 REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, UINT uIndex, LPREBARBANDINFOW lprbbi, BOOL bUnicode)
2275 REBAR_BAND *lpBand;
2277 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2278 return FALSE;
2280 if (uIndex >= infoPtr->uNumBands)
2281 return FALSE;
2283 TRACE("index %u (bUnicode=%d)\n", uIndex, bUnicode);
2285 /* copy band information */
2286 lpBand = REBAR_GetBand(infoPtr, uIndex);
2288 if (lprbbi->fMask & RBBIM_STYLE)
2289 lprbbi->fStyle = lpBand->fStyle;
2291 if (lprbbi->fMask & RBBIM_COLORS) {
2292 lprbbi->clrFore = lpBand->clrFore;
2293 lprbbi->clrBack = lpBand->clrBack;
2294 if (lprbbi->clrBack == CLR_DEFAULT)
2295 lprbbi->clrBack = infoPtr->clrBtnFace;
2298 if (lprbbi->fMask & RBBIM_TEXT) {
2299 if (bUnicode)
2300 Str_GetPtrW(lpBand->lpText, lprbbi->lpText, lprbbi->cch);
2301 else
2302 Str_GetPtrWtoA(lpBand->lpText, (LPSTR)lprbbi->lpText, lprbbi->cch);
2305 if (lprbbi->fMask & RBBIM_IMAGE)
2306 lprbbi->iImage = lpBand->iImage;
2308 if (lprbbi->fMask & RBBIM_CHILD)
2309 lprbbi->hwndChild = lpBand->hwndChild;
2311 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2312 lprbbi->cxMinChild = lpBand->cxMinChild;
2313 lprbbi->cyMinChild = lpBand->cyMinChild;
2314 /* to make tests pass we follow Windows behaviour and allow to read these fields only
2315 * for RBBS_VARIABLEHEIGHTS bands */
2316 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2317 lprbbi->cyChild = lpBand->cyChild;
2318 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2319 lprbbi->cyIntegral = lpBand->cyIntegral;
2323 if (lprbbi->fMask & RBBIM_SIZE)
2324 lprbbi->cx = lpBand->cx;
2326 if (lprbbi->fMask & RBBIM_BACKGROUND)
2327 lprbbi->hbmBack = lpBand->hbmBack;
2329 if (lprbbi->fMask & RBBIM_ID)
2330 lprbbi->wID = lpBand->wID;
2332 /* check for additional data */
2333 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE) {
2334 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2335 lprbbi->cxIdeal = lpBand->cxIdeal;
2337 if (lprbbi->fMask & RBBIM_LPARAM)
2338 lprbbi->lParam = lpBand->lParam;
2340 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2341 lprbbi->cxHeader = lpBand->cxHeader;
2344 REBAR_DumpBandInfo(lprbbi);
2346 return TRUE;
2350 static LRESULT
2351 REBAR_GetBarHeight (const REBAR_INFO *infoPtr)
2353 INT nHeight;
2355 nHeight = infoPtr->calcSize.cy;
2357 TRACE("height = %d\n", nHeight);
2359 return nHeight;
2363 static LRESULT
2364 REBAR_GetBarInfo (const REBAR_INFO *infoPtr, LPREBARINFO lpInfo)
2366 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2367 return FALSE;
2369 TRACE("getting bar info!\n");
2371 if (infoPtr->himl) {
2372 lpInfo->himl = infoPtr->himl;
2373 lpInfo->fMask |= RBIM_IMAGELIST;
2376 return TRUE;
2380 static inline LRESULT
2381 REBAR_GetBkColor (const REBAR_INFO *infoPtr)
2383 COLORREF clr = infoPtr->clrBk;
2385 if (clr == CLR_DEFAULT)
2386 clr = infoPtr->clrBtnFace;
2388 TRACE("background color 0x%06x!\n", clr);
2390 return clr;
2394 /* << REBAR_GetColorScheme >> */
2395 /* << REBAR_GetDropTarget >> */
2398 static LRESULT
2399 REBAR_GetPalette (const REBAR_INFO *infoPtr)
2401 FIXME("empty stub!\n");
2403 return 0;
2407 static LRESULT
2408 REBAR_GetRect (const REBAR_INFO *infoPtr, INT iBand, RECT *lprc)
2410 REBAR_BAND *lpBand;
2412 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2413 return FALSE;
2414 if (!lprc)
2415 return FALSE;
2417 lpBand = REBAR_GetBand(infoPtr, iBand);
2418 /* For CCS_VERT the coordinates will be swapped - like on Windows */
2419 CopyRect (lprc, &lpBand->rcBand);
2421 TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
2423 return TRUE;
2427 static inline LRESULT
2428 REBAR_GetRowCount (const REBAR_INFO *infoPtr)
2430 TRACE("%u\n", infoPtr->uNumRows);
2432 return infoPtr->uNumRows;
2436 static LRESULT
2437 REBAR_GetRowHeight (const REBAR_INFO *infoPtr, INT iRow)
2439 int j = 0, ret = 0;
2440 UINT i;
2441 REBAR_BAND *lpBand;
2443 for (i=0; i<infoPtr->uNumBands; i++) {
2444 lpBand = REBAR_GetBand(infoPtr, i);
2445 if (HIDDENBAND(lpBand)) continue;
2446 if (lpBand->iRow != iRow) continue;
2447 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2448 if (j > ret) ret = j;
2451 TRACE("row %d, height %d\n", iRow, ret);
2453 return ret;
2457 static inline LRESULT
2458 REBAR_GetTextColor (const REBAR_INFO *infoPtr)
2460 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2462 return infoPtr->clrText;
2466 static inline LRESULT
2467 REBAR_GetToolTips (const REBAR_INFO *infoPtr)
2469 return (LRESULT)infoPtr->hwndToolTip;
2473 static inline LRESULT
2474 REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
2476 TRACE("%s hwnd=%p\n",
2477 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2479 return infoPtr->bUnicode;
2483 static inline LRESULT
2484 REBAR_GetVersion (const REBAR_INFO *infoPtr)
2486 TRACE("version %d\n", infoPtr->iVersion);
2487 return infoPtr->iVersion;
2491 static LRESULT
2492 REBAR_HitTest (const REBAR_INFO *infoPtr, LPRBHITTESTINFO lprbht)
2494 if (!lprbht)
2495 return -1;
2497 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2499 return lprbht->iBand;
2503 static LRESULT
2504 REBAR_IdToIndex (const REBAR_INFO *infoPtr, UINT uId)
2506 UINT i;
2508 if (infoPtr->uNumBands < 1)
2509 return -1;
2511 for (i = 0; i < infoPtr->uNumBands; i++) {
2512 if (REBAR_GetBand(infoPtr, i)->wID == uId) {
2513 TRACE("id %u is band %u found!\n", uId, i);
2514 return i;
2518 TRACE("id %u is not found\n", uId);
2519 return -1;
2523 static LRESULT
2524 REBAR_InsertBandT(REBAR_INFO *infoPtr, INT iIndex, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2526 REBAR_BAND *lpBand;
2528 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2529 return FALSE;
2531 /* trace the index as signed to see the -1 */
2532 TRACE("insert band at %d (bUnicode=%d)!\n", iIndex, bUnicode);
2533 REBAR_DumpBandInfo(lprbbi);
2535 if (!(lpBand = Alloc(sizeof(REBAR_BAND)))) return FALSE;
2536 if ((iIndex == -1) || (iIndex > infoPtr->uNumBands))
2537 iIndex = infoPtr->uNumBands;
2538 if (DPA_InsertPtr(infoPtr->bands, iIndex, lpBand) == -1)
2540 Free(lpBand);
2541 return FALSE;
2543 infoPtr->uNumBands++;
2545 TRACE("index %d!\n", iIndex);
2547 /* initialize band */
2548 memset(lpBand, 0, sizeof(*lpBand));
2549 lpBand->clrFore = infoPtr->clrText == CLR_NONE ? infoPtr->clrBtnText :
2550 infoPtr->clrText;
2551 lpBand->clrBack = infoPtr->clrBk == CLR_NONE ? infoPtr->clrBtnFace :
2552 infoPtr->clrBk;
2553 lpBand->iImage = -1;
2555 REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
2557 /* Make sure the defaults for these are correct */
2558 if (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE || !(lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2559 lpBand->cyChild = lpBand->cyMinChild;
2560 lpBand->cyMaxChild = 0x7fffffff;
2561 lpBand->cyIntegral = 0;
2564 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2565 if (bUnicode)
2566 Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
2567 else
2568 Str_SetPtrAtoW(&lpBand->lpText, (LPSTR)lprbbi->lpText);
2571 REBAR_ValidateBand (infoPtr, lpBand);
2572 /* On insert of second band, revalidate band 1 to possible add gripper */
2573 if (infoPtr->uNumBands == 2)
2574 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2576 REBAR_DumpBand (infoPtr);
2578 REBAR_Layout(infoPtr);
2579 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2581 return TRUE;
2585 static LRESULT
2586 REBAR_MaximizeBand (const REBAR_INFO *infoPtr, INT iBand, LPARAM lParam)
2588 REBAR_BAND *lpBand;
2589 int iRowBegin, iRowEnd;
2590 int cxDesired, extra, extraOrig;
2591 int cxIdealBand;
2593 /* Validate */
2594 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2595 /* error !!! */
2596 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
2597 iBand, infoPtr->uNumBands);
2598 return FALSE;
2601 lpBand = REBAR_GetBand(infoPtr, iBand);
2603 if (lpBand->fStyle & RBBS_HIDDEN)
2605 /* Windows is buggy and creates a hole */
2606 WARN("Ignoring maximize request on a hidden band (%d)\n", iBand);
2607 return FALSE;
2610 cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
2611 if (lParam && (lpBand->cxEffective < cxIdealBand))
2612 cxDesired = cxIdealBand;
2613 else
2614 cxDesired = infoPtr->calcSize.cx;
2616 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2617 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2618 extraOrig = extra = cxDesired - lpBand->cxEffective;
2619 if (extra > 0)
2620 extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iBand, extra, TRUE);
2621 if (extra > 0)
2622 extra = REBAR_ShrinkBandsLTR(infoPtr, next_visible(infoPtr, iBand), iRowEnd, extra, TRUE);
2623 lpBand->cxEffective += extraOrig - extra;
2624 lpBand->cx = lpBand->cxEffective;
2625 TRACE("(%d, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", iBand, lParam, cxDesired, lpBand->cx, extraOrig, extra);
2626 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2628 if (infoPtr->dwStyle & CCS_VERT)
2629 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2630 else
2631 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2632 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2633 return TRUE;
2638 static LRESULT
2639 REBAR_MinimizeBand (const REBAR_INFO *infoPtr, INT iBand)
2641 REBAR_BAND *lpBand;
2642 int iPrev, iRowBegin, iRowEnd;
2644 /* A "minimize" band is equivalent to "dragging" the gripper
2645 * of than band to the right till the band is only the size
2646 * of the cxHeader.
2649 /* Validate */
2650 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2651 /* error !!! */
2652 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
2653 iBand, infoPtr->uNumBands);
2654 return FALSE;
2657 /* compute amount of movement and validate */
2658 lpBand = REBAR_GetBand(infoPtr, iBand);
2660 if (lpBand->fStyle & RBBS_HIDDEN)
2662 /* Windows is buggy and creates a hole/overlap */
2663 WARN("Ignoring minimize request on a hidden band (%d)\n", iBand);
2664 return FALSE;
2667 iPrev = prev_visible(infoPtr, iBand);
2668 /* if first band in row */
2669 if (iPrev < 0 || REBAR_GetBand(infoPtr, iPrev)->iRow != lpBand->iRow) {
2670 int iNext = next_visible(infoPtr, iBand);
2671 if (iNext < infoPtr->uNumBands && REBAR_GetBand(infoPtr, iNext)->iRow == lpBand->iRow) {
2672 TRACE("(%d): Minimizing the first band in row is by maximizing the second\n", iBand);
2673 REBAR_MaximizeBand(infoPtr, iNext, FALSE);
2675 else
2676 TRACE("(%d): Only one band in row - nothing to do\n", iBand);
2677 return TRUE;
2680 REBAR_GetBand(infoPtr, iPrev)->cxEffective += lpBand->cxEffective - lpBand->cxMinBand;
2681 REBAR_GetBand(infoPtr, iPrev)->cx = REBAR_GetBand(infoPtr, iPrev)->cxEffective;
2682 lpBand->cx = lpBand->cxEffective = lpBand->cxMinBand;
2684 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2685 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2686 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2688 if (infoPtr->dwStyle & CCS_VERT)
2689 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2690 else
2691 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2692 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2693 return FALSE;
2697 static LRESULT
2698 REBAR_MoveBand (REBAR_INFO *infoPtr, INT iFrom, INT iTo)
2700 REBAR_BAND *lpBand;
2702 /* Validate */
2703 if ((infoPtr->uNumBands == 0) ||
2704 (iFrom < 0) || iFrom >= infoPtr->uNumBands ||
2705 (iTo < 0) || iTo >= infoPtr->uNumBands) {
2706 /* error !!! */
2707 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
2708 iFrom, iTo, infoPtr->uNumBands);
2709 return FALSE;
2712 lpBand = REBAR_GetBand(infoPtr, iFrom);
2713 DPA_DeletePtr(infoPtr->bands, iFrom);
2714 DPA_InsertPtr(infoPtr->bands, iTo, lpBand);
2716 TRACE("moved band %d to index %d\n", iFrom, iTo);
2717 REBAR_DumpBand (infoPtr);
2719 /* **************************************************** */
2720 /* */
2721 /* We do not do a REBAR_Layout here because the native */
2722 /* control does not do that. The actual layout and */
2723 /* repaint is done by the *next* real action, ex.: */
2724 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
2725 /* */
2726 /* **************************************************** */
2728 return TRUE;
2732 /* return TRUE if two strings are different */
2733 static BOOL
2734 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
2736 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
2739 static LRESULT
2740 REBAR_SetBandInfoT(REBAR_INFO *infoPtr, INT iBand, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2742 REBAR_BAND *lpBand;
2743 UINT uChanged;
2745 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2746 return FALSE;
2748 if (iBand >= infoPtr->uNumBands)
2749 return FALSE;
2751 TRACE("index %d\n", iBand);
2752 REBAR_DumpBandInfo (lprbbi);
2754 /* set band information */
2755 lpBand = REBAR_GetBand(infoPtr, iBand);
2757 uChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2758 if (lprbbi->fMask & RBBIM_TEXT) {
2759 LPWSTR wstr = NULL;
2760 if (bUnicode)
2761 Str_SetPtrW(&wstr, lprbbi->lpText);
2762 else
2763 Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
2765 if (REBAR_strdifW(wstr, lpBand->lpText)) {
2766 Free(lpBand->lpText);
2767 lpBand->lpText = wstr;
2768 uChanged |= RBBIM_TEXT;
2770 else
2771 Free(wstr);
2774 REBAR_ValidateBand (infoPtr, lpBand);
2776 REBAR_DumpBand (infoPtr);
2778 if (uChanged & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IMAGE)) {
2779 REBAR_Layout(infoPtr);
2780 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2783 return TRUE;
2787 static LRESULT
2788 REBAR_SetBarInfo (REBAR_INFO *infoPtr, const REBARINFO *lpInfo)
2790 REBAR_BAND *lpBand;
2791 UINT i;
2793 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2794 return FALSE;
2796 TRACE("setting bar info!\n");
2798 if (lpInfo->fMask & RBIM_IMAGELIST) {
2799 infoPtr->himl = lpInfo->himl;
2800 if (infoPtr->himl) {
2801 INT cx, cy;
2802 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
2803 infoPtr->imageSize.cx = cx;
2804 infoPtr->imageSize.cy = cy;
2806 else {
2807 infoPtr->imageSize.cx = 0;
2808 infoPtr->imageSize.cy = 0;
2810 TRACE("new image cx=%d, cy=%d\n", infoPtr->imageSize.cx,
2811 infoPtr->imageSize.cy);
2814 /* revalidate all bands to reset flags for images in headers of bands */
2815 for (i=0; i<infoPtr->uNumBands; i++) {
2816 lpBand = REBAR_GetBand(infoPtr, i);
2817 REBAR_ValidateBand (infoPtr, lpBand);
2820 return TRUE;
2824 static LRESULT
2825 REBAR_SetBkColor (REBAR_INFO *infoPtr, COLORREF clr)
2827 COLORREF clrTemp;
2829 clrTemp = infoPtr->clrBk;
2830 infoPtr->clrBk = clr;
2832 TRACE("background color 0x%06x!\n", infoPtr->clrBk);
2834 return clrTemp;
2838 /* << REBAR_SetColorScheme >> */
2839 /* << REBAR_SetPalette >> */
2842 static LRESULT
2843 REBAR_SetParent (REBAR_INFO *infoPtr, HWND parent)
2845 HWND hwndTemp = infoPtr->hwndNotify;
2847 infoPtr->hwndNotify = parent;
2849 return (LRESULT)hwndTemp;
2853 static LRESULT
2854 REBAR_SetTextColor (REBAR_INFO *infoPtr, COLORREF clr)
2856 COLORREF clrTemp;
2858 clrTemp = infoPtr->clrText;
2859 infoPtr->clrText = clr;
2861 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2863 return clrTemp;
2867 /* << REBAR_SetTooltips >> */
2870 static inline LRESULT
2871 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, BOOL unicode)
2873 BOOL bTemp = infoPtr->bUnicode;
2875 TRACE("to %s hwnd=%p, was %s\n",
2876 unicode ? "TRUE" : "FALSE", infoPtr->hwndSelf,
2877 (bTemp) ? "TRUE" : "FALSE");
2879 infoPtr->bUnicode = unicode;
2881 return bTemp;
2885 static LRESULT
2886 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
2888 INT iOldVersion = infoPtr->iVersion;
2890 if (iVersion > COMCTL32_VERSION)
2891 return -1;
2893 infoPtr->iVersion = iVersion;
2895 TRACE("new version %d\n", iVersion);
2897 return iOldVersion;
2901 static LRESULT
2902 REBAR_ShowBand (REBAR_INFO *infoPtr, INT iBand, BOOL show)
2904 REBAR_BAND *lpBand;
2906 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2907 return FALSE;
2909 lpBand = REBAR_GetBand(infoPtr, iBand);
2911 if (show) {
2912 TRACE("show band %d\n", iBand);
2913 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
2914 if (IsWindow (lpBand->hwndChild))
2915 ShowWindow (lpBand->hwndChild, SW_SHOW);
2917 else {
2918 TRACE("hide band %d\n", iBand);
2919 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
2920 if (IsWindow (lpBand->hwndChild))
2921 ShowWindow (lpBand->hwndChild, SW_HIDE);
2924 REBAR_Layout(infoPtr);
2925 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2927 return TRUE;
2931 static LRESULT
2932 REBAR_SizeToRect (REBAR_INFO *infoPtr, const RECT *lpRect)
2934 if (!lpRect) return FALSE;
2936 TRACE("[%s]\n", wine_dbgstr_rect(lpRect));
2937 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, lpRect));
2938 return TRUE;
2943 static LRESULT
2944 REBAR_Create (REBAR_INFO *infoPtr, LPCREATESTRUCTW cs)
2946 RECT wnrc1, clrc1;
2948 if (TRACE_ON(rebar)) {
2949 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
2950 GetClientRect(infoPtr->hwndSelf, &clrc1);
2951 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
2952 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
2953 cs->x, cs->y, cs->cx, cs->cy);
2956 TRACE("created!\n");
2958 if (OpenThemeData (infoPtr->hwndSelf, themeClass))
2960 /* native seems to clear WS_BORDER when themed */
2961 infoPtr->dwStyle &= ~WS_BORDER;
2964 return 0;
2968 static LRESULT
2969 REBAR_Destroy (REBAR_INFO *infoPtr)
2971 REBAR_BAND *lpBand;
2972 UINT i;
2974 /* clean up each band */
2975 for (i = 0; i < infoPtr->uNumBands; i++) {
2976 lpBand = REBAR_GetBand(infoPtr, i);
2978 /* delete text strings */
2979 Free (lpBand->lpText);
2980 lpBand->lpText = NULL;
2981 /* destroy child window */
2982 DestroyWindow (lpBand->hwndChild);
2983 Free (lpBand);
2986 /* free band array */
2987 DPA_Destroy (infoPtr->bands);
2988 infoPtr->bands = NULL;
2990 DestroyCursor (infoPtr->hcurArrow);
2991 DestroyCursor (infoPtr->hcurHorz);
2992 DestroyCursor (infoPtr->hcurVert);
2993 DestroyCursor (infoPtr->hcurDrag);
2994 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
2995 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
2997 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2999 /* free rebar info data */
3000 Free (infoPtr);
3001 TRACE("destroyed!\n");
3002 return 0;
3005 static LRESULT
3006 REBAR_GetFont (const REBAR_INFO *infoPtr)
3008 return (LRESULT)infoPtr->hFont;
3011 static LRESULT
3012 REBAR_PushChevron(const REBAR_INFO *infoPtr, UINT uBand, LPARAM lParam)
3014 if (uBand < infoPtr->uNumBands)
3016 NMREBARCHEVRON nmrbc;
3017 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
3019 TRACE("Pressed chevron on band %u\n", uBand);
3021 /* redraw chevron in pushed state */
3022 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
3023 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
3024 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3026 /* notify app so it can display a popup menu or whatever */
3027 nmrbc.uBand = uBand;
3028 nmrbc.wID = lpBand->wID;
3029 nmrbc.lParam = lpBand->lParam;
3030 nmrbc.rc = lpBand->rcChevron;
3031 nmrbc.lParamNM = lParam;
3032 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3034 /* redraw chevron in previous state */
3035 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3036 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3038 return TRUE;
3040 return FALSE;
3043 static LRESULT
3044 REBAR_LButtonDown (REBAR_INFO *infoPtr, LPARAM lParam)
3046 UINT htFlags;
3047 INT iHitBand;
3048 POINT ptMouseDown;
3049 ptMouseDown.x = (short)LOWORD(lParam);
3050 ptMouseDown.y = (short)HIWORD(lParam);
3052 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3054 if (htFlags == RBHT_CHEVRON)
3056 REBAR_PushChevron(infoPtr, iHitBand, 0);
3058 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3060 REBAR_BAND *lpBand;
3062 TRACE("Starting drag\n");
3064 lpBand = REBAR_GetBand(infoPtr, iHitBand);
3066 SetCapture (infoPtr->hwndSelf);
3067 infoPtr->iGrabbedBand = iHitBand;
3069 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3070 infoPtr->dragStart.x = (short)LOWORD(lParam);
3071 infoPtr->dragStart.y = (short)HIWORD(lParam);
3072 infoPtr->dragNow = infoPtr->dragStart;
3073 if (infoPtr->dwStyle & CCS_VERT)
3074 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3075 else
3076 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3078 return 0;
3081 static LRESULT
3082 REBAR_LButtonUp (REBAR_INFO *infoPtr)
3084 if (infoPtr->iGrabbedBand >= 0)
3086 NMHDR layout;
3087 RECT rect;
3089 infoPtr->dragStart.x = 0;
3090 infoPtr->dragStart.y = 0;
3091 infoPtr->dragNow = infoPtr->dragStart;
3093 ReleaseCapture ();
3095 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3096 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3097 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3098 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3101 infoPtr->iGrabbedBand = -1;
3103 GetClientRect(infoPtr->hwndSelf, &rect);
3104 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3107 return 0;
3110 static LRESULT
3111 REBAR_MouseLeave (REBAR_INFO *infoPtr)
3113 if (infoPtr->ichevronhotBand >= 0)
3115 REBAR_BAND *lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3116 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3118 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3119 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3122 infoPtr->iOldBand = -1;
3123 infoPtr->ichevronhotBand = -2;
3125 return TRUE;
3128 static LRESULT
3129 REBAR_MouseMove (REBAR_INFO *infoPtr, LPARAM lParam)
3131 REBAR_BAND *lpChevronBand;
3132 POINT ptMove;
3134 ptMove.x = (short)LOWORD(lParam);
3135 ptMove.y = (short)HIWORD(lParam);
3137 /* if we are currently dragging a band */
3138 if (infoPtr->iGrabbedBand >= 0)
3140 REBAR_BAND *band;
3141 int yPtMove = (infoPtr->dwStyle & CCS_VERT ? ptMove.x : ptMove.y);
3143 if (GetCapture() != infoPtr->hwndSelf)
3144 ERR("We are dragging but haven't got capture?!?\n");
3146 band = REBAR_GetBand(infoPtr, infoPtr->iGrabbedBand);
3148 /* if mouse did not move much, exit */
3149 if ((abs(ptMove.x - infoPtr->dragNow.x) <= mindragx) &&
3150 (abs(ptMove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3152 /* on first significant mouse movement, issue notify */
3153 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
3154 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
3155 /* Notify returned TRUE - abort drag */
3156 infoPtr->dragStart.x = 0;
3157 infoPtr->dragStart.y = 0;
3158 infoPtr->dragNow = infoPtr->dragStart;
3159 infoPtr->iGrabbedBand = -1;
3160 ReleaseCapture ();
3161 return 0;
3163 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
3166 /* Test for valid drag case - must not be first band in row */
3167 if ((yPtMove < band->rcBand.top) ||
3168 (yPtMove > band->rcBand.bottom)) {
3169 REBAR_HandleUDDrag (infoPtr, &ptMove);
3171 else {
3172 REBAR_HandleLRDrag (infoPtr, &ptMove);
3175 else
3177 INT iHitBand;
3178 UINT htFlags;
3179 TRACKMOUSEEVENT trackinfo;
3181 REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
3183 if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
3185 lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3186 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3188 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3189 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3191 infoPtr->ichevronhotBand = -2;
3194 if (htFlags == RBHT_CHEVRON)
3196 /* fill in the TRACKMOUSEEVENT struct */
3197 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
3198 trackinfo.dwFlags = TME_QUERY;
3199 trackinfo.hwndTrack = infoPtr->hwndSelf;
3200 trackinfo.dwHoverTime = 0;
3202 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
3203 _TrackMouseEvent(&trackinfo);
3205 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
3206 if(!(trackinfo.dwFlags & TME_LEAVE))
3208 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
3210 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
3211 /* and can properly deactivate the hot chevron */
3212 _TrackMouseEvent(&trackinfo);
3215 lpChevronBand = REBAR_GetBand(infoPtr, iHitBand);
3216 if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
3218 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
3219 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3220 infoPtr->ichevronhotBand = iHitBand;
3223 infoPtr->iOldBand = iHitBand;
3226 return 0;
3230 static inline LRESULT
3231 REBAR_NCCalcSize (const REBAR_INFO *infoPtr, RECT *rect)
3233 HTHEME theme;
3235 if (infoPtr->dwStyle & WS_BORDER) {
3236 rect->left = min(rect->left + GetSystemMetrics(SM_CXEDGE), rect->right);
3237 rect->right = max(rect->right - GetSystemMetrics(SM_CXEDGE), rect->left);
3238 rect->top = min(rect->top + GetSystemMetrics(SM_CYEDGE), rect->bottom);
3239 rect->bottom = max(rect->bottom - GetSystemMetrics(SM_CYEDGE), rect->top);
3241 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3243 /* FIXME: should use GetThemeInt */
3244 rect->top = min(rect->top + 1, rect->bottom);
3246 TRACE("new client=(%s)\n", wine_dbgstr_rect(rect));
3247 return 0;
3251 static LRESULT
3252 REBAR_NCCreate (HWND hwnd, const CREATESTRUCTW *cs)
3254 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3255 RECT wnrc1, clrc1;
3256 NONCLIENTMETRICSW ncm;
3257 HFONT tfont;
3259 if (infoPtr) {
3260 ERR("Strange info structure pointer *not* NULL\n");
3261 return FALSE;
3264 if (TRACE_ON(rebar)) {
3265 GetWindowRect(hwnd, &wnrc1);
3266 GetClientRect(hwnd, &clrc1);
3267 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
3268 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
3269 cs->x, cs->y, cs->cx, cs->cy);
3272 /* allocate memory for info structure */
3273 infoPtr = Alloc (sizeof(REBAR_INFO));
3274 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
3276 /* initialize info structure - initial values are 0 */
3277 infoPtr->clrBk = CLR_NONE;
3278 infoPtr->clrText = CLR_NONE;
3279 infoPtr->clrBtnText = comctl32_color.clrBtnText;
3280 infoPtr->clrBtnFace = comctl32_color.clrBtnFace;
3281 infoPtr->iOldBand = -1;
3282 infoPtr->ichevronhotBand = -2;
3283 infoPtr->iGrabbedBand = -1;
3284 infoPtr->hwndSelf = hwnd;
3285 infoPtr->DoRedraw = TRUE;
3286 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3287 infoPtr->hcurHorz = LoadCursorW (0, (LPWSTR)IDC_SIZEWE);
3288 infoPtr->hcurVert = LoadCursorW (0, (LPWSTR)IDC_SIZENS);
3289 infoPtr->hcurDrag = LoadCursorW (0, (LPWSTR)IDC_SIZE);
3290 infoPtr->fStatus = 0;
3291 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3292 infoPtr->bands = DPA_Create(8);
3294 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3295 REBAR_NotifyFormat(infoPtr, NF_REQUERY);
3297 /* Stow away the original style */
3298 infoPtr->orgStyle = cs->style;
3299 /* add necessary styles to the requested styles */
3300 infoPtr->dwStyle = cs->style | WS_VISIBLE;
3301 if ((infoPtr->dwStyle & CCS_LAYOUT_MASK) == 0)
3302 infoPtr->dwStyle |= CCS_TOP;
3303 SetWindowLongW (hwnd, GWL_STYLE, infoPtr->dwStyle);
3305 /* get font handle for Caption Font */
3306 ncm.cbSize = sizeof(ncm);
3307 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
3308 /* if the font is bold, set to normal */
3309 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3310 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3312 tfont = CreateFontIndirectW (&ncm.lfCaptionFont);
3313 if (tfont) {
3314 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3317 /* native does:
3318 GetSysColor (numerous);
3319 GetSysColorBrush (numerous) (see WM_SYSCOLORCHANGE);
3320 *GetStockObject (SYSTEM_FONT);
3321 *SetWindowLong (hwnd, 0, info ptr);
3322 *WM_NOTIFYFORMAT;
3323 *SetWindowLong (hwnd, GWL_STYLE, style+0x10000001);
3324 WS_VISIBLE = 0x10000000;
3325 CCS_TOP = 0x00000001;
3326 *SystemParametersInfo (SPI_GETNONCLIENTMETRICS...);
3327 *CreateFontIndirect (lfCaptionFont from above);
3328 GetDC ();
3329 SelectObject (hdc, fontabove);
3330 GetTextMetrics (hdc, ); guessing is tmHeight
3331 SelectObject (hdc, oldfont);
3332 ReleaseDC ();
3333 GetWindowRect ();
3334 MapWindowPoints (0, parent, rectabove, 2);
3335 GetWindowRect ();
3336 GetClientRect ();
3337 ClientToScreen (clientrect);
3338 SetWindowPos (hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER);
3340 return TRUE;
3344 static LRESULT
3345 REBAR_NCHitTest (const REBAR_INFO *infoPtr, LPARAM lParam)
3347 NMMOUSE nmmouse;
3348 POINT clpt;
3349 INT i;
3350 UINT scrap;
3351 LRESULT ret = HTCLIENT;
3354 * Differences from doc at MSDN (as observed with version 4.71 of
3355 * comctl32.dll
3356 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3357 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3358 * 3. native always seems to return HTCLIENT if notify return is 0.
3361 clpt.x = (short)LOWORD(lParam);
3362 clpt.y = (short)HIWORD(lParam);
3363 ScreenToClient (infoPtr->hwndSelf, &clpt);
3364 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3365 (INT *)&nmmouse.dwItemSpec);
3366 nmmouse.dwItemData = 0;
3367 nmmouse.pt = clpt;
3368 nmmouse.dwHitInfo = 0;
3369 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3370 TRACE("notify changed return value from %ld to %d\n",
3371 ret, i);
3372 ret = (LRESULT) i;
3374 TRACE("returning %ld, client point (%d,%d)\n", ret, clpt.x, clpt.y);
3375 return ret;
3379 static LRESULT
3380 REBAR_NCPaint (const REBAR_INFO *infoPtr)
3382 RECT rcWindow;
3383 HDC hdc;
3384 HTHEME theme;
3386 if (infoPtr->dwStyle & WS_MINIMIZE)
3387 return 0; /* Nothing to do */
3389 if (infoPtr->dwStyle & WS_BORDER) {
3391 /* adjust rectangle and draw the necessary edge */
3392 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3393 return 0;
3394 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3395 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3396 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3397 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3398 ReleaseDC( infoPtr->hwndSelf, hdc );
3400 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3402 /* adjust rectangle and draw the necessary edge */
3403 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3404 return 0;
3405 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3406 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3407 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3408 DrawThemeEdge (theme, hdc, 0, 0, &rcWindow, BDR_RAISEDINNER, BF_TOP, NULL);
3409 ReleaseDC( infoPtr->hwndSelf, hdc );
3412 return 0;
3416 static LRESULT
3417 REBAR_NotifyFormat (REBAR_INFO *infoPtr, LPARAM cmd)
3419 INT i;
3421 if (cmd == NF_REQUERY) {
3422 i = SendMessageW(REBAR_GetNotifyParent (infoPtr),
3423 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
3424 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
3425 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
3426 i = NFR_ANSI;
3428 infoPtr->bUnicode = (i == NFR_UNICODE) ? 1 : 0;
3429 return (LRESULT)i;
3431 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3435 static LRESULT
3436 REBAR_Paint (const REBAR_INFO *infoPtr, HDC hdc)
3438 if (hdc) {
3439 TRACE("painting\n");
3440 REBAR_Refresh (infoPtr, hdc);
3441 } else {
3442 PAINTSTRUCT ps;
3443 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
3444 TRACE("painting (%s)\n", wine_dbgstr_rect(&ps.rcPaint));
3445 if (ps.fErase) {
3446 /* Erase area of paint if requested */
3447 REBAR_EraseBkGnd (infoPtr, hdc);
3449 REBAR_Refresh (infoPtr, hdc);
3450 EndPaint (infoPtr->hwndSelf, &ps);
3453 return 0;
3457 static LRESULT
3458 REBAR_SetCursor (const REBAR_INFO *infoPtr, LPARAM lParam)
3460 POINT pt;
3461 UINT flags;
3463 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
3465 GetCursorPos (&pt);
3466 ScreenToClient (infoPtr->hwndSelf, &pt);
3468 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
3470 if (flags == RBHT_GRABBER) {
3471 if ((infoPtr->dwStyle & CCS_VERT) &&
3472 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
3473 SetCursor (infoPtr->hcurVert);
3474 else
3475 SetCursor (infoPtr->hcurHorz);
3477 else if (flags != RBHT_CLIENT)
3478 SetCursor (infoPtr->hcurArrow);
3480 return 0;
3484 static LRESULT
3485 REBAR_SetFont (REBAR_INFO *infoPtr, HFONT font)
3487 REBAR_BAND *lpBand;
3488 UINT i;
3490 infoPtr->hFont = font;
3492 /* revalidate all bands to change sizes of text in headers of bands */
3493 for (i=0; i<infoPtr->uNumBands; i++) {
3494 lpBand = REBAR_GetBand(infoPtr, i);
3495 REBAR_ValidateBand (infoPtr, lpBand);
3498 REBAR_Layout(infoPtr);
3499 return 0;
3503 /*****************************************************
3505 * Handles the WM_SETREDRAW message.
3507 * Documentation:
3508 * According to testing V4.71 of COMCTL32 returns the
3509 * *previous* status of the redraw flag (either 0 or -1)
3510 * instead of the MSDN documented value of 0 if handled
3512 *****************************************************/
3513 static inline LRESULT
3514 REBAR_SetRedraw (REBAR_INFO *infoPtr, BOOL redraw)
3516 BOOL oldredraw = infoPtr->DoRedraw;
3518 TRACE("set to %s, fStatus=%08x\n",
3519 (redraw) ? "TRUE" : "FALSE", infoPtr->fStatus);
3520 infoPtr->DoRedraw = redraw;
3521 if (redraw) {
3522 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
3523 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
3524 REBAR_ForceResize (infoPtr);
3525 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3527 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
3529 return (oldredraw) ? -1 : 0;
3533 static LRESULT
3534 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3536 TRACE("wParam=%lx, lParam=%lx\n", wParam, lParam);
3538 /* avoid _Layout resize recursion (but it shouldn't be infinite and it seems Windows does recurse) */
3539 if (infoPtr->fStatus & SELF_RESIZE) {
3540 infoPtr->fStatus &= ~SELF_RESIZE;
3541 TRACE("SELF_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
3542 infoPtr->fStatus, lParam);
3543 return 0;
3546 if (infoPtr->dwStyle & RBS_AUTOSIZE)
3547 REBAR_AutoSize(infoPtr, TRUE);
3548 else
3549 REBAR_Layout(infoPtr);
3551 return 0;
3555 static LRESULT
3556 REBAR_StyleChanged (REBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
3558 TRACE("current style=%08x, styleOld=%08x, style being set to=%08x\n",
3559 infoPtr->dwStyle, lpStyle->styleOld, lpStyle->styleNew);
3560 if (nType == GWL_STYLE)
3562 infoPtr->orgStyle = infoPtr->dwStyle = lpStyle->styleNew;
3563 if (GetWindowTheme (infoPtr->hwndSelf))
3564 infoPtr->dwStyle &= ~WS_BORDER;
3565 /* maybe it should be COMMON_STYLES like in toolbar */
3566 if ((lpStyle->styleNew ^ lpStyle->styleOld) & CCS_VERT)
3567 REBAR_Layout(infoPtr);
3569 return FALSE;
3572 /* update theme after a WM_THEMECHANGED message */
3573 static LRESULT theme_changed (REBAR_INFO* infoPtr)
3575 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
3576 CloseThemeData (theme);
3577 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
3578 /* WS_BORDER disappears when theming is enabled and reappears when
3579 * disabled... */
3580 infoPtr->dwStyle &= ~WS_BORDER;
3581 infoPtr->dwStyle |= theme ? 0 : (infoPtr->orgStyle & WS_BORDER);
3582 return 0;
3585 static LRESULT
3586 REBAR_WindowPosChanged (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3588 LRESULT ret;
3589 RECT rc;
3591 ret = DefWindowProcW(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
3592 wParam, lParam);
3593 GetWindowRect(infoPtr->hwndSelf, &rc);
3594 TRACE("hwnd %p new pos (%s)\n", infoPtr->hwndSelf, wine_dbgstr_rect(&rc));
3595 return ret;
3599 static LRESULT WINAPI
3600 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3602 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3604 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
3605 hwnd, uMsg, wParam, lParam);
3606 if (!infoPtr && (uMsg != WM_NCCREATE))
3607 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3608 switch (uMsg)
3610 /* case RB_BEGINDRAG: */
3612 case RB_DELETEBAND:
3613 return REBAR_DeleteBand (infoPtr, wParam);
3615 /* case RB_DRAGMOVE: */
3616 /* case RB_ENDDRAG: */
3618 case RB_GETBANDBORDERS:
3619 return REBAR_GetBandBorders (infoPtr, wParam, (LPRECT)lParam);
3621 case RB_GETBANDCOUNT:
3622 return REBAR_GetBandCount (infoPtr);
3624 case RB_GETBANDINFO_OLD:
3625 case RB_GETBANDINFOA:
3626 case RB_GETBANDINFOW:
3627 return REBAR_GetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3628 uMsg == RB_GETBANDINFOW);
3629 case RB_GETBARHEIGHT:
3630 return REBAR_GetBarHeight (infoPtr);
3632 case RB_GETBARINFO:
3633 return REBAR_GetBarInfo (infoPtr, (LPREBARINFO)lParam);
3635 case RB_GETBKCOLOR:
3636 return REBAR_GetBkColor (infoPtr);
3638 /* case RB_GETCOLORSCHEME: */
3639 /* case RB_GETDROPTARGET: */
3641 case RB_GETPALETTE:
3642 return REBAR_GetPalette (infoPtr);
3644 case RB_GETRECT:
3645 return REBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
3647 case RB_GETROWCOUNT:
3648 return REBAR_GetRowCount (infoPtr);
3650 case RB_GETROWHEIGHT:
3651 return REBAR_GetRowHeight (infoPtr, wParam);
3653 case RB_GETTEXTCOLOR:
3654 return REBAR_GetTextColor (infoPtr);
3656 case RB_GETTOOLTIPS:
3657 return REBAR_GetToolTips (infoPtr);
3659 case RB_GETUNICODEFORMAT:
3660 return REBAR_GetUnicodeFormat (infoPtr);
3662 case CCM_GETVERSION:
3663 return REBAR_GetVersion (infoPtr);
3665 case RB_HITTEST:
3666 return REBAR_HitTest (infoPtr, (LPRBHITTESTINFO)lParam);
3668 case RB_IDTOINDEX:
3669 return REBAR_IdToIndex (infoPtr, wParam);
3671 case RB_INSERTBANDA:
3672 case RB_INSERTBANDW:
3673 return REBAR_InsertBandT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3674 uMsg == RB_INSERTBANDW);
3675 case RB_MAXIMIZEBAND:
3676 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
3678 case RB_MINIMIZEBAND:
3679 return REBAR_MinimizeBand (infoPtr, wParam);
3681 case RB_MOVEBAND:
3682 return REBAR_MoveBand (infoPtr, wParam, lParam);
3684 case RB_PUSHCHEVRON:
3685 return REBAR_PushChevron (infoPtr, wParam, lParam);
3687 case RB_SETBANDINFOA:
3688 case RB_SETBANDINFOW:
3689 return REBAR_SetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3690 uMsg == RB_SETBANDINFOW);
3691 case RB_SETBARINFO:
3692 return REBAR_SetBarInfo (infoPtr, (LPREBARINFO)lParam);
3694 case RB_SETBKCOLOR:
3695 return REBAR_SetBkColor (infoPtr, lParam);
3697 /* case RB_SETCOLORSCHEME: */
3698 /* case RB_SETPALETTE: */
3700 case RB_SETPARENT:
3701 return REBAR_SetParent (infoPtr, (HWND)wParam);
3703 case RB_SETTEXTCOLOR:
3704 return REBAR_SetTextColor (infoPtr, lParam);
3706 /* case RB_SETTOOLTIPS: */
3708 case RB_SETUNICODEFORMAT:
3709 return REBAR_SetUnicodeFormat (infoPtr, wParam);
3711 case CCM_SETVERSION:
3712 return REBAR_SetVersion (infoPtr, (INT)wParam);
3714 case RB_SHOWBAND:
3715 return REBAR_ShowBand (infoPtr, wParam, lParam);
3717 case RB_SIZETORECT:
3718 return REBAR_SizeToRect (infoPtr, (LPCRECT)lParam);
3721 /* Messages passed to parent */
3722 case WM_COMMAND:
3723 case WM_DRAWITEM:
3724 case WM_NOTIFY:
3725 case WM_MEASUREITEM:
3726 return SendMessageW(REBAR_GetNotifyParent (infoPtr), uMsg, wParam, lParam);
3729 /* case WM_CHARTOITEM: supported according to ControlSpy */
3731 case WM_CREATE:
3732 return REBAR_Create (infoPtr, (LPCREATESTRUCTW)lParam);
3734 case WM_DESTROY:
3735 return REBAR_Destroy (infoPtr);
3737 case WM_ERASEBKGND:
3738 return REBAR_EraseBkGnd (infoPtr, (HDC)wParam);
3740 case WM_GETFONT:
3741 return REBAR_GetFont (infoPtr);
3743 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
3745 case WM_LBUTTONDOWN:
3746 return REBAR_LButtonDown (infoPtr, lParam);
3748 case WM_LBUTTONUP:
3749 return REBAR_LButtonUp (infoPtr);
3751 case WM_MOUSEMOVE:
3752 return REBAR_MouseMove (infoPtr, lParam);
3754 case WM_MOUSELEAVE:
3755 return REBAR_MouseLeave (infoPtr);
3757 case WM_NCCALCSIZE:
3758 return REBAR_NCCalcSize (infoPtr, (RECT*)lParam);
3760 case WM_NCCREATE:
3761 return REBAR_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
3763 case WM_NCHITTEST:
3764 return REBAR_NCHitTest (infoPtr, lParam);
3766 case WM_NCPAINT:
3767 return REBAR_NCPaint (infoPtr);
3769 case WM_NOTIFYFORMAT:
3770 return REBAR_NotifyFormat (infoPtr, lParam);
3772 case WM_PRINTCLIENT:
3773 case WM_PAINT:
3774 return REBAR_Paint (infoPtr, (HDC)wParam);
3776 /* case WM_PALETTECHANGED: supported according to ControlSpy */
3777 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
3778 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
3779 /* case WM_RBUTTONUP: supported according to ControlSpy */
3781 case WM_SETCURSOR:
3782 return REBAR_SetCursor (infoPtr, lParam);
3784 case WM_SETFONT:
3785 return REBAR_SetFont (infoPtr, (HFONT)wParam);
3787 case WM_SETREDRAW:
3788 return REBAR_SetRedraw (infoPtr, wParam);
3790 case WM_SIZE:
3791 return REBAR_Size (infoPtr, wParam, lParam);
3793 case WM_STYLECHANGED:
3794 return REBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
3796 case WM_THEMECHANGED:
3797 return theme_changed (infoPtr);
3799 case WM_SYSCOLORCHANGE:
3800 COMCTL32_RefreshSysColors();
3801 return 0;
3803 /* case WM_VKEYTOITEM: supported according to ControlSpy */
3804 /* case WM_WININICHANGE: */
3806 case WM_WINDOWPOSCHANGED:
3807 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
3809 default:
3810 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
3811 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
3812 uMsg, wParam, lParam);
3813 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3818 VOID
3819 REBAR_Register (void)
3821 WNDCLASSW wndClass;
3823 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
3824 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
3825 wndClass.lpfnWndProc = REBAR_WindowProc;
3826 wndClass.cbClsExtra = 0;
3827 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
3828 wndClass.hCursor = 0;
3829 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
3830 #if GLATESTING
3831 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
3832 #endif
3833 wndClass.lpszClassName = REBARCLASSNAMEW;
3835 RegisterClassW (&wndClass);
3837 mindragx = GetSystemMetrics (SM_CXDRAG);
3838 mindragy = GetSystemMetrics (SM_CYDRAG);
3843 VOID
3844 REBAR_Unregister (void)
3846 UnregisterClassW (REBARCLASSNAMEW, NULL);