]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/widgets/Item.java
Remove invalid SHA-256-Digests
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / widgets / Item.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 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.widgets;
15
16
17 import org.eclipse.swt.*;
18 import org.eclipse.swt.graphics.*;
19 import org.eclipse.swt.internal.*;
20
21 /**
22  * This class is the abstract superclass of all non-windowed
23  * user interface objects that occur within specific controls.
24  * For example, a tree will contain tree items.
25  * <dl>
26  * <dt><b>Styles:</b></dt>
27  * <dd>(none)</dd>
28  * <dt><b>Events:</b></dt>
29  * <dd>(none)</dd>
30  * </dl>
31  *
32  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
33  */
34
35 public abstract class Item extends Widget {
36         String text;
37         Image image;
38         /**
39          * Maximum number of characters Windows can reliably display in one line.
40          * Mac and Linux can display more but we are limited by windows here.
41          */
42         static final int TEXT_LIMIT = 8192;
43
44         static final String ELLIPSIS = "...";
45
46
47
48 /**
49  * Constructs a new instance of this class given its parent
50  * and a style value describing its behavior and appearance.
51  * The item is added to the end of the items maintained by its parent.
52  * <p>
53  * The style value is either one of the style constants defined in
54  * class <code>SWT</code> which is applicable to instances of this
55  * class, or must be built by <em>bitwise OR</em>'ing together
56  * (that is, using the <code>int</code> "|" operator) two or more
57  * of those <code>SWT</code> style constants. The class description
58  * lists the style constants that are applicable to the class.
59  * Style bits are also inherited from superclasses.
60  * </p>
61  *
62  * @param parent a widget which will be the parent of the new instance (cannot be null)
63  * @param style the style of item to construct
64  *
65  * @exception IllegalArgumentException <ul>
66  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
67  * </ul>
68  * @exception SWTException <ul>
69  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
70  * </ul>
71  *
72  * @see SWT
73  * @see Widget#getStyle
74  */
75 public Item (Widget parent, int style) {
76         super (parent, style);
77         text = "";
78 }
79
80 /**
81  * Constructs a new instance of this class given its parent
82  * and a style value describing its behavior and appearance,
83  * and the index at which to place it in the items maintained
84  * by its parent.
85  * <p>
86  * The style value is either one of the style constants defined in
87  * class <code>SWT</code> which is applicable to instances of this
88  * class, or must be built by <em>bitwise OR</em>'ing together
89  * (that is, using the <code>int</code> "|" operator) two or more
90  * of those <code>SWT</code> style constants. The class description
91  * lists the style constants that are applicable to the class.
92  * Style bits are also inherited from superclasses.
93  * </p>
94  *
95  * @param parent a widget which will be the parent of the new instance (cannot be null)
96  * @param style the style of item to construct
97  * @param index the zero-relative index at which to store the receiver in its parent
98  *
99  * @exception IllegalArgumentException <ul>
100  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
101  *    <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
102  * </ul>
103  * @exception SWTException <ul>
104  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
105  * </ul>
106  *
107  * @see SWT
108  * @see Widget#getStyle
109  */
110 public Item (Widget parent, int style, int index) {
111         this (parent, style);
112 }
113
114 @Override
115 protected void checkSubclass () {
116         /* Do Nothing - Subclassing is allowed */
117 }
118
119 /**
120  * Returns the receiver's image if it has one, or null
121  * if it does not.
122  *
123  * @return the receiver's image
124  *
125  * @exception SWTException <ul>
126  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
127  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
128  * </ul>
129  */
130 public Image getImage () {
131         checkWidget ();
132         return image;
133 }
134
135 @Override
136 String getNameText () {
137         return getText ();
138 }
139
140 /**
141  * Returns the receiver's text, which will be an empty
142  * string if it has never been set.
143  *
144  * @return the receiver's text
145  *
146  * @exception SWTException <ul>
147  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
148  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
149  * </ul>
150  */
151 public String getText () {
152         checkWidget();
153         return text;
154 }
155
156 @Override
157 void releaseWidget () {
158         super.releaseWidget ();
159         text = null;
160         image = null;
161 }
162
163 /**
164  * Sets the receiver's image to the argument, which may be
165  * null indicating that no image should be displayed.
166  *
167  * @param image the image to display on the receiver (may be null)
168  *
169  * @exception IllegalArgumentException <ul>
170  *    <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
171  * </ul>
172  * @exception SWTException <ul>
173  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
174  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
175  * </ul>
176  */
177 public void setImage (Image image) {
178         checkWidget ();
179         if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
180         this.image = image;
181 }
182
183 /**
184  * Sets the receiver's text.
185  * <p>
186  * Note: If control characters like '\n', '\t' etc. are used
187  * in the string, then the behavior is platform dependent.
188  * </p>
189  * @param string the new text
190  *
191  * @exception IllegalArgumentException <ul>
192  *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>
193  * </ul>
194  * @exception SWTException <ul>
195  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
196  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
197  * </ul>
198  */
199 public void setText (String string) {
200         checkWidget ();
201         if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
202         text = string;
203         if ((state & HAS_AUTO_DIRECTION) != 0) {
204                 updateTextDirection (AUTO_TEXT_DIRECTION);
205         }
206 }
207
208 boolean updateTextDirection(int textDirection) {
209         /*
210          * textDirection argument passed here is either (1) AUTO_TEXT_DIRECTION, or
211          * (2) 0 (i.e. match orientation) or FLIP_TEXT_DIRECTION (mismatch orientation).
212          */
213         if (textDirection == AUTO_TEXT_DIRECTION) {
214                 state |= HAS_AUTO_DIRECTION;
215                 textDirection = (style ^ BidiUtil.resolveTextDirection (text)) == 0 ? 0 : SWT.FLIP_TEXT_DIRECTION;
216         } else {
217                 state &= ~HAS_AUTO_DIRECTION;
218         }
219         if (((style & SWT.FLIP_TEXT_DIRECTION) ^ textDirection) != 0) {
220                 style ^= SWT.FLIP_TEXT_DIRECTION;
221                 return true;
222         }
223         return textDirection == AUTO_TEXT_DIRECTION;
224 }
225
226 }