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