kernel32/tests: Add more partial DBCS character tests that contains a null character.
[wine.git] / dlls / comctl32 / rebar.c
blobde8155aa43bdc51dbbbf03aba54499a8d57313d0
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 lpBand->fDraw &= ~NTF_INVALIDATE;
810 work = lpBand->rcBand;
811 work.right += SEP_WIDTH;
812 work.bottom += SEP_WIDTH;
813 TRACE("invalidating %s\n", wine_dbgstr_rect(&work));
814 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
815 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
823 static VOID
824 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
825 /* Function: this routine initializes all the rectangles in */
826 /* each band in a row to fit in the adjusted rcBand rect. */
827 /* *** Supports only Vertical bars. *** */
829 REBAR_BAND *lpBand;
830 UINT i, xoff;
831 RECT work;
833 for(i=rstart; i<rend; i++){
834 RECT rcBand;
835 lpBand = REBAR_GetBand(infoPtr, i);
836 if (HIDDENBAND(lpBand)) continue;
838 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
840 /* set initial gripper rectangle */
841 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
843 /* calculate gripper rectangle */
844 if (lpBand->fStatus & HAS_GRIPPER) {
845 lpBand->fDraw |= DRAW_GRIPPER;
847 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
848 /* vertical gripper */
849 lpBand->rcGripper.left += 3;
850 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
851 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
852 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
854 /* initialize Caption image rectangle */
855 SetRect (&lpBand->rcCapImage, rcBand.left,
856 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
857 rcBand.right,
858 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
860 else {
861 /* horizontal gripper */
862 lpBand->rcGripper.left += 2;
863 lpBand->rcGripper.right -= 2;
864 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
865 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
867 /* initialize Caption image rectangle */
868 SetRect (&lpBand->rcCapImage, rcBand.left,
869 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
870 rcBand.right,
871 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
874 else { /* no gripper will be drawn */
875 xoff = 0;
876 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
877 /* if no gripper but either image or text, then leave space */
878 xoff = REBAR_ALWAYS_SPACE;
879 /* initialize Caption image rectangle */
880 SetRect (&lpBand->rcCapImage,
881 rcBand.left, rcBand.top+xoff,
882 rcBand.right, rcBand.top+xoff);
885 /* image is visible */
886 if (lpBand->fStatus & HAS_IMAGE) {
887 lpBand->fDraw |= DRAW_IMAGE;
889 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
890 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
892 /* set initial caption text rectangle */
893 SetRect (&lpBand->rcCapText,
894 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
895 rcBand.right, rcBand.top+lpBand->cxHeader);
897 else {
898 /* set initial caption text rectangle */
899 SetRect (&lpBand->rcCapText,
900 rcBand.left, lpBand->rcCapImage.bottom,
901 rcBand.right, rcBand.top+lpBand->cxHeader);
904 /* text is visible */
905 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
906 lpBand->fDraw |= DRAW_TEXT;
907 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
908 lpBand->rcCapText.bottom);
911 /* set initial child window rectangle if there is a child */
912 if (lpBand->hwndChild) {
913 int cxBand = rcBand.right - rcBand.left;
914 xoff = (cxBand - lpBand->cyChild) / 2;
915 SetRect (&lpBand->rcChild,
916 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
917 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
919 else {
920 SetRect (&lpBand->rcChild,
921 rcBand.left, rcBand.top+lpBand->cxHeader,
922 rcBand.right, rcBand.bottom);
925 if (lpBand->fDraw & NTF_INVALIDATE) {
926 lpBand->fDraw &= ~NTF_INVALIDATE;
927 work = rcBand;
928 work.bottom += SEP_WIDTH;
929 work.right += SEP_WIDTH;
930 TRACE("invalidating %s\n", wine_dbgstr_rect(&work));
931 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
932 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
939 static VOID
940 REBAR_ForceResize (REBAR_INFO *infoPtr)
941 /* Function: This changes the size of the REBAR window to that */
942 /* calculated by REBAR_Layout. */
944 INT x, y, width, height;
945 INT xedge = 0, yedge = 0;
946 RECT rcSelf;
948 TRACE("new size [%d x %d]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
950 if (infoPtr->dwStyle & CCS_NORESIZE)
951 return;
953 if (infoPtr->dwStyle & WS_BORDER)
955 xedge = GetSystemMetrics(SM_CXEDGE);
956 yedge = GetSystemMetrics(SM_CYEDGE);
957 /* swap for CCS_VERT? */
960 /* compute rebar window rect in parent client coordinates */
961 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
962 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
963 translate_rect(infoPtr, &rcSelf, &rcSelf);
965 height = infoPtr->calcSize.cy + 2*yedge;
966 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
967 RECT rcParent;
969 x = -xedge;
970 width = infoPtr->calcSize.cx + 2*xedge;
971 y = 0; /* quiet compiler warning */
972 switch ( infoPtr->dwStyle & CCS_LAYOUT_MASK) {
973 case 0: /* shouldn't happen - see NCCreate */
974 case CCS_TOP:
975 y = ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER) - yedge;
976 break;
977 case CCS_NOMOVEY:
978 y = rcSelf.top;
979 break;
980 case CCS_BOTTOM:
981 GetClientRect(GetParent(infoPtr->hwndSelf), &rcParent);
982 translate_rect(infoPtr, &rcParent, &rcParent);
983 y = rcParent.bottom - infoPtr->calcSize.cy - yedge;
984 break;
987 else {
988 x = rcSelf.left;
989 /* As on Windows if the CCS_NODIVIDER is not present the control will move
990 * 2 pixel down after every layout */
991 y = rcSelf.top + ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
992 width = rcSelf.right - rcSelf.left;
995 TRACE("hwnd %p, style=%08x, setting at (%d,%d) for (%d,%d)\n",
996 infoPtr->hwndSelf, infoPtr->dwStyle, x, y, width, height);
998 /* Set flag to ignore next WM_SIZE message and resize the window */
999 infoPtr->fStatus |= SELF_RESIZE;
1000 if ((infoPtr->dwStyle & CCS_VERT) == 0)
1001 SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
1002 else
1003 SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
1004 infoPtr->fStatus &= ~SELF_RESIZE;
1008 static VOID
1009 REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
1011 static const WCHAR strComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
1012 REBAR_BAND *lpBand;
1013 WCHAR szClassName[40];
1014 UINT i;
1015 NMREBARCHILDSIZE rbcz;
1016 HDWP deferpos;
1018 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1019 ERR("BeginDeferWindowPos returned NULL\n");
1021 for (i = start; i < endplus; i++) {
1022 lpBand = REBAR_GetBand(infoPtr, i);
1024 if (HIDDENBAND(lpBand)) continue;
1025 if (lpBand->hwndChild) {
1026 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1028 /* Always generate the RBN_CHILDSIZE even if child
1029 did not change */
1030 rbcz.uBand = i;
1031 rbcz.wID = lpBand->wID;
1032 rbcz.rcChild = lpBand->rcChild;
1033 translate_rect(infoPtr, &rbcz.rcBand, &lpBand->rcBand);
1034 if (infoPtr->dwStyle & CCS_VERT)
1035 rbcz.rcBand.top += lpBand->cxHeader;
1036 else
1037 rbcz.rcBand.left += lpBand->cxHeader;
1038 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1039 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1040 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1041 TRACE(" from (%s) to (%s)\n",
1042 wine_dbgstr_rect(&lpBand->rcChild),
1043 wine_dbgstr_rect(&rbcz.rcChild));
1044 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1047 GetClassNameW (lpBand->hwndChild, szClassName, sizeof(szClassName)/sizeof(szClassName[0]));
1048 if (!lstrcmpW (szClassName, strComboBox) ||
1049 !lstrcmpW (szClassName, WC_COMBOBOXEXW)) {
1050 INT nEditHeight, yPos;
1051 RECT rc;
1053 /* special placement code for combo or comboex box */
1056 /* get size of edit line */
1057 GetWindowRect (lpBand->hwndChild, &rc);
1058 nEditHeight = rc.bottom - rc.top;
1059 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1061 /* center combo box inside child area */
1062 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1063 lpBand->hwndChild,
1064 lpBand->rcChild.left, yPos,
1065 lpBand->rcChild.right - lpBand->rcChild.left,
1066 nEditHeight);
1067 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1068 lpBand->rcChild.left,
1069 /*lpBand->rcChild.top*/ yPos,
1070 lpBand->rcChild.right - lpBand->rcChild.left,
1071 nEditHeight,
1072 SWP_NOZORDER);
1073 if (!deferpos)
1074 ERR("DeferWindowPos returned NULL\n");
1076 else {
1077 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1078 lpBand->hwndChild,
1079 lpBand->rcChild.left, lpBand->rcChild.top,
1080 lpBand->rcChild.right - lpBand->rcChild.left,
1081 lpBand->rcChild.bottom - lpBand->rcChild.top);
1082 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1083 lpBand->rcChild.left,
1084 lpBand->rcChild.top,
1085 lpBand->rcChild.right - lpBand->rcChild.left,
1086 lpBand->rcChild.bottom - lpBand->rcChild.top,
1087 SWP_NOZORDER);
1088 if (!deferpos)
1089 ERR("DeferWindowPos returned NULL\n");
1093 if (!EndDeferWindowPos(deferpos))
1094 ERR("EndDeferWindowPos returned NULL\n");
1096 if (infoPtr->DoRedraw)
1097 UpdateWindow (infoPtr->hwndSelf);
1100 /* Returns the next visible band (the first visible band in [i+1; infoPtr->uNumBands) )
1101 * or infoPtr->uNumBands if none */
1102 static int next_visible(const REBAR_INFO *infoPtr, int i)
1104 unsigned int n;
1105 for (n = i + 1; n < infoPtr->uNumBands; n++)
1106 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1107 break;
1108 return n;
1111 /* Returns the previous visible band (the last visible band in [0; i) )
1112 * or -1 if none */
1113 static int prev_visible(const REBAR_INFO *infoPtr, int i)
1115 int n;
1116 for (n = i - 1; n >= 0; n--)
1117 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1118 break;
1119 return n;
1122 /* Returns the first visible band or infoPtr->uNumBands if none */
1123 static int first_visible(const REBAR_INFO *infoPtr)
1125 return next_visible(infoPtr, -1); /* this works*/
1128 /* Returns the first visible band for the given row (or iBand if none) */
1129 static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
1131 int iLastBand = iBand;
1132 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1133 while ((iBand = prev_visible(infoPtr, iBand)) >= 0) {
1134 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1135 break;
1136 else
1137 iLastBand = iBand;
1139 return iLastBand;
1142 /* Returns the first visible band for the next row (or infoPtr->uNumBands if none) */
1143 static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
1145 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1146 while ((iBand = next_visible(infoPtr, iBand)) < infoPtr->uNumBands)
1147 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1148 break;
1149 return iBand;
1152 /* Compute the rcBand.{left,right} from the cxEffective bands widths computed earlier.
1153 * iBeginBand must be visible */
1154 static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1156 int xPos = 0, i;
1157 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1159 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1160 if (lpBand->rcBand.left != xPos || lpBand->rcBand.right != xPos + lpBand->cxEffective) {
1161 lpBand->fDraw |= NTF_INVALIDATE;
1162 TRACE("Setting rect %d to %d,%d\n", i, xPos, xPos + lpBand->cxEffective);
1163 lpBand->rcBand.left = xPos;
1164 lpBand->rcBand.right = xPos + lpBand->cxEffective;
1166 xPos += lpBand->cxEffective + SEP_WIDTH;
1170 /* The rationale of this function is probably as follows: if we have some space
1171 * to distribute we want to add it to a band on the right. However we don't want
1172 * to unminimize a minimized band so we search for a band that is big enough.
1173 * For some reason "big enough" is defined as bigger than the minimum size of the
1174 * first band in the row
1176 static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1178 INT cxMinFirstBand = 0, i;
1180 cxMinFirstBand = REBAR_GetBand(infoPtr, iBeginBand)->cxMinBand;
1182 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1183 if (REBAR_GetBand(infoPtr, i)->cxEffective > cxMinFirstBand &&
1184 !(REBAR_GetBand(infoPtr, i)->fStyle & RBBS_FIXEDSIZE))
1185 break;
1187 if (i < iBeginBand)
1188 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1189 if (REBAR_GetBand(infoPtr, i)->cxMinBand == cxMinFirstBand)
1190 break;
1192 TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
1193 return REBAR_GetBand(infoPtr, i);
1196 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the right */
1197 static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1199 REBAR_BAND *lpBand;
1200 INT width, i;
1202 TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
1203 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1205 lpBand = REBAR_GetBand(infoPtr, i);
1207 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1208 cxShrink -= lpBand->cxEffective - width;
1209 lpBand->cxEffective = width;
1210 if (bEnforce && lpBand->cx > lpBand->cxEffective)
1211 lpBand->cx = lpBand->cxEffective;
1212 if (cxShrink == 0)
1213 break;
1215 return cxShrink;
1219 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the left.
1220 * iBeginBand must be visible */
1221 static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1223 REBAR_BAND *lpBand;
1224 INT width, i;
1226 TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
1227 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1229 lpBand = REBAR_GetBand(infoPtr, i);
1231 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1232 cxShrink -= lpBand->cxEffective - width;
1233 lpBand->cxEffective = width;
1234 if (bEnforce)
1235 lpBand->cx = lpBand->cxEffective;
1236 if (cxShrink == 0)
1237 break;
1239 return cxShrink;
1242 /* Tries to move a band to a given offset within a row. */
1243 static int REBAR_MoveBandToRowOffset(REBAR_INFO *infoPtr, INT iBand, INT iFirstBand,
1244 INT iLastBand, INT xOff, BOOL reorder)
1246 REBAR_BAND *insertBand = REBAR_GetBand(infoPtr, iBand);
1247 int xPos = 0, i;
1248 const BOOL setBreak = REBAR_GetBand(infoPtr, iFirstBand)->fStyle & RBBS_BREAK;
1250 /* Find the band's new position */
1251 if(reorder)
1253 /* Used during an LR band reorder drag */
1254 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1256 if(xPos > xOff)
1257 break;
1258 xPos += REBAR_GetBand(infoPtr, i)->cxEffective + SEP_WIDTH;
1261 else
1263 /* Used during a UD band insertion drag */
1264 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1266 const REBAR_BAND *band = REBAR_GetBand(infoPtr, i);
1267 if(xPos + band->cxMinBand / 2 > xOff)
1268 break;
1269 xPos += band->cxEffective + SEP_WIDTH;
1273 /* Move the band to its new position */
1274 DPA_DeletePtr(infoPtr->bands, iBand);
1275 if(i > iBand)
1276 i--;
1277 DPA_InsertPtr(infoPtr->bands, i, insertBand);
1279 /* Ensure only the last band has the RBBS_BREAK flag set */
1280 insertBand->fStyle &= ~RBBS_BREAK;
1281 if(setBreak)
1282 REBAR_GetBand(infoPtr, iFirstBand)->fStyle |= RBBS_BREAK;
1284 /* Return the currently grabbed band */
1285 if(infoPtr->iGrabbedBand == iBand)
1287 infoPtr->iGrabbedBand = i;
1288 return i;
1290 else return -1;
1293 /* Set the heights of the visible bands in [iBeginBand; iEndBand) to the max height. iBeginBand must be visible */
1294 static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
1296 REBAR_BAND *lpBand;
1297 int yMaxHeight = 0;
1298 int yPos = yStart;
1299 int row = REBAR_GetBand(infoPtr, iBeginBand)->iRow;
1300 int i;
1301 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1303 lpBand = REBAR_GetBand(infoPtr, i);
1304 lpBand->cyRowSoFar = yMaxHeight;
1305 yMaxHeight = max(yMaxHeight, lpBand->cyMinBand);
1307 TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
1309 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1311 lpBand = REBAR_GetBand(infoPtr, i);
1312 /* we may be called for multiple rows if RBS_VARHEIGHT not set */
1313 if (lpBand->iRow != row) {
1314 yPos += yMaxHeight + SEP_WIDTH;
1315 row = lpBand->iRow;
1318 if (lpBand->rcBand.top != yPos || lpBand->rcBand.bottom != yPos + yMaxHeight) {
1319 lpBand->fDraw |= NTF_INVALIDATE;
1320 lpBand->rcBand.top = yPos;
1321 lpBand->rcBand.bottom = yPos + yMaxHeight;
1322 TRACE("Band %d: %s\n", i, wine_dbgstr_rect(&lpBand->rcBand));
1325 return yPos + yMaxHeight;
1328 /* Layout the row [iBeginBand; iEndBand). iBeginBand must be visible */
1329 static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
1331 REBAR_BAND *lpBand;
1332 int i, extra;
1333 int width = 0;
1335 TRACE("Adjusting row [%d;%d). Width: %d\n", iBeginBand, iEndBand, cx);
1336 for (i = iBeginBand; i < iEndBand; i++)
1337 REBAR_GetBand(infoPtr, i)->iRow = *piRow;
1339 /* compute the extra space */
1340 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1342 lpBand = REBAR_GetBand(infoPtr, i);
1343 if (i > iBeginBand)
1344 width += SEP_WIDTH;
1345 lpBand->cxEffective = max(lpBand->cxMinBand, lpBand->cx);
1346 width += lpBand->cxEffective;
1349 extra = cx - width;
1350 TRACE("Extra space: %d\n", extra);
1351 if (extra < 0) {
1352 int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
1353 if (ret > 0 && next_visible(infoPtr, iBeginBand) != iEndBand) /* one band may be longer than expected... */
1354 ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
1355 } else
1356 if (extra > 0) {
1357 lpBand = REBAR_FindBandToGrow(infoPtr, iBeginBand, iEndBand);
1358 lpBand->cxEffective += extra;
1361 REBAR_SetRowRectsX(infoPtr, iBeginBand, iEndBand);
1362 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1364 if (*piRow > 0)
1365 *pyPos += SEP_WIDTH;
1366 *pyPos = REBAR_SetBandsHeight(infoPtr, iBeginBand, iEndBand, *pyPos);
1368 (*piRow)++;
1371 static VOID
1372 REBAR_Layout(REBAR_INFO *infoPtr)
1374 REBAR_BAND *lpBand;
1375 RECT rcAdj;
1376 SIZE oldSize;
1377 INT adjcx, i;
1378 INT rowstart;
1379 INT row = 0;
1380 INT xMin, yPos;
1382 if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
1383 GetClientRect(infoPtr->hwndSelf, &rcAdj);
1384 else
1385 GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
1386 TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
1388 adjcx = get_rect_cx(infoPtr, &rcAdj);
1390 if (infoPtr->uNumBands == 0) {
1391 TRACE("No bands - setting size to (0,%d), style: %x\n", adjcx, infoPtr->dwStyle);
1392 infoPtr->calcSize.cx = adjcx;
1393 /* the calcSize.cy won't change for a 0 band rebar */
1394 infoPtr->uNumRows = 0;
1395 REBAR_ForceResize(infoPtr);
1396 return;
1399 yPos = 0;
1400 xMin = 0;
1401 rowstart = first_visible(infoPtr);
1402 /* divide rows */
1403 for (i = rowstart; i < infoPtr->uNumBands; i = next_visible(infoPtr, i))
1405 lpBand = REBAR_GetBand(infoPtr, i);
1407 if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->cxMinBand > adjcx)) {
1408 TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
1409 REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
1410 rowstart = i;
1411 xMin = 0;
1413 else
1414 xMin += SEP_WIDTH;
1416 xMin += lpBand->cxMinBand;
1418 if (rowstart < infoPtr->uNumBands)
1419 REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
1421 if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
1422 yPos = REBAR_SetBandsHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, 0);
1424 infoPtr->uNumRows = row;
1426 if (infoPtr->dwStyle & CCS_VERT)
1427 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1428 else
1429 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1430 /* now compute size of Rebar itself */
1431 oldSize = infoPtr->calcSize;
1433 infoPtr->calcSize.cx = adjcx;
1434 infoPtr->calcSize.cy = yPos;
1435 TRACE("calcsize size=(%d, %d), origheight=(%d,%d)\n",
1436 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1437 oldSize.cx, oldSize.cy);
1439 REBAR_DumpBand (infoPtr);
1440 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1441 REBAR_ForceResize (infoPtr);
1443 /* note: after a RBN_HEIGHTCHANGE native sends once again all the RBN_CHILDSIZE
1444 * and does another ForceResize */
1445 if (oldSize.cy != infoPtr->calcSize.cy)
1447 NMHDR heightchange;
1448 REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1449 REBAR_AutoSize(infoPtr, FALSE);
1453 /* iBeginBand must be visible */
1454 static int
1455 REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
1457 int cyBandsOld;
1458 int cyBandsNew = 0;
1459 int i;
1461 TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
1463 cyBandsOld = REBAR_GetBand(infoPtr, iBeginBand)->rcBand.bottom -
1464 REBAR_GetBand(infoPtr, iBeginBand)->rcBand.top;
1465 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1467 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1468 int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
1469 int cyChild = round_child_height(lpBand, cyMaxChild);
1471 if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
1473 TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
1474 *fChanged = TRUE;
1475 lpBand->cyChild = cyChild;
1476 lpBand->fDraw |= NTF_INVALIDATE;
1477 update_min_band_height(infoPtr, lpBand);
1479 cyBandsNew = max(cyBandsNew, lpBand->cyMinBand);
1481 return cyBandsNew - cyBandsOld;
1484 /* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
1485 static VOID
1486 REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
1488 int extra = height - infoPtr->calcSize.cy; /* may be negative */
1489 BOOL fChanged = FALSE;
1490 UINT uNumRows = infoPtr->uNumRows;
1491 int i;
1493 if (uNumRows == 0) /* avoid division by 0 */
1494 return;
1496 /* That's not exactly what Windows does but should be similar */
1498 /* Pass one: break-up/glue rows */
1499 if (extra > 0)
1501 for (i = prev_visible(infoPtr, infoPtr->uNumBands); i > 0; i = prev_visible(infoPtr, i))
1503 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1504 int cyBreakExtra; /* additional cy for the rebar after a RBBS_BREAK on this band */
1506 height = lpBand->rcBand.bottom - lpBand->rcBand.top;
1508 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1509 cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
1510 else
1511 cyBreakExtra = height; /* 'height' => 'height' + 'height'*/
1512 cyBreakExtra += SEP_WIDTH;
1514 if (extra <= cyBreakExtra / 2)
1515 break;
1517 if (!(lpBand->fStyle & RBBS_BREAK))
1519 TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
1520 lpBand->fStyle |= RBBS_BREAK;
1521 lpBand->fDraw |= NTF_INVALIDATE;
1522 fChanged = TRUE;
1523 extra -= cyBreakExtra;
1524 uNumRows++;
1525 /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
1526 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1527 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->cyMinBand;
1531 /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
1533 /* Pass two: increase/decrease control height */
1534 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1536 int i = first_visible(infoPtr);
1537 int iRow = 0;
1538 while (i < infoPtr->uNumBands)
1540 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1541 int extraForRow = extra / (int)(uNumRows - iRow);
1542 int rowEnd;
1544 /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
1545 for (rowEnd = next_visible(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_visible(infoPtr, rowEnd))
1546 if (REBAR_GetBand(infoPtr, rowEnd)->iRow != lpBand->iRow ||
1547 REBAR_GetBand(infoPtr, rowEnd)->fStyle & RBBS_BREAK)
1548 break;
1550 extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
1551 TRACE("extra = %d\n", extra);
1552 i = rowEnd;
1553 iRow++;
1556 else
1557 REBAR_SizeChildrenToHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
1559 if (fChanged)
1560 REBAR_Layout(infoPtr);
1563 static VOID
1564 REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout)
1566 RECT rc, rcNew;
1567 NMRBAUTOSIZE autosize;
1569 if (needsLayout)
1570 REBAR_Layout(infoPtr);
1571 GetClientRect(infoPtr->hwndSelf, &rc);
1572 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, &rc));
1573 GetClientRect(infoPtr->hwndSelf, &rcNew);
1575 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
1576 autosize.fChanged = (memcmp(&rc, &rcNew, sizeof(RECT)) == 0);
1577 autosize.rcTarget = rc;
1578 autosize.rcActual = rcNew;
1579 REBAR_Notify((NMHDR *)&autosize, infoPtr, RBN_AUTOSIZE);
1582 static VOID
1583 REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1584 /* Function: This routine evaluates the band specs supplied */
1585 /* by the user and updates the following 5 fields in */
1586 /* the internal band structure: cxHeader, cyHeader, cxMinBand, cyMinBand, fStatus */
1588 UINT header=0;
1589 UINT textheight=0, imageheight = 0;
1590 UINT i, nonfixed;
1591 REBAR_BAND *tBand;
1593 lpBand->fStatus = 0;
1594 lpBand->cxMinBand = 0;
1595 lpBand->cyMinBand = 0;
1597 /* Data coming in from users into the cx... and cy... fields */
1598 /* may be bad, just garbage, because the user never clears */
1599 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1600 /* along if the fields exist in the input area. Here we must */
1601 /* determine if the data is valid. I have no idea how MS does */
1602 /* the validation, but it does because the RB_GETBANDINFO */
1603 /* returns a 0 when I know the sample program passed in an */
1604 /* address. Here I will use the algorithm that if the value */
1605 /* is greater than 65535 then it is bad and replace it with */
1606 /* a zero. Feel free to improve the algorithm. - GA 12/2000 */
1607 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1608 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1609 if (lpBand->cx > 65535) lpBand->cx = 0;
1610 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1611 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1612 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1613 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1615 /* TODO : we could try return to the caller if a value changed so that */
1616 /* a REBAR_Layout is needed. Till now the caller should call it */
1617 /* it always (we should also check what native does) */
1619 /* Header is where the image, text and gripper exist */
1620 /* in the band and precede the child window. */
1622 /* count number of non-FIXEDSIZE and non-Hidden bands */
1623 nonfixed = 0;
1624 for (i=0; i<infoPtr->uNumBands; i++){
1625 tBand = REBAR_GetBand(infoPtr, i);
1626 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1627 nonfixed++;
1630 /* calculate gripper rectangle */
1631 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1632 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1633 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1635 lpBand->fStatus |= HAS_GRIPPER;
1636 if (infoPtr->dwStyle & CCS_VERT)
1637 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1638 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1639 else
1640 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1641 else
1642 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1643 /* Always have 4 pixels before anything else */
1644 header += REBAR_ALWAYS_SPACE;
1647 /* image is visible */
1648 if (lpBand->iImage != -1 && (infoPtr->himl)) {
1649 lpBand->fStatus |= HAS_IMAGE;
1650 if (infoPtr->dwStyle & CCS_VERT) {
1651 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1652 imageheight = infoPtr->imageSize.cx + 4;
1654 else {
1655 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1656 imageheight = infoPtr->imageSize.cy + 4;
1660 /* text is visible */
1661 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
1662 !(lpBand->fStyle & RBBS_HIDETITLE)) {
1663 HDC hdc = GetDC (0);
1664 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1665 SIZE size;
1667 lpBand->fStatus |= HAS_TEXT;
1668 GetTextExtentPoint32W (hdc, lpBand->lpText,
1669 lstrlenW (lpBand->lpText), &size);
1670 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1671 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1673 SelectObject (hdc, hOldFont);
1674 ReleaseDC (0, hdc);
1677 /* if no gripper but either image or text, then leave space */
1678 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1679 !(lpBand->fStatus & HAS_GRIPPER)) {
1680 header += REBAR_ALWAYS_SPACE;
1683 /* check if user overrode the header value */
1684 if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
1685 lpBand->cxHeader = header;
1686 lpBand->cyHeader = max(textheight, imageheight);
1688 /* Now compute minimum size of child window */
1689 update_min_band_height(infoPtr, lpBand); /* update lpBand->cyMinBand from cyHeader and cyChild*/
1691 lpBand->cxMinBand = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
1692 if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
1693 lpBand->cxMinBand += CHEVRON_WIDTH;
1696 static UINT
1697 REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
1698 /* Function: This routine copies the supplied values from */
1699 /* user input (lprbbi) to the internal band structure. */
1700 /* It returns the mask of what changed. */
1702 UINT uChanged = 0x0;
1704 lpBand->fMask |= lprbbi->fMask;
1706 if( (lprbbi->fMask & RBBIM_STYLE) &&
1707 (lpBand->fStyle != lprbbi->fStyle ) )
1709 lpBand->fStyle = lprbbi->fStyle;
1710 uChanged |= RBBIM_STYLE;
1713 if( (lprbbi->fMask & RBBIM_COLORS) &&
1714 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
1715 ( lpBand->clrBack != lprbbi->clrBack ) ) )
1717 lpBand->clrFore = lprbbi->clrFore;
1718 lpBand->clrBack = lprbbi->clrBack;
1719 uChanged |= RBBIM_COLORS;
1722 if( (lprbbi->fMask & RBBIM_IMAGE) &&
1723 ( lpBand->iImage != lprbbi->iImage ) )
1725 lpBand->iImage = lprbbi->iImage;
1726 uChanged |= RBBIM_IMAGE;
1729 if( (lprbbi->fMask & RBBIM_CHILD) &&
1730 (lprbbi->hwndChild != lpBand->hwndChild ) )
1732 if (lprbbi->hwndChild) {
1733 lpBand->hwndChild = lprbbi->hwndChild;
1734 lpBand->hwndPrevParent =
1735 SetParent (lpBand->hwndChild, hwnd);
1736 /* below in trace from WinRAR */
1737 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
1738 /* above in trace from WinRAR */
1740 else {
1741 TRACE("child: %p prev parent: %p\n",
1742 lpBand->hwndChild, lpBand->hwndPrevParent);
1743 lpBand->hwndChild = 0;
1744 lpBand->hwndPrevParent = 0;
1746 uChanged |= RBBIM_CHILD;
1749 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
1750 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
1751 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
1752 ( (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) &&
1753 ( (lpBand->cyChild != lprbbi->cyChild ) ||
1754 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
1755 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
1756 ( (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE) &&
1757 ( (lpBand->cyChild ||
1758 lpBand->cyMaxChild ||
1759 lpBand->cyIntegral ) ) ) ) )
1761 lpBand->cxMinChild = lprbbi->cxMinChild;
1762 lpBand->cyMinChild = lprbbi->cyMinChild;
1763 /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
1764 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
1765 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1766 lpBand->cyIntegral = lprbbi->cyIntegral;
1768 lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild); /* make (cyChild - cyMinChild) a multiple of cyIntergral */
1770 else {
1771 lpBand->cyChild = lpBand->cyMinChild;
1772 lpBand->cyMaxChild = 0x7fffffff;
1773 lpBand->cyIntegral = 0;
1775 uChanged |= RBBIM_CHILDSIZE;
1778 if( (lprbbi->fMask & RBBIM_SIZE) &&
1779 (lpBand->cx != lprbbi->cx ) )
1781 lpBand->cx = lprbbi->cx;
1782 uChanged |= RBBIM_SIZE;
1785 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
1786 ( lpBand->hbmBack != lprbbi->hbmBack ) )
1788 lpBand->hbmBack = lprbbi->hbmBack;
1789 uChanged |= RBBIM_BACKGROUND;
1792 if( (lprbbi->fMask & RBBIM_ID) &&
1793 (lpBand->wID != lprbbi->wID ) )
1795 lpBand->wID = lprbbi->wID;
1796 uChanged |= RBBIM_ID;
1799 /* check for additional data */
1800 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE) {
1801 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
1802 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
1804 lpBand->cxIdeal = lprbbi->cxIdeal;
1805 uChanged |= RBBIM_IDEALSIZE;
1808 if( (lprbbi->fMask & RBBIM_LPARAM) &&
1809 (lpBand->lParam != lprbbi->lParam ) )
1811 lpBand->lParam = lprbbi->lParam;
1812 uChanged |= RBBIM_LPARAM;
1815 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
1816 (lpBand->cxHeader != lprbbi->cxHeader ) )
1818 lpBand->cxHeader = lprbbi->cxHeader;
1819 lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
1820 uChanged |= RBBIM_HEADERSIZE;
1824 return uChanged;
1827 static LRESULT REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, HDC hdc)
1828 /* Function: This erases the background rectangle by drawing */
1829 /* each band with its background color (or the default) and */
1830 /* draws each bands right separator if necessary. The row */
1831 /* separators are drawn on the first band of the next row. */
1833 REBAR_BAND *lpBand;
1834 UINT i;
1835 INT oldrow;
1836 RECT cr;
1837 COLORREF old = CLR_NONE, new;
1838 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1840 GetClientRect (infoPtr->hwndSelf, &cr);
1842 oldrow = -1;
1843 for(i=0; i<infoPtr->uNumBands; i++) {
1844 RECT rcBand;
1845 lpBand = REBAR_GetBand(infoPtr, i);
1846 if (HIDDENBAND(lpBand)) continue;
1847 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1849 /* draw band separator between rows */
1850 if (lpBand->iRow != oldrow) {
1851 oldrow = lpBand->iRow;
1852 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1853 RECT rcRowSep;
1854 rcRowSep = rcBand;
1855 if (infoPtr->dwStyle & CCS_VERT) {
1856 rcRowSep.right += SEP_WIDTH_SIZE;
1857 rcRowSep.bottom = infoPtr->calcSize.cx;
1858 if (theme)
1859 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_RIGHT, NULL);
1860 else
1861 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
1863 else {
1864 rcRowSep.bottom += SEP_WIDTH_SIZE;
1865 rcRowSep.right = infoPtr->calcSize.cx;
1866 if (theme)
1867 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1868 else
1869 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
1871 TRACE ("drawing band separator bottom (%s)\n",
1872 wine_dbgstr_rect(&rcRowSep));
1876 /* draw band separator between bands in a row */
1877 if (infoPtr->dwStyle & RBS_BANDBORDERS && lpBand->rcBand.left > 0) {
1878 RECT rcSep;
1879 rcSep = rcBand;
1880 if (infoPtr->dwStyle & CCS_VERT) {
1881 rcSep.bottom = rcSep.top;
1882 rcSep.top -= SEP_WIDTH_SIZE;
1883 if (theme)
1884 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1885 else
1886 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
1888 else {
1889 rcSep.right = rcSep.left;
1890 rcSep.left -= SEP_WIDTH_SIZE;
1891 if (theme)
1892 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_RIGHT, NULL);
1893 else
1894 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
1896 TRACE("drawing band separator right (%s)\n",
1897 wine_dbgstr_rect(&rcSep));
1900 /* draw the actual background */
1901 if (lpBand->clrBack != CLR_NONE) {
1902 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
1903 lpBand->clrBack;
1904 #if GLATESTING
1905 /* testing only - make background green to see it */
1906 new = RGB(0,128,0);
1907 #endif
1909 else {
1910 /* In the absence of documentation for Rebar vs. CLR_NONE,
1911 * we will use the default BtnFace color. Note documentation
1912 * exists for Listview and Imagelist.
1914 new = infoPtr->clrBtnFace;
1915 #if GLATESTING
1916 /* testing only - make background green to see it */
1917 new = RGB(0,128,0);
1918 #endif
1921 if (theme)
1923 /* When themed, the background color is ignored (but not a
1924 * background bitmap */
1925 DrawThemeBackground (theme, hdc, 0, 0, &cr, &rcBand);
1927 else
1929 old = SetBkColor (hdc, new);
1930 TRACE("%s background color=0x%06x, band %s\n",
1931 (lpBand->clrBack == CLR_NONE) ? "none" :
1932 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
1933 GetBkColor(hdc), wine_dbgstr_rect(&rcBand));
1934 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &rcBand, NULL, 0, 0);
1935 if (lpBand->clrBack != CLR_NONE)
1936 SetBkColor (hdc, old);
1939 return TRUE;
1942 static void
1943 REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
1945 REBAR_BAND *lpBand;
1946 RECT rect;
1947 UINT iCount;
1949 GetClientRect (infoPtr->hwndSelf, &rect);
1951 *pFlags = RBHT_NOWHERE;
1952 if (PtInRect (&rect, *lpPt))
1954 if (infoPtr->uNumBands == 0) {
1955 *pFlags = RBHT_NOWHERE;
1956 if (pBand)
1957 *pBand = -1;
1958 TRACE("NOWHERE\n");
1959 return;
1961 else {
1962 /* somewhere inside */
1963 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
1964 RECT rcBand;
1965 lpBand = REBAR_GetBand(infoPtr, iCount);
1966 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1967 if (HIDDENBAND(lpBand)) continue;
1968 if (PtInRect (&rcBand, *lpPt)) {
1969 if (pBand)
1970 *pBand = iCount;
1971 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
1972 *pFlags = RBHT_GRABBER;
1973 TRACE("ON GRABBER %d\n", iCount);
1974 return;
1976 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
1977 *pFlags = RBHT_CAPTION;
1978 TRACE("ON CAPTION %d\n", iCount);
1979 return;
1981 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
1982 *pFlags = RBHT_CAPTION;
1983 TRACE("ON CAPTION %d\n", iCount);
1984 return;
1986 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
1987 *pFlags = RBHT_CLIENT;
1988 TRACE("ON CLIENT %d\n", iCount);
1989 return;
1991 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
1992 *pFlags = RBHT_CHEVRON;
1993 TRACE("ON CHEVRON %d\n", iCount);
1994 return;
1996 else {
1997 *pFlags = RBHT_NOWHERE;
1998 TRACE("NOWHERE %d\n", iCount);
1999 return;
2004 *pFlags = RBHT_NOWHERE;
2005 if (pBand)
2006 *pBand = -1;
2008 TRACE("NOWHERE\n");
2009 return;
2012 else {
2013 *pFlags = RBHT_NOWHERE;
2014 if (pBand)
2015 *pBand = -1;
2016 TRACE("NOWHERE\n");
2017 return;
2021 static void
2022 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2023 /* Function: This will implement the functionality of a */
2024 /* Gripper drag within a row. It will not implement "out- */
2025 /* of-row" drags. (They are detected and handled in */
2026 /* REBAR_MouseMove.) */
2028 REBAR_BAND *hitBand;
2029 INT iHitBand, iRowBegin, iRowEnd;
2030 INT movement, xBand, cxLeft = 0;
2031 BOOL shrunkBands = FALSE;
2033 iHitBand = infoPtr->iGrabbedBand;
2034 iRowBegin = get_row_begin_for_band(infoPtr, iHitBand);
2035 iRowEnd = get_row_end_for_band(infoPtr, iHitBand);
2036 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2038 xBand = hitBand->rcBand.left;
2039 movement = (infoPtr->dwStyle&CCS_VERT ? ptsmove->y : ptsmove->x)
2040 - (xBand + REBAR_PRE_GRIPPER - infoPtr->ihitoffset);
2042 /* Dragging the first band in a row cannot cause shrinking */
2043 if(iHitBand != iRowBegin)
2045 if (movement < 0) {
2046 cxLeft = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iHitBand, -movement, TRUE);
2048 if(cxLeft < -movement)
2050 hitBand->cxEffective += -movement - cxLeft;
2051 hitBand->cx = hitBand->cxEffective;
2052 shrunkBands = TRUE;
2055 } else if (movement > 0) {
2057 cxLeft = movement;
2058 if (prev_visible(infoPtr, iHitBand) >= 0)
2059 cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
2061 if(cxLeft < movement)
2063 REBAR_BAND *lpPrev = REBAR_GetBand(infoPtr, prev_visible(infoPtr, iHitBand));
2064 lpPrev->cxEffective += movement - cxLeft;
2065 lpPrev->cx = hitBand->cxEffective;
2066 shrunkBands = TRUE;
2072 if(!shrunkBands)
2074 /* It was not possible to move the band by shrinking bands.
2075 * Try relocating the band instead. */
2076 REBAR_MoveBandToRowOffset(infoPtr, iHitBand, iRowBegin,
2077 iRowEnd, xBand + movement, TRUE);
2080 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2081 if (infoPtr->dwStyle & CCS_VERT)
2082 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
2083 else
2084 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
2085 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2088 static void
2089 REBAR_HandleUDDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2091 INT yOff = (infoPtr->dwStyle & CCS_VERT) ? ptsmove->x : ptsmove->y;
2092 INT iHitBand, iRowBegin, iNextRowBegin;
2093 REBAR_BAND *hitBand, *rowBeginBand;
2095 if(infoPtr->uNumBands <= 0)
2096 ERR("There are no bands in this rebar\n");
2098 /* Up/down dragging can only occur when there is more than one
2099 * band in the rebar */
2100 if(infoPtr->uNumBands <= 1)
2101 return;
2103 iHitBand = infoPtr->iGrabbedBand;
2104 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2106 /* If we're taking a band that has the RBBS_BREAK style set, this
2107 * style needs to be reapplied to the band that is going to become
2108 * the new start of the row. */
2109 if((hitBand->fStyle & RBBS_BREAK) &&
2110 (iHitBand < infoPtr->uNumBands - 1))
2111 REBAR_GetBand(infoPtr, iHitBand + 1)->fStyle |= RBBS_BREAK;
2113 if(yOff < 0)
2115 /* Place the band above the current top row */
2116 if(iHitBand==0 && (infoPtr->uNumBands==1 || REBAR_GetBand(infoPtr, 1)->fStyle&RBBS_BREAK))
2117 return;
2118 DPA_DeletePtr(infoPtr->bands, iHitBand);
2119 hitBand->fStyle &= ~RBBS_BREAK;
2120 REBAR_GetBand(infoPtr, 0)->fStyle |= RBBS_BREAK;
2121 infoPtr->iGrabbedBand = DPA_InsertPtr(
2122 infoPtr->bands, 0, hitBand);
2124 else if(yOff > REBAR_GetBand(infoPtr, infoPtr->uNumBands - 1)->rcBand.bottom)
2126 /* Place the band below the current bottom row */
2127 if(iHitBand == infoPtr->uNumBands-1 && hitBand->fStyle&RBBS_BREAK)
2128 return;
2129 DPA_DeletePtr(infoPtr->bands, iHitBand);
2130 hitBand->fStyle |= RBBS_BREAK;
2131 infoPtr->iGrabbedBand = DPA_InsertPtr(
2132 infoPtr->bands, infoPtr->uNumBands - 1, hitBand);
2134 else
2136 /* Place the band in the prexisting row the mouse is hovering over */
2137 iRowBegin = first_visible(infoPtr);
2138 while(iRowBegin < infoPtr->uNumBands)
2140 iNextRowBegin = get_row_end_for_band(infoPtr, iRowBegin);
2141 rowBeginBand = REBAR_GetBand(infoPtr, iRowBegin);
2142 if(rowBeginBand->rcBand.bottom > yOff)
2144 REBAR_MoveBandToRowOffset(
2145 infoPtr, iHitBand, iRowBegin, iNextRowBegin,
2146 ((infoPtr->dwStyle & CCS_VERT) ? ptsmove->y : ptsmove->x)
2147 - REBAR_PRE_GRIPPER - infoPtr->ihitoffset, FALSE);
2148 break;
2151 iRowBegin = iNextRowBegin;
2155 REBAR_Layout(infoPtr);
2159 /* << REBAR_BeginDrag >> */
2162 static LRESULT
2163 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam)
2165 UINT uBand = (UINT)wParam;
2166 REBAR_BAND *lpBand;
2168 if (uBand >= infoPtr->uNumBands)
2169 return FALSE;
2171 TRACE("deleting band %u!\n", uBand);
2172 lpBand = REBAR_GetBand(infoPtr, uBand);
2173 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2174 /* TODO: a return of 1 should probably cancel the deletion */
2176 if (lpBand->hwndChild)
2177 ShowWindow(lpBand->hwndChild, SW_HIDE);
2178 Free(lpBand->lpText);
2179 Free(lpBand);
2181 infoPtr->uNumBands--;
2182 DPA_DeletePtr(infoPtr->bands, uBand);
2184 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2186 /* if only 1 band left the re-validate to possible eliminate gripper */
2187 if (infoPtr->uNumBands == 1)
2188 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2190 REBAR_Layout(infoPtr);
2192 return TRUE;
2196 /* << REBAR_DragMove >> */
2197 /* << REBAR_EndDrag >> */
2200 static LRESULT
2201 REBAR_GetBandBorders (const REBAR_INFO *infoPtr, UINT uBand, RECT *lpRect)
2203 REBAR_BAND *lpBand;
2205 if (!lpRect)
2206 return 0;
2207 if (uBand >= infoPtr->uNumBands)
2208 return 0;
2210 lpBand = REBAR_GetBand(infoPtr, uBand);
2212 /* FIXME - the following values were determined by experimentation */
2213 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2214 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2215 /* difference in size of the control area with and without the */
2216 /* style. - GA */
2217 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2218 if (infoPtr->dwStyle & CCS_VERT) {
2219 lpRect->left = 1;
2220 lpRect->top = lpBand->cxHeader + 4;
2221 lpRect->right = 1;
2222 lpRect->bottom = 0;
2224 else {
2225 lpRect->left = lpBand->cxHeader + 4;
2226 lpRect->top = 1;
2227 lpRect->right = 0;
2228 lpRect->bottom = 1;
2231 else {
2232 lpRect->left = lpBand->cxHeader;
2234 return 0;
2238 static inline LRESULT
2239 REBAR_GetBandCount (const REBAR_INFO *infoPtr)
2241 TRACE("band count %u!\n", infoPtr->uNumBands);
2243 return infoPtr->uNumBands;
2247 static LRESULT
2248 REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, UINT uIndex, LPREBARBANDINFOW lprbbi, BOOL bUnicode)
2250 REBAR_BAND *lpBand;
2252 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2253 return FALSE;
2255 if (uIndex >= infoPtr->uNumBands)
2256 return FALSE;
2258 TRACE("index %u (bUnicode=%d)\n", uIndex, bUnicode);
2260 /* copy band information */
2261 lpBand = REBAR_GetBand(infoPtr, uIndex);
2263 if (lprbbi->fMask & RBBIM_STYLE)
2264 lprbbi->fStyle = lpBand->fStyle;
2266 if (lprbbi->fMask & RBBIM_COLORS) {
2267 lprbbi->clrFore = lpBand->clrFore;
2268 lprbbi->clrBack = lpBand->clrBack;
2269 if (lprbbi->clrBack == CLR_DEFAULT)
2270 lprbbi->clrBack = infoPtr->clrBtnFace;
2273 if (lprbbi->fMask & RBBIM_TEXT) {
2274 if (bUnicode)
2275 Str_GetPtrW(lpBand->lpText, lprbbi->lpText, lprbbi->cch);
2276 else
2277 Str_GetPtrWtoA(lpBand->lpText, (LPSTR)lprbbi->lpText, lprbbi->cch);
2280 if (lprbbi->fMask & RBBIM_IMAGE)
2281 lprbbi->iImage = lpBand->iImage;
2283 if (lprbbi->fMask & RBBIM_CHILD)
2284 lprbbi->hwndChild = lpBand->hwndChild;
2286 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2287 lprbbi->cxMinChild = lpBand->cxMinChild;
2288 lprbbi->cyMinChild = lpBand->cyMinChild;
2289 /* to make tests pass we follow Windows' behaviour and allow reading these fields only
2290 * for RBBS_VARIABLEHEIGHTS bands */
2291 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2292 lprbbi->cyChild = lpBand->cyChild;
2293 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2294 lprbbi->cyIntegral = lpBand->cyIntegral;
2298 if (lprbbi->fMask & RBBIM_SIZE)
2299 lprbbi->cx = lpBand->cx;
2301 if (lprbbi->fMask & RBBIM_BACKGROUND)
2302 lprbbi->hbmBack = lpBand->hbmBack;
2304 if (lprbbi->fMask & RBBIM_ID)
2305 lprbbi->wID = lpBand->wID;
2307 /* check for additional data */
2308 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE) {
2309 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2310 lprbbi->cxIdeal = lpBand->cxIdeal;
2312 if (lprbbi->fMask & RBBIM_LPARAM)
2313 lprbbi->lParam = lpBand->lParam;
2315 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2316 lprbbi->cxHeader = lpBand->cxHeader;
2319 REBAR_DumpBandInfo(lprbbi);
2321 return TRUE;
2325 static LRESULT
2326 REBAR_GetBarHeight (const REBAR_INFO *infoPtr)
2328 INT nHeight;
2330 nHeight = infoPtr->calcSize.cy;
2332 TRACE("height = %d\n", nHeight);
2334 return nHeight;
2338 static LRESULT
2339 REBAR_GetBarInfo (const REBAR_INFO *infoPtr, LPREBARINFO lpInfo)
2341 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2342 return FALSE;
2344 TRACE("getting bar info!\n");
2346 if (infoPtr->himl) {
2347 lpInfo->himl = infoPtr->himl;
2348 lpInfo->fMask |= RBIM_IMAGELIST;
2351 return TRUE;
2355 static inline LRESULT
2356 REBAR_GetBkColor (const REBAR_INFO *infoPtr)
2358 COLORREF clr = infoPtr->clrBk;
2360 if (clr == CLR_DEFAULT)
2361 clr = infoPtr->clrBtnFace;
2363 TRACE("background color 0x%06x!\n", clr);
2365 return clr;
2369 /* << REBAR_GetColorScheme >> */
2370 /* << REBAR_GetDropTarget >> */
2373 static LRESULT
2374 REBAR_GetPalette (const REBAR_INFO *infoPtr)
2376 FIXME("empty stub!\n");
2378 return 0;
2382 static LRESULT
2383 REBAR_GetRect (const REBAR_INFO *infoPtr, INT iBand, RECT *lprc)
2385 REBAR_BAND *lpBand;
2387 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2388 return FALSE;
2389 if (!lprc)
2390 return FALSE;
2392 lpBand = REBAR_GetBand(infoPtr, iBand);
2393 /* For CCS_VERT the coordinates will be swapped - like on Windows */
2394 CopyRect (lprc, &lpBand->rcBand);
2396 TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
2398 return TRUE;
2402 static inline LRESULT
2403 REBAR_GetRowCount (const REBAR_INFO *infoPtr)
2405 TRACE("%u\n", infoPtr->uNumRows);
2407 return infoPtr->uNumRows;
2411 static LRESULT
2412 REBAR_GetRowHeight (const REBAR_INFO *infoPtr, INT iRow)
2414 int j = 0, ret = 0;
2415 UINT i;
2416 REBAR_BAND *lpBand;
2418 for (i=0; i<infoPtr->uNumBands; i++) {
2419 lpBand = REBAR_GetBand(infoPtr, i);
2420 if (HIDDENBAND(lpBand)) continue;
2421 if (lpBand->iRow != iRow) continue;
2422 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2423 if (j > ret) ret = j;
2426 TRACE("row %d, height %d\n", iRow, ret);
2428 return ret;
2432 static inline LRESULT
2433 REBAR_GetTextColor (const REBAR_INFO *infoPtr)
2435 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2437 return infoPtr->clrText;
2441 static inline LRESULT
2442 REBAR_GetToolTips (const REBAR_INFO *infoPtr)
2444 return (LRESULT)infoPtr->hwndToolTip;
2448 static inline LRESULT
2449 REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
2451 TRACE("%s hwnd=%p\n",
2452 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2454 return infoPtr->bUnicode;
2458 static inline LRESULT
2459 REBAR_GetVersion (const REBAR_INFO *infoPtr)
2461 TRACE("version %d\n", infoPtr->iVersion);
2462 return infoPtr->iVersion;
2466 static LRESULT
2467 REBAR_HitTest (const REBAR_INFO *infoPtr, LPRBHITTESTINFO lprbht)
2469 if (!lprbht)
2470 return -1;
2472 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2474 return lprbht->iBand;
2478 static LRESULT
2479 REBAR_IdToIndex (const REBAR_INFO *infoPtr, UINT uId)
2481 UINT i;
2483 if (infoPtr->uNumBands < 1)
2484 return -1;
2486 for (i = 0; i < infoPtr->uNumBands; i++) {
2487 if (REBAR_GetBand(infoPtr, i)->wID == uId) {
2488 TRACE("id %u is band %u found!\n", uId, i);
2489 return i;
2493 TRACE("id %u is not found\n", uId);
2494 return -1;
2498 static LRESULT
2499 REBAR_InsertBandT(REBAR_INFO *infoPtr, INT iIndex, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2501 REBAR_BAND *lpBand;
2503 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2504 return FALSE;
2506 /* trace the index as signed to see the -1 */
2507 TRACE("insert band at %d (bUnicode=%d)!\n", iIndex, bUnicode);
2508 REBAR_DumpBandInfo(lprbbi);
2510 if (!(lpBand = Alloc(sizeof(REBAR_BAND)))) return FALSE;
2511 if ((iIndex == -1) || (iIndex > infoPtr->uNumBands))
2512 iIndex = infoPtr->uNumBands;
2513 if (DPA_InsertPtr(infoPtr->bands, iIndex, lpBand) == -1)
2515 Free(lpBand);
2516 return FALSE;
2518 infoPtr->uNumBands++;
2520 TRACE("index %d!\n", iIndex);
2522 /* initialize band */
2523 memset(lpBand, 0, sizeof(*lpBand));
2524 lpBand->clrFore = infoPtr->clrText == CLR_NONE ? infoPtr->clrBtnText :
2525 infoPtr->clrText;
2526 lpBand->clrBack = infoPtr->clrBk == CLR_NONE ? infoPtr->clrBtnFace :
2527 infoPtr->clrBk;
2528 lpBand->iImage = -1;
2530 REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
2532 /* Make sure the defaults for these are correct */
2533 if (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE || !(lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2534 lpBand->cyChild = lpBand->cyMinChild;
2535 lpBand->cyMaxChild = 0x7fffffff;
2536 lpBand->cyIntegral = 0;
2539 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2540 if (bUnicode)
2541 Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
2542 else
2543 Str_SetPtrAtoW(&lpBand->lpText, (LPSTR)lprbbi->lpText);
2546 REBAR_ValidateBand (infoPtr, lpBand);
2547 /* On insert of second band, revalidate band 1 to possible add gripper */
2548 if (infoPtr->uNumBands == 2)
2549 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2551 REBAR_DumpBand (infoPtr);
2553 REBAR_Layout(infoPtr);
2554 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2556 return TRUE;
2560 static LRESULT
2561 REBAR_MaximizeBand (const REBAR_INFO *infoPtr, INT iBand, LPARAM lParam)
2563 REBAR_BAND *lpBand;
2564 int iRowBegin, iRowEnd;
2565 int cxDesired, extra, extraOrig;
2566 int cxIdealBand;
2568 /* Validate */
2569 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2570 /* error !!! */
2571 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
2572 iBand, infoPtr->uNumBands);
2573 return FALSE;
2576 lpBand = REBAR_GetBand(infoPtr, iBand);
2578 if (lpBand->fStyle & RBBS_HIDDEN)
2580 /* Windows is buggy and creates a hole */
2581 WARN("Ignoring maximize request on a hidden band (%d)\n", iBand);
2582 return FALSE;
2585 cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
2586 if (lParam && (lpBand->cxEffective < cxIdealBand))
2587 cxDesired = cxIdealBand;
2588 else
2589 cxDesired = infoPtr->calcSize.cx;
2591 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2592 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2593 extraOrig = extra = cxDesired - lpBand->cxEffective;
2594 if (extra > 0)
2595 extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iBand, extra, TRUE);
2596 if (extra > 0)
2597 extra = REBAR_ShrinkBandsLTR(infoPtr, next_visible(infoPtr, iBand), iRowEnd, extra, TRUE);
2598 lpBand->cxEffective += extraOrig - extra;
2599 lpBand->cx = lpBand->cxEffective;
2600 TRACE("(%d, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", iBand, lParam, cxDesired, lpBand->cx, extraOrig, extra);
2601 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2603 if (infoPtr->dwStyle & CCS_VERT)
2604 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2605 else
2606 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2607 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2608 return TRUE;
2613 static LRESULT
2614 REBAR_MinimizeBand (const REBAR_INFO *infoPtr, INT iBand)
2616 REBAR_BAND *lpBand;
2617 int iPrev, iRowBegin, iRowEnd;
2619 /* A "minimize" band is equivalent to "dragging" the gripper
2620 * of than band to the right till the band is only the size
2621 * of the cxHeader.
2624 /* Validate */
2625 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2626 /* error !!! */
2627 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
2628 iBand, infoPtr->uNumBands);
2629 return FALSE;
2632 /* compute amount of movement and validate */
2633 lpBand = REBAR_GetBand(infoPtr, iBand);
2635 if (lpBand->fStyle & RBBS_HIDDEN)
2637 /* Windows is buggy and creates a hole/overlap */
2638 WARN("Ignoring minimize request on a hidden band (%d)\n", iBand);
2639 return FALSE;
2642 iPrev = prev_visible(infoPtr, iBand);
2643 /* if first band in row */
2644 if (iPrev < 0 || REBAR_GetBand(infoPtr, iPrev)->iRow != lpBand->iRow) {
2645 int iNext = next_visible(infoPtr, iBand);
2646 if (iNext < infoPtr->uNumBands && REBAR_GetBand(infoPtr, iNext)->iRow == lpBand->iRow) {
2647 TRACE("(%d): Minimizing the first band in row is by maximizing the second\n", iBand);
2648 REBAR_MaximizeBand(infoPtr, iNext, FALSE);
2650 else
2651 TRACE("(%d): Only one band in row - nothing to do\n", iBand);
2652 return TRUE;
2655 REBAR_GetBand(infoPtr, iPrev)->cxEffective += lpBand->cxEffective - lpBand->cxMinBand;
2656 REBAR_GetBand(infoPtr, iPrev)->cx = REBAR_GetBand(infoPtr, iPrev)->cxEffective;
2657 lpBand->cx = lpBand->cxEffective = lpBand->cxMinBand;
2659 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2660 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2661 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2663 if (infoPtr->dwStyle & CCS_VERT)
2664 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2665 else
2666 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2667 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2668 return FALSE;
2672 static LRESULT
2673 REBAR_MoveBand (REBAR_INFO *infoPtr, INT iFrom, INT iTo)
2675 REBAR_BAND *lpBand;
2677 /* Validate */
2678 if ((infoPtr->uNumBands == 0) ||
2679 (iFrom < 0) || iFrom >= infoPtr->uNumBands ||
2680 (iTo < 0) || iTo >= infoPtr->uNumBands) {
2681 /* error !!! */
2682 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
2683 iFrom, iTo, infoPtr->uNumBands);
2684 return FALSE;
2687 lpBand = REBAR_GetBand(infoPtr, iFrom);
2688 DPA_DeletePtr(infoPtr->bands, iFrom);
2689 DPA_InsertPtr(infoPtr->bands, iTo, lpBand);
2691 TRACE("moved band %d to index %d\n", iFrom, iTo);
2692 REBAR_DumpBand (infoPtr);
2694 /* **************************************************** */
2695 /* */
2696 /* We do not do a REBAR_Layout here because the native */
2697 /* control does not do that. The actual layout and */
2698 /* repaint is done by the *next* real action, ex.: */
2699 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
2700 /* */
2701 /* **************************************************** */
2703 return TRUE;
2707 /* return TRUE if two strings are different */
2708 static BOOL
2709 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
2711 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
2714 static LRESULT
2715 REBAR_SetBandInfoT(REBAR_INFO *infoPtr, INT iBand, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2717 REBAR_BAND *lpBand;
2718 UINT uChanged;
2720 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2721 return FALSE;
2723 if (iBand >= infoPtr->uNumBands)
2724 return FALSE;
2726 TRACE("index %d\n", iBand);
2727 REBAR_DumpBandInfo (lprbbi);
2729 /* set band information */
2730 lpBand = REBAR_GetBand(infoPtr, iBand);
2732 uChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2733 if (lprbbi->fMask & RBBIM_TEXT) {
2734 LPWSTR wstr = NULL;
2735 if (bUnicode)
2736 Str_SetPtrW(&wstr, lprbbi->lpText);
2737 else
2738 Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
2740 if (REBAR_strdifW(wstr, lpBand->lpText)) {
2741 Free(lpBand->lpText);
2742 lpBand->lpText = wstr;
2743 uChanged |= RBBIM_TEXT;
2745 else
2746 Free(wstr);
2749 REBAR_ValidateBand (infoPtr, lpBand);
2751 REBAR_DumpBand (infoPtr);
2753 if (uChanged & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IMAGE)) {
2754 REBAR_Layout(infoPtr);
2755 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2758 return TRUE;
2762 static LRESULT
2763 REBAR_SetBarInfo (REBAR_INFO *infoPtr, const REBARINFO *lpInfo)
2765 REBAR_BAND *lpBand;
2766 UINT i;
2768 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2769 return FALSE;
2771 TRACE("setting bar info!\n");
2773 if (lpInfo->fMask & RBIM_IMAGELIST) {
2774 infoPtr->himl = lpInfo->himl;
2775 if (infoPtr->himl) {
2776 INT cx, cy;
2777 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
2778 infoPtr->imageSize.cx = cx;
2779 infoPtr->imageSize.cy = cy;
2781 else {
2782 infoPtr->imageSize.cx = 0;
2783 infoPtr->imageSize.cy = 0;
2785 TRACE("new image cx=%d, cy=%d\n", infoPtr->imageSize.cx,
2786 infoPtr->imageSize.cy);
2789 /* revalidate all bands to reset flags for images in headers of bands */
2790 for (i=0; i<infoPtr->uNumBands; i++) {
2791 lpBand = REBAR_GetBand(infoPtr, i);
2792 REBAR_ValidateBand (infoPtr, lpBand);
2795 return TRUE;
2799 static LRESULT
2800 REBAR_SetBkColor (REBAR_INFO *infoPtr, COLORREF clr)
2802 COLORREF clrTemp;
2804 clrTemp = infoPtr->clrBk;
2805 infoPtr->clrBk = clr;
2807 TRACE("background color 0x%06x!\n", infoPtr->clrBk);
2809 return clrTemp;
2813 /* << REBAR_SetColorScheme >> */
2814 /* << REBAR_SetPalette >> */
2817 static LRESULT
2818 REBAR_SetParent (REBAR_INFO *infoPtr, HWND parent)
2820 HWND hwndTemp = infoPtr->hwndNotify;
2822 infoPtr->hwndNotify = parent;
2824 return (LRESULT)hwndTemp;
2828 static LRESULT
2829 REBAR_SetTextColor (REBAR_INFO *infoPtr, COLORREF clr)
2831 COLORREF clrTemp;
2833 clrTemp = infoPtr->clrText;
2834 infoPtr->clrText = clr;
2836 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2838 return clrTemp;
2842 /* << REBAR_SetTooltips >> */
2845 static inline LRESULT
2846 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, BOOL unicode)
2848 BOOL bTemp = infoPtr->bUnicode;
2850 TRACE("to %s hwnd=%p, was %s\n",
2851 unicode ? "TRUE" : "FALSE", infoPtr->hwndSelf,
2852 (bTemp) ? "TRUE" : "FALSE");
2854 infoPtr->bUnicode = unicode;
2856 return bTemp;
2860 static LRESULT
2861 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
2863 INT iOldVersion = infoPtr->iVersion;
2865 if (iVersion > COMCTL32_VERSION)
2866 return -1;
2868 infoPtr->iVersion = iVersion;
2870 TRACE("new version %d\n", iVersion);
2872 return iOldVersion;
2876 static LRESULT
2877 REBAR_ShowBand (REBAR_INFO *infoPtr, INT iBand, BOOL show)
2879 REBAR_BAND *lpBand;
2881 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2882 return FALSE;
2884 lpBand = REBAR_GetBand(infoPtr, iBand);
2886 if (show) {
2887 TRACE("show band %d\n", iBand);
2888 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
2889 if (IsWindow (lpBand->hwndChild))
2890 ShowWindow (lpBand->hwndChild, SW_SHOW);
2892 else {
2893 TRACE("hide band %d\n", iBand);
2894 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
2895 if (IsWindow (lpBand->hwndChild))
2896 ShowWindow (lpBand->hwndChild, SW_HIDE);
2899 REBAR_Layout(infoPtr);
2900 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2902 return TRUE;
2906 static LRESULT
2907 REBAR_SizeToRect (REBAR_INFO *infoPtr, const RECT *lpRect)
2909 if (!lpRect) return FALSE;
2911 TRACE("[%s]\n", wine_dbgstr_rect(lpRect));
2912 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, lpRect));
2913 return TRUE;
2918 static LRESULT
2919 REBAR_Create (REBAR_INFO *infoPtr, LPCREATESTRUCTW cs)
2921 RECT wnrc1, clrc1;
2923 if (TRACE_ON(rebar)) {
2924 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
2925 GetClientRect(infoPtr->hwndSelf, &clrc1);
2926 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
2927 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
2928 cs->x, cs->y, cs->cx, cs->cy);
2931 TRACE("created!\n");
2933 if (OpenThemeData (infoPtr->hwndSelf, themeClass))
2935 /* native seems to clear WS_BORDER when themed */
2936 infoPtr->dwStyle &= ~WS_BORDER;
2939 return 0;
2943 static LRESULT
2944 REBAR_Destroy (REBAR_INFO *infoPtr)
2946 REBAR_BAND *lpBand;
2947 UINT i;
2949 /* clean up each band */
2950 for (i = 0; i < infoPtr->uNumBands; i++) {
2951 lpBand = REBAR_GetBand(infoPtr, i);
2953 /* delete text strings */
2954 Free (lpBand->lpText);
2955 lpBand->lpText = NULL;
2956 /* destroy child window */
2957 DestroyWindow (lpBand->hwndChild);
2958 Free (lpBand);
2961 /* free band array */
2962 DPA_Destroy (infoPtr->bands);
2963 infoPtr->bands = NULL;
2965 DestroyCursor (infoPtr->hcurArrow);
2966 DestroyCursor (infoPtr->hcurHorz);
2967 DestroyCursor (infoPtr->hcurVert);
2968 DestroyCursor (infoPtr->hcurDrag);
2969 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
2970 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
2972 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2974 /* free rebar info data */
2975 Free (infoPtr);
2976 TRACE("destroyed!\n");
2977 return 0;
2980 static LRESULT
2981 REBAR_GetFont (const REBAR_INFO *infoPtr)
2983 return (LRESULT)infoPtr->hFont;
2986 static LRESULT
2987 REBAR_PushChevron(const REBAR_INFO *infoPtr, UINT uBand, LPARAM lParam)
2989 if (uBand < infoPtr->uNumBands)
2991 NMREBARCHEVRON nmrbc;
2992 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
2994 TRACE("Pressed chevron on band %u\n", uBand);
2996 /* redraw chevron in pushed state */
2997 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
2998 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
2999 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3001 /* notify app so it can display a popup menu or whatever */
3002 nmrbc.uBand = uBand;
3003 nmrbc.wID = lpBand->wID;
3004 nmrbc.lParam = lpBand->lParam;
3005 nmrbc.rc = lpBand->rcChevron;
3006 nmrbc.lParamNM = lParam;
3007 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3009 /* redraw chevron in previous state */
3010 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3011 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3013 return TRUE;
3015 return FALSE;
3018 static LRESULT
3019 REBAR_LButtonDown (REBAR_INFO *infoPtr, LPARAM lParam)
3021 UINT htFlags;
3022 INT iHitBand;
3023 POINT ptMouseDown;
3024 ptMouseDown.x = (short)LOWORD(lParam);
3025 ptMouseDown.y = (short)HIWORD(lParam);
3027 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3029 if (htFlags == RBHT_CHEVRON)
3031 REBAR_PushChevron(infoPtr, iHitBand, 0);
3033 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3035 REBAR_BAND *lpBand;
3037 TRACE("Starting drag\n");
3039 lpBand = REBAR_GetBand(infoPtr, iHitBand);
3041 SetCapture (infoPtr->hwndSelf);
3042 infoPtr->iGrabbedBand = iHitBand;
3044 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3045 infoPtr->dragStart.x = (short)LOWORD(lParam);
3046 infoPtr->dragStart.y = (short)HIWORD(lParam);
3047 infoPtr->dragNow = infoPtr->dragStart;
3048 if (infoPtr->dwStyle & CCS_VERT)
3049 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3050 else
3051 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3053 return 0;
3056 static LRESULT
3057 REBAR_LButtonUp (REBAR_INFO *infoPtr)
3059 if (infoPtr->iGrabbedBand >= 0)
3061 NMHDR layout;
3062 RECT rect;
3064 infoPtr->dragStart.x = 0;
3065 infoPtr->dragStart.y = 0;
3066 infoPtr->dragNow = infoPtr->dragStart;
3068 ReleaseCapture ();
3070 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3071 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3072 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3073 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3076 infoPtr->iGrabbedBand = -1;
3078 GetClientRect(infoPtr->hwndSelf, &rect);
3079 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3082 return 0;
3085 static LRESULT
3086 REBAR_MouseLeave (REBAR_INFO *infoPtr)
3088 if (infoPtr->ichevronhotBand >= 0)
3090 REBAR_BAND *lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3091 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3093 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3094 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3097 infoPtr->iOldBand = -1;
3098 infoPtr->ichevronhotBand = -2;
3100 return TRUE;
3103 static LRESULT
3104 REBAR_MouseMove (REBAR_INFO *infoPtr, LPARAM lParam)
3106 REBAR_BAND *lpChevronBand;
3107 POINT ptMove;
3109 ptMove.x = (short)LOWORD(lParam);
3110 ptMove.y = (short)HIWORD(lParam);
3112 /* if we are currently dragging a band */
3113 if (infoPtr->iGrabbedBand >= 0)
3115 REBAR_BAND *band;
3116 int yPtMove = (infoPtr->dwStyle & CCS_VERT ? ptMove.x : ptMove.y);
3118 if (GetCapture() != infoPtr->hwndSelf)
3119 ERR("We are dragging but haven't got capture?!?\n");
3121 band = REBAR_GetBand(infoPtr, infoPtr->iGrabbedBand);
3123 /* if mouse did not move much, exit */
3124 if ((abs(ptMove.x - infoPtr->dragNow.x) <= mindragx) &&
3125 (abs(ptMove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3127 /* on first significant mouse movement, issue notify */
3128 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
3129 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
3130 /* Notify returned TRUE - abort drag */
3131 infoPtr->dragStart.x = 0;
3132 infoPtr->dragStart.y = 0;
3133 infoPtr->dragNow = infoPtr->dragStart;
3134 infoPtr->iGrabbedBand = -1;
3135 ReleaseCapture ();
3136 return 0;
3138 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
3141 /* Test for valid drag case - must not be first band in row */
3142 if ((yPtMove < band->rcBand.top) ||
3143 (yPtMove > band->rcBand.bottom)) {
3144 REBAR_HandleUDDrag (infoPtr, &ptMove);
3146 else {
3147 REBAR_HandleLRDrag (infoPtr, &ptMove);
3150 else
3152 INT iHitBand;
3153 UINT htFlags;
3154 TRACKMOUSEEVENT trackinfo;
3156 REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
3158 if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
3160 lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3161 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3163 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3164 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3166 infoPtr->ichevronhotBand = -2;
3169 if (htFlags == RBHT_CHEVRON)
3171 /* fill in the TRACKMOUSEEVENT struct */
3172 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
3173 trackinfo.dwFlags = TME_QUERY;
3174 trackinfo.hwndTrack = infoPtr->hwndSelf;
3175 trackinfo.dwHoverTime = 0;
3177 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
3178 _TrackMouseEvent(&trackinfo);
3180 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
3181 if(!(trackinfo.dwFlags & TME_LEAVE))
3183 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
3185 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
3186 /* and can properly deactivate the hot chevron */
3187 _TrackMouseEvent(&trackinfo);
3190 lpChevronBand = REBAR_GetBand(infoPtr, iHitBand);
3191 if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
3193 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
3194 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3195 infoPtr->ichevronhotBand = iHitBand;
3198 infoPtr->iOldBand = iHitBand;
3201 return 0;
3205 static inline LRESULT
3206 REBAR_NCCalcSize (const REBAR_INFO *infoPtr, RECT *rect)
3208 HTHEME theme;
3210 if (infoPtr->dwStyle & WS_BORDER) {
3211 rect->left = min(rect->left + GetSystemMetrics(SM_CXEDGE), rect->right);
3212 rect->right = max(rect->right - GetSystemMetrics(SM_CXEDGE), rect->left);
3213 rect->top = min(rect->top + GetSystemMetrics(SM_CYEDGE), rect->bottom);
3214 rect->bottom = max(rect->bottom - GetSystemMetrics(SM_CYEDGE), rect->top);
3216 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3218 /* FIXME: should use GetThemeInt */
3219 rect->top = min(rect->top + 1, rect->bottom);
3221 TRACE("new client=(%s)\n", wine_dbgstr_rect(rect));
3222 return 0;
3226 static LRESULT
3227 REBAR_NCCreate (HWND hwnd, const CREATESTRUCTW *cs)
3229 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3230 RECT wnrc1, clrc1;
3231 NONCLIENTMETRICSW ncm;
3232 HFONT tfont;
3234 if (infoPtr) {
3235 ERR("Strange info structure pointer *not* NULL\n");
3236 return FALSE;
3239 if (TRACE_ON(rebar)) {
3240 GetWindowRect(hwnd, &wnrc1);
3241 GetClientRect(hwnd, &clrc1);
3242 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
3243 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
3244 cs->x, cs->y, cs->cx, cs->cy);
3247 /* allocate memory for info structure */
3248 infoPtr = Alloc (sizeof(REBAR_INFO));
3249 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
3251 /* initialize info structure - initial values are 0 */
3252 infoPtr->clrBk = CLR_NONE;
3253 infoPtr->clrText = CLR_NONE;
3254 infoPtr->clrBtnText = comctl32_color.clrBtnText;
3255 infoPtr->clrBtnFace = comctl32_color.clrBtnFace;
3256 infoPtr->iOldBand = -1;
3257 infoPtr->ichevronhotBand = -2;
3258 infoPtr->iGrabbedBand = -1;
3259 infoPtr->hwndSelf = hwnd;
3260 infoPtr->DoRedraw = TRUE;
3261 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3262 infoPtr->hcurHorz = LoadCursorW (0, (LPWSTR)IDC_SIZEWE);
3263 infoPtr->hcurVert = LoadCursorW (0, (LPWSTR)IDC_SIZENS);
3264 infoPtr->hcurDrag = LoadCursorW (0, (LPWSTR)IDC_SIZE);
3265 infoPtr->fStatus = 0;
3266 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3267 infoPtr->bands = DPA_Create(8);
3269 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3270 REBAR_NotifyFormat(infoPtr, NF_REQUERY);
3272 /* Stow away the original style */
3273 infoPtr->orgStyle = cs->style;
3274 /* add necessary styles to the requested styles */
3275 infoPtr->dwStyle = cs->style | WS_VISIBLE;
3276 if ((infoPtr->dwStyle & CCS_LAYOUT_MASK) == 0)
3277 infoPtr->dwStyle |= CCS_TOP;
3278 SetWindowLongW (hwnd, GWL_STYLE, infoPtr->dwStyle);
3280 /* get font handle for Caption Font */
3281 ncm.cbSize = sizeof(ncm);
3282 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
3283 /* if the font is bold, set to normal */
3284 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3285 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3287 tfont = CreateFontIndirectW (&ncm.lfCaptionFont);
3288 if (tfont) {
3289 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3292 return TRUE;
3296 static LRESULT
3297 REBAR_NCHitTest (const REBAR_INFO *infoPtr, LPARAM lParam)
3299 NMMOUSE nmmouse;
3300 POINT clpt;
3301 INT i;
3302 UINT scrap;
3303 LRESULT ret = HTCLIENT;
3306 * Differences from doc at MSDN (as observed with version 4.71 of
3307 * comctl32.dll
3308 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3309 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3310 * 3. native always seems to return HTCLIENT if notify return is 0.
3313 clpt.x = (short)LOWORD(lParam);
3314 clpt.y = (short)HIWORD(lParam);
3315 ScreenToClient (infoPtr->hwndSelf, &clpt);
3316 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3317 (INT *)&nmmouse.dwItemSpec);
3318 nmmouse.dwItemData = 0;
3319 nmmouse.pt = clpt;
3320 nmmouse.dwHitInfo = 0;
3321 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3322 TRACE("notify changed return value from %ld to %d\n",
3323 ret, i);
3324 ret = (LRESULT) i;
3326 TRACE("returning %ld, client point (%d,%d)\n", ret, clpt.x, clpt.y);
3327 return ret;
3331 static LRESULT
3332 REBAR_NCPaint (const REBAR_INFO *infoPtr)
3334 RECT rcWindow;
3335 HDC hdc;
3336 HTHEME theme;
3338 if (infoPtr->dwStyle & WS_MINIMIZE)
3339 return 0; /* Nothing to do */
3341 if (infoPtr->dwStyle & WS_BORDER) {
3343 /* adjust rectangle and draw the necessary edge */
3344 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3345 return 0;
3346 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3347 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3348 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3349 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3350 ReleaseDC( infoPtr->hwndSelf, hdc );
3352 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3354 /* adjust rectangle and draw the necessary edge */
3355 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3356 return 0;
3357 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3358 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3359 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3360 DrawThemeEdge (theme, hdc, 0, 0, &rcWindow, BDR_RAISEDINNER, BF_TOP, NULL);
3361 ReleaseDC( infoPtr->hwndSelf, hdc );
3364 return 0;
3368 static LRESULT
3369 REBAR_NotifyFormat (REBAR_INFO *infoPtr, LPARAM cmd)
3371 INT i;
3373 if (cmd == NF_REQUERY) {
3374 i = SendMessageW(REBAR_GetNotifyParent (infoPtr),
3375 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
3376 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
3377 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
3378 i = NFR_ANSI;
3380 infoPtr->bUnicode = (i == NFR_UNICODE);
3381 return (LRESULT)i;
3383 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3387 static LRESULT
3388 REBAR_Paint (const REBAR_INFO *infoPtr, HDC hdc)
3390 if (hdc) {
3391 TRACE("painting\n");
3392 REBAR_Refresh (infoPtr, hdc);
3393 } else {
3394 PAINTSTRUCT ps;
3395 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
3396 TRACE("painting (%s)\n", wine_dbgstr_rect(&ps.rcPaint));
3397 if (ps.fErase) {
3398 /* Erase area of paint if requested */
3399 REBAR_EraseBkGnd (infoPtr, hdc);
3401 REBAR_Refresh (infoPtr, hdc);
3402 EndPaint (infoPtr->hwndSelf, &ps);
3405 return 0;
3409 static LRESULT
3410 REBAR_SetCursor (const REBAR_INFO *infoPtr, LPARAM lParam)
3412 POINT pt;
3413 UINT flags;
3415 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
3417 GetCursorPos (&pt);
3418 ScreenToClient (infoPtr->hwndSelf, &pt);
3420 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
3422 if (flags == RBHT_GRABBER) {
3423 if ((infoPtr->dwStyle & CCS_VERT) &&
3424 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
3425 SetCursor (infoPtr->hcurVert);
3426 else
3427 SetCursor (infoPtr->hcurHorz);
3429 else if (flags != RBHT_CLIENT)
3430 SetCursor (infoPtr->hcurArrow);
3432 return 0;
3436 static LRESULT
3437 REBAR_SetFont (REBAR_INFO *infoPtr, HFONT font)
3439 REBAR_BAND *lpBand;
3440 UINT i;
3442 infoPtr->hFont = font;
3444 /* revalidate all bands to change sizes of text in headers of bands */
3445 for (i=0; i<infoPtr->uNumBands; i++) {
3446 lpBand = REBAR_GetBand(infoPtr, i);
3447 REBAR_ValidateBand (infoPtr, lpBand);
3450 REBAR_Layout(infoPtr);
3451 return 0;
3455 /*****************************************************
3457 * Handles the WM_SETREDRAW message.
3459 * Documentation:
3460 * According to testing V4.71 of COMCTL32 returns the
3461 * *previous* status of the redraw flag (either 0 or -1)
3462 * instead of the MSDN documented value of 0 if handled
3464 *****************************************************/
3465 static inline LRESULT
3466 REBAR_SetRedraw (REBAR_INFO *infoPtr, BOOL redraw)
3468 BOOL oldredraw = infoPtr->DoRedraw;
3470 TRACE("set to %s, fStatus=%08x\n",
3471 (redraw) ? "TRUE" : "FALSE", infoPtr->fStatus);
3472 infoPtr->DoRedraw = redraw;
3473 if (redraw) {
3474 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
3475 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
3476 REBAR_ForceResize (infoPtr);
3477 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3479 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
3481 return (oldredraw) ? -1 : 0;
3485 static LRESULT
3486 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3488 TRACE("wParam=%lx, lParam=%lx\n", wParam, lParam);
3490 /* avoid _Layout resize recursion (but it shouldn't be infinite and it seems Windows does recurse) */
3491 if (infoPtr->fStatus & SELF_RESIZE) {
3492 infoPtr->fStatus &= ~SELF_RESIZE;
3493 TRACE("SELF_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
3494 infoPtr->fStatus, lParam);
3495 return 0;
3498 if (infoPtr->dwStyle & RBS_AUTOSIZE)
3499 REBAR_AutoSize(infoPtr, TRUE);
3500 else
3501 REBAR_Layout(infoPtr);
3503 return 0;
3507 static LRESULT
3508 REBAR_StyleChanged (REBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
3510 TRACE("current style=%08x, styleOld=%08x, style being set to=%08x\n",
3511 infoPtr->dwStyle, lpStyle->styleOld, lpStyle->styleNew);
3512 if (nType == GWL_STYLE)
3514 infoPtr->orgStyle = infoPtr->dwStyle = lpStyle->styleNew;
3515 if (GetWindowTheme (infoPtr->hwndSelf))
3516 infoPtr->dwStyle &= ~WS_BORDER;
3517 /* maybe it should be COMMON_STYLES like in toolbar */
3518 if ((lpStyle->styleNew ^ lpStyle->styleOld) & CCS_VERT)
3519 REBAR_Layout(infoPtr);
3521 return FALSE;
3524 /* update theme after a WM_THEMECHANGED message */
3525 static LRESULT theme_changed (REBAR_INFO* infoPtr)
3527 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
3528 CloseThemeData (theme);
3529 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
3530 /* WS_BORDER disappears when theming is enabled and reappears when
3531 * disabled... */
3532 infoPtr->dwStyle &= ~WS_BORDER;
3533 infoPtr->dwStyle |= theme ? 0 : (infoPtr->orgStyle & WS_BORDER);
3534 return 0;
3537 static LRESULT
3538 REBAR_WindowPosChanged (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3540 LRESULT ret;
3541 RECT rc;
3543 ret = DefWindowProcW(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
3544 wParam, lParam);
3545 GetWindowRect(infoPtr->hwndSelf, &rc);
3546 TRACE("hwnd %p new pos (%s)\n", infoPtr->hwndSelf, wine_dbgstr_rect(&rc));
3547 return ret;
3551 static LRESULT WINAPI
3552 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3554 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3556 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
3557 hwnd, uMsg, wParam, lParam);
3558 if (!infoPtr && (uMsg != WM_NCCREATE))
3559 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3560 switch (uMsg)
3562 /* case RB_BEGINDRAG: */
3564 case RB_DELETEBAND:
3565 return REBAR_DeleteBand (infoPtr, wParam);
3567 /* case RB_DRAGMOVE: */
3568 /* case RB_ENDDRAG: */
3570 case RB_GETBANDBORDERS:
3571 return REBAR_GetBandBorders (infoPtr, wParam, (LPRECT)lParam);
3573 case RB_GETBANDCOUNT:
3574 return REBAR_GetBandCount (infoPtr);
3576 case RB_GETBANDINFO_OLD:
3577 case RB_GETBANDINFOA:
3578 case RB_GETBANDINFOW:
3579 return REBAR_GetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3580 uMsg == RB_GETBANDINFOW);
3581 case RB_GETBARHEIGHT:
3582 return REBAR_GetBarHeight (infoPtr);
3584 case RB_GETBARINFO:
3585 return REBAR_GetBarInfo (infoPtr, (LPREBARINFO)lParam);
3587 case RB_GETBKCOLOR:
3588 return REBAR_GetBkColor (infoPtr);
3590 /* case RB_GETCOLORSCHEME: */
3591 /* case RB_GETDROPTARGET: */
3593 case RB_GETPALETTE:
3594 return REBAR_GetPalette (infoPtr);
3596 case RB_GETRECT:
3597 return REBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
3599 case RB_GETROWCOUNT:
3600 return REBAR_GetRowCount (infoPtr);
3602 case RB_GETROWHEIGHT:
3603 return REBAR_GetRowHeight (infoPtr, wParam);
3605 case RB_GETTEXTCOLOR:
3606 return REBAR_GetTextColor (infoPtr);
3608 case RB_GETTOOLTIPS:
3609 return REBAR_GetToolTips (infoPtr);
3611 case RB_GETUNICODEFORMAT:
3612 return REBAR_GetUnicodeFormat (infoPtr);
3614 case CCM_GETVERSION:
3615 return REBAR_GetVersion (infoPtr);
3617 case RB_HITTEST:
3618 return REBAR_HitTest (infoPtr, (LPRBHITTESTINFO)lParam);
3620 case RB_IDTOINDEX:
3621 return REBAR_IdToIndex (infoPtr, wParam);
3623 case RB_INSERTBANDA:
3624 case RB_INSERTBANDW:
3625 return REBAR_InsertBandT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3626 uMsg == RB_INSERTBANDW);
3627 case RB_MAXIMIZEBAND:
3628 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
3630 case RB_MINIMIZEBAND:
3631 return REBAR_MinimizeBand (infoPtr, wParam);
3633 case RB_MOVEBAND:
3634 return REBAR_MoveBand (infoPtr, wParam, lParam);
3636 case RB_PUSHCHEVRON:
3637 return REBAR_PushChevron (infoPtr, wParam, lParam);
3639 case RB_SETBANDINFOA:
3640 case RB_SETBANDINFOW:
3641 return REBAR_SetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3642 uMsg == RB_SETBANDINFOW);
3643 case RB_SETBARINFO:
3644 return REBAR_SetBarInfo (infoPtr, (LPREBARINFO)lParam);
3646 case RB_SETBKCOLOR:
3647 return REBAR_SetBkColor (infoPtr, lParam);
3649 /* case RB_SETCOLORSCHEME: */
3650 /* case RB_SETPALETTE: */
3652 case RB_SETPARENT:
3653 return REBAR_SetParent (infoPtr, (HWND)wParam);
3655 case RB_SETTEXTCOLOR:
3656 return REBAR_SetTextColor (infoPtr, lParam);
3658 /* case RB_SETTOOLTIPS: */
3660 case RB_SETUNICODEFORMAT:
3661 return REBAR_SetUnicodeFormat (infoPtr, wParam);
3663 case CCM_SETVERSION:
3664 return REBAR_SetVersion (infoPtr, (INT)wParam);
3666 case RB_SHOWBAND:
3667 return REBAR_ShowBand (infoPtr, wParam, lParam);
3669 case RB_SIZETORECT:
3670 return REBAR_SizeToRect (infoPtr, (LPCRECT)lParam);
3673 /* Messages passed to parent */
3674 case WM_COMMAND:
3675 case WM_DRAWITEM:
3676 case WM_NOTIFY:
3677 case WM_MEASUREITEM:
3678 return SendMessageW(REBAR_GetNotifyParent (infoPtr), uMsg, wParam, lParam);
3681 /* case WM_CHARTOITEM: supported according to ControlSpy */
3683 case WM_CREATE:
3684 return REBAR_Create (infoPtr, (LPCREATESTRUCTW)lParam);
3686 case WM_DESTROY:
3687 return REBAR_Destroy (infoPtr);
3689 case WM_ERASEBKGND:
3690 return REBAR_EraseBkGnd (infoPtr, (HDC)wParam);
3692 case WM_GETFONT:
3693 return REBAR_GetFont (infoPtr);
3695 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
3697 case WM_LBUTTONDOWN:
3698 return REBAR_LButtonDown (infoPtr, lParam);
3700 case WM_LBUTTONUP:
3701 return REBAR_LButtonUp (infoPtr);
3703 case WM_MOUSEMOVE:
3704 return REBAR_MouseMove (infoPtr, lParam);
3706 case WM_MOUSELEAVE:
3707 return REBAR_MouseLeave (infoPtr);
3709 case WM_NCCALCSIZE:
3710 return REBAR_NCCalcSize (infoPtr, (RECT*)lParam);
3712 case WM_NCCREATE:
3713 return REBAR_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
3715 case WM_NCHITTEST:
3716 return REBAR_NCHitTest (infoPtr, lParam);
3718 case WM_NCPAINT:
3719 return REBAR_NCPaint (infoPtr);
3721 case WM_NOTIFYFORMAT:
3722 return REBAR_NotifyFormat (infoPtr, lParam);
3724 case WM_PRINTCLIENT:
3725 case WM_PAINT:
3726 return REBAR_Paint (infoPtr, (HDC)wParam);
3728 /* case WM_PALETTECHANGED: supported according to ControlSpy */
3729 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
3730 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
3731 /* case WM_RBUTTONUP: supported according to ControlSpy */
3733 case WM_SETCURSOR:
3734 return REBAR_SetCursor (infoPtr, lParam);
3736 case WM_SETFONT:
3737 return REBAR_SetFont (infoPtr, (HFONT)wParam);
3739 case WM_SETREDRAW:
3740 return REBAR_SetRedraw (infoPtr, wParam);
3742 case WM_SIZE:
3743 return REBAR_Size (infoPtr, wParam, lParam);
3745 case WM_STYLECHANGED:
3746 return REBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
3748 case WM_THEMECHANGED:
3749 return theme_changed (infoPtr);
3751 case WM_SYSCOLORCHANGE:
3752 COMCTL32_RefreshSysColors();
3753 return 0;
3755 /* case WM_VKEYTOITEM: supported according to ControlSpy */
3756 /* case WM_WININICHANGE: */
3758 case WM_WINDOWPOSCHANGED:
3759 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
3761 default:
3762 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
3763 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
3764 uMsg, wParam, lParam);
3765 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3770 VOID
3771 REBAR_Register (void)
3773 WNDCLASSW wndClass;
3775 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
3776 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
3777 wndClass.lpfnWndProc = REBAR_WindowProc;
3778 wndClass.cbClsExtra = 0;
3779 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
3780 wndClass.hCursor = 0;
3781 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
3782 #if GLATESTING
3783 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
3784 #endif
3785 wndClass.lpszClassName = REBARCLASSNAMEW;
3787 RegisterClassW (&wndClass);
3789 mindragx = GetSystemMetrics (SM_CXDRAG);
3790 mindragy = GetSystemMetrics (SM_CYDRAG);
3795 VOID
3796 REBAR_Unregister (void)
3798 UnregisterClassW (REBARCLASSNAMEW, NULL);