KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > widgets > CoolBar


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.widgets;
12
13
14 import org.eclipse.swt.internal.win32.*;
15 import org.eclipse.swt.*;
16 import org.eclipse.swt.graphics.*;
17
18 /**
19  * Instances of this class provide an area for dynamically
20  * positioning the items they contain.
21  * <p>
22  * The item children that may be added to instances of this class
23  * must be of type <code>CoolItem</code>.
24  * </p><p>
25  * Note that although this class is a subclass of <code>Composite</code>,
26  * it does not make sense to add <code>Control</code> children to it,
27  * or set a layout on it.
28  * </p><p>
29  * <dl>
30  * <dt><b>Styles:</b></dt>
31  * <dd>FLAT, HORIZONTAL, VERTICAL</dd>
32  * <dt><b>Events:</b></dt>
33  * <dd>(none)</dd>
34  * </dl>
35  * </p><p>
36  * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
37  * </p><p>
38  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
39  * </p>
40  */

41
42 public class CoolBar extends Composite {
43     CoolItem [] items;
44     CoolItem [] originalItems;
45     boolean locked;
46     boolean ignoreResize;
47     static final int ReBarProc;
48     static final TCHAR ReBarClass = new TCHAR (0, OS.REBARCLASSNAME, true);
49     static {
50         INITCOMMONCONTROLSEX icex = new INITCOMMONCONTROLSEX ();
51         icex.dwSize = INITCOMMONCONTROLSEX.sizeof;
52         icex.dwICC = OS.ICC_COOL_CLASSES;
53         OS.InitCommonControlsEx (icex);
54         WNDCLASS lpWndClass = new WNDCLASS ();
55         OS.GetClassInfo (0, ReBarClass, lpWndClass);
56         ReBarProc = lpWndClass.lpfnWndProc;
57     }
58     static final int SEPARATOR_WIDTH = 2;
59     static final int MAX_WIDTH = 0x7FFF;
60     static final int DEFAULT_COOLBAR_WIDTH = 0;
61     static final int DEFAULT_COOLBAR_HEIGHT = 0;
62
63 /**
64  * Constructs a new instance of this class given its parent
65  * and a style value describing its behavior and appearance.
66  * <p>
67  * The style value is either one of the style constants defined in
68  * class <code>SWT</code> which is applicable to instances of this
69  * class, or must be built by <em>bitwise OR</em>'ing together
70  * (that is, using the <code>int</code> "|" operator) two or more
71  * of those <code>SWT</code> style constants. The class description
72  * lists the style constants that are applicable to the class.
73  * Style bits are also inherited from superclasses.
74  * </p>
75  *
76  * @param parent a composite control which will be the parent of the new instance (cannot be null)
77  * @param style the style of control to construct
78  *
79  * @exception IllegalArgumentException <ul>
80  * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
81  * </ul>
82  * @exception SWTException <ul>
83  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
84  * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
85  * </ul>
86  *
87  * @see SWT
88  * @see Widget#checkSubclass
89  * @see Widget#getStyle
90  */

91 public CoolBar (Composite parent, int style) {
92     super (parent, checkStyle (style));
93     /*
94     * Ensure that either of HORIZONTAL or VERTICAL is set.
95     * NOTE: HORIZONTAL and VERTICAL have the same values
96     * as H_SCROLL and V_SCROLL so it is necessary to first
97     * clear these bits to avoid scroll bars and then reset
98     * the bits using the original style supplied by the
99     * programmer.
100     *
101     * NOTE: The CCS_VERT style cannot be applied when the
102     * widget is created because of this conflict.
103     */

104     if ((style & SWT.VERTICAL) != 0) {
105         this.style |= SWT.VERTICAL;
106         int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
107         OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.CCS_VERT);
108     } else {
109         this.style |= SWT.HORIZONTAL;
110     }
111 }
112
113 int callWindowProc (int hwnd, int msg, int wParam, int lParam) {
114     if (handle == 0) return 0;
115     return OS.CallWindowProc (ReBarProc, hwnd, msg, wParam, lParam);
116 }
117
118 static int checkStyle (int style) {
119     style |= SWT.NO_FOCUS;
120     /*
121     * Even though it is legal to create this widget
122     * with scroll bars, they serve no useful purpose
123     * because they do not automatically scroll the
124     * widget's client area. The fix is to clear
125     * the SWT style.
126     */

127     return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
128 }
129
130 protected void checkSubclass () {
131     if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
132 }
133
134 public Point computeSize (int wHint, int hHint, boolean changed) {
135     checkWidget ();
136     int width = 0, height = 0;
137     int border = getBorderWidth ();
138     int newWidth = wHint == SWT.DEFAULT ? 0x3FFF : wHint + (border * 2);
139     int newHeight = hHint == SWT.DEFAULT ? 0x3FFF : hHint + (border * 2);
140     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
141     if (count != 0) {
142         ignoreResize = true;
143         boolean redraw = false;
144         if (OS.IsWindowVisible (handle)) {
145             if (OS.COMCTL32_MAJOR >= 6) {
146                 redraw = true;
147                 OS.UpdateWindow (handle);
148                 OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
149             } else {
150                 redraw = drawCount == 0;
151                 if (redraw) {
152                     OS.UpdateWindow (handle);
153                     OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
154                 }
155             }
156         }
157         RECT oldRect = new RECT ();
158         OS.GetWindowRect (handle, oldRect);
159         int oldWidth = oldRect.right - oldRect.left;
160         int oldHeight = oldRect.bottom - oldRect.top;
161         int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOREDRAW | OS.SWP_NOZORDER;
162         SetWindowPos (handle, 0, 0, 0, newWidth, newHeight, flags);
163         RECT rect = new RECT ();
164         OS.SendMessage (handle, OS.RB_GETRECT, count - 1, rect);
165         height = Math.max (height, rect.bottom);
166         SetWindowPos (handle, 0, 0, 0, oldWidth, oldHeight, flags);
167         REBARBANDINFO rbBand = new REBARBANDINFO ();
168         rbBand.cbSize = REBARBANDINFO.sizeof;
169         rbBand.fMask = OS.RBBIM_IDEALSIZE | OS.RBBIM_STYLE;
170         int rowWidth = 0;
171         for (int i = 0; i < count; i++) {
172             OS.SendMessage(handle, OS.RB_GETBANDINFO, i, rbBand);
173             if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) {
174                 width = Math.max(width, rowWidth);
175                 rowWidth = 0;
176             }
177             rowWidth += rbBand.cxIdeal + getMargin (i);
178         }
179         width = Math.max(width, rowWidth);
180         if (redraw) {
181             if (OS.COMCTL32_MAJOR >= 6) {
182                 OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
183             } else {
184                 OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
185             }
186         }
187         ignoreResize = false;
188     }
189     if (width == 0) width = DEFAULT_COOLBAR_WIDTH;
190     if (height == 0) height = DEFAULT_COOLBAR_HEIGHT;
191     if ((style & SWT.VERTICAL) != 0) {
192         int tmp = width;
193         width = height;
194         height = tmp;
195     }
196     if (wHint != SWT.DEFAULT) width = wHint;
197     if (hHint != SWT.DEFAULT) height = hHint;
198     height += border * 2;
199     width += border * 2;
200     return new Point (width, height);
201 }
202
203 void createHandle () {
204     super.createHandle ();
205     state &= ~(CANVAS | THEME_BACKGROUND);
206     
207     /*
208     * Feature in Windows. When the control is created,
209     * it does not use the default system font. A new HFONT
210     * is created and destroyed when the control is destroyed.
211     * This means that a program that queries the font from
212     * this control, uses the font in another control and then
213     * destroys this control will have the font unexpectedly
214     * destroyed in the other control. The fix is to assign
215     * the font ourselves each time the control is created.
216     * The control will not destroy a font that it did not
217     * create.
218     */

219     int hFont = OS.GetStockObject (OS.SYSTEM_FONT);
220     OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
221 }
222
223 void createItem (CoolItem item, int index) {
224     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
225     if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
226     int id = 0;
227     while (id < items.length && items [id] != null) id++;
228     if (id == items.length) {
229         CoolItem [] newItems = new CoolItem [items.length + 4];
230         System.arraycopy (items, 0, newItems, 0, items.length);
231         items = newItems;
232     }
233     int hHeap = OS.GetProcessHeap ();
234     int lpText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
235     REBARBANDINFO rbBand = new REBARBANDINFO ();
236     rbBand.cbSize = REBARBANDINFO.sizeof;
237     rbBand.fMask = OS.RBBIM_TEXT | OS.RBBIM_STYLE | OS.RBBIM_ID;
238     rbBand.fStyle = OS.RBBS_VARIABLEHEIGHT | OS.RBBS_GRIPPERALWAYS;
239     if ((item.style & SWT.DROP_DOWN) != 0) {
240         rbBand.fStyle |= OS.RBBS_USECHEVRON;
241     }
242     rbBand.lpText = lpText;
243     rbBand.wID = id;
244
245     /*
246     * Feature in Windows. When inserting an item at end of a row,
247     * sometimes, Windows will begin to place the item on the right
248     * side of the cool bar. The fix is to resize the new items to
249     * the maximum size and then resize the next to last item to the
250     * ideal size.
251     */

252     int lastIndex = getLastIndexOfRow (index - 1);
253     boolean fixLast = index == lastIndex + 1;
254     if (fixLast) {
255         rbBand.fMask |= OS.RBBIM_SIZE;
256         rbBand.cx = MAX_WIDTH;
257     }
258     
259     /*
260     * Feature in Windows. Is possible that the item at index zero
261     * has the RBBS_BREAK flag set. When a new item is inserted at
262     * position zero, the previous item at position zero moves to
263     * a new line. The fix is to detect this case and clear the
264     * RBBS_BREAK flag on the previous item before inserting the
265     * new item.
266     */

267     if (index == 0 && count > 0) {
268         getItem (0).setWrap (false);
269     }
270     
271     /* Insert the item */
272     if (OS.SendMessage (handle, OS.RB_INSERTBAND, index, rbBand) == 0) {
273         error (SWT.ERROR_ITEM_NOT_ADDED);
274     }
275     
276     /* Resize the next to last item to the ideal size */
277     if (fixLast) {
278         resizeToPreferredWidth (lastIndex);
279     }
280     
281     OS.HeapFree (hHeap, 0, lpText);
282     items [item.id = id] = item;
283     int length = originalItems.length;
284     CoolItem [] newOriginals = new CoolItem [length + 1];
285     System.arraycopy (originalItems, 0, newOriginals, 0, index);
286     System.arraycopy (originalItems, index, newOriginals, index + 1, length - index);
287     newOriginals [index] = item;
288     originalItems = newOriginals;
289 }
290
291 void createWidget () {
292     super.createWidget ();
293     items = new CoolItem [4];
294     originalItems = new CoolItem [0];
295 }
296
297 void destroyItem (CoolItem item) {
298     int index = OS.SendMessage (handle, OS.RB_IDTOINDEX, item.id, 0);
299     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
300     if (count != 0) {
301         int lastIndex = getLastIndexOfRow (index);
302         if (index == lastIndex) {
303             /*
304             * Feature in Windows. If the last item in a row is
305             * given its ideal size, it will be placed at the far
306             * right hand edge of the coolbar. It is preferred
307             * that the last item appear next to the second last
308             * item. The fix is to size the last item of each row
309             * so that it occupies all the available space to the
310             * right in the row.
311             */

312             resizeToMaximumWidth (lastIndex - 1);
313         }
314     }
315         
316     /*
317     * Feature in Windows. When Windows removed a rebar
318     * band, it makes the band child invisible. The fix
319     * is to show the child.
320     */

321     Control control = item.control;
322     boolean wasVisible = control != null && !control.isDisposed() && control.getVisible ();
323
324     /*
325     * When a wrapped item is being deleted, make the next
326     * item in the row wrapped in order to preserve the row.
327     * In order to avoid an unnecessary layout, temporarily
328     * ignore WM_SIZE. If the next item is wrapped then a
329     * row will be deleted and the WM_SIZE is necessary.
330     */

331     CoolItem nextItem = null;
332     if (item.getWrap ()) {
333         if (index + 1 < count) {
334             nextItem = getItem (index + 1);
335             ignoreResize = !nextItem.getWrap ();
336         }
337     }
338     if (OS.SendMessage (handle, OS.RB_DELETEBAND, index, 0) == 0) {
339         error (SWT.ERROR_ITEM_NOT_REMOVED);
340     }
341     items [item.id] = null;
342     item.id = -1;
343     if (ignoreResize) {
344         nextItem.setWrap (true);
345         ignoreResize = false;
346     }
347     
348     /* Restore the visible state of the control */
349     if (wasVisible) control.setVisible (true);
350     
351     index = 0;
352     while (index < originalItems.length) {
353         if (originalItems [index] == item) break;
354         index++;
355     }
356     int length = originalItems.length - 1;
357     CoolItem [] newOriginals = new CoolItem [length];
358     System.arraycopy (originalItems, 0, newOriginals, 0, index);
359     System.arraycopy (originalItems, index + 1, newOriginals, index, length - index);
360     originalItems = newOriginals;
361 }
362
363 void drawThemeBackground (int hDC, int hwnd, RECT rect) {
364     if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
365         if (background == -1 && (style & SWT.FLAT) != 0) {
366             Control control = findBackgroundControl ();
367             if (control != null && control.backgroundImage != null) {
368                 fillBackground (hDC, control.getBackgroundPixel (), rect);
369                 return;
370             }
371         }
372     }
373     RECT rect2 = new RECT ();
374     OS.GetClientRect (handle, rect2);
375     OS.MapWindowPoints (handle, hwnd, rect2, 2);
376     POINT lpPoint = new POINT ();
377     OS.SetWindowOrgEx (hDC, -rect2.left, -rect2.top, lpPoint);
378     OS.SendMessage (handle, OS.WM_PRINT, hDC, OS.PRF_CLIENT | OS.PRF_ERASEBKGND);
379     OS.SetWindowOrgEx (hDC, lpPoint.x, lpPoint.y, null);
380 }
381
382 Control findThemeControl () {
383     if ((style & SWT.FLAT) != 0) return this;
384     return background == -1 && backgroundImage == null ? this : super.findThemeControl ();
385 }
386
387 int getMargin (int index) {
388     int margin = 0;
389     if (OS.COMCTL32_MAJOR >= 6) {
390         MARGINS margins = new MARGINS ();
391         OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins);
392         margin += margins.cxLeftWidth + margins.cxRightWidth;
393     }
394     RECT rect = new RECT ();
395     OS.SendMessage (handle, OS.RB_GETBANDBORDERS, index, rect);
396     if ((style & SWT.FLAT) != 0) {
397         /*
398         * Bug in Windows. When the style bit RBS_BANDBORDERS is not set
399         * the rectangle returned by RBS_BANDBORDERS is four pixels too small.
400         * The fix is to add four pixels to the result.
401         */

402         if ((style & SWT.VERTICAL) != 0) {
403             margin += rect.top + 4;
404         } else {
405             margin += rect.left + 4;
406         }
407     } else {
408         if ((style & SWT.VERTICAL) != 0) {
409             margin += rect.top + rect.bottom;
410         } else {
411             margin += rect.left + rect.right;
412         }
413     }
414     if ((style & SWT.FLAT) == 0) {
415         if (!isLastItemOfRow (index)) {
416             margin += CoolBar.SEPARATOR_WIDTH;
417         }
418     }
419     return margin;
420 }
421
422 /**
423  * Returns the item that is currently displayed at the given,
424  * zero-relative index. Throws an exception if the index is
425  * out of range.
426  *
427  * @param index the visual index of the item to return
428  * @return the item at the given visual index
429  *
430  * @exception IllegalArgumentException <ul>
431  * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
432  * </ul>
433  * @exception SWTException <ul>
434  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
435  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
436  * </ul>
437  */

