Mercurial > projects > dwt-mac
comparison dwt/graphics/Device.d @ 36:db5a898b2119
Fixed a lot of compile errors
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Tue, 07 Oct 2008 12:56:18 +0200 |
parents | 71b49a659702 |
children | 642f460a0908 |
comparison
equal
deleted
inserted
replaced
35:7d135fe0caf2 | 36:db5a898b2119 |
---|---|
10 * | 10 * |
11 * Port to the D programming language: | 11 * Port to the D programming language: |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 12 * Jacob Carlborg <jacob.carlborg@gmail.com> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module dwt.graphics.Device; | 14 module dwt.graphics.Device; |
15 | |
16 import dwt.dwthelper.utils; | |
17 | 15 |
18 import dwt.DWT; | 16 import dwt.DWT; |
19 import dwt.DWTException; | 17 import dwt.DWTException; |
20 import dwt.internal.Compatibility; | 18 import dwt.internal.Compatibility; |
21 import dwt.internal.cocoa.NSArray; | 19 import dwt.internal.cocoa.NSArray; |
28 import dwt.internal.cocoa.NSString; | 26 import dwt.internal.cocoa.NSString; |
29 import dwt.internal.cocoa.NSValue; | 27 import dwt.internal.cocoa.NSValue; |
30 import dwt.internal.cocoa.OS; | 28 import dwt.internal.cocoa.OS; |
31 import dwt.internal.cocoa.id; | 29 import dwt.internal.cocoa.id; |
32 | 30 |
31 import dwt.dwthelper.Runnable; | |
32 import dwt.dwthelper.utils; | |
33 import dwt.graphics.Drawable; | 33 import dwt.graphics.Drawable; |
34 | |
35 import dwt.graphics.Color; | 34 import dwt.graphics.Color; |
36 import dwt.graphics.DeviceData; | 35 import dwt.graphics.DeviceData; |
37 import dwt.graphics.Font; | 36 import dwt.graphics.Font; |
38 import dwt.graphics.FontData; | 37 import dwt.graphics.FontData; |
39 import dwt.graphics.GCData; | 38 import dwt.graphics.GCData; |
39 import dwt.graphics.Point; | |
40 import dwt.graphics.Rectangle; | 40 import dwt.graphics.Rectangle; |
41 import dwt.internal.cocoa.NSInteger; | 41 import dwt.internal.cocoa.NSInteger; |
42 import objc = dwt.internal.objc.runtime; | |
42 | 43 |
43 | 44 |
44 /** | 45 /** |
45 * This class is the abstract superclass of all device objects, | 46 * This class is the abstract superclass of all device objects, |
46 * such as the Display device and the Printer device. Devices | 47 * such as the Display device and the Printer device. Devices |
47 * can have a graphics context cast(GC) created for them, and they | 48 * can have a graphics context cast(GC) created for them, and they |
48 * can be drawn on by sending messages to the associated GC. | 49 * can be drawn on by sending messages to the associated GC. |
49 */ | 50 */ |
50 public abstract class Device : Drawable { | 51 public abstract class Device : Drawable { |
51 | 52 |
52 /* Debugging */ | 53 /* debug_ing */ |
53 public static bool DEBUG; | 54 public static const bool DEBUG = true; |
54 bool debugg = DEBUG; | 55 bool debug_ = DEBUG; |
55 bool tracking = DEBUG; | 56 bool tracking = DEBUG; |
56 Error [] errors; | 57 Error [] errors; |
57 Object [] objects; | 58 Object [] objects; |
58 Object trackingLock; | 59 Object trackingLock; |
59 | 60 |
125 * @see DeviceData | 126 * @see DeviceData |
126 */ | 127 */ |
127 public this(DeviceData data) { | 128 public this(DeviceData data) { |
128 synchronized (Device.classinfo) { | 129 synchronized (Device.classinfo) { |
129 if (data !is null) { | 130 if (data !is null) { |
130 debugg = data.debugg; | 131 debug_ = data.debug_; |
131 tracking = data.tracking; | 132 tracking = data.tracking; |
132 } | 133 } |
133 if (tracking) { | 134 if (tracking) { |
134 errors = new Error [128]; | 135 errors = new Error [128]; |
135 objects = new Object [128]; | 136 objects = new Object [128]; |
136 trackingLock = new Object (); | 137 trackingLock = new Object (); |
137 } | 138 } |
138 create (data); | 139 create (data); |
139 init (); | 140 init_ (); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 /** | 144 /** |
144 * Throws an <code>DWTException</code> if the receiver can not | 145 * Throws an <code>DWTException</code> if the receiver can not |
267 * @see DeviceData | 268 * @see DeviceData |
268 */ | 269 */ |
269 public DeviceData getDeviceData () { | 270 public DeviceData getDeviceData () { |
270 checkDevice(); | 271 checkDevice(); |
271 DeviceData data = new DeviceData (); | 272 DeviceData data = new DeviceData (); |
272 data.debugg = debugg; | 273 data.debug_ = debug_; |
273 data.tracking = tracking; | 274 data.tracking = tracking; |
274 if (tracking) { | 275 if (tracking) { |
275 synchronized (trackingLock) { | 276 synchronized (trackingLock) { |
276 int count = 0, length = objects.length; | 277 int count = 0, length = objects.length; |
277 for (int i=0; i<length; i++) { | 278 for (int i=0; i<length; i++) { |
343 * </ul> | 344 * </ul> |
344 */ | 345 */ |
345 public Point getDPI () { | 346 public Point getDPI () { |
346 checkDevice (); | 347 checkDevice (); |
347 NSDictionary dictionary = NSScreen.mainScreen().deviceDescription(); | 348 NSDictionary dictionary = NSScreen.mainScreen().deviceDescription(); |
348 NSValue value = new NSValue(dictionary.objectForKey(new id(OS.NSDeviceResolution())).id_); | 349 NSValue value = new NSValue(dictionary.objectForKey(new id(OS.NSDeviceResolution().id_)).id_); |
349 NSSize size = value.sizeValue(); | 350 NSSize size = value.sizeValue(); |
350 return new Point(cast(int)size.width, cast(int)size.height); | 351 return new Point(cast(int)size.width, cast(int)size.height); |
351 } | 352 } |
352 | 353 |
353 /** | 354 /** |
484 * call the <code>super</code> implementation. | 485 * call the <code>super</code> implementation. |
485 * </p> | 486 * </p> |
486 * | 487 * |
487 * @see #create | 488 * @see #create |
488 */ | 489 */ |
489 protected void init () { | 490 protected void init_ () { |
490 /* Create the standard colors */ | 491 /* Create the standard colors */ |
491 COLOR_BLACK = new Color (this, 0,0,0); | 492 COLOR_BLACK = new Color (this, 0,0,0); |
492 COLOR_DARK_RED = new Color (this, 0x80,0,0); | 493 COLOR_DARK_RED = new Color (this, 0x80,0,0); |
493 COLOR_DARK_GREEN = new Color (this, 0,0x80,0); | 494 COLOR_DARK_GREEN = new Color (this, 0,0x80,0); |
494 COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0); | 495 COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0); |
521 * </p> | 522 * </p> |
522 * | 523 * |
523 * @param data the platform specific GC data | 524 * @param data the platform specific GC data |
524 * @return the platform specific GC handle | 525 * @return the platform specific GC handle |
525 */ | 526 */ |
526 public abstract int internal_new_GC (GCData data); | 527 public abstract objc.id internal_new_GC (GCData data); |
527 | 528 |
528 /** | 529 /** |
529 * Invokes platform specific functionality to dispose a GC handle. | 530 * Invokes platform specific functionality to dispose a GC handle. |
530 * <p> | 531 * <p> |
531 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | 532 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public |
584 void new_Object (Object object) { | 585 void new_Object (Object object) { |
585 synchronized (trackingLock) { | 586 synchronized (trackingLock) { |
586 for (int i=0; i<objects.length; i++) { | 587 for (int i=0; i<objects.length; i++) { |
587 if (objects [i] is null) { | 588 if (objects [i] is null) { |
588 objects [i] = object; | 589 objects [i] = object; |
589 errors [i] = new Error (); | 590 errors [i] = new Error (""); |
590 return; | 591 return; |
591 } | 592 } |
592 } | 593 } |
593 Object [] newObjects = new Object [objects.length + 128]; | 594 Object [] newObjects = new Object [objects.length + 128]; |
594 System.arraycopy (objects, 0, newObjects, 0, objects.length); | 595 System.arraycopy (objects, 0, newObjects, 0, objects.length); |
595 newObjects [objects.length] = object; | 596 newObjects [objects.length] = object; |
596 objects = newObjects; | 597 objects = newObjects; |
597 Error [] newErrors = new Error [errors.length + 128]; | 598 Error [] newErrors = new Error [errors.length + 128]; |
598 System.arraycopy (errors, 0, newErrors, 0, errors.length); | 599 System.arraycopy (errors, 0, newErrors, 0, errors.length); |
599 newErrors [errors.length] = new Error (); | 600 newErrors [errors.length] = new Error (""); |
600 errors = newErrors; | 601 errors = newErrors; |
601 } | 602 } |
602 } | 603 } |
603 | 604 |
604 /** | 605 /** |