KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.swt.events.*;
18
19 /**
20  * Instances of this class are selectable user interface
21  * objects that represent the dynamically positionable
22  * areas of a <code>CoolBar</code>.
23  * <dl>
24  * <dt><b>Styles:</b></dt>
25  * <dd>DROP_DOWN</dd>
26  * <dt><b>Events:</b></dt>
27  * <dd>Selection</dd>
28  * </dl>
29  * <p>
30  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
31  * </p>
32  */

33
34 public class CoolItem extends Item {
35     CoolBar parent;
36     Control control;
37     int id;
38     boolean ideal, minimum;
39
40 /**
41  * Constructs a new instance of this class given its parent
42  * (which must be a <code>CoolBar</code>) and a style value
43  * describing its behavior and appearance. The item is added
44  * to the end of the items maintained by its parent.
45  * <p>
46  * The style value is either one of the style constants defined in
47  * class <code>SWT</code> which is applicable to instances of this
48  * class, or must be built by <em>bitwise OR</em>'ing together
49  * (that is, using the <code>int</code> "|" operator) two or more
50  * of those <code>SWT</code> style constants. The class description
51  * lists the style constants that are applicable to the class.
52  * Style bits are also inherited from superclasses.
53  * </p>
54  *
55  * @param parent a composite control which will be the parent of the new instance (cannot be null)
56  * @param style the style of control to construct
57  *
58  * @exception IllegalArgumentException <ul>
59  * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
60  * </ul>
61  * @exception SWTException <ul>
62  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
63  * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
64  * </ul>
65  *
66  * @see SWT#DROP_DOWN
67  * @see Widget#checkSubclass
68  * @see Widget#getStyle
69  */

70 public CoolItem (CoolBar parent, int style) {
71     super (parent, style);
72     this.parent = parent;
73     parent.createItem (this, parent.getItemCount ());
74 }
75
76 /**
77  * Constructs a new instance of this class given its parent
78  * (which must be a <code>CoolBar</code>), a style value
79  * describing its behavior and appearance, and the index
80  * at which to place it in the items maintained by its parent.
81  * <p>
82  * The style value is either one of the style constants defined in
83  * class <code>SWT</code> which is applicable to instances of this
84  * class, or must be built by <em>bitwise OR</em>'ing together
85  * (that is, using the <code>int</code> "|" operator) two or more
86  * of those <code>SWT</code> style constants. The class description
87  * lists the style constants that are applicable to the class.
88  * Style bits are also inherited from superclasses.
89  * </p>
90  *
91  * @param parent a composite control which will be the parent of the new instance (cannot be null)
92  * @param style the style of control to construct
93  * @param index the zero-relative index at which to store the receiver in its parent
94  *
95  * @exception IllegalArgumentException <ul>
96  * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
97  * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
98  * </ul>
99  * @exception SWTException <ul>
100  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
101  * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
102  * </ul>
103  *
104  * @see SWT#DROP_DOWN
105  * @see Widget#checkSubclass
106  * @see Widget#getStyle
107  */

108 public CoolItem (CoolBar parent, int style, int index) {
109     super (parent, style);
110     this.parent = parent;
111     parent.createItem (this, index);
112 }
113
114 /**
115  * Adds the listener to the collection of listeners that will
116  * be notified when the control is selected by the user, by sending it one
117  * of the messages defined in the <code>SelectionListener</code>
118  * interface.
119  * <p>
120  * If <code>widgetSelected</code> is called when the mouse is over
121  * the drop-down arrow (or 'chevron') portion of the cool item,
122  * the event object detail field contains the value <code>SWT.ARROW</code>,
123  * and the x and y fields in the event object represent the point at
124  * the bottom left of the chevron, where the menu should be popped up.
125  * <code>widgetDefaultSelected</code> is not called.
126  * </p>
127  *
128  * @param listener the listener which should be notified when the control is selected by the user
129  *
130  * @exception IllegalArgumentException <ul>
131  * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
132  * </ul>
133  * @exception SWTException <ul>
134  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
135  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
136  * </ul>
137  *
138  * @see SelectionListener
139  * @see #removeSelectionListener
140  * @see SelectionEvent
141  *
142  * @since 2.0
143  */

144 public void addSelectionListener(SelectionListener listener) {
145     checkWidget();
146     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
147     TypedListener typedListener = new TypedListener (listener);
148     addListener (SWT.Selection,typedListener);
149     addListener (SWT.DefaultSelection,typedListener);
150 }
151
152 protected void checkSubclass () {
153     if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
154 }
155
156 /**
157  * Returns the preferred size of the receiver.
158  * <p>
159  * The <em>preferred size</em> of a <code>CoolItem</code> is the size that
160  * it would best be displayed at. The width hint and height hint arguments
161  * allow the caller to ask the instance questions such as "Given a particular
162  * width, how high does it need to be to show all of the contents?"
163  * To indicate that the caller does not wish to constrain a particular
164  * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
165  * </p>
166  *
167  * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
168  * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
169  * @return the preferred size
170  *
171  * @exception SWTException <ul>
172  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
173  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
174  * </ul>
175  *
176  * @see Layout
177  * @see #getBounds
178  * @see #getSize
179  * @see Control#getBorderWidth
180  * @see Scrollable#computeTrim
181  * @see Scrollable#getClientArea
182  */

183 public Point computeSize (int wHint, int hHint) {
184     checkWidget ();
185     int index = parent.indexOf (this);
186     if (index == -1) return new Point (0, 0);
187     int width = wHint, height = hHint;
188     if (wHint == SWT.DEFAULT) width = 32;
189     if (hHint == SWT.DEFAULT) height = 32;
190     if ((parent.style & SWT.VERTICAL) != 0) {
191         height += parent.getMargin (index);
192     } else {
193         width += parent.getMargin (index);
194     }
195     return new Point (width, height);
196 }
197
198 void destroyWidget () {
199     parent.destroyItem (this);
200     releaseHandle ();
201 }
202
203 /**
204  * Returns a rectangle describing the receiver's size and location
205  * relative to its parent.
206  *
207  * @return the receiver's bounding rectangle
208  *
209  * @exception SWTException <ul>
210  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
211  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
212  * </ul>
213  */

214 public Rectangle getBounds () {
215     checkWidget ();
216     int index = parent.indexOf (this);
217     if (index == -1) return new Rectangle (0, 0, 0, 0);
218     int hwnd = parent.handle;
219     RECT rect = new RECT ();
220     OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
221     if (OS.COMCTL32_MAJOR >= 6) {
222         MARGINS margins = new MARGINS ();
223         OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
224         rect.left -= margins.cxLeftWidth;
225         rect.right += margins.cxRightWidth;
226     }
227     if (!parent.isLastItemOfRow (index)) {
228         rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
229     }
230     int width = rect.right - rect.left;
231     int height = rect.bottom - rect.top;
232     if ((parent.style & SWT.VERTICAL) != 0) {
233         return new Rectangle (rect.top, rect.left, height, width);
234     }
235     return new Rectangle (rect.left, rect.top, width, height);
236 }
237
238 Rectangle getClientArea () {
239     checkWidget ();
240     int index = parent.indexOf (this);
241     if (index == -1) return new Rectangle (0, 0, 0, 0);
242     int hwnd = parent.handle;
243     RECT insetRect = new RECT ();
244     OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, insetRect);
245     RECT rect = new RECT ();
246     OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
247     int x = rect.left + insetRect.left;
248     int y = rect.top;
249     int width = rect.right - rect.left - insetRect.left;
250     int height = rect.bottom - rect.top;
251     if ((parent.style & SWT.FLAT) == 0) {
252         y += insetRect.top;
253         width -= insetRect.right;
254         height -= insetRect.top + insetRect.bottom;
255     }
256     if (index == 0) {
257         REBARBANDINFO rbBand = new REBARBANDINFO ();
258         rbBand.cbSize = REBARBANDINFO.sizeof;
259         rbBand.fMask = OS.RBBIM_HEADERSIZE;
260         OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
261         width = width - rbBand.cxHeader + 1;
262     }
263     return new Rectangle (x, y, Math.max (0, width), Math.max (0, height));
264 }
265
266 /**
267  * Returns the control that is associated with the receiver.
268  *
269  * @return the control that is contained by the receiver
270  *
271  * @exception SWTException <ul>
272  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
273  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
274  * </ul>
275  */

