# HG changeset patch # User Jacob Carlborg # Date 1230736600 -3600 # Node ID 7046ca5a6d778f0a9df399d008f5f9b54b482e80 # Parent d9893755f670acea638142dbd9db98d41c15feff Ported dwt.printing.Printer diff -r d9893755f670 -r 7046ca5a6d77 dwt/printing/PrintDialog.d --- a/dwt/printing/PrintDialog.d Wed Dec 31 16:07:41 2008 +0100 +++ b/dwt/printing/PrintDialog.d Wed Dec 31 16:16:40 2008 +0100 @@ -30,6 +30,7 @@ import dwt.widgets.Shell; import dwt.widgets.Widget; +import dwt.printing.Printer; import dwt.printing.PrinterData; /** diff -r d9893755f670 -r 7046ca5a6d77 dwt/printing/Printer.d --- a/dwt/printing/Printer.d Wed Dec 31 16:07:41 2008 +0100 +++ b/dwt/printing/Printer.d Wed Dec 31 16:16:40 2008 +0100 @@ -7,6 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg *******************************************************************************/ module dwt.printing.Printer; @@ -37,6 +40,10 @@ import dwt.internal.cocoa.NSWindow; import dwt.internal.cocoa.OS; +import Carbon = dwt.internal.c.Carbon; +import dwt.internal.objc.cocoa.Cocoa; +import dwt.printing.PrinterData; + /** * Instances of this class are used to print to a printer. * Applications create a GC on a printer using new GC(printer) @@ -78,9 +85,9 @@ */ public static PrinterData[] getPrinterList() { NSArray printers = NSPrinter.printerNames(); - int count = (int)/*64*/printers.count(); + NSUInteger count = printers.count(); PrinterData[] result = new PrinterData[count]; - for (int i = 0; i < count; i++) { + for (NSUInteger i = 0; i < count; i++) { NSString str = new NSString(printers.objectAtIndex(i)); result[i] = new PrinterData(DRIVER, str.getString()); } @@ -116,7 +123,7 @@ * * @see Device#dispose */ -public Printer() { +public this() { this(null); } @@ -138,7 +145,7 @@ * * @see Device#dispose */ -public Printer(PrinterData data) { +public this(PrinterData data) { super (checkNull(data)); } @@ -196,9 +203,9 @@ * @param deviceData the device data */ protected void create(DeviceData deviceData) { - data = (PrinterData)deviceData; + data = cast(PrinterData)deviceData; if (data.otherData !is null) { - NSData nsData = NSData.dataWithBytes(data.otherData, data.otherData.length); + NSData nsData = NSData.dataWithBytes(data.otherData.ptr, data.otherData.length); printInfo = new NSPrintInfo(NSKeyedUnarchiver.unarchiveObjectWithData(nsData).id); } else { printInfo = NSPrintInfo.sharedPrintInfo(); @@ -214,13 +221,13 @@ * the user chooses the preview button. The fix is to reset the job disposition. */ NSString job = printInfo.jobDisposition(); - if (job.isEqual(new NSString(OS.NSPrintPreviewJob()))) { + if (job.isEqual(new NSString(OS.NSPrintPreviewJob_))) { printInfo.setJobDisposition(job); } NSRect rect = NSRect(); - window = (NSWindow)new NSWindow().alloc(); + window = cast(NSWindow)(new NSWindow()).alloc(); window.initWithContentRect(rect, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false); - view = (NSView)new NSView().alloc(); + view = cast(NSView)(new NSView()).alloc(); view.initWithFrame(rect); window.setContentView(view); operation = NSPrintOperation.printOperationWithView(view, printInfo); @@ -259,7 +266,7 @@ * @param data the platform specific GC data * @return the platform specific GC handle */ -public int /*long*/ internal_new_GC(GCData data) { +public objc.id internal_new_GC(GCData data) { if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if (data !is null) { if (isGCCreated) DWT.error(DWT.ERROR_INVALID_ARGUMENT); @@ -267,14 +274,15 @@ data.background = getSystemColor(DWT.COLOR_WHITE).handle; data.foreground = getSystemColor(DWT.COLOR_BLACK).handle; data.font = getSystemFont (); - data.size = printInfo.paperSize(); + data.sizeStruct = printInfo.paperSize(); + data.size = &data.sizeStruct; isGCCreated = true; } return operation.context().id; } -protected void init () { - super.init(); +protected void init_ () { + super.init_(); } /** @@ -290,7 +298,7 @@ * @param hDC the platform specific GC handle * @param data the platform specific GC data */ -public void internal_dispose_GC(int /*long*/ context, GCData data) { +public void internal_dispose_GC(objc.id context, GCData data) { if (data !is null) isGCCreated = false; } @@ -413,7 +421,7 @@ transform.translateXBy(imageBounds.x, rect.height - imageBounds.y); transform.scaleXBy(1, -1); Point dpi = getDPI (), screenDPI = getIndependentDPI(); - transform.scaleXBy(screenDPI.x / (float)dpi.x, screenDPI.y / (float)dpi.y); + transform.scaleXBy(screenDPI.x / cast(Carbon.CGFloat)dpi.x, screenDPI.y / cast(Carbon.CGFloat)dpi.y); transform.concat(); return true; } @@ -474,7 +482,7 @@ checkDevice(); NSSize size = printInfo.paperSize(); Point dpi = getDPI (), screenDPI = getIndependentDPI(); - return new Rectangle (0, 0, (int)(size.width * dpi.x / screenDPI.x), (int)(size.height * dpi.y / screenDPI.y)); + return new Rectangle (0, 0, cast(int)(size.width * dpi.x / screenDPI.x), cast(int)(size.height * dpi.y / screenDPI.y)); } /** @@ -498,7 +506,7 @@ checkDevice(); NSRect rect = printInfo.imageablePageBounds(); Point dpi = getDPI (), screenDPI = getIndependentDPI(); - return new Rectangle(0, 0, (int)(rect.width * dpi.x / screenDPI.x), (int)(rect.height * dpi.y / screenDPI.y)); + return new Rectangle(0, 0, cast(int)(rect.width * dpi.x / screenDPI.x), cast(int)(rect.height * dpi.y / screenDPI.y)); } /**