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