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.Control;
|
|
14
|
|
15 import java.lang.all;
|
|
16
|
|
17
|
|
18 import org.eclipse.swt.SWT;
|
|
19 //import org.eclipse.swt.accessibility.Accessible;
|
|
20 import org.eclipse.swt.events.ControlListener;
|
|
21 import org.eclipse.swt.events.FocusListener;
|
|
22 import org.eclipse.swt.events.HelpListener;
|
|
23 import org.eclipse.swt.events.KeyListener;
|
|
24 import org.eclipse.swt.events.MouseListener;
|
|
25 import org.eclipse.swt.events.MouseMoveListener;
|
|
26 import org.eclipse.swt.events.MouseTrackListener;
|
|
27 import org.eclipse.swt.events.PaintListener;
|
|
28 import org.eclipse.swt.events.TraverseListener;
|
|
29 import org.eclipse.swt.events.DragDetectListener;
|
|
30 import org.eclipse.swt.events.MenuDetectListener;
|
|
31 import org.eclipse.swt.events.MouseWheelListener;
|
|
32 import org.eclipse.swt.graphics.Color;
|
|
33 import org.eclipse.swt.graphics.Cursor;
|
|
34 import org.eclipse.swt.graphics.Device;
|
|
35 import org.eclipse.swt.graphics.Drawable;
|
|
36 import org.eclipse.swt.graphics.Font;
|
|
37 import org.eclipse.swt.graphics.GC;
|
|
38 import org.eclipse.swt.graphics.GCData;
|
|
39 import org.eclipse.swt.graphics.Image;
|
|
40 import org.eclipse.swt.graphics.Point;
|
|
41 import org.eclipse.swt.graphics.Rectangle;
|
|
42 import org.eclipse.swt.graphics.Region;
|
|
43 import org.eclipse.swt.internal.Converter;
|
|
44 import org.eclipse.swt.internal.SWTEventListener;
|
|
45 import org.eclipse.swt.internal.accessibility.gtk.ATK;
|
|
46 import org.eclipse.swt.internal.gtk.OS;
|
|
47 import org.eclipse.swt.widgets.Composite;
|
|
48 import org.eclipse.swt.widgets.Decorations;
|
|
49 import org.eclipse.swt.widgets.Display;
|
|
50 import org.eclipse.swt.widgets.Event;
|
|
51 import org.eclipse.swt.widgets.Listener;
|
|
52 import org.eclipse.swt.widgets.Menu;
|
|
53 import org.eclipse.swt.widgets.Monitor;
|
|
54 import org.eclipse.swt.widgets.Shell;
|
|
55 import org.eclipse.swt.widgets.TypedListener;
|
|
56 import org.eclipse.swt.widgets.Widget;
|
|
57 import org.eclipse.swt.accessibility.Accessible;
|
|
58
|
|
59 import tango.core.Thread;
|
|
60
|
|
61
|
|
62 /**
|
|
63 * Control is the abstract superclass of all windowed user interface classes.
|
|
64 * <p>
|
|
65 * <dl>
|
|
66 * <dt><b>Styles:</b>
|
|
67 * <dd>BORDER</dd>
|
|
68 * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
|
|
69 * <dt><b>Events:</b>
|
|
70 * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter,
|
|
71 * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
|
|
72 * </dl>
|
|
73 * </p><p>
|
|
74 * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
|
|
75 * </p><p>
|
|
76 * IMPORTANT: This class is intended to be subclassed <em>only</em>
|
|
77 * within the SWT implementation.
|
|
78 * </p>
|
|
79 *
|
|
80 * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a>
|
|
81 * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
|
|
82 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
|
|
83 */
|
|
84 public abstract class Control : Widget, Drawable {
|
|
85
|
|
86 alias Widget.mnemonicHit mnemonicHit;
|
|
87 alias Widget.mnemonicMatch mnemonicMatch;
|
|
88 alias Widget.setForegroundColor setForegroundColor;
|
|
89 alias Widget.translateTraversal translateTraversal;
|
|
90 alias Widget.windowProc windowProc;
|
|
91
|
|
92 GtkWidget* fixedHandle;
|
|
93 GdkWindow* redrawWindow;
|
|
94 GdkWindow* enableWindow;
|
|
95 int drawCount;
|
|
96 Composite parent;
|
|
97 Cursor cursor;
|
|
98 Menu menu;
|
|
99 Image backgroundImage;
|
|
100 Font font;
|
|
101 Region region;
|
|
102 String toolTipText;
|
|
103 Object layoutData;
|
|
104 Accessible accessible;
|
|
105
|
|
106 this () {
|
|
107 }
|
|
108
|
|
109 /**
|
|
110 * Constructs a new instance of this class given its parent
|
|
111 * and a style value describing its behavior and appearance.
|
|
112 * <p>
|
|
113 * The style value is either one of the style constants defined in
|
|
114 * class <code>SWT</code> which is applicable to instances of this
|
|
115 * class, or must be built by <em>bitwise OR</em>'ing together
|
|
116 * (that is, using the <code>int</code> "|" operator) two or more
|
|
117 * of those <code>SWT</code> style constants. The class description
|
|
118 * lists the style constants that are applicable to the class.
|
|
119 * Style bits are also inherited from superclasses.
|
|
120 * </p>
|
|
121 *
|
|
122 * @param parent a composite control which will be the parent of the new instance (cannot be null)
|
|
123 * @param style the style of control to construct
|
|
124 *
|
|
125 * @exception IllegalArgumentException <ul>
|
|
126 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
|
|
127 * </ul>
|
|
128 * @exception SWTException <ul>
|
|
129 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
|
|
130 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
|
|
131 * </ul>
|
|
132 *
|
|
133 * @see SWT#BORDER
|
|
134 * @see Widget#checkSubclass
|
|
135 * @see Widget#getStyle
|
|
136 */
|
|
137 public this (Composite parent, int style) {
|
|
138 super (parent, style);
|
|
139 this.parent = parent;
|
|
140 createWidget (0);
|
|
141 }
|
|
142
|
|
143 Font defaultFont () {
|
|
144 return display.getSystemFont ();
|
|
145 }
|
|
146
|
|
147 override void deregister () {
|
|
148 super.deregister ();
|
|
149 if (fixedHandle !is null) display.removeWidget (fixedHandle);
|
|
150 auto imHandle = imHandle ();
|
|
151 if (imHandle !is null) display.removeWidget (cast(GtkWidget*)imHandle);
|
|
152 }
|
|
153
|
|
154 bool drawGripper (int x, int y, int width, int height, bool vertical) {
|
|
155 auto paintHandle = paintHandle ();
|
|
156 auto window = OS.GTK_WIDGET_WINDOW (paintHandle);
|
|
157 if (window is null) return false;
|
|
158 int orientation = vertical ? OS.GTK_ORIENTATION_HORIZONTAL : OS.GTK_ORIENTATION_VERTICAL;
|
|
159 if ((style & SWT.MIRRORED) !is 0) x = getClientWidth () - width - x;
|
|
160 char dummy;
|
|
161 OS.gtk_paint_handle (OS.gtk_widget_get_style (paintHandle), window, OS.GTK_STATE_NORMAL, OS.GTK_SHADOW_OUT, null, paintHandle, &dummy, x, y, width, height, orientation);
|
|
162 return true;
|
|
163 }
|
|
164
|
|
165 void enableWidget (bool enabled) {
|
|
166 OS.gtk_widget_set_sensitive (handle, enabled);
|
|
167 }
|
|
168
|
|
169 GtkWidget* enterExitHandle () {
|
|
170 return eventHandle ();
|
|
171 }
|
|
172
|
|
173 GtkWidget* eventHandle () {
|
|
174 return handle;
|
|
175 }
|
|
176
|
|
177 GdkWindow* eventWindow () {
|
|
178 auto eventHandle = eventHandle ();
|
|
179 OS.gtk_widget_realize (eventHandle);
|
|
180 return OS.GTK_WIDGET_WINDOW (eventHandle);
|
|
181 }
|
|
182
|
|
183 void fixFocus (Control focusControl) {
|
|
184 Shell shell = getShell ();
|
|
185 Control control = this;
|
|
186 while (control !is shell && (control = control.parent) !is null) {
|
|
187 if (control.setFocus ()) return;
|
|
188 }
|
|
189 shell.setSavedFocus (focusControl);
|
|
190 auto focusHandle_ = shell.vboxHandle;
|
|
191 OS.GTK_WIDGET_SET_FLAGS (focusHandle_, OS.GTK_CAN_FOCUS);
|
|
192 OS.gtk_widget_grab_focus (focusHandle_);
|
|
193 OS.GTK_WIDGET_UNSET_FLAGS (focusHandle_, OS.GTK_CAN_FOCUS);
|
|
194 }
|
|
195
|
|
196 public void fixStyle () {
|
|
197 if (fixedHandle !is null) fixStyle (fixedHandle);
|
|
198 }
|
|
199
|
|
200 void fixStyle (GtkWidget* handle) {
|
|
201 /*
|
|
202 * Feature in GTK. Some GTK themes apply a different background to
|
|
203 * the contents of a GtkNotebook. However, in an SWT TabFolder, the
|
|
204 * children are not parented below the GtkNotebook widget, and usually
|
|
205 * have their own GtkFixed. The fix is to look up the correct style
|
|
206 * for a child of a GtkNotebook and apply its background to any GtkFixed
|
|
207 * widgets that are direct children of an SWT TabFolder.
|
|
208 *
|
|
209 * Note that this has to be when the theme settings changes and that it
|
|
210 * should not override the application background.
|
|
211 */
|
|
212 if ((state & BACKGROUND) !is 0) return;
|
|
213 auto childStyle = parent.childStyle ();
|
|
214 if (childStyle !is null) {
|
|
215 GdkColor color;
|
|
216 OS.gtk_style_get_bg (childStyle, 0, &color);
|
|
217 OS.gtk_widget_modify_bg (handle, 0, &color);
|
|
218 }
|
|
219 }
|
|
220
|
|
221 GtkWidget* focusHandle () {
|
|
222 return handle;
|
|
223 }
|
|
224
|
|
225 GtkWidget* fontHandle () {
|
|
226 return handle;
|
|
227 }
|
|
228
|
|
229 bool hasFocus () {
|
|
230 return this is display.getFocusControl();
|
|
231 }
|
|
232
|
|
233 override void hookEvents () {
|
|
234 /* Connect the keyboard signals */
|
|
235 auto focusHandle_ = focusHandle ();
|
|
236 int focusMask = OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | OS.GDK_FOCUS_CHANGE_MASK;
|
|
237 OS.gtk_widget_add_events (focusHandle_, focusMask);
|
|
238 OS.g_signal_connect_closure_by_id (focusHandle_, display.signalIds [POPUP_MENU], 0, display.closures [POPUP_MENU], false);
|
|
239 OS.g_signal_connect_closure_by_id (focusHandle_, display.signalIds [SHOW_HELP], 0, display.closures [SHOW_HELP], false);
|
|
240 OS.g_signal_connect_closure_by_id (focusHandle_, display.signalIds [KEY_PRESS_EVENT], 0, display.closures [KEY_PRESS_EVENT], false);
|
|
241 OS.g_signal_connect_closure_by_id (focusHandle_, display.signalIds [KEY_RELEASE_EVENT], 0, display.closures [KEY_RELEASE_EVENT], false);
|
|
242 OS.g_signal_connect_closure_by_id (focusHandle_, display.signalIds [FOCUS], 0, display.closures [FOCUS], false);
|
|
243 OS.g_signal_connect_closure_by_id (focusHandle_, display.signalIds [FOCUS_IN_EVENT], 0, display.closures [FOCUS_IN_EVENT], false);
|
|
244 OS.g_signal_connect_closure_by_id (focusHandle_, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false);
|
|
245
|
|
246 /* Connect the mouse signals */
|
|
247 auto eventHandle = eventHandle ();
|
|
248 int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK;
|
|
249 OS.gtk_widget_add_events (eventHandle, eventMask);
|
|
250 OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
|
|
251 OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false);
|
|
252 OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT], false);
|
|
253 OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [SCROLL_EVENT], 0, display.closures [SCROLL_EVENT], false);
|
|
254
|
|
255 /* Connect enter/exit signals */
|
|
256 auto enterExitHandle = enterExitHandle ();
|
|
257 int enterExitMask = OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK;
|
|
258 OS.gtk_widget_add_events (enterExitHandle, enterExitMask);
|
|
259 OS.g_signal_connect_closure_by_id (enterExitHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
|
|
260 OS.g_signal_connect_closure_by_id (enterExitHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false);
|
|
261
|
|
262 /*
|
|
263 * Feature in GTK. Events such as mouse move are propagate up
|
|
264 * the widget hierarchy and are seen by the parent. This is the
|
|
265 * correct GTK behavior but not correct for SWT. The fix is to
|
|
266 * hook a signal after and stop the propagation using a negative
|
|
267 * event number to distinguish this case.
|
|
268 *
|
|
269 * The signal is hooked to the fixedHandle to catch events sent to
|
|
270 * lightweight widgets.
|
|
271 */
|
|
272 auto blockHandle = fixedHandle !is null ? fixedHandle : eventHandle;
|
|
273 OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT_INVERSE], true);
|
|
274 OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT_INVERSE], true);
|
|
275 OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT_INVERSE], true);
|
|
276
|
|
277 /* Connect the event_after signal for both key and mouse */
|
|
278 OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
|
|
279 if (focusHandle_ !is eventHandle) {
|
|
280 OS.g_signal_connect_closure_by_id (focusHandle_, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
|
|
281 }
|
|
282
|
|
283 /* Connect the paint signal */
|
|
284 auto paintHandle = paintHandle ();
|
|
285 int paintMask = OS.GDK_EXPOSURE_MASK | OS.GDK_VISIBILITY_NOTIFY_MASK;
|
|
286 OS.gtk_widget_add_events (paintHandle, paintMask);
|
|
287 OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT_INVERSE], false);
|
|
288 OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [VISIBILITY_NOTIFY_EVENT], 0, display.closures [VISIBILITY_NOTIFY_EVENT], false);
|
|
289 OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT], true);
|
|
290
|
|
291 /* Connect the Input Method signals */
|
|
292 OS.g_signal_connect_closure_by_id (handle, display.signalIds [REALIZE], 0, display.closures [REALIZE], true);
|
|
293 OS.g_signal_connect_closure_by_id (handle, display.signalIds [UNREALIZE], 0, display.closures [UNREALIZE], false);
|
|
294 auto imHandle = imHandle ();
|
|
295 if (imHandle !is null) {
|
|
296 OS.g_signal_connect_closure (imHandle, OS.commit.ptr, display.closures [COMMIT], false);
|
|
297 OS.g_signal_connect_closure (imHandle, OS.preedit_changed.ptr, display.closures [PREEDIT_CHANGED], false);
|
|
298 }
|
|
299
|
|
300 OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [STYLE_SET], 0, display.closures [STYLE_SET], false);
|
|
301
|
|
302 auto topHandle_ = topHandle ();
|
|
303 OS.g_signal_connect_closure_by_id (topHandle_, display.signalIds [MAP], 0, display.closures [MAP], true);
|
|
304 }
|
|
305
|
|
306 override int /*long*/ hoverProc (GtkWidget* widget) {
|
|
307 int x, y;
|
|
308 int mask;
|
|
309 OS.gdk_window_get_pointer (null, &x, &y, &mask);
|
|
310 sendMouseEvent (SWT.MouseHover, 0, /*time*/0, x , y , false, mask );
|
|
311 /* Always return zero in order to cancel the hover timer */
|
|
312 return 0;
|
|
313 }
|
|
314
|
|
315 override GtkWidget* topHandle() {
|
|
316 if (fixedHandle !is null) return fixedHandle;
|
|
317 return super.topHandle ();
|
|
318 }
|
|
319
|
|
320 GtkWidget* paintHandle () {
|
|
321 auto topHandle_ = topHandle ();
|
|
322 auto paintHandle = handle;
|
|
323 while (paintHandle !is topHandle_) {
|
|
324 if ((OS.GTK_WIDGET_FLAGS (paintHandle) & OS.GTK_NO_WINDOW) is 0) break;
|
|
325 paintHandle = OS.gtk_widget_get_parent (paintHandle);
|
|
326 }
|
|
327 return paintHandle;
|
|
328 }
|
|
329
|
|
330 override GdkWindow* paintWindow () {
|
|
331 auto paintHandle = paintHandle ();
|
|
332 OS.gtk_widget_realize (paintHandle);
|
|
333 return OS.GTK_WIDGET_WINDOW (paintHandle);
|
|
334 }
|
|
335
|
|
336 /**
|
|
337 * Prints the receiver and all children.
|
|
338 *
|
|
339 * @param gc the gc where the drawing occurs
|
|
340 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
|
|
341 *
|
|
342 * @exception IllegalArgumentException <ul>
|
|
343 * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
|
|
344 * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
|
|
345 * </ul>
|
|
346 * @exception SWTException <ul>
|
|
347 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
348 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
349 * </ul>
|
|
350 *
|
|
351 * @since 3.4
|
|
352 */
|
|
353 public bool print (GC gc) {
|
|
354 checkWidget ();
|
|
355 if (gc is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
356 if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
357 auto topHandle_ = topHandle ();
|
|
358 OS.gtk_widget_realize (topHandle_);
|
|
359 auto window = OS.GTK_WIDGET_WINDOW (topHandle_);
|
|
360 GCData data = gc.getGCData ();
|
|
361 OS.gdk_window_process_updates (window, cast(int)true);
|
|
362 printWidget (gc, data.drawable, OS.gdk_drawable_get_depth (data.drawable), 0, 0);
|
|
363 return true;
|
|
364 }
|
|
365
|
|
366 void printWidget (GC gc, GdkDrawable* drawable, int depth, int x, int y) {
|
|
367 bool obscured = (state & OBSCURED) !is 0;
|
|
368 state &= ~OBSCURED;
|
|
369 auto topHandle_ = topHandle ();
|
|
370 auto window = OS.GTK_WIDGET_WINDOW (topHandle_);
|
|
371 printWindow (true, this, gc.handle, drawable, depth, window, x, y);
|
|
372 if (obscured) state |= OBSCURED;
|
|
373 }
|
|
374
|
|
375 void printWindow (bool first, Control control, GdkGC* gc, GdkDrawable* drawable, int depth, GdkDrawable* window, int x, int y) {
|
|
376 if (OS.gdk_drawable_get_depth (window) !is depth) return;
|
|
377 GdkRectangle rect;
|
|
378 int width, height;
|
|
379 OS.gdk_drawable_get_size (window, &width, &height);
|
|
380 rect.width = width;
|
|
381 rect.height = height;
|
|
382 OS.gdk_window_begin_paint_rect (window, &rect);
|
|
383 GdkDrawable* real_drawable;
|
|
384 int x_offset, y_offset;
|
|
385 OS.gdk_window_get_internal_paint_info (window, &real_drawable, &x_offset, &y_offset);
|
|
386 void* userData;
|
|
387 OS.gdk_window_get_user_data (window, &userData);
|
|
388 if (userData !is null) {
|
|
389 GdkEventExpose* event = cast(GdkEventExpose*) OS.gdk_event_new (OS.GDK_EXPOSE);
|
|
390 event.type = OS.GDK_EXPOSE;
|
|
391 event.window = cast(GdkDrawable*)OS.g_object_ref (window);
|
|
392 event.area.width = rect.width;
|
|
393 event.area.height = rect.height;
|
|
394 event.region = OS.gdk_region_rectangle (&rect);
|
|
395 OS.gtk_widget_send_expose (userData, cast(GdkEvent*)event);
|
|
396 OS.gdk_event_free (cast(GdkEvent*)event);
|
|
397 }
|
|
398 int srcX = x_offset, srcY = y_offset;
|
|
399 int destX = x, destY = y, destWidth = width, destHeight = height;
|
|
400 if (!first) {
|
|
401 int cX, cY;
|
|
402 OS.gdk_window_get_position (window, &cX, &cY);
|
|
403 auto parentWindow = OS.gdk_window_get_parent (window);
|
|
404 int pW, pH;
|
|
405 OS.gdk_drawable_get_size (parentWindow, &pW, &pH);
|
|
406 srcX = x_offset - cX;
|
|
407 srcY = y_offset - cY;
|
|
408 destX = x - cX;
|
|
409 destY = y - cY;
|
|
410 destWidth = Math.min (cX + width, pW);
|
|
411 destHeight = Math.min (cY + height, pH);
|
|
412 }
|
|
413 OS.gdk_draw_drawable (drawable, gc, real_drawable, srcX, srcY, destX, destY, destWidth, destHeight);
|
|
414 OS.gdk_window_end_paint (window);
|
|
415 auto children = OS.gdk_window_get_children (window);
|
|
416 if (children !is null) {
|
|
417 auto windows = children;
|
|
418 while (windows !is null) {
|
|
419 auto child = cast(GdkDrawable*) OS.g_list_data (windows);
|
|
420 if (OS.gdk_window_is_visible (child)) {
|
|
421 void* data;
|
|
422 OS.gdk_window_get_user_data (child, &data);
|
|
423 if (data !is null) {
|
|
424 Widget widget = display.findWidget ( cast(GtkWidget*) data);
|
|
425 if (widget is null || widget is control) {
|
|
426 int x_pos, y_pos;
|
|
427 OS.gdk_window_get_position (child, &x_pos, &y_pos);
|
|
428 printWindow (false, control, gc, drawable, depth, child, x + x_pos, y + y_pos);
|
|
429 }
|
|
430 }
|
|
431 }
|
|
432 windows = OS.g_list_next (windows);
|
|
433 }
|
|
434 OS.g_list_free (children);
|
|
435 }
|
|
436 }
|
|
437
|
|
438 /**
|
|
439 * Returns the preferred size of the receiver.
|
|
440 * <p>
|
|
441 * The <em>preferred size</em> of a control is the size that it would
|
|
442 * best be displayed at. The width hint and height hint arguments
|
|
443 * allow the caller to ask a control questions such as "Given a particular
|
|
444 * width, how high does the control need to be to show all of the contents?"
|
|
445 * To indicate that the caller does not wish to constrain a particular
|
|
446 * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
|
|
447 * </p>
|
|
448 *
|
|
449 * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
|
|
450 * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
|
|
451 * @return the preferred size of the control
|
|
452 *
|
|
453 * @exception SWTException <ul>
|
|
454 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
455 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
456 * </ul>
|
|
457 *
|
|
458 * @see Layout
|
|
459 * @see #getBorderWidth
|
|
460 * @see #getBounds
|
|
461 * @see #getSize
|
|
462 * @see #pack(bool)
|
|
463 * @see "computeTrim, getClientArea for controls that implement them"
|
|
464 */
|
|
465 public Point computeSize (int wHint, int hHint) {
|
|
466 return computeSize (wHint, hHint, true);
|
|
467 }
|
|
468
|
|
469 Control computeTabGroup () {
|
|
470 if (isTabGroup()) return this;
|
|
471 return parent.computeTabGroup ();
|
|
472 }
|
|
473
|
|
474 Control[] computeTabList() {
|
|
475 if (isTabGroup()) {
|
|
476 if (getVisible() && getEnabled()) {
|
|
477 return [this];
|
|
478 }
|
|
479 }
|
|
480 return new Control[0];
|
|
481 }
|
|
482
|
|
483 Control computeTabRoot () {
|
|
484 Control[] tabList = parent._getTabList();
|
|
485 if (tabList !is null) {
|
|
486 int index = 0;
|
|
487 while (index < tabList.length) {
|
|
488 if (tabList [index] is this) break;
|
|
489 index++;
|
|
490 }
|
|
491 if (index is tabList.length) {
|
|
492 if (isTabGroup ()) return this;
|
|
493 }
|
|
494 }
|
|
495 return parent.computeTabRoot ();
|
|
496 }
|
|
497
|
|
498 void checkBuffered () {
|
|
499 style |= SWT.DOUBLE_BUFFERED;
|
|
500 }
|
|
501
|
|
502 void checkBackground () {
|
|
503 Shell shell = getShell ();
|
|
504 if (this is shell) return;
|
|
505 state &= ~PARENT_BACKGROUND;
|
|
506 Composite composite = parent;
|
|
507 do {
|
|
508 int mode = composite.backgroundMode;
|
|
509 if (mode !is SWT.INHERIT_NONE) {
|
|
510 if (mode is SWT.INHERIT_DEFAULT) {
|
|
511 Control control = this;
|
|
512 do {
|
|
513 if ((control.state & THEME_BACKGROUND) is 0) {
|
|
514 return;
|
|
515 }
|
|
516 control = control.parent;
|
|
517 } while (control !is composite);
|
|
518 }
|
|
519 state |= PARENT_BACKGROUND;
|
|
520 return;
|
|
521 }
|
|
522 if (composite is shell) break;
|
|
523 composite = composite.parent;
|
|
524 } while (true);
|
|
525 }
|
|
526
|
|
527 void checkBorder () {
|
|
528 if (getBorderWidth () is 0) style &= ~SWT.BORDER;
|
|
529 }
|
|
530
|
|
531 void checkMirrored () {
|
|
532 if ((style & SWT.RIGHT_TO_LEFT) !is 0) style |= SWT.MIRRORED;
|
|
533 }
|
|
534
|
|
535 GtkStyle* childStyle () {
|
|
536 return parent.childStyle ();
|
|
537 }
|
|
538
|
|
539 override void createWidget (int index) {
|
|
540 state |= DRAG_DETECT;
|
|
541 checkOrientation (parent);
|
|
542 super.createWidget (index);
|
|
543 checkBackground ();
|
|
544 if ((state & PARENT_BACKGROUND) !is 0) setBackground ();
|
|
545 checkBuffered ();
|
|
546 showWidget ();
|
|
547 setInitialBounds ();
|
|
548 setZOrder (null, false, false);
|
|
549 setRelations ();
|
|
550 checkMirrored ();
|
|
551 checkBorder ();
|
|
552 }
|
|
553
|
|
554 /**
|
|
555 * Returns the preferred size of the receiver.
|
|
556 * <p>
|
|
557 * The <em>preferred size</em> of a control is the size that it would
|
|
558 * best be displayed at. The width hint and height hint arguments
|
|
559 * allow the caller to ask a control questions such as "Given a particular
|
|
560 * width, how high does the control need to be to show all of the contents?"
|
|
561 * To indicate that the caller does not wish to constrain a particular
|
|
562 * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
|
|
563 * </p><p>
|
|
564 * If the changed flag is <code>true</code>, it indicates that the receiver's
|
|
565 * <em>contents</em> have changed, therefore any caches that a layout manager
|
|
566 * containing the control may have been keeping need to be flushed. When the
|
|
567 * control is resized, the changed flag will be <code>false</code>, so layout
|
|
568 * manager caches can be retained.
|
|
569 * </p>
|
|
570 *
|
|
571 * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
|
|
572 * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
|
|
573 * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
|
|
574 * @return the preferred size of the control.
|
|
575 *
|
|
576 * @exception SWTException <ul>
|
|
577 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
578 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
579 * </ul>
|
|
580 *
|
|
581 * @see Layout
|
|
582 * @see #getBorderWidth
|
|
583 * @see #getBounds
|
|
584 * @see #getSize
|
|
585 * @see #pack(bool)
|
|
586 * @see "computeTrim, getClientArea for controls that implement them"
|
|
587 */
|
|
588 public Point computeSize (int wHint, int hHint, bool changed) {
|
|
589 checkWidget();
|
|
590 if (wHint !is SWT.DEFAULT && wHint < 0) wHint = 0;
|
|
591 if (hHint !is SWT.DEFAULT && hHint < 0) hHint = 0;
|
|
592 return computeNativeSize (handle, wHint, hHint, changed);
|
|
593 }
|
|
594
|
|
595 Point computeNativeSize (GtkWidget* h, int wHint, int hHint, bool changed) {
|
|
596 int width = wHint, height = hHint;
|
|
597 if (wHint is SWT.DEFAULT && hHint is SWT.DEFAULT) {
|
|
598 GtkRequisition requisition;
|
|
599 gtk_widget_size_request (h, &requisition);
|
|
600 width = OS.GTK_WIDGET_REQUISITION_WIDTH (h);
|
|
601 height = OS.GTK_WIDGET_REQUISITION_HEIGHT (h);
|
|
602 } else if (wHint is SWT.DEFAULT || hHint is SWT.DEFAULT) {
|
|
603 int reqWidth, reqHeight;
|
|
604 OS.gtk_widget_get_size_request (h, &reqWidth, &reqHeight);
|
|
605 OS.gtk_widget_set_size_request (h, wHint, hHint);
|
|
606 GtkRequisition requisition;
|
|
607 gtk_widget_size_request (h, &requisition);
|
|
608 OS.gtk_widget_set_size_request (h, reqWidth, reqHeight);
|
|
609 width = wHint is SWT.DEFAULT ? requisition.width : wHint;
|
|
610 height = hHint is SWT.DEFAULT ? requisition.height : hHint;
|
|
611 }
|
|
612 return new Point (width, height);
|
|
613 }
|
|
614
|
|
615 void forceResize () {
|
|
616 /*
|
|
617 * Force size allocation on all children of this widget's
|
|
618 * topHandle. Note that all calls to gtk_widget_size_allocate()
|
|
619 * must be preceded by a call to gtk_widget_size_request().
|
|
620 */
|
|
621 auto topHandle_ = topHandle ();
|
|
622 GtkRequisition requisition;
|
|
623 gtk_widget_size_request (topHandle_, &requisition);
|
|
624 GtkAllocation allocation;
|
|
625 allocation.x = OS.GTK_WIDGET_X (topHandle_);
|
|
626 allocation.y = OS.GTK_WIDGET_Y (topHandle_);
|
|
627 allocation.width = OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
628 allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle_);
|
|
629 OS.gtk_widget_size_allocate (topHandle_, &allocation);
|
|
630 }
|
|
631
|
|
632 /**
|
|
633 * Returns the accessible object for the receiver.
|
|
634 * If this is the first time this object is requested,
|
|
635 * then the object is created and returned.
|
|
636 *
|
|
637 * @return the accessible object
|
|
638 *
|
|
639 * @exception SWTException <ul>
|
|
640 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
641 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
642 * </ul>
|
|
643 *
|
|
644 * @see Accessible#addAccessibleListener
|
|
645 * @see Accessible#addAccessibleControlListener
|
|
646 *
|
|
647 * @since 2.0
|
|
648 */
|
|
649 public Accessible getAccessible () {
|
|
650 checkWidget ();
|
|
651 if (accessible is null) {
|
|
652 accessible = Accessible.internal_new_Accessible (this);
|
|
653 }
|
|
654 return accessible;
|
|
655 }
|
|
656
|
|
657 /**
|
|
658 * Returns a rectangle describing the receiver's size and location
|
|
659 * relative to its parent (or its display if its parent is null),
|
|
660 * unless the receiver is a shell. In this case, the location is
|
|
661 * relative to the display.
|
|
662 *
|
|
663 * @return the receiver's bounding rectangle
|
|
664 *
|
|
665 * @exception SWTException <ul>
|
|
666 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
667 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
668 * </ul>
|
|
669 */
|
|
670 public Rectangle getBounds () {
|
|
671 checkWidget();
|
|
672 auto topHandle_ = topHandle ();
|
|
673 int x = OS.GTK_WIDGET_X (topHandle_);
|
|
674 int y = OS.GTK_WIDGET_Y (topHandle_);
|
|
675 int width = (state & ZERO_WIDTH) !is 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
676 int height = (state & ZERO_HEIGHT) !is 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle_);
|
|
677 if ((parent.style & SWT.MIRRORED) !is 0) x = parent.getClientWidth () - width - x;
|
|
678 return new Rectangle (x, y, width, height);
|
|
679 }
|
|
680
|
|
681 /**
|
|
682 * Sets the receiver's size and location to the rectangular
|
|
683 * area specified by the argument. The <code>x</code> and
|
|
684 * <code>y</code> fields of the rectangle are relative to
|
|
685 * the receiver's parent (or its display if its parent is null).
|
|
686 * <p>
|
|
687 * Note: Attempting to set the width or height of the
|
|
688 * receiver to a negative number will cause that
|
|
689 * value to be set to zero instead.
|
|
690 * </p>
|
|
691 *
|
|
692 * @param rect the new bounds for the receiver
|
|
693 *
|
|
694 * @exception SWTException <ul>
|
|
695 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
696 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
697 * </ul>
|
|
698 */
|
|
699 public void setBounds (Rectangle rect) {
|
|
700 checkWidget ();
|
|
701 if (rect is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
702 setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true);
|
|
703 }
|
|
704
|
|
705 /**
|
|
706 * Sets the receiver's size and location to the rectangular
|
|
707 * area specified by the arguments. The <code>x</code> and
|
|
708 * <code>y</code> arguments are relative to the receiver's
|
|
709 * parent (or its display if its parent is null), unless
|
|
710 * the receiver is a shell. In this case, the <code>x</code>
|
|
711 * and <code>y</code> arguments are relative to the display.
|
|
712 * <p>
|
|
713 * Note: Attempting to set the width or height of the
|
|
714 * receiver to a negative number will cause that
|
|
715 * value to be set to zero instead.
|
|
716 * </p>
|
|
717 *
|
|
718 * @param x the new x coordinate for the receiver
|
|
719 * @param y the new y coordinate for the receiver
|
|
720 * @param width the new width for the receiver
|
|
721 * @param height the new height for the receiver
|
|
722 *
|
|
723 * @exception SWTException <ul>
|
|
724 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
725 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
726 * </ul>
|
|
727 */
|
|
728 public void setBounds (int x, int y, int width, int height) {
|
|
729 checkWidget();
|
|
730 setBounds (x, y, Math.max (0, width), Math.max (0, height), true, true);
|
|
731 }
|
|
732
|
|
733 void markLayout (bool changed, bool all) {
|
|
734 /* Do nothing */
|
|
735 }
|
|
736
|
|
737 override void modifyStyle (GtkWidget* handle, GtkRcStyle* style) {
|
|
738 super.modifyStyle(handle, style);
|
|
739 /*
|
|
740 * Bug in GTK. When changing the style of a control that
|
|
741 * has had a region set on it, the region is lost. The
|
|
742 * fix is to set the region again.
|
|
743 */
|
|
744 if (region !is null) OS.gdk_window_shape_combine_region (OS.GTK_WIDGET_WINDOW (topHandle ()), region.handle, 0, 0);
|
|
745 }
|
|
746
|
|
747 void moveHandle (int x, int y) {
|
|
748 auto topHandle_ = topHandle ();
|
|
749 auto parentHandle = parent.parentingHandle ();
|
|
750 /*
|
|
751 * Feature in GTK. Calling gtk_fixed_move() to move a child causes
|
|
752 * the whole parent to redraw. This is a performance problem. The
|
|
753 * fix is temporarily make the parent not visible during the move.
|
|
754 *
|
|
755 * NOTE: Because every widget in SWT has an X window, the new and
|
|
756 * old bounds of the child are correctly redrawn.
|
|
757 */
|
|
758 int flags = OS.GTK_WIDGET_FLAGS (parentHandle);
|
|
759 OS.GTK_WIDGET_UNSET_FLAGS (parentHandle, OS.GTK_VISIBLE);
|
|
760 OS.gtk_fixed_move (cast(GtkFixed*)parentHandle, topHandle_, x, y);
|
|
761 if ((flags & OS.GTK_VISIBLE) !is 0) {
|
|
762 OS.GTK_WIDGET_SET_FLAGS (parentHandle, OS.GTK_VISIBLE);
|
|
763 }
|
|
764 }
|
|
765
|
|
766 void resizeHandle (int width, int height) {
|
|
767 auto topHandle_ = topHandle ();
|
|
768 OS.gtk_widget_set_size_request (topHandle_, width, height);
|
|
769 if (topHandle_ !is handle) OS.gtk_widget_set_size_request (handle, width, height);
|
|
770 }
|
|
771
|
|
772 int setBounds (int x, int y, int width, int height, bool move, bool resize) {
|
|
773 auto topHandle_ = topHandle ();
|
|
774 bool sendMove = move;
|
|
775 if ((parent.style & SWT.MIRRORED) !is 0) {
|
|
776 int clientWidth = parent.getClientWidth ();
|
|
777 int oldWidth = (state & ZERO_WIDTH) !is 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
778 int oldX = clientWidth - oldWidth - OS.GTK_WIDGET_X (topHandle_);
|
|
779 if (move) {
|
|
780 sendMove &= x !is oldX;
|
|
781 x = clientWidth - (resize ? width : oldWidth) - x;
|
|
782 } else {
|
|
783 move = true;
|
|
784 x = clientWidth - (resize ? width : oldWidth) - oldX;
|
|
785 y = OS.GTK_WIDGET_Y (topHandle_);
|
|
786 }
|
|
787 }
|
|
788 bool sameOrigin = true, sameExtent = true;
|
|
789 if (move) {
|
|
790 int oldX = OS.GTK_WIDGET_X (topHandle_);
|
|
791 int oldY = OS.GTK_WIDGET_Y (topHandle_);
|
|
792 sameOrigin = x is oldX && y is oldY;
|
|
793 if (!sameOrigin) {
|
|
794 if (enableWindow !is null) {
|
|
795 OS.gdk_window_move (enableWindow, x, y);
|
|
796 }
|
|
797 moveHandle (x, y);
|
|
798 }
|
|
799 }
|
|
800 int clientWidth = 0;
|
|
801 if (resize) {
|
|
802 int oldWidth = (state & ZERO_WIDTH) !is 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
803 int oldHeight = (state & ZERO_HEIGHT) !is 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle_);
|
|
804 sameExtent = width is oldWidth && height is oldHeight;
|
|
805 if (!sameExtent && (style & SWT.MIRRORED) !is 0) clientWidth = getClientWidth ();
|
|
806 if (!sameExtent && !(width is 0 && height is 0)) {
|
|
807 int newWidth = Math.max (1, width);
|
|
808 int newHeight = Math.max (1, height);
|
|
809 if (redrawWindow !is null) {
|
|
810 OS.gdk_window_resize (redrawWindow, newWidth, newHeight);
|
|
811 }
|
|
812 if (enableWindow !is null) {
|
|
813 OS.gdk_window_resize (enableWindow, newWidth, newHeight);
|
|
814 }
|
|
815 resizeHandle (newWidth, newHeight);
|
|
816 }
|
|
817 }
|
|
818 if (!sameOrigin || !sameExtent) {
|
|
819 /*
|
|
820 * Cause a size allocation this widget's topHandle. Note that
|
|
821 * all calls to gtk_widget_size_allocate() must be preceded by
|
|
822 * a call to gtk_widget_size_request().
|
|
823 */
|
|
824 GtkRequisition requisition;
|
|
825 gtk_widget_size_request (topHandle_, &requisition);
|
|
826 GtkAllocation allocation;
|
|
827 if (move) {
|
|
828 allocation.x = x;
|
|
829 allocation.y = y;
|
|
830 } else {
|
|
831 allocation.x = OS.GTK_WIDGET_X (topHandle_);
|
|
832 allocation.y = OS.GTK_WIDGET_Y (topHandle_);
|
|
833 }
|
|
834 if (resize) {
|
|
835 allocation.width = width;
|
|
836 allocation.height = height;
|
|
837 } else {
|
|
838 allocation.width = OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
839 allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle_);
|
|
840 }
|
|
841 OS.gtk_widget_size_allocate (topHandle_, &allocation);
|
|
842 }
|
|
843 /*
|
|
844 * Bug in GTK. Widgets cannot be sized smaller than 1x1.
|
|
845 * The fix is to hide zero-sized widgets and show them again
|
|
846 * when they are resized larger.
|
|
847 */
|
|
848 if (!sameExtent) {
|
|
849 state = (width is 0) ? state | ZERO_WIDTH : state & ~ZERO_WIDTH;
|
|
850 state = (height is 0) ? state | ZERO_HEIGHT : state & ~ZERO_HEIGHT;
|
|
851 if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) !is 0) {
|
|
852 if (enableWindow !is null) {
|
|
853 OS.gdk_window_hide (enableWindow);
|
|
854 }
|
|
855 OS.gtk_widget_hide (topHandle_);
|
|
856 } else {
|
|
857 if ((state & HIDDEN) is 0) {
|
|
858 if (enableWindow !is null) {
|
|
859 OS.gdk_window_show_unraised (enableWindow);
|
|
860 }
|
|
861 OS.gtk_widget_show (topHandle_);
|
|
862 }
|
|
863 }
|
|
864 if ((style & SWT.MIRRORED) !is 0) moveChildren (clientWidth);
|
|
865 }
|
|
866 int result = 0;
|
|
867 if (move && !sameOrigin) {
|
|
868 Control control = findBackgroundControl ();
|
|
869 if (control !is null && control.backgroundImage !is null) {
|
|
870 if (isVisible ()) redrawWidget (0, 0, 0, 0, true, true, true);
|
|
871 }
|
|
872 if (sendMove) sendEvent (SWT.Move);
|
|
873 result |= MOVED;
|
|
874 }
|
|
875 if (resize && !sameExtent) {
|
|
876 sendEvent (SWT.Resize);
|
|
877 result |= RESIZED;
|
|
878 }
|
|
879 return result;
|
|
880 }
|
|
881
|
|
882 /**
|
|
883 * Returns a point describing the receiver's location relative
|
|
884 * to its parent (or its display if its parent is null), unless
|
|
885 * the receiver is a shell. In this case, the point is
|
|
886 * relative to the display.
|
|
887 *
|
|
888 * @return the receiver's location
|
|
889 *
|
|
890 * @exception SWTException <ul>
|
|
891 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
892 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
893 * </ul>
|
|
894 */
|
|
895 public Point getLocation () {
|
|
896 checkWidget();
|
|
897 auto topHandle_ = topHandle ();
|
|
898 int x = OS.GTK_WIDGET_X (topHandle_);
|
|
899 int y = OS.GTK_WIDGET_Y (topHandle_);
|
|
900 if ((parent.style & SWT.MIRRORED) !is 0) {
|
|
901 int width = (state & ZERO_WIDTH) !is 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
902 x = parent.getClientWidth () - width - x;
|
|
903 }
|
|
904 return new Point (x, y);
|
|
905 }
|
|
906
|
|
907 /**
|
|
908 * Sets the receiver's location to the point specified by
|
|
909 * the arguments which are relative to the receiver's
|
|
910 * parent (or its display if its parent is null), unless
|
|
911 * the receiver is a shell. In this case, the point is
|
|
912 * relative to the display.
|
|
913 *
|
|
914 * @param location the new location for the receiver
|
|
915 *
|
|
916 * @exception SWTException <ul>
|
|
917 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
918 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
919 * </ul>
|
|
920 */
|
|
921 public void setLocation (Point location) {
|
|
922 checkWidget ();
|
|
923 if (location is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
924 setBounds (location.x, location.y, 0, 0, true, false);
|
|
925 }
|
|
926
|
|
927 /**
|
|
928 * Sets the receiver's location to the point specified by
|
|
929 * the arguments which are relative to the receiver's
|
|
930 * parent (or its display if its parent is null), unless
|
|
931 * the receiver is a shell. In this case, the point is
|
|
932 * relative to the display.
|
|
933 *
|
|
934 * @param x the new x coordinate for the receiver
|
|
935 * @param y the new y coordinate for the receiver
|
|
936 *
|
|
937 * @exception SWTException <ul>
|
|
938 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
939 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
940 * </ul>
|
|
941 */
|
|
942 public void setLocation(int x, int y) {
|
|
943 checkWidget();
|
|
944 setBounds (x, y, 0, 0, true, false);
|
|
945 }
|
|
946
|
|
947 /**
|
|
948 * Returns a point describing the receiver's size. The
|
|
949 * x coordinate of the result is the width of the receiver.
|
|
950 * The y coordinate of the result is the height of the
|
|
951 * receiver.
|
|
952 *
|
|
953 * @return the receiver's size
|
|
954 *
|
|
955 * @exception SWTException <ul>
|
|
956 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
957 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
958 * </ul>
|
|
959 */
|
|
960 public Point getSize () {
|
|
961 checkWidget();
|
|
962 auto topHandle_ = topHandle ();
|
|
963 int width = (state & ZERO_WIDTH) !is 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
964 int height = (state & ZERO_HEIGHT) !is 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle_);
|
|
965 return new Point (width, height);
|
|
966 }
|
|
967
|
|
968 /**
|
|
969 * Sets the receiver's size to the point specified by the argument.
|
|
970 * <p>
|
|
971 * Note: Attempting to set the width or height of the
|
|
972 * receiver to a negative number will cause them to be
|
|
973 * set to zero instead.
|
|
974 * </p>
|
|
975 *
|
|
976 * @param size the new size for the receiver
|
|
977 *
|
|
978 * @exception IllegalArgumentException <ul>
|
|
979 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
|
|
980 * </ul>
|
|
981 * @exception SWTException <ul>
|
|
982 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
983 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
984 * </ul>
|
|
985 */
|
|
986 public void setSize (Point size) {
|
|
987 checkWidget ();
|
|
988 if (size is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
989 setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true);
|
|
990 }
|
|
991
|
|
992 /**
|
|
993 * Sets the shape of the control to the region specified
|
|
994 * by the argument. When the argument is null, the
|
|
995 * default shape of the control is restored.
|
|
996 *
|
|
997 * @param region the region that defines the shape of the control (or null)
|
|
998 *
|
|
999 * @exception IllegalArgumentException <ul>
|
|
1000 * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
|
|
1001 * </ul>
|
|
1002 * @exception SWTException <ul>
|
|
1003 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1004 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1005 * </ul>
|
|
1006 *
|
|
1007 * @since 3.4
|
|
1008 */
|
|
1009 public void setRegion (Region region) {
|
|
1010 checkWidget ();
|
|
1011 if (region !is null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
1012 auto window = OS.GTK_WIDGET_WINDOW (topHandle ());
|
|
1013 auto shape_region = (region is null) ? null : region.handle;
|
|
1014 OS.gdk_window_shape_combine_region (window, shape_region, 0, 0);
|
|
1015 this.region = region;
|
|
1016 }
|
|
1017
|
|
1018 void setRelations () {
|
|
1019 auto parentHandle = parent.parentingHandle ();
|
|
1020 auto list = OS.gtk_container_get_children (cast(GtkContainer*)parentHandle);
|
|
1021 if (list is null) return;
|
|
1022 int count = OS.g_list_length (list);
|
|
1023 if (count > 1) {
|
|
1024 /*
|
|
1025 * the receiver is the last item in the list, so its predecessor will
|
|
1026 * be the second-last item in the list
|
|
1027 */
|
|
1028 auto handle = cast(GtkWidget*) OS.g_list_nth_data (list, count - 2);
|
|
1029 if (handle !is null) {
|
|
1030 Widget widget = display.getWidget (handle);
|
|
1031 if (widget !is null && widget !is this) {
|
|
1032 if (auto sibling = cast(Control)widget ) {
|
|
1033 sibling.addRelation (this);
|
|
1034 }
|
|
1035 }
|
|
1036 }
|
|
1037 }
|
|
1038 OS.g_list_free (list);
|
|
1039 }
|
|
1040
|
|
1041 /**
|
|
1042 * Sets the receiver's size to the point specified by the arguments.
|
|
1043 * <p>
|
|
1044 * Note: Attempting to set the width or height of the
|
|
1045 * receiver to a negative number will cause that
|
|
1046 * value to be set to zero instead.
|
|
1047 * </p>
|
|
1048 *
|
|
1049 * @param width the new width for the receiver
|
|
1050 * @param height the new height for the receiver
|
|
1051 *
|
|
1052 * @exception SWTException <ul>
|
|
1053 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1054 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1055 * </ul>
|
|
1056 */
|
|
1057 public void setSize (int width, int height) {
|
|
1058 checkWidget();
|
|
1059 setBounds (0, 0, Math.max (0, width), Math.max (0, height), false, true);
|
|
1060 }
|
|
1061
|
|
1062 /*
|
|
1063 * Answers a bool indicating whether a Label that precedes the receiver in
|
|
1064 * a layout should be read by screen readers as the recevier's label.
|
|
1065 */
|
|
1066 bool isDescribedByLabel () {
|
|
1067 return true;
|
|
1068 }
|
|
1069
|
|
1070 bool isFocusHandle (GtkWidget* widget) {
|
|
1071 return widget is focusHandle ();
|
|
1072 }
|
|
1073
|
|
1074 /**
|
|
1075 * Moves the receiver above the specified control in the
|
|
1076 * drawing order. If the argument is null, then the receiver
|
|
1077 * is moved to the top of the drawing order. The control at
|
|
1078 * the top of the drawing order will not be covered by other
|
|
1079 * controls even if they occupy intersecting areas.
|
|
1080 *
|
|
1081 * @param control the sibling control (or null)
|
|
1082 *
|
|
1083 * @exception IllegalArgumentException <ul>
|
|
1084 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
|
|
1085 * </ul>
|
|
1086 * @exception SWTException <ul>
|
|
1087 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1088 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1089 * </ul>
|
|
1090 *
|
|
1091 * @see Control#moveBelow
|
|
1092 * @see Composite#getChildren
|
|
1093 */
|
|
1094 public void moveAbove (Control control) {
|
|
1095 checkWidget();
|
|
1096 if (control !is null) {
|
|
1097 if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
1098 if (parent !is control.parent) return;
|
|
1099 }
|
|
1100 setZOrder (control, true, true);
|
|
1101 }
|
|
1102
|
|
1103 /**
|
|
1104 * Moves the receiver below the specified control in the
|
|
1105 * drawing order. If the argument is null, then the receiver
|
|
1106 * is moved to the bottom of the drawing order. The control at
|
|
1107 * the bottom of the drawing order will be covered by all other
|
|
1108 * controls which occupy intersecting areas.
|
|
1109 *
|
|
1110 * @param control the sibling control (or null)
|
|
1111 *
|
|
1112 * @exception IllegalArgumentException <ul>
|
|
1113 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
|
|
1114 * </ul>
|
|
1115 * @exception SWTException <ul>
|
|
1116 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1117 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1118 * </ul>
|
|
1119 *
|
|
1120 * @see Control#moveAbove
|
|
1121 * @see Composite#getChildren
|
|
1122 */
|
|
1123 public void moveBelow (Control control) {
|
|
1124 checkWidget();
|
|
1125 if (control !is null) {
|
|
1126 if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
|
|
1127 if (parent !is control.parent) return;
|
|
1128 }
|
|
1129 setZOrder (control, false, true);
|
|
1130 }
|
|
1131
|
|
1132 void moveChildren (int oldWidth) {
|
|
1133 }
|
|
1134
|
|
1135 /**
|
|
1136 * Causes the receiver to be resized to its preferred size.
|
|
1137 * For a composite, this involves computing the preferred size
|
|
1138 * from its layout, if there is one.
|
|
1139 *
|
|
1140 * @exception SWTException <ul>
|
|
1141 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1142 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1143 * </ul>
|
|
1144 *
|
|
1145 * @see #computeSize(int, int, bool)
|
|
1146 */
|
|
1147 public void pack () {
|
|
1148 pack (true);
|
|
1149 }
|
|
1150
|
|
1151 /**
|
|
1152 * Causes the receiver to be resized to its preferred size.
|
|
1153 * For a composite, this involves computing the preferred size
|
|
1154 * from its layout, if there is one.
|
|
1155 * <p>
|
|
1156 * If the changed flag is <code>true</code>, it indicates that the receiver's
|
|
1157 * <em>contents</em> have changed, therefore any caches that a layout manager
|
|
1158 * containing the control may have been keeping need to be flushed. When the
|
|
1159 * control is resized, the changed flag will be <code>false</code>, so layout
|
|
1160 * manager caches can be retained.
|
|
1161 * </p>
|
|
1162 *
|
|
1163 * @param changed whether or not the receiver's contents have changed
|
|
1164 *
|
|
1165 * @exception SWTException <ul>
|
|
1166 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1167 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1168 * </ul>
|
|
1169 *
|
|
1170 * @see #computeSize(int, int, bool)
|
|
1171 */
|
|
1172 public void pack (bool changed) {
|
|
1173 setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
|
|
1174 }
|
|
1175
|
|
1176 /**
|
|
1177 * Sets the layout data associated with the receiver to the argument.
|
|
1178 *
|
|
1179 * @param layoutData the new layout data for the receiver.
|
|
1180 *
|
|
1181 * @exception SWTException <ul>
|
|
1182 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1183 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1184 * </ul>
|
|
1185 */
|
|
1186 public void setLayoutData (Object layoutData) {
|
|
1187 checkWidget();
|
|
1188 this.layoutData = layoutData;
|
|
1189 }
|
|
1190
|
|
1191 /**
|
|
1192 * Returns a point which is the result of converting the
|
|
1193 * argument, which is specified in display relative coordinates,
|
|
1194 * to coordinates relative to the receiver.
|
|
1195 * <p>
|
|
1196 * @param x the x coordinate to be translated
|
|
1197 * @param y the y coordinate to be translated
|
|
1198 * @return the translated coordinates
|
|
1199 *
|
|
1200 * @exception SWTException <ul>
|
|
1201 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1202 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1203 * </ul>
|
|
1204 *
|
|
1205 * @since 2.1
|
|
1206 */
|
|
1207 public Point toControl (int x, int y) {
|
|
1208 checkWidget ();
|
|
1209 auto window = eventWindow ();
|
|
1210 int origin_x, origin_y;
|
|
1211 OS.gdk_window_get_origin (window, &origin_x, &origin_y);
|
|
1212 x -= origin_x ;
|
|
1213 y -= origin_y ;
|
|
1214 if ((style & SWT.MIRRORED) !is 0) x = getClientWidth () - x;
|
|
1215 return new Point (x, y);
|
|
1216 }
|
|
1217
|
|
1218 /**
|
|
1219 * Returns a point which is the result of converting the
|
|
1220 * argument, which is specified in display relative coordinates,
|
|
1221 * to coordinates relative to the receiver.
|
|
1222 * <p>
|
|
1223 * @param point the point to be translated (must not be null)
|
|
1224 * @return the translated coordinates
|
|
1225 *
|
|
1226 * @exception IllegalArgumentException <ul>
|
|
1227 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
|
|
1228 * </ul>
|
|
1229 * @exception SWTException <ul>
|
|
1230 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1231 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1232 * </ul>
|
|
1233 */
|
|
1234 public Point toControl (Point point) {
|
|
1235 checkWidget ();
|
|
1236 if (point is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1237 return toControl (point.x, point.y);
|
|
1238 }
|
|
1239
|
|
1240 /**
|
|
1241 * Returns a point which is the result of converting the
|
|
1242 * argument, which is specified in coordinates relative to
|
|
1243 * the receiver, to display relative coordinates.
|
|
1244 * <p>
|
|
1245 * @param x the x coordinate to be translated
|
|
1246 * @param y the y coordinate to be translated
|
|
1247 * @return the translated coordinates
|
|
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 * @since 2.1
|
|
1255 */
|
|
1256 public Point toDisplay (int x, int y) {
|
|
1257 checkWidget();
|
|
1258 auto window = eventWindow ();
|
|
1259 int origin_x, origin_y;
|
|
1260 OS.gdk_window_get_origin (window, &origin_x, &origin_y);
|
|
1261 if ((style & SWT.MIRRORED) !is 0) x = getClientWidth () - x;
|
|
1262 x += origin_x ;
|
|
1263 y += origin_y ;
|
|
1264 return new Point (x, y);
|
|
1265 }
|
|
1266
|
|
1267 /**
|
|
1268 * Returns a point which is the result of converting the
|
|
1269 * argument, which is specified in coordinates relative to
|
|
1270 * the receiver, to display relative coordinates.
|
|
1271 * <p>
|
|
1272 * @param point the point to be translated (must not be null)
|
|
1273 * @return the translated coordinates
|
|
1274 *
|
|
1275 * @exception IllegalArgumentException <ul>
|
|
1276 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
|
|
1277 * </ul>
|
|
1278 * @exception SWTException <ul>
|
|
1279 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1280 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1281 * </ul>
|
|
1282 */
|
|
1283 public Point toDisplay (Point point) {
|
|
1284 checkWidget();
|
|
1285 if (point is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1286 return toDisplay (point.x, point.y);
|
|
1287 }
|
|
1288
|
|
1289 /**
|
|
1290 * Adds the listener to the collection of listeners who will
|
|
1291 * be notified when the control is moved or resized, by sending
|
|
1292 * it one of the messages defined in the <code>ControlListener</code>
|
|
1293 * interface.
|
|
1294 *
|
|
1295 * @param listener the listener which should be notified
|
|
1296 *
|
|
1297 * @exception IllegalArgumentException <ul>
|
|
1298 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1299 * </ul>
|
|
1300 * @exception SWTException <ul>
|
|
1301 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1302 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1303 * </ul>
|
|
1304 *
|
|
1305 * @see ControlListener
|
|
1306 * @see #removeControlListener
|
|
1307 */
|
|
1308 public void addControlListener(ControlListener listener) {
|
|
1309 checkWidget();
|
|
1310 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1311 TypedListener typedListener = new TypedListener (listener);
|
|
1312 addListener (SWT.Resize,typedListener);
|
|
1313 addListener (SWT.Move,typedListener);
|
|
1314 }
|
|
1315
|
|
1316 /**
|
|
1317 * Adds the listener to the collection of listeners who will
|
|
1318 * be notified when a drag gesture occurs, by sending it
|
|
1319 * one of the messages defined in the <code>DragDetectListener</code>
|
|
1320 * interface.
|
|
1321 *
|
|
1322 * @param listener the listener which should be notified
|
|
1323 *
|
|
1324 * @exception IllegalArgumentException <ul>
|
|
1325 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1326 * </ul>
|
|
1327 * @exception SWTException <ul>
|
|
1328 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1329 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1330 * </ul>
|
|
1331 *
|
|
1332 * @see DragDetectListener
|
|
1333 * @see #removeDragDetectListener
|
|
1334 *
|
|
1335 * @since 3.3
|
|
1336 */
|
|
1337 public void addDragDetectListener (DragDetectListener listener) {
|
|
1338 checkWidget ();
|
|
1339 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1340 TypedListener typedListener = new TypedListener (listener);
|
|
1341 addListener (SWT.DragDetect,typedListener);
|
|
1342 }
|
|
1343
|
|
1344 /**
|
|
1345 * Adds the listener to the collection of listeners who will
|
|
1346 * be notified when the control gains or loses focus, by sending
|
|
1347 * it one of the messages defined in the <code>FocusListener</code>
|
|
1348 * interface.
|
|
1349 *
|
|
1350 * @param listener the listener which should be notified
|
|
1351 *
|
|
1352 * @exception IllegalArgumentException <ul>
|
|
1353 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1354 * </ul>
|
|
1355 * @exception SWTException <ul>
|
|
1356 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1357 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1358 * </ul>
|
|
1359 *
|
|
1360 * @see FocusListener
|
|
1361 * @see #removeFocusListener
|
|
1362 */
|
|
1363 public void addFocusListener(FocusListener listener) {
|
|
1364 checkWidget();
|
|
1365 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1366 TypedListener typedListener = new TypedListener (listener);
|
|
1367 addListener(SWT.FocusIn,typedListener);
|
|
1368 addListener(SWT.FocusOut,typedListener);
|
|
1369 }
|
|
1370
|
|
1371 /**
|
|
1372 * Adds the listener to the collection of listeners who will
|
|
1373 * be notified when help events are generated for the control,
|
|
1374 * by sending it one of the messages defined in the
|
|
1375 * <code>HelpListener</code> interface.
|
|
1376 *
|
|
1377 * @param listener the listener which should be notified
|
|
1378 *
|
|
1379 * @exception IllegalArgumentException <ul>
|
|
1380 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1381 * </ul>
|
|
1382 * @exception SWTException <ul>
|
|
1383 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1384 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1385 * </ul>
|
|
1386 *
|
|
1387 * @see HelpListener
|
|
1388 * @see #removeHelpListener
|
|
1389 */
|
|
1390 public void addHelpListener (HelpListener listener) {
|
|
1391 checkWidget();
|
|
1392 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1393 TypedListener typedListener = new TypedListener (listener);
|
|
1394 addListener (SWT.Help, typedListener);
|
|
1395 }
|
|
1396
|
|
1397 /**
|
|
1398 * Adds the listener to the collection of listeners who will
|
|
1399 * be notified when keys are pressed and released on the system keyboard, by sending
|
|
1400 * it one of the messages defined in the <code>KeyListener</code>
|
|
1401 * interface.
|
|
1402 * <p>
|
|
1403 * When a key listener is added to a control, the control
|
|
1404 * will take part in widget traversal. By default, all
|
|
1405 * traversal keys (such as the tab key and so on) are
|
|
1406 * delivered to the control. In order for a control to take
|
|
1407 * part in traversal, it should listen for traversal events.
|
|
1408 * Otherwise, the user can traverse into a control but not
|
|
1409 * out. Note that native controls such as table and tree
|
|
1410 * implement key traversal in the operating system. It is
|
|
1411 * not necessary to add traversal listeners for these controls,
|
|
1412 * unless you want to override the default traversal.
|
|
1413 * </p>
|
|
1414 * @param listener the listener which should be notified
|
|
1415 *
|
|
1416 * @exception IllegalArgumentException <ul>
|
|
1417 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1418 * </ul>
|
|
1419 * @exception SWTException <ul>
|
|
1420 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1421 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1422 * </ul>
|
|
1423 *
|
|
1424 * @see KeyListener
|
|
1425 * @see #removeKeyListener
|
|
1426 */
|
|
1427 public void addKeyListener(KeyListener listener) {
|
|
1428 checkWidget();
|
|
1429 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1430 TypedListener typedListener = new TypedListener (listener);
|
|
1431 addListener(SWT.KeyUp,typedListener);
|
|
1432 addListener(SWT.KeyDown,typedListener);
|
|
1433 }
|
|
1434
|
|
1435 /**
|
|
1436 * Adds the listener to the collection of listeners who will
|
|
1437 * be notified when the platform-specific context menu trigger
|
|
1438 * has occurred, by sending it one of the messages defined in
|
|
1439 * the <code>MenuDetectListener</code> interface.
|
|
1440 *
|
|
1441 * @param listener the listener which should be notified
|
|
1442 *
|
|
1443 * @exception IllegalArgumentException <ul>
|
|
1444 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1445 * </ul>
|
|
1446 * @exception SWTException <ul>
|
|
1447 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1448 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1449 * </ul>
|
|
1450 *
|
|
1451 * @see MenuDetectListener
|
|
1452 * @see #removeMenuDetectListener
|
|
1453 *
|
|
1454 * @since 3.3
|
|
1455 */
|
|
1456 public void addMenuDetectListener (MenuDetectListener listener) {
|
|
1457 checkWidget ();
|
|
1458 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1459 TypedListener typedListener = new TypedListener (listener);
|
|
1460 addListener (SWT.MenuDetect, typedListener);
|
|
1461 }
|
|
1462
|
|
1463 /**
|
|
1464 * Adds the listener to the collection of listeners who will
|
|
1465 * be notified when mouse buttons are pressed and released, by sending
|
|
1466 * it one of the messages defined in the <code>MouseListener</code>
|
|
1467 * interface.
|
|
1468 *
|
|
1469 * @param listener the listener which should be notified
|
|
1470 *
|
|
1471 * @exception IllegalArgumentException <ul>
|
|
1472 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1473 * </ul>
|
|
1474 * @exception SWTException <ul>
|
|
1475 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1476 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1477 * </ul>
|
|
1478 *
|
|
1479 * @see MouseListener
|
|
1480 * @see #removeMouseListener
|
|
1481 */
|
|
1482 public void addMouseListener(MouseListener listener) {
|
|
1483 checkWidget();
|
|
1484 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1485 TypedListener typedListener = new TypedListener (listener);
|
|
1486 addListener(SWT.MouseDown,typedListener);
|
|
1487 addListener(SWT.MouseUp,typedListener);
|
|
1488 addListener(SWT.MouseDoubleClick,typedListener);
|
|
1489 }
|
|
1490
|
|
1491 /**
|
|
1492 * Adds the listener to the collection of listeners who will
|
|
1493 * be notified when the mouse moves, by sending it one of the
|
|
1494 * messages defined in the <code>MouseMoveListener</code>
|
|
1495 * interface.
|
|
1496 *
|
|
1497 * @param listener the listener which should be notified
|
|
1498 *
|
|
1499 * @exception IllegalArgumentException <ul>
|
|
1500 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1501 * </ul>
|
|
1502 * @exception SWTException <ul>
|
|
1503 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1504 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1505 * </ul>
|
|
1506 *
|
|
1507 * @see MouseMoveListener
|
|
1508 * @see #removeMouseMoveListener
|
|
1509 */
|
|
1510 public void addMouseMoveListener(MouseMoveListener listener) {
|
|
1511 checkWidget();
|
|
1512 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1513 TypedListener typedListener = new TypedListener (listener);
|
|
1514 addListener(SWT.MouseMove,typedListener);
|
|
1515 }
|
|
1516
|
|
1517 /**
|
|
1518 * Adds the listener to the collection of listeners who will
|
|
1519 * be notified when the mouse passes or hovers over controls, by sending
|
|
1520 * it one of the messages defined in the <code>MouseTrackListener</code>
|
|
1521 * interface.
|
|
1522 *
|
|
1523 * @param listener the listener which should be notified
|
|
1524 *
|
|
1525 * @exception IllegalArgumentException <ul>
|
|
1526 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1527 * </ul>
|
|
1528 * @exception SWTException <ul>
|
|
1529 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1530 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1531 * </ul>
|
|
1532 *
|
|
1533 * @see MouseTrackListener
|
|
1534 * @see #removeMouseTrackListener
|
|
1535 */
|
|
1536 public void addMouseTrackListener (MouseTrackListener listener) {
|
|
1537 checkWidget();
|
|
1538 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1539 TypedListener typedListener = new TypedListener (listener);
|
|
1540 addListener (SWT.MouseEnter,typedListener);
|
|
1541 addListener (SWT.MouseExit,typedListener);
|
|
1542 addListener (SWT.MouseHover,typedListener);
|
|
1543 }
|
|
1544
|
|
1545 /**
|
|
1546 * Adds the listener to the collection of listeners who will
|
|
1547 * be notified when the mouse wheel is scrolled, by sending
|
|
1548 * it one of the messages defined in the
|
|
1549 * <code>MouseWheelListener</code> interface.
|
|
1550 *
|
|
1551 * @param listener the listener which should be notified
|
|
1552 *
|
|
1553 * @exception IllegalArgumentException <ul>
|
|
1554 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1555 * </ul>
|
|
1556 * @exception SWTException <ul>
|
|
1557 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1558 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1559 * </ul>
|
|
1560 *
|
|
1561 * @see MouseWheelListener
|
|
1562 * @see #removeMouseWheelListener
|
|
1563 *
|
|
1564 * @since 3.3
|
|
1565 */
|
|
1566 public void addMouseWheelListener (MouseWheelListener listener) {
|
|
1567 checkWidget ();
|
|
1568 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1569 TypedListener typedListener = new TypedListener (listener);
|
|
1570 addListener (SWT.MouseWheel, typedListener);
|
|
1571 }
|
|
1572
|
|
1573 /**
|
|
1574 * Adds the listener to the collection of listeners who will
|
|
1575 * be notified when the receiver needs to be painted, by sending it
|
|
1576 * one of the messages defined in the <code>PaintListener</code>
|
|
1577 * interface.
|
|
1578 *
|
|
1579 * @param listener the listener which should be notified
|
|
1580 *
|
|
1581 * @exception IllegalArgumentException <ul>
|
|
1582 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1583 * </ul>
|
|
1584 * @exception SWTException <ul>
|
|
1585 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1586 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1587 * </ul>
|
|
1588 *
|
|
1589 * @see PaintListener
|
|
1590 * @see #removePaintListener
|
|
1591 */
|
|
1592 public void addPaintListener(PaintListener listener) {
|
|
1593 checkWidget();
|
|
1594 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1595 TypedListener typedListener = new TypedListener (listener);
|
|
1596 addListener(SWT.Paint,typedListener);
|
|
1597 }
|
|
1598
|
|
1599 void addRelation (Control control) {
|
|
1600 }
|
|
1601
|
|
1602 /**
|
|
1603 * Adds the listener to the collection of listeners who will
|
|
1604 * be notified when traversal events occur, by sending it
|
|
1605 * one of the messages defined in the <code>TraverseListener</code>
|
|
1606 * interface.
|
|
1607 *
|
|
1608 * @param listener the listener which should be notified
|
|
1609 *
|
|
1610 * @exception IllegalArgumentException <ul>
|
|
1611 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1612 * </ul>
|
|
1613 * @exception SWTException <ul>
|
|
1614 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1615 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1616 * </ul>
|
|
1617 *
|
|
1618 * @see TraverseListener
|
|
1619 * @see #removeTraverseListener
|
|
1620 */
|
|
1621 public void addTraverseListener (TraverseListener listener) {
|
|
1622 checkWidget();
|
|
1623 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1624 TypedListener typedListener = new TypedListener (listener);
|
|
1625 addListener (SWT.Traverse,typedListener);
|
|
1626 }
|
|
1627
|
|
1628 /**
|
|
1629 * Removes the listener from the collection of listeners who will
|
|
1630 * be notified when the control is moved or resized.
|
|
1631 *
|
|
1632 * @param listener the listener which should no longer be notified
|
|
1633 *
|
|
1634 * @exception IllegalArgumentException <ul>
|
|
1635 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1636 * </ul>
|
|
1637 * @exception SWTException <ul>
|
|
1638 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1639 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1640 * </ul>
|
|
1641 *
|
|
1642 * @see ControlListener
|
|
1643 * @see #addControlListener
|
|
1644 */
|
|
1645 public void removeControlListener (ControlListener listener) {
|
|
1646 checkWidget();
|
|
1647 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1648 if (eventTable is null) return;
|
|
1649 eventTable.unhook (SWT.Move, listener);
|
|
1650 eventTable.unhook (SWT.Resize, listener);
|
|
1651 }
|
|
1652
|
|
1653 /**
|
|
1654 * Removes the listener from the collection of listeners who will
|
|
1655 * be notified when a drag gesture occurs.
|
|
1656 *
|
|
1657 * @param listener the listener which should no longer be notified
|
|
1658 *
|
|
1659 * @exception IllegalArgumentException <ul>
|
|
1660 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1661 * </ul>
|
|
1662 * @exception SWTException <ul>
|
|
1663 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1664 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1665 * </ul>
|
|
1666 *
|
|
1667 * @see DragDetectListener
|
|
1668 * @see #addDragDetectListener
|
|
1669 *
|
|
1670 * @since 3.3
|
|
1671 */
|
|
1672 public void removeDragDetectListener(DragDetectListener listener) {
|
|
1673 checkWidget ();
|
|
1674 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1675 if (eventTable is null) return;
|
|
1676 eventTable.unhook (SWT.DragDetect, listener);
|
|
1677 }
|
|
1678
|
|
1679 /**
|
|
1680 * Removes the listener from the collection of listeners who will
|
|
1681 * be notified when the control gains or loses focus.
|
|
1682 *
|
|
1683 * @param listener the listener which should no longer be notified
|
|
1684 *
|
|
1685 * @exception IllegalArgumentException <ul>
|
|
1686 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1687 * </ul>
|
|
1688 * @exception SWTException <ul>
|
|
1689 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1690 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1691 * </ul>
|
|
1692 *
|
|
1693 * @see FocusListener
|
|
1694 * @see #addFocusListener
|
|
1695 */
|
|
1696 public void removeFocusListener(FocusListener listener) {
|
|
1697 checkWidget();
|
|
1698 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1699 if (eventTable is null) return;
|
|
1700 eventTable.unhook (SWT.FocusIn, listener);
|
|
1701 eventTable.unhook (SWT.FocusOut, listener);
|
|
1702 }
|
|
1703 /**
|
|
1704 * Removes the listener from the collection of listeners who will
|
|
1705 * be notified when the help events are generated for the control.
|
|
1706 *
|
|
1707 * @param listener the listener which should no longer be notified
|
|
1708 *
|
|
1709 * @exception IllegalArgumentException <ul>
|
|
1710 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1711 * </ul>
|
|
1712 * @exception SWTException <ul>
|
|
1713 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1714 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1715 * </ul>
|
|
1716 *
|
|
1717 * @see HelpListener
|
|
1718 * @see #addHelpListener
|
|
1719 */
|
|
1720 public void removeHelpListener (HelpListener listener) {
|
|
1721 checkWidget();
|
|
1722 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1723 if (eventTable is null) return;
|
|
1724 eventTable.unhook (SWT.Help, listener);
|
|
1725 }
|
|
1726 /**
|
|
1727 * Removes the listener from the collection of listeners who will
|
|
1728 * be notified when keys are pressed and released on the system keyboard.
|
|
1729 *
|
|
1730 * @param listener the listener which should no longer be notified
|
|
1731 *
|
|
1732 * @exception IllegalArgumentException <ul>
|
|
1733 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1734 * </ul>
|
|
1735 * @exception SWTException <ul>
|
|
1736 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1737 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1738 * </ul>
|
|
1739 *
|
|
1740 * @see KeyListener
|
|
1741 * @see #addKeyListener
|
|
1742 */
|
|
1743 public void removeKeyListener(KeyListener listener) {
|
|
1744 checkWidget();
|
|
1745 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1746 if (eventTable is null) return;
|
|
1747 eventTable.unhook (SWT.KeyUp, listener);
|
|
1748 eventTable.unhook (SWT.KeyDown, listener);
|
|
1749 }
|
|
1750 /**
|
|
1751 * Removes the listener from the collection of listeners who will
|
|
1752 * be notified when the platform-specific context menu trigger has
|
|
1753 * occurred.
|
|
1754 *
|
|
1755 * @param listener the listener which should no longer be notified
|
|
1756 *
|
|
1757 * @exception IllegalArgumentException <ul>
|
|
1758 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1759 * </ul>
|
|
1760 * @exception SWTException <ul>
|
|
1761 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1762 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1763 * </ul>
|
|
1764 *
|
|
1765 * @see MenuDetectListener
|
|
1766 * @see #addMenuDetectListener
|
|
1767 *
|
|
1768 * @since 3.3
|
|
1769 */
|
|
1770 public void removeMenuDetectListener (MenuDetectListener listener) {
|
|
1771 checkWidget ();
|
|
1772 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1773 if (eventTable is null) return;
|
|
1774 eventTable.unhook (SWT.MenuDetect, listener);
|
|
1775 }
|
|
1776 /**
|
|
1777 * Removes the listener from the collection of listeners who will
|
|
1778 * be notified when mouse buttons are pressed and released.
|
|
1779 *
|
|
1780 * @param listener the listener which should no longer be notified
|
|
1781 *
|
|
1782 * @exception IllegalArgumentException <ul>
|
|
1783 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1784 * </ul>
|
|
1785 * @exception SWTException <ul>
|
|
1786 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1787 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1788 * </ul>
|
|
1789 *
|
|
1790 * @see MouseListener
|
|
1791 * @see #addMouseListener
|
|
1792 */
|
|
1793 public void removeMouseListener (MouseListener listener) {
|
|
1794 checkWidget();
|
|
1795 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1796 if (eventTable is null) return;
|
|
1797 eventTable.unhook (SWT.MouseDown, listener);
|
|
1798 eventTable.unhook (SWT.MouseUp, listener);
|
|
1799 eventTable.unhook (SWT.MouseDoubleClick, listener);
|
|
1800 }
|
|
1801 /**
|
|
1802 * Removes the listener from the collection of listeners who will
|
|
1803 * be notified when the mouse moves.
|
|
1804 *
|
|
1805 * @param listener the listener which should no longer be notified
|
|
1806 *
|
|
1807 * @exception IllegalArgumentException <ul>
|
|
1808 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1809 * </ul>
|
|
1810 * @exception SWTException <ul>
|
|
1811 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1812 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1813 * </ul>
|
|
1814 *
|
|
1815 * @see MouseMoveListener
|
|
1816 * @see #addMouseMoveListener
|
|
1817 */
|
|
1818 public void removeMouseMoveListener(MouseMoveListener listener) {
|
|
1819 checkWidget();
|
|
1820 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1821 if (eventTable is null) return;
|
|
1822 eventTable.unhook (SWT.MouseMove, listener);
|
|
1823 }
|
|
1824
|
|
1825 /**
|
|
1826 * Removes the listener from the collection of listeners who will
|
|
1827 * be notified when the mouse passes or hovers over controls.
|
|
1828 *
|
|
1829 * @param listener the listener which should no longer be notified
|
|
1830 *
|
|
1831 * @exception IllegalArgumentException <ul>
|
|
1832 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1833 * </ul>
|
|
1834 * @exception SWTException <ul>
|
|
1835 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1836 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1837 * </ul>
|
|
1838 *
|
|
1839 * @see MouseTrackListener
|
|
1840 * @see #addMouseTrackListener
|
|
1841 */
|
|
1842 public void removeMouseTrackListener(MouseTrackListener listener) {
|
|
1843 checkWidget();
|
|
1844 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1845 if (eventTable is null) return;
|
|
1846 eventTable.unhook (SWT.MouseEnter, listener);
|
|
1847 eventTable.unhook (SWT.MouseExit, listener);
|
|
1848 eventTable.unhook (SWT.MouseHover, listener);
|
|
1849 }
|
|
1850
|
|
1851 /**
|
|
1852 * Removes the listener from the collection of listeners who will
|
|
1853 * be notified when the mouse wheel is scrolled.
|
|
1854 *
|
|
1855 * @param listener the listener which should no longer be notified
|
|
1856 *
|
|
1857 * @exception IllegalArgumentException <ul>
|
|
1858 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1859 * </ul>
|
|
1860 * @exception SWTException <ul>
|
|
1861 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1862 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1863 * </ul>
|
|
1864 *
|
|
1865 * @see MouseWheelListener
|
|
1866 * @see #addMouseWheelListener
|
|
1867 *
|
|
1868 * @since 3.3
|
|
1869 */
|
|
1870 public void removeMouseWheelListener (MouseWheelListener listener) {
|
|
1871 checkWidget ();
|
|
1872 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1873 if (eventTable is null) return;
|
|
1874 eventTable.unhook (SWT.MouseWheel, listener);
|
|
1875 }
|
|
1876
|
|
1877 /**
|
|
1878 * Removes the listener from the collection of listeners who will
|
|
1879 * be notified when the receiver needs to be painted.
|
|
1880 *
|
|
1881 * @param listener the listener which should no longer be notified
|
|
1882 *
|
|
1883 * @exception IllegalArgumentException <ul>
|
|
1884 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1885 * </ul>
|
|
1886 * @exception SWTException <ul>
|
|
1887 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1888 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1889 * </ul>
|
|
1890 *
|
|
1891 * @see PaintListener
|
|
1892 * @see #addPaintListener
|
|
1893 */
|
|
1894 public void removePaintListener(PaintListener listener) {
|
|
1895 checkWidget();
|
|
1896 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1897 if (eventTable is null) return;
|
|
1898 eventTable.unhook(SWT.Paint, listener);
|
|
1899 }
|
|
1900
|
|
1901 /*
|
|
1902 * Remove "Labelled by" relations from the receiver.
|
|
1903 */
|
|
1904 void removeRelation () {
|
|
1905 if (!isDescribedByLabel ()) return; /* there will not be any */
|
|
1906 auto accessible = OS.gtk_widget_get_accessible (handle);
|
|
1907 if (accessible is null) return;
|
|
1908 auto set = ATK.atk_object_ref_relation_set (accessible);
|
|
1909 int count = ATK.atk_relation_set_get_n_relations (set);
|
|
1910 for (int i = 0; i < count; i++) {
|
|
1911 auto relation = ATK.atk_relation_set_get_relation (set, 0);
|
|
1912 ATK.atk_relation_set_remove (set, relation);
|
|
1913 }
|
|
1914 OS.g_object_unref (set);
|
|
1915 }
|
|
1916
|
|
1917 /**
|
|
1918 * Removes the listener from the collection of listeners who will
|
|
1919 * be notified when traversal events occur.
|
|
1920 *
|
|
1921 * @param listener the listener which should no longer be notified
|
|
1922 *
|
|
1923 * @exception IllegalArgumentException <ul>
|
|
1924 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
1925 * </ul>
|
|
1926 * @exception SWTException <ul>
|
|
1927 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1928 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1929 * </ul>
|
|
1930 *
|
|
1931 * @see TraverseListener
|
|
1932 * @see #addTraverseListener
|
|
1933 */
|
|
1934 public void removeTraverseListener(TraverseListener listener) {
|
|
1935 checkWidget ();
|
|
1936 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1937 if (eventTable is null) return;
|
|
1938 eventTable.unhook (SWT.Traverse, listener);
|
|
1939 }
|
|
1940
|
|
1941 /**
|
|
1942 * Detects a drag and drop gesture. This method is used
|
|
1943 * to detect a drag gesture when called from within a mouse
|
|
1944 * down listener.
|
|
1945 *
|
|
1946 * <p>By default, a drag is detected when the gesture
|
|
1947 * occurs anywhere within the client area of a control.
|
|
1948 * Some controls, such as tables and trees, override this
|
|
1949 * behavior. In addition to the operating system specific
|
|
1950 * drag gesture, they require the mouse to be inside an
|
|
1951 * item. Custom widget writers can use <code>setDragDetect</code>
|
|
1952 * to disable the default detection, listen for mouse down,
|
|
1953 * and then call <code>dragDetect()</code> from within the
|
|
1954 * listener to conditionally detect a drag.
|
|
1955 * </p>
|
|
1956 *
|
|
1957 * @param event the mouse down event
|
|
1958 *
|
|
1959 * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
|
|
1960 *
|
|
1961 * @exception IllegalArgumentException <ul>
|
|
1962 * <li>ERROR_NULL_ARGUMENT when the event is null</li>
|
|
1963 * </ul>
|
|
1964 * @exception SWTException <ul>
|
|
1965 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
1966 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
1967 * </ul>
|
|
1968 *
|
|
1969 * @see DragDetectListener
|
|
1970 * @see #addDragDetectListener
|
|
1971 *
|
|
1972 * @see #getDragDetect
|
|
1973 * @see #setDragDetect
|
|
1974 *
|
|
1975 * @since 3.3
|
|
1976 */
|
|
1977 public bool dragDetect (Event event) {
|
|
1978 checkWidget ();
|
|
1979 if (event is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
1980 return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
|
|
1981 }
|
|
1982
|
|
1983 /**
|
|
1984 * Detects a drag and drop gesture. This method is used
|
|
1985 * to detect a drag gesture when called from within a mouse
|
|
1986 * down listener.
|
|
1987 *
|
|
1988 * <p>By default, a drag is detected when the gesture
|
|
1989 * occurs anywhere within the client area of a control.
|
|
1990 * Some controls, such as tables and trees, override this
|
|
1991 * behavior. In addition to the operating system specific
|
|
1992 * drag gesture, they require the mouse to be inside an
|
|
1993 * item. Custom widget writers can use <code>setDragDetect</code>
|
|
1994 * to disable the default detection, listen for mouse down,
|
|
1995 * and then call <code>dragDetect()</code> from within the
|
|
1996 * listener to conditionally detect a drag.
|
|
1997 * </p>
|
|
1998 *
|
|
1999 * @param event the mouse down event
|
|
2000 *
|
|
2001 * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
|
|
2002 *
|
|
2003 * @exception IllegalArgumentException <ul>
|
|
2004 * <li>ERROR_NULL_ARGUMENT when the event is null</li>
|
|
2005 * </ul>
|
|
2006 * @exception SWTException <ul>
|
|
2007 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2008 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2009 * </ul>
|
|
2010 *
|
|
2011 * @see DragDetectListener
|
|
2012 * @see #addDragDetectListener
|
|
2013 *
|
|
2014 * @see #getDragDetect
|
|
2015 * @see #setDragDetect
|
|
2016 *
|
|
2017 * @since 3.3
|
|
2018 */
|
|
2019 public bool dragDetect (MouseEvent event) {
|
|
2020 checkWidget ();
|
|
2021 if (event is null) error (SWT.ERROR_NULL_ARGUMENT);
|
|
2022 return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
|
|
2023 }
|
|
2024
|
|
2025 bool dragDetect (int button, int count, int stateMask, int x, int y) {
|
|
2026 if (button !is 1 || count !is 1) return false;
|
|
2027 if (!dragDetect (x, y, false, null)) return false;
|
|
2028 return sendDragEvent (button, stateMask, x, y, true);
|
|
2029 }
|
|
2030
|
|
2031 bool dragDetect (int x, int y, bool filter, bool* consume) {
|
|
2032 bool quit = false, dragging = false;
|
|
2033 while (!quit) {
|
|
2034 GdkEvent* eventPtr;
|
|
2035 while (true) {
|
|
2036 eventPtr = OS.gdk_event_get ();
|
|
2037 if (eventPtr !is null) {
|
|
2038 break;
|
|
2039 } else {
|
|
2040 try {Thread.sleep(0.050);} catch (Exception ex) {}
|
|
2041 }
|
|
2042 }
|
|
2043 switch (cast(int)OS.GDK_EVENT_TYPE (eventPtr)) {
|
|
2044 case OS.GDK_MOTION_NOTIFY: {
|
|
2045 GdkEventMotion* gdkMotionEvent = cast(GdkEventMotion*)eventPtr;
|
|
2046 if ((gdkMotionEvent.state & OS.GDK_BUTTON1_MASK) !is 0) {
|
|
2047 if (OS.gtk_drag_check_threshold (handle, x, y, cast(int) gdkMotionEvent.x, cast(int) gdkMotionEvent.y)) {
|
|
2048 dragging = true;
|
|
2049 quit = true;
|
|
2050 }
|
|
2051 } else {
|
|
2052 quit = true;
|
|
2053 }
|
|
2054 int newX, newY;
|
|
2055 OS.gdk_window_get_pointer (gdkMotionEvent.window, &newX, &newY, null);
|
|
2056 break;
|
|
2057 }
|
|
2058 case OS.GDK_KEY_PRESS:
|
|
2059 case OS.GDK_KEY_RELEASE: {
|
|
2060 GdkEventKey* gdkEvent = cast(GdkEventKey*)eventPtr;
|
|
2061 if (gdkEvent.keyval is OS.GDK_Escape) quit = true;
|
|
2062 break;
|
|
2063 }
|
|
2064 case OS.GDK_BUTTON_RELEASE:
|
|
2065 case OS.GDK_BUTTON_PRESS:
|
|
2066 case OS.GDK_2BUTTON_PRESS:
|
|
2067 case OS.GDK_3BUTTON_PRESS: {
|
|
2068 OS.gdk_event_put (eventPtr);
|
|
2069 quit = true;
|
|
2070 break;
|
|
2071 }
|
|
2072 default:
|
|
2073 OS.gtk_main_do_event (eventPtr);
|
|
2074 }
|
|
2075 OS.gdk_event_free (eventPtr);
|
|
2076 }
|
|
2077 return dragging;
|
|
2078 }
|
|
2079
|
|
2080 bool filterKey (int keyval, GdkEventKey* event) {
|
|
2081 auto imHandle = imHandle ();
|
|
2082 if (imHandle !is null) {
|
|
2083 return cast(bool)OS.gtk_im_context_filter_keypress (imHandle, event);
|
|
2084 }
|
|
2085 return false;
|
|
2086 }
|
|
2087
|
|
2088 Control findBackgroundControl () {
|
|
2089 if ((state & BACKGROUND) !is 0 || backgroundImage !is null) return this;
|
|
2090 return (state & PARENT_BACKGROUND) !is 0 ? parent.findBackgroundControl () : null;
|
|
2091 }
|
|
2092
|
|
2093 Menu [] findMenus (Control control) {
|
|
2094 if (menu !is null && this !is control) return [menu];
|
|
2095 return new Menu [0];
|
|
2096 }
|
|
2097
|
|
2098 void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
|
|
2099 oldShell.fixShell (newShell, this);
|
|
2100 oldDecorations.fixDecorations (newDecorations, this, menus);
|
|
2101 }
|
|
2102
|
|
2103 override int /*long*/ fixedMapProc (GtkWidget* widget) {
|
|
2104 OS.GTK_WIDGET_SET_FLAGS (widget, OS.GTK_MAPPED);
|
|
2105 auto widgetList = OS.gtk_container_get_children (cast(GtkContainer*)widget);
|
|
2106 if (widgetList !is null) {
|
|
2107 auto widgets = widgetList;
|
|
2108 while (widgets !is null) {
|
|
2109 auto child = cast(GtkWidget*)OS.g_list_data (widgets);
|
|
2110 if (OS.GTK_WIDGET_VISIBLE (child) && OS.gtk_widget_get_child_visible (child) && !OS.GTK_WIDGET_MAPPED (child)) {
|
|
2111 OS.gtk_widget_map (child);
|
|
2112 }
|
|
2113 widgets = cast(GList*)OS.g_list_next (widgets);
|
|
2114 }
|
|
2115 OS.g_list_free (widgetList);
|
|
2116 }
|
|
2117 if ((OS.GTK_WIDGET_FLAGS (widget) & OS.GTK_NO_WINDOW) is 0) {
|
|
2118 OS.gdk_window_show_unraised (OS.GTK_WIDGET_WINDOW (widget));
|
|
2119 }
|
|
2120 return 0;
|
|
2121 }
|
|
2122
|
|
2123 void fixModal(GtkWidget* group, GtkWidget* modalGroup) {
|
|
2124 }
|
|
2125
|
|
2126 /**
|
|
2127 * Forces the receiver to have the <em>keyboard focus</em>, causing
|
|
2128 * all keyboard events to be delivered to it.
|
|
2129 *
|
|
2130 * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
|
|
2131 *
|
|
2132 * @exception SWTException <ul>
|
|
2133 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2134 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2135 * </ul>
|
|
2136 *
|
|
2137 * @see #setFocus
|
|
2138 */
|
|
2139 public bool forceFocus () {
|
|
2140 checkWidget();
|
|
2141 if (display.focusEvent is SWT.FocusOut) return false;
|
|
2142 Shell shell = getShell ();
|
|
2143 shell.setSavedFocus (this);
|
|
2144 if (!isEnabled () || !isVisible ()) return false;
|
|
2145 shell.bringToTop (false);
|
|
2146 return forceFocus (focusHandle ());
|
|
2147 }
|
|
2148
|
|
2149 bool forceFocus (GtkWidget* focusHandle_) {
|
|
2150 /* When the control is zero sized it must be realized */
|
|
2151 OS.gtk_widget_realize (focusHandle_);
|
|
2152 OS.gtk_widget_grab_focus (focusHandle_);
|
|
2153 Shell shell = getShell ();
|
|
2154 auto shellHandle = shell.shellHandle;
|
|
2155 auto handle = OS.gtk_window_get_focus (cast(GtkWindow*)shellHandle);
|
|
2156 while (handle !is null) {
|
|
2157 if (handle is focusHandle_) return true;
|
|
2158 Widget widget = display.getWidget (handle);
|
|
2159 if (widget !is null && (null !is cast(Control)widget)) {
|
|
2160 return widget is this;
|
|
2161 }
|
|
2162 handle = OS.gtk_widget_get_parent (handle);
|
|
2163 }
|
|
2164 return false;
|
|
2165 }
|
|
2166
|
|
2167 /**
|
|
2168 * Returns the receiver's background color.
|
|
2169 *
|
|
2170 * @return the background color
|
|
2171 *
|
|
2172 * @exception SWTException <ul>
|
|
2173 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2174 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2175 * </ul>
|
|
2176 */
|
|
2177 public Color getBackground () {
|
|
2178 checkWidget();
|
|
2179 Control control = findBackgroundControl ();
|
|
2180 if (control is null) control = this;
|
|
2181 return Color.gtk_new (display, control.getBackgroundColor ());
|
|
2182 }
|
|
2183
|
|
2184 GdkColor* getBackgroundColor () {
|
|
2185 return getBgColor ();
|
|
2186 }
|
|
2187
|
|
2188 /**
|
|
2189 * Returns the receiver's background image.
|
|
2190 *
|
|
2191 * @return the background image
|
|
2192 *
|
|
2193 * @exception SWTException <ul>
|
|
2194 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2195 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2196 * </ul>
|
|
2197 *
|
|
2198 * @since 3.2
|
|
2199 */
|
|
2200 public Image getBackgroundImage () {
|
|
2201 checkWidget ();
|
|
2202 Control control = findBackgroundControl ();
|
|
2203 if (control is null) control = this;
|
|
2204 return control.backgroundImage;
|
|
2205 }
|
|
2206
|
|
2207 GdkColor* getBgColor () {
|
|
2208 auto fontHandle_ = fontHandle ();
|
|
2209 OS.gtk_widget_realize (fontHandle_);
|
|
2210 GdkColor* color = new GdkColor ();
|
|
2211 OS.gtk_style_get_bg (OS.gtk_widget_get_style (fontHandle_), OS.GTK_STATE_NORMAL, color);
|
|
2212 return color;
|
|
2213 }
|
|
2214
|
|
2215 GdkColor* getBaseColor () {
|
|
2216 auto fontHandle_ = fontHandle ();
|
|
2217 OS.gtk_widget_realize (fontHandle_);
|
|
2218 GdkColor* color = new GdkColor ();
|
|
2219 OS.gtk_style_get_base (OS.gtk_widget_get_style (fontHandle_), OS.GTK_STATE_NORMAL, color);
|
|
2220 return color;
|
|
2221 }
|
|
2222
|
|
2223 /**
|
|
2224 * Returns the receiver's border width.
|
|
2225 *
|
|
2226 * @return the border width
|
|
2227 *
|
|
2228 * @exception SWTException <ul>
|
|
2229 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2230 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2231 * </ul>
|
|
2232 */
|
|
2233 public int getBorderWidth () {
|
|
2234 checkWidget();
|
|
2235 return 0;
|
|
2236 }
|
|
2237
|
|
2238 int getClientWidth () {
|
|
2239 return 0;
|
|
2240 }
|
|
2241
|
|
2242 /**
|
|
2243 * Returns the receiver's cursor, or null if it has not been set.
|
|
2244 * <p>
|
|
2245 * When the mouse pointer passes over a control its appearance
|
|
2246 * is changed to match the control's cursor.
|
|
2247 * </p>
|
|
2248 *
|
|
2249 * @return the receiver's cursor or <code>null</code>
|
|
2250 *
|
|
2251 * @exception SWTException <ul>
|
|
2252 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2253 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2254 * </ul>
|
|
2255 *
|
|
2256 * @since 3.3
|
|
2257 */
|
|
2258 public Cursor getCursor () {
|
|
2259 checkWidget ();
|
|
2260 return cursor;
|
|
2261 }
|
|
2262
|
|
2263 /**
|
|
2264 * Returns <code>true</code> if the receiver is detecting
|
|
2265 * drag gestures, and <code>false</code> otherwise.
|
|
2266 *
|
|
2267 * @return the receiver's drag detect state
|
|
2268 *
|
|
2269 * @exception SWTException <ul>
|
|
2270 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2271 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2272 * </ul>
|
|
2273 *
|
|
2274 * @since 3.3
|
|
2275 */
|
|
2276 public bool getDragDetect () {
|
|
2277 checkWidget ();
|
|
2278 return (state & DRAG_DETECT) !is 0;
|
|
2279 }
|
|
2280
|
|
2281 /**
|
|
2282 * Returns <code>true</code> if the receiver is enabled, and
|
|
2283 * <code>false</code> otherwise. A disabled control is typically
|
|
2284 * not selectable from the user interface and draws with an
|
|
2285 * inactive or "grayed" look.
|
|
2286 *
|
|
2287 * @return the receiver's enabled state
|
|
2288 *
|
|
2289 * @exception SWTException <ul>
|
|
2290 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2291 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2292 * </ul>
|
|
2293 *
|
|
2294 * @see #isEnabled
|
|
2295 */
|
|
2296 public bool getEnabled () {
|
|
2297 checkWidget ();
|
|
2298 return (state & DISABLED) is 0;
|
|
2299 }
|
|
2300
|
|
2301 /**
|
|
2302 * Returns the font that the receiver will use to paint textual information.
|
|
2303 *
|
|
2304 * @return the receiver's font
|
|
2305 *
|
|
2306 * @exception SWTException <ul>
|
|
2307 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2308 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2309 * </ul>
|
|
2310 */
|
|
2311 public Font getFont () {
|
|
2312 checkWidget();
|
|
2313 return font !is null ? font : defaultFont ();
|
|
2314 }
|
|
2315
|
|
2316 PangoFontDescription* getFontDescription () {
|
|
2317 auto fontHandle_ = fontHandle ();
|
|
2318 OS.gtk_widget_realize (fontHandle_);
|
|
2319 return OS.gtk_style_get_font_desc (OS.gtk_widget_get_style (fontHandle_));
|
|
2320 }
|
|
2321
|
|
2322 /**
|
|
2323 * Returns the foreground color that the receiver will use to draw.
|
|
2324 *
|
|
2325 * @return the receiver's foreground color
|
|
2326 *
|
|
2327 * @exception SWTException <ul>
|
|
2328 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2329 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2330 * </ul>
|
|
2331 */
|
|
2332 public Color getForeground () {
|
|
2333 checkWidget();
|
|
2334 return Color.gtk_new (display, getForegroundColor ());
|
|
2335 }
|
|
2336
|
|
2337 GdkColor* getForegroundColor () {
|
|
2338 return getFgColor ();
|
|
2339 }
|
|
2340
|
|
2341 GdkColor* getFgColor () {
|
|
2342 auto fontHandle_ = fontHandle ();
|
|
2343 OS.gtk_widget_realize (fontHandle_);
|
|
2344 GdkColor* color = new GdkColor ();
|
|
2345 OS.gtk_style_get_fg (OS.gtk_widget_get_style (fontHandle_), OS.GTK_STATE_NORMAL, color);
|
|
2346 return color;
|
|
2347 }
|
|
2348
|
|
2349 Point getIMCaretPos () {
|
|
2350 return new Point (0, 0);
|
|
2351 }
|
|
2352
|
|
2353 GdkColor* getTextColor () {
|
|
2354 auto fontHandle_ = fontHandle ();
|
|
2355 OS.gtk_widget_realize (fontHandle_);
|
|
2356 GdkColor* color = new GdkColor ();
|
|
2357 OS.gtk_style_get_text (OS.gtk_widget_get_style (fontHandle_), OS.GTK_STATE_NORMAL, color);
|
|
2358 return color;
|
|
2359 }
|
|
2360
|
|
2361 /**
|
|
2362 * Returns layout data which is associated with the receiver.
|
|
2363 *
|
|
2364 * @return the receiver's layout data
|
|
2365 *
|
|
2366 * @exception SWTException <ul>
|
|
2367 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2368 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2369 * </ul>
|
|
2370 */
|
|
2371 public Object getLayoutData () {
|
|
2372 checkWidget();
|
|
2373 return layoutData;
|
|
2374 }
|
|
2375
|
|
2376 /**
|
|
2377 * Returns the receiver's pop up menu if it has one, or null
|
|
2378 * if it does not. All controls may optionally have a pop up
|
|
2379 * menu that is displayed when the user requests one for
|
|
2380 * the control. The sequence of key strokes, button presses
|
|
2381 * and/or button releases that are used to request a pop up
|
|
2382 * menu is platform specific.
|
|
2383 *
|
|
2384 * @return the receiver's menu
|
|
2385 *
|
|
2386 * @exception SWTException <ul>
|
|
2387 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2388 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2389 * </ul>
|
|
2390 */
|
|
2391 public Menu getMenu () {
|
|
2392 checkWidget();
|
|
2393 return menu;
|
|
2394 }
|
|
2395
|
|
2396 /**
|
|
2397 * Returns the receiver's monitor.
|
|
2398 *
|
|
2399 * @return the receiver's monitor
|
|
2400 *
|
|
2401 * @since 3.0
|
|
2402 */
|
|
2403 public org.eclipse.swt.widgets.Monitor.Monitor getMonitor () {
|
|
2404 checkWidget();
|
|
2405 org.eclipse.swt.widgets.Monitor.Monitor monitor = null;
|
|
2406 auto screen = OS.gdk_screen_get_default ();
|
|
2407 if (screen !is null) {
|
|
2408 int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, paintWindow ());
|
|
2409 GdkRectangle dest;
|
|
2410 OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, &dest);
|
|
2411 monitor = new org.eclipse.swt.widgets.Monitor.Monitor ();
|
|
2412 monitor.handle = monitorNumber;
|
|
2413 monitor.x = dest.x;
|
|
2414 monitor.y = dest.y;
|
|
2415 monitor.width = dest.width;
|
|
2416 monitor.height = dest.height;
|
|
2417 Rectangle workArea = null;
|
|
2418 if (monitorNumber is 0) workArea = display.getWorkArea ();
|
|
2419 if (workArea !is null) {
|
|
2420 monitor.clientX = workArea.x;
|
|
2421 monitor.clientY = workArea.y;
|
|
2422 monitor.clientWidth = workArea.width;
|
|
2423 monitor.clientHeight = workArea.height;
|
|
2424 } else {
|
|
2425 monitor.clientX = monitor.x;
|
|
2426 monitor.clientY = monitor.y;
|
|
2427 monitor.clientWidth = monitor.width;
|
|
2428 monitor.clientHeight = monitor.height;
|
|
2429 }
|
|
2430 } else {
|
|
2431 monitor = display.getPrimaryMonitor ();
|
|
2432 }
|
|
2433 return monitor;
|
|
2434 }
|
|
2435
|
|
2436 /**
|
|
2437 * Returns the receiver's parent, which must be a <code>Composite</code>
|
|
2438 * or null when the receiver is a shell that was created with null or
|
|
2439 * a display for a parent.
|
|
2440 *
|
|
2441 * @return the receiver's parent
|
|
2442 *
|
|
2443 * @exception SWTException <ul>
|
|
2444 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2445 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2446 * </ul>
|
|
2447 */
|
|
2448 public Composite getParent () {
|
|
2449 checkWidget();
|
|
2450 return parent;
|
|
2451 }
|
|
2452
|
|
2453 Control [] getPath () {
|
|
2454 int count = 0;
|
|
2455 Shell shell = getShell ();
|
|
2456 Control control = this;
|
|
2457 while (control !is shell) {
|
|
2458 count++;
|
|
2459 control = control.parent;
|
|
2460 }
|
|
2461 control = this;
|
|
2462 Control [] result = new Control [count];
|
|
2463 while (control !is shell) {
|
|
2464 result [--count] = control;
|
|
2465 control = control.parent;
|
|
2466 }
|
|
2467 return result;
|
|
2468 }
|
|
2469
|
|
2470 /**
|
|
2471 * Returns the region that defines the shape of the control,
|
|
2472 * or null if the control has the default shape.
|
|
2473 *
|
|
2474 * @return the region that defines the shape of the shell (or null)
|
|
2475 *
|
|
2476 * @exception SWTException <ul>
|
|
2477 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2478 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2479 * </ul>
|
|
2480 *
|
|
2481 * @since 3.4
|
|
2482 */
|
|
2483 public Region getRegion () {
|
|
2484 checkWidget ();
|
|
2485 return region;
|
|
2486 }
|
|
2487
|
|
2488 /**
|
|
2489 * Returns the receiver's shell. For all controls other than
|
|
2490 * shells, this simply returns the control's nearest ancestor
|
|
2491 * shell. Shells return themselves, even if they are children
|
|
2492 * of other shells.
|
|
2493 *
|
|
2494 * @return the receiver's shell
|
|
2495 *
|
|
2496 * @exception SWTException <ul>
|
|
2497 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2498 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2499 * </ul>
|
|
2500 *
|
|
2501 * @see #getParent
|
|
2502 */
|
|
2503 public Shell getShell() {
|
|
2504 checkWidget();
|
|
2505 return _getShell();
|
|
2506 }
|
|
2507
|
|
2508 Shell _getShell() {
|
|
2509 return parent._getShell();
|
|
2510 }
|
|
2511
|
|
2512 /**
|
|
2513 * Returns the receiver's tool tip text, or null if it has
|
|
2514 * not been set.
|
|
2515 *
|
|
2516 * @return the receiver's tool tip text
|
|
2517 *
|
|
2518 * @exception SWTException <ul>
|
|
2519 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2520 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2521 * </ul>
|
|
2522 */
|
|
2523 public String getToolTipText () {
|
|
2524 checkWidget();
|
|
2525 return toolTipText;
|
|
2526 }
|
|
2527 /**
|
|
2528 * Returns <code>true</code> if the receiver is visible, and
|
|
2529 * <code>false</code> otherwise.
|
|
2530 * <p>
|
|
2531 * If one of the receiver's ancestors is not visible or some
|
|
2532 * other condition makes the receiver not visible, this method
|
|
2533 * may still indicate that it is considered visible even though
|
|
2534 * it may not actually be showing.
|
|
2535 * </p>
|
|
2536 *
|
|
2537 * @return the receiver's visibility state
|
|
2538 *
|
|
2539 * @exception SWTException <ul>
|
|
2540 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
2541 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
2542 * </ul>
|
|
2543 */
|
|
2544 public bool getVisible () {
|
|
2545 checkWidget();
|
|
2546 return (state & HIDDEN) is 0;
|
|
2547 }
|
|
2548
|
|
2549 override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) {
|
|
2550 return gtk_button_press_event (widget, event, true);
|
|
2551 }
|
|
2552
|
|
2553 int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* gdkEvent, bool sendMouseDown) {
|
|
2554 if (gdkEvent.type is OS.GDK_3BUTTON_PRESS) return 0;
|
|
2555
|
|
2556 /*
|
|
2557 * When a shell is created with SWT.ON_TOP and SWT.NO_FOCUS,
|
|
2558 * do not activate the shell when the user clicks on the
|
|
2559 * the client area or on the border or a control within the
|
|
2560 * shell that does not take focus.
|
|
2561 */
|
|
2562 Shell shell = _getShell ();
|
|
2563 if (((shell.style & SWT.ON_TOP) !is 0) && (((shell.style & SWT.NO_FOCUS) is 0) || ((style & SWT.NO_FOCUS) is 0))) {
|
|
2564 shell.forceActive();
|
|
2565 }
|
|
2566 int /*long*/ result = 0;
|
|
2567 if (gdkEvent.type is OS.GDK_BUTTON_PRESS) {
|
|
2568 display.clickCount = 1;
|
|
2569 auto nextEvent = OS.gdk_event_peek ();
|
|
2570 if (nextEvent !is null) {
|
|
2571 int eventType = OS.GDK_EVENT_TYPE (nextEvent);
|
|
2572 if (eventType is OS.GDK_2BUTTON_PRESS) display.clickCount = 2;
|
|
2573 if (eventType is OS.GDK_3BUTTON_PRESS) display.clickCount = 3;
|
|
2574 OS.gdk_event_free (nextEvent);
|
|
2575 }
|
|
2576 bool dragging = false;
|
|
2577 if ((state & DRAG_DETECT) !is 0 && hooks (SWT.DragDetect)) {
|
|
2578 if (gdkEvent.button is 1) {
|
|
2579 bool consume = false;
|
|
2580 if (dragDetect (cast(int) gdkEvent.x, cast(int) gdkEvent.y, true, &consume)) {
|
|
2581 dragging = true;
|
|
2582 if (consume ) result = 1;
|
|
2583 }
|
|
2584 if (isDisposed ()) return 1;
|
|
2585 }
|
|
2586 }
|
|
2587 if (sendMouseDown && !sendMouseEvent (SWT.MouseDown, gdkEvent.button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state)) {
|
|
2588 result = 1;
|
|
2589 }
|
|
2590 if (isDisposed ()) return 1;
|
|
2591 if (dragging) {
|
|
2592 sendDragEvent (gdkEvent.button, gdkEvent.state, cast(int) gdkEvent.x, cast(int) gdkEvent.y, false);
|
|
2593 if (isDisposed ()) return 1;
|
|
2594 }
|
|
2595 /*
|
|
2596 * Pop up the context menu in the button press event for widgets
|
|
2597 * that have default operating system menus in order to stop the
|
|
2598 * operating system from displaying the menu if necessary.
|
|
2599 */
|
|
2600 if ((state & MENU) !is 0) {
|
|
2601 if (gdkEvent.button is 3) {
|
|
2602 if (showMenu (cast(int)gdkEvent.x_root, cast(int)gdkEvent.y_root)) {
|
|
2603 result = 1;
|
|
2604 }
|
|
2605 }
|
|
2606 }
|
|
2607 } else {
|
|
2608 display.clickCount = 2;
|
|
2609 result = sendMouseEvent (SWT.MouseDoubleClick, gdkEvent.button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
|
|
2610 if (isDisposed ()) return 1;
|
|
2611 }
|
|
2612 if (!shell.isDisposed ()) shell.setActiveControl (this);
|
|
2613 return result;
|
|
2614 }
|
|
2615
|
|
2616 override int /*long*/ gtk_button_release_event (GtkWidget* widget, GdkEventButton* gdkEvent) {
|
|
2617 /*
|
|
2618 * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK
|
|
2619 * does not deliver a corresponding GTK event. Button 6 and 7
|
|
2620 * are mapped to buttons 4 and 5 in SWT. The fix is to change
|
|
2621 * the button number of the event to a negative number so that
|
|
2622 * it gets dispatched by GTK. SWT has been modified to look
|
|
2623 * for negative button numbers.
|
|
2624 */
|
|
2625 int button = gdkEvent.button;
|
|
2626 switch (button) {
|
|
2627 case -6: button = 4; break;
|
|
2628 case -7: button = 5; break;
|
|
2629 default:
|
|
2630 }
|
|
2631 return sendMouseEvent (SWT.MouseUp, button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
|
|
2632 }
|
|
2633
|
|
2634 override int /*long*/ gtk_commit (GtkIMContext* imcontext, char* text) {
|
|
2635 char [] chars = fromStringz( text );
|
|
2636 if (chars.length is 0) return 0;
|
|
2637 sendIMKeyEvent (SWT.KeyDown, null, chars);
|
|
2638 return 0;
|
|
2639 }
|
|
2640
|
|
2641 override int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* gdkEvent) {
|
|
2642 if (OS.GTK_VERSION >= OS.buildVERSION (2, 12, 0)) {
|
|
2643 /*
|
|
2644 * Feature in GTK. Children of a shell will inherit and display the shell's
|
|
2645 * tooltip if they do not have a tooltip of their own. The fix is to use the
|
|
2646 * new tooltip API in GTK 2.12 to null the shell's tooltip when the control
|
|
2647 * being entered does not have any tooltip text set.
|
|
2648 */
|
|
2649 char* buffer = null;
|
|
2650 if (toolTipText !is null && toolTipText.length !is 0) {
|
|
2651 char [] chars = fixMnemonic (toolTipText, false);
|
|
2652 buffer = toStringz(chars);
|
|
2653 }
|
|
2654 auto toolHandle = getShell().handle;
|
|
2655 OS.gtk_widget_set_tooltip_text (toolHandle, buffer);
|
|
2656 }
|
|
2657 if (display.currentControl is this) return 0;
|
|
2658 if (gdkEvent.mode !is OS.GDK_CROSSING_NORMAL && gdkEvent.mode !is OS.GDK_CROSSING_UNGRAB) return 0;
|
|
2659 if ((gdkEvent.state & (OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK)) !is 0) return 0;
|
|
2660 if (display.currentControl !is null && !display.currentControl.isDisposed ()) {
|
|
2661 display.removeMouseHoverTimeout (display.currentControl.handle);
|
|
2662 display.currentControl.sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state);
|
|
2663 }
|
|
2664 if (!isDisposed ()) {
|
|
2665 display.currentControl = this;
|
|
2666 return sendMouseEvent (SWT.MouseEnter, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
|
|
2667 }
|
|
2668 return 0;
|
|
2669 }
|
|
2670
|
|
2671 override int /*long*/ gtk_event_after (GtkWidget* widget, GdkEvent* gdkEvent) {
|
|
2672 switch (cast(int)gdkEvent.type) {
|
|
2673 case OS.GDK_BUTTON_PRESS: {
|
|
2674 if (widget !is eventHandle ()) break;
|
|
2675 /*
|
|
2676 * Pop up the context menu in the event_after signal to allow
|
|
2677 * the widget to process the button press. This allows widgets
|
|
2678 * such as GtkTreeView to select items before a menu is shown.
|
|
2679 */
|
|
2680 if ((state & MENU) is 0) {
|
|
2681 GdkEventButton* gdkEventButton = cast(GdkEventButton*)gdkEvent;
|
|
2682 if (gdkEventButton.button is 3) {
|
|
2683 showMenu (cast(int) gdkEventButton.x_root, cast(int) gdkEventButton.y_root);
|
|
2684 }
|
|
2685 }
|
|
2686 break;
|
|
2687 }
|
|
2688 case OS.GDK_FOCUS_CHANGE: {
|
|
2689 if (!isFocusHandle (widget)) break;
|
|
2690 GdkEventFocus* gdkEventFocus = cast(GdkEventFocus*)gdkEvent;
|
|
2691
|
|
2692 /*
|
|
2693 * Feature in GTK. The GTK combo box popup under some window managers
|
|
2694 * is implemented as a GTK_MENU. When it pops up, it causes the combo
|
|
2695 * box to lose focus when focus is received for the menu. The
|
|
2696 * fix is to check the current grab handle and see if it is a GTK_MENU
|
|
2697 * and ignore the focus event when the menu is both shown and hidden.
|
|
2698 */
|
|
2699 Display display = this.display;
|
|
2700 if (gdkEventFocus.in_ !is 0) {
|
|
2701 if (display.ignoreFocus) {
|
|
2702 display.ignoreFocus = false;
|
|
2703 break;
|
|
2704 }
|
|
2705 } else {
|
|
2706 display.ignoreFocus = false;
|
|
2707 auto grabHandle = OS.gtk_grab_get_current ();
|
|
2708 if (grabHandle !is null) {
|
|
2709 if (OS.G_OBJECT_TYPE ( cast(GTypeInstance*)grabHandle) is OS.GTK_TYPE_MENU ()) {
|
|
2710 display.ignoreFocus = true;
|
|
2711 break;
|
|
2712 }
|
|
2713 }
|
|
2714 }
|
|
2715
|
|
2716 sendFocusEvent (gdkEventFocus.in_ !is 0 ? SWT.FocusIn : SWT.FocusOut);
|
|
2717 break;
|
|
2718 default:
|
|
2719 }
|
|
2720 }
|
|
2721 return 0;
|
|
2722 }
|
|
2723
|
|
2724 override int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* gdkEvent) {
|
|
2725 if ((state & OBSCURED) !is 0) return 0;
|
|
2726 if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0;
|
|
2727 Event event = new Event ();
|
|
2728 event.count = gdkEvent.count;
|
|
2729 event.x = gdkEvent.area.x;
|
|
2730 event.y = gdkEvent.area.y;
|
|
2731 event.width = gdkEvent.area.width;
|
|
2732 event.height = gdkEvent.area.height;
|
|
2733 if ((style & SWT.MIRRORED) !is 0) event.x = getClientWidth () - event.width - event.x;
|
|
2734 GCData data = new GCData ();
|
|
2735 data.damageRgn = gdkEvent.region;
|
|
2736 GC gc = event.gc = GC.gtk_new (this, data);
|
|
2737 OS.gdk_gc_set_clip_region (gc.handle, gdkEvent.region);
|
|
2738 sendEvent (SWT.Paint, event);
|
|
2739 gc.dispose ();
|
|
2740 event.gc = null;
|
|
2741 return 0;
|
|
2742 }
|
|
2743
|
|
2744 override int /*long*/ gtk_focus (GtkWidget* widget, int directionType) {
|
|
2745 /* Stop GTK traversal for every widget */
|
|
2746 return 1;
|
|
2747 }
|
|
2748
|
|
2749 override int /*long*/ gtk_focus_in_event (GtkWidget* widget, GdkEventFocus* event) {
|
|
2750 // widget could be disposed at this point
|
|
2751 if (handle !is null) {
|
|
2752 Control oldControl = display.imControl;
|
|
2753 if (oldControl !is this) {
|
|
2754 if (oldControl !is null && !oldControl.isDisposed ()) {
|
|
2755 auto oldIMHandle = oldControl.imHandle ();
|
|
2756 if (oldIMHandle !is null) OS.gtk_im_context_reset (oldIMHandle);
|
|
2757 }
|
|
2758 }
|
|
2759 if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
|
|
2760 auto imHandle = imHandle ();
|
|
2761 if (imHandle !is null) OS.gtk_im_context_focus_in (imHandle);
|
|
2762 }
|
|
2763 }
|
|
2764 return 0;
|
|
2765 }
|
|
2766
|
|
2767 override int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) {
|
|
2768 // widget could be disposed at this point
|
|
2769 if (handle !is null) {
|
|
2770 if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
|
|
2771 auto imHandle = imHandle ();
|
|
2772 if (imHandle !is null) {
|
|
2773 OS.gtk_im_context_focus_out (imHandle);
|
|
2774 }
|
|
2775 }
|
|
2776 }
|
|
2777 return 0;
|
|
2778 }
|
|
2779
|
|
2780 override int /*long*/ gtk_key_press_event (GtkWidget* widget, GdkEventKey* gdkEvent) {
|
|
2781 if (!hasFocus ()) return 0;
|
|
2782
|
|
2783 if (translateMnemonic (gdkEvent.keyval, gdkEvent)) return 1;
|
|
2784 // widget could be disposed at this point
|
|
2785 if (isDisposed ()) return 0;
|
|
2786
|
|
2787 if (filterKey (gdkEvent.keyval, gdkEvent)) return 1;
|
|
2788 // widget could be disposed at this point
|
|
2789 if (isDisposed ()) return 0;
|
|
2790
|
|
2791 if (translateTraversal (gdkEvent)) return 1;
|
|
2792 // widget could be disposed at this point
|
|
2793 if (isDisposed ()) return 0;
|
|
2794 return super.gtk_key_press_event (widget, gdkEvent);
|
|
2795 }
|
|
2796
|
|
2797 override int /*long*/ gtk_key_release_event (GtkWidget* widget, GdkEventKey* event) {
|
|
2798 if (!hasFocus ()) return 0;
|
|
2799 auto imHandle = imHandle ();
|
|
2800 if (imHandle !is null) {
|
|
2801 if (OS.gtk_im_context_filter_keypress (imHandle, event)) return 1;
|
|
2802 }
|
|
2803 return super.gtk_key_release_event (widget, event);
|
|
2804 }
|
|
2805
|
|
2806 override int /*long*/ gtk_leave_notify_event (GtkWidget* widget, GdkEventCrossing* gdkEvent) {
|
|
2807 if (display.currentControl !is this) return 0;
|
|
2808 display.removeMouseHoverTimeout (handle);
|
|
2809 int result = 0;
|
|
2810 if (sendLeaveNotify () || display.getCursorControl () is null) {
|
|
2811 if (gdkEvent.mode !is OS.GDK_CROSSING_NORMAL && gdkEvent.mode !is OS.GDK_CROSSING_UNGRAB) return 0;
|
|
2812 if ((gdkEvent.state & (OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK)) !is 0) return 0;
|
|
2813 result = sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
|
|
2814 display.currentControl = null;
|
|
2815 }
|
|
2816 return result;
|
|
2817 }
|
|
2818
|
|
2819 override int /*long*/ gtk_mnemonic_activate (GtkWidget* widget, int /*long*/ arg1) {
|
|
2820 int result = 0;
|
|
2821 auto eventPtr = OS.gtk_get_current_event ();
|
|
2822 if (eventPtr !is null) {
|
|
2823 GdkEventKey* keyEvent = cast(GdkEventKey*)eventPtr;
|
|
2824 if (keyEvent.type is OS.GDK_KEY_PRESS) {
|
|
2825 Control focusControl = display.getFocusControl ();
|
|
2826 auto focusHandle_ = focusControl !is null ? focusControl.focusHandle () : null;
|
|
2827 if (focusHandle_ !is null) {
|
|
2828 display.mnemonicControl = this;
|
|
2829 OS.gtk_widget_event (focusHandle_, eventPtr);
|
|
2830 display.mnemonicControl = null;
|
|
2831 }
|
|
2832 result = 1;
|
|
2833 }
|
|
2834 OS.gdk_event_free (eventPtr);
|
|
2835 }
|
|
2836 return result;
|
|
2837 }
|
|
2838
|
|
2839 override int /*long*/ gtk_motion_notify_event (GtkWidget* widget, GdkEventMotion* gdkEvent) {
|
|
2840 if (this is display.currentControl && (hooks (SWT.MouseHover) || filters (SWT.MouseHover))) {
|
|
2841 display.addMouseHoverTimeout (handle);
|
|
2842 }
|
|
2843 double x = gdkEvent.x_root, y = gdkEvent.y_root;
|
|
2844 int state = gdkEvent.state;
|
|
2845 if (gdkEvent.is_hint !is 0) {
|
|
2846 int pointer_x, pointer_y;
|
|
2847 int mask;
|
|
2848 auto window = eventWindow ();
|
|
2849 OS.gdk_window_get_pointer (window, &pointer_x, &pointer_y, &mask);
|
|
2850 x = pointer_x;
|
|
2851 y = pointer_y;
|
|
2852 state = mask;
|
|
2853 }
|
|
2854 int result = sendMouseEvent (SWT.MouseMove, 0, gdkEvent.time, x, y, gdkEvent.is_hint !is 0, state) ? 0 : 1;
|
|
2855 return result;
|
|
2856 }
|
|
2857
|
|
2858 override int /*long*/ gtk_popup_menu (GtkWidget* widget) {
|
|
2859 if (!hasFocus()) return 0;
|
|
2860 int x, y ;
|
|
2861 OS.gdk_window_get_pointer (null, &x, &y, null);
|
|
2862 return showMenu (x, y) ? 1 : 0;
|
|
2863 }
|
|
2864
|
|
2865 override int /*long*/ gtk_preedit_changed (GtkIMContext* imcontext) {
|
|
2866 display.showIMWindow (this);
|
|
2867 return 0;
|
|
2868 }
|
|
2869
|
|
2870 override int /*long*/ gtk_realize (GtkWidget* widget) {
|
|
2871 auto imHandle = imHandle ();
|
|
2872 if (imHandle !is null) {
|
|
2873 auto window = OS.GTK_WIDGET_WINDOW (paintHandle ());
|
|
2874 OS.gtk_im_context_set_client_window (imHandle, window);
|
|
2875 }
|
|
2876 if (backgroundImage !is null) {
|
|
2877 auto window = OS.GTK_WIDGET_WINDOW (paintHandle ());
|
|
2878 if (window !is null) OS.gdk_window_set_back_pixmap (window, cast(GdkPixmap*)backgroundImage.pixmap, false);
|
|
2879 }
|
|
2880 return 0;
|
|
2881 }
|
|
2882
|
|
2883 override int /*long*/ gtk_scroll_event (GtkWidget* widget, GdkEventScroll* gdkEvent) {
|
|
2884 switch (cast(int)gdkEvent.direction) {
|
|
2885 case OS.GDK_SCROLL_UP:
|
|
2886 return sendMouseEvent (SWT.MouseWheel, 0, 3, SWT.SCROLL_LINE, true, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
|
|
2887 case OS.GDK_SCROLL_DOWN:
|
|
2888 return sendMouseEvent (SWT.MouseWheel, 0, -3, SWT.SCROLL_LINE, true, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
|
|
2889 case OS.GDK_SCROLL_LEFT:
|
|
2890 return sendMouseEvent (SWT.MouseDown, 4, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
|
|
2891 case OS.GDK_SCROLL_RIGHT:
|
|
2892 return sendMouseEvent (SWT.MouseDown, 5, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
|
|
2893 default:
|
|
2894 }
|
|
2895 return 0;
|
|
2896 }
|
|
2897
|
|
2898 override int /*long*/ gtk_show_help (GtkWidget* widget, int /*long*/ helpType) {
|
|
2899 if (!hasFocus ()) return 0;
|
|
2900 return sendHelpEvent (helpType) ? 1 : 0;
|
|
2901 }
|
|
2902
|
|
2903 override int /*long*/ gtk_style_set (GtkWidget* widget, int /*long*/ previousStyle) {
|
|
2904 if (backgroundImage !is null) {
|
|
2905 setBackgroundPixmap (backgroundImage.pixmap);
|
|
2906 }
|
|
2907 return 0;
|
|
2908 }
|
|
2909
|
|
2910 override int /*long*/ gtk_unrealize (GtkWidget* widget) {
|
|
2911 auto imHandle = imHandle ();
|
|
2912 if (imHandle !is null) OS.gtk_im_context_set_client_window (imHandle, null);
|
|
2913 return 0;
|
|
2914 }
|
|
2915
|
|
2916 override int /*long*/ gtk_visibility_notify_event (GtkWidget* widget, GdkEventVisibility* gdkEvent) {
|
|
2917 auto paintWindow = paintWindow();
|
|
2918 auto window = gdkEvent.window;
|
|
2919 if (window is paintWindow) {
|
|
2920 if (gdkEvent.state is OS.GDK_VISIBILITY_FULLY_OBSCURED) {
|
|
2921 state |= OBSCURED;
|
|
2922 } else {
|
|
2923 if ((state & OBSCURED) !is 0) {
|
|
2924 int width, height;
|
|
2925 OS.gdk_drawable_get_size (cast(GdkDrawable*)window, &width, &height);
|
|
2926 GdkRectangle rect;
|
|
2927 rect.width = width;
|
|
2928 rect.height = height;
|
|
2929 OS.gdk_window_invalidate_rect (window, &rect, false);
|
|
2930 }
|
|
2931 state &= ~OBSCURED;
|
|
2932 }
|
|
2933 }
|
|
2934 return 0;
|
|
2935 }
|
|
2936
|
|
2937 /*no override*/ void gtk_widget_size_request (GtkWidget* widget, GtkRequisition* requisition) {
|
|
2938 OS.gtk_widget_size_request (widget, requisition);
|
|
2939 }
|
|
2940
|
|
2941 /**
|
|
2942 * Invokes platform specific functionality to allocate a new GC handle.
|
|
2943 * <p>
|
|
2944 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
|
|
2945 * API for <code>Control</code>. It is marked public only so that it
|
|
2946 * can be shared within the packages provided by SWT. It is not
|
|
2947 * available on all platforms, and should never be called from
|
|
2948 * application code.
|
|
2949 * </p>
|
|
2950 *
|
|
2951 * @param data the platform specific GC data
|
|
2952 * @return the platform specific GC handle
|
|
2953 */
|
|
2954 public GdkGC* internal_new_GC (GCData data) {
|
|
2955 checkWidget ();
|
|
2956 auto window = paintWindow ();
|
|
2957 if (window is null) SWT.error (SWT.ERROR_NO_HANDLES);
|
|
2958 auto gdkGC = OS.gdk_gc_new (cast(GdkDrawable*)window);
|
|
2959 if (gdkGC is null) error (SWT.ERROR_NO_HANDLES);
|
|
2960 if (data !is null) {
|
|
2961 int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
|
|
2962 if ((data.style & mask) is 0) {
|
|
2963 data.style |= style & (mask | SWT.MIRRORED);
|
|
2964 } else {
|
|
2965 if ((data.style & SWT.RIGHT_TO_LEFT) !is 0) {
|
|
2966 data.style |= SWT.MIRRORED;
|
|
2967 }
|
|
2968 }
|
|
2969 data.drawable = cast(GdkDrawable*)window;
|
|
2970 data.device = display;
|
|
2971 data.foreground = getForegroundColor ();
|
|
2972 Control control = findBackgroundControl ();
|
|
2973 if (control is null) control = this;
|
|
2974 data.background = control.getBackgroundColor ();
|
|
2975 data.font = font !is null ? font : defaultFont ();
|
|
2976 }
|
|
2977 return gdkGC;
|
|
2978 }
|
|
2979
|
|
2980 GtkIMContext* imHandle () {
|
|
2981 return null;
|
|
2982 }
|
|
2983
|
|
2984 /**
|
|
2985 * Invokes platform specific functionality to dispose a GC handle.
|
|
2986 * <p>
|
|
2987 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
|
|
2988 * API for <code>Control</code>. It is marked public only so that it
|
|
2989 * can be shared within the packages provided by SWT. It is not
|
|
2990 * available on all platforms, and should never be called from
|
|
2991 * application code.
|
|
2992 * </p>
|
|
2993 *
|
|
2994 * @param hDC the platform specific GC handle
|
|
2995 * @param data the platform specific GC data
|
|
2996 */
|
|
2997 public void internal_dispose_GC (GdkGC* gdkGC, GCData data) {
|
|
2998 checkWidget ();
|
|
2999 OS.g_object_unref (gdkGC);
|
|
3000 }
|
|
3001
|
|
3002 /**
|
|
3003 * Returns <code>true</code> if the underlying operating
|
|
3004 * system supports this reparenting, otherwise <code>false</code>
|
|
3005 *
|
|
3006 * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
|
|
3007 *
|
|
3008 * @exception SWTException <ul>
|
|
3009 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3010 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3011 * </ul>
|
|
3012 */
|
|
3013 public bool isReparentable () {
|
|
3014 checkWidget();
|
|
3015 return true;
|
|
3016 }
|
|
3017 bool isShowing () {
|
|
3018 /*
|
|
3019 * This is not complete. Need to check if the
|
|
3020 * widget is obscurred by a parent or sibling.
|
|
3021 */
|
|
3022 if (!isVisible ()) return false;
|
|
3023 Control control = this;
|
|
3024 while (control !is null) {
|
|
3025 Point size = control.getSize ();
|
|
3026 if (size.x is 0 || size.y is 0) {
|
|
3027 return false;
|
|
3028 }
|
|
3029 control = control.parent;
|
|
3030 }
|
|
3031 return true;
|
|
3032 }
|
|
3033 bool isTabGroup () {
|
|
3034 Control [] tabList = parent._getTabList ();
|
|
3035 if (tabList !is null) {
|
|
3036 for (int i=0; i<tabList.length; i++) {
|
|
3037 if (tabList [i] is this) return true;
|
|
3038 }
|
|
3039 }
|
|
3040 int code = traversalCode (0, null);
|
|
3041 if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) !is 0) return false;
|
|
3042 return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) !is 0;
|
|
3043 }
|
|
3044 bool isTabItem () {
|
|
3045 Control [] tabList = parent._getTabList ();
|
|
3046 if (tabList !is null) {
|
|
3047 for (int i=0; i<tabList.length; i++) {
|
|
3048 if (tabList [i] is this) return false;
|
|
3049 }
|
|
3050 }
|
|
3051 int code = traversalCode (0, null);
|
|
3052 return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) !is 0;
|
|
3053 }
|
|
3054
|
|
3055 /**
|
|
3056 * Returns <code>true</code> if the receiver is enabled and all
|
|
3057 * ancestors up to and including the receiver's nearest ancestor
|
|
3058 * shell are enabled. Otherwise, <code>false</code> is returned.
|
|
3059 * A disabled control is typically not selectable from the user
|
|
3060 * interface and draws with an inactive or "grayed" look.
|
|
3061 *
|
|
3062 * @return the receiver's enabled state
|
|
3063 *
|
|
3064 * @exception SWTException <ul>
|
|
3065 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3066 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3067 * </ul>
|
|
3068 *
|
|
3069 * @see #getEnabled
|
|
3070 */
|
|
3071 public bool isEnabled () {
|
|
3072 checkWidget ();
|
|
3073 return getEnabled () && parent.isEnabled ();
|
|
3074 }
|
|
3075
|
|
3076 bool isFocusAncestor (Control control) {
|
|
3077 while (control !is null && control !is this && !( null !is cast(Shell)control )) {
|
|
3078 control = control.parent;
|
|
3079 }
|
|
3080 return control is this;
|
|
3081 }
|
|
3082
|
|
3083 /**
|
|
3084 * Returns <code>true</code> if the receiver has the user-interface
|
|
3085 * focus, and <code>false</code> otherwise.
|
|
3086 *
|
|
3087 * @return the receiver's focus state
|
|
3088 *
|
|
3089 * @exception SWTException <ul>
|
|
3090 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3091 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3092 * </ul>
|
|
3093 */
|
|
3094 public bool isFocusControl () {
|
|
3095 checkWidget();
|
|
3096 Control focusControl = display.focusControl;
|
|
3097 if (focusControl !is null && !focusControl.isDisposed ()) {
|
|
3098 return this is focusControl;
|
|
3099 }
|
|
3100 return hasFocus ();
|
|
3101 }
|
|
3102
|
|
3103 /**
|
|
3104 * Returns <code>true</code> if the receiver is visible and all
|
|
3105 * ancestors up to and including the receiver's nearest ancestor
|
|
3106 * shell are visible. Otherwise, <code>false</code> is returned.
|
|
3107 *
|
|
3108 * @return the receiver's visibility state
|
|
3109 *
|
|
3110 * @exception SWTException <ul>
|
|
3111 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3112 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3113 * </ul>
|
|
3114 *
|
|
3115 * @see #getVisible
|
|
3116 */
|
|
3117 public bool isVisible () {
|
|
3118 checkWidget();
|
|
3119 return getVisible () && parent.isVisible ();
|
|
3120 }
|
|
3121
|
|
3122 Decorations menuShell () {
|
|
3123 return parent.menuShell ();
|
|
3124 }
|
|
3125
|
|
3126 bool mnemonicHit (wchar key) {
|
|
3127 return false;
|
|
3128 }
|
|
3129
|
|
3130 bool mnemonicMatch (wchar key) {
|
|
3131 return false;
|
|
3132 }
|
|
3133
|
|
3134 override void register () {
|
|
3135 super.register ();
|
|
3136 if (fixedHandle !is null) display.addWidget (fixedHandle, this);
|
|
3137 auto imHandle = imHandle ();
|
|
3138 if (imHandle !is null) display.addWidget (cast(GtkWidget*)imHandle, this);
|
|
3139 }
|
|
3140
|
|
3141 /**
|
|
3142 * Causes the entire bounds of the receiver to be marked
|
|
3143 * as needing to be redrawn. The next time a paint request
|
|
3144 * is processed, the control will be completely painted,
|
|
3145 * including the background.
|
|
3146 *
|
|
3147 * @exception SWTException <ul>
|
|
3148 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3149 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3150 * </ul>
|
|
3151 *
|
|
3152 * @see #update()
|
|
3153 * @see PaintListener
|
|
3154 * @see SWT#Paint
|
|
3155 * @see SWT#NO_BACKGROUND
|
|
3156 * @see SWT#NO_REDRAW_RESIZE
|
|
3157 * @see SWT#NO_MERGE_PAINTS
|
|
3158 * @see SWT#DOUBLE_BUFFERED
|
|
3159 */
|
|
3160 public void redraw () {
|
|
3161 checkWidget();
|
|
3162 redraw (false);
|
|
3163 }
|
|
3164
|
|
3165 void redraw (bool all) {
|
|
3166 // checkWidget();
|
|
3167 if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return;
|
|
3168 redrawWidget (0, 0, 0, 0, true, all, false);
|
|
3169 }
|
|
3170
|
|
3171 /**
|
|
3172 * Causes the rectangular area of the receiver specified by
|
|
3173 * the arguments to be marked as needing to be redrawn.
|
|
3174 * The next time a paint request is processed, that area of
|
|
3175 * the receiver will be painted, including the background.
|
|
3176 * If the <code>all</code> flag is <code>true</code>, any
|
|
3177 * children of the receiver which intersect with the specified
|
|
3178 * area will also paint their intersecting areas. If the
|
|
3179 * <code>all</code> flag is <code>false</code>, the children
|
|
3180 * will not be painted.
|
|
3181 *
|
|
3182 * @param x the x coordinate of the area to draw
|
|
3183 * @param y the y coordinate of the area to draw
|
|
3184 * @param width the width of the area to draw
|
|
3185 * @param height the height of the area to draw
|
|
3186 * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise
|
|
3187 *
|
|
3188 * @exception SWTException <ul>
|
|
3189 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3190 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3191 * </ul>
|
|
3192 *
|
|
3193 * @see #update()
|
|
3194 * @see PaintListener
|
|
3195 * @see SWT#Paint
|
|
3196 * @see SWT#NO_BACKGROUND
|
|
3197 * @see SWT#NO_REDRAW_RESIZE
|
|
3198 * @see SWT#NO_MERGE_PAINTS
|
|
3199 * @see SWT#DOUBLE_BUFFERED
|
|
3200 */
|
|
3201 public void redraw (int x, int y, int width, int height, bool all) {
|
|
3202 checkWidget();
|
|
3203 if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return;
|
|
3204 if ((style & SWT.MIRRORED) !is 0) x = getClientWidth () - width - x;
|
|
3205 redrawWidget (x, y, width, height, false, all, false);
|
|
3206 }
|
|
3207
|
|
3208 void redrawChildren () {
|
|
3209 }
|
|
3210
|
|
3211 void redrawWidget (int x, int y, int width, int height, bool redrawAll, bool all, bool trim) {
|
|
3212 if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) is 0) return;
|
|
3213 auto window = paintWindow ();
|
|
3214 GdkRectangle rect;
|
|
3215 if (redrawAll) {
|
|
3216 int w, h;
|
|
3217 OS.gdk_drawable_get_size (cast(GdkDrawable*)window, &w, &h);
|
|
3218 rect.width = w;
|
|
3219 rect.height = h;
|
|
3220 } else {
|
|
3221 rect.x = x;
|
|
3222 rect.y = y;
|
|
3223 rect.width = width;
|
|
3224 rect.height = height;
|
|
3225 }
|
|
3226 OS.gdk_window_invalidate_rect (window, &rect, all);
|
|
3227 }
|
|
3228
|
|
3229 override void release (bool destroy) {
|
|
3230 Control next = null, previous = null;
|
|
3231 if (destroy && parent !is null) {
|
|
3232 Control[] children = parent._getChildren ();
|
|
3233 int index = 0;
|
|
3234 while (index < children.length) {
|
|
3235 if (children [index] is this) break;
|
|
3236 index++;
|
|
3237 }
|
|
3238 if (0 < index && (index + 1) < children.length) {
|
|
3239 next = children [index + 1];
|
|
3240 previous = children [index - 1];
|
|
3241 }
|
|
3242 }
|
|
3243 super.release (destroy);
|
|
3244 if (destroy) {
|
|
3245 if (previous !is null) previous.addRelation (next);
|
|
3246 }
|
|
3247 }
|
|
3248
|
|
3249 override void releaseHandle () {
|
|
3250 super.releaseHandle ();
|
|
3251 fixedHandle = null;
|
|
3252 parent = null;
|
|
3253 }
|
|
3254
|
|
3255 override void releaseParent () {
|
|
3256 parent.removeControl (this);
|
|
3257 }
|
|
3258
|
|
3259 override void releaseWidget () {
|
|
3260 super.releaseWidget ();
|
|
3261 if (display.currentControl is this) display.currentControl = null;
|
|
3262 display.removeMouseHoverTimeout (handle);
|
|
3263 auto imHandle = imHandle ();
|
|
3264 if (imHandle !is null) {
|
|
3265 OS.gtk_im_context_reset (imHandle);
|
|
3266 OS.gtk_im_context_set_client_window (imHandle, null);
|
|
3267 }
|
|
3268 if (enableWindow !is null) {
|
|
3269 OS.gdk_window_set_user_data (enableWindow, null);
|
|
3270 OS.gdk_window_destroy (enableWindow);
|
|
3271 enableWindow = null;
|
|
3272 }
|
|
3273 redrawWindow = null;
|
|
3274 if (menu !is null && !menu.isDisposed ()) {
|
|
3275 menu.dispose ();
|
|
3276 }
|
|
3277 menu = null;
|
|
3278 cursor = null;
|
|
3279 toolTipText = null;
|
|
3280 layoutData = null;
|
|
3281 accessible = null;
|
|
3282 region = null;
|
|
3283 }
|
|
3284
|
|
3285 bool sendDragEvent (int button, int stateMask, int x, int y, bool isStateMask) {
|
|
3286 Event event = new Event ();
|
|
3287 event.button = button;
|
|
3288 event.x = x;
|
|
3289 event.y = y;
|
|
3290 if ((style & SWT.MIRRORED) !is 0) event.x = getClientWidth () - event.x;
|
|
3291 if (isStateMask) {
|
|
3292 event.stateMask = stateMask;
|
|
3293 } else {
|
|
3294 setInputState (event, stateMask);
|
|
3295 }
|
|
3296 postEvent (SWT.DragDetect, event);
|
|
3297 if (isDisposed ()) return false;
|
|
3298 return event.doit;
|
|
3299 }
|
|
3300
|
|
3301 void sendFocusEvent (int type) {
|
|
3302 Shell shell = _getShell ();
|
|
3303 Display display = this.display;
|
|
3304 display.focusControl = this;
|
|
3305 display.focusEvent = type;
|
|
3306 sendEvent (type);
|
|
3307 display.focusControl = null;
|
|
3308 display.focusEvent = SWT.None;
|
|
3309 /*
|
|
3310 * It is possible that the shell may be
|
|
3311 * disposed at this point. If this happens
|
|
3312 * don't send the activate and deactivate
|
|
3313 * events.
|
|
3314 */
|
|
3315 if (!shell.isDisposed ()) {
|
|
3316 switch (type) {
|
|
3317 case SWT.FocusIn:
|
|
3318 shell.setActiveControl (this);
|
|
3319 break;
|
|
3320 case SWT.FocusOut:
|
|
3321 if (shell !is display.activeShell) {
|
|
3322 shell.setActiveControl (null);
|
|
3323 }
|
|
3324 break;
|
|
3325 default:
|
|
3326 }
|
|
3327 }
|
|
3328 }
|
|
3329
|
|
3330 bool sendHelpEvent (int /*long*/ helpType) {
|
|
3331 Control control = this;
|
|
3332 while (control !is null) {
|
|
3333 if (control.hooks (SWT.Help)) {
|
|
3334 control.postEvent (SWT.Help);
|
|
3335 return true;
|
|
3336 }
|
|
3337 control = control.parent;
|
|
3338 }
|
|
3339 return false;
|
|
3340 }
|
|
3341
|
|
3342 bool sendLeaveNotify() {
|
|
3343 return false;
|
|
3344 }
|
|
3345
|
|
3346 bool sendMouseEvent (int type, int button, int time, double x, double y, bool is_hint, int state) {
|
|
3347 return sendMouseEvent (type, button, 0, 0, false, time, x, y, is_hint, state);
|
|
3348 }
|
|
3349
|
|
3350 bool sendMouseEvent (int type, int button, int count, int detail, bool send, int time, double x, double y, bool is_hint, int state) {
|
|
3351 if (!hooks (type) && !filters (type)) return true;
|
|
3352 Event event = new Event ();
|
|
3353 event.time = time;
|
|
3354 event.button = button;
|
|
3355 event.detail = detail;
|
|
3356 event.count = count;
|
|
3357 if (is_hint) {
|
|
3358 event.x = cast(int)x;
|
|
3359 event.y = cast(int)y;
|
|
3360 } else {
|
|
3361 auto window = eventWindow ();
|
|
3362 int origin_x, origin_y;
|
|
3363 OS.gdk_window_get_origin (window, &origin_x, &origin_y);
|
|
3364 event.x = cast(int)x - origin_x;
|
|
3365 event.y = cast(int)y - origin_y;
|
|
3366 }
|
|
3367 if ((style & SWT.MIRRORED) !is 0) event.x = getClientWidth () - event.x;
|
|
3368 setInputState (event, state);
|
|
3369 if (send) {
|
|
3370 sendEvent (type, event);
|
|
3371 if (isDisposed ()) return false;
|
|
3372 } else {
|
|
3373 postEvent (type, event);
|
|
3374 }
|
|
3375 return event.doit;
|
|
3376 }
|
|
3377
|
|
3378 void setBackground () {
|
|
3379 if ((state & PARENT_BACKGROUND) !is 0 && (state & BACKGROUND) is 0 && backgroundImage is null) {
|
|
3380 setParentBackground ();
|
|
3381 } else {
|
|
3382 setWidgetBackground ();
|
|
3383 }
|
|
3384 redrawWidget (0, 0, 0, 0, true, false, false);
|
|
3385 }
|
|
3386
|
|
3387 /**
|
|
3388 * Sets the receiver's background color to the color specified
|
|
3389 * by the argument, or to the default system color for the control
|
|
3390 * if the argument is null.
|
|
3391 * <p>
|
|
3392 * Note: This operation is a hint and may be overridden by the platform.
|
|
3393 * For example, on Windows the background of a Button cannot be changed.
|
|
3394 * </p>
|
|
3395 * @param color the new color (or null)
|
|
3396 *
|
|
3397 * @exception IllegalArgumentException <ul>
|
|
3398 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
|
|
3399 * </ul>
|
|
3400 * @exception SWTException <ul>
|
|
3401 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3402 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3403 * </ul>
|
|
3404 */
|
|
3405 public void setBackground (Color color) {
|
|
3406 checkWidget();
|
|
3407 if (((state & BACKGROUND) is 0) && color is null) return;
|
|
3408 GdkColor* gdkColor = null;
|
|
3409 if (color !is null) {
|
|
3410 if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
|
|
3411 gdkColor = color.handle;
|
|
3412 }
|
|
3413 bool set = false;
|
|
3414 if (gdkColor is null) {
|
|
3415 auto style = OS.gtk_widget_get_modifier_style (handle);
|
|
3416 set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_BG) !is 0;
|
|
3417 } else {
|
|
3418 GdkColor* oldColor = getBackgroundColor ();
|
|
3419 set = oldColor.pixel !is gdkColor.pixel;
|
|
3420 }
|
|
3421 if (set) {
|
|
3422 if (color is null) {
|
|
3423 state &= ~BACKGROUND;
|
|
3424 } else {
|
|
3425 state |= BACKGROUND;
|
|
3426 }
|
|
3427 setBackgroundColor (gdkColor);
|
|
3428 redrawChildren ();
|
|
3429 }
|
|
3430 }
|
|
3431
|
|
3432 void setBackgroundColor (GtkWidget* handle, GdkColor* color) {
|
|
3433 int index = OS.GTK_STATE_NORMAL;
|
|
3434 auto style = OS.gtk_widget_get_modifier_style (handle);
|
|
3435 auto ptr = OS.gtk_rc_style_get_bg_pixmap_name (style, index);
|
|
3436 if (ptr !is null) OS.g_free (ptr);
|
|
3437 String name = color is null ? "<parent>" : "<none>" ;
|
|
3438 ptr = cast(char*)OS.g_malloc (name.length+1);
|
|
3439 ptr[ 0 .. name.length ] = name;
|
|
3440 ptr[ name.length ] = '\0';
|
|
3441 OS.gtk_rc_style_set_bg_pixmap_name (style, index, ptr);
|
|
3442 OS.gtk_rc_style_set_bg (style, index, color);
|
|
3443 int flags = OS.gtk_rc_style_get_color_flags (style, index);
|
|
3444 flags = (color is null) ? flags & ~OS.GTK_RC_BG : flags | OS.GTK_RC_BG;
|
|
3445 OS.gtk_rc_style_set_color_flags (style, index, flags);
|
|
3446 modifyStyle (handle, style);
|
|
3447 }
|
|
3448
|
|
3449 void setBackgroundColor (GdkColor* color) {
|
|
3450 setBackgroundColor (handle, color);
|
|
3451 }
|
|
3452
|
|
3453 /**
|
|
3454 * Sets the receiver's background image to the image specified
|
|
3455 * by the argument, or to the default system color for the control
|
|
3456 * if the argument is null. The background image is tiled to fill
|
|
3457 * the available space.
|
|
3458 * <p>
|
|
3459 * Note: This operation is a hint and may be overridden by the platform.
|
|
3460 * For example, on Windows the background of a Button cannot be changed.
|
|
3461 * </p>
|
|
3462 * @param image the new image (or null)
|
|
3463 *
|
|
3464 * @exception IllegalArgumentException <ul>
|
|
3465 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
|
|
3466 * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
|
|
3467 * </ul>
|
|
3468 * @exception SWTException <ul>
|
|
3469 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3470 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3471 * </ul>
|
|
3472 *
|
|
3473 * @since 3.2
|
|
3474 */
|
|
3475 public void setBackgroundImage (Image image) {
|
|
3476 checkWidget ();
|
|
3477 if (image !is null && image.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
|
|
3478 if (image is backgroundImage) return;
|
|
3479 this.backgroundImage = image;
|
|
3480 if (backgroundImage !is null) {
|
|
3481 setBackgroundPixmap (backgroundImage.pixmap);
|
|
3482 redrawWidget (0, 0, 0, 0, true, false, false);
|
|
3483 } else {
|
|
3484 setWidgetBackground ();
|
|
3485 }
|
|
3486 redrawChildren ();
|
|
3487 }
|
|
3488
|
|
3489 void setBackgroundPixmap (GdkDrawable* pixmap) {
|
|
3490 auto window = OS.GTK_WIDGET_WINDOW (paintHandle ());
|
|
3491 if (window !is null) OS.gdk_window_set_back_pixmap (window, cast(GdkPixmap*)backgroundImage.pixmap, false);
|
|
3492 }
|
|
3493
|
|
3494 /**
|
|
3495 * If the argument is <code>true</code>, causes the receiver to have
|
|
3496 * all mouse events delivered to it until the method is called with
|
|
3497 * <code>false</code> as the argument. Note that on some platforms,
|
|
3498 * a mouse button must currently be down for capture to be assigned.
|
|
3499 *
|
|
3500 * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
|
|
3501 *
|
|
3502 * @exception SWTException <ul>
|
|
3503 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3504 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3505 * </ul>
|
|
3506 */
|
|
3507 public void setCapture (bool capture) {
|
|
3508 checkWidget();
|
|
3509 /* FIXME !!!!! */
|
|
3510 /*
|
|
3511 if (capture) {
|
|
3512 OS.gtk_widget_grab_focus (handle);
|
|
3513 } else {
|
|
3514 OS.gtk_widget_grab_default (handle);
|
|
3515 }
|
|
3516 */
|
|
3517 }
|
|
3518 /**
|
|
3519 * Sets the receiver's cursor to the cursor specified by the
|
|
3520 * argument, or to the default cursor for that kind of control
|
|
3521 * if the argument is null.
|
|
3522 * <p>
|
|
3523 * When the mouse pointer passes over a control its appearance
|
|
3524 * is changed to match the control's cursor.
|
|
3525 * </p>
|
|
3526 *
|
|
3527 * @param cursor the new cursor (or null)
|
|
3528 *
|
|
3529 * @exception IllegalArgumentException <ul>
|
|
3530 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
|
|
3531 * </ul>
|
|
3532 * @exception SWTException <ul>
|
|
3533 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3534 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3535 * </ul>
|
|
3536 */
|
|
3537 public void setCursor (Cursor cursor) {
|
|
3538 checkWidget();
|
|
3539 if (cursor !is null && cursor.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
|
|
3540 this.cursor = cursor;
|
|
3541 gtk_setCursor (cursor !is null ? cursor.handle : null);
|
|
3542 }
|
|
3543
|
|
3544 void gtk_setCursor (GdkCursor* cursor) {
|
|
3545 auto window = eventWindow ();
|
|
3546 if (window !is null) {
|
|
3547 OS.gdk_window_set_cursor (window, cursor);
|
|
3548 if (!OS.GDK_WINDOWING_X11 ()) {
|
|
3549 OS.gdk_flush ();
|
|
3550 } else {
|
|
3551 auto xDisplay = OS.GDK_DISPLAY ();
|
|
3552 OS.XFlush (xDisplay);
|
|
3553 }
|
|
3554 }
|
|
3555 }
|
|
3556
|
|
3557 /**
|
|
3558 * Sets the receiver's drag detect state. If the argument is
|
|
3559 * <code>true</code>, the receiver will detect drag gestures,
|
|
3560 * otherwise these gestures will be ignored.
|
|
3561 *
|
|
3562 * @param dragDetect the new drag detect state
|
|
3563 *
|
|
3564 * @exception SWTException <ul>
|
|
3565 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3566 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3567 * </ul>
|
|
3568 *
|
|
3569 * @since 3.3
|
|
3570 */
|
|
3571 public void setDragDetect (bool dragDetect) {
|
|
3572 checkWidget ();
|
|
3573 if (dragDetect) {
|
|
3574 state |= DRAG_DETECT;
|
|
3575 } else {
|
|
3576 state &= ~DRAG_DETECT;
|
|
3577 }
|
|
3578 }
|
|
3579
|
|
3580 /**
|
|
3581 * Enables the receiver if the argument is <code>true</code>,
|
|
3582 * and disables it otherwise. A disabled control is typically
|
|
3583 * not selectable from the user interface and draws with an
|
|
3584 * inactive or "grayed" look.
|
|
3585 *
|
|
3586 * @param enabled the new enabled state
|
|
3587 *
|
|
3588 * @exception SWTException <ul>
|
|
3589 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3590 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3591 * </ul>
|
|
3592 */
|
|
3593 public void setEnabled (bool enabled) {
|
|
3594 checkWidget();
|
|
3595 if (((state & DISABLED) is 0) is enabled) return;
|
|
3596 Control control = null;
|
|
3597 bool fixFocus_ = false;
|
|
3598 if (!enabled) {
|
|
3599 if (display.focusEvent !is SWT.FocusOut) {
|
|
3600 control = display.getFocusControl ();
|
|
3601 fixFocus_ = isFocusAncestor (control);
|
|
3602 }
|
|
3603 }
|
|
3604 if (enabled) {
|
|
3605 state &= ~DISABLED;
|
|
3606 } else {
|
|
3607 state |= DISABLED;
|
|
3608 }
|
|
3609 enableWidget (enabled);
|
|
3610 if (isDisposed ()) return;
|
|
3611 if (enabled) {
|
|
3612 if (enableWindow !is null) {
|
|
3613 OS.gdk_window_set_user_data (enableWindow, null);
|
|
3614 OS.gdk_window_destroy (enableWindow);
|
|
3615 enableWindow = null;
|
|
3616 }
|
|
3617 } else {
|
|
3618 OS.gtk_widget_realize (handle);
|
|
3619 auto parentHandle = parent.eventHandle ();
|
|
3620 auto window = parent.eventWindow();
|
|
3621 auto topHandle_ = topHandle ();
|
|
3622 GdkWindowAttr attributes;
|
|
3623 attributes.x = OS.GTK_WIDGET_X (topHandle_);
|
|
3624 attributes.y = OS.GTK_WIDGET_Y (topHandle_);
|
|
3625 attributes.width = (state & ZERO_WIDTH) !is 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
3626 attributes.height = (state & ZERO_HEIGHT) !is 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle_);
|
|
3627 attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask);
|
|
3628 attributes.wclass = OS.GDK_INPUT_ONLY;
|
|
3629 attributes.window_type = OS.GDK_WINDOW_CHILD;
|
|
3630 enableWindow = OS.gdk_window_new (window, &attributes, OS.GDK_WA_X | OS.GDK_WA_Y);
|
|
3631 if (enableWindow !is null) {
|
|
3632 OS.gdk_window_set_user_data (enableWindow, parentHandle);
|
|
3633 if (!OS.GDK_WINDOWING_X11 ()) {
|
|
3634 OS.gdk_window_raise (enableWindow);
|
|
3635 } else {
|
|
3636 auto topWindow = OS.GTK_WIDGET_WINDOW (topHandle_);
|
|
3637 auto xDisplay = OS.gdk_x11_drawable_get_xdisplay (cast(GdkDrawable*)topWindow);
|
|
3638 auto xWindow = OS.gdk_x11_drawable_get_xid (cast(GdkDrawable*)enableWindow);
|
|
3639 int xScreen = OS.XDefaultScreen (xDisplay);
|
|
3640 int flags = OS.CWStackMode | OS.CWSibling;
|
|
3641 XWindowChanges changes;
|
|
3642 changes.sibling = OS.gdk_x11_drawable_get_xid (cast(GdkDrawable*)topWindow);
|
|
3643 changes.stack_mode = OS.Above;
|
|
3644 OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, &changes);
|
|
3645 }
|
|
3646 if (OS.GTK_WIDGET_VISIBLE (topHandle_)) OS.gdk_window_show_unraised (enableWindow);
|
|
3647 }
|
|
3648 }
|
|
3649 if (fixFocus_) fixFocus (control);
|
|
3650 }
|
|
3651
|
|
3652 /**
|
|
3653 * Causes the receiver to have the <em>keyboard focus</em>,
|
|
3654 * such that all keyboard events will be delivered to it. Focus
|
|
3655 * reassignment will respect applicable platform constraints.
|
|
3656 *
|
|
3657 * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
|
|
3658 *
|
|
3659 * @exception SWTException <ul>
|
|
3660 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3661 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3662 * </ul>
|
|
3663 *
|
|
3664 * @see #forceFocus
|
|
3665 */
|
|
3666 public bool setFocus () {
|
|
3667 checkWidget();
|
|
3668 if ((style & SWT.NO_FOCUS) !is 0) return false;
|
|
3669 return forceFocus ();
|
|
3670 }
|
|
3671
|
|
3672 /**
|
|
3673 * Sets the font that the receiver will use to paint textual information
|
|
3674 * to the font specified by the argument, or to the default font for that
|
|
3675 * kind of control if the argument is null.
|
|
3676 *
|
|
3677 * @param font the new font (or null)
|
|
3678 *
|
|
3679 * @exception IllegalArgumentException <ul>
|
|
3680 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
|
|
3681 * </ul>
|
|
3682 * @exception SWTException <ul>
|
|
3683 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3684 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3685 * </ul>
|
|
3686 */
|
|
3687 public void setFont (Font font) {
|
|
3688 checkWidget();
|
|
3689 if (((state & FONT) is 0) && font is null) return;
|
|
3690 this.font = font;
|
|
3691 PangoFontDescription* fontDesc;
|
|
3692 if (font is null) {
|
|
3693 fontDesc = defaultFont ().handle;
|
|
3694 } else {
|
|
3695 if (font.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
|
|
3696 fontDesc = font.handle;
|
|
3697 }
|
|
3698 if (font is null) {
|
|
3699 state &= ~FONT;
|
|
3700 } else {
|
|
3701 state |= FONT;
|
|
3702 }
|
|
3703 setFontDescription (fontDesc);
|
|
3704 }
|
|
3705
|
|
3706 void setFontDescription (PangoFontDescription* font) {
|
|
3707 OS.gtk_widget_modify_font (handle, font);
|
|
3708 }
|
|
3709
|
|
3710 /**
|
|
3711 * Sets the receiver's foreground color to the color specified
|
|
3712 * by the argument, or to the default system color for the control
|
|
3713 * if the argument is null.
|
|
3714 * <p>
|
|
3715 * Note: This operation is a hint and may be overridden by the platform.
|
|
3716 * </p>
|
|
3717 * @param color the new color (or null)
|
|
3718 *
|
|
3719 * @exception IllegalArgumentException <ul>
|
|
3720 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
|
|
3721 * </ul>
|
|
3722 * @exception SWTException <ul>
|
|
3723 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3724 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3725 * </ul>
|
|
3726 */
|
|
3727 public void setForeground (Color color) {
|
|
3728 checkWidget();
|
|
3729 if (((state & FOREGROUND) is 0) && color is null) return;
|
|
3730 GdkColor* gdkColor = null;
|
|
3731 if (color !is null) {
|
|
3732 if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
|
|
3733 gdkColor = color.handle;
|
|
3734 }
|
|
3735 bool set = false;
|
|
3736 if (gdkColor is null) {
|
|
3737 auto style = OS.gtk_widget_get_modifier_style (handle);
|
|
3738 set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_FG) !is 0;
|
|
3739 } else {
|
|
3740 GdkColor* oldColor = getForegroundColor ();
|
|
3741 set = oldColor.pixel !is gdkColor.pixel;
|
|
3742 }
|
|
3743 if (set) {
|
|
3744 if (color is null) {
|
|
3745 state &= ~FOREGROUND;
|
|
3746 } else {
|
|
3747 state |= FOREGROUND;
|
|
3748 }
|
|
3749 setForegroundColor (gdkColor);
|
|
3750 }
|
|
3751 }
|
|
3752
|
|
3753 void setForegroundColor (GdkColor* color) {
|
|
3754 setForegroundColor (handle, color);
|
|
3755 }
|
|
3756
|
|
3757 void setInitialBounds () {
|
|
3758 if ((state & ZERO_WIDTH) !is 0 && (state & ZERO_HEIGHT) !is 0) {
|
|
3759 /*
|
|
3760 * Feature in GTK. On creation, each widget's allocation is
|
|
3761 * initialized to a position of (-1, -1) until the widget is
|
|
3762 * first sized. The fix is to set the value to (0, 0) as
|
|
3763 * expected by SWT.
|
|
3764 */
|
|
3765 auto topHandle_ = topHandle ();
|
|
3766 if ((parent.style & SWT.MIRRORED) !is 0) {
|
|
3767 OS.GTK_WIDGET_SET_X (topHandle_, parent.getClientWidth ());
|
|
3768 } else {
|
|
3769 OS.GTK_WIDGET_SET_X (topHandle_, 0);
|
|
3770 }
|
|
3771 OS.GTK_WIDGET_SET_Y (topHandle_, 0);
|
|
3772 } else {
|
|
3773 resizeHandle (1, 1);
|
|
3774 forceResize ();
|
|
3775 }
|
|
3776 }
|
|
3777
|
|
3778 /**
|
|
3779 * Sets the receiver's pop up menu to the argument.
|
|
3780 * All controls may optionally have a pop up
|
|
3781 * menu that is displayed when the user requests one for
|
|
3782 * the control. The sequence of key strokes, button presses
|
|
3783 * and/or button releases that are used to request a pop up
|
|
3784 * menu is platform specific.
|
|
3785 * <p>
|
|
3786 * Note: Disposing of a control that has a pop up menu will
|
|
3787 * dispose of the menu. To avoid this behavior, set the
|
|
3788 * menu to null before the control is disposed.
|
|
3789 * </p>
|
|
3790 *
|
|
3791 * @param menu the new pop up menu
|
|
3792 *
|
|
3793 * @exception IllegalArgumentException <ul>
|
|
3794 * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
|
|
3795 * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
|
|
3796 * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
|
|
3797 * </ul>
|
|
3798 * @exception SWTException <ul>
|
|
3799 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3800 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3801 * </ul>
|
|
3802 */
|
|
3803 public void setMenu (Menu menu) {
|
|
3804 checkWidget();
|
|
3805 if (menu !is null) {
|
|
3806 if ((menu.style & SWT.POP_UP) is 0) {
|
|
3807 error (SWT.ERROR_MENU_NOT_POP_UP);
|
|
3808 }
|
|
3809 if (menu.parent !is menuShell ()) {
|
|
3810 error (SWT.ERROR_INVALID_PARENT);
|
|
3811 }
|
|
3812 }
|
|
3813 this.menu = menu;
|
|
3814 }
|
|
3815
|
|
3816 override void setOrientation () {
|
|
3817 if ((style & SWT.RIGHT_TO_LEFT) !is 0) {
|
|
3818 if (handle !is null) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL);
|
|
3819 if (fixedHandle !is null) OS.gtk_widget_set_direction (fixedHandle, OS.GTK_TEXT_DIR_RTL);
|
|
3820 }
|
|
3821 }
|
|
3822
|
|
3823 /**
|
|
3824 * Changes the parent of the widget to be the one provided if
|
|
3825 * the underlying operating system supports this feature.
|
|
3826 * Returns <code>true</code> if the parent is successfully changed.
|
|
3827 *
|
|
3828 * @param parent the new parent for the control.
|
|
3829 * @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
|
|
3830 *
|
|
3831 * @exception IllegalArgumentException <ul>
|
|
3832 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
|
|
3833 * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
|
|
3834 * </ul>
|
|
3835 * @exception SWTException <ul>
|
|
3836 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3837 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3838 * </ul>
|
|
3839 */
|
|
3840 public bool setParent (Composite parent) {
|
|
3841 checkWidget ();
|
|
3842 if (parent is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
|
|
3843 if (parent.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
|
|
3844 if (this.parent is parent) return true;
|
|
3845 if (!isReparentable ()) return false;
|
|
3846 auto topHandle_ = topHandle ();
|
|
3847 int x = OS.GTK_WIDGET_X (topHandle_);
|
|
3848 int width = (state & ZERO_WIDTH) !is 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle_);
|
|
3849 if ((this.parent.style & SWT.MIRRORED) !is 0) {
|
|
3850 x = this.parent.getClientWidth () - width - x;
|
|
3851 }
|
|
3852 if ((parent.style & SWT.MIRRORED) !is 0) {
|
|
3853 x = parent.getClientWidth () - width - x;
|
|
3854 }
|
|
3855 int y = OS.GTK_WIDGET_Y (topHandle_);
|
|
3856 releaseParent ();
|
|
3857 Shell newShell = parent.getShell (), oldShell = getShell ();
|
|
3858 Decorations newDecorations = parent.menuShell (), oldDecorations = menuShell ();
|
|
3859 Menu [] menus = oldShell.findMenus (this);
|
|
3860 if (oldShell !is newShell || oldDecorations !is newDecorations) {
|
|
3861 fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
|
|
3862 newDecorations.fixAccelGroup ();
|
|
3863 oldDecorations.fixAccelGroup ();
|
|
3864 }
|
|
3865 auto newParent = parent.parentingHandle();
|
|
3866 OS.gtk_widget_reparent (topHandle_, newParent);
|
|
3867 OS.gtk_fixed_move (cast(GtkFixed*)newParent, topHandle_, x, y);
|
|
3868 this.parent = parent;
|
|
3869 setZOrder (null, false, true);
|
|
3870 return true;
|
|
3871 }
|
|
3872
|
|
3873 void setParentBackground () {
|
|
3874 setBackgroundColor (handle, null);
|
|
3875 if (fixedHandle !is null) setBackgroundColor (fixedHandle, null);
|
|
3876 }
|
|
3877
|
|
3878 void setParentWindow (GtkWidget* widget) {
|
|
3879 }
|
|
3880
|
|
3881 bool setRadioSelection (bool value) {
|
|
3882 return false;
|
|
3883 }
|
|
3884
|
|
3885 /**
|
|
3886 * If the argument is <code>false</code>, causes subsequent drawing
|
|
3887 * operations in the receiver to be ignored. No drawing of any kind
|
|
3888 * can occur in the receiver until the flag is set to true.
|
|
3889 * Graphics operations that occurred while the flag was
|
|
3890 * <code>false</code> are lost. When the flag is set to <code>true</code>,
|
|
3891 * the entire widget is marked as needing to be redrawn. Nested calls
|
|
3892 * to this method are stacked.
|
|
3893 * <p>
|
|
3894 * Note: This operation is a hint and may not be supported on some
|
|
3895 * platforms or for some widgets.
|
|
3896 * </p>
|
|
3897 *
|
|
3898 * @param redraw the new redraw state
|
|
3899 *
|
|
3900 * @exception SWTException <ul>
|
|
3901 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3902 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3903 * </ul>
|
|
3904 *
|
|
3905 * @see #redraw(int, int, int, int, bool)
|
|
3906 * @see #update()
|
|
3907 */
|
|
3908 public void setRedraw (bool redraw) {
|
|
3909 checkWidget();
|
|
3910 if (redraw) {
|
|
3911 if (--drawCount is 0) {
|
|
3912 if (redrawWindow !is null) {
|
|
3913 auto window = paintWindow ();
|
|
3914 /* Explicitly hiding the window avoids flicker on GTK+ >= 2.6 */
|
|
3915 OS.gdk_window_hide (redrawWindow);
|
|
3916 OS.gdk_window_destroy (redrawWindow);
|
|
3917 OS.gdk_window_set_events (window, OS.gtk_widget_get_events (paintHandle ()));
|
|
3918 redrawWindow = null;
|
|
3919 }
|
|
3920 }
|
|
3921 } else {
|
|
3922 if (drawCount++ is 0) {
|
|
3923 if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) !is 0) {
|
|
3924 auto window = paintWindow ();
|
|
3925 Rectangle rect = getBounds ();
|
|
3926 GdkWindowAttr attributes;
|
|
3927 attributes.width = rect.width;
|
|
3928 attributes.height = rect.height;
|
|
3929 attributes.event_mask = OS.GDK_EXPOSURE_MASK;
|
|
3930 attributes.window_type = OS.GDK_WINDOW_CHILD;
|
|
3931 redrawWindow = OS.gdk_window_new (window, &attributes, 0);
|
|
3932 if (redrawWindow !is null) {
|
|
3933 int mouseMask = OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK |
|
|
3934 OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK |
|
|
3935 OS.GDK_POINTER_MOTION_MASK | OS.GDK_POINTER_MOTION_HINT_MASK |
|
|
3936 OS.GDK_BUTTON_MOTION_MASK | OS.GDK_BUTTON1_MOTION_MASK |
|
|
3937 OS.GDK_BUTTON2_MOTION_MASK | OS.GDK_BUTTON3_MOTION_MASK;
|
|
3938 OS.gdk_window_set_events (window, OS.gdk_window_get_events (window) & ~mouseMask);
|
|
3939 OS.gdk_window_set_back_pixmap (redrawWindow, null, false);
|
|
3940 OS.gdk_window_show (redrawWindow);
|
|
3941 }
|
|
3942 }
|
|
3943 }
|
|
3944 }
|
|
3945 }
|
|
3946
|
|
3947 bool setTabGroupFocus (bool next) {
|
|
3948 return setTabItemFocus (next);
|
|
3949 }
|
|
3950 bool setTabItemFocus (bool next) {
|
|
3951 if (!isShowing ()) return false;
|
|
3952 return forceFocus ();
|
|
3953 }
|
|
3954
|
|
3955 /**
|
|
3956 * Sets the receiver's tool tip text to the argument, which
|
|
3957 * may be null indicating that no tool tip text should be shown.
|
|
3958 *
|
|
3959 * @param str the new tool tip text (or null)
|
|
3960 *
|
|
3961 * @exception SWTException <ul>
|
|
3962 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
3963 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
3964 * </ul>
|
|
3965 */
|
|
3966 public void setToolTipText (String str) {
|
|
3967 checkWidget();
|
|
3968 setToolTipText (_getShell (), str);
|
|
3969 toolTipText = str;
|
|
3970 }
|
|
3971
|
|
3972 void setToolTipText (Shell shell, String newString) {
|
|
3973 if (OS.GTK_VERSION >= OS.buildVERSION (2, 12, 0)) {
|
|
3974 /*
|
|
3975 * Feature in GTK. In order to prevent children widgets
|
|
3976 * from inheriting their parent's tooltip, the tooltip is
|
|
3977 * a set on a shell only. In order to force the shell tooltip
|
|
3978 * to update when a new tip string is set, the existing string
|
|
3979 * in the tooltip is set to null, followed by running a query.
|
|
3980 * The real tip text can then be set.
|
|
3981 *
|
|
3982 * Note that this will only run if the control for which the
|
|
3983 * tooltip is being set is the current control (i.e. the control
|
|
3984 * under the pointer).
|
|
3985 */
|
|
3986 if (display.currentControl is this) {
|
|
3987 shell.setToolTipText (shell.handle, eventHandle (), newString);
|
|
3988 }
|
|
3989 } else {
|
|
3990 shell.setToolTipText (eventHandle (), newString);
|
|
3991 }
|
|
3992 }
|
|
3993
|
|
3994 /**
|
|
3995 * Marks the receiver as visible if the argument is <code>true</code>,
|
|
3996 * and marks it invisible otherwise.
|
|
3997 * <p>
|
|
3998 * If one of the receiver's ancestors is not visible or some
|
|
3999 * other condition makes the receiver not visible, marking
|
|
4000 * it visible may not actually cause it to be displayed.
|
|
4001 * </p>
|
|
4002 *
|
|
4003 * @param visible the new visibility state
|
|
4004 *
|
|
4005 * @exception SWTException <ul>
|
|
4006 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
4007 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
4008 * </ul>
|
|
4009 */
|
|
4010 public void setVisible (bool visible) {
|
|
4011 checkWidget();
|
|
4012 if (((state & HIDDEN) is 0) is visible) return;
|
|
4013 auto topHandle_ = topHandle();
|
|
4014 if (visible) {
|
|
4015 /*
|
|
4016 * It is possible (but unlikely), that application
|
|
4017 * code could have disposed the widget in the show
|
|
4018 * event. If this happens, just return.
|
|
4019 */
|
|
4020 sendEvent (SWT.Show);
|
|
4021 if (isDisposed ()) return;
|
|
4022 state &= ~HIDDEN;
|
|
4023 if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) is 0) {
|
|
4024 if (enableWindow !is null) OS.gdk_window_show_unraised (enableWindow);
|
|
4025 OS.gtk_widget_show (topHandle_);
|
|
4026 }
|
|
4027 } else {
|
|
4028 /*
|
|
4029 * Bug in GTK. Invoking gtk_widget_hide() on a widget that has
|
|
4030 * focus causes a focus_out_event to be sent. If the client disposes
|
|
4031 * the widget inside the event, GTK GP's. The fix is to reassign focus
|
|
4032 * before hiding the widget.
|
|
4033 *
|
|
4034 * NOTE: In order to stop the same widget from taking focus,
|
|
4035 * temporarily clear and set the GTK_VISIBLE flag.
|
|
4036 */
|
|
4037 Control control = null;
|
|
4038 bool fixFocus_ = false;
|
|
4039 if (display.focusEvent !is SWT.FocusOut) {
|
|
4040 control = display.getFocusControl ();
|
|
4041 fixFocus_ = isFocusAncestor (control);
|
|
4042 }
|
|
4043 state |= HIDDEN;
|
|
4044 if (fixFocus_) {
|
|
4045 OS.GTK_WIDGET_UNSET_FLAGS (topHandle_, OS.GTK_VISIBLE);
|
|
4046 fixFocus (control);
|
|
4047 if (isDisposed ()) return;
|
|
4048 OS.GTK_WIDGET_SET_FLAGS (topHandle_, OS.GTK_VISIBLE);
|
|
4049 }
|
|
4050 OS.gtk_widget_hide (topHandle_);
|
|
4051 if (isDisposed ()) return;
|
|
4052 if (enableWindow !is null) OS.gdk_window_hide (enableWindow);
|
|
4053 sendEvent (SWT.Hide);
|
|
4054 }
|
|
4055 }
|
|
4056
|
|
4057 void setZOrder (Control sibling, bool above, bool fixRelations) {
|
|
4058 setZOrder (sibling, above, fixRelations, true);
|
|
4059 }
|
|
4060
|
|
4061 void setZOrder (Control sibling, bool above, bool fixRelations, bool fixChildren) {
|
|
4062 int index = 0, siblingIndex = 0, oldNextIndex = -1;
|
|
4063 Control[] children = null;
|
|
4064 if (fixRelations) {
|
|
4065 /* determine the receiver's and sibling's indexes in the parent */
|
|
4066 children = parent._getChildren ();
|
|
4067 while (index < children.length) {
|
|
4068 if (children [index] is this) break;
|
|
4069 index++;
|
|
4070 }
|
|
4071 if (sibling !is null) {
|
|
4072 while (siblingIndex < children.length) {
|
|
4073 if (children [siblingIndex] is sibling) break;
|
|
4074 siblingIndex++;
|
|
4075 }
|
|
4076 }
|
|
4077 /* remove "Labelled by" relationships that will no longer be valid */
|
|
4078 removeRelation ();
|
|
4079 if (index + 1 < children.length) {
|
|
4080 oldNextIndex = index + 1;
|
|
4081 children [oldNextIndex].removeRelation ();
|
|
4082 }
|
|
4083 if (sibling !is null) {
|
|
4084 if (above) {
|
|
4085 sibling.removeRelation ();
|
|
4086 } else {
|
|
4087 if (siblingIndex + 1 < children.length) {
|
|
4088 children [siblingIndex + 1].removeRelation ();
|
|
4089 }
|
|
4090 }
|
|
4091 }
|
|
4092 }
|
|
4093
|
|
4094 auto topHandle_ = topHandle ();
|
|
4095 auto siblingHandle = sibling !is null ? sibling.topHandle () : null;
|
|
4096 auto window = OS.GTK_WIDGET_WINDOW (topHandle_);
|
|
4097 if (window !is null) {
|
|
4098 GdkWindow* siblingWindow;
|
|
4099 if (sibling !is null) {
|
|
4100 if (above && sibling.enableWindow !is null) {
|
|
4101 siblingWindow = enableWindow;
|
|
4102 } else {
|
|
4103 siblingWindow = OS.GTK_WIDGET_WINDOW (siblingHandle);
|
|
4104 }
|
|
4105 }
|
|
4106 auto redrawWindow = fixChildren ? parent.redrawWindow : null;
|
|
4107 if (!OS.GDK_WINDOWING_X11 () || (siblingWindow is null && (!above || redrawWindow is null))) {
|
|
4108 if (above) {
|
|
4109 OS.gdk_window_raise (window);
|
|
4110 if (redrawWindow !is null) OS.gdk_window_raise (redrawWindow);
|
|
4111 if (enableWindow !is null) OS.gdk_window_raise (enableWindow);
|
|
4112 } else {
|
|
4113 if (enableWindow !is null) OS.gdk_window_lower (enableWindow);
|
|
4114 OS.gdk_window_lower (window);
|
|
4115 }
|
|
4116 } else {
|
|
4117 XWindowChanges changes;
|
|
4118 changes.sibling = OS.gdk_x11_drawable_get_xid (cast(GdkDrawable*)(siblingWindow !is null ? siblingWindow : redrawWindow));
|
|
4119 changes.stack_mode = above ? OS.Above : OS.Below;
|
|
4120 if (redrawWindow !is null && siblingWindow is null) changes.stack_mode = OS.Below;
|
|
4121 auto xDisplay = OS.gdk_x11_drawable_get_xdisplay (cast(GdkDrawable*)window);
|
|
4122 auto xWindow = OS.gdk_x11_drawable_get_xid (cast(GdkDrawable*)window);
|
|
4123 int xScreen = OS.XDefaultScreen (xDisplay);
|
|
4124 int flags = OS.CWStackMode | OS.CWSibling;
|
|
4125 /*
|
|
4126 * Feature in X. If the receiver is a top level, XConfigureWindow ()
|
|
4127 * will fail (with a BadMatch error) for top level shells because top
|
|
4128 * level shells are reparented by the window manager and do not share
|
|
4129 * the same X window parent. This is the correct behavior but it is
|
|
4130 * unexpected. The fix is to use XReconfigureWMWindow () instead.
|
|
4131 * When the receiver is not a top level shell, XReconfigureWMWindow ()
|
|
4132 * behaves the same as XConfigureWindow ().
|
|
4133 */
|
|
4134 OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, &changes);
|
|
4135 if (enableWindow !is null) {
|
|
4136 changes.sibling = OS.gdk_x11_drawable_get_xid (cast(GdkDrawable*)window);
|
|
4137 changes.stack_mode = OS.Above;
|
|
4138 xWindow = OS.gdk_x11_drawable_get_xid (cast(GdkDrawable*)enableWindow);
|
|
4139 OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, &changes);
|
|
4140 }
|
|
4141 }
|
|
4142 }
|
|
4143 if (fixChildren) {
|
|
4144 if (above) {
|
|
4145 parent.moveAbove (topHandle_, siblingHandle);
|
|
4146 } else {
|
|
4147 parent.moveBelow (topHandle_, siblingHandle);
|
|
4148 }
|
|
4149 }
|
|
4150 /* Make sure that the parent internal windows are on the bottom of the stack */
|
|
4151 if (!above && fixChildren) parent.fixZOrder ();
|
|
4152
|
|
4153 if (fixRelations) {
|
|
4154 /* determine the receiver's new index in the parent */
|
|
4155 if (sibling !is null) {
|
|
4156 if (above) {
|
|
4157 index = siblingIndex - (index < siblingIndex ? 1 : 0);
|
|
4158 } else {
|
|
4159 index = siblingIndex + (siblingIndex < index ? 1 : 0);
|
|
4160 }
|
|
4161 } else {
|
|
4162 if (above) {
|
|
4163 index = 0;
|
|
4164 } else {
|
|
4165 index = children.length - 1;
|
|
4166 }
|
|
4167 }
|
|
4168
|
|
4169 /* add new "Labelled by" relations as needed */
|
|
4170 children = parent._getChildren ();
|
|
4171 if (0 < index) {
|
|
4172 children [index - 1].addRelation (this);
|
|
4173 }
|
|
4174 if (index + 1 < children.length) {
|
|
4175 addRelation (children [index + 1]);
|
|
4176 }
|
|
4177 if (oldNextIndex !is -1) {
|
|
4178 if (oldNextIndex <= index) oldNextIndex--;
|
|
4179 /* the last two conditions below ensure that duplicate relations are not hooked */
|
|
4180 if (0 < oldNextIndex && oldNextIndex !is index && oldNextIndex !is index + 1) {
|
|
4181 children [oldNextIndex - 1].addRelation (children [oldNextIndex]);
|
|
4182 }
|
|
4183 }
|
|
4184 }
|
|
4185 }
|
|
4186
|
|
4187 void setWidgetBackground () {
|
|
4188 if (fixedHandle !is null) {
|
|
4189 auto style = OS.gtk_widget_get_modifier_style (fixedHandle);
|
|
4190 modifyStyle (fixedHandle, style);
|
|
4191 }
|
|
4192 auto style = OS.gtk_widget_get_modifier_style (handle);
|
|
4193 modifyStyle (handle, style);
|
|
4194 }
|
|
4195
|
|
4196 bool showMenu (int x, int y) {
|
|
4197 Event event = new Event ();
|
|
4198 event.x = x;
|
|
4199 event.y = y;
|
|
4200 sendEvent (SWT.MenuDetect, event);
|
|
4201 if (event.doit) {
|
|
4202 if (menu !is null && !menu.isDisposed ()) {
|
|
4203 bool hooksKeys = hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
|
|
4204 menu.createIMMenu (hooksKeys ? imHandle() : null);
|
|
4205 if (event.x !is x || event.y !is y) {
|
|
4206 menu.setLocation (event.x, event.y);
|
|
4207 }
|
|
4208 menu.setVisible (true);
|
|
4209 return true;
|
|
4210 }
|
|
4211 }
|
|
4212 return false;
|
|
4213 }
|
|
4214
|
|
4215 void showWidget () {
|
|
4216 // Comment this line to disable zero-sized widgets
|
|
4217 state |= ZERO_WIDTH | ZERO_HEIGHT;
|
|
4218 auto topHandle_ = topHandle ();
|
|
4219 auto parentHandle = parent.parentingHandle ();
|
|
4220 parent.setParentWindow (topHandle_);
|
|
4221 OS.gtk_container_add (cast(GtkContainer*)parentHandle, topHandle_);
|
|
4222 if (handle !is null && handle !is topHandle_) OS.gtk_widget_show (handle);
|
|
4223 if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) is 0) {
|
|
4224 if (fixedHandle !is null) OS.gtk_widget_show (fixedHandle);
|
|
4225 }
|
|
4226 if (fixedHandle !is null) fixStyle (fixedHandle);
|
|
4227 }
|
|
4228
|
|
4229 void sort (int [] items) {
|
|
4230 /* Shell Sort from K&R, pg 108 */
|
|
4231 int length = items.length;
|
|
4232 for (int gap=length/2; gap>0; gap/=2) {
|
|
4233 for (int i=gap; i<length; i++) {
|
|
4234 for (int j=i-gap; j>=0; j-=gap) {
|
|
4235 if (items [j] <= items [j + gap]) {
|
|
4236 int swap = items [j];
|
|
4237 items [j] = items [j + gap];
|
|
4238 items [j + gap] = swap;
|
|
4239 }
|
|
4240 }
|
|
4241 }
|
|
4242 }
|
|
4243 }
|
|
4244
|
|
4245 /**
|
|
4246 * Based on the argument, perform one of the expected platform
|
|
4247 * traversal action. The argument should be one of the constants:
|
|
4248 * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
|
|
4249 * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
|
|
4250 * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
|
|
4251 *
|
|
4252 * @param traversal the type of traversal
|
|
4253 * @return true if the traversal succeeded
|
|
4254 *
|
|
4255 * @exception SWTException <ul>
|
|
4256 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
4257 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
4258 * </ul>
|
|
4259 */
|
|
4260 public bool traverse (int traversal) {
|
|
4261 checkWidget ();
|
|
4262 Event event = new Event ();
|
|
4263 event.doit = true;
|
|
4264 event.detail = traversal;
|
|
4265 return traverse (event);
|
|
4266 }
|
|
4267
|
|
4268 bool translateMnemonic (Event event, Control control) {
|
|
4269 if (control is this) return false;
|
|
4270 if (!isVisible () || !isEnabled ()) return false;
|
|
4271 event.doit = this is display.mnemonicControl || mnemonicMatch (event.character);
|
|
4272 return traverse (event);
|
|
4273 }
|
|
4274
|
|
4275 bool translateMnemonic (int keyval, GdkEventKey* gdkEvent) {
|
|
4276 int key = OS.gdk_keyval_to_unicode (keyval);
|
|
4277 if (key < 0x20) return false;
|
|
4278 if (gdkEvent.state is 0) {
|
|
4279 int code = traversalCode (keyval, gdkEvent);
|
|
4280 if ((code & SWT.TRAVERSE_MNEMONIC) is 0) return false;
|
|
4281 } else {
|
|
4282 Shell shell = _getShell ();
|
|
4283 int mask = OS.GDK_CONTROL_MASK | OS.GDK_SHIFT_MASK | OS.GDK_MOD1_MASK;
|
|
4284 if ((gdkEvent.state & mask) !is OS.gtk_window_get_mnemonic_modifier (cast(GtkWindow*)shell.shellHandle)) return false;
|
|
4285 }
|
|
4286 Decorations shell = menuShell ();
|
|
4287 if (shell.isVisible () && shell.isEnabled ()) {
|
|
4288 Event event = new Event ();
|
|
4289 event.detail = SWT.TRAVERSE_MNEMONIC;
|
|
4290 if (setKeyState (event, gdkEvent)) {
|
|
4291 return translateMnemonic (event, null) || shell.translateMnemonic (event, this);
|
|
4292 }
|
|
4293 }
|
|
4294 return false;
|
|
4295 }
|
|
4296
|
|
4297 bool translateTraversal (GdkEventKey* keyEvent) {
|
|
4298 int detail = SWT.TRAVERSE_NONE;
|
|
4299 int key = keyEvent.keyval;
|
|
4300 int code = traversalCode (key, keyEvent);
|
|
4301 bool all = false;
|
|
4302 switch (key) {
|
|
4303 case OS.GDK_Escape: {
|
|
4304 all = true;
|
|
4305 detail = SWT.TRAVERSE_ESCAPE;
|
|
4306 break;
|
|
4307 }
|
|
4308 case OS.GDK_KP_Enter:
|
|
4309 case OS.GDK_Return: {
|
|
4310 all = true;
|
|
4311 detail = SWT.TRAVERSE_RETURN;
|
|
4312 break;
|
|
4313 }
|
|
4314 case OS.GDK_ISO_Left_Tab:
|
|
4315 case OS.GDK_Tab: {
|
|
4316 bool next = (keyEvent.state & OS.GDK_SHIFT_MASK) is 0;
|
|
4317 detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
|
|
4318 break;
|
|
4319 }
|
|
4320 case OS.GDK_Up:
|
|
4321 case OS.GDK_Left:
|
|
4322 case OS.GDK_Down:
|
|
4323 case OS.GDK_Right: {
|
|
4324 bool next = key is OS.GDK_Down || key is OS.GDK_Right;
|
|
4325 if (parent !is null && (parent.style & SWT.MIRRORED) !is 0) {
|
|
4326 if (key is OS.GDK_Left || key is OS.GDK_Right) next = !next;
|
|
4327 }
|
|
4328 detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS;
|
|
4329 break;
|
|
4330 }
|
|
4331 case OS.GDK_Page_Up:
|
|
4332 case OS.GDK_Page_Down: {
|
|
4333 all = true;
|
|
4334 if ((keyEvent.state & OS.GDK_CONTROL_MASK) is 0) return false;
|
|
4335 detail = key is OS.GDK_Page_Down ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
|
|
4336 break;
|
|
4337 }
|
|
4338 default:
|
|
4339 return false;
|
|
4340 }
|
|
4341 Event event = new Event ();
|
|
4342 event.doit = (code & detail) !is 0;
|
|
4343 event.detail = detail;
|
|
4344 event.time = keyEvent.time;
|
|
4345 if (!setKeyState (event, keyEvent)) return false;
|
|
4346 Shell shell = getShell ();
|
|
4347 Control control = this;
|
|
4348 do {
|
|
4349 if (control.traverse (event)) return true;
|
|
4350 if (!event.doit && control.hooks (SWT.Traverse)) return false;
|
|
4351 if (control is shell) return false;
|
|
4352 control = control.parent;
|
|
4353 } while (all && control !is null);
|
|
4354 return false;
|
|
4355 }
|
|
4356
|
|
4357 int traversalCode (int key, GdkEventKey* event) {
|
|
4358 int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS;
|
|
4359 Shell shell = getShell ();
|
|
4360 if (shell.parent !is null) code |= SWT.TRAVERSE_ESCAPE;
|
|
4361 return code;
|
|
4362 }
|
|
4363
|
|
4364 bool traverse (Event event) {
|
|
4365 /*
|
|
4366 * It is possible (but unlikely), that application
|
|
4367 * code could have disposed the widget in the traverse
|
|
4368 * event. If this happens, return true to stop further
|
|
4369 * event processing.
|
|
4370 */
|
|
4371 sendEvent (SWT.Traverse, event);
|
|
4372 if (isDisposed ()) return true;
|
|
4373 if (!event.doit) return false;
|
|
4374 switch (event.detail) {
|
|
4375 case SWT.TRAVERSE_NONE: return true;
|
|
4376 case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
|
|
4377 case SWT.TRAVERSE_RETURN: return traverseReturn ();
|
|
4378 case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
|
|
4379 case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
|
|
4380 case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
|
|
4381 case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
|
|
4382 case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event.character);
|
|
4383 case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true);
|
|
4384 case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false);
|
|
4385 default:
|
|
4386 }
|
|
4387 return false;
|
|
4388 }
|
|
4389
|
|
4390 bool traverseEscape () {
|
|
4391 return false;
|
|
4392 }
|
|
4393
|
|
4394 bool traverseGroup (bool next) {
|
|
4395 Control root = computeTabRoot ();
|
|
4396 Control group = computeTabGroup ();
|
|
4397 Control [] list = root.computeTabList ();
|
|
4398 int length = list.length;
|
|
4399 int index = 0;
|
|
4400 while (index < length) {
|
|
4401 if (list [index] is group) break;
|
|
4402 index++;
|
|
4403 }
|
|
4404 /*
|
|
4405 * It is possible (but unlikely), that application
|
|
4406 * code could have disposed the widget in focus in
|
|
4407 * or out events. Ensure that a disposed widget is
|
|
4408 * not accessed.
|
|
4409 */
|
|
4410 if (index is length) return false;
|
|
4411 int start = index, offset = (next) ? 1 : -1;
|
|
4412 while ((index = ((index + offset + length) % length)) !is start) {
|
|
4413 Control control = list [index];
|
|
4414 if (!control.isDisposed () && control.setTabGroupFocus (next)) {
|
|
4415 return true;
|
|
4416 }
|
|
4417 }
|
|
4418 if (group.isDisposed ()) return false;
|
|
4419 return group.setTabGroupFocus (next);
|
|
4420 }
|
|
4421
|
|
4422 bool traverseItem (bool next) {
|
|
4423 Control [] children = parent._getChildren ();
|
|
4424 int length = children.length;
|
|
4425 int index = 0;
|
|
4426 while (index < length) {
|
|
4427 if (children [index] is this) break;
|
|
4428 index++;
|
|
4429 }
|
|
4430 /*
|
|
4431 * It is possible (but unlikely), that application
|
|
4432 * code could have disposed the widget in focus in
|
|
4433 * or out events. Ensure that a disposed widget is
|
|
4434 * not accessed.
|
|
4435 */
|
|
4436 if (index is length) return false;
|
|
4437 int start = index, offset = (next) ? 1 : -1;
|
|
4438 while ((index = (index + offset + length) % length) !is start) {
|
|
4439 Control child = children [index];
|
|
4440 if (!child.isDisposed () && child.isTabItem ()) {
|
|
4441 if (child.setTabItemFocus (next)) return true;
|
|
4442 }
|
|
4443 }
|
|
4444 return false;
|
|
4445 }
|
|
4446
|
|
4447 bool traverseReturn () {
|
|
4448 return false;
|
|
4449 }
|
|
4450
|
|
4451 bool traversePage (bool next) {
|
|
4452 return false;
|
|
4453 }
|
|
4454
|
|
4455 bool traverseMnemonic (char key) {
|
|
4456 return mnemonicHit (key);
|
|
4457 }
|
|
4458
|
|
4459 /**
|
|
4460 * Forces all outstanding paint requests for the widget
|
|
4461 * to be processed before this method returns. If there
|
|
4462 * are no outstanding paint request, this method does
|
|
4463 * nothing.
|
|
4464 * <p>
|
|
4465 * Note: This method does not cause a redraw.
|
|
4466 * </p>
|
|
4467 *
|
|
4468 * @exception SWTException <ul>
|
|
4469 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
|
|
4470 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
|
|
4471 * </ul>
|
|
4472 *
|
|
4473 * @see #redraw()
|
|
4474 * @see #redraw(int, int, int, int, bool)
|
|
4475 * @see PaintListener
|
|
4476 * @see SWT#Paint
|
|
4477 */
|
|
4478 public void update () {
|
|
4479 checkWidget ();
|
|
4480 update (false, true);
|
|
4481 }
|
|
4482
|
|
4483 void update (bool all, bool flush) {
|
|
4484 // checkWidget();
|
|
4485 if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return;
|
|
4486 if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) is 0) return;
|
|
4487 auto window = paintWindow ();
|
|
4488 if (flush) display.flushExposes (window, all);
|
|
4489 OS.gdk_window_process_updates (window, all);
|
|
4490 OS.gdk_flush ();
|
|
4491 }
|
|
4492
|
|
4493 void updateBackgroundMode () {
|
|
4494 int oldState = state & PARENT_BACKGROUND;
|
|
4495 checkBackground ();
|
|
4496 if (oldState !is (state & PARENT_BACKGROUND)) {
|
|
4497 setBackground ();
|
|
4498 }
|
|
4499 }
|
|
4500
|
|
4501 void updateLayout (bool all) {
|
|
4502 /* Do nothing */
|
|
4503 }
|
|
4504
|
|
4505 override int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) {
|
|
4506 switch (cast(int)/*64*/user_data) {
|
|
4507 case EXPOSE_EVENT_INVERSE: {
|
|
4508 if ((OS.GTK_VERSION < OS.buildVERSION (2, 8, 0)) && ((state & OBSCURED) is 0)) {
|
|
4509 Control control = findBackgroundControl ();
|
|
4510 if (control !is null && control.backgroundImage !is null) {
|
|
4511 GdkEventExpose* gdkEvent = cast(GdkEventExpose*)arg0;
|
|
4512 auto paintWindow = paintWindow();
|
|
4513 auto window = gdkEvent.window;
|
|
4514 if (window !is paintWindow) break;
|
|
4515 auto gdkGC = OS.gdk_gc_new (cast(GdkDrawable*)window);
|
|
4516 OS.gdk_gc_set_clip_region (gdkGC, gdkEvent.region);
|
|
4517 int dest_x, dest_y;
|
|
4518 OS.gtk_widget_translate_coordinates (paintHandle (), control.paintHandle (), 0, 0, &dest_x, &dest_y);
|
|
4519 OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED);
|
|
4520 OS.gdk_gc_set_ts_origin (gdkGC, -dest_x, -dest_y);
|
|
4521 OS.gdk_gc_set_tile (gdkGC, cast(GdkPixmap*)control.backgroundImage.pixmap);
|
|
4522 OS.gdk_draw_rectangle (cast(GdkDrawable*)window, gdkGC, 1, gdkEvent.area.x, gdkEvent.area.y, gdkEvent.area.width, gdkEvent.area.height);
|
|
4523 OS.g_object_unref (gdkGC);
|
|
4524 }
|
|
4525 }
|
|
4526 break;
|
|
4527 default:
|
|
4528 }
|
|
4529 }
|
|
4530 return super.windowProc (handle, arg0, user_data);
|
|
4531 }
|
|
4532 }
|