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