Mercurial > projects > dwt-addons
annotate dwtx/ui/forms/HyperlinkGroup.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.HyperlinkGroup; | |
14 | |
15 import dwtx.ui.forms.HyperlinkSettings; | |
16 | |
17 import dwt.DWT; | |
18 import dwt.graphics.Color; | |
19 import dwt.widgets.Display; | |
20 import dwt.widgets.Event; | |
21 import dwt.widgets.Listener; | |
22 import dwtx.ui.forms.events.HyperlinkEvent; | |
23 import dwtx.ui.forms.events.IHyperlinkListener; | |
24 import dwtx.ui.forms.widgets.Hyperlink; | |
25 | |
26 import dwt.dwthelper.utils; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
27 import dwtx.dwtxhelper.Collection; |
75 | 28 |
29 /** | |
30 * Manages a group of hyperlinks. It tracks activation, updates normal and | |
31 * active colors and updates underline state depending on the underline | |
32 * preference. Hyperlink labels are added to the group after creation and are | |
33 * automatically removed from the group when they are disposed. | |
34 * | |
35 * @since 3.0 | |
36 */ | |
37 | |
38 public final class HyperlinkGroup : HyperlinkSettings { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
39 private ArrayList links; |
75 | 40 private Hyperlink lastActivated; |
41 private Hyperlink lastEntered; | |
42 private GroupListener listener; | |
43 private bool isActiveBackgroundSet; | |
44 private bool isActiveForegroundSet; | |
45 private bool isBackgroundSet; | |
46 private bool isForegroundSet; | |
47 | |
48 private class GroupListener : Listener, IHyperlinkListener { | |
49 | |
50 private Color previousBackground; | |
51 private Color previousForeground; | |
52 | |
53 public void handleEvent(Event e) { | |
54 switch (e.type) { | |
55 case DWT.MouseEnter : | |
56 onMouseEnter(e); | |
57 break; | |
58 case DWT.MouseExit : | |
59 onMouseExit(e); | |
60 break; | |
61 case DWT.MouseDown : | |
62 onMouseDown(e); | |
63 break; | |
64 case DWT.Dispose : | |
65 unhook(cast(Hyperlink) e.widget); | |
66 break; | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
104
diff
changeset
|
67 default: |
75 | 68 } |
69 } | |
70 private void onMouseEnter(Event e) { | |
71 Hyperlink link = cast(Hyperlink) e.widget; | |
72 previousBackground = link.getBackground(); | |
73 previousForeground = link.getForeground(); | |
74 if (isActiveBackgroundSet) | |
75 link.setBackground(getActiveBackground()); | |
76 if (isActiveForegroundSet) | |
77 link.setForeground(getActiveForeground()); | |
78 if (getHyperlinkUnderlineMode() is UNDERLINE_HOVER) | |
79 link.setUnderlined(true); | |
80 link.setCursor(getHyperlinkCursor()); | |
81 } | |
82 private void onMouseExit(Event e) { | |
83 Hyperlink link = cast(Hyperlink) e.widget; | |
84 if (isActiveBackgroundSet) | |
85 link.setBackground(previousBackground); | |
86 if (isActiveForegroundSet) | |
87 link.setForeground(previousForeground); | |
88 if (getHyperlinkUnderlineMode() is UNDERLINE_HOVER) | |
89 link.setUnderlined(false); | |
90 } | |
91 public void linkActivated(HyperlinkEvent e) { | |
92 } | |
93 | |
94 public void linkEntered(HyperlinkEvent e) { | |
95 Hyperlink link = cast(Hyperlink) e.widget; | |
96 if (lastEntered !is null) { | |
97 linkExited(lastEntered); | |
98 } | |
99 lastEntered = link; | |
100 } | |
101 | |
102 public void linkExited(HyperlinkEvent e) { | |
103 linkExited(cast(Hyperlink) e.widget); | |
104 } | |
105 private void linkExited(Hyperlink link) { | |
106 link.setCursor(null); | |
107 if (lastEntered is link) | |
108 lastEntered = null; | |
109 } | |
110 } | |
111 | |
112 /** | |
113 * Creates a hyperlink group. | |
114 */ | |
115 | |
116 public this(Display display) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
117 links = new ArrayList(); |
75 | 118 super(display); |
119 listener = new GroupListener(); | |
120 } | |
121 | |
122 /** | |
123 * Returns the link that has been active the last, or <code>null</code> | |
124 * if no link has been active yet or the last active link has been | |
125 * disposed. | |
126 * | |
127 * @return the last active link or <code>null</code> | |
128 */ | |
129 public Hyperlink getLastActivated() { | |
130 return lastActivated; | |
131 } | |
132 /** | |
133 * Adds a hyperlink to the group to be jointly managed. Hyperlink will be | |
134 * managed until it is disposed. Settings like colors, cursors and modes | |
135 * will affect all managed hyperlinks. | |
136 * | |
137 * @param link | |
138 */ | |
139 | |
140 public void add(Hyperlink link) { | |
141 if (isBackgroundSet) | |
142 link.setBackground(getBackground()); | |
143 if (isForegroundSet) | |
144 link.setForeground(getForeground()); | |
145 if (getHyperlinkUnderlineMode() is UNDERLINE_ALWAYS) | |
146 link.setUnderlined(true); | |
147 hook(link); | |
148 } | |
149 | |
150 /** | |
151 * Sets the new active hyperlink background for all the links. | |
152 * | |
153 * @param newActiveBackground | |
154 * the new active background | |
155 */ | |
156 public void setActiveBackground(Color newActiveBackground) { | |
157 super.setActiveBackground(newActiveBackground); | |
158 isActiveBackgroundSet = true; | |
159 } | |
160 | |
161 /** | |
162 * Sets the new active hyperlink foreground for all the links. | |
163 * | |
164 * @param newActiveForeground | |
165 * the new active foreground | |
166 */ | |
167 public void setActiveForeground(Color newActiveForeground) { | |
168 super.setActiveForeground(newActiveForeground); | |
169 isActiveForegroundSet = true; | |
170 } | |
171 | |
172 /** | |
173 * Sets the group background and also sets the background of all the | |
174 * currently managed links. | |
175 * | |
176 * @param bg | |
177 * the new background | |
178 */ | |
179 public void setBackground(Color bg) { | |
180 super.setBackground(bg); | |
181 isBackgroundSet = true; | |
182 if (links !is null) { | |
183 for (int i = 0; i < links.size(); i++) { | |
184 Hyperlink label = cast(Hyperlink) links.get(i); | |
185 label.setBackground(bg); | |
186 } | |
187 } | |
188 } | |
189 /** | |
190 * Sets the group foreground and also sets the background of all the | |
191 * currently managed links. | |
192 * | |
193 * @param fg | |
194 * the new foreground | |
195 */ | |
196 public void setForeground(Color fg) { | |
197 super.setForeground(fg); | |
198 isForegroundSet = true; | |
199 if (links !is null) { | |
200 for (int i = 0; i < links.size(); i++) { | |
201 Hyperlink label = cast(Hyperlink) links.get(i); | |
202 label.setForeground(fg); | |
203 } | |
204 } | |
205 } | |
206 /** | |
207 * Sets the hyperlink underline mode. | |
208 * | |
209 * @param mode | |
210 * the new hyperlink underline mode | |
211 * @see HyperlinkSettings | |
212 */ | |
213 public void setHyperlinkUnderlineMode(int mode) { | |
214 super.setHyperlinkUnderlineMode(mode); | |
215 if (links !is null) { | |
216 for (int i = 0; i < links.size(); i++) { | |
217 Hyperlink label = cast(Hyperlink) links.get(i); | |
218 label.setUnderlined(mode is UNDERLINE_ALWAYS); | |
219 } | |
220 } | |
221 } | |
222 | |
223 private void hook(Hyperlink link) { | |
224 link.addListener(DWT.MouseDown, listener); | |
225 link.addHyperlinkListener(listener); | |
226 link.addListener(DWT.Dispose, listener); | |
227 link.addListener(DWT.MouseEnter, listener); | |
228 link.addListener(DWT.MouseExit, listener); | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
229 links.add(link); |
75 | 230 } |
231 | |
232 private void unhook(Hyperlink link) { | |
233 link.removeListener(DWT.MouseDown, listener); | |
234 link.removeHyperlinkListener(listener); | |
235 link.removeListener(DWT.MouseEnter, listener); | |
236 link.removeListener(DWT.MouseExit, listener); | |
237 if (lastActivated is link) | |
238 lastActivated = null; | |
239 if (lastEntered is link) | |
240 lastEntered = null; | |
241 links.remove(link); | |
242 } | |
243 | |
244 private void onMouseDown(Event e) { | |
245 if (e.button is 1) | |
246 return; | |
247 lastActivated = cast(Hyperlink) e.widget; | |
248 } | |
249 } |