276 public Control getControl () {
277     checkWidget ();
278     return control;
279 }
280
281 /**
282  * Returns the receiver's parent, which must be a <code>CoolBar</code>.
283  *
284  * @return the receiver's parent
285  *
286  * @exception SWTException <ul>
287  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
288  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
289  * </ul>
290  */

291 public CoolBar getParent () {
292     checkWidget ();
293     return parent;
294 }
295
296 void releaseHandle () {
297     super.releaseHandle ();
298     parent = null;
299     id = -1;
300     control = null;
301 }
302
303 /**
304  * Sets the control that is associated with the receiver
305  * to the argument.
306  *
307  * @param control the new control that will be contained by the receiver
308  *
309  * @exception IllegalArgumentException <ul>
310  * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
311  * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
312  * </ul>
313  * @exception SWTException <ul>
314  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
315  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
316  * </ul>
317  */

318 public void setControl (Control control) {
319     checkWidget ();
320     if (control != null) {
321         if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
322         if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
323     }
324     int index = parent.indexOf (this);
325     if (index == -1) return;
326     if (this.control != null && this.control.isDisposed ()) {
327         this.control = null;
328     }
329     Control oldControl = this.control, newControl = control;
330     int hwnd = parent.handle;
331     int hwndChild = newControl != null ? control.topHandle () : 0;
332     REBARBANDINFO rbBand = new REBARBANDINFO ();
333     rbBand.cbSize = REBARBANDINFO.sizeof;
334     rbBand.fMask = OS.RBBIM_CHILD;
335     rbBand.hwndChild = hwndChild;
336     this.control = newControl;
337
338     /*
339     * Feature in Windows. When Windows sets the rebar band child,
340     * it makes the new child visible and hides the old child and
341     * moves the new child to the top of the Z-order. The fix is
342     * to save and restore the visibility and Z-order.
343     */

344     int hwndAbove = 0;
345     if (newControl != null) {
346         hwndAbove = OS.GetWindow (hwndChild, OS.GW_HWNDPREV);
347     }
348     boolean hideNew = newControl != null && !newControl.getVisible ();
349     boolean showOld = oldControl != null && oldControl.getVisible ();
350     OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
351     if (hideNew) newControl.setVisible (false);
352     if (showOld) oldControl.setVisible (true);
353     if (hwndAbove != 0 && hwndAbove != hwndChild) {
354         int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
355         SetWindowPos (hwndChild, hwndAbove, 0, 0, 0, 0, flags);
356     }
357 }
358
359 /**
360  * Returns a point describing the receiver's ideal size.
361  * The x coordinate of the result is the ideal width of the receiver.
362  * The y coordinate of the result is the ideal height of the receiver.
363  *
364  * @return the receiver's ideal size
365  *
366  * @exception SWTException <ul>
367  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
368  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
369  * </ul>
370  */