438 public CoolItem getItem (int index) {
439     checkWidget ();
440     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
441     if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
442     REBARBANDINFO rbBand = new REBARBANDINFO ();
443     rbBand.cbSize = REBARBANDINFO.sizeof;
444     rbBand.fMask = OS.RBBIM_ID;
445     OS.SendMessage (handle, OS.RB_GETBANDINFO, index, rbBand);
446     return items [rbBand.wID];
447 }
448
449 /**
450  * Returns the number of items contained in the receiver.
451  *
452  * @return the number of items
453  *
454  * @exception SWTException <ul>
455  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
456  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
457  * </ul>
458  */

459 public int getItemCount () {
460     checkWidget ();
461     return OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
462 }
463
464 /**
465  * Returns an array of zero-relative ints that map
466  * the creation order of the receiver's items to the
467  * order in which they are currently being displayed.
468  * <p>
469  * Specifically, the indices of the returned array represent
470  * the current visual order of the items, and the contents
471  * of the array represent the creation order of the items.
472  * </p><p>
473  * Note: This is not the actual structure used by the receiver
474  * to maintain its list of items, so modifying the array will
475  * not affect the receiver.
476  * </p>
477  *
478  * @return the current visual order of the receiver's items
479  *
480  * @exception SWTException <ul>
481  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
482  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
483  * </ul>
484  */

