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