Never delete the font object received by WM_SETFONT.
[wine/testsucceed.git] / dlls / comctl32 / rebar.c
blob545b8a154be8ddec2c460e9ed26015ab10c61229
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 8a
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.
93 * Still to do:
94 * 2. Following still not handled: RBBS_FIXEDBMP,
95 * RBBS_USECHEVRON, CCS_NORESIZE,
96 * CCS_NOMOVEX, CCS_NOMOVEY
97 * 3. Following are only partially handled:
98 * RBS_AUTOSIZE, RBBS_VARIABLEHEIGHT
99 * 5. Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
100 * to set the size of the separator width (the value SEP_WIDTH_SIZE
101 * in here). Should be fixed!!
102 * 6. The following messages are not implemented:
103 * RB_BEGINDRAG, RB_DRAGMOVE, RB_ENDDRAG, RB_GETCOLORSCHEME,
104 * RB_GETDROPTARGET, RB_MAXIMIZEBAND,
105 * RB_SETCOLORSCHEME, RB_SETPALETTE, RB_SETTOOLTIPS
106 * WM_CHARTOITEM, WM_LBUTTONDBLCLK, WM_MEASUREITEM,
107 * WM_PALETTECHANGED, WM_PRINTCLIENT, WM_QUERYNEWPALETTE,
108 * WM_RBUTTONDOWN, WM_RBUTTONUP,
109 * WM_SYSCOLORCHANGE, WM_VKEYTOITEM, WM_WININICHANGE
110 * 7. The following notifications are not implemented:
111 * NM_CUSTOMDRAW, NM_RELEASEDCAPTURE
112 * RB_CHEVRONPUSHED, RBN_MINMAX
115 #include <stdlib.h>
116 #include <string.h>
118 #include "winbase.h"
119 #include "wingdi.h"
120 #include "wine/unicode.h"
121 #include "commctrl.h"
122 /* #include "spy.h" */
123 #include "debugtools.h"
125 DEFAULT_DEBUG_CHANNEL(rebar);
127 typedef struct
129 UINT fStyle;
130 UINT fMask;
131 COLORREF clrFore;
132 COLORREF clrBack;
133 INT iImage;
134 HWND hwndChild;
135 UINT cxMinChild; /* valid if _CHILDSIZE */
136 UINT cyMinChild; /* valid if _CHILDSIZE */
137 UINT cx; /* valid if _SIZE */
138 HBITMAP hbmBack;
139 UINT wID;
140 UINT cyChild; /* valid if _CHILDSIZE */
141 UINT cyMaxChild; /* valid if _CHILDSIZE */
142 UINT cyIntegral; /* valid if _CHILDSIZE */
143 UINT cxIdeal;
144 LPARAM lParam;
145 UINT cxHeader;
147 UINT lcx; /* minimum cx for band */
148 UINT ccx; /* current cx for band */
149 UINT hcx; /* maximum cx for band */
150 UINT lcy; /* minimum cy for band */
151 UINT ccy; /* current cy for band */
152 UINT hcy; /* maximum cy for band */
154 SIZE offChild; /* x,y offset if child is not FIXEDSIZE */
155 UINT uMinHeight;
156 INT iRow; /* row this band assigned to */
157 UINT fStatus; /* status flags, reset only by _Validate */
158 UINT fDraw; /* drawing flags, reset only by _Layout */
159 UINT uCDret; /* last return from NM_CUSTOMDRAW */
160 RECT rcoldBand; /* previous calculated band rectangle */
161 RECT rcBand; /* calculated band rectangle */
162 RECT rcGripper; /* calculated gripper rectangle */
163 RECT rcCapImage; /* calculated caption image rectangle */
164 RECT rcCapText; /* calculated caption text rectangle */
165 RECT rcChild; /* calculated child rectangle */
167 LPWSTR lpText;
168 HWND hwndPrevParent;
169 } REBAR_BAND;
171 /* fStatus flags */
172 #define HAS_GRIPPER 0x00000001
173 #define HAS_IMAGE 0x00000002
174 #define HAS_TEXT 0x00000004
176 /* fDraw flags */
177 #define DRAW_GRIPPER 0x00000001
178 #define DRAW_IMAGE 0x00000002
179 #define DRAW_TEXT 0x00000004
180 #define DRAW_RIGHTSEP 0x00000010
181 #define DRAW_BOTTOMSEP 0x00000020
182 #define NTF_INVALIDATE 0x01000000
184 typedef struct
186 INT istartband; /* index of first band in row */
187 INT iendband; /* index of last band in row */
188 } REBAR_ROW;
191 typedef struct
193 COLORREF clrBk; /* background color */
194 COLORREF clrText; /* text color */
195 COLORREF clrBtnText; /* system color for BTNTEXT */
196 COLORREF clrBtnFace; /* system color for BTNFACE */
197 HIMAGELIST himl; /* handle to imagelist */
198 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
199 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
200 HWND hwndSelf; /* handle of REBAR window itself */
201 HWND hwndToolTip; /* handle to the tool tip control */
202 HWND hwndNotify; /* notification window (parent) */
203 HFONT hDefaultFont;
204 HFONT hFont; /* handle to the rebar's font */
205 SIZE imageSize; /* image size (image list) */
206 DWORD dwStyle; /* window style */
207 SIZE calcSize; /* calculated rebar size */
208 SIZE oldSize; /* previous calculated rebar size */
209 BOOL bUnicode; /* TRUE if this window is W type */
210 BOOL NtfUnicode; /* TRUE if parent wants notify in W format */
211 BOOL DoRedraw; /* TRUE to acutally draw bands */
212 UINT fStatus; /* Status flags (see below) */
213 HCURSOR hcurArrow; /* handle to the arrow cursor */
214 HCURSOR hcurHorz; /* handle to the EW cursor */
215 HCURSOR hcurVert; /* handle to the NS cursor */
216 HCURSOR hcurDrag; /* handle to the drag cursor */
217 INT iVersion; /* version number */
218 POINTS dragStart; /* x,y of button down */
219 POINTS dragNow; /* x,y of this MouseMove */
220 INT ihitBand; /* band number of band whose gripper was grabbed */
221 INT ihitoffset; /* offset of hotspot from gripper.left */
223 REBAR_ROW *rows; /* pointer to row indexes */
224 REBAR_BAND *bands; /* pointer to the array of rebar bands */
225 } REBAR_INFO;
227 /* fStatus flags */
228 #define BEGIN_DRAG_ISSUED 0x00000001
229 #define AUTO_RESIZE 0x00000002
230 #define RESIZE_ANYHOW 0x00000004
231 #define NTF_HGHTCHG 0x00000008
232 #define BAND_NEEDS_LAYOUT 0x00000010
233 #define BAND_NEEDS_REDRAW 0x00000020
234 #define CREATE_RUNNING 0x00000040
236 /* ---- REBAR layout constants. Mostly determined by ---- */
237 /* ---- experiment on WIN 98. ---- */
239 /* Width (or height) of separators between bands (either horz. or */
240 /* vert.). True only if RBS_BANDBORDERS is set */
241 #define SEP_WIDTH_SIZE 2
242 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
244 /* Blank (background color) space between Gripper (if present) */
245 /* and next item (image, text, or window). Always present */
246 #define REBAR_ALWAYS_SPACE 4
248 /* Blank (background color) space after Image (if present). */
249 #define REBAR_POST_IMAGE 2
251 /* Blank (background color) space after Text (if present). */
252 #define REBAR_POST_TEXT 4
254 /* Height of vertical gripper in a CCS_VERT rebar. */
255 #define GRIPPER_HEIGHT 16
257 /* Blank (background color) space before Gripper (if present). */
258 #define REBAR_PRE_GRIPPER 2
260 /* Width (of normal vertical gripper) or height (of horz. gripper) */
261 /* if present. */
262 #define GRIPPER_WIDTH 3
264 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
265 /* either top or bottom */
266 #define REBAR_DIVIDER 2
268 /* This is the increment that is used over the band height */
269 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
271 /* ---- End of REBAR layout constants. ---- */
274 /* The following 6 defines return the proper rcBand element */
275 /* depending on whether CCS_VERT was set. */
276 #define rcBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.top : b->rcBand.left)
277 #define rcBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.bottom : b->rcBand.right)
278 #define rcBw(b) ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.bottom - b->rcBand.top) : \
279 (b->rcBand.right - b->rcBand.left))
280 #define ircBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.left : b->rcBand.top)
281 #define ircBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.right : b->rcBand.bottom)
282 #define ircBw(b) ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.right - b->rcBand.left) : \
283 (b->rcBand.bottom - b->rcBand.top))
285 /* The following define determines if a given band is hidden */
286 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
287 ((infoPtr->dwStyle & CCS_VERT) && \
288 ((a)->fStyle & RBBS_NOVERT)))
290 /* The following defines adjust the right or left end of a rectangle */
291 #define READJ(b,i) {if(infoPtr->dwStyle & CCS_VERT) b->rcBand.bottom+=(i); \
292 else b->rcBand.right += (i);}
293 #define LEADJ(b,i) {if(infoPtr->dwStyle & CCS_VERT) b->rcBand.top+=(i); \
294 else b->rcBand.left += (i);}
297 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongA (hwnd, 0))
300 /* "constant values" retrieved when DLL was initialized */
301 /* FIXME we do this when the classes are registered. */
302 static UINT mindragx = 0;
303 static UINT mindragy = 0;
305 static char *band_stylename[] = {
306 "RBBS_BREAK", /* 0001 */
307 "RBBS_FIXEDSIZE", /* 0002 */
308 "RBBS_CHILDEDGE", /* 0004 */
309 "RBBS_HIDDEN", /* 0008 */
310 "RBBS_NOVERT", /* 0010 */
311 "RBBS_FIXEDBMP", /* 0020 */
312 "RBBS_VARIABLEHEIGHT", /* 0040 */
313 "RBBS_GRIPPERALWAYS", /* 0080 */
314 "RBBS_NOGRIPPER", /* 0100 */
315 NULL };
317 static char *band_maskname[] = {
318 "RBBIM_STYLE", /* 0x00000001 */
319 "RBBIM_COLORS", /* 0x00000002 */
320 "RBBIM_TEXT", /* 0x00000004 */
321 "RBBIM_IMAGE", /* 0x00000008 */
322 "RBBIM_CHILD", /* 0x00000010 */
323 "RBBIM_CHILDSIZE", /* 0x00000020 */
324 "RBBIM_SIZE", /* 0x00000040 */
325 "RBBIM_BACKGROUND", /* 0x00000080 */
326 "RBBIM_ID", /* 0x00000100 */
327 "RBBIM_IDEALSIZE", /* 0x00000200 */
328 "RBBIM_LPARAM", /* 0x00000400 */
329 "RBBIM_HEADERSIZE", /* 0x00000800 */
330 NULL };
333 static CHAR line[200];
336 static CHAR *
337 REBAR_FmtStyle( UINT style)
339 INT i = 0;
341 *line = 0;
342 while (band_stylename[i]) {
343 if (style & (1<<i)) {
344 if (*line != 0) strcat(line, " | ");
345 strcat(line, band_stylename[i]);
347 i++;
349 return line;
353 static CHAR *
354 REBAR_FmtMask( UINT mask)
356 INT i = 0;
358 *line = 0;
359 while (band_maskname[i]) {
360 if (mask & (1<<i)) {
361 if (*line != 0) strcat(line, " | ");
362 strcat(line, band_maskname[i]);
364 i++;
366 return line;
370 static VOID
371 REBAR_DumpBandInfo( LPREBARBANDINFOA pB)
373 if( !TRACE_ON(rebar) ) return;
374 TRACE("band info: ID=%u, size=%u, child=%04x, clrF=0x%06lx, clrB=0x%06lx\n",
375 pB->wID, pB->cbSize, pB->hwndChild, pB->clrFore, pB->clrBack);
376 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
377 if (pB->fMask & RBBIM_STYLE)
378 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
379 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
380 TRACE("band info:");
381 if (pB->fMask & RBBIM_SIZE)
382 DPRINTF(" cx=%u", pB->cx);
383 if (pB->fMask & RBBIM_IDEALSIZE)
384 DPRINTF(" xIdeal=%u", pB->cxIdeal);
385 if (pB->fMask & RBBIM_HEADERSIZE)
386 DPRINTF(" xHeader=%u", pB->cxHeader);
387 if (pB->fMask & RBBIM_LPARAM)
388 DPRINTF(" lParam=0x%08lx", pB->lParam);
389 DPRINTF("\n");
391 if (pB->fMask & RBBIM_CHILDSIZE)
392 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
393 pB->cxMinChild,
394 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
397 static VOID
398 REBAR_DumpBand (REBAR_INFO *iP)
400 REBAR_BAND *pB;
401 UINT i;
403 if(! TRACE_ON(rebar) ) return;
405 TRACE("hwnd=%04x: color=%08lx/%08lx, bands=%u, rows=%u, cSize=%ld,%ld\n",
406 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
407 iP->calcSize.cx, iP->calcSize.cy);
408 TRACE("hwnd=%04x: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, ihitBand=%d\n",
409 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
410 iP->dragNow.x, iP->dragNow.y,
411 iP->ihitBand);
412 TRACE("hwnd=%04x: style=%08lx, I'm Unicode=%s, notify in Unicode=%s, redraw=%s\n",
413 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
414 (iP->NtfUnicode)?"TRUE":"FALSE", (iP->DoRedraw)?"TRUE":"FALSE");
415 for (i = 0; i < iP->uNumBands; i++) {
416 pB = &iP->bands[i];
417 TRACE("band # %u: ID=%u, child=%04x, row=%u, clrF=0x%06lx, clrB=0x%06lx\n",
418 i, pB->wID, pB->hwndChild, pB->iRow, pB->clrFore, pB->clrBack);
419 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
420 if (pB->fMask & RBBIM_STYLE)
421 TRACE("band # %u: style=0x%08x (%s)\n",
422 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
423 TRACE("band # %u: uMinH=%u xHeader=%u",
424 i, pB->uMinHeight, pB->cxHeader);
425 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
426 if (pB->fMask & RBBIM_SIZE)
427 DPRINTF(" cx=%u", pB->cx);
428 if (pB->fMask & RBBIM_IDEALSIZE)
429 DPRINTF(" xIdeal=%u", pB->cxIdeal);
430 if (pB->fMask & RBBIM_LPARAM)
431 DPRINTF(" lParam=0x%08lx", pB->lParam);
433 DPRINTF("\n");
434 if (RBBIM_CHILDSIZE)
435 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
436 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
437 if (pB->fMask & RBBIM_TEXT)
438 TRACE("band # %u: text=%s\n",
439 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
440 TRACE("band # %u: lcx=%u, ccx=%u, hcx=%u, lcy=%u, ccy=%u, hcy=%u, offChild=%ld,%ld\n",
441 i, pB->lcx, pB->ccx, pB->hcx, pB->lcy, pB->ccy, pB->hcy, pB->offChild.cx, pB->offChild.cy);
442 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%d,%d)-(%d,%d), Grip=(%d,%d)-(%d,%d)\n",
443 i, pB->fStatus, pB->fDraw,
444 pB->rcBand.left, pB->rcBand.top, pB->rcBand.right, pB->rcBand.bottom,
445 pB->rcGripper.left, pB->rcGripper.top, pB->rcGripper.right, pB->rcGripper.bottom);
446 TRACE("band # %u: Img=(%d,%d)-(%d,%d), Txt=(%d,%d)-(%d,%d), Child=(%d,%d)-(%d,%d)\n",
448 pB->rcCapImage.left, pB->rcCapImage.top, pB->rcCapImage.right, pB->rcCapImage.bottom,
449 pB->rcCapText.left, pB->rcCapText.top, pB->rcCapText.right, pB->rcCapText.bottom,
450 pB->rcChild.left, pB->rcChild.top, pB->rcChild.right, pB->rcChild.bottom);
456 static HWND
457 REBAR_GetNotifyParent (REBAR_INFO *infoPtr)
459 HWND parent, owner;
461 parent = infoPtr->hwndNotify;
462 if (!parent) {
463 parent = GetParent (infoPtr->hwndSelf);
464 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
465 if (owner) parent = owner;
467 return parent;
471 static INT
472 REBAR_Notify (NMHDR *nmhdr, REBAR_INFO *infoPtr, UINT code)
474 HWND parent;
476 parent = REBAR_GetNotifyParent (infoPtr);
477 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
478 nmhdr->hwndFrom = infoPtr->hwndSelf;
479 nmhdr->code = code;
481 TRACE("window %04x, code=%08x, %s\n", parent, code,
482 (infoPtr->NtfUnicode) ? "via Unicode" : "via ANSI");
484 if (infoPtr->NtfUnicode)
485 return SendMessageW (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
486 (LPARAM)nmhdr);
487 else
488 return SendMessageA (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
489 (LPARAM)nmhdr);
492 static INT
493 REBAR_Notify_NMREBAR (REBAR_INFO *infoPtr, UINT uBand, UINT code)
495 NMREBAR notify_rebar;
496 REBAR_BAND *lpBand;
498 notify_rebar.dwMask = 0;
499 if (uBand!=-1) {
500 lpBand = &infoPtr->bands[uBand];
501 if (lpBand->fMask & RBBIM_ID) {
502 notify_rebar.dwMask |= RBNM_ID;
503 notify_rebar.wID = lpBand->wID;
505 if (lpBand->fMask & RBBIM_LPARAM) {
506 notify_rebar.dwMask |= RBNM_LPARAM;
507 notify_rebar.lParam = lpBand->lParam;
509 if (lpBand->fMask & RBBIM_STYLE) {
510 notify_rebar.dwMask |= RBNM_STYLE;
511 notify_rebar.fStyle = lpBand->fStyle;
514 notify_rebar.uBand = uBand;
515 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
518 static VOID
519 REBAR_DrawBand (HDC hdc, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
521 HFONT hOldFont = 0;
522 INT oldBkMode = 0;
523 NMCUSTOMDRAW nmcd;
525 if (lpBand->fDraw & DRAW_TEXT) {
526 hOldFont = SelectObject (hdc, infoPtr->hFont);
527 oldBkMode = SetBkMode (hdc, TRANSPARENT);
530 /* should test for CDRF_NOTIFYITEMDRAW here */
531 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
532 nmcd.hdc = hdc;
533 nmcd.rc = lpBand->rcBand;
534 nmcd.rc.right = lpBand->rcCapText.right;
535 nmcd.rc.bottom = lpBand->rcCapText.bottom;
536 nmcd.dwItemSpec = lpBand->wID;
537 nmcd.uItemState = 0;
538 nmcd.lItemlParam = lpBand->lParam;
539 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
540 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
541 if (oldBkMode != TRANSPARENT)
542 SetBkMode (hdc, oldBkMode);
543 SelectObject (hdc, hOldFont);
544 return;
547 /* draw gripper */
548 if (lpBand->fDraw & DRAW_GRIPPER)
549 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
551 /* draw caption image */
552 if (lpBand->fDraw & DRAW_IMAGE) {
553 POINT pt;
555 /* center image */
556 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
557 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
559 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
560 pt.x, pt.y,
561 ILD_TRANSPARENT);
564 /* draw caption text */
565 if (lpBand->fDraw & DRAW_TEXT) {
566 /* need to handle CDRF_NEWFONT here */
567 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
568 COLORREF oldcolor = CLR_NONE;
569 oldcolor = SetTextColor (hdc, (lpBand->clrFore != CLR_NONE) ?
570 lpBand->clrFore : infoPtr->clrBtnText);
571 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
572 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
573 if (oldBkMode != TRANSPARENT)
574 SetBkMode (hdc, oldBkMode);
575 SetTextColor (hdc, oldcolor);
576 SelectObject (hdc, hOldFont);
579 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
580 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
581 nmcd.hdc = hdc;
582 nmcd.rc = lpBand->rcBand;
583 nmcd.rc.right = lpBand->rcCapText.right;
584 nmcd.rc.bottom = lpBand->rcCapText.bottom;
585 nmcd.dwItemSpec = lpBand->wID;
586 nmcd.uItemState = 0;
587 nmcd.lItemlParam = lpBand->lParam;
588 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
593 static VOID
594 REBAR_Refresh (REBAR_INFO *infoPtr, HDC hdc)
596 REBAR_BAND *lpBand;
597 UINT i, oldrow;
599 if (!infoPtr->DoRedraw) return;
601 oldrow = infoPtr->bands[0].iRow;
602 for (i = 0; i < infoPtr->uNumBands; i++) {
603 lpBand = &infoPtr->bands[i];
605 if (HIDDENBAND(lpBand)) continue;
607 /* now draw the band */
608 TRACE("[%04x] drawing band %i, flags=%08x\n",
609 infoPtr->hwndSelf, i, lpBand->fDraw);
610 REBAR_DrawBand (hdc, infoPtr, lpBand);
616 static void
617 REBAR_FixVert (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
618 INT mcy)
619 /* Function: */
620 /* Cycle through bands in row and fix height of each band. */
621 /* Also determine whether each band has changed. */
622 /* On entry: */
623 /* all bands at desired size. */
624 /* start and end bands are *not* hidden */
626 REBAR_BAND *lpBand;
627 INT i;
629 for (i = (INT)rowstart; i<=(INT)rowend; i++) {
630 lpBand = &infoPtr->bands[i];
631 if (HIDDENBAND(lpBand)) continue;
633 /* adjust height of bands in row to "mcy" value */
634 if (infoPtr->dwStyle & CCS_VERT) {
635 if (lpBand->rcBand.right != lpBand->rcBand.left + mcy)
636 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
638 else {
639 if (lpBand->rcBand.bottom != lpBand->rcBand.top + mcy)
640 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
644 /* mark whether we need to invalidate this band and trace */
645 if ((lpBand->rcoldBand.left !=lpBand->rcBand.left) ||
646 (lpBand->rcoldBand.top !=lpBand->rcBand.top) ||
647 (lpBand->rcoldBand.right !=lpBand->rcBand.right) ||
648 (lpBand->rcoldBand.bottom !=lpBand->rcBand.bottom)) {
649 lpBand->fDraw |= NTF_INVALIDATE;
650 TRACE("band %d row=%d: changed to (%d,%d)-(%d,%d) from (%d,%d)-(%d,%d)\n",
651 i, lpBand->iRow,
652 lpBand->rcBand.left, lpBand->rcBand.top,
653 lpBand->rcBand.right, lpBand->rcBand.bottom,
654 lpBand->rcoldBand.left, lpBand->rcoldBand.top,
655 lpBand->rcoldBand.right, lpBand->rcoldBand.bottom);
657 else
658 TRACE("band %d row=%d: unchanged (%d,%d)-(%d,%d)\n",
659 i, lpBand->iRow,
660 lpBand->rcBand.left, lpBand->rcBand.top,
661 lpBand->rcBand.right, lpBand->rcBand.bottom);
666 static void
667 REBAR_AdjustBands (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
668 INT maxx, INT mcy)
669 /* Function: This routine distributes the extra space in a row. */
670 /* See algorithm below. */
671 /* On entry: */
672 /* all bands @ ->cxHeader size */
673 /* start and end bands are *not* hidden */
675 REBAR_BAND *lpBand;
676 UINT x, xsep, extra, curwidth, fudge;
677 INT i, last_adjusted;
679 TRACE("start=%u, end=%u, max x=%d, max y=%d\n",
680 rowstart, rowend, maxx, mcy);
682 /* ******************* Phase 1 ************************ */
683 /* Alg: */
684 /* For each visible band with valid child */
685 /* a. inflate band till either all extra space used */
686 /* or band's ->ccx reached. */
687 /* If any band modified, add any space left to last band */
688 /* adjusted. */
689 /* */
690 /* ****************************************************** */
691 lpBand = &infoPtr->bands[rowend];
692 extra = maxx - rcBrb(lpBand);
693 x = 0;
694 last_adjusted = -1;
695 for (i=(INT)rowstart; i<=(INT)rowend; i++) {
696 lpBand = &infoPtr->bands[i];
697 if (HIDDENBAND(lpBand)) continue;
698 xsep = (x == 0) ? 0 : SEP_WIDTH;
699 curwidth = rcBw(lpBand);
701 /* set new left/top point */
702 if (infoPtr->dwStyle & CCS_VERT)
703 lpBand->rcBand.top = x + xsep;
704 else
705 lpBand->rcBand.left = x + xsep;
707 /* compute new width */
708 if (lpBand->hwndChild && extra) {
709 /* set to the "current" band size less the header */
710 fudge = lpBand->ccx;
711 last_adjusted = i;
712 if ((lpBand->fMask & RBBIM_SIZE) && (lpBand->cx > 0) &&
713 (fudge > curwidth)) {
714 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d, extra=%d\n",
715 i, fudge-curwidth, fudge, curwidth, extra);
716 if ((fudge - curwidth) > extra)
717 fudge = curwidth + extra;
718 extra -= (fudge - curwidth);
719 curwidth = fudge;
721 else {
722 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d\n",
723 i, extra, fudge, curwidth);
724 curwidth += extra;
725 extra = 0;
729 /* set new right/bottom point */
730 if (infoPtr->dwStyle & CCS_VERT)
731 lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
732 else
733 lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
734 TRACE("Phase 1 band %d, (%d,%d)-(%d,%d), orig x=%d, xsep=%d\n",
735 i, lpBand->rcBand.left, lpBand->rcBand.top,
736 lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
737 x = rcBrb(lpBand);
739 if ((x >= maxx) || (last_adjusted != -1)) {
740 if (x > maxx) {
741 ERR("Phase 1 failed, x=%d, maxx=%d, start=%u, end=%u\n",
742 x, maxx, rowstart, rowend);
744 /* done, so spread extra space */
745 if (x < maxx) {
746 fudge = maxx - x;
747 TRACE("Need to spread %d on last adjusted band %d\n",
748 fudge, last_adjusted);
749 for (i=(INT)last_adjusted; i<=(INT)rowend; i++) {
750 lpBand = &infoPtr->bands[i];
751 if (HIDDENBAND(lpBand)) continue;
753 /* set right/bottom point */
754 if (i != last_adjusted) {
755 if (infoPtr->dwStyle & CCS_VERT)
756 lpBand->rcBand.top += fudge;
757 else
758 lpBand->rcBand.left += fudge;
761 /* set left/bottom point */
762 if (infoPtr->dwStyle & CCS_VERT)
763 lpBand->rcBand.bottom += fudge;
764 else
765 lpBand->rcBand.right += fudge;
768 TRACE("Phase 1 succeeded, used x=%d\n", x);
769 REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
770 return;
773 /* ******************* Phase 2 ************************ */
774 /* Alg: */
775 /* Find first visible band, put all */
776 /* extra space there. */
777 /* */
778 /* ****************************************************** */
780 x = 0;
781 for (i=(INT)rowstart; i<=(INT)rowend; i++) {
782 lpBand = &infoPtr->bands[i];
783 if (HIDDENBAND(lpBand)) continue;
784 xsep = (x == 0) ? 0 : SEP_WIDTH;
785 curwidth = rcBw(lpBand);
787 /* set new left/top point */
788 if (infoPtr->dwStyle & CCS_VERT)
789 lpBand->rcBand.top = x + xsep;
790 else
791 lpBand->rcBand.left = x + xsep;
793 /* compute new width */
794 if (extra) {
795 curwidth += extra;
796 extra = 0;
799 /* set new right/bottom point */
800 if (infoPtr->dwStyle & CCS_VERT)
801 lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
802 else
803 lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
804 TRACE("Phase 2 band %d, (%d,%d)-(%d,%d), orig x=%d, xsep=%d\n",
805 i, lpBand->rcBand.left, lpBand->rcBand.top,
806 lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
807 x = rcBrb(lpBand);
809 if (x >= maxx) {
810 if (x > maxx) {
811 ERR("Phase 2 failed, x=%d, maxx=%d, start=%u, end=%u\n",
812 x, maxx, rowstart, rowend);
814 /* done, so spread extra space */
815 TRACE("Phase 2 succeeded, used x=%d\n", x);
816 REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
817 return;
820 /* ******************* Phase 3 ************************ */
821 /* at this point everything is back to ->cxHeader values */
822 /* and should not have gotten here. */
823 /* ****************************************************** */
825 lpBand = &infoPtr->bands[rowstart];
826 ERR("Serious problem adjusting row %d, start band %d, end band %d\n",
827 lpBand->iRow, rowstart, rowend);
828 REBAR_DumpBand (infoPtr);
829 return;
833 static void
834 REBAR_CalcHorzBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
835 /* Function: this routine initializes all the rectangles in */
836 /* each band in a row to fit in the adjusted rcBand rect. */
837 /* *** Supports only Horizontal bars. *** */
839 REBAR_BAND *lpBand;
840 UINT i, xoff, yoff;
841 HWND parenthwnd;
842 RECT oldChild, work;
844 /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
845 parenthwnd = GetParent (infoPtr->hwndSelf);
847 for(i=rstart; i<rend; i++){
848 lpBand = &infoPtr->bands[i];
849 if (HIDDENBAND(lpBand)) {
850 SetRect (&lpBand->rcChild,
851 lpBand->rcBand.right, lpBand->rcBand.top,
852 lpBand->rcBand.right, lpBand->rcBand.bottom);
853 continue;
856 oldChild = lpBand->rcChild;
858 /* set initial gripper rectangle */
859 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
860 lpBand->rcBand.left, lpBand->rcBand.bottom);
862 /* calculate gripper rectangle */
863 if ( lpBand->fStatus & HAS_GRIPPER) {
864 lpBand->fDraw |= DRAW_GRIPPER;
865 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
866 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
867 lpBand->rcGripper.top += 2;
868 lpBand->rcGripper.bottom -= 2;
870 SetRect (&lpBand->rcCapImage,
871 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
872 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
874 else { /* no gripper will be drawn */
875 xoff = 0;
876 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
877 /* if no gripper but either image or text, then leave space */
878 xoff = REBAR_ALWAYS_SPACE;
879 SetRect (&lpBand->rcCapImage,
880 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
881 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
884 /* image is visible */
885 if (lpBand->fStatus & HAS_IMAGE) {
886 lpBand->fDraw |= DRAW_IMAGE;
887 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
888 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
890 /* set initial caption text rectangle */
891 SetRect (&lpBand->rcCapText,
892 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
893 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
894 /* update band height
895 if (lpBand->uMinHeight < infoPtr->imageSize.cy + 2) {
896 lpBand->uMinHeight = infoPtr->imageSize.cy + 2;
897 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->uMinHeight;
898 } */
900 else {
901 /* set initial caption text rectangle */
902 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
903 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
906 /* text is visible */
907 if (lpBand->fStatus & HAS_TEXT) {
908 lpBand->fDraw |= DRAW_TEXT;
909 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
910 lpBand->rcCapText.right-REBAR_POST_TEXT);
913 /* set initial child window rectangle if there is a child */
914 if (lpBand->fMask & RBBIM_CHILD) {
915 xoff = lpBand->offChild.cx;
916 yoff = lpBand->offChild.cy;
917 SetRect (&lpBand->rcChild,
918 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top+yoff,
919 lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
921 else {
922 SetRect (&lpBand->rcChild,
923 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
924 lpBand->rcBand.right, lpBand->rcBand.bottom);
927 /* flag if notify required and invalidate rectangle */
928 if (notify &&
929 ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
930 (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
931 TRACE("Child rectangle changed for band %u\n", i);
932 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
933 oldChild.left, oldChild.top,
934 oldChild.right, oldChild.bottom,
935 lpBand->rcChild.left, lpBand->rcChild.top,
936 lpBand->rcChild.right, lpBand->rcChild.bottom);
938 if (lpBand->fDraw & NTF_INVALIDATE) {
939 TRACE("invalidating (%d,%d)-(%d,%d)\n",
940 lpBand->rcBand.left,
941 lpBand->rcBand.top,
942 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0),
943 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0));
944 lpBand->fDraw &= ~NTF_INVALIDATE;
945 work = lpBand->rcBand;
946 if (lpBand->fDraw & DRAW_RIGHTSEP) work.right += SEP_WIDTH_SIZE;
947 if (lpBand->fDraw & DRAW_BOTTOMSEP) work.bottom += SEP_WIDTH_SIZE;
948 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
956 static VOID
957 REBAR_CalcVertBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
958 /* Function: this routine initializes all the rectangles in */
959 /* each band in a row to fit in the adjusted rcBand rect. */
960 /* *** Supports only Vertical bars. *** */
962 REBAR_BAND *lpBand;
963 UINT i, xoff, yoff;
964 HWND parenthwnd;
965 RECT oldChild, work;
967 /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
968 parenthwnd = GetParent (infoPtr->hwndSelf);
970 for(i=rstart; i<rend; i++){
971 lpBand = &infoPtr->bands[i];
972 if (HIDDENBAND(lpBand)) continue;
973 oldChild = lpBand->rcChild;
975 /* set initial gripper rectangle */
976 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
977 lpBand->rcBand.right, lpBand->rcBand.top);
979 /* calculate gripper rectangle */
980 if (lpBand->fStatus & HAS_GRIPPER) {
981 lpBand->fDraw |= DRAW_GRIPPER;
983 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
984 /* vertical gripper */
985 lpBand->rcGripper.left += 3;
986 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
987 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
988 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
990 /* initialize Caption image rectangle */
991 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
992 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
993 lpBand->rcBand.right,
994 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
996 else {
997 /* horizontal gripper */
998 lpBand->rcGripper.left += 2;
999 lpBand->rcGripper.right -= 2;
1000 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
1001 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
1003 /* initialize Caption image rectangle */
1004 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1005 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1006 lpBand->rcBand.right,
1007 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1010 else { /* no gripper will be drawn */
1011 xoff = 0;
1012 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
1013 /* if no gripper but either image or text, then leave space */
1014 xoff = REBAR_ALWAYS_SPACE;
1015 /* initialize Caption image rectangle */
1016 SetRect (&lpBand->rcCapImage,
1017 lpBand->rcBand.left, lpBand->rcBand.top+xoff,
1018 lpBand->rcBand.right, lpBand->rcBand.top+xoff);
1021 /* image is visible */
1022 if (lpBand->fStatus & HAS_IMAGE) {
1023 lpBand->fDraw |= DRAW_IMAGE;
1025 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
1026 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
1028 /* set initial caption text rectangle */
1029 SetRect (&lpBand->rcCapText,
1030 lpBand->rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
1031 lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1032 /* update band height *
1033 if (lpBand->uMinHeight < infoPtr->imageSize.cx + 2) {
1034 lpBand->uMinHeight = infoPtr->imageSize.cx + 2;
1035 lpBand->rcBand.right = lpBand->rcBand.left + lpBand->uMinHeight;
1036 } */
1038 else {
1039 /* set initial caption text rectangle */
1040 SetRect (&lpBand->rcCapText,
1041 lpBand->rcBand.left, lpBand->rcCapImage.bottom,
1042 lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1045 /* text is visible */
1046 if (lpBand->fStatus & HAS_TEXT) {
1047 lpBand->fDraw |= DRAW_TEXT;
1048 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
1049 lpBand->rcCapText.bottom);
1052 /* set initial child window rectangle if there is a child */
1053 if (lpBand->fMask & RBBIM_CHILD) {
1054 yoff = lpBand->offChild.cx;
1055 xoff = lpBand->offChild.cy;
1056 SetRect (&lpBand->rcChild,
1057 lpBand->rcBand.left+xoff, lpBand->rcBand.top+lpBand->cxHeader,
1058 lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
1060 else {
1061 SetRect (&lpBand->rcChild,
1062 lpBand->rcBand.left, lpBand->rcBand.top+lpBand->cxHeader,
1063 lpBand->rcBand.right, lpBand->rcBand.bottom);
1066 /* flag if notify required and invalidate rectangle */
1067 if (notify &&
1068 ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
1069 (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
1070 TRACE("Child rectangle changed for band %u\n", i);
1071 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
1072 oldChild.left, oldChild.top,
1073 oldChild.right, oldChild.bottom,
1074 lpBand->rcChild.left, lpBand->rcChild.top,
1075 lpBand->rcChild.right, lpBand->rcChild.bottom);
1077 if (lpBand->fDraw & NTF_INVALIDATE) {
1078 TRACE("invalidating (%d,%d)-(%d,%d)\n",
1079 lpBand->rcBand.left,
1080 lpBand->rcBand.top,
1081 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0),
1082 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0));
1083 lpBand->fDraw &= ~NTF_INVALIDATE;
1084 work = lpBand->rcBand;
1085 if (lpBand->fDraw & DRAW_RIGHTSEP) work.bottom += SEP_WIDTH_SIZE;
1086 if (lpBand->fDraw & DRAW_BOTTOMSEP) work.right += SEP_WIDTH_SIZE;
1087 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
1094 static VOID
1095 REBAR_ForceResize (REBAR_INFO *infoPtr)
1096 /* Function: This changes the size of the REBAR window to that */
1097 /* calculated by REBAR_Layout. */
1099 RECT rc;
1100 INT x, y, width, height;
1101 INT xedge = GetSystemMetrics(SM_CXEDGE);
1102 INT yedge = GetSystemMetrics(SM_CYEDGE);
1104 /* TEST TEST TEST */
1105 GetWindowRect (infoPtr->hwndSelf, &rc);
1106 /* END TEST END TEST END TEST */
1109 GetClientRect (infoPtr->hwndSelf, &rc);
1111 TRACE( " old [%ld x %ld], new [%ld x %ld], client [%d x %d]\n",
1112 infoPtr->oldSize.cx, infoPtr->oldSize.cy,
1113 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1114 rc.right, rc.bottom);
1116 /* If we need to shrink client, then skip size test */
1117 if ((infoPtr->calcSize.cy >= rc.bottom) &&
1118 (infoPtr->calcSize.cx >= rc.right)) {
1120 /* if size did not change then skip process */
1121 if ((infoPtr->oldSize.cx == infoPtr->calcSize.cx) &&
1122 (infoPtr->oldSize.cy == infoPtr->calcSize.cy) &&
1123 !(infoPtr->fStatus & RESIZE_ANYHOW))
1125 TRACE("skipping reset\n");
1126 return;
1130 infoPtr->fStatus &= ~RESIZE_ANYHOW;
1131 /* Set flag to ignore next WM_SIZE message */
1132 infoPtr->fStatus |= AUTO_RESIZE;
1134 width = 0;
1135 height = 0;
1136 x = 0;
1137 y = 0;
1139 if (infoPtr->dwStyle & WS_BORDER) {
1140 width = 2 * xedge;
1141 height = 2 * yedge;
1144 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
1145 INT mode = infoPtr->dwStyle & (CCS_VERT | CCS_TOP | CCS_BOTTOM);
1146 RECT rcPcl;
1148 GetClientRect(GetParent(infoPtr->hwndSelf), &rcPcl);
1149 switch (mode) {
1150 case CCS_TOP:
1151 /* _TOP sets width to parents width */
1152 width += (rcPcl.right - rcPcl.left);
1153 height += infoPtr->calcSize.cy;
1154 x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1155 y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1156 y += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1157 break;
1158 case CCS_BOTTOM:
1159 /* FIXME: wrong wrong wrong */
1160 /* _BOTTOM sets width to parents width */
1161 width += (rcPcl.right - rcPcl.left);
1162 height += infoPtr->calcSize.cy;
1163 x += -xedge;
1164 y = rcPcl.bottom - height + 1;
1165 break;
1166 case CCS_LEFT:
1167 /* _LEFT sets height to parents height */
1168 width += infoPtr->calcSize.cx;
1169 height += (rcPcl.bottom - rcPcl.top);
1170 x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1171 x += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1172 y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1173 break;
1174 case CCS_RIGHT:
1175 /* FIXME: wrong wrong wrong */
1176 /* _RIGHT sets height to parents height */
1177 width += infoPtr->calcSize.cx;
1178 height += (rcPcl.bottom - rcPcl.top);
1179 x = rcPcl.right - width + 1;
1180 y = -yedge;
1181 break;
1182 default:
1183 width += infoPtr->calcSize.cx;
1184 height += infoPtr->calcSize.cy;
1187 else {
1188 width += infoPtr->calcSize.cx;
1189 height += infoPtr->calcSize.cy;
1192 TRACE("hwnd %04x, style=%08lx, setting at (%d,%d) for (%d,%d)\n",
1193 infoPtr->hwndSelf, infoPtr->dwStyle,
1194 x, y, width, height);
1195 SetWindowPos (infoPtr->hwndSelf, 0, x, y, width, height,
1196 SWP_NOZORDER);
1200 static VOID
1201 REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
1203 REBAR_BAND *lpBand;
1204 CHAR szClassName[40];
1205 UINT i;
1206 NMREBARCHILDSIZE rbcz;
1207 NMHDR heightchange;
1208 HDWP deferpos;
1210 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1211 ERR("BeginDeferWindowPos returned NULL\n");
1213 for (i = start; i < endplus; i++) {
1214 lpBand = &infoPtr->bands[i];
1216 if (HIDDENBAND(lpBand)) continue;
1217 if (lpBand->hwndChild) {
1218 TRACE("hwndChild = %x\n", lpBand->hwndChild);
1220 /* Always geterate the RBN_CHILDSIZE even it child
1221 did not change */
1222 rbcz.uBand = i;
1223 rbcz.wID = lpBand->wID;
1224 rbcz.rcChild = lpBand->rcChild;
1225 rbcz.rcBand = lpBand->rcBand;
1226 rbcz.rcBand.left += lpBand->cxHeader;
1227 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1228 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1229 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1230 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
1231 lpBand->rcChild.left, lpBand->rcChild.top,
1232 lpBand->rcChild.right, lpBand->rcChild.bottom,
1233 rbcz.rcChild.left, rbcz.rcChild.top,
1234 rbcz.rcChild.right, rbcz.rcChild.bottom);
1235 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1238 /* native (IE4 in "Favorites" frame **1) does:
1239 * SetRect (&rc, -1, -1, -1, -1)
1240 * EqualRect (&rc,band->rc???)
1241 * if ret==0
1242 * CopyRect (band->rc????, &rc)
1243 * set flag outside of loop
1246 GetClassNameA (lpBand->hwndChild, szClassName, 40);
1247 if (!lstrcmpA (szClassName, "ComboBox") ||
1248 !lstrcmpA (szClassName, WC_COMBOBOXEXA)) {
1249 INT nEditHeight, yPos;
1250 RECT rc;
1252 /* special placement code for combo or comboex box */
1255 /* get size of edit line */
1256 GetWindowRect (lpBand->hwndChild, &rc);
1257 nEditHeight = rc.bottom - rc.top;
1258 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1260 /* center combo box inside child area */
1261 TRACE("moving child (Combo(Ex)) %04x to (%d,%d) for (%d,%d)\n",
1262 lpBand->hwndChild,
1263 lpBand->rcChild.left, yPos,
1264 lpBand->rcChild.right - lpBand->rcChild.left,
1265 nEditHeight);
1266 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1267 lpBand->rcChild.left,
1268 /*lpBand->rcChild.top*/ yPos,
1269 lpBand->rcChild.right - lpBand->rcChild.left,
1270 nEditHeight,
1271 SWP_NOZORDER);
1272 if (!deferpos)
1273 ERR("DeferWindowPos returned NULL\n");
1275 else {
1276 TRACE("moving child (Other) %04x to (%d,%d) for (%d,%d)\n",
1277 lpBand->hwndChild,
1278 lpBand->rcChild.left, lpBand->rcChild.top,
1279 lpBand->rcChild.right - lpBand->rcChild.left,
1280 lpBand->rcChild.bottom - lpBand->rcChild.top);
1281 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1282 lpBand->rcChild.left,
1283 lpBand->rcChild.top,
1284 lpBand->rcChild.right - lpBand->rcChild.left,
1285 lpBand->rcChild.bottom - lpBand->rcChild.top,
1286 SWP_NOZORDER);
1287 if (!deferpos)
1288 ERR("DeferWindowPos returned NULL\n");
1292 if (!EndDeferWindowPos(deferpos))
1293 ERR("EndDeferWindowPos returned NULL\n");
1295 UpdateWindow (infoPtr->hwndSelf);
1297 if (infoPtr->fStatus & NTF_HGHTCHG) {
1298 infoPtr->fStatus &= ~NTF_HGHTCHG;
1299 REBAR_Notify (&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1302 /* native (from **1 above) does:
1303 * UpdateWindow(rebar)
1304 * REBAR_ForceResize
1305 * RBN_HEIGHTCHANGE if necessary
1306 * if ret from any EqualRect was 0
1307 * Goto "BeginDeferWindowPos"
1313 static VOID
1314 REBAR_Layout (REBAR_INFO *infoPtr, LPRECT lpRect, BOOL notify, BOOL resetclient)
1315 /* Function: This routine is resposible for laying out all */
1316 /* the bands in a rebar. It assigns each band to a row and*/
1317 /* determines when to start a new row. */
1319 REBAR_BAND *lpBand, *prevBand;
1320 RECT rcClient, rcAdj;
1321 INT initx, inity, x, y, cx, cxsep, mmcy, mcy, clientcx, clientcy;
1322 INT adjcx, adjcy, row, rightx, bottomy, origheight;
1323 UINT i, j, rowstart, origrows;
1324 BOOL dobreak;
1326 if (!(infoPtr->fStatus & BAND_NEEDS_LAYOUT)) {
1327 TRACE("no layout done. No band changed.\n");
1328 REBAR_DumpBand (infoPtr);
1329 return;
1331 infoPtr->fStatus &= ~BAND_NEEDS_LAYOUT;
1332 if (!infoPtr->DoRedraw) infoPtr->fStatus |= BAND_NEEDS_REDRAW;
1334 GetClientRect (infoPtr->hwndSelf, &rcClient);
1335 TRACE("Client is (%d,%d)-(%d,%d)\n",
1336 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
1338 if (lpRect) {
1339 rcAdj = *lpRect;
1340 TRACE("adjustment rect is (%d,%d)-(%d,%d)\n",
1341 rcAdj.left, rcAdj.top, rcAdj.right, rcAdj.bottom);
1343 else {
1344 CopyRect (&rcAdj, &rcClient);
1347 clientcx = rcClient.right - rcClient.left;
1348 clientcy = rcClient.bottom - rcClient.top;
1349 adjcx = rcAdj.right - rcAdj.left;
1350 adjcy = rcAdj.bottom - rcAdj.top;
1351 if (resetclient) {
1352 TRACE("window client rect will be set to adj rect\n");
1353 clientcx = adjcx;
1354 clientcy = adjcy;
1357 if (!infoPtr->DoRedraw && (clientcx == 0) && (clientcy == 0)) {
1358 ERR("no redraw and client is zero, skip layout\n");
1359 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1360 return;
1363 /* save height of original control */
1364 if (infoPtr->dwStyle & CCS_VERT)
1365 origheight = infoPtr->calcSize.cx;
1366 else
1367 origheight = infoPtr->calcSize.cy;
1368 origrows = infoPtr->uNumRows;
1370 initx = 0;
1371 inity = 0;
1373 /* ******* Start Phase 1 - all bands on row at minimum size ******* */
1375 TRACE("band loop constants, clientcx=%d, clientcy=%d, adjcx=%d, adjcy=%d\n",
1376 clientcx, clientcy, adjcx, adjcy);
1377 x = initx;
1378 y = inity;
1379 row = 1;
1380 cx = 0;
1381 mcy = 0;
1382 rowstart = 0;
1383 prevBand = NULL;
1385 for (i = 0; i < infoPtr->uNumBands; i++) {
1386 lpBand = &infoPtr->bands[i];
1387 lpBand->fDraw = 0;
1388 lpBand->iRow = row;
1390 if (HIDDENBAND(lpBand)) continue;
1392 lpBand->rcoldBand = lpBand->rcBand;
1394 /* Set the offset of the child window */
1395 if ((lpBand->fMask & RBBIM_CHILD) &&
1396 !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
1397 lpBand->offChild.cx = 4; /* ??? */
1399 lpBand->offChild.cy = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 2 : 0);
1401 /* separator from previous band */
1402 cxsep = ( ((infoPtr->dwStyle & CCS_VERT) ? y==inity : x==initx)) ?
1403 0 : SEP_WIDTH;
1405 /* Header: includes gripper, text, image */
1406 cx = lpBand->cxHeader;
1407 if (lpBand->fStyle & RBBS_FIXEDSIZE) cx = lpBand->lcx;
1409 if (infoPtr->dwStyle & CCS_VERT)
1410 dobreak = (y + cx + cxsep > adjcy);
1411 else
1412 dobreak = (x + cx + cxsep > adjcx);
1414 /* This is the check for whether we need to start a new row */
1415 if ( ( (lpBand->fStyle & RBBS_BREAK) && (i != 0) ) ||
1416 ( ((infoPtr->dwStyle & CCS_VERT) ? (y != 0) : (x != 0)) && dobreak)) {
1418 for (j = rowstart; j < i; j++) {
1419 REBAR_BAND *lpB;
1420 lpB = &infoPtr->bands[j];
1421 if (infoPtr->dwStyle & CCS_VERT) {
1422 lpB->rcBand.right = lpB->rcBand.left + mcy;
1424 else {
1425 lpB->rcBand.bottom = lpB->rcBand.top + mcy;
1429 TRACE("P1 Spliting to new row %d on band %u\n", row+1, i);
1430 if (infoPtr->dwStyle & CCS_VERT) {
1431 y = inity;
1432 x += (mcy + SEP_WIDTH);
1434 else {
1435 x = initx;
1436 y += (mcy + SEP_WIDTH);
1439 mcy = 0;
1440 cxsep = 0;
1441 row++;
1442 lpBand->iRow = row;
1443 prevBand = NULL;
1444 rowstart = i;
1447 if (mcy < lpBand->lcy + REBARSPACE(lpBand))
1448 mcy = lpBand->lcy + REBARSPACE(lpBand);
1450 /* if boundary rect specified then limit mcy */
1451 if (lpRect) {
1452 if (infoPtr->dwStyle & CCS_VERT) {
1453 if (x+mcy > adjcx) {
1454 mcy = adjcx - x;
1455 TRACE("P1 row %u limiting mcy=%d, adjcx=%d, x=%d\n",
1456 i, mcy, adjcx, x);
1459 else {
1460 if (y+mcy > adjcy) {
1461 mcy = adjcy - y;
1462 TRACE("P1 row %u limiting mcy=%d, adjcy=%d, y=%d\n",
1463 i, mcy, adjcy, y);
1468 TRACE("P1 band %u, row %d, x=%d, y=%d, cxsep=%d, cx=%d\n",
1469 i, row,
1470 x, y, cxsep, cx);
1471 if (infoPtr->dwStyle & CCS_VERT) {
1472 /* bound the bottom side if we have a bounding rectangle */
1473 rightx = clientcx;
1474 bottomy = (lpRect) ? min(clientcy, y+cxsep+cx) : y+cxsep+cx;
1475 lpBand->rcBand.left = x;
1476 lpBand->rcBand.right = x + min(mcy,
1477 lpBand->lcy+REBARSPACE(lpBand));
1478 lpBand->rcBand.top = min(bottomy, y + cxsep);
1479 lpBand->rcBand.bottom = bottomy;
1480 lpBand->uMinHeight = lpBand->lcy;
1481 y = bottomy;
1483 else {
1484 /* bound the right side if we have a bounding rectangle */
1485 rightx = (lpRect) ? min(clientcx, x+cxsep+cx) : x+cxsep+cx;
1486 bottomy = clientcy;
1487 lpBand->rcBand.left = min(rightx, x + cxsep);
1488 lpBand->rcBand.right = rightx;
1489 lpBand->rcBand.top = y;
1490 lpBand->rcBand.bottom = y + min(mcy,
1491 lpBand->lcy+REBARSPACE(lpBand));
1492 lpBand->uMinHeight = lpBand->lcy;
1493 x = rightx;
1495 TRACE("P1 band %u, row %d, (%d,%d)-(%d,%d)\n",
1496 i, row,
1497 lpBand->rcBand.left, lpBand->rcBand.top,
1498 lpBand->rcBand.right, lpBand->rcBand.bottom);
1499 prevBand = lpBand;
1501 } /* for (i = 0; i < infoPtr->uNumBands... */
1503 if (infoPtr->dwStyle & CCS_VERT)
1504 x += mcy;
1505 else
1506 y += mcy;
1508 for (j = rowstart; j < infoPtr->uNumBands; j++) {
1509 lpBand = &infoPtr->bands[j];
1510 if (infoPtr->dwStyle & CCS_VERT) {
1511 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
1513 else {
1514 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
1518 if (infoPtr->uNumBands)
1519 infoPtr->uNumRows = row;
1521 /* ******* End Phase 1 - all bands on row at minimum size ******* */
1524 /* ******* Start Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1526 mmcy = 0;
1527 if (!(infoPtr->dwStyle & RBS_VARHEIGHT)) {
1528 INT xy;
1530 /* get the max height of all bands */
1531 for (i=0; i<infoPtr->uNumBands; i++) {
1532 lpBand = &infoPtr->bands[i];
1533 if (HIDDENBAND(lpBand)) continue;
1534 if (infoPtr->dwStyle & CCS_VERT)
1535 mmcy = max(mmcy, lpBand->rcBand.right - lpBand->rcBand.left);
1536 else
1537 mmcy = max(mmcy, lpBand->rcBand.bottom - lpBand->rcBand.top);
1540 /* now adjust all rectangles by using the height found above */
1541 xy = 0;
1542 row = 1;
1543 for (i=0; i<infoPtr->uNumBands; i++) {
1544 lpBand = &infoPtr->bands[i];
1545 if (HIDDENBAND(lpBand)) continue;
1546 if (lpBand->iRow != row)
1547 xy += (mmcy + SEP_WIDTH);
1548 if (infoPtr->dwStyle & CCS_VERT) {
1549 lpBand->rcBand.left = xy;
1550 lpBand->rcBand.right = xy + mmcy;
1552 else {
1553 lpBand->rcBand.top = xy;
1554 lpBand->rcBand.bottom = xy + mmcy;
1558 /* set the x/y values to the correct maximum */
1559 if (infoPtr->dwStyle & CCS_VERT)
1560 x = xy + mmcy;
1561 else
1562 y = xy + mmcy;
1565 /* ******* End Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1568 /* ******* Start Phase 2 - split rows till adjustment height full ******* */
1570 /* assumes that the following variables contain: */
1571 /* y/x current height/width of all rows */
1572 if (lpRect) {
1573 INT i, j, prev_rh, new_rh, adj_rh, prev_idx, current_idx;
1574 REBAR_BAND *prev, *current, *walk;
1576 /* FIXME: problem # 2 */
1577 if (((infoPtr->dwStyle & CCS_VERT) ?
1578 #if PROBLEM2
1579 (x < adjcx) : (y < adjcy)
1580 #else
1581 (adjcx - x > 4) : (adjcy - y > 4)
1582 #endif
1583 ) &&
1584 (infoPtr->uNumBands > 1)) {
1585 for (i=(INT)infoPtr->uNumBands-2; i>=0; i--) {
1586 TRACE("P2 adjcx=%d, adjcy=%d, x=%d, y=%d\n",
1587 adjcx, adjcy, x, y);
1589 /* find the current band (starts at i+1) */
1590 current = &infoPtr->bands[i+1];
1591 current_idx = i+1;
1592 while (HIDDENBAND(current)) {
1593 i--;
1594 if (i < 0) break; /* out of bands */
1595 current = &infoPtr->bands[i+1];
1596 current_idx = i+1;
1598 if (i < 0) break; /* out of bands */
1600 /* now find the prev band (starts at i) */
1601 prev = &infoPtr->bands[i];
1602 prev_idx = i;
1603 while (HIDDENBAND(prev)) {
1604 i--;
1605 if (i < 0) break; /* out of bands */
1606 prev = &infoPtr->bands[i];
1607 prev_idx = i;
1609 if (i < 0) break; /* out of bands */
1611 prev_rh = ircBw(prev);
1612 if (prev->iRow == current->iRow) {
1613 new_rh = (infoPtr->dwStyle & RBS_VARHEIGHT) ?
1614 current->lcy + REBARSPACE(current) :
1615 mmcy;
1616 adj_rh = new_rh + SEP_WIDTH;
1617 infoPtr->uNumRows++;
1618 current->fDraw |= NTF_INVALIDATE;
1619 current->iRow++;
1620 if (infoPtr->dwStyle & CCS_VERT) {
1621 current->rcBand.top = inity;
1622 current->rcBand.bottom = clientcy;
1623 current->rcBand.left += (prev_rh + SEP_WIDTH);
1624 current->rcBand.right = current->rcBand.left + new_rh;
1625 x += adj_rh;
1627 else {
1628 current->rcBand.left = initx;
1629 current->rcBand.right = clientcx;
1630 current->rcBand.top += (prev_rh + SEP_WIDTH);
1631 current->rcBand.bottom = current->rcBand.top + new_rh;
1632 y += adj_rh;
1634 TRACE("P2 moving band %d to own row at (%d,%d)-(%d,%d)\n",
1635 current_idx,
1636 current->rcBand.left, current->rcBand.top,
1637 current->rcBand.right, current->rcBand.bottom);
1638 TRACE("P2 prev band %d at (%d,%d)-(%d,%d)\n",
1639 prev_idx,
1640 prev->rcBand.left, prev->rcBand.top,
1641 prev->rcBand.right, prev->rcBand.bottom);
1642 TRACE("P2 values: prev_rh=%d, new_rh=%d, adj_rh=%d\n",
1643 prev_rh, new_rh, adj_rh);
1644 /* for bands below current adjust row # and top/bottom */
1645 for (j = current_idx+1; j<infoPtr->uNumBands; j++) {
1646 walk = &infoPtr->bands[j];
1647 if (HIDDENBAND(walk)) continue;
1648 walk->fDraw |= NTF_INVALIDATE;
1649 walk->iRow++;
1650 if (infoPtr->dwStyle & CCS_VERT) {
1651 walk->rcBand.left += adj_rh;
1652 walk->rcBand.right += adj_rh;
1654 else {
1655 walk->rcBand.top += adj_rh;
1656 walk->rcBand.bottom += adj_rh;
1659 if ((infoPtr->dwStyle & CCS_VERT) ? (x >= adjcx) : (y >= adjcy))
1660 break; /* all done */
1666 /* ******* End Phase 2 - split rows till adjustment height full ******* */
1669 /* ******* Start Phase 2a - create array of start and end ******* */
1670 /* indexes by row */
1672 if (infoPtr->uNumRows != origrows) {
1673 if (infoPtr->rows) COMCTL32_Free (infoPtr->rows);
1674 infoPtr->rows = COMCTL32_Alloc (sizeof (REBAR_ROW) * infoPtr->uNumRows);
1677 row = 0;
1678 for (i = 0; i < infoPtr->uNumBands; i++) {
1679 lpBand = &infoPtr->bands[i];
1680 if (HIDDENBAND(lpBand)) continue;
1682 if (lpBand->iRow > row) {
1683 row++;
1684 infoPtr->rows[row-1].istartband = i;
1686 if (row == 0) {
1687 ERR("P2a bug!!!!!!\n");
1689 infoPtr->rows[row-1].iendband = i;
1692 for (i = 0; i < infoPtr->uNumRows; i++) {
1693 REBAR_ROW *p;
1695 p = &infoPtr->rows[i];
1696 TRACE("P2a row %d, starts %d, ends %d\n",
1697 i+1, p->istartband, p->iendband);
1700 /* ******* End Phase 2a - create array of start and end ******* */
1701 /* indexes by row */
1704 /* ******* Start Phase 2b - adjust all bands for height full ******* */
1705 /* assumes that the following variables contain: */
1706 /* y/x current height/width of all rows */
1707 /* clientcy/clientcx height/width of client area */
1709 if (((infoPtr->dwStyle & CCS_VERT) ? clientcx > x : clientcy > y) &&
1710 infoPtr->uNumBands) {
1711 INT diff, i, iband, j;
1713 diff = (infoPtr->dwStyle & CCS_VERT) ? clientcx - x : clientcy - y;
1714 for (i = infoPtr->uNumRows; i >= 1; i--) {
1715 /* if row has more than 1 band, ignore row */
1716 if (infoPtr->rows[i-1].istartband != infoPtr->rows[i-1].iendband)
1717 continue;
1718 /* point to only band in row */
1719 iband = infoPtr->rows[i-1].istartband;
1720 lpBand = &infoPtr->bands[iband];
1721 if(HIDDENBAND(lpBand)) continue;
1722 if (!lpBand->fMask & RBBS_VARIABLEHEIGHT) continue;
1723 if (((INT)lpBand->cyMaxChild < 1) ||
1724 ((INT)lpBand->cyIntegral < 1)) {
1725 if (lpBand->cyMaxChild + lpBand->cyIntegral == 0) continue;
1726 ERR("P2b band %u RBBS_VARIABLEHEIGHT set but cyMax=%d, cyInt=%d\n",
1727 iband, lpBand->cyMaxChild, lpBand->cyIntegral);
1728 continue;
1730 /* j is now the maximum height/width in the client area */
1731 j = ((diff / lpBand->cyIntegral) * lpBand->cyIntegral) +
1732 ircBw(lpBand);
1733 if (j > lpBand->cyMaxChild + REBARSPACE(lpBand))
1734 j = lpBand->cyMaxChild + REBARSPACE(lpBand);
1735 diff -= (j - ircBw(lpBand));
1736 if (infoPtr->dwStyle & CCS_VERT)
1737 lpBand->rcBand.right = lpBand->rcBand.left + j;
1738 else
1739 lpBand->rcBand.bottom = lpBand->rcBand.top + j;
1740 TRACE("P2b band %d, row %d changed to (%d,%d)-(%d,%d)\n",
1741 iband, lpBand->iRow,
1742 lpBand->rcBand.left, lpBand->rcBand.top,
1743 lpBand->rcBand.right, lpBand->rcBand.bottom);
1744 if (diff <= 0) break;
1746 if (diff < 0) {
1747 ERR("P2b allocated more than available, diff=%d\n", diff);
1748 diff = 0;
1750 if (infoPtr->dwStyle & CCS_VERT)
1751 x = clientcx - diff;
1752 else
1753 y = clientcy - diff;
1756 /* ******* End Phase 2b - adjust all bands for height full ******* */
1759 /* ******* Start Phase 3 - adjust all bands for width full ******* */
1761 if (infoPtr->uNumBands) {
1762 REBAR_ROW *p;
1764 /* If RBS_BANDBORDERS set then indicate to draw bottom separator */
1765 /* on all bands in all rows but last row. */
1766 /* Also indicate to draw the right separator for each band in */
1767 /* each row but the rightmost band. */
1768 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1770 for(i = 0; i < infoPtr->uNumRows; i++) {
1771 p = &infoPtr->rows[i];
1772 for (j = p->istartband; j <= p->iendband; j++) {
1773 lpBand = &infoPtr->bands[j];
1774 if (HIDDENBAND(lpBand)) continue;
1775 if (j != p->iendband)
1776 lpBand->fDraw |= DRAW_RIGHTSEP;
1777 if (i != infoPtr->uNumRows-1)
1778 lpBand->fDraw |= DRAW_BOTTOMSEP;
1783 /* Distribute the extra space on the horizontal and adjust */
1784 /* all bands in row to same height. */
1785 for (i=1; i<=infoPtr->uNumRows; i++) {
1786 p = &infoPtr->rows[i-1];
1787 mcy = 0;
1789 TRACE("P3 processing row %d, starting band %d, ending band %d\n",
1790 i, p->istartband, p->iendband);
1792 /* Find the largest height of the bands in the row */
1793 for (j = p->istartband; j <= p->iendband; j++) {
1794 lpBand = &infoPtr->bands[j];
1795 if (HIDDENBAND(lpBand)) continue;
1796 if (mcy < ircBw(lpBand))
1797 mcy = ircBw(lpBand);
1800 REBAR_AdjustBands (infoPtr, p->istartband, p->iendband,
1801 (infoPtr->dwStyle & CCS_VERT) ?
1802 clientcy : clientcx, mcy);
1805 /* Calculate the other rectangles in each band */
1806 if (infoPtr->dwStyle & CCS_VERT) {
1807 REBAR_CalcVertBand (infoPtr, 0, infoPtr->uNumBands,
1808 notify);
1810 else {
1811 REBAR_CalcHorzBand (infoPtr, 0, infoPtr->uNumBands,
1812 notify);
1816 /* ******* End Phase 3 - adjust all bands for width full ******* */
1818 /* now compute size of Rebar itself */
1819 infoPtr->oldSize = infoPtr->calcSize;
1820 if (infoPtr->uNumBands == 0) {
1821 /* we have no bands, so make size the size of client */
1822 x = clientcx;
1823 y = clientcy;
1825 if (infoPtr->dwStyle & CCS_VERT) {
1826 infoPtr->calcSize.cx = x;
1827 infoPtr->calcSize.cy = clientcy;
1828 TRACE("vert, notify=%d, x=%d, origheight=%d\n",
1829 notify, x, origheight);
1830 if (notify && (x != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1832 else {
1833 infoPtr->calcSize.cx = clientcx;
1834 infoPtr->calcSize.cy = y;
1835 TRACE("horz, notify=%d, y=%d, origheight=%d\n",
1836 notify, y, origheight);
1837 if (notify && (y != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1840 REBAR_DumpBand (infoPtr);
1842 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1844 REBAR_ForceResize (infoPtr);
1848 static VOID
1849 REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1850 /* Function: This routine evaluates the band specs supplied */
1851 /* by the user and updates the following 5 fields in */
1852 /* the internal band structure: cxHeader, lcx, lcy, hcx, hcy*/
1854 UINT header=0;
1855 UINT textheight=0;
1857 lpBand->fStatus = 0;
1858 lpBand->lcx = 0;
1859 lpBand->lcy = 0;
1860 lpBand->ccx = 0;
1861 lpBand->ccy = 0;
1862 lpBand->hcx = 0;
1863 lpBand->hcy = 0;
1865 /* Data comming in from users into the cx... and cy... fields */
1866 /* may be bad, just garbage, because the user never clears */
1867 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1868 /* along if the fields exist in the input area. Here we must */
1869 /* determine if the data is valid. I have no idea how MS does */
1870 /* the validation, but it does because the RB_GETBANDINFO */
1871 /* returns a 0 when I know the sample program passed in an */
1872 /* address. Here I will use the algorithim that if the value */
1873 /* is greater than 65535 then it is bad and replace it with */
1874 /* a zero. Feel free to improve the algorithim. - GA 12/2000 */
1875 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1876 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1877 if (lpBand->cx > 65535) lpBand->cx = 0;
1878 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1879 if (lpBand->cyMaxChild > 65535) lpBand->cyMaxChild = 0;
1880 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1881 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1882 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1884 /* FIXME: probably should only set NEEDS_LAYOUT flag when */
1885 /* values change. Till then always set it. */
1886 TRACE("setting NEEDS_LAYOUT\n");
1887 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1889 /* Header is where the image, text and gripper exist */
1890 /* in the band and preceed the child window. */
1892 /* calculate gripper rectangle */
1893 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1894 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1895 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (infoPtr->uNumBands > 1)))
1897 lpBand->fStatus |= HAS_GRIPPER;
1898 if (infoPtr->dwStyle & CCS_VERT)
1899 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1900 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1901 else
1902 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1903 else
1904 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1905 /* Always have 4 pixels before anything else */
1906 header += REBAR_ALWAYS_SPACE;
1909 /* image is visible */
1910 if ((lpBand->fMask & RBBIM_IMAGE) && (infoPtr->himl)) {
1911 lpBand->fStatus |= HAS_IMAGE;
1912 if (infoPtr->dwStyle & CCS_VERT) {
1913 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1914 lpBand->lcy = infoPtr->imageSize.cx + 2;
1916 else {
1917 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1918 lpBand->lcy = infoPtr->imageSize.cy + 2;
1922 /* text is visible */
1923 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText)) {
1924 HDC hdc = GetDC (0);
1925 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1926 SIZE size;
1928 lpBand->fStatus |= HAS_TEXT;
1929 GetTextExtentPoint32W (hdc, lpBand->lpText,
1930 lstrlenW (lpBand->lpText), &size);
1931 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1932 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1934 SelectObject (hdc, hOldFont);
1935 ReleaseDC (0, hdc);
1938 /* if no gripper but either image or text, then leave space */
1939 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1940 !(lpBand->fStatus & HAS_GRIPPER)) {
1941 header += REBAR_ALWAYS_SPACE;
1944 /* check if user overrode the header value */
1945 if (!(lpBand->fMask & RBBIM_HEADERSIZE))
1946 lpBand->cxHeader = header;
1949 /* Now compute minimum size of child window */
1950 lpBand->offChild.cx = 0;
1951 lpBand->offChild.cy = 0;
1952 lpBand->lcy = textheight;
1953 lpBand->ccy = lpBand->lcy;
1954 if (lpBand->fMask & RBBIM_CHILDSIZE) {
1955 lpBand->lcx = lpBand->cxMinChild;
1957 /* Set the .cy values for CHILDSIZE case */
1958 lpBand->lcy = max(lpBand->lcy, lpBand->cyMinChild);
1959 lpBand->ccy = lpBand->lcy;
1960 lpBand->hcy = lpBand->lcy;
1961 if (lpBand->cyMaxChild != 0xffffffff) {
1962 lpBand->hcy = lpBand->cyMaxChild;
1964 if (lpBand->cyChild != 0xffffffff)
1965 lpBand->ccy = max (lpBand->cyChild, lpBand->lcy);
1967 TRACE("_CHILDSIZE\n");
1969 if (lpBand->fMask & RBBIM_SIZE) {
1970 lpBand->hcx = max (lpBand->cx-lpBand->cxHeader, lpBand->lcx);
1971 TRACE("_SIZE\n");
1973 else
1974 lpBand->hcx = lpBand->lcx;
1975 lpBand->ccx = lpBand->hcx;
1977 /* make ->.cx include header size for _Layout */
1978 lpBand->lcx += lpBand->cxHeader;
1979 lpBand->ccx += lpBand->cxHeader;
1980 lpBand->hcx += lpBand->cxHeader;
1984 static void
1985 REBAR_CommonSetupBand (HWND hwnd, LPREBARBANDINFOA lprbbi, REBAR_BAND *lpBand)
1986 /* Function: This routine copies the supplied values from */
1987 /* user input (lprbbi) to the internal band structure. */
1989 lpBand->fMask |= lprbbi->fMask;
1991 if (lprbbi->fMask & RBBIM_STYLE)
1992 lpBand->fStyle = lprbbi->fStyle;
1994 if (lprbbi->fMask & RBBIM_COLORS) {
1995 lpBand->clrFore = lprbbi->clrFore;
1996 lpBand->clrBack = lprbbi->clrBack;
1999 if (lprbbi->fMask & RBBIM_IMAGE)
2000 lpBand->iImage = lprbbi->iImage;
2002 if (lprbbi->fMask & RBBIM_CHILD) {
2003 if (lprbbi->hwndChild) {
2004 lpBand->hwndChild = lprbbi->hwndChild;
2005 lpBand->hwndPrevParent =
2006 SetParent (lpBand->hwndChild, hwnd);
2007 /* below in trace fro WinRAR */
2008 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
2009 /* above in trace fro WinRAR */
2011 else {
2012 TRACE("child: 0x%x prev parent: 0x%x\n",
2013 lpBand->hwndChild, lpBand->hwndPrevParent);
2014 lpBand->hwndChild = 0;
2015 lpBand->hwndPrevParent = 0;
2019 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2020 lpBand->cxMinChild = lprbbi->cxMinChild;
2021 lpBand->cyMinChild = lprbbi->cyMinChild;
2022 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2023 lpBand->cyChild = lprbbi->cyChild;
2024 lpBand->cyMaxChild = lprbbi->cyMaxChild;
2025 lpBand->cyIntegral = lprbbi->cyIntegral;
2027 else { /* special case - these should be zeroed out since */
2028 /* RBBIM_CHILDSIZE added these in WIN32_IE >= 0x0400 */
2029 lpBand->cyChild = 0;
2030 lpBand->cyMaxChild = 0;
2031 lpBand->cyIntegral = 0;
2035 if (lprbbi->fMask & RBBIM_SIZE)
2036 lpBand->cx = lprbbi->cx;
2038 if (lprbbi->fMask & RBBIM_BACKGROUND)
2039 lpBand->hbmBack = lprbbi->hbmBack;
2041 if (lprbbi->fMask & RBBIM_ID)
2042 lpBand->wID = lprbbi->wID;
2044 /* check for additional data */
2045 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2046 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2047 lpBand->cxIdeal = lprbbi->cxIdeal;
2049 if (lprbbi->fMask & RBBIM_LPARAM)
2050 lpBand->lParam = lprbbi->lParam;
2052 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2053 lpBand->cxHeader = lprbbi->cxHeader;
2057 static LRESULT
2058 REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, RECT *clip)
2059 /* Function: This erases the background rectangle by drawing */
2060 /* each band with its background color (or the default) and */
2061 /* draws each bands right separator if necessary. The row */
2062 /* separators are drawn on the first band of the next row. */
2064 REBAR_BAND *lpBand;
2065 INT i, oldrow;
2066 HDC hdc = (HDC)wParam;
2067 RECT rect;
2068 COLORREF old, new;
2070 oldrow = -1;
2071 for(i=0; i<infoPtr->uNumBands; i++) {
2072 lpBand = &infoPtr->bands[i];
2073 if (HIDDENBAND(lpBand)) continue;
2075 /* draw band separator between rows */
2076 if (lpBand->iRow != oldrow) {
2077 oldrow = lpBand->iRow;
2078 if (lpBand->fDraw & DRAW_BOTTOMSEP) {
2079 RECT rcRowSep;
2080 rcRowSep = lpBand->rcBand;
2081 if (infoPtr->dwStyle & CCS_VERT) {
2082 rcRowSep.right += SEP_WIDTH_SIZE;
2083 rcRowSep.bottom = infoPtr->calcSize.cy;
2084 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
2086 else {
2087 rcRowSep.bottom += SEP_WIDTH_SIZE;
2088 rcRowSep.right = infoPtr->calcSize.cx;
2089 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
2091 TRACE ("drawing band separator bottom (%d,%d)-(%d,%d)\n",
2092 rcRowSep.left, rcRowSep.top,
2093 rcRowSep.right, rcRowSep.bottom);
2097 /* draw band separator between bands in a row */
2098 if (lpBand->fDraw & DRAW_RIGHTSEP) {
2099 RECT rcSep;
2100 rcSep = lpBand->rcBand;
2101 if (infoPtr->dwStyle & CCS_VERT) {
2102 rcSep.bottom += SEP_WIDTH_SIZE;
2103 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
2105 else {
2106 rcSep.right += SEP_WIDTH_SIZE;
2107 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
2109 TRACE("drawing band separator right (%d,%d)-(%d,%d)\n",
2110 rcSep.left, rcSep.top, rcSep.right, rcSep.bottom);
2113 /* draw the actual background */
2114 if (lpBand->clrBack != CLR_NONE)
2115 new = lpBand->clrBack;
2116 else
2117 new = infoPtr->clrBtnFace;
2118 rect = lpBand->rcBand;
2119 #if GLATESTING
2120 /* testing only - make background green to see it */
2121 new = RGB(0,128,0);
2122 #endif
2123 old = SetBkColor (hdc, new);
2124 TRACE("%s background color=0x%06lx, band (%d,%d)-(%d,%d), clip (%d,%d)-(%d,%d)\n",
2125 (lpBand->clrBack == CLR_NONE) ? "std" : "",
2126 new,
2127 lpBand->rcBand.left,lpBand->rcBand.top,
2128 lpBand->rcBand.right,lpBand->rcBand.bottom,
2129 clip->left, clip->top,
2130 clip->right, clip->bottom);
2131 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, 0);
2132 SetBkColor (hdc, old);
2134 return TRUE;
2137 static void
2138 REBAR_InternalHitTest (REBAR_INFO *infoPtr, LPPOINT lpPt, UINT *pFlags, INT *pBand)
2140 REBAR_BAND *lpBand;
2141 RECT rect;
2142 INT iCount;
2144 GetClientRect (infoPtr->hwndSelf, &rect);
2146 *pFlags = RBHT_NOWHERE;
2147 if (PtInRect (&rect, *lpPt))
2149 if (infoPtr->uNumBands == 0) {
2150 *pFlags = RBHT_NOWHERE;
2151 if (pBand)
2152 *pBand = -1;
2153 TRACE("NOWHERE\n");
2154 return;
2156 else {
2157 /* somewhere inside */
2158 infoPtr->ihitBand = -1;
2159 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
2160 lpBand = &infoPtr->bands[iCount];
2161 if (HIDDENBAND(lpBand)) continue;
2162 if (PtInRect (&lpBand->rcBand, *lpPt)) {
2163 if (pBand)
2164 *pBand = iCount;
2165 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
2166 *pFlags = RBHT_GRABBER;
2167 infoPtr->ihitBand = iCount;
2168 TRACE("ON GRABBER %d\n", iCount);
2169 return;
2171 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
2172 *pFlags = RBHT_CAPTION;
2173 TRACE("ON CAPTION %d\n", iCount);
2174 return;
2176 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2177 *pFlags = RBHT_CAPTION;
2178 TRACE("ON CAPTION %d\n", iCount);
2179 return;
2181 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2182 *pFlags = RBHT_CLIENT;
2183 TRACE("ON CLIENT %d\n", iCount);
2184 return;
2186 else {
2187 *pFlags = RBHT_NOWHERE;
2188 TRACE("NOWHERE %d\n", iCount);
2189 return;
2194 *pFlags = RBHT_NOWHERE;
2195 if (pBand)
2196 *pBand = -1;
2198 TRACE("NOWHERE\n");
2199 return;
2202 else {
2203 *pFlags = RBHT_NOWHERE;
2204 if (pBand)
2205 *pBand = -1;
2206 TRACE("NOWHERE\n");
2207 return;
2210 TRACE("flags=0x%X\n", *pFlags);
2211 return;
2215 static INT
2216 REBAR_Shrink (REBAR_INFO *infoPtr, REBAR_BAND *band, INT movement, INT i)
2217 /* Function: This attempts to shrink the given band by the */
2218 /* the amount in "movement". A shrink to the left is indi- */
2219 /* cated by "movement" being negative. "i" is merely the */
2220 /* band index for trace messages. */
2222 INT Leadjust, Readjust, avail, ret;
2224 /* Note: a left drag is indicated by "movement" being negative. */
2225 /* Similarly, a right drag is indicated by "movement" */
2226 /* being positive. "movement" should never be 0, but if */
2227 /* it is then the band does not move. */
2229 avail = rcBw(band) - band->lcx;
2231 /* now compute the Left End adjustment factor and Right End */
2232 /* adjustment factor. They may be different if shrinking. */
2233 if (avail <= 0) {
2234 /* if this band is not shrinkable, then just move it */
2235 Leadjust = Readjust = movement;
2236 ret = movement;
2238 else {
2239 if (movement < 0) {
2240 /* Drag to left */
2241 if (avail <= abs(movement)) {
2242 Readjust = movement;
2243 Leadjust = movement + avail;
2244 ret = Leadjust;
2246 else {
2247 Readjust = movement;
2248 Leadjust = 0;
2249 ret = 0;
2252 else {
2253 /* Drag to right */
2254 if (avail <= abs(movement)) {
2255 Leadjust = movement;
2256 Readjust = movement - avail;
2257 ret = Readjust;
2259 else {
2260 Leadjust = movement;
2261 Readjust = 0;
2262 ret = 0;
2267 /* Reasonability Check */
2268 if (rcBlt(band) + Leadjust < 0) {
2269 ERR("adjustment will fail, band %d: left=%d, right=%d, move=%d, rtn=%d\n",
2270 i, Leadjust, Readjust, movement, ret);
2273 LEADJ(band, Leadjust);
2274 READJ(band, Readjust);
2276 TRACE("band %d: left=%d, right=%d, move=%d, rtn=%d, rcBand=(%d,%d)-(%d,%d)\n",
2277 i, Leadjust, Readjust, movement, ret,
2278 band->rcBand.left, band->rcBand.top,
2279 band->rcBand.right, band->rcBand.bottom);
2280 return ret;
2284 static void
2285 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, POINTS *ptsmove)
2286 /* Function: This will implement the functionality of a */
2287 /* Gripper drag within a row. It will not implement "out- */
2288 /* of-row" drags. (They are detected and handled in */
2289 /* REBAR_MouseMove.) */
2290 /* **** FIXME Switching order of bands in a row not **** */
2291 /* **** yet implemented. **** */
2293 REBAR_BAND *hitBand, *band, *mindBand, *maxdBand;
2294 RECT newrect;
2295 INT imindBand = -1, imaxdBand, ihitBand, i, movement;
2296 INT RHeaderSum = 0, LHeaderSum = 0;
2297 INT compress;
2299 /* on first significant mouse movement, issue notify */
2301 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
2302 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
2303 /* Notify returned TRUE - abort drag */
2304 infoPtr->dragStart.x = 0;
2305 infoPtr->dragStart.y = 0;
2306 infoPtr->dragNow = infoPtr->dragStart;
2307 infoPtr->ihitBand = -1;
2308 ReleaseCapture ();
2309 return ;
2311 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
2314 ihitBand = infoPtr->ihitBand;
2315 hitBand = &infoPtr->bands[ihitBand];
2316 imaxdBand = ihitBand; /* to suppress warning message */
2318 /* find all the bands in the row of the one whose Gripper was seized */
2319 for (i=0; i<infoPtr->uNumBands; i++) {
2320 band = &infoPtr->bands[i];
2321 if (HIDDENBAND(band)) continue;
2322 if (band->iRow == hitBand->iRow) {
2323 imaxdBand = i;
2324 if (imindBand == -1) imindBand = i;
2325 /* minimum size of each band is size of header plus */
2326 /* size of minimum child plus offset of child from header plus */
2327 /* a one to separate each band. */
2328 if (i < ihitBand)
2329 LHeaderSum += (band->lcx + SEP_WIDTH);
2330 else
2331 RHeaderSum += (band->lcx + SEP_WIDTH);
2335 if (RHeaderSum) RHeaderSum -= SEP_WIDTH; /* no separator afterlast band */
2337 mindBand = &infoPtr->bands[imindBand];
2338 maxdBand = &infoPtr->bands[imaxdBand];
2340 if (imindBand == imaxdBand) return; /* nothing to drag agains */
2341 if (imindBand == ihitBand) return; /* first band in row, cant drag */
2343 /* limit movement to inside adjustable bands - Left */
2344 if ( (ptsmove->x < mindBand->rcBand.left) ||
2345 (ptsmove->x > maxdBand->rcBand.right) ||
2346 (ptsmove->y < mindBand->rcBand.top) ||
2347 (ptsmove->y > maxdBand->rcBand.bottom))
2348 return; /* should swap bands */
2350 if (infoPtr->dwStyle & CCS_VERT)
2351 movement = ptsmove->y - ((hitBand->rcBand.top+REBAR_PRE_GRIPPER) -
2352 infoPtr->ihitoffset);
2353 else
2354 movement = ptsmove->x - ((hitBand->rcBand.left+REBAR_PRE_GRIPPER) -
2355 infoPtr->ihitoffset);
2356 infoPtr->dragNow = *ptsmove;
2358 TRACE("before: movement=%d (%d,%d), imindBand=%d, ihitBand=%d, imaxdBand=%d, LSum=%d, RSum=%d\n",
2359 movement, ptsmove->x, ptsmove->y, imindBand, ihitBand,
2360 imaxdBand, LHeaderSum, RHeaderSum);
2361 REBAR_DumpBand (infoPtr);
2363 if (movement < 0) {
2365 /* *** Drag left/up *** */
2366 compress = rcBlt(hitBand) - rcBlt(mindBand) -
2367 LHeaderSum;
2368 if (compress < abs(movement)) {
2369 TRACE("limiting left drag, was %d changed to %d\n",
2370 movement, -compress);
2371 movement = -compress;
2374 for (i=ihitBand; i>=imindBand; i--) {
2375 band = &infoPtr->bands[i];
2376 if (HIDDENBAND(band)) continue;
2377 if (i == ihitBand) {
2378 LEADJ(band, movement)
2380 else
2381 movement = REBAR_Shrink (infoPtr, band, movement, i);
2382 band->ccx = rcBw(band);
2385 else {
2386 BOOL first = TRUE;
2388 /* *** Drag right/down *** */
2389 compress = rcBrb(maxdBand) - rcBlt(hitBand) -
2390 RHeaderSum;
2391 if (compress < abs(movement)) {
2392 TRACE("limiting right drag, was %d changed to %d\n",
2393 movement, compress);
2394 movement = compress;
2396 for (i=ihitBand-1; i<=imaxdBand; i++) {
2397 band = &infoPtr->bands[i];
2398 if (HIDDENBAND(band)) continue;
2399 if (first) {
2400 first = FALSE;
2401 READJ(band, movement)
2403 else
2404 movement = REBAR_Shrink (infoPtr, band, movement, i);
2405 band->ccx = rcBw(band);
2409 /* recompute all rectangles */
2410 if (infoPtr->dwStyle & CCS_VERT) {
2411 REBAR_CalcVertBand (infoPtr, imindBand, imaxdBand+1,
2412 FALSE);
2414 else {
2415 REBAR_CalcHorzBand (infoPtr, imindBand, imaxdBand+1,
2416 FALSE);
2419 TRACE("bands after adjustment, see band # %d, %d\n",
2420 imindBand, imaxdBand);
2421 REBAR_DumpBand (infoPtr);
2423 SetRect (&newrect,
2424 mindBand->rcBand.left,
2425 mindBand->rcBand.top,
2426 maxdBand->rcBand.right,
2427 maxdBand->rcBand.bottom);
2429 REBAR_MoveChildWindows (infoPtr, imindBand, imaxdBand+1);
2431 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
2432 UpdateWindow (infoPtr->hwndSelf);
2438 /* << REBAR_BeginDrag >> */
2441 static LRESULT
2442 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2444 UINT uBand = (UINT)wParam;
2445 HWND childhwnd = 0;
2446 REBAR_BAND *lpBand;
2448 if (uBand >= infoPtr->uNumBands)
2449 return FALSE;
2451 TRACE("deleting band %u!\n", uBand);
2452 lpBand = &infoPtr->bands[uBand];
2453 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2455 if (infoPtr->uNumBands == 1) {
2456 TRACE(" simple delete!\n");
2457 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2458 childhwnd = lpBand->hwndChild;
2459 COMCTL32_Free (infoPtr->bands);
2460 infoPtr->bands = NULL;
2461 infoPtr->uNumBands = 0;
2463 else {
2464 REBAR_BAND *oldBands = infoPtr->bands;
2465 TRACE("complex delete! [uBand=%u]\n", uBand);
2467 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2468 childhwnd = lpBand->hwndChild;
2470 infoPtr->uNumBands--;
2471 infoPtr->bands = COMCTL32_Alloc (sizeof (REBAR_BAND) * infoPtr->uNumBands);
2472 if (uBand > 0) {
2473 memcpy (&infoPtr->bands[0], &oldBands[0],
2474 uBand * sizeof(REBAR_BAND));
2477 if (uBand < infoPtr->uNumBands) {
2478 memcpy (&infoPtr->bands[uBand], &oldBands[uBand+1],
2479 (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
2482 COMCTL32_Free (oldBands);
2485 if (childhwnd)
2486 ShowWindow (childhwnd, SW_HIDE);
2488 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2490 /* if only 1 band left the re-validate to possible eliminate gripper */
2491 if (infoPtr->uNumBands == 1)
2492 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2494 TRACE("setting NEEDS_LAYOUT\n");
2495 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
2496 infoPtr->fStatus |= RESIZE_ANYHOW;
2497 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
2499 return TRUE;
2503 /* << REBAR_DragMove >> */
2504 /* << REBAR_EndDrag >> */
2507 static LRESULT
2508 REBAR_GetBandBorders (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2510 LPRECT lpRect = (LPRECT)lParam;
2511 REBAR_BAND *lpBand;
2513 if (!lParam)
2514 return 0;
2515 if ((UINT)wParam >= infoPtr->uNumBands)
2516 return 0;
2518 lpBand = &infoPtr->bands[(UINT)wParam];
2520 /* FIXME - the following values were determined by experimentation */
2521 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2522 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2523 /* difference in size of the control area with and without the */
2524 /* style. - GA */
2525 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2526 if (infoPtr->dwStyle & CCS_VERT) {
2527 lpRect->left = 1;
2528 lpRect->top = lpBand->cxHeader + 4;
2529 lpRect->right = 1;
2530 lpRect->bottom = 0;
2532 else {
2533 lpRect->left = lpBand->cxHeader + 4;
2534 lpRect->top = 1;
2535 lpRect->right = 0;
2536 lpRect->bottom = 1;
2539 else {
2540 lpRect->left = lpBand->cxHeader;
2542 return 0;
2546 inline static LRESULT
2547 REBAR_GetBandCount (REBAR_INFO *infoPtr)
2549 TRACE("band count %u!\n", infoPtr->uNumBands);
2551 return infoPtr->uNumBands;
2555 static LRESULT
2556 REBAR_GetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2558 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2559 REBAR_BAND *lpBand;
2561 if (lprbbi == NULL)
2562 return FALSE;
2563 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
2564 return FALSE;
2565 if ((UINT)wParam >= infoPtr->uNumBands)
2566 return FALSE;
2568 TRACE("index %u\n", (UINT)wParam);
2570 /* copy band information */
2571 lpBand = &infoPtr->bands[(UINT)wParam];
2573 if (lprbbi->fMask & RBBIM_STYLE)
2574 lprbbi->fStyle = lpBand->fStyle;
2576 if (lprbbi->fMask & RBBIM_COLORS) {
2577 lprbbi->clrFore = lpBand->clrFore;
2578 lprbbi->clrBack = lpBand->clrBack;
2579 if (lprbbi->clrBack == CLR_NONE)
2580 lprbbi->clrBack = infoPtr->clrBtnFace;
2583 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2584 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2586 if (!WideCharToMultiByte( CP_ACP, 0, lpBand->lpText, -1,
2587 lprbbi->lpText, lprbbi->cch, NULL, NULL ))
2588 lprbbi->lpText[lprbbi->cch-1] = 0;
2590 else
2591 *lprbbi->lpText = 0;
2594 if (lprbbi->fMask & RBBIM_IMAGE) {
2595 if (lpBand->fMask & RBBIM_IMAGE)
2596 lprbbi->iImage = lpBand->iImage;
2597 else
2598 lprbbi->iImage = -1;
2601 if (lprbbi->fMask & RBBIM_CHILD)
2602 lprbbi->hwndChild = lpBand->hwndChild;
2604 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2605 lprbbi->cxMinChild = lpBand->cxMinChild;
2606 lprbbi->cyMinChild = lpBand->cyMinChild;
2607 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2608 lprbbi->cyChild = lpBand->cyChild;
2609 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2610 lprbbi->cyIntegral = lpBand->cyIntegral;
2614 if (lprbbi->fMask & RBBIM_SIZE)
2615 lprbbi->cx = lpBand->cx;
2617 if (lprbbi->fMask & RBBIM_BACKGROUND)
2618 lprbbi->hbmBack = lpBand->hbmBack;
2620 if (lprbbi->fMask & RBBIM_ID)
2621 lprbbi->wID = lpBand->wID;
2623 /* check for additional data */
2624 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2625 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2626 lprbbi->cxIdeal = lpBand->cxIdeal;
2628 if (lprbbi->fMask & RBBIM_LPARAM)
2629 lprbbi->lParam = lpBand->lParam;
2631 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2632 lprbbi->cxHeader = lpBand->cxHeader;
2635 REBAR_DumpBandInfo (lprbbi);
2637 return TRUE;
2641 static LRESULT
2642 REBAR_GetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2644 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2645 REBAR_BAND *lpBand;
2647 if (lprbbi == NULL)
2648 return FALSE;
2649 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
2650 return FALSE;
2651 if ((UINT)wParam >= infoPtr->uNumBands)
2652 return FALSE;
2654 TRACE("index %u\n", (UINT)wParam);
2656 /* copy band information */
2657 lpBand = &infoPtr->bands[(UINT)wParam];
2659 if (lprbbi->fMask & RBBIM_STYLE)
2660 lprbbi->fStyle = lpBand->fStyle;
2662 if (lprbbi->fMask & RBBIM_COLORS) {
2663 lprbbi->clrFore = lpBand->clrFore;
2664 lprbbi->clrBack = lpBand->clrBack;
2665 if (lprbbi->clrBack == CLR_NONE)
2666 lprbbi->clrBack = infoPtr->clrBtnFace;
2669 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2670 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2671 lstrcpynW (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
2672 else
2673 *lprbbi->lpText = 0;
2676 if (lprbbi->fMask & RBBIM_IMAGE) {
2677 if (lpBand->fMask & RBBIM_IMAGE)
2678 lprbbi->iImage = lpBand->iImage;
2679 else
2680 lprbbi->iImage = -1;
2683 if (lprbbi->fMask & RBBIM_CHILD)
2684 lprbbi->hwndChild = lpBand->hwndChild;
2686 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2687 lprbbi->cxMinChild = lpBand->cxMinChild;
2688 lprbbi->cyMinChild = lpBand->cyMinChild;
2689 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2690 lprbbi->cyChild = lpBand->cyChild;
2691 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2692 lprbbi->cyIntegral = lpBand->cyIntegral;
2696 if (lprbbi->fMask & RBBIM_SIZE)
2697 lprbbi->cx = lpBand->cx;
2699 if (lprbbi->fMask & RBBIM_BACKGROUND)
2700 lprbbi->hbmBack = lpBand->hbmBack;
2702 if (lprbbi->fMask & RBBIM_ID)
2703 lprbbi->wID = lpBand->wID;
2705 /* check for additional data */
2706 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2707 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2708 lprbbi->cxIdeal = lpBand->cxIdeal;
2710 if (lprbbi->fMask & RBBIM_LPARAM)
2711 lprbbi->lParam = lpBand->lParam;
2713 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2714 lprbbi->cxHeader = lpBand->cxHeader;
2717 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
2719 return TRUE;
2723 static LRESULT
2724 REBAR_GetBarHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2726 INT nHeight;
2728 nHeight = (infoPtr->dwStyle & CCS_VERT) ? infoPtr->calcSize.cx : infoPtr->calcSize.cy;
2730 TRACE("height = %d\n", nHeight);
2732 return nHeight;
2736 static LRESULT
2737 REBAR_GetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2739 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
2741 if (lpInfo == NULL)
2742 return FALSE;
2744 if (lpInfo->cbSize < sizeof (REBARINFO))
2745 return FALSE;
2747 TRACE("getting bar info!\n");
2749 if (infoPtr->himl) {
2750 lpInfo->himl = infoPtr->himl;
2751 lpInfo->fMask |= RBIM_IMAGELIST;
2754 return TRUE;
2758 inline static LRESULT
2759 REBAR_GetBkColor (REBAR_INFO *infoPtr)
2761 COLORREF clr = infoPtr->clrBk;
2763 if (clr == CLR_NONE)
2764 clr = infoPtr->clrBtnFace;
2766 TRACE("background color 0x%06lx!\n", clr);
2768 return clr;
2772 /* << REBAR_GetColorScheme >> */
2773 /* << REBAR_GetDropTarget >> */
2776 static LRESULT
2777 REBAR_GetPalette (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2779 FIXME("empty stub!\n");
2781 return 0;
2785 static LRESULT
2786 REBAR_GetRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2788 INT iBand = (INT)wParam;
2789 LPRECT lprc = (LPRECT)lParam;
2790 REBAR_BAND *lpBand;
2792 if ((iBand < 0) && ((UINT)iBand >= infoPtr->uNumBands))
2793 return FALSE;
2794 if (!lprc)
2795 return FALSE;
2797 lpBand = &infoPtr->bands[iBand];
2798 CopyRect (lprc, &lpBand->rcBand);
2800 TRACE("band %d, (%d,%d)-(%d,%d)\n", iBand,
2801 lprc->left, lprc->top, lprc->right, lprc->bottom);
2803 return TRUE;
2807 inline static LRESULT
2808 REBAR_GetRowCount (REBAR_INFO *infoPtr)
2810 TRACE("%u\n", infoPtr->uNumRows);
2812 return infoPtr->uNumRows;
2816 static LRESULT
2817 REBAR_GetRowHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2819 INT iRow = (INT)wParam;
2820 int ret = 0;
2821 int i, j = 0;
2822 REBAR_BAND *lpBand;
2824 for (i=0; i<infoPtr->uNumBands; i++) {
2825 lpBand = &infoPtr->bands[i];
2826 if (HIDDENBAND(lpBand)) continue;
2827 if (lpBand->iRow != iRow) continue;
2828 if (infoPtr->dwStyle & CCS_VERT)
2829 j = lpBand->rcBand.right - lpBand->rcBand.left;
2830 else
2831 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2832 if (j > ret) ret = j;
2835 TRACE("row %d, height %d\n", iRow, ret);
2837 return ret;
2841 inline static LRESULT
2842 REBAR_GetTextColor (REBAR_INFO *infoPtr)
2844 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
2846 return infoPtr->clrText;
2850 inline static LRESULT
2851 REBAR_GetToolTips (REBAR_INFO *infoPtr)
2853 return infoPtr->hwndToolTip;
2857 inline static LRESULT
2858 REBAR_GetUnicodeFormat (REBAR_INFO *infoPtr)
2860 TRACE("%s hwnd=0x%x\n",
2861 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2863 return infoPtr->bUnicode;
2867 inline static LRESULT
2868 REBAR_GetVersion (REBAR_INFO *infoPtr)
2870 TRACE("version %d\n", infoPtr->iVersion);
2871 return infoPtr->iVersion;
2875 static LRESULT
2876 REBAR_HitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2878 LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
2880 if (!lprbht)
2881 return -1;
2883 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2885 return lprbht->iBand;
2889 static LRESULT
2890 REBAR_IdToIndex (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2892 UINT i;
2894 if (infoPtr == NULL)
2895 return -1;
2897 if (infoPtr->uNumBands < 1)
2898 return -1;
2900 for (i = 0; i < infoPtr->uNumBands; i++) {
2901 if (infoPtr->bands[i].wID == (UINT)wParam) {
2902 TRACE("id %u is band %u found!\n", (UINT)wParam, i);
2903 return i;
2907 TRACE("id %u is not found\n", (UINT)wParam);
2908 return -1;
2912 static LRESULT
2913 REBAR_InsertBandA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2915 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2916 UINT uIndex = (UINT)wParam;
2917 REBAR_BAND *lpBand;
2919 if (infoPtr == NULL)
2920 return FALSE;
2921 if (lprbbi == NULL)
2922 return FALSE;
2923 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
2924 return FALSE;
2926 /* trace the index as signed to see the -1 */
2927 TRACE("insert band at %d!\n", (INT)uIndex);
2928 REBAR_DumpBandInfo (lprbbi);
2930 if (infoPtr->uNumBands == 0) {
2931 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
2932 uIndex = 0;
2934 else {
2935 REBAR_BAND *oldBands = infoPtr->bands;
2936 infoPtr->bands =
2937 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
2938 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
2939 uIndex = infoPtr->uNumBands;
2941 /* pre insert copy */
2942 if (uIndex > 0) {
2943 memcpy (&infoPtr->bands[0], &oldBands[0],
2944 uIndex * sizeof(REBAR_BAND));
2947 /* post copy */
2948 if (uIndex < infoPtr->uNumBands - 1) {
2949 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
2950 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
2953 COMCTL32_Free (oldBands);
2956 infoPtr->uNumBands++;
2958 TRACE("index %u!\n", uIndex);
2960 /* initialize band (infoPtr->bands[uIndex])*/
2961 lpBand = &infoPtr->bands[uIndex];
2962 lpBand->fMask = 0;
2963 lpBand->fStatus = 0;
2964 lpBand->clrFore = infoPtr->clrText;
2965 lpBand->clrBack = infoPtr->clrBk;
2966 lpBand->hwndChild = 0;
2967 lpBand->hwndPrevParent = 0;
2969 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2970 lpBand->lpText = NULL;
2971 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2972 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
2973 if (len > 1) {
2974 lpBand->lpText = (LPWSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
2975 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
2979 REBAR_ValidateBand (infoPtr, lpBand);
2980 /* On insert of second band, revalidate band 1 to possible add gripper */
2981 if (infoPtr->uNumBands == 2)
2982 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2984 REBAR_DumpBand (infoPtr);
2986 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
2987 InvalidateRect(infoPtr->hwndSelf, 0, 1);
2989 return TRUE;
2993 static LRESULT
2994 REBAR_InsertBandW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2996 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2997 UINT uIndex = (UINT)wParam;
2998 REBAR_BAND *lpBand;
3000 if (infoPtr == NULL)
3001 return FALSE;
3002 if (lprbbi == NULL)
3003 return FALSE;
3004 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
3005 return FALSE;
3007 /* trace the index as signed to see the -1 */
3008 TRACE("insert band at %d!\n", (INT)uIndex);
3009 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3011 if (infoPtr->uNumBands == 0) {
3012 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
3013 uIndex = 0;
3015 else {
3016 REBAR_BAND *oldBands = infoPtr->bands;
3017 infoPtr->bands =
3018 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3019 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3020 uIndex = infoPtr->uNumBands;
3022 /* pre insert copy */
3023 if (uIndex > 0) {
3024 memcpy (&infoPtr->bands[0], &oldBands[0],
3025 uIndex * sizeof(REBAR_BAND));
3028 /* post copy */
3029 if (uIndex < infoPtr->uNumBands - 1) {
3030 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3031 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
3034 COMCTL32_Free (oldBands);
3037 infoPtr->uNumBands++;
3039 TRACE("index %u!\n", uIndex);
3041 /* initialize band (infoPtr->bands[uIndex])*/
3042 lpBand = &infoPtr->bands[uIndex];
3043 lpBand->fMask = 0;
3044 lpBand->fStatus = 0;
3045 lpBand->clrFore = infoPtr->clrText;
3046 lpBand->clrBack = infoPtr->clrBk;
3047 lpBand->hwndChild = 0;
3048 lpBand->hwndPrevParent = 0;
3050 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3051 lpBand->lpText = NULL;
3052 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3053 INT len = lstrlenW (lprbbi->lpText);
3054 if (len > 0) {
3055 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
3056 strcpyW (lpBand->lpText, lprbbi->lpText);
3060 REBAR_ValidateBand (infoPtr, lpBand);
3061 /* On insert of second band, revalidate band 1 to possible add gripper */
3062 if (infoPtr->uNumBands == 2)
3063 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3065 REBAR_DumpBand (infoPtr);
3067 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3068 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3070 return TRUE;
3074 static LRESULT
3075 REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3077 REBAR_BAND *lpBand;
3078 UINT uBand = (UINT) wParam;
3080 /* Validate */
3081 if ((infoPtr->uNumBands == 0) ||
3082 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3083 /* error !!! */
3084 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
3085 (INT)uBand, infoPtr->uNumBands);
3086 return FALSE;
3089 lpBand = &infoPtr->bands[uBand];
3091 if (lParam && (lpBand->fMask & RBBIM_IDEALSIZE)) {
3092 /* handle setting ideal size */
3093 lpBand->ccx = lpBand->cxIdeal;
3095 else {
3096 /* handle setting to max */
3097 FIXME("(uBand = %u fIdeal = %s) case not coded\n",
3098 (UINT)wParam, lParam ? "TRUE" : "FALSE");
3099 return FALSE;
3102 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3103 REBAR_Layout (infoPtr, 0, TRUE, TRUE);
3104 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
3106 return TRUE;
3111 static LRESULT
3112 REBAR_MinimizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3114 REBAR_BAND *band, *lpBand;
3115 UINT uBand = (UINT) wParam;
3116 RECT newrect;
3117 INT imindBand, imaxdBand, iprevBand, startBand, endBand;
3118 INT movement, i;
3120 /* A "minimize" band is equivalent to "dragging" the gripper
3121 * of than band to the right till the band is only the size
3122 * of the cxHeader.
3125 /* Validate */
3126 if ((infoPtr->uNumBands == 0) ||
3127 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3128 /* error !!! */
3129 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
3130 (INT)uBand, infoPtr->uNumBands);
3131 return FALSE;
3134 /* compute amount of movement and validate */
3135 lpBand = &infoPtr->bands[uBand];
3137 if (infoPtr->dwStyle & CCS_VERT)
3138 movement = lpBand->rcBand.bottom - lpBand->rcBand.top -
3139 lpBand->cxHeader;
3140 else
3141 movement = lpBand->rcBand.right - lpBand->rcBand.left -
3142 lpBand->cxHeader;
3143 if (movement < 0) {
3144 ERR("something is wrong, band=(%d,%d)-(%d,%d), cxheader=%d\n",
3145 lpBand->rcBand.left, lpBand->rcBand.top,
3146 lpBand->rcBand.right, lpBand->rcBand.bottom,
3147 lpBand->cxHeader);
3148 return FALSE;
3151 imindBand = -1;
3152 imaxdBand = -1;
3153 iprevBand = -1; /* to suppress warning message */
3155 /* find the first band in row of the one whose is being minimized */
3156 for (i=0; i<infoPtr->uNumBands; i++) {
3157 band = &infoPtr->bands[i];
3158 if (HIDDENBAND(band)) continue;
3159 if (band->iRow == lpBand->iRow) {
3160 imaxdBand = i;
3161 if (imindBand == -1) imindBand = i;
3165 /* if the selected band is first in row then need to expand */
3166 /* next visible band */
3167 if (imindBand == uBand) {
3168 band = NULL;
3169 movement = -movement;
3170 /* find the first visible band to the right of the selected band */
3171 for (i=uBand+1; i<=imaxdBand; i++) {
3172 band = &infoPtr->bands[i];
3173 if (!HIDDENBAND(band)) {
3174 iprevBand = i;
3175 LEADJ(band, movement);
3176 band->ccx = rcBw(band);
3177 break;
3180 /* what case is this */
3181 if (iprevBand == -1) {
3182 ERR("no previous visible band\n");
3183 return FALSE;
3185 startBand = uBand;
3186 endBand = iprevBand;
3187 SetRect (&newrect,
3188 lpBand->rcBand.left,
3189 lpBand->rcBand.top,
3190 band->rcBand.right,
3191 band->rcBand.bottom);
3193 /* otherwise expand previous visible band */
3194 else {
3195 band = NULL;
3196 /* find the first visible band to the left of the selected band */
3197 for (i=uBand-1; i>=imindBand; i--) {
3198 band = &infoPtr->bands[i];
3199 if (!HIDDENBAND(band)) {
3200 iprevBand = i;
3201 READJ(band, movement);
3202 band->ccx = rcBw(band);
3203 break;
3206 /* what case is this */
3207 if (iprevBand == -1) {
3208 ERR("no previous visible band\n");
3209 return FALSE;
3211 startBand = iprevBand;
3212 endBand = uBand;
3213 SetRect (&newrect,
3214 band->rcBand.left,
3215 band->rcBand.top,
3216 lpBand->rcBand.right,
3217 lpBand->rcBand.bottom);
3220 REBAR_Shrink (infoPtr, lpBand, movement, uBand);
3222 /* recompute all rectangles */
3223 if (infoPtr->dwStyle & CCS_VERT) {
3224 REBAR_CalcVertBand (infoPtr, startBand, endBand+1,
3225 FALSE);
3227 else {
3228 REBAR_CalcHorzBand (infoPtr, startBand, endBand+1,
3229 FALSE);
3232 TRACE("bands after minimize, see band # %d, %d\n",
3233 startBand, endBand);
3234 REBAR_DumpBand (infoPtr);
3236 REBAR_MoveChildWindows (infoPtr, startBand, endBand+1);
3238 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
3239 UpdateWindow (infoPtr->hwndSelf);
3240 return FALSE;
3244 static LRESULT
3245 REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3247 REBAR_BAND *oldBands = infoPtr->bands;
3248 REBAR_BAND holder;
3249 UINT uFrom = (UINT)wParam;
3250 UINT uTo = (UINT)lParam;
3252 /* Validate */
3253 if ((infoPtr->uNumBands == 0) ||
3254 ((INT)uFrom < 0) || (uFrom >= infoPtr->uNumBands) ||
3255 ((INT)uTo < 0) || (uTo >= infoPtr->uNumBands)) {
3256 /* error !!! */
3257 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
3258 (INT)uFrom, (INT)uTo, infoPtr->uNumBands);
3259 return FALSE;
3262 /* save one to be moved */
3263 memcpy (&holder, &oldBands[uFrom], sizeof(REBAR_BAND));
3265 /* close up rest of bands (psuedo delete) */
3266 if (uFrom < infoPtr->uNumBands - 1) {
3267 memcpy (&oldBands[uFrom], &oldBands[uFrom+1],
3268 (infoPtr->uNumBands - uFrom - 1) * sizeof(REBAR_BAND));
3271 /* allocate new space and copy rest of bands into it */
3272 infoPtr->bands =
3273 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
3275 /* pre insert copy */
3276 if (uTo > 0) {
3277 memcpy (&infoPtr->bands[0], &oldBands[0],
3278 uTo * sizeof(REBAR_BAND));
3281 /* set moved band */
3282 memcpy (&infoPtr->bands[uTo], &holder, sizeof(REBAR_BAND));
3284 /* post copy */
3285 if (uTo < infoPtr->uNumBands - 1) {
3286 memcpy (&infoPtr->bands[uTo+1], &oldBands[uTo],
3287 (infoPtr->uNumBands - uTo - 1) * sizeof(REBAR_BAND));
3290 COMCTL32_Free (oldBands);
3292 TRACE("moved band %d to index %d\n", uFrom, uTo);
3293 REBAR_DumpBand (infoPtr);
3295 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3296 /* **************************************************** */
3297 /* */
3298 /* We do not do a REBAR_Layout here because the native */
3299 /* control does not do that. The actual layout and */
3300 /* repaint is done by the *next* real action, ex.: */
3301 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
3302 /* */
3303 /* **************************************************** */
3305 return TRUE;
3309 static LRESULT
3310 REBAR_SetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3312 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
3313 REBAR_BAND *lpBand;
3315 if (lprbbi == NULL)
3316 return FALSE;
3317 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
3318 return FALSE;
3319 if ((UINT)wParam >= infoPtr->uNumBands)
3320 return FALSE;
3322 TRACE("index %u\n", (UINT)wParam);
3323 REBAR_DumpBandInfo (lprbbi);
3325 /* set band information */
3326 lpBand = &infoPtr->bands[(UINT)wParam];
3328 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3329 if (lprbbi->fMask & RBBIM_TEXT) {
3330 if (lpBand->lpText) {
3331 COMCTL32_Free (lpBand->lpText);
3332 lpBand->lpText = NULL;
3334 if (lprbbi->lpText) {
3335 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3336 lpBand->lpText = (LPWSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
3337 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3341 REBAR_ValidateBand (infoPtr, lpBand);
3343 REBAR_DumpBand (infoPtr);
3345 if (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) {
3346 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3347 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3350 return TRUE;
3354 static LRESULT
3355 REBAR_SetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3357 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3358 REBAR_BAND *lpBand;
3360 if (lprbbi == NULL)
3361 return FALSE;
3362 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
3363 return FALSE;
3364 if ((UINT)wParam >= infoPtr->uNumBands)
3365 return FALSE;
3367 TRACE("index %u\n", (UINT)wParam);
3368 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3370 /* set band information */
3371 lpBand = &infoPtr->bands[(UINT)wParam];
3373 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3374 if (lprbbi->fMask & RBBIM_TEXT) {
3375 if (lpBand->lpText) {
3376 COMCTL32_Free (lpBand->lpText);
3377 lpBand->lpText = NULL;
3379 if (lprbbi->lpText) {
3380 INT len = lstrlenW (lprbbi->lpText);
3381 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
3382 strcpyW (lpBand->lpText, lprbbi->lpText);
3386 REBAR_ValidateBand (infoPtr, lpBand);
3388 REBAR_DumpBand (infoPtr);
3390 if (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) {
3391 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3392 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3395 return TRUE;
3399 static LRESULT
3400 REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3402 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
3403 REBAR_BAND *lpBand;
3404 UINT i;
3406 if (lpInfo == NULL)
3407 return FALSE;
3409 if (lpInfo->cbSize < sizeof (REBARINFO))
3410 return FALSE;
3412 TRACE("setting bar info!\n");
3414 if (lpInfo->fMask & RBIM_IMAGELIST) {
3415 infoPtr->himl = lpInfo->himl;
3416 if (infoPtr->himl) {
3417 INT cx, cy;
3418 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
3419 infoPtr->imageSize.cx = cx;
3420 infoPtr->imageSize.cy = cy;
3422 else {
3423 infoPtr->imageSize.cx = 0;
3424 infoPtr->imageSize.cy = 0;
3426 TRACE("new image cx=%ld, cy=%ld\n", infoPtr->imageSize.cx,
3427 infoPtr->imageSize.cy);
3430 /* revalidate all bands to reset flags for images in headers of bands */
3431 for (i=0; i<infoPtr->uNumBands; i++) {
3432 lpBand = &infoPtr->bands[i];
3433 REBAR_ValidateBand (infoPtr, lpBand);
3436 return TRUE;
3440 static LRESULT
3441 REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3443 COLORREF clrTemp;
3445 clrTemp = infoPtr->clrBk;
3446 infoPtr->clrBk = (COLORREF)lParam;
3448 TRACE("background color 0x%06lx!\n", infoPtr->clrBk);
3450 return clrTemp;
3454 /* << REBAR_SetColorScheme >> */
3455 /* << REBAR_SetPalette >> */
3458 static LRESULT
3459 REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3461 HWND hwndTemp = infoPtr->hwndNotify;
3463 infoPtr->hwndNotify = (HWND)wParam;
3465 return (LRESULT)hwndTemp;
3469 static LRESULT
3470 REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3472 COLORREF clrTemp;
3474 clrTemp = infoPtr->clrText;
3475 infoPtr->clrText = (COLORREF)lParam;
3477 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
3479 return clrTemp;
3483 /* << REBAR_SetTooltips >> */
3486 inline static LRESULT
3487 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, WPARAM wParam)
3489 BOOL bTemp = infoPtr->bUnicode;
3491 TRACE("to %s hwnd=0x%04x, was %s\n",
3492 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf,
3493 (bTemp) ? "TRUE" : "FALSE");
3495 infoPtr->bUnicode = (BOOL)wParam;
3497 return bTemp;
3501 static LRESULT
3502 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
3504 INT iOldVersion = infoPtr->iVersion;
3506 if (iVersion > COMCTL32_VERSION)
3507 return -1;
3509 infoPtr->iVersion = iVersion;
3511 TRACE("new version %d\n", iVersion);
3513 return iOldVersion;
3517 static LRESULT
3518 REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3520 REBAR_BAND *lpBand;
3522 if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
3523 return FALSE;
3525 lpBand = &infoPtr->bands[(INT)wParam];
3527 if ((BOOL)lParam) {
3528 TRACE("show band %d\n", (INT)wParam);
3529 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
3530 if (IsWindow (lpBand->hwndChild))
3531 ShowWindow (lpBand->hwndChild, SW_SHOW);
3533 else {
3534 TRACE("hide band %d\n", (INT)wParam);
3535 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
3536 if (IsWindow (lpBand->hwndChild))
3537 ShowWindow (lpBand->hwndChild, SW_HIDE);
3540 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3541 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3543 return TRUE;
3547 static LRESULT
3548 REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3550 LPRECT lpRect = (LPRECT)lParam;
3551 RECT t1;
3553 if (lpRect == NULL)
3554 return FALSE;
3556 TRACE("[%d %d %d %d]\n",
3557 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
3559 /* what is going on???? */
3560 GetWindowRect(infoPtr->hwndSelf, &t1);
3561 TRACE("window rect [%d %d %d %d]\n",
3562 t1.left, t1.top, t1.right, t1.bottom);
3563 GetClientRect(infoPtr->hwndSelf, &t1);
3564 TRACE("client rect [%d %d %d %d]\n",
3565 t1.left, t1.top, t1.right, t1.bottom);
3567 /* force full _Layout processing */
3568 TRACE("setting NEEDS_LAYOUT\n");
3569 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3570 REBAR_Layout (infoPtr, lpRect, TRUE, FALSE);
3571 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3572 return TRUE;
3577 static LRESULT
3578 REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3580 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3581 RECT wnrc1, clrc1;
3583 if (TRACE_ON(rebar)) {
3584 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
3585 GetClientRect(infoPtr->hwndSelf, &clrc1);
3586 TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
3587 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3588 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3589 cs->x, cs->y, cs->cx, cs->cy);
3592 TRACE("created!\n");
3593 return 0;
3597 static LRESULT
3598 REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3600 REBAR_BAND *lpBand;
3601 INT i;
3604 /* free rebar bands */
3605 if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
3606 /* clean up each band */
3607 for (i = 0; i < infoPtr->uNumBands; i++) {
3608 lpBand = &infoPtr->bands[i];
3610 /* delete text strings */
3611 if (lpBand->lpText) {
3612 COMCTL32_Free (lpBand->lpText);
3613 lpBand->lpText = NULL;
3615 /* destroy child window */
3616 DestroyWindow (lpBand->hwndChild);
3619 /* free band array */
3620 COMCTL32_Free (infoPtr->bands);
3621 infoPtr->bands = NULL;
3624 DeleteObject (infoPtr->hcurArrow);
3625 DeleteObject (infoPtr->hcurHorz);
3626 DeleteObject (infoPtr->hcurVert);
3627 DeleteObject (infoPtr->hcurDrag);
3628 if(infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
3629 SetWindowLongA (infoPtr->hwndSelf, 0, 0);
3631 /* free rebar info data */
3632 COMCTL32_Free (infoPtr);
3633 TRACE("destroyed!\n");
3634 return 0;
3638 static LRESULT
3639 REBAR_EraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3641 RECT cliprect;
3643 if (GetClipBox ( (HDC)wParam, &cliprect))
3644 return REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &cliprect);
3645 return 0;
3649 static LRESULT
3650 REBAR_GetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3652 return (LRESULT)infoPtr->hFont;
3656 static LRESULT
3657 REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3659 REBAR_BAND *lpBand;
3661 /* If InternalHitTest did not find a hit on the Gripper, */
3662 /* then ignore the button click. */
3663 if (infoPtr->ihitBand == -1) return 0;
3665 SetCapture (infoPtr->hwndSelf);
3667 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3668 lpBand = &infoPtr->bands[infoPtr->ihitBand];
3669 infoPtr->dragStart = MAKEPOINTS(lParam);
3670 infoPtr->dragNow = infoPtr->dragStart;
3671 if (infoPtr->dwStyle & CCS_VERT)
3672 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.top+REBAR_PRE_GRIPPER);
3673 else
3674 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left+REBAR_PRE_GRIPPER);
3676 return 0;
3680 static LRESULT
3681 REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3683 NMHDR layout;
3684 RECT rect;
3685 INT ihitBand;
3687 /* If InternalHitTest did not find a hit on the Gripper, */
3688 /* then ignore the button click. */
3689 if (infoPtr->ihitBand == -1) return 0;
3691 ihitBand = infoPtr->ihitBand;
3692 infoPtr->dragStart.x = 0;
3693 infoPtr->dragStart.y = 0;
3694 infoPtr->dragNow = infoPtr->dragStart;
3695 infoPtr->ihitBand = -1;
3697 ReleaseCapture ();
3699 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3700 REBAR_Notify((NMHDR *) &layout, infoPtr, RBN_LAYOUTCHANGED);
3701 REBAR_Notify_NMREBAR (infoPtr, ihitBand, RBN_ENDDRAG);
3702 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3705 GetClientRect(infoPtr->hwndSelf, &rect);
3706 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3708 return 0;
3712 static LRESULT
3713 REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3715 REBAR_BAND *band1, *band2;
3716 POINTS ptsmove;
3718 /* Validate entry as hit on Gripper has occured */
3719 if (GetCapture() != infoPtr->hwndSelf) return 0;
3720 if (infoPtr->ihitBand == -1) return 0;
3722 ptsmove = MAKEPOINTS(lParam);
3724 /* if mouse did not move much, exit */
3725 if ((abs(ptsmove.x - infoPtr->dragNow.x) <= mindragx) &&
3726 (abs(ptsmove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3728 band1 = &infoPtr->bands[infoPtr->ihitBand-1];
3729 band2 = &infoPtr->bands[infoPtr->ihitBand];
3731 /* Test for valid drag case - must not be first band in row */
3732 if (infoPtr->dwStyle & CCS_VERT) {
3733 if ((ptsmove.x < band2->rcBand.left) ||
3734 (ptsmove.x > band2->rcBand.right) ||
3735 ((infoPtr->ihitBand > 0) && (band1->iRow != band2->iRow))) {
3736 FIXME("Cannot drag to other rows yet!!\n");
3738 else {
3739 REBAR_HandleLRDrag (infoPtr, &ptsmove);
3742 else {
3743 if ((ptsmove.y < band2->rcBand.top) ||
3744 (ptsmove.y > band2->rcBand.bottom) ||
3745 ((infoPtr->ihitBand > 0) && (band1->iRow != band2->iRow))) {
3746 FIXME("Cannot drag to other rows yet!!\n");
3748 else {
3749 REBAR_HandleLRDrag (infoPtr, &ptsmove);
3752 return 0;
3756 inline static LRESULT
3757 REBAR_NCCalcSize (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3759 if (infoPtr->dwStyle & WS_BORDER) {
3760 InflateRect((LPRECT)lParam, -GetSystemMetrics(SM_CXEDGE),
3761 -GetSystemMetrics(SM_CYEDGE));
3763 TRACE("new client=(%d,%d)-(%d,%d)\n",
3764 ((LPRECT)lParam)->left, ((LPRECT)lParam)->top,
3765 ((LPRECT)lParam)->right, ((LPRECT)lParam)->bottom);
3766 return 0;
3770 static LRESULT
3771 REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3773 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3774 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3775 RECT wnrc1, clrc1;
3776 NONCLIENTMETRICSA ncm;
3777 HFONT tfont;
3778 INT i;
3780 if (infoPtr != NULL) {
3781 ERR("Strange info structure pointer *not* NULL\n");
3782 return FALSE;
3785 if (TRACE_ON(rebar)) {
3786 GetWindowRect(hwnd, &wnrc1);
3787 GetClientRect(hwnd, &clrc1);
3788 TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
3789 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3790 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3791 cs->x, cs->y, cs->cx, cs->cy);
3794 /* allocate memory for info structure */
3795 infoPtr = (REBAR_INFO *)COMCTL32_Alloc (sizeof(REBAR_INFO));
3796 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
3798 /* initialize info structure - initial values are 0 */
3799 infoPtr->clrBk = CLR_NONE;
3800 infoPtr->clrText = CLR_NONE;
3801 infoPtr->clrBtnText = GetSysColor (COLOR_BTNTEXT);
3802 infoPtr->clrBtnFace = GetSysColor (COLOR_BTNFACE);
3803 infoPtr->ihitBand = -1;
3804 infoPtr->hwndSelf = hwnd;
3805 infoPtr->DoRedraw = TRUE;
3806 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
3807 infoPtr->hcurHorz = LoadCursorA (0, IDC_SIZEWEA);
3808 infoPtr->hcurVert = LoadCursorA (0, IDC_SIZENSA);
3809 infoPtr->hcurDrag = LoadCursorA (0, IDC_SIZEA);
3810 infoPtr->bUnicode = IsWindowUnicode (hwnd);
3811 infoPtr->fStatus = CREATE_RUNNING;
3812 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3814 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3815 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
3816 WM_NOTIFYFORMAT, hwnd, NF_QUERY);
3817 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
3818 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
3820 i = NFR_ANSI;
3822 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
3824 /* add necessary styles to the requested styles */
3825 infoPtr->dwStyle = cs->style | WS_VISIBLE | CCS_TOP;
3826 SetWindowLongA (hwnd, GWL_STYLE, infoPtr->dwStyle);
3828 /* get font handle for Caption Font */
3829 ncm.cbSize = sizeof(NONCLIENTMETRICSA);
3830 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS,
3831 ncm.cbSize, &ncm, 0);
3832 /* if the font is bold, set to normal */
3833 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3834 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3836 tfont = CreateFontIndirectA (&ncm.lfCaptionFont);
3837 if (tfont) {
3838 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3841 /* native does:
3842 GetSysColor (numerous);
3843 GetSysColorBrush (numerous) (see WM_SYSCOLORCHANGE);
3844 *GetStockObject (SYSTEM_FONT);
3845 *SetWindowLong (hwnd, 0, info ptr);
3846 *WM_NOTIFYFORMAT;
3847 *SetWindowLong (hwnd, GWL_STYLE, style+0x10000001);
3848 WS_VISIBLE = 0x10000000;
3849 CCS_TOP = 0x00000001;
3850 *SystemParametersInfo (SPI_GETNONCLIENTMETRICS...);
3851 *CreateFontIndirect (lfCaptionFont from above);
3852 GetDC ();
3853 SelectObject (hdc, fontabove);
3854 GetTextMetrics (hdc, ); guessing is tmHeight
3855 SelectObject (hdc, oldfont);
3856 ReleaseDC ();
3857 GetWindowRect ();
3858 MapWindowPoints (0, parent, rectabove, 2);
3859 GetWindowRect ();
3860 GetClientRect ();
3861 ClientToScreen (clientrect);
3862 SetWindowPos (hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER);
3864 return TRUE;
3868 static LRESULT
3869 REBAR_NCHitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3871 NMMOUSE nmmouse;
3872 POINTS shortpt;
3873 POINT clpt, pt;
3874 INT i;
3875 UINT scrap;
3876 LRESULT ret = HTCLIENT;
3879 * Differences from doc at MSDN (as observed with version 4.71 of
3880 * comctl32.dll
3881 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3882 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3883 * 3. native always seems to return HTCLIENT if notify return is 0.
3886 shortpt = MAKEPOINTS (lParam);
3887 POINTSTOPOINT(pt, shortpt);
3888 clpt = pt;
3889 ScreenToClient (infoPtr->hwndSelf, &clpt);
3890 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3891 (INT *)&nmmouse.dwItemSpec);
3892 nmmouse.dwItemData = 0;
3893 nmmouse.pt = clpt;
3894 nmmouse.dwHitInfo = 0;
3895 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3896 TRACE("notify changed return value from %ld to %d\n",
3897 ret, i);
3898 ret = (LRESULT) i;
3900 TRACE("returning %ld, client point (%ld,%ld)\n", ret, clpt.x, clpt.y);
3901 return ret;
3905 static LRESULT
3906 REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3908 RECT rcWindow;
3909 HDC hdc;
3911 if (infoPtr->dwStyle & WS_MINIMIZE)
3912 return 0; /* Nothing to do */
3914 if (infoPtr->dwStyle & WS_BORDER) {
3916 /* adjust rectangle and draw the necessary edge */
3917 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3918 return 0;
3919 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3920 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3921 TRACE("rect (%d,%d)-(%d,%d)\n",
3922 rcWindow.left, rcWindow.top,
3923 rcWindow.right, rcWindow.bottom);
3924 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3925 ReleaseDC( infoPtr->hwndSelf, hdc );
3928 return 0;
3932 static LRESULT
3933 REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3935 INT i;
3937 if (lParam == NF_REQUERY) {
3938 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
3939 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
3940 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
3941 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
3943 i = NFR_ANSI;
3945 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
3946 return (LRESULT)i;
3948 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3952 static LRESULT
3953 REBAR_Paint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3955 HDC hdc;
3956 PAINTSTRUCT ps;
3957 RECT rc;
3959 GetClientRect(infoPtr->hwndSelf, &rc);
3960 hdc = wParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : (HDC)wParam;
3962 TRACE("painting (%d,%d)-(%d,%d) client (%d,%d)-(%d,%d)\n",
3963 ps.rcPaint.left, ps.rcPaint.top,
3964 ps.rcPaint.right, ps.rcPaint.bottom,
3965 rc.left, rc.top, rc.right, rc.bottom);
3967 if (ps.fErase) {
3968 /* Erase area of paint if requested */
3969 REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &ps.rcPaint);
3972 REBAR_Refresh (infoPtr, hdc);
3973 if (!wParam)
3974 EndPaint (infoPtr->hwndSelf, &ps);
3975 return 0;
3979 static LRESULT
3980 REBAR_SetCursor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3982 POINT pt;
3983 UINT flags;
3985 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
3987 GetCursorPos (&pt);
3988 ScreenToClient (infoPtr->hwndSelf, &pt);
3990 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
3992 if (flags == RBHT_GRABBER) {
3993 if ((infoPtr->dwStyle & CCS_VERT) &&
3994 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
3995 SetCursor (infoPtr->hcurVert);
3996 else
3997 SetCursor (infoPtr->hcurHorz);
3999 else if (flags != RBHT_CLIENT)
4000 SetCursor (infoPtr->hcurArrow);
4002 return 0;
4006 static LRESULT
4007 REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4009 RECT rcClient;
4010 REBAR_BAND *lpBand;
4011 UINT i;
4013 infoPtr->hFont = (HFONT)wParam;
4015 /* revalidate all bands to change sizes of text in headers of bands */
4016 for (i=0; i<infoPtr->uNumBands; i++) {
4017 lpBand = &infoPtr->bands[i];
4018 REBAR_ValidateBand (infoPtr, lpBand);
4022 if (LOWORD(lParam)) {
4023 GetClientRect (infoPtr->hwndSelf, &rcClient);
4024 REBAR_Layout (infoPtr, &rcClient, FALSE, TRUE);
4027 return 0;
4031 inline static LRESULT
4032 REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4033 /*****************************************************
4035 * Function;
4036 * Handles the WM_SETREDRAW message.
4038 * Documentation:
4039 * According to testing V4.71 of COMCTL32 returns the
4040 * *previous* status of the redraw flag (either 0 or -1)
4041 * instead of the MSDN documented value of 0 if handled
4043 *****************************************************/
4045 BOOL oldredraw = infoPtr->DoRedraw;
4047 TRACE("set to %s, fStatus=%08x\n",
4048 (wParam) ? "TRUE" : "FALSE", infoPtr->fStatus);
4049 infoPtr->DoRedraw = (BOOL) wParam;
4050 if (wParam) {
4051 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
4052 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
4053 REBAR_ForceResize (infoPtr);
4054 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
4056 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
4058 return (oldredraw) ? -1 : 0;
4062 static LRESULT
4063 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4065 RECT rcClient;
4067 /* auto resize deadlock check */
4068 if (infoPtr->fStatus & AUTO_RESIZE) {
4069 infoPtr->fStatus &= ~AUTO_RESIZE;
4070 TRACE("AUTO_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
4071 infoPtr->fStatus, lParam);
4072 return 0;
4075 if (infoPtr->fStatus & CREATE_RUNNING) {
4076 /* still in CreateWindow */
4077 RECT rcWin;
4079 if ((INT)wParam != SIZE_RESTORED) {
4080 ERR("WM_SIZE in create and flags=%08x, lParam=%08lx\n",
4081 wParam, lParam);
4084 TRACE("still in CreateWindow\n");
4085 infoPtr->fStatus &= ~CREATE_RUNNING;
4086 GetWindowRect ( infoPtr->hwndSelf, &rcWin);
4087 TRACE("win rect (%d,%d)-(%d,%d)\n",
4088 rcWin.left, rcWin.top, rcWin.right, rcWin.bottom);
4090 if ((lParam == 0) && (rcWin.right-rcWin.left == 0) &&
4091 (rcWin.bottom-rcWin.top == 0)) {
4092 /* native control seems to do this */
4093 GetClientRect (GetParent(infoPtr->hwndSelf), &rcClient);
4094 TRACE("sizing rebar, message and client zero, parent client (%d,%d)\n",
4095 rcClient.right, rcClient.bottom);
4097 else {
4098 INT cx, cy;
4100 cx = rcWin.right - rcWin.left;
4101 cy = rcWin.bottom - rcWin.top;
4102 if ((cx == LOWORD(lParam)) && (cy == HIWORD(lParam))) {
4103 return 0;
4106 /* do the actual WM_SIZE request */
4107 GetClientRect (infoPtr->hwndSelf, &rcClient);
4108 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%d,%d)\n",
4109 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4110 LOWORD(lParam), HIWORD(lParam),
4111 rcClient.right, rcClient.bottom);
4114 else {
4115 if ((INT)wParam != SIZE_RESTORED) {
4116 ERR("WM_SIZE out of create and flags=%08x, lParam=%08lx\n",
4117 wParam, lParam);
4120 /* Handle cases when outside of the CreateWindow process */
4122 GetClientRect (infoPtr->hwndSelf, &rcClient);
4123 if ((lParam == 0) && (rcClient.right + rcClient.bottom != 0) &&
4124 (infoPtr->dwStyle & RBS_AUTOSIZE)) {
4125 /* on a WM_SIZE to zero and current client not zero and AUTOSIZE */
4126 /* native seems to use the current client rect for the size */
4127 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4128 TRACE("sizing rebar to client (%d,%d) size is zero but AUTOSIZE set\n",
4129 rcClient.right, rcClient.bottom);
4131 else {
4132 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%d,%d)\n",
4133 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4134 LOWORD(lParam), HIWORD(lParam),
4135 rcClient.right, rcClient.bottom);
4139 if (infoPtr->dwStyle & RBS_AUTOSIZE) {
4140 NMRBAUTOSIZE autosize;
4142 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
4143 autosize.fChanged = 0; /* ??? */
4144 autosize.rcActual = autosize.rcTarget; /* ??? */
4145 REBAR_Notify((NMHDR *) &autosize, infoPtr, RBN_AUTOSIZE);
4146 TRACE("RBN_AUTOSIZE client=(%d,%d), lp=%08lx\n",
4147 autosize.rcTarget.right, autosize.rcTarget.bottom, lParam);
4150 if ((infoPtr->calcSize.cx != rcClient.right) ||
4151 (infoPtr->calcSize.cy != rcClient.bottom))
4152 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4154 REBAR_Layout (infoPtr, &rcClient, TRUE, TRUE);
4155 infoPtr->fStatus &= ~AUTO_RESIZE;
4157 return 0;
4161 static LRESULT
4162 REBAR_StyleChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4164 STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
4166 TRACE("current style=%08lx, styleOld=%08lx, style being set to=%08lx\n",
4167 infoPtr->dwStyle, ss->styleOld, ss->styleNew);
4168 infoPtr->dwStyle = ss->styleNew;
4170 return FALSE;
4174 static LRESULT WINAPI
4175 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4177 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
4179 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
4180 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
4181 if (!infoPtr && (uMsg != WM_NCCREATE))
4182 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4183 switch (uMsg)
4185 /* case RB_BEGINDRAG: */
4187 case RB_DELETEBAND:
4188 return REBAR_DeleteBand (infoPtr, wParam, lParam);
4190 /* case RB_DRAGMOVE: */
4191 /* case RB_ENDDRAG: */
4193 case RB_GETBANDBORDERS:
4194 return REBAR_GetBandBorders (infoPtr, wParam, lParam);
4196 case RB_GETBANDCOUNT:
4197 return REBAR_GetBandCount (infoPtr);
4199 case RB_GETBANDINFO: /* obsoleted after IE3, but we have to
4200 support it anyway. */
4201 case RB_GETBANDINFOA:
4202 return REBAR_GetBandInfoA (infoPtr, wParam, lParam);
4204 case RB_GETBANDINFOW:
4205 return REBAR_GetBandInfoW (infoPtr, wParam, lParam);
4207 case RB_GETBARHEIGHT:
4208 return REBAR_GetBarHeight (infoPtr, wParam, lParam);
4210 case RB_GETBARINFO:
4211 return REBAR_GetBarInfo (infoPtr, wParam, lParam);
4213 case RB_GETBKCOLOR:
4214 return REBAR_GetBkColor (infoPtr);
4216 /* case RB_GETCOLORSCHEME: */
4217 /* case RB_GETDROPTARGET: */
4219 case RB_GETPALETTE:
4220 return REBAR_GetPalette (infoPtr, wParam, lParam);
4222 case RB_GETRECT:
4223 return REBAR_GetRect (infoPtr, wParam, lParam);
4225 case RB_GETROWCOUNT:
4226 return REBAR_GetRowCount (infoPtr);
4228 case RB_GETROWHEIGHT:
4229 return REBAR_GetRowHeight (infoPtr, wParam, lParam);
4231 case RB_GETTEXTCOLOR:
4232 return REBAR_GetTextColor (infoPtr);
4234 case RB_GETTOOLTIPS:
4235 return REBAR_GetToolTips (infoPtr);
4237 case RB_GETUNICODEFORMAT:
4238 return REBAR_GetUnicodeFormat (infoPtr);
4240 case CCM_GETVERSION:
4241 return REBAR_GetVersion (infoPtr);
4243 case RB_HITTEST:
4244 return REBAR_HitTest (infoPtr, wParam, lParam);
4246 case RB_IDTOINDEX:
4247 return REBAR_IdToIndex (infoPtr, wParam, lParam);
4249 case RB_INSERTBANDA:
4250 return REBAR_InsertBandA (infoPtr, wParam, lParam);
4252 case RB_INSERTBANDW:
4253 return REBAR_InsertBandW (infoPtr, wParam, lParam);
4255 case RB_MAXIMIZEBAND:
4256 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
4258 case RB_MINIMIZEBAND:
4259 return REBAR_MinimizeBand (infoPtr, wParam, lParam);
4261 case RB_MOVEBAND:
4262 return REBAR_MoveBand (infoPtr, wParam, lParam);
4264 case RB_SETBANDINFOA:
4265 return REBAR_SetBandInfoA (infoPtr, wParam, lParam);
4267 case RB_SETBANDINFOW:
4268 return REBAR_SetBandInfoW (infoPtr, wParam, lParam);
4270 case RB_SETBARINFO:
4271 return REBAR_SetBarInfo (infoPtr, wParam, lParam);
4273 case RB_SETBKCOLOR:
4274 return REBAR_SetBkColor (infoPtr, wParam, lParam);
4276 /* case RB_SETCOLORSCHEME: */
4277 /* case RB_SETPALETTE: */
4278 /* return REBAR_GetPalette (infoPtr, wParam, lParam); */
4280 case RB_SETPARENT:
4281 return REBAR_SetParent (infoPtr, wParam, lParam);
4283 case RB_SETTEXTCOLOR:
4284 return REBAR_SetTextColor (infoPtr, wParam, lParam);
4286 /* case RB_SETTOOLTIPS: */
4288 case RB_SETUNICODEFORMAT:
4289 return REBAR_SetUnicodeFormat (infoPtr, wParam);
4291 case CCM_SETVERSION:
4292 return REBAR_SetVersion (infoPtr, (INT)wParam);
4294 case RB_SHOWBAND:
4295 return REBAR_ShowBand (infoPtr, wParam, lParam);
4297 case RB_SIZETORECT:
4298 return REBAR_SizeToRect (infoPtr, wParam, lParam);
4301 /* Messages passed to parent */
4302 case WM_COMMAND:
4303 case WM_DRAWITEM:
4304 case WM_NOTIFY:
4305 if (infoPtr->NtfUnicode)
4306 return SendMessageW (REBAR_GetNotifyParent (infoPtr),
4307 uMsg, wParam, lParam);
4308 else
4309 return SendMessageA (REBAR_GetNotifyParent (infoPtr),
4310 uMsg, wParam, lParam);
4313 /* case WM_CHARTOITEM: supported according to ControlSpy */
4315 case WM_CREATE:
4316 return REBAR_Create (infoPtr, wParam, lParam);
4318 case WM_DESTROY:
4319 return REBAR_Destroy (infoPtr, wParam, lParam);
4321 case WM_ERASEBKGND:
4322 return REBAR_EraseBkGnd (infoPtr, wParam, lParam);
4324 case WM_GETFONT:
4325 return REBAR_GetFont (infoPtr, wParam, lParam);
4327 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
4329 case WM_LBUTTONDOWN:
4330 return REBAR_LButtonDown (infoPtr, wParam, lParam);
4332 case WM_LBUTTONUP:
4333 return REBAR_LButtonUp (infoPtr, wParam, lParam);
4335 /* case WM_MEASUREITEM: supported according to ControlSpy */
4337 case WM_MOUSEMOVE:
4338 return REBAR_MouseMove (infoPtr, wParam, lParam);
4340 case WM_NCCALCSIZE:
4341 return REBAR_NCCalcSize (infoPtr, wParam, lParam);
4343 case WM_NCCREATE:
4344 return REBAR_NCCreate (hwnd, wParam, lParam);
4346 case WM_NCHITTEST:
4347 return REBAR_NCHitTest (infoPtr, wParam, lParam);
4349 case WM_NCPAINT:
4350 return REBAR_NCPaint (infoPtr, wParam, lParam);
4352 case WM_NOTIFYFORMAT:
4353 return REBAR_NotifyFormat (infoPtr, wParam, lParam);
4355 case WM_PAINT:
4356 return REBAR_Paint (infoPtr, wParam, lParam);
4358 /* case WM_PALETTECHANGED: supported according to ControlSpy */
4359 /* case WM_PRINTCLIENT: supported according to ControlSpy */
4360 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
4361 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
4362 /* case WM_RBUTTONUP: supported according to ControlSpy */
4364 case WM_SETCURSOR:
4365 return REBAR_SetCursor (infoPtr, wParam, lParam);
4367 case WM_SETFONT:
4368 return REBAR_SetFont (infoPtr, wParam, lParam);
4370 case WM_SETREDRAW:
4371 return REBAR_SetRedraw (infoPtr, wParam, lParam);
4373 case WM_SIZE:
4374 return REBAR_Size (infoPtr, wParam, lParam);
4376 case WM_STYLECHANGED:
4377 return REBAR_StyleChanged (infoPtr, wParam, lParam);
4379 /* case WM_SYSCOLORCHANGE: supported according to ControlSpy */
4380 /* "Applications that have brushes using the existing system colors
4381 should delete those brushes and recreate them using the new
4382 system colors." per MSDN */
4384 /* case WM_VKEYTOITEM: supported according to ControlSpy */
4385 /* case WM_WININICHANGE: */
4387 default:
4388 if (uMsg >= WM_USER)
4389 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
4390 uMsg, wParam, lParam);
4391 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4393 return 0;
4397 VOID
4398 REBAR_Register (void)
4400 WNDCLASSA wndClass;
4402 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4403 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
4404 wndClass.lpfnWndProc = (WNDPROC)REBAR_WindowProc;
4405 wndClass.cbClsExtra = 0;
4406 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
4407 wndClass.hCursor = 0;
4408 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
4409 #if GLATESTING
4410 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
4411 #endif
4412 wndClass.lpszClassName = REBARCLASSNAMEA;
4414 RegisterClassA (&wndClass);
4416 mindragx = GetSystemMetrics (SM_CXDRAG);
4417 mindragy = GetSystemMetrics (SM_CYDRAG);
4422 VOID
4423 REBAR_Unregister (void)
4425 UnregisterClassA (REBARCLASSNAMEA, (HINSTANCE)NULL);