Mercurial > projects > dwt2
comparison org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultInformationControl.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.jface.text.DefaultInformationControl; | |
14 | |
15 import org.eclipse.jface.text.IDocumentPartitioningListener; // packageimport | |
16 import org.eclipse.jface.text.DefaultTextHover; // packageimport | |
17 import org.eclipse.jface.text.AbstractInformationControl; // packageimport | |
18 import org.eclipse.jface.text.TextUtilities; // packageimport | |
19 import org.eclipse.jface.text.IInformationControlCreatorExtension; // packageimport | |
20 import org.eclipse.jface.text.AbstractInformationControlManager; // packageimport | |
21 import org.eclipse.jface.text.ITextViewerExtension2; // packageimport | |
22 import org.eclipse.jface.text.IDocumentPartitioner; // packageimport | |
23 import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport | |
24 import org.eclipse.jface.text.ITextSelection; // packageimport | |
25 import org.eclipse.jface.text.Document; // packageimport | |
26 import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider; // packageimport | |
27 import org.eclipse.jface.text.ITextListener; // packageimport | |
28 import org.eclipse.jface.text.BadPartitioningException; // packageimport | |
29 import org.eclipse.jface.text.ITextViewerExtension5; // packageimport | |
30 import org.eclipse.jface.text.IDocumentPartitionerExtension3; // packageimport | |
31 import org.eclipse.jface.text.IUndoManager; // packageimport | |
32 import org.eclipse.jface.text.ITextHoverExtension2; // packageimport | |
33 import org.eclipse.jface.text.IRepairableDocument; // packageimport | |
34 import org.eclipse.jface.text.IRewriteTarget; // packageimport | |
35 import org.eclipse.jface.text.DefaultPositionUpdater; // packageimport | |
36 import org.eclipse.jface.text.RewriteSessionEditProcessor; // packageimport | |
37 import org.eclipse.jface.text.TextViewerHoverManager; // packageimport | |
38 import org.eclipse.jface.text.DocumentRewriteSession; // packageimport | |
39 import org.eclipse.jface.text.TextViewer; // packageimport | |
40 import org.eclipse.jface.text.ITextViewerExtension8; // packageimport | |
41 import org.eclipse.jface.text.RegExMessages; // packageimport | |
42 import org.eclipse.jface.text.IDelayedInputChangeProvider; // packageimport | |
43 import org.eclipse.jface.text.ITextOperationTargetExtension; // packageimport | |
44 import org.eclipse.jface.text.IWidgetTokenOwner; // packageimport | |
45 import org.eclipse.jface.text.IViewportListener; // packageimport | |
46 import org.eclipse.jface.text.GapTextStore; // packageimport | |
47 import org.eclipse.jface.text.MarkSelection; // packageimport | |
48 import org.eclipse.jface.text.IDocumentPartitioningListenerExtension; // packageimport | |
49 import org.eclipse.jface.text.IDocumentAdapterExtension; // packageimport | |
50 import org.eclipse.jface.text.IInformationControlExtension; // packageimport | |
51 import org.eclipse.jface.text.IDocumentPartitioningListenerExtension2; // packageimport | |
52 import org.eclipse.jface.text.DefaultDocumentAdapter; // packageimport | |
53 import org.eclipse.jface.text.ITextViewerExtension3; // packageimport | |
54 import org.eclipse.jface.text.IInformationControlCreator; // packageimport | |
55 import org.eclipse.jface.text.TypedRegion; // packageimport | |
56 import org.eclipse.jface.text.ISynchronizable; // packageimport | |
57 import org.eclipse.jface.text.IMarkRegionTarget; // packageimport | |
58 import org.eclipse.jface.text.TextViewerUndoManager; // packageimport | |
59 import org.eclipse.jface.text.IRegion; // packageimport | |
60 import org.eclipse.jface.text.IInformationControlExtension2; // packageimport | |
61 import org.eclipse.jface.text.IDocumentExtension4; // packageimport | |
62 import org.eclipse.jface.text.IDocumentExtension2; // packageimport | |
63 import org.eclipse.jface.text.IDocumentPartitionerExtension2; // packageimport | |
64 import org.eclipse.jface.text.Assert; // packageimport | |
65 import org.eclipse.jface.text.IWidgetTokenOwnerExtension; // packageimport | |
66 import org.eclipse.jface.text.DocumentClone; // packageimport | |
67 import org.eclipse.jface.text.DefaultUndoManager; // packageimport | |
68 import org.eclipse.jface.text.IFindReplaceTarget; // packageimport | |
69 import org.eclipse.jface.text.IAutoEditStrategy; // packageimport | |
70 import org.eclipse.jface.text.ILineTrackerExtension; // packageimport | |
71 import org.eclipse.jface.text.IUndoManagerExtension; // packageimport | |
72 import org.eclipse.jface.text.TextSelection; // packageimport | |
73 import org.eclipse.jface.text.DefaultAutoIndentStrategy; // packageimport | |
74 import org.eclipse.jface.text.IAutoIndentStrategy; // packageimport | |
75 import org.eclipse.jface.text.IPainter; // packageimport | |
76 import org.eclipse.jface.text.IInformationControl; // packageimport | |
77 import org.eclipse.jface.text.IInformationControlExtension3; // packageimport | |
78 import org.eclipse.jface.text.ITextViewerExtension6; // packageimport | |
79 import org.eclipse.jface.text.IInformationControlExtension4; // packageimport | |
80 import org.eclipse.jface.text.DefaultLineTracker; // packageimport | |
81 import org.eclipse.jface.text.IDocumentInformationMappingExtension; // packageimport | |
82 import org.eclipse.jface.text.IRepairableDocumentExtension; // packageimport | |
83 import org.eclipse.jface.text.ITextHover; // packageimport | |
84 import org.eclipse.jface.text.FindReplaceDocumentAdapter; // packageimport | |
85 import org.eclipse.jface.text.ILineTracker; // packageimport | |
86 import org.eclipse.jface.text.Line; // packageimport | |
87 import org.eclipse.jface.text.ITextViewerExtension; // packageimport | |
88 import org.eclipse.jface.text.IDocumentAdapter; // packageimport | |
89 import org.eclipse.jface.text.TextEvent; // packageimport | |
90 import org.eclipse.jface.text.BadLocationException; // packageimport | |
91 import org.eclipse.jface.text.AbstractDocument; // packageimport | |
92 import org.eclipse.jface.text.AbstractLineTracker; // packageimport | |
93 import org.eclipse.jface.text.TreeLineTracker; // packageimport | |
94 import org.eclipse.jface.text.ITextPresentationListener; // packageimport | |
95 import org.eclipse.jface.text.Region; // packageimport | |
96 import org.eclipse.jface.text.ITextViewer; // packageimport | |
97 import org.eclipse.jface.text.IDocumentInformationMapping; // packageimport | |
98 import org.eclipse.jface.text.MarginPainter; // packageimport | |
99 import org.eclipse.jface.text.IPaintPositionManager; // packageimport | |
100 import org.eclipse.jface.text.TextPresentation; // packageimport | |
101 import org.eclipse.jface.text.IFindReplaceTargetExtension; // packageimport | |
102 import org.eclipse.jface.text.ISlaveDocumentManagerExtension; // packageimport | |
103 import org.eclipse.jface.text.ISelectionValidator; // packageimport | |
104 import org.eclipse.jface.text.IDocumentExtension; // packageimport | |
105 import org.eclipse.jface.text.PropagatingFontFieldEditor; // packageimport | |
106 import org.eclipse.jface.text.ConfigurableLineTracker; // packageimport | |
107 import org.eclipse.jface.text.SlaveDocumentEvent; // packageimport | |
108 import org.eclipse.jface.text.IDocumentListener; // packageimport | |
109 import org.eclipse.jface.text.PaintManager; // packageimport | |
110 import org.eclipse.jface.text.IFindReplaceTargetExtension3; // packageimport | |
111 import org.eclipse.jface.text.ITextDoubleClickStrategy; // packageimport | |
112 import org.eclipse.jface.text.IDocumentExtension3; // packageimport | |
113 import org.eclipse.jface.text.Position; // packageimport | |
114 import org.eclipse.jface.text.TextMessages; // packageimport | |
115 import org.eclipse.jface.text.CopyOnWriteTextStore; // packageimport | |
116 import org.eclipse.jface.text.WhitespaceCharacterPainter; // packageimport | |
117 import org.eclipse.jface.text.IPositionUpdater; // packageimport | |
118 import org.eclipse.jface.text.DefaultTextDoubleClickStrategy; // packageimport | |
119 import org.eclipse.jface.text.ListLineTracker; // packageimport | |
120 import org.eclipse.jface.text.ITextInputListener; // packageimport | |
121 import org.eclipse.jface.text.BadPositionCategoryException; // packageimport | |
122 import org.eclipse.jface.text.IWidgetTokenKeeperExtension; // packageimport | |
123 import org.eclipse.jface.text.IInputChangedListener; // packageimport | |
124 import org.eclipse.jface.text.ITextOperationTarget; // packageimport | |
125 import org.eclipse.jface.text.IDocumentInformationMappingExtension2; // packageimport | |
126 import org.eclipse.jface.text.ITextViewerExtension7; // packageimport | |
127 import org.eclipse.jface.text.IInformationControlExtension5; // packageimport | |
128 import org.eclipse.jface.text.IDocumentRewriteSessionListener; // packageimport | |
129 import org.eclipse.jface.text.JFaceTextUtil; // packageimport | |
130 import org.eclipse.jface.text.AbstractReusableInformationControlCreator; // packageimport | |
131 import org.eclipse.jface.text.TabsToSpacesConverter; // packageimport | |
132 import org.eclipse.jface.text.CursorLinePainter; // packageimport | |
133 import org.eclipse.jface.text.ITextHoverExtension; // packageimport | |
134 import org.eclipse.jface.text.IEventConsumer; // packageimport | |
135 import org.eclipse.jface.text.IDocument; // packageimport | |
136 import org.eclipse.jface.text.IWidgetTokenKeeper; // packageimport | |
137 import org.eclipse.jface.text.DocumentCommand; // packageimport | |
138 import org.eclipse.jface.text.TypedPosition; // packageimport | |
139 import org.eclipse.jface.text.IEditingSupportRegistry; // packageimport | |
140 import org.eclipse.jface.text.IDocumentPartitionerExtension; // packageimport | |
141 import org.eclipse.jface.text.AbstractHoverInformationControlManager; // packageimport | |
142 import org.eclipse.jface.text.IEditingSupport; // packageimport | |
143 import org.eclipse.jface.text.IMarkSelection; // packageimport | |
144 import org.eclipse.jface.text.ISlaveDocumentManager; // packageimport | |
145 import org.eclipse.jface.text.DocumentEvent; // packageimport | |
146 import org.eclipse.jface.text.DocumentPartitioningChangedEvent; // packageimport | |
147 import org.eclipse.jface.text.ITextStore; // packageimport | |
148 import org.eclipse.jface.text.JFaceTextMessages; // packageimport | |
149 import org.eclipse.jface.text.DocumentRewriteSessionEvent; // packageimport | |
150 import org.eclipse.jface.text.SequentialRewriteTextStore; // packageimport | |
151 import org.eclipse.jface.text.DocumentRewriteSessionType; // packageimport | |
152 import org.eclipse.jface.text.TextAttribute; // packageimport | |
153 import org.eclipse.jface.text.ITextViewerExtension4; // packageimport | |
154 import org.eclipse.jface.text.ITypedRegion; // packageimport | |
155 | |
156 | |
157 import java.lang.all; | |
158 import java.util.Set; | |
159 | |
160 | |
161 | |
162 import org.eclipse.swt.SWT; | |
163 import org.eclipse.swt.custom.StyledText; | |
164 import org.eclipse.swt.events.DisposeEvent; | |
165 import org.eclipse.swt.events.DisposeListener; | |
166 import org.eclipse.swt.graphics.Color; | |
167 import org.eclipse.swt.graphics.Drawable; | |
168 import org.eclipse.swt.graphics.Point; | |
169 import org.eclipse.swt.graphics.Rectangle; | |
170 import org.eclipse.swt.layout.FillLayout; | |
171 import org.eclipse.swt.widgets.Composite; | |
172 import org.eclipse.swt.widgets.Display; | |
173 import org.eclipse.swt.widgets.Shell; | |
174 import org.eclipse.jface.action.ToolBarManager; | |
175 import org.eclipse.jface.internal.text.html.HTMLTextPresenter; | |
176 import org.eclipse.jface.resource.JFaceResources; | |
177 import org.eclipse.jface.util.Geometry; | |
178 | |
179 /** | |
180 * An information presenter determines the style presentation | |
181 * of information displayed in the default information control. | |
182 * The interface can be implemented by clients. | |
183 */ | |
184 public interface IInformationPresenter { | |
185 | |
186 /** | |
187 * Updates the given presentation of the given information and | |
188 * thereby may manipulate the information to be displayed. The manipulation | |
189 * could be the extraction of textual encoded style information etc. Returns the | |
190 * manipulated information. | |
191 * <p> | |
192 * <strong>Note:</strong> The given display must only be used for measuring.</p> | |
193 * | |
194 * @param display the display of the information control | |
195 * @param hoverInfo the information to be presented | |
196 * @param presentation the presentation to be updated | |
197 * @param maxWidth the maximal width in pixels | |
198 * @param maxHeight the maximal height in pixels | |
199 * | |
200 * @return the manipulated information | |
201 * @deprecated As of 3.2, replaced by {@link DefaultInformationControl.IInformationPresenterExtension#updatePresentation(Drawable, String, TextPresentation, int, int)} | |
202 */ | |
203 String updatePresentation(Display display, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight); | |
204 } | |
205 alias IInformationPresenter DefaultInformationControl_IInformationPresenter; | |
206 | |
207 /** | |
208 * An information presenter determines the style presentation | |
209 * of information displayed in the default information control. | |
210 * The interface can be implemented by clients. | |
211 * | |
212 * @since 3.2 | |
213 */ | |
214 public interface IInformationPresenterExtension { | |
215 | |
216 /** | |
217 * Updates the given presentation of the given information and | |
218 * thereby may manipulate the information to be displayed. The manipulation | |
219 * could be the extraction of textual encoded style information etc. Returns the | |
220 * manipulated information. | |
221 * <p> | |
222 * Replaces {@link DefaultInformationControl.IInformationPresenter#updatePresentation(Display, String, TextPresentation, int, int)} | |
223 * Implementations should use the font of the given <code>drawable</code> to calculate | |
224 * the size of the text to be presented. | |
225 * </p> | |
226 * | |
227 * @param drawable the drawable of the information control | |
228 * @param hoverInfo the information to be presented | |
229 * @param presentation the presentation to be updated | |
230 * @param maxWidth the maximal width in pixels | |
231 * @param maxHeight the maximal height in pixels | |
232 * | |
233 * @return the manipulated information | |
234 */ | |
235 String updatePresentation(Drawable drawable, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight); | |
236 } | |
237 alias IInformationPresenterExtension DefaultInformationControl_IInformationPresenterExtension; | |
238 | |
239 | |
240 /** | |
241 * Default implementation of {@link org.eclipse.jface.text.IInformationControl}. | |
242 * <p> | |
243 * Displays textual information in a {@link org.eclipse.swt.custom.StyledText} | |
244 * widget. Before displaying, the information set to this information control is | |
245 * processed by an <code>IInformationPresenter</code>. | |
246 * | |
247 * @since 2.0 | |
248 */ | |
249 public class DefaultInformationControl : AbstractInformationControl , DisposeListener { | |
250 | |
251 /** | |
252 * Inner border thickness in pixels. | |
253 * @since 3.1 | |
254 */ | |
255 private static const int INNER_BORDER= 1; | |
256 | |
257 /** The control's text widget */ | |
258 private StyledText fText; | |
259 /** The information presenter, or <code>null</code> if none. */ | |
260 private const IInformationPresenter fPresenter; | |
261 /** A cached text presentation */ | |
262 private const TextPresentation fPresentation; | |
263 | |
264 /** | |
265 * Additional styles to use for the text control. | |
266 * @since 3.4, previously called <code>fTextStyle</code> | |
267 */ | |
268 private const int fAdditionalTextStyles; | |
269 | |
270 /** | |
271 * Creates a default information control with the given shell as parent. An information | |
272 * presenter that can handle simple HTML is used to process the information to be displayed. | |
273 * | |
274 * @param parent the parent shell | |
275 * @param isResizeable <code>true</code> if the control should be resizable | |
276 * @since 3.4 | |
277 */ | |
278 public this(Shell parent, bool isResizeable) { | |
279 fPresentation= new TextPresentation(); | |
280 super(parent, isResizeable); | |
281 fAdditionalTextStyles= isResizeable ? SWT.V_SCROLL | SWT.H_SCROLL : SWT.NONE; | |
282 fPresenter= new HTMLTextPresenter(!isResizeable); | |
283 create(); | |
284 } | |
285 | |
286 /** | |
287 * Creates a default information control with the given shell as parent. An information | |
288 * presenter that can handle simple HTML is used to process the information to be displayed. | |
289 * | |
290 * @param parent the parent shell | |
291 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field | |
292 * @since 3.4 | |
293 */ | |
294 public this(Shell parent, String statusFieldText) { | |
295 this(parent, statusFieldText, new HTMLTextPresenter(true)); | |
296 } | |
297 | |
298 /** | |
299 * Creates a default information control with the given shell as parent. The | |
300 * given information presenter is used to process the information to be | |
301 * displayed. | |
302 * | |
303 * @param parent the parent shell | |
304 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field | |
305 * @param presenter the presenter to be used, or <code>null</code> if no presenter should be used | |
306 * @since 3.4 | |
307 */ | |
308 public this(Shell parent, String statusFieldText, IInformationPresenter presenter) { | |
309 fPresentation= new TextPresentation(); | |
310 super(parent, statusFieldText); | |
311 fAdditionalTextStyles= SWT.NONE; | |
312 fPresenter= presenter; | |
313 create(); | |
314 } | |
315 | |
316 /** | |
317 * Creates a resizable default information control with the given shell as parent. An | |
318 * information presenter that can handle simple HTML is used to process the information to be | |
319 * displayed. | |
320 * | |
321 * @param parent the parent shell | |
322 * @param toolBarManager the manager or <code>null</code> if toolbar is not desired | |
323 * @since 3.4 | |
324 */ | |
325 public this(Shell parent, ToolBarManager toolBarManager) { | |
326 this(parent, toolBarManager, new HTMLTextPresenter(false)); | |
327 } | |
328 | |
329 /** | |
330 * Creates a resizable default information control with the given shell as | |
331 * parent. The given information presenter is used to process the | |
332 * information to be displayed. | |
333 * | |
334 * @param parent the parent shell | |
335 * @param toolBarManager the manager or <code>null</code> if toolbar is not desired | |
336 * @param presenter the presenter to be used, or <code>null</code> if no presenter should be used | |
337 * @since 3.4 | |
338 */ | |
339 public this(Shell parent, ToolBarManager toolBarManager, IInformationPresenter presenter) { | |
340 fPresentation= new TextPresentation(); | |
341 super(parent, toolBarManager); | |
342 fAdditionalTextStyles= SWT.V_SCROLL | SWT.H_SCROLL; | |
343 fPresenter= presenter; | |
344 create(); | |
345 } | |
346 | |
347 /** | |
348 * Creates a default information control with the given shell as parent. | |
349 * No information presenter is used to process the information | |
350 * to be displayed. | |
351 * | |
352 * @param parent the parent shell | |
353 */ | |
354 public this(Shell parent) { | |
355 this(parent, cast(String)null, null); | |
356 } | |
357 | |
358 /** | |
359 * Creates a default information control with the given shell as parent. The given | |
360 * information presenter is used to process the information to be displayed. | |
361 * | |
362 * @param parent the parent shell | |
363 * @param presenter the presenter to be used | |
364 */ | |
365 public this(Shell parent, IInformationPresenter presenter) { | |
366 this(parent, cast(String)null, presenter); | |
367 } | |
368 | |
369 /** | |
370 * Creates a default information control with the given shell as parent. The | |
371 * given information presenter is used to process the information to be | |
372 * displayed. The given styles are applied to the created styled text | |
373 * widget. | |
374 * | |
375 * @param parent the parent shell | |
376 * @param shellStyle the additional styles for the shell | |
377 * @param style the additional styles for the styled text widget | |
378 * @param presenter the presenter to be used | |
379 * @deprecated As of 3.4, replaced by simpler constructors | |
380 */ | |
381 public this(Shell parent, int shellStyle, int style, IInformationPresenter presenter) { | |
382 this(parent, shellStyle, style, presenter, null); | |
383 } | |
384 | |
385 /** | |
386 * Creates a default information control with the given shell as parent. The | |
387 * given information presenter is used to process the information to be | |
388 * displayed. The given styles are applied to the created styled text | |
389 * widget. | |
390 * | |
391 * @param parentShell the parent shell | |
392 * @param shellStyle the additional styles for the shell | |
393 * @param style the additional styles for the styled text widget | |
394 * @param presenter the presenter to be used | |
395 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field | |
396 * @since 3.0 | |
397 * @deprecated As of 3.4, replaced by simpler constructors | |
398 */ | |
399 public this(Shell parentShell, int shellStyle, int style, IInformationPresenter presenter, String statusFieldText) { | |
400 fPresentation= new TextPresentation(); | |
401 super(parentShell, SWT.NO_FOCUS | SWT.ON_TOP | shellStyle, statusFieldText, null); | |
402 fAdditionalTextStyles= style; | |
403 fPresenter= presenter; | |
404 create(); | |
405 } | |
406 | |
407 /** | |
408 * Creates a default information control with the given shell as parent. The | |
409 * given information presenter is used to process the information to be | |
410 * displayed. | |
411 * | |
412 * @param parent the parent shell | |
413 * @param textStyles the additional styles for the styled text widget | |
414 * @param presenter the presenter to be used | |
415 * @deprecated As of 3.4, replaced by {@link #DefaultInformationControl(Shell, DefaultInformationControl.IInformationPresenter)} | |
416 */ | |
417 public this(Shell parent, int textStyles, IInformationPresenter presenter) { | |
418 this(parent, textStyles, presenter, null); | |
419 } | |
420 | |
421 /** | |
422 * Creates a default information control with the given shell as parent. The | |
423 * given information presenter is used to process the information to be | |
424 * displayed. | |
425 * | |
426 * @param parent the parent shell | |
427 * @param textStyles the additional styles for the styled text widget | |
428 * @param presenter the presenter to be used | |
429 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field | |
430 * @since 3.0 | |
431 * @deprecated As of 3.4, replaced by {@link #DefaultInformationControl(Shell, String, DefaultInformationControl.IInformationPresenter)} | |
432 */ | |
433 public this(Shell parent, int textStyles, IInformationPresenter presenter, String statusFieldText) { | |
434 fPresentation= new TextPresentation(); | |
435 super(parent, statusFieldText); | |
436 fAdditionalTextStyles= textStyles; | |
437 fPresenter= presenter; | |
438 create(); | |
439 } | |
440 | |
441 /* | |
442 * @see org.eclipse.jface.text.AbstractInformationControl#createContent(org.eclipse.swt.widgets.Composite) | |
443 */ | |
444 protected void createContent(Composite parent) { | |
445 fText= new StyledText(parent, SWT.MULTI | SWT.READ_ONLY | fAdditionalTextStyles); | |
446 fText.setForeground(parent.getForeground()); | |
447 fText.setBackground(parent.getBackground()); | |
448 fText.setFont(JFaceResources.getDialogFont()); | |
449 FillLayout layout= cast(FillLayout)parent.getLayout(); | |
450 if (fText.getWordWrap()) { | |
451 // indent does not work for wrapping StyledText, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56342 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=115432 | |
452 layout.marginHeight= INNER_BORDER; | |
453 layout.marginWidth= INNER_BORDER; | |
454 } else { | |
455 fText.setIndent(INNER_BORDER); | |
456 } | |
457 } | |
458 | |
459 /* | |
460 * @see IInformationControl#setInformation(String) | |
461 */ | |
462 public void setInformation(String content) { | |
463 if (fPresenter is null) { | |
464 fText.setText(content); | |
465 } else { | |
466 fPresentation.clear(); | |
467 | |
468 int maxWidth= -1; | |
469 int maxHeight= -1; | |
470 Point constraints= getSizeConstraints(); | |
471 if (constraints !is null) { | |
472 maxWidth= constraints.x; | |
473 maxHeight= constraints.y; | |
474 if (fText.getWordWrap()) { | |
475 maxWidth-= INNER_BORDER * 2; | |
476 maxHeight-= INNER_BORDER * 2; | |
477 } else { | |
478 maxWidth-= INNER_BORDER; // indent | |
479 } | |
480 Rectangle trim= computeTrim(); | |
481 maxWidth-= trim.width; | |
482 maxHeight-= trim.height; | |
483 maxWidth-= fText.getCaret().getSize().x; // StyledText adds a border at the end of the line for the caret. | |
484 } | |
485 if (isResizable()) | |
486 maxHeight= Integer.MAX_VALUE; | |
487 | |
488 if ( cast(IInformationPresenterExtension)fPresenter ) | |
489 content= (cast(IInformationPresenterExtension)fPresenter).updatePresentation(fText, content, fPresentation, maxWidth, maxHeight); | |
490 else | |
491 content= fPresenter.updatePresentation(getShell().getDisplay(), content, fPresentation, maxWidth, maxHeight); | |
492 | |
493 if (content !is null) { | |
494 fText.setText(content); | |
495 TextPresentation.applyTextPresentation(fPresentation, fText); | |
496 } else { | |
497 fText.setText(""); //$NON-NLS-1$ | |
498 } | |
499 } | |
500 } | |
501 | |
502 /* | |
503 * @see IInformationControl#setVisible(bool) | |
504 */ | |
505 public void setVisible(bool visible) { | |
506 if (visible) { | |
507 if (fText.getWordWrap()) { | |
508 Point currentSize= getShell().getSize(); | |
509 getShell().pack(true); | |
510 Point newSize= getShell().getSize(); | |
511 if (newSize.x > currentSize.x || newSize.y > currentSize.y) | |
512 setSize(currentSize.x, currentSize.y); // restore previous size | |
513 } | |
514 } | |
515 | |
516 super.setVisible(visible); | |
517 } | |
518 | |
519 /* | |
520 * @see IInformationControl#computeSizeHint() | |
521 */ | |
522 public Point computeSizeHint() { | |
523 // see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=117602 | |
524 int widthHint= SWT.DEFAULT; | |
525 Point constraints= getSizeConstraints(); | |
526 if (constraints !is null && fText.getWordWrap()) | |
527 widthHint= constraints.x; | |
528 | |
529 return getShell().computeSize(widthHint, SWT.DEFAULT, true); | |
530 } | |
531 | |
532 /* | |
533 * @see org.eclipse.jface.text.AbstractInformationControl#computeTrim() | |
534 */ | |
535 public Rectangle computeTrim() { | |
536 return Geometry.add(super.computeTrim(), fText.computeTrim(0, 0, 0, 0)); | |
537 } | |
538 | |
539 /* | |
540 * @see IInformationControl#setForegroundColor(Color) | |
541 */ | |
542 public void setForegroundColor(Color foreground) { | |
543 super.setForegroundColor(foreground); | |
544 fText.setForeground(foreground); | |
545 } | |
546 | |
547 /* | |
548 * @see IInformationControl#setBackgroundColor(Color) | |
549 */ | |
550 public void setBackgroundColor(Color background) { | |
551 super.setBackgroundColor(background); | |
552 fText.setBackground(background); | |
553 } | |
554 | |
555 /* | |
556 * @see IInformationControlExtension#hasContents() | |
557 */ | |
558 public bool hasContents() { | |
559 return fText.getCharCount() > 0; | |
560 } | |
561 | |
562 /** | |
563 * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) | |
564 * @since 3.0 | |
565 * @deprecated As of 3.2, no longer used and called | |
566 */ | |
567 public void widgetDisposed(DisposeEvent event) { | |
568 } | |
569 | |
570 /* | |
571 * @see org.eclipse.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator() | |
572 * @since 3.4 | |
573 */ | |
574 public IInformationControlCreator getInformationPresenterControlCreator() { | |
575 return new class() IInformationControlCreator { | |
576 /* | |
577 * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell) | |
578 */ | |
579 public IInformationControl createInformationControl(Shell parent) { | |
580 return new DefaultInformationControl(parent, cast(ToolBarManager) null, fPresenter); | |
581 } | |
582 }; | |
583 } | |
584 | |
585 } |