]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/custom/CTabItem.java
Remove invalid SHA-256-Digests
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / custom / CTabItem.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2012 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.custom;
15
16
17 import org.eclipse.swt.*;
18 import org.eclipse.swt.graphics.*;
19 import org.eclipse.swt.widgets.*;
20
21 /**
22  * Instances of this class represent a selectable user interface object
23  * that represent a page in a notebook widget.
24  *
25  * <dl>
26  * <dt><b>Styles:</b></dt>
27  * <dd>SWT.CLOSE</dd>
28  * <dt><b>Events:</b></dt>
29  * <dd>(none)</dd>
30  * </dl>
31  * <p>
32  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
33  * </p>
34  *
35  * @see <a href="http://www.eclipse.org/swt/snippets/#ctabfolder">CTabFolder, CTabItem snippets</a>
36  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
37  * @noextend This class is not intended to be subclassed by clients.
38  */
39 public class CTabItem extends Item {
40         CTabFolder parent;
41         int x,y,width,height = 0;
42         Control control; // the tab page
43
44         String toolTipText;
45         String shortenedText;
46         int shortenedTextWidth;
47
48         // Appearance
49         Font font;
50         Image disabledImage;
51
52         Rectangle closeRect = new Rectangle(0, 0, 0, 0);
53         int closeImageState = SWT.BACKGROUND;
54         int state = SWT.NONE;
55         boolean showClose = false;
56         boolean showing = false;
57
58 /**
59  * Constructs a new instance of this class given its parent
60  * (which must be a <code>CTabFolder</code>) and a style value
61  * describing its behavior and appearance. The item is added
62  * to the end of the items maintained by its parent.
63  * <p>
64  * The style value is either one of the style constants defined in
65  * class <code>SWT</code> which is applicable to instances of this
66  * class, or must be built by <em>bitwise OR</em>'ing together
67  * (that is, using the <code>int</code> "|" operator) two or more
68  * of those <code>SWT</code> style constants. The class description
69  * lists the style constants that are applicable to the class.
70  * Style bits are also inherited from superclasses.
71  * </p>
72  *
73  * @param parent a CTabFolder which will be the parent of the new instance (cannot be null)
74  * @param style the style of control to construct
75  *
76  * @exception IllegalArgumentException <ul>
77  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
78  * </ul>
79  * @exception SWTException <ul>
80  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
81  * </ul>
82  *
83  * @see SWT
84  * @see Widget#getStyle()
85  */
86 public CTabItem (CTabFolder parent, int style) {
87         this(parent, style, parent.getItemCount());
88 }
89 /**
90  * Constructs a new instance of this class given its parent
91  * (which must be a <code>CTabFolder</code>), a style value
92  * describing its behavior and appearance, and the index
93  * at which to place it in the items maintained by its parent.
94  * <p>
95  * The style value is either one of the style constants defined in
96  * class <code>SWT</code> which is applicable to instances of this
97  * class, or must be built by <em>bitwise OR</em>'ing together
98  * (that is, using the <code>int</code> "|" operator) two or more
99  * of those <code>SWT</code> style constants. The class description
100  * lists the style constants that are applicable to the class.
101  * Style bits are also inherited from superclasses.
102  * </p>
103  *
104  * @param parent a CTabFolder which will be the parent of the new instance (cannot be null)
105  * @param style the style of control to construct
106  * @param index the zero-relative index to store the receiver in its parent
107  *
108  * @exception IllegalArgumentException <ul>
109  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
110  *    <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
111  * </ul>
112  * @exception SWTException <ul>
113  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
114  * </ul>
115  *
116  * @see SWT
117  * @see Widget#getStyle()
118  */
119 public CTabItem (CTabFolder parent, int style, int index) {
120         super (parent, style);
121         showClose = (style & SWT.CLOSE) != 0;
122         parent.createItem (this, index);
123 }
124
125
126 @Override
127 public void dispose() {
128         if (isDisposed ()) return;
129         //if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
130         parent.destroyItem(this);
131         super.dispose();
132         parent = null;
133         control = null;
134         toolTipText = null;
135         shortenedText = null;
136         font = null;
137 }
138
139 /**
140  * Returns a rectangle describing the receiver's size and location
141  * relative to its parent.
142  *
143  * @return the receiver's bounding column rectangle
144  *
145  * @exception SWTException <ul>
146  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
147  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
148  * </ul>
149  */
150 public Rectangle getBounds () {
151         /*
152          * This call is intentionally commented out, to allow this getter method to be
153          * called from a thread which is different from one that created the widget.
154          */
155         //checkWidget();
156         parent.runUpdate();
157         return new Rectangle(x, y, width, height);
158 }
159 /**
160 * Gets the control that is displayed in the content area of the tab item.
161 *
162 * @return the control
163 *
164 * @exception SWTException <ul>
165 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
166 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
167 * </ul>
168 */
169 public Control getControl () {
170         checkWidget();
171         return control;
172 }
173 /**
174  * Get the image displayed in the tab if the tab is disabled.
175  *
176  * @return the disabled image or null
177  *
178  * @exception SWTException <ul>
179  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
180  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
181  * </ul>
182  *
183  * @deprecated the disabled image is not used
184  */
185 @Deprecated
186 public Image getDisabledImage(){
187         checkWidget();
188         return disabledImage;
189 }
190 /**
191  * Returns the font that the receiver will use to paint textual information.
192  *
193  * @return the receiver's font
194  *
195  * @exception SWTException <ul>
196  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
197  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
198  * </ul>
199  *
200  *  @since 3.0
201  */
202 public Font getFont() {
203         checkWidget();
204         if (font != null) return font;
205         return parent.getFont();
206 }
207 /**
208  * Returns the receiver's parent, which must be a <code>CTabFolder</code>.
209  *
210  * @return the receiver's parent
211  *
212  * @exception SWTException <ul>
213  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
214  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
215  * </ul>
216  */
217 public CTabFolder getParent () {
218         /*
219          * This call is intentionally commented out, to allow this getter method to be
220          * called from a thread which is different from one that created the widget.
221          */
222         //checkWidget();
223         return parent;
224 }
225 /**
226  * Returns <code>true</code> to indicate that the receiver's close button should be shown.
227  * Otherwise return <code>false</code>. The initial value is defined by the style (SWT.CLOSE)
228  * that was used to create the receiver.
229  *
230  * @return <code>true</code> if the close button should be shown
231  *
232  * @exception SWTException <ul>
233  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
234  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
235  * </ul>
236  *
237  * @since 3.4
238  */
239 public boolean getShowClose() {
240         checkWidget();
241         return showClose;
242 }
243 /**
244  * Returns the receiver's tool tip text, or null if it has
245  * not been set.
246  *
247  * @return the receiver's tool tip text
248  *
249  * @exception SWTException <ul>
250  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
251  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
252  * </ul>
253  */
254 public String getToolTipText () {
255         checkWidget();
256         if (toolTipText == null && shortenedText != null) {
257                 String text = getText();
258                 if (!shortenedText.equals(text)) return text;
259         }
260         return toolTipText;
261 }
262 /**
263 * Returns <code>true</code> if the item will be rendered in the visible area of the CTabFolder. Returns false otherwise.
264 *
265 *  @return <code>true</code> if the item will be rendered in the visible area of the CTabFolder. Returns false otherwise.
266 *
267 *  @exception SWTException <ul>
268  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
269  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
270  * </ul>
271  *
272 * @since 3.0
273 */
274 public boolean isShowing () {
275         checkWidget();
276         return showing;
277 }
278
279 /**
280  * Sets the control that is used to fill the client area of
281  * the tab folder when the user selects the tab item.
282  *
283  * @param control the new control (or null)
284  *
285  * @exception IllegalArgumentException <ul>
286  *    <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
287  *    <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
288  * </ul>
289  * @exception SWTException <ul>
290  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
291  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
292  * </ul>
293  */
294 public void setControl (Control control) {
295         checkWidget();
296         if (control != null) {
297                 if (control.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
298                 if (control.getParent() != parent) SWT.error (SWT.ERROR_INVALID_PARENT);
299         }
300         if (this.control != null && !this.control.isDisposed()) {
301                 this.control.setVisible(false);
302         }
303         this.control = control;
304         if (this.control != null) {
305                 int index = parent.indexOf (this);
306                 if (index == parent.getSelectionIndex ()){
307                         this.control.setBounds(parent.getClientArea ());
308                         this.control.setVisible(true);
309                 } else {
310                         int selectedIndex = parent.getSelectionIndex();
311                         Control selectedControl = null;
312                         if (selectedIndex != -1) {
313                                 selectedControl = parent.getItem(selectedIndex).control;
314                         }
315                         if (this.control != selectedControl) {
316                                 this.control.setVisible(false);
317                         }
318                 }
319         }
320 }
321 /**
322  * Sets the image that is displayed if the tab item is disabled.
323  * Null will clear the image.
324  *
325  * @param image the image to be displayed when the item is disabled or null
326  *
327  * @exception SWTException <ul>
328  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
329  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
330  * </ul>
331  *
332  * @deprecated This image is not used
333  */
334 @Deprecated
335 public void setDisabledImage (Image image) {
336         checkWidget();
337         if (image != null && image.isDisposed ()) {
338                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
339         }
340         this.disabledImage = image;
341 }
342 boolean setFocus () {
343         return control != null && !control.isDisposed() && control.setFocus ();
344 }
345 /**
346  * Sets the font that the receiver will use to paint textual information
347  * for this item to the font specified by the argument, or to the default font
348  * for that kind of control if the argument is null.
349  *
350  * @param font the new font (or null)
351  *
352  * @exception IllegalArgumentException <ul>
353  *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
354  * </ul>
355  * @exception SWTException <ul>
356  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
357  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
358  * </ul>
359  *
360  * @since 3.0
361  */
362 public void setFont (Font font){
363         checkWidget();
364         if (font != null && font.isDisposed ()) {
365                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
366         }
367         if (font == null && this.font == null) return;
368         if (font != null && font.equals(this.font)) return;
369         this.font = font;
370         parent.updateFolder(CTabFolder.UPDATE_TAB_HEIGHT | CTabFolder.REDRAW_TABS);
371 }
372 @Override
373 public void setImage (Image image) {
374         checkWidget();
375         if (image != null && image.isDisposed ()) {
376                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
377         }
378         Image oldImage = getImage();
379         if (image == null && oldImage == null) return;
380         if (image != null && image.equals(oldImage)) return;
381         super.setImage(image);
382         parent.updateFolder(CTabFolder.UPDATE_TAB_HEIGHT | CTabFolder.REDRAW_TABS);
383 }
384 /**
385  * Sets to <code>true</code> to indicate that the receiver's close button should be shown.
386  * If the parent (CTabFolder) was created with SWT.CLOSE style, changing this value has
387  * no effect.
388  *
389  * @param close the new state of the close button
390  *
391  * @exception SWTException <ul>
392  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
393  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
394  * </ul>
395  *
396  * @since 3.4
397  */
398 public void setShowClose(boolean close) {
399         checkWidget();
400         if (showClose == close) return;
401         showClose = close;
402         parent.updateFolder(CTabFolder.REDRAW_TABS);
403 }
404 /**
405  * Sets the text to display on the tab.
406  * A carriage return '\n' allows to display multi line text.
407  *
408  * @param string the tab name
409  *
410  * @exception SWTException <ul>
411  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
412  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
413  * </ul>
414  */
415 @Override
416 public void setText (String string) {
417         checkWidget();
418         if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
419         if (string.equals(getText())) return;
420         super.setText(string);
421         shortenedText = null;
422         shortenedTextWidth = 0;
423         parent.updateFolder(CTabFolder.UPDATE_TAB_HEIGHT | CTabFolder.REDRAW_TABS);
424 }
425 /**
426  * Sets the receiver's tool tip text to the argument, which
427  * may be null indicating that the default tool tip for the
428  * control will be shown. For a control that has a default
429  * tool tip, such as the Tree control on Windows, setting
430  * the tool tip text to an empty string replaces the default,
431  * causing no tool tip text to be shown.
432  * <p>
433  * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
434  * To display a single '&amp;' in the tool tip, the character '&amp;' can be
435  * escaped by doubling it in the string.
436  * </p>
437  *
438  * @param string the new tool tip text (or null)
439  *
440  * @exception SWTException <ul>
441  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
442  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
443  * </ul>
444  */
445 public void setToolTipText (String string) {
446         checkWidget();
447         toolTipText = string;
448 }
449
450 }