76
|
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 module dwt.widgets.CoolItem;
|
|
12
|
|
13
|
|
14
|
|
15 import dwt.DWT;
|
|
16 import dwt.DWTException;
|
|
17 import dwt.events.SelectionEvent;
|
|
18 import dwt.events.SelectionListener;
|
|
19 import dwt.graphics.Color;
|
|
20 import dwt.graphics.GC;
|
|
21 import dwt.graphics.Image;
|
|
22 import dwt.graphics.ImageData;
|
|
23 import dwt.graphics.PaletteData;
|
|
24 import dwt.graphics.Point;
|
|
25 import dwt.graphics.RGB;
|
|
26 import dwt.graphics.Rectangle;
|
|
27 import dwt.widgets.Item;
|
|
28 import dwt.widgets.Control;
|
|
29 import dwt.widgets.CoolBar;
|
|
30 import dwt.widgets.ToolBar;
|
|
31 import dwt.widgets.Event;
|
|
32 import dwt.widgets.TypedListener;
|
|
33 import dwt.widgets.ToolBar;
|
|
34 import dwt.widgets.ToolItem;
|
|
35 import dwt.widgets.Listener;
|
|
36
|
|
37 /**
|
|
38 * Instances of this class are selectable user interface
|
|
39 * objects that represent the dynamically positionable
|
|
40 * areas of a <code>CoolBar</code>.
|
|
41 * <dl>
|
|
42 * <dt><b>Styles:</b></dt>
|
|
43 * <dd>DROP_DOWN</dd>
|
|
44 * <dt><b>Events:</b></dt>
|
|
45 * <dd>Selection</dd>
|
|
46 * </dl>
|
|
47 * <p>
|
|
48 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
|
|
49 * </p>
|
|
50 */
|
|
51 public class CoolItem : Item {
|
|
52 Control control;
|
|
53 CoolBar parent;
|
|
54 bool ideal;
|
|
55 int preferredWidth, preferredHeight, minimumWidth, minimumHeight, requestedWidth;
|
|
56 Rectangle itemBounds;
|
|
57
|
|
58 static const int MARGIN_WIDTH = 4;
|
|
59 static const int GRABBER_WIDTH = 2;
|
|
60 static const int MINIMUM_WIDTH = (2 * MARGIN_WIDTH) + GRABBER_WIDTH;
|
|
61
|
|
62 private int CHEVRON_HORIZONTAL_TRIM = -1; //platform dependent values
|
|
63 private int CHEVRON_VERTICAL_TRIM = -1;
|
|
64 private static const int CHEVRON_LEFT_MARGIN = 2;
|
|
65 private static const int CHEVRON_IMAGE_WIDTH = 8; //Width to draw the double arrow
|
|
66
|
|
67 ToolBar chevron;
|
|
68 bool wrap;
|
|
69 Image arrowImage = null;
|
|
70
|
|
71 /**
|
|
72 * Constructs a new instance of this class given its parent
|
|
73 * (which must be a <code>CoolBar</code>) and a style value
|
|
74 * describing its behavior and appearance. The item is added
|
|
75 * to the end of the items maintained by its parent.
|
|
76 * <p>
|
|
77 * The style value is either one of the style constants defined in
|
|
78 * class <code>DWT</code> which is applicable to instances of this
|
|
79 * class, or must be built by <em>bitwise OR</em>'ing together
|
|
80 * (that is, using the <code>int</code> "|" operator) two or more
|
|
81 * of those <code>DWT</code> style constants. The class description
|
|
82 * lists the style constants that are applicable to the class.
|
|
83 * Style bits are also inherited from superclasses.
|
|
84 * </p>
|
|
85 *
|
|
86 * @param parent a composite control which will be the parent of the new instance (cannot be null)
|
|
87 * @param style the style of control to construct
|
|
88 *
|
|
89 * @exception IllegalArgumentException <ul>
|
|
90 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
|
|
91 * </ul>
|
|
92 * @exception DWTException <ul>
|
|
93 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
|
|
94 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
|
|
95 * </ul>
|
|
96 *
|
|
97 * @see DWT#DROP_DOWN
|
|
98 * @see Widget#checkSubclass
|
|
99 * @see Widget#getStyle
|
|
100 */
|
|
101 public this (CoolBar parent, int style) {
|
|
102 super(parent, style);
|
|
103 itemBounds = new Rectangle(0, 0, 0, 0);
|
|
104 this.parent = parent;
|
|
105 parent.createItem (this, parent.getItemCount());
|
|
106 calculateChevronTrim ();
|
|
107 }
|
|
108 /**
|
|
109 * Constructs a new instance of this class given its parent
|
|
110 * (which must be a <code>CoolBar</code>), a style value
|
|
111 * describing its behavior and appearance, and the index
|
|
112 * at which to place it in the items maintained by its parent.
|
|
113 * <p>
|
|
114 * The style value is either one of the style constants defined in
|
|
115 * class <code>DWT</code> which is applicable to instances of this
|
|
116 * class, or must be built by <em>bitwise OR</em>'ing together
|
|
117 * (that is, using the <code>int</code> "|" operator) two or more
|
|
118 * of those <code>DWT</code> style constants. The class description
|
|
119 * lists the style constants that are applicable to the class.
|
|
120 * Style bits are also inherited from superclasses.
|
|
121 * </p>
|
|
122 *
|
|
123 * @param parent a composite control which will be the parent of the new instance (cannot be null)
|
|
124 * @param style the style of control to construct
|
|
125 * @param index the zero-relative index at which to store the receiver in its parent
|
|
126 *
|
|
127 * @exception IllegalArgumentException <ul>
|
|
128 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
|
|
129 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
|
|
130 * </ul>
|
|
131 * @exception DWTException <ul>
|
|
132 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
|
|
133 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
|
|
134 * </ul>
|
|
135 *
|
|
136 * @see DWT#DROP_DOWN
|
|
137 * @see Widget#checkSubclass
|
|
138 * @see Widget#getStyle
|
|
139 */
|
|
140 public this (CoolBar parent, int style, int index) {
|
|
141 super(parent, style);
|
|
142 itemBounds = new Rectangle(0, 0, 0, 0);
|
|
143 this.parent = parent;
|
|
144 parent.createItem (this, index);
|
|
145 calculateChevronTrim ();
|
|
146 }
|
|
147 /**
|
|
148 * Adds the listener to the collection of listeners that will
|
|
149 * be notified when the control is selected by the user, by sending it one
|
|
150 * of the messages defined in the <code>SelectionListener</code>
|
|
151 * interface.
|
|
152 * <p>
|
|
153 * If <code>widgetSelected</code> is called when the mouse is over
|
|
154 * the drop-down arrow (or 'chevron') portion of the cool item,
|
|
155 * the event object detail field contains the value <code>DWT.ARROW</code>,
|
|
156 * and the x and y fields in the event object represent the point at
|
|
157 * the bottom left of the chevron, where the menu should be popped up.
|
|
158 * <code>widgetDefaultSelected</code> is not called.
|
|
159 * </p>
|
|
160 *
|
|
161 * @param listener the listener which should be notified when the control is selected by the user
|
|
162 *
|
|
163 * @exception IllegalArgumentException <ul>
|
|
164 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
165 * </ul>
|
|
166 * @exception DWTException <ul>
|
|
167 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
168 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
169 * </ul>
|
|
170 *
|
|
171 * @see SelectionListener
|
|
172 * @see #removeSelectionListener
|
|
173 * @see SelectionEvent
|
|
174 *
|
|
175 * @since 2.0
|
|
176 */
|
|
177 public void addSelectionListener(SelectionListener listener) {
|
|
178 checkWidget();
|
|
179 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
|
|
180 TypedListener typedListener = new TypedListener (listener);
|
|
181 addListener (DWT.Selection,typedListener);
|
|
182 addListener (DWT.DefaultSelection,typedListener);
|
|
183 }
|
|
184 protected void checkSubclass () {
|
|
185 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS);
|
|
186 }
|
|
187 /*
|
|
188 * Find the trim size of the Toolbar widget in the current platform.
|
|
189 */
|
|
190 void calculateChevronTrim () {
|
|
191 ToolBar tb = new ToolBar (parent, DWT.FLAT);
|
|
192 ToolItem ti = new ToolItem (tb, DWT.PUSH);
|
|
193 Image image = new Image (display, 1, 1);
|
|
194 ti.setImage (image);
|
|
195 Point size = tb.computeSize (DWT.DEFAULT, DWT.DEFAULT);
|
|
196 size = parent.fixPoint(size.x, size.y);
|
|
197 CHEVRON_HORIZONTAL_TRIM = size.x - 1;
|
|
198 CHEVRON_VERTICAL_TRIM = size.y - 1;
|
|
199 tb.dispose ();
|
|
200 ti.dispose ();
|
|
201 image.dispose ();
|
|
202 }
|
|
203 /**
|
|
204 * Returns the preferred size of the receiver.
|
|
205 * <p>
|
|
206 * The <em>preferred size</em> of a <code>CoolItem</code> is the size that
|
|
207 * it would best be displayed at. The width hint and height hint arguments
|
|
208 * allow the caller to ask the instance questions such as "Given a particular
|
|
209 * width, how high does it need to be to show all of the contents?"
|
|
210 * To indicate that the caller does not wish to constrain a particular
|
|
211 * dimension, the constant <code>DWT.DEFAULT</code> is passed for the hint.
|
|
212 * </p>
|
|
213 *
|
|
214 * @param wHint the width hint (can be <code>DWT.DEFAULT</code>)
|
|
215 * @param hHint the height hint (can be <code>DWT.DEFAULT</code>)
|
|
216 * @return the preferred size
|
|
217 *
|
|
218 * @exception DWTException <ul>
|
|
219 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
220 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
221 * </ul>
|
|
222 *
|
|
223 * @see Layout
|
|
224 * @see #getBounds
|
|
225 * @see #getSize
|
|
226 * @see Control#getBorderWidth
|
|
227 * @see Scrollable#computeTrim
|
|
228 * @see Scrollable#getClientArea
|
|
229 */
|
|
230 public Point computeSize (int wHint, int hHint) {
|
|
231 checkWidget();
|
|
232 int width = wHint, height = hHint;
|
|
233 if (wHint is DWT.DEFAULT) width = 32;
|
|
234 if (hHint is DWT.DEFAULT) height = 32;
|
|
235 if ((parent.style & DWT.VERTICAL) !is 0) {
|
|
236 height += MINIMUM_WIDTH;
|
|
237 } else {
|
|
238 width += MINIMUM_WIDTH;
|
|
239 }
|
|
240 return new Point (width, height);
|
|
241 }
|
|
242 public void dispose () {
|
|
243 if (isDisposed()) return;
|
|
244
|
|
245 /*
|
|
246 * Must call parent.destroyItem() before super.dispose(), since it needs to
|
|
247 * query the bounds to properly remove the item.
|
|
248 */
|
|
249 parent.destroyItem(this);
|
|
250 super.dispose ();
|
|
251 parent = null;
|
|
252 control = null;
|
|
253
|
|
254 /*
|
|
255 * Although the parent for the chevron is the CoolBar (CoolItem can not be the parent)
|
|
256 * it has to be disposed with the item
|
|
257 */
|
|
258 if (chevron !is null && !chevron.isDisposed()) chevron.dispose();
|
|
259 chevron = null;
|
|
260 if (arrowImage !is null && !arrowImage.isDisposed()) arrowImage.dispose();
|
|
261 arrowImage = null;
|
|
262 }
|
|
263
|
|
264 Image createArrowImage (int width, int height) {
|
|
265 Point point = parent.fixPoint(width, height);
|
|
266 width = point.x;
|
|
267 height = point.y;
|
|
268 Color foreground = parent.getForeground ();
|
|
269 Color black = display.getSystemColor (DWT.COLOR_BLACK);
|
|
270 Color background = parent.getBackground ();
|
|
271
|
|
272 PaletteData palette = new PaletteData ( [foreground.getRGB(), background.getRGB(), black.getRGB() ] );
|
|
273 ImageData imageData = new ImageData (width, height, 4, palette);
|
|
274 imageData.transparentPixel = 1;
|
|
275 Image image = new Image (display, imageData);
|
|
276
|
|
277 GC gc = new GC (image);
|
|
278 gc.setBackground (background);
|
|
279 gc.fillRectangle (0, 0, width, height);
|
|
280 gc.setForeground (black);
|
|
281
|
|
282 int startX = 0 ;
|
|
283 if ((parent.style & DWT.VERTICAL) !is 0) {
|
|
284 startX = width - CHEVRON_IMAGE_WIDTH;
|
|
285 }
|
|
286 int startY = height / 6;
|
|
287 int step = 2;
|
|
288 gc.drawLine (startX, startY, startX + step, startY + step);
|
|
289 gc.drawLine (startX, startY + (2 * step), startX + step, startY + step);
|
|
290 startX++;
|
|
291 gc.drawLine (startX, startY, startX + step, startY + step);
|
|
292 gc.drawLine (startX, startY + (2 * step), startX + step, startY + step);
|
|
293 startX += 3;
|
|
294 gc.drawLine (startX, startY, startX + step, startY + step);
|
|
295 gc.drawLine (startX, startY + (2 * step), startX + step, startY + step);
|
|
296 startX++;
|
|
297 gc.drawLine (startX, startY, startX + step, startY + step);
|
|
298 gc.drawLine (startX, startY + (2 * step), startX + step, startY + step);
|
|
299 gc.dispose ();
|
|
300 return image;
|
|
301 }
|
|
302 /**
|
|
303 * Returns a rectangle describing the receiver's size and location
|
|
304 * relative to its parent.
|
|
305 *
|
|
306 * @return the receiver's bounding rectangle
|
|
307 *
|
|
308 * @exception DWTException <ul>
|
|
309 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
310 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
311 * </ul>
|
|
312 */
|
|
313 public Rectangle getBounds () {
|
|
314 checkWidget();
|
|
315 return parent.fixRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
|
|
316 }
|
|
317 Rectangle internalGetBounds () {
|
|
318 return new Rectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
|
|
319 }
|
|
320 /**
|
|
321 * Returns the control that is associated with the receiver.
|
|
322 *
|
|
323 * @return the control that is contained by the receiver
|
|
324 *
|
|
325 * @exception DWTException <ul>
|
|
326 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
327 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
328 * </ul>
|
|
329 */
|
|
330 public Control getControl () {
|
|
331 checkWidget();
|
|
332 return control;
|
|
333 }
|
|
334 /**
|
|
335 * Returns the minimum size that the cool item can
|
|
336 * be resized to using the cool item's gripper.
|
|
337 *
|
|
338 * @return a point containing the minimum width and height of the cool item, in pixels
|
|
339 *
|
|
340 * @exception DWTException <ul>
|
|
341 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
342 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
343 * </ul>
|
|
344 *
|
|
345 * @since 2.0
|
|
346 */
|
|
347 public Point getMinimumSize () {
|
|
348 checkWidget();
|
|
349 return parent.fixPoint(minimumWidth, minimumHeight);
|
|
350 }
|
|
351 /**
|
|
352 * Returns the receiver's parent, which must be a <code>CoolBar</code>.
|
|
353 *
|
|
354 * @return the receiver's parent
|
|
355 *
|
|
356 * @exception DWTException <ul>
|
|
357 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
358 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
359 * </ul>
|
|
360 */
|
|
361 public CoolBar getParent () {
|
|
362 checkWidget();
|
|
363 return parent;
|
|
364 }
|
|
365 /**
|
|
366 * Returns a point describing the receiver's ideal size.
|
|
367 * The x coordinate of the result is the ideal width of the receiver.
|
|
368 * The y coordinate of the result is the ideal height of the receiver.
|
|
369 *
|
|
370 * @return the receiver's ideal size
|
|
371 *
|
|
372 * @exception DWTException <ul>
|
|
373 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
374 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
375 * </ul>
|
|
376 */
|
|
377 public Point getPreferredSize () {
|
|
378 checkWidget();
|
|
379 return parent.fixPoint(preferredWidth, preferredHeight);
|
|
380 }
|
|
381 /**
|
|
382 * Returns a point describing the receiver's size. The
|
|
383 * x coordinate of the result is the width of the receiver.
|
|
384 * The y coordinate of the result is the height of the
|
|
385 * receiver.
|
|
386 *
|
|
387 * @return the receiver's size
|
|
388 *
|
|
389 * @exception DWTException <ul>
|
|
390 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
391 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
392 * </ul>
|
|
393 */
|
|
394 public Point getSize () {
|
|
395 checkWidget();
|
|
396 return parent.fixPoint(itemBounds.width, itemBounds.height);
|
|
397 }
|
|
398 int internalGetMinimumWidth () {
|
|
399 int width = minimumWidth + MINIMUM_WIDTH;
|
|
400 if ((style & DWT.DROP_DOWN) !is 0 && width < preferredWidth) {
|
|
401 width += CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
|
|
402 }
|
|
403 return width;
|
|
404 }
|
|
405 /*
|
|
406 * Called when the chevron is selected.
|
|
407 */
|
|
408 void onSelection (Event ev) {
|
|
409 Rectangle bounds = chevron.getBounds();
|
|
410 Event event = new Event();
|
|
411 event.detail = DWT.ARROW;
|
|
412 if ((parent.style & DWT.VERTICAL) !is 0) {
|
|
413 event.x = bounds.x + bounds.width;
|
|
414 event.y = bounds.y;
|
|
415 } else {
|
|
416 event.x = bounds.x;
|
|
417 event.y = bounds.y + bounds.height;
|
|
418 }
|
|
419 postEvent (DWT.Selection, event);
|
|
420 }
|
|
421 /**
|
|
422 * Removes the listener from the collection of listeners that
|
|
423 * will be notified when the control is selected by the user.
|
|
424 *
|
|
425 * @param listener the listener which should no longer be notified
|
|
426 *
|
|
427 * @exception IllegalArgumentException <ul>
|
|
428 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
429 * </ul>
|
|
430 * @exception DWTException <ul>
|
|
431 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
432 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
433 * </ul>
|
|
434 *
|
|
435 * @see SelectionListener
|
|
436 * @see #addSelectionListener
|
|
437 *
|
|
438 * @since 2.0
|
|
439 */
|
|
440 public void removeSelectionListener(SelectionListener listener) {
|
|
441 checkWidget();
|
|
442 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
|
|
443 if (eventTable is null) return;
|
|
444 eventTable.unhook (DWT.Selection, listener);
|
|
445 eventTable.unhook (DWT.DefaultSelection,listener);
|
|
446 }
|
|
447 void setBounds (int x, int y, int width, int height) {
|
|
448 itemBounds.x = x;
|
|
449 itemBounds.y = y;
|
|
450 itemBounds.width = width;
|
|
451 itemBounds.height = height;
|
|
452 if (control !is null) {
|
|
453 int controlWidth = width - MINIMUM_WIDTH;
|
|
454 if ((style & DWT.DROP_DOWN) !is 0 && width < preferredWidth) {
|
|
455 controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
|
|
456 }
|
|
457 control.setBounds (parent.fixRectangle(x + MINIMUM_WIDTH, y, controlWidth, height));
|
|
458 }
|
|
459 updateChevron();
|
|
460 }
|
|
461 /**
|
|
462 * Sets the control that is associated with the receiver
|
|
463 * to the argument.
|
|
464 *
|
|
465 * @param control the new control that will be contained by the receiver
|
|
466 *
|
|
467 * @exception IllegalArgumentException <ul>
|
|
468 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
|
|
469 * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
|
|
470 * </ul>
|
|
471 * @exception DWTException <ul>
|
|
472 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
473 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
474 * </ul>
|
|
475 */
|
|
476 public void setControl (Control control) {
|
|
477 checkWidget();
|
|
478 if (control !is null) {
|
|
479 if (control.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
|
|
480 if (control.parent !is parent) error (DWT.ERROR_INVALID_PARENT);
|
|
481 }
|
|
482 this.control = control;
|
|
483 if (control !is null) {
|
|
484 int controlWidth = itemBounds.width - MINIMUM_WIDTH;
|
|
485 if ((style & DWT.DROP_DOWN) !is 0 && itemBounds.width < preferredWidth) {
|
|
486 controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
|
|
487 }
|
|
488 control.setBounds (parent.fixRectangle(itemBounds.x + MINIMUM_WIDTH, itemBounds.y, controlWidth, itemBounds.height));
|
|
489 }
|
|
490 }
|
|
491 /**
|
|
492 * Sets the minimum size that the cool item can be resized to
|
|
493 * using the cool item's gripper, to the point specified by the arguments.
|
|
494 *
|
|
495 * @param width the minimum width of the cool item, in pixels
|
|
496 * @param height the minimum height of the cool item, in pixels
|
|
497 *
|
|
498 * @exception DWTException <ul>
|
|
499 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
500 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
501 * </ul>
|
|
502 *
|
|
503 * @since 2.0
|
|
504 */
|
|
505 public void setMinimumSize (int width, int height) {
|
|
506 checkWidget ();
|
|
507 Point point = parent.fixPoint(width, height);
|
|
508 minimumWidth = point.x;
|
|
509 minimumHeight = point.y;
|
|
510 }
|
|
511 /**
|
|
512 * Sets the minimum size that the cool item can be resized to
|
|
513 * using the cool item's gripper, to the point specified by the argument.
|
|
514 *
|
|
515 * @param size a point representing the minimum width and height of the cool item, in pixels
|
|
516 *
|
|
517 * @exception IllegalArgumentException <ul>
|
|
518 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
|
|
519 * </ul>
|
|
520 * @exception DWTException <ul>
|
|
521 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
522 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
523 * </ul>
|
|
524 *
|
|
525 * @since 2.0
|
|
526 */
|
|
527 public void setMinimumSize (Point size) {
|
|
528 checkWidget ();
|
|
529 if (size is null) error(DWT.ERROR_NULL_ARGUMENT);
|
|
530 setMinimumSize(size.x, size.y);
|
|
531 }
|
|
532 /**
|
|
533 * Sets the receiver's ideal size to the point specified by the arguments.
|
|
534 *
|
|
535 * @param width the new ideal width for the receiver
|
|
536 * @param height the new ideal height for the receiver
|
|
537 *
|
|
538 * @exception DWTException <ul>
|
|
539 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
540 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
541 * </ul>
|
|
542 */
|
|
543 public void setPreferredSize (int width, int height) {
|
|
544 checkWidget();
|
|
545 ideal = true;
|
|
546 Point point = parent.fixPoint(width, height);
|
|
547 preferredWidth = Math.max (point.x, MINIMUM_WIDTH);
|
|
548 preferredHeight = point.y;
|
|
549 }
|
|
550 /**
|
|
551 * Sets the receiver's ideal size to the point specified by the argument.
|
|
552 *
|
|
553 * @param size the new ideal size for the receiver
|
|
554 *
|
|
555 * @exception IllegalArgumentException <ul>
|
|
556 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
|
|
557 * </ul>
|
|
558 * @exception DWTException <ul>
|
|
559 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
560 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
561 * </ul>
|
|
562 */
|
|
563 public void setPreferredSize (Point size) {
|
|
564 checkWidget();
|
|
565 if (size is null) error(DWT.ERROR_NULL_ARGUMENT);
|
|
566 setPreferredSize(size.x, size.y);
|
|
567 }
|
|
568 /**
|
|
569 * Sets the receiver's size to the point specified by the arguments.
|
|
570 * <p>
|
|
571 * Note: Attempting to set the width or height of the
|
|
572 * receiver to a negative number will cause that
|
|
573 * value to be set to zero instead.
|
|
574 * </p>
|
|
575 *
|
|
576 * @param width the new width for the receiver
|
|
577 * @param height the new height for the receiver
|
|
578 *
|
|
579 * @exception DWTException <ul>
|
|
580 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
581 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
582 * </ul>
|
|
583 */
|
|
584 public void setSize (int width, int height) {
|
|
585 checkWidget();
|
|
586 Point point = parent.fixPoint(width, height);
|
|
587 width = Math.max(point.x, minimumWidth + MINIMUM_WIDTH);
|
|
588 height = point.y;
|
|
589 if (!ideal) {
|
|
590 preferredWidth = width;
|
|
591 preferredHeight = height;
|
|
592 }
|
|
593 itemBounds.width = requestedWidth = width;
|
|
594 itemBounds.height = height;
|
|
595 if (control !is null) {
|
|
596 int controlWidth = width - MINIMUM_WIDTH;
|
|
597 if ((style & DWT.DROP_DOWN) !is 0 && width < preferredWidth) {
|
|
598 controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
|
|
599 }
|
|
600 control.setSize(parent.fixPoint(controlWidth, height));
|
|
601 }
|
|
602 parent.relayout();
|
|
603 updateChevron();
|
|
604 }
|
|
605 /**
|
|
606 * Sets the receiver's size to the point specified by the argument.
|
|
607 * <p>
|
|
608 * Note: Attempting to set the width or height of the
|
|
609 * receiver to a negative number will cause them to be
|
|
610 * set to zero instead.
|
|
611 * </p>
|
|
612 *
|
|
613 * @param size the new size for the receiver
|
|
614 *
|
|
615 * @exception IllegalArgumentException <ul>
|
|
616 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
|
|
617 * </ul>
|
|
618 * @exception DWTException <ul>
|
|
619 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
620 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
621 * </ul>
|
|
622 */
|
|
623 public void setSize (Point size) {
|
|
624 checkWidget();
|
|
625 if (size is null) error (DWT.ERROR_NULL_ARGUMENT);
|
|
626 setSize (size.x, size.y);
|
|
627 }
|
|
628 void updateChevron() {
|
|
629 if (control !is null) {
|
|
630 int width = itemBounds.width;
|
|
631 if ((style & DWT.DROP_DOWN) !is 0 && width < preferredWidth) {
|
|
632 if (chevron is null) {
|
|
633 chevron = new ToolBar (parent, DWT.FLAT | DWT.NO_FOCUS);
|
|
634 ToolItem toolItem = new ToolItem (chevron, DWT.PUSH);
|
|
635 toolItem.addListener (DWT.Selection, new class () Listener {
|
|
636 public void handleEvent (Event event) {
|
|
637 this.outer.onSelection (event);
|
|
638 }
|
|
639 });
|
|
640 }
|
|
641 int controlHeight, currentImageHeight = 0;
|
|
642 if ((parent.style & DWT.VERTICAL) !is 0) {
|
|
643 controlHeight = control.getSize ().x;
|
|
644 if (arrowImage !is null) currentImageHeight = arrowImage.getBounds().width;
|
|
645 } else {
|
|
646 controlHeight = control.getSize ().y;
|
|
647 if (arrowImage !is null) currentImageHeight = arrowImage.getBounds().height;
|
|
648 }
|
|
649 int height = Math.min (controlHeight, itemBounds.height);
|
|
650 int imageHeight = Math.max(1, height - CHEVRON_VERTICAL_TRIM);
|
|
651 if (currentImageHeight !is imageHeight) {
|
|
652 Image image = createArrowImage (CHEVRON_IMAGE_WIDTH, imageHeight);
|
|
653 chevron.getItem (0).setImage (image);
|
|
654 if (arrowImage !is null) arrowImage.dispose ();
|
|
655 arrowImage = image;
|
|
656 }
|
|
657 chevron.setBackground (parent.getBackground());
|
|
658 chevron.setBounds (parent.fixRectangle (
|
|
659 itemBounds.x + width - CHEVRON_LEFT_MARGIN - CHEVRON_IMAGE_WIDTH - CHEVRON_HORIZONTAL_TRIM,
|
|
660 itemBounds.y,
|
|
661 CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM,
|
|
662 height));
|
|
663 chevron.setVisible(true);
|
|
664 } else {
|
|
665 if (chevron !is null) {
|
|
666 chevron.setVisible(false);
|
|
667 }
|
|
668 }
|
|
669 }
|
|
670 }
|
|
671 }
|