Mercurial > projects > dwt-addons
annotate dwtx/ui/forms/widgets/ToggleHyperlink.d @ 200:eb3414669eb0 default tip
fix for dmd 1.041 and tango 0.99.8
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 28 Mar 2009 03:09:57 +0100 |
parents | c3583c6ec027 |
children |
rev | line source |
---|---|
75 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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 dwtx.ui.forms.widgets.ToggleHyperlink; | |
14 | |
15 import dwtx.ui.forms.widgets.AbstractHyperlink; | |
76 | 16 import dwtx.ui.forms.widgets.ExpandableComposite; |
75 | 17 |
18 import dwt.DWT; | |
19 import dwt.accessibility.ACC; | |
20 import dwt.accessibility.AccessibleAdapter; | |
21 import dwt.accessibility.AccessibleControlAdapter; | |
22 import dwt.accessibility.AccessibleControlEvent; | |
23 import dwt.accessibility.AccessibleEvent; | |
24 import dwt.graphics.Color; | |
25 import dwt.graphics.Point; | |
26 import dwt.graphics.Rectangle; | |
27 import dwt.widgets.Composite; | |
28 import dwt.widgets.Event; | |
29 import dwt.widgets.Listener; | |
30 import dwtx.ui.forms.events.HyperlinkAdapter; | |
31 import dwtx.ui.forms.events.HyperlinkEvent; | |
32 import dwtx.ui.internal.forms.Messages; | |
33 | |
34 import dwt.dwthelper.utils; | |
35 | |
36 /** | |
37 * A custom selectable control that can be used to control areas that can be | |
38 * expanded or collapsed. | |
39 * <p> | |
40 * This is an abstract class. Subclasses are responsible for rendering the | |
41 * control using decoration and hover decoration color. Control should be | |
42 * rendered based on the current expansion state. | |
43 * | |
44 * @since 3.0 | |
45 */ | |
46 public abstract class ToggleHyperlink : AbstractHyperlink { | |
77
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
76
diff
changeset
|
47 |
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
76
diff
changeset
|
48 alias AbstractHyperlink.computeSize computeSize; |
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
76
diff
changeset
|
49 |
75 | 50 protected int innerWidth; |
51 protected int innerHeight; | |
52 protected bool hover; | |
53 package bool hover_package(){ | |
54 return hover; | |
55 } | |
56 package bool hover_package( bool v){ | |
57 return (hover = v); | |
58 } | |
59 private bool expanded; | |
60 private Color decorationColor; | |
61 private Color hoverColor; | |
62 /** | |
63 * Creates a control in a provided composite. | |
64 * | |
65 * @param parent | |
66 * the parent | |
67 * @param style | |
68 * the style | |
69 */ | |
70 public this(Composite parent, int style) { | |
71 super(parent, style); | |
72 Listener listener = new class Listener { | |
73 public void handleEvent(Event e) { | |
74 switch (e.type) { | |
75 case DWT.MouseEnter: | |
76 hover=true; | |
77 redraw(); | |
78 break; | |
79 case DWT.MouseExit: | |
80 hover = false; | |
81 redraw(); | |
82 break; | |
83 case DWT.KeyDown: | |
84 onKeyDown(e); | |
85 break; | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
86 default: |
75 | 87 } |
88 } | |
89 }; | |
90 addListener(DWT.MouseEnter, listener); | |
91 addListener(DWT.MouseExit, listener); | |
92 addListener(DWT.KeyDown, listener); | |
93 addHyperlinkListener(new class HyperlinkAdapter { | |
94 public void linkActivated(HyperlinkEvent e) { | |
95 setExpanded(!isExpanded()); | |
96 } | |
97 }); | |
98 initAccessible(); | |
99 } | |
100 /** | |
101 * Sets the color of the decoration. | |
102 * | |
103 * @param decorationColor | |
104 */ | |
105 public void setDecorationColor(Color decorationColor) { | |
106 this.decorationColor = decorationColor; | |
107 } | |
108 /** | |
109 * Returns the color of the decoration. | |
110 * | |
111 * @return decoration color | |
112 */ | |
113 public Color getDecorationColor() { | |
114 return decorationColor; | |
115 } | |
116 /** | |
117 * Sets the hover color of decoration. Hover color will be used when mouse | |
118 * enters the decoration area. | |
119 * | |
120 * @param hoverColor | |
121 * the hover color to use | |
122 */ | |
123 public void setHoverDecorationColor(Color hoverColor) { | |
124 this.hoverColor = hoverColor; | |
125 } | |
126 /** | |
127 * Returns the hover color of the decoration. | |
128 * | |
129 * @return the hover color of the decoration. | |
130 * @since 3.1 | |
131 */ | |
132 public Color getHoverDecorationColor() { | |
133 return hoverColor; | |
134 } | |
135 | |
136 /** | |
137 * Returns the hover color of the decoration. | |
138 * | |
139 * @return the hover color of the decoration. | |
140 * @deprecated use <code>getHoverDecorationColor</code> | |
141 * @see #getHoverDecorationColor() | |
142 */ | |
143 public Color geHoverDecorationColor() { | |
144 return hoverColor; | |
145 } | |
146 /** | |
147 * Computes the size of the control. | |
148 * | |
149 * @param wHint | |
150 * width hint | |
151 * @param hHint | |
152 * height hint | |
153 * @param changed | |
154 * if true, flush any saved layout state | |
155 */ | |
156 public Point computeSize(int wHint, int hHint, bool changed) { | |
157 int width, height; | |
158 /* | |
159 if (wHint !is DWT.DEFAULT) | |
160 width = wHint; | |
161 else */ | |
162 width = innerWidth + 2 * marginWidth; | |
163 /* | |
164 if (hHint !is DWT.DEFAULT) | |
165 height = hHint; | |
166 else */ | |
167 height = innerHeight + 2 * marginHeight; | |
168 return new Point(width, height); | |
169 } | |
170 /** | |
171 * Returns the expansion state of the toggle control. When toggle is in the | |
172 * normal (downward) state, the value is <samp>true </samp>. Collapsed | |
173 * control will return <samp>false </samp>. | |
174 * | |
175 * @return <samp>false </samp> if collapsed, <samp>true </samp> otherwise. | |
176 */ | |
177 public bool isExpanded() { | |
178 return expanded; | |
179 } | |
180 /** | |
181 * Sets the expansion state of the twistie control | |
182 * | |
183 * @param expanded the expansion state | |
184 */ | |
185 public void setExpanded(bool expanded) { | |
186 this.expanded = expanded; | |
187 getAccessible().selectionChanged(); | |
188 redraw(); | |
189 } | |
190 private void initAccessible() { | |
191 getAccessible().addAccessibleListener(new class AccessibleAdapter { | |
192 public void getHelp(AccessibleEvent e) { | |
193 e.result = getToolTipText(); | |
194 } | |
195 public void getName(AccessibleEvent e) { | |
196 String name=Messages.ToggleHyperlink_accessibleName; | |
197 if (null !is cast(ExpandableComposite)getParent() ) { | |
198 name ~= Messages.ToggleHyperlink_accessibleColumn ~ (cast(ExpandableComposite)getParent()).getText(); | |
199 int index = name.indexOf('&'); | |
200 if (index !is -1) { | |
76 | 201 name = name.substring(0, index) ~ name.substring(index + 1); |
75 | 202 } |
203 } | |
204 e.result = name; | |
205 } | |
206 public void getDescription(AccessibleEvent e) { | |
207 getName(e); | |
208 } | |
209 }); | |
210 getAccessible().addAccessibleControlListener( | |
211 new class AccessibleControlAdapter { | |
212 public void getChildAtPoint(AccessibleControlEvent e) { | |
213 Point testPoint = toControl(new Point(e.x, e.y)); | |
214 if (getBounds().contains(testPoint)) { | |
215 e.childID = ACC.CHILDID_SELF; | |
216 } | |
217 } | |
218 public void getLocation(AccessibleControlEvent e) { | |
219 Rectangle location = getBounds(); | |
220 Point pt = toDisplay(new Point(location.x, location.y)); | |
221 e.x = pt.x; | |
222 e.y = pt.y; | |
223 e.width = location.width; | |
224 e.height = location.height; | |
225 } | |
226 public void getSelection (AccessibleControlEvent e) { | |
227 if (this.outer.getSelection()) | |
228 e.childID = ACC.CHILDID_SELF; | |
229 } | |
230 | |
231 public void getFocus (AccessibleControlEvent e) { | |
232 if (this.outer.getSelection()) | |
233 e.childID = ACC.CHILDID_SELF; | |
234 } | |
235 public void getChildCount(AccessibleControlEvent e) { | |
236 e.detail = 0; | |
237 } | |
238 public void getRole(AccessibleControlEvent e) { | |
239 e.detail = ACC.ROLE_TREE; | |
240 } | |
241 public void getState(AccessibleControlEvent e) { | |
242 int state = ACC.STATE_FOCUSABLE; | |
243 if (this.outer.getSelection()) | |
244 state |= ACC.STATE_FOCUSED; | |
245 state |= this.outer.isExpanded() | |
246 ? ACC.STATE_EXPANDED | |
247 : ACC.STATE_COLLAPSED; | |
248 e.detail = state; | |
249 } | |
250 }); | |
251 } | |
252 private void onKeyDown(Event e) { | |
76 | 253 if (e.keyCode is DWT.ARROW_RIGHT) { |
75 | 254 // expand if collapsed |
255 if (!isExpanded()) { | |
256 handleActivate(e); | |
257 } | |
258 e.doit=false; | |
259 } | |
76 | 260 else if (e.keyCode is DWT.ARROW_LEFT) { |
75 | 261 // collapse if expanded |
262 if (isExpanded()) { | |
263 handleActivate(e); | |
264 } | |
265 e.doit=false; | |
266 } | |
267 } | |
268 } |