CreateDIBSection takes a const pointer to BITMAPINFO.
[wine/testsucceed.git] / dlls / comctl32 / rebar.c
blobbe8347c06519a270b1865af5a97e3608c0619589
1 /*
2 * Testing: set to 1 to make background brush *always* green
3 */
4 #define GLATESTING 0
6 /*
8 * 2. At "FIXME: problem # 2" WinRAR:
9 * if "#if 1" then last band draws in separate row
10 * if "#if 0" then last band draws in previous row *** just like native ***
13 #define PROBLEM2 0
16 * 3. REBAR_MoveChildWindows should have a loop because more than
17 * one pass is made (together with the RBN_CHILDSIZEs) is made on
18 * at least RB_INSERTBAND
23 * Rebar control rev 8e
25 * Copyright 1998, 1999 Eric Kohl
27 * This library is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU Lesser General Public
29 * License as published by the Free Software Foundation; either
30 * version 2.1 of the License, or (at your option) any later version.
32 * This library is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 * Lesser General Public License for more details.
37 * You should have received a copy of the GNU Lesser General Public
38 * License along with this library; if not, write to the Free Software
39 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 * NOTES
42 * An author is needed! Any volunteers?
43 * I will only improve this control once in a while.
44 * Eric <ekohl@abo.rhein-zeitung.de>
46 * TODO:
47 * - vertical placement
48 * - ComboBox and ComboBoxEx placement
49 * - center image
50 * - Layout code.
51 * - Display code.
52 * - Some messages.
53 * - All notifications.
55 * Changes Guy Albertelli <galberte@neo.lrun.com>
56 * rev 2,3,4
57 * - Implement initial version of row grouping, row separators,
58 * text and background colors. Support additional messages.
59 * Support RBBS_BREAK. Implement ERASEBKGND and improve painting.
60 * rev 5
61 * - implement support for dragging Gripper left or right in a row. Supports
62 * WM_LBUTTONDOWN, WM_LBUTTONUP, and WM_MOUSEMOVE. Also support
63 * RBS_BANDBORDERS.
64 * rev 6
65 * - Fix or implement notifications for RBN_HEIGHTCHANGE, RBN_CHILDSIZE.
66 * - Correct styles RBBS_NOGRIPPER, RBBS_GRIPPERALWAYS, and RBBS_FIXEDSIZE.
67 * - Fix algorithm for Layout and AdjustBand.
69 * rev 7
70 * - Fix algorithm for _Layout and _AdjustBand.
71 * - Fix or implement RBN_ENDDRAG, RB_MOVEBAND, WM_SETREDRAW,
72 * WM_STYLECHANGED, RB_MINIMIZEBAND, RBBS_VARIABLEHEIGHT, RBS_VARHEIGHT,
73 * RBBS_HIDDEN, WM_NOTIFYFORMAT, NM_NCHITTEST, WM_SETREDRAW, RBS_AUTOSIZE,
74 * WM_SETFONT, RBS_BORDERS
75 * - Create structures in WM_NCCREATE
76 * - Additional performance enhancements.
78 * rev 8
79 * 1. Create array of start and end band indexes by row and use.
80 * 2. Fix problem with REBAR_Layout Phase 2b to process only if only
81 * band in row.
82 * 3. Set the Caption Font (Regular) as default font for text.
83 * 4. Delete font handle on control distruction.
84 * 5. Add UpdateWindow call in _MoveChildWindows to match repainting done
85 * by native control
86 * 6. Improve some traces.
87 * 7. Invalidate window rectangles after SetBandInfo, InsertBand, ShowBand
88 * so that repainting is correct.
89 * 8. Implement RB_MAXIMIZEBAND for the "ideal=TRUE" case.
90 * 9. Implement item custom draw notifications partially. Only done for
91 * ITEMPREPAINT and ITEMPOSTPAINT. (Used by IE4 for "Favorites" frame
92 * to draw the word "Favorites").
93 * rev 8a
94 * 10. Handle CCS_NODIVIDER and fix WS_BORDER code.
95 * 11. Fix logic error in _AdjustBands where flag was set to valid band
96 * number (0) to indicate *no* band.
97 * 12. Fix CCS_VERT errors in _ForceResize, _NCCalcSize, and _NCPaint.
98 * 13. Support some special cases of CCS_TOP (and therefore CCS_LEFT),
99 * CCS_BOTTOM (and therefore CCS_RIGHT) and CCS_NOPARENTALIGN. Not
100 * at all sure whether this is all cases.
101 * 14. Handle returned value for the RBN_CHILDSIZE notify.
102 * 15. Implement RBBS_CHILDEDGE, and set each bands "offChild" at _Layout
103 * time.
104 * 16. Fix REBARSPACE. It should depend on CCS_NODIVIDER.
105 * rev 8b
106 * 17. Fix determination of whether Gripper is needed in _ValidateBand.
107 * 18. Fix _AdjustBand processing of RBBS_FIXEDSIZE.
108 * rev 8c
109 * 19. Fix problem in _Layout when all lengths are 0.
110 * 20. If CLR_NONE specified, we will use default BtnFace color when drawing.
111 * 21. Fix test in REBAR_Layout.
112 * rev 8d
113 * 22. Add support for WM_WINDOWPOSCHANGED to save new origin of window.
114 * 23. Correct RBN_CHILDSIZE rect value for CCS_VERT rebar.
115 * 24. Do UpdateWindow only if doing redraws.
116 * rev 8e
117 * 25. Adjust setting of offChild.cx based on RBBS_CHILDEDGE.
120 * Still to do:
121 * 2. Following still not handled: RBBS_FIXEDBMP,
122 * CCS_NORESIZE,
123 * CCS_NOMOVEX, CCS_NOMOVEY
124 * 3. Following are only partially handled:
125 * RBS_AUTOSIZE, RBBS_VARIABLEHEIGHT
126 * 5. Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
127 * to set the size of the separator width (the value SEP_WIDTH_SIZE
128 * in here). Should be fixed!!
129 * 6. The following messages are not implemented:
130 * RB_BEGINDRAG, RB_DRAGMOVE, RB_ENDDRAG, RB_GETCOLORSCHEME,
131 * RB_GETDROPTARGET, RB_MAXIMIZEBAND,
132 * RB_SETCOLORSCHEME, RB_SETPALETTE, RB_SETTOOLTIPS
133 * WM_CHARTOITEM, WM_LBUTTONDBLCLK, WM_MEASUREITEM,
134 * WM_PALETTECHANGED, WM_PRINTCLIENT, WM_QUERYNEWPALETTE,
135 * WM_RBUTTONDOWN, WM_RBUTTONUP,
136 * WM_SYSCOLORCHANGE, WM_VKEYTOITEM, WM_WININICHANGE
137 * 7. The following notifications are not implemented:
138 * NM_CUSTOMDRAW, NM_RELEASEDCAPTURE
139 * RBN_MINMAX
142 #include <stdarg.h>
143 #include <stdlib.h>
144 #include <string.h>
146 #include "windef.h"
147 #include "winbase.h"
148 #include "wingdi.h"
149 #include "wine/unicode.h"
150 #include "winuser.h"
151 #include "winnls.h"
152 #include "commctrl.h"
153 #include "comctl32.h"
154 #include "wine/debug.h"
156 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
158 typedef struct
160 UINT fStyle;
161 UINT fMask;
162 COLORREF clrFore;
163 COLORREF clrBack;
164 INT iImage;
165 HWND hwndChild;
166 UINT cxMinChild; /* valid if _CHILDSIZE */
167 UINT cyMinChild; /* valid if _CHILDSIZE */
168 UINT cx; /* valid if _SIZE */
169 HBITMAP hbmBack;
170 UINT wID;
171 UINT cyChild; /* valid if _CHILDSIZE */
172 UINT cyMaxChild; /* valid if _CHILDSIZE */
173 UINT cyIntegral; /* valid if _CHILDSIZE */
174 UINT cxIdeal;
175 LPARAM lParam;
176 UINT cxHeader;
178 UINT lcx; /* minimum cx for band */
179 UINT ccx; /* current cx for band */
180 UINT hcx; /* maximum cx for band */
181 UINT lcy; /* minimum cy for band */
182 UINT ccy; /* current cy for band */
183 UINT hcy; /* maximum cy for band */
185 SIZE offChild; /* x,y offset if child is not FIXEDSIZE */
186 UINT uMinHeight;
187 INT iRow; /* row this band assigned to */
188 UINT fStatus; /* status flags, reset only by _Validate */
189 UINT fDraw; /* drawing flags, reset only by _Layout */
190 UINT uCDret; /* last return from NM_CUSTOMDRAW */
191 RECT rcoldBand; /* previous calculated band rectangle */
192 RECT rcBand; /* calculated band rectangle */
193 RECT rcGripper; /* calculated gripper rectangle */
194 RECT rcCapImage; /* calculated caption image rectangle */
195 RECT rcCapText; /* calculated caption text rectangle */
196 RECT rcChild; /* calculated child rectangle */
197 RECT rcChevron; /* calculated chevron rectangle */
199 LPWSTR lpText;
200 HWND hwndPrevParent;
201 } REBAR_BAND;
203 /* fStatus flags */
204 #define HAS_GRIPPER 0x00000001
205 #define HAS_IMAGE 0x00000002
206 #define HAS_TEXT 0x00000004
208 /* fDraw flags */
209 #define DRAW_GRIPPER 0x00000001
210 #define DRAW_IMAGE 0x00000002
211 #define DRAW_TEXT 0x00000004
212 #define DRAW_RIGHTSEP 0x00000010
213 #define DRAW_BOTTOMSEP 0x00000020
214 #define DRAW_CHEVRONHOT 0x00000040
215 #define DRAW_CHEVRONPUSHED 0x00000080
216 #define NTF_INVALIDATE 0x01000000
218 typedef struct
220 INT istartband; /* index of first band in row */
221 INT iendband; /* index of last band in row */
222 } REBAR_ROW;
225 typedef struct
227 COLORREF clrBk; /* background color */
228 COLORREF clrText; /* text color */
229 COLORREF clrBtnText; /* system color for BTNTEXT */
230 COLORREF clrBtnFace; /* system color for BTNFACE */
231 HIMAGELIST himl; /* handle to imagelist */
232 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
233 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
234 HWND hwndSelf; /* handle of REBAR window itself */
235 HWND hwndToolTip; /* handle to the tool tip control */
236 HWND hwndNotify; /* notification window (parent) */
237 HFONT hDefaultFont;
238 HFONT hFont; /* handle to the rebar's font */
239 SIZE imageSize; /* image size (image list) */
240 DWORD dwStyle; /* window style */
241 SIZE calcSize; /* calculated rebar size */
242 SIZE oldSize; /* previous calculated rebar size */
243 BOOL bUnicode; /* TRUE if this window is W type */
244 BOOL NtfUnicode; /* TRUE if parent wants notify in W format */
245 BOOL DoRedraw; /* TRUE to acutally draw bands */
246 UINT fStatus; /* Status flags (see below) */
247 HCURSOR hcurArrow; /* handle to the arrow cursor */
248 HCURSOR hcurHorz; /* handle to the EW cursor */
249 HCURSOR hcurVert; /* handle to the NS cursor */
250 HCURSOR hcurDrag; /* handle to the drag cursor */
251 INT iVersion; /* version number */
252 POINTS dragStart; /* x,y of button down */
253 POINTS dragNow; /* x,y of this MouseMove */
254 INT iOldBand; /* last band that had the mouse cursor over it */
255 INT ihitoffset; /* offset of hotspot from gripper.left */
256 POINT origin; /* left/upper corner of client */
257 INT ichevronhotBand; /* last band that had a hot chevron */
258 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
260 REBAR_ROW *rows; /* pointer to row indexes */
261 REBAR_BAND *bands; /* pointer to the array of rebar bands */
262 } REBAR_INFO;
264 /* fStatus flags */
265 #define BEGIN_DRAG_ISSUED 0x00000001
266 #define AUTO_RESIZE 0x00000002
267 #define RESIZE_ANYHOW 0x00000004
268 #define NTF_HGHTCHG 0x00000008
269 #define BAND_NEEDS_LAYOUT 0x00000010
270 #define BAND_NEEDS_REDRAW 0x00000020
271 #define CREATE_RUNNING 0x00000040
273 /* ---- REBAR layout constants. Mostly determined by ---- */
274 /* ---- experiment on WIN 98. ---- */
276 /* Width (or height) of separators between bands (either horz. or */
277 /* vert.). True only if RBS_BANDBORDERS is set */
278 #define SEP_WIDTH_SIZE 2
279 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
281 /* Blank (background color) space between Gripper (if present) */
282 /* and next item (image, text, or window). Always present */
283 #define REBAR_ALWAYS_SPACE 4
285 /* Blank (background color) space after Image (if present). */
286 #define REBAR_POST_IMAGE 2
288 /* Blank (background color) space after Text (if present). */
289 #define REBAR_POST_TEXT 4
291 /* Height of vertical gripper in a CCS_VERT rebar. */
292 #define GRIPPER_HEIGHT 16
294 /* Blank (background color) space before Gripper (if present). */
295 #define REBAR_PRE_GRIPPER 2
297 /* Width (of normal vertical gripper) or height (of horz. gripper) */
298 /* if present. */
299 #define GRIPPER_WIDTH 3
301 /* Width of the chevron button if present */
302 #define CHEVRON_WIDTH 10
304 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
305 /* either top or bottom */
306 #define REBAR_DIVIDER 2
308 /* This is the increment that is used over the band height */
309 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
311 /* ---- End of REBAR layout constants. ---- */
313 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
315 /* The following 6 defines return the proper rcBand element */
316 /* depending on whether CCS_VERT was set. */
317 #define rcBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.top : b->rcBand.left)
318 #define rcBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.bottom : b->rcBand.right)
319 #define rcBw(b) ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.bottom - b->rcBand.top) : \
320 (b->rcBand.right - b->rcBand.left))
321 #define ircBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.left : b->rcBand.top)
322 #define ircBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.right : b->rcBand.bottom)
323 #define ircBw(b) ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.right - b->rcBand.left) : \
324 (b->rcBand.bottom - b->rcBand.top))
326 /* The following define determines if a given band is hidden */
327 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
328 ((infoPtr->dwStyle & CCS_VERT) && \
329 ((a)->fStyle & RBBS_NOVERT)))
331 /* The following defines adjust the right or left end of a rectangle */
332 #define READJ(b,i) do { if(infoPtr->dwStyle & CCS_VERT) b->rcBand.bottom+=(i); \
333 else b->rcBand.right += (i); } while(0)
334 #define LEADJ(b,i) do { if(infoPtr->dwStyle & CCS_VERT) b->rcBand.top+=(i); \
335 else b->rcBand.left += (i); } while(0)
338 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongA (hwnd, 0))
341 /* "constant values" retrieved when DLL was initialized */
342 /* FIXME we do this when the classes are registered. */
343 static UINT mindragx = 0;
344 static UINT mindragy = 0;
346 static const char *band_stylename[] = {
347 "RBBS_BREAK", /* 0001 */
348 "RBBS_FIXEDSIZE", /* 0002 */
349 "RBBS_CHILDEDGE", /* 0004 */
350 "RBBS_HIDDEN", /* 0008 */
351 "RBBS_NOVERT", /* 0010 */
352 "RBBS_FIXEDBMP", /* 0020 */
353 "RBBS_VARIABLEHEIGHT", /* 0040 */
354 "RBBS_GRIPPERALWAYS", /* 0080 */
355 "RBBS_NOGRIPPER", /* 0100 */
356 NULL };
358 static const char *band_maskname[] = {
359 "RBBIM_STYLE", /* 0x00000001 */
360 "RBBIM_COLORS", /* 0x00000002 */
361 "RBBIM_TEXT", /* 0x00000004 */
362 "RBBIM_IMAGE", /* 0x00000008 */
363 "RBBIM_CHILD", /* 0x00000010 */
364 "RBBIM_CHILDSIZE", /* 0x00000020 */
365 "RBBIM_SIZE", /* 0x00000040 */
366 "RBBIM_BACKGROUND", /* 0x00000080 */
367 "RBBIM_ID", /* 0x00000100 */
368 "RBBIM_IDEALSIZE", /* 0x00000200 */
369 "RBBIM_LPARAM", /* 0x00000400 */
370 "RBBIM_HEADERSIZE", /* 0x00000800 */
371 NULL };
374 static CHAR line[200];
377 static CHAR *
378 REBAR_FmtStyle( UINT style)
380 INT i = 0;
382 *line = 0;
383 while (band_stylename[i]) {
384 if (style & (1<<i)) {
385 if (*line != 0) strcat(line, " | ");
386 strcat(line, band_stylename[i]);
388 i++;
390 return line;
394 static CHAR *
395 REBAR_FmtMask( UINT mask)
397 INT i = 0;
399 *line = 0;
400 while (band_maskname[i]) {
401 if (mask & (1<<i)) {
402 if (*line != 0) strcat(line, " | ");
403 strcat(line, band_maskname[i]);
405 i++;
407 return line;
411 static VOID
412 REBAR_DumpBandInfo( LPREBARBANDINFOA pB)
414 if( !TRACE_ON(rebar) ) return;
415 TRACE("band info: ID=%u, size=%u, child=%p, clrF=0x%06lx, clrB=0x%06lx\n",
416 pB->wID, pB->cbSize, pB->hwndChild, pB->clrFore, pB->clrBack);
417 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
418 if (pB->fMask & RBBIM_STYLE)
419 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
420 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
421 TRACE("band info:");
422 if (pB->fMask & RBBIM_SIZE)
423 TRACE(" cx=%u", pB->cx);
424 if (pB->fMask & RBBIM_IDEALSIZE)
425 TRACE(" xIdeal=%u", pB->cxIdeal);
426 if (pB->fMask & RBBIM_HEADERSIZE)
427 TRACE(" xHeader=%u", pB->cxHeader);
428 if (pB->fMask & RBBIM_LPARAM)
429 TRACE(" lParam=0x%08lx", pB->lParam);
430 TRACE("\n");
432 if (pB->fMask & RBBIM_CHILDSIZE)
433 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
434 pB->cxMinChild,
435 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
438 static VOID
439 REBAR_DumpBand (REBAR_INFO *iP)
441 REBAR_BAND *pB;
442 UINT i;
444 if(! TRACE_ON(rebar) ) return;
446 TRACE("hwnd=%p: color=%08lx/%08lx, bands=%u, rows=%u, cSize=%ld,%ld\n",
447 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
448 iP->calcSize.cx, iP->calcSize.cy);
449 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
450 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
451 iP->dragNow.x, iP->dragNow.y,
452 iP->iGrabbedBand);
453 TRACE("hwnd=%p: style=%08lx, I'm Unicode=%s, notify in Unicode=%s, redraw=%s\n",
454 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
455 (iP->NtfUnicode)?"TRUE":"FALSE", (iP->DoRedraw)?"TRUE":"FALSE");
456 for (i = 0; i < iP->uNumBands; i++) {
457 pB = &iP->bands[i];
458 TRACE("band # %u: ID=%u, child=%p, row=%u, clrF=0x%06lx, clrB=0x%06lx\n",
459 i, pB->wID, pB->hwndChild, pB->iRow, pB->clrFore, pB->clrBack);
460 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
461 if (pB->fMask & RBBIM_STYLE)
462 TRACE("band # %u: style=0x%08x (%s)\n",
463 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
464 TRACE("band # %u: uMinH=%u xHeader=%u",
465 i, pB->uMinHeight, pB->cxHeader);
466 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
467 if (pB->fMask & RBBIM_SIZE)
468 TRACE(" cx=%u", pB->cx);
469 if (pB->fMask & RBBIM_IDEALSIZE)
470 TRACE(" xIdeal=%u", pB->cxIdeal);
471 if (pB->fMask & RBBIM_LPARAM)
472 TRACE(" lParam=0x%08lx", pB->lParam);
474 TRACE("\n");
475 if (RBBIM_CHILDSIZE)
476 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
477 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
478 if (pB->fMask & RBBIM_TEXT)
479 TRACE("band # %u: text=%s\n",
480 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
481 TRACE("band # %u: lcx=%u, ccx=%u, hcx=%u, lcy=%u, ccy=%u, hcy=%u, offChild=%ld,%ld\n",
482 i, pB->lcx, pB->ccx, pB->hcx, pB->lcy, pB->ccy, pB->hcy, pB->offChild.cx, pB->offChild.cy);
483 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%ld,%ld)-(%ld,%ld), Grip=(%ld,%ld)-(%ld,%ld)\n",
484 i, pB->fStatus, pB->fDraw,
485 pB->rcBand.left, pB->rcBand.top, pB->rcBand.right, pB->rcBand.bottom,
486 pB->rcGripper.left, pB->rcGripper.top, pB->rcGripper.right, pB->rcGripper.bottom);
487 TRACE("band # %u: Img=(%ld,%ld)-(%ld,%ld), Txt=(%ld,%ld)-(%ld,%ld), Child=(%ld,%ld)-(%ld,%ld)\n",
489 pB->rcCapImage.left, pB->rcCapImage.top, pB->rcCapImage.right, pB->rcCapImage.bottom,
490 pB->rcCapText.left, pB->rcCapText.top, pB->rcCapText.right, pB->rcCapText.bottom,
491 pB->rcChild.left, pB->rcChild.top, pB->rcChild.right, pB->rcChild.bottom);
496 static void
497 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
499 INT x, y;
500 HPEN hPen, hOldPen;
502 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
503 hOldPen = SelectObject ( hdc, hPen );
504 x = left + 2;
505 y = top;
506 MoveToEx (hdc, x, y, NULL);
507 LineTo (hdc, x+5, y++); x++;
508 MoveToEx (hdc, x, y, NULL);
509 LineTo (hdc, x+3, y++); x++;
510 MoveToEx (hdc, x, y, NULL);
511 LineTo (hdc, x+1, y++);
512 SelectObject( hdc, hOldPen );
513 DeleteObject( hPen );
516 static HWND
517 REBAR_GetNotifyParent (REBAR_INFO *infoPtr)
519 HWND parent, owner;
521 parent = infoPtr->hwndNotify;
522 if (!parent) {
523 parent = GetParent (infoPtr->hwndSelf);
524 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
525 if (owner) parent = owner;
527 return parent;
531 static INT
532 REBAR_Notify (NMHDR *nmhdr, REBAR_INFO *infoPtr, UINT code)
534 HWND parent;
536 parent = REBAR_GetNotifyParent (infoPtr);
537 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
538 nmhdr->hwndFrom = infoPtr->hwndSelf;
539 nmhdr->code = code;
541 TRACE("window %p, code=%08x, %s\n", parent, code,
542 (infoPtr->NtfUnicode) ? "via Unicode" : "via ANSI");
544 if (infoPtr->NtfUnicode)
545 return SendMessageW (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
546 (LPARAM)nmhdr);
547 else
548 return SendMessageA (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
549 (LPARAM)nmhdr);
552 static INT
553 REBAR_Notify_NMREBAR (REBAR_INFO *infoPtr, UINT uBand, UINT code)
555 NMREBAR notify_rebar;
556 REBAR_BAND *lpBand;
558 notify_rebar.dwMask = 0;
559 if (uBand!=-1) {
560 lpBand = &infoPtr->bands[uBand];
561 if (lpBand->fMask & RBBIM_ID) {
562 notify_rebar.dwMask |= RBNM_ID;
563 notify_rebar.wID = lpBand->wID;
565 if (lpBand->fMask & RBBIM_LPARAM) {
566 notify_rebar.dwMask |= RBNM_LPARAM;
567 notify_rebar.lParam = lpBand->lParam;
569 if (lpBand->fMask & RBBIM_STYLE) {
570 notify_rebar.dwMask |= RBNM_STYLE;
571 notify_rebar.fStyle = lpBand->fStyle;
574 notify_rebar.uBand = uBand;
575 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
578 static VOID
579 REBAR_DrawBand (HDC hdc, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
581 HFONT hOldFont = 0;
582 INT oldBkMode = 0;
583 NMCUSTOMDRAW nmcd;
585 if (lpBand->fDraw & DRAW_TEXT) {
586 hOldFont = SelectObject (hdc, infoPtr->hFont);
587 oldBkMode = SetBkMode (hdc, TRANSPARENT);
590 /* should test for CDRF_NOTIFYITEMDRAW here */
591 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
592 nmcd.hdc = hdc;
593 nmcd.rc = lpBand->rcBand;
594 nmcd.rc.right = lpBand->rcCapText.right;
595 nmcd.rc.bottom = lpBand->rcCapText.bottom;
596 nmcd.dwItemSpec = lpBand->wID;
597 nmcd.uItemState = 0;
598 nmcd.lItemlParam = lpBand->lParam;
599 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
600 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
601 if (oldBkMode != TRANSPARENT)
602 SetBkMode (hdc, oldBkMode);
603 SelectObject (hdc, hOldFont);
604 return;
607 /* draw gripper */
608 if (lpBand->fDraw & DRAW_GRIPPER)
609 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
611 /* draw caption image */
612 if (lpBand->fDraw & DRAW_IMAGE) {
613 POINT pt;
615 /* center image */
616 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
617 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
619 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
620 pt.x, pt.y,
621 ILD_TRANSPARENT);
624 /* draw caption text */
625 if (lpBand->fDraw & DRAW_TEXT) {
626 /* need to handle CDRF_NEWFONT here */
627 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
628 COLORREF oldcolor = CLR_NONE;
629 COLORREF new;
630 if (lpBand->clrFore != CLR_NONE) {
631 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
632 lpBand->clrFore;
633 oldcolor = SetTextColor (hdc, new);
635 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
636 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
637 if (oldBkMode != TRANSPARENT)
638 SetBkMode (hdc, oldBkMode);
639 if (lpBand->clrFore != CLR_NONE)
640 SetTextColor (hdc, oldcolor);
641 SelectObject (hdc, hOldFont);
644 if (!IsRectEmpty(&lpBand->rcChevron))
646 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
648 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
649 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
651 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
653 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
654 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
656 else
657 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
660 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
661 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
662 nmcd.hdc = hdc;
663 nmcd.rc = lpBand->rcBand;
664 nmcd.rc.right = lpBand->rcCapText.right;
665 nmcd.rc.bottom = lpBand->rcCapText.bottom;
666 nmcd.dwItemSpec = lpBand->wID;
667 nmcd.uItemState = 0;
668 nmcd.lItemlParam = lpBand->lParam;
669 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
674 static VOID
675 REBAR_Refresh (REBAR_INFO *infoPtr, HDC hdc)
677 REBAR_BAND *lpBand;
678 UINT i, oldrow;
680 if (!infoPtr->DoRedraw) return;
682 oldrow = infoPtr->bands[0].iRow;
683 for (i = 0; i < infoPtr->uNumBands; i++) {
684 lpBand = &infoPtr->bands[i];
686 if (HIDDENBAND(lpBand)) continue;
688 /* now draw the band */
689 TRACE("[%p] drawing band %i, flags=%08x\n",
690 infoPtr->hwndSelf, i, lpBand->fDraw);
691 REBAR_DrawBand (hdc, infoPtr, lpBand);
697 static void
698 REBAR_FixVert (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
699 INT mcy)
700 /* Function: */
701 /* Cycle through bands in row and fix height of each band. */
702 /* Also determine whether each band has changed. */
703 /* On entry: */
704 /* all bands at desired size. */
705 /* start and end bands are *not* hidden */
707 REBAR_BAND *lpBand;
708 INT i;
710 for (i = (INT)rowstart; i<=(INT)rowend; i++) {
711 lpBand = &infoPtr->bands[i];
712 if (HIDDENBAND(lpBand)) continue;
714 /* adjust height of bands in row to "mcy" value */
715 if (infoPtr->dwStyle & CCS_VERT) {
716 if (lpBand->rcBand.right != lpBand->rcBand.left + mcy)
717 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
719 else {
720 if (lpBand->rcBand.bottom != lpBand->rcBand.top + mcy)
721 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
725 /* mark whether we need to invalidate this band and trace */
726 if ((lpBand->rcoldBand.left !=lpBand->rcBand.left) ||
727 (lpBand->rcoldBand.top !=lpBand->rcBand.top) ||
728 (lpBand->rcoldBand.right !=lpBand->rcBand.right) ||
729 (lpBand->rcoldBand.bottom !=lpBand->rcBand.bottom)) {
730 lpBand->fDraw |= NTF_INVALIDATE;
731 TRACE("band %d row=%d: changed to (%ld,%ld)-(%ld,%ld) from (%ld,%ld)-(%ld,%ld)\n",
732 i, lpBand->iRow,
733 lpBand->rcBand.left, lpBand->rcBand.top,
734 lpBand->rcBand.right, lpBand->rcBand.bottom,
735 lpBand->rcoldBand.left, lpBand->rcoldBand.top,
736 lpBand->rcoldBand.right, lpBand->rcoldBand.bottom);
738 else
739 TRACE("band %d row=%d: unchanged (%ld,%ld)-(%ld,%ld)\n",
740 i, lpBand->iRow,
741 lpBand->rcBand.left, lpBand->rcBand.top,
742 lpBand->rcBand.right, lpBand->rcBand.bottom);
747 static void
748 REBAR_AdjustBands (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
749 INT maxx, INT mcy)
750 /* Function: This routine distributes the extra space in a row. */
751 /* See algorithm below. */
752 /* On entry: */
753 /* all bands @ ->cxHeader size */
754 /* start and end bands are *not* hidden */
756 REBAR_BAND *lpBand;
757 UINT x, xsep, extra, curwidth, fudge;
758 INT i, last_adjusted;
760 TRACE("start=%u, end=%u, max x=%d, max y=%d\n",
761 rowstart, rowend, maxx, mcy);
763 /* ******************* Phase 1 ************************ */
764 /* Alg: */
765 /* For each visible band with valid child */
766 /* a. inflate band till either all extra space used */
767 /* or band's ->ccx reached. */
768 /* If any band modified, add any space left to last band */
769 /* adjusted. */
770 /* */
771 /* ****************************************************** */
772 lpBand = &infoPtr->bands[rowend];
773 extra = maxx - rcBrb(lpBand);
774 x = 0;
775 last_adjusted = -1;
776 for (i=(INT)rowstart; i<=(INT)rowend; i++) {
777 lpBand = &infoPtr->bands[i];
778 if (HIDDENBAND(lpBand)) continue;
779 xsep = (x == 0) ? 0 : SEP_WIDTH;
780 curwidth = rcBw(lpBand);
782 /* set new left/top point */
783 if (infoPtr->dwStyle & CCS_VERT)
784 lpBand->rcBand.top = x + xsep;
785 else
786 lpBand->rcBand.left = x + xsep;
788 /* compute new width */
789 if ((lpBand->hwndChild && extra) && !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
790 /* set to the "current" band size less the header */
791 fudge = lpBand->ccx;
792 last_adjusted = i;
793 if ((lpBand->fMask & RBBIM_SIZE) && (lpBand->cx > 0) &&
794 (fudge > curwidth)) {
795 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d, extra=%d\n",
796 i, fudge-curwidth, fudge, curwidth, extra);
797 if ((fudge - curwidth) > extra)
798 fudge = curwidth + extra;
799 extra -= (fudge - curwidth);
800 curwidth = fudge;
802 else {
803 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d\n",
804 i, extra, fudge, curwidth);
805 curwidth += extra;
806 extra = 0;
810 /* set new right/bottom point */
811 if (infoPtr->dwStyle & CCS_VERT)
812 lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
813 else
814 lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
815 TRACE("Phase 1 band %d, (%ld,%ld)-(%ld,%ld), orig x=%d, xsep=%d\n",
816 i, lpBand->rcBand.left, lpBand->rcBand.top,
817 lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
818 x = rcBrb(lpBand);
820 if ((x >= maxx) || (last_adjusted != -1)) {
821 if (x > maxx) {
822 ERR("Phase 1 failed, x=%d, maxx=%d, start=%u, end=%u\n",
823 x, maxx, rowstart, rowend);
825 /* done, so spread extra space */
826 if (x < maxx) {
827 fudge = maxx - x;
828 TRACE("Need to spread %d on last adjusted band %d\n",
829 fudge, last_adjusted);
830 for (i=(INT)last_adjusted; i<=(INT)rowend; i++) {
831 lpBand = &infoPtr->bands[i];
832 if (HIDDENBAND(lpBand)) continue;
834 /* set right/bottom point */
835 if (i != last_adjusted) {
836 if (infoPtr->dwStyle & CCS_VERT)
837 lpBand->rcBand.top += fudge;
838 else
839 lpBand->rcBand.left += fudge;
842 /* set left/bottom point */
843 if (infoPtr->dwStyle & CCS_VERT)
844 lpBand->rcBand.bottom += fudge;
845 else
846 lpBand->rcBand.right += fudge;
849 TRACE("Phase 1 succeeded, used x=%d\n", x);
850 REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
851 return;
854 /* ******************* Phase 2 ************************ */
855 /* Alg: */
856 /* Find first visible band, put all */
857 /* extra space there. */
858 /* */
859 /* ****************************************************** */
861 x = 0;
862 for (i=(INT)rowstart; i<=(INT)rowend; i++) {
863 lpBand = &infoPtr->bands[i];
864 if (HIDDENBAND(lpBand)) continue;
865 xsep = (x == 0) ? 0 : SEP_WIDTH;
866 curwidth = rcBw(lpBand);
868 /* set new left/top point */
869 if (infoPtr->dwStyle & CCS_VERT)
870 lpBand->rcBand.top = x + xsep;
871 else
872 lpBand->rcBand.left = x + xsep;
874 /* compute new width */
875 if (extra) {
876 curwidth += extra;
877 extra = 0;
880 /* set new right/bottom point */
881 if (infoPtr->dwStyle & CCS_VERT)
882 lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
883 else
884 lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
885 TRACE("Phase 2 band %d, (%ld,%ld)-(%ld,%ld), orig x=%d, xsep=%d\n",
886 i, lpBand->rcBand.left, lpBand->rcBand.top,
887 lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
888 x = rcBrb(lpBand);
890 if (x >= maxx) {
891 if (x > maxx) {
892 ERR("Phase 2 failed, x=%d, maxx=%d, start=%u, end=%u\n",
893 x, maxx, rowstart, rowend);
895 /* done, so spread extra space */
896 TRACE("Phase 2 succeeded, used x=%d\n", x);
897 REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
898 return;
901 /* ******************* Phase 3 ************************ */
902 /* at this point everything is back to ->cxHeader values */
903 /* and should not have gotten here. */
904 /* ****************************************************** */
906 lpBand = &infoPtr->bands[rowstart];
907 ERR("Serious problem adjusting row %d, start band %d, end band %d\n",
908 lpBand->iRow, rowstart, rowend);
909 REBAR_DumpBand (infoPtr);
910 return;
914 static void
915 REBAR_CalcHorzBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
916 /* Function: this routine initializes all the rectangles in */
917 /* each band in a row to fit in the adjusted rcBand rect. */
918 /* *** Supports only Horizontal bars. *** */
920 REBAR_BAND *lpBand;
921 UINT i, xoff, yoff;
922 HWND parenthwnd;
923 RECT oldChild, work;
925 /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
926 parenthwnd = GetParent (infoPtr->hwndSelf);
928 for(i=rstart; i<rend; i++){
929 lpBand = &infoPtr->bands[i];
930 if (HIDDENBAND(lpBand)) {
931 SetRect (&lpBand->rcChild,
932 lpBand->rcBand.right, lpBand->rcBand.top,
933 lpBand->rcBand.right, lpBand->rcBand.bottom);
934 continue;
937 oldChild = lpBand->rcChild;
939 /* set initial gripper rectangle */
940 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
941 lpBand->rcBand.left, lpBand->rcBand.bottom);
943 /* calculate gripper rectangle */
944 if ( lpBand->fStatus & HAS_GRIPPER) {
945 lpBand->fDraw |= DRAW_GRIPPER;
946 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
947 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
948 lpBand->rcGripper.top += 2;
949 lpBand->rcGripper.bottom -= 2;
951 SetRect (&lpBand->rcCapImage,
952 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
953 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
955 else { /* no gripper will be drawn */
956 xoff = 0;
957 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
958 /* if no gripper but either image or text, then leave space */
959 xoff = REBAR_ALWAYS_SPACE;
960 SetRect (&lpBand->rcCapImage,
961 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
962 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
965 /* image is visible */
966 if (lpBand->fStatus & HAS_IMAGE) {
967 lpBand->fDraw |= DRAW_IMAGE;
968 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
969 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
971 /* set initial caption text rectangle */
972 SetRect (&lpBand->rcCapText,
973 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
974 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
975 /* update band height
976 if (lpBand->uMinHeight < infoPtr->imageSize.cy + 2) {
977 lpBand->uMinHeight = infoPtr->imageSize.cy + 2;
978 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->uMinHeight;
979 } */
981 else {
982 /* set initial caption text rectangle */
983 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
984 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
987 /* text is visible */
988 if (lpBand->fStatus & HAS_TEXT) {
989 lpBand->fDraw |= DRAW_TEXT;
990 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
991 lpBand->rcCapText.right-REBAR_POST_TEXT);
994 /* set initial child window rectangle if there is a child */
995 if (lpBand->fMask & RBBIM_CHILD) {
996 xoff = lpBand->offChild.cx;
997 yoff = lpBand->offChild.cy;
998 SetRect (&lpBand->rcChild,
999 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top+yoff,
1000 lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
1001 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
1003 lpBand->rcChild.right -= CHEVRON_WIDTH;
1004 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
1005 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
1006 lpBand->rcChild.bottom);
1009 else {
1010 SetRect (&lpBand->rcChild,
1011 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
1012 lpBand->rcBand.right, lpBand->rcBand.bottom);
1015 /* flag if notify required and invalidate rectangle */
1016 if (notify &&
1017 ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
1018 (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
1019 TRACE("Child rectangle changed for band %u\n", i);
1020 TRACE(" from (%ld,%ld)-(%ld,%ld) to (%ld,%ld)-(%ld,%ld)\n",
1021 oldChild.left, oldChild.top,
1022 oldChild.right, oldChild.bottom,
1023 lpBand->rcChild.left, lpBand->rcChild.top,
1024 lpBand->rcChild.right, lpBand->rcChild.bottom);
1026 if (lpBand->fDraw & NTF_INVALIDATE) {
1027 TRACE("invalidating (%ld,%ld)-(%ld,%ld)\n",
1028 lpBand->rcBand.left,
1029 lpBand->rcBand.top,
1030 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0),
1031 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0));
1032 lpBand->fDraw &= ~NTF_INVALIDATE;
1033 work = lpBand->rcBand;
1034 if (lpBand->fDraw & DRAW_RIGHTSEP) work.right += SEP_WIDTH_SIZE;
1035 if (lpBand->fDraw & DRAW_BOTTOMSEP) work.bottom += SEP_WIDTH_SIZE;
1036 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
1044 static VOID
1045 REBAR_CalcVertBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
1046 /* Function: this routine initializes all the rectangles in */
1047 /* each band in a row to fit in the adjusted rcBand rect. */
1048 /* *** Supports only Vertical bars. *** */
1050 REBAR_BAND *lpBand;
1051 UINT i, xoff, yoff;
1052 HWND parenthwnd;
1053 RECT oldChild, work;
1055 /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
1056 parenthwnd = GetParent (infoPtr->hwndSelf);
1058 for(i=rstart; i<rend; i++){
1059 lpBand = &infoPtr->bands[i];
1060 if (HIDDENBAND(lpBand)) continue;
1061 oldChild = lpBand->rcChild;
1063 /* set initial gripper rectangle */
1064 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
1065 lpBand->rcBand.right, lpBand->rcBand.top);
1067 /* calculate gripper rectangle */
1068 if (lpBand->fStatus & HAS_GRIPPER) {
1069 lpBand->fDraw |= DRAW_GRIPPER;
1071 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
1072 /* vertical gripper */
1073 lpBand->rcGripper.left += 3;
1074 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
1075 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
1076 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
1078 /* initialize Caption image rectangle */
1079 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1080 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1081 lpBand->rcBand.right,
1082 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1084 else {
1085 /* horizontal gripper */
1086 lpBand->rcGripper.left += 2;
1087 lpBand->rcGripper.right -= 2;
1088 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
1089 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
1091 /* initialize Caption image rectangle */
1092 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1093 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1094 lpBand->rcBand.right,
1095 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1098 else { /* no gripper will be drawn */
1099 xoff = 0;
1100 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
1101 /* if no gripper but either image or text, then leave space */
1102 xoff = REBAR_ALWAYS_SPACE;
1103 /* initialize Caption image rectangle */
1104 SetRect (&lpBand->rcCapImage,
1105 lpBand->rcBand.left, lpBand->rcBand.top+xoff,
1106 lpBand->rcBand.right, lpBand->rcBand.top+xoff);
1109 /* image is visible */
1110 if (lpBand->fStatus & HAS_IMAGE) {
1111 lpBand->fDraw |= DRAW_IMAGE;
1113 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
1114 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
1116 /* set initial caption text rectangle */
1117 SetRect (&lpBand->rcCapText,
1118 lpBand->rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
1119 lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1120 /* update band height *
1121 if (lpBand->uMinHeight < infoPtr->imageSize.cx + 2) {
1122 lpBand->uMinHeight = infoPtr->imageSize.cx + 2;
1123 lpBand->rcBand.right = lpBand->rcBand.left + lpBand->uMinHeight;
1124 } */
1126 else {
1127 /* set initial caption text rectangle */
1128 SetRect (&lpBand->rcCapText,
1129 lpBand->rcBand.left, lpBand->rcCapImage.bottom,
1130 lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1133 /* text is visible */
1134 if (lpBand->fStatus & HAS_TEXT) {
1135 lpBand->fDraw |= DRAW_TEXT;
1136 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
1137 lpBand->rcCapText.bottom);
1140 /* set initial child window rectangle if there is a child */
1141 if (lpBand->fMask & RBBIM_CHILD) {
1142 yoff = lpBand->offChild.cx;
1143 xoff = lpBand->offChild.cy;
1144 SetRect (&lpBand->rcChild,
1145 lpBand->rcBand.left+xoff, lpBand->rcBand.top+lpBand->cxHeader,
1146 lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
1148 else {
1149 SetRect (&lpBand->rcChild,
1150 lpBand->rcBand.left, lpBand->rcBand.top+lpBand->cxHeader,
1151 lpBand->rcBand.right, lpBand->rcBand.bottom);
1154 /* flag if notify required and invalidate rectangle */
1155 if (notify &&
1156 ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
1157 (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
1158 TRACE("Child rectangle changed for band %u\n", i);
1159 TRACE(" from (%ld,%ld)-(%ld,%ld) to (%ld,%ld)-(%ld,%ld)\n",
1160 oldChild.left, oldChild.top,
1161 oldChild.right, oldChild.bottom,
1162 lpBand->rcChild.left, lpBand->rcChild.top,
1163 lpBand->rcChild.right, lpBand->rcChild.bottom);
1165 if (lpBand->fDraw & NTF_INVALIDATE) {
1166 TRACE("invalidating (%ld,%ld)-(%ld,%ld)\n",
1167 lpBand->rcBand.left,
1168 lpBand->rcBand.top,
1169 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0),
1170 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0));
1171 lpBand->fDraw &= ~NTF_INVALIDATE;
1172 work = lpBand->rcBand;
1173 if (lpBand->fDraw & DRAW_RIGHTSEP) work.bottom += SEP_WIDTH_SIZE;
1174 if (lpBand->fDraw & DRAW_BOTTOMSEP) work.right += SEP_WIDTH_SIZE;
1175 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
1182 static VOID
1183 REBAR_ForceResize (REBAR_INFO *infoPtr)
1184 /* Function: This changes the size of the REBAR window to that */
1185 /* calculated by REBAR_Layout. */
1187 RECT rc;
1188 INT x, y, width, height;
1189 INT xedge = GetSystemMetrics(SM_CXEDGE);
1190 INT yedge = GetSystemMetrics(SM_CYEDGE);
1192 /* TEST TEST TEST */
1193 GetWindowRect (infoPtr->hwndSelf, &rc);
1194 /* END TEST END TEST END TEST */
1197 GetClientRect (infoPtr->hwndSelf, &rc);
1199 TRACE( " old [%ld x %ld], new [%ld x %ld], client [%ld x %ld]\n",
1200 infoPtr->oldSize.cx, infoPtr->oldSize.cy,
1201 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1202 rc.right, rc.bottom);
1204 /* If we need to shrink client, then skip size test */
1205 if ((infoPtr->calcSize.cy >= rc.bottom) &&
1206 (infoPtr->calcSize.cx >= rc.right)) {
1208 /* if size did not change then skip process */
1209 if ((infoPtr->oldSize.cx == infoPtr->calcSize.cx) &&
1210 (infoPtr->oldSize.cy == infoPtr->calcSize.cy) &&
1211 !(infoPtr->fStatus & RESIZE_ANYHOW))
1213 TRACE("skipping reset\n");
1214 return;
1218 infoPtr->fStatus &= ~RESIZE_ANYHOW;
1219 /* Set flag to ignore next WM_SIZE message */
1220 infoPtr->fStatus |= AUTO_RESIZE;
1222 width = 0;
1223 height = 0;
1224 x = 0;
1225 y = 0;
1227 if (infoPtr->dwStyle & WS_BORDER) {
1228 width = 2 * xedge;
1229 height = 2 * yedge;
1232 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
1233 INT mode = infoPtr->dwStyle & (CCS_VERT | CCS_TOP | CCS_BOTTOM);
1234 RECT rcPcl;
1236 GetClientRect(GetParent(infoPtr->hwndSelf), &rcPcl);
1237 switch (mode) {
1238 case CCS_TOP:
1239 /* _TOP sets width to parents width */
1240 width += (rcPcl.right - rcPcl.left);
1241 height += infoPtr->calcSize.cy;
1242 x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1243 y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1244 y += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1245 break;
1246 case CCS_BOTTOM:
1247 /* FIXME: wrong wrong wrong */
1248 /* _BOTTOM sets width to parents width */
1249 width += (rcPcl.right - rcPcl.left);
1250 height += infoPtr->calcSize.cy;
1251 x += -xedge;
1252 y = rcPcl.bottom - height + 1;
1253 break;
1254 case CCS_LEFT:
1255 /* _LEFT sets height to parents height */
1256 width += infoPtr->calcSize.cx;
1257 height += (rcPcl.bottom - rcPcl.top);
1258 x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1259 x += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1260 y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1261 break;
1262 case CCS_RIGHT:
1263 /* FIXME: wrong wrong wrong */
1264 /* _RIGHT sets height to parents height */
1265 width += infoPtr->calcSize.cx;
1266 height += (rcPcl.bottom - rcPcl.top);
1267 x = rcPcl.right - width + 1;
1268 y = -yedge;
1269 break;
1270 default:
1271 width += infoPtr->calcSize.cx;
1272 height += infoPtr->calcSize.cy;
1275 else {
1276 width += infoPtr->calcSize.cx;
1277 height += infoPtr->calcSize.cy;
1278 x = infoPtr->origin.x;
1279 y = infoPtr->origin.y;
1282 TRACE("hwnd %p, style=%08lx, setting at (%d,%d) for (%d,%d)\n",
1283 infoPtr->hwndSelf, infoPtr->dwStyle,
1284 x, y, width, height);
1285 SetWindowPos (infoPtr->hwndSelf, 0, x, y, width, height,
1286 SWP_NOZORDER);
1290 static VOID
1291 REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
1293 REBAR_BAND *lpBand;
1294 CHAR szClassName[40];
1295 UINT i;
1296 NMREBARCHILDSIZE rbcz;
1297 NMHDR heightchange;
1298 HDWP deferpos;
1300 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1301 ERR("BeginDeferWindowPos returned NULL\n");
1303 for (i = start; i < endplus; i++) {
1304 lpBand = &infoPtr->bands[i];
1306 if (HIDDENBAND(lpBand)) continue;
1307 if (lpBand->hwndChild) {
1308 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1310 /* Always geterate the RBN_CHILDSIZE even it child
1311 did not change */
1312 rbcz.uBand = i;
1313 rbcz.wID = lpBand->wID;
1314 rbcz.rcChild = lpBand->rcChild;
1315 rbcz.rcBand = lpBand->rcBand;
1316 if (infoPtr->dwStyle & CCS_VERT)
1317 rbcz.rcBand.top += lpBand->cxHeader;
1318 else
1319 rbcz.rcBand.left += lpBand->cxHeader;
1320 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1321 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1322 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1323 TRACE(" from (%ld,%ld)-(%ld,%ld) to (%ld,%ld)-(%ld,%ld)\n",
1324 lpBand->rcChild.left, lpBand->rcChild.top,
1325 lpBand->rcChild.right, lpBand->rcChild.bottom,
1326 rbcz.rcChild.left, rbcz.rcChild.top,
1327 rbcz.rcChild.right, rbcz.rcChild.bottom);
1328 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1331 /* native (IE4 in "Favorites" frame **1) does:
1332 * SetRect (&rc, -1, -1, -1, -1)
1333 * EqualRect (&rc,band->rc???)
1334 * if ret==0
1335 * CopyRect (band->rc????, &rc)
1336 * set flag outside of loop
1339 GetClassNameA (lpBand->hwndChild, szClassName, 40);
1340 if (!lstrcmpA (szClassName, "ComboBox") ||
1341 !lstrcmpA (szClassName, WC_COMBOBOXEXA)) {
1342 INT nEditHeight, yPos;
1343 RECT rc;
1345 /* special placement code for combo or comboex box */
1348 /* get size of edit line */
1349 GetWindowRect (lpBand->hwndChild, &rc);
1350 nEditHeight = rc.bottom - rc.top;
1351 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1353 /* center combo box inside child area */
1354 TRACE("moving child (Combo(Ex)) %p to (%ld,%d) for (%ld,%d)\n",
1355 lpBand->hwndChild,
1356 lpBand->rcChild.left, yPos,
1357 lpBand->rcChild.right - lpBand->rcChild.left,
1358 nEditHeight);
1359 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1360 lpBand->rcChild.left,
1361 /*lpBand->rcChild.top*/ yPos,
1362 lpBand->rcChild.right - lpBand->rcChild.left,
1363 nEditHeight,
1364 SWP_NOZORDER);
1365 if (!deferpos)
1366 ERR("DeferWindowPos returned NULL\n");
1368 else {
1369 TRACE("moving child (Other) %p to (%ld,%ld) for (%ld,%ld)\n",
1370 lpBand->hwndChild,
1371 lpBand->rcChild.left, lpBand->rcChild.top,
1372 lpBand->rcChild.right - lpBand->rcChild.left,
1373 lpBand->rcChild.bottom - lpBand->rcChild.top);
1374 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1375 lpBand->rcChild.left,
1376 lpBand->rcChild.top,
1377 lpBand->rcChild.right - lpBand->rcChild.left,
1378 lpBand->rcChild.bottom - lpBand->rcChild.top,
1379 SWP_NOZORDER);
1380 if (!deferpos)
1381 ERR("DeferWindowPos returned NULL\n");
1385 if (!EndDeferWindowPos(deferpos))
1386 ERR("EndDeferWindowPos returned NULL\n");
1388 if (infoPtr->DoRedraw)
1389 UpdateWindow (infoPtr->hwndSelf);
1391 if (infoPtr->fStatus & NTF_HGHTCHG) {
1392 infoPtr->fStatus &= ~NTF_HGHTCHG;
1393 REBAR_Notify (&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1396 /* native (from **1 above) does:
1397 * UpdateWindow(rebar)
1398 * REBAR_ForceResize
1399 * RBN_HEIGHTCHANGE if necessary
1400 * if ret from any EqualRect was 0
1401 * Goto "BeginDeferWindowPos"
1407 static VOID
1408 REBAR_Layout (REBAR_INFO *infoPtr, LPRECT lpRect, BOOL notify, BOOL resetclient)
1409 /* Function: This routine is resposible for laying out all */
1410 /* the bands in a rebar. It assigns each band to a row and*/
1411 /* determines when to start a new row. */
1413 REBAR_BAND *lpBand, *prevBand;
1414 RECT rcClient, rcAdj;
1415 INT initx, inity, x, y, cx, cxsep, mmcy, mcy, clientcx, clientcy;
1416 INT adjcx, adjcy, row, rightx, bottomy, origheight;
1417 UINT i, j, rowstart, origrows, cntonrow;
1418 BOOL dobreak;
1420 if (!(infoPtr->fStatus & BAND_NEEDS_LAYOUT)) {
1421 TRACE("no layout done. No band changed.\n");
1422 REBAR_DumpBand (infoPtr);
1423 return;
1425 infoPtr->fStatus &= ~BAND_NEEDS_LAYOUT;
1426 if (!infoPtr->DoRedraw) infoPtr->fStatus |= BAND_NEEDS_REDRAW;
1428 GetClientRect (infoPtr->hwndSelf, &rcClient);
1429 TRACE("Client is (%ld,%ld)-(%ld,%ld)\n",
1430 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
1432 if (lpRect) {
1433 rcAdj = *lpRect;
1434 TRACE("adjustment rect is (%ld,%ld)-(%ld,%ld)\n",
1435 rcAdj.left, rcAdj.top, rcAdj.right, rcAdj.bottom);
1437 else {
1438 CopyRect (&rcAdj, &rcClient);
1441 clientcx = rcClient.right - rcClient.left;
1442 clientcy = rcClient.bottom - rcClient.top;
1443 adjcx = rcAdj.right - rcAdj.left;
1444 adjcy = rcAdj.bottom - rcAdj.top;
1445 if (resetclient) {
1446 TRACE("window client rect will be set to adj rect\n");
1447 clientcx = adjcx;
1448 clientcy = adjcy;
1451 if (!infoPtr->DoRedraw && (clientcx == 0) && (clientcy == 0)) {
1452 ERR("no redraw and client is zero, skip layout\n");
1453 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1454 return;
1457 /* save height of original control */
1458 if (infoPtr->dwStyle & CCS_VERT)
1459 origheight = infoPtr->calcSize.cx;
1460 else
1461 origheight = infoPtr->calcSize.cy;
1462 origrows = infoPtr->uNumRows;
1464 initx = 0;
1465 inity = 0;
1467 /* ******* Start Phase 1 - all bands on row at minimum size ******* */
1469 TRACE("band loop constants, clientcx=%d, clientcy=%d, adjcx=%d, adjcy=%d\n",
1470 clientcx, clientcy, adjcx, adjcy);
1471 x = initx;
1472 y = inity;
1473 row = 1;
1474 cx = 0;
1475 mcy = 0;
1476 rowstart = 0;
1477 prevBand = NULL;
1478 cntonrow = 0;
1480 for (i = 0; i < infoPtr->uNumBands; i++) {
1481 lpBand = &infoPtr->bands[i];
1482 lpBand->fDraw = 0;
1483 lpBand->iRow = row;
1485 SetRectEmpty(&lpBand->rcChevron);
1487 if (HIDDENBAND(lpBand)) continue;
1489 lpBand->rcoldBand = lpBand->rcBand;
1491 /* Set the offset of the child window */
1492 if ((lpBand->fMask & RBBIM_CHILD) &&
1493 !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
1494 lpBand->offChild.cx = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 4 : 0);
1496 lpBand->offChild.cy = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 2 : 0);
1498 /* separator from previous band */
1499 cxsep = (cntonrow == 0) ? 0 : SEP_WIDTH;
1500 cx = lpBand->lcx;
1502 if (infoPtr->dwStyle & CCS_VERT)
1503 dobreak = (y + cx + cxsep > adjcy);
1504 else
1505 dobreak = (x + cx + cxsep > adjcx);
1507 /* This is the check for whether we need to start a new row */
1508 if ( ( (lpBand->fStyle & RBBS_BREAK) && (i != 0) ) ||
1509 ( ((infoPtr->dwStyle & CCS_VERT) ? (y != 0) : (x != 0)) && dobreak)) {
1511 for (j = rowstart; j < i; j++) {
1512 REBAR_BAND *lpB;
1513 lpB = &infoPtr->bands[j];
1514 if (infoPtr->dwStyle & CCS_VERT) {
1515 lpB->rcBand.right = lpB->rcBand.left + mcy;
1517 else {
1518 lpB->rcBand.bottom = lpB->rcBand.top + mcy;
1522 TRACE("P1 Spliting to new row %d on band %u\n", row+1, i);
1523 if (infoPtr->dwStyle & CCS_VERT) {
1524 y = inity;
1525 x += (mcy + SEP_WIDTH);
1527 else {
1528 x = initx;
1529 y += (mcy + SEP_WIDTH);
1532 mcy = 0;
1533 cxsep = 0;
1534 row++;
1535 lpBand->iRow = row;
1536 prevBand = NULL;
1537 rowstart = i;
1538 cntonrow = 0;
1541 if (mcy < lpBand->lcy + REBARSPACE(lpBand))
1542 mcy = lpBand->lcy + REBARSPACE(lpBand);
1544 /* if boundary rect specified then limit mcy */
1545 if (lpRect) {
1546 if (infoPtr->dwStyle & CCS_VERT) {
1547 if (x+mcy > adjcx) {
1548 mcy = adjcx - x;
1549 TRACE("P1 row %u limiting mcy=%d, adjcx=%d, x=%d\n",
1550 i, mcy, adjcx, x);
1553 else {
1554 if (y+mcy > adjcy) {
1555 mcy = adjcy - y;
1556 TRACE("P1 row %u limiting mcy=%d, adjcy=%d, y=%d\n",
1557 i, mcy, adjcy, y);
1562 TRACE("P1 band %u, row %d, x=%d, y=%d, cxsep=%d, cx=%d\n",
1563 i, row,
1564 x, y, cxsep, cx);
1565 if (infoPtr->dwStyle & CCS_VERT) {
1566 /* bound the bottom side if we have a bounding rectangle */
1567 rightx = clientcx;
1568 bottomy = (lpRect) ? min(clientcy, y+cxsep+cx) : y+cxsep+cx;
1569 lpBand->rcBand.left = x;
1570 lpBand->rcBand.right = x + min(mcy,
1571 lpBand->lcy+REBARSPACE(lpBand));
1572 lpBand->rcBand.top = min(bottomy, y + cxsep);
1573 lpBand->rcBand.bottom = bottomy;
1574 lpBand->uMinHeight = lpBand->lcy;
1575 y = bottomy;
1577 else {
1578 /* bound the right side if we have a bounding rectangle */
1579 rightx = (lpRect) ? min(clientcx, x+cxsep+cx) : x+cxsep+cx;
1580 bottomy = clientcy;
1581 lpBand->rcBand.left = min(rightx, x + cxsep);
1582 lpBand->rcBand.right = rightx;
1583 lpBand->rcBand.top = y;
1584 lpBand->rcBand.bottom = y + min(mcy,
1585 lpBand->lcy+REBARSPACE(lpBand));
1586 lpBand->uMinHeight = lpBand->lcy;
1587 x = rightx;
1589 TRACE("P1 band %u, row %d, (%ld,%ld)-(%ld,%ld)\n",
1590 i, row,
1591 lpBand->rcBand.left, lpBand->rcBand.top,
1592 lpBand->rcBand.right, lpBand->rcBand.bottom);
1593 prevBand = lpBand;
1594 cntonrow++;
1596 } /* for (i = 0; i < infoPtr->uNumBands... */
1598 if (infoPtr->dwStyle & CCS_VERT)
1599 x += mcy;
1600 else
1601 y += mcy;
1603 for (j = rowstart; j < infoPtr->uNumBands; j++) {
1604 lpBand = &infoPtr->bands[j];
1605 if (infoPtr->dwStyle & CCS_VERT) {
1606 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
1608 else {
1609 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
1613 if (infoPtr->uNumBands)
1614 infoPtr->uNumRows = row;
1616 /* ******* End Phase 1 - all bands on row at minimum size ******* */
1619 /* ******* Start Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1621 mmcy = 0;
1622 if (!(infoPtr->dwStyle & RBS_VARHEIGHT)) {
1623 INT xy;
1625 /* get the max height of all bands */
1626 for (i=0; i<infoPtr->uNumBands; i++) {
1627 lpBand = &infoPtr->bands[i];
1628 if (HIDDENBAND(lpBand)) continue;
1629 if (infoPtr->dwStyle & CCS_VERT)
1630 mmcy = max(mmcy, lpBand->rcBand.right - lpBand->rcBand.left);
1631 else
1632 mmcy = max(mmcy, lpBand->rcBand.bottom - lpBand->rcBand.top);
1635 /* now adjust all rectangles by using the height found above */
1636 xy = 0;
1637 row = 1;
1638 for (i=0; i<infoPtr->uNumBands; i++) {
1639 lpBand = &infoPtr->bands[i];
1640 if (HIDDENBAND(lpBand)) continue;
1641 if (lpBand->iRow != row)
1642 xy += (mmcy + SEP_WIDTH);
1643 if (infoPtr->dwStyle & CCS_VERT) {
1644 lpBand->rcBand.left = xy;
1645 lpBand->rcBand.right = xy + mmcy;
1647 else {
1648 lpBand->rcBand.top = xy;
1649 lpBand->rcBand.bottom = xy + mmcy;
1653 /* set the x/y values to the correct maximum */
1654 if (infoPtr->dwStyle & CCS_VERT)
1655 x = xy + mmcy;
1656 else
1657 y = xy + mmcy;
1660 /* ******* End Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1663 /* ******* Start Phase 2 - split rows till adjustment height full ******* */
1665 /* assumes that the following variables contain: */
1666 /* y/x current height/width of all rows */
1667 if (lpRect) {
1668 INT i, prev_rh, new_rh, adj_rh, prev_idx, current_idx;
1669 REBAR_BAND *prev, *current, *walk;
1670 UINT j;
1672 /* FIXME: problem # 2 */
1673 if (((infoPtr->dwStyle & CCS_VERT) ?
1674 #if PROBLEM2
1675 (x < adjcx) : (y < adjcy)
1676 #else
1677 (adjcx - x > 5) : (adjcy - y > 4)
1678 #endif
1679 ) &&
1680 (infoPtr->uNumBands > 1)) {
1681 for (i=(INT)infoPtr->uNumBands-2; i>=0; i--) {
1682 TRACE("P2 adjcx=%d, adjcy=%d, x=%d, y=%d\n",
1683 adjcx, adjcy, x, y);
1685 /* find the current band (starts at i+1) */
1686 current = &infoPtr->bands[i+1];
1687 current_idx = i+1;
1688 while (HIDDENBAND(current)) {
1689 i--;
1690 if (i < 0) break; /* out of bands */
1691 current = &infoPtr->bands[i+1];
1692 current_idx = i+1;
1694 if (i < 0) break; /* out of bands */
1696 /* now find the prev band (starts at i) */
1697 prev = &infoPtr->bands[i];
1698 prev_idx = i;
1699 while (HIDDENBAND(prev)) {
1700 i--;
1701 if (i < 0) break; /* out of bands */
1702 prev = &infoPtr->bands[i];
1703 prev_idx = i;
1705 if (i < 0) break; /* out of bands */
1707 prev_rh = ircBw(prev);
1708 if (prev->iRow == current->iRow) {
1709 new_rh = (infoPtr->dwStyle & RBS_VARHEIGHT) ?
1710 current->lcy + REBARSPACE(current) :
1711 mmcy;
1712 adj_rh = new_rh + SEP_WIDTH;
1713 infoPtr->uNumRows++;
1714 current->fDraw |= NTF_INVALIDATE;
1715 current->iRow++;
1716 if (infoPtr->dwStyle & CCS_VERT) {
1717 current->rcBand.top = inity;
1718 current->rcBand.bottom = clientcy;
1719 current->rcBand.left += (prev_rh + SEP_WIDTH);
1720 current->rcBand.right = current->rcBand.left + new_rh;
1721 x += adj_rh;
1723 else {
1724 current->rcBand.left = initx;
1725 current->rcBand.right = clientcx;
1726 current->rcBand.top += (prev_rh + SEP_WIDTH);
1727 current->rcBand.bottom = current->rcBand.top + new_rh;
1728 y += adj_rh;
1730 TRACE("P2 moving band %d to own row at (%ld,%ld)-(%ld,%ld)\n",
1731 current_idx,
1732 current->rcBand.left, current->rcBand.top,
1733 current->rcBand.right, current->rcBand.bottom);
1734 TRACE("P2 prev band %d at (%ld,%ld)-(%ld,%ld)\n",
1735 prev_idx,
1736 prev->rcBand.left, prev->rcBand.top,
1737 prev->rcBand.right, prev->rcBand.bottom);
1738 TRACE("P2 values: prev_rh=%d, new_rh=%d, adj_rh=%d\n",
1739 prev_rh, new_rh, adj_rh);
1740 /* for bands below current adjust row # and top/bottom */
1741 for (j = current_idx+1; j<infoPtr->uNumBands; j++) {
1742 walk = &infoPtr->bands[j];
1743 if (HIDDENBAND(walk)) continue;
1744 walk->fDraw |= NTF_INVALIDATE;
1745 walk->iRow++;
1746 if (infoPtr->dwStyle & CCS_VERT) {
1747 walk->rcBand.left += adj_rh;
1748 walk->rcBand.right += adj_rh;
1750 else {
1751 walk->rcBand.top += adj_rh;
1752 walk->rcBand.bottom += adj_rh;
1755 if ((infoPtr->dwStyle & CCS_VERT) ? (x >= adjcx) : (y >= adjcy))
1756 break; /* all done */
1762 /* ******* End Phase 2 - split rows till adjustment height full ******* */
1765 /* ******* Start Phase 2a - create array of start and end ******* */
1766 /* indexes by row */
1768 if (infoPtr->uNumRows != origrows) {
1769 if (infoPtr->rows) Free (infoPtr->rows);
1770 infoPtr->rows = Alloc (sizeof (REBAR_ROW) * infoPtr->uNumRows);
1773 row = 0;
1774 for (i = 0; i < infoPtr->uNumBands; i++) {
1775 lpBand = &infoPtr->bands[i];
1776 if (HIDDENBAND(lpBand)) continue;
1778 if (lpBand->iRow > row) {
1779 row++;
1780 infoPtr->rows[row-1].istartband = i;
1782 if (row == 0) {
1783 ERR("P2a bug!!!!!!\n");
1785 infoPtr->rows[row-1].iendband = i;
1788 for (i = 0; i < infoPtr->uNumRows; i++) {
1789 REBAR_ROW *p;
1791 p = &infoPtr->rows[i];
1792 TRACE("P2a row %d, starts %d, ends %d\n",
1793 i+1, p->istartband, p->iendband);
1796 /* ******* End Phase 2a - create array of start and end ******* */
1797 /* indexes by row */
1800 /* ******* Start Phase 2b - adjust all bands for height full ******* */
1801 /* assumes that the following variables contain: */
1802 /* y/x current height/width of all rows */
1803 /* clientcy/clientcx height/width of client area */
1805 if (((infoPtr->dwStyle & CCS_VERT) ? clientcx > x : clientcy > y) &&
1806 infoPtr->uNumBands) {
1807 INT diff, i, iband;
1808 UINT j;
1810 diff = (infoPtr->dwStyle & CCS_VERT) ? clientcx - x : clientcy - y;
1811 for (i = infoPtr->uNumRows; i >= 1; i--) {
1812 /* if row has more than 1 band, ignore row */
1813 if (infoPtr->rows[i-1].istartband != infoPtr->rows[i-1].iendband)
1814 continue;
1815 /* point to only band in row */
1816 iband = infoPtr->rows[i-1].istartband;
1817 lpBand = &infoPtr->bands[iband];
1818 if(HIDDENBAND(lpBand)) continue;
1819 if (lpBand->fMask & RBBS_VARIABLEHEIGHT) continue;
1820 if (((INT)lpBand->cyMaxChild < 1) ||
1821 ((INT)lpBand->cyIntegral < 1)) {
1822 if (lpBand->cyMaxChild + lpBand->cyIntegral == 0) continue;
1823 ERR("P2b band %u RBBS_VARIABLEHEIGHT set but cyMax=%d, cyInt=%d\n",
1824 iband, lpBand->cyMaxChild, lpBand->cyIntegral);
1825 continue;
1827 /* j is now the maximum height/width in the client area */
1828 j = ((diff / lpBand->cyIntegral) * lpBand->cyIntegral) +
1829 ircBw(lpBand);
1830 if (j > lpBand->cyMaxChild + REBARSPACE(lpBand))
1831 j = lpBand->cyMaxChild + REBARSPACE(lpBand);
1832 diff -= (j - ircBw(lpBand));
1833 if (infoPtr->dwStyle & CCS_VERT)
1834 lpBand->rcBand.right = lpBand->rcBand.left + j;
1835 else
1836 lpBand->rcBand.bottom = lpBand->rcBand.top + j;
1837 TRACE("P2b band %d, row %d changed to (%ld,%ld)-(%ld,%ld)\n",
1838 iband, lpBand->iRow,
1839 lpBand->rcBand.left, lpBand->rcBand.top,
1840 lpBand->rcBand.right, lpBand->rcBand.bottom);
1841 if (diff <= 0) break;
1843 if (diff < 0) {
1844 ERR("P2b allocated more than available, diff=%d\n", diff);
1845 diff = 0;
1847 if (infoPtr->dwStyle & CCS_VERT)
1848 x = clientcx - diff;
1849 else
1850 y = clientcy - diff;
1853 /* ******* End Phase 2b - adjust all bands for height full ******* */
1856 /* ******* Start Phase 3 - adjust all bands for width full ******* */
1858 if (infoPtr->uNumBands) {
1859 REBAR_ROW *p;
1861 /* If RBS_BANDBORDERS set then indicate to draw bottom separator */
1862 /* on all bands in all rows but last row. */
1863 /* Also indicate to draw the right separator for each band in */
1864 /* each row but the rightmost band. */
1865 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1867 for(i = 0; i < infoPtr->uNumRows; i++) {
1868 p = &infoPtr->rows[i];
1869 for (j = p->istartband; j <= p->iendband; j++) {
1870 lpBand = &infoPtr->bands[j];
1871 if (HIDDENBAND(lpBand)) continue;
1872 if (j != p->iendband)
1873 lpBand->fDraw |= DRAW_RIGHTSEP;
1874 if (i != infoPtr->uNumRows-1)
1875 lpBand->fDraw |= DRAW_BOTTOMSEP;
1880 /* Distribute the extra space on the horizontal and adjust */
1881 /* all bands in row to same height. */
1882 for (i=1; i<=infoPtr->uNumRows; i++) {
1883 p = &infoPtr->rows[i-1];
1884 mcy = 0;
1886 TRACE("P3 processing row %d, starting band %d, ending band %d\n",
1887 i, p->istartband, p->iendband);
1889 /* Find the largest height of the bands in the row */
1890 for (j = p->istartband; j <= p->iendband; j++) {
1891 lpBand = &infoPtr->bands[j];
1892 if (HIDDENBAND(lpBand)) continue;
1893 if (mcy < ircBw(lpBand))
1894 mcy = ircBw(lpBand);
1897 REBAR_AdjustBands (infoPtr, p->istartband, p->iendband,
1898 (infoPtr->dwStyle & CCS_VERT) ?
1899 clientcy : clientcx, mcy);
1902 /* Calculate the other rectangles in each band */
1903 if (infoPtr->dwStyle & CCS_VERT) {
1904 REBAR_CalcVertBand (infoPtr, 0, infoPtr->uNumBands,
1905 notify);
1907 else {
1908 REBAR_CalcHorzBand (infoPtr, 0, infoPtr->uNumBands,
1909 notify);
1913 /* ******* End Phase 3 - adjust all bands for width full ******* */
1915 /* now compute size of Rebar itself */
1916 infoPtr->oldSize = infoPtr->calcSize;
1917 if (infoPtr->uNumBands == 0) {
1918 /* we have no bands, so make size the size of client */
1919 x = clientcx;
1920 y = clientcy;
1922 if (infoPtr->dwStyle & CCS_VERT) {
1923 infoPtr->calcSize.cx = x;
1924 infoPtr->calcSize.cy = clientcy;
1925 TRACE("vert, notify=%d, x=%d, origheight=%d\n",
1926 notify, x, origheight);
1927 if (notify && (x != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1929 else {
1930 infoPtr->calcSize.cx = clientcx;
1931 infoPtr->calcSize.cy = y;
1932 TRACE("horz, notify=%d, y=%d, origheight=%d\n",
1933 notify, y, origheight);
1934 if (notify && (y != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1937 REBAR_DumpBand (infoPtr);
1939 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1941 REBAR_ForceResize (infoPtr);
1945 static VOID
1946 REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1947 /* Function: This routine evaluates the band specs supplied */
1948 /* by the user and updates the following 5 fields in */
1949 /* the internal band structure: cxHeader, lcx, lcy, hcx, hcy*/
1951 UINT header=0;
1952 UINT textheight=0;
1953 UINT i, nonfixed;
1954 REBAR_BAND *tBand;
1956 lpBand->fStatus = 0;
1957 lpBand->lcx = 0;
1958 lpBand->lcy = 0;
1959 lpBand->ccx = 0;
1960 lpBand->ccy = 0;
1961 lpBand->hcx = 0;
1962 lpBand->hcy = 0;
1964 /* Data comming in from users into the cx... and cy... fields */
1965 /* may be bad, just garbage, because the user never clears */
1966 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1967 /* along if the fields exist in the input area. Here we must */
1968 /* determine if the data is valid. I have no idea how MS does */
1969 /* the validation, but it does because the RB_GETBANDINFO */
1970 /* returns a 0 when I know the sample program passed in an */
1971 /* address. Here I will use the algorithim that if the value */
1972 /* is greater than 65535 then it is bad and replace it with */
1973 /* a zero. Feel free to improve the algorithim. - GA 12/2000 */
1974 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1975 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1976 if (lpBand->cx > 65535) lpBand->cx = 0;
1977 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1978 if (lpBand->cyMaxChild > 65535) lpBand->cyMaxChild = 0;
1979 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1980 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1981 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1983 /* FIXME: probably should only set NEEDS_LAYOUT flag when */
1984 /* values change. Till then always set it. */
1985 TRACE("setting NEEDS_LAYOUT\n");
1986 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1988 /* Header is where the image, text and gripper exist */
1989 /* in the band and preceed the child window. */
1991 /* count number of non-FIXEDSIZE and non-Hidden bands */
1992 nonfixed = 0;
1993 for (i=0; i<infoPtr->uNumBands; i++){
1994 tBand = &infoPtr->bands[i];
1995 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1996 nonfixed++;
1999 /* calculate gripper rectangle */
2000 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
2001 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
2002 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
2004 lpBand->fStatus |= HAS_GRIPPER;
2005 if (infoPtr->dwStyle & CCS_VERT)
2006 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
2007 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
2008 else
2009 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
2010 else
2011 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
2012 /* Always have 4 pixels before anything else */
2013 header += REBAR_ALWAYS_SPACE;
2016 /* image is visible */
2017 if ((lpBand->fMask & RBBIM_IMAGE) && (infoPtr->himl)) {
2018 lpBand->fStatus |= HAS_IMAGE;
2019 if (infoPtr->dwStyle & CCS_VERT) {
2020 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
2021 lpBand->lcy = infoPtr->imageSize.cx + 2;
2023 else {
2024 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
2025 lpBand->lcy = infoPtr->imageSize.cy + 2;
2029 /* text is visible */
2030 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText)) {
2031 HDC hdc = GetDC (0);
2032 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
2033 SIZE size;
2035 lpBand->fStatus |= HAS_TEXT;
2036 GetTextExtentPoint32W (hdc, lpBand->lpText,
2037 lstrlenW (lpBand->lpText), &size);
2038 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
2039 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
2041 SelectObject (hdc, hOldFont);
2042 ReleaseDC (0, hdc);
2045 /* if no gripper but either image or text, then leave space */
2046 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
2047 !(lpBand->fStatus & HAS_GRIPPER)) {
2048 header += REBAR_ALWAYS_SPACE;
2051 /* check if user overrode the header value */
2052 if (!(lpBand->fMask & RBBIM_HEADERSIZE))
2053 lpBand->cxHeader = header;
2056 /* Now compute minimum size of child window */
2057 lpBand->offChild.cx = 0;
2058 lpBand->offChild.cy = 0;
2059 lpBand->lcy = textheight;
2060 lpBand->ccy = lpBand->lcy;
2061 if (lpBand->fMask & RBBIM_CHILDSIZE) {
2062 lpBand->lcx = lpBand->cxMinChild;
2064 /* Set the .cy values for CHILDSIZE case */
2065 lpBand->lcy = max(lpBand->lcy, lpBand->cyMinChild);
2066 lpBand->ccy = lpBand->lcy;
2067 lpBand->hcy = lpBand->lcy;
2068 if (lpBand->cyMaxChild != 0xffffffff) {
2069 lpBand->hcy = lpBand->cyMaxChild;
2071 if (lpBand->cyChild != 0xffffffff)
2072 lpBand->ccy = max (lpBand->cyChild, lpBand->lcy);
2074 TRACE("_CHILDSIZE\n");
2076 if (lpBand->fMask & RBBIM_SIZE) {
2077 lpBand->hcx = max (lpBand->cx-lpBand->cxHeader, lpBand->lcx);
2078 TRACE("_SIZE\n");
2080 else
2081 lpBand->hcx = lpBand->lcx;
2082 lpBand->ccx = lpBand->hcx;
2084 /* make ->.cx include header size for _Layout */
2085 lpBand->lcx += lpBand->cxHeader;
2086 lpBand->ccx += lpBand->cxHeader;
2087 lpBand->hcx += lpBand->cxHeader;
2091 static BOOL
2092 REBAR_CommonSetupBand (HWND hwnd, LPREBARBANDINFOA lprbbi, REBAR_BAND *lpBand)
2093 /* Function: This routine copies the supplied values from */
2094 /* user input (lprbbi) to the internal band structure. */
2095 /* It returns true if something changed and false if not. */
2097 BOOL bChanged = FALSE;
2099 lpBand->fMask |= lprbbi->fMask;
2101 if( (lprbbi->fMask & RBBIM_STYLE) &&
2102 (lpBand->fStyle != lprbbi->fStyle ) )
2104 lpBand->fStyle = lprbbi->fStyle;
2105 bChanged = TRUE;
2108 if( (lprbbi->fMask & RBBIM_COLORS) &&
2109 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
2110 ( lpBand->clrBack != lprbbi->clrBack ) ) )
2112 lpBand->clrFore = lprbbi->clrFore;
2113 lpBand->clrBack = lprbbi->clrBack;
2114 bChanged = TRUE;
2117 if( (lprbbi->fMask & RBBIM_IMAGE) &&
2118 ( lpBand->iImage != lprbbi->iImage ) )
2120 lpBand->iImage = lprbbi->iImage;
2121 bChanged = TRUE;
2124 if( (lprbbi->fMask & RBBIM_CHILD) &&
2125 (lprbbi->hwndChild != lpBand->hwndChild ) )
2127 if (lprbbi->hwndChild) {
2128 lpBand->hwndChild = lprbbi->hwndChild;
2129 lpBand->hwndPrevParent =
2130 SetParent (lpBand->hwndChild, hwnd);
2131 /* below in trace fro WinRAR */
2132 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
2133 /* above in trace fro WinRAR */
2135 else {
2136 TRACE("child: %p prev parent: %p\n",
2137 lpBand->hwndChild, lpBand->hwndPrevParent);
2138 lpBand->hwndChild = 0;
2139 lpBand->hwndPrevParent = 0;
2141 bChanged = TRUE;
2144 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
2145 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
2146 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
2147 ( (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) &&
2148 ( (lpBand->cyChild != lprbbi->cyChild ) ||
2149 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
2150 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
2151 ( (lprbbi->cbSize < sizeof (REBARBANDINFOA)) &&
2152 ( (lpBand->cyChild ||
2153 lpBand->cyMaxChild ||
2154 lpBand->cyIntegral ) ) ) ) )
2156 lpBand->cxMinChild = lprbbi->cxMinChild;
2157 lpBand->cyMinChild = lprbbi->cyMinChild;
2158 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2159 lpBand->cyChild = lprbbi->cyChild;
2160 lpBand->cyMaxChild = lprbbi->cyMaxChild;
2161 lpBand->cyIntegral = lprbbi->cyIntegral;
2163 else { /* special case - these should be zeroed out since */
2164 /* RBBIM_CHILDSIZE added these in WIN32_IE >= 0x0400 */
2165 lpBand->cyChild = 0;
2166 lpBand->cyMaxChild = 0;
2167 lpBand->cyIntegral = 0;
2169 bChanged = TRUE;
2172 if( (lprbbi->fMask & RBBIM_SIZE) &&
2173 (lpBand->cx != lprbbi->cx ) )
2175 lpBand->cx = lprbbi->cx;
2176 bChanged = TRUE;
2179 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
2180 ( lpBand->hbmBack != lprbbi->hbmBack ) )
2182 lpBand->hbmBack = lprbbi->hbmBack;
2183 bChanged = TRUE;
2186 if( (lprbbi->fMask & RBBIM_ID) &&
2187 (lpBand->wID != lprbbi->wID ) )
2189 lpBand->wID = lprbbi->wID;
2190 bChanged = TRUE;
2193 /* check for additional data */
2194 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2195 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
2196 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
2198 lpBand->cxIdeal = lprbbi->cxIdeal;
2199 bChanged = TRUE;
2202 if( (lprbbi->fMask & RBBIM_LPARAM) &&
2203 (lpBand->lParam != lprbbi->lParam ) )
2205 lpBand->lParam = lprbbi->lParam;
2206 bChanged = TRUE;
2209 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
2210 (lpBand->cxHeader != lprbbi->cxHeader ) )
2212 lpBand->cxHeader = lprbbi->cxHeader;
2213 bChanged = TRUE;
2217 return bChanged;
2220 static LRESULT
2221 REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, RECT *clip)
2222 /* Function: This erases the background rectangle by drawing */
2223 /* each band with its background color (or the default) and */
2224 /* draws each bands right separator if necessary. The row */
2225 /* separators are drawn on the first band of the next row. */
2227 REBAR_BAND *lpBand;
2228 UINT i;
2229 INT oldrow;
2230 HDC hdc = (HDC)wParam;
2231 RECT rect;
2232 COLORREF old = CLR_NONE, new;
2234 oldrow = -1;
2235 for(i=0; i<infoPtr->uNumBands; i++) {
2236 lpBand = &infoPtr->bands[i];
2237 if (HIDDENBAND(lpBand)) continue;
2239 /* draw band separator between rows */
2240 if (lpBand->iRow != oldrow) {
2241 oldrow = lpBand->iRow;
2242 if (lpBand->fDraw & DRAW_BOTTOMSEP) {
2243 RECT rcRowSep;
2244 rcRowSep = lpBand->rcBand;
2245 if (infoPtr->dwStyle & CCS_VERT) {
2246 rcRowSep.right += SEP_WIDTH_SIZE;
2247 rcRowSep.bottom = infoPtr->calcSize.cy;
2248 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
2250 else {
2251 rcRowSep.bottom += SEP_WIDTH_SIZE;
2252 rcRowSep.right = infoPtr->calcSize.cx;
2253 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
2255 TRACE ("drawing band separator bottom (%ld,%ld)-(%ld,%ld)\n",
2256 rcRowSep.left, rcRowSep.top,
2257 rcRowSep.right, rcRowSep.bottom);
2261 /* draw band separator between bands in a row */
2262 if (lpBand->fDraw & DRAW_RIGHTSEP) {
2263 RECT rcSep;
2264 rcSep = lpBand->rcBand;
2265 if (infoPtr->dwStyle & CCS_VERT) {
2266 rcSep.bottom += SEP_WIDTH_SIZE;
2267 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
2269 else {
2270 rcSep.right += SEP_WIDTH_SIZE;
2271 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
2273 TRACE("drawing band separator right (%ld,%ld)-(%ld,%ld)\n",
2274 rcSep.left, rcSep.top, rcSep.right, rcSep.bottom);
2277 /* draw the actual background */
2278 if (lpBand->clrBack != CLR_NONE) {
2279 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
2280 lpBand->clrBack;
2281 #if GLATESTING
2282 /* testing only - make background green to see it */
2283 new = RGB(0,128,0);
2284 #endif
2286 else {
2287 /* In the absence of documentation for Rebar vs. CLR_NONE,
2288 * we will use the default BtnFace color. Note documentation
2289 * exists for Listview and Imagelist.
2291 new = infoPtr->clrBtnFace;
2292 #if GLATESTING
2293 /* testing only - make background green to see it */
2294 new = RGB(0,128,0);
2295 #endif
2297 old = SetBkColor (hdc, new);
2299 rect = lpBand->rcBand;
2300 TRACE("%s background color=0x%06lx, band (%ld,%ld)-(%ld,%ld), clip (%ld,%ld)-(%ld,%ld)\n",
2301 (lpBand->clrBack == CLR_NONE) ? "none" :
2302 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
2303 GetBkColor(hdc),
2304 lpBand->rcBand.left,lpBand->rcBand.top,
2305 lpBand->rcBand.right,lpBand->rcBand.bottom,
2306 clip->left, clip->top,
2307 clip->right, clip->bottom);
2308 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, 0);
2309 if (lpBand->clrBack != CLR_NONE)
2310 SetBkColor (hdc, old);
2312 return TRUE;
2315 static void
2316 REBAR_InternalHitTest (REBAR_INFO *infoPtr, const LPPOINT lpPt, UINT *pFlags, INT *pBand)
2318 REBAR_BAND *lpBand;
2319 RECT rect;
2320 UINT iCount;
2322 GetClientRect (infoPtr->hwndSelf, &rect);
2324 *pFlags = RBHT_NOWHERE;
2325 if (PtInRect (&rect, *lpPt))
2327 if (infoPtr->uNumBands == 0) {
2328 *pFlags = RBHT_NOWHERE;
2329 if (pBand)
2330 *pBand = -1;
2331 TRACE("NOWHERE\n");
2332 return;
2334 else {
2335 /* somewhere inside */
2336 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
2337 lpBand = &infoPtr->bands[iCount];
2338 if (HIDDENBAND(lpBand)) continue;
2339 if (PtInRect (&lpBand->rcBand, *lpPt)) {
2340 if (pBand)
2341 *pBand = iCount;
2342 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
2343 *pFlags = RBHT_GRABBER;
2344 TRACE("ON GRABBER %d\n", iCount);
2345 return;
2347 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
2348 *pFlags = RBHT_CAPTION;
2349 TRACE("ON CAPTION %d\n", iCount);
2350 return;
2352 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2353 *pFlags = RBHT_CAPTION;
2354 TRACE("ON CAPTION %d\n", iCount);
2355 return;
2357 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2358 *pFlags = RBHT_CLIENT;
2359 TRACE("ON CLIENT %d\n", iCount);
2360 return;
2362 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
2363 *pFlags = RBHT_CHEVRON;
2364 TRACE("ON CHEVRON %d\n", iCount);
2365 return;
2367 else {
2368 *pFlags = RBHT_NOWHERE;
2369 TRACE("NOWHERE %d\n", iCount);
2370 return;
2375 *pFlags = RBHT_NOWHERE;
2376 if (pBand)
2377 *pBand = -1;
2379 TRACE("NOWHERE\n");
2380 return;
2383 else {
2384 *pFlags = RBHT_NOWHERE;
2385 if (pBand)
2386 *pBand = -1;
2387 TRACE("NOWHERE\n");
2388 return;
2393 static INT
2394 REBAR_Shrink (REBAR_INFO *infoPtr, REBAR_BAND *band, INT movement, INT i)
2395 /* Function: This attempts to shrink the given band by the */
2396 /* the amount in "movement". A shrink to the left is indi- */
2397 /* cated by "movement" being negative. "i" is merely the */
2398 /* band index for trace messages. */
2400 INT Leadjust, Readjust, avail, ret;
2402 /* Note: a left drag is indicated by "movement" being negative. */
2403 /* Similarly, a right drag is indicated by "movement" */
2404 /* being positive. "movement" should never be 0, but if */
2405 /* it is then the band does not move. */
2407 avail = rcBw(band) - band->lcx;
2409 /* now compute the Left End adjustment factor and Right End */
2410 /* adjustment factor. They may be different if shrinking. */
2411 if (avail <= 0) {
2412 /* if this band is not shrinkable, then just move it */
2413 Leadjust = Readjust = movement;
2414 ret = movement;
2416 else {
2417 if (movement < 0) {
2418 /* Drag to left */
2419 if (avail <= abs(movement)) {
2420 Readjust = movement;
2421 Leadjust = movement + avail;
2422 ret = Leadjust;
2424 else {
2425 Readjust = movement;
2426 Leadjust = 0;
2427 ret = 0;
2430 else {
2431 /* Drag to right */
2432 if (avail <= abs(movement)) {
2433 Leadjust = movement;
2434 Readjust = movement - avail;
2435 ret = Readjust;
2437 else {
2438 Leadjust = movement;
2439 Readjust = 0;
2440 ret = 0;
2445 /* Reasonability Check */
2446 if (rcBlt(band) + Leadjust < 0) {
2447 ERR("adjustment will fail, band %d: left=%d, right=%d, move=%d, rtn=%d\n",
2448 i, Leadjust, Readjust, movement, ret);
2451 LEADJ(band, Leadjust);
2452 READJ(band, Readjust);
2454 TRACE("band %d: left=%d, right=%d, move=%d, rtn=%d, rcBand=(%ld,%ld)-(%ld,%ld)\n",
2455 i, Leadjust, Readjust, movement, ret,
2456 band->rcBand.left, band->rcBand.top,
2457 band->rcBand.right, band->rcBand.bottom);
2458 return ret;
2462 static void
2463 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, POINTS *ptsmove)
2464 /* Function: This will implement the functionality of a */
2465 /* Gripper drag within a row. It will not implement "out- */
2466 /* of-row" drags. (They are detected and handled in */
2467 /* REBAR_MouseMove.) */
2468 /* **** FIXME Switching order of bands in a row not **** */
2469 /* **** yet implemented. **** */
2471 REBAR_BAND *hitBand, *band, *mindBand, *maxdBand;
2472 RECT newrect;
2473 INT imindBand = -1, imaxdBand, ihitBand, i, movement;
2474 INT RHeaderSum = 0, LHeaderSum = 0;
2475 INT compress;
2477 /* on first significant mouse movement, issue notify */
2479 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
2480 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
2481 /* Notify returned TRUE - abort drag */
2482 infoPtr->dragStart.x = 0;
2483 infoPtr->dragStart.y = 0;
2484 infoPtr->dragNow = infoPtr->dragStart;
2485 infoPtr->iGrabbedBand = -1;
2486 ReleaseCapture ();
2487 return ;
2489 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
2492 ihitBand = infoPtr->iGrabbedBand;
2493 hitBand = &infoPtr->bands[ihitBand];
2494 imaxdBand = ihitBand; /* to suppress warning message */
2496 /* find all the bands in the row of the one whose Gripper was seized */
2497 for (i=0; i<infoPtr->uNumBands; i++) {
2498 band = &infoPtr->bands[i];
2499 if (HIDDENBAND(band)) continue;
2500 if (band->iRow == hitBand->iRow) {
2501 imaxdBand = i;
2502 if (imindBand == -1) imindBand = i;
2503 /* minimum size of each band is size of header plus */
2504 /* size of minimum child plus offset of child from header plus */
2505 /* a one to separate each band. */
2506 if (i < ihitBand)
2507 LHeaderSum += (band->lcx + SEP_WIDTH);
2508 else
2509 RHeaderSum += (band->lcx + SEP_WIDTH);
2513 if (RHeaderSum) RHeaderSum -= SEP_WIDTH; /* no separator afterlast band */
2515 mindBand = &infoPtr->bands[imindBand];
2516 maxdBand = &infoPtr->bands[imaxdBand];
2518 if (imindBand == imaxdBand) return; /* nothing to drag agains */
2519 if (imindBand == ihitBand) return; /* first band in row, cant drag */
2521 /* limit movement to inside adjustable bands - Left */
2522 if ( (ptsmove->x < mindBand->rcBand.left) ||
2523 (ptsmove->x > maxdBand->rcBand.right) ||
2524 (ptsmove->y < mindBand->rcBand.top) ||
2525 (ptsmove->y > maxdBand->rcBand.bottom))
2526 return; /* should swap bands */
2528 if (infoPtr->dwStyle & CCS_VERT)
2529 movement = ptsmove->y - ((hitBand->rcBand.top+REBAR_PRE_GRIPPER) -
2530 infoPtr->ihitoffset);
2531 else
2532 movement = ptsmove->x - ((hitBand->rcBand.left+REBAR_PRE_GRIPPER) -
2533 infoPtr->ihitoffset);
2534 infoPtr->dragNow = *ptsmove;
2536 TRACE("before: movement=%d (%d,%d), imindBand=%d, ihitBand=%d, imaxdBand=%d, LSum=%d, RSum=%d\n",
2537 movement, ptsmove->x, ptsmove->y, imindBand, ihitBand,
2538 imaxdBand, LHeaderSum, RHeaderSum);
2539 REBAR_DumpBand (infoPtr);
2541 if (movement < 0) {
2543 /* *** Drag left/up *** */
2544 compress = rcBlt(hitBand) - rcBlt(mindBand) -
2545 LHeaderSum;
2546 if (compress < abs(movement)) {
2547 TRACE("limiting left drag, was %d changed to %d\n",
2548 movement, -compress);
2549 movement = -compress;
2552 for (i=ihitBand; i>=imindBand; i--) {
2553 band = &infoPtr->bands[i];
2554 if (HIDDENBAND(band)) continue;
2555 if (i == ihitBand) {
2556 LEADJ(band, movement);
2558 else
2559 movement = REBAR_Shrink (infoPtr, band, movement, i);
2560 band->ccx = rcBw(band);
2563 else {
2564 BOOL first = TRUE;
2566 /* *** Drag right/down *** */
2567 compress = rcBrb(maxdBand) - rcBlt(hitBand) -
2568 RHeaderSum;
2569 if (compress < abs(movement)) {
2570 TRACE("limiting right drag, was %d changed to %d\n",
2571 movement, compress);
2572 movement = compress;
2574 for (i=ihitBand-1; i<=imaxdBand; i++) {
2575 band = &infoPtr->bands[i];
2576 if (HIDDENBAND(band)) continue;
2577 if (first) {
2578 first = FALSE;
2579 READJ(band, movement);
2581 else
2582 movement = REBAR_Shrink (infoPtr, band, movement, i);
2583 band->ccx = rcBw(band);
2587 /* recompute all rectangles */
2588 if (infoPtr->dwStyle & CCS_VERT) {
2589 REBAR_CalcVertBand (infoPtr, imindBand, imaxdBand+1,
2590 FALSE);
2592 else {
2593 REBAR_CalcHorzBand (infoPtr, imindBand, imaxdBand+1,
2594 FALSE);
2597 TRACE("bands after adjustment, see band # %d, %d\n",
2598 imindBand, imaxdBand);
2599 REBAR_DumpBand (infoPtr);
2601 SetRect (&newrect,
2602 mindBand->rcBand.left,
2603 mindBand->rcBand.top,
2604 maxdBand->rcBand.right,
2605 maxdBand->rcBand.bottom);
2607 REBAR_MoveChildWindows (infoPtr, imindBand, imaxdBand+1);
2609 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
2610 UpdateWindow (infoPtr->hwndSelf);
2616 /* << REBAR_BeginDrag >> */
2619 static LRESULT
2620 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2622 UINT uBand = (UINT)wParam;
2623 HWND childhwnd = 0;
2624 REBAR_BAND *lpBand;
2626 if (uBand >= infoPtr->uNumBands)
2627 return FALSE;
2629 TRACE("deleting band %u!\n", uBand);
2630 lpBand = &infoPtr->bands[uBand];
2631 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2633 if (infoPtr->uNumBands == 1) {
2634 TRACE(" simple delete!\n");
2635 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2636 childhwnd = lpBand->hwndChild;
2637 Free (infoPtr->bands);
2638 infoPtr->bands = NULL;
2639 infoPtr->uNumBands = 0;
2641 else {
2642 REBAR_BAND *oldBands = infoPtr->bands;
2643 TRACE("complex delete! [uBand=%u]\n", uBand);
2645 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2646 childhwnd = lpBand->hwndChild;
2648 infoPtr->uNumBands--;
2649 infoPtr->bands = Alloc (sizeof (REBAR_BAND) * infoPtr->uNumBands);
2650 if (uBand > 0) {
2651 memcpy (&infoPtr->bands[0], &oldBands[0],
2652 uBand * sizeof(REBAR_BAND));
2655 if (uBand < infoPtr->uNumBands) {
2656 memcpy (&infoPtr->bands[uBand], &oldBands[uBand+1],
2657 (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
2660 Free (oldBands);
2663 if (childhwnd)
2664 ShowWindow (childhwnd, SW_HIDE);
2666 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2668 /* if only 1 band left the re-validate to possible eliminate gripper */
2669 if (infoPtr->uNumBands == 1)
2670 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2672 TRACE("setting NEEDS_LAYOUT\n");
2673 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
2674 infoPtr->fStatus |= RESIZE_ANYHOW;
2675 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
2677 return TRUE;
2681 /* << REBAR_DragMove >> */
2682 /* << REBAR_EndDrag >> */
2685 static LRESULT
2686 REBAR_GetBandBorders (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2688 LPRECT lpRect = (LPRECT)lParam;
2689 REBAR_BAND *lpBand;
2691 if (!lParam)
2692 return 0;
2693 if ((UINT)wParam >= infoPtr->uNumBands)
2694 return 0;
2696 lpBand = &infoPtr->bands[(UINT)wParam];
2698 /* FIXME - the following values were determined by experimentation */
2699 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2700 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2701 /* difference in size of the control area with and without the */
2702 /* style. - GA */
2703 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2704 if (infoPtr->dwStyle & CCS_VERT) {
2705 lpRect->left = 1;
2706 lpRect->top = lpBand->cxHeader + 4;
2707 lpRect->right = 1;
2708 lpRect->bottom = 0;
2710 else {
2711 lpRect->left = lpBand->cxHeader + 4;
2712 lpRect->top = 1;
2713 lpRect->right = 0;
2714 lpRect->bottom = 1;
2717 else {
2718 lpRect->left = lpBand->cxHeader;
2720 return 0;
2724 inline static LRESULT
2725 REBAR_GetBandCount (REBAR_INFO *infoPtr)
2727 TRACE("band count %u!\n", infoPtr->uNumBands);
2729 return infoPtr->uNumBands;
2733 static LRESULT
2734 REBAR_GetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2736 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2737 REBAR_BAND *lpBand;
2739 if (lprbbi == NULL)
2740 return FALSE;
2741 if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2742 return FALSE;
2743 if ((UINT)wParam >= infoPtr->uNumBands)
2744 return FALSE;
2746 TRACE("index %u\n", (UINT)wParam);
2748 /* copy band information */
2749 lpBand = &infoPtr->bands[(UINT)wParam];
2751 if (lprbbi->fMask & RBBIM_STYLE)
2752 lprbbi->fStyle = lpBand->fStyle;
2754 if (lprbbi->fMask & RBBIM_COLORS) {
2755 lprbbi->clrFore = lpBand->clrFore;
2756 lprbbi->clrBack = lpBand->clrBack;
2757 if (lprbbi->clrBack == CLR_DEFAULT)
2758 lprbbi->clrBack = infoPtr->clrBtnFace;
2761 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2762 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2764 if (!WideCharToMultiByte( CP_ACP, 0, lpBand->lpText, -1,
2765 lprbbi->lpText, lprbbi->cch, NULL, NULL ))
2766 lprbbi->lpText[lprbbi->cch-1] = 0;
2768 else
2769 *lprbbi->lpText = 0;
2772 if (lprbbi->fMask & RBBIM_IMAGE) {
2773 if (lpBand->fMask & RBBIM_IMAGE)
2774 lprbbi->iImage = lpBand->iImage;
2775 else
2776 lprbbi->iImage = -1;
2779 if (lprbbi->fMask & RBBIM_CHILD)
2780 lprbbi->hwndChild = lpBand->hwndChild;
2782 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2783 lprbbi->cxMinChild = lpBand->cxMinChild;
2784 lprbbi->cyMinChild = lpBand->cyMinChild;
2785 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2786 lprbbi->cyChild = lpBand->cyChild;
2787 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2788 lprbbi->cyIntegral = lpBand->cyIntegral;
2792 if (lprbbi->fMask & RBBIM_SIZE)
2793 lprbbi->cx = lpBand->cx;
2795 if (lprbbi->fMask & RBBIM_BACKGROUND)
2796 lprbbi->hbmBack = lpBand->hbmBack;
2798 if (lprbbi->fMask & RBBIM_ID)
2799 lprbbi->wID = lpBand->wID;
2801 /* check for additional data */
2802 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2803 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2804 lprbbi->cxIdeal = lpBand->cxIdeal;
2806 if (lprbbi->fMask & RBBIM_LPARAM)
2807 lprbbi->lParam = lpBand->lParam;
2809 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2810 lprbbi->cxHeader = lpBand->cxHeader;
2813 REBAR_DumpBandInfo (lprbbi);
2815 return TRUE;
2819 static LRESULT
2820 REBAR_GetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2822 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2823 REBAR_BAND *lpBand;
2825 if (lprbbi == NULL)
2826 return FALSE;
2827 if (lprbbi->cbSize < REBARBANDINFOW_V3_SIZE)
2828 return FALSE;
2829 if ((UINT)wParam >= infoPtr->uNumBands)
2830 return FALSE;
2832 TRACE("index %u\n", (UINT)wParam);
2834 /* copy band information */
2835 lpBand = &infoPtr->bands[(UINT)wParam];
2837 if (lprbbi->fMask & RBBIM_STYLE)
2838 lprbbi->fStyle = lpBand->fStyle;
2840 if (lprbbi->fMask & RBBIM_COLORS) {
2841 lprbbi->clrFore = lpBand->clrFore;
2842 lprbbi->clrBack = lpBand->clrBack;
2843 if (lprbbi->clrBack == CLR_DEFAULT)
2844 lprbbi->clrBack = infoPtr->clrBtnFace;
2847 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2848 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2849 lstrcpynW (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
2850 else
2851 *lprbbi->lpText = 0;
2854 if (lprbbi->fMask & RBBIM_IMAGE) {
2855 if (lpBand->fMask & RBBIM_IMAGE)
2856 lprbbi->iImage = lpBand->iImage;
2857 else
2858 lprbbi->iImage = -1;
2861 if (lprbbi->fMask & RBBIM_CHILD)
2862 lprbbi->hwndChild = lpBand->hwndChild;
2864 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2865 lprbbi->cxMinChild = lpBand->cxMinChild;
2866 lprbbi->cyMinChild = lpBand->cyMinChild;
2867 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2868 lprbbi->cyChild = lpBand->cyChild;
2869 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2870 lprbbi->cyIntegral = lpBand->cyIntegral;
2874 if (lprbbi->fMask & RBBIM_SIZE)
2875 lprbbi->cx = lpBand->cx;
2877 if (lprbbi->fMask & RBBIM_BACKGROUND)
2878 lprbbi->hbmBack = lpBand->hbmBack;
2880 if (lprbbi->fMask & RBBIM_ID)
2881 lprbbi->wID = lpBand->wID;
2883 /* check for additional data */
2884 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2885 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2886 lprbbi->cxIdeal = lpBand->cxIdeal;
2888 if (lprbbi->fMask & RBBIM_LPARAM)
2889 lprbbi->lParam = lpBand->lParam;
2891 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2892 lprbbi->cxHeader = lpBand->cxHeader;
2895 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
2897 return TRUE;
2901 static LRESULT
2902 REBAR_GetBarHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2904 INT nHeight;
2906 nHeight = (infoPtr->dwStyle & CCS_VERT) ? infoPtr->calcSize.cx : infoPtr->calcSize.cy;
2908 TRACE("height = %d\n", nHeight);
2910 return nHeight;
2914 static LRESULT
2915 REBAR_GetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2917 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
2919 if (lpInfo == NULL)
2920 return FALSE;
2922 if (lpInfo->cbSize < sizeof (REBARINFO))
2923 return FALSE;
2925 TRACE("getting bar info!\n");
2927 if (infoPtr->himl) {
2928 lpInfo->himl = infoPtr->himl;
2929 lpInfo->fMask |= RBIM_IMAGELIST;
2932 return TRUE;
2936 inline static LRESULT
2937 REBAR_GetBkColor (REBAR_INFO *infoPtr)
2939 COLORREF clr = infoPtr->clrBk;
2941 if (clr == CLR_DEFAULT)
2942 clr = infoPtr->clrBtnFace;
2944 TRACE("background color 0x%06lx!\n", clr);
2946 return clr;
2950 /* << REBAR_GetColorScheme >> */
2951 /* << REBAR_GetDropTarget >> */
2954 static LRESULT
2955 REBAR_GetPalette (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2957 FIXME("empty stub!\n");
2959 return 0;
2963 static LRESULT
2964 REBAR_GetRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2966 INT iBand = (INT)wParam;
2967 LPRECT lprc = (LPRECT)lParam;
2968 REBAR_BAND *lpBand;
2970 if ((iBand < 0) && ((UINT)iBand >= infoPtr->uNumBands))
2971 return FALSE;
2972 if (!lprc)
2973 return FALSE;
2975 lpBand = &infoPtr->bands[iBand];
2976 CopyRect (lprc, &lpBand->rcBand);
2978 TRACE("band %d, (%ld,%ld)-(%ld,%ld)\n", iBand,
2979 lprc->left, lprc->top, lprc->right, lprc->bottom);
2981 return TRUE;
2985 inline static LRESULT
2986 REBAR_GetRowCount (REBAR_INFO *infoPtr)
2988 TRACE("%u\n", infoPtr->uNumRows);
2990 return infoPtr->uNumRows;
2994 static LRESULT
2995 REBAR_GetRowHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2997 INT iRow = (INT)wParam;
2998 int j = 0, ret = 0;
2999 UINT i;
3000 REBAR_BAND *lpBand;
3002 for (i=0; i<infoPtr->uNumBands; i++) {
3003 lpBand = &infoPtr->bands[i];
3004 if (HIDDENBAND(lpBand)) continue;
3005 if (lpBand->iRow != iRow) continue;
3006 if (infoPtr->dwStyle & CCS_VERT)
3007 j = lpBand->rcBand.right - lpBand->rcBand.left;
3008 else
3009 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
3010 if (j > ret) ret = j;
3013 TRACE("row %d, height %d\n", iRow, ret);
3015 return ret;
3019 inline static LRESULT
3020 REBAR_GetTextColor (REBAR_INFO *infoPtr)
3022 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
3024 return infoPtr->clrText;
3028 inline static LRESULT
3029 REBAR_GetToolTips (REBAR_INFO *infoPtr)
3031 return (LRESULT)infoPtr->hwndToolTip;
3035 inline static LRESULT
3036 REBAR_GetUnicodeFormat (REBAR_INFO *infoPtr)
3038 TRACE("%s hwnd=%p\n",
3039 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
3041 return infoPtr->bUnicode;
3045 inline static LRESULT
3046 REBAR_GetVersion (REBAR_INFO *infoPtr)
3048 TRACE("version %d\n", infoPtr->iVersion);
3049 return infoPtr->iVersion;
3053 static LRESULT
3054 REBAR_HitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3056 LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
3058 if (!lprbht)
3059 return -1;
3061 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
3063 return lprbht->iBand;
3067 static LRESULT
3068 REBAR_IdToIndex (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3070 UINT i;
3072 if (infoPtr == NULL)
3073 return -1;
3075 if (infoPtr->uNumBands < 1)
3076 return -1;
3078 for (i = 0; i < infoPtr->uNumBands; i++) {
3079 if (infoPtr->bands[i].wID == (UINT)wParam) {
3080 TRACE("id %u is band %u found!\n", (UINT)wParam, i);
3081 return i;
3085 TRACE("id %u is not found\n", (UINT)wParam);
3086 return -1;
3090 static LRESULT
3091 REBAR_InsertBandA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3093 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
3094 UINT uIndex = (UINT)wParam;
3095 REBAR_BAND *lpBand;
3097 if (infoPtr == NULL)
3098 return FALSE;
3099 if (lprbbi == NULL)
3100 return FALSE;
3101 if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
3102 return FALSE;
3104 /* trace the index as signed to see the -1 */
3105 TRACE("insert band at %d!\n", (INT)uIndex);
3106 REBAR_DumpBandInfo (lprbbi);
3108 if (infoPtr->uNumBands == 0) {
3109 infoPtr->bands = (REBAR_BAND *)Alloc (sizeof (REBAR_BAND));
3110 uIndex = 0;
3112 else {
3113 REBAR_BAND *oldBands = infoPtr->bands;
3114 infoPtr->bands =
3115 (REBAR_BAND *)Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3116 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3117 uIndex = infoPtr->uNumBands;
3119 /* pre insert copy */
3120 if (uIndex > 0) {
3121 memcpy (&infoPtr->bands[0], &oldBands[0],
3122 uIndex * sizeof(REBAR_BAND));
3125 /* post copy */
3126 if (uIndex < infoPtr->uNumBands - 1) {
3127 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3128 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
3131 Free (oldBands);
3134 infoPtr->uNumBands++;
3136 TRACE("index %u!\n", uIndex);
3138 /* initialize band (infoPtr->bands[uIndex])*/
3139 lpBand = &infoPtr->bands[uIndex];
3140 lpBand->fMask = 0;
3141 lpBand->fStatus = 0;
3142 lpBand->clrFore = infoPtr->clrText;
3143 lpBand->clrBack = infoPtr->clrBk;
3144 lpBand->hwndChild = 0;
3145 lpBand->hwndPrevParent = 0;
3147 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3148 lpBand->lpText = NULL;
3149 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3150 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3151 if (len > 1) {
3152 lpBand->lpText = (LPWSTR)Alloc (len*sizeof(WCHAR));
3153 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3157 REBAR_ValidateBand (infoPtr, lpBand);
3158 /* On insert of second band, revalidate band 1 to possible add gripper */
3159 if (infoPtr->uNumBands == 2)
3160 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3162 REBAR_DumpBand (infoPtr);
3164 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3165 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3167 return TRUE;
3171 static LRESULT
3172 REBAR_InsertBandW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3174 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3175 UINT uIndex = (UINT)wParam;
3176 REBAR_BAND *lpBand;
3178 if (infoPtr == NULL)
3179 return FALSE;
3180 if (lprbbi == NULL)
3181 return FALSE;
3182 if (lprbbi->cbSize < REBARBANDINFOW_V3_SIZE)
3183 return FALSE;
3185 /* trace the index as signed to see the -1 */
3186 TRACE("insert band at %d!\n", (INT)uIndex);
3187 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3189 if (infoPtr->uNumBands == 0) {
3190 infoPtr->bands = (REBAR_BAND *)Alloc (sizeof (REBAR_BAND));
3191 uIndex = 0;
3193 else {
3194 REBAR_BAND *oldBands = infoPtr->bands;
3195 infoPtr->bands =
3196 (REBAR_BAND *)Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3197 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3198 uIndex = infoPtr->uNumBands;
3200 /* pre insert copy */
3201 if (uIndex > 0) {
3202 memcpy (&infoPtr->bands[0], &oldBands[0],
3203 uIndex * sizeof(REBAR_BAND));
3206 /* post copy */
3207 if (uIndex <= infoPtr->uNumBands - 1) {
3208 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3209 (infoPtr->uNumBands - uIndex) * sizeof(REBAR_BAND));
3212 Free (oldBands);
3215 infoPtr->uNumBands++;
3217 TRACE("index %u!\n", uIndex);
3219 /* initialize band (infoPtr->bands[uIndex])*/
3220 lpBand = &infoPtr->bands[uIndex];
3221 lpBand->fMask = 0;
3222 lpBand->fStatus = 0;
3223 lpBand->clrFore = infoPtr->clrText;
3224 lpBand->clrBack = infoPtr->clrBk;
3225 lpBand->hwndChild = 0;
3226 lpBand->hwndPrevParent = 0;
3228 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3229 lpBand->lpText = NULL;
3230 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3231 INT len = lstrlenW (lprbbi->lpText);
3232 if (len > 0) {
3233 lpBand->lpText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
3234 strcpyW (lpBand->lpText, lprbbi->lpText);
3238 REBAR_ValidateBand (infoPtr, lpBand);
3239 /* On insert of second band, revalidate band 1 to possible add gripper */
3240 if (infoPtr->uNumBands == 2)
3241 REBAR_ValidateBand (infoPtr, &infoPtr->bands[uIndex ? 0 : 1]);
3243 REBAR_DumpBand (infoPtr);
3245 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3246 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3248 return TRUE;
3252 static LRESULT
3253 REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3255 REBAR_BAND *lpBand;
3256 UINT uBand = (UINT) wParam;
3258 /* Validate */
3259 if ((infoPtr->uNumBands == 0) ||
3260 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3261 /* error !!! */
3262 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
3263 (INT)uBand, infoPtr->uNumBands);
3264 return FALSE;
3267 lpBand = &infoPtr->bands[uBand];
3269 if (lParam && (lpBand->fMask & RBBIM_IDEALSIZE)) {
3270 /* handle setting ideal size */
3271 lpBand->ccx = lpBand->cxIdeal;
3273 else {
3274 /* handle setting to max */
3275 FIXME("(uBand = %u fIdeal = %s) case not coded\n",
3276 (UINT)wParam, lParam ? "TRUE" : "FALSE");
3277 return FALSE;
3280 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3281 REBAR_Layout (infoPtr, 0, TRUE, TRUE);
3282 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
3284 return TRUE;
3289 static LRESULT
3290 REBAR_MinimizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3292 REBAR_BAND *band, *lpBand;
3293 UINT uBand = (UINT) wParam;
3294 RECT newrect;
3295 INT imindBand, imaxdBand, iprevBand, startBand, endBand;
3296 INT movement, i;
3298 /* A "minimize" band is equivalent to "dragging" the gripper
3299 * of than band to the right till the band is only the size
3300 * of the cxHeader.
3303 /* Validate */
3304 if ((infoPtr->uNumBands == 0) ||
3305 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3306 /* error !!! */
3307 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
3308 (INT)uBand, infoPtr->uNumBands);
3309 return FALSE;
3312 /* compute amount of movement and validate */
3313 lpBand = &infoPtr->bands[uBand];
3315 if (infoPtr->dwStyle & CCS_VERT)
3316 movement = lpBand->rcBand.bottom - lpBand->rcBand.top -
3317 lpBand->cxHeader;
3318 else
3319 movement = lpBand->rcBand.right - lpBand->rcBand.left -
3320 lpBand->cxHeader;
3321 if (movement < 0) {
3322 ERR("something is wrong, band=(%ld,%ld)-(%ld,%ld), cxheader=%d\n",
3323 lpBand->rcBand.left, lpBand->rcBand.top,
3324 lpBand->rcBand.right, lpBand->rcBand.bottom,
3325 lpBand->cxHeader);
3326 return FALSE;
3329 imindBand = -1;
3330 imaxdBand = -1;
3331 iprevBand = -1; /* to suppress warning message */
3333 /* find the first band in row of the one whose is being minimized */
3334 for (i=0; i<infoPtr->uNumBands; i++) {
3335 band = &infoPtr->bands[i];
3336 if (HIDDENBAND(band)) continue;
3337 if (band->iRow == lpBand->iRow) {
3338 imaxdBand = i;
3339 if (imindBand == -1) imindBand = i;
3343 /* if the selected band is first in row then need to expand */
3344 /* next visible band */
3345 if (imindBand == uBand) {
3346 band = NULL;
3347 movement = -movement;
3348 /* find the first visible band to the right of the selected band */
3349 for (i=uBand+1; i<=imaxdBand; i++) {
3350 band = &infoPtr->bands[i];
3351 if (!HIDDENBAND(band)) {
3352 iprevBand = i;
3353 LEADJ(band, movement);
3354 band->ccx = rcBw(band);
3355 break;
3358 /* what case is this */
3359 if (iprevBand == -1) {
3360 ERR("no previous visible band\n");
3361 return FALSE;
3363 startBand = uBand;
3364 endBand = iprevBand;
3365 SetRect (&newrect,
3366 lpBand->rcBand.left,
3367 lpBand->rcBand.top,
3368 band->rcBand.right,
3369 band->rcBand.bottom);
3371 /* otherwise expand previous visible band */
3372 else {
3373 band = NULL;
3374 /* find the first visible band to the left of the selected band */
3375 for (i=uBand-1; i>=imindBand; i--) {
3376 band = &infoPtr->bands[i];
3377 if (!HIDDENBAND(band)) {
3378 iprevBand = i;
3379 READJ(band, movement);
3380 band->ccx = rcBw(band);
3381 break;
3384 /* what case is this */
3385 if (iprevBand == -1) {
3386 ERR("no previous visible band\n");
3387 return FALSE;
3389 startBand = iprevBand;
3390 endBand = uBand;
3391 SetRect (&newrect,
3392 band->rcBand.left,
3393 band->rcBand.top,
3394 lpBand->rcBand.right,
3395 lpBand->rcBand.bottom);
3398 REBAR_Shrink (infoPtr, lpBand, movement, uBand);
3400 /* recompute all rectangles */
3401 if (infoPtr->dwStyle & CCS_VERT) {
3402 REBAR_CalcVertBand (infoPtr, startBand, endBand+1,
3403 FALSE);
3405 else {
3406 REBAR_CalcHorzBand (infoPtr, startBand, endBand+1,
3407 FALSE);
3410 TRACE("bands after minimize, see band # %d, %d\n",
3411 startBand, endBand);
3412 REBAR_DumpBand (infoPtr);
3414 REBAR_MoveChildWindows (infoPtr, startBand, endBand+1);
3416 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
3417 UpdateWindow (infoPtr->hwndSelf);
3418 return FALSE;
3422 static LRESULT
3423 REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3425 REBAR_BAND *oldBands = infoPtr->bands;
3426 REBAR_BAND holder;
3427 UINT uFrom = (UINT)wParam;
3428 UINT uTo = (UINT)lParam;
3430 /* Validate */
3431 if ((infoPtr->uNumBands == 0) ||
3432 ((INT)uFrom < 0) || (uFrom >= infoPtr->uNumBands) ||
3433 ((INT)uTo < 0) || (uTo >= infoPtr->uNumBands)) {
3434 /* error !!! */
3435 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
3436 (INT)uFrom, (INT)uTo, infoPtr->uNumBands);
3437 return FALSE;
3440 /* save one to be moved */
3441 memcpy (&holder, &oldBands[uFrom], sizeof(REBAR_BAND));
3443 /* close up rest of bands (pseudo delete) */
3444 if (uFrom < infoPtr->uNumBands - 1) {
3445 memcpy (&oldBands[uFrom], &oldBands[uFrom+1],
3446 (infoPtr->uNumBands - uFrom - 1) * sizeof(REBAR_BAND));
3449 /* allocate new space and copy rest of bands into it */
3450 infoPtr->bands =
3451 (REBAR_BAND *)Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
3453 /* pre insert copy */
3454 if (uTo > 0) {
3455 memcpy (&infoPtr->bands[0], &oldBands[0],
3456 uTo * sizeof(REBAR_BAND));
3459 /* set moved band */
3460 memcpy (&infoPtr->bands[uTo], &holder, sizeof(REBAR_BAND));
3462 /* post copy */
3463 if (uTo < infoPtr->uNumBands - 1) {
3464 memcpy (&infoPtr->bands[uTo+1], &oldBands[uTo],
3465 (infoPtr->uNumBands - uTo - 1) * sizeof(REBAR_BAND));
3468 Free (oldBands);
3470 TRACE("moved band %d to index %d\n", uFrom, uTo);
3471 REBAR_DumpBand (infoPtr);
3473 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3474 /* **************************************************** */
3475 /* */
3476 /* We do not do a REBAR_Layout here because the native */
3477 /* control does not do that. The actual layout and */
3478 /* repaint is done by the *next* real action, ex.: */
3479 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
3480 /* */
3481 /* **************************************************** */
3483 return TRUE;
3487 /* return TRUE if two strings are different */
3488 static BOOL
3489 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
3491 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
3494 static LRESULT
3495 REBAR_SetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3497 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
3498 REBAR_BAND *lpBand;
3499 BOOL bChanged;
3501 if (lprbbi == NULL)
3502 return FALSE;
3503 if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
3504 return FALSE;
3505 if ((UINT)wParam >= infoPtr->uNumBands)
3506 return FALSE;
3508 TRACE("index %u\n", (UINT)wParam);
3509 REBAR_DumpBandInfo (lprbbi);
3511 /* set band information */
3512 lpBand = &infoPtr->bands[(UINT)wParam];
3514 bChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3515 if (lprbbi->fMask & RBBIM_TEXT) {
3516 LPWSTR wstr = NULL;
3518 if (lprbbi->lpText)
3520 INT len;
3521 len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3522 if (len > 1)
3523 wstr = (LPWSTR)Alloc (len*sizeof(WCHAR));
3524 if (wstr)
3525 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, wstr, len );
3527 if (REBAR_strdifW(lpBand->lpText, wstr)) {
3528 if (lpBand->lpText) {
3529 Free (lpBand->lpText);
3530 lpBand->lpText = NULL;
3532 if (wstr) {
3533 lpBand->lpText = wstr;
3534 wstr = NULL;
3536 bChanged = TRUE;
3538 if (wstr)
3539 Free (wstr);
3542 REBAR_ValidateBand (infoPtr, lpBand);
3544 REBAR_DumpBand (infoPtr);
3546 if (bChanged && (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE))) {
3547 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3548 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3551 return TRUE;
3554 static LRESULT
3555 REBAR_SetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3557 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3558 REBAR_BAND *lpBand;
3559 BOOL bChanged;
3561 if (lprbbi == NULL)
3562 return FALSE;
3563 if (lprbbi->cbSize < REBARBANDINFOW_V3_SIZE)
3564 return FALSE;
3565 if ((UINT)wParam >= infoPtr->uNumBands)
3566 return FALSE;
3568 TRACE("index %u\n", (UINT)wParam);
3569 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3571 /* set band information */
3572 lpBand = &infoPtr->bands[(UINT)wParam];
3574 bChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3575 if( (lprbbi->fMask & RBBIM_TEXT) &&
3576 REBAR_strdifW( lpBand->lpText, lprbbi->lpText ) ) {
3577 if (lpBand->lpText) {
3578 Free (lpBand->lpText);
3579 lpBand->lpText = NULL;
3581 if (lprbbi->lpText) {
3582 INT len = lstrlenW (lprbbi->lpText);
3583 if (len > 0)
3585 lpBand->lpText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
3586 strcpyW (lpBand->lpText, lprbbi->lpText);
3589 bChanged = TRUE;
3592 REBAR_ValidateBand (infoPtr, lpBand);
3594 REBAR_DumpBand (infoPtr);
3596 if ( bChanged && (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) ) {
3597 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3598 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3601 return TRUE;
3605 static LRESULT
3606 REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3608 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
3609 REBAR_BAND *lpBand;
3610 UINT i;
3612 if (lpInfo == NULL)
3613 return FALSE;
3615 if (lpInfo->cbSize < sizeof (REBARINFO))
3616 return FALSE;
3618 TRACE("setting bar info!\n");
3620 if (lpInfo->fMask & RBIM_IMAGELIST) {
3621 infoPtr->himl = lpInfo->himl;
3622 if (infoPtr->himl) {
3623 INT cx, cy;
3624 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
3625 infoPtr->imageSize.cx = cx;
3626 infoPtr->imageSize.cy = cy;
3628 else {
3629 infoPtr->imageSize.cx = 0;
3630 infoPtr->imageSize.cy = 0;
3632 TRACE("new image cx=%ld, cy=%ld\n", infoPtr->imageSize.cx,
3633 infoPtr->imageSize.cy);
3636 /* revalidate all bands to reset flags for images in headers of bands */
3637 for (i=0; i<infoPtr->uNumBands; i++) {
3638 lpBand = &infoPtr->bands[i];
3639 REBAR_ValidateBand (infoPtr, lpBand);
3642 return TRUE;
3646 static LRESULT
3647 REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3649 COLORREF clrTemp;
3651 clrTemp = infoPtr->clrBk;
3652 infoPtr->clrBk = (COLORREF)lParam;
3654 TRACE("background color 0x%06lx!\n", infoPtr->clrBk);
3656 return clrTemp;
3660 /* << REBAR_SetColorScheme >> */
3661 /* << REBAR_SetPalette >> */
3664 static LRESULT
3665 REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3667 HWND hwndTemp = infoPtr->hwndNotify;
3669 infoPtr->hwndNotify = (HWND)wParam;
3671 return (LRESULT)hwndTemp;
3675 static LRESULT
3676 REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3678 COLORREF clrTemp;
3680 clrTemp = infoPtr->clrText;
3681 infoPtr->clrText = (COLORREF)lParam;
3683 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
3685 return clrTemp;
3689 /* << REBAR_SetTooltips >> */
3692 inline static LRESULT
3693 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, WPARAM wParam)
3695 BOOL bTemp = infoPtr->bUnicode;
3697 TRACE("to %s hwnd=%p, was %s\n",
3698 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf,
3699 (bTemp) ? "TRUE" : "FALSE");
3701 infoPtr->bUnicode = (BOOL)wParam;
3703 return bTemp;
3707 static LRESULT
3708 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
3710 INT iOldVersion = infoPtr->iVersion;
3712 if (iVersion > COMCTL32_VERSION)
3713 return -1;
3715 infoPtr->iVersion = iVersion;
3717 TRACE("new version %d\n", iVersion);
3719 return iOldVersion;
3723 static LRESULT
3724 REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3726 REBAR_BAND *lpBand;
3728 if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
3729 return FALSE;
3731 lpBand = &infoPtr->bands[(INT)wParam];
3733 if ((BOOL)lParam) {
3734 TRACE("show band %d\n", (INT)wParam);
3735 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
3736 if (IsWindow (lpBand->hwndChild))
3737 ShowWindow (lpBand->hwndChild, SW_SHOW);
3739 else {
3740 TRACE("hide band %d\n", (INT)wParam);
3741 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
3742 if (IsWindow (lpBand->hwndChild))
3743 ShowWindow (lpBand->hwndChild, SW_HIDE);
3746 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3747 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3748 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3750 return TRUE;
3754 static LRESULT
3755 REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3757 LPRECT lpRect = (LPRECT)lParam;
3758 RECT t1;
3760 if (lpRect == NULL)
3761 return FALSE;
3763 TRACE("[%ld %ld %ld %ld]\n",
3764 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
3766 /* what is going on???? */
3767 GetWindowRect(infoPtr->hwndSelf, &t1);
3768 TRACE("window rect [%ld %ld %ld %ld]\n",
3769 t1.left, t1.top, t1.right, t1.bottom);
3770 GetClientRect(infoPtr->hwndSelf, &t1);
3771 TRACE("client rect [%ld %ld %ld %ld]\n",
3772 t1.left, t1.top, t1.right, t1.bottom);
3774 /* force full _Layout processing */
3775 TRACE("setting NEEDS_LAYOUT\n");
3776 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3777 REBAR_Layout (infoPtr, lpRect, TRUE, FALSE);
3778 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3779 return TRUE;
3784 static LRESULT
3785 REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3787 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3788 RECT wnrc1, clrc1;
3790 if (TRACE_ON(rebar)) {
3791 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
3792 GetClientRect(infoPtr->hwndSelf, &clrc1);
3793 TRACE("window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld) cs=(%d,%d %dx%d)\n",
3794 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3795 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3796 cs->x, cs->y, cs->cx, cs->cy);
3799 TRACE("created!\n");
3800 return 0;
3804 static LRESULT
3805 REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3807 REBAR_BAND *lpBand;
3808 UINT i;
3811 /* free rebar bands */
3812 if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
3813 /* clean up each band */
3814 for (i = 0; i < infoPtr->uNumBands; i++) {
3815 lpBand = &infoPtr->bands[i];
3817 /* delete text strings */
3818 if (lpBand->lpText) {
3819 Free (lpBand->lpText);
3820 lpBand->lpText = NULL;
3822 /* destroy child window */
3823 DestroyWindow (lpBand->hwndChild);
3826 /* free band array */
3827 Free (infoPtr->bands);
3828 infoPtr->bands = NULL;
3831 DeleteObject (infoPtr->hcurArrow);
3832 DeleteObject (infoPtr->hcurHorz);
3833 DeleteObject (infoPtr->hcurVert);
3834 DeleteObject (infoPtr->hcurDrag);
3835 if(infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
3836 SetWindowLongA (infoPtr->hwndSelf, 0, 0);
3838 /* free rebar info data */
3839 Free (infoPtr);
3840 TRACE("destroyed!\n");
3841 return 0;
3845 static LRESULT
3846 REBAR_EraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3848 RECT cliprect;
3850 if (GetClipBox ( (HDC)wParam, &cliprect))
3851 return REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &cliprect);
3852 return 0;
3856 static LRESULT
3857 REBAR_GetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3859 return (LRESULT)infoPtr->hFont;
3862 static LRESULT
3863 REBAR_PushChevron(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3865 if (wParam >= 0 && (UINT)wParam < infoPtr->uNumBands)
3867 NMREBARCHEVRON nmrbc;
3868 REBAR_BAND *lpBand = &infoPtr->bands[wParam];
3870 TRACE("Pressed chevron on band %d\n", wParam);
3872 /* redraw chevron in pushed state */
3873 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
3874 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
3875 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3877 /* notify app so it can display a popup menu or whatever */
3878 nmrbc.uBand = wParam;
3879 nmrbc.wID = lpBand->wID;
3880 nmrbc.lParam = lpBand->lParam;
3881 nmrbc.rc = lpBand->rcChevron;
3882 nmrbc.lParamNM = lParam;
3883 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3885 /* redraw chevron in previous state */
3886 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3887 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3889 return TRUE;
3891 return FALSE;
3894 static LRESULT
3895 REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3897 REBAR_BAND *lpBand;
3898 UINT htFlags;
3899 UINT iHitBand;
3900 POINT ptMouseDown;
3901 ptMouseDown.x = (INT)LOWORD(lParam);
3902 ptMouseDown.y = (INT)HIWORD(lParam);
3904 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3905 lpBand = &infoPtr->bands[iHitBand];
3907 if (htFlags == RBHT_CHEVRON)
3909 REBAR_PushChevron(infoPtr, iHitBand, 0);
3911 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3913 TRACE("Starting drag\n");
3915 SetCapture (infoPtr->hwndSelf);
3916 infoPtr->iGrabbedBand = iHitBand;
3918 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3919 infoPtr->dragStart = MAKEPOINTS(lParam);
3920 infoPtr->dragNow = infoPtr->dragStart;
3921 if (infoPtr->dwStyle & CCS_VERT)
3922 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.top+REBAR_PRE_GRIPPER);
3923 else
3924 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left+REBAR_PRE_GRIPPER);
3926 return 0;
3929 static LRESULT
3930 REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3932 if (infoPtr->iGrabbedBand >= 0)
3934 NMHDR layout;
3935 RECT rect;
3937 infoPtr->dragStart.x = 0;
3938 infoPtr->dragStart.y = 0;
3939 infoPtr->dragNow = infoPtr->dragStart;
3941 ReleaseCapture ();
3943 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3944 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3945 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3946 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3949 infoPtr->iGrabbedBand = -1;
3951 GetClientRect(infoPtr->hwndSelf, &rect);
3952 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3955 return 0;
3958 static LRESULT
3959 REBAR_MouseLeave (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3961 if (infoPtr->ichevronhotBand >= 0)
3963 REBAR_BAND *lpChevronBand = &infoPtr->bands[infoPtr->ichevronhotBand];
3964 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3966 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3967 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3970 infoPtr->iOldBand = -1;
3971 infoPtr->ichevronhotBand = -2;
3973 return TRUE;
3976 static LRESULT
3977 REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3979 REBAR_BAND *lpChevronBand;
3980 POINTS ptsmove;
3982 ptsmove = MAKEPOINTS(lParam);
3984 /* if we are currently dragging a band */
3985 if (infoPtr->iGrabbedBand >= 0)
3987 REBAR_BAND *band1, *band2;
3989 if (GetCapture() != infoPtr->hwndSelf)
3990 ERR("We are dragging but haven't got capture?!?\n");
3992 band1 = &infoPtr->bands[infoPtr->iGrabbedBand-1];
3993 band2 = &infoPtr->bands[infoPtr->iGrabbedBand];
3995 /* if mouse did not move much, exit */
3996 if ((abs(ptsmove.x - infoPtr->dragNow.x) <= mindragx) &&
3997 (abs(ptsmove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3999 /* Test for valid drag case - must not be first band in row */
4000 if (infoPtr->dwStyle & CCS_VERT) {
4001 if ((ptsmove.x < band2->rcBand.left) ||
4002 (ptsmove.x > band2->rcBand.right) ||
4003 ((infoPtr->iGrabbedBand > 0) && (band1->iRow != band2->iRow))) {
4004 FIXME("Cannot drag to other rows yet!!\n");
4006 else {
4007 REBAR_HandleLRDrag (infoPtr, &ptsmove);
4010 else {
4011 if ((ptsmove.y < band2->rcBand.top) ||
4012 (ptsmove.y > band2->rcBand.bottom) ||
4013 ((infoPtr->iGrabbedBand > 0) && (band1->iRow != band2->iRow))) {
4014 FIXME("Cannot drag to other rows yet!!\n");
4016 else {
4017 REBAR_HandleLRDrag (infoPtr, &ptsmove);
4021 else
4023 POINT ptMove;
4024 INT iHitBand;
4025 UINT htFlags;
4026 TRACKMOUSEEVENT trackinfo;
4028 ptMove.x = (INT)ptsmove.x;
4029 ptMove.y = (INT)ptsmove.y;
4030 REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
4032 if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
4034 lpChevronBand = &infoPtr->bands[infoPtr->ichevronhotBand];
4035 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
4037 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
4038 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
4040 infoPtr->ichevronhotBand = -2;
4043 if (htFlags == RBHT_CHEVRON)
4045 /* fill in the TRACKMOUSEEVENT struct */
4046 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4047 trackinfo.dwFlags = TME_QUERY;
4048 trackinfo.hwndTrack = infoPtr->hwndSelf;
4049 trackinfo.dwHoverTime = 0;
4051 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4052 _TrackMouseEvent(&trackinfo);
4054 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4055 if(!(trackinfo.dwFlags & TME_LEAVE))
4057 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4059 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4060 /* and can properly deactivate the hot chevron */
4061 _TrackMouseEvent(&trackinfo);
4064 lpChevronBand = &infoPtr->bands[iHitBand];
4065 if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
4067 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
4068 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
4069 infoPtr->ichevronhotBand = iHitBand;
4072 infoPtr->iOldBand = iHitBand;
4075 return 0;
4079 inline static LRESULT
4080 REBAR_NCCalcSize (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4082 if (infoPtr->dwStyle & WS_BORDER) {
4083 InflateRect((LPRECT)lParam, -GetSystemMetrics(SM_CXEDGE),
4084 -GetSystemMetrics(SM_CYEDGE));
4086 TRACE("new client=(%ld,%ld)-(%ld,%ld)\n",
4087 ((LPRECT)lParam)->left, ((LPRECT)lParam)->top,
4088 ((LPRECT)lParam)->right, ((LPRECT)lParam)->bottom);
4089 return 0;
4093 static LRESULT
4094 REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4096 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
4097 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
4098 RECT wnrc1, clrc1;
4099 NONCLIENTMETRICSA ncm;
4100 HFONT tfont;
4101 INT i;
4103 if (infoPtr != NULL) {
4104 ERR("Strange info structure pointer *not* NULL\n");
4105 return FALSE;
4108 if (TRACE_ON(rebar)) {
4109 GetWindowRect(hwnd, &wnrc1);
4110 GetClientRect(hwnd, &clrc1);
4111 TRACE("window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld) cs=(%d,%d %dx%d)\n",
4112 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
4113 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
4114 cs->x, cs->y, cs->cx, cs->cy);
4117 /* allocate memory for info structure */
4118 infoPtr = (REBAR_INFO *)Alloc (sizeof(REBAR_INFO));
4119 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
4121 /* initialize info structure - initial values are 0 */
4122 infoPtr->clrBk = CLR_NONE;
4123 infoPtr->clrText = CLR_NONE;
4124 infoPtr->clrBtnText = GetSysColor (COLOR_BTNTEXT);
4125 infoPtr->clrBtnFace = GetSysColor (COLOR_BTNFACE);
4126 infoPtr->iOldBand = -1;
4127 infoPtr->ichevronhotBand = -2;
4128 infoPtr->iGrabbedBand = -1;
4129 infoPtr->hwndSelf = hwnd;
4130 infoPtr->DoRedraw = TRUE;
4131 infoPtr->hcurArrow = LoadCursorA (0, (LPSTR)IDC_ARROW);
4132 infoPtr->hcurHorz = LoadCursorA (0, (LPSTR)IDC_SIZEWE);
4133 infoPtr->hcurVert = LoadCursorA (0, (LPSTR)IDC_SIZENS);
4134 infoPtr->hcurDrag = LoadCursorA (0, (LPSTR)IDC_SIZE);
4135 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4136 infoPtr->fStatus = CREATE_RUNNING;
4137 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
4139 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
4140 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
4141 WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
4142 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
4143 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
4145 i = NFR_ANSI;
4147 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
4149 /* add necessary styles to the requested styles */
4150 infoPtr->dwStyle = cs->style | WS_VISIBLE | CCS_TOP;
4151 SetWindowLongA (hwnd, GWL_STYLE, infoPtr->dwStyle);
4153 /* get font handle for Caption Font */
4154 ncm.cbSize = sizeof(NONCLIENTMETRICSA);
4155 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS,
4156 ncm.cbSize, &ncm, 0);
4157 /* if the font is bold, set to normal */
4158 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
4159 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
4161 tfont = CreateFontIndirectA (&ncm.lfCaptionFont);
4162 if (tfont) {
4163 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
4166 /* native does:
4167 GetSysColor (numerous);
4168 GetSysColorBrush (numerous) (see WM_SYSCOLORCHANGE);
4169 *GetStockObject (SYSTEM_FONT);
4170 *SetWindowLong (hwnd, 0, info ptr);
4171 *WM_NOTIFYFORMAT;
4172 *SetWindowLong (hwnd, GWL_STYLE, style+0x10000001);
4173 WS_VISIBLE = 0x10000000;
4174 CCS_TOP = 0x00000001;
4175 *SystemParametersInfo (SPI_GETNONCLIENTMETRICS...);
4176 *CreateFontIndirect (lfCaptionFont from above);
4177 GetDC ();
4178 SelectObject (hdc, fontabove);
4179 GetTextMetrics (hdc, ); guessing is tmHeight
4180 SelectObject (hdc, oldfont);
4181 ReleaseDC ();
4182 GetWindowRect ();
4183 MapWindowPoints (0, parent, rectabove, 2);
4184 GetWindowRect ();
4185 GetClientRect ();
4186 ClientToScreen (clientrect);
4187 SetWindowPos (hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER);
4189 return TRUE;
4193 static LRESULT
4194 REBAR_NCHitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4196 NMMOUSE nmmouse;
4197 POINTS shortpt;
4198 POINT clpt, pt;
4199 INT i;
4200 UINT scrap;
4201 LRESULT ret = HTCLIENT;
4204 * Differences from doc at MSDN (as observed with version 4.71 of
4205 * comctl32.dll
4206 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
4207 * 2. if band is not identified .dwItemSpec is 0xffffffff.
4208 * 3. native always seems to return HTCLIENT if notify return is 0.
4211 shortpt = MAKEPOINTS (lParam);
4212 POINTSTOPOINT(pt, shortpt);
4213 clpt = pt;
4214 ScreenToClient (infoPtr->hwndSelf, &clpt);
4215 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
4216 (INT *)&nmmouse.dwItemSpec);
4217 nmmouse.dwItemData = 0;
4218 nmmouse.pt = clpt;
4219 nmmouse.dwHitInfo = 0;
4220 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
4221 TRACE("notify changed return value from %ld to %d\n",
4222 ret, i);
4223 ret = (LRESULT) i;
4225 TRACE("returning %ld, client point (%ld,%ld)\n", ret, clpt.x, clpt.y);
4226 return ret;
4230 static LRESULT
4231 REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4233 RECT rcWindow;
4234 HDC hdc;
4236 if (infoPtr->dwStyle & WS_MINIMIZE)
4237 return 0; /* Nothing to do */
4239 if (infoPtr->dwStyle & WS_BORDER) {
4241 /* adjust rectangle and draw the necessary edge */
4242 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
4243 return 0;
4244 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
4245 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
4246 TRACE("rect (%ld,%ld)-(%ld,%ld)\n",
4247 rcWindow.left, rcWindow.top,
4248 rcWindow.right, rcWindow.bottom);
4249 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
4250 ReleaseDC( infoPtr->hwndSelf, hdc );
4253 return 0;
4257 static LRESULT
4258 REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4260 INT i;
4262 if (lParam == NF_REQUERY) {
4263 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
4264 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
4265 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
4266 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
4268 i = NFR_ANSI;
4270 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
4271 return (LRESULT)i;
4273 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
4277 static LRESULT
4278 REBAR_Paint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4280 HDC hdc;
4281 PAINTSTRUCT ps;
4282 RECT rc;
4284 GetClientRect(infoPtr->hwndSelf, &rc);
4285 hdc = wParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : (HDC)wParam;
4287 TRACE("painting (%ld,%ld)-(%ld,%ld) client (%ld,%ld)-(%ld,%ld)\n",
4288 ps.rcPaint.left, ps.rcPaint.top,
4289 ps.rcPaint.right, ps.rcPaint.bottom,
4290 rc.left, rc.top, rc.right, rc.bottom);
4292 if (ps.fErase) {
4293 /* Erase area of paint if requested */
4294 REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &ps.rcPaint);
4297 REBAR_Refresh (infoPtr, hdc);
4298 if (!wParam)
4299 EndPaint (infoPtr->hwndSelf, &ps);
4300 return 0;
4304 static LRESULT
4305 REBAR_SetCursor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4307 POINT pt;
4308 UINT flags;
4310 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
4312 GetCursorPos (&pt);
4313 ScreenToClient (infoPtr->hwndSelf, &pt);
4315 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
4317 if (flags == RBHT_GRABBER) {
4318 if ((infoPtr->dwStyle & CCS_VERT) &&
4319 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
4320 SetCursor (infoPtr->hcurVert);
4321 else
4322 SetCursor (infoPtr->hcurHorz);
4324 else if (flags != RBHT_CLIENT)
4325 SetCursor (infoPtr->hcurArrow);
4327 return 0;
4331 static LRESULT
4332 REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4334 RECT rcClient;
4335 REBAR_BAND *lpBand;
4336 UINT i;
4338 infoPtr->hFont = (HFONT)wParam;
4340 /* revalidate all bands to change sizes of text in headers of bands */
4341 for (i=0; i<infoPtr->uNumBands; i++) {
4342 lpBand = &infoPtr->bands[i];
4343 REBAR_ValidateBand (infoPtr, lpBand);
4347 if (LOWORD(lParam)) {
4348 GetClientRect (infoPtr->hwndSelf, &rcClient);
4349 REBAR_Layout (infoPtr, &rcClient, FALSE, TRUE);
4352 return 0;
4356 inline static LRESULT
4357 REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4358 /*****************************************************
4360 * Function;
4361 * Handles the WM_SETREDRAW message.
4363 * Documentation:
4364 * According to testing V4.71 of COMCTL32 returns the
4365 * *previous* status of the redraw flag (either 0 or -1)
4366 * instead of the MSDN documented value of 0 if handled
4368 *****************************************************/
4370 BOOL oldredraw = infoPtr->DoRedraw;
4372 TRACE("set to %s, fStatus=%08x\n",
4373 (wParam) ? "TRUE" : "FALSE", infoPtr->fStatus);
4374 infoPtr->DoRedraw = (BOOL) wParam;
4375 if (wParam) {
4376 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
4377 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
4378 REBAR_ForceResize (infoPtr);
4379 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
4381 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
4383 return (oldredraw) ? -1 : 0;
4387 static LRESULT
4388 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4390 RECT rcClient;
4392 /* auto resize deadlock check */
4393 if (infoPtr->fStatus & AUTO_RESIZE) {
4394 infoPtr->fStatus &= ~AUTO_RESIZE;
4395 TRACE("AUTO_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
4396 infoPtr->fStatus, lParam);
4397 return 0;
4400 if (infoPtr->fStatus & CREATE_RUNNING) {
4401 /* still in CreateWindow */
4402 RECT rcWin;
4404 if ((INT)wParam != SIZE_RESTORED) {
4405 ERR("WM_SIZE in create and flags=%08x, lParam=%08lx\n",
4406 wParam, lParam);
4409 TRACE("still in CreateWindow\n");
4410 infoPtr->fStatus &= ~CREATE_RUNNING;
4411 GetWindowRect ( infoPtr->hwndSelf, &rcWin);
4412 TRACE("win rect (%ld,%ld)-(%ld,%ld)\n",
4413 rcWin.left, rcWin.top, rcWin.right, rcWin.bottom);
4415 if ((lParam == 0) && (rcWin.right-rcWin.left == 0) &&
4416 (rcWin.bottom-rcWin.top == 0)) {
4417 /* native control seems to do this */
4418 GetClientRect (GetParent(infoPtr->hwndSelf), &rcClient);
4419 TRACE("sizing rebar, message and client zero, parent client (%ld,%ld)\n",
4420 rcClient.right, rcClient.bottom);
4422 else {
4423 INT cx, cy;
4425 cx = rcWin.right - rcWin.left;
4426 cy = rcWin.bottom - rcWin.top;
4427 if ((cx == LOWORD(lParam)) && (cy == HIWORD(lParam))) {
4428 return 0;
4431 /* do the actual WM_SIZE request */
4432 GetClientRect (infoPtr->hwndSelf, &rcClient);
4433 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%ld,%ld)\n",
4434 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4435 LOWORD(lParam), HIWORD(lParam),
4436 rcClient.right, rcClient.bottom);
4439 else {
4440 if ((INT)wParam != SIZE_RESTORED) {
4441 ERR("WM_SIZE out of create and flags=%08x, lParam=%08lx\n",
4442 wParam, lParam);
4445 /* Handle cases when outside of the CreateWindow process */
4447 GetClientRect (infoPtr->hwndSelf, &rcClient);
4448 if ((lParam == 0) && (rcClient.right + rcClient.bottom != 0) &&
4449 (infoPtr->dwStyle & RBS_AUTOSIZE)) {
4450 /* on a WM_SIZE to zero and current client not zero and AUTOSIZE */
4451 /* native seems to use the current client rect for the size */
4452 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4453 TRACE("sizing rebar to client (%ld,%ld) size is zero but AUTOSIZE set\n",
4454 rcClient.right, rcClient.bottom);
4456 else {
4457 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%ld,%ld)\n",
4458 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4459 LOWORD(lParam), HIWORD(lParam),
4460 rcClient.right, rcClient.bottom);
4464 if (infoPtr->dwStyle & RBS_AUTOSIZE) {
4465 NMRBAUTOSIZE autosize;
4467 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
4468 autosize.fChanged = 0; /* ??? */
4469 autosize.rcActual = autosize.rcTarget; /* ??? */
4470 REBAR_Notify((NMHDR *) &autosize, infoPtr, RBN_AUTOSIZE);
4471 TRACE("RBN_AUTOSIZE client=(%ld,%ld), lp=%08lx\n",
4472 autosize.rcTarget.right, autosize.rcTarget.bottom, lParam);
4475 if ((infoPtr->calcSize.cx != rcClient.right) ||
4476 (infoPtr->calcSize.cy != rcClient.bottom))
4477 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4479 REBAR_Layout (infoPtr, &rcClient, TRUE, TRUE);
4480 infoPtr->fStatus &= ~AUTO_RESIZE;
4482 return 0;
4486 static LRESULT
4487 REBAR_StyleChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4489 STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
4491 TRACE("current style=%08lx, styleOld=%08lx, style being set to=%08lx\n",
4492 infoPtr->dwStyle, ss->styleOld, ss->styleNew);
4493 infoPtr->dwStyle = ss->styleNew;
4495 return FALSE;
4499 static LRESULT
4500 REBAR_WindowPosChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4502 WINDOWPOS *lpwp = (WINDOWPOS *)lParam;
4503 LRESULT ret;
4504 RECT rc;
4506 /* Save the new origin of this window - used by _ForceResize */
4507 infoPtr->origin.x = lpwp->x;
4508 infoPtr->origin.y = lpwp->y;
4509 ret = DefWindowProcA(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
4510 wParam, lParam);
4511 GetWindowRect(infoPtr->hwndSelf, &rc);
4512 TRACE("hwnd %p new pos (%ld,%ld)-(%ld,%ld)\n",
4513 infoPtr->hwndSelf, rc.left, rc.top, rc.right, rc.bottom);
4514 return ret;
4518 static LRESULT WINAPI
4519 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4521 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
4523 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
4524 hwnd, uMsg, wParam, lParam);
4525 if (!infoPtr && (uMsg != WM_NCCREATE))
4526 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4527 switch (uMsg)
4529 /* case RB_BEGINDRAG: */
4531 case RB_DELETEBAND:
4532 return REBAR_DeleteBand (infoPtr, wParam, lParam);
4534 /* case RB_DRAGMOVE: */
4535 /* case RB_ENDDRAG: */
4537 case RB_GETBANDBORDERS:
4538 return REBAR_GetBandBorders (infoPtr, wParam, lParam);
4540 case RB_GETBANDCOUNT:
4541 return REBAR_GetBandCount (infoPtr);
4543 case RB_GETBANDINFO_OLD:
4544 case RB_GETBANDINFOA:
4545 return REBAR_GetBandInfoA (infoPtr, wParam, lParam);
4547 case RB_GETBANDINFOW:
4548 return REBAR_GetBandInfoW (infoPtr, wParam, lParam);
4550 case RB_GETBARHEIGHT:
4551 return REBAR_GetBarHeight (infoPtr, wParam, lParam);
4553 case RB_GETBARINFO:
4554 return REBAR_GetBarInfo (infoPtr, wParam, lParam);
4556 case RB_GETBKCOLOR:
4557 return REBAR_GetBkColor (infoPtr);
4559 /* case RB_GETCOLORSCHEME: */
4560 /* case RB_GETDROPTARGET: */
4562 case RB_GETPALETTE:
4563 return REBAR_GetPalette (infoPtr, wParam, lParam);
4565 case RB_GETRECT:
4566 return REBAR_GetRect (infoPtr, wParam, lParam);
4568 case RB_GETROWCOUNT:
4569 return REBAR_GetRowCount (infoPtr);
4571 case RB_GETROWHEIGHT:
4572 return REBAR_GetRowHeight (infoPtr, wParam, lParam);
4574 case RB_GETTEXTCOLOR:
4575 return REBAR_GetTextColor (infoPtr);
4577 case RB_GETTOOLTIPS:
4578 return REBAR_GetToolTips (infoPtr);
4580 case RB_GETUNICODEFORMAT:
4581 return REBAR_GetUnicodeFormat (infoPtr);
4583 case CCM_GETVERSION:
4584 return REBAR_GetVersion (infoPtr);
4586 case RB_HITTEST:
4587 return REBAR_HitTest (infoPtr, wParam, lParam);
4589 case RB_IDTOINDEX:
4590 return REBAR_IdToIndex (infoPtr, wParam, lParam);
4592 case RB_INSERTBANDA:
4593 return REBAR_InsertBandA (infoPtr, wParam, lParam);
4595 case RB_INSERTBANDW:
4596 return REBAR_InsertBandW (infoPtr, wParam, lParam);
4598 case RB_MAXIMIZEBAND:
4599 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
4601 case RB_MINIMIZEBAND:
4602 return REBAR_MinimizeBand (infoPtr, wParam, lParam);
4604 case RB_MOVEBAND:
4605 return REBAR_MoveBand (infoPtr, wParam, lParam);
4607 case RB_PUSHCHEVRON:
4608 return REBAR_PushChevron (infoPtr, wParam, lParam);
4610 case RB_SETBANDINFOA:
4611 return REBAR_SetBandInfoA (infoPtr, wParam, lParam);
4613 case RB_SETBANDINFOW:
4614 return REBAR_SetBandInfoW (infoPtr, wParam, lParam);
4616 case RB_SETBARINFO:
4617 return REBAR_SetBarInfo (infoPtr, wParam, lParam);
4619 case RB_SETBKCOLOR:
4620 return REBAR_SetBkColor (infoPtr, wParam, lParam);
4622 /* case RB_SETCOLORSCHEME: */
4623 /* case RB_SETPALETTE: */
4624 /* return REBAR_GetPalette (infoPtr, wParam, lParam); */
4626 case RB_SETPARENT:
4627 return REBAR_SetParent (infoPtr, wParam, lParam);
4629 case RB_SETTEXTCOLOR:
4630 return REBAR_SetTextColor (infoPtr, wParam, lParam);
4632 /* case RB_SETTOOLTIPS: */
4634 case RB_SETUNICODEFORMAT:
4635 return REBAR_SetUnicodeFormat (infoPtr, wParam);
4637 case CCM_SETVERSION:
4638 return REBAR_SetVersion (infoPtr, (INT)wParam);
4640 case RB_SHOWBAND:
4641 return REBAR_ShowBand (infoPtr, wParam, lParam);
4643 case RB_SIZETORECT:
4644 return REBAR_SizeToRect (infoPtr, wParam, lParam);
4647 /* Messages passed to parent */
4648 case WM_COMMAND:
4649 case WM_DRAWITEM:
4650 case WM_NOTIFY:
4651 if (infoPtr->NtfUnicode)
4652 return SendMessageW (REBAR_GetNotifyParent (infoPtr),
4653 uMsg, wParam, lParam);
4654 else
4655 return SendMessageA (REBAR_GetNotifyParent (infoPtr),
4656 uMsg, wParam, lParam);
4659 /* case WM_CHARTOITEM: supported according to ControlSpy */
4661 case WM_CREATE:
4662 return REBAR_Create (infoPtr, wParam, lParam);
4664 case WM_DESTROY:
4665 return REBAR_Destroy (infoPtr, wParam, lParam);
4667 case WM_ERASEBKGND:
4668 return REBAR_EraseBkGnd (infoPtr, wParam, lParam);
4670 case WM_GETFONT:
4671 return REBAR_GetFont (infoPtr, wParam, lParam);
4673 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
4675 case WM_LBUTTONDOWN:
4676 return REBAR_LButtonDown (infoPtr, wParam, lParam);
4678 case WM_LBUTTONUP:
4679 return REBAR_LButtonUp (infoPtr, wParam, lParam);
4681 /* case WM_MEASUREITEM: supported according to ControlSpy */
4683 case WM_MOUSEMOVE:
4684 return REBAR_MouseMove (infoPtr, wParam, lParam);
4686 case WM_MOUSELEAVE:
4687 return REBAR_MouseLeave (infoPtr, wParam, lParam);
4689 case WM_NCCALCSIZE:
4690 return REBAR_NCCalcSize (infoPtr, wParam, lParam);
4692 case WM_NCCREATE:
4693 return REBAR_NCCreate (hwnd, wParam, lParam);
4695 case WM_NCHITTEST:
4696 return REBAR_NCHitTest (infoPtr, wParam, lParam);
4698 case WM_NCPAINT:
4699 return REBAR_NCPaint (infoPtr, wParam, lParam);
4701 case WM_NOTIFYFORMAT:
4702 return REBAR_NotifyFormat (infoPtr, wParam, lParam);
4704 case WM_PAINT:
4705 return REBAR_Paint (infoPtr, wParam, lParam);
4707 /* case WM_PALETTECHANGED: supported according to ControlSpy */
4708 /* case WM_PRINTCLIENT: supported according to ControlSpy */
4709 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
4710 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
4711 /* case WM_RBUTTONUP: supported according to ControlSpy */
4713 case WM_SETCURSOR:
4714 return REBAR_SetCursor (infoPtr, wParam, lParam);
4716 case WM_SETFONT:
4717 return REBAR_SetFont (infoPtr, wParam, lParam);
4719 case WM_SETREDRAW:
4720 return REBAR_SetRedraw (infoPtr, wParam, lParam);
4722 case WM_SIZE:
4723 return REBAR_Size (infoPtr, wParam, lParam);
4725 case WM_STYLECHANGED:
4726 return REBAR_StyleChanged (infoPtr, wParam, lParam);
4728 /* case WM_SYSCOLORCHANGE: supported according to ControlSpy */
4729 /* "Applications that have brushes using the existing system colors
4730 should delete those brushes and recreate them using the new
4731 system colors." per MSDN */
4733 /* case WM_VKEYTOITEM: supported according to ControlSpy */
4734 /* case WM_WININICHANGE: */
4736 case WM_WINDOWPOSCHANGED:
4737 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
4739 default:
4740 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
4741 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
4742 uMsg, wParam, lParam);
4743 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4745 return 0;
4749 VOID
4750 REBAR_Register (void)
4752 WNDCLASSA wndClass;
4754 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4755 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
4756 wndClass.lpfnWndProc = (WNDPROC)REBAR_WindowProc;
4757 wndClass.cbClsExtra = 0;
4758 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
4759 wndClass.hCursor = 0;
4760 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
4761 #if GLATESTING
4762 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
4763 #endif
4764 wndClass.lpszClassName = REBARCLASSNAMEA;
4766 RegisterClassA (&wndClass);
4768 mindragx = GetSystemMetrics (SM_CXDRAG);
4769 mindragy = GetSystemMetrics (SM_CYDRAG);
4774 VOID
4775 REBAR_Unregister (void)
4777 UnregisterClassA (REBARCLASSNAMEA, NULL);