485 public int [] getItemOrder () {
486     checkWidget ();
487     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
488     int [] indices = new int [count];
489     REBARBANDINFO rbBand = new REBARBANDINFO ();
490     rbBand.cbSize = REBARBANDINFO.sizeof;
491     rbBand.fMask = OS.RBBIM_ID;
492     for (int i=0; i<count; i++) {
493         OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
494         CoolItem item = items [rbBand.wID];
495         int index = 0;
496         while (index<originalItems.length) {
497             if (originalItems [index] == item) break;
498             index++;
499         }
500         if (index == originalItems.length) error (SWT.ERROR_CANNOT_GET_ITEM);
501         indices [i] = index;
502     }
503     return indices;
504 }
505
506 /**
507  * Returns an array of <code>CoolItem</code>s in the order
508  * in which they are currently being displayed.
509  * <p>
510  * Note: This is not the actual structure used by the receiver
511  * to maintain its list of items, so modifying the array will
512  * not affect the receiver.
513  * </p>
514  *
515  * @return the receiver's items in their current visual order
516  *
517  * @exception SWTException <ul>
518  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
519  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
520  * </ul>
521  */

522 public CoolItem [] getItems () {
523     checkWidget ();
524     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
525     CoolItem [] result = new CoolItem [count];
526     REBARBANDINFO rbBand = new REBARBANDINFO ();
527     rbBand.cbSize = REBARBANDINFO.sizeof;
528     rbBand.fMask = OS.RBBIM_ID;
529     for (int i=0; i<count; i++) {
530         OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
531         result [i] = items [rbBand.wID];
532     }
533     return result;
534 }
535
536 /**
537  * Returns an array of points whose x and y coordinates describe
538  * the widths and heights (respectively) of the items in the receiver
539  * in the order in which they are currently being displayed.
540  *
541  * @return the receiver's item sizes in their current visual order
542  *
543  * @exception SWTException <ul>
544  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
545  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
546  * </ul>
547  */

