Mercurial > projects > dwt-addons
annotate dwtx/jface/text/AbstractInformationControlManager.d @ 161:f8d52b926852
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:49:30 +0200 |
parents | 3678e4f1a766 |
children | 1a5b8f8129df |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
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 | |
10 * Sean Montgomery, sean_montgomery@comcast.net - https://bugs.eclipse.org/bugs/show_bug.cgi?id=45095 | |
11 * Port to the D programming language: | |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | |
14 | |
131 | 15 |
151 | 16 module dwtx.jface.text.AbstractInformationControlManager; |
17 | |
131 | 18 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport |
19 import dwtx.jface.text.DefaultTextHover; // packageimport | |
20 import dwtx.jface.text.AbstractInformationControl; // packageimport | |
21 import dwtx.jface.text.TextUtilities; // packageimport | |
22 import dwtx.jface.text.IInformationControlCreatorExtension; // packageimport | |
23 import dwtx.jface.text.ITextViewerExtension2; // packageimport | |
24 import dwtx.jface.text.IDocumentPartitioner; // packageimport | |
25 import dwtx.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport | |
26 import dwtx.jface.text.ITextSelection; // packageimport | |
27 import dwtx.jface.text.Document; // packageimport | |
28 import dwtx.jface.text.FindReplaceDocumentAdapterContentProposalProvider; // packageimport | |
29 import dwtx.jface.text.ITextListener; // packageimport | |
30 import dwtx.jface.text.BadPartitioningException; // packageimport | |
31 import dwtx.jface.text.ITextViewerExtension5; // packageimport | |
32 import dwtx.jface.text.IDocumentPartitionerExtension3; // packageimport | |
33 import dwtx.jface.text.IUndoManager; // packageimport | |
34 import dwtx.jface.text.ITextHoverExtension2; // packageimport | |
35 import dwtx.jface.text.IRepairableDocument; // packageimport | |
36 import dwtx.jface.text.IRewriteTarget; // packageimport | |
37 import dwtx.jface.text.DefaultPositionUpdater; // packageimport | |
38 import dwtx.jface.text.RewriteSessionEditProcessor; // packageimport | |
39 import dwtx.jface.text.TextViewerHoverManager; // packageimport | |
40 import dwtx.jface.text.DocumentRewriteSession; // packageimport | |
41 import dwtx.jface.text.TextViewer; // packageimport | |
42 import dwtx.jface.text.ITextViewerExtension8; // packageimport | |
43 import dwtx.jface.text.RegExMessages; // packageimport | |
44 import dwtx.jface.text.IDelayedInputChangeProvider; // packageimport | |
45 import dwtx.jface.text.ITextOperationTargetExtension; // packageimport | |
46 import dwtx.jface.text.IWidgetTokenOwner; // packageimport | |
47 import dwtx.jface.text.IViewportListener; // packageimport | |
48 import dwtx.jface.text.GapTextStore; // packageimport | |
49 import dwtx.jface.text.MarkSelection; // packageimport | |
50 import dwtx.jface.text.IDocumentPartitioningListenerExtension; // packageimport | |
51 import dwtx.jface.text.IDocumentAdapterExtension; // packageimport | |
52 import dwtx.jface.text.IInformationControlExtension; // packageimport | |
53 import dwtx.jface.text.IDocumentPartitioningListenerExtension2; // packageimport | |
54 import dwtx.jface.text.DefaultDocumentAdapter; // packageimport | |
55 import dwtx.jface.text.ITextViewerExtension3; // packageimport | |
56 import dwtx.jface.text.IInformationControlCreator; // packageimport | |
57 import dwtx.jface.text.TypedRegion; // packageimport | |
58 import dwtx.jface.text.ISynchronizable; // packageimport | |
59 import dwtx.jface.text.IMarkRegionTarget; // packageimport | |
60 import dwtx.jface.text.TextViewerUndoManager; // packageimport | |
61 import dwtx.jface.text.IRegion; // packageimport | |
62 import dwtx.jface.text.IInformationControlExtension2; // packageimport | |
63 import dwtx.jface.text.IDocumentExtension4; // packageimport | |
64 import dwtx.jface.text.IDocumentExtension2; // packageimport | |
65 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport | |
161 | 66 // import dwtx.jface.text.Assert; // packageimport |
131 | 67 import dwtx.jface.text.DefaultInformationControl; // packageimport |
68 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport | |
69 import dwtx.jface.text.DocumentClone; // packageimport | |
70 import dwtx.jface.text.DefaultUndoManager; // packageimport | |
71 import dwtx.jface.text.IFindReplaceTarget; // packageimport | |
72 import dwtx.jface.text.IAutoEditStrategy; // packageimport | |
73 import dwtx.jface.text.ILineTrackerExtension; // packageimport | |
74 import dwtx.jface.text.IUndoManagerExtension; // packageimport | |
75 import dwtx.jface.text.TextSelection; // packageimport | |
76 import dwtx.jface.text.DefaultAutoIndentStrategy; // packageimport | |
77 import dwtx.jface.text.IAutoIndentStrategy; // packageimport | |
78 import dwtx.jface.text.IPainter; // packageimport | |
79 import dwtx.jface.text.IInformationControl; // packageimport | |
80 import dwtx.jface.text.IInformationControlExtension3; // packageimport | |
81 import dwtx.jface.text.ITextViewerExtension6; // packageimport | |
82 import dwtx.jface.text.IInformationControlExtension4; // packageimport | |
83 import dwtx.jface.text.DefaultLineTracker; // packageimport | |
84 import dwtx.jface.text.IDocumentInformationMappingExtension; // packageimport | |
85 import dwtx.jface.text.IRepairableDocumentExtension; // packageimport | |
86 import dwtx.jface.text.ITextHover; // packageimport | |
87 import dwtx.jface.text.FindReplaceDocumentAdapter; // packageimport | |
88 import dwtx.jface.text.ILineTracker; // packageimport | |
89 import dwtx.jface.text.Line; // packageimport | |
90 import dwtx.jface.text.ITextViewerExtension; // packageimport | |
91 import dwtx.jface.text.IDocumentAdapter; // packageimport | |
92 import dwtx.jface.text.TextEvent; // packageimport | |
93 import dwtx.jface.text.BadLocationException; // packageimport | |
94 import dwtx.jface.text.AbstractDocument; // packageimport | |
95 import dwtx.jface.text.AbstractLineTracker; // packageimport | |
96 import dwtx.jface.text.TreeLineTracker; // packageimport | |
97 import dwtx.jface.text.ITextPresentationListener; // packageimport | |
98 import dwtx.jface.text.Region; // packageimport | |
99 import dwtx.jface.text.ITextViewer; // packageimport | |
100 import dwtx.jface.text.IDocumentInformationMapping; // packageimport | |
101 import dwtx.jface.text.MarginPainter; // packageimport | |
102 import dwtx.jface.text.IPaintPositionManager; // packageimport | |
103 import dwtx.jface.text.TextPresentation; // packageimport | |
104 import dwtx.jface.text.IFindReplaceTargetExtension; // packageimport | |
105 import dwtx.jface.text.ISlaveDocumentManagerExtension; // packageimport | |
106 import dwtx.jface.text.ISelectionValidator; // packageimport | |
107 import dwtx.jface.text.IDocumentExtension; // packageimport | |
108 import dwtx.jface.text.PropagatingFontFieldEditor; // packageimport | |
109 import dwtx.jface.text.ConfigurableLineTracker; // packageimport | |
110 import dwtx.jface.text.SlaveDocumentEvent; // packageimport | |
111 import dwtx.jface.text.IDocumentListener; // packageimport | |
112 import dwtx.jface.text.PaintManager; // packageimport | |
113 import dwtx.jface.text.IFindReplaceTargetExtension3; // packageimport | |
114 import dwtx.jface.text.ITextDoubleClickStrategy; // packageimport | |
115 import dwtx.jface.text.IDocumentExtension3; // packageimport | |
116 import dwtx.jface.text.Position; // packageimport | |
117 import dwtx.jface.text.TextMessages; // packageimport | |
118 import dwtx.jface.text.CopyOnWriteTextStore; // packageimport | |
119 import dwtx.jface.text.WhitespaceCharacterPainter; // packageimport | |
120 import dwtx.jface.text.IPositionUpdater; // packageimport | |
121 import dwtx.jface.text.DefaultTextDoubleClickStrategy; // packageimport | |
122 import dwtx.jface.text.ListLineTracker; // packageimport | |
123 import dwtx.jface.text.ITextInputListener; // packageimport | |
124 import dwtx.jface.text.BadPositionCategoryException; // packageimport | |
125 import dwtx.jface.text.IWidgetTokenKeeperExtension; // packageimport | |
126 import dwtx.jface.text.IInputChangedListener; // packageimport | |
127 import dwtx.jface.text.ITextOperationTarget; // packageimport | |
128 import dwtx.jface.text.IDocumentInformationMappingExtension2; // packageimport | |
129 import dwtx.jface.text.ITextViewerExtension7; // packageimport | |
130 import dwtx.jface.text.IInformationControlExtension5; // packageimport | |
131 import dwtx.jface.text.IDocumentRewriteSessionListener; // packageimport | |
132 import dwtx.jface.text.JFaceTextUtil; // packageimport | |
133 import dwtx.jface.text.AbstractReusableInformationControlCreator; // packageimport | |
134 import dwtx.jface.text.TabsToSpacesConverter; // packageimport | |
135 import dwtx.jface.text.CursorLinePainter; // packageimport | |
136 import dwtx.jface.text.ITextHoverExtension; // packageimport | |
137 import dwtx.jface.text.IEventConsumer; // packageimport | |
138 import dwtx.jface.text.IDocument; // packageimport | |
139 import dwtx.jface.text.IWidgetTokenKeeper; // packageimport | |
140 import dwtx.jface.text.DocumentCommand; // packageimport | |
141 import dwtx.jface.text.TypedPosition; // packageimport | |
142 import dwtx.jface.text.IEditingSupportRegistry; // packageimport | |
143 import dwtx.jface.text.IDocumentPartitionerExtension; // packageimport | |
144 import dwtx.jface.text.AbstractHoverInformationControlManager; // packageimport | |
145 import dwtx.jface.text.IEditingSupport; // packageimport | |
146 import dwtx.jface.text.IMarkSelection; // packageimport | |
147 import dwtx.jface.text.ISlaveDocumentManager; // packageimport | |
148 import dwtx.jface.text.DocumentEvent; // packageimport | |
149 import dwtx.jface.text.DocumentPartitioningChangedEvent; // packageimport | |
150 import dwtx.jface.text.ITextStore; // packageimport | |
151 import dwtx.jface.text.JFaceTextMessages; // packageimport | |
152 import dwtx.jface.text.DocumentRewriteSessionEvent; // packageimport | |
153 import dwtx.jface.text.SequentialRewriteTextStore; // packageimport | |
154 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport | |
155 import dwtx.jface.text.TextAttribute; // packageimport | |
156 import dwtx.jface.text.ITextViewerExtension4; // packageimport | |
157 import dwtx.jface.text.ITypedRegion; // packageimport | |
158 | |
129 | 159 import dwt.dwthelper.utils; |
160 | |
161 | |
162 | |
163 | |
164 | |
165 import dwt.DWT; | |
166 import dwt.events.DisposeEvent; | |
167 import dwt.events.DisposeListener; | |
168 import dwt.graphics.GC; | |
169 import dwt.graphics.Point; | |
170 import dwt.graphics.Rectangle; | |
171 import dwt.widgets.Control; | |
172 import dwt.widgets.Display; | |
173 import dwt.widgets.Monitor; | |
174 import dwtx.core.runtime.Assert; | |
175 import dwtx.core.runtime.Platform; | |
176 import dwtx.jface.dialogs.IDialogSettings; | |
177 import dwtx.jface.internal.text.InformationControlReplacer; | |
178 import dwtx.jface.internal.text.InternalAccessor; | |
156 | 179 import dwtx.jface.text.ITextViewerExtension8; |
129 | 180 import dwtx.jface.util.Geometry; |
181 | |
182 | |
183 /** | |
184 * Manages the life cycle, visibility, layout, and contents of an | |
185 * {@link dwtx.jface.text.IInformationControl}. This manager can be | |
186 * installed on and removed from a control, referred to as the subject control, | |
187 * i.e. the one from which the subject of the information to be shown is | |
188 * retrieved. Also a manager can be enabled or disabled. An installed and | |
189 * enabled manager can be forced to show information in its information control | |
190 * using <code>showInformation</code>. An information control manager uses an | |
191 * <code>IInformationControlCloser</code> to define the behavior when a | |
192 * presented information control must be closed. The disposal of the subject and | |
193 * the information control are internally handled by the information control | |
194 * manager and are not the responsibility of the information control closer. | |
195 * | |
196 * @see dwtx.jface.text.IInformationControl | |
197 * @since 2.0 | |
198 */ | |
199 abstract public class AbstractInformationControlManager { | |
200 | |
201 /** | |
202 * An internal class that gives access to internal methods. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
203 * |
129 | 204 * @since 3.4 |
205 */ | |
206 class MyInternalAccessor : InternalAccessor { | |
207 public IInformationControl getCurrentInformationControl() { | |
137 | 208 return this.outer.getCurrentInformationControl(); |
129 | 209 } |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
210 |
129 | 211 public void setInformationControlReplacer(InformationControlReplacer replacer) { |
137 | 212 this.outer.setInformationControlReplacer(replacer); |
129 | 213 } |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
214 |
129 | 215 public InformationControlReplacer getInformationControlReplacer() { |
137 | 216 return this.outer.getInformationControlReplacer(); |
129 | 217 } |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
218 |
129 | 219 public bool canReplace(IInformationControl control) { |
137 | 220 return this.outer.canReplace(control); |
129 | 221 } |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
222 |
129 | 223 public bool isReplaceInProgress() { |
137 | 224 return this.outer.isReplaceInProgress(); |
129 | 225 } |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
226 |
129 | 227 public void replaceInformationControl(bool takeFocus) { |
137 | 228 this.outer.replaceInformationControl(takeFocus); |
129 | 229 } |
230 | |
231 public void cropToClosestMonitor(Rectangle bounds) { | |
137 | 232 this.outer.cropToClosestMonitor(bounds); |
129 | 233 } |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
234 |
129 | 235 public void setHoverEnrichMode(EnrichMode mode) { |
236 throw new UnsupportedOperationException("only implemented in AbstractHoverInformationControlManager"); //$NON-NLS-1$ | |
237 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
238 |
129 | 239 public bool getAllowMouseExit() { |
240 throw new UnsupportedOperationException("only implemented in AnnotationBarHoverManager"); //$NON-NLS-1$ | |
241 } | |
242 } | |
243 | |
244 /** | |
245 * Interface of an information control closer. An information control closer | |
246 * monitors its information control and its subject control and closes the | |
247 * information control if necessary. | |
248 * <p> | |
249 * Clients must implement this interface in order to equip an information | |
250 * control manager accordingly. | |
251 */ | |
252 public interface IInformationControlCloser { | |
253 | |
254 /** | |
255 * Sets the closer's subject control. This is the control that parents | |
256 * the information control and from which the subject of the information | |
257 * to be shown is retrieved. <p> | |
258 * Must be called before <code>start</code>. May again be called | |
259 * between <code>start</code> and <code>stop</code>. | |
260 * | |
261 * @param subject the subject control | |
262 */ | |
263 public void setSubjectControl(Control subject); | |
264 | |
265 /** | |
266 * Sets the closer's information control, the one to close if necessary. <p> | |
267 * Must be called before <code>start</code>. May again be called | |
268 * between <code>start</code> and <code>stop</code>. | |
269 * | |
270 * @param control the information control | |
271 */ | |
272 public void setInformationControl(IInformationControl control); | |
273 | |
274 /** | |
275 * Tells this closer to start monitoring the subject and the information | |
276 * control. The presented information is considered valid for the given | |
277 * area of the subject control's display. | |
278 * | |
279 * @param subjectArea the area for which the presented information is valid | |
280 */ | |
281 public void start(Rectangle subjectArea); | |
282 | |
283 /** | |
284 * Tells this closer to stop monitoring the subject and the information control. | |
285 */ | |
286 public void stop(); | |
287 } | |
288 | |
289 | |
290 | |
291 /** | |
292 * Constitutes entities to enumerate anchors for the layout of the information control. | |
293 */ | |
294 public static final class Anchor { | |
146 | 295 private const int fFlag; |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
296 private this(int flag) { |
129 | 297 fFlag= flag; |
298 } | |
299 /** | |
300 * Returns the DWT direction flag. One of {@link DWT#BOTTOM}, {@link DWT#TOP}, | |
301 * {@link DWT#LEFT}, {@link DWT#RIGHT}, {@link DWT#CENTER}, | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
302 * |
129 | 303 * @return the DWT direction flag |
304 * @since 3.3 | |
305 */ | |
306 int getSWTFlag() { | |
307 return fFlag; | |
308 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
309 |
160 | 310 public override String toString() { |
129 | 311 switch (fFlag) { |
312 case DWT.BOTTOM: return "BOTTOM"; //$NON-NLS-1$ | |
313 case DWT.TOP: return "TOP"; //$NON-NLS-1$ | |
314 case DWT.LEFT: return "LEFT"; //$NON-NLS-1$ | |
315 case DWT.RIGHT: return "RIGHT"; //$NON-NLS-1$ | |
316 case DWT.CENTER: return "CENTER"; //$NON-NLS-1$ | |
317 default: return Integer.toHexString(fFlag); | |
318 } | |
319 } | |
320 } | |
321 | |
322 /** Internal anchor list. */ | |
159 | 323 private static Anchor[] ANCHORS_; |
324 private static Anchor[] ANCHORS() { | |
325 if( ANCHORS_ is null ) ANCHORS_= [ new Anchor(DWT.TOP), new Anchor(DWT.BOTTOM), new Anchor(DWT.LEFT), new Anchor(DWT.RIGHT) ]; | |
326 return ANCHORS_; | |
327 } | |
328 | |
129 | 329 |
330 /** Anchor representing the top of the information area */ | |
159 | 331 public static Anchor ANCHOR_TOP() { return ANCHORS()[0]; } |
129 | 332 /** Anchor representing the bottom of the information area */ |
159 | 333 public static Anchor ANCHOR_BOTTOM() { return ANCHORS()[1]; } |
129 | 334 /** Anchor representing the left side of the information area */ |
159 | 335 public static Anchor ANCHOR_LEFT() { return ANCHORS()[2]; } |
129 | 336 /** Anchor representing the right side of the information area */ |
159 | 337 public static Anchor ANCHOR_RIGHT() { return ANCHORS()[3]; } |
129 | 338 /** |
339 * Anchor representing the middle of the subject control | |
340 * @since 2.1 | |
341 */ | |
161 | 342 public static Anchor ANCHOR_GLOBAL_; |
343 public static Anchor ANCHOR_GLOBAL(){ | |
344 if( ANCHOR_GLOBAL_ is null ) ANCHOR_GLOBAL_ = new Anchor(DWT.CENTER); | |
345 return ANCHOR_GLOBAL_; | |
346 } | |
129 | 347 |
348 /** | |
349 * Dialog store constant for the location's x-coordinate. | |
350 * @since 3.0 | |
351 */ | |
147 | 352 public static const String STORE_LOCATION_X= "location.x"; //$NON-NLS-1$ |
129 | 353 /** |
354 * Dialog store constant for the location's y-coordinate. | |
355 * @since 3.0 | |
356 */ | |
147 | 357 public static const String STORE_LOCATION_Y= "location.y"; //$NON-NLS-1$ |
129 | 358 /** |
359 * Dialog store constant for the size's width. | |
360 * @since 3.0 | |
361 */ | |
147 | 362 public static const String STORE_SIZE_WIDTH= "size.width"; //$NON-NLS-1$ |
129 | 363 /** |
364 * Dialog store constant for the size's height. | |
365 * @since 3.0 | |
366 */ | |
147 | 367 public static const String STORE_SIZE_HEIGHT= "size.height"; //$NON-NLS-1$ |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
368 |
129 | 369 /** |
370 * Tells whether this class and its subclasses are in debug mode. | |
371 * <p> | |
372 * Subclasses may use this. | |
373 * </p> | |
374 * @since 3.4 | |
375 */ | |
159 | 376 private static bool DEBUG_; |
377 private static bool DEBUG_init = false; | |
378 protected static bool DEBUG(){ | |
379 if( !DEBUG_init ){ | |
380 DEBUG_init = true; | |
381 DEBUG_ = "true".equalsIgnoreCase(Platform.getDebugOption("dwtx.jface.text/debug/AbstractInformationControlManager")); //$NON-NLS-1$//$NON-NLS-2$ | |
382 } | |
383 return DEBUG_; | |
384 } | |
129 | 385 |
386 | |
387 /** The subject control of the information control */ | |
388 private Control fSubjectControl; | |
389 | |
390 /** The display area for which the information to be presented is valid */ | |
391 private Rectangle fSubjectArea; | |
392 | |
393 /** The information to be presented */ | |
394 private Object fInformation; | |
395 | |
396 /** Indicates whether the information control takes focus when visible */ | |
397 private bool fTakesFocusWhenVisible= false; | |
398 | |
399 /** | |
400 * The information control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
401 * |
129 | 402 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API |
403 * compatibility reasons. | |
404 */ | |
405 protected IInformationControl fInformationControl; | |
406 | |
407 /** | |
408 * The information control creator. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
409 * |
129 | 410 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API |
411 * compatibility reasons. | |
412 */ | |
413 protected IInformationControlCreator fInformationControlCreator; | |
414 | |
415 /** | |
416 * The information control closer. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
417 * |
129 | 418 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API |
419 * compatibility reasons. | |
420 */ | |
421 protected IInformationControlCloser fInformationControlCloser; | |
422 | |
423 /** | |
424 * Indicates that the information control has been disposed. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
425 * |
129 | 426 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API |
427 * compatibility reasons. | |
428 */ | |
429 protected bool fDisposed= false; | |
430 | |
431 /** | |
432 * The information control replacer to be used when this information control | |
433 * needs to be replaced with another information control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
434 * |
129 | 435 * @since 3.4 |
436 */ | |
437 private InformationControlReplacer fInformationControlReplacer; | |
438 | |
439 /** Indicates the enable state of this manager */ | |
440 private bool fEnabled= false; | |
441 | |
442 /** Cached, computed size constraints of the information control in points */ | |
443 private Point fSizeConstraints; | |
444 | |
445 /** The vertical margin when laying out the information control */ | |
446 private int fMarginY= 5; | |
447 | |
448 /** The horizontal margin when laying out the information control */ | |
449 private int fMarginX= 5; | |
450 | |
451 /** The width constraint of the information control in characters */ | |
452 private int fWidthConstraint= 60; | |
453 | |
454 /** The height constraint of the information control in characters */ | |
455 private int fHeightConstraint= 6; | |
456 | |
457 /** Indicates whether the size constraints should be enforced as minimal control size */ | |
458 private bool fEnforceAsMinimalSize= false; | |
459 | |
460 /** Indicates whether the size constraints should be enforced as maximal control size */ | |
461 private bool fEnforceAsMaximalSize= false; | |
462 | |
463 /** The anchor for laying out the information control in relation to the subject control */ | |
159 | 464 private Anchor fAnchor; |
129 | 465 |
466 /** | |
467 * The anchor sequence used to layout the information control if the original anchor | |
468 * can not be used because the information control would not fit in the display client area. | |
469 * <p> | |
470 * The fallback anchor for a given anchor is the one that comes directly after the given anchor or | |
471 * is the first one in the sequence if the given anchor is the last one in the sequence. | |
472 * <p> | |
473 * </p> | |
474 * Note: This sequence is ignored if the original anchor is not contained in this sequence. | |
475 * </p> | |
476 * | |
477 * @see #fAnchor | |
478 */ | |
159 | 479 private Anchor[] fFallbackAnchors; |
129 | 480 /** |
481 * The custom information control creator. | |
482 * @since 3.0 | |
483 */ | |
156 | 484 private /+volatile+/ IInformationControlCreator fCustomInformationControlCreator; |
129 | 485 |
486 /** | |
487 * Tells whether a custom information control is in use. | |
488 * @since 3.0 | |
489 */ | |
490 private bool fIsCustomInformationControl= false; | |
491 | |
492 /** | |
493 * The dialog settings for the control's bounds. | |
494 * @since 3.0 | |
495 */ | |
496 private IDialogSettings fDialogSettings; | |
497 | |
498 /** | |
499 * Tells whether the control's location should be read | |
500 * from the dialog settings and whether the last | |
501 * valid control's size is stored back into the settings. | |
502 * | |
503 * @since 3.0 | |
504 */ | |
505 private bool fIsRestoringLocation; | |
506 | |
507 /** | |
508 * Tells whether the control's size should be read | |
509 * from the dialog settings and whether the last | |
510 * valid control's size is stored back into the settings. | |
511 * | |
512 * @since 3.0 | |
513 */ | |
514 private bool fIsRestoringSize; | |
515 | |
516 /** | |
517 * The dispose listener on the subject control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
518 * |
129 | 519 * @since 3.1 |
520 */ | |
521 private DisposeListener fSubjectControlDisposeListener; | |
522 | |
523 | |
524 /** | |
525 * Creates a new information control manager using the given information control creator. | |
526 * By default the following configuration is given: | |
527 * <ul> | |
528 * <li> enabled is false | |
529 * <li> horizontal margin is 5 points | |
530 * <li> vertical margin is 5 points | |
531 * <li> width constraint is 60 characters | |
532 * <li> height constraint is 6 characters | |
533 * <li> enforce constraints as minimal size is false | |
534 * <li> enforce constraints as maximal size is false | |
535 * <li> layout anchor is ANCHOR_BOTTOM | |
536 * <li> fall back anchors is { ANCHOR_TOP, ANCHOR_BOTTOM, ANCHOR_LEFT, ANCHOR_RIGHT, ANCHOR_GLOBAL } | |
537 * <li> takes focus when visible is false | |
538 * </ul> | |
539 * | |
540 * @param creator the information control creator | |
541 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
542 protected this(IInformationControlCreator creator) { |
159 | 543 fAnchor= ANCHOR_BOTTOM(); |
544 fFallbackAnchors= ANCHORS(); | |
161 | 545 Assert.isNotNull(cast(Object)creator); |
129 | 546 fInformationControlCreator= creator; |
547 } | |
548 | |
549 /** | |
550 * Computes the information to be displayed and the area in which the computed | |
551 * information is valid. Implementation of this method must finish their computation | |
552 * by setting the computation results using <code>setInformation</code>. | |
553 */ | |
554 abstract protected void computeInformation(); | |
555 | |
556 /** | |
557 * Sets the parameters of the information to be displayed. These are the information itself and | |
558 * the area for which the given information is valid. This so called subject area is a graphical | |
559 * region of the information control's subject control. This method calls <code>presentInformation()</code> | |
560 * to trigger the presentation of the computed information. | |
561 * | |
562 * @param information the information, or <code>null</code> if none is available | |
563 * @param subjectArea the subject area, or <code>null</code> if none is available | |
564 */ | |
565 protected final void setInformation(String information, Rectangle subjectArea) { | |
161 | 566 setInformation(stringcast(information), subjectArea); |
129 | 567 } |
568 | |
569 /** | |
570 * Sets the parameters of the information to be displayed. These are the information itself and | |
571 * the area for which the given information is valid. This so called subject area is a graphical | |
572 * region of the information control's subject control. This method calls <code>presentInformation()</code> | |
573 * to trigger the presentation of the computed information. | |
574 * | |
575 * @param information the information, or <code>null</code> if none is available | |
576 * @param subjectArea the subject area, or <code>null</code> if none is available | |
577 * @since 2.1 | |
578 */ | |
579 protected final void setInformation(Object information, Rectangle subjectArea) { | |
580 fInformation= information; | |
581 fSubjectArea= subjectArea; | |
582 presentInformation(); | |
583 } | |
584 | |
585 /** | |
586 * Sets the information control closer for this manager. | |
587 * | |
588 * @param closer the information control closer for this manager | |
589 */ | |
590 protected void setCloser(IInformationControlCloser closer) { | |
591 fInformationControlCloser= closer; | |
592 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
593 |
129 | 594 /** |
595 * Sets the information control replacer for this manager and disposes the | |
596 * old one if set. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
597 * |
129 | 598 * @param replacer the information control replacer for this manager, or |
599 * <code>null</code> if no information control replacing should | |
600 * take place | |
601 * @since 3.4 | |
602 */ | |
603 void setInformationControlReplacer(InformationControlReplacer replacer) { | |
604 if (fInformationControlReplacer !is null) | |
605 fInformationControlReplacer.dispose(); | |
606 fInformationControlReplacer= replacer; | |
607 } | |
608 | |
609 /** | |
610 * Returns the current information control replacer or <code>null</code> if none has been installed. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
611 * |
129 | 612 * @return the current information control replacer or <code>null</code> if none has been installed |
613 * @since 3.4 | |
614 */ | |
615 InformationControlReplacer getInformationControlReplacer() { | |
616 return fInformationControlReplacer; | |
617 } | |
618 | |
619 /** | |
620 * Returns whether an information control replacer has been installed. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
621 * |
129 | 622 * @return whether an information control replacer has been installed |
623 * @since 3.4 | |
624 */ | |
625 bool hasInformationControlReplacer() { | |
626 return fInformationControlReplacer !is null; | |
627 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
628 |
129 | 629 /** |
630 * Tests whether the given information control is replaceable. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
631 * |
129 | 632 * @param iControl information control or <code>null</code> if none |
633 * @return <code>true</code> if information control is replaceable, <code>false</code> otherwise | |
634 * @since 3.4 | |
635 */ | |
636 bool canReplace(IInformationControl iControl) { | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
637 return cast(IInformationControlExtension3)iControl |
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
638 && cast(IInformationControlExtension5)iControl |
134 | 639 && (cast(IInformationControlExtension5) iControl).getInformationPresenterControlCreator() !is null; |
129 | 640 } |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
641 |
129 | 642 /** |
643 * Returns the current information control, or <code>null</code> if none. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
644 * |
129 | 645 * @return the current information control, or <code>null</code> if none |
646 * @since 3.4 | |
647 */ | |
648 IInformationControl getCurrentInformationControl() { | |
649 return fInformationControl; | |
650 } | |
651 | |
652 /** | |
653 * Tells whether this manager's information control is currently being replaced. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
654 * |
129 | 655 * @return <code>true</code> if a replace is in progress |
656 * @since 3.4 | |
657 */ | |
658 bool isReplaceInProgress() { | |
659 return fInformationControlReplacer !is null && fInformationControlReplacer.isReplacing(); | |
660 } | |
661 | |
662 /** | |
663 * Sets the horizontal and vertical margin to be used when laying out the | |
664 * information control relative to the subject control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
665 * |
129 | 666 * @param xMargin the x-margin |
667 * @param yMargin the y-Margin | |
668 */ | |
669 public void setMargins(int xMargin, int yMargin) { | |
670 fMarginX= xMargin; | |
671 fMarginY= yMargin; | |
672 } | |
673 | |
674 /** | |
675 * Sets the width- and height constraints of the information control. | |
676 * | |
677 * @param widthInChar the width constraint in number of characters | |
678 * @param heightInChar the height constrain in number of characters | |
679 * @param enforceAsMinimalSize indicates whether the constraints describe the minimal allowed size of the control | |
680 * @param enforceAsMaximalSize indicates whether the constraints describe the maximal allowed size of the control | |
681 */ | |
682 public void setSizeConstraints(int widthInChar, int heightInChar, bool enforceAsMinimalSize, bool enforceAsMaximalSize) { | |
683 fSizeConstraints= null; | |
684 fWidthConstraint= widthInChar; | |
685 fHeightConstraint= heightInChar; | |
686 fEnforceAsMinimalSize= enforceAsMinimalSize; | |
687 fEnforceAsMaximalSize= enforceAsMaximalSize; | |
688 | |
689 } | |
690 | |
691 /** | |
692 * Tells this information control manager to open the information | |
693 * control with the values contained in the given dialog settings | |
694 * and to store the control's last valid size in the given dialog | |
695 * settings. | |
696 * <p> | |
697 * Note: This API is only valid if the information control implements | |
698 * {@link IInformationControlExtension3}. Not following this restriction | |
699 * will later result in an {@link UnsupportedOperationException}. | |
700 * </p> | |
701 * <p> | |
702 * The constants used to store the values are: | |
703 * <ul> | |
704 * <li>{@link AbstractInformationControlManager#STORE_LOCATION_X}</li> | |
705 * <li>{@link AbstractInformationControlManager#STORE_LOCATION_Y}</li> | |
706 * <li>{@link AbstractInformationControlManager#STORE_SIZE_WIDTH}</li> | |
707 * <li>{@link AbstractInformationControlManager#STORE_SIZE_HEIGHT}</li> | |
708 * </ul> | |
709 * </p> | |
710 * | |
711 * @param dialogSettings | |
712 * @param restoreLocation <code>true</code> iff the location is must be (re-)stored | |
713 * @param restoreSize <code>true</code>iff the size is (re-)stored | |
714 * @since 3.0 | |
715 */ | |
716 public void setRestoreInformationControlBounds(IDialogSettings dialogSettings, bool restoreLocation, bool restoreSize) { | |
717 Assert.isTrue(dialogSettings !is null && (restoreLocation || restoreSize)); | |
718 fDialogSettings= dialogSettings; | |
719 fIsRestoringLocation= restoreLocation; | |
720 fIsRestoringSize= restoreSize; | |
721 } | |
722 | |
723 /** | |
724 * Sets the anchor used for laying out the information control relative to the | |
725 * subject control. E.g, using <code>ANCHOR_TOP</code> indicates that the | |
726 * information control is position above the area for which the information to | |
727 * be displayed is valid. | |
728 * | |
729 * @param anchor the layout anchor | |
730 */ | |
731 public void setAnchor(Anchor anchor) { | |
732 fAnchor= anchor; | |
733 } | |
734 | |
735 /** | |
736 * Sets the anchors fallback sequence used to layout the information control if the original | |
737 * anchor can not be used because the information control would not fit in the display client | |
738 * area. | |
739 * <p> | |
740 * The fallback anchor for a given anchor is the one that comes directly after the given anchor or | |
741 * is the first one in the sequence if the given anchor is the last one in the sequence. | |
742 * <p> | |
743 * </p> | |
744 * Note: This sequence is ignored if the original anchor is not contained in this list. | |
745 * </p> | |
746 * | |
747 * @param fallbackAnchors the array with the anchor fallback sequence | |
748 * @see #setAnchor(AbstractInformationControlManager.Anchor) | |
749 */ | |
750 public void setFallbackAnchors(Anchor[] fallbackAnchors) { | |
751 if (fallbackAnchors !is null) { | |
752 fFallbackAnchors= new Anchor[fallbackAnchors.length]; | |
753 System.arraycopy(fallbackAnchors, 0, fFallbackAnchors, 0, fallbackAnchors.length); | |
754 } else | |
755 fFallbackAnchors= null; | |
756 } | |
757 | |
758 /** | |
759 * Sets the temporary custom control creator, overriding this manager's default information control creator. | |
760 * | |
761 * @param informationControlCreator the creator, possibly <code>null</code> | |
762 * @since 3.0 | |
763 */ | |
764 protected void setCustomInformationControlCreator(IInformationControlCreator informationControlCreator) { | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
765 if (informationControlCreator !is null && cast(IInformationControlCreatorExtension)fCustomInformationControlCreator) { |
134 | 766 IInformationControlCreatorExtension extension= cast(IInformationControlCreatorExtension) fCustomInformationControlCreator; |
129 | 767 if (extension.canReplace(informationControlCreator)) |
768 return; | |
769 } | |
770 fCustomInformationControlCreator= informationControlCreator; | |
771 } | |
772 | |
773 /** | |
774 * Tells the manager whether it should set the focus to the information control when made visible. | |
775 * | |
776 * @param takesFocus <code>true</code> if information control should take focus when made visible | |
777 */ | |
778 public void takesFocusWhenVisible(bool takesFocus) { | |
779 fTakesFocusWhenVisible= takesFocus; | |
780 } | |
781 | |
782 /** | |
783 * Handles the disposal of the subject control. By default, the information control | |
784 * is disposed by calling <code>disposeInformationControl</code>. Subclasses may extend | |
785 * this method. | |
786 */ | |
787 protected void handleSubjectControlDisposed() { | |
788 disposeInformationControl(); | |
789 } | |
790 | |
791 /** | |
792 * Installs this manager on the given control. The control is now taking the role of | |
793 * the subject control. This implementation sets the control also as the information | |
794 * control closer's subject control and automatically enables this manager. | |
795 * | |
796 * @param subjectControl the subject control | |
797 */ | |
798 public void install(Control subjectControl) { | |
799 if (fSubjectControl !is null && !fSubjectControl.isDisposed() && fSubjectControlDisposeListener !is null) | |
800 fSubjectControl.removeDisposeListener(fSubjectControlDisposeListener); | |
801 | |
802 fSubjectControl= subjectControl; | |
803 | |
804 if (fSubjectControl !is null) | |
805 fSubjectControl.addDisposeListener(getSubjectControlDisposeListener()); | |
806 | |
807 if (fInformationControlCloser !is null) | |
808 fInformationControlCloser.setSubjectControl(subjectControl); | |
809 | |
810 setEnabled(true); | |
811 fDisposed= false; | |
812 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
813 |
129 | 814 /** |
815 * Returns the dispose listener which gets added | |
816 * to the subject control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
817 * |
129 | 818 * @return the dispose listener |
819 * @since 3.1 | |
820 */ | |
821 private DisposeListener getSubjectControlDisposeListener() { | |
822 if (fSubjectControlDisposeListener is null) { | |
135 | 823 fSubjectControlDisposeListener= new class() DisposeListener { |
129 | 824 public void widgetDisposed(DisposeEvent e) { |
825 handleSubjectControlDisposed(); | |
826 } | |
827 }; | |
828 } | |
829 return fSubjectControlDisposeListener; | |
830 } | |
831 | |
832 /** | |
833 * Returns the subject control of this manager/information control. | |
834 * | |
835 * @return the subject control | |
836 */ | |
837 protected Control getSubjectControl() { | |
838 return fSubjectControl; | |
839 } | |
840 | |
841 /** | |
842 * Returns the actual subject area. | |
843 * | |
844 * @return the actual subject area | |
845 */ | |
846 protected Rectangle getSubjectArea() { | |
847 return fSubjectArea; | |
848 } | |
849 | |
850 /** | |
851 * Sets the enable state of this manager. | |
852 * | |
853 * @param enabled the enable state | |
854 * @deprecated visibility will be changed to protected | |
855 */ | |
856 public void setEnabled(bool enabled) { | |
857 fEnabled= enabled; | |
858 } | |
859 | |
860 /** | |
861 * Returns whether this manager is enabled or not. | |
862 * | |
863 * @return <code>true</code> if this manager is enabled otherwise <code>false</code> | |
864 */ | |
865 protected bool isEnabled() { | |
866 return fEnabled; | |
867 } | |
868 | |
869 /** | |
870 * Computes the size constraints of the information control in points based on the | |
871 * default font of the given subject control as well as the size constraints in character | |
872 * width. | |
873 * | |
874 * @param subjectControl the subject control | |
875 * @param informationControl the information control whose size constraints are computed | |
876 * @return the computed size constraints in points | |
877 */ | |
878 protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) { | |
879 | |
880 if (fSizeConstraints is null) { | |
138 | 881 if ( cast(IInformationControlExtension5)informationControl ) { |
134 | 882 IInformationControlExtension5 iControl5= cast(IInformationControlExtension5) informationControl; |
129 | 883 fSizeConstraints= iControl5.computeSizeConstraints(fWidthConstraint, fHeightConstraint); |
884 if (fSizeConstraints !is null) | |
885 return Geometry.copy(fSizeConstraints); | |
886 } | |
887 if (subjectControl is null) | |
888 return null; | |
889 | |
890 GC gc= new GC(subjectControl); | |
891 gc.setFont(subjectControl.getFont()); | |
892 int width= gc.getFontMetrics().getAverageCharWidth(); | |
893 int height = gc.getFontMetrics().getHeight(); | |
894 gc.dispose(); | |
895 | |
896 fSizeConstraints= new Point (fWidthConstraint * width, fHeightConstraint * height); | |
897 } | |
898 | |
899 return new Point(fSizeConstraints.x, fSizeConstraints.y); | |
900 } | |
901 | |
902 /** | |
903 * Computes the size constraints of the information control in points. | |
904 * | |
905 * @param subjectControl the subject control | |
906 * @param subjectArea the subject area | |
907 * @param informationControl the information control whose size constraints are computed | |
908 * @return the computed size constraints in points | |
909 * @since 3.0 | |
910 */ | |
911 protected Point computeSizeConstraints(Control subjectControl, Rectangle subjectArea, IInformationControl informationControl) { | |
912 return computeSizeConstraints(subjectControl, informationControl); | |
913 } | |
914 | |
915 /** | |
916 * Handles the disposal of the information control. By default, the information | |
917 * control closer is stopped. | |
918 */ | |
919 protected void handleInformationControlDisposed() { | |
920 | |
921 storeInformationControlBounds(); | |
922 | |
138 | 923 if ( cast(IInformationControlExtension5)fInformationControl ) |
129 | 924 fSizeConstraints= null; |
925 fInformationControl= null; | |
926 if (fInformationControlCloser !is null) { | |
927 fInformationControlCloser.setInformationControl(null); //XXX: null is against the spec | |
928 fInformationControlCloser.stop(); | |
929 } | |
930 } | |
931 | |
932 /** | |
933 * Returns the information control. If the information control has not been created yet, | |
934 * it is automatically created. | |
935 * | |
936 * @return the information control | |
937 */ | |
938 protected IInformationControl getInformationControl() { | |
939 | |
940 if (fDisposed) | |
941 return fInformationControl; | |
942 | |
943 IInformationControlCreator creator= null; | |
944 | |
945 if (fCustomInformationControlCreator is null) { | |
946 creator= fInformationControlCreator; | |
947 if (fIsCustomInformationControl && fInformationControl !is null) { | |
138 | 948 if ( cast(IInformationControlExtension5)fInformationControl ) |
129 | 949 fSizeConstraints= null; |
950 fInformationControl.dispose(); | |
951 fInformationControl= null; | |
952 } | |
953 fIsCustomInformationControl= false; | |
954 | |
955 } else { | |
956 | |
957 creator= fCustomInformationControlCreator; | |
138 | 958 if ( cast(IInformationControlCreatorExtension)creator ) { |
134 | 959 IInformationControlCreatorExtension extension= cast(IInformationControlCreatorExtension) creator; |
129 | 960 if (fInformationControl !is null && extension.canReuse(fInformationControl)) |
961 return fInformationControl; | |
962 } | |
963 if (fInformationControl !is null) { | |
138 | 964 if ( cast(IInformationControlExtension5)fInformationControl ) |
129 | 965 fSizeConstraints= null; |
966 fInformationControl.dispose(); | |
967 fInformationControl= null; | |
968 } | |
969 fIsCustomInformationControl= true; | |
970 } | |
971 | |
972 if (fInformationControl is null) { | |
973 fInformationControl= creator.createInformationControl(fSubjectControl.getShell()); | |
135 | 974 fInformationControl.addDisposeListener(new class() DisposeListener { |
129 | 975 public void widgetDisposed(DisposeEvent e) { |
976 handleInformationControlDisposed(); | |
977 } | |
978 }); | |
979 | |
980 if (fInformationControlCloser !is null) | |
981 fInformationControlCloser.setInformationControl(fInformationControl); | |
982 } | |
983 | |
984 return fInformationControl; | |
985 } | |
986 | |
987 /** | |
988 * Computes the display location of the information control. The location is computed | |
989 * considering the given subject area, the anchor at the subject area, and the | |
990 * size of the information control. This method does not care about whether the information | |
991 * control would be completely visible when placed at the result location. | |
992 * | |
993 * @param subjectArea the subject area | |
994 * @param controlSize the size of the information control | |
995 * @param anchor the anchor at the subject area | |
996 * @return the display location of the information control | |
997 */ | |
998 protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) { | |
999 int xShift= 0; | |
1000 int yShift= 0; | |
1001 | |
1002 switch (anchor.getSWTFlag()) { | |
1003 case DWT.CENTER: | |
1004 Point subjectControlSize= fSubjectControl.getSize(); | |
1005 Point location= new Point(subjectControlSize.x / 2, subjectControlSize.y / 2); | |
1006 location.x -= (controlSize.x / 2); | |
1007 location.y -= (controlSize.y / 2); | |
1008 return fSubjectControl.toDisplay(location); | |
1009 case DWT.BOTTOM: | |
1010 yShift= subjectArea.height + fMarginY; | |
1011 break; | |
1012 case DWT.RIGHT: | |
1013 xShift= fMarginX + subjectArea.width; | |
1014 break; | |
1015 case DWT.TOP: | |
1016 yShift= -controlSize.y - fMarginY; | |
1017 break; | |
1018 case DWT.LEFT: | |
1019 xShift= -controlSize.x - fMarginX; | |
1020 break; | |
1021 } | |
1022 | |
1023 bool isRTL= fSubjectControl !is null && (fSubjectControl.getStyle() & DWT.RIGHT_TO_LEFT) !is 0; | |
1024 if (isRTL) | |
1025 xShift += controlSize.x; | |
1026 | |
1027 return fSubjectControl.toDisplay(new Point(subjectArea.x + xShift, subjectArea.y + yShift)); | |
1028 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1029 |
129 | 1030 /** |
1031 * Computes the area available for an information control given an anchor and the subject area | |
1032 * within <code>bounds</code>. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1033 * |
129 | 1034 * @param subjectArea the subject area |
1035 * @param bounds the bounds | |
1036 * @param anchor the anchor at the subject area | |
1037 * @return the area available at the given anchor relative to the subject area, confined to the | |
1038 * monitor's client area | |
1039 * @since 3.3 | |
1040 */ | |
1041 protected Rectangle computeAvailableArea(Rectangle subjectArea, Rectangle bounds, Anchor anchor) { | |
1042 Rectangle area; | |
1043 switch (anchor.getSWTFlag()) { | |
1044 case DWT.CENTER: | |
1045 area= bounds; | |
1046 break; | |
1047 case DWT.BOTTOM: | |
1048 int y= subjectArea.y + subjectArea.height + fMarginY; | |
1049 area= new Rectangle(bounds.x, y, bounds.width, bounds.y + bounds.height - y); | |
1050 break; | |
1051 case DWT.RIGHT: | |
1052 int x= subjectArea.x + subjectArea.width + fMarginX; | |
1053 area= new Rectangle(x, bounds.y, bounds.x + bounds.width - x, bounds.height); | |
1054 break; | |
1055 case DWT.TOP: | |
1056 area= new Rectangle(bounds.x, bounds.y, bounds.width, subjectArea.y - bounds.y - fMarginY); | |
1057 break; | |
1058 case DWT.LEFT: | |
1059 area= new Rectangle(bounds.x, bounds.y, subjectArea.x - bounds.x - fMarginX, bounds.height); | |
1060 break; | |
1061 default: | |
1062 Assert.isLegal(false); | |
1063 return null; | |
1064 } | |
1065 | |
1066 // Don't return negative areas if the subjectArea overlaps with the monitor bounds. | |
1067 area.intersect(bounds); | |
1068 return area; | |
1069 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1070 |
129 | 1071 /** |
1072 * Checks whether a control of the given size at the given location would be completely visible | |
1073 * in the given display area when laid out by using the given anchor. If not, this method tries | |
1074 * to shift the control orthogonal to the direction given by the anchor to make it visible. If possible | |
1075 * it updates the location.<p> | |
1076 * This method returns <code>true</code> if the potentially updated position results in a | |
1077 * completely visible control, or <code>false</code> otherwise. | |
1078 * | |
1079 * | |
1080 * @param location the location of the control | |
1081 * @param size the size of the control | |
1082 * @param displayArea the display area in which the control should be visible | |
1083 * @param anchor anchor for lying out the control | |
1084 * @return <code>true</code>if the updated location is useful | |
1085 */ | |
1086 protected bool updateLocation(Point location, Point size, Rectangle displayArea, Anchor anchor) { | |
1087 | |
1088 int displayLowerRightX= displayArea.x + displayArea.width; | |
1089 int displayLowerRightY= displayArea.y + displayArea.height; | |
1090 int lowerRightX= location.x + size.x; | |
1091 int lowerRightY= location.y + size.y; | |
1092 | |
1093 if (ANCHOR_BOTTOM is anchor || ANCHOR_TOP is anchor) { | |
1094 | |
1095 if (ANCHOR_BOTTOM is anchor) { | |
1096 if (lowerRightY > displayLowerRightY) | |
1097 return false; | |
1098 } else { | |
1099 if (location.y < displayArea.y) | |
1100 return false; | |
1101 } | |
1102 | |
1103 if (lowerRightX > displayLowerRightX) | |
1104 location.x= location.x - (lowerRightX - displayLowerRightX); | |
1105 | |
1106 return (location.x >= displayArea.x && location.y >= displayArea.y); | |
1107 | |
1108 } else if (ANCHOR_RIGHT is anchor || ANCHOR_LEFT is anchor) { | |
1109 | |
1110 if (ANCHOR_RIGHT is anchor) { | |
1111 if (lowerRightX > displayLowerRightX) | |
1112 return false; | |
1113 } else { | |
1114 if (location.x < displayArea.x) | |
1115 return false; | |
1116 } | |
1117 | |
1118 if (lowerRightY > displayLowerRightY) | |
1119 location.y= location.y - (lowerRightY - displayLowerRightY); | |
1120 | |
1121 return (location.x >= displayArea.x && location.y >= displayArea.y); | |
1122 | |
1123 } else if (ANCHOR_GLOBAL is anchor) { | |
1124 | |
1125 if (lowerRightX > displayLowerRightX) | |
1126 location.x= location.x - (lowerRightX - displayLowerRightX); | |
1127 | |
1128 if (lowerRightY > displayLowerRightY) | |
1129 location.y= location.y - (lowerRightY - displayLowerRightY); | |
1130 | |
1131 return (location.x >= displayArea.x && location.y >= displayArea.y); | |
1132 } | |
1133 | |
1134 return false; | |
1135 } | |
1136 | |
1137 /** | |
1138 * Returns the next fallback anchor as specified by this manager's | |
1139 * fallback anchor sequence. | |
1140 * <p> | |
1141 * The fallback anchor for the given anchor is the one that comes directly after | |
1142 * the given anchor or is the first one in the sequence if the given anchor is the | |
1143 * last one in the sequence. | |
1144 * </p> | |
1145 * <p> | |
1146 * Note: It is the callers responsibility to prevent an endless loop i.e. to test | |
1147 * whether a given anchor has already been used once. | |
1148 * then | |
1149 * </p> | |
1150 * | |
1151 * @param anchor the current anchor | |
1152 * @return the next fallback anchor or <code>null</code> if no fallback anchor is available | |
1153 */ | |
1154 protected Anchor getNextFallbackAnchor(Anchor anchor) { | |
1155 | |
1156 if (anchor is null || fFallbackAnchors is null) | |
1157 return null; | |
1158 | |
1159 for (int i= 0; i < fFallbackAnchors.length; i++) { | |
1160 if (fFallbackAnchors[i] is anchor) | |
1161 return fFallbackAnchors[i + 1 is fFallbackAnchors.length ? 0 : i + 1]; | |
1162 } | |
1163 | |
1164 return null; | |
1165 } | |
1166 | |
1167 /** | |
1168 * Computes the location of the information control depending on the | |
1169 * subject area and the size of the information control. This method attempts | |
1170 * to find a location at which the information control lies completely in the display's | |
1171 * client area while honoring the manager's default anchor. If this isn't possible using the | |
1172 * default anchor, the fallback anchors are tried out. | |
1173 * | |
1174 * @param subjectArea the information area | |
1175 * @param controlSize the size of the information control | |
1176 * @return the computed location of the information control | |
1177 */ | |
1178 protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) { | |
1179 Rectangle subjectAreaDisplayRelative= Geometry.toDisplay(fSubjectControl, subjectArea); | |
1180 | |
1181 Point upperLeft; | |
1182 Anchor testAnchor= fAnchor; | |
1183 Rectangle bestBounds= null; | |
1184 int bestArea= Integer.MIN_VALUE; | |
1185 Anchor bestAnchor= null; | |
1186 do { | |
1187 | |
1188 upperLeft= computeLocation(subjectArea, controlSize, testAnchor); | |
161 | 1189 dwt.widgets.Monitor.Monitor monitor= getClosestMonitor(subjectAreaDisplayRelative, testAnchor); |
129 | 1190 if (updateLocation(upperLeft, controlSize, monitor.getClientArea(), testAnchor)) |
1191 return upperLeft; | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1192 |
129 | 1193 // compute available area for this anchor and update if better than best |
1194 Rectangle available= computeAvailableArea(subjectAreaDisplayRelative, monitor.getClientArea(), testAnchor); | |
1195 Rectangle proposed= new Rectangle(upperLeft.x, upperLeft.y, controlSize.x, controlSize.y); | |
1196 available.intersect(proposed); | |
1197 int area= available.width * available.height; | |
1198 if (area > bestArea) { | |
1199 bestArea= area; | |
1200 bestBounds= available; | |
1201 bestAnchor= testAnchor; | |
1202 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1203 |
129 | 1204 testAnchor= getNextFallbackAnchor(testAnchor); |
1205 | |
1206 } while (testAnchor !is fAnchor && testAnchor !is null); | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1207 |
129 | 1208 // no anchor is perfect - select the one with larges area and set the size to not overlap with the subjectArea |
1209 if (bestAnchor !is ANCHOR_GLOBAL) | |
1210 Geometry.set(controlSize, Geometry.getSize(bestBounds)); | |
1211 return Geometry.getLocation(bestBounds); | |
1212 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1213 |
129 | 1214 /** |
1215 * Gets the closest monitor given an anchor and the subject area. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1216 * |
129 | 1217 * @param area the subject area |
1218 * @param anchor the anchor | |
1219 * @return the monitor closest to the edge of <code>area</code> defined by | |
1220 * <code>anchor</code> | |
1221 * @since 3.3 | |
1222 */ | |
161 | 1223 private dwt.widgets.Monitor.Monitor getClosestMonitor(Rectangle area, Anchor anchor) { |
129 | 1224 Point center; |
1225 if (ANCHOR_GLOBAL is anchor) | |
1226 center= Geometry.centerPoint(area); | |
1227 else | |
1228 center= Geometry.centerPoint(Geometry.getExtrudedEdge(area, 0, anchor.getSWTFlag())); | |
1229 return getClosestMonitor(fSubjectControl.getDisplay(), Geometry.createRectangle(center, new Point(0, 0))); | |
1230 } | |
1231 | |
1232 /** | |
1233 * Copied from dwtx.jface.window.Window. Returns the monitor whose client area contains | |
1234 * the given point. If no monitor contains the point, returns the monitor that is closest to the | |
1235 * point. If this is ever made public, it should be moved into a separate utility class. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1236 * |
129 | 1237 * @param display the display to search for monitors |
1238 * @param rectangle the rectangle to find the closest monitor for (display coordinates) | |
1239 * @return the monitor closest to the given point | |
1240 * @since 3.3 | |
1241 */ | |
161 | 1242 private dwt.widgets.Monitor.Monitor getClosestMonitor(Display display, Rectangle rectangle) { |
129 | 1243 int closest = Integer.MAX_VALUE; |
1244 | |
1245 Point toFind= Geometry.centerPoint(rectangle); | |
161 | 1246 dwt.widgets.Monitor.Monitor[] monitors = display.getMonitors(); |
1247 dwt.widgets.Monitor.Monitor result = monitors[0]; | |
129 | 1248 |
1249 for (int idx = 0; idx < monitors.length; idx++) { | |
161 | 1250 dwt.widgets.Monitor.Monitor current = monitors[idx]; |
129 | 1251 |
1252 Rectangle clientArea = current.getClientArea(); | |
1253 | |
1254 if (clientArea.contains(toFind)) { | |
1255 return current; | |
1256 } | |
1257 | |
1258 int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); | |
1259 if (distance < closest) { | |
1260 closest = distance; | |
1261 result = current; | |
1262 } | |
1263 } | |
1264 | |
1265 return result; | |
1266 } | |
1267 | |
1268 /** | |
1269 * Computes information to be displayed as well as the subject area | |
1270 * and initiates that this information is presented in the information control. | |
1271 * This happens only if this controller is enabled. | |
1272 */ | |
1273 public void showInformation() { | |
1274 if (fEnabled) | |
1275 doShowInformation(); | |
1276 } | |
1277 | |
1278 /** | |
1279 * Computes information to be displayed as well as the subject area | |
1280 * and initiates that this information is presented in the information control. | |
1281 */ | |
1282 protected void doShowInformation() { | |
1283 fSubjectArea= null; | |
1284 fInformation= null; | |
1285 computeInformation(); | |
1286 } | |
1287 | |
1288 /** | |
1289 * Presents the information in the information control or hides the information | |
1290 * control if no information should be presented. The information has previously | |
1291 * been set using <code>setInformation</code>. | |
1292 */ | |
1293 protected void presentInformation() { | |
1294 bool hasContents= false; | |
161 | 1295 if ( stringcast(fInformation) ) |
1296 hasContents= (stringcast(fInformation)).trim().length() > 0; | |
129 | 1297 else |
1298 hasContents= (fInformation !is null); | |
1299 | |
1300 if (fSubjectArea !is null && hasContents) | |
1301 internalShowInformationControl(fSubjectArea, fInformation); | |
1302 else | |
1303 hideInformationControl(); | |
1304 } | |
1305 | |
1306 /** | |
1307 * Opens the information control with the given information and the specified | |
1308 * subject area. It also activates the information control closer. | |
1309 * | |
1310 * @param subjectArea the information area | |
1311 * @param information the information | |
1312 */ | |
1313 private void internalShowInformationControl(Rectangle subjectArea, Object information) { | |
138 | 1314 if ( cast(InformationControlReplacer)this ) { |
134 | 1315 (cast(InformationControlReplacer) this).showInformationControl(subjectArea, information); |
129 | 1316 return; |
1317 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1318 |
129 | 1319 IInformationControl informationControl= getInformationControl(); |
1320 if (informationControl !is null) { | |
1321 | |
1322 Point sizeConstraints= computeSizeConstraints(fSubjectControl, fSubjectArea, informationControl); | |
138 | 1323 if ( cast(IInformationControlExtension3)informationControl ) { |
134 | 1324 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) informationControl; |
129 | 1325 Rectangle trim= iControl3.computeTrim(); |
1326 sizeConstraints.x += trim.width; | |
1327 sizeConstraints.y += trim.height; | |
1328 } | |
1329 informationControl.setSizeConstraints(sizeConstraints.x, sizeConstraints.y); | |
1330 | |
138 | 1331 if ( cast(IInformationControlExtension2)informationControl ) |
134 | 1332 (cast(IInformationControlExtension2)informationControl).setInput(information); |
129 | 1333 else |
1334 informationControl.setInformation(information.toString()); | |
1335 | |
138 | 1336 if ( cast(IInformationControlExtension)informationControl ) { |
134 | 1337 IInformationControlExtension extension= cast(IInformationControlExtension)informationControl; |
129 | 1338 if (!extension.hasContents()) |
1339 return; | |
1340 } | |
1341 | |
1342 Point size= null; | |
1343 Point location= null; | |
1344 Rectangle bounds= restoreInformationControlBounds(); | |
1345 | |
1346 if (bounds !is null) { | |
1347 if (bounds.x > -1 && bounds.y > -1) | |
1348 location= Geometry.getLocation(bounds); | |
1349 | |
1350 if (bounds.width > -1 && bounds.height > -1) | |
1351 size= Geometry.getSize(bounds); | |
1352 } | |
1353 | |
1354 if (size is null) | |
1355 size= informationControl.computeSizeHint(); | |
1356 | |
1357 if (fEnforceAsMinimalSize) | |
1358 size= Geometry.max(size, sizeConstraints); | |
1359 if (fEnforceAsMaximalSize) | |
1360 size= Geometry.min(size, sizeConstraints); | |
1361 | |
1362 if (location is null) | |
1363 location= computeInformationControlLocation(subjectArea, size); | |
1364 | |
1365 Rectangle controlBounds= Geometry.createRectangle(location, size); | |
1366 cropToClosestMonitor(controlBounds); | |
1367 location= Geometry.getLocation(controlBounds); | |
1368 size= Geometry.getSize(controlBounds); | |
1369 informationControl.setLocation(location); | |
1370 informationControl.setSize(size.x, size.y); | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1371 |
129 | 1372 showInformationControl(subjectArea); |
1373 } | |
1374 } | |
1375 | |
1376 /** | |
1377 * Crops the given bounds such that they lie completely on the closest monitor. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1378 * |
129 | 1379 * @param bounds shell bounds to crop |
1380 * @since 3.4 | |
1381 */ | |
1382 void cropToClosestMonitor(Rectangle bounds) { | |
1383 Rectangle monitorBounds= getClosestMonitor(fSubjectControl.getDisplay(), bounds).getClientArea(); | |
1384 bounds.intersect(monitorBounds); | |
1385 } | |
1386 | |
1387 /** | |
1388 * Hides the information control and stops the information control closer. | |
1389 */ | |
1390 protected void hideInformationControl() { | |
1391 if (fInformationControl !is null) { | |
1392 storeInformationControlBounds(); | |
1393 fInformationControl.setVisible(false); | |
1394 if (fInformationControlCloser !is null) | |
1395 fInformationControlCloser.stop(); | |
1396 } | |
1397 } | |
1398 | |
1399 /** | |
1400 * Shows the information control and starts the information control closer. | |
1401 * This method may not be called by clients. | |
1402 * | |
1403 * @param subjectArea the information area | |
1404 */ | |
1405 protected void showInformationControl(Rectangle subjectArea) { | |
1406 fInformationControl.setVisible(true); | |
1407 | |
1408 if (fTakesFocusWhenVisible) | |
1409 fInformationControl.setFocus(); | |
1410 | |
1411 if (fInformationControlCloser !is null) | |
1412 fInformationControlCloser.start(subjectArea); | |
1413 } | |
1414 | |
1415 /** | |
1416 * Replaces this manager's information control as defined by | |
1417 * the information control replacer. | |
1418 * <strong>Must only be called when {@link #fInformationControl} instanceof {@link IInformationControlExtension3}!</strong> | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1419 * |
129 | 1420 * @param takeFocus <code>true</code> iff the replacing information control should take focus |
1421 * | |
1422 * @since 3.4 | |
1423 */ | |
1424 void replaceInformationControl(bool takeFocus) { | |
1425 if (fInformationControlReplacer !is null && canReplace(fInformationControl)) { | |
134 | 1426 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) fInformationControl; |
129 | 1427 Rectangle b= iControl3.getBounds(); |
1428 Rectangle t= iControl3.computeTrim(); | |
1429 Rectangle contentBounds= new Rectangle(b.x - t.x, b.y - t.y, b.width - t.width, b.height - t.height); | |
134 | 1430 IInformationControlCreator informationPresenterControlCreator= (cast(IInformationControlExtension5) fInformationControl).getInformationPresenterControlCreator(); |
129 | 1431 fInformationControlReplacer.replaceInformationControl(informationPresenterControlCreator, contentBounds, fInformation, fSubjectArea, takeFocus); |
1432 } | |
1433 hideInformationControl(); | |
1434 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1435 |
129 | 1436 /** |
1437 * Disposes this manager's information control. | |
1438 */ | |
1439 public void disposeInformationControl() { | |
1440 if (fInformationControl !is null) { | |
1441 fInformationControl.dispose(); | |
1442 handleInformationControlDisposed(); | |
1443 } | |
1444 } | |
1445 | |
1446 /** | |
1447 * Disposes this manager and if necessary all dependent parts such as | |
1448 * the information control. For symmetry it first disables this manager. | |
1449 */ | |
1450 public void dispose() { | |
1451 if (!fDisposed) { | |
1452 | |
1453 fDisposed= true; | |
1454 | |
1455 setEnabled(false); | |
1456 disposeInformationControl(); | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1457 |
129 | 1458 if (fInformationControlReplacer !is null) { |
1459 fInformationControlReplacer.dispose(); | |
1460 fInformationControlReplacer= null; | |
1461 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1462 |
129 | 1463 if (fSubjectControl !is null && !fSubjectControl.isDisposed() && fSubjectControlDisposeListener !is null) |
1464 fSubjectControl.removeDisposeListener(fSubjectControlDisposeListener); | |
1465 fSubjectControl= null; | |
1466 fSubjectControlDisposeListener= null; | |
1467 | |
1468 fIsCustomInformationControl= false; | |
1469 fCustomInformationControlCreator= null; | |
1470 fInformationControlCreator= null; | |
1471 fInformationControlCloser= null; | |
1472 } | |
1473 } | |
1474 | |
1475 // ------ control's size handling dialog settings ------ | |
1476 | |
1477 /** | |
1478 * Stores the information control's bounds. | |
1479 * | |
1480 * @since 3.0 | |
1481 */ | |
1482 protected void storeInformationControlBounds() { | |
1483 if (fDialogSettings is null || fInformationControl is null || !(fIsRestoringLocation || fIsRestoringSize)) | |
1484 return; | |
1485 | |
138 | 1486 if (!( cast(IInformationControlExtension3)fInformationControl )) |
129 | 1487 throw new UnsupportedOperationException(); |
1488 | |
134 | 1489 bool controlRestoresSize= (cast(IInformationControlExtension3)fInformationControl).restoresSize(); |
1490 bool controlRestoresLocation= (cast(IInformationControlExtension3)fInformationControl).restoresLocation(); | |
129 | 1491 |
134 | 1492 Rectangle bounds= (cast(IInformationControlExtension3)fInformationControl).getBounds(); |
129 | 1493 if (bounds is null) |
1494 return; | |
1495 | |
1496 if (fIsRestoringSize && controlRestoresSize) { | |
1497 fDialogSettings.put(STORE_SIZE_WIDTH, bounds.width); | |
1498 fDialogSettings.put(STORE_SIZE_HEIGHT, bounds.height); | |
1499 } | |
1500 if (fIsRestoringLocation && controlRestoresLocation) { | |
1501 fDialogSettings.put(STORE_LOCATION_X, bounds.x); | |
1502 fDialogSettings.put(STORE_LOCATION_Y, bounds.y); | |
1503 } | |
1504 } | |
1505 /** | |
1506 * Restores the information control's bounds. | |
1507 * | |
1508 * @return the stored bounds | |
1509 * @since 3.0 | |
1510 */ | |
1511 protected Rectangle restoreInformationControlBounds() { | |
1512 if (fDialogSettings is null || !(fIsRestoringLocation || fIsRestoringSize)) | |
1513 return null; | |
1514 | |
138 | 1515 if (!( cast(IInformationControlExtension3)fInformationControl )) |
129 | 1516 throw new UnsupportedOperationException(); |
1517 | |
134 | 1518 bool controlRestoresSize= (cast(IInformationControlExtension3)fInformationControl).restoresSize(); |
1519 bool controlRestoresLocation= (cast(IInformationControlExtension3)fInformationControl).restoresLocation(); | |
129 | 1520 |
1521 Rectangle bounds= new Rectangle(-1, -1, -1, -1); | |
1522 | |
1523 if (fIsRestoringSize && controlRestoresSize) { | |
1524 try { | |
1525 bounds.width= fDialogSettings.getInt(STORE_SIZE_WIDTH); | |
1526 bounds.height= fDialogSettings.getInt(STORE_SIZE_HEIGHT); | |
1527 } catch (NumberFormatException ex) { | |
1528 bounds.width= -1; | |
1529 bounds.height= -1; | |
1530 } | |
1531 } | |
1532 | |
1533 if (fIsRestoringLocation && controlRestoresLocation) { | |
1534 try { | |
1535 bounds.x= fDialogSettings.getInt(STORE_LOCATION_X); | |
1536 bounds.y= fDialogSettings.getInt(STORE_LOCATION_Y); | |
1537 } catch (NumberFormatException ex) { | |
1538 bounds.x= -1; | |
1539 bounds.y= -1; | |
1540 } | |
1541 } | |
1542 | |
1543 // sanity check | |
1544 if (bounds.x is -1 && bounds.y is -1 && bounds.width is -1 && bounds.height is -1) | |
1545 return null; | |
1546 | |
1547 Rectangle maxBounds= null; | |
1548 if (fSubjectControl !is null && !fSubjectControl.isDisposed()) | |
1549 maxBounds= fSubjectControl.getDisplay().getBounds(); | |
1550 else { | |
1551 // fallback | |
1552 Display display= Display.getCurrent(); | |
1553 if (display is null) | |
1554 display= Display.getDefault(); | |
1555 if (display !is null && !display.isDisposed()) | |
1556 maxBounds= display.getBounds(); | |
1557 } | |
1558 | |
1559 | |
1560 if (bounds.width > -1 && bounds.height > -1) { | |
1561 if (maxBounds !is null) { | |
1562 bounds.width= Math.min(bounds.width, maxBounds.width); | |
1563 bounds.height= Math.min(bounds.height, maxBounds.height); | |
1564 } | |
1565 | |
1566 // Enforce an absolute minimal size | |
1567 bounds.width= Math.max(bounds.width, 30); | |
1568 bounds.height= Math.max(bounds.height, 30); | |
1569 } | |
1570 | |
1571 if (bounds.x > -1 && bounds.y > -1 && maxBounds !is null) { | |
1572 bounds.x= Math.max(bounds.x, maxBounds.x); | |
1573 bounds.y= Math.max(bounds.y, maxBounds.y); | |
1574 | |
1575 if (bounds .width > -1 && bounds.height > -1) { | |
1576 bounds.x= Math.min(bounds.x, maxBounds.width - bounds.width); | |
1577 bounds.y= Math.min(bounds.y, maxBounds.height - bounds.height); | |
1578 } | |
1579 } | |
1580 | |
1581 return bounds; | |
1582 } | |
1583 | |
1584 /** | |
1585 * Returns an adapter that gives access to internal methods. | |
1586 * <p> | |
1587 * <strong>Note:</strong> This method is not intended to be referenced or overridden by clients.</p> | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1588 * |
129 | 1589 * @return the replaceable information control accessor |
1590 * @since 3.4 | |
1591 * @noreference This method is not intended to be referenced by clients. | |
1592 * @nooverride This method is not intended to be re-implemented or extended by clients. | |
1593 */ | |
1594 public InternalAccessor getInternalAccessor() { | |
1595 return new MyInternalAccessor(); | |
1596 } | |
1597 } |