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