371 public Point getPreferredSize () {
372     checkWidget ();
373     int index = parent.indexOf (this);
374     if (index == -1) return new Point (0, 0);
375     int hwnd = parent.handle;
376     REBARBANDINFO rbBand = new REBARBANDINFO ();
377     rbBand.cbSize = REBARBANDINFO.sizeof;
378     rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
379     OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
380     int width = rbBand.cxIdeal + parent.getMargin (index);
381     if ((parent.style & SWT.VERTICAL) != 0) {
382         return new Point (rbBand.cyMaxChild, width);
383     }
384     return new Point (width, rbBand.cyMaxChild);
385 }
386
387 /**
388  * Sets the receiver's ideal size to the point specified by the arguments.
389  *
390  * @param width the new ideal width for the receiver
391  * @param height the new ideal height for the receiver
392  *
393  * @exception SWTException <ul>
394  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
395  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
396  * </ul>
397  */

398 public void setPreferredSize (int width, int height) {
399     checkWidget ();
400     int index = parent.indexOf (this);
401     if (index == -1) return;
402     width = Math.max (0, width);
403     height = Math.max (0, height);
404     ideal = true;
405     int hwnd = parent.handle;
406     int cxIdeal, cyMaxChild;
407     if ((parent.style & SWT.VERTICAL) != 0) {
408         cxIdeal = Math.max (0, height - parent.getMargin (index));
409         cyMaxChild = width;
410     } else {
411         cxIdeal = Math.max (0, width - parent.getMargin (index));
412         cyMaxChild = height;
413     }
414     REBARBANDINFO rbBand = new REBARBANDINFO ();
415     rbBand.cbSize = REBARBANDINFO.sizeof;
416     
417     /* Get the child size fields first so we don't overwrite them. */
418     rbBand.fMask = OS.RBBIM_CHILDSIZE;
419     OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
420     
421     /* Set the size fields we are currently modifying. */
422     rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
423     rbBand.cxIdeal = cxIdeal;
424     rbBand.cyMaxChild = cyMaxChild;
425     if (!minimum) rbBand.cyMinChild = cyMaxChild;
426     OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
427 }
428
429 /**
430  * Sets the receiver's ideal size to the point specified by the argument.
431  *
432  * @param size the new ideal size for the receiver
433  *
434  * @exception IllegalArgumentException <ul>
435  * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
436  * </ul>
437  * @exception SWTException <ul>
438  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
439  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
440  * </ul>
441  */

