Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/widgets/Display.d @ 48:ddbfe84d86df
[swt lin] versioned imports
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 27 Mar 2009 12:05:20 +0100 |
parents | 65761bc28ab2 |
children | 7a2dd761a8b2 |
rev | line source |
---|---|
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.Display; | |
14 | |
15 import org.eclipse.swt.SWT; | |
16 import org.eclipse.swt.graphics.Color; | |
17 import org.eclipse.swt.graphics.Cursor; | |
18 import org.eclipse.swt.graphics.Device; | |
19 import org.eclipse.swt.graphics.DeviceData; | |
20 import org.eclipse.swt.graphics.Font; | |
21 import org.eclipse.swt.graphics.GCData; | |
22 import org.eclipse.swt.graphics.Image; | |
23 import org.eclipse.swt.graphics.ImageData; | |
24 import org.eclipse.swt.graphics.PaletteData; | |
25 import org.eclipse.swt.graphics.Point; | |
26 import org.eclipse.swt.graphics.Rectangle; | |
27 import org.eclipse.swt.graphics.Resource; | |
28 import org.eclipse.swt.internal.Compatibility; | |
29 import org.eclipse.swt.internal.Converter; | |
30 import org.eclipse.swt.internal.Lock; | |
31 import org.eclipse.swt.internal.LONG; | |
32 import org.eclipse.swt.internal.gtk.OS; | |
33 import org.eclipse.swt.widgets.Caret; | |
34 import org.eclipse.swt.widgets.Control; | |
35 import org.eclipse.swt.widgets.Dialog; | |
36 import org.eclipse.swt.widgets.Event; | |
37 import org.eclipse.swt.widgets.EventTable; | |
38 import org.eclipse.swt.widgets.Listener; | |
39 import org.eclipse.swt.widgets.Menu; | |
40 import org.eclipse.swt.widgets.Monitor; | |
41 import org.eclipse.swt.widgets.Shell; | |
42 import org.eclipse.swt.widgets.Synchronizer; | |
43 import org.eclipse.swt.widgets.Tray; | |
44 import org.eclipse.swt.widgets.Widget; | |
45 | |
46 import java.lang.all; | |
47 | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
48 import java.lang.Thread; |
48 | 49 version(Tango){ |
50 import tango.stdc.string; | |
51 } else { // Phobos | |
52 } | |
25 | 53 |
54 /** | |
55 * Instances of this class are responsible for managing the | |
56 * connection between SWT and the underlying operating | |
57 * system. Their most important function is to implement | |
58 * the SWT event loop in terms of the platform event model. | |
59 * They also provide various methods for accessing information | |
60 * about the operating system, and have overall control over | |
61 * the operating system resources which SWT allocates. | |
62 * <p> | |
63 * Applications which are built with SWT will <em>almost always</em> | |
64 * require only a single display. In particular, some platforms | |
65 * which SWT supports will not allow more than one <em>active</em> | |
66 * display. In other words, some platforms do not support | |
67 * creating a new display if one already exists that has not been | |
68 * sent the <code>dispose()</code> message. | |
69 * <p> | |
70 * In SWT, the thread which creates a <code>Display</code> | |
71 * instance is distinguished as the <em>user-interface thread</em> | |
72 * for that display. | |
73 * </p> | |
74 * The user-interface thread for a particular display has the | |
75 * following special attributes: | |
76 * <ul> | |
77 * <li> | |
78 * The event loop for that display must be run from the thread. | |
79 * </li> | |
80 * <li> | |
81 * Some SWT API methods (notably, most of the public methods in | |
82 * <code>Widget</code> and its subclasses), may only be called | |
83 * from the thread. (To support multi-threaded user-interface | |
84 * applications, class <code>Display</code> provides inter-thread | |
85 * communication methods which allow threads other than the | |
86 * user-interface thread to request that it perform operations | |
87 * on their behalf.) | |
88 * </li> | |
89 * <li> | |
90 * The thread is not allowed to construct other | |
91 * <code>Display</code>s until that display has been disposed. | |
92 * (Note that, this is in addition to the restriction mentioned | |
93 * above concerning platform support for multiple displays. Thus, | |
94 * the only way to have multiple simultaneously active displays, | |
95 * even on platforms which support it, is to have multiple threads.) | |
96 * </li> | |
97 * </ul> | |
98 * Enforcing these attributes allows SWT to be implemented directly | |
99 * on the underlying operating system's event model. This has | |
100 * numerous benefits including smaller footprint, better use of | |
101 * resources, safer memory management, clearer program logic, | |
102 * better performance, and fewer overall operating system threads | |
103 * required. The down side however, is that care must be taken | |
104 * (only) when constructing multi-threaded applications to use the | |
105 * inter-thread communication mechanisms which this class provides | |
106 * when required. | |
107 * </p><p> | |
108 * All SWT API methods which may only be called from the user-interface | |
109 * thread are distinguished in their documentation by indicating that | |
110 * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>" | |
111 * SWT exception. | |
112 * </p> | |
113 * <dl> | |
114 * <dt><b>Styles:</b></dt> | |
115 * <dd>(none)</dd> | |
116 * <dt><b>Events:</b></dt> | |
117 * <dd>Close, Dispose, Settings</dd> | |
118 * </dl> | |
119 * <p> | |
120 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
121 * </p> | |
122 * @see #syncExec | |
123 * @see #asyncExec | |
124 * @see #wake | |
125 * @see #readAndDispatch | |
126 * @see #sleep | |
127 * @see Device#dispose | |
128 * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a> | |
129 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
130 */ | |
131 public class Display : Device { | |
132 | |
133 /* Events Dispatching and Callback */ | |
134 int gdkEventCount; | |
135 GdkEvent* [] gdkEvents; | |
136 Widget [] gdkEventWidgets; | |
137 int [] dispatchEvents; | |
138 Event [] eventQueue; | |
139 GPollFD[] fds; | |
140 int allocated_nfds; | |
141 bool wake_state; | |
142 int max_priority, timeout; | |
143 void*/*Callback*/ eventCallback, filterCallback; | |
144 | |
145 CallbackData*[int] windowProcCallbackDatas; // to prevent GC from collect | |
146 | |
147 CallbackData filterProcCallbackData; | |
148 EventTable eventTable, filterTable; | |
149 static String APP_NAME = "SWT"; //$NON-NLS-1$ | |
150 static const String DISPATCH_EVENT_KEY = "org.eclipse.swt.internal.gtk.dispatchEvent"; | |
151 static const String ADD_WIDGET_KEY = "org.eclipse.swt.internal.addWidget"; | |
152 GClosure*[] closures; | |
153 int [] signalIds; | |
154 | |
155 /* Widget Table */ | |
156 int [] indexTable; | |
157 int freeSlot; | |
158 GtkWidget* lastHandle; | |
159 Widget lastWidget; | |
160 Widget [] widgetTable; | |
161 const static int GROW_SIZE = 1024; | |
162 static int SWT_OBJECT_INDEX; | |
163 static int SWT_OBJECT_INDEX1; | |
164 static int SWT_OBJECT_INDEX2; | |
165 | |
166 /* Modality */ | |
167 Shell [] modalShells; | |
168 Dialog modalDialog; | |
169 static final String GET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.getModalDialog"; //$NON-NLS-1$ | |
170 static final String SET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.setModalDialog"; //$NON-NLS-1$ | |
171 | |
172 /* Focus */ | |
173 int focusEvent; | |
174 Control focusControl; | |
175 Shell activeShell; | |
176 bool activePending; | |
177 bool ignoreActivate, ignoreFocus; | |
178 | |
179 /* Input method resources */ | |
180 Control imControl; | |
181 GtkWindow* preeditWindow; | |
182 GtkLabel* preeditLabel; | |
183 | |
184 /* Sync/Async Widget Communication */ | |
185 Synchronizer synchronizer; | |
186 Thread thread; | |
187 | |
188 /* Display Shutdown */ | |
189 Runnable [] disposeList; | |
190 | |
191 /* System Tray */ | |
192 Tray tray; | |
193 | |
194 /* Timers */ | |
195 int [] timerIds; | |
196 Runnable [] timerList; | |
197 CallbackData timerProcCallbackData; | |
198 | |
199 /* Caret */ | |
200 Caret currentCaret; | |
201 int caretId; | |
202 CallbackData caretProcCallbackData; | |
203 | |
204 /* Mnemonics */ | |
205 Control mnemonicControl; | |
206 | |
207 /* Mouse hover */ | |
208 int mouseHoverId; | |
209 GtkWidget* mouseHoverHandle; | |
210 CallbackData mouseHoverProcCallbackData; | |
211 | |
212 /* Menu position callback */ | |
213 | |
214 /* Tooltip size allocate callback */ | |
215 | |
216 /* Shell map callback */ | |
217 CallbackData shellMapProcCallbackData; | |
218 GClosure* shellMapProcClosure; | |
219 | |
220 /* Idle proc callback */ | |
221 CallbackData idleProcCallbackData; | |
222 int idleHandle; | |
223 static const String ADD_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk.addIdleProc"; | |
224 static const String REMOVE_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk.removeIdleProc"; | |
225 Object idleLock; | |
226 bool idleNeeded; | |
227 | |
228 /* GtkTreeView callbacks */ | |
229 int[] treeSelection; | |
230 int treeSelectionLength; | |
231 | |
232 /* Set direction callback */ | |
233 CallbackData setDirectionProcCallbackData; | |
234 static const String GET_DIRECTION_PROC_KEY = "org.eclipse.swt.internal.gtk.getDirectionProc"; //$NON-NLS-1$ | |
235 | |
236 /* Set emissionProc callback */ | |
237 CallbackData emissionProcCallbackData; | |
238 static const String GET_EMISSION_PROC_KEY = "org.eclipse.swt.internal.gtk.getEmissionProc"; //$NON-NLS-1$ | |
239 | |
240 /* Get all children callback */ | |
241 CallbackData allChildrenProcCallbackData; | |
242 GList* allChildren; | |
243 | |
244 CallbackData cellDataProcCallbackData; | |
245 | |
246 /* Settings callbacks */ | |
247 GtkWidget* shellHandle; | |
248 bool settingsChanged, runSettingsFld; | |
249 CallbackData styleSetProcCallbackData; | |
250 | |
251 /* Entry focus behaviour */ | |
252 bool entrySelectOnFocus; | |
253 | |
254 /* Enter/Exit events */ | |
255 Control currentControl; | |
256 | |
257 /* Flush exposes */ | |
258 int /*long*/ checkIfEventProc; | |
259 void*/*Callback*/ checkIfEventCallback; | |
260 GdkWindow* flushWindow; | |
261 bool flushAll; | |
262 GdkRectangle* flushRect; | |
263 XExposeEvent* exposeEvent; | |
264 XVisibilityEvent* visibilityEvent; | |
265 //int /*long*/ [] flushData = new int /*long*/ [1]; | |
266 | |
267 /* System Resources */ | |
268 Font systemFont; | |
269 Image errorImage, infoImage, questionImage, warningImage; | |
270 Cursor [] cursors; | |
271 Resource [] resources; | |
272 static const int RESOURCE_SIZE = 1 + 4 + SWT.CURSOR_HAND + 1; | |
273 | |
274 /* Colors */ | |
275 GdkColor* COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW; | |
276 GdkColor* COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_FOREGROUND, COLOR_WIDGET_BORDER; | |
277 GdkColor* COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT; | |
278 GdkColor* COLOR_INFO_BACKGROUND, COLOR_INFO_FOREGROUND; | |
279 GdkColor* COLOR_TITLE_FOREGROUND, COLOR_TITLE_BACKGROUND, COLOR_TITLE_BACKGROUND_GRADIENT; | |
280 GdkColor* COLOR_TITLE_INACTIVE_FOREGROUND, COLOR_TITLE_INACTIVE_BACKGROUND, COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT; | |
281 | |
282 /* Popup Menus */ | |
283 Menu [] popups; | |
284 | |
285 /* Click count*/ | |
286 int clickCount = 1; | |
287 | |
288 /* Timestamp of the Last Received Events */ | |
289 int lastEventTime, lastUserEventTime; | |
290 | |
291 /* Fixed Subclass */ | |
292 static int /*long*/ fixed_type; | |
293 static int /*long*/ fixed_info_ptr; | |
294 static extern(C) void function(GtkWidget* handle, GtkAllocation* allocation) oldFixedSizeAllocateProc; | |
295 | |
296 | |
297 /* Renderer Subclass */ | |
298 static int /*long*/ text_renderer_type, pixbuf_renderer_type, toggle_renderer_type; | |
299 static int /*long*/ text_renderer_info_ptr, pixbuf_renderer_info_ptr, toggle_renderer_info_ptr; | |
300 | |
301 /* Key Mappings */ | |
302 static const int [] [] KeyTable = [ | |
303 | |
304 /* Keyboard and Mouse Masks */ | |
305 [OS.GDK_Alt_L, SWT.ALT], | |
306 [OS.GDK_Alt_R, SWT.ALT], | |
307 [OS.GDK_Meta_L, SWT.ALT], | |
308 [OS.GDK_Meta_R, SWT.ALT], | |
309 [OS.GDK_Shift_L, SWT.SHIFT], | |
310 [OS.GDK_Shift_R, SWT.SHIFT], | |
311 [OS.GDK_Control_L, SWT.CONTROL], | |
312 [OS.GDK_Control_R, SWT.CONTROL], | |
313 // [OS.GDK_????, SWT.COMMAND], | |
314 // [OS.GDK_????, SWT.COMMAND], | |
315 | |
316 /* Non-Numeric Keypad Keys */ | |
317 [OS.GDK_Up, SWT.ARROW_UP], | |
318 [OS.GDK_KP_Up, SWT.ARROW_UP], | |
319 [OS.GDK_Down, SWT.ARROW_DOWN], | |
320 [OS.GDK_KP_Down, SWT.ARROW_DOWN], | |
321 [OS.GDK_Left, SWT.ARROW_LEFT], | |
322 [OS.GDK_KP_Left, SWT.ARROW_LEFT], | |
323 [OS.GDK_Right, SWT.ARROW_RIGHT], | |
324 [OS.GDK_KP_Right, SWT.ARROW_RIGHT], | |
325 [OS.GDK_Page_Up, SWT.PAGE_UP], | |
326 [OS.GDK_KP_Page_Up, SWT.PAGE_UP], | |
327 [OS.GDK_Page_Down, SWT.PAGE_DOWN], | |
328 [OS.GDK_KP_Page_Down, SWT.PAGE_DOWN], | |
329 [OS.GDK_Home, SWT.HOME], | |
330 [OS.GDK_KP_Home, SWT.HOME], | |
331 [OS.GDK_End, SWT.END], | |
332 [OS.GDK_KP_End, SWT.END], | |
333 [OS.GDK_Insert, SWT.INSERT], | |
334 [OS.GDK_KP_Insert, SWT.INSERT], | |
335 | |
336 /* Virtual and Ascii Keys */ | |
337 [OS.GDK_BackSpace, SWT.BS], | |
338 [OS.GDK_Return, SWT.CR], | |
339 [OS.GDK_Delete, SWT.DEL], | |
340 [OS.GDK_KP_Delete, SWT.DEL], | |
341 [OS.GDK_Escape, SWT.ESC], | |
342 [OS.GDK_Linefeed, SWT.LF], | |
343 [OS.GDK_Tab, SWT.TAB], | |
344 [OS.GDK_ISO_Left_Tab, SWT.TAB], | |
345 | |
346 /* Functions Keys */ | |
347 [OS.GDK_F1, SWT.F1], | |
348 [OS.GDK_F2, SWT.F2], | |
349 [OS.GDK_F3, SWT.F3], | |
350 [OS.GDK_F4, SWT.F4], | |
351 [OS.GDK_F5, SWT.F5], | |
352 [OS.GDK_F6, SWT.F6], | |
353 [OS.GDK_F7, SWT.F7], | |
354 [OS.GDK_F8, SWT.F8], | |
355 [OS.GDK_F9, SWT.F9], | |
356 [OS.GDK_F10, SWT.F10], | |
357 [OS.GDK_F11, SWT.F11], | |
358 [OS.GDK_F12, SWT.F12], | |
359 [OS.GDK_F13, SWT.F13], | |
360 [OS.GDK_F14, SWT.F14], | |
361 [OS.GDK_F15, SWT.F15], | |
362 | |
363 /* Numeric Keypad Keys */ | |
364 [OS.GDK_KP_Multiply, SWT.KEYPAD_MULTIPLY], | |
365 [OS.GDK_KP_Add, SWT.KEYPAD_ADD], | |
366 [OS.GDK_KP_Enter, SWT.KEYPAD_CR], | |
367 [OS.GDK_KP_Subtract, SWT.KEYPAD_SUBTRACT], | |
368 [OS.GDK_KP_Decimal, SWT.KEYPAD_DECIMAL], | |
369 [OS.GDK_KP_Divide, SWT.KEYPAD_DIVIDE], | |
370 [OS.GDK_KP_0, SWT.KEYPAD_0], | |
371 [OS.GDK_KP_1, SWT.KEYPAD_1], | |
372 [OS.GDK_KP_2, SWT.KEYPAD_2], | |
373 [OS.GDK_KP_3, SWT.KEYPAD_3], | |
374 [OS.GDK_KP_4, SWT.KEYPAD_4], | |
375 [OS.GDK_KP_5, SWT.KEYPAD_5], | |
376 [OS.GDK_KP_6, SWT.KEYPAD_6], | |
377 [OS.GDK_KP_7, SWT.KEYPAD_7], | |
378 [OS.GDK_KP_8, SWT.KEYPAD_8], | |
379 [OS.GDK_KP_9, SWT.KEYPAD_9], | |
380 [OS.GDK_KP_Equal, SWT.KEYPAD_EQUAL], | |
381 | |
382 /* Other keys */ | |
383 [OS.GDK_Caps_Lock, SWT.CAPS_LOCK], | |
384 [OS.GDK_Num_Lock, SWT.NUM_LOCK], | |
385 [OS.GDK_Scroll_Lock, SWT.SCROLL_LOCK], | |
386 [OS.GDK_Pause, SWT.PAUSE], | |
387 [OS.GDK_Break, SWT.BREAK], | |
388 [OS.GDK_Print, SWT.PRINT_SCREEN], | |
389 [OS.GDK_Help, SWT.HELP], | |
390 | |
391 ]; | |
392 | |
393 /* Multiple Displays. */ | |
394 static Display Default; | |
395 static Display [] Displays; | |
396 | |
397 /* Package name */ | |
398 static const String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; | |
399 /* This code is intentionally commented. | |
400 * ".class" can not be used on CLDC. | |
401 */ | |
402 // static { | |
403 // String name = Display.class.getName (); | |
404 // int index = name.lastIndexOf ('.'); | |
405 // PACKAGE_NAME = name.substring (0, index + 1); | |
406 // } | |
407 | |
408 static this() { | |
409 Displays = new Display [4]; | |
410 initDeviceFinder(); | |
411 SWT_OBJECT_INDEX = OS.g_quark_from_string ("SWT_OBJECT_INDEX"); | |
412 SWT_OBJECT_INDEX1 = OS.g_quark_from_string ("SWT_OBJECT_INDEX1"); | |
413 SWT_OBJECT_INDEX2 = OS.g_quark_from_string ("SWT_OBJECT_INDEX2"); | |
414 } | |
415 | |
416 /* GTK Version */ | |
417 static const int MAJOR = 2; | |
418 static const int MINOR = 0; | |
419 static const int MICRO = 6; | |
420 | |
421 /* Display Data */ | |
422 Object data; | |
423 String [] keys; | |
424 Object [] values; | |
425 | |
426 /* Initial Guesses for Shell Trimmings. */ | |
427 int borderTrimWidth = 4, borderTrimHeight = 4; | |
428 int resizeTrimWidth = 6, resizeTrimHeight = 6; | |
429 int titleBorderTrimWidth = 5, titleBorderTrimHeight = 28; | |
430 int titleResizeTrimWidth = 6, titleResizeTrimHeight = 29; | |
431 int titleTrimWidth = 0, titleTrimHeight = 23; | |
432 bool ignoreTrim; | |
433 | |
434 /* Window Manager */ | |
435 String windowManager; | |
436 | |
437 /* | |
438 * TEMPORARY CODE. Install the runnable that | |
439 * gets the current display. This code will | |
440 * be removed in the future. | |
441 */ | |
442 private static void initDeviceFinder(){ | |
443 DeviceFinder = new class() Runnable { | |
444 public void run () { | |
445 Device device = getCurrent (); | |
446 if (device is null) { | |
447 device = getDefault (); | |
448 } | |
449 setDevice (device); | |
450 } | |
451 }; | |
452 } | |
453 | |
454 /* | |
455 * TEMPORARY CODE. | |
456 */ | |
457 static void setDevice (Device device) { | |
458 CurrentDevice = device; | |
459 } | |
460 | |
461 /** | |
462 * Constructs a new instance of this class. | |
463 * <p> | |
464 * Note: The resulting display is marked as the <em>current</em> | |
465 * display. If this is the first display which has been | |
466 * constructed since the application started, it is also | |
467 * marked as the <em>default</em> display. | |
468 * </p> | |
469 * | |
470 * @exception SWTException <ul> | |
471 * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li> | |
472 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
473 * </ul> | |
474 * | |
475 * @see #getCurrent | |
476 * @see #getDefault | |
477 * @see Widget#checkSubclass | |
478 * @see Shell | |
479 */ | |
480 public this () { | |
481 this (null); | |
482 } | |
483 | |
484 /** | |
485 * Constructs a new instance of this class using the parameter. | |
486 * | |
487 * @param data the device data | |
488 */ | |
489 public this (DeviceData data) { | |
490 super (data); | |
491 synchronizer = new Synchronizer (this); | |
492 idleLock = new Object(); | |
493 flushRect = new GdkRectangle (); | |
494 exposeEvent = new XExposeEvent (); | |
495 visibilityEvent = new XVisibilityEvent (); | |
496 cursors = new Cursor [SWT.CURSOR_HAND + 1]; | |
497 } | |
498 | |
499 /** | |
500 * Adds the listener to the collection of listeners who will | |
501 * be notified when an event of the given type occurs anywhere | |
502 * in a widget. The event type is one of the event constants | |
503 * defined in class <code>SWT</code>. When the event does occur, | |
504 * the listener is notified by sending it the <code>handleEvent()</code> | |
505 * message. | |
506 * <p> | |
507 * Setting the type of an event to <code>SWT.None</code> from | |
508 * within the <code>handleEvent()</code> method can be used to | |
509 * change the event type and stop subsequent Java listeners | |
510 * from running. Because event filters run before other listeners, | |
511 * event filters can both block other listeners and set arbitrary | |
512 * fields within an event. For this reason, event filters are both | |
513 * powerful and dangerous. They should generally be avoided for | |
514 * performance, debugging and code maintenance reasons. | |
515 * </p> | |
516 * | |
517 * @param eventType the type of event to listen for | |
518 * @param listener the listener which should be notified when the event occurs | |
519 * | |
520 * @exception IllegalArgumentException <ul> | |
521 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
522 * </ul> | |
523 * @exception SWTException <ul> | |
524 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
525 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
526 * </ul> | |
527 * | |
528 * @see Listener | |
529 * @see SWT | |
530 * @see #removeFilter | |
531 * @see #removeListener | |
532 * | |
533 * @since 3.0 | |
534 */ | |
535 public void addFilter (int eventType, Listener listener) { | |
536 checkDevice (); | |
537 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
538 if (filterTable is null) filterTable = new EventTable (); | |
539 filterTable.hook (eventType, listener); | |
540 } | |
541 | |
542 void addGdkEvent (GdkEvent* event) { | |
543 if (gdkEvents is null) { | |
544 int length = GROW_SIZE; | |
545 gdkEvents.length = length; | |
546 gdkEventWidgets.length = length; | |
547 gdkEventCount = 0; | |
548 } | |
549 if (gdkEventCount is gdkEvents.length) { | |
550 int length = gdkEventCount + GROW_SIZE; | |
551 GdkEvent* [] newEvents = new GdkEvent* [length]; | |
552 SimpleType!(GdkEvent*).arraycopy (gdkEvents, 0, newEvents, 0, gdkEventCount); | |
553 gdkEvents = newEvents; | |
554 Widget [] newWidgets = new Widget [length]; | |
555 System.arraycopy (gdkEventWidgets, 0, newWidgets, 0, gdkEventCount); | |
556 gdkEventWidgets = newWidgets; | |
557 } | |
558 Widget widget = null; | |
559 GtkWidget* handle = OS.gtk_get_event_widget (event); | |
560 if (handle !is null) { | |
561 do { | |
562 widget = getWidget (handle); | |
563 } while (widget is null && (handle = OS.gtk_widget_get_parent (handle)) !is null); | |
564 } | |
565 gdkEvents [gdkEventCount] = event; | |
566 gdkEventWidgets [gdkEventCount] = widget; | |
567 gdkEventCount++; | |
568 } | |
569 | |
570 void addIdleProc() { | |
571 synchronized (idleLock){ | |
572 this.idleNeeded = true; | |
573 if (idleHandle is 0) { | |
574 idleProcCallbackData.display = this; | |
575 idleProcCallbackData.data = null; | |
576 idleHandle = OS.g_idle_add ( &idleProcFunc, &idleProcCallbackData ); | |
577 } | |
578 } | |
579 } | |
580 | |
581 /** | |
582 * Adds the listener to the collection of listeners who will | |
583 * be notified when an event of the given type occurs. The event | |
584 * type is one of the event constants defined in class <code>SWT</code>. | |
585 * When the event does occur in the display, the listener is notified by | |
586 * sending it the <code>handleEvent()</code> message. | |
587 * | |
588 * @param eventType the type of event to listen for | |
589 * @param listener the listener which should be notified when the event occurs | |
590 * | |
591 * @exception IllegalArgumentException <ul> | |
592 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
593 * </ul> | |
594 * @exception SWTException <ul> | |
595 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
596 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
597 * </ul> | |
598 * | |
599 * @see Listener | |
600 * @see SWT | |
601 * @see #removeListener | |
602 * | |
603 * @since 2.0 | |
604 */ | |
605 public void addListener (int eventType, Listener listener) { | |
606 checkDevice (); | |
607 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
608 if (eventTable is null) eventTable = new EventTable (); | |
609 eventTable.hook (eventType, listener); | |
610 } | |
611 | |
612 void allChildrenCollect( GtkWidget* widget, int recurse ){ | |
613 allChildrenProcCallbackData.display = this; | |
614 allChildrenProcCallbackData.data = cast(void*)recurse; | |
615 OS.gtk_container_forall (cast(GtkContainer*)widget, cast(GtkCallback)&allChildrenProcFunc, &allChildrenProcCallbackData); | |
616 } | |
617 private static extern(C) int /*long*/ allChildrenProcFunc (GtkWidget* handle, void* user_data) { | |
618 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
619 CallbackData* cbdata = cast(CallbackData*)user_data; | |
620 return cbdata.display.allChildrenProc( cast(GtkWidget*)handle, cast(int)cbdata.data ); | |
621 } | |
622 int /*long*/ allChildrenProc (GtkWidget* widget, int /*long*/ recurse) { | |
623 allChildren = OS.g_list_append (allChildren, widget); | |
624 if (recurse !is 0 && OS.GTK_IS_CONTAINER (cast(GTypeInstance*)widget)) { | |
625 allChildrenProcCallbackData.display = this; | |
626 allChildrenProcCallbackData.data = cast(void*)recurse; | |
627 OS.gtk_container_forall (cast(GtkContainer*)widget, cast(GtkCallback)&allChildrenProcFunc, &allChildrenProcCallbackData); | |
628 } | |
629 return 0; | |
630 } | |
631 | |
632 void addMouseHoverTimeout (GtkWidget* handle) { | |
633 if (mouseHoverId !is 0) OS.gtk_timeout_remove (mouseHoverId); | |
634 mouseHoverProcCallbackData.display = this; | |
635 mouseHoverProcCallbackData.data = cast(void*)handle; | |
636 mouseHoverId = OS.gtk_timeout_add (400, &mouseHoverProcFunc, &mouseHoverProcCallbackData); | |
637 mouseHoverHandle = handle; | |
638 } | |
639 | |
640 void addPopup (Menu menu) { | |
641 if (popups is null) popups = new Menu [4]; | |
642 int length = popups.length; | |
643 for (int i=0; i<length; i++) { | |
644 if (popups [i] is menu) return; | |
645 } | |
646 int index = 0; | |
647 while (index < length) { | |
648 if (popups [index] is null) break; | |
649 index++; | |
650 } | |
651 if (index is length) { | |
652 Menu [] newPopups = new Menu [length + 4]; | |
653 System.arraycopy (popups, 0, newPopups, 0, length); | |
654 popups = newPopups; | |
655 } | |
656 popups [index] = menu; | |
657 } | |
658 | |
659 void addWidget (GtkWidget* handle, Widget widget) { | |
660 if (handle is null) return; | |
661 if (freeSlot is -1) { | |
662 int len = (freeSlot = indexTable.length) + GROW_SIZE; | |
663 int[] newIndexTable = new int[len]; | |
664 Widget[] newWidgetTable = new Widget [len]; | |
665 System.arraycopy (indexTable, 0, newIndexTable, 0, freeSlot); | |
666 System.arraycopy (widgetTable, 0, newWidgetTable, 0, freeSlot); | |
667 for (int i = freeSlot; i < len - 1; i++) { | |
668 newIndexTable[i] = i + 1; | |
669 } | |
670 newIndexTable[len - 1] = -1; | |
671 indexTable = newIndexTable; | |
672 widgetTable = newWidgetTable; | |
673 } | |
674 int index = freeSlot + 1; | |
675 OS.g_object_set_qdata (cast(GObject*)handle, SWT_OBJECT_INDEX, cast(void*)index); | |
676 int oldSlot = freeSlot; | |
677 freeSlot = indexTable[oldSlot]; | |
678 indexTable [oldSlot] = -2; | |
679 widgetTable [oldSlot] = widget; | |
680 } | |
681 | |
682 /** | |
683 * Causes the <code>run()</code> method of the runnable to | |
684 * be invoked by the user-interface thread at the next | |
685 * reasonable opportunity. The caller of this method continues | |
686 * to run in parallel, and is not notified when the | |
687 * runnable has completed. Specifying <code>null</code> as the | |
688 * runnable simply wakes the user-interface thread when run. | |
689 * <p> | |
690 * Note that at the time the runnable is invoked, widgets | |
691 * that have the receiver as their display may have been | |
692 * disposed. Therefore, it is necessary to check for this | |
693 * case inside the runnable before accessing the widget. | |
694 * </p> | |
695 * | |
696 * @param runnable code to run on the user-interface thread or <code>null</code> | |
697 * | |
698 * @exception SWTException <ul> | |
699 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
700 * </ul> | |
701 * | |
702 * @see #syncExec | |
703 */ | |
704 public void asyncExec (Runnable runnable) { | |
705 synchronized (Device.classinfo) { | |
706 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
707 synchronized (idleLock) { | |
708 if (idleNeeded && idleHandle is 0) { | |
709 //NOTE: calling unlocked function in OS | |
710 idleHandle = OS.g_idle_add (&idleProcFunc, cast(void*) this); | |
711 } | |
712 } | |
713 synchronizer.asyncExec (runnable); | |
714 } | |
715 } | |
716 | |
717 /** | |
718 * Causes the system hardware to emit a short sound | |
719 * (if it supports this capability). | |
720 * | |
721 * @exception SWTException <ul> | |
722 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
723 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
724 * </ul> | |
725 */ | |
726 public void beep () { | |
727 if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); | |
728 OS.gdk_beep(); | |
729 if (!OS.GDK_WINDOWING_X11 ()) { | |
730 OS.gdk_flush (); | |
731 } else { | |
732 void* xDisplay = OS.GDK_DISPLAY (); | |
733 OS.XFlush (xDisplay); | |
734 } | |
735 } | |
736 | |
737 void doCellDataProc( GtkWidget* widget, GtkTreeViewColumn *tree_column, GtkCellRenderer *cell_renderer ){ | |
738 cellDataProcCallbackData.display = this; | |
739 cellDataProcCallbackData.data = widget; | |
740 OS.gtk_tree_view_column_set_cell_data_func ( tree_column, cell_renderer, &cellDataProcFunc, &cellDataProcCallbackData, null ); | |
741 } | |
742 | |
743 private static extern(C) void cellDataProcFunc ( | |
744 GtkTreeViewColumn *tree_column, | |
745 GtkCellRenderer *cell, | |
746 GtkTreeModel *tree_model, | |
747 GtkTreeIter *iter, | |
748 void* data) | |
749 { | |
750 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
751 CallbackData* cbdata = cast(CallbackData*)data; | |
752 return cbdata.display.cellDataProc( tree_column, cell, tree_model, iter, cbdata.data ); | |
753 } | |
754 | |
755 void cellDataProc( | |
756 GtkTreeViewColumn *tree_column, | |
757 GtkCellRenderer *cell, | |
758 GtkTreeModel *tree_model, | |
759 GtkTreeIter *iter, | |
760 void* data) | |
761 { | |
762 Widget widget = getWidget (cast(GtkWidget*)data); | |
763 if (widget is null) return; | |
764 widget.cellDataProc (tree_column, cell, tree_model, iter, data); | |
765 } | |
766 | |
767 protected override void checkDevice () { | |
768 if (thread is null) error (SWT.ERROR_WIDGET_DISPOSED); | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
769 if (thread !is Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
25 | 770 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); |
771 } | |
772 | |
773 static void checkDisplay (Thread thread, bool multiple) { | |
774 synchronized (Device.classinfo) { | |
775 for (int i=0; i<Displays.length; i++) { | |
776 if (Displays [i] !is null) { | |
777 if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); //$NON-NLS-1$ | |
778 if (Displays [i].thread is thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS); | |
779 } | |
780 } | |
781 } | |
782 } | |
783 | |
784 private static extern(C) int checkIfEventProcFunc (void* display, XEvent* xEvent, char* userData) { | |
785 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
786 auto disp = cast(Display)userData; | |
787 return disp.checkIfEventProcMeth( display, xEvent ); | |
788 } | |
789 | |
790 int checkIfEventProcMeth (void* display, XEvent* xEvent) { | |
791 int type = xEvent.type; | |
792 switch (type) { | |
793 case OS.VisibilityNotify: | |
794 case OS.Expose: | |
795 case OS.GraphicsExpose: | |
796 break; | |
797 default: | |
798 return 0; | |
799 } | |
800 GdkWindow* window = OS.gdk_window_lookup ( xEvent.xany.window ); | |
801 if (window is null) return 0; | |
802 if (flushWindow !is null) { | |
803 if (flushAll) { | |
804 auto tempWindow = window; | |
805 do { | |
806 if (tempWindow is flushWindow) break; | |
807 } while ((tempWindow = OS.gdk_window_get_parent (tempWindow)) !is null); | |
808 if (tempWindow !is flushWindow) return 0; | |
809 } else { | |
810 if (window !is flushWindow) return 0; | |
811 } | |
812 } | |
813 *exposeEvent = *cast(XExposeEvent*)xEvent; | |
814 switch (type) { | |
815 case OS.Expose: | |
816 case OS.GraphicsExpose: { | |
817 flushRect.x = exposeEvent.x; | |
818 flushRect.y = exposeEvent.y; | |
819 flushRect.width = exposeEvent.width; | |
820 flushRect.height = exposeEvent.height; | |
821 OS.gdk_window_invalidate_rect (window, flushRect, true); | |
822 exposeEvent.type = -1; | |
823 memmove (xEvent, exposeEvent, XExposeEvent.sizeof); | |
824 break; | |
825 } | |
826 case OS.VisibilityNotify: { | |
827 memmove (visibilityEvent, xEvent, XVisibilityEvent.sizeof); | |
828 GtkWidget* handle; | |
829 OS.gdk_window_get_user_data (window, cast(void**) & handle); | |
830 Widget widget = handle !is null ? getWidget (handle) : null; | |
831 if (auto control = cast(Control)widget ) { | |
832 if (window is control.paintWindow ()) { | |
833 if (visibilityEvent.state is OS.VisibilityFullyObscured) { | |
834 control.state |= Widget.OBSCURED; | |
835 } else { | |
836 control.state &= ~Widget.OBSCURED; | |
837 } | |
838 } | |
839 } | |
840 break; | |
841 default: | |
842 } | |
843 } | |
844 return 0; | |
845 } | |
846 | |
847 /** | |
848 * Checks that this class can be subclassed. | |
849 * <p> | |
850 * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>. | |
851 * </p> | |
852 * | |
853 * @exception SWTException <ul> | |
854 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
855 * </ul> | |
856 * | |
857 * @see Widget#checkSubclass | |
858 */ | |
859 protected void checkSubclass () { | |
860 //PORTING_TODO if (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS); | |
861 } | |
862 | |
863 void clearModal (Shell shell) { | |
864 if (modalShells is null) return; | |
865 int index = 0, length_ = modalShells.length; | |
866 while (index < length_) { | |
867 if (modalShells [index] is shell) break; | |
868 if (modalShells [index] is null) return; | |
869 index++; | |
870 } | |
871 if (index is length_) return; | |
872 System.arraycopy (modalShells, index + 1, modalShells, index, --length_ - index); | |
873 modalShells [length_] = null; | |
874 if (index is 0 && modalShells [0] is null) modalShells = null; | |
875 Shell [] shells = getShells (); | |
876 for (int i=0; i<shells.length; i++) shells [i].updateModal (); | |
877 } | |
878 | |
879 /** | |
880 * Requests that the connection between SWT and the underlying | |
881 * operating system be closed. | |
882 * | |
883 * @exception SWTException <ul> | |
884 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
885 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
886 * </ul> | |
887 * | |
888 * @see Device#dispose | |
889 * | |
890 * @since 2.0 | |
891 */ | |
892 public void close () { | |
893 checkDevice (); | |
894 Event event = new Event (); | |
895 sendEvent (SWT.Close, event); | |
896 if (event.doit) dispose (); | |
897 } | |
898 | |
899 /** | |
900 * Creates the device in the operating system. If the device | |
901 * does not have a handle, this method may do nothing depending | |
902 * on the device. | |
903 * <p> | |
904 * This method is called before <code>init</code>. | |
905 * </p> | |
906 * | |
907 * @param data the DeviceData which describes the receiver | |
908 * | |
909 * @see #init | |
910 */ | |
911 protected override void create (DeviceData data) { | |
912 checkSubclass (); | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
913 checkDisplay(thread = Thread.currentThread (), false); |
25 | 914 createDisplay (data); |
915 register (this); | |
916 if (Default is null) Default = this; | |
917 } | |
918 | |
919 private static extern(C) int XErrorHandler( void*, XErrorEvent* ){ | |
920 getDwtLogger().error ( __FILE__, __LINE__, "*** XError" ); | |
921 byte* p; | |
922 *p = 3; | |
923 return 0; | |
924 } | |
925 | |
926 void createDisplay (DeviceData data) { | |
927 /* Required for g_main_context_wakeup */ | |
928 if (!OS.g_thread_supported ()) { | |
929 OS.g_thread_init (null); | |
930 } | |
931 OS.gtk_set_locale(); | |
932 int cnt = 2; | |
933 char*[] args = [ "name".ptr, "--sync".ptr, null ]; | |
934 char** a = args.ptr; | |
935 if (!OS.gtk_init_check (&cnt, &a )) { | |
936 } | |
937 assert( cnt is 1 ); | |
938 if (OS.GDK_WINDOWING_X11 ()) xDisplay = cast(void*) OS.GDK_DISPLAY (); | |
939 | |
940 OS.XSetErrorHandler( &Display.XErrorHandler ); | |
941 char* ptr = OS.gtk_check_version (MAJOR, MINOR, MICRO); | |
942 if (ptr !is null) { | |
943 char [] buffer = fromStringz(ptr); | |
944 getDwtLogger().warn (__FILE__, __LINE__,"***WARNING: {}", buffer ); | |
945 getDwtLogger().warn (__FILE__, __LINE__,"***WARNING: SWT requires GTK {}.{}.{}", MAJOR, MINOR, MICRO ); | |
946 int major = OS.gtk_major_version (), minor = OS.gtk_minor_version (), micro = OS.gtk_micro_version (); | |
947 getDwtLogger().warn (__FILE__, __LINE__,"***WARNING: Detected: {}.{}.{}", major, minor, micro); | |
948 } | |
949 if (fixed_type is 0) { | |
950 GTypeInfo* fixed_info = new GTypeInfo (); | |
951 fixed_info.class_size = GtkFixedClass.sizeof; | |
952 fixed_info.class_init = & fixedClassInitProcFunc; | |
953 fixed_info.instance_size = GtkFixed.sizeof; | |
954 fixed_type = OS.g_type_register_static (OS.GTK_TYPE_FIXED (), "SwtFixed".ptr, fixed_info, 0); | |
955 } | |
956 if (text_renderer_type is 0) { | |
957 GTypeInfo* renderer_info = new GTypeInfo (); | |
958 renderer_info.class_size = GtkCellRendererTextClass.sizeof; | |
959 renderer_info.class_init = & rendererClassInitProcFunc; | |
960 renderer_info.instance_size = GtkCellRendererText.sizeof; | |
961 text_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_TEXT (), "SwtTextRenderer".ptr, renderer_info, 0); | |
962 } | |
963 if (pixbuf_renderer_type is 0) { | |
964 GTypeInfo* renderer_info = new GTypeInfo (); | |
965 renderer_info.class_size = GtkCellRendererPixbufClass.sizeof; | |
966 renderer_info.class_init = & rendererClassInitProcFunc; | |
967 renderer_info.instance_size = GtkCellRendererPixbuf.sizeof; | |
968 pixbuf_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_PIXBUF (), "SwtPixbufRenderer".ptr, renderer_info, 0); | |
969 } | |
970 if (toggle_renderer_type is 0) { | |
971 GTypeInfo* renderer_info = new GTypeInfo (); | |
972 renderer_info.class_size = GtkCellRendererToggleClass.sizeof; | |
973 renderer_info.class_init = & rendererClassInitProcFunc; | |
974 renderer_info.instance_size = GtkCellRendererToggle.sizeof; | |
975 toggle_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_TOGGLE (), "SwtToggleRenderer".ptr, renderer_info, 0); | |
976 } | |
977 | |
978 OS.gtk_widget_set_default_direction (OS.GTK_TEXT_DIR_LTR); | |
979 OS.gdk_rgb_init (); | |
980 char* p = toStringz(APP_NAME); | |
981 OS.g_set_prgname (p); | |
982 OS.gdk_set_program_class (p); | |
983 OS.gtk_rc_parse_string ("style \"swt-flat\" { GtkToolbar::shadow-type = none } widget \"*.swt-toolbar-flat\" style : highest \"swt-flat\"".ptr); | |
984 | |
985 /* Initialize the hidden shell */ | |
986 shellHandle = OS.gtk_window_new (OS.GTK_WINDOW_TOPLEVEL); | |
987 if (shellHandle is null) SWT.error (SWT.ERROR_NO_HANDLES); | |
988 OS.gtk_widget_realize (shellHandle); | |
989 | |
990 /* Initialize the filter and event callback */ | |
991 OS.gdk_event_handler_set (&eventProcFunc, cast(void*)this, null); | |
992 //filterProcCallbackData.display = this; | |
993 //filterProcCallbackData.data = null; | |
994 //OS.gdk_window_add_filter (null, &filterProcFunc, cast(void*)&filterProcCallbackData ); | |
995 doWindowAddFilter( &filterProcCallbackData, null, null ); | |
996 } | |
997 | |
998 /* | |
999 * Used by Shell | |
1000 */ | |
1001 package void doWindowAddFilter( CallbackData* cbdata, GdkWindow* window, GtkWidget* widget ){ | |
1002 cbdata.display = this; | |
1003 cbdata.data = widget; | |
1004 OS.gdk_window_add_filter (window, &filterProcFunc, cbdata ); | |
1005 } | |
1006 | |
1007 package void doWindowRemoveFilter( CallbackData* cbdata, GdkWindow* window, GtkWidget* widget ){ | |
1008 cbdata.display = this; | |
1009 cbdata.data = widget; | |
1010 OS.gdk_window_remove_filter(window, &filterProcFunc, cbdata ); | |
1011 } | |
1012 | |
1013 Image createImage (String name) { | |
1014 auto style = OS.gtk_widget_get_default_style (); | |
1015 String buffer = name; | |
1016 auto pixbuf = OS.gtk_icon_set_render_icon ( | |
1017 OS.gtk_icon_factory_lookup_default (buffer.ptr), style, | |
1018 OS.GTK_TEXT_DIR_NONE, | |
1019 OS.GTK_STATE_NORMAL, | |
1020 OS.GTK_ICON_SIZE_DIALOG, null, null ); | |
1021 if (pixbuf is null) return null; | |
1022 int width = OS.gdk_pixbuf_get_width (pixbuf); | |
1023 int height = OS.gdk_pixbuf_get_height (pixbuf); | |
1024 int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); | |
1025 bool hasAlpha = cast(bool)OS.gdk_pixbuf_get_has_alpha (pixbuf); | |
1026 char* pixels = OS.gdk_pixbuf_get_pixels (pixbuf); | |
1027 byte [] data = new byte [stride * height]; | |
1028 memmove (data.ptr, pixels, data.length); | |
1029 OS.g_object_unref (pixbuf); | |
1030 ImageData imageData = null; | |
1031 if (hasAlpha) { | |
1032 PaletteData palette = new PaletteData (0xFF000000, 0xFF0000, 0xFF00); | |
1033 imageData = new ImageData (width, height, 32, palette); | |
1034 byte [] alpha = new byte [stride * height]; | |
1035 for (int y=0; y<height; y++) { | |
1036 for (int x=0; x<width; x++) { | |
1037 alpha [y*width+x] = data [y*stride+x*4+3]; | |
1038 data [y*stride+x*4+3] = 0; | |
1039 } | |
1040 } | |
1041 imageData.setAlphas (0, 0, width * height, alpha, 0); | |
1042 } else { | |
1043 PaletteData palette = new PaletteData (0xFF0000, 0xFF00, 0xFF); | |
1044 imageData = new ImageData (width, height, 24, palette); | |
1045 } | |
1046 imageData.data = data; | |
1047 imageData.bytesPerLine = stride; | |
1048 return new Image (this, imageData); | |
1049 } | |
1050 | |
1051 static GdkPixbuf* createPixbuf(Image image) { | |
1052 int w, h; | |
1053 OS.gdk_drawable_get_size (image.pixmap, &w, &h); | |
1054 auto colormap = OS.gdk_colormap_get_system (); | |
1055 GdkPixbuf* pixbuf; | |
1056 bool hasMask = image.mask !is null && OS.gdk_drawable_get_depth (image.mask) is 1; | |
1057 if (hasMask) { | |
1058 pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w, h ); | |
1059 if (pixbuf is null) SWT.error (SWT.ERROR_NO_HANDLES); | |
1060 OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w, h); | |
1061 auto maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, w, h); | |
1062 if (maskPixbuf is null) SWT.error (SWT.ERROR_NO_HANDLES); | |
1063 OS.gdk_pixbuf_get_from_drawable(maskPixbuf, image.mask, null, 0, 0, 0, 0, w, h); | |
1064 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); | |
1065 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf); | |
1066 byte[] line = new byte[stride]; | |
1067 int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); | |
1068 auto maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); | |
1069 byte[] maskLine = new byte[maskStride]; | |
1070 for (int y=0; y<h; y++) { | |
1071 auto offset = pixels + (y * stride); | |
1072 memmove(line.ptr, offset, stride); | |
1073 auto maskOffset = maskPixels + (y * maskStride); | |
1074 memmove(maskLine.ptr, maskOffset, maskStride); | |
1075 for (int x=0; x<w; x++) { | |
1076 if (maskLine[x * 3] is 0) { | |
1077 line[x * 4 + 3] = 0; | |
1078 } | |
1079 } | |
1080 memmove(offset, line.ptr, stride); | |
1081 } | |
1082 OS.g_object_unref(maskPixbuf); | |
1083 } else { | |
1084 ImageData data = image.getImageData (); | |
1085 bool hasAlpha = data.getTransparencyType () is SWT.TRANSPARENCY_ALPHA; | |
1086 pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w, h); | |
1087 if (pixbuf is null) SWT.error (SWT.ERROR_NO_HANDLES); | |
1088 OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w, h); | |
1089 if (hasAlpha) { | |
1090 byte [] alpha = data.alphaData; | |
1091 int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); | |
1092 auto pixels = OS.gdk_pixbuf_get_pixels (pixbuf); | |
1093 byte [] line = new byte [stride]; | |
1094 for (int y = 0; y < h; y++) { | |
1095 auto offset = pixels + (y * stride); | |
1096 memmove (line.ptr, offset, stride); | |
1097 for (int x = 0; x < w; x++) { | |
1098 line [x*4+3] = alpha [y*w+x]; | |
1099 } | |
1100 memmove (offset, line.ptr, stride); | |
1101 } | |
1102 } | |
1103 } | |
1104 return pixbuf; | |
1105 } | |
1106 | |
1107 static void deregister (Display display) { | |
1108 synchronized (Device.classinfo) { | |
1109 for (int i=0; i<Displays.length; i++) { | |
1110 if (display is Displays [i]) Displays [i] = null; | |
1111 } | |
1112 } | |
1113 } | |
1114 | |
1115 /** | |
1116 * Destroys the device in the operating system and releases | |
1117 * the device's handle. If the device does not have a handle, | |
1118 * this method may do nothing depending on the device. | |
1119 * <p> | |
1120 * This method is called after <code>release</code>. | |
1121 * </p> | |
1122 * @see Device#dispose | |
1123 * @see #release | |
1124 */ | |
1125 protected override void destroy () { | |
1126 if (this is Default) Default = null; | |
1127 deregister (this); | |
1128 destroyDisplay (); | |
1129 } | |
1130 | |
1131 void destroyDisplay () { | |
1132 } | |
1133 | |
1134 static extern(C) int /*long*/ emissionFunc (GSignalInvocationHint* ihint, uint n_param_values, GValue* param_values, void* data) { | |
1135 auto cb = cast(CallbackData*)data; | |
1136 return cb.display.emissionProc( ihint, n_param_values, param_values, cb.data ); | |
1137 } | |
1138 | |
1139 int /*long*/ emissionProc (GSignalInvocationHint* ihint, uint n_param_values, GValue* param_values, void* data) { | |
1140 if (OS.gtk_widget_get_toplevel (OS.g_value_peek_pointer(param_values)) is data) { | |
1141 OS.gtk_widget_set_direction (OS.g_value_peek_pointer(param_values), OS.GTK_TEXT_DIR_RTL); | |
1142 } | |
1143 return 1; | |
1144 } | |
1145 | |
1146 /** | |
1147 * Returns the display which the given thread is the | |
1148 * user-interface thread for, or null if the given thread | |
1149 * is not a user-interface thread for any display. Specifying | |
1150 * <code>null</code> as the thread will return <code>null</code> | |
1151 * for the display. | |
1152 * | |
1153 * @param thread the user-interface thread | |
1154 * @return the display for the given thread | |
1155 */ | |
1156 public static Display findDisplay (Thread thread) { | |
1157 synchronized (Device.classinfo) { | |
1158 for (int i=0; i<Displays.length; i++) { | |
1159 Display display = Displays [i]; | |
1160 if (display !is null && display.thread is thread) { | |
1161 return display; | |
1162 } | |
1163 } | |
1164 return null; | |
1165 } | |
1166 } | |
1167 | |
1168 /** | |
1169 * Causes the <code>run()</code> method of the runnable to | |
1170 * be invoked by the user-interface thread just before the | |
1171 * receiver is disposed. Specifying a <code>null</code> runnable | |
1172 * is ignored. | |
1173 * | |
1174 * @param runnable code to run at dispose time. | |
1175 * | |
1176 * @exception SWTException <ul> | |
1177 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1178 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1179 * </ul> | |
1180 */ | |
1181 public void disposeExec (Runnable runnable) { | |
1182 checkDevice (); | |
1183 if (disposeList is null) disposeList = new Runnable [4]; | |
1184 for (int i=0; i<disposeList.length; i++) { | |
1185 if (disposeList [i] is null) { | |
1186 disposeList [i] = runnable; | |
1187 return; | |
1188 } | |
1189 } | |
1190 Runnable [] newDisposeList = new Runnable [disposeList.length + 4]; | |
1191 SimpleType!(Runnable).arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length); | |
1192 newDisposeList [disposeList.length] = runnable; | |
1193 disposeList = newDisposeList; | |
1194 } | |
1195 | |
1196 /** | |
1197 * Does whatever display specific cleanup is required, and then | |
1198 * uses the code in <code>SWTError.error</code> to handle the error. | |
1199 * | |
1200 * @param code the descriptive error code | |
1201 * | |
1202 * @see SWTError#error | |
1203 */ | |
1204 void error (int code) { | |
1205 SWT.error (code); | |
1206 } | |
1207 | |
1208 private static extern(C) void eventProcFunc (GdkEvent* event, void* data) { | |
1209 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1210 Display disp = cast(Display)data; | |
1211 disp.eventProcMeth(event); | |
1212 } | |
1213 void eventProcMeth (GdkEvent* event) { | |
1214 /* | |
1215 * Use gdk_event_get_time() rather than event.time or | |
1216 * gtk_get_current_event_time(). If the event does not | |
1217 * have a time stamp, then the field will contain garbage. | |
1218 * Note that calling gtk_get_current_event_time() from | |
1219 * outside of gtk_main_do_event() seems to always | |
1220 * return zero. | |
1221 */ | |
1222 int time = OS.gdk_event_get_time (event); | |
1223 if (time !is 0) lastEventTime = time; | |
1224 | |
1225 int eventType = OS.GDK_EVENT_TYPE (event); | |
1226 switch (eventType) { | |
1227 case OS.GDK_BUTTON_PRESS: | |
1228 case OS.GDK_KEY_PRESS: | |
1229 lastUserEventTime = time; | |
1230 default: | |
1231 } | |
1232 bool dispatch = true; | |
1233 if (dispatchEvents !is null) { | |
1234 dispatch = false; | |
1235 for (int i = 0; i < dispatchEvents.length; i++) { | |
1236 if (eventType is dispatchEvents [i]) { | |
1237 dispatch = true; | |
1238 break; | |
1239 } | |
1240 } | |
1241 } | |
1242 if (!dispatch) { | |
1243 addGdkEvent (OS.gdk_event_copy (event)); | |
1244 return 0; | |
1245 } | |
1246 OS.gtk_main_do_event (event); | |
1247 if (dispatchEvents is null) putGdkEvents (); | |
1248 return 0; | |
1249 } | |
1250 | |
1251 /** | |
1252 * Given the operating system handle for a widget, returns | |
1253 * the instance of the <code>Widget</code> subclass which | |
1254 * represents it in the currently running application, if | |
1255 * such exists, or null if no matching widget can be found. | |
1256 * <p> | |
1257 * <b>IMPORTANT:</b> This method should not be called from | |
1258 * application code. The arguments are platform-specific. | |
1259 * </p> | |
1260 * | |
1261 * @param handle the handle for the widget | |
1262 * @return the SWT widget that the handle represents | |
1263 * | |
1264 * @exception SWTException <ul> | |
1265 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1266 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1267 * </ul> | |
1268 */ | |
1269 public Widget findWidget (GtkWidget* handle) { | |
1270 checkDevice (); | |
1271 return getWidget (handle); | |
1272 } | |
1273 | |
1274 /** | |
1275 * Given the operating system handle for a widget, | |
1276 * and widget-specific id, returns the instance of | |
1277 * the <code>Widget</code> subclass which represents | |
1278 * the handle/id pair in the currently running application, | |
1279 * if such exists, or null if no matching widget can be found. | |
1280 * <p> | |
1281 * <b>IMPORTANT:</b> This method should not be called from | |
1282 * application code. The arguments are platform-specific. | |
1283 * </p> | |
1284 * | |
1285 * @param handle the handle for the widget | |
1286 * @param id the id for the subwidget (usually an item) | |
1287 * @return the SWT widget that the handle/id pair represents | |
1288 * | |
1289 * @exception SWTException <ul> | |
1290 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1291 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1292 * </ul> | |
1293 * | |
1294 * @since 3.1 | |
1295 */ | |
1296 public Widget findWidget (GtkWidget* handle, int id) { | |
1297 checkDevice (); | |
1298 return null; | |
1299 } | |
1300 | |
1301 /** | |
1302 * Given a widget and a widget-specific id, returns the | |
1303 * instance of the <code>Widget</code> subclass which represents | |
1304 * the widget/id pair in the currently running application, | |
1305 * if such exists, or null if no matching widget can be found. | |
1306 * | |
1307 * @param widget the widget | |
1308 * @param id the id for the subwidget (usually an item) | |
1309 * @return the SWT subwidget (usually an item) that the widget/id pair represents | |
1310 * | |
1311 * @exception SWTException <ul> | |
1312 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1313 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1314 * </ul> | |
1315 * | |
1316 * @since 3.3 | |
1317 */ | |
1318 public Widget findWidget (Widget widget, int /*long*/ id) { | |
1319 checkDevice (); | |
1320 return null; | |
1321 } | |
1322 | |
1323 private static extern(C) void fixedClassInitProcFunc (void* g_class, void* class_data) { | |
1324 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1325 GtkWidgetClass* klass = cast(GtkWidgetClass*)g_class; | |
1326 klass.map = &fixedMapProcFunc; | |
1327 oldFixedSizeAllocateProc = klass.size_allocate; | |
1328 klass.size_allocate = &fixedSizeAllocateProc; | |
1329 } | |
1330 | |
1331 private static extern(C) void fixedMapProcFunc (GtkWidget * handle) { | |
1332 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1333 Display display = getCurrent (); | |
1334 Widget widget = display.getWidget (handle); | |
1335 if (widget !is null) widget.fixedMapProc (handle); | |
1336 } | |
1337 | |
1338 private static extern(C) static void fixedSizeAllocateProc (GtkWidget* handle, GtkAllocation* allocation) { | |
1339 Display display = getCurrent (); | |
1340 Widget widget = display.getWidget (handle); | |
1341 if (widget !is null) return widget.fixedSizeAllocateProc (handle, allocation); | |
1342 return oldFixedSizeAllocateProc(handle, allocation); | |
1343 } | |
1344 | |
1345 private static extern(C) void rendererClassInitProcFunc (void* g_class, void* class_data) { | |
1346 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1347 GtkCellRendererClass* klass = cast(GtkCellRendererClass*)g_class; | |
1348 klass.render = &rendererRenderProcFunc; | |
1349 klass.get_size = &rendererGetSizeProcFunc; | |
1350 | |
1351 } | |
1352 private static extern(C) void rendererGetSizeProcFunc( | |
1353 GtkCellRenderer *cell, | |
1354 GtkWidget *handle, | |
1355 GdkRectangle *cell_area, | |
1356 int *x_offset, | |
1357 int *y_offset, | |
1358 int *width, | |
1359 int *height) | |
1360 { | |
1361 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1362 Display display = getCurrent (); | |
1363 Widget widget = display.getWidget (handle); | |
1364 if (widget !is null) widget.rendererGetSizeProc (cell, handle, cell_area, x_offset, y_offset, width, height); | |
1365 } | |
1366 private static extern(C) void rendererRenderProcFunc(GtkCellRenderer * cell, GdkDrawable * window, GtkWidget * handle, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, int flags){ | |
1367 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1368 Display display = getCurrent (); | |
1369 Widget widget = display.getWidget (handle); | |
1370 if (widget !is null) widget.rendererRenderProc (cell, window, handle, background_area, cell_area, expose_area, flags); | |
1371 } | |
1372 | |
1373 void flushExposes (GdkWindow* window, bool all) { | |
1374 OS.gdk_flush (); | |
1375 OS.gdk_flush (); | |
1376 if (OS.GDK_WINDOWING_X11 ()) { | |
1377 this.flushWindow = window; | |
1378 this.flushAll = all; | |
1379 auto xDisplay = OS.GDK_DISPLAY (); | |
1380 auto xEvent = cast(XEvent*)OS.g_malloc (XEvent.sizeof); | |
1381 OS.XCheckIfEvent (xDisplay, xEvent, &checkIfEventProcFunc, cast(char*)this ); | |
1382 OS.g_free (xEvent); | |
1383 this.flushWindow = null; | |
1384 } | |
1385 } | |
1386 | |
1387 /** | |
1388 * Returns the currently active <code>Shell</code>, or null | |
1389 * if no shell belonging to the currently running application | |
1390 * is active. | |
1391 * | |
1392 * @return the active shell or null | |
1393 * | |
1394 * @exception SWTException <ul> | |
1395 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1396 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1397 * </ul> | |
1398 */ | |
1399 public Shell getActiveShell () { | |
1400 checkDevice (); | |
1401 return activeShell; | |
1402 } | |
1403 | |
1404 /** | |
1405 * Returns a rectangle describing the receiver's size and location. Note that | |
1406 * on multi-monitor systems the origin can be negative. | |
1407 * | |
1408 * @return the bounding rectangle | |
1409 * | |
1410 * @exception SWTException <ul> | |
1411 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1412 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1413 * </ul> | |
1414 */ | |
1415 public override Rectangle getBounds () { | |
1416 checkDevice (); | |
1417 return new Rectangle (0, 0, OS.gdk_screen_width (), OS.gdk_screen_height ()); | |
1418 } | |
1419 | |
1420 /** | |
1421 * Returns the display which the currently running thread is | |
1422 * the user-interface thread for, or null if the currently | |
1423 * running thread is not a user-interface thread for any display. | |
1424 * | |
1425 * @return the current display | |
1426 */ | |
1427 public static Display getCurrent () { | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
1428 return findDisplay (Thread.currentThread ()); |
25 | 1429 } |
1430 | |
1431 int getCaretBlinkTime () { | |
1432 // checkDevice (); | |
1433 auto settings = OS.gtk_settings_get_default (); | |
1434 if (settings is null) return 500; | |
1435 int buffer; | |
1436 OS.g_object_get1 (settings, OS.gtk_cursor_blink.ptr, &buffer ); | |
1437 if (buffer is 0) return 0; | |
1438 OS.g_object_get1 (settings, OS.gtk_cursor_blink_time.ptr, &buffer); | |
1439 if (buffer is 0) return 500; | |
1440 /* | |
1441 * By experimentation, GTK application don't use the whole | |
1442 * blink cycle time. Instead, they divide up the time, using | |
1443 * an effective blink rate of about 1/2 the total time. | |
1444 */ | |
1445 return buffer / 2; | |
1446 } | |
1447 | |
1448 /** | |
1449 * Returns the control which the on-screen pointer is currently | |
1450 * over top of, or null if it is not currently over one of the | |
1451 * controls built by the currently running application. | |
1452 * | |
1453 * @return the control under the cursor | |
1454 * | |
1455 * @exception SWTException <ul> | |
1456 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1457 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1458 * </ul> | |
1459 */ | |
1460 public Control getCursorControl () { | |
1461 checkDevice(); | |
1462 int x, y; | |
1463 GtkWidget* handle; | |
1464 GtkWidget* user_data; | |
1465 auto window = OS.gdk_window_at_pointer (&x, &y); | |
1466 if (window !is null) { | |
1467 OS.gdk_window_get_user_data (window, cast(void**)&user_data); | |
1468 handle = user_data; | |
1469 } else { | |
1470 /* | |
1471 * Feature in GTK. gdk_window_at_pointer() will not return a window | |
1472 * if the pointer is over a foreign embedded window. The fix is to use | |
1473 * XQueryPointer to find the containing GDK window. | |
1474 */ | |
1475 if (!OS.GDK_WINDOWING_X11 ()) return null; | |
1476 OS.gdk_error_trap_push (); | |
1477 int unusedInt; | |
1478 uint unusedUInt; | |
1479 uint unusedPtr; | |
1480 uint buffer; | |
1481 uint xWindow, xParent = OS.XDefaultRootWindow (xDisplay); | |
1482 do { | |
1483 if (OS.XQueryPointer (xDisplay, xParent, &unusedPtr, &buffer, &unusedInt, &unusedInt, &unusedInt, &unusedInt, &unusedUInt) is 0) { | |
1484 handle = null; | |
1485 break; | |
1486 } | |
1487 if ((xWindow = buffer) !is 0) { | |
1488 xParent = xWindow; | |
1489 auto gdkWindow = OS.gdk_window_lookup (xWindow); | |
1490 if (gdkWindow !is null) { | |
1491 OS.gdk_window_get_user_data (gdkWindow, cast(void**)&user_data); | |
1492 if (user_data !is null) handle = user_data; | |
1493 } | |
1494 } | |
1495 } while (xWindow !is 0); | |
1496 OS.gdk_error_trap_pop (); | |
1497 } | |
1498 if (handle is null) return null; | |
1499 do { | |
1500 Widget widget = getWidget (handle); | |
1501 if (widget !is null && (null !is cast(Control)widget)) { | |
1502 Control control = cast(Control) widget; | |
1503 if (control.isEnabled ()) return control; | |
1504 } | |
1505 } while ((handle = OS.gtk_widget_get_parent (handle)) !is null); | |
1506 return null; | |
1507 } | |
1508 | |
1509 bool filterEvent (Event event) { | |
1510 if (filterTable !is null) filterTable.sendEvent (event); | |
1511 return false; | |
1512 } | |
1513 | |
1514 bool filters (int eventType) { | |
1515 if (filterTable is null) return false; | |
1516 return filterTable.hooks (eventType); | |
1517 } | |
1518 | |
1519 private static extern(C) int filterProcFunc (GdkXEvent* xEvent, GdkEvent* gdkEvent, void* data) { | |
1520 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1521 auto callbackdata = cast(CallbackData*)data; | |
1522 auto disp = callbackdata.display; | |
1523 if( disp is null ) return 0; | |
1524 auto res = disp.filterProcMeth(xEvent,gdkEvent,callbackdata); | |
1525 return res; | |
1526 } | |
1527 | |
1528 int filterProcMeth (GdkXEvent* xEvent, GdkEvent* gdkEvent, CallbackData* callbackData) { | |
1529 if( callbackData.data is null ){ | |
1530 /* | |
1531 * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK | |
1532 * does not deliver a corresponding GTK event. Button 6 and 7 | |
1533 * are mapped to buttons 4 and 5 in SWT. The fix is to change | |
1534 * the button number of the event to a negative number so that | |
1535 * it gets dispatched by GTK. SWT has been modified to look | |
1536 * for negative button numbers. | |
1537 */ | |
1538 XButtonEvent* mouseEvent = cast(XButtonEvent*) xEvent; | |
1539 if (mouseEvent.type is OS.ButtonRelease) { | |
1540 switch (mouseEvent.button) { | |
1541 case 6: | |
1542 case 7: | |
1543 mouseEvent.button = -mouseEvent.button; | |
1544 break; | |
1545 default: | |
1546 } | |
1547 } | |
1548 } | |
1549 Widget widget = getWidget (cast(GtkWidget*)callbackData.data); | |
1550 if (widget is null) return 0; | |
1551 return widget.filterProc (cast(XEvent*)xEvent, gdkEvent, callbackData.data); | |
1552 } | |
1553 | |
1554 /** | |
1555 * Returns the location of the on-screen pointer relative | |
1556 * to the top left corner of the screen. | |
1557 * | |
1558 * @return the cursor location | |
1559 * | |
1560 * @exception SWTException <ul> | |
1561 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1562 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1563 * </ul> | |
1564 */ | |
1565 public Point getCursorLocation () { | |
1566 checkDevice (); | |
1567 int x, y; | |
1568 OS.gdk_window_get_pointer (null, &x, &y, null); | |
1569 return new Point (x, y); | |
1570 } | |
1571 | |
1572 /** | |
1573 * Returns an array containing the recommended cursor sizes. | |
1574 * | |
1575 * @return the array of cursor sizes | |
1576 * | |
1577 * @exception SWTException <ul> | |
1578 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1579 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1580 * </ul> | |
1581 * | |
1582 * @since 3.0 | |
1583 */ | |
1584 public Point [] getCursorSizes () { | |
1585 checkDevice (); | |
1586 return [new Point (16, 16), new Point (32, 32)]; | |
1587 } | |
1588 | |
1589 /** | |
1590 * Returns the application defined property of the receiver | |
1591 * with the specified name, or null if it has not been set. | |
1592 * <p> | |
1593 * Applications may have associated arbitrary objects with the | |
1594 * receiver in this fashion. If the objects stored in the | |
1595 * properties need to be notified when the display is disposed | |
1596 * of, it is the application's responsibility to provide a | |
1597 * <code>disposeExec()</code> handler which does so. | |
1598 * </p> | |
1599 * | |
1600 * @param key the name of the property | |
1601 * @return the value of the property or null if it has not been set | |
1602 * | |
1603 * @exception SWTException <ul> | |
1604 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1605 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1606 * </ul> | |
1607 * | |
1608 * @see #setData(String, Object) | |
1609 * @see #disposeExec(Runnable) | |
1610 */ | |
1611 public Object getData (String key) { | |
1612 checkDevice (); | |
1613 // SWT extension: allow null for zero length string | |
1614 //if (key is null) error (SWT.ERROR_NULL_ARGUMENT); | |
1615 if (key.equals (DISPATCH_EVENT_KEY)) { | |
1616 return new ArrayWrapperInt(dispatchEvents); | |
1617 } | |
1618 if (key.equals (GET_MODAL_DIALOG)) { | |
1619 return modalDialog; | |
1620 } | |
1621 if (key.equals (GET_DIRECTION_PROC_KEY)) { | |
1622 return new LONG (cast(int) &setDirectionProcFunc); | |
1623 } | |
1624 if (key.equals (GET_EMISSION_PROC_KEY)) { | |
1625 return new LONG (cast(int) &emissionFunc); | |
1626 } | |
1627 if (keys is null) return null; | |
1628 for (int i=0; i<keys.length; i++) { | |
1629 if (keys [i].equals(key)) return values [i]; | |
1630 } | |
1631 return null; | |
1632 } | |
1633 | |
1634 /** | |
1635 * Returns the application defined, display specific data | |
1636 * associated with the receiver, or null if it has not been | |
1637 * set. The <em>display specific data</em> is a single, | |
1638 * unnamed field that is stored with every display. | |
1639 * <p> | |
1640 * Applications may put arbitrary objects in this field. If | |
1641 * the object stored in the display specific data needs to | |
1642 * be notified when the display is disposed of, it is the | |
1643 * application's responsibility to provide a | |
1644 * <code>disposeExec()</code> handler which does so. | |
1645 * </p> | |
1646 * | |
1647 * @return the display specific data | |
1648 * | |
1649 * @exception SWTException <ul> | |
1650 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1651 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1652 * </ul> | |
1653 * | |
1654 * @see #setData(Object) | |
1655 * @see #disposeExec(Runnable) | |
1656 */ | |
1657 public Object getData () { | |
1658 checkDevice (); | |
1659 return data; | |
1660 } | |
1661 | |
1662 /** | |
1663 * Returns a point whose x coordinate is the horizontal | |
1664 * dots per inch of the display, and whose y coordinate | |
1665 * is the vertical dots per inch of the display. | |
1666 * | |
1667 * @return the horizontal and vertical DPI | |
1668 * | |
1669 * @exception SWTException <ul> | |
1670 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1671 * </ul> | |
1672 */ | |
1673 public override Point getDPI () { | |
1674 checkDevice (); | |
1675 int widthMM = OS.gdk_screen_width_mm (); | |
1676 int width = OS.gdk_screen_width (); | |
1677 int dpi = Compatibility.round (254 * width, widthMM * 10); | |
1678 return new Point (dpi, dpi); | |
1679 } | |
1680 | |
1681 int /*long*/ gtk_fixed_get_type () { | |
1682 return fixed_type; | |
1683 } | |
1684 | |
1685 int /*long*/ gtk_cell_renderer_text_get_type () { | |
1686 return text_renderer_type; | |
1687 } | |
1688 | |
1689 int /*long*/ gtk_cell_renderer_pixbuf_get_type () { | |
1690 return pixbuf_renderer_type; | |
1691 } | |
1692 | |
1693 int /*long*/ gtk_cell_renderer_toggle_get_type () { | |
1694 return toggle_renderer_type; | |
1695 } | |
1696 | |
1697 /** | |
1698 * Returns the default display. One is created (making the | |
1699 * thread that invokes this method its user-interface thread) | |
1700 * if it did not already exist. | |
1701 * | |
1702 * @return the default display | |
1703 */ | |
1704 public static Display getDefault () { | |
1705 synchronized (Device.classinfo) { | |
1706 if (Default is null) Default = new Display (); | |
1707 return Default; | |
1708 } | |
1709 } | |
1710 | |
1711 // /+static bool isValidClass (Class clazz) { | |
1712 // //PORTING_TODO String name = clazz.getName (); | |
1713 // //PORTING_TODO int index = name.lastIndexOf ('.'); | |
1714 // //PORTING_TODO return name.substring (0, index + 1)==/*eq*/ PACKAGE_PREFIX; | |
1715 // return true; | |
1716 // }+/ | |
1717 | |
1718 /** | |
1719 * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>. | |
1720 * The button dismissal alignment is the ordering that should be used when positioning the | |
1721 * default dismissal button for a dialog. For example, in a dialog that contains an OK and | |
1722 * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the | |
1723 * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>, | |
1724 * the button ordering should be CANCEL/OK. | |
1725 * | |
1726 * @return the button dismissal order | |
1727 * | |
1728 * @exception SWTException <ul> | |
1729 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1730 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1731 * </ul> | |
1732 * | |
1733 * @since 2.1 | |
1734 */ | |
1735 public int getDismissalAlignment () { | |
1736 checkDevice (); | |
1737 return SWT.RIGHT; | |
1738 } | |
1739 | |
1740 /** | |
1741 * Returns the longest duration, in milliseconds, between | |
1742 * two mouse button clicks that will be considered a | |
1743 * <em>double click</em> by the underlying operating system. | |
1744 * | |
1745 * @return the double click time | |
1746 * | |
1747 * @exception SWTException <ul> | |
1748 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1749 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1750 * </ul> | |
1751 */ | |
1752 public int getDoubleClickTime () { | |
1753 checkDevice (); | |
1754 auto settings = OS.gtk_settings_get_default (); | |
1755 int buffer; | |
1756 OS.g_object_get1 (settings, OS.gtk_double_click_time.ptr, &buffer); | |
1757 return buffer; | |
1758 } | |
1759 | |
1760 /** | |
1761 * Returns the control which currently has keyboard focus, | |
1762 * or null if keyboard events are not currently going to | |
1763 * any of the controls built by the currently running | |
1764 * application. | |
1765 * | |
1766 * @return the control under the cursor | |
1767 * | |
1768 * @exception SWTException <ul> | |
1769 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1770 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1771 * </ul> | |
1772 */ | |
1773 public Control getFocusControl () { | |
1774 checkDevice (); | |
1775 if (focusControl !is null && !focusControl.isDisposed ()) { | |
1776 return focusControl; | |
1777 } | |
1778 if (activeShell is null) return null; | |
1779 auto shellHandle = activeShell.shellHandle; | |
1780 auto handle = OS.gtk_window_get_focus (cast(GtkWindow*)shellHandle); | |
1781 if (handle is null) return null; | |
1782 do { | |
1783 Widget widget = getWidget (handle); | |
1784 if (widget !is null && (null !is cast(Control)widget)) { | |
1785 Control control = cast(Control) widget; | |
1786 return control.isEnabled () ? control : null; | |
1787 } | |
1788 } while ((handle = OS.gtk_widget_get_parent (handle)) !is null); | |
1789 return null; | |
1790 } | |
1791 | |
1792 /** | |
1793 * Returns true when the high contrast mode is enabled. | |
1794 * Otherwise, false is returned. | |
1795 * <p> | |
1796 * Note: This operation is a hint and is not supported on | |
1797 * platforms that do not have this concept. | |
1798 * </p> | |
1799 * | |
1800 * @return the high contrast mode | |
1801 * | |
1802 * @exception SWTException <ul> | |
1803 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1804 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1805 * </ul> | |
1806 * | |
1807 * @since 3.0 | |
1808 */ | |
1809 public bool getHighContrast () { | |
1810 checkDevice (); | |
1811 return false; | |
1812 } | |
1813 | |
1814 public override int getDepth () { | |
1815 checkDevice (); | |
1816 auto visual = OS.gdk_visual_get_system(); | |
1817 return visual.depth; | |
1818 } | |
1819 | |
1820 /** | |
1821 * Returns the maximum allowed depth of icons on this display, in bits per pixel. | |
1822 * On some platforms, this may be different than the actual depth of the display. | |
1823 * | |
1824 * @return the maximum icon depth | |
1825 * | |
1826 * @exception SWTException <ul> | |
1827 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1828 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1829 * </ul> | |
1830 * | |
1831 * @see Device#getDepth | |
1832 */ | |
1833 public int getIconDepth () { | |
1834 checkDevice (); | |
1835 return getDepth (); | |
1836 } | |
1837 | |
1838 /** | |
1839 * Returns an array containing the recommended icon sizes. | |
1840 * | |
1841 * @return the array of icon sizes | |
1842 * | |
1843 * @exception SWTException <ul> | |
1844 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1845 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1846 * </ul> | |
1847 * | |
1848 * @see Decorations#setImages(Image[]) | |
1849 * | |
1850 * @since 3.0 | |
1851 */ | |
1852 public Point [] getIconSizes () { | |
1853 checkDevice (); | |
1854 return [new Point (16, 16), new Point (32, 32)]; | |
1855 } | |
1856 | |
1857 int getLastEventTime () { | |
1858 return lastEventTime; | |
1859 } | |
1860 | |
1861 int getMessageCount () { | |
1862 return synchronizer.getMessageCount (); | |
1863 } | |
1864 | |
1865 Dialog getModalDialog () { | |
1866 return modalDialog; | |
1867 } | |
1868 | |
1869 /** | |
1870 * Returns the work area, an EWMH property to store the size | |
1871 * and position of the screen not covered by dock and panel | |
1872 * windows. See http://freedesktop.org/Standards/wm-spec. | |
1873 */ | |
1874 Rectangle getWorkArea() { | |
1875 auto atom = OS.gdk_atom_intern ("_NET_WORKAREA".ptr, true); | |
1876 if (atom is null/*OS.GDK_NONE*/) return null; | |
1877 void* actualType; | |
1878 int actualFormat; | |
1879 int actualLength; | |
1880 char* data; | |
1881 if (!OS.gdk_property_get (cast(GdkDrawable*)OS.GDK_ROOT_PARENT (), atom, null/*OS.GDK_NONE*/, 0, 16, 0, &actualType, &actualFormat, &actualLength, &data)) { | |
1882 return null; | |
1883 } | |
1884 Rectangle result = null; | |
1885 if (data !is null) { | |
1886 if (actualLength is 16) { | |
1887 int[] values = (cast(int*)data)[0..4]; | |
1888 result = new Rectangle (values [0],values [1],values [2],values [3]); | |
1889 } else if (actualLength is 32) { | |
1890 long[] values = (cast(long*)data)[0..4]; | |
1891 result = new Rectangle (cast(int)values [0],cast(int)values [1],cast(int)values [2],cast(int)values [3]); | |
1892 } | |
1893 OS.g_free (data); | |
1894 } | |
1895 return result; | |
1896 } | |
1897 | |
1898 /** | |
1899 * Returns an array of monitors attached to the device. | |
1900 * | |
1901 * @return the array of monitors | |
1902 * | |
1903 * @since 3.0 | |
1904 */ | |
1905 public org.eclipse.swt.widgets.Monitor.Monitor [] getMonitors () { | |
1906 checkDevice (); | |
1907 org.eclipse.swt.widgets.Monitor.Monitor [] monitors = null; | |
1908 Rectangle workArea = getWorkArea(); | |
1909 auto screen = OS.gdk_screen_get_default (); | |
1910 if (screen !is null) { | |
1911 int monitorCount = OS.gdk_screen_get_n_monitors (screen); | |
1912 if (monitorCount > 0) { | |
1913 monitors = new org.eclipse.swt.widgets.Monitor.Monitor [monitorCount]; | |
1914 GdkRectangle* dest = new GdkRectangle (); | |
1915 for (int i = 0; i < monitorCount; i++) { | |
1916 OS.gdk_screen_get_monitor_geometry (screen, i, dest); | |
1917 auto monitor = new org.eclipse.swt.widgets.Monitor.Monitor (); | |
1918 monitor.handle = i; | |
1919 monitor.x = dest.x; | |
1920 monitor.y = dest.y; | |
1921 monitor.width = dest.width; | |
1922 monitor.height = dest.height; | |
1923 if (i is 0 && workArea !is null) { | |
1924 monitor.clientX = workArea.x; | |
1925 monitor.clientY = workArea.y; | |
1926 monitor.clientWidth = workArea.width; | |
1927 monitor.clientHeight = workArea.height; | |
1928 } else { | |
1929 monitor.clientX = monitor.x; | |
1930 monitor.clientY = monitor.y; | |
1931 monitor.clientWidth = monitor.width; | |
1932 monitor.clientHeight = monitor.height; | |
1933 } | |
1934 monitors [i] = monitor; | |
1935 } | |
1936 } | |
1937 } | |
1938 if (monitors is null) { | |
1939 /* No multimonitor support detected, default to one monitor */ | |
1940 auto monitor = new org.eclipse.swt.widgets.Monitor.Monitor (); | |
1941 Rectangle bounds = getBounds (); | |
1942 monitor.x = bounds.x; | |
1943 monitor.y = bounds.y; | |
1944 monitor.width = bounds.width; | |
1945 monitor.height = bounds.height; | |
1946 if (workArea !is null) { | |
1947 monitor.clientX = workArea.x; | |
1948 monitor.clientY = workArea.y; | |
1949 monitor.clientWidth = workArea.width; | |
1950 monitor.clientHeight = workArea.height; | |
1951 } else { | |
1952 monitor.clientX = monitor.x; | |
1953 monitor.clientY = monitor.y; | |
1954 monitor.clientWidth = monitor.width; | |
1955 monitor.clientHeight = monitor.height; | |
1956 } | |
1957 monitors = [ monitor ]; | |
1958 } | |
1959 return monitors; | |
1960 } | |
1961 | |
1962 /** | |
1963 * Returns the primary monitor for that device. | |
1964 * | |
1965 * @return the primary monitor | |
1966 * | |
1967 * @since 3.0 | |
1968 */ | |
1969 public org.eclipse.swt.widgets.Monitor.Monitor getPrimaryMonitor () { | |
1970 checkDevice (); | |
1971 auto monitors = getMonitors (); | |
1972 return monitors [0]; | |
1973 } | |
1974 | |
1975 /** | |
1976 * Returns a (possibly empty) array containing all shells which have | |
1977 * not been disposed and have the receiver as their display. | |
1978 * | |
1979 * @return the receiver's shells | |
1980 * | |
1981 * @exception SWTException <ul> | |
1982 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1983 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1984 * </ul> | |
1985 */ | |
1986 public Shell [] getShells () { | |
1987 checkDevice (); | |
1988 int index = 0; | |
1989 Shell [] result = new Shell [16]; | |
1990 for (int i = 0; i < widgetTable.length; i++) { | |
1991 Widget widget = widgetTable [i]; | |
1992 if (widget !is null && (null !is cast(Shell)widget)) { | |
1993 int j = 0; | |
1994 while (j < index) { | |
1995 if (result [j] is widget) break; | |
1996 j++; | |
1997 } | |
1998 if (j is index) { | |
1999 if (index is result.length) { | |
2000 Shell [] newResult = new Shell [index + 16]; | |
2001 System.arraycopy (result, 0, newResult, 0, index); | |
2002 result = newResult; | |
2003 } | |
2004 result [index++] = cast(Shell) widget; | |
2005 } | |
2006 } | |
2007 } | |
2008 if (index is result.length) return result; | |
2009 Shell [] newResult = new Shell [index]; | |
2010 System.arraycopy (result, 0, newResult, 0, index); | |
2011 return newResult; | |
2012 } | |
2013 | |
2014 /** | |
2015 * Gets the synchronizer used by the display. | |
2016 * | |
2017 * @return the receiver's synchronizer | |
2018 * | |
2019 * @exception SWTException <ul> | |
2020 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2021 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2022 * </ul> | |
2023 * | |
2024 * @since 3.4 | |
2025 */ | |
2026 public Synchronizer getSynchronizer () { | |
2027 checkDevice (); | |
2028 return synchronizer; | |
2029 } | |
2030 | |
2031 /** | |
2032 * Returns the thread that has invoked <code>syncExec</code> | |
2033 * or null if no such runnable is currently being invoked by | |
2034 * the user-interface thread. | |
2035 * <p> | |
2036 * Note: If a runnable invoked by asyncExec is currently | |
2037 * running, this method will return null. | |
2038 * </p> | |
2039 * | |
2040 * @return the receiver's sync-interface thread | |
2041 * | |
2042 * @exception SWTException <ul> | |
2043 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2044 * </ul> | |
2045 */ | |
2046 public Thread getSyncThread () { | |
2047 synchronized (Device.classinfo) { | |
2048 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
2049 return synchronizer.syncThread; | |
2050 } | |
2051 } | |
2052 | |
2053 /** | |
2054 * Returns the matching standard color for the given | |
2055 * constant, which should be one of the color constants | |
2056 * specified in class <code>SWT</code>. Any value other | |
2057 * than one of the SWT color constants which is passed | |
2058 * in will result in the color black. This color should | |
2059 * not be free'd because it was allocated by the system, | |
2060 * not the application. | |
2061 * | |
2062 * @param id the color constant | |
2063 * @return the matching color | |
2064 * | |
2065 * @exception SWTException <ul> | |
2066 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2067 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2068 * </ul> | |
2069 * | |
2070 * @see SWT | |
2071 */ | |
2072 public override Color getSystemColor (int id) { | |
2073 checkDevice (); | |
2074 GdkColor* gdkColor = null; | |
2075 switch (id) { | |
2076 case SWT.COLOR_INFO_FOREGROUND: gdkColor = COLOR_INFO_FOREGROUND; break; | |
2077 case SWT.COLOR_INFO_BACKGROUND: gdkColor = COLOR_INFO_BACKGROUND; break; | |
2078 case SWT.COLOR_TITLE_FOREGROUND: gdkColor = COLOR_TITLE_FOREGROUND; break; | |
2079 case SWT.COLOR_TITLE_BACKGROUND: gdkColor = COLOR_TITLE_BACKGROUND; break; | |
2080 case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_BACKGROUND_GRADIENT; break; | |
2081 case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: gdkColor = COLOR_TITLE_INACTIVE_FOREGROUND; break; | |
2082 case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND; break; | |
2083 case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT; break; | |
2084 case SWT.COLOR_WIDGET_DARK_SHADOW: gdkColor = COLOR_WIDGET_DARK_SHADOW; break; | |
2085 case SWT.COLOR_WIDGET_NORMAL_SHADOW: gdkColor = COLOR_WIDGET_NORMAL_SHADOW; break; | |
2086 case SWT.COLOR_WIDGET_LIGHT_SHADOW: gdkColor = COLOR_WIDGET_LIGHT_SHADOW; break; | |
2087 case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: gdkColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break; | |
2088 case SWT.COLOR_WIDGET_BACKGROUND: gdkColor = COLOR_WIDGET_BACKGROUND; break; | |
2089 case SWT.COLOR_WIDGET_FOREGROUND: gdkColor = COLOR_WIDGET_FOREGROUND; break; | |
2090 case SWT.COLOR_WIDGET_BORDER: gdkColor = COLOR_WIDGET_BORDER; break; | |
2091 case SWT.COLOR_LIST_FOREGROUND: gdkColor = COLOR_LIST_FOREGROUND; break; | |
2092 case SWT.COLOR_LIST_BACKGROUND: gdkColor = COLOR_LIST_BACKGROUND; break; | |
2093 case SWT.COLOR_LIST_SELECTION: gdkColor = COLOR_LIST_SELECTION; break; | |
2094 case SWT.COLOR_LIST_SELECTION_TEXT: gdkColor = COLOR_LIST_SELECTION_TEXT; break; | |
2095 default: | |
2096 return super.getSystemColor (id); | |
2097 } | |
2098 if (gdkColor is null) return super.getSystemColor (SWT.COLOR_BLACK); | |
2099 return Color.gtk_new (this, gdkColor); | |
2100 } | |
2101 | |
2102 /** | |
2103 * Returns the matching standard platform cursor for the given | |
2104 * constant, which should be one of the cursor constants | |
2105 * specified in class <code>SWT</code>. This cursor should | |
2106 * not be free'd because it was allocated by the system, | |
2107 * not the application. A value of <code>null</code> will | |
2108 * be returned if the supplied constant is not an SWT cursor | |
2109 * constant. | |
2110 * | |
2111 * @param id the SWT cursor constant | |
2112 * @return the corresponding cursor or <code>null</code> | |
2113 * | |
2114 * @exception SWTException <ul> | |
2115 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2116 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2117 * </ul> | |
2118 * | |
2119 * @see SWT#CURSOR_ARROW | |
2120 * @see SWT#CURSOR_WAIT | |
2121 * @see SWT#CURSOR_CROSS | |
2122 * @see SWT#CURSOR_APPSTARTING | |
2123 * @see SWT#CURSOR_HELP | |
2124 * @see SWT#CURSOR_SIZEALL | |
2125 * @see SWT#CURSOR_SIZENESW | |
2126 * @see SWT#CURSOR_SIZENS | |
2127 * @see SWT#CURSOR_SIZENWSE | |
2128 * @see SWT#CURSOR_SIZEWE | |
2129 * @see SWT#CURSOR_SIZEN | |
2130 * @see SWT#CURSOR_SIZES | |
2131 * @see SWT#CURSOR_SIZEE | |
2132 * @see SWT#CURSOR_SIZEW | |
2133 * @see SWT#CURSOR_SIZENE | |
2134 * @see SWT#CURSOR_SIZESE | |
2135 * @see SWT#CURSOR_SIZESW | |
2136 * @see SWT#CURSOR_SIZENW | |
2137 * @see SWT#CURSOR_UPARROW | |
2138 * @see SWT#CURSOR_IBEAM | |
2139 * @see SWT#CURSOR_NO | |
2140 * @see SWT#CURSOR_HAND | |
2141 * | |
2142 * @since 3.0 | |
2143 */ | |
2144 public Cursor getSystemCursor (int id) { | |
2145 checkDevice (); | |
2146 if (!(0 <= id && id < cursors.length)) return null; | |
2147 if (cursors [id] is null) { | |
2148 cursors [id] = new Cursor (this, id); | |
2149 } | |
2150 return cursors [id]; | |
2151 } | |
2152 | |
2153 /** | |
2154 * Returns the matching standard platform image for the given | |
2155 * constant, which should be one of the icon constants | |
2156 * specified in class <code>SWT</code>. This image should | |
2157 * not be free'd because it was allocated by the system, | |
2158 * not the application. A value of <code>null</code> will | |
2159 * be returned either if the supplied constant is not an | |
2160 * SWT icon constant or if the platform does not define an | |
2161 * image that corresponds to the constant. | |
2162 * | |
2163 * @param id the SWT icon constant | |
2164 * @return the corresponding image or <code>null</code> | |
2165 * | |
2166 * @exception SWTException <ul> | |
2167 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2168 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2169 * </ul> | |
2170 * | |
2171 * @see SWT#ICON_ERROR | |
2172 * @see SWT#ICON_INFORMATION | |
2173 * @see SWT#ICON_QUESTION | |
2174 * @see SWT#ICON_WARNING | |
2175 * @see SWT#ICON_WORKING | |
2176 * | |
2177 * @since 3.0 | |
2178 */ | |
2179 public Image getSystemImage (int id) { | |
2180 checkDevice (); | |
2181 switch (id) { | |
2182 case SWT.ICON_ERROR: | |
2183 if (errorImage is null) { | |
2184 errorImage = createImage ("gtk-dialog-error"); //$NON-NLS-1$ | |
2185 } | |
2186 return errorImage; | |
2187 case SWT.ICON_INFORMATION: | |
2188 case SWT.ICON_WORKING: | |
2189 if (infoImage is null) { | |
2190 infoImage = createImage ("gtk-dialog-info"); //$NON-NLS-1$ | |
2191 } | |
2192 return infoImage; | |
2193 case SWT.ICON_QUESTION: | |
2194 if (questionImage is null) { | |
2195 questionImage = createImage ("gtk-dialog-question"); //$NON-NLS-1$ | |
2196 } | |
2197 return questionImage; | |
2198 case SWT.ICON_WARNING: | |
2199 if (warningImage is null) { | |
2200 warningImage = createImage ("gtk-dialog-warning"); //$NON-NLS-1$ | |
2201 } | |
2202 return warningImage; | |
2203 default: | |
2204 } | |
2205 return null; | |
2206 } | |
2207 | |
2208 void initializeSystemColors () { | |
2209 GdkColor* gdkColor; | |
2210 | |
2211 /* Get Tooltip resources */ | |
2212 auto tooltipShellHandle = OS.gtk_window_new (OS.GTK_WINDOW_POPUP); | |
2213 if (tooltipShellHandle is null) SWT.error (SWT.ERROR_NO_HANDLES); | |
2214 // byte[] gtk_tooltips = Converter.wcsToMbcs (null, "gtk-tooltips", true); | |
2215 OS.gtk_widget_set_name (tooltipShellHandle, "gtk-tooltips".ptr ); | |
2216 OS.gtk_widget_realize (tooltipShellHandle); | |
2217 auto tooltipStyle = OS.gtk_widget_get_style (tooltipShellHandle); | |
2218 gdkColor = new GdkColor(); | |
2219 OS.gtk_style_get_fg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor); | |
2220 COLOR_INFO_FOREGROUND = gdkColor; | |
2221 gdkColor = new GdkColor(); | |
2222 OS.gtk_style_get_bg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor); | |
2223 COLOR_INFO_BACKGROUND = gdkColor; | |
2224 OS.gtk_widget_destroy (tooltipShellHandle); | |
2225 | |
2226 /* Get Shell resources */ | |
2227 auto style = OS.gtk_widget_get_style (shellHandle); | |
2228 gdkColor = new GdkColor(); | |
2229 OS.gtk_style_get_black (style, gdkColor); | |
2230 COLOR_WIDGET_DARK_SHADOW = gdkColor; | |
2231 gdkColor = new GdkColor(); | |
2232 OS.gtk_style_get_dark (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2233 COLOR_WIDGET_NORMAL_SHADOW = gdkColor; | |
2234 gdkColor = new GdkColor(); | |
2235 OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2236 COLOR_WIDGET_LIGHT_SHADOW = gdkColor; | |
2237 gdkColor = new GdkColor(); | |
2238 OS.gtk_style_get_light (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2239 COLOR_WIDGET_HIGHLIGHT_SHADOW = gdkColor; | |
2240 gdkColor = new GdkColor(); | |
2241 OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2242 COLOR_WIDGET_FOREGROUND = gdkColor; | |
2243 gdkColor = new GdkColor(); | |
2244 OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2245 COLOR_WIDGET_BACKGROUND = gdkColor; | |
2246 //gdkColor = new GdkColor(); | |
2247 //OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2248 //COLOR_TEXT_FOREGROUND = gdkColor; | |
2249 //gdkColor = new GdkColor(); | |
2250 //OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2251 //COLOR_TEXT_BACKGROUND = gdkColor; | |
2252 gdkColor = new GdkColor(); | |
2253 OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2254 COLOR_LIST_FOREGROUND = gdkColor; | |
2255 gdkColor = new GdkColor(); | |
2256 OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2257 COLOR_LIST_BACKGROUND = gdkColor; | |
2258 gdkColor = new GdkColor(); | |
2259 OS.gtk_style_get_text (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2260 COLOR_LIST_SELECTION_TEXT = gdkColor; | |
2261 gdkColor = new GdkColor(); | |
2262 OS.gtk_style_get_base (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2263 COLOR_LIST_SELECTION = gdkColor; | |
2264 gdkColor = new GdkColor(); | |
2265 OS.gtk_style_get_bg (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2266 COLOR_TITLE_BACKGROUND = gdkColor; | |
2267 gdkColor = new GdkColor(); | |
2268 OS.gtk_style_get_fg (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2269 COLOR_TITLE_FOREGROUND = gdkColor; | |
2270 gdkColor = new GdkColor(); | |
2271 OS.gtk_style_get_light (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2272 COLOR_TITLE_BACKGROUND_GRADIENT = gdkColor; | |
2273 gdkColor = new GdkColor(); | |
2274 OS.gtk_style_get_bg (style, OS.GTK_STATE_INSENSITIVE, gdkColor); | |
2275 COLOR_TITLE_INACTIVE_BACKGROUND = gdkColor; | |
2276 gdkColor = new GdkColor(); | |
2277 OS.gtk_style_get_fg (style, OS.GTK_STATE_INSENSITIVE, gdkColor); | |
2278 COLOR_TITLE_INACTIVE_FOREGROUND = gdkColor; | |
2279 gdkColor = new GdkColor(); | |
2280 OS.gtk_style_get_light (style, OS.GTK_STATE_INSENSITIVE, gdkColor); | |
2281 COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = gdkColor; | |
2282 } | |
2283 | |
2284 /** | |
2285 * Returns a reasonable font for applications to use. | |
2286 * On some platforms, this will match the "default font" | |
2287 * or "system font" if such can be found. This font | |
2288 * should not be free'd because it was allocated by the | |
2289 * system, not the application. | |
2290 * <p> | |
2291 * Typically, applications which want the default look | |
2292 * should simply not set the font on the widgets they | |
2293 * create. Widgets are always created with the correct | |
2294 * default font for the class of user-interface component | |
2295 * they represent. | |
2296 * </p> | |
2297 * | |
2298 * @return a font | |
2299 * | |
2300 * @exception SWTException <ul> | |
2301 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2302 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2303 * </ul> | |
2304 */ | |
2305 public override Font getSystemFont () { | |
2306 checkDevice (); | |
2307 if (systemFont !is null) return systemFont; | |
2308 auto style = OS.gtk_widget_get_style (shellHandle); | |
2309 auto defaultFont = OS.pango_font_description_copy (OS.gtk_style_get_font_desc (style)); | |
2310 return systemFont = Font.gtk_new (this, defaultFont); | |
2311 } | |
2312 | |
2313 /** | |
2314 * Returns the single instance of the system tray or null | |
2315 * when there is no system tray available for the platform. | |
2316 * | |
2317 * @return the system tray or <code>null</code> | |
2318 * | |
2319 * @exception SWTException <ul> | |
2320 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2321 * </ul> | |
2322 * | |
2323 * @since 3.0 | |
2324 */ | |
2325 public Tray getSystemTray () { | |
2326 checkDevice (); | |
2327 if (tray !is null) return tray; | |
2328 return tray = new Tray (this, SWT.NONE); | |
2329 } | |
2330 | |
2331 /** | |
2332 * Returns the user-interface thread for the receiver. | |
2333 * | |
2334 * @return the receiver's user-interface thread | |
2335 * | |
2336 * @exception SWTException <ul> | |
2337 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2338 * </ul> | |
2339 */ | |
2340 public Thread getThread () { | |
2341 synchronized (Device.classinfo) { | |
2342 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
2343 return thread; | |
2344 } | |
2345 } | |
2346 | |
2347 Widget getWidget (GtkWidget* handle) { | |
2348 if (handle is null) return null; | |
2349 if (lastWidget !is null && lastHandle is handle) return lastWidget; | |
2350 auto index = cast(int) OS.g_object_get_qdata ( cast(GObject*)handle, SWT_OBJECT_INDEX) - 1; | |
2351 if (0 <= index && index < widgetTable.length) { | |
2352 lastHandle = handle; | |
2353 return lastWidget = widgetTable [cast(int)/*64*/index]; | |
2354 } | |
2355 return null; | |
2356 } | |
2357 | |
2358 private static extern(C) int idleProcFunc (void* data) { | |
2359 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
2360 auto dbdata = cast(CallbackData*)data; | |
2361 return dbdata.display.idleProc(); | |
2362 } | |
2363 private int idleProc () { | |
2364 bool result = runAsyncMessages (false); | |
2365 if (!result) { | |
2366 synchronized (idleLock) { | |
2367 idleHandle = 0; | |
2368 } | |
2369 } | |
2370 return result ? 1 : 0; | |
2371 return 0; | |
2372 } | |
2373 | |
2374 /** | |
2375 * Initializes any internal resources needed by the | |
2376 * device. | |
2377 * <p> | |
2378 * This method is called after <code>create</code>. | |
2379 * </p> | |
2380 * | |
2381 * @see #create | |
2382 */ | |
2383 protected override void init_ () { | |
2384 super.init_ (); | |
2385 initializeCallbacks (); | |
2386 initializeSystemColors (); | |
2387 initializeSystemSettings (); | |
2388 initializeWidgetTable (); | |
2389 initializeWindowManager (); | |
2390 } | |
2391 | |
2392 void initializeCallbacks () { | |
2393 closures = new GClosure* [Widget.LAST_SIGNAL]; | |
2394 signalIds = new int [Widget.LAST_SIGNAL]; | |
2395 | |
2396 /* Cache signals for GtkWidget */ | |
2397 signalIds [Widget.BUTTON_PRESS_EVENT] = OS.g_signal_lookup (OS.button_press_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2398 signalIds [Widget.BUTTON_RELEASE_EVENT] = OS.g_signal_lookup (OS.button_release_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2399 signalIds [Widget.CONFIGURE_EVENT] = OS.g_signal_lookup (OS.configure_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2400 signalIds [Widget.DELETE_EVENT] = OS.g_signal_lookup (OS.delete_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2401 signalIds [Widget.ENTER_NOTIFY_EVENT] = OS.g_signal_lookup (OS.enter_notify_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2402 signalIds [Widget.EVENT] = OS.g_signal_lookup (OS.event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2403 signalIds [Widget.EVENT_AFTER] = OS.g_signal_lookup (OS.event_after.ptr, OS.GTK_TYPE_WIDGET ()); | |
2404 signalIds [Widget.EXPOSE_EVENT] = OS.g_signal_lookup (OS.expose_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2405 signalIds [Widget.FOCUS] = OS.g_signal_lookup (OS.focus.ptr, OS.GTK_TYPE_WIDGET ()); | |
2406 signalIds [Widget.FOCUS_IN_EVENT] = OS.g_signal_lookup (OS.focus_in_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2407 signalIds [Widget.FOCUS_OUT_EVENT] = OS.g_signal_lookup (OS.focus_out_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2408 signalIds [Widget.GRAB_FOCUS] = OS.g_signal_lookup (OS.grab_focus.ptr, OS.GTK_TYPE_WIDGET ()); | |
2409 signalIds [Widget.HIDE] = OS.g_signal_lookup (OS.hide.ptr, OS.GTK_TYPE_WIDGET ()); | |
2410 signalIds [Widget.KEY_PRESS_EVENT] = OS.g_signal_lookup (OS.key_press_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2411 signalIds [Widget.KEY_RELEASE_EVENT] = OS.g_signal_lookup (OS.key_release_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2412 signalIds [Widget.LEAVE_NOTIFY_EVENT] = OS.g_signal_lookup (OS.leave_notify_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2413 signalIds [Widget.MAP] = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET ()); | |
2414 signalIds [Widget.MAP_EVENT] = OS.g_signal_lookup (OS.map_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2415 signalIds [Widget.MNEMONIC_ACTIVATE] = OS.g_signal_lookup (OS.mnemonic_activate.ptr, OS.GTK_TYPE_WIDGET ()); | |
2416 signalIds [Widget.MOTION_NOTIFY_EVENT] = OS.g_signal_lookup (OS.motion_notify_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2417 signalIds [Widget.POPUP_MENU] = OS.g_signal_lookup (OS.popup_menu.ptr, OS.GTK_TYPE_WIDGET ()); | |
2418 signalIds [Widget.REALIZE] = OS.g_signal_lookup (OS.realize.ptr, OS.GTK_TYPE_WIDGET ()); | |
2419 signalIds [Widget.SCROLL_EVENT] = OS.g_signal_lookup (OS.scroll_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2420 signalIds [Widget.SHOW] = OS.g_signal_lookup (OS.show.ptr, OS.GTK_TYPE_WIDGET ()); | |
2421 signalIds [Widget.SHOW_HELP] = OS.g_signal_lookup (OS.show_help.ptr, OS.GTK_TYPE_WIDGET ()); | |
2422 signalIds [Widget.SIZE_ALLOCATE] = OS.g_signal_lookup (OS.size_allocate.ptr, OS.GTK_TYPE_WIDGET ()); | |
2423 signalIds [Widget.STYLE_SET] = OS.g_signal_lookup (OS.style_set.ptr, OS.GTK_TYPE_WIDGET ()); | |
2424 signalIds [Widget.UNMAP] = OS.g_signal_lookup (OS.unmap.ptr, OS.GTK_TYPE_WIDGET ()); | |
2425 signalIds [Widget.UNMAP_EVENT] = OS.g_signal_lookup (OS.unmap_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2426 signalIds [Widget.UNREALIZE] = OS.g_signal_lookup (OS.realize.ptr, OS.GTK_TYPE_WIDGET ()); | |
2427 signalIds [Widget.VISIBILITY_NOTIFY_EVENT] = OS.g_signal_lookup (OS.visibility_notify_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2428 signalIds [Widget.WINDOW_STATE_EVENT] = OS.g_signal_lookup (OS.window_state_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2429 | |
2430 GClosure* do_cclosure_new( GCallback cb, int value, int notify ){ | |
2431 CallbackData* res= new CallbackData; | |
2432 res.display = this; | |
2433 res.data = cast(void*)value; | |
2434 windowProcCallbackDatas[ value ] = res; | |
2435 return OS.g_cclosure_new( cb, cast(void*)res, cast(GClosureNotify)notify ); | |
2436 } | |
2437 | |
2438 GCallback windowProc2 = cast(GCallback)&windowProcFunc2; | |
2439 closures [Widget.ACTIVATE] = do_cclosure_new (windowProc2, Widget.ACTIVATE, 0); | |
2440 closures [Widget.ACTIVATE_INVERSE] = do_cclosure_new (windowProc2, Widget.ACTIVATE_INVERSE, 0); | |
2441 closures [Widget.CHANGED] = do_cclosure_new (windowProc2, Widget.CHANGED, 0); | |
2442 closures [Widget.CLICKED] = do_cclosure_new (windowProc2, Widget.CLICKED, 0); | |
2443 closures [Widget.DAY_SELECTED] = do_cclosure_new (windowProc2, Widget.DAY_SELECTED, 0); | |
2444 closures [Widget.HIDE] = do_cclosure_new (windowProc2, Widget.HIDE, 0); | |
2445 closures [Widget.GRAB_FOCUS] = do_cclosure_new (windowProc2, Widget.GRAB_FOCUS, 0); | |
2446 closures [Widget.MAP] = do_cclosure_new (windowProc2, Widget.MAP, 0); | |
2447 closures [Widget.MONTH_CHANGED] = do_cclosure_new (windowProc2, Widget.MONTH_CHANGED, 0); | |
2448 closures [Widget.OUTPUT] = do_cclosure_new (windowProc2, Widget.OUTPUT, 0); | |
2449 closures [Widget.POPUP_MENU] = do_cclosure_new (windowProc2, Widget.POPUP_MENU, 0); | |
2450 closures [Widget.PREEDIT_CHANGED] = do_cclosure_new (windowProc2, Widget.PREEDIT_CHANGED, 0); | |
2451 closures [Widget.REALIZE] = do_cclosure_new (windowProc2, Widget.REALIZE, 0); | |
2452 closures [Widget.SELECT] = do_cclosure_new (windowProc2, Widget.SELECT, 0); | |
2453 closures [Widget.SHOW] = do_cclosure_new (windowProc2, Widget.SHOW, 0); | |
2454 closures [Widget.VALUE_CHANGED] = do_cclosure_new (windowProc2, Widget.VALUE_CHANGED, 0); | |
2455 closures [Widget.UNMAP] = do_cclosure_new (windowProc2, Widget.UNMAP, 0); | |
2456 closures [Widget.UNREALIZE] = do_cclosure_new (windowProc2, Widget.UNREALIZE, 0); | |
2457 | |
2458 GCallback windowProc3 = cast(GCallback)&windowProcFunc3; | |
2459 closures [Widget.BUTTON_PRESS_EVENT] = do_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT, 0); | |
2460 closures [Widget.BUTTON_PRESS_EVENT_INVERSE] = do_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT_INVERSE, 0); | |
2461 closures [Widget.BUTTON_RELEASE_EVENT] = do_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT, 0); | |
2462 closures [Widget.BUTTON_RELEASE_EVENT_INVERSE] = do_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT_INVERSE, 0); | |
2463 closures [Widget.COMMIT] = do_cclosure_new (windowProc3, Widget.COMMIT, 0); | |
2464 closures [Widget.CONFIGURE_EVENT] = do_cclosure_new (windowProc3, Widget.CONFIGURE_EVENT, 0); | |
2465 closures [Widget.DELETE_EVENT] = do_cclosure_new (windowProc3, Widget.DELETE_EVENT, 0); | |
2466 closures [Widget.ENTER_NOTIFY_EVENT] = do_cclosure_new (windowProc3, Widget.ENTER_NOTIFY_EVENT, 0); | |
2467 closures [Widget.EVENT] = do_cclosure_new (windowProc3, Widget.EVENT, 0); | |
2468 closures [Widget.EVENT_AFTER] = do_cclosure_new (windowProc3, Widget.EVENT_AFTER, 0); | |
2469 closures [Widget.EXPOSE_EVENT] = do_cclosure_new (windowProc3, Widget.EXPOSE_EVENT, 0); | |
2470 closures [Widget.EXPOSE_EVENT_INVERSE] = do_cclosure_new (windowProc3, Widget.EXPOSE_EVENT_INVERSE, 0); | |
2471 closures [Widget.FOCUS] = do_cclosure_new (windowProc3, Widget.FOCUS, 0); | |
2472 closures [Widget.FOCUS_IN_EVENT] = do_cclosure_new (windowProc3, Widget.FOCUS_IN_EVENT, 0); | |
2473 closures [Widget.FOCUS_OUT_EVENT] = do_cclosure_new (windowProc3, Widget.FOCUS_OUT_EVENT, 0); | |
2474 closures [Widget.KEY_PRESS_EVENT] = do_cclosure_new (windowProc3, Widget.KEY_PRESS_EVENT, 0); | |
2475 closures [Widget.KEY_RELEASE_EVENT] = do_cclosure_new (windowProc3, Widget.KEY_RELEASE_EVENT, 0); | |
2476 closures [Widget.INPUT] = do_cclosure_new (windowProc3, Widget.INPUT, 0); | |
2477 closures [Widget.LEAVE_NOTIFY_EVENT] = do_cclosure_new (windowProc3, Widget.LEAVE_NOTIFY_EVENT, 0); | |
2478 closures [Widget.MAP_EVENT] = do_cclosure_new (windowProc3, Widget.MAP_EVENT, 0); | |
2479 closures [Widget.MNEMONIC_ACTIVATE] = do_cclosure_new (windowProc3, Widget.MNEMONIC_ACTIVATE, 0); | |
2480 closures [Widget.MOTION_NOTIFY_EVENT] = do_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT, 0); | |
2481 closures [Widget.MOTION_NOTIFY_EVENT_INVERSE] = do_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT_INVERSE, 0); | |
2482 closures [Widget.MOVE_FOCUS] = do_cclosure_new (windowProc3, Widget.MOVE_FOCUS, 0); | |
2483 closures [Widget.POPULATE_POPUP] = do_cclosure_new (windowProc3, Widget.POPULATE_POPUP, 0); | |
2484 closures [Widget.SCROLL_EVENT] = do_cclosure_new (windowProc3, Widget.SCROLL_EVENT, 0); | |
2485 closures [Widget.SHOW_HELP] = do_cclosure_new (windowProc3, Widget.SHOW_HELP, 0); | |
2486 closures [Widget.SIZE_ALLOCATE] = do_cclosure_new (windowProc3, Widget.SIZE_ALLOCATE, 0); | |
2487 closures [Widget.STYLE_SET] = do_cclosure_new (windowProc3, Widget.STYLE_SET, 0); | |
2488 closures [Widget.TOGGLED] = do_cclosure_new (windowProc3, Widget.TOGGLED, 0); | |
2489 closures [Widget.UNMAP_EVENT] = do_cclosure_new (windowProc3, Widget.UNMAP_EVENT, 0); | |
2490 closures [Widget.VISIBILITY_NOTIFY_EVENT] = do_cclosure_new (windowProc3, Widget.VISIBILITY_NOTIFY_EVENT, 0); | |
2491 closures [Widget.WINDOW_STATE_EVENT] = do_cclosure_new (windowProc3, Widget.WINDOW_STATE_EVENT, 0); | |
2492 | |
2493 GCallback windowProc4 = cast(GCallback)&windowProcFunc4; | |
2494 closures [Widget.DELETE_RANGE] = do_cclosure_new (windowProc4, Widget.DELETE_RANGE, 0); | |
2495 closures [Widget.DELETE_TEXT] = do_cclosure_new (windowProc4, Widget.DELETE_TEXT, 0); | |
2496 closures [Widget.ROW_ACTIVATED] = do_cclosure_new (windowProc4, Widget.ROW_ACTIVATED, 0); | |
2497 closures [Widget.SCROLL_CHILD] = do_cclosure_new (windowProc4, Widget.SCROLL_CHILD, 0); | |
2498 closures [Widget.SWITCH_PAGE] = do_cclosure_new (windowProc4, Widget.SWITCH_PAGE, 0); | |
2499 closures [Widget.TEST_COLLAPSE_ROW] = do_cclosure_new (windowProc4, Widget.TEST_COLLAPSE_ROW, 0); | |
2500 closures [Widget.TEST_EXPAND_ROW] = do_cclosure_new (windowProc4, Widget.TEST_EXPAND_ROW, 0); | |
2501 | |
2502 GCallback windowProc5 = cast(GCallback)&windowProcFunc5; | |
2503 closures [Widget.CHANGE_VALUE] = do_cclosure_new (windowProc5, Widget.CHANGE_VALUE, 0); | |
2504 closures [Widget.EXPAND_COLLAPSE_CURSOR_ROW] = do_cclosure_new (windowProc5, Widget.EXPAND_COLLAPSE_CURSOR_ROW, 0); | |
2505 closures [Widget.INSERT_TEXT] = do_cclosure_new (windowProc5, Widget.INSERT_TEXT, 0); | |
2506 closures [Widget.TEXT_BUFFER_INSERT_TEXT] = do_cclosure_new (windowProc5, Widget.TEXT_BUFFER_INSERT_TEXT, 0); | |
2507 | |
2508 for (int i = 0; i < Widget.LAST_SIGNAL; i++) { | |
2509 if (closures [i] !is null) OS.g_closure_ref (closures [i]); | |
2510 } | |
2511 shellMapProcCallbackData.display = this; | |
2512 shellMapProcCallbackData.data = null; | |
2513 shellMapProcClosure = OS.g_cclosure_new (cast(GCallback)&shellMapProcFunc, &shellMapProcCallbackData, cast(GClosureNotify)0); | |
2514 OS.g_closure_ref (shellMapProcClosure); | |
2515 } | |
2516 | |
2517 void* getWindowProcUserData( int value ){ | |
2518 return windowProcCallbackDatas[ value ]; | |
2519 | |
2520 } | |
2521 | |
2522 void initializeSystemSettings () { | |
2523 styleSetProcCallbackData.display = this; | |
2524 styleSetProcCallbackData.data = null; | |
2525 OS.g_signal_connect (shellHandle, OS.style_set.ptr, cast(GCallback)&styleSetProcFunc, &styleSetProcCallbackData); | |
2526 | |
2527 /* | |
2528 * Feature in GTK. Despite the fact that the | |
2529 * gtk-entry-select-on-focus property is a global | |
2530 * setting, it is initialized when the GtkEntry | |
2531 * is initialized. This means that it cannot be | |
2532 * accessed before a GtkEntry is created. The | |
2533 * fix is to for the initializaion by creating | |
2534 * a temporary GtkEntry. | |
2535 */ | |
2536 auto entry = OS.gtk_entry_new (); | |
2537 OS.gtk_widget_destroy (entry); | |
2538 int buffer2; | |
2539 auto settings = OS.gtk_settings_get_default (); | |
2540 OS.g_object_get1 (settings, OS.gtk_entry_select_on_focus.ptr, &buffer2); | |
2541 entrySelectOnFocus = buffer2 !is 0; | |
2542 } | |
2543 | |
2544 void initializeWidgetTable () { | |
2545 indexTable = new int [GROW_SIZE]; | |
2546 widgetTable = new Widget [GROW_SIZE]; | |
2547 for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1; | |
2548 indexTable [GROW_SIZE - 1] = -1; | |
2549 } | |
2550 | |
2551 void initializeWindowManager () { | |
2552 /* Get the window manager name */ | |
2553 windowManager = ""; //$NON-NLS-1$ | |
2554 if (OS.GTK_VERSION >= OS.buildVERSION (2, 2, 0)) { | |
2555 auto screen = OS.gdk_screen_get_default (); | |
2556 if (screen !is null) { | |
2557 auto ptr2 = OS.gdk_x11_screen_get_window_manager_name (screen); | |
2558 windowManager = fromStringz( ptr2 ); | |
2559 } | |
2560 } | |
2561 } | |
2562 | |
2563 /** | |
2564 * Invokes platform specific functionality to dispose a GC handle. | |
2565 * <p> | |
2566 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
2567 * API for <code>Display</code>. It is marked public only so that it | |
2568 * can be shared within the packages provided by SWT. It is not | |
2569 * available on all platforms, and should never be called from | |
2570 * application code. | |
2571 * </p> | |
2572 * | |
2573 * @param hDC the platform specific GC handle | |
2574 * @param data the platform specific GC data | |
2575 */ | |
2576 public override void internal_dispose_GC (GdkGC* gdkGC, GCData data) { | |
2577 OS.g_object_unref (gdkGC); | |
2578 } | |
2579 | |
2580 /** | |
2581 * Invokes platform specific functionality to allocate a new GC handle. | |
2582 * <p> | |
2583 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
2584 * API for <code>Display</code>. It is marked public only so that it | |
2585 * can be shared within the packages provided by SWT. It is not | |
2586 * available on all platforms, and should never be called from | |
2587 * application code. | |
2588 * </p> | |
2589 * | |
2590 * @param data the platform specific GC data | |
2591 * @return the platform specific GC handle | |
2592 * | |
2593 * @exception SWTException <ul> | |
2594 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2595 * </ul> | |
2596 * @exception SWTError <ul> | |
2597 * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li> | |
2598 * </ul> | |
2599 */ | |
2600 public override GdkGC* internal_new_GC (GCData data) { | |
2601 if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED); | |
2602 auto root = cast(GdkDrawable *) OS.GDK_ROOT_PARENT (); | |
2603 auto gdkGC = OS.gdk_gc_new (root); | |
2604 if (gdkGC is null) SWT.error (SWT.ERROR_NO_HANDLES); | |
2605 OS.gdk_gc_set_subwindow (gdkGC, OS.GDK_INCLUDE_INFERIORS); | |
2606 if (data !is null) { | |
2607 int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; | |
2608 if ((data.style & mask) is 0) { | |
2609 data.style |= SWT.LEFT_TO_RIGHT; | |
2610 } | |
2611 data.device = this; | |
2612 data.drawable = root; | |
2613 data.background = getSystemColor (SWT.COLOR_WHITE).handle; | |
2614 data.foreground = getSystemColor (SWT.COLOR_BLACK).handle; | |
2615 data.font = getSystemFont (); | |
2616 } | |
2617 return gdkGC; | |
2618 return null; | |
2619 } | |
2620 | |
2621 bool isValidThread () { | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
2622 return thread is Thread.currentThread (); |
25 | 2623 } |
2624 | |
2625 /** | |
2626 * Maps a point from one coordinate system to another. | |
2627 * When the control is null, coordinates are mapped to | |
2628 * the display. | |
2629 * <p> | |
2630 * NOTE: On right-to-left platforms where the coordinate | |
2631 * systems are mirrored, special care needs to be taken | |
2632 * when mapping coordinates from one control to another | |
2633 * to ensure the result is correctly mirrored. | |
2634 * | |
2635 * Mapping a point that is the origin of a rectangle and | |
2636 * then adding the width and height is not equivalent to | |
2637 * mapping the rectangle. When one control is mirrored | |
2638 * and the other is not, adding the width and height to a | |
2639 * point that was mapped causes the rectangle to extend | |
2640 * in the wrong direction. Mapping the entire rectangle | |
2641 * instead of just one point causes both the origin and | |
2642 * the corner of the rectangle to be mapped. | |
2643 * </p> | |
2644 * | |
2645 * @param from the source <code>Control</code> or <code>null</code> | |
2646 * @param to the destination <code>Control</code> or <code>null</code> | |
2647 * @param point to be mapped | |
2648 * @return point with mapped coordinates | |
2649 * | |
2650 * @exception IllegalArgumentException <ul> | |
2651 * <li>ERROR_NULL_ARGUMENT - if the point is null</li> | |
2652 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> | |
2653 * </ul> | |
2654 * @exception SWTException <ul> | |
2655 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2656 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2657 * </ul> | |
2658 * | |
2659 * @since 2.1.2 | |
2660 */ | |
2661 public Point map (Control from, Control to, Point point) { | |
2662 checkDevice (); | |
2663 if (point is null) error (SWT.ERROR_NULL_ARGUMENT); | |
2664 return map (from, to, point.x, point.y); | |
2665 } | |
2666 | |
2667 /** | |
2668 * Maps a point from one coordinate system to another. | |
2669 * When the control is null, coordinates are mapped to | |
2670 * the display. | |
2671 * <p> | |
2672 * NOTE: On right-to-left platforms where the coordinate | |
2673 * systems are mirrored, special care needs to be taken | |
2674 * when mapping coordinates from one control to another | |
2675 * to ensure the result is correctly mirrored. | |
2676 * | |
2677 * Mapping a point that is the origin of a rectangle and | |
2678 * then adding the width and height is not equivalent to | |
2679 * mapping the rectangle. When one control is mirrored | |
2680 * and the other is not, adding the width and height to a | |
2681 * point that was mapped causes the rectangle to extend | |
2682 * in the wrong direction. Mapping the entire rectangle | |
2683 * instead of just one point causes both the origin and | |
2684 * the corner of the rectangle to be mapped. | |
2685 * </p> | |
2686 * | |
2687 * @param from the source <code>Control</code> or <code>null</code> | |
2688 * @param to the destination <code>Control</code> or <code>null</code> | |
2689 * @param x coordinates to be mapped | |
2690 * @param y coordinates to be mapped | |
2691 * @return point with mapped coordinates | |
2692 * | |
2693 * @exception IllegalArgumentException <ul> | |
2694 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> | |
2695 * </ul> | |
2696 * @exception SWTException <ul> | |
2697 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2698 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2699 * </ul> | |
2700 * | |
2701 * @since 2.1.2 | |
2702 */ | |
2703 public Point map (Control from, Control to, int x, int y) { | |
2704 checkDevice (); | |
2705 if (from !is null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); | |
2706 if (to !is null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); | |
2707 Point point = new Point (x, y); | |
2708 if (from is to) return point; | |
2709 if (from !is null) { | |
2710 auto window = from.eventWindow (); | |
2711 int origin_x, origin_y; | |
2712 OS.gdk_window_get_origin (window, &origin_x, &origin_y); | |
2713 if ((from.style & SWT.MIRRORED) !is 0) point.x = from.getClientWidth () - point.x; | |
2714 point.x += origin_x; | |
2715 point.y += origin_y; | |
2716 } | |
2717 if (to !is null) { | |
2718 auto window = to.eventWindow (); | |
2719 int origin_x, origin_y; | |
2720 OS.gdk_window_get_origin (window, &origin_x, &origin_y); | |
2721 point.x -= origin_x; | |
2722 point.y -= origin_y; | |
2723 if ((to.style & SWT.MIRRORED) !is 0) point.x = to.getClientWidth () - point.x; | |
2724 } | |
2725 return point; | |
2726 } | |
2727 | |
2728 /** | |
2729 * Maps a point from one coordinate system to another. | |
2730 * When the control is null, coordinates are mapped to | |
2731 * the display. | |
2732 * <p> | |
2733 * NOTE: On right-to-left platforms where the coordinate | |
2734 * systems are mirrored, special care needs to be taken | |
2735 * when mapping coordinates from one control to another | |
2736 * to ensure the result is correctly mirrored. | |
2737 * | |
2738 * Mapping a point that is the origin of a rectangle and | |
2739 * then adding the width and height is not equivalent to | |
2740 * mapping the rectangle. When one control is mirrored | |
2741 * and the other is not, adding the width and height to a | |
2742 * point that was mapped causes the rectangle to extend | |
2743 * in the wrong direction. Mapping the entire rectangle | |
2744 * instead of just one point causes both the origin and | |
2745 * the corner of the rectangle to be mapped. | |
2746 * </p> | |
2747 * | |
2748 * @param from the source <code>Control</code> or <code>null</code> | |
2749 * @param to the destination <code>Control</code> or <code>null</code> | |
2750 * @param rectangle to be mapped | |
2751 * @return rectangle with mapped coordinates | |
2752 * | |
2753 * @exception IllegalArgumentException <ul> | |
2754 * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> | |
2755 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> | |
2756 * </ul> | |
2757 * @exception SWTException <ul> | |
2758 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2759 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2760 * </ul> | |
2761 * | |
2762 * @since 2.1.2 | |
2763 */ | |
2764 public Rectangle map (Control from, Control to, Rectangle rectangle) { | |
2765 checkDevice(); | |
2766 if (rectangle is null) error (SWT.ERROR_NULL_ARGUMENT); | |
2767 return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height); | |
2768 } | |
2769 | |
2770 static wchar mbcsToWcs (wchar ch) { | |
2771 int key = ch & 0xFFFF; | |
2772 if (key <= 0x7F) return ch; | |
2773 char [] buffer; | |
2774 if (key <= 0xFF) { | |
2775 buffer = new char [1]; | |
2776 buffer [0] = cast(char) key; | |
2777 } else { | |
2778 buffer = new char [2]; | |
2779 buffer [0] = cast(char) ((key >> 8) & 0xFF); | |
2780 buffer [1] = cast(char) (key & 0xFF); | |
2781 } | |
2782 wchar [] result = Converter.mbcsToWcs (null, buffer); | |
2783 if (result.length is 0) return 0; | |
2784 return result [0]; | |
2785 } | |
2786 | |
2787 | |
2788 package void doMenuPositionProc( GtkMenu* window, bool hasLocation ){ | |
2789 /* | |
2790 * Bug in GTK. The timestamp passed into gtk_menu_popup is used | |
2791 * to perform an X pointer grab. It cannot be zero, else the grab | |
2792 * will fail. The fix is to ensure that the timestamp of the last | |
2793 * event processed is used. | |
2794 */ | |
2795 OS.gtk_menu_popup (window, null, null, | |
2796 hasLocation ? &menuPositionProcFunc : null, | |
2797 cast(void*)this, 0, getLastEventTime() ); | |
2798 } | |
2799 | |
2800 private static extern(C) void menuPositionProcFunc (GtkMenu* menu, int* x, int* y, int* push_in, void* user_data) { | |
2801 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
2802 auto display = cast(Display)user_data; | |
2803 display.menuPositionProc( menu, x, y, push_in, null ); | |
2804 } | |
2805 | |
2806 void menuPositionProc (GtkMenu* menu, int* x, int* y, int* push_in, void* user_data) { | |
2807 Widget widget = getWidget (cast(GtkWidget*)menu); | |
2808 if (widget is null) return 0; | |
2809 widget.menuPositionProc (menu, x, y, push_in, user_data); | |
2810 } | |
2811 | |
2812 /** | |
2813 * Maps a point from one coordinate system to another. | |
2814 * When the control is null, coordinates are mapped to | |
2815 * the display. | |
2816 * <p> | |
2817 * NOTE: On right-to-left platforms where the coordinate | |
2818 * systems are mirrored, special care needs to be taken | |
2819 * when mapping coordinates from one control to another | |
2820 * to ensure the result is correctly mirrored. | |
2821 * | |
2822 * Mapping a point that is the origin of a rectangle and | |
2823 * then adding the width and height is not equivalent to | |
2824 * mapping the rectangle. When one control is mirrored | |
2825 * and the other is not, adding the width and height to a | |
2826 * point that was mapped causes the rectangle to extend | |
2827 * in the wrong direction. Mapping the entire rectangle | |
2828 * instead of just one point causes both the origin and | |
2829 * the corner of the rectangle to be mapped. | |
2830 * </p> | |
2831 * | |
2832 * @param from the source <code>Control</code> or <code>null</code> | |
2833 * @param to the destination <code>Control</code> or <code>null</code> | |
2834 * @param x coordinates to be mapped | |
2835 * @param y coordinates to be mapped | |
2836 * @param width coordinates to be mapped | |
2837 * @param height coordinates to be mapped | |
2838 * @return rectangle with mapped coordinates | |
2839 * | |
2840 * @exception IllegalArgumentException <ul> | |
2841 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> | |
2842 * </ul> | |
2843 * @exception SWTException <ul> | |
2844 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2845 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2846 * </ul> | |
2847 * | |
2848 * @since 2.1.2 | |
2849 */ | |
2850 public Rectangle map (Control from, Control to, int x, int y, int width, int height) { | |
2851 checkDevice(); | |
2852 if (from !is null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); | |
2853 if (to !is null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); | |
2854 Rectangle rect = new Rectangle (x, y, width, height); | |
2855 if (from is to) return rect; | |
2856 bool fromRTL = false, toRTL = false; | |
2857 if (from !is null) { | |
2858 auto window = from.eventWindow (); | |
2859 int origin_x, origin_y; | |
2860 OS.gdk_window_get_origin (window, &origin_x, &origin_y); | |
2861 fromRTL = (from.style & SWT.MIRRORED) !is 0; | |
2862 if (fromRTL) rect.x = from.getClientWidth() - rect.x; | |
2863 rect.x += origin_x; | |
2864 rect.y += origin_y; | |
2865 } | |
2866 if (to !is null) { | |
2867 auto window = to.eventWindow (); | |
2868 int origin_x, origin_y; | |
2869 OS.gdk_window_get_origin (window, &origin_x, &origin_y); | |
2870 rect.x -= origin_x; | |
2871 rect.y -= origin_y; | |
2872 toRTL = (to.style & SWT.MIRRORED) !is 0; | |
2873 if (toRTL) rect.x = to.getClientWidth () - rect.x; | |
2874 } | |
2875 if (fromRTL !is toRTL) rect.x -= rect.width; | |
2876 return rect; | |
2877 } | |
2878 | |
2879 private static extern(C) int /*long*/ mouseHoverProcFunc ( void* user_data) { | |
2880 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
2881 CallbackData* cbdata = cast(CallbackData*)user_data; | |
2882 return cbdata.display.mouseHoverProc( cast(GtkWidget*)cbdata.data ); | |
2883 } | |
2884 int /*long*/ mouseHoverProc (GtkWidget* handle) { | |
2885 Widget widget = getWidget (handle); | |
2886 if (widget is null) return 0; | |
2887 return widget.hoverProc (handle); | |
2888 } | |
2889 | |
2890 /** | |
2891 * Generate a low level system event. | |
2892 * | |
2893 * <code>post</code> is used to generate low level keyboard | |
2894 * and mouse events. The intent is to enable automated UI | |
2895 * testing by simulating the input from the user. Most | |
2896 * SWT applications should never need to call this method. | |
2897 * <p> | |
2898 * Note that this operation can fail when the operating system | |
2899 * fails to generate the event for any reason. For example, | |
2900 * this can happen when there is no such key or mouse button | |
2901 * or when the system event queue is full. | |
2902 * </p> | |
2903 * <p> | |
2904 * <b>Event Types:</b> | |
2905 * <p>KeyDown, KeyUp | |
2906 * <p>The following fields in the <code>Event</code> apply: | |
2907 * <ul> | |
2908 * <li>(in) type KeyDown or KeyUp</li> | |
2909 * <p> Either one of: | |
2910 * <li>(in) character a character that corresponds to a keyboard key</li> | |
2911 * <li>(in) keyCode the key code of the key that was typed, | |
2912 * as defined by the key code constants in class <code>SWT</code></li> | |
2913 * </ul> | |
2914 * <p>MouseDown, MouseUp</p> | |
2915 * <p>The following fields in the <code>Event</code> apply: | |
2916 * <ul> | |
2917 * <li>(in) type MouseDown or MouseUp | |
2918 * <li>(in) button the button that is pressed or released | |
2919 * </ul> | |
2920 * <p>MouseMove</p> | |
2921 * <p>The following fields in the <code>Event</code> apply: | |
2922 * <ul> | |
2923 * <li>(in) type MouseMove | |
2924 * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates | |
2925 * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates | |
2926 * </ul> | |
2927 * </dl> | |
2928 * | |
2929 * @param event the event to be generated | |
2930 * | |
2931 * @return true if the event was generated or false otherwise | |
2932 * | |
2933 * @exception IllegalArgumentException <ul> | |
2934 * <li>ERROR_NULL_ARGUMENT - if the event is null</li> | |
2935 * </ul> | |
2936 * @exception SWTException <ul> | |
2937 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2938 * </ul> | |
2939 * | |
2940 * @since 3.0 | |
2941 * | |
2942 */ | |
2943 public bool post (Event event) { | |
2944 synchronized (Device.classinfo) { | |
2945 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
2946 if (event is null) error (SWT.ERROR_NULL_ARGUMENT); | |
2947 if (!OS.GDK_WINDOWING_X11()) return false; | |
2948 auto xDisplay = OS.GDK_DISPLAY (); | |
2949 int type = event.type; | |
2950 switch (type) { | |
2951 case SWT.KeyDown: | |
2952 case SWT.KeyUp: { | |
2953 int keyCode = 0; | |
2954 auto keysym = untranslateKey (event.keyCode); | |
2955 if (keysym !is 0) keyCode = OS.XKeysymToKeycode (xDisplay, keysym); | |
2956 if (keyCode is 0) { | |
2957 char key = event.character; | |
2958 switch (key) { | |
2959 case SWT.BS: keysym = OS.GDK_BackSpace; break; | |
2960 case SWT.CR: keysym = OS.GDK_Return; break; | |
2961 case SWT.DEL: keysym = OS.GDK_Delete; break; | |
2962 case SWT.ESC: keysym = OS.GDK_Escape; break; | |
2963 case SWT.TAB: keysym = OS.GDK_Tab; break; | |
2964 case SWT.LF: keysym = OS.GDK_Linefeed; break; | |
2965 default: | |
2966 keysym = key; | |
2967 } | |
2968 keyCode = OS.XKeysymToKeycode (xDisplay, keysym); | |
2969 if (keyCode is 0) return false; | |
2970 } | |
2971 OS.XTestFakeKeyEvent (xDisplay, keyCode, type is SWT.KeyDown, 0); | |
2972 return true; | |
2973 } | |
2974 case SWT.MouseDown: | |
2975 case SWT.MouseMove: | |
2976 case SWT.MouseUp: { | |
2977 if (type is SWT.MouseMove) { | |
2978 OS.XTestFakeMotionEvent (xDisplay, -1, event.x, event.y, 0); | |
2979 } else { | |
2980 int button = event.button; | |
2981 switch (button) { | |
2982 case 1: | |
2983 case 2: | |
2984 case 3: break; | |
2985 case 4: button = 6; break; | |
2986 case 5: button = 7; break; | |
2987 default: return false; | |
2988 } | |
2989 OS.XTestFakeButtonEvent (xDisplay, button, type is SWT.MouseDown, 0); | |
2990 } | |
2991 return true; | |
2992 default: | |
2993 } | |
2994 /* | |
2995 * This code is intentionally commented. After posting a | |
2996 * mouse wheel event the system may respond unpredictably | |
2997 * to subsequent mouse actions. | |
2998 */ | |
2999 // case SWT.MouseWheel: { | |
3000 // if (event.count is 0) return false; | |
3001 // int button = event.count < 0 ? 5 : 4; | |
3002 // OS.XTestFakeButtonEvent (xDisplay, button, type is SWT.MouseWheel, 0); | |
3003 // } | |
3004 } | |
3005 return false; | |
3006 } | |
3007 } | |
3008 | |
3009 void postEvent (Event event) { | |
3010 /* | |
3011 * Place the event at the end of the event queue. | |
3012 * This code is always called in the Display's | |
3013 * thread so it must be re-enterant but does not | |
3014 * need to be synchronized. | |
3015 */ | |
3016 if (eventQueue is null) eventQueue = new Event [4]; | |
3017 int index = 0; | |
3018 int length = eventQueue.length; | |
3019 while (index < length) { | |
3020 if (eventQueue [index] is null) break; | |
3021 index++; | |
3022 } | |
3023 if (index is length) { | |
3024 Event [] newQueue = new Event [length + 4]; | |
3025 System.arraycopy (eventQueue, 0, newQueue, 0, length); | |
3026 eventQueue = newQueue; | |
3027 } | |
3028 eventQueue [index] = event; | |
3029 } | |
3030 | |
3031 void putGdkEvents () { | |
3032 if (gdkEventCount !is 0) { | |
3033 for (int i = 0; i < gdkEventCount; i++) { | |
3034 auto event = gdkEvents [i]; | |
3035 Widget widget = gdkEventWidgets [i]; | |
3036 if (widget is null || !widget.isDisposed ()) { | |
3037 OS.gdk_event_put (event); | |
3038 } | |
3039 OS.gdk_event_free (event); | |
3040 gdkEvents [i] = null; | |
3041 gdkEventWidgets [i] = null; | |
3042 } | |
3043 gdkEventCount = 0; | |
3044 } | |
3045 } | |
3046 | |
3047 /** | |
3048 * Reads an event from the operating system's event queue, | |
3049 * dispatches it appropriately, and returns <code>true</code> | |
3050 * if there is potentially more work to do, or <code>false</code> | |
3051 * if the caller can sleep until another event is placed on | |
3052 * the event queue. | |
3053 * <p> | |
3054 * In addition to checking the system event queue, this method also | |
3055 * checks if any inter-thread messages (created by <code>syncExec()</code> | |
3056 * or <code>asyncExec()</code>) are waiting to be processed, and if | |
3057 * so handles them before returning. | |
3058 * </p> | |
3059 * | |
3060 * @return <code>false</code> if the caller can sleep upon return from this method | |
3061 * | |
3062 * @exception SWTException <ul> | |
3063 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3064 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3065 * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li> | |
3066 * </ul> | |
3067 * | |
3068 * @see #sleep | |
3069 * @see #wake | |
3070 */ | |
3071 public bool readAndDispatch () { | |
3072 checkDevice (); | |
3073 bool events = false; | |
3074 events |= runSettings (); | |
3075 events |= runPopups (); | |
3076 events |= cast(bool)OS.g_main_context_iteration (null, false); | |
3077 if (events) { | |
3078 runDeferredEvents (); | |
3079 return true; | |
3080 } | |
3081 return runAsyncMessages (false); | |
3082 } | |
3083 | |
3084 static void register (Display display) { | |
3085 synchronized (Device.classinfo) { | |
3086 for (int i=0; i<Displays.length; i++) { | |
3087 if (Displays [i] is null) { | |
3088 Displays [i] = display; | |
3089 return; | |
3090 } | |
3091 } | |
3092 Display [] newDisplays = new Display [Displays.length + 4]; | |
3093 System.arraycopy (Displays, 0, newDisplays, 0, Displays.length); | |
3094 newDisplays [Displays.length] = display; | |
3095 Displays = newDisplays; | |
3096 } | |
3097 } | |
3098 | |
3099 /** | |
3100 * Releases any internal resources back to the operating | |
3101 * system and clears all fields except the device handle. | |
3102 * <p> | |
3103 * Disposes all shells which are currently open on the display. | |
3104 * After this method has been invoked, all related related shells | |
3105 * will answer <code>true</code> when sent the message | |
3106 * <code>isDisposed()</code>. | |
3107 * </p><p> | |
3108 * When a device is destroyed, resources that were acquired | |
3109 * on behalf of the programmer need to be returned to the | |
3110 * operating system. For example, if the device allocated a | |
3111 * font to be used as the system font, this font would be | |
3112 * freed in <code>release</code>. Also,to assist the garbage | |
3113 * collector and minimize the amount of memory that is not | |
3114 * reclaimed when the programmer keeps a reference to a | |
3115 * disposed device, all fields except the handle are zero'd. | |
3116 * The handle is needed by <code>destroy</code>. | |
3117 * </p> | |
3118 * This method is called before <code>destroy</code>. | |
3119 * | |
3120 * @see Device#dispose | |
3121 * @see #destroy | |
3122 */ | |
3123 protected override void release () { | |
3124 sendEvent (SWT.Dispose, new Event ()); | |
3125 Shell [] shells = getShells (); | |
3126 for (int i=0; i<shells.length; i++) { | |
3127 Shell shell = shells [i]; | |
3128 if (!shell.isDisposed ()) shell.dispose (); | |
3129 } | |
3130 if (tray !is null) tray.dispose (); | |
3131 tray = null; | |
3132 while (readAndDispatch ()) {} | |
3133 if (disposeList !is null) { | |
3134 for (int i=0; i<disposeList.length; i++) { | |
3135 if (disposeList [i] !is null) disposeList [i].run (); | |
3136 } | |
3137 } | |
3138 disposeList = null; | |
3139 synchronizer.releaseSynchronizer (); | |
3140 synchronizer = null; | |
3141 releaseDisplay (); | |
3142 super.release (); | |
3143 } | |
3144 | |
3145 void releaseDisplay () { | |
3146 | |
3147 /* Dispose xfilter callback */ | |
3148 OS.gdk_window_remove_filter(null, &filterProcFunc, null); | |
3149 | |
3150 /* Dispose checkIfEvent callback */ | |
3151 | |
3152 /* Dispose preedit window */ | |
3153 if (preeditWindow !is null) OS.gtk_widget_destroy ( &preeditWindow.bin.container.widget); | |
3154 imControl = null; | |
3155 | |
3156 /* Dispose the menu callback */ | |
3157 | |
3158 /* Dispose the tooltip map callback */ | |
3159 | |
3160 /* Dispose the shell map callback */ | |
3161 | |
3162 /* Dispose the run async messages callback */ | |
3163 if (idleHandle !is 0) OS.g_source_remove (idleHandle); | |
3164 idleHandle = 0; | |
3165 | |
3166 /* Dispose GtkTreeView callbacks */ | |
3167 | |
3168 /* Dispose the set direction callback */ | |
3169 | |
3170 /* Dispose the emission proc callback */ | |
3171 | |
3172 /* Dispose the set direction callback */ | |
3173 | |
3174 /* Dispose the caret callback */ | |
3175 if (caretId !is 0) OS.gtk_timeout_remove (caretId); | |
3176 caretId = 0; | |
3177 | |
3178 /* Release closures */ | |
3179 for (int i = 0; i < Widget.LAST_SIGNAL; i++) { | |
3180 if (closures [i] !is null) OS.g_closure_unref (closures [i]); | |
3181 } | |
3182 if (shellMapProcClosure !is null) OS.g_closure_unref (shellMapProcClosure); | |
3183 | |
3184 /* Dispose the timer callback */ | |
3185 if (timerIds !is null) { | |
3186 for (int i=0; i<timerIds.length; i++) { | |
3187 if (timerIds [i] !is 0) OS.gtk_timeout_remove (timerIds [i]); | |
3188 } | |
3189 } | |
3190 timerIds = null; | |
3191 timerList = null; | |
3192 | |
3193 /* Dispose mouse hover callback */ | |
3194 if (mouseHoverId !is 0) OS.gtk_timeout_remove (mouseHoverId); | |
3195 mouseHoverId = 0; | |
3196 mouseHoverHandle = null; | |
3197 | |
3198 /* Dispose the default font */ | |
3199 if (systemFont !is null) systemFont.dispose (); | |
3200 systemFont = null; | |
3201 | |
3202 /* Dispose the System Images */ | |
3203 if (errorImage !is null) errorImage.dispose(); | |
3204 if (infoImage !is null) infoImage.dispose(); | |
3205 if (questionImage !is null) questionImage.dispose(); | |
3206 if (warningImage !is null) warningImage.dispose(); | |
3207 errorImage = infoImage = questionImage = warningImage = null; | |
3208 | |
3209 /* Release the System Cursors */ | |
3210 for (int i = 0; i < cursors.length; i++) { | |
3211 if (cursors [i] !is null) cursors [i].dispose (); | |
3212 } | |
3213 cursors = null; | |
3214 | |
3215 /* Release Acquired Resources */ | |
3216 if (resources !is null) { | |
3217 for (int i=0; i<resources.length; i++) { | |
3218 if (resources [i] !is null) resources [i].dispose (); | |
3219 } | |
3220 resources = null; | |
3221 } | |
3222 | |
3223 /* Release the System Colors */ | |
3224 COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW = | |
3225 COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER = | |
3226 COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT = | |
3227 COLOR_WIDGET_FOREGROUND = COLOR_TITLE_FOREGROUND = COLOR_TITLE_BACKGROUND = COLOR_TITLE_BACKGROUND_GRADIENT = | |
3228 COLOR_TITLE_INACTIVE_FOREGROUND = COLOR_TITLE_INACTIVE_BACKGROUND = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = | |
3229 COLOR_INFO_BACKGROUND = COLOR_INFO_FOREGROUND = null; | |
3230 | |
3231 /* Dispose the event callback */ | |
3232 OS.gdk_event_handler_set (null, null, null); | |
3233 | |
3234 /* Dispose the hidden shell */ | |
3235 if (shellHandle !is null) OS.gtk_widget_destroy (shellHandle); | |
3236 shellHandle = null; | |
3237 | |
3238 /* Dispose the settings callback */ | |
3239 | |
3240 /* Release the sleep resources */ | |
3241 max_priority = 0; | |
3242 timeout = 0; | |
3243 if (fds !is null) OS.g_free (fds.ptr); | |
3244 fds = null; | |
3245 | |
3246 /* Release references */ | |
3247 popups = null; | |
3248 thread = null; | |
3249 lastWidget = activeShell = null; | |
3250 //flushData = null; | |
3251 closures = null; | |
3252 indexTable = signalIds = treeSelection = null; | |
3253 widgetTable = modalShells = null; | |
3254 data = null; | |
3255 values = null; | |
3256 keys = null; | |
3257 windowManager = null; | |
3258 eventTable = filterTable = null; | |
3259 modalDialog = null; | |
3260 flushRect = null; | |
3261 exposeEvent = null; | |
3262 visibilityEvent = null; | |
3263 idleLock = null; | |
3264 } | |
3265 | |
3266 /** | |
3267 * Removes the listener from the collection of listeners who will | |
3268 * be notified when an event of the given type occurs anywhere in | |
3269 * a widget. The event type is one of the event constants defined | |
3270 * in class <code>SWT</code>. | |
3271 * | |
3272 * @param eventType the type of event to listen for | |
3273 * @param listener the listener which should no longer be notified when the event occurs | |
3274 * | |
3275 * @exception IllegalArgumentException <ul> | |
3276 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
3277 * </ul> | |
3278 * @exception SWTException <ul> | |
3279 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3280 * </ul> | |
3281 * | |
3282 * @see Listener | |
3283 * @see SWT | |
3284 * @see #addFilter | |
3285 * @see #addListener | |
3286 * | |
3287 * @since 3.0 | |
3288 */ | |
3289 public void removeFilter (int eventType, Listener listener) { | |
3290 checkDevice (); | |
3291 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3292 if (filterTable is null) return; | |
3293 filterTable.unhook (eventType, listener); | |
3294 if (filterTable.size () is 0) filterTable = null; | |
3295 } | |
3296 | |
3297 GdkEvent* removeGdkEvent () { | |
3298 if (gdkEventCount is 0) return null; | |
3299 auto event = gdkEvents [0]; | |
3300 --gdkEventCount; | |
3301 SimpleType!(GdkEvent*).arraycopy (gdkEvents, 1, gdkEvents, 0, gdkEventCount); | |
3302 System.arraycopy (gdkEventWidgets, 1, gdkEventWidgets, 0, gdkEventCount); | |
3303 gdkEvents [gdkEventCount] = null; | |
3304 gdkEventWidgets [gdkEventCount] = null; | |
3305 if (gdkEventCount is 0) { | |
3306 gdkEvents = null; | |
3307 gdkEventWidgets = null; | |
3308 } | |
3309 return event; | |
3310 } | |
3311 | |
3312 void removeIdleProc () { | |
3313 synchronized (idleLock) { | |
3314 if (idleHandle !is 0) OS.g_source_remove (idleHandle); | |
3315 idleNeeded = false; | |
3316 idleHandle = 0; | |
3317 } | |
3318 } | |
3319 /** | |
3320 * Removes the listener from the collection of listeners who will | |
3321 * be notified when an event of the given type occurs. The event type | |
3322 * is one of the event constants defined in class <code>SWT</code>. | |
3323 * | |
3324 * @param eventType the type of event to listen for | |
3325 * @param listener the listener which should no longer be notified | |
3326 * | |
3327 * @exception IllegalArgumentException <ul> | |
3328 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
3329 * </ul> | |
3330 * @exception SWTException <ul> | |
3331 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3332 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3333 * </ul> | |
3334 * | |
3335 * @see Listener | |
3336 * @see SWT | |
3337 * @see #addListener | |
3338 * | |
3339 * @since 2.0 | |
3340 */ | |
3341 public void removeListener (int eventType, Listener listener) { | |
3342 checkDevice (); | |
3343 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3344 if (eventTable is null) return; | |
3345 eventTable.unhook (eventType, listener); | |
3346 } | |
3347 | |
3348 void removeMouseHoverTimeout (void* handle) { | |
3349 if (handle !is mouseHoverHandle) return; | |
3350 if (mouseHoverId !is 0) OS.gtk_timeout_remove (mouseHoverId); | |
3351 mouseHoverId = 0; | |
3352 mouseHoverHandle = null; | |
3353 } | |
3354 | |
3355 void removePopup (Menu menu) { | |
3356 if (popups is null) return; | |
3357 for (int i=0; i<popups.length; i++) { | |
3358 if (popups [i] is menu) { | |
3359 popups [i] = null; | |
3360 return; | |
3361 } | |
3362 } | |
3363 } | |
3364 | |
3365 Widget removeWidget (GtkWidget* handle) { | |
3366 if (handle is null) return null; | |
3367 lastWidget = null; | |
3368 Widget widget = null; | |
3369 int index = cast(int)/*64*/ OS.g_object_get_qdata (cast(GObject*)handle, SWT_OBJECT_INDEX) - 1; | |
3370 if (0 <= index && index < widgetTable.length) { | |
3371 widget = widgetTable [index]; | |
3372 widgetTable [index] = null; | |
3373 indexTable [index] = freeSlot; | |
3374 freeSlot = index; | |
3375 OS.g_object_set_qdata (cast(GObject*)handle, SWT_OBJECT_INDEX, null); | |
3376 } | |
3377 return widget; | |
3378 } | |
3379 | |
3380 bool runAsyncMessages (bool all) { | |
3381 return synchronizer.runAsyncMessages (all); | |
3382 } | |
3383 | |
3384 bool runDeferredEvents () { | |
3385 /* | |
3386 * Run deferred events. This code is always | |
3387 * called in the Display's thread so it must | |
3388 * be re-enterant but need not be synchronized. | |
3389 */ | |
3390 while (eventQueue !is null) { | |
3391 | |
3392 /* Take an event off the queue */ | |
3393 Event event = eventQueue [0]; | |
3394 if (event is null) break; | |
3395 int len = eventQueue.length; | |
3396 System.arraycopy (eventQueue, 1, eventQueue, 0, --len); | |
3397 eventQueue [len] = null; | |
3398 | |
3399 /* Run the event */ | |
3400 Widget widget = event.widget; | |
3401 if (widget !is null && !widget.isDisposed ()) { | |
3402 Widget item = event.item; | |
3403 if (item is null || !item.isDisposed ()) { | |
3404 widget.sendEvent (event); | |
3405 } | |
3406 } | |
3407 | |
3408 /* | |
3409 * At this point, the event queue could | |
3410 * be null due to a recursive invokation | |
3411 * when running the event. | |
3412 */ | |
3413 } | |
3414 | |
3415 /* Clear the queue */ | |
3416 eventQueue = null; | |
3417 return true; | |
3418 } | |
3419 | |
3420 bool runPopups () { | |
3421 if (popups is null) return false; | |
3422 bool result = false; | |
3423 while (popups !is null) { | |
3424 Menu menu = popups [0]; | |
3425 if (menu is null) break; | |
3426 int len = popups.length; | |
3427 System.arraycopy (popups, 1, popups, 0, --len); | |
3428 popups [len] = null; | |
3429 runDeferredEvents (); | |
3430 if (!menu.isDisposed ()) menu._setVisible (true); | |
3431 result = true; | |
3432 } | |
3433 popups = null; | |
3434 return result; | |
3435 } | |
3436 | |
3437 bool runSettings () { | |
3438 if (!runSettingsFld) return false; | |
3439 runSettingsFld = false; | |
3440 saveResources (); | |
3441 initializeSystemColors (); | |
3442 sendEvent (SWT.Settings, null); | |
3443 Shell [] shells = getShells (); | |
3444 for (int i=0; i<shells.length; i++) { | |
3445 Shell shell = shells [i]; | |
3446 if (!shell.isDisposed ()) { | |
3447 shell.fixStyle (); | |
3448 shell.redraw (true); | |
3449 shell.layout (true, true); | |
3450 } | |
3451 } | |
3452 return true; | |
3453 } | |
3454 | |
3455 /** | |
3456 * On platforms which support it, sets the application name | |
3457 * to be the argument. On Motif, for example, this can be used | |
3458 * to set the name used for resource lookup. Specifying | |
3459 * <code>null</code> for the name clears it. | |
3460 * | |
3461 * @param name the new app name or <code>null</code> | |
3462 */ | |
3463 public static void setAppName (String name) { | |
3464 APP_NAME = name; | |
3465 } | |
3466 | |
3467 /** | |
3468 * Sets the location of the on-screen pointer relative to the top left corner | |
3469 * of the screen. <b>Note: It is typically considered bad practice for a | |
3470 * program to move the on-screen pointer location.</b> | |
3471 * | |
3472 * @param x the new x coordinate for the cursor | |
3473 * @param y the new y coordinate for the cursor | |
3474 * | |
3475 * @exception SWTException <ul> | |
3476 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3477 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3478 * </ul> | |
3479 * | |
3480 * @since 2.1 | |
3481 */ | |
3482 public void setCursorLocation (int x, int y) { | |
3483 checkDevice (); | |
3484 if (OS.GDK_WINDOWING_X11 ()) { | |
3485 auto xDisplay = OS.GDK_DISPLAY (); | |
3486 auto xWindow = OS.XDefaultRootWindow (xDisplay); | |
3487 OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, x, y); | |
3488 } | |
3489 } | |
3490 | |
3491 /** | |
3492 * Sets the location of the on-screen pointer relative to the top left corner | |
3493 * of the screen. <b>Note: It is typically considered bad practice for a | |
3494 * program to move the on-screen pointer location.</b> | |
3495 * | |
3496 * @param point new position | |
3497 * | |
3498 * @exception SWTException <ul> | |
3499 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3500 * <li>ERROR_NULL_ARGUMENT - if the point is null | |
3501 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3502 * </ul> | |
3503 * | |
3504 * @since 2.0 | |
3505 */ | |
3506 public void setCursorLocation (Point point) { | |
3507 checkDevice (); | |
3508 if (point is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3509 setCursorLocation (point.x, point.y); | |
3510 } | |
3511 | |
3512 /** | |
3513 * Sets the application defined property of the receiver | |
3514 * with the specified name to the given argument. | |
3515 * <p> | |
3516 * Applications may have associated arbitrary objects with the | |
3517 * receiver in this fashion. If the objects stored in the | |
3518 * properties need to be notified when the display is disposed | |
3519 * of, it is the application's responsibility provide a | |
3520 * <code>disposeExec()</code> handler which does so. | |
3521 * </p> | |
3522 * | |
3523 * @param key the name of the property | |
3524 * @param value the new value for the property | |
3525 * | |
3526 * @exception SWTException <ul> | |
3527 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3528 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3529 * </ul> | |
3530 * | |
3531 * @see #getData(String) | |
3532 * @see #disposeExec(Runnable) | |
3533 */ | |
3534 public void setData (String key, Object value) { | |
3535 checkDevice (); | |
3536 // SWT extension: allow null for zero length string | |
3537 //if (key is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3538 | |
3539 if (key.equals (DISPATCH_EVENT_KEY)) { | |
3540 ArrayWrapperInt wrappedValue; | |
3541 if (value is null || (null !is (wrappedValue=cast(ArrayWrapperInt)value))) { | |
3542 dispatchEvents = wrappedValue.array; | |
3543 if (value is null) putGdkEvents (); | |
3544 return; | |
3545 } | |
3546 } | |
3547 if (key.equals (SET_MODAL_DIALOG)) { | |
3548 setModalDialog (cast(Dialog) data); | |
3549 return; | |
3550 } | |
3551 | |
3552 if (key.equals (ADD_WIDGET_KEY)) { | |
3553 auto wrap = cast(ArrayWrapperObject) value; | |
3554 if( wrap is null ) SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " []"); | |
3555 Object [] data = wrap.array; | |
3556 auto handle = (cast(LONG) data [0]).value; | |
3557 Widget widget = cast(Widget) data [1]; | |
3558 if (widget !is null) { | |
3559 addWidget (cast(GtkWidget*)handle, widget); | |
3560 } else { | |
3561 removeWidget (cast(GtkWidget*)handle); | |
3562 } | |
3563 } | |
3564 | |
3565 if (key==/*eq*/ ADD_IDLE_PROC_KEY) { | |
3566 addIdleProc (); | |
3567 return; | |
3568 } | |
3569 if (key==/*eq*/ REMOVE_IDLE_PROC_KEY) { | |
3570 removeIdleProc (); | |
3571 return; | |
3572 } | |
3573 | |
3574 /* Remove the key/value pair */ | |
3575 if (value is null) { | |
3576 if (keys is null) return; | |
3577 int index = 0; | |
3578 while (index < keys.length && keys [index]!=/*!eq*/ key) index++; | |
3579 if (index is keys.length) return; | |
3580 if (keys.length is 1) { | |
3581 keys = null; | |
3582 values = null; | |
3583 } else { | |
3584 String [] newKeys = new String [keys.length - 1]; | |
3585 Object [] newValues = new Object [values.length - 1]; | |
3586 System.arraycopy (keys, 0, newKeys, 0, index); | |
3587 System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index); | |
3588 System.arraycopy (values, 0, newValues, 0, index); | |
3589 System.arraycopy (values, index + 1, newValues, index, newValues.length - index); | |
3590 keys = newKeys; | |
3591 values = newValues; | |
3592 } | |
3593 return; | |
3594 } | |
3595 | |
3596 /* Add the key/value pair */ | |
3597 if (keys is null) { | |
3598 keys = [key]; | |
3599 values = [value]; | |
3600 return; | |
3601 } | |
3602 for (int i=0; i<keys.length; i++) { | |
3603 if (keys [i]==/*eq*/ key) { | |
3604 values [i] = value; | |
3605 return; | |
3606 } | |
3607 } | |
3608 String [] newKeys = new String [keys.length + 1]; | |
3609 Object [] newValues = new Object [values.length + 1]; | |
3610 System.arraycopy (keys, 0, newKeys, 0, keys.length); | |
3611 System.arraycopy (values, 0, newValues, 0, values.length); | |
3612 newKeys [keys.length] = key; | |
3613 newValues [values.length] = value; | |
3614 keys = newKeys; | |
3615 values = newValues; | |
3616 } | |
3617 | |
3618 /** | |
3619 * Sets the application defined, display specific data | |
3620 * associated with the receiver, to the argument. | |
3621 * The <em>display specific data</em> is a single, | |
3622 * unnamed field that is stored with every display. | |
3623 * <p> | |
3624 * Applications may put arbitrary objects in this field. If | |
3625 * the object stored in the display specific data needs to | |
3626 * be notified when the display is disposed of, it is the | |
3627 * application's responsibility provide a | |
3628 * <code>disposeExec()</code> handler which does so. | |
3629 * </p> | |
3630 * | |
3631 * @param data the new display specific data | |
3632 * | |
3633 * @exception SWTException <ul> | |
3634 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3635 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3636 * </ul> | |
3637 * | |
3638 * @see #getData() | |
3639 * @see #disposeExec(Runnable) | |
3640 */ | |
3641 public void setData (Object data) { | |
3642 checkDevice (); | |
3643 this.data = data; | |
3644 } | |
3645 | |
3646 | |
3647 void doSetDirectionProc( GtkWidget* widget, int direction ){ | |
3648 setDirectionProcCallbackData.display = this; | |
3649 setDirectionProcCallbackData.data = cast(void*)direction; | |
3650 OS.gtk_container_forall (cast(GtkContainer*)widget, cast(GtkCallback)&setDirectionProcFunc, &setDirectionProcCallbackData); | |
3651 } | |
3652 | |
3653 package static extern(C) int /*long*/ setDirectionProcFunc (GtkWidget* widget, void* data) { | |
3654 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3655 CallbackData* cbdata = cast(CallbackData*)data; | |
3656 return cbdata.display.setDirectionProc( widget, cast(int)cbdata.data ); | |
3657 } | |
3658 int /*long*/ setDirectionProc (GtkWidget* widget, int /*long*/ direction) { | |
3659 OS.gtk_widget_set_direction (widget, direction); | |
3660 if (OS.GTK_IS_MENU_ITEM (widget)) { | |
3661 auto submenu = OS.gtk_menu_item_get_submenu (widget); | |
3662 if (submenu !is null) { | |
3663 OS.gtk_widget_set_direction (submenu, cast(int)/*64*/ direction); | |
3664 OS.gtk_container_forall (cast(GtkContainer*)submenu, cast(GtkCallback)&setDirectionProcFunc, cast(void*)direction); | |
3665 } | |
3666 } | |
3667 if (OS.GTK_IS_CONTAINER (cast(GTypeInstance*)widget)) { | |
3668 OS.gtk_container_forall (cast(GtkContainer*)widget, cast(GtkCallback)&setDirectionProcFunc, cast(void*)direction); | |
3669 } | |
3670 return 0; | |
3671 } | |
3672 | |
3673 void setModalDialog (Dialog modalDailog) { | |
3674 this.modalDialog = modalDailog; | |
3675 Shell [] shells = getShells (); | |
3676 for (int i=0; i<shells.length; i++) shells [i].updateModal (); | |
3677 } | |
3678 | |
3679 void setModalShell (Shell shell) { | |
3680 if (modalShells is null) modalShells = new Shell [4]; | |
3681 int index = 0, length = modalShells.length; | |
3682 while (index < length) { | |
3683 if (modalShells [index] is shell) return; | |
3684 if (modalShells [index] is null) break; | |
3685 index++; | |
3686 } | |
3687 if (index is length) { | |
3688 Shell [] newModalShells = new Shell [length + 4]; | |
3689 System.arraycopy (modalShells, 0, newModalShells, 0, length); | |
3690 modalShells = newModalShells; | |
3691 } | |
3692 modalShells [index] = shell; | |
3693 Shell [] shells = getShells (); | |
3694 for (int i=0; i<shells.length; i++) shells [i].updateModal (); | |
3695 } | |
3696 | |
3697 /** | |
3698 * Sets the synchronizer used by the display to be | |
3699 * the argument, which can not be null. | |
3700 * | |
3701 * @param synchronizer the new synchronizer for the display (must not be null) | |
3702 * | |
3703 * @exception IllegalArgumentException <ul> | |
3704 * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li> | |
3705 * </ul> | |
3706 * @exception SWTException <ul> | |
3707 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3708 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3709 * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li> | |
3710 * </ul> | |
3711 */ | |
3712 public void setSynchronizer (Synchronizer synchronizer) { | |
3713 checkDevice (); | |
3714 if (synchronizer is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3715 if (synchronizer is this.synchronizer) return; | |
3716 Synchronizer oldSynchronizer; | |
3717 synchronized (Device.classinfo) { | |
3718 oldSynchronizer = this.synchronizer; | |
3719 this.synchronizer = synchronizer; | |
3720 } | |
3721 if (oldSynchronizer !is null) { | |
3722 oldSynchronizer.runAsyncMessages(true); | |
3723 } | |
3724 } | |
3725 | |
3726 void showIMWindow (Control control) { | |
3727 imControl = control; | |
3728 if (preeditWindow is null) { | |
3729 preeditWindow = cast(GtkWindow*)OS.gtk_window_new (OS.GTK_WINDOW_POPUP); | |
3730 if (preeditWindow is null) error (SWT.ERROR_NO_HANDLES); | |
3731 preeditLabel = cast(GtkLabel*) OS.gtk_label_new (null); | |
3732 if (preeditLabel is null) error (SWT.ERROR_NO_HANDLES); | |
3733 OS.gtk_container_add (cast(GtkContainer*)preeditWindow, cast(GtkWidget*) preeditLabel); | |
3734 OS.gtk_widget_show (cast(GtkWidget*)preeditLabel); | |
3735 } | |
3736 char* preeditString; | |
3737 PangoAttrList* pangoAttrs; | |
3738 auto imHandle = control.imHandle (); | |
3739 OS.gtk_im_context_get_preedit_string (imHandle, &preeditString, &pangoAttrs, null); | |
3740 if (preeditString !is null && strlen (preeditString) > 0) { | |
3741 Control widget = control.findBackgroundControl (); | |
3742 if (widget is null) widget = control; | |
3743 OS.gtk_widget_modify_bg (cast(GtkWidget*)preeditWindow, OS.GTK_STATE_NORMAL, widget.getBackgroundColor ()); | |
3744 widget.setForegroundColor (cast(GtkWidget*)preeditLabel, control.getForegroundColor()); | |
3745 OS.gtk_widget_modify_font (cast(GtkWidget*)preeditLabel, control.getFontDescription ()); | |
3746 if (pangoAttrs !is null) OS.gtk_label_set_attributes (preeditLabel, pangoAttrs); | |
3747 OS.gtk_label_set_text (preeditLabel, preeditString); | |
3748 Point point = control.toDisplay (control.getIMCaretPos ()); | |
3749 OS.gtk_window_move (preeditWindow, point.x, point.y); | |
3750 GtkRequisition requisition; | |
3751 OS.gtk_widget_size_request (cast(GtkWidget*)preeditLabel, &requisition); | |
3752 OS.gtk_window_resize (preeditWindow, requisition.width, requisition.height); | |
3753 OS.gtk_widget_show (cast(GtkWidget*)preeditWindow); | |
3754 } else { | |
3755 OS.gtk_widget_hide (cast(GtkWidget*)preeditWindow); | |
3756 } | |
3757 if (preeditString !is null) OS.g_free (preeditString); | |
3758 if (pangoAttrs !is null) OS.pango_attr_list_unref (pangoAttrs); | |
3759 } | |
3760 | |
3761 /** | |
3762 * Causes the user-interface thread to <em>sleep</em> (that is, | |
3763 * to be put in a state where it does not consume CPU cycles) | |
3764 * until an event is received or it is otherwise awakened. | |
3765 * | |
3766 * @return <code>true</code> if an event requiring dispatching was placed on the queue. | |
3767 * | |
3768 * @exception SWTException <ul> | |
3769 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3770 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3771 * </ul> | |
3772 * | |
3773 * @see #wake | |
3774 */ | |
3775 public bool sleep () { | |
3776 checkDevice (); | |
3777 if (gdkEventCount is 0) { | |
3778 gdkEvents = null; | |
3779 gdkEventWidgets = null; | |
3780 } | |
3781 if (settingsChanged) { | |
3782 settingsChanged = false; | |
3783 runSettingsFld = true; | |
3784 return false; | |
3785 } | |
3786 if (getMessageCount () !is 0) return true; | |
3787 if (fds is null) { | |
3788 allocated_nfds = 2; | |
3789 GPollFD* ptr = cast(GPollFD*) OS.g_malloc( GPollFD.sizeof * allocated_nfds ); | |
3790 fds = ptr[ 0 .. allocated_nfds ]; | |
3791 } | |
3792 max_priority = timeout = 0; | |
3793 auto context = OS.g_main_context_default (); | |
3794 bool result = false; | |
3795 do { | |
3796 if (OS.g_main_context_acquire (context)) { | |
3797 result = cast(bool)OS.g_main_context_prepare (context, &max_priority); | |
3798 int nfds; | |
3799 while ((nfds = OS.g_main_context_query (context, max_priority, &timeout, fds.ptr, allocated_nfds)) > allocated_nfds) { | |
3800 OS.g_free (fds.ptr); | |
3801 allocated_nfds = nfds; | |
3802 GPollFD* ptr = cast(GPollFD*) OS.g_malloc( GPollFD.sizeof * allocated_nfds ); | |
3803 fds = ptr[ 0 .. allocated_nfds ]; | |
3804 } | |
3805 GPollFunc poll = OS.g_main_context_get_poll_func (context); | |
3806 if (poll !is null) { | |
3807 if (nfds > 0 || timeout !is 0) { | |
3808 /* | |
3809 * Bug in GTK. For some reason, g_main_context_wakeup() may | |
3810 * fail to wake up the UI thread from the polling function. | |
3811 * The fix is to sleep for a maximum of 50 milliseconds. | |
3812 */ | |
3813 if (timeout < 0) timeout = 50; | |
3814 | |
3815 /* Exit the OS lock to allow other threads to enter GTK */ | |
3816 Lock lock = OS.lock; | |
3817 int count = lock.lock (); | |
3818 for (int i = 0; i < count; i++) lock.unlock (); | |
3819 try { | |
3820 wake_state = false; | |
3821 poll( fds.ptr, nfds, timeout); | |
3822 } finally { | |
3823 for (int i = 0; i < count; i++) lock.lock (); | |
3824 lock.unlock (); | |
3825 } | |
3826 } | |
3827 } | |
3828 OS.g_main_context_check (context, max_priority, fds.ptr, nfds); | |
3829 OS.g_main_context_release (context); | |
3830 } | |
3831 } while (!result && getMessageCount () is 0 && !wake_state); | |
3832 wake_state = false; | |
3833 return true; | |
3834 } | |
3835 | |
3836 /** | |
3837 * Causes the <code>run()</code> method of the runnable to | |
3838 * be invoked by the user-interface thread after the specified | |
3839 * number of milliseconds have elapsed. If milliseconds is less | |
3840 * than zero, the runnable is not executed. | |
3841 * <p> | |
3842 * Note that at the time the runnable is invoked, widgets | |
3843 * that have the receiver as their display may have been | |
3844 * disposed. Therefore, it is necessary to check for this | |
3845 * case inside the runnable before accessing the widget. | |
3846 * </p> | |
3847 * | |
3848 * @param milliseconds the delay before running the runnable | |
3849 * @param runnable code to run on the user-interface thread | |
3850 * | |
3851 * @exception IllegalArgumentException <ul> | |
3852 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li> | |
3853 * </ul> | |
3854 * @exception SWTException <ul> | |
3855 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3856 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3857 * </ul> | |
3858 * | |
3859 * @see #asyncExec | |
3860 */ | |
3861 public void timerExec (int milliseconds, Runnable runnable) { | |
3862 checkDevice (); | |
3863 if (runnable is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3864 if (timerList is null) timerList = new Runnable [4]; | |
3865 if (timerIds is null) timerIds = new int [4]; | |
3866 int index = 0; | |
3867 while (index < timerList.length) { | |
3868 if (timerList [index] is runnable) break; | |
3869 index++; | |
3870 } | |
3871 if (index !is timerList.length) { | |
3872 OS.gtk_timeout_remove (timerIds [index]); | |
3873 timerList [index] = null; | |
3874 timerIds [index] = 0; | |
3875 if (milliseconds < 0) return; | |
3876 } else { | |
3877 if (milliseconds < 0) return; | |
3878 index = 0; | |
3879 while (index < timerList.length) { | |
3880 if (timerList [index] is null) break; | |
3881 index++; | |
3882 } | |
3883 if (index is timerList.length) { | |
3884 Runnable [] newTimerList = new Runnable [timerList.length + 4]; | |
3885 SimpleType!(Runnable).arraycopy (timerList, 0, newTimerList, 0, timerList.length); | |
3886 timerList = newTimerList; | |
3887 int [] newTimerIds = new int [timerIds.length + 4]; | |
3888 System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length); | |
3889 timerIds = newTimerIds; | |
3890 } | |
3891 } | |
3892 timerProcCallbackData.display = this; | |
3893 timerProcCallbackData.data = cast(void*)index; | |
3894 int timerId = OS.gtk_timeout_add (milliseconds, &timerProcFunc, &timerProcCallbackData); | |
3895 if (timerId !is 0) { | |
3896 timerIds [index] = timerId; | |
3897 timerList [index] = runnable; | |
3898 } | |
3899 } | |
3900 | |
3901 | |
3902 private static extern(C) int timerProcFunc ( void * data ) { | |
3903 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3904 CallbackData* cbdata = cast( CallbackData* ) data; | |
3905 return cbdata.display.timerProc( cast(int) cbdata.data ); | |
3906 } | |
3907 | |
3908 int /*long*/ timerProc (int /*long*/ i) { | |
3909 if (timerList is null) return 0; | |
3910 int index = cast(int)/*64*/i; | |
3911 if (0 <= index && index < timerList.length) { | |
3912 Runnable runnable = timerList [index]; | |
3913 timerList [index] = null; | |
3914 timerIds [index] = 0; | |
3915 if (runnable !is null) runnable.run (); | |
3916 } | |
3917 return 0; | |
3918 } | |
3919 | |
3920 private static extern(C) int caretProcFunc ( void * data ) { | |
3921 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3922 CallbackData* cbdata = cast( CallbackData* ) data; | |
3923 return cbdata.display.caretProc( cast(int) cbdata.data ); | |
3924 } | |
3925 int /*long*/ caretProc (int /*long*/ clientData) { | |
3926 caretId = 0; | |
3927 if (currentCaret is null) { | |
3928 return 0; | |
3929 } | |
3930 if (currentCaret.blinkCaret()) { | |
3931 int blinkRate = currentCaret.blinkRate; | |
3932 if (blinkRate is 0) return 0; | |
3933 caretProcCallbackData.display = this; | |
3934 caretProcCallbackData.data = cast(void*)0; | |
3935 caretId = OS.gtk_timeout_add (blinkRate, &caretProcFunc, &caretProcCallbackData); | |
3936 } else { | |
3937 currentCaret = null; | |
3938 } | |
3939 return 0; | |
3940 } | |
3941 | |
3942 | |
3943 package int doSizeAllocateConnect( CallbackData* cbdata, GtkWidget* window, GtkWidget* widget ){ | |
3944 cbdata.display = this; | |
3945 cbdata.data = cast(void*)widget; | |
3946 return OS.g_signal_connect (cast(void*)window, OS.size_allocate.ptr, cast(GCallback)&sizeAllocateProcFunc, cast(void*)&cbdata); | |
3947 } | |
3948 | |
3949 private static extern(C) void sizeAllocateProcFunc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
3950 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3951 auto cbdata = cast(CallbackData*)user_data; | |
3952 cbdata.display.sizeAllocateProc( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); | |
3953 } | |
3954 | |
3955 void sizeAllocateProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
3956 Widget widget = getWidget ( cast(GtkWidget*)user_data); | |
3957 if (widget is null) return 0; | |
3958 widget.sizeAllocateProc (handle, arg0, user_data); | |
3959 } | |
3960 | |
3961 | |
3962 package int doSizeRequestConnect( CallbackData* cbdata, GtkWidget* window, GtkWidget* widget ){ | |
3963 cbdata.display = this; | |
3964 cbdata.data = cast(void*)widget; | |
3965 return OS.g_signal_connect (cast(void*)window, OS.size_request.ptr, cast(GCallback)&sizeRequestProcFunc, cast(void*)&cbdata ); | |
3966 } | |
3967 | |
3968 private static extern(C) void sizeRequestProcFunc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
3969 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3970 auto cbdata = cast(CallbackData*)user_data; | |
3971 cbdata.display.sizeRequestProcMeth( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); | |
3972 } | |
3973 | |
3974 int /*long*/ sizeRequestProcMeth (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
3975 Widget widget = getWidget (cast(GtkWidget*)user_data); | |
3976 if (widget is null) return 0; | |
3977 return widget.sizeRequestProc (handle, arg0, user_data); | |
3978 } | |
3979 | |
3980 package void doTreeSelectionProcConnect( CallbackData* cbdata, GtkWidget* widget, GtkTreeSelection* selection ){ | |
3981 cbdata.display = this; | |
3982 cbdata.data = cast(void*)widget; | |
3983 OS.gtk_tree_selection_selected_foreach (selection, &treeSelectionProcFunc, widget); | |
3984 } | |
3985 | |
3986 private static extern(C) void treeSelectionProcFunc (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, void* data) { | |
3987 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3988 auto cbdata = cast(CallbackData*)data; | |
3989 cbdata.display.treeSelectionProcMeth( model, path, iter, cbdata.data ); | |
3990 } | |
3991 | |
3992 void treeSelectionProcMeth (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, void* data) { | |
3993 Widget widget = getWidget (cast(GtkWidget*)data); | |
3994 if (widget is null) return 0; | |
3995 widget.treeSelectionProc (model, path, iter, treeSelection, treeSelectionLength++); | |
3996 } | |
3997 | |
3998 void saveResources () { | |
3999 int resourceCount = 0; | |
4000 if (resources is null) { | |
4001 resources = new Resource [RESOURCE_SIZE]; | |
4002 } else { | |
4003 resourceCount = resources.length; | |
4004 Resource [] newResources = new Resource [resourceCount + RESOURCE_SIZE]; | |
4005 System.arraycopy (resources, 0, newResources, 0, resourceCount); | |
4006 resources = newResources; | |
4007 } | |
4008 if (systemFont !is null) { | |
4009 resources [resourceCount++] = systemFont; | |
4010 systemFont = null; | |
4011 } | |
4012 if (errorImage !is null) resources [resourceCount++] = errorImage; | |
4013 if (infoImage !is null) resources [resourceCount++] = infoImage; | |
4014 if (questionImage !is null) resources [resourceCount++] = questionImage; | |
4015 if (warningImage !is null) resources [resourceCount++] = warningImage; | |
4016 errorImage = infoImage = questionImage = warningImage = null; | |
4017 for (int i=0; i<cursors.length; i++) { | |
4018 if (cursors [i] !is null) resources [resourceCount++] = cursors [i]; | |
4019 cursors [i] = null; | |
4020 } | |
4021 if (resourceCount < RESOURCE_SIZE) { | |
4022 Resource [] newResources = new Resource [resourceCount]; | |
4023 System.arraycopy (resources, 0, newResources, 0, resourceCount); | |
4024 resources = newResources; | |
4025 } | |
4026 } | |
4027 | |
4028 void sendEvent (int eventType, Event event) { | |
4029 if (eventTable is null && filterTable is null) { | |
4030 return; | |
4031 } | |
4032 if (event is null) event = new Event (); | |
4033 event.display = this; | |
4034 event.type = eventType; | |
4035 if (event.time is 0) event.time = getLastEventTime (); | |
4036 if (!filterEvent (event)) { | |
4037 if (eventTable !is null) eventTable.sendEvent (event); | |
4038 } | |
4039 } | |
4040 | |
4041 void setCurrentCaret (Caret caret) { | |
4042 if (caretId !is 0) OS.gtk_timeout_remove(caretId); | |
4043 caretId = 0; | |
4044 currentCaret = caret; | |
4045 if (caret is null) return; | |
4046 int blinkRate = currentCaret.blinkRate; | |
4047 caretProcCallbackData.display = this; | |
4048 caretProcCallbackData.data = cast(void*)0; | |
4049 caretId = OS.gtk_timeout_add (blinkRate, &caretProcFunc, &caretProcCallbackData); | |
4050 } | |
4051 | |
4052 private static extern(C) int /*long*/ shellMapProcFunc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { | |
4053 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4054 auto cbdata = cast(CallbackData*)user_data; | |
4055 return cbdata.display.shellMapProc( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); | |
4056 } | |
4057 | |
4058 int /*long*/ shellMapProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
4059 Widget widget = getWidget (cast(GtkWidget*)handle); | |
4060 if (widget is null) return 0; | |
4061 return widget.shellMapProc (handle, arg0, user_data); | |
4062 } | |
4063 | |
4064 private static extern(C) int /*long*/ styleSetProcFunc (int /*long*/ gobject, int /*long*/ arg1, int /*long*/ user_data) { | |
4065 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4066 auto cbdata = cast(CallbackData*)user_data; | |
4067 return cbdata.display.styleSetProcMeth( gobject, arg1, cast(int)cbdata.data ); | |
4068 } | |
4069 int /*long*/ styleSetProcMeth (int /*long*/ gobject, int /*long*/ arg1, int /*long*/ user_data) { | |
4070 settingsChanged = true; | |
4071 return 0; | |
4072 } | |
4073 | |
4074 /** | |
4075 * Causes the <code>run()</code> method of the runnable to | |
4076 * be invoked by the user-interface thread at the next | |
4077 * reasonable opportunity. The thread which calls this method | |
4078 * is suspended until the runnable completes. Specifying <code>null</code> | |
4079 * as the runnable simply wakes the user-interface thread. | |
4080 * <p> | |
4081 * Note that at the time the runnable is invoked, widgets | |
4082 * that have the receiver as their display may have been | |
4083 * disposed. Therefore, it is necessary to check for this | |
4084 * case inside the runnable before accessing the widget. | |
4085 * </p> | |
4086 * | |
4087 * @param runnable code to run on the user-interface thread or <code>null</code> | |
4088 * | |
4089 * @exception SWTException <ul> | |
4090 * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li> | |
4091 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
4092 * </ul> | |
4093 * | |
4094 * @see #asyncExec | |
4095 */ | |
4096 public void syncExec (Runnable runnable) { | |
4097 Synchronizer synchronizer; | |
4098 synchronized (Device.classinfo) { | |
4099 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
4100 synchronizer = this.synchronizer; | |
4101 synchronized (idleLock) { | |
4102 if (idleNeeded && idleHandle is 0) { | |
4103 //NOTE: calling unlocked function in OS | |
4104 idleProcCallbackData.display = this; | |
4105 idleProcCallbackData.data = cast(void*)0; | |
4106 //PORTING_TODO: was _g_idle_add, calling directly | |
4107 idleHandle = OS.g_idle_add (&idleProcFunc, &idleProcCallbackData); | |
4108 } | |
4109 } | |
4110 } | |
4111 synchronizer.syncExec (runnable); | |
4112 } | |
4113 | |
4114 static int translateKey (int key) { | |
4115 for (int i=0; i<KeyTable.length; i++) { | |
4116 if (KeyTable [i] [0] is key) return KeyTable [i] [1]; | |
4117 } | |
4118 return 0; | |
4119 } | |
4120 | |
4121 static int untranslateKey (int key) { | |
4122 for (int i=0; i<KeyTable.length; i++) { | |
4123 if (KeyTable [i] [1] is key) return KeyTable [i] [0]; | |
4124 } | |
4125 return 0; | |
4126 } | |
4127 | |
4128 /** | |
4129 * Forces all outstanding paint requests for the display | |
4130 * to be processed before this method returns. | |
4131 * | |
4132 * @exception SWTException <ul> | |
4133 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4134 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
4135 * </ul> | |
4136 * | |
4137 * @see Control#update() | |
4138 */ | |
4139 public void update () { | |
4140 checkDevice (); | |
4141 flushExposes (null, true); | |
4142 OS.gdk_window_process_all_updates (); | |
4143 } | |
4144 | |
4145 /** | |
4146 * If the receiver's user-interface thread was <code>sleep</code>ing, | |
4147 * causes it to be awakened and start running again. Note that this | |
4148 * method may be called from any thread. | |
4149 * | |
4150 * @exception SWTException <ul> | |
4151 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
4152 * </ul> | |
4153 * | |
4154 * @see #sleep | |
4155 */ | |
4156 public void wake () { | |
4157 synchronized (Device.classinfo) { | |
4158 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
4159 if (thread is Thread.currentThread ()) return; |
25 | 4160 wakeThread (); |
4161 } | |
4162 } | |
4163 | |
4164 void wakeThread () { | |
4165 OS.g_main_context_wakeup (null); | |
4166 wake_state = true; | |
4167 } | |
4168 | |
4169 static dchar wcsToMbcs (char ch) { | |
4170 //PORTING_TODO not sure about this | |
4171 int key = ch & 0xFFFF; | |
4172 if (key <= 0x7F) return ch; | |
4173 char [] buffer = Converter.wcsToMbcs (null,[ch], false); | |
4174 if (buffer.length is 1) return '\0'; | |
4175 if (buffer.length is 2) { | |
4176 return cast(char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF)); | |
4177 } | |
4178 return '\0'; | |
4179 } | |
4180 | |
4181 private static extern(C) int /*long*/ windowProcFunc2 (GtkWidget* handle, int /*long*/ user_data) { | |
4182 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4183 CallbackData* cbdata = cast(CallbackData*)user_data; | |
4184 return cbdata.display.windowProc( handle, cast(int)cbdata.data ); | |
4185 } | |
4186 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ user_data) { | |
4187 Widget widget = getWidget (handle); | |
4188 if (widget is null) return 0; | |
4189 return widget.windowProc (handle, user_data); | |
4190 } | |
4191 | |
4192 private static extern(C) int /*long*/ windowProcFunc3 (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { | |
4193 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4194 CallbackData* cbdata = cast(CallbackData*)user_data; | |
4195 return cbdata.display.windowProc( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); | |
4196 } | |
4197 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
4198 Widget widget = getWidget (handle); | |
4199 if (widget is null) return 0; | |
4200 return widget.windowProc (handle, arg0, user_data); | |
4201 } | |
4202 | |
4203 private static extern(C) int /*long*/ windowProcFunc4 (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) { | |
4204 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4205 CallbackData* cbdata = cast(CallbackData*)user_data; | |
4206 return cbdata.display.windowProc( cast(GtkWidget*)handle, arg0, arg1, cast(int)cbdata.data ); | |
4207 } | |
4208 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) { | |
4209 Widget widget = getWidget (handle); | |
4210 if (widget is null) return 0; | |
4211 return widget.windowProc (handle, arg0, arg1, user_data); | |
4212 } | |
4213 | |
4214 private static extern(C) int /*long*/ windowProcFunc5 (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) { | |
4215 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4216 CallbackData* cbdata = cast(CallbackData*)user_data; | |
4217 return cbdata.display.windowProc( cast(GtkWidget*)handle, arg0, arg1, arg2, cast(int)cbdata.data ); | |
4218 } | |
4219 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) { | |
4220 Widget widget = getWidget (handle); | |
4221 if (widget is null) return 0; | |
4222 return widget.windowProc (handle, arg0, arg1, arg2, user_data); | |
4223 } | |
4224 | |
4225 package int doWindowTimerAdd( CallbackData* cbdata, int delay, GtkWidget* widget ){ | |
4226 OS.g_object_set_data(cast(GObject*)widget, Display.classinfo.name.ptr, cast(void*)this); | |
4227 return OS.gtk_timeout_add (delay, &windowTimerProcFunc, widget); | |
4228 } | |
4229 private static extern(C) int /*long*/ windowTimerProcFunc (void* user_data) { | |
4230 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4231 Display d = cast(Display) OS.g_object_get_data(cast(GObject*)user_data, Display.classinfo.name.ptr ); | |
4232 return d.windowTimerProc( cast(GtkWidget*)user_data ); | |
4233 } | |
4234 | |
4235 int /*long*/ windowTimerProc (GtkWidget* handle) { | |
4236 Widget widget = getWidget (handle); | |
4237 if (widget is null) return 0; | |
4238 return widget.timerProc (handle); | |
4239 } | |
4240 | |
4241 } | |
4242 | |
4243 package struct CallbackData { | |
4244 Display display; | |
4245 void* data; | |
4246 } | |
4247 |