Mercurial > projects > dwt-mac
annotate dwt/widgets/ToolTip.d @ 128:07399639c0c8
Added DWT extension to dwt.widgets.MessageBox
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 17 Jan 2009 16:26:49 +0100 |
parents | 63a09873578e |
children | 0ba75290f8ce |
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 assert(false); | |
132 } | |
133 } | |
134 }; | |
135 addListener (DWT.Dispose, listener); | |
136 tip.addListener (DWT.Paint, listener); | |
137 tip.addListener (DWT.MouseDown, listener); | |
138 } | |
139 | |
140 static int checkStyle (int style) { | |
141 int mask = DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING; | |
142 if ((style & mask) is 0) return style; | |
143 return checkBits (style, DWT.ICON_INFORMATION, DWT.ICON_WARNING, DWT.ICON_ERROR, 0, 0, 0); | |
144 } | |
145 | |
146 /** | |
147 * Adds the listener to the collection of listeners who will | |
148 * be notified when the receiver is selected by the user, by sending | |
149 * it one of the messages defined in the <code>SelectionListener</code> | |
150 * interface. | |
151 * <p> | |
152 * <code>widgetSelected</code> is called when the receiver is selected. | |
153 * <code>widgetDefaultSelected</code> is not called. | |
154 * </p> | |
155 * | |
156 * @param listener the listener which should be notified when the receiver is selected by the user | |
157 * | |
158 * @exception IllegalArgumentException <ul> | |
159 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
160 * </ul> | |
161 * @exception DWTException <ul> | |
162 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
163 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
164 * </ul> | |
165 * | |
166 * @see SelectionListener | |
167 * @see #removeSelectionListener | |
168 * @see SelectionEvent | |
169 */ | |
170 public void addSelectionListener (SelectionListener listener) { | |
171 checkWidget (); | |
172 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
173 TypedListener typedListener = new TypedListener (listener); | |
174 addListener (DWT.Selection,typedListener); | |
175 addListener (DWT.DefaultSelection,typedListener); | |
176 } | |
177 | |
178 void configure () { | |
179 Display display = parent.getDisplay (); | |
180 int x = this.x; | |
181 int y = this.y; | |
182 if (x is -1 || y is -1) { | |
183 Point point; | |
184 if (item !is null) { | |
185 point = item.getLocation (); | |
186 } else { | |
187 point = display.getCursorLocation (); | |
188 } | |
189 x = point.x; | |
190 y = point.y; | |
191 } | |
192 dwt.widgets.Monitor.Monitor monitor = parent.getMonitor (); | |
193 Rectangle dest = monitor.getBounds (); | |
194 Point size = getSize (dest.width / 4); | |
195 int w = size.x; | |
196 int h = size.y; | |
197 int t = (style & DWT.BALLOON) !is 0 ? TIP_HEIGHT : 0; | |
198 int i = (style & DWT.BALLOON) !is 0 ? 16 : 0; | |
199 tip.setSize (w, h + t); | |
200 int [] polyline; | |
201 spikeAbove = dest.height >= y + size.y + t; | |
202 if (dest.width >= x + size.x) { | |
203 if (dest.height >= y + size.y + t) { | |
204 polyline = [ | |
205 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t, | |
206 16, t, 16, 0, 35, t, | |
207 w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t, | |
208 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, | |
209 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, | |
210 0, 5+t]; | |
211 borderPolygon = [ | |
212 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t, | |
213 16, t, 16, 1, 35, t, | |
214 w-6, 0+t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t, | |
215 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, | |
216 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t, | |
217 0, 5+t]; | |
218 tip.setLocation (Math.max (0, x - i), y); | |
219 } else { | |
220 polyline = [ | |
221 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0, | |
222 w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5, | |
223 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, | |
224 35, h, 16, h+t, 16, h, | |
225 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, | |
226 0, 5]; | |
227 borderPolygon = [ | |
228 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0, | |
229 w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5, | |
230 w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1, | |
231 36, h-1, 16, h+t-1, 16, h-1, | |
232 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6, | |
233 0, 5]; | |
234 tip.setLocation (Math.max (0, x - i), y - size.y - t); | |
235 } | |
236 } else { | |
237 if (dest.height >= y + size.y + t) { | |
238 polyline = [ | |
239 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t, | |
240 w-35, t, w-16, 0, w-16, t, | |
241 w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t, | |
242 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, | |
243 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, | |
244 0, 5+t]; | |
245 borderPolygon = [ | |
246 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t, | |
247 w-35, t, w-17, 2, w-17, t, | |
248 w-6, t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t, | |
249 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, | |
250 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t, | |
251 0, 5+t]; | |
252 tip.setLocation (Math.min (dest.width - size.x, x - size.x + i), y); | |
253 } else { | |
254 polyline = [ | |
255 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0, | |
256 w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5, | |
257 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, | |
258 w-16, h, w-16, h+t, w-35, h, | |
259 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, | |
260 0, 5]; | |
261 borderPolygon = [ | |
262 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0, | |
263 w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5, | |
264 w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1, | |
265 w-17, h-1, w-17, h+t-2, w-36, h-1, | |
266 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6, | |
267 0, 5]; | |
268 tip.setLocation (Math.min (dest.width - size.x, x - size.x + i), y - size.y - t); | |
269 } | |
270 } | |
271 if ((style & DWT.BALLOON) !is 0) { | |
272 if (region !is null) region.dispose (); | |
273 region = new Region (display); | |
274 region.add (polyline); | |
275 tip.setRegion (region); | |
276 } | |
277 } | |
278 | |
279 /** | |
280 * Returns <code>true</code> if the receiver is automatically | |
281 * hidden by the platform, and <code>false</code> otherwise. | |
282 * | |
283 * @return the receiver's auto hide state | |
284 * | |
285 * @exception DWTException <ul> | |
286 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
287 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
288 * </ul> | |
289 * | |
290 */ | |
291 public bool getAutoHide () { | |
292 checkWidget (); | |
293 return autohide; | |
294 } | |
295 | |
296 Point getSize (int maxWidth) { | |
297 int textWidth = 0, messageWidth = 0; | |
298 if (layoutText !is null) { | |
299 layoutText.setWidth (-1); | |
300 textWidth = layoutText.getBounds ().width; | |
301 } | |
302 if (layoutMessage !is null) { | |
303 layoutMessage.setWidth (-1); | |
304 messageWidth = layoutMessage.getBounds ().width; | |
305 } | |
306 int messageTrim = 2 * INSET + 2 * BORDER + 2 * PADDING; | |
307 bool hasImage = layoutText !is null && (style & DWT.BALLOON) !is 0 && (style & (DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING)) !is 0; | |
308 int textTrim = messageTrim + (hasImage ? IMAGE_SIZE : 0); | |
309 int width = Math.min (maxWidth, Math.max (textWidth + textTrim, messageWidth + messageTrim)); | |
310 int textHeight = 0, messageHeight = 0; | |
311 if (layoutText !is null) { | |
312 layoutText.setWidth (maxWidth - textTrim); | |
313 textHeight = layoutText.getBounds ().height; | |
314 } | |
315 if (layoutMessage !is null) { | |
316 layoutMessage.setWidth (maxWidth - messageTrim); | |
317 messageHeight = layoutMessage.getBounds ().height; | |
318 } | |
319 int height = 2 * BORDER + 2 * PADDING + messageHeight; | |
320 if (layoutText !is null) height += Math.max (IMAGE_SIZE, textHeight) + 2 * PADDING; | |
321 return new Point (width, height); | |
322 } | |
323 | |
324 /** | |
325 * Returns the receiver's message, which will be an empty | |
326 * string if it has never been set. | |
327 * | |
328 * @return the receiver's message | |
329 * | |
330 * @exception DWTException <ul> | |
331 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
332 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
333 * </ul> | |
334 */ | |
335 public String getMessage () { | |
336 checkWidget (); | |
337 return layoutMessage !is null ? layoutMessage.getText() : ""; | |
338 } | |
339 | |
340 /** | |
341 * Returns the receiver's parent, which must be a <code>Shell</code>. | |
342 * | |
343 * @return the receiver's parent | |
344 * | |
345 * @exception DWTException <ul> | |
346 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
347 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
348 * </ul> | |
349 */ | |
350 public Shell getParent () { | |
351 checkWidget (); | |
352 return parent; | |
353 } | |
354 | |
355 /** | |
356 * Returns the receiver's text, which will be an empty | |
357 * string if it has never been set. | |
358 * | |
359 * @return the receiver's text | |
360 * | |
361 * @exception DWTException <ul> | |
362 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
363 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
364 * </ul> | |
365 */ | |
366 public String getText () { | |
367 checkWidget (); | |
368 return layoutText !is null ? layoutText.getText() : ""; | |
369 } | |
370 | |
371 /** | |
372 * Returns <code>true</code> if the receiver is visible, and | |
373 * <code>false</code> otherwise. | |
374 * <p> | |
375 * If one of the receiver's ancestors is not visible or some | |
376 * other condition makes the receiver not visible, this method | |
377 * may still indicate that it is considered visible even though | |
378 * it may not actually be showing. | |
379 * </p> | |
380 * | |
381 * @return the receiver's visibility state | |
382 * | |
383 * @exception DWTException <ul> | |
384 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
385 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
386 * </ul> | |
387 */ | |
388 public bool getVisible () { | |
389 checkWidget (); | |
390 return tip.getVisible (); | |
391 } | |
392 | |
393 /** | |
394 * Returns <code>true</code> if the receiver is visible and all | |
395 * of the receiver's ancestors are visible and <code>false</code> | |
396 * otherwise. | |
397 * | |
398 * @return the receiver's visibility state | |
399 * | |
400 * @exception DWTException <ul> | |
401 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
402 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
403 * </ul> | |
404 * | |
405 * @see #getVisible | |
406 */ | |
407 public bool isVisible () { | |
408 checkWidget (); | |
409 return getVisible (); | |
410 } | |
411 | |
412 void onDispose (Event event) { | |
413 removeListener (DWT.Dispose, listener); | |
414 notifyListeners (DWT.Dispose, event); | |
415 event.type = DWT.None; | |
416 | |
417 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
|
418 Display display = getDisplay (); |
123 | 419 display.timerExec (-1, runnable); |
420 } | |
421 runnable = null; | |
422 tip.dispose (); | |
423 tip = null; | |
424 if (region !is null) region.dispose (); | |
425 region = null; | |
426 if (layoutText !is null) layoutText.dispose (); | |
427 layoutText = null; | |
428 if (layoutMessage !is null) layoutMessage.dispose (); | |
429 layoutMessage = null; | |
430 if (boldFont !is null) boldFont.dispose (); | |
431 boldFont = null; | |
432 borderPolygon = null; | |
433 } | |
434 | |
435 void onMouseDown (Event event) { | |
436 notifyListeners (DWT.Selection, new Event ()); | |
437 setVisible (false); | |
438 } | |
439 | |
440 void onPaint (Event event) { | |
441 GC gc = event.gc; | |
442 int x = BORDER + PADDING; | |
443 int y = BORDER + PADDING; | |
444 if ((style & DWT.BALLOON) !is 0) { | |
445 if (spikeAbove) y += TIP_HEIGHT; | |
446 gc.drawPolygon (borderPolygon); | |
447 } else { | |
448 Rectangle rect = tip.getClientArea (); | |
449 gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height -1); | |
450 } | |
451 if (layoutText !is null) { | |
452 int id = style & (DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING); | |
453 if ((style & DWT.BALLOON) !is 0 && id !is 0) { | |
454 Display display = getDisplay (); | |
455 Image image = display.getSystemImage (id); | |
456 Rectangle rect = image.getBounds (); | |
457 gc.drawImage (image, 0, 0, rect.width, rect.height, x, y, IMAGE_SIZE, IMAGE_SIZE); | |
458 x += IMAGE_SIZE; | |
459 } | |
460 x += INSET; | |
461 layoutText.draw (gc, x, y); | |
462 y += 2 * PADDING + Math.max (IMAGE_SIZE, layoutText.getBounds ().height); | |
463 } | |
464 if (layoutMessage !is null) { | |
465 x = BORDER + PADDING + INSET; | |
466 layoutMessage.draw (gc, x, y); | |
467 } | |
468 } | |
469 | |
470 /** | |
471 * Removes the listener from the collection of listeners who will | |
472 * be notified when the receiver is selected by the user. | |
473 * | |
474 * @param listener the listener which should no longer be notified | |
475 * | |
476 * @exception IllegalArgumentException <ul> | |
477 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
478 * </ul> | |
479 * @exception DWTException <ul> | |
480 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
481 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
482 * </ul> | |
483 * | |
484 * @see SelectionListener | |
485 * @see #addSelectionListener | |
486 */ | |
487 public void removeSelectionListener (SelectionListener listener) { | |
488 checkWidget(); | |
489 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
490 if (eventTable is null) return; | |
491 eventTable.unhook (DWT.Selection, listener); | |
492 eventTable.unhook (DWT.DefaultSelection,listener); | |
493 } | |
494 | |
495 /** | |
496 * Makes the receiver hide automatically when <code>true</code>, | |
497 * and remain visible when <code>false</code>. | |
498 * | |
499 * @param autoHide the auto hide state | |
500 * | |
501 * @exception DWTException <ul> | |
502 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
503 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
504 * </ul> | |
505 * | |
506 * @see #getVisible | |
507 * @see #setVisible | |
508 */ | |
509 public void setAutoHide (bool autohide) { | |
510 checkWidget (); | |
511 this.autohide = autohide; | |
512 //TODO - update when visible | |
513 } | |
514 | |
515 /** | |
516 * Sets the location of the receiver, which must be a tooltip, | |
517 * to the point specified by the arguments which are relative | |
518 * to the display. | |
519 * <p> | |
520 * Note that this is different from most widgets where the | |
521 * location of the widget is relative to the parent. | |
522 * </p> | |
523 * | |
524 * @param x the new x coordinate for the receiver | |
525 * @param y the new y coordinate for the receiver | |
526 * | |
527 * @exception DWTException <ul> | |
528 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
529 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
530 * </ul> | |
531 */ | |
532 public void setLocation (int x, int y) { | |
533 checkWidget (); | |
534 if (this.x is x && this.y is y) return; | |
535 this.x = x; | |
536 this.y = y; | |
537 if (tip.getVisible ()) configure (); | |
538 } | |
539 | |
540 /** | |
541 * Sets the location of the receiver, which must be a tooltip, | |
542 * to the point specified by the argument which is relative | |
543 * to the display. | |
544 * <p> | |
545 * Note that this is different from most widgets where the | |
546 * location of the widget is relative to the parent. | |
547 * </p><p> | |
548 * Note that the platform window manager ultimately has control | |
549 * over the location of tooltips. | |
550 * </p> | |
551 * | |
552 * @param location the new location for the receiver | |
553 * | |
554 * @exception IllegalArgumentException <ul> | |
555 * <li>ERROR_NULL_ARGUMENT - if the point is null</li> | |
556 * </ul> | |
557 * @exception DWTException <ul> | |
558 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
559 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
560 * </ul> | |
561 */ | |
562 public void setLocation (Point location) { | |
563 checkWidget (); | |
564 if (location is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
565 setLocation (location.x, location.y); | |
566 } | |
567 | |
568 /** | |
569 * Sets the receiver's message. | |
570 * | |
571 * @param string the new message | |
572 * | |
573 * @exception IllegalArgumentException <ul> | |
574 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
575 * </ul> | |
576 * @exception DWTException <ul> | |
577 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
578 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
579 * </ul> | |
580 */ | |
581 public void setMessage (String string) { | |
582 checkWidget (); | |
583 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
584 if (layoutMessage !is null) layoutMessage.dispose(); | |
585 layoutMessage = null; | |
586 if (string.length () !is 0) { | |
587 Display display = getDisplay (); | |
588 layoutMessage = new TextLayout (display); | |
589 layoutMessage.setText (string); | |
590 } | |
591 if (tip.getVisible ()) configure (); | |
592 } | |
593 | |
594 /** | |
595 * Sets the receiver's text. | |
596 * | |
597 * @param string the new text | |
598 * | |
599 * @exception IllegalArgumentException <ul> | |
600 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
601 * </ul> | |
602 * @exception DWTException <ul> | |
603 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
604 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
605 * </ul> | |
606 */ | |
607 public void setText (String string) { | |
608 checkWidget (); | |
609 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
610 if (layoutText !is null) layoutText.dispose (); | |
611 layoutText = null; | |
612 if (boldFont !is null) boldFont.dispose (); | |
613 boldFont = null; | |
614 if (string.length () !is 0) { | |
615 Display display = getDisplay (); | |
616 layoutText = new TextLayout (display); | |
617 layoutText.setText (string); | |
618 Font font = display.getSystemFont (); | |
619 FontData data = font.getFontData () [0]; | |
620 boldFont = new Font (cast(Device) display, data.getName (), data.getHeight (), DWT.BOLD); | |
621 TextStyle style = new TextStyle (boldFont, null, null); | |
622 layoutText.setStyle (style, 0, string.length ()); | |
623 } | |
624 if (tip.getVisible ()) configure (); | |
625 } | |
626 | |
627 /** | |
628 * Marks the receiver as visible if the argument is <code>true</code>, | |
629 * and marks it invisible otherwise. | |
630 * <p> | |
631 * If one of the receiver's ancestors is not visible or some | |
632 * other condition makes the receiver not visible, marking | |
633 * it visible may not actually cause it to be displayed. | |
634 * </p> | |
635 * | |
636 * @param visible the new visibility state | |
637 * | |
638 * @exception DWTException <ul> | |
639 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
640 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
641 * </ul> | |
642 */ | |
643 public void setVisible (bool visible) { | |
644 if (visible) configure (); | |
645 tip.setVisible (visible); | |
646 Display display = getDisplay (); | |
647 if (runnable !is null) display.timerExec (-1, runnable); | |
648 runnable = null; | |
649 if (autohide && visible) { | |
650 runnable = new class Runnable { | |
651 public void run () { | |
652 if (!isDisposed ()) setVisible (false); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
653 } |
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
|
654 }; |
123 | 655 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
|
656 } |
123 | 657 } |
658 | |
659 } |