548 public Point [] getItemSizes () {
549     checkWidget ();
550     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
551     Point [] sizes = new Point [count];
552     REBARBANDINFO rbBand = new REBARBANDINFO ();
553     rbBand.cbSize = REBARBANDINFO.sizeof;
554     rbBand.fMask = OS.RBBIM_CHILDSIZE;
555     int separator = (style & SWT.FLAT) == 0 ? SEPARATOR_WIDTH : 0;
556     MARGINS margins = new MARGINS ();
557     for (int i=0; i<count; i++) {
558         RECT rect = new RECT ();
559         OS.SendMessage (handle, OS.RB_GETRECT, i, rect);
560         OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
561         if (OS.COMCTL32_MAJOR >= 6) {
562             OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins);
563             rect.left -= margins.cxLeftWidth;
564             rect.right += margins.cxRightWidth;
565         }
566         if (!isLastItemOfRow(i)) rect.right += separator;
567         if ((style & SWT.VERTICAL) != 0) {
568             sizes [i] = new Point (rbBand.cyChild, rect.right - rect.left);
569         } else {
570             sizes [i] = new Point (rect.right - rect.left, rbBand.cyChild);
571         }
572     }
573     return sizes;
574 }
575
576 int getLastIndexOfRow (int index) {
577     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
578     if (count == 0) return -1;
579     REBARBANDINFO rbBand = new REBARBANDINFO ();
580     rbBand.cbSize = REBARBANDINFO.sizeof;
581     rbBand.fMask = OS.RBBIM_STYLE;
582     for (int i=index + 1; i<count; i++) {
583         OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
584         if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) {
585             return i - 1;
586         }
587     }
588     return count - 1;
589 }
590
591 boolean isLastItemOfRow (int index) {
592     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
593     if (index + 1 == count) return true;
594     REBARBANDINFO rbBand = new REBARBANDINFO ();
595     rbBand.cbSize = REBARBANDINFO.sizeof;
596     rbBand.fMask = OS.RBBIM_STYLE;
597     OS.SendMessage (handle, OS.RB_GETBANDINFO, index + 1, rbBand);
598     return (rbBand.fStyle & OS.RBBS_BREAK) != 0;
599 }
600
601 /**
602  * Returns whether or not the receiver is 'locked'. When a coolbar
603  * is locked, its items cannot be repositioned.
604  *
605  * @return true if the coolbar is locked, false otherwise
606  *
607  * @exception SWTException <ul>
608  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
609  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
610  * </ul>
611  *
612  * @since 2.0
613  */

614 public boolean getLocked () {
615     checkWidget ();
616     return locked;
617 }
618
619 /**
620  * Returns an array of ints that describe the zero-relative
621  * indices of any item(s) in the receiver that will begin on
622  * a new row. The 0th visible item always begins the first row,
623  * therefore it does not count as a wrap index.
624  *
625  * @return an array containing the receiver's wrap indices, or an empty array if all items are in one row
626  *
627  * @exception SWTException <ul>
628  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
629  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
630  * </ul>
631  */

