Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/widgets/Widget.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | fb3aa8075988 |
children |
rev | line source |
---|---|
25 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.widgets.Widget; | |
14 | |
15 import org.eclipse.swt.SWT; | |
16 import java.lang.all; | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
17 import java.nonstandard.UnsafeUtf; |
25 | 18 |
19 import org.eclipse.swt.events.DisposeListener; | |
20 import org.eclipse.swt.internal.Converter; | |
21 import org.eclipse.swt.internal.SWTEventListener; | |
22 import org.eclipse.swt.internal.gtk.OS; | |
23 import org.eclipse.swt.widgets.Display; | |
24 import org.eclipse.swt.widgets.Event; | |
25 import org.eclipse.swt.widgets.EventTable; | |
26 import org.eclipse.swt.widgets.Listener; | |
27 import org.eclipse.swt.widgets.TypedListener; | |
28 | |
48 | 29 import java.lang.Thread; |
25 | 30 |
31 | |
32 /** | |
33 * This class is the abstract superclass of all user interface objects. | |
34 * Widgets are created, disposed and issue notification to listeners | |
35 * when events occur which affect them. | |
36 * <dl> | |
37 * <dt><b>Styles:</b></dt> | |
38 * <dd>(none)</dd> | |
39 * <dt><b>Events:</b></dt> | |
40 * <dd>Dispose</dd> | |
41 * </dl> | |
42 * <p> | |
43 * IMPORTANT: This class is intended to be subclassed <em>only</em> | |
44 * within the SWT implementation. However, it has not been marked | |
45 * final to allow those outside of the SWT development team to implement | |
46 * patched versions of the class in order to get around specific | |
47 * limitations in advance of when those limitations can be addressed | |
48 * by the team. Any class built using subclassing to access the internals | |
49 * of this class will likely fail to compile or run between releases and | |
50 * may be strongly platform specific. Subclassing should not be attempted | |
51 * without an intimate and detailed understanding of the workings of the | |
52 * hierarchy. No support is provided for user-written classes which are | |
53 * implemented as subclasses of this class. | |
54 * </p> | |
55 * | |
56 * @see #checkSubclass | |
57 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
58 */ | |
59 public abstract class Widget { | |
60 /** | |
61 * the handle to the OS resource | |
62 * (Warning: This field is platform dependent) | |
63 * <p> | |
64 * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT | |
65 * public API. It is marked public only so that it can be shared | |
66 * within the packages provided by SWT. It is not available on all | |
67 * platforms and should never be accessed from application code. | |
68 * </p> | |
69 */ | |
70 public GtkWidget* handle; | |
71 int style, state; | |
72 Display display; | |
73 EventTable eventTable; | |
74 Object data; | |
75 | |
76 /* Global state flags */ | |
77 static const int DISPOSED = 1<<0; | |
78 static const int CANVAS = 1<<1; | |
79 static const int KEYED_DATA = 1<<2; | |
80 static const int HANDLE = 1<<3; | |
81 static const int DISABLED = 1<<4; | |
82 static const int MENU = 1<<5; | |
83 static const int OBSCURED = 1<<6; | |
84 static const int MOVED = 1<<7; | |
85 static const int RESIZED = 1<<8; | |
86 static const int ZERO_WIDTH = 1<<9; | |
87 static const int ZERO_HEIGHT = 1<<10; | |
88 static const int HIDDEN = 1<<11; | |
89 static const int FOREGROUND = 1<<12; | |
90 static const int BACKGROUND = 1<<13; | |
91 static const int FONT = 1<<14; | |
92 static const int PARENT_BACKGROUND = 1<<15; | |
93 static const int THEME_BACKGROUND = 1<<16; | |
94 | |
95 /* A layout was requested on this widget */ | |
96 static const int LAYOUT_NEEDED = 1<<17; | |
97 | |
98 /* The preferred size of a child has changed */ | |
99 static const int LAYOUT_CHANGED = 1<<18; | |
100 | |
101 /* A layout was requested in this widget hierachy */ | |
102 static const int LAYOUT_CHILD = 1<<19; | |
103 | |
104 /* More global state flags */ | |
105 static const int RELEASED = 1<<20; | |
106 static const int DISPOSE_SENT = 1<<21; | |
107 static const int FOREIGN_HANDLE = 1<<22; | |
108 static const int DRAG_DETECT = 1<<23; | |
109 | |
110 /* Default size for widgets */ | |
111 static const int DEFAULT_WIDTH = 64; | |
112 static const int DEFAULT_HEIGHT = 64; | |
113 | |
114 /* GTK signals data */ | |
115 static const int ACTIVATE = 1; | |
116 static const int BUTTON_PRESS_EVENT = 2; | |
117 static const int BUTTON_PRESS_EVENT_INVERSE = 3; | |
118 static const int BUTTON_RELEASE_EVENT = 4; | |
119 static const int BUTTON_RELEASE_EVENT_INVERSE = 5; | |
120 static const int CHANGED = 6; | |
121 static const int CHANGE_VALUE = 7; | |
122 static const int CLICKED = 8; | |
123 static const int COMMIT = 9; | |
124 static const int CONFIGURE_EVENT = 10; | |
125 static const int DELETE_EVENT = 11; | |
126 static const int DELETE_RANGE = 12; | |
127 static const int DELETE_TEXT = 13; | |
128 static const int ENTER_NOTIFY_EVENT = 14; | |
129 static const int EVENT = 15; | |
130 static const int EVENT_AFTER = 16; | |
131 static const int EXPAND_COLLAPSE_CURSOR_ROW = 17; | |
132 static const int EXPOSE_EVENT = 18; | |
133 static const int EXPOSE_EVENT_INVERSE = 19; | |
134 static const int FOCUS = 20; | |
135 static const int FOCUS_IN_EVENT = 21; | |
136 static const int FOCUS_OUT_EVENT = 22; | |
137 static const int GRAB_FOCUS = 23; | |
138 static const int HIDE = 24; | |
139 static const int INPUT = 25; | |
140 static const int INSERT_TEXT = 26; | |
141 static const int KEY_PRESS_EVENT = 27; | |
142 static const int KEY_RELEASE_EVENT = 28; | |
143 static const int LEAVE_NOTIFY_EVENT = 29; | |
144 static const int MAP = 30; | |
145 static const int MAP_EVENT = 31; | |
146 static const int MNEMONIC_ACTIVATE = 32; | |
147 static const int MOTION_NOTIFY_EVENT = 33; | |
148 static const int MOTION_NOTIFY_EVENT_INVERSE = 34; | |
149 static const int MOVE_FOCUS = 35; | |
150 static const int OUTPUT = 36; | |
151 static const int POPULATE_POPUP = 37; | |
152 static const int POPUP_MENU = 38; | |
153 static const int PREEDIT_CHANGED = 39; | |
154 static const int REALIZE = 40; | |
155 static const int ROW_ACTIVATED = 41; | |
156 static const int SCROLL_CHILD = 42; | |
157 static const int SCROLL_EVENT = 43; | |
158 static const int SELECT = 44; | |
159 static const int SHOW = 45; | |
160 static const int SHOW_HELP = 46; | |
161 static const int SIZE_ALLOCATE = 47; | |
162 static const int STYLE_SET = 48; | |
163 static const int SWITCH_PAGE = 49; | |
164 static const int TEST_COLLAPSE_ROW = 50; | |
165 static const int TEST_EXPAND_ROW = 51; | |
166 static const int TEXT_BUFFER_INSERT_TEXT = 52; | |
167 static const int TOGGLED = 53; | |
168 static const int UNMAP = 54; | |
169 static const int UNMAP_EVENT = 55; | |
170 static const int UNREALIZE = 56; | |
171 static const int VALUE_CHANGED = 57; | |
172 static const int VISIBILITY_NOTIFY_EVENT = 58; | |
173 static const int WINDOW_STATE_EVENT = 59; | |
174 static const int ACTIVATE_INVERSE = 60; | |
175 static const int DAY_SELECTED = 61; | |
176 static const int MONTH_CHANGED = 62; | |
177 static const int LAST_SIGNAL = 63; | |
178 | |
113 | 179 static String UD_Getter(String name) (){ |
180 return "void* ud"~name~"(){ return getDisplay().getWindowProcUserData( "~name~"); }\n"; | |
181 } | |
25 | 182 |
113 | 183 mixin ( UD_Getter!( "ACTIVATE" )); |
184 mixin ( UD_Getter!( "BUTTON_PRESS_EVENT" )); | |
185 mixin ( UD_Getter!( "BUTTON_PRESS_EVENT_INVERSE" )); | |
186 mixin ( UD_Getter!( "BUTTON_RELEASE_EVENT" )); | |
187 mixin ( UD_Getter!( "BUTTON_RELEASE_EVENT_INVERSE" )); | |
188 mixin ( UD_Getter!( "CHANGED" )); | |
189 mixin ( UD_Getter!( "CHANGE_VALUE" )); | |
190 mixin ( UD_Getter!( "CLICKED" )); | |
191 mixin ( UD_Getter!( "COMMIT" )); | |
192 mixin ( UD_Getter!( "CONFIGURE_EVENT" )); | |
193 mixin ( UD_Getter!( "DELETE_EVENT" )); | |
194 mixin ( UD_Getter!( "DELETE_RANGE" )); | |
195 mixin ( UD_Getter!( "DELETE_TEXT" )); | |
196 mixin ( UD_Getter!( "ENTER_NOTIFY_EVENT" )); | |
197 mixin ( UD_Getter!( "EVENT" )); | |
198 mixin ( UD_Getter!( "EVENT_AFTER" )); | |
199 mixin ( UD_Getter!( "EXPAND_COLLAPSE_CURSOR_ROW" )); | |
200 mixin ( UD_Getter!( "EXPOSE_EVENT" )); | |
201 mixin ( UD_Getter!( "EXPOSE_EVENT_INVERSE" )); | |
202 mixin ( UD_Getter!( "FOCUS" )); | |
203 mixin ( UD_Getter!( "FOCUS_IN_EVENT" )); | |
204 mixin ( UD_Getter!( "FOCUS_OUT_EVENT" )); | |
205 mixin ( UD_Getter!( "GRAB_FOCUS" )); | |
206 mixin ( UD_Getter!( "HIDE" )); | |
207 mixin ( UD_Getter!( "INPUT" )); | |
208 mixin ( UD_Getter!( "INSERT_TEXT" )); | |
209 mixin ( UD_Getter!( "KEY_PRESS_EVENT" )); | |
210 mixin ( UD_Getter!( "KEY_RELEASE_EVENT" )); | |
211 mixin ( UD_Getter!( "LEAVE_NOTIFY_EVENT" )); | |
212 mixin ( UD_Getter!( "MAP" )); | |
213 mixin ( UD_Getter!( "MAP_EVENT" )); | |
214 mixin ( UD_Getter!( "MNEMONIC_ACTIVATE" )); | |
215 mixin ( UD_Getter!( "MOTION_NOTIFY_EVENT" )); | |
216 mixin ( UD_Getter!( "MOTION_NOTIFY_EVENT_INVERSE" )); | |
217 mixin ( UD_Getter!( "MOVE_FOCUS" )); | |
218 mixin ( UD_Getter!( "OUTPUT" )); | |
219 mixin ( UD_Getter!( "POPULATE_POPUP" )); | |
220 mixin ( UD_Getter!( "POPUP_MENU" )); | |
221 mixin ( UD_Getter!( "PREEDIT_CHANGED" )); | |
222 mixin ( UD_Getter!( "REALIZE" )); | |
223 mixin ( UD_Getter!( "ROW_ACTIVATED" )); | |
224 mixin ( UD_Getter!( "SCROLL_CHILD" )); | |
225 mixin ( UD_Getter!( "SCROLL_EVENT" )); | |
226 mixin ( UD_Getter!( "SELECT" )); | |
227 mixin ( UD_Getter!( "SHOW" )); | |
228 mixin ( UD_Getter!( "SHOW_HELP" )); | |
229 mixin ( UD_Getter!( "SIZE_ALLOCATE" )); | |
230 mixin ( UD_Getter!( "STYLE_SET" )); | |
231 mixin ( UD_Getter!( "SWITCH_PAGE" )); | |
232 mixin ( UD_Getter!( "TEST_COLLAPSE_ROW" )); | |
233 mixin ( UD_Getter!( "TEST_EXPAND_ROW" )); | |
234 mixin ( UD_Getter!( "TEXT_BUFFER_INSERT_TEXT" )); | |
235 mixin ( UD_Getter!( "TOGGLED" )); | |
236 mixin ( UD_Getter!( "UNMAP" )); | |
237 mixin ( UD_Getter!( "UNMAP_EVENT" )); | |
238 mixin ( UD_Getter!( "UNREALIZE" )); | |
239 mixin ( UD_Getter!( "VALUE_CHANGED" )); | |
240 mixin ( UD_Getter!( "VISIBILITY_NOTIFY_EVENT" )); | |
241 mixin ( UD_Getter!( "WINDOW_STATE_EVENT" )); | |
242 mixin ( UD_Getter!( "ACTIVATE_INVERSE" )); | |
243 mixin ( UD_Getter!( "DAY_SELECTED" )); | |
244 mixin ( UD_Getter!( "MONTH_CHANGED" )); | |
245 mixin ( UD_Getter!( "LAST_SIGNAL" )); | |
25 | 246 |
247 /** | |
248 * Prevents uninitialized instances from being created outside the package. | |
249 */ | |
250 this () {} | |
251 | |
252 /** | |
253 * Constructs a new instance of this class given its parent | |
254 * and a style value describing its behavior and appearance. | |
255 * <p> | |
256 * The style value is either one of the style constants defined in | |
257 * class <code>SWT</code> which is applicable to instances of this | |
258 * class, or must be built by <em>bitwise OR</em>'ing together | |
259 * (that is, using the <code>int</code> "|" operator) two or more | |
260 * of those <code>SWT</code> style constants. The class description | |
261 * lists the style constants that are applicable to the class. | |
262 * Style bits are also inherited from superclasses. | |
263 * </p> | |
264 * | |
265 * @param parent a widget which will be the parent of the new instance (cannot be null) | |
266 * @param style the style of widget to construct | |
267 * | |
268 * @exception IllegalArgumentException <ul> | |
269 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
270 * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> | |
271 * </ul> | |
272 * @exception SWTException <ul> | |
273 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
274 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
275 * </ul> | |
276 * | |
277 * @see SWT | |
278 * @see #checkSubclass | |
279 * @see #getStyle | |
280 */ | |
281 public this (Widget parent, int style) { | |
282 checkSubclass (); | |
283 checkParent (parent); | |
284 this.style = style; | |
285 display = parent.display; | |
286 } | |
287 | |
288 void _addListener (int eventType, Listener listener) { | |
289 if (eventTable is null) eventTable = new EventTable (); | |
290 eventTable.hook (eventType, listener); | |
291 } | |
292 | |
293 /** | |
294 * Adds the listener to the collection of listeners who will | |
295 * be notified when an event of the given type occurs. When the | |
296 * event does occur in the widget, the listener is notified by | |
297 * sending it the <code>handleEvent()</code> message. The event | |
298 * type is one of the event constants defined in class <code>SWT</code>. | |
299 * | |
300 * @param eventType the type of event to listen for | |
301 * @param listener the listener which should be notified when the event occurs | |
302 * | |
303 * @exception IllegalArgumentException <ul> | |
304 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
305 * </ul> | |
306 * @exception SWTException <ul> | |
307 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
308 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
309 * </ul> | |
310 * | |
311 * @see Listener | |
312 * @see SWT | |
313 * @see #getListeners(int) | |
314 * @see #removeListener(int, Listener) | |
315 * @see #notifyListeners | |
316 */ | |
317 public void addListener (int eventType, Listener listener) { | |
318 checkWidget (); | |
319 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
320 _addListener (eventType, listener); | |
321 } | |
322 | |
323 /** | |
324 * Adds the listener to the collection of listeners who will | |
325 * be notified when the widget is disposed. When the widget is | |
326 * disposed, the listener is notified by sending it the | |
327 * <code>widgetDisposed()</code> message. | |
328 * | |
329 * @param listener the listener which should be notified when the receiver is disposed | |
330 * | |
331 * @exception IllegalArgumentException <ul> | |
332 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
333 * </ul> | |
334 * @exception SWTException <ul> | |
335 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
336 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
337 * </ul> | |
338 * | |
339 * @see DisposeListener | |
340 * @see #removeDisposeListener | |
341 */ | |
342 public void addDisposeListener (DisposeListener listener) { | |
343 checkWidget (); | |
344 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
345 TypedListener typedListener = new TypedListener (listener); | |
346 addListener (SWT.Dispose, typedListener); | |
347 } | |
348 | |
349 GdkWindow* paintWindow () { | |
350 return null; | |
351 } | |
352 | |
353 static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) { | |
354 int mask = int0 | int1 | int2 | int3 | int4 | int5; | |
355 if ((style & mask) is 0) style |= int0; | |
356 if ((style & int0) !is 0) style = (style & ~mask) | int0; | |
357 if ((style & int1) !is 0) style = (style & ~mask) | int1; | |
358 if ((style & int2) !is 0) style = (style & ~mask) | int2; | |
359 if ((style & int3) !is 0) style = (style & ~mask) | int3; | |
360 if ((style & int4) !is 0) style = (style & ~mask) | int4; | |
361 if ((style & int5) !is 0) style = (style & ~mask) | int5; | |
362 return style; | |
363 } | |
364 | |
365 void cellDataProc ( | |
366 GtkTreeViewColumn *tree_column, | |
367 GtkCellRenderer *cell, | |
368 GtkTreeModel *tree_model, | |
369 GtkTreeIter *iter, | |
370 void* data) | |
371 { | |
372 } | |
373 | |
374 void checkOpen () { | |
375 /* Do nothing */ | |
376 } | |
377 | |
378 void checkOrientation (Widget parent) { | |
379 style &= ~SWT.MIRRORED; | |
380 if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) is 0) { | |
381 if (parent !is null) { | |
382 if ((parent.style & SWT.LEFT_TO_RIGHT) !is 0) style |= SWT.LEFT_TO_RIGHT; | |
383 if ((parent.style & SWT.RIGHT_TO_LEFT) !is 0) style |= SWT.RIGHT_TO_LEFT; | |
384 } | |
385 } | |
386 style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0); | |
387 /* Versions of GTK prior to 2.8 do not render RTL text properly */ | |
388 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 0)) { | |
389 style &= ~SWT.RIGHT_TO_LEFT; | |
390 style |= SWT.LEFT_TO_RIGHT; | |
391 } | |
392 } | |
393 | |
394 /** | |
395 * Throws an exception if the specified widget can not be | |
396 * used as a parent for the receiver. | |
397 * | |
398 * @exception IllegalArgumentException <ul> | |
399 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
400 * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> | |
401 * </ul> | |
402 * @exception SWTException <ul> | |
403 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
404 * </ul> | |
405 */ | |
406 void checkParent (Widget parent) { | |
407 if (parent is null) error (SWT.ERROR_NULL_ARGUMENT); | |
408 if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); | |
409 parent.checkWidget (); | |
410 parent.checkOpen (); | |
411 } | |
412 | |
413 /** | |
414 * Checks that this class can be subclassed. | |
415 * <p> | |
416 * The SWT class library is intended to be subclassed | |
417 * only at specific, controlled points (most notably, | |
418 * <code>Composite</code> and <code>Canvas</code> when | |
419 * implementing new widgets). This method enforces this | |
420 * rule unless it is overridden. | |
421 * </p><p> | |
422 * <em>IMPORTANT:</em> By providing an implementation of this | |
423 * method that allows a subclass of a class which does not | |
424 * normally allow subclassing to be created, the implementer | |
425 * agrees to be fully responsible for the fact that any such | |
426 * subclass will likely fail between SWT releases and will be | |
427 * strongly platform specific. No support is provided for | |
428 * user-written classes which are implemented in this fashion. | |
429 * </p><p> | |
430 * The ability to subclass outside of the allowed SWT classes | |
431 * is intended purely to enable those not on the SWT development | |
432 * team to implement patches in order to get around specific | |
433 * limitations in advance of when those limitations can be | |
434 * addressed by the team. Subclassing should not be attempted | |
435 * without an intimate and detailed understanding of the hierarchy. | |
436 * </p> | |
437 * | |
438 * @exception SWTException <ul> | |
439 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
440 * </ul> | |
441 */ | |
442 protected void checkSubclass () { | |
443 if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); | |
444 } | |
445 | |
446 /** | |
447 * Throws an <code>SWTException</code> if the receiver can not | |
448 * be accessed by the caller. This may include both checks on | |
449 * the state of the receiver and more generally on the entire | |
450 * execution context. This method <em>should</em> be called by | |
451 * widget implementors to enforce the standard SWT invariants. | |
452 * <p> | |
453 * Currently, it is an error to invoke any method (other than | |
454 * <code>isDisposed()</code>) on a widget that has had its | |
455 * <code>dispose()</code> method called. It is also an error | |
456 * to call widget methods from any thread that is different | |
457 * from the thread that created the widget. | |
458 * </p><p> | |
459 * In future releases of SWT, there may be more or fewer error | |
460 * checks and exceptions may be thrown for different reasons. | |
461 * </p> | |
462 * | |
463 * @exception SWTException <ul> | |
464 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
465 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
466 * </ul> | |
467 */ | |
468 public void checkWidget () { | |
469 Display display = this.display; | |
470 if (display is null) error (SWT.ERROR_WIDGET_DISPOSED); | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
471 if (display.thread !is Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
25 | 472 if ((state & DISPOSED) !is 0) error (SWT.ERROR_WIDGET_DISPOSED); |
473 } | |
474 | |
475 void createHandle (int index) { | |
476 } | |
477 | |
478 void createWidget (int index) { | |
479 createHandle (index); | |
480 setOrientation (); | |
481 hookEvents (); | |
482 register (); | |
483 } | |
484 | |
485 void deregister () { | |
486 if (handle is null) return; | |
487 if ((state & HANDLE) !is 0) display.removeWidget (handle); | |
488 } | |
489 | |
490 void destroyWidget () { | |
491 GtkWidget* h = topHandle (); | |
492 releaseHandle (); | |
493 if (h !is null && (state & HANDLE) !is 0) { | |
494 OS.gtk_widget_destroy (h); | |
495 } | |
496 } | |
497 | |
498 /** | |
499 * Disposes of the operating system resources associated with | |
500 * the receiver and all its descendants. After this method has | |
501 * been invoked, the receiver and all descendants will answer | |
502 * <code>true</code> when sent the message <code>isDisposed()</code>. | |
503 * Any internal connections between the widgets in the tree will | |
504 * have been removed to facilitate garbage collection. | |
505 * <p> | |
506 * NOTE: This method is not called recursively on the descendants | |
507 * of the receiver. This means that, widget implementers can not | |
508 * detect when a widget is being disposed of by re-implementing | |
509 * this method, but should instead listen for the <code>Dispose</code> | |
510 * event. | |
511 * </p> | |
512 * | |
513 * @exception SWTException <ul> | |
514 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
515 * </ul> | |
516 * | |
517 * @see #addDisposeListener | |
518 * @see #removeDisposeListener | |
519 * @see #checkWidget | |
520 */ | |
521 public void dispose () { | |
522 /* | |
523 * Note: It is valid to attempt to dispose a widget | |
524 * more than once. If this happens, fail silently. | |
525 */ | |
526 if (isDisposed ()) return; | |
527 if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); | |
528 release (true); | |
529 } | |
530 | |
531 void error (int code) { | |
532 SWT.error (code); | |
533 } | |
534 | |
535 /** | |
536 * Returns the application defined widget data associated | |
537 * with the receiver, or null if it has not been set. The | |
538 * <em>widget data</em> is a single, unnamed field that is | |
539 * stored with every widget. | |
540 * <p> | |
541 * Applications may put arbitrary objects in this field. If | |
542 * the object stored in the widget data needs to be notified | |
543 * when the widget is disposed of, it is the application's | |
544 * responsibility to hook the Dispose event on the widget and | |
545 * do so. | |
546 * </p> | |
547 * | |
548 * @return the widget data | |
549 * | |
550 * @exception SWTException <ul> | |
551 * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li> | |
552 * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> | |
553 * </ul> | |
554 * | |
555 * @see #setData(Object) | |
556 */ | |
557 public Object getData () { | |
558 checkWidget(); | |
559 return (state & KEYED_DATA) !is 0 ? (cast(ArrayWrapperObject)data).array[0] : data; | |
560 } | |
561 public String getDataStr () { | |
562 return stringcast( getData() ); | |
563 } | |
564 | |
565 /** | |
566 * Returns the application defined property of the receiver | |
567 * with the specified name, or null if it has not been set. | |
568 * <p> | |
569 * Applications may have associated arbitrary objects with the | |
570 * receiver in this fashion. If the objects stored in the | |
571 * properties need to be notified when the widget is disposed | |
572 * of, it is the application's responsibility to hook the | |
573 * Dispose event on the widget and do so. | |
574 * </p> | |
575 * | |
576 * @param key the name of the property | |
577 * @return the value of the property or null if it has not been set | |
578 * | |
579 * @exception SWTException <ul> | |
580 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
581 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
582 * </ul> | |
583 * | |
584 * @see #setData(String, Object) | |
585 */ | |
586 public Object getData (String key) { | |
587 checkWidget(); | |
588 // SWT extension: allow null for zero length string | |
589 //if (key is null) error (SWT.ERROR_NULL_ARGUMENT); | |
590 if ((state & KEYED_DATA) !is 0) { | |
591 Object[] table = (cast(ArrayWrapperObject) data).array; | |
592 for (int i=1; i<table.length; i+=2) { | |
51 | 593 String tablekey = stringcast(table[i]); |
594 if (key.equals( tablekey) ) return table [i+1]; | |
25 | 595 } |
596 } | |
597 return null; | |
598 } | |
599 public String getDataStr (String key) { | |
600 return stringcast( getData(key) ); | |
601 } | |
602 | |
603 /** | |
604 * Returns the <code>Display</code> that is associated with | |
605 * the receiver. | |
606 * <p> | |
607 * A widget's display is either provided when it is created | |
608 * (for example, top level <code>Shell</code>s) or is the | |
609 * same as its parent's display. | |
610 * </p> | |
611 * | |
612 * @return the receiver's display | |
613 * | |
614 * @exception SWTException <ul> | |
615 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
616 * </ul> | |
617 */ | |
618 public Display getDisplay () { | |
619 Display display = this.display; | |
620 if (display is null) error (SWT.ERROR_WIDGET_DISPOSED); | |
621 return display; | |
622 } | |
623 | |
624 /** | |
625 * Returns an array of listeners who will be notified when an event | |
626 * of the given type occurs. The event type is one of the event constants | |
627 * defined in class <code>SWT</code>. | |
628 * | |
629 * @param eventType the type of event to listen for | |
630 * @return an array of listeners that will be notified when the event occurs | |
631 * | |
632 * @exception SWTException <ul> | |
633 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
634 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
635 * </ul> | |
636 * | |
637 * @see Listener | |
638 * @see SWT | |
639 * @see #addListener(int, Listener) | |
640 * @see #removeListener(int, Listener) | |
641 * @see #notifyListeners | |
642 * | |
643 * @since 3.4 | |
644 */ | |
645 public Listener[] getListeners (int eventType) { | |
646 checkWidget(); | |
647 if (eventTable is null) return new Listener[0]; | |
648 return eventTable.getListeners(eventType); | |
649 } | |
650 | |
651 String getName () { | |
652 // String str = getClass ().getName (); | |
653 // int index = str.lastIndexOf ('.'); | |
654 // if (index is -1) return str; | |
655 String str = this.classinfo.name; | |
656 int index = str.length; | |
657 while ((--index > 0) && (str[index] !is '.')) {} | |
658 return str[index + 1 .. $ ]; | |
659 } | |
660 | |
661 String getNameText () { | |
662 return ""; | |
663 } | |
664 | |
665 /** | |
666 * Returns the receiver's style information. | |
667 * <p> | |
668 * Note that the value which is returned by this method <em>may | |
669 * not match</em> the value which was provided to the constructor | |
670 * when the receiver was created. This can occur when the underlying | |
671 * operating system does not support a particular combination of | |
672 * requested styles. For example, if the platform widget used to | |
673 * implement a particular SWT widget always has scroll bars, the | |
674 * result of calling this method would always have the | |
675 * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set. | |
676 * </p> | |
677 * | |
678 * @return the style bits | |
679 * | |
680 * @exception SWTException <ul> | |
681 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
682 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
683 * </ul> | |
684 */ | |
685 public int getStyle () { | |
686 checkWidget (); | |
687 return style; | |
688 } | |
689 | |
690 | |
691 int /*long*/ gtk_activate (GtkWidget* widget) { | |
692 return 0; | |
693 } | |
694 | |
695 int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) { | |
696 return 0; | |
697 } | |
698 | |
699 int /*long*/ gtk_button_release_event (GtkWidget* widget, GdkEventButton* event) { | |
700 return 0; | |
701 } | |
702 | |
703 int /*long*/ gtk_changed (GtkWidget* widget) { | |
704 return 0; | |
705 } | |
706 | |
707 int /*long*/ gtk_change_value (GtkWidget* widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) { | |
708 return 0; | |
709 } | |
710 | |
711 int /*long*/ gtk_clicked (GtkWidget* widget) { | |
712 return 0; | |
713 } | |
714 | |
715 int /*long*/ gtk_commit (GtkIMContext* imcontext, char* text) { | |
716 return 0; | |
717 } | |
718 | |
719 int /*long*/ gtk_configure_event (GtkWidget* widget, int /*long*/ event) { | |
720 return 0; | |
721 } | |
722 | |
723 int /*long*/ gtk_day_selected (GtkWidget* widget) { | |
724 return 0; | |
725 } | |
726 | |
727 int /*long*/ gtk_delete_event (GtkWidget* widget, int /*long*/ event) { | |
728 return 0; | |
729 } | |
730 | |
731 int /*long*/ gtk_delete_range (GtkWidget* widget, int /*long*/ iter1, int /*long*/ iter2) { | |
732 return 0; | |
733 } | |
734 | |
735 int /*long*/ gtk_delete_text (GtkWidget* widget, int /*long*/ start_pos, int /*long*/ end_pos) { | |
736 return 0; | |
737 } | |
738 | |
739 int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { | |
740 return 0; | |
741 } | |
742 | |
743 int /*long*/ gtk_event (GtkWidget* widget, GdkEvent* event) { | |
744 return 0; | |
745 } | |
746 | |
747 int /*long*/ gtk_event_after (GtkWidget* widget, GdkEvent* event) { | |
748 return 0; | |
749 } | |
750 | |
751 int /*long*/ gtk_expand_collapse_cursor_row (GtkWidget* widget, int /*long*/ logical, int /*long*/ expand, int /*long*/ open_all) { | |
752 return 0; | |
753 } | |
754 | |
755 int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* event) { | |
756 return 0; | |
757 } | |
758 | |
759 int /*long*/ gtk_focus (GtkWidget* widget, int directionType) { | |
760 return 0; | |
761 } | |
762 | |
763 int /*long*/ gtk_focus_in_event (GtkWidget* widget, GdkEventFocus* event) { | |
764 return 0; | |
765 } | |
766 | |
767 int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { | |
768 return 0; | |
769 } | |
770 | |
771 int /*long*/ gtk_grab_focus (GtkWidget* widget) { | |
772 return 0; | |
773 } | |
774 | |
775 int /*long*/ gtk_hide (GtkWidget* widget) { | |
776 return 0; | |
777 } | |
778 | |
779 int /*long*/ gtk_input (GtkWidget* widget, int /*long*/ arg1) { | |
780 return 0; | |
781 } | |
782 | |
783 int /*long*/ gtk_insert_text (GtkEditable* widget, char* new_text, int new_text_length, int position) { | |
784 return 0; | |
785 } | |
786 | |
787 int /*long*/ gtk_key_press_event (GtkWidget* widget, GdkEventKey* event) { | |
788 return sendKeyEvent (SWT.KeyDown, event) ? 0 : 1; | |
789 } | |
790 | |
791 int /*long*/ gtk_key_release_event (GtkWidget* widget, GdkEventKey* event) { | |
792 return sendKeyEvent (SWT.KeyUp, event) ? 0 : 1; | |
793 } | |
794 | |
795 int /*long*/ gtk_leave_notify_event (GtkWidget* widget, GdkEventCrossing* event) { | |
796 return 0; | |
797 } | |
798 | |
799 int /*long*/ gtk_map (GtkWidget* widget) { | |
800 return 0; | |
801 } | |
802 | |
803 int /*long*/ gtk_map_event (GtkWidget* widget, int /*long*/ event) { | |
804 return 0; | |
805 } | |
806 | |
807 int /*long*/ gtk_mnemonic_activate (GtkWidget* widget, int /*long*/ arg1) { | |
808 return 0; | |
809 } | |
810 | |
811 int /*long*/ gtk_month_changed (GtkWidget* widget) { | |
812 return 0; | |
813 } | |
814 | |
815 int /*long*/ gtk_motion_notify_event (GtkWidget* widget, GdkEventMotion* event) { | |
816 return 0; | |
817 } | |
818 | |
819 int /*long*/ gtk_move_focus (GtkWidget* widget, int directionType) { | |
820 return 0; | |
821 } | |
822 | |
823 int /*long*/ gtk_output (GtkWidget* widget) { | |
824 return 0; | |
825 } | |
826 | |
827 int /*long*/ gtk_populate_popup (GtkWidget* widget, GtkWidget* menu) { | |
828 return 0; | |
829 } | |
830 | |
831 int /*long*/ gtk_popup_menu (GtkWidget* widget) { | |
832 return 0; | |
833 } | |
834 | |
835 int /*long*/ gtk_preedit_changed (GtkIMContext* imcontext) { | |
836 return 0; | |
837 } | |
838 | |
839 int /*long*/ gtk_realize (GtkWidget* widget) { | |
840 return 0; | |
841 } | |
842 | |
843 void gtk_row_activated (GtkTreeView* tree, GtkTreePath* path, GtkTreeViewColumn* column) { | |
844 } | |
845 | |
846 int /*long*/ gtk_scroll_child (GtkWidget* widget, int /*long*/ scrollType, int /*long*/ horizontal) { | |
847 return 0; | |
848 } | |
849 | |
850 int /*long*/ gtk_scroll_event (GtkWidget* widget, GdkEventScroll* event) { | |
851 return 0; | |
852 } | |
853 | |
854 int /*long*/ gtk_select (int /*long*/ item) { | |
855 return 0; | |
856 } | |
857 | |
858 int /*long*/ gtk_show (GtkWidget* widget) { | |
859 return 0; | |
860 } | |
861 | |
862 int /*long*/ gtk_show_help (GtkWidget* widget, int /*long*/ helpType) { | |
863 return 0; | |
864 } | |
865 | |
866 int /*long*/ gtk_size_allocate (GtkWidget* widget, int /*long*/ allocation) { | |
867 return 0; | |
868 } | |
869 | |
870 int /*long*/ gtk_style_set (GtkWidget* widget, int /*long*/ previousStyle) { | |
871 return 0; | |
872 } | |
873 | |
874 int /*long*/ gtk_switch_page (GtkWidget* widget, int /*long*/ page, int /*long*/ page_num) { | |
875 return 0; | |
876 } | |
877 | |
878 int gtk_test_collapse_row ( | |
879 GtkTreeView *tree_view, | |
880 GtkTreeIter *iter, | |
881 GtkTreePath *path) | |
882 { | |
883 return 0; | |
884 } | |
885 | |
886 int /*long*/ gtk_test_expand_row ( | |
887 GtkTreeView *tree_view, | |
888 GtkTreeIter *iter, | |
889 GtkTreePath *path) | |
890 { | |
891 return 0; | |
892 } | |
893 | |
894 int /*long*/ gtk_text_buffer_insert_text (GtkTextBuffer *buffer, GtkTextIter *iter, char *text, int len) { | |
895 return 0; | |
896 } | |
897 | |
898 int /*long*/ gtk_timer () { | |
899 return 0; | |
900 } | |
901 | |
902 int /*long*/ gtk_toggled (int /*long*/ renderer, char* pathStr) { | |
903 return 0; | |
904 } | |
905 | |
906 int /*long*/ gtk_unmap (GtkWidget* widget) { | |
907 return 0; | |
908 } | |
909 | |
910 int /*long*/ gtk_unmap_event (GtkWidget* widget, int /*long*/ event) { | |
911 return 0; | |
912 } | |
913 | |
914 int /*long*/ gtk_unrealize (GtkWidget* widget) { | |
915 return 0; | |
916 } | |
917 | |
918 int /*long*/ gtk_value_changed (int /*long*/ adjustment) { | |
919 return 0; | |
920 } | |
921 | |
922 int /*long*/ gtk_visibility_notify_event (GtkWidget* widget, GdkEventVisibility* event) { | |
923 return 0; | |
924 } | |
925 | |
926 int /*long*/ gtk_window_state_event (GtkWidget* widget, GdkEventWindowState* event) { | |
927 return 0; | |
928 } | |
929 | |
930 int fontHeight ( PangoFontDescription* font, GtkWidget* widgetHandle ) { | |
931 auto context = OS.gtk_widget_get_pango_context (widgetHandle); | |
932 auto lang = OS.pango_context_get_language (context); | |
933 auto metrics = OS.pango_context_get_metrics (context, font, lang); | |
934 int ascent = OS.pango_font_metrics_get_ascent (metrics); | |
935 int descent = OS.pango_font_metrics_get_descent (metrics); | |
936 OS.pango_font_metrics_unref (metrics); | |
937 return OS.PANGO_PIXELS (ascent + descent); | |
938 } | |
939 | |
940 int filterProc (XEvent* xEvent, GdkEvent* gdkEvent, void* data) { | |
941 return 0; | |
942 } | |
943 | |
944 bool filters (int eventType) { | |
945 return display.filters (eventType); | |
946 } | |
947 | |
948 int /*long*/ fixedMapProc (GtkWidget* widget) { | |
949 return 0; | |
950 } | |
951 | |
952 void fixedSizeAllocateProc(GtkWidget* widget, GtkAllocation* allocationPtr) { | |
953 return Display.oldFixedSizeAllocateProc(widget, allocationPtr); | |
954 } | |
955 | |
956 char [] fixMnemonic (String str) { | |
957 return fixMnemonic (str, true); | |
958 } | |
959 | |
960 char [] fixMnemonic (String str, bool replace) { | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
961 char[] text = str.dup; |
25 | 962 int i = 0, j = 0; |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
963 char [] result = new char [str.length * 2]; |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
964 while (i < str.length) { |
25 | 965 switch (text [i]) { |
966 case '&': | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
967 if (i + 1 < str.length && text [i + 1] == '&') { |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
968 result [j++] = text [i++]; |
25 | 969 } else { |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
970 if (replace) result [j++] = '_'; |
25 | 971 } |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
972 i++; |
25 | 973 break; |
974 case '_': | |
975 if (replace) result [j++] = '_'; | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
976 //FALL THROUGH |
25 | 977 default: |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
978 result [j++] = text [i++]; |
25 | 979 } |
980 } | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
981 if (j < result.length) result [j++] = 0; |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
982 return result[0 .. j]; |
25 | 983 } |
984 | |
985 /** | |
986 * Returns <code>true</code> if the widget has been disposed, | |
987 * and <code>false</code> otherwise. | |
988 * <p> | |
989 * This method gets the dispose state for the widget. | |
990 * When a widget has been disposed, it is an error to | |
991 * invoke any other method using the widget. | |
992 * </p> | |
993 * | |
994 * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise | |
995 */ | |
996 public bool isDisposed () { | |
997 return (state & DISPOSED) !is 0; | |
998 } | |
999 | |
1000 /** | |
1001 * Returns <code>true</code> if there are any listeners | |
1002 * for the specified event type associated with the receiver, | |
1003 * and <code>false</code> otherwise. The event type is one of | |
1004 * the event constants defined in class <code>SWT</code>. | |
1005 * | |
1006 * @param eventType the type of event | |
1007 * @return true if the event is hooked | |
1008 * | |
1009 * @exception SWTException <ul> | |
1010 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1011 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1012 * </ul> | |
1013 * | |
1014 * @see SWT | |
1015 */ | |
1016 public bool isListening (int eventType) { | |
1017 checkWidget (); | |
1018 return hooks (eventType); | |
1019 } | |
1020 | |
1021 bool isValidThread () { | |
1022 return getDisplay ().isValidThread (); | |
1023 } | |
1024 | |
1025 bool isValidSubclass() { | |
1026 return true;//Display.isValidClass(getClass()); | |
1027 } | |
1028 | |
1029 void hookEvents () { | |
1030 } | |
1031 | |
1032 /* | |
1033 * Returns <code>true</code> if the specified eventType is | |
1034 * hooked, and <code>false</code> otherwise. Implementations | |
1035 * of SWT can avoid creating objects and sending events | |
1036 * when an event happens in the operating system but | |
1037 * there are no listeners hooked for the event. | |
1038 * | |
1039 * @param eventType the event to be checked | |
1040 * | |
1041 * @return <code>true</code> when the eventType is hooked and <code>false</code> otherwise | |
1042 * | |
1043 * @see #isListening | |
1044 */ | |
1045 bool hooks (int eventType) { | |
1046 if (eventTable is null) return false; | |
1047 return eventTable.hooks (eventType); | |
1048 } | |
1049 | |
1050 int /*long*/ hoverProc (GtkWidget* widget) { | |
1051 return 0; | |
1052 } | |
1053 | |
1054 void menuPositionProc (GtkMenu* menu, int* x, int* y, int* push_in, void* user_data) { | |
1055 } | |
1056 | |
1057 bool mnemonicHit (GtkWidget* mnemonicHandle, wchar key) { | |
1058 if (!mnemonicMatch (mnemonicHandle, key)) return false; | |
1059 OS.g_signal_handlers_block_matched ( cast(void*)mnemonicHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udMNEMONIC_ACTIVATE); | |
1060 bool result = cast(bool)OS.gtk_widget_mnemonic_activate (cast(GtkWidget*)mnemonicHandle, false); | |
1061 OS.g_signal_handlers_unblock_matched (cast(void*)mnemonicHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udMNEMONIC_ACTIVATE); | |
1062 return result; | |
1063 } | |
1064 | |
1065 bool mnemonicMatch (GtkWidget* mnemonicHandle, wchar key) { | |
1066 int keyval1 = OS.gdk_keyval_to_lower (OS.gdk_unicode_to_keyval (key)); | |
1067 int keyval2 = OS.gdk_keyval_to_lower (OS.gtk_label_get_mnemonic_keyval (cast(GtkLabel*)mnemonicHandle)); | |
1068 return keyval1 is keyval2; | |
1069 } | |
1070 | |
1071 void modifyStyle (GtkWidget* handle, GtkRcStyle* style) { | |
1072 OS.gtk_widget_modify_style (handle, style); | |
1073 } | |
1074 | |
1075 /** | |
1076 * Notifies all of the receiver's listeners for events | |
1077 * of the given type that one such event has occurred by | |
1078 * invoking their <code>handleEvent()</code> method. The | |
1079 * event type is one of the event constants defined in class | |
1080 * <code>SWT</code>. | |
1081 * | |
1082 * @param eventType the type of event which has occurred | |
1083 * @param event the event data | |
1084 * | |
1085 * @exception SWTException <ul> | |
1086 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1087 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1088 * </ul> | |
1089 * | |
1090 * @see SWT | |
1091 * @see #addListener | |
1092 * @see #getListeners(int) | |
1093 * @see #removeListener(int, Listener) | |
1094 */ | |
1095 public void notifyListeners (int eventType, Event event) { | |
1096 checkWidget(); | |
1097 if (event is null) event = new Event (); | |
1098 sendEvent (eventType, event); | |
1099 } | |
1100 | |
1101 void postEvent (int eventType) { | |
1102 sendEvent (eventType, null, false); | |
1103 } | |
1104 | |
1105 void postEvent (int eventType, Event event) { | |
1106 sendEvent (eventType, event, false); | |
1107 } | |
1108 | |
1109 void register () { | |
1110 if (handle is null) return; | |
1111 if ((state & HANDLE) !is 0) display.addWidget (handle, this); | |
1112 } | |
1113 | |
1114 void release (bool destroy) { | |
1115 if ((state & DISPOSE_SENT) is 0) { | |
1116 state |= DISPOSE_SENT; | |
1117 sendEvent (SWT.Dispose); | |
1118 } | |
1119 if ((state & DISPOSED) is 0) { | |
1120 releaseChildren (destroy); | |
1121 } | |
1122 if ((state & RELEASED) is 0) { | |
1123 state |= RELEASED; | |
1124 if (destroy) { | |
1125 releaseParent (); | |
1126 releaseWidget (); | |
1127 destroyWidget (); | |
1128 } else { | |
1129 releaseWidget (); | |
1130 releaseHandle (); | |
1131 } | |
1132 } | |
1133 } | |
1134 | |
1135 void releaseChildren (bool destroy) { | |
1136 } | |
1137 | |
1138 void releaseHandle () { | |
1139 handle = null; | |
1140 state |= DISPOSED; | |
1141 display = null; | |
1142 } | |
1143 | |
1144 void releaseParent () { | |
1145 /* Do nothing */ | |
1146 } | |
1147 | |
1148 void releaseWidget () { | |
1149 deregister (); | |
1150 eventTable = null; | |
1151 data = null; | |
1152 } | |
1153 | |
1154 /** | |
1155 * Removes the listener from the collection of listeners who will | |
1156 * be notified when an event of the given type occurs. The event | |
1157 * type is one of the event constants defined in class <code>SWT</code>. | |
1158 * | |
1159 * @param eventType the type of event to listen for | |
1160 * @param listener the listener which should no longer be notified | |
1161 * | |
1162 * @exception IllegalArgumentException <ul> | |
1163 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
1164 * </ul> | |
1165 * @exception SWTException <ul> | |
1166 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1167 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1168 * </ul> | |
1169 * | |
1170 * @see Listener | |
1171 * @see SWT | |
1172 * @see #addListener | |
1173 * @see #getListeners(int) | |
1174 * @see #notifyListeners | |
1175 */ | |
1176 public void removeListener (int eventType, Listener handler) { | |
1177 checkWidget (); | |
1178 if (handler is null) error (SWT.ERROR_NULL_ARGUMENT); | |
1179 if (eventTable is null) return; | |
1180 eventTable.unhook (eventType, handler); | |
1181 } | |
1182 | |
1183 /** | |
1184 * Removes the listener from the collection of listeners who will | |
1185 * be notified when an event of the given type occurs. | |
1186 * <p> | |
1187 * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT | |
1188 * public API. It is marked public only so that it can be shared | |
1189 * within the packages provided by SWT. It should never be | |
1190 * referenced from application code. | |
1191 * </p> | |
1192 * | |
1193 * @param eventType the type of event to listen for | |
1194 * @param listener the listener which should no longer be notified | |
1195 * | |
1196 * @exception IllegalArgumentException <ul> | |
1197 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
1198 * </ul> | |
1199 * @exception SWTException <ul> | |
1200 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1201 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1202 * </ul> | |
1203 * | |
1204 * @see Listener | |
1205 * @see #addListener | |
1206 */ | |
1207 protected void removeListener (int eventType, SWTEventListener handler) { | |
1208 checkWidget (); | |
1209 if (handler is null) error (SWT.ERROR_NULL_ARGUMENT); | |
1210 if (eventTable is null) return; | |
1211 eventTable.unhook (eventType, handler); | |
1212 } | |
1213 | |
1214 void rendererGetSizeProc ( | |
1215 GtkCellRenderer *cell, | |
1216 GtkWidget *widget, | |
1217 GdkRectangle *cell_area, | |
1218 int *x_offset, | |
1219 int *y_offset, | |
1220 int *width, | |
1221 int *height) | |
1222 { | |
1223 } | |
1224 | |
1225 void rendererRenderProc ( | |
1226 GtkCellRenderer * cell, | |
1227 GdkDrawable * window, | |
1228 GtkWidget * widget, | |
1229 GdkRectangle *background_area, | |
1230 GdkRectangle *cell_area, | |
1231 GdkRectangle *expose_area, | |
1232 int flags) | |
1233 { | |
1234 } | |
1235 | |
1236 /** | |
1237 * Removes the listener from the collection of listeners who will | |
1238 * be notified when the widget is disposed. | |
1239 * | |
1240 * @param listener the listener which should no longer be notified | |
1241 * | |
1242 * @exception IllegalArgumentException <ul> | |
1243 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
1244 * </ul> | |
1245 * @exception SWTException <ul> | |
1246 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1247 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1248 * </ul> | |
1249 * | |
1250 * @see DisposeListener | |
1251 * @see #addDisposeListener | |
1252 */ | |
1253 public void removeDisposeListener (DisposeListener listener) { | |
1254 checkWidget (); | |
1255 if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); | |
1256 if (eventTable is null) return; | |
1257 eventTable.unhook (SWT.Dispose, listener); | |
1258 } | |
1259 | |
1260 | |
1261 void sendEvent (Event event) { | |
1262 Display display = event.display; | |
1263 if (!display.filterEvent (event)) { | |
1264 if (eventTable !is null) eventTable.sendEvent (event); | |
1265 } | |
1266 } | |
1267 | |
1268 void sendEvent (int eventType) { | |
1269 sendEvent (eventType, null, true); | |
1270 } | |
1271 | |
1272 void sendEvent (int eventType, Event event) { | |
1273 sendEvent (eventType, event, true); | |
1274 } | |
1275 | |
1276 void sendEvent (int eventType, Event event, bool send) { | |
1277 if (eventTable is null && !display.filters (eventType)) { | |
1278 return; | |
1279 } | |
1280 if (event is null) event = new Event (); | |
1281 event.type = eventType; | |
1282 event.display = display; | |
1283 event.widget = this; | |
1284 if (event.time is 0) { | |
1285 event.time = display.getLastEventTime (); | |
1286 } | |
1287 if (send) { | |
1288 sendEvent (event); | |
1289 } else { | |
1290 display.postEvent (event); | |
1291 } | |
1292 } | |
1293 | |
1294 bool sendKeyEvent (int type, GdkEventKey* keyEvent) { | |
1295 int len = keyEvent.length; | |
1296 if (keyEvent.string is null || OS.g_utf8_strlen (keyEvent.string, len) <= 1) { | |
1297 Event event = new Event (); | |
1298 event.time = keyEvent.time; | |
1299 if (!setKeyState (event, keyEvent)) return true; | |
1300 sendEvent (type, event); | |
1301 // widget could be disposed at this point | |
1302 | |
1303 /* | |
1304 * It is possible (but unlikely), that application | |
1305 * code could have disposed the widget in the key | |
1306 * events. If this happens, end the processing of | |
1307 * the key by returning false. | |
1308 */ | |
1309 if (isDisposed ()) return false; | |
1310 return event.doit; | |
1311 } | |
1312 char [] chars = fromStringz( keyEvent.string ); | |
1313 return sendIMKeyEvent (type, keyEvent, chars) !is null; | |
1314 } | |
1315 | |
1316 char [] sendIMKeyEvent (int type, GdkEventKey* keyEvent, char [] chars) { | |
1317 int index = 0, count = 0, state = 0; | |
1318 GdkEvent* ptr = null; | |
1319 if (keyEvent is null) { | |
1320 ptr = OS.gtk_get_current_event (); | |
1321 if (ptr !is null) { | |
1322 keyEvent = cast(GdkEventKey*)ptr; | |
1323 switch (cast(int)keyEvent.type) { | |
1324 case OS.GDK_KEY_PRESS: | |
1325 case OS.GDK_KEY_RELEASE: | |
1326 state = keyEvent.state; | |
1327 break; | |
1328 default: | |
1329 keyEvent = null; | |
1330 break; | |
1331 } | |
1332 } | |
1333 } | |
1334 if (keyEvent is null) { | |
1335 int buffer; | |
1336 OS.gtk_get_current_event_state (&buffer); | |
1337 state = buffer; | |
1338 } | |
1339 while (index < chars.length) { | |
1340 Event event = new Event (); | |
1341 //PORTING take care of utf8 | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
1342 if (keyEvent !is null && chars.UCScount() <= 1) { |
25 | 1343 setKeyState (event, keyEvent); |
1344 } else { | |
1345 setInputState (event, state); | |
1346 } | |
1347 //PORTING take care of utf8 | |
1348 int incr; | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
113
diff
changeset
|
1349 event.character = cast(wchar) chars.dcharAt(index, incr); |
25 | 1350 sendEvent (type, event); |
1351 | |
1352 /* | |
1353 * It is possible (but unlikely), that application | |
1354 * code could have disposed the widget in the key | |
1355 * events. If this happens, end the processing of | |
1356 * the key by returning null. | |
1357 */ | |
1358 if (isDisposed ()) { | |
1359 if (ptr !is null) OS.gdk_event_free (ptr); | |
1360 return null; | |
1361 } | |
1362 | |
1363 //PORTING take care of utf8 | |
1364 if (event.doit) { | |
1365 for( int i = 0; i < incr; i++ ){ | |
1366 chars [count+i] = chars [index+i]; | |
1367 } | |
1368 count+=incr; | |
1369 } | |
1370 index+=incr; | |
1371 } | |
1372 if (ptr !is null) OS.gdk_event_free (ptr); | |
1373 if (count is 0) return null; | |
1374 if (index !is count) { | |
1375 char [] result = new char [count]; | |
1376 System.arraycopy (chars, 0, result, 0, count); | |
1377 return result; | |
1378 } | |
1379 return chars; | |
1380 } | |
1381 | |
1382 /** | |
1383 * Sets the application defined widget data associated | |
1384 * with the receiver to be the argument. The <em>widget | |
1385 * data</em> is a single, unnamed field that is stored | |
1386 * with every widget. | |
1387 * <p> | |
1388 * Applications may put arbitrary objects in this field. If | |
1389 * the object stored in the widget data needs to be notified | |
1390 * when the widget is disposed of, it is the application's | |
1391 * responsibility to hook the Dispose event on the widget and | |
1392 * do so. | |
1393 * </p> | |
1394 * | |
1395 * @param data the widget data | |
1396 * | |
1397 * @exception SWTException <ul> | |
1398 * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li> | |
1399 * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> | |
1400 * </ul> | |
1401 * | |
1402 * @see #getData() | |
1403 */ | |
1404 public void setData (Object data) { | |
1405 checkWidget(); | |
1406 if ((state & KEYED_DATA) !is 0) { | |
1407 (cast(ArrayWrapperObject) this.data).array[0] = data; | |
1408 } else { | |
1409 this.data = data; | |
1410 } | |
1411 } | |
1412 public void setDataStr (String data) { | |
1413 setData( stringcast(data)); | |
1414 } | |
1415 | |
1416 /** | |
1417 * Sets the application defined property of the receiver | |
1418 * with the specified name to the given value. | |
1419 * <p> | |
1420 * Applications may associate arbitrary objects with the | |
1421 * receiver in this fashion. If the objects stored in the | |
1422 * properties need to be notified when the widget is disposed | |
1423 * of, it is the application's responsibility to hook the | |
1424 * Dispose event on the widget and do so. | |
1425 * </p> | |
1426 * | |
1427 * @param key the name of the property | |
1428 * @param value the new value for the property | |
1429 * | |
1430 * @exception SWTException <ul> | |
1431 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1432 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1433 * </ul> | |
1434 * | |
1435 * @see #getData(String) | |
1436 */ | |
1437 public void setData (String key, Object value) { | |
1438 checkWidget(); | |
1439 // SWT extension: allow null for zero length string | |
1440 //if (key is null) error (SWT.ERROR_NULL_ARGUMENT); | |
1441 int index = 1; | |
1442 Object [] table = null; | |
1443 if ((state & KEYED_DATA) !is 0) { | |
1444 table = (cast(ArrayWrapperObject) data).array; | |
1445 while (index < table.length) { | |
51 | 1446 String tablekey = stringcast(table[index]); |
25 | 1447 if (key.equals (tablekey) ) break; |
1448 index += 2; | |
1449 } | |
1450 } | |
1451 if (value !is null) { | |
1452 if ((state & KEYED_DATA) !is 0) { | |
1453 if (index is table.length) { | |
1454 Object [] newTable = new Object [table.length + 2]; | |
1455 System.arraycopy (table, 0, newTable, 0, table.length); | |
1456 table = newTable; | |
1457 data = new ArrayWrapperObject( table ); | |
1458 } | |
1459 } else { | |
1460 table = new Object [3]; | |
1461 table [0] = data; | |
1462 data = new ArrayWrapperObject( table ); | |
1463 state |= KEYED_DATA; | |
1464 } | |
1465 table [index] = new ArrayWrapperString( key ); | |
1466 table [index + 1] = value; | |
1467 } else { | |
1468 if ((state & KEYED_DATA) !is 0) { | |
1469 if (index !is table.length) { | |
1470 int len = table.length - 2; | |
1471 if (len is 1) { | |
1472 data = table [0]; | |
1473 state &= ~KEYED_DATA; | |
1474 } else { | |
1475 Object [] newTable = new Object [len]; | |
1476 System.arraycopy (table, 0, newTable, 0, index); | |
1477 System.arraycopy (table, index + 2, newTable, index, len - index); | |
1478 data = new ArrayWrapperObject( newTable ); | |
1479 } | |
1480 } | |
1481 } | |
1482 } | |
1483 } | |
1484 public void setDataStr (String key, String value) { | |
1485 setData(key, stringcast(value)); | |
1486 } | |
1487 | |
1488 void setForegroundColor (GtkWidget* handle, GdkColor* color) { | |
1489 auto style = OS.gtk_widget_get_modifier_style (handle); | |
1490 OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_NORMAL, color); | |
1491 OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_ACTIVE, color); | |
1492 OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_PRELIGHT, color); | |
1493 int flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL); | |
1494 flags = (color is null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG; | |
1495 OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_NORMAL, flags); | |
1496 flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_ACTIVE); | |
1497 flags = (color is null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG; | |
1498 OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_ACTIVE, flags); | |
1499 flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_PRELIGHT); | |
1500 flags = (color is null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG; | |
1501 OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_PRELIGHT, flags); | |
1502 | |
1503 OS.gtk_rc_style_set_text (style, OS.GTK_STATE_NORMAL, color); | |
1504 OS.gtk_rc_style_set_text (style, OS.GTK_STATE_ACTIVE, color); | |
1505 OS.gtk_rc_style_set_text (style, OS.GTK_STATE_PRELIGHT, color); | |
1506 flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL); | |
1507 flags = (color is null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT; | |
1508 OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_NORMAL, flags); | |
1509 flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_PRELIGHT); | |
1510 flags = (color is null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT; | |
1511 OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_PRELIGHT, flags); | |
1512 flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_ACTIVE); | |
1513 flags = (color is null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT; | |
1514 OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_ACTIVE, flags); | |
1515 modifyStyle (handle, style); | |
1516 } | |
1517 | |
1518 bool setInputState (Event event, int state) { | |
1519 if ((state & OS.GDK_MOD1_MASK) !is 0) event.stateMask |= SWT.ALT; | |
1520 if ((state & OS.GDK_SHIFT_MASK) !is 0) event.stateMask |= SWT.SHIFT; | |
1521 if ((state & OS.GDK_CONTROL_MASK) !is 0) event.stateMask |= SWT.CONTROL; | |
1522 if ((state & OS.GDK_BUTTON1_MASK) !is 0) event.stateMask |= SWT.BUTTON1; | |
1523 if ((state & OS.GDK_BUTTON2_MASK) !is 0) event.stateMask |= SWT.BUTTON2; | |
1524 if ((state & OS.GDK_BUTTON3_MASK) !is 0) event.stateMask |= SWT.BUTTON3; | |
1525 return true; | |
1526 } | |
1527 | |
1528 bool setKeyState (Event event, GdkEventKey* keyEvent) { | |
1529 if (keyEvent.string !is null && OS.g_utf8_strlen (keyEvent.string, keyEvent.length) > 1) return false; | |
1530 bool isNull = false; | |
1531 event.keyCode = Display.translateKey (keyEvent.keyval); | |
1532 switch (keyEvent.keyval) { | |
1533 case OS.GDK_BackSpace: event.character = SWT.BS; break; | |
1534 case OS.GDK_Linefeed: event.character = SWT.LF; break; | |
1535 case OS.GDK_KP_Enter: | |
1536 case OS.GDK_Return: event.character = SWT.CR; break; | |
1537 case OS.GDK_KP_Delete: | |
1538 case OS.GDK_Delete: event.character = SWT.DEL; break; | |
1539 case OS.GDK_Escape: event.character = SWT.ESC; break; | |
1540 case OS.GDK_Tab: | |
1541 case OS.GDK_ISO_Left_Tab: event.character = SWT.TAB; break; | |
1542 default: { | |
1543 if (event.keyCode is 0) { | |
1544 uint keyval; | |
1545 int effective_group, level; | |
1546 int consumed_modifiers; | |
1547 if (OS.gdk_keymap_translate_keyboard_state(OS.gdk_keymap_get_default (), keyEvent.hardware_keycode, 0, keyEvent.group, &keyval, &effective_group, &level, &consumed_modifiers)) { | |
1548 event.keyCode = OS.gdk_keyval_to_unicode (keyval ); | |
1549 } | |
1550 } | |
1551 int key = keyEvent.keyval; | |
1552 if ((keyEvent.state & OS.GDK_CONTROL_MASK) !is 0 && (0 <= key && key <= 0x7F)) { | |
1553 if ('a' <= key && key <= 'z') key -= 'a' - 'A'; | |
1554 if (64 <= key && key <= 95) key -= 64; | |
1555 event.character = cast(char) key; | |
1556 isNull = keyEvent.keyval is '@' && key is 0; | |
1557 } else { | |
1558 event.character = cast(char) OS.gdk_keyval_to_unicode (key); | |
1559 } | |
1560 } | |
1561 } | |
1562 if (event.keyCode is 0 && event.character is 0) { | |
1563 if (!isNull) return false; | |
1564 } | |
1565 return setInputState (event, keyEvent.state); | |
1566 } | |
1567 | |
1568 void setOrientation () { | |
1569 } | |
1570 | |
1571 int /*long*/ shellMapProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
1572 return 0; | |
1573 } | |
1574 | |
1575 int /*long*/ sizeAllocateProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
1576 return 0; | |
1577 } | |
1578 | |
1579 int /*long*/ sizeRequestProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
1580 return 0; | |
1581 } | |
1582 | |
1583 /** | |
1584 * Returns a string containing a concise, human-readable | |
1585 * description of the receiver. | |
1586 * | |
1587 * @return a string representation of the receiver | |
1588 */ | |
1589 public override String toString () { | |
1590 String str = "*Disposed*"; | |
1591 if (!isDisposed ()) { | |
1592 str = "*Wrong Thread*"; | |
1593 if (isValidThread ()) str = getNameText (); | |
1594 } | |
1595 return getName () ~ " {" ~ str ~ "}"; | |
1596 } | |
1597 | |
1598 GtkWidget* topHandle () { | |
1599 return handle; | |
1600 } | |
1601 | |
1602 int /*long*/ timerProc (GtkWidget* widget) { | |
1603 return 0; | |
1604 } | |
1605 | |
1606 void treeSelectionProc ( | |
1607 GtkTreeModel *model, | |
1608 GtkTreePath *path, | |
1609 GtkTreeIter *iter, | |
1610 int[] selection, | |
1611 int length) | |
1612 { | |
1613 } | |
1614 | |
1615 bool translateTraversal (int event) { | |
1616 return false; | |
1617 } | |
1618 | |
1619 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ user_data) { | |
1620 void trace( String str ){ | |
1621 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Widget windowProc {}", str ).flush; | |
1622 } | |
1623 | |
1624 switch (cast(int)/*64*/user_data) { | |
1625 case ACTIVATE: | |
1626 trace( "ACTIVATE" ); | |
1627 return gtk_activate (handle); | |
1628 case CHANGED: | |
1629 trace( "CHANGED" ); | |
1630 return gtk_changed (handle); | |
1631 case CLICKED: | |
1632 trace( "CLICKED" ); | |
1633 return gtk_clicked (handle); | |
1634 case DAY_SELECTED: | |
1635 trace( "DAY_SELECTED" ); | |
1636 return gtk_day_selected (handle); | |
1637 case HIDE: | |
1638 trace( "HIDE" ); | |
1639 return gtk_hide (handle); | |
1640 case GRAB_FOCUS: | |
1641 trace( "GRAB_FOCUS" ); | |
1642 return gtk_grab_focus (handle); | |
1643 case MAP: | |
1644 trace( "MAP" ); | |
1645 return gtk_map (handle); | |
1646 case MONTH_CHANGED: | |
1647 trace( "MONTH_CHANGED" ); | |
1648 return gtk_month_changed (handle); | |
1649 case OUTPUT: | |
1650 trace( "OUTPUT" ); | |
1651 return gtk_output (handle); | |
1652 case POPUP_MENU: | |
1653 trace( "POPUP_MENU" ); | |
1654 return gtk_popup_menu (handle); | |
1655 case PREEDIT_CHANGED: | |
1656 trace( "PREEDIT_CHANGED" ); | |
1657 return gtk_preedit_changed (cast(GtkIMContext*)handle); | |
1658 case REALIZE: | |
1659 trace( "REALIZE" ); | |
1660 return gtk_realize (handle); | |
1661 case SELECT: | |
1662 trace( "SELECT" ); | |
1663 return gtk_select (cast(int)handle); | |
1664 case SHOW: | |
1665 trace( "SHOW" ); | |
1666 return gtk_show (handle); | |
1667 case VALUE_CHANGED: | |
1668 trace( "VALUE_CHANGED" ); | |
1669 return gtk_value_changed (cast(int)handle); | |
1670 case UNMAP: | |
1671 trace( "UNMAP" ); | |
1672 return gtk_unmap (handle); | |
1673 case UNREALIZE: | |
1674 trace( "UNREALIZE" ); | |
1675 return gtk_unrealize (handle); | |
1676 default: | |
1677 trace( "default" ); | |
1678 return 0; | |
1679 } | |
1680 } | |
1681 | |
1682 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { | |
1683 void trace( String str ){ | |
1684 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Widget windowProc1 {}", str ).flush; | |
1685 } | |
1686 | |
1687 switch (cast(int)/*64*/user_data) { | |
1688 case EXPOSE_EVENT_INVERSE: { | |
1689 trace( "EXPOSE_EVENT_INVERSE" ); | |
1690 GdkEventExpose* gdkEvent = cast(GdkEventExpose*) arg0; | |
1691 auto paintWindow = paintWindow(); | |
1692 auto window = gdkEvent.window; | |
1693 if (window !is paintWindow) return 0; | |
1694 return (state & OBSCURED) !is 0 ? 1 : 0; | |
1695 } | |
1696 case BUTTON_PRESS_EVENT_INVERSE: | |
1697 case BUTTON_RELEASE_EVENT_INVERSE: | |
1698 case MOTION_NOTIFY_EVENT_INVERSE: { | |
1699 trace( "BUTTON_PRESS_EVENT_INVERSE BUTTON_RELEASE_EVENT_INVERSE MOTION_NOTIFY_EVENT_INVERSE" ); | |
1700 return 1; | |
1701 } | |
1702 case BUTTON_PRESS_EVENT: | |
1703 trace( "BUTTON_PRESS_EVENT" ); | |
1704 return gtk_button_press_event (handle, cast(GdkEventButton*)arg0); | |
1705 case BUTTON_RELEASE_EVENT: | |
1706 trace( "BUTTON_RELEASE_EVENT" ); | |
1707 return gtk_button_release_event (handle, cast(GdkEventButton*)arg0); | |
1708 case COMMIT: | |
1709 trace( "COMMIT" ); | |
1710 return gtk_commit (cast(GtkIMContext*)handle, cast(char*)arg0); | |
1711 case CONFIGURE_EVENT: | |
1712 trace( "CONFIGURE_EVENT" ); | |
1713 return gtk_configure_event (handle, arg0); | |
1714 case DELETE_EVENT: | |
1715 trace( "DELETE_EVENT" ); | |
1716 return gtk_delete_event (handle, arg0); | |
1717 case ENTER_NOTIFY_EVENT: | |
1718 trace( "ENTER_NOTIFY_EVENT" ); | |
1719 return gtk_enter_notify_event (handle, cast(GdkEventCrossing*)arg0); | |
1720 case EVENT: | |
1721 trace( "EVENT" ); | |
1722 return gtk_event (handle, cast(GdkEvent*)arg0); | |
1723 case POPULATE_POPUP: | |
1724 trace( "POPULATE_POPUP" ); | |
1725 return gtk_populate_popup (handle, cast(GtkWidget*)arg0); | |
1726 case EVENT_AFTER: | |
1727 trace( "EVENT_AFTER" ); | |
1728 return gtk_event_after (handle, cast(GdkEvent*)arg0); | |
1729 case EXPOSE_EVENT: | |
1730 trace( "EXPOSE_EVENT" ); | |
1731 return gtk_expose_event (handle, cast(GdkEventExpose*)arg0); | |
1732 case FOCUS: | |
1733 trace( "FOCUS" ); | |
1734 return gtk_focus (handle, arg0); | |
1735 case FOCUS_IN_EVENT: | |
1736 trace( "FOCUS_IN_EVENT" ); | |
1737 return gtk_focus_in_event (handle, cast(GdkEventFocus*)arg0); | |
1738 case FOCUS_OUT_EVENT: | |
1739 trace( "FOCUS_OUT_EVENT" ); | |
1740 return gtk_focus_out_event (handle, cast(GdkEventFocus*)arg0); | |
1741 case KEY_PRESS_EVENT: | |
1742 trace( "KEY_PRESS_EVENT" ); | |
1743 return gtk_key_press_event (handle, cast(GdkEventKey*)arg0); | |
1744 case KEY_RELEASE_EVENT: | |
1745 trace( "KEY_RELEASE_EVENT" ); | |
1746 return gtk_key_release_event (handle, cast(GdkEventKey*)arg0); | |
1747 case INPUT: | |
1748 trace( "INPUT" ); | |
1749 return gtk_input (handle, arg0); | |
1750 case LEAVE_NOTIFY_EVENT: | |
1751 trace( "LEAVE_NOTIFY_EVENT" ); | |
1752 return gtk_leave_notify_event (handle, cast(GdkEventCrossing*)arg0); | |
1753 case MAP_EVENT: | |
1754 trace( "MAP_EVENT" ); | |
1755 return gtk_map_event (handle, arg0); | |
1756 case MNEMONIC_ACTIVATE: | |
1757 trace( "MNEMONIC_ACTIVATE" ); | |
1758 return gtk_mnemonic_activate (handle, arg0); | |
1759 case MOTION_NOTIFY_EVENT: | |
1760 trace( "MOTION_NOTIFY_EVENT" ); | |
1761 return gtk_motion_notify_event (handle, cast(GdkEventMotion*)arg0); | |
1762 case MOVE_FOCUS: | |
1763 trace( "MOVE_FOCUS" ); | |
1764 return gtk_move_focus (handle, arg0); | |
1765 case SCROLL_EVENT: | |
1766 trace( "SCROLL_EVENT" ); | |
1767 return gtk_scroll_event (handle, cast(GdkEventScroll*)arg0); | |
1768 case SHOW_HELP: | |
1769 trace( "SHOW_HELP" ); | |
1770 return gtk_show_help (handle, arg0); | |
1771 case SIZE_ALLOCATE: | |
1772 trace( "SIZE_ALLOCATE" ); | |
1773 return gtk_size_allocate (handle, arg0); | |
1774 case STYLE_SET: | |
1775 trace( "STYLE_SET" ); | |
1776 return gtk_style_set (handle, arg0); | |
1777 case TOGGLED: | |
1778 trace( "TOGGLED" ); | |
1779 return gtk_toggled (cast(int)handle, cast(char*)arg0); | |
1780 case UNMAP_EVENT: | |
1781 trace( "UNMAP_EVENT" ); | |
1782 return gtk_unmap_event (handle, arg0); | |
1783 case VISIBILITY_NOTIFY_EVENT: | |
1784 trace( "VISIBILITY_NOTIFY_EVENT" ); | |
1785 return gtk_visibility_notify_event (handle, cast(GdkEventVisibility*)arg0); | |
1786 case WINDOW_STATE_EVENT: | |
1787 trace( "WINDOW_STATE_EVENT" ); | |
1788 return gtk_window_state_event (handle, cast(GdkEventWindowState*)arg0); | |
1789 default: | |
1790 trace( "default" ); | |
1791 return 0; | |
1792 } | |
1793 } | |
1794 | |
1795 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) { | |
1796 void trace( String str ){ | |
1797 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Widget windowProc2 {}", str ).flush; | |
1798 } | |
1799 | |
1800 switch (cast(int)/*64*/user_data) { | |
1801 case DELETE_RANGE: | |
1802 trace( "DELETE_RANGE" ); | |
1803 return gtk_delete_range (handle, arg0, arg1); | |
1804 case DELETE_TEXT: | |
1805 trace( "DELETE_TEXT" ); | |
1806 return gtk_delete_text (handle, arg0, arg1); | |
1807 case ROW_ACTIVATED: | |
1808 trace( "ROW_ACTIVATED" ); | |
1809 gtk_row_activated (cast(GtkTreeView*)handle, cast(GtkTreePath*)arg0, cast(GtkTreeViewColumn*)arg1); | |
1810 return 0; | |
1811 case SCROLL_CHILD: | |
1812 trace( "SCROLL_CHILD" ); | |
1813 return gtk_scroll_child (handle, arg0, arg1); | |
1814 case SWITCH_PAGE: | |
1815 trace( "SWITCH_PAGE" ); | |
1816 return gtk_switch_page (handle, arg0, arg1); | |
1817 case TEST_COLLAPSE_ROW: | |
1818 trace( "TEST_COLLAPSE_ROW" ); | |
1819 return gtk_test_collapse_row (cast(GtkTreeView*)handle, cast(GtkTreeIter*)arg0, cast(GtkTreePath*)arg1); | |
1820 case TEST_EXPAND_ROW: | |
1821 trace( "TEST_EXPAND_ROW" ); | |
1822 return gtk_test_expand_row(cast(GtkTreeView*)handle, cast(GtkTreeIter*)arg0, cast(GtkTreePath*)arg1); | |
1823 default: | |
1824 trace( "default" ); | |
1825 return 0; | |
1826 } | |
1827 } | |
1828 | |
1829 int /*long*/ windowProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) { | |
1830 void trace( String str ){ | |
1831 version(LOG) getDwtLogger().error( __FILE__, __LINE__, "Widget windowProc3 {}", str ).flush; | |
1832 } | |
1833 | |
1834 switch (cast(int)/*64*/user_data) { | |
1835 case CHANGE_VALUE: | |
1836 trace( "CHANGE_VALUE" ); | |
1837 return gtk_change_value (handle, arg0, arg1, arg2); | |
1838 case EXPAND_COLLAPSE_CURSOR_ROW: | |
1839 trace( "EXPAND_COLLAPSE_CURSOR_ROW" ); | |
1840 return gtk_expand_collapse_cursor_row (handle, arg0, arg1, arg2); | |
1841 case INSERT_TEXT: | |
1842 trace( "INSERT_TEXT" ); | |
1843 return gtk_insert_text (cast(GtkEditable*)handle, cast(char*)arg0, arg1, arg2); | |
1844 case TEXT_BUFFER_INSERT_TEXT: | |
1845 trace( "TEXT_BUFFER_INSERT_TEXT" ); | |
1846 return gtk_text_buffer_insert_text (cast(GtkTextBuffer*)handle, cast(GtkTextIter*)arg0, cast(char*)arg1, arg2); | |
1847 default: | |
1848 trace( "default" ); | |
1849 return 0; | |
1850 } | |
1851 } | |
1852 | |
1853 } |