Mercurial > projects > dwt-addons
annotate dwtx/jface/dialogs/Dialog.d @ 70:46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 01:36:46 +0200 |
parents | f44bd8465f2f |
children | 0aafcf6e5217 |
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 */ | |
387 public static IDialogBlockedHandler blockedHandler; | |
388 static this(){ | |
389 blockedHandler = new class IDialogBlockedHandler { | |
390 /* | |
391 * (non-Javadoc) | |
392 * | |
393 * @see dwtx.jface.dialogs.IDialogBlockedHandler#clearBlocked() | |
394 */ | |
395 public void clearBlocked() { | |
396 // No default behaviour | |
397 } | |
398 | |
399 /* | |
400 * (non-Javadoc) | |
401 * | |
402 * @see dwtx.jface.dialogs.IDialogBlockedHandler#showBlocked(dwtx.core.runtime.IProgressMonitor, | |
403 * dwtx.core.runtime.IStatus, java.lang.String) | |
404 */ | |
405 public void showBlocked(IProgressMonitor blocking, | |
406 IStatus blockingStatus, String blockedName) { | |
407 // No default behaviour | |
408 } | |
409 | |
410 /* | |
411 * (non-Javadoc) | |
412 * | |
413 * @see dwtx.jface.dialogs.IDialogBlockedHandler#showBlocked(dwt.widgets.Shell, | |
414 * dwtx.core.runtime.IProgressMonitor, | |
415 * dwtx.core.runtime.IStatus, java.lang.String) | |
416 */ | |
417 public void showBlocked(Shell parentShell, IProgressMonitor blocking, | |
418 IStatus blockingStatus, String blockedName) { | |
419 // No default behaviour | |
420 } | |
421 }; | |
422 } | |
423 | |
424 /** | |
425 * Creates a dialog instance. Note that the window will have no visual | |
426 * representation (no widgets) until it is told to open. By default, | |
427 * <code>open</code> blocks for dialogs. | |
428 * | |
429 * @param parentShell | |
430 * the parent shell, or <code>null</code> to create a top-level | |
431 * shell | |
432 */ | |
433 protected this(Shell parentShell) { | |
434 this(new SameShellProvider(parentShell)); | |
435 if (parentShell is null && Policy.DEBUG_DIALOG_NO_PARENT) { | |
436 Policy.getLog().log( | |
437 new Status(IStatus.INFO, Policy.JFACE, IStatus.INFO, this | |
438 .classinfo.name | |
439 ~ " created with no shell",//$NON-NLS-1$ | |
440 new Exception( null, null ))); | |
441 } | |
442 } | |
443 | |
444 /** | |
445 * Creates a dialog with the given parent. | |
446 * | |
447 * @param parentShell | |
448 * object that returns the current parent shell | |
449 * | |
450 * @since 3.1 | |
451 */ | |
452 protected this(IShellProvider parentShell) { | |
453 super(parentShell); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
454 if (isResizable()) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
455 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
|
456 | getDefaultOrientation()); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
457 } else { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
458 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
|
459 | getDefaultOrientation()); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
460 } |
8 | 461 setBlockOnOpen(true); |
462 } | |
463 | |
464 /** | |
465 * Notifies that this dialog's button with the given id has been pressed. | |
466 * <p> | |
467 * The <code>Dialog</code> implementation of this framework method calls | |
468 * <code>okPressed</code> if the ok button is the pressed, and | |
469 * <code>cancelPressed</code> if the cancel button is the pressed. All | |
470 * other button presses are ignored. Subclasses may override to handle other | |
471 * buttons, but should call <code>super.buttonPressed</code> if the | |
472 * default handling of the ok and cancel buttons is desired. | |
473 * </p> | |
474 * | |
475 * @param buttonId | |
476 * the id of the button that was pressed (see | |
477 * <code>IDialogConstants.*_ID</code> constants) | |
478 */ | |
479 protected void buttonPressed(int buttonId) { | |
480 if (IDialogConstants.OK_ID is buttonId) { | |
481 okPressed(); | |
482 } else if (IDialogConstants.CANCEL_ID is buttonId) { | |
483 cancelPressed(); | |
484 } | |
485 } | |
486 | |
487 /** | |
488 * Notifies that the cancel button of this dialog has been pressed. | |
489 * <p> | |
490 * The <code>Dialog</code> implementation of this framework method sets | |
491 * this dialog's return code to <code>Window.CANCEL</code> and closes the | |
492 * dialog. Subclasses may override if desired. | |
493 * </p> | |
494 */ | |
495 protected void cancelPressed() { | |
496 setReturnCode(CANCEL); | |
497 close(); | |
498 } | |
499 | |
500 /** | |
501 * Returns the number of pixels corresponding to the height of the given | |
502 * number of characters. | |
503 * <p> | |
504 * This method may only be called after <code>initializeDialogUnits</code> | |
505 * has been called. | |
506 * </p> | |
507 * <p> | |
508 * Clients may call this framework method, but should not override it. | |
509 * </p> | |
510 * | |
511 * @param chars | |
512 * the number of characters | |
513 * @return the number of pixels | |
514 */ | |
515 protected int convertHeightInCharsToPixels(int chars) { | |
516 // test for failure to initialize for backward compatibility | |
517 if (fontMetrics is null) { | |
518 return 0; | |
519 } | |
520 return convertHeightInCharsToPixels(fontMetrics, chars); | |
521 } | |
522 | |
523 /** | |
524 * Returns the number of pixels corresponding to the given number of | |
525 * horizontal dialog units. | |
526 * <p> | |
527 * This method may only be called after <code>initializeDialogUnits</code> | |
528 * has been called. | |
529 * </p> | |
530 * <p> | |
531 * Clients may call this framework method, but should not override it. | |
532 * </p> | |
533 * | |
534 * @param dlus | |
535 * the number of horizontal dialog units | |
536 * @return the number of pixels | |
537 */ | |
538 protected int convertHorizontalDLUsToPixels(int dlus) { | |
539 // test for failure to initialize for backward compatibility | |
540 if (fontMetrics is null) { | |
541 return 0; | |
542 } | |
543 return convertHorizontalDLUsToPixels(fontMetrics, dlus); | |
544 } | |
545 | |
546 /** | |
547 * Returns the number of pixels corresponding to the given number of | |
548 * vertical dialog units. | |
549 * <p> | |
550 * This method may only be called after <code>initializeDialogUnits</code> | |
551 * has been called. | |
552 * </p> | |
553 * <p> | |
554 * Clients may call this framework method, but should not override it. | |
555 * </p> | |
556 * | |
557 * @param dlus | |
558 * the number of vertical dialog units | |
559 * @return the number of pixels | |
560 */ | |
561 protected int convertVerticalDLUsToPixels(int dlus) { | |
562 // test for failure to initialize for backward compatibility | |
563 if (fontMetrics is null) { | |
564 return 0; | |
565 } | |
566 return convertVerticalDLUsToPixels(fontMetrics, dlus); | |
567 } | |
568 | |
569 /** | |
570 * Returns the number of pixels corresponding to the width of the given | |
571 * number of characters. | |
572 * <p> | |
573 * This method may only be called after <code>initializeDialogUnits</code> | |
574 * has been called. | |
575 * </p> | |
576 * <p> | |
577 * Clients may call this framework method, but should not override it. | |
578 * </p> | |
579 * | |
580 * @param chars | |
581 * the number of characters | |
582 * @return the number of pixels | |
583 */ | |
584 protected int convertWidthInCharsToPixels(int chars) { | |
585 // test for failure to initialize for backward compatibility | |
586 if (fontMetrics is null) { | |
587 return 0; | |
588 } | |
589 return convertWidthInCharsToPixels(fontMetrics, chars); | |
590 } | |
591 | |
592 /** | |
593 * Creates a new button with the given id. | |
594 * <p> | |
595 * The <code>Dialog</code> implementation of this framework method creates | |
596 * a standard push button, registers it for selection events including | |
597 * button presses, and registers default buttons with its shell. The button | |
598 * id is stored as the button's client data. If the button id is | |
599 * <code>IDialogConstants.CANCEL_ID</code>, the new button will be | |
600 * accessible from <code>getCancelButton()</code>. If the button id is | |
601 * <code>IDialogConstants.OK_ID</code>, the new button will be accesible | |
602 * from <code>getOKButton()</code>. Note that the parent's layout is | |
603 * assumed to be a <code>GridLayout</code> and the number of columns in | |
604 * this layout is incremented. Subclasses may override. | |
605 * </p> | |
606 * | |
607 * @param parent | |
608 * the parent composite | |
609 * @param id | |
610 * the id of the button (see <code>IDialogConstants.*_ID</code> | |
611 * constants for standard dialog button ids) | |
612 * @param label | |
613 * the label from the button | |
614 * @param defaultButton | |
615 * <code>true</code> if the button is to be the default button, | |
616 * and <code>false</code> otherwise | |
617 * | |
618 * @return the new button | |
619 * | |
620 * @see #getCancelButton | |
621 * @see #getOKButton() | |
622 */ | |
623 protected Button createButton(Composite parent, int id, String label, | |
624 bool defaultButton) { | |
625 // increment the number of columns in the button bar | |
626 (cast(GridLayout) parent.getLayout()).numColumns++; | |
627 Button button = new Button(parent, DWT.PUSH); | |
628 button.setText(label); | |
629 button.setFont(JFaceResources.getDialogFont()); | |
630 button.setData(new ValueWrapperInt(id)); | |
631 button.addSelectionListener(new class SelectionAdapter { | |
632 public void widgetSelected(SelectionEvent event) { | |
633 buttonPressed((cast(ValueWrapperInt) event.widget.getData()).value); | |
634 } | |
635 }); | |
636 if (defaultButton) { | |
637 Shell shell = parent.getShell(); | |
638 if (shell !is null) { | |
639 shell.setDefaultButton(button); | |
640 } | |
641 } | |
642 buttons[id] = button; | |
643 setButtonLayoutData(button); | |
644 return button; | |
645 } | |
646 | |
647 /** | |
648 * Creates and returns the contents of this dialog's button bar. | |
649 * <p> | |
650 * The <code>Dialog</code> implementation of this framework method lays | |
651 * out a button bar and calls the <code>createButtonsForButtonBar</code> | |
652 * framework method to populate it. Subclasses may override. | |
653 * </p> | |
654 * <p> | |
655 * The returned control's layout data must be an instance of | |
656 * <code>GridData</code>. | |
657 * </p> | |
658 * | |
659 * @param parent | |
660 * the parent composite to contain the button bar | |
661 * @return the button bar control | |
662 */ | |
663 protected Control createButtonBar(Composite parent) { | |
664 Composite composite = new Composite(parent, DWT.NONE); | |
665 // create a layout with spacing and margins appropriate for the font | |
666 // size. | |
667 GridLayout layout = new GridLayout(); | |
668 layout.numColumns = 0; // this is incremented by createButton | |
669 layout.makeColumnsEqualWidth = true; | |
670 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); | |
671 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); | |
672 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); | |
673 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); | |
674 composite.setLayout(layout); | |
675 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END | |
676 | GridData.VERTICAL_ALIGN_CENTER); | |
677 composite.setLayoutData(data); | |
678 composite.setFont(parent.getFont()); | |
679 | |
680 // Add the buttons to the button bar. | |
681 createButtonsForButtonBar(composite); | |
682 return composite; | |
683 } | |
684 | |
685 /** | |
686 * Adds buttons to this dialog's button bar. | |
687 * <p> | |
688 * The <code>Dialog</code> implementation of this framework method adds | |
689 * standard ok and cancel buttons using the <code>createButton</code> | |
690 * framework method. These standard buttons will be accessible from | |
691 * <code>getCancelButton</code>, and <code>getOKButton</code>. | |
692 * Subclasses may override. | |
693 * </p> | |
694 * | |
695 * @param parent | |
696 * the button bar composite | |
697 */ | |
698 protected void createButtonsForButtonBar(Composite parent) { | |
699 // create OK and Cancel buttons by default | |
700 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, | |
701 true); | |
702 createButton(parent, IDialogConstants.CANCEL_ID, | |
703 IDialogConstants.CANCEL_LABEL, false); | |
704 } | |
705 | |
706 /* | |
707 * @see Window.initializeBounds() | |
708 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
709 protected override void initializeBounds() { |
8 | 710 String platform = DWT.getPlatform(); |
711 if ("carbon".equals(platform)) { //$NON-NLS-1$ | |
712 // On Mac OS X the default button must be the right-most button | |
713 Shell shell = getShell(); | |
714 if (shell !is null) { | |
715 Button defaultButton = shell.getDefaultButton(); | |
716 if (defaultButton !is null | |
717 && isContained(buttonBar, defaultButton)) { | |
718 defaultButton.moveBelow(null); | |
719 } | |
720 } | |
721 } | |
722 | |
723 super.initializeBounds(); | |
724 } | |
725 | |
726 /** | |
727 * Returns true if the given Control is a direct or indirect child of | |
728 * container. | |
729 * | |
730 * @param container | |
731 * the potential parent | |
732 * @param control | |
733 * @return bool <code>true</code> if control is a child of container | |
734 */ | |
735 private bool isContained(Control container, Control control) { | |
736 Composite parent; | |
737 while ((parent = control.getParent()) !is null) { | |
738 if (parent is container) { | |
739 return true; | |
740 } | |
741 control = parent; | |
742 } | |
743 return false; | |
744 } | |
745 | |
746 /** | |
747 * The <code>Dialog</code> implementation of this <code>Window</code> | |
748 * method creates and lays out the top level composite for the dialog, and | |
749 * determines the appropriate horizontal and vertical dialog units based on | |
750 * the font size. It then calls the <code>createDialogArea</code> and | |
751 * <code>createButtonBar</code> methods to create the dialog area and | |
752 * button bar, respectively. Overriding <code>createDialogArea</code> and | |
753 * <code>createButtonBar</code> are recommended rather than overriding | |
754 * this method. | |
755 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
756 protected override Control createContents(Composite parent) { |
8 | 757 // create the top level composite for the dialog |
758 Composite composite = new Composite(parent, 0); | |
759 GridLayout layout = new GridLayout(); | |
760 layout.marginHeight = 0; | |
761 layout.marginWidth = 0; | |
762 layout.verticalSpacing = 0; | |
763 composite.setLayout(layout); | |
764 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
765 applyDialogFont(composite); | |
766 // initialize the dialog units | |
767 initializeDialogUnits(composite); | |
768 // create the dialog area and button bar | |
769 dialogArea = createDialogArea(composite); | |
770 buttonBar = createButtonBar(composite); | |
771 | |
772 return composite; | |
773 } | |
774 | |
775 /** | |
776 * Creates and returns the contents of the upper part of this dialog (above | |
777 * the button bar). | |
778 * <p> | |
779 * The <code>Dialog</code> implementation of this framework method creates | |
780 * and returns a new <code>Composite</code> with standard margins and | |
781 * spacing. | |
782 * </p> | |
783 * <p> | |
784 * The returned control's layout data must be an instance of | |
785 * <code>GridData</code>. This method must not modify the parent's | |
786 * layout. | |
787 * </p> | |
788 * <p> | |
789 * Subclasses must override this method but may call <code>super</code> as | |
790 * in the following example: | |
791 * </p> | |
792 * | |
793 * <pre> | |
794 * Composite composite = (Composite) super.createDialogArea(parent); | |
795 * //add controls to composite as necessary | |
796 * return composite; | |
797 * </pre> | |
798 * | |
799 * @param parent | |
800 * the parent composite to contain the dialog area | |
801 * @return the dialog area control | |
802 */ | |
803 protected Control createDialogArea(Composite parent) { | |
804 // create a composite with standard margins and spacing | |
805 Composite composite = new Composite(parent, DWT.NONE); | |
806 GridLayout layout = new GridLayout(); | |
807 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); | |
808 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); | |
809 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); | |
810 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); | |
811 composite.setLayout(layout); | |
812 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
813 applyDialogFont(composite); | |
814 return composite; | |
815 } | |
816 | |
817 /** | |
818 * Returns the button created by the method <code>createButton</code> for | |
819 * the specified ID as defined on <code>IDialogConstants</code>. If | |
820 * <code>createButton</code> was never called with this ID, or if | |
821 * <code>createButton</code> is overridden, this method will return | |
822 * <code>null</code>. | |
823 * | |
824 * @param id | |
825 * the id of the button to look for | |
826 * | |
827 * @return the button for the ID or <code>null</code> | |
828 * | |
829 * @see #createButton(Composite, int, String, bool) | |
830 * @since 2.0 | |
831 */ | |
832 protected Button getButton(int id) { | |
60 | 833 if( auto btn = id in buttons ){ |
834 return *btn; | |
835 } | |
836 return null; | |
8 | 837 } |
838 | |
839 /** | |
840 * Returns the button bar control. | |
841 * <p> | |
842 * Clients may call this framework method, but should not override it. | |
843 * </p> | |
844 * | |
845 * @return the button bar, or <code>null</code> if the button bar has not | |
846 * been created yet | |
847 */ | |
848 protected Control getButtonBar() { | |
849 return buttonBar; | |
850 } | |
851 | |
852 /** | |
853 * Returns the button created when <code>createButton</code> is called | |
854 * with an ID of <code>IDialogConstants.CANCEL_ID</code>. If | |
855 * <code>createButton</code> was never called with this parameter, or if | |
856 * <code>createButton</code> is overridden, <code>getCancelButton</code> | |
857 * will return <code>null</code>. | |
858 * | |
859 * @return the cancel button or <code>null</code> | |
860 * | |
861 * @see #createButton(Composite, int, String, bool) | |
862 * @since 2.0 | |
863 * @deprecated Use <code>getButton(IDialogConstants.CANCEL_ID)</code> | |
864 * instead. This method will be removed soon. | |
865 */ | |
866 protected Button getCancelButton() { | |
867 return getButton(IDialogConstants.CANCEL_ID); | |
868 } | |
869 | |
870 /** | |
871 * Returns the dialog area control. | |
872 * <p> | |
873 * Clients may call this framework method, but should not override it. | |
874 * </p> | |
875 * | |
876 * @return the dialog area, or <code>null</code> if the dialog area has | |
877 * not been created yet | |
878 */ | |
879 protected Control getDialogArea() { | |
880 return dialogArea; | |
881 } | |
882 | |
883 /** | |
884 * Returns the standard dialog image with the given key. Note that these | |
885 * images are managed by the dialog framework, and must not be disposed by | |
886 * another party. | |
887 * | |
888 * @param key | |
889 * one of the <code>Dialog.DLG_IMG_* </code> constants | |
890 * @return the standard dialog image | |
891 * | |
892 * NOTE: Dialog does not use the following images in the registry | |
893 * DLG_IMG_ERROR DLG_IMG_INFO DLG_IMG_QUESTION DLG_IMG_WARNING | |
894 * | |
895 * They are now coming directly from DWT, see ImageRegistry. For backwards | |
896 * compatibility they are still supported, however new code should use DWT | |
897 * for these. | |
898 * | |
899 * @see Display#getSystemImage(int) | |
900 */ | |
901 public static Image getImage(String key) { | |
902 return JFaceResources.getImageRegistry().get(key); | |
903 } | |
904 | |
905 /** | |
906 * Returns the button created when <code>createButton</code> is called | |
907 * with an ID of <code>IDialogConstants.OK_ID</code>. If | |
908 * <code>createButton</code> was never called with this parameter, or if | |
909 * <code>createButton</code> is overridden, <code>getOKButton</code> | |
910 * will return <code>null</code>. | |
911 * | |
912 * @return the OK button or <code>null</code> | |
913 * | |
914 * @see #createButton(Composite, int, String, bool) | |
915 * @since 2.0 | |
916 * @deprecated Use <code>getButton(IDialogConstants.OK_ID)</code> instead. | |
917 * This method will be removed soon. | |
918 */ | |
919 protected Button getOKButton() { | |
920 return getButton(IDialogConstants.OK_ID); | |
921 } | |
922 | |
923 /** | |
924 * Initializes the computation of horizontal and vertical dialog units based | |
925 * on the size of current font. | |
926 * <p> | |
927 * This method must be called before any of the dialog unit based conversion | |
928 * methods are called. | |
929 * </p> | |
930 * | |
931 * @param control | |
932 * a control from which to obtain the current font | |
933 */ | |
934 protected void initializeDialogUnits(Control control) { | |
935 // Compute and store a font metric | |
936 GC gc = new GC(control); | |
937 gc.setFont(JFaceResources.getDialogFont()); | |
938 fontMetrics = gc.getFontMetrics(); | |
939 gc.dispose(); | |
940 } | |
941 | |
942 /** | |
943 * Notifies that the ok button of this dialog has been pressed. | |
944 * <p> | |
945 * The <code>Dialog</code> implementation of this framework method sets | |
946 * this dialog's return code to <code>Window.OK</code> and closes the | |
947 * dialog. Subclasses may override. | |
948 * </p> | |
949 */ | |
950 protected void okPressed() { | |
951 setReturnCode(OK); | |
952 close(); | |
953 } | |
954 | |
955 /** | |
956 * Set the layout data of the button to a GridData with appropriate heights | |
957 * and widths. | |
958 * | |
959 * @param button | |
960 */ | |
961 protected void setButtonLayoutData(Button button) { | |
962 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
963 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); | |
964 Point minSize = button.computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | |
965 data.widthHint = Math.max(widthHint, minSize.x); | |
966 button.setLayoutData(data); | |
967 } | |
968 | |
969 /** | |
970 * Set the layout data of the button to a FormData with appropriate heights | |
971 * and widths. | |
972 * | |
973 * @param button | |
974 */ | |
975 protected void setButtonLayoutFormData(Button button) { | |
976 FormData data = new FormData(); | |
977 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); | |
978 Point minSize = button.computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | |
979 data.width = Math.max(widthHint, minSize.x); | |
980 button.setLayoutData(data); | |
981 } | |
982 | |
983 /** | |
984 * @see dwtx.jface.window.Window#close() | |
985 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
986 public override bool close() { |
8 | 987 if (getShell() !is null && !getShell().isDisposed()) { |
988 saveDialogBounds(getShell()); | |
989 } | |
990 | |
991 bool returnValue = super.close(); | |
992 if (returnValue) { | |
993 buttons = null; | |
994 buttonBar = null; | |
995 dialogArea = null; | |
996 } | |
997 return returnValue; | |
998 } | |
999 | |
1000 /** | |
1001 * Applies the dialog font to all controls that currently have the default | |
1002 * font. | |
1003 * | |
1004 * @param control | |
1005 * the control to apply the font to. Font will also be applied to | |
1006 * its children. If the control is <code>null</code> nothing | |
1007 * happens. | |
1008 */ | |
1009 public static void applyDialogFont(Control control) { | |
1010 if (control is null || dialogFontIsDefault()) { | |
1011 return; | |
1012 } | |
1013 Font dialogFont = JFaceResources.getDialogFont(); | |
1014 applyDialogFont(control, dialogFont); | |
1015 } | |
1016 | |
1017 /** | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1018 * Sets the dialog font on the control and any of its children if their font |
8 | 1019 * is not otherwise set. |
1020 * | |
1021 * @param control | |
1022 * the control to apply the font to. Font will also be applied to | |
1023 * its children. | |
1024 * @param dialogFont | |
1025 * the dialog font to set | |
1026 */ | |
1027 private static void applyDialogFont(Control control, Font dialogFont) { | |
1028 if (hasDefaultFont(control)) { | |
1029 control.setFont(dialogFont); | |
1030 } | |
1031 if ( auto comp = cast(Composite)control ) { | |
1032 Control[] children = comp.getChildren(); | |
1033 for (int i = 0; i < children.length; i++) { | |
1034 applyDialogFont(children[i], dialogFont); | |
1035 } | |
1036 } | |
1037 } | |
1038 | |
1039 /** | |
1040 * Return whether or not this control has the same font as it's default. | |
1041 * | |
1042 * @param control | |
1043 * Control | |
1044 * @return bool | |
1045 */ | |
1046 private static bool hasDefaultFont(Control control) { | |
1047 FontData[] controlFontData = control.getFont().getFontData(); | |
1048 FontData[] defaultFontData = getDefaultFont(control).getFontData(); | |
1049 if (controlFontData.length is defaultFontData.length) { | |
1050 for (int i = 0; i < controlFontData.length; i++) { | |
1051 if (controlFontData[i].opEquals(defaultFontData[i])) { | |
1052 continue; | |
1053 } | |
1054 return false; | |
1055 } | |
1056 return true; | |
1057 } | |
1058 return false; | |
1059 } | |
1060 | |
1061 /** | |
1062 * Get the default font for this type of control. | |
1063 * | |
1064 * @param control | |
1065 * @return the default font | |
1066 */ | |
1067 private static Font getDefaultFont(Control control) { | |
1068 String fontName = "DEFAULT_FONT_" ~ control.classinfo.name; //$NON-NLS-1$ | |
1069 if (JFaceResources.getFontRegistry().hasValueFor(fontName)) { | |
1070 return JFaceResources.getFontRegistry().get(fontName); | |
1071 } | |
1072 Font cached = control.getFont(); | |
1073 control.setFont(null); | |
1074 Font defaultFont = control.getFont(); | |
1075 control.setFont(cached); | |
1076 JFaceResources.getFontRegistry().put(fontName, | |
1077 defaultFont.getFontData()); | |
1078 return defaultFont; | |
1079 } | |
1080 | |
1081 /** | |
1082 * Return whether or not the dialog font is currently the same as the | |
1083 * default font. | |
1084 * | |
1085 * @return bool if the two are the same | |
1086 */ | |
1087 protected static bool dialogFontIsDefault() { | |
1088 FontData[] dialogFontData = JFaceResources.getFontRegistry() | |
1089 .getFontData(JFaceResources.DIALOG_FONT); | |
1090 FontData[] defaultFontData = JFaceResources.getFontRegistry() | |
1091 .getFontData(JFaceResources.DEFAULT_FONT); | |
1092 return ArrayEquals(dialogFontData, defaultFontData); | |
1093 } | |
1094 | |
1095 /* | |
1096 * (non-Javadoc) | |
1097 * | |
1098 * @see dwtx.jface.window.Window#create() | |
1099 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1100 public override void create() { |
8 | 1101 super.create(); |
1102 applyDialogFont(buttonBar); | |
1103 } | |
1104 | |
1105 /** | |
1106 * Get the IDialogBlockedHandler to be used by WizardDialogs and | |
1107 * ModalContexts. | |
1108 * | |
1109 * @return Returns the blockedHandler. | |
1110 */ | |
1111 public static IDialogBlockedHandler getBlockedHandler() { | |
1112 return blockedHandler; | |
1113 } | |
1114 | |
1115 /** | |
1116 * Set the IDialogBlockedHandler to be used by WizardDialogs and | |
1117 * ModalContexts. | |
1118 * | |
1119 * @param blockedHandler | |
1120 * The blockedHandler for the dialogs. | |
1121 */ | |
1122 public static void setBlockedHandler(IDialogBlockedHandler blockedHandler) { | |
1123 Dialog.blockedHandler = blockedHandler; | |
1124 } | |
1125 | |
1126 /** | |
1127 * Gets the dialog settings that should be used for remembering the bounds of | |
1128 * of the dialog, according to the dialog bounds strategy. | |
1129 * | |
1130 * @return settings the dialog settings used to store the dialog's location | |
1131 * and/or size, or <code>null</code> if the dialog's bounds should | |
1132 * never be stored. | |
1133 * | |
1134 * @since 3.2 | |
1135 * @see Dialog#getDialogBoundsStrategy() | |
1136 */ | |
1137 protected IDialogSettings getDialogBoundsSettings() { | |
1138 return null; | |
1139 } | |
1140 | |
1141 /** | |
1142 * Get the integer constant that describes the strategy for persisting the | |
1143 * dialog bounds. This strategy is ignored if the implementer does not also | |
1144 * specify the dialog settings for storing the bounds in | |
1145 * Dialog.getDialogBoundsSettings(). | |
1146 * | |
1147 * @return the constant describing the strategy for persisting the dialog | |
1148 * bounds. | |
1149 * | |
1150 * @since 3.2 | |
1151 * @see Dialog#DIALOG_PERSISTLOCATION | |
1152 * @see Dialog#DIALOG_PERSISTSIZE | |
1153 * @see Dialog#getDialogBoundsSettings() | |
1154 */ | |
1155 protected int getDialogBoundsStrategy() { | |
1156 return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE; | |
1157 } | |
1158 | |
1159 /** | |
1160 * Saves the bounds of the shell in the appropriate dialog settings. The | |
1161 * bounds are recorded relative to the parent shell, if there is one, or | |
1162 * display coordinates if there is no parent shell. | |
1163 * | |
1164 * @param shell | |
1165 * The shell whose bounds are to be stored | |
1166 * | |
1167 * @since 3.2 | |
1168 */ | |
1169 private void saveDialogBounds(Shell shell) { | |
1170 IDialogSettings settings = getDialogBoundsSettings(); | |
1171 if (settings !is null) { | |
1172 Point shellLocation = shell.getLocation(); | |
1173 Point shellSize = shell.getSize(); | |
1174 Shell parent = getParentShell(); | |
1175 if (parent !is null) { | |
1176 Point parentLocation = parent.getLocation(); | |
1177 shellLocation.x -= parentLocation.x; | |
1178 shellLocation.y -= parentLocation.y; | |
1179 } | |
1180 int strategy = getDialogBoundsStrategy(); | |
1181 if ((strategy & DIALOG_PERSISTLOCATION) !is 0) { | |
1182 settings.put(DIALOG_ORIGIN_X, shellLocation.x); | |
1183 settings.put(DIALOG_ORIGIN_Y, shellLocation.y); | |
1184 } | |
1185 if ((strategy & DIALOG_PERSISTSIZE) !is 0) { | |
1186 settings.put(DIALOG_WIDTH, shellSize.x); | |
1187 settings.put(DIALOG_HEIGHT, shellSize.y); | |
1188 FontData [] fontDatas = JFaceResources.getDialogFont().getFontData(); | |
1189 if (fontDatas.length > 0) { | |
1190 settings.put(DIALOG_FONT_DATA, fontDatas[0].toString()); | |
1191 } | |
1192 } | |
1193 } | |
1194 } | |
1195 | |
1196 /** | |
1197 * Returns the initial size to use for the shell. Overridden | |
1198 * to check whether a size has been stored in dialog settings. | |
1199 * If a size has been stored, it is returned. | |
1200 * | |
1201 * @return the initial size of the shell | |
1202 * | |
1203 * @since 3.2 | |
1204 * @see #getDialogBoundsSettings() | |
1205 * @see #getDialogBoundsStrategy() | |
1206 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1207 protected override Point getInitialSize() { |
8 | 1208 Point result = super.getInitialSize(); |
1209 | |
1210 // Check the dialog settings for a stored size. | |
1211 if ((getDialogBoundsStrategy() & DIALOG_PERSISTSIZE)!is 0) { | |
1212 IDialogSettings settings = getDialogBoundsSettings(); | |
1213 if (settings !is null) { | |
1214 // Check that the dialog font matches the font used | |
1215 // when the bounds was stored. If the font has changed, | |
1216 // we do not honor the stored settings. | |
1217 // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=132821 | |
1218 bool useStoredBounds = true; | |
1219 String previousDialogFontData = settings.get(DIALOG_FONT_DATA); | |
1220 // There is a previously stored font, so we will check it. | |
1221 // Note that if we haven't stored the font before, then we will | |
1222 // use the stored bounds. This allows restoring of dialog bounds | |
1223 // that were stored before we started storing the fontdata. | |
1224 if (previousDialogFontData !is null && previousDialogFontData.length > 0) { | |
1225 FontData [] fontDatas = JFaceResources.getDialogFont().getFontData(); | |
1226 if (fontDatas.length > 0) { | |
1227 String currentDialogFontData = fontDatas[0].toString(); | |
1228 useStoredBounds = currentDialogFontData.equalsIgnoreCase(previousDialogFontData); | |
1229 } | |
1230 } | |
1231 if (useStoredBounds) { | |
1232 try { | |
1233 // Get the stored width and height. | |
1234 int width = settings.getInt(DIALOG_WIDTH); | |
1235 if (width !is DIALOG_DEFAULT_BOUNDS) { | |
1236 result.x = width; | |
1237 } | |
1238 int height = settings.getInt(DIALOG_HEIGHT); | |
1239 if (height !is DIALOG_DEFAULT_BOUNDS) { | |
1240 result.y = height; | |
1241 } | |
1242 | |
1243 } catch (NumberFormatException e) { | |
1244 } | |
1245 } | |
1246 } | |
1247 } | |
1248 // No attempt is made to constrain the bounds. The default | |
1249 // constraining behavior in Window will be used. | |
1250 return result; | |
1251 } | |
1252 | |
1253 /** | |
1254 * Returns the initial location to use for the shell. Overridden | |
1255 * to check whether the bounds of the dialog have been stored in | |
1256 * dialog settings. If a location has been stored, it is returned. | |
1257 * | |
1258 * @param initialSize | |
1259 * the initial size of the shell, as returned by | |
1260 * <code>getInitialSize</code>. | |
1261 * @return the initial location of the shell | |
1262 * | |
1263 * @since 3.2 | |
1264 * @see #getDialogBoundsSettings() | |
1265 * @see #getDialogBoundsStrategy() | |
1266 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1267 protected override Point getInitialLocation(Point initialSize) { |
8 | 1268 Point result = super.getInitialLocation(initialSize); |
1269 if ((getDialogBoundsStrategy() & DIALOG_PERSISTLOCATION)!is 0) { | |
1270 IDialogSettings settings = getDialogBoundsSettings(); | |
1271 if (settings !is null) { | |
1272 try { | |
1273 int x = settings.getInt(DIALOG_ORIGIN_X); | |
1274 int y = settings.getInt(DIALOG_ORIGIN_Y); | |
1275 result = new Point(x, y); | |
1276 // The coordinates were stored relative to the parent shell. | |
1277 // Convert to display coordinates. | |
1278 Shell parent = getParentShell(); | |
1279 if (parent !is null) { | |
1280 Point parentLocation = parent.getLocation(); | |
1281 result.x += parentLocation.x; | |
1282 result.y += parentLocation.y; | |
1283 } | |
1284 } catch (NumberFormatException e) { | |
1285 } | |
1286 } | |
1287 } | |
1288 // No attempt is made to constrain the bounds. The default | |
1289 // constraining behavior in Window will be used. | |
1290 return result; | |
1291 } | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1292 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1293 /** |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1294 * 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
|
1295 * 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
|
1296 * set. |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1297 * |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1298 * 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
|
1299 * 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
|
1300 * 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
|
1301 * 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
|
1302 * 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
|
1303 * the same set of style bits. |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1304 * |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1305 * 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
|
1306 * 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
|
1307 * <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
|
1308 * 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
|
1309 * |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1310 * @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
|
1311 * 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
|
1312 * resizable dialogs |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1313 * |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1314 * @since 3.4 |
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 protected bool isResizable() { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1317 return false; |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
60
diff
changeset
|
1318 } |
8 | 1319 } |