Mercurial > projects > dwt-addons
annotate dwtx/jface/internal/text/InformationControlReplacer.d @ 156:a9566845f1cb
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 25 Aug 2008 19:03:46 +0200 |
parents | 5cf141e43417 |
children | 1a5b8f8129df |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 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 | |
150 | 7 * |
129 | 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 dwtx.jface.internal.text.InformationControlReplacer; | |
14 | |
131 | 15 import dwtx.jface.internal.text.NonDeletingPositionUpdater; // packageimport |
16 import dwtx.jface.internal.text.InternalAccessor; // packageimport | |
17 import dwtx.jface.internal.text.StickyHoverManager; // packageimport | |
18 import dwtx.jface.internal.text.TableOwnerDrawSupport; // packageimport | |
19 import dwtx.jface.internal.text.DelayedInputChangeListener; // packageimport | |
20 | |
21 | |
129 | 22 import dwt.dwthelper.utils; |
23 | |
24 | |
25 | |
26 import dwt.graphics.Point; | |
27 import dwt.graphics.Rectangle; | |
28 import dwt.widgets.Shell; | |
29 import dwtx.jface.text.AbstractInformationControlManager; | |
30 import dwtx.jface.text.AbstractReusableInformationControlCreator; | |
31 import dwtx.jface.text.DefaultInformationControl; | |
32 import dwtx.jface.text.IInformationControl; | |
33 import dwtx.jface.text.IInformationControlCreator; | |
34 import dwtx.jface.text.IInformationControlExtension2; | |
35 import dwtx.jface.text.IInformationControlExtension3; | |
36 import dwtx.jface.util.Geometry; | |
37 | |
38 | |
39 /** | |
40 * An information control replacer can replace an | |
41 * {@link AbstractInformationControlManager}'s control. | |
42 * | |
43 * @see AbstractInformationControlManager#setInformationControlReplacer(InformationControlReplacer) | |
44 * @since 3.4 | |
45 */ | |
46 public class InformationControlReplacer : AbstractInformationControlManager { | |
150 | 47 |
129 | 48 /** |
49 * Minimal width in pixels. | |
50 */ | |
147 | 51 private static const int MIN_WIDTH= 80; |
129 | 52 /** |
53 * Minimal height in pixels. | |
54 */ | |
147 | 55 private static const int MIN_HEIGHT= 50; |
150 | 56 |
129 | 57 /** |
58 * Default control creator. | |
59 */ | |
60 protected static class DefaultInformationControlCreator : AbstractReusableInformationControlCreator { | |
61 public IInformationControl doCreateInformationControl(Shell shell) { | |
62 return new DefaultInformationControl(shell, true); | |
63 } | |
64 } | |
65 | |
66 private bool fIsReplacing; | |
67 private Object fReplacableInformation; | |
68 private bool fDelayedInformationSet; | |
69 private Rectangle fReplaceableArea; | |
70 private Rectangle fContentBounds; | |
150 | 71 |
72 | |
129 | 73 /** |
74 * Creates a new information control replacer. | |
150 | 75 * |
129 | 76 * @param creator the default information control creator |
77 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
78 public this(IInformationControlCreator creator) { |
129 | 79 super(creator); |
80 takesFocusWhenVisible(false); | |
81 } | |
82 | |
83 /** | |
84 * Replace the information control. | |
150 | 85 * |
129 | 86 * @param informationPresenterControlCreator the information presenter control creator |
87 * @param contentBounds the bounds of the content area of the information control | |
88 * @param information the information to show | |
89 * @param subjectArea the subject area | |
90 * @param takeFocus <code>true</code> iff the replacing information control should take focus | |
91 */ | |
156 | 92 public void replaceInformationControl(IInformationControlCreator informationPresenterControlCreator, Rectangle contentBounds, Object information, Rectangle subjectArea, bool takeFocus) { |
150 | 93 |
129 | 94 try { |
95 fIsReplacing= true; | |
96 if (! fDelayedInformationSet) | |
97 fReplacableInformation= information; | |
98 else | |
99 takeFocus= true; // delayed input has been set, so the original info control must have been focused | |
100 fContentBounds= contentBounds; | |
101 fReplaceableArea= subjectArea; | |
150 | 102 |
129 | 103 setCustomInformationControlCreator(informationPresenterControlCreator); |
150 | 104 |
129 | 105 takesFocusWhenVisible(takeFocus); |
150 | 106 |
129 | 107 showInformation(); |
108 } finally { | |
109 fIsReplacing= false; | |
110 fReplacableInformation= null; | |
111 fDelayedInformationSet= false; | |
112 fReplaceableArea= null; | |
113 setCustomInformationControlCreator(null); | |
114 } | |
115 } | |
150 | 116 |
129 | 117 /* |
118 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation() | |
119 */ | |
120 protected void computeInformation() { | |
121 if (fIsReplacing && fReplacableInformation !is null) { | |
122 setInformation(fReplacableInformation, fReplaceableArea); | |
123 return; | |
124 } | |
150 | 125 |
126 if (DEBUG) | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
127 System.out_.println("InformationControlReplacer: no active replaceable"); //$NON-NLS-1$ |
129 | 128 } |
129 | |
130 /** | |
131 * Opens the information control with the given information and the specified | |
132 * subject area. It also activates the information control closer. | |
133 * | |
134 * @param subjectArea the information area | |
135 * @param information the information | |
136 */ | |
137 public void showInformationControl(Rectangle subjectArea, Object information) { | |
138 IInformationControl informationControl= getInformationControl(); | |
150 | 139 |
129 | 140 Rectangle controlBounds= fContentBounds; |
138 | 141 if ( cast(IInformationControlExtension3)informationControl ) { |
134 | 142 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) informationControl; |
129 | 143 Rectangle trim= iControl3.computeTrim(); |
144 controlBounds= Geometry.add(controlBounds, trim); | |
150 | 145 |
129 | 146 /* |
147 * Ensure minimal size. Interacting with a tiny information control | |
148 * (resizing, selecting text) would be a pain. | |
149 */ | |
150 controlBounds.width= Math.max(controlBounds.width, MIN_WIDTH); | |
151 controlBounds.height= Math.max(controlBounds.height, MIN_HEIGHT); | |
150 | 152 |
129 | 153 getInternalAccessor().cropToClosestMonitor(controlBounds); |
154 } | |
150 | 155 |
129 | 156 Point location= Geometry.getLocation(controlBounds); |
157 Point size= Geometry.getSize(controlBounds); | |
150 | 158 |
129 | 159 // Caveat: some IInformationControls fail unless setSizeConstraints(..) is called with concrete values |
160 informationControl.setSizeConstraints(size.x, size.y); | |
150 | 161 |
138 | 162 if ( cast(IInformationControlExtension2)informationControl ) |
134 | 163 (cast(IInformationControlExtension2) informationControl).setInput(information); |
129 | 164 else |
165 informationControl.setInformation(information.toString()); | |
150 | 166 |
129 | 167 informationControl.setLocation(location); |
168 informationControl.setSize(size.x, size.y); | |
150 | 169 |
129 | 170 showInformationControl(subjectArea); |
171 } | |
150 | 172 |
129 | 173 /* |
174 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl() | |
175 */ | |
176 public void hideInformationControl() { | |
177 super.hideInformationControl(); | |
178 } | |
179 | |
180 /** | |
181 * @param input the delayed input, or <code>null</code> to request cancellation | |
182 */ | |
183 public void setDelayedInput(Object input) { | |
184 fReplacableInformation= input; | |
185 if (! isReplacing()) { | |
186 fDelayedInformationSet= true; | |
150 | 187 } else if (cast(IInformationControlExtension2)getCurrentInformationControl2() ) { |
134 | 188 (cast(IInformationControlExtension2) getCurrentInformationControl2()).setInput(input); |
129 | 189 } else if (getCurrentInformationControl2() !is null) { |
190 getCurrentInformationControl2().setInformation(input.toString()); | |
191 } | |
192 } | |
193 | |
194 /** | |
195 * Tells whether the replacer is currently replacing another information control. | |
150 | 196 * |
129 | 197 * @return <code>true</code> while code from {@link #replaceInformationControl(IInformationControlCreator, Rectangle, Object, Rectangle, bool)} is run |
198 */ | |
199 public bool isReplacing() { | |
200 return fIsReplacing; | |
201 } | |
150 | 202 |
129 | 203 /** |
204 * @return the current information control, or <code>null</code> if none available | |
205 */ | |
206 public IInformationControl getCurrentInformationControl2() { | |
207 return getInternalAccessor().getCurrentInformationControl(); | |
208 } | |
150 | 209 |
129 | 210 /** |
211 * The number of pixels to blow up the keep-up zone. | |
150 | 212 * |
129 | 213 * @return the margin in pixels |
214 */ | |
215 public int getKeepUpMargin() { | |
216 return 15; | |
217 } | |
218 } |