ia2comproxy: Introduce new proxy stub DLL for IAccessible2.
[wine.git] / dlls / comctl32 / rebar.c
blob61fd30c445f1e8d24830de39a3f134a8046121a5
1 /*
2 * Rebar control
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2007, 2008 Mikolaj Zalewski
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 19, 2004, by Robert Shearman.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features or bugs please note them below.
30 * TODO
31 * Styles:
32 * - RBS_DBLCLKTOGGLE
33 * - RBS_FIXEDORDER
34 * - RBS_REGISTERDROP
35 * - RBS_TOOLTIPS
36 * Messages:
37 * - RB_BEGINDRAG
38 * - RB_DRAGMOVE
39 * - RB_ENDDRAG
40 * - RB_GETBANDMARGINS
41 * - RB_GETCOLORSCHEME
42 * - RB_GETDROPTARGET
43 * - RB_GETPALETTE
44 * - RB_SETCOLORSCHEME
45 * - RB_SETPALETTE
46 * - RB_SETTOOLTIPS
47 * - WM_CHARTOITEM
48 * - WM_LBUTTONDBLCLK
49 * - WM_PALETTECHANGED
50 * - WM_QUERYNEWPALETTE
51 * - WM_RBUTTONDOWN
52 * - WM_RBUTTONUP
53 * - WM_SYSCOLORCHANGE
54 * - WM_VKEYTOITEM
55 * - WM_WININICHANGE
56 * Notifications:
57 * - NM_HCHITTEST
58 * - NM_RELEASEDCAPTURE
59 * - RBN_AUTOBREAK
60 * - RBN_GETOBJECT
61 * - RBN_MINMAX
62 * Band styles:
63 * - RBBS_FIXEDBMP
64 * Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
65 * to set the size of the separator width (the value SEP_WIDTH_SIZE
66 * in here). Should be fixed!!
70 * Testing: set to 1 to make background brush *always* green
72 #define GLATESTING 0
75 * 3. REBAR_MoveChildWindows should have a loop because more than
76 * one pass (together with the RBN_CHILDSIZEs) is made on
77 * at least RB_INSERTBAND
80 #include <assert.h>
81 #include <stdarg.h>
82 #include <stdlib.h>
83 #include <string.h>
85 #include "windef.h"
86 #include "winbase.h"
87 #include "wingdi.h"
88 #include "winuser.h"
89 #include "winnls.h"
90 #include "commctrl.h"
91 #include "comctl32.h"
92 #include "uxtheme.h"
93 #include "vssym32.h"
94 #include "wine/debug.h"
96 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
98 typedef struct
100 UINT fStyle;
101 UINT fMask;
102 COLORREF clrFore;
103 COLORREF clrBack;
104 INT iImage;
105 HWND hwndChild;
106 UINT cxMinChild; /* valid if _CHILDSIZE */
107 UINT cyMinChild; /* valid if _CHILDSIZE */
108 UINT cx; /* valid if _SIZE */
109 HBITMAP hbmBack;
110 UINT wID;
111 UINT cyChild; /* valid if _CHILDSIZE */
112 UINT cyMaxChild; /* valid if _CHILDSIZE */
113 UINT cyIntegral; /* valid if _CHILDSIZE */
114 UINT cxIdeal;
115 LPARAM lParam;
116 UINT cxHeader;
118 INT cxEffective; /* current cx for band */
119 UINT cyHeader; /* the height of the header */
120 UINT cxMinBand; /* minimum cx for band */
121 UINT cyMinBand; /* minimum cy for band */
123 UINT cyRowSoFar; /* for RBS_VARHEIGHT - the height of the row if it would break on this band (set by _Layout) */
124 INT iRow; /* zero-based index of the row this band assigned to */
125 UINT fStatus; /* status flags, reset only by _Validate */
126 UINT fDraw; /* drawing flags, reset only by _Layout */
127 UINT uCDret; /* last return from NM_CUSTOMDRAW */
128 RECT rcBand; /* calculated band rectangle - coordinates swapped for CCS_VERT */
129 RECT rcGripper; /* calculated gripper rectangle */
130 RECT rcCapImage; /* calculated caption image rectangle */
131 RECT rcCapText; /* calculated caption text rectangle */
132 RECT rcChild; /* calculated child rectangle */
133 RECT rcChevron; /* calculated chevron rectangle */
135 LPWSTR lpText;
136 HWND hwndPrevParent;
137 } REBAR_BAND;
139 /* has a value of: 0, CCS_TOP, CCS_NOMOVEY, CCS_BOTTOM */
140 #define CCS_LAYOUT_MASK 0x3
142 /* fStatus flags */
143 #define HAS_GRIPPER 0x00000001
144 #define HAS_IMAGE 0x00000002
145 #define HAS_TEXT 0x00000004
147 /* fDraw flags */
148 #define DRAW_GRIPPER 0x00000001
149 #define DRAW_IMAGE 0x00000002
150 #define DRAW_TEXT 0x00000004
151 #define DRAW_CHEVRONHOT 0x00000040
152 #define DRAW_CHEVRONPUSHED 0x00000080
153 #define NTF_INVALIDATE 0x01000000
155 typedef struct
157 COLORREF clrBk; /* background color */
158 COLORREF clrText; /* text color */
159 COLORREF clrBtnText; /* system color for BTNTEXT */
160 COLORREF clrBtnFace; /* system color for BTNFACE */
161 HIMAGELIST himl; /* handle to imagelist */
162 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
163 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
164 HWND hwndSelf; /* handle of REBAR window itself */
165 HWND hwndToolTip; /* handle to the tool tip control */
166 HWND hwndNotify; /* notification window (parent) */
167 HFONT hDefaultFont;
168 HFONT hFont; /* handle to the rebar's font */
169 SIZE imageSize; /* image size (image list) */
170 DWORD dwStyle; /* window style */
171 DWORD orgStyle; /* original style (dwStyle may change) */
172 SIZE calcSize; /* calculated rebar size - coordinates swapped for CCS_VERT */
173 BOOL bUnicode; /* TRUE if parent wants notify in W format */
174 BOOL DoRedraw; /* TRUE to actually draw bands */
175 UINT fStatus; /* Status flags (see below) */
176 HCURSOR hcurArrow; /* handle to the arrow cursor */
177 HCURSOR hcurHorz; /* handle to the EW cursor */
178 HCURSOR hcurVert; /* handle to the NS cursor */
179 HCURSOR hcurDrag; /* handle to the drag cursor */
180 INT iVersion; /* version number */
181 POINT dragStart; /* x,y of button down */
182 POINT dragNow; /* x,y of this MouseMove */
183 INT iOldBand; /* last band that had the mouse cursor over it */
184 INT ihitoffset; /* offset of hotspot from gripper.left */
185 INT ichevronhotBand; /* last band that had a hot chevron */
186 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
188 HDPA bands; /* pointer to the array of rebar bands */
189 } REBAR_INFO;
191 /* fStatus flags */
192 #define BEGIN_DRAG_ISSUED 0x00000001
193 #define SELF_RESIZE 0x00000002
194 #define BAND_NEEDS_REDRAW 0x00000020
196 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
197 #define RBBS_UNDOC_FIXEDHEADER 0x40000000
199 /* ---- REBAR layout constants. Mostly determined by ---- */
200 /* ---- experiment on WIN 98. ---- */
202 /* Width (or height) of separators between bands (either horz. or */
203 /* vert.). True only if RBS_BANDBORDERS is set */
204 #define SEP_WIDTH_SIZE 2
205 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
207 /* Blank (background color) space between Gripper (if present) */
208 /* and next item (image, text, or window). Always present */
209 #define REBAR_ALWAYS_SPACE 4
211 /* Blank (background color) space after Image (if present). */
212 #define REBAR_POST_IMAGE 2
214 /* Blank (background color) space after Text (if present). */
215 #define REBAR_POST_TEXT 4
217 /* Height of vertical gripper in a CCS_VERT rebar. */
218 #define GRIPPER_HEIGHT 16
220 /* Blank (background color) space before Gripper (if present). */
221 #define REBAR_PRE_GRIPPER 2
223 /* Width (of normal vertical gripper) or height (of horz. gripper) */
224 /* if present. */
225 #define GRIPPER_WIDTH 3
227 /* Width of the chevron button if present */
228 #define CHEVRON_WIDTH 10
230 /* the gap between the child and the next band */
231 #define REBAR_POST_CHILD 4
233 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
234 /* either top or bottom */
235 #define REBAR_DIVIDER 2
237 /* height of a rebar without a child */
238 #define REBAR_NO_CHILD_HEIGHT 4
240 /* minimum vertical height of a normal bar */
241 /* or minimum width of a CCS_VERT bar - from experiment on Win2k */
242 #define REBAR_MINSIZE 23
244 /* This is the increment that is used over the band height */
245 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
247 /* ---- End of REBAR layout constants. ---- */
249 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
251 /* The following define determines if a given band is hidden */
252 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
253 ((infoPtr->dwStyle & CCS_VERT) && \
254 ((a)->fStyle & RBBS_NOVERT)))
256 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
258 static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, LPARAM lParam);
259 static void REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout);
261 /* no index check here */
262 static inline REBAR_BAND* REBAR_GetBand(const REBAR_INFO *infoPtr, INT i)
264 assert(i >= 0 && i < infoPtr->uNumBands);
265 return DPA_GetPtr(infoPtr->bands, i);
268 /* "constant values" retrieved when DLL was initialized */
269 /* FIXME we do this when the classes are registered. */
270 static UINT mindragx = 0;
271 static UINT mindragy = 0;
273 static const char * const band_stylename[] = {
274 "RBBS_BREAK", /* 0001 */
275 "RBBS_FIXEDSIZE", /* 0002 */
276 "RBBS_CHILDEDGE", /* 0004 */
277 "RBBS_HIDDEN", /* 0008 */
278 "RBBS_NOVERT", /* 0010 */
279 "RBBS_FIXEDBMP", /* 0020 */
280 "RBBS_VARIABLEHEIGHT", /* 0040 */
281 "RBBS_GRIPPERALWAYS", /* 0080 */
282 "RBBS_NOGRIPPER", /* 0100 */
283 "RBBS_USECHEVRON", /* 0200 */
284 "RBBS_HIDETITLE", /* 0400 */
285 "RBBS_TOPALIGN", /* 0800 */
286 NULL };
288 static const char * const band_maskname[] = {
289 "RBBIM_STYLE", /* 0x00000001 */
290 "RBBIM_COLORS", /* 0x00000002 */
291 "RBBIM_TEXT", /* 0x00000004 */
292 "RBBIM_IMAGE", /* 0x00000008 */
293 "RBBIM_CHILD", /* 0x00000010 */
294 "RBBIM_CHILDSIZE", /* 0x00000020 */
295 "RBBIM_SIZE", /* 0x00000040 */
296 "RBBIM_BACKGROUND", /* 0x00000080 */
297 "RBBIM_ID", /* 0x00000100 */
298 "RBBIM_IDEALSIZE", /* 0x00000200 */
299 "RBBIM_LPARAM", /* 0x00000400 */
300 "RBBIM_HEADERSIZE", /* 0x00000800 */
301 "RBBIM_CHEVRONLOCATION", /* 0x00001000 */
302 "RBBIM_CHEVRONSTATE", /* 0x00002000 */
303 NULL };
305 static const WCHAR themeClass[] = L"Rebar";
307 static CHAR *
308 REBAR_FmtStyle(char *buffer, UINT style)
310 INT i = 0;
312 *buffer = 0;
313 while (band_stylename[i]) {
314 if (style & (1<<i)) {
315 if (*buffer) strcat(buffer, " | ");
316 strcat(buffer, band_stylename[i]);
318 i++;
320 return buffer;
324 static CHAR *
325 REBAR_FmtMask(char *buffer, UINT mask)
327 INT i = 0;
329 *buffer = 0;
330 while (band_maskname[i]) {
331 if (mask & (1<<i)) {
332 if (*buffer) strcat(buffer, " | ");
333 strcat(buffer, band_maskname[i]);
335 i++;
337 return buffer;
341 static VOID
342 REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
344 char buff[300];
346 if( !TRACE_ON(rebar) ) return;
347 TRACE("band info: ");
348 if (pB->fMask & RBBIM_ID)
349 TRACE("ID=%u, ", pB->wID);
350 TRACE("size=%u, child=%p", pB->cbSize, pB->hwndChild);
351 if (pB->fMask & RBBIM_COLORS)
352 TRACE(", clrF=%#lx, clrB=%#lx", pB->clrFore, pB->clrBack);
353 TRACE("\n");
355 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(buff, pB->fMask));
356 if (pB->fMask & RBBIM_STYLE)
357 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(buff, pB->fStyle));
358 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
359 TRACE("band info:");
360 if (pB->fMask & RBBIM_SIZE)
361 TRACE(" cx=%u", pB->cx);
362 if (pB->fMask & RBBIM_IDEALSIZE)
363 TRACE(" xIdeal=%u", pB->cxIdeal);
364 if (pB->fMask & RBBIM_HEADERSIZE)
365 TRACE(" xHeader=%u", pB->cxHeader);
366 if (pB->fMask & RBBIM_LPARAM)
367 TRACE(" lParam %Ix", pB->lParam);
368 TRACE("\n");
370 if (pB->fMask & RBBIM_CHILDSIZE)
371 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
372 pB->cxMinChild,
373 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
376 static VOID
377 REBAR_DumpBand (const REBAR_INFO *iP)
379 char buff[300];
380 REBAR_BAND *pB;
381 UINT i;
383 if(! TRACE_ON(rebar) ) return;
385 TRACE("hwnd=%p: color=%#lx/%#lx, bands=%u, rows=%u, cSize=%ld,%ld\n",
386 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
387 iP->calcSize.cx, iP->calcSize.cy);
388 TRACE("hwnd=%p: flags=%#x, dragStart=%ld,%ld, dragNow=%ld,%ld, iGrabbedBand=%d\n",
389 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
390 iP->dragNow.x, iP->dragNow.y,
391 iP->iGrabbedBand);
392 TRACE("hwnd=%p: style=%#lx, notify in Unicode=%s, redraw=%s\n",
393 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
394 (iP->DoRedraw)?"TRUE":"FALSE");
395 for (i = 0; i < iP->uNumBands; i++) {
396 pB = REBAR_GetBand(iP, i);
397 TRACE("band # %u:", i);
398 if (pB->fMask & RBBIM_ID)
399 TRACE(" ID=%u", pB->wID);
400 if (pB->fMask & RBBIM_CHILD)
401 TRACE(" child=%p", pB->hwndChild);
402 if (pB->fMask & RBBIM_COLORS)
403 TRACE(" clrF=%#lx clrB=%#lx", pB->clrFore, pB->clrBack);
404 TRACE("\n");
405 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(buff, pB->fMask));
406 if (pB->fMask & RBBIM_STYLE)
407 TRACE("band # %u: style=0x%08x (%s)\n", i, pB->fStyle, REBAR_FmtStyle(buff, pB->fStyle));
408 TRACE("band # %u: xHeader=%u",
409 i, pB->cxHeader);
410 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
411 if (pB->fMask & RBBIM_SIZE)
412 TRACE(" cx=%u", pB->cx);
413 if (pB->fMask & RBBIM_IDEALSIZE)
414 TRACE(" xIdeal=%u", pB->cxIdeal);
415 if (pB->fMask & RBBIM_LPARAM)
416 TRACE(" lParam %Ix", pB->lParam);
418 TRACE("\n");
419 if (RBBIM_CHILDSIZE)
420 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
421 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
422 if (pB->fMask & RBBIM_TEXT)
423 TRACE("band # %u: text=%s\n",
424 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
425 TRACE("band # %u: cxMinBand=%u, cxEffective=%u, cyMinBand=%u\n",
426 i, pB->cxMinBand, pB->cxEffective, pB->cyMinBand);
427 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
428 i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
429 wine_dbgstr_rect(&pB->rcGripper));
430 TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
431 i, wine_dbgstr_rect(&pB->rcCapImage),
432 wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
437 /* dest can be equal to src */
438 static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
440 if (infoPtr->dwStyle & CCS_VERT) {
441 int tmp;
442 tmp = src->left;
443 dest->left = src->top;
444 dest->top = tmp;
446 tmp = src->right;
447 dest->right = src->bottom;
448 dest->bottom = tmp;
449 } else {
450 *dest = *src;
454 static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
456 if (infoPtr->dwStyle & CCS_VERT)
457 return lpRect->bottom - lpRect->top;
458 return lpRect->right - lpRect->left;
461 static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
463 if (infoPtr->dwStyle & CCS_VERT)
464 return lpRect->right - lpRect->left;
465 return lpRect->bottom - lpRect->top;
468 static int round_child_height(const REBAR_BAND *lpBand, int cyHeight)
470 int cy = 0;
471 if (lpBand->cyIntegral == 0)
472 return cyHeight;
473 cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
474 cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
475 cy = min(cy, lpBand->cyMaxChild);
476 return cy;
479 static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
481 lpBand->cyMinBand = max(lpBand->cyHeader,
482 (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
485 static void
486 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
488 INT x, y;
489 HPEN hPen, hOldPen;
491 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
492 hOldPen = SelectObject ( hdc, hPen );
493 x = left + 2;
494 y = top;
495 MoveToEx (hdc, x, y, NULL);
496 LineTo (hdc, x+5, y++); x++;
497 MoveToEx (hdc, x, y, NULL);
498 LineTo (hdc, x+3, y++); x++;
499 MoveToEx (hdc, x, y, NULL);
500 LineTo (hdc, x+1, y);
501 SelectObject( hdc, hOldPen );
502 DeleteObject( hPen );
505 static HWND
506 REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
508 HWND parent, owner;
510 parent = infoPtr->hwndNotify;
511 if (!parent) {
512 parent = GetParent (infoPtr->hwndSelf);
513 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
514 if (owner) parent = owner;
516 return parent;
520 static INT
521 REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
523 HWND parent;
525 parent = REBAR_GetNotifyParent (infoPtr);
526 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
527 nmhdr->hwndFrom = infoPtr->hwndSelf;
528 nmhdr->code = code;
530 TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
532 return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
535 static INT
536 REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
538 NMREBAR notify_rebar;
540 notify_rebar.dwMask = 0;
541 if (uBand != -1) {
542 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
544 if (lpBand->fMask & RBBIM_ID) {
545 notify_rebar.dwMask |= RBNM_ID;
546 notify_rebar.wID = lpBand->wID;
548 if (lpBand->fMask & RBBIM_LPARAM) {
549 notify_rebar.dwMask |= RBNM_LPARAM;
550 notify_rebar.lParam = lpBand->lParam;
552 if (lpBand->fMask & RBBIM_STYLE) {
553 notify_rebar.dwMask |= RBNM_STYLE;
554 notify_rebar.fStyle = lpBand->fStyle;
557 notify_rebar.uBand = uBand;
558 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
561 static VOID
562 REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
564 HFONT hOldFont = 0;
565 INT oldBkMode = 0;
566 NMCUSTOMDRAW nmcd;
567 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
568 RECT rcBand;
570 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
572 if (lpBand->fDraw & DRAW_TEXT) {
573 hOldFont = SelectObject (hdc, infoPtr->hFont);
574 oldBkMode = SetBkMode (hdc, TRANSPARENT);
577 /* should test for CDRF_NOTIFYITEMDRAW here */
578 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
579 nmcd.hdc = hdc;
580 nmcd.rc = rcBand;
581 nmcd.rc.right = lpBand->rcCapText.right;
582 nmcd.rc.bottom = lpBand->rcCapText.bottom;
583 nmcd.dwItemSpec = lpBand->wID;
584 nmcd.uItemState = 0;
585 nmcd.lItemlParam = lpBand->lParam;
586 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
587 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
588 if (oldBkMode != TRANSPARENT)
589 SetBkMode (hdc, oldBkMode);
590 SelectObject (hdc, hOldFont);
591 return;
594 /* draw gripper */
595 if (lpBand->fDraw & DRAW_GRIPPER)
597 if (theme)
599 RECT rcGripper = lpBand->rcGripper;
600 int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
601 GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
602 OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
603 lpBand->rcGripper.top - rcGripper.top);
604 DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
606 else
607 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
610 /* draw caption image */
611 if (lpBand->fDraw & DRAW_IMAGE) {
612 POINT pt;
614 /* center image */
615 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
616 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
618 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
619 pt.x, pt.y,
620 ILD_TRANSPARENT);
623 /* draw caption text */
624 if (lpBand->fDraw & DRAW_TEXT) {
625 /* need to handle CDRF_NEWFONT here */
626 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
627 COLORREF oldcolor = CLR_NONE;
628 COLORREF new;
629 if (lpBand->clrFore != CLR_NONE) {
630 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
631 lpBand->clrFore;
632 oldcolor = SetTextColor (hdc, new);
634 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
635 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
636 if (oldBkMode != TRANSPARENT)
637 SetBkMode (hdc, oldBkMode);
638 if (lpBand->clrFore != CLR_NONE)
639 SetTextColor (hdc, oldcolor);
640 SelectObject (hdc, hOldFont);
643 if (!IsRectEmpty(&lpBand->rcChevron))
645 if (theme)
647 int stateId;
648 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
649 stateId = CHEVS_PRESSED;
650 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
651 stateId = CHEVS_HOT;
652 else
653 stateId = CHEVS_NORMAL;
654 DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
656 else
658 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
660 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
661 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
663 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
665 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
666 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
668 else
669 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
673 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
674 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
675 nmcd.hdc = hdc;
676 nmcd.rc = rcBand;
677 nmcd.rc.right = lpBand->rcCapText.right;
678 nmcd.rc.bottom = lpBand->rcCapText.bottom;
679 nmcd.dwItemSpec = lpBand->wID;
680 nmcd.uItemState = 0;
681 nmcd.lItemlParam = lpBand->lParam;
682 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
687 static VOID
688 REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
690 REBAR_BAND *lpBand;
691 UINT i;
693 if (!infoPtr->DoRedraw) return;
695 for (i = 0; i < infoPtr->uNumBands; i++) {
696 lpBand = REBAR_GetBand(infoPtr, i);
698 if (HIDDENBAND(lpBand)) continue;
700 /* now draw the band */
701 TRACE("[%p] drawing band %i, flags=%08x\n",
702 infoPtr->hwndSelf, i, lpBand->fDraw);
703 REBAR_DrawBand (hdc, infoPtr, lpBand);
708 static void
709 REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
710 /* Function: this routine initializes all the rectangles in */
711 /* each band in a row to fit in the adjusted rcBand rect. */
712 /* *** Supports only Horizontal bars. *** */
714 REBAR_BAND *lpBand;
715 UINT i, xoff;
716 RECT work;
718 for(i=rstart; i<rend; i++){
719 lpBand = REBAR_GetBand(infoPtr, i);
720 if (HIDDENBAND(lpBand)) {
721 SetRect (&lpBand->rcChild,
722 lpBand->rcBand.right, lpBand->rcBand.top,
723 lpBand->rcBand.right, lpBand->rcBand.bottom);
724 continue;
727 /* set initial gripper rectangle */
728 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
729 lpBand->rcBand.left, lpBand->rcBand.bottom);
731 /* calculate gripper rectangle */
732 if ( lpBand->fStatus & HAS_GRIPPER) {
733 lpBand->fDraw |= DRAW_GRIPPER;
734 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
735 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
736 InflateRect(&lpBand->rcGripper, 0, -2);
738 SetRect (&lpBand->rcCapImage,
739 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
740 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
742 else { /* no gripper will be drawn */
743 xoff = 0;
744 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
745 /* if no gripper but either image or text, then leave space */
746 xoff = REBAR_ALWAYS_SPACE;
747 SetRect (&lpBand->rcCapImage,
748 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
749 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
752 /* image is visible */
753 if (lpBand->fStatus & HAS_IMAGE) {
754 lpBand->fDraw |= DRAW_IMAGE;
755 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
756 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
758 /* set initial caption text rectangle */
759 SetRect (&lpBand->rcCapText,
760 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
761 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
763 else {
764 /* set initial caption text rectangle */
765 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
766 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
769 /* text is visible */
770 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
771 lpBand->fDraw |= DRAW_TEXT;
772 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
773 lpBand->rcCapText.right-REBAR_POST_TEXT);
776 /* set initial child window rectangle if there is a child */
777 if (lpBand->hwndChild) {
779 lpBand->rcChild.left = lpBand->rcBand.left + lpBand->cxHeader;
780 lpBand->rcChild.right = lpBand->rcBand.right - REBAR_POST_CHILD;
782 if (lpBand->cyChild > 0) {
784 UINT yoff = (lpBand->rcBand.bottom - lpBand->rcBand.top - lpBand->cyChild) / 2;
786 /* center child if height is known */
787 lpBand->rcChild.top = lpBand->rcBand.top + yoff;
788 lpBand->rcChild.bottom = lpBand->rcBand.top + yoff + lpBand->cyChild;
790 else {
791 lpBand->rcChild.top = lpBand->rcBand.top;
792 lpBand->rcChild.bottom = lpBand->rcBand.bottom;
795 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
797 lpBand->rcChild.right -= CHEVRON_WIDTH;
798 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
799 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
800 lpBand->rcChild.bottom);
803 else {
804 SetRect (&lpBand->rcChild,
805 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
806 lpBand->rcBand.right, lpBand->rcBand.bottom);
809 /* flag if notify required and invalidate rectangle */
810 if (lpBand->fDraw & NTF_INVALIDATE) {
811 lpBand->fDraw &= ~NTF_INVALIDATE;
812 work = lpBand->rcBand;
813 work.right += SEP_WIDTH;
814 work.bottom += SEP_WIDTH;
815 TRACE("invalidating %s\n", wine_dbgstr_rect(&work));
816 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
817 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
825 static VOID
826 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
827 /* Function: this routine initializes all the rectangles in */
828 /* each band in a row to fit in the adjusted rcBand rect. */
829 /* *** Supports only Vertical bars. *** */
831 REBAR_BAND *lpBand;
832 UINT i, xoff;
833 RECT work;
835 for(i=rstart; i<rend; i++){
836 RECT rcBand;
837 lpBand = REBAR_GetBand(infoPtr, i);
838 if (HIDDENBAND(lpBand)) continue;
840 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
842 /* set initial gripper rectangle */
843 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
845 /* calculate gripper rectangle */
846 if (lpBand->fStatus & HAS_GRIPPER) {
847 lpBand->fDraw |= DRAW_GRIPPER;
849 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
850 /* vertical gripper */
851 lpBand->rcGripper.left += 3;
852 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
853 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
854 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
856 /* initialize Caption image rectangle */
857 SetRect (&lpBand->rcCapImage, rcBand.left,
858 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
859 rcBand.right,
860 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
862 else {
863 /* horizontal gripper */
864 InflateRect(&lpBand->rcGripper, -2, 0);
865 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
866 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
868 /* initialize Caption image rectangle */
869 SetRect (&lpBand->rcCapImage, rcBand.left,
870 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
871 rcBand.right,
872 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
875 else { /* no gripper will be drawn */
876 xoff = 0;
877 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
878 /* if no gripper but either image or text, then leave space */
879 xoff = REBAR_ALWAYS_SPACE;
880 /* initialize Caption image rectangle */
881 SetRect (&lpBand->rcCapImage,
882 rcBand.left, rcBand.top+xoff,
883 rcBand.right, rcBand.top+xoff);
886 /* image is visible */
887 if (lpBand->fStatus & HAS_IMAGE) {
888 lpBand->fDraw |= DRAW_IMAGE;
890 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
891 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
893 /* set initial caption text rectangle */
894 SetRect (&lpBand->rcCapText,
895 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
896 rcBand.right, rcBand.top+lpBand->cxHeader);
898 else {
899 /* set initial caption text rectangle */
900 SetRect (&lpBand->rcCapText,
901 rcBand.left, lpBand->rcCapImage.bottom,
902 rcBand.right, rcBand.top+lpBand->cxHeader);
905 /* text is visible */
906 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
907 lpBand->fDraw |= DRAW_TEXT;
908 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
909 lpBand->rcCapText.bottom);
912 /* set initial child window rectangle if there is a child */
913 if (lpBand->hwndChild) {
914 int cxBand = rcBand.right - rcBand.left;
915 xoff = (cxBand - lpBand->cyChild) / 2;
916 SetRect (&lpBand->rcChild,
917 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
918 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
920 else {
921 SetRect (&lpBand->rcChild,
922 rcBand.left, rcBand.top+lpBand->cxHeader,
923 rcBand.right, rcBand.bottom);
926 if (lpBand->fDraw & NTF_INVALIDATE) {
927 lpBand->fDraw &= ~NTF_INVALIDATE;
928 work = rcBand;
929 work.bottom += SEP_WIDTH;
930 work.right += SEP_WIDTH;
931 TRACE("invalidating %s\n", wine_dbgstr_rect(&work));
932 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
933 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
940 static VOID
941 REBAR_ForceResize (REBAR_INFO *infoPtr)
942 /* Function: This changes the size of the REBAR window to that */
943 /* calculated by REBAR_Layout. */
945 INT x, y, width, height;
946 INT xedge = 0, yedge = 0;
947 RECT rcSelf;
949 TRACE("new size [%ld x %ld]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
951 if (infoPtr->dwStyle & CCS_NORESIZE)
952 return;
954 if (infoPtr->dwStyle & WS_BORDER)
956 xedge = GetSystemMetrics(SM_CXEDGE);
957 yedge = GetSystemMetrics(SM_CYEDGE);
958 /* swap for CCS_VERT? */
961 /* compute rebar window rect in parent client coordinates */
962 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
963 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
964 translate_rect(infoPtr, &rcSelf, &rcSelf);
966 height = infoPtr->calcSize.cy + 2*yedge;
967 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
968 RECT rcParent;
970 x = -xedge;
971 width = infoPtr->calcSize.cx + 2*xedge;
972 y = 0; /* quiet compiler warning */
973 switch ( infoPtr->dwStyle & CCS_LAYOUT_MASK) {
974 case 0: /* shouldn't happen - see NCCreate */
975 case CCS_TOP:
976 y = ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER) - yedge;
977 break;
978 case CCS_NOMOVEY:
979 y = rcSelf.top;
980 break;
981 case CCS_BOTTOM:
982 GetClientRect(GetParent(infoPtr->hwndSelf), &rcParent);
983 translate_rect(infoPtr, &rcParent, &rcParent);
984 y = rcParent.bottom - infoPtr->calcSize.cy - yedge;
985 break;
988 else {
989 x = rcSelf.left;
990 /* As on Windows if the CCS_NODIVIDER is not present the control will move
991 * 2 pixel down after every layout */
992 y = rcSelf.top + ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
993 width = rcSelf.right - rcSelf.left;
996 TRACE("hwnd %p, style %#lx, setting at (%d,%d) for (%d,%d)\n", infoPtr->hwndSelf, infoPtr->dwStyle,
997 x, y, width, height);
999 /* Set flag to ignore next WM_SIZE message and resize the window */
1000 infoPtr->fStatus |= SELF_RESIZE;
1001 if ((infoPtr->dwStyle & CCS_VERT) == 0)
1002 SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
1003 else
1004 SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
1005 infoPtr->fStatus &= ~SELF_RESIZE;
1009 static VOID
1010 REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
1012 REBAR_BAND *lpBand;
1013 WCHAR szClassName[40];
1014 UINT i;
1015 NMREBARCHILDSIZE rbcz;
1016 HDWP deferpos;
1018 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1019 ERR("BeginDeferWindowPos returned NULL\n");
1021 for (i = start; i < endplus; i++) {
1022 lpBand = REBAR_GetBand(infoPtr, i);
1024 if (HIDDENBAND(lpBand)) continue;
1025 if (lpBand->hwndChild) {
1026 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1028 /* Always generate the RBN_CHILDSIZE even if child
1029 did not change */
1030 rbcz.uBand = i;
1031 rbcz.wID = lpBand->wID;
1032 rbcz.rcChild = lpBand->rcChild;
1033 translate_rect(infoPtr, &rbcz.rcBand, &lpBand->rcBand);
1034 if (infoPtr->dwStyle & CCS_VERT)
1035 rbcz.rcBand.top += lpBand->cxHeader;
1036 else
1037 rbcz.rcBand.left += lpBand->cxHeader;
1038 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1039 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1040 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1041 TRACE(" from (%s) to (%s)\n",
1042 wine_dbgstr_rect(&lpBand->rcChild),
1043 wine_dbgstr_rect(&rbcz.rcChild));
1044 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1047 GetClassNameW (lpBand->hwndChild, szClassName, ARRAY_SIZE(szClassName));
1048 if (!lstrcmpW (szClassName, WC_COMBOBOXW) ||
1049 !lstrcmpW (szClassName, WC_COMBOBOXEXW)) {
1050 INT nEditHeight, yPos;
1051 RECT rc;
1053 /* special placement code for combo or comboex box */
1056 /* get size of edit line */
1057 GetWindowRect (lpBand->hwndChild, &rc);
1058 nEditHeight = rc.bottom - rc.top;
1059 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1061 /* center combo box inside child area */
1062 TRACE("moving child (Combo(Ex)) %p to (%ld,%d) for (%ld,%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 (%ld,%ld) for (%ld,%ld)\n",
1078 lpBand->hwndChild,
1079 lpBand->rcChild.left, lpBand->rcChild.top,
1080 lpBand->rcChild.right - lpBand->rcChild.left,
1081 lpBand->rcChild.bottom - lpBand->rcChild.top);
1082 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1083 lpBand->rcChild.left,
1084 lpBand->rcChild.top,
1085 lpBand->rcChild.right - lpBand->rcChild.left,
1086 lpBand->rcChild.bottom - lpBand->rcChild.top,
1087 SWP_NOZORDER);
1088 if (!deferpos)
1089 ERR("DeferWindowPos returned NULL\n");
1093 if (!EndDeferWindowPos(deferpos))
1094 ERR("EndDeferWindowPos returned NULL\n");
1096 if (infoPtr->DoRedraw)
1097 UpdateWindow (infoPtr->hwndSelf);
1100 /* Returns the next visible band (the first visible band in [i+1; infoPtr->uNumBands) )
1101 * or infoPtr->uNumBands if none */
1102 static int next_visible(const REBAR_INFO *infoPtr, int i)
1104 unsigned int n;
1105 for (n = i + 1; n < infoPtr->uNumBands; n++)
1106 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1107 break;
1108 return n;
1111 /* Returns the previous visible band (the last visible band in [0; i) )
1112 * or -1 if none */
1113 static int prev_visible(const REBAR_INFO *infoPtr, int i)
1115 int n;
1116 for (n = i - 1; n >= 0; n--)
1117 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1118 break;
1119 return n;
1122 /* Returns the first visible band or infoPtr->uNumBands if none */
1123 static int first_visible(const REBAR_INFO *infoPtr)
1125 return next_visible(infoPtr, -1); /* this works*/
1128 /* Returns the first visible band for the given row (or iBand if none) */
1129 static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
1131 int iLastBand = iBand;
1132 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1133 while ((iBand = prev_visible(infoPtr, iBand)) >= 0) {
1134 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1135 break;
1136 else
1137 iLastBand = iBand;
1139 return iLastBand;
1142 /* Returns the first visible band for the next row (or infoPtr->uNumBands if none) */
1143 static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
1145 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1146 while ((iBand = next_visible(infoPtr, iBand)) < infoPtr->uNumBands)
1147 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1148 break;
1149 return iBand;
1152 /* Compute the rcBand.{left,right} from the cxEffective bands widths computed earlier.
1153 * iBeginBand must be visible */
1154 static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1156 int xPos = 0, i;
1157 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1159 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1160 if (lpBand->rcBand.left != xPos || lpBand->rcBand.right != xPos + lpBand->cxEffective) {
1161 lpBand->fDraw |= NTF_INVALIDATE;
1162 TRACE("Setting rect %d to %d,%d\n", i, xPos, xPos + lpBand->cxEffective);
1163 lpBand->rcBand.left = xPos;
1164 lpBand->rcBand.right = xPos + lpBand->cxEffective;
1166 xPos += lpBand->cxEffective + SEP_WIDTH;
1170 /* The rationale of this function is probably as follows: if we have some space
1171 * to distribute we want to add it to a band on the right. However we don't want
1172 * to unminimize a minimized band so we search for a band that is big enough.
1173 * For some reason "big enough" is defined as bigger than the minimum size of the
1174 * first band in the row
1176 static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1178 INT cxMinFirstBand = 0, i;
1180 cxMinFirstBand = REBAR_GetBand(infoPtr, iBeginBand)->cxMinBand;
1182 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1183 if (REBAR_GetBand(infoPtr, i)->cxEffective > cxMinFirstBand &&
1184 !(REBAR_GetBand(infoPtr, i)->fStyle & RBBS_FIXEDSIZE))
1185 break;
1187 if (i < iBeginBand)
1188 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1189 if (REBAR_GetBand(infoPtr, i)->cxMinBand == cxMinFirstBand)
1190 break;
1192 TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
1193 return REBAR_GetBand(infoPtr, i);
1196 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the right */
1197 static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1199 REBAR_BAND *lpBand;
1200 INT width, i;
1202 TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
1203 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1205 lpBand = REBAR_GetBand(infoPtr, i);
1207 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1208 cxShrink -= lpBand->cxEffective - width;
1209 lpBand->cxEffective = width;
1210 if (bEnforce && lpBand->cx > lpBand->cxEffective)
1211 lpBand->cx = lpBand->cxEffective;
1212 if (cxShrink == 0)
1213 break;
1215 return cxShrink;
1219 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the left.
1220 * iBeginBand must be visible */
1221 static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1223 REBAR_BAND *lpBand;
1224 INT width, i;
1226 TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
1227 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1229 lpBand = REBAR_GetBand(infoPtr, i);
1231 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1232 cxShrink -= lpBand->cxEffective - width;
1233 lpBand->cxEffective = width;
1234 if (bEnforce)
1235 lpBand->cx = lpBand->cxEffective;
1236 if (cxShrink == 0)
1237 break;
1239 return cxShrink;
1242 /* Tries to move a band to a given offset within a row. */
1243 static int REBAR_MoveBandToRowOffset(REBAR_INFO *infoPtr, INT iBand, INT iFirstBand,
1244 INT iLastBand, INT xOff, BOOL reorder)
1246 REBAR_BAND *insertBand = REBAR_GetBand(infoPtr, iBand);
1247 int xPos = 0, i;
1248 const BOOL setBreak = REBAR_GetBand(infoPtr, iFirstBand)->fStyle & RBBS_BREAK;
1250 /* Find the band's new position */
1251 if(reorder)
1253 /* Used during an LR band reorder drag */
1254 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1256 if(xPos > xOff)
1257 break;
1258 xPos += REBAR_GetBand(infoPtr, i)->cxEffective + SEP_WIDTH;
1261 else
1263 /* Used during a UD band insertion drag */
1264 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1266 const REBAR_BAND *band = REBAR_GetBand(infoPtr, i);
1267 if(xPos + band->cxMinBand / 2 > xOff)
1268 break;
1269 xPos += band->cxEffective + SEP_WIDTH;
1273 /* Move the band to its new position */
1274 DPA_DeletePtr(infoPtr->bands, iBand);
1275 if(i > iBand)
1276 i--;
1277 DPA_InsertPtr(infoPtr->bands, i, insertBand);
1279 /* Ensure only the last band has the RBBS_BREAK flag set */
1280 insertBand->fStyle &= ~RBBS_BREAK;
1281 if(setBreak)
1282 REBAR_GetBand(infoPtr, iFirstBand)->fStyle |= RBBS_BREAK;
1284 /* Return the currently grabbed band */
1285 if(infoPtr->iGrabbedBand == iBand)
1287 infoPtr->iGrabbedBand = i;
1288 return i;
1290 else return -1;
1293 /* Set the heights of the visible bands in [iBeginBand; iEndBand) to the max height. iBeginBand must be visible */
1294 static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
1296 REBAR_BAND *lpBand;
1297 int yMaxHeight = 0;
1298 int yPos = yStart;
1299 int row, i;
1301 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1303 lpBand = REBAR_GetBand(infoPtr, i);
1304 lpBand->cyRowSoFar = yMaxHeight;
1305 yMaxHeight = max(yMaxHeight, lpBand->cyMinBand);
1307 TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
1309 row = iBeginBand < iEndBand ? REBAR_GetBand(infoPtr, iBeginBand)->iRow : 0;
1311 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1313 lpBand = REBAR_GetBand(infoPtr, i);
1314 /* we may be called for multiple rows if RBS_VARHEIGHT not set */
1315 if (lpBand->iRow != row) {
1316 yPos += yMaxHeight + SEP_WIDTH;
1317 row = lpBand->iRow;
1320 if (lpBand->rcBand.top != yPos || lpBand->rcBand.bottom != yPos + yMaxHeight) {
1321 lpBand->fDraw |= NTF_INVALIDATE;
1322 lpBand->rcBand.top = yPos;
1323 lpBand->rcBand.bottom = yPos + yMaxHeight;
1324 TRACE("Band %d: %s\n", i, wine_dbgstr_rect(&lpBand->rcBand));
1327 return yPos + yMaxHeight;
1330 /* Layout the row [iBeginBand; iEndBand). iBeginBand must be visible */
1331 static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
1333 REBAR_BAND *lpBand;
1334 int i, extra;
1335 int width = 0;
1337 TRACE("Adjusting row [%d;%d). Width: %d\n", iBeginBand, iEndBand, cx);
1338 for (i = iBeginBand; i < iEndBand; i++)
1339 REBAR_GetBand(infoPtr, i)->iRow = *piRow;
1341 /* compute the extra space */
1342 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1344 lpBand = REBAR_GetBand(infoPtr, i);
1345 if (i > iBeginBand)
1346 width += SEP_WIDTH;
1347 lpBand->cxEffective = max(lpBand->cxMinBand, lpBand->cx);
1348 width += lpBand->cxEffective;
1351 extra = cx - width;
1352 TRACE("Extra space: %d\n", extra);
1353 if (extra < 0) {
1354 int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
1355 if (ret > 0 && next_visible(infoPtr, iBeginBand) != iEndBand) /* one band may be longer than expected... */
1356 ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
1357 } else
1358 if (extra > 0) {
1359 lpBand = REBAR_FindBandToGrow(infoPtr, iBeginBand, iEndBand);
1360 lpBand->cxEffective += extra;
1363 REBAR_SetRowRectsX(infoPtr, iBeginBand, iEndBand);
1364 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1366 if (*piRow > 0)
1367 *pyPos += SEP_WIDTH;
1368 *pyPos = REBAR_SetBandsHeight(infoPtr, iBeginBand, iEndBand, *pyPos);
1370 (*piRow)++;
1373 static VOID
1374 REBAR_Layout(REBAR_INFO *infoPtr)
1376 REBAR_BAND *lpBand;
1377 RECT rcAdj;
1378 SIZE oldSize;
1379 INT adjcx, i;
1380 INT rowstart;
1381 INT row = 0;
1382 INT xMin, yPos;
1384 if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
1385 GetClientRect(infoPtr->hwndSelf, &rcAdj);
1386 else
1387 GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
1388 TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
1390 adjcx = get_rect_cx(infoPtr, &rcAdj);
1392 if (infoPtr->uNumBands == 0) {
1393 TRACE("No bands - setting size to (0,%d), style: %#lx\n", adjcx, infoPtr->dwStyle);
1394 infoPtr->calcSize.cx = adjcx;
1395 /* the calcSize.cy won't change for a 0 band rebar */
1396 infoPtr->uNumRows = 0;
1397 REBAR_ForceResize(infoPtr);
1398 return;
1401 yPos = 0;
1402 xMin = 0;
1403 rowstart = first_visible(infoPtr);
1404 /* divide rows */
1405 for (i = rowstart; i < infoPtr->uNumBands; i = next_visible(infoPtr, i))
1407 lpBand = REBAR_GetBand(infoPtr, i);
1409 if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->cxMinBand > adjcx)) {
1410 TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
1411 REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
1412 rowstart = i;
1413 xMin = 0;
1415 else
1416 xMin += SEP_WIDTH;
1418 xMin += lpBand->cxMinBand;
1420 if (rowstart < infoPtr->uNumBands)
1421 REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
1423 if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
1424 yPos = REBAR_SetBandsHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, 0);
1426 infoPtr->uNumRows = row;
1428 if (infoPtr->dwStyle & CCS_VERT)
1429 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1430 else
1431 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1432 /* now compute size of Rebar itself */
1433 oldSize = infoPtr->calcSize;
1435 infoPtr->calcSize.cx = adjcx;
1436 infoPtr->calcSize.cy = yPos;
1437 TRACE("calcsize size=(%ld, %ld), origheight=(%ld,%ld)\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1438 oldSize.cx, oldSize.cy);
1440 REBAR_DumpBand (infoPtr);
1441 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1442 REBAR_ForceResize (infoPtr);
1444 /* note: after a RBN_HEIGHTCHANGE native sends once again all the RBN_CHILDSIZE
1445 * and does another ForceResize */
1446 if (oldSize.cy != infoPtr->calcSize.cy)
1448 NMHDR heightchange;
1449 REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1450 REBAR_AutoSize(infoPtr, FALSE);
1454 /* iBeginBand must be visible */
1455 static int
1456 REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
1458 int cyBandsOld;
1459 int cyBandsNew = 0;
1460 int i;
1462 TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
1464 cyBandsOld = REBAR_GetBand(infoPtr, iBeginBand)->rcBand.bottom -
1465 REBAR_GetBand(infoPtr, iBeginBand)->rcBand.top;
1466 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1468 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1469 int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
1470 int cyChild = round_child_height(lpBand, cyMaxChild);
1472 if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
1474 TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
1475 *fChanged = TRUE;
1476 lpBand->cyChild = cyChild;
1477 lpBand->fDraw |= NTF_INVALIDATE;
1478 update_min_band_height(infoPtr, lpBand);
1480 cyBandsNew = max(cyBandsNew, lpBand->cyMinBand);
1482 return cyBandsNew - cyBandsOld;
1485 /* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
1486 static VOID
1487 REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
1489 int extra = height - infoPtr->calcSize.cy; /* may be negative */
1490 BOOL fChanged = FALSE;
1491 UINT uNumRows = infoPtr->uNumRows;
1492 int i;
1494 if (uNumRows == 0) /* avoid division by 0 */
1495 return;
1497 /* That's not exactly what Windows does but should be similar */
1499 /* Pass one: break-up/glue rows */
1500 if (extra > 0)
1502 for (i = prev_visible(infoPtr, infoPtr->uNumBands); i > 0; i = prev_visible(infoPtr, i))
1504 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1505 int cyBreakExtra; /* additional cy for the rebar after a RBBS_BREAK on this band */
1507 height = lpBand->rcBand.bottom - lpBand->rcBand.top;
1509 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1510 cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
1511 else
1512 cyBreakExtra = height; /* 'height' => 'height' + 'height'*/
1513 cyBreakExtra += SEP_WIDTH;
1515 if (extra <= cyBreakExtra / 2)
1516 break;
1518 if (!(lpBand->fStyle & RBBS_BREAK))
1520 TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
1521 lpBand->fStyle |= RBBS_BREAK;
1522 lpBand->fDraw |= NTF_INVALIDATE;
1523 fChanged = TRUE;
1524 extra -= cyBreakExtra;
1525 uNumRows++;
1526 /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
1527 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1528 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->cyMinBand;
1532 /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
1534 /* Pass two: increase/decrease control height */
1535 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1537 int i = first_visible(infoPtr);
1538 int iRow = 0;
1539 while (i < infoPtr->uNumBands)
1541 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1542 int extraForRow = extra / (int)(uNumRows - iRow);
1543 int rowEnd;
1545 /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
1546 for (rowEnd = next_visible(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_visible(infoPtr, rowEnd))
1547 if (REBAR_GetBand(infoPtr, rowEnd)->iRow != lpBand->iRow ||
1548 REBAR_GetBand(infoPtr, rowEnd)->fStyle & RBBS_BREAK)
1549 break;
1551 extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
1552 TRACE("extra = %d\n", extra);
1553 i = rowEnd;
1554 iRow++;
1557 else
1558 REBAR_SizeChildrenToHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
1560 if (fChanged)
1561 REBAR_Layout(infoPtr);
1564 static VOID
1565 REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout)
1567 RECT rc, rcNew;
1568 NMRBAUTOSIZE autosize;
1570 if (needsLayout)
1571 REBAR_Layout(infoPtr);
1572 GetClientRect(infoPtr->hwndSelf, &rc);
1573 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, &rc));
1574 GetClientRect(infoPtr->hwndSelf, &rcNew);
1576 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
1577 autosize.fChanged = EqualRect(&rc, &rcNew);
1578 autosize.rcTarget = rc;
1579 autosize.rcActual = rcNew;
1580 REBAR_Notify((NMHDR *)&autosize, infoPtr, RBN_AUTOSIZE);
1583 static VOID
1584 REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1585 /* Function: This routine evaluates the band specs supplied */
1586 /* by the user and updates the following 5 fields in */
1587 /* the internal band structure: cxHeader, cyHeader, cxMinBand, cyMinBand, fStatus */
1589 UINT header=0;
1590 UINT textheight=0, imageheight = 0;
1591 UINT i, nonfixed;
1592 REBAR_BAND *tBand;
1594 lpBand->fStatus = 0;
1595 lpBand->cxMinBand = 0;
1596 lpBand->cyMinBand = 0;
1598 /* Data coming in from users into the cx... and cy... fields */
1599 /* may be bad, just garbage, because the user never clears */
1600 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1601 /* along if the fields exist in the input area. Here we must */
1602 /* determine if the data is valid. I have no idea how MS does */
1603 /* the validation, but it does because the RB_GETBANDINFO */
1604 /* returns a 0 when I know the sample program passed in an */
1605 /* address. Here I will use the algorithm that if the value */
1606 /* is greater than 65535 then it is bad and replace it with */
1607 /* a zero. Feel free to improve the algorithm. - GA 12/2000 */
1608 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1609 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1610 if (lpBand->cx > 65535) lpBand->cx = 0;
1611 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1612 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1613 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1614 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1616 /* TODO : we could try return to the caller if a value changed so that */
1617 /* a REBAR_Layout is needed. Till now the caller should call it */
1618 /* it always (we should also check what native does) */
1620 /* Header is where the image, text and gripper exist */
1621 /* in the band and precede the child window. */
1623 /* count number of non-FIXEDSIZE and non-Hidden bands */
1624 nonfixed = 0;
1625 for (i=0; i<infoPtr->uNumBands; i++){
1626 tBand = REBAR_GetBand(infoPtr, i);
1627 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1628 nonfixed++;
1631 /* calculate gripper rectangle */
1632 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1633 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1634 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1636 lpBand->fStatus |= HAS_GRIPPER;
1637 if (infoPtr->dwStyle & CCS_VERT)
1638 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1639 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1640 else
1641 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1642 else
1643 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1644 /* Always have 4 pixels before anything else */
1645 header += REBAR_ALWAYS_SPACE;
1648 /* image is visible */
1649 if (lpBand->iImage != -1 && (infoPtr->himl)) {
1650 lpBand->fStatus |= HAS_IMAGE;
1651 if (infoPtr->dwStyle & CCS_VERT) {
1652 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1653 imageheight = infoPtr->imageSize.cx + 4;
1655 else {
1656 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1657 imageheight = infoPtr->imageSize.cy + 4;
1661 /* text is visible */
1662 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
1663 !(lpBand->fStyle & RBBS_HIDETITLE)) {
1664 HDC hdc = GetDC (0);
1665 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1666 SIZE size;
1668 lpBand->fStatus |= HAS_TEXT;
1669 GetTextExtentPoint32W (hdc, lpBand->lpText,
1670 lstrlenW (lpBand->lpText), &size);
1671 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1672 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1674 SelectObject (hdc, hOldFont);
1675 ReleaseDC (0, hdc);
1678 /* if no gripper but either image or text, then leave space */
1679 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1680 !(lpBand->fStatus & HAS_GRIPPER)) {
1681 header += REBAR_ALWAYS_SPACE;
1684 /* check if user overrode the header value */
1685 if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
1686 lpBand->cxHeader = header;
1687 lpBand->cyHeader = max(textheight, imageheight);
1689 /* Now compute minimum size of child window */
1690 update_min_band_height(infoPtr, lpBand); /* update lpBand->cyMinBand from cyHeader and cyChild*/
1692 lpBand->cxMinBand = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
1693 if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
1694 lpBand->cxMinBand += CHEVRON_WIDTH;
1697 static UINT
1698 REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
1699 /* Function: This routine copies the supplied values from */
1700 /* user input (lprbbi) to the internal band structure. */
1701 /* It returns the mask of what changed. */
1703 UINT uChanged = 0x0;
1705 lpBand->fMask |= lprbbi->fMask;
1707 if( (lprbbi->fMask & RBBIM_STYLE) &&
1708 (lpBand->fStyle != lprbbi->fStyle ) )
1710 lpBand->fStyle = lprbbi->fStyle;
1711 uChanged |= RBBIM_STYLE;
1714 if( (lprbbi->fMask & RBBIM_COLORS) &&
1715 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
1716 ( lpBand->clrBack != lprbbi->clrBack ) ) )
1718 lpBand->clrFore = lprbbi->clrFore;
1719 lpBand->clrBack = lprbbi->clrBack;
1720 uChanged |= RBBIM_COLORS;
1723 if( (lprbbi->fMask & RBBIM_IMAGE) &&
1724 ( lpBand->iImage != lprbbi->iImage ) )
1726 lpBand->iImage = lprbbi->iImage;
1727 uChanged |= RBBIM_IMAGE;
1730 if( (lprbbi->fMask & RBBIM_CHILD) &&
1731 (lprbbi->hwndChild != lpBand->hwndChild ) )
1733 if (lprbbi->hwndChild) {
1734 lpBand->hwndChild = lprbbi->hwndChild;
1735 lpBand->hwndPrevParent =
1736 SetParent (lpBand->hwndChild, hwnd);
1737 /* below in trace from WinRAR */
1738 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
1739 /* above in trace from WinRAR */
1741 else {
1742 TRACE("child: %p prev parent: %p\n",
1743 lpBand->hwndChild, lpBand->hwndPrevParent);
1744 lpBand->hwndChild = 0;
1745 lpBand->hwndPrevParent = 0;
1747 uChanged |= RBBIM_CHILD;
1750 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
1751 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
1752 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
1753 ( (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) &&
1754 ( (lpBand->cyChild != lprbbi->cyChild ) ||
1755 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
1756 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
1757 ( (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE) &&
1758 ( (lpBand->cyChild ||
1759 lpBand->cyMaxChild ||
1760 lpBand->cyIntegral ) ) ) ) )
1762 lpBand->cxMinChild = lprbbi->cxMinChild;
1763 lpBand->cyMinChild = lprbbi->cyMinChild;
1764 /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
1765 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
1766 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1767 lpBand->cyIntegral = lprbbi->cyIntegral;
1769 lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild); /* make (cyChild - cyMinChild) a multiple of cyIntergral */
1771 else {
1772 lpBand->cyChild = lpBand->cyMinChild;
1773 lpBand->cyMaxChild = 0x7fffffff;
1774 lpBand->cyIntegral = 0;
1776 uChanged |= RBBIM_CHILDSIZE;
1779 if( (lprbbi->fMask & RBBIM_SIZE) &&
1780 (lpBand->cx != lprbbi->cx ) )
1782 lpBand->cx = lprbbi->cx;
1783 uChanged |= RBBIM_SIZE;
1786 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
1787 ( lpBand->hbmBack != lprbbi->hbmBack ) )
1789 lpBand->hbmBack = lprbbi->hbmBack;
1790 uChanged |= RBBIM_BACKGROUND;
1793 if( (lprbbi->fMask & RBBIM_ID) &&
1794 (lpBand->wID != lprbbi->wID ) )
1796 lpBand->wID = lprbbi->wID;
1797 uChanged |= RBBIM_ID;
1800 /* check for additional data */
1801 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE) {
1802 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
1803 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
1805 lpBand->cxIdeal = lprbbi->cxIdeal;
1806 uChanged |= RBBIM_IDEALSIZE;
1809 if( (lprbbi->fMask & RBBIM_LPARAM) &&
1810 (lpBand->lParam != lprbbi->lParam ) )
1812 lpBand->lParam = lprbbi->lParam;
1813 uChanged |= RBBIM_LPARAM;
1816 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
1817 (lpBand->cxHeader != lprbbi->cxHeader ) )
1819 lpBand->cxHeader = lprbbi->cxHeader;
1820 lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
1821 uChanged |= RBBIM_HEADERSIZE;
1825 return uChanged;
1828 static LRESULT REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, HDC hdc)
1829 /* Function: This erases the background rectangle by drawing */
1830 /* each band with its background color (or the default) and */
1831 /* draws each bands right separator if necessary. The row */
1832 /* separators are drawn on the first band of the next row. */
1834 REBAR_BAND *lpBand;
1835 UINT i;
1836 INT oldrow;
1837 RECT cr;
1838 COLORREF old = CLR_NONE, new;
1839 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1841 GetClientRect (infoPtr->hwndSelf, &cr);
1843 oldrow = -1;
1844 for(i=0; i<infoPtr->uNumBands; i++) {
1845 RECT rcBand;
1846 lpBand = REBAR_GetBand(infoPtr, i);
1847 if (HIDDENBAND(lpBand)) continue;
1848 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1850 /* draw band separator between rows */
1851 if (lpBand->iRow != oldrow) {
1852 oldrow = lpBand->iRow;
1853 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1854 RECT rcRowSep;
1855 rcRowSep = rcBand;
1856 if (infoPtr->dwStyle & CCS_VERT) {
1857 rcRowSep.right += SEP_WIDTH_SIZE;
1858 rcRowSep.bottom = infoPtr->calcSize.cx;
1859 if (theme)
1860 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_RIGHT, NULL);
1861 else
1862 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
1864 else {
1865 rcRowSep.bottom += SEP_WIDTH_SIZE;
1866 rcRowSep.right = infoPtr->calcSize.cx;
1867 if (theme)
1868 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1869 else
1870 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
1872 TRACE ("drawing band separator bottom (%s)\n",
1873 wine_dbgstr_rect(&rcRowSep));
1877 /* draw band separator between bands in a row */
1878 if (infoPtr->dwStyle & RBS_BANDBORDERS && lpBand->rcBand.left > 0) {
1879 RECT rcSep;
1880 rcSep = rcBand;
1881 if (infoPtr->dwStyle & CCS_VERT) {
1882 rcSep.bottom = rcSep.top;
1883 rcSep.top -= SEP_WIDTH_SIZE;
1884 if (theme)
1885 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1886 else
1887 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
1889 else {
1890 rcSep.right = rcSep.left;
1891 rcSep.left -= SEP_WIDTH_SIZE;
1892 if (theme)
1893 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_RIGHT, NULL);
1894 else
1895 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
1897 TRACE("drawing band separator right (%s)\n",
1898 wine_dbgstr_rect(&rcSep));
1901 /* draw the actual background */
1902 if (lpBand->clrBack != CLR_NONE) {
1903 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
1904 lpBand->clrBack;
1905 #if GLATESTING
1906 /* testing only - make background green to see it */
1907 new = RGB(0,128,0);
1908 #endif
1910 else {
1911 /* In the absence of documentation for Rebar vs. CLR_NONE,
1912 * we will use the default BtnFace color. Note documentation
1913 * exists for Listview and Imagelist.
1915 new = infoPtr->clrBtnFace;
1916 #if GLATESTING
1917 /* testing only - make background green to see it */
1918 new = RGB(0,128,0);
1919 #endif
1922 if (theme)
1924 /* When themed, the background color is ignored (but not a
1925 * background bitmap */
1926 DrawThemeBackground (theme, hdc, 0, 0, &cr, &rcBand);
1928 else
1930 old = SetBkColor (hdc, new);
1931 TRACE("%s background color %#lx, band %s\n",
1932 (lpBand->clrBack == CLR_NONE) ? "none" :
1933 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
1934 GetBkColor(hdc), wine_dbgstr_rect(&rcBand));
1935 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &rcBand, NULL, 0, 0);
1936 if (lpBand->clrBack != CLR_NONE)
1937 SetBkColor (hdc, old);
1940 return TRUE;
1943 static void
1944 REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
1946 REBAR_BAND *lpBand;
1947 RECT rect;
1948 UINT iCount;
1950 GetClientRect (infoPtr->hwndSelf, &rect);
1952 *pFlags = RBHT_NOWHERE;
1953 if (PtInRect (&rect, *lpPt))
1955 if (infoPtr->uNumBands == 0) {
1956 *pFlags = RBHT_NOWHERE;
1957 if (pBand)
1958 *pBand = -1;
1959 TRACE("NOWHERE\n");
1960 return;
1962 else {
1963 /* somewhere inside */
1964 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
1965 RECT rcBand;
1966 lpBand = REBAR_GetBand(infoPtr, iCount);
1967 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1968 if (HIDDENBAND(lpBand)) continue;
1969 if (PtInRect (&rcBand, *lpPt)) {
1970 if (pBand)
1971 *pBand = iCount;
1972 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
1973 *pFlags = RBHT_GRABBER;
1974 TRACE("ON GRABBER %d\n", iCount);
1975 return;
1977 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
1978 *pFlags = RBHT_CAPTION;
1979 TRACE("ON CAPTION %d\n", iCount);
1980 return;
1982 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
1983 *pFlags = RBHT_CAPTION;
1984 TRACE("ON CAPTION %d\n", iCount);
1985 return;
1987 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
1988 *pFlags = RBHT_CLIENT;
1989 TRACE("ON CLIENT %d\n", iCount);
1990 return;
1992 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
1993 *pFlags = RBHT_CHEVRON;
1994 TRACE("ON CHEVRON %d\n", iCount);
1995 return;
1997 else {
1998 *pFlags = RBHT_NOWHERE;
1999 TRACE("NOWHERE %d\n", iCount);
2000 return;
2005 *pFlags = RBHT_NOWHERE;
2006 if (pBand)
2007 *pBand = -1;
2009 TRACE("NOWHERE\n");
2010 return;
2013 else {
2014 *pFlags = RBHT_NOWHERE;
2015 if (pBand)
2016 *pBand = -1;
2017 TRACE("NOWHERE\n");
2018 return;
2022 static void
2023 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2024 /* Function: This will implement the functionality of a */
2025 /* Gripper drag within a row. It will not implement "out- */
2026 /* of-row" drags. (They are detected and handled in */
2027 /* REBAR_MouseMove.) */
2029 REBAR_BAND *hitBand;
2030 INT iHitBand, iRowBegin, iRowEnd;
2031 INT movement, xBand, cxLeft = 0;
2032 BOOL shrunkBands = FALSE;
2034 iHitBand = infoPtr->iGrabbedBand;
2035 iRowBegin = get_row_begin_for_band(infoPtr, iHitBand);
2036 iRowEnd = get_row_end_for_band(infoPtr, iHitBand);
2037 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2039 xBand = hitBand->rcBand.left;
2040 movement = (infoPtr->dwStyle&CCS_VERT ? ptsmove->y : ptsmove->x)
2041 - (xBand + REBAR_PRE_GRIPPER - infoPtr->ihitoffset);
2043 /* Dragging the first band in a row cannot cause shrinking */
2044 if(iHitBand != iRowBegin)
2046 if (movement < 0) {
2047 cxLeft = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iHitBand, -movement, TRUE);
2049 if(cxLeft < -movement)
2051 hitBand->cxEffective += -movement - cxLeft;
2052 hitBand->cx = hitBand->cxEffective;
2053 shrunkBands = TRUE;
2056 } else if (movement > 0) {
2058 cxLeft = movement;
2059 if (prev_visible(infoPtr, iHitBand) >= 0)
2060 cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
2062 if(cxLeft < movement)
2064 REBAR_BAND *lpPrev = REBAR_GetBand(infoPtr, prev_visible(infoPtr, iHitBand));
2065 lpPrev->cxEffective += movement - cxLeft;
2066 lpPrev->cx = hitBand->cxEffective;
2067 shrunkBands = TRUE;
2073 if(!shrunkBands)
2075 /* It was not possible to move the band by shrinking bands.
2076 * Try relocating the band instead. */
2077 REBAR_MoveBandToRowOffset(infoPtr, iHitBand, iRowBegin,
2078 iRowEnd, xBand + movement, TRUE);
2081 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2082 if (infoPtr->dwStyle & CCS_VERT)
2083 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
2084 else
2085 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
2086 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2089 static void
2090 REBAR_HandleUDDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2092 INT yOff = (infoPtr->dwStyle & CCS_VERT) ? ptsmove->x : ptsmove->y;
2093 INT iHitBand, iRowBegin, iNextRowBegin;
2094 REBAR_BAND *hitBand, *rowBeginBand;
2096 if(infoPtr->uNumBands <= 0)
2097 ERR("There are no bands in this rebar\n");
2099 /* Up/down dragging can only occur when there is more than one
2100 * band in the rebar */
2101 if(infoPtr->uNumBands <= 1)
2102 return;
2104 iHitBand = infoPtr->iGrabbedBand;
2105 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2107 /* If we're taking a band that has the RBBS_BREAK style set, this
2108 * style needs to be reapplied to the band that is going to become
2109 * the new start of the row. */
2110 if((hitBand->fStyle & RBBS_BREAK) &&
2111 (iHitBand < infoPtr->uNumBands - 1))
2112 REBAR_GetBand(infoPtr, iHitBand + 1)->fStyle |= RBBS_BREAK;
2114 if(yOff < 0)
2116 /* Place the band above the current top row */
2117 if(iHitBand==0 && (infoPtr->uNumBands==1 || REBAR_GetBand(infoPtr, 1)->fStyle&RBBS_BREAK))
2118 return;
2119 DPA_DeletePtr(infoPtr->bands, iHitBand);
2120 hitBand->fStyle &= ~RBBS_BREAK;
2121 REBAR_GetBand(infoPtr, 0)->fStyle |= RBBS_BREAK;
2122 infoPtr->iGrabbedBand = DPA_InsertPtr(
2123 infoPtr->bands, 0, hitBand);
2125 else if(yOff > REBAR_GetBand(infoPtr, infoPtr->uNumBands - 1)->rcBand.bottom)
2127 /* Place the band below the current bottom row */
2128 if(iHitBand == infoPtr->uNumBands-1 && hitBand->fStyle&RBBS_BREAK)
2129 return;
2130 DPA_DeletePtr(infoPtr->bands, iHitBand);
2131 hitBand->fStyle |= RBBS_BREAK;
2132 infoPtr->iGrabbedBand = DPA_InsertPtr(
2133 infoPtr->bands, infoPtr->uNumBands - 1, hitBand);
2135 else
2137 /* Place the band in the preexisting row the mouse is hovering over */
2138 iRowBegin = first_visible(infoPtr);
2139 while(iRowBegin < infoPtr->uNumBands)
2141 iNextRowBegin = get_row_end_for_band(infoPtr, iRowBegin);
2142 rowBeginBand = REBAR_GetBand(infoPtr, iRowBegin);
2143 if(rowBeginBand->rcBand.bottom > yOff)
2145 REBAR_MoveBandToRowOffset(
2146 infoPtr, iHitBand, iRowBegin, iNextRowBegin,
2147 ((infoPtr->dwStyle & CCS_VERT) ? ptsmove->y : ptsmove->x)
2148 - REBAR_PRE_GRIPPER - infoPtr->ihitoffset, FALSE);
2149 break;
2152 iRowBegin = iNextRowBegin;
2156 REBAR_Layout(infoPtr);
2160 /* << REBAR_BeginDrag >> */
2163 static LRESULT
2164 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam)
2166 UINT uBand = (UINT)wParam;
2167 REBAR_BAND *lpBand;
2169 if (uBand >= infoPtr->uNumBands)
2170 return FALSE;
2172 TRACE("deleting band %u!\n", uBand);
2173 lpBand = REBAR_GetBand(infoPtr, uBand);
2174 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2175 /* TODO: a return of 1 should probably cancel the deletion */
2177 if (lpBand->hwndChild)
2178 ShowWindow(lpBand->hwndChild, SW_HIDE);
2179 Free(lpBand->lpText);
2180 Free(lpBand);
2182 infoPtr->uNumBands--;
2183 DPA_DeletePtr(infoPtr->bands, uBand);
2185 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2187 /* if only 1 band left the re-validate to possible eliminate gripper */
2188 if (infoPtr->uNumBands == 1)
2189 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2191 REBAR_Layout(infoPtr);
2193 return TRUE;
2197 /* << REBAR_DragMove >> */
2198 /* << REBAR_EndDrag >> */
2201 static LRESULT
2202 REBAR_GetBandBorders (const REBAR_INFO *infoPtr, UINT uBand, RECT *lpRect)
2204 REBAR_BAND *lpBand;
2206 if (!lpRect)
2207 return 0;
2208 if (uBand >= infoPtr->uNumBands)
2209 return 0;
2211 lpBand = REBAR_GetBand(infoPtr, uBand);
2213 /* FIXME - the following values were determined by experimentation */
2214 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2215 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2216 /* difference in size of the control area with and without the */
2217 /* style. - GA */
2218 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2219 if (infoPtr->dwStyle & CCS_VERT) {
2220 lpRect->left = 1;
2221 lpRect->top = lpBand->cxHeader + 4;
2222 lpRect->right = 1;
2223 lpRect->bottom = 0;
2225 else {
2226 lpRect->left = lpBand->cxHeader + 4;
2227 lpRect->top = 1;
2228 lpRect->right = 0;
2229 lpRect->bottom = 1;
2232 else {
2233 lpRect->left = lpBand->cxHeader;
2235 return 0;
2239 static inline LRESULT
2240 REBAR_GetBandCount (const REBAR_INFO *infoPtr)
2242 TRACE("band count %u!\n", infoPtr->uNumBands);
2244 return infoPtr->uNumBands;
2248 static LRESULT
2249 REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, UINT uIndex, LPREBARBANDINFOW lprbbi, BOOL bUnicode)
2251 REBAR_BAND *lpBand;
2253 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2254 return FALSE;
2256 if (uIndex >= infoPtr->uNumBands)
2257 return FALSE;
2259 TRACE("index %u (bUnicode=%d)\n", uIndex, bUnicode);
2261 /* copy band information */
2262 lpBand = REBAR_GetBand(infoPtr, uIndex);
2264 if (lprbbi->fMask & RBBIM_STYLE)
2265 lprbbi->fStyle = lpBand->fStyle;
2267 if (lprbbi->fMask & RBBIM_COLORS) {
2268 lprbbi->clrFore = lpBand->clrFore;
2269 lprbbi->clrBack = lpBand->clrBack;
2270 if (lprbbi->clrBack == CLR_DEFAULT)
2271 lprbbi->clrBack = infoPtr->clrBtnFace;
2274 if (lprbbi->fMask & RBBIM_TEXT) {
2275 if (bUnicode)
2276 Str_GetPtrW(lpBand->lpText, lprbbi->lpText, lprbbi->cch);
2277 else
2278 Str_GetPtrWtoA(lpBand->lpText, (LPSTR)lprbbi->lpText, lprbbi->cch);
2281 if (lprbbi->fMask & RBBIM_IMAGE)
2282 lprbbi->iImage = lpBand->iImage;
2284 if (lprbbi->fMask & RBBIM_CHILD)
2285 lprbbi->hwndChild = lpBand->hwndChild;
2287 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2288 lprbbi->cxMinChild = lpBand->cxMinChild;
2289 lprbbi->cyMinChild = lpBand->cyMinChild;
2290 /* to make tests pass we follow Windows' behaviour and allow reading these fields only
2291 * for RBBS_VARIABLEHEIGHTS bands */
2292 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2293 lprbbi->cyChild = lpBand->cyChild;
2294 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2295 lprbbi->cyIntegral = lpBand->cyIntegral;
2299 if (lprbbi->fMask & RBBIM_SIZE)
2300 lprbbi->cx = lpBand->cx;
2302 if (lprbbi->fMask & RBBIM_BACKGROUND)
2303 lprbbi->hbmBack = lpBand->hbmBack;
2305 if (lprbbi->fMask & RBBIM_ID)
2306 lprbbi->wID = lpBand->wID;
2308 /* check for additional data */
2309 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE) {
2310 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2311 lprbbi->cxIdeal = lpBand->cxIdeal;
2313 if (lprbbi->fMask & RBBIM_LPARAM)
2314 lprbbi->lParam = lpBand->lParam;
2316 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2317 lprbbi->cxHeader = lpBand->cxHeader;
2320 REBAR_DumpBandInfo(lprbbi);
2322 return TRUE;
2326 static LRESULT
2327 REBAR_GetBarHeight (const REBAR_INFO *infoPtr)
2329 INT nHeight;
2331 nHeight = infoPtr->calcSize.cy;
2333 TRACE("height = %d\n", nHeight);
2335 return nHeight;
2339 static LRESULT
2340 REBAR_GetBarInfo (const REBAR_INFO *infoPtr, LPREBARINFO lpInfo)
2342 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2343 return FALSE;
2345 TRACE("getting bar info!\n");
2347 if (infoPtr->himl) {
2348 lpInfo->himl = infoPtr->himl;
2349 lpInfo->fMask |= RBIM_IMAGELIST;
2352 return TRUE;
2356 static inline LRESULT
2357 REBAR_GetBkColor (const REBAR_INFO *infoPtr)
2359 COLORREF clr = infoPtr->clrBk;
2361 if (clr == CLR_DEFAULT)
2362 clr = infoPtr->clrBtnFace;
2364 TRACE("background color %#lx\n", clr);
2366 return clr;
2370 /* << REBAR_GetColorScheme >> */
2371 /* << REBAR_GetDropTarget >> */
2374 static LRESULT
2375 REBAR_GetPalette (const REBAR_INFO *infoPtr)
2377 FIXME("empty stub!\n");
2379 return 0;
2383 static LRESULT
2384 REBAR_GetRect (const REBAR_INFO *infoPtr, INT iBand, RECT *lprc)
2386 REBAR_BAND *lpBand;
2388 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2389 return FALSE;
2390 if (!lprc)
2391 return FALSE;
2393 lpBand = REBAR_GetBand(infoPtr, iBand);
2394 /* For CCS_VERT the coordinates will be swapped - like on Windows */
2395 *lprc = lpBand->rcBand;
2397 TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
2399 return TRUE;
2403 static inline LRESULT
2404 REBAR_GetRowCount (const REBAR_INFO *infoPtr)
2406 TRACE("%u\n", infoPtr->uNumRows);
2408 return infoPtr->uNumRows;
2412 static LRESULT
2413 REBAR_GetRowHeight (const REBAR_INFO *infoPtr, INT iRow)
2415 int j = 0, ret = 0;
2416 UINT i;
2417 REBAR_BAND *lpBand;
2419 for (i=0; i<infoPtr->uNumBands; i++) {
2420 lpBand = REBAR_GetBand(infoPtr, i);
2421 if (HIDDENBAND(lpBand)) continue;
2422 if (lpBand->iRow != iRow) continue;
2423 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2424 if (j > ret) ret = j;
2427 TRACE("row %d, height %d\n", iRow, ret);
2429 return ret;
2433 static inline LRESULT
2434 REBAR_GetTextColor (const REBAR_INFO *infoPtr)
2436 TRACE("text color %#lx\n", infoPtr->clrText);
2438 return infoPtr->clrText;
2442 static inline LRESULT
2443 REBAR_GetToolTips (const REBAR_INFO *infoPtr)
2445 return (LRESULT)infoPtr->hwndToolTip;
2449 static inline LRESULT
2450 REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
2452 TRACE("%s hwnd=%p\n",
2453 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2455 return infoPtr->bUnicode;
2459 static inline LRESULT
2460 REBAR_GetVersion (const REBAR_INFO *infoPtr)
2462 TRACE("version %d\n", infoPtr->iVersion);
2463 return infoPtr->iVersion;
2467 static LRESULT
2468 REBAR_HitTest (const REBAR_INFO *infoPtr, LPRBHITTESTINFO lprbht)
2470 if (!lprbht)
2471 return -1;
2473 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2475 return lprbht->iBand;
2479 static LRESULT
2480 REBAR_IdToIndex (const REBAR_INFO *infoPtr, UINT uId)
2482 UINT i;
2484 if (infoPtr->uNumBands < 1)
2485 return -1;
2487 for (i = 0; i < infoPtr->uNumBands; i++) {
2488 if (REBAR_GetBand(infoPtr, i)->wID == uId) {
2489 TRACE("id %u is band %u found!\n", uId, i);
2490 return i;
2494 TRACE("id %u is not found\n", uId);
2495 return -1;
2499 static LRESULT
2500 REBAR_InsertBandT(REBAR_INFO *infoPtr, INT iIndex, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2502 REBAR_BAND *lpBand;
2504 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2505 return FALSE;
2507 /* trace the index as signed to see the -1 */
2508 TRACE("insert band at %d (bUnicode=%d)!\n", iIndex, bUnicode);
2509 REBAR_DumpBandInfo(lprbbi);
2511 if (!(lpBand = Alloc(sizeof(REBAR_BAND)))) return FALSE;
2512 if ((iIndex == -1) || (iIndex > infoPtr->uNumBands))
2513 iIndex = infoPtr->uNumBands;
2514 if (DPA_InsertPtr(infoPtr->bands, iIndex, lpBand) == -1)
2516 Free(lpBand);
2517 return FALSE;
2519 infoPtr->uNumBands++;
2521 TRACE("index %d!\n", iIndex);
2523 /* initialize band */
2524 memset(lpBand, 0, sizeof(*lpBand));
2525 lpBand->clrFore = infoPtr->clrText == CLR_NONE ? infoPtr->clrBtnText :
2526 infoPtr->clrText;
2527 lpBand->clrBack = infoPtr->clrBk == CLR_NONE ? infoPtr->clrBtnFace :
2528 infoPtr->clrBk;
2529 lpBand->iImage = -1;
2531 REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
2533 /* Make sure the defaults for these are correct */
2534 if (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE || !(lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2535 lpBand->cyChild = lpBand->cyMinChild;
2536 lpBand->cyMaxChild = 0x7fffffff;
2537 lpBand->cyIntegral = 0;
2540 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2541 if (bUnicode)
2542 Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
2543 else
2544 Str_SetPtrAtoW(&lpBand->lpText, (LPSTR)lprbbi->lpText);
2547 REBAR_ValidateBand (infoPtr, lpBand);
2548 /* On insert of second band, revalidate band 1 to possible add gripper */
2549 if (infoPtr->uNumBands == 2)
2550 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2552 REBAR_DumpBand (infoPtr);
2554 REBAR_Layout(infoPtr);
2555 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2557 return TRUE;
2561 static LRESULT
2562 REBAR_MaximizeBand (const REBAR_INFO *infoPtr, INT iBand, LPARAM lParam)
2564 REBAR_BAND *lpBand;
2565 int iRowBegin, iRowEnd;
2566 int cxDesired, extra, extraOrig;
2567 int cxIdealBand;
2569 /* Validate */
2570 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2571 /* error !!! */
2572 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
2573 iBand, infoPtr->uNumBands);
2574 return FALSE;
2577 lpBand = REBAR_GetBand(infoPtr, iBand);
2579 if (lpBand->fStyle & RBBS_HIDDEN)
2581 /* Windows is buggy and creates a hole */
2582 WARN("Ignoring maximize request on a hidden band (%d)\n", iBand);
2583 return FALSE;
2586 cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
2587 if (lParam && (lpBand->cxEffective < cxIdealBand))
2588 cxDesired = cxIdealBand;
2589 else
2590 cxDesired = infoPtr->calcSize.cx;
2592 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2593 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2594 extraOrig = extra = cxDesired - lpBand->cxEffective;
2595 if (extra > 0)
2596 extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iBand, extra, TRUE);
2597 if (extra > 0)
2598 extra = REBAR_ShrinkBandsLTR(infoPtr, next_visible(infoPtr, iBand), iRowEnd, extra, TRUE);
2599 lpBand->cxEffective += extraOrig - extra;
2600 lpBand->cx = lpBand->cxEffective;
2601 TRACE("(%d, %Id): Wanted size %d, obtained %d (shrink %d, %d)\n", iBand, lParam, cxDesired, lpBand->cx, extraOrig, extra);
2602 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2604 if (infoPtr->dwStyle & CCS_VERT)
2605 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2606 else
2607 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2608 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2609 return TRUE;
2614 static LRESULT
2615 REBAR_MinimizeBand (const REBAR_INFO *infoPtr, INT iBand)
2617 REBAR_BAND *lpBand;
2618 int iPrev, iRowBegin, iRowEnd;
2620 /* A "minimize" band is equivalent to "dragging" the gripper
2621 * of than band to the right till the band is only the size
2622 * of the cxHeader.
2625 /* Validate */
2626 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2627 /* error !!! */
2628 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
2629 iBand, infoPtr->uNumBands);
2630 return FALSE;
2633 /* compute amount of movement and validate */
2634 lpBand = REBAR_GetBand(infoPtr, iBand);
2636 if (lpBand->fStyle & RBBS_HIDDEN)
2638 /* Windows is buggy and creates a hole/overlap */
2639 WARN("Ignoring minimize request on a hidden band (%d)\n", iBand);
2640 return FALSE;
2643 iPrev = prev_visible(infoPtr, iBand);
2644 /* if first band in row */
2645 if (iPrev < 0 || REBAR_GetBand(infoPtr, iPrev)->iRow != lpBand->iRow) {
2646 int iNext = next_visible(infoPtr, iBand);
2647 if (iNext < infoPtr->uNumBands && REBAR_GetBand(infoPtr, iNext)->iRow == lpBand->iRow) {
2648 TRACE("(%d): Minimizing the first band in row is by maximizing the second\n", iBand);
2649 REBAR_MaximizeBand(infoPtr, iNext, FALSE);
2651 else
2652 TRACE("(%d): Only one band in row - nothing to do\n", iBand);
2653 return TRUE;
2656 REBAR_GetBand(infoPtr, iPrev)->cxEffective += lpBand->cxEffective - lpBand->cxMinBand;
2657 REBAR_GetBand(infoPtr, iPrev)->cx = REBAR_GetBand(infoPtr, iPrev)->cxEffective;
2658 lpBand->cx = lpBand->cxEffective = lpBand->cxMinBand;
2660 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2661 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2662 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2664 if (infoPtr->dwStyle & CCS_VERT)
2665 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2666 else
2667 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2668 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2669 return FALSE;
2673 static LRESULT
2674 REBAR_MoveBand (REBAR_INFO *infoPtr, INT iFrom, INT iTo)
2676 REBAR_BAND *lpBand;
2678 /* Validate */
2679 if ((infoPtr->uNumBands == 0) ||
2680 (iFrom < 0) || iFrom >= infoPtr->uNumBands ||
2681 (iTo < 0) || iTo >= infoPtr->uNumBands) {
2682 /* error !!! */
2683 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
2684 iFrom, iTo, infoPtr->uNumBands);
2685 return FALSE;
2688 lpBand = REBAR_GetBand(infoPtr, iFrom);
2689 DPA_DeletePtr(infoPtr->bands, iFrom);
2690 DPA_InsertPtr(infoPtr->bands, iTo, lpBand);
2692 TRACE("moved band %d to index %d\n", iFrom, iTo);
2693 REBAR_DumpBand (infoPtr);
2695 /* **************************************************** */
2696 /* */
2697 /* We do not do a REBAR_Layout here because the native */
2698 /* control does not do that. The actual layout and */
2699 /* repaint is done by the *next* real action, ex.: */
2700 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
2701 /* */
2702 /* **************************************************** */
2704 return TRUE;
2708 /* return TRUE if two strings are different */
2709 static BOOL
2710 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
2712 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
2715 static LRESULT
2716 REBAR_SetBandInfoT(REBAR_INFO *infoPtr, INT iBand, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2718 REBAR_BAND *lpBand;
2719 UINT uChanged;
2721 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2722 return FALSE;
2724 if (iBand >= infoPtr->uNumBands)
2725 return FALSE;
2727 TRACE("index %d\n", iBand);
2728 REBAR_DumpBandInfo (lprbbi);
2730 /* set band information */
2731 lpBand = REBAR_GetBand(infoPtr, iBand);
2733 uChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2734 if (lprbbi->fMask & RBBIM_TEXT) {
2735 LPWSTR wstr = NULL;
2736 if (bUnicode)
2737 Str_SetPtrW(&wstr, lprbbi->lpText);
2738 else
2739 Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
2741 if (REBAR_strdifW(wstr, lpBand->lpText)) {
2742 Free(lpBand->lpText);
2743 lpBand->lpText = wstr;
2744 uChanged |= RBBIM_TEXT;
2746 else
2747 Free(wstr);
2750 REBAR_ValidateBand (infoPtr, lpBand);
2752 REBAR_DumpBand (infoPtr);
2754 if (uChanged & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IMAGE)) {
2755 REBAR_Layout(infoPtr);
2756 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2759 return TRUE;
2763 static LRESULT
2764 REBAR_SetBarInfo (REBAR_INFO *infoPtr, const REBARINFO *lpInfo)
2766 REBAR_BAND *lpBand;
2767 UINT i;
2769 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2770 return FALSE;
2772 TRACE("setting bar info!\n");
2774 if (lpInfo->fMask & RBIM_IMAGELIST) {
2775 infoPtr->himl = lpInfo->himl;
2776 if (infoPtr->himl) {
2777 INT cx, cy;
2778 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
2779 infoPtr->imageSize.cx = cx;
2780 infoPtr->imageSize.cy = cy;
2782 else {
2783 infoPtr->imageSize.cx = 0;
2784 infoPtr->imageSize.cy = 0;
2786 TRACE("new image cx=%ld, cy=%ld\n", infoPtr->imageSize.cx, 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 %#lx\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 %#lx\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 OpenThemeData(infoPtr->hwndSelf, themeClass);
2933 TRACE("created!\n");
2934 return 0;
2938 static LRESULT
2939 REBAR_Destroy (REBAR_INFO *infoPtr)
2941 REBAR_BAND *lpBand;
2942 UINT i;
2944 /* clean up each band */
2945 for (i = 0; i < infoPtr->uNumBands; i++) {
2946 lpBand = REBAR_GetBand(infoPtr, i);
2948 /* delete text strings */
2949 Free (lpBand->lpText);
2950 lpBand->lpText = NULL;
2951 /* destroy child window */
2952 DestroyWindow (lpBand->hwndChild);
2953 Free (lpBand);
2956 /* free band array */
2957 DPA_Destroy (infoPtr->bands);
2958 infoPtr->bands = NULL;
2960 DestroyCursor (infoPtr->hcurArrow);
2961 DestroyCursor (infoPtr->hcurHorz);
2962 DestroyCursor (infoPtr->hcurVert);
2963 DestroyCursor (infoPtr->hcurDrag);
2964 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
2965 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
2967 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2969 /* free rebar info data */
2970 Free (infoPtr);
2971 TRACE("destroyed!\n");
2972 return 0;
2975 static LRESULT
2976 REBAR_GetFont (const REBAR_INFO *infoPtr)
2978 return (LRESULT)infoPtr->hFont;
2981 static LRESULT
2982 REBAR_PushChevron(const REBAR_INFO *infoPtr, UINT uBand, LPARAM lParam)
2984 if (uBand < infoPtr->uNumBands)
2986 NMREBARCHEVRON nmrbc;
2987 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
2989 TRACE("Pressed chevron on band %u\n", uBand);
2991 /* redraw chevron in pushed state */
2992 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
2993 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
2994 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
2996 /* notify app so it can display a popup menu or whatever */
2997 nmrbc.uBand = uBand;
2998 nmrbc.wID = lpBand->wID;
2999 nmrbc.lParam = lpBand->lParam;
3000 nmrbc.rc = lpBand->rcChevron;
3001 nmrbc.lParamNM = lParam;
3002 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3004 /* redraw chevron in previous state */
3005 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3006 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3008 return TRUE;
3010 return FALSE;
3013 static LRESULT
3014 REBAR_LButtonDown (REBAR_INFO *infoPtr, LPARAM lParam)
3016 UINT htFlags;
3017 INT iHitBand;
3018 POINT ptMouseDown;
3019 ptMouseDown.x = (short)LOWORD(lParam);
3020 ptMouseDown.y = (short)HIWORD(lParam);
3022 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3024 if (htFlags == RBHT_CHEVRON)
3026 REBAR_PushChevron(infoPtr, iHitBand, 0);
3028 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3030 REBAR_BAND *lpBand;
3032 TRACE("Starting drag\n");
3034 lpBand = REBAR_GetBand(infoPtr, iHitBand);
3036 SetCapture (infoPtr->hwndSelf);
3037 infoPtr->iGrabbedBand = iHitBand;
3039 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3040 infoPtr->dragStart.x = (short)LOWORD(lParam);
3041 infoPtr->dragStart.y = (short)HIWORD(lParam);
3042 infoPtr->dragNow = infoPtr->dragStart;
3043 if (infoPtr->dwStyle & CCS_VERT)
3044 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3045 else
3046 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3048 return 0;
3051 static LRESULT
3052 REBAR_LButtonUp (REBAR_INFO *infoPtr)
3054 if (infoPtr->iGrabbedBand >= 0)
3056 NMHDR layout;
3057 RECT rect;
3059 infoPtr->dragStart.x = 0;
3060 infoPtr->dragStart.y = 0;
3061 infoPtr->dragNow = infoPtr->dragStart;
3063 ReleaseCapture ();
3065 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3066 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3067 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3068 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3071 infoPtr->iGrabbedBand = -1;
3073 GetClientRect(infoPtr->hwndSelf, &rect);
3074 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3077 return 0;
3080 static LRESULT
3081 REBAR_MouseLeave (REBAR_INFO *infoPtr)
3083 if (infoPtr->ichevronhotBand >= 0)
3085 REBAR_BAND *lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3086 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3088 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3089 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3092 infoPtr->iOldBand = -1;
3093 infoPtr->ichevronhotBand = -2;
3095 return TRUE;
3098 static LRESULT
3099 REBAR_MouseMove (REBAR_INFO *infoPtr, LPARAM lParam)
3101 REBAR_BAND *lpChevronBand;
3102 POINT ptMove;
3104 ptMove.x = (short)LOWORD(lParam);
3105 ptMove.y = (short)HIWORD(lParam);
3107 /* if we are currently dragging a band */
3108 if (infoPtr->iGrabbedBand >= 0)
3110 REBAR_BAND *band;
3111 int yPtMove = (infoPtr->dwStyle & CCS_VERT ? ptMove.x : ptMove.y);
3113 if (GetCapture() != infoPtr->hwndSelf)
3114 ERR("We are dragging but haven't got capture?!?\n");
3116 band = REBAR_GetBand(infoPtr, infoPtr->iGrabbedBand);
3118 /* if mouse did not move much, exit */
3119 if ((abs(ptMove.x - infoPtr->dragNow.x) <= mindragx) &&
3120 (abs(ptMove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3122 /* on first significant mouse movement, issue notify */
3123 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
3124 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
3125 /* Notify returned TRUE - abort drag */
3126 infoPtr->dragStart.x = 0;
3127 infoPtr->dragStart.y = 0;
3128 infoPtr->dragNow = infoPtr->dragStart;
3129 infoPtr->iGrabbedBand = -1;
3130 ReleaseCapture ();
3131 return 0;
3133 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
3136 /* Test for valid drag case - must not be first band in row */
3137 if ((yPtMove < band->rcBand.top) ||
3138 (yPtMove > band->rcBand.bottom)) {
3139 REBAR_HandleUDDrag (infoPtr, &ptMove);
3141 else {
3142 REBAR_HandleLRDrag (infoPtr, &ptMove);
3145 else
3147 INT iHitBand;
3148 UINT htFlags;
3149 TRACKMOUSEEVENT trackinfo;
3151 REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
3153 if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
3155 lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3156 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3158 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3159 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3161 infoPtr->ichevronhotBand = -2;
3164 if (htFlags == RBHT_CHEVRON)
3166 /* fill in the TRACKMOUSEEVENT struct */
3167 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
3168 trackinfo.dwFlags = TME_QUERY;
3169 trackinfo.hwndTrack = infoPtr->hwndSelf;
3170 trackinfo.dwHoverTime = 0;
3172 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
3173 _TrackMouseEvent(&trackinfo);
3175 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
3176 if(!(trackinfo.dwFlags & TME_LEAVE))
3178 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
3180 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
3181 /* and can properly deactivate the hot chevron */
3182 _TrackMouseEvent(&trackinfo);
3185 lpChevronBand = REBAR_GetBand(infoPtr, iHitBand);
3186 if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
3188 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
3189 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3190 infoPtr->ichevronhotBand = iHitBand;
3193 infoPtr->iOldBand = iHitBand;
3196 return 0;
3200 static inline LRESULT
3201 REBAR_NCCalcSize (const REBAR_INFO *infoPtr, RECT *rect)
3203 if (infoPtr->dwStyle & WS_BORDER) {
3204 rect->left = min(rect->left + GetSystemMetrics(SM_CXEDGE), rect->right);
3205 rect->right = max(rect->right - GetSystemMetrics(SM_CXEDGE), rect->left);
3206 rect->top = min(rect->top + GetSystemMetrics(SM_CYEDGE), rect->bottom);
3207 rect->bottom = max(rect->bottom - GetSystemMetrics(SM_CYEDGE), rect->top);
3210 TRACE("new client=(%s)\n", wine_dbgstr_rect(rect));
3211 return 0;
3215 static LRESULT
3216 REBAR_NCCreate (HWND hwnd, const CREATESTRUCTW *cs)
3218 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3219 RECT wnrc1, clrc1;
3220 NONCLIENTMETRICSW ncm;
3221 HFONT tfont;
3223 if (infoPtr) {
3224 ERR("Strange info structure pointer *not* NULL\n");
3225 return FALSE;
3228 if (TRACE_ON(rebar)) {
3229 GetWindowRect(hwnd, &wnrc1);
3230 GetClientRect(hwnd, &clrc1);
3231 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
3232 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
3233 cs->x, cs->y, cs->cx, cs->cy);
3236 /* allocate memory for info structure */
3237 infoPtr = Alloc (sizeof(REBAR_INFO));
3238 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
3240 /* initialize info structure - initial values are 0 */
3241 infoPtr->clrBk = CLR_NONE;
3242 infoPtr->clrText = CLR_NONE;
3243 infoPtr->clrBtnText = comctl32_color.clrBtnText;
3244 infoPtr->clrBtnFace = comctl32_color.clrBtnFace;
3245 infoPtr->iOldBand = -1;
3246 infoPtr->ichevronhotBand = -2;
3247 infoPtr->iGrabbedBand = -1;
3248 infoPtr->hwndSelf = hwnd;
3249 infoPtr->DoRedraw = TRUE;
3250 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3251 infoPtr->hcurHorz = LoadCursorW (0, (LPWSTR)IDC_SIZEWE);
3252 infoPtr->hcurVert = LoadCursorW (0, (LPWSTR)IDC_SIZENS);
3253 infoPtr->hcurDrag = LoadCursorW (0, (LPWSTR)IDC_SIZE);
3254 infoPtr->fStatus = 0;
3255 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3256 infoPtr->bands = DPA_Create(8);
3258 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3259 REBAR_NotifyFormat(infoPtr, NF_REQUERY);
3261 /* Stow away the original style */
3262 infoPtr->orgStyle = cs->style;
3263 /* add necessary styles to the requested styles */
3264 infoPtr->dwStyle = cs->style | WS_VISIBLE;
3265 if ((infoPtr->dwStyle & CCS_LAYOUT_MASK) == 0)
3266 infoPtr->dwStyle |= CCS_TOP;
3267 SetWindowLongW (hwnd, GWL_STYLE, infoPtr->dwStyle);
3269 /* get font handle for Caption Font */
3270 ncm.cbSize = sizeof(ncm);
3271 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
3272 /* if the font is bold, set to normal */
3273 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3274 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3276 tfont = CreateFontIndirectW (&ncm.lfCaptionFont);
3277 if (tfont) {
3278 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3281 return TRUE;
3285 static LRESULT
3286 REBAR_NCHitTest (const REBAR_INFO *infoPtr, LPARAM lParam)
3288 NMMOUSE nmmouse;
3289 POINT clpt;
3290 INT i;
3291 UINT scrap;
3292 LRESULT ret = HTCLIENT;
3295 * Differences from doc at MSDN (as observed with version 4.71 of
3296 * comctl32.dll
3297 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3298 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3299 * 3. native always seems to return HTCLIENT if notify return is 0.
3302 clpt.x = (short)LOWORD(lParam);
3303 clpt.y = (short)HIWORD(lParam);
3304 ScreenToClient (infoPtr->hwndSelf, &clpt);
3305 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3306 (INT *)&nmmouse.dwItemSpec);
3307 nmmouse.dwItemData = 0;
3308 nmmouse.pt = clpt;
3309 nmmouse.dwHitInfo = 0;
3310 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST)))
3312 TRACE("notify changed return value from %Id to %d\n", ret, i);
3313 ret = (LRESULT) i;
3315 TRACE("returning %Id, client point %s\n", ret, wine_dbgstr_point(&clpt));
3316 return ret;
3320 static LRESULT
3321 REBAR_NCPaint (const REBAR_INFO *infoPtr)
3323 RECT rcWindow;
3324 HDC hdc;
3325 HTHEME theme;
3327 if (infoPtr->dwStyle & WS_MINIMIZE)
3328 return 0; /* Nothing to do */
3330 if (infoPtr->dwStyle & WS_BORDER) {
3332 /* adjust rectangle and draw the necessary edge */
3333 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3334 return 0;
3335 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3336 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3337 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3338 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3339 ReleaseDC( infoPtr->hwndSelf, hdc );
3341 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
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 DrawThemeEdge (theme, hdc, 0, 0, &rcWindow, BDR_RAISEDINNER, BF_TOP, NULL);
3350 ReleaseDC( infoPtr->hwndSelf, hdc );
3353 return 0;
3357 static LRESULT
3358 REBAR_NotifyFormat (REBAR_INFO *infoPtr, LPARAM cmd)
3360 INT i;
3362 if (cmd == NF_REQUERY) {
3363 i = SendMessageW(REBAR_GetNotifyParent (infoPtr),
3364 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
3365 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
3366 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
3367 i = NFR_ANSI;
3369 infoPtr->bUnicode = (i == NFR_UNICODE);
3370 return (LRESULT)i;
3372 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3376 static LRESULT
3377 REBAR_Paint (const REBAR_INFO *infoPtr, HDC hdc)
3379 if (hdc) {
3380 TRACE("painting\n");
3381 REBAR_Refresh (infoPtr, hdc);
3382 } else {
3383 PAINTSTRUCT ps;
3384 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
3385 TRACE("painting (%s)\n", wine_dbgstr_rect(&ps.rcPaint));
3386 if (ps.fErase) {
3387 /* Erase area of paint if requested */
3388 REBAR_EraseBkGnd (infoPtr, hdc);
3390 REBAR_Refresh (infoPtr, hdc);
3391 EndPaint (infoPtr->hwndSelf, &ps);
3394 return 0;
3398 static LRESULT
3399 REBAR_SetCursor (const REBAR_INFO *infoPtr, LPARAM lParam)
3401 POINT pt;
3402 UINT flags;
3404 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
3406 GetCursorPos (&pt);
3407 ScreenToClient (infoPtr->hwndSelf, &pt);
3409 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
3411 if (flags == RBHT_GRABBER) {
3412 if ((infoPtr->dwStyle & CCS_VERT) &&
3413 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
3414 SetCursor (infoPtr->hcurVert);
3415 else
3416 SetCursor (infoPtr->hcurHorz);
3418 else if (flags != RBHT_CLIENT)
3419 SetCursor (infoPtr->hcurArrow);
3421 return 0;
3425 static LRESULT
3426 REBAR_SetFont (REBAR_INFO *infoPtr, HFONT font)
3428 REBAR_BAND *lpBand;
3429 UINT i;
3431 infoPtr->hFont = font;
3433 /* revalidate all bands to change sizes of text in headers of bands */
3434 for (i=0; i<infoPtr->uNumBands; i++) {
3435 lpBand = REBAR_GetBand(infoPtr, i);
3436 REBAR_ValidateBand (infoPtr, lpBand);
3439 REBAR_Layout(infoPtr);
3440 return 0;
3444 /*****************************************************
3446 * Handles the WM_SETREDRAW message.
3448 * Documentation:
3449 * According to testing V4.71 of COMCTL32 returns the
3450 * *previous* status of the redraw flag (either 0 or -1)
3451 * instead of the MSDN documented value of 0 if handled
3453 *****************************************************/
3454 static inline LRESULT
3455 REBAR_SetRedraw (REBAR_INFO *infoPtr, BOOL redraw)
3457 BOOL oldredraw = infoPtr->DoRedraw;
3459 TRACE("set to %s, fStatus=%08x\n",
3460 (redraw) ? "TRUE" : "FALSE", infoPtr->fStatus);
3461 infoPtr->DoRedraw = redraw;
3462 if (redraw) {
3463 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
3464 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
3465 REBAR_ForceResize (infoPtr);
3466 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3468 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
3470 return (oldredraw) ? -1 : 0;
3474 static LRESULT
3475 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3477 TRACE("wParam %Ix, lParam %Ix\n", wParam, lParam);
3479 /* avoid _Layout resize recursion (but it shouldn't be infinite and it seems Windows does recurse) */
3480 if (infoPtr->fStatus & SELF_RESIZE) {
3481 infoPtr->fStatus &= ~SELF_RESIZE;
3482 TRACE("SELF_RESIZE was set, reset, fStatus=%08x lparam %Ix\n", infoPtr->fStatus, lParam);
3483 return 0;
3486 if (infoPtr->dwStyle & RBS_AUTOSIZE)
3487 REBAR_AutoSize(infoPtr, TRUE);
3488 else
3489 REBAR_Layout(infoPtr);
3491 return 0;
3495 static LRESULT
3496 REBAR_StyleChanged (REBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
3498 TRACE("current style %#lx, styleOld %#lx, style being set to %#lx\n",
3499 infoPtr->dwStyle, lpStyle->styleOld, lpStyle->styleNew);
3500 if (nType == GWL_STYLE)
3502 infoPtr->orgStyle = infoPtr->dwStyle = lpStyle->styleNew;
3503 /* maybe it should be COMMON_STYLES like in toolbar */
3504 if ((lpStyle->styleNew ^ lpStyle->styleOld) & CCS_VERT)
3505 REBAR_Layout(infoPtr);
3507 return FALSE;
3510 /* update theme after a WM_THEMECHANGED message */
3511 static LRESULT theme_changed (REBAR_INFO* infoPtr)
3513 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
3514 CloseThemeData (theme);
3515 OpenThemeData(infoPtr->hwndSelf, themeClass);
3516 return 0;
3519 static LRESULT
3520 REBAR_WindowPosChanged (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3522 LRESULT ret;
3523 RECT rc;
3525 ret = DefWindowProcW(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
3526 wParam, lParam);
3527 GetWindowRect(infoPtr->hwndSelf, &rc);
3528 TRACE("hwnd %p new pos (%s)\n", infoPtr->hwndSelf, wine_dbgstr_rect(&rc));
3529 return ret;
3533 static LRESULT WINAPI
3534 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3536 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3538 TRACE("hwnd %p, msg %x, wparam %Ix, lparam %Ix\n", hwnd, uMsg, wParam, lParam);
3540 if (!infoPtr && (uMsg != WM_NCCREATE))
3541 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3542 switch (uMsg)
3544 /* case RB_BEGINDRAG: */
3546 case RB_DELETEBAND:
3547 return REBAR_DeleteBand (infoPtr, wParam);
3549 /* case RB_DRAGMOVE: */
3550 /* case RB_ENDDRAG: */
3552 case RB_GETBANDBORDERS:
3553 return REBAR_GetBandBorders (infoPtr, wParam, (LPRECT)lParam);
3555 case RB_GETBANDCOUNT:
3556 return REBAR_GetBandCount (infoPtr);
3558 case RB_GETBANDINFO_OLD:
3559 case RB_GETBANDINFOA:
3560 case RB_GETBANDINFOW:
3561 return REBAR_GetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3562 uMsg == RB_GETBANDINFOW);
3563 case RB_GETBARHEIGHT:
3564 return REBAR_GetBarHeight (infoPtr);
3566 case RB_GETBARINFO:
3567 return REBAR_GetBarInfo (infoPtr, (LPREBARINFO)lParam);
3569 case RB_GETBKCOLOR:
3570 return REBAR_GetBkColor (infoPtr);
3572 /* case RB_GETCOLORSCHEME: */
3573 /* case RB_GETDROPTARGET: */
3575 case RB_GETPALETTE:
3576 return REBAR_GetPalette (infoPtr);
3578 case RB_GETRECT:
3579 return REBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
3581 case RB_GETROWCOUNT:
3582 return REBAR_GetRowCount (infoPtr);
3584 case RB_GETROWHEIGHT:
3585 return REBAR_GetRowHeight (infoPtr, wParam);
3587 case RB_GETTEXTCOLOR:
3588 return REBAR_GetTextColor (infoPtr);
3590 case RB_GETTOOLTIPS:
3591 return REBAR_GetToolTips (infoPtr);
3593 case RB_GETUNICODEFORMAT:
3594 return REBAR_GetUnicodeFormat (infoPtr);
3596 case CCM_GETVERSION:
3597 return REBAR_GetVersion (infoPtr);
3599 case RB_HITTEST:
3600 return REBAR_HitTest (infoPtr, (LPRBHITTESTINFO)lParam);
3602 case RB_IDTOINDEX:
3603 return REBAR_IdToIndex (infoPtr, wParam);
3605 case RB_INSERTBANDA:
3606 case RB_INSERTBANDW:
3607 return REBAR_InsertBandT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3608 uMsg == RB_INSERTBANDW);
3609 case RB_MAXIMIZEBAND:
3610 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
3612 case RB_MINIMIZEBAND:
3613 return REBAR_MinimizeBand (infoPtr, wParam);
3615 case RB_MOVEBAND:
3616 return REBAR_MoveBand (infoPtr, wParam, lParam);
3618 case RB_PUSHCHEVRON:
3619 return REBAR_PushChevron (infoPtr, wParam, lParam);
3621 case RB_SETBANDINFOA:
3622 case RB_SETBANDINFOW:
3623 return REBAR_SetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3624 uMsg == RB_SETBANDINFOW);
3625 case RB_SETBARINFO:
3626 return REBAR_SetBarInfo (infoPtr, (LPREBARINFO)lParam);
3628 case RB_SETBKCOLOR:
3629 return REBAR_SetBkColor (infoPtr, lParam);
3631 /* case RB_SETCOLORSCHEME: */
3632 /* case RB_SETPALETTE: */
3634 case RB_SETPARENT:
3635 return REBAR_SetParent (infoPtr, (HWND)wParam);
3637 case RB_SETTEXTCOLOR:
3638 return REBAR_SetTextColor (infoPtr, lParam);
3640 /* case RB_SETTOOLTIPS: */
3642 case RB_SETUNICODEFORMAT:
3643 return REBAR_SetUnicodeFormat (infoPtr, wParam);
3645 case CCM_SETVERSION:
3646 return REBAR_SetVersion (infoPtr, (INT)wParam);
3648 case RB_SHOWBAND:
3649 return REBAR_ShowBand (infoPtr, wParam, lParam);
3651 case RB_SIZETORECT:
3652 return REBAR_SizeToRect (infoPtr, (LPCRECT)lParam);
3655 /* Messages passed to parent */
3656 case WM_COMMAND:
3657 case WM_DRAWITEM:
3658 case WM_NOTIFY:
3659 case WM_MEASUREITEM:
3660 return SendMessageW(REBAR_GetNotifyParent (infoPtr), uMsg, wParam, lParam);
3663 /* case WM_CHARTOITEM: supported according to ControlSpy */
3665 case WM_CREATE:
3666 return REBAR_Create (infoPtr, (LPCREATESTRUCTW)lParam);
3668 case WM_DESTROY:
3669 return REBAR_Destroy (infoPtr);
3671 case WM_ERASEBKGND:
3672 return REBAR_EraseBkGnd (infoPtr, (HDC)wParam);
3674 case WM_GETFONT:
3675 return REBAR_GetFont (infoPtr);
3677 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
3679 case WM_LBUTTONDOWN:
3680 return REBAR_LButtonDown (infoPtr, lParam);
3682 case WM_LBUTTONUP:
3683 return REBAR_LButtonUp (infoPtr);
3685 case WM_MOUSEMOVE:
3686 return REBAR_MouseMove (infoPtr, lParam);
3688 case WM_MOUSELEAVE:
3689 return REBAR_MouseLeave (infoPtr);
3691 case WM_NCCALCSIZE:
3692 return REBAR_NCCalcSize (infoPtr, (RECT*)lParam);
3694 case WM_NCCREATE:
3695 return REBAR_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
3697 case WM_NCHITTEST:
3698 return REBAR_NCHitTest (infoPtr, lParam);
3700 case WM_NCPAINT:
3701 return REBAR_NCPaint (infoPtr);
3703 case WM_NOTIFYFORMAT:
3704 return REBAR_NotifyFormat (infoPtr, lParam);
3706 case WM_PRINTCLIENT:
3707 case WM_PAINT:
3708 return REBAR_Paint (infoPtr, (HDC)wParam);
3710 /* case WM_PALETTECHANGED: supported according to ControlSpy */
3711 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
3712 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
3713 /* case WM_RBUTTONUP: supported according to ControlSpy */
3715 case WM_SETCURSOR:
3716 return REBAR_SetCursor (infoPtr, lParam);
3718 case WM_SETFONT:
3719 return REBAR_SetFont (infoPtr, (HFONT)wParam);
3721 case WM_SETREDRAW:
3722 return REBAR_SetRedraw (infoPtr, wParam);
3724 case WM_SIZE:
3725 return REBAR_Size (infoPtr, wParam, lParam);
3727 case WM_STYLECHANGED:
3728 return REBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
3730 case WM_THEMECHANGED:
3731 return theme_changed (infoPtr);
3733 case WM_SYSCOLORCHANGE:
3734 COMCTL32_RefreshSysColors();
3735 return 0;
3737 /* case WM_VKEYTOITEM: supported according to ControlSpy */
3738 /* case WM_WININICHANGE: */
3740 case WM_WINDOWPOSCHANGED:
3741 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
3743 default:
3744 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
3745 ERR("unknown msg %04x, wp %Ix, lp %Ix\n", uMsg, wParam, lParam);
3746 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3751 VOID
3752 REBAR_Register (void)
3754 WNDCLASSW wndClass;
3756 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
3757 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
3758 wndClass.lpfnWndProc = REBAR_WindowProc;
3759 wndClass.cbClsExtra = 0;
3760 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
3761 wndClass.hCursor = 0;
3762 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
3763 #if GLATESTING
3764 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
3765 #endif
3766 wndClass.lpszClassName = REBARCLASSNAMEW;
3768 RegisterClassW (&wndClass);
3770 mindragx = GetSystemMetrics (SM_CXDRAG);
3771 mindragy = GetSystemMetrics (SM_CYDRAG);
3776 VOID
3777 REBAR_Unregister (void)
3779 UnregisterClassW (REBARCLASSNAMEW, NULL);