Mercurial > projects > dwt-mac
comparison dwt/custom/CTabFolder.d @ 41:6337764516f1
Sync dwt/custom with dwt-linux (took copy of complete folder)
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 07 Oct 2008 16:29:55 +0200 |
parents | f565d3a95c0a |
children | c41e13089a3c |
comparison
equal
deleted
inserted
replaced
40:fbe68c33eeee | 41:6337764516f1 |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | 10 * Port to the D programming language: |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 11 * Frank Benoit <benoit@tionex.de> |
13 *******************************************************************************/ | 12 *******************************************************************************/ |
14 module dwt.custom.CTabFolder; | 13 module dwt.custom.CTabFolder; |
15 | 14 |
16 import dwt.DWT; | 15 import dwt.DWT; |
17 import dwt.DWTException; | 16 import dwt.DWTException; |
19 import dwt.accessibility.Accessible; | 18 import dwt.accessibility.Accessible; |
20 import dwt.accessibility.AccessibleAdapter; | 19 import dwt.accessibility.AccessibleAdapter; |
21 import dwt.accessibility.AccessibleControlAdapter; | 20 import dwt.accessibility.AccessibleControlAdapter; |
22 import dwt.accessibility.AccessibleControlEvent; | 21 import dwt.accessibility.AccessibleControlEvent; |
23 import dwt.accessibility.AccessibleEvent; | 22 import dwt.accessibility.AccessibleEvent; |
24 import dwt.custom.CTabFolderListener; | |
25 import dwt.custom.CTabFolder2Listener; | |
26 import dwt.custom.CTabItem; | |
27 import dwt.events.SelectionAdapter; | 23 import dwt.events.SelectionAdapter; |
28 import dwt.events.SelectionEvent; | 24 import dwt.events.SelectionEvent; |
29 import dwt.events.SelectionListener; | 25 import dwt.events.SelectionListener; |
30 import dwt.graphics.Color; | 26 import dwt.graphics.Color; |
31 import dwt.graphics.Font; | 27 import dwt.graphics.Font; |
43 import dwt.widgets.Layout; | 39 import dwt.widgets.Layout; |
44 import dwt.widgets.Listener; | 40 import dwt.widgets.Listener; |
45 import dwt.widgets.Menu; | 41 import dwt.widgets.Menu; |
46 import dwt.widgets.MenuItem; | 42 import dwt.widgets.MenuItem; |
47 import dwt.widgets.TypedListener; | 43 import dwt.widgets.TypedListener; |
48 | 44 import dwt.custom.CTabItem; |
49 /** | 45 import dwt.custom.CTabFolder2Listener; |
50 * | 46 import dwt.custom.CTabFolderListener; |
47 import dwt.custom.CTabFolderLayout; | |
48 import dwt.custom.CTabFolderEvent; | |
49 | |
50 import dwt.dwthelper.utils; | |
51 import tango.util.Convert; | |
52 static import tango.text.convert.Utf; | |
53 | |
54 /** | |
55 * | |
51 * Instances of this class implement the notebook user interface | 56 * Instances of this class implement the notebook user interface |
52 * metaphor. It allows the user to select a notebook page from | 57 * metaphor. It allows the user to select a notebook page from |
53 * set of pages. | 58 * set of pages. |
54 * <p> | 59 * <p> |
55 * The item children that may be added to instances of this class | 60 * The item children that may be added to instances of this class |
66 * <dt><b>Events:</b></dt> | 71 * <dt><b>Events:</b></dt> |
67 * <dd>Selection</dd> | 72 * <dd>Selection</dd> |
68 * <dd>"CTabFolder2"</dd> | 73 * <dd>"CTabFolder2"</dd> |
69 * </dl> | 74 * </dl> |
70 * <p> | 75 * <p> |
71 * Note: Only one of the styles TOP and BOTTOM | 76 * Note: Only one of the styles TOP and BOTTOM |
72 * may be specified. | 77 * may be specified. |
73 * </p><p> | 78 * </p><p> |
74 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | 79 * IMPORTANT: This class is <em>not</em> intended to be subclassed. |
75 * </p> | 80 * </p> |
76 */ | 81 * |
77 | 82 * @see <a href="http://www.eclipse.org/swt/snippets/#ctabfolder">CTabFolder, CTabItem snippets</a> |
78 public class CTabFolder : Composite | 83 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: CustomControlExample</a> |
79 { | 84 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
85 */ | |
86 | |
87 public class CTabFolder : Composite { | |
80 | 88 |
81 /** | 89 /** |
82 * marginWidth specifies the number of pixels of horizontal margin | 90 * marginWidth specifies the number of pixels of horizontal margin |
83 * that will be placed along the left and right edges of the form. | 91 * that will be placed along the left and right edges of the form. |
84 * | 92 * |
92 * The default value is 0. | 100 * The default value is 0. |
93 */ | 101 */ |
94 public int marginHeight = 0; | 102 public int marginHeight = 0; |
95 | 103 |
96 /** | 104 /** |
97 * A multiple of the tab height that specifies the minimum width to which a tab | 105 * A multiple of the tab height that specifies the minimum width to which a tab |
98 * will be compressed before scrolling arrows are used to navigate the tabs. | 106 * will be compressed before scrolling arrows are used to navigate the tabs. |
99 * | 107 * |
100 * NOTE This field is badly named and can not be fixed for backwards compatibility. | 108 * NOTE This field is badly named and can not be fixed for backwards compatibility. |
101 * It should not be capitalized. | 109 * It should not be capitalized. |
102 * | 110 * |
103 * @deprecated This field is no longer used. See setMinimumCharacters(int) | 111 * @deprecated This field is no longer used. See setMinimumCharacters(int) |
104 */ | 112 */ |
105 public int MIN_TAB_WIDTH = 4; | 113 public int MIN_TAB_WIDTH = 4; |
106 | 114 |
107 /** | 115 /** |
108 * Color of innermost line of drop shadow border. | 116 * Color of innermost line of drop shadow border. |
109 * | 117 * |
110 * NOTE This field is badly named and can not be fixed for backwards compatibility. | 118 * NOTE This field is badly named and can not be fixed for backwards compatibility. |
111 * It should be capitalized. | 119 * It should be capitalized. |
112 * | 120 * |
113 * @deprecated drop shadow border is no longer drawn in 3.0 | 121 * @deprecated drop shadow border is no longer drawn in 3.0 |
114 */ | 122 */ |
115 public static RGB borderInsideRGB = new RGB(132, 130, 132); | 123 public static RGB borderInsideRGB; |
116 /** | 124 /** |
117 * Color of middle line of drop shadow border. | 125 * Color of middle line of drop shadow border. |
118 * | 126 * |
119 * NOTE This field is badly named and can not be fixed for backwards compatibility. | 127 * NOTE This field is badly named and can not be fixed for backwards compatibility. |
120 * It should be capitalized. | 128 * It should be capitalized. |
121 * | 129 * |
122 * @deprecated drop shadow border is no longer drawn in 3.0 | 130 * @deprecated drop shadow border is no longer drawn in 3.0 |
123 */ | 131 */ |
124 public static RGB borderMiddleRGB = new RGB(143, 141, 138); | 132 public static RGB borderMiddleRGB; |
125 /** | 133 /** |
126 * Color of outermost line of drop shadow border. | 134 * Color of outermost line of drop shadow border. |
127 * | 135 * |
128 * NOTE This field is badly named and can not be fixed for backwards compatibility. | 136 * NOTE This field is badly named and can not be fixed for backwards compatibility. |
129 * It should be capitalized. | 137 * It should be capitalized. |
130 * | 138 * |
131 * @deprecated drop shadow border is no longer drawn in 3.0 | 139 * @deprecated drop shadow border is no longer drawn in 3.0 |
132 */ | 140 */ |
133 public static RGB borderOutsideRGB = new RGB(171, 168, 165); | 141 public static RGB borderOutsideRGB; |
134 | 142 |
135 /* sizing, positioning */ | 143 /* sizing, positioning */ |
136 int xClient, yClient; | 144 int xClient, yClient; |
137 bool onBottom = false; | 145 bool onBottom = false; |
138 bool single = false; | 146 bool single = false; |
140 int fixedTabHeight = DWT.DEFAULT; | 148 int fixedTabHeight = DWT.DEFAULT; |
141 int tabHeight; | 149 int tabHeight; |
142 int minChars = 20; | 150 int minChars = 20; |
143 | 151 |
144 /* item management */ | 152 /* item management */ |
145 CTabItem items[] = new CTabItem[0]; | 153 CTabItem items[]; |
146 int firstIndex = -1; // index of the left most visible tab. | 154 int firstIndex = -1; // index of the left most visible tab. |
147 int selectedIndex = -1; | 155 int selectedIndex = -1; |
148 int[] priority = new int[0]; | 156 int[] priority; |
149 bool mru = false; | 157 bool mru = false; |
150 Listener listener; | 158 Listener listener; |
151 | 159 |
152 /* External Listener management */ | 160 /* External Listener management */ |
153 CTabFolder2Listener[] folderListeners = new CTabFolder2Listener[0]; | 161 CTabFolder2Listener[] folderListeners; |
154 // support for deprecated listener mechanism | 162 // support for deprecated listener mechanism |
155 CTabFolderListener[] tabListeners = new CTabFolderListener[0]; | 163 CTabFolderListener[] tabListeners; |
156 | 164 |
157 /* Selected item appearance */ | 165 /* Selected item appearance */ |
158 Image selectionBgImage; | 166 Image selectionBgImage; |
159 Color[] selectionGradientColors; | 167 Color[] selectionGradientColors; |
160 int[] selectionGradientPercents; | 168 int[] selectionGradientPercents; |
161 bool selectionGradientVertical; | 169 bool selectionGradientVertical; |
162 Color selectionForeground; | 170 Color selectionForeground; |
163 Color selectionBackground; //selection fade end | 171 Color selectionBackground; //selection fade end |
164 Color selectionFadeStart; | 172 Color selectionFadeStart; |
165 | 173 |
166 Color selectionHighlightGradientBegin = null; //null is no highlight | 174 Color selectionHighlightGradientBegin = null; //null is no highlight |
167 //Although we are given new colours all the time to show different states (active, etc), | 175 //Although we are given new colours all the time to show different states (active, etc), |
168 //some of which may have a highlight and some not, we'd like to retain the highlight colours | 176 //some of which may have a highlight and some not, we'd like to retain the highlight colours |
169 //as a cache so that we can reuse them if we're again told to show the highlight. | 177 //as a cache so that we can reuse them if we're again told to show the highlight. |
170 //We are relying on the fact that only one tab state usually gets a highlight, so only | 178 //We are relying on the fact that only one tab state usually gets a highlight, so only |
171 //a single cache is required. If that happens to not be true, cache simply becomes less effective, | 179 //a single cache is required. If that happens to not be true, cache simply becomes less effective, |
172 //but we don't leak colours. | 180 //but we don't leak colours. |
173 Color[] selectionHighlightGradientColorsCache = null; //null is a legal value, check on access | 181 Color[] selectionHighlightGradientColorsCache = null; //null is a legal value, check on access |
174 | 182 |
175 /* Unselected item appearance */ | 183 /* Unselected item appearance */ |
176 Image bgImage; | 184 Image bgImage; |
177 Color[] gradientColors; | 185 Color[] gradientColors; |
178 int[] gradientPercents; | 186 int[] gradientPercents; |
183 | 191 |
184 // close, min/max and chevron buttons | 192 // close, min/max and chevron buttons |
185 bool showClose = false; | 193 bool showClose = false; |
186 bool showUnselectedClose = true; | 194 bool showUnselectedClose = true; |
187 | 195 |
188 Rectangle chevronRect = new Rectangle(0, 0, 0, 0); | 196 Rectangle chevronRect; |
189 int chevronImageState = NORMAL; | 197 int chevronImageState = NORMAL; |
190 bool showChevron = false; | 198 bool showChevron = false; |
191 Menu showMenu; | 199 Menu showMenu; |
192 | 200 |
193 bool showMin = false; | 201 bool showMin = false; |
194 Rectangle minRect = new Rectangle(0, 0, 0, 0); | 202 Rectangle minRect; |
195 bool minimized = false; | 203 bool minimized = false; |
196 int minImageState = NORMAL; | 204 int minImageState = NORMAL; |
197 | 205 |
198 bool showMax = false; | 206 bool showMax = false; |
199 Rectangle maxRect = new Rectangle(0, 0, 0, 0); | 207 Rectangle maxRect; |
200 bool maximized = false; | 208 bool maximized = false; |
201 int maxImageState = NORMAL; | 209 int maxImageState = NORMAL; |
202 | 210 |
203 Control topRight; | 211 Control topRight; |
204 Rectangle topRightRect = new Rectangle(0, 0, 0, 0); | 212 Rectangle topRightRect; |
205 int topRightAlignment = DWT.RIGHT; | 213 int topRightAlignment = DWT.RIGHT; |
206 | 214 |
207 // borders and shapes | 215 // borders and shapes |
208 int borderLeft = 0; | 216 int borderLeft = 0; |
209 int borderRight = 0; | 217 int borderRight = 0; |
217 int[] topCurveHighlightStart; | 225 int[] topCurveHighlightStart; |
218 int[] topCurveHighlightEnd; | 226 int[] topCurveHighlightEnd; |
219 int curveWidth = 0; | 227 int curveWidth = 0; |
220 int curveIndent = 0; | 228 int curveIndent = 0; |
221 | 229 |
222 // when disposing CTabFolder, don't try to layout the items or | 230 // when disposing CTabFolder, don't try to layout the items or |
223 // change the selection as each child is destroyed. | 231 // change the selection as each child is destroyed. |
224 bool inDispose = false; | 232 bool inDispose = false; |
225 | 233 |
226 // keep track of size changes in order to redraw only affected area | 234 // keep track of size changes in order to redraw only affected area |
227 // on Resize | 235 // on Resize |
228 Point oldSize; | 236 Point oldSize; |
229 Font oldFont; | 237 Font oldFont; |
230 | 238 |
231 // internal constants | 239 // internal constants |
232 static const int DEFAULT_WIDTH = 64; | 240 static const int DEFAULT_WIDTH = 64; |
233 static const int DEFAULT_HEIGHT = 64; | 241 static const int DEFAULT_HEIGHT = 64; |
234 static const int BUTTON_SIZE = 18; | 242 static const int BUTTON_SIZE = 18; |
235 | 243 |
236 static const int[] | 244 static const int[] TOP_LEFT_CORNER = [0,6, 1,5, 1,4, 4,1, 5,1, 6,0]; |
237 TOP_LEFT_CORNER = new int[][0 , 6 , 1 , 5 , 1 , 4 , 4 , 1 , 5 , 1 , 6 , 0]; | 245 |
238 | 246 //TOP_LEFT_CORNER_HILITE is laid out in reverse (ie. top to bottom) |
239 // TOP_LEFT_CORNER_HILITE is laid out in reverse (ie. top to bottom) | 247 //so can fade in same direction as right swoop curve |
240 // so can fade in same direction as right swoop curve | 248 static const int[] TOP_LEFT_CORNER_HILITE = [5,2, 4,2, 3,3, 2,4, 2,5, 1,6]; |
241 static const int[] | 249 |
242 TOP_LEFT_CORNER_HILITE = new int[][5 , 2 , 4 , 2 , 3 , 3 , 2 , 4 , 2 , 5 , 1 , 6]; | 250 static const int[] TOP_RIGHT_CORNER = [-6,0, -5,1, -4,1, -1,4, -1,5, 0,6]; |
243 | 251 static const int[] BOTTOM_LEFT_CORNER = [0,-6, 1,-5, 1,-4, 4,-1, 5,-1, 6,0]; |
244 static const int[] | 252 static const int[] BOTTOM_RIGHT_CORNER = [-6,0, -5,-1, -4,-1, -1,-4, -1,-5, 0,-6]; |
245 TOP_RIGHT_CORNER = new int[][-6 , 0 , -5 , 1 , -4 , 1 , -1 , 4 , -1 , 5 , 0 , 6]; | 253 |
246 static const int[] | 254 static const int[] SIMPLE_TOP_LEFT_CORNER = [0,2, 1,1, 2,0]; |
247 BOTTOM_LEFT_CORNER = new int[][0 , -6 , 1 , -5 , 1 , -4 , 4 , -1 , 5 , -1 , 6 , 0]; | 255 static const int[] SIMPLE_TOP_RIGHT_CORNER = [-2,0, -1,1, 0,2]; |
248 static const int[] | 256 static const int[] SIMPLE_BOTTOM_LEFT_CORNER = [0,-2, 1,-1, 2,0]; |
249 BOTTOM_RIGHT_CORNER = new int[][-6 , 0 , -5 , -1 , -4 , -1 , -1 , -4 , -1 , -5 , 0 , -6]; | 257 static const int[] SIMPLE_BOTTOM_RIGHT_CORNER = [-2,0, -1,-1, 0,-2]; |
250 | 258 static const int[] SIMPLE_UNSELECTED_INNER_CORNER = [0,0]; |
251 static const int[] | 259 |
252 SIMPLE_TOP_LEFT_CORNER = new int[][0 , 2 , 1 , 1 , 2 , 0]; | 260 static const int[] TOP_LEFT_CORNER_BORDERLESS = [0,6, 1,5, 1,4, 4,1, 5,1, 6,0]; |
253 static const int[] | 261 static const int[] TOP_RIGHT_CORNER_BORDERLESS = [-7,0, -6,1, -5,1, -2,4, -2,5, -1,6]; |
254 SIMPLE_TOP_RIGHT_CORNER = new int[][-2 , 0 , -1 , 1 , 0 , 2]; | 262 static const int[] BOTTOM_LEFT_CORNER_BORDERLESS = [0,-6, 1,-6, 1,-5, 2,-4, 4,-2, 5,-1, 6,-1, 6,0]; |
255 static const int[] | 263 static const int[] BOTTOM_RIGHT_CORNER_BORDERLESS = [-7,0, -7,-1, -6,-1, -5,-2, -3,-4, -2,-5, -2,-6, -1,-6]; |
256 SIMPLE_BOTTOM_LEFT_CORNER = new int[][0 , -2 , 1 , -1 , 2 , 0]; | 264 |
257 static const int[] | 265 static const int[] SIMPLE_TOP_LEFT_CORNER_BORDERLESS = [0,2, 1,1, 2,0]; |
258 SIMPLE_BOTTOM_RIGHT_CORNER = new int[][-2 , 0 , -1 , -1 , 0 , -2]; | 266 static const int[] SIMPLE_TOP_RIGHT_CORNER_BORDERLESS= [-3,0, -2,1, -1,2]; |
259 static const int[] SIMPLE_UNSELECTED_INNER_CORNER = new int[][0 , 0]; | 267 static const int[] SIMPLE_BOTTOM_LEFT_CORNER_BORDERLESS = [0,-3, 1,-2, 2,-1, 3,0]; |
260 | 268 static const int[] SIMPLE_BOTTOM_RIGHT_CORNER_BORDERLESS = [-4,0, -3,-1, -2,-2, -1,-3]; |
261 static const int[] | |
262 TOP_LEFT_CORNER_BORDERLESS = new int[][0 , 6 , 1 , 5 , 1 , 4 , 4 , 1 , 5 , 1 , 6 , 0]; | |
263 static const int[] | |
264 TOP_RIGHT_CORNER_BORDERLESS = new int[][-7 , 0 , -6 , 1 , -5 , 1 , -2 , 4 , -2 , 5 , -1 , 6]; | |
265 static const int[] | |
266 BOTTOM_LEFT_CORNER_BORDERLESS = new int[][0 , -6 , 1 , -6 , 1 , -5 , 2 , -4 , 4 , -2 , 5 , -1 , 6 , -1 , 6 , 0]; | |
267 static const int[] | |
268 BOTTOM_RIGHT_CORNER_BORDERLESS = new int[][-7 , 0 , -7 , -1 , -6 , -1 , -5 , -2 , -3 , -4 , -2 , -5 , -2 , -6 , -1 , -6]; | |
269 | |
270 static const int[] | |
271 SIMPLE_TOP_LEFT_CORNER_BORDERLESS = new int[][0 , 2 , 1 , 1 , 2 , 0]; | |
272 static const int[] | |
273 SIMPLE_TOP_RIGHT_CORNER_BORDERLESS = new int[][-3 , 0 , -2 , 1 , -1 , 2]; | |
274 static const int[] | |
275 SIMPLE_BOTTOM_LEFT_CORNER_BORDERLESS = new int[][0 , -3 , 1 , -2 , 2 , -1 , 3 , 0]; | |
276 static const int[] | |
277 SIMPLE_BOTTOM_RIGHT_CORNER_BORDERLESS = new int[][-4 , 0 , -3 , -1 , -2 , -2 , -1 , -3]; | |
278 | 269 |
279 static const int SELECTION_FOREGROUND = DWT.COLOR_LIST_FOREGROUND; | 270 static const int SELECTION_FOREGROUND = DWT.COLOR_LIST_FOREGROUND; |
280 static const int SELECTION_BACKGROUND = DWT.COLOR_LIST_BACKGROUND; | 271 static const int SELECTION_BACKGROUND = DWT.COLOR_LIST_BACKGROUND; |
281 static const int BORDER1_COLOR = DWT.COLOR_WIDGET_NORMAL_SHADOW; | 272 static const int BORDER1_COLOR = DWT.COLOR_WIDGET_NORMAL_SHADOW; |
282 static const int FOREGROUND = DWT.COLOR_WIDGET_FOREGROUND; | 273 static const int FOREGROUND = DWT.COLOR_WIDGET_FOREGROUND; |
286 | 277 |
287 static const int NONE = 0; | 278 static const int NONE = 0; |
288 static const int NORMAL = 1; | 279 static const int NORMAL = 1; |
289 static const int HOT = 2; | 280 static const int HOT = 2; |
290 static const int SELECTED = 3; | 281 static const int SELECTED = 3; |
291 static const RGB CLOSE_FILL = new RGB(252, 160, 160); | 282 static const RGB CLOSE_FILL; |
292 | 283 |
293 static const int CHEVRON_CHILD_ID = 0; | 284 static const int CHEVRON_CHILD_ID = 0; |
294 static const int MINIMIZE_CHILD_ID = 1; | 285 static const int MINIMIZE_CHILD_ID = 1; |
295 static const int MAXIMIZE_CHILD_ID = 2; | 286 static const int MAXIMIZE_CHILD_ID = 2; |
296 static const int EXTRA_CHILD_ID_COUNT = 3; | 287 static const int EXTRA_CHILD_ID_COUNT = 3; |
297 | 288 |
298 /** | 289 static this(){ |
299 * Constructs a new instance of this class given its parent | 290 borderInsideRGB = new RGB (132, 130, 132); |
300 * and a style value describing its behavior and appearance. | 291 borderMiddleRGB = new RGB (143, 141, 138); |
301 * <p> | 292 borderOutsideRGB = new RGB (171, 168, 165); |
302 * The style value is either one of the style constants defined in | 293 CLOSE_FILL = new RGB(252, 160, 160); |
303 * class <code>DWT</code> which is applicable to instances of this | 294 } |
304 * class, or must be built by <em>bitwise OR</em>'ing together | 295 |
305 * (that is, using the <code>int</code> "|" operator) two or more | 296 /** |
306 * of those <code>DWT</code> style constants. The class description | 297 * Constructs a new instance of this class given its parent |
307 * lists the style constants that are applicable to the class. | 298 * and a style value describing its behavior and appearance. |
308 * Style bits are also inherited from superclasses. | 299 * <p> |
309 * </p> | 300 * The style value is either one of the style constants defined in |
310 * | 301 * class <code>DWT</code> which is applicable to instances of this |
311 * @param parent a widget which will be the parent of the new instance (cannot be null) | 302 * class, or must be built by <em>bitwise OR</em>'ing together |
312 * @param style the style of widget to construct | 303 * (that is, using the <code>int</code> "|" operator) two or more |
313 * | 304 * of those <code>DWT</code> style constants. The class description |
314 * @exception IllegalArgumentException <ul> | 305 * lists the style constants that are applicable to the class. |
315 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | 306 * Style bits are also inherited from superclasses. |
316 * </ul> | 307 * </p> |
317 * @exception DWTException <ul> | 308 * |
318 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | 309 * @param parent a widget which will be the parent of the new instance (cannot be null) |
319 * </ul> | 310 * @param style the style of widget to construct |
320 * | 311 * |
321 * @see DWT#TOP | 312 * @exception IllegalArgumentException <ul> |
322 * @see DWT#BOTTOM | 313 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
323 * @see DWT#FLAT | 314 * </ul> |
324 * @see DWT#BORDER | 315 * @exception DWTException <ul> |
325 * @see DWT#SINGLE | 316 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
326 * @see DWT#MULTI | 317 * </ul> |
327 * @see #getStyle() | 318 * |
319 * @see DWT#TOP | |
320 * @see DWT#BOTTOM | |
321 * @see DWT#FLAT | |
322 * @see DWT#BORDER | |
323 * @see DWT#SINGLE | |
324 * @see DWT#MULTI | |
325 * @see #getStyle() | |
326 */ | |
327 public this(Composite parent, int style) { | |
328 chevronRect = new Rectangle(0, 0, 0, 0); | |
329 minRect = new Rectangle(0, 0, 0, 0); | |
330 maxRect = new Rectangle(0, 0, 0, 0); | |
331 topRightRect = new Rectangle(0, 0, 0, 0); | |
332 super(parent, checkStyle (parent, style)); | |
333 super.setLayout(new CTabFolderLayout()); | |
334 int style2 = super.getStyle(); | |
335 oldFont = getFont(); | |
336 onBottom = (style2 & DWT.BOTTOM) !is 0; | |
337 showClose = (style2 & DWT.CLOSE) !is 0; | |
338 // showMin = (style2 & DWT.MIN) !is 0; - conflicts with DWT.TOP | |
339 // showMax = (style2 & DWT.MAX) !is 0; - conflicts with DWT.BOTTOM | |
340 single = (style2 & DWT.SINGLE) !is 0; | |
341 borderLeft = borderRight = (style & DWT.BORDER) !is 0 ? 1 : 0; | |
342 borderTop = onBottom ? borderLeft : 0; | |
343 borderBottom = onBottom ? 0 : borderLeft; | |
344 highlight_header = (style & DWT.FLAT) !is 0 ? 1 : 3; | |
345 highlight_margin = (style & DWT.FLAT) !is 0 ? 0 : 2; | |
346 //set up default colors | |
347 Display display = getDisplay(); | |
348 selectionForeground = display.getSystemColor(SELECTION_FOREGROUND); | |
349 selectionBackground = display.getSystemColor(SELECTION_BACKGROUND); | |
350 borderColor = display.getSystemColor(BORDER1_COLOR); | |
351 updateTabHeight(false); | |
352 | |
353 initAccessible(); | |
354 | |
355 // Add all listeners | |
356 listener = new class() Listener { | |
357 public void handleEvent(Event event) { | |
358 switch (event.type) { | |
359 case DWT.Dispose: onDispose(event); break; | |
360 case DWT.DragDetect: onDragDetect(event); break; | |
361 case DWT.FocusIn: onFocus(event); break; | |
362 case DWT.FocusOut: onFocus(event); break; | |
363 case DWT.KeyDown: onKeyDown(event); break; | |
364 case DWT.MouseDoubleClick: onMouseDoubleClick(event); break; | |
365 case DWT.MouseDown: onMouse(event); break; | |
366 case DWT.MouseEnter: onMouse(event); break; | |
367 case DWT.MouseExit: onMouse(event); break; | |
368 case DWT.MouseMove: onMouse(event); break; | |
369 case DWT.MouseUp: onMouse(event); break; | |
370 case DWT.Paint: onPaint(event); break; | |
371 case DWT.Resize: onResize(); break; | |
372 case DWT.Traverse: onTraverse(event); break; | |
373 default: | |
374 } | |
375 } | |
376 }; | |
377 | |
378 int[] folderEvents = [ | |
379 DWT.Dispose, | |
380 DWT.DragDetect, | |
381 DWT.FocusIn, | |
382 DWT.FocusOut, | |
383 DWT.KeyDown, | |
384 DWT.MouseDoubleClick, | |
385 DWT.MouseDown, | |
386 DWT.MouseEnter, | |
387 DWT.MouseExit, | |
388 DWT.MouseMove, | |
389 DWT.MouseUp, | |
390 DWT.Paint, | |
391 DWT.Resize, | |
392 DWT.Traverse, | |
393 ]; | |
394 for (int i = 0; i < folderEvents.length; i++) { | |
395 addListener(folderEvents[i], listener); | |
396 } | |
397 } | |
398 static int checkStyle (Composite parent, int style) { | |
399 int mask = DWT.CLOSE | DWT.TOP | DWT.BOTTOM | DWT.FLAT | DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT | DWT.SINGLE | DWT.MULTI; | |
400 style = style & mask; | |
401 // TOP and BOTTOM are mutually exclusive. | |
402 // TOP is the default | |
403 if ((style & DWT.TOP) !is 0) style = style & ~DWT.BOTTOM; | |
404 // SINGLE and MULTI are mutually exclusive. | |
405 // MULTI is the default | |
406 if ((style & DWT.MULTI) !is 0) style = style & ~DWT.SINGLE; | |
407 // reduce the flash by not redrawing the entire area on a Resize event | |
408 style |= DWT.NO_REDRAW_RESIZE; | |
409 //TEMPORARY CODE | |
410 /* | |
411 * The default background on carbon and some GTK themes is not a solid color | |
412 * but a texture. To show the correct default background, we must allow | |
413 * the operating system to draw it and therefore, we can not use the | |
414 * NO_BACKGROUND style. The NO_BACKGROUND style is not required on platforms | |
415 * that use double buffering which is true in both of these cases. | |
328 */ | 416 */ |
329 public this (Composite parent, int style) | 417 String platform = DWT.getPlatform(); |
330 { | 418 if ("carbon"==platform || "gtk"==platform) return style; //$NON-NLS-1$ //$NON-NLS-2$ |
331 super(parent, checkStyle(parent, style)); | 419 |
332 super.setLayout(new CTabFolderLayout()); | 420 //TEMPORARY CODE |
333 int style2 = super.getStyle(); | 421 /* |
334 oldFont = getFont(); | 422 * In Right To Left orientation on Windows, all GC calls that use a brush are drawing |
335 onBottom = (style2 & DWT.BOTTOM) !is 0; | 423 * offset by one pixel. This results in some parts of the CTabFolder not drawing correctly. |
336 showClose = (style2 & DWT.CLOSE) !is 0; | 424 * To alleviate some of the appearance problems, allow the OS to draw the background. |
337 // showMin = (style2 & DWT.MIN) !is 0; - conflicts with DWT.TOP | 425 * This does not draw correctly but the result is less obviously wrong. |
338 // showMax = (style2 & DWT.MAX) !is 0; - conflicts with DWT.BOTTOM | |
339 single = (style2 & DWT.SINGLE) !is 0; | |
340 borderLeft = borderRight = (style & DWT.BORDER) !is 0 ? 1 : 0; | |
341 borderTop = onBottom ? borderLeft : 0; | |
342 borderBottom = onBottom ? 0 : borderLeft; | |
343 highlight_header = (style & DWT.FLAT) !is 0 ? 1 : 3; | |
344 highlight_margin = (style & DWT.FLAT) !is 0 ? 0 : 2; | |
345 //set up default colors | |
346 Display display = getDisplay(); | |
347 selectionForeground = display.getSystemColor(SELECTION_FOREGROUND); | |
348 selectionBackground = display.getSystemColor(SELECTION_BACKGROUND); | |
349 borderColor = display.getSystemColor(BORDER1_COLOR); | |
350 updateTabHeight(false); | |
351 | |
352 initAccessible(); | |
353 | |
354 // Add all listeners | |
355 listener = new class Listener | |
356 { | |
357 public void handleEvent (Event event) | |
358 { | |
359 switch (event.type) | |
360 { | |
361 case DWT.Dispose: | |
362 onDispose(event); | |
363 break; | |
364 case DWT.DragDetect: | |
365 onDragDetect(event); | |
366 break; | |
367 case DWT.FocusIn: | |
368 onFocus(event); | |
369 break; | |
370 case DWT.FocusOut: | |
371 onFocus(event); | |
372 break; | |
373 case DWT.KeyDown: | |
374 onKeyDown(event); | |
375 break; | |
376 case DWT.MouseDoubleClick: | |
377 onMouseDoubleClick(event); | |
378 break; | |
379 case DWT.MouseDown: | |
380 onMouse(event); | |
381 break; | |
382 case DWT.MouseEnter: | |
383 onMouse(event); | |
384 break; | |
385 case DWT.MouseExit: | |
386 onMouse(event); | |
387 break; | |
388 case DWT.MouseMove: | |
389 onMouse(event); | |
390 break; | |
391 case DWT.MouseUp: | |
392 onMouse(event); | |
393 break; | |
394 case DWT.Paint: | |
395 onPaint(event); | |
396 break; | |
397 case DWT.Resize: | |
398 onResize(); | |
399 break; | |
400 case DWT.Traverse: | |
401 onTraverse(event); | |
402 break; | |
403 } | |
404 } | |
405 }; | |
406 | |
407 int[] | |
408 folderEvents = new int[][DWT.Dispose , DWT.DragDetect , DWT.FocusIn , DWT.FocusOut , DWT.KeyDown , DWT.MouseDoubleClick , DWT.MouseDown , DWT.MouseEnter , DWT.MouseExit , DWT.MouseMove , DWT.MouseUp , DWT.Paint , DWT.Resize , DWT.Traverse]; | |
409 for (int i = 0; i < folderEvents.length; i++) | |
410 { | |
411 addListener(folderEvents[i], listener); | |
412 } | |
413 } | |
414 | |
415 static int checkStyle (Composite parent, int style) | |
416 { | |
417 int | |
418 mask = DWT.CLOSE | DWT.TOP | DWT.BOTTOM | DWT.FLAT | DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT | DWT.SINGLE | DWT.MULTI; | |
419 style = style & mask; | |
420 // TOP and BOTTOM are mutually exclusive. | |
421 // TOP is the default | |
422 if ((style & DWT.TOP) !is 0) | |
423 style = style & ~DWT.BOTTOM; | |
424 // SINGLE and MULTI are mutually exclusive. | |
425 // MULTI is the default | |
426 if ((style & DWT.MULTI) !is 0) | |
427 style = style & ~DWT.SINGLE; | |
428 // reduce the flash by not redrawing the entire area on a Resize event | |
429 style |= DWT.NO_REDRAW_RESIZE; | |
430 //TEMPORARY CODE | |
431 /* | |
432 * The default background on carbon and some GTK themes is not a solid color | |
433 * but a texture. To show the correct default background, we must allow | |
434 * the operating system to draw it and therefore, we can not use the | |
435 * NO_BACKGROUND style. The NO_BACKGROUND style is not required on platforms | |
436 * that use double buffering which is true in both of these cases. | |
437 */ | |
438 String platform = DWT.getPlatform(); | |
439 if ("carbon".opEquals(platform) || "gtk".opEquals(platform)) | |
440 return style; //$NON-NLS-1$ //$NON-NLS-2$ | |
441 | |
442 //TEMPORARY CODE | |
443 /* | |
444 * In Right To Left orientation on Windows, all GC calls that use a brush are drawing | |
445 * offset by one pixel. This results in some parts of the CTabFolder not drawing correctly. | |
446 * To alleviate some of the appearance problems, allow the OS to draw the background. | |
447 * This does not draw correctly but the result is less obviously wrong. | |
448 */ | |
449 if ((style & DWT.RIGHT_TO_LEFT) !is 0) | |
450 return style; | |
451 if ((parent.getStyle() & DWT.MIRRORED) !is 0 && (style & DWT.LEFT_TO_RIGHT) is 0) | |
452 return style; | |
453 | |
454 return style | DWT.NO_BACKGROUND; | |
455 } | |
456 | |
457 static void fillRegion (GC gc, Region region) | |
458 { | |
459 // NOTE: region passed in to this function will be modified | |
460 Region clipping = new Region(); | |
461 gc.getClipping(clipping); | |
462 region.intersect(clipping); | |
463 gc.setClipping(region); | |
464 gc.fillRectangle(region.getBounds()); | |
465 gc.setClipping(clipping); | |
466 clipping.dispose(); | |
467 } | |
468 | |
469 /** | |
470 * | |
471 * Adds the listener to the collection of listeners who will | |
472 * be notified when a tab item is closed, minimized, maximized, | |
473 * restored, or to show the list of items that are not | |
474 * currently visible. | |
475 * | |
476 * @param listener the listener which should be notified | |
477 * | |
478 * @exception IllegalArgumentException <ul> | |
479 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
480 * </ul> | |
481 * | |
482 * @exception DWTException <ul> | |
483 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
484 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
485 * </ul> | |
486 * | |
487 * @see CTabFolder2Listener | |
488 * @see #removeCTabFolder2Listener(CTabFolder2Listener) | |
489 * | |
490 * @since 3.0 | |
491 */ | 426 */ |
492 public void addCTabFolder2Listener (CTabFolder2Listener listener) | 427 if ((style & DWT.RIGHT_TO_LEFT) !is 0) return style; |
493 { | 428 if ((parent.getStyle() & DWT.MIRRORED) !is 0 && (style & DWT.LEFT_TO_RIGHT) is 0) return style; |
494 checkWidget(); | 429 |
495 if (listener is null) | 430 return style | DWT.NO_BACKGROUND; |
496 DWT.error(DWT.ERROR_NULL_ARGUMENT); | 431 } |
497 // add to array | 432 static void fillRegion(GC gc, Region region) { |
498 CTabFolder2Listener[] | 433 // NOTE: region passed in to this function will be modified |
499 newListeners = new CTabFolder2Listener[folderListeners.length + 1]; | 434 Region clipping = new Region(); |
500 System.arraycopy(folderListeners, 0, newListeners, 0, | 435 gc.getClipping(clipping); |
501 folderListeners.length); | 436 region.intersect(clipping); |
502 folderListeners = newListeners; | 437 gc.setClipping(region); |
503 folderListeners[folderListeners.length - 1] = listener; | 438 gc.fillRectangle(region.getBounds()); |
504 } | 439 gc.setClipping(clipping); |
505 | 440 clipping.dispose(); |
506 /** | 441 } |
507 * Adds the listener to the collection of listeners who will | 442 /** |
508 * be notified when a tab item is closed. | 443 * |
509 * | 444 * Adds the listener to the collection of listeners who will |
510 * @param listener the listener which should be notified | 445 * be notified when a tab item is closed, minimized, maximized, |
511 * | 446 * restored, or to show the list of items that are not |
512 * @exception IllegalArgumentException <ul> | 447 * currently visible. |
513 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | 448 * |
514 * </ul> | 449 * @param listener the listener which should be notified |
515 * @exception DWTException <ul> | 450 * |
516 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | 451 * @exception IllegalArgumentException <ul> |
517 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | 452 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
518 * </ul> | 453 * </ul> |
519 * | 454 * |
520 * @see CTabFolderListener | 455 * @exception DWTException <ul> |
521 * @see #removeCTabFolderListener(CTabFolderListener) | 456 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> |
522 * | 457 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> |
523 * @deprecated use addCTabFolder2Listener(CTabFolder2Listener) | 458 * </ul> |
524 */ | 459 * |
525 public void addCTabFolderListener (CTabFolderListener listener) | 460 * @see CTabFolder2Listener |
526 { | 461 * @see #removeCTabFolder2Listener(CTabFolder2Listener) |
527 checkWidget(); | 462 * |
528 if (listener is null) | 463 * @since 3.0 |
529 DWT.error(DWT.ERROR_NULL_ARGUMENT); | 464 */ |
530 // add to array | 465 public void addCTabFolder2Listener(CTabFolder2Listener listener) { |
531 CTabFolderListener[] | 466 checkWidget(); |
532 newTabListeners = new CTabFolderListener[tabListeners.length + 1]; | 467 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); |
533 System.arraycopy(tabListeners, 0, newTabListeners, 0, | 468 // add to array |
534 tabListeners.length); | 469 CTabFolder2Listener[] newListeners = new CTabFolder2Listener[folderListeners.length + 1]; |
535 tabListeners = newTabListeners; | 470 SimpleType!(CTabFolder2Listener).arraycopy(folderListeners, 0, newListeners, 0, folderListeners.length); |
536 tabListeners[tabListeners.length - 1] = listener; | 471 folderListeners = newListeners; |
537 // display close button to be backwards compatible | 472 folderListeners[folderListeners.length - 1] = listener; |
538 if (!showClose) | 473 } |
539 { | 474 /** |
540 showClose = true; | 475 * Adds the listener to the collection of listeners who will |
541 updateItems(); | 476 * be notified when a tab item is closed. |
542 redraw(); | 477 * |
543 } | 478 * @param listener the listener which should be notified |
544 } | 479 * |
545 | 480 * @exception IllegalArgumentException <ul> |
546 /** | 481 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
547 * Adds the listener to the collection of listeners who will | 482 * </ul> |
548 * be notified when the user changes the receiver's selection, by sending | 483 * @exception DWTException <ul> |
549 * it one of the messages defined in the <code>SelectionListener</code> | 484 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> |
550 * interface. | 485 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> |
551 * <p> | 486 * </ul> |
552 * <code>widgetSelected</code> is called when the user changes the selected tab. | 487 * |
553 * <code>widgetDefaultSelected</code> is not called. | 488 * @see CTabFolderListener |
554 * </p> | 489 * @see #removeCTabFolderListener(CTabFolderListener) |
555 * | 490 * |
556 * @param listener the listener which should be notified when the user changes the receiver's selection | 491 * @deprecated use addCTabFolder2Listener(CTabFolder2Listener) |
557 * | 492 */ |
558 * @exception IllegalArgumentException <ul> | 493 public void addCTabFolderListener(CTabFolderListener listener) { |
559 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | 494 checkWidget(); |
560 * </ul> | 495 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); |
561 * @exception DWTException <ul> | 496 // add to array |
562 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 497 CTabFolderListener[] newTabListeners = new CTabFolderListener[tabListeners.length + 1]; |
563 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 498 SimpleType!(CTabFolderListener).arraycopy(tabListeners, 0, newTabListeners, 0, tabListeners.length); |
564 * </ul> | 499 tabListeners = newTabListeners; |
565 * | 500 tabListeners[tabListeners.length - 1] = listener; |
566 * @see SelectionListener | 501 // display close button to be backwards compatible |
567 * @see #removeSelectionListener | 502 if (!showClose) { |
568 * @see SelectionEvent | 503 showClose = true; |
569 */ | 504 updateItems(); |
570 public void addSelectionListener (SelectionListener listener) | 505 redraw(); |
571 { | 506 } |
572 checkWidget(); | 507 } |
573 if (listener is null) | 508 /** |
574 { | 509 * Adds the listener to the collection of listeners who will |
575 DWT.error(DWT.ERROR_NULL_ARGUMENT); | 510 * be notified when the user changes the receiver's selection, by sending |
576 } | 511 * it one of the messages defined in the <code>SelectionListener</code> |
577 TypedListener typedListener = new TypedListener(listener); | 512 * interface. |
578 addListener(DWT.Selection, typedListener); | 513 * <p> |
579 addListener(DWT.DefaultSelection, typedListener); | 514 * <code>widgetSelected</code> is called when the user changes the selected tab. |
580 } | 515 * <code>widgetDefaultSelected</code> is not called. |
581 | 516 * </p> |
582 void antialias (int[] shape, RGB lineRGB, RGB innerRGB, RGB outerRGB, GC gc) | 517 * |
583 { | 518 * @param listener the listener which should be notified when the user changes the receiver's selection |
584 // Don't perform anti-aliasing on Mac and WPF because the platform | 519 * |
585 // already does it. The simple style also does not require anti-aliasing. | 520 * @exception IllegalArgumentException <ul> |
586 if (simple || "carbon".opEquals(DWT.getPlatform()) || "wpf".opEquals( | 521 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
587 DWT.getPlatform())) | 522 * </ul> |
588 return; //$NON-NLS-1$ | 523 * @exception DWTException <ul> |
589 // Don't perform anti-aliasing on low resolution displays | 524 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
590 if (getDisplay().getDepth() < 15) | 525 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
591 return; | 526 * </ul> |
592 if (outerRGB !is null) | 527 * |
593 { | 528 * @see SelectionListener |
594 int index = 0; | 529 * @see #removeSelectionListener |
595 bool left = true; | 530 * @see SelectionEvent |
596 int oldY = onBottom ? 0 : getSize().y; | 531 */ |
597 int[] outer = new int[shape.length]; | 532 public void addSelectionListener(SelectionListener listener) { |
598 for (int i = 0; i < shape.length / 2; i++) | 533 checkWidget(); |
599 { | 534 if (listener is null) { |
600 if (left && (index + 3 < shape.length)) | 535 DWT.error(DWT.ERROR_NULL_ARGUMENT); |
601 { | 536 } |
602 left = onBottom ? oldY <= shape[index + 3] : oldY >= shape[index + 3]; | 537 TypedListener typedListener = new TypedListener(listener); |
603 oldY = shape[index + 1]; | 538 addListener(DWT.Selection, typedListener); |
604 } | 539 addListener(DWT.DefaultSelection, typedListener); |
605 outer[index] = shape[index++] + (left ? -1 : +1); | 540 } |
606 outer[index] = shape[index++]; | 541 void antialias (int[] shape, RGB lineRGB, RGB innerRGB, RGB outerRGB, GC gc){ |
607 } | 542 // Don't perform anti-aliasing on Mac and WPF because the platform |
608 RGB from = lineRGB; | 543 // already does it. The simple style also does not require anti-aliasing. |
609 RGB to = outerRGB; | 544 if (simple || "carbon".equals(DWT.getPlatform()) || "wpf".equals(DWT.getPlatform())) return; //$NON-NLS-1$ |
610 int red = from.red + 2 * (to.red - from.red) / 3; | 545 // Don't perform anti-aliasing on low resolution displays |
611 int green = from.green + 2 * (to.green - from.green) / 3; | 546 if (getDisplay().getDepth() < 15) return; |
612 int blue = from.blue + 2 * (to.blue - from.blue) / 3; | 547 if (outerRGB !is null) { |
613 Color color = new Color(getDisplay(), red, green, blue); | 548 int index = 0; |
614 gc.setForeground(color); | 549 bool left = true; |
615 gc.drawPolyline(outer); | 550 int oldY = onBottom ? 0 : getSize().y; |
616 color.dispose(); | 551 int[] outer = new int[shape.length]; |
617 } | 552 for (int i = 0; i < shape.length/2; i++) { |
618 if (innerRGB !is null) | 553 if (left && (index + 3 < shape.length)) { |
619 { | 554 left = onBottom ? oldY <= shape[index+3] : oldY >= shape[index+3]; |
620 int[] inner = new int[shape.length]; | 555 oldY = shape[index+1]; |
621 int index = 0; | 556 } |
622 bool left = true; | 557 outer[index] = shape[index] + (left ? -1 : +1); |
623 int oldY = onBottom ? 0 : getSize().y; | 558 index++; |
624 for (int i = 0; i < shape.length / 2; i++) | 559 outer[index] = shape[index]; |
625 { | 560 index++; |
626 if (left && (index + 3 < shape.length)) | 561 } |
627 { | 562 RGB from = lineRGB; |
628 left = onBottom ? oldY <= shape[index + 3] : oldY >= shape[index + 3]; | 563 RGB to = outerRGB; |
629 oldY = shape[index + 1]; | 564 int red = from.red + 2*(to.red - from.red)/3; |
630 } | 565 int green = from.green + 2*(to.green - from.green)/3; |
631 inner[index] = shape[index++] + (left ? +1 : -1); | 566 int blue = from.blue + 2*(to.blue - from.blue)/3; |
632 inner[index] = shape[index++]; | 567 Color color = new Color(getDisplay(), red, green, blue); |
633 } | 568 gc.setForeground(color); |
634 RGB from = lineRGB; | 569 gc.drawPolyline(outer); |
635 RGB to = innerRGB; | 570 color.dispose(); |
636 int red = from.red + 2 * (to.red - from.red) / 3; | 571 } |
637 int green = from.green + 2 * (to.green - from.green) / 3; | 572 if (innerRGB !is null) { |
638 int blue = from.blue + 2 * (to.blue - from.blue) / 3; | 573 int[] inner = new int[shape.length]; |
639 Color color = new Color(getDisplay(), red, green, blue); | 574 int index = 0; |
640 gc.setForeground(color); | 575 bool left = true; |
641 gc.drawPolyline(inner); | 576 int oldY = onBottom ? 0 : getSize().y; |
642 color.dispose(); | 577 for (int i = 0; i < shape.length/2; i++) { |
643 } | 578 if (left && (index + 3 < shape.length)) { |
644 } | 579 left = onBottom ? oldY <= shape[index+3] : oldY >= shape[index+3]; |
645 | 580 oldY = shape[index+1]; |
646 public Rectangle computeTrim (int x, int y, int width, int height) | 581 } |
647 { | 582 inner[index] = shape[index] + (left ? +1 : -1); |
648 checkWidget(); | 583 index++; |
649 int trimX = x - marginWidth - highlight_margin - borderLeft; | 584 inner[index] = shape[index]; |
650 int | 585 index++; |
651 trimWidth = width + borderLeft + borderRight + 2 * marginWidth + 2 * highlight_margin; | 586 } |
652 if (minimized) | 587 RGB from = lineRGB; |
653 { | 588 RGB to = innerRGB; |
654 int | 589 int red = from.red + 2*(to.red - from.red)/3; |
655 trimY = onBottom ? y - borderTop : y - highlight_header - tabHeight - borderTop; | 590 int green = from.green + 2*(to.green - from.green)/3; |
656 int | 591 int blue = from.blue + 2*(to.blue - from.blue)/3; |
657 trimHeight = borderTop + borderBottom + tabHeight + highlight_header; | 592 Color color = new Color(getDisplay(), red, green, blue); |
658 return new Rectangle(trimX, trimY, trimWidth, trimHeight); | 593 gc.setForeground(color); |
659 } | 594 gc.drawPolyline(inner); |
660 else | 595 color.dispose(); |
661 { | 596 } |
662 int | 597 } |
663 trimY = onBottom ? y - marginHeight - highlight_margin - borderTop : y - marginHeight - highlight_header - tabHeight - borderTop; | 598 public override Rectangle computeTrim (int x, int y, int width, int height) { |
664 int | 599 checkWidget(); |
665 trimHeight = height + borderTop + borderBottom + 2 * marginHeight + tabHeight + highlight_header + highlight_margin; | 600 int trimX = x - marginWidth - highlight_margin - borderLeft; |
666 return new Rectangle(trimX, trimY, trimWidth, trimHeight); | 601 int trimWidth = width + borderLeft + borderRight + 2*marginWidth + 2*highlight_margin; |
667 } | 602 if (minimized) { |
668 } | 603 int trimY = onBottom ? y - borderTop : y - highlight_header - tabHeight - borderTop; |
669 | 604 int trimHeight = borderTop + borderBottom + tabHeight + highlight_header; |
670 void createItem (CTabItem item, int index) | 605 return new Rectangle (trimX, trimY, trimWidth, trimHeight); |
671 { | 606 } else { |
672 if (0 > index || index > getItemCount()) | 607 int trimY = onBottom ? y - marginHeight - highlight_margin - borderTop: y - marginHeight - highlight_header - tabHeight - borderTop; |
673 DWT.error(DWT.ERROR_INVALID_RANGE); | 608 int trimHeight = height + borderTop + borderBottom + 2*marginHeight + tabHeight + highlight_header + highlight_margin; |
674 item.parent = this; | 609 return new Rectangle (trimX, trimY, trimWidth, trimHeight); |
675 CTabItem[] newItems = new CTabItem[items.length + 1]; | 610 } |
676 System.arraycopy(items, 0, newItems, 0, index); | 611 } |
677 newItems[index] = item; | 612 void createItem (CTabItem item, int index) { |
678 System.arraycopy(items, index, newItems, index + 1, | 613 if (0 > index || index > getItemCount ())DWT.error (DWT.ERROR_INVALID_RANGE); |
679 items.length - index); | 614 item.parent = this; |
680 items = newItems; | 615 CTabItem[] newItems = new CTabItem [items.length + 1]; |
681 if (selectedIndex >= index) | 616 System.arraycopy(items, 0, newItems, 0, index); |
682 selectedIndex++; | 617 newItems[index] = item; |
683 int[] newPriority = new int[priority.length + 1]; | 618 System.arraycopy(items, index, newItems, index + 1, items.length - index); |
684 int next = 0, priorityIndex = priority.length; | 619 items = newItems; |
685 for (int i = 0; i < priority.length; i++) | 620 if (selectedIndex >= index) selectedIndex ++; |
686 { | 621 int[] newPriority = new int[priority.length + 1]; |
687 if (!mru && priority[i] is index) | 622 int next = 0, priorityIndex = priority.length; |
688 { | 623 for (int i = 0; i < priority.length; i++) { |
689 priorityIndex = next++; | 624 if (!mru && priority[i] is index) { |
690 } | 625 priorityIndex = next++; |
691 newPriority[next++] = priority[i] >= index ? priority[i] + 1 : priority[i]; | 626 } |
692 } | 627 newPriority[next++] = priority[i] >= index ? priority[i] + 1 : priority[i]; |
693 newPriority[priorityIndex] = index; | 628 } |
694 priority = newPriority; | 629 newPriority[priorityIndex] = index; |
695 | 630 priority = newPriority; |
696 if (items.length is 1) | 631 |
697 { | 632 if (items.length is 1) { |
698 if (!updateTabHeight(false)) | 633 if (!updateTabHeight(false)) updateItems(); |
699 updateItems(); | 634 redraw(); |
700 redraw(); | 635 } else { |
701 } | |
702 else | |
703 { | |
704 updateItems(); | |
705 redrawTabs(); | |
706 } | |
707 } | |
708 | |
709 void destroyItem (CTabItem item) | |
710 { | |
711 if (inDispose) | |
712 return; | |
713 int index = indexOf(item); | |
714 if (index is -1) | |
715 return; | |
716 | |
717 if (items.length is 1) | |
718 { | |
719 items = new CTabItem[0]; | |
720 priority = new int[0]; | |
721 firstIndex = -1; | |
722 selectedIndex = -1; | |
723 | |
724 Control control = item.getControl(); | |
725 if (control !is null && !control.isDisposed()) | |
726 { | |
727 control.setVisible(false); | |
728 } | |
729 setToolTipText(null); | |
730 setButtonBounds(); | |
731 redraw(); | |
732 return; | |
733 } | |
734 | |
735 CTabItem[] newItems = new CTabItem[items.length - 1]; | |
736 System.arraycopy(items, 0, newItems, 0, index); | |
737 System.arraycopy(items, index + 1, newItems, index, | |
738 items.length - index - 1); | |
739 items = newItems; | |
740 | |
741 int[] newPriority = new int[priority.length - 1]; | |
742 int next = 0; | |
743 for (int i = 0; i < priority.length; i++) | |
744 { | |
745 if (priority[i] is index) | |
746 continue; | |
747 newPriority[next++] = priority[i] > index ? priority[i] - 1 : priority[i]; | |
748 } | |
749 priority = newPriority; | |
750 | |
751 // move the selection if this item is selected | |
752 if (selectedIndex is index) | |
753 { | |
754 Control control = item.getControl(); | |
755 selectedIndex = -1; | |
756 int nextSelection = mru ? priority[0] : Math.max(0, index - 1); | |
757 setSelection(nextSelection, true); | |
758 if (control !is null && !control.isDisposed()) | |
759 { | |
760 control.setVisible(false); | |
761 } | |
762 } | |
763 else if (selectedIndex > index) | |
764 { | |
765 selectedIndex--; | |
766 } | |
767 | |
768 updateItems(); | 636 updateItems(); |
769 redrawTabs(); | 637 redrawTabs(); |
770 } | 638 } |
771 | 639 } |
772 void drawBackground (GC gc, int[] shape, bool selected) | 640 void destroyItem (CTabItem item) { |
773 { | 641 if (inDispose) return; |
774 Color | 642 int index = indexOf(item); |
775 defaultBackground = selected ? selectionBackground : getBackground(); | 643 if (index is -1) return; |
776 Image image = selected ? selectionBgImage : bgImage; | 644 |
777 Color[] colors = selected ? selectionGradientColors : gradientColors; | 645 if (items.length is 1) { |
778 int[] | 646 items = new CTabItem[0]; |
779 percents = selected ? selectionGradientPercents : gradientPercents; | 647 priority = new int[0]; |
780 bool vertical = selected ? selectionGradientVertical : gradientVertical; | 648 firstIndex = -1; |
781 Point size = getSize(); | 649 selectedIndex = -1; |
782 int width = size.x; | 650 |
783 int height = tabHeight + highlight_header; | 651 Control control = item.getControl(); |
784 int x = 0; | 652 if (control !is null && !control.isDisposed()) { |
785 if (borderLeft > 0) | 653 control.setVisible(false); |
786 { | 654 } |
787 x += 1; | 655 setToolTipText(null); |
788 width -= 2; | 656 setButtonBounds(); |
789 } | 657 redraw(); |
790 int y = onBottom ? size.y - borderBottom - height : borderTop; | 658 return; |
791 drawBackground(gc, shape, x, y, width, height, defaultBackground, | 659 } |
792 image, colors, percents, vertical); | 660 |
793 } | 661 CTabItem[] newItems = new CTabItem [items.length - 1]; |
794 | 662 System.arraycopy(items, 0, newItems, 0, index); |
795 void drawBackground (GC gc, int[] shape, int x, int y, int width, | 663 System.arraycopy(items, index + 1, newItems, index, items.length - index - 1); |
796 int height, Color defaultBackground, Image image, Color[] colors, | 664 items = newItems; |
797 int[] percents, bool vertical) | 665 |
798 { | 666 int[] newPriority = new int[priority.length - 1]; |
799 Region clipping = new Region(); | 667 int next = 0; |
800 gc.getClipping(clipping); | 668 for (int i = 0; i < priority.length; i++) { |
801 Region region = new Region(); | 669 if (priority [i] is index) continue; |
802 region.add(shape); | 670 newPriority[next++] = priority[i] > index ? priority[i] - 1 : priority [i]; |
803 region.intersect(clipping); | 671 } |
804 gc.setClipping(region); | 672 priority = newPriority; |
805 | 673 |
806 if (image !is null) | 674 // move the selection if this item is selected |
807 { | 675 if (selectedIndex is index) { |
808 // draw the background image in shape | 676 Control control = item.getControl(); |
677 selectedIndex = -1; | |
678 int nextSelection = mru ? priority[0] : Math.max(0, index - 1); | |
679 setSelection(nextSelection, true); | |
680 if (control !is null && !control.isDisposed()) { | |
681 control.setVisible(false); | |
682 } | |
683 } else if (selectedIndex > index) { | |
684 selectedIndex --; | |
685 } | |
686 | |
687 updateItems(); | |
688 redrawTabs(); | |
689 } | |
690 void drawBackground(GC gc, int[] shape, bool selected) { | |
691 Color defaultBackground = selected ? selectionBackground : getBackground(); | |
692 Image image = selected ? selectionBgImage : bgImage; | |
693 Color[] colors = selected ? selectionGradientColors : gradientColors; | |
694 int[] percents = selected ? selectionGradientPercents : gradientPercents; | |
695 bool vertical = selected ? selectionGradientVertical : gradientVertical; | |
696 Point size = getSize(); | |
697 int width = size.x; | |
698 int height = tabHeight + highlight_header; | |
699 int x = 0; | |
700 if (borderLeft > 0) { | |
701 x += 1; width -= 2; | |
702 } | |
703 int y = onBottom ? size.y - borderBottom - height : borderTop; | |
704 drawBackground(gc, shape, x, y, width, height, defaultBackground, image, colors, percents, vertical); | |
705 } | |
706 void drawBackground(GC gc, int[] shape, int x, int y, int width, int height, Color defaultBackground, Image image, Color[] colors, int[] percents, bool vertical) { | |
707 Region clipping = new Region(); | |
708 gc.getClipping(clipping); | |
709 Region region = new Region(); | |
710 region.add(shape); | |
711 region.intersect(clipping); | |
712 gc.setClipping(region); | |
713 | |
714 if (image !is null) { | |
715 // draw the background image in shape | |
716 gc.setBackground(defaultBackground); | |
717 gc.fillRectangle(x, y, width, height); | |
718 Rectangle imageRect = image.getBounds(); | |
719 gc.drawImage(image, imageRect.x, imageRect.y, imageRect.width, imageRect.height, x, y, width, height); | |
720 } else if (colors !is null) { | |
721 // draw gradient | |
722 if (colors.length is 1) { | |
723 Color background = colors[0] !is null ? colors[0] : defaultBackground; | |
724 gc.setBackground(background); | |
725 gc.fillRectangle(x, y, width, height); | |
726 } else { | |
727 if (vertical) { | |
728 if (onBottom) { | |
729 int pos = 0; | |
730 if (percents[percents.length - 1] < 100) { | |
731 pos = percents[percents.length - 1] * height / 100; | |
732 gc.setBackground(defaultBackground); | |
733 gc.fillRectangle(x, y, width, pos); | |
734 } | |
735 Color lastColor = colors[colors.length-1]; | |
736 if (lastColor is null) lastColor = defaultBackground; | |
737 for (int i = percents.length-1; i >= 0; i--) { | |
738 gc.setForeground(lastColor); | |
739 lastColor = colors[i]; | |
740 if (lastColor is null) lastColor = defaultBackground; | |
741 gc.setBackground(lastColor); | |
742 int gradientHeight = percents[i] * height / 100; | |
743 gc.fillGradientRectangle(x, y+pos, width, gradientHeight, true); | |
744 pos += gradientHeight; | |
745 } | |
746 } else { | |
747 Color lastColor = colors[0]; | |
748 if (lastColor is null) lastColor = defaultBackground; | |
749 int pos = 0; | |
750 for (int i = 0; i < percents.length; i++) { | |
751 gc.setForeground(lastColor); | |
752 lastColor = colors[i + 1]; | |
753 if (lastColor is null) lastColor = defaultBackground; | |
754 gc.setBackground(lastColor); | |
755 int gradientHeight = percents[i] * height / 100; | |
756 gc.fillGradientRectangle(x, y+pos, width, gradientHeight, true); | |
757 pos += gradientHeight; | |
758 } | |
759 if (pos < height) { | |
760 gc.setBackground(defaultBackground); | |
761 gc.fillRectangle(x, pos, width, height-pos+1); | |
762 } | |
763 } | |
764 } else { //horizontal gradient | |
765 y = 0; | |
766 height = getSize().y; | |
767 Color lastColor = colors[0]; | |
768 if (lastColor is null) lastColor = defaultBackground; | |
769 int pos = 0; | |
770 for (int i = 0; i < percents.length; ++i) { | |
771 gc.setForeground(lastColor); | |
772 lastColor = colors[i + 1]; | |
773 if (lastColor is null) lastColor = defaultBackground; | |
774 gc.setBackground(lastColor); | |
775 int gradientWidth = (percents[i] * width / 100) - pos; | |
776 gc.fillGradientRectangle(x+pos, y, gradientWidth, height, false); | |
777 pos += gradientWidth; | |
778 } | |
779 if (pos < width) { | |
780 gc.setBackground(defaultBackground); | |
781 gc.fillRectangle(x+pos, y, width-pos, height); | |
782 } | |
783 } | |
784 } | |
785 } else { | |
786 // draw a solid background using default background in shape | |
787 if ((getStyle() & DWT.NO_BACKGROUND) !is 0 || defaultBackground!=getBackground()) { | |
809 gc.setBackground(defaultBackground); | 788 gc.setBackground(defaultBackground); |
810 gc.fillRectangle(x, y, width, height); | 789 gc.fillRectangle(x, y, width, height); |
811 Rectangle imageRect = image.getBounds(); | 790 } |
812 gc.drawImage(image, imageRect.x, imageRect.y, imageRect.width, | 791 } |
813 imageRect.height, x, y, width, height); | 792 gc.setClipping(clipping); |
814 } | 793 clipping.dispose(); |
815 else if (colors !is null) | 794 region.dispose(); |
816 { | 795 } |
817 // draw gradient | 796 void drawBody(Event event) { |
818 if (colors.length is 1) | 797 GC gc = event.gc; |
819 { | 798 Point size = getSize(); |
820 Color | 799 |
821 background = colors[0] !is null ? colors[0] : defaultBackground; | 800 // fill in body |
822 gc.setBackground(background); | 801 if (!minimized){ |
823 gc.fillRectangle(x, y, width, height); | 802 int width = size.x - borderLeft - borderRight - 2*highlight_margin; |
824 } | 803 int height = size.y - borderTop - borderBottom - tabHeight - highlight_header - highlight_margin; |
825 else | 804 // Draw highlight margin |
826 { | 805 if (highlight_margin > 0) { |
827 if (vertical) | 806 int[] shape = null; |
828 { | 807 if (onBottom) { |
829 if (onBottom) | 808 int x1 = borderLeft; |
830 { | 809 int y1 = borderTop; |
831 int pos = 0; | 810 int x2 = size.x - borderRight; |
832 if (percents[percents.length - 1] < 100) | 811 int y2 = size.y - borderBottom - tabHeight - highlight_header; |
833 { | 812 shape = [x1,y1, x2,y1, x2,y2, x2-highlight_margin,y2, |
834 pos = percents[percents.length - 1] * height / 100; | 813 x2-highlight_margin, y1+highlight_margin, x1+highlight_margin,y1+highlight_margin, |
835 gc.setBackground(defaultBackground); | 814 x1+highlight_margin,y2, x1,y2]; |
836 gc.fillRectangle(x, y, width, pos); | 815 } else { |
816 int x1 = borderLeft; | |
817 int y1 = borderTop + tabHeight + highlight_header; | |
818 int x2 = size.x - borderRight; | |
819 int y2 = size.y - borderBottom; | |
820 shape = [x1,y1, x1+highlight_margin,y1, x1+highlight_margin,y2-highlight_margin, | |
821 x2-highlight_margin,y2-highlight_margin, x2-highlight_margin,y1, | |
822 x2,y1, x2,y2, x1,y2]; | |
823 } | |
824 // If horizontal gradient, show gradient across the whole area | |
825 if (selectedIndex !is -1 && selectionGradientColors !is null && selectionGradientColors.length > 1 && !selectionGradientVertical) { | |
826 drawBackground(gc, shape, true); | |
827 } else if (selectedIndex is -1 && gradientColors !is null && gradientColors.length > 1 && !gradientVertical) { | |
828 drawBackground(gc, shape, false); | |
829 } else { | |
830 gc.setBackground(selectedIndex is -1 ? getBackground() : selectionBackground); | |
831 gc.fillPolygon(shape); | |
832 } | |
833 } | |
834 //Draw client area | |
835 if ((getStyle() & DWT.NO_BACKGROUND) !is 0) { | |
836 gc.setBackground(getBackground()); | |
837 gc.fillRectangle(xClient - marginWidth, yClient - marginHeight, width, height); | |
838 } | |
839 } else { | |
840 if ((getStyle() & DWT.NO_BACKGROUND) !is 0) { | |
841 int height = borderTop + tabHeight + highlight_header + borderBottom; | |
842 if (size.y > height) { | |
843 gc.setBackground(getParent().getBackground()); | |
844 gc.fillRectangle(0, height, size.x, size.y - height); | |
845 } | |
846 } | |
847 } | |
848 | |
849 //draw 1 pixel border around outside | |
850 if (borderLeft > 0) { | |
851 gc.setForeground(borderColor); | |
852 int x1 = borderLeft - 1; | |
853 int x2 = size.x - borderRight; | |
854 int y1 = onBottom ? borderTop - 1 : borderTop + tabHeight; | |
855 int y2 = onBottom ? size.y - tabHeight - borderBottom - 1 : size.y - borderBottom; | |
856 gc.drawLine(x1, y1, x1, y2); // left | |
857 gc.drawLine(x2, y1, x2, y2); // right | |
858 if (onBottom) { | |
859 gc.drawLine(x1, y1, x2, y1); // top | |
860 } else { | |
861 gc.drawLine(x1, y2, x2, y2); // bottom | |
862 } | |
863 } | |
864 } | |
865 | |
866 void drawChevron(GC gc) { | |
867 if (chevronRect.width is 0 || chevronRect.height is 0) return; | |
868 // draw chevron (10x7) | |
869 Display display = getDisplay(); | |
870 Point dpi = display.getDPI(); | |
871 int fontHeight = 72 * 10 / dpi.y; | |
872 FontData fd = getFont().getFontData()[0]; | |
873 fd.setHeight(fontHeight); | |
874 Font f = new Font(display, fd); | |
875 int fHeight = f.getFontData()[0].getHeight() * dpi.y / 72; | |
876 int indent = Math.max(2, (chevronRect.height - fHeight - 4) /2); | |
877 int x = chevronRect.x + 2; | |
878 int y = chevronRect.y + indent; | |
879 int count; | |
880 if (single) { | |
881 count = selectedIndex is -1 ? items.length : items.length - 1; | |
882 } else { | |
883 int showCount = 0; | |
884 while (showCount < priority.length && items[priority[showCount]].showing) { | |
885 showCount++; | |
886 } | |
887 count = items.length - showCount; | |
888 } | |
889 String chevronString = count > 99 ? "99+" : to!(String)(count); //$NON-NLS-1$ | |
890 switch (chevronImageState) { | |
891 case NORMAL: { | |
892 Color chevronBorder = single ? getSelectionForeground() : getForeground(); | |
893 gc.setForeground(chevronBorder); | |
894 gc.setFont(f); | |
895 gc.drawLine(x,y, x+2,y+2); | |
896 gc.drawLine(x+2,y+2, x,y+4); | |
897 gc.drawLine(x+1,y, x+3,y+2); | |
898 gc.drawLine(x+3,y+2, x+1,y+4); | |
899 gc.drawLine(x+4,y, x+6,y+2); | |
900 gc.drawLine(x+6,y+2, x+5,y+4); | |
901 gc.drawLine(x+5,y, x+7,y+2); | |
902 gc.drawLine(x+7,y+2, x+4,y+4); | |
903 gc.drawString(chevronString, x+7, y+3, true); | |
904 break; | |
905 } | |
906 case HOT: { | |
907 gc.setForeground(display.getSystemColor(BUTTON_BORDER)); | |
908 gc.setBackground(display.getSystemColor(BUTTON_FILL)); | |
909 gc.setFont(f); | |
910 gc.fillRoundRectangle(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, 6, 6); | |
911 gc.drawRoundRectangle(chevronRect.x, chevronRect.y, chevronRect.width - 1, chevronRect.height - 1, 6, 6); | |
912 gc.drawLine(x,y, x+2,y+2); | |
913 gc.drawLine(x+2,y+2, x,y+4); | |
914 gc.drawLine(x+1,y, x+3,y+2); | |
915 gc.drawLine(x+3,y+2, x+1,y+4); | |
916 gc.drawLine(x+4,y, x+6,y+2); | |
917 gc.drawLine(x+6,y+2, x+5,y+4); | |
918 gc.drawLine(x+5,y, x+7,y+2); | |
919 gc.drawLine(x+7,y+2, x+4,y+4); | |
920 gc.drawString(chevronString, x+7, y+3, true); | |
921 break; | |
922 } | |
923 case SELECTED: { | |
924 gc.setForeground(display.getSystemColor(BUTTON_BORDER)); | |
925 gc.setBackground(display.getSystemColor(BUTTON_FILL)); | |
926 gc.setFont(f); | |
927 gc.fillRoundRectangle(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, 6, 6); | |
928 gc.drawRoundRectangle(chevronRect.x, chevronRect.y, chevronRect.width - 1, chevronRect.height - 1, 6, 6); | |
929 gc.drawLine(x+1,y+1, x+3,y+3); | |
930 gc.drawLine(x+3,y+3, x+1,y+5); | |
931 gc.drawLine(x+2,y+1, x+4,y+3); | |
932 gc.drawLine(x+4,y+3, x+2,y+5); | |
933 gc.drawLine(x+5,y+1, x+7,y+3); | |
934 gc.drawLine(x+7,y+3, x+6,y+5); | |
935 gc.drawLine(x+6,y+1, x+8,y+3); | |
936 gc.drawLine(x+8,y+3, x+5,y+5); | |
937 gc.drawString(chevronString, x+8, y+4, true); | |
938 break; | |
939 } | |
940 default: | |
941 } | |
942 f.dispose(); | |
943 } | |
944 void drawMaximize(GC gc) { | |
945 if (maxRect.width is 0 || maxRect.height is 0) return; | |
946 Display display = getDisplay(); | |
947 // 5x4 or 7x9 | |
948 int x = maxRect.x + (CTabFolder.BUTTON_SIZE - 10)/2; | |
949 int y = maxRect.y + 3; | |
950 | |
951 gc.setForeground(display.getSystemColor(BUTTON_BORDER)); | |
952 gc.setBackground(display.getSystemColor(BUTTON_FILL)); | |
953 | |
954 switch (maxImageState) { | |
955 case NORMAL: { | |
956 if (!maximized) { | |
957 gc.fillRectangle(x, y, 9, 9); | |
958 gc.drawRectangle(x, y, 9, 9); | |
959 gc.drawLine(x+1, y+2, x+8, y+2); | |
960 } else { | |
961 gc.fillRectangle(x, y+3, 5, 4); | |
962 gc.fillRectangle(x+2, y, 5, 4); | |
963 gc.drawRectangle(x, y+3, 5, 4); | |
964 gc.drawRectangle(x+2, y, 5, 4); | |
965 gc.drawLine(x+3, y+1, x+6, y+1); | |
966 gc.drawLine(x+1, y+4, x+4, y+4); | |
967 } | |
968 break; | |
969 } | |
970 case HOT: { | |
971 gc.fillRoundRectangle(maxRect.x, maxRect.y, maxRect.width, maxRect.height, 6, 6); | |
972 gc.drawRoundRectangle(maxRect.x, maxRect.y, maxRect.width - 1, maxRect.height - 1, 6, 6); | |
973 if (!maximized) { | |
974 gc.fillRectangle(x, y, 9, 9); | |
975 gc.drawRectangle(x, y, 9, 9); | |
976 gc.drawLine(x+1, y+2, x+8, y+2); | |
977 } else { | |
978 gc.fillRectangle(x, y+3, 5, 4); | |
979 gc.fillRectangle(x+2, y, 5, 4); | |
980 gc.drawRectangle(x, y+3, 5, 4); | |
981 gc.drawRectangle(x+2, y, 5, 4); | |
982 gc.drawLine(x+3, y+1, x+6, y+1); | |
983 gc.drawLine(x+1, y+4, x+4, y+4); | |
984 } | |
985 break; | |
986 } | |
987 case SELECTED: { | |
988 gc.fillRoundRectangle(maxRect.x, maxRect.y, maxRect.width, maxRect.height, 6, 6); | |
989 gc.drawRoundRectangle(maxRect.x, maxRect.y, maxRect.width - 1, maxRect.height - 1, 6, 6); | |
990 if (!maximized) { | |
991 gc.fillRectangle(x+1, y+1, 9, 9); | |
992 gc.drawRectangle(x+1, y+1, 9, 9); | |
993 gc.drawLine(x+2, y+3, x+9, y+3); | |
994 } else { | |
995 gc.fillRectangle(x+1, y+4, 5, 4); | |
996 gc.fillRectangle(x+3, y+1, 5, 4); | |
997 gc.drawRectangle(x+1, y+4, 5, 4); | |
998 gc.drawRectangle(x+3, y+1, 5, 4); | |
999 gc.drawLine(x+4, y+2, x+7, y+2); | |
1000 gc.drawLine(x+2, y+5, x+5, y+5); | |
1001 } | |
1002 break; | |
1003 } | |
1004 default: | |
1005 } | |
1006 } | |
1007 void drawMinimize(GC gc) { | |
1008 if (minRect.width is 0 || minRect.height is 0) return; | |
1009 Display display = getDisplay(); | |
1010 // 5x4 or 9x3 | |
1011 int x = minRect.x + (BUTTON_SIZE - 10)/2; | |
1012 int y = minRect.y + 3; | |
1013 | |
1014 gc.setForeground(display.getSystemColor(BUTTON_BORDER)); | |
1015 gc.setBackground(display.getSystemColor(BUTTON_FILL)); | |
1016 | |
1017 switch (minImageState) { | |
1018 case NORMAL: { | |
1019 if (!minimized) { | |
1020 gc.fillRectangle(x, y, 9, 3); | |
1021 gc.drawRectangle(x, y, 9, 3); | |
1022 } else { | |
1023 gc.fillRectangle(x, y+3, 5, 4); | |
1024 gc.fillRectangle(x+2, y, 5, 4); | |
1025 gc.drawRectangle(x, y+3, 5, 4); | |
1026 gc.drawRectangle(x+2, y, 5, 4); | |
1027 gc.drawLine(x+3, y+1, x+6, y+1); | |
1028 gc.drawLine(x+1, y+4, x+4, y+4); | |
1029 } | |
1030 break; | |
1031 } | |
1032 case HOT: { | |
1033 gc.fillRoundRectangle(minRect.x, minRect.y, minRect.width, minRect.height, 6, 6); | |
1034 gc.drawRoundRectangle(minRect.x, minRect.y, minRect.width - 1, minRect.height - 1, 6, 6); | |
1035 if (!minimized) { | |
1036 gc.fillRectangle(x, y, 9, 3); | |
1037 gc.drawRectangle(x, y, 9, 3); | |
1038 } else { | |
1039 gc.fillRectangle(x, y+3, 5, 4); | |
1040 gc.fillRectangle(x+2, y, 5, 4); | |
1041 gc.drawRectangle(x, y+3, 5, 4); | |
1042 gc.drawRectangle(x+2, y, 5, 4); | |
1043 gc.drawLine(x+3, y+1, x+6, y+1); | |
1044 gc.drawLine(x+1, y+4, x+4, y+4); | |
1045 } | |
1046 break; | |
1047 } | |
1048 case SELECTED: { | |
1049 gc.fillRoundRectangle(minRect.x, minRect.y, minRect.width, minRect.height, 6, 6); | |
1050 gc.drawRoundRectangle(minRect.x, minRect.y, minRect.width - 1, minRect.height - 1, 6, 6); | |
1051 if (!minimized) { | |
1052 gc.fillRectangle(x+1, y+1, 9, 3); | |
1053 gc.drawRectangle(x+1, y+1, 9, 3); | |
1054 } else { | |
1055 gc.fillRectangle(x+1, y+4, 5, 4); | |
1056 gc.fillRectangle(x+3, y+1, 5, 4); | |
1057 gc.drawRectangle(x+1, y+4, 5, 4); | |
1058 gc.drawRectangle(x+3, y+1, 5, 4); | |
1059 gc.drawLine(x+4, y+2, x+7, y+2); | |
1060 gc.drawLine(x+2, y+5, x+5, y+5); | |
1061 } | |
1062 break; | |
1063 } | |
1064 default: | |
1065 } | |
1066 } | |
1067 void drawTabArea(Event event) { | |
1068 GC gc = event.gc; | |
1069 Point size = getSize(); | |
1070 int[] shape = null; | |
1071 | |
1072 if (tabHeight is 0) { | |
1073 int style = getStyle(); | |
1074 if ((style & DWT.FLAT) !is 0 && (style & DWT.BORDER) is 0) return; | |
1075 int x1 = borderLeft - 1; | |
1076 int x2 = size.x - borderRight; | |
1077 int y1 = onBottom ? size.y - borderBottom - highlight_header - 1 : borderTop + highlight_header; | |
1078 int y2 = onBottom ? size.y - borderBottom : borderTop; | |
1079 if (borderLeft > 0 && onBottom) y2 -= 1; | |
1080 | |
1081 shape = [x1, y1, x1,y2, x2,y2, x2,y1]; | |
1082 | |
1083 // If horizontal gradient, show gradient across the whole area | |
1084 if (selectedIndex !is -1 && selectionGradientColors !is null && selectionGradientColors.length > 1 && !selectionGradientVertical) { | |
1085 drawBackground(gc, shape, true); | |
1086 } else if (selectedIndex is -1 && gradientColors !is null && gradientColors.length > 1 && !gradientVertical) { | |
1087 drawBackground(gc, shape, false); | |
1088 } else { | |
1089 gc.setBackground(selectedIndex is -1 ? getBackground() : selectionBackground); | |
1090 gc.fillPolygon(shape); | |
1091 } | |
1092 | |
1093 //draw 1 pixel border | |
1094 if (borderLeft > 0) { | |
1095 gc.setForeground(borderColor); | |
1096 gc.drawPolyline(shape); | |
1097 } | |
1098 return; | |
1099 } | |
1100 | |
1101 int x = Math.max(0, borderLeft - 1); | |
1102 int y = onBottom ? size.y - borderBottom - tabHeight : borderTop; | |
1103 int width = size.x - borderLeft - borderRight + 1; | |
1104 int height = tabHeight - 1; | |
1105 | |
1106 // Draw Tab Header | |
1107 if (onBottom) { | |
1108 int[] left, right; | |
1109 if ((getStyle() & DWT.BORDER) !is 0) { | |
1110 left = simple ? SIMPLE_BOTTOM_LEFT_CORNER : BOTTOM_LEFT_CORNER; | |
1111 right = simple ? SIMPLE_BOTTOM_RIGHT_CORNER : BOTTOM_RIGHT_CORNER; | |
1112 } else { | |
1113 left = simple ? SIMPLE_BOTTOM_LEFT_CORNER_BORDERLESS : BOTTOM_LEFT_CORNER_BORDERLESS; | |
1114 right = simple ? SIMPLE_BOTTOM_RIGHT_CORNER_BORDERLESS : BOTTOM_RIGHT_CORNER_BORDERLESS; | |
1115 } | |
1116 shape = new int[left.length + right.length + 4]; | |
1117 int index = 0; | |
1118 shape[index++] = x; | |
1119 shape[index++] = y-highlight_header; | |
1120 for (int i = 0; i < left.length/2; i++) { | |
1121 shape[index++] = x+left[2*i]; | |
1122 shape[index++] = y+height+left[2*i+1]; | |
1123 if (borderLeft is 0) shape[index-1] += 1; | |
1124 } | |
1125 for (int i = 0; i < right.length/2; i++) { | |
1126 shape[index++] = x+width+right[2*i]; | |
1127 shape[index++] = y+height+right[2*i+1]; | |
1128 if (borderLeft is 0) shape[index-1] += 1; | |
1129 } | |
1130 shape[index++] = x+width; | |
1131 shape[index++] = y-highlight_header; | |
1132 } else { | |
1133 int[] left, right; | |
1134 if ((getStyle() & DWT.BORDER) !is 0) { | |
1135 left = simple ? SIMPLE_TOP_LEFT_CORNER : TOP_LEFT_CORNER; | |
1136 right = simple ? SIMPLE_TOP_RIGHT_CORNER : TOP_RIGHT_CORNER; | |
1137 } else { | |
1138 left = simple ? SIMPLE_TOP_LEFT_CORNER_BORDERLESS : TOP_LEFT_CORNER_BORDERLESS; | |
1139 right = simple ? SIMPLE_TOP_RIGHT_CORNER_BORDERLESS : TOP_RIGHT_CORNER_BORDERLESS; | |
1140 } | |
1141 shape = new int[left.length + right.length + 4]; | |
1142 int index = 0; | |
1143 shape[index++] = x; | |
1144 shape[index++] = y+height+highlight_header + 1; | |
1145 for (int i = 0; i < left.length/2; i++) { | |
1146 shape[index++] = x+left[2*i]; | |
1147 shape[index++] = y+left[2*i+1]; | |
1148 } | |
1149 for (int i = 0; i < right.length/2; i++) { | |
1150 shape[index++] = x+width+right[2*i]; | |
1151 shape[index++] = y+right[2*i+1]; | |
1152 } | |
1153 shape[index++] = x+width; | |
1154 shape[index++] = y+height+highlight_header + 1; | |
1155 } | |
1156 // Fill in background | |
1157 bool bkSelected = single && selectedIndex !is -1; | |
1158 drawBackground(gc, shape, bkSelected); | |
1159 // Fill in parent background for non-rectangular shape | |
1160 Region r = new Region(); | |
1161 r.add(new Rectangle(x, y, width + 1, height + 1)); | |
1162 r.subtract(shape); | |
1163 gc.setBackground(getParent().getBackground()); | |
1164 fillRegion(gc, r); | |
1165 r.dispose(); | |
1166 | |
1167 // Draw the unselected tabs. | |
1168 if (!single) { | |
1169 for (int i=0; i < items.length; i++) { | |
1170 if (i !is selectedIndex && event.getBounds().intersects(items[i].getBounds())) { | |
1171 items[i].onPaint(gc, false); | |
1172 } | |
1173 } | |
1174 } | |
1175 | |
1176 // Draw selected tab | |
1177 if (selectedIndex !is -1) { | |
1178 CTabItem item = items[selectedIndex]; | |
1179 item.onPaint(gc, true); | |
1180 } else { | |
1181 // if no selected tab - draw line across bottom of all tabs | |
1182 int x1 = borderLeft; | |
1183 int y1 = (onBottom) ? size.y - borderBottom - tabHeight - 1 : borderTop + tabHeight; | |
1184 int x2 = size.x - borderRight; | |
1185 gc.setForeground(borderColor); | |
1186 gc.drawLine(x1, y1, x2, y1); | |
1187 } | |
1188 | |
1189 // Draw Buttons | |
1190 drawChevron(gc); | |
1191 drawMinimize(gc); | |
1192 drawMaximize(gc); | |
1193 | |
1194 // Draw border line | |
1195 if (borderLeft > 0) { | |
1196 RGB outside = getParent().getBackground().getRGB(); | |
1197 antialias(shape, borderColor.getRGB(), null, outside, gc); | |
1198 gc.setForeground(borderColor); | |
1199 gc.drawPolyline(shape); | |
1200 } | |
1201 } | |
1202 /** | |
1203 * Returns <code>true</code> if the receiver's border is visible. | |
1204 * | |
1205 * @return the receiver's border visibility state | |
1206 * | |
1207 * @exception DWTException <ul> | |
1208 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1209 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1210 * </ul> | |
1211 * | |
1212 * @since 3.0 | |
1213 */ | |
1214 public bool getBorderVisible() { | |
1215 checkWidget(); | |
1216 return borderLeft is 1; | |
1217 } | |
1218 public override Rectangle getClientArea() { | |
1219 checkWidget(); | |
1220 if (minimized) return new Rectangle(xClient, yClient, 0, 0); | |
1221 Point size = getSize(); | |
1222 int width = size.x - borderLeft - borderRight - 2*marginWidth - 2*highlight_margin; | |
1223 int height = size.y - borderTop - borderBottom - 2*marginHeight - highlight_margin - highlight_header; | |
1224 height -= tabHeight; | |
1225 return new Rectangle(xClient, yClient, width, height); | |
1226 } | |
1227 /** | |
1228 * Return the tab that is located at the specified index. | |
1229 * | |
1230 * @param index the index of the tab item | |
1231 * @return the item at the specified index | |
1232 * | |
1233 * @exception IllegalArgumentException <ul> | |
1234 * <li>ERROR_INVALID_RANGE - if the index is out of range</li> | |
1235 * </ul> | |
1236 * @exception DWTException <ul> | |
1237 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1238 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1239 * </ul> | |
1240 */ | |
1241 public CTabItem getItem (int index) { | |
1242 //checkWidget(); | |
1243 if (index < 0 || index >= items.length) | |
1244 DWT.error(DWT.ERROR_INVALID_RANGE); | |
1245 return items [index]; | |
1246 } | |
1247 /** | |
1248 * Gets the item at a point in the widget. | |
1249 * | |
1250 * @param pt the point in coordinates relative to the CTabFolder | |
1251 * @return the item at a point or null | |
1252 * | |
1253 * @exception DWTException <ul> | |
1254 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1255 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1256 * </ul> | |
1257 */ | |
1258 public CTabItem getItem (Point pt) { | |
1259 //checkWidget(); | |
1260 if (items.length is 0) return null; | |
1261 Point size = getSize(); | |
1262 if (size.x <= borderLeft + borderRight) return null; | |
1263 if (showChevron && chevronRect.contains(pt)) return null; | |
1264 for (int i = 0; i < priority.length; i++) { | |
1265 CTabItem item = items[priority[i]]; | |
1266 Rectangle rect = item.getBounds(); | |
1267 if (rect.contains(pt)) return item; | |
1268 } | |
1269 return null; | |
1270 } | |
1271 /** | |
1272 * Return the number of tabs in the folder. | |
1273 * | |
1274 * @return the number of tabs in the folder | |
1275 * | |
1276 * @exception DWTException <ul> | |
1277 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1278 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1279 * </ul> | |
1280 */ | |
1281 public int getItemCount(){ | |
1282 //checkWidget(); | |
1283 return items.length; | |
1284 } | |
1285 /** | |
1286 * Return the tab items. | |
1287 * | |
1288 * @return the tab items | |
1289 * | |
1290 * @exception DWTException <ul> | |
1291 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1292 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1293 * </ul> | |
1294 */ | |
1295 public CTabItem [] getItems() { | |
1296 //checkWidget(); | |
1297 CTabItem[] tabItems = new CTabItem [items.length]; | |
1298 System.arraycopy(items, 0, tabItems, 0, items.length); | |
1299 return tabItems; | |
1300 } | |
1301 /* | |
1302 * Return the lowercase of the first non-'&' character following | |
1303 * an '&' character in the given string. If there are no '&' | |
1304 * characters in the given string, return '\0'. | |
1305 */ | |
1306 dchar _findMnemonic (String string) { | |
1307 if (string is null) return '\0'; | |
1308 int index = 0; | |
1309 int length_ = string.length; | |
1310 do { | |
1311 while (index < length_ && string[index] !is '&') index++; | |
1312 if (++index >= length_) return '\0'; | |
1313 if (string[index] !is '&') return CharacterFirstToLower(string[index..$]); | |
1314 index++; | |
1315 } while (index < length_); | |
1316 return '\0'; | |
1317 } | |
1318 String stripMnemonic (String string) { | |
1319 int index = 0; | |
1320 int length_ = string.length; | |
1321 do { | |
1322 while ((index < length_) && (string[index] !is '&')) index++; | |
1323 if (++index >= length_) return string; | |
1324 if (string[index] !is '&') { | |
1325 return string.substring(0, index-1) ~ string.substring(index, length_); | |
1326 } | |
1327 index++; | |
1328 } while (index < length_); | |
1329 return string; | |
1330 } | |
1331 /** | |
1332 * Returns <code>true</code> if the receiver is minimized. | |
1333 * | |
1334 * @return the receiver's minimized state | |
1335 * | |
1336 * @exception DWTException <ul> | |
1337 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1338 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1339 * </ul> | |
1340 * | |
1341 * @since 3.0 | |
1342 */ | |
1343 public bool getMinimized() { | |
1344 checkWidget(); | |
1345 return minimized; | |
1346 } | |
1347 /** | |
1348 * Returns <code>true</code> if the minimize button | |
1349 * is visible. | |
1350 * | |
1351 * @return the visibility of the minimized button | |
1352 * | |
1353 * @exception DWTException <ul> | |
1354 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1355 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1356 * </ul> | |
1357 * | |
1358 * @since 3.0 | |
1359 */ | |
1360 public bool getMinimizeVisible() { | |
1361 checkWidget(); | |
1362 return showMin; | |
1363 } | |
1364 /** | |
1365 * Returns the number of characters that will | |
1366 * appear in a fully compressed tab. | |
1367 * | |
1368 * @return number of characters that will appear in a fully compressed tab | |
1369 * | |
1370 * @since 3.0 | |
1371 */ | |
1372 public int getMinimumCharacters() { | |
1373 checkWidget(); | |
1374 return minChars; | |
1375 } | |
1376 /** | |
1377 * Returns <code>true</code> if the receiver is maximized. | |
1378 * <p> | |
1379 * | |
1380 * @return the receiver's maximized state | |
1381 * | |
1382 * @exception DWTException <ul> | |
1383 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1384 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1385 * </ul> | |
1386 * | |
1387 * @since 3.0 | |
1388 */ | |
1389 public bool getMaximized() { | |
1390 checkWidget(); | |
1391 return maximized; | |
1392 } | |
1393 /** | |
1394 * Returns <code>true</code> if the maximize button | |
1395 * is visible. | |
1396 * | |
1397 * @return the visibility of the maximized button | |
1398 * | |
1399 * @exception DWTException <ul> | |
1400 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1401 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1402 * </ul> | |
1403 * | |
1404 * @since 3.0 | |
1405 */ | |
1406 public bool getMaximizeVisible() { | |
1407 checkWidget(); | |
1408 return showMax; | |
1409 } | |
1410 /** | |
1411 * Returns <code>true</code> if the receiver displays most | |
1412 * recently used tabs and <code>false</code> otherwise. | |
1413 * <p> | |
1414 * When there is not enough horizontal space to show all the tabs, | |
1415 * by default, tabs are shown sequentially from left to right in | |
1416 * order of their index. When the MRU visibility is turned on, | |
1417 * the tabs that are visible will be the tabs most recently selected. | |
1418 * Tabs will still maintain their left to right order based on index | |
1419 * but only the most recently selected tabs are visible. | |
1420 * <p> | |
1421 * For example, consider a CTabFolder that contains "Tab 1", "Tab 2", | |
1422 * "Tab 3" and "Tab 4" (in order by index). The user selects | |
1423 * "Tab 1" and then "Tab 3". If the CTabFolder is now | |
1424 * compressed so that only two tabs are visible, by default, | |
1425 * "Tab 2" and "Tab 3" will be shown ("Tab 3" since it is currently | |
1426 * selected and "Tab 2" because it is the previous item in index order). | |
1427 * If MRU visibility is enabled, the two visible tabs will be "Tab 1" | |
1428 * and "Tab 3" (in that order from left to right).</p> | |
1429 * | |
1430 * @return the receiver's header's visibility state | |
1431 * | |
1432 * @exception DWTException <ul> | |
1433 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1434 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1435 * </ul> | |
1436 * | |
1437 * @since 3.1 | |
1438 */ | |
1439 public bool getMRUVisible() { | |
1440 checkWidget(); | |
1441 return mru; | |
1442 } | |
1443 int getRightItemEdge (){ | |
1444 int x = getSize().x - borderRight - 3; | |
1445 if (showMin) x -= BUTTON_SIZE; | |
1446 if (showMax) x -= BUTTON_SIZE; | |
1447 if (showChevron) x -= 3*BUTTON_SIZE/2; | |
1448 if (topRight !is null && topRightAlignment !is DWT.FILL) { | |
1449 Point rightSize = topRight.computeSize(DWT.DEFAULT, DWT.DEFAULT); | |
1450 x -= rightSize.x + 3; | |
1451 } | |
1452 return Math.max(0, x); | |
1453 } | |
1454 /** | |
1455 * Return the selected tab item, or null if there is no selection. | |
1456 * | |
1457 * @return the selected tab item, or null if none has been selected | |
1458 * | |
1459 * @exception DWTException <ul> | |
1460 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1461 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1462 * </ul> | |
1463 */ | |
1464 public CTabItem getSelection() { | |
1465 //checkWidget(); | |
1466 if (selectedIndex is -1) return null; | |
1467 return items[selectedIndex]; | |
1468 } | |
1469 /** | |
1470 * Returns the receiver's selection background color. | |
1471 * | |
1472 * @return the selection background color of the receiver | |
1473 * | |
1474 * @exception DWTException <ul> | |
1475 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1476 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1477 * </ul> | |
1478 * | |
1479 * @since 3.0 | |
1480 */ | |
1481 public Color getSelectionBackground() { | |
1482 checkWidget(); | |
1483 return selectionBackground; | |
1484 } | |
1485 /** | |
1486 * Returns the receiver's selection foreground color. | |
1487 * | |
1488 * @return the selection foreground color of the receiver | |
1489 * | |
1490 * @exception DWTException <ul> | |
1491 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1492 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1493 * </ul> | |
1494 * | |
1495 * @since 3.0 | |
1496 */ | |
1497 public Color getSelectionForeground() { | |
1498 checkWidget(); | |
1499 return selectionForeground; | |
1500 } | |
1501 /** | |
1502 * Return the index of the selected tab item, or -1 if there | |
1503 * is no selection. | |
1504 * | |
1505 * @return the index of the selected tab item or -1 | |
1506 * | |
1507 * @exception DWTException <ul> | |
1508 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1509 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1510 * </ul> | |
1511 */ | |
1512 public int getSelectionIndex() { | |
1513 //checkWidget(); | |
1514 return selectedIndex; | |
1515 } | |
1516 /** | |
1517 * Returns <code>true</code> if the CTabFolder is rendered | |
1518 * with a simple, traditional shape. | |
1519 * | |
1520 * @return <code>true</code> if the CTabFolder is rendered with a simple shape | |
1521 * | |
1522 * @since 3.0 | |
1523 */ | |
1524 public bool getSimple() { | |
1525 checkWidget(); | |
1526 return simple; | |
1527 } | |
1528 /** | |
1529 * Returns <code>true</code> if the CTabFolder only displays the selected tab | |
1530 * and <code>false</code> if the CTabFolder displays multiple tabs. | |
1531 * | |
1532 * @return <code>true</code> if the CTabFolder only displays the selected tab and <code>false</code> if the CTabFolder displays multiple tabs | |
1533 * | |
1534 * @since 3.0 | |
1535 */ | |
1536 public bool getSingle() { | |
1537 checkWidget(); | |
1538 return single; | |
1539 } | |
1540 | |
1541 public override int getStyle() { | |
1542 int style = super.getStyle(); | |
1543 style &= ~(DWT.TOP | DWT.BOTTOM); | |
1544 style |= onBottom ? DWT.BOTTOM : DWT.TOP; | |
1545 style &= ~(DWT.SINGLE | DWT.MULTI); | |
1546 style |= single ? DWT.SINGLE : DWT.MULTI; | |
1547 if (borderLeft !is 0) style |= DWT.BORDER; | |
1548 style &= ~DWT.CLOSE; | |
1549 if (showClose) style |= DWT.CLOSE; | |
1550 return style; | |
1551 } | |
1552 /** | |
1553 * Returns the height of the tab | |
1554 * | |
1555 * @return the height of the tab | |
1556 * | |
1557 * @exception DWTException <ul> | |
1558 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1559 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1560 * </ul> | |
1561 */ | |
1562 public int getTabHeight(){ | |
1563 checkWidget(); | |
1564 if (fixedTabHeight !is DWT.DEFAULT) return fixedTabHeight; | |
1565 return tabHeight - 1; // -1 for line drawn across top of tab | |
1566 } | |
1567 /** | |
1568 * Returns the position of the tab. Possible values are DWT.TOP or DWT.BOTTOM. | |
1569 * | |
1570 * @return the position of the tab | |
1571 * | |
1572 * @exception DWTException <ul> | |
1573 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1574 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1575 * </ul> | |
1576 */ | |
1577 public int getTabPosition(){ | |
1578 checkWidget(); | |
1579 return onBottom ? DWT.BOTTOM : DWT.TOP; | |
1580 } | |
1581 /** | |
1582 * Returns the control in the top right corner of the tab folder. | |
1583 * Typically this is a close button or a composite with a menu and close button. | |
1584 * | |
1585 * @return the control in the top right corner of the tab folder or null | |
1586 * | |
1587 * @exception DWTException <ul> | |
1588 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1589 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1590 * </ul> | |
1591 * | |
1592 * @since 2.1 | |
1593 */ | |
1594 public Control getTopRight() { | |
1595 checkWidget(); | |
1596 return topRight; | |
1597 } | |
1598 /** | |
1599 * Returns <code>true</code> if the close button appears | |
1600 * when the user hovers over an unselected tabs. | |
1601 * | |
1602 * @return <code>true</code> if the close button appears on unselected tabs | |
1603 * | |
1604 * @since 3.0 | |
1605 */ | |
1606 public bool getUnselectedCloseVisible() { | |
1607 checkWidget(); | |
1608 return showUnselectedClose; | |
1609 } | |
1610 /** | |
1611 * Returns <code>true</code> if an image appears | |
1612 * in unselected tabs. | |
1613 * | |
1614 * @return <code>true</code> if an image appears in unselected tabs | |
1615 * | |
1616 * @since 3.0 | |
1617 */ | |
1618 public bool getUnselectedImageVisible() { | |
1619 checkWidget(); | |
1620 return showUnselectedImage; | |
1621 } | |
1622 /** | |
1623 * Return the index of the specified tab or -1 if the tab is not | |
1624 * in the receiver. | |
1625 * | |
1626 * @param item the tab item for which the index is required | |
1627 * | |
1628 * @return the index of the specified tab item or -1 | |
1629 * | |
1630 * @exception IllegalArgumentException <ul> | |
1631 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
1632 * </ul> | |
1633 * | |
1634 * @exception DWTException <ul> | |
1635 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1636 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1637 * </ul> | |
1638 */ | |
1639 public int indexOf(CTabItem item) { | |
1640 checkWidget(); | |
1641 if (item is null) { | |
1642 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
1643 } | |
1644 for (int i = 0; i < items.length; i++) { | |
1645 if (items[i] is item) return i; | |
1646 } | |
1647 return -1; | |
1648 } | |
1649 void initAccessible() { | |
1650 Accessible accessible = getAccessible(); | |
1651 accessible.addAccessibleListener(new class() AccessibleAdapter { | |
1652 public void getName(AccessibleEvent e) { | |
1653 String name = null; | |
1654 int childID = e.childID; | |
1655 if (childID >= 0 && childID < items.length) { | |
1656 name = stripMnemonic(items[childID].getText()); | |
1657 } else if (childID is items.length + CHEVRON_CHILD_ID) { | |
1658 name = DWT.getMessage("SWT_ShowList"); //$NON-NLS-1$ | |
1659 } else if (childID is items.length + MINIMIZE_CHILD_ID) { | |
1660 name = minimized ? DWT.getMessage("SWT_Restore") : DWT.getMessage("SWT_Minimize"); //$NON-NLS-1$ //$NON-NLS-2$ | |
1661 } else if (childID is items.length + MAXIMIZE_CHILD_ID) { | |
1662 name = maximized ? DWT.getMessage("SWT_Restore") : DWT.getMessage("SWT_Maximize"); //$NON-NLS-1$ //$NON-NLS-2$ | |
1663 } | |
1664 e.result = name; | |
1665 } | |
1666 | |
1667 public void getHelp(AccessibleEvent e) { | |
1668 String help = null; | |
1669 int childID = e.childID; | |
1670 if (childID is ACC.CHILDID_SELF) { | |
1671 help = getToolTipText(); | |
1672 } else if (childID >= 0 && childID < items.length) { | |
1673 help = items[childID].getToolTipText(); | |
1674 } | |
1675 e.result = help; | |
1676 } | |
1677 | |
1678 public void getKeyboardShortcut(AccessibleEvent e) { | |
1679 String shortcut = null; | |
1680 int childID = e.childID; | |
1681 if (childID >= 0 && childID < items.length) { | |
1682 String text = items[childID].getText(); | |
1683 if (text !is null) { | |
1684 dchar mnemonic = _findMnemonic(text); | |
1685 if (mnemonic !is '\0') { | |
1686 shortcut = "Alt+"~tango.text.convert.Utf.toString([mnemonic]); //$NON-NLS-1$ | |
1687 } | |
1688 } | |
1689 } | |
1690 e.result = shortcut; | |
1691 } | |
1692 }); | |
1693 | |
1694 accessible.addAccessibleControlListener(new class() AccessibleControlAdapter { | |
1695 public void getChildAtPoint(AccessibleControlEvent e) { | |
1696 Point testPoint = toControl(e.x, e.y); | |
1697 int childID = ACC.CHILDID_NONE; | |
1698 for (int i = 0; i < items.length; i++) { | |
1699 if (items[i].getBounds().contains(testPoint)) { | |
1700 childID = i; | |
1701 break; | |
1702 } | |
1703 } | |
1704 if (childID is ACC.CHILDID_NONE) { | |
1705 if (showChevron && chevronRect.contains(testPoint)) { | |
1706 childID = items.length + CHEVRON_CHILD_ID; | |
1707 } else if (showMin && minRect.contains(testPoint)) { | |
1708 childID = items.length + MINIMIZE_CHILD_ID; | |
1709 } else if (showMax && maxRect.contains(testPoint)) { | |
1710 childID = items.length + MAXIMIZE_CHILD_ID; | |
1711 } else { | |
1712 Rectangle location = getBounds(); | |
1713 location.height = location.height - getClientArea().height; | |
1714 if (location.contains(testPoint)) { | |
1715 childID = ACC.CHILDID_SELF; | |
1716 } | |
1717 } | |
1718 } | |
1719 e.childID = childID; | |
1720 } | |
1721 | |
1722 public void getLocation(AccessibleControlEvent e) { | |
1723 Rectangle location = null; | |
1724 Point pt = null; | |
1725 int childID = e.childID; | |
1726 if (childID is ACC.CHILDID_SELF) { | |
1727 location = getBounds(); | |
1728 pt = getParent().toDisplay(location.x, location.y); | |
1729 } else { | |
1730 if (childID >= 0 && childID < items.length && items[childID].isShowing()) { | |
1731 location = items[childID].getBounds(); | |
1732 } else if (showChevron && childID is items.length + CHEVRON_CHILD_ID) { | |
1733 location = chevronRect; | |
1734 } else if (showMin && childID is items.length + MINIMIZE_CHILD_ID) { | |
1735 location = minRect; | |
1736 } else if (showMax && childID is items.length + MAXIMIZE_CHILD_ID) { | |
1737 location = maxRect; | |
1738 } | |
1739 if (location !is null) { | |
1740 pt = toDisplay(location.x, location.y); | |
1741 } | |
1742 } | |
1743 if (location !is null && pt !is null) { | |
1744 e.x = pt.x; | |
1745 e.y = pt.y; | |
1746 e.width = location.width; | |
1747 e.height = location.height; | |
1748 } | |
1749 } | |
1750 | |
1751 public void getChildCount(AccessibleControlEvent e) { | |
1752 e.detail = items.length + EXTRA_CHILD_ID_COUNT; | |
1753 } | |
1754 | |
1755 public void getDefaultAction(AccessibleControlEvent e) { | |
1756 String action = null; | |
1757 int childID = e.childID; | |
1758 if (childID >= 0 && childID < items.length) { | |
1759 action = DWT.getMessage ("SWT_Switch"); //$NON-NLS-1$ | |
1760 } | |
1761 if (childID >= items.length && childID < items.length + EXTRA_CHILD_ID_COUNT) { | |
1762 action = DWT.getMessage ("SWT_Press"); //$NON-NLS-1$ | |
1763 } | |
1764 e.result = action; | |
1765 } | |
1766 | |
1767 public void getFocus(AccessibleControlEvent e) { | |
1768 int childID = ACC.CHILDID_NONE; | |
1769 if (isFocusControl()) { | |
1770 if (selectedIndex is -1) { | |
1771 childID = ACC.CHILDID_SELF; | |
1772 } else { | |
1773 childID = selectedIndex; | |
1774 } | |
1775 } | |
1776 e.childID = childID; | |
1777 } | |
1778 | |
1779 public void getRole(AccessibleControlEvent e) { | |
1780 int role = 0; | |
1781 int childID = e.childID; | |
1782 if (childID is ACC.CHILDID_SELF) { | |
1783 role = ACC.ROLE_TABFOLDER; | |
1784 } else if (childID >= 0 && childID < items.length) { | |
1785 role = ACC.ROLE_TABITEM; | |
1786 } else if (childID >= items.length && childID < items.length + EXTRA_CHILD_ID_COUNT) { | |
1787 role = ACC.ROLE_PUSHBUTTON; | |
1788 } | |
1789 e.detail = role; | |
1790 } | |
1791 | |
1792 public void getSelection(AccessibleControlEvent e) { | |
1793 e.childID = (selectedIndex is -1) ? ACC.CHILDID_NONE : selectedIndex; | |
1794 } | |
1795 | |
1796 public void getState(AccessibleControlEvent e) { | |
1797 int state = 0; | |
1798 int childID = e.childID; | |
1799 if (childID is ACC.CHILDID_SELF) { | |
1800 state = ACC.STATE_NORMAL; | |
1801 } else if (childID >= 0 && childID < items.length) { | |
1802 state = ACC.STATE_SELECTABLE; | |
1803 if (isFocusControl()) { | |
1804 state |= ACC.STATE_FOCUSABLE; | |
1805 } | |
1806 if (selectedIndex is childID) { | |
1807 state |= ACC.STATE_SELECTED; | |
1808 if (isFocusControl()) { | |
1809 state |= ACC.STATE_FOCUSED; | |
1810 } | |
1811 } | |
1812 } else if (childID is items.length + CHEVRON_CHILD_ID) { | |
1813 state = showChevron ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; | |
1814 } else if (childID is items.length + MINIMIZE_CHILD_ID) { | |
1815 state = showMin ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; | |
1816 } else if (childID is items.length + MAXIMIZE_CHILD_ID) { | |
1817 state = showMax ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; | |
1818 } | |
1819 e.detail = state; | |
1820 } | |
1821 | |
1822 public void getChildren(AccessibleControlEvent e) { | |
1823 int childIdCount = items.length + EXTRA_CHILD_ID_COUNT; | |
1824 Object[] children = new Object[childIdCount]; | |
1825 for (int i = 0; i < childIdCount; i++) { | |
1826 children[i] = new Integer(i); | |
1827 } | |
1828 e.children = children; | |
1829 } | |
1830 }); | |
1831 | |
1832 addListener(DWT.Selection, new class(accessible) Listener { | |
1833 Accessible acc; | |
1834 this( Accessible a ){ | |
1835 this.acc = a; | |
1836 } | |
1837 public void handleEvent(Event event) { | |
1838 if (isFocusControl()) { | |
1839 if (selectedIndex is -1) { | |
1840 acc.setFocus(ACC.CHILDID_SELF); | |
1841 } else { | |
1842 acc.setFocus(selectedIndex); | |
1843 } | |
1844 } | |
1845 } | |
1846 }); | |
1847 | |
1848 addListener(DWT.FocusIn, new class(accessible) Listener { | |
1849 Accessible acc; | |
1850 this( Accessible a ){ this.acc = a; } | |
1851 public void handleEvent(Event event) { | |
1852 if (selectedIndex is -1) { | |
1853 acc.setFocus(ACC.CHILDID_SELF); | |
1854 } else { | |
1855 acc.setFocus(selectedIndex); | |
1856 } | |
1857 } | |
1858 }); | |
1859 } | |
1860 | |
1861 void onKeyDown (Event event) { | |
1862 switch (event.keyCode) { | |
1863 case DWT.ARROW_LEFT: | |
1864 case DWT.ARROW_RIGHT: | |
1865 int count = items.length; | |
1866 if (count is 0) return; | |
1867 if (selectedIndex is -1) return; | |
1868 int leadKey = (getStyle() & DWT.RIGHT_TO_LEFT) !is 0 ? DWT.ARROW_RIGHT : DWT.ARROW_LEFT; | |
1869 int offset = event.keyCode is leadKey ? -1 : 1; | |
1870 int index; | |
1871 if (!mru) { | |
1872 index = selectedIndex + offset; | |
1873 } else { | |
1874 int[] visible = new int[items.length]; | |
1875 int idx = 0; | |
1876 int current = -1; | |
1877 for (int i = 0; i < items.length; i++) { | |
1878 if (items[i].showing) { | |
1879 if (i is selectedIndex) current = idx; | |
1880 visible [idx++] = i; | |
1881 } | |
1882 } | |
1883 if (current + offset >= 0 && current + offset < idx){ | |
1884 index = visible [current + offset]; | |
1885 } else { | |
1886 if (showChevron) { | |
1887 CTabFolderEvent e = new CTabFolderEvent(this); | |
1888 e.widget = this; | |
1889 e.time = event.time; | |
1890 e.x = chevronRect.x; | |
1891 e.y = chevronRect.y; | |
1892 e.width = chevronRect.width; | |
1893 e.height = chevronRect.height; | |
1894 e.doit = true; | |
1895 for (int i = 0; i < folderListeners.length; i++) { | |
1896 folderListeners[i].showList(e); | |
837 } | 1897 } |
838 Color lastColor = colors[colors.length - 1]; | 1898 if (e.doit && !isDisposed()) { |
839 if (lastColor is null) | 1899 showList(chevronRect); |
840 lastColor = defaultBackground; | |
841 for (int i = percents.length - 1; i >= 0; i--) | |
842 { | |
843 gc.setForeground(lastColor); | |
844 lastColor = colors[i]; | |
845 if (lastColor is null) | |
846 lastColor = defaultBackground; | |
847 gc.setBackground(lastColor); | |
848 int gradientHeight = percents[i] * height / 100; | |
849 gc.fillGradientRectangle(x, y + pos, width, | |
850 gradientHeight, true); | |
851 pos += gradientHeight; | |
852 } | 1900 } |
853 } | 1901 } |
854 else | 1902 return; |
855 { | 1903 } |
856 Color lastColor = colors[0]; | 1904 } |
857 if (lastColor is null) | 1905 if (index < 0 || index >= count) return; |
858 lastColor = defaultBackground; | 1906 setSelection (index, true); |
859 int pos = 0; | 1907 forceFocus(); |
860 for (int i = 0; i < percents.length; i++) | 1908 default: |
861 { | 1909 } |
862 gc.setForeground(lastColor); | 1910 } |
863 lastColor = colors[i + 1]; | 1911 void onDispose(Event event) { |
864 if (lastColor is null) | 1912 removeListener(DWT.Dispose, listener); |
865 lastColor = defaultBackground; | 1913 notifyListeners(DWT.Dispose, event); |
866 gc.setBackground(lastColor); | 1914 event.type = DWT.None; |
867 int gradientHeight = percents[i] * height / 100; | 1915 /* |
868 gc.fillGradientRectangle(x, y + pos, width, | 1916 * Usually when an item is disposed, destroyItem will change the size of the items array, |
869 gradientHeight, true); | 1917 * reset the bounds of all the tabs and manage the widget associated with the tab. |
870 pos += gradientHeight; | 1918 * Since the whole folder is being disposed, this is not necessary. For speed |
1919 * the inDispose flag is used to skip over this part of the item dispose. | |
1920 */ | |
1921 inDispose = true; | |
1922 | |
1923 if (showMenu !is null && !showMenu.isDisposed()) { | |
1924 showMenu.dispose(); | |
1925 showMenu = null; | |
1926 } | |
1927 int length = items.length; | |
1928 for (int i = 0; i < length; i++) { | |
1929 if (items[i] !is null) { | |
1930 items[i].dispose(); | |
1931 } | |
1932 } | |
1933 | |
1934 selectionGradientColors = null; | |
1935 selectionGradientPercents = null; | |
1936 selectionBgImage = null; | |
1937 | |
1938 selectionBackground = null; | |
1939 selectionForeground = null; | |
1940 disposeSelectionHighlightGradientColors(); | |
1941 } | |
1942 void onDragDetect(Event event) { | |
1943 bool consume = false; | |
1944 if (chevronRect.contains(event.x, event.y) || | |
1945 minRect.contains(event.x, event.y) || | |
1946 maxRect.contains(event.x, event.y)){ | |
1947 consume = true; | |
1948 } else { | |
1949 for (int i = 0; i < items.length; i++) { | |
1950 if (items[i].closeRect.contains(event.x, event.y)) { | |
1951 consume = true; | |
1952 break; | |
1953 } | |
1954 } | |
1955 } | |
1956 if (consume) { | |
1957 event.type = DWT.None; | |
1958 } | |
1959 } | |
1960 void onFocus(Event event) { | |
1961 checkWidget(); | |
1962 if (selectedIndex >= 0) { | |
1963 redraw(); | |
1964 } else { | |
1965 setSelection(0, true); | |
1966 } | |
1967 } | |
1968 bool onMnemonic (Event event) { | |
1969 auto key = event.character; | |
1970 for (int i = 0; i < items.length; i++) { | |
1971 if (items[i] !is null) { | |
1972 auto mnemonic = _findMnemonic (items[i].getText ()); | |
1973 if (mnemonic !is '\0') { | |
1974 if ( CharacterToLower(key) is mnemonic) { | |
1975 setSelection(i, true); | |
1976 return true; | |
1977 } | |
1978 } | |
1979 } | |
1980 } | |
1981 return false; | |
1982 } | |
1983 void onMouseDoubleClick(Event event) { | |
1984 if (event.button !is 1 || | |
1985 (event.stateMask & DWT.BUTTON2) !is 0 || | |
1986 (event.stateMask & DWT.BUTTON3) !is 0) return; | |
1987 Event e = new Event(); | |
1988 e.item = getItem(new Point(event.x, event.y)); | |
1989 if (e.item !is null) { | |
1990 notifyListeners(DWT.DefaultSelection, e); | |
1991 } | |
1992 } | |
1993 void onMouse(Event event) { | |
1994 int x = event.x, y = event.y; | |
1995 switch (event.type) { | |
1996 case DWT.MouseEnter: { | |
1997 setToolTipText(null); | |
1998 break; | |
1999 } | |
2000 case DWT.MouseExit: { | |
2001 if (minImageState !is NORMAL) { | |
2002 minImageState = NORMAL; | |
2003 redraw(minRect.x, minRect.y, minRect.width, minRect.height, false); | |
2004 } | |
2005 if (maxImageState !is NORMAL) { | |
2006 maxImageState = NORMAL; | |
2007 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false); | |
2008 } | |
2009 if (chevronImageState !is NORMAL) { | |
2010 chevronImageState = NORMAL; | |
2011 redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false); | |
2012 } | |
2013 for (int i=0; i<items.length; i++) { | |
2014 CTabItem item = items[i]; | |
2015 if (i !is selectedIndex && item.closeImageState !is NONE) { | |
2016 item.closeImageState = NONE; | |
2017 redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false); | |
2018 } | |
2019 if (i is selectedIndex && item.closeImageState !is NORMAL) { | |
2020 item.closeImageState = NORMAL; | |
2021 redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false); | |
2022 } | |
2023 } | |
2024 break; | |
2025 } | |
2026 case DWT.MouseDown: { | |
2027 if (minRect.contains(x, y)) { | |
2028 if (event.button !is 1) return; | |
2029 minImageState = SELECTED; | |
2030 redraw(minRect.x, minRect.y, minRect.width, minRect.height, false); | |
2031 update(); | |
2032 return; | |
2033 } | |
2034 if (maxRect.contains(x, y)) { | |
2035 if (event.button !is 1) return; | |
2036 maxImageState = SELECTED; | |
2037 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false); | |
2038 update(); | |
2039 return; | |
2040 } | |
2041 if (chevronRect.contains(x, y)) { | |
2042 if (event.button !is 1) return; | |
2043 if (chevronImageState !is HOT) { | |
2044 chevronImageState = HOT; | |
2045 } else { | |
2046 chevronImageState = SELECTED; | |
2047 } | |
2048 redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false); | |
2049 update(); | |
2050 return; | |
2051 } | |
2052 CTabItem item = null; | |
2053 if (single) { | |
2054 if (selectedIndex !is -1) { | |
2055 Rectangle bounds = items[selectedIndex].getBounds(); | |
2056 if (bounds.contains(x, y)){ | |
2057 item = items[selectedIndex]; | |
2058 } | |
2059 } | |
2060 } else { | |
2061 for (int i=0; i<items.length; i++) { | |
2062 Rectangle bounds = items[i].getBounds(); | |
2063 if (bounds.contains(x, y)){ | |
2064 item = items[i]; | |
2065 } | |
2066 } | |
2067 } | |
2068 if (item !is null) { | |
2069 if (item.closeRect.contains(x,y)){ | |
2070 if (event.button !is 1) return; | |
2071 item.closeImageState = SELECTED; | |
2072 redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false); | |
2073 update(); | |
2074 return; | |
2075 } | |
2076 int index = indexOf(item); | |
2077 if (item.showing){ | |
2078 setSelection(index, true); | |
2079 } | |
2080 return; | |
2081 } | |
2082 break; | |
2083 } | |
2084 case DWT.MouseMove: { | |
2085 _setToolTipText(event.x, event.y); | |
2086 bool close = false, minimize = false, maximize = false, chevron = false; | |
2087 if (minRect.contains(x, y)) { | |
2088 minimize = true; | |
2089 if (minImageState !is SELECTED && minImageState !is HOT) { | |
2090 minImageState = HOT; | |
2091 redraw(minRect.x, minRect.y, minRect.width, minRect.height, false); | |
2092 } | |
2093 } | |
2094 if (maxRect.contains(x, y)) { | |
2095 maximize = true; | |
2096 if (maxImageState !is SELECTED && maxImageState !is HOT) { | |
2097 maxImageState = HOT; | |
2098 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false); | |
2099 } | |
2100 } | |
2101 if (chevronRect.contains(x, y)) { | |
2102 chevron = true; | |
2103 if (chevronImageState !is SELECTED && chevronImageState !is HOT) { | |
2104 chevronImageState = HOT; | |
2105 redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false); | |
2106 } | |
2107 } | |
2108 if (minImageState !is NORMAL && !minimize) { | |
2109 minImageState = NORMAL; | |
2110 redraw(minRect.x, minRect.y, minRect.width, minRect.height, false); | |
2111 } | |
2112 if (maxImageState !is NORMAL && !maximize) { | |
2113 maxImageState = NORMAL; | |
2114 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false); | |
2115 } | |
2116 if (chevronImageState !is NORMAL && !chevron) { | |
2117 chevronImageState = NORMAL; | |
2118 redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false); | |
2119 } | |
2120 for (int i=0; i<items.length; i++) { | |
2121 CTabItem item = items[i]; | |
2122 close = false; | |
2123 if (item.getBounds().contains(x, y)) { | |
2124 close = true; | |
2125 if (item.closeRect.contains(x, y)) { | |
2126 if (item.closeImageState !is SELECTED && item.closeImageState !is HOT) { | |
2127 item.closeImageState = HOT; | |
2128 redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false); | |
871 } | 2129 } |
872 if (pos < height) | 2130 } else { |
873 { | 2131 if (item.closeImageState !is NORMAL) { |
874 gc.setBackground(defaultBackground); | 2132 item.closeImageState = NORMAL; |
875 gc.fillRectangle(x, pos, width, height - pos + 1); | 2133 redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false); |
876 } | 2134 } |
877 } | 2135 } |
878 } | 2136 } |
879 else | 2137 if (i !is selectedIndex && item.closeImageState !is NONE && !close) { |
880 { //horizontal gradient | 2138 item.closeImageState = NONE; |
881 y = 0; | 2139 redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false); |
882 height = getSize().y; | 2140 } |
883 Color lastColor = colors[0]; | 2141 if (i is selectedIndex && item.closeImageState !is NORMAL && !close) { |
884 if (lastColor is null) | 2142 item.closeImageState = NORMAL; |
885 lastColor = defaultBackground; | 2143 redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false); |
886 int pos = 0; | 2144 } |
887 for (int i = 0; i < percents.length; ++i) | 2145 } |
888 { | 2146 break; |
889 gc.setForeground(lastColor); | 2147 } |
890 lastColor = colors[i + 1]; | 2148 case DWT.MouseUp: { |
891 if (lastColor is null) | 2149 if (event.button !is 1) return; |
892 lastColor = defaultBackground; | 2150 if (chevronRect.contains(x, y)) { |
893 gc.setBackground(lastColor); | 2151 bool selected = chevronImageState is SELECTED; |
894 int gradientWidth = (percents[i] * width / 100) - pos; | 2152 if (!selected) return; |
895 gc.fillGradientRectangle(x + pos, y, gradientWidth, | 2153 CTabFolderEvent e = new CTabFolderEvent(this); |
896 height, false); | 2154 e.widget = this; |
897 pos += gradientWidth; | 2155 e.time = event.time; |
2156 e.x = chevronRect.x; | |
2157 e.y = chevronRect.y; | |
2158 e.width = chevronRect.width; | |
2159 e.height = chevronRect.height; | |
2160 e.doit = true; | |
2161 for (int i = 0; i < folderListeners.length; i++) { | |
2162 folderListeners[i].showList(e); | |
2163 } | |
2164 if (e.doit && !isDisposed()) { | |
2165 showList(chevronRect); | |
2166 } | |
2167 return; | |
2168 } | |
2169 if (minRect.contains(x, y)) { | |
2170 bool selected = minImageState is SELECTED; | |
2171 minImageState = HOT; | |
2172 redraw(minRect.x, minRect.y, minRect.width, minRect.height, false); | |
2173 if (!selected) return; | |
2174 CTabFolderEvent e = new CTabFolderEvent(this); | |
2175 e.widget = this; | |
2176 e.time = event.time; | |
2177 for (int i = 0; i < folderListeners.length; i++) { | |
2178 if (minimized) { | |
2179 folderListeners[i].restore(e); | |
2180 } else { | |
2181 folderListeners[i].minimize(e); | |
898 } | 2182 } |
899 if (pos < width) | 2183 } |
900 { | 2184 return; |
901 gc.setBackground(defaultBackground); | 2185 } |
902 gc.fillRectangle(x + pos, y, width - pos, height); | 2186 if (maxRect.contains(x, y)) { |
2187 bool selected = maxImageState is SELECTED; | |
2188 maxImageState = HOT; | |
2189 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false); | |
2190 if (!selected) return; | |
2191 CTabFolderEvent e = new CTabFolderEvent(this); | |
2192 e.widget = this; | |
2193 e.time = event.time; | |
2194 for (int i = 0; i < folderListeners.length; i++) { | |
2195 if (maximized) { | |
2196 folderListeners[i].restore(e); | |
2197 } else { | |
2198 folderListeners[i].maximize(e); | |
903 } | 2199 } |
904 } | 2200 } |
905 } | |
906 } | |
907 else | |
908 { | |
909 // draw a solid background using default background in shape | |
910 if ((getStyle() & DWT.NO_BACKGROUND) !is 0 || !defaultBackground.opEquals( | |
911 getBackground())) | |
912 { | |
913 gc.setBackground(defaultBackground); | |
914 gc.fillRectangle(x, y, width, height); | |
915 } | |
916 } | |
917 gc.setClipping(clipping); | |
918 clipping.dispose(); | |
919 region.dispose(); | |
920 } | |
921 | |
922 void drawBody (Event event) | |
923 { | |
924 GC gc = event.gc; | |
925 Point size = getSize(); | |
926 | |
927 // fill in body | |
928 if (!minimized) | |
929 { | |
930 int | |
931 width = size.x - borderLeft - borderRight - 2 * highlight_margin; | |
932 int | |
933 height = size.y - borderTop - borderBottom - tabHeight - highlight_header - highlight_margin; | |
934 // Draw highlight margin | |
935 if (highlight_margin > 0) | |
936 { | |
937 int[] shape = null; | |
938 if (onBottom) | |
939 { | |
940 int x1 = borderLeft; | |
941 int y1 = borderTop; | |
942 int x2 = size.x - borderRight; | |
943 int | |
944 y2 = size.y - borderBottom - tabHeight - highlight_header; | |
945 shape = new int[][x1 , y1 , x2 , y1 , x2 , y2 , x2 - highlight_margin , y2 , x2 - highlight_margin , y1 + highlight_margin , x1 + highlight_margin , y1 + highlight_margin , x1 + highlight_margin , y2 , x1 , y2]; | |
946 } | |
947 else | |
948 { | |
949 int x1 = borderLeft; | |
950 int y1 = borderTop + tabHeight + highlight_header; | |
951 int x2 = size.x - borderRight; | |
952 int y2 = size.y - borderBottom; | |
953 shape = new int[][x1 , y1 , x1 + highlight_margin , y1 , x1 + highlight_margin , y2 - highlight_margin , x2 - highlight_margin , y2 - highlight_margin , x2 - highlight_margin , y1 , x2 , y1 , x2 , y2 , x1 , y2]; | |
954 } | |
955 // If horizontal gradient, show gradient across the whole area | |
956 if (selectedIndex !is -1 && selectionGradientColors !is null && selectionGradientColors.length > 1 && !selectionGradientVertical) | |
957 { | |
958 drawBackground(gc, shape, true); | |
959 } | |
960 else if (selectedIndex is -1 && gradientColors !is null && gradientColors.length > 1 && !gradientVertical) | |
961 { | |
962 drawBackground(gc, shape, false); | |
963 } | |
964 else | |
965 { | |
966 gc.setBackground( | |
967 selectedIndex is -1 ? getBackground() : selectionBackground); | |
968 gc.fillPolygon(shape); | |
969 } | |
970 } | |
971 //Draw client area | |
972 if ((getStyle() & DWT.NO_BACKGROUND) !is 0) | |
973 { | |
974 gc.setBackground(getBackground()); | |
975 gc.fillRectangle(xClient - marginWidth, yClient - marginHeight, | |
976 width, height); | |
977 } | |
978 } | |
979 else | |
980 { | |
981 if ((getStyle() & DWT.NO_BACKGROUND) !is 0) | |
982 { | |
983 int | |
984 height = borderTop + tabHeight + highlight_header + borderBottom; | |
985 if (size.y > height) | |
986 { | |
987 gc.setBackground(getParent().getBackground()); | |
988 gc.fillRectangle(0, height, size.x, size.y - height); | |
989 } | |
990 } | |
991 } | |
992 | |
993 //draw 1 pixel border around outside | |
994 if (borderLeft > 0) | |
995 { | |
996 gc.setForeground(borderColor); | |
997 int x1 = borderLeft - 1; | |
998 int x2 = size.x - borderRight; | |
999 int y1 = onBottom ? borderTop - 1 : borderTop + tabHeight; | |
1000 int | |
1001 y2 = onBottom ? size.y - tabHeight - borderBottom - 1 : size.y - borderBottom; | |
1002 gc.drawLine(x1, y1, x1, y2); // left | |
1003 gc.drawLine(x2, y1, x2, y2); // right | |
1004 if (onBottom) | |
1005 { | |
1006 gc.drawLine(x1, y1, x2, y1); // top | |
1007 } | |
1008 else | |
1009 { | |
1010 gc.drawLine(x1, y2, x2, y2); // bottom | |
1011 } | |
1012 } | |
1013 } | |
1014 | |
1015 void drawChevron (GC gc) | |
1016 { | |
1017 if (chevronRect.width is 0 || chevronRect.height is 0) | |
1018 return; | |
1019 // draw chevron (10x7) | |
1020 Display display = getDisplay(); | |
1021 Point dpi = display.getDPI(); | |
1022 int fontHeight = 72 * 10 / dpi.y; | |
1023 FontData fd = getFont().getFontData()[0]; | |
1024 fd.setHeight(fontHeight); | |
1025 Font f = new Font(display, fd); | |
1026 int fHeight = f.getFontData()[0].getHeight() * dpi.y / 72; | |
1027 int indent = Math.max(2, (chevronRect.height - fHeight - 4) / 2); | |
1028 int x = chevronRect.x + 2; | |
1029 int y = chevronRect.y + indent; | |
1030 int count; | |
1031 if (single) | |
1032 { | |
1033 count = selectedIndex is -1 ? items.length : items.length - 1; | |
1034 } | |
1035 else | |
1036 { | |
1037 int showCount = 0; | |
1038 while (showCount < priority.length && items[priority[showCount]].showing) | |
1039 { | |
1040 showCount++; | |
1041 } | |
1042 count = items.length - showCount; | |
1043 } | |
1044 String chevronString = count > 99 ? "99+" : String.valueOf(count); //$NON-NLS-1$ | |
1045 switch (chevronImageState) | |
1046 { | |
1047 case NORMAL: | |
1048 { | |
1049 Color | |
1050 chevronBorder = single ? getSelectionForeground() : getForeground(); | |
1051 gc.setForeground(chevronBorder); | |
1052 gc.setFont(f); | |
1053 gc.drawLine(x, y, x + 2, y + 2); | |
1054 gc.drawLine(x + 2, y + 2, x, y + 4); | |
1055 gc.drawLine(x + 1, y, x + 3, y + 2); | |
1056 gc.drawLine(x + 3, y + 2, x + 1, y + 4); | |
1057 gc.drawLine(x + 4, y, x + 6, y + 2); | |
1058 gc.drawLine(x + 6, y + 2, x + 5, y + 4); | |
1059 gc.drawLine(x + 5, y, x + 7, y + 2); | |
1060 gc.drawLine(x + 7, y + 2, x + 4, y + 4); | |
1061 gc.drawString(chevronString, x + 7, y + 3, true); | |
1062 break; | |
1063 } | |
1064 case HOT: | |
1065 { | |
1066 gc.setForeground(display.getSystemColor(BUTTON_BORDER)); | |
1067 gc.setBackground(display.getSystemColor(BUTTON_FILL)); | |
1068 gc.setFont(f); | |
1069 gc.fillRoundRectangle(chevronRect.x, chevronRect.y, | |
1070 chevronRect.width, chevronRect.height, 6, 6); | |
1071 gc.drawRoundRectangle(chevronRect.x, chevronRect.y, | |
1072 chevronRect.width - 1, chevronRect.height - 1, 6, 6); | |
1073 gc.drawLine(x, y, x + 2, y + 2); | |
1074 gc.drawLine(x + 2, y + 2, x, y + 4); | |
1075 gc.drawLine(x + 1, y, x + 3, y + 2); | |
1076 gc.drawLine(x + 3, y + 2, x + 1, y + 4); | |
1077 gc.drawLine(x + 4, y, x + 6, y + 2); | |
1078 gc.drawLine(x + 6, y + 2, x + 5, y + 4); | |
1079 gc.drawLine(x + 5, y, x + 7, y + 2); | |
1080 gc.drawLine(x + 7, y + 2, x + 4, y + 4); | |
1081 gc.drawString(chevronString, x + 7, y + 3, true); | |
1082 break; | |
1083 } | |
1084 case SELECTED: | |
1085 { | |
1086 gc.setForeground(display.getSystemColor(BUTTON_BORDER)); | |
1087 gc.setBackground(display.getSystemColor(BUTTON_FILL)); | |
1088 gc.setFont(f); | |
1089 gc.fillRoundRectangle(chevronRect.x, chevronRect.y, | |
1090 chevronRect.width, chevronRect.height, 6, 6); | |
1091 gc.drawRoundRectangle(chevronRect.x, chevronRect.y, | |
1092 chevronRect.width - 1, chevronRect.height - 1, 6, 6); | |
1093 gc.drawLine(x + 1, y + 1, x + 3, y + 3); | |
1094 gc.drawLine(x + 3, y + 3, x + 1, y + 5); | |
1095 gc.drawLine(x + 2, y + 1, x + 4, y + 3); | |
1096 gc.drawLine(x + 4, y + 3, x + 2, y + 5); | |
1097 gc.drawLine(x + 5, y + 1, x + 7, y + 3); | |
1098 gc.drawLine(x + 7, y + 3, x + 6, y + 5); | |
1099 gc.drawLine(x + 6, y + 1, x + 8, y + 3); | |
1100 gc.drawLine(x + 8, y + 3, x + 5, y + 5); | |
1101 gc.drawString(chevronString, x + 8, y + 4, true); | |
1102 break; | |
1103 } | |
1104 } | |
1105 f.dispose(); | |
1106 } | |
1107 | |
1108 void drawMaximize (GC gc) | |
1109 { | |
1110 if (maxRect.width is 0 || maxRect.height is 0) | |
1111 return; | |
1112 Display display = getDisplay(); | |
1113 // 5x4 or 7x9 | |
1114 int x = maxRect.x + (CTabFolder.BUTTON_SIZE - 10) / 2; | |
1115 int y = maxRect.y + 3; | |
1116 | |
1117 gc.setForeground(display.getSystemColor(BUTTON_BORDER)); | |
1118 gc.setBackground(display.getSystemColor(BUTTON_FILL)); | |
1119 | |
1120 switch (maxImageState) | |
1121 { | |
1122 case NORMAL: | |
1123 { | |
1124 if (!maximized) | |
1125 { | |
1126 gc.fillRectangle(x, y, 9, 9); | |
1127 gc.drawRectangle(x, y, 9, 9); | |
1128 gc.drawLine(x + 1, y + 2, x + 8, y + 2); | |
1129 } | |
1130 else | |
1131 { | |
1132 gc.fillRectangle(x, y + 3, 5, 4); | |
1133 gc.fillRectangle(x + 2, y, 5, 4); | |
1134 gc.drawRectangle(x, y + 3, 5, 4); | |
1135 gc.drawRectangle(x + 2, y, 5, 4); | |
1136 gc.drawLine(x + 3, y + 1, x + 6, y + 1); | |
1137 gc.drawLine(x + 1, y + 4, x + 4, y + 4); | |
1138 } | |
1139 break; | |
1140 } | |
1141 case HOT: | |
1142 { | |
1143 gc.fillRoundRectangle(maxRect.x, maxRect.y, maxRect.width, | |
1144 maxRect.height, 6, 6); | |
1145 gc.drawRoundRectangle(maxRect.x, maxRect.y, maxRect.width - 1, | |
1146 maxRect.height - 1, 6, 6); | |
1147 if (!maximized) | |
1148 { | |
1149 gc.fillRectangle(x, y, 9, 9); | |
1150 gc.drawRectangle(x, y, 9, 9); | |
1151 gc.drawLine(x + 1, y + 2, x + 8, y + 2); | |
1152 } | |
1153 else | |
1154 { | |
1155 gc.fillRectangle(x, y + 3, 5, 4); | |
1156 gc.fillRectangle(x + 2, y, 5, 4); | |
1157 gc.drawRectangle(x, y + 3, 5, 4); | |
1158 gc.drawRectangle(x + 2, y, 5, 4); | |
1159 gc.drawLine(x + 3, y + 1, x + 6, y + 1); | |
1160 gc.drawLine(x + 1, y + 4, x + 4, y + 4); | |
1161 } | |
1162 break; | |
1163 } | |
1164 case SELECTED: | |
1165 { | |
1166 gc.fillRoundRectangle(maxRect.x, maxRect.y, maxRect.width, | |
1167 maxRect.height, 6, 6); | |
1168 gc.drawRoundRectangle(maxRect.x, maxRect.y, maxRect.width - 1, | |
1169 maxRect.height - 1, 6, 6); | |
1170 if (!maximized) | |
1171 { | |
1172 gc.fillRectangle(x + 1, y + 1, 9, 9); | |
1173 gc.drawRectangle(x + 1, y + 1, 9, 9); | |
1174 gc.drawLine(x + 2, y + 3, x + 9, y + 3); | |
1175 } | |
1176 else | |
1177 { | |
1178 gc.fillRectangle(x + 1, y + 4, 5, 4); | |
1179 gc.fillRectangle(x + 3, y + 1, 5, 4); | |
1180 gc.drawRectangle(x + 1, y + 4, 5, 4); | |
1181 gc.drawRectangle(x + 3, y + 1, 5, 4); | |
1182 gc.drawLine(x + 4, y + 2, x + 7, y + 2); | |
1183 gc.drawLine(x + 2, y + 5, x + 5, y + 5); | |
1184 } | |
1185 break; | |
1186 } | |
1187 } | |
1188 } | |
1189 | |
1190 void drawMinimize (GC gc) | |
1191 { | |
1192 if (minRect.width is 0 || minRect.height is 0) | |
1193 return; | |
1194 Display display = getDisplay(); | |
1195 // 5x4 or 9x3 | |
1196 int x = minRect.x + (BUTTON_SIZE - 10) / 2; | |
1197 int y = minRect.y + 3; | |
1198 | |
1199 gc.setForeground(display.getSystemColor(BUTTON_BORDER)); | |
1200 gc.setBackground(display.getSystemColor(BUTTON_FILL)); | |
1201 | |
1202 switch (minImageState) | |
1203 { | |
1204 case NORMAL: | |
1205 { | |
1206 if (!minimized) | |
1207 { | |
1208 gc.fillRectangle(x, y, 9, 3); | |
1209 gc.drawRectangle(x, y, 9, 3); | |
1210 } | |
1211 else | |
1212 { | |
1213 gc.fillRectangle(x, y + 3, 5, 4); | |
1214 gc.fillRectangle(x + 2, y, 5, 4); | |
1215 gc.drawRectangle(x, y + 3, 5, 4); | |
1216 gc.drawRectangle(x + 2, y, 5, 4); | |
1217 gc.drawLine(x + 3, y + 1, x + 6, y + 1); | |
1218 gc.drawLine(x + 1, y + 4, x + 4, y + 4); | |
1219 } | |
1220 break; | |
1221 } | |
1222 case HOT: | |
1223 { | |
1224 gc.fillRoundRectangle(minRect.x, minRect.y, minRect.width, | |
1225 minRect.height, 6, 6); | |
1226 gc.drawRoundRectangle(minRect.x, minRect.y, minRect.width - 1, | |
1227 minRect.height - 1, 6, 6); | |
1228 if (!minimized) | |
1229 { | |
1230 gc.fillRectangle(x, y, 9, 3); | |
1231 gc.drawRectangle(x, y, 9, 3); | |
1232 } | |
1233 else | |
1234 { | |
1235 gc.fillRectangle(x, y + 3, 5, 4); | |
1236 gc.fillRectangle(x + 2, y, 5, 4); | |
1237 gc.drawRectangle(x, y + 3, 5, 4); | |
1238 gc.drawRectangle(x + 2, y, 5, 4); | |
1239 gc.drawLine(x + 3, y + 1, x + 6, y + 1); | |
1240 gc.drawLine(x + 1, y + 4, x + 4, y + 4); | |
1241 } | |
1242 break; | |
1243 } | |
1244 case SELECTED: | |
1245 { | |
1246 gc.fillRoundRectangle(minRect.x, minRect.y, minRect.width, | |
1247 minRect.height, 6, 6); | |
1248 gc.drawRoundRectangle(minRect.x, minRect.y, minRect.width - 1, | |
1249 minRect.height - 1, 6, 6); | |
1250 if (!minimized) | |
1251 { | |
1252 gc.fillRectangle(x + 1, y + 1, 9, 3); | |
1253 gc.drawRectangle(x + 1, y + 1, 9, 3); | |
1254 } | |
1255 else | |
1256 { | |
1257 gc.fillRectangle(x + 1, y + 4, 5, 4); | |
1258 gc.fillRectangle(x + 3, y + 1, 5, 4); | |
1259 gc.drawRectangle(x + 1, y + 4, 5, 4); | |
1260 gc.drawRectangle(x + 3, y + 1, 5, 4); | |
1261 gc.drawLine(x + 4, y + 2, x + 7, y + 2); | |
1262 gc.drawLine(x + 2, y + 5, x + 5, y + 5); | |
1263 } | |
1264 break; | |
1265 } | |
1266 } | |
1267 } | |
1268 | |
1269 void drawTabArea (Event event) | |
1270 { | |
1271 GC gc = event.gc; | |
1272 Point size = getSize(); | |
1273 int[] shape = null; | |
1274 | |
1275 if (tabHeight is 0) | |
1276 { | |
1277 int style = getStyle(); | |
1278 if ((style & DWT.FLAT) !is 0 && (style & DWT.BORDER) is 0) | |
1279 return; | 2201 return; |
1280 int x1 = borderLeft - 1; | 2202 } |
1281 int x2 = size.x - borderRight; | 2203 CTabItem item = null; |
1282 int | 2204 if (single) { |
1283 y1 = onBottom ? size.y - borderBottom - highlight_header - 1 : borderTop + highlight_header; | 2205 if (selectedIndex !is -1) { |
1284 int y2 = onBottom ? size.y - borderBottom : borderTop; | 2206 Rectangle bounds = items[selectedIndex].getBounds(); |
1285 if (borderLeft > 0 && onBottom) | 2207 if (bounds.contains(x, y)){ |
1286 y2 -= 1; | 2208 item = items[selectedIndex]; |
1287 | |
1288 shape = new int[][x1 , y1 , x1 , y2 , x2 , y2 , x2 , y1]; | |
1289 | |
1290 // If horizontal gradient, show gradient across the whole area | |
1291 if (selectedIndex !is -1 && selectionGradientColors !is null && selectionGradientColors.length > 1 && !selectionGradientVertical) | |
1292 { | |
1293 drawBackground(gc, shape, true); | |
1294 } | |
1295 else if (selectedIndex is -1 && gradientColors !is null && gradientColors.length > 1 && !gradientVertical) | |
1296 { | |
1297 drawBackground(gc, shape, false); | |
1298 } | |
1299 else | |
1300 { | |
1301 gc.setBackground( | |
1302 selectedIndex is -1 ? getBackground() : selectionBackground); | |
1303 gc.fillPolygon(shape); | |
1304 } | |
1305 | |
1306 //draw 1 pixel border | |
1307 if (borderLeft > 0) | |
1308 { | |
1309 gc.setForeground(borderColor); | |
1310 gc.drawPolyline(shape); | |
1311 } | |
1312 return; | |
1313 } | |
1314 | |
1315 int x = Math.max(0, borderLeft - 1); | |
1316 int y = onBottom ? size.y - borderBottom - tabHeight : borderTop; | |
1317 int width = size.x - borderLeft - borderRight + 1; | |
1318 int height = tabHeight - 1; | |
1319 | |
1320 // Draw Tab Header | |
1321 if (onBottom) | |
1322 { | |
1323 int[] left, right; | |
1324 if ((getStyle() & DWT.BORDER) !is 0) | |
1325 { | |
1326 left = simple ? SIMPLE_BOTTOM_LEFT_CORNER : BOTTOM_LEFT_CORNER; | |
1327 right = simple ? SIMPLE_BOTTOM_RIGHT_CORNER : BOTTOM_RIGHT_CORNER; | |
1328 } | |
1329 else | |
1330 { | |
1331 left = simple ? SIMPLE_BOTTOM_LEFT_CORNER_BORDERLESS : BOTTOM_LEFT_CORNER_BORDERLESS; | |
1332 right = simple ? SIMPLE_BOTTOM_RIGHT_CORNER_BORDERLESS : BOTTOM_RIGHT_CORNER_BORDERLESS; | |
1333 } | |
1334 shape = new int[left.length + right.length + 4]; | |
1335 int index = 0; | |
1336 shape[index++] = x; | |
1337 shape[index++] = y - highlight_header; | |
1338 for (int i = 0; i < left.length / 2; i++) | |
1339 { | |
1340 shape[index++] = x + left[2 * i]; | |
1341 shape[index++] = y + height + left[2 * i + 1]; | |
1342 if (borderLeft is 0) | |
1343 shape[index - 1] += 1; | |
1344 } | |
1345 for (int i = 0; i < right.length / 2; i++) | |
1346 { | |
1347 shape[index++] = x + width + right[2 * i]; | |
1348 shape[index++] = y + height + right[2 * i + 1]; | |
1349 if (borderLeft is 0) | |
1350 shape[index - 1] += 1; | |
1351 } | |
1352 shape[index++] = x + width; | |
1353 shape[index++] = y - highlight_header; | |
1354 } | |
1355 else | |
1356 { | |
1357 int[] left, right; | |
1358 if ((getStyle() & DWT.BORDER) !is 0) | |
1359 { | |
1360 left = simple ? SIMPLE_TOP_LEFT_CORNER : TOP_LEFT_CORNER; | |
1361 right = simple ? SIMPLE_TOP_RIGHT_CORNER : TOP_RIGHT_CORNER; | |
1362 } | |
1363 else | |
1364 { | |
1365 left = simple ? SIMPLE_TOP_LEFT_CORNER_BORDERLESS : TOP_LEFT_CORNER_BORDERLESS; | |
1366 right = simple ? SIMPLE_TOP_RIGHT_CORNER_BORDERLESS : TOP_RIGHT_CORNER_BORDERLESS; | |
1367 } | |
1368 shape = new int[left.length + right.length + 4]; | |
1369 int index = 0; | |
1370 shape[index++] = x; | |
1371 shape[index++] = y + height + highlight_header + 1; | |
1372 for (int i = 0; i < left.length / 2; i++) | |
1373 { | |
1374 shape[index++] = x + left[2 * i]; | |
1375 shape[index++] = y + left[2 * i + 1]; | |
1376 } | |
1377 for (int i = 0; i < right.length / 2; i++) | |
1378 { | |
1379 shape[index++] = x + width + right[2 * i]; | |
1380 shape[index++] = y + right[2 * i + 1]; | |
1381 } | |
1382 shape[index++] = x + width; | |
1383 shape[index++] = y + height + highlight_header + 1; | |
1384 } | |
1385 // Fill in background | |
1386 bool bkSelected = single && selectedIndex !is -1; | |
1387 drawBackground(gc, shape, bkSelected); | |
1388 // Fill in parent background for non-rectangular shape | |
1389 Region r = new Region(); | |
1390 r.add(new Rectangle(x, y, width + 1, height + 1)); | |
1391 r.subtract(shape); | |
1392 gc.setBackground(getParent().getBackground()); | |
1393 fillRegion(gc, r); | |
1394 r.dispose(); | |
1395 | |
1396 // Draw the unselected tabs. | |
1397 if (!single) | |
1398 { | |
1399 for (int i = 0; i < items.length; i++) | |
1400 { | |
1401 if (i !is selectedIndex && event.getBounds().intersects( | |
1402 items[i].getBounds())) | |
1403 { | |
1404 items[i].onPaint(gc, false); | |
1405 } | |
1406 } | |
1407 } | |
1408 | |
1409 // Draw selected tab | |
1410 if (selectedIndex !is -1) | |
1411 { | |
1412 CTabItem item = items[selectedIndex]; | |
1413 item.onPaint(gc, true); | |
1414 } | |
1415 else | |
1416 { | |
1417 // if no selected tab - draw line across bottom of all tabs | |
1418 int x1 = borderLeft; | |
1419 int | |
1420 y1 = (onBottom) ? size.y - borderBottom - tabHeight - 1 : borderTop + tabHeight; | |
1421 int x2 = size.x - borderRight; | |
1422 gc.setForeground(borderColor); | |
1423 gc.drawLine(x1, y1, x2, y1); | |
1424 } | |
1425 | |
1426 // Draw Buttons | |
1427 drawChevron(gc); | |
1428 drawMinimize(gc); | |
1429 drawMaximize(gc); | |
1430 | |
1431 // Draw border line | |
1432 if (borderLeft > 0) | |
1433 { | |
1434 RGB outside = getParent().getBackground().getRGB(); | |
1435 antialias(shape, borderColor.getRGB(), null, outside, gc); | |
1436 gc.setForeground(borderColor); | |
1437 gc.drawPolyline(shape); | |
1438 } | |
1439 } | |
1440 | |
1441 /** | |
1442 * Returns <code>true</code> if the receiver's border is visible. | |
1443 * | |
1444 * @return the receiver's border visibility state | |
1445 * | |
1446 * @exception DWTException <ul> | |
1447 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1448 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1449 * </ul> | |
1450 * | |
1451 * @since 3.0 | |
1452 */ | |
1453 public bool getBorderVisible () | |
1454 { | |
1455 checkWidget(); | |
1456 return borderLeft is 1; | |
1457 } | |
1458 | |
1459 public Rectangle getClientArea () | |
1460 { | |
1461 checkWidget(); | |
1462 if (minimized) | |
1463 return new Rectangle(xClient, yClient, 0, 0); | |
1464 Point size = getSize(); | |
1465 int | |
1466 width = size.x - borderLeft - borderRight - 2 * marginWidth - 2 * highlight_margin; | |
1467 int | |
1468 height = size.y - borderTop - borderBottom - 2 * marginHeight - highlight_margin - highlight_header; | |
1469 height -= tabHeight; | |
1470 return new Rectangle(xClient, yClient, width, height); | |
1471 } | |
1472 | |
1473 /** | |
1474 * Return the tab that is located at the specified index. | |
1475 * | |
1476 * @param index the index of the tab item | |
1477 * @return the item at the specified index | |
1478 * | |
1479 * @exception IllegalArgumentException <ul> | |
1480 * <li>ERROR_INVALID_RANGE - if the index is out of range</li> | |
1481 * </ul> | |
1482 * @exception DWTException <ul> | |
1483 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1484 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1485 * </ul> | |
1486 */ | |
1487 public CTabItem getItem (int index) | |
1488 { | |
1489 //checkWidget(); | |
1490 if (index < 0 || index >= items.length) | |
1491 DWT.error(DWT.ERROR_INVALID_RANGE); | |
1492 return items[index]; | |
1493 } | |
1494 | |
1495 /** | |
1496 * Gets the item at a point in the widget. | |
1497 * | |
1498 * @param pt the point in coordinates relative to the CTabFolder | |
1499 * @return the item at a point or null | |
1500 * | |
1501 * @exception DWTException <ul> | |
1502 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1503 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1504 * </ul> | |
1505 */ | |
1506 public CTabItem getItem (Point pt) | |
1507 { | |
1508 //checkWidget(); | |
1509 if (items.length is 0) | |
1510 return null; | |
1511 Point size = getSize(); | |
1512 if (size.x <= borderLeft + borderRight) | |
1513 return null; | |
1514 if (showChevron && chevronRect.contains(pt)) | |
1515 return null; | |
1516 for (int i = 0; i < priority.length; i++) | |
1517 { | |
1518 CTabItem item = items[priority[i]]; | |
1519 Rectangle rect = item.getBounds(); | |
1520 if (rect.contains(pt)) | |
1521 return item; | |
1522 } | |
1523 return null; | |
1524 } | |
1525 | |
1526 /** | |
1527 * Return the number of tabs in the folder. | |
1528 * | |
1529 * @return the number of tabs in the folder | |
1530 * | |
1531 * @exception DWTException <ul> | |
1532 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1533 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1534 * </ul> | |
1535 */ | |
1536 public int getItemCount () | |
1537 { | |
1538 //checkWidget(); | |
1539 return items.length; | |
1540 } | |
1541 | |
1542 /** | |
1543 * Return the tab items. | |
1544 * | |
1545 * @return the tab items | |
1546 * | |
1547 * @exception DWTException <ul> | |
1548 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1549 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1550 * </ul> | |
1551 */ | |
1552 public CTabItem[] getItems () | |
1553 { | |
1554 //checkWidget(); | |
1555 CTabItem[] tabItems = new CTabItem[items.length]; | |
1556 System.arraycopy(items, 0, tabItems, 0, items.length); | |
1557 return tabItems; | |
1558 } | |
1559 | |
1560 /* | |
1561 * Return the lowercase of the first non-'&' character following | |
1562 * an '&' character in the given String. If there are no '&' | |
1563 * characters in the given String, return '\0'. | |
1564 */ | |
1565 char _findMnemonic (String String) | |
1566 { | |
1567 if (String is null) | |
1568 return '\0'; | |
1569 int index = 0; | |
1570 int length = String.length(); | |
1571 do | |
1572 { | |
1573 while (index < length && String.charAt(index) !is '&') | |
1574 index++; | |
1575 if (++index >= length) | |
1576 return '\0'; | |
1577 if (String.charAt(index) !is '&') | |
1578 return Character.toLowerCase(String.charAt(index)); | |
1579 index++; | |
1580 } while (index < length); | |
1581 return '\0'; | |
1582 } | |
1583 | |
1584 String stripMnemonic (String String) | |
1585 { | |
1586 int index = 0; | |
1587 int length = String.length(); | |
1588 do | |
1589 { | |
1590 while ((index < length) && (String.charAt(index) !is '&')) | |
1591 index++; | |
1592 if (++index >= length) | |
1593 return String; | |
1594 if (String.charAt(index) !is '&') | |
1595 { | |
1596 return String.substring(0, index - 1) + String.substring(index, | |
1597 length); | |
1598 } | |
1599 index++; | |
1600 } while (index < length); | |
1601 return String; | |
1602 } | |
1603 | |
1604 /** | |
1605 * Returns <code>true</code> if the receiver is minimized. | |
1606 * | |
1607 * @return the receiver's minimized state | |
1608 * | |
1609 * @exception DWTException <ul> | |
1610 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1611 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1612 * </ul> | |
1613 * | |
1614 * @since 3.0 | |
1615 */ | |
1616 public bool getMinimized () | |
1617 { | |
1618 checkWidget(); | |
1619 return minimized; | |
1620 } | |
1621 | |
1622 /** | |
1623 * Returns <code>true</code> if the minimize button | |
1624 * is visible. | |
1625 * | |
1626 * @return the visibility of the minimized button | |
1627 * | |
1628 * @exception DWTException <ul> | |
1629 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1630 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1631 * </ul> | |
1632 * | |
1633 * @since 3.0 | |
1634 */ | |
1635 public bool getMinimizeVisible () | |
1636 { | |
1637 checkWidget(); | |
1638 return showMin; | |
1639 } | |
1640 | |
1641 /** | |
1642 * Returns the number of characters that will | |
1643 * appear in a fully compressed tab. | |
1644 * | |
1645 * @return number of characters that will appear in a fully compressed tab | |
1646 * | |
1647 * @since 3.0 | |
1648 */ | |
1649 public int getMinimumCharacters () | |
1650 { | |
1651 checkWidget(); | |
1652 return minChars; | |
1653 } | |
1654 | |
1655 /** | |
1656 * Returns <code>true</code> if the receiver is maximized. | |
1657 * <p> | |
1658 * | |
1659 * @return the receiver's maximized state | |
1660 * | |
1661 * @exception DWTException <ul> | |
1662 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1663 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1664 * </ul> | |
1665 * | |
1666 * @since 3.0 | |
1667 */ | |
1668 public bool getMaximized () | |
1669 { | |
1670 checkWidget(); | |
1671 return maximized; | |
1672 } | |
1673 | |
1674 /** | |
1675 * Returns <code>true</code> if the maximize button | |
1676 * is visible. | |
1677 * | |
1678 * @return the visibility of the maximized button | |
1679 * | |
1680 * @exception DWTException <ul> | |
1681 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1682 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1683 * </ul> | |
1684 * | |
1685 * @since 3.0 | |
1686 */ | |
1687 public bool getMaximizeVisible () | |
1688 { | |
1689 checkWidget(); | |
1690 return showMax; | |
1691 } | |
1692 | |
1693 /** | |
1694 * Returns <code>true</code> if the receiver displays most | |
1695 * recently used tabs and <code>false</code> otherwise. | |
1696 * <p> | |
1697 * When there is not enough horizontal space to show all the tabs, | |
1698 * by default, tabs are shown sequentially from left to right in | |
1699 * order of their index. When the MRU visibility is turned on, | |
1700 * the tabs that are visible will be the tabs most recently selected. | |
1701 * Tabs will still maintain their left to right order based on index | |
1702 * but only the most recently selected tabs are visible. | |
1703 * <p> | |
1704 * For example, consider a CTabFolder that contains "Tab 1", "Tab 2", | |
1705 * "Tab 3" and "Tab 4" (in order by index). The user selects | |
1706 * "Tab 1" and then "Tab 3". If the CTabFolder is now | |
1707 * compressed so that only two tabs are visible, by default, | |
1708 * "Tab 2" and "Tab 3" will be shown ("Tab 3" since it is currently | |
1709 * selected and "Tab 2" because it is the previous item in index order). | |
1710 * If MRU visibility is enabled, the two visible tabs will be "Tab 1" | |
1711 * and "Tab 3" (in that order from left to right).</p> | |
1712 * | |
1713 * @return the receiver's header's visibility state | |
1714 * | |
1715 * @exception DWTException <ul> | |
1716 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1717 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1718 * </ul> | |
1719 * | |
1720 * @since 3.1 | |
1721 */ | |
1722 public bool getMRUVisible () | |
1723 { | |
1724 checkWidget(); | |
1725 return mru; | |
1726 } | |
1727 | |
1728 int getRightItemEdge () | |
1729 { | |
1730 int x = getSize().x - borderRight - 3; | |
1731 if (showMin) | |
1732 x -= BUTTON_SIZE; | |
1733 if (showMax) | |
1734 x -= BUTTON_SIZE; | |
1735 if (showChevron) | |
1736 x -= 3 * BUTTON_SIZE / 2; | |
1737 if (topRight !is null && topRightAlignment !is DWT.FILL) | |
1738 { | |
1739 Point rightSize = topRight.computeSize(DWT.DEFAULT, DWT.DEFAULT); | |
1740 x -= rightSize.x + 3; | |
1741 } | |
1742 return Math.max(0, x); | |
1743 } | |
1744 | |
1745 /** | |
1746 * Return the selected tab item, or null if there is no selection. | |
1747 * | |
1748 * @return the selected tab item, or null if none has been selected | |
1749 * | |
1750 * @exception DWTException <ul> | |
1751 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1752 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1753 * </ul> | |
1754 */ | |
1755 public CTabItem getSelection () | |
1756 { | |
1757 //checkWidget(); | |
1758 if (selectedIndex is -1) | |
1759 return null; | |
1760 return items[selectedIndex]; | |
1761 } | |
1762 | |
1763 /** | |
1764 * Returns the receiver's selection background color. | |
1765 * | |
1766 * @return the selection background color of the receiver | |
1767 * | |
1768 * @exception DWTException <ul> | |
1769 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1770 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1771 * </ul> | |
1772 * | |
1773 * @since 3.0 | |
1774 */ | |
1775 public Color getSelectionBackground () | |
1776 { | |
1777 checkWidget(); | |
1778 return selectionBackground; | |
1779 } | |
1780 | |
1781 /** | |
1782 * Returns the receiver's selection foreground color. | |
1783 * | |
1784 * @return the selection foreground color of the receiver | |
1785 * | |
1786 * @exception DWTException <ul> | |
1787 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1788 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1789 * </ul> | |
1790 * | |
1791 * @since 3.0 | |
1792 */ | |
1793 public Color getSelectionForeground () | |
1794 { | |
1795 checkWidget(); | |
1796 return selectionForeground; | |
1797 } | |
1798 | |
1799 /** | |
1800 * Return the index of the selected tab item, or -1 if there | |
1801 * is no selection. | |
1802 * | |
1803 * @return the index of the selected tab item or -1 | |
1804 * | |
1805 * @exception DWTException <ul> | |
1806 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1807 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1808 * </ul> | |
1809 */ | |
1810 public int getSelectionIndex () | |
1811 { | |
1812 //checkWidget(); | |
1813 return selectedIndex; | |
1814 } | |
1815 | |
1816 /** | |
1817 * Returns <code>true</code> if the CTabFolder is rendered | |
1818 * with a simple, traditional shape. | |
1819 * | |
1820 * @return <code>true</code> if the CTabFolder is rendered with a simple shape | |
1821 * | |
1822 * @since 3.0 | |
1823 */ | |
1824 public bool getSimple () | |
1825 { | |
1826 checkWidget(); | |
1827 return simple; | |
1828 } | |
1829 | |
1830 /** | |
1831 * Returns <code>true</code> if the CTabFolder only displays the selected tab | |
1832 * and <code>false</code> if the CTabFolder displays multiple tabs. | |
1833 * | |
1834 * @return <code>true</code> if the CTabFolder only displays the selected tab and <code>false</code> if the CTabFolder displays multiple tabs | |
1835 * | |
1836 * @since 3.0 | |
1837 */ | |
1838 public bool getSingle () | |
1839 { | |
1840 checkWidget(); | |
1841 return single; | |
1842 } | |
1843 | |
1844 public int getStyle () | |
1845 { | |
1846 int style = super.getStyle(); | |
1847 style &= ~(DWT.TOP | DWT.BOTTOM); | |
1848 style |= onBottom ? DWT.BOTTOM : DWT.TOP; | |
1849 style &= ~(DWT.SINGLE | DWT.MULTI); | |
1850 style |= single ? DWT.SINGLE : DWT.MULTI; | |
1851 if (borderLeft !is 0) | |
1852 style |= DWT.BORDER; | |
1853 style &= ~DWT.CLOSE; | |
1854 if (showClose) | |
1855 style |= DWT.CLOSE; | |
1856 return style; | |
1857 } | |
1858 | |
1859 /** | |
1860 * Returns the height of the tab | |
1861 * | |
1862 * @return the height of the tab | |
1863 * | |
1864 * @exception DWTException <ul> | |
1865 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1866 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1867 * </ul> | |
1868 */ | |
1869 public int getTabHeight () | |
1870 { | |
1871 checkWidget(); | |
1872 if (fixedTabHeight !is DWT.DEFAULT) | |
1873 return fixedTabHeight; | |
1874 return tabHeight - 1; // -1 for line drawn across top of tab | |
1875 } | |
1876 | |
1877 /** | |
1878 * Returns the position of the tab. Possible values are DWT.TOP or DWT.BOTTOM. | |
1879 * | |
1880 * @return the position of the tab | |
1881 * | |
1882 * @exception DWTException <ul> | |
1883 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1884 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1885 * </ul> | |
1886 */ | |
1887 public int getTabPosition () | |
1888 { | |
1889 checkWidget(); | |
1890 return onBottom ? DWT.BOTTOM : DWT.TOP; | |
1891 } | |
1892 | |
1893 /** | |
1894 * Returns the control in the top right corner of the tab folder. | |
1895 * Typically this is a close button or a composite with a menu and close button. | |
1896 * | |
1897 * @return the control in the top right corner of the tab folder or null | |
1898 * | |
1899 * @exception DWTException <ul> | |
1900 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1901 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1902 * </ul> | |
1903 * | |
1904 * @since 2.1 | |
1905 */ | |
1906 public Control getTopRight () | |
1907 { | |
1908 checkWidget(); | |
1909 return topRight; | |
1910 } | |
1911 | |
1912 /** | |
1913 * Returns <code>true</code> if the close button appears | |
1914 * when the user hovers over an unselected tabs. | |
1915 * | |
1916 * @return <code>true</code> if the close button appears on unselected tabs | |
1917 * | |
1918 * @since 3.0 | |
1919 */ | |
1920 public bool getUnselectedCloseVisible () | |
1921 { | |
1922 checkWidget(); | |
1923 return showUnselectedClose; | |
1924 } | |
1925 | |
1926 /** | |
1927 * Returns <code>true</code> if an image appears | |
1928 * in unselected tabs. | |
1929 * | |
1930 * @return <code>true</code> if an image appears in unselected tabs | |
1931 * | |
1932 * @since 3.0 | |
1933 */ | |
1934 public bool getUnselectedImageVisible () | |
1935 { | |
1936 checkWidget(); | |
1937 return showUnselectedImage; | |
1938 } | |
1939 | |
1940 /** | |
1941 * Return the index of the specified tab or -1 if the tab is not | |
1942 * in the receiver. | |
1943 * | |
1944 * @param item the tab item for which the index is required | |
1945 * | |
1946 * @return the index of the specified tab item or -1 | |
1947 * | |
1948 * @exception IllegalArgumentException <ul> | |
1949 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
1950 * </ul> | |
1951 * | |
1952 * @exception DWTException <ul> | |
1953 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
1954 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
1955 * </ul> | |
1956 */ | |
1957 public int indexOf (CTabItem item) | |
1958 { | |
1959 checkWidget(); | |
1960 if (item is null) | |
1961 { | |
1962 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
1963 } | |
1964 for (int i = 0; i < items.length; i++) | |
1965 { | |
1966 if (items[i] is item) | |
1967 return i; | |
1968 } | |
1969 return -1; | |
1970 } | |
1971 | |
1972 void initAccessible () | |
1973 { | |
1974 const Accessible accessible = getAccessible(); | |
1975 accessible.addAccessibleListener(new class AccessibleAdapter | |
1976 { | |
1977 public void getName (AccessibleEvent e) | |
1978 { | |
1979 String name = null; | |
1980 int childID = e.childID; | |
1981 if (childID >= 0 && childID < items.length) | |
1982 { | |
1983 name = stripMnemonic(items[childID].getText()); | |
1984 } | |
1985 else if (childID is items.length + CHEVRON_CHILD_ID) | |
1986 { | |
1987 name = DWT.getMessage("DWT_ShowList"); //$NON-NLS-1$ | |
1988 } | |
1989 else if (childID is items.length + MINIMIZE_CHILD_ID) | |
1990 { | |
1991 name = minimized ? DWT.getMessage("DWT_Restore") : DWT.getMessage( | |
1992 "DWT_Minimize"); //$NON-NLS-1$ //$NON-NLS-2$ | |
1993 } | |
1994 else if (childID is items.length + MAXIMIZE_CHILD_ID) | |
1995 { | |
1996 name = maximized ? DWT.getMessage("DWT_Restore") : DWT.getMessage( | |
1997 "DWT_Maximize"); //$NON-NLS-1$ //$NON-NLS-2$ | |
1998 } | |
1999 e.result = name; | |
2000 } | |
2001 | |
2002 public void getHelp (AccessibleEvent e) | |
2003 { | |
2004 String help = null; | |
2005 int childID = e.childID; | |
2006 if (childID is ACC.CHILDID_SELF) | |
2007 { | |
2008 help = getToolTipText(); | |
2009 } | |
2010 else if (childID >= 0 && childID < items.length) | |
2011 { | |
2012 help = items[childID].getToolTipText(); | |
2013 } | |
2014 e.result = help; | |
2015 } | |
2016 | |
2017 public void getKeyboardShortcut (AccessibleEvent e) | |
2018 { | |
2019 String shortcut = null; | |
2020 int childID = e.childID; | |
2021 if (childID >= 0 && childID < items.length) | |
2022 { | |
2023 String text = items[childID].getText(); | |
2024 if (text !is null) | |
2025 { | |
2026 char mnemonic = _findMnemonic(text); | |
2027 if (mnemonic !is '\0') | |
2028 { | |
2029 shortcut = "Alt+" + mnemonic; //$NON-NLS-1$ | |
2030 } | 2209 } |
2031 } | 2210 } |
2032 } | 2211 } else { |
2033 e.result = shortcut; | 2212 for (int i=0; i<items.length; i++) { |
2034 } | 2213 Rectangle bounds = items[i].getBounds(); |
2035 } ); | 2214 if (bounds.contains(x, y)){ |
2036 | 2215 item = items[i]; |
2037 accessible.addAccessibleControlListener( | 2216 } |
2038 new class AccessibleControlAdapter | 2217 } |
2039 { | 2218 } |
2040 public void getChildAtPoint (AccessibleControlEvent e) | 2219 if (item !is null) { |
2041 { | 2220 if (item.closeRect.contains(x,y)) { |
2042 Point testPoint = toControl(e.x, e.y); | 2221 bool selected = item.closeImageState is SELECTED; |
2043 int childID = ACC.CHILDID_NONE; | 2222 item.closeImageState = HOT; |
2044 for (int i = 0; i < items.length; i++) | 2223 redraw(item.closeRect.x, item.closeRect.y, item.closeRect.width, item.closeRect.height, false); |
2045 { | 2224 if (!selected) return; |
2046 if (items[i].getBounds().contains(testPoint)) | 2225 CTabFolderEvent e = new CTabFolderEvent(this); |
2047 { | 2226 e.widget = this; |
2048 childID = i; | 2227 e.time = event.time; |
2049 break; | 2228 e.item = item; |
2050 } | 2229 e.doit = true; |
2051 } | 2230 for (int j = 0; j < folderListeners.length; j++) { |
2052 if (childID is ACC.CHILDID_NONE) | 2231 CTabFolder2Listener listener = folderListeners[j]; |
2053 { | 2232 listener.close(e); |
2054 if (showChevron && chevronRect.contains(testPoint)) | 2233 } |
2055 { | 2234 for (int j = 0; j < tabListeners.length; j++) { |
2056 childID = items.length + CHEVRON_CHILD_ID; | 2235 CTabFolderListener listener = tabListeners[j]; |
2057 } | 2236 listener.itemClosed(e); |
2058 else if (showMin && minRect.contains(testPoint)) | 2237 } |
2059 { | 2238 if (e.doit) item.dispose(); |
2060 childID = items.length + MINIMIZE_CHILD_ID; | 2239 if (!isDisposed() && item.isDisposed()) { |
2061 } | 2240 Display display = getDisplay(); |
2062 else if (showMax && maxRect.contains(testPoint)) | 2241 Point pt = display.getCursorLocation(); |
2063 { | 2242 pt = display.map(null, this, pt.x, pt.y); |
2064 childID = items.length + MAXIMIZE_CHILD_ID; | 2243 CTabItem nextItem = getItem(pt); |
2065 } | 2244 if (nextItem !is null) { |
2066 else | 2245 if (nextItem.closeRect.contains(pt)) { |
2067 { | 2246 if (nextItem.closeImageState !is SELECTED && nextItem.closeImageState !is HOT) { |
2068 Rectangle location = getBounds(); | 2247 nextItem.closeImageState = HOT; |
2069 location.height = location.height - getClientArea().height; | 2248 redraw(nextItem.closeRect.x, nextItem.closeRect.y, nextItem.closeRect.width, nextItem.closeRect.height, false); |
2070 if (location.contains(testPoint)) | 2249 } |
2071 { | 2250 } else { |
2072 childID = ACC.CHILDID_SELF; | 2251 if (nextItem.closeImageState !is NORMAL) { |
2252 nextItem.closeImageState = NORMAL; | |
2253 redraw(nextItem.closeRect.x, nextItem.closeRect.y, nextItem.closeRect.width, nextItem.closeRect.height, false); | |
2073 } | 2254 } |
2074 } | 2255 } |
2075 } | 2256 } |
2076 e.childID = childID; | |
2077 } | |
2078 | |
2079 public void getLocation (AccessibleControlEvent e) | |
2080 { | |
2081 Rectangle location = null; | |
2082 Point pt = null; | |
2083 int childID = e.childID; | |
2084 if (childID is ACC.CHILDID_SELF) | |
2085 { | |
2086 location = getBounds(); | |
2087 pt = getParent().toDisplay(location.x, location.y); | |
2088 } | |
2089 else | |
2090 { | |
2091 if (childID >= 0 && childID < items.length && items[childID].isShowing()) | |
2092 { | |
2093 location = items[childID].getBounds(); | |
2094 } | |
2095 else if (showChevron && childID is items.length + CHEVRON_CHILD_ID) | |
2096 { | |
2097 location = chevronRect; | |
2098 } | |
2099 else if (showMin && childID is items.length + MINIMIZE_CHILD_ID) | |
2100 { | |
2101 location = minRect; | |
2102 } | |
2103 else if (showMax && childID is items.length + MAXIMIZE_CHILD_ID) | |
2104 { | |
2105 location = maxRect; | |
2106 } | |
2107 if (location !is null) | |
2108 { | |
2109 pt = toDisplay(location.x, location.y); | |
2110 } | |
2111 } | |
2112 if (location !is null && pt !is null) | |
2113 { | |
2114 e.x = pt.x; | |
2115 e.y = pt.y; | |
2116 e.width = location.width; | |
2117 e.height = location.height; | |
2118 } | |
2119 } | |
2120 | |
2121 public void getChildCount (AccessibleControlEvent e) | |
2122 { | |
2123 e.detail = items.length + EXTRA_CHILD_ID_COUNT; | |
2124 } | |
2125 | |
2126 public void getDefaultAction (AccessibleControlEvent e) | |
2127 { | |
2128 String action = null; | |
2129 int childID = e.childID; | |
2130 if (childID >= 0 && childID < items.length) | |
2131 { | |
2132 action = DWT.getMessage("DWT_Switch"); //$NON-NLS-1$ | |
2133 } | |
2134 if (childID >= items.length && childID < items.length + EXTRA_CHILD_ID_COUNT) | |
2135 { | |
2136 action = DWT.getMessage("DWT_Press"); //$NON-NLS-1$ | |
2137 } | |
2138 e.result = action; | |
2139 } | |
2140 | |
2141 public void getFocus (AccessibleControlEvent e) | |
2142 { | |
2143 int childID = ACC.CHILDID_NONE; | |
2144 if (isFocusControl()) | |
2145 { | |
2146 if (selectedIndex is -1) | |
2147 { | |
2148 childID = ACC.CHILDID_SELF; | |
2149 } | |
2150 else | |
2151 { | |
2152 childID = selectedIndex; | |
2153 } | |
2154 } | |
2155 e.childID = childID; | |
2156 } | |
2157 | |
2158 public void getRole (AccessibleControlEvent e) | |
2159 { | |
2160 int role = 0; | |
2161 int childID = e.childID; | |
2162 if (childID is ACC.CHILDID_SELF) | |
2163 { | |
2164 role = ACC.ROLE_TABFOLDER; | |
2165 } | |
2166 else if (childID >= 0 && childID < items.length) | |
2167 { | |
2168 role = ACC.ROLE_TABITEM; | |
2169 } | |
2170 else if (childID >= items.length && childID < items.length + EXTRA_CHILD_ID_COUNT) | |
2171 { | |
2172 role = ACC.ROLE_PUSHBUTTON; | |
2173 } | |
2174 e.detail = role; | |
2175 } | |
2176 | |
2177 public void getSelection (AccessibleControlEvent e) | |
2178 { | |
2179 e.childID = (selectedIndex is -1) ? ACC.CHILDID_NONE : selectedIndex; | |
2180 } | |
2181 | |
2182 public void getState (AccessibleControlEvent e) | |
2183 { | |
2184 int state = 0; | |
2185 int childID = e.childID; | |
2186 if (childID is ACC.CHILDID_SELF) | |
2187 { | |
2188 state = ACC.STATE_NORMAL; | |
2189 } | |
2190 else if (childID >= 0 && childID < items.length) | |
2191 { | |
2192 state = ACC.STATE_SELECTABLE; | |
2193 if (isFocusControl()) | |
2194 { | |
2195 state |= ACC.STATE_FOCUSABLE; | |
2196 } | |
2197 if (selectedIndex is childID) | |
2198 { | |
2199 state |= ACC.STATE_SELECTED; | |
2200 if (isFocusControl()) | |
2201 { | |
2202 state |= ACC.STATE_FOCUSED; | |
2203 } | |
2204 } | |
2205 } | |
2206 else if (childID is items.length + CHEVRON_CHILD_ID) | |
2207 { | |
2208 state = showChevron ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; | |
2209 } | |
2210 else if (childID is items.length + MINIMIZE_CHILD_ID) | |
2211 { | |
2212 state = showMin ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; | |
2213 } | |
2214 else if (childID is items.length + MAXIMIZE_CHILD_ID) | |
2215 { | |
2216 state = showMax ? ACC.STATE_NORMAL : ACC.STATE_INVISIBLE; | |
2217 } | |
2218 e.detail = state; | |
2219 } | |
2220 | |
2221 public void getChildren (AccessibleControlEvent e) | |
2222 { | |
2223 int childIdCount = items.length + EXTRA_CHILD_ID_COUNT; | |
2224 Object[] children = new Object[childIdCount]; | |
2225 for (int i = 0; i < childIdCount; i++) | |
2226 { | |
2227 children[i] = new Integer(i); | |
2228 } | |
2229 e.children = children; | |
2230 } | |
2231 }); | |
2232 | |
2233 addListener(DWT.Selection, new class(accessible) Listener | |
2234 { | |
2235 | |
2236 Accessible accessible; | |
2237 | |
2238 this (Accessible accessible) | |
2239 { | |
2240 this.accessible = accessible; | |
2241 } | |
2242 | |
2243 public void handleEvent (Event event) | |
2244 { | |
2245 if (isFocusControl()) | |
2246 { | |
2247 if (selectedIndex is -1) | |
2248 { | |
2249 accessible.setFocus(ACC.CHILDID_SELF); | |
2250 } | |
2251 else | |
2252 { | |
2253 accessible.setFocus(selectedIndex); | |
2254 } | |
2255 } | |
2256 } | |
2257 }); | |
2258 | |
2259 addListener(DWT.FocusIn, new class(accessible) Listener | |
2260 { | |
2261 | |
2262 Accessible accessible; | |
2263 | |
2264 this (Accessible accessible) | |
2265 { | |
2266 this.accessible = accessible; | |
2267 } | |
2268 | |
2269 public void handleEvent (Event event) | |
2270 { | |
2271 if (selectedIndex is -1) | |
2272 { | |
2273 accessible.setFocus(ACC.CHILDID_SELF); | |
2274 } | |
2275 else | |
2276 { | |
2277 accessible.setFocus(selectedIndex); | |
2278 } | |
2279 } | |
2280 }); | |
2281 } | |
2282 | |
2283 void onKeyDown (Event event) | |
2284 { | |
2285 switch (event.keyCode) | |
2286 { | |
2287 case DWT.ARROW_LEFT: | |
2288 case DWT.ARROW_RIGHT: | |
2289 int count = items.length; | |
2290 if (count is 0) | |
2291 return; | |
2292 if (selectedIndex is -1) | |
2293 return; | |
2294 int | |
2295 leadKey = (getStyle() & DWT.RIGHT_TO_LEFT) !is 0 ? DWT.ARROW_RIGHT : DWT.ARROW_LEFT; | |
2296 int offset = event.keyCode is leadKey ? -1 : 1; | |
2297 int index; | |
2298 if (!mru) | |
2299 { | |
2300 index = selectedIndex + offset; | |
2301 } | |
2302 else | |
2303 { | |
2304 int[] visible = new int[items.length]; | |
2305 int idx = 0; | |
2306 int current = -1; | |
2307 for (int i = 0; i < items.length; i++) | |
2308 { | |
2309 if (items[i].showing) | |
2310 { | |
2311 if (i is selectedIndex) | |
2312 current = idx; | |
2313 visible[idx++] = i; | |
2314 } | |
2315 } | |
2316 if (current + offset >= 0 && current + offset < idx) | |
2317 { | |
2318 index = visible[current + offset]; | |
2319 } | |
2320 else | |
2321 { | |
2322 if (showChevron) | |
2323 { | |
2324 CTabFolderEvent e = new CTabFolderEvent(this); | |
2325 e.widget = this; | |
2326 e.time = event.time; | |
2327 e.x = chevronRect.x; | |
2328 e.y = chevronRect.y; | |
2329 e.width = chevronRect.width; | |
2330 e.height = chevronRect.height; | |
2331 e.doit = true; | |
2332 for (int i = 0; i < folderListeners.length; i++) | |
2333 { | |
2334 folderListeners[i].showList(e); | |
2335 } | |
2336 if (e.doit && !isDisposed()) | |
2337 { | |
2338 showList(chevronRect); | |
2339 } | |
2340 } | |
2341 return; | |
2342 } | |
2343 } | |
2344 if (index < 0 || index >= count) | |
2345 return; | |
2346 setSelection(index, true); | |
2347 forceFocus(); | |
2348 } | |
2349 } | |
2350 | |
2351 void onDispose (Event event) | |
2352 { | |
2353 removeListener(DWT.Dispose, listener); | |
2354 notifyListeners(DWT.Dispose, event); | |
2355 event.type = DWT.None; | |
2356 /* | |
2357 * Usually when an item is disposed, destroyItem will change the size of the items array, | |
2358 * reset the bounds of all the tabs and manage the widget associated with the tab. | |
2359 * Since the whole folder is being disposed, this is not necessary. For speed | |
2360 * the inDispose flag is used to skip over this part of the item dispose. | |
2361 */ | |
2362 inDispose = true; | |
2363 | |
2364 if (showMenu !is null && !showMenu.isDisposed()) | |
2365 { | |
2366 showMenu.dispose(); | |
2367 showMenu = null; | |
2368 } | |
2369 int length = items.length; | |
2370 for (int i = 0; i < length; i++) | |
2371 { | |
2372 if (items[i] !is null) | |
2373 { | |
2374 items[i].dispose(); | |
2375 } | |
2376 } | |
2377 | |
2378 selectionGradientColors = null; | |
2379 selectionGradientPercents = null; | |
2380 selectionBgImage = null; | |
2381 | |
2382 selectionBackground = null; | |
2383 selectionForeground = null; | |
2384 disposeSelectionHighlightGradientColors(); | |
2385 } | |
2386 | |
2387 void onDragDetect (Event event) | |
2388 { | |
2389 bool consume = false; | |
2390 if (chevronRect.contains(event.x, event.y) || minRect.contains(event.x, | |
2391 event.y) || maxRect.contains(event.x, event.y)) | |
2392 { | |
2393 consume = true; | |
2394 } | |
2395 else | |
2396 { | |
2397 for (int i = 0; i < items.length; i++) | |
2398 { | |
2399 if (items[i].closeRect.contains(event.x, event.y)) | |
2400 { | |
2401 consume = true; | |
2402 break; | |
2403 } | |
2404 } | |
2405 } | |
2406 if (consume) | |
2407 { | |
2408 event.type = DWT.None; | |
2409 } | |
2410 } | |
2411 | |
2412 void onFocus (Event event) | |
2413 { | |
2414 checkWidget(); | |
2415 if (selectedIndex >= 0) | |
2416 { | |
2417 redraw(); | |
2418 } | |
2419 else | |
2420 { | |
2421 setSelection(0, true); | |
2422 } | |
2423 } | |
2424 | |
2425 bool onMnemonic (Event event) | |
2426 { | |
2427 char key = event.character; | |
2428 for (int i = 0; i < items.length; i++) | |
2429 { | |
2430 if (items[i] !is null) | |
2431 { | |
2432 char mnemonic = _findMnemonic(items[i].getText()); | |
2433 if (mnemonic !is '\0') | |
2434 { | |
2435 if (Character.toLowerCase(key) is mnemonic) | |
2436 { | |
2437 setSelection(i, true); | |
2438 return true; | |
2439 } | |
2440 } | |
2441 } | |
2442 } | |
2443 return false; | |
2444 } | |
2445 | |
2446 void onMouseDoubleClick (Event event) | |
2447 { | |
2448 if (event.button !is 1 || (event.stateMask & DWT.BUTTON2) !is 0 || (event.stateMask & DWT.BUTTON3) !is 0) | |
2449 return; | |
2450 Event e = new Event(); | |
2451 e.item = getItem(new Point(event.x, event.y)); | |
2452 if (e.item !is null) | |
2453 { | |
2454 notifyListeners(DWT.DefaultSelection, e); | |
2455 } | |
2456 } | |
2457 | |
2458 void onMouse (Event event) | |
2459 { | |
2460 int x = event.x, y = event.y; | |
2461 switch (event.type) | |
2462 { | |
2463 case DWT.MouseEnter: | |
2464 { | |
2465 setToolTipText(null); | |
2466 break; | |
2467 } | |
2468 case DWT.MouseExit: | |
2469 { | |
2470 if (minImageState !is NORMAL) | |
2471 { | |
2472 minImageState = NORMAL; | |
2473 redraw(minRect.x, minRect.y, minRect.width, minRect.height, | |
2474 false); | |
2475 } | |
2476 if (maxImageState !is NORMAL) | |
2477 { | |
2478 maxImageState = NORMAL; | |
2479 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, | |
2480 false); | |
2481 } | |
2482 if (chevronImageState !is NORMAL) | |
2483 { | |
2484 chevronImageState = NORMAL; | |
2485 redraw(chevronRect.x, chevronRect.y, chevronRect.width, | |
2486 chevronRect.height, false); | |
2487 } | |
2488 for (int i = 0; i < items.length; i++) | |
2489 { | |
2490 CTabItem item = items[i]; | |
2491 if (i !is selectedIndex && item.closeImageState !is NONE) | |
2492 { | |
2493 item.closeImageState = NONE; | |
2494 redraw(item.closeRect.x, item.closeRect.y, | |
2495 item.closeRect.width, item.closeRect.height, | |
2496 false); | |
2497 } | |
2498 if (i is selectedIndex && item.closeImageState !is NORMAL) | |
2499 { | |
2500 item.closeImageState = NORMAL; | |
2501 redraw(item.closeRect.x, item.closeRect.y, | |
2502 item.closeRect.width, item.closeRect.height, | |
2503 false); | |
2504 } | |
2505 } | |
2506 break; | |
2507 } | |
2508 case DWT.MouseDown: | |
2509 { | |
2510 if (minRect.contains(x, y)) | |
2511 { | |
2512 if (event.button !is 1) | |
2513 return; | |
2514 minImageState = SELECTED; | |
2515 redraw(minRect.x, minRect.y, minRect.width, minRect.height, | |
2516 false); | |
2517 update(); | |
2518 return; | |
2519 } | |
2520 if (maxRect.contains(x, y)) | |
2521 { | |
2522 if (event.button !is 1) | |
2523 return; | |
2524 maxImageState = SELECTED; | |
2525 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, | |
2526 false); | |
2527 update(); | |
2528 return; | |
2529 } | |
2530 if (chevronRect.contains(x, y)) | |
2531 { | |
2532 if (event.button !is 1) | |
2533 return; | |
2534 if (chevronImageState !is HOT) | |
2535 { | |
2536 chevronImageState = HOT; | |
2537 } | |
2538 else | |
2539 { | |
2540 chevronImageState = SELECTED; | |
2541 } | |
2542 redraw(chevronRect.x, chevronRect.y, chevronRect.width, | |
2543 chevronRect.height, false); | |
2544 update(); | |
2545 return; | |
2546 } | |
2547 CTabItem item = null; | |
2548 if (single) | |
2549 { | |
2550 if (selectedIndex !is -1) | |
2551 { | |
2552 Rectangle bounds = items[selectedIndex].getBounds(); | |
2553 if (bounds.contains(x, y)) | |
2554 { | |
2555 item = items[selectedIndex]; | |
2556 } | |
2557 } | |
2558 } | |
2559 else | |
2560 { | |
2561 for (int i = 0; i < items.length; i++) | |
2562 { | |
2563 Rectangle bounds = items[i].getBounds(); | |
2564 if (bounds.contains(x, y)) | |
2565 { | |
2566 item = items[i]; | |
2567 } | |
2568 } | |
2569 } | |
2570 if (item !is null) | |
2571 { | |
2572 if (item.closeRect.contains(x, y)) | |
2573 { | |
2574 if (event.button !is 1) | |
2575 return; | |
2576 item.closeImageState = SELECTED; | |
2577 redraw(item.closeRect.x, item.closeRect.y, | |
2578 item.closeRect.width, item.closeRect.height, | |
2579 false); | |
2580 update(); | |
2581 return; | |
2582 } | |
2583 int index = indexOf(item); | |
2584 if (item.showing) | |
2585 { | |
2586 setSelection(index, true); | |
2587 } | 2257 } |
2588 return; | 2258 return; |
2589 } | 2259 } |
2590 break; | 2260 } |
2591 } | 2261 default: |
2592 case DWT.MouseMove: | 2262 } |
2593 { | 2263 } |
2594 _setToolTipText(event.x, event.y); | 2264 } |
2595 bool close = false, minimize = false, maximize = false, | 2265 bool onPageTraversal(Event event) { |
2596 chevron = false; | 2266 int count = items.length; |
2597 if (minRect.contains(x, y)) | 2267 if (count is 0) return false; |
2598 { | 2268 int index = selectedIndex; |
2599 minimize = true; | 2269 if (index is -1) { |
2600 if (minImageState !is SELECTED && minImageState !is HOT) | 2270 index = 0; |
2601 { | 2271 } else { |
2602 minImageState = HOT; | 2272 int offset = (event.detail is DWT.TRAVERSE_PAGE_NEXT) ? 1 : -1; |
2603 redraw(minRect.x, minRect.y, minRect.width, | 2273 if (!mru) { |
2604 minRect.height, false); | 2274 index = (selectedIndex + offset + count) % count; |
2605 } | 2275 } else { |
2606 } | 2276 int[] visible = new int[items.length]; |
2607 if (maxRect.contains(x, y)) | 2277 int idx = 0; |
2608 { | 2278 int current = -1; |
2609 maximize = true; | 2279 for (int i = 0; i < items.length; i++) { |
2610 if (maxImageState !is SELECTED && maxImageState !is HOT) | 2280 if (items[i].showing) { |
2611 { | 2281 if (i is selectedIndex) current = idx; |
2612 maxImageState = HOT; | 2282 visible [idx++] = i; |
2613 redraw(maxRect.x, maxRect.y, maxRect.width, | 2283 } |
2614 maxRect.height, false); | 2284 } |
2615 } | 2285 if (current + offset >= 0 && current + offset < idx){ |
2616 } | 2286 index = visible [current + offset]; |
2617 if (chevronRect.contains(x, y)) | 2287 } else { |
2618 { | 2288 if (showChevron) { |
2619 chevron = true; | |
2620 if (chevronImageState !is SELECTED && chevronImageState !is HOT) | |
2621 { | |
2622 chevronImageState = HOT; | |
2623 redraw(chevronRect.x, chevronRect.y, chevronRect.width, | |
2624 chevronRect.height, false); | |
2625 } | |
2626 } | |
2627 if (minImageState !is NORMAL && !minimize) | |
2628 { | |
2629 minImageState = NORMAL; | |
2630 redraw(minRect.x, minRect.y, minRect.width, minRect.height, | |
2631 false); | |
2632 } | |
2633 if (maxImageState !is NORMAL && !maximize) | |
2634 { | |
2635 maxImageState = NORMAL; | |
2636 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, | |
2637 false); | |
2638 } | |
2639 if (chevronImageState !is NORMAL && !chevron) | |
2640 { | |
2641 chevronImageState = NORMAL; | |
2642 redraw(chevronRect.x, chevronRect.y, chevronRect.width, | |
2643 chevronRect.height, false); | |
2644 } | |
2645 for (int i = 0; i < items.length; i++) | |
2646 { | |
2647 CTabItem item = items[i]; | |
2648 close = false; | |
2649 if (item.getBounds().contains(x, y)) | |
2650 { | |
2651 close = true; | |
2652 if (item.closeRect.contains(x, y)) | |
2653 { | |
2654 if (item.closeImageState !is SELECTED && item.closeImageState !is HOT) | |
2655 { | |
2656 item.closeImageState = HOT; | |
2657 redraw(item.closeRect.x, item.closeRect.y, | |
2658 item.closeRect.width, | |
2659 item.closeRect.height, false); | |
2660 } | |
2661 } | |
2662 else | |
2663 { | |
2664 if (item.closeImageState !is NORMAL) | |
2665 { | |
2666 item.closeImageState = NORMAL; | |
2667 redraw(item.closeRect.x, item.closeRect.y, | |
2668 item.closeRect.width, | |
2669 item.closeRect.height, false); | |
2670 } | |
2671 } | |
2672 } | |
2673 if (i !is selectedIndex && item.closeImageState !is NONE && !close) | |
2674 { | |
2675 item.closeImageState = NONE; | |
2676 redraw(item.closeRect.x, item.closeRect.y, | |
2677 item.closeRect.width, item.closeRect.height, | |
2678 false); | |
2679 } | |
2680 if (i is selectedIndex && item.closeImageState !is NORMAL && !close) | |
2681 { | |
2682 item.closeImageState = NORMAL; | |
2683 redraw(item.closeRect.x, item.closeRect.y, | |
2684 item.closeRect.width, item.closeRect.height, | |
2685 false); | |
2686 } | |
2687 } | |
2688 break; | |
2689 } | |
2690 case DWT.MouseUp: | |
2691 { | |
2692 if (event.button !is 1) | |
2693 return; | |
2694 if (chevronRect.contains(x, y)) | |
2695 { | |
2696 bool selected = chevronImageState is SELECTED; | |
2697 if (!selected) | |
2698 return; | |
2699 CTabFolderEvent e = new CTabFolderEvent(this); | 2289 CTabFolderEvent e = new CTabFolderEvent(this); |
2700 e.widget = this; | 2290 e.widget = this; |
2701 e.time = event.time; | 2291 e.time = event.time; |
2702 e.x = chevronRect.x; | 2292 e.x = chevronRect.x; |
2703 e.y = chevronRect.y; | 2293 e.y = chevronRect.y; |
2704 e.width = chevronRect.width; | 2294 e.width = chevronRect.width; |
2705 e.height = chevronRect.height; | 2295 e.height = chevronRect.height; |
2706 e.doit = true; | 2296 e.doit = true; |
2707 for (int i = 0; i < folderListeners.length; i++) | 2297 for (int i = 0; i < folderListeners.length; i++) { |
2708 { | |
2709 folderListeners[i].showList(e); | 2298 folderListeners[i].showList(e); |
2710 } | 2299 } |
2711 if (e.doit && !isDisposed()) | 2300 if (e.doit && !isDisposed()) { |
2712 { | |
2713 showList(chevronRect); | 2301 showList(chevronRect); |
2714 } | 2302 } |
2715 return; | 2303 } |
2716 } | 2304 return true; |
2717 if (minRect.contains(x, y)) | 2305 } |
2718 { | 2306 } |
2719 bool selected = minImageState is SELECTED; | 2307 } |
2720 minImageState = HOT; | 2308 setSelection (index, true); |
2721 redraw(minRect.x, minRect.y, minRect.width, minRect.height, | 2309 return true; |
2722 false); | 2310 } |
2723 if (!selected) | 2311 void onPaint(Event event) { |
2724 return; | 2312 if (inDispose) return; |
2725 CTabFolderEvent e = new CTabFolderEvent(this); | 2313 Font font = getFont(); |
2726 e.widget = this; | 2314 if (oldFont is null || oldFont!=font) { |
2727 e.time = event.time; | 2315 // handle case where default font changes |
2728 for (int i = 0; i < folderListeners.length; i++) | 2316 oldFont = font; |
2729 { | 2317 if (!updateTabHeight(false)) { |
2730 if (minimized) | |
2731 { | |
2732 folderListeners[i].restore(e); | |
2733 } | |
2734 else | |
2735 { | |
2736 folderListeners[i].minimize(e); | |
2737 } | |
2738 } | |
2739 return; | |
2740 } | |
2741 if (maxRect.contains(x, y)) | |
2742 { | |
2743 bool selected = maxImageState is SELECTED; | |
2744 maxImageState = HOT; | |
2745 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, | |
2746 false); | |
2747 if (!selected) | |
2748 return; | |
2749 CTabFolderEvent e = new CTabFolderEvent(this); | |
2750 e.widget = this; | |
2751 e.time = event.time; | |
2752 for (int i = 0; i < folderListeners.length; i++) | |
2753 { | |
2754 if (maximized) | |
2755 { | |
2756 folderListeners[i].restore(e); | |
2757 } | |
2758 else | |
2759 { | |
2760 folderListeners[i].maximize(e); | |
2761 } | |
2762 } | |
2763 return; | |
2764 } | |
2765 CTabItem item = null; | |
2766 if (single) | |
2767 { | |
2768 if (selectedIndex !is -1) | |
2769 { | |
2770 Rectangle bounds = items[selectedIndex].getBounds(); | |
2771 if (bounds.contains(x, y)) | |
2772 { | |
2773 item = items[selectedIndex]; | |
2774 } | |
2775 } | |
2776 } | |
2777 else | |
2778 { | |
2779 for (int i = 0; i < items.length; i++) | |
2780 { | |
2781 Rectangle bounds = items[i].getBounds(); | |
2782 if (bounds.contains(x, y)) | |
2783 { | |
2784 item = items[i]; | |
2785 } | |
2786 } | |
2787 } | |
2788 if (item !is null) | |
2789 { | |
2790 if (item.closeRect.contains(x, y)) | |
2791 { | |
2792 bool selected = item.closeImageState is SELECTED; | |
2793 item.closeImageState = HOT; | |
2794 redraw(item.closeRect.x, item.closeRect.y, | |
2795 item.closeRect.width, item.closeRect.height, | |
2796 false); | |
2797 if (!selected) | |
2798 return; | |
2799 CTabFolderEvent e = new CTabFolderEvent(this); | |
2800 e.widget = this; | |
2801 e.time = event.time; | |
2802 e.item = item; | |
2803 e.doit = true; | |
2804 for (int j = 0; j < folderListeners.length; j++) | |
2805 { | |
2806 CTabFolder2Listener listener = folderListeners[j]; | |
2807 listener.close(e); | |
2808 } | |
2809 for (int j = 0; j < tabListeners.length; j++) | |
2810 { | |
2811 CTabFolderListener listener = tabListeners[j]; | |
2812 listener.itemClosed(e); | |
2813 } | |
2814 if (e.doit) | |
2815 item.dispose(); | |
2816 if (!isDisposed() && item.isDisposed()) | |
2817 { | |
2818 Display display = getDisplay(); | |
2819 Point pt = display.getCursorLocation(); | |
2820 pt = display.map(null, this, pt.x, pt.y); | |
2821 CTabItem nextItem = getItem(pt); | |
2822 if (nextItem !is null) | |
2823 { | |
2824 if (nextItem.closeRect.contains(pt)) | |
2825 { | |
2826 if (nextItem.closeImageState !is SELECTED && nextItem.closeImageState !is HOT) | |
2827 { | |
2828 nextItem.closeImageState = HOT; | |
2829 redraw(nextItem.closeRect.x, | |
2830 nextItem.closeRect.y, | |
2831 nextItem.closeRect.width, | |
2832 nextItem.closeRect.height, | |
2833 false); | |
2834 } | |
2835 } | |
2836 else | |
2837 { | |
2838 if (nextItem.closeImageState !is NORMAL) | |
2839 { | |
2840 nextItem.closeImageState = NORMAL; | |
2841 redraw(nextItem.closeRect.x, | |
2842 nextItem.closeRect.y, | |
2843 nextItem.closeRect.width, | |
2844 nextItem.closeRect.height, | |
2845 false); | |
2846 } | |
2847 } | |
2848 } | |
2849 } | |
2850 return; | |
2851 } | |
2852 } | |
2853 } | |
2854 } | |
2855 } | |
2856 | |
2857 bool onPageTraversal (Event event) | |
2858 { | |
2859 int count = items.length; | |
2860 if (count is 0) | |
2861 return false; | |
2862 int index = selectedIndex; | |
2863 if (index is -1) | |
2864 { | |
2865 index = 0; | |
2866 } | |
2867 else | |
2868 { | |
2869 int offset = (event.detail is DWT.TRAVERSE_PAGE_NEXT) ? 1 : -1; | |
2870 if (!mru) | |
2871 { | |
2872 index = (selectedIndex + offset + count) % count; | |
2873 } | |
2874 else | |
2875 { | |
2876 int[] visible = new int[items.length]; | |
2877 int idx = 0; | |
2878 int current = -1; | |
2879 for (int i = 0; i < items.length; i++) | |
2880 { | |
2881 if (items[i].showing) | |
2882 { | |
2883 if (i is selectedIndex) | |
2884 current = idx; | |
2885 visible[idx++] = i; | |
2886 } | |
2887 } | |
2888 if (current + offset >= 0 && current + offset < idx) | |
2889 { | |
2890 index = visible[current + offset]; | |
2891 } | |
2892 else | |
2893 { | |
2894 if (showChevron) | |
2895 { | |
2896 CTabFolderEvent e = new CTabFolderEvent(this); | |
2897 e.widget = this; | |
2898 e.time = event.time; | |
2899 e.x = chevronRect.x; | |
2900 e.y = chevronRect.y; | |
2901 e.width = chevronRect.width; | |
2902 e.height = chevronRect.height; | |
2903 e.doit = true; | |
2904 for (int i = 0; i < folderListeners.length; i++) | |
2905 { | |
2906 folderListeners[i].showList(e); | |
2907 } | |
2908 if (e.doit && !isDisposed()) | |
2909 { | |
2910 showList(chevronRect); | |
2911 } | |
2912 } | |
2913 return true; | |
2914 } | |
2915 } | |
2916 } | |
2917 setSelection(index, true); | |
2918 return true; | |
2919 } | |
2920 | |
2921 void onPaint (Event event) | |
2922 { | |
2923 if (inDispose) | |
2924 return; | |
2925 Font font = getFont(); | |
2926 if (oldFont is null || !oldFont.opEquals(font)) | |
2927 { | |
2928 // handle case where default font changes | |
2929 oldFont = font; | |
2930 if (!updateTabHeight(false)) | |
2931 { | |
2932 updateItems(); | |
2933 redraw(); | |
2934 return; | |
2935 } | |
2936 } | |
2937 | |
2938 GC gc = event.gc; | |
2939 Font gcFont = gc.getFont(); | |
2940 Color gcBackground = gc.getBackground(); | |
2941 Color gcForeground = gc.getForeground(); | |
2942 | |
2943 // Useful for debugging paint problems | |
2944 //{ | |
2945 //Point size = getSize(); | |
2946 //gc.setBackground(getDisplay().getSystemColor(DWT.COLOR_GREEN)); | |
2947 //gc.fillRectangle(-10, -10, size.x + 20, size.y+20); | |
2948 //} | |
2949 | |
2950 drawBody(event); | |
2951 | |
2952 gc.setFont(gcFont); | |
2953 gc.setForeground(gcForeground); | |
2954 gc.setBackground(gcBackground); | |
2955 | |
2956 drawTabArea(event); | |
2957 | |
2958 gc.setFont(gcFont); | |
2959 gc.setForeground(gcForeground); | |
2960 gc.setBackground(gcBackground); | |
2961 } | |
2962 | |
2963 void onResize () | |
2964 { | |
2965 if (updateItems()) | |
2966 redrawTabs(); | |
2967 | |
2968 Point size = getSize(); | |
2969 if (oldSize is null) | |
2970 { | |
2971 redraw(); | |
2972 } | |
2973 else | |
2974 { | |
2975 if (onBottom && size.y !is oldSize.y) | |
2976 { | |
2977 redraw(); | |
2978 } | |
2979 else | |
2980 { | |
2981 int x1 = Math.min(size.x, oldSize.x); | |
2982 if (size.x !is oldSize.x) | |
2983 x1 -= borderRight + highlight_margin + 2; | |
2984 if (!simple) | |
2985 x1 -= 5; // rounded top right corner | |
2986 int y1 = Math.min(size.y, oldSize.y); | |
2987 if (size.y !is oldSize.y) | |
2988 y1 -= borderBottom + highlight_margin; | |
2989 int x2 = Math.max(size.x, oldSize.x); | |
2990 int y2 = Math.max(size.y, oldSize.y); | |
2991 redraw(0, y1, x2, y2 - y1, false); | |
2992 redraw(x1, 0, x2 - x1, y2, false); | |
2993 } | |
2994 } | |
2995 oldSize = size; | |
2996 } | |
2997 | |
2998 void onTraverse (Event event) | |
2999 { | |
3000 switch (event.detail) | |
3001 { | |
3002 case DWT.TRAVERSE_ESCAPE: | |
3003 case DWT.TRAVERSE_RETURN: | |
3004 case DWT.TRAVERSE_TAB_NEXT: | |
3005 case DWT.TRAVERSE_TAB_PREVIOUS: | |
3006 Control focusControl = getDisplay().getFocusControl(); | |
3007 if (focusControl is this) | |
3008 event.doit = true; | |
3009 break; | |
3010 case DWT.TRAVERSE_MNEMONIC: | |
3011 event.doit = onMnemonic(event); | |
3012 if (event.doit) | |
3013 event.detail = DWT.TRAVERSE_NONE; | |
3014 break; | |
3015 case DWT.TRAVERSE_PAGE_NEXT: | |
3016 case DWT.TRAVERSE_PAGE_PREVIOUS: | |
3017 event.doit = onPageTraversal(event); | |
3018 event.detail = DWT.TRAVERSE_NONE; | |
3019 break; | |
3020 } | |
3021 } | |
3022 | |
3023 void redrawTabs () | |
3024 { | |
3025 Point size = getSize(); | |
3026 if (onBottom) | |
3027 { | |
3028 redraw(0, size.y - borderBottom - tabHeight - highlight_header - 1, | |
3029 size.x, borderBottom + tabHeight + highlight_header + 1, | |
3030 false); | |
3031 } | |
3032 else | |
3033 { | |
3034 redraw(0, 0, size.x, borderTop + tabHeight + highlight_header + 1, | |
3035 false); | |
3036 } | |
3037 } | |
3038 | |
3039 /** | |
3040 * Removes the listener. | |
3041 * | |
3042 * @param listener the listener | |
3043 * | |
3044 * @exception IllegalArgumentException <ul> | |
3045 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
3046 * </ul> | |
3047 * | |
3048 * @exception DWTException <ul> | |
3049 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
3050 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
3051 * </ul> | |
3052 * | |
3053 * @see #addCTabFolder2Listener(CTabFolder2Listener) | |
3054 * | |
3055 * @since 3.0 | |
3056 */ | |
3057 public void removeCTabFolder2Listener (CTabFolder2Listener listener) | |
3058 { | |
3059 checkWidget(); | |
3060 if (listener is null) | |
3061 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
3062 if (folderListeners.length is 0) | |
3063 return; | |
3064 int index = -1; | |
3065 for (int i = 0; i < folderListeners.length; i++) | |
3066 { | |
3067 if (listener is folderListeners[i]) | |
3068 { | |
3069 index = i; | |
3070 break; | |
3071 } | |
3072 } | |
3073 if (index is -1) | |
3074 return; | |
3075 if (folderListeners.length is 1) | |
3076 { | |
3077 folderListeners = new CTabFolder2Listener[0]; | |
3078 return; | |
3079 } | |
3080 CTabFolder2Listener[] | |
3081 newTabListeners = new CTabFolder2Listener[folderListeners.length - 1]; | |
3082 System.arraycopy(folderListeners, 0, newTabListeners, 0, index); | |
3083 System.arraycopy(folderListeners, index + 1, newTabListeners, index, | |
3084 folderListeners.length - index - 1); | |
3085 folderListeners = newTabListeners; | |
3086 } | |
3087 | |
3088 /** | |
3089 * Removes the listener. | |
3090 * | |
3091 * @param listener the listener | |
3092 * | |
3093 * @exception IllegalArgumentException <ul> | |
3094 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
3095 * </ul> | |
3096 * | |
3097 * @exception DWTException <ul> | |
3098 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
3099 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
3100 * </ul> | |
3101 * | |
3102 * @deprecated see removeCTabFolderCloseListener(CTabFolderListener) | |
3103 */ | |
3104 public void removeCTabFolderListener (CTabFolderListener listener) | |
3105 { | |
3106 checkWidget(); | |
3107 if (listener is null) | |
3108 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
3109 if (tabListeners.length is 0) | |
3110 return; | |
3111 int index = -1; | |
3112 for (int i = 0; i < tabListeners.length; i++) | |
3113 { | |
3114 if (listener is tabListeners[i]) | |
3115 { | |
3116 index = i; | |
3117 break; | |
3118 } | |
3119 } | |
3120 if (index is -1) | |
3121 return; | |
3122 if (tabListeners.length is 1) | |
3123 { | |
3124 tabListeners = new CTabFolderListener[0]; | |
3125 return; | |
3126 } | |
3127 CTabFolderListener[] | |
3128 newTabListeners = new CTabFolderListener[tabListeners.length - 1]; | |
3129 System.arraycopy(tabListeners, 0, newTabListeners, 0, index); | |
3130 System.arraycopy(tabListeners, index + 1, newTabListeners, index, | |
3131 tabListeners.length - index - 1); | |
3132 tabListeners = newTabListeners; | |
3133 } | |
3134 | |
3135 /** | |
3136 * Removes the listener from the collection of listeners who will | |
3137 * be notified when the user changes the receiver's selection. | |
3138 * | |
3139 * @param listener the listener which should no longer be notified | |
3140 * | |
3141 * @exception IllegalArgumentException <ul> | |
3142 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
3143 * </ul> | |
3144 * @exception DWTException <ul> | |
3145 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3146 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3147 * </ul> | |
3148 * | |
3149 * @see SelectionListener | |
3150 * @see #addSelectionListener | |
3151 */ | |
3152 public void removeSelectionListener (SelectionListener listener) | |
3153 { | |
3154 checkWidget(); | |
3155 if (listener is null) | |
3156 { | |
3157 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
3158 } | |
3159 removeListener(DWT.Selection, listener); | |
3160 removeListener(DWT.DefaultSelection, listener); | |
3161 } | |
3162 | |
3163 public void setBackground (Color color) | |
3164 { | |
3165 super.setBackground(color); | |
3166 redraw(); | |
3167 } | |
3168 | |
3169 /** | |
3170 * Specify a gradient of colours to be drawn in the background of the unselected tabs. | |
3171 * For example to draw a gradient that varies from dark blue to blue and then to | |
3172 * white, use the following call to setBackground: | |
3173 * <pre> | |
3174 * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), | |
3175 * display.getSystemColor(DWT.COLOR_BLUE), | |
3176 * display.getSystemColor(DWT.COLOR_WHITE), | |
3177 * display.getSystemColor(DWT.COLOR_WHITE)}, | |
3178 * new int[] {25, 50, 100}); | |
3179 * </pre> | |
3180 * | |
3181 * @param colors an array of Color that specifies the colors to appear in the gradient | |
3182 * in order of appearance left to right. The value <code>null</code> clears the | |
3183 * background gradient. The value <code>null</code> can be used inside the array of | |
3184 * Color to specify the background color. | |
3185 * @param percents an array of integers between 0 and 100 specifying the percent of the width | |
3186 * of the widget at which the color should change. The size of the percents array must be one | |
3187 * less than the size of the colors array. | |
3188 * | |
3189 * @exception DWTException <ul> | |
3190 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
3191 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
3192 * </ul> | |
3193 * | |
3194 * @since 3.0 | |
3195 */ | |
3196 void setBackground (Color[] colors, int[] percents) | |
3197 { | |
3198 setBackground(colors, percents, false); | |
3199 } | |
3200 | |
3201 /** | |
3202 * Specify a gradient of colours to be drawn in the background of the unselected tab. | |
3203 * For example to draw a vertical gradient that varies from dark blue to blue and then to | |
3204 * white, use the following call to setBackground: | |
3205 * <pre> | |
3206 * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), | |
3207 * display.getSystemColor(DWT.COLOR_BLUE), | |
3208 * display.getSystemColor(DWT.COLOR_WHITE), | |
3209 * display.getSystemColor(DWT.COLOR_WHITE)}, | |
3210 * new int[] {25, 50, 100}, true); | |
3211 * </pre> | |
3212 * | |
3213 * @param colors an array of Color that specifies the colors to appear in the gradient | |
3214 * in order of appearance left to right. The value <code>null</code> clears the | |
3215 * background gradient. The value <code>null</code> can be used inside the array of | |
3216 * Color to specify the background color. | |
3217 * @param percents an array of integers between 0 and 100 specifying the percent of the width | |
3218 * of the widget at which the color should change. The size of the percents array must be one | |
3219 * less than the size of the colors array. | |
3220 * | |
3221 * @param vertical indicate the direction of the gradient. True is vertical and false is horizontal. | |
3222 * | |
3223 * @exception DWTException <ul> | |
3224 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
3225 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
3226 * </ul> | |
3227 * | |
3228 * @since 3.0 | |
3229 */ | |
3230 void setBackground (Color[] colors, int[] percents, bool vertical) | |
3231 { | |
3232 checkWidget(); | |
3233 if (colors !is null) | |
3234 { | |
3235 if (percents is null || percents.length !is colors.length - 1) | |
3236 { | |
3237 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
3238 } | |
3239 for (int i = 0; i < percents.length; i++) | |
3240 { | |
3241 if (percents[i] < 0 || percents[i] > 100) | |
3242 { | |
3243 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
3244 } | |
3245 if (i > 0 && percents[i] < percents[i - 1]) | |
3246 { | |
3247 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
3248 } | |
3249 } | |
3250 if (getDisplay().getDepth() < 15) | |
3251 { | |
3252 // Don't use gradients on low color displays | |
3253 colors = new Color[][colors[colors.length - 1]]; | |
3254 percents = new int[][]; | |
3255 } | |
3256 } | |
3257 | |
3258 // Are these settings the same as before? | |
3259 if (bgImage is null) | |
3260 { | |
3261 if ((gradientColors !is null) && (colors !is null) && (gradientColors.length is colors.length)) | |
3262 { | |
3263 bool same = false; | |
3264 for (int i = 0; i < gradientColors.length; i++) | |
3265 { | |
3266 if (gradientColors[i] is null) | |
3267 { | |
3268 same = colors[i] is null; | |
3269 } | |
3270 else | |
3271 { | |
3272 same = gradientColors[i].opEquals(colors[i]); | |
3273 } | |
3274 if (!same) | |
3275 break; | |
3276 } | |
3277 if (same) | |
3278 { | |
3279 for (int i = 0; i < gradientPercents.length; i++) | |
3280 { | |
3281 same = gradientPercents[i] is percents[i]; | |
3282 if (!same) | |
3283 break; | |
3284 } | |
3285 } | |
3286 if (same && this.gradientVertical is vertical) | |
3287 return; | |
3288 } | |
3289 } | |
3290 else | |
3291 { | |
3292 bgImage = null; | |
3293 } | |
3294 // Store the new settings | |
3295 if (colors is null) | |
3296 { | |
3297 gradientColors = null; | |
3298 gradientPercents = null; | |
3299 gradientVertical = false; | |
3300 setBackground(cast(Color) null); | |
3301 } | |
3302 else | |
3303 { | |
3304 gradientColors = new Color[colors.length]; | |
3305 for (int i = 0; i < colors.length; ++i) | |
3306 { | |
3307 gradientColors[i] = colors[i]; | |
3308 } | |
3309 gradientPercents = new int[percents.length]; | |
3310 for (int i = 0; i < percents.length; ++i) | |
3311 { | |
3312 gradientPercents[i] = percents[i]; | |
3313 } | |
3314 gradientVertical = vertical; | |
3315 setBackground(gradientColors[gradientColors.length - 1]); | |
3316 } | |
3317 | |
3318 // Refresh with the new settings | |
3319 redraw(); | |
3320 } | |
3321 | |
3322 /** | |
3323 * Set the image to be drawn in the background of the unselected tab. Image | |
3324 * is stretched or compressed to cover entire unselected tab area. | |
3325 * | |
3326 * @param image the image to be drawn in the background | |
3327 * | |
3328 * @exception DWTException <ul> | |
3329 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3330 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3331 * </ul> | |
3332 * | |
3333 * @since 3.0 | |
3334 */ | |
3335 void setBackground (Image image) | |
3336 { | |
3337 checkWidget(); | |
3338 if (image is bgImage) | |
3339 return; | |
3340 if (image !is null) | |
3341 { | |
3342 gradientColors = null; | |
3343 gradientPercents = null; | |
3344 } | |
3345 bgImage = image; | |
3346 redraw(); | |
3347 } | |
3348 | |
3349 /** | |
3350 * Toggle the visibility of the border | |
3351 * | |
3352 * @param show true if the border should be displayed | |
3353 * | |
3354 * @exception DWTException <ul> | |
3355 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3356 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3357 * </ul> | |
3358 */ | |
3359 public void setBorderVisible (bool show) | |
3360 { | |
3361 checkWidget(); | |
3362 if ((borderLeft is 1) is show) | |
3363 return; | |
3364 borderLeft = borderRight = show ? 1 : 0; | |
3365 borderTop = onBottom ? borderLeft : 0; | |
3366 borderBottom = onBottom ? 0 : borderLeft; | |
3367 Rectangle rectBefore = getClientArea(); | |
3368 updateItems(); | |
3369 Rectangle rectAfter = getClientArea(); | |
3370 if (!rectBefore.opEquals(rectAfter)) | |
3371 { | |
3372 notifyListeners(DWT.Resize, new Event()); | |
3373 } | |
3374 redraw(); | |
3375 } | |
3376 | |
3377 void setButtonBounds () | |
3378 { | |
3379 Point size = getSize(); | |
3380 int oldX, oldY, oldWidth, oldHeight; | |
3381 // max button | |
3382 oldX = maxRect.x; | |
3383 oldY = maxRect.y; | |
3384 oldWidth = maxRect.width; | |
3385 oldHeight = maxRect.height; | |
3386 maxRect.x = maxRect.y = maxRect.width = maxRect.height = 0; | |
3387 if (showMax) | |
3388 { | |
3389 maxRect.x = size.x - borderRight - BUTTON_SIZE - 3; | |
3390 if (borderRight > 0) | |
3391 maxRect.x += 1; | |
3392 maxRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - BUTTON_SIZE) / 2 : borderTop + (tabHeight - BUTTON_SIZE) / 2; | |
3393 maxRect.width = BUTTON_SIZE; | |
3394 maxRect.height = BUTTON_SIZE; | |
3395 } | |
3396 if (oldX !is maxRect.x || oldWidth !is maxRect.width || oldY !is maxRect.y || oldHeight !is maxRect.height) | |
3397 { | |
3398 int left = Math.min(oldX, maxRect.x); | |
3399 int right = Math.max(oldX + oldWidth, maxRect.x + maxRect.width); | |
3400 int | |
3401 top = onBottom ? size.y - borderBottom - tabHeight : borderTop + 1; | |
3402 redraw(left, top, right - left, tabHeight, false); | |
3403 } | |
3404 | |
3405 // min button | |
3406 oldX = minRect.x; | |
3407 oldY = minRect.y; | |
3408 oldWidth = minRect.width; | |
3409 oldHeight = minRect.height; | |
3410 minRect.x = minRect.y = minRect.width = minRect.height = 0; | |
3411 if (showMin) | |
3412 { | |
3413 minRect.x = size.x - borderRight - maxRect.width - BUTTON_SIZE - 3; | |
3414 if (borderRight > 0) | |
3415 minRect.x += 1; | |
3416 minRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - BUTTON_SIZE) / 2 : borderTop + (tabHeight - BUTTON_SIZE) / 2; | |
3417 minRect.width = BUTTON_SIZE; | |
3418 minRect.height = BUTTON_SIZE; | |
3419 } | |
3420 if (oldX !is minRect.x || oldWidth !is minRect.width || oldY !is minRect.y || oldHeight !is minRect.height) | |
3421 { | |
3422 int left = Math.min(oldX, minRect.x); | |
3423 int right = Math.max(oldX + oldWidth, minRect.x + minRect.width); | |
3424 int | |
3425 top = onBottom ? size.y - borderBottom - tabHeight : borderTop + 1; | |
3426 redraw(left, top, right - left, tabHeight, false); | |
3427 } | |
3428 | |
3429 // top right control | |
3430 oldX = topRightRect.x; | |
3431 oldY = topRightRect.y; | |
3432 oldWidth = topRightRect.width; | |
3433 oldHeight = topRightRect.height; | |
3434 topRightRect.x = topRightRect.y = topRightRect.width = topRightRect.height = 0; | |
3435 if (topRight !is null) | |
3436 { | |
3437 switch (topRightAlignment) | |
3438 { | |
3439 case DWT.FILL: | |
3440 { | |
3441 int | |
3442 rightEdge = size.x - borderRight - 3 - maxRect.width - minRect.width; | |
3443 if (!simple && borderRight > 0 && !showMax && !showMin) | |
3444 rightEdge -= 2; | |
3445 if (single) | |
3446 { | |
3447 if (items.length is 0 || selectedIndex is -1) | |
3448 { | |
3449 topRightRect.x = borderLeft + 3; | |
3450 topRightRect.width = rightEdge - topRightRect.x; | |
3451 } | |
3452 else | |
3453 { | |
3454 // fill size is 0 if item compressed | |
3455 CTabItem item = items[selectedIndex]; | |
3456 if (item.x + item.width + 7 + 3 * BUTTON_SIZE / 2 >= rightEdge) | |
3457 break; | |
3458 topRightRect.x = item.x + item.width + 7 + 3 * BUTTON_SIZE / 2; | |
3459 topRightRect.width = rightEdge - topRightRect.x; | |
3460 } | |
3461 } | |
3462 else | |
3463 { | |
3464 // fill size is 0 if chevron showing | |
3465 if (showChevron) | |
3466 break; | |
3467 if (items.length is 0) | |
3468 { | |
3469 topRightRect.x = borderLeft + 3; | |
3470 } | |
3471 else | |
3472 { | |
3473 CTabItem item = items[items.length - 1]; | |
3474 topRightRect.x = item.x + item.width; | |
3475 if (!simple && items.length - 1 is selectedIndex) | |
3476 topRightRect.x += curveWidth - curveIndent; | |
3477 } | |
3478 topRightRect.width = Math.max(0, | |
3479 rightEdge - topRightRect.x); | |
3480 } | |
3481 topRightRect.y = onBottom ? size.y - borderBottom - tabHeight : borderTop + 1; | |
3482 topRightRect.height = tabHeight - 1; | |
3483 break; | |
3484 } | |
3485 case DWT.RIGHT: | |
3486 { | |
3487 Point topRightSize = topRight.computeSize(DWT.DEFAULT, | |
3488 tabHeight, false); | |
3489 int | |
3490 rightEdge = size.x - borderRight - 3 - maxRect.width - minRect.width; | |
3491 if (!simple && borderRight > 0 && !showMax && !showMin) | |
3492 rightEdge -= 2; | |
3493 topRightRect.x = rightEdge - topRightSize.x; | |
3494 topRightRect.width = topRightSize.x; | |
3495 topRightRect.y = onBottom ? size.y - borderBottom - tabHeight : borderTop + 1; | |
3496 topRightRect.height = tabHeight - 1; | |
3497 } | |
3498 } | |
3499 topRight.setBounds(topRightRect); | |
3500 } | |
3501 if (oldX !is topRightRect.x || oldWidth !is topRightRect.width || oldY !is topRightRect.y || oldHeight !is topRightRect.height) | |
3502 { | |
3503 int left = Math.min(oldX, topRightRect.x); | |
3504 int right = Math.max(oldX + oldWidth, | |
3505 topRightRect.x + topRightRect.width); | |
3506 int | |
3507 top = onBottom ? size.y - borderBottom - tabHeight : borderTop + 1; | |
3508 redraw(left, top, right - left, tabHeight, false); | |
3509 } | |
3510 | |
3511 // chevron button | |
3512 oldX = chevronRect.x; | |
3513 oldY = chevronRect.y; | |
3514 oldWidth = chevronRect.width; | |
3515 oldHeight = chevronRect.height; | |
3516 chevronRect.x = chevronRect.y = chevronRect.height = chevronRect.width = 0; | |
3517 if (single) | |
3518 { | |
3519 if (selectedIndex is -1 || items.length > 1) | |
3520 { | |
3521 chevronRect.width = 3 * BUTTON_SIZE / 2; | |
3522 chevronRect.height = BUTTON_SIZE; | |
3523 chevronRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - chevronRect.height) / 2 : borderTop + (tabHeight - chevronRect.height) / 2; | |
3524 if (selectedIndex is -1) | |
3525 { | |
3526 chevronRect.x = size.x - borderRight - 3 - minRect.width - maxRect.width - topRightRect.width - chevronRect.width; | |
3527 } | |
3528 else | |
3529 { | |
3530 CTabItem item = items[selectedIndex]; | |
3531 int | |
3532 w = size.x - borderRight - 3 - minRect.width - maxRect.width - chevronRect.width; | |
3533 if (topRightRect.width > 0) | |
3534 w -= topRightRect.width + 3; | |
3535 chevronRect.x = Math.min(item.x + item.width + 3, w); | |
3536 } | |
3537 if (borderRight > 0) | |
3538 chevronRect.x += 1; | |
3539 } | |
3540 } | |
3541 else | |
3542 { | |
3543 if (showChevron) | |
3544 { | |
3545 chevronRect.width = 3 * BUTTON_SIZE / 2; | |
3546 chevronRect.height = BUTTON_SIZE; | |
3547 int i = 0, lastIndex = -1; | |
3548 while (i < priority.length && items[priority[i]].showing) | |
3549 { | |
3550 lastIndex = Math.max(lastIndex, priority[i++]); | |
3551 } | |
3552 if (lastIndex is -1) | |
3553 lastIndex = firstIndex; | |
3554 CTabItem lastItem = items[lastIndex]; | |
3555 int w = lastItem.x + lastItem.width + 3; | |
3556 if (!simple && lastIndex is selectedIndex) | |
3557 w += curveWidth - 2 * curveIndent; | |
3558 chevronRect.x = Math.min(w, getRightItemEdge()); | |
3559 chevronRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - chevronRect.height) / 2 : borderTop + (tabHeight - chevronRect.height) / 2; | |
3560 } | |
3561 } | |
3562 if (oldX !is chevronRect.x || oldWidth !is chevronRect.width || oldY !is chevronRect.y || oldHeight !is chevronRect.height) | |
3563 { | |
3564 int left = Math.min(oldX, chevronRect.x); | |
3565 int right = Math.max(oldX + oldWidth, | |
3566 chevronRect.x + chevronRect.width); | |
3567 int | |
3568 top = onBottom ? size.y - borderBottom - tabHeight : borderTop + 1; | |
3569 redraw(left, top, right - left, tabHeight, false); | |
3570 } | |
3571 } | |
3572 | |
3573 public void setFont (Font font) | |
3574 { | |
3575 checkWidget(); | |
3576 if (font !is null && font.opEquals(getFont())) | |
3577 return; | |
3578 super.setFont(font); | |
3579 oldFont = getFont(); | |
3580 if (!updateTabHeight(false)) | |
3581 { | |
3582 updateItems(); | 2318 updateItems(); |
3583 redraw(); | 2319 redraw(); |
3584 } | 2320 return; |
3585 } | 2321 } |
3586 | 2322 } |
3587 public void setForeground (Color color) | 2323 |
3588 { | 2324 GC gc = event.gc; |
3589 super.setForeground(color); | 2325 Font gcFont = gc.getFont(); |
2326 Color gcBackground = gc.getBackground(); | |
2327 Color gcForeground = gc.getForeground(); | |
2328 | |
2329 // Useful for debugging paint problems | |
2330 //{ | |
2331 //Point size = getSize(); | |
2332 //gc.setBackground(getDisplay().getSystemColor(DWT.COLOR_GREEN)); | |
2333 //gc.fillRectangle(-10, -10, size.x + 20, size.y+20); | |
2334 //} | |
2335 | |
2336 drawBody(event); | |
2337 | |
2338 gc.setFont(gcFont); | |
2339 gc.setForeground(gcForeground); | |
2340 gc.setBackground(gcBackground); | |
2341 | |
2342 drawTabArea(event); | |
2343 | |
2344 gc.setFont(gcFont); | |
2345 gc.setForeground(gcForeground); | |
2346 gc.setBackground(gcBackground); | |
2347 } | |
2348 | |
2349 void onResize() { | |
2350 if (updateItems()) redrawTabs(); | |
2351 | |
2352 Point size = getSize(); | |
2353 if (oldSize is null) { | |
3590 redraw(); | 2354 redraw(); |
3591 } | 2355 } else { |
3592 | 2356 if (onBottom && size.y !is oldSize.y) { |
3593 /** | 2357 redraw(); |
3594 * Display an insert marker before or after the specified tab item. | 2358 } else { |
3595 * | 2359 int x1 = Math.min(size.x, oldSize.x); |
3596 * A value of null will clear the mark. | 2360 if (size.x !is oldSize.x) x1 -= borderRight + highlight_margin + 2; |
3597 * | 2361 if (!simple) x1 -= 5; // rounded top right corner |
3598 * @param item the item with which the mark is associated or null | 2362 int y1 = Math.min(size.y, oldSize.y); |
3599 * | 2363 if (size.y !is oldSize.y) y1 -= borderBottom + highlight_margin; |
3600 * @param after true if the mark should be displayed after the specified item | 2364 int x2 = Math.max(size.x, oldSize.x); |
3601 * | 2365 int y2 = Math.max(size.y, oldSize.y); |
3602 * @exception DWTException <ul> | 2366 redraw(0, y1, x2, y2 - y1, false); |
3603 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 2367 redraw(x1, 0, x2 - x1, y2, false); |
3604 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 2368 } |
3605 * </ul> | 2369 } |
3606 */ | 2370 oldSize = size; |
3607 public void setInsertMark (CTabItem item, bool after) | 2371 } |
3608 { | 2372 void onTraverse (Event event) { |
3609 checkWidget(); | 2373 switch (event.detail) { |
3610 } | 2374 case DWT.TRAVERSE_ESCAPE: |
3611 | 2375 case DWT.TRAVERSE_RETURN: |
3612 /** | 2376 case DWT.TRAVERSE_TAB_NEXT: |
3613 * Display an insert marker before or after the specified tab item. | 2377 case DWT.TRAVERSE_TAB_PREVIOUS: |
3614 * | 2378 Control focusControl = getDisplay().getFocusControl(); |
3615 * A value of -1 will clear the mark. | 2379 if (focusControl is this) event.doit = true; |
3616 * | 2380 break; |
3617 * @param index the index of the item with which the mark is associated or null | 2381 case DWT.TRAVERSE_MNEMONIC: |
3618 * | 2382 event.doit = onMnemonic(event); |
3619 * @param after true if the mark should be displayed after the specified item | 2383 if (event.doit) event.detail = DWT.TRAVERSE_NONE; |
3620 * | 2384 break; |
3621 * @exception IllegalArgumentException<ul> | 2385 case DWT.TRAVERSE_PAGE_NEXT: |
3622 * </ul> | 2386 case DWT.TRAVERSE_PAGE_PREVIOUS: |
3623 * | 2387 event.doit = onPageTraversal(event); |
3624 * @exception DWTException <ul> | 2388 event.detail = DWT.TRAVERSE_NONE; |
3625 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 2389 break; |
3626 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 2390 default: |
3627 * </ul> | 2391 } |
3628 */ | 2392 } |
3629 public void setInsertMark (int index, bool after) | 2393 void redrawTabs() { |
3630 { | 2394 Point size = getSize(); |
3631 checkWidget(); | 2395 if (onBottom) { |
3632 if (index < -1 || index >= getItemCount()) | 2396 redraw(0, size.y - borderBottom - tabHeight - highlight_header - 1, size.x, borderBottom + tabHeight + highlight_header + 1, false); |
3633 { | 2397 } else { |
2398 redraw(0, 0, size.x, borderTop + tabHeight + highlight_header + 1, false); | |
2399 } | |
2400 } | |
2401 /** | |
2402 * Removes the listener. | |
2403 * | |
2404 * @param listener the listener which should no longer be notified | |
2405 * | |
2406 * @exception IllegalArgumentException <ul> | |
2407 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
2408 * </ul> | |
2409 * | |
2410 * @exception DWTException <ul> | |
2411 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
2412 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
2413 * </ul> | |
2414 * | |
2415 * @see #addCTabFolder2Listener(CTabFolder2Listener) | |
2416 * | |
2417 * @since 3.0 | |
2418 */ | |
2419 public void removeCTabFolder2Listener(CTabFolder2Listener listener) { | |
2420 checkWidget(); | |
2421 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
2422 if (folderListeners.length is 0) return; | |
2423 int index = -1; | |
2424 for (int i = 0; i < folderListeners.length; i++) { | |
2425 if (listener is folderListeners[i]){ | |
2426 index = i; | |
2427 break; | |
2428 } | |
2429 } | |
2430 if (index is -1) return; | |
2431 if (folderListeners.length is 1) { | |
2432 folderListeners = new CTabFolder2Listener[0]; | |
2433 return; | |
2434 } | |
2435 CTabFolder2Listener[] newTabListeners = new CTabFolder2Listener[folderListeners.length - 1]; | |
2436 SimpleType!(CTabFolder2Listener).arraycopy(folderListeners, 0, newTabListeners, 0, index); | |
2437 SimpleType!(CTabFolder2Listener).arraycopy(folderListeners, index + 1, newTabListeners, index, folderListeners.length - index - 1); | |
2438 folderListeners = newTabListeners; | |
2439 } | |
2440 /** | |
2441 * Removes the listener. | |
2442 * | |
2443 * @param listener the listener which should no longer be notified | |
2444 * | |
2445 * @exception IllegalArgumentException <ul> | |
2446 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
2447 * </ul> | |
2448 * | |
2449 * @exception DWTException <ul> | |
2450 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
2451 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
2452 * </ul> | |
2453 * | |
2454 * @deprecated see removeCTabFolderCloseListener(CTabFolderListener) | |
2455 */ | |
2456 public void removeCTabFolderListener(CTabFolderListener listener) { | |
2457 checkWidget(); | |
2458 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
2459 if (tabListeners.length is 0) return; | |
2460 int index = -1; | |
2461 for (int i = 0; i < tabListeners.length; i++) { | |
2462 if (listener is tabListeners[i]){ | |
2463 index = i; | |
2464 break; | |
2465 } | |
2466 } | |
2467 if (index is -1) return; | |
2468 if (tabListeners.length is 1) { | |
2469 tabListeners = new CTabFolderListener[0]; | |
2470 return; | |
2471 } | |
2472 CTabFolderListener[] newTabListeners = new CTabFolderListener[tabListeners.length - 1]; | |
2473 SimpleType!(CTabFolderListener).arraycopy(tabListeners, 0, newTabListeners, 0, index); | |
2474 SimpleType!(CTabFolderListener).arraycopy(tabListeners, index + 1, newTabListeners, index, tabListeners.length - index - 1); | |
2475 tabListeners = newTabListeners; | |
2476 } | |
2477 /** | |
2478 * Removes the listener from the collection of listeners who will | |
2479 * be notified when the user changes the receiver's selection. | |
2480 * | |
2481 * @param listener the listener which should no longer be notified | |
2482 * | |
2483 * @exception IllegalArgumentException <ul> | |
2484 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
2485 * </ul> | |
2486 * @exception DWTException <ul> | |
2487 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2488 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2489 * </ul> | |
2490 * | |
2491 * @see SelectionListener | |
2492 * @see #addSelectionListener | |
2493 */ | |
2494 public void removeSelectionListener(SelectionListener listener) { | |
2495 checkWidget(); | |
2496 if (listener is null) { | |
2497 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
2498 } | |
2499 removeListener(DWT.Selection, listener); | |
2500 removeListener(DWT.DefaultSelection, listener); | |
2501 } | |
2502 public override void setBackground (Color color) { | |
2503 super.setBackground(color); | |
2504 redraw(); | |
2505 } | |
2506 /** | |
2507 * Specify a gradient of colours to be drawn in the background of the unselected tabs. | |
2508 * For example to draw a gradient that varies from dark blue to blue and then to | |
2509 * white, use the following call to setBackground: | |
2510 * <pre> | |
2511 * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), | |
2512 * display.getSystemColor(DWT.COLOR_BLUE), | |
2513 * display.getSystemColor(DWT.COLOR_WHITE), | |
2514 * display.getSystemColor(DWT.COLOR_WHITE)}, | |
2515 * new int[] {25, 50, 100}); | |
2516 * </pre> | |
2517 * | |
2518 * @param colors an array of Color that specifies the colors to appear in the gradient | |
2519 * in order of appearance left to right. The value <code>null</code> clears the | |
2520 * background gradient. The value <code>null</code> can be used inside the array of | |
2521 * Color to specify the background color. | |
2522 * @param percents an array of integers between 0 and 100 specifying the percent of the width | |
2523 * of the widget at which the color should change. The size of the percents array must be one | |
2524 * less than the size of the colors array. | |
2525 * | |
2526 * @exception DWTException <ul> | |
2527 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
2528 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
2529 * </ul> | |
2530 * | |
2531 * @since 3.0 | |
2532 */ | |
2533 void setBackground(Color[] colors, int[] percents) { | |
2534 setBackground(colors, percents, false); | |
2535 } | |
2536 /** | |
2537 * Specify a gradient of colours to be drawn in the background of the unselected tab. | |
2538 * For example to draw a vertical gradient that varies from dark blue to blue and then to | |
2539 * white, use the following call to setBackground: | |
2540 * <pre> | |
2541 * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), | |
2542 * display.getSystemColor(DWT.COLOR_BLUE), | |
2543 * display.getSystemColor(DWT.COLOR_WHITE), | |
2544 * display.getSystemColor(DWT.COLOR_WHITE)}, | |
2545 * new int[] {25, 50, 100}, true); | |
2546 * </pre> | |
2547 * | |
2548 * @param colors an array of Color that specifies the colors to appear in the gradient | |
2549 * in order of appearance left to right. The value <code>null</code> clears the | |
2550 * background gradient. The value <code>null</code> can be used inside the array of | |
2551 * Color to specify the background color. | |
2552 * @param percents an array of integers between 0 and 100 specifying the percent of the width | |
2553 * of the widget at which the color should change. The size of the percents array must be one | |
2554 * less than the size of the colors array. | |
2555 * | |
2556 * @param vertical indicate the direction of the gradient. True is vertical and false is horizontal. | |
2557 * | |
2558 * @exception DWTException <ul> | |
2559 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
2560 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
2561 * </ul> | |
2562 * | |
2563 * @since 3.0 | |
2564 */ | |
2565 void setBackground(Color[] colors, int[] percents, bool vertical) { | |
2566 checkWidget(); | |
2567 if (colors !is null) { | |
2568 if (percents is null || percents.length !is colors.length - 1) { | |
3634 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 2569 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
3635 } | 2570 } |
3636 } | 2571 for (int i = 0; i < percents.length; i++) { |
3637 | 2572 if (percents[i] < 0 || percents[i] > 100) { |
3638 bool setItemLocation () | 2573 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
3639 { | 2574 } |
3640 bool changed = false; | 2575 if (i > 0 && percents[i] < percents[i-1]) { |
3641 if (items.length is 0) | 2576 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
3642 return false; | 2577 } |
3643 Point size = getSize(); | 2578 } |
3644 int y = onBottom ? Math.max(borderBottom, | 2579 if (getDisplay().getDepth() < 15) { |
3645 size.y - borderBottom - tabHeight) : borderTop; | 2580 // Don't use gradients on low color displays |
3646 if (single) | 2581 colors = [colors[colors.length - 1]]; |
3647 { | 2582 percents = null; |
3648 int defaultX = getDisplay().getBounds().width + 10; // off screen | 2583 } |
3649 for (int i = 0; i < items.length; i++) | 2584 } |
3650 { | 2585 |
3651 CTabItem item = items[i]; | 2586 // Are these settings the same as before? |
3652 if (i is selectedIndex) | 2587 if (bgImage is null) { |
3653 { | 2588 if ((gradientColors !is null) && (colors !is null) && |
3654 firstIndex = selectedIndex; | 2589 (gradientColors.length is colors.length)) { |
3655 int oldX = item.x, oldY = item.y; | 2590 bool same = false; |
3656 item.x = borderLeft; | 2591 for (int i = 0; i < gradientColors.length; i++) { |
3657 item.y = y; | 2592 if (gradientColors[i] is null) { |
3658 item.showing = true; | 2593 same = colors[i] is null; |
3659 if (showClose || item.showClose) | 2594 } else { |
3660 { | 2595 same = cast(bool)(gradientColors[i]==colors[i]); |
3661 item.closeRect.x = borderLeft + CTabItem.LEFT_MARGIN; | 2596 } |
3662 item.closeRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - BUTTON_SIZE) / 2 : borderTop + (tabHeight - BUTTON_SIZE) / 2; | 2597 if (!same) break; |
2598 } | |
2599 if (same) { | |
2600 for (int i = 0; i < gradientPercents.length; i++) { | |
2601 same = gradientPercents[i] is percents[i]; | |
2602 if (!same) break; | |
2603 } | |
2604 } | |
2605 if (same && this.gradientVertical is vertical) return; | |
2606 } | |
2607 } else { | |
2608 bgImage = null; | |
2609 } | |
2610 // Store the new settings | |
2611 if (colors is null) { | |
2612 gradientColors = null; | |
2613 gradientPercents = null; | |
2614 gradientVertical = false; | |
2615 setBackground(cast(Color)null); | |
2616 } else { | |
2617 gradientColors = new Color[colors.length]; | |
2618 for (int i = 0; i < colors.length; ++i) { | |
2619 gradientColors[i] = colors[i]; | |
2620 } | |
2621 gradientPercents = new int[percents.length]; | |
2622 for (int i = 0; i < percents.length; ++i) { | |
2623 gradientPercents[i] = percents[i]; | |
2624 } | |
2625 gradientVertical = vertical; | |
2626 setBackground(gradientColors[gradientColors.length-1]); | |
2627 } | |
2628 | |
2629 // Refresh with the new settings | |
2630 redraw(); | |
2631 } | |
2632 | |
2633 /** | |
2634 * Set the image to be drawn in the background of the unselected tab. Image | |
2635 * is stretched or compressed to cover entire unselected tab area. | |
2636 * | |
2637 * @param image the image to be drawn in the background | |
2638 * | |
2639 * @exception DWTException <ul> | |
2640 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2641 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2642 * </ul> | |
2643 * | |
2644 * @since 3.0 | |
2645 */ | |
2646 void setBackground(Image image) { | |
2647 checkWidget(); | |
2648 if (image is bgImage) return; | |
2649 if (image !is null) { | |
2650 gradientColors = null; | |
2651 gradientPercents = null; | |
2652 } | |
2653 bgImage = image; | |
2654 redraw(); | |
2655 } | |
2656 /** | |
2657 * Toggle the visibility of the border | |
2658 * | |
2659 * @param show true if the border should be displayed | |
2660 * | |
2661 * @exception DWTException <ul> | |
2662 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2663 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2664 * </ul> | |
2665 */ | |
2666 public void setBorderVisible(bool show) { | |
2667 checkWidget(); | |
2668 if ((borderLeft is 1) is show) return; | |
2669 borderLeft = borderRight = show ? 1 : 0; | |
2670 borderTop = onBottom ? borderLeft : 0; | |
2671 borderBottom = onBottom ? 0 : borderLeft; | |
2672 Rectangle rectBefore = getClientArea(); | |
2673 updateItems(); | |
2674 Rectangle rectAfter = getClientArea(); | |
2675 if (rectBefore!=rectAfter) { | |
2676 notifyListeners(DWT.Resize, new Event()); | |
2677 } | |
2678 redraw(); | |
2679 } | |
2680 void setButtonBounds() { | |
2681 Point size = getSize(); | |
2682 int oldX, oldY, oldWidth, oldHeight; | |
2683 // max button | |
2684 oldX = maxRect.x; | |
2685 oldY = maxRect.y; | |
2686 oldWidth = maxRect.width; | |
2687 oldHeight = maxRect.height; | |
2688 maxRect.x = maxRect.y = maxRect.width = maxRect.height = 0; | |
2689 if (showMax) { | |
2690 maxRect.x = size.x - borderRight - BUTTON_SIZE - 3; | |
2691 if (borderRight > 0) maxRect.x += 1; | |
2692 maxRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - BUTTON_SIZE)/2: borderTop + (tabHeight - BUTTON_SIZE)/2; | |
2693 maxRect.width = BUTTON_SIZE; | |
2694 maxRect.height = BUTTON_SIZE; | |
2695 } | |
2696 if (oldX !is maxRect.x || oldWidth !is maxRect.width || | |
2697 oldY !is maxRect.y || oldHeight !is maxRect.height) { | |
2698 int left = Math.min(oldX, maxRect.x); | |
2699 int right = Math.max(oldX + oldWidth, maxRect.x + maxRect.width); | |
2700 int top = onBottom ? size.y - borderBottom - tabHeight: borderTop + 1; | |
2701 redraw(left, top, right - left, tabHeight, false); | |
2702 } | |
2703 | |
2704 // min button | |
2705 oldX = minRect.x; | |
2706 oldY = minRect.y; | |
2707 oldWidth = minRect.width; | |
2708 oldHeight = minRect.height; | |
2709 minRect.x = minRect.y = minRect.width = minRect.height = 0; | |
2710 if (showMin) { | |
2711 minRect.x = size.x - borderRight - maxRect.width - BUTTON_SIZE - 3; | |
2712 if (borderRight > 0) minRect.x += 1; | |
2713 minRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - BUTTON_SIZE)/2: borderTop + (tabHeight - BUTTON_SIZE)/2; | |
2714 minRect.width = BUTTON_SIZE; | |
2715 minRect.height = BUTTON_SIZE; | |
2716 } | |
2717 if (oldX !is minRect.x || oldWidth !is minRect.width || | |
2718 oldY !is minRect.y || oldHeight !is minRect.height) { | |
2719 int left = Math.min(oldX, minRect.x); | |
2720 int right = Math.max(oldX + oldWidth, minRect.x + minRect.width); | |
2721 int top = onBottom ? size.y - borderBottom - tabHeight: borderTop + 1; | |
2722 redraw(left, top, right - left, tabHeight, false); | |
2723 } | |
2724 | |
2725 // top right control | |
2726 oldX = topRightRect.x; | |
2727 oldY = topRightRect.y; | |
2728 oldWidth = topRightRect.width; | |
2729 oldHeight = topRightRect.height; | |
2730 topRightRect.x = topRightRect.y = topRightRect.width = topRightRect.height = 0; | |
2731 if (topRight !is null) { | |
2732 switch (topRightAlignment) { | |
2733 case DWT.FILL: { | |
2734 int rightEdge = size.x - borderRight - 3 - maxRect.width - minRect.width; | |
2735 if (!simple && borderRight > 0 && !showMax && !showMin) rightEdge -= 2; | |
2736 if (single) { | |
2737 if (items.length is 0 || selectedIndex is -1) { | |
2738 topRightRect.x = borderLeft + 3; | |
2739 topRightRect.width = rightEdge - topRightRect.x; | |
2740 } else { | |
2741 // fill size is 0 if item compressed | |
2742 CTabItem item = items[selectedIndex]; | |
2743 if (item.x + item.width + 7 + 3*BUTTON_SIZE/2 >= rightEdge) break; | |
2744 topRightRect.x = item.x + item.width + 7 + 3*BUTTON_SIZE/2; | |
2745 topRightRect.width = rightEdge - topRightRect.x; | |
3663 } | 2746 } |
3664 if (item.x !is oldX || item.y !is oldY) | 2747 } else { |
3665 changed = true; | 2748 // fill size is 0 if chevron showing |
3666 } | 2749 if (showChevron) break; |
3667 else | 2750 if (items.length is 0) { |
3668 { | 2751 topRightRect.x = borderLeft + 3; |
3669 item.x = defaultX; | 2752 } else { |
3670 item.showing = false; | 2753 CTabItem item = items[items.length - 1]; |
3671 } | 2754 topRightRect.x = item.x + item.width; |
3672 } | 2755 if (!simple && items.length - 1 is selectedIndex) topRightRect.x += curveWidth - curveIndent; |
3673 } | |
3674 else | |
3675 { | |
3676 int rightItemEdge = getRightItemEdge(); | |
3677 int maxWidth = rightItemEdge - borderLeft; | |
3678 int width = 0; | |
3679 for (int i = 0; i < priority.length; i++) | |
3680 { | |
3681 CTabItem item = items[priority[i]]; | |
3682 width += item.width; | |
3683 item.showing = i is 0 ? true : item.width > 0 && width <= maxWidth; | |
3684 if (!simple && priority[i] is selectedIndex) | |
3685 width += curveWidth - 2 * curveIndent; | |
3686 } | |
3687 int x = 0; | |
3688 int defaultX = getDisplay().getBounds().width + 10; // off screen | |
3689 firstIndex = items.length - 1; | |
3690 for (int i = 0; i < items.length; i++) | |
3691 { | |
3692 CTabItem item = items[i]; | |
3693 if (!item.showing) | |
3694 { | |
3695 if (item.x !is defaultX) | |
3696 changed = true; | |
3697 item.x = defaultX; | |
3698 } | |
3699 else | |
3700 { | |
3701 firstIndex = Math.min(firstIndex, i); | |
3702 if (item.x !is x || item.y !is y) | |
3703 changed = true; | |
3704 item.x = x; | |
3705 item.y = y; | |
3706 if (i is selectedIndex) | |
3707 { | |
3708 int edge = Math.min(item.x + item.width, rightItemEdge); | |
3709 item.closeRect.x = edge - CTabItem.RIGHT_MARGIN - BUTTON_SIZE; | |
3710 } | 2756 } |
3711 else | 2757 topRightRect.width = Math.max(0, rightEdge - topRightRect.x); |
3712 { | 2758 } |
3713 item.closeRect.x = item.x + item.width - CTabItem.RIGHT_MARGIN - BUTTON_SIZE; | 2759 topRightRect.y = onBottom ? size.y - borderBottom - tabHeight: borderTop + 1; |
3714 } | 2760 topRightRect.height = tabHeight - 1; |
3715 item.closeRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - BUTTON_SIZE) / 2 : borderTop + (tabHeight - BUTTON_SIZE) / 2; | |
3716 x = x + item.width; | |
3717 if (!simple && i is selectedIndex) | |
3718 x += curveWidth - 2 * curveIndent; | |
3719 } | |
3720 } | |
3721 } | |
3722 return changed; | |
3723 } | |
3724 | |
3725 bool setItemSize () | |
3726 { | |
3727 bool changed = false; | |
3728 if (isDisposed()) | |
3729 return changed; | |
3730 Point size = getSize(); | |
3731 if (size.x <= 0 || size.y <= 0) | |
3732 return changed; | |
3733 xClient = borderLeft + marginWidth + highlight_margin; | |
3734 if (onBottom) | |
3735 { | |
3736 yClient = borderTop + highlight_margin + marginHeight; | |
3737 } | |
3738 else | |
3739 { | |
3740 yClient = borderTop + tabHeight + highlight_header + marginHeight; | |
3741 } | |
3742 showChevron = false; | |
3743 if (single) | |
3744 { | |
3745 showChevron = true; | |
3746 if (selectedIndex !is -1) | |
3747 { | |
3748 CTabItem tab = items[selectedIndex]; | |
3749 GC gc = new GC(this); | |
3750 int width = tab.preferredWidth(gc, true, false); | |
3751 gc.dispose(); | |
3752 width = Math.min(width, getRightItemEdge() - borderLeft); | |
3753 if (tab.height !is tabHeight || tab.width !is width) | |
3754 { | |
3755 changed = true; | |
3756 tab.shortenedText = null; | |
3757 tab.shortenedTextWidth = 0; | |
3758 tab.height = tabHeight; | |
3759 tab.width = width; | |
3760 tab.closeRect.width = tab.closeRect.height = 0; | |
3761 if (showClose || tab.showClose) | |
3762 { | |
3763 tab.closeRect.width = BUTTON_SIZE; | |
3764 tab.closeRect.height = BUTTON_SIZE; | |
3765 } | |
3766 } | |
3767 } | |
3768 return changed; | |
3769 } | |
3770 | |
3771 if (items.length is 0) | |
3772 return changed; | |
3773 | |
3774 int[] widths; | |
3775 GC gc = new GC(this); | |
3776 int tabAreaWidth = size.x - borderLeft - borderRight - 3; | |
3777 if (showMin) | |
3778 tabAreaWidth -= BUTTON_SIZE; | |
3779 if (showMax) | |
3780 tabAreaWidth -= BUTTON_SIZE; | |
3781 if (topRightAlignment is DWT.RIGHT && topRight !is null) | |
3782 { | |
3783 Point rightSize = topRight.computeSize(DWT.DEFAULT, DWT.DEFAULT, | |
3784 false); | |
3785 tabAreaWidth -= rightSize.x + 3; | |
3786 } | |
3787 if (!simple) | |
3788 tabAreaWidth -= curveWidth - 2 * curveIndent; | |
3789 tabAreaWidth = Math.max(0, tabAreaWidth); | |
3790 | |
3791 // First, try the minimum tab size at full compression. | |
3792 int minWidth = 0; | |
3793 int[] minWidths = new int[items.length]; | |
3794 for (int i = 0; i < priority.length; i++) | |
3795 { | |
3796 int index = priority[i]; | |
3797 minWidths[index] = items[index].preferredWidth(gc, | |
3798 index is selectedIndex, true); | |
3799 minWidth += minWidths[index]; | |
3800 if (minWidth > tabAreaWidth) | |
3801 break; | 2761 break; |
3802 } | 2762 } |
3803 if (minWidth > tabAreaWidth) | 2763 case DWT.RIGHT: { |
3804 { | 2764 Point topRightSize = topRight.computeSize(DWT.DEFAULT, tabHeight, false); |
3805 // full compression required and a chevron | 2765 int rightEdge = size.x - borderRight - 3 - maxRect.width - minRect.width; |
3806 showChevron = items.length > 1; | 2766 if (!simple && borderRight > 0 && !showMax && !showMin) rightEdge -= 2; |
3807 if (showChevron) | 2767 topRightRect.x = rightEdge - topRightSize.x; |
3808 tabAreaWidth -= 3 * BUTTON_SIZE / 2; | 2768 topRightRect.width = topRightSize.x; |
3809 widths = minWidths; | 2769 topRightRect.y = onBottom ? size.y - borderBottom - tabHeight: borderTop + 1; |
3810 int index = selectedIndex !is -1 ? selectedIndex : 0; | 2770 topRightRect.height = tabHeight - 1; |
3811 if (tabAreaWidth < widths[index]) | 2771 } |
3812 { | 2772 default: |
3813 widths[index] = Math.max(0, tabAreaWidth); | 2773 } |
3814 } | 2774 topRight.setBounds(topRightRect); |
3815 } | 2775 } |
3816 else | 2776 if (oldX !is topRightRect.x || oldWidth !is topRightRect.width || |
3817 { | 2777 oldY !is topRightRect.y || oldHeight !is topRightRect.height) { |
3818 int maxWidth = 0; | 2778 int left = Math.min(oldX, topRightRect.x); |
3819 int[] maxWidths = new int[items.length]; | 2779 int right = Math.max(oldX + oldWidth, topRightRect.x + topRightRect.width); |
3820 for (int i = 0; i < items.length; i++) | 2780 int top = onBottom ? size.y - borderBottom - tabHeight : borderTop + 1; |
3821 { | 2781 redraw(left, top, right - left, tabHeight, false); |
3822 maxWidths[i] = items[i].preferredWidth(gc, i is selectedIndex, | 2782 } |
3823 false); | 2783 |
3824 maxWidth += maxWidths[i]; | 2784 // chevron button |
3825 } | 2785 oldX = chevronRect.x; |
3826 if (maxWidth <= tabAreaWidth) | 2786 oldY = chevronRect.y; |
3827 { | 2787 oldWidth = chevronRect.width; |
3828 // no compression required | 2788 oldHeight = chevronRect.height; |
3829 widths = maxWidths; | 2789 chevronRect.x = chevronRect.y = chevronRect.height = chevronRect.width = 0; |
3830 } | 2790 if (single) { |
3831 else | 2791 if (selectedIndex is -1 || items.length > 1) { |
3832 { | 2792 chevronRect.width = 3*BUTTON_SIZE/2; |
3833 // determine compression for each item | 2793 chevronRect.height = BUTTON_SIZE; |
3834 int extra = (tabAreaWidth - minWidth) / items.length; | 2794 chevronRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - chevronRect.height)/2 : borderTop + (tabHeight - chevronRect.height)/2; |
3835 while (true) | 2795 if (selectedIndex is -1) { |
3836 { | 2796 chevronRect.x = size.x - borderRight - 3 - minRect.width - maxRect.width - topRightRect.width - chevronRect.width; |
3837 int large = 0, totalWidth = 0; | 2797 } else { |
3838 for (int i = 0; i < items.length; i++) | 2798 CTabItem item = items[selectedIndex]; |
3839 { | 2799 int w = size.x - borderRight - 3 - minRect.width - maxRect.width - chevronRect.width; |
3840 if (maxWidths[i] > minWidths[i] + extra) | 2800 if (topRightRect.width > 0) w -= topRightRect.width + 3; |
3841 { | 2801 chevronRect.x = Math.min(item.x + item.width + 3, w); |
3842 totalWidth += minWidths[i] + extra; | 2802 } |
3843 large++; | 2803 if (borderRight > 0) chevronRect.x += 1; |
3844 } | 2804 } |
3845 else | 2805 } else { |
3846 { | 2806 if (showChevron) { |
3847 totalWidth += maxWidths[i]; | 2807 chevronRect.width = 3*BUTTON_SIZE/2; |
3848 } | 2808 chevronRect.height = BUTTON_SIZE; |
3849 } | 2809 int i = 0, lastIndex = -1; |
3850 if (totalWidth >= tabAreaWidth) | 2810 while (i < priority.length && items[priority[i]].showing) { |
3851 { | 2811 lastIndex = Math.max(lastIndex, priority[i++]); |
3852 extra--; | 2812 } |
3853 break; | 2813 if (lastIndex is -1) lastIndex = firstIndex; |
3854 } | 2814 CTabItem lastItem = items[lastIndex]; |
3855 if (large is 0 || tabAreaWidth - totalWidth < large) | 2815 int w = lastItem.x + lastItem.width + 3; |
3856 break; | 2816 if (!simple && lastIndex is selectedIndex) w += curveWidth - 2*curveIndent; |
3857 extra++; | 2817 chevronRect.x = Math.min(w, getRightItemEdge()); |
3858 } | 2818 chevronRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - chevronRect.height)/2 : borderTop + (tabHeight - chevronRect.height)/2; |
3859 widths = new int[items.length]; | 2819 } |
3860 for (int i = 0; i < items.length; i++) | 2820 } |
3861 { | 2821 if (oldX !is chevronRect.x || oldWidth !is chevronRect.width || |
3862 widths[i] = Math.min(maxWidths[i], minWidths[i] + extra); | 2822 oldY !is chevronRect.y || oldHeight !is chevronRect.height) { |
3863 } | 2823 int left = Math.min(oldX, chevronRect.x); |
3864 } | 2824 int right = Math.max(oldX + oldWidth, chevronRect.x + chevronRect.width); |
3865 } | 2825 int top = onBottom ? size.y - borderBottom - tabHeight: borderTop + 1; |
3866 gc.dispose(); | 2826 redraw(left, top, right - left, tabHeight, false); |
3867 | 2827 } |
3868 for (int i = 0; i < items.length; i++) | 2828 } |
3869 { | 2829 public override void setFont(Font font) { |
3870 CTabItem tab = items[i]; | 2830 checkWidget(); |
3871 int width = widths[i]; | 2831 if (font !is null && font==getFont()) return; |
3872 if (tab.height !is tabHeight || tab.width !is width) | 2832 super.setFont(font); |
3873 { | 2833 oldFont = getFont(); |
2834 if (!updateTabHeight(false)) { | |
2835 updateItems(); | |
2836 redraw(); | |
2837 } | |
2838 } | |
2839 public override void setForeground (Color color) { | |
2840 super.setForeground(color); | |
2841 redraw(); | |
2842 } | |
2843 /** | |
2844 * Display an insert marker before or after the specified tab item. | |
2845 * | |
2846 * A value of null will clear the mark. | |
2847 * | |
2848 * @param item the item with which the mark is associated or null | |
2849 * | |
2850 * @param after true if the mark should be displayed after the specified item | |
2851 * | |
2852 * @exception DWTException <ul> | |
2853 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2854 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2855 * </ul> | |
2856 */ | |
2857 public void setInsertMark(CTabItem item, bool after) { | |
2858 checkWidget(); | |
2859 } | |
2860 /** | |
2861 * Display an insert marker before or after the specified tab item. | |
2862 * | |
2863 * A value of -1 will clear the mark. | |
2864 * | |
2865 * @param index the index of the item with which the mark is associated or null | |
2866 * | |
2867 * @param after true if the mark should be displayed after the specified item | |
2868 * | |
2869 * @exception IllegalArgumentException<ul> | |
2870 * </ul> | |
2871 * | |
2872 * @exception DWTException <ul> | |
2873 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2874 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2875 * </ul> | |
2876 */ | |
2877 public void setInsertMark(int index, bool after) { | |
2878 checkWidget(); | |
2879 if (index < -1 || index >= getItemCount()) { | |
2880 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
2881 } | |
2882 } | |
2883 bool setItemLocation() { | |
2884 bool changed = false; | |
2885 if (items.length is 0) return false; | |
2886 Point size = getSize(); | |
2887 int y = onBottom ? Math.max(borderBottom, size.y - borderBottom - tabHeight) : borderTop; | |
2888 if (single) { | |
2889 int defaultX = getDisplay().getBounds().width + 10; // off screen | |
2890 for (int i = 0; i < items.length; i++) { | |
2891 CTabItem item = items[i]; | |
2892 if (i is selectedIndex) { | |
2893 firstIndex = selectedIndex; | |
2894 int oldX = item.x, oldY = item.y; | |
2895 item.x = borderLeft; | |
2896 item.y = y; | |
2897 item.showing = true; | |
2898 if (showClose || item.showClose) { | |
2899 item.closeRect.x = borderLeft + CTabItem.LEFT_MARGIN; | |
2900 item.closeRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - BUTTON_SIZE)/2: borderTop + (tabHeight - BUTTON_SIZE)/2; | |
2901 } | |
2902 if (item.x !is oldX || item.y !is oldY) changed = true; | |
2903 } else { | |
2904 item.x = defaultX; | |
2905 item.showing = false; | |
2906 } | |
2907 } | |
2908 } else { | |
2909 int rightItemEdge = getRightItemEdge(); | |
2910 int maxWidth = rightItemEdge - borderLeft; | |
2911 int width = 0; | |
2912 for (int i = 0; i < priority.length; i++) { | |
2913 CTabItem item = items[priority[i]]; | |
2914 width += item.width; | |
2915 item.showing = i is 0 ? true : item.width > 0 && width <= maxWidth; | |
2916 if (!simple && priority[i] is selectedIndex) width += curveWidth - 2*curveIndent; | |
2917 } | |
2918 int x = 0; | |
2919 int defaultX = getDisplay().getBounds().width + 10; // off screen | |
2920 firstIndex = items.length - 1; | |
2921 for (int i = 0; i < items.length; i++) { | |
2922 CTabItem item = items[i]; | |
2923 if (!item.showing) { | |
2924 if (item.x !is defaultX) changed = true; | |
2925 item.x = defaultX; | |
2926 } else { | |
2927 firstIndex = Math.min(firstIndex, i); | |
2928 if (item.x !is x || item.y !is y) changed = true; | |
2929 item.x = x; | |
2930 item.y = y; | |
2931 if (i is selectedIndex) { | |
2932 int edge = Math.min(item.x + item.width, rightItemEdge); | |
2933 item.closeRect.x = edge - CTabItem.RIGHT_MARGIN - BUTTON_SIZE; | |
2934 } else { | |
2935 item.closeRect.x = item.x + item.width - CTabItem.RIGHT_MARGIN - BUTTON_SIZE; | |
2936 } | |
2937 item.closeRect.y = onBottom ? size.y - borderBottom - tabHeight + (tabHeight - BUTTON_SIZE)/2: borderTop + (tabHeight - BUTTON_SIZE)/2; | |
2938 x = x + item.width; | |
2939 if (!simple && i is selectedIndex) x += curveWidth - 2*curveIndent; | |
2940 } | |
2941 } | |
2942 } | |
2943 return changed; | |
2944 } | |
2945 bool setItemSize() { | |
2946 bool changed = false; | |
2947 if (isDisposed()) return changed; | |
2948 Point size = getSize(); | |
2949 if (size.x <= 0 || size.y <= 0) return changed; | |
2950 xClient = borderLeft + marginWidth + highlight_margin; | |
2951 if (onBottom) { | |
2952 yClient = borderTop + highlight_margin + marginHeight; | |
2953 } else { | |
2954 yClient = borderTop + tabHeight + highlight_header + marginHeight; | |
2955 } | |
2956 showChevron = false; | |
2957 if (single) { | |
2958 showChevron = true; | |
2959 if (selectedIndex !is -1) { | |
2960 CTabItem tab = items[selectedIndex]; | |
2961 GC gc = new GC(this); | |
2962 int width = tab.preferredWidth(gc, true, false); | |
2963 gc.dispose(); | |
2964 width = Math.min(width, getRightItemEdge() - borderLeft); | |
2965 if (tab.height !is tabHeight || tab.width !is width) { | |
3874 changed = true; | 2966 changed = true; |
3875 tab.shortenedText = null; | 2967 tab.shortenedText = null; |
3876 tab.shortenedTextWidth = 0; | 2968 tab.shortenedTextWidth = 0; |
3877 tab.height = tabHeight; | 2969 tab.height = tabHeight; |
3878 tab.width = width; | 2970 tab.width = width; |
3879 tab.closeRect.width = tab.closeRect.height = 0; | 2971 tab.closeRect.width = tab.closeRect.height = 0; |
3880 if (showClose || tab.showClose) | 2972 if (showClose || tab.showClose) { |
3881 { | 2973 tab.closeRect.width = BUTTON_SIZE; |
3882 if (i is selectedIndex || showUnselectedClose) | 2974 tab.closeRect.height = BUTTON_SIZE; |
3883 { | 2975 } |
3884 tab.closeRect.width = BUTTON_SIZE; | 2976 } |
3885 tab.closeRect.height = BUTTON_SIZE; | 2977 } |
2978 return changed; | |
2979 } | |
2980 | |
2981 if (items.length is 0) return changed; | |
2982 | |
2983 int[] widths; | |
2984 GC gc = new GC(this); | |
2985 int tabAreaWidth = size.x - borderLeft - borderRight - 3; | |
2986 if (showMin) tabAreaWidth -= BUTTON_SIZE; | |
2987 if (showMax) tabAreaWidth -= BUTTON_SIZE; | |
2988 if (topRightAlignment is DWT.RIGHT && topRight !is null) { | |
2989 Point rightSize = topRight.computeSize(DWT.DEFAULT, DWT.DEFAULT, false); | |
2990 tabAreaWidth -= rightSize.x + 3; | |
2991 } | |
2992 if (!simple) tabAreaWidth -= curveWidth - 2*curveIndent; | |
2993 tabAreaWidth = Math.max(0, tabAreaWidth); | |
2994 | |
2995 // First, try the minimum tab size at full compression. | |
2996 int minWidth = 0; | |
2997 int[] minWidths = new int[items.length]; | |
2998 for (int i = 0; i < priority.length; i++) { | |
2999 int index = priority[i]; | |
3000 minWidths[index] = items[index].preferredWidth(gc, index is selectedIndex, true); | |
3001 minWidth += minWidths[index]; | |
3002 if (minWidth > tabAreaWidth) break; | |
3003 } | |
3004 if (minWidth > tabAreaWidth) { | |
3005 // full compression required and a chevron | |
3006 showChevron = items.length > 1; | |
3007 if (showChevron) tabAreaWidth -= 3*BUTTON_SIZE/2; | |
3008 widths = minWidths; | |
3009 int index = selectedIndex !is -1 ? selectedIndex : 0; | |
3010 if (tabAreaWidth < widths[index]) { | |
3011 widths[index] = Math.max(0, tabAreaWidth); | |
3012 } | |
3013 } else { | |
3014 int maxWidth = 0; | |
3015 int[] maxWidths = new int[items.length]; | |
3016 for (int i = 0; i < items.length; i++) { | |
3017 maxWidths[i] = items[i].preferredWidth(gc, i is selectedIndex, false); | |
3018 maxWidth += maxWidths[i]; | |
3019 } | |
3020 if (maxWidth <= tabAreaWidth) { | |
3021 // no compression required | |
3022 widths = maxWidths; | |
3023 } else { | |
3024 // determine compression for each item | |
3025 int extra = (tabAreaWidth - minWidth) / items.length; | |
3026 while (true) { | |
3027 int large = 0, totalWidth = 0; | |
3028 for (int i = 0 ; i < items.length; i++) { | |
3029 if (maxWidths[i] > minWidths[i] + extra) { | |
3030 totalWidth += minWidths[i] + extra; | |
3031 large++; | |
3032 } else { | |
3033 totalWidth += maxWidths[i]; | |
3886 } | 3034 } |
3887 } | 3035 } |
3888 } | 3036 if (totalWidth >= tabAreaWidth) { |
3889 } | 3037 extra--; |
3890 return changed; | 3038 break; |
3891 } | 3039 } |
3892 | 3040 if (large is 0 || tabAreaWidth - totalWidth < large) break; |
3893 /** | 3041 extra++; |
3894 * Marks the receiver's maximize button as visible if the argument is <code>true</code>, | 3042 } |
3895 * and marks it invisible otherwise. | 3043 widths = new int[items.length]; |
3896 * | 3044 for (int i = 0; i < items.length; i++) { |
3897 * @param visible the new visibility state | 3045 widths[i] = Math.min(maxWidths[i], minWidths[i] + extra); |
3898 * | 3046 } |
3899 * @exception DWTException <ul> | 3047 } |
3900 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 3048 } |
3901 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 3049 gc.dispose(); |
3902 * </ul> | 3050 |
3903 * | 3051 for (int i = 0; i < items.length; i++) { |
3904 * @since 3.0 | 3052 CTabItem tab = items[i]; |
3905 */ | 3053 int width = widths[i]; |
3906 public void setMaximizeVisible (bool visible) | 3054 if (tab.height !is tabHeight || tab.width !is width) { |
3907 { | 3055 changed = true; |
3908 checkWidget(); | 3056 tab.shortenedText = null; |
3909 if (showMax is visible) | 3057 tab.shortenedTextWidth = 0; |
3910 return; | 3058 tab.height = tabHeight; |
3911 // display maximize button | 3059 tab.width = width; |
3912 showMax = visible; | 3060 tab.closeRect.width = tab.closeRect.height = 0; |
3061 if (showClose || tab.showClose) { | |
3062 if (i is selectedIndex || showUnselectedClose) { | |
3063 tab.closeRect.width = BUTTON_SIZE; | |
3064 tab.closeRect.height = BUTTON_SIZE; | |
3065 } | |
3066 } | |
3067 } | |
3068 } | |
3069 return changed; | |
3070 } | |
3071 /** | |
3072 * Marks the receiver's maximize button as visible if the argument is <code>true</code>, | |
3073 * and marks it invisible otherwise. | |
3074 * | |
3075 * @param visible the new visibility state | |
3076 * | |
3077 * @exception DWTException <ul> | |
3078 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3079 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3080 * </ul> | |
3081 * | |
3082 * @since 3.0 | |
3083 */ | |
3084 public void setMaximizeVisible(bool visible) { | |
3085 checkWidget(); | |
3086 if (showMax is visible) return; | |
3087 // display maximize button | |
3088 showMax = visible; | |
3089 updateItems(); | |
3090 redraw(); | |
3091 } | |
3092 /** | |
3093 * Sets the layout which is associated with the receiver to be | |
3094 * the argument which may be null. | |
3095 * <p> | |
3096 * Note: No Layout can be set on this Control because it already | |
3097 * manages the size and position of its children. | |
3098 * </p> | |
3099 * | |
3100 * @param layout the receiver's new layout or null | |
3101 * | |
3102 * @exception DWTException <ul> | |
3103 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3104 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3105 * </ul> | |
3106 */ | |
3107 public override void setLayout (Layout layout) { | |
3108 checkWidget(); | |
3109 return; | |
3110 } | |
3111 /** | |
3112 * Sets the maximized state of the receiver. | |
3113 * | |
3114 * @param maximize the new maximized state | |
3115 * | |
3116 * @exception DWTException <ul> | |
3117 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3118 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3119 * </ul> | |
3120 * | |
3121 * @since 3.0 | |
3122 */ | |
3123 public void setMaximized(bool maximize) { | |
3124 checkWidget (); | |
3125 if (this.maximized is maximize) return; | |
3126 if (maximize && this.minimized) setMinimized(false); | |
3127 this.maximized = maximize; | |
3128 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false); | |
3129 } | |
3130 /** | |
3131 * Marks the receiver's minimize button as visible if the argument is <code>true</code>, | |
3132 * and marks it invisible otherwise. | |
3133 * | |
3134 * @param visible the new visibility state | |
3135 * | |
3136 * @exception DWTException <ul> | |
3137 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3138 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3139 * </ul> | |
3140 * | |
3141 * @since 3.0 | |
3142 */ | |
3143 public void setMinimizeVisible(bool visible) { | |
3144 checkWidget(); | |
3145 if (showMin is visible) return; | |
3146 // display minimize button | |
3147 showMin = visible; | |
3148 updateItems(); | |
3149 redraw(); | |
3150 } | |
3151 /** | |
3152 * Sets the minimized state of the receiver. | |
3153 * | |
3154 * @param minimize the new minimized state | |
3155 * | |
3156 * @exception DWTException <ul> | |
3157 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3158 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3159 * </ul> | |
3160 * | |
3161 * @since 3.0 | |
3162 */ | |
3163 public void setMinimized(bool minimize) { | |
3164 checkWidget (); | |
3165 if (this.minimized is minimize) return; | |
3166 if (minimize && this.maximized) setMaximized(false); | |
3167 this.minimized = minimize; | |
3168 redraw(minRect.x, minRect.y, minRect.width, minRect.height, false); | |
3169 } | |
3170 | |
3171 /** | |
3172 * Sets the minimum number of characters that will | |
3173 * be displayed in a fully compressed tab. | |
3174 * | |
3175 * @param count the minimum number of characters that will be displayed in a fully compressed tab | |
3176 * | |
3177 * @exception DWTException <ul> | |
3178 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3179 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3180 * <li>ERROR_INVALID_RANGE - if the count is less than zero</li> | |
3181 * </ul> | |
3182 * | |
3183 * @since 3.0 | |
3184 */ | |
3185 public void setMinimumCharacters(int count) { | |
3186 checkWidget (); | |
3187 if (count < 0) DWT.error(DWT.ERROR_INVALID_RANGE); | |
3188 if (minChars is count) return; | |
3189 minChars = count; | |
3190 if (updateItems()) redrawTabs(); | |
3191 } | |
3192 | |
3193 /** | |
3194 * When there is not enough horizontal space to show all the tabs, | |
3195 * by default, tabs are shown sequentially from left to right in | |
3196 * order of their index. When the MRU visibility is turned on, | |
3197 * the tabs that are visible will be the tabs most recently selected. | |
3198 * Tabs will still maintain their left to right order based on index | |
3199 * but only the most recently selected tabs are visible. | |
3200 * <p> | |
3201 * For example, consider a CTabFolder that contains "Tab 1", "Tab 2", | |
3202 * "Tab 3" and "Tab 4" (in order by index). The user selects | |
3203 * "Tab 1" and then "Tab 3". If the CTabFolder is now | |
3204 * compressed so that only two tabs are visible, by default, | |
3205 * "Tab 2" and "Tab 3" will be shown ("Tab 3" since it is currently | |
3206 * selected and "Tab 2" because it is the previous item in index order). | |
3207 * If MRU visibility is enabled, the two visible tabs will be "Tab 1" | |
3208 * and "Tab 3" (in that order from left to right).</p> | |
3209 * | |
3210 * @param show the new visibility state | |
3211 * | |
3212 * @exception DWTException <ul> | |
3213 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3214 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3215 * </ul> | |
3216 * | |
3217 * @since 3.1 | |
3218 */ | |
3219 public void setMRUVisible(bool show) { | |
3220 checkWidget(); | |
3221 if (mru is show) return; | |
3222 mru = show; | |
3223 if (!mru) { | |
3224 int idx = firstIndex; | |
3225 int next = 0; | |
3226 for (int i = firstIndex; i < items.length; i++) { | |
3227 priority[next++] = i; | |
3228 } | |
3229 for (int i = 0; i < idx; i++) { | |
3230 priority[next++] = i; | |
3231 } | |
3232 if (updateItems()) redrawTabs(); | |
3233 } | |
3234 } | |
3235 /** | |
3236 * Set the selection to the tab at the specified item. | |
3237 * | |
3238 * @param item the tab item to be selected | |
3239 * | |
3240 * @exception IllegalArgumentException <ul> | |
3241 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
3242 * </ul> | |
3243 * | |
3244 * @exception DWTException <ul> | |
3245 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
3246 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
3247 * </ul> | |
3248 */ | |
3249 public void setSelection(CTabItem item) { | |
3250 checkWidget(); | |
3251 if (item is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
3252 int index = indexOf(item); | |
3253 setSelection(index); | |
3254 } | |
3255 /** | |
3256 * Set the selection to the tab at the specified index. | |
3257 * | |
3258 * @param index the index of the tab item to be selected | |
3259 * | |
3260 * @exception DWTException <ul> | |
3261 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3262 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3263 * </ul> | |
3264 */ | |
3265 public void setSelection(int index) { | |
3266 checkWidget(); | |
3267 if (index < 0 || index >= items.length) return; | |
3268 CTabItem selection = items[index]; | |
3269 if (selectedIndex is index) { | |
3270 showItem(selection); | |
3271 return; | |
3272 } | |
3273 | |
3274 int oldIndex = selectedIndex; | |
3275 selectedIndex = index; | |
3276 if (oldIndex !is -1) { | |
3277 items[oldIndex].closeImageState = NONE; | |
3278 } | |
3279 selection.closeImageState = NORMAL; | |
3280 selection.showing = false; | |
3281 | |
3282 Control newControl = selection.control; | |
3283 Control oldControl = null; | |
3284 if (oldIndex !is -1) { | |
3285 oldControl = items[oldIndex].control; | |
3286 } | |
3287 | |
3288 if (newControl !is oldControl) { | |
3289 if (newControl !is null && !newControl.isDisposed()) { | |
3290 newControl.setBounds(getClientArea()); | |
3291 newControl.setVisible(true); | |
3292 } | |
3293 if (oldControl !is null && !oldControl.isDisposed()) { | |
3294 oldControl.setVisible(false); | |
3295 } | |
3296 } | |
3297 showItem(selection); | |
3298 redraw(); | |
3299 } | |
3300 void setSelection(int index, bool notify) { | |
3301 int oldSelectedIndex = selectedIndex; | |
3302 setSelection(index); | |
3303 if (notify && selectedIndex !is oldSelectedIndex && selectedIndex !is -1) { | |
3304 Event event = new Event(); | |
3305 event.item = getItem(selectedIndex); | |
3306 notifyListeners(DWT.Selection, event); | |
3307 } | |
3308 } | |
3309 /** | |
3310 * Sets the receiver's selection background color to the color specified | |
3311 * by the argument, or to the default system color for the control | |
3312 * if the argument is null. | |
3313 * | |
3314 * @param color the new color (or null) | |
3315 * | |
3316 * @exception IllegalArgumentException <ul> | |
3317 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
3318 * </ul> | |
3319 * @exception DWTException <ul> | |
3320 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3321 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3322 * </ul> | |
3323 * | |
3324 * @since 3.0 | |
3325 */ | |
3326 public void setSelectionBackground (Color color) { | |
3327 checkWidget(); | |
3328 setSelectionHighlightGradientColor(null); | |
3329 if (selectionBackground is color) return; | |
3330 if (color is null) color = getDisplay().getSystemColor(SELECTION_BACKGROUND); | |
3331 selectionBackground = color; | |
3332 if (selectedIndex > -1) redraw(); | |
3333 } | |
3334 /** | |
3335 * Specify a gradient of colours to be draw in the background of the selected tab. | |
3336 * For example to draw a gradient that varies from dark blue to blue and then to | |
3337 * white, use the following call to setBackground: | |
3338 * <pre> | |
3339 * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), | |
3340 * display.getSystemColor(DWT.COLOR_BLUE), | |
3341 * display.getSystemColor(DWT.COLOR_WHITE), | |
3342 * display.getSystemColor(DWT.COLOR_WHITE)}, | |
3343 * new int[] {25, 50, 100}); | |
3344 * </pre> | |
3345 * | |
3346 * @param colors an array of Color that specifies the colors to appear in the gradient | |
3347 * in order of appearance left to right. The value <code>null</code> clears the | |
3348 * background gradient. The value <code>null</code> can be used inside the array of | |
3349 * Color to specify the background color. | |
3350 * @param percents an array of integers between 0 and 100 specifying the percent of the width | |
3351 * of the widget at which the color should change. The size of the percents array must be one | |
3352 * less than the size of the colors array. | |
3353 * | |
3354 * @exception DWTException <ul> | |
3355 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
3356 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
3357 * </ul> | |
3358 */ | |
3359 public void setSelectionBackground(Color[] colors, int[] percents) { | |
3360 setSelectionBackground(colors, percents, false); | |
3361 } | |
3362 /** | |
3363 * Specify a gradient of colours to be draw in the background of the selected tab. | |
3364 * For example to draw a vertical gradient that varies from dark blue to blue and then to | |
3365 * white, use the following call to setBackground: | |
3366 * <pre> | |
3367 * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), | |
3368 * display.getSystemColor(DWT.COLOR_BLUE), | |
3369 * display.getSystemColor(DWT.COLOR_WHITE), | |
3370 * display.getSystemColor(DWT.COLOR_WHITE)}, | |
3371 * new int[] {25, 50, 100}, true); | |
3372 * </pre> | |
3373 * | |
3374 * @param colors an array of Color that specifies the colors to appear in the gradient | |
3375 * in order of appearance left to right. The value <code>null</code> clears the | |
3376 * background gradient. The value <code>null</code> can be used inside the array of | |
3377 * Color to specify the background color. | |
3378 * @param percents an array of integers between 0 and 100 specifying the percent of the width | |
3379 * of the widget at which the color should change. The size of the percents array must be one | |
3380 * less than the size of the colors array. | |
3381 * | |
3382 * @param vertical indicate the direction of the gradient. True is vertical and false is horizontal. | |
3383 * | |
3384 * @exception DWTException <ul> | |
3385 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
3386 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
3387 * </ul> | |
3388 * | |
3389 * @since 3.0 | |
3390 */ | |
3391 public void setSelectionBackground(Color[] colors, int[] percents, bool vertical) { | |
3392 checkWidget(); | |
3393 int colorsLength; | |
3394 Color highlightBeginColor = null; //null is no highlight | |
3395 | |
3396 if (colors !is null) { | |
3397 //The colors array can optionally have an extra entry which describes the highlight top color | |
3398 //Thus its either one or two larger than the percents array | |
3399 if (percents is null || | |
3400 ! ((percents.length is colors.length - 1) || (percents.length is colors.length - 2))){ | |
3401 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
3402 } | |
3403 for (int i = 0; i < percents.length; i++) { | |
3404 if (percents[i] < 0 || percents[i] > 100) { | |
3405 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
3406 } | |
3407 if (i > 0 && percents[i] < percents[i-1]) { | |
3408 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
3409 } | |
3410 } | |
3411 //If the colors is exactly two more than percents then last is highlight | |
3412 //Keep track of *real* colorsLength (minus the highlight) | |
3413 if(percents.length is colors.length - 2) { | |
3414 highlightBeginColor = colors[colors.length - 1]; | |
3415 colorsLength = colors.length - 1; | |
3416 } else { | |
3417 colorsLength = colors.length; | |
3418 } | |
3419 if (getDisplay().getDepth() < 15) { | |
3420 // Don't use gradients on low color displays | |
3421 colors = [colors[colorsLength - 1]]; | |
3422 colorsLength = colors.length; | |
3423 percents = null; | |
3424 } | |
3425 } else { | |
3426 colorsLength = 0; | |
3427 } | |
3428 | |
3429 // Are these settings the same as before? | |
3430 if (selectionBgImage is null) { | |
3431 if ((selectionGradientColors !is null) && (colors !is null) && | |
3432 (selectionGradientColors.length is colorsLength)) { | |
3433 bool same = false; | |
3434 for (int i = 0; i < selectionGradientColors.length; i++) { | |
3435 if (selectionGradientColors[i] is null) { | |
3436 same = colors[i] is null; | |
3437 } else { | |
3438 same = cast(bool)(selectionGradientColors[i]==colors[i]); | |
3439 } | |
3440 if (!same) break; | |
3441 } | |
3442 if (same) { | |
3443 for (int i = 0; i < selectionGradientPercents.length; i++) { | |
3444 same = selectionGradientPercents[i] is percents[i]; | |
3445 if (!same) break; | |
3446 } | |
3447 } | |
3448 if (same && this.selectionGradientVertical is vertical) return; | |
3449 } | |
3450 } else { | |
3451 selectionBgImage = null; | |
3452 } | |
3453 // Store the new settings | |
3454 if (colors is null) { | |
3455 selectionGradientColors = null; | |
3456 selectionGradientPercents = null; | |
3457 selectionGradientVertical = false; | |
3458 setSelectionBackground(cast(Color)null); | |
3459 setSelectionHighlightGradientColor(null); | |
3460 } else { | |
3461 selectionGradientColors = new Color[colorsLength]; | |
3462 for (int i = 0; i < colorsLength; ++i) { | |
3463 selectionGradientColors[i] = colors[i]; | |
3464 } | |
3465 selectionGradientPercents = new int[percents.length]; | |
3466 for (int i = 0; i < percents.length; ++i) { | |
3467 selectionGradientPercents[i] = percents[i]; | |
3468 } | |
3469 selectionGradientVertical = vertical; | |
3470 setSelectionBackground(selectionGradientColors[selectionGradientColors.length-1]); | |
3471 setSelectionHighlightGradientColor(highlightBeginColor); | |
3472 } | |
3473 | |
3474 // Refresh with the new settings | |
3475 if (selectedIndex > -1) redraw(); | |
3476 } | |
3477 | |
3478 /* | |
3479 * Set the color for the highlight start for selected tabs. | |
3480 * Update the cache of highlight gradient colors if required. | |
3481 */ | |
3482 | |
3483 void setSelectionHighlightGradientColor(Color start) { | |
3484 //Set to null to match all the early return cases. | |
3485 //For early returns, don't realloc the cache, we may get a cache hit next time we're given the highlight | |
3486 selectionHighlightGradientBegin = null; | |
3487 | |
3488 if(start is null) | |
3489 return; | |
3490 | |
3491 //don't bother on low colour | |
3492 if (getDisplay().getDepth() < 15) | |
3493 return; | |
3494 | |
3495 //don't bother if we don't have a background gradient | |
3496 if(selectionGradientColors.length < 2) | |
3497 return; | |
3498 | |
3499 //OK we know its a valid gradient now | |
3500 selectionHighlightGradientBegin = start; | |
3501 | |
3502 if(! isSelectionHighlightColorsCacheHit(start)) | |
3503 createSelectionHighlightGradientColors(start); //if no cache hit then compute new ones | |
3504 } | |
3505 | |
3506 /* | |
3507 * Return true if given start color, the cache of highlight colors we have | |
3508 * would match the highlight colors we'd compute. | |
3509 */ | |
3510 bool isSelectionHighlightColorsCacheHit(Color start) { | |
3511 | |
3512 if(selectionHighlightGradientColorsCache is null) | |
3513 return false; | |
3514 | |
3515 //this case should never happen but check to be safe before accessing array indexes | |
3516 if(selectionHighlightGradientColorsCache.length < 2) | |
3517 return false; | |
3518 | |
3519 Color highlightBegin = selectionHighlightGradientColorsCache[0]; | |
3520 Color highlightEnd = selectionHighlightGradientColorsCache[selectionHighlightGradientColorsCache.length - 1]; | |
3521 | |
3522 if( highlightBegin!=start) | |
3523 return false; | |
3524 | |
3525 //Compare number of colours we have vs. we'd compute | |
3526 if(selectionHighlightGradientColorsCache.length !is tabHeight) | |
3527 return false; | |
3528 | |
3529 //Compare existing highlight end to what it would be (selectionBackground) | |
3530 if( highlightEnd!=selectionBackground) | |
3531 return false; | |
3532 | |
3533 return true; | |
3534 } | |
3535 | |
3536 /** | |
3537 * Set the image to be drawn in the background of the selected tab. Image | |
3538 * is stretched or compressed to cover entire selection tab area. | |
3539 * | |
3540 * @param image the image to be drawn in the background | |
3541 * | |
3542 * @exception DWTException <ul> | |
3543 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3544 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3545 * </ul> | |
3546 */ | |
3547 public void setSelectionBackground(Image image) { | |
3548 checkWidget(); | |
3549 setSelectionHighlightGradientColor(null); | |
3550 if (image is selectionBgImage) return; | |
3551 if (image !is null) { | |
3552 selectionGradientColors = null; | |
3553 selectionGradientPercents = null; | |
3554 disposeSelectionHighlightGradientColors(); | |
3555 } | |
3556 selectionBgImage = image; | |
3557 if (selectedIndex > -1) redraw(); | |
3558 } | |
3559 /** | |
3560 * Set the foreground color of the selected tab. | |
3561 * | |
3562 * @param color the color of the text displayed in the selected tab | |
3563 * | |
3564 * @exception DWTException <ul> | |
3565 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3566 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3567 * </ul> | |
3568 */ | |
3569 public void setSelectionForeground (Color color) { | |
3570 checkWidget(); | |
3571 if (selectionForeground is color) return; | |
3572 if (color is null) color = getDisplay().getSystemColor(SELECTION_FOREGROUND); | |
3573 selectionForeground = color; | |
3574 if (selectedIndex > -1) redraw(); | |
3575 } | |
3576 | |
3577 /* | |
3578 * Allocate colors for the highlight line. | |
3579 * Colours will be a gradual blend ranging from to. | |
3580 * Blend length will be tab height. | |
3581 * Recompute this if tab height changes. | |
3582 * Could remain null if there'd be no gradient (start=end or low colour display) | |
3583 */ | |
3584 void createSelectionHighlightGradientColors(Color start) { | |
3585 disposeSelectionHighlightGradientColors(); //dispose if existing | |
3586 | |
3587 if(start is null) //shouldn't happen but just to be safe | |
3588 return; | |
3589 | |
3590 //alloc colours for entire height to ensure it matches wherever we stop drawing | |
3591 int fadeGradientSize = tabHeight; | |
3592 | |
3593 RGB from = start.getRGB(); | |
3594 RGB to = selectionBackground.getRGB(); | |
3595 | |
3596 selectionHighlightGradientColorsCache = new Color[fadeGradientSize]; | |
3597 int denom = fadeGradientSize - 1; | |
3598 | |
3599 for (int i = 0; i < fadeGradientSize; i++) { | |
3600 int propFrom = denom - i; | |
3601 int propTo = i; | |
3602 int red = (to.red * propTo + from.red * propFrom) / denom; | |
3603 int green = (to.green * propTo + from.green * propFrom) / denom; | |
3604 int blue = (to.blue * propTo + from.blue * propFrom) / denom; | |
3605 selectionHighlightGradientColorsCache[i] = new Color(getDisplay(), red, green, blue); | |
3606 } | |
3607 } | |
3608 | |
3609 void disposeSelectionHighlightGradientColors() { | |
3610 if(selectionHighlightGradientColorsCache is null) | |
3611 return; | |
3612 for (int i = 0; i < selectionHighlightGradientColorsCache.length; i++) { | |
3613 selectionHighlightGradientColorsCache[i].dispose(); | |
3614 } | |
3615 selectionHighlightGradientColorsCache = null; | |
3616 } | |
3617 | |
3618 /* | |
3619 * Return the gradient start color for selected tabs, which is the start of the tab fade | |
3620 * (end is selectionBackground). | |
3621 */ | |
3622 Color getSelectionBackgroundGradientBegin() { | |
3623 if (selectionGradientColors is null) | |
3624 return getSelectionBackground(); | |
3625 if (selectionGradientColors.length is 0) | |
3626 return getSelectionBackground(); | |
3627 return selectionGradientColors[0]; | |
3628 } | |
3629 | |
3630 /** | |
3631 * Sets the shape that the CTabFolder will use to render itself. | |
3632 * | |
3633 * @param simple <code>true</code> if the CTabFolder should render itself in a simple, traditional style | |
3634 * | |
3635 * @exception DWTException <ul> | |
3636 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3637 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3638 * </ul> | |
3639 * | |
3640 * @since 3.0 | |
3641 */ | |
3642 public void setSimple(bool simple) { | |
3643 checkWidget(); | |
3644 if (this.simple !is simple) { | |
3645 this.simple = simple; | |
3646 Rectangle rectBefore = getClientArea(); | |
3913 updateItems(); | 3647 updateItems(); |
3648 Rectangle rectAfter = getClientArea(); | |
3649 if (rectBefore!=rectAfter) { | |
3650 notifyListeners(DWT.Resize, new Event()); | |
3651 } | |
3914 redraw(); | 3652 redraw(); |
3915 } | 3653 } |
3916 | 3654 } |
3917 /** | 3655 /** |
3918 * Sets the layout which is associated with the receiver to be | 3656 * Sets the number of tabs that the CTabFolder should display |
3919 * the argument which may be null. | 3657 * |
3920 * <p> | 3658 * @param single <code>true</code> if only the selected tab should be displayed otherwise, multiple tabs will be shown. |
3921 * Note: No Layout can be set on this Control because it already | 3659 * |
3922 * manages the size and position of its children. | 3660 * @exception DWTException <ul> |
3923 * </p> | 3661 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
3924 * | 3662 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
3925 * @param layout the receiver's new layout or null | 3663 * </ul> |
3926 * | 3664 * |
3927 * @exception DWTException <ul> | 3665 * @since 3.0 |
3928 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 3666 */ |
3929 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 3667 public void setSingle(bool single) { |
3930 * </ul> | 3668 checkWidget(); |
3931 */ | 3669 if (this.single !is single) { |
3932 public void setLayout (Layout layout) | 3670 this.single = single; |
3933 { | 3671 if (!single) { |
3934 checkWidget(); | 3672 for (int i = 0; i < items.length; i++) { |
3935 return; | 3673 if (i !is selectedIndex && items[i].closeImageState is NORMAL) { |
3936 } | 3674 items[i].closeImageState = NONE; |
3937 | 3675 } |
3938 /** | 3676 } |
3939 * Sets the maximized state of the receiver. | 3677 } |
3940 * | 3678 Rectangle rectBefore = getClientArea(); |
3941 * @param maximize the new maximized state | |
3942 * | |
3943 * @exception DWTException <ul> | |
3944 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3945 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3946 * </ul> | |
3947 * | |
3948 * @since 3.0 | |
3949 */ | |
3950 public void setMaximized (bool maximize) | |
3951 { | |
3952 checkWidget(); | |
3953 if (this.maximized is maximize) | |
3954 return; | |
3955 if (maximize && this.minimized) | |
3956 setMinimized(false); | |
3957 this.maximized = maximize; | |
3958 redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false); | |
3959 } | |
3960 | |
3961 /** | |
3962 * Marks the receiver's minimize button as visible if the argument is <code>true</code>, | |
3963 * and marks it invisible otherwise. | |
3964 * | |
3965 * @param visible the new visibility state | |
3966 * | |
3967 * @exception DWTException <ul> | |
3968 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3969 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3970 * </ul> | |
3971 * | |
3972 * @since 3.0 | |
3973 */ | |
3974 public void setMinimizeVisible (bool visible) | |
3975 { | |
3976 checkWidget(); | |
3977 if (showMin is visible) | |
3978 return; | |
3979 // display minimize button | |
3980 showMin = visible; | |
3981 updateItems(); | 3679 updateItems(); |
3680 Rectangle rectAfter = getClientArea(); | |
3681 if (rectBefore!=rectAfter) { | |
3682 notifyListeners(DWT.Resize, new Event()); | |
3683 } | |
3982 redraw(); | 3684 redraw(); |
3983 } | 3685 } |
3984 | 3686 } |
3985 /** | 3687 /** |
3986 * Sets the minimized state of the receiver. | 3688 * Specify a fixed height for the tab items. If no height is specified, |
3987 * | 3689 * the default height is the height of the text or the image, whichever |
3988 * @param minimize the new minimized state | 3690 * is greater. Specifying a height of -1 will revert to the default height. |
3989 * | 3691 * |
3990 * @exception DWTException <ul> | 3692 * @param height the pixel value of the height or -1 |
3991 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 3693 * |
3992 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 3694 * @exception DWTException <ul> |
3993 * </ul> | 3695 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
3994 * | 3696 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
3995 * @since 3.0 | 3697 * <li>ERROR_INVALID_ARGUMENT - if called with a height of less than 0</li> |
3996 */ | 3698 * </ul> |
3997 public void setMinimized (bool minimize) | 3699 */ |
3998 { | 3700 public void setTabHeight(int height) { |
3999 checkWidget(); | 3701 checkWidget(); |
4000 if (this.minimized is minimize) | 3702 if (height < -1) { |
4001 return; | 3703 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
4002 if (minimize && this.maximized) | 3704 } |
4003 setMaximized(false); | 3705 fixedTabHeight = height; |
4004 this.minimized = minimize; | 3706 updateTabHeight(false); |
4005 redraw(minRect.x, minRect.y, minRect.width, minRect.height, false); | 3707 } |
4006 } | 3708 /** |
4007 | 3709 * Specify whether the tabs should appear along the top of the folder |
4008 /** | 3710 * or along the bottom of the folder. |
4009 * Sets the minimum number of characters that will | 3711 * |
4010 * be displayed in a fully compressed tab. | 3712 * @param position <code>DWT.TOP</code> for tabs along the top or <code>DWT.BOTTOM</code> for tabs along the bottom |
4011 * | 3713 * |
4012 * @param count the minimum number of characters that will be displayed in a fully compressed tab | 3714 * @exception DWTException <ul> |
4013 * | 3715 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
4014 * @exception DWTException <ul> | 3716 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
4015 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 3717 * <li>ERROR_INVALID_ARGUMENT - if the position value is not either DWT.TOP or DWT.BOTTOM</li> |
4016 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 3718 * </ul> |
4017 * <li>ERROR_INVALID_RANGE - if the count is less than zero</li> | 3719 * |
4018 * </ul> | 3720 * @since 3.0 |
4019 * | 3721 */ |
4020 * @since 3.0 | 3722 public void setTabPosition(int position) { |
4021 */ | 3723 checkWidget(); |
4022 public void setMinimumCharacters (int count) | 3724 if (position !is DWT.TOP && position !is DWT.BOTTOM) { |
4023 { | 3725 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
4024 checkWidget(); | 3726 } |
4025 if (count < 0) | 3727 if (onBottom !is (position is DWT.BOTTOM)) { |
4026 DWT.error(DWT.ERROR_INVALID_RANGE); | 3728 onBottom = position is DWT.BOTTOM; |
4027 if (minChars is count) | 3729 borderTop = onBottom ? borderLeft : 0; |
4028 return; | 3730 borderBottom = onBottom ? 0 : borderRight; |
4029 minChars = count; | 3731 updateTabHeight(true); |
4030 if (updateItems()) | 3732 Rectangle rectBefore = getClientArea(); |
4031 redrawTabs(); | 3733 updateItems(); |
4032 } | 3734 Rectangle rectAfter = getClientArea(); |
4033 | 3735 if (rectBefore!=rectAfter) { |
4034 /** | 3736 notifyListeners(DWT.Resize, new Event()); |
4035 * When there is not enough horizontal space to show all the tabs, | 3737 } |
4036 * by default, tabs are shown sequentially from left to right in | |
4037 * order of their index. When the MRU visibility is turned on, | |
4038 * the tabs that are visible will be the tabs most recently selected. | |
4039 * Tabs will still maintain their left to right order based on index | |
4040 * but only the most recently selected tabs are visible. | |
4041 * <p> | |
4042 * For example, consider a CTabFolder that contains "Tab 1", "Tab 2", | |
4043 * "Tab 3" and "Tab 4" (in order by index). The user selects | |
4044 * "Tab 1" and then "Tab 3". If the CTabFolder is now | |
4045 * compressed so that only two tabs are visible, by default, | |
4046 * "Tab 2" and "Tab 3" will be shown ("Tab 3" since it is currently | |
4047 * selected and "Tab 2" because it is the previous item in index order). | |
4048 * If MRU visibility is enabled, the two visible tabs will be "Tab 1" | |
4049 * and "Tab 3" (in that order from left to right).</p> | |
4050 * | |
4051 * @param show the new visibility state | |
4052 * | |
4053 * @exception DWTException <ul> | |
4054 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4055 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4056 * </ul> | |
4057 * | |
4058 * @since 3.1 | |
4059 */ | |
4060 public void setMRUVisible (bool show) | |
4061 { | |
4062 checkWidget(); | |
4063 if (mru is show) | |
4064 return; | |
4065 mru = show; | |
4066 if (!mru) | |
4067 { | |
4068 int idx = firstIndex; | |
4069 int next = 0; | |
4070 for (int i = firstIndex; i < items.length; i++) | |
4071 { | |
4072 priority[next++] = i; | |
4073 } | |
4074 for (int i = 0; i < idx; i++) | |
4075 { | |
4076 priority[next++] = i; | |
4077 } | |
4078 if (updateItems()) | |
4079 redrawTabs(); | |
4080 } | |
4081 } | |
4082 | |
4083 /** | |
4084 * Set the selection to the tab at the specified item. | |
4085 * | |
4086 * @param item the tab item to be selected | |
4087 * | |
4088 * @exception IllegalArgumentException <ul> | |
4089 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
4090 * </ul> | |
4091 * | |
4092 * @exception DWTException <ul> | |
4093 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
4094 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
4095 * </ul> | |
4096 */ | |
4097 public void setSelection (CTabItem item) | |
4098 { | |
4099 checkWidget(); | |
4100 if (item is null) | |
4101 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
4102 int index = indexOf(item); | |
4103 setSelection(index); | |
4104 } | |
4105 | |
4106 /** | |
4107 * Set the selection to the tab at the specified index. | |
4108 * | |
4109 * @param index the index of the tab item to be selected | |
4110 * | |
4111 * @exception DWTException <ul> | |
4112 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4113 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4114 * </ul> | |
4115 */ | |
4116 public void setSelection (int index) | |
4117 { | |
4118 checkWidget(); | |
4119 if (index < 0 || index >= items.length) | |
4120 return; | |
4121 CTabItem selection = items[index]; | |
4122 if (selectedIndex is index) | |
4123 { | |
4124 showItem(selection); | |
4125 return; | |
4126 } | |
4127 | |
4128 int oldIndex = selectedIndex; | |
4129 selectedIndex = index; | |
4130 if (oldIndex !is -1) | |
4131 { | |
4132 items[oldIndex].closeImageState = NONE; | |
4133 } | |
4134 selection.closeImageState = NORMAL; | |
4135 selection.showing = false; | |
4136 | |
4137 Control newControl = selection.control; | |
4138 Control oldControl = null; | |
4139 if (oldIndex !is -1) | |
4140 { | |
4141 oldControl = items[oldIndex].control; | |
4142 } | |
4143 | |
4144 if (newControl !is oldControl) | |
4145 { | |
4146 if (newControl !is null && !newControl.isDisposed()) | |
4147 { | |
4148 newControl.setBounds(getClientArea()); | |
4149 newControl.setVisible(true); | |
4150 } | |
4151 if (oldControl !is null && !oldControl.isDisposed()) | |
4152 { | |
4153 oldControl.setVisible(false); | |
4154 } | |
4155 } | |
4156 showItem(selection); | |
4157 redraw(); | 3738 redraw(); |
4158 } | 3739 } |
4159 | 3740 } |
4160 void setSelection (int index, bool notify) | 3741 /** |
4161 { | 3742 * Set the control that appears in the top right corner of the tab folder. |
4162 int oldSelectedIndex = selectedIndex; | 3743 * Typically this is a close button or a composite with a Menu and close button. |
4163 setSelection(index); | 3744 * The topRight control is optional. Setting the top right control to null will |
4164 if (notify && selectedIndex !is oldSelectedIndex && selectedIndex !is -1) | 3745 * remove it from the tab folder. |
4165 { | 3746 * |
4166 Event event = new Event(); | 3747 * @param control the control to be displayed in the top right corner or null |
4167 event.item = getItem(selectedIndex); | 3748 * |
4168 notifyListeners(DWT.Selection, event); | 3749 * @exception DWTException <ul> |
4169 } | 3750 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
4170 } | 3751 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
4171 | 3752 * <li>ERROR_INVALID_ARGUMENT - if the control is not a child of this CTabFolder</li> |
4172 /** | 3753 * </ul> |
4173 * Sets the receiver's selection background color to the color specified | 3754 * |
4174 * by the argument, or to the default system color for the control | 3755 * @since 2.1 |
4175 * if the argument is null. | 3756 */ |
4176 * | 3757 public void setTopRight(Control control) { |
4177 * @param color the new color (or null) | 3758 setTopRight(control, DWT.RIGHT); |
4178 * | 3759 } |
4179 * @exception IllegalArgumentException <ul> | 3760 /** |
4180 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | 3761 * Set the control that appears in the top right corner of the tab folder. |
4181 * </ul> | 3762 * Typically this is a close button or a composite with a Menu and close button. |
4182 * @exception DWTException <ul> | 3763 * The topRight control is optional. Setting the top right control to null |
4183 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 3764 * will remove it from the tab folder. |
4184 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 3765 * <p> |
4185 * </ul> | 3766 * The alignment parameter sets the layout of the control in the tab area. |
4186 * | 3767 * <code>DWT.RIGHT</code> will cause the control to be positioned on the far |
4187 * @since 3.0 | 3768 * right of the folder and it will have its default size. <code>DWT.FILL</code> |
4188 */ | 3769 * will size the control to fill all the available space to the right of the |
4189 public void setSelectionBackground (Color color) | 3770 * last tab. If there is no available space, the control will not be visible. |
4190 { | 3771 * </p> |
4191 checkWidget(); | 3772 * |
4192 setSelectionHighlightGradientColor(null); | 3773 * @param control the control to be displayed in the top right corner or null |
4193 if (selectionBackground is color) | 3774 * @param alignment <code>DWT.RIGHT</code> or <code>DWT.FILL</code> |
4194 return; | 3775 * |
4195 if (color is null) | 3776 * @exception DWTException <ul> |
4196 color = getDisplay().getSystemColor(SELECTION_BACKGROUND); | 3777 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
4197 selectionBackground = color; | 3778 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
4198 if (selectedIndex > -1) | 3779 * <li>ERROR_INVALID_ARGUMENT - if the control is not a child of this CTabFolder</li> |
4199 redraw(); | 3780 * </ul> |
4200 } | 3781 * |
4201 | 3782 * @since 3.0 |
4202 /** | 3783 */ |
4203 * Specify a gradient of colours to be draw in the background of the selected tab. | 3784 public void setTopRight(Control control, int alignment) { |
4204 * For example to draw a gradient that varies from dark blue to blue and then to | 3785 checkWidget(); |
4205 * white, use the following call to setBackground: | 3786 if (alignment !is DWT.RIGHT && alignment !is DWT.FILL) { |
4206 * <pre> | 3787 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
4207 * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), | 3788 } |
4208 * display.getSystemColor(DWT.COLOR_BLUE), | 3789 if (control !is null && control.getParent() !is this) { |
4209 * display.getSystemColor(DWT.COLOR_WHITE), | 3790 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
4210 * display.getSystemColor(DWT.COLOR_WHITE)}, | 3791 } |
4211 * new int[] {25, 50, 100}); | 3792 topRight = control; |
4212 * </pre> | 3793 topRightAlignment = alignment; |
4213 * | 3794 if (updateItems()) redraw(); |
4214 * @param colors an array of Color that specifies the colors to appear in the gradient | 3795 } |
4215 * in order of appearance left to right. The value <code>null</code> clears the | 3796 /** |
4216 * background gradient. The value <code>null</code> can be used inside the array of | 3797 * Specify whether the close button appears |
4217 * Color to specify the background color. | 3798 * when the user hovers over an unselected tabs. |
4218 * @param percents an array of integers between 0 and 100 specifying the percent of the width | 3799 * |
4219 * of the widget at which the color should change. The size of the percents array must be one | 3800 * @param visible <code>true</code> makes the close button appear |
4220 * less than the size of the colors array. | 3801 * |
4221 * | 3802 * @exception DWTException <ul> |
4222 * @exception DWTException <ul> | 3803 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
4223 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | 3804 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
4224 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | 3805 * </ul> |
4225 * </ul> | 3806 * |
4226 */ | 3807 * @since 3.0 |
4227 public void setSelectionBackground (Color[] colors, int[] percents) | 3808 */ |
4228 { | 3809 public void setUnselectedCloseVisible(bool visible) { |
4229 setSelectionBackground(colors, percents, false); | 3810 checkWidget(); |
4230 } | 3811 if (showUnselectedClose is visible) return; |
4231 | 3812 // display close button when mouse hovers |
4232 /** | 3813 showUnselectedClose = visible; |
4233 * Specify a gradient of colours to be draw in the background of the selected tab. | 3814 updateItems(); |
4234 * For example to draw a vertical gradient that varies from dark blue to blue and then to | 3815 redraw(); |
4235 * white, use the following call to setBackground: | 3816 } |
4236 * <pre> | 3817 /** |
4237 * cfolder.setBackground(new Color[]{display.getSystemColor(DWT.COLOR_DARK_BLUE), | 3818 * Specify whether the image appears on unselected tabs. |
4238 * display.getSystemColor(DWT.COLOR_BLUE), | 3819 * |
4239 * display.getSystemColor(DWT.COLOR_WHITE), | 3820 * @param visible <code>true</code> makes the image appear |
4240 * display.getSystemColor(DWT.COLOR_WHITE)}, | 3821 * |
4241 * new int[] {25, 50, 100}, true); | 3822 * @exception DWTException <ul> |
4242 * </pre> | 3823 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
4243 * | 3824 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
4244 * @param colors an array of Color that specifies the colors to appear in the gradient | 3825 * </ul> |
4245 * in order of appearance left to right. The value <code>null</code> clears the | 3826 * |
4246 * background gradient. The value <code>null</code> can be used inside the array of | 3827 * @since 3.0 |
4247 * Color to specify the background color. | 3828 */ |
4248 * @param percents an array of integers between 0 and 100 specifying the percent of the width | 3829 public void setUnselectedImageVisible(bool visible) { |
4249 * of the widget at which the color should change. The size of the percents array must be one | 3830 checkWidget(); |
4250 * less than the size of the colors array. | 3831 if (showUnselectedImage is visible) return; |
4251 * | 3832 // display image on unselected items |
4252 * @param vertical indicate the direction of the gradient. True is vertical and false is horizontal. | 3833 showUnselectedImage = visible; |
4253 * | 3834 updateItems(); |
4254 * @exception DWTException <ul> | 3835 redraw(); |
4255 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | 3836 } |
4256 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | 3837 /** |
4257 * </ul> | 3838 * Shows the item. If the item is already showing in the receiver, |
4258 * | 3839 * this method simply returns. Otherwise, the items are scrolled until |
4259 * @since 3.0 | 3840 * the item is visible. |
4260 */ | 3841 * |
4261 public void setSelectionBackground (Color[] colors, int[] percents, | 3842 * @param item the item to be shown |
4262 bool vertical) | 3843 * |
4263 { | 3844 * @exception IllegalArgumentException <ul> |
4264 checkWidget(); | 3845 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> |
4265 int colorsLength; | 3846 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> |
4266 Color highlightBeginColor = null; //null is no highlight | 3847 * </ul> |
4267 | 3848 * @exception DWTException <ul> |
4268 if (colors !is null) | 3849 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
4269 { | 3850 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
4270 //The colors array can optionally have an extra entry which describes the highlight top color | 3851 * </ul> |
4271 //Thus its either one or two larger than the percents array | 3852 * |
4272 if (percents is null || !((percents.length is colors.length - 1) || (percents.length is colors.length - 2))) | 3853 * @see CTabFolder#showSelection() |
4273 { | 3854 * |
4274 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 3855 * @since 2.0 |
4275 } | 3856 */ |
4276 for (int i = 0; i < percents.length; i++) | 3857 public void showItem (CTabItem item) { |
4277 { | 3858 checkWidget(); |
4278 if (percents[i] < 0 || percents[i] > 100) | 3859 if (item is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); |
4279 { | 3860 if (item.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
4280 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 3861 int index = indexOf(item); |
4281 } | 3862 if (index is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
4282 if (i > 0 && percents[i] < percents[i - 1]) | 3863 int idx = -1; |
4283 { | 3864 for (int i = 0; i < priority.length; i++) { |
4284 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 3865 if (priority[i] is index) { |
4285 } | 3866 idx = i; |
4286 } | 3867 break; |
4287 //If the colors is exactly two more than percents then last is highlight | 3868 } |
4288 //Keep track of *real* colorsLength (minus the highlight) | 3869 } |
4289 if (percents.length is colors.length - 2) | 3870 if (mru) { |
4290 { | 3871 // move to front of mru order |
4291 highlightBeginColor = colors[colors.length - 1]; | 3872 int[] newPriority = new int[priority.length]; |
4292 colorsLength = colors.length - 1; | 3873 System.arraycopy(priority, 0, newPriority, 1, idx); |
4293 } | 3874 System.arraycopy(priority, idx+1, newPriority, idx+1, priority.length - idx - 1); |
4294 else | 3875 newPriority[0] = index; |
4295 { | 3876 priority = newPriority; |
4296 colorsLength = colors.length; | 3877 } |
4297 } | 3878 if (item.isShowing()) return; |
4298 if (getDisplay().getDepth() < 15) | 3879 updateItems(index); |
4299 { | 3880 redrawTabs(); |
4300 // Don't use gradients on low color displays | 3881 } |
4301 colors = new Color[][colors[colorsLength - 1]]; | 3882 void showList (Rectangle rect) { |
4302 colorsLength = colors.length; | 3883 if (items.length is 0 || !showChevron) return; |
4303 percents = new int[][]; | 3884 if (showMenu is null || showMenu.isDisposed()) { |
4304 } | 3885 showMenu = new Menu(this); |
4305 } | 3886 } else { |
4306 else | 3887 MenuItem[] items = showMenu.getItems(); |
4307 { | 3888 for (int i = 0; i < items.length; i++) { |
4308 colorsLength = 0; | 3889 items[i].dispose(); |
4309 } | 3890 } |
4310 | 3891 } |
4311 // Are these settings the same as before? | 3892 static const String id = "CTabFolder_showList_Index"; //$NON-NLS-1$ |
4312 if (selectionBgImage is null) | 3893 for (int i = 0; i < items.length; i++) { |
4313 { | 3894 CTabItem tab = items[i]; |
4314 if ((selectionGradientColors !is null) && (colors !is null) && (selectionGradientColors.length is colorsLength)) | 3895 if (tab.showing) continue; |
4315 { | 3896 MenuItem item = new MenuItem(showMenu, DWT.NONE); |
4316 bool same = false; | 3897 item.setText(tab.getText()); |
4317 for (int i = 0; i < selectionGradientColors.length; i++) | 3898 item.setImage(tab.getImage()); |
4318 { | 3899 item.setData(id, tab); |
4319 if (selectionGradientColors[i] is null) | 3900 item.addSelectionListener(new class() SelectionAdapter { |
4320 { | 3901 public void widgetSelected(SelectionEvent e) { |
4321 same = colors[i] is null; | 3902 MenuItem menuItem = cast(MenuItem)e.widget; |
4322 } | 3903 int index = indexOf(cast(CTabItem)menuItem.getData(id)); |
4323 else | 3904 this.outer.setSelection(index, true); |
4324 { | 3905 } |
4325 same = selectionGradientColors[i].opEquals(colors[i]); | 3906 }); |
4326 } | 3907 } |
4327 if (!same) | 3908 int x = rect.x; |
4328 break; | 3909 int y = rect.y + rect.height; |
4329 } | 3910 Point location = getDisplay().map(this, null, x, y); |
4330 if (same) | 3911 showMenu.setLocation(location.x, location.y); |
4331 { | 3912 showMenu.setVisible(true); |
4332 for (int i = 0; i < selectionGradientPercents.length; i++) | 3913 } |
4333 { | 3914 /** |
4334 same = selectionGradientPercents[i] is percents[i]; | 3915 * Shows the selection. If the selection is already showing in the receiver, |
4335 if (!same) | 3916 * this method simply returns. Otherwise, the items are scrolled until |
4336 break; | 3917 * the selection is visible. |
4337 } | 3918 * |
4338 } | 3919 * @exception DWTException <ul> |
4339 if (same && this.selectionGradientVertical is vertical) | 3920 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
4340 return; | 3921 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
4341 } | 3922 * </ul> |
4342 } | 3923 * |
4343 else | 3924 * @see CTabFolder#showItem(CTabItem) |
4344 { | 3925 * |
4345 selectionBgImage = null; | 3926 * @since 2.0 |
4346 } | 3927 */ |
4347 // Store the new settings | 3928 public void showSelection () { |
4348 if (colors is null) | 3929 checkWidget (); |
4349 { | 3930 if (selectedIndex !is -1) { |
4350 selectionGradientColors = null; | 3931 showItem(getSelection()); |
4351 selectionGradientPercents = null; | 3932 } |
4352 selectionGradientVertical = false; | 3933 } |
4353 setSelectionBackground(cast(Color) null); | 3934 |
4354 setSelectionHighlightGradientColor(null); | 3935 void _setToolTipText (int x, int y) { |
4355 } | 3936 String oldTip = getToolTipText(); |
4356 else | 3937 String newTip = _getToolTip(x, y); |
4357 { | 3938 if (newTip is null || newTip!=oldTip) { |
4358 selectionGradientColors = new Color[colorsLength]; | 3939 setToolTipText(newTip); |
4359 for (int i = 0; i < colorsLength; ++i) | 3940 } |
4360 { | 3941 } |
4361 selectionGradientColors[i] = colors[i]; | 3942 |
4362 } | 3943 bool updateItems() { |
4363 selectionGradientPercents = new int[percents.length]; | 3944 return updateItems(selectedIndex); |
4364 for (int i = 0; i < percents.length; ++i) | 3945 } |
4365 { | 3946 |
4366 selectionGradientPercents[i] = percents[i]; | 3947 bool updateItems(int showIndex) { |
4367 } | 3948 if (!single && !mru && showIndex !is -1) { |
4368 selectionGradientVertical = vertical; | 3949 // make sure selected item will be showing |
4369 setSelectionBackground( | 3950 int firstIndex = showIndex; |
4370 selectionGradientColors[selectionGradientColors.length - 1]); | 3951 if (priority[0] < showIndex) { |
4371 setSelectionHighlightGradientColor(highlightBeginColor); | 3952 int maxWidth = getRightItemEdge() - borderLeft; |
4372 } | 3953 if (!simple) maxWidth -= curveWidth - 2*curveIndent; |
4373 | 3954 int width = 0; |
4374 // Refresh with the new settings | 3955 int[] widths = new int[items.length]; |
4375 if (selectedIndex > -1) | 3956 GC gc = new GC(this); |
4376 redraw(); | 3957 for (int i = priority[0]; i <= showIndex; i++) { |
4377 } | 3958 widths[i] = items[i].preferredWidth(gc, i is selectedIndex, true); |
4378 | 3959 width += widths[i]; |
4379 /* | 3960 if (width > maxWidth) break; |
4380 * Set the color for the highlight start for selected tabs. | 3961 } |
4381 * Update the cache of highlight gradient colors if required. | 3962 if (width > maxWidth) { |
4382 */ | 3963 width = 0; |
4383 | 3964 for (int i = showIndex; i >= 0; i--) { |
4384 void setSelectionHighlightGradientColor (Color start) | 3965 if (widths[i] is 0) widths[i] = items[i].preferredWidth(gc, i is selectedIndex, true); |
4385 { | |
4386 //Set to null to match all the early return cases. | |
4387 //For early returns, don't realloc the cache, we may get a cache hit next time we're given the highlight | |
4388 selectionHighlightGradientBegin = null; | |
4389 | |
4390 if (start is null) | |
4391 return; | |
4392 | |
4393 //don't bother on low colour | |
4394 if (getDisplay().getDepth() < 15) | |
4395 return; | |
4396 | |
4397 //don't bother if we don't have a background gradient | |
4398 if (selectionGradientColors.length < 2) | |
4399 return; | |
4400 | |
4401 //OK we know its a valid gradient now | |
4402 selectionHighlightGradientBegin = start; | |
4403 | |
4404 if (!isSelectionHighlightColorsCacheHit(start)) | |
4405 createSelectionHighlightGradientColors(start); //if no cache hit then compute new ones | |
4406 } | |
4407 | |
4408 /* | |
4409 * Return true if given start color, the cache of highlight colors we have | |
4410 * would match the highlight colors we'd compute. | |
4411 */ | |
4412 bool isSelectionHighlightColorsCacheHit (Color start) | |
4413 { | |
4414 | |
4415 if (selectionHighlightGradientColorsCache is null) | |
4416 return false; | |
4417 | |
4418 //this case should never happen but check to be safe before accessing array indexes | |
4419 if (selectionHighlightGradientColorsCache.length < 2) | |
4420 return false; | |
4421 | |
4422 Color highlightBegin = selectionHighlightGradientColorsCache[0]; | |
4423 Color | |
4424 highlightEnd = selectionHighlightGradientColorsCache[selectionHighlightGradientColorsCache.length - 1]; | |
4425 | |
4426 if (!highlightBegin.opEquals(start)) | |
4427 return false; | |
4428 | |
4429 //Compare number of colours we have vs. we'd compute | |
4430 if (selectionHighlightGradientColorsCache.length !is tabHeight) | |
4431 return false; | |
4432 | |
4433 //Compare existing highlight end to what it would be (selectionBackground) | |
4434 if (!highlightEnd.opEquals(selectionBackground)) | |
4435 return false; | |
4436 | |
4437 return true; | |
4438 } | |
4439 | |
4440 /** | |
4441 * Set the image to be drawn in the background of the selected tab. Image | |
4442 * is stretched or compressed to cover entire selection tab area. | |
4443 * | |
4444 * @param image the image to be drawn in the background | |
4445 * | |
4446 * @exception DWTException <ul> | |
4447 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4448 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4449 * </ul> | |
4450 */ | |
4451 public void setSelectionBackground (Image image) | |
4452 { | |
4453 checkWidget(); | |
4454 setSelectionHighlightGradientColor(null); | |
4455 if (image is selectionBgImage) | |
4456 return; | |
4457 if (image !is null) | |
4458 { | |
4459 selectionGradientColors = null; | |
4460 selectionGradientPercents = null; | |
4461 disposeSelectionHighlightGradientColors(); | |
4462 } | |
4463 selectionBgImage = image; | |
4464 if (selectedIndex > -1) | |
4465 redraw(); | |
4466 } | |
4467 | |
4468 /** | |
4469 * Set the foreground color of the selected tab. | |
4470 * | |
4471 * @param color the color of the text displayed in the selected tab | |
4472 * | |
4473 * @exception DWTException <ul> | |
4474 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4475 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4476 * </ul> | |
4477 */ | |
4478 public void setSelectionForeground (Color color) | |
4479 { | |
4480 checkWidget(); | |
4481 if (selectionForeground is color) | |
4482 return; | |
4483 if (color is null) | |
4484 color = getDisplay().getSystemColor(SELECTION_FOREGROUND); | |
4485 selectionForeground = color; | |
4486 if (selectedIndex > -1) | |
4487 redraw(); | |
4488 } | |
4489 | |
4490 /* | |
4491 * Allocate colors for the highlight line. | |
4492 * Colours will be a gradual blend ranging from to. | |
4493 * Blend length will be tab height. | |
4494 * Recompute this if tab height changes. | |
4495 * Could remain null if there'd be no gradient (start=end or low colour display) | |
4496 */ | |
4497 void createSelectionHighlightGradientColors (Color start) | |
4498 { | |
4499 disposeSelectionHighlightGradientColors(); //dispose if existing | |
4500 | |
4501 if (start is null) | |
4502 //shouldn't happen but just to be safe | |
4503 return; | |
4504 | |
4505 //alloc colours for entire height to ensure it matches wherever we stop drawing | |
4506 int fadeGradientSize = tabHeight; | |
4507 | |
4508 RGB from = start.getRGB(); | |
4509 RGB to = selectionBackground.getRGB(); | |
4510 | |
4511 selectionHighlightGradientColorsCache = new Color[fadeGradientSize]; | |
4512 int denom = fadeGradientSize - 1; | |
4513 | |
4514 for (int i = 0; i < fadeGradientSize; i++) | |
4515 { | |
4516 int propFrom = denom - i; | |
4517 int propTo = i; | |
4518 int red = (to.red * propTo + from.red * propFrom) / denom; | |
4519 int green = (to.green * propTo + from.green * propFrom) / denom; | |
4520 int blue = (to.blue * propTo + from.blue * propFrom) / denom; | |
4521 selectionHighlightGradientColorsCache[i] = new Color(getDisplay(), | |
4522 red, green, blue); | |
4523 } | |
4524 } | |
4525 | |
4526 void disposeSelectionHighlightGradientColors () | |
4527 { | |
4528 if (selectionHighlightGradientColorsCache is null) | |
4529 return; | |
4530 for (int i = 0; i < selectionHighlightGradientColorsCache.length; i++) | |
4531 { | |
4532 selectionHighlightGradientColorsCache[i].dispose(); | |
4533 } | |
4534 selectionHighlightGradientColorsCache = null; | |
4535 } | |
4536 | |
4537 /* | |
4538 * Return the gradient start color for selected tabs, which is the start of the tab fade | |
4539 * (end is selectionBackground). | |
4540 */ | |
4541 Color getSelectionBackgroundGradientBegin () | |
4542 { | |
4543 if (selectionGradientColors is null) | |
4544 return getSelectionBackground(); | |
4545 if (selectionGradientColors.length is 0) | |
4546 return getSelectionBackground(); | |
4547 return selectionGradientColors[0]; | |
4548 } | |
4549 | |
4550 /** | |
4551 * Sets the shape that the CTabFolder will use to render itself. | |
4552 * | |
4553 * @param simple <code>true</code> if the CTabFolder should render itself in a simple, traditional style | |
4554 * | |
4555 * @exception DWTException <ul> | |
4556 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4557 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4558 * </ul> | |
4559 * | |
4560 * @since 3.0 | |
4561 */ | |
4562 public void setSimple (bool simple) | |
4563 { | |
4564 checkWidget(); | |
4565 if (this.simple !is simple) | |
4566 { | |
4567 this.simple = simple; | |
4568 Rectangle rectBefore = getClientArea(); | |
4569 updateItems(); | |
4570 Rectangle rectAfter = getClientArea(); | |
4571 if (!rectBefore.opEquals(rectAfter)) | |
4572 { | |
4573 notifyListeners(DWT.Resize, new Event()); | |
4574 } | |
4575 redraw(); | |
4576 } | |
4577 } | |
4578 | |
4579 /** | |
4580 * Sets the number of tabs that the CTabFolder should display | |
4581 * | |
4582 * @param single <code>true</code> if only the selected tab should be displayed otherwise, multiple tabs will be shown. | |
4583 * | |
4584 * @exception DWTException <ul> | |
4585 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4586 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4587 * </ul> | |
4588 * | |
4589 * @since 3.0 | |
4590 */ | |
4591 public void setSingle (bool single) | |
4592 { | |
4593 checkWidget(); | |
4594 if (this.single !is single) | |
4595 { | |
4596 this.single = single; | |
4597 if (!single) | |
4598 { | |
4599 for (int i = 0; i < items.length; i++) | |
4600 { | |
4601 if (i !is selectedIndex && items[i].closeImageState is NORMAL) | |
4602 { | |
4603 items[i].closeImageState = NONE; | |
4604 } | |
4605 } | |
4606 } | |
4607 Rectangle rectBefore = getClientArea(); | |
4608 updateItems(); | |
4609 Rectangle rectAfter = getClientArea(); | |
4610 if (!rectBefore.opEquals(rectAfter)) | |
4611 { | |
4612 notifyListeners(DWT.Resize, new Event()); | |
4613 } | |
4614 redraw(); | |
4615 } | |
4616 } | |
4617 | |
4618 /** | |
4619 * Specify a fixed height for the tab items. If no height is specified, | |
4620 * the default height is the height of the text or the image, whichever | |
4621 * is greater. Specifying a height of -1 will revert to the default height. | |
4622 * | |
4623 * @param height the pixel value of the height or -1 | |
4624 * | |
4625 * @exception DWTException <ul> | |
4626 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4627 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4628 * <li>ERROR_INVALID_ARGUMENT - if called with a height of less than 0</li> | |
4629 * </ul> | |
4630 */ | |
4631 public void setTabHeight (int height) | |
4632 { | |
4633 checkWidget(); | |
4634 if (height < -1) | |
4635 { | |
4636 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
4637 } | |
4638 fixedTabHeight = height; | |
4639 updateTabHeight(false); | |
4640 } | |
4641 | |
4642 /** | |
4643 * Specify whether the tabs should appear along the top of the folder | |
4644 * or along the bottom of the folder. | |
4645 * | |
4646 * @param position <code>DWT.TOP</code> for tabs along the top or <code>DWT.BOTTOM</code> for tabs along the bottom | |
4647 * | |
4648 * @exception DWTException <ul> | |
4649 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4650 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4651 * <li>ERROR_INVALID_ARGUMENT - if the position value is not either DWT.TOP or DWT.BOTTOM</li> | |
4652 * </ul> | |
4653 * | |
4654 * @since 3.0 | |
4655 */ | |
4656 public void setTabPosition (int position) | |
4657 { | |
4658 checkWidget(); | |
4659 if (position !is DWT.TOP && position !is DWT.BOTTOM) | |
4660 { | |
4661 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
4662 } | |
4663 if (onBottom !is (position is DWT.BOTTOM)) | |
4664 { | |
4665 onBottom = position is DWT.BOTTOM; | |
4666 borderTop = onBottom ? borderLeft : 0; | |
4667 borderBottom = onBottom ? 0 : borderRight; | |
4668 updateTabHeight(true); | |
4669 Rectangle rectBefore = getClientArea(); | |
4670 updateItems(); | |
4671 Rectangle rectAfter = getClientArea(); | |
4672 if (!rectBefore.opEquals(rectAfter)) | |
4673 { | |
4674 notifyListeners(DWT.Resize, new Event()); | |
4675 } | |
4676 redraw(); | |
4677 } | |
4678 } | |
4679 | |
4680 /** | |
4681 * Set the control that appears in the top right corner of the tab folder. | |
4682 * Typically this is a close button or a composite with a Menu and close button. | |
4683 * The topRight control is optional. Setting the top right control to null will | |
4684 * remove it from the tab folder. | |
4685 * | |
4686 * @param control the control to be displayed in the top right corner or null | |
4687 * | |
4688 * @exception DWTException <ul> | |
4689 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4690 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4691 * <li>ERROR_INVALID_ARGUMENT - if the control is not a child of this CTabFolder</li> | |
4692 * </ul> | |
4693 * | |
4694 * @since 2.1 | |
4695 */ | |
4696 public void setTopRight (Control control) | |
4697 { | |
4698 setTopRight(control, DWT.RIGHT); | |
4699 } | |
4700 | |
4701 /** | |
4702 * Set the control that appears in the top right corner of the tab folder. | |
4703 * Typically this is a close button or a composite with a Menu and close button. | |
4704 * The topRight control is optional. Setting the top right control to null | |
4705 * will remove it from the tab folder. | |
4706 * <p> | |
4707 * The alignment parameter sets the layout of the control in the tab area. | |
4708 * <code>DWT.RIGHT</code> will cause the control to be positioned on the far | |
4709 * right of the folder and it will have its default size. <code>DWT.FILL</code> | |
4710 * will size the control to fill all the available space to the right of the | |
4711 * last tab. If there is no available space, the control will not be visible. | |
4712 * </p> | |
4713 * | |
4714 * @param control the control to be displayed in the top right corner or null | |
4715 * @param alignment <code>DWT.RIGHT</code> or <code>DWT.FILL</code> | |
4716 * | |
4717 * @exception DWTException <ul> | |
4718 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4719 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4720 * <li>ERROR_INVALID_ARGUMENT - if the control is not a child of this CTabFolder</li> | |
4721 * </ul> | |
4722 * | |
4723 * @since 3.0 | |
4724 */ | |
4725 public void setTopRight (Control control, int alignment) | |
4726 { | |
4727 checkWidget(); | |
4728 if (alignment !is DWT.RIGHT && alignment !is DWT.FILL) | |
4729 { | |
4730 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
4731 } | |
4732 if (control !is null && control.getParent() !is this) | |
4733 { | |
4734 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
4735 } | |
4736 topRight = control; | |
4737 topRightAlignment = alignment; | |
4738 if (updateItems()) | |
4739 redraw(); | |
4740 } | |
4741 | |
4742 /** | |
4743 * Specify whether the close button appears | |
4744 * when the user hovers over an unselected tabs. | |
4745 * | |
4746 * @param visible <code>true</code> makes the close button appear | |
4747 * | |
4748 * @exception DWTException <ul> | |
4749 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4750 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4751 * </ul> | |
4752 * | |
4753 * @since 3.0 | |
4754 */ | |
4755 public void setUnselectedCloseVisible (bool visible) | |
4756 { | |
4757 checkWidget(); | |
4758 if (showUnselectedClose is visible) | |
4759 return; | |
4760 // display close button when mouse hovers | |
4761 showUnselectedClose = visible; | |
4762 updateItems(); | |
4763 redraw(); | |
4764 } | |
4765 | |
4766 /** | |
4767 * Specify whether the image appears on unselected tabs. | |
4768 * | |
4769 * @param visible <code>true</code> makes the image appear | |
4770 * | |
4771 * @exception DWTException <ul> | |
4772 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4773 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4774 * </ul> | |
4775 * | |
4776 * @since 3.0 | |
4777 */ | |
4778 public void setUnselectedImageVisible (bool visible) | |
4779 { | |
4780 checkWidget(); | |
4781 if (showUnselectedImage is visible) | |
4782 return; | |
4783 // display image on unselected items | |
4784 showUnselectedImage = visible; | |
4785 updateItems(); | |
4786 redraw(); | |
4787 } | |
4788 | |
4789 /** | |
4790 * Shows the item. If the item is already showing in the receiver, | |
4791 * this method simply returns. Otherwise, the items are scrolled until | |
4792 * the item is visible. | |
4793 * | |
4794 * @param item the item to be shown | |
4795 * | |
4796 * @exception IllegalArgumentException <ul> | |
4797 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
4798 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
4799 * </ul> | |
4800 * @exception DWTException <ul> | |
4801 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4802 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4803 * </ul> | |
4804 * | |
4805 * @see CTabFolder#showSelection() | |
4806 * | |
4807 * @since 2.0 | |
4808 */ | |
4809 public void showItem (CTabItem item) | |
4810 { | |
4811 checkWidget(); | |
4812 if (item is null) | |
4813 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
4814 if (item.isDisposed()) | |
4815 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
4816 int index = indexOf(item); | |
4817 if (index is -1) | |
4818 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
4819 int idx = -1; | |
4820 for (int i = 0; i < priority.length; i++) | |
4821 { | |
4822 if (priority[i] is index) | |
4823 { | |
4824 idx = i; | |
4825 break; | |
4826 } | |
4827 } | |
4828 if (mru) | |
4829 { | |
4830 // move to front of mru order | |
4831 int[] newPriority = new int[priority.length]; | |
4832 System.arraycopy(priority, 0, newPriority, 1, idx); | |
4833 System.arraycopy(priority, idx + 1, newPriority, idx + 1, | |
4834 priority.length - idx - 1); | |
4835 newPriority[0] = index; | |
4836 priority = newPriority; | |
4837 } | |
4838 if (item.isShowing()) | |
4839 return; | |
4840 updateItems(index); | |
4841 redrawTabs(); | |
4842 } | |
4843 | |
4844 void showList (Rectangle rect) | |
4845 { | |
4846 if (items.length is 0 || !showChevron) | |
4847 return; | |
4848 if (showMenu is null || showMenu.isDisposed()) | |
4849 { | |
4850 showMenu = new Menu(this); | |
4851 } | |
4852 else | |
4853 { | |
4854 MenuItem[] items = showMenu.getItems(); | |
4855 for (int i = 0; i < items.length; i++) | |
4856 { | |
4857 items[i].dispose(); | |
4858 } | |
4859 } | |
4860 const String id = "CTabFolder_showList_Index"; //$NON-NLS-1$ | |
4861 for (int i = 0; i < items.length; i++) | |
4862 { | |
4863 CTabItem tab = items[i]; | |
4864 if (tab.showing) | |
4865 continue; | |
4866 MenuItem item = new MenuItem(showMenu, DWT.NONE); | |
4867 item.setText(tab.getText()); | |
4868 item.setImage(tab.getImage()); | |
4869 item.setData(id, tab); | |
4870 item.addSelectionListener(new class SelectionAdapter | |
4871 { | |
4872 public void widgetSelected (SelectionEvent e) | |
4873 { | |
4874 MenuItem menuItem = cast(MenuItem) e.widget; | |
4875 int index = indexOf(cast(CTabItem) menuItem.getData(id)); | |
4876 this.setSelection(index, true); | |
4877 } | |
4878 }); | |
4879 } | |
4880 int x = rect.x; | |
4881 int y = rect.y + rect.height; | |
4882 Point location = getDisplay().map(this, null, x, y); | |
4883 showMenu.setLocation(location.x, location.y); | |
4884 showMenu.setVisible(true); | |
4885 } | |
4886 | |
4887 /** | |
4888 * Shows the selection. If the selection is already showing in the receiver, | |
4889 * this method simply returns. Otherwise, the items are scrolled until | |
4890 * the selection is visible. | |
4891 * | |
4892 * @exception DWTException <ul> | |
4893 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
4894 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4895 * </ul> | |
4896 * | |
4897 * @see CTabFolder#showItem(CTabItem) | |
4898 * | |
4899 * @since 2.0 | |
4900 */ | |
4901 public void showSelection () | |
4902 { | |
4903 checkWidget(); | |
4904 if (selectedIndex !is -1) | |
4905 { | |
4906 showItem(getSelection()); | |
4907 } | |
4908 } | |
4909 | |
4910 void _setToolTipText (int x, int y) | |
4911 { | |
4912 String oldTip = getToolTipText(); | |
4913 String newTip = _getToolTip(x, y); | |
4914 if (newTip is null || !newTip.opEquals(oldTip)) | |
4915 { | |
4916 setToolTipText(newTip); | |
4917 } | |
4918 } | |
4919 | |
4920 bool updateItems () | |
4921 { | |
4922 return updateItems(selectedIndex); | |
4923 } | |
4924 | |
4925 bool updateItems (int showIndex) | |
4926 { | |
4927 if (!single && !mru && showIndex !is -1) | |
4928 { | |
4929 // make sure selected item will be showing | |
4930 int firstIndex = showIndex; | |
4931 if (priority[0] < showIndex) | |
4932 { | |
4933 int maxWidth = getRightItemEdge() - borderLeft; | |
4934 if (!simple) | |
4935 maxWidth -= curveWidth - 2 * curveIndent; | |
4936 int width = 0; | |
4937 int[] widths = new int[items.length]; | |
4938 GC gc = new GC(this); | |
4939 for (int i = priority[0]; i <= showIndex; i++) | |
4940 { | |
4941 widths[i] = items[i].preferredWidth(gc, i is selectedIndex, | |
4942 true); | |
4943 width += widths[i]; | 3966 width += widths[i]; |
4944 if (width > maxWidth) | 3967 if (width > maxWidth) break; |
4945 break; | 3968 firstIndex = i; |
4946 } | 3969 } |
4947 if (width > maxWidth) | 3970 } else { |
4948 { | 3971 firstIndex = priority[0]; |
4949 width = 0; | 3972 for (int i = showIndex + 1; i < items.length; i++) { |
4950 for (int i = showIndex; i >= 0; i--) | 3973 widths[i] = items[i].preferredWidth(gc, i is selectedIndex, true); |
4951 { | 3974 width += widths[i]; |
4952 if (widths[i] is 0) | 3975 if (width >= maxWidth) break; |
4953 widths[i] = items[i].preferredWidth(gc, | 3976 } |
4954 i is selectedIndex, true); | 3977 if (width < maxWidth) { |
3978 for (int i = priority[0] - 1; i >= 0; i--) { | |
3979 if (widths[i] is 0) widths[i] = items[i].preferredWidth(gc, i is selectedIndex, true); | |
4955 width += widths[i]; | 3980 width += widths[i]; |
4956 if (width > maxWidth) | 3981 if (width > maxWidth) break; |
4957 break; | |
4958 firstIndex = i; | 3982 firstIndex = i; |
4959 } | 3983 } |
4960 } | 3984 } |
4961 else | |
4962 { | |
4963 firstIndex = priority[0]; | |
4964 for (int i = showIndex + 1; i < items.length; i++) | |
4965 { | |
4966 widths[i] = items[i].preferredWidth(gc, | |
4967 i is selectedIndex, true); | |
4968 width += widths[i]; | |
4969 if (width >= maxWidth) | |
4970 break; | |
4971 } | |
4972 if (width < maxWidth) | |
4973 { | |
4974 for (int i = priority[0] - 1; i >= 0; i--) | |
4975 { | |
4976 if (widths[i] is 0) | |
4977 widths[i] = items[i].preferredWidth(gc, | |
4978 i is selectedIndex, true); | |
4979 width += widths[i]; | |
4980 if (width > maxWidth) | |
4981 break; | |
4982 firstIndex = i; | |
4983 } | |
4984 } | |
4985 } | |
4986 gc.dispose(); | |
4987 } | |
4988 if (firstIndex !is priority[0]) | |
4989 { | |
4990 int index = 0; | |
4991 for (int i = firstIndex; i < items.length; i++) | |
4992 { | |
4993 priority[index++] = i; | |
4994 } | |
4995 for (int i = 0; i < firstIndex; i++) | |
4996 { | |
4997 priority[index++] = i; | |
4998 } | |
4999 } | |
5000 } | |
5001 | |
5002 bool oldShowChevron = showChevron; | |
5003 bool changed = setItemSize(); | |
5004 changed |= setItemLocation(); | |
5005 setButtonBounds(); | |
5006 changed |= showChevron !is oldShowChevron; | |
5007 if (changed && getToolTipText() !is null) | |
5008 { | |
5009 Point pt = getDisplay().getCursorLocation(); | |
5010 pt = toControl(pt); | |
5011 _setToolTipText(pt.x, pt.y); | |
5012 } | |
5013 return changed; | |
5014 } | |
5015 | |
5016 bool updateTabHeight (bool force) | |
5017 { | |
5018 int style = getStyle(); | |
5019 if (fixedTabHeight is 0 && (style & DWT.FLAT) !is 0 && (style & DWT.BORDER) is 0) | |
5020 highlight_header = 0; | |
5021 int oldHeight = tabHeight; | |
5022 if (fixedTabHeight !is DWT.DEFAULT) | |
5023 { | |
5024 tabHeight = fixedTabHeight is 0 ? 0 : fixedTabHeight + 1; // +1 for line drawn across top of tab | |
5025 } | |
5026 else | |
5027 { | |
5028 int tempHeight = 0; | |
5029 GC gc = new GC(this); | |
5030 if (items.length is 0) | |
5031 { | |
5032 tempHeight = gc.textExtent("Default", CTabItem.FLAGS).y + CTabItem.TOP_MARGIN + CTabItem.BOTTOM_MARGIN; //$NON-NLS-1$ | |
5033 } | |
5034 else | |
5035 { | |
5036 for (int i = 0; i < items.length; i++) | |
5037 { | |
5038 tempHeight = Math.max(tempHeight, items[i].preferredHeight( | |
5039 gc)); | |
5040 } | |
5041 } | 3985 } |
5042 gc.dispose(); | 3986 gc.dispose(); |
5043 tabHeight = tempHeight; | 3987 } |
5044 } | 3988 if (firstIndex !is priority[0]) { |
5045 if (!force && tabHeight is oldHeight) | 3989 int index = 0; |
5046 return false; | 3990 for (int i = firstIndex; i < items.length; i++) { |
5047 | 3991 priority[index++] = i; |
5048 oldSize = null; | 3992 } |
5049 if (onBottom) | 3993 for (int i = 0; i < firstIndex; i++) { |
5050 { | 3994 priority[index++] = i; |
5051 int d = tabHeight - 12; | 3995 } |
5052 curve = new int[][0 , 13 + d , 0 , 12 + d , 2 , 12 + d , 3 , 11 + d , 5 , 11 + d , 6 , 10 + d , 7 , 10 + d , 9 , 8 + d , 10 , 8 + d , 11 , 7 + d , 11 + d , 7 , 12 + d , 6 , 13 + d , 6 , 15 + d , 4 , 16 + d , 4 , 17 + d , 3 , 19 + d , 3 , 20 + d , 2 , 22 + d , 2 , 23 + d , 1]; | 3996 } |
5053 curveWidth = 26 + d; | 3997 } |
5054 curveIndent = curveWidth / 3; | 3998 |
5055 } | 3999 bool oldShowChevron = showChevron; |
5056 else | 4000 bool changed = setItemSize(); |
5057 { | 4001 changed |= setItemLocation(); |
5058 int d = tabHeight - 12; | 4002 setButtonBounds(); |
5059 curve = new int[][0 , 0 , 0 , 1 , 2 , 1 , 3 , 2 , 5 , 2 , 6 , 3 , 7 , 3 , 9 , 5 , 10 , 5 , 11 , 6 , 11 + d , 6 + d , 12 + d , 7 + d , 13 + d , 7 + d , 15 + d , 9 + d , 16 + d , 9 + d , 17 + d , 10 + d , 19 + d , 10 + d , 20 + d , 11 + d , 22 + d , 11 + d , 23 + d , 12 + d]; | 4003 changed |= showChevron !is oldShowChevron; |
5060 curveWidth = 26 + d; | 4004 if (changed && getToolTipText() !is null) { |
5061 curveIndent = curveWidth / 3; | 4005 Point pt = getDisplay().getCursorLocation(); |
5062 | 4006 pt = toControl(pt); |
5063 //this could be static but since values depend on curve, better to keep in one place | 4007 _setToolTipText(pt.x, pt.y); |
5064 topCurveHighlightStart = new int[][0 , 2 , 1 , 2 , 2 , 2 , 3 , 3 , 4 , 3 , 5 , 3 , 6 , 4 , 7 , 4 , 8 , 5 , 9 , 6 , 10 , 6]; | 4008 } |
5065 | 4009 return changed; |
5066 //also, by adding in 'd' here we save some math cost when drawing the curve | 4010 } |
5067 topCurveHighlightEnd = new int[][10 + d , 6 + d , 11 + d , 7 + d , 12 + d , 8 + d , 13 + d , 8 + d , 14 + d , 9 + d , 15 + d , 10 + d , 16 + d , 10 + d , 17 + d , 11 + d , 18 + d , 11 + d , 19 + d , 11 + d , 20 + d , 12 + d , 21 + d , 12 + d , 22 + d , 12 + d]; | 4011 bool updateTabHeight(bool force){ |
5068 } | 4012 int style = getStyle(); |
5069 notifyListeners(DWT.Resize, new Event()); | 4013 if (fixedTabHeight is 0 && (style & DWT.FLAT) !is 0 && (style & DWT.BORDER) is 0) highlight_header = 0; |
5070 return true; | 4014 int oldHeight = tabHeight; |
5071 } | 4015 if (fixedTabHeight !is DWT.DEFAULT) { |
5072 | 4016 tabHeight = fixedTabHeight is 0 ? 0 : fixedTabHeight + 1; // +1 for line drawn across top of tab |
5073 String _getToolTip (int x, int y) | 4017 } else { |
5074 { | 4018 int tempHeight = 0; |
5075 if (showMin && minRect.contains(x, y)) | 4019 GC gc = new GC(this); |
5076 return minimized ? DWT.getMessage("DWT_Restore") : DWT.getMessage( | 4020 if (items.length is 0) { |
5077 "DWT_Minimize"); //$NON-NLS-1$ //$NON-NLS-2$ | 4021 tempHeight = gc.textExtent("Default", CTabItem.FLAGS).y + CTabItem.TOP_MARGIN + CTabItem.BOTTOM_MARGIN; //$NON-NLS-1$ |
5078 if (showMax && maxRect.contains(x, y)) | 4022 } else { |
5079 return maximized ? DWT.getMessage("DWT_Restore") : DWT.getMessage( | 4023 for (int i=0; i < items.length; i++) { |
5080 "DWT_Maximize"); //$NON-NLS-1$ //$NON-NLS-2$ | 4024 tempHeight = Math.max(tempHeight, items[i].preferredHeight(gc)); |
5081 if (showChevron && chevronRect.contains(x, y)) | 4025 } |
5082 return DWT.getMessage("DWT_ShowList"); //$NON-NLS-1$ | 4026 } |
5083 CTabItem item = getItem(new Point(x, y)); | 4027 gc.dispose(); |
5084 if (item is null) | 4028 tabHeight = tempHeight; |
5085 return null; | 4029 } |
5086 if (!item.showing) | 4030 if (!force && tabHeight is oldHeight) return false; |
5087 return null; | 4031 |
5088 if ((showClose || item.showClose) && item.closeRect.contains(x, y)) | 4032 oldSize = null; |
5089 { | 4033 if (onBottom) { |
5090 return DWT.getMessage("DWT_Close"); //$NON-NLS-1$ | 4034 int d = tabHeight - 12; |
5091 } | 4035 curve = [0,13+d, 0,12+d, 2,12+d, 3,11+d, 5,11+d, 6,10+d, 7,10+d, 9,8+d, 10,8+d, |
5092 return item.getToolTipText(); | 4036 11,7+d, 11+d,7, |
5093 } | 4037 12+d,6, 13+d,6, 15+d,4, 16+d,4, 17+d,3, 19+d,3, 20+d,2, 22+d,2, 23+d,1]; |
5094 } | 4038 curveWidth = 26+d; |
4039 curveIndent = curveWidth/3; | |
4040 } else { | |
4041 int d = tabHeight - 12; | |
4042 curve = [0,0, 0,1, 2,1, 3,2, 5,2, 6,3, 7,3, 9,5, 10,5, | |
4043 11,6, 11+d,6+d, | |
4044 12+d,7+d, 13+d,7+d, 15+d,9+d, 16+d,9+d, 17+d,10+d, 19+d,10+d, 20+d,11+d, 22+d,11+d, 23+d,12+d]; | |
4045 curveWidth = 26+d; | |
4046 curveIndent = curveWidth/3; | |
4047 | |
4048 //this could be static but since values depend on curve, better to keep in one place | |
4049 topCurveHighlightStart = [ | |
4050 0, 2, 1, 2, 2, 2, | |
4051 3, 3, 4, 3, 5, 3, | |
4052 6, 4, 7, 4, | |
4053 8, 5, | |
4054 9, 6, 10, 6]; | |
4055 | |
4056 //also, by adding in 'd' here we save some math cost when drawing the curve | |
4057 topCurveHighlightEnd = [ | |
4058 10+d, 6+d, | |
4059 11+d, 7+d, | |
4060 12+d, 8+d, 13+d, 8+d, | |
4061 14+d, 9+d, | |
4062 15+d, 10+d, 16+d, 10+d, | |
4063 17+d, 11+d, 18+d, 11+d, 19+d, 11+d, | |
4064 20+d, 12+d, 21+d, 12+d, 22+d, 12+d ]; | |
4065 } | |
4066 notifyListeners(DWT.Resize, new Event()); | |
4067 return true; | |
4068 } | |
4069 String _getToolTip(int x, int y) { | |
4070 if (showMin && minRect.contains(x, y)) return minimized ? DWT.getMessage("SWT_Restore") : DWT.getMessage("SWT_Minimize"); //$NON-NLS-1$ //$NON-NLS-2$ | |
4071 if (showMax && maxRect.contains(x, y)) return maximized ? DWT.getMessage("SWT_Restore") : DWT.getMessage("SWT_Maximize"); //$NON-NLS-1$ //$NON-NLS-2$ | |
4072 if (showChevron && chevronRect.contains(x, y)) return DWT.getMessage("SWT_ShowList"); //$NON-NLS-1$ | |
4073 CTabItem item = getItem(new Point (x, y)); | |
4074 if (item is null) return null; | |
4075 if (!item.showing) return null; | |
4076 if ((showClose || item.showClose) && item.closeRect.contains(x, y)) { | |
4077 return DWT.getMessage("SWT_Close"); //$NON-NLS-1$ | |
4078 } | |
4079 return item.getToolTipText(); | |
4080 } | |
4081 } |