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