Mercurial > projects > dwt-addons
annotate dwtx/jface/text/AbstractInformationControlManager.d @ 159:7926b636c282
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 01:57:58 +0200 |
parents | a9566845f1cb |
children | 3678e4f1a766 |
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 | |
66 import dwtx.jface.text.Assert; // packageimport | |
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 |
129 | 310 public String toString() { |
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 */ | |
146 | 342 public const static Anchor ANCHOR_GLOBAL= new Anchor(DWT.CENTER); |
129 | 343 |
344 /** | |
345 * Dialog store constant for the location's x-coordinate. | |
346 * @since 3.0 | |
347 */ | |
147 | 348 public static const String STORE_LOCATION_X= "location.x"; //$NON-NLS-1$ |
129 | 349 /** |
350 * Dialog store constant for the location's y-coordinate. | |
351 * @since 3.0 | |
352 */ | |
147 | 353 public static const String STORE_LOCATION_Y= "location.y"; //$NON-NLS-1$ |
129 | 354 /** |
355 * Dialog store constant for the size's width. | |
356 * @since 3.0 | |
357 */ | |
147 | 358 public static const String STORE_SIZE_WIDTH= "size.width"; //$NON-NLS-1$ |
129 | 359 /** |
360 * Dialog store constant for the size's height. | |
361 * @since 3.0 | |
362 */ | |
147 | 363 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
|
364 |
129 | 365 /** |
366 * Tells whether this class and its subclasses are in debug mode. | |
367 * <p> | |
368 * Subclasses may use this. | |
369 * </p> | |
370 * @since 3.4 | |
371 */ | |
159 | 372 private static bool DEBUG_; |
373 private static bool DEBUG_init = false; | |
374 protected static bool DEBUG(){ | |
375 if( !DEBUG_init ){ | |
376 DEBUG_init = true; | |
377 DEBUG_ = "true".equalsIgnoreCase(Platform.getDebugOption("dwtx.jface.text/debug/AbstractInformationControlManager")); //$NON-NLS-1$//$NON-NLS-2$ | |
378 } | |
379 return DEBUG_; | |
380 } | |
129 | 381 |
382 | |
383 /** The subject control of the information control */ | |
384 private Control fSubjectControl; | |
385 | |
386 /** The display area for which the information to be presented is valid */ | |
387 private Rectangle fSubjectArea; | |
388 | |
389 /** The information to be presented */ | |
390 private Object fInformation; | |
391 | |
392 /** Indicates whether the information control takes focus when visible */ | |
393 private bool fTakesFocusWhenVisible= false; | |
394 | |
395 /** | |
396 * The information control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
397 * |
129 | 398 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API |
399 * compatibility reasons. | |
400 */ | |
401 protected IInformationControl fInformationControl; | |
402 | |
403 /** | |
404 * The information control creator. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
405 * |
129 | 406 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API |
407 * compatibility reasons. | |
408 */ | |
409 protected IInformationControlCreator fInformationControlCreator; | |
410 | |
411 /** | |
412 * The information control closer. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
413 * |
129 | 414 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API |
415 * compatibility reasons. | |
416 */ | |
417 protected IInformationControlCloser fInformationControlCloser; | |
418 | |
419 /** | |
420 * Indicates that the information control has been disposed. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
421 * |
129 | 422 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API |
423 * compatibility reasons. | |
424 */ | |
425 protected bool fDisposed= false; | |
426 | |
427 /** | |
428 * The information control replacer to be used when this information control | |
429 * needs to be replaced with another information control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
430 * |
129 | 431 * @since 3.4 |
432 */ | |
433 private InformationControlReplacer fInformationControlReplacer; | |
434 | |
435 /** Indicates the enable state of this manager */ | |
436 private bool fEnabled= false; | |
437 | |
438 /** Cached, computed size constraints of the information control in points */ | |
439 private Point fSizeConstraints; | |
440 | |
441 /** The vertical margin when laying out the information control */ | |
442 private int fMarginY= 5; | |
443 | |
444 /** The horizontal margin when laying out the information control */ | |
445 private int fMarginX= 5; | |
446 | |
447 /** The width constraint of the information control in characters */ | |
448 private int fWidthConstraint= 60; | |
449 | |
450 /** The height constraint of the information control in characters */ | |
451 private int fHeightConstraint= 6; | |
452 | |
453 /** Indicates whether the size constraints should be enforced as minimal control size */ | |
454 private bool fEnforceAsMinimalSize= false; | |
455 | |
456 /** Indicates whether the size constraints should be enforced as maximal control size */ | |
457 private bool fEnforceAsMaximalSize= false; | |
458 | |
459 /** The anchor for laying out the information control in relation to the subject control */ | |
159 | 460 private Anchor fAnchor; |
129 | 461 |
462 /** | |
463 * The anchor sequence used to layout the information control if the original anchor | |
464 * can not be used because the information control would not fit in the display client area. | |
465 * <p> | |
466 * The fallback anchor for a given anchor is the one that comes directly after the given anchor or | |
467 * is the first one in the sequence if the given anchor is the last one in the sequence. | |
468 * <p> | |
469 * </p> | |
470 * Note: This sequence is ignored if the original anchor is not contained in this sequence. | |
471 * </p> | |
472 * | |
473 * @see #fAnchor | |
474 */ | |
159 | 475 private Anchor[] fFallbackAnchors; |
129 | 476 /** |
477 * The custom information control creator. | |
478 * @since 3.0 | |
479 */ | |
156 | 480 private /+volatile+/ IInformationControlCreator fCustomInformationControlCreator; |
129 | 481 |
482 /** | |
483 * Tells whether a custom information control is in use. | |
484 * @since 3.0 | |
485 */ | |
486 private bool fIsCustomInformationControl= false; | |
487 | |
488 /** | |
489 * The dialog settings for the control's bounds. | |
490 * @since 3.0 | |
491 */ | |
492 private IDialogSettings fDialogSettings; | |
493 | |
494 /** | |
495 * Tells whether the control's location should be read | |
496 * from the dialog settings and whether the last | |
497 * valid control's size is stored back into the settings. | |
498 * | |
499 * @since 3.0 | |
500 */ | |
501 private bool fIsRestoringLocation; | |
502 | |
503 /** | |
504 * Tells whether the control's size should be read | |
505 * from the dialog settings and whether the last | |
506 * valid control's size is stored back into the settings. | |
507 * | |
508 * @since 3.0 | |
509 */ | |
510 private bool fIsRestoringSize; | |
511 | |
512 /** | |
513 * The dispose listener on the subject control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
514 * |
129 | 515 * @since 3.1 |
516 */ | |
517 private DisposeListener fSubjectControlDisposeListener; | |
518 | |
519 | |
520 /** | |
521 * Creates a new information control manager using the given information control creator. | |
522 * By default the following configuration is given: | |
523 * <ul> | |
524 * <li> enabled is false | |
525 * <li> horizontal margin is 5 points | |
526 * <li> vertical margin is 5 points | |
527 * <li> width constraint is 60 characters | |
528 * <li> height constraint is 6 characters | |
529 * <li> enforce constraints as minimal size is false | |
530 * <li> enforce constraints as maximal size is false | |
531 * <li> layout anchor is ANCHOR_BOTTOM | |
532 * <li> fall back anchors is { ANCHOR_TOP, ANCHOR_BOTTOM, ANCHOR_LEFT, ANCHOR_RIGHT, ANCHOR_GLOBAL } | |
533 * <li> takes focus when visible is false | |
534 * </ul> | |
535 * | |
536 * @param creator the information control creator | |
537 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
538 protected this(IInformationControlCreator creator) { |
159 | 539 fAnchor= ANCHOR_BOTTOM(); |
540 fFallbackAnchors= ANCHORS(); | |
129 | 541 Assert.isNotNull(creator); |
542 fInformationControlCreator= creator; | |
543 } | |
544 | |
545 /** | |
546 * Computes the information to be displayed and the area in which the computed | |
547 * information is valid. Implementation of this method must finish their computation | |
548 * by setting the computation results using <code>setInformation</code>. | |
549 */ | |
550 abstract protected void computeInformation(); | |
551 | |
552 /** | |
553 * Sets the parameters of the information to be displayed. These are the information itself and | |
554 * the area for which the given information is valid. This so called subject area is a graphical | |
555 * region of the information control's subject control. This method calls <code>presentInformation()</code> | |
556 * to trigger the presentation of the computed information. | |
557 * | |
558 * @param information the information, or <code>null</code> if none is available | |
559 * @param subjectArea the subject area, or <code>null</code> if none is available | |
560 */ | |
561 protected final void setInformation(String information, Rectangle subjectArea) { | |
134 | 562 setInformation(cast(Object)information, subjectArea); |
129 | 563 } |
564 | |
565 /** | |
566 * Sets the parameters of the information to be displayed. These are the information itself and | |
567 * the area for which the given information is valid. This so called subject area is a graphical | |
568 * region of the information control's subject control. This method calls <code>presentInformation()</code> | |
569 * to trigger the presentation of the computed information. | |
570 * | |
571 * @param information the information, or <code>null</code> if none is available | |
572 * @param subjectArea the subject area, or <code>null</code> if none is available | |
573 * @since 2.1 | |
574 */ | |
575 protected final void setInformation(Object information, Rectangle subjectArea) { | |
576 fInformation= information; | |
577 fSubjectArea= subjectArea; | |
578 presentInformation(); | |
579 } | |
580 | |
581 /** | |
582 * Sets the information control closer for this manager. | |
583 * | |
584 * @param closer the information control closer for this manager | |
585 */ | |
586 protected void setCloser(IInformationControlCloser closer) { | |
587 fInformationControlCloser= closer; | |
588 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
589 |
129 | 590 /** |
591 * Sets the information control replacer for this manager and disposes the | |
592 * old one if set. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
593 * |
129 | 594 * @param replacer the information control replacer for this manager, or |
595 * <code>null</code> if no information control replacing should | |
596 * take place | |
597 * @since 3.4 | |
598 */ | |
599 void setInformationControlReplacer(InformationControlReplacer replacer) { | |
600 if (fInformationControlReplacer !is null) | |
601 fInformationControlReplacer.dispose(); | |
602 fInformationControlReplacer= replacer; | |
603 } | |
604 | |
605 /** | |
606 * 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
|
607 * |
129 | 608 * @return the current information control replacer or <code>null</code> if none has been installed |
609 * @since 3.4 | |
610 */ | |
611 InformationControlReplacer getInformationControlReplacer() { | |
612 return fInformationControlReplacer; | |
613 } | |
614 | |
615 /** | |
616 * 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
|
617 * |
129 | 618 * @return whether an information control replacer has been installed |
619 * @since 3.4 | |
620 */ | |
621 bool hasInformationControlReplacer() { | |
622 return fInformationControlReplacer !is null; | |
623 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
624 |
129 | 625 /** |
626 * Tests whether the given information control is replaceable. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
627 * |
129 | 628 * @param iControl information control or <code>null</code> if none |
629 * @return <code>true</code> if information control is replaceable, <code>false</code> otherwise | |
630 * @since 3.4 | |
631 */ | |
632 bool canReplace(IInformationControl iControl) { | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
633 return cast(IInformationControlExtension3)iControl |
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
634 && cast(IInformationControlExtension5)iControl |
134 | 635 && (cast(IInformationControlExtension5) iControl).getInformationPresenterControlCreator() !is null; |
129 | 636 } |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
637 |
129 | 638 /** |
639 * 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
|
640 * |
129 | 641 * @return the current information control, or <code>null</code> if none |
642 * @since 3.4 | |
643 */ | |
644 IInformationControl getCurrentInformationControl() { | |
645 return fInformationControl; | |
646 } | |
647 | |
648 /** | |
649 * 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
|
650 * |
129 | 651 * @return <code>true</code> if a replace is in progress |
652 * @since 3.4 | |
653 */ | |
654 bool isReplaceInProgress() { | |
655 return fInformationControlReplacer !is null && fInformationControlReplacer.isReplacing(); | |
656 } | |
657 | |
658 /** | |
659 * Sets the horizontal and vertical margin to be used when laying out the | |
660 * information control relative to the subject control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
661 * |
129 | 662 * @param xMargin the x-margin |
663 * @param yMargin the y-Margin | |
664 */ | |
665 public void setMargins(int xMargin, int yMargin) { | |
666 fMarginX= xMargin; | |
667 fMarginY= yMargin; | |
668 } | |
669 | |
670 /** | |
671 * Sets the width- and height constraints of the information control. | |
672 * | |
673 * @param widthInChar the width constraint in number of characters | |
674 * @param heightInChar the height constrain in number of characters | |
675 * @param enforceAsMinimalSize indicates whether the constraints describe the minimal allowed size of the control | |
676 * @param enforceAsMaximalSize indicates whether the constraints describe the maximal allowed size of the control | |
677 */ | |
678 public void setSizeConstraints(int widthInChar, int heightInChar, bool enforceAsMinimalSize, bool enforceAsMaximalSize) { | |
679 fSizeConstraints= null; | |
680 fWidthConstraint= widthInChar; | |
681 fHeightConstraint= heightInChar; | |
682 fEnforceAsMinimalSize= enforceAsMinimalSize; | |
683 fEnforceAsMaximalSize= enforceAsMaximalSize; | |
684 | |
685 } | |
686 | |
687 /** | |
688 * Tells this information control manager to open the information | |
689 * control with the values contained in the given dialog settings | |
690 * and to store the control's last valid size in the given dialog | |
691 * settings. | |
692 * <p> | |
693 * Note: This API is only valid if the information control implements | |
694 * {@link IInformationControlExtension3}. Not following this restriction | |
695 * will later result in an {@link UnsupportedOperationException}. | |
696 * </p> | |
697 * <p> | |
698 * The constants used to store the values are: | |
699 * <ul> | |
700 * <li>{@link AbstractInformationControlManager#STORE_LOCATION_X}</li> | |
701 * <li>{@link AbstractInformationControlManager#STORE_LOCATION_Y}</li> | |
702 * <li>{@link AbstractInformationControlManager#STORE_SIZE_WIDTH}</li> | |
703 * <li>{@link AbstractInformationControlManager#STORE_SIZE_HEIGHT}</li> | |
704 * </ul> | |
705 * </p> | |
706 * | |
707 * @param dialogSettings | |
708 * @param restoreLocation <code>true</code> iff the location is must be (re-)stored | |
709 * @param restoreSize <code>true</code>iff the size is (re-)stored | |
710 * @since 3.0 | |
711 */ | |
712 public void setRestoreInformationControlBounds(IDialogSettings dialogSettings, bool restoreLocation, bool restoreSize) { | |
713 Assert.isTrue(dialogSettings !is null && (restoreLocation || restoreSize)); | |
714 fDialogSettings= dialogSettings; | |
715 fIsRestoringLocation= restoreLocation; | |
716 fIsRestoringSize= restoreSize; | |
717 } | |
718 | |
719 /** | |
720 * Sets the anchor used for laying out the information control relative to the | |
721 * subject control. E.g, using <code>ANCHOR_TOP</code> indicates that the | |
722 * information control is position above the area for which the information to | |
723 * be displayed is valid. | |
724 * | |
725 * @param anchor the layout anchor | |
726 */ | |
727 public void setAnchor(Anchor anchor) { | |
728 fAnchor= anchor; | |
729 } | |
730 | |
731 /** | |
732 * Sets the anchors fallback sequence used to layout the information control if the original | |
733 * anchor can not be used because the information control would not fit in the display client | |
734 * area. | |
735 * <p> | |
736 * The fallback anchor for a given anchor is the one that comes directly after the given anchor or | |
737 * is the first one in the sequence if the given anchor is the last one in the sequence. | |
738 * <p> | |
739 * </p> | |
740 * Note: This sequence is ignored if the original anchor is not contained in this list. | |
741 * </p> | |
742 * | |
743 * @param fallbackAnchors the array with the anchor fallback sequence | |
744 * @see #setAnchor(AbstractInformationControlManager.Anchor) | |
745 */ | |
746 public void setFallbackAnchors(Anchor[] fallbackAnchors) { | |
747 if (fallbackAnchors !is null) { | |
748 fFallbackAnchors= new Anchor[fallbackAnchors.length]; | |
749 System.arraycopy(fallbackAnchors, 0, fFallbackAnchors, 0, fallbackAnchors.length); | |
750 } else | |
751 fFallbackAnchors= null; | |
752 } | |
753 | |
754 /** | |
755 * Sets the temporary custom control creator, overriding this manager's default information control creator. | |
756 * | |
757 * @param informationControlCreator the creator, possibly <code>null</code> | |
758 * @since 3.0 | |
759 */ | |
760 protected void setCustomInformationControlCreator(IInformationControlCreator informationControlCreator) { | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
761 if (informationControlCreator !is null && cast(IInformationControlCreatorExtension)fCustomInformationControlCreator) { |
134 | 762 IInformationControlCreatorExtension extension= cast(IInformationControlCreatorExtension) fCustomInformationControlCreator; |
129 | 763 if (extension.canReplace(informationControlCreator)) |
764 return; | |
765 } | |
766 fCustomInformationControlCreator= informationControlCreator; | |
767 } | |
768 | |
769 /** | |
770 * Tells the manager whether it should set the focus to the information control when made visible. | |
771 * | |
772 * @param takesFocus <code>true</code> if information control should take focus when made visible | |
773 */ | |
774 public void takesFocusWhenVisible(bool takesFocus) { | |
775 fTakesFocusWhenVisible= takesFocus; | |
776 } | |
777 | |
778 /** | |
779 * Handles the disposal of the subject control. By default, the information control | |
780 * is disposed by calling <code>disposeInformationControl</code>. Subclasses may extend | |
781 * this method. | |
782 */ | |
783 protected void handleSubjectControlDisposed() { | |
784 disposeInformationControl(); | |
785 } | |
786 | |
787 /** | |
788 * Installs this manager on the given control. The control is now taking the role of | |
789 * the subject control. This implementation sets the control also as the information | |
790 * control closer's subject control and automatically enables this manager. | |
791 * | |
792 * @param subjectControl the subject control | |
793 */ | |
794 public void install(Control subjectControl) { | |
795 if (fSubjectControl !is null && !fSubjectControl.isDisposed() && fSubjectControlDisposeListener !is null) | |
796 fSubjectControl.removeDisposeListener(fSubjectControlDisposeListener); | |
797 | |
798 fSubjectControl= subjectControl; | |
799 | |
800 if (fSubjectControl !is null) | |
801 fSubjectControl.addDisposeListener(getSubjectControlDisposeListener()); | |
802 | |
803 if (fInformationControlCloser !is null) | |
804 fInformationControlCloser.setSubjectControl(subjectControl); | |
805 | |
806 setEnabled(true); | |
807 fDisposed= false; | |
808 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
809 |
129 | 810 /** |
811 * Returns the dispose listener which gets added | |
812 * to the subject control. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
813 * |
129 | 814 * @return the dispose listener |
815 * @since 3.1 | |
816 */ | |
817 private DisposeListener getSubjectControlDisposeListener() { | |
818 if (fSubjectControlDisposeListener is null) { | |
135 | 819 fSubjectControlDisposeListener= new class() DisposeListener { |
129 | 820 public void widgetDisposed(DisposeEvent e) { |
821 handleSubjectControlDisposed(); | |
822 } | |
823 }; | |
824 } | |
825 return fSubjectControlDisposeListener; | |
826 } | |
827 | |
828 /** | |
829 * Returns the subject control of this manager/information control. | |
830 * | |
831 * @return the subject control | |
832 */ | |
833 protected Control getSubjectControl() { | |
834 return fSubjectControl; | |
835 } | |
836 | |
837 /** | |
838 * Returns the actual subject area. | |
839 * | |
840 * @return the actual subject area | |
841 */ | |
842 protected Rectangle getSubjectArea() { | |
843 return fSubjectArea; | |
844 } | |
845 | |
846 /** | |
847 * Sets the enable state of this manager. | |
848 * | |
849 * @param enabled the enable state | |
850 * @deprecated visibility will be changed to protected | |
851 */ | |
852 public void setEnabled(bool enabled) { | |
853 fEnabled= enabled; | |
854 } | |
855 | |
856 /** | |
857 * Returns whether this manager is enabled or not. | |
858 * | |
859 * @return <code>true</code> if this manager is enabled otherwise <code>false</code> | |
860 */ | |
861 protected bool isEnabled() { | |
862 return fEnabled; | |
863 } | |
864 | |
865 /** | |
866 * Computes the size constraints of the information control in points based on the | |
867 * default font of the given subject control as well as the size constraints in character | |
868 * width. | |
869 * | |
870 * @param subjectControl the subject control | |
871 * @param informationControl the information control whose size constraints are computed | |
872 * @return the computed size constraints in points | |
873 */ | |
874 protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) { | |
875 | |
876 if (fSizeConstraints is null) { | |
138 | 877 if ( cast(IInformationControlExtension5)informationControl ) { |
134 | 878 IInformationControlExtension5 iControl5= cast(IInformationControlExtension5) informationControl; |
129 | 879 fSizeConstraints= iControl5.computeSizeConstraints(fWidthConstraint, fHeightConstraint); |
880 if (fSizeConstraints !is null) | |
881 return Geometry.copy(fSizeConstraints); | |
882 } | |
883 if (subjectControl is null) | |
884 return null; | |
885 | |
886 GC gc= new GC(subjectControl); | |
887 gc.setFont(subjectControl.getFont()); | |
888 int width= gc.getFontMetrics().getAverageCharWidth(); | |
889 int height = gc.getFontMetrics().getHeight(); | |
890 gc.dispose(); | |
891 | |
892 fSizeConstraints= new Point (fWidthConstraint * width, fHeightConstraint * height); | |
893 } | |
894 | |
895 return new Point(fSizeConstraints.x, fSizeConstraints.y); | |
896 } | |
897 | |
898 /** | |
899 * Computes the size constraints of the information control in points. | |
900 * | |
901 * @param subjectControl the subject control | |
902 * @param subjectArea the subject area | |
903 * @param informationControl the information control whose size constraints are computed | |
904 * @return the computed size constraints in points | |
905 * @since 3.0 | |
906 */ | |
907 protected Point computeSizeConstraints(Control subjectControl, Rectangle subjectArea, IInformationControl informationControl) { | |
908 return computeSizeConstraints(subjectControl, informationControl); | |
909 } | |
910 | |
911 /** | |
912 * Handles the disposal of the information control. By default, the information | |
913 * control closer is stopped. | |
914 */ | |
915 protected void handleInformationControlDisposed() { | |
916 | |
917 storeInformationControlBounds(); | |
918 | |
138 | 919 if ( cast(IInformationControlExtension5)fInformationControl ) |
129 | 920 fSizeConstraints= null; |
921 fInformationControl= null; | |
922 if (fInformationControlCloser !is null) { | |
923 fInformationControlCloser.setInformationControl(null); //XXX: null is against the spec | |
924 fInformationControlCloser.stop(); | |
925 } | |
926 } | |
927 | |
928 /** | |
929 * Returns the information control. If the information control has not been created yet, | |
930 * it is automatically created. | |
931 * | |
932 * @return the information control | |
933 */ | |
934 protected IInformationControl getInformationControl() { | |
935 | |
936 if (fDisposed) | |
937 return fInformationControl; | |
938 | |
939 IInformationControlCreator creator= null; | |
940 | |
941 if (fCustomInformationControlCreator is null) { | |
942 creator= fInformationControlCreator; | |
943 if (fIsCustomInformationControl && fInformationControl !is null) { | |
138 | 944 if ( cast(IInformationControlExtension5)fInformationControl ) |
129 | 945 fSizeConstraints= null; |
946 fInformationControl.dispose(); | |
947 fInformationControl= null; | |
948 } | |
949 fIsCustomInformationControl= false; | |
950 | |
951 } else { | |
952 | |
953 creator= fCustomInformationControlCreator; | |
138 | 954 if ( cast(IInformationControlCreatorExtension)creator ) { |
134 | 955 IInformationControlCreatorExtension extension= cast(IInformationControlCreatorExtension) creator; |
129 | 956 if (fInformationControl !is null && extension.canReuse(fInformationControl)) |
957 return fInformationControl; | |
958 } | |
959 if (fInformationControl !is null) { | |
138 | 960 if ( cast(IInformationControlExtension5)fInformationControl ) |
129 | 961 fSizeConstraints= null; |
962 fInformationControl.dispose(); | |
963 fInformationControl= null; | |
964 } | |
965 fIsCustomInformationControl= true; | |
966 } | |
967 | |
968 if (fInformationControl is null) { | |
969 fInformationControl= creator.createInformationControl(fSubjectControl.getShell()); | |
135 | 970 fInformationControl.addDisposeListener(new class() DisposeListener { |
129 | 971 public void widgetDisposed(DisposeEvent e) { |
972 handleInformationControlDisposed(); | |
973 } | |
974 }); | |
975 | |
976 if (fInformationControlCloser !is null) | |
977 fInformationControlCloser.setInformationControl(fInformationControl); | |
978 } | |
979 | |
980 return fInformationControl; | |
981 } | |
982 | |
983 /** | |
984 * Computes the display location of the information control. The location is computed | |
985 * considering the given subject area, the anchor at the subject area, and the | |
986 * size of the information control. This method does not care about whether the information | |
987 * control would be completely visible when placed at the result location. | |
988 * | |
989 * @param subjectArea the subject area | |
990 * @param controlSize the size of the information control | |
991 * @param anchor the anchor at the subject area | |
992 * @return the display location of the information control | |
993 */ | |
994 protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) { | |
995 int xShift= 0; | |
996 int yShift= 0; | |
997 | |
998 switch (anchor.getSWTFlag()) { | |
999 case DWT.CENTER: | |
1000 Point subjectControlSize= fSubjectControl.getSize(); | |
1001 Point location= new Point(subjectControlSize.x / 2, subjectControlSize.y / 2); | |
1002 location.x -= (controlSize.x / 2); | |
1003 location.y -= (controlSize.y / 2); | |
1004 return fSubjectControl.toDisplay(location); | |
1005 case DWT.BOTTOM: | |
1006 yShift= subjectArea.height + fMarginY; | |
1007 break; | |
1008 case DWT.RIGHT: | |
1009 xShift= fMarginX + subjectArea.width; | |
1010 break; | |
1011 case DWT.TOP: | |
1012 yShift= -controlSize.y - fMarginY; | |
1013 break; | |
1014 case DWT.LEFT: | |
1015 xShift= -controlSize.x - fMarginX; | |
1016 break; | |
1017 } | |
1018 | |
1019 bool isRTL= fSubjectControl !is null && (fSubjectControl.getStyle() & DWT.RIGHT_TO_LEFT) !is 0; | |
1020 if (isRTL) | |
1021 xShift += controlSize.x; | |
1022 | |
1023 return fSubjectControl.toDisplay(new Point(subjectArea.x + xShift, subjectArea.y + yShift)); | |
1024 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1025 |
129 | 1026 /** |
1027 * Computes the area available for an information control given an anchor and the subject area | |
1028 * within <code>bounds</code>. | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1029 * |
129 | 1030 * @param subjectArea the subject area |
1031 * @param bounds the bounds | |
1032 * @param anchor the anchor at the subject area | |
1033 * @return the area available at the given anchor relative to the subject area, confined to the | |
1034 * monitor's client area | |
1035 * @since 3.3 | |
1036 */ | |
1037 protected Rectangle computeAvailableArea(Rectangle subjectArea, Rectangle bounds, Anchor anchor) { | |
1038 Rectangle area; | |
1039 switch (anchor.getSWTFlag()) { | |
1040 case DWT.CENTER: | |
1041 area= bounds; | |
1042 break; | |
1043 case DWT.BOTTOM: | |
1044 int y= subjectArea.y + subjectArea.height + fMarginY; | |
1045 area= new Rectangle(bounds.x, y, bounds.width, bounds.y + bounds.height - y); | |
1046 break; | |
1047 case DWT.RIGHT: | |
1048 int x= subjectArea.x + subjectArea.width + fMarginX; | |
1049 area= new Rectangle(x, bounds.y, bounds.x + bounds.width - x, bounds.height); | |
1050 break; | |
1051 case DWT.TOP: | |
1052 area= new Rectangle(bounds.x, bounds.y, bounds.width, subjectArea.y - bounds.y - fMarginY); | |
1053 break; | |
1054 case DWT.LEFT: | |
1055 area= new Rectangle(bounds.x, bounds.y, subjectArea.x - bounds.x - fMarginX, bounds.height); | |
1056 break; | |
1057 default: | |
1058 Assert.isLegal(false); | |
1059 return null; | |
1060 } | |
1061 | |
1062 // Don't return negative areas if the subjectArea overlaps with the monitor bounds. | |
1063 area.intersect(bounds); | |
1064 return area; | |
1065 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1066 |
129 | 1067 /** |
1068 * Checks whether a control of the given size at the given location would be completely visible | |
1069 * in the given display area when laid out by using the given anchor. If not, this method tries | |
1070 * to shift the control orthogonal to the direction given by the anchor to make it visible. If possible | |
1071 * it updates the location.<p> | |
1072 * This method returns <code>true</code> if the potentially updated position results in a | |
1073 * completely visible control, or <code>false</code> otherwise. | |
1074 * | |
1075 * | |
1076 * @param location the location of the control | |
1077 * @param size the size of the control | |
1078 * @param displayArea the display area in which the control should be visible | |
1079 * @param anchor anchor for lying out the control | |
1080 * @return <code>true</code>if the updated location is useful | |
1081 */ | |
1082 protected bool updateLocation(Point location, Point size, Rectangle displayArea, Anchor anchor) { | |
1083 | |
1084 int displayLowerRightX= displayArea.x + displayArea.width; | |
1085 int displayLowerRightY= displayArea.y + displayArea.height; | |
1086 int lowerRightX= location.x + size.x; | |
1087 int lowerRightY= location.y + size.y; | |
1088 | |
1089 if (ANCHOR_BOTTOM is anchor || ANCHOR_TOP is anchor) { | |
1090 | |
1091 if (ANCHOR_BOTTOM is anchor) { | |
1092 if (lowerRightY > displayLowerRightY) | |
1093 return false; | |
1094 } else { | |
1095 if (location.y < displayArea.y) | |
1096 return false; | |
1097 } | |
1098 | |
1099 if (lowerRightX > displayLowerRightX) | |
1100 location.x= location.x - (lowerRightX - displayLowerRightX); | |
1101 | |
1102 return (location.x >= displayArea.x && location.y >= displayArea.y); | |
1103 | |
1104 } else if (ANCHOR_RIGHT is anchor || ANCHOR_LEFT is anchor) { | |
1105 | |
1106 if (ANCHOR_RIGHT is anchor) { | |
1107 if (lowerRightX > displayLowerRightX) | |
1108 return false; | |
1109 } else { | |
1110 if (location.x < displayArea.x) | |
1111 return false; | |
1112 } | |
1113 | |
1114 if (lowerRightY > displayLowerRightY) | |
1115 location.y= location.y - (lowerRightY - displayLowerRightY); | |
1116 | |
1117 return (location.x >= displayArea.x && location.y >= displayArea.y); | |
1118 | |
1119 } else if (ANCHOR_GLOBAL is anchor) { | |
1120 | |
1121 if (lowerRightX > displayLowerRightX) | |
1122 location.x= location.x - (lowerRightX - displayLowerRightX); | |
1123 | |
1124 if (lowerRightY > displayLowerRightY) | |
1125 location.y= location.y - (lowerRightY - displayLowerRightY); | |
1126 | |
1127 return (location.x >= displayArea.x && location.y >= displayArea.y); | |
1128 } | |
1129 | |
1130 return false; | |
1131 } | |
1132 | |
1133 /** | |
1134 * Returns the next fallback anchor as specified by this manager's | |
1135 * fallback anchor sequence. | |
1136 * <p> | |
1137 * The fallback anchor for the given anchor is the one that comes directly after | |
1138 * the given anchor or is the first one in the sequence if the given anchor is the | |
1139 * last one in the sequence. | |
1140 * </p> | |
1141 * <p> | |
1142 * Note: It is the callers responsibility to prevent an endless loop i.e. to test | |
1143 * whether a given anchor has already been used once. | |
1144 * then | |
1145 * </p> | |
1146 * | |
1147 * @param anchor the current anchor | |
1148 * @return the next fallback anchor or <code>null</code> if no fallback anchor is available | |
1149 */ | |
1150 protected Anchor getNextFallbackAnchor(Anchor anchor) { | |
1151 | |
1152 if (anchor is null || fFallbackAnchors is null) | |
1153 return null; | |
1154 | |
1155 for (int i= 0; i < fFallbackAnchors.length; i++) { | |
1156 if (fFallbackAnchors[i] is anchor) | |
1157 return fFallbackAnchors[i + 1 is fFallbackAnchors.length ? 0 : i + 1]; | |
1158 } | |
1159 | |
1160 return null; | |
1161 } | |
1162 | |
1163 /** | |
1164 * Computes the location of the information control depending on the | |
1165 * subject area and the size of the information control. This method attempts | |
1166 * to find a location at which the information control lies completely in the display's | |
1167 * client area while honoring the manager's default anchor. If this isn't possible using the | |
1168 * default anchor, the fallback anchors are tried out. | |
1169 * | |
1170 * @param subjectArea the information area | |
1171 * @param controlSize the size of the information control | |
1172 * @return the computed location of the information control | |
1173 */ | |
1174 protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) { | |
1175 Rectangle subjectAreaDisplayRelative= Geometry.toDisplay(fSubjectControl, subjectArea); | |
1176 | |
1177 Point upperLeft; | |
1178 Anchor testAnchor= fAnchor; | |
1179 Rectangle bestBounds= null; | |
1180 int bestArea= Integer.MIN_VALUE; | |
1181 Anchor bestAnchor= null; | |
1182 do { | |
1183 | |
1184 upperLeft= computeLocation(subjectArea, controlSize, testAnchor); | |
1185 Monitor monitor= getClosestMonitor(subjectAreaDisplayRelative, testAnchor); | |
1186 if (updateLocation(upperLeft, controlSize, monitor.getClientArea(), testAnchor)) | |
1187 return upperLeft; | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1188 |
129 | 1189 // compute available area for this anchor and update if better than best |
1190 Rectangle available= computeAvailableArea(subjectAreaDisplayRelative, monitor.getClientArea(), testAnchor); | |
1191 Rectangle proposed= new Rectangle(upperLeft.x, upperLeft.y, controlSize.x, controlSize.y); | |
1192 available.intersect(proposed); | |
1193 int area= available.width * available.height; | |
1194 if (area > bestArea) { | |
1195 bestArea= area; | |
1196 bestBounds= available; | |
1197 bestAnchor= testAnchor; | |
1198 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1199 |
129 | 1200 testAnchor= getNextFallbackAnchor(testAnchor); |
1201 | |
1202 } while (testAnchor !is fAnchor && testAnchor !is null); | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1203 |
129 | 1204 // no anchor is perfect - select the one with larges area and set the size to not overlap with the subjectArea |
1205 if (bestAnchor !is ANCHOR_GLOBAL) | |
1206 Geometry.set(controlSize, Geometry.getSize(bestBounds)); | |
1207 return Geometry.getLocation(bestBounds); | |
1208 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1209 |
129 | 1210 /** |
1211 * 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
|
1212 * |
129 | 1213 * @param area the subject area |
1214 * @param anchor the anchor | |
1215 * @return the monitor closest to the edge of <code>area</code> defined by | |
1216 * <code>anchor</code> | |
1217 * @since 3.3 | |
1218 */ | |
1219 private Monitor getClosestMonitor(Rectangle area, Anchor anchor) { | |
1220 Point center; | |
1221 if (ANCHOR_GLOBAL is anchor) | |
1222 center= Geometry.centerPoint(area); | |
1223 else | |
1224 center= Geometry.centerPoint(Geometry.getExtrudedEdge(area, 0, anchor.getSWTFlag())); | |
1225 return getClosestMonitor(fSubjectControl.getDisplay(), Geometry.createRectangle(center, new Point(0, 0))); | |
1226 } | |
1227 | |
1228 /** | |
1229 * Copied from dwtx.jface.window.Window. Returns the monitor whose client area contains | |
1230 * the given point. If no monitor contains the point, returns the monitor that is closest to the | |
1231 * 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
|
1232 * |
129 | 1233 * @param display the display to search for monitors |
1234 * @param rectangle the rectangle to find the closest monitor for (display coordinates) | |
1235 * @return the monitor closest to the given point | |
1236 * @since 3.3 | |
1237 */ | |
1238 private Monitor getClosestMonitor(Display display, Rectangle rectangle) { | |
1239 int closest = Integer.MAX_VALUE; | |
1240 | |
1241 Point toFind= Geometry.centerPoint(rectangle); | |
1242 Monitor[] monitors = display.getMonitors(); | |
1243 Monitor result = monitors[0]; | |
1244 | |
1245 for (int idx = 0; idx < monitors.length; idx++) { | |
1246 Monitor current = monitors[idx]; | |
1247 | |
1248 Rectangle clientArea = current.getClientArea(); | |
1249 | |
1250 if (clientArea.contains(toFind)) { | |
1251 return current; | |
1252 } | |
1253 | |
1254 int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); | |
1255 if (distance < closest) { | |
1256 closest = distance; | |
1257 result = current; | |
1258 } | |
1259 } | |
1260 | |
1261 return result; | |
1262 } | |
1263 | |
1264 /** | |
1265 * Computes information to be displayed as well as the subject area | |
1266 * and initiates that this information is presented in the information control. | |
1267 * This happens only if this controller is enabled. | |
1268 */ | |
1269 public void showInformation() { | |
1270 if (fEnabled) | |
1271 doShowInformation(); | |
1272 } | |
1273 | |
1274 /** | |
1275 * Computes information to be displayed as well as the subject area | |
1276 * and initiates that this information is presented in the information control. | |
1277 */ | |
1278 protected void doShowInformation() { | |
1279 fSubjectArea= null; | |
1280 fInformation= null; | |
1281 computeInformation(); | |
1282 } | |
1283 | |
1284 /** | |
1285 * Presents the information in the information control or hides the information | |
1286 * control if no information should be presented. The information has previously | |
1287 * been set using <code>setInformation</code>. | |
1288 */ | |
1289 protected void presentInformation() { | |
1290 bool hasContents= false; | |
138 | 1291 if ( cast(String)fInformation ) |
134 | 1292 hasContents= (cast(String)fInformation).trim().length() > 0; |
129 | 1293 else |
1294 hasContents= (fInformation !is null); | |
1295 | |
1296 if (fSubjectArea !is null && hasContents) | |
1297 internalShowInformationControl(fSubjectArea, fInformation); | |
1298 else | |
1299 hideInformationControl(); | |
1300 } | |
1301 | |
1302 /** | |
1303 * Opens the information control with the given information and the specified | |
1304 * subject area. It also activates the information control closer. | |
1305 * | |
1306 * @param subjectArea the information area | |
1307 * @param information the information | |
1308 */ | |
1309 private void internalShowInformationControl(Rectangle subjectArea, Object information) { | |
138 | 1310 if ( cast(InformationControlReplacer)this ) { |
134 | 1311 (cast(InformationControlReplacer) this).showInformationControl(subjectArea, information); |
129 | 1312 return; |
1313 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1314 |
129 | 1315 IInformationControl informationControl= getInformationControl(); |
1316 if (informationControl !is null) { | |
1317 | |
1318 Point sizeConstraints= computeSizeConstraints(fSubjectControl, fSubjectArea, informationControl); | |
138 | 1319 if ( cast(IInformationControlExtension3)informationControl ) { |
134 | 1320 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) informationControl; |
129 | 1321 Rectangle trim= iControl3.computeTrim(); |
1322 sizeConstraints.x += trim.width; | |
1323 sizeConstraints.y += trim.height; | |
1324 } | |
1325 informationControl.setSizeConstraints(sizeConstraints.x, sizeConstraints.y); | |
1326 | |
138 | 1327 if ( cast(IInformationControlExtension2)informationControl ) |
134 | 1328 (cast(IInformationControlExtension2)informationControl).setInput(information); |
129 | 1329 else |
1330 informationControl.setInformation(information.toString()); | |
1331 | |
138 | 1332 if ( cast(IInformationControlExtension)informationControl ) { |
134 | 1333 IInformationControlExtension extension= cast(IInformationControlExtension)informationControl; |
129 | 1334 if (!extension.hasContents()) |
1335 return; | |
1336 } | |
1337 | |
1338 Point size= null; | |
1339 Point location= null; | |
1340 Rectangle bounds= restoreInformationControlBounds(); | |
1341 | |
1342 if (bounds !is null) { | |
1343 if (bounds.x > -1 && bounds.y > -1) | |
1344 location= Geometry.getLocation(bounds); | |
1345 | |
1346 if (bounds.width > -1 && bounds.height > -1) | |
1347 size= Geometry.getSize(bounds); | |
1348 } | |
1349 | |
1350 if (size is null) | |
1351 size= informationControl.computeSizeHint(); | |
1352 | |
1353 if (fEnforceAsMinimalSize) | |
1354 size= Geometry.max(size, sizeConstraints); | |
1355 if (fEnforceAsMaximalSize) | |
1356 size= Geometry.min(size, sizeConstraints); | |
1357 | |
1358 if (location is null) | |
1359 location= computeInformationControlLocation(subjectArea, size); | |
1360 | |
1361 Rectangle controlBounds= Geometry.createRectangle(location, size); | |
1362 cropToClosestMonitor(controlBounds); | |
1363 location= Geometry.getLocation(controlBounds); | |
1364 size= Geometry.getSize(controlBounds); | |
1365 informationControl.setLocation(location); | |
1366 informationControl.setSize(size.x, size.y); | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1367 |
129 | 1368 showInformationControl(subjectArea); |
1369 } | |
1370 } | |
1371 | |
1372 /** | |
1373 * 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
|
1374 * |
129 | 1375 * @param bounds shell bounds to crop |
1376 * @since 3.4 | |
1377 */ | |
1378 void cropToClosestMonitor(Rectangle bounds) { | |
1379 Rectangle monitorBounds= getClosestMonitor(fSubjectControl.getDisplay(), bounds).getClientArea(); | |
1380 bounds.intersect(monitorBounds); | |
1381 } | |
1382 | |
1383 /** | |
1384 * Hides the information control and stops the information control closer. | |
1385 */ | |
1386 protected void hideInformationControl() { | |
1387 if (fInformationControl !is null) { | |
1388 storeInformationControlBounds(); | |
1389 fInformationControl.setVisible(false); | |
1390 if (fInformationControlCloser !is null) | |
1391 fInformationControlCloser.stop(); | |
1392 } | |
1393 } | |
1394 | |
1395 /** | |
1396 * Shows the information control and starts the information control closer. | |
1397 * This method may not be called by clients. | |
1398 * | |
1399 * @param subjectArea the information area | |
1400 */ | |
1401 protected void showInformationControl(Rectangle subjectArea) { | |
1402 fInformationControl.setVisible(true); | |
1403 | |
1404 if (fTakesFocusWhenVisible) | |
1405 fInformationControl.setFocus(); | |
1406 | |
1407 if (fInformationControlCloser !is null) | |
1408 fInformationControlCloser.start(subjectArea); | |
1409 } | |
1410 | |
1411 /** | |
1412 * Replaces this manager's information control as defined by | |
1413 * the information control replacer. | |
1414 * <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
|
1415 * |
129 | 1416 * @param takeFocus <code>true</code> iff the replacing information control should take focus |
1417 * | |
1418 * @since 3.4 | |
1419 */ | |
1420 void replaceInformationControl(bool takeFocus) { | |
1421 if (fInformationControlReplacer !is null && canReplace(fInformationControl)) { | |
134 | 1422 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) fInformationControl; |
129 | 1423 Rectangle b= iControl3.getBounds(); |
1424 Rectangle t= iControl3.computeTrim(); | |
1425 Rectangle contentBounds= new Rectangle(b.x - t.x, b.y - t.y, b.width - t.width, b.height - t.height); | |
134 | 1426 IInformationControlCreator informationPresenterControlCreator= (cast(IInformationControlExtension5) fInformationControl).getInformationPresenterControlCreator(); |
129 | 1427 fInformationControlReplacer.replaceInformationControl(informationPresenterControlCreator, contentBounds, fInformation, fSubjectArea, takeFocus); |
1428 } | |
1429 hideInformationControl(); | |
1430 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1431 |
129 | 1432 /** |
1433 * Disposes this manager's information control. | |
1434 */ | |
1435 public void disposeInformationControl() { | |
1436 if (fInformationControl !is null) { | |
1437 fInformationControl.dispose(); | |
1438 handleInformationControlDisposed(); | |
1439 } | |
1440 } | |
1441 | |
1442 /** | |
1443 * Disposes this manager and if necessary all dependent parts such as | |
1444 * the information control. For symmetry it first disables this manager. | |
1445 */ | |
1446 public void dispose() { | |
1447 if (!fDisposed) { | |
1448 | |
1449 fDisposed= true; | |
1450 | |
1451 setEnabled(false); | |
1452 disposeInformationControl(); | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1453 |
129 | 1454 if (fInformationControlReplacer !is null) { |
1455 fInformationControlReplacer.dispose(); | |
1456 fInformationControlReplacer= null; | |
1457 } | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1458 |
129 | 1459 if (fSubjectControl !is null && !fSubjectControl.isDisposed() && fSubjectControlDisposeListener !is null) |
1460 fSubjectControl.removeDisposeListener(fSubjectControlDisposeListener); | |
1461 fSubjectControl= null; | |
1462 fSubjectControlDisposeListener= null; | |
1463 | |
1464 fIsCustomInformationControl= false; | |
1465 fCustomInformationControlCreator= null; | |
1466 fInformationControlCreator= null; | |
1467 fInformationControlCloser= null; | |
1468 } | |
1469 } | |
1470 | |
1471 // ------ control's size handling dialog settings ------ | |
1472 | |
1473 /** | |
1474 * Stores the information control's bounds. | |
1475 * | |
1476 * @since 3.0 | |
1477 */ | |
1478 protected void storeInformationControlBounds() { | |
1479 if (fDialogSettings is null || fInformationControl is null || !(fIsRestoringLocation || fIsRestoringSize)) | |
1480 return; | |
1481 | |
138 | 1482 if (!( cast(IInformationControlExtension3)fInformationControl )) |
129 | 1483 throw new UnsupportedOperationException(); |
1484 | |
134 | 1485 bool controlRestoresSize= (cast(IInformationControlExtension3)fInformationControl).restoresSize(); |
1486 bool controlRestoresLocation= (cast(IInformationControlExtension3)fInformationControl).restoresLocation(); | |
129 | 1487 |
134 | 1488 Rectangle bounds= (cast(IInformationControlExtension3)fInformationControl).getBounds(); |
129 | 1489 if (bounds is null) |
1490 return; | |
1491 | |
1492 if (fIsRestoringSize && controlRestoresSize) { | |
1493 fDialogSettings.put(STORE_SIZE_WIDTH, bounds.width); | |
1494 fDialogSettings.put(STORE_SIZE_HEIGHT, bounds.height); | |
1495 } | |
1496 if (fIsRestoringLocation && controlRestoresLocation) { | |
1497 fDialogSettings.put(STORE_LOCATION_X, bounds.x); | |
1498 fDialogSettings.put(STORE_LOCATION_Y, bounds.y); | |
1499 } | |
1500 } | |
1501 /** | |
1502 * Restores the information control's bounds. | |
1503 * | |
1504 * @return the stored bounds | |
1505 * @since 3.0 | |
1506 */ | |
1507 protected Rectangle restoreInformationControlBounds() { | |
1508 if (fDialogSettings is null || !(fIsRestoringLocation || fIsRestoringSize)) | |
1509 return null; | |
1510 | |
138 | 1511 if (!( cast(IInformationControlExtension3)fInformationControl )) |
129 | 1512 throw new UnsupportedOperationException(); |
1513 | |
134 | 1514 bool controlRestoresSize= (cast(IInformationControlExtension3)fInformationControl).restoresSize(); |
1515 bool controlRestoresLocation= (cast(IInformationControlExtension3)fInformationControl).restoresLocation(); | |
129 | 1516 |
1517 Rectangle bounds= new Rectangle(-1, -1, -1, -1); | |
1518 | |
1519 if (fIsRestoringSize && controlRestoresSize) { | |
1520 try { | |
1521 bounds.width= fDialogSettings.getInt(STORE_SIZE_WIDTH); | |
1522 bounds.height= fDialogSettings.getInt(STORE_SIZE_HEIGHT); | |
1523 } catch (NumberFormatException ex) { | |
1524 bounds.width= -1; | |
1525 bounds.height= -1; | |
1526 } | |
1527 } | |
1528 | |
1529 if (fIsRestoringLocation && controlRestoresLocation) { | |
1530 try { | |
1531 bounds.x= fDialogSettings.getInt(STORE_LOCATION_X); | |
1532 bounds.y= fDialogSettings.getInt(STORE_LOCATION_Y); | |
1533 } catch (NumberFormatException ex) { | |
1534 bounds.x= -1; | |
1535 bounds.y= -1; | |
1536 } | |
1537 } | |
1538 | |
1539 // sanity check | |
1540 if (bounds.x is -1 && bounds.y is -1 && bounds.width is -1 && bounds.height is -1) | |
1541 return null; | |
1542 | |
1543 Rectangle maxBounds= null; | |
1544 if (fSubjectControl !is null && !fSubjectControl.isDisposed()) | |
1545 maxBounds= fSubjectControl.getDisplay().getBounds(); | |
1546 else { | |
1547 // fallback | |
1548 Display display= Display.getCurrent(); | |
1549 if (display is null) | |
1550 display= Display.getDefault(); | |
1551 if (display !is null && !display.isDisposed()) | |
1552 maxBounds= display.getBounds(); | |
1553 } | |
1554 | |
1555 | |
1556 if (bounds.width > -1 && bounds.height > -1) { | |
1557 if (maxBounds !is null) { | |
1558 bounds.width= Math.min(bounds.width, maxBounds.width); | |
1559 bounds.height= Math.min(bounds.height, maxBounds.height); | |
1560 } | |
1561 | |
1562 // Enforce an absolute minimal size | |
1563 bounds.width= Math.max(bounds.width, 30); | |
1564 bounds.height= Math.max(bounds.height, 30); | |
1565 } | |
1566 | |
1567 if (bounds.x > -1 && bounds.y > -1 && maxBounds !is null) { | |
1568 bounds.x= Math.max(bounds.x, maxBounds.x); | |
1569 bounds.y= Math.max(bounds.y, maxBounds.y); | |
1570 | |
1571 if (bounds .width > -1 && bounds.height > -1) { | |
1572 bounds.x= Math.min(bounds.x, maxBounds.width - bounds.width); | |
1573 bounds.y= Math.min(bounds.y, maxBounds.height - bounds.height); | |
1574 } | |
1575 } | |
1576 | |
1577 return bounds; | |
1578 } | |
1579 | |
1580 /** | |
1581 * Returns an adapter that gives access to internal methods. | |
1582 * <p> | |
1583 * <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
|
1584 * |
129 | 1585 * @return the replaceable information control accessor |
1586 * @since 3.4 | |
1587 * @noreference This method is not intended to be referenced by clients. | |
1588 * @nooverride This method is not intended to be re-implemented or extended by clients. | |
1589 */ | |
1590 public InternalAccessor getInternalAccessor() { | |
1591 return new MyInternalAccessor(); | |
1592 } | |
1593 } |