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