Mercurial > projects > dwt-mac
annotate dwt/widgets/ToolTip.d @ 151:0ba75290f8ce
Added a bunch of missing defaults to switch statements
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 10 Jun 2009 21:52:31 +0200 |
parents | 07399639c0c8 |
children |
rev | line source |
---|---|
45 | 1 /******************************************************************************* |
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 |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
10 * |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
11 * Port to the D programming language: |
45 | 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.ToolTip; |
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 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
17 import dwt.DWT; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
18 import dwt.DWTException; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
19 import dwt.events.SelectionEvent; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
20 import dwt.events.SelectionListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
21 import dwt.graphics.Color; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
22 import dwt.graphics.Font; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
23 import dwt.graphics.FontData; |
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.Point; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
27 import dwt.graphics.Rectangle; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
28 import dwt.graphics.Region; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
29 import dwt.graphics.TextLayout; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
30 import dwt.graphics.TextStyle; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
31 |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
32 import dwt.dwthelper.utils; |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
58
diff
changeset
|
33 import dwt.graphics.Device; |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
34 import dwt.widgets.Display; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
35 import dwt.widgets.Event; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
36 import dwt.widgets.Listener; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
37 import dwt.widgets.Shell; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
38 import dwt.widgets.TrayItem; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
39 import dwt.widgets.TypedListener; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
40 import dwt.widgets.Widget; |
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
41 |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
42 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
43 * Instances of this class represent popup windows that are used |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
44 * to inform or warn the user. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
45 * <p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
46 * <dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
47 * <dt><b>Styles:</b></dt> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
48 * <dd>BALLOON, ICON_ERROR, ICON_INFORMATION, ICON_WARNING</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
49 * <dt><b>Events:</b></dt> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
50 * <dd>Selection</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
51 * </dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
52 * </p><p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
53 * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
54 * and ICON_WARNING may be specified. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
55 * </p><p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
56 * IMPORTANT: This class is intended to be subclassed <em>only</em> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
57 * within the DWT implementation. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
58 * </p> |
45 | 59 * |
60 * @see <a href="http://www.eclipse.org/swt/snippets/#tooltips">Tool Tips snippets</a> | |
61 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | |
62 * @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
|
63 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
64 * @since 3.2 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
65 */ |
3 | 66 public class ToolTip : Widget { |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
67 Shell parent, tip; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
68 TrayItem item; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
69 int x, y; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
70 int [] borderPolygon; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
71 bool spikeAbove, autohide; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
72 Listener listener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
73 TextLayout layoutText, layoutMessage; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
74 Region region; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
75 Font boldFont; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
76 Runnable runnable; |
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 static final int BORDER = 5; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
79 static final int PADDING = 5; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
80 static final int INSET = 4; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
81 static final int TIP_HEIGHT = 20; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
82 static final int IMAGE_SIZE = 16; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
83 static final int DELAY = 10000; |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
84 |
123 | 85 /** |
86 * Constructs a new instance of this class given its parent | |
87 * and a style value describing its behavior and appearance. | |
88 * <p> | |
89 * The style value is either one of the style constants defined in | |
90 * class <code>DWT</code> which is applicable to instances of this | |
91 * class, or must be built by <em>bitwise OR</em>'ing together | |
92 * (that is, using the <code>int</code> "|" operator) two or more | |
93 * of those <code>DWT</code> style constants. The class description | |
94 * lists the style constants that are applicable to the class. | |
95 * Style bits are also inherited from superclasses. | |
96 * </p> | |
97 * | |
98 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
99 * @param style the style of control to construct | |
100 * | |
101 * @exception IllegalArgumentException <ul> | |
102 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
103 * </ul> | |
104 * @exception DWTException <ul> | |
105 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
106 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
107 * </ul> | |
108 * | |
109 * @see DWT#ICON_ERROR | |
110 * @see DWT#ICON_INFORMATION | |
111 * @see DWT#ICON_WARNING | |
112 * @see Widget#checkSubclass | |
113 * @see Widget#getStyle | |
114 */ | |
115 public this (Shell parent, int style) { | |
116 super (parent, checkStyle (style)); | |
117 this.parent = parent; | |
118 this.autohide = true; | |
119 x = y = -1; | |
120 Display display = getDisplay (); | |
121 tip = new Shell (parent, DWT.ON_TOP | DWT.NO_TRIM); | |
122 Color background = display.getSystemColor (DWT.COLOR_INFO_BACKGROUND); | |
123 tip.setBackground (background); | |
124 listener = new class Listener { | |
125 public void handleEvent (Event event) { | |
126 switch (event.type) { | |
127 case DWT.Dispose: onDispose (event); break; | |
128 case DWT.Paint: onPaint (event); break; | |
129 case DWT.MouseDown: onMouseDown (event); break; | |
130 default: | |
131 } | |
132 } | |
133 }; | |
134 addListener (DWT.Dispose, listener); | |
135 tip.addListener (DWT.Paint, listener); | |
136 tip.addListener (DWT.MouseDown, listener); | |
137 } | |
138 | |
139 static int checkStyle (int style) { | |
140 int mask = DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING; | |
141 if ((style & mask) is 0) return style; | |
142 return checkBits (style, DWT.ICON_INFORMATION, DWT.ICON_WARNING, DWT.ICON_ERROR, 0, 0, 0); | |
143 } | |
144 | |
145 /** | |
146 * Adds the listener to the collection of listeners who will | |
147 * be notified when the receiver is selected by the user, by sending | |
148 * it one of the messages defined in the <code>SelectionListener</code> | |
149 * interface. | |
150 * <p> | |
151 * <code>widgetSelected</code> is called when the receiver is selected. | |
152 * <code>widgetDefaultSelected</code> is not called. | |
153 * </p> | |
154 * | |
155 * @param listener the listener which should be notified when the receiver is selected by the user | |
156 * | |
157 * @exception IllegalArgumentException <ul> | |
158 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
159 * </ul> | |
160 * @exception DWTException <ul> | |
161 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
162 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
163 * </ul> | |
164 * | |
165 * @see SelectionListener | |
166 * @see #removeSelectionListener | |
167 * @see SelectionEvent | |
168 */ | |
169 public void addSelectionListener (SelectionListener listener) { | |
170 checkWidget (); | |
171 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
172 TypedListener typedListener = new TypedListener (listener); | |
173 addListener (DWT.Selection,typedListener); | |
174 addListener (DWT.DefaultSelection,typedListener); | |
175 } | |
176 | |
177 void configure () { | |
178 Display display = parent.getDisplay (); | |
179 int x = this.x; | |
180 int y = this.y; | |
181 if (x is -1 || y is -1) { | |
182 Point point; | |
183 if (item !is null) { | |
184 point = item.getLocation (); | |
185 } else { | |
186 point = display.getCursorLocation (); | |
187 } | |
188 x = point.x; | |
189 y = point.y; | |
190 } | |
191 dwt.widgets.Monitor.Monitor monitor = parent.getMonitor (); | |
192 Rectangle dest = monitor.getBounds (); | |
193 Point size = getSize (dest.width / 4); | |
194 int w = size.x; | |
195 int h = size.y; | |
196 int t = (style & DWT.BALLOON) !is 0 ? TIP_HEIGHT : 0; | |
197 int i = (style & DWT.BALLOON) !is 0 ? 16 : 0; | |
198 tip.setSize (w, h + t); | |
199 int [] polyline; | |
200 spikeAbove = dest.height >= y + size.y + t; | |
201 if (dest.width >= x + size.x) { | |
202 if (dest.height >= y + size.y + t) { | |
203 polyline = [ | |
204 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t, | |
205 16, t, 16, 0, 35, t, | |
206 w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t, | |
207 w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t, | |
208 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t, | |
209 0, 5+t]; | |
210 borderPolygon = [ | |
211 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t, | |
212 16, t, 16, 1, 35, t, | |
213 w-6, 0+t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t, | |
214 w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t, | |
215 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t, | |
216 0, 5+t]; | |
217 tip.setLocation (Math.max (0, x - i), y); | |
218 } else { | |
219 polyline = [ | |
220 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0, | |
221 w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5, | |
222 w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h, | |
223 35, h, 16, h+t, 16, h, | |
224 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5, | |
225 0, 5]; | |
226 borderPolygon = [ | |
227 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0, | |
228 w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5, | |
229 w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1, | |
230 36, h-1, 16, h+t-1, 16, h-1, | |
231 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6, | |
232 0, 5]; | |
233 tip.setLocation (Math.max (0, x - i), y - size.y - t); | |
234 } | |
235 } else { | |
236 if (dest.height >= y + size.y + t) { | |
237 polyline = [ | |
238 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t, | |
239 w-35, t, w-16, 0, w-16, t, | |
240 w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t, | |
241 w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t, | |
242 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t, | |
243 0, 5+t]; | |
244 borderPolygon = [ | |
245 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t, | |
246 w-35, t, w-17, 2, w-17, t, | |
247 w-6, t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t, | |
248 w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t, | |
249 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t, | |
250 0, 5+t]; | |
251 tip.setLocation (Math.min (dest.width - size.x, x - size.x + i), y); | |
252 } else { | |
253 polyline = [ | |
254 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0, | |
255 w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5, | |
256 w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h, | |
257 w-16, h, w-16, h+t, w-35, h, | |
258 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5, | |
259 0, 5]; | |
260 borderPolygon = [ | |
261 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0, | |
262 w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5, | |
263 w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1, | |
264 w-17, h-1, w-17, h+t-2, w-36, h-1, | |
265 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6, | |
266 0, 5]; | |
267 tip.setLocation (Math.min (dest.width - size.x, x - size.x + i), y - size.y - t); | |
268 } | |
269 } | |
270 if ((style & DWT.BALLOON) !is 0) { | |
271 if (region !is null) region.dispose (); | |
272 region = new Region (display); | |
273 region.add (polyline); | |
274 tip.setRegion (region); | |
275 } | |
276 } | |
277 | |
278 /** | |
279 * Returns <code>true</code> if the receiver is automatically | |
280 * hidden by the platform, and <code>false</code> otherwise. | |
281 * | |
282 * @return the receiver's auto hide state | |
283 * | |
284 * @exception DWTException <ul> | |
285 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
286 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
287 * </ul> | |
288 * | |
289 */ | |
290 public bool getAutoHide () { | |
291 checkWidget (); | |
292 return autohide; | |
293 } | |
294 | |
295 Point getSize (int maxWidth) { | |
296 int textWidth = 0, messageWidth = 0; | |
297 if (layoutText !is null) { | |
298 layoutText.setWidth (-1); | |
299 textWidth = layoutText.getBounds ().width; | |
300 } | |
301 if (layoutMessage !is null) { | |
302 layoutMessage.setWidth (-1); | |
303 messageWidth = layoutMessage.getBounds ().width; | |
304 } | |
305 int messageTrim = 2 * INSET + 2 * BORDER + 2 * PADDING; | |
306 bool hasImage = layoutText !is null && (style & DWT.BALLOON) !is 0 && (style & (DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING)) !is 0; | |
307 int textTrim = messageTrim + (hasImage ? IMAGE_SIZE : 0); | |
308 int width = Math.min (maxWidth, Math.max (textWidth + textTrim, messageWidth + messageTrim)); | |
309 int textHeight = 0, messageHeight = 0; | |
310 if (layoutText !is null) { | |
311 layoutText.setWidth (maxWidth - textTrim); | |
312 textHeight = layoutText.getBounds ().height; | |
313 } | |
314 if (layoutMessage !is null) { | |
315 layoutMessage.setWidth (maxWidth - messageTrim); | |
316 messageHeight = layoutMessage.getBounds ().height; | |
317 } | |
318 int height = 2 * BORDER + 2 * PADDING + messageHeight; | |
319 if (layoutText !is null) height += Math.max (IMAGE_SIZE, textHeight) + 2 * PADDING; | |
320 return new Point (width, height); | |
321 } | |
322 | |
323 /** | |
324 * Returns the receiver's message, which will be an empty | |
325 * string if it has never been set. | |
326 * | |
327 * @return the receiver's message | |
328 * | |
329 * @exception DWTException <ul> | |
330 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
331 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
332 * </ul> | |
333 */ | |
334 public String getMessage () { | |
335 checkWidget (); | |
336 return layoutMessage !is null ? layoutMessage.getText() : ""; | |
337 } | |
338 | |
339 /** | |
340 * Returns the receiver's parent, which must be a <code>Shell</code>. | |
341 * | |
342 * @return the receiver's parent | |
343 * | |
344 * @exception DWTException <ul> | |
345 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
346 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
347 * </ul> | |
348 */ | |
349 public Shell getParent () { | |
350 checkWidget (); | |
351 return parent; | |
352 } | |
353 | |
354 /** | |
355 * Returns the receiver's text, which will be an empty | |
356 * string if it has never been set. | |
357 * | |
358 * @return the receiver's text | |
359 * | |
360 * @exception DWTException <ul> | |
361 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
362 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
363 * </ul> | |
364 */ | |
365 public String getText () { | |
366 checkWidget (); | |
367 return layoutText !is null ? layoutText.getText() : ""; | |
368 } | |
369 | |
370 /** | |
371 * Returns <code>true</code> if the receiver is visible, and | |
372 * <code>false</code> otherwise. | |
373 * <p> | |
374 * If one of the receiver's ancestors is not visible or some | |
375 * other condition makes the receiver not visible, this method | |
376 * may still indicate that it is considered visible even though | |
377 * it may not actually be showing. | |
378 * </p> | |
379 * | |
380 * @return the receiver's visibility state | |
381 * | |
382 * @exception DWTException <ul> | |
383 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
384 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
385 * </ul> | |
386 */ | |
387 public bool getVisible () { | |
388 checkWidget (); | |
389 return tip.getVisible (); | |
390 } | |
391 | |
392 /** | |
393 * Returns <code>true</code> if the receiver is visible and all | |
394 * of the receiver's ancestors are visible and <code>false</code> | |
395 * otherwise. | |
396 * | |
397 * @return the receiver's visibility state | |
398 * | |
399 * @exception DWTException <ul> | |
400 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
401 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
402 * </ul> | |
403 * | |
404 * @see #getVisible | |
405 */ | |
406 public bool isVisible () { | |
407 checkWidget (); | |
408 return getVisible (); | |
409 } | |
410 | |
411 void onDispose (Event event) { | |
412 removeListener (DWT.Dispose, listener); | |
413 notifyListeners (DWT.Dispose, event); | |
414 event.type = DWT.None; | |
415 | |
416 if (runnable !is null) { | |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
417 Display display = getDisplay (); |
123 | 418 display.timerExec (-1, runnable); |
419 } | |
420 runnable = null; | |
421 tip.dispose (); | |
422 tip = null; | |
423 if (region !is null) region.dispose (); | |
424 region = null; | |
425 if (layoutText !is null) layoutText.dispose (); | |
426 layoutText = null; | |
427 if (layoutMessage !is null) layoutMessage.dispose (); | |
428 layoutMessage = null; | |
429 if (boldFont !is null) boldFont.dispose (); | |
430 boldFont = null; | |
431 borderPolygon = null; | |
432 } | |
433 | |
434 void onMouseDown (Event event) { | |
435 notifyListeners (DWT.Selection, new Event ()); | |
436 setVisible (false); | |
437 } | |
438 | |
439 void onPaint (Event event) { | |
440 GC gc = event.gc; | |
441 int x = BORDER + PADDING; | |
442 int y = BORDER + PADDING; | |
443 if ((style & DWT.BALLOON) !is 0) { | |
444 if (spikeAbove) y += TIP_HEIGHT; | |
445 gc.drawPolygon (borderPolygon); | |
446 } else { | |
447 Rectangle rect = tip.getClientArea (); | |
448 gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height -1); | |
449 } | |
450 if (layoutText !is null) { | |
451 int id = style & (DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING); | |
452 if ((style & DWT.BALLOON) !is 0 && id !is 0) { | |
453 Display display = getDisplay (); | |
454 Image image = display.getSystemImage (id); | |
455 Rectangle rect = image.getBounds (); | |
456 gc.drawImage (image, 0, 0, rect.width, rect.height, x, y, IMAGE_SIZE, IMAGE_SIZE); | |
457 x += IMAGE_SIZE; | |
458 } | |
459 x += INSET; | |
460 layoutText.draw (gc, x, y); | |
461 y += 2 * PADDING + Math.max (IMAGE_SIZE, layoutText.getBounds ().height); | |
462 } | |
463 if (layoutMessage !is null) { | |
464 x = BORDER + PADDING + INSET; | |
465 layoutMessage.draw (gc, x, y); | |
466 } | |
467 } | |
468 | |
469 /** | |
470 * Removes the listener from the collection of listeners who will | |
471 * be notified when the receiver is selected by the user. | |
472 * | |
473 * @param listener the listener which should no longer be notified | |
474 * | |
475 * @exception IllegalArgumentException <ul> | |
476 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
477 * </ul> | |
478 * @exception DWTException <ul> | |
479 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
480 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
481 * </ul> | |
482 * | |
483 * @see SelectionListener | |
484 * @see #addSelectionListener | |
485 */ | |
486 public void removeSelectionListener (SelectionListener listener) { | |
487 checkWidget(); | |
488 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
489 if (eventTable is null) return; | |
490 eventTable.unhook (DWT.Selection, listener); | |
491 eventTable.unhook (DWT.DefaultSelection,listener); | |
492 } | |
493 | |
494 /** | |
495 * Makes the receiver hide automatically when <code>true</code>, | |
496 * and remain visible when <code>false</code>. | |
497 * | |
498 * @param autoHide the auto hide state | |
499 * | |
500 * @exception DWTException <ul> | |
501 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
502 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
503 * </ul> | |
504 * | |
505 * @see #getVisible | |
506 * @see #setVisible | |
507 */ | |
508 public void setAutoHide (bool autohide) { | |
509 checkWidget (); | |
510 this.autohide = autohide; | |
511 //TODO - update when visible | |
512 } | |
513 | |
514 /** | |
515 * Sets the location of the receiver, which must be a tooltip, | |
516 * to the point specified by the arguments which are relative | |
517 * to the display. | |
518 * <p> | |
519 * Note that this is different from most widgets where the | |
520 * location of the widget is relative to the parent. | |
521 * </p> | |
522 * | |
523 * @param x the new x coordinate for the receiver | |
524 * @param y the new y coordinate for the receiver | |
525 * | |
526 * @exception DWTException <ul> | |
527 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
528 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
529 * </ul> | |
530 */ | |
531 public void setLocation (int x, int y) { | |
532 checkWidget (); | |
533 if (this.x is x && this.y is y) return; | |
534 this.x = x; | |
535 this.y = y; | |
536 if (tip.getVisible ()) configure (); | |
537 } | |
538 | |
539 /** | |
540 * Sets the location of the receiver, which must be a tooltip, | |
541 * to the point specified by the argument which is relative | |
542 * to the display. | |
543 * <p> | |
544 * Note that this is different from most widgets where the | |
545 * location of the widget is relative to the parent. | |
546 * </p><p> | |
547 * Note that the platform window manager ultimately has control | |
548 * over the location of tooltips. | |
549 * </p> | |
550 * | |
551 * @param location the new location for the receiver | |
552 * | |
553 * @exception IllegalArgumentException <ul> | |
554 * <li>ERROR_NULL_ARGUMENT - if the point is null</li> | |
555 * </ul> | |
556 * @exception DWTException <ul> | |
557 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
558 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
559 * </ul> | |
560 */ | |
561 public void setLocation (Point location) { | |
562 checkWidget (); | |
563 if (location is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
564 setLocation (location.x, location.y); | |
565 } | |
566 | |
567 /** | |
568 * Sets the receiver's message. | |
569 * | |
570 * @param string the new message | |
571 * | |
572 * @exception IllegalArgumentException <ul> | |
573 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
574 * </ul> | |
575 * @exception DWTException <ul> | |
576 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
577 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
578 * </ul> | |
579 */ | |
580 public void setMessage (String string) { | |
581 checkWidget (); | |
582 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
583 if (layoutMessage !is null) layoutMessage.dispose(); | |
584 layoutMessage = null; | |
585 if (string.length () !is 0) { | |
586 Display display = getDisplay (); | |
587 layoutMessage = new TextLayout (display); | |
588 layoutMessage.setText (string); | |
589 } | |
590 if (tip.getVisible ()) configure (); | |
591 } | |
592 | |
593 /** | |
594 * Sets the receiver's text. | |
595 * | |
596 * @param string the new text | |
597 * | |
598 * @exception IllegalArgumentException <ul> | |
599 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
600 * </ul> | |
601 * @exception DWTException <ul> | |
602 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
603 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
604 * </ul> | |
605 */ | |
606 public void setText (String string) { | |
607 checkWidget (); | |
608 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
609 if (layoutText !is null) layoutText.dispose (); | |
610 layoutText = null; | |
611 if (boldFont !is null) boldFont.dispose (); | |
612 boldFont = null; | |
613 if (string.length () !is 0) { | |
614 Display display = getDisplay (); | |
615 layoutText = new TextLayout (display); | |
616 layoutText.setText (string); | |
617 Font font = display.getSystemFont (); | |
618 FontData data = font.getFontData () [0]; | |
619 boldFont = new Font (cast(Device) display, data.getName (), data.getHeight (), DWT.BOLD); | |
620 TextStyle style = new TextStyle (boldFont, null, null); | |
621 layoutText.setStyle (style, 0, string.length ()); | |
622 } | |
623 if (tip.getVisible ()) configure (); | |
624 } | |
625 | |
626 /** | |
627 * Marks the receiver as visible if the argument is <code>true</code>, | |
628 * and marks it invisible otherwise. | |
629 * <p> | |
630 * If one of the receiver's ancestors is not visible or some | |
631 * other condition makes the receiver not visible, marking | |
632 * it visible may not actually cause it to be displayed. | |
633 * </p> | |
634 * | |
635 * @param visible the new visibility state | |
636 * | |
637 * @exception DWTException <ul> | |
638 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
639 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
640 * </ul> | |
641 */ | |
642 public void setVisible (bool visible) { | |
643 if (visible) configure (); | |
644 tip.setVisible (visible); | |
645 Display display = getDisplay (); | |
646 if (runnable !is null) display.timerExec (-1, runnable); | |
647 runnable = null; | |
648 if (autohide && visible) { | |
649 runnable = new class Runnable { | |
650 public void run () { | |
651 if (!isDisposed ()) setVisible (false); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
652 } |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
653 }; |
123 | 654 display.timerExec(DELAY, runnable); |
37
642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
36
diff
changeset
|
655 } |
123 | 656 } |
657 | |
658 } |