]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/widgets/CoolItem.java
Remove invalid SHA-256-Digests
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / widgets / CoolItem.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2018 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.widgets;
15
16
17 import org.eclipse.swt.*;
18 import org.eclipse.swt.events.*;
19 import org.eclipse.swt.graphics.*;
20 import org.eclipse.swt.internal.*;
21 import org.eclipse.swt.internal.win32.*;
22
23 /**
24  * Instances of this class are selectable user interface
25  * objects that represent the dynamically positionable
26  * areas of a <code>CoolBar</code>.
27  * <dl>
28  * <dt><b>Styles:</b></dt>
29  * <dd>DROP_DOWN</dd>
30  * <dt><b>Events:</b></dt>
31  * <dd>Selection</dd>
32  * </dl>
33  * <p>
34  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
35  * </p>
36  *
37  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
38  * @noextend This class is not intended to be subclassed by clients.
39  */
40 public class CoolItem extends Item {
41         CoolBar parent;
42         Control control;
43         int id;
44         boolean ideal, minimum;
45
46 /**
47  * Constructs a new instance of this class given its parent
48  * (which must be a <code>CoolBar</code>) and a style value
49  * describing its behavior and appearance. The item is added
50  * to the end of the items maintained by its parent.
51  * <p>
52  * The style value is either one of the style constants defined in
53  * class <code>SWT</code> which is applicable to instances of this
54  * class, or must be built by <em>bitwise OR</em>'ing together
55  * (that is, using the <code>int</code> "|" operator) two or more
56  * of those <code>SWT</code> style constants. The class description
57  * lists the style constants that are applicable to the class.
58  * Style bits are also inherited from superclasses.
59  * </p>
60  *
61  * @param parent a composite control which will be the parent of the new instance (cannot be null)
62  * @param style the style of control to construct
63  *
64  * @exception IllegalArgumentException <ul>
65  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
66  * </ul>
67  * @exception SWTException <ul>
68  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
69  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
70  * </ul>
71  *
72  * @see SWT#DROP_DOWN
73  * @see Widget#checkSubclass
74  * @see Widget#getStyle
75  */
76 public CoolItem (CoolBar parent, int style) {
77         super (parent, style);
78         this.parent = parent;
79         parent.createItem (this, parent.getItemCount ());
80 }
81
82 /**
83  * Constructs a new instance of this class given its parent
84  * (which must be a <code>CoolBar</code>), a style value
85  * describing its behavior and appearance, and the index
86  * at which to place it in the items maintained by its parent.
87  * <p>
88  * The style value is either one of the style constants defined in
89  * class <code>SWT</code> which is applicable to instances of this
90  * class, or must be built by <em>bitwise OR</em>'ing together
91  * (that is, using the <code>int</code> "|" operator) two or more
92  * of those <code>SWT</code> style constants. The class description
93  * lists the style constants that are applicable to the class.
94  * Style bits are also inherited from superclasses.
95  * </p>
96  *
97  * @param parent a composite control which will be the parent of the new instance (cannot be null)
98  * @param style the style of control to construct
99  * @param index the zero-relative index at which to store the receiver in its parent
100  *
101  * @exception IllegalArgumentException <ul>
102  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
103  *    <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
104  * </ul>
105  * @exception SWTException <ul>
106  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
107  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
108  * </ul>
109  *
110  * @see SWT#DROP_DOWN
111  * @see Widget#checkSubclass
112  * @see Widget#getStyle
113  */
114 public CoolItem (CoolBar parent, int style, int index) {
115         super (parent, style);
116         this.parent = parent;
117         parent.createItem (this, index);
118 }
119
120 /**
121  * Adds the listener to the collection of listeners that will
122  * be notified when the control is selected by the user, by sending it one
123  * of the messages defined in the <code>SelectionListener</code>
124  * interface.
125  * <p>
126  * If <code>widgetSelected</code> is called when the mouse is over
127  * the drop-down arrow (or 'chevron') portion of the cool item,
128  * the event object detail field contains the value <code>SWT.ARROW</code>,
129  * and the x and y fields in the event object represent the point at
130  * the bottom left of the chevron, where the menu should be popped up.
131  * <code>widgetDefaultSelected</code> is not called.
132  * </p>
133  *
134  * @param listener the listener which should be notified when the control is selected by the user
135  *
136  * @exception IllegalArgumentException <ul>
137  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
138  * </ul>
139  * @exception SWTException <ul>
140  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
141  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
142  * </ul>
143  *
144  * @see SelectionListener
145  * @see #removeSelectionListener
146  * @see SelectionEvent
147  *
148  * @since 2.0
149  */
150 public void addSelectionListener(SelectionListener listener) {
151         checkWidget();
152         if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
153         TypedListener typedListener = new TypedListener (listener);
154         addListener (SWT.Selection,typedListener);
155         addListener (SWT.DefaultSelection,typedListener);
156 }
157
158 @Override
159 protected void checkSubclass () {
160         if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
161 }
162
163 /**
164  * Returns the preferred size of the receiver.
165  * <p>
166  * The <em>preferred size</em> of a <code>CoolItem</code> is the size that
167  * it would best be displayed at. The width hint and height hint arguments
168  * allow the caller to ask the instance questions such as "Given a particular
169  * width, how high does it need to be to show all of the contents?"
170  * To indicate that the caller does not wish to constrain a particular
171  * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
172  * </p>
173  *
174  * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
175  * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
176  * @return the preferred size
177  *
178  * @exception SWTException <ul>
179  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
180  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
181  * </ul>
182  *
183  * @see Layout
184  * @see #getBounds
185  * @see #getSize
186  * @see Control#getBorderWidth
187  * @see Scrollable#computeTrim
188  * @see Scrollable#getClientArea
189  */
190 public Point computeSize (int wHint, int hHint) {
191         checkWidget ();
192         wHint = (wHint != SWT.DEFAULT ? DPIUtil.autoScaleUp(wHint) : wHint);
193         hHint = (hHint != SWT.DEFAULT ? DPIUtil.autoScaleUp(hHint) : hHint);
194         return DPIUtil.autoScaleDown(computeSizeInPixels(wHint, hHint));
195 }
196 Point computeSizeInPixels (int wHint, int hHint) {
197         int index = parent.indexOf (this);
198         if (index == -1) return new Point (0, 0);
199         int width = wHint, height = hHint;
200         if (wHint == SWT.DEFAULT) width = 32;
201         if (hHint == SWT.DEFAULT) height = 32;
202         if ((parent.style & SWT.VERTICAL) != 0) {
203                 height += parent.getMargin (index);
204         } else {
205                 width += parent.getMargin (index);
206         }
207         return new Point (width, height);
208 }
209
210 @Override
211 void destroyWidget () {
212         parent.destroyItem (this);
213         releaseHandle ();
214 }
215
216 /**
217  * Returns a rectangle describing the receiver's size and location
218  * relative to its parent.
219  *
220  * @return the receiver's bounding rectangle
221  *
222  * @exception SWTException <ul>
223  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
224  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
225  * </ul>
226  */
227 public Rectangle getBounds () {
228         checkWidget ();
229         return DPIUtil.autoScaleDown(getBoundsInPixels());
230 }
231
232 Rectangle getBoundsInPixels () {
233         int index = parent.indexOf (this);
234         if (index == -1) return new Rectangle (0, 0, 0, 0);
235         long hwnd = parent.handle;
236         RECT rect = new RECT ();
237         OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
238         MARGINS margins = new MARGINS ();
239         OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
240         rect.left -= margins.cxLeftWidth;
241         rect.right += margins.cxRightWidth;
242         if (!parent.isLastItemOfRow (index)) {
243                 rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
244         }
245         int width = rect.right - rect.left;
246         int height = rect.bottom - rect.top;
247         if ((parent.style & SWT.VERTICAL) != 0) {
248                 return new Rectangle (rect.top, rect.left, height, width);
249         }
250         return new Rectangle (rect.left, rect.top, width, height);
251 }
252
253 Rectangle getClientArea () {
254         checkWidget ();
255         int index = parent.indexOf (this);
256         if (index == -1) return new Rectangle (0, 0, 0, 0);
257         long hwnd = parent.handle;
258         RECT insetRect = new RECT ();
259         OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, insetRect);
260         RECT rect = new RECT ();
261         OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
262         int x = rect.left + insetRect.left;
263         int y = rect.top;
264         int width = rect.right - rect.left - insetRect.left;
265         int height = rect.bottom - rect.top;
266         if ((parent.style & SWT.FLAT) == 0) {
267                 y += insetRect.top;
268                 width -= insetRect.right;
269                 height -= insetRect.top + insetRect.bottom;
270         }
271         if (index == 0) {
272                 REBARBANDINFO rbBand = new REBARBANDINFO ();
273                 rbBand.cbSize = REBARBANDINFO.sizeof;
274                 rbBand.fMask = OS.RBBIM_HEADERSIZE;
275                 OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
276                 width = width - rbBand.cxHeader + 1;
277         }
278         return new Rectangle (x, y, Math.max (0, width), Math.max (0, height));
279 }
280
281 /**
282  * Returns the control that is associated with the receiver.
283  *
284  * @return the control that is contained by the receiver
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 Control getControl () {
292         checkWidget ();
293         return control;
294 }
295
296 /**
297  * Returns the receiver's parent, which must be a <code>CoolBar</code>.
298  *
299  * @return the receiver's parent
300  *
301  * @exception SWTException <ul>
302  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
303  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
304  * </ul>
305  */
306 public CoolBar getParent () {
307         checkWidget ();
308         return parent;
309 }
310
311 @Override
312 void releaseHandle () {
313         super.releaseHandle ();
314         parent = null;
315         id = -1;
316         control = null;
317 }
318
319 /**
320  * Sets the control that is associated with the receiver
321  * to the argument.
322  *
323  * @param control the new control that will be contained by the receiver
324  *
325  * @exception IllegalArgumentException <ul>
326  *    <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
327  *    <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
328  * </ul>
329  * @exception SWTException <ul>
330  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
331  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
332  * </ul>
333  */
334 public void setControl (Control control) {
335         checkWidget ();
336         if (control != null) {
337                 if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
338                 if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
339         }
340         int index = parent.indexOf (this);
341         if (index == -1) return;
342         if (this.control != null && this.control.isDisposed ()) {
343                 this.control = null;
344         }
345         Control oldControl = this.control, newControl = control;
346         long hwnd = parent.handle;
347         long hwndChild = newControl != null ? control.topHandle () : 0;
348         REBARBANDINFO rbBand = new REBARBANDINFO ();
349         rbBand.cbSize = REBARBANDINFO.sizeof;
350         rbBand.fMask = OS.RBBIM_CHILD;
351         rbBand.hwndChild = hwndChild;
352         this.control = newControl;
353
354         /*
355         * Feature in Windows.  When Windows sets the rebar band child,
356         * it makes the new child visible and hides the old child and
357         * moves the new child to the top of the Z-order.  The fix is
358         * to save and restore the visibility and Z-order.
359         */
360         long hwndAbove = 0;
361         if (newControl != null) {
362                 hwndAbove = OS.GetWindow (hwndChild, OS.GW_HWNDPREV);
363         }
364         boolean hideNew = newControl != null && !newControl.getVisible ();
365         boolean showOld = oldControl != null && oldControl.getVisible ();
366         OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
367         if (hideNew) newControl.setVisible (false);
368         if (showOld) oldControl.setVisible (true);
369         if (hwndAbove != 0 && hwndAbove != hwndChild) {
370                 int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
371                 OS.SetWindowPos (hwndChild, hwndAbove, 0, 0, 0, 0, flags);
372         }
373 }
374
375 /**
376  * Returns a point describing the receiver's ideal size.
377  * The x coordinate of the result is the ideal width of the receiver.
378  * The y coordinate of the result is the ideal height of the receiver.
379  *
380  * @return the receiver's ideal size
381  *
382  * @exception SWTException <ul>
383  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
384  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
385  * </ul>
386  */
387 public Point getPreferredSize () {
388         checkWidget ();
389         return DPIUtil.autoScaleDown(getPreferredSizeInPixels());
390 }
391
392 Point getPreferredSizeInPixels () {
393         int index = parent.indexOf (this);
394         if (index == -1) return new Point (0, 0);
395         long hwnd = parent.handle;
396         REBARBANDINFO rbBand = new REBARBANDINFO ();
397         rbBand.cbSize = REBARBANDINFO.sizeof;
398         rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
399         OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
400         int width = rbBand.cxIdeal + parent.getMargin (index);
401         if ((parent.style & SWT.VERTICAL) != 0) {
402                 return new Point (rbBand.cyMaxChild, width);
403         }
404         return new Point (width, rbBand.cyMaxChild);
405 }
406
407 /**
408  * Sets the receiver's ideal size to the point specified by the arguments.
409  *
410  * @param width the new ideal width for the receiver
411  * @param height the new ideal height for the receiver
412  *
413  * @exception SWTException <ul>
414  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
415  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
416  * </ul>
417  */
418 public void setPreferredSize (int width, int height) {
419         checkWidget ();
420         setPreferredSizeInPixels(DPIUtil.autoScaleUp(width), DPIUtil.autoScaleUp(height));
421 }
422
423 void setPreferredSizeInPixels (int width, int height) {
424         int index = parent.indexOf (this);
425         if (index == -1) return;
426         width = Math.max (0, width);
427         height = Math.max (0, height);
428         ideal = true;
429         long hwnd = parent.handle;
430         int cxIdeal, cyMaxChild;
431         if ((parent.style & SWT.VERTICAL) != 0) {
432                 cxIdeal = Math.max (0, height - parent.getMargin (index));
433                 cyMaxChild = width;
434         } else {
435                 cxIdeal = Math.max (0, width - parent.getMargin (index));
436                 cyMaxChild = height;
437         }
438         REBARBANDINFO rbBand = new REBARBANDINFO ();
439         rbBand.cbSize = REBARBANDINFO.sizeof;
440
441         /* Get the child size fields first so we don't overwrite them. */
442         rbBand.fMask = OS.RBBIM_CHILDSIZE;
443         OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
444
445         /* Set the size fields we are currently modifying. */
446         rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
447         rbBand.cxIdeal = cxIdeal;
448         rbBand.cyMaxChild = cyMaxChild;
449         if (!minimum) rbBand.cyMinChild = cyMaxChild;
450         OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
451 }
452
453 /**
454  * Sets the receiver's ideal size to the point specified by the argument.
455  *
456  * @param size the new ideal size for the receiver
457  *
458  * @exception IllegalArgumentException <ul>
459  *    <li>ERROR_NULL_ARGUMENT - if the point is null</li>
460  * </ul>
461  * @exception SWTException <ul>
462  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
463  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
464  * </ul>
465  */
466 public void setPreferredSize (Point size) {
467         checkWidget ();
468         if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
469         size = DPIUtil.autoScaleUp(size);
470         setPreferredSizeInPixels(size.x, size.y);
471 }
472
473 /**
474  * Returns a point describing the receiver's size. The
475  * x coordinate of the result is the width of the receiver.
476  * The y coordinate of the result is the height of the
477  * receiver.
478  *
479  * @return the receiver's size
480  *
481  * @exception SWTException <ul>
482  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
483  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
484  * </ul>
485  */
486 public Point getSize () {
487         checkWidget ();
488         return DPIUtil.autoScaleDown(getSizeInPixels());
489 }
490
491 Point getSizeInPixels() {
492         int index = parent.indexOf (this);
493         if (index == -1) new Point (0, 0);
494         long hwnd = parent.handle;
495         RECT rect = new RECT ();
496         OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
497         MARGINS margins = new MARGINS ();
498         OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
499         rect.left -= margins.cxLeftWidth;
500         rect.right += margins.cxRightWidth;
501         if (!parent.isLastItemOfRow (index)) {
502                 rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
503         }
504         int width = rect.right - rect.left;
505         int height = rect.bottom - rect.top;
506         if ((parent.style & SWT.VERTICAL) != 0) {
507                 return new Point (height, width);
508         }
509         return new Point (width, height);
510 }
511
512 /**
513  * Sets the receiver's size to the point specified by the arguments.
514  * <p>
515  * Note: Attempting to set the width or height of the
516  * receiver to a negative number will cause that
517  * value to be set to zero instead.
518  * </p>
519  *
520  * @param width the new width for the receiver
521  * @param height the new height for the receiver
522  *
523  * @exception SWTException <ul>
524  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
525  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
526  * </ul>
527  */
528 public void setSize (int width, int height) {
529         checkWidget ();
530         setSizeInPixels(DPIUtil.autoScaleUp(width), DPIUtil.autoScaleUp(height));
531 }
532
533 void setSizeInPixels (int width, int height) {
534         int index = parent.indexOf (this);
535         if (index == -1) return;
536         width = Math.max (0, width);
537         height = Math.max (0, height);
538         long hwnd = parent.handle;
539         int cx, cyChild, cxIdeal;
540         if ((parent.style & SWT.VERTICAL) != 0) {
541                 cx = height;
542                 cyChild = width;
543                 cxIdeal = Math.max (0, height - parent.getMargin (index));
544         } else {
545                 cx = width;
546                 cyChild = height;
547                 cxIdeal = Math.max (0, width - parent.getMargin (index));
548         }
549         REBARBANDINFO rbBand = new REBARBANDINFO ();
550         rbBand.cbSize = REBARBANDINFO.sizeof;
551
552         /* Get the child size fields first so we don't overwrite them. */
553         rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
554         OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
555
556         /* Set the size fields we are currently modifying. */
557         if (!ideal) rbBand.cxIdeal = cxIdeal;
558         if (!minimum) rbBand.cyMinChild = cyChild;
559         rbBand.cyChild = cyChild;
560
561         /*
562         * Do not set the size for the last item on the row.
563         */
564         if (!parent.isLastItemOfRow (index)) {
565                 MARGINS margins = new MARGINS ();
566                 OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
567                 cx -= margins.cxLeftWidth + margins.cxRightWidth;
568                 int separator = (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
569                 rbBand.cx = cx - separator;
570                 rbBand.fMask |= OS.RBBIM_SIZE;
571         }
572         OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
573 }
574
575 /**
576  * Sets the receiver's size to the point specified by the argument.
577  * <p>
578  * Note: Attempting to set the width or height of the
579  * receiver to a negative number will cause them to be
580  * set to zero instead.
581  * </p>
582  *
583  * @param size the new size for the receiver
584  *
585  * @exception IllegalArgumentException <ul>
586  *    <li>ERROR_NULL_ARGUMENT - if the point is null</li>
587  * </ul>
588  * @exception SWTException <ul>
589  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
590  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
591  * </ul>
592  */
593 public void setSize (Point size) {
594         checkWidget ();
595         if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
596         size = DPIUtil.autoScaleUp(size);
597         setSizeInPixels(size.x, size.y);
598 }
599
600 /**
601  * Returns the minimum size that the cool item can
602  * be resized to using the cool item's gripper.
603  *
604  * @return a point containing the minimum width and height of the cool item, in SWT logical points
605  *
606  * @exception SWTException <ul>
607  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
608  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
609  * </ul>
610  *
611  * @since 2.0
612  */
613 public Point getMinimumSize () {
614         checkWidget ();
615         return DPIUtil.autoScaleDown(getMinimumSizeInPixels());
616 }
617
618 Point getMinimumSizeInPixels () {
619         int index = parent.indexOf (this);
620         if (index == -1) return new Point (0, 0);
621         long hwnd = parent.handle;
622         REBARBANDINFO rbBand = new REBARBANDINFO ();
623         rbBand.cbSize = REBARBANDINFO.sizeof;
624         rbBand.fMask = OS.RBBIM_CHILDSIZE;
625         OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
626         if ((parent.style & SWT.VERTICAL) != 0) {
627                 return new Point (rbBand.cyMinChild, rbBand.cxMinChild);
628         }
629         return new Point (rbBand.cxMinChild, rbBand.cyMinChild);
630 }
631
632 /**
633  * Sets the minimum size that the cool item can be resized to
634  * using the cool item's gripper, to the point specified by the arguments.
635  *
636  * @param width the minimum width of the cool item, in SWT logical points
637  * @param height the minimum height of the cool item, in SWT logical points
638  *
639  * @exception SWTException <ul>
640  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
641  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
642  * </ul>
643  *
644  * @since 2.0
645  */
646 public void setMinimumSize (int width, int height) {
647         checkWidget ();
648         setMinimumSizeInPixels(DPIUtil.autoScaleUp(width), DPIUtil.autoScaleUp(height));
649 }
650
651 void setMinimumSizeInPixels (int width, int height) {
652         int index = parent.indexOf (this);
653         if (index == -1) return;
654         width = Math.max (0, width);
655         height = Math.max (0, height);
656         minimum = true;
657         long hwnd = parent.handle;
658         int cxMinChild, cyMinChild;
659         if ((parent.style & SWT.VERTICAL) != 0) {
660                 cxMinChild = height;
661                 cyMinChild = width;
662         } else {
663                 cxMinChild = width;
664                 cyMinChild = height;
665         }
666         REBARBANDINFO rbBand = new REBARBANDINFO ();
667         rbBand.cbSize = REBARBANDINFO.sizeof;
668
669         /* Get the child size fields first so we don't overwrite them. */
670         rbBand.fMask = OS.RBBIM_CHILDSIZE;
671         OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
672
673         /* Set the size fields we are currently modifying. */
674         rbBand.cxMinChild = cxMinChild;
675         rbBand.cyMinChild = cyMinChild;
676         OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
677 }
678
679 /**
680  * Sets the minimum size that the cool item can be resized to
681  * using the cool item's gripper, to the point specified by the argument.
682  *
683  * @param size a point representing the minimum width and height of the cool item, in SWT logical points
684  *
685  * @exception IllegalArgumentException <ul>
686  *    <li>ERROR_NULL_ARGUMENT - if the point is null</li>
687  * </ul>
688  * @exception SWTException <ul>
689  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
690  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
691  * </ul>
692  *
693  * @since 2.0
694  */
695 public void setMinimumSize (Point size) {
696         checkWidget ();
697         if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
698         size = DPIUtil.autoScaleUp(size);
699         setMinimumSizeInPixels(size.x, size.y);
700 }
701
702 boolean getWrap() {
703         int index = parent.indexOf (this);
704         long hwnd = parent.handle;
705         REBARBANDINFO rbBand = new REBARBANDINFO ();
706         rbBand.cbSize = REBARBANDINFO.sizeof;
707         rbBand.fMask = OS.RBBIM_STYLE;
708         OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
709         return (rbBand.fStyle & OS.RBBS_BREAK) != 0;
710 }
711
712 void setWrap(boolean wrap) {
713         int index = parent.indexOf (this);
714         long hwnd = parent.handle;
715         REBARBANDINFO rbBand = new REBARBANDINFO ();
716         rbBand.cbSize = REBARBANDINFO.sizeof;
717         rbBand.fMask = OS.RBBIM_STYLE;
718         OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
719         if (wrap) {
720                 rbBand.fStyle |= OS.RBBS_BREAK;
721         } else {
722                 rbBand.fStyle &= ~OS.RBBS_BREAK;
723         }
724         OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
725 }
726
727 /**
728  * Removes the listener from the collection of listeners that
729  * will be notified when the control is selected by the user.
730  *
731  * @param listener the listener which should no longer be notified
732  *
733  * @exception IllegalArgumentException <ul>
734  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
735  * </ul>
736  * @exception SWTException <ul>
737  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
738  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
739  * </ul>
740  *
741  * @see SelectionListener
742  * @see #addSelectionListener
743  *
744  * @since 2.0
745  */
746 public void removeSelectionListener(SelectionListener listener) {
747         checkWidget();
748         if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
749         if (eventTable == null) return;
750         eventTable.unhook (SWT.Selection, listener);
751         eventTable.unhook (SWT.DefaultSelection,listener);
752 }
753
754 }