Mercurial > projects > dwt-mac
comparison dwt/graphics/Device.d @ 28:71b49a659702
Ported dwt.graphics.Device
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Mon, 08 Sep 2008 22:42:00 +0200 |
parents | 5b53d338c709 |
children | db5a898b2119 |
comparison
equal
deleted
inserted
replaced
27:dfcc6c4c4317 | 28:71b49a659702 |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.graphics.Device; | 14 module dwt.graphics.Device; |
12 | 15 |
13 import dwt.dwthelper.utils; | 16 import dwt.dwthelper.utils; |
14 | 17 |
27 import dwt.internal.cocoa.OS; | 30 import dwt.internal.cocoa.OS; |
28 import dwt.internal.cocoa.id; | 31 import dwt.internal.cocoa.id; |
29 | 32 |
30 import dwt.graphics.Drawable; | 33 import dwt.graphics.Drawable; |
31 | 34 |
35 import dwt.graphics.Color; | |
36 import dwt.graphics.DeviceData; | |
37 import dwt.graphics.Font; | |
38 import dwt.graphics.FontData; | |
39 import dwt.graphics.GCData; | |
40 import dwt.graphics.Rectangle; | |
41 import dwt.internal.cocoa.NSInteger; | |
42 | |
43 | |
32 /** | 44 /** |
33 * This class is the abstract superclass of all device objects, | 45 * This class is the abstract superclass of all device objects, |
34 * such as the Display device and the Printer device. Devices | 46 * such as the Display device and the Printer device. Devices |
35 * can have a graphics context cast(GC) created for them, and they | 47 * can have a graphics context cast(GC) created for them, and they |
36 * can be drawn on by sending messages to the associated GC. | 48 * can be drawn on by sending messages to the associated GC. |
37 */ | 49 */ |
38 public abstract class Device : Drawable { | 50 public abstract class Device : Drawable { |
39 | 51 |
40 /* Debugging */ | 52 /* Debugging */ |
41 public static bool DEBUG; | 53 public static bool DEBUG; |
42 bool debug = DEBUG; | 54 bool debugg = DEBUG; |
43 bool tracking = DEBUG; | 55 bool tracking = DEBUG; |
44 Error [] errors; | 56 Error [] errors; |
45 Object [] objects; | 57 Object [] objects; |
46 Object trackingLock; | 58 Object trackingLock; |
47 | 59 |
67 * | 79 * |
68 * This code will be removed in the future. | 80 * This code will be removed in the future. |
69 */ | 81 */ |
70 protected static Device CurrentDevice; | 82 protected static Device CurrentDevice; |
71 protected static Runnable DeviceFinder; | 83 protected static Runnable DeviceFinder; |
72 static { | 84 static this (){ |
73 try { | 85 try { |
74 Class.forName ("dwt.widgets.Display"); | 86 ClassInfo.find ("dwt.widgets.Display"); |
75 } catch (Throwable e) {} | 87 } catch (Throwable e) {} |
76 } | 88 } |
77 | 89 |
78 /* | 90 /* |
79 * TEMPORARY CODE. | 91 * TEMPORARY CODE. |
111 * @see #create | 123 * @see #create |
112 * @see #init | 124 * @see #init |
113 * @see DeviceData | 125 * @see DeviceData |
114 */ | 126 */ |
115 public this(DeviceData data) { | 127 public this(DeviceData data) { |
116 synchronized (Device.class) { | 128 synchronized (Device.classinfo) { |
117 if (data !is null) { | 129 if (data !is null) { |
118 debug = data.debug; | 130 debugg = data.debugg; |
119 tracking = data.tracking; | 131 tracking = data.tracking; |
120 } | 132 } |
121 if (tracking) { | 133 if (tracking) { |
122 errors = new Error [128]; | 134 errors = new Error [128]; |
123 objects = new Object [128]; | 135 objects = new Object [128]; |
178 * @see #release | 190 * @see #release |
179 * @see #destroy | 191 * @see #destroy |
180 * @see #checkDevice | 192 * @see #checkDevice |
181 */ | 193 */ |
182 public void dispose () { | 194 public void dispose () { |
183 synchronized (Device.class) { | 195 synchronized (Device.classinfo) { |
184 if (isDisposed()) return; | 196 if (isDisposed()) return; |
185 checkDevice (); | 197 checkDevice (); |
186 release (); | 198 release (); |
187 destroy (); | 199 destroy (); |
188 disposed = true; | 200 disposed = true; |
255 * @see DeviceData | 267 * @see DeviceData |
256 */ | 268 */ |
257 public DeviceData getDeviceData () { | 269 public DeviceData getDeviceData () { |
258 checkDevice(); | 270 checkDevice(); |
259 DeviceData data = new DeviceData (); | 271 DeviceData data = new DeviceData (); |
260 data.debug = debug; | 272 data.debugg = debugg; |
261 data.tracking = tracking; | 273 data.tracking = tracking; |
262 if (tracking) { | 274 if (tracking) { |
263 synchronized (trackingLock) { | 275 synchronized (trackingLock) { |
264 int count = 0, length = objects.length; | 276 int count = 0, length = objects.length; |
265 for (int i=0; i<length; i++) { | 277 for (int i=0; i<length; i++) { |
331 * </ul> | 343 * </ul> |
332 */ | 344 */ |
333 public Point getDPI () { | 345 public Point getDPI () { |
334 checkDevice (); | 346 checkDevice (); |
335 NSDictionary dictionary = NSScreen.mainScreen().deviceDescription(); | 347 NSDictionary dictionary = NSScreen.mainScreen().deviceDescription(); |
336 NSValue value = new NSValue(dictionary.objectForKey(new id(OS.NSDeviceResolution())).id); | 348 NSValue value = new NSValue(dictionary.objectForKey(new id(OS.NSDeviceResolution())).id_); |
337 NSSize size = value.sizeValue(); | 349 NSSize size = value.sizeValue(); |
338 return new Point(cast(int)size.width, cast(int)size.height); | 350 return new Point(cast(int)size.width, cast(int)size.height); |
339 } | 351 } |
340 | 352 |
341 /** | 353 /** |
355 checkDevice (); | 367 checkDevice (); |
356 if (!scalable) return new FontData[0]; | 368 if (!scalable) return new FontData[0]; |
357 NSArray fonts = NSFontManager.sharedFontManager().availableFonts(); | 369 NSArray fonts = NSFontManager.sharedFontManager().availableFonts(); |
358 int count = 0; | 370 int count = 0; |
359 FontData[] fds = new FontData[fonts.count()]; | 371 FontData[] fds = new FontData[fonts.count()]; |
360 for (int i = 0; i < fds.length; i++) { | 372 for (NSUInteger i = 0; i < fds.length; i++) { |
361 NSString str = new NSString(fonts.objectAtIndex(i)); | 373 NSString str = new NSString(fonts.objectAtIndex(i)); |
362 char[] buffer = new char[str.length()]; | 374 char[] buffer = new char[str.length()]; |
363 str.getCharacters_(buffer); | 375 str.getCharacters_(buffer.toString16().ptr); |
364 String nsName = new String(buffer); | 376 String nsName = buffer.dup; |
365 String name = nsName; | 377 String name = nsName; |
366 int index = nsName.indexOf('-'); | 378 int index = nsName.indexOf('-'); |
367 if (index !is -1) name = name.substring(0, index); | 379 if (index !is -1) name = name.substring(0, index); |
368 int style = DWT.NORMAL; | 380 int style = DWT.NORMAL; |
369 if (nsName.indexOf("Italic") !is -1) style |= DWT.ITALIC; | 381 if (nsName.indexOf("Italic") !is -1) style |= DWT.ITALIC; |
537 * invoke any other method using the device. | 549 * invoke any other method using the device. |
538 * | 550 * |
539 * @return <code>true</code> when the device is disposed and <code>false</code> otherwise | 551 * @return <code>true</code> when the device is disposed and <code>false</code> otherwise |
540 */ | 552 */ |
541 public bool isDisposed () { | 553 public bool isDisposed () { |
542 synchronized (Device.class) { | 554 synchronized (Device.classinfo) { |
543 return disposed; | 555 return disposed; |
544 } | 556 } |
545 } | 557 } |
546 | 558 |
547 /** | 559 /** |