Mercurial > projects > dwt-linux
annotate dwt/graphics/Device.d @ 54:8f049b136add
first example working
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 11 Jan 2008 14:31:37 +0100 |
parents | 27324bbbac70 |
children | 93981635e709 |
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; | |
488 } | |
489 return COLOR_BLACK; | |
490 } | |
491 | |
492 /** | |
493 * Returns a reasonable font for applications to use. | |
494 * On some platforms, this will match the "default font" | |
495 * or "system font" if such can be found. This font | |
496 * should not be freed because it was allocated by the | |
497 * system, not the application. | |
498 * <p> | |
499 * Typically, applications which want the default look | |
500 * should simply not set the font on the widgets they | |
501 * create. Widgets are always created with the correct | |
502 * default font for the class of user-interface component | |
503 * they represent. | |
504 * </p> | |
505 * | |
506 * @return a font | |
507 * | |
508 * @exception SWTException <ul> | |
509 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
510 * </ul> | |
511 */ | |
512 public Font getSystemFont () { | |
513 checkDevice (); | |
514 return systemFont; | |
515 } | |
516 | |
517 /** | |
518 * Returns <code>true</code> if the underlying window system prints out | |
519 * warning messages on the console, and <code>setWarnings</code> | |
520 * had previously been called with <code>true</code>. | |
521 * | |
522 * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise | |
523 * | |
524 * @exception SWTException <ul> | |
525 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
526 * </ul> | |
527 */ | |
19 | 528 public bool getWarnings () { |
18 | 529 checkDevice (); |
54 | 530 return warningLevel is 0; |
18 | 531 } |
532 | |
533 /** | |
534 * Initializes any internal resources needed by the | |
535 * device. | |
536 * <p> | |
537 * This method is called after <code>create</code>. | |
538 * </p><p> | |
539 * If subclasses reimplement this method, they must | |
540 * call the <code>super</code> implementation. | |
541 * </p> | |
542 * | |
543 * @see #create | |
544 */ | |
545 protected void init () { | |
19 | 546 if (xDisplay !is null) { |
547 int event_basep, error_basep; | |
548 if (OS.XRenderQueryExtension (xDisplay, &event_basep, &error_basep)) { | |
549 int major_version, minor_version; | |
550 OS.XRenderQueryVersion (xDisplay, &major_version, &minor_version); | |
54 | 551 useXRender = major_version > 0 || (major_version is 0 && minor_version >= 8); |
18 | 552 } |
553 } | |
554 | |
19 | 555 if (debugging) { |
556 if (xDisplay !is null) { | |
18 | 557 /* Create the warning and error callbacks */ |
19 | 558 synchronized (CREATE_LOCK) { |
18 | 559 int index = 0; |
560 while (index < Devices.length) { | |
54 | 561 if (Devices [index] !is null) break; |
18 | 562 index++; |
563 } | |
54 | 564 if (index is Devices.length) { |
19 | 565 OS.XSetErrorHandler ( & XErrorProcFunc ); |
566 OS.XSetIOErrorHandler ( & XIOErrorProcFunc ); | |
18 | 567 } |
568 } | |
569 OS.XSynchronize (xDisplay, true); | |
570 } | |
571 } | |
572 | |
573 /* Create GTK warnings and error callbacks */ | |
19 | 574 if (xDisplay !is null) { |
18 | 575 /* Set GTK warning and error handlers */ |
19 | 576 if (debugging) { |
18 | 577 int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION; |
578 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
|
579 handler_ids [i] = OS.g_log_set_handler (toStringz(log_domains [i]), flags, & logFunction, cast(void*)this); |
18 | 580 } |
581 } | |
582 } | |
583 | |
19 | 584 /* Create the standard colors */ |
18 | 585 COLOR_BLACK = new Color (this, 0,0,0); |
586 COLOR_DARK_RED = new Color (this, 0x80,0,0); | |
587 COLOR_DARK_GREEN = new Color (this, 0,0x80,0); | |
588 COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0); | |
589 COLOR_DARK_BLUE = new Color (this, 0,0,0x80); | |
590 COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80); | |
591 COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80); | |
592 COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0); | |
593 COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80); | |
594 COLOR_RED = new Color (this, 0xFF,0,0); | |
595 COLOR_GREEN = new Color (this, 0,0xFF,0); | |
596 COLOR_YELLOW = new Color (this, 0xFF,0xFF,0); | |
597 COLOR_BLUE = new Color (this, 0,0,0xFF); | |
598 COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF); | |
599 COLOR_CYAN = new Color (this, 0,0xFF,0xFF); | |
600 COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF); | |
601 | |
602 emptyTab = OS.pango_tab_array_new(1, false); | |
19 | 603 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
|
604 OS.pango_tab_array_set_tab(emptyTab, 0, OS.PANGO_TAB_LEFT, 1); |
18 | 605 |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
606 shellHandle = OS.gtk_window_new(OS.GTK_WINDOW_TOPLEVEL); |
19 | 607 if (shellHandle is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 608 OS.gtk_widget_realize(shellHandle); |
609 } | |
610 | |
611 /** | |
612 * Invokes platform specific functionality to allocate a new GC handle. | |
613 * <p> | |
614 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
615 * API for <code>Device</code>. It is marked public only so that it | |
616 * can be shared within the packages provided by SWT. It is not | |
617 * available on all platforms, and should never be called from | |
618 * application code. | |
619 * </p> | |
620 * | |
621 * @param data the platform specific GC data | |
622 * @return the platform specific GC handle | |
623 */ | |
19 | 624 public abstract GdkGC* internal_new_GC (GCData data); |
18 | 625 |
626 /** | |
627 * Invokes platform specific functionality to dispose a GC handle. | |
628 * <p> | |
629 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
630 * API for <code>Device</code>. It is marked public only so that it | |
631 * can be shared within the packages provided by SWT. It is not | |
632 * available on all platforms, and should never be called from | |
633 * application code. | |
634 * </p> | |
635 * | |
636 * @param hDC the platform specific GC handle | |
637 * @param data the platform specific GC data | |
638 */ | |
19 | 639 public abstract void internal_dispose_GC (GdkGC* handle, GCData data); |
18 | 640 |
641 /** | |
642 * Returns <code>true</code> if the device has been disposed, | |
643 * and <code>false</code> otherwise. | |
644 * <p> | |
645 * This method gets the dispose state for the device. | |
646 * When a device has been disposed, it is an error to | |
647 * invoke any other method using the device. | |
648 * | |
649 * @return <code>true</code> when the device is disposed and <code>false</code> otherwise | |
650 */ | |
19 | 651 public bool isDisposed () { |
18 | 652 return disposed; |
653 } | |
654 | |
655 /** | |
656 * Loads the font specified by a file. The font will be | |
657 * present in the list of fonts available to the application. | |
658 * | |
659 * @param path the font file path | |
660 * @return whether the font was successfully loaded | |
661 * | |
662 * @exception SWTException <ul> | |
663 * <li>ERROR_NULL_ARGUMENT - if path is null</li> | |
664 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
665 * </ul> | |
666 * | |
667 * @see Font | |
668 * | |
669 * @since 3.3 | |
670 */ | |
19 | 671 public bool loadFont (char[] path) { |
18 | 672 checkDevice(); |
54 | 673 if (path is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); |
19 | 674 return cast(bool) OS.FcConfigAppFontAddFile (null, toStringz(path)); |
18 | 675 } |
676 | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
677 private static extern(C) void logFunction (char* log_domain, int log_level, char* message, void* user_data) { |
19 | 678 Device dev = cast(Device)user_data; |
54 | 679 if (dev.warningLevel is 0) { |
19 | 680 if (DEBUG || dev.debugging) { |
681 foreach( msg; new TracedException ("") ){ | |
682 Stderr.formatln( "trc {}", msg ); | |
683 } | |
18 | 684 } |
19 | 685 OS.g_log_default_handler (log_domain, log_level, message, user_data); |
18 | 686 } |
687 return 0; | |
688 } | |
689 | |
690 void new_Object (Object object) { | |
691 for (int i=0; i<objects.length; i++) { | |
19 | 692 if (objects [i] is null) { |
18 | 693 objects [i] = object; |
19 | 694 errors [i] = new TracedException (""); |
18 | 695 return; |
696 } | |
697 } | |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
698 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
|
699 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
|
700 newObjects [objects.length] = object; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
701 objects = newObjects; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
702 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
|
703 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
|
704 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
|
705 errors = newErrors; |
18 | 706 } |
707 | |
708 static synchronized void register (Device device) { | |
709 for (int i=0; i<Devices.length; i++) { | |
19 | 710 if (Devices [i] is null) { |
18 | 711 Devices [i] = device; |
712 return; | |
713 } | |
714 } | |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
715 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
|
716 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
|
717 newDevices [Devices.length] = device; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
718 Devices = newDevices; |
18 | 719 } |
720 | |
721 /** | |
722 * Releases any internal resources back to the operating | |
723 * system and clears all fields except the device handle. | |
724 * <p> | |
725 * When a device is destroyed, resources that were acquired | |
726 * on behalf of the programmer need to be returned to the | |
727 * operating system. For example, if the device allocated a | |
728 * font to be used as the system font, this font would be | |
729 * freed in <code>release</code>. Also,to assist the garbage | |
730 * collector and minimize the amount of memory that is not | |
731 * reclaimed when the programmer keeps a reference to a | |
732 * disposed device, all fields except the handle are zero'd. | |
733 * The handle is needed by <code>destroy</code>. | |
734 * </p> | |
735 * This method is called before <code>destroy</code>. | |
736 * </p><p> | |
737 * If subclasses reimplement this method, they must | |
738 * call the <code>super</code> implementation. | |
739 * </p> | |
740 * | |
741 * @see #dispose | |
742 * @see #destroy | |
743 */ | |
744 protected void release () { | |
19 | 745 if (shellHandle !is null) OS.gtk_widget_destroy(shellHandle); |
746 shellHandle = null; | |
18 | 747 |
19 | 748 if (gdkColors !is null) { |
749 auto colormap = OS.gdk_colormap_get_system(); | |
18 | 750 for (int i = 0; i < gdkColors.length; i++) { |
19 | 751 GdkColor* color = gdkColors [i]; |
752 if (color !is null) { | |
18 | 753 while (colorRefCount [i] > 0) { |
754 OS.gdk_colormap_free_colors(colormap, color, 1); | |
755 --colorRefCount [i]; | |
756 } | |
757 } | |
758 } | |
759 } | |
760 gdkColors = null; | |
761 colorRefCount = null; | |
762 COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW = COLOR_DARK_BLUE = | |
763 COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED = | |
764 COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null; | |
765 | |
19 | 766 if (emptyTab !is null ) OS.pango_tab_array_free(emptyTab); |
767 emptyTab = null; | |
18 | 768 |
769 /* Free the GTK error and warning handler */ | |
19 | 770 if (xDisplay !is null) { |
18 | 771 for (int i=0; i<handler_ids.length; i++) { |
19 | 772 if (handler_ids [i] !is 0 ) { |
773 OS.g_log_remove_handler (toStringz(log_domains [i]), handler_ids [i]); | |
18 | 774 handler_ids [i] = 0; |
775 } | |
776 } | |
19 | 777 //logCallback.dispose (); logCallback = null; |
18 | 778 handler_ids = null; log_domains = null; |
19 | 779 //logProcFld = 0; |
18 | 780 } |
781 } | |
782 | |
783 /** | |
784 * If the underlying window system supports printing warning messages | |
785 * to the console, setting warnings to <code>false</code> prevents these | |
786 * messages from being printed. If the argument is <code>true</code> then | |
787 * message printing is not blocked. | |
788 * | |
789 * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise | |
790 * | |
791 * @exception SWTException <ul> | |
792 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> | |
793 * </ul> | |
794 */ | |
19 | 795 public void setWarnings (bool warnings) { |
18 | 796 checkDevice (); |
797 if (warnings) { | |
54 | 798 if (--warningLevel is 0) { |
19 | 799 if (debugging) return; |
800 for (int i=0; i<handler_ids.length; i++) { | |
54 | 801 if (handler_ids [i] !is 0) { |
19 | 802 OS.g_log_remove_handler (toStringz(log_domains [i]), handler_ids [i]); |
803 handler_ids [i] = 0; | |
804 } | |
805 } | |
18 | 806 } |
807 } else { | |
54 | 808 if (warningLevel++ is 0) { |
19 | 809 if (debugging) return; |
810 int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION; | |
811 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
|
812 handler_ids [i] = OS.g_log_set_handler (toStringz(log_domains [i]), flags, & logFunction, cast(void*)this ); |
19 | 813 } |
18 | 814 } |
815 } | |
816 } | |
817 | |
28 | 818 private static extern(C) int /*long*/ XErrorProcFunc (void* xDisplay, dwt.internal.gtk.OS.XErrorEvent* xErrorEvent) { |
18 | 819 Device device = findDevice (xDisplay); |
54 | 820 if (device !is null) { |
821 if (device.warningLevel is 0) { | |
19 | 822 if (DEBUG || device.debugging) { |
823 foreach( msg; new TracedException ("") ){ | |
824 Stderr.formatln( "trc {}", msg ); | |
825 } | |
18 | 826 } |
19 | 827 //PORTING_FIXME ?? |
828 //OS.Call (XErrorProc, xDisplay, xErrorEvent); | |
18 | 829 } |
830 } else { | |
19 | 831 if (DEBUG) (new SWTError ()).printStackTrace (); |
832 //PORTING_FIXME ?? | |
833 //OS.Call (XErrorProc, xDisplay, xErrorEvent); | |
18 | 834 } |
835 return 0; | |
836 } | |
837 | |
28 | 838 private static extern(C) int /*long*/ XIOErrorProcFunc (void* xDisplay) { |
18 | 839 Device device = findDevice (xDisplay); |
54 | 840 if (device !is null) { |
19 | 841 if (DEBUG || device.debugging) { |
842 foreach( msg; new TracedException ("") ){ | |
843 Stderr.formatln( "trc {}", msg ); | |
844 } | |
18 | 845 } |
846 } else { | |
19 | 847 if (DEBUG) { |
848 foreach( msg; new TracedException ("") ){ | |
849 Stderr.formatln( "trc {}", msg ); | |
850 } | |
851 } | |
18 | 852 } |
19 | 853 //PORTING_FIXME ?? |
854 //OS.Call (XIOErrorProc, xDisplay, 0); | |
18 | 855 return 0; |
856 } | |
857 | |
858 } |