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