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

Last change on this file since 10367 was 10139, checked in by sandervl, 22 years ago

different rebar fix

File size: 131.1 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
1231#ifdef __WIN32OS2__
1232//NOTE: this one is causing problems!!!!
1233 if(height != 0)
1234#endif
1235 SetWindowPos (infoPtr->hwndSelf, 0, x, y, width, height,
1236 SWP_NOZORDER);
1237}
1238
1239
1240static VOID
1241REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
1242{
1243 REBAR_BAND *lpBand;
1244 CHAR szClassName[40];
1245 UINT i;
1246 NMREBARCHILDSIZE rbcz;
1247 NMHDR heightchange;
1248 HDWP deferpos;
1249
1250 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1251 ERR("BeginDeferWindowPos returned NULL\n");
1252
1253 for (i = start; i < endplus; i++) {
1254 lpBand = &infoPtr->bands[i];
1255
1256 if (HIDDENBAND(lpBand)) continue;
1257 if (lpBand->hwndChild) {
1258 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1259
1260 /* Always geterate the RBN_CHILDSIZE even it child
1261 did not change */
1262 rbcz.uBand = i;
1263 rbcz.wID = lpBand->wID;
1264 rbcz.rcChild = lpBand->rcChild;
1265 rbcz.rcBand = lpBand->rcBand;
1266 if (infoPtr->dwStyle & CCS_VERT)
1267 rbcz.rcBand.top += lpBand->cxHeader;
1268 else
1269 rbcz.rcBand.left += lpBand->cxHeader;
1270 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1271 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1272 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1273 TRACE(" from (%d,%d)-(%d,%d) to (%d,%d)-(%d,%d)\n",
1274 lpBand->rcChild.left, lpBand->rcChild.top,
1275 lpBand->rcChild.right, lpBand->rcChild.bottom,
1276 rbcz.rcChild.left, rbcz.rcChild.top,
1277 rbcz.rcChild.right, rbcz.rcChild.bottom);
1278 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1279 }
1280
1281 /* native (IE4 in "Favorites" frame **1) does:
1282 * SetRect (&rc, -1, -1, -1, -1)
1283 * EqualRect (&rc,band->rc???)
1284 * if ret==0
1285 * CopyRect (band->rc????, &rc)
1286 * set flag outside of loop
1287 */
1288
1289 GetClassNameA (lpBand->hwndChild, szClassName, 40);
1290 if (!lstrcmpA (szClassName, "ComboBox") ||
1291 !lstrcmpA (szClassName, WC_COMBOBOXEXA)) {
1292 INT nEditHeight, yPos;
1293 RECT rc;
1294
1295 /* special placement code for combo or comboex box */
1296
1297
1298 /* get size of edit line */
1299 GetWindowRect (lpBand->hwndChild, &rc);
1300 nEditHeight = rc.bottom - rc.top;
1301 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1302
1303 /* center combo box inside child area */
1304 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1305 lpBand->hwndChild,
1306 lpBand->rcChild.left, yPos,
1307 lpBand->rcChild.right - lpBand->rcChild.left,
1308 nEditHeight);
1309 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1310 lpBand->rcChild.left,
1311 /*lpBand->rcChild.top*/ yPos,
1312 lpBand->rcChild.right - lpBand->rcChild.left,
1313 nEditHeight,
1314 SWP_NOZORDER);
1315 if (!deferpos)
1316 ERR("DeferWindowPos returned NULL\n");
1317 }
1318 else {
1319 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1320 lpBand->hwndChild,
1321 lpBand->rcChild.left, lpBand->rcChild.top,
1322 lpBand->rcChild.right - lpBand->rcChild.left,
1323 lpBand->rcChild.bottom - lpBand->rcChild.top);
1324 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1325 lpBand->rcChild.left,
1326 lpBand->rcChild.top,
1327 lpBand->rcChild.right - lpBand->rcChild.left,
1328 lpBand->rcChild.bottom - lpBand->rcChild.top,
1329 SWP_NOZORDER);
1330 if (!deferpos)
1331 ERR("DeferWindowPos returned NULL\n");
1332 }
1333 }
1334 }
1335 if (!EndDeferWindowPos(deferpos))
1336 ERR("EndDeferWindowPos returned NULL\n");
1337
1338 if (infoPtr->DoRedraw)
1339 UpdateWindow (infoPtr->hwndSelf);
1340
1341 if (infoPtr->fStatus & NTF_HGHTCHG) {
1342 infoPtr->fStatus &= ~NTF_HGHTCHG;
1343 REBAR_Notify (&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1344 }
1345
1346 /* native (from **1 above) does:
1347 * UpdateWindow(rebar)
1348 * REBAR_ForceResize
1349 * RBN_HEIGHTCHANGE if necessary
1350 * if ret from any EqualRect was 0
1351 * Goto "BeginDeferWindowPos"
1352 */
1353
1354}
1355
1356
1357static VOID
1358REBAR_Layout (REBAR_INFO *infoPtr, LPRECT lpRect, BOOL notify, BOOL resetclient)
1359 /* Function: This routine is resposible for laying out all */
1360 /* the bands in a rebar. It assigns each band to a row and*/
1361 /* determines when to start a new row. */
1362{
1363 REBAR_BAND *lpBand, *prevBand;
1364 RECT rcClient, rcAdj;
1365 INT initx, inity, x, y, cx, cxsep, mmcy, mcy, clientcx, clientcy;
1366 INT adjcx, adjcy, row, rightx, bottomy, origheight;
1367 UINT i, j, rowstart, origrows, cntonrow;
1368 BOOL dobreak;
1369
1370 if (!(infoPtr->fStatus & BAND_NEEDS_LAYOUT)) {
1371 TRACE("no layout done. No band changed.\n");
1372 REBAR_DumpBand (infoPtr);
1373 return;
1374 }
1375 infoPtr->fStatus &= ~BAND_NEEDS_LAYOUT;
1376 if (!infoPtr->DoRedraw) infoPtr->fStatus |= BAND_NEEDS_REDRAW;
1377
1378 GetClientRect (infoPtr->hwndSelf, &rcClient);
1379 TRACE("Client is (%d,%d)-(%d,%d)\n",
1380 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
1381
1382 if (lpRect) {
1383 rcAdj = *lpRect;
1384 TRACE("adjustment rect is (%d,%d)-(%d,%d)\n",
1385 rcAdj.left, rcAdj.top, rcAdj.right, rcAdj.bottom);
1386 }
1387 else {
1388 CopyRect (&rcAdj, &rcClient);
1389 }
1390
1391 clientcx = rcClient.right - rcClient.left;
1392 clientcy = rcClient.bottom - rcClient.top;
1393 adjcx = rcAdj.right - rcAdj.left;
1394 adjcy = rcAdj.bottom - rcAdj.top;
1395 if (resetclient) {
1396 TRACE("window client rect will be set to adj rect\n");
1397 clientcx = adjcx;
1398 clientcy = adjcy;
1399 }
1400
1401 if (!infoPtr->DoRedraw && (clientcx == 0) && (clientcy == 0)) {
1402 ERR("no redraw and client is zero, skip layout\n");
1403 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1404 return;
1405 }
1406
1407 /* save height of original control */
1408 if (infoPtr->dwStyle & CCS_VERT)
1409 origheight = infoPtr->calcSize.cx;
1410 else
1411 origheight = infoPtr->calcSize.cy;
1412 origrows = infoPtr->uNumRows;
1413
1414 initx = 0;
1415 inity = 0;
1416
1417 /* ******* Start Phase 1 - all bands on row at minimum size ******* */
1418
1419 TRACE("band loop constants, clientcx=%d, clientcy=%d, adjcx=%d, adjcy=%d\n",
1420 clientcx, clientcy, adjcx, adjcy);
1421 x = initx;
1422 y = inity;
1423 row = 1;
1424 cx = 0;
1425 mcy = 0;
1426 rowstart = 0;
1427 prevBand = NULL;
1428 cntonrow = 0;
1429
1430 for (i = 0; i < infoPtr->uNumBands; i++) {
1431 lpBand = &infoPtr->bands[i];
1432 lpBand->fDraw = 0;
1433 lpBand->iRow = row;
1434
1435 if (HIDDENBAND(lpBand)) continue;
1436
1437 lpBand->rcoldBand = lpBand->rcBand;
1438
1439 /* Set the offset of the child window */
1440 if ((lpBand->fMask & RBBIM_CHILD) &&
1441 !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
1442 lpBand->offChild.cx = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 4 : 0);
1443 }
1444 lpBand->offChild.cy = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 2 : 0);
1445
1446 /* separator from previous band */
1447 cxsep = (cntonrow == 0) ? 0 : SEP_WIDTH;
1448
1449 /* Header: includes gripper, text, image */
1450 cx = lpBand->cxHeader;
1451 if (lpBand->fStyle & RBBS_FIXEDSIZE) cx = lpBand->lcx;
1452
1453 if (infoPtr->dwStyle & CCS_VERT)
1454 dobreak = (y + cx + cxsep > adjcy);
1455 else
1456 dobreak = (x + cx + cxsep > adjcx);
1457
1458 /* This is the check for whether we need to start a new row */
1459 if ( ( (lpBand->fStyle & RBBS_BREAK) && (i != 0) ) ||
1460 ( ((infoPtr->dwStyle & CCS_VERT) ? (y != 0) : (x != 0)) && dobreak)) {
1461
1462 for (j = rowstart; j < i; j++) {
1463 REBAR_BAND *lpB;
1464 lpB = &infoPtr->bands[j];
1465 if (infoPtr->dwStyle & CCS_VERT) {
1466 lpB->rcBand.right = lpB->rcBand.left + mcy;
1467 }
1468 else {
1469 lpB->rcBand.bottom = lpB->rcBand.top + mcy;
1470 }
1471 }
1472
1473 TRACE("P1 Spliting to new row %d on band %u\n", row+1, i);
1474 if (infoPtr->dwStyle & CCS_VERT) {
1475 y = inity;
1476 x += (mcy + SEP_WIDTH);
1477 }
1478 else {
1479 x = initx;
1480 y += (mcy + SEP_WIDTH);
1481 }
1482
1483 mcy = 0;
1484 cxsep = 0;
1485 row++;
1486 lpBand->iRow = row;
1487 prevBand = NULL;
1488 rowstart = i;
1489 cntonrow = 0;
1490 }
1491
1492 if (mcy < lpBand->lcy + REBARSPACE(lpBand))
1493 mcy = lpBand->lcy + REBARSPACE(lpBand);
1494
1495 /* if boundary rect specified then limit mcy */
1496 if (lpRect) {
1497 if (infoPtr->dwStyle & CCS_VERT) {
1498 if (x+mcy > adjcx) {
1499 mcy = adjcx - x;
1500 TRACE("P1 row %u limiting mcy=%d, adjcx=%d, x=%d\n",
1501 i, mcy, adjcx, x);
1502 }
1503 }
1504 else {
1505 if (y+mcy > adjcy) {
1506 mcy = adjcy - y;
1507 TRACE("P1 row %u limiting mcy=%d, adjcy=%d, y=%d\n",
1508 i, mcy, adjcy, y);
1509 }
1510 }
1511 }
1512
1513 TRACE("P1 band %u, row %d, x=%d, y=%d, cxsep=%d, cx=%d\n",
1514 i, row,
1515 x, y, cxsep, cx);
1516 if (infoPtr->dwStyle & CCS_VERT) {
1517 /* bound the bottom side if we have a bounding rectangle */
1518 rightx = clientcx;
1519 bottomy = (lpRect) ? min(clientcy, y+cxsep+cx) : y+cxsep+cx;
1520 lpBand->rcBand.left = x;
1521 lpBand->rcBand.right = x + min(mcy,
1522 lpBand->lcy+REBARSPACE(lpBand));
1523 lpBand->rcBand.top = min(bottomy, y + cxsep);
1524 lpBand->rcBand.bottom = bottomy;
1525 lpBand->uMinHeight = lpBand->lcy;
1526 y = bottomy;
1527 }
1528 else {
1529 /* bound the right side if we have a bounding rectangle */
1530 rightx = (lpRect) ? min(clientcx, x+cxsep+cx) : x+cxsep+cx;
1531 bottomy = clientcy;
1532 lpBand->rcBand.left = min(rightx, x + cxsep);
1533 lpBand->rcBand.right = rightx;
1534 lpBand->rcBand.top = y;
1535 lpBand->rcBand.bottom = y + min(mcy,
1536 lpBand->lcy+REBARSPACE(lpBand));
1537 lpBand->uMinHeight = lpBand->lcy;
1538 x = rightx;
1539 }
1540 TRACE("P1 band %u, row %d, (%d,%d)-(%d,%d)\n",
1541 i, row,
1542 lpBand->rcBand.left, lpBand->rcBand.top,
1543 lpBand->rcBand.right, lpBand->rcBand.bottom);
1544 prevBand = lpBand;
1545 cntonrow++;
1546
1547 } /* for (i = 0; i < infoPtr->uNumBands... */
1548
1549 if (infoPtr->dwStyle & CCS_VERT)
1550 x += mcy;
1551 else
1552 y += mcy;
1553
1554 for (j = rowstart; j < infoPtr->uNumBands; j++) {
1555 lpBand = &infoPtr->bands[j];
1556 if (infoPtr->dwStyle & CCS_VERT) {
1557 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
1558 }
1559 else {
1560 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
1561 }
1562 }
1563
1564 if (infoPtr->uNumBands)
1565 infoPtr->uNumRows = row;
1566
1567 /* ******* End Phase 1 - all bands on row at minimum size ******* */
1568
1569
1570 /* ******* Start Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1571
1572 mmcy = 0;
1573 if (!(infoPtr->dwStyle & RBS_VARHEIGHT)) {
1574 INT xy;
1575
1576 /* get the max height of all bands */
1577 for (i=0; i<infoPtr->uNumBands; i++) {
1578 lpBand = &infoPtr->bands[i];
1579 if (HIDDENBAND(lpBand)) continue;
1580 if (infoPtr->dwStyle & CCS_VERT)
1581 mmcy = max(mmcy, lpBand->rcBand.right - lpBand->rcBand.left);
1582 else
1583 mmcy = max(mmcy, lpBand->rcBand.bottom - lpBand->rcBand.top);
1584 }
1585
1586 /* now adjust all rectangles by using the height found above */
1587 xy = 0;
1588 row = 1;
1589 for (i=0; i<infoPtr->uNumBands; i++) {
1590 lpBand = &infoPtr->bands[i];
1591 if (HIDDENBAND(lpBand)) continue;
1592 if (lpBand->iRow != row)
1593 xy += (mmcy + SEP_WIDTH);
1594 if (infoPtr->dwStyle & CCS_VERT) {
1595 lpBand->rcBand.left = xy;
1596 lpBand->rcBand.right = xy + mmcy;
1597 }
1598 else {
1599 lpBand->rcBand.top = xy;
1600 lpBand->rcBand.bottom = xy + mmcy;
1601 }
1602 }
1603
1604 /* set the x/y values to the correct maximum */
1605 if (infoPtr->dwStyle & CCS_VERT)
1606 x = xy + mmcy;
1607 else
1608 y = xy + mmcy;
1609 }
1610
1611 /* ******* End Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1612
1613
1614 /* ******* Start Phase 2 - split rows till adjustment height full ******* */
1615
1616 /* assumes that the following variables contain: */
1617 /* y/x current height/width of all rows */
1618 if (lpRect) {
1619 INT i, j, prev_rh, new_rh, adj_rh, prev_idx, current_idx;
1620 REBAR_BAND *prev, *current, *walk;
1621
1622/* FIXME: problem # 2 */
1623 if (((infoPtr->dwStyle & CCS_VERT) ?
1624#if PROBLEM2
1625 (x < adjcx) : (y < adjcy)
1626#else
1627 (adjcx - x > 4) : (adjcy - y > 4)
1628#endif
1629 ) &&
1630 (infoPtr->uNumBands > 1)) {
1631 for (i=(INT)infoPtr->uNumBands-2; i>=0; i--) {
1632 TRACE("P2 adjcx=%d, adjcy=%d, x=%d, y=%d\n",
1633 adjcx, adjcy, x, y);
1634
1635 /* find the current band (starts at i+1) */
1636 current = &infoPtr->bands[i+1];
1637 current_idx = i+1;
1638 while (HIDDENBAND(current)) {
1639 i--;
1640 if (i < 0) break; /* out of bands */
1641 current = &infoPtr->bands[i+1];
1642 current_idx = i+1;
1643 }
1644 if (i < 0) break; /* out of bands */
1645
1646 /* now find the prev band (starts at i) */
1647 prev = &infoPtr->bands[i];
1648 prev_idx = i;
1649 while (HIDDENBAND(prev)) {
1650 i--;
1651 if (i < 0) break; /* out of bands */
1652 prev = &infoPtr->bands[i];
1653 prev_idx = i;
1654 }
1655 if (i < 0) break; /* out of bands */
1656
1657 prev_rh = ircBw(prev);
1658 if (prev->iRow == current->iRow) {
1659 new_rh = (infoPtr->dwStyle & RBS_VARHEIGHT) ?
1660 current->lcy + REBARSPACE(current) :
1661 mmcy;
1662 adj_rh = new_rh + SEP_WIDTH;
1663 infoPtr->uNumRows++;
1664 current->fDraw |= NTF_INVALIDATE;
1665 current->iRow++;
1666 if (infoPtr->dwStyle & CCS_VERT) {
1667 current->rcBand.top = inity;
1668 current->rcBand.bottom = clientcy;
1669 current->rcBand.left += (prev_rh + SEP_WIDTH);
1670 current->rcBand.right = current->rcBand.left + new_rh;
1671 x += adj_rh;
1672 }
1673 else {
1674 current->rcBand.left = initx;
1675 current->rcBand.right = clientcx;
1676 current->rcBand.top += (prev_rh + SEP_WIDTH);
1677 current->rcBand.bottom = current->rcBand.top + new_rh;
1678 y += adj_rh;
1679 }
1680 TRACE("P2 moving band %d to own row at (%d,%d)-(%d,%d)\n",
1681 current_idx,
1682 current->rcBand.left, current->rcBand.top,
1683 current->rcBand.right, current->rcBand.bottom);
1684 TRACE("P2 prev band %d at (%d,%d)-(%d,%d)\n",
1685 prev_idx,
1686 prev->rcBand.left, prev->rcBand.top,
1687 prev->rcBand.right, prev->rcBand.bottom);
1688 TRACE("P2 values: prev_rh=%d, new_rh=%d, adj_rh=%d\n",
1689 prev_rh, new_rh, adj_rh);
1690 /* for bands below current adjust row # and top/bottom */
1691 for (j = current_idx+1; j<infoPtr->uNumBands; j++) {
1692 walk = &infoPtr->bands[j];
1693 if (HIDDENBAND(walk)) continue;
1694 walk->fDraw |= NTF_INVALIDATE;
1695 walk->iRow++;
1696 if (infoPtr->dwStyle & CCS_VERT) {
1697 walk->rcBand.left += adj_rh;
1698 walk->rcBand.right += adj_rh;
1699 }
1700 else {
1701 walk->rcBand.top += adj_rh;
1702 walk->rcBand.bottom += adj_rh;
1703 }
1704 }
1705 if ((infoPtr->dwStyle & CCS_VERT) ? (x >= adjcx) : (y >= adjcy))
1706 break; /* all done */
1707 }
1708 }
1709 }
1710 }
1711
1712 /* ******* End Phase 2 - split rows till adjustment height full ******* */
1713
1714
1715 /* ******* Start Phase 2a - create array of start and end ******* */
1716 /* indexes by row */
1717
1718 if (infoPtr->uNumRows != origrows) {
1719 if (infoPtr->rows) COMCTL32_Free (infoPtr->rows);
1720 infoPtr->rows = COMCTL32_Alloc (sizeof (REBAR_ROW) * infoPtr->uNumRows);
1721 }
1722
1723 row = 0;
1724 for (i = 0; i < infoPtr->uNumBands; i++) {
1725 lpBand = &infoPtr->bands[i];
1726 if (HIDDENBAND(lpBand)) continue;
1727
1728 if (lpBand->iRow > row) {
1729 row++;
1730 infoPtr->rows[row-1].istartband = i;
1731 }
1732 if (row == 0) {
1733 ERR("P2a bug!!!!!!\n");
1734 }
1735 infoPtr->rows[row-1].iendband = i;
1736 }
1737
1738 for (i = 0; i < infoPtr->uNumRows; i++) {
1739 REBAR_ROW *p;
1740
1741 p = &infoPtr->rows[i];
1742 TRACE("P2a row %d, starts %d, ends %d\n",
1743 i+1, p->istartband, p->iendband);
1744 }
1745
1746 /* ******* End Phase 2a - create array of start and end ******* */
1747 /* indexes by row */
1748
1749
1750 /* ******* Start Phase 2b - adjust all bands for height full ******* */
1751 /* assumes that the following variables contain: */
1752 /* y/x current height/width of all rows */
1753 /* clientcy/clientcx height/width of client area */
1754
1755 if (((infoPtr->dwStyle & CCS_VERT) ? clientcx > x : clientcy > y) &&
1756 infoPtr->uNumBands) {
1757 INT diff, i, iband, j;
1758
1759 diff = (infoPtr->dwStyle & CCS_VERT) ? clientcx - x : clientcy - y;
1760 for (i = infoPtr->uNumRows; i >= 1; i--) {
1761 /* if row has more than 1 band, ignore row */
1762 if (infoPtr->rows[i-1].istartband != infoPtr->rows[i-1].iendband)
1763 continue;
1764 /* point to only band in row */
1765 iband = infoPtr->rows[i-1].istartband;
1766 lpBand = &infoPtr->bands[iband];
1767 if(HIDDENBAND(lpBand)) continue;
1768 if (lpBand->fMask & RBBS_VARIABLEHEIGHT) continue;
1769 if (((INT)lpBand->cyMaxChild < 1) ||
1770 ((INT)lpBand->cyIntegral < 1)) {
1771 if (lpBand->cyMaxChild + lpBand->cyIntegral == 0) continue;
1772 ERR("P2b band %u RBBS_VARIABLEHEIGHT set but cyMax=%d, cyInt=%d\n",
1773 iband, lpBand->cyMaxChild, lpBand->cyIntegral);
1774 continue;
1775 }
1776 /* j is now the maximum height/width in the client area */
1777 j = ((diff / lpBand->cyIntegral) * lpBand->cyIntegral) +
1778 ircBw(lpBand);
1779 if (j > lpBand->cyMaxChild + REBARSPACE(lpBand))
1780 j = lpBand->cyMaxChild + REBARSPACE(lpBand);
1781 diff -= (j - ircBw(lpBand));
1782 if (infoPtr->dwStyle & CCS_VERT)
1783 lpBand->rcBand.right = lpBand->rcBand.left + j;
1784 else
1785 lpBand->rcBand.bottom = lpBand->rcBand.top + j;
1786 TRACE("P2b band %d, row %d changed to (%d,%d)-(%d,%d)\n",
1787 iband, lpBand->iRow,
1788 lpBand->rcBand.left, lpBand->rcBand.top,
1789 lpBand->rcBand.right, lpBand->rcBand.bottom);
1790 if (diff <= 0) break;
1791 }
1792 if (diff < 0) {
1793 ERR("P2b allocated more than available, diff=%d\n", diff);
1794 diff = 0;
1795 }
1796 if (infoPtr->dwStyle & CCS_VERT)
1797 x = clientcx - diff;
1798 else
1799 y = clientcy - diff;
1800 }
1801
1802 /* ******* End Phase 2b - adjust all bands for height full ******* */
1803
1804
1805 /* ******* Start Phase 3 - adjust all bands for width full ******* */
1806
1807 if (infoPtr->uNumBands) {
1808 REBAR_ROW *p;
1809
1810 /* If RBS_BANDBORDERS set then indicate to draw bottom separator */
1811 /* on all bands in all rows but last row. */
1812 /* Also indicate to draw the right separator for each band in */
1813 /* each row but the rightmost band. */
1814 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1815
1816 for(i = 0; i < infoPtr->uNumRows; i++) {
1817 p = &infoPtr->rows[i];
1818 for (j = p->istartband; j <= p->iendband; j++) {
1819 lpBand = &infoPtr->bands[j];
1820 if (HIDDENBAND(lpBand)) continue;
1821 if (j != p->iendband)
1822 lpBand->fDraw |= DRAW_RIGHTSEP;
1823 if (i != infoPtr->uNumRows-1)
1824 lpBand->fDraw |= DRAW_BOTTOMSEP;
1825 }
1826 }
1827 }
1828
1829 /* Distribute the extra space on the horizontal and adjust */
1830 /* all bands in row to same height. */
1831 for (i=1; i<=infoPtr->uNumRows; i++) {
1832 p = &infoPtr->rows[i-1];
1833 mcy = 0;
1834
1835 TRACE("P3 processing row %d, starting band %d, ending band %d\n",
1836 i, p->istartband, p->iendband);
1837
1838 /* Find the largest height of the bands in the row */
1839 for (j = p->istartband; j <= p->iendband; j++) {
1840 lpBand = &infoPtr->bands[j];
1841 if (HIDDENBAND(lpBand)) continue;
1842 if (mcy < ircBw(lpBand))
1843 mcy = ircBw(lpBand);
1844 }
1845
1846 REBAR_AdjustBands (infoPtr, p->istartband, p->iendband,
1847 (infoPtr->dwStyle & CCS_VERT) ?
1848 clientcy : clientcx, mcy);
1849 }
1850
1851 /* Calculate the other rectangles in each band */
1852 if (infoPtr->dwStyle & CCS_VERT) {
1853 REBAR_CalcVertBand (infoPtr, 0, infoPtr->uNumBands,
1854 notify);
1855 }
1856 else {
1857 REBAR_CalcHorzBand (infoPtr, 0, infoPtr->uNumBands,
1858 notify);
1859 }
1860 }
1861
1862 /* ******* End Phase 3 - adjust all bands for width full ******* */
1863
1864 /* now compute size of Rebar itself */
1865 infoPtr->oldSize = infoPtr->calcSize;
1866 if (infoPtr->uNumBands == 0) {
1867 /* we have no bands, so make size the size of client */
1868 x = clientcx;
1869 y = clientcy;
1870 }
1871 if (infoPtr->dwStyle & CCS_VERT) {
1872 infoPtr->calcSize.cx = x;
1873 infoPtr->calcSize.cy = clientcy;
1874 TRACE("vert, notify=%d, x=%d, origheight=%d\n",
1875 notify, x, origheight);
1876 if (notify && (x != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1877 }
1878 else {
1879 infoPtr->calcSize.cx = clientcx;
1880 infoPtr->calcSize.cy = y;
1881 TRACE("horz, notify=%d, y=%d, origheight=%d\n",
1882 notify, y, origheight);
1883 if (notify && (y != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1884 }
1885
1886 REBAR_DumpBand (infoPtr);
1887
1888 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1889
1890 REBAR_ForceResize (infoPtr);
1891}
1892
1893
1894static VOID
1895REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1896 /* Function: This routine evaluates the band specs supplied */
1897 /* by the user and updates the following 5 fields in */
1898 /* the internal band structure: cxHeader, lcx, lcy, hcx, hcy*/
1899{
1900 UINT header=0;
1901 UINT textheight=0;
1902 INT i, nonfixed;
1903 REBAR_BAND *tBand;
1904
1905 lpBand->fStatus = 0;
1906 lpBand->lcx = 0;
1907 lpBand->lcy = 0;
1908 lpBand->ccx = 0;
1909 lpBand->ccy = 0;
1910 lpBand->hcx = 0;
1911 lpBand->hcy = 0;
1912
1913 /* Data comming in from users into the cx... and cy... fields */
1914 /* may be bad, just garbage, because the user never clears */
1915 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1916 /* along if the fields exist in the input area. Here we must */
1917 /* determine if the data is valid. I have no idea how MS does */
1918 /* the validation, but it does because the RB_GETBANDINFO */
1919 /* returns a 0 when I know the sample program passed in an */
1920 /* address. Here I will use the algorithim that if the value */
1921 /* is greater than 65535 then it is bad and replace it with */
1922 /* a zero. Feel free to improve the algorithim. - GA 12/2000 */
1923 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1924 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1925 if (lpBand->cx > 65535) lpBand->cx = 0;
1926 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1927 if (lpBand->cyMaxChild > 65535) lpBand->cyMaxChild = 0;
1928 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1929 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1930 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1931
1932 /* FIXME: probably should only set NEEDS_LAYOUT flag when */
1933 /* values change. Till then always set it. */
1934 TRACE("setting NEEDS_LAYOUT\n");
1935 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1936
1937 /* Header is where the image, text and gripper exist */
1938 /* in the band and preceed the child window. */
1939
1940 /* count number of non-FIXEDSIZE and non-Hidden bands */
1941 nonfixed = 0;
1942 for (i=0; i<infoPtr->uNumBands; i++){
1943 tBand = &infoPtr->bands[i];
1944 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1945 nonfixed++;
1946 }
1947
1948 /* calculate gripper rectangle */
1949 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1950 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1951 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1952 ) {
1953 lpBand->fStatus |= HAS_GRIPPER;
1954 if (infoPtr->dwStyle & CCS_VERT)
1955 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1956 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1957 else
1958 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1959 else
1960 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1961 /* Always have 4 pixels before anything else */
1962 header += REBAR_ALWAYS_SPACE;
1963 }
1964
1965 /* image is visible */
1966 if ((lpBand->fMask & RBBIM_IMAGE) && (infoPtr->himl)) {
1967 lpBand->fStatus |= HAS_IMAGE;
1968 if (infoPtr->dwStyle & CCS_VERT) {
1969 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1970 lpBand->lcy = infoPtr->imageSize.cx + 2;
1971 }
1972 else {
1973 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1974 lpBand->lcy = infoPtr->imageSize.cy + 2;
1975 }
1976 }
1977
1978 /* text is visible */
1979 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText)) {
1980 HDC hdc = GetDC (0);
1981 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1982 SIZE size;
1983
1984 lpBand->fStatus |= HAS_TEXT;
1985 GetTextExtentPoint32W (hdc, lpBand->lpText,
1986 lstrlenW (lpBand->lpText), &size);
1987 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1988 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1989
1990 SelectObject (hdc, hOldFont);
1991 ReleaseDC (0, hdc);
1992 }
1993
1994 /* if no gripper but either image or text, then leave space */
1995 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1996 !(lpBand->fStatus & HAS_GRIPPER)) {
1997 header += REBAR_ALWAYS_SPACE;
1998 }
1999
2000 /* check if user overrode the header value */
2001 if (!(lpBand->fMask & RBBIM_HEADERSIZE))
2002 lpBand->cxHeader = header;
2003
2004
2005 /* Now compute minimum size of child window */
2006 lpBand->offChild.cx = 0;
2007 lpBand->offChild.cy = 0;
2008 lpBand->lcy = textheight;
2009 lpBand->ccy = lpBand->lcy;
2010 if (lpBand->fMask & RBBIM_CHILDSIZE) {
2011 lpBand->lcx = lpBand->cxMinChild;
2012
2013 /* Set the .cy values for CHILDSIZE case */
2014 lpBand->lcy = max(lpBand->lcy, lpBand->cyMinChild);
2015 lpBand->ccy = lpBand->lcy;
2016 lpBand->hcy = lpBand->lcy;
2017 if (lpBand->cyMaxChild != 0xffffffff) {
2018 lpBand->hcy = lpBand->cyMaxChild;
2019 }
2020 if (lpBand->cyChild != 0xffffffff)
2021 lpBand->ccy = max (lpBand->cyChild, lpBand->lcy);
2022
2023 TRACE("_CHILDSIZE\n");
2024 }
2025 if (lpBand->fMask & RBBIM_SIZE) {
2026 lpBand->hcx = max (lpBand->cx-lpBand->cxHeader, lpBand->lcx);
2027 TRACE("_SIZE\n");
2028 }
2029 else
2030 lpBand->hcx = lpBand->lcx;
2031 lpBand->ccx = lpBand->hcx;
2032
2033 /* make ->.cx include header size for _Layout */
2034 lpBand->lcx += lpBand->cxHeader;
2035 lpBand->ccx += lpBand->cxHeader;
2036 lpBand->hcx += lpBand->cxHeader;
2037
2038}
2039
2040static void
2041REBAR_CommonSetupBand (HWND hwnd, LPREBARBANDINFOA lprbbi, REBAR_BAND *lpBand)
2042 /* Function: This routine copies the supplied values from */
2043 /* user input (lprbbi) to the internal band structure. */
2044{
2045 lpBand->fMask |= lprbbi->fMask;
2046
2047 if (lprbbi->fMask & RBBIM_STYLE)
2048 lpBand->fStyle = lprbbi->fStyle;
2049
2050 if (lprbbi->fMask & RBBIM_COLORS) {
2051 lpBand->clrFore = lprbbi->clrFore;
2052 lpBand->clrBack = lprbbi->clrBack;
2053 }
2054
2055 if (lprbbi->fMask & RBBIM_IMAGE)
2056 lpBand->iImage = lprbbi->iImage;
2057
2058 if (lprbbi->fMask & RBBIM_CHILD) {
2059 if (lprbbi->hwndChild) {
2060 lpBand->hwndChild = lprbbi->hwndChild;
2061 lpBand->hwndPrevParent =
2062 SetParent (lpBand->hwndChild, hwnd);
2063 /* below in trace fro WinRAR */
2064 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
2065 /* above in trace fro WinRAR */
2066 }
2067 else {
2068 TRACE("child: %p prev parent: %p\n",
2069 lpBand->hwndChild, lpBand->hwndPrevParent);
2070 lpBand->hwndChild = 0;
2071 lpBand->hwndPrevParent = 0;
2072 }
2073 }
2074
2075 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2076 lpBand->cxMinChild = lprbbi->cxMinChild;
2077 lpBand->cyMinChild = lprbbi->cyMinChild;
2078 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2079 lpBand->cyChild = lprbbi->cyChild;
2080 lpBand->cyMaxChild = lprbbi->cyMaxChild;
2081 lpBand->cyIntegral = lprbbi->cyIntegral;
2082 }
2083 else { /* special case - these should be zeroed out since */
2084 /* RBBIM_CHILDSIZE added these in WIN32_IE >= 0x0400 */
2085 lpBand->cyChild = 0;
2086 lpBand->cyMaxChild = 0;
2087 lpBand->cyIntegral = 0;
2088 }
2089 }
2090
2091 if (lprbbi->fMask & RBBIM_SIZE)
2092 lpBand->cx = lprbbi->cx;
2093
2094 if (lprbbi->fMask & RBBIM_BACKGROUND)
2095 lpBand->hbmBack = lprbbi->hbmBack;
2096
2097 if (lprbbi->fMask & RBBIM_ID)
2098 lpBand->wID = lprbbi->wID;
2099
2100 /* check for additional data */
2101 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2102 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2103 lpBand->cxIdeal = lprbbi->cxIdeal;
2104
2105 if (lprbbi->fMask & RBBIM_LPARAM)
2106 lpBand->lParam = lprbbi->lParam;
2107
2108 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2109 lpBand->cxHeader = lprbbi->cxHeader;
2110 }
2111}
2112
2113static LRESULT
2114REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, RECT *clip)
2115 /* Function: This erases the background rectangle by drawing */
2116 /* each band with its background color (or the default) and */
2117 /* draws each bands right separator if necessary. The row */
2118 /* separators are drawn on the first band of the next row. */
2119{
2120 REBAR_BAND *lpBand;
2121 INT i, oldrow;
2122 HDC hdc = (HDC)wParam;
2123 RECT rect;
2124 COLORREF old = CLR_NONE, new;
2125
2126 oldrow = -1;
2127 for(i=0; i<infoPtr->uNumBands; i++) {
2128 lpBand = &infoPtr->bands[i];
2129 if (HIDDENBAND(lpBand)) continue;
2130
2131 /* draw band separator between rows */
2132 if (lpBand->iRow != oldrow) {
2133 oldrow = lpBand->iRow;
2134 if (lpBand->fDraw & DRAW_BOTTOMSEP) {
2135 RECT rcRowSep;
2136 rcRowSep = lpBand->rcBand;
2137 if (infoPtr->dwStyle & CCS_VERT) {
2138 rcRowSep.right += SEP_WIDTH_SIZE;
2139 rcRowSep.bottom = infoPtr->calcSize.cy;
2140 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
2141 }
2142 else {
2143 rcRowSep.bottom += SEP_WIDTH_SIZE;
2144 rcRowSep.right = infoPtr->calcSize.cx;
2145 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
2146 }
2147 TRACE ("drawing band separator bottom (%d,%d)-(%d,%d)\n",
2148 rcRowSep.left, rcRowSep.top,
2149 rcRowSep.right, rcRowSep.bottom);
2150 }
2151 }
2152
2153 /* draw band separator between bands in a row */
2154 if (lpBand->fDraw & DRAW_RIGHTSEP) {
2155 RECT rcSep;
2156 rcSep = lpBand->rcBand;
2157 if (infoPtr->dwStyle & CCS_VERT) {
2158 rcSep.bottom += SEP_WIDTH_SIZE;
2159 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
2160 }
2161 else {
2162 rcSep.right += SEP_WIDTH_SIZE;
2163 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
2164 }
2165 TRACE("drawing band separator right (%d,%d)-(%d,%d)\n",
2166 rcSep.left, rcSep.top, rcSep.right, rcSep.bottom);
2167 }
2168
2169 /* draw the actual background */
2170 if (lpBand->clrBack != CLR_NONE) {
2171 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
2172 lpBand->clrBack;
2173#if GLATESTING
2174 /* testing only - make background green to see it */
2175 new = RGB(0,128,0);
2176#endif
2177 }
2178 else {
2179 /* In the absence of documentation for Rebar vs. CLR_NONE,
2180 * we will use the default BtnFace color. Note documentation
2181 * exists for Listview and Imagelist.
2182 */
2183 new = infoPtr->clrBtnFace;
2184#if GLATESTING
2185 /* testing only - make background green to see it */
2186 new = RGB(0,128,0);
2187#endif
2188 }
2189 old = SetBkColor (hdc, new);
2190
2191 rect = lpBand->rcBand;
2192 TRACE("%s background color=0x%06lx, band (%d,%d)-(%d,%d), clip (%d,%d)-(%d,%d)\n",
2193 (lpBand->clrBack == CLR_NONE) ? "none" :
2194 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
2195 GetBkColor(hdc),
2196 lpBand->rcBand.left,lpBand->rcBand.top,
2197 lpBand->rcBand.right,lpBand->rcBand.bottom,
2198 clip->left, clip->top,
2199 clip->right, clip->bottom);
2200 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, 0);
2201 if (lpBand->clrBack != CLR_NONE)
2202 SetBkColor (hdc, old);
2203 }
2204 return TRUE;
2205}
2206
2207static void
2208REBAR_InternalHitTest (REBAR_INFO *infoPtr, LPPOINT lpPt, UINT *pFlags, INT *pBand)
2209{
2210 REBAR_BAND *lpBand;
2211 RECT rect;
2212 INT iCount;
2213
2214 GetClientRect (infoPtr->hwndSelf, &rect);
2215
2216 *pFlags = RBHT_NOWHERE;
2217 if (PtInRect (&rect, *lpPt))
2218 {
2219 if (infoPtr->uNumBands == 0) {
2220 *pFlags = RBHT_NOWHERE;
2221 if (pBand)
2222 *pBand = -1;
2223 TRACE("NOWHERE\n");
2224 return;
2225 }
2226 else {
2227 /* somewhere inside */
2228 infoPtr->ihitBand = -1;
2229 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
2230 lpBand = &infoPtr->bands[iCount];
2231 if (HIDDENBAND(lpBand)) continue;
2232 if (PtInRect (&lpBand->rcBand, *lpPt)) {
2233 if (pBand)
2234 *pBand = iCount;
2235 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
2236 *pFlags = RBHT_GRABBER;
2237 infoPtr->ihitBand = iCount;
2238 TRACE("ON GRABBER %d\n", iCount);
2239 return;
2240 }
2241 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
2242 *pFlags = RBHT_CAPTION;
2243 TRACE("ON CAPTION %d\n", iCount);
2244 return;
2245 }
2246 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2247 *pFlags = RBHT_CAPTION;
2248 TRACE("ON CAPTION %d\n", iCount);
2249 return;
2250 }
2251 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2252 *pFlags = RBHT_CLIENT;
2253 TRACE("ON CLIENT %d\n", iCount);
2254 return;
2255 }
2256 else {
2257 *pFlags = RBHT_NOWHERE;
2258 TRACE("NOWHERE %d\n", iCount);
2259 return;
2260 }
2261 }
2262 }
2263
2264 *pFlags = RBHT_NOWHERE;
2265 if (pBand)
2266 *pBand = -1;
2267
2268 TRACE("NOWHERE\n");
2269 return;
2270 }
2271 }
2272 else {
2273 *pFlags = RBHT_NOWHERE;
2274 if (pBand)
2275 *pBand = -1;
2276 TRACE("NOWHERE\n");
2277 return;
2278 }
2279
2280 TRACE("flags=0x%X\n", *pFlags);
2281 return;
2282}
2283
2284
2285static INT
2286REBAR_Shrink (REBAR_INFO *infoPtr, REBAR_BAND *band, INT movement, INT i)
2287 /* Function: This attempts to shrink the given band by the */
2288 /* the amount in "movement". A shrink to the left is indi- */
2289 /* cated by "movement" being negative. "i" is merely the */
2290 /* band index for trace messages. */
2291{
2292 INT Leadjust, Readjust, avail, ret;
2293
2294 /* Note: a left drag is indicated by "movement" being negative. */
2295 /* Similarly, a right drag is indicated by "movement" */
2296 /* being positive. "movement" should never be 0, but if */
2297 /* it is then the band does not move. */
2298
2299 avail = rcBw(band) - band->lcx;
2300
2301 /* now compute the Left End adjustment factor and Right End */
2302 /* adjustment factor. They may be different if shrinking. */
2303 if (avail <= 0) {
2304 /* if this band is not shrinkable, then just move it */
2305 Leadjust = Readjust = movement;
2306 ret = movement;
2307 }
2308 else {
2309 if (movement < 0) {
2310 /* Drag to left */
2311 if (avail <= abs(movement)) {
2312 Readjust = movement;
2313 Leadjust = movement + avail;
2314 ret = Leadjust;
2315 }
2316 else {
2317 Readjust = movement;
2318 Leadjust = 0;
2319 ret = 0;
2320 }
2321 }
2322 else {
2323 /* Drag to right */
2324 if (avail <= abs(movement)) {
2325 Leadjust = movement;
2326 Readjust = movement - avail;
2327 ret = Readjust;
2328 }
2329 else {
2330 Leadjust = movement;
2331 Readjust = 0;
2332 ret = 0;
2333 }
2334 }
2335 }
2336
2337 /* Reasonability Check */
2338 if (rcBlt(band) + Leadjust < 0) {
2339 ERR("adjustment will fail, band %d: left=%d, right=%d, move=%d, rtn=%d\n",
2340 i, Leadjust, Readjust, movement, ret);
2341 }
2342
2343 LEADJ(band, Leadjust);
2344 READJ(band, Readjust);
2345
2346 TRACE("band %d: left=%d, right=%d, move=%d, rtn=%d, rcBand=(%d,%d)-(%d,%d)\n",
2347 i, Leadjust, Readjust, movement, ret,
2348 band->rcBand.left, band->rcBand.top,
2349 band->rcBand.right, band->rcBand.bottom);
2350 return ret;
2351}
2352
2353
2354static void
2355REBAR_HandleLRDrag (REBAR_INFO *infoPtr, POINTS *ptsmove)
2356 /* Function: This will implement the functionality of a */
2357 /* Gripper drag within a row. It will not implement "out- */
2358 /* of-row" drags. (They are detected and handled in */
2359 /* REBAR_MouseMove.) */
2360 /* **** FIXME Switching order of bands in a row not **** */
2361 /* **** yet implemented. **** */
2362{
2363 REBAR_BAND *hitBand, *band, *mindBand, *maxdBand;
2364 RECT newrect;
2365 INT imindBand = -1, imaxdBand, ihitBand, i, movement;
2366 INT RHeaderSum = 0, LHeaderSum = 0;
2367 INT compress;
2368
2369 /* on first significant mouse movement, issue notify */
2370
2371 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
2372 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
2373 /* Notify returned TRUE - abort drag */
2374 infoPtr->dragStart.x = 0;
2375 infoPtr->dragStart.y = 0;
2376 infoPtr->dragNow = infoPtr->dragStart;
2377 infoPtr->ihitBand = -1;
2378 ReleaseCapture ();
2379 return ;
2380 }
2381 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
2382 }
2383
2384 ihitBand = infoPtr->ihitBand;
2385 hitBand = &infoPtr->bands[ihitBand];
2386 imaxdBand = ihitBand; /* to suppress warning message */
2387
2388 /* find all the bands in the row of the one whose Gripper was seized */
2389 for (i=0; i<infoPtr->uNumBands; i++) {
2390 band = &infoPtr->bands[i];
2391 if (HIDDENBAND(band)) continue;
2392 if (band->iRow == hitBand->iRow) {
2393 imaxdBand = i;
2394 if (imindBand == -1) imindBand = i;
2395 /* minimum size of each band is size of header plus */
2396 /* size of minimum child plus offset of child from header plus */
2397 /* a one to separate each band. */
2398 if (i < ihitBand)
2399 LHeaderSum += (band->lcx + SEP_WIDTH);
2400 else
2401 RHeaderSum += (band->lcx + SEP_WIDTH);
2402
2403 }
2404 }
2405 if (RHeaderSum) RHeaderSum -= SEP_WIDTH; /* no separator afterlast band */
2406
2407 mindBand = &infoPtr->bands[imindBand];
2408 maxdBand = &infoPtr->bands[imaxdBand];
2409
2410 if (imindBand == imaxdBand) return; /* nothing to drag agains */
2411 if (imindBand == ihitBand) return; /* first band in row, cant drag */
2412
2413 /* limit movement to inside adjustable bands - Left */
2414 if ( (ptsmove->x < mindBand->rcBand.left) ||
2415 (ptsmove->x > maxdBand->rcBand.right) ||
2416 (ptsmove->y < mindBand->rcBand.top) ||
2417 (ptsmove->y > maxdBand->rcBand.bottom))
2418 return; /* should swap bands */
2419
2420 if (infoPtr->dwStyle & CCS_VERT)
2421 movement = ptsmove->y - ((hitBand->rcBand.top+REBAR_PRE_GRIPPER) -
2422 infoPtr->ihitoffset);
2423 else
2424 movement = ptsmove->x - ((hitBand->rcBand.left+REBAR_PRE_GRIPPER) -
2425 infoPtr->ihitoffset);
2426 infoPtr->dragNow = *ptsmove;
2427
2428 TRACE("before: movement=%d (%d,%d), imindBand=%d, ihitBand=%d, imaxdBand=%d, LSum=%d, RSum=%d\n",
2429 movement, ptsmove->x, ptsmove->y, imindBand, ihitBand,
2430 imaxdBand, LHeaderSum, RHeaderSum);
2431 REBAR_DumpBand (infoPtr);
2432
2433 if (movement < 0) {
2434
2435 /* *** Drag left/up *** */
2436 compress = rcBlt(hitBand) - rcBlt(mindBand) -
2437 LHeaderSum;
2438 if (compress < abs(movement)) {
2439 TRACE("limiting left drag, was %d changed to %d\n",
2440 movement, -compress);
2441 movement = -compress;
2442 }
2443
2444 for (i=ihitBand; i>=imindBand; i--) {
2445 band = &infoPtr->bands[i];
2446 if (HIDDENBAND(band)) continue;
2447 if (i == ihitBand) {
2448 LEADJ(band, movement);
2449 }
2450 else
2451 movement = REBAR_Shrink (infoPtr, band, movement, i);
2452 band->ccx = rcBw(band);
2453 }
2454 }
2455 else {
2456 BOOL first = TRUE;
2457
2458 /* *** Drag right/down *** */
2459 compress = rcBrb(maxdBand) - rcBlt(hitBand) -
2460 RHeaderSum;
2461 if (compress < abs(movement)) {
2462 TRACE("limiting right drag, was %d changed to %d\n",
2463 movement, compress);
2464 movement = compress;
2465 }
2466 for (i=ihitBand-1; i<=imaxdBand; i++) {
2467 band = &infoPtr->bands[i];
2468 if (HIDDENBAND(band)) continue;
2469 if (first) {
2470 first = FALSE;
2471 READJ(band, movement);
2472 }
2473 else
2474 movement = REBAR_Shrink (infoPtr, band, movement, i);
2475 band->ccx = rcBw(band);
2476 }
2477 }
2478
2479 /* recompute all rectangles */
2480 if (infoPtr->dwStyle & CCS_VERT) {
2481 REBAR_CalcVertBand (infoPtr, imindBand, imaxdBand+1,
2482 FALSE);
2483 }
2484 else {
2485 REBAR_CalcHorzBand (infoPtr, imindBand, imaxdBand+1,
2486 FALSE);
2487 }
2488
2489 TRACE("bands after adjustment, see band # %d, %d\n",
2490 imindBand, imaxdBand);
2491 REBAR_DumpBand (infoPtr);
2492
2493 SetRect (&newrect,
2494 mindBand->rcBand.left,
2495 mindBand->rcBand.top,
2496 maxdBand->rcBand.right,
2497 maxdBand->rcBand.bottom);
2498
2499 REBAR_MoveChildWindows (infoPtr, imindBand, imaxdBand+1);
2500
2501 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
2502 UpdateWindow (infoPtr->hwndSelf);
2503
2504}
2505
2506
2507
2508/* << REBAR_BeginDrag >> */
2509
2510
2511static LRESULT
2512REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2513{
2514 UINT uBand = (UINT)wParam;
2515 HWND childhwnd = 0;
2516 REBAR_BAND *lpBand;
2517
2518 if (uBand >= infoPtr->uNumBands)
2519 return FALSE;
2520
2521 TRACE("deleting band %u!\n", uBand);
2522 lpBand = &infoPtr->bands[uBand];
2523 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2524
2525 if (infoPtr->uNumBands == 1) {
2526 TRACE(" simple delete!\n");
2527 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2528 childhwnd = lpBand->hwndChild;
2529 COMCTL32_Free (infoPtr->bands);
2530 infoPtr->bands = NULL;
2531 infoPtr->uNumBands = 0;
2532 }
2533 else {
2534 REBAR_BAND *oldBands = infoPtr->bands;
2535 TRACE("complex delete! [uBand=%u]\n", uBand);
2536
2537 if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2538 childhwnd = lpBand->hwndChild;
2539
2540 infoPtr->uNumBands--;
2541 infoPtr->bands = COMCTL32_Alloc (sizeof (REBAR_BAND) * infoPtr->uNumBands);
2542 if (uBand > 0) {
2543 memcpy (&infoPtr->bands[0], &oldBands[0],
2544 uBand * sizeof(REBAR_BAND));
2545 }
2546
2547 if (uBand < infoPtr->uNumBands) {
2548 memcpy (&infoPtr->bands[uBand], &oldBands[uBand+1],
2549 (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
2550 }
2551
2552 COMCTL32_Free (oldBands);
2553 }
2554
2555 if (childhwnd)
2556 ShowWindow (childhwnd, SW_HIDE);
2557
2558 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2559
2560 /* if only 1 band left the re-validate to possible eliminate gripper */
2561 if (infoPtr->uNumBands == 1)
2562 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2563
2564 TRACE("setting NEEDS_LAYOUT\n");
2565 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
2566 infoPtr->fStatus |= RESIZE_ANYHOW;
2567 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
2568
2569 return TRUE;
2570}
2571
2572
2573/* << REBAR_DragMove >> */
2574/* << REBAR_EndDrag >> */
2575
2576
2577static LRESULT
2578REBAR_GetBandBorders (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2579{
2580 LPRECT lpRect = (LPRECT)lParam;
2581 REBAR_BAND *lpBand;
2582
2583 if (!lParam)
2584 return 0;
2585 if ((UINT)wParam >= infoPtr->uNumBands)
2586 return 0;
2587
2588 lpBand = &infoPtr->bands[(UINT)wParam];
2589
2590 /* FIXME - the following values were determined by experimentation */
2591 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2592 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2593 /* difference in size of the control area with and without the */
2594 /* style. - GA */
2595 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2596 if (infoPtr->dwStyle & CCS_VERT) {
2597 lpRect->left = 1;
2598 lpRect->top = lpBand->cxHeader + 4;
2599 lpRect->right = 1;
2600 lpRect->bottom = 0;
2601 }
2602 else {
2603 lpRect->left = lpBand->cxHeader + 4;
2604 lpRect->top = 1;
2605 lpRect->right = 0;
2606 lpRect->bottom = 1;
2607 }
2608 }
2609 else {
2610 lpRect->left = lpBand->cxHeader;
2611 }
2612 return 0;
2613}
2614
2615
2616inline static LRESULT
2617REBAR_GetBandCount (REBAR_INFO *infoPtr)
2618{
2619 TRACE("band count %u!\n", infoPtr->uNumBands);
2620
2621 return infoPtr->uNumBands;
2622}
2623
2624
2625static LRESULT
2626REBAR_GetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2627{
2628 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2629 REBAR_BAND *lpBand;
2630
2631 if (lprbbi == NULL)
2632 return FALSE;
2633 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
2634 return FALSE;
2635 if ((UINT)wParam >= infoPtr->uNumBands)
2636 return FALSE;
2637
2638 TRACE("index %u\n", (UINT)wParam);
2639
2640 /* copy band information */
2641 lpBand = &infoPtr->bands[(UINT)wParam];
2642
2643 if (lprbbi->fMask & RBBIM_STYLE)
2644 lprbbi->fStyle = lpBand->fStyle;
2645
2646 if (lprbbi->fMask & RBBIM_COLORS) {
2647 lprbbi->clrFore = lpBand->clrFore;
2648 lprbbi->clrBack = lpBand->clrBack;
2649 if (lprbbi->clrBack == CLR_DEFAULT)
2650 lprbbi->clrBack = infoPtr->clrBtnFace;
2651 }
2652
2653 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2654 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2655 {
2656 if (!WideCharToMultiByte( CP_ACP, 0, lpBand->lpText, -1,
2657 lprbbi->lpText, lprbbi->cch, NULL, NULL ))
2658 lprbbi->lpText[lprbbi->cch-1] = 0;
2659 }
2660 else
2661 *lprbbi->lpText = 0;
2662 }
2663
2664 if (lprbbi->fMask & RBBIM_IMAGE) {
2665 if (lpBand->fMask & RBBIM_IMAGE)
2666 lprbbi->iImage = lpBand->iImage;
2667 else
2668 lprbbi->iImage = -1;
2669 }
2670
2671 if (lprbbi->fMask & RBBIM_CHILD)
2672 lprbbi->hwndChild = lpBand->hwndChild;
2673
2674 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2675 lprbbi->cxMinChild = lpBand->cxMinChild;
2676 lprbbi->cyMinChild = lpBand->cyMinChild;
2677 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2678 lprbbi->cyChild = lpBand->cyChild;
2679 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2680 lprbbi->cyIntegral = lpBand->cyIntegral;
2681 }
2682 }
2683
2684 if (lprbbi->fMask & RBBIM_SIZE)
2685 lprbbi->cx = lpBand->cx;
2686
2687 if (lprbbi->fMask & RBBIM_BACKGROUND)
2688 lprbbi->hbmBack = lpBand->hbmBack;
2689
2690 if (lprbbi->fMask & RBBIM_ID)
2691 lprbbi->wID = lpBand->wID;
2692
2693 /* check for additional data */
2694 if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2695 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2696 lprbbi->cxIdeal = lpBand->cxIdeal;
2697
2698 if (lprbbi->fMask & RBBIM_LPARAM)
2699 lprbbi->lParam = lpBand->lParam;
2700
2701 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2702 lprbbi->cxHeader = lpBand->cxHeader;
2703 }
2704
2705 REBAR_DumpBandInfo (lprbbi);
2706
2707 return TRUE;
2708}
2709
2710
2711static LRESULT
2712REBAR_GetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2713{
2714 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2715 REBAR_BAND *lpBand;
2716
2717 if (lprbbi == NULL)
2718 return FALSE;
2719 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
2720 return FALSE;
2721 if ((UINT)wParam >= infoPtr->uNumBands)
2722 return FALSE;
2723
2724 TRACE("index %u\n", (UINT)wParam);
2725
2726 /* copy band information */
2727 lpBand = &infoPtr->bands[(UINT)wParam];
2728
2729 if (lprbbi->fMask & RBBIM_STYLE)
2730 lprbbi->fStyle = lpBand->fStyle;
2731
2732 if (lprbbi->fMask & RBBIM_COLORS) {
2733 lprbbi->clrFore = lpBand->clrFore;
2734 lprbbi->clrBack = lpBand->clrBack;
2735 if (lprbbi->clrBack == CLR_DEFAULT)
2736 lprbbi->clrBack = infoPtr->clrBtnFace;
2737 }
2738
2739 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2740 if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2741 lstrcpynW (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
2742 else
2743 *lprbbi->lpText = 0;
2744 }
2745
2746 if (lprbbi->fMask & RBBIM_IMAGE) {
2747 if (lpBand->fMask & RBBIM_IMAGE)
2748 lprbbi->iImage = lpBand->iImage;
2749 else
2750 lprbbi->iImage = -1;
2751 }
2752
2753 if (lprbbi->fMask & RBBIM_CHILD)
2754 lprbbi->hwndChild = lpBand->hwndChild;
2755
2756 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2757 lprbbi->cxMinChild = lpBand->cxMinChild;
2758 lprbbi->cyMinChild = lpBand->cyMinChild;
2759 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2760 lprbbi->cyChild = lpBand->cyChild;
2761 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2762 lprbbi->cyIntegral = lpBand->cyIntegral;
2763 }
2764 }
2765
2766 if (lprbbi->fMask & RBBIM_SIZE)
2767 lprbbi->cx = lpBand->cx;
2768
2769 if (lprbbi->fMask & RBBIM_BACKGROUND)
2770 lprbbi->hbmBack = lpBand->hbmBack;
2771
2772 if (lprbbi->fMask & RBBIM_ID)
2773 lprbbi->wID = lpBand->wID;
2774
2775 /* check for additional data */
2776 if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2777 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2778 lprbbi->cxIdeal = lpBand->cxIdeal;
2779
2780 if (lprbbi->fMask & RBBIM_LPARAM)
2781 lprbbi->lParam = lpBand->lParam;
2782
2783 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2784 lprbbi->cxHeader = lpBand->cxHeader;
2785 }
2786
2787 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
2788
2789 return TRUE;
2790}
2791
2792
2793static LRESULT
2794REBAR_GetBarHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2795{
2796 INT nHeight;
2797
2798 nHeight = (infoPtr->dwStyle & CCS_VERT) ? infoPtr->calcSize.cx : infoPtr->calcSize.cy;
2799
2800 TRACE("height = %d\n", nHeight);
2801
2802 return nHeight;
2803}
2804
2805
2806static LRESULT
2807REBAR_GetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2808{
2809 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
2810
2811 if (lpInfo == NULL)
2812 return FALSE;
2813
2814 if (lpInfo->cbSize < sizeof (REBARINFO))
2815 return FALSE;
2816
2817 TRACE("getting bar info!\n");
2818
2819 if (infoPtr->himl) {
2820 lpInfo->himl = infoPtr->himl;
2821 lpInfo->fMask |= RBIM_IMAGELIST;
2822 }
2823
2824 return TRUE;
2825}
2826
2827
2828inline static LRESULT
2829REBAR_GetBkColor (REBAR_INFO *infoPtr)
2830{
2831 COLORREF clr = infoPtr->clrBk;
2832
2833 if (clr == CLR_DEFAULT)
2834 clr = infoPtr->clrBtnFace;
2835
2836 TRACE("background color 0x%06lx!\n", clr);
2837
2838 return clr;
2839}
2840
2841
2842/* << REBAR_GetColorScheme >> */
2843/* << REBAR_GetDropTarget >> */
2844
2845
2846static LRESULT
2847REBAR_GetPalette (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2848{
2849 FIXME("empty stub!\n");
2850
2851 return 0;
2852}
2853
2854
2855static LRESULT
2856REBAR_GetRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2857{
2858 INT iBand = (INT)wParam;
2859 LPRECT lprc = (LPRECT)lParam;
2860 REBAR_BAND *lpBand;
2861
2862 if ((iBand < 0) && ((UINT)iBand >= infoPtr->uNumBands))
2863 return FALSE;
2864 if (!lprc)
2865 return FALSE;
2866
2867 lpBand = &infoPtr->bands[iBand];
2868 CopyRect (lprc, &lpBand->rcBand);
2869
2870 TRACE("band %d, (%d,%d)-(%d,%d)\n", iBand,
2871 lprc->left, lprc->top, lprc->right, lprc->bottom);
2872
2873 return TRUE;
2874}
2875
2876
2877inline static LRESULT
2878REBAR_GetRowCount (REBAR_INFO *infoPtr)
2879{
2880 TRACE("%u\n", infoPtr->uNumRows);
2881
2882 return infoPtr->uNumRows;
2883}
2884
2885
2886static LRESULT
2887REBAR_GetRowHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2888{
2889 INT iRow = (INT)wParam;
2890 int ret = 0;
2891 int i, j = 0;
2892 REBAR_BAND *lpBand;
2893
2894 for (i=0; i<infoPtr->uNumBands; i++) {
2895 lpBand = &infoPtr->bands[i];
2896 if (HIDDENBAND(lpBand)) continue;
2897 if (lpBand->iRow != iRow) continue;
2898 if (infoPtr->dwStyle & CCS_VERT)
2899 j = lpBand->rcBand.right - lpBand->rcBand.left;
2900 else
2901 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2902 if (j > ret) ret = j;
2903 }
2904
2905 TRACE("row %d, height %d\n", iRow, ret);
2906
2907 return ret;
2908}
2909
2910
2911inline static LRESULT
2912REBAR_GetTextColor (REBAR_INFO *infoPtr)
2913{
2914 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
2915
2916 return infoPtr->clrText;
2917}
2918
2919
2920inline static LRESULT
2921REBAR_GetToolTips (REBAR_INFO *infoPtr)
2922{
2923 return (LRESULT)infoPtr->hwndToolTip;
2924}
2925
2926
2927inline static LRESULT
2928REBAR_GetUnicodeFormat (REBAR_INFO *infoPtr)
2929{
2930 TRACE("%s hwnd=%p\n",
2931 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2932
2933 return infoPtr->bUnicode;
2934}
2935
2936
2937inline static LRESULT
2938REBAR_GetVersion (REBAR_INFO *infoPtr)
2939{
2940 TRACE("version %d\n", infoPtr->iVersion);
2941 return infoPtr->iVersion;
2942}
2943
2944
2945static LRESULT
2946REBAR_HitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2947{
2948 LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
2949
2950 if (!lprbht)
2951 return -1;
2952
2953 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2954
2955 return lprbht->iBand;
2956}
2957
2958
2959static LRESULT
2960REBAR_IdToIndex (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2961{
2962 UINT i;
2963
2964 if (infoPtr == NULL)
2965 return -1;
2966
2967 if (infoPtr->uNumBands < 1)
2968 return -1;
2969
2970 for (i = 0; i < infoPtr->uNumBands; i++) {
2971 if (infoPtr->bands[i].wID == (UINT)wParam) {
2972 TRACE("id %u is band %u found!\n", (UINT)wParam, i);
2973 return i;
2974 }
2975 }
2976
2977 TRACE("id %u is not found\n", (UINT)wParam);
2978 return -1;
2979}
2980
2981
2982static LRESULT
2983REBAR_InsertBandA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2984{
2985 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2986 UINT uIndex = (UINT)wParam;
2987 REBAR_BAND *lpBand;
2988
2989 if (infoPtr == NULL)
2990 return FALSE;
2991 if (lprbbi == NULL)
2992 return FALSE;
2993 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
2994 return FALSE;
2995
2996 /* trace the index as signed to see the -1 */
2997 TRACE("insert band at %d!\n", (INT)uIndex);
2998 REBAR_DumpBandInfo (lprbbi);
2999
3000 if (infoPtr->uNumBands == 0) {
3001 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
3002 uIndex = 0;
3003 }
3004 else {
3005 REBAR_BAND *oldBands = infoPtr->bands;
3006 infoPtr->bands =
3007 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3008 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3009 uIndex = infoPtr->uNumBands;
3010
3011 /* pre insert copy */
3012 if (uIndex > 0) {
3013 memcpy (&infoPtr->bands[0], &oldBands[0],
3014 uIndex * sizeof(REBAR_BAND));
3015 }
3016
3017 /* post copy */
3018 if (uIndex < infoPtr->uNumBands - 1) {
3019 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3020 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
3021 }
3022
3023 COMCTL32_Free (oldBands);
3024 }
3025
3026 infoPtr->uNumBands++;
3027
3028 TRACE("index %u!\n", uIndex);
3029
3030 /* initialize band (infoPtr->bands[uIndex])*/
3031 lpBand = &infoPtr->bands[uIndex];
3032 lpBand->fMask = 0;
3033 lpBand->fStatus = 0;
3034 lpBand->clrFore = infoPtr->clrText;
3035 lpBand->clrBack = infoPtr->clrBk;
3036 lpBand->hwndChild = 0;
3037 lpBand->hwndPrevParent = 0;
3038
3039 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3040 lpBand->lpText = NULL;
3041 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3042 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3043 if (len > 1) {
3044 lpBand->lpText = (LPWSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
3045 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3046 }
3047 }
3048
3049 REBAR_ValidateBand (infoPtr, lpBand);
3050 /* On insert of second band, revalidate band 1 to possible add gripper */
3051 if (infoPtr->uNumBands == 2)
3052 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3053
3054 REBAR_DumpBand (infoPtr);
3055
3056 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3057 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3058
3059 return TRUE;
3060}
3061
3062
3063static LRESULT
3064REBAR_InsertBandW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3065{
3066 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3067 UINT uIndex = (UINT)wParam;
3068 REBAR_BAND *lpBand;
3069
3070 if (infoPtr == NULL)
3071 return FALSE;
3072 if (lprbbi == NULL)
3073 return FALSE;
3074 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
3075 return FALSE;
3076
3077 /* trace the index as signed to see the -1 */
3078 TRACE("insert band at %d!\n", (INT)uIndex);
3079 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3080
3081 if (infoPtr->uNumBands == 0) {
3082 infoPtr->bands = (REBAR_BAND *)COMCTL32_Alloc (sizeof (REBAR_BAND));
3083 uIndex = 0;
3084 }
3085 else {
3086 REBAR_BAND *oldBands = infoPtr->bands;
3087 infoPtr->bands =
3088 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3089 if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3090 uIndex = infoPtr->uNumBands;
3091
3092 /* pre insert copy */
3093 if (uIndex > 0) {
3094 memcpy (&infoPtr->bands[0], &oldBands[0],
3095 uIndex * sizeof(REBAR_BAND));
3096 }
3097
3098 /* post copy */
3099 if (uIndex < infoPtr->uNumBands - 1) {
3100 memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3101 (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
3102 }
3103
3104 COMCTL32_Free (oldBands);
3105 }
3106
3107 infoPtr->uNumBands++;
3108
3109 TRACE("index %u!\n", uIndex);
3110
3111 /* initialize band (infoPtr->bands[uIndex])*/
3112 lpBand = &infoPtr->bands[uIndex];
3113 lpBand->fMask = 0;
3114 lpBand->fStatus = 0;
3115 lpBand->clrFore = infoPtr->clrText;
3116 lpBand->clrBack = infoPtr->clrBk;
3117 lpBand->hwndChild = 0;
3118 lpBand->hwndPrevParent = 0;
3119
3120 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3121 lpBand->lpText = NULL;
3122 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3123 INT len = lstrlenW (lprbbi->lpText);
3124 if (len > 0) {
3125 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
3126 strcpyW (lpBand->lpText, lprbbi->lpText);
3127 }
3128 }
3129
3130 REBAR_ValidateBand (infoPtr, lpBand);
3131 /* On insert of second band, revalidate band 1 to possible add gripper */
3132 if (infoPtr->uNumBands == 2)
3133 REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3134
3135 REBAR_DumpBand (infoPtr);
3136
3137 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3138 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3139
3140 return TRUE;
3141}
3142
3143
3144static LRESULT
3145REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3146{
3147 REBAR_BAND *lpBand;
3148 UINT uBand = (UINT) wParam;
3149
3150 /* Validate */
3151 if ((infoPtr->uNumBands == 0) ||
3152 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3153 /* error !!! */
3154 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
3155 (INT)uBand, infoPtr->uNumBands);
3156 return FALSE;
3157 }
3158
3159 lpBand = &infoPtr->bands[uBand];
3160
3161 if (lParam && (lpBand->fMask & RBBIM_IDEALSIZE)) {
3162 /* handle setting ideal size */
3163 lpBand->ccx = lpBand->cxIdeal;
3164 }
3165 else {
3166 /* handle setting to max */
3167 FIXME("(uBand = %u fIdeal = %s) case not coded\n",
3168 (UINT)wParam, lParam ? "TRUE" : "FALSE");
3169 return FALSE;
3170 }
3171
3172 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3173 REBAR_Layout (infoPtr, 0, TRUE, TRUE);
3174 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
3175
3176 return TRUE;
3177
3178}
3179
3180
3181static LRESULT
3182REBAR_MinimizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3183{
3184 REBAR_BAND *band, *lpBand;
3185 UINT uBand = (UINT) wParam;
3186 RECT newrect;
3187 INT imindBand, imaxdBand, iprevBand, startBand, endBand;
3188 INT movement, i;
3189
3190 /* A "minimize" band is equivalent to "dragging" the gripper
3191 * of than band to the right till the band is only the size
3192 * of the cxHeader.
3193 */
3194
3195 /* Validate */
3196 if ((infoPtr->uNumBands == 0) ||
3197 ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3198 /* error !!! */
3199 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
3200 (INT)uBand, infoPtr->uNumBands);
3201 return FALSE;
3202 }
3203
3204 /* compute amount of movement and validate */
3205 lpBand = &infoPtr->bands[uBand];
3206
3207 if (infoPtr->dwStyle & CCS_VERT)
3208 movement = lpBand->rcBand.bottom - lpBand->rcBand.top -
3209 lpBand->cxHeader;
3210 else
3211 movement = lpBand->rcBand.right - lpBand->rcBand.left -
3212 lpBand->cxHeader;
3213 if (movement < 0) {
3214 ERR("something is wrong, band=(%d,%d)-(%d,%d), cxheader=%d\n",
3215 lpBand->rcBand.left, lpBand->rcBand.top,
3216 lpBand->rcBand.right, lpBand->rcBand.bottom,
3217 lpBand->cxHeader);
3218 return FALSE;
3219 }
3220
3221 imindBand = -1;
3222 imaxdBand = -1;
3223 iprevBand = -1; /* to suppress warning message */
3224
3225 /* find the first band in row of the one whose is being minimized */
3226 for (i=0; i<infoPtr->uNumBands; i++) {
3227 band = &infoPtr->bands[i];
3228 if (HIDDENBAND(band)) continue;
3229 if (band->iRow == lpBand->iRow) {
3230 imaxdBand = i;
3231 if (imindBand == -1) imindBand = i;
3232 }
3233 }
3234
3235 /* if the selected band is first in row then need to expand */
3236 /* next visible band */
3237 if (imindBand == uBand) {
3238 band = NULL;
3239 movement = -movement;
3240 /* find the first visible band to the right of the selected band */
3241 for (i=uBand+1; i<=imaxdBand; i++) {
3242 band = &infoPtr->bands[i];
3243 if (!HIDDENBAND(band)) {
3244 iprevBand = i;
3245 LEADJ(band, movement);
3246 band->ccx = rcBw(band);
3247 break;
3248 }
3249 }
3250 /* what case is this */
3251 if (iprevBand == -1) {
3252 ERR("no previous visible band\n");
3253 return FALSE;
3254 }
3255 startBand = uBand;
3256 endBand = iprevBand;
3257 SetRect (&newrect,
3258 lpBand->rcBand.left,
3259 lpBand->rcBand.top,
3260 band->rcBand.right,
3261 band->rcBand.bottom);
3262 }
3263 /* otherwise expand previous visible band */
3264 else {
3265 band = NULL;
3266 /* find the first visible band to the left of the selected band */
3267 for (i=uBand-1; i>=imindBand; i--) {
3268 band = &infoPtr->bands[i];
3269 if (!HIDDENBAND(band)) {
3270 iprevBand = i;
3271 READJ(band, movement);
3272 band->ccx = rcBw(band);
3273 break;
3274 }
3275 }
3276 /* what case is this */
3277 if (iprevBand == -1) {
3278 ERR("no previous visible band\n");
3279 return FALSE;
3280 }
3281 startBand = iprevBand;
3282 endBand = uBand;
3283 SetRect (&newrect,
3284 band->rcBand.left,
3285 band->rcBand.top,
3286 lpBand->rcBand.right,
3287 lpBand->rcBand.bottom);
3288 }
3289
3290 REBAR_Shrink (infoPtr, lpBand, movement, uBand);
3291
3292 /* recompute all rectangles */
3293 if (infoPtr->dwStyle & CCS_VERT) {
3294 REBAR_CalcVertBand (infoPtr, startBand, endBand+1,
3295 FALSE);
3296 }
3297 else {
3298 REBAR_CalcHorzBand (infoPtr, startBand, endBand+1,
3299 FALSE);
3300 }
3301
3302 TRACE("bands after minimize, see band # %d, %d\n",
3303 startBand, endBand);
3304 REBAR_DumpBand (infoPtr);
3305
3306 REBAR_MoveChildWindows (infoPtr, startBand, endBand+1);
3307
3308 InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
3309 UpdateWindow (infoPtr->hwndSelf);
3310 return FALSE;
3311}
3312
3313
3314static LRESULT
3315REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3316{
3317 REBAR_BAND *oldBands = infoPtr->bands;
3318 REBAR_BAND holder;
3319 UINT uFrom = (UINT)wParam;
3320 UINT uTo = (UINT)lParam;
3321
3322 /* Validate */
3323 if ((infoPtr->uNumBands == 0) ||
3324 ((INT)uFrom < 0) || (uFrom >= infoPtr->uNumBands) ||
3325 ((INT)uTo < 0) || (uTo >= infoPtr->uNumBands)) {
3326 /* error !!! */
3327 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
3328 (INT)uFrom, (INT)uTo, infoPtr->uNumBands);
3329 return FALSE;
3330 }
3331
3332 /* save one to be moved */
3333 memcpy (&holder, &oldBands[uFrom], sizeof(REBAR_BAND));
3334
3335 /* close up rest of bands (psuedo delete) */
3336 if (uFrom < infoPtr->uNumBands - 1) {
3337 memcpy (&oldBands[uFrom], &oldBands[uFrom+1],
3338 (infoPtr->uNumBands - uFrom - 1) * sizeof(REBAR_BAND));
3339 }
3340
3341 /* allocate new space and copy rest of bands into it */
3342 infoPtr->bands =
3343 (REBAR_BAND *)COMCTL32_Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
3344
3345 /* pre insert copy */
3346 if (uTo > 0) {
3347 memcpy (&infoPtr->bands[0], &oldBands[0],
3348 uTo * sizeof(REBAR_BAND));
3349 }
3350
3351 /* set moved band */
3352 memcpy (&infoPtr->bands[uTo], &holder, sizeof(REBAR_BAND));
3353
3354 /* post copy */
3355 if (uTo < infoPtr->uNumBands - 1) {
3356 memcpy (&infoPtr->bands[uTo+1], &oldBands[uTo],
3357 (infoPtr->uNumBands - uTo - 1) * sizeof(REBAR_BAND));
3358 }
3359
3360 COMCTL32_Free (oldBands);
3361
3362 TRACE("moved band %d to index %d\n", uFrom, uTo);
3363 REBAR_DumpBand (infoPtr);
3364
3365 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3366 /* **************************************************** */
3367 /* */
3368 /* We do not do a REBAR_Layout here because the native */
3369 /* control does not do that. The actual layout and */
3370 /* repaint is done by the *next* real action, ex.: */
3371 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
3372 /* */
3373 /* **************************************************** */
3374
3375 return TRUE;
3376}
3377
3378
3379static LRESULT
3380REBAR_SetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3381{
3382 LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
3383 REBAR_BAND *lpBand;
3384
3385 if (lprbbi == NULL)
3386 return FALSE;
3387 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEA)
3388 return FALSE;
3389 if ((UINT)wParam >= infoPtr->uNumBands)
3390 return FALSE;
3391
3392 TRACE("index %u\n", (UINT)wParam);
3393 REBAR_DumpBandInfo (lprbbi);
3394
3395 /* set band information */
3396 lpBand = &infoPtr->bands[(UINT)wParam];
3397
3398 REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3399 if (lprbbi->fMask & RBBIM_TEXT) {
3400 if (lpBand->lpText) {
3401 COMCTL32_Free (lpBand->lpText);
3402 lpBand->lpText = NULL;
3403 }
3404 if (lprbbi->lpText) {
3405 INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3406 lpBand->lpText = (LPWSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
3407 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3408 }
3409 }
3410
3411 REBAR_ValidateBand (infoPtr, lpBand);
3412
3413 REBAR_DumpBand (infoPtr);
3414
3415 if (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) {
3416 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3417 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3418 }
3419
3420 return TRUE;
3421}
3422
3423
3424static LRESULT
3425REBAR_SetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3426{
3427 LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3428 REBAR_BAND *lpBand;
3429
3430 if (lprbbi == NULL)
3431 return FALSE;
3432 if (lprbbi->cbSize < REBARBANDINFO_V3_SIZEW)
3433 return FALSE;
3434 if ((UINT)wParam >= infoPtr->uNumBands)
3435 return FALSE;
3436
3437 TRACE("index %u\n", (UINT)wParam);
3438 REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3439
3440 /* set band information */
3441 lpBand = &infoPtr->bands[(UINT)wParam];
3442
3443 REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3444 if (lprbbi->fMask & RBBIM_TEXT) {
3445 if (lpBand->lpText) {
3446 COMCTL32_Free (lpBand->lpText);
3447 lpBand->lpText = NULL;
3448 }
3449 if (lprbbi->lpText) {
3450 INT len = lstrlenW (lprbbi->lpText);
3451 lpBand->lpText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
3452 strcpyW (lpBand->lpText, lprbbi->lpText);
3453 }
3454 }
3455
3456 REBAR_ValidateBand (infoPtr, lpBand);
3457
3458 REBAR_DumpBand (infoPtr);
3459
3460 if (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) {
3461 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3462 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3463 }
3464
3465 return TRUE;
3466}
3467
3468
3469static LRESULT
3470REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3471{
3472 LPREBARINFO lpInfo = (LPREBARINFO)lParam;
3473 REBAR_BAND *lpBand;
3474 UINT i;
3475
3476 if (lpInfo == NULL)
3477 return FALSE;
3478
3479 if (lpInfo->cbSize < sizeof (REBARINFO))
3480 return FALSE;
3481
3482 TRACE("setting bar info!\n");
3483
3484 if (lpInfo->fMask & RBIM_IMAGELIST) {
3485 infoPtr->himl = lpInfo->himl;
3486 if (infoPtr->himl) {
3487 INT cx, cy;
3488 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
3489 infoPtr->imageSize.cx = cx;
3490 infoPtr->imageSize.cy = cy;
3491 }
3492 else {
3493 infoPtr->imageSize.cx = 0;
3494 infoPtr->imageSize.cy = 0;
3495 }
3496 TRACE("new image cx=%ld, cy=%ld\n", infoPtr->imageSize.cx,
3497 infoPtr->imageSize.cy);
3498 }
3499
3500 /* revalidate all bands to reset flags for images in headers of bands */
3501 for (i=0; i<infoPtr->uNumBands; i++) {
3502 lpBand = &infoPtr->bands[i];
3503 REBAR_ValidateBand (infoPtr, lpBand);
3504 }
3505
3506 return TRUE;
3507}
3508
3509
3510static LRESULT
3511REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3512{
3513 COLORREF clrTemp;
3514
3515 clrTemp = infoPtr->clrBk;
3516 infoPtr->clrBk = (COLORREF)lParam;
3517
3518 TRACE("background color 0x%06lx!\n", infoPtr->clrBk);
3519
3520 return clrTemp;
3521}
3522
3523
3524/* << REBAR_SetColorScheme >> */
3525/* << REBAR_SetPalette >> */
3526
3527
3528static LRESULT
3529REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3530{
3531 HWND hwndTemp = infoPtr->hwndNotify;
3532
3533 infoPtr->hwndNotify = (HWND)wParam;
3534
3535 return (LRESULT)hwndTemp;
3536}
3537
3538
3539static LRESULT
3540REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3541{
3542 COLORREF clrTemp;
3543
3544 clrTemp = infoPtr->clrText;
3545 infoPtr->clrText = (COLORREF)lParam;
3546
3547 TRACE("text color 0x%06lx!\n", infoPtr->clrText);
3548
3549 return clrTemp;
3550}
3551
3552
3553/* << REBAR_SetTooltips >> */
3554
3555
3556inline static LRESULT
3557REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, WPARAM wParam)
3558{
3559 BOOL bTemp = infoPtr->bUnicode;
3560
3561 TRACE("to %s hwnd=%p, was %s\n",
3562 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf,
3563 (bTemp) ? "TRUE" : "FALSE");
3564
3565 infoPtr->bUnicode = (BOOL)wParam;
3566
3567 return bTemp;
3568}
3569
3570
3571static LRESULT
3572REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
3573{
3574 INT iOldVersion = infoPtr->iVersion;
3575
3576 if (iVersion > COMCTL32_VERSION)
3577 return -1;
3578
3579 infoPtr->iVersion = iVersion;
3580
3581 TRACE("new version %d\n", iVersion);
3582
3583 return iOldVersion;
3584}
3585
3586
3587static LRESULT
3588REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3589{
3590 REBAR_BAND *lpBand;
3591
3592 if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
3593 return FALSE;
3594
3595 lpBand = &infoPtr->bands[(INT)wParam];
3596
3597 if ((BOOL)lParam) {
3598 TRACE("show band %d\n", (INT)wParam);
3599 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
3600 if (IsWindow (lpBand->hwndChild))
3601 ShowWindow (lpBand->hwndChild, SW_SHOW);
3602 }
3603 else {
3604 TRACE("hide band %d\n", (INT)wParam);
3605 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
3606 if (IsWindow (lpBand->hwndChild))
3607 ShowWindow (lpBand->hwndChild, SW_HIDE);
3608 }
3609
3610 REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3611 InvalidateRect(infoPtr->hwndSelf, 0, 1);
3612
3613 return TRUE;
3614}
3615
3616
3617static LRESULT
3618REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3619{
3620 LPRECT lpRect = (LPRECT)lParam;
3621 RECT t1;
3622
3623 if (lpRect == NULL)
3624 return FALSE;
3625
3626 TRACE("[%d %d %d %d]\n",
3627 lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
3628
3629 /* what is going on???? */
3630 GetWindowRect(infoPtr->hwndSelf, &t1);
3631 TRACE("window rect [%d %d %d %d]\n",
3632 t1.left, t1.top, t1.right, t1.bottom);
3633 GetClientRect(infoPtr->hwndSelf, &t1);
3634 TRACE("client rect [%d %d %d %d]\n",
3635 t1.left, t1.top, t1.right, t1.bottom);
3636
3637 /* force full _Layout processing */
3638 TRACE("setting NEEDS_LAYOUT\n");
3639 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3640 REBAR_Layout (infoPtr, lpRect, TRUE, FALSE);
3641 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3642 return TRUE;
3643}
3644
3645
3646
3647static LRESULT
3648REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3649{
3650 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3651 RECT wnrc1, clrc1;
3652
3653 if (TRACE_ON(rebar)) {
3654 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
3655 GetClientRect(infoPtr->hwndSelf, &clrc1);
3656 TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
3657 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3658 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3659 cs->x, cs->y, cs->cx, cs->cy);
3660 }
3661
3662 TRACE("created!\n");
3663 return 0;
3664}
3665
3666
3667static LRESULT
3668REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3669{
3670 REBAR_BAND *lpBand;
3671 INT i;
3672
3673
3674 /* free rebar bands */
3675 if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
3676 /* clean up each band */
3677 for (i = 0; i < infoPtr->uNumBands; i++) {
3678 lpBand = &infoPtr->bands[i];
3679
3680 /* delete text strings */
3681 if (lpBand->lpText) {
3682 COMCTL32_Free (lpBand->lpText);
3683 lpBand->lpText = NULL;
3684 }
3685 /* destroy child window */
3686 DestroyWindow (lpBand->hwndChild);
3687 }
3688
3689 /* free band array */
3690 COMCTL32_Free (infoPtr->bands);
3691 infoPtr->bands = NULL;
3692 }
3693
3694 DeleteObject (infoPtr->hcurArrow);
3695 DeleteObject (infoPtr->hcurHorz);
3696 DeleteObject (infoPtr->hcurVert);
3697 DeleteObject (infoPtr->hcurDrag);
3698 if(infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
3699 SetWindowLongA (infoPtr->hwndSelf, 0, 0);
3700
3701 /* free rebar info data */
3702 COMCTL32_Free (infoPtr);
3703 TRACE("destroyed!\n");
3704 return 0;
3705}
3706
3707
3708static LRESULT
3709REBAR_EraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3710{
3711 RECT cliprect;
3712
3713 if (GetClipBox ( (HDC)wParam, &cliprect))
3714 return REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &cliprect);
3715 return 0;
3716}
3717
3718
3719static LRESULT
3720REBAR_GetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3721{
3722 return (LRESULT)infoPtr->hFont;
3723}
3724
3725
3726static LRESULT
3727REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3728{
3729 REBAR_BAND *lpBand;
3730
3731 /* If InternalHitTest did not find a hit on the Gripper, */
3732 /* then ignore the button click. */
3733 if (infoPtr->ihitBand == -1) return 0;
3734
3735 SetCapture (infoPtr->hwndSelf);
3736
3737 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3738 lpBand = &infoPtr->bands[infoPtr->ihitBand];
3739 infoPtr->dragStart = MAKEPOINTS(lParam);
3740 infoPtr->dragNow = infoPtr->dragStart;
3741 if (infoPtr->dwStyle & CCS_VERT)
3742 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.top+REBAR_PRE_GRIPPER);
3743 else
3744 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left+REBAR_PRE_GRIPPER);
3745
3746 return 0;
3747}
3748
3749
3750static LRESULT
3751REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3752{
3753 NMHDR layout;
3754 RECT rect;
3755 INT ihitBand;
3756
3757 /* If InternalHitTest did not find a hit on the Gripper, */
3758 /* then ignore the button click. */
3759 if (infoPtr->ihitBand == -1) return 0;
3760
3761 ihitBand = infoPtr->ihitBand;
3762 infoPtr->dragStart.x = 0;
3763 infoPtr->dragStart.y = 0;
3764 infoPtr->dragNow = infoPtr->dragStart;
3765 infoPtr->ihitBand = -1;
3766
3767 ReleaseCapture ();
3768
3769 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3770 REBAR_Notify((NMHDR *) &layout, infoPtr, RBN_LAYOUTCHANGED);
3771 REBAR_Notify_NMREBAR (infoPtr, ihitBand, RBN_ENDDRAG);
3772 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3773 }
3774
3775 GetClientRect(infoPtr->hwndSelf, &rect);
3776 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3777
3778 return 0;
3779}
3780
3781
3782static LRESULT
3783REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3784{
3785 REBAR_BAND *band1, *band2;
3786 POINTS ptsmove;
3787
3788 /* Validate entry as hit on Gripper has occurred */
3789 if (GetCapture() != infoPtr->hwndSelf) return 0;
3790 if (infoPtr->ihitBand == -1) return 0;
3791
3792 ptsmove = MAKEPOINTS(lParam);
3793
3794 /* if mouse did not move much, exit */
3795 if ((abs(ptsmove.x - infoPtr->dragNow.x) <= mindragx) &&
3796 (abs(ptsmove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3797
3798 band1 = &infoPtr->bands[infoPtr->ihitBand-1];
3799 band2 = &infoPtr->bands[infoPtr->ihitBand];
3800
3801 /* Test for valid drag case - must not be first band in row */
3802 if (infoPtr->dwStyle & CCS_VERT) {
3803 if ((ptsmove.x < band2->rcBand.left) ||
3804 (ptsmove.x > band2->rcBand.right) ||
3805 ((infoPtr->ihitBand > 0) && (band1->iRow != band2->iRow))) {
3806 FIXME("Cannot drag to other rows yet!!\n");
3807 }
3808 else {
3809 REBAR_HandleLRDrag (infoPtr, &ptsmove);
3810 }
3811 }
3812 else {
3813 if ((ptsmove.y < band2->rcBand.top) ||
3814 (ptsmove.y > band2->rcBand.bottom) ||
3815 ((infoPtr->ihitBand > 0) && (band1->iRow != band2->iRow))) {
3816 FIXME("Cannot drag to other rows yet!!\n");
3817 }
3818 else {
3819 REBAR_HandleLRDrag (infoPtr, &ptsmove);
3820 }
3821 }
3822 return 0;
3823}
3824
3825
3826inline static LRESULT
3827REBAR_NCCalcSize (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3828{
3829 if (infoPtr->dwStyle & WS_BORDER) {
3830 InflateRect((LPRECT)lParam, -GetSystemMetrics(SM_CXEDGE),
3831 -GetSystemMetrics(SM_CYEDGE));
3832 }
3833 TRACE("new client=(%d,%d)-(%d,%d)\n",
3834 ((LPRECT)lParam)->left, ((LPRECT)lParam)->top,
3835 ((LPRECT)lParam)->right, ((LPRECT)lParam)->bottom);
3836 return 0;
3837}
3838
3839
3840static LRESULT
3841REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3842{
3843 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3844 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3845 RECT wnrc1, clrc1;
3846 NONCLIENTMETRICSA ncm;
3847 HFONT tfont;
3848 INT i;
3849
3850 if (infoPtr != NULL) {
3851 ERR("Strange info structure pointer *not* NULL\n");
3852 return FALSE;
3853 }
3854
3855 if (TRACE_ON(rebar)) {
3856 GetWindowRect(hwnd, &wnrc1);
3857 GetClientRect(hwnd, &clrc1);
3858 TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
3859 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3860 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3861 cs->x, cs->y, cs->cx, cs->cy);
3862 }
3863
3864 /* allocate memory for info structure */
3865 infoPtr = (REBAR_INFO *)COMCTL32_Alloc (sizeof(REBAR_INFO));
3866 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
3867
3868 /* initialize info structure - initial values are 0 */
3869 infoPtr->clrBk = CLR_NONE;
3870 infoPtr->clrText = CLR_NONE;
3871 infoPtr->clrBtnText = GetSysColor (COLOR_BTNTEXT);
3872 infoPtr->clrBtnFace = GetSysColor (COLOR_BTNFACE);
3873 infoPtr->ihitBand = -1;
3874 infoPtr->hwndSelf = hwnd;
3875 infoPtr->DoRedraw = TRUE;
3876 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
3877 infoPtr->hcurHorz = LoadCursorA (0, IDC_SIZEWEA);
3878 infoPtr->hcurVert = LoadCursorA (0, IDC_SIZENSA);
3879 infoPtr->hcurDrag = LoadCursorA (0, IDC_SIZEA);
3880 infoPtr->bUnicode = IsWindowUnicode (hwnd);
3881 infoPtr->fStatus = CREATE_RUNNING;
3882 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3883
3884 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3885 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
3886 WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
3887 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
3888 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
3889 i);
3890 i = NFR_ANSI;
3891 }
3892 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
3893
3894 /* add necessary styles to the requested styles */
3895 infoPtr->dwStyle = cs->style | WS_VISIBLE | CCS_TOP;
3896 SetWindowLongA (hwnd, GWL_STYLE, infoPtr->dwStyle);
3897
3898 /* get font handle for Caption Font */
3899 ncm.cbSize = sizeof(NONCLIENTMETRICSA);
3900 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS,
3901 ncm.cbSize, &ncm, 0);
3902 /* if the font is bold, set to normal */
3903 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3904 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3905 }
3906 tfont = CreateFontIndirectA (&ncm.lfCaptionFont);
3907 if (tfont) {
3908 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3909 }
3910
3911/* native does:
3912 GetSysColor (numerous);
3913 GetSysColorBrush (numerous) (see WM_SYSCOLORCHANGE);
3914 *GetStockObject (SYSTEM_FONT);
3915 *SetWindowLong (hwnd, 0, info ptr);
3916 *WM_NOTIFYFORMAT;
3917 *SetWindowLong (hwnd, GWL_STYLE, style+0x10000001);
3918 WS_VISIBLE = 0x10000000;
3919 CCS_TOP = 0x00000001;
3920 *SystemParametersInfo (SPI_GETNONCLIENTMETRICS...);
3921 *CreateFontIndirect (lfCaptionFont from above);
3922 GetDC ();
3923 SelectObject (hdc, fontabove);
3924 GetTextMetrics (hdc, ); guessing is tmHeight
3925 SelectObject (hdc, oldfont);
3926 ReleaseDC ();
3927 GetWindowRect ();
3928 MapWindowPoints (0, parent, rectabove, 2);
3929 GetWindowRect ();
3930 GetClientRect ();
3931 ClientToScreen (clientrect);
3932 SetWindowPos (hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER);
3933 */
3934 return TRUE;
3935}
3936
3937
3938static LRESULT
3939REBAR_NCHitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3940{
3941 NMMOUSE nmmouse;
3942 POINTS shortpt;
3943 POINT clpt, pt;
3944 INT i;
3945 UINT scrap;
3946 LRESULT ret = HTCLIENT;
3947
3948 /*
3949 * Differences from doc at MSDN (as observed with version 4.71 of
3950 * comctl32.dll
3951 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3952 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3953 * 3. native always seems to return HTCLIENT if notify return is 0.
3954 */
3955
3956 shortpt = MAKEPOINTS (lParam);
3957 POINTSTOPOINT(pt, shortpt);
3958 clpt = pt;
3959 ScreenToClient (infoPtr->hwndSelf, &clpt);
3960 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3961 (INT *)&nmmouse.dwItemSpec);
3962 nmmouse.dwItemData = 0;
3963 nmmouse.pt = clpt;
3964 nmmouse.dwHitInfo = 0;
3965 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3966 TRACE("notify changed return value from %ld to %d\n",
3967 ret, i);
3968 ret = (LRESULT) i;
3969 }
3970 TRACE("returning %ld, client point (%ld,%ld)\n", ret, clpt.x, clpt.y);
3971 return ret;
3972}
3973
3974
3975static LRESULT
3976REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3977{
3978 RECT rcWindow;
3979 HDC hdc;
3980
3981 if (infoPtr->dwStyle & WS_MINIMIZE)
3982 return 0; /* Nothing to do */
3983
3984 if (infoPtr->dwStyle & WS_BORDER) {
3985
3986 /* adjust rectangle and draw the necessary edge */
3987 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3988 return 0;
3989 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3990 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3991 TRACE("rect (%d,%d)-(%d,%d)\n",
3992 rcWindow.left, rcWindow.top,
3993 rcWindow.right, rcWindow.bottom);
3994 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3995 ReleaseDC( infoPtr->hwndSelf, hdc );
3996 }
3997
3998 return 0;
3999}
4000
4001
4002static LRESULT
4003REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4004{
4005 INT i;
4006
4007 if (lParam == NF_REQUERY) {
4008 i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
4009 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
4010 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
4011 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
4012 i);
4013 i = NFR_ANSI;
4014 }
4015 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
4016 return (LRESULT)i;
4017 }
4018 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
4019}
4020
4021
4022static LRESULT
4023REBAR_Paint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4024{
4025 HDC hdc;
4026 PAINTSTRUCT ps;
4027 RECT rc;
4028
4029 GetClientRect(infoPtr->hwndSelf, &rc);
4030 hdc = wParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : (HDC)wParam;
4031
4032 TRACE("painting (%d,%d)-(%d,%d) client (%d,%d)-(%d,%d)\n",
4033 ps.rcPaint.left, ps.rcPaint.top,
4034 ps.rcPaint.right, ps.rcPaint.bottom,
4035 rc.left, rc.top, rc.right, rc.bottom);
4036
4037 if (ps.fErase) {
4038 /* Erase area of paint if requested */
4039 REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &ps.rcPaint);
4040 }
4041
4042 REBAR_Refresh (infoPtr, hdc);
4043 if (!wParam)
4044 EndPaint (infoPtr->hwndSelf, &ps);
4045 return 0;
4046}
4047
4048
4049static LRESULT
4050REBAR_SetCursor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4051{
4052 POINT pt;
4053 UINT flags;
4054
4055 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
4056
4057 GetCursorPos (&pt);
4058 ScreenToClient (infoPtr->hwndSelf, &pt);
4059
4060 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
4061
4062 if (flags == RBHT_GRABBER) {
4063 if ((infoPtr->dwStyle & CCS_VERT) &&
4064 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
4065 SetCursor (infoPtr->hcurVert);
4066 else
4067 SetCursor (infoPtr->hcurHorz);
4068 }
4069 else if (flags != RBHT_CLIENT)
4070 SetCursor (infoPtr->hcurArrow);
4071
4072 return 0;
4073}
4074
4075
4076static LRESULT
4077REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4078{
4079 RECT rcClient;
4080 REBAR_BAND *lpBand;
4081 UINT i;
4082
4083 infoPtr->hFont = (HFONT)wParam;
4084
4085 /* revalidate all bands to change sizes of text in headers of bands */
4086 for (i=0; i<infoPtr->uNumBands; i++) {
4087 lpBand = &infoPtr->bands[i];
4088 REBAR_ValidateBand (infoPtr, lpBand);
4089 }
4090
4091
4092 if (LOWORD(lParam)) {
4093 GetClientRect (infoPtr->hwndSelf, &rcClient);
4094 REBAR_Layout (infoPtr, &rcClient, FALSE, TRUE);
4095 }
4096
4097 return 0;
4098}
4099
4100
4101inline static LRESULT
4102REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4103 /*****************************************************
4104 *
4105 * Function;
4106 * Handles the WM_SETREDRAW message.
4107 *
4108 * Documentation:
4109 * According to testing V4.71 of COMCTL32 returns the
4110 * *previous* status of the redraw flag (either 0 or -1)
4111 * instead of the MSDN documented value of 0 if handled
4112 *
4113 *****************************************************/
4114{
4115 BOOL oldredraw = infoPtr->DoRedraw;
4116
4117 TRACE("set to %s, fStatus=%08x\n",
4118 (wParam) ? "TRUE" : "FALSE", infoPtr->fStatus);
4119 infoPtr->DoRedraw = (BOOL) wParam;
4120 if (wParam) {
4121 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
4122 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
4123 REBAR_ForceResize (infoPtr);
4124 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
4125 }
4126 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
4127 }
4128 return (oldredraw) ? -1 : 0;
4129}
4130
4131
4132static LRESULT
4133REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4134{
4135 RECT rcClient;
4136
4137 /* auto resize deadlock check */
4138 if (infoPtr->fStatus & AUTO_RESIZE) {
4139 infoPtr->fStatus &= ~AUTO_RESIZE;
4140 TRACE("AUTO_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
4141 infoPtr->fStatus, lParam);
4142 return 0;
4143 }
4144
4145 if (infoPtr->fStatus & CREATE_RUNNING) {
4146 /* still in CreateWindow */
4147 RECT rcWin;
4148
4149 if ((INT)wParam != SIZE_RESTORED) {
4150 ERR("WM_SIZE in create and flags=%08x, lParam=%08lx\n",
4151 wParam, lParam);
4152 }
4153
4154 TRACE("still in CreateWindow\n");
4155 infoPtr->fStatus &= ~CREATE_RUNNING;
4156 GetWindowRect ( infoPtr->hwndSelf, &rcWin);
4157 TRACE("win rect (%d,%d)-(%d,%d)\n",
4158 rcWin.left, rcWin.top, rcWin.right, rcWin.bottom);
4159
4160 if ((lParam == 0) && (rcWin.right-rcWin.left == 0) &&
4161 (rcWin.bottom-rcWin.top == 0)) {
4162 /* native control seems to do this */
4163 GetClientRect (GetParent(infoPtr->hwndSelf), &rcClient);
4164 TRACE("sizing rebar, message and client zero, parent client (%d,%d)\n",
4165 rcClient.right, rcClient.bottom);
4166 }
4167 else {
4168 INT cx, cy;
4169
4170 cx = rcWin.right - rcWin.left;
4171 cy = rcWin.bottom - rcWin.top;
4172 if ((cx == LOWORD(lParam)) && (cy == HIWORD(lParam))) {
4173 return 0;
4174 }
4175
4176 /* do the actual WM_SIZE request */
4177 GetClientRect (infoPtr->hwndSelf, &rcClient);
4178 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%d,%d)\n",
4179 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4180 LOWORD(lParam), HIWORD(lParam),
4181 rcClient.right, rcClient.bottom);
4182 }
4183 }
4184 else {
4185 if ((INT)wParam != SIZE_RESTORED) {
4186 ERR("WM_SIZE out of create and flags=%08x, lParam=%08lx\n",
4187 wParam, lParam);
4188 }
4189
4190 /* Handle cases when outside of the CreateWindow process */
4191
4192 GetClientRect (infoPtr->hwndSelf, &rcClient);
4193 if ((lParam == 0) && (rcClient.right + rcClient.bottom != 0) &&
4194 (infoPtr->dwStyle & RBS_AUTOSIZE)) {
4195 /* on a WM_SIZE to zero and current client not zero and AUTOSIZE */
4196 /* native seems to use the current client rect for the size */
4197 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4198 TRACE("sizing rebar to client (%d,%d) size is zero but AUTOSIZE set\n",
4199 rcClient.right, rcClient.bottom);
4200 }
4201 else {
4202 TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%d,%d)\n",
4203 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4204 LOWORD(lParam), HIWORD(lParam),
4205 rcClient.right, rcClient.bottom);
4206 }
4207 }
4208
4209 if (infoPtr->dwStyle & RBS_AUTOSIZE) {
4210 NMRBAUTOSIZE autosize;
4211
4212 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
4213 autosize.fChanged = 0; /* ??? */
4214 autosize.rcActual = autosize.rcTarget; /* ??? */
4215 REBAR_Notify((NMHDR *) &autosize, infoPtr, RBN_AUTOSIZE);
4216 TRACE("RBN_AUTOSIZE client=(%d,%d), lp=%08lx\n",
4217 autosize.rcTarget.right, autosize.rcTarget.bottom, lParam);
4218 }
4219
4220 if ((infoPtr->calcSize.cx != rcClient.right) ||
4221 (infoPtr->calcSize.cy != rcClient.bottom))
4222 infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4223
4224 REBAR_Layout (infoPtr, &rcClient, TRUE, TRUE);
4225 infoPtr->fStatus &= ~AUTO_RESIZE;
4226
4227 return 0;
4228}
4229
4230
4231static LRESULT
4232REBAR_StyleChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4233{
4234 STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
4235
4236 TRACE("current style=%08lx, styleOld=%08lx, style being set to=%08lx\n",
4237 infoPtr->dwStyle, ss->styleOld, ss->styleNew);
4238 infoPtr->dwStyle = ss->styleNew;
4239
4240 return FALSE;
4241}
4242
4243
4244static LRESULT
4245REBAR_WindowPosChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4246{
4247 WINDOWPOS *lpwp = (WINDOWPOS *)lParam;
4248 LRESULT ret;
4249 RECT rc;
4250
4251 /* Save the new origin of this window - used by _ForceResize */
4252 infoPtr->origin.x = lpwp->x;
4253 infoPtr->origin.y = lpwp->y;
4254 ret = DefWindowProcA(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
4255 wParam, lParam);
4256 GetWindowRect(infoPtr->hwndSelf, &rc);
4257 TRACE("hwnd %p new pos (%d,%d)-(%d,%d)\n",
4258 infoPtr->hwndSelf, rc.left, rc.top, rc.right, rc.bottom);
4259 return ret;
4260}
4261
4262
4263static LRESULT WINAPI
4264REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4265{
4266 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
4267
4268 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
4269 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
4270 if (!infoPtr && (uMsg != WM_NCCREATE))
4271 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4272 switch (uMsg)
4273 {
4274/* case RB_BEGINDRAG: */
4275
4276 case RB_DELETEBAND:
4277 return REBAR_DeleteBand (infoPtr, wParam, lParam);
4278
4279/* case RB_DRAGMOVE: */
4280/* case RB_ENDDRAG: */
4281
4282 case RB_GETBANDBORDERS:
4283 return REBAR_GetBandBorders (infoPtr, wParam, lParam);
4284
4285 case RB_GETBANDCOUNT:
4286 return REBAR_GetBandCount (infoPtr);
4287
4288 case RB_GETBANDINFO: /* obsoleted after IE3, but we have to
4289 support it anyway. */
4290 case RB_GETBANDINFOA:
4291 return REBAR_GetBandInfoA (infoPtr, wParam, lParam);
4292
4293 case RB_GETBANDINFOW:
4294 return REBAR_GetBandInfoW (infoPtr, wParam, lParam);
4295
4296 case RB_GETBARHEIGHT:
4297 return REBAR_GetBarHeight (infoPtr, wParam, lParam);
4298
4299 case RB_GETBARINFO:
4300 return REBAR_GetBarInfo (infoPtr, wParam, lParam);
4301
4302 case RB_GETBKCOLOR:
4303 return REBAR_GetBkColor (infoPtr);
4304
4305/* case RB_GETCOLORSCHEME: */
4306/* case RB_GETDROPTARGET: */
4307
4308 case RB_GETPALETTE:
4309 return REBAR_GetPalette (infoPtr, wParam, lParam);
4310
4311 case RB_GETRECT:
4312 return REBAR_GetRect (infoPtr, wParam, lParam);
4313
4314 case RB_GETROWCOUNT:
4315 return REBAR_GetRowCount (infoPtr);
4316
4317 case RB_GETROWHEIGHT:
4318 return REBAR_GetRowHeight (infoPtr, wParam, lParam);
4319
4320 case RB_GETTEXTCOLOR:
4321 return REBAR_GetTextColor (infoPtr);
4322
4323 case RB_GETTOOLTIPS:
4324 return REBAR_GetToolTips (infoPtr);
4325
4326 case RB_GETUNICODEFORMAT:
4327 return REBAR_GetUnicodeFormat (infoPtr);
4328
4329 case CCM_GETVERSION:
4330 return REBAR_GetVersion (infoPtr);
4331
4332 case RB_HITTEST:
4333 return REBAR_HitTest (infoPtr, wParam, lParam);
4334
4335 case RB_IDTOINDEX:
4336 return REBAR_IdToIndex (infoPtr, wParam, lParam);
4337
4338 case RB_INSERTBANDA:
4339 return REBAR_InsertBandA (infoPtr, wParam, lParam);
4340
4341 case RB_INSERTBANDW:
4342 return REBAR_InsertBandW (infoPtr, wParam, lParam);
4343
4344 case RB_MAXIMIZEBAND:
4345 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
4346
4347 case RB_MINIMIZEBAND:
4348 return REBAR_MinimizeBand (infoPtr, wParam, lParam);
4349
4350 case RB_MOVEBAND:
4351 return REBAR_MoveBand (infoPtr, wParam, lParam);
4352
4353 case RB_SETBANDINFOA:
4354 return REBAR_SetBandInfoA (infoPtr, wParam, lParam);
4355
4356 case RB_SETBANDINFOW:
4357 return REBAR_SetBandInfoW (infoPtr, wParam, lParam);
4358
4359 case RB_SETBARINFO:
4360 return REBAR_SetBarInfo (infoPtr, wParam, lParam);
4361
4362 case RB_SETBKCOLOR:
4363 return REBAR_SetBkColor (infoPtr, wParam, lParam);
4364
4365/* case RB_SETCOLORSCHEME: */
4366/* case RB_SETPALETTE: */
4367/* return REBAR_GetPalette (infoPtr, wParam, lParam); */
4368
4369 case RB_SETPARENT:
4370 return REBAR_SetParent (infoPtr, wParam, lParam);
4371
4372 case RB_SETTEXTCOLOR:
4373 return REBAR_SetTextColor (infoPtr, wParam, lParam);
4374
4375/* case RB_SETTOOLTIPS: */
4376
4377 case RB_SETUNICODEFORMAT:
4378 return REBAR_SetUnicodeFormat (infoPtr, wParam);
4379
4380 case CCM_SETVERSION:
4381 return REBAR_SetVersion (infoPtr, (INT)wParam);
4382
4383 case RB_SHOWBAND:
4384 return REBAR_ShowBand (infoPtr, wParam, lParam);
4385
4386 case RB_SIZETORECT:
4387 return REBAR_SizeToRect (infoPtr, wParam, lParam);
4388
4389
4390/* Messages passed to parent */
4391 case WM_COMMAND:
4392 case WM_DRAWITEM:
4393 case WM_NOTIFY:
4394 if (infoPtr->NtfUnicode)
4395 return SendMessageW (REBAR_GetNotifyParent (infoPtr),
4396 uMsg, wParam, lParam);
4397 else
4398 return SendMessageA (REBAR_GetNotifyParent (infoPtr),
4399 uMsg, wParam, lParam);
4400
4401
4402/* case WM_CHARTOITEM: supported according to ControlSpy */
4403
4404 case WM_CREATE:
4405 return REBAR_Create (infoPtr, wParam, lParam);
4406
4407 case WM_DESTROY:
4408 return REBAR_Destroy (infoPtr, wParam, lParam);
4409
4410 case WM_ERASEBKGND:
4411 return REBAR_EraseBkGnd (infoPtr, wParam, lParam);
4412
4413 case WM_GETFONT:
4414 return REBAR_GetFont (infoPtr, wParam, lParam);
4415
4416/* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
4417
4418 case WM_LBUTTONDOWN:
4419 return REBAR_LButtonDown (infoPtr, wParam, lParam);
4420
4421 case WM_LBUTTONUP:
4422 return REBAR_LButtonUp (infoPtr, wParam, lParam);
4423
4424/* case WM_MEASUREITEM: supported according to ControlSpy */
4425
4426 case WM_MOUSEMOVE:
4427 return REBAR_MouseMove (infoPtr, wParam, lParam);
4428
4429 case WM_NCCALCSIZE:
4430 return REBAR_NCCalcSize (infoPtr, wParam, lParam);
4431
4432 case WM_NCCREATE:
4433 return REBAR_NCCreate (hwnd, wParam, lParam);
4434
4435 case WM_NCHITTEST:
4436 return REBAR_NCHitTest (infoPtr, wParam, lParam);
4437
4438 case WM_NCPAINT:
4439 return REBAR_NCPaint (infoPtr, wParam, lParam);
4440
4441 case WM_NOTIFYFORMAT:
4442 return REBAR_NotifyFormat (infoPtr, wParam, lParam);
4443
4444 case WM_PAINT:
4445 return REBAR_Paint (infoPtr, wParam, lParam);
4446
4447/* case WM_PALETTECHANGED: supported according to ControlSpy */
4448/* case WM_PRINTCLIENT: supported according to ControlSpy */
4449/* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
4450/* case WM_RBUTTONDOWN: supported according to ControlSpy */
4451/* case WM_RBUTTONUP: supported according to ControlSpy */
4452
4453 case WM_SETCURSOR:
4454 return REBAR_SetCursor (infoPtr, wParam, lParam);
4455
4456 case WM_SETFONT:
4457 return REBAR_SetFont (infoPtr, wParam, lParam);
4458
4459 case WM_SETREDRAW:
4460 return REBAR_SetRedraw (infoPtr, wParam, lParam);
4461
4462 case WM_SIZE:
4463 return REBAR_Size (infoPtr, wParam, lParam);
4464
4465 case WM_STYLECHANGED:
4466 return REBAR_StyleChanged (infoPtr, wParam, lParam);
4467
4468/* case WM_SYSCOLORCHANGE: supported according to ControlSpy */
4469/* "Applications that have brushes using the existing system colors
4470 should delete those brushes and recreate them using the new
4471 system colors." per MSDN */
4472
4473/* case WM_VKEYTOITEM: supported according to ControlSpy */
4474/* case WM_WININICHANGE: */
4475
4476 case WM_WINDOWPOSCHANGED:
4477 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
4478
4479 default:
4480 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
4481 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
4482 uMsg, wParam, lParam);
4483 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4484 }
4485 return 0;
4486}
4487
4488
4489VOID
4490REBAR_Register (void)
4491{
4492 WNDCLASSA wndClass;
4493
4494 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4495 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
4496 wndClass.lpfnWndProc = (WNDPROC)REBAR_WindowProc;
4497 wndClass.cbClsExtra = 0;
4498 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
4499 wndClass.hCursor = 0;
4500 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
4501#if GLATESTING
4502 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
4503#endif
4504 wndClass.lpszClassName = REBARCLASSNAMEA;
4505
4506 RegisterClassA (&wndClass);
4507
4508 mindragx = GetSystemMetrics (SM_CXDRAG);
4509 mindragy = GetSystemMetrics (SM_CYDRAG);
4510
4511}
4512
4513
4514VOID
4515REBAR_Unregister (void)
4516{
4517 UnregisterClassA (REBARCLASSNAMEA, (HINSTANCE)NULL);
4518}
Note: See TracBrowser for help on using the repository browser.