Mercurial > projects > dwt-mac
comparison 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 |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
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 * | 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 <doob@me.com> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module dwt.widgets.FontDialog; | 14 module dwt.widgets.FontDialog; |
15 | 15 |
16 | 16 |
17 import dwt.DWT; | 17 import dwt.DWT; |
20 import dwt.graphics.FontData; | 20 import dwt.graphics.FontData; |
21 import dwt.graphics.PaletteData; | 21 import dwt.graphics.PaletteData; |
22 import dwt.graphics.RGB; | 22 import dwt.graphics.RGB; |
23 import dwt.internal.cocoa.NSApplication; | 23 import dwt.internal.cocoa.NSApplication; |
24 import dwt.internal.cocoa.NSFont; | 24 import dwt.internal.cocoa.NSFont; |
25 import dwt.internal.cocoa.NSFontManager; | |
26 import dwt.internal.cocoa.NSFontPanel; | 25 import dwt.internal.cocoa.NSFontPanel; |
27 import dwt.internal.cocoa.NSString; | 26 import dwt.internal.cocoa.NSString; |
28 import dwt.internal.cocoa.OS; | 27 import dwt.internal.cocoa.OS; |
29 import dwt.internal.cocoa.SWTPanelDelegate; | 28 import dwt.internal.cocoa.SWTPanelDelegate; |
30 | 29 |
45 * </dl> | 44 * </dl> |
46 * <p> | 45 * <p> |
47 * IMPORTANT: This class is intended to be subclassed <em>only</em> | 46 * IMPORTANT: This class is intended to be subclassed <em>only</em> |
48 * within the DWT implementation. | 47 * within the DWT implementation. |
49 * </p> | 48 * </p> |
49 * | |
50 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a> | |
51 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
50 */ | 52 */ |
51 public class FontDialog : Dialog { | 53 public class FontDialog : Dialog { |
52 FontData fontData; | 54 FontData fontData; |
53 RGB rgb; | 55 RGB rgb; |
54 bool open_; | 56 bool selected; |
55 int fontID, fontSize; | 57 int fontID, fontSize; |
56 | 58 |
57 /** | 59 /** |
58 * Constructs a new instance of this class given only its parent. | 60 * Constructs a new instance of this class given only its parent. |
59 * | 61 * |
94 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | 96 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
95 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | 97 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
96 * </ul> | 98 * </ul> |
97 */ | 99 */ |
98 public this (Shell parent, int style) { | 100 public this (Shell parent, int style) { |
99 super (parent, style); | 101 super (parent, checkStyle (parent, style)); |
100 checkSubclass (); | 102 checkSubclass (); |
101 } | 103 } |
102 | 104 |
103 void changeFont(int arg0) { | 105 void changeFont(objc.id id, objc.SEL sel, objc.id arg0) { |
106 selected = true; | |
104 } | 107 } |
105 | 108 |
106 /** | 109 /** |
107 * Returns a FontData object describing the font that was | 110 * Returns a FontData object describing the font that was |
108 * selected in the dialog, or null if none is available. | 111 * selected in the dialog, or null if none is available. |
216 * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> | 219 * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> |
217 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> | 220 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> |
218 * </ul> | 221 * </ul> |
219 */ | 222 */ |
220 public FontData open () { | 223 public FontData open () { |
221 Display display = parent !is null ? parent.display : Display.getCurrent (); | 224 Display display = parent !is null ? parent.display : Display.getCurrent (); |
222 | |
223 NSFontPanel panel = NSFontPanel.sharedFontPanel(); | 225 NSFontPanel panel = NSFontPanel.sharedFontPanel(); |
224 panel.setTitle(NSString.stringWith(title !is null ? title : "")); | 226 panel.setTitle(NSString.stringWith(title !is null ? title : "")); |
225 if (fontData !is null) { | 227 bool create = fontData !is null; |
226 Font font = new Font(display, fontData); | 228 Font font = create ? new Font(display, fontData) : display.getSystemFont(); |
227 NSFontManager.sharedFontManager().setSelectedFont(font.handle, false); | 229 panel.setPanelFont(font.handle, false); |
228 font.dispose(); | |
229 } | |
230 SWTPanelDelegate delegate_ = cast(SWTPanelDelegate)(new SWTPanelDelegate()).alloc().init(); | 230 SWTPanelDelegate delegate_ = cast(SWTPanelDelegate)(new SWTPanelDelegate()).alloc().init(); |
231 NSInteger jniRef = OS.NewGlobalRef(this); | 231 char* jniRef = OS.NewGlobalRef(this); |
232 if (jniRef is 0) DWT.error(DWT.ERROR_NO_HANDLES); | 232 if (jniRef is null) DWT.error(DWT.ERROR_NO_HANDLES); |
233 delegate_.setTag(jniRef); | 233 OS.object_setInstanceVariable(delegate.id, Display.DWT_OBJECT, jniRef); |
234 panel.setDelegate(delegate_); | 234 panel.setDelegate(delegate_); |
235 fontData = null; | 235 fontData = null; |
236 selected = false; | |
236 panel.orderFront(null); | 237 panel.orderFront(null); |
237 NSApplication.sharedApplication().runModalForWindow_(panel); | 238 NSApplication.sharedApplication().runModalForWindow(panel); |
239 if (selected) { | |
240 NSFont nsFont = panel.panelConvertFont(font.handle); | |
241 if (nsFont !is null) { | |
242 fontData = Font.cocoa_new(display, nsFont).getFontData()[0]; | |
243 } | |
244 } | |
238 panel.setDelegate(null); | 245 panel.setDelegate(null); |
239 delegate_.release(); | 246 delegate_.release(); |
240 OS.DeleteGlobalRef(jniRef); | 247 OS.DeleteGlobalRef(jniRef); |
241 NSFont font = NSFontManager.sharedFontManager().selectedFont(); | 248 if (create) font.dispose(); |
242 if (font !is null) { | |
243 //TODO - this does work | |
244 fontData = Font.cocoa_new(display, font).getFontData()[0]; | |
245 } | |
246 return fontData; | 249 return fontData; |
247 } | 250 } |
248 | 251 |
249 /** | 252 /** |
250 * Sets a FontData object describing the font to be | 253 * Sets a FontData object describing the font to be |
291 */ | 294 */ |
292 public void setRGB (RGB rgb) { | 295 public void setRGB (RGB rgb) { |
293 this.rgb = rgb; | 296 this.rgb = rgb; |
294 } | 297 } |
295 | 298 |
296 void windowWillClose(int sender) { | 299 void windowWillClose(objc.id id, objc.SEL sel, objc.id sender) { |
297 NSApplication.sharedApplication().stop(null); | 300 NSApplication.sharedApplication().stop(null); |
298 } | 301 } |
299 | 302 |
300 } | 303 } |