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