d6eed2e740e42ebd99c419875991b2c2eb1002f2
[reactos.git] / reactos / 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_PALETTECHANGED
50 * - WM_QUERYNEWPALETTE
51 * - WM_RBUTTONDOWN
52 * - WM_RBUTTONUP
53 * - WM_SYSCOLORCHANGE
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 <vssym32.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 /* has a value of: 0, CCS_TOP, CCS_NOMOVEY, CCS_BOTTOM */
141 #define CCS_LAYOUT_MASK 0x3
142
143 /* fStatus flags */
144 #define HAS_GRIPPER 0x00000001
145 #define HAS_IMAGE 0x00000002
146 #define HAS_TEXT 0x00000004
147
148 /* fDraw flags */
149 #define DRAW_GRIPPER 0x00000001
150 #define DRAW_IMAGE 0x00000002
151 #define DRAW_TEXT 0x00000004
152 #define DRAW_CHEVRONHOT 0x00000040
153 #define DRAW_CHEVRONPUSHED 0x00000080
154 #define NTF_INVALIDATE 0x01000000
155
156 typedef struct
157 {
158 COLORREF clrBk; /* background color */
159 COLORREF clrText; /* text color */
160 COLORREF clrBtnText; /* system color for BTNTEXT */
161 COLORREF clrBtnFace; /* system color for BTNFACE */
162 HIMAGELIST himl; /* handle to imagelist */
163 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
164 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
165 HWND hwndSelf; /* handle of REBAR window itself */
166 HWND hwndToolTip; /* handle to the tool tip control */
167 HWND hwndNotify; /* notification window (parent) */
168 HFONT hDefaultFont;
169 HFONT hFont; /* handle to the rebar's font */
170 SIZE imageSize; /* image size (image list) */
171 DWORD dwStyle; /* window style */
172 DWORD orgStyle; /* original style (dwStyle may change) */
173 SIZE calcSize; /* calculated rebar size - coordinates swapped for CCS_VERT */
174 BOOL bUnicode; /* TRUE if parent wants notify in W format */
175 BOOL DoRedraw; /* TRUE to actually draw bands */
176 UINT fStatus; /* Status flags (see below) */
177 HCURSOR hcurArrow; /* handle to the arrow cursor */
178 HCURSOR hcurHorz; /* handle to the EW cursor */
179 HCURSOR hcurVert; /* handle to the NS cursor */
180 HCURSOR hcurDrag; /* handle to the drag cursor */
181 INT iVersion; /* version number */
182 POINT dragStart; /* x,y of button down */
183 POINT dragNow; /* x,y of this MouseMove */
184 INT iOldBand; /* last band that had the mouse cursor over it */
185 INT ihitoffset; /* offset of hotspot from gripper.left */
186 INT ichevronhotBand; /* last band that had a hot chevron */
187 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
188
189 HDPA bands; /* pointer to the array of rebar bands */
190 } REBAR_INFO;
191
192 /* fStatus flags */
193 #define BEGIN_DRAG_ISSUED 0x00000001
194 #define SELF_RESIZE 0x00000002
195 #define BAND_NEEDS_REDRAW 0x00000020
196
197 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
198 #define RBBS_UNDOC_FIXEDHEADER 0x40000000
199
200 /* ---- REBAR layout constants. Mostly determined by ---- */
201 /* ---- experiment on WIN 98. ---- */
202
203 /* Width (or height) of separators between bands (either horz. or */
204 /* vert.). True only if RBS_BANDBORDERS is set */
205 #define SEP_WIDTH_SIZE 2
206 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
207
208 /* Blank (background color) space between Gripper (if present) */
209 /* and next item (image, text, or window). Always present */
210 #define REBAR_ALWAYS_SPACE 4
211
212 /* Blank (background color) space after Image (if present). */
213 #define REBAR_POST_IMAGE 2
214
215 /* Blank (background color) space after Text (if present). */
216 #define REBAR_POST_TEXT 4
217
218 /* Height of vertical gripper in a CCS_VERT rebar. */
219 #define GRIPPER_HEIGHT 16
220
221 /* Blank (background color) space before Gripper (if present). */
222 #define REBAR_PRE_GRIPPER 2
223
224 /* Width (of normal vertical gripper) or height (of horz. gripper) */
225 /* if present. */
226 #define GRIPPER_WIDTH 3
227
228 /* Width of the chevron button if present */
229 #define CHEVRON_WIDTH 10
230
231 /* the gap between the child and the next band */
232 #define REBAR_POST_CHILD 4
233
234 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
235 /* either top or bottom */
236 #define REBAR_DIVIDER 2
237
238 /* height of a rebar without a child */
239 #define REBAR_NO_CHILD_HEIGHT 4
240
241 /* minimum vertical height of a normal bar */
242 /* or minimum width of a CCS_VERT bar - from experiment on Win2k */
243 #define REBAR_MINSIZE 23
244
245 /* This is the increment that is used over the band height */
246 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
247
248 /* ---- End of REBAR layout constants. ---- */
249
250 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
251
252 /* The following define determines if a given band is hidden */
253 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
254 ((infoPtr->dwStyle & CCS_VERT) && \
255 ((a)->fStyle & RBBS_NOVERT)))
256
257 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
258
259 static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, LPARAM lParam);
260 static void REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout);
261
262 /* no index check here */
263 static inline REBAR_BAND* REBAR_GetBand(const REBAR_INFO *infoPtr, INT i)
264 {
265 assert(i >= 0 && i < infoPtr->uNumBands);
266 return DPA_GetPtr(infoPtr->bands, i);
267 }
268
269 /* "constant values" retrieved when DLL was initialized */
270 /* FIXME we do this when the classes are registered. */
271 static UINT mindragx = 0;
272 static UINT mindragy = 0;
273
274 static const char * const band_stylename[] = {
275 "RBBS_BREAK", /* 0001 */
276 "RBBS_FIXEDSIZE", /* 0002 */
277 "RBBS_CHILDEDGE", /* 0004 */
278 "RBBS_HIDDEN", /* 0008 */
279 "RBBS_NOVERT", /* 0010 */
280 "RBBS_FIXEDBMP", /* 0020 */
281 "RBBS_VARIABLEHEIGHT", /* 0040 */
282 "RBBS_GRIPPERALWAYS", /* 0080 */
283 "RBBS_NOGRIPPER", /* 0100 */
284 NULL };
285
286 static const char * const band_maskname[] = {
287 "RBBIM_STYLE", /* 0x00000001 */
288 "RBBIM_COLORS", /* 0x00000002 */
289 "RBBIM_TEXT", /* 0x00000004 */
290 "RBBIM_IMAGE", /* 0x00000008 */
291 "RBBIM_CHILD", /* 0x00000010 */
292 "RBBIM_CHILDSIZE", /* 0x00000020 */
293 "RBBIM_SIZE", /* 0x00000040 */
294 "RBBIM_BACKGROUND", /* 0x00000080 */
295 "RBBIM_ID", /* 0x00000100 */
296 "RBBIM_IDEALSIZE", /* 0x00000200 */
297 "RBBIM_LPARAM", /* 0x00000400 */
298 "RBBIM_HEADERSIZE", /* 0x00000800 */
299 NULL };
300
301
302 static CHAR line[200];
303
304 static const WCHAR themeClass[] = { 'R','e','b','a','r',0 };
305
306 static CHAR *
307 REBAR_FmtStyle( UINT style)
308 {
309 INT i = 0;
310
311 *line = 0;
312 while (band_stylename[i]) {
313 if (style & (1<<i)) {
314 if (*line != 0) strcat(line, " | ");
315 strcat(line, band_stylename[i]);
316 }
317 i++;
318 }
319 return line;
320 }
321
322
323 static CHAR *
324 REBAR_FmtMask( UINT mask)
325 {
326 INT i = 0;
327
328 *line = 0;
329 while (band_maskname[i]) {
330 if (mask & (1<<i)) {
331 if (*line != 0) strcat(line, " | ");
332 strcat(line, band_maskname[i]);
333 }
334 i++;
335 }
336 return line;
337 }
338
339
340 static VOID
341 REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
342 {
343 if( !TRACE_ON(rebar) ) return;
344 TRACE("band info: ");
345 if (pB->fMask & RBBIM_ID)
346 TRACE("ID=%u, ", pB->wID);
347 TRACE("size=%u, child=%p", pB->cbSize, pB->hwndChild);
348 if (pB->fMask & RBBIM_COLORS)
349 TRACE(", clrF=0x%06x, clrB=0x%06x", pB->clrFore, pB->clrBack);
350 TRACE("\n");
351
352 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
353 if (pB->fMask & RBBIM_STYLE)
354 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
355 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
356 TRACE("band info:");
357 if (pB->fMask & RBBIM_SIZE)
358 TRACE(" cx=%u", pB->cx);
359 if (pB->fMask & RBBIM_IDEALSIZE)
360 TRACE(" xIdeal=%u", pB->cxIdeal);
361 if (pB->fMask & RBBIM_HEADERSIZE)
362 TRACE(" xHeader=%u", pB->cxHeader);
363 if (pB->fMask & RBBIM_LPARAM)
364 TRACE(" lParam=0x%08lx", pB->lParam);
365 TRACE("\n");
366 }
367 if (pB->fMask & RBBIM_CHILDSIZE)
368 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
369 pB->cxMinChild,
370 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
371 }
372
373 static VOID
374 REBAR_DumpBand (const REBAR_INFO *iP)
375 {
376 REBAR_BAND *pB;
377 UINT i;
378
379 if(! TRACE_ON(rebar) ) return;
380
381 TRACE("hwnd=%p: color=%08x/%08x, bands=%u, rows=%u, cSize=%d,%d\n",
382 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
383 iP->calcSize.cx, iP->calcSize.cy);
384 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
385 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
386 iP->dragNow.x, iP->dragNow.y,
387 iP->iGrabbedBand);
388 TRACE("hwnd=%p: style=%08x, notify in Unicode=%s, redraw=%s\n",
389 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
390 (iP->DoRedraw)?"TRUE":"FALSE");
391 for (i = 0; i < iP->uNumBands; i++) {
392 pB = REBAR_GetBand(iP, i);
393 TRACE("band # %u:", i);
394 if (pB->fMask & RBBIM_ID)
395 TRACE(" ID=%u", pB->wID);
396 if (pB->fMask & RBBIM_CHILD)
397 TRACE(" child=%p", pB->hwndChild);
398 if (pB->fMask & RBBIM_COLORS)
399 TRACE(" clrF=0x%06x clrB=0x%06x", pB->clrFore, pB->clrBack);
400 TRACE("\n");
401 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
402 if (pB->fMask & RBBIM_STYLE)
403 TRACE("band # %u: style=0x%08x (%s)\n",
404 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
405 TRACE("band # %u: xHeader=%u",
406 i, pB->cxHeader);
407 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
408 if (pB->fMask & RBBIM_SIZE)
409 TRACE(" cx=%u", pB->cx);
410 if (pB->fMask & RBBIM_IDEALSIZE)
411 TRACE(" xIdeal=%u", pB->cxIdeal);
412 if (pB->fMask & RBBIM_LPARAM)
413 TRACE(" lParam=0x%08lx", pB->lParam);
414 }
415 TRACE("\n");
416 if (RBBIM_CHILDSIZE)
417 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
418 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
419 if (pB->fMask & RBBIM_TEXT)
420 TRACE("band # %u: text=%s\n",
421 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
422 TRACE("band # %u: cxMinBand=%u, cxEffective=%u, cyMinBand=%u\n",
423 i, pB->cxMinBand, pB->cxEffective, pB->cyMinBand);
424 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
425 i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
426 wine_dbgstr_rect(&pB->rcGripper));
427 TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
428 i, wine_dbgstr_rect(&pB->rcCapImage),
429 wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
430 }
431
432 }
433
434 /* dest can be equal to src */
435 static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
436 {
437 if (infoPtr->dwStyle & CCS_VERT) {
438 int tmp;
439 tmp = src->left;
440 dest->left = src->top;
441 dest->top = tmp;
442
443 tmp = src->right;
444 dest->right = src->bottom;
445 dest->bottom = tmp;
446 } else {
447 *dest = *src;
448 }
449 }
450
451 static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
452 {
453 if (infoPtr->dwStyle & CCS_VERT)
454 return lpRect->bottom - lpRect->top;
455 return lpRect->right - lpRect->left;
456 }
457
458 static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
459 {
460 if (infoPtr->dwStyle & CCS_VERT)
461 return lpRect->right - lpRect->left;
462 return lpRect->bottom - lpRect->top;
463 }
464
465 static int round_child_height(const REBAR_BAND *lpBand, int cyHeight)
466 {
467 int cy = 0;
468 if (lpBand->cyIntegral == 0)
469 return cyHeight;
470 cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
471 cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
472 cy = min(cy, lpBand->cyMaxChild);
473 return cy;
474 }
475
476 static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
477 {
478 lpBand->cyMinBand = max(lpBand->cyHeader,
479 (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
480 }
481
482 static void
483 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
484 {
485 INT x, y;
486 HPEN hPen, hOldPen;
487
488 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
489 hOldPen = SelectObject ( hdc, hPen );
490 x = left + 2;
491 y = top;
492 MoveToEx (hdc, x, y, NULL);
493 LineTo (hdc, x+5, y++); x++;
494 MoveToEx (hdc, x, y, NULL);
495 LineTo (hdc, x+3, y++); x++;
496 MoveToEx (hdc, x, y, NULL);
497 LineTo (hdc, x+1, y);
498 SelectObject( hdc, hOldPen );
499 DeleteObject( hPen );
500 }
501
502 static HWND
503 REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
504 {
505 HWND parent, owner;
506
507 parent = infoPtr->hwndNotify;
508 if (!parent) {
509 parent = GetParent (infoPtr->hwndSelf);
510 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
511 if (owner) parent = owner;
512 }
513 return parent;
514 }
515
516
517 static INT
518 REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
519 {
520 HWND parent;
521
522 parent = REBAR_GetNotifyParent (infoPtr);
523 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
524 nmhdr->hwndFrom = infoPtr->hwndSelf;
525 nmhdr->code = code;
526
527 TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
528
529 return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
530 }
531
532 static INT
533 REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
534 {
535 NMREBAR notify_rebar;
536
537 notify_rebar.dwMask = 0;
538 if (uBand != -1) {
539 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
540
541 if (lpBand->fMask & RBBIM_ID) {
542 notify_rebar.dwMask |= RBNM_ID;
543 notify_rebar.wID = lpBand->wID;
544 }
545 if (lpBand->fMask & RBBIM_LPARAM) {
546 notify_rebar.dwMask |= RBNM_LPARAM;
547 notify_rebar.lParam = lpBand->lParam;
548 }
549 if (lpBand->fMask & RBBIM_STYLE) {
550 notify_rebar.dwMask |= RBNM_STYLE;
551 notify_rebar.fStyle = lpBand->fStyle;
552 }
553 }
554 notify_rebar.uBand = uBand;
555 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
556 }
557
558 static VOID
559 REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
560 {
561 HFONT hOldFont = 0;
562 INT oldBkMode = 0;
563 NMCUSTOMDRAW nmcd;
564 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
565 RECT rcBand;
566
567 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
568
569 if (lpBand->fDraw & DRAW_TEXT) {
570 hOldFont = SelectObject (hdc, infoPtr->hFont);
571 oldBkMode = SetBkMode (hdc, TRANSPARENT);
572 }
573
574 /* should test for CDRF_NOTIFYITEMDRAW here */
575 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
576 nmcd.hdc = hdc;
577 nmcd.rc = rcBand;
578 nmcd.rc.right = lpBand->rcCapText.right;
579 nmcd.rc.bottom = lpBand->rcCapText.bottom;
580 nmcd.dwItemSpec = lpBand->wID;
581 nmcd.uItemState = 0;
582 nmcd.lItemlParam = lpBand->lParam;
583 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
584 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
585 if (oldBkMode != TRANSPARENT)
586 SetBkMode (hdc, oldBkMode);
587 SelectObject (hdc, hOldFont);
588 return;
589 }
590
591 /* draw gripper */
592 if (lpBand->fDraw & DRAW_GRIPPER)
593 {
594 if (theme)
595 {
596 RECT rcGripper = lpBand->rcGripper;
597 int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
598 GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
599 OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
600 lpBand->rcGripper.top - rcGripper.top);
601 DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
602 }
603 else
604 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
605 }
606
607 /* draw caption image */
608 if (lpBand->fDraw & DRAW_IMAGE) {
609 POINT pt;
610
611 /* center image */
612 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
613 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
614
615 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
616 pt.x, pt.y,
617 ILD_TRANSPARENT);
618 }
619
620 /* draw caption text */
621 if (lpBand->fDraw & DRAW_TEXT) {
622 /* need to handle CDRF_NEWFONT here */
623 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
624 COLORREF oldcolor = CLR_NONE;
625 COLORREF new;
626 if (lpBand->clrFore != CLR_NONE) {
627 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
628 lpBand->clrFore;
629 oldcolor = SetTextColor (hdc, new);
630 }
631 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
632 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
633 if (oldBkMode != TRANSPARENT)
634 SetBkMode (hdc, oldBkMode);
635 if (lpBand->clrFore != CLR_NONE)
636 SetTextColor (hdc, oldcolor);
637 SelectObject (hdc, hOldFont);
638 }
639
640 if (!IsRectEmpty(&lpBand->rcChevron))
641 {
642 if (theme)
643 {
644 int stateId;
645 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
646 stateId = CHEVS_PRESSED;
647 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
648 stateId = CHEVS_HOT;
649 else
650 stateId = CHEVS_NORMAL;
651 DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
652 }
653 else
654 {
655 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
656 {
657 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
658 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
659 }
660 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
661 {
662 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
663 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
664 }
665 else
666 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
667 }
668 }
669
670 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
671 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
672 nmcd.hdc = hdc;
673 nmcd.rc = rcBand;
674 nmcd.rc.right = lpBand->rcCapText.right;
675 nmcd.rc.bottom = lpBand->rcCapText.bottom;
676 nmcd.dwItemSpec = lpBand->wID;
677 nmcd.uItemState = 0;
678 nmcd.lItemlParam = lpBand->lParam;
679 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
680 }
681 }
682
683
684 static VOID
685 REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
686 {
687 REBAR_BAND *lpBand;
688 UINT i;
689
690 if (!infoPtr->DoRedraw) return;
691
692 for (i = 0; i < infoPtr->uNumBands; i++) {
693 lpBand = REBAR_GetBand(infoPtr, i);
694
695 if (HIDDENBAND(lpBand)) continue;
696
697 /* now draw the band */
698 TRACE("[%p] drawing band %i, flags=%08x\n",
699 infoPtr->hwndSelf, i, lpBand->fDraw);
700 REBAR_DrawBand (hdc, infoPtr, lpBand);
701 }
702 }
703
704
705 static void
706 REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
707 /* Function: this routine initializes all the rectangles in */
708 /* each band in a row to fit in the adjusted rcBand rect. */
709 /* *** Supports only Horizontal bars. *** */
710 {
711 REBAR_BAND *lpBand;
712 UINT i, xoff;
713 RECT work;
714
715 for(i=rstart; i<rend; i++){
716 lpBand = REBAR_GetBand(infoPtr, i);
717 if (HIDDENBAND(lpBand)) {
718 SetRect (&lpBand->rcChild,
719 lpBand->rcBand.right, lpBand->rcBand.top,
720 lpBand->rcBand.right, lpBand->rcBand.bottom);
721 continue;
722 }
723
724 /* set initial gripper rectangle */
725 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
726 lpBand->rcBand.left, lpBand->rcBand.bottom);
727
728 /* calculate gripper rectangle */
729 if ( lpBand->fStatus & HAS_GRIPPER) {
730 lpBand->fDraw |= DRAW_GRIPPER;
731 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
732 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
733 lpBand->rcGripper.top += 2;
734 lpBand->rcGripper.bottom -= 2;
735
736 SetRect (&lpBand->rcCapImage,
737 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
738 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
739 }
740 else { /* no gripper will be drawn */
741 xoff = 0;
742 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
743 /* if no gripper but either image or text, then leave space */
744 xoff = REBAR_ALWAYS_SPACE;
745 SetRect (&lpBand->rcCapImage,
746 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
747 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
748 }
749
750 /* image is visible */
751 if (lpBand->fStatus & HAS_IMAGE) {
752 lpBand->fDraw |= DRAW_IMAGE;
753 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
754 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
755
756 /* set initial caption text rectangle */
757 SetRect (&lpBand->rcCapText,
758 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
759 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
760 }
761 else {
762 /* set initial caption text rectangle */
763 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
764 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
765 }
766
767 /* text is visible */
768 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
769 lpBand->fDraw |= DRAW_TEXT;
770 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
771 lpBand->rcCapText.right-REBAR_POST_TEXT);
772 }
773
774 /* set initial child window rectangle if there is a child */
775 if (lpBand->hwndChild) {
776
777 lpBand->rcChild.left = lpBand->rcBand.left + lpBand->cxHeader;
778 lpBand->rcChild.right = lpBand->rcBand.right - REBAR_POST_CHILD;
779
780 if (lpBand->cyChild > 0) {
781
782 UINT yoff = (lpBand->rcBand.bottom - lpBand->rcBand.top - lpBand->cyChild) / 2;
783
784 /* center child if height is known */
785 lpBand->rcChild.top = lpBand->rcBand.top + yoff;
786 lpBand->rcChild.bottom = lpBand->rcBand.top + yoff + lpBand->cyChild;
787 }
788 else {
789 lpBand->rcChild.top = lpBand->rcBand.top;
790 lpBand->rcChild.bottom = lpBand->rcBand.bottom;
791 }
792
793 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
794 {
795 lpBand->rcChild.right -= CHEVRON_WIDTH;
796 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
797 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
798 lpBand->rcChild.bottom);
799 }
800 }
801 else {
802 SetRect (&lpBand->rcChild,
803 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
804 lpBand->rcBand.right, lpBand->rcBand.bottom);
805 }
806
807 /* flag if notify required and invalidate rectangle */
808 if (lpBand->fDraw & NTF_INVALIDATE) {
809 TRACE("invalidating (%d,%d)-(%d,%d)\n",
810 lpBand->rcBand.left,
811 lpBand->rcBand.top,
812 lpBand->rcBand.right + SEP_WIDTH,
813 lpBand->rcBand.bottom + SEP_WIDTH);
814 lpBand->fDraw &= ~NTF_INVALIDATE;
815 work = lpBand->rcBand;
816 work.right += SEP_WIDTH;
817 work.bottom += SEP_WIDTH;
818 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
819 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
820 }
821
822 }
823
824 }
825
826
827 static VOID
828 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
829 /* Function: this routine initializes all the rectangles in */
830 /* each band in a row to fit in the adjusted rcBand rect. */
831 /* *** Supports only Vertical bars. *** */
832 {
833 REBAR_BAND *lpBand;
834 UINT i, xoff;
835 RECT work;
836
837 for(i=rstart; i<rend; i++){
838 RECT rcBand;
839 lpBand = REBAR_GetBand(infoPtr, i);
840 if (HIDDENBAND(lpBand)) continue;
841
842 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
843
844 /* set initial gripper rectangle */
845 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
846
847 /* calculate gripper rectangle */
848 if (lpBand->fStatus & HAS_GRIPPER) {
849 lpBand->fDraw |= DRAW_GRIPPER;
850
851 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
852 /* vertical gripper */
853 lpBand->rcGripper.left += 3;
854 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
855 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
856 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
857
858 /* initialize Caption image rectangle */
859 SetRect (&lpBand->rcCapImage, rcBand.left,
860 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
861 rcBand.right,
862 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
863 }
864 else {
865 /* horizontal gripper */
866 lpBand->rcGripper.left += 2;
867 lpBand->rcGripper.right -= 2;
868 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
869 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
870
871 /* initialize Caption image rectangle */
872 SetRect (&lpBand->rcCapImage, rcBand.left,
873 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
874 rcBand.right,
875 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
876 }
877 }
878 else { /* no gripper will be drawn */
879 xoff = 0;
880 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
881 /* if no gripper but either image or text, then leave space */
882 xoff = REBAR_ALWAYS_SPACE;
883 /* initialize Caption image rectangle */
884 SetRect (&lpBand->rcCapImage,
885 rcBand.left, rcBand.top+xoff,
886 rcBand.right, rcBand.top+xoff);
887 }
888
889 /* image is visible */
890 if (lpBand->fStatus & HAS_IMAGE) {
891 lpBand->fDraw |= DRAW_IMAGE;
892
893 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
894 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
895
896 /* set initial caption text rectangle */
897 SetRect (&lpBand->rcCapText,
898 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
899 rcBand.right, rcBand.top+lpBand->cxHeader);
900 }
901 else {
902 /* set initial caption text rectangle */
903 SetRect (&lpBand->rcCapText,
904 rcBand.left, lpBand->rcCapImage.bottom,
905 rcBand.right, rcBand.top+lpBand->cxHeader);
906 }
907
908 /* text is visible */
909 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
910 lpBand->fDraw |= DRAW_TEXT;
911 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
912 lpBand->rcCapText.bottom);
913 }
914
915 /* set initial child window rectangle if there is a child */
916 if (lpBand->hwndChild) {
917 int cxBand = rcBand.right - rcBand.left;
918 xoff = (cxBand - lpBand->cyChild) / 2;
919 SetRect (&lpBand->rcChild,
920 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
921 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
922 }
923 else {
924 SetRect (&lpBand->rcChild,
925 rcBand.left, rcBand.top+lpBand->cxHeader,
926 rcBand.right, rcBand.bottom);
927 }
928
929 if (lpBand->fDraw & NTF_INVALIDATE) {
930 TRACE("invalidating (%d,%d)-(%d,%d)\n",
931 rcBand.left,
932 rcBand.top,
933 rcBand.right + SEP_WIDTH,
934 rcBand.bottom + SEP_WIDTH);
935 lpBand->fDraw &= ~NTF_INVALIDATE;
936 work = rcBand;
937 work.bottom += SEP_WIDTH;
938 work.right += SEP_WIDTH;
939 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
940 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
941 }
942
943 }
944 }
945
946
947 static VOID
948 REBAR_ForceResize (REBAR_INFO *infoPtr)
949 /* Function: This changes the size of the REBAR window to that */
950 /* calculated by REBAR_Layout. */
951 {
952 INT x, y, width, height;
953 INT xedge = 0, yedge = 0;
954 RECT rcSelf;
955
956 TRACE("new size [%d x %d]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
957
958 if (infoPtr->dwStyle & CCS_NORESIZE)
959 return;
960
961 if (infoPtr->dwStyle & WS_BORDER)
962 {
963 xedge = GetSystemMetrics(SM_CXEDGE);
964 yedge = GetSystemMetrics(SM_CYEDGE);
965 /* swap for CCS_VERT? */
966 }
967
968 /* compute rebar window rect in parent client coordinates */
969 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
970 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
971 translate_rect(infoPtr, &rcSelf, &rcSelf);
972
973 height = infoPtr->calcSize.cy + 2*yedge;
974 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
975 RECT rcParent;
976
977 x = -xedge;
978 width = infoPtr->calcSize.cx + 2*xedge;
979 y = 0; /* quiet compiler warning */
980 switch ( infoPtr->dwStyle & CCS_LAYOUT_MASK) {
981 case 0: /* shouldn't happen - see NCCreate */
982 case CCS_TOP:
983 y = ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER) - yedge;
984 break;
985 case CCS_NOMOVEY:
986 y = rcSelf.top;
987 break;
988 case CCS_BOTTOM:
989 GetClientRect(GetParent(infoPtr->hwndSelf), &rcParent);
990 translate_rect(infoPtr, &rcParent, &rcParent);
991 y = rcParent.bottom - infoPtr->calcSize.cy - yedge;
992 break;
993 }
994 }
995 else {
996 x = rcSelf.left;
997 /* As on Windows if the CCS_NODIVIDER is not present the control will move
998 * 2 pixel down after every layout */
999 y = rcSelf.top + ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1000 width = rcSelf.right - rcSelf.left;
1001 }
1002
1003 TRACE("hwnd %p, style=%08x, setting at (%d,%d) for (%d,%d)\n",
1004 infoPtr->hwndSelf, infoPtr->dwStyle, x, y, width, height);
1005
1006 /* Set flag to ignore next WM_SIZE message and resize the window */
1007 infoPtr->fStatus |= SELF_RESIZE;
1008 if ((infoPtr->dwStyle & CCS_VERT) == 0)
1009 SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
1010 else
1011 SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
1012 infoPtr->fStatus &= ~SELF_RESIZE;
1013 }
1014
1015
1016 static VOID
1017 REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
1018 {
1019 static const WCHAR strComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
1020 REBAR_BAND *lpBand;
1021 WCHAR szClassName[40];
1022 UINT i;
1023 NMREBARCHILDSIZE rbcz;
1024 HDWP deferpos;
1025
1026 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1027 ERR("BeginDeferWindowPos returned NULL\n");
1028
1029 for (i = start; i < endplus; i++) {
1030 lpBand = REBAR_GetBand(infoPtr, i);
1031
1032 if (HIDDENBAND(lpBand)) continue;
1033 if (lpBand->hwndChild) {
1034 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1035
1036 /* Always generate the RBN_CHILDSIZE even if child
1037 did not change */
1038 rbcz.uBand = i;
1039 rbcz.wID = lpBand->wID;
1040 rbcz.rcChild = lpBand->rcChild;
1041 translate_rect(infoPtr, &rbcz.rcBand, &lpBand->rcBand);
1042 if (infoPtr->dwStyle & CCS_VERT)
1043 rbcz.rcBand.top += lpBand->cxHeader;
1044 else
1045 rbcz.rcBand.left += lpBand->cxHeader;
1046 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1047 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1048 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1049 TRACE(" from (%s) to (%s)\n",
1050 wine_dbgstr_rect(&lpBand->rcChild),
1051 wine_dbgstr_rect(&rbcz.rcChild));
1052 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1053 }
1054
1055 GetClassNameW (lpBand->hwndChild, szClassName, sizeof(szClassName)/sizeof(szClassName[0]));
1056 if (!lstrcmpW (szClassName, strComboBox) ||
1057 !lstrcmpW (szClassName, WC_COMBOBOXEXW)) {
1058 INT nEditHeight, yPos;
1059 RECT rc;
1060
1061 /* special placement code for combo or comboex box */
1062
1063
1064 /* get size of edit line */
1065 GetWindowRect (lpBand->hwndChild, &rc);
1066 nEditHeight = rc.bottom - rc.top;
1067 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1068
1069 /* center combo box inside child area */
1070 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1071 lpBand->hwndChild,
1072 lpBand->rcChild.left, yPos,
1073 lpBand->rcChild.right - lpBand->rcChild.left,
1074 nEditHeight);
1075 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1076 lpBand->rcChild.left,
1077 /*lpBand->rcChild.top*/ yPos,
1078 lpBand->rcChild.right - lpBand->rcChild.left,
1079 nEditHeight,
1080 SWP_NOZORDER);
1081 if (!deferpos)
1082 ERR("DeferWindowPos returned NULL\n");
1083 }
1084 else {
1085 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1086 lpBand->hwndChild,
1087 lpBand->rcChild.left, lpBand->rcChild.top,
1088 lpBand->rcChild.right - lpBand->rcChild.left,
1089 lpBand->rcChild.bottom - lpBand->rcChild.top);
1090 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1091 lpBand->rcChild.left,
1092 lpBand->rcChild.top,
1093 lpBand->rcChild.right - lpBand->rcChild.left,
1094 lpBand->rcChild.bottom - lpBand->rcChild.top,
1095 SWP_NOZORDER);
1096 if (!deferpos)
1097 ERR("DeferWindowPos returned NULL\n");
1098 }
1099 }
1100 }
1101 if (!EndDeferWindowPos(deferpos))
1102 ERR("EndDeferWindowPos returned NULL\n");
1103
1104 if (infoPtr->DoRedraw)
1105 UpdateWindow (infoPtr->hwndSelf);
1106 }
1107
1108 /* Returns the next visible band (the first visible band in [i+1; infoPtr->uNumBands) )
1109 * or infoPtr->uNumBands if none */
1110 static int next_visible(const REBAR_INFO *infoPtr, int i)
1111 {
1112 unsigned int n;
1113 for (n = i + 1; n < infoPtr->uNumBands; n++)
1114 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1115 break;
1116 return n;
1117 }
1118
1119 /* Returns the previous visible band (the last visible band in [0; i) )
1120 * or -1 if none */
1121 static int prev_visible(const REBAR_INFO *infoPtr, int i)
1122 {
1123 int n;
1124 for (n = i - 1; n >= 0; n--)
1125 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1126 break;
1127 return n;
1128 }
1129
1130 /* Returns the first visible band or infoPtr->uNumBands if none */
1131 static int first_visible(const REBAR_INFO *infoPtr)
1132 {
1133 return next_visible(infoPtr, -1); /* this works*/
1134 }
1135
1136 /* Returns the first visible band for the given row (or iBand if none) */
1137 static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
1138 {
1139 int iLastBand = iBand;
1140 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1141 while ((iBand = prev_visible(infoPtr, iBand)) >= 0) {
1142 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1143 break;
1144 else
1145 iLastBand = iBand;
1146 }
1147 return iLastBand;
1148 }
1149
1150 /* Returns the first visible band for the next row (or infoPtr->uNumBands if none) */
1151 static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
1152 {
1153 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1154 while ((iBand = next_visible(infoPtr, iBand)) < infoPtr->uNumBands)
1155 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1156 break;
1157 return iBand;
1158 }
1159
1160 /* Compute the rcBand.{left,right} from the cxEffective bands widths computed earlier.
1161 * iBeginBand must be visible */
1162 static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1163 {
1164 int xPos = 0, i;
1165 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1166 {
1167 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1168 if (lpBand->rcBand.left != xPos || lpBand->rcBand.right != xPos + lpBand->cxEffective) {
1169 lpBand->fDraw |= NTF_INVALIDATE;
1170 TRACE("Setting rect %d to %d,%d\n", i, xPos, xPos + lpBand->cxEffective);
1171 lpBand->rcBand.left = xPos;
1172 lpBand->rcBand.right = xPos + lpBand->cxEffective;
1173 }
1174 xPos += lpBand->cxEffective + SEP_WIDTH;
1175 }
1176 }
1177
1178 /* The rationale of this function is probably as follows: if we have some space
1179 * to distribute we want to add it to a band on the right. However we don't want
1180 * to unminimize a minimized band so we search for a band that is big enough.
1181 * For some reason "big enough" is defined as bigger than the minimum size of the
1182 * first band in the row
1183 */
1184 static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1185 {
1186 INT cxMinFirstBand = 0, i;
1187
1188 cxMinFirstBand = REBAR_GetBand(infoPtr, iBeginBand)->cxMinBand;
1189
1190 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1191 if (REBAR_GetBand(infoPtr, i)->cxEffective > cxMinFirstBand &&
1192 !(REBAR_GetBand(infoPtr, i)->fStyle & RBBS_FIXEDSIZE))
1193 break;
1194
1195 if (i < iBeginBand)
1196 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1197 if (REBAR_GetBand(infoPtr, i)->cxMinBand == cxMinFirstBand)
1198 break;
1199
1200 TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
1201 return REBAR_GetBand(infoPtr, i);
1202 }
1203
1204 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the right */
1205 static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1206 {
1207 REBAR_BAND *lpBand;
1208 INT width, i;
1209
1210 TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
1211 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1212 {
1213 lpBand = REBAR_GetBand(infoPtr, i);
1214
1215 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1216 cxShrink -= lpBand->cxEffective - width;
1217 lpBand->cxEffective = width;
1218 if (bEnforce && lpBand->cx > lpBand->cxEffective)
1219 lpBand->cx = lpBand->cxEffective;
1220 if (cxShrink == 0)
1221 break;
1222 }
1223 return cxShrink;
1224 }
1225
1226
1227 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the left.
1228 * iBeginBand must be visible */
1229 static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1230 {
1231 REBAR_BAND *lpBand;
1232 INT width, i;
1233
1234 TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
1235 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1236 {
1237 lpBand = REBAR_GetBand(infoPtr, i);
1238
1239 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1240 cxShrink -= lpBand->cxEffective - width;
1241 lpBand->cxEffective = width;
1242 if (bEnforce)
1243 lpBand->cx = lpBand->cxEffective;
1244 if (cxShrink == 0)
1245 break;
1246 }
1247 return cxShrink;
1248 }
1249
1250 /* Tries to move a band to a given offset within a row. */
1251 static int REBAR_MoveBandToRowOffset(REBAR_INFO *infoPtr, INT iBand, INT iFirstBand,
1252 INT iLastBand, INT xOff, BOOL reorder)
1253 {
1254 REBAR_BAND *insertBand = REBAR_GetBand(infoPtr, iBand);
1255 int xPos = 0, i;
1256 const BOOL setBreak = REBAR_GetBand(infoPtr, iFirstBand)->fStyle & RBBS_BREAK;
1257
1258 /* Find the band's new position */
1259 if(reorder)
1260 {
1261 /* Used during an LR band reorder drag */
1262 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1263 {
1264 if(xPos > xOff)
1265 break;
1266 xPos += REBAR_GetBand(infoPtr, i)->cxEffective + SEP_WIDTH;
1267 }
1268 }
1269 else
1270 {
1271 /* Used during a UD band insertion drag */
1272 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1273 {
1274 const REBAR_BAND *band = REBAR_GetBand(infoPtr, i);
1275 if(xPos + band->cxMinBand / 2 > xOff)
1276 break;
1277 xPos += band->cxEffective + SEP_WIDTH;
1278 }
1279 }
1280
1281 /* Move the band to its new position */
1282 DPA_DeletePtr(infoPtr->bands, iBand);
1283 if(i > iBand)
1284 i--;
1285 DPA_InsertPtr(infoPtr->bands, i, insertBand);
1286
1287 /* Ensure only the last band has the RBBS_BREAK flag set */
1288 insertBand->fStyle &= ~RBBS_BREAK;
1289 if(setBreak)
1290 REBAR_GetBand(infoPtr, iFirstBand)->fStyle |= RBBS_BREAK;
1291
1292 /* Return the currently grabbed band */
1293 if(infoPtr->iGrabbedBand == iBand)
1294 {
1295 infoPtr->iGrabbedBand = i;
1296 return i;
1297 }
1298 else return -1;
1299 }
1300
1301 /* Set the heights of the visible bands in [iBeginBand; iEndBand) to the max height. iBeginBand must be visible */
1302 static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
1303 {
1304 REBAR_BAND *lpBand;
1305 int yMaxHeight = 0;
1306 int yPos = yStart;
1307 int row = REBAR_GetBand(infoPtr, iBeginBand)->iRow;
1308 int i;
1309 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1310 {
1311 lpBand = REBAR_GetBand(infoPtr, i);
1312 lpBand->cyRowSoFar = yMaxHeight;
1313 yMaxHeight = max(yMaxHeight, lpBand->cyMinBand);
1314 }
1315 TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
1316
1317 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1318 {
1319 lpBand = REBAR_GetBand(infoPtr, i);
1320 /* we may be called for multiple rows if RBS_VARHEIGHT not set */
1321 if (lpBand->iRow != row) {
1322 yPos += yMaxHeight + SEP_WIDTH;
1323 row = lpBand->iRow;
1324 }
1325
1326 if (lpBand->rcBand.top != yPos || lpBand->rcBand.bottom != yPos + yMaxHeight) {
1327 lpBand->fDraw |= NTF_INVALIDATE;
1328 lpBand->rcBand.top = yPos;
1329 lpBand->rcBand.bottom = yPos + yMaxHeight;
1330 TRACE("Band %d: %s\n", i, wine_dbgstr_rect(&lpBand->rcBand));
1331 }
1332 }
1333 return yPos + yMaxHeight;
1334 }
1335
1336 /* Layout the row [iBeginBand; iEndBand). iBeginBand must be visible */
1337 static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
1338 {
1339 REBAR_BAND *lpBand;
1340 int i, extra;
1341 int width = 0;
1342
1343 TRACE("Adjusting row [%d;%d). Width: %d\n", iBeginBand, iEndBand, cx);
1344 for (i = iBeginBand; i < iEndBand; i++)
1345 REBAR_GetBand(infoPtr, i)->iRow = *piRow;
1346
1347 /* compute the extra space */
1348 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1349 {
1350 lpBand = REBAR_GetBand(infoPtr, i);
1351 if (i > iBeginBand)
1352 width += SEP_WIDTH;
1353 lpBand->cxEffective = max(lpBand->cxMinBand, lpBand->cx);
1354 width += lpBand->cxEffective;
1355 }
1356
1357 extra = cx - width;
1358 TRACE("Extra space: %d\n", extra);
1359 if (extra < 0) {
1360 int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
1361 if (ret > 0 && next_visible(infoPtr, iBeginBand) != iEndBand) /* one band may be longer than expected... */
1362 ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
1363 } else
1364 if (extra > 0) {
1365 lpBand = REBAR_FindBandToGrow(infoPtr, iBeginBand, iEndBand);
1366 lpBand->cxEffective += extra;
1367 }
1368
1369 REBAR_SetRowRectsX(infoPtr, iBeginBand, iEndBand);
1370 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1371 {
1372 if (*piRow > 0)
1373 *pyPos += SEP_WIDTH;
1374 *pyPos = REBAR_SetBandsHeight(infoPtr, iBeginBand, iEndBand, *pyPos);
1375 }
1376 (*piRow)++;
1377 }
1378
1379 static VOID
1380 REBAR_Layout(REBAR_INFO *infoPtr)
1381 {
1382 REBAR_BAND *lpBand;
1383 RECT rcAdj;
1384 SIZE oldSize;
1385 INT adjcx, i;
1386 INT rowstart;
1387 INT row = 0;
1388 INT xMin, yPos;
1389
1390 if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
1391 GetClientRect(infoPtr->hwndSelf, &rcAdj);
1392 else
1393 GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
1394 TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
1395
1396 adjcx = get_rect_cx(infoPtr, &rcAdj);
1397
1398 if (infoPtr->uNumBands == 0) {
1399 TRACE("No bands - setting size to (0,%d), vert: %x\n", adjcx, infoPtr->dwStyle & CCS_VERT);
1400 infoPtr->calcSize.cx = adjcx;
1401 /* the calcSize.cy won't change for a 0 band rebar */
1402 infoPtr->uNumRows = 0;
1403 REBAR_ForceResize(infoPtr);
1404 return;
1405 }
1406
1407 yPos = 0;
1408 xMin = 0;
1409 rowstart = first_visible(infoPtr);
1410 /* divide rows */
1411 for (i = rowstart; i < infoPtr->uNumBands; i = next_visible(infoPtr, i))
1412 {
1413 lpBand = REBAR_GetBand(infoPtr, i);
1414
1415 if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->cxMinBand > adjcx)) {
1416 TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
1417 REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
1418 rowstart = i;
1419 xMin = 0;
1420 }
1421 else
1422 xMin += SEP_WIDTH;
1423
1424 xMin += lpBand->cxMinBand;
1425 }
1426 if (rowstart < infoPtr->uNumBands)
1427 REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
1428
1429 if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
1430 yPos = REBAR_SetBandsHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, 0);
1431
1432 infoPtr->uNumRows = row;
1433
1434 if (infoPtr->dwStyle & CCS_VERT)
1435 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1436 else
1437 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1438 /* now compute size of Rebar itself */
1439 oldSize = infoPtr->calcSize;
1440
1441 infoPtr->calcSize.cx = adjcx;
1442 infoPtr->calcSize.cy = yPos;
1443 TRACE("calcsize size=(%d, %d), origheight=(%d,%d)\n",
1444 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1445 oldSize.cx, oldSize.cy);
1446
1447 REBAR_DumpBand (infoPtr);
1448 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1449 REBAR_ForceResize (infoPtr);
1450
1451 /* note: after a RBN_HEIGHTCHANGE native sends once again all the RBN_CHILDSIZE
1452 * and does another ForceResize */
1453 if (oldSize.cy != infoPtr->calcSize.cy)
1454 {
1455 NMHDR heightchange;
1456 REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1457 REBAR_AutoSize(infoPtr, FALSE);
1458 }
1459 }
1460
1461 /* iBeginBand must be visible */
1462 static int
1463 REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
1464 {
1465 int cyBandsOld;
1466 int cyBandsNew = 0;
1467 int i;
1468
1469 TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
1470
1471 cyBandsOld = REBAR_GetBand(infoPtr, iBeginBand)->rcBand.bottom -
1472 REBAR_GetBand(infoPtr, iBeginBand)->rcBand.top;
1473 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1474 {
1475 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1476 int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
1477 int cyChild = round_child_height(lpBand, cyMaxChild);
1478
1479 if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
1480 {
1481 TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
1482 *fChanged = TRUE;
1483 lpBand->cyChild = cyChild;
1484 lpBand->fDraw |= NTF_INVALIDATE;
1485 update_min_band_height(infoPtr, lpBand);
1486 }
1487 cyBandsNew = max(cyBandsNew, lpBand->cyMinBand);
1488 }
1489 return cyBandsNew - cyBandsOld;
1490 }
1491
1492 /* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
1493 static VOID
1494 REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
1495 {
1496 int extra = height - infoPtr->calcSize.cy; /* may be negative */
1497 BOOL fChanged = FALSE;
1498 UINT uNumRows = infoPtr->uNumRows;
1499 int i;
1500
1501 if (uNumRows == 0) /* avoid division by 0 */
1502 return;
1503
1504 /* That's not exactly what Windows does but should be similar */
1505
1506 /* Pass one: break-up/glue rows */
1507 if (extra > 0)
1508 {
1509 for (i = prev_visible(infoPtr, infoPtr->uNumBands); i > 0; i = prev_visible(infoPtr, i))
1510 {
1511 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1512 int cyBreakExtra; /* additional cy for the rebar after a RBBS_BREAK on this band */
1513
1514 height = lpBand->rcBand.bottom - lpBand->rcBand.top;
1515
1516 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1517 cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
1518 else
1519 cyBreakExtra = height; /* 'height' => 'height' + 'height'*/
1520 cyBreakExtra += SEP_WIDTH;
1521
1522 if (extra <= cyBreakExtra / 2)
1523 break;
1524
1525 if (!(lpBand->fStyle & RBBS_BREAK))
1526 {
1527 TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
1528 lpBand->fStyle |= RBBS_BREAK;
1529 lpBand->fDraw |= NTF_INVALIDATE;
1530 fChanged = TRUE;
1531 extra -= cyBreakExtra;
1532 uNumRows++;
1533 /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
1534 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1535 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->cyMinBand;
1536 }
1537 }
1538 }
1539 /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
1540
1541 /* Pass two: increase/decrease control height */
1542 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1543 {
1544 int i = first_visible(infoPtr);
1545 int iRow = 0;
1546 while (i < infoPtr->uNumBands)
1547 {
1548 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1549 int extraForRow = extra / (int)(uNumRows - iRow);
1550 int rowEnd;
1551
1552 /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
1553 for (rowEnd = next_visible(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_visible(infoPtr, rowEnd))
1554 if (REBAR_GetBand(infoPtr, rowEnd)->iRow != lpBand->iRow ||
1555 REBAR_GetBand(infoPtr, rowEnd)->fStyle & RBBS_BREAK)
1556 break;
1557
1558 extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
1559 TRACE("extra = %d\n", extra);
1560 i = rowEnd;
1561 iRow++;
1562 }
1563 }
1564 else
1565 REBAR_SizeChildrenToHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
1566
1567 if (fChanged)
1568 REBAR_Layout(infoPtr);
1569 }
1570
1571 static VOID
1572 REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout)
1573 {
1574 RECT rc, rcNew;
1575 NMRBAUTOSIZE autosize;
1576
1577 if (needsLayout)
1578 REBAR_Layout(infoPtr);
1579 GetClientRect(infoPtr->hwndSelf, &rc);
1580 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, &rc));
1581 GetClientRect(infoPtr->hwndSelf, &rcNew);
1582
1583 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
1584 autosize.fChanged = (memcmp(&rc, &rcNew, sizeof(RECT)) == 0);
1585 autosize.rcTarget = rc;
1586 autosize.rcActual = rcNew;
1587 REBAR_Notify((NMHDR *)&autosize, infoPtr, RBN_AUTOSIZE);
1588 }
1589
1590 static VOID
1591 REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1592 /* Function: This routine evaluates the band specs supplied */
1593 /* by the user and updates the following 5 fields in */
1594 /* the internal band structure: cxHeader, cyHeader, cxMinBand, cyMinBand, fStatus */
1595 {
1596 UINT header=0;
1597 UINT textheight=0, imageheight = 0;
1598 UINT i, nonfixed;
1599 REBAR_BAND *tBand;
1600
1601 lpBand->fStatus = 0;
1602 lpBand->cxMinBand = 0;
1603 lpBand->cyMinBand = 0;
1604
1605 /* Data coming in from users into the cx... and cy... fields */
1606 /* may be bad, just garbage, because the user never clears */
1607 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1608 /* along if the fields exist in the input area. Here we must */
1609 /* determine if the data is valid. I have no idea how MS does */
1610 /* the validation, but it does because the RB_GETBANDINFO */
1611 /* returns a 0 when I know the sample program passed in an */
1612 /* address. Here I will use the algorithm that if the value */
1613 /* is greater than 65535 then it is bad and replace it with */
1614 /* a zero. Feel free to improve the algorithm. - GA 12/2000 */
1615 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1616 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1617 if (lpBand->cx > 65535) lpBand->cx = 0;
1618 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1619 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1620 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1621 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1622
1623 /* TODO : we could try return to the caller if a value changed so that */
1624 /* a REBAR_Layout is needed. Till now the caller should call it */
1625 /* it always (we should also check what native does) */
1626
1627 /* Header is where the image, text and gripper exist */
1628 /* in the band and precede the child window. */
1629
1630 /* count number of non-FIXEDSIZE and non-Hidden bands */
1631 nonfixed = 0;
1632 for (i=0; i<infoPtr->uNumBands; i++){
1633 tBand = REBAR_GetBand(infoPtr, i);
1634 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1635 nonfixed++;
1636 }
1637
1638 /* calculate gripper rectangle */
1639 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1640 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1641 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1642 ) {
1643 lpBand->fStatus |= HAS_GRIPPER;
1644 if (infoPtr->dwStyle & CCS_VERT)
1645 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1646 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1647 else
1648 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1649 else
1650 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1651 /* Always have 4 pixels before anything else */
1652 header += REBAR_ALWAYS_SPACE;
1653 }
1654
1655 /* image is visible */
1656 if (lpBand->iImage != -1 && (infoPtr->himl)) {
1657 lpBand->fStatus |= HAS_IMAGE;
1658 if (infoPtr->dwStyle & CCS_VERT) {
1659 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1660 imageheight = infoPtr->imageSize.cx + 4;
1661 }
1662 else {
1663 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1664 imageheight = infoPtr->imageSize.cy + 4;
1665 }
1666 }
1667
1668 /* text is visible */
1669 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
1670 !(lpBand->fStyle & RBBS_HIDETITLE)) {
1671 HDC hdc = GetDC (0);
1672 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1673 SIZE size;
1674
1675 lpBand->fStatus |= HAS_TEXT;
1676 GetTextExtentPoint32W (hdc, lpBand->lpText,
1677 lstrlenW (lpBand->lpText), &size);
1678 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1679 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1680
1681 SelectObject (hdc, hOldFont);
1682 ReleaseDC (0, hdc);
1683 }
1684
1685 /* if no gripper but either image or text, then leave space */
1686 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1687 !(lpBand->fStatus & HAS_GRIPPER)) {
1688 header += REBAR_ALWAYS_SPACE;
1689 }
1690
1691 /* check if user overrode the header value */
1692 if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
1693 lpBand->cxHeader = header;
1694 lpBand->cyHeader = max(textheight, imageheight);
1695
1696 /* Now compute minimum size of child window */
1697 update_min_band_height(infoPtr, lpBand); /* update lpBand->cyMinBand from cyHeader and cyChild*/
1698
1699 lpBand->cxMinBand = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
1700 if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
1701 lpBand->cxMinBand += CHEVRON_WIDTH;
1702 }
1703
1704 static UINT
1705 REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
1706 /* Function: This routine copies the supplied values from */
1707 /* user input (lprbbi) to the internal band structure. */
1708 /* It returns the mask of what changed. */
1709 {
1710 UINT uChanged = 0x0;
1711
1712 lpBand->fMask |= lprbbi->fMask;
1713
1714 if( (lprbbi->fMask & RBBIM_STYLE) &&
1715 (lpBand->fStyle != lprbbi->fStyle ) )
1716 {
1717 lpBand->fStyle = lprbbi->fStyle;
1718 uChanged |= RBBIM_STYLE;
1719 }
1720
1721 if( (lprbbi->fMask & RBBIM_COLORS) &&
1722 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
1723 ( lpBand->clrBack != lprbbi->clrBack ) ) )
1724 {
1725 lpBand->clrFore = lprbbi->clrFore;
1726 lpBand->clrBack = lprbbi->clrBack;
1727 uChanged |= RBBIM_COLORS;
1728 }
1729
1730 if( (lprbbi->fMask & RBBIM_IMAGE) &&
1731 ( lpBand->iImage != lprbbi->iImage ) )
1732 {
1733 lpBand->iImage = lprbbi->iImage;
1734 uChanged |= RBBIM_IMAGE;
1735 }
1736
1737 if( (lprbbi->fMask & RBBIM_CHILD) &&
1738 (lprbbi->hwndChild != lpBand->hwndChild ) )
1739 {
1740 if (lprbbi->hwndChild) {
1741 lpBand->hwndChild = lprbbi->hwndChild;
1742 lpBand->hwndPrevParent =
1743 SetParent (lpBand->hwndChild, hwnd);
1744 /* below in trace from WinRAR */
1745 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
1746 /* above in trace from WinRAR */
1747 }
1748 else {
1749 TRACE("child: %p prev parent: %p\n",
1750 lpBand->hwndChild, lpBand->hwndPrevParent);
1751 lpBand->hwndChild = 0;
1752 lpBand->hwndPrevParent = 0;
1753 }
1754 uChanged |= RBBIM_CHILD;
1755 }
1756
1757 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
1758 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
1759 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
1760 ( (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) &&
1761 ( (lpBand->cyChild != lprbbi->cyChild ) ||
1762 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
1763 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
1764 ( (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE) &&
1765 ( (lpBand->cyChild ||
1766 lpBand->cyMaxChild ||
1767 lpBand->cyIntegral ) ) ) ) )
1768 {
1769 lpBand->cxMinChild = lprbbi->cxMinChild;
1770 lpBand->cyMinChild = lprbbi->cyMinChild;
1771 /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
1772 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
1773 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1774 lpBand->cyIntegral = lprbbi->cyIntegral;
1775
1776 lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild); /* make (cyChild - cyMinChild) a multiple of cyIntergral */
1777 }
1778 else {
1779 lpBand->cyChild = lpBand->cyMinChild;
1780 lpBand->cyMaxChild = 0x7fffffff;
1781 lpBand->cyIntegral = 0;
1782 }
1783 uChanged |= RBBIM_CHILDSIZE;
1784 }
1785
1786 if( (lprbbi->fMask & RBBIM_SIZE) &&
1787 (lpBand->cx != lprbbi->cx ) )
1788 {
1789 lpBand->cx = lprbbi->cx;
1790 uChanged |= RBBIM_SIZE;
1791 }
1792
1793 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
1794 ( lpBand->hbmBack != lprbbi->hbmBack ) )
1795 {
1796 lpBand->hbmBack = lprbbi->hbmBack;
1797 uChanged |= RBBIM_BACKGROUND;
1798 }
1799
1800 if( (lprbbi->fMask & RBBIM_ID) &&
1801 (lpBand->wID != lprbbi->wID ) )
1802 {
1803 lpBand->wID = lprbbi->wID;
1804 uChanged |= RBBIM_ID;
1805 }
1806
1807 /* check for additional data */
1808 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE) {
1809 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
1810 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
1811 {
1812 lpBand->cxIdeal = lprbbi->cxIdeal;
1813 uChanged |= RBBIM_IDEALSIZE;
1814 }
1815
1816 if( (lprbbi->fMask & RBBIM_LPARAM) &&
1817 (lpBand->lParam != lprbbi->lParam ) )
1818 {
1819 lpBand->lParam = lprbbi->lParam;
1820 uChanged |= RBBIM_LPARAM;
1821 }
1822
1823 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
1824 (lpBand->cxHeader != lprbbi->cxHeader ) )
1825 {
1826 lpBand->cxHeader = lprbbi->cxHeader;
1827 lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
1828 uChanged |= RBBIM_HEADERSIZE;
1829 }
1830 }
1831
1832 return uChanged;
1833 }
1834
1835 static LRESULT REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, HDC hdc)
1836 /* Function: This erases the background rectangle by drawing */
1837 /* each band with its background color (or the default) and */
1838 /* draws each bands right separator if necessary. The row */
1839 /* separators are drawn on the first band of the next row. */
1840 {
1841 REBAR_BAND *lpBand;
1842 UINT i;
1843 INT oldrow;
1844 RECT cr;
1845 COLORREF old = CLR_NONE, new;
1846 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1847
1848 GetClientRect (infoPtr->hwndSelf, &cr);
1849
1850 oldrow = -1;
1851 for(i=0; i<infoPtr->uNumBands; i++) {
1852 RECT rcBand;
1853 lpBand = REBAR_GetBand(infoPtr, i);
1854 if (HIDDENBAND(lpBand)) continue;
1855 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1856
1857 /* draw band separator between rows */
1858 if (lpBand->iRow != oldrow) {
1859 oldrow = lpBand->iRow;
1860 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1861 RECT rcRowSep;
1862 rcRowSep = rcBand;
1863 if (infoPtr->dwStyle & CCS_VERT) {
1864 rcRowSep.right += SEP_WIDTH_SIZE;
1865 rcRowSep.bottom = infoPtr->calcSize.cx;
1866 if (theme)
1867 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_RIGHT, NULL);
1868 else
1869 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
1870 }
1871 else {
1872 rcRowSep.bottom += SEP_WIDTH_SIZE;
1873 rcRowSep.right = infoPtr->calcSize.cx;
1874 if (theme)
1875 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1876 else
1877 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
1878 }
1879 TRACE ("drawing band separator bottom (%s)\n",
1880 wine_dbgstr_rect(&rcRowSep));
1881 }
1882 }
1883
1884 /* draw band separator between bands in a row */
1885 if (infoPtr->dwStyle & RBS_BANDBORDERS && lpBand->rcBand.left > 0) {
1886 RECT rcSep;
1887 rcSep = rcBand;
1888 if (infoPtr->dwStyle & CCS_VERT) {
1889 rcSep.bottom = rcSep.top;
1890 rcSep.top -= SEP_WIDTH_SIZE;
1891 if (theme)
1892 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1893 else
1894 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
1895 }
1896 else {
1897 rcSep.right = rcSep.left;
1898 rcSep.left -= SEP_WIDTH_SIZE;
1899 if (theme)
1900 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_RIGHT, NULL);
1901 else
1902 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
1903 }
1904 TRACE("drawing band separator right (%s)\n",
1905 wine_dbgstr_rect(&rcSep));
1906 }
1907
1908 /* draw the actual background */
1909 if (lpBand->clrBack != CLR_NONE) {
1910 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
1911 lpBand->clrBack;
1912 #if GLATESTING
1913 /* testing only - make background green to see it */
1914 new = RGB(0,128,0);
1915 #endif
1916 }
1917 else {
1918 /* In the absence of documentation for Rebar vs. CLR_NONE,
1919 * we will use the default BtnFace color. Note documentation
1920 * exists for Listview and Imagelist.
1921 */
1922 new = infoPtr->clrBtnFace;
1923 #if GLATESTING
1924 /* testing only - make background green to see it */
1925 new = RGB(0,128,0);
1926 #endif
1927 }
1928
1929 if (theme)
1930 {
1931 /* When themed, the background color is ignored (but not a
1932 * background bitmap */
1933 DrawThemeBackground (theme, hdc, 0, 0, &cr, &rcBand);
1934 }
1935 else
1936 {
1937 old = SetBkColor (hdc, new);
1938 TRACE("%s background color=0x%06x, band %s\n",
1939 (lpBand->clrBack == CLR_NONE) ? "none" :
1940 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
1941 GetBkColor(hdc), wine_dbgstr_rect(&rcBand));
1942 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &rcBand, NULL, 0, 0);
1943 if (lpBand->clrBack != CLR_NONE)
1944 SetBkColor (hdc, old);
1945 }
1946 }
1947 return TRUE;
1948 }
1949
1950 static void
1951 REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
1952 {
1953 REBAR_BAND *lpBand;
1954 RECT rect;
1955 UINT iCount;
1956
1957 GetClientRect (infoPtr->hwndSelf, &rect);
1958
1959 *pFlags = RBHT_NOWHERE;
1960 if (PtInRect (&rect, *lpPt))
1961 {
1962 if (infoPtr->uNumBands == 0) {
1963 *pFlags = RBHT_NOWHERE;
1964 if (pBand)
1965 *pBand = -1;
1966 TRACE("NOWHERE\n");
1967 return;
1968 }
1969 else {
1970 /* somewhere inside */
1971 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
1972 RECT rcBand;
1973 lpBand = REBAR_GetBand(infoPtr, iCount);
1974 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1975 if (HIDDENBAND(lpBand)) continue;
1976 if (PtInRect (&rcBand, *lpPt)) {
1977 if (pBand)
1978 *pBand = iCount;
1979 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
1980 *pFlags = RBHT_GRABBER;
1981 TRACE("ON GRABBER %d\n", iCount);
1982 return;
1983 }
1984 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
1985 *pFlags = RBHT_CAPTION;
1986 TRACE("ON CAPTION %d\n", iCount);
1987 return;
1988 }
1989 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
1990 *pFlags = RBHT_CAPTION;
1991 TRACE("ON CAPTION %d\n", iCount);
1992 return;
1993 }
1994 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
1995 *pFlags = RBHT_CLIENT;
1996 TRACE("ON CLIENT %d\n", iCount);
1997 return;
1998 }
1999 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
2000 *pFlags = RBHT_CHEVRON;
2001 TRACE("ON CHEVRON %d\n", iCount);
2002 return;
2003 }
2004 else {
2005 *pFlags = RBHT_NOWHERE;
2006 TRACE("NOWHERE %d\n", iCount);
2007 return;
2008 }
2009 }
2010 }
2011
2012 *pFlags = RBHT_NOWHERE;
2013 if (pBand)
2014 *pBand = -1;
2015
2016 TRACE("NOWHERE\n");
2017 return;
2018 }
2019 }
2020 else {
2021 *pFlags = RBHT_NOWHERE;
2022 if (pBand)
2023 *pBand = -1;
2024 TRACE("NOWHERE\n");
2025 return;
2026 }
2027 }
2028
2029 static void
2030 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2031 /* Function: This will implement the functionality of a */
2032 /* Gripper drag within a row. It will not implement "out- */
2033 /* of-row" drags. (They are detected and handled in */
2034 /* REBAR_MouseMove.) */
2035 {
2036 REBAR_BAND *hitBand;
2037 INT iHitBand, iRowBegin, iRowEnd;
2038 INT movement, xBand, cxLeft = 0;
2039 BOOL shrunkBands = FALSE;
2040
2041 iHitBand = infoPtr->iGrabbedBand;
2042 iRowBegin = get_row_begin_for_band(infoPtr, iHitBand);
2043 iRowEnd = get_row_end_for_band(infoPtr, iHitBand);
2044 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2045
2046 xBand = hitBand->rcBand.left;
2047 movement = (infoPtr->dwStyle&CCS_VERT ? ptsmove->y : ptsmove->x)
2048 - (xBand + REBAR_PRE_GRIPPER - infoPtr->ihitoffset);
2049
2050 /* Dragging the first band in a row cannot cause shrinking */
2051 if(iHitBand != iRowBegin)
2052 {
2053 if (movement < 0) {
2054 cxLeft = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iHitBand, -movement, TRUE);
2055
2056 if(cxLeft < -movement)
2057 {
2058 hitBand->cxEffective += -movement - cxLeft;
2059 hitBand->cx = hitBand->cxEffective;
2060 shrunkBands = TRUE;
2061 }
2062
2063 } else if (movement > 0) {
2064
2065 cxLeft = movement;
2066 if (prev_visible(infoPtr, iHitBand) >= 0)
2067 cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
2068
2069 if(cxLeft < movement)
2070 {
2071 REBAR_BAND *lpPrev = REBAR_GetBand(infoPtr, prev_visible(infoPtr, iHitBand));
2072 lpPrev->cxEffective += movement - cxLeft;
2073 lpPrev->cx = hitBand->cxEffective;
2074 shrunkBands = TRUE;
2075 }
2076
2077 }
2078 }
2079
2080 if(!shrunkBands)
2081 {
2082 /* It was not possible to move the band by shrinking bands.
2083 * Try relocating the band instead. */
2084 REBAR_MoveBandToRowOffset(infoPtr, iHitBand, iRowBegin,
2085 iRowEnd, xBand + movement, TRUE);
2086 }
2087
2088 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2089 if (infoPtr->dwStyle & CCS_VERT)
2090 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
2091 else
2092 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
2093 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2094 }
2095
2096 static void
2097 REBAR_HandleUDDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2098 {
2099 INT yOff = (infoPtr->dwStyle & CCS_VERT) ? ptsmove->x : ptsmove->y;
2100 INT iHitBand, iRowBegin, iNextRowBegin;
2101 REBAR_BAND *hitBand, *rowBeginBand;
2102
2103 if(infoPtr->uNumBands <= 0)
2104 ERR("There are no bands in this rebar\n");
2105
2106 /* Up/down dragging can only occur when there is more than one
2107 * band in the rebar */
2108 if(infoPtr->uNumBands <= 1)
2109 return;
2110
2111 iHitBand = infoPtr->iGrabbedBand;
2112 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2113
2114 /* If we're taking a band that has the RBBS_BREAK style set, this
2115 * style needs to be reapplied to the band that is going to become
2116 * the new start of the row. */
2117 if((hitBand->fStyle & RBBS_BREAK) &&
2118 (iHitBand < infoPtr->uNumBands - 1))
2119 REBAR_GetBand(infoPtr, iHitBand + 1)->fStyle |= RBBS_BREAK;
2120
2121 if(yOff < 0)
2122 {
2123 /* Place the band above the current top row */
2124 if(iHitBand==0 && (infoPtr->uNumBands==1 || REBAR_GetBand(infoPtr, 1)->fStyle&RBBS_BREAK))
2125 return;
2126 DPA_DeletePtr(infoPtr->bands, iHitBand);
2127 hitBand->fStyle &= ~RBBS_BREAK;
2128 REBAR_GetBand(infoPtr, 0)->fStyle |= RBBS_BREAK;
2129 infoPtr->iGrabbedBand = DPA_InsertPtr(
2130 infoPtr->bands, 0, hitBand);
2131 }
2132 else if(yOff > REBAR_GetBand(infoPtr, infoPtr->uNumBands - 1)->rcBand.bottom)
2133 {
2134 /* Place the band below the current bottom row */
2135 if(iHitBand == infoPtr->uNumBands-1 && hitBand->fStyle&RBBS_BREAK)
2136 return;
2137 DPA_DeletePtr(infoPtr->bands, iHitBand);
2138 hitBand->fStyle |= RBBS_BREAK;
2139 infoPtr->iGrabbedBand = DPA_InsertPtr(
2140 infoPtr->bands, infoPtr->uNumBands - 1, hitBand);
2141 }
2142 else
2143 {
2144 /* Place the band in the prexisting row the mouse is hovering over */
2145 iRowBegin = first_visible(infoPtr);
2146 while(iRowBegin < infoPtr->uNumBands)
2147 {
2148 iNextRowBegin = get_row_end_for_band(infoPtr, iRowBegin);
2149 rowBeginBand = REBAR_GetBand(infoPtr, iRowBegin);
2150 if(rowBeginBand->rcBand.bottom > yOff)
2151 {
2152 REBAR_MoveBandToRowOffset(
2153 infoPtr, iHitBand, iRowBegin, iNextRowBegin,
2154 ((infoPtr->dwStyle & CCS_VERT) ? ptsmove->y : ptsmove->x)
2155 - REBAR_PRE_GRIPPER - infoPtr->ihitoffset, FALSE);
2156 break;
2157 }
2158
2159 iRowBegin = iNextRowBegin;
2160 }
2161 }
2162
2163 REBAR_Layout(infoPtr);
2164 }
2165
2166
2167 /* << REBAR_BeginDrag >> */
2168
2169
2170 static LRESULT
2171 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam)
2172 {
2173 UINT uBand = (UINT)wParam;
2174 REBAR_BAND *lpBand;
2175
2176 if (uBand >= infoPtr->uNumBands)
2177 return FALSE;
2178
2179 TRACE("deleting band %u!\n", uBand);
2180 lpBand = REBAR_GetBand(infoPtr, uBand);
2181 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2182 /* TODO: a return of 1 should probably cancel the deletion */
2183
2184 if (lpBand->hwndChild)
2185 ShowWindow(lpBand->hwndChild, SW_HIDE);
2186 Free(lpBand->lpText);
2187 Free(lpBand);
2188
2189 infoPtr->uNumBands--;
2190 DPA_DeletePtr(infoPtr->bands, uBand);
2191
2192 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2193
2194 /* if only 1 band left the re-validate to possible eliminate gripper */
2195 if (infoPtr->uNumBands == 1)
2196 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2197
2198 REBAR_Layout(infoPtr);
2199
2200 return TRUE;
2201 }
2202
2203
2204 /* << REBAR_DragMove >> */
2205 /* << REBAR_EndDrag >> */
2206
2207
2208 static LRESULT
2209 REBAR_GetBandBorders (const REBAR_INFO *infoPtr, UINT uBand, RECT *lpRect)
2210 {
2211 REBAR_BAND *lpBand;
2212
2213 if (!lpRect)
2214 return 0;
2215 if (uBand >= infoPtr->uNumBands)
2216 return 0;
2217
2218 lpBand = REBAR_GetBand(infoPtr, uBand);
2219
2220 /* FIXME - the following values were determined by experimentation */
2221 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2222 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2223 /* difference in size of the control area with and without the */
2224 /* style. - GA */
2225 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2226 if (infoPtr->dwStyle & CCS_VERT) {
2227 lpRect->left = 1;
2228 lpRect->top = lpBand->cxHeader + 4;
2229 lpRect->right = 1;
2230 lpRect->bottom = 0;
2231 }
2232 else {
2233 lpRect->left = lpBand->cxHeader + 4;
2234 lpRect->top = 1;
2235 lpRect->right = 0;
2236 lpRect->bottom = 1;
2237 }
2238 }
2239 else {
2240 lpRect->left = lpBand->cxHeader;
2241 }
2242 return 0;
2243 }
2244
2245
2246 static inline LRESULT
2247 REBAR_GetBandCount (const REBAR_INFO *infoPtr)
2248 {
2249 TRACE("band count %u!\n", infoPtr->uNumBands);
2250
2251 return infoPtr->uNumBands;
2252 }
2253
2254
2255 static LRESULT
2256 REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, UINT uIndex, LPREBARBANDINFOW lprbbi, BOOL bUnicode)
2257 {
2258 REBAR_BAND *lpBand;
2259
2260 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2261 return FALSE;
2262
2263 if (uIndex >= infoPtr->uNumBands)
2264 return FALSE;
2265
2266 TRACE("index %u (bUnicode=%d)\n", uIndex, bUnicode);
2267
2268 /* copy band information */
2269 lpBand = REBAR_GetBand(infoPtr, uIndex);
2270
2271 if (lprbbi->fMask & RBBIM_STYLE)
2272 lprbbi->fStyle = lpBand->fStyle;
2273
2274 if (lprbbi->fMask & RBBIM_COLORS) {
2275 lprbbi->clrFore = lpBand->clrFore;
2276 lprbbi->clrBack = lpBand->clrBack;
2277 if (lprbbi->clrBack == CLR_DEFAULT)
2278 lprbbi->clrBack = infoPtr->clrBtnFace;
2279 }
2280
2281 if (lprbbi->fMask & RBBIM_TEXT) {
2282 if (bUnicode)
2283 Str_GetPtrW(lpBand->lpText, lprbbi->lpText, lprbbi->cch);
2284 else
2285 Str_GetPtrWtoA(lpBand->lpText, (LPSTR)lprbbi->lpText, lprbbi->cch);
2286 }
2287
2288 if (lprbbi->fMask & RBBIM_IMAGE)
2289 lprbbi->iImage = lpBand->iImage;
2290
2291 if (lprbbi->fMask & RBBIM_CHILD)
2292 lprbbi->hwndChild = lpBand->hwndChild;
2293
2294 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2295 lprbbi->cxMinChild = lpBand->cxMinChild;
2296 lprbbi->cyMinChild = lpBand->cyMinChild;
2297 /* to make tests pass we follow Windows behaviour and allow to read these fields only
2298 * for RBBS_VARIABLEHEIGHTS bands */
2299 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2300 lprbbi->cyChild = lpBand->cyChild;
2301 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2302 lprbbi->cyIntegral = lpBand->cyIntegral;
2303 }
2304 }
2305
2306 if (lprbbi->fMask & RBBIM_SIZE)
2307 lprbbi->cx = lpBand->cx;
2308
2309 if (lprbbi->fMask & RBBIM_BACKGROUND)
2310 lprbbi->hbmBack = lpBand->hbmBack;
2311
2312 if (lprbbi->fMask & RBBIM_ID)
2313 lprbbi->wID = lpBand->wID;
2314
2315 /* check for additional data */
2316 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE) {
2317 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2318 lprbbi->cxIdeal = lpBand->cxIdeal;
2319
2320 if (lprbbi->fMask & RBBIM_LPARAM)
2321 lprbbi->lParam = lpBand->lParam;
2322
2323 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2324 lprbbi->cxHeader = lpBand->cxHeader;
2325 }
2326
2327 REBAR_DumpBandInfo(lprbbi);
2328
2329 return TRUE;
2330 }
2331
2332
2333 static LRESULT
2334 REBAR_GetBarHeight (const REBAR_INFO *infoPtr)
2335 {
2336 INT nHeight;
2337
2338 nHeight = infoPtr->calcSize.cy;
2339
2340 TRACE("height = %d\n", nHeight);
2341
2342 return nHeight;
2343 }
2344
2345
2346 static LRESULT
2347 REBAR_GetBarInfo (const REBAR_INFO *infoPtr, LPREBARINFO lpInfo)
2348 {
2349 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2350 return FALSE;
2351
2352 TRACE("getting bar info!\n");
2353
2354 if (infoPtr->himl) {
2355 lpInfo->himl = infoPtr->himl;
2356 lpInfo->fMask |= RBIM_IMAGELIST;
2357 }
2358
2359 return TRUE;
2360 }
2361
2362
2363 static inline LRESULT
2364 REBAR_GetBkColor (const REBAR_INFO *infoPtr)
2365 {
2366 COLORREF clr = infoPtr->clrBk;
2367
2368 if (clr == CLR_DEFAULT)
2369 clr = infoPtr->clrBtnFace;
2370
2371 TRACE("background color 0x%06x!\n", clr);
2372
2373 return clr;
2374 }
2375
2376
2377 /* << REBAR_GetColorScheme >> */
2378 /* << REBAR_GetDropTarget >> */
2379
2380
2381 static LRESULT
2382 REBAR_GetPalette (const REBAR_INFO *infoPtr)
2383 {
2384 FIXME("empty stub!\n");
2385
2386 return 0;
2387 }
2388
2389
2390 static LRESULT
2391 REBAR_GetRect (const REBAR_INFO *infoPtr, INT iBand, RECT *lprc)
2392 {
2393 REBAR_BAND *lpBand;
2394
2395 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2396 return FALSE;
2397 if (!lprc)
2398 return FALSE;
2399
2400 lpBand = REBAR_GetBand(infoPtr, iBand);
2401 /* For CCS_VERT the coordinates will be swapped - like on Windows */
2402 CopyRect (lprc, &lpBand->rcBand);
2403
2404 TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
2405
2406 return TRUE;
2407 }
2408
2409
2410 static inline LRESULT
2411 REBAR_GetRowCount (const REBAR_INFO *infoPtr)
2412 {
2413 TRACE("%u\n", infoPtr->uNumRows);
2414
2415 return infoPtr->uNumRows;
2416 }
2417
2418
2419 static LRESULT
2420 REBAR_GetRowHeight (const REBAR_INFO *infoPtr, INT iRow)
2421 {
2422 int j = 0, ret = 0;
2423 UINT i;
2424 REBAR_BAND *lpBand;
2425
2426 for (i=0; i<infoPtr->uNumBands; i++) {
2427 lpBand = REBAR_GetBand(infoPtr, i);
2428 if (HIDDENBAND(lpBand)) continue;
2429 if (lpBand->iRow != iRow) continue;
2430 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2431 if (j > ret) ret = j;
2432 }
2433
2434 TRACE("row %d, height %d\n", iRow, ret);
2435
2436 return ret;
2437 }
2438
2439
2440 static inline LRESULT
2441 REBAR_GetTextColor (const REBAR_INFO *infoPtr)
2442 {
2443 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2444
2445 return infoPtr->clrText;
2446 }
2447
2448
2449 static inline LRESULT
2450 REBAR_GetToolTips (const REBAR_INFO *infoPtr)
2451 {
2452 return (LRESULT)infoPtr->hwndToolTip;
2453 }
2454
2455
2456 static inline LRESULT
2457 REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
2458 {
2459 TRACE("%s hwnd=%p\n",
2460 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2461
2462 return infoPtr->bUnicode;
2463 }
2464
2465
2466 static inline LRESULT
2467 REBAR_GetVersion (const REBAR_INFO *infoPtr)
2468 {
2469 TRACE("version %d\n", infoPtr->iVersion);
2470 return infoPtr->iVersion;
2471 }
2472
2473
2474 static LRESULT
2475 REBAR_HitTest (const REBAR_INFO *infoPtr, LPRBHITTESTINFO lprbht)
2476 {
2477 if (!lprbht)
2478 return -1;
2479
2480 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2481
2482 return lprbht->iBand;
2483 }
2484
2485
2486 static LRESULT
2487 REBAR_IdToIndex (const REBAR_INFO *infoPtr, UINT uId)
2488 {
2489 UINT i;
2490
2491 if (infoPtr->uNumBands < 1)
2492 return -1;
2493
2494 for (i = 0; i < infoPtr->uNumBands; i++) {
2495 if (REBAR_GetBand(infoPtr, i)->wID == uId) {
2496 TRACE("id %u is band %u found!\n", uId, i);
2497 return i;
2498 }
2499 }
2500
2501 TRACE("id %u is not found\n", uId);
2502 return -1;
2503 }
2504
2505
2506 static LRESULT
2507 REBAR_InsertBandT(REBAR_INFO *infoPtr, INT iIndex, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2508 {
2509 REBAR_BAND *lpBand;
2510
2511 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2512 return FALSE;
2513
2514 /* trace the index as signed to see the -1 */
2515 TRACE("insert band at %d (bUnicode=%d)!\n", iIndex, bUnicode);
2516 REBAR_DumpBandInfo(lprbbi);
2517
2518 if (!(lpBand = Alloc(sizeof(REBAR_BAND)))) return FALSE;
2519 if ((iIndex == -1) || (iIndex > infoPtr->uNumBands))
2520 iIndex = infoPtr->uNumBands;
2521 if (DPA_InsertPtr(infoPtr->bands, iIndex, lpBand) == -1)
2522 {
2523 Free(lpBand);
2524 return FALSE;
2525 }
2526 infoPtr->uNumBands++;
2527
2528 TRACE("index %d!\n", iIndex);
2529
2530 /* initialize band */
2531 memset(lpBand, 0, sizeof(*lpBand));
2532 lpBand->clrFore = infoPtr->clrText;
2533 lpBand->clrBack = infoPtr->clrBk;
2534 lpBand->iImage = -1;
2535
2536 REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
2537
2538 /* Make sure the defaults for these are correct */
2539 if (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE || !(lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2540 lpBand->cyChild = lpBand->cyMinChild;
2541 lpBand->cyMaxChild = 0x7fffffff;
2542 lpBand->cyIntegral = 0;
2543 }
2544
2545 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2546 if (bUnicode)
2547 Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
2548 else
2549 Str_SetPtrAtoW(&lpBand->lpText, (LPSTR)lprbbi->lpText);
2550 }
2551
2552 REBAR_ValidateBand (infoPtr, lpBand);
2553 /* On insert of second band, revalidate band 1 to possible add gripper */
2554 if (infoPtr->uNumBands == 2)
2555 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2556
2557 REBAR_DumpBand (infoPtr);
2558
2559 REBAR_Layout(infoPtr);
2560 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2561
2562 return TRUE;
2563 }
2564
2565
2566 static LRESULT
2567 REBAR_MaximizeBand (const REBAR_INFO *infoPtr, INT iBand, LPARAM lParam)
2568 {
2569 REBAR_BAND *lpBand;
2570 int iRowBegin, iRowEnd;
2571 int cxDesired, extra, extraOrig;
2572 int cxIdealBand;
2573
2574 /* Validate */
2575 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2576 /* error !!! */
2577 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
2578 iBand, infoPtr->uNumBands);
2579 return FALSE;
2580 }
2581
2582 lpBand = REBAR_GetBand(infoPtr, iBand);
2583
2584 if (lpBand->fStyle & RBBS_HIDDEN)
2585 {
2586 /* Windows is buggy and creates a hole */
2587 WARN("Ignoring maximize request on a hidden band (%d)\n", iBand);
2588 return FALSE;
2589 }
2590
2591 cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
2592 if (lParam && (lpBand->cxEffective < cxIdealBand))
2593 cxDesired = cxIdealBand;
2594 else
2595 cxDesired = infoPtr->calcSize.cx;
2596
2597 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2598 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2599 extraOrig = extra = cxDesired - lpBand->cxEffective;
2600 if (extra > 0)
2601 extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iBand, extra, TRUE);
2602 if (extra > 0)
2603 extra = REBAR_ShrinkBandsLTR(infoPtr, next_visible(infoPtr, iBand), iRowEnd, extra, TRUE);
2604 lpBand->cxEffective += extraOrig - extra;
2605 lpBand->cx = lpBand->cxEffective;
2606 TRACE("(%d, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", iBand, lParam, cxDesired, lpBand->cx, extraOrig, extra);
2607 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2608
2609 if (infoPtr->dwStyle & CCS_VERT)
2610 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2611 else
2612 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2613 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2614 return TRUE;
2615
2616 }
2617
2618
2619 static LRESULT
2620 REBAR_MinimizeBand (const REBAR_INFO *infoPtr, INT iBand)
2621 {
2622 REBAR_BAND *lpBand;
2623 int iPrev, iRowBegin, iRowEnd;
2624
2625 /* A "minimize" band is equivalent to "dragging" the gripper
2626 * of than band to the right till the band is only the size
2627 * of the cxHeader.
2628 */
2629
2630 /* Validate */
2631 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2632 /* error !!! */
2633 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
2634 iBand, infoPtr->uNumBands);
2635 return FALSE;
2636 }
2637
2638 /* compute amount of movement and validate */
2639 lpBand = REBAR_GetBand(infoPtr, iBand);
2640
2641 if (lpBand->fStyle & RBBS_HIDDEN)
2642 {
2643 /* Windows is buggy and creates a hole/overlap */
2644 WARN("Ignoring minimize request on a hidden band (%d)\n", iBand);
2645 return FALSE;
2646 }
2647
2648 iPrev = prev_visible(infoPtr, iBand);
2649 /* if first band in row */
2650 if (iPrev < 0 || REBAR_GetBand(infoPtr, iPrev)->iRow != lpBand->iRow) {
2651 int iNext = next_visible(infoPtr, iBand);
2652 if (iNext < infoPtr->uNumBands && REBAR_GetBand(infoPtr, iNext)->iRow == lpBand->iRow) {
2653 TRACE("(%d): Minimizing the first band in row is by maximizing the second\n", iBand);
2654 REBAR_MaximizeBand(infoPtr, iNext, FALSE);
2655 }
2656 else
2657 TRACE("(%d): Only one band in row - nothing to do\n", iBand);
2658 return TRUE;
2659 }
2660
2661 REBAR_GetBand(infoPtr, iPrev)->cxEffective += lpBand->cxEffective - lpBand->cxMinBand;
2662 REBAR_GetBand(infoPtr, iPrev)->cx = REBAR_GetBand(infoPtr, iPrev)->cxEffective;
2663 lpBand->cx = lpBand->cxEffective = lpBand->cxMinBand;
2664
2665 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2666 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2667 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2668
2669 if (infoPtr->dwStyle & CCS_VERT)
2670 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2671 else
2672 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2673 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2674 return FALSE;
2675 }
2676
2677
2678 static LRESULT
2679 REBAR_MoveBand (REBAR_INFO *infoPtr, INT iFrom, INT iTo)
2680 {
2681 REBAR_BAND *lpBand;
2682
2683 /* Validate */
2684 if ((infoPtr->uNumBands == 0) ||
2685 (iFrom < 0) || iFrom >= infoPtr->uNumBands ||
2686 (iTo < 0) || iTo >= infoPtr->uNumBands) {
2687 /* error !!! */
2688 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
2689 iFrom, iTo, infoPtr->uNumBands);
2690 return FALSE;
2691 }
2692
2693 lpBand = REBAR_GetBand(infoPtr, iFrom);
2694 DPA_DeletePtr(infoPtr->bands, iFrom);
2695 DPA_InsertPtr(infoPtr->bands, iTo, lpBand);
2696
2697 TRACE("moved band %d to index %d\n", iFrom, iTo);
2698 REBAR_DumpBand (infoPtr);
2699
2700 /* **************************************************** */
2701 /* */
2702 /* We do not do a REBAR_Layout here because the native */
2703 /* control does not do that. The actual layout and */
2704 /* repaint is done by the *next* real action, ex.: */
2705 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
2706 /* */
2707 /* **************************************************** */
2708
2709 return TRUE;
2710 }
2711
2712
2713 /* return TRUE if two strings are different */
2714 static BOOL
2715 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
2716 {
2717 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
2718 }
2719
2720 static LRESULT
2721 REBAR_SetBandInfoT(REBAR_INFO *infoPtr, INT iBand, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2722 {
2723 REBAR_BAND *lpBand;
2724 UINT uChanged;
2725
2726 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2727 return FALSE;
2728
2729 if (iBand >= infoPtr->uNumBands)
2730 return FALSE;
2731
2732 TRACE("index %d\n", iBand);
2733 REBAR_DumpBandInfo (lprbbi);
2734
2735 /* set band information */
2736 lpBand = REBAR_GetBand(infoPtr, iBand);
2737
2738 uChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2739 if (lprbbi->fMask & RBBIM_TEXT) {
2740 LPWSTR wstr = NULL;
2741 if (bUnicode)
2742 Str_SetPtrW(&wstr, lprbbi->lpText);
2743 else
2744 Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
2745
2746 if (REBAR_strdifW(wstr, lpBand->lpText)) {
2747 Free(lpBand->lpText);
2748 lpBand->lpText = wstr;
2749 uChanged |= RBBIM_TEXT;
2750 }
2751 else
2752 Free(wstr);
2753 }
2754
2755 REBAR_ValidateBand (infoPtr, lpBand);
2756
2757 REBAR_DumpBand (infoPtr);
2758
2759 if (uChanged & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IMAGE)) {
2760 REBAR_Layout(infoPtr);
2761 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2762 }
2763
2764 return TRUE;
2765 }
2766
2767
2768 static LRESULT
2769 REBAR_SetBarInfo (REBAR_INFO *infoPtr, const REBARINFO *lpInfo)
2770 {
2771 REBAR_BAND *lpBand;
2772 UINT i;
2773
2774 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2775 return FALSE;
2776
2777 TRACE("setting bar info!\n");
2778
2779 if (lpInfo->fMask & RBIM_IMAGELIST) {
2780 infoPtr->himl = lpInfo->himl;
2781 if (infoPtr->himl) {
2782 INT cx, cy;
2783 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
2784 infoPtr->imageSize.cx = cx;
2785 infoPtr->imageSize.cy = cy;
2786 }
2787 else {
2788 infoPtr->imageSize.cx = 0;
2789 infoPtr->imageSize.cy = 0;
2790 }
2791 TRACE("new image cx=%d, cy=%d\n", infoPtr->imageSize.cx,
2792 infoPtr->imageSize.cy);
2793 }
2794
2795 /* revalidate all bands to reset flags for images in headers of bands */
2796 for (i=0; i<infoPtr->uNumBands; i++) {
2797 lpBand = REBAR_GetBand(infoPtr, i);
2798 REBAR_ValidateBand (infoPtr, lpBand);
2799 }
2800
2801 return TRUE;
2802 }
2803
2804
2805 static LRESULT
2806 REBAR_SetBkColor (REBAR_INFO *infoPtr, COLORREF clr)
2807 {
2808 COLORREF clrTemp;
2809
2810 clrTemp = infoPtr->clrBk;
2811 infoPtr->clrBk = clr;
2812
2813 TRACE("background color 0x%06x!\n", infoPtr->clrBk);
2814
2815 return clrTemp;
2816 }
2817
2818
2819 /* << REBAR_SetColorScheme >> */
2820 /* << REBAR_SetPalette >> */
2821
2822
2823 static LRESULT
2824 REBAR_SetParent (REBAR_INFO *infoPtr, HWND parent)
2825 {
2826 HWND hwndTemp = infoPtr->hwndNotify;
2827
2828 infoPtr->hwndNotify = parent;
2829
2830 return (LRESULT)hwndTemp;
2831 }
2832
2833
2834 static LRESULT
2835 REBAR_SetTextColor (REBAR_INFO *infoPtr, COLORREF clr)
2836 {
2837 COLORREF clrTemp;
2838
2839 clrTemp = infoPtr->clrText;
2840 infoPtr->clrText = clr;
2841
2842 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2843
2844 return clrTemp;
2845 }
2846
2847
2848 /* << REBAR_SetTooltips >> */
2849
2850
2851 static inline LRESULT
2852 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, BOOL unicode)
2853 {
2854 BOOL bTemp = infoPtr->bUnicode;
2855
2856 TRACE("to %s hwnd=%p, was %s\n",
2857 unicode ? "TRUE" : "FALSE", infoPtr->hwndSelf,
2858 (bTemp) ? "TRUE" : "FALSE");
2859
2860 infoPtr->bUnicode = unicode;
2861
2862 return bTemp;
2863 }
2864
2865
2866 static LRESULT
2867 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
2868 {
2869 INT iOldVersion = infoPtr->iVersion;
2870
2871 if (iVersion > COMCTL32_VERSION)
2872 return -1;
2873
2874 infoPtr->iVersion = iVersion;
2875
2876 TRACE("new version %d\n", iVersion);
2877
2878 return iOldVersion;
2879 }
2880
2881
2882 static LRESULT
2883 REBAR_ShowBand (REBAR_INFO *infoPtr, INT iBand, BOOL show)
2884 {
2885 REBAR_BAND *lpBand;
2886
2887 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2888 return FALSE;
2889
2890 lpBand = REBAR_GetBand(infoPtr, iBand);
2891
2892 if (show) {
2893 TRACE("show band %d\n", iBand);
2894 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
2895 if (IsWindow (lpBand->hwndChild))
2896 ShowWindow (lpBand->hwndChild, SW_SHOW);
2897 }
2898 else {
2899 TRACE("hide band %d\n", iBand);
2900 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
2901 if (IsWindow (lpBand->hwndChild))
2902 ShowWindow (lpBand->hwndChild, SW_HIDE);
2903 }
2904
2905 REBAR_Layout(infoPtr);
2906 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2907
2908 return TRUE;
2909 }
2910
2911
2912 static LRESULT
2913 REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM flags, RECT *lpRect)
2914 {
2915 if (!lpRect) return FALSE;
2916
2917 TRACE("[%s]\n", wine_dbgstr_rect(lpRect));
2918 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, lpRect));
2919
2920 /* Note that this undocumented flag is available on comctl32 v6 or later */
2921 if ((flags & RBSTR_CHANGERECT) != 0)
2922 {
2923 RECT rcRebar;
2924 GetClientRect(infoPtr->hwndSelf, &rcRebar);
2925 lpRect->bottom = lpRect->top + (rcRebar.bottom - rcRebar.top);
2926 }
2927 return TRUE;
2928 }
2929
2930
2931
2932 static LRESULT
2933 REBAR_Create (REBAR_INFO *infoPtr, LPCREATESTRUCTW cs)
2934 {
2935 RECT wnrc1, clrc1;
2936
2937 if (TRACE_ON(rebar)) {
2938 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
2939 GetClientRect(infoPtr->hwndSelf, &clrc1);
2940 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
2941 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
2942 cs->x, cs->y, cs->cx, cs->cy);
2943 }
2944
2945 TRACE("created!\n");
2946
2947 if (OpenThemeData (infoPtr->hwndSelf, themeClass))
2948 {
2949 /* native seems to clear WS_BORDER when themed */
2950 infoPtr->dwStyle &= ~WS_BORDER;
2951 }
2952
2953 return 0;
2954 }
2955
2956
2957 static LRESULT
2958 REBAR_Destroy (REBAR_INFO *infoPtr)
2959 {
2960 REBAR_BAND *lpBand;
2961 UINT i;
2962
2963 /* clean up each band */
2964 for (i = 0; i < infoPtr->uNumBands; i++) {
2965 lpBand = REBAR_GetBand(infoPtr, i);
2966
2967 /* delete text strings */
2968 Free (lpBand->lpText);
2969 lpBand->lpText = NULL;
2970 /* destroy child window */
2971 DestroyWindow (lpBand->hwndChild);
2972 Free (lpBand);
2973 }
2974
2975 /* free band array */
2976 DPA_Destroy (infoPtr->bands);
2977 infoPtr->bands = NULL;
2978
2979 DestroyCursor (infoPtr->hcurArrow);
2980 DestroyCursor (infoPtr->hcurHorz);
2981 DestroyCursor (infoPtr->hcurVert);
2982 DestroyCursor (infoPtr->hcurDrag);
2983 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
2984 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
2985
2986 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2987
2988 /* free rebar info data */
2989 Free (infoPtr);
2990 TRACE("destroyed!\n");
2991 return 0;
2992 }
2993
2994 static LRESULT
2995 REBAR_GetFont (const REBAR_INFO *infoPtr)
2996 {
2997 return (LRESULT)infoPtr->hFont;
2998 }
2999
3000 static LRESULT
3001 REBAR_PushChevron(const REBAR_INFO *infoPtr, UINT uBand, LPARAM lParam)
3002 {
3003 if (uBand < infoPtr->uNumBands)
3004 {
3005 NMREBARCHEVRON nmrbc;
3006 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
3007
3008 TRACE("Pressed chevron on band %u\n", uBand);
3009
3010 /* redraw chevron in pushed state */
3011 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
3012 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
3013 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3014
3015 /* notify app so it can display a popup menu or whatever */
3016 nmrbc.uBand = uBand;
3017 nmrbc.wID = lpBand->wID;
3018 nmrbc.lParam = lpBand->lParam;
3019 nmrbc.rc = lpBand->rcChevron;
3020 nmrbc.lParamNM = lParam;
3021 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3022
3023 /* redraw chevron in previous state */
3024 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3025 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3026
3027 return TRUE;
3028 }
3029 return FALSE;
3030 }
3031
3032 static LRESULT
3033 REBAR_LButtonDown (REBAR_INFO *infoPtr, LPARAM lParam)
3034 {
3035 UINT htFlags;
3036 INT iHitBand;
3037 POINT ptMouseDown;
3038 ptMouseDown.x = (short)LOWORD(lParam);
3039 ptMouseDown.y = (short)HIWORD(lParam);
3040
3041 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3042
3043 if (htFlags == RBHT_CHEVRON)
3044 {
3045 REBAR_PushChevron(infoPtr, iHitBand, 0);
3046 }
3047 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3048 {
3049 REBAR_BAND *lpBand;
3050
3051 TRACE("Starting drag\n");
3052
3053 lpBand = REBAR_GetBand(infoPtr, iHitBand);
3054
3055 SetCapture (infoPtr->hwndSelf);
3056 infoPtr->iGrabbedBand = iHitBand;
3057
3058 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3059 infoPtr->dragStart.x = (short)LOWORD(lParam);
3060 infoPtr->dragStart.y = (short)HIWORD(lParam);
3061 infoPtr->dragNow = infoPtr->dragStart;
3062 if (infoPtr->dwStyle & CCS_VERT)
3063 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3064 else
3065 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3066 }
3067 return 0;
3068 }
3069
3070 static LRESULT
3071 REBAR_LButtonUp (REBAR_INFO *infoPtr)
3072 {
3073 if (infoPtr->iGrabbedBand >= 0)
3074 {
3075 NMHDR layout;
3076 RECT rect;
3077
3078 infoPtr->dragStart.x = 0;
3079 infoPtr->dragStart.y = 0;
3080 infoPtr->dragNow = infoPtr->dragStart;
3081
3082 ReleaseCapture ();
3083
3084 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3085 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3086 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3087 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3088 }
3089
3090 infoPtr->iGrabbedBand = -1;
3091
3092 GetClientRect(infoPtr->hwndSelf, &rect);
3093 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3094 }
3095
3096 return 0;
3097 }
3098
3099 static LRESULT
3100 REBAR_MouseLeave (REBAR_INFO *infoPtr)
3101 {
3102 if (infoPtr->ichevronhotBand >= 0)
3103 {
3104 REBAR_BAND *lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3105 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3106 {
3107 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3108 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3109 }
3110 }
3111 infoPtr->iOldBand = -1;
3112 infoPtr->ichevronhotBand = -2;
3113
3114 return TRUE;
3115 }
3116
3117 static LRESULT
3118 REBAR_MouseMove (REBAR_INFO *infoPtr, LPARAM lParam)
3119 {
3120 REBAR_BAND *lpChevronBand;
3121 POINT ptMove;
3122
3123 ptMove.x = (short)LOWORD(lParam);
3124 ptMove.y = (short)HIWORD(lParam);
3125
3126 /* if we are currently dragging a band */
3127 if (infoPtr->iGrabbedBand >= 0)
3128 {
3129 REBAR_BAND *band;
3130 int yPtMove = (infoPtr->dwStyle & CCS_VERT ? ptMove.x : ptMove.y);
3131
3132 if (GetCapture() != infoPtr->hwndSelf)
3133 ERR("We are dragging but haven't got capture?!?\n");
3134
3135 band = REBAR_GetBand(infoPtr, infoPtr->iGrabbedBand);
3136
3137 /* if mouse did not move much, exit */
3138 if ((abs(ptMove.x - infoPtr->dragNow.x) <= mindragx) &&
3139 (abs(ptMove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3140
3141 /* on first significant mouse movement, issue notify */
3142 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
3143 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
3144 /* Notify returned TRUE - abort drag */
3145 infoPtr->dragStart.x = 0;
3146 infoPtr->dragStart.y = 0;
3147 infoPtr->dragNow = infoPtr->dragStart;
3148 infoPtr->iGrabbedBand = -1;
3149 ReleaseCapture ();
3150 return 0;
3151 }
3152 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
3153 }
3154
3155 /* Test for valid drag case - must not be first band in row */
3156 if ((yPtMove < band->rcBand.top) ||
3157 (yPtMove > band->rcBand.bottom)) {
3158 REBAR_HandleUDDrag (infoPtr, &ptMove);
3159 }
3160 else {
3161 REBAR_HandleLRDrag (infoPtr, &ptMove);
3162 }
3163 }
3164 else
3165 {
3166 INT iHitBand;
3167 UINT htFlags;
3168 TRACKMOUSEEVENT trackinfo;
3169
3170 REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
3171
3172 if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
3173 {
3174 lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3175 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3176 {
3177 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3178 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3179 }
3180 infoPtr->ichevronhotBand = -2;
3181 }
3182
3183 if (htFlags == RBHT_CHEVRON)
3184 {
3185 /* fill in the TRACKMOUSEEVENT struct */
3186 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
3187 trackinfo.dwFlags = TME_QUERY;
3188 trackinfo.hwndTrack = infoPtr->hwndSelf;
3189 trackinfo.dwHoverTime = 0;
3190
3191 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
3192 _TrackMouseEvent(&trackinfo);
3193
3194 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
3195 if(!(trackinfo.dwFlags & TME_LEAVE))
3196 {
3197 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
3198
3199 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
3200 /* and can properly deactivate the hot chevron */
3201 _TrackMouseEvent(&trackinfo);
3202 }
3203
3204 lpChevronBand = REBAR_GetBand(infoPtr, iHitBand);
3205 if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
3206 {
3207 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
3208 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3209 infoPtr->ichevronhotBand = iHitBand;
3210 }
3211 }
3212 infoPtr->iOldBand = iHitBand;
3213 }
3214
3215 return 0;
3216 }
3217
3218
3219 static inline LRESULT
3220 REBAR_NCCalcSize (const REBAR_INFO *infoPtr, RECT *rect)
3221 {
3222 HTHEME theme;
3223
3224 if (infoPtr->dwStyle & WS_BORDER) {
3225 rect->left = min(rect->left + GetSystemMetrics(SM_CXEDGE), rect->right);
3226 rect->right = max(rect->right - GetSystemMetrics(SM_CXEDGE), rect->left);
3227 rect->top = min(rect->top + GetSystemMetrics(SM_CYEDGE), rect->bottom);
3228 rect->bottom = max(rect->bottom - GetSystemMetrics(SM_CYEDGE), rect->top);
3229 }
3230 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3231 {
3232 /* FIXME: should use GetThemeInt */
3233 rect->top = min(rect->top + 1, rect->bottom);
3234 }
3235 TRACE("new client=(%s)\n", wine_dbgstr_rect(rect));
3236 return 0;
3237 }
3238
3239
3240 static LRESULT
3241 REBAR_NCCreate (HWND hwnd, const CREATESTRUCTW *cs)
3242 {
3243 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3244 RECT wnrc1, clrc1;
3245 NONCLIENTMETRICSW ncm;
3246 HFONT tfont;
3247
3248 if (infoPtr) {
3249 ERR("Strange info structure pointer *not* NULL\n");
3250 return FALSE;
3251 }
3252
3253 if (TRACE_ON(rebar)) {
3254 GetWindowRect(hwnd, &wnrc1);
3255 GetClientRect(hwnd, &clrc1);
3256 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
3257 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
3258 cs->x, cs->y, cs->cx, cs->cy);
3259 }
3260
3261 /* allocate memory for info structure */
3262 infoPtr = Alloc (sizeof(REBAR_INFO));
3263 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
3264
3265 /* initialize info structure - initial values are 0 */
3266 infoPtr->clrBk = CLR_NONE;
3267 infoPtr->clrText = CLR_NONE;
3268 infoPtr->clrBtnText = comctl32_color.clrBtnText;
3269 infoPtr->clrBtnFace = comctl32_color.clrBtnFace;
3270 infoPtr->iOldBand = -1;
3271 infoPtr->ichevronhotBand = -2;
3272 infoPtr->iGrabbedBand = -1;
3273 infoPtr->hwndSelf = hwnd;
3274 infoPtr->DoRedraw = TRUE;
3275 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3276 infoPtr->hcurHorz = LoadCursorW (0, (LPWSTR)IDC_SIZEWE);
3277 infoPtr->hcurVert = LoadCursorW (0, (LPWSTR)IDC_SIZENS);
3278 infoPtr->hcurDrag = LoadCursorW (0, (LPWSTR)IDC_SIZE);
3279 infoPtr->fStatus = 0;
3280 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3281 infoPtr->bands = DPA_Create(8);
3282
3283 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3284 REBAR_NotifyFormat(infoPtr, NF_REQUERY);
3285
3286 /* Stow away the original style */
3287 infoPtr->orgStyle = cs->style;
3288 /* add necessary styles to the requested styles */
3289 infoPtr->dwStyle = cs->style | WS_VISIBLE;
3290 if ((infoPtr->dwStyle & CCS_LAYOUT_MASK) == 0)
3291 infoPtr->dwStyle |= CCS_TOP;
3292 SetWindowLongW (hwnd, GWL_STYLE, infoPtr->dwStyle);
3293
3294 /* get font handle for Caption Font */
3295 ncm.cbSize = sizeof(ncm);
3296 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
3297 /* if the font is bold, set to normal */
3298 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3299 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3300 }
3301 tfont = CreateFontIndirectW (&ncm.lfCaptionFont);
3302 if (tfont) {
3303 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3304 }
3305
3306 return TRUE;
3307 }
3308
3309
3310 static LRESULT
3311 REBAR_NCHitTest (const REBAR_INFO *infoPtr, LPARAM lParam)
3312 {
3313 NMMOUSE nmmouse;
3314 POINT clpt;
3315 INT i;
3316 UINT scrap;
3317 LRESULT ret = HTCLIENT;
3318
3319 /*
3320 * Differences from doc at MSDN (as observed with version 4.71 of
3321 * comctl32.dll
3322 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3323 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3324 * 3. native always seems to return HTCLIENT if notify return is 0.
3325 */
3326
3327 clpt.x = (short)LOWORD(lParam);
3328 clpt.y = (short)HIWORD(lParam);
3329 ScreenToClient (infoPtr->hwndSelf, &clpt);
3330 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3331 (INT *)&nmmouse.dwItemSpec);
3332 nmmouse.dwItemData = 0;
3333 nmmouse.pt = clpt;
3334 nmmouse.dwHitInfo = 0;
3335 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3336 TRACE("notify changed return value from %ld to %d\n",
3337 ret, i);
3338 ret = (LRESULT) i;
3339 }
3340 TRACE("returning %ld, client point (%d,%d)\n", ret, clpt.x, clpt.y);
3341 return ret;
3342 }
3343
3344
3345 static LRESULT
3346 REBAR_NCPaint (const REBAR_INFO *infoPtr)
3347 {
3348 RECT rcWindow;
3349 HDC hdc;
3350 HTHEME theme;
3351
3352 if (infoPtr->dwStyle & WS_MINIMIZE)
3353 return 0; /* Nothing to do */
3354
3355 if (infoPtr->dwStyle & WS_BORDER) {
3356
3357 /* adjust rectangle and draw the necessary edge */
3358 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3359 return 0;
3360 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3361 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3362 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3363 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3364 ReleaseDC( infoPtr->hwndSelf, hdc );
3365 }
3366 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3367 {
3368 /* adjust rectangle and draw the necessary edge */
3369 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3370 return 0;
3371 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3372 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3373 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3374 DrawThemeEdge (theme, hdc, 0, 0, &rcWindow, BDR_RAISEDINNER, BF_TOP, NULL);
3375 ReleaseDC( infoPtr->hwndSelf, hdc );
3376 }
3377
3378 return 0;
3379 }
3380
3381
3382 static LRESULT
3383 REBAR_NotifyFormat (REBAR_INFO *infoPtr, LPARAM cmd)
3384 {
3385 INT i;
3386
3387 if (cmd == NF_REQUERY) {
3388 i = SendMessageW(REBAR_GetNotifyParent (infoPtr),
3389 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
3390 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
3391 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
3392 i = NFR_ANSI;
3393 }
3394 infoPtr->bUnicode = (i == NFR_UNICODE) ? 1 : 0;
3395 return (LRESULT)i;
3396 }
3397 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3398 }
3399
3400
3401 static LRESULT
3402 REBAR_Paint (const REBAR_INFO *infoPtr, HDC hdc)
3403 {
3404 if (hdc) {
3405 TRACE("painting\n");
3406 REBAR_Refresh (infoPtr, hdc);
3407 } else {
3408 PAINTSTRUCT ps;
3409 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
3410 TRACE("painting (%s)\n", wine_dbgstr_rect(&ps.rcPaint));
3411 if (ps.fErase) {
3412 /* Erase area of paint if requested */
3413 REBAR_EraseBkGnd (infoPtr, hdc);
3414 }
3415 REBAR_Refresh (infoPtr, hdc);
3416 EndPaint (infoPtr->hwndSelf, &ps);
3417 }
3418
3419 return 0;
3420 }
3421
3422
3423 static LRESULT
3424 REBAR_SetCursor (const REBAR_INFO *infoPtr, LPARAM lParam)
3425 {
3426 POINT pt;
3427 UINT flags;
3428
3429 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
3430
3431 GetCursorPos (&pt);
3432 ScreenToClient (infoPtr->hwndSelf, &pt);
3433
3434 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
3435
3436 if (flags == RBHT_GRABBER) {
3437 if ((infoPtr->dwStyle & CCS_VERT) &&
3438 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
3439 SetCursor (infoPtr->hcurVert);
3440 else
3441 SetCursor (infoPtr->hcurHorz);
3442 }
3443 else if (flags != RBHT_CLIENT)
3444 SetCursor (infoPtr->hcurArrow);
3445
3446 return 0;
3447 }
3448
3449
3450 static LRESULT
3451 REBAR_SetFont (REBAR_INFO *infoPtr, HFONT font)
3452 {
3453 REBAR_BAND *lpBand;
3454 UINT i;
3455
3456 infoPtr->hFont = font;
3457
3458 /* revalidate all bands to change sizes of text in headers of bands */
3459 for (i=0; i<infoPtr->uNumBands; i++) {
3460 lpBand = REBAR_GetBand(infoPtr, i);
3461 REBAR_ValidateBand (infoPtr, lpBand);
3462 }
3463
3464 REBAR_Layout(infoPtr);
3465 return 0;
3466 }
3467
3468
3469 /*****************************************************
3470 *
3471 * Handles the WM_SETREDRAW message.
3472 *
3473 * Documentation:
3474 * According to testing V4.71 of COMCTL32 returns the
3475 * *previous* status of the redraw flag (either 0 or -1)
3476 * instead of the MSDN documented value of 0 if handled
3477 *
3478 *****************************************************/
3479 static inline LRESULT
3480 REBAR_SetRedraw (REBAR_INFO *infoPtr, BOOL redraw)
3481 {
3482 BOOL oldredraw = infoPtr->DoRedraw;
3483
3484 TRACE("set to %s, fStatus=%08x\n",
3485 (redraw) ? "TRUE" : "FALSE", infoPtr->fStatus);
3486 infoPtr->DoRedraw = redraw;
3487 if (redraw) {
3488 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
3489 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
3490 REBAR_ForceResize (infoPtr);
3491 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3492 }
3493 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
3494 }
3495 return (oldredraw) ? -1 : 0;
3496 }
3497
3498
3499 static LRESULT
3500 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3501 {
3502 TRACE("wParam=%lx, lParam=%lx\n", wParam, lParam);
3503
3504 /* avoid _Layout resize recursion (but it shouldn't be infinite and it seems Windows does recurse) */
3505 if (infoPtr->fStatus & SELF_RESIZE) {
3506 infoPtr->fStatus &= ~SELF_RESIZE;
3507 TRACE("SELF_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
3508 infoPtr->fStatus, lParam);
3509 return 0;
3510 }
3511
3512 if (infoPtr->dwStyle & RBS_AUTOSIZE)
3513 REBAR_AutoSize(infoPtr, TRUE);
3514 else
3515 REBAR_Layout(infoPtr);
3516
3517 return 0;
3518 }
3519
3520
3521 static LRESULT
3522 REBAR_StyleChanged (REBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
3523 {
3524 TRACE("current style=%08x, styleOld=%08x, style being set to=%08x\n",
3525 infoPtr->dwStyle, lpStyle->styleOld, lpStyle->styleNew);
3526 if (nType == GWL_STYLE)
3527 {
3528 infoPtr->orgStyle = infoPtr->dwStyle = lpStyle->styleNew;
3529 if (GetWindowTheme (infoPtr->hwndSelf))
3530 infoPtr->dwStyle &= ~WS_BORDER;
3531 /* maybe it should be COMMON_STYLES like in toolbar */
3532 if ((lpStyle->styleNew ^ lpStyle->styleOld) & CCS_VERT)
3533 REBAR_Layout(infoPtr);
3534 }
3535 return FALSE;
3536 }
3537
3538 /* update theme after a WM_THEMECHANGED message */
3539 static LRESULT theme_changed (REBAR_INFO* infoPtr)
3540 {
3541 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
3542 CloseThemeData (theme);
3543 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
3544 /* WS_BORDER disappears when theming is enabled and reappears when
3545 * disabled... */
3546 infoPtr->dwStyle &= ~WS_BORDER;
3547 infoPtr->dwStyle |= theme ? 0 : (infoPtr->orgStyle & WS_BORDER);
3548 return 0;
3549 }
3550
3551 static LRESULT
3552 REBAR_WindowPosChanged (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3553 {
3554 LRESULT ret;
3555 RECT rc;
3556
3557 ret = DefWindowProcW(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
3558 wParam, lParam);
3559 GetWindowRect(infoPtr->hwndSelf, &rc);
3560 TRACE("hwnd %p new pos (%s)\n", infoPtr->hwndSelf, wine_dbgstr_rect(&rc));
3561 return ret;
3562 }
3563
3564
3565 static LRESULT WINAPI
3566 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3567 {
3568 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3569
3570 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
3571 hwnd, uMsg, wParam, lParam);
3572 if (!infoPtr && (uMsg != WM_NCCREATE))
3573 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3574 switch (uMsg)
3575 {
3576 /* case RB_BEGINDRAG: */
3577
3578 case RB_DELETEBAND:
3579 return REBAR_DeleteBand (infoPtr, wParam);
3580
3581 /* case RB_DRAGMOVE: */
3582 /* case RB_ENDDRAG: */
3583
3584 case RB_GETBANDBORDERS:
3585 return REBAR_GetBandBorders (infoPtr, wParam, (LPRECT)lParam);
3586
3587 case RB_GETBANDCOUNT:
3588 return REBAR_GetBandCount (infoPtr);
3589
3590 case RB_GETBANDINFO_OLD:
3591 case RB_GETBANDINFOA:
3592 case RB_GETBANDINFOW:
3593 return REBAR_GetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3594 uMsg == RB_GETBANDINFOW);
3595 case RB_GETBARHEIGHT:
3596 return REBAR_GetBarHeight (infoPtr);
3597
3598 case RB_GETBARINFO:
3599 return REBAR_GetBarInfo (infoPtr, (LPREBARINFO)lParam);
3600
3601 case RB_GETBKCOLOR:
3602 return REBAR_GetBkColor (infoPtr);
3603
3604 /* case RB_GETCOLORSCHEME: */
3605 /* case RB_GETDROPTARGET: */
3606
3607 case RB_GETPALETTE:
3608 return REBAR_GetPalette (infoPtr);
3609
3610 case RB_GETRECT:
3611 return REBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
3612
3613 case RB_GETROWCOUNT:
3614 return REBAR_GetRowCount (infoPtr);
3615
3616 case RB_GETROWHEIGHT:
3617 return REBAR_GetRowHeight (infoPtr, wParam);
3618
3619 case RB_GETTEXTCOLOR:
3620 return REBAR_GetTextColor (infoPtr);
3621
3622 case RB_GETTOOLTIPS:
3623 return REBAR_GetToolTips (infoPtr);
3624
3625 case RB_GETUNICODEFORMAT:
3626 return REBAR_GetUnicodeFormat (infoPtr);
3627
3628 case CCM_GETVERSION:
3629 return REBAR_GetVersion (infoPtr);
3630
3631 case RB_HITTEST:
3632 return REBAR_HitTest (infoPtr, (LPRBHITTESTINFO)lParam);
3633
3634 case RB_IDTOINDEX:
3635 return REBAR_IdToIndex (infoPtr, wParam);
3636
3637 case RB_INSERTBANDA:
3638 case RB_INSERTBANDW:
3639 return REBAR_InsertBandT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3640 uMsg == RB_INSERTBANDW);
3641 case RB_MAXIMIZEBAND:
3642 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
3643
3644 case RB_MINIMIZEBAND:
3645 return REBAR_MinimizeBand (infoPtr, wParam);
3646
3647 case RB_MOVEBAND:
3648 return REBAR_MoveBand (infoPtr, wParam, lParam);
3649
3650 case RB_PUSHCHEVRON:
3651 return REBAR_PushChevron (infoPtr, wParam, lParam);
3652
3653 case RB_SETBANDINFOA:
3654 case RB_SETBANDINFOW:
3655 return REBAR_SetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3656 uMsg == RB_SETBANDINFOW);
3657 case RB_SETBARINFO:
3658 return REBAR_SetBarInfo (infoPtr, (LPREBARINFO)lParam);
3659
3660 case RB_SETBKCOLOR:
3661 return REBAR_SetBkColor (infoPtr, lParam);
3662
3663 /* case RB_SETCOLORSCHEME: */
3664 /* case RB_SETPALETTE: */
3665
3666 case RB_SETPARENT:
3667 return REBAR_SetParent (infoPtr, (HWND)wParam);
3668
3669 case RB_SETTEXTCOLOR:
3670 return REBAR_SetTextColor (infoPtr, lParam);
3671
3672 /* case RB_SETTOOLTIPS: */
3673
3674 case RB_SETUNICODEFORMAT:
3675 return REBAR_SetUnicodeFormat (infoPtr, wParam);
3676
3677 case CCM_SETVERSION:
3678 return REBAR_SetVersion (infoPtr, (INT)wParam);
3679
3680 case RB_SHOWBAND:
3681 return REBAR_ShowBand (infoPtr, wParam, lParam);
3682
3683 case RB_SIZETORECT:
3684 return REBAR_SizeToRect (infoPtr, wParam, (LPRECT)lParam);
3685
3686
3687 /* Messages passed to parent */
3688 case WM_COMMAND:
3689 case WM_DRAWITEM:
3690 case WM_NOTIFY:
3691 case WM_MEASUREITEM:
3692 return SendMessageW(REBAR_GetNotifyParent (infoPtr), uMsg, wParam, lParam);
3693
3694
3695 /* case WM_CHARTOITEM: supported according to ControlSpy */
3696
3697 case WM_CREATE:
3698 return REBAR_Create (infoPtr, (LPCREATESTRUCTW)lParam);
3699
3700 case WM_DESTROY:
3701 return REBAR_Destroy (infoPtr);
3702
3703 case WM_ERASEBKGND:
3704 return REBAR_EraseBkGnd (infoPtr, (HDC)wParam);
3705
3706 case WM_GETFONT:
3707 return REBAR_GetFont (infoPtr);
3708
3709 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
3710
3711 case WM_LBUTTONDOWN:
3712 return REBAR_LButtonDown (infoPtr, lParam);
3713
3714 case WM_LBUTTONUP:
3715 return REBAR_LButtonUp (infoPtr);
3716
3717 case WM_MOUSEMOVE:
3718 return REBAR_MouseMove (infoPtr, lParam);
3719
3720 case WM_MOUSELEAVE:
3721 return REBAR_MouseLeave (infoPtr);
3722
3723 case WM_NCCALCSIZE:
3724 return REBAR_NCCalcSize (infoPtr, (RECT*)lParam);
3725
3726 case WM_NCCREATE:
3727 return REBAR_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
3728
3729 case WM_NCHITTEST:
3730 return REBAR_NCHitTest (infoPtr, lParam);
3731
3732 case WM_NCPAINT:
3733 return REBAR_NCPaint (infoPtr);
3734
3735 case WM_NOTIFYFORMAT:
3736 return REBAR_NotifyFormat (infoPtr, lParam);
3737
3738 case WM_PRINTCLIENT:
3739 case WM_PAINT:
3740 return REBAR_Paint (infoPtr, (HDC)wParam);
3741
3742 /* case WM_PALETTECHANGED: supported according to ControlSpy */
3743 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
3744 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
3745 /* case WM_RBUTTONUP: supported according to ControlSpy */
3746
3747 case WM_SETCURSOR:
3748 return REBAR_SetCursor (infoPtr, lParam);
3749
3750 case WM_SETFONT:
3751 return REBAR_SetFont (infoPtr, (HFONT)wParam);
3752
3753 case WM_SETREDRAW:
3754 return REBAR_SetRedraw (infoPtr, wParam);
3755
3756 case WM_SIZE:
3757 return REBAR_Size (infoPtr, wParam, lParam);
3758
3759 case WM_STYLECHANGED:
3760 return REBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
3761
3762 case WM_THEMECHANGED:
3763 return theme_changed (infoPtr);
3764
3765 case WM_SYSCOLORCHANGE:
3766 COMCTL32_RefreshSysColors();
3767 infoPtr->clrBtnText = comctl32_color.clrBtnText;
3768 infoPtr->clrBtnFace = comctl32_color.clrBtnFace;
3769 return 0;
3770
3771 /* case WM_VKEYTOITEM: supported according to ControlSpy */
3772 /* case WM_WININICHANGE: */
3773
3774 case WM_WINDOWPOSCHANGED:
3775 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
3776
3777 default:
3778 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
3779 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
3780 uMsg, wParam, lParam);
3781 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3782 }
3783 }
3784
3785
3786 VOID
3787 REBAR_Register (void)
3788 {
3789 WNDCLASSW wndClass;
3790
3791 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
3792 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
3793 wndClass.lpfnWndProc = REBAR_WindowProc;
3794 wndClass.cbClsExtra = 0;
3795 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
3796 wndClass.hCursor = 0;
3797 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
3798 #if GLATESTING
3799 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
3800 #endif
3801 wndClass.lpszClassName = REBARCLASSNAMEW;
3802
3803 RegisterClassW (&wndClass);
3804
3805 mindragx = GetSystemMetrics (SM_CXDRAG);
3806 mindragy = GetSystemMetrics (SM_CYDRAG);
3807
3808 }
3809
3810
3811 VOID
3812 REBAR_Unregister (void)
3813 {
3814 UnregisterClassW (REBARCLASSNAMEW, NULL);
3815 }