632 public int [] getWrapIndices () {
633     checkWidget ();
634     CoolItem [] items = getItems ();
635     int [] indices = new int [items.length];
636     int count = 0;
637     for (int i=0; i<items.length; i++) {
638         if (items [i].getWrap ()) indices [count++] = i;
639     }
640     int [] result = new int [count];
641     System.arraycopy (indices, 0, result, 0, count);
642     return result;
643 }
644
645 /**
646  * Searches the receiver's items in the order they are currently
647  * being displayed, starting at the first item (index 0), until
648  * an item is found that is equal to the argument, and returns
649  * the index of that item. If no item is found, returns -1.
650  *
651  * @param item the search item
652  * @return the visual order index of the search item, or -1 if the item is not found
653  *
654  * @exception IllegalArgumentException <ul>
655  * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
656  * <li>ERROR_INVALID_ARGUMENT - if the item is disposed</li>
657  * </ul>
658  * @exception SWTException <ul>
659  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
660  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
661  * </ul>
662  */

663 public int indexOf (CoolItem item) {
664     checkWidget ();
665     if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
666     if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
667     return OS.SendMessage (handle, OS.RB_IDTOINDEX, item.id, 0);
668 }
669
670 void resizeToPreferredWidth (int index) {
671     /*
672     * Bug in Windows. When RB_GETBANDBORDERS is sent
673     * with an index out of range, Windows GP's. The
674     * fix is to ensure the index is in range.
675     */

676     int count = OS.SendMessage(handle, OS.RB_GETBANDCOUNT, 0, 0);
677     if (0 <= index && index < count) {
678         REBARBANDINFO rbBand = new REBARBANDINFO();
679         rbBand.cbSize = REBARBANDINFO.sizeof;
680         rbBand.fMask = OS.RBBIM_IDEALSIZE;
681         OS.SendMessage (handle, OS.RB_GETBANDINFO, index, rbBand);
682         RECT rect = new RECT ();
683         OS.SendMessage (handle, OS.RB_GETBANDBORDERS, index, rect);
684         rbBand.cx = rbBand.cxIdeal + rect.left;
685         if ((style & SWT.FLAT) == 0) rbBand.cx += rect.right;
686         rbBand.fMask = OS.RBBIM_SIZE;
687         OS.SendMessage (handle, OS.RB_SETBANDINFO, index, rbBand);
688     }
689 }
690
691 void resizeToMaximumWidth (int index) {
692     REBARBANDINFO rbBand = new REBARBANDINFO();
693     rbBand.cbSize = REBARBANDINFO.sizeof;
694     rbBand.fMask = OS.RBBIM_SIZE;
695     rbBand.cx = MAX_WIDTH;
696     OS.SendMessage (handle, OS.RB_SETBANDINFO, index, rbBand);
697 }
698
699 void releaseChildren (boolean destroy) {
700     if (items != null) {
701         for (int i=0; i<items.length; i++) {
702             CoolItem item = items [i];
703             if (item != null && !item.isDisposed ()) {
704                 item.release (false);
705             }
706         }
707         items = null;
708     }
709     super.releaseChildren (destroy);
710 }
711
712 void removeControl (Control control) {
713     super.removeControl (control);
714     for (int i=0; i<items.length; i++) {
715         CoolItem item = items [i];
716         if (item != null && item.control == control) {
717             item.setControl (null);
718         }
719     }
720 }
721
722 void setBackgroundPixel (int pixel) {
723     if (pixel == -1) pixel = defaultBackground ();
724     OS.SendMessage (handle, OS.RB_SETBKCOLOR, 0, pixel);
725     setItemColors (OS.SendMessage (handle, OS.RB_GETTEXTCOLOR, 0, 0), pixel);
726     /*
727     * Feature in Windows. For some reason, Windows
728     * does not fully erase the coolbar area and coolbar
729     * items when you set the background. The fix is
730     * to invalidate the coolbar area.
731     */

732     if (!OS.IsWindowVisible (handle)) return;
733     if (OS.IsWinCE) {
734         OS.InvalidateRect (handle, null, true);
735     } else {
736         int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
737         OS.RedrawWindow (handle, null, 0, flags);
738     }
739 }
740
741 void setForegroundPixel (int pixel) {
742     if (pixel == -1) pixel = defaultForeground ();
743     OS.SendMessage (handle, OS.RB_SETTEXTCOLOR, 0, pixel);
744     setItemColors (pixel, OS.SendMessage (handle, OS.RB_GETBKCOLOR, 0, 0));
745 }
746
747 void setItemColors (int foreColor, int backColor) {
748     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
749     REBARBANDINFO rbBand = new REBARBANDINFO ();
750     rbBand.cbSize = REBARBANDINFO.sizeof;
751     rbBand.fMask = OS.RBBIM_COLORS;
752     rbBand.clrFore = foreColor;
753     rbBand.clrBack = backColor;
754     for (int i=0; i<count; i++) {
755         OS.SendMessage (handle, OS.RB_SETBANDINFO, i, rbBand);
756     }
757 }
758
759 /**
760  * Sets the receiver's item order, wrap indices, and item sizes
761  * all at once. This method is typically used to restore the
762  * displayed state of the receiver to a previously stored state.
763  * <p>
764  * The item order is the order in which the items in the receiver
765  * should be displayed, given in terms of the zero-relative ordering
766  * of when the items were added.
767  * </p><p>
768  * The wrap indices are the indices of all item(s) in the receiver
769  * that will begin on a new row. The indices are given in the order
770  * specified by the item order. The 0th item always begins the first
771  * row, therefore it does not count as a wrap index. If wrap indices
772  * is null or empty, the items will be placed on one line.
773  * </p><p>
774  * The sizes are specified in an array of points whose x and y
775  * coordinates describe the new widths and heights (respectively)
776  * of the receiver's items in the order specified by the item order.
777  * </p>
778  *
779  * @param itemOrder an array of indices that describe the new order to display the items in
780  * @param wrapIndices an array of wrap indices, or null
781  * @param sizes an array containing the new sizes for each of the receiver's items in visual order
782  *
783  * @exception SWTException <ul>
784  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
785  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
786  * </ul>
787  * @exception IllegalArgumentException <ul>
788  * <li>ERROR_NULL_ARGUMENT - if item order or sizes is null</li>
789  * <li>ERROR_INVALID_ARGUMENT - if item order or sizes is not the same length as the number of items</li>
790  * </ul>
791  */

