Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/widgets/Display.d @ 113:fb3aa8075988
D2 support for the linux port.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 06 Apr 2011 21:57:23 +0200 |
parents | b397a43d66d1 |
children | 536e43f63c81 |
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; | |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
169 static const String GET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.getModalDialog"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
170 static const String SET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.setModalDialog"; //$NON-NLS-1$ |
25 | 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; | |
51 | 823 OS.memmove (xEvent, exposeEvent, XExposeEvent.sizeof); |
25 | 824 break; |
825 } | |
826 case OS.VisibilityNotify: { | |
51 | 827 OS.memmove (visibilityEvent, xEvent, XVisibilityEvent.sizeof); |
25 | 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; | |
113
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
933 CCharPtr[] args = [ "name".ptr, "--sync".ptr, "".ptr ]; |
51 | 934 CCharPtr* a = args.ptr; |
25 | 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]; | |
51 | 1028 OS.memmove (data.ptr, pixels, data.length); |
25 | 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); | |
51 | 1072 OS.memmove(line.ptr, offset, stride); |
25 | 1073 auto maskOffset = maskPixels + (y * maskStride); |
51 | 1074 OS.memmove(maskLine.ptr, maskOffset, maskStride); |
25 | 1075 for (int x=0; x<w; x++) { |
1076 if (maskLine[x * 3] is 0) { | |
1077 line[x * 4 + 3] = 0; | |
1078 } | |
1079 } | |
51 | 1080 OS.memmove(offset, line.ptr, stride); |
25 | 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); | |
51 | 1096 OS.memmove (line.ptr, offset, stride); |
25 | 1097 for (int x = 0; x < w; x++) { |
1098 line [x*4+3] = alpha [y*w+x]; | |
1099 } | |
51 | 1100 OS.memmove (offset, line.ptr, stride); |
25 | 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)); | |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
51
diff
changeset
|
1244 return; |
25 | 1245 } |
1246 OS.gtk_main_do_event (event); | |
1247 if (dispatchEvents is null) putGdkEvents (); | |
1248 } | |
1249 | |
1250 /** | |
1251 * Given the operating system handle for a widget, returns | |
1252 * the instance of the <code>Widget</code> subclass which | |
1253 * represents it in the currently running application, if | |
1254 * such exists, or null if no matching widget can be found. | |
1255 * <p> | |
1256 * <b>IMPORTANT:</b> This method should not be called from | |
1257 * application code. The arguments are platform-specific. | |
1258 * </p> | |
1259 * | |
1260 * @param handle the handle for the widget | |
1261 * @return the SWT widget that the handle represents | |
1262 * | |
1263 * @exception SWTException <ul> | |
1264 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1265 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1266 * </ul> | |
1267 */ | |
1268 public Widget findWidget (GtkWidget* handle) { | |
1269 checkDevice (); | |
1270 return getWidget (handle); | |
1271 } | |
1272 | |
1273 /** | |
1274 * Given the operating system handle for a widget, | |
1275 * and widget-specific id, returns the instance of | |
1276 * the <code>Widget</code> subclass which represents | |
1277 * the handle/id pair in the currently running application, | |
1278 * if such exists, or null if no matching widget can be found. | |
1279 * <p> | |
1280 * <b>IMPORTANT:</b> This method should not be called from | |
1281 * application code. The arguments are platform-specific. | |
1282 * </p> | |
1283 * | |
1284 * @param handle the handle for the widget | |
1285 * @param id the id for the subwidget (usually an item) | |
1286 * @return the SWT widget that the handle/id pair represents | |
1287 * | |
1288 * @exception SWTException <ul> | |
1289 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1290 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1291 * </ul> | |
1292 * | |
1293 * @since 3.1 | |
1294 */ | |
1295 public Widget findWidget (GtkWidget* handle, int id) { | |
1296 checkDevice (); | |
1297 return null; | |
1298 } | |
1299 | |
1300 /** | |
1301 * Given a widget and a widget-specific id, returns the | |
1302 * instance of the <code>Widget</code> subclass which represents | |
1303 * the widget/id pair in the currently running application, | |
1304 * if such exists, or null if no matching widget can be found. | |
1305 * | |
1306 * @param widget the widget | |
1307 * @param id the id for the subwidget (usually an item) | |
1308 * @return the SWT subwidget (usually an item) that the widget/id pair represents | |
1309 * | |
1310 * @exception SWTException <ul> | |
1311 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1312 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1313 * </ul> | |
1314 * | |
1315 * @since 3.3 | |
1316 */ | |
1317 public Widget findWidget (Widget widget, int /*long*/ id) { | |
1318 checkDevice (); | |
1319 return null; | |
1320 } | |
1321 | |
1322 private static extern(C) void fixedClassInitProcFunc (void* g_class, void* class_data) { | |
1323 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1324 GtkWidgetClass* klass = cast(GtkWidgetClass*)g_class; | |
1325 klass.map = &fixedMapProcFunc; | |
1326 oldFixedSizeAllocateProc = klass.size_allocate; | |
1327 klass.size_allocate = &fixedSizeAllocateProc; | |
1328 } | |
1329 | |
1330 private static extern(C) void fixedMapProcFunc (GtkWidget * handle) { | |
1331 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1332 Display display = getCurrent (); | |
1333 Widget widget = display.getWidget (handle); | |
1334 if (widget !is null) widget.fixedMapProc (handle); | |
1335 } | |
1336 | |
1337 private static extern(C) static void fixedSizeAllocateProc (GtkWidget* handle, GtkAllocation* allocation) { | |
1338 Display display = getCurrent (); | |
1339 Widget widget = display.getWidget (handle); | |
1340 if (widget !is null) return widget.fixedSizeAllocateProc (handle, allocation); | |
1341 return oldFixedSizeAllocateProc(handle, allocation); | |
1342 } | |
1343 | |
1344 private static extern(C) void rendererClassInitProcFunc (void* g_class, void* class_data) { | |
1345 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1346 GtkCellRendererClass* klass = cast(GtkCellRendererClass*)g_class; | |
1347 klass.render = &rendererRenderProcFunc; | |
1348 klass.get_size = &rendererGetSizeProcFunc; | |
1349 | |
1350 } | |
1351 private static extern(C) void rendererGetSizeProcFunc( | |
1352 GtkCellRenderer *cell, | |
1353 GtkWidget *handle, | |
1354 GdkRectangle *cell_area, | |
1355 int *x_offset, | |
1356 int *y_offset, | |
1357 int *width, | |
1358 int *height) | |
1359 { | |
1360 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1361 Display display = getCurrent (); | |
1362 Widget widget = display.getWidget (handle); | |
1363 if (widget !is null) widget.rendererGetSizeProc (cell, handle, cell_area, x_offset, y_offset, width, height); | |
1364 } | |
1365 private static extern(C) void rendererRenderProcFunc(GtkCellRenderer * cell, GdkDrawable * window, GtkWidget * handle, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, int flags){ | |
1366 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1367 Display display = getCurrent (); | |
1368 Widget widget = display.getWidget (handle); | |
1369 if (widget !is null) widget.rendererRenderProc (cell, window, handle, background_area, cell_area, expose_area, flags); | |
1370 } | |
1371 | |
1372 void flushExposes (GdkWindow* window, bool all) { | |
1373 OS.gdk_flush (); | |
1374 OS.gdk_flush (); | |
1375 if (OS.GDK_WINDOWING_X11 ()) { | |
1376 this.flushWindow = window; | |
1377 this.flushAll = all; | |
1378 auto xDisplay = OS.GDK_DISPLAY (); | |
1379 auto xEvent = cast(XEvent*)OS.g_malloc (XEvent.sizeof); | |
1380 OS.XCheckIfEvent (xDisplay, xEvent, &checkIfEventProcFunc, cast(char*)this ); | |
1381 OS.g_free (xEvent); | |
1382 this.flushWindow = null; | |
1383 } | |
1384 } | |
1385 | |
1386 /** | |
1387 * Returns the currently active <code>Shell</code>, or null | |
1388 * if no shell belonging to the currently running application | |
1389 * is active. | |
1390 * | |
1391 * @return the active shell or null | |
1392 * | |
1393 * @exception SWTException <ul> | |
1394 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1395 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1396 * </ul> | |
1397 */ | |
1398 public Shell getActiveShell () { | |
1399 checkDevice (); | |
1400 return activeShell; | |
1401 } | |
1402 | |
1403 /** | |
1404 * Returns a rectangle describing the receiver's size and location. Note that | |
1405 * on multi-monitor systems the origin can be negative. | |
1406 * | |
1407 * @return the bounding rectangle | |
1408 * | |
1409 * @exception SWTException <ul> | |
1410 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1411 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1412 * </ul> | |
1413 */ | |
1414 public override Rectangle getBounds () { | |
1415 checkDevice (); | |
1416 return new Rectangle (0, 0, OS.gdk_screen_width (), OS.gdk_screen_height ()); | |
1417 } | |
1418 | |
1419 /** | |
1420 * Returns the display which the currently running thread is | |
1421 * the user-interface thread for, or null if the currently | |
1422 * running thread is not a user-interface thread for any display. | |
1423 * | |
1424 * @return the current display | |
1425 */ | |
1426 public static Display getCurrent () { | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
1427 return findDisplay (Thread.currentThread ()); |
25 | 1428 } |
1429 | |
1430 int getCaretBlinkTime () { | |
1431 // checkDevice (); | |
1432 auto settings = OS.gtk_settings_get_default (); | |
1433 if (settings is null) return 500; | |
1434 int buffer; | |
1435 OS.g_object_get1 (settings, OS.gtk_cursor_blink.ptr, &buffer ); | |
1436 if (buffer is 0) return 0; | |
1437 OS.g_object_get1 (settings, OS.gtk_cursor_blink_time.ptr, &buffer); | |
1438 if (buffer is 0) return 500; | |
1439 /* | |
1440 * By experimentation, GTK application don't use the whole | |
1441 * blink cycle time. Instead, they divide up the time, using | |
1442 * an effective blink rate of about 1/2 the total time. | |
1443 */ | |
1444 return buffer / 2; | |
1445 } | |
1446 | |
1447 /** | |
1448 * Returns the control which the on-screen pointer is currently | |
1449 * over top of, or null if it is not currently over one of the | |
1450 * controls built by the currently running application. | |
1451 * | |
1452 * @return the control under the cursor | |
1453 * | |
1454 * @exception SWTException <ul> | |
1455 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1456 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1457 * </ul> | |
1458 */ | |
1459 public Control getCursorControl () { | |
1460 checkDevice(); | |
1461 int x, y; | |
1462 GtkWidget* handle; | |
1463 GtkWidget* user_data; | |
1464 auto window = OS.gdk_window_at_pointer (&x, &y); | |
1465 if (window !is null) { | |
1466 OS.gdk_window_get_user_data (window, cast(void**)&user_data); | |
1467 handle = user_data; | |
1468 } else { | |
1469 /* | |
1470 * Feature in GTK. gdk_window_at_pointer() will not return a window | |
1471 * if the pointer is over a foreign embedded window. The fix is to use | |
1472 * XQueryPointer to find the containing GDK window. | |
1473 */ | |
1474 if (!OS.GDK_WINDOWING_X11 ()) return null; | |
1475 OS.gdk_error_trap_push (); | |
1476 int unusedInt; | |
1477 uint unusedUInt; | |
1478 uint unusedPtr; | |
1479 uint buffer; | |
1480 uint xWindow, xParent = OS.XDefaultRootWindow (xDisplay); | |
1481 do { | |
1482 if (OS.XQueryPointer (xDisplay, xParent, &unusedPtr, &buffer, &unusedInt, &unusedInt, &unusedInt, &unusedInt, &unusedUInt) is 0) { | |
1483 handle = null; | |
1484 break; | |
1485 } | |
1486 if ((xWindow = buffer) !is 0) { | |
1487 xParent = xWindow; | |
1488 auto gdkWindow = OS.gdk_window_lookup (xWindow); | |
1489 if (gdkWindow !is null) { | |
1490 OS.gdk_window_get_user_data (gdkWindow, cast(void**)&user_data); | |
1491 if (user_data !is null) handle = user_data; | |
1492 } | |
1493 } | |
1494 } while (xWindow !is 0); | |
1495 OS.gdk_error_trap_pop (); | |
1496 } | |
1497 if (handle is null) return null; | |
1498 do { | |
1499 Widget widget = getWidget (handle); | |
1500 if (widget !is null && (null !is cast(Control)widget)) { | |
1501 Control control = cast(Control) widget; | |
1502 if (control.isEnabled ()) return control; | |
1503 } | |
1504 } while ((handle = OS.gtk_widget_get_parent (handle)) !is null); | |
1505 return null; | |
1506 } | |
1507 | |
1508 bool filterEvent (Event event) { | |
1509 if (filterTable !is null) filterTable.sendEvent (event); | |
1510 return false; | |
1511 } | |
1512 | |
1513 bool filters (int eventType) { | |
1514 if (filterTable is null) return false; | |
1515 return filterTable.hooks (eventType); | |
1516 } | |
1517 | |
1518 private static extern(C) int filterProcFunc (GdkXEvent* xEvent, GdkEvent* gdkEvent, void* data) { | |
1519 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
1520 auto callbackdata = cast(CallbackData*)data; | |
1521 auto disp = callbackdata.display; | |
1522 if( disp is null ) return 0; | |
1523 auto res = disp.filterProcMeth(xEvent,gdkEvent,callbackdata); | |
1524 return res; | |
1525 } | |
1526 | |
1527 int filterProcMeth (GdkXEvent* xEvent, GdkEvent* gdkEvent, CallbackData* callbackData) { | |
1528 if( callbackData.data is null ){ | |
1529 /* | |
1530 * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK | |
1531 * does not deliver a corresponding GTK event. Button 6 and 7 | |
1532 * are mapped to buttons 4 and 5 in SWT. The fix is to change | |
1533 * the button number of the event to a negative number so that | |
1534 * it gets dispatched by GTK. SWT has been modified to look | |
1535 * for negative button numbers. | |
1536 */ | |
1537 XButtonEvent* mouseEvent = cast(XButtonEvent*) xEvent; | |
1538 if (mouseEvent.type is OS.ButtonRelease) { | |
1539 switch (mouseEvent.button) { | |
1540 case 6: | |
1541 case 7: | |
1542 mouseEvent.button = -mouseEvent.button; | |
1543 break; | |
1544 default: | |
1545 } | |
1546 } | |
1547 } | |
1548 Widget widget = getWidget (cast(GtkWidget*)callbackData.data); | |
1549 if (widget is null) return 0; | |
1550 return widget.filterProc (cast(XEvent*)xEvent, gdkEvent, callbackData.data); | |
1551 } | |
1552 | |
1553 /** | |
1554 * Returns the location of the on-screen pointer relative | |
1555 * to the top left corner of the screen. | |
1556 * | |
1557 * @return the cursor location | |
1558 * | |
1559 * @exception SWTException <ul> | |
1560 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1561 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1562 * </ul> | |
1563 */ | |
1564 public Point getCursorLocation () { | |
1565 checkDevice (); | |
1566 int x, y; | |
1567 OS.gdk_window_get_pointer (null, &x, &y, null); | |
1568 return new Point (x, y); | |
1569 } | |
1570 | |
1571 /** | |
1572 * Returns an array containing the recommended cursor sizes. | |
1573 * | |
1574 * @return the array of cursor sizes | |
1575 * | |
1576 * @exception SWTException <ul> | |
1577 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1578 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1579 * </ul> | |
1580 * | |
1581 * @since 3.0 | |
1582 */ | |
1583 public Point [] getCursorSizes () { | |
1584 checkDevice (); | |
1585 return [new Point (16, 16), new Point (32, 32)]; | |
1586 } | |
1587 | |
1588 /** | |
1589 * Returns the application defined property of the receiver | |
1590 * with the specified name, or null if it has not been set. | |
1591 * <p> | |
1592 * Applications may have associated arbitrary objects with the | |
1593 * receiver in this fashion. If the objects stored in the | |
1594 * properties need to be notified when the display is disposed | |
1595 * of, it is the application's responsibility to provide a | |
1596 * <code>disposeExec()</code> handler which does so. | |
1597 * </p> | |
1598 * | |
1599 * @param key the name of the property | |
1600 * @return the value of the property or null if it has not been set | |
1601 * | |
1602 * @exception SWTException <ul> | |
1603 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1604 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1605 * </ul> | |
1606 * | |
1607 * @see #setData(String, Object) | |
1608 * @see #disposeExec(Runnable) | |
1609 */ | |
1610 public Object getData (String key) { | |
1611 checkDevice (); | |
1612 // SWT extension: allow null for zero length string | |
1613 //if (key is null) error (SWT.ERROR_NULL_ARGUMENT); | |
1614 if (key.equals (DISPATCH_EVENT_KEY)) { | |
1615 return new ArrayWrapperInt(dispatchEvents); | |
1616 } | |
1617 if (key.equals (GET_MODAL_DIALOG)) { | |
1618 return modalDialog; | |
1619 } | |
1620 if (key.equals (GET_DIRECTION_PROC_KEY)) { | |
1621 return new LONG (cast(int) &setDirectionProcFunc); | |
1622 } | |
1623 if (key.equals (GET_EMISSION_PROC_KEY)) { | |
1624 return new LONG (cast(int) &emissionFunc); | |
1625 } | |
1626 if (keys is null) return null; | |
1627 for (int i=0; i<keys.length; i++) { | |
1628 if (keys [i].equals(key)) return values [i]; | |
1629 } | |
1630 return null; | |
1631 } | |
1632 | |
1633 /** | |
1634 * Returns the application defined, display specific data | |
1635 * associated with the receiver, or null if it has not been | |
1636 * set. The <em>display specific data</em> is a single, | |
1637 * unnamed field that is stored with every display. | |
1638 * <p> | |
1639 * Applications may put arbitrary objects in this field. If | |
1640 * the object stored in the display specific data needs to | |
1641 * be notified when the display is disposed of, it is the | |
1642 * application's responsibility to provide a | |
1643 * <code>disposeExec()</code> handler which does so. | |
1644 * </p> | |
1645 * | |
1646 * @return the display specific data | |
1647 * | |
1648 * @exception SWTException <ul> | |
1649 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1650 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1651 * </ul> | |
1652 * | |
1653 * @see #setData(Object) | |
1654 * @see #disposeExec(Runnable) | |
1655 */ | |
1656 public Object getData () { | |
1657 checkDevice (); | |
1658 return data; | |
1659 } | |
1660 | |
1661 /** | |
1662 * Returns a point whose x coordinate is the horizontal | |
1663 * dots per inch of the display, and whose y coordinate | |
1664 * is the vertical dots per inch of the display. | |
1665 * | |
1666 * @return the horizontal and vertical DPI | |
1667 * | |
1668 * @exception SWTException <ul> | |
1669 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1670 * </ul> | |
1671 */ | |
1672 public override Point getDPI () { | |
1673 checkDevice (); | |
1674 int widthMM = OS.gdk_screen_width_mm (); | |
1675 int width = OS.gdk_screen_width (); | |
1676 int dpi = Compatibility.round (254 * width, widthMM * 10); | |
1677 return new Point (dpi, dpi); | |
1678 } | |
1679 | |
1680 int /*long*/ gtk_fixed_get_type () { | |
1681 return fixed_type; | |
1682 } | |
1683 | |
1684 int /*long*/ gtk_cell_renderer_text_get_type () { | |
1685 return text_renderer_type; | |
1686 } | |
1687 | |
1688 int /*long*/ gtk_cell_renderer_pixbuf_get_type () { | |
1689 return pixbuf_renderer_type; | |
1690 } | |
1691 | |
1692 int /*long*/ gtk_cell_renderer_toggle_get_type () { | |
1693 return toggle_renderer_type; | |
1694 } | |
1695 | |
1696 /** | |
1697 * Returns the default display. One is created (making the | |
1698 * thread that invokes this method its user-interface thread) | |
1699 * if it did not already exist. | |
1700 * | |
1701 * @return the default display | |
1702 */ | |
1703 public static Display getDefault () { | |
1704 synchronized (Device.classinfo) { | |
1705 if (Default is null) Default = new Display (); | |
1706 return Default; | |
1707 } | |
1708 } | |
1709 | |
1710 // /+static bool isValidClass (Class clazz) { | |
1711 // //PORTING_TODO String name = clazz.getName (); | |
1712 // //PORTING_TODO int index = name.lastIndexOf ('.'); | |
1713 // //PORTING_TODO return name.substring (0, index + 1)==/*eq*/ PACKAGE_PREFIX; | |
1714 // return true; | |
1715 // }+/ | |
1716 | |
1717 /** | |
1718 * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>. | |
1719 * The button dismissal alignment is the ordering that should be used when positioning the | |
1720 * default dismissal button for a dialog. For example, in a dialog that contains an OK and | |
1721 * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the | |
1722 * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>, | |
1723 * the button ordering should be CANCEL/OK. | |
1724 * | |
1725 * @return the button dismissal order | |
1726 * | |
1727 * @exception SWTException <ul> | |
1728 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1729 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1730 * </ul> | |
1731 * | |
1732 * @since 2.1 | |
1733 */ | |
1734 public int getDismissalAlignment () { | |
1735 checkDevice (); | |
1736 return SWT.RIGHT; | |
1737 } | |
1738 | |
1739 /** | |
1740 * Returns the longest duration, in milliseconds, between | |
1741 * two mouse button clicks that will be considered a | |
1742 * <em>double click</em> by the underlying operating system. | |
1743 * | |
1744 * @return the double click time | |
1745 * | |
1746 * @exception SWTException <ul> | |
1747 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1748 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1749 * </ul> | |
1750 */ | |
1751 public int getDoubleClickTime () { | |
1752 checkDevice (); | |
1753 auto settings = OS.gtk_settings_get_default (); | |
1754 int buffer; | |
1755 OS.g_object_get1 (settings, OS.gtk_double_click_time.ptr, &buffer); | |
1756 return buffer; | |
1757 } | |
1758 | |
1759 /** | |
1760 * Returns the control which currently has keyboard focus, | |
1761 * or null if keyboard events are not currently going to | |
1762 * any of the controls built by the currently running | |
1763 * application. | |
1764 * | |
1765 * @return the control under the cursor | |
1766 * | |
1767 * @exception SWTException <ul> | |
1768 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1769 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1770 * </ul> | |
1771 */ | |
1772 public Control getFocusControl () { | |
1773 checkDevice (); | |
1774 if (focusControl !is null && !focusControl.isDisposed ()) { | |
1775 return focusControl; | |
1776 } | |
1777 if (activeShell is null) return null; | |
1778 auto shellHandle = activeShell.shellHandle; | |
1779 auto handle = OS.gtk_window_get_focus (cast(GtkWindow*)shellHandle); | |
1780 if (handle is null) return null; | |
1781 do { | |
1782 Widget widget = getWidget (handle); | |
1783 if (widget !is null && (null !is cast(Control)widget)) { | |
1784 Control control = cast(Control) widget; | |
1785 return control.isEnabled () ? control : null; | |
1786 } | |
1787 } while ((handle = OS.gtk_widget_get_parent (handle)) !is null); | |
1788 return null; | |
1789 } | |
1790 | |
1791 /** | |
1792 * Returns true when the high contrast mode is enabled. | |
1793 * Otherwise, false is returned. | |
1794 * <p> | |
1795 * Note: This operation is a hint and is not supported on | |
1796 * platforms that do not have this concept. | |
1797 * </p> | |
1798 * | |
1799 * @return the high contrast mode | |
1800 * | |
1801 * @exception SWTException <ul> | |
1802 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1803 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1804 * </ul> | |
1805 * | |
1806 * @since 3.0 | |
1807 */ | |
1808 public bool getHighContrast () { | |
1809 checkDevice (); | |
1810 return false; | |
1811 } | |
1812 | |
1813 public override int getDepth () { | |
1814 checkDevice (); | |
1815 auto visual = OS.gdk_visual_get_system(); | |
1816 return visual.depth; | |
1817 } | |
1818 | |
1819 /** | |
1820 * Returns the maximum allowed depth of icons on this display, in bits per pixel. | |
1821 * On some platforms, this may be different than the actual depth of the display. | |
1822 * | |
1823 * @return the maximum icon depth | |
1824 * | |
1825 * @exception SWTException <ul> | |
1826 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1827 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1828 * </ul> | |
1829 * | |
1830 * @see Device#getDepth | |
1831 */ | |
1832 public int getIconDepth () { | |
1833 checkDevice (); | |
1834 return getDepth (); | |
1835 } | |
1836 | |
1837 /** | |
1838 * Returns an array containing the recommended icon sizes. | |
1839 * | |
1840 * @return the array of icon sizes | |
1841 * | |
1842 * @exception SWTException <ul> | |
1843 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1844 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1845 * </ul> | |
1846 * | |
1847 * @see Decorations#setImages(Image[]) | |
1848 * | |
1849 * @since 3.0 | |
1850 */ | |
1851 public Point [] getIconSizes () { | |
1852 checkDevice (); | |
1853 return [new Point (16, 16), new Point (32, 32)]; | |
1854 } | |
1855 | |
1856 int getLastEventTime () { | |
1857 return lastEventTime; | |
1858 } | |
1859 | |
1860 int getMessageCount () { | |
1861 return synchronizer.getMessageCount (); | |
1862 } | |
1863 | |
1864 Dialog getModalDialog () { | |
1865 return modalDialog; | |
1866 } | |
1867 | |
1868 /** | |
1869 * Returns the work area, an EWMH property to store the size | |
1870 * and position of the screen not covered by dock and panel | |
1871 * windows. See http://freedesktop.org/Standards/wm-spec. | |
1872 */ | |
1873 Rectangle getWorkArea() { | |
1874 auto atom = OS.gdk_atom_intern ("_NET_WORKAREA".ptr, true); | |
1875 if (atom is null/*OS.GDK_NONE*/) return null; | |
1876 void* actualType; | |
1877 int actualFormat; | |
1878 int actualLength; | |
1879 char* data; | |
1880 if (!OS.gdk_property_get (cast(GdkDrawable*)OS.GDK_ROOT_PARENT (), atom, null/*OS.GDK_NONE*/, 0, 16, 0, &actualType, &actualFormat, &actualLength, &data)) { | |
1881 return null; | |
1882 } | |
1883 Rectangle result = null; | |
1884 if (data !is null) { | |
1885 if (actualLength is 16) { | |
1886 int[] values = (cast(int*)data)[0..4]; | |
1887 result = new Rectangle (values [0],values [1],values [2],values [3]); | |
1888 } else if (actualLength is 32) { | |
1889 long[] values = (cast(long*)data)[0..4]; | |
1890 result = new Rectangle (cast(int)values [0],cast(int)values [1],cast(int)values [2],cast(int)values [3]); | |
1891 } | |
1892 OS.g_free (data); | |
1893 } | |
1894 return result; | |
1895 } | |
1896 | |
1897 /** | |
1898 * Returns an array of monitors attached to the device. | |
1899 * | |
1900 * @return the array of monitors | |
1901 * | |
1902 * @since 3.0 | |
1903 */ | |
1904 public org.eclipse.swt.widgets.Monitor.Monitor [] getMonitors () { | |
1905 checkDevice (); | |
1906 org.eclipse.swt.widgets.Monitor.Monitor [] monitors = null; | |
1907 Rectangle workArea = getWorkArea(); | |
1908 auto screen = OS.gdk_screen_get_default (); | |
1909 if (screen !is null) { | |
1910 int monitorCount = OS.gdk_screen_get_n_monitors (screen); | |
1911 if (monitorCount > 0) { | |
1912 monitors = new org.eclipse.swt.widgets.Monitor.Monitor [monitorCount]; | |
1913 GdkRectangle* dest = new GdkRectangle (); | |
1914 for (int i = 0; i < monitorCount; i++) { | |
1915 OS.gdk_screen_get_monitor_geometry (screen, i, dest); | |
1916 auto monitor = new org.eclipse.swt.widgets.Monitor.Monitor (); | |
1917 monitor.handle = i; | |
1918 monitor.x = dest.x; | |
1919 monitor.y = dest.y; | |
1920 monitor.width = dest.width; | |
1921 monitor.height = dest.height; | |
1922 if (i is 0 && workArea !is null) { | |
1923 monitor.clientX = workArea.x; | |
1924 monitor.clientY = workArea.y; | |
1925 monitor.clientWidth = workArea.width; | |
1926 monitor.clientHeight = workArea.height; | |
1927 } else { | |
1928 monitor.clientX = monitor.x; | |
1929 monitor.clientY = monitor.y; | |
1930 monitor.clientWidth = monitor.width; | |
1931 monitor.clientHeight = monitor.height; | |
1932 } | |
1933 monitors [i] = monitor; | |
1934 } | |
1935 } | |
1936 } | |
1937 if (monitors is null) { | |
1938 /* No multimonitor support detected, default to one monitor */ | |
1939 auto monitor = new org.eclipse.swt.widgets.Monitor.Monitor (); | |
1940 Rectangle bounds = getBounds (); | |
1941 monitor.x = bounds.x; | |
1942 monitor.y = bounds.y; | |
1943 monitor.width = bounds.width; | |
1944 monitor.height = bounds.height; | |
1945 if (workArea !is null) { | |
1946 monitor.clientX = workArea.x; | |
1947 monitor.clientY = workArea.y; | |
1948 monitor.clientWidth = workArea.width; | |
1949 monitor.clientHeight = workArea.height; | |
1950 } else { | |
1951 monitor.clientX = monitor.x; | |
1952 monitor.clientY = monitor.y; | |
1953 monitor.clientWidth = monitor.width; | |
1954 monitor.clientHeight = monitor.height; | |
1955 } | |
1956 monitors = [ monitor ]; | |
1957 } | |
1958 return monitors; | |
1959 } | |
1960 | |
1961 /** | |
1962 * Returns the primary monitor for that device. | |
1963 * | |
1964 * @return the primary monitor | |
1965 * | |
1966 * @since 3.0 | |
1967 */ | |
1968 public org.eclipse.swt.widgets.Monitor.Monitor getPrimaryMonitor () { | |
1969 checkDevice (); | |
1970 auto monitors = getMonitors (); | |
1971 return monitors [0]; | |
1972 } | |
1973 | |
1974 /** | |
1975 * Returns a (possibly empty) array containing all shells which have | |
1976 * not been disposed and have the receiver as their display. | |
1977 * | |
1978 * @return the receiver's shells | |
1979 * | |
1980 * @exception SWTException <ul> | |
1981 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1982 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
1983 * </ul> | |
1984 */ | |
1985 public Shell [] getShells () { | |
1986 checkDevice (); | |
1987 int index = 0; | |
1988 Shell [] result = new Shell [16]; | |
1989 for (int i = 0; i < widgetTable.length; i++) { | |
1990 Widget widget = widgetTable [i]; | |
1991 if (widget !is null && (null !is cast(Shell)widget)) { | |
1992 int j = 0; | |
1993 while (j < index) { | |
1994 if (result [j] is widget) break; | |
1995 j++; | |
1996 } | |
1997 if (j is index) { | |
1998 if (index is result.length) { | |
1999 Shell [] newResult = new Shell [index + 16]; | |
2000 System.arraycopy (result, 0, newResult, 0, index); | |
2001 result = newResult; | |
2002 } | |
2003 result [index++] = cast(Shell) widget; | |
2004 } | |
2005 } | |
2006 } | |
2007 if (index is result.length) return result; | |
2008 Shell [] newResult = new Shell [index]; | |
2009 System.arraycopy (result, 0, newResult, 0, index); | |
2010 return newResult; | |
2011 } | |
2012 | |
2013 /** | |
2014 * Gets the synchronizer used by the display. | |
2015 * | |
2016 * @return the receiver's synchronizer | |
2017 * | |
2018 * @exception SWTException <ul> | |
2019 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2020 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2021 * </ul> | |
2022 * | |
2023 * @since 3.4 | |
2024 */ | |
2025 public Synchronizer getSynchronizer () { | |
2026 checkDevice (); | |
2027 return synchronizer; | |
2028 } | |
2029 | |
2030 /** | |
2031 * Returns the thread that has invoked <code>syncExec</code> | |
2032 * or null if no such runnable is currently being invoked by | |
2033 * the user-interface thread. | |
2034 * <p> | |
2035 * Note: If a runnable invoked by asyncExec is currently | |
2036 * running, this method will return null. | |
2037 * </p> | |
2038 * | |
2039 * @return the receiver's sync-interface thread | |
2040 * | |
2041 * @exception SWTException <ul> | |
2042 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2043 * </ul> | |
2044 */ | |
2045 public Thread getSyncThread () { | |
2046 synchronized (Device.classinfo) { | |
2047 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
2048 return synchronizer.syncThread; | |
2049 } | |
2050 } | |
2051 | |
2052 /** | |
2053 * Returns the matching standard color for the given | |
2054 * constant, which should be one of the color constants | |
2055 * specified in class <code>SWT</code>. Any value other | |
2056 * than one of the SWT color constants which is passed | |
2057 * in will result in the color black. This color should | |
2058 * not be free'd because it was allocated by the system, | |
2059 * not the application. | |
2060 * | |
2061 * @param id the color constant | |
2062 * @return the matching color | |
2063 * | |
2064 * @exception SWTException <ul> | |
2065 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2066 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2067 * </ul> | |
2068 * | |
2069 * @see SWT | |
2070 */ | |
2071 public override Color getSystemColor (int id) { | |
2072 checkDevice (); | |
2073 GdkColor* gdkColor = null; | |
2074 switch (id) { | |
2075 case SWT.COLOR_INFO_FOREGROUND: gdkColor = COLOR_INFO_FOREGROUND; break; | |
2076 case SWT.COLOR_INFO_BACKGROUND: gdkColor = COLOR_INFO_BACKGROUND; break; | |
2077 case SWT.COLOR_TITLE_FOREGROUND: gdkColor = COLOR_TITLE_FOREGROUND; break; | |
2078 case SWT.COLOR_TITLE_BACKGROUND: gdkColor = COLOR_TITLE_BACKGROUND; break; | |
2079 case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_BACKGROUND_GRADIENT; break; | |
2080 case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: gdkColor = COLOR_TITLE_INACTIVE_FOREGROUND; break; | |
2081 case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND; break; | |
2082 case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT; break; | |
2083 case SWT.COLOR_WIDGET_DARK_SHADOW: gdkColor = COLOR_WIDGET_DARK_SHADOW; break; | |
2084 case SWT.COLOR_WIDGET_NORMAL_SHADOW: gdkColor = COLOR_WIDGET_NORMAL_SHADOW; break; | |
2085 case SWT.COLOR_WIDGET_LIGHT_SHADOW: gdkColor = COLOR_WIDGET_LIGHT_SHADOW; break; | |
2086 case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: gdkColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break; | |
2087 case SWT.COLOR_WIDGET_BACKGROUND: gdkColor = COLOR_WIDGET_BACKGROUND; break; | |
2088 case SWT.COLOR_WIDGET_FOREGROUND: gdkColor = COLOR_WIDGET_FOREGROUND; break; | |
2089 case SWT.COLOR_WIDGET_BORDER: gdkColor = COLOR_WIDGET_BORDER; break; | |
2090 case SWT.COLOR_LIST_FOREGROUND: gdkColor = COLOR_LIST_FOREGROUND; break; | |
2091 case SWT.COLOR_LIST_BACKGROUND: gdkColor = COLOR_LIST_BACKGROUND; break; | |
2092 case SWT.COLOR_LIST_SELECTION: gdkColor = COLOR_LIST_SELECTION; break; | |
2093 case SWT.COLOR_LIST_SELECTION_TEXT: gdkColor = COLOR_LIST_SELECTION_TEXT; break; | |
2094 default: | |
2095 return super.getSystemColor (id); | |
2096 } | |
2097 if (gdkColor is null) return super.getSystemColor (SWT.COLOR_BLACK); | |
2098 return Color.gtk_new (this, gdkColor); | |
2099 } | |
2100 | |
2101 /** | |
2102 * Returns the matching standard platform cursor for the given | |
2103 * constant, which should be one of the cursor constants | |
2104 * specified in class <code>SWT</code>. This cursor should | |
2105 * not be free'd because it was allocated by the system, | |
2106 * not the application. A value of <code>null</code> will | |
2107 * be returned if the supplied constant is not an SWT cursor | |
2108 * constant. | |
2109 * | |
2110 * @param id the SWT cursor constant | |
2111 * @return the corresponding cursor or <code>null</code> | |
2112 * | |
2113 * @exception SWTException <ul> | |
2114 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2115 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2116 * </ul> | |
2117 * | |
2118 * @see SWT#CURSOR_ARROW | |
2119 * @see SWT#CURSOR_WAIT | |
2120 * @see SWT#CURSOR_CROSS | |
2121 * @see SWT#CURSOR_APPSTARTING | |
2122 * @see SWT#CURSOR_HELP | |
2123 * @see SWT#CURSOR_SIZEALL | |
2124 * @see SWT#CURSOR_SIZENESW | |
2125 * @see SWT#CURSOR_SIZENS | |
2126 * @see SWT#CURSOR_SIZENWSE | |
2127 * @see SWT#CURSOR_SIZEWE | |
2128 * @see SWT#CURSOR_SIZEN | |
2129 * @see SWT#CURSOR_SIZES | |
2130 * @see SWT#CURSOR_SIZEE | |
2131 * @see SWT#CURSOR_SIZEW | |
2132 * @see SWT#CURSOR_SIZENE | |
2133 * @see SWT#CURSOR_SIZESE | |
2134 * @see SWT#CURSOR_SIZESW | |
2135 * @see SWT#CURSOR_SIZENW | |
2136 * @see SWT#CURSOR_UPARROW | |
2137 * @see SWT#CURSOR_IBEAM | |
2138 * @see SWT#CURSOR_NO | |
2139 * @see SWT#CURSOR_HAND | |
2140 * | |
2141 * @since 3.0 | |
2142 */ | |
2143 public Cursor getSystemCursor (int id) { | |
2144 checkDevice (); | |
2145 if (!(0 <= id && id < cursors.length)) return null; | |
2146 if (cursors [id] is null) { | |
2147 cursors [id] = new Cursor (this, id); | |
2148 } | |
2149 return cursors [id]; | |
2150 } | |
2151 | |
2152 /** | |
2153 * Returns the matching standard platform image for the given | |
2154 * constant, which should be one of the icon constants | |
2155 * specified in class <code>SWT</code>. This image should | |
2156 * not be free'd because it was allocated by the system, | |
2157 * not the application. A value of <code>null</code> will | |
2158 * be returned either if the supplied constant is not an | |
2159 * SWT icon constant or if the platform does not define an | |
2160 * image that corresponds to the constant. | |
2161 * | |
2162 * @param id the SWT icon constant | |
2163 * @return the corresponding image or <code>null</code> | |
2164 * | |
2165 * @exception SWTException <ul> | |
2166 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2167 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2168 * </ul> | |
2169 * | |
2170 * @see SWT#ICON_ERROR | |
2171 * @see SWT#ICON_INFORMATION | |
2172 * @see SWT#ICON_QUESTION | |
2173 * @see SWT#ICON_WARNING | |
2174 * @see SWT#ICON_WORKING | |
2175 * | |
2176 * @since 3.0 | |
2177 */ | |
2178 public Image getSystemImage (int id) { | |
2179 checkDevice (); | |
2180 switch (id) { | |
2181 case SWT.ICON_ERROR: | |
2182 if (errorImage is null) { | |
2183 errorImage = createImage ("gtk-dialog-error"); //$NON-NLS-1$ | |
2184 } | |
2185 return errorImage; | |
2186 case SWT.ICON_INFORMATION: | |
2187 case SWT.ICON_WORKING: | |
2188 if (infoImage is null) { | |
2189 infoImage = createImage ("gtk-dialog-info"); //$NON-NLS-1$ | |
2190 } | |
2191 return infoImage; | |
2192 case SWT.ICON_QUESTION: | |
2193 if (questionImage is null) { | |
2194 questionImage = createImage ("gtk-dialog-question"); //$NON-NLS-1$ | |
2195 } | |
2196 return questionImage; | |
2197 case SWT.ICON_WARNING: | |
2198 if (warningImage is null) { | |
2199 warningImage = createImage ("gtk-dialog-warning"); //$NON-NLS-1$ | |
2200 } | |
2201 return warningImage; | |
2202 default: | |
2203 } | |
2204 return null; | |
2205 } | |
2206 | |
2207 void initializeSystemColors () { | |
2208 GdkColor* gdkColor; | |
2209 | |
2210 /* Get Tooltip resources */ | |
2211 auto tooltipShellHandle = OS.gtk_window_new (OS.GTK_WINDOW_POPUP); | |
2212 if (tooltipShellHandle is null) SWT.error (SWT.ERROR_NO_HANDLES); | |
2213 // byte[] gtk_tooltips = Converter.wcsToMbcs (null, "gtk-tooltips", true); | |
2214 OS.gtk_widget_set_name (tooltipShellHandle, "gtk-tooltips".ptr ); | |
2215 OS.gtk_widget_realize (tooltipShellHandle); | |
2216 auto tooltipStyle = OS.gtk_widget_get_style (tooltipShellHandle); | |
2217 gdkColor = new GdkColor(); | |
2218 OS.gtk_style_get_fg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor); | |
2219 COLOR_INFO_FOREGROUND = gdkColor; | |
2220 gdkColor = new GdkColor(); | |
2221 OS.gtk_style_get_bg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor); | |
2222 COLOR_INFO_BACKGROUND = gdkColor; | |
2223 OS.gtk_widget_destroy (tooltipShellHandle); | |
2224 | |
2225 /* Get Shell resources */ | |
2226 auto style = OS.gtk_widget_get_style (shellHandle); | |
2227 gdkColor = new GdkColor(); | |
2228 OS.gtk_style_get_black (style, gdkColor); | |
2229 COLOR_WIDGET_DARK_SHADOW = gdkColor; | |
2230 gdkColor = new GdkColor(); | |
2231 OS.gtk_style_get_dark (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2232 COLOR_WIDGET_NORMAL_SHADOW = gdkColor; | |
2233 gdkColor = new GdkColor(); | |
2234 OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2235 COLOR_WIDGET_LIGHT_SHADOW = gdkColor; | |
2236 gdkColor = new GdkColor(); | |
2237 OS.gtk_style_get_light (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2238 COLOR_WIDGET_HIGHLIGHT_SHADOW = gdkColor; | |
2239 gdkColor = new GdkColor(); | |
2240 OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2241 COLOR_WIDGET_FOREGROUND = gdkColor; | |
2242 gdkColor = new GdkColor(); | |
2243 OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2244 COLOR_WIDGET_BACKGROUND = gdkColor; | |
2245 //gdkColor = new GdkColor(); | |
2246 //OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2247 //COLOR_TEXT_FOREGROUND = gdkColor; | |
2248 //gdkColor = new GdkColor(); | |
2249 //OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2250 //COLOR_TEXT_BACKGROUND = gdkColor; | |
2251 gdkColor = new GdkColor(); | |
2252 OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2253 COLOR_LIST_FOREGROUND = gdkColor; | |
2254 gdkColor = new GdkColor(); | |
2255 OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor); | |
2256 COLOR_LIST_BACKGROUND = gdkColor; | |
2257 gdkColor = new GdkColor(); | |
2258 OS.gtk_style_get_text (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2259 COLOR_LIST_SELECTION_TEXT = gdkColor; | |
2260 gdkColor = new GdkColor(); | |
2261 OS.gtk_style_get_base (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2262 COLOR_LIST_SELECTION = gdkColor; | |
2263 gdkColor = new GdkColor(); | |
2264 OS.gtk_style_get_bg (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2265 COLOR_TITLE_BACKGROUND = gdkColor; | |
2266 gdkColor = new GdkColor(); | |
2267 OS.gtk_style_get_fg (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2268 COLOR_TITLE_FOREGROUND = gdkColor; | |
2269 gdkColor = new GdkColor(); | |
2270 OS.gtk_style_get_light (style, OS.GTK_STATE_SELECTED, gdkColor); | |
2271 COLOR_TITLE_BACKGROUND_GRADIENT = gdkColor; | |
2272 gdkColor = new GdkColor(); | |
2273 OS.gtk_style_get_bg (style, OS.GTK_STATE_INSENSITIVE, gdkColor); | |
2274 COLOR_TITLE_INACTIVE_BACKGROUND = gdkColor; | |
2275 gdkColor = new GdkColor(); | |
2276 OS.gtk_style_get_fg (style, OS.GTK_STATE_INSENSITIVE, gdkColor); | |
2277 COLOR_TITLE_INACTIVE_FOREGROUND = gdkColor; | |
2278 gdkColor = new GdkColor(); | |
2279 OS.gtk_style_get_light (style, OS.GTK_STATE_INSENSITIVE, gdkColor); | |
2280 COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = gdkColor; | |
2281 } | |
2282 | |
2283 /** | |
2284 * Returns a reasonable font for applications to use. | |
2285 * On some platforms, this will match the "default font" | |
2286 * or "system font" if such can be found. This font | |
2287 * should not be free'd because it was allocated by the | |
2288 * system, not the application. | |
2289 * <p> | |
2290 * Typically, applications which want the default look | |
2291 * should simply not set the font on the widgets they | |
2292 * create. Widgets are always created with the correct | |
2293 * default font for the class of user-interface component | |
2294 * they represent. | |
2295 * </p> | |
2296 * | |
2297 * @return a font | |
2298 * | |
2299 * @exception SWTException <ul> | |
2300 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2301 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2302 * </ul> | |
2303 */ | |
2304 public override Font getSystemFont () { | |
2305 checkDevice (); | |
2306 if (systemFont !is null) return systemFont; | |
2307 auto style = OS.gtk_widget_get_style (shellHandle); | |
2308 auto defaultFont = OS.pango_font_description_copy (OS.gtk_style_get_font_desc (style)); | |
2309 return systemFont = Font.gtk_new (this, defaultFont); | |
2310 } | |
2311 | |
2312 /** | |
2313 * Returns the single instance of the system tray or null | |
2314 * when there is no system tray available for the platform. | |
2315 * | |
2316 * @return the system tray or <code>null</code> | |
2317 * | |
2318 * @exception SWTException <ul> | |
2319 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2320 * </ul> | |
2321 * | |
2322 * @since 3.0 | |
2323 */ | |
2324 public Tray getSystemTray () { | |
2325 checkDevice (); | |
2326 if (tray !is null) return tray; | |
2327 return tray = new Tray (this, SWT.NONE); | |
2328 } | |
2329 | |
2330 /** | |
2331 * Returns the user-interface thread for the receiver. | |
2332 * | |
2333 * @return the receiver's user-interface thread | |
2334 * | |
2335 * @exception SWTException <ul> | |
2336 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2337 * </ul> | |
2338 */ | |
2339 public Thread getThread () { | |
2340 synchronized (Device.classinfo) { | |
2341 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
2342 return thread; | |
2343 } | |
2344 } | |
2345 | |
2346 Widget getWidget (GtkWidget* handle) { | |
2347 if (handle is null) return null; | |
2348 if (lastWidget !is null && lastHandle is handle) return lastWidget; | |
2349 auto index = cast(int) OS.g_object_get_qdata ( cast(GObject*)handle, SWT_OBJECT_INDEX) - 1; | |
2350 if (0 <= index && index < widgetTable.length) { | |
2351 lastHandle = handle; | |
2352 return lastWidget = widgetTable [cast(int)/*64*/index]; | |
2353 } | |
2354 return null; | |
2355 } | |
2356 | |
2357 private static extern(C) int idleProcFunc (void* data) { | |
2358 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
2359 auto dbdata = cast(CallbackData*)data; | |
2360 return dbdata.display.idleProc(); | |
2361 } | |
2362 private int idleProc () { | |
2363 bool result = runAsyncMessages (false); | |
2364 if (!result) { | |
2365 synchronized (idleLock) { | |
2366 idleHandle = 0; | |
2367 } | |
2368 } | |
2369 return result ? 1 : 0; | |
2370 return 0; | |
2371 } | |
2372 | |
2373 /** | |
2374 * Initializes any internal resources needed by the | |
2375 * device. | |
2376 * <p> | |
2377 * This method is called after <code>create</code>. | |
2378 * </p> | |
2379 * | |
2380 * @see #create | |
2381 */ | |
2382 protected override void init_ () { | |
2383 super.init_ (); | |
2384 initializeCallbacks (); | |
2385 initializeSystemColors (); | |
2386 initializeSystemSettings (); | |
2387 initializeWidgetTable (); | |
2388 initializeWindowManager (); | |
2389 } | |
2390 | |
2391 void initializeCallbacks () { | |
2392 closures = new GClosure* [Widget.LAST_SIGNAL]; | |
2393 signalIds = new int [Widget.LAST_SIGNAL]; | |
2394 | |
2395 /* Cache signals for GtkWidget */ | |
2396 signalIds [Widget.BUTTON_PRESS_EVENT] = OS.g_signal_lookup (OS.button_press_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2397 signalIds [Widget.BUTTON_RELEASE_EVENT] = OS.g_signal_lookup (OS.button_release_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2398 signalIds [Widget.CONFIGURE_EVENT] = OS.g_signal_lookup (OS.configure_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2399 signalIds [Widget.DELETE_EVENT] = OS.g_signal_lookup (OS.delete_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2400 signalIds [Widget.ENTER_NOTIFY_EVENT] = OS.g_signal_lookup (OS.enter_notify_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2401 signalIds [Widget.EVENT] = OS.g_signal_lookup (OS.event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2402 signalIds [Widget.EVENT_AFTER] = OS.g_signal_lookup (OS.event_after.ptr, OS.GTK_TYPE_WIDGET ()); | |
2403 signalIds [Widget.EXPOSE_EVENT] = OS.g_signal_lookup (OS.expose_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2404 signalIds [Widget.FOCUS] = OS.g_signal_lookup (OS.focus.ptr, OS.GTK_TYPE_WIDGET ()); | |
2405 signalIds [Widget.FOCUS_IN_EVENT] = OS.g_signal_lookup (OS.focus_in_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2406 signalIds [Widget.FOCUS_OUT_EVENT] = OS.g_signal_lookup (OS.focus_out_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2407 signalIds [Widget.GRAB_FOCUS] = OS.g_signal_lookup (OS.grab_focus.ptr, OS.GTK_TYPE_WIDGET ()); | |
2408 signalIds [Widget.HIDE] = OS.g_signal_lookup (OS.hide.ptr, OS.GTK_TYPE_WIDGET ()); | |
2409 signalIds [Widget.KEY_PRESS_EVENT] = OS.g_signal_lookup (OS.key_press_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2410 signalIds [Widget.KEY_RELEASE_EVENT] = OS.g_signal_lookup (OS.key_release_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2411 signalIds [Widget.LEAVE_NOTIFY_EVENT] = OS.g_signal_lookup (OS.leave_notify_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2412 signalIds [Widget.MAP] = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET ()); | |
2413 signalIds [Widget.MAP_EVENT] = OS.g_signal_lookup (OS.map_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2414 signalIds [Widget.MNEMONIC_ACTIVATE] = OS.g_signal_lookup (OS.mnemonic_activate.ptr, OS.GTK_TYPE_WIDGET ()); | |
2415 signalIds [Widget.MOTION_NOTIFY_EVENT] = OS.g_signal_lookup (OS.motion_notify_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2416 signalIds [Widget.POPUP_MENU] = OS.g_signal_lookup (OS.popup_menu.ptr, OS.GTK_TYPE_WIDGET ()); | |
2417 signalIds [Widget.REALIZE] = OS.g_signal_lookup (OS.realize.ptr, OS.GTK_TYPE_WIDGET ()); | |
2418 signalIds [Widget.SCROLL_EVENT] = OS.g_signal_lookup (OS.scroll_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2419 signalIds [Widget.SHOW] = OS.g_signal_lookup (OS.show.ptr, OS.GTK_TYPE_WIDGET ()); | |
2420 signalIds [Widget.SHOW_HELP] = OS.g_signal_lookup (OS.show_help.ptr, OS.GTK_TYPE_WIDGET ()); | |
2421 signalIds [Widget.SIZE_ALLOCATE] = OS.g_signal_lookup (OS.size_allocate.ptr, OS.GTK_TYPE_WIDGET ()); | |
2422 signalIds [Widget.STYLE_SET] = OS.g_signal_lookup (OS.style_set.ptr, OS.GTK_TYPE_WIDGET ()); | |
2423 signalIds [Widget.UNMAP] = OS.g_signal_lookup (OS.unmap.ptr, OS.GTK_TYPE_WIDGET ()); | |
2424 signalIds [Widget.UNMAP_EVENT] = OS.g_signal_lookup (OS.unmap_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2425 signalIds [Widget.UNREALIZE] = OS.g_signal_lookup (OS.realize.ptr, OS.GTK_TYPE_WIDGET ()); | |
2426 signalIds [Widget.VISIBILITY_NOTIFY_EVENT] = OS.g_signal_lookup (OS.visibility_notify_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2427 signalIds [Widget.WINDOW_STATE_EVENT] = OS.g_signal_lookup (OS.window_state_event.ptr, OS.GTK_TYPE_WIDGET ()); | |
2428 | |
2429 GClosure* do_cclosure_new( GCallback cb, int value, int notify ){ | |
2430 CallbackData* res= new CallbackData; | |
2431 res.display = this; | |
2432 res.data = cast(void*)value; | |
2433 windowProcCallbackDatas[ value ] = res; | |
2434 return OS.g_cclosure_new( cb, cast(void*)res, cast(GClosureNotify)notify ); | |
2435 } | |
2436 | |
2437 GCallback windowProc2 = cast(GCallback)&windowProcFunc2; | |
2438 closures [Widget.ACTIVATE] = do_cclosure_new (windowProc2, Widget.ACTIVATE, 0); | |
2439 closures [Widget.ACTIVATE_INVERSE] = do_cclosure_new (windowProc2, Widget.ACTIVATE_INVERSE, 0); | |
2440 closures [Widget.CHANGED] = do_cclosure_new (windowProc2, Widget.CHANGED, 0); | |
2441 closures [Widget.CLICKED] = do_cclosure_new (windowProc2, Widget.CLICKED, 0); | |
2442 closures [Widget.DAY_SELECTED] = do_cclosure_new (windowProc2, Widget.DAY_SELECTED, 0); | |
2443 closures [Widget.HIDE] = do_cclosure_new (windowProc2, Widget.HIDE, 0); | |
2444 closures [Widget.GRAB_FOCUS] = do_cclosure_new (windowProc2, Widget.GRAB_FOCUS, 0); | |
2445 closures [Widget.MAP] = do_cclosure_new (windowProc2, Widget.MAP, 0); | |
2446 closures [Widget.MONTH_CHANGED] = do_cclosure_new (windowProc2, Widget.MONTH_CHANGED, 0); | |
2447 closures [Widget.OUTPUT] = do_cclosure_new (windowProc2, Widget.OUTPUT, 0); | |
2448 closures [Widget.POPUP_MENU] = do_cclosure_new (windowProc2, Widget.POPUP_MENU, 0); | |
2449 closures [Widget.PREEDIT_CHANGED] = do_cclosure_new (windowProc2, Widget.PREEDIT_CHANGED, 0); | |
2450 closures [Widget.REALIZE] = do_cclosure_new (windowProc2, Widget.REALIZE, 0); | |
2451 closures [Widget.SELECT] = do_cclosure_new (windowProc2, Widget.SELECT, 0); | |
2452 closures [Widget.SHOW] = do_cclosure_new (windowProc2, Widget.SHOW, 0); | |
2453 closures [Widget.VALUE_CHANGED] = do_cclosure_new (windowProc2, Widget.VALUE_CHANGED, 0); | |
2454 closures [Widget.UNMAP] = do_cclosure_new (windowProc2, Widget.UNMAP, 0); | |
2455 closures [Widget.UNREALIZE] = do_cclosure_new (windowProc2, Widget.UNREALIZE, 0); | |
2456 | |
2457 GCallback windowProc3 = cast(GCallback)&windowProcFunc3; | |
2458 closures [Widget.BUTTON_PRESS_EVENT] = do_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT, 0); | |
2459 closures [Widget.BUTTON_PRESS_EVENT_INVERSE] = do_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT_INVERSE, 0); | |
2460 closures [Widget.BUTTON_RELEASE_EVENT] = do_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT, 0); | |
2461 closures [Widget.BUTTON_RELEASE_EVENT_INVERSE] = do_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT_INVERSE, 0); | |
2462 closures [Widget.COMMIT] = do_cclosure_new (windowProc3, Widget.COMMIT, 0); | |
2463 closures [Widget.CONFIGURE_EVENT] = do_cclosure_new (windowProc3, Widget.CONFIGURE_EVENT, 0); | |
2464 closures [Widget.DELETE_EVENT] = do_cclosure_new (windowProc3, Widget.DELETE_EVENT, 0); | |
2465 closures [Widget.ENTER_NOTIFY_EVENT] = do_cclosure_new (windowProc3, Widget.ENTER_NOTIFY_EVENT, 0); | |
2466 closures [Widget.EVENT] = do_cclosure_new (windowProc3, Widget.EVENT, 0); | |
2467 closures [Widget.EVENT_AFTER] = do_cclosure_new (windowProc3, Widget.EVENT_AFTER, 0); | |
2468 closures [Widget.EXPOSE_EVENT] = do_cclosure_new (windowProc3, Widget.EXPOSE_EVENT, 0); | |
2469 closures [Widget.EXPOSE_EVENT_INVERSE] = do_cclosure_new (windowProc3, Widget.EXPOSE_EVENT_INVERSE, 0); | |
2470 closures [Widget.FOCUS] = do_cclosure_new (windowProc3, Widget.FOCUS, 0); | |
2471 closures [Widget.FOCUS_IN_EVENT] = do_cclosure_new (windowProc3, Widget.FOCUS_IN_EVENT, 0); | |
2472 closures [Widget.FOCUS_OUT_EVENT] = do_cclosure_new (windowProc3, Widget.FOCUS_OUT_EVENT, 0); | |
2473 closures [Widget.KEY_PRESS_EVENT] = do_cclosure_new (windowProc3, Widget.KEY_PRESS_EVENT, 0); | |
2474 closures [Widget.KEY_RELEASE_EVENT] = do_cclosure_new (windowProc3, Widget.KEY_RELEASE_EVENT, 0); | |
2475 closures [Widget.INPUT] = do_cclosure_new (windowProc3, Widget.INPUT, 0); | |
2476 closures [Widget.LEAVE_NOTIFY_EVENT] = do_cclosure_new (windowProc3, Widget.LEAVE_NOTIFY_EVENT, 0); | |
2477 closures [Widget.MAP_EVENT] = do_cclosure_new (windowProc3, Widget.MAP_EVENT, 0); | |
2478 closures [Widget.MNEMONIC_ACTIVATE] = do_cclosure_new (windowProc3, Widget.MNEMONIC_ACTIVATE, 0); | |
2479 closures [Widget.MOTION_NOTIFY_EVENT] = do_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT, 0); | |
2480 closures [Widget.MOTION_NOTIFY_EVENT_INVERSE] = do_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT_INVERSE, 0); | |
2481 closures [Widget.MOVE_FOCUS] = do_cclosure_new (windowProc3, Widget.MOVE_FOCUS, 0); | |
2482 closures [Widget.POPULATE_POPUP] = do_cclosure_new (windowProc3, Widget.POPULATE_POPUP, 0); | |
2483 closures [Widget.SCROLL_EVENT] = do_cclosure_new (windowProc3, Widget.SCROLL_EVENT, 0); | |
2484 closures [Widget.SHOW_HELP] = do_cclosure_new (windowProc3, Widget.SHOW_HELP, 0); | |
2485 closures [Widget.SIZE_ALLOCATE] = do_cclosure_new (windowProc3, Widget.SIZE_ALLOCATE, 0); | |
2486 closures [Widget.STYLE_SET] = do_cclosure_new (windowProc3, Widget.STYLE_SET, 0); | |
2487 closures [Widget.TOGGLED] = do_cclosure_new (windowProc3, Widget.TOGGLED, 0); | |
2488 closures [Widget.UNMAP_EVENT] = do_cclosure_new (windowProc3, Widget.UNMAP_EVENT, 0); | |
2489 closures [Widget.VISIBILITY_NOTIFY_EVENT] = do_cclosure_new (windowProc3, Widget.VISIBILITY_NOTIFY_EVENT, 0); | |
2490 closures [Widget.WINDOW_STATE_EVENT] = do_cclosure_new (windowProc3, Widget.WINDOW_STATE_EVENT, 0); | |
2491 | |
2492 GCallback windowProc4 = cast(GCallback)&windowProcFunc4; | |
2493 closures [Widget.DELETE_RANGE] = do_cclosure_new (windowProc4, Widget.DELETE_RANGE, 0); | |
2494 closures [Widget.DELETE_TEXT] = do_cclosure_new (windowProc4, Widget.DELETE_TEXT, 0); | |
2495 closures [Widget.ROW_ACTIVATED] = do_cclosure_new (windowProc4, Widget.ROW_ACTIVATED, 0); | |
2496 closures [Widget.SCROLL_CHILD] = do_cclosure_new (windowProc4, Widget.SCROLL_CHILD, 0); | |
2497 closures [Widget.SWITCH_PAGE] = do_cclosure_new (windowProc4, Widget.SWITCH_PAGE, 0); | |
2498 closures [Widget.TEST_COLLAPSE_ROW] = do_cclosure_new (windowProc4, Widget.TEST_COLLAPSE_ROW, 0); | |
2499 closures [Widget.TEST_EXPAND_ROW] = do_cclosure_new (windowProc4, Widget.TEST_EXPAND_ROW, 0); | |
2500 | |
2501 GCallback windowProc5 = cast(GCallback)&windowProcFunc5; | |
2502 closures [Widget.CHANGE_VALUE] = do_cclosure_new (windowProc5, Widget.CHANGE_VALUE, 0); | |
2503 closures [Widget.EXPAND_COLLAPSE_CURSOR_ROW] = do_cclosure_new (windowProc5, Widget.EXPAND_COLLAPSE_CURSOR_ROW, 0); | |
2504 closures [Widget.INSERT_TEXT] = do_cclosure_new (windowProc5, Widget.INSERT_TEXT, 0); | |
2505 closures [Widget.TEXT_BUFFER_INSERT_TEXT] = do_cclosure_new (windowProc5, Widget.TEXT_BUFFER_INSERT_TEXT, 0); | |
2506 | |
2507 for (int i = 0; i < Widget.LAST_SIGNAL; i++) { | |
2508 if (closures [i] !is null) OS.g_closure_ref (closures [i]); | |
2509 } | |
2510 shellMapProcCallbackData.display = this; | |
2511 shellMapProcCallbackData.data = null; | |
2512 shellMapProcClosure = OS.g_cclosure_new (cast(GCallback)&shellMapProcFunc, &shellMapProcCallbackData, cast(GClosureNotify)0); | |
2513 OS.g_closure_ref (shellMapProcClosure); | |
2514 } | |
2515 | |
2516 void* getWindowProcUserData( int value ){ | |
2517 return windowProcCallbackDatas[ value ]; | |
2518 | |
2519 } | |
2520 | |
2521 void initializeSystemSettings () { | |
2522 styleSetProcCallbackData.display = this; | |
2523 styleSetProcCallbackData.data = null; | |
2524 OS.g_signal_connect (shellHandle, OS.style_set.ptr, cast(GCallback)&styleSetProcFunc, &styleSetProcCallbackData); | |
2525 | |
2526 /* | |
2527 * Feature in GTK. Despite the fact that the | |
2528 * gtk-entry-select-on-focus property is a global | |
2529 * setting, it is initialized when the GtkEntry | |
2530 * is initialized. This means that it cannot be | |
2531 * accessed before a GtkEntry is created. The | |
2532 * fix is to for the initializaion by creating | |
2533 * a temporary GtkEntry. | |
2534 */ | |
2535 auto entry = OS.gtk_entry_new (); | |
2536 OS.gtk_widget_destroy (entry); | |
2537 int buffer2; | |
2538 auto settings = OS.gtk_settings_get_default (); | |
2539 OS.g_object_get1 (settings, OS.gtk_entry_select_on_focus.ptr, &buffer2); | |
2540 entrySelectOnFocus = buffer2 !is 0; | |
2541 } | |
2542 | |
2543 void initializeWidgetTable () { | |
2544 indexTable = new int [GROW_SIZE]; | |
2545 widgetTable = new Widget [GROW_SIZE]; | |
2546 for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1; | |
2547 indexTable [GROW_SIZE - 1] = -1; | |
2548 } | |
2549 | |
2550 void initializeWindowManager () { | |
2551 /* Get the window manager name */ | |
2552 windowManager = ""; //$NON-NLS-1$ | |
2553 if (OS.GTK_VERSION >= OS.buildVERSION (2, 2, 0)) { | |
2554 auto screen = OS.gdk_screen_get_default (); | |
2555 if (screen !is null) { | |
2556 auto ptr2 = OS.gdk_x11_screen_get_window_manager_name (screen); | |
51 | 2557 windowManager = fromStringz( ptr2 )._idup(); |
25 | 2558 } |
2559 } | |
2560 } | |
2561 | |
2562 /** | |
2563 * Invokes platform specific functionality to dispose a GC handle. | |
2564 * <p> | |
2565 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
2566 * API for <code>Display</code>. It is marked public only so that it | |
2567 * can be shared within the packages provided by SWT. It is not | |
2568 * available on all platforms, and should never be called from | |
2569 * application code. | |
2570 * </p> | |
2571 * | |
2572 * @param hDC the platform specific GC handle | |
2573 * @param data the platform specific GC data | |
2574 */ | |
2575 public override void internal_dispose_GC (GdkGC* gdkGC, GCData data) { | |
2576 OS.g_object_unref (gdkGC); | |
2577 } | |
2578 | |
2579 /** | |
2580 * Invokes platform specific functionality to allocate a new GC handle. | |
2581 * <p> | |
2582 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
2583 * API for <code>Display</code>. It is marked public only so that it | |
2584 * can be shared within the packages provided by SWT. It is not | |
2585 * available on all platforms, and should never be called from | |
2586 * application code. | |
2587 * </p> | |
2588 * | |
2589 * @param data the platform specific GC data | |
2590 * @return the platform specific GC handle | |
2591 * | |
2592 * @exception SWTException <ul> | |
2593 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2594 * </ul> | |
2595 * @exception SWTError <ul> | |
2596 * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li> | |
2597 * </ul> | |
2598 */ | |
2599 public override GdkGC* internal_new_GC (GCData data) { | |
2600 if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED); | |
2601 auto root = cast(GdkDrawable *) OS.GDK_ROOT_PARENT (); | |
2602 auto gdkGC = OS.gdk_gc_new (root); | |
2603 if (gdkGC is null) SWT.error (SWT.ERROR_NO_HANDLES); | |
2604 OS.gdk_gc_set_subwindow (gdkGC, OS.GDK_INCLUDE_INFERIORS); | |
2605 if (data !is null) { | |
2606 int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; | |
2607 if ((data.style & mask) is 0) { | |
2608 data.style |= SWT.LEFT_TO_RIGHT; | |
2609 } | |
2610 data.device = this; | |
2611 data.drawable = root; | |
2612 data.background = getSystemColor (SWT.COLOR_WHITE).handle; | |
2613 data.foreground = getSystemColor (SWT.COLOR_BLACK).handle; | |
2614 data.font = getSystemFont (); | |
2615 } | |
2616 return gdkGC; | |
2617 return null; | |
2618 } | |
2619 | |
2620 bool isValidThread () { | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
2621 return thread is Thread.currentThread (); |
25 | 2622 } |
2623 | |
2624 /** | |
2625 * Maps a point from one coordinate system to another. | |
2626 * When the control is null, coordinates are mapped to | |
2627 * the display. | |
2628 * <p> | |
2629 * NOTE: On right-to-left platforms where the coordinate | |
2630 * systems are mirrored, special care needs to be taken | |
2631 * when mapping coordinates from one control to another | |
2632 * to ensure the result is correctly mirrored. | |
2633 * | |
2634 * Mapping a point that is the origin of a rectangle and | |
2635 * then adding the width and height is not equivalent to | |
2636 * mapping the rectangle. When one control is mirrored | |
2637 * and the other is not, adding the width and height to a | |
2638 * point that was mapped causes the rectangle to extend | |
2639 * in the wrong direction. Mapping the entire rectangle | |
2640 * instead of just one point causes both the origin and | |
2641 * the corner of the rectangle to be mapped. | |
2642 * </p> | |
2643 * | |
2644 * @param from the source <code>Control</code> or <code>null</code> | |
2645 * @param to the destination <code>Control</code> or <code>null</code> | |
2646 * @param point to be mapped | |
2647 * @return point with mapped coordinates | |
2648 * | |
2649 * @exception IllegalArgumentException <ul> | |
2650 * <li>ERROR_NULL_ARGUMENT - if the point is null</li> | |
2651 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> | |
2652 * </ul> | |
2653 * @exception SWTException <ul> | |
2654 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2655 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2656 * </ul> | |
2657 * | |
2658 * @since 2.1.2 | |
2659 */ | |
2660 public Point map (Control from, Control to, Point point) { | |
2661 checkDevice (); | |
2662 if (point is null) error (SWT.ERROR_NULL_ARGUMENT); | |
2663 return map (from, to, point.x, point.y); | |
2664 } | |
2665 | |
2666 /** | |
2667 * Maps a point from one coordinate system to another. | |
2668 * When the control is null, coordinates are mapped to | |
2669 * the display. | |
2670 * <p> | |
2671 * NOTE: On right-to-left platforms where the coordinate | |
2672 * systems are mirrored, special care needs to be taken | |
2673 * when mapping coordinates from one control to another | |
2674 * to ensure the result is correctly mirrored. | |
2675 * | |
2676 * Mapping a point that is the origin of a rectangle and | |
2677 * then adding the width and height is not equivalent to | |
2678 * mapping the rectangle. When one control is mirrored | |
2679 * and the other is not, adding the width and height to a | |
2680 * point that was mapped causes the rectangle to extend | |
2681 * in the wrong direction. Mapping the entire rectangle | |
2682 * instead of just one point causes both the origin and | |
2683 * the corner of the rectangle to be mapped. | |
2684 * </p> | |
2685 * | |
2686 * @param from the source <code>Control</code> or <code>null</code> | |
2687 * @param to the destination <code>Control</code> or <code>null</code> | |
2688 * @param x coordinates to be mapped | |
2689 * @param y coordinates to be mapped | |
2690 * @return point with mapped coordinates | |
2691 * | |
2692 * @exception IllegalArgumentException <ul> | |
2693 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> | |
2694 * </ul> | |
2695 * @exception SWTException <ul> | |
2696 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2697 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2698 * </ul> | |
2699 * | |
2700 * @since 2.1.2 | |
2701 */ | |
2702 public Point map (Control from, Control to, int x, int y) { | |
2703 checkDevice (); | |
2704 if (from !is null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); | |
2705 if (to !is null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); | |
2706 Point point = new Point (x, y); | |
2707 if (from is to) return point; | |
2708 if (from !is null) { | |
2709 auto window = from.eventWindow (); | |
2710 int origin_x, origin_y; | |
2711 OS.gdk_window_get_origin (window, &origin_x, &origin_y); | |
2712 if ((from.style & SWT.MIRRORED) !is 0) point.x = from.getClientWidth () - point.x; | |
2713 point.x += origin_x; | |
2714 point.y += origin_y; | |
2715 } | |
2716 if (to !is null) { | |
2717 auto window = to.eventWindow (); | |
2718 int origin_x, origin_y; | |
2719 OS.gdk_window_get_origin (window, &origin_x, &origin_y); | |
2720 point.x -= origin_x; | |
2721 point.y -= origin_y; | |
2722 if ((to.style & SWT.MIRRORED) !is 0) point.x = to.getClientWidth () - point.x; | |
2723 } | |
2724 return point; | |
2725 } | |
2726 | |
2727 /** | |
2728 * Maps a point from one coordinate system to another. | |
2729 * When the control is null, coordinates are mapped to | |
2730 * the display. | |
2731 * <p> | |
2732 * NOTE: On right-to-left platforms where the coordinate | |
2733 * systems are mirrored, special care needs to be taken | |
2734 * when mapping coordinates from one control to another | |
2735 * to ensure the result is correctly mirrored. | |
2736 * | |
2737 * Mapping a point that is the origin of a rectangle and | |
2738 * then adding the width and height is not equivalent to | |
2739 * mapping the rectangle. When one control is mirrored | |
2740 * and the other is not, adding the width and height to a | |
2741 * point that was mapped causes the rectangle to extend | |
2742 * in the wrong direction. Mapping the entire rectangle | |
2743 * instead of just one point causes both the origin and | |
2744 * the corner of the rectangle to be mapped. | |
2745 * </p> | |
2746 * | |
2747 * @param from the source <code>Control</code> or <code>null</code> | |
2748 * @param to the destination <code>Control</code> or <code>null</code> | |
2749 * @param rectangle to be mapped | |
2750 * @return rectangle with mapped coordinates | |
2751 * | |
2752 * @exception IllegalArgumentException <ul> | |
2753 * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> | |
2754 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> | |
2755 * </ul> | |
2756 * @exception SWTException <ul> | |
2757 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2758 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2759 * </ul> | |
2760 * | |
2761 * @since 2.1.2 | |
2762 */ | |
2763 public Rectangle map (Control from, Control to, Rectangle rectangle) { | |
2764 checkDevice(); | |
2765 if (rectangle is null) error (SWT.ERROR_NULL_ARGUMENT); | |
2766 return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height); | |
2767 } | |
2768 | |
2769 static wchar mbcsToWcs (wchar ch) { | |
2770 int key = ch & 0xFFFF; | |
2771 if (key <= 0x7F) return ch; | |
2772 char [] buffer; | |
2773 if (key <= 0xFF) { | |
2774 buffer = new char [1]; | |
2775 buffer [0] = cast(char) key; | |
2776 } else { | |
2777 buffer = new char [2]; | |
2778 buffer [0] = cast(char) ((key >> 8) & 0xFF); | |
2779 buffer [1] = cast(char) (key & 0xFF); | |
2780 } | |
2781 wchar [] result = Converter.mbcsToWcs (null, buffer); | |
2782 if (result.length is 0) return 0; | |
2783 return result [0]; | |
2784 } | |
2785 | |
2786 | |
2787 package void doMenuPositionProc( GtkMenu* window, bool hasLocation ){ | |
2788 /* | |
2789 * Bug in GTK. The timestamp passed into gtk_menu_popup is used | |
2790 * to perform an X pointer grab. It cannot be zero, else the grab | |
2791 * will fail. The fix is to ensure that the timestamp of the last | |
2792 * event processed is used. | |
2793 */ | |
2794 OS.gtk_menu_popup (window, null, null, | |
2795 hasLocation ? &menuPositionProcFunc : null, | |
2796 cast(void*)this, 0, getLastEventTime() ); | |
2797 } | |
2798 | |
2799 private static extern(C) void menuPositionProcFunc (GtkMenu* menu, int* x, int* y, int* push_in, void* user_data) { | |
2800 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
2801 auto display = cast(Display)user_data; | |
2802 display.menuPositionProc( menu, x, y, push_in, null ); | |
2803 } | |
2804 | |
2805 void menuPositionProc (GtkMenu* menu, int* x, int* y, int* push_in, void* user_data) { | |
2806 Widget widget = getWidget (cast(GtkWidget*)menu); | |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
51
diff
changeset
|
2807 if (widget is null) return; |
25 | 2808 widget.menuPositionProc (menu, x, y, push_in, user_data); |
2809 } | |
2810 | |
2811 /** | |
2812 * Maps a point from one coordinate system to another. | |
2813 * When the control is null, coordinates are mapped to | |
2814 * the display. | |
2815 * <p> | |
2816 * NOTE: On right-to-left platforms where the coordinate | |
2817 * systems are mirrored, special care needs to be taken | |
2818 * when mapping coordinates from one control to another | |
2819 * to ensure the result is correctly mirrored. | |
2820 * | |
2821 * Mapping a point that is the origin of a rectangle and | |
2822 * then adding the width and height is not equivalent to | |
2823 * mapping the rectangle. When one control is mirrored | |
2824 * and the other is not, adding the width and height to a | |
2825 * point that was mapped causes the rectangle to extend | |
2826 * in the wrong direction. Mapping the entire rectangle | |
2827 * instead of just one point causes both the origin and | |
2828 * the corner of the rectangle to be mapped. | |
2829 * </p> | |
2830 * | |
2831 * @param from the source <code>Control</code> or <code>null</code> | |
2832 * @param to the destination <code>Control</code> or <code>null</code> | |
2833 * @param x coordinates to be mapped | |
2834 * @param y coordinates to be mapped | |
2835 * @param width coordinates to be mapped | |
2836 * @param height coordinates to be mapped | |
2837 * @return rectangle with mapped coordinates | |
2838 * | |
2839 * @exception IllegalArgumentException <ul> | |
2840 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> | |
2841 * </ul> | |
2842 * @exception SWTException <ul> | |
2843 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2844 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2845 * </ul> | |
2846 * | |
2847 * @since 2.1.2 | |
2848 */ | |
2849 public Rectangle map (Control from, Control to, int x, int y, int width, int height) { | |
2850 checkDevice(); | |
2851 if (from !is null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); | |
2852 if (to !is null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); | |
2853 Rectangle rect = new Rectangle (x, y, width, height); | |
2854 if (from is to) return rect; | |
2855 bool fromRTL = false, toRTL = false; | |
2856 if (from !is null) { | |
2857 auto window = from.eventWindow (); | |
2858 int origin_x, origin_y; | |
2859 OS.gdk_window_get_origin (window, &origin_x, &origin_y); | |
2860 fromRTL = (from.style & SWT.MIRRORED) !is 0; | |
2861 if (fromRTL) rect.x = from.getClientWidth() - rect.x; | |
2862 rect.x += origin_x; | |
2863 rect.y += origin_y; | |
2864 } | |
2865 if (to !is null) { | |
2866 auto window = to.eventWindow (); | |
2867 int origin_x, origin_y; | |
2868 OS.gdk_window_get_origin (window, &origin_x, &origin_y); | |
2869 rect.x -= origin_x; | |
2870 rect.y -= origin_y; | |
2871 toRTL = (to.style & SWT.MIRRORED) !is 0; | |
2872 if (toRTL) rect.x = to.getClientWidth () - rect.x; | |
2873 } | |
2874 if (fromRTL !is toRTL) rect.x -= rect.width; | |
2875 return rect; | |
2876 } | |
2877 | |
2878 private static extern(C) int /*long*/ mouseHoverProcFunc ( void* user_data) { | |
2879 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
2880 CallbackData* cbdata = cast(CallbackData*)user_data; | |
2881 return cbdata.display.mouseHoverProc( cast(GtkWidget*)cbdata.data ); | |
2882 } | |
2883 int /*long*/ mouseHoverProc (GtkWidget* handle) { | |
2884 Widget widget = getWidget (handle); | |
2885 if (widget is null) return 0; | |
2886 return widget.hoverProc (handle); | |
2887 } | |
2888 | |
2889 /** | |
2890 * Generate a low level system event. | |
2891 * | |
2892 * <code>post</code> is used to generate low level keyboard | |
2893 * and mouse events. The intent is to enable automated UI | |
2894 * testing by simulating the input from the user. Most | |
2895 * SWT applications should never need to call this method. | |
2896 * <p> | |
2897 * Note that this operation can fail when the operating system | |
2898 * fails to generate the event for any reason. For example, | |
2899 * this can happen when there is no such key or mouse button | |
2900 * or when the system event queue is full. | |
2901 * </p> | |
2902 * <p> | |
2903 * <b>Event Types:</b> | |
2904 * <p>KeyDown, KeyUp | |
2905 * <p>The following fields in the <code>Event</code> apply: | |
2906 * <ul> | |
2907 * <li>(in) type KeyDown or KeyUp</li> | |
2908 * <p> Either one of: | |
2909 * <li>(in) character a character that corresponds to a keyboard key</li> | |
2910 * <li>(in) keyCode the key code of the key that was typed, | |
2911 * as defined by the key code constants in class <code>SWT</code></li> | |
2912 * </ul> | |
2913 * <p>MouseDown, MouseUp</p> | |
2914 * <p>The following fields in the <code>Event</code> apply: | |
2915 * <ul> | |
2916 * <li>(in) type MouseDown or MouseUp | |
2917 * <li>(in) button the button that is pressed or released | |
2918 * </ul> | |
2919 * <p>MouseMove</p> | |
2920 * <p>The following fields in the <code>Event</code> apply: | |
2921 * <ul> | |
2922 * <li>(in) type MouseMove | |
2923 * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates | |
2924 * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates | |
2925 * </ul> | |
2926 * </dl> | |
2927 * | |
2928 * @param event the event to be generated | |
2929 * | |
2930 * @return true if the event was generated or false otherwise | |
2931 * | |
2932 * @exception IllegalArgumentException <ul> | |
2933 * <li>ERROR_NULL_ARGUMENT - if the event is null</li> | |
2934 * </ul> | |
2935 * @exception SWTException <ul> | |
2936 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
2937 * </ul> | |
2938 * | |
2939 * @since 3.0 | |
2940 * | |
2941 */ | |
2942 public bool post (Event event) { | |
2943 synchronized (Device.classinfo) { | |
2944 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
2945 if (event is null) error (SWT.ERROR_NULL_ARGUMENT); | |
2946 if (!OS.GDK_WINDOWING_X11()) return false; | |
2947 auto xDisplay = OS.GDK_DISPLAY (); | |
2948 int type = event.type; | |
2949 switch (type) { | |
2950 case SWT.KeyDown: | |
2951 case SWT.KeyUp: { | |
2952 int keyCode = 0; | |
2953 auto keysym = untranslateKey (event.keyCode); | |
2954 if (keysym !is 0) keyCode = OS.XKeysymToKeycode (xDisplay, keysym); | |
2955 if (keyCode is 0) { | |
113
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
2956 char key = cast(char) event.character; |
25 | 2957 switch (key) { |
2958 case SWT.BS: keysym = OS.GDK_BackSpace; break; | |
2959 case SWT.CR: keysym = OS.GDK_Return; break; | |
2960 case SWT.DEL: keysym = OS.GDK_Delete; break; | |
2961 case SWT.ESC: keysym = OS.GDK_Escape; break; | |
2962 case SWT.TAB: keysym = OS.GDK_Tab; break; | |
2963 case SWT.LF: keysym = OS.GDK_Linefeed; break; | |
2964 default: | |
2965 keysym = key; | |
2966 } | |
2967 keyCode = OS.XKeysymToKeycode (xDisplay, keysym); | |
2968 if (keyCode is 0) return false; | |
2969 } | |
2970 OS.XTestFakeKeyEvent (xDisplay, keyCode, type is SWT.KeyDown, 0); | |
2971 return true; | |
2972 } | |
2973 case SWT.MouseDown: | |
2974 case SWT.MouseMove: | |
2975 case SWT.MouseUp: { | |
2976 if (type is SWT.MouseMove) { | |
2977 OS.XTestFakeMotionEvent (xDisplay, -1, event.x, event.y, 0); | |
2978 } else { | |
2979 int button = event.button; | |
2980 switch (button) { | |
2981 case 1: | |
2982 case 2: | |
2983 case 3: break; | |
2984 case 4: button = 6; break; | |
2985 case 5: button = 7; break; | |
2986 default: return false; | |
2987 } | |
2988 OS.XTestFakeButtonEvent (xDisplay, button, type is SWT.MouseDown, 0); | |
2989 } | |
2990 return true; | |
2991 default: | |
2992 } | |
2993 /* | |
2994 * This code is intentionally commented. After posting a | |
2995 * mouse wheel event the system may respond unpredictably | |
2996 * to subsequent mouse actions. | |
2997 */ | |
2998 // case SWT.MouseWheel: { | |
2999 // if (event.count is 0) return false; | |
3000 // int button = event.count < 0 ? 5 : 4; | |
3001 // OS.XTestFakeButtonEvent (xDisplay, button, type is SWT.MouseWheel, 0); | |
3002 // } | |
3003 } | |
3004 return false; | |
3005 } | |
3006 } | |
3007 | |
3008 void postEvent (Event event) { | |
3009 /* | |
3010 * Place the event at the end of the event queue. | |
3011 * This code is always called in the Display's | |
3012 * thread so it must be re-enterant but does not | |
3013 * need to be synchronized. | |
3014 */ | |
3015 if (eventQueue is null) eventQueue = new Event [4]; | |
3016 int index = 0; | |
3017 int length = eventQueue.length; | |
3018 while (index < length) { | |
3019 if (eventQueue [index] is null) break; | |
3020 index++; | |
3021 } | |
3022 if (index is length) { | |
3023 Event [] newQueue = new Event [length + 4]; | |
3024 System.arraycopy (eventQueue, 0, newQueue, 0, length); | |
3025 eventQueue = newQueue; | |
3026 } | |
3027 eventQueue [index] = event; | |
3028 } | |
3029 | |
3030 void putGdkEvents () { | |
3031 if (gdkEventCount !is 0) { | |
3032 for (int i = 0; i < gdkEventCount; i++) { | |
3033 auto event = gdkEvents [i]; | |
3034 Widget widget = gdkEventWidgets [i]; | |
3035 if (widget is null || !widget.isDisposed ()) { | |
3036 OS.gdk_event_put (event); | |
3037 } | |
3038 OS.gdk_event_free (event); | |
3039 gdkEvents [i] = null; | |
3040 gdkEventWidgets [i] = null; | |
3041 } | |
3042 gdkEventCount = 0; | |
3043 } | |
3044 } | |
3045 | |
3046 /** | |
3047 * Reads an event from the operating system's event queue, | |
3048 * dispatches it appropriately, and returns <code>true</code> | |
3049 * if there is potentially more work to do, or <code>false</code> | |
3050 * if the caller can sleep until another event is placed on | |
3051 * the event queue. | |
3052 * <p> | |
3053 * In addition to checking the system event queue, this method also | |
3054 * checks if any inter-thread messages (created by <code>syncExec()</code> | |
3055 * or <code>asyncExec()</code>) are waiting to be processed, and if | |
3056 * so handles them before returning. | |
3057 * </p> | |
3058 * | |
3059 * @return <code>false</code> if the caller can sleep upon return from this method | |
3060 * | |
3061 * @exception SWTException <ul> | |
3062 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3063 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3064 * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li> | |
3065 * </ul> | |
3066 * | |
3067 * @see #sleep | |
3068 * @see #wake | |
3069 */ | |
3070 public bool readAndDispatch () { | |
3071 checkDevice (); | |
3072 bool events = false; | |
3073 events |= runSettings (); | |
3074 events |= runPopups (); | |
3075 events |= cast(bool)OS.g_main_context_iteration (null, false); | |
3076 if (events) { | |
3077 runDeferredEvents (); | |
3078 return true; | |
3079 } | |
3080 return runAsyncMessages (false); | |
3081 } | |
3082 | |
3083 static void register (Display display) { | |
3084 synchronized (Device.classinfo) { | |
3085 for (int i=0; i<Displays.length; i++) { | |
3086 if (Displays [i] is null) { | |
3087 Displays [i] = display; | |
3088 return; | |
3089 } | |
3090 } | |
3091 Display [] newDisplays = new Display [Displays.length + 4]; | |
3092 System.arraycopy (Displays, 0, newDisplays, 0, Displays.length); | |
3093 newDisplays [Displays.length] = display; | |
3094 Displays = newDisplays; | |
3095 } | |
3096 } | |
3097 | |
3098 /** | |
3099 * Releases any internal resources back to the operating | |
3100 * system and clears all fields except the device handle. | |
3101 * <p> | |
3102 * Disposes all shells which are currently open on the display. | |
3103 * After this method has been invoked, all related related shells | |
3104 * will answer <code>true</code> when sent the message | |
3105 * <code>isDisposed()</code>. | |
3106 * </p><p> | |
3107 * When a device is destroyed, resources that were acquired | |
3108 * on behalf of the programmer need to be returned to the | |
3109 * operating system. For example, if the device allocated a | |
3110 * font to be used as the system font, this font would be | |
3111 * freed in <code>release</code>. Also,to assist the garbage | |
3112 * collector and minimize the amount of memory that is not | |
3113 * reclaimed when the programmer keeps a reference to a | |
3114 * disposed device, all fields except the handle are zero'd. | |
3115 * The handle is needed by <code>destroy</code>. | |
3116 * </p> | |
3117 * This method is called before <code>destroy</code>. | |
3118 * | |
3119 * @see Device#dispose | |
3120 * @see #destroy | |
3121 */ | |
3122 protected override void release () { | |
3123 sendEvent (SWT.Dispose, new Event ()); | |
3124 Shell [] shells = getShells (); | |
3125 for (int i=0; i<shells.length; i++) { | |
3126 Shell shell = shells [i]; | |
3127 if (!shell.isDisposed ()) shell.dispose (); | |
3128 } | |
3129 if (tray !is null) tray.dispose (); | |
3130 tray = null; | |
3131 while (readAndDispatch ()) {} | |
3132 if (disposeList !is null) { | |
3133 for (int i=0; i<disposeList.length; i++) { | |
3134 if (disposeList [i] !is null) disposeList [i].run (); | |
3135 } | |
3136 } | |
3137 disposeList = null; | |
3138 synchronizer.releaseSynchronizer (); | |
3139 synchronizer = null; | |
3140 releaseDisplay (); | |
3141 super.release (); | |
3142 } | |
3143 | |
3144 void releaseDisplay () { | |
3145 | |
3146 /* Dispose xfilter callback */ | |
3147 OS.gdk_window_remove_filter(null, &filterProcFunc, null); | |
3148 | |
3149 /* Dispose checkIfEvent callback */ | |
3150 | |
3151 /* Dispose preedit window */ | |
3152 if (preeditWindow !is null) OS.gtk_widget_destroy ( &preeditWindow.bin.container.widget); | |
3153 imControl = null; | |
3154 | |
3155 /* Dispose the menu callback */ | |
3156 | |
3157 /* Dispose the tooltip map callback */ | |
3158 | |
3159 /* Dispose the shell map callback */ | |
3160 | |
3161 /* Dispose the run async messages callback */ | |
3162 if (idleHandle !is 0) OS.g_source_remove (idleHandle); | |
3163 idleHandle = 0; | |
3164 | |
3165 /* Dispose GtkTreeView callbacks */ | |
3166 | |
3167 /* Dispose the set direction callback */ | |
3168 | |
3169 /* Dispose the emission proc callback */ | |
3170 | |
3171 /* Dispose the set direction callback */ | |
3172 | |
3173 /* Dispose the caret callback */ | |
3174 if (caretId !is 0) OS.gtk_timeout_remove (caretId); | |
3175 caretId = 0; | |
3176 | |
3177 /* Release closures */ | |
3178 for (int i = 0; i < Widget.LAST_SIGNAL; i++) { | |
3179 if (closures [i] !is null) OS.g_closure_unref (closures [i]); | |
3180 } | |
3181 if (shellMapProcClosure !is null) OS.g_closure_unref (shellMapProcClosure); | |
3182 | |
3183 /* Dispose the timer callback */ | |
3184 if (timerIds !is null) { | |
3185 for (int i=0; i<timerIds.length; i++) { | |
3186 if (timerIds [i] !is 0) OS.gtk_timeout_remove (timerIds [i]); | |
3187 } | |
3188 } | |
3189 timerIds = null; | |
3190 timerList = null; | |
3191 | |
3192 /* Dispose mouse hover callback */ | |
3193 if (mouseHoverId !is 0) OS.gtk_timeout_remove (mouseHoverId); | |
3194 mouseHoverId = 0; | |
3195 mouseHoverHandle = null; | |
3196 | |
3197 /* Dispose the default font */ | |
3198 if (systemFont !is null) systemFont.dispose (); | |
3199 systemFont = null; | |
3200 | |
3201 /* Dispose the System Images */ | |
3202 if (errorImage !is null) errorImage.dispose(); | |
3203 if (infoImage !is null) infoImage.dispose(); | |
3204 if (questionImage !is null) questionImage.dispose(); | |
3205 if (warningImage !is null) warningImage.dispose(); | |
3206 errorImage = infoImage = questionImage = warningImage = null; | |
3207 | |
3208 /* Release the System Cursors */ | |
3209 for (int i = 0; i < cursors.length; i++) { | |
3210 if (cursors [i] !is null) cursors [i].dispose (); | |
3211 } | |
3212 cursors = null; | |
3213 | |
3214 /* Release Acquired Resources */ | |
3215 if (resources !is null) { | |
3216 for (int i=0; i<resources.length; i++) { | |
3217 if (resources [i] !is null) resources [i].dispose (); | |
3218 } | |
3219 resources = null; | |
3220 } | |
3221 | |
3222 /* Release the System Colors */ | |
3223 COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW = | |
3224 COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER = | |
3225 COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT = | |
3226 COLOR_WIDGET_FOREGROUND = COLOR_TITLE_FOREGROUND = COLOR_TITLE_BACKGROUND = COLOR_TITLE_BACKGROUND_GRADIENT = | |
3227 COLOR_TITLE_INACTIVE_FOREGROUND = COLOR_TITLE_INACTIVE_BACKGROUND = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = | |
3228 COLOR_INFO_BACKGROUND = COLOR_INFO_FOREGROUND = null; | |
3229 | |
3230 /* Dispose the event callback */ | |
3231 OS.gdk_event_handler_set (null, null, null); | |
3232 | |
3233 /* Dispose the hidden shell */ | |
3234 if (shellHandle !is null) OS.gtk_widget_destroy (shellHandle); | |
3235 shellHandle = null; | |
3236 | |
3237 /* Dispose the settings callback */ | |
3238 | |
3239 /* Release the sleep resources */ | |
3240 max_priority = 0; | |
3241 timeout = 0; | |
3242 if (fds !is null) OS.g_free (fds.ptr); | |
3243 fds = null; | |
3244 | |
3245 /* Release references */ | |
3246 popups = null; | |
3247 thread = null; | |
3248 lastWidget = activeShell = null; | |
3249 //flushData = null; | |
3250 closures = null; | |
3251 indexTable = signalIds = treeSelection = null; | |
3252 widgetTable = modalShells = null; | |
3253 data = null; | |
3254 values = null; | |
3255 keys = null; | |
3256 windowManager = null; | |
3257 eventTable = filterTable = null; | |
3258 modalDialog = null; | |
3259 flushRect = null; | |
3260 exposeEvent = null; | |
3261 visibilityEvent = null; | |
3262 idleLock = null; | |
3263 } | |
3264 | |
3265 /** | |
3266 * Removes the listener from the collection of listeners who will | |
3267 * be notified when an event of the given type occurs anywhere in | |
3268 * a widget. The event type is one of the event constants defined | |
3269 * in class <code>SWT</code>. | |
3270 * | |
3271 * @param eventType the type of event to listen for | |
3272 * @param listener the listener which should no longer be notified when the event occurs | |
3273 * | |
3274 * @exception IllegalArgumentException <ul> | |
3275 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
3276 * </ul> | |
3277 * @exception SWTException <ul> | |
3278 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3279 * </ul> | |
3280 * | |
3281 * @see Listener | |
3282 * @see SWT | |
3283 * @see #addFilter | |
3284 * @see #addListener | |
3285 * | |
3286 * @since 3.0 | |
3287 */ | |
3288 public void removeFilter (int eventType, Listener listener) { | |
3289 checkDevice (); | |
3290 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3291 if (filterTable is null) return; | |
3292 filterTable.unhook (eventType, listener); | |
3293 if (filterTable.size () is 0) filterTable = null; | |
3294 } | |
3295 | |
3296 GdkEvent* removeGdkEvent () { | |
3297 if (gdkEventCount is 0) return null; | |
3298 auto event = gdkEvents [0]; | |
3299 --gdkEventCount; | |
3300 SimpleType!(GdkEvent*).arraycopy (gdkEvents, 1, gdkEvents, 0, gdkEventCount); | |
3301 System.arraycopy (gdkEventWidgets, 1, gdkEventWidgets, 0, gdkEventCount); | |
3302 gdkEvents [gdkEventCount] = null; | |
3303 gdkEventWidgets [gdkEventCount] = null; | |
3304 if (gdkEventCount is 0) { | |
3305 gdkEvents = null; | |
3306 gdkEventWidgets = null; | |
3307 } | |
3308 return event; | |
3309 } | |
3310 | |
3311 void removeIdleProc () { | |
3312 synchronized (idleLock) { | |
3313 if (idleHandle !is 0) OS.g_source_remove (idleHandle); | |
3314 idleNeeded = false; | |
3315 idleHandle = 0; | |
3316 } | |
3317 } | |
3318 /** | |
3319 * Removes the listener from the collection of listeners who will | |
3320 * be notified when an event of the given type occurs. The event type | |
3321 * is one of the event constants defined in class <code>SWT</code>. | |
3322 * | |
3323 * @param eventType the type of event to listen for | |
3324 * @param listener the listener which should no longer be notified | |
3325 * | |
3326 * @exception IllegalArgumentException <ul> | |
3327 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
3328 * </ul> | |
3329 * @exception SWTException <ul> | |
3330 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3331 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3332 * </ul> | |
3333 * | |
3334 * @see Listener | |
3335 * @see SWT | |
3336 * @see #addListener | |
3337 * | |
3338 * @since 2.0 | |
3339 */ | |
3340 public void removeListener (int eventType, Listener listener) { | |
3341 checkDevice (); | |
3342 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3343 if (eventTable is null) return; | |
3344 eventTable.unhook (eventType, listener); | |
3345 } | |
3346 | |
3347 void removeMouseHoverTimeout (void* handle) { | |
3348 if (handle !is mouseHoverHandle) return; | |
3349 if (mouseHoverId !is 0) OS.gtk_timeout_remove (mouseHoverId); | |
3350 mouseHoverId = 0; | |
3351 mouseHoverHandle = null; | |
3352 } | |
3353 | |
3354 void removePopup (Menu menu) { | |
3355 if (popups is null) return; | |
3356 for (int i=0; i<popups.length; i++) { | |
3357 if (popups [i] is menu) { | |
3358 popups [i] = null; | |
3359 return; | |
3360 } | |
3361 } | |
3362 } | |
3363 | |
3364 Widget removeWidget (GtkWidget* handle) { | |
3365 if (handle is null) return null; | |
3366 lastWidget = null; | |
3367 Widget widget = null; | |
3368 int index = cast(int)/*64*/ OS.g_object_get_qdata (cast(GObject*)handle, SWT_OBJECT_INDEX) - 1; | |
3369 if (0 <= index && index < widgetTable.length) { | |
3370 widget = widgetTable [index]; | |
3371 widgetTable [index] = null; | |
3372 indexTable [index] = freeSlot; | |
3373 freeSlot = index; | |
3374 OS.g_object_set_qdata (cast(GObject*)handle, SWT_OBJECT_INDEX, null); | |
3375 } | |
3376 return widget; | |
3377 } | |
3378 | |
3379 bool runAsyncMessages (bool all) { | |
3380 return synchronizer.runAsyncMessages (all); | |
3381 } | |
3382 | |
3383 bool runDeferredEvents () { | |
3384 /* | |
3385 * Run deferred events. This code is always | |
3386 * called in the Display's thread so it must | |
3387 * be re-enterant but need not be synchronized. | |
3388 */ | |
3389 while (eventQueue !is null) { | |
3390 | |
3391 /* Take an event off the queue */ | |
3392 Event event = eventQueue [0]; | |
3393 if (event is null) break; | |
3394 int len = eventQueue.length; | |
3395 System.arraycopy (eventQueue, 1, eventQueue, 0, --len); | |
3396 eventQueue [len] = null; | |
3397 | |
3398 /* Run the event */ | |
3399 Widget widget = event.widget; | |
3400 if (widget !is null && !widget.isDisposed ()) { | |
3401 Widget item = event.item; | |
3402 if (item is null || !item.isDisposed ()) { | |
3403 widget.sendEvent (event); | |
3404 } | |
3405 } | |
3406 | |
3407 /* | |
3408 * At this point, the event queue could | |
3409 * be null due to a recursive invokation | |
3410 * when running the event. | |
3411 */ | |
3412 } | |
3413 | |
3414 /* Clear the queue */ | |
3415 eventQueue = null; | |
3416 return true; | |
3417 } | |
3418 | |
3419 bool runPopups () { | |
3420 if (popups is null) return false; | |
3421 bool result = false; | |
3422 while (popups !is null) { | |
3423 Menu menu = popups [0]; | |
3424 if (menu is null) break; | |
3425 int len = popups.length; | |
3426 System.arraycopy (popups, 1, popups, 0, --len); | |
3427 popups [len] = null; | |
3428 runDeferredEvents (); | |
3429 if (!menu.isDisposed ()) menu._setVisible (true); | |
3430 result = true; | |
3431 } | |
3432 popups = null; | |
3433 return result; | |
3434 } | |
3435 | |
3436 bool runSettings () { | |
3437 if (!runSettingsFld) return false; | |
3438 runSettingsFld = false; | |
3439 saveResources (); | |
3440 initializeSystemColors (); | |
3441 sendEvent (SWT.Settings, null); | |
3442 Shell [] shells = getShells (); | |
3443 for (int i=0; i<shells.length; i++) { | |
3444 Shell shell = shells [i]; | |
3445 if (!shell.isDisposed ()) { | |
3446 shell.fixStyle (); | |
3447 shell.redraw (true); | |
3448 shell.layout (true, true); | |
3449 } | |
3450 } | |
3451 return true; | |
3452 } | |
3453 | |
3454 /** | |
3455 * On platforms which support it, sets the application name | |
3456 * to be the argument. On Motif, for example, this can be used | |
3457 * to set the name used for resource lookup. Specifying | |
3458 * <code>null</code> for the name clears it. | |
3459 * | |
3460 * @param name the new app name or <code>null</code> | |
3461 */ | |
3462 public static void setAppName (String name) { | |
3463 APP_NAME = name; | |
3464 } | |
3465 | |
3466 /** | |
3467 * Sets the location of the on-screen pointer relative to the top left corner | |
3468 * of the screen. <b>Note: It is typically considered bad practice for a | |
3469 * program to move the on-screen pointer location.</b> | |
3470 * | |
3471 * @param x the new x coordinate for the cursor | |
3472 * @param y the new y coordinate for the cursor | |
3473 * | |
3474 * @exception SWTException <ul> | |
3475 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3476 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3477 * </ul> | |
3478 * | |
3479 * @since 2.1 | |
3480 */ | |
3481 public void setCursorLocation (int x, int y) { | |
3482 checkDevice (); | |
3483 if (OS.GDK_WINDOWING_X11 ()) { | |
3484 auto xDisplay = OS.GDK_DISPLAY (); | |
3485 auto xWindow = OS.XDefaultRootWindow (xDisplay); | |
3486 OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, x, y); | |
3487 } | |
3488 } | |
3489 | |
3490 /** | |
3491 * Sets the location of the on-screen pointer relative to the top left corner | |
3492 * of the screen. <b>Note: It is typically considered bad practice for a | |
3493 * program to move the on-screen pointer location.</b> | |
3494 * | |
3495 * @param point new position | |
3496 * | |
3497 * @exception SWTException <ul> | |
3498 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3499 * <li>ERROR_NULL_ARGUMENT - if the point is null | |
3500 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3501 * </ul> | |
3502 * | |
3503 * @since 2.0 | |
3504 */ | |
3505 public void setCursorLocation (Point point) { | |
3506 checkDevice (); | |
3507 if (point is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3508 setCursorLocation (point.x, point.y); | |
3509 } | |
3510 | |
3511 /** | |
3512 * Sets the application defined property of the receiver | |
3513 * with the specified name to the given argument. | |
3514 * <p> | |
3515 * Applications may have associated arbitrary objects with the | |
3516 * receiver in this fashion. If the objects stored in the | |
3517 * properties need to be notified when the display is disposed | |
3518 * of, it is the application's responsibility provide a | |
3519 * <code>disposeExec()</code> handler which does so. | |
3520 * </p> | |
3521 * | |
3522 * @param key the name of the property | |
3523 * @param value the new value for the property | |
3524 * | |
3525 * @exception SWTException <ul> | |
3526 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3527 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3528 * </ul> | |
3529 * | |
3530 * @see #getData(String) | |
3531 * @see #disposeExec(Runnable) | |
3532 */ | |
3533 public void setData (String key, Object value) { | |
3534 checkDevice (); | |
3535 // SWT extension: allow null for zero length string | |
3536 //if (key is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3537 | |
3538 if (key.equals (DISPATCH_EVENT_KEY)) { | |
3539 ArrayWrapperInt wrappedValue; | |
3540 if (value is null || (null !is (wrappedValue=cast(ArrayWrapperInt)value))) { | |
3541 dispatchEvents = wrappedValue.array; | |
3542 if (value is null) putGdkEvents (); | |
3543 return; | |
3544 } | |
3545 } | |
3546 if (key.equals (SET_MODAL_DIALOG)) { | |
3547 setModalDialog (cast(Dialog) data); | |
3548 return; | |
3549 } | |
3550 | |
3551 if (key.equals (ADD_WIDGET_KEY)) { | |
3552 auto wrap = cast(ArrayWrapperObject) value; | |
3553 if( wrap is null ) SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " []"); | |
3554 Object [] data = wrap.array; | |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
51
diff
changeset
|
3555 auto handle = (cast(LONG) data [0]).intValue; |
25 | 3556 Widget widget = cast(Widget) data [1]; |
3557 if (widget !is null) { | |
3558 addWidget (cast(GtkWidget*)handle, widget); | |
3559 } else { | |
3560 removeWidget (cast(GtkWidget*)handle); | |
3561 } | |
3562 } | |
3563 | |
3564 if (key==/*eq*/ ADD_IDLE_PROC_KEY) { | |
3565 addIdleProc (); | |
3566 return; | |
3567 } | |
3568 if (key==/*eq*/ REMOVE_IDLE_PROC_KEY) { | |
3569 removeIdleProc (); | |
3570 return; | |
3571 } | |
3572 | |
3573 /* Remove the key/value pair */ | |
3574 if (value is null) { | |
3575 if (keys is null) return; | |
3576 int index = 0; | |
3577 while (index < keys.length && keys [index]!=/*!eq*/ key) index++; | |
3578 if (index is keys.length) return; | |
3579 if (keys.length is 1) { | |
3580 keys = null; | |
3581 values = null; | |
3582 } else { | |
3583 String [] newKeys = new String [keys.length - 1]; | |
3584 Object [] newValues = new Object [values.length - 1]; | |
3585 System.arraycopy (keys, 0, newKeys, 0, index); | |
3586 System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index); | |
3587 System.arraycopy (values, 0, newValues, 0, index); | |
3588 System.arraycopy (values, index + 1, newValues, index, newValues.length - index); | |
3589 keys = newKeys; | |
3590 values = newValues; | |
3591 } | |
3592 return; | |
3593 } | |
3594 | |
3595 /* Add the key/value pair */ | |
3596 if (keys is null) { | |
3597 keys = [key]; | |
3598 values = [value]; | |
3599 return; | |
3600 } | |
3601 for (int i=0; i<keys.length; i++) { | |
3602 if (keys [i]==/*eq*/ key) { | |
3603 values [i] = value; | |
3604 return; | |
3605 } | |
3606 } | |
3607 String [] newKeys = new String [keys.length + 1]; | |
3608 Object [] newValues = new Object [values.length + 1]; | |
3609 System.arraycopy (keys, 0, newKeys, 0, keys.length); | |
3610 System.arraycopy (values, 0, newValues, 0, values.length); | |
3611 newKeys [keys.length] = key; | |
3612 newValues [values.length] = value; | |
3613 keys = newKeys; | |
3614 values = newValues; | |
3615 } | |
3616 | |
3617 /** | |
3618 * Sets the application defined, display specific data | |
3619 * associated with the receiver, to the argument. | |
3620 * The <em>display specific data</em> is a single, | |
3621 * unnamed field that is stored with every display. | |
3622 * <p> | |
3623 * Applications may put arbitrary objects in this field. If | |
3624 * the object stored in the display specific data needs to | |
3625 * be notified when the display is disposed of, it is the | |
3626 * application's responsibility provide a | |
3627 * <code>disposeExec()</code> handler which does so. | |
3628 * </p> | |
3629 * | |
3630 * @param data the new display specific data | |
3631 * | |
3632 * @exception SWTException <ul> | |
3633 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3634 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3635 * </ul> | |
3636 * | |
3637 * @see #getData() | |
3638 * @see #disposeExec(Runnable) | |
3639 */ | |
3640 public void setData (Object data) { | |
3641 checkDevice (); | |
3642 this.data = data; | |
3643 } | |
3644 | |
3645 | |
3646 void doSetDirectionProc( GtkWidget* widget, int direction ){ | |
3647 setDirectionProcCallbackData.display = this; | |
3648 setDirectionProcCallbackData.data = cast(void*)direction; | |
3649 OS.gtk_container_forall (cast(GtkContainer*)widget, cast(GtkCallback)&setDirectionProcFunc, &setDirectionProcCallbackData); | |
3650 } | |
3651 | |
3652 package static extern(C) int /*long*/ setDirectionProcFunc (GtkWidget* widget, void* data) { | |
3653 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3654 CallbackData* cbdata = cast(CallbackData*)data; | |
3655 return cbdata.display.setDirectionProc( widget, cast(int)cbdata.data ); | |
3656 } | |
3657 int /*long*/ setDirectionProc (GtkWidget* widget, int /*long*/ direction) { | |
3658 OS.gtk_widget_set_direction (widget, direction); | |
3659 if (OS.GTK_IS_MENU_ITEM (widget)) { | |
3660 auto submenu = OS.gtk_menu_item_get_submenu (widget); | |
3661 if (submenu !is null) { | |
3662 OS.gtk_widget_set_direction (submenu, cast(int)/*64*/ direction); | |
3663 OS.gtk_container_forall (cast(GtkContainer*)submenu, cast(GtkCallback)&setDirectionProcFunc, cast(void*)direction); | |
3664 } | |
3665 } | |
3666 if (OS.GTK_IS_CONTAINER (cast(GTypeInstance*)widget)) { | |
3667 OS.gtk_container_forall (cast(GtkContainer*)widget, cast(GtkCallback)&setDirectionProcFunc, cast(void*)direction); | |
3668 } | |
3669 return 0; | |
3670 } | |
3671 | |
3672 void setModalDialog (Dialog modalDailog) { | |
3673 this.modalDialog = modalDailog; | |
3674 Shell [] shells = getShells (); | |
3675 for (int i=0; i<shells.length; i++) shells [i].updateModal (); | |
3676 } | |
3677 | |
3678 void setModalShell (Shell shell) { | |
3679 if (modalShells is null) modalShells = new Shell [4]; | |
3680 int index = 0, length = modalShells.length; | |
3681 while (index < length) { | |
3682 if (modalShells [index] is shell) return; | |
3683 if (modalShells [index] is null) break; | |
3684 index++; | |
3685 } | |
3686 if (index is length) { | |
3687 Shell [] newModalShells = new Shell [length + 4]; | |
3688 System.arraycopy (modalShells, 0, newModalShells, 0, length); | |
3689 modalShells = newModalShells; | |
3690 } | |
3691 modalShells [index] = shell; | |
3692 Shell [] shells = getShells (); | |
3693 for (int i=0; i<shells.length; i++) shells [i].updateModal (); | |
3694 } | |
3695 | |
3696 /** | |
3697 * Sets the synchronizer used by the display to be | |
3698 * the argument, which can not be null. | |
3699 * | |
3700 * @param synchronizer the new synchronizer for the display (must not be null) | |
3701 * | |
3702 * @exception IllegalArgumentException <ul> | |
3703 * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li> | |
3704 * </ul> | |
3705 * @exception SWTException <ul> | |
3706 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3707 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3708 * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li> | |
3709 * </ul> | |
3710 */ | |
3711 public void setSynchronizer (Synchronizer synchronizer) { | |
3712 checkDevice (); | |
3713 if (synchronizer is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3714 if (synchronizer is this.synchronizer) return; | |
3715 Synchronizer oldSynchronizer; | |
3716 synchronized (Device.classinfo) { | |
3717 oldSynchronizer = this.synchronizer; | |
3718 this.synchronizer = synchronizer; | |
3719 } | |
3720 if (oldSynchronizer !is null) { | |
3721 oldSynchronizer.runAsyncMessages(true); | |
3722 } | |
3723 } | |
3724 | |
3725 void showIMWindow (Control control) { | |
3726 imControl = control; | |
3727 if (preeditWindow is null) { | |
3728 preeditWindow = cast(GtkWindow*)OS.gtk_window_new (OS.GTK_WINDOW_POPUP); | |
3729 if (preeditWindow is null) error (SWT.ERROR_NO_HANDLES); | |
3730 preeditLabel = cast(GtkLabel*) OS.gtk_label_new (null); | |
3731 if (preeditLabel is null) error (SWT.ERROR_NO_HANDLES); | |
3732 OS.gtk_container_add (cast(GtkContainer*)preeditWindow, cast(GtkWidget*) preeditLabel); | |
3733 OS.gtk_widget_show (cast(GtkWidget*)preeditLabel); | |
3734 } | |
3735 char* preeditString; | |
3736 PangoAttrList* pangoAttrs; | |
3737 auto imHandle = control.imHandle (); | |
3738 OS.gtk_im_context_get_preedit_string (imHandle, &preeditString, &pangoAttrs, null); | |
51 | 3739 if (preeditString !is null && OS.strlen (preeditString) > 0) { |
25 | 3740 Control widget = control.findBackgroundControl (); |
3741 if (widget is null) widget = control; | |
3742 OS.gtk_widget_modify_bg (cast(GtkWidget*)preeditWindow, OS.GTK_STATE_NORMAL, widget.getBackgroundColor ()); | |
3743 widget.setForegroundColor (cast(GtkWidget*)preeditLabel, control.getForegroundColor()); | |
3744 OS.gtk_widget_modify_font (cast(GtkWidget*)preeditLabel, control.getFontDescription ()); | |
3745 if (pangoAttrs !is null) OS.gtk_label_set_attributes (preeditLabel, pangoAttrs); | |
3746 OS.gtk_label_set_text (preeditLabel, preeditString); | |
3747 Point point = control.toDisplay (control.getIMCaretPos ()); | |
3748 OS.gtk_window_move (preeditWindow, point.x, point.y); | |
3749 GtkRequisition requisition; | |
3750 OS.gtk_widget_size_request (cast(GtkWidget*)preeditLabel, &requisition); | |
3751 OS.gtk_window_resize (preeditWindow, requisition.width, requisition.height); | |
3752 OS.gtk_widget_show (cast(GtkWidget*)preeditWindow); | |
3753 } else { | |
3754 OS.gtk_widget_hide (cast(GtkWidget*)preeditWindow); | |
3755 } | |
3756 if (preeditString !is null) OS.g_free (preeditString); | |
3757 if (pangoAttrs !is null) OS.pango_attr_list_unref (pangoAttrs); | |
3758 } | |
3759 | |
3760 /** | |
3761 * Causes the user-interface thread to <em>sleep</em> (that is, | |
3762 * to be put in a state where it does not consume CPU cycles) | |
3763 * until an event is received or it is otherwise awakened. | |
3764 * | |
3765 * @return <code>true</code> if an event requiring dispatching was placed on the queue. | |
3766 * | |
3767 * @exception SWTException <ul> | |
3768 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3769 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3770 * </ul> | |
3771 * | |
3772 * @see #wake | |
3773 */ | |
3774 public bool sleep () { | |
3775 checkDevice (); | |
3776 if (gdkEventCount is 0) { | |
3777 gdkEvents = null; | |
3778 gdkEventWidgets = null; | |
3779 } | |
3780 if (settingsChanged) { | |
3781 settingsChanged = false; | |
3782 runSettingsFld = true; | |
3783 return false; | |
3784 } | |
3785 if (getMessageCount () !is 0) return true; | |
3786 if (fds is null) { | |
3787 allocated_nfds = 2; | |
3788 GPollFD* ptr = cast(GPollFD*) OS.g_malloc( GPollFD.sizeof * allocated_nfds ); | |
3789 fds = ptr[ 0 .. allocated_nfds ]; | |
3790 } | |
3791 max_priority = timeout = 0; | |
3792 auto context = OS.g_main_context_default (); | |
3793 bool result = false; | |
3794 do { | |
3795 if (OS.g_main_context_acquire (context)) { | |
3796 result = cast(bool)OS.g_main_context_prepare (context, &max_priority); | |
3797 int nfds; | |
3798 while ((nfds = OS.g_main_context_query (context, max_priority, &timeout, fds.ptr, allocated_nfds)) > allocated_nfds) { | |
3799 OS.g_free (fds.ptr); | |
3800 allocated_nfds = nfds; | |
3801 GPollFD* ptr = cast(GPollFD*) OS.g_malloc( GPollFD.sizeof * allocated_nfds ); | |
3802 fds = ptr[ 0 .. allocated_nfds ]; | |
3803 } | |
3804 GPollFunc poll = OS.g_main_context_get_poll_func (context); | |
3805 if (poll !is null) { | |
3806 if (nfds > 0 || timeout !is 0) { | |
3807 /* | |
3808 * Bug in GTK. For some reason, g_main_context_wakeup() may | |
3809 * fail to wake up the UI thread from the polling function. | |
3810 * The fix is to sleep for a maximum of 50 milliseconds. | |
3811 */ | |
3812 if (timeout < 0) timeout = 50; | |
3813 | |
3814 /* Exit the OS lock to allow other threads to enter GTK */ | |
3815 Lock lock = OS.lock; | |
3816 int count = lock.lock (); | |
3817 for (int i = 0; i < count; i++) lock.unlock (); | |
3818 try { | |
3819 wake_state = false; | |
3820 poll( fds.ptr, nfds, timeout); | |
3821 } finally { | |
3822 for (int i = 0; i < count; i++) lock.lock (); | |
3823 lock.unlock (); | |
3824 } | |
3825 } | |
3826 } | |
3827 OS.g_main_context_check (context, max_priority, fds.ptr, nfds); | |
3828 OS.g_main_context_release (context); | |
3829 } | |
3830 } while (!result && getMessageCount () is 0 && !wake_state); | |
3831 wake_state = false; | |
3832 return true; | |
3833 } | |
3834 | |
3835 /** | |
3836 * Causes the <code>run()</code> method of the runnable to | |
3837 * be invoked by the user-interface thread after the specified | |
3838 * number of milliseconds have elapsed. If milliseconds is less | |
3839 * than zero, the runnable is not executed. | |
3840 * <p> | |
3841 * Note that at the time the runnable is invoked, widgets | |
3842 * that have the receiver as their display may have been | |
3843 * disposed. Therefore, it is necessary to check for this | |
3844 * case inside the runnable before accessing the widget. | |
3845 * </p> | |
3846 * | |
3847 * @param milliseconds the delay before running the runnable | |
3848 * @param runnable code to run on the user-interface thread | |
3849 * | |
3850 * @exception IllegalArgumentException <ul> | |
3851 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li> | |
3852 * </ul> | |
3853 * @exception SWTException <ul> | |
3854 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3855 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
3856 * </ul> | |
3857 * | |
3858 * @see #asyncExec | |
3859 */ | |
3860 public void timerExec (int milliseconds, Runnable runnable) { | |
3861 checkDevice (); | |
3862 if (runnable is null) error (SWT.ERROR_NULL_ARGUMENT); | |
3863 if (timerList is null) timerList = new Runnable [4]; | |
3864 if (timerIds is null) timerIds = new int [4]; | |
3865 int index = 0; | |
3866 while (index < timerList.length) { | |
3867 if (timerList [index] is runnable) break; | |
3868 index++; | |
3869 } | |
3870 if (index !is timerList.length) { | |
3871 OS.gtk_timeout_remove (timerIds [index]); | |
3872 timerList [index] = null; | |
3873 timerIds [index] = 0; | |
3874 if (milliseconds < 0) return; | |
3875 } else { | |
3876 if (milliseconds < 0) return; | |
3877 index = 0; | |
3878 while (index < timerList.length) { | |
3879 if (timerList [index] is null) break; | |
3880 index++; | |
3881 } | |
3882 if (index is timerList.length) { | |
3883 Runnable [] newTimerList = new Runnable [timerList.length + 4]; | |
3884 SimpleType!(Runnable).arraycopy (timerList, 0, newTimerList, 0, timerList.length); | |
3885 timerList = newTimerList; | |
3886 int [] newTimerIds = new int [timerIds.length + 4]; | |
3887 System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length); | |
3888 timerIds = newTimerIds; | |
3889 } | |
3890 } | |
3891 timerProcCallbackData.display = this; | |
3892 timerProcCallbackData.data = cast(void*)index; | |
3893 int timerId = OS.gtk_timeout_add (milliseconds, &timerProcFunc, &timerProcCallbackData); | |
3894 if (timerId !is 0) { | |
3895 timerIds [index] = timerId; | |
3896 timerList [index] = runnable; | |
3897 } | |
3898 } | |
3899 | |
3900 | |
3901 private static extern(C) int timerProcFunc ( void * data ) { | |
3902 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3903 CallbackData* cbdata = cast( CallbackData* ) data; | |
3904 return cbdata.display.timerProc( cast(int) cbdata.data ); | |
3905 } | |
3906 | |
3907 int /*long*/ timerProc (int /*long*/ i) { | |
3908 if (timerList is null) return 0; | |
3909 int index = cast(int)/*64*/i; | |
3910 if (0 <= index && index < timerList.length) { | |
3911 Runnable runnable = timerList [index]; | |
3912 timerList [index] = null; | |
3913 timerIds [index] = 0; | |
3914 if (runnable !is null) runnable.run (); | |
3915 } | |
3916 return 0; | |
3917 } | |
3918 | |
3919 private static extern(C) int caretProcFunc ( void * data ) { | |
3920 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3921 CallbackData* cbdata = cast( CallbackData* ) data; | |
3922 return cbdata.display.caretProc( cast(int) cbdata.data ); | |
3923 } | |
3924 int /*long*/ caretProc (int /*long*/ clientData) { | |
3925 caretId = 0; | |
3926 if (currentCaret is null) { | |
3927 return 0; | |
3928 } | |
3929 if (currentCaret.blinkCaret()) { | |
3930 int blinkRate = currentCaret.blinkRate; | |
3931 if (blinkRate is 0) return 0; | |
3932 caretProcCallbackData.display = this; | |
3933 caretProcCallbackData.data = cast(void*)0; | |
3934 caretId = OS.gtk_timeout_add (blinkRate, &caretProcFunc, &caretProcCallbackData); | |
3935 } else { | |
3936 currentCaret = null; | |
3937 } | |
3938 return 0; | |
3939 } | |
3940 | |
3941 | |
3942 package int doSizeAllocateConnect( CallbackData* cbdata, GtkWidget* window, GtkWidget* widget ){ | |
3943 cbdata.display = this; | |
3944 cbdata.data = cast(void*)widget; | |
3945 return OS.g_signal_connect (cast(void*)window, OS.size_allocate.ptr, cast(GCallback)&sizeAllocateProcFunc, cast(void*)&cbdata); | |
3946 } | |
3947 | |
3948 private static extern(C) void sizeAllocateProcFunc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
3949 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3950 auto cbdata = cast(CallbackData*)user_data; | |
3951 cbdata.display.sizeAllocateProc( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); | |
3952 } | |
3953 | |
3954 void sizeAllocateProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
3955 Widget widget = getWidget ( cast(GtkWidget*)user_data); | |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
51
diff
changeset
|
3956 if (widget is null) return; |
25 | 3957 widget.sizeAllocateProc (handle, arg0, user_data); |
3958 } | |
3959 | |
3960 | |
3961 package int doSizeRequestConnect( CallbackData* cbdata, GtkWidget* window, GtkWidget* widget ){ | |
3962 cbdata.display = this; | |
3963 cbdata.data = cast(void*)widget; | |
3964 return OS.g_signal_connect (cast(void*)window, OS.size_request.ptr, cast(GCallback)&sizeRequestProcFunc, cast(void*)&cbdata ); | |
3965 } | |
3966 | |
3967 private static extern(C) void sizeRequestProcFunc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
3968 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3969 auto cbdata = cast(CallbackData*)user_data; | |
3970 cbdata.display.sizeRequestProcMeth( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); | |
3971 } | |
3972 | |
3973 int /*long*/ sizeRequestProcMeth (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
3974 Widget widget = getWidget (cast(GtkWidget*)user_data); | |
3975 if (widget is null) return 0; | |
3976 return widget.sizeRequestProc (handle, arg0, user_data); | |
3977 } | |
3978 | |
3979 package void doTreeSelectionProcConnect( CallbackData* cbdata, GtkWidget* widget, GtkTreeSelection* selection ){ | |
3980 cbdata.display = this; | |
3981 cbdata.data = cast(void*)widget; | |
3982 OS.gtk_tree_selection_selected_foreach (selection, &treeSelectionProcFunc, widget); | |
3983 } | |
3984 | |
3985 private static extern(C) void treeSelectionProcFunc (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, void* data) { | |
3986 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
3987 auto cbdata = cast(CallbackData*)data; | |
3988 cbdata.display.treeSelectionProcMeth( model, path, iter, cbdata.data ); | |
3989 } | |
3990 | |
3991 void treeSelectionProcMeth (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, void* data) { | |
3992 Widget widget = getWidget (cast(GtkWidget*)data); | |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
51
diff
changeset
|
3993 if (widget is null) return; |
25 | 3994 widget.treeSelectionProc (model, path, iter, treeSelection, treeSelectionLength++); |
3995 } | |
3996 | |
3997 void saveResources () { | |
3998 int resourceCount = 0; | |
3999 if (resources is null) { | |
4000 resources = new Resource [RESOURCE_SIZE]; | |
4001 } else { | |
4002 resourceCount = resources.length; | |
4003 Resource [] newResources = new Resource [resourceCount + RESOURCE_SIZE]; | |
4004 System.arraycopy (resources, 0, newResources, 0, resourceCount); | |
4005 resources = newResources; | |
4006 } | |
4007 if (systemFont !is null) { | |
4008 resources [resourceCount++] = systemFont; | |
4009 systemFont = null; | |
4010 } | |
4011 if (errorImage !is null) resources [resourceCount++] = errorImage; | |
4012 if (infoImage !is null) resources [resourceCount++] = infoImage; | |
4013 if (questionImage !is null) resources [resourceCount++] = questionImage; | |
4014 if (warningImage !is null) resources [resourceCount++] = warningImage; | |
4015 errorImage = infoImage = questionImage = warningImage = null; | |
4016 for (int i=0; i<cursors.length; i++) { | |
4017 if (cursors [i] !is null) resources [resourceCount++] = cursors [i]; | |
4018 cursors [i] = null; | |
4019 } | |
4020 if (resourceCount < RESOURCE_SIZE) { | |
4021 Resource [] newResources = new Resource [resourceCount]; | |
4022 System.arraycopy (resources, 0, newResources, 0, resourceCount); | |
4023 resources = newResources; | |
4024 } | |
4025 } | |
4026 | |
4027 void sendEvent (int eventType, Event event) { | |
4028 if (eventTable is null && filterTable is null) { | |
4029 return; | |
4030 } | |
4031 if (event is null) event = new Event (); | |
4032 event.display = this; | |
4033 event.type = eventType; | |
4034 if (event.time is 0) event.time = getLastEventTime (); | |
4035 if (!filterEvent (event)) { | |
4036 if (eventTable !is null) eventTable.sendEvent (event); | |
4037 } | |
4038 } | |
4039 | |
4040 void setCurrentCaret (Caret caret) { | |
4041 if (caretId !is 0) OS.gtk_timeout_remove(caretId); | |
4042 caretId = 0; | |
4043 currentCaret = caret; | |
4044 if (caret is null) return; | |
4045 int blinkRate = currentCaret.blinkRate; | |
4046 caretProcCallbackData.display = this; | |
4047 caretProcCallbackData.data = cast(void*)0; | |
4048 caretId = OS.gtk_timeout_add (blinkRate, &caretProcFunc, &caretProcCallbackData); | |
4049 } | |
4050 | |
4051 private static extern(C) int /*long*/ shellMapProcFunc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { | |
4052 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4053 auto cbdata = cast(CallbackData*)user_data; | |
4054 return cbdata.display.shellMapProc( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); | |
4055 } | |
4056 | |
4057 int /*long*/ shellMapProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
4058 Widget widget = getWidget (cast(GtkWidget*)handle); | |
4059 if (widget is null) return 0; | |
4060 return widget.shellMapProc (handle, arg0, user_data); | |
4061 } | |
4062 | |
4063 private static extern(C) int /*long*/ styleSetProcFunc (int /*long*/ gobject, int /*long*/ arg1, int /*long*/ user_data) { | |
4064 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4065 auto cbdata = cast(CallbackData*)user_data; | |
4066 return cbdata.display.styleSetProcMeth( gobject, arg1, cast(int)cbdata.data ); | |
4067 } | |
4068 int /*long*/ styleSetProcMeth (int /*long*/ gobject, int /*long*/ arg1, int /*long*/ user_data) { | |
4069 settingsChanged = true; | |
4070 return 0; | |
4071 } | |
4072 | |
4073 /** | |
4074 * Causes the <code>run()</code> method of the runnable to | |
4075 * be invoked by the user-interface thread at the next | |
4076 * reasonable opportunity. The thread which calls this method | |
4077 * is suspended until the runnable completes. Specifying <code>null</code> | |
4078 * as the runnable simply wakes the user-interface thread. | |
4079 * <p> | |
4080 * Note that at the time the runnable is invoked, widgets | |
4081 * that have the receiver as their display may have been | |
4082 * disposed. Therefore, it is necessary to check for this | |
4083 * case inside the runnable before accessing the widget. | |
4084 * </p> | |
4085 * | |
4086 * @param runnable code to run on the user-interface thread or <code>null</code> | |
4087 * | |
4088 * @exception SWTException <ul> | |
4089 * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li> | |
4090 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
4091 * </ul> | |
4092 * | |
4093 * @see #asyncExec | |
4094 */ | |
4095 public void syncExec (Runnable runnable) { | |
4096 Synchronizer synchronizer; | |
4097 synchronized (Device.classinfo) { | |
4098 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
4099 synchronizer = this.synchronizer; | |
4100 synchronized (idleLock) { | |
4101 if (idleNeeded && idleHandle is 0) { | |
4102 //NOTE: calling unlocked function in OS | |
4103 idleProcCallbackData.display = this; | |
4104 idleProcCallbackData.data = cast(void*)0; | |
4105 //PORTING_TODO: was _g_idle_add, calling directly | |
4106 idleHandle = OS.g_idle_add (&idleProcFunc, &idleProcCallbackData); | |
4107 } | |
4108 } | |
4109 } | |
4110 synchronizer.syncExec (runnable); | |
4111 } | |
4112 | |
4113 static int translateKey (int key) { | |
4114 for (int i=0; i<KeyTable.length; i++) { | |
4115 if (KeyTable [i] [0] is key) return KeyTable [i] [1]; | |
4116 } | |
4117 return 0; | |
4118 } | |
4119 | |
4120 static int untranslateKey (int key) { | |
4121 for (int i=0; i<KeyTable.length; i++) { | |
4122 if (KeyTable [i] [1] is key) return KeyTable [i] [0]; | |
4123 } | |
4124 return 0; | |
4125 } | |
4126 | |
4127 /** | |
4128 * Forces all outstanding paint requests for the display | |
4129 * to be processed before this method returns. | |
4130 * | |
4131 * @exception SWTException <ul> | |
4132 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
4133 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
4134 * </ul> | |
4135 * | |
4136 * @see Control#update() | |
4137 */ | |
4138 public void update () { | |
4139 checkDevice (); | |
4140 flushExposes (null, true); | |
4141 OS.gdk_window_process_all_updates (); | |
4142 } | |
4143 | |
4144 /** | |
4145 * If the receiver's user-interface thread was <code>sleep</code>ing, | |
4146 * causes it to be awakened and start running again. Note that this | |
4147 * method may be called from any thread. | |
4148 * | |
4149 * @exception SWTException <ul> | |
4150 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
4151 * </ul> | |
4152 * | |
4153 * @see #sleep | |
4154 */ | |
4155 public void wake () { | |
4156 synchronized (Device.classinfo) { | |
4157 if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
4158 if (thread is Thread.currentThread ()) return; |
25 | 4159 wakeThread (); |
4160 } | |
4161 } | |
4162 | |
4163 void wakeThread () { | |
4164 OS.g_main_context_wakeup (null); | |
4165 wake_state = true; | |
4166 } | |
4167 | |
4168 static dchar wcsToMbcs (char ch) { | |
4169 //PORTING_TODO not sure about this | |
4170 int key = ch & 0xFFFF; | |
4171 if (key <= 0x7F) return ch; | |
4172 char [] buffer = Converter.wcsToMbcs (null,[ch], false); | |
4173 if (buffer.length is 1) return '\0'; | |
4174 if (buffer.length is 2) { | |
4175 return cast(char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF)); | |
4176 } | |
4177 return '\0'; | |
4178 } | |
4179 | |
4180 private static extern(C) int /*long*/ windowProcFunc2 (GtkWidget* handle, int /*long*/ user_data) { | |
4181 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4182 CallbackData* cbdata = cast(CallbackData*)user_data; | |
4183 return cbdata.display.windowProc( handle, cast(int)cbdata.data ); | |
4184 } | |
4185 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ user_data) { | |
4186 Widget widget = getWidget (handle); | |
4187 if (widget is null) return 0; | |
4188 return widget.windowProc (handle, user_data); | |
4189 } | |
4190 | |
4191 private static extern(C) int /*long*/ windowProcFunc3 (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { | |
4192 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4193 CallbackData* cbdata = cast(CallbackData*)user_data; | |
4194 return cbdata.display.windowProc( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); | |
4195 } | |
4196 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
4197 Widget widget = getWidget (handle); | |
4198 if (widget is null) return 0; | |
4199 return widget.windowProc (handle, arg0, user_data); | |
4200 } | |
4201 | |
4202 private static extern(C) int /*long*/ windowProcFunc4 (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) { | |
4203 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4204 CallbackData* cbdata = cast(CallbackData*)user_data; | |
4205 return cbdata.display.windowProc( cast(GtkWidget*)handle, arg0, arg1, cast(int)cbdata.data ); | |
4206 } | |
4207 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) { | |
4208 Widget widget = getWidget (handle); | |
4209 if (widget is null) return 0; | |
4210 return widget.windowProc (handle, arg0, arg1, user_data); | |
4211 } | |
4212 | |
4213 private static extern(C) int /*long*/ windowProcFunc5 (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) { | |
4214 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4215 CallbackData* cbdata = cast(CallbackData*)user_data; | |
4216 return cbdata.display.windowProc( cast(GtkWidget*)handle, arg0, arg1, arg2, cast(int)cbdata.data ); | |
4217 } | |
4218 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) { | |
4219 Widget widget = getWidget (handle); | |
4220 if (widget is null) return 0; | |
4221 return widget.windowProc (handle, arg0, arg1, arg2, user_data); | |
4222 } | |
4223 | |
4224 package int doWindowTimerAdd( CallbackData* cbdata, int delay, GtkWidget* widget ){ | |
4225 OS.g_object_set_data(cast(GObject*)widget, Display.classinfo.name.ptr, cast(void*)this); | |
4226 return OS.gtk_timeout_add (delay, &windowTimerProcFunc, widget); | |
4227 } | |
4228 private static extern(C) int /*long*/ windowTimerProcFunc (void* user_data) { | |
4229 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Display {}:", __LINE__ ).flush; | |
4230 Display d = cast(Display) OS.g_object_get_data(cast(GObject*)user_data, Display.classinfo.name.ptr ); | |
4231 return d.windowTimerProc( cast(GtkWidget*)user_data ); | |
4232 } | |
4233 | |
4234 int /*long*/ windowTimerProc (GtkWidget* handle) { | |
4235 Widget widget = getWidget (handle); | |
4236 if (widget is null) return 0; | |
4237 return widget.timerProc (handle); | |
4238 } | |
4239 | |
4240 } | |
4241 | |
4242 package struct CallbackData { | |
4243 Display display; | |
4244 void* data; | |
4245 } | |
4246 |