1 |
/******************************************************************************* |
= |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
|
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
|
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
|
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
|
7 |
* |
8 |
* Contributors: |
|
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
|
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
|
10 |
*******************************************************************************/ |
|
|
<> |
11 |
|
|
|
|
12 |
/******************************************************************************* |
|
|
|
13 |
* Additions/modifications to this source file by Oracle America, Inc. 2011 |
|
|
|
14 |
*******************************************************************************/ |
|
|
|
15 |
|
11 |
package org.eclipse.swt.widgets; |
= |
16 |
package org.eclipse.swt.widgets; |
12 |
|
|
17 |
|
13 |
|
|
18 |
|
14 |
import org.eclipse.swt.*; |
|
19 |
import org.eclipse.swt.*; |
15 |
import org.eclipse.swt.graphics.*; |
|
20 |
import org.eclipse.swt.graphics.*; |
16 |
|
|
21 |
|
17 |
import com.ibm.ugl.eswt.OS; |
|
22 |
import com.ibm.ugl.eswt.OS; |
18 |
|
|
23 |
|
19 |
/** |
|
24 |
/** |
20 |
* Instances of this class are controls which are capable |
|
25 |
* Instances of this class are controls which are capable |
21 |
* of containing other controls. |
|
26 |
* of containing other controls. |
22 |
* <dl> |
|
27 |
* <dl> |
23 |
* <dt><b>Styles:</b></dt> |
|
28 |
* <dt><b>Styles:</b></dt> |
24 |
* <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP</dd> |
|
29 |
* <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP</dd> |
25 |
* <dt><b>Events:</b></dt> |
|
30 |
* <dt><b>Events:</b></dt> |
26 |
* <dd>(none)</dd> |
|
31 |
* <dd>(none)</dd> |
27 |
* </dl> |
|
32 |
* </dl> |
28 |
* <p> |
|
33 |
* <p> |
29 |
* Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>, |
|
34 |
* Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>, |
30 |
* and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>. |
|
35 |
* and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>. |
31 |
* They can be used with <code>Composite</code> if you are drawing your own, but their |
|
36 |
* They can be used with <code>Composite</code> if you are drawing your own, but their |
32 |
* behavior is undefined if they are used with subclasses of <code>Composite</code> other |
|
37 |
* behavior is undefined if they are used with subclasses of <code>Composite</code> other |
33 |
* than <code>Canvas</code>. |
|
38 |
* than <code>Canvas</code>. |
34 |
* </p><p> |
|
39 |
* </p><p> |
35 |
* This class may be subclassed by custom control implementors |
|
40 |
* This class may be subclassed by custom control implementors |
36 |
* who are building controls that are constructed from aggregates |
|
41 |
* who are building controls that are constructed from aggregates |
37 |
* of other controls. |
|
42 |
* of other controls. |
38 |
* </p> |
|
43 |
* </p> |
39 |
* |
|
44 |
* |
40 |
* @see Canvas |
|
45 |
* @see Canvas |
41 |
*/ |
|
46 |
*/ |
42 |
public class Composite extends Scrollable { |
|
47 |
public class Composite extends Scrollable { |
43 |
Layout layout; |
|
48 |
Layout layout; |
44 |
Control[] tabList; |
|
49 |
Control[] tabList; |
45 |
Control[] children; |
|
50 |
Control[] children; |
46 |
int childCount; |
|
51 |
int childCount; |
47 |
|
|
52 |
|
48 |
Composite () { |
|
53 |
Composite () { |
49 |
/* Do nothing */ |
|
54 |
/* Do nothing */ |
50 |
} |
|
55 |
} |
51 |
/** |
|
56 |
/** |
52 |
* Constructs a new instance of this class given its parent |
|
57 |
* Constructs a new instance of this class given its parent |
53 |
* and a style value describing its behavior and appearance. |
|
58 |
* and a style value describing its behavior and appearance. |
54 |
* <p> |
|
59 |
* <p> |
55 |
* The style value is either one of the style constants defined in |
|
60 |
* The style value is either one of the style constants defined in |
56 |
* class <code>SWT</code> which is applicable to instances of this |
|
61 |
* class <code>SWT</code> which is applicable to instances of this |
57 |
* class, or must be built by <em>bitwise OR</em>'ing together |
|
62 |
* class, or must be built by <em>bitwise OR</em>'ing together |
58 |
* (that is, using the <code>int</code> "|" operator) two or more |
|
63 |
* (that is, using the <code>int</code> "|" operator) two or more |
59 |
* of those <code>SWT</code> style constants. The class description |
|
64 |
* of those <code>SWT</code> style constants. The class description |
60 |
* lists the style constants that are applicable to the class. |
|
65 |
* lists the style constants that are applicable to the class. |
61 |
* Style bits are also inherited from superclasses. |
|
66 |
* Style bits are also inherited from superclasses. |
62 |
* </p> |
|
67 |
* </p> |
63 |
* |
|
68 |
* |
64 |
* @param parent a widget which will be the parent of the new instance (cannot be null) |
|
69 |
* @param parent a widget which will be the parent of the new instance (cannot be null) |
65 |
* @param style the style of widget to construct |
|
70 |
* @param style the style of widget to construct |
66 |
* |
|
71 |
* |
67 |
* @exception IllegalArgumentException <ul> |
|
72 |
* @exception IllegalArgumentException <ul> |
68 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
|
73 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
69 |
* </ul> |
|
74 |
* </ul> |
70 |
* @exception SWTException <ul> |
|
75 |
* @exception SWTException <ul> |
71 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
|
76 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
72 |
* </ul> |
|
77 |
* </ul> |
73 |
* |
|
78 |
* |
74 |
* @see SWT#NO_BACKGROUND |
|
79 |
* @see SWT#NO_BACKGROUND |
75 |
* @see SWT#NO_FOCUS |
|
80 |
* @see SWT#NO_FOCUS |
76 |
* @see SWT#NO_MERGE_PAINTS |
|
81 |
* @see SWT#NO_MERGE_PAINTS |
77 |
* @see SWT#NO_REDRAW_RESIZE |
|
82 |
* @see SWT#NO_REDRAW_RESIZE |
78 |
* @see SWT#NO_RADIO_GROUP |
|
83 |
* @see SWT#NO_RADIO_GROUP |
79 |
* @see Widget#getStyle |
|
84 |
* @see Widget#getStyle |
80 |
*/ |
|
85 |
*/ |
81 |
public Composite(Composite parent, int style) { |
|
86 |
public Composite(Composite parent, int style) { |
82 |
super(parent, style); |
<> |
87 |
super(parent, style); |
|
|
|
88 |
if (!(this instanceof Combo)) |
|
|
|
89 |
this.internal_style |= SWT.NO_FOCUS; |
83 |
} |
= |
90 |
} |
84 |
|
|
91 |
|
85 |
Control[] _getTabList () { |
|
92 |
Control[] _getTabList () { |
86 |
if (tabList == null) return tabList; |
|
93 |
if (tabList == null) return tabList; |
87 |
int index = 0, count = 0; |
|
94 |
int index = 0, count = 0; |
88 |
while (index < tabList.length) { |
|
95 |
while (index < tabList.length) { |
89 |
if (!tabList[index].isDisposed()) count++; |
|
96 |
if (!tabList[index].isDisposed()) count++; |
90 |
index++; |
|
97 |
index++; |
91 |
} |
|
98 |
} |
92 |
if (index == count) return tabList; |
|
99 |
if (index == count) return tabList; |
93 |
Control[] newList = new Control[count]; |
|
100 |
Control[] newList = new Control[count]; |
94 |
index = 0; |
|
101 |
index = 0; |
95 |
for (int i = 0; i < tabList.length; i++) { |
|
102 |
for (int i = 0; i < tabList.length; i++) { |
96 |
if (!tabList[index].isDisposed()) { |
|
103 |
if (!tabList[index].isDisposed()) { |
97 |
newList[index++] = tabList[i]; |
|
104 |
newList[index++] = tabList[i]; |
98 |
} |
|
105 |
} |
99 |
} |
|
106 |
} |
100 |
tabList = newList; |
|
107 |
tabList = newList; |
101 |
return tabList; |
|
108 |
return tabList; |
102 |
} |
|
109 |
} |
103 |
protected void checkSubclass() { |
|
110 |
protected void checkSubclass() { |
104 |
/* Do nothing - Subclassing is allowed */ |
|
111 |
/* Do nothing - Subclassing is allowed */ |
105 |
} |
|
112 |
} |
106 |
|
|
113 |
|
107 |
// This method was made public so that the mobile extension |
|
114 |
// This method was made public so that the mobile extension |
108 |
// group can use it. |
|
115 |
// group can use it. |
109 |
public void internal_removeChild(Control child) { |
|
116 |
public void internal_removeChild(Control child) { |
110 |
if (child == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
|
117 |
if (child == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
111 |
if (children == null) return; |
|
118 |
if (children == null) return; |
112 |
|
|
119 |
|
113 |
for (int i=0;i<childCount;i++) { |
|
120 |
for (int i=0;i<childCount;i++) { |
114 |
if (children[i].equals(child)) { |
|
121 |
if (children[i].equals(child)) { |
115 |
System.arraycopy(children, i+1, children, i, childCount-i-1); |
|
122 |
System.arraycopy(children, i+1, children, i, childCount-i-1); |
116 |
// free the last control which is no longer accessible |
|
123 |
// free the last control which is no longer accessible |
117 |
children[childCount - 1] = null; |
|
124 |
children[childCount - 1] = null; |
118 |
childCount--; |
|
125 |
childCount--; |
119 |
} |
|
126 |
} |
120 |
} |
|
127 |
} |
121 |
} |
|
128 |
} |
122 |
|
|
129 |
|
123 |
void addChild(Control child) { |
|
130 |
void addChild(Control child) { |
124 |
if (child == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
|
131 |
if (child == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
125 |
|
|
132 |
|
126 |
// Create the default array if this is the first child |
|
133 |
// Create the default array if this is the first child |
127 |
if (children == null) { |
|
134 |
if (children == null) { |
128 |
children = new Control[5]; |
|
135 |
children = new Control[5]; |
129 |
childCount = 0; |
|
136 |
childCount = 0; |
130 |
} |
|
137 |
} |
131 |
|
|
138 |
|
132 |
// Grow the child array if more space is needed |
|
139 |
// Grow the child array if more space is needed |
133 |
if (childCount == children.length) { |
|
140 |
if (childCount == children.length) { |
134 |
Control[] newChildren = new Control[childCount * 2]; |
|
141 |
Control[] newChildren = new Control[childCount * 2]; |
135 |
System.arraycopy(children, 0, newChildren, 0, childCount); |
|
142 |
System.arraycopy(children, 0, newChildren, 0, childCount); |
136 |
children = newChildren; |
|
143 |
children = newChildren; |
137 |
} |
|
144 |
} |
138 |
|
|
145 |
|
139 |
children[childCount++] = child; |
|
146 |
children[childCount++] = child; |
140 |
} |
|
147 |
} |
141 |
|
|
148 |
|
142 |
|
|
149 |
|
143 |
public Point computeSize(int wHint, int hHint, boolean changed) { |
|
150 |
public Point computeSize(int wHint, int hHint, boolean changed) { |
144 |
checkWidget(); |
|
151 |
checkWidget(); |
145 |
Point size; |
|
152 |
Point size; |
146 |
if (layout != null) { |
|
153 |
if (layout != null) { |
147 |
if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { |
|
154 |
if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { |
148 |
size = layout.computeSize(this, wHint, hHint, changed); |
|
155 |
size = layout.computeSize(this, wHint, hHint, changed); |
149 |
} else { |
|
156 |
} else { |
150 |
size = new Point(wHint, hHint); |
|
157 |
size = new Point(wHint, hHint); |
151 |
} |
|
158 |
} |
152 |
} else { |
|
159 |
} else { |
153 |
size = minimumSize(); |
|
160 |
size = minimumSize(); |
154 |
} |
|
161 |
} |
155 |
if (size.x == 0) size.x = DEFAULT_WIDTH; |
|
162 |
if (size.x == 0) size.x = DEFAULT_WIDTH; |
156 |
if (size.y == 0) size.y = DEFAULT_HEIGHT; |
|
163 |
if (size.y == 0) size.y = DEFAULT_HEIGHT; |
157 |
if (wHint != SWT.DEFAULT) size.x = wHint; |
|
164 |
if (wHint != SWT.DEFAULT) size.x = wHint; |
158 |
if (hHint != SWT.DEFAULT) size.y = hHint; |
|
165 |
if (hHint != SWT.DEFAULT) size.y = hHint; |
159 |
Rectangle trim = computeTrim(0, 0, size.x, size.y); |
|
166 |
Rectangle trim = computeTrim(0, 0, size.x, size.y); |
160 |
return new Point(trim.width, trim.height); |
|
167 |
return new Point(trim.width, trim.height); |
161 |
} |
|
168 |
} |
162 |
Control[] computeTabList() { |
|
169 |
Control[] computeTabList() { |
163 |
Control result[] = super.computeTabList(); |
|
170 |
Control result[] = super.computeTabList(); |
164 |
if (result.length == 0) return result; |
|
171 |
if (result.length == 0) return result; |
165 |
|
|
172 |
|
166 |
int listCount; |
|
173 |
int listCount; |
167 |
Control[] list; |
|
174 |
Control[] list; |
168 |
|
|
175 |
|
169 |
if (tabList != null) { |
|
176 |
if (tabList != null) { |
170 |
list = _getTabList(); |
|
177 |
list = _getTabList(); |
171 |
listCount = list.length; |
|
178 |
listCount = list.length; |
172 |
} else { |
|
179 |
} else { |
173 |
list = children; |
|
180 |
list = children; |
174 |
listCount = childCount; |
|
181 |
listCount = childCount; |
175 |
} |
|
182 |
} |
176 |
for (int i = 0; i < listCount; i++) { |
|
183 |
for (int i = 0; i < listCount; i++) { |
177 |
Control child = list[i]; |
|
184 |
Control child = list[i]; |
178 |
Control[] childList = child.computeTabList(); |
|
185 |
Control[] childList = child.computeTabList(); |
179 |
int length = 0; |
|
186 |
int length = 0; |
180 |
for (int j = 0; j < childList.length; j++) { |
|
187 |
for (int j = 0; j < childList.length; j++) { |
181 |
if((childList[j].internal_style & SWT.NO_FOCUS) == 0) { |
|
188 |
if((childList[j].internal_style & SWT.NO_FOCUS) == 0) { |
182 |
length++; |
|
189 |
length++; |
183 |
} |
|
190 |
} |
184 |
} |
|
191 |
} |
185 |
if(length > 0) { |
|
192 |
if(length > 0) { |
186 |
Control[] newResult = new Control[result.length + length]; |
|
193 |
Control[] newResult = new Control[result.length + length]; |
187 |
System.arraycopy(result, 0, newResult, 0, result.length); |
|
194 |
System.arraycopy(result, 0, newResult, 0, result.length); |
188 |
for (int j=0, k=0; j<childList.length; j++) { |
|
195 |
for (int j=0, k=0; j<childList.length; j++) { |
189 |
if((childList[j].internal_style & SWT.NO_FOCUS) == 0) { |
|
196 |
if((childList[j].internal_style & SWT.NO_FOCUS) == 0) { |
190 |
System.arraycopy(childList, j, newResult, result.length + k, 1); |
|
197 |
System.arraycopy(childList, j, newResult, result.length + k, 1); |
191 |
k++; |
|
198 |
k++; |
192 |
} |
|
199 |
} |
193 |
} |
|
200 |
} |
194 |
result = newResult; |
|
201 |
result = newResult; |
195 |
} |
|
202 |
} |
196 |
} |
|
203 |
} |
197 |
return result; |
|
204 |
return result; |
198 |
} |
|
205 |
} |
199 |
protected void internal_createHandle(int index) { |
|
206 |
protected void internal_createHandle(int index) { |
200 |
internal_handle = OS.Composite_New(internal_parent.internal_handle, internal_getNativeStyle()); |
|
207 |
internal_handle = OS.Composite_New(internal_parent.internal_handle, internal_getNativeStyle()); |
201 |
} |
|
208 |
} |
202 |
|
|
209 |
|
203 |
protected int internal_getNativeStyle() { |
|
210 |
protected int internal_getNativeStyle() { |
204 |
int nativeStyle = super.internal_getNativeStyle(); |
|
211 |
int nativeStyle = super.internal_getNativeStyle(); |
205 |
|
|
212 |
|
206 |
if ((internal_style & SWT.NO_BACKGROUND) == SWT.NO_BACKGROUND) { |
|
213 |
if ((internal_style & SWT.NO_BACKGROUND) == SWT.NO_BACKGROUND) { |
207 |
nativeStyle |= OS.STYLE_NO_BACKGROUND; |
|
214 |
nativeStyle |= OS.STYLE_NO_BACKGROUND; |
208 |
} |
|
215 |
} |
209 |
if ((internal_style & SWT.NO_FOCUS) == SWT.NO_FOCUS) { |
|
216 |
if ((internal_style & SWT.NO_FOCUS) == SWT.NO_FOCUS) { |
210 |
nativeStyle |= OS.STYLE_NO_FOCUS; |
|
217 |
nativeStyle |= OS.STYLE_NO_FOCUS; |
211 |
} |
|
218 |
} |
212 |
if ((internal_style & SWT.NO_MERGE_PAINTS) == SWT.NO_MERGE_PAINTS) { |
|
219 |
if ((internal_style & SWT.NO_MERGE_PAINTS) == SWT.NO_MERGE_PAINTS) { |
213 |
nativeStyle |= OS.STYLE_NO_MERGE_PAINTS; |
|
220 |
nativeStyle |= OS.STYLE_NO_MERGE_PAINTS; |
214 |
} |
|
221 |
} |
215 |
if ((internal_style & SWT.NO_REDRAW_RESIZE) == SWT.NO_REDRAW_RESIZE) { |
|
222 |
if ((internal_style & SWT.NO_REDRAW_RESIZE) == SWT.NO_REDRAW_RESIZE) { |
216 |
nativeStyle |= OS.STYLE_NO_REDRAW_RESIZE; |
|
223 |
nativeStyle |= OS.STYLE_NO_REDRAW_RESIZE; |
217 |
} |
|
224 |
} |
218 |
return nativeStyle; |
|
225 |
return nativeStyle; |
219 |
} |
|
226 |
} |
220 |
/** |
|
227 |
/** |
221 |
* Returns a (possibly empty) array containing the receiver's children. |
|
228 |
* Returns a (possibly empty) array containing the receiver's children. |
222 |
* Children are returned in the order that they are drawn. |
|
229 |
* Children are returned in the order that they are drawn. |
223 |
* <p> |
|
230 |
* <p> |
224 |
* Note: This is not the actual structure used by the receiver |
|
231 |
* Note: This is not the actual structure used by the receiver |
225 |
* to maintain its list of children, so modifying the array will |
|
232 |
* to maintain its list of children, so modifying the array will |
226 |
* not affect the receiver. |
|
233 |
* not affect the receiver. |
227 |
* </p> |
|
234 |
* </p> |
228 |
* |
|
235 |
* |
229 |
* @return an array of children |
|
236 |
* @return an array of children |
230 |
* |
|
237 |
* |
231 |
* @see Control#moveAbove |
|
238 |
* @see Control#moveAbove |
232 |
* @see Control#moveBelow |
|
239 |
* @see Control#moveBelow |
233 |
* |
|
240 |
* |
234 |
* @exception SWTException <ul> |
|
241 |
* @exception SWTException <ul> |
235 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
242 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
236 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
243 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
237 |
* </ul> |
|
244 |
* </ul> |
238 |
*/ |
|
245 |
*/ |
239 |
public Control[] getChildren() { |
|
246 |
public Control[] getChildren() { |
240 |
checkWidget(); |
|
247 |
checkWidget(); |
241 |
Control[] childrenCopy = new Control[childCount]; |
|
248 |
Control[] childrenCopy = new Control[childCount]; |
242 |
if (childCount > 0) { |
|
249 |
if (childCount > 0) { |
243 |
System.arraycopy(children, 0, childrenCopy, 0, childCount); |
|
250 |
System.arraycopy(children, 0, childrenCopy, 0, childCount); |
244 |
} |
|
251 |
} |
245 |
return childrenCopy; |
|
252 |
return childrenCopy; |
246 |
} |
|
253 |
} |
247 |
/** |
|
254 |
/** |
248 |
* Returns layout which is associated with the receiver, or |
|
255 |
* Returns layout which is associated with the receiver, or |
249 |
* null if one has not been set. |
|
256 |
* null if one has not been set. |
250 |
* |
|
257 |
* |
251 |
* @return the receiver's layout or null |
|
258 |
* @return the receiver's layout or null |
252 |
* |
|
259 |
* |
253 |
* @exception SWTException <ul> |
|
260 |
* @exception SWTException <ul> |
254 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
261 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
255 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
262 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
256 |
* </ul> |
|
263 |
* </ul> |
257 |
*/ |
|
264 |
*/ |
258 |
public Layout getLayout() { |
|
265 |
public Layout getLayout() { |
259 |
checkWidget(); |
|
266 |
checkWidget(); |
260 |
return layout; |
|
267 |
return layout; |
261 |
} |
|
268 |
} |
262 |
/** |
|
269 |
/** |
263 |
* Gets the (possibly empty) tabbing order for the control. |
|
270 |
* Gets the (possibly empty) tabbing order for the control. |
264 |
* |
|
271 |
* |
265 |
* @return tabList the ordered list of controls representing the tab order |
|
272 |
* @return tabList the ordered list of controls representing the tab order |
266 |
* |
|
273 |
* |
267 |
* @exception SWTException <ul> |
|
274 |
* @exception SWTException <ul> |
268 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
275 |
* <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> |
|
276 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
270 |
* </ul> |
|
277 |
* </ul> |
271 |
* |
|
278 |
* |
272 |
* @see #setTabList |
|
279 |
* @see #setTabList |
273 |
*/ |
|
280 |
*/ |
274 |
public Control[] getTabList() { |
|
281 |
public Control[] getTabList() { |
275 |
checkWidget(); |
|
282 |
checkWidget(); |
276 |
Control[] tabList = _getTabList(); |
|
283 |
Control[] tabList = _getTabList(); |
277 |
if (tabList == null) { |
|
284 |
if (tabList == null) { |
278 |
int count = 0; |
|
285 |
int count = 0; |
279 |
|
|
286 |
|
280 |
for (int i = 0; i < childCount; i++) { |
|
287 |
for (int i = 0; i < childCount; i++) { |
281 |
if (children[i].isTabGroup()) count++; |
|
288 |
if (children[i].isTabGroup()) count++; |
282 |
} |
|
289 |
} |
283 |
tabList = new Control[count]; |
|
290 |
tabList = new Control[count]; |
284 |
int index = 0; |
|
291 |
int index = 0; |
285 |
for (int i = 0; i < childCount; i++) { |
|
292 |
for (int i = 0; i < childCount; i++) { |
286 |
if (children[i].isTabGroup()) { |
|
293 |
if (children[i].isTabGroup()) { |
287 |
tabList[index++] = children[i]; |
|
294 |
tabList[index++] = children[i]; |
288 |
} |
|
295 |
} |
289 |
} |
|
296 |
} |
290 |
} |
|
297 |
} |
291 |
return tabList; |
|
298 |
return tabList; |
292 |
} |
|
299 |
} |
293 |
boolean hooksKeys() { |
|
300 |
boolean hooksKeys() { |
294 |
return hooks(SWT.KeyDown) || hooks(SWT.KeyUp) || hooks(SWT.Traverse); |
|
301 |
return hooks(SWT.KeyDown) || hooks(SWT.KeyUp) || hooks(SWT.Traverse); |
295 |
} |
|
302 |
} |
296 |
/** |
|
303 |
/** |
297 |
* If the receiver has a layout, asks the layout to <em>lay out</em> |
|
304 |
* If the receiver has a layout, asks the layout to <em>lay out</em> |
298 |
* (that is, set the size and location of) the receiver's children. |
|
305 |
* (that is, set the size and location of) the receiver's children. |
299 |
* If the receiver does not have a layout, do nothing. |
|
306 |
* If the receiver does not have a layout, do nothing. |
300 |
* <p> |
|
307 |
* <p> |
301 |
* This is equivalent to calling <code>layout(true)</code>. |
|
308 |
* This is equivalent to calling <code>layout(true)</code>. |
302 |
* </p> |
|
309 |
* </p> |
303 |
* |
|
310 |
* |
304 |
* @exception SWTException <ul> |
|
311 |
* @exception SWTException <ul> |
305 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
312 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
306 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
313 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
307 |
* </ul> |
|
314 |
* </ul> |
308 |
*/ |
|
315 |
*/ |
309 |
public void layout() { |
|
316 |
public void layout() { |
310 |
checkWidget(); |
|
317 |
checkWidget(); |
311 |
layout(true); |
|
318 |
layout(true); |
312 |
} |
|
319 |
} |
313 |
/** |
|
320 |
/** |
314 |
* If the receiver has a layout, asks the layout to <em>lay out</em> |
|
321 |
* If the receiver has a layout, asks the layout to <em>lay out</em> |
315 |
* (that is, set the size and location of) the receiver's children. |
|
322 |
* (that is, set the size and location of) the receiver's children. |
316 |
* If the argument is <code>true</code> the layout must not rely |
|
323 |
* If the argument is <code>true</code> the layout must not rely |
317 |
* on any information it has cached about the immediate children. If it |
|
324 |
* on any information it has cached about the immediate children. If it |
318 |
* is <code>false</code> the layout may (potentially) optimize the |
|
325 |
* is <code>false</code> the layout may (potentially) optimize the |
319 |
* work it is doing by assuming that none of the receiver's |
|
326 |
* work it is doing by assuming that none of the receiver's |
320 |
* children has changed state since the last layout. |
|
327 |
* children has changed state since the last layout. |
321 |
* If the receiver does not have a layout, do nothing. |
|
328 |
* If the receiver does not have a layout, do nothing. |
322 |
* <p> |
|
329 |
* <p> |
323 |
* If a child is resized as a result of a call to layout, the |
|
330 |
* If a child is resized as a result of a call to layout, the |
324 |
* resize event will invoke the layout of the child. The layout |
|
331 |
* resize event will invoke the layout of the child. The layout |
325 |
* will cascade down through all child widgets in the receiver's widget |
|
332 |
* will cascade down through all child widgets in the receiver's widget |
326 |
* tree until a child is encountered that does not resize. Note that |
|
333 |
* tree until a child is encountered that does not resize. Note that |
327 |
* a layout due to a resize will not flush any cached information |
|
334 |
* a layout due to a resize will not flush any cached information |
328 |
* (same as <code>layout(false)</code>).</p> |
|
335 |
* (same as <code>layout(false)</code>).</p> |
329 |
* |
|
336 |
* |
330 |
* @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise |
|
337 |
* @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise |
331 |
* |
|
338 |
* |
332 |
* @exception SWTException <ul> |
|
339 |
* @exception SWTException <ul> |
333 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
340 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
334 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
341 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
335 |
* </ul> |
|
342 |
* </ul> |
336 |
*/ |
|
343 |
*/ |
337 |
public void layout(boolean changed) { |
|
344 |
public void layout(boolean changed) { |
338 |
checkWidget(); |
|
345 |
checkWidget(); |
339 |
if (layout == null) return; |
|
346 |
if (layout == null) return; |
340 |
if (childCount > 0) { |
|
347 |
if (childCount > 0) { |
341 |
layout.layout(this,changed); |
|
348 |
layout.layout(this,changed); |
342 |
} |
|
349 |
} |
343 |
} |
|
350 |
} |
344 |
Point minimumSize() { |
|
351 |
Point minimumSize() { |
345 |
int width = 0, height = 0; |
|
352 |
int width = 0, height = 0; |
346 |
for (int i = 0; i < childCount; i++) { |
|
353 |
for (int i = 0; i < childCount; i++) { |
347 |
Rectangle rect = children[i].getBounds(); |
|
354 |
Rectangle rect = children[i].getBounds(); |
348 |
width = Math.max(width, rect.x + rect.width); |
|
355 |
width = Math.max(width, rect.x + rect.width); |
349 |
height = Math.max(height, rect.y + rect.height); |
|
356 |
height = Math.max(height, rect.y + rect.height); |
350 |
} |
|
357 |
} |
351 |
return new Point(width, height); |
|
358 |
return new Point(width, height); |
352 |
} |
|
359 |
} |
353 |
void releaseWidget() { |
|
360 |
void releaseWidget() { |
354 |
// childCount will be modified as part of the |
|
361 |
// childCount will be modified as part of the |
355 |
// release, so it cannot be the iterator. |
|
362 |
// release, so it cannot be the iterator. |
356 |
int temp = childCount; |
|
363 |
int temp = childCount; |
357 |
for (int i = 0; i < temp; i++) { |
|
364 |
for (int i = 0; i < temp; i++) { |
358 |
// The children array will shrink as part of the release, so |
|
365 |
// The children array will shrink as part of the release, so |
359 |
// the safest thing to do is always remove the first one. |
|
366 |
// the safest thing to do is always remove the first one. |
360 |
Control child = children[0]; |
|
367 |
Control child = children[0]; |
361 |
if (!child.isDisposed()) { |
|
368 |
if (!child.isDisposed()) { |
362 |
child.releaseWidget(); |
|
369 |
child.releaseWidget(); |
363 |
child.releaseHandle(); |
|
370 |
child.releaseHandle(); |
364 |
} |
|
371 |
} |
365 |
} |
|
372 |
} |
366 |
layout = null; |
|
373 |
layout = null; |
367 |
super.releaseWidget(); |
|
374 |
super.releaseWidget(); |
368 |
} |
|
375 |
} |
369 |
public void setBounds(int x, int y, int width, int height) { |
|
376 |
public void setBounds(int x, int y, int width, int height) { |
370 |
super.setBounds(x, y, width, height); |
|
377 |
super.setBounds(x, y, width, height); |
371 |
// not needed because CContainerPeer adjusts scroll bars? |
|
378 |
// not needed because CContainerPeer adjusts scroll bars? |
372 |
// resizeClientArea(width, height); |
|
379 |
// resizeClientArea(width, height); |
373 |
if (layout != null) layout(false); |
|
380 |
if (layout != null) layout(false); |
374 |
} |
|
381 |
} |
375 |
/** |
|
382 |
/** |
376 |
* Sets the layout which is associated with the receiver to be |
|
383 |
* Sets the layout which is associated with the receiver to be |
377 |
* the argument which may be null. |
|
384 |
* the argument which may be null. |
378 |
* |
|
385 |
* |
379 |
* @param layout the receiver's new layout or null |
|
386 |
* @param layout the receiver's new layout or null |
380 |
* |
|
387 |
* |
381 |
* @exception SWTException <ul> |
|
388 |
* @exception SWTException <ul> |
382 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
389 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
383 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
390 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
384 |
* </ul> |
|
391 |
* </ul> |
385 |
*/ |
|
392 |
*/ |
386 |
public void setLayout(Layout layout) { |
|
393 |
public void setLayout(Layout layout) { |
387 |
checkWidget(); |
|
394 |
checkWidget(); |
388 |
this.layout = layout; |
|
395 |
this.layout = layout; |
389 |
} |
|
396 |
} |
390 |
public void setSize(int width, int height) { |
|
397 |
public void setSize(int width, int height) { |
391 |
super.setSize(width, height); |
|
398 |
super.setSize(width, height); |
392 |
// not needed because CContainerPeer adjusts scroll bars? |
|
399 |
// not needed because CContainerPeer adjusts scroll bars? |
393 |
// resizeClientArea(width, height); |
|
400 |
// resizeClientArea(width, height); |
394 |
if (layout != null) layout(false); |
|
401 |
if (layout != null) layout(false); |
395 |
} |
|
402 |
} |
396 |
/** |
|
403 |
/** |
397 |
* Sets the tabbing order for the specified controls to |
|
404 |
* Sets the tabbing order for the specified controls to |
398 |
* match the order that they occur in the argument list. |
|
405 |
* match the order that they occur in the argument list. |
399 |
* |
|
406 |
* |
400 |
* @param tabList the ordered list of controls representing the tab order or null |
|
407 |
* @param tabList the ordered list of controls representing the tab order or null |
401 |
* |
|
408 |
* |
402 |
* @exception IllegalArgumentException <ul> |
|
409 |
* @exception IllegalArgumentException <ul> |
403 |
* <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li> |
|
410 |
* <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li> |
404 |
* <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li> |
|
411 |
* <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li> |
405 |
* </ul> |
|
412 |
* </ul> |
406 |
* @exception SWTException <ul> |
|
413 |
* @exception SWTException <ul> |
407 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
414 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
408 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
415 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
409 |
* </ul> |
|
416 |
* </ul> |
410 |
*/ |
|
417 |
*/ |
411 |
public void setTabList(Control[] tabList) { |
|
418 |
public void setTabList(Control[] tabList) { |
412 |
checkWidget(); |
|
419 |
checkWidget(); |
413 |
if (tabList == null) error(SWT.ERROR_NULL_ARGUMENT); |
|
420 |
if (tabList == null) error(SWT.ERROR_NULL_ARGUMENT); |
414 |
for (int i=0; i<tabList.length; i++) { |
|
421 |
for (int i=0; i<tabList.length; i++) { |
415 |
Control control = tabList[i]; |
|
422 |
Control control = tabList[i]; |
416 |
if (control == null) error(SWT.ERROR_INVALID_ARGUMENT); |
|
423 |
if (control == null) error(SWT.ERROR_INVALID_ARGUMENT); |
417 |
if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); |
|
424 |
if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); |
418 |
if (control.internal_parent != this) error(SWT.ERROR_INVALID_PARENT); |
|
425 |
if (control.internal_parent != this) error(SWT.ERROR_INVALID_PARENT); |
419 |
} |
|
426 |
} |
420 |
this.tabList = tabList; |
|
427 |
this.tabList = tabList; |
421 |
} |
|
428 |
} |
422 |
boolean setTabGroupFocus() { |
|
429 |
boolean setTabGroupFocus() { |
423 |
if (isTabItem()) return setTabItemFocus(); |
|
430 |
if (isTabItem()) return setTabItemFocus(); |
424 |
if ((internal_style & SWT.NO_FOCUS) == 0) { |
|
431 |
if ((internal_style & SWT.NO_FOCUS) == 0) { |
425 |
// Combo is the only Composite in eSWT which is excepted |
|
432 |
// Combo is the only Composite in eSWT which is excepted |
426 |
// from the hooksKeys() call because it does not behave like |
|
433 |
// from the hooksKeys() call because it does not behave like |
427 |
// other Composites. |
|
434 |
// other Composites. |
428 |
boolean takeFocus = true; |
|
435 |
boolean takeFocus = true; |
429 |
if (isTrueComposite()) takeFocus = hooksKeys(); |
|
436 |
if (isTrueComposite()) takeFocus = hooksKeys(); |
430 |
if (takeFocus && setTabItemFocus()) return true; |
|
437 |
if (takeFocus && setTabItemFocus()) return true; |
431 |
} |
|
438 |
} |
432 |
for (int i=0; i<childCount; i++) { |
|
439 |
for (int i=0; i<childCount; i++) { |
433 |
Control child = children[i]; |
|
440 |
Control child = children[i]; |
434 |
if (child.isTabItem() && child.setTabItemFocus()) return true; |
|
441 |
if (child.isTabItem() && child.setTabItemFocus()) return true; |
435 |
} |
|
442 |
} |
436 |
return false; |
|
443 |
return false; |
437 |
} |
|
444 |
} |
438 |
boolean setTabItemFocus() { |
|
445 |
boolean setTabItemFocus() { |
439 |
if ((internal_style & SWT.NO_FOCUS) == 0) { |
|
446 |
if ((internal_style & SWT.NO_FOCUS) == 0) { |
440 |
// Combo is the only Composite in eSWT which is excepted |
|
447 |
// Combo is the only Composite in eSWT which is excepted |
441 |
// from the hooksKeys() call because it does not behave like |
|
448 |
// from the hooksKeys() call because it does not behave like |
442 |
// other Composites. |
|
449 |
// other Composites. |
443 |
boolean takeFocus = true; |
|
450 |
boolean takeFocus = true; |
444 |
if (isTrueComposite()) takeFocus = hooksKeys(); |
|
451 |
if (isTrueComposite()) takeFocus = hooksKeys(); |
445 |
if (takeFocus) { |
|
452 |
if (takeFocus) { |
446 |
if (!isShowing()) return false; |
|
453 |
if (!isShowing()) return false; |
447 |
if (forceFocus()) return true; |
|
454 |
if (forceFocus()) return true; |
448 |
} |
|
455 |
} |
449 |
} |
|
456 |
} |
450 |
return super.setTabItemFocus(); |
|
457 |
return super.setTabItemFocus(); |
451 |
} |
|
458 |
} |
452 |
int traversalCode() { |
|
459 |
int traversalCode() { |
453 |
if (isTrueComposite()) { |
|
460 |
if (isTrueComposite()) { |
454 |
// if ((internal_style & SWT.NO_FOCUS) != 0) return 0; |
|
461 |
// if ((internal_style & SWT.NO_FOCUS) != 0) return 0; |
455 |
if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) return 0; |
|
462 |
if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) return 0; |
456 |
} |
|
463 |
} |
457 |
return super.traversalCode(); |
|
464 |
return super.traversalCode(); |
458 |
} |
|
465 |
} |
459 |
|
|
466 |
|
460 |
/* |
|
467 |
/* |
461 |
* See Combo. |
|
468 |
* See Combo. |
462 |
*/ |
|
469 |
*/ |
463 |
boolean isTrueComposite() { |
|
470 |
boolean isTrueComposite() { |
464 |
return true; |
|
471 |
return true; |
465 |
} |
|
472 |
} |
466 |
|
|
473 |
|
467 |
/* (non-Javadoc) |
|
474 |
/* (non-Javadoc) |
468 |
* @see org.eclipse.swt.widgets.Control#setFocus() |
|
475 |
* @see org.eclipse.swt.widgets.Control#setFocus() |
469 |
*/ |
|
476 |
*/ |
470 |
public boolean setFocus() { |
|
477 |
public boolean setFocus() { |
471 |
checkWidget(); |
|
478 |
checkWidget(); |
472 |
if (children != null) { |
|
479 |
if (children != null) { |
473 |
for (int i=0; i<childCount; i++) { |
|
480 |
for (int i=0; i<childCount; i++) { |
474 |
Control child = children[i]; |
|
481 |
Control child = children[i]; |
475 |
if (child.getVisible() && child.setFocus()) return true; |
|
482 |
if (child.getVisible() && child.setFocus()) return true; |
476 |
} |
|
483 |
} |
477 |
} |
|
484 |
} |
478 |
return super.setFocus(); |
|
485 |
return super.setFocus(); |
479 |
} |
|
486 |
} |
480 |
|
|
487 |
|
481 |
void clientAreaResized() { |
|
488 |
void clientAreaResized() { |
482 |
layout(); |
|
489 |
layout(); |
483 |
} |
|
490 |
} |
484 |
|
|
491 |
|
485 |
public boolean allowTraverseByArrowKey(Event event) { |
|
492 |
public boolean allowTraverseByArrowKey(Event event) { |
486 |
switch (event.keyCode) { |
|
493 |
switch (event.keyCode) { |
487 |
case SWT.ARROW_LEFT : |
|
494 |
case SWT.ARROW_LEFT : |
488 |
case SWT.ARROW_RIGHT : |
|
495 |
case SWT.ARROW_RIGHT : |
489 |
case SWT.ARROW_UP : |
|
496 |
case SWT.ARROW_UP : |
490 |
case SWT.ARROW_DOWN : |
|
497 |
case SWT.ARROW_DOWN : |
491 |
return true; |
|
498 |
return true; |
492 |
} |
|
499 |
} |
493 |
return false; |
|
500 |
return false; |
494 |
} |
|
501 |
} |
495 |
|
|
502 |
|
496 |
protected boolean traverse(Event event) { |
|
503 |
protected boolean traverse(Event event) { |
497 |
if (isDisposed()) return false; |
|
504 |
if (isDisposed()) return false; |
498 |
if(allowTraverseByArrowKey(event)) { |
|
505 |
if(allowTraverseByArrowKey(event)) { |
499 |
return traverseByArrowKey(event); |
|
506 |
return traverseByArrowKey(event); |
500 |
} |
|
507 |
} |
501 |
return super.traverse(event); |
|
508 |
return super.traverse(event); |
502 |
} |
|
509 |
} |
503 |
|
|
510 |
|
504 |
} |
|
511 |
} |