source: trunk/src/comctl32/rebar.c@ 10010

Last change on this file since 10010 was 9370, checked in by sandervl, 23 years ago

Wine resync

File size: 131.0 KB
Line 
1/*
2 * Testing: set to 1 to make background brush *always* green
3 */
4#define GLATESTING 0
5
6/*
7 *
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 ***
11 *
12 */
13#define PROBLEM2 0
14
15/*
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
19 */
20
21
22/*
23 * Rebar control rev 8e
24 *
25 * Copyright 1998, 1999 Eric Kohl
26 *
27 * This library is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU Lesser General Public
29 * License as published by the Free Software Foundation; either
30 * version 2.1 of the License, or (at your option) any later version.
31 *
32 * This library is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 * Lesser General Public License for more details.
36 *
37 * You should have received a copy of the GNU Lesser General Public
38 * License along with this library; if not, write to the Free Software
39 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 *
41 * NOTES
42 * An author is needed! Any volunteers?
43 * I will only improve this control once in a while.
44 * Eric <ekohl@abo.rhein-zeitung.de>
45 *
46 * TODO:
47 * - vertical placement
48 * - ComboBox and ComboBoxEx placement
49 * - center image
50 * - Layout code.
51 * - Display code.
52 * - Some messages.
53 * - All notifications.
54
55 * Changes Guy Albertelli <galberte@neo.lrun.com>
56 * rev 2,3,4
57 * - Implement initial version of row grouping, row separators,
58 * text and background colors. Support additional messages.
59 * Support RBBS_BREAK. Implement ERASEBKGND and improve painting.
60 * rev 5
61 * - implement support for dragging Gripper left or right in a row. Supports
62 * WM_LBUTTONDOWN, WM_LBUTTONUP, and WM_MOUSEMOVE. Also support
63 * RBS_BANDBORDERS.
64 * rev 6
65 * - Fix or implement notifications for RBN_HEIGHTCHANGE, RBN_CHILDSIZE.
66 * - Correct styles RBBS_NOGRIPPER, RBBS_GRIPPERALWAYS, and RBBS_FIXEDSIZE.
67 * - Fix algorithm for Layout and AdjustBand.
68 *
69 * rev 7
70 * - Fix algorithm for _Layout and _AdjustBand.
71 * - Fix or implement RBN_ENDDRAG, RB_MOVEBAND, WM_SETREDRAW,
72 * WM_STYLECHANGED, RB_MINIMIZEBAND, RBBS_VARIABLEHEIGHT, RBS_VARHEIGHT,
73 * RBBS_HIDDEN, WM_NOTIFYFORMAT, NM_NCHITTEST, WM_SETREDRAW, RBS_AUTOSIZE,
74 * WM_SETFONT, RBS_BORDERS
75 * - Create structures in WM_NCCREATE
76 * - Additional performance enhancements.
77 *
78 * rev 8
79 * 1. Create array of start and end band indexes by row and use.
80 * 2. Fix problem with REBAR_Layout Phase 2b to process only if only
81 * band in row.
82 * 3. Set the Caption Font (Regular) as default font for text.
83 * 4. Delete font handle on control distruction.
84 * 5. Add UpdateWindow call in _MoveChildWindows to match repainting done
85 * by native control
86 * 6. Improve some traces.
87 * 7. Invalidate window rectangles after SetBandInfo, InsertBand, ShowBand
88 * so that repainting is correct.
89 * 8. Implement RB_MAXIMIZEBAND for the "ideal=TRUE" case.
90 * 9. Implement item custom draw notifications partially. Only done for
91 * ITEMPREPAINT and ITEMPOSTPAINT. (Used by IE4 for "Favorites" frame
92 * to draw the word "Favorites").
93 * rev 8a
94 * 10. Handle CCS_NODIVIDER and fix WS_BORDER code.
95 * 11. Fix logic error in _AdjustBands where flag was set to valid band
96 * number (0) to indicate *no* band.
97 * 12. Fix CCS_VERT errors in _ForceResize, _NCCalcSize, and _NCPaint.
98 * 13. Support some special cases of CCS_TOP (and therefore CCS_LEFT),
99 * CCS_BOTTOM (and therefore CCS_RIGHT) and CCS_NOPARENTALIGN. Not
100 * at all sure whether this is all cases.
101 * 14. Handle returned value for the RBN_CHILDSIZE notify.
102 * 15. Implement RBBS_CHILDEDGE, and set each bands "offChild" at _Layout
103 * time.
104 * 16. Fix REBARSPACE. It should depend on CCS_NODIVIDER.
105 * rev 8b
106 * 17. Fix determination of whether Gripper is needed in _ValidateBand.
107 * 18. Fix _AdjustBand processing of RBBS_FIXEDSIZE.
108 * rev 8c
109 * 19. Fix problem in _Layout when all lengths are 0.
110 * 20. If CLR_NONE specified, we will use default BtnFace color when drawing.
111 * 21. Fix test in REBAR_Layout.
112 * rev 8d
113 * 22. Add support for WM_WINDOWPOSCHANGED to save new origin of window.
114 * 23. Correct RBN_CHILDSIZE rect value for CCS_VERT rebar.
115 * 24. Do UpdateWindow only if doing redraws.
116 * rev 8e
117 * 25. Adjust setting of offChild.cx based on RBBS_CHILDEDGE.
118 *
119 *
120 * Still to do:
121 * 2. Following still not handled: RBBS_FIXEDBMP,
122 * RBBS_USECHEVRON, CCS_NORESIZE,
123 * CCS_NOMOVEX, CCS_NOMOVEY
124 * 3. Following are only partially handled:
125 * RBS_AUTOSIZE, RBBS_VARIABLEHEIGHT
126 * 5. Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
127 * to set the size of the separator width (the value SEP_WIDTH_SIZE
128 * in here). Should be fixed!!
129 * 6. The following messages are not implemented:
130 * RB_BEGINDRAG, RB_DRAGMOVE, RB_ENDDRAG, RB_GETCOLORSCHEME,
131 * RB_GETDROPTARGET, RB_MAXIMIZEBAND,
132 * RB_SETCOLORSCHEME, RB_SETPALETTE, RB_SETTOOLTIPS
133 * WM_CHARTOITEM, WM_LBUTTONDBLCLK, WM_MEASUREITEM,
134 * WM_PALETTECHANGED, WM_PRINTCLIENT, WM_QUERYNEWPALETTE,
135 * WM_RBUTTONDOWN, WM_RBUTTONUP,
136 * WM_SYSCOLORCHANGE, WM_VKEYTOITEM, WM_WININICHANGE
137 * 7. The following notifications are not implemented:
138 * NM_CUSTOMDRAW, NM_RELEASEDCAPTURE
139 * RB_CHEVRONPUSHED, RBN_MINMAX
140 */
141
142#include <stdlib.h>
143#include <string.h>
144
145#include "winbase.h"
146#include "wingdi.h"
147#include "wine/unicode.h"
148#include "commctrl.h"
149/* #include "spy.h" */
150#include "wine/debug.h"
151
152WINE_DEFAULT_DEBUG_CHANNEL(rebar);
153
154typedef struct
155{
156 UINT fStyle;
157 UINT fMask;
158 COLORREF clrFore;
159 COLORREF clrBack;
160 INT iImage;
161 HWND hwndChild;
162 UINT cxMinChild; /* valid if _CHILDSIZE */
163 UINT cyMinChild; /* valid if _CHILDSIZE */
164 UINT cx; /* valid if _SIZE */
165 HBITMAP hbmBack;
166 UINT wID;
167 UINT cyChild; /* valid if _CHILDSIZE */
168 UINT cyMaxChild; /* valid if _CHILDSIZE */
169 UINT cyIntegral; /* valid if _CHILDSIZE */
170 UINT cxIdeal;
171 LPARAM lParam;
172 UINT cxHeader;
173
174 UINT lcx; /* minimum cx for band */
175 UINT ccx; /* current cx for band */
176 UINT hcx; /* maximum cx for band */
177 UINT lcy; /* minimum cy for band */
178 UINT ccy; /* current cy for band */
179 UINT hcy; /* maximum cy for band */
180
181 SIZE offChild; /* x,y offset if child is not FIXEDSIZE */
182 UINT uMinHeight;
183 INT iRow; /* row this band assigned to */
184 UINT fStatus; /* status flags, reset only by _Validate */
185 UINT fDraw; /* drawing flags, reset only by _Layout */
186 UINT uCDret; /* last return from NM_CUSTOMDRAW */
187 RECT rcoldBand; /* previous calculated band rectangle */
188 RECT rcBand; /* calculated band rectangle */
189 RECT rcGripper; /* calculated gripper rectangle */
190 RECT rcCapImage; /* calculated caption image rectangle */
191 RECT rcCapText; /* calculated caption text rectangle */
192 RECT rcChild; /* calculated child rectangle */
193
194 LPWSTR lpText;
195 HWND hwndPrevParent;
196} REBAR_BAND;
197
198/* fStatus flags */
199#define HAS_GRIPPER 0x00000001
200#define HAS_IMAGE 0x00000002
201#define HAS_TEXT 0x00000004
202
203/* fDraw flags */
204#define DRAW_GRIPPER 0x00000001
205#define DRAW_IMAGE 0x00000002
206#define DRAW_TEXT 0x00000004
207#define DRAW_RIGHTSEP 0x00000010
208#define DRAW_BOTTOMSEP 0x00000020
209#define NTF_INVALIDATE 0x01000000
210
211typedef struct
212{
213 INT istartband; /* index of first band in row */
214 INT iendband; /* index of last band in row */
215} REBAR_ROW;
216
217
218typedef struct
219{
220 COLORREF clrBk; /* background color */
221 COLORREF clrText; /* text color */
222 COLORREF clrBtnText; /* system color for BTNTEXT */
223 COLORREF clrBtnFace; /* system color for BTNFACE */
224 HIMAGELIST himl; /* handle to imagelist */
225 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
226 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
227 HWND hwndSelf; /* handle of REBAR window itself */
228 HWND hwndToolTip; /* handle to the tool tip control */
229 HWND hwndNotify; /* notification window (parent) */
230 HFONT hDefaultFont;
231 HFONT hFont; /* handle to the rebar's font */
232 SIZE imageSize; /* image size (image list) */
233 DWORD dwStyle; /* window style */
234 SIZE calcSize; /* calculated rebar size */
235 SIZE oldSize; /* previous calculated rebar size */
236 BOOL bUnicode; /* TRUE if this window is W type */
237 BOOL NtfUnicode; /* TRUE if parent wants notify in W format */
238 BOOL DoRedraw; /* TRUE to acutally draw bands */
239 UINT fStatus; /* Status flags (see below) */
240 HCURSOR hcurArrow; /* handle to the arrow cursor */
241 HCURSOR hcurHorz; /* handle to the EW cursor */
242 HCURSOR hcurVert; /* handle to the NS cursor */
243 HCURSOR hcurDrag; /* handle to the drag cursor */
244 INT iVersion; /* version number */
245 POINTS dragStart; /* x,y of button down */
246 POINTS dragNow; /* x,y of this MouseMove */
247 INT ihitBand; /* band number of band whose gripper was grabbed */
248 INT ihitoffset; /* offset of hotspot from gripper.left */
249 POINT origin; /* left/upper corner of client */
250
251 REBAR_ROW *rows; /* pointer to row indexes */
252 REBAR_BAND *bands; /* pointer to the array of rebar bands */
253} REBAR_INFO;
254
255/* fStatus flags */
256#define BEGIN_DRAG_ISSUED 0x00000001
257#define AUTO_RESIZE 0x00000002
258#define RESIZE_ANYHOW 0x00000004
259#define NTF_HGHTCHG 0x00000008
260#define BAND_NEEDS_LAYOUT 0x00000010
261#define BAND_NEEDS_REDRAW 0x00000020
262#define CREATE_RUNNING 0x00000040
263
264/* ---- REBAR layout constants. Mostly determined by ---- */
265/* ---- experiment on WIN 98. ---- */
266
267/* Width (or height) of separators between bands (either horz. or */
268/* vert.). True only if RBS_BANDBORDERS is set */
269#define SEP_WIDTH_SIZE 2
270#define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
271
272/* Blank (background color) space between Gripper (if present) */
273/* and next item (image, text, or window). Always present */
274#define REBAR_ALWAYS_SPACE 4
275
276/* Blank (background color) space after Image (if present). */
277#define REBAR_POST_IMAGE 2
278
279/* Blank (background color) space after Text (if present). */
280#define REBAR_POST_TEXT 4
281
282/* Height of vertical gripper in a CCS_VERT rebar. */
283#define GRIPPER_HEIGHT 16
284
285/* Blank (background color) space before Gripper (if present). */
286#define REBAR_PRE_GRIPPER 2
287
288/* Width (of normal vertical gripper) or height (of horz. gripper) */
289/* if present. */
290#define GRIPPER_WIDTH 3
291
292/* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
293/* either top or bottom */
294#define REBAR_DIVIDER 2
295
296/* This is the increment that is used over the band height */
297#define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
298
299/* ---- End of REBAR layout constants. ---- */
300
301
302/* The following 6 defines return the proper rcBand element */
303/* depending on whether CCS_VERT was set. */
304#define rcBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.top : b->rcBand.left)
305#define rcBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.bottom : b->rcBand.right)
306#define rcBw(b) ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.bottom - b->rcBand.top) : \
307 (b->rcBand.right - b->rcBand.left))
308#define ircBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.left : b->rcBand.top)
309#define ircBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.right : b->rcBand.bottom)
310#define ircBw(b) ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.right - b->rcBand.left) : \
311 (b->rcBand.bottom - b->rcBand.top))
312
313/* The following define determines if a given band is hidden */
314#define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
315 ((infoPtr->dwStyle & CCS_VERT) && \
316 ((a)->fStyle & RBBS_NOVERT)))
317
318/* The following defines adjust the right or left end of a rectangle */
319#define READJ(b,i) do { if(infoPtr->dwStyle & CCS_VERT) b->rcBand.bottom+=(i); \
320 else b->rcBand.right += (i); } while(0)
321#define LEADJ(b,i) do { if(infoPtr->dwStyle & CCS_VERT) b->rcBand.top+=(i); \
322 else b->rcBand.left += (i); } while(0)
323
324
325#define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongA (hwnd, 0))
326
327
328/* "constant values" retrieved when DLL was initialized */
329/* FIXME we do this when the classes are registered. */
330static UINT mindragx = 0;
331static UINT mindragy = 0;
332
333static char *band_stylename[] = {
334 "RBBS_BREAK", /* 0001 */
335 "RBBS_FIXEDSIZE", /* 0002 */
336 "RBBS_CHILDEDGE", /* 0004 */
337 "RBBS_HIDDEN", /* 0008 */
338 "RBBS_NOVERT", /* 0010 */
339 "RBBS_FIXEDBMP", /* 0020 */
340 "RBBS_VARIABLEHEIGHT", /* 0040 */
341 "RBBS_GRIPPERALWAYS", /* 0080 */
342 "RBBS_NOGRIPPER", /* 0100 */
343 NULL };
344
345static char *band_maskname[] = {
346 "RBBIM_STYLE", /* 0x00000001 */
347 "RBBIM_COLORS", /* 0x00000002 */
348 "RBBIM_TEXT", /* 0x00000004 */
349 "RBBIM_IMAGE", /* 0x00000008 */
350 "RBBIM_CHILD", /* 0x00000010 */
351 "RBBIM_CHILDSIZE", /* 0x00000020 */
352 "RBBIM_SIZE", /* 0x00000040 */
353 "RBBIM_BACKGROUND", /* 0x00000080 */
354 "RBBIM_ID", /* 0x00000100 */
355 "RBBIM_IDEALSIZE", /* 0x00000200 */
356 "RBBIM_LPARAM", /* 0x00000400 */
357 "RBBIM_HEADERSIZE", /* 0x00000800 */
358 NULL };
359
360
361static CHAR line[200];
362
363
364static CHAR *
365REBAR_FmtStyle( UINT style)
366{
367 INT i = 0;
368
369 *line = 0;
370 while (band_stylename[i]) {
371 if (style & (1<<i)) {
372 if (*line != 0) strcat(line, " | ");
373 strcat(line, band_stylename[i]);
374 }
375 i++;
376 }
377 return line;
378}
379
380
381static CHAR *
382REBAR_FmtMask( UINT mask)
383{
384 INT i = 0;
385
386 *line = 0;
387 while (band_maskname[i]) {
388 if (mask & (1<<i)) {
389 if (*line != 0) strcat(line, " | ");
390 strcat(line, band_maskname[i]);
391 }
392 i++;
393 }
394 return line;
395}
396
397
398static VOID
399REBAR_DumpBandInfo( LPREBARBANDINFOA pB)
400{
401 if( !TRACE_ON(rebar) ) return;
402 TRACE("band info: ID=%u, size=%u, child=%p, clrF=0x%06lx, clrB=0x%06lx\n",
403 pB->wID, pB->cbSize, pB->hwndChild, pB->clrFore, pB->clrBack);
404 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
405 if (pB->fMask & RBBIM_STYLE)
406 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
407 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
408 TRACE("band info:");
409 if (pB->fMask & RBBIM_SIZE)
410 DPRINTF(" cx=%u", pB->cx);
411 if (pB->fMask & RBBIM_IDEALSIZE)
412 DPRINTF(" xIdeal=%u", pB->cxIdeal);
413 if (pB->fMask & RBBIM_HEADERSIZE)
414 DPRINTF(" xHeader=%u", pB->cxHeader);
415 if (pB->fMask & RBBIM_LPARAM)
416 DPRINTF(" lParam=0x%08lx", pB->lParam);
417 DPRINTF("\n");
418 }
419 if (pB->fMask & RBBIM_CHILDSIZE)
420 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
421 pB->cxMinChild,
422 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
423}
424
425static VOID
426REBAR_DumpBand (REBAR_INFO *iP)
427{
428 REBAR_BAND *pB;
429 UINT i;
430
431 if(! TRACE_ON(rebar) ) return;
432
433 TRACE("hwnd=%p: color=%08lx/%08lx, bands=%u, rows=%u, cSize=%ld,%ld\n",
434 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
435 iP->calcSize.cx, iP->calcSize.cy);
436 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, ihitBand=%d\n",
437 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
438 iP->dragNow.x, iP->dragNow.y,
439 iP->ihitBand);
440 TRACE("hwnd=%p: style=%08lx, I'm Unicode=%s, notify in Unicode=%s, redraw=%s\n",
441 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
442 (iP->NtfUnicode)?"TRUE":"FALSE", (iP->DoRedraw)?"TRUE":"FALSE");
443 for (i = 0; i < iP->uNumBands; i++) {
444 pB = &iP->bands[i];
445 TRACE("band # %u: ID=%u, child=%p, row=%u, clrF=0x%06lx, clrB=0x%06lx\n",
446 i, pB->wID, pB->hwndChild, pB->iRow, pB->clrFore, pB->clrBack);
447 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
448 if (pB->fMask & RBBIM_STYLE)
449 TRACE("band # %u: style=0x%08x (%s)\n",
450 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
451 TRACE("band # %u: uMinH=%u xHeader=%u",
452 i, pB->uMinHeight, pB->cxHeader);
453 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
454 if (pB->fMask & RBBIM_SIZE)
455 DPRINTF(" cx=%u", pB->cx);
456 if (pB->fMask & RBBIM_IDEALSIZE)
457 DPRINTF(" xIdeal=%u", pB->cxIdeal);
458 if (pB->fMask & RBBIM_LPARAM)
459 DPRINTF(" lParam=0x%08lx", pB->lParam);
460 }
461 DPRINTF("\n");
462 if (RBBIM_CHILDSIZE)
463 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
464 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
465 if (pB->fMask & RBBIM_TEXT)
466 TRACE("band # %u: text=%s\n",
467 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
468 TRACE("band # %u: lcx=%u, ccx=%u, hcx=%u, lcy=%u, ccy=%u, hcy=%u, offChild=%ld,%ld\n",
469 i, pB->lcx, pB->ccx, pB->hcx, pB->lcy, pB->ccy, pB->hcy, pB->offChild.cx, pB->offChild.cy);
470 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%d,%d)-(%d,%d), Grip=(%d,%d)-(%d,%d)\n",
471 i, pB->fStatus, pB->fDraw,
472 pB->rcBand.left, pB->rcBand.top, pB->rcBand.right, pB->rcBand.bottom,
473 pB->rcGripper.left, pB->rcGripper.top, pB->rcGripper.right, pB->rcGripper.bottom);
474 TRACE("band # %u: Img=(%d,%d)-(%d,%d), Txt=(%d,%d)-(%d,%d), Child=(%d,%d)-(%d,%d)\n",
475 i,
476 pB->rcCapImage.left, pB->rcCapImage.top, pB->rcCapImage.right, pB->rcCapImage.bottom,
477 pB->rcCapText.left, pB->rcCapText.top, pB->rcCapText.right, pB->rcCapText.bottom,
478 pB->rcChild.left, pB->rcChild.top, pB->rcChild.right, pB->rcChild.bottom);
479 }
480
481}
482
483
484static HWND
485REBAR_GetNotifyParent (REBAR_INFO *infoPtr)
486{
487 HWND parent, owner;
488
489 parent = infoPtr->hwndNotify;
490 if (!parent) {
491 parent = GetParent (infoPtr->hwndSelf);
492 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
493 if (owner) parent = owner;
494 }
495 return parent;
496}
497
498
499static INT
500REBAR_Notify (NMHDR *nmhdr, REBAR_INFO *infoPtr, UINT code)
501{
502 HWND parent;
503
504 parent = REBAR_GetNotifyParent (infoPtr);
505 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
506 nmhdr->hwndFrom = infoPtr->hwndSelf;
507 nmhdr->code = code;
508
509 TRACE("window %p, code=%08x, %s\n", parent, code,
510 (infoPtr->NtfUnicode) ? "via Unicode" : "via ANSI");
511
512 if (infoPtr->NtfUnicode)
513 return SendMessageW (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
514 (LPARAM)nmhdr);
515 else
516 return SendMessageA (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
517 (LPARAM)nmhdr);
518}
519
520static INT
521REBAR_Notify_NMREBAR (REBAR_INFO *infoPtr, UINT uBand, UINT code)
522{
523 NMREBAR notify_rebar;
524 REBAR_BAND *lpBand;
525
526 notify_rebar.dwMask = 0;
527 if (uBand!=-1) {
528 lpBand = &infoPtr->bands[uBand];
529 if (lpBand->fMask & RBBIM_ID) {
530 notify_rebar.dwMask |= RBNM_ID;
531 notify_rebar.wID = lpBand->wID;
532 }
533 if (lpBand->fMask & RBBIM_LPARAM) {
534 notify_rebar.dwMask |= RBNM_LPARAM;
535 notify_rebar.lParam = lpBand->lParam;
536 }
537 if (lpBand->fMask & RBBIM_STYLE) {
538 notify_rebar.dwMask |= RBNM_STYLE;
539 notify_rebar.fStyle = lpBand->fStyle;
540 }
541 }
542 notify_rebar.uBand = uBand;
543 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
544}
545
546static VOID
547REBAR_DrawBand (HDC hdc, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
548{
549 HFONT hOldFont = 0;
550 INT oldBkMode = 0;
551 NMCUSTOMDRAW nmcd;
552
553 if (lpBand->fDraw & DRAW_TEXT) {
554 hOldFont = SelectObject (hdc, infoPtr->hFont);
555 oldBkMode = SetBkMode (hdc, TRANSPARENT);
556 }
557
558 /* should test for CDRF_NOTIFYITEMDRAW here */
559 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
560 nmcd.hdc = hdc;
561 nmcd.rc = lpBand->rcBand;
562 nmcd.rc.right = lpBand->rcCapText.right;
563 nmcd.rc.bottom = lpBand->rcCapText.bottom;
564 nmcd.dwItemSpec = lpBand->wID;
565 nmcd.uItemState = 0;
566 nmcd.lItemlParam = lpBand->lParam;
567 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
568 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
569 if (oldBkMode != TRANSPARENT)
570 SetBkMode (hdc, oldBkMode);
571 SelectObject (hdc, hOldFont);
572 return;
573 }
574
575 /* draw gripper */
576 if (lpBand->fDraw & DRAW_GRIPPER)
577 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
578
579 /* draw caption image */
580 if (lpBand->fDraw & DRAW_IMAGE) {
581 POINT pt;
582
583 /* center image */
584 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
585 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
586
587 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
588 pt.x, pt.y,
589 ILD_TRANSPARENT);
590 }
591
592 /* draw caption text */
593 if (lpBand->fDraw & DRAW_TEXT) {
594 /* need to handle CDRF_NEWFONT here */
595 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
596 COLORREF oldcolor = CLR_NONE;
597 COLORREF new;
598 if (lpBand->clrFore != CLR_NONE) {
599 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
600 lpBand->clrFore;
601 oldcolor = SetTextColor (hdc, new);
602 }
603 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
604 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
605 if (oldBkMode != TRANSPARENT)
606 SetBkMode (hdc, oldBkMode);
607 if (lpBand->clrFore != CLR_NONE)
608 SetTextColor (hdc, oldcolor);
609 SelectObject (hdc, hOldFont);
610 }
611
612 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
613 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
614 nmcd.hdc = hdc;
615 nmcd.rc = lpBand->rcBand;
616 nmcd.rc.right = lpBand->rcCapText.right;
617 nmcd.rc.bottom = lpBand->rcCapText.bottom;
618 nmcd.dwItemSpec = lpBand->wID;
619 nmcd.uItemState = 0;
620 nmcd.lItemlParam = lpBand->lParam;
621 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
622 }
623}
624
625
626static VOID
627REBAR_Refresh (REBAR_INFO *infoPtr, HDC hdc)
628{
629 REBAR_BAND *lpBand;
630 UINT i, oldrow;
631
632 if (!infoPtr->DoRedraw) return;
633
634 oldrow = infoPtr->bands[0].iRow;
635 for (i = 0; i < infoPtr->uNumBands; i++) {
636 lpBand = &infoPtr->bands[i];
637
638 if (HIDDENBAND(lpBand)) continue;
639
640 /* now draw the band */
641 TRACE("[%p] drawing band %i, flags=%08x\n",
642 infoPtr->hwndSelf, i, lpBand->fDraw);
643 REBAR_DrawBand (hdc, infoPtr, lpBand);
644
645 }
646}
647
648
649static void
650REBAR_FixVert (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
651 INT mcy)
652 /* Function: */
653 /* Cycle through bands in row and fix height of each band. */
654 /* Also determine whether each band has changed. */
655 /* On entry: */
656 /* all bands at desired size. */
657 /* start and end bands are *not* hidden */
658{
659 REBAR_BAND *lpBand;
660 INT i;
661
662 for (i = (INT)rowstart; i<=(INT)rowend; i++) {
663 lpBand = &infoPtr->bands[i];
664 if (HIDDENBAND(lpBand)) continue;
665
666 /* adjust height of bands in row to "mcy" value */
667 if (infoPtr->dwStyle & CCS_VERT) {
668 if (lpBand->rcBand.right != lpBand->rcBand.left + mcy)
669 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
670 }
671 else {
672 if (lpBand->rcBand.bottom != lpBand->rcBand.top + mcy)
673 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
674
675 }
676
677 /* mark whether we need to invalidate this band and trace */
678 if ((lpBand->rcoldBand.left !=lpBand->rcBand.left) ||
679 (lpBand->rcoldBand.top !=lpBand->rcBand.top) ||
680 (lpBand->rcoldBand.right !=lpBand->rcBand.right) ||
681 (lpBand->rcoldBand.bottom !=lpBand->rcBand.bottom)) {
682 lpBand->fDraw |= NTF_INVALIDATE;
683 TRACE("band %d row=%d: changed to (%d,%d)-(%d,%d) from (%d,%d)-(%d,%d)\n",
684 i, lpBand->iRow,
685 lpBand->rcBand.left, lpBand->rcBand.top,
686 lpBand->rcBand.right, lpBand->rcBand.bottom,
687 lpBand->rcoldBand.left, lpBand->rcoldBand.top,
688 lpBand->rcoldBand.right, lpBand->rcoldBand.bottom);
689 }
690 else
691 TRACE("band %d row=%d: unchanged (%d,%d)-(%d,%d)\n",
692 i, lpBand->iRow,
693 lpBand->rcBand.left, lpBand->rcBand.top,
694 lpBand->rcBand.right, lpBand->rcBand.bottom);
695 }
696}
697
698
699static void
700REBAR_AdjustBands (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
701 INT maxx, INT mcy)
702 /* Function: This routine distributes the extra space in a row. */
703 /* See algorithm below. */
704 /* On entry: */
705 /* all bands @ ->cxHeader size */
706 /* start and end bands are *not* hidden */
707{
708 REBAR_BAND *lpBand;
709 UINT x, xsep, extra, curwidth, fudge;
710 INT i, last_adjusted;
711
712 TRACE("start=%u, end=%u, max x=%d, max y=%d\n",
713 rowstart, rowend, maxx, mcy);
714
715 /* ******************* Phase 1 ************************ */
716 /* Alg: */
717 /* For each visible band with valid child */
718 /* a. inflate band till either all extra space used */
719 /* or band's ->ccx reached. */
720 /* If any band modified, add any space left to last band */
721 /* adjusted. */
722 /* */
723 /* ****************************************************** */
724 lpBand = &infoPtr->bands[rowend];
725 extra = maxx - rcBrb(lpBand);
726 x = 0;
727 last_adjusted = -1;
728 for (i=(INT)rowstart; i<=(INT)rowend; i++) {
729 lpBand = &infoPtr->bands[i];
730 if (HIDDENBAND(lpBand)) continue;
731 xsep = (x == 0) ? 0 : SEP_WIDTH;
732 curwidth = rcBw(lpBand);
733
734 /* set new left/top point */
735 if (infoPtr->dwStyle & CCS_VERT)
736 lpBand->rcBand.top = x + xsep;
737 else
738 lpBand->rcBand.left = x + xsep;
739
740 /* compute new width */
741 if ((lpBand->hwndChild && extra) && !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
742 /* set to the "current" band size less the header */
743 fudge = lpBand->ccx;
744 last_adjusted = i;
745 if ((lpBand->fMask & RBBIM_SIZE) && (lpBand->cx > 0) &&
746 (fudge > curwidth)) {
747 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d, extra=%d\n",
748 i, fudge-curwidth, fudge, curwidth, extra);
749 if ((fudge - curwidth) > extra)
750 fudge = curwidth + extra;
751 extra -= (fudge - curwidth);
752 curwidth = fudge;
753 }
754 else {
755 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d\n",
756 i, extra, fudge, curwidth);
757 curwidth += extra;
758 extra = 0;
759 }
760 }
761
762 /* set new right/bottom point */
763 if (infoPtr->dwStyle & CCS_VERT)
764 lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
765 else
766 lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
767 TRACE("Phase 1 band %d, (%d,%d)-(%d,%d), orig x=%d, xsep=%d\n",
768 i, lpBand->rcBand.left, lpBand->rcBand.top,
769 lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
770 x = rcBrb(lpBand);
771 }
772 if ((x >= maxx) || (last_adjusted != -1)) {
773 if (x > maxx) {
774 ERR("Phase 1 failed, x=%d, maxx=%d, start=%u, end=%u\n",
775 x, maxx, rowstart, rowend);
776 }
777 /* done, so spread extra space */
778 if (x < maxx) {
779 fudge = maxx - x;
780 TRACE("Need to spread %d on last adjusted band %d\n",
781 fudge, last_adjusted);
782 for (i=(INT)last_adjusted; i<=(INT)rowend; i++) {
783 lpBand = &infoPtr->bands[i];
784 if (HIDDENBAND(lpBand)) continue;
785
786 /* set right/bottom point */
787 if (i != last_adjusted) {
788 if (infoPtr->dwStyle & CCS_VERT)
789 lpBand->rcBand.top += fudge;
790 else
791 lpBand->rcBand.left += fudge;
792 }
793
794 /* set left/bottom point */
795 if (infoPtr->dwStyle & CCS_VERT)
796 lpBand->rcBand.bottom += fudge;
797 else
798 lpBand->rcBand.right += fudge;
799 }
800 }
801 TRACE("Phase 1 succeeded, used x=%d\n", x);
802 REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
803 return;
804 }
805
806 /* ******************* Phase 2 ************************ */
807 /* Alg: */
808 /* Find first visible band, put all */
809 /* extra space there. */
810 /* */
811 /* ****************************************************** */
812
813 x = 0;
814 for (i=(INT)rowstart; i<=(INT)rowend; i++) {
815 lpBand = &infoPtr->bands[i];
816 if (HIDDENBAND(lpBand)) continue;
817 xsep = (x == 0) ? 0 : SEP_WIDTH;
818 curwidth = rcBw(lpBand);
819
820 /* set new left/top point */
821 if (infoPtr->dwStyle & CCS_VERT)
822 lpBand->rcBand.top = x + xsep;
823 else
824 lpBand->rcBand.left = x + xsep;
825
826 /* compute new width */
827 if (extra) {
828 curwidth += extra;
829 extra = 0;
830 }
831
832 /* set new right/bottom point */
833 if (infoPtr->dwStyle & CCS_VERT)
834 lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
835 else
836 lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
837 TRACE("Phase 2 band %d, (%d,%d)-(%d,%d), orig x=%d, xsep=%d\n",
838 i, lpBand->rcBand.left, lpBand->rcBand.top,
839 lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
840 x = rcBrb(lpBand);
841 }
842 if (x >= maxx) {
843 if (x > maxx) {
844 ERR("Phase 2 failed, x=%d, maxx=%d, start=%u, end=%u\n",
845 x, maxx, rowstart, rowend);
846 }
847 /* done, so spread extra space */
848 TRACE("Phase 2 succeeded, used x=%d\n", x);
849 REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
850 return;
851 }
852
853 /* ******************* Phase 3 ************************ */
854 /* at this point everything is back to ->cxHeader values */
855 /* and should not have gotten here. */
856 /* ****************************************************** */
857
858 lpBand = &infoPtr->bands[rowstart];
859 ERR("Serious problem adjusting row %d, start band %d, end band %d\n",
860 lpBand->iRow, rowstart, rowend);
861 REBAR_DumpBand (infoPtr);
862 return;
863}
864
865
866static void
867REBAR_CalcHorzBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
868 /* Function: this routine initializes all the rectangles in */
869 /* each band in a row to fit in the adjusted rcBand rect. */
870 /* *** Supports only Horizontal bars. *** */
871{
872 REBAR_BAND *lpBand;
873 UINT i, xoff, yoff;
874 HWND parenthwnd;
875 RECT oldChild, work;
876
877 /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
878 parenthwnd = GetParent (infoPtr->hwndSelf);
879
880 for(i=rstart; i<rend; i++){
881 lpBand = &infoPtr->bands[i];
882 if (HIDDENBAND(lpBand)) {
883 SetRect (&lpBand->rcChild,
884 lpBand->rcBand.right, lpBand->rcBand.top,
885 lpBand->rcBand.right, lpBand->rcBand.bottom);
886 continue;
887 }
888
889 oldChild = lpBand->rcChild;
890
891 /* set initial gripper rectangle */
892 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
893 lpBand->rcBand.left, lpBand->rcBand.bottom);
894
895 /* calculate gripper rectangle */
896 if ( lpBand->fStatus & HAS_GRIPPER) {
897 lpBand->fDraw |= DRAW_GRIPPER;
898 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
899 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
900 lpBand->rcGripper.top += 2;
901 lpBand->rcGripper.bottom -= 2;
902
903 SetRect (&lpBand->rcCapImage,
904 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
905 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
906 }
907 else { /* no gripper will be drawn */
908 xoff = 0;
909 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
910 /* if no gripper but either image or text, then leave space */
911 xoff = REBAR_ALWAYS_SPACE;
912 SetRect (&lpBand->rcCapImage,
913 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
914 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
915 }
916
917 /* image is visible */
918 if (lpBand->fStatus & HAS_IMAGE) {
919 lpBand->fDraw |= DRAW_IMAGE;
920 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
921 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
922
923 /* set initial caption text rectangle */
924 SetRect (&lpBand->rcCapText,
925 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
926 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
927 /* update band height
928 if (lpBand->uMinHeight < infoPtr->imageSize.cy + 2) {
929 lpBand->uMinHeight = infoPtr->imageSize.cy + 2;
930 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->uMinHeight;
931 } */
932 }
933 else {
934 /* set initial caption text rectangle */
935 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
936 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
937 }
938
939 /* text is visible */
940 if (lpBand->fStatus & HAS_TEXT) {
941 lpBand->fDraw |= DRAW_TEXT;
942 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
943 lpBand->rcCapText.right-REBAR_POST_TEXT);
944 }
945
946 /* set initial child window rectangle if there is a child */
947 if (lpBand->fMask & RBBIM_CHILD) {
948 xoff = lpBand->offChild.cx;
949 yoff = lpBand->offChild.cy;
950 SetRect (&lpBand->rcChild,
951 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top+yoff,
952 lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
953 }
954 else {
955 SetRect (&lpBand->rcChild,
956 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
957 lpBand->rcBand.right, lpBand->rcBand.bottom);
958 }
959
960 /* flag if notify required and invalidate rectangle */
961 if (notify &&
962 ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
963 (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
964 TRACE("Child rectangle changed for band %u\n", i);
965 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
966 oldChild.left, oldChild.top,
967 oldChild.right, oldChild.bottom,
968 lpBand->rcChild.left, lpBand->rcChild.top,
969 lpBand->rcChild.right, lpBand->rcChild.bottom);
970 }
971 if (lpBand->fDraw & NTF_INVALIDATE) {
972 TRACE("invalidating (%d,%d)-(%d,%d)\n",
973 lpBand->rcBand.left,
974 lpBand->rcBand.top,
975 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0),
976 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0));
977 lpBand->fDraw &= ~NTF_INVALIDATE;
978 work = lpBand->rcBand;
979 if (lpBand->fDraw & DRAW_RIGHTSEP) work.right += SEP_WIDTH_SIZE;
980 if (lpBand->fDraw & DRAW_BOTTOMSEP) work.bottom += SEP_WIDTH_SIZE;
981 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
982 }
983
984 }
985
986}
987
988
989static VOID
990REBAR_CalcVertBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
991 /* Function: this routine initializes all the rectangles in */
992 /* each band in a row to fit in the adjusted rcBand rect. */
993 /* *** Supports only Vertical bars. *** */
994{
995 REBAR_BAND *lpBand;
996 UINT i, xoff, yoff;
997 HWND parenthwnd;
998 RECT oldChild, work;
999
1000 /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
1001 parenthwnd = GetParent (infoPtr->hwndSelf);
1002
1003 for(i=rstart; i<rend; i++){
1004 lpBand = &infoPtr->bands[i];
1005 if (HIDDENBAND(lpBand)) continue;
1006 oldChild = lpBand->rcChild;
1007
1008 /* set initial gripper rectangle */
1009 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
1010 lpBand->rcBand.right, lpBand->rcBand.top);
1011
1012 /* calculate gripper rectangle */
1013 if (lpBand->fStatus & HAS_GRIPPER) {
1014 lpBand->fDraw |= DRAW_GRIPPER;
1015
1016 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
1017 /* vertical gripper */
1018 lpBand->rcGripper.left += 3;
1019 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
1020 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
1021 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
1022
1023 /* initialize Caption image rectangle */
1024 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1025 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1026 lpBand->rcBand.right,
1027 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1028 }
1029 else {
1030 /* horizontal gripper */
1031 lpBand->rcGripper.left += 2;
1032 lpBand->rcGripper.right -= 2;
1033 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
1034 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
1035
1036 /* initialize Caption image rectangle */
1037 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1038 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1039 lpBand->rcBand.right,
1040 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1041 }
1042 }
1043 else { /* no gripper will be drawn */
1044 xoff = 0;
1045 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
1046 /* if no gripper but either image or text, then leave space */
1047 xoff = REBAR_ALWAYS_SPACE;
1048 /* initialize Caption image rectangle */
1049 SetRect (&lpBand->rcCapImage,
1050 lpBand->rcBand.left, lpBand->rcBand.top+xoff,
1051 lpBand->rcBand.right, lpBand->rcBand.top+xoff);
1052 }
1053
1054 /* image is visible */
1055 if (lpBand->fStatus & HAS_IMAGE) {
1056 lpBand->fDraw |= DRAW_IMAGE;
1057
1058 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
1059 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
1060
1061 /* set initial caption text rectangle */
1062 SetRect (&lpBand->rcCapText,
1063 lpBand->rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
1064 lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1065 /* update band height *
1066 if (lpBand->uMinHeight < infoPtr->imageSize.cx + 2) {
1067 lpBand->uMinHeight = infoPtr->imageSize.cx + 2;
1068 lpBand->rcBand.right = lpBand->rcBand.left + lpBand->uMinHeight;
1069 } */
1070 }
1071 else {
1072 /* set initial caption text rectangle */
1073 SetRect (&lpBand->rcCapText,
1074 lpBand->rcBand.left, lpBand->rcCapImage.bottom,
1075 lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1076 }
1077
1078 /* text is visible */
1079 if (lpBand->fStatus & HAS_TEXT) {
1080 lpBand->fDraw |= DRAW_TEXT;
1081 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
1082 lpBand->rcCapText.bottom);
1083 }
1084
1085 /* set initial child window rectangle if there is a child */
1086 if (lpBand->fMask & RBBIM_CHILD) {
1087 yoff = lpBand->offChild.cx;
1088 xoff = lpBand->offChild.cy;
1089 SetRect (&lpBand->rcChild,
1090 lpBand->rcBand.left+xoff, lpBand->rcBand.top+lpBand->cxHeader,
1091 lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
1092 }
1093 else {
1094 SetRect (&lpBand->rcChild,
1095 lpBand->rcBand.left, lpBand->rcBand.top+lpBand->cxHeader,
1096 lpBand->rcBand.right, lpBand->rcBand.bottom);
1097 }
1098
1099 /* flag if notify required and invalidate rectangle */
1100 if (notify &&
1101 ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
1102 (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
1103 TRACE("Child rectangle changed for band %u\n", i);
1104 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
1105 oldChild.left, oldChild.top,
1106 oldChild.right, oldChild.bottom,
1107 lpBand->rcChild.left, lpBand->rcChild.top,
1108 lpBand->rcChild.right, lpBand->rcChild.bottom);
1109 }
1110 if (lpBand->fDraw & NTF_INVALIDATE) {
1111 TRACE("invalidating (%d,%d)-(%d,%d)\n",
1112 lpBand->rcBand.left,
1113 lpBand->rcBand.top,
1114 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0),
1115 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0));
1116 lpBand->fDraw &= ~NTF_INVALIDATE;
1117 work = lpBand->rcBand;
1118 if (lpBand->fDraw & DRAW_RIGHTSEP) work.bottom += SEP_WIDTH_SIZE;
1119 if (lpBand->fDraw & DRAW_BOTTOMSEP) work.right += SEP_WIDTH_SIZE;
1120 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
1121 }
1122
1123 }
1124}
1125
1126
1127static VOID
1128REBAR_ForceResize (REBAR_INFO *infoPtr)
1129 /* Function: This changes the size of the REBAR window to that */
1130 /* calculated by REBAR_Layout. */
1131{
1132 RECT rc;
1133 INT x, y, width, height;
1134 INT xedge = GetSystemMetrics(SM_CXEDGE);
1135 INT yedge = GetSystemMetrics(SM_CYEDGE);
1136
1137 /* TEST TEST TEST */
1138 GetWindowRect (infoPtr->hwndSelf, &rc);
1139 /* END TEST END TEST END TEST */
1140
1141
1142 GetClientRect (infoPtr->hwndSelf, &rc);
1143
1144 TRACE( " old [%ld x %ld], new [%ld x %ld], client [%d x %d]\n",
1145 infoPtr->oldSize.cx, infoPtr->oldSize.cy,
1146 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1147 rc.right, rc.bottom);
1148
1149 /* If we need to shrink client, then skip size test */
1150 if ((infoPtr->calcSize.cy >= rc.bottom) &&
1151 (infoPtr->calcSize.cx >= rc.right)) {
1152
1153 /* if size did not change then skip process */
1154 if ((infoPtr->oldSize.cx == infoPtr->calcSize.cx) &&
1155 (infoPtr->oldSize.cy == infoPtr->calcSize.cy) &&
1156 !(infoPtr->fStatus & RESIZE_ANYHOW))
1157 {
1158 TRACE("skipping reset\n");
1159 return;
1160 }
1161 }
1162
1163 infoPtr->fStatus &= ~RESIZE_ANYHOW;
1164 /* Set flag to ignore next WM_SIZE message */
1165 infoPtr->fStatus |= AUTO_RESIZE;
1166
1167 width = 0;
1168 height = 0;
1169 x = 0;
1170 y = 0;
1171
1172 if (infoPtr->dwStyle & WS_BORDER) {
1173 width = 2 * xedge;
1174 height = 2 * yedge;
1175 }
1176
1177 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
1178 INT mode = infoPtr->dwStyle & (CCS_VERT | CCS_TOP | CCS_BOTTOM);
1179 RECT rcPcl;
1180
1181 GetClientRect(GetParent(infoPtr->hwndSelf), &rcPcl);
1182 switch (mode) {
1183 case CCS_TOP:
1184 /* _TOP sets width to parents width */
1185 width += (rcPcl.right - rcPcl.left);
1186 height += infoPtr->calcSize.cy;
1187 x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1188 y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1189 y += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1190 break;
1191 case CCS_BOTTOM:
1192 /* FIXME: wrong wrong wrong */
1193 /* _BOTTOM sets width to parents width */
1194 width += (rcPcl.right - rcPcl.left);
1195 height += infoPtr->calcSize.cy;
1196 x += -xedge;
1197 y = rcPcl.bottom - height + 1;
1198 break;
1199 case CCS_LEFT:
1200 /* _LEFT sets height to parents height */
1201 width += infoPtr->calcSize.cx;
1202 height += (rcPcl.bottom - rcPcl.top);
1203 x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1204 x += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1205 y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1206 break;
1207 case CCS_RIGHT:
1208 /* FIXME: wrong wrong wrong */
1209 /* _RIGHT sets height to parents height */
1210 width += infoPtr->calcSize.cx;
1211 height += (rcPcl.bottom - rcPcl.top);
1212 x = rcPcl.right - width + 1;
1213 y = -yedge;
1214 break;
1215 default:
1216 width += infoPtr->calcSize.cx;
1217 height += infoPtr->calcSize.cy;
1218 }
1219 }
1220 else {
1221 width += infoPtr->calcSize.cx;
1222 height += infoPtr->calcSize.cy;
1223 x = infoPtr->origin.x;
1224 y = infoPtr->origin.y;
1225 }
1226
1227 TRACE("hwnd %p, style=%08lx, setting at (%d,%d) for (%d,%d)\n",
1228 infoPtr->hwndSelf, infoPtr->dwStyle,
1229 x, y, width, height);
1230 SetWindowPos (infoPtr->hwndSelf, 0, x, y, width, height,
1231 SWP_NOZORDER);
1232}
1233
1234
1235static VOID
1236REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
1237{
1238 REBAR_BAND *lpBand;
1239 CHAR szClassName[40];
1240 UINT i;
1241 NMREBARCHILDSIZE rbcz;
1242 NMHDR heightchange;
1243 HDWP deferpos;
1244
1245 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1246 ERR("BeginDeferWindowPos returned NULL\n");
1247
1248 for (i = start; i < endplus; i++) {
1249 lpBand = &infoPtr->bands[i];
1250
1251 if (HIDDENBAND(lpBand)) continue;
1252 if (lpBand->hwndChild) {
1253 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1254
1255 /* Always geterate the RBN_CHILDSIZE even it child
1256 did not change */
1257 rbcz.uBand = i;
1258 rbcz.wID = lpBand->wID;
1259 rbcz.rcChild = lpBand->rcChild;
1260 rbcz.rcBand = lpBand->rcBand;
1261 if (infoPtr->dwStyle & CCS_VERT)
1262 rbcz.rcBand.top += lpBand->cxHeader;
1263 else
1264 rbcz.rcBand.left += lpBand->cxHeader;
1265 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1266 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1267 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1268 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
1269 lpBand->rcChild.left, lpBand->rcChild.top,
1270 lpBand->rcChild.right, lpBand->rcChild.bottom,
1271 rbcz.rcChild.left, rbcz.rcChild.top,
1272 rbcz.rcChild.right, rbcz.rcChild.bottom);
1273 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1274 }
1275
1276 /* native (IE4 in "Favorites" frame **1) does:
1277 * SetRect (&rc, -1, -1, -1, -1)
1278 * EqualRect (&rc,band->rc???)
1279 * if ret==0
1280 * CopyRect (band->rc????, &rc)
1281 * set flag outside of loop
1282 */
1283
1284 GetClassNameA (lpBand->hwndChild, szClassName, 40);
1285 if (!lstrcmpA (szClassName, "ComboBox") ||
1286 !lstrcmpA (szClassName, WC_COMBOBOXEXA)) {
1287 INT nEditHeight, yPos;
1288 RECT rc;
1289
1290 /* special placement code for combo or comboex box */
1291
1292
1293 /* get size of edit line */
1294 GetWindowRect (lpBand->hwndChild, &rc);
1295 nEditHeight = rc.bottom - rc.top;
1296 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1297
1298 /* center combo box inside child area */
1299 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1300 lpBand->hwndChild,
1301 lpBand->rcChild.left, yPos,
1302 lpBand->rcChild.right - lpBand->rcChild.left,
1303 nEditHeight);
1304 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1305 lpBand->rcChild.left,
1306 /*lpBand->rcChild.top*/ yPos,
1307 lpBand->rcChild.right - lpBand->rcChild.left,
1308 nEditHeight,
1309 SWP_NOZORDER);
1310 if (!deferpos)
1311 ERR("DeferWindowPos returned NULL\n");
1312 }
1313 else {
1314 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1315 lpBand->hwndChild,
1316 lpBand->rcChild.left, lpBand->rcChild.top,
1317 lpBand->rcChild.right - lpBand->rcChild.left,
1318 lpBand->rcChild.bottom - lpBand->rcChild.top);
1319 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1320 lpBand->rcChild.left,
1321 lpBand->rcChild.top,
1322 lpBand->rcChild.right - lpBand->rcChild.left,
1323 lpBand->rcChild.bottom - lpBand->rcChild.top,
1324 SWP_NOZORDER);
1325 if (!deferpos)
1326 ERR("DeferWindowPos returned NULL\n");
1327 }
1328 }
1329 }
1330 if (!EndDeferWindowPos(deferpos))
1331 ERR("EndDeferWindowPos returned NULL\n");
1332
1333 if (infoPtr->DoRedraw)
1334 UpdateWindow (infoPtr->hwndSelf);
1335
1336 if (infoPtr->fStatus & NTF_HGHTCHG) {
1337 infoPtr->fStatus &= ~NTF_HGHTCHG;
1338 REBAR_Notify (&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1339 }
1340
1341 /* native (from **1 above) does:
1342 * UpdateWindow(rebar)
1343 * REBAR_ForceResize
1344 * RBN_HEIGHTCHANGE if necessary
1345 * if ret from any EqualRect was 0
1346 * Goto "BeginDeferWindowPos"
1347 */
1348
1349}
1350
1351
1352static VOID
1353REBAR_Layout (REBAR_INFO *infoPtr, LPRECT lpRect, BOOL notify, BOOL resetclient)
1354 /* Function: This routine is resposible for laying out all */
1355 /* the bands in a rebar. It assigns each band to a row and*/
1356 /* determines when to start a new row. */
1357{
1358 REBAR_BAND *lpBand, *prevBand;
1359 RECT rcClient, rcAdj;
1360 INT initx, inity, x, y, cx, cxsep, mmcy, mcy, clientcx, clientcy;
1361 INT adjcx, adjcy, row, rightx, bottomy, origheight;
1362 UINT i, j, rowstart, origrows, cntonrow;
1363 BOOL dobreak;
1364
1365 if (!(infoPtr->fStatus & BAND_NEEDS_LAYOUT)) {
1366 TRACE("no layout done. No band changed.\n");
1367 REBAR_DumpBand (infoPtr);
1368 return;
1369 }
1370 infoPtr->fStatus &= ~BAND_NEEDS_LAYOUT;
1371 if (!infoPtr->DoRedraw) infoPtr->fStatus |= BAND_NEEDS_REDRAW;
1372
1373 GetClientRect (infoPtr->hwndSelf, &rcClient);
1374 TRACE("Client is (%d,%d)-(%d,%d)\n",
1375 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
1376
1377 if (lpRect) {
1378 rcAdj = *lpRect;
1379 TRACE("adjustment rect is (%d,%d)-(%d,%d)\n",
1380 rcAdj.left, rcAdj.top, rcAdj.right, rcAdj.bottom);
1381 }
1382 else {
1383 CopyRect (&rcAdj, &rcClient);
1384 }
1385
1386 clientcx = rcClient.right - rcClient.left;
1387 clientcy = rcClient.bottom - rcClient.top;
1388 adjcx = rcAdj.right - rcAdj.left;
1389 adjcy = rcAdj.bottom - rcAdj.top;
1390 if (resetclient) {
1391 TRACE("window client rect will be set to adj rect\n");
1392 clientcx = adjcx;
1393 clientcy = adjcy;
1394 }
1395
1396 if (!infoPtr->DoRedraw && (clientcx == 0) && (clientcy == 0)) {
1397 ERR("no redraw and client is zero, skip layout\n");
1398 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1399 return;
1400 }
1401
1402 /* save height of original control */
1403 if (infoPtr->dwStyle & CCS_VERT)
1404 origheight = infoPtr->calcSize.cx;
1405 else
1406 origheight = infoPtr->calcSize.cy;
1407 origrows = infoPtr->uNumRows;
1408
1409 initx = 0;
1410 inity = 0;
1411
1412 /* ******* Start Phase 1 - all bands on row at minimum size ******* */
1413
1414 TRACE("band loop constants, clientcx=%d, clientcy=%d, adjcx=%d, adjcy=%d\n",
1415 clientcx, clientcy, adjcx, adjcy);
1416 x = initx;
1417 y = inity;
1418 row = 1;
1419 cx = 0;
1420 mcy = 0;
1421 rowstart = 0;
1422 prevBand = NULL;
1423 cntonrow = 0;
1424
1425 for (i = 0; i < infoPtr->uNumBands; i++) {
1426 lpBand = &infoPtr->bands[i];
1427 lpBand->fDraw = 0;
1428 lpBand->iRow = row;
1429
1430 if (HIDDENBAND(lpBand)) continue;
1431
1432 lpBand->rcoldBand = lpBand->rcBand;
1433
1434 /* Set the offset of the child window */
1435 if ((lpBand->fMask & RBBIM_CHILD) &&
1436 !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
1437 lpBand->offChild.cx = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 4 : 0);
1438 }
1439 lpBand->offChild.cy = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 2 : 0);
1440
1441 /* separator from previous band */
1442 cxsep = (cntonrow == 0) ? 0 : SEP_WIDTH;
1443
1444 /* Header: includes gripper, text, image */
1445 cx = lpBand->cxHeader;
1446 if (lpBand->fStyle & RBBS_FIXEDSIZE) cx = lpBand->lcx;
1447
1448 if (infoPtr->dwStyle & CCS_VERT)
1449 dobreak = (y + cx + cxsep > adjcy);
1450 else
1451 dobreak = (x + cx + cxsep > adjcx);
1452
1453 /* This is the check for whether we need to start a new row */
1454 if ( ( (lpBand->fStyle & RBBS_BREAK) && (i != 0) ) ||
1455 ( ((infoPtr->dwStyle & CCS_VERT) ? (y != 0) : (x != 0)) && dobreak)) {
1456
1457 for (j = rowstart; j < i; j++) {
1458 REBAR_BAND *lpB;
1459 lpB = &infoPtr->bands[j];
1460 if (infoPtr->dwStyle & CCS_VERT) {
1461 lpB->rcBand.right = lpB->rcBand.left + mcy;
1462 }
1463 else {
1464 lpB->rcBand.bottom = lpB->rcBand.top + mcy;
1465 }
1466 }
1467
1468 TRACE("P1 Spliting to new row %d on band %u\n", row+1, i);
1469 if (infoPtr->dwStyle & CCS_VERT) {
1470 y = inity;
1471 x += (mcy + SEP_WIDTH);
1472 }
1473 else {
1474 x = initx;
1475 y += (mcy + SEP_WIDTH);
1476 }
1477
1478 mcy = 0;
1479 cxsep = 0;
1480 row++;
1481 lpBand->iRow = row;
1482 prevBand = NULL;
1483 rowstart = i;
1484 cntonrow = 0;
1485 }
1486
1487 if (mcy < lpBand->lcy + REBARSPACE(lpBand))
1488 mcy = lpBand->lcy + REBARSPACE(lpBand);
1489
1490 /* if boundary rect specified then limit mcy */
1491 if (lpRect) {
1492 if (infoPtr->dwStyle & CCS_VERT) {
1493 if (x+mcy > adjcx) {
1494 mcy = adjcx - x;
1495 TRACE("P1 row %u limiting mcy=%d, adjcx=%d, x=%d\n",
1496 i, mcy, adjcx, x);
1497 }
1498 }
1499 else {
1500 if (y+mcy > adjcy) {
1501 mcy = adjcy - y;
1502 TRACE("P1 row %u limiting mcy=%d, adjcy=%d, y=%d\n",
1503 i, mcy, adjcy, y);
1504 }
1505 }
1506 }
1507
1508 TRACE("P1 band %u, row %d, x=%d, y=%d, cxsep=%d, cx=%d\n",
1509 i, row,
1510 x, y, cxsep, cx);
1511 if (infoPtr->dwStyle & CCS_VERT) {
1512 /* bound the bottom side if we have a bounding rectangle */
1513 rightx = clientcx;
1514 bottomy = (lpRect) ? min(clientcy, y+cxsep+cx) : y+cxsep+cx;
1515 lpBand->rcBand.left = x;
1516 lpBand->rcBand.right = x + min(mcy,
1517 lpBand->lcy+REBARSPACE(lpBand));
1518 lpBand->rcBand.top = min(bottomy, y + cxsep);
1519 lpBand->rcBand.bottom = bottomy;
1520 lpBand->uMinHeight = lpBand->lcy;
1521 y = bottomy;
1522 }
1523 else {
1524 /* bound the right side if we have a bounding rectangle */
1525 rightx = (lpRect) ? min(clientcx, x+cxsep+cx) : x+cxsep+cx;
1526 bottomy = clientcy;
1527 lpBand->rcBand.left = min(rightx, x + cxsep);
1528 lpBand->rcBand.right = rightx;
1529 lpBand->rcBand.top = y;
1530 lpBand->rcBand.bottom = y + min(mcy,
1531 lpBand->lcy+REBARSPACE(lpBand));
1532 lpBand->uMinHeight = lpBand->lcy;
1533 x = rightx;
1534 }
1535 TRACE("P1 band %u, row %d, (%d,%d)-(%d,%d)\n",
1536 i, row,
1537 lpBand->rcBand.left, lpBand->rcBand.top,
1538 lpBand->rcBand.right, lpBand->rcBand.bottom);
1539 prevBand = lpBand;
1540 cntonrow++;
1541
1542 } /* for (i = 0; i < infoPtr->uNumBands... */
1543
1544 if (infoPtr->dwStyle & CCS_VERT)
1545 x += mcy;
1546 else
1547 y += mcy;
1548
1549 for (j = rowstart; j < infoPtr->uNumBands; j++) {
1550 lpBand = &infoPtr->bands[j];
1551 if (infoPtr->dwStyle & CCS_VERT) {
1552 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
1553 }
1554 else {
1555 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
1556 }
1557 }
1558
1559 if (infoPtr->uNumBands)
1560 infoPtr->uNumRows = row;
1561
1562 /* ******* End Phase 1 - all bands on row at minimum size ******* */
1563
1564
1565 /* ******* Start Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1566
1567 mmcy = 0;
1568 if (!(infoPtr->dwStyle & RBS_VARHEIGHT)) {
1569 INT xy;
1570
1571 /* get the max height of all bands */
1572 for (i=0; i<infoPtr->uNumBands; i++) {
1573 lpBand = &infoPtr->bands[i];
1574 if (HIDDENBAND(lpBand)) continue;
1575 if (infoPtr->dwStyle & CCS_VERT)
1576 mmcy = max(mmcy, lpBand->rcBand.right - lpBand->rcBand.left);
1577 else
1578 mmcy = max(mmcy, lpBand->rcBand.bottom - lpBand->rcBand.top);
1579 }
1580
1581 /* now adjust all rectangles by using the height found above */
1582 xy = 0;
1583 row = 1;
1584 for (i=0; i<infoPtr->uNumBands; i++) {
1585 lpBand = &infoPtr->bands[i];
1586 if (HIDDENBAND(lpBand)) continue;
1587 if (lpBand->iRow != row)
1588 xy += (mmcy + SEP_WIDTH);
1589 if (infoPtr->dwStyle & CCS_VERT) {
1590 lpBand->rcBand.left = xy;
1591 lpBand->rcBand.right = xy + mmcy;
1592 }
1593 else {
1594 lpBand->rcBand.top = xy;
1595 lpBand->rcBand.bottom = xy + mmcy;
1596 }
1597 }
1598
1599 /* set the x/y values to the correct maximum */
1600 if (infoPtr->dwStyle & CCS_VERT)
1601 x = xy + mmcy;
1602 else
1603 y = xy + mmcy;
1604 }
1605
1606 /* ******* End Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1607
1608
1609 /* ******* Start Phase 2 - split rows till adjustment height full ******* */
1610
1611 /* assumes that the following variables contain: */
1612 /* y/x current height/width of all rows */
1613 if (lpRect) {
1614 INT i, j, prev_rh, new_rh, adj_rh, prev_idx, current_idx;
1615 REBAR_BAND *prev, *current, *walk;
1616
1617/* FIXME: problem # 2 */
1618 if (((infoPtr->dwStyle & CCS_VERT) ?
1619#if PROBLEM2
1620 (x < adjcx) : (y < adjcy)
1621#else
1622 (adjcx - x > 4) : (adjcy - y > 4)
1623#endif
1624 ) &&
1625 (infoPtr->uNumBands > 1)) {
1626 for (i=(INT)infoPtr->uNumBands-2; i>=0; i--) {
1627 TRACE("P2 adjcx=%d, adjcy=%d, x=%d, y=%d\n",
1628 adjcx, adjcy, x, y);
1629
1630 /* find the current band (starts at i+1) */
1631 current = &infoPtr->bands[i+1];
1632 current_idx = i+1;
1633 while (HIDDENBAND(current)) {
1634 i--;
1635 if (i < 0) break; /* out of bands */
1636 current = &infoPtr->bands[i+1];
1637 current_idx = i+1;
1638 }
1639 if (i < 0) break; /* out of bands */
1640
1641 /* now find the prev band (starts at i) */
1642 prev = &infoPtr->bands[i];
1643 prev_idx = i;
1644 while (HIDDENBAND(prev)) {
1645 i--;
1646 if (i < 0) break; /* out of bands */
1647 prev = &infoPtr->bands[i];
1648 prev_idx = i;
1649 }
1650 if (i < 0) break; /* out of bands */
1651
1652 prev_rh = ircBw(prev);
1653 if (prev->iRow == current->iRow) {
1654 new_rh = (infoPtr->dwStyle & RBS_VARHEIGHT) ?
1655 current->lcy + REBARSPACE(current) :
1656 mmcy;
1657 adj_rh = new_rh + SEP_WIDTH;
1658 infoPtr->uNumRows++;
1659 current->fDraw |= NTF_INVALIDATE;
1660 current->iRow++;
1661 if (infoPtr->dwStyle & CCS_VERT) {
1662 current->rcBand.top = inity;
1663 current->rcBand.bottom = clientcy;
1664 current->rcBand.left += (prev_rh + SEP_WIDTH);
1665 current->rcBand.right = current->rcBand.left + new_rh;
1666 x += adj_rh;
1667 }
1668 else {
1669 current->rcBand.left = initx;
1670 current->rcBand.right = clientcx;
1671 current->rcBand.top += (prev_rh + SEP_WIDTH);
1672 current->rcBand.bottom = current->rcBand.top + new_rh;
1673 y += adj_rh;
1674 }
1675 TRACE("P2 moving band %d to own row at (%d,%d)-(%d,%d)\n",
1676 current_idx,
1677 current->rcBand.left, current->rcBand.top,
1678 current->rcBand.right, current->rcBand.bottom);
1679 TRACE("P2 prev band %d at (%d,%d)-(%d,%d)\n",
1680 prev_idx,
1681 prev->rcBand.left, prev->rcBand.top,
1682 prev->rcBand.right, prev->rcBand.bottom);
1683 TRACE("P2 values: prev_rh=%d, new_rh=%d, adj_rh=%d\n",
1684 prev_rh, new_rh, adj_rh);
1685 /* for bands below current adjust row # and top/bottom */
1686 for (j = current_idx+1; j<infoPtr->uNumBands; j++) {
1687 walk = &infoPtr->bands[j];
1688 if (HIDDENBAND(walk)) continue;
1689 walk->fDraw |= NTF_INVALIDATE;
1690 walk->iRow++;
1691 if (infoPtr->dwStyle & CCS_VERT) {
1692 walk->rcBand.left += adj_rh;
1693 walk->rcBand.right += adj_rh;
1694 }
1695 else {
1696 walk->rcBand.top += adj_rh;
1697 walk->rcBand.bottom += adj_rh;
1698 }
1699 }
1700 if ((infoPtr->dwStyle & CCS_VERT) ? (x >= adjcx) : (y >= adjcy))
1701 break; /* all done */
1702 }
1703 }
1704 }
1705 }
1706
1707 /* ******* End Phase 2 - split rows till adjustment height full ******* */
1708
1709
1710 /* ******* Start Phase 2a - create array of start and end ******* */
1711 /* indexes by row */
1712
1713 if (infoPtr->uNumRows != origrows) {
1714 if (infoPtr->rows) COMCTL32_Free (infoPtr->rows);
1715 infoPtr->rows = COMCTL32_Alloc (sizeof (REBAR_ROW) * infoPtr->uNumRows);
1716 }
1717
1718 row = 0;
1719 for (i = 0; i < infoPtr->uNumBands; i++) {
1720 lpBand = &infoPtr->bands[i];
1721 if (HIDDENBAND(lpBand)) continue;
1722
1723 if (lpBand->iRow > row) {
1724 row++;
1725 infoPtr->rows[row-1].istartband = i;
1726 }
1727 if (row == 0) {
1728 ERR("P2a bug!!!!!!\n");
1729 }
1730 infoPtr->rows[row-1].iendband = i;
1731 }
1732
1733 for (i = 0; i < infoPtr->uNumRows; i++) {
1734 REBAR_ROW *p;
1735
1736 p = &infoPtr->rows[i];
1737 TRACE("P2a row %d, starts %d, ends %d\n",
1738 i+1, p->istartband, p->iendband);
1739 }
1740
1741 /* ******* End Phase 2a - create array of start and end ******* */
1742 /* indexes by row */
1743
1744
1745 /* ******* Start Phase 2b - adjust all bands for height full ******* */
1746 /* assumes that the following variables contain: */
1747 /* y/x current height/width of all rows */
1748 /* clientcy/clientcx height/width of client area */
1749
1750 if (((infoPtr->dwStyle & CCS_VERT) ? clientcx > x : clientcy > y) &&
1751 infoPtr->uNumBands) {
1752 INT diff, i, iband, j;
1753
1754 diff = (infoPtr->dwStyle & CCS_VERT) ? clientcx - x : clientcy - y;
1755 for (i = infoPtr->uNumRows; i >= 1; i--) {
1756 /* if row has more than 1 band, ignore row */
1757 if (infoPtr->rows[i-1].istartband != infoPtr->rows[i-1].iendband)
1758 continue;
1759 /* point to only band in row */
1760 iband = infoPtr->rows[i-1].istartband;
1761 lpBand = &infoPtr->bands[iband];
1762 if(HIDDENBAND(lpBand)) continue;
1763 if (lpBand->fMask & RBBS_VARIABLEHEIGHT) continue;
1764 if (((INT)lpBand->cyMaxChild < 1) ||
1765 ((INT)lpBand->cyIntegral < 1)) {
1766 if (lpBand->cyMaxChild + lpBand->cyIntegral == 0) continue;
1767 ERR("P2b band %u RBBS_VARIABLEHEIGHT set but cyMax=%d, cyInt=%d\n",
1768 iband, lpBand->cyMaxChild, lpBand->cyIntegral);
1769 continue;
1770 }
1771 /* j is now the maximum height/width in the client area */
1772 j = ((diff / lpBand->cyIntegral) * lpBand->cyIntegral) +
1773 ircBw(lpBand);
1774 if (j > lpBand->cyMaxChild + REBARSPACE(lpBand))
1775 j = lpBand->cyMaxChild + REBARSPACE(lpBand);
1776 diff -= (j - ircBw(lpBand));
1777 if (infoPtr->dwStyle & CCS_VERT)
1778 lpBand->rcBand.right = lpBand->rcBand.left + j;
1779 else
1780 lpBand->rcBand.bottom = lpBand->rcBand.top + j;
1781 TRACE("P2b band %d, row %d changed to (%d,%d)-(%d,%d)\n",
1782 iband, lpBand->iRow,
1783 lpBand->rcBand.left, lpBand->rcBand.top,
1784 lpBand->rcBand.right, lpBand->rcBand.bottom);
1785 if (diff <= 0) break;
1786 }
1787 if (diff < 0) {
1788 ERR("P2b allocated more than available, diff=%d\n", diff);
1789 diff = 0;
1790 }
1791 if (infoPtr->dwStyle & CCS_VERT)
1792 x = clientcx - diff;
1793 else
1794 y = clientcy - diff;
1795 }
1796
1797 /* ******* End Phase 2b - adjust all bands for height full ******* */
1798
1799
1800 /* ******* Start Phase 3 - adjust all bands for width full ******* */
1801
1802 if (infoPtr->uNumBands) {
1803 REBAR_ROW *p;
1804
1805 /* If RBS_BANDBORDERS set then indicate to draw bottom separator */
1806 /* on all bands in all rows but last row. */
1807 /* Also indicate to draw the right separator for each band in */
1808 /* each row but the rightmost band. */
1809 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1810
1811 for(i = 0; i < infoPtr->uNumRows; i++) {
1812 p = &infoPtr->rows[i];
1813 for (j = p->istartband; j <= p->iendband; j++) {
1814 lpBand = &infoPtr->bands[j];
1815 if (HIDDENBAND(lpBand)) continue;
1816 if (j != p->iendband)
1817 lpBand->fDraw |= DRAW_RIGHTSEP;
1818 if (i != infoPtr->uNumRows-1)
1819 lpBand->fDraw |= DRAW_BOTTOMSEP;
1820 }
1821 }
1822 }
1823
1824 /* Distribute the extra space on the horizontal and adjust */
1825 /* all bands in row to same height. */
1826 for (i=1; i<=infoPtr->uNumRows; i++) {
1827 p = &infoPtr->rows[i-1];
1828 mcy = 0;
1829
1830 TRACE("P3 processing row %d, starting band %d, ending band %d\n",
1831 i, p->istartband, p->iendband);
1832
1833 /* Find the largest height of the bands in the row */
1834 for (j = p->istartband; j <= p->iendband; j++) {
1835 lpBand = &infoPtr->bands[j];
1836 if (HIDDENBAND(lpBand)) continue;
1837 if (mcy < ircBw(lpBand))
1838 mcy = ircBw(lpBand);
1839 }
1840
1841 REBAR_AdjustBands (infoPtr, p->istartband, p->iendband,
1842 (infoPtr->dwStyle & CCS_VERT) ?
1843 clientcy : clientcx, mcy);
1844 }
1845
1846 /* Calculate the other rectangles in each band */
1847 if (infoPtr->dwStyle & CCS_VERT) {
1848 REBAR_CalcVertBand (infoPtr, 0, infoPtr->uNumBands,
1849 notify);
1850 }
1851 else {
1852 REBAR_CalcHorzBand (infoPtr, 0, infoPtr->uNumBands,
1853 notify);
1854 }
1855 }
1856
1857 /* ******* End Phase 3 - adjust all bands for width full ******* */
1858
1859 /* now compute size of Rebar itself */
1860 infoPtr->oldSize = infoPtr->calcSize;
1861 if (infoPtr->uNumBands == 0) {
1862 /* we have no bands, so make size the size of client */
1863 x = clientcx;
1864 y = clientcy;
1865 }
1866 if (infoPtr->dwStyle & CCS_VERT) {
1867 infoPtr->calcSize.cx = x;
1868 infoPtr->calcSize.cy = clientcy;
1869 TRACE("vert, notify=%d, x=%d, origheight=%d\n",
1870 notify, x, origheight);
1871 if (notify && (x != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1872 }
1873 else {
1874 infoPtr->calcSize.cx = clientcx;
1875 infoPtr->calcSize.cy = y;
1876 TRACE("horz, notify=%d, y=%d, origheight=%d\n",
1877 notify, y, origheight);
1878 if (notify && (y != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1879 }
1880
1881 REBAR_DumpBand (infoPtr);
1882
1883 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1884
1885 REBAR_ForceResize (infoPtr);
1886}
1887
1888
1889static VOID
1890REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1891 /* Function: This routine evaluates the band specs supplied */
1892 /* by the user and updates the following 5 fields in */
1893 /* the internal band structure: cxHeader, lcx, lcy, hcx, hcy*/
1894{
1895 UINT header=0;
1896 UINT textheight=0;
1897 INT i, nonfixed;
1898 REBAR_BAND *tBand;
1899
1900 lpBand->fStatus = 0;
1901 lpBand->lcx = 0;
1902 lpBand->lcy = 0;
1903 lpBand->ccx = 0;
1904 lpBand->ccy = 0;
1905 lpBand->hcx = 0;
1906 lpBand->hcy = 0;
1907
1908 /* Data comming in from users into the cx... and cy... fields */
1909 /* may be bad, just garbage, because the user never clears */
1910 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1911 /* along if the fields exist in the input area. Here we must */
1912 /* determine if the data is valid. I have no idea how MS does */
1913 /* the validation, but it does because the RB_GETBANDINFO */
1914 /* returns a 0 when I know the sample program passed in an */
1915 /* address. Here I will use the algorithim that if the value */
1916 /* is greater than 65535 then it is bad and replace it with */
1917 /* a zero. Feel free to improve the algorithim. - GA 12/2000 */
1918 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1919 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1920 if (lpBand->cx > 65535) lpBand->cx = 0;
1921 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1922 if (lpBand->cyMaxChild > 65535) lpBand->cyMaxChild = 0;
1923 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1924 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1925 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1926
1927 /* FIXME: probably should only set NEEDS_LAYOUT flag when */
1928 /* values change. Till then always set it. */
1929 TRACE("setting NEEDS_LAYOUT\n");
1930 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1931
1932 /* Header is where the image, text and gripper exist */
1933 /* in the band and preceed the child window. */
1934
1935 /* count number of non-FIXEDSIZE and non-Hidden bands */
1936 nonfixed = 0;
1937 for (i=0; i<infoPtr->uNumBands; i++){
1938 tBand = &infoPtr->bands[i];
1939 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1940 nonfixed++;
1941 }
1942
1943 /* calculate gripper rectangle */
1944 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1945 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1946 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1947 ) {
1948 lpBand->fStatus |= HAS_GRIPPER;
1949 if (infoPtr->dwStyle & CCS_VERT)
1950 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1951 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1952 else
1953 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1954 else
1955 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1956 /* Always have 4 pixels before anything else */
1957 header += REBAR_ALWAYS_SPACE;
1958 }
1959
1960 /* image is visible */
1961 if ((lpBand->fMask & RBBIM_IMAGE) && (infoPtr->himl)) {
1962 lpBand->fStatus |= HAS_IMAGE;
1963 if (infoPtr->dwStyle & CCS_VERT) {
1964 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1965 lpBand->lcy = infoPtr->imageSize.cx + 2;
1966 }
1967 else {
1968 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1969 lpBand->lcy = infoPtr->imageSize.cy + 2;
1970 }
1971 }
1972
1973 /* text is visible */
1974 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText)) {
1975 HDC hdc = GetDC (0);
1976 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1977 SIZE size;
1978
1979 lpBand->fStatus |= HAS_TEXT;
1980 GetTextExtentPoint32W (hdc, lpBand->lpText,
1981 lstrlenW (lpBand->lpText), &size);
1982 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1983 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1984
1985 SelectObject (hdc, hOldFont);
1986 ReleaseDC (0, hdc);
1987 }
1988
1989 /* if no gripper but either image or text, then leave space */
1990 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1991 !(lpBand->fStatus & HAS_GRIPPER)) {
1992 header += REBAR_ALWAYS_SPACE;
1993 }
1994
1995 /* check if user overrode the header value */
1996 if (!(lpBand->fMask & RBBIM_HEADERSIZE))
1997 lpBand->cxHeader = header;
1998
1999
2000 /* Now compute minimum size of child window */
2001 lpBand->offChild.cx = 0;
2002 lpBand->offChild.cy = 0;
2003 lpBand->lcy = textheight;
2004 lpBand->ccy = lpBand->lcy;
2005 if (lpBand->fMask & RBBIM_CHILDSIZE) {
2006 lpBand->lcx = lpBand->cxMinChild;
2007
2008 /* Set the .cy values for CHILDSIZE case */
2009 lpBand->lcy = max(lpBand->lcy, lpBand->cyMinChild);
2010 lpBand->ccy = lpBand->lcy;
2011 lpBand->hcy = lpBand->lcy;
2012 if (lpBand->cyMaxChild != 0xffffffff) {
2013 lpBand->hcy = lpBand->cyMaxChild;
2014 }
2015 if (lpBand->cyChild != 0xffffffff)
2016 lpBand->ccy = max (lpBand->cyChild, lpBand->lcy);
2017
2018 TRACE("_CHILDSIZE\n");
2019 }
2020 if (lpBand->fMask & RBBIM_SIZE) {
2021 lpBand->hcx = max (lpBand->cx-lpBand->cxHeader, lpBand->lcx);
2022 TRACE("_SIZE\n");
2023 }
2024 else
2025 lpBand->hcx = lpBand->lcx;
2026 lpBand->ccx = lpBand->hcx;
2027
2028 /* make ->.cx include header size for _Layout */
2029 lpBand->lcx += lpBand->cxHeader;
2030 lpBand->ccx += lpBand->cxHeader;
2031 lpBand->hcx += lpBand->cxHeader;
2032
2033}
2034
2035static void
2036REBAR_CommonSetupBand (HWND hwnd, LPREBARBANDINFOA lprbbi, REBAR_BAND *lpBand)
2037 /* Function: This routine copies the supplied values from */
2038 /* user input (lprbbi) to the internal band structure. */
2039{
2040 lpBand->fMask |= lprbbi->fMask;
2041
2042 if (lprbbi->fMask & RBBIM_STYLE)
2043 lpBand->fStyle = lprbbi->fStyle;
2044
2045 if (lprbbi->fMask & RBBIM_COLORS) {
2046 lpBand->clrFore = lprbbi->clrFore;
2047 lpBand->clrBack = lprbbi->clrBack;
2048 }
2049
2050 if (lprbbi->fMask & RBBIM_IMAGE)
2051 lpBand->iImage = lprbbi->iImage;
2052
2053 if (lprbbi->fMask & RBBIM_CHILD) {
2054 if (lprbbi->hwndChild) {
2055 lpBand->hwndChild = lprbbi->hwndChild;
2056 lpBand->hwndPrevParent =
2057 SetParent (lpBand->hwndChild, hwnd);
2058 /* below in trace fro WinRAR */
2059 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
2060 /* above in trace fro WinRAR */
2061 }
2062 else {
2063 TRACE("child: %p prev parent: %p\n",
2064 lpBand->hwndChild, lpBand->hwndPrevParent);
2065 lpBand->hwndChild = 0;
2066 lpBand->hwndPrevParent = 0;
2067 }
2068 }
2069
2070 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2071 lpBand->cxMinChild = lprbbi->cxMinChild;
2072 lpBand->cyMinChild = lprbbi->cyMinChild;
2073 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2074 lpBand->cyChild = lprbbi->cyChild;
2075 lpBand->cyMaxChild = lprbbi->cyMaxChild;
2076 lpBand->cyIntegral = lprbbi->cyIntegral;
2077 }
2078 else { /* special case - these should be zeroed out since */
2079 /* RBBIM_CHILDSIZE added these in WIN32_IE >= 0x0400 */
2080 lpBand->cyChild = 0;
2081 lpBand->cyMaxChild = 0;
2082 lpBand->cyIntegral = 0;
2083 }
2084 }
2085
2086 if (lprbbi->fMask & RBBIM_SIZE)
2087 lpBand->cx = lprbbi->cx;
2088
2089 if (lprbbi->fMask & RBBIM_BACKGROUND)
2090 lpBand->hbmBack = lprbbi->hbmBack;
2091
2092 if (lprbbi->fMask & RBBIM_ID)
2093 lpBand->wID = lprbbi->wID;
2094
2095 /* check for additional data */
2096 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2097 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2098 lpBand->cxIdeal = lprbbi->cxIdeal;
2099
2100 if (lprbbi->fMask & RBBIM_LPARAM)
2101 lpBand->lParam = lprbbi->lParam;
2102
2103 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2104 lpBand->cxHeader = lprbbi->cxHeader;
2105 }
2106}
2107
2108static LRESULT
2109REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, RECT *clip)
2110 /* Function: This erases the background rectangle by drawing */
2111 /* each band with its background color (or the default) and */
2112 /* draws each bands right separator if necessary. The row */
2113 /* separators are drawn on the first band of the next row. */
2114{
2115 REBAR_BAND *lpBand;
2116 INT i, oldrow;
2117 HDC hdc = (HDC)wParam;
2118 RECT rect;
2119 COLORREF old = CLR_NONE, new;
2120
2121 oldrow = -1;
2122 for(i=0; i<infoPtr->uNumBands; i++) {
2123 lpBand = &infoPtr->bands[i];
2124 if (HIDDENBAND(lpBand)) continue;
2125
2126 /* draw band separator between rows */
2127 if (lpBand->iRow != oldrow) {
2128 oldrow = lpBand->iRow;
2129 if (lpBand->fDraw & DRAW_BOTTOMSEP) {
2130 RECT rcRowSep;
2131 rcRowSep = lpBand->rcBand;
2132 if (infoPtr->dwStyle & CCS_VERT) {
2133 rcRowSep.right += SEP_WIDTH_SIZE;
2134 rcRowSep.bottom = infoPtr->calcSize.cy;
2135 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
2136 }
2137 else {
2138 rcRowSep.bottom += SEP_WIDTH_SIZE;
2139 rcRowSep.right = infoPtr->calcSize.cx;
2140 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
2141 }
2142 TRACE ("drawing band separator bottom (%d,%d)-(%d,%d)\n",
2143 rcRowSep.left, rcRowSep.top,
2144 rcRowSep.right, rcRowSep.bottom);
2145 }
2146 }
2147
2148 /* draw band separator between bands in a row */
2149 if (lpBand->fDraw & DRAW_RIGHTSEP) {
2150 RECT rcSep;
2151 rcSep = lpBand->rcBand;
2152 if (infoPtr->dwStyle & CCS_VERT) {
2153 rcSep.bottom += SEP_WIDTH_SIZE;
2154 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
2155 }
2156 else {
2157 rcSep.right += SEP_WIDTH_SIZE;
2158 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
2159 }
2160 TRACE("drawing band separator right (%d,%d)-(%d,%d)\n",
2161 rcSep.left, rcSep.top, rcSep.right, rcSep.bottom);
2162 }
2163
2164 /* draw the actual background */
2165 if (lpBand->clrBack != CLR_NONE) {
2166 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
2167 lpBand->clrBack;
2168#if GLATESTING
2169 /* testing only - make background green to see it */
2170 new = RGB(0,128,0);
2171#endif
2172 }
2173 else {
2174 /* In the absence of documentation for Rebar vs. CLR_NONE,
2175 * we will use the default BtnFace color. Note documentation
2176 * exists for Listview and Imagelist.
2177 */
2178 new = infoPtr->clrBtnFace;
2179#if GLATESTING
2180 /* testing only - make background green to see it */
2181 new = RGB(0,128,0);
2182#endif
2183 }
2184 old = SetBkColor (hdc, new);
2185
2186 rect = lpBand->rcBand;
2187 TRACE("%s background color=0x%06lx, band (%d,%d)-(%d,%d), clip (%d,%d)-(%d,%d)\n",
2188 (lpBand->clrBack == CLR_NONE) ? "none" :
2189 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
2190 GetBkColor(hdc),
2191 lpBand->rcBand.left,lpBand->rcBand.top,
2192 lpBand->rcBand.right,lpBand->rcBand.bottom,
2193 clip->left, clip->top,
2194 clip->right, clip->bottom);
2195 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, 0);
2196 if (lpBand->clrBack != CLR_NONE)
2197 SetBkColor (hdc, old);
2198 }
2199 return TRUE;
2200}
2201
2202static void
2203REBAR_InternalHitTest (REBAR_INFO *infoPtr, LPPOINT lpPt, UINT *pFlags, INT *pBand)
2204{
2205 REBAR_BAND *lpBand;
2206 RECT rect;
2207 INT iCount;
2208
2209 GetClientRect (infoPtr->hwndSelf, &rect);
2210
2211 *pFlags = RBHT_NOWHERE;
2212 if (PtInRect (&rect, *lpPt))
2213 {
2214 if (infoPtr->uNumBands == 0) {
2215 *pFlags = RBHT_NOWHERE;
2216 if (pBand)
2217 *pBand = -1;
2218 TRACE("NOWHERE\n");
2219 return;
2220 }
2221 else {
2222 /* somewhere inside */
2223 infoPtr->ihitBand = -1;
2224 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
2225 lpBand = &infoPtr->bands[iCount];
2226 if (HIDDENBAND(lpBand)) continue;
2227 if (PtInRect (&lpBand->rcBand, *lpPt)) {
2228 if (pBand)
2229 *pBand = iCount;
2230 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
2231 *pFlags = RBHT_GRABBER;
2232 infoPtr->ihitBand = iCount;
2233 TRACE("ON GRABBER %d\n", iCount);
2234 return;
2235 }
2236 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
2237 *pFlags = RBHT_CAPTION;
2238 TRACE("ON CAPTION %d\n", iCount);
2239 return;
2240 }
2241 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2242 *pFlags = RBHT_CAPTION;
2243 TRACE("ON CAPTION %d\n", iCount);
2244 return;
2245 }
2246 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2247 *pFlags = RBHT_CLIENT;
2248 TRACE("ON CLIENT %d\n", iCount);
2249 return;
2250 }
2251 else {
2252 *pFlags = RBHT_NOWHERE;
2253 TRACE("NOWHERE %d\n", iCount);
2254 return;
2255 }
2256 }
2257 }
2258
2259 *pFlags = RBHT_NOWHERE;
2260 if (pBand)
2261 *pBand = -1;
2262
2263 TRACE("NOWHERE\n");
2264 return;
2265 }
2266 }
2267 else {
2268 *pFlags = RBHT_NOWHERE;
2269 if (pBand)
2270 *pBand = -1;
2271 TRACE("NOWHERE\n");
2272 return;
2273 }
2274
2275 TRACE("flags=0x%X\n", *pFlags);
2276 return;
2277}
2278
2279
2280static INT
2281REBAR_Shrink (REBAR_INFO *infoPtr, REBAR_BAND *band, INT movement, INT i)
2282 /* Function: This attempts to shrink the given band by the */
2283 /* the amount in "movement". A shrink to the left is indi- */
2284 /* cated by "movement" being negative. "i" is merely the */
2285 /* band index for trace messages. */
2286{
2287 INT Leadjust, Readjust, avail, ret;
2288
2289 /* Note: a left drag is indicated by "movement" being negative. */
2290 /* Similarly, a right drag is indicated by "movement" */
2291 /* being positive. "movement" should never be 0, but if */
2292 /* it is then the band does not move. */
2293
2294 avail = rcBw(band) - band->lcx;
2295
2296 /* now compute the Left End adjustment factor and Right End */
2297 /* adjustment factor. They may be different if shrinking. */
2298 if (avail <= 0) {
2299 /* if this band is not shrinkable, then just move it */
2300 Leadjust = Readjust = movement;
2301 ret = movement;
2302 }
2303 else {
2304 if (movement < 0) {
2305 /* Drag to left */
2306 if (avail <= abs(movement)) {
2307 Readjust = movement;
2308 Leadjust = movement + avail;
2309 ret = Leadjust;
2310 }
2311 else {
2312 Readjust = movement;
2313 Leadjust = 0;
2314 ret = 0;
2315 }
2316 }
2317 else {
2318 /* Drag to right */
2319 if (avail <= abs(movement)) {
2320 Leadjust = movement;
2321 Readjust = movement - avail;
2322 ret = Readjust;
2323 }
2324 else {
2325 Leadjust = movement;
2326 Readjust = 0;
2327 ret = 0;
2328 }
2329 }
2330 }
2331
2332 /* Reasonability Check */
2333 if (rcBlt(band) + Leadjust < 0) {
2334 ERR("adjustment will fail, band %d: left=%d, right=%d, move=%d, rtn=%d\n",
2335 i, Leadjust, Readjust, movement, ret);
2336 }
2337
2338 LEADJ(band, Leadjust);
2339 READJ(band, Readjust);
2340
2341 TRACE("band %d: left=%d, right=%d, move=%d, rtn=%d, rcBand=(%d,%d)-(%d,%d)\n",
2342 i, Leadjust, Readjust, movement, ret,
2343 band->rcBand.left, band->rcBand.top,
2344 band->rcBand.right, band->rcBand.bottom);
2345 return ret;
2346}
2347
2348
2349static void
2350REBAR_HandleLRDrag (REBAR_INFO *infoPtr, POINTS *ptsmove)
2351 /* Function: This will implement the functionality of a */
2352 /* Gripper drag within a row. It will not implement "out- */
2353 /* of-row" drags. (They are detected and handled in */
2354 /* REBAR_MouseMove.) */
2355 /* **** FIXME Switching order of bands in a row not **** */
2356 /* **** yet implemented. **** */
2357{
2358 REBAR_BAND *hitBand, *band, *mindBand, *maxdBand;
2359 RECT newrect;
2360 INT imindBand = -1, imaxdBand, ihitBand, i, movement;
2361 INT RHeaderSum = 0, LHeaderSum = 0;
2362 INT compress;
2363
2364 /* on first significant mouse movement, issue notify */
2365
2366 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
2367 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
2368 /* Notify returned TRUE - abort drag */
2369 infoPtr->dragStart.x = 0;
2370 infoPtr->dragStart.y = 0;
2371 infoPtr->dragNow = infoPtr->dragStart;
2372 infoPtr->ihitBand = -1;
2373 ReleaseCapture ();
2374 return ;
2375 }
2376 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
2377 }
2378
2379 ihitBand = infoPtr->ihitBand;
2380 hitBand = &infoPtr->bands[ihitBand];
2381 imaxdBand = ihitBand; /* to suppress warning message */
2382
2383 /* find all the bands in the row of the one whose Gripper was seized */
2384 for (i=0; i<infoPtr->uNumBands; i++) {
2385 band = &infoPtr->bands[i];
2386 if (HIDDENBAND(band)) continue;
2387 if (band->iRow == hitBand->iRow) {
2388 imaxdBand = i;
2389 if (imindBand == -1) imindBand = i;
2390 /* minimum size of each band is size of header plus */
2391 /* size of minimum child plus offset of child from header plus */
2392 /* a one to separate each band. */
2393 if (i < ihitBand)
2394 LHeaderSum += (band->lcx + SEP_WIDTH);
2395 else
2396 RHeaderSum += (band->lcx + SEP_WIDTH);
2397
2398 }
2399 }
2400 if (RHeaderSum) RHeaderSum -= SEP_WIDTH; /* no separator afterlast band */
2401
2402 mindBand = &infoPtr->bands[imindBand];
2403 maxdBand = &infoPtr->bands[imaxdBand];
2404
2405 if (imindBand == imaxdBand) return; /* nothing to drag agains */
2406 if (imindBand == ihitBand) return; /* first band in row, cant drag */
2407
2408 /* limit movement to inside adjustable bands - Left */
2409 if ( (ptsmove->x < mindBand->rcBand.left) ||
2410 (ptsmove->x > maxdBand->rcBand.right) ||
2411 (ptsmove->y < mindBand->rcBand.top) ||
2412 (ptsmove->y > maxdBand->rcBand.bottom))
2413 return; /* should swap bands */
2414
2415 if (infoPtr->dwStyle & CCS_VERT)
2416 movement = ptsmove->y - ((hitBand->rcBand.top+REBAR_PRE_GRIPPER) -
2417 infoPtr->ihitoffset);
2418 else
2419 movement = ptsmove->x - ((hitBand->rcBand.left+REBAR_PRE_GRIPPER) -
2420 infoPtr->ihitoffset);
2421 infoPtr->dragNow = *ptsmove;
2422
2423 TRACE("before: movement=%d (%d,%d), imindBand=%d, ihitBand=%d, imaxdBand=%d, LSum=%d, RSum=%d\n",
2424 movement, ptsmove->x, ptsmove->y, imindBand, ihitBand,
2425 imaxdBand, LHeaderSum, RHeaderSum);
2426 REBAR_DumpBand (infoPtr);
2427
2428 if (movement < 0) {
2429
2430 /* *** Drag left/up *** */
2431 compress = rcBlt(hitBand) - rcBlt(mindBand) -
2432 LHeaderSum;
2433 if (compress < abs(movement)) {
2434 TRACE("limiting left drag, was %d changed to %d\n",
2435 movement, -compress);
2436 movement = -compress;
2437 }
2438
2439 for (i=ihitBand; i>=imindBand; i--) {
2440 band = &infoPtr->bands[i];
2441 if (HIDDENBAND(band)) continue;
2442 if (i == ihitBand) {
2443 LEADJ(band, movement);
2444 }
2445 else
2446 movement = REBAR_Shrink (infoPtr, band, movement, i);
2447 band->ccx = rcBw(band);
2448 }
2449 }
2450 else {
2451 BOOL first = TRUE;
2452
2453 /* *** Drag right/down *** */
2454 compress = rcBrb(maxdBand) - rcBlt(hitBand) -
2455 RHeaderSum;
2456 if (compress < abs(movement)) {
2457 TRACE("limiting right drag, was %d changed to %d\n",
2458 movement, compress);
2459 movement = compress;
2460 }
2461 for (i=ihitBand-1; i<=imaxdBand; i++) {
2462 band = &infoPtr->bands[i];
2463 if (HIDDENBAND(band)) continue;
2464 if (first) {
2465 first = FALSE;
2466 READJ(band, movement);
2467 }
2468 else
2469 movement = REBAR_Shrink (infoPtr, band, movement, i);
2470 band->ccx = rcBw(band);
2471 }
2472 }
2473
2474 /* recompute all rectangles */
2475 if (infoPtr->dwStyle & CCS_VERT) {
2476 REBAR_CalcVertBand (infoPtr, imindBand, imaxdBand+1,
2477 FALSE);
2478 }
2479 else {
2480 REBAR_CalcHorzBand (infoPtr, imindBand, imaxdBand+1,
2481 FALSE);
2482 }
2483
2484 TRACE("bands after adjustment, see band # %d, %d\n",
2485 imindBand, imaxdBand);
2486 REBAR_DumpBand (infoPtr);
2487
2488 SetRect (&newrect,
2489 mindBand->rcBand.left,
2490 mindBand->rcBand.top,
2491 maxdBand->rcBand.right,
2492 maxdBand->rcBand.bottom);
2493
2494 REBAR_MoveChildWindows (infoPtr, imindBand, imaxdBand+1);
2495
2496 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
2497 UpdateWindow (infoPtr->hwndSelf);
2498
2499}
2500
2501
2502
2503/* << REBAR_BeginDrag >> */
2504
2505
2506static LRESULT
2507REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2508{
2509 UINT uBand = (UINT)wParam;
2510 HWND childhwnd = 0;
2511 REBAR_BAND *lpBand;
2512
2513 if (uBand >= infoPtr->uNumBands)
2514 return FALSE;
2515
2516 TRACE("deleting band %u!\n", uBand);
2517 lpBand = &infoPtr->bands[uBand];
2518 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2519
2520 if (infoPtr->uNumBands == 1) {
2521 TRACE(" simple delete!\n");
2522 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2523 childhwnd = lpBand->hwndChild;
2524 COMCTL32_Free (infoPtr->bands);
2525 infoPtr->bands = NULL;
2526 infoPtr->uNumBands = 0;
2527 }
2528 else {
2529 REBAR_BAND *oldBands = infoPtr->bands;
2530 TRACE("complex delete! [uBand=%u]\n", uBand);
2531
2532 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2533 childhwnd = lpBand->hwndChild;
2534
2535 infoPtr->uNumBands--;
2536 infoPtr->bands = COMCTL32_Alloc (sizeof (REBAR_BAND) * infoPtr->uNumBands);
2537 if (uBand > 0) {
2538 memcpy (&infoPtr->bands[0], &oldBands[0],
2539 uBand * sizeof(REBAR_BAND));
2540 }
2541
2542 if (uBand < infoPtr->uNumBands) {
2543 memcpy (&infoPtr->bands[uBand], &oldBands[uBand+1],
2544 (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
2545 }
2546
2547 COMCTL32_Free (oldBands);
2548 }
2549
2550 if (childhwnd)
2551 ShowWindow (childhwnd, SW_HIDE);
2552
2553 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2554
2555 /* if only 1 band left the re-validate to possible eliminate gripper */
2556 if (infoPtr->uNumBands == 1)
2557 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2558
2559 TRACE("setting NEEDS_LAYOUT\n");
2560 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
2561 infoPtr->fStatus |= RESIZE_ANYHOW;
2562 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
2563
2564 return TRUE;
2565}
2566
2567
2568/* << REBAR_DragMove >> */
2569/* << REBAR_EndDrag >> */
2570
2571
2572static LRESULT
2573REBAR_GetBandBorders (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2574{
2575 LPRECT lpRect = (LPRECT)lParam;
2576 REBAR_BAND *lpBand;
2577
2578 if (!lParam)
2579 return 0;
2580 if ((UINT)wParam >= infoPtr->uNumBands)
2581 return 0;
2582
2583 lpBand = &infoPtr->bands[(UINT)wParam];
2584
2585 /* FIXME - the following values were determined by experimentation */
2586 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2587 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2588 /* difference in size of the control area with and without the */
2589 /* style. - GA */
2590 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2591 if (infoPtr->dwStyle & CCS_VERT) {
2592 lpRect->left = 1;
2593 lpRect->top = lpBand->cxHeader + 4;
2594 lpRect->right = 1;
2595 lpRect->bottom = 0;
2596 }
2597 else {
2598 lpRect->left = lpBand->cxHeader + 4;
2599 lpRect->top = 1;
2600 lpRect->right = 0;
2601 lpRect->bottom = 1;
2602 }
2603 }
2604 else {
2605 lpRect->left = lpBand->cxHeader;
2606 }
2607 return 0;
2608}
2609
2610
2611inline static LRESULT
2612REBAR_GetBandCount (REBAR_INFO *infoPtr)
2613{
2614 TRACE("band count %u!\n", infoPtr->uNumBands);
2615
2616 return infoPtr->uNumBands;
2617}
2618
2619
2620static LRESULT
2621REBAR_GetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2622{
2623 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2624 REBAR_BAND *lpBand;
2625
2626 if (lprbbi == NULL)
2627 return FALSE;
2628 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
2629 return FALSE;
2630 if ((UINT)wParam >= infoPtr->uNumBands)
2631 return FALSE;
2632
2633 TRACE("index %u\n", (UINT)wParam);
2634
2635 /* copy band information */
2636 lpBand = &infoPtr->bands[(UINT)wParam];
2637
2638 if (lprbbi->fMask & RBBIM_STYLE)
2639 lprbbi->fStyle = lpBand->fStyle;
2640
2641 if (lprbbi->fMask & RBBIM_COLORS) {
2642 lprbbi->clrFore = lpBand->clrFore;
2643 lprbbi->clrBack = lpBand->clrBack;
2644 if (lprbbi->clrBack == CLR_DEFAULT)
2645 lprbbi->clrBack = infoPtr->clrBtnFace;
2646 }
2647
2648 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2649 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2650 {
2651 if (!WideCharToMultiByte( CP_ACP, 0, lpBand->lpText, -1,
2652 lprbbi->lpText, lprbbi->cch, NULL, NULL ))
2653 lprbbi->lpText[lprbbi->cch-1] = 0;
2654 }
2655 else
2656 *lprbbi->lpText = 0;
2657 }
2658
2659 if (lprbbi->fMask & RBBIM_IMAGE) {
2660 if (lpBand->fMask & RBBIM_IMAGE)
2661 lprbbi->iImage = lpBand->iImage;
2662 else
2663 lprbbi->iImage = -1;
2664 }
2665
2666 if (lprbbi->fMask & RBBIM_CHILD)
2667 lprbbi->hwndChild = lpBand->hwndChild;
2668
2669 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2670 lprbbi->cxMinChild = lpBand->cxMinChild;
2671 lprbbi->cyMinChild = lpBand->cyMinChild;
2672 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2673 lprbbi->cyChild = lpBand->cyChild;
2674 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2675 lprbbi->cyIntegral = lpBand->cyIntegral;
2676 }
2677 }
2678
2679 if (lprbbi->fMask & RBBIM_SIZE)
2680 lprbbi->cx = lpBand->cx;
2681
2682 if (lprbbi->fMask & RBBIM_BACKGROUND)
2683 lprbbi->hbmBack = lpBand->hbmBack;
2684
2685 if (lprbbi->fMask & RBBIM_ID)
2686 lprbbi->wID = lpBand->wID;
2687
2688 /* check for additional data */
2689 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2690 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2691 lprbbi->cxIdeal = lpBand->cxIdeal;
2692
2693 if (lprbbi->fMask & RBBIM_LPARAM)
2694 lprbbi->lParam = lpBand->lParam;
2695
2696 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2697 lprbbi->cxHeader = lpBand->cxHeader;
2698 }
2699
2700 REBAR_DumpBandInfo (lprbbi);
2701
2702 return TRUE;
2703}
2704
2705
2706static LRESULT
2707REBAR_GetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2708{
2709 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2710 REBAR_BAND *lpBand;
2711
2712 if (lprbbi == NULL)
2713 return FALSE;
2714 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
2715 return FALSE;
2716 if ((UINT)wParam >= infoPtr->uNumBands)
2717 return FALSE;
2718
2719 TRACE("index %u\n", (UINT)wParam);
2720
2721 /* copy band information */
2722 lpBand = &infoPtr->bands[(UINT)wParam];
2723
2724 if (lprbbi->fMask & RBBIM_STYLE)
2725 lprbbi->fStyle = lpBand->fStyle;
2726
2727 if (lprbbi->fMask & RBBIM_COLORS) {
2728 lprbbi->clrFore = lpBand->clrFore;
2729 lprbbi->clrBack = lpBand->clrBack;
2730 if (lprbbi->clrBack == CLR_DEFAULT)
2731 lprbbi->clrBack = infoPtr->clrBtnFace;
2732 }
2733
2734 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2735 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2736 lstrcpynW (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
2737 else
2738 *lprbbi->lpText = 0;
2739 }
2740
2741 if (lprbbi->fMask & RBBIM_IMAGE) {
2742 if (lpBand->fMask & RBBIM_IMAGE)
2743 lprbbi->iImage = lpBand->iImage;
2744 else
2745 lprbbi->iImage = -1;
2746 }
2747
2748 if (lprbbi->fMask & RBBIM_CHILD)
2749 lprbbi->hwndChild = lpBand->hwndChild;
2750
2751 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2752 lprbbi->cxMinChild = lpBand->cxMinChild;
2753 lprbbi->cyMinChild = lpBand->cyMinChild;
2754 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2755 lprbbi->cyChild = lpBand->cyChild;
2756 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2757 lprbbi->cyIntegral = lpBand->cyIntegral;
2758 }
2759 }
2760
2761 if (lprbbi->fMask & RBBIM_SIZE)
2762 lprbbi->cx = lpBand->cx;
2763
2764 if (lprbbi->fMask & RBBIM_BACKGROUND)
2765 lprbbi->hbmBack = lpBand->hbmBack;
2766
2767 if (lprbbi->fMask & RBBIM_ID)
2768 lprbbi->wID = lpBand->wID;
2769
2770 /* check for additional data */
2771 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2772 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2773 lprbbi->cxIdeal = lpBand->cxIdeal;
2774
2775 if (lprbbi->fMask & RBBIM_LPARAM)
2776 lprbbi->lParam = lpBand->lParam;
2777
2778 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2779 lprbbi->cxHeader = lpBand->cxHeader;
2780 }
2781
2782 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
2783
2784 return TRUE;
2785}
2786
2787
2788static LRESULT
2789REBAR_GetBarHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2790{
2791 INT nHeight;
2792
2793 nHeight = (infoPtr->dwStyle & CCS_VERT) ? infoPtr->calcSize.cx : infoPtr->calcSize.cy;
2794
2795 TRACE("height = %d\n", nHeight);
2796
2797 return nHeight;
2798}
2799
2800
2801static LRESULT
2802REBAR_GetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2803{
2804 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
2805
2806 if (lpInfo == NULL)
2807 return FALSE;
2808
2809 if (lpInfo->cbSize < sizeof (REBARINFO))
2810 return FALSE;
2811
2812 TRACE("getting bar info!\n");
2813
2814 if (infoPtr->himl) {
2815 lpInfo->himl = infoPtr->himl;
2816 lpInfo->fMask |= RBIM_IMAGELIST;
2817 }
2818
2819 return TRUE;
2820}
2821
2822
2823inline static LRESULT
2824REBAR_GetBkColor (REBAR_INFO *infoPtr)
2825{
2826 COLORREF clr = infoPtr->clrBk;
2827
2828 if (clr == CLR_DEFAULT)
2829 clr = infoPtr->clrBtnFace;
2830
2831 TRACE("background color 0x%06lx!\n", clr);
2832
2833 return clr;
2834}
2835
2836
2837/* << REBAR_GetColorScheme >> */
2838/* << REBAR_GetDropTarget >> */
2839
2840
2841static LRESULT
2842REBAR_GetPalette (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2843{
2844 FIXME("empty stub!\n");
2845
2846 return 0;
2847}
2848
2849
2850static LRESULT
2851REBAR_GetRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2852{
2853 INT iBand = (INT)wParam;
2854 LPRECT lprc = (LPRECT)lParam;
2855 REBAR_BAND *lpBand;
2856
2857 if ((iBand < 0) && ((UINT)iBand >= infoPtr->uNumBands))
2858 return FALSE;
2859 if (!lprc)
2860 return FALSE;
2861
2862 lpBand = &infoPtr->bands[iBand];
2863 CopyRect (lprc, &lpBand->rcBand);
2864
2865 TRACE("band %d, (%d,%d)-(%d,%d)\n", iBand,
2866 lprc->left, lprc->top, lprc->right, lprc->bottom);
2867
2868 return TRUE;
2869}
2870
2871
2872inline static LRESULT
2873REBAR_GetRowCount (REBAR_INFO *infoPtr)
2874{
2875 TRACE("%u\n", infoPtr->uNumRows);
2876
2877 return infoPtr->uNumRows;
2878}
2879
2880
2881static LRESULT
2882REBAR_GetRowHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2883{
2884 INT iRow = (INT)wParam;
2885 int ret = 0;
2886 int i, j = 0;
2887 REBAR_BAND *lpBand;
2888
2889 for (i=0; i<infoPtr->uNumBands; i++) {
2890 lpBand = &infoPtr->bands[i];
2891 if (HIDDENBAND(lpBand)) continue;
2892 if (lpBand->iRow != iRow) continue;
2893 if (infoPtr->dwStyle & CCS_VERT)
2894 j = lpBand->rcBand.right - lpBand->rcBand.left;
2895 else
2896 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2897 if (j > ret) ret = j;
2898 }
2899
2900 TRACE("row %d, height %d\n", iRow, ret);
2901
2902 return ret;
2903}
2904
2905
2906inline static LRESULT
2907REBAR_GetTextColor (REBAR_INFO *infoPtr)
2908{
2909 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
2910
2911 return infoPtr->clrText;
2912}
2913
2914
2915inline static LRESULT
2916REBAR_GetToolTips (REBAR_INFO *infoPtr)
2917{
2918 return (LRESULT)infoPtr->hwndToolTip;
2919}
2920
2921
2922inline static LRESULT
2923REBAR_GetUnicodeFormat (REBAR_INFO *infoPtr)
2924{
2925 TRACE("%s hwnd=%p\n",
2926 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2927
2928 return infoPtr->bUnicode;
2929}
2930
2931
2932inline static LRESULT
2933REBAR_GetVersion (REBAR_INFO *infoPtr)
2934{
2935 TRACE("version %d\n", infoPtr->iVersion);
2936 return infoPtr->iVersion;
2937}
2938
2939
2940static LRESULT
2941REBAR_HitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2942{
2943 LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
2944
2945 if (!lprbht)
2946 return -1;
2947
2948 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2949
2950 return lprbht->iBand;
2951}
2952
2953
2954static LRESULT
2955REBAR_IdToIndex (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2956{
2957 UINT i;
2958
2959 if (infoPtr == NULL)
2960 return -1;
2961
2962 if (infoPtr->uNumBands < 1)
2963 return -1;
2964
2965 for (i = 0; i < infoPtr->uNumBands; i++) {
2966 if (infoPtr->bands[i].wID == (UINT)wParam) {
2967 TRACE("id %u is band %u found!\n", (UINT)wParam, i);
2968 return i;
2969 }
2970 }
2971
2972 TRACE("id %u is not found\n", (UINT)wParam);
2973 return -1;
2974}
2975
2976
2977static LRESULT
2978REBAR_InsertBandA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2979{
2980 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2981 UINT uIndex = (UINT)wParam;
2982 REBAR_BAND *lpBand;
2983
2984 if (infoPtr == NULL)
2985 return FALSE;
2986 if (lprbbi == NULL)
2987 return FALSE;
2988 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
2989 return FALSE;
2990
2991 /* trace the index as signed to see the -1 */
2992 TRACE("insert band at %d!\n", (INT)uIndex);
2993 REBAR_DumpBandInfo (lprbbi);
2994
2995 if (infoPtr->uNumBands == 0) {
2996 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
2997 uIndex = 0;
2998 }
2999 else {
3000 REBAR_BAND *oldBands = infoPtr->bands;
3001 infoPtr->bands =
3002 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3003 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3004 uIndex = infoPtr->uNumBands;
3005
3006 /* pre insert copy */
3007 if (uIndex > 0) {
3008 memcpy (&infoPtr->bands[0], &oldBands[0],
3009 uIndex * sizeof(REBAR_BAND));
3010 }
3011
3012 /* post copy */
3013 if (uIndex < infoPtr->uNumBands - 1) {
3014 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3015 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
3016 }
3017
3018 COMCTL32_Free (oldBands);
3019 }
3020
3021 infoPtr->uNumBands++;
3022
3023 TRACE("index %u!\n", uIndex);
3024
3025 /* initialize band (infoPtr->bands[uIndex])*/
3026 lpBand = &infoPtr->bands[uIndex];
3027 lpBand->fMask = 0;
3028 lpBand->fStatus = 0;
3029 lpBand->clrFore = infoPtr->clrText;
3030 lpBand->clrBack = infoPtr->clrBk;
3031 lpBand->hwndChild = 0;
3032 lpBand->hwndPrevParent = 0;
3033
3034 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3035 lpBand->lpText = NULL;
3036 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3037 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3038 if (len > 1) {
3039 lpBand->lpText = (LPWSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
3040 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3041 }
3042 }
3043
3044 REBAR_ValidateBand (infoPtr, lpBand);
3045 /* On insert of second band, revalidate band 1 to possible add gripper */
3046 if (infoPtr->uNumBands == 2)
3047 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3048
3049 REBAR_DumpBand (infoPtr);
3050
3051 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3052 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3053
3054 return TRUE;
3055}
3056
3057
3058static LRESULT
3059REBAR_InsertBandW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3060{
3061 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3062 UINT uIndex = (UINT)wParam;
3063 REBAR_BAND *lpBand;
3064
3065 if (infoPtr == NULL)
3066 return FALSE;
3067 if (lprbbi == NULL)
3068 return FALSE;
3069 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
3070 return FALSE;
3071
3072 /* trace the index as signed to see the -1 */
3073 TRACE("insert band at %d!\n", (INT)uIndex);
3074 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3075
3076 if (infoPtr->uNumBands == 0) {
3077 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
3078 uIndex = 0;
3079 }
3080 else {
3081 REBAR_BAND *oldBands = infoPtr->bands;
3082 infoPtr->bands =
3083 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3084 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3085 uIndex = infoPtr->uNumBands;
3086
3087 /* pre insert copy */
3088 if (uIndex > 0) {
3089 memcpy (&infoPtr->bands[0], &oldBands[0],
3090 uIndex * sizeof(REBAR_BAND));
3091 }
3092
3093 /* post copy */
3094 if (uIndex < infoPtr->uNumBands - 1) {
3095 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3096 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
3097 }
3098
3099 COMCTL32_Free (oldBands);
3100 }
3101
3102 infoPtr->uNumBands++;
3103
3104 TRACE("index %u!\n", uIndex);
3105
3106 /* initialize band (infoPtr->bands[uIndex])*/
3107 lpBand = &infoPtr->bands[uIndex];
3108 lpBand->fMask = 0;
3109 lpBand->fStatus = 0;
3110 lpBand->clrFore = infoPtr->clrText;
3111 lpBand->clrBack = infoPtr->clrBk;
3112 lpBand->hwndChild = 0;
3113 lpBand->hwndPrevParent = 0;
3114
3115 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3116 lpBand->lpText = NULL;
3117 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3118 INT len = lstrlenW (lprbbi->lpText);
3119 if (len > 0) {
3120 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
3121 strcpyW (lpBand->lpText, lprbbi->lpText);
3122 }
3123 }
3124
3125 REBAR_ValidateBand (infoPtr, lpBand);
3126 /* On insert of second band, revalidate band 1 to possible add gripper */
3127 if (infoPtr->uNumBands == 2)
3128 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3129
3130 REBAR_DumpBand (infoPtr);
3131
3132 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3133 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3134
3135 return TRUE;
3136}
3137
3138
3139static LRESULT
3140REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3141{
3142 REBAR_BAND *lpBand;
3143 UINT uBand = (UINT) wParam;
3144
3145 /* Validate */
3146 if ((infoPtr->uNumBands == 0) ||
3147 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3148 /* error !!! */
3149 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
3150 (INT)uBand, infoPtr->uNumBands);
3151 return FALSE;
3152 }
3153
3154 lpBand = &infoPtr->bands[uBand];
3155
3156 if (lParam && (lpBand->fMask & RBBIM_IDEALSIZE)) {
3157 /* handle setting ideal size */
3158 lpBand->ccx = lpBand->cxIdeal;
3159 }
3160 else {
3161 /* handle setting to max */
3162 FIXME("(uBand = %u fIdeal = %s) case not coded\n",
3163 (UINT)wParam, lParam ? "TRUE" : "FALSE");
3164 return FALSE;
3165 }
3166
3167 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3168 REBAR_Layout (infoPtr, 0, TRUE, TRUE);
3169 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
3170
3171 return TRUE;
3172
3173}
3174
3175
3176static LRESULT
3177REBAR_MinimizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3178{
3179 REBAR_BAND *band, *lpBand;
3180 UINT uBand = (UINT) wParam;
3181 RECT newrect;
3182 INT imindBand, imaxdBand, iprevBand, startBand, endBand;
3183 INT movement, i;
3184
3185 /* A "minimize" band is equivalent to "dragging" the gripper
3186 * of than band to the right till the band is only the size
3187 * of the cxHeader.
3188 */
3189
3190 /* Validate */
3191 if ((infoPtr->uNumBands == 0) ||
3192 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3193 /* error !!! */
3194 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
3195 (INT)uBand, infoPtr->uNumBands);
3196 return FALSE;
3197 }
3198
3199 /* compute amount of movement and validate */
3200 lpBand = &infoPtr->bands[uBand];
3201
3202 if (infoPtr->dwStyle & CCS_VERT)
3203 movement = lpBand->rcBand.bottom - lpBand->rcBand.top -
3204 lpBand->cxHeader;
3205 else
3206 movement = lpBand->rcBand.right - lpBand->rcBand.left -
3207 lpBand->cxHeader;
3208 if (movement < 0) {
3209 ERR("something is wrong, band=(%d,%d)-(%d,%d), cxheader=%d\n",
3210 lpBand->rcBand.left, lpBand->rcBand.top,
3211 lpBand->rcBand.right, lpBand->rcBand.bottom,
3212 lpBand->cxHeader);
3213 return FALSE;
3214 }
3215
3216 imindBand = -1;
3217 imaxdBand = -1;
3218 iprevBand = -1; /* to suppress warning message */
3219
3220 /* find the first band in row of the one whose is being minimized */
3221 for (i=0; i<infoPtr->uNumBands; i++) {
3222 band = &infoPtr->bands[i];
3223 if (HIDDENBAND(band)) continue;
3224 if (band->iRow == lpBand->iRow) {
3225 imaxdBand = i;
3226 if (imindBand == -1) imindBand = i;
3227 }
3228 }
3229
3230 /* if the selected band is first in row then need to expand */
3231 /* next visible band */
3232 if (imindBand == uBand) {
3233 band = NULL;
3234 movement = -movement;
3235 /* find the first visible band to the right of the selected band */
3236 for (i=uBand+1; i<=imaxdBand; i++) {
3237 band = &infoPtr->bands[i];
3238 if (!HIDDENBAND(band)) {
3239 iprevBand = i;
3240 LEADJ(band, movement);
3241 band->ccx = rcBw(band);
3242 break;
3243 }
3244 }
3245 /* what case is this */
3246 if (iprevBand == -1) {
3247 ERR("no previous visible band\n");
3248 return FALSE;
3249 }
3250 startBand = uBand;
3251 endBand = iprevBand;
3252 SetRect (&newrect,
3253 lpBand->rcBand.left,
3254 lpBand->rcBand.top,
3255 band->rcBand.right,
3256 band->rcBand.bottom);
3257 }
3258 /* otherwise expand previous visible band */
3259 else {
3260 band = NULL;
3261 /* find the first visible band to the left of the selected band */
3262 for (i=uBand-1; i>=imindBand; i--) {
3263 band = &infoPtr->bands[i];
3264 if (!HIDDENBAND(band)) {
3265 iprevBand = i;
3266 READJ(band, movement);
3267 band->ccx = rcBw(band);
3268 break;
3269 }
3270 }
3271 /* what case is this */
3272 if (iprevBand == -1) {
3273 ERR("no previous visible band\n");
3274 return FALSE;
3275 }
3276 startBand = iprevBand;
3277 endBand = uBand;
3278 SetRect (&newrect,
3279 band->rcBand.left,
3280 band->rcBand.top,
3281 lpBand->rcBand.right,
3282 lpBand->rcBand.bottom);
3283 }
3284
3285 REBAR_Shrink (infoPtr, lpBand, movement, uBand);
3286
3287 /* recompute all rectangles */
3288 if (infoPtr->dwStyle & CCS_VERT) {
3289 REBAR_CalcVertBand (infoPtr, startBand, endBand+1,
3290 FALSE);
3291 }
3292 else {
3293 REBAR_CalcHorzBand (infoPtr, startBand, endBand+1,
3294 FALSE);
3295 }
3296
3297 TRACE("bands after minimize, see band # %d, %d\n",
3298 startBand, endBand);
3299 REBAR_DumpBand (infoPtr);
3300
3301 REBAR_MoveChildWindows (infoPtr, startBand, endBand+1);
3302
3303 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
3304 UpdateWindow (infoPtr->hwndSelf);
3305 return FALSE;
3306}
3307
3308
3309static LRESULT
3310REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3311{
3312 REBAR_BAND *oldBands = infoPtr->bands;
3313 REBAR_BAND holder;
3314 UINT uFrom = (UINT)wParam;
3315 UINT uTo = (UINT)lParam;
3316
3317 /* Validate */
3318 if ((infoPtr->uNumBands == 0) ||
3319 ((INT)uFrom < 0) || (uFrom >= infoPtr->uNumBands) ||
3320 ((INT)uTo < 0) || (uTo >= infoPtr->uNumBands)) {
3321 /* error !!! */
3322 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
3323 (INT)uFrom, (INT)uTo, infoPtr->uNumBands);
3324 return FALSE;
3325 }
3326
3327 /* save one to be moved */
3328 memcpy (&holder, &oldBands[uFrom], sizeof(REBAR_BAND));
3329
3330 /* close up rest of bands (psuedo delete) */
3331 if (uFrom < infoPtr->uNumBands - 1) {
3332 memcpy (&oldBands[uFrom], &oldBands[uFrom+1],
3333 (infoPtr->uNumBands - uFrom - 1) * sizeof(REBAR_BAND));
3334 }
3335
3336 /* allocate new space and copy rest of bands into it */
3337 infoPtr->bands =
3338 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
3339
3340 /* pre insert copy */
3341 if (uTo > 0) {
3342 memcpy (&infoPtr->bands[0], &oldBands[0],
3343 uTo * sizeof(REBAR_BAND));
3344 }
3345
3346 /* set moved band */
3347 memcpy (&infoPtr->bands[uTo], &holder, sizeof(REBAR_BAND));
3348
3349 /* post copy */
3350 if (uTo < infoPtr->uNumBands - 1) {
3351 memcpy (&infoPtr->bands[uTo+1], &oldBands[uTo],
3352 (infoPtr->uNumBands - uTo - 1) * sizeof(REBAR_BAND));
3353 }
3354
3355 COMCTL32_Free (oldBands);
3356
3357 TRACE("moved band %d to index %d\n", uFrom, uTo);
3358 REBAR_DumpBand (infoPtr);
3359
3360 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3361 /* **************************************************** */
3362 /* */
3363 /* We do not do a REBAR_Layout here because the native */
3364 /* control does not do that. The actual layout and */
3365 /* repaint is done by the *next* real action, ex.: */
3366 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
3367 /* */
3368 /* **************************************************** */
3369
3370 return TRUE;
3371}
3372
3373
3374static LRESULT
3375REBAR_SetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3376{
3377 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
3378 REBAR_BAND *lpBand;
3379
3380 if (lprbbi == NULL)
3381 return FALSE;
3382 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
3383 return FALSE;
3384 if ((UINT)wParam >= infoPtr->uNumBands)
3385 return FALSE;
3386
3387 TRACE("index %u\n", (UINT)wParam);
3388 REBAR_DumpBandInfo (lprbbi);
3389
3390 /* set band information */
3391 lpBand = &infoPtr->bands[(UINT)wParam];
3392
3393 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3394 if (lprbbi->fMask & RBBIM_TEXT) {
3395 if (lpBand->lpText) {
3396 COMCTL32_Free (lpBand->lpText);
3397 lpBand->lpText = NULL;
3398 }
3399 if (lprbbi->lpText) {
3400 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3401 lpBand->lpText = (LPWSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
3402 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3403 }
3404 }
3405
3406 REBAR_ValidateBand (infoPtr, lpBand);
3407
3408 REBAR_DumpBand (infoPtr);
3409
3410 if (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) {
3411 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3412 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3413 }
3414
3415 return TRUE;
3416}
3417
3418
3419static LRESULT
3420REBAR_SetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3421{
3422 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3423 REBAR_BAND *lpBand;
3424
3425 if (lprbbi == NULL)
3426 return FALSE;
3427 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
3428 return FALSE;
3429 if ((UINT)wParam >= infoPtr->uNumBands)
3430 return FALSE;
3431
3432 TRACE("index %u\n", (UINT)wParam);
3433 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3434
3435 /* set band information */
3436 lpBand = &infoPtr->bands[(UINT)wParam];
3437
3438 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3439 if (lprbbi->fMask & RBBIM_TEXT) {
3440 if (lpBand->lpText) {
3441 COMCTL32_Free (lpBand->lpText);
3442 lpBand->lpText = NULL;
3443 }
3444 if (lprbbi->lpText) {
3445 INT len = lstrlenW (lprbbi->lpText);
3446 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
3447 strcpyW (lpBand->lpText, lprbbi->lpText);
3448 }
3449 }
3450
3451 REBAR_ValidateBand (infoPtr, lpBand);
3452
3453 REBAR_DumpBand (infoPtr);
3454
3455 if (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) {
3456 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3457 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3458 }
3459
3460 return TRUE;
3461}
3462
3463
3464static LRESULT
3465REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3466{
3467 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
3468 REBAR_BAND *lpBand;
3469 UINT i;
3470
3471 if (lpInfo == NULL)
3472 return FALSE;
3473
3474 if (lpInfo->cbSize < sizeof (REBARINFO))
3475 return FALSE;
3476
3477 TRACE("setting bar info!\n");
3478
3479 if (lpInfo->fMask & RBIM_IMAGELIST) {
3480 infoPtr->himl = lpInfo->himl;
3481 if (infoPtr->himl) {
3482 INT cx, cy;
3483 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
3484 infoPtr->imageSize.cx = cx;
3485 infoPtr->imageSize.cy = cy;
3486 }
3487 else {
3488 infoPtr->imageSize.cx = 0;
3489 infoPtr->imageSize.cy = 0;
3490 }
3491 TRACE("new image cx=%ld, cy=%ld\n", infoPtr->imageSize.cx,
3492 infoPtr->imageSize.cy);
3493 }
3494
3495 /* revalidate all bands to reset flags for images in headers of bands */
3496 for (i=0; i<infoPtr->uNumBands; i++) {
3497 lpBand = &infoPtr->bands[i];
3498 REBAR_ValidateBand (infoPtr, lpBand);
3499 }
3500
3501 return TRUE;
3502}
3503
3504
3505static LRESULT
3506REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3507{
3508 COLORREF clrTemp;
3509
3510 clrTemp = infoPtr->clrBk;
3511 infoPtr->clrBk = (COLORREF)lParam;
3512
3513 TRACE("background color 0x%06lx!\n", infoPtr->clrBk);
3514
3515 return clrTemp;
3516}
3517
3518
3519/* << REBAR_SetColorScheme >> */
3520/* << REBAR_SetPalette >> */
3521
3522
3523static LRESULT
3524REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3525{
3526 HWND hwndTemp = infoPtr->hwndNotify;
3527
3528 infoPtr->hwndNotify = (HWND)wParam;
3529
3530 return (LRESULT)hwndTemp;
3531}
3532
3533
3534static LRESULT
3535REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3536{
3537 COLORREF clrTemp;
3538
3539 clrTemp = infoPtr->clrText;
3540 infoPtr->clrText = (COLORREF)lParam;
3541
3542 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
3543
3544 return clrTemp;
3545}
3546
3547
3548/* << REBAR_SetTooltips >> */
3549
3550
3551inline static LRESULT
3552REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, WPARAM wParam)
3553{
3554 BOOL bTemp = infoPtr->bUnicode;
3555
3556 TRACE("to %s hwnd=%p, was %s\n",
3557 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf,
3558 (bTemp) ? "TRUE" : "FALSE");
3559
3560 infoPtr->bUnicode = (BOOL)wParam;
3561
3562 return bTemp;
3563}
3564
3565
3566static LRESULT
3567REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
3568{
3569 INT iOldVersion = infoPtr->iVersion;
3570
3571 if (iVersion > COMCTL32_VERSION)
3572 return -1;
3573
3574 infoPtr->iVersion = iVersion;
3575
3576 TRACE("new version %d\n", iVersion);
3577
3578 return iOldVersion;
3579}
3580
3581
3582static LRESULT
3583REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3584{
3585 REBAR_BAND *lpBand;
3586
3587 if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
3588 return FALSE;
3589
3590 lpBand = &infoPtr->bands[(INT)wParam];
3591
3592 if ((BOOL)lParam) {
3593 TRACE("show band %d\n", (INT)wParam);
3594 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
3595 if (IsWindow (lpBand->hwndChild))
3596 ShowWindow (lpBand->hwndChild, SW_SHOW);
3597 }
3598 else {
3599 TRACE("hide band %d\n", (INT)wParam);
3600 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
3601 if (IsWindow (lpBand->hwndChild))
3602 ShowWindow (lpBand->hwndChild, SW_HIDE);
3603 }
3604
3605 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3606 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3607
3608 return TRUE;
3609}
3610
3611
3612static LRESULT
3613REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3614{
3615 LPRECT lpRect = (LPRECT)lParam;
3616 RECT t1;
3617
3618 if (lpRect == NULL)
3619 return FALSE;
3620
3621 TRACE("[%d %d %d %d]\n",
3622 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
3623
3624 /* what is going on???? */
3625 GetWindowRect(infoPtr->hwndSelf, &t1);
3626 TRACE("window rect [%d %d %d %d]\n",
3627 t1.left, t1.top, t1.right, t1.bottom);
3628 GetClientRect(infoPtr->hwndSelf, &t1);
3629 TRACE("client rect [%d %d %d %d]\n",
3630 t1.left, t1.top, t1.right, t1.bottom);
3631
3632 /* force full _Layout processing */
3633 TRACE("setting NEEDS_LAYOUT\n");
3634 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3635 REBAR_Layout (infoPtr, lpRect, TRUE, FALSE);
3636 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3637 return TRUE;
3638}
3639
3640
3641
3642static LRESULT
3643REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3644{
3645 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3646 RECT wnrc1, clrc1;
3647
3648 if (TRACE_ON(rebar)) {
3649 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
3650 GetClientRect(infoPtr->hwndSelf, &clrc1);
3651 TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
3652 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3653 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3654 cs->x, cs->y, cs->cx, cs->cy);
3655 }
3656
3657 TRACE("created!\n");
3658 return 0;
3659}
3660
3661
3662static LRESULT
3663REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3664{
3665 REBAR_BAND *lpBand;
3666 INT i;
3667
3668
3669 /* free rebar bands */
3670 if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
3671 /* clean up each band */
3672 for (i = 0; i < infoPtr->uNumBands; i++) {
3673 lpBand = &infoPtr->bands[i];
3674
3675 /* delete text strings */
3676 if (lpBand->lpText) {
3677 COMCTL32_Free (lpBand->lpText);
3678 lpBand->lpText = NULL;
3679 }
3680 /* destroy child window */
3681 DestroyWindow (lpBand->hwndChild);
3682 }
3683
3684 /* free band array */
3685 COMCTL32_Free (infoPtr->bands);
3686 infoPtr->bands = NULL;
3687 }
3688
3689 DeleteObject (infoPtr->hcurArrow);
3690 DeleteObject (infoPtr->hcurHorz);
3691 DeleteObject (infoPtr->hcurVert);
3692 DeleteObject (infoPtr->hcurDrag);
3693 if(infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
3694 SetWindowLongA (infoPtr->hwndSelf, 0, 0);
3695
3696 /* free rebar info data */
3697 COMCTL32_Free (infoPtr);
3698 TRACE("destroyed!\n");
3699 return 0;
3700}
3701
3702
3703static LRESULT
3704REBAR_EraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3705{
3706 RECT cliprect;
3707
3708 if (GetClipBox ( (HDC)wParam, &cliprect))
3709 return REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &cliprect);
3710 return 0;
3711}
3712
3713
3714static LRESULT
3715REBAR_GetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3716{
3717 return (LRESULT)infoPtr->hFont;
3718}
3719
3720
3721static LRESULT
3722REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3723{
3724 REBAR_BAND *lpBand;
3725
3726 /* If InternalHitTest did not find a hit on the Gripper, */
3727 /* then ignore the button click. */
3728 if (infoPtr->ihitBand == -1) return 0;
3729
3730 SetCapture (infoPtr->hwndSelf);
3731
3732 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3733 lpBand = &infoPtr->bands[infoPtr->ihitBand];
3734 infoPtr->dragStart = MAKEPOINTS(lParam);
3735 infoPtr->dragNow = infoPtr->dragStart;
3736 if (infoPtr->dwStyle & CCS_VERT)
3737 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.top+REBAR_PRE_GRIPPER);
3738 else
3739 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left+REBAR_PRE_GRIPPER);
3740
3741 return 0;
3742}
3743
3744
3745static LRESULT
3746REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3747{
3748 NMHDR layout;
3749 RECT rect;
3750 INT ihitBand;
3751
3752 /* If InternalHitTest did not find a hit on the Gripper, */
3753 /* then ignore the button click. */
3754 if (infoPtr->ihitBand == -1) return 0;
3755
3756 ihitBand = infoPtr->ihitBand;
3757 infoPtr->dragStart.x = 0;
3758 infoPtr->dragStart.y = 0;
3759 infoPtr->dragNow = infoPtr->dragStart;
3760 infoPtr->ihitBand = -1;
3761
3762 ReleaseCapture ();
3763
3764 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3765 REBAR_Notify((NMHDR *) &layout, infoPtr, RBN_LAYOUTCHANGED);
3766 REBAR_Notify_NMREBAR (infoPtr, ihitBand, RBN_ENDDRAG);
3767 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3768 }
3769
3770 GetClientRect(infoPtr->hwndSelf, &rect);
3771 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3772
3773 return 0;
3774}
3775
3776
3777static LRESULT
3778REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3779{
3780 REBAR_BAND *band1, *band2;
3781 POINTS ptsmove;
3782
3783 /* Validate entry as hit on Gripper has occurred */
3784 if (GetCapture() != infoPtr->hwndSelf) return 0;
3785 if (infoPtr->ihitBand == -1) return 0;
3786
3787 ptsmove = MAKEPOINTS(lParam);
3788
3789 /* if mouse did not move much, exit */
3790 if ((abs(ptsmove.x - infoPtr->dragNow.x) <= mindragx) &&
3791 (abs(ptsmove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3792
3793 band1 = &infoPtr->bands[infoPtr->ihitBand-1];
3794 band2 = &infoPtr->bands[infoPtr->ihitBand];
3795
3796 /* Test for valid drag case - must not be first band in row */
3797 if (infoPtr->dwStyle & CCS_VERT) {
3798 if ((ptsmove.x < band2->rcBand.left) ||
3799 (ptsmove.x > band2->rcBand.right) ||
3800 ((infoPtr->ihitBand > 0) && (band1->iRow != band2->iRow))) {
3801 FIXME("Cannot drag to other rows yet!!\n");
3802 }
3803 else {
3804 REBAR_HandleLRDrag (infoPtr, &ptsmove);
3805 }
3806 }
3807 else {
3808 if ((ptsmove.y < band2->rcBand.top) ||
3809 (ptsmove.y > band2->rcBand.bottom) ||
3810 ((infoPtr->ihitBand > 0) && (band1->iRow != band2->iRow))) {
3811 FIXME("Cannot drag to other rows yet!!\n");
3812 }
3813 else {
3814 REBAR_HandleLRDrag (infoPtr, &ptsmove);
3815 }
3816 }
3817 return 0;
3818}
3819
3820
3821inline static LRESULT
3822REBAR_NCCalcSize (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3823{
3824 if (infoPtr->dwStyle & WS_BORDER) {
3825 InflateRect((LPRECT)lParam, -GetSystemMetrics(SM_CXEDGE),
3826 -GetSystemMetrics(SM_CYEDGE));
3827 }
3828 TRACE("new client=(%d,%d)-(%d,%d)\n",
3829 ((LPRECT)lParam)->left, ((LPRECT)lParam)->top,
3830 ((LPRECT)lParam)->right, ((LPRECT)lParam)->bottom);
3831 return 0;
3832}
3833
3834
3835static LRESULT
3836REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3837{
3838 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3839 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3840 RECT wnrc1, clrc1;
3841 NONCLIENTMETRICSA ncm;
3842 HFONT tfont;
3843 INT i;
3844
3845 if (infoPtr != NULL) {
3846 ERR("Strange info structure pointer *not* NULL\n");
3847 return FALSE;
3848 }
3849
3850 if (TRACE_ON(rebar)) {
3851 GetWindowRect(hwnd, &wnrc1);
3852 GetClientRect(hwnd, &clrc1);
3853 TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
3854 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3855 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3856 cs->x, cs->y, cs->cx, cs->cy);
3857 }
3858
3859 /* allocate memory for info structure */
3860 infoPtr = (REBAR_INFO *)COMCTL32_Alloc (sizeof(REBAR_INFO));
3861 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
3862
3863 /* initialize info structure - initial values are 0 */
3864 infoPtr->clrBk = CLR_NONE;
3865 infoPtr->clrText = CLR_NONE;
3866 infoPtr->clrBtnText = GetSysColor (COLOR_BTNTEXT);
3867 infoPtr->clrBtnFace = GetSysColor (COLOR_BTNFACE);
3868 infoPtr->ihitBand = -1;
3869 infoPtr->hwndSelf = hwnd;
3870 infoPtr->DoRedraw = TRUE;
3871 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
3872 infoPtr->hcurHorz = LoadCursorA (0, IDC_SIZEWEA);
3873 infoPtr->hcurVert = LoadCursorA (0, IDC_SIZENSA);
3874 infoPtr->hcurDrag = LoadCursorA (0, IDC_SIZEA);
3875 infoPtr->bUnicode = IsWindowUnicode (hwnd);
3876 infoPtr->fStatus = CREATE_RUNNING;
3877 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3878
3879 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3880 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
3881 WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
3882 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
3883 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
3884 i);
3885 i = NFR_ANSI;
3886 }
3887 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
3888
3889 /* add necessary styles to the requested styles */
3890 infoPtr->dwStyle = cs->style | WS_VISIBLE | CCS_TOP;
3891 SetWindowLongA (hwnd, GWL_STYLE, infoPtr->dwStyle);
3892
3893 /* get font handle for Caption Font */
3894 ncm.cbSize = sizeof(NONCLIENTMETRICSA);
3895 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS,
3896 ncm.cbSize, &ncm, 0);
3897 /* if the font is bold, set to normal */
3898 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3899 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3900 }
3901 tfont = CreateFontIndirectA (&ncm.lfCaptionFont);
3902 if (tfont) {
3903 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3904 }
3905
3906/* native does:
3907 GetSysColor (numerous);
3908 GetSysColorBrush (numerous) (see WM_SYSCOLORCHANGE);
3909 *GetStockObject (SYSTEM_FONT);
3910 *SetWindowLong (hwnd, 0, info ptr);
3911 *WM_NOTIFYFORMAT;
3912 *SetWindowLong (hwnd, GWL_STYLE, style+0x10000001);
3913 WS_VISIBLE = 0x10000000;
3914 CCS_TOP = 0x00000001;
3915 *SystemParametersInfo (SPI_GETNONCLIENTMETRICS...);
3916 *CreateFontIndirect (lfCaptionFont from above);
3917 GetDC ();
3918 SelectObject (hdc, fontabove);
3919 GetTextMetrics (hdc, ); guessing is tmHeight
3920 SelectObject (hdc, oldfont);
3921 ReleaseDC ();
3922 GetWindowRect ();
3923 MapWindowPoints (0, parent, rectabove, 2);
3924 GetWindowRect ();
3925 GetClientRect ();
3926 ClientToScreen (clientrect);
3927 SetWindowPos (hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER);
3928 */
3929 return TRUE;
3930}
3931
3932
3933static LRESULT
3934REBAR_NCHitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3935{
3936 NMMOUSE nmmouse;
3937 POINTS shortpt;
3938 POINT clpt, pt;
3939 INT i;
3940 UINT scrap;
3941 LRESULT ret = HTCLIENT;
3942
3943 /*
3944 * Differences from doc at MSDN (as observed with version 4.71 of
3945 * comctl32.dll
3946 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3947 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3948 * 3. native always seems to return HTCLIENT if notify return is 0.
3949 */
3950
3951 shortpt = MAKEPOINTS (lParam);
3952 POINTSTOPOINT(pt, shortpt);
3953 clpt = pt;
3954 ScreenToClient (infoPtr->hwndSelf, &clpt);
3955 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3956 (INT *)&nmmouse.dwItemSpec);
3957 nmmouse.dwItemData = 0;
3958 nmmouse.pt = clpt;
3959 nmmouse.dwHitInfo = 0;
3960 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3961 TRACE("notify changed return value from %ld to %d\n",
3962 ret, i);
3963 ret = (LRESULT) i;
3964 }
3965 TRACE("returning %ld, client point (%ld,%ld)\n", ret, clpt.x, clpt.y);
3966 return ret;
3967}
3968
3969
3970static LRESULT
3971REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3972{
3973 RECT rcWindow;
3974 HDC hdc;
3975
3976 if (infoPtr->dwStyle & WS_MINIMIZE)
3977 return 0; /* Nothing to do */
3978
3979 if (infoPtr->dwStyle & WS_BORDER) {
3980
3981 /* adjust rectangle and draw the necessary edge */
3982 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3983 return 0;
3984 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3985 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3986 TRACE("rect (%d,%d)-(%d,%d)\n",
3987 rcWindow.left, rcWindow.top,
3988 rcWindow.right, rcWindow.bottom);
3989 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3990 ReleaseDC( infoPtr->hwndSelf, hdc );
3991 }
3992
3993 return 0;
3994}
3995
3996
3997static LRESULT
3998REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3999{
4000 INT i;
4001
4002 if (lParam == NF_REQUERY) {
4003 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
4004 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
4005 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
4006 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
4007 i);
4008 i = NFR_ANSI;
4009 }
4010 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
4011 return (LRESULT)i;
4012 }
4013 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
4014}
4015
4016
4017static LRESULT
4018REBAR_Paint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4019{
4020 HDC hdc;
4021 PAINTSTRUCT ps;
4022 RECT rc;
4023
4024 GetClientRect(infoPtr->hwndSelf, &rc);
4025 hdc = wParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : (HDC)wParam;
4026
4027 TRACE("painting (%d,%d)-(%d,%d) client (%d,%d)-(%d,%d)\n",
4028 ps.rcPaint.left, ps.rcPaint.top,
4029 ps.rcPaint.right, ps.rcPaint.bottom,
4030 rc.left, rc.top, rc.right, rc.bottom);
4031
4032 if (ps.fErase) {
4033 /* Erase area of paint if requested */
4034 REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &ps.rcPaint);
4035 }
4036
4037 REBAR_Refresh (infoPtr, hdc);
4038 if (!wParam)
4039 EndPaint (infoPtr->hwndSelf, &ps);
4040 return 0;
4041}
4042
4043
4044static LRESULT
4045REBAR_SetCursor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4046{
4047 POINT pt;
4048 UINT flags;
4049
4050 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
4051
4052 GetCursorPos (&pt);
4053 ScreenToClient (infoPtr->hwndSelf, &pt);
4054
4055 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
4056
4057 if (flags == RBHT_GRABBER) {
4058 if ((infoPtr->dwStyle & CCS_VERT) &&
4059 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
4060 SetCursor (infoPtr->hcurVert);
4061 else
4062 SetCursor (infoPtr->hcurHorz);
4063 }
4064 else if (flags != RBHT_CLIENT)
4065 SetCursor (infoPtr->hcurArrow);
4066
4067 return 0;
4068}
4069
4070
4071static LRESULT
4072REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4073{
4074 RECT rcClient;
4075 REBAR_BAND *lpBand;
4076 UINT i;
4077
4078 infoPtr->hFont = (HFONT)wParam;
4079
4080 /* revalidate all bands to change sizes of text in headers of bands */
4081 for (i=0; i<infoPtr->uNumBands; i++) {
4082 lpBand = &infoPtr->bands[i];
4083 REBAR_ValidateBand (infoPtr, lpBand);
4084 }
4085
4086
4087 if (LOWORD(lParam)) {
4088 GetClientRect (infoPtr->hwndSelf, &rcClient);
4089 REBAR_Layout (infoPtr, &rcClient, FALSE, TRUE);
4090 }
4091
4092 return 0;
4093}
4094
4095
4096inline static LRESULT
4097REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4098 /*****************************************************
4099 *
4100 * Function;
4101 * Handles the WM_SETREDRAW message.
4102 *
4103 * Documentation:
4104 * According to testing V4.71 of COMCTL32 returns the
4105 * *previous* status of the redraw flag (either 0 or -1)
4106 * instead of the MSDN documented value of 0 if handled
4107 *
4108 *****************************************************/
4109{
4110 BOOL oldredraw = infoPtr->DoRedraw;
4111
4112 TRACE("set to %s, fStatus=%08x\n",
4113 (wParam) ? "TRUE" : "FALSE", infoPtr->fStatus);
4114 infoPtr->DoRedraw = (BOOL) wParam;
4115 if (wParam) {
4116 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
4117 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
4118 REBAR_ForceResize (infoPtr);
4119 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
4120 }
4121 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
4122 }
4123 return (oldredraw) ? -1 : 0;
4124}
4125
4126
4127static LRESULT
4128REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4129{
4130 RECT rcClient;
4131
4132 /* auto resize deadlock check */
4133 if (infoPtr->fStatus & AUTO_RESIZE) {
4134 infoPtr->fStatus &= ~AUTO_RESIZE;
4135 TRACE("AUTO_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
4136 infoPtr->fStatus, lParam);
4137 return 0;
4138 }
4139
4140 if (infoPtr->fStatus & CREATE_RUNNING) {
4141 /* still in CreateWindow */
4142 RECT rcWin;
4143
4144 if ((INT)wParam != SIZE_RESTORED) {
4145 ERR("WM_SIZE in create and flags=%08x, lParam=%08lx\n",
4146 wParam, lParam);
4147 }
4148
4149 TRACE("still in CreateWindow\n");
4150 infoPtr->fStatus &= ~CREATE_RUNNING;
4151 GetWindowRect ( infoPtr->hwndSelf, &rcWin);
4152 TRACE("win rect (%d,%d)-(%d,%d)\n",
4153 rcWin.left, rcWin.top, rcWin.right, rcWin.bottom);
4154
4155 if ((lParam == 0) && (rcWin.right-rcWin.left == 0) &&
4156 (rcWin.bottom-rcWin.top == 0)) {
4157 /* native control seems to do this */
4158 GetClientRect (GetParent(infoPtr->hwndSelf), &rcClient);
4159 TRACE("sizing rebar, message and client zero, parent client (%d,%d)\n",
4160 rcClient.right, rcClient.bottom);
4161 }
4162 else {
4163 INT cx, cy;
4164
4165 cx = rcWin.right - rcWin.left;
4166 cy = rcWin.bottom - rcWin.top;
4167 if ((cx == LOWORD(lParam)) && (cy == HIWORD(lParam))) {
4168 return 0;
4169 }
4170
4171 /* do the actual WM_SIZE request */
4172 GetClientRect (infoPtr->hwndSelf, &rcClient);
4173 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%d,%d)\n",
4174 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4175 LOWORD(lParam), HIWORD(lParam),
4176 rcClient.right, rcClient.bottom);
4177 }
4178 }
4179 else {
4180 if ((INT)wParam != SIZE_RESTORED) {
4181 ERR("WM_SIZE out of create and flags=%08x, lParam=%08lx\n",
4182 wParam, lParam);
4183 }
4184
4185 /* Handle cases when outside of the CreateWindow process */
4186
4187 GetClientRect (infoPtr->hwndSelf, &rcClient);
4188 if ((lParam == 0) && (rcClient.right + rcClient.bottom != 0) &&
4189 (infoPtr->dwStyle & RBS_AUTOSIZE)) {
4190 /* on a WM_SIZE to zero and current client not zero and AUTOSIZE */
4191 /* native seems to use the current client rect for the size */
4192 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4193 TRACE("sizing rebar to client (%d,%d) size is zero but AUTOSIZE set\n",
4194 rcClient.right, rcClient.bottom);
4195 }
4196 else {
4197 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%d,%d)\n",
4198 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4199 LOWORD(lParam), HIWORD(lParam),
4200 rcClient.right, rcClient.bottom);
4201 }
4202 }
4203
4204 if (infoPtr->dwStyle & RBS_AUTOSIZE) {
4205 NMRBAUTOSIZE autosize;
4206
4207 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
4208 autosize.fChanged = 0; /* ??? */
4209 autosize.rcActual = autosize.rcTarget; /* ??? */
4210 REBAR_Notify((NMHDR *) &autosize, infoPtr, RBN_AUTOSIZE);
4211 TRACE("RBN_AUTOSIZE client=(%d,%d), lp=%08lx\n",
4212 autosize.rcTarget.right, autosize.rcTarget.bottom, lParam);
4213 }
4214
4215 if ((infoPtr->calcSize.cx != rcClient.right) ||
4216 (infoPtr->calcSize.cy != rcClient.bottom))
4217 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4218
4219 REBAR_Layout (infoPtr, &rcClient, TRUE, TRUE);
4220 infoPtr->fStatus &= ~AUTO_RESIZE;
4221
4222 return 0;
4223}
4224
4225
4226static LRESULT
4227REBAR_StyleChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4228{
4229 STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
4230
4231 TRACE("current style=%08lx, styleOld=%08lx, style being set to=%08lx\n",
4232 infoPtr->dwStyle, ss->styleOld, ss->styleNew);
4233 infoPtr->dwStyle = ss->styleNew;
4234
4235 return FALSE;
4236}
4237
4238
4239static LRESULT
4240REBAR_WindowPosChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4241{
4242 WINDOWPOS *lpwp = (WINDOWPOS *)lParam;
4243 LRESULT ret;
4244 RECT rc;
4245
4246 /* Save the new origin of this window - used by _ForceResize */
4247 infoPtr->origin.x = lpwp->x;
4248 infoPtr->origin.y = lpwp->y;
4249 ret = DefWindowProcA(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
4250 wParam, lParam);
4251 GetWindowRect(infoPtr->hwndSelf, &rc);
4252 TRACE("hwnd %p new pos (%d,%d)-(%d,%d)\n",
4253 infoPtr->hwndSelf, rc.left, rc.top, rc.right, rc.bottom);
4254 return ret;
4255}
4256
4257
4258static LRESULT WINAPI
4259REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4260{
4261 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
4262
4263 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
4264 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
4265 if (!infoPtr && (uMsg != WM_NCCREATE))
4266 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4267 switch (uMsg)
4268 {
4269/* case RB_BEGINDRAG: */
4270
4271 case RB_DELETEBAND:
4272 return REBAR_DeleteBand (infoPtr, wParam, lParam);
4273
4274/* case RB_DRAGMOVE: */
4275/* case RB_ENDDRAG: */
4276
4277 case RB_GETBANDBORDERS:
4278 return REBAR_GetBandBorders (infoPtr, wParam, lParam);
4279
4280 case RB_GETBANDCOUNT:
4281 return REBAR_GetBandCount (infoPtr);
4282
4283 case RB_GETBANDINFO: /* obsoleted after IE3, but we have to
4284 support it anyway. */
4285 case RB_GETBANDINFOA:
4286 return REBAR_GetBandInfoA (infoPtr, wParam, lParam);
4287
4288 case RB_GETBANDINFOW:
4289 return REBAR_GetBandInfoW (infoPtr, wParam, lParam);
4290
4291 case RB_GETBARHEIGHT:
4292 return REBAR_GetBarHeight (infoPtr, wParam, lParam);
4293
4294 case RB_GETBARINFO:
4295 return REBAR_GetBarInfo (infoPtr, wParam, lParam);
4296
4297 case RB_GETBKCOLOR:
4298 return REBAR_GetBkColor (infoPtr);
4299
4300/* case RB_GETCOLORSCHEME: */
4301/* case RB_GETDROPTARGET: */
4302
4303 case RB_GETPALETTE:
4304 return REBAR_GetPalette (infoPtr, wParam, lParam);
4305
4306 case RB_GETRECT:
4307 return REBAR_GetRect (infoPtr, wParam, lParam);
4308
4309 case RB_GETROWCOUNT:
4310 return REBAR_GetRowCount (infoPtr);
4311
4312 case RB_GETROWHEIGHT:
4313 return REBAR_GetRowHeight (infoPtr, wParam, lParam);
4314
4315 case RB_GETTEXTCOLOR:
4316 return REBAR_GetTextColor (infoPtr);
4317
4318 case RB_GETTOOLTIPS:
4319 return REBAR_GetToolTips (infoPtr);
4320
4321 case RB_GETUNICODEFORMAT:
4322 return REBAR_GetUnicodeFormat (infoPtr);
4323
4324 case CCM_GETVERSION:
4325 return REBAR_GetVersion (infoPtr);
4326
4327 case RB_HITTEST:
4328 return REBAR_HitTest (infoPtr, wParam, lParam);
4329
4330 case RB_IDTOINDEX:
4331 return REBAR_IdToIndex (infoPtr, wParam, lParam);
4332
4333 case RB_INSERTBANDA:
4334 return REBAR_InsertBandA (infoPtr, wParam, lParam);
4335
4336 case RB_INSERTBANDW:
4337 return REBAR_InsertBandW (infoPtr, wParam, lParam);
4338
4339 case RB_MAXIMIZEBAND:
4340 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
4341
4342 case RB_MINIMIZEBAND:
4343 return REBAR_MinimizeBand (infoPtr, wParam, lParam);
4344
4345 case RB_MOVEBAND:
4346 return REBAR_MoveBand (infoPtr, wParam, lParam);
4347
4348 case RB_SETBANDINFOA:
4349 return REBAR_SetBandInfoA (infoPtr, wParam, lParam);
4350
4351 case RB_SETBANDINFOW:
4352 return REBAR_SetBandInfoW (infoPtr, wParam, lParam);
4353
4354 case RB_SETBARINFO:
4355 return REBAR_SetBarInfo (infoPtr, wParam, lParam);
4356
4357 case RB_SETBKCOLOR:
4358 return REBAR_SetBkColor (infoPtr, wParam, lParam);
4359
4360/* case RB_SETCOLORSCHEME: */
4361/* case RB_SETPALETTE: */
4362/* return REBAR_GetPalette (infoPtr, wParam, lParam); */
4363
4364 case RB_SETPARENT:
4365 return REBAR_SetParent (infoPtr, wParam, lParam);
4366
4367 case RB_SETTEXTCOLOR:
4368 return REBAR_SetTextColor (infoPtr, wParam, lParam);
4369
4370/* case RB_SETTOOLTIPS: */
4371
4372 case RB_SETUNICODEFORMAT:
4373 return REBAR_SetUnicodeFormat (infoPtr, wParam);
4374
4375 case CCM_SETVERSION:
4376 return REBAR_SetVersion (infoPtr, (INT)wParam);
4377
4378 case RB_SHOWBAND:
4379 return REBAR_ShowBand (infoPtr, wParam, lParam);
4380
4381 case RB_SIZETORECT:
4382 return REBAR_SizeToRect (infoPtr, wParam, lParam);
4383
4384
4385/* Messages passed to parent */
4386 case WM_COMMAND:
4387 case WM_DRAWITEM:
4388 case WM_NOTIFY:
4389 if (infoPtr->NtfUnicode)
4390 return SendMessageW (REBAR_GetNotifyParent (infoPtr),
4391 uMsg, wParam, lParam);
4392 else
4393 return SendMessageA (REBAR_GetNotifyParent (infoPtr),
4394 uMsg, wParam, lParam);
4395
4396
4397/* case WM_CHARTOITEM: supported according to ControlSpy */
4398
4399 case WM_CREATE:
4400 return REBAR_Create (infoPtr, wParam, lParam);
4401
4402 case WM_DESTROY:
4403 return REBAR_Destroy (infoPtr, wParam, lParam);
4404
4405 case WM_ERASEBKGND:
4406 return REBAR_EraseBkGnd (infoPtr, wParam, lParam);
4407
4408 case WM_GETFONT:
4409 return REBAR_GetFont (infoPtr, wParam, lParam);
4410
4411/* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
4412
4413 case WM_LBUTTONDOWN:
4414 return REBAR_LButtonDown (infoPtr, wParam, lParam);
4415
4416 case WM_LBUTTONUP:
4417 return REBAR_LButtonUp (infoPtr, wParam, lParam);
4418
4419/* case WM_MEASUREITEM: supported according to ControlSpy */
4420
4421 case WM_MOUSEMOVE:
4422 return REBAR_MouseMove (infoPtr, wParam, lParam);
4423
4424 case WM_NCCALCSIZE:
4425 return REBAR_NCCalcSize (infoPtr, wParam, lParam);
4426
4427 case WM_NCCREATE:
4428 return REBAR_NCCreate (hwnd, wParam, lParam);
4429
4430 case WM_NCHITTEST:
4431 return REBAR_NCHitTest (infoPtr, wParam, lParam);
4432
4433 case WM_NCPAINT:
4434 return REBAR_NCPaint (infoPtr, wParam, lParam);
4435
4436 case WM_NOTIFYFORMAT:
4437 return REBAR_NotifyFormat (infoPtr, wParam, lParam);
4438
4439 case WM_PAINT:
4440 return REBAR_Paint (infoPtr, wParam, lParam);
4441
4442/* case WM_PALETTECHANGED: supported according to ControlSpy */
4443/* case WM_PRINTCLIENT: supported according to ControlSpy */
4444/* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
4445/* case WM_RBUTTONDOWN: supported according to ControlSpy */
4446/* case WM_RBUTTONUP: supported according to ControlSpy */
4447
4448 case WM_SETCURSOR:
4449 return REBAR_SetCursor (infoPtr, wParam, lParam);
4450
4451 case WM_SETFONT:
4452 return REBAR_SetFont (infoPtr, wParam, lParam);
4453
4454 case WM_SETREDRAW:
4455 return REBAR_SetRedraw (infoPtr, wParam, lParam);
4456
4457 case WM_SIZE:
4458 return REBAR_Size (infoPtr, wParam, lParam);
4459
4460 case WM_STYLECHANGED:
4461 return REBAR_StyleChanged (infoPtr, wParam, lParam);
4462
4463/* case WM_SYSCOLORCHANGE: supported according to ControlSpy */
4464/* "Applications that have brushes using the existing system colors
4465 should delete those brushes and recreate them using the new
4466 system colors." per MSDN */
4467
4468/* case WM_VKEYTOITEM: supported according to ControlSpy */
4469/* case WM_WININICHANGE: */
4470
4471 case WM_WINDOWPOSCHANGED:
4472 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
4473
4474 default:
4475 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
4476 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
4477 uMsg, wParam, lParam);
4478 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4479 }
4480 return 0;
4481}
4482
4483
4484VOID
4485REBAR_Register (void)
4486{
4487 WNDCLASSA wndClass;
4488
4489 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4490 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
4491 wndClass.lpfnWndProc = (WNDPROC)REBAR_WindowProc;
4492 wndClass.cbClsExtra = 0;
4493 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
4494 wndClass.hCursor = 0;
4495 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
4496#if GLATESTING
4497 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
4498#endif
4499 wndClass.lpszClassName = REBARCLASSNAMEA;
4500
4501 RegisterClassA (&wndClass);
4502
4503 mindragx = GetSystemMetrics (SM_CXDRAG);
4504 mindragy = GetSystemMetrics (SM_CYDRAG);
4505
4506}
4507
4508
4509VOID
4510REBAR_Unregister (void)
4511{
4512 UnregisterClassA (REBARCLASSNAMEA, (HINSTANCE)NULL);
4513}
Note: See TracBrowser for help on using the repository browser.