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