Fix problem exposed by the improvements in version 8b. Demonstrated by
[wine/gsoc_dplay.git] / dlls / comctl32 / rebar.c
blobe2063ca1abb87ade30bd89ea52af237fb9005a24
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 8b
25 * Copyright 1998, 1999 Eric Kohl
27 * NOTES
28 * An author is needed! Any volunteers?
29 * I will only improve this control once in a while.
30 * Eric <ekohl@abo.rhein-zeitung.de>
32 * TODO:
33 * - vertical placement
34 * - ComboBox and ComboBoxEx placement
35 * - center image
36 * - Layout code.
37 * - Display code.
38 * - Some messages.
39 * - All notifications.
41 * Changes Guy Albertelli <galberte@neo.lrun.com>
42 * rev 2,3,4
43 * - Implement initial version of row grouping, row separators,
44 * text and background colors. Support additional messages.
45 * Support RBBS_BREAK. Implement ERASEBKGND and improve painting.
46 * rev 5
47 * - implement support for dragging Gripper left or right in a row. Supports
48 * WM_LBUTTONDOWN, WM_LBUTTONUP, and WM_MOUSEMOVE. Also support
49 * RBS_BANDBORDERS.
50 * rev 6
51 * - Fix or implement notifications for RBN_HEIGHTCHANGE, RBN_CHILDSIZE.
52 * - Correct styles RBBS_NOGRIPPER, RBBS_GRIPPERALWAYS, and RBBS_FIXEDSIZE.
53 * - Fix algorithm for Layout and AdjustBand.
55 * rev 7
56 * - Fix algorithm for _Layout and _AdjustBand.
57 * - Fix or implement RBN_ENDDRAG, RB_MOVEBAND, WM_SETREDRAW,
58 * WM_STYLECHANGED, RB_MINIMIZEBAND, RBBS_VARIABLEHEIGHT, RBS_VARHEIGHT,
59 * RBBS_HIDDEN, WM_NOTIFYFORMAT, NM_NCHITTEST, WM_SETREDRAW, RBS_AUTOSIZE,
60 * WM_SETFONT, RBS_BORDERS
61 * - Create structures in WM_NCCREATE
62 * - Additional performance enhancements.
64 * rev 8
65 * 1. Create array of start and end band indexes by row and use.
66 * 2. Fix problem with REBAR_Layout Phase 2b to process only if only
67 * band in row.
68 * 3. Set the Caption Font (Regular) as default font for text.
69 * 4. Delete font handle on control distruction.
70 * 5. Add UpdateWindow call in _MoveChildWindows to match repainting done
71 * by native control
72 * 6. Improve some traces.
73 * 7. Invalidate window rectangles after SetBandInfo, InsertBand, ShowBand
74 * so that repainting is correct.
75 * 8. Implement RB_MAXIMIZEBAND for the "ideal=TRUE" case.
76 * 9. Implement item custom draw notifications partially. Only done for
77 * ITEMPREPAINT and ITEMPOSTPAINT. (Used by IE4 for "Favorites" frame
78 * to draw the word "Favorites").
79 * rev 8a
80 * 10. Handle CCS_NODIVIDER and fix WS_BORDER code.
81 * 11. Fix logic error in _AdjustBands where flag was set to valid band
82 * number (0) to indicate *no* band.
83 * 12. Fix CCS_VERT errors in _ForceResize, _NCCalcSize, and _NCPaint.
84 * 13. Support some special cases of CCS_TOP (and therefore CCS_LEFT),
85 * CCS_BOTTOM (and therefore CCS_RIGHT) and CCS_NOPARENTALIGN. Not
86 * at all sure whether this is all cases.
87 * 14. Handle returned value for the RBN_CHILDSIZE notify.
88 * 15. Implement RBBS_CHILDEDGE, and set each bands "offChild" at _Layout
89 * time.
90 * 16. Fix REBARSPACE. It should depend on CCS_NODIVIDER.
91 * rev 8b
92 * 17. Fix determination of whether Gripper is needed in _ValidateBand.
93 * 18. Fix _AdjustBand processing of RBBS_FIXEDSIZE.
94 * rev 8c
95 * 19. Fix problem in _Layout when all lengths are 0.
98 * Still to do:
99 * 2. Following still not handled: RBBS_FIXEDBMP,
100 * RBBS_USECHEVRON, CCS_NORESIZE,
101 * CCS_NOMOVEX, CCS_NOMOVEY
102 * 3. Following are only partially handled:
103 * RBS_AUTOSIZE, RBBS_VARIABLEHEIGHT
104 * 5. Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
105 * to set the size of the separator width (the value SEP_WIDTH_SIZE
106 * in here). Should be fixed!!
107 * 6. The following messages are not implemented:
108 * RB_BEGINDRAG, RB_DRAGMOVE, RB_ENDDRAG, RB_GETCOLORSCHEME,
109 * RB_GETDROPTARGET, RB_MAXIMIZEBAND,
110 * RB_SETCOLORSCHEME, RB_SETPALETTE, RB_SETTOOLTIPS
111 * WM_CHARTOITEM, WM_LBUTTONDBLCLK, WM_MEASUREITEM,
112 * WM_PALETTECHANGED, WM_PRINTCLIENT, WM_QUERYNEWPALETTE,
113 * WM_RBUTTONDOWN, WM_RBUTTONUP,
114 * WM_SYSCOLORCHANGE, WM_VKEYTOITEM, WM_WININICHANGE
115 * 7. The following notifications are not implemented:
116 * NM_CUSTOMDRAW, NM_RELEASEDCAPTURE
117 * RB_CHEVRONPUSHED, RBN_MINMAX
120 #include <stdlib.h>
121 #include <string.h>
123 #include "winbase.h"
124 #include "wingdi.h"
125 #include "wine/unicode.h"
126 #include "commctrl.h"
127 /* #include "spy.h" */
128 #include "debugtools.h"
130 DEFAULT_DEBUG_CHANNEL(rebar);
132 typedef struct
134 UINT fStyle;
135 UINT fMask;
136 COLORREF clrFore;
137 COLORREF clrBack;
138 INT iImage;
139 HWND hwndChild;
140 UINT cxMinChild; /* valid if _CHILDSIZE */
141 UINT cyMinChild; /* valid if _CHILDSIZE */
142 UINT cx; /* valid if _SIZE */
143 HBITMAP hbmBack;
144 UINT wID;
145 UINT cyChild; /* valid if _CHILDSIZE */
146 UINT cyMaxChild; /* valid if _CHILDSIZE */
147 UINT cyIntegral; /* valid if _CHILDSIZE */
148 UINT cxIdeal;
149 LPARAM lParam;
150 UINT cxHeader;
152 UINT lcx; /* minimum cx for band */
153 UINT ccx; /* current cx for band */
154 UINT hcx; /* maximum cx for band */
155 UINT lcy; /* minimum cy for band */
156 UINT ccy; /* current cy for band */
157 UINT hcy; /* maximum cy for band */
159 SIZE offChild; /* x,y offset if child is not FIXEDSIZE */
160 UINT uMinHeight;
161 INT iRow; /* row this band assigned to */
162 UINT fStatus; /* status flags, reset only by _Validate */
163 UINT fDraw; /* drawing flags, reset only by _Layout */
164 UINT uCDret; /* last return from NM_CUSTOMDRAW */
165 RECT rcoldBand; /* previous calculated band rectangle */
166 RECT rcBand; /* calculated band rectangle */
167 RECT rcGripper; /* calculated gripper rectangle */
168 RECT rcCapImage; /* calculated caption image rectangle */
169 RECT rcCapText; /* calculated caption text rectangle */
170 RECT rcChild; /* calculated child rectangle */
172 LPWSTR lpText;
173 HWND hwndPrevParent;
174 } REBAR_BAND;
176 /* fStatus flags */
177 #define HAS_GRIPPER 0x00000001
178 #define HAS_IMAGE 0x00000002
179 #define HAS_TEXT 0x00000004
181 /* fDraw flags */
182 #define DRAW_GRIPPER 0x00000001
183 #define DRAW_IMAGE 0x00000002
184 #define DRAW_TEXT 0x00000004
185 #define DRAW_RIGHTSEP 0x00000010
186 #define DRAW_BOTTOMSEP 0x00000020
187 #define NTF_INVALIDATE 0x01000000
189 typedef struct
191 INT istartband; /* index of first band in row */
192 INT iendband; /* index of last band in row */
193 } REBAR_ROW;
196 typedef struct
198 COLORREF clrBk; /* background color */
199 COLORREF clrText; /* text color */
200 COLORREF clrBtnText; /* system color for BTNTEXT */
201 COLORREF clrBtnFace; /* system color for BTNFACE */
202 HIMAGELIST himl; /* handle to imagelist */
203 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
204 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
205 HWND hwndSelf; /* handle of REBAR window itself */
206 HWND hwndToolTip; /* handle to the tool tip control */
207 HWND hwndNotify; /* notification window (parent) */
208 HFONT hDefaultFont;
209 HFONT hFont; /* handle to the rebar's font */
210 SIZE imageSize; /* image size (image list) */
211 DWORD dwStyle; /* window style */
212 SIZE calcSize; /* calculated rebar size */
213 SIZE oldSize; /* previous calculated rebar size */
214 BOOL bUnicode; /* TRUE if this window is W type */
215 BOOL NtfUnicode; /* TRUE if parent wants notify in W format */
216 BOOL DoRedraw; /* TRUE to acutally draw bands */
217 UINT fStatus; /* Status flags (see below) */
218 HCURSOR hcurArrow; /* handle to the arrow cursor */
219 HCURSOR hcurHorz; /* handle to the EW cursor */
220 HCURSOR hcurVert; /* handle to the NS cursor */
221 HCURSOR hcurDrag; /* handle to the drag cursor */
222 INT iVersion; /* version number */
223 POINTS dragStart; /* x,y of button down */
224 POINTS dragNow; /* x,y of this MouseMove */
225 INT ihitBand; /* band number of band whose gripper was grabbed */
226 INT ihitoffset; /* offset of hotspot from gripper.left */
228 REBAR_ROW *rows; /* pointer to row indexes */
229 REBAR_BAND *bands; /* pointer to the array of rebar bands */
230 } REBAR_INFO;
232 /* fStatus flags */
233 #define BEGIN_DRAG_ISSUED 0x00000001
234 #define AUTO_RESIZE 0x00000002
235 #define RESIZE_ANYHOW 0x00000004
236 #define NTF_HGHTCHG 0x00000008
237 #define BAND_NEEDS_LAYOUT 0x00000010
238 #define BAND_NEEDS_REDRAW 0x00000020
239 #define CREATE_RUNNING 0x00000040
241 /* ---- REBAR layout constants. Mostly determined by ---- */
242 /* ---- experiment on WIN 98. ---- */
244 /* Width (or height) of separators between bands (either horz. or */
245 /* vert.). True only if RBS_BANDBORDERS is set */
246 #define SEP_WIDTH_SIZE 2
247 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
249 /* Blank (background color) space between Gripper (if present) */
250 /* and next item (image, text, or window). Always present */
251 #define REBAR_ALWAYS_SPACE 4
253 /* Blank (background color) space after Image (if present). */
254 #define REBAR_POST_IMAGE 2
256 /* Blank (background color) space after Text (if present). */
257 #define REBAR_POST_TEXT 4
259 /* Height of vertical gripper in a CCS_VERT rebar. */
260 #define GRIPPER_HEIGHT 16
262 /* Blank (background color) space before Gripper (if present). */
263 #define REBAR_PRE_GRIPPER 2
265 /* Width (of normal vertical gripper) or height (of horz. gripper) */
266 /* if present. */
267 #define GRIPPER_WIDTH 3
269 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
270 /* either top or bottom */
271 #define REBAR_DIVIDER 2
273 /* This is the increment that is used over the band height */
274 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
276 /* ---- End of REBAR layout constants. ---- */
279 /* The following 6 defines return the proper rcBand element */
280 /* depending on whether CCS_VERT was set. */
281 #define rcBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.top : b->rcBand.left)
282 #define rcBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.bottom : b->rcBand.right)
283 #define rcBw(b) ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.bottom - b->rcBand.top) : \
284 (b->rcBand.right - b->rcBand.left))
285 #define ircBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.left : b->rcBand.top)
286 #define ircBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.right : b->rcBand.bottom)
287 #define ircBw(b) ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.right - b->rcBand.left) : \
288 (b->rcBand.bottom - b->rcBand.top))
290 /* The following define determines if a given band is hidden */
291 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
292 ((infoPtr->dwStyle & CCS_VERT) && \
293 ((a)->fStyle & RBBS_NOVERT)))
295 /* The following defines adjust the right or left end of a rectangle */
296 #define READJ(b,i) {if(infoPtr->dwStyle & CCS_VERT) b->rcBand.bottom+=(i); \
297 else b->rcBand.right += (i);}
298 #define LEADJ(b,i) {if(infoPtr->dwStyle & CCS_VERT) b->rcBand.top+=(i); \
299 else b->rcBand.left += (i);}
302 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongA (hwnd, 0))
305 /* "constant values" retrieved when DLL was initialized */
306 /* FIXME we do this when the classes are registered. */
307 static UINT mindragx = 0;
308 static UINT mindragy = 0;
310 static char *band_stylename[] = {
311 "RBBS_BREAK", /* 0001 */
312 "RBBS_FIXEDSIZE", /* 0002 */
313 "RBBS_CHILDEDGE", /* 0004 */
314 "RBBS_HIDDEN", /* 0008 */
315 "RBBS_NOVERT", /* 0010 */
316 "RBBS_FIXEDBMP", /* 0020 */
317 "RBBS_VARIABLEHEIGHT", /* 0040 */
318 "RBBS_GRIPPERALWAYS", /* 0080 */
319 "RBBS_NOGRIPPER", /* 0100 */
320 NULL };
322 static char *band_maskname[] = {
323 "RBBIM_STYLE", /* 0x00000001 */
324 "RBBIM_COLORS", /* 0x00000002 */
325 "RBBIM_TEXT", /* 0x00000004 */
326 "RBBIM_IMAGE", /* 0x00000008 */
327 "RBBIM_CHILD", /* 0x00000010 */
328 "RBBIM_CHILDSIZE", /* 0x00000020 */
329 "RBBIM_SIZE", /* 0x00000040 */
330 "RBBIM_BACKGROUND", /* 0x00000080 */
331 "RBBIM_ID", /* 0x00000100 */
332 "RBBIM_IDEALSIZE", /* 0x00000200 */
333 "RBBIM_LPARAM", /* 0x00000400 */
334 "RBBIM_HEADERSIZE", /* 0x00000800 */
335 NULL };
338 static CHAR line[200];
341 static CHAR *
342 REBAR_FmtStyle( UINT style)
344 INT i = 0;
346 *line = 0;
347 while (band_stylename[i]) {
348 if (style & (1<<i)) {
349 if (*line != 0) strcat(line, " | ");
350 strcat(line, band_stylename[i]);
352 i++;
354 return line;
358 static CHAR *
359 REBAR_FmtMask( UINT mask)
361 INT i = 0;
363 *line = 0;
364 while (band_maskname[i]) {
365 if (mask & (1<<i)) {
366 if (*line != 0) strcat(line, " | ");
367 strcat(line, band_maskname[i]);
369 i++;
371 return line;
375 static VOID
376 REBAR_DumpBandInfo( LPREBARBANDINFOA pB)
378 if( !TRACE_ON(rebar) ) return;
379 TRACE("band info: ID=%u, size=%u, child=%04x, clrF=0x%06lx, clrB=0x%06lx\n",
380 pB->wID, pB->cbSize, pB->hwndChild, pB->clrFore, pB->clrBack);
381 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
382 if (pB->fMask & RBBIM_STYLE)
383 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
384 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
385 TRACE("band info:");
386 if (pB->fMask & RBBIM_SIZE)
387 DPRINTF(" cx=%u", pB->cx);
388 if (pB->fMask & RBBIM_IDEALSIZE)
389 DPRINTF(" xIdeal=%u", pB->cxIdeal);
390 if (pB->fMask & RBBIM_HEADERSIZE)
391 DPRINTF(" xHeader=%u", pB->cxHeader);
392 if (pB->fMask & RBBIM_LPARAM)
393 DPRINTF(" lParam=0x%08lx", pB->lParam);
394 DPRINTF("\n");
396 if (pB->fMask & RBBIM_CHILDSIZE)
397 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
398 pB->cxMinChild,
399 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
402 static VOID
403 REBAR_DumpBand (REBAR_INFO *iP)
405 REBAR_BAND *pB;
406 UINT i;
408 if(! TRACE_ON(rebar) ) return;
410 TRACE("hwnd=%04x: color=%08lx/%08lx, bands=%u, rows=%u, cSize=%ld,%ld\n",
411 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
412 iP->calcSize.cx, iP->calcSize.cy);
413 TRACE("hwnd=%04x: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, ihitBand=%d\n",
414 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
415 iP->dragNow.x, iP->dragNow.y,
416 iP->ihitBand);
417 TRACE("hwnd=%04x: style=%08lx, I'm Unicode=%s, notify in Unicode=%s, redraw=%s\n",
418 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
419 (iP->NtfUnicode)?"TRUE":"FALSE", (iP->DoRedraw)?"TRUE":"FALSE");
420 for (i = 0; i < iP->uNumBands; i++) {
421 pB = &iP->bands[i];
422 TRACE("band # %u: ID=%u, child=%04x, row=%u, clrF=0x%06lx, clrB=0x%06lx\n",
423 i, pB->wID, pB->hwndChild, pB->iRow, pB->clrFore, pB->clrBack);
424 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
425 if (pB->fMask & RBBIM_STYLE)
426 TRACE("band # %u: style=0x%08x (%s)\n",
427 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
428 TRACE("band # %u: uMinH=%u xHeader=%u",
429 i, pB->uMinHeight, pB->cxHeader);
430 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
431 if (pB->fMask & RBBIM_SIZE)
432 DPRINTF(" cx=%u", pB->cx);
433 if (pB->fMask & RBBIM_IDEALSIZE)
434 DPRINTF(" xIdeal=%u", pB->cxIdeal);
435 if (pB->fMask & RBBIM_LPARAM)
436 DPRINTF(" lParam=0x%08lx", pB->lParam);
438 DPRINTF("\n");
439 if (RBBIM_CHILDSIZE)
440 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
441 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
442 if (pB->fMask & RBBIM_TEXT)
443 TRACE("band # %u: text=%s\n",
444 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
445 TRACE("band # %u: lcx=%u, ccx=%u, hcx=%u, lcy=%u, ccy=%u, hcy=%u, offChild=%ld,%ld\n",
446 i, pB->lcx, pB->ccx, pB->hcx, pB->lcy, pB->ccy, pB->hcy, pB->offChild.cx, pB->offChild.cy);
447 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%d,%d)-(%d,%d), Grip=(%d,%d)-(%d,%d)\n",
448 i, pB->fStatus, pB->fDraw,
449 pB->rcBand.left, pB->rcBand.top, pB->rcBand.right, pB->rcBand.bottom,
450 pB->rcGripper.left, pB->rcGripper.top, pB->rcGripper.right, pB->rcGripper.bottom);
451 TRACE("band # %u: Img=(%d,%d)-(%d,%d), Txt=(%d,%d)-(%d,%d), Child=(%d,%d)-(%d,%d)\n",
453 pB->rcCapImage.left, pB->rcCapImage.top, pB->rcCapImage.right, pB->rcCapImage.bottom,
454 pB->rcCapText.left, pB->rcCapText.top, pB->rcCapText.right, pB->rcCapText.bottom,
455 pB->rcChild.left, pB->rcChild.top, pB->rcChild.right, pB->rcChild.bottom);
461 static HWND
462 REBAR_GetNotifyParent (REBAR_INFO *infoPtr)
464 HWND parent, owner;
466 parent = infoPtr->hwndNotify;
467 if (!parent) {
468 parent = GetParent (infoPtr->hwndSelf);
469 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
470 if (owner) parent = owner;
472 return parent;
476 static INT
477 REBAR_Notify (NMHDR *nmhdr, REBAR_INFO *infoPtr, UINT code)
479 HWND parent;
481 parent = REBAR_GetNotifyParent (infoPtr);
482 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
483 nmhdr->hwndFrom = infoPtr->hwndSelf;
484 nmhdr->code = code;
486 TRACE("window %04x, code=%08x, %s\n", parent, code,
487 (infoPtr->NtfUnicode) ? "via Unicode" : "via ANSI");
489 if (infoPtr->NtfUnicode)
490 return SendMessageW (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
491 (LPARAM)nmhdr);
492 else
493 return SendMessageA (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
494 (LPARAM)nmhdr);
497 static INT
498 REBAR_Notify_NMREBAR (REBAR_INFO *infoPtr, UINT uBand, UINT code)
500 NMREBAR notify_rebar;
501 REBAR_BAND *lpBand;
503 notify_rebar.dwMask = 0;
504 if (uBand!=-1) {
505 lpBand = &infoPtr->bands[uBand];
506 if (lpBand->fMask & RBBIM_ID) {
507 notify_rebar.dwMask |= RBNM_ID;
508 notify_rebar.wID = lpBand->wID;
510 if (lpBand->fMask & RBBIM_LPARAM) {
511 notify_rebar.dwMask |= RBNM_LPARAM;
512 notify_rebar.lParam = lpBand->lParam;
514 if (lpBand->fMask & RBBIM_STYLE) {
515 notify_rebar.dwMask |= RBNM_STYLE;
516 notify_rebar.fStyle = lpBand->fStyle;
519 notify_rebar.uBand = uBand;
520 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
523 static VOID
524 REBAR_DrawBand (HDC hdc, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
526 HFONT hOldFont = 0;
527 INT oldBkMode = 0;
528 NMCUSTOMDRAW nmcd;
530 if (lpBand->fDraw & DRAW_TEXT) {
531 hOldFont = SelectObject (hdc, infoPtr->hFont);
532 oldBkMode = SetBkMode (hdc, TRANSPARENT);
535 /* should test for CDRF_NOTIFYITEMDRAW here */
536 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
537 nmcd.hdc = hdc;
538 nmcd.rc = lpBand->rcBand;
539 nmcd.rc.right = lpBand->rcCapText.right;
540 nmcd.rc.bottom = lpBand->rcCapText.bottom;
541 nmcd.dwItemSpec = lpBand->wID;
542 nmcd.uItemState = 0;
543 nmcd.lItemlParam = lpBand->lParam;
544 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
545 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
546 if (oldBkMode != TRANSPARENT)
547 SetBkMode (hdc, oldBkMode);
548 SelectObject (hdc, hOldFont);
549 return;
552 /* draw gripper */
553 if (lpBand->fDraw & DRAW_GRIPPER)
554 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
556 /* draw caption image */
557 if (lpBand->fDraw & DRAW_IMAGE) {
558 POINT pt;
560 /* center image */
561 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
562 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
564 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
565 pt.x, pt.y,
566 ILD_TRANSPARENT);
569 /* draw caption text */
570 if (lpBand->fDraw & DRAW_TEXT) {
571 /* need to handle CDRF_NEWFONT here */
572 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
573 COLORREF oldcolor = CLR_NONE;
574 COLORREF new;
575 if (lpBand->clrFore != CLR_NONE) {
576 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
577 lpBand->clrFore;
578 oldcolor = SetTextColor (hdc, new);
580 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
581 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
582 if (oldBkMode != TRANSPARENT)
583 SetBkMode (hdc, oldBkMode);
584 if (lpBand->clrFore != CLR_NONE)
585 SetTextColor (hdc, oldcolor);
586 SelectObject (hdc, hOldFont);
589 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
590 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
591 nmcd.hdc = hdc;
592 nmcd.rc = lpBand->rcBand;
593 nmcd.rc.right = lpBand->rcCapText.right;
594 nmcd.rc.bottom = lpBand->rcCapText.bottom;
595 nmcd.dwItemSpec = lpBand->wID;
596 nmcd.uItemState = 0;
597 nmcd.lItemlParam = lpBand->lParam;
598 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
603 static VOID
604 REBAR_Refresh (REBAR_INFO *infoPtr, HDC hdc)
606 REBAR_BAND *lpBand;
607 UINT i, oldrow;
609 if (!infoPtr->DoRedraw) return;
611 oldrow = infoPtr->bands[0].iRow;
612 for (i = 0; i < infoPtr->uNumBands; i++) {
613 lpBand = &infoPtr->bands[i];
615 if (HIDDENBAND(lpBand)) continue;
617 /* now draw the band */
618 TRACE("[%04x] drawing band %i, flags=%08x\n",
619 infoPtr->hwndSelf, i, lpBand->fDraw);
620 REBAR_DrawBand (hdc, infoPtr, lpBand);
626 static void
627 REBAR_FixVert (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
628 INT mcy)
629 /* Function: */
630 /* Cycle through bands in row and fix height of each band. */
631 /* Also determine whether each band has changed. */
632 /* On entry: */
633 /* all bands at desired size. */
634 /* start and end bands are *not* hidden */
636 REBAR_BAND *lpBand;
637 INT i;
639 for (i = (INT)rowstart; i<=(INT)rowend; i++) {
640 lpBand = &infoPtr->bands[i];
641 if (HIDDENBAND(lpBand)) continue;
643 /* adjust height of bands in row to "mcy" value */
644 if (infoPtr->dwStyle & CCS_VERT) {
645 if (lpBand->rcBand.right != lpBand->rcBand.left + mcy)
646 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
648 else {
649 if (lpBand->rcBand.bottom != lpBand->rcBand.top + mcy)
650 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
654 /* mark whether we need to invalidate this band and trace */
655 if ((lpBand->rcoldBand.left !=lpBand->rcBand.left) ||
656 (lpBand->rcoldBand.top !=lpBand->rcBand.top) ||
657 (lpBand->rcoldBand.right !=lpBand->rcBand.right) ||
658 (lpBand->rcoldBand.bottom !=lpBand->rcBand.bottom)) {
659 lpBand->fDraw |= NTF_INVALIDATE;
660 TRACE("band %d row=%d: changed to (%d,%d)-(%d,%d) from (%d,%d)-(%d,%d)\n",
661 i, lpBand->iRow,
662 lpBand->rcBand.left, lpBand->rcBand.top,
663 lpBand->rcBand.right, lpBand->rcBand.bottom,
664 lpBand->rcoldBand.left, lpBand->rcoldBand.top,
665 lpBand->rcoldBand.right, lpBand->rcoldBand.bottom);
667 else
668 TRACE("band %d row=%d: unchanged (%d,%d)-(%d,%d)\n",
669 i, lpBand->iRow,
670 lpBand->rcBand.left, lpBand->rcBand.top,
671 lpBand->rcBand.right, lpBand->rcBand.bottom);
676 static void
677 REBAR_AdjustBands (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
678 INT maxx, INT mcy)
679 /* Function: This routine distributes the extra space in a row. */
680 /* See algorithm below. */
681 /* On entry: */
682 /* all bands @ ->cxHeader size */
683 /* start and end bands are *not* hidden */
685 REBAR_BAND *lpBand;
686 UINT x, xsep, extra, curwidth, fudge;
687 INT i, last_adjusted;
689 TRACE("start=%u, end=%u, max x=%d, max y=%d\n",
690 rowstart, rowend, maxx, mcy);
692 /* ******************* Phase 1 ************************ */
693 /* Alg: */
694 /* For each visible band with valid child */
695 /* a. inflate band till either all extra space used */
696 /* or band's ->ccx reached. */
697 /* If any band modified, add any space left to last band */
698 /* adjusted. */
699 /* */
700 /* ****************************************************** */
701 lpBand = &infoPtr->bands[rowend];
702 extra = maxx - rcBrb(lpBand);
703 x = 0;
704 last_adjusted = -1;
705 for (i=(INT)rowstart; i<=(INT)rowend; i++) {
706 lpBand = &infoPtr->bands[i];
707 if (HIDDENBAND(lpBand)) continue;
708 xsep = (x == 0) ? 0 : SEP_WIDTH;
709 curwidth = rcBw(lpBand);
711 /* set new left/top point */
712 if (infoPtr->dwStyle & CCS_VERT)
713 lpBand->rcBand.top = x + xsep;
714 else
715 lpBand->rcBand.left = x + xsep;
717 /* compute new width */
718 if ((lpBand->hwndChild && extra) && !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
719 /* set to the "current" band size less the header */
720 fudge = lpBand->ccx;
721 last_adjusted = i;
722 if ((lpBand->fMask & RBBIM_SIZE) && (lpBand->cx > 0) &&
723 (fudge > curwidth)) {
724 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d, extra=%d\n",
725 i, fudge-curwidth, fudge, curwidth, extra);
726 if ((fudge - curwidth) > extra)
727 fudge = curwidth + extra;
728 extra -= (fudge - curwidth);
729 curwidth = fudge;
731 else {
732 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d\n",
733 i, extra, fudge, curwidth);
734 curwidth += extra;
735 extra = 0;
739 /* set new right/bottom point */
740 if (infoPtr->dwStyle & CCS_VERT)
741 lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
742 else
743 lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
744 TRACE("Phase 1 band %d, (%d,%d)-(%d,%d), orig x=%d, xsep=%d\n",
745 i, lpBand->rcBand.left, lpBand->rcBand.top,
746 lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
747 x = rcBrb(lpBand);
749 if ((x >= maxx) || (last_adjusted != -1)) {
750 if (x > maxx) {
751 ERR("Phase 1 failed, x=%d, maxx=%d, start=%u, end=%u\n",
752 x, maxx, rowstart, rowend);
754 /* done, so spread extra space */
755 if (x < maxx) {
756 fudge = maxx - x;
757 TRACE("Need to spread %d on last adjusted band %d\n",
758 fudge, last_adjusted);
759 for (i=(INT)last_adjusted; i<=(INT)rowend; i++) {
760 lpBand = &infoPtr->bands[i];
761 if (HIDDENBAND(lpBand)) continue;
763 /* set right/bottom point */
764 if (i != last_adjusted) {
765 if (infoPtr->dwStyle & CCS_VERT)
766 lpBand->rcBand.top += fudge;
767 else
768 lpBand->rcBand.left += fudge;
771 /* set left/bottom point */
772 if (infoPtr->dwStyle & CCS_VERT)
773 lpBand->rcBand.bottom += fudge;
774 else
775 lpBand->rcBand.right += fudge;
778 TRACE("Phase 1 succeeded, used x=%d\n", x);
779 REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
780 return;
783 /* ******************* Phase 2 ************************ */
784 /* Alg: */
785 /* Find first visible band, put all */
786 /* extra space there. */
787 /* */
788 /* ****************************************************** */
790 x = 0;
791 for (i=(INT)rowstart; i<=(INT)rowend; i++) {
792 lpBand = &infoPtr->bands[i];
793 if (HIDDENBAND(lpBand)) continue;
794 xsep = (x == 0) ? 0 : SEP_WIDTH;
795 curwidth = rcBw(lpBand);
797 /* set new left/top point */
798 if (infoPtr->dwStyle & CCS_VERT)
799 lpBand->rcBand.top = x + xsep;
800 else
801 lpBand->rcBand.left = x + xsep;
803 /* compute new width */
804 if (extra) {
805 curwidth += extra;
806 extra = 0;
809 /* set new right/bottom point */
810 if (infoPtr->dwStyle & CCS_VERT)
811 lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
812 else
813 lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
814 TRACE("Phase 2 band %d, (%d,%d)-(%d,%d), orig x=%d, xsep=%d\n",
815 i, lpBand->rcBand.left, lpBand->rcBand.top,
816 lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
817 x = rcBrb(lpBand);
819 if (x >= maxx) {
820 if (x > maxx) {
821 ERR("Phase 2 failed, x=%d, maxx=%d, start=%u, end=%u\n",
822 x, maxx, rowstart, rowend);
824 /* done, so spread extra space */
825 TRACE("Phase 2 succeeded, used x=%d\n", x);
826 REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
827 return;
830 /* ******************* Phase 3 ************************ */
831 /* at this point everything is back to ->cxHeader values */
832 /* and should not have gotten here. */
833 /* ****************************************************** */
835 lpBand = &infoPtr->bands[rowstart];
836 ERR("Serious problem adjusting row %d, start band %d, end band %d\n",
837 lpBand->iRow, rowstart, rowend);
838 REBAR_DumpBand (infoPtr);
839 return;
843 static void
844 REBAR_CalcHorzBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
845 /* Function: this routine initializes all the rectangles in */
846 /* each band in a row to fit in the adjusted rcBand rect. */
847 /* *** Supports only Horizontal bars. *** */
849 REBAR_BAND *lpBand;
850 UINT i, xoff, yoff;
851 HWND parenthwnd;
852 RECT oldChild, work;
854 /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
855 parenthwnd = GetParent (infoPtr->hwndSelf);
857 for(i=rstart; i<rend; i++){
858 lpBand = &infoPtr->bands[i];
859 if (HIDDENBAND(lpBand)) {
860 SetRect (&lpBand->rcChild,
861 lpBand->rcBand.right, lpBand->rcBand.top,
862 lpBand->rcBand.right, lpBand->rcBand.bottom);
863 continue;
866 oldChild = lpBand->rcChild;
868 /* set initial gripper rectangle */
869 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
870 lpBand->rcBand.left, lpBand->rcBand.bottom);
872 /* calculate gripper rectangle */
873 if ( lpBand->fStatus & HAS_GRIPPER) {
874 lpBand->fDraw |= DRAW_GRIPPER;
875 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
876 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
877 lpBand->rcGripper.top += 2;
878 lpBand->rcGripper.bottom -= 2;
880 SetRect (&lpBand->rcCapImage,
881 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
882 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
884 else { /* no gripper will be drawn */
885 xoff = 0;
886 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
887 /* if no gripper but either image or text, then leave space */
888 xoff = REBAR_ALWAYS_SPACE;
889 SetRect (&lpBand->rcCapImage,
890 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
891 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
894 /* image is visible */
895 if (lpBand->fStatus & HAS_IMAGE) {
896 lpBand->fDraw |= DRAW_IMAGE;
897 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
898 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
900 /* set initial caption text rectangle */
901 SetRect (&lpBand->rcCapText,
902 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
903 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
904 /* update band height
905 if (lpBand->uMinHeight < infoPtr->imageSize.cy + 2) {
906 lpBand->uMinHeight = infoPtr->imageSize.cy + 2;
907 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->uMinHeight;
908 } */
910 else {
911 /* set initial caption text rectangle */
912 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
913 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
916 /* text is visible */
917 if (lpBand->fStatus & HAS_TEXT) {
918 lpBand->fDraw |= DRAW_TEXT;
919 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
920 lpBand->rcCapText.right-REBAR_POST_TEXT);
923 /* set initial child window rectangle if there is a child */
924 if (lpBand->fMask & RBBIM_CHILD) {
925 xoff = lpBand->offChild.cx;
926 yoff = lpBand->offChild.cy;
927 SetRect (&lpBand->rcChild,
928 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top+yoff,
929 lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
931 else {
932 SetRect (&lpBand->rcChild,
933 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
934 lpBand->rcBand.right, lpBand->rcBand.bottom);
937 /* flag if notify required and invalidate rectangle */
938 if (notify &&
939 ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
940 (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
941 TRACE("Child rectangle changed for band %u\n", i);
942 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
943 oldChild.left, oldChild.top,
944 oldChild.right, oldChild.bottom,
945 lpBand->rcChild.left, lpBand->rcChild.top,
946 lpBand->rcChild.right, lpBand->rcChild.bottom);
948 if (lpBand->fDraw & NTF_INVALIDATE) {
949 TRACE("invalidating (%d,%d)-(%d,%d)\n",
950 lpBand->rcBand.left,
951 lpBand->rcBand.top,
952 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0),
953 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0));
954 lpBand->fDraw &= ~NTF_INVALIDATE;
955 work = lpBand->rcBand;
956 if (lpBand->fDraw & DRAW_RIGHTSEP) work.right += SEP_WIDTH_SIZE;
957 if (lpBand->fDraw & DRAW_BOTTOMSEP) work.bottom += SEP_WIDTH_SIZE;
958 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
966 static VOID
967 REBAR_CalcVertBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
968 /* Function: this routine initializes all the rectangles in */
969 /* each band in a row to fit in the adjusted rcBand rect. */
970 /* *** Supports only Vertical bars. *** */
972 REBAR_BAND *lpBand;
973 UINT i, xoff, yoff;
974 HWND parenthwnd;
975 RECT oldChild, work;
977 /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
978 parenthwnd = GetParent (infoPtr->hwndSelf);
980 for(i=rstart; i<rend; i++){
981 lpBand = &infoPtr->bands[i];
982 if (HIDDENBAND(lpBand)) continue;
983 oldChild = lpBand->rcChild;
985 /* set initial gripper rectangle */
986 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
987 lpBand->rcBand.right, lpBand->rcBand.top);
989 /* calculate gripper rectangle */
990 if (lpBand->fStatus & HAS_GRIPPER) {
991 lpBand->fDraw |= DRAW_GRIPPER;
993 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
994 /* vertical gripper */
995 lpBand->rcGripper.left += 3;
996 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
997 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
998 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
1000 /* initialize Caption image rectangle */
1001 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1002 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1003 lpBand->rcBand.right,
1004 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1006 else {
1007 /* horizontal gripper */
1008 lpBand->rcGripper.left += 2;
1009 lpBand->rcGripper.right -= 2;
1010 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
1011 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
1013 /* initialize Caption image rectangle */
1014 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1015 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1016 lpBand->rcBand.right,
1017 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1020 else { /* no gripper will be drawn */
1021 xoff = 0;
1022 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
1023 /* if no gripper but either image or text, then leave space */
1024 xoff = REBAR_ALWAYS_SPACE;
1025 /* initialize Caption image rectangle */
1026 SetRect (&lpBand->rcCapImage,
1027 lpBand->rcBand.left, lpBand->rcBand.top+xoff,
1028 lpBand->rcBand.right, lpBand->rcBand.top+xoff);
1031 /* image is visible */
1032 if (lpBand->fStatus & HAS_IMAGE) {
1033 lpBand->fDraw |= DRAW_IMAGE;
1035 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
1036 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
1038 /* set initial caption text rectangle */
1039 SetRect (&lpBand->rcCapText,
1040 lpBand->rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
1041 lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1042 /* update band height *
1043 if (lpBand->uMinHeight < infoPtr->imageSize.cx + 2) {
1044 lpBand->uMinHeight = infoPtr->imageSize.cx + 2;
1045 lpBand->rcBand.right = lpBand->rcBand.left + lpBand->uMinHeight;
1046 } */
1048 else {
1049 /* set initial caption text rectangle */
1050 SetRect (&lpBand->rcCapText,
1051 lpBand->rcBand.left, lpBand->rcCapImage.bottom,
1052 lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1055 /* text is visible */
1056 if (lpBand->fStatus & HAS_TEXT) {
1057 lpBand->fDraw |= DRAW_TEXT;
1058 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
1059 lpBand->rcCapText.bottom);
1062 /* set initial child window rectangle if there is a child */
1063 if (lpBand->fMask & RBBIM_CHILD) {
1064 yoff = lpBand->offChild.cx;
1065 xoff = lpBand->offChild.cy;
1066 SetRect (&lpBand->rcChild,
1067 lpBand->rcBand.left+xoff, lpBand->rcBand.top+lpBand->cxHeader,
1068 lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
1070 else {
1071 SetRect (&lpBand->rcChild,
1072 lpBand->rcBand.left, lpBand->rcBand.top+lpBand->cxHeader,
1073 lpBand->rcBand.right, lpBand->rcBand.bottom);
1076 /* flag if notify required and invalidate rectangle */
1077 if (notify &&
1078 ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
1079 (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
1080 TRACE("Child rectangle changed for band %u\n", i);
1081 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
1082 oldChild.left, oldChild.top,
1083 oldChild.right, oldChild.bottom,
1084 lpBand->rcChild.left, lpBand->rcChild.top,
1085 lpBand->rcChild.right, lpBand->rcChild.bottom);
1087 if (lpBand->fDraw & NTF_INVALIDATE) {
1088 TRACE("invalidating (%d,%d)-(%d,%d)\n",
1089 lpBand->rcBand.left,
1090 lpBand->rcBand.top,
1091 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0),
1092 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0));
1093 lpBand->fDraw &= ~NTF_INVALIDATE;
1094 work = lpBand->rcBand;
1095 if (lpBand->fDraw & DRAW_RIGHTSEP) work.bottom += SEP_WIDTH_SIZE;
1096 if (lpBand->fDraw & DRAW_BOTTOMSEP) work.right += SEP_WIDTH_SIZE;
1097 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
1104 static VOID
1105 REBAR_ForceResize (REBAR_INFO *infoPtr)
1106 /* Function: This changes the size of the REBAR window to that */
1107 /* calculated by REBAR_Layout. */
1109 RECT rc;
1110 INT x, y, width, height;
1111 INT xedge = GetSystemMetrics(SM_CXEDGE);
1112 INT yedge = GetSystemMetrics(SM_CYEDGE);
1114 /* TEST TEST TEST */
1115 GetWindowRect (infoPtr->hwndSelf, &rc);
1116 /* END TEST END TEST END TEST */
1119 GetClientRect (infoPtr->hwndSelf, &rc);
1121 TRACE( " old [%ld x %ld], new [%ld x %ld], client [%d x %d]\n",
1122 infoPtr->oldSize.cx, infoPtr->oldSize.cy,
1123 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1124 rc.right, rc.bottom);
1126 /* If we need to shrink client, then skip size test */
1127 if ((infoPtr->calcSize.cy >= rc.bottom) &&
1128 (infoPtr->calcSize.cx >= rc.right)) {
1130 /* if size did not change then skip process */
1131 if ((infoPtr->oldSize.cx == infoPtr->calcSize.cx) &&
1132 (infoPtr->oldSize.cy == infoPtr->calcSize.cy) &&
1133 !(infoPtr->fStatus & RESIZE_ANYHOW))
1135 TRACE("skipping reset\n");
1136 return;
1140 infoPtr->fStatus &= ~RESIZE_ANYHOW;
1141 /* Set flag to ignore next WM_SIZE message */
1142 infoPtr->fStatus |= AUTO_RESIZE;
1144 width = 0;
1145 height = 0;
1146 x = 0;
1147 y = 0;
1149 if (infoPtr->dwStyle & WS_BORDER) {
1150 width = 2 * xedge;
1151 height = 2 * yedge;
1154 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
1155 INT mode = infoPtr->dwStyle & (CCS_VERT | CCS_TOP | CCS_BOTTOM);
1156 RECT rcPcl;
1158 GetClientRect(GetParent(infoPtr->hwndSelf), &rcPcl);
1159 switch (mode) {
1160 case CCS_TOP:
1161 /* _TOP sets width to parents width */
1162 width += (rcPcl.right - rcPcl.left);
1163 height += infoPtr->calcSize.cy;
1164 x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1165 y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1166 y += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1167 break;
1168 case CCS_BOTTOM:
1169 /* FIXME: wrong wrong wrong */
1170 /* _BOTTOM sets width to parents width */
1171 width += (rcPcl.right - rcPcl.left);
1172 height += infoPtr->calcSize.cy;
1173 x += -xedge;
1174 y = rcPcl.bottom - height + 1;
1175 break;
1176 case CCS_LEFT:
1177 /* _LEFT sets height to parents height */
1178 width += infoPtr->calcSize.cx;
1179 height += (rcPcl.bottom - rcPcl.top);
1180 x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1181 x += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1182 y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1183 break;
1184 case CCS_RIGHT:
1185 /* FIXME: wrong wrong wrong */
1186 /* _RIGHT sets height to parents height */
1187 width += infoPtr->calcSize.cx;
1188 height += (rcPcl.bottom - rcPcl.top);
1189 x = rcPcl.right - width + 1;
1190 y = -yedge;
1191 break;
1192 default:
1193 width += infoPtr->calcSize.cx;
1194 height += infoPtr->calcSize.cy;
1197 else {
1198 width += infoPtr->calcSize.cx;
1199 height += infoPtr->calcSize.cy;
1202 TRACE("hwnd %04x, style=%08lx, setting at (%d,%d) for (%d,%d)\n",
1203 infoPtr->hwndSelf, infoPtr->dwStyle,
1204 x, y, width, height);
1205 SetWindowPos (infoPtr->hwndSelf, 0, x, y, width, height,
1206 SWP_NOZORDER);
1210 static VOID
1211 REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
1213 REBAR_BAND *lpBand;
1214 CHAR szClassName[40];
1215 UINT i;
1216 NMREBARCHILDSIZE rbcz;
1217 NMHDR heightchange;
1218 HDWP deferpos;
1220 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1221 ERR("BeginDeferWindowPos returned NULL\n");
1223 for (i = start; i < endplus; i++) {
1224 lpBand = &infoPtr->bands[i];
1226 if (HIDDENBAND(lpBand)) continue;
1227 if (lpBand->hwndChild) {
1228 TRACE("hwndChild = %x\n", lpBand->hwndChild);
1230 /* Always geterate the RBN_CHILDSIZE even it child
1231 did not change */
1232 rbcz.uBand = i;
1233 rbcz.wID = lpBand->wID;
1234 rbcz.rcChild = lpBand->rcChild;
1235 rbcz.rcBand = lpBand->rcBand;
1236 rbcz.rcBand.left += lpBand->cxHeader;
1237 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1238 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1239 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1240 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
1241 lpBand->rcChild.left, lpBand->rcChild.top,
1242 lpBand->rcChild.right, lpBand->rcChild.bottom,
1243 rbcz.rcChild.left, rbcz.rcChild.top,
1244 rbcz.rcChild.right, rbcz.rcChild.bottom);
1245 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1248 /* native (IE4 in "Favorites" frame **1) does:
1249 * SetRect (&rc, -1, -1, -1, -1)
1250 * EqualRect (&rc,band->rc???)
1251 * if ret==0
1252 * CopyRect (band->rc????, &rc)
1253 * set flag outside of loop
1256 GetClassNameA (lpBand->hwndChild, szClassName, 40);
1257 if (!lstrcmpA (szClassName, "ComboBox") ||
1258 !lstrcmpA (szClassName, WC_COMBOBOXEXA)) {
1259 INT nEditHeight, yPos;
1260 RECT rc;
1262 /* special placement code for combo or comboex box */
1265 /* get size of edit line */
1266 GetWindowRect (lpBand->hwndChild, &rc);
1267 nEditHeight = rc.bottom - rc.top;
1268 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1270 /* center combo box inside child area */
1271 TRACE("moving child (Combo(Ex)) %04x to (%d,%d) for (%d,%d)\n",
1272 lpBand->hwndChild,
1273 lpBand->rcChild.left, yPos,
1274 lpBand->rcChild.right - lpBand->rcChild.left,
1275 nEditHeight);
1276 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1277 lpBand->rcChild.left,
1278 /*lpBand->rcChild.top*/ yPos,
1279 lpBand->rcChild.right - lpBand->rcChild.left,
1280 nEditHeight,
1281 SWP_NOZORDER);
1282 if (!deferpos)
1283 ERR("DeferWindowPos returned NULL\n");
1285 else {
1286 TRACE("moving child (Other) %04x to (%d,%d) for (%d,%d)\n",
1287 lpBand->hwndChild,
1288 lpBand->rcChild.left, lpBand->rcChild.top,
1289 lpBand->rcChild.right - lpBand->rcChild.left,
1290 lpBand->rcChild.bottom - lpBand->rcChild.top);
1291 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1292 lpBand->rcChild.left,
1293 lpBand->rcChild.top,
1294 lpBand->rcChild.right - lpBand->rcChild.left,
1295 lpBand->rcChild.bottom - lpBand->rcChild.top,
1296 SWP_NOZORDER);
1297 if (!deferpos)
1298 ERR("DeferWindowPos returned NULL\n");
1302 if (!EndDeferWindowPos(deferpos))
1303 ERR("EndDeferWindowPos returned NULL\n");
1305 UpdateWindow (infoPtr->hwndSelf);
1307 if (infoPtr->fStatus & NTF_HGHTCHG) {
1308 infoPtr->fStatus &= ~NTF_HGHTCHG;
1309 REBAR_Notify (&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1312 /* native (from **1 above) does:
1313 * UpdateWindow(rebar)
1314 * REBAR_ForceResize
1315 * RBN_HEIGHTCHANGE if necessary
1316 * if ret from any EqualRect was 0
1317 * Goto "BeginDeferWindowPos"
1323 static VOID
1324 REBAR_Layout (REBAR_INFO *infoPtr, LPRECT lpRect, BOOL notify, BOOL resetclient)
1325 /* Function: This routine is resposible for laying out all */
1326 /* the bands in a rebar. It assigns each band to a row and*/
1327 /* determines when to start a new row. */
1329 REBAR_BAND *lpBand, *prevBand;
1330 RECT rcClient, rcAdj;
1331 INT initx, inity, x, y, cx, cxsep, mmcy, mcy, clientcx, clientcy;
1332 INT adjcx, adjcy, row, rightx, bottomy, origheight;
1333 UINT i, j, rowstart, origrows, cntonrow;
1334 BOOL dobreak;
1336 if (!(infoPtr->fStatus & BAND_NEEDS_LAYOUT)) {
1337 TRACE("no layout done. No band changed.\n");
1338 REBAR_DumpBand (infoPtr);
1339 return;
1341 infoPtr->fStatus &= ~BAND_NEEDS_LAYOUT;
1342 if (!infoPtr->DoRedraw) infoPtr->fStatus |= BAND_NEEDS_REDRAW;
1344 GetClientRect (infoPtr->hwndSelf, &rcClient);
1345 TRACE("Client is (%d,%d)-(%d,%d)\n",
1346 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
1348 if (lpRect) {
1349 rcAdj = *lpRect;
1350 TRACE("adjustment rect is (%d,%d)-(%d,%d)\n",
1351 rcAdj.left, rcAdj.top, rcAdj.right, rcAdj.bottom);
1353 else {
1354 CopyRect (&rcAdj, &rcClient);
1357 clientcx = rcClient.right - rcClient.left;
1358 clientcy = rcClient.bottom - rcClient.top;
1359 adjcx = rcAdj.right - rcAdj.left;
1360 adjcy = rcAdj.bottom - rcAdj.top;
1361 if (resetclient) {
1362 TRACE("window client rect will be set to adj rect\n");
1363 clientcx = adjcx;
1364 clientcy = adjcy;
1367 if (!infoPtr->DoRedraw && (clientcx == 0) && (clientcy == 0)) {
1368 ERR("no redraw and client is zero, skip layout\n");
1369 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1370 return;
1373 /* save height of original control */
1374 if (infoPtr->dwStyle & CCS_VERT)
1375 origheight = infoPtr->calcSize.cx;
1376 else
1377 origheight = infoPtr->calcSize.cy;
1378 origrows = infoPtr->uNumRows;
1380 initx = 0;
1381 inity = 0;
1383 /* ******* Start Phase 1 - all bands on row at minimum size ******* */
1385 TRACE("band loop constants, clientcx=%d, clientcy=%d, adjcx=%d, adjcy=%d\n",
1386 clientcx, clientcy, adjcx, adjcy);
1387 x = initx;
1388 y = inity;
1389 row = 1;
1390 cx = 0;
1391 mcy = 0;
1392 rowstart = 0;
1393 prevBand = NULL;
1394 cntonrow = 0;
1396 for (i = 0; i < infoPtr->uNumBands; i++) {
1397 lpBand = &infoPtr->bands[i];
1398 lpBand->fDraw = 0;
1399 lpBand->iRow = row;
1401 if (HIDDENBAND(lpBand)) continue;
1403 lpBand->rcoldBand = lpBand->rcBand;
1405 /* Set the offset of the child window */
1406 if ((lpBand->fMask & RBBIM_CHILD) &&
1407 !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
1408 lpBand->offChild.cx = 4; /* ??? */
1410 lpBand->offChild.cy = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 2 : 0);
1412 /* separator from previous band */
1413 cxsep = (cntonrow == 0) ? 0 : SEP_WIDTH;
1415 /* Header: includes gripper, text, image */
1416 cx = lpBand->cxHeader;
1417 if (lpBand->fStyle & RBBS_FIXEDSIZE) cx = lpBand->lcx;
1419 if (infoPtr->dwStyle & CCS_VERT)
1420 dobreak = (y + cx + cxsep > adjcy);
1421 else
1422 dobreak = (x + cx + cxsep > adjcx);
1424 /* This is the check for whether we need to start a new row */
1425 if ( ( (lpBand->fStyle & RBBS_BREAK) && (i != 0) ) ||
1426 ( ((infoPtr->dwStyle & CCS_VERT) ? (y != 0) : (x != 0)) && dobreak)) {
1428 for (j = rowstart; j < i; j++) {
1429 REBAR_BAND *lpB;
1430 lpB = &infoPtr->bands[j];
1431 if (infoPtr->dwStyle & CCS_VERT) {
1432 lpB->rcBand.right = lpB->rcBand.left + mcy;
1434 else {
1435 lpB->rcBand.bottom = lpB->rcBand.top + mcy;
1439 TRACE("P1 Spliting to new row %d on band %u\n", row+1, i);
1440 if (infoPtr->dwStyle & CCS_VERT) {
1441 y = inity;
1442 x += (mcy + SEP_WIDTH);
1444 else {
1445 x = initx;
1446 y += (mcy + SEP_WIDTH);
1449 mcy = 0;
1450 cxsep = 0;
1451 row++;
1452 lpBand->iRow = row;
1453 prevBand = NULL;
1454 rowstart = i;
1455 cntonrow = 0;
1458 if (mcy < lpBand->lcy + REBARSPACE(lpBand))
1459 mcy = lpBand->lcy + REBARSPACE(lpBand);
1461 /* if boundary rect specified then limit mcy */
1462 if (lpRect) {
1463 if (infoPtr->dwStyle & CCS_VERT) {
1464 if (x+mcy > adjcx) {
1465 mcy = adjcx - x;
1466 TRACE("P1 row %u limiting mcy=%d, adjcx=%d, x=%d\n",
1467 i, mcy, adjcx, x);
1470 else {
1471 if (y+mcy > adjcy) {
1472 mcy = adjcy - y;
1473 TRACE("P1 row %u limiting mcy=%d, adjcy=%d, y=%d\n",
1474 i, mcy, adjcy, y);
1479 TRACE("P1 band %u, row %d, x=%d, y=%d, cxsep=%d, cx=%d\n",
1480 i, row,
1481 x, y, cxsep, cx);
1482 if (infoPtr->dwStyle & CCS_VERT) {
1483 /* bound the bottom side if we have a bounding rectangle */
1484 rightx = clientcx;
1485 bottomy = (lpRect) ? min(clientcy, y+cxsep+cx) : y+cxsep+cx;
1486 lpBand->rcBand.left = x;
1487 lpBand->rcBand.right = x + min(mcy,
1488 lpBand->lcy+REBARSPACE(lpBand));
1489 lpBand->rcBand.top = min(bottomy, y + cxsep);
1490 lpBand->rcBand.bottom = bottomy;
1491 lpBand->uMinHeight = lpBand->lcy;
1492 y = bottomy;
1494 else {
1495 /* bound the right side if we have a bounding rectangle */
1496 rightx = (lpRect) ? min(clientcx, x+cxsep+cx) : x+cxsep+cx;
1497 bottomy = clientcy;
1498 lpBand->rcBand.left = min(rightx, x + cxsep);
1499 lpBand->rcBand.right = rightx;
1500 lpBand->rcBand.top = y;
1501 lpBand->rcBand.bottom = y + min(mcy,
1502 lpBand->lcy+REBARSPACE(lpBand));
1503 lpBand->uMinHeight = lpBand->lcy;
1504 x = rightx;
1506 TRACE("P1 band %u, row %d, (%d,%d)-(%d,%d)\n",
1507 i, row,
1508 lpBand->rcBand.left, lpBand->rcBand.top,
1509 lpBand->rcBand.right, lpBand->rcBand.bottom);
1510 prevBand = lpBand;
1511 cntonrow++;
1513 } /* for (i = 0; i < infoPtr->uNumBands... */
1515 if (infoPtr->dwStyle & CCS_VERT)
1516 x += mcy;
1517 else
1518 y += mcy;
1520 for (j = rowstart; j < infoPtr->uNumBands; j++) {
1521 lpBand = &infoPtr->bands[j];
1522 if (infoPtr->dwStyle & CCS_VERT) {
1523 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
1525 else {
1526 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
1530 if (infoPtr->uNumBands)
1531 infoPtr->uNumRows = row;
1533 /* ******* End Phase 1 - all bands on row at minimum size ******* */
1536 /* ******* Start Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1538 mmcy = 0;
1539 if (!(infoPtr->dwStyle & RBS_VARHEIGHT)) {
1540 INT xy;
1542 /* get the max height of all bands */
1543 for (i=0; i<infoPtr->uNumBands; i++) {
1544 lpBand = &infoPtr->bands[i];
1545 if (HIDDENBAND(lpBand)) continue;
1546 if (infoPtr->dwStyle & CCS_VERT)
1547 mmcy = max(mmcy, lpBand->rcBand.right - lpBand->rcBand.left);
1548 else
1549 mmcy = max(mmcy, lpBand->rcBand.bottom - lpBand->rcBand.top);
1552 /* now adjust all rectangles by using the height found above */
1553 xy = 0;
1554 row = 1;
1555 for (i=0; i<infoPtr->uNumBands; i++) {
1556 lpBand = &infoPtr->bands[i];
1557 if (HIDDENBAND(lpBand)) continue;
1558 if (lpBand->iRow != row)
1559 xy += (mmcy + SEP_WIDTH);
1560 if (infoPtr->dwStyle & CCS_VERT) {
1561 lpBand->rcBand.left = xy;
1562 lpBand->rcBand.right = xy + mmcy;
1564 else {
1565 lpBand->rcBand.top = xy;
1566 lpBand->rcBand.bottom = xy + mmcy;
1570 /* set the x/y values to the correct maximum */
1571 if (infoPtr->dwStyle & CCS_VERT)
1572 x = xy + mmcy;
1573 else
1574 y = xy + mmcy;
1577 /* ******* End Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1580 /* ******* Start Phase 2 - split rows till adjustment height full ******* */
1582 /* assumes that the following variables contain: */
1583 /* y/x current height/width of all rows */
1584 if (lpRect) {
1585 INT i, j, prev_rh, new_rh, adj_rh, prev_idx, current_idx;
1586 REBAR_BAND *prev, *current, *walk;
1588 /* FIXME: problem # 2 */
1589 if (((infoPtr->dwStyle & CCS_VERT) ?
1590 #if PROBLEM2
1591 (x < adjcx) : (y < adjcy)
1592 #else
1593 (adjcx - x > 4) : (adjcy - y > 4)
1594 #endif
1595 ) &&
1596 (infoPtr->uNumBands > 1)) {
1597 for (i=(INT)infoPtr->uNumBands-2; i>=0; i--) {
1598 TRACE("P2 adjcx=%d, adjcy=%d, x=%d, y=%d\n",
1599 adjcx, adjcy, x, y);
1601 /* find the current band (starts at i+1) */
1602 current = &infoPtr->bands[i+1];
1603 current_idx = i+1;
1604 while (HIDDENBAND(current)) {
1605 i--;
1606 if (i < 0) break; /* out of bands */
1607 current = &infoPtr->bands[i+1];
1608 current_idx = i+1;
1610 if (i < 0) break; /* out of bands */
1612 /* now find the prev band (starts at i) */
1613 prev = &infoPtr->bands[i];
1614 prev_idx = i;
1615 while (HIDDENBAND(prev)) {
1616 i--;
1617 if (i < 0) break; /* out of bands */
1618 prev = &infoPtr->bands[i];
1619 prev_idx = i;
1621 if (i < 0) break; /* out of bands */
1623 prev_rh = ircBw(prev);
1624 if (prev->iRow == current->iRow) {
1625 new_rh = (infoPtr->dwStyle & RBS_VARHEIGHT) ?
1626 current->lcy + REBARSPACE(current) :
1627 mmcy;
1628 adj_rh = new_rh + SEP_WIDTH;
1629 infoPtr->uNumRows++;
1630 current->fDraw |= NTF_INVALIDATE;
1631 current->iRow++;
1632 if (infoPtr->dwStyle & CCS_VERT) {
1633 current->rcBand.top = inity;
1634 current->rcBand.bottom = clientcy;
1635 current->rcBand.left += (prev_rh + SEP_WIDTH);
1636 current->rcBand.right = current->rcBand.left + new_rh;
1637 x += adj_rh;
1639 else {
1640 current->rcBand.left = initx;
1641 current->rcBand.right = clientcx;
1642 current->rcBand.top += (prev_rh + SEP_WIDTH);
1643 current->rcBand.bottom = current->rcBand.top + new_rh;
1644 y += adj_rh;
1646 TRACE("P2 moving band %d to own row at (%d,%d)-(%d,%d)\n",
1647 current_idx,
1648 current->rcBand.left, current->rcBand.top,
1649 current->rcBand.right, current->rcBand.bottom);
1650 TRACE("P2 prev band %d at (%d,%d)-(%d,%d)\n",
1651 prev_idx,
1652 prev->rcBand.left, prev->rcBand.top,
1653 prev->rcBand.right, prev->rcBand.bottom);
1654 TRACE("P2 values: prev_rh=%d, new_rh=%d, adj_rh=%d\n",
1655 prev_rh, new_rh, adj_rh);
1656 /* for bands below current adjust row # and top/bottom */
1657 for (j = current_idx+1; j<infoPtr->uNumBands; j++) {
1658 walk = &infoPtr->bands[j];
1659 if (HIDDENBAND(walk)) continue;
1660 walk->fDraw |= NTF_INVALIDATE;
1661 walk->iRow++;
1662 if (infoPtr->dwStyle & CCS_VERT) {
1663 walk->rcBand.left += adj_rh;
1664 walk->rcBand.right += adj_rh;
1666 else {
1667 walk->rcBand.top += adj_rh;
1668 walk->rcBand.bottom += adj_rh;
1671 if ((infoPtr->dwStyle & CCS_VERT) ? (x >= adjcx) : (y >= adjcy))
1672 break; /* all done */
1678 /* ******* End Phase 2 - split rows till adjustment height full ******* */
1681 /* ******* Start Phase 2a - create array of start and end ******* */
1682 /* indexes by row */
1684 if (infoPtr->uNumRows != origrows) {
1685 if (infoPtr->rows) COMCTL32_Free (infoPtr->rows);
1686 infoPtr->rows = COMCTL32_Alloc (sizeof (REBAR_ROW) * infoPtr->uNumRows);
1689 row = 0;
1690 for (i = 0; i < infoPtr->uNumBands; i++) {
1691 lpBand = &infoPtr->bands[i];
1692 if (HIDDENBAND(lpBand)) continue;
1694 if (lpBand->iRow > row) {
1695 row++;
1696 infoPtr->rows[row-1].istartband = i;
1698 if (row == 0) {
1699 ERR("P2a bug!!!!!!\n");
1701 infoPtr->rows[row-1].iendband = i;
1704 for (i = 0; i < infoPtr->uNumRows; i++) {
1705 REBAR_ROW *p;
1707 p = &infoPtr->rows[i];
1708 TRACE("P2a row %d, starts %d, ends %d\n",
1709 i+1, p->istartband, p->iendband);
1712 /* ******* End Phase 2a - create array of start and end ******* */
1713 /* indexes by row */
1716 /* ******* Start Phase 2b - adjust all bands for height full ******* */
1717 /* assumes that the following variables contain: */
1718 /* y/x current height/width of all rows */
1719 /* clientcy/clientcx height/width of client area */
1721 if (((infoPtr->dwStyle & CCS_VERT) ? clientcx > x : clientcy > y) &&
1722 infoPtr->uNumBands) {
1723 INT diff, i, iband, j;
1725 diff = (infoPtr->dwStyle & CCS_VERT) ? clientcx - x : clientcy - y;
1726 for (i = infoPtr->uNumRows; i >= 1; i--) {
1727 /* if row has more than 1 band, ignore row */
1728 if (infoPtr->rows[i-1].istartband != infoPtr->rows[i-1].iendband)
1729 continue;
1730 /* point to only band in row */
1731 iband = infoPtr->rows[i-1].istartband;
1732 lpBand = &infoPtr->bands[iband];
1733 if(HIDDENBAND(lpBand)) continue;
1734 if (!(lpBand->fMask & RBBS_VARIABLEHEIGHT)) continue;
1735 if (((INT)lpBand->cyMaxChild < 1) ||
1736 ((INT)lpBand->cyIntegral < 1)) {
1737 if (lpBand->cyMaxChild + lpBand->cyIntegral == 0) continue;
1738 ERR("P2b band %u RBBS_VARIABLEHEIGHT set but cyMax=%d, cyInt=%d\n",
1739 iband, lpBand->cyMaxChild, lpBand->cyIntegral);
1740 continue;
1742 /* j is now the maximum height/width in the client area */
1743 j = ((diff / lpBand->cyIntegral) * lpBand->cyIntegral) +
1744 ircBw(lpBand);
1745 if (j > lpBand->cyMaxChild + REBARSPACE(lpBand))
1746 j = lpBand->cyMaxChild + REBARSPACE(lpBand);
1747 diff -= (j - ircBw(lpBand));
1748 if (infoPtr->dwStyle & CCS_VERT)
1749 lpBand->rcBand.right = lpBand->rcBand.left + j;
1750 else
1751 lpBand->rcBand.bottom = lpBand->rcBand.top + j;
1752 TRACE("P2b band %d, row %d changed to (%d,%d)-(%d,%d)\n",
1753 iband, lpBand->iRow,
1754 lpBand->rcBand.left, lpBand->rcBand.top,
1755 lpBand->rcBand.right, lpBand->rcBand.bottom);
1756 if (diff <= 0) break;
1758 if (diff < 0) {
1759 ERR("P2b allocated more than available, diff=%d\n", diff);
1760 diff = 0;
1762 if (infoPtr->dwStyle & CCS_VERT)
1763 x = clientcx - diff;
1764 else
1765 y = clientcy - diff;
1768 /* ******* End Phase 2b - adjust all bands for height full ******* */
1771 /* ******* Start Phase 3 - adjust all bands for width full ******* */
1773 if (infoPtr->uNumBands) {
1774 REBAR_ROW *p;
1776 /* If RBS_BANDBORDERS set then indicate to draw bottom separator */
1777 /* on all bands in all rows but last row. */
1778 /* Also indicate to draw the right separator for each band in */
1779 /* each row but the rightmost band. */
1780 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1782 for(i = 0; i < infoPtr->uNumRows; i++) {
1783 p = &infoPtr->rows[i];
1784 for (j = p->istartband; j <= p->iendband; j++) {
1785 lpBand = &infoPtr->bands[j];
1786 if (HIDDENBAND(lpBand)) continue;
1787 if (j != p->iendband)
1788 lpBand->fDraw |= DRAW_RIGHTSEP;
1789 if (i != infoPtr->uNumRows-1)
1790 lpBand->fDraw |= DRAW_BOTTOMSEP;
1795 /* Distribute the extra space on the horizontal and adjust */
1796 /* all bands in row to same height. */
1797 for (i=1; i<=infoPtr->uNumRows; i++) {
1798 p = &infoPtr->rows[i-1];
1799 mcy = 0;
1801 TRACE("P3 processing row %d, starting band %d, ending band %d\n",
1802 i, p->istartband, p->iendband);
1804 /* Find the largest height of the bands in the row */
1805 for (j = p->istartband; j <= p->iendband; j++) {
1806 lpBand = &infoPtr->bands[j];
1807 if (HIDDENBAND(lpBand)) continue;
1808 if (mcy < ircBw(lpBand))
1809 mcy = ircBw(lpBand);
1812 REBAR_AdjustBands (infoPtr, p->istartband, p->iendband,
1813 (infoPtr->dwStyle & CCS_VERT) ?
1814 clientcy : clientcx, mcy);
1817 /* Calculate the other rectangles in each band */
1818 if (infoPtr->dwStyle & CCS_VERT) {
1819 REBAR_CalcVertBand (infoPtr, 0, infoPtr->uNumBands,
1820 notify);
1822 else {
1823 REBAR_CalcHorzBand (infoPtr, 0, infoPtr->uNumBands,
1824 notify);
1828 /* ******* End Phase 3 - adjust all bands for width full ******* */
1830 /* now compute size of Rebar itself */
1831 infoPtr->oldSize = infoPtr->calcSize;
1832 if (infoPtr->uNumBands == 0) {
1833 /* we have no bands, so make size the size of client */
1834 x = clientcx;
1835 y = clientcy;
1837 if (infoPtr->dwStyle & CCS_VERT) {
1838 infoPtr->calcSize.cx = x;
1839 infoPtr->calcSize.cy = clientcy;
1840 TRACE("vert, notify=%d, x=%d, origheight=%d\n",
1841 notify, x, origheight);
1842 if (notify && (x != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1844 else {
1845 infoPtr->calcSize.cx = clientcx;
1846 infoPtr->calcSize.cy = y;
1847 TRACE("horz, notify=%d, y=%d, origheight=%d\n",
1848 notify, y, origheight);
1849 if (notify && (y != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1852 REBAR_DumpBand (infoPtr);
1854 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1856 REBAR_ForceResize (infoPtr);
1860 static VOID
1861 REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1862 /* Function: This routine evaluates the band specs supplied */
1863 /* by the user and updates the following 5 fields in */
1864 /* the internal band structure: cxHeader, lcx, lcy, hcx, hcy*/
1866 UINT header=0;
1867 UINT textheight=0;
1868 INT i, nonfixed;
1869 REBAR_BAND *tBand;
1871 lpBand->fStatus = 0;
1872 lpBand->lcx = 0;
1873 lpBand->lcy = 0;
1874 lpBand->ccx = 0;
1875 lpBand->ccy = 0;
1876 lpBand->hcx = 0;
1877 lpBand->hcy = 0;
1879 /* Data comming in from users into the cx... and cy... fields */
1880 /* may be bad, just garbage, because the user never clears */
1881 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1882 /* along if the fields exist in the input area. Here we must */
1883 /* determine if the data is valid. I have no idea how MS does */
1884 /* the validation, but it does because the RB_GETBANDINFO */
1885 /* returns a 0 when I know the sample program passed in an */
1886 /* address. Here I will use the algorithim that if the value */
1887 /* is greater than 65535 then it is bad and replace it with */
1888 /* a zero. Feel free to improve the algorithim. - GA 12/2000 */
1889 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1890 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1891 if (lpBand->cx > 65535) lpBand->cx = 0;
1892 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1893 if (lpBand->cyMaxChild > 65535) lpBand->cyMaxChild = 0;
1894 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1895 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1896 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1898 /* FIXME: probably should only set NEEDS_LAYOUT flag when */
1899 /* values change. Till then always set it. */
1900 TRACE("setting NEEDS_LAYOUT\n");
1901 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1903 /* Header is where the image, text and gripper exist */
1904 /* in the band and preceed the child window. */
1906 /* count number of non-FIXEDSIZE and non-Hidden bands */
1907 nonfixed = 0;
1908 for (i=0; i<infoPtr->uNumBands; i++){
1909 tBand = &infoPtr->bands[i];
1910 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1911 nonfixed++;
1914 /* calculate gripper rectangle */
1915 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1916 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1917 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1919 lpBand->fStatus |= HAS_GRIPPER;
1920 if (infoPtr->dwStyle & CCS_VERT)
1921 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1922 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1923 else
1924 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1925 else
1926 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1927 /* Always have 4 pixels before anything else */
1928 header += REBAR_ALWAYS_SPACE;
1931 /* image is visible */
1932 if ((lpBand->fMask & RBBIM_IMAGE) && (infoPtr->himl)) {
1933 lpBand->fStatus |= HAS_IMAGE;
1934 if (infoPtr->dwStyle & CCS_VERT) {
1935 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1936 lpBand->lcy = infoPtr->imageSize.cx + 2;
1938 else {
1939 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1940 lpBand->lcy = infoPtr->imageSize.cy + 2;
1944 /* text is visible */
1945 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText)) {
1946 HDC hdc = GetDC (0);
1947 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1948 SIZE size;
1950 lpBand->fStatus |= HAS_TEXT;
1951 GetTextExtentPoint32W (hdc, lpBand->lpText,
1952 lstrlenW (lpBand->lpText), &size);
1953 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1954 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1956 SelectObject (hdc, hOldFont);
1957 ReleaseDC (0, hdc);
1960 /* if no gripper but either image or text, then leave space */
1961 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1962 !(lpBand->fStatus & HAS_GRIPPER)) {
1963 header += REBAR_ALWAYS_SPACE;
1966 /* check if user overrode the header value */
1967 if (!(lpBand->fMask & RBBIM_HEADERSIZE))
1968 lpBand->cxHeader = header;
1971 /* Now compute minimum size of child window */
1972 lpBand->offChild.cx = 0;
1973 lpBand->offChild.cy = 0;
1974 lpBand->lcy = textheight;
1975 lpBand->ccy = lpBand->lcy;
1976 if (lpBand->fMask & RBBIM_CHILDSIZE) {
1977 lpBand->lcx = lpBand->cxMinChild;
1979 /* Set the .cy values for CHILDSIZE case */
1980 lpBand->lcy = max(lpBand->lcy, lpBand->cyMinChild);
1981 lpBand->ccy = lpBand->lcy;
1982 lpBand->hcy = lpBand->lcy;
1983 if (lpBand->cyMaxChild != 0xffffffff) {
1984 lpBand->hcy = lpBand->cyMaxChild;
1986 if (lpBand->cyChild != 0xffffffff)
1987 lpBand->ccy = max (lpBand->cyChild, lpBand->lcy);
1989 TRACE("_CHILDSIZE\n");
1991 if (lpBand->fMask & RBBIM_SIZE) {
1992 lpBand->hcx = max (lpBand->cx-lpBand->cxHeader, lpBand->lcx);
1993 TRACE("_SIZE\n");
1995 else
1996 lpBand->hcx = lpBand->lcx;
1997 lpBand->ccx = lpBand->hcx;
1999 /* make ->.cx include header size for _Layout */
2000 lpBand->lcx += lpBand->cxHeader;
2001 lpBand->ccx += lpBand->cxHeader;
2002 lpBand->hcx += lpBand->cxHeader;
2006 static void
2007 REBAR_CommonSetupBand (HWND hwnd, LPREBARBANDINFOA lprbbi, REBAR_BAND *lpBand)
2008 /* Function: This routine copies the supplied values from */
2009 /* user input (lprbbi) to the internal band structure. */
2011 lpBand->fMask |= lprbbi->fMask;
2013 if (lprbbi->fMask & RBBIM_STYLE)
2014 lpBand->fStyle = lprbbi->fStyle;
2016 if (lprbbi->fMask & RBBIM_COLORS) {
2017 lpBand->clrFore = lprbbi->clrFore;
2018 lpBand->clrBack = lprbbi->clrBack;
2021 if (lprbbi->fMask & RBBIM_IMAGE)
2022 lpBand->iImage = lprbbi->iImage;
2024 if (lprbbi->fMask & RBBIM_CHILD) {
2025 if (lprbbi->hwndChild) {
2026 lpBand->hwndChild = lprbbi->hwndChild;
2027 lpBand->hwndPrevParent =
2028 SetParent (lpBand->hwndChild, hwnd);
2029 /* below in trace fro WinRAR */
2030 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
2031 /* above in trace fro WinRAR */
2033 else {
2034 TRACE("child: 0x%x prev parent: 0x%x\n",
2035 lpBand->hwndChild, lpBand->hwndPrevParent);
2036 lpBand->hwndChild = 0;
2037 lpBand->hwndPrevParent = 0;
2041 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2042 lpBand->cxMinChild = lprbbi->cxMinChild;
2043 lpBand->cyMinChild = lprbbi->cyMinChild;
2044 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2045 lpBand->cyChild = lprbbi->cyChild;
2046 lpBand->cyMaxChild = lprbbi->cyMaxChild;
2047 lpBand->cyIntegral = lprbbi->cyIntegral;
2049 else { /* special case - these should be zeroed out since */
2050 /* RBBIM_CHILDSIZE added these in WIN32_IE >= 0x0400 */
2051 lpBand->cyChild = 0;
2052 lpBand->cyMaxChild = 0;
2053 lpBand->cyIntegral = 0;
2057 if (lprbbi->fMask & RBBIM_SIZE)
2058 lpBand->cx = lprbbi->cx;
2060 if (lprbbi->fMask & RBBIM_BACKGROUND)
2061 lpBand->hbmBack = lprbbi->hbmBack;
2063 if (lprbbi->fMask & RBBIM_ID)
2064 lpBand->wID = lprbbi->wID;
2066 /* check for additional data */
2067 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2068 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2069 lpBand->cxIdeal = lprbbi->cxIdeal;
2071 if (lprbbi->fMask & RBBIM_LPARAM)
2072 lpBand->lParam = lprbbi->lParam;
2074 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2075 lpBand->cxHeader = lprbbi->cxHeader;
2079 static LRESULT
2080 REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, RECT *clip)
2081 /* Function: This erases the background rectangle by drawing */
2082 /* each band with its background color (or the default) and */
2083 /* draws each bands right separator if necessary. The row */
2084 /* separators are drawn on the first band of the next row. */
2086 REBAR_BAND *lpBand;
2087 INT i, oldrow;
2088 HDC hdc = (HDC)wParam;
2089 RECT rect;
2090 COLORREF old = CLR_NONE, new;
2092 oldrow = -1;
2093 for(i=0; i<infoPtr->uNumBands; i++) {
2094 lpBand = &infoPtr->bands[i];
2095 if (HIDDENBAND(lpBand)) continue;
2097 /* draw band separator between rows */
2098 if (lpBand->iRow != oldrow) {
2099 oldrow = lpBand->iRow;
2100 if (lpBand->fDraw & DRAW_BOTTOMSEP) {
2101 RECT rcRowSep;
2102 rcRowSep = lpBand->rcBand;
2103 if (infoPtr->dwStyle & CCS_VERT) {
2104 rcRowSep.right += SEP_WIDTH_SIZE;
2105 rcRowSep.bottom = infoPtr->calcSize.cy;
2106 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
2108 else {
2109 rcRowSep.bottom += SEP_WIDTH_SIZE;
2110 rcRowSep.right = infoPtr->calcSize.cx;
2111 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
2113 TRACE ("drawing band separator bottom (%d,%d)-(%d,%d)\n",
2114 rcRowSep.left, rcRowSep.top,
2115 rcRowSep.right, rcRowSep.bottom);
2119 /* draw band separator between bands in a row */
2120 if (lpBand->fDraw & DRAW_RIGHTSEP) {
2121 RECT rcSep;
2122 rcSep = lpBand->rcBand;
2123 if (infoPtr->dwStyle & CCS_VERT) {
2124 rcSep.bottom += SEP_WIDTH_SIZE;
2125 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
2127 else {
2128 rcSep.right += SEP_WIDTH_SIZE;
2129 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
2131 TRACE("drawing band separator right (%d,%d)-(%d,%d)\n",
2132 rcSep.left, rcSep.top, rcSep.right, rcSep.bottom);
2135 /* draw the actual background */
2136 if (lpBand->clrBack != CLR_NONE) {
2137 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
2138 lpBand->clrBack;
2139 #if GLATESTING
2140 /* testing only - make background green to see it */
2141 new = RGB(0,128,0);
2142 #endif
2143 old = SetBkColor (hdc, new);
2146 rect = lpBand->rcBand;
2147 TRACE("%s background color=0x%06lx, band (%d,%d)-(%d,%d), clip (%d,%d)-(%d,%d)\n",
2148 (lpBand->clrBack == CLR_NONE) ? "none" :
2149 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
2150 GetBkColor(hdc),
2151 lpBand->rcBand.left,lpBand->rcBand.top,
2152 lpBand->rcBand.right,lpBand->rcBand.bottom,
2153 clip->left, clip->top,
2154 clip->right, clip->bottom);
2155 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, 0);
2156 if (lpBand->clrBack != CLR_NONE)
2157 SetBkColor (hdc, old);
2159 return TRUE;
2162 static void
2163 REBAR_InternalHitTest (REBAR_INFO *infoPtr, LPPOINT lpPt, UINT *pFlags, INT *pBand)
2165 REBAR_BAND *lpBand;
2166 RECT rect;
2167 INT iCount;
2169 GetClientRect (infoPtr->hwndSelf, &rect);
2171 *pFlags = RBHT_NOWHERE;
2172 if (PtInRect (&rect, *lpPt))
2174 if (infoPtr->uNumBands == 0) {
2175 *pFlags = RBHT_NOWHERE;
2176 if (pBand)
2177 *pBand = -1;
2178 TRACE("NOWHERE\n");
2179 return;
2181 else {
2182 /* somewhere inside */
2183 infoPtr->ihitBand = -1;
2184 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
2185 lpBand = &infoPtr->bands[iCount];
2186 if (HIDDENBAND(lpBand)) continue;
2187 if (PtInRect (&lpBand->rcBand, *lpPt)) {
2188 if (pBand)
2189 *pBand = iCount;
2190 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
2191 *pFlags = RBHT_GRABBER;
2192 infoPtr->ihitBand = iCount;
2193 TRACE("ON GRABBER %d\n", iCount);
2194 return;
2196 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
2197 *pFlags = RBHT_CAPTION;
2198 TRACE("ON CAPTION %d\n", iCount);
2199 return;
2201 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2202 *pFlags = RBHT_CAPTION;
2203 TRACE("ON CAPTION %d\n", iCount);
2204 return;
2206 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2207 *pFlags = RBHT_CLIENT;
2208 TRACE("ON CLIENT %d\n", iCount);
2209 return;
2211 else {
2212 *pFlags = RBHT_NOWHERE;
2213 TRACE("NOWHERE %d\n", iCount);
2214 return;
2219 *pFlags = RBHT_NOWHERE;
2220 if (pBand)
2221 *pBand = -1;
2223 TRACE("NOWHERE\n");
2224 return;
2227 else {
2228 *pFlags = RBHT_NOWHERE;
2229 if (pBand)
2230 *pBand = -1;
2231 TRACE("NOWHERE\n");
2232 return;
2235 TRACE("flags=0x%X\n", *pFlags);
2236 return;
2240 static INT
2241 REBAR_Shrink (REBAR_INFO *infoPtr, REBAR_BAND *band, INT movement, INT i)
2242 /* Function: This attempts to shrink the given band by the */
2243 /* the amount in "movement". A shrink to the left is indi- */
2244 /* cated by "movement" being negative. "i" is merely the */
2245 /* band index for trace messages. */
2247 INT Leadjust, Readjust, avail, ret;
2249 /* Note: a left drag is indicated by "movement" being negative. */
2250 /* Similarly, a right drag is indicated by "movement" */
2251 /* being positive. "movement" should never be 0, but if */
2252 /* it is then the band does not move. */
2254 avail = rcBw(band) - band->lcx;
2256 /* now compute the Left End adjustment factor and Right End */
2257 /* adjustment factor. They may be different if shrinking. */
2258 if (avail <= 0) {
2259 /* if this band is not shrinkable, then just move it */
2260 Leadjust = Readjust = movement;
2261 ret = movement;
2263 else {
2264 if (movement < 0) {
2265 /* Drag to left */
2266 if (avail <= abs(movement)) {
2267 Readjust = movement;
2268 Leadjust = movement + avail;
2269 ret = Leadjust;
2271 else {
2272 Readjust = movement;
2273 Leadjust = 0;
2274 ret = 0;
2277 else {
2278 /* Drag to right */
2279 if (avail <= abs(movement)) {
2280 Leadjust = movement;
2281 Readjust = movement - avail;
2282 ret = Readjust;
2284 else {
2285 Leadjust = movement;
2286 Readjust = 0;
2287 ret = 0;
2292 /* Reasonability Check */
2293 if (rcBlt(band) + Leadjust < 0) {
2294 ERR("adjustment will fail, band %d: left=%d, right=%d, move=%d, rtn=%d\n",
2295 i, Leadjust, Readjust, movement, ret);
2298 LEADJ(band, Leadjust);
2299 READJ(band, Readjust);
2301 TRACE("band %d: left=%d, right=%d, move=%d, rtn=%d, rcBand=(%d,%d)-(%d,%d)\n",
2302 i, Leadjust, Readjust, movement, ret,
2303 band->rcBand.left, band->rcBand.top,
2304 band->rcBand.right, band->rcBand.bottom);
2305 return ret;
2309 static void
2310 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, POINTS *ptsmove)
2311 /* Function: This will implement the functionality of a */
2312 /* Gripper drag within a row. It will not implement "out- */
2313 /* of-row" drags. (They are detected and handled in */
2314 /* REBAR_MouseMove.) */
2315 /* **** FIXME Switching order of bands in a row not **** */
2316 /* **** yet implemented. **** */
2318 REBAR_BAND *hitBand, *band, *mindBand, *maxdBand;
2319 RECT newrect;
2320 INT imindBand = -1, imaxdBand, ihitBand, i, movement;
2321 INT RHeaderSum = 0, LHeaderSum = 0;
2322 INT compress;
2324 /* on first significant mouse movement, issue notify */
2326 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
2327 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
2328 /* Notify returned TRUE - abort drag */
2329 infoPtr->dragStart.x = 0;
2330 infoPtr->dragStart.y = 0;
2331 infoPtr->dragNow = infoPtr->dragStart;
2332 infoPtr->ihitBand = -1;
2333 ReleaseCapture ();
2334 return ;
2336 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
2339 ihitBand = infoPtr->ihitBand;
2340 hitBand = &infoPtr->bands[ihitBand];
2341 imaxdBand = ihitBand; /* to suppress warning message */
2343 /* find all the bands in the row of the one whose Gripper was seized */
2344 for (i=0; i<infoPtr->uNumBands; i++) {
2345 band = &infoPtr->bands[i];
2346 if (HIDDENBAND(band)) continue;
2347 if (band->iRow == hitBand->iRow) {
2348 imaxdBand = i;
2349 if (imindBand == -1) imindBand = i;
2350 /* minimum size of each band is size of header plus */
2351 /* size of minimum child plus offset of child from header plus */
2352 /* a one to separate each band. */
2353 if (i < ihitBand)
2354 LHeaderSum += (band->lcx + SEP_WIDTH);
2355 else
2356 RHeaderSum += (band->lcx + SEP_WIDTH);
2360 if (RHeaderSum) RHeaderSum -= SEP_WIDTH; /* no separator afterlast band */
2362 mindBand = &infoPtr->bands[imindBand];
2363 maxdBand = &infoPtr->bands[imaxdBand];
2365 if (imindBand == imaxdBand) return; /* nothing to drag agains */
2366 if (imindBand == ihitBand) return; /* first band in row, cant drag */
2368 /* limit movement to inside adjustable bands - Left */
2369 if ( (ptsmove->x < mindBand->rcBand.left) ||
2370 (ptsmove->x > maxdBand->rcBand.right) ||
2371 (ptsmove->y < mindBand->rcBand.top) ||
2372 (ptsmove->y > maxdBand->rcBand.bottom))
2373 return; /* should swap bands */
2375 if (infoPtr->dwStyle & CCS_VERT)
2376 movement = ptsmove->y - ((hitBand->rcBand.top+REBAR_PRE_GRIPPER) -
2377 infoPtr->ihitoffset);
2378 else
2379 movement = ptsmove->x - ((hitBand->rcBand.left+REBAR_PRE_GRIPPER) -
2380 infoPtr->ihitoffset);
2381 infoPtr->dragNow = *ptsmove;
2383 TRACE("before: movement=%d (%d,%d), imindBand=%d, ihitBand=%d, imaxdBand=%d, LSum=%d, RSum=%d\n",
2384 movement, ptsmove->x, ptsmove->y, imindBand, ihitBand,
2385 imaxdBand, LHeaderSum, RHeaderSum);
2386 REBAR_DumpBand (infoPtr);
2388 if (movement < 0) {
2390 /* *** Drag left/up *** */
2391 compress = rcBlt(hitBand) - rcBlt(mindBand) -
2392 LHeaderSum;
2393 if (compress < abs(movement)) {
2394 TRACE("limiting left drag, was %d changed to %d\n",
2395 movement, -compress);
2396 movement = -compress;
2399 for (i=ihitBand; i>=imindBand; i--) {
2400 band = &infoPtr->bands[i];
2401 if (HIDDENBAND(band)) continue;
2402 if (i == ihitBand) {
2403 LEADJ(band, movement)
2405 else
2406 movement = REBAR_Shrink (infoPtr, band, movement, i);
2407 band->ccx = rcBw(band);
2410 else {
2411 BOOL first = TRUE;
2413 /* *** Drag right/down *** */
2414 compress = rcBrb(maxdBand) - rcBlt(hitBand) -
2415 RHeaderSum;
2416 if (compress < abs(movement)) {
2417 TRACE("limiting right drag, was %d changed to %d\n",
2418 movement, compress);
2419 movement = compress;
2421 for (i=ihitBand-1; i<=imaxdBand; i++) {
2422 band = &infoPtr->bands[i];
2423 if (HIDDENBAND(band)) continue;
2424 if (first) {
2425 first = FALSE;
2426 READJ(band, movement)
2428 else
2429 movement = REBAR_Shrink (infoPtr, band, movement, i);
2430 band->ccx = rcBw(band);
2434 /* recompute all rectangles */
2435 if (infoPtr->dwStyle & CCS_VERT) {
2436 REBAR_CalcVertBand (infoPtr, imindBand, imaxdBand+1,
2437 FALSE);
2439 else {
2440 REBAR_CalcHorzBand (infoPtr, imindBand, imaxdBand+1,
2441 FALSE);
2444 TRACE("bands after adjustment, see band # %d, %d\n",
2445 imindBand, imaxdBand);
2446 REBAR_DumpBand (infoPtr);
2448 SetRect (&newrect,
2449 mindBand->rcBand.left,
2450 mindBand->rcBand.top,
2451 maxdBand->rcBand.right,
2452 maxdBand->rcBand.bottom);
2454 REBAR_MoveChildWindows (infoPtr, imindBand, imaxdBand+1);
2456 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
2457 UpdateWindow (infoPtr->hwndSelf);
2463 /* << REBAR_BeginDrag >> */
2466 static LRESULT
2467 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2469 UINT uBand = (UINT)wParam;
2470 HWND childhwnd = 0;
2471 REBAR_BAND *lpBand;
2473 if (uBand >= infoPtr->uNumBands)
2474 return FALSE;
2476 TRACE("deleting band %u!\n", uBand);
2477 lpBand = &infoPtr->bands[uBand];
2478 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2480 if (infoPtr->uNumBands == 1) {
2481 TRACE(" simple delete!\n");
2482 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2483 childhwnd = lpBand->hwndChild;
2484 COMCTL32_Free (infoPtr->bands);
2485 infoPtr->bands = NULL;
2486 infoPtr->uNumBands = 0;
2488 else {
2489 REBAR_BAND *oldBands = infoPtr->bands;
2490 TRACE("complex delete! [uBand=%u]\n", uBand);
2492 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2493 childhwnd = lpBand->hwndChild;
2495 infoPtr->uNumBands--;
2496 infoPtr->bands = COMCTL32_Alloc (sizeof (REBAR_BAND) * infoPtr->uNumBands);
2497 if (uBand > 0) {
2498 memcpy (&infoPtr->bands[0], &oldBands[0],
2499 uBand * sizeof(REBAR_BAND));
2502 if (uBand < infoPtr->uNumBands) {
2503 memcpy (&infoPtr->bands[uBand], &oldBands[uBand+1],
2504 (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
2507 COMCTL32_Free (oldBands);
2510 if (childhwnd)
2511 ShowWindow (childhwnd, SW_HIDE);
2513 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2515 /* if only 1 band left the re-validate to possible eliminate gripper */
2516 if (infoPtr->uNumBands == 1)
2517 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2519 TRACE("setting NEEDS_LAYOUT\n");
2520 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
2521 infoPtr->fStatus |= RESIZE_ANYHOW;
2522 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
2524 return TRUE;
2528 /* << REBAR_DragMove >> */
2529 /* << REBAR_EndDrag >> */
2532 static LRESULT
2533 REBAR_GetBandBorders (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2535 LPRECT lpRect = (LPRECT)lParam;
2536 REBAR_BAND *lpBand;
2538 if (!lParam)
2539 return 0;
2540 if ((UINT)wParam >= infoPtr->uNumBands)
2541 return 0;
2543 lpBand = &infoPtr->bands[(UINT)wParam];
2545 /* FIXME - the following values were determined by experimentation */
2546 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2547 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2548 /* difference in size of the control area with and without the */
2549 /* style. - GA */
2550 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2551 if (infoPtr->dwStyle & CCS_VERT) {
2552 lpRect->left = 1;
2553 lpRect->top = lpBand->cxHeader + 4;
2554 lpRect->right = 1;
2555 lpRect->bottom = 0;
2557 else {
2558 lpRect->left = lpBand->cxHeader + 4;
2559 lpRect->top = 1;
2560 lpRect->right = 0;
2561 lpRect->bottom = 1;
2564 else {
2565 lpRect->left = lpBand->cxHeader;
2567 return 0;
2571 inline static LRESULT
2572 REBAR_GetBandCount (REBAR_INFO *infoPtr)
2574 TRACE("band count %u!\n", infoPtr->uNumBands);
2576 return infoPtr->uNumBands;
2580 static LRESULT
2581 REBAR_GetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2583 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2584 REBAR_BAND *lpBand;
2586 if (lprbbi == NULL)
2587 return FALSE;
2588 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
2589 return FALSE;
2590 if ((UINT)wParam >= infoPtr->uNumBands)
2591 return FALSE;
2593 TRACE("index %u\n", (UINT)wParam);
2595 /* copy band information */
2596 lpBand = &infoPtr->bands[(UINT)wParam];
2598 if (lprbbi->fMask & RBBIM_STYLE)
2599 lprbbi->fStyle = lpBand->fStyle;
2601 if (lprbbi->fMask & RBBIM_COLORS) {
2602 lprbbi->clrFore = lpBand->clrFore;
2603 lprbbi->clrBack = lpBand->clrBack;
2604 if (lprbbi->clrBack == CLR_DEFAULT)
2605 lprbbi->clrBack = infoPtr->clrBtnFace;
2608 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2609 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2611 if (!WideCharToMultiByte( CP_ACP, 0, lpBand->lpText, -1,
2612 lprbbi->lpText, lprbbi->cch, NULL, NULL ))
2613 lprbbi->lpText[lprbbi->cch-1] = 0;
2615 else
2616 *lprbbi->lpText = 0;
2619 if (lprbbi->fMask & RBBIM_IMAGE) {
2620 if (lpBand->fMask & RBBIM_IMAGE)
2621 lprbbi->iImage = lpBand->iImage;
2622 else
2623 lprbbi->iImage = -1;
2626 if (lprbbi->fMask & RBBIM_CHILD)
2627 lprbbi->hwndChild = lpBand->hwndChild;
2629 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2630 lprbbi->cxMinChild = lpBand->cxMinChild;
2631 lprbbi->cyMinChild = lpBand->cyMinChild;
2632 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2633 lprbbi->cyChild = lpBand->cyChild;
2634 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2635 lprbbi->cyIntegral = lpBand->cyIntegral;
2639 if (lprbbi->fMask & RBBIM_SIZE)
2640 lprbbi->cx = lpBand->cx;
2642 if (lprbbi->fMask & RBBIM_BACKGROUND)
2643 lprbbi->hbmBack = lpBand->hbmBack;
2645 if (lprbbi->fMask & RBBIM_ID)
2646 lprbbi->wID = lpBand->wID;
2648 /* check for additional data */
2649 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2650 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2651 lprbbi->cxIdeal = lpBand->cxIdeal;
2653 if (lprbbi->fMask & RBBIM_LPARAM)
2654 lprbbi->lParam = lpBand->lParam;
2656 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2657 lprbbi->cxHeader = lpBand->cxHeader;
2660 REBAR_DumpBandInfo (lprbbi);
2662 return TRUE;
2666 static LRESULT
2667 REBAR_GetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2669 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2670 REBAR_BAND *lpBand;
2672 if (lprbbi == NULL)
2673 return FALSE;
2674 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
2675 return FALSE;
2676 if ((UINT)wParam >= infoPtr->uNumBands)
2677 return FALSE;
2679 TRACE("index %u\n", (UINT)wParam);
2681 /* copy band information */
2682 lpBand = &infoPtr->bands[(UINT)wParam];
2684 if (lprbbi->fMask & RBBIM_STYLE)
2685 lprbbi->fStyle = lpBand->fStyle;
2687 if (lprbbi->fMask & RBBIM_COLORS) {
2688 lprbbi->clrFore = lpBand->clrFore;
2689 lprbbi->clrBack = lpBand->clrBack;
2690 if (lprbbi->clrBack == CLR_DEFAULT)
2691 lprbbi->clrBack = infoPtr->clrBtnFace;
2694 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2695 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2696 lstrcpynW (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
2697 else
2698 *lprbbi->lpText = 0;
2701 if (lprbbi->fMask & RBBIM_IMAGE) {
2702 if (lpBand->fMask & RBBIM_IMAGE)
2703 lprbbi->iImage = lpBand->iImage;
2704 else
2705 lprbbi->iImage = -1;
2708 if (lprbbi->fMask & RBBIM_CHILD)
2709 lprbbi->hwndChild = lpBand->hwndChild;
2711 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2712 lprbbi->cxMinChild = lpBand->cxMinChild;
2713 lprbbi->cyMinChild = lpBand->cyMinChild;
2714 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2715 lprbbi->cyChild = lpBand->cyChild;
2716 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2717 lprbbi->cyIntegral = lpBand->cyIntegral;
2721 if (lprbbi->fMask & RBBIM_SIZE)
2722 lprbbi->cx = lpBand->cx;
2724 if (lprbbi->fMask & RBBIM_BACKGROUND)
2725 lprbbi->hbmBack = lpBand->hbmBack;
2727 if (lprbbi->fMask & RBBIM_ID)
2728 lprbbi->wID = lpBand->wID;
2730 /* check for additional data */
2731 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2732 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2733 lprbbi->cxIdeal = lpBand->cxIdeal;
2735 if (lprbbi->fMask & RBBIM_LPARAM)
2736 lprbbi->lParam = lpBand->lParam;
2738 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2739 lprbbi->cxHeader = lpBand->cxHeader;
2742 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
2744 return TRUE;
2748 static LRESULT
2749 REBAR_GetBarHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2751 INT nHeight;
2753 nHeight = (infoPtr->dwStyle & CCS_VERT) ? infoPtr->calcSize.cx : infoPtr->calcSize.cy;
2755 TRACE("height = %d\n", nHeight);
2757 return nHeight;
2761 static LRESULT
2762 REBAR_GetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2764 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
2766 if (lpInfo == NULL)
2767 return FALSE;
2769 if (lpInfo->cbSize < sizeof (REBARINFO))
2770 return FALSE;
2772 TRACE("getting bar info!\n");
2774 if (infoPtr->himl) {
2775 lpInfo->himl = infoPtr->himl;
2776 lpInfo->fMask |= RBIM_IMAGELIST;
2779 return TRUE;
2783 inline static LRESULT
2784 REBAR_GetBkColor (REBAR_INFO *infoPtr)
2786 COLORREF clr = infoPtr->clrBk;
2788 if (clr == CLR_DEFAULT)
2789 clr = infoPtr->clrBtnFace;
2791 TRACE("background color 0x%06lx!\n", clr);
2793 return clr;
2797 /* << REBAR_GetColorScheme >> */
2798 /* << REBAR_GetDropTarget >> */
2801 static LRESULT
2802 REBAR_GetPalette (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2804 FIXME("empty stub!\n");
2806 return 0;
2810 static LRESULT
2811 REBAR_GetRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2813 INT iBand = (INT)wParam;
2814 LPRECT lprc = (LPRECT)lParam;
2815 REBAR_BAND *lpBand;
2817 if ((iBand < 0) && ((UINT)iBand >= infoPtr->uNumBands))
2818 return FALSE;
2819 if (!lprc)
2820 return FALSE;
2822 lpBand = &infoPtr->bands[iBand];
2823 CopyRect (lprc, &lpBand->rcBand);
2825 TRACE("band %d, (%d,%d)-(%d,%d)\n", iBand,
2826 lprc->left, lprc->top, lprc->right, lprc->bottom);
2828 return TRUE;
2832 inline static LRESULT
2833 REBAR_GetRowCount (REBAR_INFO *infoPtr)
2835 TRACE("%u\n", infoPtr->uNumRows);
2837 return infoPtr->uNumRows;
2841 static LRESULT
2842 REBAR_GetRowHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2844 INT iRow = (INT)wParam;
2845 int ret = 0;
2846 int i, j = 0;
2847 REBAR_BAND *lpBand;
2849 for (i=0; i<infoPtr->uNumBands; i++) {
2850 lpBand = &infoPtr->bands[i];
2851 if (HIDDENBAND(lpBand)) continue;
2852 if (lpBand->iRow != iRow) continue;
2853 if (infoPtr->dwStyle & CCS_VERT)
2854 j = lpBand->rcBand.right - lpBand->rcBand.left;
2855 else
2856 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2857 if (j > ret) ret = j;
2860 TRACE("row %d, height %d\n", iRow, ret);
2862 return ret;
2866 inline static LRESULT
2867 REBAR_GetTextColor (REBAR_INFO *infoPtr)
2869 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
2871 return infoPtr->clrText;
2875 inline static LRESULT
2876 REBAR_GetToolTips (REBAR_INFO *infoPtr)
2878 return infoPtr->hwndToolTip;
2882 inline static LRESULT
2883 REBAR_GetUnicodeFormat (REBAR_INFO *infoPtr)
2885 TRACE("%s hwnd=0x%x\n",
2886 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2888 return infoPtr->bUnicode;
2892 inline static LRESULT
2893 REBAR_GetVersion (REBAR_INFO *infoPtr)
2895 TRACE("version %d\n", infoPtr->iVersion);
2896 return infoPtr->iVersion;
2900 static LRESULT
2901 REBAR_HitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2903 LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
2905 if (!lprbht)
2906 return -1;
2908 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2910 return lprbht->iBand;
2914 static LRESULT
2915 REBAR_IdToIndex (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2917 UINT i;
2919 if (infoPtr == NULL)
2920 return -1;
2922 if (infoPtr->uNumBands < 1)
2923 return -1;
2925 for (i = 0; i < infoPtr->uNumBands; i++) {
2926 if (infoPtr->bands[i].wID == (UINT)wParam) {
2927 TRACE("id %u is band %u found!\n", (UINT)wParam, i);
2928 return i;
2932 TRACE("id %u is not found\n", (UINT)wParam);
2933 return -1;
2937 static LRESULT
2938 REBAR_InsertBandA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2940 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2941 UINT uIndex = (UINT)wParam;
2942 REBAR_BAND *lpBand;
2944 if (infoPtr == NULL)
2945 return FALSE;
2946 if (lprbbi == NULL)
2947 return FALSE;
2948 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
2949 return FALSE;
2951 /* trace the index as signed to see the -1 */
2952 TRACE("insert band at %d!\n", (INT)uIndex);
2953 REBAR_DumpBandInfo (lprbbi);
2955 if (infoPtr->uNumBands == 0) {
2956 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
2957 uIndex = 0;
2959 else {
2960 REBAR_BAND *oldBands = infoPtr->bands;
2961 infoPtr->bands =
2962 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
2963 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
2964 uIndex = infoPtr->uNumBands;
2966 /* pre insert copy */
2967 if (uIndex > 0) {
2968 memcpy (&infoPtr->bands[0], &oldBands[0],
2969 uIndex * sizeof(REBAR_BAND));
2972 /* post copy */
2973 if (uIndex < infoPtr->uNumBands - 1) {
2974 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
2975 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
2978 COMCTL32_Free (oldBands);
2981 infoPtr->uNumBands++;
2983 TRACE("index %u!\n", uIndex);
2985 /* initialize band (infoPtr->bands[uIndex])*/
2986 lpBand = &infoPtr->bands[uIndex];
2987 lpBand->fMask = 0;
2988 lpBand->fStatus = 0;
2989 lpBand->clrFore = infoPtr->clrText;
2990 lpBand->clrBack = infoPtr->clrBk;
2991 lpBand->hwndChild = 0;
2992 lpBand->hwndPrevParent = 0;
2994 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2995 lpBand->lpText = NULL;
2996 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2997 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
2998 if (len > 1) {
2999 lpBand->lpText = (LPWSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
3000 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3004 REBAR_ValidateBand (infoPtr, lpBand);
3005 /* On insert of second band, revalidate band 1 to possible add gripper */
3006 if (infoPtr->uNumBands == 2)
3007 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3009 REBAR_DumpBand (infoPtr);
3011 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3012 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3014 return TRUE;
3018 static LRESULT
3019 REBAR_InsertBandW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3021 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3022 UINT uIndex = (UINT)wParam;
3023 REBAR_BAND *lpBand;
3025 if (infoPtr == NULL)
3026 return FALSE;
3027 if (lprbbi == NULL)
3028 return FALSE;
3029 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
3030 return FALSE;
3032 /* trace the index as signed to see the -1 */
3033 TRACE("insert band at %d!\n", (INT)uIndex);
3034 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3036 if (infoPtr->uNumBands == 0) {
3037 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
3038 uIndex = 0;
3040 else {
3041 REBAR_BAND *oldBands = infoPtr->bands;
3042 infoPtr->bands =
3043 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3044 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3045 uIndex = infoPtr->uNumBands;
3047 /* pre insert copy */
3048 if (uIndex > 0) {
3049 memcpy (&infoPtr->bands[0], &oldBands[0],
3050 uIndex * sizeof(REBAR_BAND));
3053 /* post copy */
3054 if (uIndex < infoPtr->uNumBands - 1) {
3055 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3056 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
3059 COMCTL32_Free (oldBands);
3062 infoPtr->uNumBands++;
3064 TRACE("index %u!\n", uIndex);
3066 /* initialize band (infoPtr->bands[uIndex])*/
3067 lpBand = &infoPtr->bands[uIndex];
3068 lpBand->fMask = 0;
3069 lpBand->fStatus = 0;
3070 lpBand->clrFore = infoPtr->clrText;
3071 lpBand->clrBack = infoPtr->clrBk;
3072 lpBand->hwndChild = 0;
3073 lpBand->hwndPrevParent = 0;
3075 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3076 lpBand->lpText = NULL;
3077 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3078 INT len = lstrlenW (lprbbi->lpText);
3079 if (len > 0) {
3080 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
3081 strcpyW (lpBand->lpText, lprbbi->lpText);
3085 REBAR_ValidateBand (infoPtr, lpBand);
3086 /* On insert of second band, revalidate band 1 to possible add gripper */
3087 if (infoPtr->uNumBands == 2)
3088 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3090 REBAR_DumpBand (infoPtr);
3092 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3093 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3095 return TRUE;
3099 static LRESULT
3100 REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3102 REBAR_BAND *lpBand;
3103 UINT uBand = (UINT) wParam;
3105 /* Validate */
3106 if ((infoPtr->uNumBands == 0) ||
3107 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3108 /* error !!! */
3109 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
3110 (INT)uBand, infoPtr->uNumBands);
3111 return FALSE;
3114 lpBand = &infoPtr->bands[uBand];
3116 if (lParam && (lpBand->fMask & RBBIM_IDEALSIZE)) {
3117 /* handle setting ideal size */
3118 lpBand->ccx = lpBand->cxIdeal;
3120 else {
3121 /* handle setting to max */
3122 FIXME("(uBand = %u fIdeal = %s) case not coded\n",
3123 (UINT)wParam, lParam ? "TRUE" : "FALSE");
3124 return FALSE;
3127 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3128 REBAR_Layout (infoPtr, 0, TRUE, TRUE);
3129 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
3131 return TRUE;
3136 static LRESULT
3137 REBAR_MinimizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3139 REBAR_BAND *band, *lpBand;
3140 UINT uBand = (UINT) wParam;
3141 RECT newrect;
3142 INT imindBand, imaxdBand, iprevBand, startBand, endBand;
3143 INT movement, i;
3145 /* A "minimize" band is equivalent to "dragging" the gripper
3146 * of than band to the right till the band is only the size
3147 * of the cxHeader.
3150 /* Validate */
3151 if ((infoPtr->uNumBands == 0) ||
3152 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3153 /* error !!! */
3154 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
3155 (INT)uBand, infoPtr->uNumBands);
3156 return FALSE;
3159 /* compute amount of movement and validate */
3160 lpBand = &infoPtr->bands[uBand];
3162 if (infoPtr->dwStyle & CCS_VERT)
3163 movement = lpBand->rcBand.bottom - lpBand->rcBand.top -
3164 lpBand->cxHeader;
3165 else
3166 movement = lpBand->rcBand.right - lpBand->rcBand.left -
3167 lpBand->cxHeader;
3168 if (movement < 0) {
3169 ERR("something is wrong, band=(%d,%d)-(%d,%d), cxheader=%d\n",
3170 lpBand->rcBand.left, lpBand->rcBand.top,
3171 lpBand->rcBand.right, lpBand->rcBand.bottom,
3172 lpBand->cxHeader);
3173 return FALSE;
3176 imindBand = -1;
3177 imaxdBand = -1;
3178 iprevBand = -1; /* to suppress warning message */
3180 /* find the first band in row of the one whose is being minimized */
3181 for (i=0; i<infoPtr->uNumBands; i++) {
3182 band = &infoPtr->bands[i];
3183 if (HIDDENBAND(band)) continue;
3184 if (band->iRow == lpBand->iRow) {
3185 imaxdBand = i;
3186 if (imindBand == -1) imindBand = i;
3190 /* if the selected band is first in row then need to expand */
3191 /* next visible band */
3192 if (imindBand == uBand) {
3193 band = NULL;
3194 movement = -movement;
3195 /* find the first visible band to the right of the selected band */
3196 for (i=uBand+1; i<=imaxdBand; i++) {
3197 band = &infoPtr->bands[i];
3198 if (!HIDDENBAND(band)) {
3199 iprevBand = i;
3200 LEADJ(band, movement);
3201 band->ccx = rcBw(band);
3202 break;
3205 /* what case is this */
3206 if (iprevBand == -1) {
3207 ERR("no previous visible band\n");
3208 return FALSE;
3210 startBand = uBand;
3211 endBand = iprevBand;
3212 SetRect (&newrect,
3213 lpBand->rcBand.left,
3214 lpBand->rcBand.top,
3215 band->rcBand.right,
3216 band->rcBand.bottom);
3218 /* otherwise expand previous visible band */
3219 else {
3220 band = NULL;
3221 /* find the first visible band to the left of the selected band */
3222 for (i=uBand-1; i>=imindBand; i--) {
3223 band = &infoPtr->bands[i];
3224 if (!HIDDENBAND(band)) {
3225 iprevBand = i;
3226 READJ(band, movement);
3227 band->ccx = rcBw(band);
3228 break;
3231 /* what case is this */
3232 if (iprevBand == -1) {
3233 ERR("no previous visible band\n");
3234 return FALSE;
3236 startBand = iprevBand;
3237 endBand = uBand;
3238 SetRect (&newrect,
3239 band->rcBand.left,
3240 band->rcBand.top,
3241 lpBand->rcBand.right,
3242 lpBand->rcBand.bottom);
3245 REBAR_Shrink (infoPtr, lpBand, movement, uBand);
3247 /* recompute all rectangles */
3248 if (infoPtr->dwStyle & CCS_VERT) {
3249 REBAR_CalcVertBand (infoPtr, startBand, endBand+1,
3250 FALSE);
3252 else {
3253 REBAR_CalcHorzBand (infoPtr, startBand, endBand+1,
3254 FALSE);
3257 TRACE("bands after minimize, see band # %d, %d\n",
3258 startBand, endBand);
3259 REBAR_DumpBand (infoPtr);
3261 REBAR_MoveChildWindows (infoPtr, startBand, endBand+1);
3263 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
3264 UpdateWindow (infoPtr->hwndSelf);
3265 return FALSE;
3269 static LRESULT
3270 REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3272 REBAR_BAND *oldBands = infoPtr->bands;
3273 REBAR_BAND holder;
3274 UINT uFrom = (UINT)wParam;
3275 UINT uTo = (UINT)lParam;
3277 /* Validate */
3278 if ((infoPtr->uNumBands == 0) ||
3279 ((INT)uFrom < 0) || (uFrom >= infoPtr->uNumBands) ||
3280 ((INT)uTo < 0) || (uTo >= infoPtr->uNumBands)) {
3281 /* error !!! */
3282 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
3283 (INT)uFrom, (INT)uTo, infoPtr->uNumBands);
3284 return FALSE;
3287 /* save one to be moved */
3288 memcpy (&holder, &oldBands[uFrom], sizeof(REBAR_BAND));
3290 /* close up rest of bands (psuedo delete) */
3291 if (uFrom < infoPtr->uNumBands - 1) {
3292 memcpy (&oldBands[uFrom], &oldBands[uFrom+1],
3293 (infoPtr->uNumBands - uFrom - 1) * sizeof(REBAR_BAND));
3296 /* allocate new space and copy rest of bands into it */
3297 infoPtr->bands =
3298 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
3300 /* pre insert copy */
3301 if (uTo > 0) {
3302 memcpy (&infoPtr->bands[0], &oldBands[0],
3303 uTo * sizeof(REBAR_BAND));
3306 /* set moved band */
3307 memcpy (&infoPtr->bands[uTo], &holder, sizeof(REBAR_BAND));
3309 /* post copy */
3310 if (uTo < infoPtr->uNumBands - 1) {
3311 memcpy (&infoPtr->bands[uTo+1], &oldBands[uTo],
3312 (infoPtr->uNumBands - uTo - 1) * sizeof(REBAR_BAND));
3315 COMCTL32_Free (oldBands);
3317 TRACE("moved band %d to index %d\n", uFrom, uTo);
3318 REBAR_DumpBand (infoPtr);
3320 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3321 /* **************************************************** */
3322 /* */
3323 /* We do not do a REBAR_Layout here because the native */
3324 /* control does not do that. The actual layout and */
3325 /* repaint is done by the *next* real action, ex.: */
3326 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
3327 /* */
3328 /* **************************************************** */
3330 return TRUE;
3334 static LRESULT
3335 REBAR_SetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3337 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
3338 REBAR_BAND *lpBand;
3340 if (lprbbi == NULL)
3341 return FALSE;
3342 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
3343 return FALSE;
3344 if ((UINT)wParam >= infoPtr->uNumBands)
3345 return FALSE;
3347 TRACE("index %u\n", (UINT)wParam);
3348 REBAR_DumpBandInfo (lprbbi);
3350 /* set band information */
3351 lpBand = &infoPtr->bands[(UINT)wParam];
3353 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3354 if (lprbbi->fMask & RBBIM_TEXT) {
3355 if (lpBand->lpText) {
3356 COMCTL32_Free (lpBand->lpText);
3357 lpBand->lpText = NULL;
3359 if (lprbbi->lpText) {
3360 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3361 lpBand->lpText = (LPWSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
3362 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3366 REBAR_ValidateBand (infoPtr, lpBand);
3368 REBAR_DumpBand (infoPtr);
3370 if (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) {
3371 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3372 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3375 return TRUE;
3379 static LRESULT
3380 REBAR_SetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3382 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3383 REBAR_BAND *lpBand;
3385 if (lprbbi == NULL)
3386 return FALSE;
3387 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
3388 return FALSE;
3389 if ((UINT)wParam >= infoPtr->uNumBands)
3390 return FALSE;
3392 TRACE("index %u\n", (UINT)wParam);
3393 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3395 /* set band information */
3396 lpBand = &infoPtr->bands[(UINT)wParam];
3398 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3399 if (lprbbi->fMask & RBBIM_TEXT) {
3400 if (lpBand->lpText) {
3401 COMCTL32_Free (lpBand->lpText);
3402 lpBand->lpText = NULL;
3404 if (lprbbi->lpText) {
3405 INT len = lstrlenW (lprbbi->lpText);
3406 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
3407 strcpyW (lpBand->lpText, lprbbi->lpText);
3411 REBAR_ValidateBand (infoPtr, lpBand);
3413 REBAR_DumpBand (infoPtr);
3415 if (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) {
3416 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3417 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3420 return TRUE;
3424 static LRESULT
3425 REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3427 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
3428 REBAR_BAND *lpBand;
3429 UINT i;
3431 if (lpInfo == NULL)
3432 return FALSE;
3434 if (lpInfo->cbSize < sizeof (REBARINFO))
3435 return FALSE;
3437 TRACE("setting bar info!\n");
3439 if (lpInfo->fMask & RBIM_IMAGELIST) {
3440 infoPtr->himl = lpInfo->himl;
3441 if (infoPtr->himl) {
3442 INT cx, cy;
3443 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
3444 infoPtr->imageSize.cx = cx;
3445 infoPtr->imageSize.cy = cy;
3447 else {
3448 infoPtr->imageSize.cx = 0;
3449 infoPtr->imageSize.cy = 0;
3451 TRACE("new image cx=%ld, cy=%ld\n", infoPtr->imageSize.cx,
3452 infoPtr->imageSize.cy);
3455 /* revalidate all bands to reset flags for images in headers of bands */
3456 for (i=0; i<infoPtr->uNumBands; i++) {
3457 lpBand = &infoPtr->bands[i];
3458 REBAR_ValidateBand (infoPtr, lpBand);
3461 return TRUE;
3465 static LRESULT
3466 REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3468 COLORREF clrTemp;
3470 clrTemp = infoPtr->clrBk;
3471 infoPtr->clrBk = (COLORREF)lParam;
3473 TRACE("background color 0x%06lx!\n", infoPtr->clrBk);
3475 return clrTemp;
3479 /* << REBAR_SetColorScheme >> */
3480 /* << REBAR_SetPalette >> */
3483 static LRESULT
3484 REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3486 HWND hwndTemp = infoPtr->hwndNotify;
3488 infoPtr->hwndNotify = (HWND)wParam;
3490 return (LRESULT)hwndTemp;
3494 static LRESULT
3495 REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3497 COLORREF clrTemp;
3499 clrTemp = infoPtr->clrText;
3500 infoPtr->clrText = (COLORREF)lParam;
3502 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
3504 return clrTemp;
3508 /* << REBAR_SetTooltips >> */
3511 inline static LRESULT
3512 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, WPARAM wParam)
3514 BOOL bTemp = infoPtr->bUnicode;
3516 TRACE("to %s hwnd=0x%04x, was %s\n",
3517 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf,
3518 (bTemp) ? "TRUE" : "FALSE");
3520 infoPtr->bUnicode = (BOOL)wParam;
3522 return bTemp;
3526 static LRESULT
3527 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
3529 INT iOldVersion = infoPtr->iVersion;
3531 if (iVersion > COMCTL32_VERSION)
3532 return -1;
3534 infoPtr->iVersion = iVersion;
3536 TRACE("new version %d\n", iVersion);
3538 return iOldVersion;
3542 static LRESULT
3543 REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3545 REBAR_BAND *lpBand;
3547 if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
3548 return FALSE;
3550 lpBand = &infoPtr->bands[(INT)wParam];
3552 if ((BOOL)lParam) {
3553 TRACE("show band %d\n", (INT)wParam);
3554 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
3555 if (IsWindow (lpBand->hwndChild))
3556 ShowWindow (lpBand->hwndChild, SW_SHOW);
3558 else {
3559 TRACE("hide band %d\n", (INT)wParam);
3560 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
3561 if (IsWindow (lpBand->hwndChild))
3562 ShowWindow (lpBand->hwndChild, SW_HIDE);
3565 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3566 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3568 return TRUE;
3572 static LRESULT
3573 REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3575 LPRECT lpRect = (LPRECT)lParam;
3576 RECT t1;
3578 if (lpRect == NULL)
3579 return FALSE;
3581 TRACE("[%d %d %d %d]\n",
3582 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
3584 /* what is going on???? */
3585 GetWindowRect(infoPtr->hwndSelf, &t1);
3586 TRACE("window rect [%d %d %d %d]\n",
3587 t1.left, t1.top, t1.right, t1.bottom);
3588 GetClientRect(infoPtr->hwndSelf, &t1);
3589 TRACE("client rect [%d %d %d %d]\n",
3590 t1.left, t1.top, t1.right, t1.bottom);
3592 /* force full _Layout processing */
3593 TRACE("setting NEEDS_LAYOUT\n");
3594 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3595 REBAR_Layout (infoPtr, lpRect, TRUE, FALSE);
3596 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3597 return TRUE;
3602 static LRESULT
3603 REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3605 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3606 RECT wnrc1, clrc1;
3608 if (TRACE_ON(rebar)) {
3609 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
3610 GetClientRect(infoPtr->hwndSelf, &clrc1);
3611 TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
3612 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3613 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3614 cs->x, cs->y, cs->cx, cs->cy);
3617 TRACE("created!\n");
3618 return 0;
3622 static LRESULT
3623 REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3625 REBAR_BAND *lpBand;
3626 INT i;
3629 /* free rebar bands */
3630 if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
3631 /* clean up each band */
3632 for (i = 0; i < infoPtr->uNumBands; i++) {
3633 lpBand = &infoPtr->bands[i];
3635 /* delete text strings */
3636 if (lpBand->lpText) {
3637 COMCTL32_Free (lpBand->lpText);
3638 lpBand->lpText = NULL;
3640 /* destroy child window */
3641 DestroyWindow (lpBand->hwndChild);
3644 /* free band array */
3645 COMCTL32_Free (infoPtr->bands);
3646 infoPtr->bands = NULL;
3649 DeleteObject (infoPtr->hcurArrow);
3650 DeleteObject (infoPtr->hcurHorz);
3651 DeleteObject (infoPtr->hcurVert);
3652 DeleteObject (infoPtr->hcurDrag);
3653 if(infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
3654 SetWindowLongA (infoPtr->hwndSelf, 0, 0);
3656 /* free rebar info data */
3657 COMCTL32_Free (infoPtr);
3658 TRACE("destroyed!\n");
3659 return 0;
3663 static LRESULT
3664 REBAR_EraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3666 RECT cliprect;
3668 if (GetClipBox ( (HDC)wParam, &cliprect))
3669 return REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &cliprect);
3670 return 0;
3674 static LRESULT
3675 REBAR_GetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3677 return (LRESULT)infoPtr->hFont;
3681 static LRESULT
3682 REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3684 REBAR_BAND *lpBand;
3686 /* If InternalHitTest did not find a hit on the Gripper, */
3687 /* then ignore the button click. */
3688 if (infoPtr->ihitBand == -1) return 0;
3690 SetCapture (infoPtr->hwndSelf);
3692 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3693 lpBand = &infoPtr->bands[infoPtr->ihitBand];
3694 infoPtr->dragStart = MAKEPOINTS(lParam);
3695 infoPtr->dragNow = infoPtr->dragStart;
3696 if (infoPtr->dwStyle & CCS_VERT)
3697 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.top+REBAR_PRE_GRIPPER);
3698 else
3699 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left+REBAR_PRE_GRIPPER);
3701 return 0;
3705 static LRESULT
3706 REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3708 NMHDR layout;
3709 RECT rect;
3710 INT ihitBand;
3712 /* If InternalHitTest did not find a hit on the Gripper, */
3713 /* then ignore the button click. */
3714 if (infoPtr->ihitBand == -1) return 0;
3716 ihitBand = infoPtr->ihitBand;
3717 infoPtr->dragStart.x = 0;
3718 infoPtr->dragStart.y = 0;
3719 infoPtr->dragNow = infoPtr->dragStart;
3720 infoPtr->ihitBand = -1;
3722 ReleaseCapture ();
3724 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3725 REBAR_Notify((NMHDR *) &layout, infoPtr, RBN_LAYOUTCHANGED);
3726 REBAR_Notify_NMREBAR (infoPtr, ihitBand, RBN_ENDDRAG);
3727 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3730 GetClientRect(infoPtr->hwndSelf, &rect);
3731 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3733 return 0;
3737 static LRESULT
3738 REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3740 REBAR_BAND *band1, *band2;
3741 POINTS ptsmove;
3743 /* Validate entry as hit on Gripper has occured */
3744 if (GetCapture() != infoPtr->hwndSelf) return 0;
3745 if (infoPtr->ihitBand == -1) return 0;
3747 ptsmove = MAKEPOINTS(lParam);
3749 /* if mouse did not move much, exit */
3750 if ((abs(ptsmove.x - infoPtr->dragNow.x) <= mindragx) &&
3751 (abs(ptsmove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3753 band1 = &infoPtr->bands[infoPtr->ihitBand-1];
3754 band2 = &infoPtr->bands[infoPtr->ihitBand];
3756 /* Test for valid drag case - must not be first band in row */
3757 if (infoPtr->dwStyle & CCS_VERT) {
3758 if ((ptsmove.x < band2->rcBand.left) ||
3759 (ptsmove.x > band2->rcBand.right) ||
3760 ((infoPtr->ihitBand > 0) && (band1->iRow != band2->iRow))) {
3761 FIXME("Cannot drag to other rows yet!!\n");
3763 else {
3764 REBAR_HandleLRDrag (infoPtr, &ptsmove);
3767 else {
3768 if ((ptsmove.y < band2->rcBand.top) ||
3769 (ptsmove.y > band2->rcBand.bottom) ||
3770 ((infoPtr->ihitBand > 0) && (band1->iRow != band2->iRow))) {
3771 FIXME("Cannot drag to other rows yet!!\n");
3773 else {
3774 REBAR_HandleLRDrag (infoPtr, &ptsmove);
3777 return 0;
3781 inline static LRESULT
3782 REBAR_NCCalcSize (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3784 if (infoPtr->dwStyle & WS_BORDER) {
3785 InflateRect((LPRECT)lParam, -GetSystemMetrics(SM_CXEDGE),
3786 -GetSystemMetrics(SM_CYEDGE));
3788 TRACE("new client=(%d,%d)-(%d,%d)\n",
3789 ((LPRECT)lParam)->left, ((LPRECT)lParam)->top,
3790 ((LPRECT)lParam)->right, ((LPRECT)lParam)->bottom);
3791 return 0;
3795 static LRESULT
3796 REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3798 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3799 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3800 RECT wnrc1, clrc1;
3801 NONCLIENTMETRICSA ncm;
3802 HFONT tfont;
3803 INT i;
3805 if (infoPtr != NULL) {
3806 ERR("Strange info structure pointer *not* NULL\n");
3807 return FALSE;
3810 if (TRACE_ON(rebar)) {
3811 GetWindowRect(hwnd, &wnrc1);
3812 GetClientRect(hwnd, &clrc1);
3813 TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
3814 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3815 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3816 cs->x, cs->y, cs->cx, cs->cy);
3819 /* allocate memory for info structure */
3820 infoPtr = (REBAR_INFO *)COMCTL32_Alloc (sizeof(REBAR_INFO));
3821 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
3823 /* initialize info structure - initial values are 0 */
3824 infoPtr->clrBk = CLR_NONE;
3825 infoPtr->clrText = CLR_NONE;
3826 infoPtr->clrBtnText = GetSysColor (COLOR_BTNTEXT);
3827 infoPtr->clrBtnFace = GetSysColor (COLOR_BTNFACE);
3828 infoPtr->ihitBand = -1;
3829 infoPtr->hwndSelf = hwnd;
3830 infoPtr->DoRedraw = TRUE;
3831 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
3832 infoPtr->hcurHorz = LoadCursorA (0, IDC_SIZEWEA);
3833 infoPtr->hcurVert = LoadCursorA (0, IDC_SIZENSA);
3834 infoPtr->hcurDrag = LoadCursorA (0, IDC_SIZEA);
3835 infoPtr->bUnicode = IsWindowUnicode (hwnd);
3836 infoPtr->fStatus = CREATE_RUNNING;
3837 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3839 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3840 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
3841 WM_NOTIFYFORMAT, hwnd, NF_QUERY);
3842 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
3843 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
3845 i = NFR_ANSI;
3847 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
3849 /* add necessary styles to the requested styles */
3850 infoPtr->dwStyle = cs->style | WS_VISIBLE | CCS_TOP;
3851 SetWindowLongA (hwnd, GWL_STYLE, infoPtr->dwStyle);
3853 /* get font handle for Caption Font */
3854 ncm.cbSize = sizeof(NONCLIENTMETRICSA);
3855 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS,
3856 ncm.cbSize, &ncm, 0);
3857 /* if the font is bold, set to normal */
3858 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3859 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3861 tfont = CreateFontIndirectA (&ncm.lfCaptionFont);
3862 if (tfont) {
3863 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3866 /* native does:
3867 GetSysColor (numerous);
3868 GetSysColorBrush (numerous) (see WM_SYSCOLORCHANGE);
3869 *GetStockObject (SYSTEM_FONT);
3870 *SetWindowLong (hwnd, 0, info ptr);
3871 *WM_NOTIFYFORMAT;
3872 *SetWindowLong (hwnd, GWL_STYLE, style+0x10000001);
3873 WS_VISIBLE = 0x10000000;
3874 CCS_TOP = 0x00000001;
3875 *SystemParametersInfo (SPI_GETNONCLIENTMETRICS...);
3876 *CreateFontIndirect (lfCaptionFont from above);
3877 GetDC ();
3878 SelectObject (hdc, fontabove);
3879 GetTextMetrics (hdc, ); guessing is tmHeight
3880 SelectObject (hdc, oldfont);
3881 ReleaseDC ();
3882 GetWindowRect ();
3883 MapWindowPoints (0, parent, rectabove, 2);
3884 GetWindowRect ();
3885 GetClientRect ();
3886 ClientToScreen (clientrect);
3887 SetWindowPos (hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER);
3889 return TRUE;
3893 static LRESULT
3894 REBAR_NCHitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3896 NMMOUSE nmmouse;
3897 POINTS shortpt;
3898 POINT clpt, pt;
3899 INT i;
3900 UINT scrap;
3901 LRESULT ret = HTCLIENT;
3904 * Differences from doc at MSDN (as observed with version 4.71 of
3905 * comctl32.dll
3906 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3907 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3908 * 3. native always seems to return HTCLIENT if notify return is 0.
3911 shortpt = MAKEPOINTS (lParam);
3912 POINTSTOPOINT(pt, shortpt);
3913 clpt = pt;
3914 ScreenToClient (infoPtr->hwndSelf, &clpt);
3915 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3916 (INT *)&nmmouse.dwItemSpec);
3917 nmmouse.dwItemData = 0;
3918 nmmouse.pt = clpt;
3919 nmmouse.dwHitInfo = 0;
3920 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3921 TRACE("notify changed return value from %ld to %d\n",
3922 ret, i);
3923 ret = (LRESULT) i;
3925 TRACE("returning %ld, client point (%ld,%ld)\n", ret, clpt.x, clpt.y);
3926 return ret;
3930 static LRESULT
3931 REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3933 RECT rcWindow;
3934 HDC hdc;
3936 if (infoPtr->dwStyle & WS_MINIMIZE)
3937 return 0; /* Nothing to do */
3939 if (infoPtr->dwStyle & WS_BORDER) {
3941 /* adjust rectangle and draw the necessary edge */
3942 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3943 return 0;
3944 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3945 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3946 TRACE("rect (%d,%d)-(%d,%d)\n",
3947 rcWindow.left, rcWindow.top,
3948 rcWindow.right, rcWindow.bottom);
3949 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3950 ReleaseDC( infoPtr->hwndSelf, hdc );
3953 return 0;
3957 static LRESULT
3958 REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3960 INT i;
3962 if (lParam == NF_REQUERY) {
3963 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
3964 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
3965 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
3966 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
3968 i = NFR_ANSI;
3970 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
3971 return (LRESULT)i;
3973 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3977 static LRESULT
3978 REBAR_Paint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3980 HDC hdc;
3981 PAINTSTRUCT ps;
3982 RECT rc;
3984 GetClientRect(infoPtr->hwndSelf, &rc);
3985 hdc = wParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : (HDC)wParam;
3987 TRACE("painting (%d,%d)-(%d,%d) client (%d,%d)-(%d,%d)\n",
3988 ps.rcPaint.left, ps.rcPaint.top,
3989 ps.rcPaint.right, ps.rcPaint.bottom,
3990 rc.left, rc.top, rc.right, rc.bottom);
3992 if (ps.fErase) {
3993 /* Erase area of paint if requested */
3994 REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &ps.rcPaint);
3997 REBAR_Refresh (infoPtr, hdc);
3998 if (!wParam)
3999 EndPaint (infoPtr->hwndSelf, &ps);
4000 return 0;
4004 static LRESULT
4005 REBAR_SetCursor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4007 POINT pt;
4008 UINT flags;
4010 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
4012 GetCursorPos (&pt);
4013 ScreenToClient (infoPtr->hwndSelf, &pt);
4015 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
4017 if (flags == RBHT_GRABBER) {
4018 if ((infoPtr->dwStyle & CCS_VERT) &&
4019 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
4020 SetCursor (infoPtr->hcurVert);
4021 else
4022 SetCursor (infoPtr->hcurHorz);
4024 else if (flags != RBHT_CLIENT)
4025 SetCursor (infoPtr->hcurArrow);
4027 return 0;
4031 static LRESULT
4032 REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4034 RECT rcClient;
4035 REBAR_BAND *lpBand;
4036 UINT i;
4038 infoPtr->hFont = (HFONT)wParam;
4040 /* revalidate all bands to change sizes of text in headers of bands */
4041 for (i=0; i<infoPtr->uNumBands; i++) {
4042 lpBand = &infoPtr->bands[i];
4043 REBAR_ValidateBand (infoPtr, lpBand);
4047 if (LOWORD(lParam)) {
4048 GetClientRect (infoPtr->hwndSelf, &rcClient);
4049 REBAR_Layout (infoPtr, &rcClient, FALSE, TRUE);
4052 return 0;
4056 inline static LRESULT
4057 REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4058 /*****************************************************
4060 * Function;
4061 * Handles the WM_SETREDRAW message.
4063 * Documentation:
4064 * According to testing V4.71 of COMCTL32 returns the
4065 * *previous* status of the redraw flag (either 0 or -1)
4066 * instead of the MSDN documented value of 0 if handled
4068 *****************************************************/
4070 BOOL oldredraw = infoPtr->DoRedraw;
4072 TRACE("set to %s, fStatus=%08x\n",
4073 (wParam) ? "TRUE" : "FALSE", infoPtr->fStatus);
4074 infoPtr->DoRedraw = (BOOL) wParam;
4075 if (wParam) {
4076 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
4077 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
4078 REBAR_ForceResize (infoPtr);
4079 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
4081 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
4083 return (oldredraw) ? -1 : 0;
4087 static LRESULT
4088 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4090 RECT rcClient;
4092 /* auto resize deadlock check */
4093 if (infoPtr->fStatus & AUTO_RESIZE) {
4094 infoPtr->fStatus &= ~AUTO_RESIZE;
4095 TRACE("AUTO_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
4096 infoPtr->fStatus, lParam);
4097 return 0;
4100 if (infoPtr->fStatus & CREATE_RUNNING) {
4101 /* still in CreateWindow */
4102 RECT rcWin;
4104 if ((INT)wParam != SIZE_RESTORED) {
4105 ERR("WM_SIZE in create and flags=%08x, lParam=%08lx\n",
4106 wParam, lParam);
4109 TRACE("still in CreateWindow\n");
4110 infoPtr->fStatus &= ~CREATE_RUNNING;
4111 GetWindowRect ( infoPtr->hwndSelf, &rcWin);
4112 TRACE("win rect (%d,%d)-(%d,%d)\n",
4113 rcWin.left, rcWin.top, rcWin.right, rcWin.bottom);
4115 if ((lParam == 0) && (rcWin.right-rcWin.left == 0) &&
4116 (rcWin.bottom-rcWin.top == 0)) {
4117 /* native control seems to do this */
4118 GetClientRect (GetParent(infoPtr->hwndSelf), &rcClient);
4119 TRACE("sizing rebar, message and client zero, parent client (%d,%d)\n",
4120 rcClient.right, rcClient.bottom);
4122 else {
4123 INT cx, cy;
4125 cx = rcWin.right - rcWin.left;
4126 cy = rcWin.bottom - rcWin.top;
4127 if ((cx == LOWORD(lParam)) && (cy == HIWORD(lParam))) {
4128 return 0;
4131 /* do the actual WM_SIZE request */
4132 GetClientRect (infoPtr->hwndSelf, &rcClient);
4133 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%d,%d)\n",
4134 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4135 LOWORD(lParam), HIWORD(lParam),
4136 rcClient.right, rcClient.bottom);
4139 else {
4140 if ((INT)wParam != SIZE_RESTORED) {
4141 ERR("WM_SIZE out of create and flags=%08x, lParam=%08lx\n",
4142 wParam, lParam);
4145 /* Handle cases when outside of the CreateWindow process */
4147 GetClientRect (infoPtr->hwndSelf, &rcClient);
4148 if ((lParam == 0) && (rcClient.right + rcClient.bottom != 0) &&
4149 (infoPtr->dwStyle & RBS_AUTOSIZE)) {
4150 /* on a WM_SIZE to zero and current client not zero and AUTOSIZE */
4151 /* native seems to use the current client rect for the size */
4152 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4153 TRACE("sizing rebar to client (%d,%d) size is zero but AUTOSIZE set\n",
4154 rcClient.right, rcClient.bottom);
4156 else {
4157 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%d,%d)\n",
4158 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4159 LOWORD(lParam), HIWORD(lParam),
4160 rcClient.right, rcClient.bottom);
4164 if (infoPtr->dwStyle & RBS_AUTOSIZE) {
4165 NMRBAUTOSIZE autosize;
4167 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
4168 autosize.fChanged = 0; /* ??? */
4169 autosize.rcActual = autosize.rcTarget; /* ??? */
4170 REBAR_Notify((NMHDR *) &autosize, infoPtr, RBN_AUTOSIZE);
4171 TRACE("RBN_AUTOSIZE client=(%d,%d), lp=%08lx\n",
4172 autosize.rcTarget.right, autosize.rcTarget.bottom, lParam);
4175 if ((infoPtr->calcSize.cx != rcClient.right) ||
4176 (infoPtr->calcSize.cy != rcClient.bottom))
4177 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4179 REBAR_Layout (infoPtr, &rcClient, TRUE, TRUE);
4180 infoPtr->fStatus &= ~AUTO_RESIZE;
4182 return 0;
4186 static LRESULT
4187 REBAR_StyleChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4189 STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
4191 TRACE("current style=%08lx, styleOld=%08lx, style being set to=%08lx\n",
4192 infoPtr->dwStyle, ss->styleOld, ss->styleNew);
4193 infoPtr->dwStyle = ss->styleNew;
4195 return FALSE;
4199 static LRESULT WINAPI
4200 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4202 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
4204 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
4205 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
4206 if (!infoPtr && (uMsg != WM_NCCREATE))
4207 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4208 switch (uMsg)
4210 /* case RB_BEGINDRAG: */
4212 case RB_DELETEBAND:
4213 return REBAR_DeleteBand (infoPtr, wParam, lParam);
4215 /* case RB_DRAGMOVE: */
4216 /* case RB_ENDDRAG: */
4218 case RB_GETBANDBORDERS:
4219 return REBAR_GetBandBorders (infoPtr, wParam, lParam);
4221 case RB_GETBANDCOUNT:
4222 return REBAR_GetBandCount (infoPtr);
4224 case RB_GETBANDINFO: /* obsoleted after IE3, but we have to
4225 support it anyway. */
4226 case RB_GETBANDINFOA:
4227 return REBAR_GetBandInfoA (infoPtr, wParam, lParam);
4229 case RB_GETBANDINFOW:
4230 return REBAR_GetBandInfoW (infoPtr, wParam, lParam);
4232 case RB_GETBARHEIGHT:
4233 return REBAR_GetBarHeight (infoPtr, wParam, lParam);
4235 case RB_GETBARINFO:
4236 return REBAR_GetBarInfo (infoPtr, wParam, lParam);
4238 case RB_GETBKCOLOR:
4239 return REBAR_GetBkColor (infoPtr);
4241 /* case RB_GETCOLORSCHEME: */
4242 /* case RB_GETDROPTARGET: */
4244 case RB_GETPALETTE:
4245 return REBAR_GetPalette (infoPtr, wParam, lParam);
4247 case RB_GETRECT:
4248 return REBAR_GetRect (infoPtr, wParam, lParam);
4250 case RB_GETROWCOUNT:
4251 return REBAR_GetRowCount (infoPtr);
4253 case RB_GETROWHEIGHT:
4254 return REBAR_GetRowHeight (infoPtr, wParam, lParam);
4256 case RB_GETTEXTCOLOR:
4257 return REBAR_GetTextColor (infoPtr);
4259 case RB_GETTOOLTIPS:
4260 return REBAR_GetToolTips (infoPtr);
4262 case RB_GETUNICODEFORMAT:
4263 return REBAR_GetUnicodeFormat (infoPtr);
4265 case CCM_GETVERSION:
4266 return REBAR_GetVersion (infoPtr);
4268 case RB_HITTEST:
4269 return REBAR_HitTest (infoPtr, wParam, lParam);
4271 case RB_IDTOINDEX:
4272 return REBAR_IdToIndex (infoPtr, wParam, lParam);
4274 case RB_INSERTBANDA:
4275 return REBAR_InsertBandA (infoPtr, wParam, lParam);
4277 case RB_INSERTBANDW:
4278 return REBAR_InsertBandW (infoPtr, wParam, lParam);
4280 case RB_MAXIMIZEBAND:
4281 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
4283 case RB_MINIMIZEBAND:
4284 return REBAR_MinimizeBand (infoPtr, wParam, lParam);
4286 case RB_MOVEBAND:
4287 return REBAR_MoveBand (infoPtr, wParam, lParam);
4289 case RB_SETBANDINFOA:
4290 return REBAR_SetBandInfoA (infoPtr, wParam, lParam);
4292 case RB_SETBANDINFOW:
4293 return REBAR_SetBandInfoW (infoPtr, wParam, lParam);
4295 case RB_SETBARINFO:
4296 return REBAR_SetBarInfo (infoPtr, wParam, lParam);
4298 case RB_SETBKCOLOR:
4299 return REBAR_SetBkColor (infoPtr, wParam, lParam);
4301 /* case RB_SETCOLORSCHEME: */
4302 /* case RB_SETPALETTE: */
4303 /* return REBAR_GetPalette (infoPtr, wParam, lParam); */
4305 case RB_SETPARENT:
4306 return REBAR_SetParent (infoPtr, wParam, lParam);
4308 case RB_SETTEXTCOLOR:
4309 return REBAR_SetTextColor (infoPtr, wParam, lParam);
4311 /* case RB_SETTOOLTIPS: */
4313 case RB_SETUNICODEFORMAT:
4314 return REBAR_SetUnicodeFormat (infoPtr, wParam);
4316 case CCM_SETVERSION:
4317 return REBAR_SetVersion (infoPtr, (INT)wParam);
4319 case RB_SHOWBAND:
4320 return REBAR_ShowBand (infoPtr, wParam, lParam);
4322 case RB_SIZETORECT:
4323 return REBAR_SizeToRect (infoPtr, wParam, lParam);
4326 /* Messages passed to parent */
4327 case WM_COMMAND:
4328 case WM_DRAWITEM:
4329 case WM_NOTIFY:
4330 if (infoPtr->NtfUnicode)
4331 return SendMessageW (REBAR_GetNotifyParent (infoPtr),
4332 uMsg, wParam, lParam);
4333 else
4334 return SendMessageA (REBAR_GetNotifyParent (infoPtr),
4335 uMsg, wParam, lParam);
4338 /* case WM_CHARTOITEM: supported according to ControlSpy */
4340 case WM_CREATE:
4341 return REBAR_Create (infoPtr, wParam, lParam);
4343 case WM_DESTROY:
4344 return REBAR_Destroy (infoPtr, wParam, lParam);
4346 case WM_ERASEBKGND:
4347 return REBAR_EraseBkGnd (infoPtr, wParam, lParam);
4349 case WM_GETFONT:
4350 return REBAR_GetFont (infoPtr, wParam, lParam);
4352 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
4354 case WM_LBUTTONDOWN:
4355 return REBAR_LButtonDown (infoPtr, wParam, lParam);
4357 case WM_LBUTTONUP:
4358 return REBAR_LButtonUp (infoPtr, wParam, lParam);
4360 /* case WM_MEASUREITEM: supported according to ControlSpy */
4362 case WM_MOUSEMOVE:
4363 return REBAR_MouseMove (infoPtr, wParam, lParam);
4365 case WM_NCCALCSIZE:
4366 return REBAR_NCCalcSize (infoPtr, wParam, lParam);
4368 case WM_NCCREATE:
4369 return REBAR_NCCreate (hwnd, wParam, lParam);
4371 case WM_NCHITTEST:
4372 return REBAR_NCHitTest (infoPtr, wParam, lParam);
4374 case WM_NCPAINT:
4375 return REBAR_NCPaint (infoPtr, wParam, lParam);
4377 case WM_NOTIFYFORMAT:
4378 return REBAR_NotifyFormat (infoPtr, wParam, lParam);
4380 case WM_PAINT:
4381 return REBAR_Paint (infoPtr, wParam, lParam);
4383 /* case WM_PALETTECHANGED: supported according to ControlSpy */
4384 /* case WM_PRINTCLIENT: supported according to ControlSpy */
4385 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
4386 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
4387 /* case WM_RBUTTONUP: supported according to ControlSpy */
4389 case WM_SETCURSOR:
4390 return REBAR_SetCursor (infoPtr, wParam, lParam);
4392 case WM_SETFONT:
4393 return REBAR_SetFont (infoPtr, wParam, lParam);
4395 case WM_SETREDRAW:
4396 return REBAR_SetRedraw (infoPtr, wParam, lParam);
4398 case WM_SIZE:
4399 return REBAR_Size (infoPtr, wParam, lParam);
4401 case WM_STYLECHANGED:
4402 return REBAR_StyleChanged (infoPtr, wParam, lParam);
4404 /* case WM_SYSCOLORCHANGE: supported according to ControlSpy */
4405 /* "Applications that have brushes using the existing system colors
4406 should delete those brushes and recreate them using the new
4407 system colors." per MSDN */
4409 /* case WM_VKEYTOITEM: supported according to ControlSpy */
4410 /* case WM_WININICHANGE: */
4412 default:
4413 if (uMsg >= WM_USER)
4414 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
4415 uMsg, wParam, lParam);
4416 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4418 return 0;
4422 VOID
4423 REBAR_Register (void)
4425 WNDCLASSA wndClass;
4427 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4428 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
4429 wndClass.lpfnWndProc = (WNDPROC)REBAR_WindowProc;
4430 wndClass.cbClsExtra = 0;
4431 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
4432 wndClass.hCursor = 0;
4433 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
4434 #if GLATESTING
4435 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
4436 #endif
4437 wndClass.lpszClassName = REBARCLASSNAMEA;
4439 RegisterClassA (&wndClass);
4441 mindragx = GetSystemMetrics (SM_CXDRAG);
4442 mindragy = GetSystemMetrics (SM_CYDRAG);
4447 VOID
4448 REBAR_Unregister (void)
4450 UnregisterClassA (REBARCLASSNAMEA, (HINSTANCE)NULL);