[CMAKE]
[reactos.git] / dll / win32 / comctl32 / rebar.c
1 /*
2 * Rebar control
3 *
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2007, 2008 Mikolaj Zalewski
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * NOTES
22 *
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 19, 2004, by Robert Shearman.
25 *
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features or bugs please note them below.
29 *
30 * TODO
31 * Styles:
32 * - RBS_DBLCLKTOGGLE
33 * - RBS_FIXEDORDER
34 * - RBS_REGISTERDROP
35 * - RBS_TOOLTIPS
36 * Messages:
37 * - RB_BEGINDRAG
38 * - RB_DRAGMOVE
39 * - RB_ENDDRAG
40 * - RB_GETBANDMARGINS
41 * - RB_GETCOLORSCHEME
42 * - RB_GETDROPTARGET
43 * - RB_GETPALETTE
44 * - RB_SETCOLORSCHEME
45 * - RB_SETPALETTE
46 * - RB_SETTOOLTIPS
47 * - WM_CHARTOITEM
48 * - WM_LBUTTONDBLCLK
49 * - WM_MEASUREITEM
50 * - WM_PALETTECHANGED
51 * - WM_QUERYNEWPALETTE
52 * - WM_RBUTTONDOWN
53 * - WM_RBUTTONUP
54 * - WM_VKEYTOITEM
55 * - WM_WININICHANGE
56 * Notifications:
57 * - NM_HCHITTEST
58 * - NM_RELEASEDCAPTURE
59 * - RBN_AUTOBREAK
60 * - RBN_GETOBJECT
61 * - RBN_MINMAX
62 * Band styles:
63 * - RBBS_FIXEDBMP
64 * Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
65 * to set the size of the separator width (the value SEP_WIDTH_SIZE
66 * in here). Should be fixed!!
67 */
68
69 /*
70 * Testing: set to 1 to make background brush *always* green
71 */
72 #define GLATESTING 0
73
74 /*
75 * 3. REBAR_MoveChildWindows should have a loop because more than
76 * one pass (together with the RBN_CHILDSIZEs) is made on
77 * at least RB_INSERTBAND
78 */
79
80 #include <assert.h>
81 #include <stdarg.h>
82 #include <stdlib.h>
83 #include <string.h>
84
85 #include "windef.h"
86 #include "winbase.h"
87 #include "wingdi.h"
88 #include "wine/unicode.h"
89 #include "winuser.h"
90 #include "winnls.h"
91 #include "commctrl.h"
92 #include "comctl32.h"
93 #include "uxtheme.h"
94 #include "tmschema.h"
95 #include "wine/debug.h"
96
97 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
98
99 typedef struct
100 {
101 UINT fStyle;
102 UINT fMask;
103 COLORREF clrFore;
104 COLORREF clrBack;
105 INT iImage;
106 HWND hwndChild;
107 UINT cxMinChild; /* valid if _CHILDSIZE */
108 UINT cyMinChild; /* valid if _CHILDSIZE */
109 UINT cx; /* valid if _SIZE */
110 HBITMAP hbmBack;
111 UINT wID;
112 UINT cyChild; /* valid if _CHILDSIZE */
113 UINT cyMaxChild; /* valid if _CHILDSIZE */
114 UINT cyIntegral; /* valid if _CHILDSIZE */
115 UINT cxIdeal;
116 LPARAM lParam;
117 UINT cxHeader;
118
119 INT cxEffective; /* current cx for band */
120 UINT cyHeader; /* the height of the header */
121 UINT cxMinBand; /* minimum cx for band */
122 UINT cyMinBand; /* minimum cy for band */
123
124 UINT cyRowSoFar; /* for RBS_VARHEIGHT - the height of the row if it would break on this band (set by _Layout) */
125 INT iRow; /* zero-based index of the row this band assigned to */
126 UINT fStatus; /* status flags, reset only by _Validate */
127 UINT fDraw; /* drawing flags, reset only by _Layout */
128 UINT uCDret; /* last return from NM_CUSTOMDRAW */
129 RECT rcBand; /* calculated band rectangle - coordinates swapped for CCS_VERT */
130 RECT rcGripper; /* calculated gripper rectangle */
131 RECT rcCapImage; /* calculated caption image rectangle */
132 RECT rcCapText; /* calculated caption text rectangle */
133 RECT rcChild; /* calculated child rectangle */
134 RECT rcChevron; /* calculated chevron rectangle */
135
136 LPWSTR lpText;
137 HWND hwndPrevParent;
138 } REBAR_BAND;
139
140 /* fStatus flags */
141 #define HAS_GRIPPER 0x00000001
142 #define HAS_IMAGE 0x00000002
143 #define HAS_TEXT 0x00000004
144
145 /* fDraw flags */
146 #define DRAW_GRIPPER 0x00000001
147 #define DRAW_IMAGE 0x00000002
148 #define DRAW_TEXT 0x00000004
149 #define DRAW_CHEVRONHOT 0x00000040
150 #define DRAW_CHEVRONPUSHED 0x00000080
151 #define NTF_INVALIDATE 0x01000000
152
153 typedef struct
154 {
155 COLORREF clrBk; /* background color */
156 COLORREF clrText; /* text color */
157 COLORREF clrBtnText; /* system color for BTNTEXT */
158 COLORREF clrBtnFace; /* system color for BTNFACE */
159 HIMAGELIST himl; /* handle to imagelist */
160 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
161 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
162 HWND hwndSelf; /* handle of REBAR window itself */
163 HWND hwndToolTip; /* handle to the tool tip control */
164 HWND hwndNotify; /* notification window (parent) */
165 HFONT hDefaultFont;
166 HFONT hFont; /* handle to the rebar's font */
167 SIZE imageSize; /* image size (image list) */
168 DWORD dwStyle; /* window style */
169 DWORD orgStyle; /* original style (dwStyle may change) */
170 SIZE calcSize; /* calculated rebar size - coordinates swapped for CCS_VERT */
171 BOOL bUnicode; /* TRUE if parent wants notify in W format */
172 BOOL DoRedraw; /* TRUE to actually draw bands */
173 UINT fStatus; /* Status flags (see below) */
174 HCURSOR hcurArrow; /* handle to the arrow cursor */
175 HCURSOR hcurHorz; /* handle to the EW cursor */
176 HCURSOR hcurVert; /* handle to the NS cursor */
177 HCURSOR hcurDrag; /* handle to the drag cursor */
178 INT iVersion; /* version number */
179 POINT dragStart; /* x,y of button down */
180 POINT dragNow; /* x,y of this MouseMove */
181 INT iOldBand; /* last band that had the mouse cursor over it */
182 INT ihitoffset; /* offset of hotspot from gripper.left */
183 INT ichevronhotBand; /* last band that had a hot chevron */
184 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
185
186 HDPA bands; /* pointer to the array of rebar bands */
187 } REBAR_INFO;
188
189 /* fStatus flags */
190 #define BEGIN_DRAG_ISSUED 0x00000001
191 #define SELF_RESIZE 0x00000002
192 #define BAND_NEEDS_REDRAW 0x00000020
193
194 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
195 #define RBBS_UNDOC_FIXEDHEADER 0x40000000
196
197 /* ---- REBAR layout constants. Mostly determined by ---- */
198 /* ---- experiment on WIN 98. ---- */
199
200 /* Width (or height) of separators between bands (either horz. or */
201 /* vert.). True only if RBS_BANDBORDERS is set */
202 #define SEP_WIDTH_SIZE 2
203 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
204
205 /* Blank (background color) space between Gripper (if present) */
206 /* and next item (image, text, or window). Always present */
207 #define REBAR_ALWAYS_SPACE 4
208
209 /* Blank (background color) space after Image (if present). */
210 #define REBAR_POST_IMAGE 2
211
212 /* Blank (background color) space after Text (if present). */
213 #define REBAR_POST_TEXT 4
214
215 /* Height of vertical gripper in a CCS_VERT rebar. */
216 #define GRIPPER_HEIGHT 16
217
218 /* Blank (background color) space before Gripper (if present). */
219 #define REBAR_PRE_GRIPPER 2
220
221 /* Width (of normal vertical gripper) or height (of horz. gripper) */
222 /* if present. */
223 #define GRIPPER_WIDTH 3
224
225 /* Width of the chevron button if present */
226 #define CHEVRON_WIDTH 10
227
228 /* the gap between the child and the next band */
229 #define REBAR_POST_CHILD 4
230
231 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
232 /* either top or bottom */
233 #define REBAR_DIVIDER 2
234
235 /* height of a rebar without a child */
236 #define REBAR_NO_CHILD_HEIGHT 4
237
238 /* minimum vertical height of a normal bar */
239 /* or minimum width of a CCS_VERT bar - from experiment on Win2k */
240 #define REBAR_MINSIZE 23
241
242 /* This is the increment that is used over the band height */
243 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
244
245 /* ---- End of REBAR layout constants. ---- */
246
247 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
248
249 /* The following define determines if a given band is hidden */
250 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
251 ((infoPtr->dwStyle & CCS_VERT) && \
252 ((a)->fStyle & RBBS_NOVERT)))
253
254 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
255
256 static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, LPARAM lParam);
257 static void REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout);
258
259 /* no index check here */
260 static inline REBAR_BAND* REBAR_GetBand(const REBAR_INFO *infoPtr, INT i)
261 {
262 assert(i >= 0 && i < infoPtr->uNumBands);
263 return DPA_GetPtr(infoPtr->bands, i);
264 }
265
266 /* "constant values" retrieved when DLL was initialized */
267 /* FIXME we do this when the classes are registered. */
268 static UINT mindragx = 0;
269 static UINT mindragy = 0;
270
271 static const char * const band_stylename[] = {
272 "RBBS_BREAK", /* 0001 */
273 "RBBS_FIXEDSIZE", /* 0002 */
274 "RBBS_CHILDEDGE", /* 0004 */
275 "RBBS_HIDDEN", /* 0008 */
276 "RBBS_NOVERT", /* 0010 */
277 "RBBS_FIXEDBMP", /* 0020 */
278 "RBBS_VARIABLEHEIGHT", /* 0040 */
279 "RBBS_GRIPPERALWAYS", /* 0080 */
280 "RBBS_NOGRIPPER", /* 0100 */
281 NULL };
282
283 static const char * const band_maskname[] = {
284 "RBBIM_STYLE", /* 0x00000001 */
285 "RBBIM_COLORS", /* 0x00000002 */
286 "RBBIM_TEXT", /* 0x00000004 */
287 "RBBIM_IMAGE", /* 0x00000008 */
288 "RBBIM_CHILD", /* 0x00000010 */
289 "RBBIM_CHILDSIZE", /* 0x00000020 */
290 "RBBIM_SIZE", /* 0x00000040 */
291 "RBBIM_BACKGROUND", /* 0x00000080 */
292 "RBBIM_ID", /* 0x00000100 */
293 "RBBIM_IDEALSIZE", /* 0x00000200 */
294 "RBBIM_LPARAM", /* 0x00000400 */
295 "RBBIM_HEADERSIZE", /* 0x00000800 */
296 NULL };
297
298
299 static CHAR line[200];
300
301 static const WCHAR themeClass[] = { 'R','e','b','a','r',0 };
302
303 static CHAR *
304 REBAR_FmtStyle( UINT style)
305 {
306 INT i = 0;
307
308 *line = 0;
309 while (band_stylename[i]) {
310 if (style & (1<<i)) {
311 if (*line != 0) strcat(line, " | ");
312 strcat(line, band_stylename[i]);
313 }
314 i++;
315 }
316 return line;
317 }
318
319
320 static CHAR *
321 REBAR_FmtMask( UINT mask)
322 {
323 INT i = 0;
324
325 *line = 0;
326 while (band_maskname[i]) {
327 if (mask & (1<<i)) {
328 if (*line != 0) strcat(line, " | ");
329 strcat(line, band_maskname[i]);
330 }
331 i++;
332 }
333 return line;
334 }
335
336
337 static VOID
338 REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
339 {
340 if( !TRACE_ON(rebar) ) return;
341 TRACE("band info: ");
342 if (pB->fMask & RBBIM_ID)
343 TRACE("ID=%u, ", pB->wID);
344 TRACE("size=%u, child=%p", pB->cbSize, pB->hwndChild);
345 if (pB->fMask & RBBIM_COLORS)
346 TRACE(", clrF=0x%06x, clrB=0x%06x", pB->clrFore, pB->clrBack);
347 TRACE("\n");
348
349 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
350 if (pB->fMask & RBBIM_STYLE)
351 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
352 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
353 TRACE("band info:");
354 if (pB->fMask & RBBIM_SIZE)
355 TRACE(" cx=%u", pB->cx);
356 if (pB->fMask & RBBIM_IDEALSIZE)
357 TRACE(" xIdeal=%u", pB->cxIdeal);
358 if (pB->fMask & RBBIM_HEADERSIZE)
359 TRACE(" xHeader=%u", pB->cxHeader);
360 if (pB->fMask & RBBIM_LPARAM)
361 TRACE(" lParam=0x%08lx", pB->lParam);
362 TRACE("\n");
363 }
364 if (pB->fMask & RBBIM_CHILDSIZE)
365 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
366 pB->cxMinChild,
367 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
368 }
369
370 static VOID
371 REBAR_DumpBand (const REBAR_INFO *iP)
372 {
373 REBAR_BAND *pB;
374 UINT i;
375
376 if(! TRACE_ON(rebar) ) return;
377
378 TRACE("hwnd=%p: color=%08x/%08x, bands=%u, rows=%u, cSize=%d,%d\n",
379 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
380 iP->calcSize.cx, iP->calcSize.cy);
381 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
382 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
383 iP->dragNow.x, iP->dragNow.y,
384 iP->iGrabbedBand);
385 TRACE("hwnd=%p: style=%08x, notify in Unicode=%s, redraw=%s\n",
386 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
387 (iP->DoRedraw)?"TRUE":"FALSE");
388 for (i = 0; i < iP->uNumBands; i++) {
389 pB = REBAR_GetBand(iP, i);
390 TRACE("band # %u:", i);
391 if (pB->fMask & RBBIM_ID)
392 TRACE(" ID=%u", pB->wID);
393 if (pB->fMask & RBBIM_CHILD)
394 TRACE(" child=%p", pB->hwndChild);
395 if (pB->fMask & RBBIM_COLORS)
396 TRACE(" clrF=0x%06x clrB=0x%06x", pB->clrFore, pB->clrBack);
397 TRACE("\n");
398 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
399 if (pB->fMask & RBBIM_STYLE)
400 TRACE("band # %u: style=0x%08x (%s)\n",
401 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
402 TRACE("band # %u: xHeader=%u",
403 i, pB->cxHeader);
404 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
405 if (pB->fMask & RBBIM_SIZE)
406 TRACE(" cx=%u", pB->cx);
407 if (pB->fMask & RBBIM_IDEALSIZE)
408 TRACE(" xIdeal=%u", pB->cxIdeal);
409 if (pB->fMask & RBBIM_LPARAM)
410 TRACE(" lParam=0x%08lx", pB->lParam);
411 }
412 TRACE("\n");
413 if (RBBIM_CHILDSIZE)
414 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
415 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
416 if (pB->fMask & RBBIM_TEXT)
417 TRACE("band # %u: text=%s\n",
418 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
419 TRACE("band # %u: cxMinBand=%u, cxEffective=%u, cyMinBand=%u\n",
420 i, pB->cxMinBand, pB->cxEffective, pB->cyMinBand);
421 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
422 i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
423 wine_dbgstr_rect(&pB->rcGripper));
424 TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
425 i, wine_dbgstr_rect(&pB->rcCapImage),
426 wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
427 }
428
429 }
430
431 /* dest can be equal to src */
432 static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
433 {
434 if (infoPtr->dwStyle & CCS_VERT) {
435 int tmp;
436 tmp = src->left;
437 dest->left = src->top;
438 dest->top = tmp;
439
440 tmp = src->right;
441 dest->right = src->bottom;
442 dest->bottom = tmp;
443 } else {
444 *dest = *src;
445 }
446 }
447
448 static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
449 {
450 if (infoPtr->dwStyle & CCS_VERT)
451 return lpRect->bottom - lpRect->top;
452 return lpRect->right - lpRect->left;
453 }
454
455 static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
456 {
457 if (infoPtr->dwStyle & CCS_VERT)
458 return lpRect->right - lpRect->left;
459 return lpRect->bottom - lpRect->top;
460 }
461
462 static int round_child_height(const REBAR_BAND *lpBand, int cyHeight)
463 {
464 int cy = 0;
465 if (lpBand->cyIntegral == 0)
466 return cyHeight;
467 cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
468 cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
469 cy = min(cy, lpBand->cyMaxChild);
470 return cy;
471 }
472
473 static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
474 {
475 lpBand->cyMinBand = max(lpBand->cyHeader,
476 (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
477 }
478
479 static void
480 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
481 {
482 INT x, y;
483 HPEN hPen, hOldPen;
484
485 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
486 hOldPen = SelectObject ( hdc, hPen );
487 x = left + 2;
488 y = top;
489 MoveToEx (hdc, x, y, NULL);
490 LineTo (hdc, x+5, y++); x++;
491 MoveToEx (hdc, x, y, NULL);
492 LineTo (hdc, x+3, y++); x++;
493 MoveToEx (hdc, x, y, NULL);
494 LineTo (hdc, x+1, y);
495 SelectObject( hdc, hOldPen );
496 DeleteObject( hPen );
497 }
498
499 static HWND
500 REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
501 {
502 HWND parent, owner;
503
504 parent = infoPtr->hwndNotify;
505 if (!parent) {
506 parent = GetParent (infoPtr->hwndSelf);
507 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
508 if (owner) parent = owner;
509 }
510 return parent;
511 }
512
513
514 static INT
515 REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
516 {
517 HWND parent;
518
519 parent = REBAR_GetNotifyParent (infoPtr);
520 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
521 nmhdr->hwndFrom = infoPtr->hwndSelf;
522 nmhdr->code = code;
523
524 TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
525
526 return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
527 }
528
529 static INT
530 REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
531 {
532 NMREBAR notify_rebar;
533
534 notify_rebar.dwMask = 0;
535 if (uBand != -1) {
536 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
537
538 if (lpBand->fMask & RBBIM_ID) {
539 notify_rebar.dwMask |= RBNM_ID;
540 notify_rebar.wID = lpBand->wID;
541 }
542 if (lpBand->fMask & RBBIM_LPARAM) {
543 notify_rebar.dwMask |= RBNM_LPARAM;
544 notify_rebar.lParam = lpBand->lParam;
545 }
546 if (lpBand->fMask & RBBIM_STYLE) {
547 notify_rebar.dwMask |= RBNM_STYLE;
548 notify_rebar.fStyle = lpBand->fStyle;
549 }
550 }
551 notify_rebar.uBand = uBand;
552 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
553 }
554
555 static VOID
556 REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
557 {
558 HFONT hOldFont = 0;
559 INT oldBkMode = 0;
560 NMCUSTOMDRAW nmcd;
561 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
562 RECT rcBand;
563
564 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
565
566 if (lpBand->fDraw & DRAW_TEXT) {
567 hOldFont = SelectObject (hdc, infoPtr->hFont);
568 oldBkMode = SetBkMode (hdc, TRANSPARENT);
569 }
570
571 /* should test for CDRF_NOTIFYITEMDRAW here */
572 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
573 nmcd.hdc = hdc;
574 nmcd.rc = rcBand;
575 nmcd.rc.right = lpBand->rcCapText.right;
576 nmcd.rc.bottom = lpBand->rcCapText.bottom;
577 nmcd.dwItemSpec = lpBand->wID;
578 nmcd.uItemState = 0;
579 nmcd.lItemlParam = lpBand->lParam;
580 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
581 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
582 if (oldBkMode != TRANSPARENT)
583 SetBkMode (hdc, oldBkMode);
584 SelectObject (hdc, hOldFont);
585 return;
586 }
587
588 /* draw gripper */
589 if (lpBand->fDraw & DRAW_GRIPPER)
590 {
591 if (theme)
592 {
593 RECT rcGripper = lpBand->rcGripper;
594 int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
595 GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
596 OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
597 lpBand->rcGripper.top - rcGripper.top);
598 DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
599 }
600 else
601 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
602 }
603
604 /* draw caption image */
605 if (lpBand->fDraw & DRAW_IMAGE) {
606 POINT pt;
607
608 /* center image */
609 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
610 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
611
612 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
613 pt.x, pt.y,
614 ILD_TRANSPARENT);
615 }
616
617 /* draw caption text */
618 if (lpBand->fDraw & DRAW_TEXT) {
619 /* need to handle CDRF_NEWFONT here */
620 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
621 COLORREF oldcolor = CLR_NONE;
622 COLORREF new;
623 if (lpBand->clrFore != CLR_NONE) {
624 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
625 lpBand->clrFore;
626 oldcolor = SetTextColor (hdc, new);
627 }
628 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
629 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
630 if (oldBkMode != TRANSPARENT)
631 SetBkMode (hdc, oldBkMode);
632 if (lpBand->clrFore != CLR_NONE)
633 SetTextColor (hdc, oldcolor);
634 SelectObject (hdc, hOldFont);
635 }
636
637 if (!IsRectEmpty(&lpBand->rcChevron))
638 {
639 if (theme)
640 {
641 int stateId;
642 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
643 stateId = CHEVS_PRESSED;
644 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
645 stateId = CHEVS_HOT;
646 else
647 stateId = CHEVS_NORMAL;
648 DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
649 }
650 else
651 {
652 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
653 {
654 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
655 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
656 }
657 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
658 {
659 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
660 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
661 }
662 else
663 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
664 }
665 }
666
667 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
668 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
669 nmcd.hdc = hdc;
670 nmcd.rc = rcBand;
671 nmcd.rc.right = lpBand->rcCapText.right;
672 nmcd.rc.bottom = lpBand->rcCapText.bottom;
673 nmcd.dwItemSpec = lpBand->wID;
674 nmcd.uItemState = 0;
675 nmcd.lItemlParam = lpBand->lParam;
676 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
677 }
678 }
679
680
681 static VOID
682 REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
683 {
684 REBAR_BAND *lpBand;
685 UINT i;
686
687 if (!infoPtr->DoRedraw) return;
688
689 for (i = 0; i < infoPtr->uNumBands; i++) {
690 lpBand = REBAR_GetBand(infoPtr, i);
691
692 if (HIDDENBAND(lpBand)) continue;
693
694 /* now draw the band */
695 TRACE("[%p] drawing band %i, flags=%08x\n",
696 infoPtr->hwndSelf, i, lpBand->fDraw);
697 REBAR_DrawBand (hdc, infoPtr, lpBand);
698 }
699 }
700
701
702 static void
703 REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
704 /* Function: this routine initializes all the rectangles in */
705 /* each band in a row to fit in the adjusted rcBand rect. */
706 /* *** Supports only Horizontal bars. *** */
707 {
708 REBAR_BAND *lpBand;
709 UINT i, xoff;
710 RECT work;
711
712 for(i=rstart; i<rend; i++){
713 lpBand = REBAR_GetBand(infoPtr, i);
714 if (HIDDENBAND(lpBand)) {
715 SetRect (&lpBand->rcChild,
716 lpBand->rcBand.right, lpBand->rcBand.top,
717 lpBand->rcBand.right, lpBand->rcBand.bottom);
718 continue;
719 }
720
721 /* set initial gripper rectangle */
722 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
723 lpBand->rcBand.left, lpBand->rcBand.bottom);
724
725 /* calculate gripper rectangle */
726 if ( lpBand->fStatus & HAS_GRIPPER) {
727 lpBand->fDraw |= DRAW_GRIPPER;
728 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
729 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
730 lpBand->rcGripper.top += 2;
731 lpBand->rcGripper.bottom -= 2;
732
733 SetRect (&lpBand->rcCapImage,
734 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
735 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
736 }
737 else { /* no gripper will be drawn */
738 xoff = 0;
739 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
740 /* if no gripper but either image or text, then leave space */
741 xoff = REBAR_ALWAYS_SPACE;
742 SetRect (&lpBand->rcCapImage,
743 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
744 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
745 }
746
747 /* image is visible */
748 if (lpBand->fStatus & HAS_IMAGE) {
749 lpBand->fDraw |= DRAW_IMAGE;
750 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
751 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
752
753 /* set initial caption text rectangle */
754 SetRect (&lpBand->rcCapText,
755 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
756 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
757 }
758 else {
759 /* set initial caption text rectangle */
760 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
761 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
762 }
763
764 /* text is visible */
765 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
766 lpBand->fDraw |= DRAW_TEXT;
767 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
768 lpBand->rcCapText.right-REBAR_POST_TEXT);
769 }
770
771 /* set initial child window rectangle if there is a child */
772 if (lpBand->hwndChild) {
773
774 lpBand->rcChild.left = lpBand->rcBand.left + lpBand->cxHeader;
775 lpBand->rcChild.right = lpBand->rcBand.right - REBAR_POST_CHILD;
776
777 if (lpBand->cyChild > 0) {
778
779 UINT yoff = (lpBand->rcBand.bottom - lpBand->rcBand.top - lpBand->cyChild) / 2;
780
781 /* center child if height is known */
782 lpBand->rcChild.top = lpBand->rcBand.top + yoff;
783 lpBand->rcChild.bottom = lpBand->rcBand.top + yoff + lpBand->cyChild;
784 }
785 else {
786 lpBand->rcChild.top = lpBand->rcBand.top;
787 lpBand->rcChild.bottom = lpBand->rcBand.bottom;
788 }
789
790 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
791 {
792 lpBand->rcChild.right -= CHEVRON_WIDTH;
793 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
794 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
795 lpBand->rcChild.bottom);
796 }
797 }
798 else {
799 SetRect (&lpBand->rcChild,
800 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
801 lpBand->rcBand.right, lpBand->rcBand.bottom);
802 }
803
804 /* flag if notify required and invalidate rectangle */
805 if (lpBand->fDraw & NTF_INVALIDATE) {
806 TRACE("invalidating (%d,%d)-(%d,%d)\n",
807 lpBand->rcBand.left,
808 lpBand->rcBand.top,
809 lpBand->rcBand.right + SEP_WIDTH,
810 lpBand->rcBand.bottom + SEP_WIDTH);
811 lpBand->fDraw &= ~NTF_INVALIDATE;
812 work = lpBand->rcBand;
813 work.right += SEP_WIDTH;
814 work.bottom += SEP_WIDTH;
815 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
816 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
817 }
818
819 }
820
821 }
822
823
824 static VOID
825 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
826 /* Function: this routine initializes all the rectangles in */
827 /* each band in a row to fit in the adjusted rcBand rect. */
828 /* *** Supports only Vertical bars. *** */
829 {
830 REBAR_BAND *lpBand;
831 UINT i, xoff;
832 RECT work;
833
834 for(i=rstart; i<rend; i++){
835 RECT rcBand;
836 lpBand = REBAR_GetBand(infoPtr, i);
837 if (HIDDENBAND(lpBand)) continue;
838
839 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
840
841 /* set initial gripper rectangle */
842 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
843
844 /* calculate gripper rectangle */
845 if (lpBand->fStatus & HAS_GRIPPER) {
846 lpBand->fDraw |= DRAW_GRIPPER;
847
848 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
849 /* vertical gripper */
850 lpBand->rcGripper.left += 3;
851 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
852 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
853 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
854
855 /* initialize Caption image rectangle */
856 SetRect (&lpBand->rcCapImage, rcBand.left,
857 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
858 rcBand.right,
859 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
860 }
861 else {
862 /* horizontal gripper */
863 lpBand->rcGripper.left += 2;
864 lpBand->rcGripper.right -= 2;
865 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
866 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
867
868 /* initialize Caption image rectangle */
869 SetRect (&lpBand->rcCapImage, rcBand.left,
870 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
871 rcBand.right,
872 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
873 }
874 }
875 else { /* no gripper will be drawn */
876 xoff = 0;
877 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
878 /* if no gripper but either image or text, then leave space */
879 xoff = REBAR_ALWAYS_SPACE;
880 /* initialize Caption image rectangle */
881 SetRect (&lpBand->rcCapImage,
882 rcBand.left, rcBand.top+xoff,
883 rcBand.right, rcBand.top+xoff);
884 }
885
886 /* image is visible */
887 if (lpBand->fStatus & HAS_IMAGE) {
888 lpBand->fDraw |= DRAW_IMAGE;
889
890 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
891 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
892
893 /* set initial caption text rectangle */
894 SetRect (&lpBand->rcCapText,
895 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
896 rcBand.right, rcBand.top+lpBand->cxHeader);
897 }
898 else {
899 /* set initial caption text rectangle */
900 SetRect (&lpBand->rcCapText,
901 rcBand.left, lpBand->rcCapImage.bottom,
902 rcBand.right, rcBand.top+lpBand->cxHeader);
903 }
904
905 /* text is visible */
906 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
907 lpBand->fDraw |= DRAW_TEXT;
908 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
909 lpBand->rcCapText.bottom);
910 }
911
912 /* set initial child window rectangle if there is a child */
913 if (lpBand->hwndChild) {
914 int cxBand = rcBand.right - rcBand.left;
915 xoff = (cxBand - lpBand->cyChild) / 2;
916 SetRect (&lpBand->rcChild,
917 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
918 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
919 }
920 else {
921 SetRect (&lpBand->rcChild,
922 rcBand.left, rcBand.top+lpBand->cxHeader,
923 rcBand.right, rcBand.bottom);
924 }
925
926 if (lpBand->fDraw & NTF_INVALIDATE) {
927 TRACE("invalidating (%d,%d)-(%d,%d)\n",
928 rcBand.left,
929 rcBand.top,
930 rcBand.right + SEP_WIDTH,
931 rcBand.bottom + SEP_WIDTH);
932 lpBand->fDraw &= ~NTF_INVALIDATE;
933 work = rcBand;
934 work.bottom += SEP_WIDTH;
935 work.right += SEP_WIDTH;
936 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
937 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
938 }
939
940 }
941 }
942
943
944 static VOID
945 REBAR_ForceResize (REBAR_INFO *infoPtr)
946 /* Function: This changes the size of the REBAR window to that */
947 /* calculated by REBAR_Layout. */
948 {
949 INT x, y, width, height;
950 INT xedge = 0, yedge = 0;
951 RECT rcSelf;
952
953 TRACE("new size [%d x %d]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
954
955 if (infoPtr->dwStyle & CCS_NORESIZE)
956 return;
957
958 if (infoPtr->dwStyle & WS_BORDER)
959 {
960 xedge = GetSystemMetrics(SM_CXEDGE);
961 yedge = GetSystemMetrics(SM_CYEDGE);
962 /* swap for CCS_VERT? */
963 }
964
965 /* compute rebar window rect in parent client coordinates */
966 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
967 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
968 translate_rect(infoPtr, &rcSelf, &rcSelf);
969
970 height = infoPtr->calcSize.cy + 2*yedge;
971 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
972 RECT rcParent;
973
974 x = -xedge;
975 width = infoPtr->calcSize.cx + 2*xedge;
976 y = 0; /* quiet compiler warning */
977 switch ( infoPtr->dwStyle & CCS_LAYOUT_MASK) {
978 case 0: /* shouldn't happen - see NCCreate */
979 case CCS_TOP:
980 y = ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER) - yedge;
981 break;
982 case CCS_NOMOVEY:
983 y = rcSelf.top;
984 break;
985 case CCS_BOTTOM:
986 GetClientRect(GetParent(infoPtr->hwndSelf), &rcParent);
987 translate_rect(infoPtr, &rcParent, &rcParent);
988 y = rcParent.bottom - infoPtr->calcSize.cy - yedge;
989 break;
990 }
991 }
992 else {
993 x = rcSelf.left;
994 /* As on Windows if the CCS_NODIVIDER is not present the control will move
995 * 2 pixel down after every layout */
996 y = rcSelf.top + ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
997 width = rcSelf.right - rcSelf.left;
998 }
999
1000 TRACE("hwnd %p, style=%08x, setting at (%d,%d) for (%d,%d)\n",
1001 infoPtr->hwndSelf, infoPtr->dwStyle, x, y, width, height);
1002
1003 /* Set flag to ignore next WM_SIZE message and resize the window */
1004 infoPtr->fStatus |= SELF_RESIZE;
1005 if ((infoPtr->dwStyle & CCS_VERT) == 0)
1006 SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
1007 else
1008 SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
1009 infoPtr->fStatus &= ~SELF_RESIZE;
1010 }
1011
1012
1013 static VOID
1014 REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
1015 {
1016 static const WCHAR strComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
1017 REBAR_BAND *lpBand;
1018 WCHAR szClassName[40];
1019 UINT i;
1020 NMREBARCHILDSIZE rbcz;
1021 HDWP deferpos;
1022
1023 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1024 ERR("BeginDeferWindowPos returned NULL\n");
1025
1026 for (i = start; i < endplus; i++) {
1027 lpBand = REBAR_GetBand(infoPtr, i);
1028
1029 if (HIDDENBAND(lpBand)) continue;
1030 if (lpBand->hwndChild) {
1031 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1032
1033 /* Always generate the RBN_CHILDSIZE even if child
1034 did not change */
1035 rbcz.uBand = i;
1036 rbcz.wID = lpBand->wID;
1037 rbcz.rcChild = lpBand->rcChild;
1038 translate_rect(infoPtr, &rbcz.rcBand, &lpBand->rcBand);
1039 if (infoPtr->dwStyle & CCS_VERT)
1040 rbcz.rcBand.top += lpBand->cxHeader;
1041 else
1042 rbcz.rcBand.left += lpBand->cxHeader;
1043 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1044 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1045 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1046 TRACE(" from (%s) to (%s)\n",
1047 wine_dbgstr_rect(&lpBand->rcChild),
1048 wine_dbgstr_rect(&rbcz.rcChild));
1049 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1050 }
1051
1052 /* native (IE4 in "Favorites" frame **1) does:
1053 * SetRect (&rc, -1, -1, -1, -1)
1054 * EqualRect (&rc,band->rc???)
1055 * if ret==0
1056 * CopyRect (band->rc????, &rc)
1057 * set flag outside of loop
1058 */
1059
1060 GetClassNameW (lpBand->hwndChild, szClassName, sizeof(szClassName)/sizeof(szClassName[0]));
1061 if (!lstrcmpW (szClassName, strComboBox) ||
1062 !lstrcmpW (szClassName, WC_COMBOBOXEXW)) {
1063 INT nEditHeight, yPos;
1064 RECT rc;
1065
1066 /* special placement code for combo or comboex box */
1067
1068
1069 /* get size of edit line */
1070 GetWindowRect (lpBand->hwndChild, &rc);
1071 nEditHeight = rc.bottom - rc.top;
1072 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1073
1074 /* center combo box inside child area */
1075 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1076 lpBand->hwndChild,
1077 lpBand->rcChild.left, yPos,
1078 lpBand->rcChild.right - lpBand->rcChild.left,
1079 nEditHeight);
1080 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1081 lpBand->rcChild.left,
1082 /*lpBand->rcChild.top*/ yPos,
1083 lpBand->rcChild.right - lpBand->rcChild.left,
1084 nEditHeight,
1085 SWP_NOZORDER);
1086 if (!deferpos)
1087 ERR("DeferWindowPos returned NULL\n");
1088 }
1089 else {
1090 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1091 lpBand->hwndChild,
1092 lpBand->rcChild.left, lpBand->rcChild.top,
1093 lpBand->rcChild.right - lpBand->rcChild.left,
1094 lpBand->rcChild.bottom - lpBand->rcChild.top);
1095 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1096 lpBand->rcChild.left,
1097 lpBand->rcChild.top,
1098 lpBand->rcChild.right - lpBand->rcChild.left,
1099 lpBand->rcChild.bottom - lpBand->rcChild.top,
1100 SWP_NOZORDER);
1101 if (!deferpos)
1102 ERR("DeferWindowPos returned NULL\n");
1103 }
1104 }
1105 }
1106 if (!EndDeferWindowPos(deferpos))
1107 ERR("EndDeferWindowPos returned NULL\n");
1108
1109 if (infoPtr->DoRedraw)
1110 UpdateWindow (infoPtr->hwndSelf);
1111
1112 /* native (from **1 above) does:
1113 * UpdateWindow(rebar)
1114 * REBAR_ForceResize
1115 * RBN_HEIGHTCHANGE if necessary
1116 * if ret from any EqualRect was 0
1117 * Goto "BeginDeferWindowPos"
1118 */
1119
1120 }
1121
1122 /* Returns the next visible band (the first visible band in [i+1; infoPtr->uNumBands) )
1123 * or infoPtr->uNumBands if none */
1124 static int next_visible(const REBAR_INFO *infoPtr, int i)
1125 {
1126 int n;
1127 for (n = i + 1; n < infoPtr->uNumBands; n++)
1128 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1129 break;
1130 return n;
1131 }
1132
1133 /* Returns the previous visible band (the last visible band in [0; i) )
1134 * or -1 if none */
1135 static int prev_visible(const REBAR_INFO *infoPtr, int i)
1136 {
1137 int n;
1138 for (n = i - 1; n >= 0; n--)
1139 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1140 break;
1141 return n;
1142 }
1143
1144 /* Returns the first visible band or infoPtr->uNumBands if none */
1145 static int first_visible(const REBAR_INFO *infoPtr)
1146 {
1147 return next_visible(infoPtr, -1); /* this works*/
1148 }
1149
1150 /* Returns the first visible band for the given row (or iBand if none) */
1151 static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
1152 {
1153 int iLastBand = iBand;
1154 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1155 while ((iBand = prev_visible(infoPtr, iBand)) >= 0) {
1156 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1157 break;
1158 else
1159 iLastBand = iBand;
1160 }
1161 return iLastBand;
1162 }
1163
1164 /* Returns the first visible band for the next row (or infoPtr->uNumBands if none) */
1165 static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
1166 {
1167 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1168 while ((iBand = next_visible(infoPtr, iBand)) < infoPtr->uNumBands)
1169 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1170 break;
1171 return iBand;
1172 }
1173
1174 /* Compute the rcBand.{left,right} from the cxEffective bands widths computed earlier.
1175 * iBeginBand must be visible */
1176 static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1177 {
1178 int xPos = 0, i;
1179 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1180 {
1181 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1182 if (lpBand->rcBand.left != xPos || lpBand->rcBand.right != xPos + lpBand->cxEffective) {
1183 lpBand->fDraw |= NTF_INVALIDATE;
1184 TRACE("Setting rect %d to %d,%d\n", i, xPos, xPos + lpBand->cxEffective);
1185 lpBand->rcBand.left = xPos;
1186 lpBand->rcBand.right = xPos + lpBand->cxEffective;
1187 }
1188 xPos += lpBand->cxEffective + SEP_WIDTH;
1189 }
1190 }
1191
1192 /* The rationale of this function is probably as follows: if we have some space
1193 * to distribute we want to add it to a band on the right. However we don't want
1194 * to unminimize a minimized band so we search for a band that is big enough.
1195 * For some reason "big enough" is defined as bigger than the minimum size of the
1196 * first band in the row
1197 */
1198 static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1199 {
1200 INT cxMinFirstBand = 0, i;
1201
1202 cxMinFirstBand = REBAR_GetBand(infoPtr, iBeginBand)->cxMinBand;
1203
1204 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1205 if (REBAR_GetBand(infoPtr, i)->cxEffective > cxMinFirstBand &&
1206 !(REBAR_GetBand(infoPtr, i)->fStyle & RBBS_FIXEDSIZE))
1207 break;
1208
1209 if (i < iBeginBand)
1210 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1211 if (REBAR_GetBand(infoPtr, i)->cxMinBand == cxMinFirstBand)
1212 break;
1213
1214 TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
1215 return REBAR_GetBand(infoPtr, i);
1216 }
1217
1218 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the right */
1219 static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1220 {
1221 REBAR_BAND *lpBand;
1222 INT width, i;
1223
1224 TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
1225 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1226 {
1227 lpBand = REBAR_GetBand(infoPtr, i);
1228
1229 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1230 cxShrink -= lpBand->cxEffective - width;
1231 lpBand->cxEffective = width;
1232 if (bEnforce && lpBand->cx > lpBand->cxEffective)
1233 lpBand->cx = lpBand->cxEffective;
1234 if (cxShrink == 0)
1235 break;
1236 }
1237 return cxShrink;
1238 }
1239
1240
1241 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the left.
1242 * iBeginBand must be visible */
1243 static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1244 {
1245 REBAR_BAND *lpBand;
1246 INT width, i;
1247
1248 TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
1249 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1250 {
1251 lpBand = REBAR_GetBand(infoPtr, i);
1252
1253 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1254 cxShrink -= lpBand->cxEffective - width;
1255 lpBand->cxEffective = width;
1256 if (bEnforce)
1257 lpBand->cx = lpBand->cxEffective;
1258 if (cxShrink == 0)
1259 break;
1260 }
1261 return cxShrink;
1262 }
1263
1264 /* Tries to move a band to a given offset within a row. */
1265 static int REBAR_MoveBandToRowOffset(REBAR_INFO *infoPtr, INT iBand, INT iFirstBand,
1266 INT iLastBand, INT xOff, BOOL reorder)
1267 {
1268 REBAR_BAND *insertBand = REBAR_GetBand(infoPtr, iBand);
1269 int xPos = 0, i;
1270 const BOOL setBreak = REBAR_GetBand(infoPtr, iFirstBand)->fStyle & RBBS_BREAK;
1271
1272 /* Find the band's new position */
1273 if(reorder)
1274 {
1275 /* Used during an LR band reorder drag */
1276 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1277 {
1278 if(xPos > xOff)
1279 break;
1280 xPos += REBAR_GetBand(infoPtr, i)->cxEffective + SEP_WIDTH;
1281 }
1282 }
1283 else
1284 {
1285 /* Used during a UD band insertion drag */
1286 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1287 {
1288 const REBAR_BAND *band = REBAR_GetBand(infoPtr, i);
1289 if(xPos + band->cxMinBand / 2 > xOff)
1290 break;
1291 xPos += band->cxEffective + SEP_WIDTH;
1292 }
1293 }
1294
1295 /* Move the band to its new position */
1296 DPA_DeletePtr(infoPtr->bands, iBand);
1297 if(i > iBand)
1298 i--;
1299 DPA_InsertPtr(infoPtr->bands, i, insertBand);
1300
1301 /* Ensure only the last band has the RBBS_BREAK flag set */
1302 insertBand->fStyle &= ~RBBS_BREAK;
1303 if(setBreak)
1304 REBAR_GetBand(infoPtr, iFirstBand)->fStyle |= RBBS_BREAK;
1305
1306 /* Return the currently grabbed band */
1307 if(infoPtr->iGrabbedBand == iBand)
1308 {
1309 infoPtr->iGrabbedBand = i;
1310 return i;
1311 }
1312 else return -1;
1313 }
1314
1315 /* Set the heights of the visible bands in [iBeginBand; iEndBand) to the max height. iBeginBand must be visible */
1316 static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
1317 {
1318 REBAR_BAND *lpBand;
1319 int yMaxHeight = 0;
1320 int yPos = yStart;
1321 int row = REBAR_GetBand(infoPtr, iBeginBand)->iRow;
1322 int i;
1323 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1324 {
1325 lpBand = REBAR_GetBand(infoPtr, i);
1326 lpBand->cyRowSoFar = yMaxHeight;
1327 yMaxHeight = max(yMaxHeight, lpBand->cyMinBand);
1328 }
1329 TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
1330
1331 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1332 {
1333 lpBand = REBAR_GetBand(infoPtr, i);
1334 /* we may be called for multiple rows if RBS_VARHEIGHT not set */
1335 if (lpBand->iRow != row) {
1336 yPos += yMaxHeight + SEP_WIDTH;
1337 row = lpBand->iRow;
1338 }
1339
1340 if (lpBand->rcBand.top != yPos || lpBand->rcBand.bottom != yPos + yMaxHeight) {
1341 lpBand->fDraw |= NTF_INVALIDATE;
1342 lpBand->rcBand.top = yPos;
1343 lpBand->rcBand.bottom = yPos + yMaxHeight;
1344 TRACE("Band %d: %s\n", i, wine_dbgstr_rect(&lpBand->rcBand));
1345 }
1346 }
1347 return yPos + yMaxHeight;
1348 }
1349
1350 /* Layout the row [iBeginBand; iEndBand). iBeginBand must be visible */
1351 static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
1352 {
1353 REBAR_BAND *lpBand;
1354 int i, extra;
1355 int width = 0;
1356
1357 TRACE("Adjusting row [%d;%d). Width: %d\n", iBeginBand, iEndBand, cx);
1358 for (i = iBeginBand; i < iEndBand; i++)
1359 REBAR_GetBand(infoPtr, i)->iRow = *piRow;
1360
1361 /* compute the extra space */
1362 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1363 {
1364 lpBand = REBAR_GetBand(infoPtr, i);
1365 if (i > iBeginBand)
1366 width += SEP_WIDTH;
1367 lpBand->cxEffective = max(lpBand->cxMinBand, lpBand->cx);
1368 width += lpBand->cxEffective;
1369 }
1370
1371 extra = cx - width;
1372 TRACE("Extra space: %d\n", extra);
1373 if (extra < 0) {
1374 int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
1375 if (ret > 0 && next_visible(infoPtr, iBeginBand) != iEndBand) /* one band may be longer than expected... */
1376 ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
1377 } else
1378 if (extra > 0) {
1379 lpBand = REBAR_FindBandToGrow(infoPtr, iBeginBand, iEndBand);
1380 lpBand->cxEffective += extra;
1381 }
1382
1383 REBAR_SetRowRectsX(infoPtr, iBeginBand, iEndBand);
1384 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1385 {
1386 if (*piRow > 0)
1387 *pyPos += SEP_WIDTH;
1388 *pyPos = REBAR_SetBandsHeight(infoPtr, iBeginBand, iEndBand, *pyPos);
1389 }
1390 (*piRow)++;
1391 }
1392
1393 static VOID
1394 REBAR_Layout(REBAR_INFO *infoPtr)
1395 {
1396 REBAR_BAND *lpBand;
1397 RECT rcAdj;
1398 SIZE oldSize;
1399 INT adjcx, i;
1400 INT rowstart;
1401 INT row = 0;
1402 INT xMin, yPos;
1403
1404 if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
1405 GetClientRect(infoPtr->hwndSelf, &rcAdj);
1406 else
1407 GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
1408 TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
1409
1410 adjcx = get_rect_cx(infoPtr, &rcAdj);
1411
1412 if (infoPtr->uNumBands == 0) {
1413 TRACE("No bands - setting size to (0,%d), vert: %lx\n", adjcx, infoPtr->dwStyle & CCS_VERT);
1414 infoPtr->calcSize.cx = adjcx;
1415 /* the calcSize.cy won't change for a 0 band rebar */
1416 infoPtr->uNumRows = 0;
1417 REBAR_ForceResize(infoPtr);
1418 return;
1419 }
1420
1421 yPos = 0;
1422 xMin = 0;
1423 rowstart = first_visible(infoPtr);
1424 /* divide rows */
1425 for (i = rowstart; i < infoPtr->uNumBands; i = next_visible(infoPtr, i))
1426 {
1427 lpBand = REBAR_GetBand(infoPtr, i);
1428
1429 if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->cxMinBand > adjcx)) {
1430 TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
1431 REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
1432 rowstart = i;
1433 xMin = 0;
1434 }
1435 else
1436 xMin += SEP_WIDTH;
1437
1438 xMin += lpBand->cxMinBand;
1439 }
1440 if (rowstart < infoPtr->uNumBands)
1441 REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
1442
1443 if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
1444 yPos = REBAR_SetBandsHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, 0);
1445
1446 infoPtr->uNumRows = row;
1447
1448 if (infoPtr->dwStyle & CCS_VERT)
1449 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1450 else
1451 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1452 /* now compute size of Rebar itself */
1453 oldSize = infoPtr->calcSize;
1454
1455 infoPtr->calcSize.cx = adjcx;
1456 infoPtr->calcSize.cy = yPos;
1457 TRACE("calcsize size=(%d, %d), origheight=(%d,%d)\n",
1458 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1459 oldSize.cx, oldSize.cy);
1460
1461 REBAR_DumpBand (infoPtr);
1462 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1463 REBAR_ForceResize (infoPtr);
1464
1465 /* note: after a RBN_HEIGHTCHANGE native sends once again all the RBN_CHILDSIZE
1466 * and does another ForceResize */
1467 if (oldSize.cy != infoPtr->calcSize.cy)
1468 {
1469 NMHDR heightchange;
1470 REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1471 REBAR_AutoSize(infoPtr, FALSE);
1472 }
1473 }
1474
1475 /* iBeginBand must be visible */
1476 static int
1477 REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
1478 {
1479 int cyBandsOld;
1480 int cyBandsNew = 0;
1481 int i;
1482
1483 TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
1484
1485 cyBandsOld = REBAR_GetBand(infoPtr, iBeginBand)->rcBand.bottom -
1486 REBAR_GetBand(infoPtr, iBeginBand)->rcBand.top;
1487 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1488 {
1489 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1490 int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
1491 int cyChild = round_child_height(lpBand, cyMaxChild);
1492
1493 if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
1494 {
1495 TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
1496 *fChanged = TRUE;
1497 lpBand->cyChild = cyChild;
1498 lpBand->fDraw |= NTF_INVALIDATE;
1499 update_min_band_height(infoPtr, lpBand);
1500 }
1501 cyBandsNew = max(cyBandsNew, lpBand->cyMinBand);
1502 }
1503 return cyBandsNew - cyBandsOld;
1504 }
1505
1506 /* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
1507 static VOID
1508 REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
1509 {
1510 int extra = height - infoPtr->calcSize.cy; /* may be negative */
1511 BOOL fChanged = FALSE;
1512 UINT uNumRows = infoPtr->uNumRows;
1513 int i;
1514
1515 if (uNumRows == 0) /* avoid division by 0 */
1516 return;
1517
1518 /* That's not exactly what Windows does but should be similar */
1519
1520 /* Pass one: break-up/glue rows */
1521 if (extra > 0)
1522 {
1523 for (i = prev_visible(infoPtr, infoPtr->uNumBands); i > 0; i = prev_visible(infoPtr, i))
1524 {
1525 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1526 int cyBreakExtra; /* additional cy for the rebar after a RBBS_BREAK on this band */
1527
1528 height = lpBand->rcBand.bottom - lpBand->rcBand.top;
1529
1530 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1531 cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
1532 else
1533 cyBreakExtra = height; /* 'height' => 'height' + 'height'*/
1534 cyBreakExtra += SEP_WIDTH;
1535
1536 if (extra <= cyBreakExtra / 2)
1537 break;
1538
1539 if (!(lpBand->fStyle & RBBS_BREAK))
1540 {
1541 TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
1542 lpBand->fStyle |= RBBS_BREAK;
1543 lpBand->fDraw |= NTF_INVALIDATE;
1544 fChanged = TRUE;
1545 extra -= cyBreakExtra;
1546 uNumRows++;
1547 /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
1548 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1549 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->cyMinBand;
1550 }
1551 }
1552 }
1553 /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
1554
1555 /* Pass two: increase/decrease control height */
1556 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1557 {
1558 int i = first_visible(infoPtr);
1559 int iRow = 0;
1560 while (i < infoPtr->uNumBands)
1561 {
1562 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1563 int extraForRow = extra / (int)(uNumRows - iRow);
1564 int rowEnd;
1565
1566 /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
1567 for (rowEnd = next_visible(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_visible(infoPtr, rowEnd))
1568 if (REBAR_GetBand(infoPtr, rowEnd)->iRow != lpBand->iRow ||
1569 REBAR_GetBand(infoPtr, rowEnd)->fStyle & RBBS_BREAK)
1570 break;
1571
1572 extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
1573 TRACE("extra = %d\n", extra);
1574 i = rowEnd;
1575 iRow++;
1576 }
1577 }
1578 else
1579 extra -= REBAR_SizeChildrenToHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
1580
1581 if (fChanged)
1582 REBAR_Layout(infoPtr);
1583 }
1584
1585 static VOID
1586 REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout)
1587 {
1588 RECT rc, rcNew;
1589 NMRBAUTOSIZE autosize;
1590
1591 if (needsLayout)
1592 REBAR_Layout(infoPtr);
1593 GetClientRect(infoPtr->hwndSelf, &rc);
1594 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, &rc));
1595 GetClientRect(infoPtr->hwndSelf, &rcNew);
1596
1597 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
1598 autosize.fChanged = (memcmp(&rc, &rcNew, sizeof(RECT)) == 0);
1599 autosize.rcTarget = rc;
1600 autosize.rcActual = rcNew;
1601 REBAR_Notify((NMHDR *)&autosize, infoPtr, RBN_AUTOSIZE);
1602 }
1603
1604 static VOID
1605 REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1606 /* Function: This routine evaluates the band specs supplied */
1607 /* by the user and updates the following 5 fields in */
1608 /* the internal band structure: cxHeader, cyHeader, cxMinBand, cyMinBand, fStatus */
1609 {
1610 UINT header=0;
1611 UINT textheight=0, imageheight = 0;
1612 UINT i, nonfixed;
1613 REBAR_BAND *tBand;
1614
1615 lpBand->fStatus = 0;
1616 lpBand->cxMinBand = 0;
1617 lpBand->cyMinBand = 0;
1618
1619 /* Data coming in from users into the cx... and cy... fields */
1620 /* may be bad, just garbage, because the user never clears */
1621 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1622 /* along if the fields exist in the input area. Here we must */
1623 /* determine if the data is valid. I have no idea how MS does */
1624 /* the validation, but it does because the RB_GETBANDINFO */
1625 /* returns a 0 when I know the sample program passed in an */
1626 /* address. Here I will use the algorithm that if the value */
1627 /* is greater than 65535 then it is bad and replace it with */
1628 /* a zero. Feel free to improve the algorithm. - GA 12/2000 */
1629 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1630 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1631 if (lpBand->cx > 65535) lpBand->cx = 0;
1632 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1633 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1634 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1635 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1636
1637 /* TODO : we could try return to the caller if a value changed so that */
1638 /* a REBAR_Layout is needed. Till now the caller should call it */
1639 /* it always (we should also check what native does) */
1640
1641 /* Header is where the image, text and gripper exist */
1642 /* in the band and precede the child window. */
1643
1644 /* count number of non-FIXEDSIZE and non-Hidden bands */
1645 nonfixed = 0;
1646 for (i=0; i<infoPtr->uNumBands; i++){
1647 tBand = REBAR_GetBand(infoPtr, i);
1648 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1649 nonfixed++;
1650 }
1651
1652 /* calculate gripper rectangle */
1653 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1654 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1655 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1656 ) {
1657 lpBand->fStatus |= HAS_GRIPPER;
1658 if (infoPtr->dwStyle & CCS_VERT)
1659 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1660 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1661 else
1662 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1663 else
1664 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1665 /* Always have 4 pixels before anything else */
1666 header += REBAR_ALWAYS_SPACE;
1667 }
1668
1669 /* image is visible */
1670 if (lpBand->iImage != -1 && (infoPtr->himl)) {
1671 lpBand->fStatus |= HAS_IMAGE;
1672 if (infoPtr->dwStyle & CCS_VERT) {
1673 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1674 imageheight = infoPtr->imageSize.cx + 4;
1675 }
1676 else {
1677 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1678 imageheight = infoPtr->imageSize.cy + 4;
1679 }
1680 }
1681
1682 /* text is visible */
1683 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
1684 !(lpBand->fStyle & RBBS_HIDETITLE)) {
1685 HDC hdc = GetDC (0);
1686 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1687 SIZE size;
1688
1689 lpBand->fStatus |= HAS_TEXT;
1690 GetTextExtentPoint32W (hdc, lpBand->lpText,
1691 lstrlenW (lpBand->lpText), &size);
1692 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1693 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1694
1695 SelectObject (hdc, hOldFont);
1696 ReleaseDC (0, hdc);
1697 }
1698
1699 /* if no gripper but either image or text, then leave space */
1700 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1701 !(lpBand->fStatus & HAS_GRIPPER)) {
1702 header += REBAR_ALWAYS_SPACE;
1703 }
1704
1705 /* check if user overrode the header value */
1706 if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
1707 lpBand->cxHeader = header;
1708 lpBand->cyHeader = max(textheight, imageheight);
1709
1710 /* Now compute minimum size of child window */
1711 update_min_band_height(infoPtr, lpBand); /* update lpBand->cyMinBand from cyHeader and cyChild*/
1712
1713 lpBand->cxMinBand = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
1714 if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
1715 lpBand->cxMinBand += CHEVRON_WIDTH;
1716 }
1717
1718 static UINT
1719 REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
1720 /* Function: This routine copies the supplied values from */
1721 /* user input (lprbbi) to the internal band structure. */
1722 /* It returns the mask of what changed. */
1723 {
1724 UINT uChanged = 0x0;
1725
1726 lpBand->fMask |= lprbbi->fMask;
1727
1728 if( (lprbbi->fMask & RBBIM_STYLE) &&
1729 (lpBand->fStyle != lprbbi->fStyle ) )
1730 {
1731 lpBand->fStyle = lprbbi->fStyle;
1732 uChanged |= RBBIM_STYLE;
1733 }
1734
1735 if( (lprbbi->fMask & RBBIM_COLORS) &&
1736 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
1737 ( lpBand->clrBack != lprbbi->clrBack ) ) )
1738 {
1739 lpBand->clrFore = lprbbi->clrFore;
1740 lpBand->clrBack = lprbbi->clrBack;
1741 uChanged |= RBBIM_COLORS;
1742 }
1743
1744 if( (lprbbi->fMask & RBBIM_IMAGE) &&
1745 ( lpBand->iImage != lprbbi->iImage ) )
1746 {
1747 lpBand->iImage = lprbbi->iImage;
1748 uChanged |= RBBIM_IMAGE;
1749 }
1750
1751 if( (lprbbi->fMask & RBBIM_CHILD) &&
1752 (lprbbi->hwndChild != lpBand->hwndChild ) )
1753 {
1754 if (lprbbi->hwndChild) {
1755 lpBand->hwndChild = lprbbi->hwndChild;
1756 lpBand->hwndPrevParent =
1757 SetParent (lpBand->hwndChild, hwnd);
1758 /* below in trace from WinRAR */
1759 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
1760 /* above in trace from WinRAR */
1761 }
1762 else {
1763 TRACE("child: %p prev parent: %p\n",
1764 lpBand->hwndChild, lpBand->hwndPrevParent);
1765 lpBand->hwndChild = 0;
1766 lpBand->hwndPrevParent = 0;
1767 }
1768 uChanged |= RBBIM_CHILD;
1769 }
1770
1771 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
1772 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
1773 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
1774 ( (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) &&
1775 ( (lpBand->cyChild != lprbbi->cyChild ) ||
1776 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
1777 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
1778 ( (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE) &&
1779 ( (lpBand->cyChild ||
1780 lpBand->cyMaxChild ||
1781 lpBand->cyIntegral ) ) ) ) )
1782 {
1783 lpBand->cxMinChild = lprbbi->cxMinChild;
1784 lpBand->cyMinChild = lprbbi->cyMinChild;
1785 /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
1786 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
1787 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1788 lpBand->cyIntegral = lprbbi->cyIntegral;
1789
1790 lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild); /* make (cyChild - cyMinChild) a multiple of cyIntergral */
1791 }
1792 else {
1793 lpBand->cyChild = lpBand->cyMinChild;
1794 lpBand->cyMaxChild = 0x7fffffff;
1795 lpBand->cyIntegral = 0;
1796 }
1797 uChanged |= RBBIM_CHILDSIZE;
1798 }
1799
1800 if( (lprbbi->fMask & RBBIM_SIZE) &&
1801 (lpBand->cx != lprbbi->cx ) )
1802 {
1803 lpBand->cx = lprbbi->cx;
1804 uChanged |= RBBIM_SIZE;
1805 }
1806
1807 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
1808 ( lpBand->hbmBack != lprbbi->hbmBack ) )
1809 {
1810 lpBand->hbmBack = lprbbi->hbmBack;
1811 uChanged |= RBBIM_BACKGROUND;
1812 }
1813
1814 if( (lprbbi->fMask & RBBIM_ID) &&
1815 (lpBand->wID != lprbbi->wID ) )
1816 {
1817 lpBand->wID = lprbbi->wID;
1818 uChanged |= RBBIM_ID;
1819 }
1820
1821 /* check for additional data */
1822 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE) {
1823 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
1824 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
1825 {
1826 lpBand->cxIdeal = lprbbi->cxIdeal;
1827 uChanged |= RBBIM_IDEALSIZE;
1828 }
1829
1830 if( (lprbbi->fMask & RBBIM_LPARAM) &&
1831 (lpBand->lParam != lprbbi->lParam ) )
1832 {
1833 lpBand->lParam = lprbbi->lParam;
1834 uChanged |= RBBIM_LPARAM;
1835 }
1836
1837 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
1838 (lpBand->cxHeader != lprbbi->cxHeader ) )
1839 {
1840 lpBand->cxHeader = lprbbi->cxHeader;
1841 lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
1842 uChanged |= RBBIM_HEADERSIZE;
1843 }
1844 }
1845
1846 return uChanged;
1847 }
1848
1849 static LRESULT REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, HDC hdc)
1850 /* Function: This erases the background rectangle by drawing */
1851 /* each band with its background color (or the default) and */
1852 /* draws each bands right separator if necessary. The row */
1853 /* separators are drawn on the first band of the next row. */
1854 {
1855 REBAR_BAND *lpBand;
1856 UINT i;
1857 INT oldrow;
1858 RECT cr;
1859 COLORREF old = CLR_NONE, new;
1860 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1861
1862 GetClientRect (infoPtr->hwndSelf, &cr);
1863
1864 oldrow = -1;
1865 for(i=0; i<infoPtr->uNumBands; i++) {
1866 RECT rcBand;
1867 lpBand = REBAR_GetBand(infoPtr, i);
1868 if (HIDDENBAND(lpBand)) continue;
1869 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1870
1871 /* draw band separator between rows */
1872 if (lpBand->iRow != oldrow) {
1873 oldrow = lpBand->iRow;
1874 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1875 RECT rcRowSep;
1876 rcRowSep = rcBand;
1877 if (infoPtr->dwStyle & CCS_VERT) {
1878 rcRowSep.right += SEP_WIDTH_SIZE;
1879 rcRowSep.bottom = infoPtr->calcSize.cx;
1880 if (theme)
1881 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_RIGHT, NULL);
1882 else
1883 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
1884 }
1885 else {
1886 rcRowSep.bottom += SEP_WIDTH_SIZE;
1887 rcRowSep.right = infoPtr->calcSize.cx;
1888 if (theme)
1889 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1890 else
1891 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
1892 }
1893 TRACE ("drawing band separator bottom (%s)\n",
1894 wine_dbgstr_rect(&rcRowSep));
1895 }
1896 }
1897
1898 /* draw band separator between bands in a row */
1899 if (infoPtr->dwStyle & RBS_BANDBORDERS && lpBand->rcBand.left > 0) {
1900 RECT rcSep;
1901 rcSep = rcBand;
1902 if (infoPtr->dwStyle & CCS_VERT) {
1903 rcSep.bottom = rcSep.top;
1904 rcSep.top -= SEP_WIDTH_SIZE;
1905 if (theme)
1906 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1907 else
1908 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
1909 }
1910 else {
1911 rcSep.right = rcSep.left;
1912 rcSep.left -= SEP_WIDTH_SIZE;
1913 if (theme)
1914 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_RIGHT, NULL);
1915 else
1916 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
1917 }
1918 TRACE("drawing band separator right (%s)\n",
1919 wine_dbgstr_rect(&rcSep));
1920 }
1921
1922 /* draw the actual background */
1923 if (lpBand->clrBack != CLR_NONE) {
1924 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
1925 lpBand->clrBack;
1926 #if GLATESTING
1927 /* testing only - make background green to see it */
1928 new = RGB(0,128,0);
1929 #endif
1930 }
1931 else {
1932 /* In the absence of documentation for Rebar vs. CLR_NONE,
1933 * we will use the default BtnFace color. Note documentation
1934 * exists for Listview and Imagelist.
1935 */
1936 new = infoPtr->clrBtnFace;
1937 #if GLATESTING
1938 /* testing only - make background green to see it */
1939 new = RGB(0,128,0);
1940 #endif
1941 }
1942
1943 if (theme)
1944 {
1945 /* When themed, the background color is ignored (but not a
1946 * background bitmap */
1947 DrawThemeBackground (theme, hdc, 0, 0, &cr, &rcBand);
1948 }
1949 else
1950 {
1951 old = SetBkColor (hdc, new);
1952 TRACE("%s background color=0x%06x, band %s\n",
1953 (lpBand->clrBack == CLR_NONE) ? "none" :
1954 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
1955 GetBkColor(hdc), wine_dbgstr_rect(&rcBand));
1956 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &rcBand, NULL, 0, 0);
1957 if (lpBand->clrBack != CLR_NONE)
1958 SetBkColor (hdc, old);
1959 }
1960 }
1961 return TRUE;
1962 }
1963
1964 static void
1965 REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
1966 {
1967 REBAR_BAND *lpBand;
1968 RECT rect;
1969 UINT iCount;
1970
1971 GetClientRect (infoPtr->hwndSelf, &rect);
1972
1973 *pFlags = RBHT_NOWHERE;
1974 if (PtInRect (&rect, *lpPt))
1975 {
1976 if (infoPtr->uNumBands == 0) {
1977 *pFlags = RBHT_NOWHERE;
1978 if (pBand)
1979 *pBand = -1;
1980 TRACE("NOWHERE\n");
1981 return;
1982 }
1983 else {
1984 /* somewhere inside */
1985 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
1986 RECT rcBand;
1987 lpBand = REBAR_GetBand(infoPtr, iCount);
1988 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1989 if (HIDDENBAND(lpBand)) continue;
1990 if (PtInRect (&rcBand, *lpPt)) {
1991 if (pBand)
1992 *pBand = iCount;
1993 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
1994 *pFlags = RBHT_GRABBER;
1995 TRACE("ON GRABBER %d\n", iCount);
1996 return;
1997 }
1998 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
1999 *pFlags = RBHT_CAPTION;
2000 TRACE("ON CAPTION %d\n", iCount);
2001 return;
2002 }
2003 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2004 *pFlags = RBHT_CAPTION;
2005 TRACE("ON CAPTION %d\n", iCount);
2006 return;
2007 }
2008 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2009 *pFlags = RBHT_CLIENT;
2010 TRACE("ON CLIENT %d\n", iCount);
2011 return;
2012 }
2013 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
2014 *pFlags = RBHT_CHEVRON;
2015 TRACE("ON CHEVRON %d\n", iCount);
2016 return;
2017 }
2018 else {
2019 *pFlags = RBHT_NOWHERE;
2020 TRACE("NOWHERE %d\n", iCount);
2021 return;
2022 }
2023 }
2024 }
2025
2026 *pFlags = RBHT_NOWHERE;
2027 if (pBand)
2028 *pBand = -1;
2029
2030 TRACE("NOWHERE\n");
2031 return;
2032 }
2033 }
2034 else {
2035 *pFlags = RBHT_NOWHERE;
2036 if (pBand)
2037 *pBand = -1;
2038 TRACE("NOWHERE\n");
2039 return;
2040 }
2041 }
2042
2043 static void
2044 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2045 /* Function: This will implement the functionality of a */
2046 /* Gripper drag within a row. It will not implement "out- */
2047 /* of-row" drags. (They are detected and handled in */
2048 /* REBAR_MouseMove.) */
2049 {
2050 REBAR_BAND *hitBand;
2051 INT iHitBand, iRowBegin, iRowEnd;
2052 INT movement, xBand, cxLeft = 0;
2053 BOOL shrunkBands = FALSE;
2054
2055 iHitBand = infoPtr->iGrabbedBand;
2056 iRowBegin = get_row_begin_for_band(infoPtr, iHitBand);
2057 iRowEnd = get_row_end_for_band(infoPtr, iHitBand);
2058 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2059
2060 xBand = hitBand->rcBand.left;
2061 movement = (infoPtr->dwStyle&CCS_VERT ? ptsmove->y : ptsmove->x)
2062 - (xBand + REBAR_PRE_GRIPPER - infoPtr->ihitoffset);
2063
2064 /* Dragging the first band in a row cannot cause shrinking */
2065 if(iHitBand != iRowBegin)
2066 {
2067 if (movement < 0) {
2068 cxLeft = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iHitBand, -movement, TRUE);
2069
2070 if(cxLeft < -movement)
2071 {
2072 hitBand->cxEffective += -movement - cxLeft;
2073 hitBand->cx = hitBand->cxEffective;
2074 shrunkBands = TRUE;
2075 }
2076
2077 } else if (movement > 0) {
2078
2079 cxLeft = movement;
2080 if (prev_visible(infoPtr, iHitBand) >= 0)
2081 cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
2082
2083 if(cxLeft < movement)
2084 {
2085 REBAR_BAND *lpPrev = REBAR_GetBand(infoPtr, prev_visible(infoPtr, iHitBand));
2086 lpPrev->cxEffective += movement - cxLeft;
2087 lpPrev->cx = hitBand->cxEffective;
2088 shrunkBands = TRUE;
2089 }
2090
2091 }
2092 }
2093
2094 if(!shrunkBands)
2095 {
2096 /* It was not possible to move the band by shrinking bands.
2097 * Try relocating the band instead. */
2098 REBAR_MoveBandToRowOffset(infoPtr, iHitBand, iRowBegin,
2099 iRowEnd, xBand + movement, TRUE);
2100 }
2101
2102 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2103 if (infoPtr->dwStyle & CCS_VERT)
2104 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
2105 else
2106 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
2107 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2108 }
2109
2110 static void
2111 REBAR_HandleUDDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2112 {
2113 INT yOff = (infoPtr->dwStyle & CCS_VERT) ? ptsmove->x : ptsmove->y;
2114 INT iHitBand, iRowBegin, iNextRowBegin;
2115 REBAR_BAND *hitBand, *rowBeginBand;
2116
2117 if(infoPtr->uNumBands <= 0)
2118 ERR("There are no bands in this rebar\n");
2119
2120 /* Up/down dragging can only occur when there is more than one
2121 * band in the rebar */
2122 if(infoPtr->uNumBands <= 1)
2123 return;
2124
2125 iHitBand = infoPtr->iGrabbedBand;
2126 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2127
2128 /* If we're taking a band that has the RBBS_BREAK style set, this
2129 * style needs to be reapplied to the band that is going to become
2130 * the new start of the row. */
2131 if((hitBand->fStyle & RBBS_BREAK) &&
2132 (iHitBand < infoPtr->uNumBands - 1))
2133 REBAR_GetBand(infoPtr, iHitBand + 1)->fStyle |= RBBS_BREAK;
2134
2135 if(yOff < 0)
2136 {
2137 /* Place the band above the current top row */
2138 DPA_DeletePtr(infoPtr->bands, iHitBand);
2139 hitBand->fStyle &= RBBS_BREAK;
2140 REBAR_GetBand(infoPtr, 0)->fStyle |= RBBS_BREAK;
2141 infoPtr->iGrabbedBand = DPA_InsertPtr(
2142 infoPtr->bands, 0, hitBand);
2143 }
2144 else if(yOff > REBAR_GetBand(infoPtr, infoPtr->uNumBands - 1)->rcBand.bottom)
2145 {
2146 /* Place the band below the current bottom row */
2147 DPA_DeletePtr(infoPtr->bands, iHitBand);
2148 hitBand->fStyle |= RBBS_BREAK;
2149 infoPtr->iGrabbedBand = DPA_InsertPtr(
2150 infoPtr->bands, infoPtr->uNumBands - 1, hitBand);
2151 }
2152 else
2153 {
2154 /* Place the band in the prexisting row the mouse is hovering over */
2155 iRowBegin = first_visible(infoPtr);
2156 while(iRowBegin < infoPtr->uNumBands)
2157 {
2158 iNextRowBegin = get_row_end_for_band(infoPtr, iRowBegin);
2159 rowBeginBand = REBAR_GetBand(infoPtr, iRowBegin);
2160 if(rowBeginBand->rcBand.bottom > yOff)
2161 {
2162 REBAR_MoveBandToRowOffset(
2163 infoPtr, iHitBand, iRowBegin, iNextRowBegin,
2164 ((infoPtr->dwStyle & CCS_VERT) ? ptsmove->y : ptsmove->x)
2165 - REBAR_PRE_GRIPPER - infoPtr->ihitoffset, FALSE);
2166 break;
2167 }
2168
2169 iRowBegin = iNextRowBegin;
2170 }
2171 }
2172
2173 REBAR_Layout(infoPtr);
2174 }
2175
2176
2177 /* << REBAR_BeginDrag >> */
2178
2179
2180 static LRESULT
2181 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam)
2182 {
2183 UINT uBand = (UINT)wParam;
2184 REBAR_BAND *lpBand;
2185
2186 if (uBand >= infoPtr->uNumBands)
2187 return FALSE;
2188
2189 TRACE("deleting band %u!\n", uBand);
2190 lpBand = REBAR_GetBand(infoPtr, uBand);
2191 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2192 /* TODO: a return of 1 should probably cancel the deletion */
2193
2194 if (lpBand->hwndChild)
2195 ShowWindow(lpBand->hwndChild, SW_HIDE);
2196 Free(lpBand->lpText);
2197 Free(lpBand);
2198
2199 infoPtr->uNumBands--;
2200 DPA_DeletePtr(infoPtr->bands, uBand);
2201
2202 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2203
2204 /* if only 1 band left the re-validate to possible eliminate gripper */
2205 if (infoPtr->uNumBands == 1)
2206 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2207
2208 REBAR_Layout(infoPtr);
2209
2210 return TRUE;
2211 }
2212
2213
2214 /* << REBAR_DragMove >> */
2215 /* << REBAR_EndDrag >> */
2216
2217
2218 static LRESULT
2219 REBAR_GetBandBorders (const REBAR_INFO *infoPtr, UINT uBand, RECT *lpRect)
2220 {
2221 REBAR_BAND *lpBand;
2222
2223 if (!lpRect)
2224 return 0;
2225 if (uBand >= infoPtr->uNumBands)
2226 return 0;
2227
2228 lpBand = REBAR_GetBand(infoPtr, uBand);
2229
2230 /* FIXME - the following values were determined by experimentation */
2231 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2232 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2233 /* difference in size of the control area with and without the */
2234 /* style. - GA */
2235 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2236 if (infoPtr->dwStyle & CCS_VERT) {
2237 lpRect->left = 1;
2238 lpRect->top = lpBand->cxHeader + 4;
2239 lpRect->right = 1;
2240 lpRect->bottom = 0;
2241 }
2242 else {
2243 lpRect->left = lpBand->cxHeader + 4;
2244 lpRect->top = 1;
2245 lpRect->right = 0;
2246 lpRect->bottom = 1;
2247 }
2248 }
2249 else {
2250 lpRect->left = lpBand->cxHeader;
2251 }
2252 return 0;
2253 }
2254
2255
2256 static inline LRESULT
2257 REBAR_GetBandCount (const REBAR_INFO *infoPtr)
2258 {
2259 TRACE("band count %u!\n", infoPtr->uNumBands);
2260
2261 return infoPtr->uNumBands;
2262 }
2263
2264
2265 static LRESULT
2266 REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, UINT uIndex, LPREBARBANDINFOW lprbbi, BOOL bUnicode)
2267 {
2268 REBAR_BAND *lpBand;
2269
2270 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2271 return FALSE;
2272
2273 if (uIndex >= infoPtr->uNumBands)
2274 return FALSE;
2275
2276 TRACE("index %u (bUnicode=%d)\n", uIndex, bUnicode);
2277
2278 /* copy band information */
2279 lpBand = REBAR_GetBand(infoPtr, uIndex);
2280
2281 if (lprbbi->fMask & RBBIM_STYLE)
2282 lprbbi->fStyle = lpBand->fStyle;
2283
2284 if (lprbbi->fMask & RBBIM_COLORS) {
2285 lprbbi->clrFore = lpBand->clrFore;
2286 lprbbi->clrBack = lpBand->clrBack;
2287 if (lprbbi->clrBack == CLR_DEFAULT)
2288 lprbbi->clrBack = infoPtr->clrBtnFace;
2289 }
2290
2291 if (lprbbi->fMask & RBBIM_TEXT) {
2292 if (bUnicode)
2293 Str_GetPtrW(lpBand->lpText, lprbbi->lpText, lprbbi->cch);
2294 else
2295 Str_GetPtrWtoA(lpBand->lpText, (LPSTR)lprbbi->lpText, lprbbi->cch);
2296 }
2297
2298 if (lprbbi->fMask & RBBIM_IMAGE)
2299 lprbbi->iImage = lpBand->iImage;
2300
2301 if (lprbbi->fMask & RBBIM_CHILD)
2302 lprbbi->hwndChild = lpBand->hwndChild;
2303
2304 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2305 lprbbi->cxMinChild = lpBand->cxMinChild;
2306 lprbbi->cyMinChild = lpBand->cyMinChild;
2307 /* to make tests pass we follow Windows behaviour and allow to read these fields only
2308 * for RBBS_VARIABLEHEIGHTS bands */
2309 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2310 lprbbi->cyChild = lpBand->cyChild;
2311 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2312 lprbbi->cyIntegral = lpBand->cyIntegral;
2313 }
2314 }
2315
2316 if (lprbbi->fMask & RBBIM_SIZE)
2317 lprbbi->cx = lpBand->cx;
2318
2319 if (lprbbi->fMask & RBBIM_BACKGROUND)
2320 lprbbi->hbmBack = lpBand->hbmBack;
2321
2322 if (lprbbi->fMask & RBBIM_ID)
2323 lprbbi->wID = lpBand->wID;
2324
2325 /* check for additional data */
2326 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE) {
2327 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2328 lprbbi->cxIdeal = lpBand->cxIdeal;
2329
2330 if (lprbbi->fMask & RBBIM_LPARAM)
2331 lprbbi->lParam = lpBand->lParam;
2332
2333 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2334 lprbbi->cxHeader = lpBand->cxHeader;
2335 }
2336
2337 REBAR_DumpBandInfo(lprbbi);
2338
2339 return TRUE;
2340 }
2341
2342
2343 static LRESULT
2344 REBAR_GetBarHeight (const REBAR_INFO *infoPtr)
2345 {
2346 INT nHeight;
2347
2348 nHeight = infoPtr->calcSize.cy;
2349
2350 TRACE("height = %d\n", nHeight);
2351
2352 return nHeight;
2353 }
2354
2355
2356 static LRESULT
2357 REBAR_GetBarInfo (const REBAR_INFO *infoPtr, LPREBARINFO lpInfo)
2358 {
2359 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2360 return FALSE;
2361
2362 TRACE("getting bar info!\n");
2363
2364 if (infoPtr->himl) {
2365 lpInfo->himl = infoPtr->himl;
2366 lpInfo->fMask |= RBIM_IMAGELIST;
2367 }
2368
2369 return TRUE;
2370 }
2371
2372
2373 static inline LRESULT
2374 REBAR_GetBkColor (const REBAR_INFO *infoPtr)
2375 {
2376 COLORREF clr = infoPtr->clrBk;
2377
2378 if (clr == CLR_DEFAULT)
2379 clr = infoPtr->clrBtnFace;
2380
2381 TRACE("background color 0x%06x!\n", clr);
2382
2383 return clr;
2384 }
2385
2386
2387 /* << REBAR_GetColorScheme >> */
2388 /* << REBAR_GetDropTarget >> */
2389
2390
2391 static LRESULT
2392 REBAR_GetPalette (const REBAR_INFO *infoPtr)
2393 {
2394 FIXME("empty stub!\n");
2395
2396 return 0;
2397 }
2398
2399
2400 static LRESULT
2401 REBAR_GetRect (const REBAR_INFO *infoPtr, INT iBand, RECT *lprc)
2402 {
2403 REBAR_BAND *lpBand;
2404
2405 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2406 return FALSE;
2407 if (!lprc)
2408 return FALSE;
2409
2410 lpBand = REBAR_GetBand(infoPtr, iBand);
2411 /* For CCS_VERT the coordinates will be swapped - like on Windows */
2412 CopyRect (lprc, &lpBand->rcBand);
2413
2414 TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
2415
2416 return TRUE;
2417 }
2418
2419
2420 static inline LRESULT
2421 REBAR_GetRowCount (const REBAR_INFO *infoPtr)
2422 {
2423 TRACE("%u\n", infoPtr->uNumRows);
2424
2425 return infoPtr->uNumRows;
2426 }
2427
2428
2429 static LRESULT
2430 REBAR_GetRowHeight (const REBAR_INFO *infoPtr, INT iRow)
2431 {
2432 int j = 0, ret = 0;
2433 UINT i;
2434 REBAR_BAND *lpBand;
2435
2436 for (i=0; i<infoPtr->uNumBands; i++) {
2437 lpBand = REBAR_GetBand(infoPtr, i);
2438 if (HIDDENBAND(lpBand)) continue;
2439 if (lpBand->iRow != iRow) continue;
2440 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2441 if (j > ret) ret = j;
2442 }
2443
2444 TRACE("row %d, height %d\n", iRow, ret);
2445
2446 return ret;
2447 }
2448
2449
2450 static inline LRESULT
2451 REBAR_GetTextColor (const REBAR_INFO *infoPtr)
2452 {
2453 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2454
2455 return infoPtr->clrText;
2456 }
2457
2458
2459 static inline LRESULT
2460 REBAR_GetToolTips (const REBAR_INFO *infoPtr)
2461 {
2462 return (LRESULT)infoPtr->hwndToolTip;
2463 }
2464
2465
2466 static inline LRESULT
2467 REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
2468 {
2469 TRACE("%s hwnd=%p\n",
2470 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2471
2472 return infoPtr->bUnicode;
2473 }
2474
2475
2476 static inline LRESULT
2477 REBAR_GetVersion (const REBAR_INFO *infoPtr)
2478 {
2479 TRACE("version %d\n", infoPtr->iVersion);
2480 return infoPtr->iVersion;
2481 }
2482
2483
2484 static LRESULT
2485 REBAR_HitTest (const REBAR_INFO *infoPtr, LPRBHITTESTINFO lprbht)
2486 {
2487 if (!lprbht)
2488 return -1;
2489
2490 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2491
2492 return lprbht->iBand;
2493 }
2494
2495
2496 static LRESULT
2497 REBAR_IdToIndex (const REBAR_INFO *infoPtr, UINT uId)
2498 {
2499 UINT i;
2500
2501 if (infoPtr->uNumBands < 1)
2502 return -1;
2503
2504 for (i = 0; i < infoPtr->uNumBands; i++) {
2505 if (REBAR_GetBand(infoPtr, i)->wID == uId) {
2506 TRACE("id %u is band %u found!\n", uId, i);
2507 return i;
2508 }
2509 }
2510
2511 TRACE("id %u is not found\n", uId);
2512 return -1;
2513 }
2514
2515
2516 static LRESULT
2517 REBAR_InsertBandT(REBAR_INFO *infoPtr, INT iIndex, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2518 {
2519 REBAR_BAND *lpBand;
2520
2521 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2522 return FALSE;
2523
2524 /* trace the index as signed to see the -1 */
2525 TRACE("insert band at %d (bUnicode=%d)!\n", iIndex, bUnicode);
2526 REBAR_DumpBandInfo(lprbbi);
2527
2528 if (!(lpBand = Alloc(sizeof(REBAR_BAND)))) return FALSE;
2529 if ((iIndex == -1) || (iIndex > infoPtr->uNumBands))
2530 iIndex = infoPtr->uNumBands;
2531 if (DPA_InsertPtr(infoPtr->bands, iIndex, lpBand) == -1)
2532 {
2533 Free(lpBand);
2534 return FALSE;
2535 }
2536 infoPtr->uNumBands++;
2537
2538 TRACE("index %d!\n", iIndex);
2539
2540 /* initialize band */
2541 memset(lpBand, 0, sizeof(*lpBand));
2542 lpBand->clrFore = infoPtr->clrText;
2543 lpBand->clrBack = infoPtr->clrBk;
2544 lpBand->iImage = -1;
2545
2546 REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
2547
2548 /* Make sure the defaults for these are correct */
2549 if (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE || !(lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2550 lpBand->cyChild = lpBand->cyMinChild;
2551 lpBand->cyMaxChild = 0x7fffffff;
2552 lpBand->cyIntegral = 0;
2553 }
2554
2555 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2556 if (bUnicode)
2557 Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
2558 else
2559 Str_SetPtrAtoW(&lpBand->lpText, (LPSTR)lprbbi->lpText);
2560 }
2561
2562 REBAR_ValidateBand (infoPtr, lpBand);
2563 /* On insert of second band, revalidate band 1 to possible add gripper */
2564 if (infoPtr->uNumBands == 2)
2565 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2566
2567 REBAR_DumpBand (infoPtr);
2568
2569 REBAR_Layout(infoPtr);
2570 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2571
2572 return TRUE;
2573 }
2574
2575
2576 static LRESULT
2577 REBAR_MaximizeBand (const REBAR_INFO *infoPtr, INT iBand, LPARAM lParam)
2578 {
2579 REBAR_BAND *lpBand;
2580 int iRowBegin, iRowEnd;
2581 int cxDesired, extra, extraOrig;
2582 int cxIdealBand;
2583
2584 /* Validate */
2585 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2586 /* error !!! */
2587 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
2588 iBand, infoPtr->uNumBands);
2589 return FALSE;
2590 }
2591
2592 lpBand = REBAR_GetBand(infoPtr, iBand);
2593
2594 if (lpBand->fStyle & RBBS_HIDDEN)
2595 {
2596 /* Windows is buggy and creates a hole */
2597 WARN("Ignoring maximize request on a hidden band (%d)\n", iBand);
2598 return FALSE;
2599 }
2600
2601 cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
2602 if (lParam && (lpBand->cxEffective < cxIdealBand))
2603 cxDesired = cxIdealBand;
2604 else
2605 cxDesired = infoPtr->calcSize.cx;
2606
2607 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2608 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2609 extraOrig = extra = cxDesired - lpBand->cxEffective;
2610 if (extra > 0)
2611 extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iBand, extra, TRUE);
2612 if (extra > 0)
2613 extra = REBAR_ShrinkBandsLTR(infoPtr, next_visible(infoPtr, iBand), iRowEnd, extra, TRUE);
2614 lpBand->cxEffective += extraOrig - extra;
2615 lpBand->cx = lpBand->cxEffective;
2616 TRACE("(%d, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", iBand, lParam, cxDesired, lpBand->cx, extraOrig, extra);
2617 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2618
2619 if (infoPtr->dwStyle & CCS_VERT)
2620 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2621 else
2622 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2623 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2624 return TRUE;
2625
2626 }
2627
2628
2629 static LRESULT
2630 REBAR_MinimizeBand (const REBAR_INFO *infoPtr, INT iBand)
2631 {
2632 REBAR_BAND *lpBand;
2633 int iPrev, iRowBegin, iRowEnd;
2634
2635 /* A "minimize" band is equivalent to "dragging" the gripper
2636 * of than band to the right till the band is only the size
2637 * of the cxHeader.
2638 */
2639
2640 /* Validate */
2641 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2642 /* error !!! */
2643 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
2644 iBand, infoPtr->uNumBands);
2645 return FALSE;
2646 }
2647
2648 /* compute amount of movement and validate */
2649 lpBand = REBAR_GetBand(infoPtr, iBand);
2650
2651 if (lpBand->fStyle & RBBS_HIDDEN)
2652 {
2653 /* Windows is buggy and creates a hole/overlap */
2654 WARN("Ignoring minimize request on a hidden band (%d)\n", iBand);
2655 return FALSE;
2656 }
2657
2658 iPrev = prev_visible(infoPtr, iBand);
2659 /* if first band in row */
2660 if (iPrev < 0 || REBAR_GetBand(infoPtr, iPrev)->iRow != lpBand->iRow) {
2661 int iNext = next_visible(infoPtr, iBand);
2662 if (iNext < infoPtr->uNumBands && REBAR_GetBand(infoPtr, iNext)->iRow == lpBand->iRow) {
2663 TRACE("(%d): Minimizing the first band in row is by maximizing the second\n", iBand);
2664 REBAR_MaximizeBand(infoPtr, iNext, FALSE);
2665 }
2666 else
2667 TRACE("(%d): Only one band in row - nothing to do\n", iBand);
2668 return TRUE;
2669 }
2670
2671 REBAR_GetBand(infoPtr, iPrev)->cxEffective += lpBand->cxEffective - lpBand->cxMinBand;
2672 REBAR_GetBand(infoPtr, iPrev)->cx = REBAR_GetBand(infoPtr, iPrev)->cxEffective;
2673 lpBand->cx = lpBand->cxEffective = lpBand->cxMinBand;
2674
2675 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2676 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2677 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2678
2679 if (infoPtr->dwStyle & CCS_VERT)
2680 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2681 else
2682 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2683 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2684 return FALSE;
2685 }
2686
2687
2688 static LRESULT
2689 REBAR_MoveBand (REBAR_INFO *infoPtr, INT iFrom, INT iTo)
2690 {
2691 REBAR_BAND *lpBand;
2692
2693 /* Validate */
2694 if ((infoPtr->uNumBands == 0) ||
2695 (iFrom < 0) || iFrom >= infoPtr->uNumBands ||
2696 (iTo < 0) || iTo >= infoPtr->uNumBands) {
2697 /* error !!! */
2698 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
2699 iFrom, iTo, infoPtr->uNumBands);
2700 return FALSE;
2701 }
2702
2703 lpBand = REBAR_GetBand(infoPtr, iFrom);
2704 DPA_DeletePtr(infoPtr->bands, iFrom);
2705 DPA_InsertPtr(infoPtr->bands, iTo, lpBand);
2706
2707 TRACE("moved band %d to index %d\n", iFrom, iTo);
2708 REBAR_DumpBand (infoPtr);
2709
2710 /* **************************************************** */
2711 /* */
2712 /* We do not do a REBAR_Layout here because the native */
2713 /* control does not do that. The actual layout and */
2714 /* repaint is done by the *next* real action, ex.: */
2715 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
2716 /* */
2717 /* **************************************************** */
2718
2719 return TRUE;
2720 }
2721
2722
2723 /* return TRUE if two strings are different */
2724 static BOOL
2725 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
2726 {
2727 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
2728 }
2729
2730 static LRESULT
2731 REBAR_SetBandInfoT(REBAR_INFO *infoPtr, INT iBand, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2732 {
2733 REBAR_BAND *lpBand;
2734 UINT uChanged;
2735
2736 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2737 return FALSE;
2738
2739 if (iBand >= infoPtr->uNumBands)
2740 return FALSE;
2741
2742 TRACE("index %d\n", iBand);
2743 REBAR_DumpBandInfo (lprbbi);
2744
2745 /* set band information */
2746 lpBand = REBAR_GetBand(infoPtr, iBand);
2747
2748 uChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2749 if (lprbbi->fMask & RBBIM_TEXT) {
2750 LPWSTR wstr = NULL;
2751 if (bUnicode)
2752 Str_SetPtrW(&wstr, lprbbi->lpText);
2753 else
2754 Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
2755
2756 if (REBAR_strdifW(wstr, lpBand->lpText)) {
2757 Free(lpBand->lpText);
2758 lpBand->lpText = wstr;
2759 uChanged |= RBBIM_TEXT;
2760 }
2761 else
2762 Free(wstr);
2763 }
2764
2765 REBAR_ValidateBand (infoPtr, lpBand);
2766
2767 REBAR_DumpBand (infoPtr);
2768
2769 if (uChanged & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IMAGE)) {
2770 REBAR_Layout(infoPtr);
2771 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2772 }
2773
2774 return TRUE;
2775 }
2776
2777
2778 static LRESULT
2779 REBAR_SetBarInfo (REBAR_INFO *infoPtr, const REBARINFO *lpInfo)
2780 {
2781 REBAR_BAND *lpBand;
2782 UINT i;
2783
2784 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2785 return FALSE;
2786
2787 TRACE("setting bar info!\n");
2788
2789 if (lpInfo->fMask & RBIM_IMAGELIST) {
2790 infoPtr->himl = lpInfo->himl;
2791 if (infoPtr->himl) {
2792 INT cx, cy;
2793 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
2794 infoPtr->imageSize.cx = cx;
2795 infoPtr->imageSize.cy = cy;
2796 }
2797 else {
2798 infoPtr->imageSize.cx = 0;
2799 infoPtr->imageSize.cy = 0;
2800 }
2801 TRACE("new image cx=%d, cy=%d\n", infoPtr->imageSize.cx,
2802 infoPtr->imageSize.cy);
2803 }
2804
2805 /* revalidate all bands to reset flags for images in headers of bands */
2806 for (i=0; i<infoPtr->uNumBands; i++) {
2807 lpBand = REBAR_GetBand(infoPtr, i);
2808 REBAR_ValidateBand (infoPtr, lpBand);
2809 }
2810
2811 return TRUE;
2812 }
2813
2814
2815 static LRESULT
2816 REBAR_SetBkColor (REBAR_INFO *infoPtr, COLORREF clr)
2817 {
2818 COLORREF clrTemp;
2819
2820 clrTemp = infoPtr->clrBk;
2821 infoPtr->clrBk = clr;
2822
2823 TRACE("background color 0x%06x!\n", infoPtr->clrBk);
2824
2825 return clrTemp;
2826 }
2827
2828
2829 /* << REBAR_SetColorScheme >> */
2830 /* << REBAR_SetPalette >> */
2831
2832
2833 static LRESULT
2834 REBAR_SetParent (REBAR_INFO *infoPtr, HWND parent)
2835 {
2836 HWND hwndTemp = infoPtr->hwndNotify;
2837
2838 infoPtr->hwndNotify = parent;
2839
2840 return (LRESULT)hwndTemp;
2841 }
2842
2843
2844 static LRESULT
2845 REBAR_SetTextColor (REBAR_INFO *infoPtr, COLORREF clr)
2846 {
2847 COLORREF clrTemp;
2848
2849 clrTemp = infoPtr->clrText;
2850 infoPtr->clrText = clr;
2851
2852 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2853
2854 return clrTemp;
2855 }
2856
2857
2858 /* << REBAR_SetTooltips >> */
2859
2860
2861 static inline LRESULT
2862 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, BOOL unicode)
2863 {
2864 BOOL bTemp = infoPtr->bUnicode;
2865
2866 TRACE("to %s hwnd=%p, was %s\n",
2867 unicode ? "TRUE" : "FALSE", infoPtr->hwndSelf,
2868 (bTemp) ? "TRUE" : "FALSE");
2869
2870 infoPtr->bUnicode = unicode;
2871
2872 return bTemp;
2873 }
2874
2875
2876 static LRESULT
2877 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
2878 {
2879 INT iOldVersion = infoPtr->iVersion;
2880
2881 if (iVersion > COMCTL32_VERSION)
2882 return -1;
2883
2884 infoPtr->iVersion = iVersion;
2885
2886 TRACE("new version %d\n", iVersion);
2887
2888 return iOldVersion;
2889 }
2890
2891
2892 static LRESULT
2893 REBAR_ShowBand (REBAR_INFO *infoPtr, INT iBand, BOOL show)
2894 {
2895 REBAR_BAND *lpBand;
2896
2897 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2898 return FALSE;
2899
2900 lpBand = REBAR_GetBand(infoPtr, iBand);
2901
2902 if (show) {
2903 TRACE("show band %d\n", iBand);
2904 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
2905 if (IsWindow (lpBand->hwndChild))
2906 ShowWindow (lpBand->hwndChild, SW_SHOW);
2907 }
2908 else {
2909 TRACE("hide band %d\n", iBand);
2910 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
2911 if (IsWindow (lpBand->hwndChild))
2912 ShowWindow (lpBand->hwndChild, SW_HIDE);
2913 }
2914
2915 REBAR_Layout(infoPtr);
2916 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2917
2918 return TRUE;
2919 }
2920
2921
2922 static LRESULT
2923 REBAR_SizeToRect (REBAR_INFO *infoPtr, const RECT *lpRect)
2924 {
2925 if (!lpRect) return FALSE;
2926
2927 TRACE("[%s]\n", wine_dbgstr_rect(lpRect));
2928 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, lpRect));
2929 return TRUE;
2930 }
2931
2932
2933
2934 static LRESULT
2935 REBAR_Create (REBAR_INFO *infoPtr, LPCREATESTRUCTW cs)
2936 {
2937 RECT wnrc1, clrc1;
2938
2939 if (TRACE_ON(rebar)) {
2940 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
2941 GetClientRect(infoPtr->hwndSelf, &clrc1);
2942 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
2943 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
2944 cs->x, cs->y, cs->cx, cs->cy);
2945 }
2946
2947 TRACE("created!\n");
2948
2949 if (OpenThemeData (infoPtr->hwndSelf, themeClass))
2950 {
2951 /* native seems to clear WS_BORDER when themed */
2952 infoPtr->dwStyle &= ~WS_BORDER;
2953 }
2954
2955 return 0;
2956 }
2957
2958
2959 static LRESULT
2960 REBAR_Destroy (REBAR_INFO *infoPtr)
2961 {
2962 REBAR_BAND *lpBand;
2963 UINT i;
2964
2965 /* clean up each band */
2966 for (i = 0; i < infoPtr->uNumBands; i++) {
2967 lpBand = REBAR_GetBand(infoPtr, i);
2968
2969 /* delete text strings */
2970 Free (lpBand->lpText);
2971 lpBand->lpText = NULL;
2972 /* destroy child window */
2973 DestroyWindow (lpBand->hwndChild);
2974 Free (lpBand);
2975 }
2976
2977 /* free band array */
2978 DPA_Destroy (infoPtr->bands);
2979 infoPtr->bands = NULL;
2980
2981 DestroyCursor (infoPtr->hcurArrow);
2982 DestroyCursor (infoPtr->hcurHorz);
2983 DestroyCursor (infoPtr->hcurVert);
2984 DestroyCursor (infoPtr->hcurDrag);
2985 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
2986 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
2987
2988 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2989
2990 /* free rebar info data */
2991 Free (infoPtr);
2992 TRACE("destroyed!\n");
2993 return 0;
2994 }
2995
2996 static LRESULT
2997 REBAR_GetFont (const REBAR_INFO *infoPtr)
2998 {
2999 return (LRESULT)infoPtr->hFont;
3000 }
3001
3002 static LRESULT
3003 REBAR_PushChevron(const REBAR_INFO *infoPtr, UINT uBand, LPARAM lParam)
3004 {
3005 if (uBand < infoPtr->uNumBands)
3006 {
3007 NMREBARCHEVRON nmrbc;
3008 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
3009
3010 TRACE("Pressed chevron on band %u\n", uBand);
3011
3012 /* redraw chevron in pushed state */
3013 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
3014 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
3015 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3016
3017 /* notify app so it can display a popup menu or whatever */
3018 nmrbc.uBand = uBand;
3019 nmrbc.wID = lpBand->wID;
3020 nmrbc.lParam = lpBand->lParam;
3021 nmrbc.rc = lpBand->rcChevron;
3022 nmrbc.lParamNM = lParam;
3023 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3024
3025 /* redraw chevron in previous state */
3026 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3027 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3028
3029 return TRUE;
3030 }
3031 return FALSE;
3032 }
3033
3034 static LRESULT
3035 REBAR_LButtonDown (REBAR_INFO *infoPtr, LPARAM lParam)
3036 {
3037 UINT htFlags;
3038 INT iHitBand;
3039 POINT ptMouseDown;
3040 ptMouseDown.x = (short)LOWORD(lParam);
3041 ptMouseDown.y = (short)HIWORD(lParam);
3042
3043 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3044
3045 if (htFlags == RBHT_CHEVRON)
3046 {
3047 REBAR_PushChevron(infoPtr, iHitBand, 0);
3048 }
3049 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3050 {
3051 REBAR_BAND *lpBand;
3052
3053 TRACE("Starting drag\n");
3054
3055 lpBand = REBAR_GetBand(infoPtr, iHitBand);
3056
3057 SetCapture (infoPtr->hwndSelf);
3058 infoPtr->iGrabbedBand = iHitBand;
3059
3060 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3061 infoPtr->dragStart.x = (short)LOWORD(lParam);
3062 infoPtr->dragStart.y = (short)HIWORD(lParam);
3063 infoPtr->dragNow = infoPtr->dragStart;
3064 if (infoPtr->dwStyle & CCS_VERT)
3065 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3066 else
3067 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3068 }
3069 return 0;
3070 }
3071
3072 static LRESULT
3073 REBAR_LButtonUp (REBAR_INFO *infoPtr)
3074 {
3075 if (infoPtr->iGrabbedBand >= 0)
3076 {
3077 NMHDR layout;
3078 RECT rect;
3079
3080 infoPtr->dragStart.x = 0;
3081 infoPtr->dragStart.y = 0;
3082 infoPtr->dragNow = infoPtr->dragStart;
3083
3084 ReleaseCapture ();
3085
3086 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3087 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3088 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3089 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3090 }
3091
3092 infoPtr->iGrabbedBand = -1;
3093
3094 GetClientRect(infoPtr->hwndSelf, &rect);
3095 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3096 }
3097
3098 return 0;
3099 }
3100
3101 static LRESULT
3102 REBAR_MouseLeave (REBAR_INFO *infoPtr)
3103 {
3104 if (infoPtr->ichevronhotBand >= 0)
3105 {
3106 REBAR_BAND *lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3107 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3108 {
3109 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3110 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3111 }
3112 }
3113 infoPtr->iOldBand = -1;
3114 infoPtr->ichevronhotBand = -2;
3115
3116 return TRUE;
3117 }
3118
3119 static LRESULT
3120 REBAR_MouseMove (REBAR_INFO *infoPtr, LPARAM lParam)
3121 {
3122 REBAR_BAND *lpChevronBand;
3123 POINT ptMove;
3124
3125 ptMove.x = (short)LOWORD(lParam);
3126 ptMove.y = (short)HIWORD(lParam);
3127
3128 /* if we are currently dragging a band */
3129 if (infoPtr->iGrabbedBand >= 0)
3130 {
3131 REBAR_BAND *band;
3132 int yPtMove = (infoPtr->dwStyle & CCS_VERT ? ptMove.x : ptMove.y);
3133
3134 if (GetCapture() != infoPtr->hwndSelf)
3135 ERR("We are dragging but haven't got capture?!?\n");
3136
3137 band = REBAR_GetBand(infoPtr, infoPtr->iGrabbedBand);
3138
3139 /* if mouse did not move much, exit */
3140 if ((abs(ptMove.x - infoPtr->dragNow.x) <= mindragx) &&
3141 (abs(ptMove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3142
3143 /* on first significant mouse movement, issue notify */
3144 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
3145 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
3146 /* Notify returned TRUE - abort drag */
3147 infoPtr->dragStart.x = 0;
3148 infoPtr->dragStart.y = 0;
3149 infoPtr->dragNow = infoPtr->dragStart;
3150 infoPtr->iGrabbedBand = -1;
3151 ReleaseCapture ();
3152