792 public void setItemLayout (int [] itemOrder, int [] wrapIndices, Point [] sizes) {
793     checkWidget ();
794     setRedraw (false);
795     setItemOrder (itemOrder);
796     setWrapIndices (wrapIndices);
797     setItemSizes (sizes);
798     setRedraw (true);
799 }
800
801 /*
802  * Sets the order that the items in the receiver should
803  * be displayed in to the given argument which is described
804  * in terms of the zero-relative ordering of when the items
805  * were added.
806  *
807  * @param itemOrder the new order to display the items in
808  *
809  * @exception SWTException <ul>
810  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
811  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
812  * </ul>
813  * @exception IllegalArgumentException <ul>
814  * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
815  * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
816  * </ul>
817  */

818 void setItemOrder (int [] itemOrder) {
819     if (itemOrder == null) error (SWT.ERROR_NULL_ARGUMENT);
820     int itemCount = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
821     if (itemOrder.length != itemCount) error (SWT.ERROR_INVALID_ARGUMENT);
822     
823     /* Ensure that itemOrder does not contain any duplicates. */
824     boolean [] set = new boolean [itemCount];
825     for (int i=0; i<itemOrder.length; i++) {
826         int index = itemOrder [i];
827         if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
828         if (set [index]) error (SWT.ERROR_INVALID_ARGUMENT);
829         set [index] = true;
830     }
831     
832     REBARBANDINFO rbBand = new REBARBANDINFO ();
833     rbBand.cbSize = REBARBANDINFO.sizeof;
834     for (int i=0; i<itemOrder.length; i++) {
835         int id = originalItems [itemOrder [i]].id;
836         int index = OS.SendMessage (handle, OS.RB_IDTOINDEX, id, 0);
837         if (index != i) {
838             int lastItemSrcRow = getLastIndexOfRow (index);
839             int lastItemDstRow = getLastIndexOfRow (i);
840             if (index == lastItemSrcRow) {
841                 resizeToPreferredWidth (index);
842             }
843             if (i == lastItemDstRow) {
844                 resizeToPreferredWidth (i);
845             }
846             
847             /* Move the item */
848             OS.SendMessage (handle, OS.RB_MOVEBAND, index, i);
849
850             if (index == lastItemSrcRow && index - 1 >= 0) {
851                 resizeToMaximumWidth (index - 1);
852             }
853             if (i == lastItemDstRow) {
854                 resizeToMaximumWidth (i);
855             }
856         }
857     }
858 }
859
860 /*
861  * Sets the width and height of the receiver's items to the ones
862  * specified by the argument, which is an array of points whose x
863  * and y coordinates describe the widths and heights (respectively)
864  * in the order in which the items are currently being displayed.
865  *
866  * @param sizes an array containing the new sizes for each of the receiver's items in visual order
867  *
868  * @exception IllegalArgumentException <ul>
869  * <li>ERROR_NULL_ARGUMENT - if the array of sizes is null</li>
870  * <li>ERROR_INVALID_ARGUMENT - if the array of sizes is not the same length as the number of items</li>
871  * </ul>
872  * @exception SWTException <ul>
873  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
874  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
875  * </ul>
876  */

877 void setItemSizes (Point [] sizes) {
878     if (sizes == null) error (SWT.ERROR_NULL_ARGUMENT);
879     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
880     if (sizes.length != count) error (SWT.ERROR_INVALID_ARGUMENT);
881     REBARBANDINFO rbBand = new REBARBANDINFO ();
882     rbBand.cbSize = REBARBANDINFO.sizeof;
883     rbBand.fMask = OS.RBBIM_ID;
884     for (int i=0; i<count; i++) {
885         OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
886         items [rbBand.wID].setSize (sizes [i].x, sizes [i].y);
887     }
888 }
889
890 /**
891  * Sets whether or not the receiver is 'locked'. When a coolbar
892  * is locked, its items cannot be repositioned.
893  *
894  * @param locked lock the coolbar if true, otherwise unlock the coolbar
895  *
896  * @exception SWTException <ul>
897  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
898  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
899  * </ul>
900  *
901  * @since 2.0
902  */

