30
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 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 *******************************************************************************/
|
|
11 module dwt.widgets.Composite;
|
|
12 import dwt.widgets.Control;
|
|
13 import dwt.internal.gtk.c.gtktypes;
|
|
14
|
|
15 class Composite : Control {
|
|
16 Control [] _getTabList ();
|
|
17 int backgroundMode;
|
|
18 GtkWidget* parentingHandle ();
|
|
19 Control [] _getChildren () ;
|
|
20 void removeControl (Control control);
|
|
21 void moveAbove (GtkWidget* child, GtkWidget* sibling);
|
|
22 void moveBelow (GtkWidget* child, GtkWidget* sibling);
|
|
23 void fixZOrder () ;
|
|
24 }
|
|
25
|
|
26 /+
|
|
27 import dwt.*;
|
|
28 import dwt.internal.cairo.*;
|
|
29 import dwt.internal.gtk.*;
|
|
30 import dwt.graphics.*;
|
|
31
|
|
32 /**
|
|
33 * Instances of this class are controls which are capable
|
|
34 * of containing other controls.
|
|
35 * <dl>
|
|
36 * <dt><b>Styles:</b></dt>
|
|
37 * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd>
|
|
38 * <dt><b>Events:</b></dt>
|
|
39 * <dd>(none)</dd>
|
|
40 * </dl>
|
|
41 * <p>
|
|
42 * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
|
|
43 * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
|
|
44 * They can be used with <code>Composite</code> if you are drawing your own, but their
|
|
45 * behavior is undefined if they are used with subclasses of <code>Composite</code> other
|
|
46 * than <code>Canvas</code>.
|
|
47 * </p><p>
|
|
48 * Note: The <code>CENTER</code> style, although undefined for composites, has the
|
|
49 * same value as <code>EMBEDDED</code> (which is used to embed widgets from other
|
|
50 * widget toolkits into SWT). On some operating systems (GTK, Motif), this may cause
|
|
51 * the children of this composite to be obscured. The <code>EMBEDDED</code> style
|
|
52 * is for use by other widget toolkits and should normally never be used.
|
|
53 * </p><p>
|
|
54 * This class may be subclassed by custom control implementors
|
|
55 * who are building controls that are constructed from aggregates
|
|
56 * of other controls.
|
|
57 * </p>
|
|
58 *
|
|
59 * @see Canvas
|
|
60 */
|
|
61 public class Composite extends Scrollable {
|
|
62 public int /*long*/ embeddedHandle;
|
|
63 int /*long*/ imHandle, socketHandle;
|
|
64 Layout layout;
|
|
65 Control[] tabList;
|
|
66 int layoutCount, backgroundMode;
|
|
67
|
|
68 static final String NO_INPUT_METHOD = "dwt.internal.gtk.noInputMethod"; //$NON-NLS-1$
|
|
69
|
|
70 Composite () {
|
|
71 /* Do nothing */
|
|
72 }
|
|
73
|
|
74 /**
|
|
75 * Constructs a new instance of this class given its parent
|
|
76 * and a style value describing its behavior and appearance.
|
|
77 * <p>
|
|
78 * The style value is either one of the style constants defined in
|
|
79 * class <code>SWT</code> which is applicable to instances of this
|
|
80 * class, or must be built by <em>bitwise OR</em>'ing together
|
|
81 * (that is, using the <code>int</code> "|" operator) two or more
|
|
82 * of those <code>SWT</code> style constants. The class description
|
|
83 * lists the style constants that are applicable to the class.
|
|
84 * Style bits are also inherited from superclasses.
|
|
85 * </p>
|
|
86 *
|
|
87 * @param parent a widget which will be the parent of the new instance (cannot be null)
|
|
88 * @param style the style of widget to construct
|
|
89 *
|
|
90 * @exception IllegalArgumentException <ul>
|
|
91 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
|
|
92 * </ul>
|
|
93 * @exception SWTException <ul>
|
|
94 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
|
|
95 * </ul>
|
|
96 *
|
|
97 * @see SWT#NO_BACKGROUND
|
|
98 * @see SWT#NO_FOCUS
|
|
99 * @see SWT#NO_MERGE_PAINTS
|
|
100 * @see SWT#NO_REDRAW_RESIZE
|
|
101 * @see SWT#NO_RADIO_GROUP
|
|
102 * @see Widget#getStyle
|
|
103 */
|
|
104 public Composite (Composite parent, int style) {
|
|
105 super (parent, style);
|
|
106 }
|
|
107
|
|
108 Control [] _getChildren () {
|
|
109 int /*long*/ parentHandle = parentingHandle ();
|
|
110 int /*long*/ list = OS.gtk_container_get_children (parentHandle);
|
|
111 if (list == 0) return new Control [0];
|
|
112 int count = OS.g_list_length (list);
|
|
113 Control [] children = new Control [count];
|
|
114 int i = 0;
|
|
115 int /*long*/ temp = list;
|
|
116 while (temp != 0) {
|
|
117 int /*long*/ handle = OS.g_list_data (temp);
|
|
118 if (handle != 0) {
|
|
119 Widget widget = display.getWidget (handle);
|
|
120 if (widget != null && widget != this) {
|
|
121 if (widget instanceof Control) {
|
|
122 children [i++] = (Control) widget;
|
|
123 }
|
|
124 }
|
|
125 }
|
|
126 temp = OS.g_list_next (temp);
|
|
127 }
|
|
128 OS.g_list_free (list);
|
|
129 if (i == count) return children;
|
|
130 Control [] newChildren = new Control [i];
|
|
131 System.arraycopy (children, 0, newChildren, 0, i);
|
|
132 return newChildren;
|
|
133 }
|
|
134
|
|
135 Control [] _getTabList () {
|
|
136 if (tabList == null) return tabList;
|
|
137 int count = 0;
|
|
138 for (int i=0; i<tabList.length; i++) {
|
|
139 if (!tabList [i].isDisposed ()) count++;
|
|
140 }
|
|
141 if (count == tabList.length) return tabList;
|
|
142 Control [] newList = new Control [count];
|
|
143 int index = 0;
|
|
144 for (int i=0; i<tabList.length; i++) {
|
|
145 if (!tabList [i].isDisposed ()) {
|
|
146 newList [index++] = tabList [i];
|
|
147 }
|
|
148 }
|
|
149 tabList = newList;
|
|
150 return tabList;
|
|
151 }
|
|
152
|
|
153 /**
|
|
154 * Clears any data that has been cached by a Layout for all widgets that
|
|
155 * are in the parent hierarchy of the changed control up to and including the
|
|
156 * receiver. If an ancestor does not have a layout, it is skipped.
|
|
157 *
|
|
158 * @param changed an array of controls that changed state and require a recalculation of size
|
|
159 *
|
|
160 * @exception IllegalArgumentException <ul>
|
|
161 * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
|
|
162 * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
|
|
163 * </ul>
|
|
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 * @since 3.1
|
|
170 */
|
|
171 public void changed (Control[] changed) {
|
|
172 checkWidget ();
|
|
173 if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
174 for (int i=0; i<changed.length; i++) {
|
|
175 Control control = changed [i];
|
|
176 if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
177 if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
178 boolean ancestor = false;
|
|
179 Composite composite = control.parent;
|
|
180 while (composite != null) {
|
|
181 ancestor = composite == this;
|
|
182 if (ancestor) break;
|
|
183 composite = composite.parent;
|
|
184 }
|
|
185 if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
|
|
186 }
|
|
187 for (int i=0; i<changed.length; i++) {
|
|
188 Control child = changed [i];
|
|
189 Composite composite = child.parent;
|
|
190 while (child != this) {
|
|
191 if (composite.layout == null || !composite.layout.flushCache (child)) {
|
|
192 composite.state |= LAYOUT_CHANGED;
|
|
193 }
|
|
194 child = composite;
|
|
195 composite = child.parent;
|
|
196 }
|
|
197 }
|
|
198 }
|
|
199
|
|
200 void checkBuffered () {
|
|
201 if ((style & SWT.DOUBLE_BUFFERED) == 0 && (style & SWT.NO_BACKGROUND) != 0) {
|
|
202 return;
|
|
203 }
|
|
204 super.checkBuffered();
|
|
205 }
|
|
206
|
|
207 protected void checkSubclass () {
|
|
208 /* Do nothing - Subclassing is allowed */
|
|
209 }
|
|
210
|
|
211 int /*long*/ childStyle () {
|
|
212 if (scrolledHandle != 0) return 0;
|
|
213 return super.childStyle ();
|
|
214 }
|
|
215
|
|
216 public Point computeSize (int wHint, int hHint, boolean changed) {
|
|
217 checkWidget ();
|
|
218 if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
|
|
219 if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
|
|
220 Point size;
|
|
221 if (layout != null) {
|
|
222 if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
|
|
223 changed |= (state & LAYOUT_CHANGED) != 0;
|
|
224 size = layout.computeSize (this, wHint, hHint, changed);
|
|
225 state &= ~LAYOUT_CHANGED;
|
|
226 } else {
|
|
227 size = new Point (wHint, hHint);
|
|
228 }
|
|
229 } else {
|
|
230 size = minimumSize (wHint, hHint, changed);
|
|
231 }
|
|
232 if (size.x == 0) size.x = DEFAULT_WIDTH;
|
|
233 if (size.y == 0) size.y = DEFAULT_HEIGHT;
|
|
234 if (wHint != SWT.DEFAULT) size.x = wHint;
|
|
235 if (hHint != SWT.DEFAULT) size.y = hHint;
|
|
236 Rectangle trim = computeTrim (0, 0, size.x, size.y);
|
|
237 return new Point (trim.width, trim.height);
|
|
238 }
|
|
239
|
|
240 Control [] computeTabList () {
|
|
241 Control result [] = super.computeTabList ();
|
|
242 if (result.length == 0) return result;
|
|
243 Control [] list = tabList != null ? _getTabList () : _getChildren ();
|
|
244 for (int i=0; i<list.length; i++) {
|
|
245 Control child = list [i];
|
|
246 Control [] childList = child.computeTabList ();
|
|
247 if (childList.length != 0) {
|
|
248 Control [] newResult = new Control [result.length + childList.length];
|
|
249 System.arraycopy (result, 0, newResult, 0, result.length);
|
|
250 System.arraycopy (childList, 0, newResult, result.length, childList.length);
|
|
251 result = newResult;
|
|
252 }
|
|
253 }
|
|
254 return result;
|
|
255 }
|
|
256
|
|
257 void createHandle (int index) {
|
|
258 state |= HANDLE | CANVAS;
|
|
259 boolean scrolled = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0;
|
|
260 if (!scrolled) state |= THEME_BACKGROUND;
|
|
261 createHandle (index, true, scrolled || (style & SWT.BORDER) != 0);
|
|
262 }
|
|
263
|
|
264 void createHandle (int index, boolean fixed, boolean scrolled) {
|
|
265 if (scrolled) {
|
|
266 if (fixed) {
|
|
267 fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
|
|
268 if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
|
|
269 OS.gtk_fixed_set_has_window (fixedHandle, true);
|
|
270 }
|
|
271 int /*long*/ vadj = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10);
|
|
272 if (vadj == 0) error (SWT.ERROR_NO_HANDLES);
|
|
273 int /*long*/ hadj = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10);
|
|
274 if (hadj == 0) error (SWT.ERROR_NO_HANDLES);
|
|
275 scrolledHandle = OS.gtk_scrolled_window_new (hadj, vadj);
|
|
276 if (scrolledHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
|
|
277 }
|
|
278 handle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
|
|
279 if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
|
|
280 OS.gtk_fixed_set_has_window (handle, true);
|
|
281 OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_FOCUS);
|
|
282 if ((style & SWT.EMBEDDED) == 0) {
|
|
283 if ((state & CANVAS) != 0 && (style & SWT.NO_FOCUS) == 0) {
|
|
284 /* Prevent an input method context from being created for the Browser widget */
|
|
285 if (display.getData (NO_INPUT_METHOD) == null) {
|
|
286 imHandle = OS.gtk_im_multicontext_new ();
|
|
287 if (imHandle == 0) error (SWT.ERROR_NO_HANDLES);
|
|
288 }
|
|
289 }
|
|
290 }
|
|
291 if (scrolled) {
|
|
292 if (fixed) OS.gtk_container_add (fixedHandle, scrolledHandle);
|
|
293 /*
|
|
294 * Force the scrolledWindow to have a single child that is
|
|
295 * not scrolled automatically. Calling gtk_container_add()
|
|
296 * seems to add the child correctly but cause a warning.
|
|
297 */
|
|
298 boolean warnings = display.getWarnings ();
|
|
299 display.setWarnings (false);
|
|
300 OS.gtk_container_add (scrolledHandle, handle);
|
|
301 display.setWarnings (warnings);
|
|
302
|
|
303 int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER;
|
|
304 int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER;
|
|
305 OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp);
|
|
306 if (hasBorder ()) {
|
|
307 OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN);
|
|
308 }
|
|
309 }
|
|
310 if ((style & SWT.EMBEDDED) != 0) {
|
|
311 socketHandle = OS.gtk_socket_new ();
|
|
312 if (socketHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
|
|
313 OS.gtk_container_add (handle, socketHandle);
|
|
314 }
|
|
315 if ((style & SWT.NO_REDRAW_RESIZE) != 0) {
|
|
316 OS.gtk_widget_set_redraw_on_allocate (handle, false);
|
|
317 }
|
|
318 /*
|
|
319 * Bug in GTK. When a widget is double buffered and the back
|
|
320 * pixmap is null, the double buffer pixmap is filled with the
|
|
321 * background of the widget rather than the current contents of
|
|
322 * the screen. If nothing is drawn during an expose event,
|
|
323 * the pixels are altered. The fix is to clear double buffering
|
|
324 * when NO_BACKGROUND is set and DOUBLE_BUFFERED
|
|
325 * is not explicitly set.
|
|
326 */
|
|
327 if ((style & SWT.DOUBLE_BUFFERED) == 0 && (style & SWT.NO_BACKGROUND) != 0) {
|
|
328 OS.gtk_widget_set_double_buffered (handle, false);
|
|
329 }
|
|
330 }
|
|
331
|
|
332 void deregister () {
|
|
333 super.deregister ();
|
|
334 if (socketHandle != 0) display.removeWidget (socketHandle);
|
|
335 }
|
|
336
|
|
337 void drawBackground (GC gc, int x, int y, int width, int height) {
|
|
338 Control control = findBackgroundControl ();
|
|
339 if (control != null) {
|
|
340 GCData data = gc.getGCData ();
|
|
341 int /*long*/ cairo = data.cairo;
|
|
342 if (cairo != 0) {
|
|
343 Cairo.cairo_save (cairo);
|
|
344 if (control.backgroundImage != null) {
|
|
345 Point pt = display.map (this, control, 0, 0);
|
|
346 Cairo.cairo_translate (cairo, -pt.x, -pt.y);
|
|
347 x += pt.x;
|
|
348 y += pt.y;
|
|
349 int /*long*/ xDisplay = OS.GDK_DISPLAY ();
|
|
350 int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual (OS.gdk_visual_get_system());
|
|
351 int /*long*/ drawable = control.backgroundImage.pixmap;
|
|
352 int /*long*/ xDrawable = OS.GDK_PIXMAP_XID (drawable);
|
|
353 int [] w = new int [1], h = new int [1];
|
|
354 OS.gdk_drawable_get_size (drawable, w, h);
|
|
355 int /*long*/ surface = Cairo.cairo_xlib_surface_create (xDisplay, xDrawable, xVisual, w [0], h [0]);
|
|
356 if (surface == 0) error (SWT.ERROR_NO_HANDLES);
|
|
357 int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface (surface);
|
|
358 if (pattern == 0) error (SWT.ERROR_NO_HANDLES);
|
|
359 Cairo.cairo_pattern_set_extend (pattern, Cairo.CAIRO_EXTEND_REPEAT);
|
|
360 Cairo.cairo_set_source (cairo, pattern);
|
|
361 Cairo.cairo_surface_destroy (surface);
|
|
362 Cairo.cairo_pattern_destroy (pattern);
|
|
363 } else {
|
|
364 GdkColor color = control.getBackgroundColor ();
|
|
365 Cairo.cairo_set_source_rgba (cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
|
|
366 }
|
|
367 Cairo.cairo_rectangle (cairo, x, y, width, height);
|
|
368 Cairo.cairo_fill (cairo);
|
|
369 Cairo.cairo_restore (cairo);
|
|
370 } else {
|
|
371 int /*long*/ gdkGC = gc.handle;
|
|
372 GdkGCValues values = new GdkGCValues ();
|
|
373 OS.gdk_gc_get_values (gdkGC, values);
|
|
374 if (control.backgroundImage != null) {
|
|
375 Point pt = display.map (this, control, 0, 0);
|
|
376 OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED);
|
|
377 OS.gdk_gc_set_ts_origin (gdkGC, -pt.x, -pt.y);
|
|
378 OS.gdk_gc_set_tile (gdkGC, control.backgroundImage.pixmap);
|
|
379 OS.gdk_draw_rectangle (data.drawable, gdkGC, 1, x, y, width, height);
|
|
380 OS.gdk_gc_set_fill (gdkGC, values.fill);
|
|
381 OS.gdk_gc_set_ts_origin (gdkGC, values.ts_x_origin, values.ts_y_origin);
|
|
382 } else {
|
|
383 GdkColor color = control.getBackgroundColor ();
|
|
384 OS.gdk_gc_set_foreground (gdkGC, color);
|
|
385 OS.gdk_draw_rectangle (data.drawable, gdkGC, 1, x, y, width, height);
|
|
386 color.pixel = values.foreground_pixel;
|
|
387 OS.gdk_gc_set_foreground (gdkGC, color);
|
|
388 }
|
|
389 }
|
|
390 } else {
|
|
391 gc.fillRectangle (x, y, width, height);
|
|
392 }
|
|
393 }
|
|
394
|
|
395 void enableWidget (boolean enabled) {
|
|
396 if ((state & CANVAS) != 0) return;
|
|
397 super.enableWidget (enabled);
|
|
398 }
|
|
399
|
|
400 Composite findDeferredControl () {
|
|
401 return layoutCount > 0 ? this : parent.findDeferredControl ();
|
|
402 }
|
|
403
|
|
404 Menu [] findMenus (Control control) {
|
|
405 if (control == this) return new Menu [0];
|
|
406 Menu result [] = super.findMenus (control);
|
|
407 Control [] children = _getChildren ();
|
|
408 for (int i=0; i<children.length; i++) {
|
|
409 Control child = children [i];
|
|
410 Menu [] menuList = child.findMenus (control);
|
|
411 if (menuList.length != 0) {
|
|
412 Menu [] newResult = new Menu [result.length + menuList.length];
|
|
413 System.arraycopy (result, 0, newResult, 0, result.length);
|
|
414 System.arraycopy (menuList, 0, newResult, result.length, menuList.length);
|
|
415 result = newResult;
|
|
416 }
|
|
417 }
|
|
418 return result;
|
|
419 }
|
|
420
|
|
421 void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
|
|
422 super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
|
|
423 Control [] children = _getChildren ();
|
|
424 for (int i=0; i<children.length; i++) {
|
|
425 children [i].fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
|
|
426 }
|
|
427 }
|
|
428
|
|
429 void fixStyle () {
|
|
430 super.fixStyle ();
|
|
431 if (scrolledHandle == 0) fixStyle (handle);
|
|
432 Control[] children = _getChildren ();
|
|
433 for (int i = 0; i < children.length; i++) {
|
|
434 children [i].fixStyle ();
|
|
435 }
|
|
436 }
|
|
437
|
|
438 void fixTabList (Control control) {
|
|
439 if (tabList == null) return;
|
|
440 int count = 0;
|
|
441 for (int i=0; i<tabList.length; i++) {
|
|
442 if (tabList [i] == control) count++;
|
|
443 }
|
|
444 if (count == 0) return;
|
|
445 Control [] newList = null;
|
|
446 int length = tabList.length - count;
|
|
447 if (length != 0) {
|
|
448 newList = new Control [length];
|
|
449 int index = 0;
|
|
450 for (int i=0; i<tabList.length; i++) {
|
|
451 if (tabList [i] != control) {
|
|
452 newList [index++] = tabList [i];
|
|
453 }
|
|
454 }
|
|
455 }
|
|
456 tabList = newList;
|
|
457 }
|
|
458
|
|
459 void fixZOrder () {
|
|
460 if ((state & CANVAS) != 0) return;
|
|
461 int /*long*/ parentHandle = parentingHandle ();
|
|
462 int /*long*/ parentWindow = OS.GTK_WIDGET_WINDOW (parentHandle);
|
|
463 if (parentWindow == 0) return;
|
|
464 int /*long*/ [] userData = new int /*long*/ [1];
|
|
465 int /*long*/ windowList = OS.gdk_window_get_children (parentWindow);
|
|
466 if (windowList != 0) {
|
|
467 int /*long*/ windows = windowList;
|
|
468 while (windows != 0) {
|
|
469 int /*long*/ window = OS.g_list_data (windows);
|
|
470 if (window != redrawWindow) {
|
|
471 OS.gdk_window_get_user_data (window, userData);
|
|
472 if (userData [0] == 0 || OS.G_OBJECT_TYPE (userData [0]) != display.gtk_fixed_get_type ()) {
|
|
473 OS.gdk_window_lower (window);
|
|
474 }
|
|
475 }
|
|
476 windows = OS.g_list_next (windows);
|
|
477 }
|
|
478 OS.g_list_free (windowList);
|
|
479 }
|
|
480 }
|
|
481
|
|
482 int /*long*/ focusHandle () {
|
|
483 if (socketHandle != 0) return socketHandle;
|
|
484 return super.focusHandle ();
|
|
485 }
|
|
486
|
|
487 boolean forceFocus (int /*long*/ focusHandle) {
|
|
488 if (socketHandle != 0) OS.GTK_WIDGET_SET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS);
|
|
489 boolean result = super.forceFocus (focusHandle);
|
|
490 if (socketHandle != 0) OS.GTK_WIDGET_UNSET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS);
|
|
491 return result;
|
|
492 }
|
|
493
|
|
494 /**
|
|
495 * Returns the receiver's background drawing mode. This
|
|
496 * will be one of the following constants defined in class
|
|
497 * <code>SWT</code>:
|
|
498 * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
|
|
499 * <code>INHERTIT_FORCE</code>.
|
|
500 *
|
|
501 * @return the background mode
|
|
502 *
|
|
503 * @exception SWTException <ul>
|
|
504 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
505 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
506 * </ul>
|
|
507 *
|
|
508 * @see SWT
|
|
509 *
|
|
510 * @since 3.2
|
|
511 */
|
|
512 public int getBackgroundMode () {
|
|
513 checkWidget ();
|
|
514 return backgroundMode;
|
|
515 }
|
|
516
|
|
517 /**
|
|
518 * Returns a (possibly empty) array containing the receiver's children.
|
|
519 * Children are returned in the order that they are drawn. The topmost
|
|
520 * control appears at the beginning of the array. Subsequent controls
|
|
521 * draw beneath this control and appear later in the array.
|
|
522 * <p>
|
|
523 * Note: This is not the actual structure used by the receiver
|
|
524 * to maintain its list of children, so modifying the array will
|
|
525 * not affect the receiver.
|
|
526 * </p>
|
|
527 *
|
|
528 * @return an array of children
|
|
529 *
|
|
530 * @see Control#moveAbove
|
|
531 * @see Control#moveBelow
|
|
532 *
|
|
533 * @exception SWTException <ul>
|
|
534 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
535 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
536 * </ul>
|
|
537 */
|
|
538 public Control [] getChildren () {
|
|
539 checkWidget();
|
|
540 return _getChildren ();
|
|
541 }
|
|
542
|
|
543 int getChildrenCount () {
|
|
544 /*
|
|
545 * NOTE: The current implementation will count
|
|
546 * non-registered children.
|
|
547 */
|
|
548 int /*long*/ list = OS.gtk_container_get_children (handle);
|
|
549 if (list == 0) return 0;
|
|
550 int count = OS.g_list_length (list);
|
|
551 OS.g_list_free (list);
|
|
552 return count;
|
|
553 }
|
|
554
|
|
555 public Rectangle getClientArea () {
|
|
556 checkWidget();
|
|
557 if ((state & CANVAS) != 0) {
|
|
558 if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) {
|
|
559 return new Rectangle (0, 0, 0, 0);
|
|
560 }
|
|
561 forceResize ();
|
|
562 int /*long*/ clientHandle = clientHandle ();
|
|
563 int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle);
|
|
564 int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle);
|
|
565 return new Rectangle (0, 0, width, height);
|
|
566 }
|
|
567 return super.getClientArea();
|
|
568 }
|
|
569
|
|
570 /**
|
|
571 * Returns layout which is associated with the receiver, or
|
|
572 * null if one has not been set.
|
|
573 *
|
|
574 * @return the receiver's layout or null
|
|
575 *
|
|
576 * @exception SWTException <ul>
|
|
577 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
578 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
579 * </ul>
|
|
580 */
|
|
581 public Layout getLayout () {
|
|
582 checkWidget();
|
|
583 return layout;
|
|
584 }
|
|
585
|
|
586 /**
|
|
587 * Returns <code>true</code> if the receiver has deferred
|
|
588 * the performing of layout, and <code>false</code> otherwise.
|
|
589 *
|
|
590 * @return the receiver's deferred layout state
|
|
591 *
|
|
592 * @exception SWTException <ul>
|
|
593 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
594 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
595 * </ul>
|
|
596 *
|
|
597 * @see #setLayoutDeferred(boolean)
|
|
598 * @see #isLayoutDeferred()
|
|
599 *
|
|
600 * @since 3.1
|
|
601 */
|
|
602 public boolean getLayoutDeferred () {
|
|
603 checkWidget ();
|
|
604 return layoutCount > 0 ;
|
|
605 }
|
|
606
|
|
607 /**
|
|
608 * Gets the (possibly empty) tabbing order for the control.
|
|
609 *
|
|
610 * @return tabList the ordered list of controls representing the tab order
|
|
611 *
|
|
612 * @exception SWTException <ul>
|
|
613 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
614 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
615 * </ul>
|
|
616 *
|
|
617 * @see #setTabList
|
|
618 */
|
|
619 public Control [] getTabList () {
|
|
620 checkWidget ();
|
|
621 Control [] tabList = _getTabList ();
|
|
622 if (tabList == null) {
|
|
623 int count = 0;
|
|
624 Control [] list =_getChildren ();
|
|
625 for (int i=0; i<list.length; i++) {
|
|
626 if (list [i].isTabGroup ()) count++;
|
|
627 }
|
|
628 tabList = new Control [count];
|
|
629 int index = 0;
|
|
630 for (int i=0; i<list.length; i++) {
|
|
631 if (list [i].isTabGroup ()) {
|
|
632 tabList [index++] = list [i];
|
|
633 }
|
|
634 }
|
|
635 }
|
|
636 return tabList;
|
|
637 }
|
|
638
|
|
639 int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
|
|
640 int /*long*/ result = super.gtk_button_press_event (widget, event);
|
|
641 if (result != 0) return result;
|
|
642 if ((state & CANVAS) != 0) {
|
|
643 if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
|
|
644 GdkEventButton gdkEvent = new GdkEventButton ();
|
|
645 OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
|
|
646 if (gdkEvent.button == 1) {
|
|
647 if (getChildrenCount () == 0) setFocus ();
|
|
648 }
|
|
649 }
|
|
650 }
|
|
651 return result;
|
|
652 }
|
|
653
|
|
654 int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) {
|
|
655 if ((state & OBSCURED) != 0) return 0;
|
|
656 if ((state & CANVAS) == 0) {
|
|
657 return super.gtk_expose_event (widget, eventPtr);
|
|
658 }
|
|
659 if ((style & SWT.NO_MERGE_PAINTS) == 0) {
|
|
660 return super.gtk_expose_event (widget, eventPtr);
|
|
661 }
|
|
662 if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0;
|
|
663 GdkEventExpose gdkEvent = new GdkEventExpose ();
|
|
664 OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof);
|
|
665 int /*long*/ [] rectangles = new int /*long*/ [1];
|
|
666 int [] n_rectangles = new int [1];
|
|
667 OS.gdk_region_get_rectangles (gdkEvent.region, rectangles, n_rectangles);
|
|
668 GdkRectangle rect = new GdkRectangle ();
|
|
669 for (int i=0; i<n_rectangles[0]; i++) {
|
|
670 Event event = new Event ();
|
|
671 OS.memmove (rect, rectangles [0] + i * GdkRectangle.sizeof, GdkRectangle.sizeof);
|
|
672 event.x = rect.x;
|
|
673 event.y = rect.y;
|
|
674 event.width = rect.width;
|
|
675 event.height = rect.height;
|
|
676 int /*long*/ damageRgn = OS.gdk_region_new ();
|
|
677 OS.gdk_region_union_with_rect (damageRgn, rect);
|
|
678 GCData data = new GCData ();
|
|
679 data.damageRgn = damageRgn;
|
|
680 GC gc = event.gc = GC.gtk_new (this, data);
|
|
681 OS.gdk_gc_set_clip_region (gc.handle, damageRgn);
|
|
682 sendEvent (SWT.Paint, event);
|
|
683 gc.dispose ();
|
|
684 OS.gdk_region_destroy (damageRgn);
|
|
685 event.gc = null;
|
|
686 }
|
|
687 OS.g_free (rectangles [0]);
|
|
688 return 0;
|
|
689 }
|
|
690
|
|
691 int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
|
|
692 int /*long*/ result = super.gtk_key_press_event (widget, event);
|
|
693 if (result != 0) return result;
|
|
694 /*
|
|
695 * Feature in GTK. The default behavior when the return key
|
|
696 * is pressed is to select the default button. This is not the
|
|
697 * expected behavior for Composite and its subclasses. The
|
|
698 * fix is to avoid calling the default handler.
|
|
699 */
|
|
700 if ((state & CANVAS) != 0 && socketHandle == 0) {
|
|
701 GdkEventKey keyEvent = new GdkEventKey ();
|
|
702 OS.memmove (keyEvent, event, GdkEventKey.sizeof);
|
|
703 int key = keyEvent.keyval;
|
|
704 switch (key) {
|
|
705 case OS.GDK_Return:
|
|
706 case OS.GDK_KP_Enter: return 1;
|
|
707 }
|
|
708 }
|
|
709 return result;
|
|
710 }
|
|
711
|
|
712 int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) {
|
|
713 if (widget == socketHandle) return 0;
|
|
714 return super.gtk_focus (widget, directionType);
|
|
715 }
|
|
716
|
|
717 int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
|
|
718 int /*long*/ result = super.gtk_focus_in_event (widget, event);
|
|
719 return (state & CANVAS) != 0 ? 1 : result;
|
|
720 }
|
|
721
|
|
722 int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
|
|
723 int /*long*/ result = super.gtk_focus_out_event (widget, event);
|
|
724 return (state & CANVAS) != 0 ? 1 : result;
|
|
725 }
|
|
726
|
|
727 int /*long*/ gtk_map (int /*long*/ widget) {
|
|
728 fixZOrder ();
|
|
729 return 0;
|
|
730 }
|
|
731
|
|
732 int /*long*/ gtk_realize (int /*long*/ widget) {
|
|
733 int /*long*/ result = super.gtk_realize (widget);
|
|
734 if ((style & SWT.NO_BACKGROUND) != 0) {
|
|
735 int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ());
|
|
736 if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, false);
|
|
737 }
|
|
738 if (socketHandle != 0) {
|
|
739 embeddedHandle = OS.gtk_socket_get_id (socketHandle);
|
|
740 }
|
|
741 return result;
|
|
742 }
|
|
743
|
|
744 int /*long*/ gtk_scroll_child (int /*long*/ widget, int /*long*/ scrollType, int /*long*/ horizontal) {
|
|
745 /* Stop GTK scroll child signal for canvas */
|
|
746 OS.g_signal_stop_emission_by_name (widget, OS.scroll_child);
|
|
747 return 1;
|
|
748 }
|
|
749
|
|
750 int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) {
|
|
751 int /*long*/ result = super.gtk_style_set (widget, previousStyle);
|
|
752 if ((style & SWT.NO_BACKGROUND) != 0) {
|
|
753 int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ());
|
|
754 if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, false);
|
|
755 }
|
|
756 return result;
|
|
757 }
|
|
758
|
|
759 boolean hasBorder () {
|
|
760 return (style & SWT.BORDER) != 0;
|
|
761 }
|
|
762
|
|
763 void hookEvents () {
|
|
764 super.hookEvents ();
|
|
765 if ((state & CANVAS) != 0) {
|
|
766 OS.gtk_widget_add_events (handle, OS.GDK_POINTER_MOTION_HINT_MASK);
|
|
767 if (scrolledHandle != 0) {
|
|
768 OS.g_signal_connect_closure (scrolledHandle, OS.scroll_child, display.closures [SCROLL_CHILD], false);
|
|
769 }
|
|
770 }
|
|
771 }
|
|
772
|
|
773 boolean hooksKeys () {
|
|
774 return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
|
|
775 }
|
|
776
|
|
777 int /*long*/ imHandle () {
|
|
778 return imHandle;
|
|
779 }
|
|
780
|
|
781 /**
|
|
782 * Returns <code>true</code> if the receiver or any ancestor
|
|
783 * up to and including the receiver's nearest ancestor shell
|
|
784 * has deferred the performing of layouts. Otherwise, <code>false</code>
|
|
785 * is returned.
|
|
786 *
|
|
787 * @return the receiver's deferred layout state
|
|
788 *
|
|
789 * @exception SWTException <ul>
|
|
790 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
791 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
792 * </ul>
|
|
793 *
|
|
794 * @see #setLayoutDeferred(boolean)
|
|
795 * @see #getLayoutDeferred()
|
|
796 *
|
|
797 * @since 3.1
|
|
798 */
|
|
799 public boolean isLayoutDeferred () {
|
|
800 checkWidget ();
|
|
801 return findDeferredControl () != null;
|
|
802 }
|
|
803
|
|
804 boolean isTabGroup() {
|
|
805 if ((state & CANVAS) != 0) return true;
|
|
806 return super.isTabGroup();
|
|
807 }
|
|
808
|
|
809 /**
|
|
810 * If the receiver has a layout, asks the layout to <em>lay out</em>
|
|
811 * (that is, set the size and location of) the receiver's children.
|
|
812 * If the receiver does not have a layout, do nothing.
|
|
813 * <p>
|
|
814 * This is equivalent to calling <code>layout(true)</code>.
|
|
815 * </p>
|
|
816 * <p>
|
|
817 * Note: Layout is different from painting. If a child is
|
|
818 * moved or resized such that an area in the parent is
|
|
819 * exposed, then the parent will paint. If no child is
|
|
820 * affected, the parent will not paint.
|
|
821 * </p>
|
|
822 *
|
|
823 * @exception SWTException <ul>
|
|
824 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
825 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
826 * </ul>
|
|
827 */
|
|
828 public void layout () {
|
|
829 checkWidget ();
|
|
830 layout (true);
|
|
831 }
|
|
832
|
|
833 /**
|
|
834 * If the receiver has a layout, asks the layout to <em>lay out</em>
|
|
835 * (that is, set the size and location of) the receiver's children.
|
|
836 * If the argument is <code>true</code> the layout must not rely
|
|
837 * on any information it has cached about the immediate children. If it
|
|
838 * is <code>false</code> the layout may (potentially) optimize the
|
|
839 * work it is doing by assuming that none of the receiver's
|
|
840 * children has changed state since the last layout.
|
|
841 * If the receiver does not have a layout, do nothing.
|
|
842 * <p>
|
|
843 * If a child is resized as a result of a call to layout, the
|
|
844 * resize event will invoke the layout of the child. The layout
|
|
845 * will cascade down through all child widgets in the receiver's widget
|
|
846 * tree until a child is encountered that does not resize. Note that
|
|
847 * a layout due to a resize will not flush any cached information
|
|
848 * (same as <code>layout(false)</code>).
|
|
849 * </p>
|
|
850 * <p>
|
|
851 * Note: Layout is different from painting. If a child is
|
|
852 * moved or resized such that an area in the parent is
|
|
853 * exposed, then the parent will paint. If no child is
|
|
854 * affected, the parent will not paint.
|
|
855 * </p>
|
|
856 *
|
|
857 * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
|
|
858 *
|
|
859 * @exception SWTException <ul>
|
|
860 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
861 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
862 * </ul>
|
|
863 */
|
|
864 public void layout (boolean changed) {
|
|
865 checkWidget ();
|
|
866 if (layout == null) return;
|
|
867 layout (changed, false);
|
|
868 }
|
|
869
|
|
870 /**
|
|
871 * If the receiver has a layout, asks the layout to <em>lay out</em>
|
|
872 * (that is, set the size and location of) the receiver's children.
|
|
873 * If the changed argument is <code>true</code> the layout must not rely
|
|
874 * on any information it has cached about its children. If it
|
|
875 * is <code>false</code> the layout may (potentially) optimize the
|
|
876 * work it is doing by assuming that none of the receiver's
|
|
877 * children has changed state since the last layout.
|
|
878 * If the all argument is <code>true</code> the layout will cascade down
|
|
879 * through all child widgets in the receiver's widget tree, regardless of
|
|
880 * whether the child has changed size. The changed argument is applied to
|
|
881 * all layouts. If the all argument is <code>false</code>, the layout will
|
|
882 * <em>not</em> cascade down through all child widgets in the receiver's widget
|
|
883 * tree. However, if a child is resized as a result of a call to layout, the
|
|
884 * resize event will invoke the layout of the child. Note that
|
|
885 * a layout due to a resize will not flush any cached information
|
|
886 * (same as <code>layout(false)</code>).
|
|
887 * </p>
|
|
888 * <p>
|
|
889 * Note: Layout is different from painting. If a child is
|
|
890 * moved or resized such that an area in the parent is
|
|
891 * exposed, then the parent will paint. If no child is
|
|
892 * affected, the parent will not paint.
|
|
893 * </p>
|
|
894 *
|
|
895 * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
|
|
896 * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise
|
|
897 *
|
|
898 * @exception SWTException <ul>
|
|
899 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
900 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
901 * </ul>
|
|
902 *
|
|
903 * @since 3.1
|
|
904 */
|
|
905 public void layout (boolean changed, boolean all) {
|
|
906 checkWidget ();
|
|
907 if (layout == null && !all) return;
|
|
908 markLayout (changed, all);
|
|
909 updateLayout (all);
|
|
910 }
|
|
911
|
|
912 /**
|
|
913 * Forces a lay out (that is, sets the size and location) of all widgets that
|
|
914 * are in the parent hierarchy of the changed control up to and including the
|
|
915 * receiver. The layouts in the hierarchy must not rely on any information
|
|
916 * cached about the changed control or any of its ancestors. The layout may
|
|
917 * (potentially) optimize the work it is doing by assuming that none of the
|
|
918 * peers of the changed control have changed state since the last layout.
|
|
919 * If an ancestor does not have a layout, skip it.
|
|
920 * <p>
|
|
921 * Note: Layout is different from painting. If a child is
|
|
922 * moved or resized such that an area in the parent is
|
|
923 * exposed, then the parent will paint. If no child is
|
|
924 * affected, the parent will not paint.
|
|
925 * </p>
|
|
926 *
|
|
927 * @param changed a control that has had a state change which requires a recalculation of its size
|
|
928 *
|
|
929 * @exception IllegalArgumentException <ul>
|
|
930 * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
|
|
931 * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
|
|
932 * </ul>
|
|
933 * @exception SWTException <ul>
|
|
934 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
935 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
936 * </ul>
|
|
937 *
|
|
938 * @since 3.1
|
|
939 */
|
|
940 public void layout (Control [] changed) {
|
|
941 checkWidget ();
|
|
942 if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
943 for (int i=0; i<changed.length; i++) {
|
|
944 Control control = changed [i];
|
|
945 if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
946 if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
947 boolean ancestor = false;
|
|
948 Composite composite = control.parent;
|
|
949 while (composite != null) {
|
|
950 ancestor = composite == this;
|
|
951 if (ancestor) break;
|
|
952 composite = composite.parent;
|
|
953 }
|
|
954 if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
|
|
955 }
|
|
956 int updateCount = 0;
|
|
957 Composite [] update = new Composite [16];
|
|
958 for (int i=0; i<changed.length; i++) {
|
|
959 Control child = changed [i];
|
|
960 Composite composite = child.parent;
|
|
961 while (child != this) {
|
|
962 if (composite.layout != null) {
|
|
963 composite.state |= LAYOUT_NEEDED;
|
|
964 if (!composite.layout.flushCache (child)) {
|
|
965 composite.state |= LAYOUT_CHANGED;
|
|
966 }
|
|
967 }
|
|
968 if (updateCount == update.length) {
|
|
969 Composite [] newUpdate = new Composite [update.length + 16];
|
|
970 System.arraycopy (update, 0, newUpdate, 0, update.length);
|
|
971 update = newUpdate;
|
|
972 }
|
|
973 child = update [updateCount++] = composite;
|
|
974 composite = child.parent;
|
|
975 }
|
|
976 }
|
|
977 for (int i=updateCount-1; i>=0; i--) {
|
|
978 update [i].updateLayout (false);
|
|
979 }
|
|
980 }
|
|
981
|
|
982 void markLayout (boolean changed, boolean all) {
|
|
983 if (layout != null) {
|
|
984 state |= LAYOUT_NEEDED;
|
|
985 if (changed) state |= LAYOUT_CHANGED;
|
|
986 }
|
|
987 if (all) {
|
|
988 Control [] children = _getChildren ();
|
|
989 for (int i=0; i<children.length; i++) {
|
|
990 children [i].markLayout (changed, all);
|
|
991 }
|
|
992 }
|
|
993 }
|
|
994
|
|
995 void moveAbove (int /*long*/ child, int /*long*/ sibling) {
|
|
996 if (child == sibling) return;
|
|
997 int /*long*/ parentHandle = parentingHandle ();
|
|
998 GtkFixed fixed = new GtkFixed ();
|
|
999 OS.memmove (fixed, parentHandle);
|
|
1000 int /*long*/ children = fixed.children;
|
|
1001 if (children == 0) return;
|
|
1002 int /*long*/ [] data = new int /*long*/ [1];
|
|
1003 int /*long*/ [] widget = new int /*long*/ [1];
|
|
1004 int /*long*/ childData = 0, childLink = 0, siblingLink = 0, temp = children;
|
|
1005 while (temp != 0) {
|
|
1006 OS.memmove (data, temp, OS.PTR_SIZEOF);
|
|
1007 OS.memmove (widget, data [0], OS.PTR_SIZEOF);
|
|
1008 if (child == widget [0]) {
|
|
1009 childLink = temp;
|
|
1010 childData = data [0];
|
|
1011 } else if (sibling == widget [0]) {
|
|
1012 siblingLink = temp;
|
|
1013 }
|
|
1014 if (childData != 0 && (sibling == 0 || siblingLink != 0)) break;
|
|
1015 temp = OS.g_list_next (temp);
|
|
1016 }
|
|
1017 children = OS.g_list_remove_link (children, childLink);
|
|
1018 if (siblingLink == 0 || OS.g_list_previous (siblingLink) == 0) {
|
|
1019 OS.g_list_free_1 (childLink);
|
|
1020 children = OS.g_list_prepend (children, childData);
|
|
1021 } else {
|
|
1022 temp = OS.g_list_previous (siblingLink);
|
|
1023 OS.g_list_set_previous (childLink, temp);
|
|
1024 OS.g_list_set_next (temp, childLink);
|
|
1025 OS.g_list_set_next (childLink, siblingLink);
|
|
1026 OS.g_list_set_previous (siblingLink, childLink);
|
|
1027 }
|
|
1028 fixed.children = children;
|
|
1029 OS.memmove (parentHandle, fixed);
|
|
1030 }
|
|
1031
|
|
1032 void moveBelow (int /*long*/ child, int /*long*/ sibling) {
|
|
1033 if (child == sibling) return;
|
|
1034 int /*long*/ parentHandle = parentingHandle ();
|
|
1035 if (sibling == 0 && parentHandle == fixedHandle) {
|
|
1036 moveAbove (child, scrolledHandle != 0 ? scrolledHandle : handle);
|
|
1037 return;
|
|
1038 }
|
|
1039 GtkFixed fixed = new GtkFixed ();
|
|
1040 OS.memmove (fixed, parentHandle);
|
|
1041 int /*long*/ children = fixed.children;
|
|
1042 if (children == 0) return;
|
|
1043 int /*long*/ [] data = new int /*long*/ [1];
|
|
1044 int /*long*/ [] widget = new int /*long*/ [1];
|
|
1045 int /*long*/ childData = 0, childLink = 0, siblingLink = 0, temp = children;
|
|
1046 while (temp != 0) {
|
|
1047 OS.memmove (data, temp, OS.PTR_SIZEOF);
|
|
1048 OS.memmove (widget, data [0], OS.PTR_SIZEOF);
|
|
1049 if (child == widget [0]) {
|
|
1050 childLink = temp;
|
|
1051 childData = data [0];
|
|
1052 } else if (sibling == widget [0]) {
|
|
1053 siblingLink = temp;
|
|
1054 }
|
|
1055 if (childData != 0 && (sibling == 0 || siblingLink != 0)) break;
|
|
1056 temp = OS.g_list_next (temp);
|
|
1057 }
|
|
1058 children = OS.g_list_remove_link (children, childLink);
|
|
1059 if (siblingLink == 0 || OS.g_list_next (siblingLink) == 0) {
|
|
1060 OS.g_list_free_1 (childLink);
|
|
1061 children = OS.g_list_append (children, childData);
|
|
1062 } else {
|
|
1063 temp = OS.g_list_next (siblingLink);
|
|
1064 OS.g_list_set_next (childLink, temp);
|
|
1065 OS.g_list_set_previous (temp, childLink);
|
|
1066 OS.g_list_set_previous (childLink, siblingLink);
|
|
1067 OS.g_list_set_next (siblingLink, childLink);
|
|
1068 }
|
|
1069 fixed.children = children;
|
|
1070 OS.memmove (parentHandle, fixed);
|
|
1071 }
|
|
1072
|
|
1073 Point minimumSize (int wHint, int hHint, boolean changed) {
|
|
1074 Control [] children = _getChildren ();
|
|
1075 int width = 0, height = 0;
|
|
1076 for (int i=0; i<children.length; i++) {
|
|
1077 Rectangle rect = children [i].getBounds ();
|
|
1078 width = Math.max (width, rect.x + rect.width);
|
|
1079 height = Math.max (height, rect.y + rect.height);
|
|
1080 }
|
|
1081 return new Point (width, height);
|
|
1082 }
|
|
1083
|
|
1084 int /*long*/ parentingHandle () {
|
|
1085 if ((state & CANVAS) != 0) return handle;
|
|
1086 return fixedHandle != 0 ? fixedHandle : handle;
|
|
1087 }
|
|
1088
|
|
1089 void redrawChildren () {
|
|
1090 super.redrawChildren ();
|
|
1091 Control [] children = _getChildren ();
|
|
1092 for (int i = 0; i < children.length; i++) {
|
|
1093 Control child = children [i];
|
|
1094 if ((child.state & PARENT_BACKGROUND) != 0) {
|
|
1095 child.redrawWidget (0, 0, 0, 0, true, false, true);
|
|
1096 child.redrawChildren ();
|
|
1097 }
|
|
1098 }
|
|
1099 }
|
|
1100
|
|
1101 void register () {
|
|
1102 super.register ();
|
|
1103 if (socketHandle != 0) display.addWidget (socketHandle, this);
|
|
1104 }
|
|
1105
|
|
1106 void releaseChildren (boolean destroy) {
|
|
1107 Control [] children = _getChildren ();
|
|
1108 for (int i=0; i<children.length; i++) {
|
|
1109 Control child = children [i];
|
|
1110 if (child != null && !child.isDisposed ()) {
|
|
1111 child.release (false);
|
|
1112 }
|
|
1113 }
|
|
1114 super.releaseChildren (destroy);
|
|
1115 }
|
|
1116
|
|
1117 void releaseHandle () {
|
|
1118 super.releaseHandle ();
|
|
1119 socketHandle = embeddedHandle = 0;
|
|
1120 }
|
|
1121
|
|
1122 void releaseWidget () {
|
|
1123 super.releaseWidget ();
|
|
1124 if (imHandle != 0) OS.g_object_unref (imHandle);
|
|
1125 imHandle = 0;
|
|
1126 layout = null;
|
|
1127 tabList = null;
|
|
1128 }
|
|
1129
|
|
1130 void removeControl (Control control) {
|
|
1131 fixTabList (control);
|
|
1132 }
|
|
1133
|
|
1134 void resizeHandle (int width, int height) {
|
|
1135 super.resizeHandle (width, height);
|
|
1136 if (socketHandle != 0) OS.gtk_widget_set_size_request (socketHandle, width, height);
|
|
1137 }
|
|
1138
|
|
1139 /**
|
|
1140 * Sets the background drawing mode to the argument which should
|
|
1141 * be one of the following constants defined in class <code>SWT</code>:
|
|
1142 * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
|
|
1143 * <code>INHERIT_FORCE</code>.
|
|
1144 *
|
|
1145 * @param mode the new background mode
|
|
1146 *
|
|
1147 * @exception SWTException <ul>
|
|
1148 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1149 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1150 * </ul>
|
|
1151 *
|
|
1152 * @see SWT
|
|
1153 *
|
|
1154 * @since 3.2
|
|
1155 */
|
|
1156 public void setBackgroundMode (int mode) {
|
|
1157 checkWidget ();
|
|
1158 backgroundMode = mode;
|
|
1159 Control[] children = _getChildren ();
|
|
1160 for (int i = 0; i < children.length; i++) {
|
|
1161 children [i].updateBackgroundMode ();
|
|
1162 }
|
|
1163 }
|
|
1164
|
|
1165 int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
|
|
1166 int result = super.setBounds (x, y, width, height, move, resize);
|
|
1167 if ((result & RESIZED) != 0 && layout != null) {
|
|
1168 markLayout (false, false);
|
|
1169 updateLayout (false);
|
|
1170 }
|
|
1171 return result;
|
|
1172 }
|
|
1173
|
|
1174 public boolean setFocus () {
|
|
1175 checkWidget();
|
|
1176 Control [] children = _getChildren ();
|
|
1177 for (int i=0; i<children.length; i++) {
|
|
1178 Control child = children [i];
|
|
1179 if (child.getVisible () && child.setFocus ()) return true;
|
|
1180 }
|
|
1181 return super.setFocus ();
|
|
1182 }
|
|
1183
|
|
1184 /**
|
|
1185 * Sets the layout which is associated with the receiver to be
|
|
1186 * the argument which may be null.
|
|
1187 *
|
|
1188 * @param layout the receiver's new layout or null
|
|
1189 *
|
|
1190 * @exception SWTException <ul>
|
|
1191 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1192 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1193 * </ul>
|
|
1194 */
|
|
1195 public void setLayout (Layout layout) {
|
|
1196 checkWidget();
|
|
1197 this.layout = layout;
|
|
1198 }
|
|
1199
|
|
1200 /**
|
|
1201 * If the argument is <code>true</code>, causes subsequent layout
|
|
1202 * operations in the receiver or any of its children to be ignored.
|
|
1203 * No layout of any kind can occur in the receiver or any of its
|
|
1204 * children until the flag is set to false.
|
|
1205 * Layout operations that occurred while the flag was
|
|
1206 * <code>true</code> are remembered and when the flag is set to
|
|
1207 * <code>false</code>, the layout operations are performed in an
|
|
1208 * optimized manner. Nested calls to this method are stacked.
|
|
1209 *
|
|
1210 * @param defer the new defer state
|
|
1211 *
|
|
1212 * @exception SWTException <ul>
|
|
1213 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1214 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1215 * </ul>
|
|
1216 *
|
|
1217 * @see #layout(boolean)
|
|
1218 * @see #layout(Control[])
|
|
1219 *
|
|
1220 * @since 3.1
|
|
1221 */
|
|
1222 public void setLayoutDeferred (boolean defer) {
|
|
1223 if (!defer) {
|
|
1224 if (--layoutCount == 0) {
|
|
1225 if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) {
|
|
1226 updateLayout (true);
|
|
1227 }
|
|
1228 }
|
|
1229 } else {
|
|
1230 layoutCount++;
|
|
1231 }
|
|
1232 }
|
|
1233
|
|
1234 boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
|
|
1235 boolean changed = super.setScrollBarVisible (bar, visible);
|
|
1236 if (changed && layout != null) {
|
|
1237 markLayout (false, false);
|
|
1238 updateLayout (false);
|
|
1239 }
|
|
1240 return changed;
|
|
1241 }
|
|
1242
|
|
1243 boolean setTabGroupFocus (boolean next) {
|
|
1244 if (isTabItem ()) return setTabItemFocus (next);
|
|
1245 boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
|
|
1246 if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
|
|
1247 if (socketHandle != 0) takeFocus = true;
|
|
1248 if (takeFocus && setTabItemFocus (next)) return true;
|
|
1249 Control [] children = _getChildren ();
|
|
1250 for (int i=0; i<children.length; i++) {
|
|
1251 Control child = children [i];
|
|
1252 if (child.isTabItem () && child.setTabItemFocus (next)) return true;
|
|
1253 }
|
|
1254 return false;
|
|
1255 }
|
|
1256
|
|
1257 boolean setTabItemFocus (boolean next) {
|
|
1258 if (!super.setTabItemFocus (next)) return false;
|
|
1259 if (socketHandle != 0) {
|
|
1260 int direction = next ? OS.GTK_DIR_TAB_FORWARD : OS.GTK_DIR_TAB_BACKWARD;
|
|
1261 OS.GTK_WIDGET_UNSET_FLAGS (socketHandle, OS.GTK_HAS_FOCUS);
|
|
1262 OS.gtk_widget_child_focus (socketHandle, direction);
|
|
1263 OS.GTK_WIDGET_SET_FLAGS (socketHandle, OS.GTK_HAS_FOCUS);
|
|
1264 }
|
|
1265 return true;
|
|
1266 }
|
|
1267
|
|
1268 /**
|
|
1269 * Sets the tabbing order for the specified controls to
|
|
1270 * match the order that they occur in the argument list.
|
|
1271 *
|
|
1272 * @param tabList the ordered list of controls representing the tab order or null
|
|
1273 *
|
|
1274 * @exception IllegalArgumentException <ul>
|
|
1275 * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
|
|
1276 * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
|
|
1277 * </ul>
|
|
1278 * @exception SWTException <ul>
|
|
1279 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1280 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1281 * </ul>
|
|
1282 */
|
|
1283 public void setTabList (Control [] tabList) {
|
|
1284 checkWidget ();
|
|
1285 if (tabList != null) {
|
|
1286 for (int i=0; i<tabList.length; i++) {
|
|
1287 Control control = tabList [i];
|
|
1288 if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
1289 if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
1290 if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
|
|
1291 }
|
|
1292 Control [] newList = new Control [tabList.length];
|
|
1293 System.arraycopy (tabList, 0, newList, 0, tabList.length);
|
|
1294 tabList = newList;
|
|
1295 }
|
|
1296 this.tabList = tabList;
|
|
1297 }
|
|
1298
|
|
1299 void showWidget () {
|
|
1300 super.showWidget ();
|
|
1301 if (socketHandle != 0) {
|
|
1302 OS.gtk_widget_show (socketHandle);
|
|
1303 embeddedHandle = OS.gtk_socket_get_id (socketHandle);
|
|
1304 }
|
|
1305 if (scrolledHandle == 0) fixStyle (handle);
|
|
1306 }
|
|
1307
|
|
1308 boolean translateMnemonic (Event event, Control control) {
|
|
1309 if (super.translateMnemonic (event, control)) return true;
|
|
1310 if (control != null) {
|
|
1311 Control [] children = _getChildren ();
|
|
1312 for (int i=0; i<children.length; i++) {
|
|
1313 Control child = children [i];
|
|
1314 if (child.translateMnemonic (event, control)) return true;
|
|
1315 }
|
|
1316 }
|
|
1317 return false;
|
|
1318 }
|
|
1319
|
|
1320 int traversalCode(int key, GdkEventKey event) {
|
|
1321 if ((state & CANVAS) != 0) {
|
|
1322 if ((style & SWT.NO_FOCUS) != 0) return 0;
|
|
1323 if (hooksKeys ()) return 0;
|
|
1324 }
|
|
1325 return super.traversalCode (key, event);
|
|
1326 }
|
|
1327
|
|
1328 boolean translateTraversal (GdkEventKey keyEvent) {
|
|
1329 if (socketHandle != 0) return false;
|
|
1330 return super.translateTraversal (keyEvent);
|
|
1331 }
|
|
1332
|
|
1333 void updateBackgroundMode () {
|
|
1334 super.updateBackgroundMode ();
|
|
1335 Control [] children = _getChildren ();
|
|
1336 for (int i = 0; i < children.length; i++) {
|
|
1337 children [i].updateBackgroundMode ();
|
|
1338 }
|
|
1339 }
|
|
1340
|
|
1341 void updateLayout (boolean all) {
|
|
1342 Composite parent = findDeferredControl ();
|
|
1343 if (parent != null) {
|
|
1344 parent.state |= LAYOUT_CHILD;
|
|
1345 return;
|
|
1346 }
|
|
1347 if ((state & LAYOUT_NEEDED) != 0) {
|
|
1348 boolean changed = (state & LAYOUT_CHANGED) != 0;
|
|
1349 state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
|
|
1350 layout.layout (this, changed);
|
|
1351 }
|
|
1352 if (all) {
|
|
1353 state &= ~LAYOUT_CHILD;
|
|
1354 Control [] children = _getChildren ();
|
|
1355 for (int i=0; i<children.length; i++) {
|
|
1356 children [i].updateLayout (all);
|
|
1357 }
|
|
1358 }
|
|
1359 }
|
|
1360 }
|
|
1361 +/ |