Mercurial > projects > dwt-linux
annotate dwt/widgets/Composite.d @ 55:93981635e709
Checked and inserted missing default switch cases.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 11 Jan 2008 15:40:16 +0100 |
parents | 7fb1ab011933 |
children | a5c274fa5af9 |
rev | line source |
---|---|
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); | |
40
7fb1ab011933
made macro implementations active, one compile problem in OS.d:2554
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
474 if (userData is null || OS.G_OBJECT_TYPE (cast(GTypeInstance*)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; | |
55
93981635e709
Checked and inserted missing default switch cases.
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
703 default: |
30 | 704 } |
705 } | |
706 return result; | |
707 } | |
708 | |
38 | 709 override int /*long*/ gtk_focus (GtkWidget* widget, int directionType) { |
34 | 710 if (widget is socketHandle) return 0; |
30 | 711 return super.gtk_focus (widget, directionType); |
712 } | |
713 | |
37 | 714 override int /*long*/ gtk_focus_in_event (GtkWidget* widget, GdkEventFocus* event) { |
30 | 715 int /*long*/ result = super.gtk_focus_in_event (widget, event); |
34 | 716 return (state & CANVAS) !is 0 ? 1 : result; |
30 | 717 } |
718 | |
37 | 719 override int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { |
34 | 720 auto result = super.gtk_focus_out_event (widget, event); |
721 return (state & CANVAS) !is 0 ? 1 : result; | |
30 | 722 } |
723 | |
34 | 724 override int /*long*/ gtk_map (GtkWidget* widget) { |
30 | 725 fixZOrder (); |
726 return 0; | |
727 } | |
728 | |
34 | 729 override int /*long*/ gtk_realize (GtkWidget* widget) { |
730 auto result = super.gtk_realize (widget); | |
731 if ((style & SWT.NO_BACKGROUND) !is 0) { | |
732 auto window = OS.GTK_WIDGET_WINDOW (paintHandle ()); | |
733 if (window !is null) OS.gdk_window_set_back_pixmap (window, null, false); | |
30 | 734 } |
34 | 735 if (socketHandle !is null) { |
736 embeddedHandle = OS.gtk_socket_get_id (cast(GtkSocket*)socketHandle); | |
30 | 737 } |
738 return result; | |
739 } | |
740 | |
34 | 741 override int /*long*/ gtk_scroll_child (GtkWidget* widget, int /*long*/ scrollType, int /*long*/ horizontal) { |
30 | 742 /* Stop GTK scroll child signal for canvas */ |
34 | 743 OS.g_signal_stop_emission_by_name (widget, OS.scroll_child.ptr); |
30 | 744 return 1; |
745 } | |
746 | |
34 | 747 override int /*long*/ gtk_style_set (GtkWidget* widget, int /*long*/ previousStyle) { |
748 auto result = super.gtk_style_set (widget, previousStyle); | |
749 if ((style & SWT.NO_BACKGROUND) !is 0) { | |
750 auto window = OS.GTK_WIDGET_WINDOW (paintHandle ()); | |
751 if (window !is null) OS.gdk_window_set_back_pixmap (window, null, false); | |
30 | 752 } |
753 return result; | |
754 } | |
755 | |
34 | 756 bool hasBorder () { |
757 return (style & SWT.BORDER) !is 0; | |
30 | 758 } |
759 | |
760 void hookEvents () { | |
761 super.hookEvents (); | |
34 | 762 if ((state & CANVAS) !is 0) { |
30 | 763 OS.gtk_widget_add_events (handle, OS.GDK_POINTER_MOTION_HINT_MASK); |
34 | 764 if (scrolledHandle !is null) { |
765 OS.g_signal_connect_closure (scrolledHandle, OS.scroll_child.ptr, display.closures [SCROLL_CHILD], false); | |
30 | 766 } |
767 } | |
768 } | |
769 | |
34 | 770 bool hooksKeys () { |
30 | 771 return hooks (SWT.KeyDown) || hooks (SWT.KeyUp); |
772 } | |
773 | |
34 | 774 GtkIMContext* imHandle () { |
775 return imHandle_; | |
30 | 776 } |
777 | |
778 /** | |
779 * Returns <code>true</code> if the receiver or any ancestor | |
780 * up to and including the receiver's nearest ancestor shell | |
781 * has deferred the performing of layouts. Otherwise, <code>false</code> | |
782 * is returned. | |
783 * | |
784 * @return the receiver's deferred layout state | |
785 * | |
786 * @exception SWTException <ul> | |
787 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
788 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
789 * </ul> | |
790 * | |
34 | 791 * @see #setLayoutDeferred(bool) |
30 | 792 * @see #getLayoutDeferred() |
793 * | |
794 * @since 3.1 | |
795 */ | |
34 | 796 public bool isLayoutDeferred () { |
30 | 797 checkWidget (); |
34 | 798 return findDeferredControl () !is null; |
30 | 799 } |
800 | |
34 | 801 bool isTabGroup() { |
802 if ((state & CANVAS) !is 0) return true; | |
30 | 803 return super.isTabGroup(); |
804 } | |
805 | |
806 /** | |
807 * If the receiver has a layout, asks the layout to <em>lay out</em> | |
808 * (that is, set the size and location of) the receiver's children. | |
809 * If the receiver does not have a layout, do nothing. | |
810 * <p> | |
811 * This is equivalent to calling <code>layout(true)</code>. | |
812 * </p> | |
813 * <p> | |
814 * Note: Layout is different from painting. If a child is | |
815 * moved or resized such that an area in the parent is | |
816 * exposed, then the parent will paint. If no child is | |
817 * affected, the parent will not paint. | |
818 * </p> | |
819 * | |
820 * @exception SWTException <ul> | |
821 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
822 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
823 * </ul> | |
824 */ | |
825 public void layout () { | |
826 checkWidget (); | |
827 layout (true); | |
828 } | |
829 | |
830 /** | |
831 * If the receiver has a layout, asks the layout to <em>lay out</em> | |
832 * (that is, set the size and location of) the receiver's children. | |
833 * If the argument is <code>true</code> the layout must not rely | |
834 * on any information it has cached about the immediate children. If it | |
835 * is <code>false</code> the layout may (potentially) optimize the | |
836 * work it is doing by assuming that none of the receiver's | |
837 * children has changed state since the last layout. | |
838 * If the receiver does not have a layout, do nothing. | |
839 * <p> | |
840 * If a child is resized as a result of a call to layout, the | |
841 * resize event will invoke the layout of the child. The layout | |
842 * will cascade down through all child widgets in the receiver's widget | |
843 * tree until a child is encountered that does not resize. Note that | |
844 * a layout due to a resize will not flush any cached information | |
845 * (same as <code>layout(false)</code>). | |
846 * </p> | |
847 * <p> | |
848 * Note: Layout is different from painting. If a child is | |
849 * moved or resized such that an area in the parent is | |
850 * exposed, then the parent will paint. If no child is | |
851 * affected, the parent will not paint. | |
852 * </p> | |
853 * | |
854 * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise | |
855 * | |
856 * @exception SWTException <ul> | |
857 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
858 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
859 * </ul> | |
860 */ | |
34 | 861 public void layout (bool changed) { |
30 | 862 checkWidget (); |
34 | 863 if (layout_ is null) return; |
30 | 864 layout (changed, false); |
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 changed argument is <code>true</code> the layout must not rely | |
871 * on any information it has cached about its 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 all argument is <code>true</code> the layout will cascade down | |
876 * through all child widgets in the receiver's widget tree, regardless of | |
877 * whether the child has changed size. The changed argument is applied to | |
878 * all layouts. If the all argument is <code>false</code>, the layout will | |
879 * <em>not</em> cascade down through all child widgets in the receiver's widget | |
880 * tree. However, if a child is resized as a result of a call to layout, the | |
881 * resize event will invoke the layout of the child. Note that | |
882 * a layout due to a resize will not flush any cached information | |
883 * (same as <code>layout(false)</code>). | |
884 * </p> | |
885 * <p> | |
886 * Note: Layout is different from painting. If a child is | |
887 * moved or resized such that an area in the parent is | |
888 * exposed, then the parent will paint. If no child is | |
889 * affected, the parent will not paint. | |
890 * </p> | |
891 * | |
892 * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise | |
893 * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise | |
894 * | |
895 * @exception SWTException <ul> | |
896 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
897 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
898 * </ul> | |
899 * | |
900 * @since 3.1 | |
901 */ | |
34 | 902 public void layout (bool changed, bool all) { |
30 | 903 checkWidget (); |
34 | 904 if (layout_ is null && !all) return; |
30 | 905 markLayout (changed, all); |
906 updateLayout (all); | |
907 } | |
908 | |
909 /** | |
910 * Forces a lay out (that is, sets the size and location) of all widgets that | |
911 * are in the parent hierarchy of the changed control up to and including the | |
912 * receiver. The layouts in the hierarchy must not rely on any information | |
913 * cached about the changed control or any of its ancestors. The layout may | |
914 * (potentially) optimize the work it is doing by assuming that none of the | |
915 * peers of the changed control have changed state since the last layout. | |
916 * If an ancestor does not have a layout, skip it. | |
917 * <p> | |
918 * Note: Layout is different from painting. If a child is | |
919 * moved or resized such that an area in the parent is | |
920 * exposed, then the parent will paint. If no child is | |
921 * affected, the parent will not paint. | |
922 * </p> | |
923 * | |
924 * @param changed a control that has had a state change which requires a recalculation of its size | |
925 * | |
926 * @exception IllegalArgumentException <ul> | |
927 * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li> | |
928 * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li> | |
929 * </ul> | |
930 * @exception SWTException <ul> | |
931 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
932 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
933 * </ul> | |
934 * | |
935 * @since 3.1 | |
936 */ | |
937 public void layout (Control [] changed) { | |
938 checkWidget (); | |
34 | 939 if (changed is null) error (SWT.ERROR_INVALID_ARGUMENT); |
30 | 940 for (int i=0; i<changed.length; i++) { |
941 Control control = changed [i]; | |
34 | 942 if (control is null) error (SWT.ERROR_INVALID_ARGUMENT); |
30 | 943 if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); |
34 | 944 bool ancestor = false; |
30 | 945 Composite composite = control.parent; |
34 | 946 while (composite !is null) { |
947 ancestor = composite is this; | |
30 | 948 if (ancestor) break; |
949 composite = composite.parent; | |
950 } | |
951 if (!ancestor) error (SWT.ERROR_INVALID_PARENT); | |
952 } | |
953 int updateCount = 0; | |
954 Composite [] update = new Composite [16]; | |
955 for (int i=0; i<changed.length; i++) { | |
956 Control child = changed [i]; | |
957 Composite composite = child.parent; | |
34 | 958 while (child !is this) { |
959 if (composite.layout_ !is null) { | |
30 | 960 composite.state |= LAYOUT_NEEDED; |
34 | 961 if (!composite.layout_.flushCache (child)) { |
30 | 962 composite.state |= LAYOUT_CHANGED; |
963 } | |
964 } | |
34 | 965 if (updateCount is update.length) { |
30 | 966 Composite [] newUpdate = new Composite [update.length + 16]; |
967 System.arraycopy (update, 0, newUpdate, 0, update.length); | |
968 update = newUpdate; | |
969 } | |
970 child = update [updateCount++] = composite; | |
971 composite = child.parent; | |
972 } | |
973 } | |
974 for (int i=updateCount-1; i>=0; i--) { | |
975 update [i].updateLayout (false); | |
976 } | |
977 } | |
978 | |
34 | 979 void markLayout (bool changed, bool all) { |
980 if (layout_ !is null) { | |
30 | 981 state |= LAYOUT_NEEDED; |
982 if (changed) state |= LAYOUT_CHANGED; | |
983 } | |
984 if (all) { | |
985 Control [] children = _getChildren (); | |
986 for (int i=0; i<children.length; i++) { | |
987 children [i].markLayout (changed, all); | |
988 } | |
989 } | |
990 } | |
991 | |
34 | 992 void moveAbove (GtkWidget* child, GtkWidget* sibling) { |
993 if (child is sibling) return; | |
994 auto parentHandle = parentingHandle (); | |
995 auto fixed = cast(GtkFixed*)parentHandle; | |
996 auto children = fixed.children; | |
997 if (children is null) return; | |
998 GList* data; | |
999 GtkWidget* widget; | |
1000 GList* childData, childLink, siblingLink; | |
1001 GList* temp = children; | |
1002 while (temp !is null) { | |
1003 data = temp; | |
1004 widget = cast(GtkWidget*) data; | |
1005 if (child is widget) { | |
30 | 1006 childLink = temp; |
34 | 1007 childData = data; |
1008 } else if (sibling is widget) { | |
30 | 1009 siblingLink = temp; |
1010 } | |
34 | 1011 if (childData !is null && (sibling is null || siblingLink !is null)) break; |
1012 temp = cast(GList*)OS.g_list_next (temp); | |
30 | 1013 } |
1014 children = OS.g_list_remove_link (children, childLink); | |
34 | 1015 if (siblingLink is null || siblingLink.prev is null) { |
30 | 1016 OS.g_list_free_1 (childLink); |
1017 children = OS.g_list_prepend (children, childData); | |
1018 } else { | |
34 | 1019 temp = siblingLink.prev; |
1020 childLink.prev = temp; | |
1021 temp.next = childLink; | |
1022 childLink.next = siblingLink; | |
1023 siblingLink.prev = childLink; | |
30 | 1024 } |
1025 fixed.children = children; | |
34 | 1026 parentHandle = cast(GtkWidget*)fixed; |
30 | 1027 } |
1028 | |
34 | 1029 void moveBelow (GtkWidget* child, GtkWidget* sibling) { |
1030 if (child is sibling) return; | |
1031 auto parentHandle = parentingHandle (); | |
1032 if (sibling is null && cast(GtkWidget*)parentHandle is cast(GtkWidget*)fixedHandle) { | |
1033 moveAbove (child, scrolledHandle !is null ? cast(GtkWidget*)scrolledHandle : handle); | |
30 | 1034 return; |
1035 } | |
34 | 1036 auto fixed = cast(GtkFixed*)parentHandle; |
1037 auto children = fixed.children; | |
1038 if (children is null) return; | |
1039 GList* data; | |
1040 GtkWidget* widget; | |
1041 GList* childData, childLink, siblingLink, temp = children; | |
1042 while (temp !is null) { | |
1043 data = temp; | |
1044 widget = cast(GtkWidget*) data; | |
1045 if (child is widget) { | |
30 | 1046 childLink = temp; |
34 | 1047 childData = data; |
1048 } else if (sibling is widget) { | |
30 | 1049 siblingLink = temp; |
1050 } | |
34 | 1051 if (childData !is null && (sibling is null || siblingLink !is null)) break; |
1052 temp = temp.next; | |
30 | 1053 } |
1054 children = OS.g_list_remove_link (children, childLink); | |
34 | 1055 if (siblingLink is null || siblingLink.next is null) { |
30 | 1056 OS.g_list_free_1 (childLink); |
1057 children = OS.g_list_append (children, childData); | |
1058 } else { | |
34 | 1059 temp = siblingLink.next; |
1060 childLink.next = temp; | |
1061 temp.prev = childLink; | |
1062 childLink.prev = siblingLink; | |
1063 siblingLink.next = childLink; | |
30 | 1064 } |
1065 fixed.children = children; | |
34 | 1066 parentHandle = cast(GtkWidget*)fixed; |
30 | 1067 } |
1068 | |
34 | 1069 Point minimumSize (int wHint, int hHint, bool changed) { |
30 | 1070 Control [] children = _getChildren (); |
1071 int width = 0, height = 0; | |
1072 for (int i=0; i<children.length; i++) { | |
1073 Rectangle rect = children [i].getBounds (); | |
1074 width = Math.max (width, rect.x + rect.width); | |
1075 height = Math.max (height, rect.y + rect.height); | |
1076 } | |
1077 return new Point (width, height); | |
1078 } | |
1079 | |
34 | 1080 GtkWidget* parentingHandle () { |
1081 if ((state & CANVAS) !is 0) return handle; | |
1082 return fixedHandle !is null ? fixedHandle : handle; | |
30 | 1083 } |
1084 | |
1085 void redrawChildren () { | |
1086 super.redrawChildren (); | |
1087 Control [] children = _getChildren (); | |
1088 for (int i = 0; i < children.length; i++) { | |
1089 Control child = children [i]; | |
34 | 1090 if ((child.state & PARENT_BACKGROUND) !is 0) { |
30 | 1091 child.redrawWidget (0, 0, 0, 0, true, false, true); |
1092 child.redrawChildren (); | |
1093 } | |
1094 } | |
1095 } | |
1096 | |
1097 void register () { | |
1098 super.register (); | |
34 | 1099 if (socketHandle !is null) display.addWidget (socketHandle, this); |
30 | 1100 } |
1101 | |
34 | 1102 void releaseChildren (bool destroy) { |
30 | 1103 Control [] children = _getChildren (); |
1104 for (int i=0; i<children.length; i++) { | |
1105 Control child = children [i]; | |
34 | 1106 if (child !is null && !child.isDisposed ()) { |
30 | 1107 child.release (false); |
1108 } | |
1109 } | |
1110 super.releaseChildren (destroy); | |
1111 } | |
1112 | |
1113 void releaseHandle () { | |
1114 super.releaseHandle (); | |
34 | 1115 socketHandle = null; |
1116 embeddedHandle = 0; | |
30 | 1117 } |
1118 | |
1119 void releaseWidget () { | |
1120 super.releaseWidget (); | |
34 | 1121 if (imHandle_ !is null) OS.g_object_unref (imHandle_); |
1122 imHandle_ = null; | |
1123 layout_ = null; | |
30 | 1124 tabList = null; |
1125 } | |
1126 | |
1127 void removeControl (Control control) { | |
1128 fixTabList (control); | |
1129 } | |
1130 | |
1131 void resizeHandle (int width, int height) { | |
1132 super.resizeHandle (width, height); | |
34 | 1133 if (socketHandle !is null) OS.gtk_widget_set_size_request (socketHandle, width, height); |
30 | 1134 } |
1135 | |
1136 /** | |
1137 * Sets the background drawing mode to the argument which should | |
1138 * be one of the following constants defined in class <code>SWT</code>: | |
1139 * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>, | |
1140 * <code>INHERIT_FORCE</code>. | |
1141 * | |
1142 * @param mode the new background mode | |
1143 * | |
1144 * @exception SWTException <ul> | |
1145 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1146 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1147 * </ul> | |
1148 * | |
1149 * @see SWT | |
1150 * | |
1151 * @since 3.2 | |
1152 */ | |
1153 public void setBackgroundMode (int mode) { | |
1154 checkWidget (); | |
1155 backgroundMode = mode; | |
1156 Control[] children = _getChildren (); | |
1157 for (int i = 0; i < children.length; i++) { | |
1158 children [i].updateBackgroundMode (); | |
1159 } | |
1160 } | |
1161 | |
34 | 1162 int setBounds (int x, int y, int width, int height, bool move, bool resize) { |
30 | 1163 int result = super.setBounds (x, y, width, height, move, resize); |
34 | 1164 if ((result & RESIZED) !is 0 && layout_ !is null) { |
30 | 1165 markLayout (false, false); |
1166 updateLayout (false); | |
1167 } | |
1168 return result; | |
1169 } | |
1170 | |
34 | 1171 public bool setFocus () { |
30 | 1172 checkWidget(); |
1173 Control [] children = _getChildren (); | |
1174 for (int i=0; i<children.length; i++) { | |
1175 Control child = children [i]; | |
1176 if (child.getVisible () && child.setFocus ()) return true; | |
1177 } | |
1178 return super.setFocus (); | |
1179 } | |
1180 | |
1181 /** | |
1182 * Sets the layout which is associated with the receiver to be | |
1183 * the argument which may be null. | |
1184 * | |
1185 * @param layout the receiver's new layout or null | |
1186 * | |
1187 * @exception SWTException <ul> | |
1188 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1189 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1190 * </ul> | |
1191 */ | |
1192 public void setLayout (Layout layout) { | |
1193 checkWidget(); | |
34 | 1194 this.layout_ = layout; |
30 | 1195 } |
1196 | |
1197 /** | |
1198 * If the argument is <code>true</code>, causes subsequent layout | |
1199 * operations in the receiver or any of its children to be ignored. | |
1200 * No layout of any kind can occur in the receiver or any of its | |
1201 * children until the flag is set to false. | |
1202 * Layout operations that occurred while the flag was | |
1203 * <code>true</code> are remembered and when the flag is set to | |
1204 * <code>false</code>, the layout operations are performed in an | |
1205 * optimized manner. Nested calls to this method are stacked. | |
1206 * | |
1207 * @param defer the new defer state | |
1208 * | |
1209 * @exception SWTException <ul> | |
1210 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1211 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1212 * </ul> | |
1213 * | |
34 | 1214 * @see #layout(bool) |
30 | 1215 * @see #layout(Control[]) |
1216 * | |
1217 * @since 3.1 | |
1218 */ | |
34 | 1219 public void setLayoutDeferred (bool defer) { |
30 | 1220 if (!defer) { |
34 | 1221 if (--layoutCount is 0) { |
1222 if ((state & LAYOUT_CHILD) !is 0 || (state & LAYOUT_NEEDED) !is 0) { | |
30 | 1223 updateLayout (true); |
1224 } | |
1225 } | |
1226 } else { | |
1227 layoutCount++; | |
1228 } | |
1229 } | |
1230 | |
34 | 1231 bool setScrollBarVisible (ScrollBar bar, bool visible) { |
1232 bool changed = super.setScrollBarVisible (bar, visible); | |
1233 if (changed && layout_ !is null) { | |
30 | 1234 markLayout (false, false); |
1235 updateLayout (false); | |
1236 } | |
1237 return changed; | |
1238 } | |
1239 | |
34 | 1240 bool setTabGroupFocus (bool next) { |
30 | 1241 if (isTabItem ()) return setTabItemFocus (next); |
34 | 1242 bool takeFocus = (style & SWT.NO_FOCUS) is 0; |
1243 if ((state & CANVAS) !is 0) takeFocus = hooksKeys (); | |
1244 if (socketHandle !is null) takeFocus = true; | |
30 | 1245 if (takeFocus && setTabItemFocus (next)) return true; |
1246 Control [] children = _getChildren (); | |
1247 for (int i=0; i<children.length; i++) { | |
1248 Control child = children [i]; | |
1249 if (child.isTabItem () && child.setTabItemFocus (next)) return true; | |
1250 } | |
1251 return false; | |
1252 } | |
1253 | |
34 | 1254 bool setTabItemFocus (bool next) { |
30 | 1255 if (!super.setTabItemFocus (next)) return false; |
34 | 1256 if (socketHandle !is null) { |
30 | 1257 int direction = next ? OS.GTK_DIR_TAB_FORWARD : OS.GTK_DIR_TAB_BACKWARD; |
1258 OS.GTK_WIDGET_UNSET_FLAGS (socketHandle, OS.GTK_HAS_FOCUS); | |
1259 OS.gtk_widget_child_focus (socketHandle, direction); | |
1260 OS.GTK_WIDGET_SET_FLAGS (socketHandle, OS.GTK_HAS_FOCUS); | |
1261 } | |
1262 return true; | |
1263 } | |
1264 | |
1265 /** | |
1266 * Sets the tabbing order for the specified controls to | |
1267 * match the order that they occur in the argument list. | |
1268 * | |
1269 * @param tabList the ordered list of controls representing the tab order or null | |
1270 * | |
1271 * @exception IllegalArgumentException <ul> | |
1272 * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li> | |
1273 * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li> | |
1274 * </ul> | |
1275 * @exception SWTException <ul> | |
1276 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1277 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1278 * </ul> | |
1279 */ | |
1280 public void setTabList (Control [] tabList) { | |
1281 checkWidget (); | |
34 | 1282 if (tabList !is null) { |
30 | 1283 for (int i=0; i<tabList.length; i++) { |
1284 Control control = tabList [i]; | |
34 | 1285 if (control is null) error (SWT.ERROR_INVALID_ARGUMENT); |
30 | 1286 if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); |
34 | 1287 if (control.parent !is this) error (SWT.ERROR_INVALID_PARENT); |
30 | 1288 } |
1289 Control [] newList = new Control [tabList.length]; | |
1290 System.arraycopy (tabList, 0, newList, 0, tabList.length); | |
1291 tabList = newList; | |
1292 } | |
1293 this.tabList = tabList; | |
1294 } | |
1295 | |
1296 void showWidget () { | |
1297 super.showWidget (); | |
34 | 1298 if (socketHandle !is null) { |
30 | 1299 OS.gtk_widget_show (socketHandle); |
34 | 1300 embeddedHandle = OS.gtk_socket_get_id (cast(GtkSocket*)socketHandle); |
30 | 1301 } |
34 | 1302 if (scrolledHandle is null) fixStyle (handle); |
30 | 1303 } |
1304 | |
34 | 1305 bool translateMnemonic (Event event, Control control) { |
30 | 1306 if (super.translateMnemonic (event, control)) return true; |
34 | 1307 if (control !is null) { |
30 | 1308 Control [] children = _getChildren (); |
1309 for (int i=0; i<children.length; i++) { | |
1310 Control child = children [i]; | |
1311 if (child.translateMnemonic (event, control)) return true; | |
1312 } | |
1313 } | |
1314 return false; | |
1315 } | |
1316 | |
34 | 1317 int traversalCode(int key, GdkEventKey* event) { |
1318 if ((state & CANVAS) !is 0) { | |
1319 if ((style & SWT.NO_FOCUS) !is 0) return 0; | |
30 | 1320 if (hooksKeys ()) return 0; |
1321 } | |
1322 return super.traversalCode (key, event); | |
1323 } | |
1324 | |
34 | 1325 bool translateTraversal (GdkEventKey* keyEvent) { |
1326 if (socketHandle !is null) return false; | |
30 | 1327 return super.translateTraversal (keyEvent); |
1328 } | |
1329 | |
1330 void updateBackgroundMode () { | |
1331 super.updateBackgroundMode (); | |
1332 Control [] children = _getChildren (); | |
1333 for (int i = 0; i < children.length; i++) { | |
1334 children [i].updateBackgroundMode (); | |
1335 } | |
1336 } | |
1337 | |
34 | 1338 void updateLayout (bool all) { |
30 | 1339 Composite parent = findDeferredControl (); |
34 | 1340 if (parent !is null) { |
30 | 1341 parent.state |= LAYOUT_CHILD; |
1342 return; | |
1343 } | |
34 | 1344 if ((state & LAYOUT_NEEDED) !is 0) { |
1345 bool changed = (state & LAYOUT_CHANGED) !is 0; | |
30 | 1346 state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED); |
34 | 1347 layout_.layout (this, changed); |
30 | 1348 } |
1349 if (all) { | |
1350 state &= ~LAYOUT_CHILD; | |
1351 Control [] children = _getChildren (); | |
1352 for (int i=0; i<children.length; i++) { | |
1353 children [i].updateLayout (all); | |
1354 } | |
1355 } | |
1356 } | |
1357 } |