903 public void setLocked (boolean locked) {
904     checkWidget ();
905     this.locked = locked;
906     int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
907     REBARBANDINFO rbBand = new REBARBANDINFO ();
908     rbBand.cbSize = REBARBANDINFO.sizeof;
909     rbBand.fMask = OS.RBBIM_STYLE;
910     for (int i=0; i<count; i++) {
911         OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
912         if (locked) {
913             rbBand.fStyle |= OS.RBBS_NOGRIPPER;
914         } else {
915             rbBand.fStyle &= ~OS.RBBS_NOGRIPPER;
916         }
917         OS.SendMessage (handle, OS.RB_SETBANDINFO, i, rbBand);
918     }
919 }
920
921 /**
922  * Sets the indices of all item(s) in the receiver that will
923  * begin on a new row. The indices are given in the order in
924  * which they are currently being displayed. The 0th item
925  * always begins the first row, therefore it does not count
926  * as a wrap index. If indices is null or empty, the items
927  * will be placed on one line.
928  *
929  * @param indices an array of wrap indices, or null
930  *
931  * @exception SWTException <ul>
932  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
933  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
934  * </ul>
935  */

936 public void setWrapIndices (int [] indices) {
937     checkWidget ();
938     if (indices == null) indices = new int [0];
939     int count = getItemCount ();
940     for (int i=0; i<indices.length; i++) {
941         if (indices [i] < 0 || indices [i] >= count) {
942             error (SWT.ERROR_INVALID_RANGE);
943         }
944     }
945     setRedraw (false);
946     CoolItem [] items = getItems ();
947     for (int i=0; i<items.length; i++) {
948         CoolItem item = items [i];
949         if (item.getWrap ()) {
950             resizeToPreferredWidth (i - 1);
951             item.setWrap (false);
952         }
953     }
954     resizeToMaximumWidth (count - 1);
955     for (int i=0; i<indices.length; i++) {
956         int index = indices [i];
957         if (0 <= index && index < items.length) {
958             CoolItem item = items [index];
959             item.setWrap (true);
960             resizeToMaximumWidth (index - 1);
961         }
962     }
963     setRedraw (true);
964 }
965
966 int widgetStyle () {
967     int bits = super.widgetStyle () | OS.CCS_NODIVIDER | OS.CCS_NORESIZE;
968     bits |= OS.RBS_VARHEIGHT | OS.RBS_DBLCLKTOGGLE;
969     if ((style & SWT.FLAT) == 0) bits |= OS.RBS_BANDBORDERS;
970     return bits;
971 }
972
973 TCHAR windowClass () {
974     return ReBarClass;
975 }
976
977 int windowProc () {
978     return ReBarProc;
979 }
980
981 LRESULT WM_COMMAND (int wParam, int lParam) {
982     /*
983     * Feature in Windows. When the coolbar window
984     * proc processes WM_COMMAND, it forwards this
985     * message to its parent. This is done so that
986     * children of this control that send this message
987     * type to their parent will notify not only
988     * this control but also the parent of this control,
989     * which is typically the application window and
990     * the window that is looking for the message.
991     * If the control did not forward the message,
992     * applications would have to subclass the control
993     * window to see the message. Because the control
994     * window is subclassed by SWT, the message
995     * is delivered twice, once by SWT and once when
996     * the message is forwarded by the window proc.
997     * The fix is to avoid calling the window proc
998     * for this control.
999     */

1000    LRESULT result = super.WM_COMMAND (wParam, lParam);
1001    if (result != null) return result;
1002    return LRESULT.ZERO;
1003}
1004
1005LRESULT WM_ERASEBKGND (int wParam, int lParam) {
1006    LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
1007    /*
1008    * Feature in Windows. For some reason, Windows
1009    * does not fully erase the area that the cool bar
1010    * occupies when the size of the cool bar is larger
1011    * than the space occupied by the cool bar items.
1012    * The fix is to erase the cool bar background.
1013    *
1014    * NOTE: On versions of Windows prior to XP, for
1015    * some reason, the cool bar draws separators in
1016    * WM_ERASEBKGND. Therefore it is essential to run
1017    * the cool bar window proc after the background has
1018    * been erased.
1019    */

1020    if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
1021        drawBackground (wParam);
1022        return null;
1023    }
1024    return result;
1025}
1026
1027LRESULT WM_NOTIFY (int wParam, int lParam) {
1028    /*
1029    * Feature in Windows. When the cool bar window
1030    * proc processes WM_NOTIFY, it forwards this
1031    * message to its parent. This is done so that
1032    * children of this control that send this message
1033    * type to their parent will notify not only
1034    * this control but also the parent of this control,
1035    * which is typically the application window and
1036    * the window that is looking for the message.
1037    * If the control did not forward the message,
1038    * applications would have to subclass the control
1039    * window to see the message. Because the control
1040    * window is subclassed by SWT, the message
1041    * is delivered twice, once by SWT and once when
1042    * the message is forwarded by the window proc.
1043    * The fix is to avoid calling the window proc
1044    * for this control.
1045    */

1046    LRESULT result = super.WM_NOTIFY (wParam, lParam);
1047    if (result != null) return result;
1048    return LRESULT.ZERO;
1049}
1050
1051LRESULT WM_SETREDRAW (int wParam, int lParam) {
1052    LRESULT result = super.WM_SETREDRAW (wParam, lParam);
1053    if (result != null) return result;
1054    /*
1055    * Feature in Windows. When redraw is turned off, the rebar
1056    * control does not call the default window proc. This means
1057    * that the rebar will redraw and children of the rebar will
1058    * also redraw. The fix is to call both the rebar window proc
1059    * and the default window proc.
1060    *
1061    * NOTE: The rebar control can resize itself in WM_SETREDRAW.
1062    * When redraw is turned off by the default window proc, this
1063    * can leave pixel corruption in the parent. The fix is to
1064    * detect the size change and damage the previous area in the
1065    * parent.
1066    *
1067    * NOTE: In version 6.00 of COMCTL32.DLL, when WM_SETREDRAW
1068    * is off, we cannot detect that the size has changed causing
1069    * pixel corruption. The fix is to disallow WM_SETREDRAW by
1070    * not running the default window proc or the rebar window
1071    * proc.
1072    */

1073    if (OS.COMCTL32_MAJOR >= 6) return LRESULT.ZERO;
1074    Rectangle rect = getBounds ();
1075    int code = callWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam);
1076    OS.DefWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam);
1077    if (!rect.equals (getBounds ())) {
1078        parent.redraw (rect.x, rect.y, rect.width, rect.height, true);
1079    }
1080    return new LRESULT (code);
1081}
1082
1083LRESULT WM_SIZE (int wParam, int lParam) {
1084    if (ignoreResize) {
1085        int code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam);
1086        if (code == 0) return LRESULT.ZERO;
1087        return new LRESULT (code);
1088    }
1089    //TEMPORARY CODE
1090
// if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
1091
// if (background == -1 && (style & SWT.FLAT) == 0) {
1092
// OS.InvalidateRect (handle, null, true);
1093
// }
1094
// }
1095
return super.WM_SIZE (wParam, lParam);
1096}
1097
1098LRESULT wmNotifyChild (NMHDR hdr, int wParam, int lParam) {
1099    switch (hdr.code) {
1100        case OS.RBN_BEGINDRAG: {
1101            int pos = OS.GetMessagePos ();
1102            POINT pt = new POINT ();
1103            pt.x = (short) (pos & 0xFFFF);
1104            pt.y = (short) (pos >> 16);
1105            OS.ScreenToClient (handle, pt);
1106            int button = display.lastButton != 0 ? display.lastButton : 1;
1107            if (!sendDragEvent (button, pt.x, pt.y)) return LRESULT.ONE;
1108            break;
1109        }
1110        case OS.RBN_CHILDSIZE: {
1111            /*
1112            * Bug in Windows. When Windows sets the size of the rebar band
1113            * child and the child is a combo box, the size of the drop down
1114            * portion of the combo box is resized to zero. The fix is to set
1115            * the size of the control to the current size after the rebar has
1116            * already resized it. If the control is not a combo, this does
1117            * nothing. If the control is a combo, the drop down portion is
1118            * recalculated.
1119            */

1120            NMREBARCHILDSIZE lprbcs = new NMREBARCHILDSIZE ();
1121            OS.MoveMemory (lprbcs, lParam, NMREBARCHILDSIZE.sizeof);
1122            if (lprbcs.uBand != -1) {
1123                CoolItem item = items [lprbcs.wID];
1124                Control control = item.control;
1125                if (control != null) {
1126                    int width = lprbcs.rcChild_right - lprbcs.rcChild_left;
1127                    int height = lprbcs.rcChild_bottom - lprbcs.rcChild_top;
1128                    control.setBounds (lprbcs.rcChild_left, lprbcs.rcChild_top, width, height);
1129                }
1130            }
1131            break;
1132        }
1133        case OS.RBN_HEIGHTCHANGE: {
1134            if (!ignoreResize) {
1135                Point size = getSize ();
1136                int border = getBorderWidth ();
1137                int barHeight = OS.SendMessage (handle, OS.RB_GETBARHEIGHT, 0, 0);
1138                if ((style & SWT.VERTICAL) != 0) {
1139                    setSize (barHeight + 2 * border, size.y);
1140                } else {
1141                    setSize (size.x, barHeight + 2 * border);
1142                }
1143            }
1144            break;
1145        }
1146        case OS.RBN_CHEVRONPUSHED: {
1147            NMREBARCHEVRON lpnm = new NMREBARCHEVRON ();
1148            OS.MoveMemory (lpnm, lParam, NMREBARCHEVRON.sizeof);
1149            CoolItem item = items [lpnm.wID];
1150            if (item != null) {
1151                Event event = new Event();
1152                event.detail = SWT.ARROW;
1153                if ((style & SWT.VERTICAL) != 0) {
1154                    event.x = lpnm.right;
1155                    event.y = lpnm.top;
1156                } else {
1157                    event.x = lpnm.left;
1158                    event.y = lpnm.bottom;
1159                }
1160                item.postEvent (SWT.Selection, event);
1161            }
1162            break;
1163        }
1164        case OS.NM_CUSTOMDRAW: {
1165            /*
1166            * Bug in Windows. On versions of Windows prior to XP,
1167            * drawing the background color in NM_CUSTOMDRAW erases
1168            * the separators. The fix is to draw the background
1169            * in WM_ERASEBKGND.
1170            */

1171            if (OS.COMCTL32_MAJOR < 6) break;
1172            if (findBackgroundControl () != null || (style & SWT.FLAT) != 0) {
1173                NMCUSTOMDRAW nmcd = new NMCUSTOMDRAW ();
1174                OS.MoveMemory (nmcd, lParam, NMCUSTOMDRAW.sizeof);
1175                switch (nmcd.dwDrawStage) {
1176                    case OS.CDDS_PREERASE:
1177                        return new LRESULT (OS.CDRF_SKIPDEFAULT | OS.CDRF_NOTIFYPOSTERASE);
1178                    case OS.CDDS_POSTERASE:
1179                        drawBackground (nmcd.hdc);
1180                        break;
1181                }
1182            }
1183            break;
1184        }
1185    }
1186    return super.wmNotifyChild (hdr, wParam, lParam);
1187}
1188}
1189
Popular Tags