Mercurial > projects > dwt-mac
comparison dwt/widgets/Button.d @ 27:dfcc6c4c4317
Ported dwt.widgets.Button
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Mon, 08 Sep 2008 18:15:39 +0200 |
parents | e831403a80a9 |
children | 7d135fe0caf2 |
comparison
equal
deleted
inserted
replaced
26:74a3be48bba8 | 27:dfcc6c4c4317 |
---|---|
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.widgets.Button; | 14 module dwt.widgets.Button; |
12 | |
13 import dwt.dwthelper.utils; | |
14 | 15 |
15 | 16 |
16 import dwt.DWT; | 17 import dwt.DWT; |
17 import dwt.DWTException; | 18 import dwt.DWTException; |
18 import dwt.events.SelectionEvent; | 19 import dwt.events.SelectionEvent; |
28 import dwt.internal.cocoa.NSRect; | 29 import dwt.internal.cocoa.NSRect; |
29 import dwt.internal.cocoa.NSString; | 30 import dwt.internal.cocoa.NSString; |
30 import dwt.internal.cocoa.OS; | 31 import dwt.internal.cocoa.OS; |
31 import dwt.internal.cocoa.SWTButton; | 32 import dwt.internal.cocoa.SWTButton; |
32 | 33 |
34 import dwt.dwthelper.utils; | |
35 import dwt.internal.cocoa.CGFloat; | |
36 import dwt.internal.cocoa.NSInteger; | |
37 import dwt.widgets.Composite; | |
38 import dwt.widgets.Decorations; | |
39 import dwt.widgets.ImageList; | |
40 import dwt.widgets.TypedListener; | |
41 | |
33 /** | 42 /** |
34 * Instances of this class represent a selectable user interface object that | 43 * Instances of this class represent a selectable user interface object that |
35 * issues notification when pressed and released. | 44 * issues notification when pressed and released. |
36 * <dl> | 45 * <dl> |
37 * <dt><b>Styles:</b></dt> | 46 * <dt><b>Styles:</b></dt> |
150 } | 159 } |
151 | 160 |
152 NSAttributedString createString() { | 161 NSAttributedString createString() { |
153 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); | 162 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); |
154 if (foreground !is null) { | 163 if (foreground !is null) { |
155 NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1); | 164 NSColor color = NSColor.colorWithDeviceRed(cast(CGFloat) foreground.handle[0], cast(CGFloat) foreground.handle[1], cast(CGFloat) foreground.handle[2], 1); |
156 dict.setObject(color, OS.NSForegroundColorAttributeName()); | 165 dict.setObject(color, OS.NSForegroundColorAttributeName()); |
157 } | 166 } |
158 if (font !is null) { | 167 if (font !is null) { |
159 dict.setObject(font.handle, OS.NSFontAttributeName()); | 168 dict.setObject(font.handle, OS.NSFontAttributeName()); |
160 } | 169 } |
164 } else if ((style & DWT.LEFT) !is 0) { | 173 } else if ((style & DWT.LEFT) !is 0) { |
165 alignment = OS.NSLeftTextAlignment; | 174 alignment = OS.NSLeftTextAlignment; |
166 } else { | 175 } else { |
167 alignment = OS.NSRightTextAlignment; | 176 alignment = OS.NSRightTextAlignment; |
168 } | 177 } |
169 NSMutableParagraphStyle pStyle = cast(NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init(); | 178 NSMutableParagraphStyle pStyle = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle()).alloc().init(); |
170 pStyle.autorelease(); | 179 pStyle.autorelease(); |
171 pStyle.setAlignment(alignment); | 180 pStyle.setAlignment(alignment); |
172 dict.setObject(pStyle, OS.NSParagraphStyleAttributeName()); | 181 dict.setObject(pStyle, OS.NSParagraphStyleAttributeName()); |
173 char [] chars = new char [text.length ()]; | 182 char [] chars = new char [text.length ()]; |
174 text.getChars (0, chars.length, chars, 0); | 183 text.getChars (0, chars.length, chars, 0); |
175 int length = fixMnemonic (chars); | 184 NSUInteger length = fixMnemonic (chars); |
176 NSString str = NSString.stringWithCharacters(chars, length); | 185 NSString str = NSString.stringWithCharacters(chars.toString16().ptr, length); |
177 NSAttributedString attribStr = (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict); | 186 NSAttributedString attribStr = (cast(NSAttributedString)(new NSAttributedString()).alloc()).initWithString_attributes_(str, dict); |
178 attribStr.autorelease(); | 187 attribStr.autorelease(); |
179 return attribStr; | 188 return attribStr; |
180 } | 189 } |
181 | 190 |
182 void createHandle () { | 191 void createHandle () { |
183 NSButton widget = cast(NSButton)new SWTButton().alloc(); | 192 NSButton widget = cast(NSButton)(new SWTButton()).alloc(); |
184 widget.initWithFrame(new NSRect()); | 193 widget.initWithFrame(NSRect()); |
185 int type = OS.NSMomentaryPushButton; | 194 int type = OS.NSMomentaryPushButton; |
186 if ((style & DWT.PUSH) !is 0) { | 195 if ((style & DWT.PUSH) !is 0) { |
187 widget.setBezelStyle(OS.NSRoundedBezelStyle); | 196 widget.setBezelStyle(OS.NSRoundedBezelStyle); |
188 } else if ((style & DWT.CHECK) !is 0) { | 197 } else if ((style & DWT.CHECK) !is 0) { |
189 type = OS.NSSwitchButton; | 198 type = OS.NSSwitchButton; |
449 void setBackground (float [] color) { | 458 void setBackground (float [] color) { |
450 NSColor nsColor; | 459 NSColor nsColor; |
451 if (color is null) { | 460 if (color is null) { |
452 return; // TODO set to OS default | 461 return; // TODO set to OS default |
453 } else { | 462 } else { |
454 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); | 463 nsColor = NSColor.colorWithDeviceRed(cast(CGFloat) color[0], cast(CGFloat) color[1], cast(CGFloat) color[2], 1); |
455 } | 464 } |
456 NSButtonCell cell = new NSButtonCell((cast(NSButton)view).cell()); | 465 NSButtonCell cell = new NSButtonCell((cast(NSButton)view).cell()); |
457 cell.setBackgroundColor(nsColor); | 466 cell.setBackgroundColor(nsColor); |
458 } | 467 } |
459 | 468 |