442 public void setPreferredSize (Point size) {
443     checkWidget ();
444     if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
445     setPreferredSize (size.x, size.y);
446 }
447
448 /**
449  * Returns a point describing the receiver's size. The
450  * x coordinate of the result is the width of the receiver.
451  * The y coordinate of the result is the height of the
452  * receiver.
453  *
454  * @return the receiver's size
455  *
456  * @exception SWTException <ul>
457  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
458  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
459  * </ul>
460  */

461 public Point getSize() {
462     checkWidget ();
463     int index = parent.indexOf (this);
464     if (index == -1) new Point (0, 0);
465     int hwnd = parent.handle;
466     RECT rect = new RECT ();
467     OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
468     if (OS.COMCTL32_MAJOR >= 6) {
469         MARGINS margins = new MARGINS ();
470         OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
471         rect.left -= margins.cxLeftWidth;
472         rect.right += margins.cxRightWidth;
473     }
474     if (!parent.isLastItemOfRow (index)) {
475         rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
476     }
477     int width = rect.right - rect.left;
478     int height = rect.bottom - rect.top;
479     if ((parent.style & SWT.VERTICAL) != 0) {
480         return new Point (height, width);
481     }
482     return new Point (width, height);
483 }
484
485 /**
486  * Sets the receiver's size to the point specified by the arguments.
487  * <p>
488  * Note: Attempting to set the width or height of the
489  * receiver to a negative number will cause that
490  * value to be set to zero instead.
491  * </p>
492  *
493  * @param width the new width for the receiver
494  * @param height the new height for the receiver
495  *
496  * @exception SWTException <ul>
497  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
498  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
499  * </ul>
500  */

