Mercurial > projects > dwt-linux
annotate dwt/graphics/Device.d @ 55:93981635e709
Checked and inserted missing default switch cases.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 11 Jan 2008 15:40:16 +0100 |
parents | 8f049b136add |
children | 8cec8f536af3 |
rev | line source |
---|---|
18 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 *******************************************************************************/ | |
11 module dwt.graphics.Device; | |
12 | |
13 import dwt.graphics.Color; | |
19 | 14 import dwt.graphics.Font; |
15 import dwt.graphics.Drawable; | |
16 import dwt.graphics.DeviceData; | |
17 import dwt.graphics.Rectangle; | |
18 import dwt.graphics.FontData; | |
19 import dwt.graphics.Font; | |
20 import dwt.graphics.GCData; | |
21 import dwt.dwthelper.Runnable; | |
22 import dwt.SWT; | |
23 import dwt.SWTError; | |
24 import dwt.internal.Compatibility; | |
25 import dwt.internal.gtk.OS; | |
26 | |
27 import tango.core.Exception; | |
28 import tango.stdc.stringz; | |
29 import tango.io.Stdout; | |
30 | |
18 | 31 /** |
32 * This class is the abstract superclass of all device objects, | |
33 * such as the Display device and the Printer device. Devices | |
34 * can have a graphics context (GC) created for them, and they | |
35 * can be drawn on by sending messages to the associated GC. | |
36 */ | |
19 | 37 public abstract class Device : Drawable { |
18 | 38 /** |
39 * the handle to the X Display | |
40 * (Warning: This field is platform dependent) | |
41 * <p> | |
42 * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT | |
43 * public API. It is marked protected only so that it can be shared | |
44 * within the packages provided by SWT. It is not available on all | |
45 * platforms and should never be accessed from application code. | |
46 * </p> | |
47 */ | |
28 | 48 protected void* xDisplay; |
19 | 49 GtkWidget* shellHandle; |
18 | 50 |
51 /* Debugging */ | |
19 | 52 public static bool DEBUG; |
53 bool debugging; | |
54 bool tracking; | |
55 TracedException [] errors; | |
18 | 56 Object [] objects; |
57 | |
58 /* Colormap and reference count */ | |
19 | 59 GdkColor *[] gdkColors; |
18 | 60 int [] colorRefCount; |
61 | |
62 /* Disposed flag */ | |
19 | 63 bool disposed; |
18 | 64 |
65 /* Warning and Error Handlers */ | |
19 | 66 //int /*long*/ logProcFld; |
67 //GLogFunc logCallback; | |
18 | 68 //NOT DONE - get list of valid names |
19 | 69 char[] [] log_domains = ["GLib-GObject"[], "GLib", "GObject", "Pango", "ATK", "GdkPixbuf", "Gdk", "Gtk", "GnomeVFS"]; |
70 int [] handler_ids;// = new int [log_domains.length]; | |
18 | 71 int warningLevel; |
72 | |
73 /* X Warning and Error Handlers */ | |
19 | 74 static extern(C) int function(void *) mXIOErrorHandler; |
75 static extern(C) int function(void *, XErrorEvent *) mXErrorHandler; | |
76 //static int mXErrorCallback, mXIOErrorCallback; | |
77 | |
18 | 78 static int /*long*/ XErrorProc, XIOErrorProc, XNullErrorProc, XNullIOErrorProc; |
19 | 79 static Device[] Devices; |
18 | 80 |
81 /* | |
82 * The following colors are listed in the Windows | |
83 * Programmer's Reference as the colors in the default | |
84 * palette. | |
85 */ | |
86 Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE; | |
87 Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED; | |
88 Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE; | |
89 | |
90 /* System Font */ | |
91 Font systemFont; | |
92 | |
19 | 93 PangoTabArray* emptyTab; |
18 | 94 |
19 | 95 bool useXRender; |
18 | 96 |
19 | 97 static bool CAIRO_LOADED; |
18 | 98 |
54 | 99 static Object CREATE_LOCK; |
18 | 100 |
101 /* | |
102 * TEMPORARY CODE. When a graphics object is | |
103 * created and the device parameter is null, | |
104 * the current Display is used. This presents | |
105 * a problem because SWT graphics does not | |
106 * reference classes in SWT widgets. The correct | |
107 * fix is to remove this feature. Unfortunately, | |
108 * too many application programs rely on this | |
109 * feature. | |
110 * | |
111 * This code will be removed in the future. | |
112 */ | |
113 protected static Device CurrentDevice; | |
114 protected static Runnable DeviceFinder; | |
115 | |
54 | 116 synchronized static void static_this(){ |
19 | 117 CREATE_LOCK = new Object(); |
118 Devices = new Device[4]; | |
119 } | |
18 | 120 /* |
121 * TEMPORARY CODE. | |
122 */ | |
123 static synchronized Device getDevice () { | |
19 | 124 if (DeviceFinder !is null) DeviceFinder.run(); |
18 | 125 Device device = CurrentDevice; |
126 CurrentDevice = null; | |
127 return device; | |
128 } | |
129 | |
130 /** | |
131 * Constructs a new instance of this class. | |
132 * <p> | |
133 * You must dispose the device when it is no longer required. | |
134 * </p> | |
135 * | |
136 * @see #create | |
137 * @see #init | |
138 * | |
139 * @since 3.1 | |
140 */ | |
19 | 141 public this() { |
18 | 142 this(null); |
143 } | |
144 | |
145 /** | |
146 * Constructs a new instance of this class. | |
147 * <p> | |
148 * You must dispose the device when it is no longer required. | |
149 * </p> | |
150 * | |
151 * @param data the DeviceData which describes the receiver | |
152 * | |
153 * @see #create | |
154 * @see #init | |
155 * @see DeviceData | |
156 */ | |
19 | 157 public this(DeviceData data) { |
158 handler_ids = new int [log_domains.length]; | |
159 debugging = DEBUG; | |
160 tracking = DEBUG; | |
161 | |
18 | 162 synchronized (CREATE_LOCK) { |
54 | 163 if (data !is null) { |
19 | 164 debugging = data.debugging; |
18 | 165 tracking = data.tracking; |
166 } | |
167 if (tracking) { | |
19 | 168 errors = new TracedException [128]; |
18 | 169 objects = new Object [128]; |
170 } | |
171 create (data); | |
172 init (); | |
173 register (this); | |
174 | |
175 /* Initialize the system font slot */ | |
176 systemFont = getSystemFont (); | |
177 } | |
178 } | |
179 | |
180 void checkCairo() { | |
181 } | |
182 | |
183 /** | |
184 * Throws an <code>SWTException</code> if the receiver can not | |
185 * be accessed by the caller. This may include both checks on | |
186 * the state of the receiver and more generally on the entire | |
187 * execution context. This method <em>should</em> be called by | |
188 * device implementors to enforce the standard SWT invariants. | |
189 * <p> | |
190 * Currently, it is an error to invoke any method (other than | |
191 * <code>isDisposed()</code> and <code>dispose()</code>) on a | |
192 * device that has had its <code>dispose()</code> method called. | |
193 * </p><p> | |
194 * In future releases of SWT, there may be more or fewer error | |
195 * checks and exceptions may be thrown for different reasons. | |
196 * <p> | |
197 * | |
198 * @exception SWTException <ul> | |
199 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
200 * </ul> | |
201 */ | |
202 protected void checkDevice () { | |
203 if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED); | |
204 } | |
205 | |
206 /** | |
207 * Creates the device in the operating system. If the device | |
208 * does not have a handle, this method may do nothing depending | |
209 * on the device. | |
210 * <p> | |
211 * This method is called before <code>init</code>. | |
212 * </p><p> | |
213 * Subclasses are supposed to reimplement this method and not | |
214 * call the <code>super</code> implementation. | |
215 * </p> | |
216 * | |
217 * @param data the DeviceData which describes the receiver | |
218 * | |
219 * @see #init | |
220 */ | |
221 protected void create (DeviceData data) { | |
222 } | |
223 | |
224 /** | |
225 * Disposes of the operating system resources associated with | |
226 * the receiver. After this method has been invoked, the receiver | |
227 * will answer <code>true</code> when sent the message | |
228 * <code>isDisposed()</code>. | |
229 * | |
230 * @see #release | |
231 * @see #destroy | |
232 * @see #checkDevice | |
233 */ | |
234 public void dispose () { | |
235 if (isDisposed()) return; | |
236 checkDevice (); | |
237 release (); | |
238 destroy (); | |
239 deregister (this); | |
19 | 240 xDisplay = null; |
18 | 241 disposed = true; |
242 if (tracking) { | |
243 objects = null; | |
244 errors = null; | |
245 } | |
246 } | |
247 | |
248 void dispose_Object (Object object) { | |
249 for (int i=0; i<objects.length; i++) { | |
19 | 250 if (objects [i] is object) { |
18 | 251 objects [i] = null; |
252 errors [i] = null; | |
253 return; | |
254 } | |
255 } | |
256 } | |
257 | |
28 | 258 static synchronized Device findDevice (void* xDisplay) { |
18 | 259 for (int i=0; i<Devices.length; i++) { |
260 Device device = Devices [i]; | |
19 | 261 if (device !is null && device.xDisplay is xDisplay) { |
18 | 262 return device; |
263 } | |
264 } | |
265 return null; | |
266 } | |
267 | |
268 synchronized static void deregister (Device device) { | |
269 for (int i=0; i<Devices.length; i++) { | |
19 | 270 if (device is Devices [i]) Devices [i] = null; |
18 | 271 } |
272 } | |
273 | |
274 /** | |
275 * Destroys the device in the operating system and releases | |
276 * the device's handle. If the device does not have a handle, | |
277 * this method may do nothing depending on the device. | |
278 * <p> | |
279 * This method is called after <code>release</code>. | |
280 * </p><p> | |
281 * Subclasses are supposed to reimplement this method and not | |
282 * call the <code>super</code> implementation. | |
283 * </p> | |
284 * | |
285 * @see #dispose | |
286 * @see #release | |
287 */ | |
288 protected void destroy () { | |
289 } | |
290 | |
291 /** | |
292 * Returns a rectangle describing the receiver's size and location. | |
293 * | |
294 * @return the bounding rectangle | |
295 * | |
296 * @exception SWTException <ul> | |
297 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
298 * </ul> | |
299 */ | |
300 public Rectangle getBounds () { | |
301 checkDevice (); | |
302 return new Rectangle(0, 0, 0, 0); | |
303 } | |
304 | |
305 /** | |
306 * Returns a <code>DeviceData</code> based on the receiver. | |
307 * Modifications made to this <code>DeviceData</code> will not | |
308 * affect the receiver. | |
309 * | |
310 * @return a <code>DeviceData</code> containing the device's data and attributes | |
311 * | |
312 * @exception SWTException <ul> | |
313 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
314 * </ul> | |
315 * | |
316 * @see DeviceData | |
317 */ | |
318 public DeviceData getDeviceData () { | |
319 checkDevice(); | |
320 DeviceData data = new DeviceData (); | |
19 | 321 data.debugging = debugging; |
18 | 322 data.tracking = tracking; |
323 int count = 0, length = 0; | |
324 if (tracking) length = objects.length; | |
325 for (int i=0; i<length; i++) { | |
54 | 326 if (objects [i] !is null) count++; |
18 | 327 } |
328 int index = 0; | |
329 data.objects = new Object [count]; | |
19 | 330 data.errors = new TracedException [count]; |
18 | 331 for (int i=0; i<length; i++) { |
54 | 332 if (objects [i] !is null) { |
18 | 333 data.objects [index] = objects [i]; |
334 data.errors [index] = errors [i]; | |
335 index++; | |
336 } | |
337 } | |
338 return data; | |
339 } | |
340 | |
341 /** | |
342 * Returns a rectangle which describes the area of the | |
343 * receiver which is capable of displaying data. | |
344 * | |
345 * @return the client area | |
346 * | |
347 * @exception SWTException <ul> | |
348 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
349 * </ul> | |
350 * | |
351 * @see #getBounds | |
352 */ | |
353 public Rectangle getClientArea () { | |
354 checkDevice (); | |
355 return getBounds (); | |
356 } | |
357 | |
358 /** | |
359 * Returns the bit depth of the screen, which is the number of | |
360 * bits it takes to represent the number of unique colors that | |
361 * the screen is currently capable of displaying. This number | |
362 * will typically be one of 1, 8, 15, 16, 24 or 32. | |
363 * | |
364 * @return the depth of the screen | |
365 * | |
366 * @exception SWTException <ul> | |
367 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
368 * </ul> | |
369 */ | |
370 public int getDepth () { | |
371 checkDevice (); | |
372 return 0; | |
373 } | |
374 | |
375 /** | |
376 * Returns a point whose x coordinate is the horizontal | |
377 * dots per inch of the display, and whose y coordinate | |
378 * is the vertical dots per inch of the display. | |
379 * | |
380 * @return the horizontal and vertical DPI | |
381 * | |
382 * @exception SWTException <ul> | |
383 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
384 * </ul> | |
385 */ | |
386 public Point getDPI () { | |
387 checkDevice (); | |
388 return new Point (72, 72); | |
389 } | |
390 | |
391 /** | |
392 * Returns <code>FontData</code> objects which describe | |
393 * the fonts that match the given arguments. If the | |
394 * <code>faceName</code> is null, all fonts will be returned. | |
395 * | |
396 * @param faceName the name of the font to look for, or null | |
397 * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned. | |
398 * @return the matching font data | |
399 * | |
400 * @exception SWTException <ul> | |
401 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
402 * </ul> | |
403 */ | |
19 | 404 public FontData[] getFontList (char[] faceName, bool scalable) { |
18 | 405 checkDevice (); |
406 if (!scalable) return new FontData[0]; | |
19 | 407 PangoFontFamily* family; |
408 PangoFontFace * face; | |
409 PangoFontFamily** families; | |
410 int n_families; | |
411 PangoFontFace ** faces; | |
412 int n_faces; | |
413 auto context = OS.gdk_pango_context_get(); | |
414 OS.pango_context_list_families(context, &families, &n_families); | |
18 | 415 int nFds = 0; |
54 | 416 FontData[] fds = new FontData[faceName !is null ? 4 : n_families]; |
19 | 417 for (int i=0; i<n_families; i++) { |
418 family = families[i]; | |
419 bool match = true; | |
54 | 420 if (faceName !is null) { |
19 | 421 auto familyName = OS.pango_font_family_get_name(family); |
422 match = Compatibility.equalsIgnoreCase(faceName, fromUtf8z( familyName )); | |
18 | 423 } |
424 if (match) { | |
19 | 425 OS.pango_font_family_list_faces(family, &faces, &n_faces); |
426 for (int j=0; j<n_faces; j++) { | |
427 face = faces[j]; | |
428 auto fontDesc = OS.pango_font_face_describe(face); | |
18 | 429 Font font = Font.gtk_new(this, fontDesc); |
430 FontData data = font.getFontData()[0]; | |
54 | 431 if (nFds is fds.length) { |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
432 FontData[] newFds = new FontData[fds.length + n_families]; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
433 System.arraycopy(fds, 0, newFds, 0, nFds); |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
434 fds = newFds; |
18 | 435 } |
436 fds[nFds++] = data; | |
437 OS.pango_font_description_free(fontDesc); | |
438 } | |
439 OS.g_free(faces[0]); | |
19 | 440 if (faceName !is null) break; |
18 | 441 } |
442 } | |
19 | 443 OS.g_free(families); |
18 | 444 OS.g_object_unref(context); |
54 | 445 if (nFds is fds.length) return fds; |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
446 FontData[] result = new FontData[nFds]; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
447 System.arraycopy(fds, 0, result, 0, nFds); |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
448 return result; |
18 | 449 } |
450 | |
451 /** | |
452 * Returns the matching standard color for the given | |
453 * constant, which should be one of the color constants | |
454 * specified in class <code>SWT</code>. Any value other | |
455 * than one of the SWT color constants which is passed | |
456 * in will result in the color black. This color should | |
457 * not be freed because it was allocated by the system, | |
458 * not the application. | |
459 * | |
460 * @param id the color constant | |
461 * @return the matching color | |
462 * | |
463 * @exception SWTException <ul> | |
464 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
465 * </ul> | |
466 * | |
467 * @see SWT | |
468 */ | |
469 public Color getSystemColor (int id) { | |
470 checkDevice (); | |
471 switch (id) { | |
472 case SWT.COLOR_BLACK: return COLOR_BLACK; | |
473 case SWT.COLOR_DARK_RED: return COLOR_DARK_RED; | |
474 case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN; | |
475 case SWT.COLOR_DARK_YELLOW: return COLOR_DARK_YELLOW; | |
476 case SWT.COLOR_DARK_BLUE: return COLOR_DARK_BLUE; | |
477 case SWT.COLOR_DARK_MAGENTA: return COLOR_DARK_MAGENTA; | |
478 case SWT.COLOR_DARK_CYAN: return COLOR_DARK_CYAN; | |
479 case SWT.COLOR_GRAY: return COLOR_GRAY; | |
480 case SWT.COLOR_DARK_GRAY: return COLOR_DARK_GRAY; | |
481 case SWT.COLOR_RED: return COLOR_RED; | |
482 case SWT.COLOR_GREEN: return COLOR_GREEN; | |
483 case SWT.COLOR_YELLOW: return COLOR_YELLOW; | |
484 case SWT.COLOR_BLUE: return COLOR_BLUE; | |
485 case SWT.COLOR_MAGENTA: return COLOR_MAGENTA; | |
486 case SWT.COLOR_CYAN: return COLOR_CYAN; | |
487 case SWT.COLOR_WHITE: return COLOR_WHITE; | |
55
93981635e709
Checked and inserted missing default switch cases.
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
488 default: |
18 | 489 } |
490 return COLOR_BLACK; | |
491 } | |
492 | |
493 /** | |
494 * Returns a reasonable font for applications to use. | |
495 * On some platforms, this will match the "default font" | |
496 * or "system font" if such can be found. This font | |
497 * should not be freed because it was allocated by the | |
498 * system, not the application. | |
499 * <p> | |
500 * Typically, applications which want the default look | |
501 * should simply not set the font on the widgets they | |
502 * create. Widgets are always created with the correct | |
503 * default font for the class of user-interface component | |
504 * they represent. | |
505 * </p> | |
506 * | |
507 * @return a font | |
508 * | |
509 * @exception SWTException <ul> | |
510 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
511 * </ul> | |
512 */ | |
513 public Font getSystemFont () { | |
514 checkDevice (); | |
515 return systemFont; | |
516 } | |
517 | |
518 /** | |
519 * Returns <code>true</code> if the underlying window system prints out | |
520 * warning messages on the console, and <code>setWarnings</code> | |
521 * had previously been called with <code>true</code>. | |
522 * | |
523 * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise | |
524 * | |
525 * @exception SWTException <ul> | |
526 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
527 * </ul> | |
528 */ | |
19 | 529 public bool getWarnings () { |
18 | 530 checkDevice (); |
54 | 531 return warningLevel is 0; |
18 | 532 } |
533 | |
534 /** | |
535 * Initializes any internal resources needed by the | |
536 * device. | |
537 * <p> | |
538 * This method is called after <code>create</code>. | |
539 * </p><p> | |
540 * If subclasses reimplement this method, they must | |
541 * call the <code>super</code> implementation. | |
542 * </p> | |
543 * | |
544 * @see #create | |
545 */ | |
546 protected void init () { | |
19 | 547 if (xDisplay !is null) { |
548 int event_basep, error_basep; | |
549 if (OS.XRenderQueryExtension (xDisplay, &event_basep, &error_basep)) { | |
550 int major_version, minor_version; | |
551 OS.XRenderQueryVersion (xDisplay, &major_version, &minor_version); | |
54 | 552 useXRender = major_version > 0 || (major_version is 0 && minor_version >= 8); |
18 | 553 } |
554 } | |
555 | |
19 | 556 if (debugging) { |
557 if (xDisplay !is null) { | |
18 | 558 /* Create the warning and error callbacks */ |
19 | 559 synchronized (CREATE_LOCK) { |
18 | 560 int index = 0; |
561 while (index < Devices.length) { | |
54 | 562 if (Devices [index] !is null) break; |
18 | 563 index++; |
564 } | |
54 | 565 if (index is Devices.length) { |
19 | 566 OS.XSetErrorHandler ( & XErrorProcFunc ); |
567 OS.XSetIOErrorHandler ( & XIOErrorProcFunc ); | |
18 | 568 } |
569 } | |
570 OS.XSynchronize (xDisplay, true); | |
571 } | |
572 } | |
573 | |
574 /* Create GTK warnings and error callbacks */ | |
19 | 575 if (xDisplay !is null) { |
18 | 576 /* Set GTK warning and error handlers */ |
19 | 577 if (debugging) { |
18 | 578 int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION; |
579 for (int i=0; i<log_domains.length; i++) { | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
580 handler_ids [i] = OS.g_log_set_handler (toStringz(log_domains [i]), flags, & logFunction, cast(void*)this); |
18 | 581 } |
582 } | |
583 } | |
584 | |
19 | 585 /* Create the standard colors */ |
18 | 586 COLOR_BLACK = new Color (this, 0,0,0); |
587 COLOR_DARK_RED = new Color (this, 0x80,0,0); | |
588 COLOR_DARK_GREEN = new Color (this, 0,0x80,0); | |
589 COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0); | |
590 COLOR_DARK_BLUE = new Color (this, 0,0,0x80); | |
591 COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80); | |
592 COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80); | |
593 COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0); | |
594 COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80); | |
595 COLOR_RED = new Color (this, 0xFF,0,0); | |
596 COLOR_GREEN = new Color (this, 0,0xFF,0); | |
597 COLOR_YELLOW = new Color (this, 0xFF,0xFF,0); | |
598 COLOR_BLUE = new Color (this, 0,0,0xFF); | |
599 COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF); | |
600 COLOR_CYAN = new Color (this, 0,0xFF,0xFF); | |
601 COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF); | |
602 | |
603 emptyTab = OS.pango_tab_array_new(1, false); | |
19 | 604 if (emptyTab is null) SWT.error(SWT.ERROR_NO_HANDLES); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
605 OS.pango_tab_array_set_tab(emptyTab, 0, OS.PANGO_TAB_LEFT, 1); |
18 | 606 |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
607 shellHandle = OS.gtk_window_new(OS.GTK_WINDOW_TOPLEVEL); |
19 | 608 if (shellHandle is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 609 OS.gtk_widget_realize(shellHandle); |
610 } | |
611 | |
612 /** | |
613 * Invokes platform specific functionality to allocate a new GC handle. | |
614 * <p> | |
615 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
616 * API for <code>Device</code>. It is marked public only so that it | |
617 * can be shared within the packages provided by SWT. It is not | |
618 * available on all platforms, and should never be called from | |
619 * application code. | |
620 * </p> | |
621 * | |
622 * @param data the platform specific GC data | |
623 * @return the platform specific GC handle | |
624 */ | |
19 | 625 public abstract GdkGC* internal_new_GC (GCData data); |
18 | 626 |
627 /** | |
628 * Invokes platform specific functionality to dispose a GC handle. | |
629 * <p> | |
630 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
631 * API for <code>Device</code>. It is marked public only so that it | |
632 * can be shared within the packages provided by SWT. It is not | |
633 * available on all platforms, and should never be called from | |
634 * application code. | |
635 * </p> | |
636 * | |
637 * @param hDC the platform specific GC handle | |
638 * @param data the platform specific GC data | |
639 */ | |
19 | 640 public abstract void internal_dispose_GC (GdkGC* handle, GCData data); |
18 | 641 |
642 /** | |
643 * Returns <code>true</code> if the device has been disposed, | |
644 * and <code>false</code> otherwise. | |
645 * <p> | |
646 * This method gets the dispose state for the device. | |
647 * When a device has been disposed, it is an error to | |
648 * invoke any other method using the device. | |
649 * | |
650 * @return <code>true</code> when the device is disposed and <code>false</code> otherwise | |
651 */ | |
19 | 652 public bool isDisposed () { |
18 | 653 return disposed; |
654 } | |
655 | |
656 /** | |
657 * Loads the font specified by a file. The font will be | |
658 * present in the list of fonts available to the application. | |
659 * | |
660 * @param path the font file path | |
661 * @return whether the font was successfully loaded | |
662 * | |
663 * @exception SWTException <ul> | |
664 * <li>ERROR_NULL_ARGUMENT - if path is null</li> | |
665 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
666 * </ul> | |
667 * | |
668 * @see Font | |
669 * | |
670 * @since 3.3 | |
671 */ | |
19 | 672 public bool loadFont (char[] path) { |
18 | 673 checkDevice(); |
54 | 674 if (path is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); |
19 | 675 return cast(bool) OS.FcConfigAppFontAddFile (null, toStringz(path)); |
18 | 676 } |
677 | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
678 private static extern(C) void logFunction (char* log_domain, int log_level, char* message, void* user_data) { |
19 | 679 Device dev = cast(Device)user_data; |
54 | 680 if (dev.warningLevel is 0) { |
19 | 681 if (DEBUG || dev.debugging) { |
682 foreach( msg; new TracedException ("") ){ | |
683 Stderr.formatln( "trc {}", msg ); | |
684 } | |
18 | 685 } |
19 | 686 OS.g_log_default_handler (log_domain, log_level, message, user_data); |
18 | 687 } |
688 return 0; | |
689 } | |
690 | |
691 void new_Object (Object object) { | |
692 for (int i=0; i<objects.length; i++) { | |
19 | 693 if (objects [i] is null) { |
18 | 694 objects [i] = object; |
19 | 695 errors [i] = new TracedException (""); |
18 | 696 return; |
697 } | |
698 } | |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
699 Object [] newObjects = new Object [objects.length + 128]; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
700 System.arraycopy (objects, 0, newObjects, 0, objects.length); |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
701 newObjects [objects.length] = object; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
702 objects = newObjects; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
703 TracedException [] newErrors = new TracedException [errors.length + 128]; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
704 System.arraycopy (errors, 0, newErrors, 0, errors.length); |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
705 newErrors [errors.length] = new TracedException (""); |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
706 errors = newErrors; |
18 | 707 } |
708 | |
709 static synchronized void register (Device device) { | |
710 for (int i=0; i<Devices.length; i++) { | |
19 | 711 if (Devices [i] is null) { |
18 | 712 Devices [i] = device; |
713 return; | |
714 } | |
715 } | |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
716 Device [] newDevices = new Device [Devices.length + 4]; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
717 System.arraycopy (Devices, 0, newDevices, 0, Devices.length); |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
718 newDevices [Devices.length] = device; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
719 Devices = newDevices; |
18 | 720 } |
721 | |
722 /** | |
723 * Releases any internal resources back to the operating | |
724 * system and clears all fields except the device handle. | |
725 * <p> | |
726 * When a device is destroyed, resources that were acquired | |
727 * on behalf of the programmer need to be returned to the | |
728 * operating system. For example, if the device allocated a | |
729 * font to be used as the system font, this font would be | |
730 * freed in <code>release</code>. Also,to assist the garbage | |
731 * collector and minimize the amount of memory that is not | |
732 * reclaimed when the programmer keeps a reference to a | |
733 * disposed device, all fields except the handle are zero'd. | |
734 * The handle is needed by <code>destroy</code>. | |
735 * </p> | |
736 * This method is called before <code>destroy</code>. | |
737 * </p><p> | |
738 * If subclasses reimplement this method, they must | |
739 * call the <code>super</code> implementation. | |
740 * </p> | |
741 * | |
742 * @see #dispose | |
743 * @see #destroy | |
744 */ | |
745 protected void release () { | |
19 | 746 if (shellHandle !is null) OS.gtk_widget_destroy(shellHandle); |
747 shellHandle = null; | |
18 | 748 |
19 | 749 if (gdkColors !is null) { |
750 auto colormap = OS.gdk_colormap_get_system(); | |
18 | 751 for (int i = 0; i < gdkColors.length; i++) { |
19 | 752 GdkColor* color = gdkColors [i]; |
753 if (color !is null) { | |
18 | 754 while (colorRefCount [i] > 0) { |
755 OS.gdk_colormap_free_colors(colormap, color, 1); | |
756 --colorRefCount [i]; | |
757 } | |
758 } | |
759 } | |
760 } | |
761 gdkColors = null; | |
762 colorRefCount = null; | |
763 COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW = COLOR_DARK_BLUE = | |
764 COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED = | |
765 COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null; | |
766 | |
19 | 767 if (emptyTab !is null ) OS.pango_tab_array_free(emptyTab); |
768 emptyTab = null; | |
18 | 769 |
770 /* Free the GTK error and warning handler */ | |
19 | 771 if (xDisplay !is null) { |
18 | 772 for (int i=0; i<handler_ids.length; i++) { |
19 | 773 if (handler_ids [i] !is 0 ) { |
774 OS.g_log_remove_handler (toStringz(log_domains [i]), handler_ids [i]); | |
18 | 775 handler_ids [i] = 0; |
776 } | |
777 } | |
19 | 778 //logCallback.dispose (); logCallback = null; |
18 | 779 handler_ids = null; log_domains = null; |
19 | 780 //logProcFld = 0; |
18 | 781 } |
782 } | |
783 | |
784 /** | |
785 * If the underlying window system supports printing warning messages | |
786 * to the console, setting warnings to <code>false</code> prevents these | |
787 * messages from being printed. If the argument is <code>true</code> then | |
788 * message printing is not blocked. | |
789 * | |
790 * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise | |
791 * | |
792 * @exception SWTException <ul> | |
793 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
794 * </ul> | |
795 */ | |
19 | 796 public void setWarnings (bool warnings) { |
18 | 797 checkDevice (); |
798 if (warnings) { | |
54 | 799 if (--warningLevel is 0) { |
19 | 800 if (debugging) return; |
801 for (int i=0; i<handler_ids.length; i++) { | |
54 | 802 if (handler_ids [i] !is 0) { |
19 | 803 OS.g_log_remove_handler (toStringz(log_domains [i]), handler_ids [i]); |
804 handler_ids [i] = 0; | |
805 } | |
806 } | |
18 | 807 } |
808 } else { | |
54 | 809 if (warningLevel++ is 0) { |
19 | 810 if (debugging) return; |
811 int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION; | |
812 for (int i=0; i<log_domains.length; i++) { | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
813 handler_ids [i] = OS.g_log_set_handler (toStringz(log_domains [i]), flags, & logFunction, cast(void*)this ); |
19 | 814 } |
18 | 815 } |
816 } | |
817 } | |
818 | |
28 | 819 private static extern(C) int /*long*/ XErrorProcFunc (void* xDisplay, dwt.internal.gtk.OS.XErrorEvent* xErrorEvent) { |
18 | 820 Device device = findDevice (xDisplay); |
54 | 821 if (device !is null) { |
822 if (device.warningLevel is 0) { | |
19 | 823 if (DEBUG || device.debugging) { |
824 foreach( msg; new TracedException ("") ){ | |
825 Stderr.formatln( "trc {}", msg ); | |
826 } | |
18 | 827 } |
19 | 828 //PORTING_FIXME ?? |
829 //OS.Call (XErrorProc, xDisplay, xErrorEvent); | |
18 | 830 } |
831 } else { | |
19 | 832 if (DEBUG) (new SWTError ()).printStackTrace (); |
833 //PORTING_FIXME ?? | |
834 //OS.Call (XErrorProc, xDisplay, xErrorEvent); | |
18 | 835 } |
836 return 0; | |
837 } | |
838 | |
28 | 839 private static extern(C) int /*long*/ XIOErrorProcFunc (void* xDisplay) { |
18 | 840 Device device = findDevice (xDisplay); |
54 | 841 if (device !is null) { |
19 | 842 if (DEBUG || device.debugging) { |
843 foreach( msg; new TracedException ("") ){ | |
844 Stderr.formatln( "trc {}", msg ); | |
845 } | |
18 | 846 } |
847 } else { | |
19 | 848 if (DEBUG) { |
849 foreach( msg; new TracedException ("") ){ | |
850 Stderr.formatln( "trc {}", msg ); | |
851 } | |
852 } | |
18 | 853 } |
19 | 854 //PORTING_FIXME ?? |
855 //OS.Call (XIOErrorProc, xDisplay, 0); | |
18 | 856 return 0; |
857 } | |
858 | |
859 } |