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