Mercurial > projects > dwt-mac
diff dwt/widgets/FontDialog.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | 642f460a0908 |
children | 96d20dc95b8c |
line wrap: on
line diff
--- a/dwt/widgets/FontDialog.d Tue Oct 21 15:20:04 2008 +0200 +++ b/dwt/widgets/FontDialog.d Mon Dec 01 17:07:00 2008 +0100 @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,7 +9,7 @@ * IBM Corporation - initial API and implementation * * Port to the D programming language: - * Jacob Carlborg <jacob.carlborg@gmail.com> + * Jacob Carlborg <doob@me.com> *******************************************************************************/ module dwt.widgets.FontDialog; @@ -22,7 +22,6 @@ import dwt.graphics.RGB; import dwt.internal.cocoa.NSApplication; import dwt.internal.cocoa.NSFont; -import dwt.internal.cocoa.NSFontManager; import dwt.internal.cocoa.NSFontPanel; import dwt.internal.cocoa.NSString; import dwt.internal.cocoa.OS; @@ -47,11 +46,14 @@ * IMPORTANT: This class is intended to be subclassed <em>only</em> * within the DWT implementation. * </p> + * + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class FontDialog : Dialog { FontData fontData; RGB rgb; - bool open_; + bool selected; int fontID, fontSize; /** @@ -96,11 +98,12 @@ * </ul> */ public this (Shell parent, int style) { - super (parent, style); + super (parent, checkStyle (parent, style)); checkSubclass (); } - void changeFont(int arg0) { +void changeFont(objc.id id, objc.SEL sel, objc.id arg0) { + selected = true; } /** @@ -218,31 +221,31 @@ * </ul> */ public FontData open () { - Display display = parent !is null ? parent.display : Display.getCurrent (); - + Display display = parent !is null ? parent.display : Display.getCurrent (); NSFontPanel panel = NSFontPanel.sharedFontPanel(); panel.setTitle(NSString.stringWith(title !is null ? title : "")); - if (fontData !is null) { - Font font = new Font(display, fontData); - NSFontManager.sharedFontManager().setSelectedFont(font.handle, false); - font.dispose(); - } + bool create = fontData !is null; + Font font = create ? new Font(display, fontData) : display.getSystemFont(); + panel.setPanelFont(font.handle, false); SWTPanelDelegate delegate_ = cast(SWTPanelDelegate)(new SWTPanelDelegate()).alloc().init(); - NSInteger jniRef = OS.NewGlobalRef(this); - if (jniRef is 0) DWT.error(DWT.ERROR_NO_HANDLES); - delegate_.setTag(jniRef); + char* jniRef = OS.NewGlobalRef(this); + if (jniRef is null) DWT.error(DWT.ERROR_NO_HANDLES); + OS.object_setInstanceVariable(delegate.id, Display.DWT_OBJECT, jniRef); panel.setDelegate(delegate_); fontData = null; + selected = false; panel.orderFront(null); - NSApplication.sharedApplication().runModalForWindow_(panel); + NSApplication.sharedApplication().runModalForWindow(panel); + if (selected) { + NSFont nsFont = panel.panelConvertFont(font.handle); + if (nsFont !is null) { + fontData = Font.cocoa_new(display, nsFont).getFontData()[0]; + } + } panel.setDelegate(null); delegate_.release(); OS.DeleteGlobalRef(jniRef); - NSFont font = NSFontManager.sharedFontManager().selectedFont(); - if (font !is null) { - //TODO - this does work - fontData = Font.cocoa_new(display, font).getFontData()[0]; - } + if (create) font.dispose(); return fontData; } @@ -293,7 +296,7 @@ this.rgb = rgb; } - void windowWillClose(int sender) { +void windowWillClose(objc.id id, objc.SEL sel, objc.id sender) { NSApplication.sharedApplication().stop(null); }