Mercurial > projects > dwt-addons
annotate dwtx/jface/dialogs/Dialog.d @ 82:0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 20 Jun 2008 12:44:40 +0200 |
parents | 46a6e0e6ccd4 |
children |
rev | line source |
---|---|
8 | 1 /******************************************************************************* |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
8 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
10 * Remy Chi Jian Suen <remy.suen@gmail.com> - Bug 218553 [JFace] mis-spelling of their in applyDialogFont(...) |
8 | 11 * Port to the D programming language: |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | |
14 module dwtx.jface.dialogs.Dialog; | |
15 | |
16 import dwtx.jface.dialogs.IDialogBlockedHandler; | |
17 import dwtx.jface.dialogs.IDialogSettings; | |
18 import dwtx.jface.dialogs.IDialogConstants; | |
19 // import tango.util.Arrays; | |
20 | |
21 import dwt.DWT; | |
22 import dwt.events.SelectionAdapter; | |
23 import dwt.events.SelectionEvent; | |
24 import dwt.graphics.Font; | |
25 import dwt.graphics.FontData; | |
26 import dwt.graphics.FontMetrics; | |
27 import dwt.graphics.GC; | |
28 import dwt.graphics.Image; | |
29 import dwt.graphics.Point; | |
30 import dwt.layout.FormData; | |
31 import dwt.layout.GridData; | |
32 import dwt.layout.GridLayout; | |
33 import dwt.widgets.Button; | |
34 import dwt.widgets.Composite; | |
35 import dwt.widgets.Control; | |
36 import dwt.widgets.Display; | |
37 import dwt.widgets.Shell; | |
38 import dwtx.core.runtime.IProgressMonitor; | |
39 import dwtx.core.runtime.IStatus; | |
40 import dwtx.core.runtime.Status; | |
41 import dwtx.jface.resource.JFaceResources; | |
42 import dwtx.jface.util.Policy; | |
43 import dwtx.jface.window.IShellProvider; | |
44 import dwtx.jface.window.SameShellProvider; | |
45 import dwtx.jface.window.Window; | |
46 | |
47 import dwt.dwthelper.utils; | |
48 | |
49 /** | |
50 * A dialog is a specialized window used for narrow-focused communication with | |
51 * the user. | |
52 * <p> | |
53 * Dialogs are usually modal. Consequently, it is generally bad practice to open | |
54 * a dialog without a parent. A modal dialog without a parent is not prevented | |
55 * from disappearing behind the application's other windows, making it very | |
56 * confusing for the user. | |
57 * </p> | |
58 * <p> | |
59 * If there is more than one modal dialog is open the second one should be | |
60 * parented off of the shell of the first one otherwise it is possible that the | |
61 * OS will give focus to the first dialog potentially blocking the UI. | |
62 * </p> | |
63 */ | |
64 public abstract class Dialog : Window { | |
65 /** | |
66 * Image registry key for error image (value | |
67 * <code>"dialog_error_image"</code>). | |
68 * | |
69 * @deprecated use | |
70 * dwt.widgets.Display.getSystemImage(DWT.ICON_ERROR) | |
71 */ | |
72 public static const String DLG_IMG_ERROR = "dialog_error_image"; //$NON-NLS-1$ | |
73 | |
74 /** | |
75 * Image registry key for info image (value <code>"dialog_info_image"</code>). | |
76 * | |
77 * @deprecated use | |
78 * dwt.widgets.Display.getSystemImage(DWT.ICON_INFORMATION) | |
79 */ | |
80 public static const String DLG_IMG_INFO = "dialog_info_imageg"; //$NON-NLS-1$ | |
81 | |
82 /** | |
83 * Image registry key for question image (value | |
84 * <code>"dialog_question_image"</code>). | |
85 * | |
86 * @deprecated dwt.widgets.Display.getSystemImage(DWT.ICON_QUESTION) | |
87 */ | |
88 public static const String DLG_IMG_QUESTION = "dialog_question_image"; //$NON-NLS-1$ | |
89 | |
90 /** | |
91 * Image registry key for warning image (value | |
92 * <code>"dialog_warning_image"</code>). | |
93 * | |
94 * @deprecated use | |
95 * dwt.widgets.Display.getSystemImage(DWT.ICON_WARNING) | |
96 */ | |
97 public static const String DLG_IMG_WARNING = "dialog_warning_image"; //$NON-NLS-1$ | |
98 | |
99 /** | |
100 * Image registry key for info message image (value | |
101 * <code>"dialog_messasge_info_image"</code>). | |
102 * | |
103 * @since 2.0 | |
104 */ | |
105 public static const String DLG_IMG_MESSAGE_INFO = "dialog_messasge_info_image"; //$NON-NLS-1$ | |
106 | |
107 /** | |
108 * Image registry key for info message image (value | |
109 * <code>"dialog_messasge_warning_image"</code>). | |
110 * | |
111 * @since 2.0 | |
112 */ | |
113 public static const String DLG_IMG_MESSAGE_WARNING = "dialog_messasge_warning_image"; //$NON-NLS-1$ | |
114 | |
115 /** | |
116 * Image registry key for info message image (value | |
117 * <code>"dialog_message_error_image"</code>). | |
118 * | |
119 * @since 2.0 | |
120 */ | |
121 public static const String DLG_IMG_MESSAGE_ERROR = "dialog_message_error_image"; //$NON-NLS-1$ | |
122 | |
123 /** | |
124 * Image registry key for help image (value | |
125 * <code>"dialog_help_image"</code>). | |
126 * | |
127 * @since 3.2 | |
128 */ | |
129 public static const String DLG_IMG_HELP = "dialog_help_image"; //$NON-NLS-1$ | |
130 | |
131 /** | |
132 * The ellipsis is the string that is used to represent shortened text. | |
133 * | |
134 * @since 3.0 | |
135 */ | |
136 public static const String ELLIPSIS = "..."; //$NON-NLS-1$ | |
137 | |
138 /** | |
139 * The dialog settings key name for stored dialog x location. | |
140 * | |
141 * @since 3.2 | |
142 */ | |
143 private static const String DIALOG_ORIGIN_X = "DIALOG_X_ORIGIN"; //$NON-NLS-1$ | |
144 | |
145 /** | |
146 * The dialog settings key name for stored dialog y location. | |
147 * | |
148 * @since 3.2 | |
149 */ | |
150 private static const String DIALOG_ORIGIN_Y = "DIALOG_Y_ORIGIN"; //$NON-NLS-1$ | |
151 | |
152 /** | |
153 * The dialog settings key name for stored dialog width. | |
154 * | |
155 * @since 3.2 | |
156 */ | |
157 private static const String DIALOG_WIDTH = "DIALOG_WIDTH"; //$NON-NLS-1$ | |
158 | |
159 /** | |
160 * The dialog settings key name for stored dialog height. | |
161 * | |
162 * @since 3.2 | |
163 */ | |
164 private static const String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$ | |
165 | |
166 /** | |
167 * The dialog settings key name for the font used when the dialog | |
168 * height and width was stored. | |
169 * | |
170 *@since 3.2 | |
171 */ | |
172 private static const String DIALOG_FONT_DATA = "DIALOG_FONT_NAME"; //$NON-NLS-1$ | |
173 | |
174 /** | |
175 * A value that can be used for stored dialog width or height that | |
176 * indicates that the default bounds should be used. | |
177 * | |
178 * @since 3.2 | |
179 */ | |
180 public static const int DIALOG_DEFAULT_BOUNDS = -1; | |
181 | |
182 /** | |
183 * Constants that can be used for specifying the strategy for persisting | |
184 * dialog bounds. These constants represent bit masks that can be used | |
185 * together. | |
186 * | |
187 *@since 3.2 | |
188 */ | |
189 | |
190 /** | |
191 * Persist the last location of the dialog. | |
192 * @since 3.2 | |
193 */ | |
194 public static const int DIALOG_PERSISTLOCATION = 0x0001; | |
195 /** | |
196 * Persist the last known size of the dialog. | |
197 * @since 3.2 | |
198 */ | |
199 public static const int DIALOG_PERSISTSIZE = 0x0002; | |
200 | |
201 /** | |
202 * The dialog area; <code>null</code> until dialog is layed out. | |
203 */ | |
204 protected Control dialogArea; | |
205 | |
206 /** | |
207 * The button bar; <code>null</code> until dialog is layed out. | |
208 */ | |
209 public Control buttonBar; | |
210 | |
211 /** | |
212 * Collection of buttons created by the <code>createButton</code> method. | |
213 */ | |
214 private Button[int] buttons; | |
215 | |
216 /** | |
217 * Font metrics to use for determining pixel sizes. | |
218 */ | |
219 private FontMetrics fontMetrics; | |
220 | |
221 /** | |
222 * Number of horizontal dialog units per character, value <code>4</code>. | |
223 */ | |
224 private static const int HORIZONTAL_DIALOG_UNIT_PER_CHAR = 4; | |
225 | |
226 /** | |
227 * Number of vertical dialog units per character, value <code>8</code>. | |
228 */ | |
229 private static const int VERTICAL_DIALOG_UNITS_PER_CHAR = 8; | |
230 | |
231 /** | |
232 * Returns the number of pixels corresponding to the height of the given | |
233 * number of characters. | |
234 * <p> | |
235 * The required <code>FontMetrics</code> parameter may be created in the | |
236 * following way: <code> | |
237 * GC gc = new GC(control); | |
238 * gc.setFont(control.getFont()); | |
239 * fontMetrics = gc.getFontMetrics(); | |
240 * gc.dispose(); | |
241 * </code> | |
242 * </p> | |
243 * | |
244 * @param fontMetrics | |
245 * used in performing the conversion | |
246 * @param chars | |
247 * the number of characters | |
248 * @return the number of pixels | |
249 * @since 2.0 | |
250 */ | |
251 public static int convertHeightInCharsToPixels(FontMetrics fontMetrics, | |
252 int chars) { | |
253 return fontMetrics.getHeight() * chars; | |
254 } | |
255 | |
256 /** | |
257 * Returns the number of pixels corresponding to the given number of | |
258 * horizontal dialog units. | |
259 * <p> | |
260 * The required <code>FontMetrics</code> parameter may be created in the | |
261 * following way: <code> | |
262 * GC gc = new GC(control); | |
263 * gc.setFont(control.getFont()); | |
264 * fontMetrics = gc.getFontMetrics(); | |
265 * gc.dispose(); | |
266 * </code> | |
267 * </p> | |
268 * | |
269 * @param fontMetrics | |
270 * used in performing the conversion | |
271 * @param dlus | |
272 * the number of horizontal dialog units | |
273 * @return the number of pixels | |
274 * @since 2.0 | |
275 */ | |
276 public static int convertHorizontalDLUsToPixels(FontMetrics fontMetrics, | |
277 int dlus) { | |
278 // round to the nearest pixel | |
279 return (fontMetrics.getAverageCharWidth() * dlus + HORIZONTAL_DIALOG_UNIT_PER_CHAR / 2) | |
280 / HORIZONTAL_DIALOG_UNIT_PER_CHAR; | |
281 } | |
282 | |
283 /** | |
284 * Returns the number of pixels corresponding to the given number of | |
285 * vertical dialog units. | |
286 * <p> | |
287 * The required <code>FontMetrics</code> parameter may be created in the | |
288 * following way: <code> | |
289 * GC gc = new GC(control); | |
290 * gc.setFont(control.getFont()); | |
291 * fontMetrics = gc.getFontMetrics(); | |
292 * gc.dispose(); | |
293 * </code> | |
294 * </p> | |
295 * | |
296 * @param fontMetrics | |
297 * used in performing the conversion | |
298 * @param dlus | |
299 * the number of vertical dialog units | |
300 * @return the number of pixels | |
301 * @since 2.0 | |
302 */ | |
303 public static int convertVerticalDLUsToPixels(FontMetrics fontMetrics, | |
304 int dlus) { | |
305 // round to the nearest pixel | |
306 return (fontMetrics.getHeight() * dlus + VERTICAL_DIALOG_UNITS_PER_CHAR / 2) | |
307 / VERTICAL_DIALOG_UNITS_PER_CHAR; | |
308 } | |
309 | |
310 /** | |
311 * Returns the number of pixels corresponding to the width of the given | |
312 * number of characters. | |
313 * <p> | |
314 * The required <code>FontMetrics</code> parameter may be created in the | |
315 * following way: <code> | |
316 * GC gc = new GC(control); | |
317 * gc.setFont(control.getFont()); | |
318 * fontMetrics = gc.getFontMetrics(); | |
319 * gc.dispose(); | |
320 * </code> | |
321 * </p> | |
322 * | |
323 * @param fontMetrics | |
324 * used in performing the conversion | |
325 * @param chars | |
326 * the number of characters | |
327 * @return the number of pixels | |
328 * @since 2.0 | |
329 */ | |
330 public static int convertWidthInCharsToPixels(FontMetrics fontMetrics, | |
331 int chars) { | |
332 return fontMetrics.getAverageCharWidth() * chars; | |
333 } | |
334 | |
335 /** | |
336 * Shortens the given text <code>textValue</code> so that its width in | |
337 * pixels does not exceed the width of the given control. Overrides | |
338 * characters in the center of the original string with an ellipsis ("...") | |
339 * if necessary. If a <code>null</code> value is given, <code>null</code> | |
340 * is returned. | |
341 * | |
342 * @param textValue | |
343 * the original string or <code>null</code> | |
344 * @param control | |
345 * the control the string will be displayed on | |
346 * @return the string to display, or <code>null</code> if null was passed | |
347 * in | |
348 * | |
349 * @since 3.0 | |
350 */ | |
351 public static String shortenText(String textValue, Control control) { | |
352 if (textValue is null) { | |
353 return null; | |
354 } | |
355 GC gc = new GC(control); | |
356 int maxWidth = control.getBounds().width - 5; | |
357 int maxExtent = gc.textExtent(textValue).x; | |
358 if (maxExtent < maxWidth) { | |
359 gc.dispose(); | |
360 return textValue; | |
361 } | |
362 int length = textValue.length; | |
363 int charsToClip = cast(int) Math.round(0.95f*length * (1 - (cast(float)maxWidth/maxExtent))); | |
364 int pivot = length / 2; | |
365 int start = pivot - (charsToClip/2); | |
366 int end = pivot + (charsToClip/2) + 1; | |
367 while (start >= 0 && end < length) { | |
368 String s1 = textValue.substring(0, start); | |
369 String s2 = textValue.substring(end, length); | |
370 String s = s1 ~ ELLIPSIS ~ s2; | |
371 int l = gc.textExtent(s).x; | |
372 if (l < maxWidth) { | |
373 gc.dispose(); | |
374 return s; | |
375 } | |
376 start--; | |
377 end++; | |
378 } | |
379 gc.dispose(); | |
380 return textValue; | |
381 } | |
382 | |
383 /** | |
384 * Create a default instance of the blocked handler which does not do | |
385 * anything. | |
386 */ | |
82
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
387 private static IDialogBlockedHandler blockedHandler_; |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
388 public static IDialogBlockedHandler blockedHandler(){ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
389 static_this_blockedhandler(); |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
390 return blockedHandler_; |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
391 } |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
392 public static IDialogBlockedHandler blockedHandler( IDialogBlockedHandler b ){ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
393 static_this_blockedhandler(); |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
394 return ( blockedHandler_ = b ); |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
395 } |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
396 private static bool static_this_blockedhandler_completed = false; |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
397 private static void static_this_blockedhandler(){ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
398 if( static_this_blockedhandler_completed ){ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
399 return; |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
400 } |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
401 synchronized{ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
402 if( static_this_blockedhandler_completed ){ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
403 return; |
8 | 404 } |
82
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
405 blockedHandler_ = new class IDialogBlockedHandler { |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
406 /* |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
407 * (non-Javadoc) |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
408 * |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
409 * @see dwtx.jface.dialogs.IDialogBlockedHandler#clearBlocked() |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
410 */ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
411 public void clearBlocked() { |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
412 // No default behaviour |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
413 } |
8 | 414 |
82
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
415 /* |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
416 * (non-Javadoc) |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
417 * |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
418 * @see dwtx.jface.dialogs.IDialogBlockedHandler#showBlocked(dwtx.core.runtime.IProgressMonitor, |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
419 * dwtx.core.runtime.IStatus, java.lang.String) |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
420 */ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
421 public void showBlocked(IProgressMonitor blocking, |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
422 IStatus blockingStatus, String blockedName) { |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
423 // No default behaviour |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
424 } |
8 | 425 |
82
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
426 /* |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
427 * (non-Javadoc) |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
428 * |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
429 * @see dwtx.jface.dialogs.IDialogBlockedHandler#showBlocked(dwt.widgets.Shell, |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
430 * dwtx.core.runtime.IProgressMonitor, |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
431 * dwtx.core.runtime.IStatus, java.lang.String) |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
432 */ |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
433 public void showBlocked(Shell parentShell, IProgressMonitor blocking, |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
434 IStatus blockingStatus, String blockedName) { |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
435 // No default behaviour |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
436 } |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
437 }; |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
438 static_this_blockedhandler_completed = true; |
0aafcf6e5217
Lazy initialization to fix cyclic dep. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
439 } |
8 | 440 } |
441 | |
442 /** | |
443 * Creates a dialog instance. Note that the window will have no visual | |
444 * representation (no widgets) until it is told to open. By default, | |
445 * <code>open</code> blocks for dialogs. | |
446 * | |
447 * @param parentShell | |
448 * the parent shell, or <code>null</code> to create a top-level | |
449 * shell | |
450 */ | |
451 protected this(Shell parentShell) { | |
452 this(new SameShellProvider(parentShell)); | |
453 if (parentShell is null && Policy.DEBUG_DIALOG_NO_PARENT) { | |
454 Policy.getLog().log( | |
455 new Status(IStatus.INFO, Policy.JFACE, IStatus.INFO, this | |
456 .classinfo.name | |
457 ~ " created with no shell",//$NON-NLS-1$ | |
458 new Exception( null, null ))); | |
459 } | |
460 } | |
461 | |
462 /** | |
463 * Creates a dialog with the given parent. | |
464 * | |
465 * @param parentShell | |
466 * object that returns the current parent shell | |
467 * | |
468 * @since 3.1 | |
469 */ | |
470 protected this(IShellProvider parentShell) { | |
471 super(parentShell); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
472 if (isResizable()) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
473 setShellStyle(DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL | DWT.MAX | DWT.RESIZE |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
474 | getDefaultOrientation()); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
475 } else { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
476 setShellStyle(DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
477 | getDefaultOrientation()); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
478 } |
8 | 479 setBlockOnOpen(true); |
480 } | |
481 | |
482 /** | |
483 * Notifies that this dialog's button with the given id has been pressed. | |
484 * <p> | |
485 * The <code>Dialog</code> implementation of this framework method calls | |
486 * <code>okPressed</code> if the ok button is the pressed, and | |
487 * <code>cancelPressed</code> if the cancel button is the pressed. All | |
488 * other button presses are ignored. Subclasses may override to handle other | |
489 * buttons, but should call <code>super.buttonPressed</code> if the | |
490 * default handling of the ok and cancel buttons is desired. | |
491 * </p> | |
492 * | |
493 * @param buttonId | |
494 * the id of the button that was pressed (see | |
495 * <code>IDialogConstants.*_ID</code> constants) | |
496 */ | |
497 protected void buttonPressed(int buttonId) { | |
498 if (IDialogConstants.OK_ID is buttonId) { | |
499 okPressed(); | |
500 } else if (IDialogConstants.CANCEL_ID is buttonId) { | |
501 cancelPressed(); | |
502 } | |
503 } | |
504 | |
505 /** | |
506 * Notifies that the cancel button of this dialog has been pressed. | |
507 * <p> | |
508 * The <code>Dialog</code> implementation of this framework method sets | |
509 * this dialog's return code to <code>Window.CANCEL</code> and closes the | |
510 * dialog. Subclasses may override if desired. | |
511 * </p> | |
512 */ | |
513 protected void cancelPressed() { | |
514 setReturnCode(CANCEL); | |
515 close(); | |
516 } | |
517 | |
518 /** | |
519 * Returns the number of pixels corresponding to the height of the given | |
520 * number of characters. | |
521 * <p> | |
522 * This method may only be called after <code>initializeDialogUnits</code> | |
523 * has been called. | |
524 * </p> | |
525 * <p> | |
526 * Clients may call this framework method, but should not override it. | |
527 * </p> | |
528 * | |
529 * @param chars | |
530 * the number of characters | |
531 * @return the number of pixels | |
532 */ | |
533 protected int convertHeightInCharsToPixels(int chars) { | |
534 // test for failure to initialize for backward compatibility | |
535 if (fontMetrics is null) { | |
536 return 0; | |
537 } | |
538 return convertHeightInCharsToPixels(fontMetrics, chars); | |
539 } | |
540 | |
541 /** | |
542 * Returns the number of pixels corresponding to the given number of | |
543 * horizontal dialog units. | |
544 * <p> | |
545 * This method may only be called after <code>initializeDialogUnits</code> | |
546 * has been called. | |
547 * </p> | |
548 * <p> | |
549 * Clients may call this framework method, but should not override it. | |
550 * </p> | |
551 * | |
552 * @param dlus | |
553 * the number of horizontal dialog units | |
554 * @return the number of pixels | |
555 */ | |
556 protected int convertHorizontalDLUsToPixels(int dlus) { | |
557 // test for failure to initialize for backward compatibility | |
558 if (fontMetrics is null) { | |
559 return 0; | |
560 } | |
561 return convertHorizontalDLUsToPixels(fontMetrics, dlus); | |
562 } | |
563 | |
564 /** | |
565 * Returns the number of pixels corresponding to the given number of | |
566 * vertical dialog units. | |
567 * <p> | |
568 * This method may only be called after <code>initializeDialogUnits</code> | |
569 * has been called. | |
570 * </p> | |
571 * <p> | |
572 * Clients may call this framework method, but should not override it. | |
573 * </p> | |
574 * | |
575 * @param dlus | |
576 * the number of vertical dialog units | |
577 * @return the number of pixels | |
578 */ | |
579 protected int convertVerticalDLUsToPixels(int dlus) { | |
580 // test for failure to initialize for backward compatibility | |
581 if (fontMetrics is null) { | |
582 return 0; | |
583 } | |
584 return convertVerticalDLUsToPixels(fontMetrics, dlus); | |
585 } | |
586 | |
587 /** | |
588 * Returns the number of pixels corresponding to the width of the given | |
589 * number of characters. | |
590 * <p> | |
591 * This method may only be called after <code>initializeDialogUnits</code> | |
592 * has been called. | |
593 * </p> | |
594 * <p> | |
595 * Clients may call this framework method, but should not override it. | |
596 * </p> | |
597 * | |
598 * @param chars | |
599 * the number of characters | |
600 * @return the number of pixels | |
601 */ | |
602 protected int convertWidthInCharsToPixels(int chars) { | |
603 // test for failure to initialize for backward compatibility | |
604 if (fontMetrics is null) { | |
605 return 0; | |
606 } | |
607 return convertWidthInCharsToPixels(fontMetrics, chars); | |
608 } | |
609 | |
610 /** | |
611 * Creates a new button with the given id. | |
612 * <p> | |
613 * The <code>Dialog</code> implementation of this framework method creates | |
614 * a standard push button, registers it for selection events including | |
615 * button presses, and registers default buttons with its shell. The button | |
616 * id is stored as the button's client data. If the button id is | |
617 * <code>IDialogConstants.CANCEL_ID</code>, the new button will be | |
618 * accessible from <code>getCancelButton()</code>. If the button id is | |
619 * <code>IDialogConstants.OK_ID</code>, the new button will be accesible | |
620 * from <code>getOKButton()</code>. Note that the parent's layout is | |
621 * assumed to be a <code>GridLayout</code> and the number of columns in | |
622 * this layout is incremented. Subclasses may override. | |
623 * </p> | |
624 * | |
625 * @param parent | |
626 * the parent composite | |
627 * @param id | |
628 * the id of the button (see <code>IDialogConstants.*_ID</code> | |
629 * constants for standard dialog button ids) | |
630 * @param label | |
631 * the label from the button | |
632 * @param defaultButton | |
633 * <code>true</code> if the button is to be the default button, | |
634 * and <code>false</code> otherwise | |
635 * | |
636 * @return the new button | |
637 * | |
638 * @see #getCancelButton | |
639 * @see #getOKButton() | |
640 */ | |
641 protected Button createButton(Composite parent, int id, String label, | |
642 bool defaultButton) { | |
643 // increment the number of columns in the button bar | |
644 (cast(GridLayout) parent.getLayout()).numColumns++; | |
645 Button button = new Button(parent, DWT.PUSH); | |
646 button.setText(label); | |
647 button.setFont(JFaceResources.getDialogFont()); | |
648 button.setData(new ValueWrapperInt(id)); | |
649 button.addSelectionListener(new class SelectionAdapter { | |
650 public void widgetSelected(SelectionEvent event) { | |
651 buttonPressed((cast(ValueWrapperInt) event.widget.getData()).value); | |
652 } | |
653 }); | |
654 if (defaultButton) { | |
655 Shell shell = parent.getShell(); | |
656 if (shell !is null) { | |
657 shell.setDefaultButton(button); | |
658 } | |
659 } | |
660 buttons[id] = button; | |
661 setButtonLayoutData(button); | |
662 return button; | |
663 } | |
664 | |
665 /** | |
666 * Creates and returns the contents of this dialog's button bar. | |
667 * <p> | |
668 * The <code>Dialog</code> implementation of this framework method lays | |
669 * out a button bar and calls the <code>createButtonsForButtonBar</code> | |
670 * framework method to populate it. Subclasses may override. | |
671 * </p> | |
672 * <p> | |
673 * The returned control's layout data must be an instance of | |
674 * <code>GridData</code>. | |
675 * </p> | |
676 * | |
677 * @param parent | |
678 * the parent composite to contain the button bar | |
679 * @return the button bar control | |
680 */ | |
681 protected Control createButtonBar(Composite parent) { | |
682 Composite composite = new Composite(parent, DWT.NONE); | |
683 // create a layout with spacing and margins appropriate for the font | |
684 // size. | |
685 GridLayout layout = new GridLayout(); | |
686 layout.numColumns = 0; // this is incremented by createButton | |
687 layout.makeColumnsEqualWidth = true; | |
688 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); | |
689 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); | |
690 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); | |
691 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); | |
692 composite.setLayout(layout); | |
693 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END | |
694 | GridData.VERTICAL_ALIGN_CENTER); | |
695 composite.setLayoutData(data); | |
696 composite.setFont(parent.getFont()); | |
697 | |
698 // Add the buttons to the button bar. | |
699 createButtonsForButtonBar(composite); | |
700 return composite; | |
701 } | |
702 | |
703 /** | |
704 * Adds buttons to this dialog's button bar. | |
705 * <p> | |
706 * The <code>Dialog</code> implementation of this framework method adds | |
707 * standard ok and cancel buttons using the <code>createButton</code> | |
708 * framework method. These standard buttons will be accessible from | |
709 * <code>getCancelButton</code>, and <code>getOKButton</code>. | |
710 * Subclasses may override. | |
711 * </p> | |
712 * | |
713 * @param parent | |
714 * the button bar composite | |
715 */ | |
716 protected void createButtonsForButtonBar(Composite parent) { | |
717 // create OK and Cancel buttons by default | |
718 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, | |
719 true); | |
720 createButton(parent, IDialogConstants.CANCEL_ID, | |
721 IDialogConstants.CANCEL_LABEL, false); | |
722 } | |
723 | |
724 /* | |
725 * @see Window.initializeBounds() | |
726 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
727 protected override void initializeBounds() { |
8 | 728 String platform = DWT.getPlatform(); |
729 if ("carbon".equals(platform)) { //$NON-NLS-1$ | |
730 // On Mac OS X the default button must be the right-most button | |
731 Shell shell = getShell(); | |
732 if (shell !is null) { | |
733 Button defaultButton = shell.getDefaultButton(); | |
734 if (defaultButton !is null | |
735 && isContained(buttonBar, defaultButton)) { | |
736 defaultButton.moveBelow(null); | |
737 } | |
738 } | |
739 } | |
740 | |
741 super.initializeBounds(); | |
742 } | |
743 | |
744 /** | |
745 * Returns true if the given Control is a direct or indirect child of | |
746 * container. | |
747 * | |
748 * @param container | |
749 * the potential parent | |
750 * @param control | |
751 * @return bool <code>true</code> if control is a child of container | |
752 */ | |
753 private bool isContained(Control container, Control control) { | |
754 Composite parent; | |
755 while ((parent = control.getParent()) !is null) { | |
756 if (parent is container) { | |
757 return true; | |
758 } | |
759 control = parent; | |
760 } | |
761 return false; | |
762 } | |
763 | |
764 /** | |
765 * The <code>Dialog</code> implementation of this <code>Window</code> | |
766 * method creates and lays out the top level composite for the dialog, and | |
767 * determines the appropriate horizontal and vertical dialog units based on | |
768 * the font size. It then calls the <code>createDialogArea</code> and | |
769 * <code>createButtonBar</code> methods to create the dialog area and | |
770 * button bar, respectively. Overriding <code>createDialogArea</code> and | |
771 * <code>createButtonBar</code> are recommended rather than overriding | |
772 * this method. | |
773 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
774 protected override Control createContents(Composite parent) { |
8 | 775 // create the top level composite for the dialog |
776 Composite composite = new Composite(parent, 0); | |
777 GridLayout layout = new GridLayout(); | |
778 layout.marginHeight = 0; | |
779 layout.marginWidth = 0; | |
780 layout.verticalSpacing = 0; | |
781 composite.setLayout(layout); | |
782 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
783 applyDialogFont(composite); | |
784 // initialize the dialog units | |
785 initializeDialogUnits(composite); | |
786 // create the dialog area and button bar | |
787 dialogArea = createDialogArea(composite); | |
788 buttonBar = createButtonBar(composite); | |
789 | |
790 return composite; | |
791 } | |
792 | |
793 /** | |
794 * Creates and returns the contents of the upper part of this dialog (above | |
795 * the button bar). | |
796 * <p> | |
797 * The <code>Dialog</code> implementation of this framework method creates | |
798 * and returns a new <code>Composite</code> with standard margins and | |
799 * spacing. | |
800 * </p> | |
801 * <p> | |
802 * The returned control's layout data must be an instance of | |
803 * <code>GridData</code>. This method must not modify the parent's | |
804 * layout. | |
805 * </p> | |
806 * <p> | |
807 * Subclasses must override this method but may call <code>super</code> as | |
808 * in the following example: | |
809 * </p> | |
810 * | |
811 * <pre> | |
812 * Composite composite = (Composite) super.createDialogArea(parent); | |
813 * //add controls to composite as necessary | |
814 * return composite; | |
815 * </pre> | |
816 * | |
817 * @param parent | |
818 * the parent composite to contain the dialog area | |
819 * @return the dialog area control | |
820 */ | |
821 protected Control createDialogArea(Composite parent) { | |
822 // create a composite with standard margins and spacing | |
823 Composite composite = new Composite(parent, DWT.NONE); | |
824 GridLayout layout = new GridLayout(); | |
825 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); | |
826 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); | |
827 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); | |
828 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); | |
829 composite.setLayout(layout); | |
830 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
831 applyDialogFont(composite); | |
832 return composite; | |
833 } | |
834 | |
835 /** | |
836 * Returns the button created by the method <code>createButton</code> for | |
837 * the specified ID as defined on <code>IDialogConstants</code>. If | |
838 * <code>createButton</code> was never called with this ID, or if | |
839 * <code>createButton</code> is overridden, this method will return | |
840 * <code>null</code>. | |
841 * | |
842 * @param id | |
843 * the id of the button to look for | |
844 * | |
845 * @return the button for the ID or <code>null</code> | |
846 * | |
847 * @see #createButton(Composite, int, String, bool) | |
848 * @since 2.0 | |
849 */ | |
850 protected Button getButton(int id) { | |
60 | 851 if( auto btn = id in buttons ){ |
852 return *btn; | |
853 } | |
854 return null; | |
8 | 855 } |
856 | |
857 /** | |
858 * Returns the button bar control. | |
859 * <p> | |
860 * Clients may call this framework method, but should not override it. | |
861 * </p> | |
862 * | |
863 * @return the button bar, or <code>null</code> if the button bar has not | |
864 * been created yet | |
865 */ | |
866 protected Control getButtonBar() { | |
867 return buttonBar; | |
868 } | |
869 | |
870 /** | |
871 * Returns the button created when <code>createButton</code> is called | |
872 * with an ID of <code>IDialogConstants.CANCEL_ID</code>. If | |
873 * <code>createButton</code> was never called with this parameter, or if | |
874 * <code>createButton</code> is overridden, <code>getCancelButton</code> | |
875 * will return <code>null</code>. | |
876 * | |
877 * @return the cancel button or <code>null</code> | |
878 * | |
879 * @see #createButton(Composite, int, String, bool) | |
880 * @since 2.0 | |
881 * @deprecated Use <code>getButton(IDialogConstants.CANCEL_ID)</code> | |
882 * instead. This method will be removed soon. | |
883 */ | |
884 protected Button getCancelButton() { | |
885 return getButton(IDialogConstants.CANCEL_ID); | |
886 } | |
887 | |
888 /** | |
889 * Returns the dialog area control. | |
890 * <p> | |
891 * Clients may call this framework method, but should not override it. | |
892 * </p> | |
893 * | |
894 * @return the dialog area, or <code>null</code> if the dialog area has | |
895 * not been created yet | |
896 */ | |
897 protected Control getDialogArea() { | |
898 return dialogArea; | |
899 } | |
900 | |
901 /** | |
902 * Returns the standard dialog image with the given key. Note that these | |
903 * images are managed by the dialog framework, and must not be disposed by | |
904 * another party. | |
905 * | |
906 * @param key | |
907 * one of the <code>Dialog.DLG_IMG_* </code> constants | |
908 * @return the standard dialog image | |
909 * | |
910 * NOTE: Dialog does not use the following images in the registry | |
911 * DLG_IMG_ERROR DLG_IMG_INFO DLG_IMG_QUESTION DLG_IMG_WARNING | |
912 * | |
913 * They are now coming directly from DWT, see ImageRegistry. For backwards | |
914 * compatibility they are still supported, however new code should use DWT | |
915 * for these. | |
916 * | |
917 * @see Display#getSystemImage(int) | |
918 */ | |
919 public static Image getImage(String key) { | |
920 return JFaceResources.getImageRegistry().get(key); | |
921 } | |
922 | |
923 /** | |
924 * Returns the button created when <code>createButton</code> is called | |
925 * with an ID of <code>IDialogConstants.OK_ID</code>. If | |
926 * <code>createButton</code> was never called with this parameter, or if | |
927 * <code>createButton</code> is overridden, <code>getOKButton</code> | |
928 * will return <code>null</code>. | |
929 * | |
930 * @return the OK button or <code>null</code> | |
931 * | |
932 * @see #createButton(Composite, int, String, bool) | |
933 * @since 2.0 | |
934 * @deprecated Use <code>getButton(IDialogConstants.OK_ID)</code> instead. | |
935 * This method will be removed soon. | |
936 */ | |
937 protected Button getOKButton() { | |
938 return getButton(IDialogConstants.OK_ID); | |
939 } | |
940 | |
941 /** | |
942 * Initializes the computation of horizontal and vertical dialog units based | |
943 * on the size of current font. | |
944 * <p> | |
945 * This method must be called before any of the dialog unit based conversion | |
946 * methods are called. | |
947 * </p> | |
948 * | |
949 * @param control | |
950 * a control from which to obtain the current font | |
951 */ | |
952 protected void initializeDialogUnits(Control control) { | |
953 // Compute and store a font metric | |
954 GC gc = new GC(control); | |
955 gc.setFont(JFaceResources.getDialogFont()); | |
956 fontMetrics = gc.getFontMetrics(); | |
957 gc.dispose(); | |
958 } | |
959 | |
960 /** | |
961 * Notifies that the ok button of this dialog has been pressed. | |
962 * <p> | |
963 * The <code>Dialog</code> implementation of this framework method sets | |
964 * this dialog's return code to <code>Window.OK</code> and closes the | |
965 * dialog. Subclasses may override. | |
966 * </p> | |
967 */ | |
968 protected void okPressed() { | |
969 setReturnCode(OK); | |
970 close(); | |
971 } | |
972 | |
973 /** | |
974 * Set the layout data of the button to a GridData with appropriate heights | |
975 * and widths. | |
976 * | |
977 * @param button | |
978 */ | |
979 protected void setButtonLayoutData(Button button) { | |
980 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
981 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); | |
982 Point minSize = button.computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | |
983 data.widthHint = Math.max(widthHint, minSize.x); | |
984 button.setLayoutData(data); | |
985 } | |
986 | |
987 /** | |
988 * Set the layout data of the button to a FormData with appropriate heights | |
989 * and widths. | |
990 * | |
991 * @param button | |
992 */ | |
993 protected void setButtonLayoutFormData(Button button) { | |
994 FormData data = new FormData(); | |
995 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); | |
996 Point minSize = button.computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | |
997 data.width = Math.max(widthHint, minSize.x); | |
998 button.setLayoutData(data); | |
999 } | |
1000 | |
1001 /** | |
1002 * @see dwtx.jface.window.Window#close() | |
1003 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1004 public override bool close() { |
8 | 1005 if (getShell() !is null && !getShell().isDisposed()) { |
1006 saveDialogBounds(getShell()); | |
1007 } | |
1008 | |
1009 bool returnValue = super.close(); | |
1010 if (returnValue) { | |
1011 buttons = null; | |
1012 buttonBar = null; | |
1013 dialogArea = null; | |
1014 } | |
1015 return returnValue; | |
1016 } | |
1017 | |
1018 /** | |
1019 * Applies the dialog font to all controls that currently have the default | |
1020 * font. | |
1021 * | |
1022 * @param control | |
1023 * the control to apply the font to. Font will also be applied to | |
1024 * its children. If the control is <code>null</code> nothing | |
1025 * happens. | |
1026 */ | |
1027 public static void applyDialogFont(Control control) { | |
1028 if (control is null || dialogFontIsDefault()) { | |
1029 return; | |
1030 } | |
1031 Font dialogFont = JFaceResources.getDialogFont(); | |
1032 applyDialogFont(control, dialogFont); | |
1033 } | |
1034 | |
1035 /** | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1036 * Sets the dialog font on the control and any of its children if their font |
8 | 1037 * is not otherwise set. |
1038 * | |
1039 * @param control | |
1040 * the control to apply the font to. Font will also be applied to | |
1041 * its children. | |
1042 * @param dialogFont | |
1043 * the dialog font to set | |
1044 */ | |
1045 private static void applyDialogFont(Control control, Font dialogFont) { | |
1046 if (hasDefaultFont(control)) { | |
1047 control.setFont(dialogFont); | |
1048 } | |
1049 if ( auto comp = cast(Composite)control ) { | |
1050 Control[] children = comp.getChildren(); | |
1051 for (int i = 0; i < children.length; i++) { | |
1052 applyDialogFont(children[i], dialogFont); | |
1053 } | |
1054 } | |
1055 } | |
1056 | |
1057 /** | |
1058 * Return whether or not this control has the same font as it's default. | |
1059 * | |
1060 * @param control | |
1061 * Control | |
1062 * @return bool | |
1063 */ | |
1064 private static bool hasDefaultFont(Control control) { | |
1065 FontData[] controlFontData = control.getFont().getFontData(); | |
1066 FontData[] defaultFontData = getDefaultFont(control).getFontData(); | |
1067 if (controlFontData.length is defaultFontData.length) { | |
1068 for (int i = 0; i < controlFontData.length; i++) { | |
1069 if (controlFontData[i].opEquals(defaultFontData[i])) { | |
1070 continue; | |
1071 } | |
1072 return false; | |
1073 } | |
1074 return true; | |
1075 } | |
1076 return false; | |
1077 } | |
1078 | |
1079 /** | |
1080 * Get the default font for this type of control. | |
1081 * | |
1082 * @param control | |
1083 * @return the default font | |
1084 */ | |
1085 private static Font getDefaultFont(Control control) { | |
1086 String fontName = "DEFAULT_FONT_" ~ control.classinfo.name; //$NON-NLS-1$ | |
1087 if (JFaceResources.getFontRegistry().hasValueFor(fontName)) { | |
1088 return JFaceResources.getFontRegistry().get(fontName); | |
1089 } | |
1090 Font cached = control.getFont(); | |
1091 control.setFont(null); | |
1092 Font defaultFont = control.getFont(); | |
1093 control.setFont(cached); | |
1094 JFaceResources.getFontRegistry().put(fontName, | |
1095 defaultFont.getFontData()); | |
1096 return defaultFont; | |
1097 } | |
1098 | |
1099 /** | |
1100 * Return whether or not the dialog font is currently the same as the | |
1101 * default font. | |
1102 * | |
1103 * @return bool if the two are the same | |
1104 */ | |
1105 protected static bool dialogFontIsDefault() { | |
1106 FontData[] dialogFontData = JFaceResources.getFontRegistry() | |
1107 .getFontData(JFaceResources.DIALOG_FONT); | |
1108 FontData[] defaultFontData = JFaceResources.getFontRegistry() | |
1109 .getFontData(JFaceResources.DEFAULT_FONT); | |
1110 return ArrayEquals(dialogFontData, defaultFontData); | |
1111 } | |
1112 | |
1113 /* | |
1114 * (non-Javadoc) | |
1115 * | |
1116 * @see dwtx.jface.window.Window#create() | |
1117 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1118 public override void create() { |
8 | 1119 super.create(); |
1120 applyDialogFont(buttonBar); | |
1121 } | |
1122 | |
1123 /** | |
1124 * Get the IDialogBlockedHandler to be used by WizardDialogs and | |
1125 * ModalContexts. | |
1126 * | |
1127 * @return Returns the blockedHandler. | |
1128 */ | |
1129 public static IDialogBlockedHandler getBlockedHandler() { | |
1130 return blockedHandler; | |
1131 } | |
1132 | |
1133 /** | |
1134 * Set the IDialogBlockedHandler to be used by WizardDialogs and | |
1135 * ModalContexts. | |
1136 * | |
1137 * @param blockedHandler | |
1138 * The blockedHandler for the dialogs. | |
1139 */ | |
1140 public static void setBlockedHandler(IDialogBlockedHandler blockedHandler) { | |
1141 Dialog.blockedHandler = blockedHandler; | |
1142 } | |
1143 | |
1144 /** | |
1145 * Gets the dialog settings that should be used for remembering the bounds of | |
1146 * of the dialog, according to the dialog bounds strategy. | |
1147 * | |
1148 * @return settings the dialog settings used to store the dialog's location | |
1149 * and/or size, or <code>null</code> if the dialog's bounds should | |
1150 * never be stored. | |
1151 * | |
1152 * @since 3.2 | |
1153 * @see Dialog#getDialogBoundsStrategy() | |
1154 */ | |
1155 protected IDialogSettings getDialogBoundsSettings() { | |
1156 return null; | |
1157 } | |
1158 | |
1159 /** | |
1160 * Get the integer constant that describes the strategy for persisting the | |
1161 * dialog bounds. This strategy is ignored if the implementer does not also | |
1162 * specify the dialog settings for storing the bounds in | |
1163 * Dialog.getDialogBoundsSettings(). | |
1164 * | |
1165 * @return the constant describing the strategy for persisting the dialog | |
1166 * bounds. | |
1167 * | |
1168 * @since 3.2 | |
1169 * @see Dialog#DIALOG_PERSISTLOCATION | |
1170 * @see Dialog#DIALOG_PERSISTSIZE | |
1171 * @see Dialog#getDialogBoundsSettings() | |
1172 */ | |
1173 protected int getDialogBoundsStrategy() { | |
1174 return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE; | |
1175 } | |
1176 | |
1177 /** | |
1178 * Saves the bounds of the shell in the appropriate dialog settings. The | |
1179 * bounds are recorded relative to the parent shell, if there is one, or | |
1180 * display coordinates if there is no parent shell. | |
1181 * | |
1182 * @param shell | |
1183 * The shell whose bounds are to be stored | |
1184 * | |
1185 * @since 3.2 | |
1186 */ | |
1187 private void saveDialogBounds(Shell shell) { | |
1188 IDialogSettings settings = getDialogBoundsSettings(); | |
1189 if (settings !is null) { | |
1190 Point shellLocation = shell.getLocation(); | |
1191 Point shellSize = shell.getSize(); | |
1192 Shell parent = getParentShell(); | |
1193 if (parent !is null) { | |
1194 Point parentLocation = parent.getLocation(); | |
1195 shellLocation.x -= parentLocation.x; | |
1196 shellLocation.y -= parentLocation.y; | |
1197 } | |
1198 int strategy = getDialogBoundsStrategy(); | |
1199 if ((strategy & DIALOG_PERSISTLOCATION) !is 0) { | |
1200 settings.put(DIALOG_ORIGIN_X, shellLocation.x); | |
1201 settings.put(DIALOG_ORIGIN_Y, shellLocation.y); | |
1202 } | |
1203 if ((strategy & DIALOG_PERSISTSIZE) !is 0) { | |
1204 settings.put(DIALOG_WIDTH, shellSize.x); | |
1205 settings.put(DIALOG_HEIGHT, shellSize.y); | |
1206 FontData [] fontDatas = JFaceResources.getDialogFont().getFontData(); | |
1207 if (fontDatas.length > 0) { | |
1208 settings.put(DIALOG_FONT_DATA, fontDatas[0].toString()); | |
1209 } | |
1210 } | |
1211 } | |
1212 } | |
1213 | |
1214 /** | |
1215 * Returns the initial size to use for the shell. Overridden | |
1216 * to check whether a size has been stored in dialog settings. | |
1217 * If a size has been stored, it is returned. | |
1218 * | |
1219 * @return the initial size of the shell | |
1220 * | |
1221 * @since 3.2 | |
1222 * @see #getDialogBoundsSettings() | |
1223 * @see #getDialogBoundsStrategy() | |
1224 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1225 protected override Point getInitialSize() { |
8 | 1226 Point result = super.getInitialSize(); |
1227 | |
1228 // Check the dialog settings for a stored size. | |
1229 if ((getDialogBoundsStrategy() & DIALOG_PERSISTSIZE)!is 0) { | |
1230 IDialogSettings settings = getDialogBoundsSettings(); | |
1231 if (settings !is null) { | |
1232 // Check that the dialog font matches the font used | |
1233 // when the bounds was stored. If the font has changed, | |
1234 // we do not honor the stored settings. | |
1235 // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=132821 | |
1236 bool useStoredBounds = true; | |
1237 String previousDialogFontData = settings.get(DIALOG_FONT_DATA); | |
1238 // There is a previously stored font, so we will check it. | |
1239 // Note that if we haven't stored the font before, then we will | |
1240 // use the stored bounds. This allows restoring of dialog bounds | |
1241 // that were stored before we started storing the fontdata. | |
1242 if (previousDialogFontData !is null && previousDialogFontData.length > 0) { | |
1243 FontData [] fontDatas = JFaceResources.getDialogFont().getFontData(); | |
1244 if (fontDatas.length > 0) { | |
1245 String currentDialogFontData = fontDatas[0].toString(); | |
1246 useStoredBounds = currentDialogFontData.equalsIgnoreCase(previousDialogFontData); | |
1247 } | |
1248 } | |
1249 if (useStoredBounds) { | |
1250 try { | |
1251 // Get the stored width and height. | |
1252 int width = settings.getInt(DIALOG_WIDTH); | |
1253 if (width !is DIALOG_DEFAULT_BOUNDS) { | |
1254 result.x = width; | |
1255 } | |
1256 int height = settings.getInt(DIALOG_HEIGHT); | |
1257 if (height !is DIALOG_DEFAULT_BOUNDS) { | |
1258 result.y = height; | |
1259 } | |
1260 | |
1261 } catch (NumberFormatException e) { | |
1262 } | |
1263 } | |
1264 } | |
1265 } | |
1266 // No attempt is made to constrain the bounds. The default | |
1267 // constraining behavior in Window will be used. | |
1268 return result; | |
1269 } | |
1270 | |
1271 /** | |
1272 * Returns the initial location to use for the shell. Overridden | |
1273 * to check whether the bounds of the dialog have been stored in | |
1274 * dialog settings. If a location has been stored, it is returned. | |
1275 * | |
1276 * @param initialSize | |
1277 * the initial size of the shell, as returned by | |
1278 * <code>getInitialSize</code>. | |
1279 * @return the initial location of the shell | |
1280 * | |
1281 * @since 3.2 | |
1282 * @see #getDialogBoundsSettings() | |
1283 * @see #getDialogBoundsStrategy() | |
1284 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1285 protected override Point getInitialLocation(Point initialSize) { |
8 | 1286 Point result = super.getInitialLocation(initialSize); |
1287 if ((getDialogBoundsStrategy() & DIALOG_PERSISTLOCATION)!is 0) { | |
1288 IDialogSettings settings = getDialogBoundsSettings(); | |
1289 if (settings !is null) { | |
1290 try { | |
1291 int x = settings.getInt(DIALOG_ORIGIN_X); | |
1292 int y = settings.getInt(DIALOG_ORIGIN_Y); | |
1293 result = new Point(x, y); | |
1294 // The coordinates were stored relative to the parent shell. | |
1295 // Convert to display coordinates. | |
1296 Shell parent = getParentShell(); | |
1297 if (parent !is null) { | |
1298 Point parentLocation = parent.getLocation(); | |
1299 result.x += parentLocation.x; | |
1300 result.y += parentLocation.y; | |
1301 } | |
1302 } catch (NumberFormatException e) { | |
1303 } | |
1304 } | |
1305 } | |
1306 // No attempt is made to constrain the bounds. The default | |
1307 // constraining behavior in Window will be used. | |
1308 return result; | |
1309 } | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1310 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1311 /** |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1312 * Returns a bool indicating whether the dialog should be |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1313 * considered resizable when the shell style is initially |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1314 * set. |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1315 * |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1316 * This method is used to ensure that all style |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1317 * bits appropriate for resizable dialogs are added to the |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1318 * shell style. Individual dialogs may always set the shell |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1319 * style to ensure that a dialog is resizable, but using this |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1320 * method ensures that resizable dialogs will be created with |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1321 * the same set of style bits. |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1322 * |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1323 * Style bits will never be removed based on the return value |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1324 * of this method. For example, if a dialog returns |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1325 * <code>false</code>, but also sets a style bit for a |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1326 * DWT.RESIZE border, the style bit will be honored. |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1327 * |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1328 * @return a bool indicating whether the dialog is |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1329 * resizable and should have the default style bits for |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1330 * resizable dialogs |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1331 * |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1332 * @since 3.4 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1333 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1334 protected bool isResizable() { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1335 return false; |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1336 } |
8 | 1337 } |