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