501 public void setSize (int width, int height) {
502     checkWidget ();
503     int index = parent.indexOf (this);
504     if (index == -1) return;
505     width = Math.max (0, width);
506     height = Math.max (0, height);
507     int hwnd = parent.handle;
508     int cx, cyChild, cxIdeal;
509     if ((parent.style & SWT.VERTICAL) != 0) {
510         cx = height;
511         cyChild = width;
512         cxIdeal = Math.max (0, height - parent.getMargin (index));
513     } else {
514         cx = width;
515         cyChild = height;
516         cxIdeal = Math.max (0, width - parent.getMargin (index));
517     }
518     REBARBANDINFO rbBand = new REBARBANDINFO ();
519     rbBand.cbSize = REBARBANDINFO.sizeof;
520     
521     /* Get the child size fields first so we don't overwrite them. */
522     rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
523     OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
524     
525     /* Set the size fields we are currently modifying. */
526     if (!ideal) rbBand.cxIdeal = cxIdeal;
527     if (!minimum) rbBand.cyMinChild = cyChild;
528     rbBand.cyChild = cyChild;
529     
530     /*
531     * Do not set the size for the last item on the row.
532     */

533     if (!parent.isLastItemOfRow (index)) {
534         if (OS.COMCTL32_MAJOR >= 6) {
535             MARGINS margins = new MARGINS ();
536             OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
537             cx -= margins.cxLeftWidth + margins.cxRightWidth;
538         }
539         int separator = (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
540         rbBand.cx = cx - separator;
541         rbBand.fMask |= OS.RBBIM_SIZE;
542     }
543     OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
544 }
545
546 /**
547  * Sets the receiver's size to the point specified by the argument.
548  * <p>
549  * Note: Attempting to set the width or height of the
550  * receiver to a negative number will cause them to be
551  * set to zero instead.
552  * </p>
553  *
554  * @param size the new size for the receiver
555  *
556  * @exception IllegalArgumentException <ul>
557  * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
558  * </ul>
559  * @exception SWTException <ul>
560  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
561  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
562  * </ul>
563  */

564 public void setSize (Point size) {
565     if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
566     setSize (size.x, size.y);
567 }
568
569 /**
570  * Returns the minimum size that the cool item can
571  * be resized to using the cool item's gripper.
572  *
573  * @return a point containing the minimum width and height of the cool item, in pixels
574  *
575  * @exception SWTException <ul>
576  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
577  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
578  * </ul>
579  *
580  * @since 2.0
581  */

582 public Point getMinimumSize () {
583     checkWidget ();
584     int index = parent.indexOf (this);
585     if (index == -1) return new Point (0, 0);
586     int hwnd = parent.handle;
587     REBARBANDINFO rbBand = new REBARBANDINFO ();
588     rbBand.cbSize = REBARBANDINFO.sizeof;
589     rbBand.fMask = OS.RBBIM_CHILDSIZE;
590     OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
591     if ((parent.style & SWT.VERTICAL) != 0) {
592         return new Point (rbBand.cyMinChild, rbBand.cxMinChild);
593     }
594     return new Point (rbBand.cxMinChild, rbBand.cyMinChild);
595 }
596
597 /**
598  * Sets the minimum size that the cool item can be resized to
599  * using the cool item's gripper, to the point specified by the arguments.
600  *
601  * @param width the minimum width of the cool item, in pixels
602  * @param height the minimum height of the cool item, in pixels
603  *
604  * @exception SWTException <ul>
605  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
606  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
607  * </ul>
608  *
609  * @since 2.0
610  */

611 public void setMinimumSize (int width, int height) {
612     checkWidget ();
613     int index = parent.indexOf (this);
614     if (index == -1) return;
615     width = Math.max (0, width);
616     height = Math.max (0, height);
617     minimum = true;
618     int hwnd = parent.handle;
619     int cxMinChild, cyMinChild;
620     if ((parent.style & SWT.VERTICAL) != 0) {
621         cxMinChild = height;
622         cyMinChild = width;
623     } else {
624         cxMinChild = width;
625         cyMinChild = height;
626     }
627     REBARBANDINFO rbBand = new REBARBANDINFO ();
628     rbBand.cbSize = REBARBANDINFO.sizeof;
629     
630     /* Get the child size fields first so we don't overwrite them. */
631     rbBand.fMask = OS.RBBIM_CHILDSIZE;
632     OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
633     
634     /* Set the size fields we are currently modifying. */
635     rbBand.cxMinChild = cxMinChild;
636     rbBand.cyMinChild = cyMinChild;
637     OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
638 }
639
640 /**
641  * Sets the minimum size that the cool item can be resized to
642  * using the cool item's gripper, to the point specified by the argument.
643  *
644  * @param size a point representing the minimum width and height of the cool item, in pixels
645  *
646  * @exception IllegalArgumentException <ul>
647  * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
648  * </ul>
649  * @exception SWTException <ul>
650  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
651  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
652  * </ul>
653  *
654  * @since 2.0
655  */

656 public void setMinimumSize (Point size) {
657     checkWidget ();
658     if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
659     setMinimumSize (size.x, size.y);
660 }
661
662 boolean getWrap() {
663     int index = parent.indexOf (this);
664     int hwnd = parent.handle;
665     REBARBANDINFO rbBand = new REBARBANDINFO ();
666     rbBand.cbSize = REBARBANDINFO.sizeof;
667     rbBand.fMask = OS.RBBIM_STYLE;
668     OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
669     return (rbBand.fStyle & OS.RBBS_BREAK) != 0;
670 }
671
672 void setWrap(boolean wrap) {
673     int index = parent.indexOf (this);
674     int hwnd = parent.handle;
675     REBARBANDINFO rbBand = new REBARBANDINFO ();
676     rbBand.cbSize = REBARBANDINFO.sizeof;
677     rbBand.fMask = OS.RBBIM_STYLE;
678     OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
679     if (wrap) {
680         rbBand.fStyle |= OS.RBBS_BREAK;
681     } else {
682         rbBand.fStyle &= ~OS.RBBS_BREAK;
683     }
684     OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
685 }
686
687 /**
688  * Removes the listener from the collection of listeners that
689  * will be notified when the control is selected by the user.
690  *
691  * @param listener the listener which should no longer be notified
692  *
693  * @exception IllegalArgumentException <ul>
694  * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
695  * </ul>
696  * @exception SWTException <ul>
697  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
698  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
699  * </ul>
700  *
701  * @see SelectionListener
702  * @see #addSelectionListener
703  *
704  * @since 2.0
705  */

706 public void removeSelectionListener(SelectionListener listener) {
707     checkWidget();
708     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
709     if (eventTable == null) return;
710     eventTable.unhook (SWT.Selection, listener);
711     eventTable.unhook (SWT.DefaultSelection,listener);
712 }
713
714 }
715
Popular Tags