annotate dwt/widgets/CoolItem.d @ 90:c7f7f4d7091a

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