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