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