Mercurial > projects > dwt-mac
comparison dwt/widgets/Button.d @ 60:62202ce0039f
Updated and fixed many modules to 3.514
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 22 Dec 2008 15:10:19 +0100 |
parents | 858e9a565d62 |
children | 63a09873578e |
comparison
equal
deleted
inserted
replaced
59:83b0ad9d9238 | 60:62202ce0039f |
---|---|
39 import dwt.internal.cocoa.OS; | 39 import dwt.internal.cocoa.OS; |
40 import dwt.internal.cocoa.SWTButton; | 40 import dwt.internal.cocoa.SWTButton; |
41 import cocoa = dwt.internal.cocoa.id; | 41 import cocoa = dwt.internal.cocoa.id; |
42 | 42 |
43 import dwt.dwthelper.utils; | 43 import dwt.dwthelper.utils; |
44 import dwt.internal.c.Carbon; | 44 import Carbon = dwt.internal.c.Carbon; |
45 import dwt.internal.cocoa.NSCell; | 45 import dwt.internal.cocoa.NSCell; |
46 import dwt.internal.cocoa.NSText; | 46 import dwt.internal.cocoa.NSText; |
47 import dwt.internal.objc.cocoa.Cocoa; | 47 import dwt.internal.objc.cocoa.Cocoa; |
48 import objc = dwt.internal.objc.runtime; | 48 import objc = dwt.internal.objc.runtime; |
49 import dwt.widgets.Composite; | 49 import dwt.widgets.Composite; |
217 } | 217 } |
218 | 218 |
219 NSAttributedString createString() { | 219 NSAttributedString createString() { |
220 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); | 220 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); |
221 if (foreground !is null) { | 221 if (foreground !is null) { |
222 NSColor color = NSColor.colorWithDeviceRed(cast(CGFloat) foreground.handle[0], cast(CGFloat) foreground.handle[1], cast(CGFloat) foreground.handle[2], 1); | 222 NSColor color = NSColor.colorWithDeviceRed(cast(Carbon.CGFloat) foreground.handle[0], cast(Carbon.CGFloat) foreground.handle[1], cast(Carbon.CGFloat) foreground.handle[2], 1); |
223 dict.setObject(color, OS.NSForegroundColorAttributeName); | 223 dict.setObject(color, OS.NSForegroundColorAttributeName); |
224 } | 224 } |
225 | 225 |
226 dict.setObject(getFont().handle, OS.NSFontAttributeName); | 226 dict.setObject(getFont().handle, OS.NSFontAttributeName); |
227 | 227 |
246 return attribStr; | 246 return attribStr; |
247 } | 247 } |
248 | 248 |
249 void createHandle () { | 249 void createHandle () { |
250 NSButton widget = cast(NSButton)(new SWTButton()).alloc(); | 250 NSButton widget = cast(NSButton)(new SWTButton()).alloc(); |
251 widget.initWithFrame(new NSRect()); | 251 widget.initWithFrame(NSRect()); |
252 NSButtonType type = OS.NSMomentaryLightButton; | 252 NSButtonType type = OS.NSMomentaryLightButton; |
253 if ((style & SWT.PUSH) !is 0) { | 253 if ((style & DWT.PUSH) !is 0) { |
254 if ((style & SWT.FLAT) !is 0) { | 254 if ((style & DWT.FLAT) !is 0) { |
255 widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle); | 255 widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle); |
256 // if ((style & SWT.BORDER) is 0) widget.setShowsBorderOnlyWhileMouseInside(true); | 256 // if ((style & DWT.BORDER) is 0) widget.setShowsBorderOnlyWhileMouseInside(true); |
257 } else { | 257 } else { |
258 widget.setBezelStyle(OS.NSRoundedBezelStyle); | 258 widget.setBezelStyle(OS.NSRoundedBezelStyle); |
259 } | 259 } |
260 } else if ((style & SWT.CHECK) !is 0) { | 260 } else if ((style & DWT.CHECK) !is 0) { |
261 type = OS.NSSwitchButton; | 261 type = OS.NSSwitchButton; |
262 widget.setAllowsMixedState (true); | 262 widget.setAllowsMixedState (true); |
263 } else if ((style & SWT.RADIO) !is 0) { | 263 } else if ((style & DWT.RADIO) !is 0) { |
264 type = OS.NSRadioButton; | 264 type = OS.NSRadioButton; |
265 } else if ((style & SWT.TOGGLE) !is 0) { | 265 } else if ((style & DWT.TOGGLE) !is 0) { |
266 type = OS.NSPushOnPushOffButton; | 266 type = OS.NSPushOnPushOffButton; |
267 if ((style & SWT.FLAT) !is 0) { | 267 if ((style & DWT.FLAT) !is 0) { |
268 widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle); | 268 widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle); |
269 // if ((style & SWT.BORDER) is 0) widget.setShowsBorderOnlyWhileMouseInside(true); | 269 // if ((style & DWT.BORDER) is 0) widget.setShowsBorderOnlyWhileMouseInside(true); |
270 } else { | 270 } else { |
271 widget.setBezelStyle(OS.NSRoundedBezelStyle); | 271 widget.setBezelStyle(OS.NSRoundedBezelStyle); |
272 } | 272 } |
273 } else if ((style & SWT.ARROW) !is 0) { | 273 } else if ((style & DWT.ARROW) !is 0) { |
274 widget.setBezelStyle(OS.NSRegularSquareBezelStyle); | 274 widget.setBezelStyle(OS.NSRegularSquareBezelStyle); |
275 } | 275 } |
276 widget.setButtonType(type); | 276 widget.setButtonType(type); |
277 widget.setTitle(NSString.stringWith("")); | 277 widget.setTitle(NSString.stringWith("")); |
278 widget.setImagePosition(OS.NSImageLeft); | 278 widget.setImagePosition(OS.NSImageLeft); |
292 NSRect frame = view.frame(); | 292 NSRect frame = view.frame(); |
293 int arrowSize = Math.min(cast(int)frame.height, cast(int)frame.width) / 2; | 293 int arrowSize = Math.min(cast(int)frame.height, cast(int)frame.width) / 2; |
294 NSGraphicsContext context = NSGraphicsContext.currentContext(); | 294 NSGraphicsContext context = NSGraphicsContext.currentContext(); |
295 context.saveGraphicsState(); | 295 context.saveGraphicsState(); |
296 NSPoint p1 = NSPoint(); | 296 NSPoint p1 = NSPoint(); |
297 p1.x = cast(CGFloat)Math.floor(-arrowSize / 2); | 297 p1.x = cast(Carbon.CGFloat)Math.floor(-arrowSize / 2); |
298 p1.y = cast(CGFloat)Math.floor(-arrowSize / 2); | 298 p1.y = cast(Carbon.CGFloat)Math.floor(-arrowSize / 2); |
299 NSPoint p2 = NSPoint(); | 299 NSPoint p2 = NSPoint(); |
300 p2.x = cast(CGFloat)Math.ceil(arrowSize / 2); | 300 p2.x = cast(Carbon.CGFloat)Math.ceil(arrowSize / 2); |
301 p2.y = p1.y; | 301 p2.y = p1.y; |
302 NSPoint p3 = NSPoint(); | 302 NSPoint p3 = NSPoint(); |
303 p3.y = cast(CGFloat)Math.ceil(arrowSize / 2); | 303 p3.y = cast(Carbon.CGFloat)Math.ceil(arrowSize / 2); |
304 | 304 |
305 NSBezierPath path = NSBezierPath.bezierPath(); | 305 NSBezierPath path = NSBezierPath.bezierPath(); |
306 path.moveToPoint(p1); | 306 path.moveToPoint(p1); |
307 path.lineToPoint(p2); | 307 path.lineToPoint(p2); |
308 path.lineToPoint(p3); | 308 path.lineToPoint(p3); |
590 void setBackground (float [] color) { | 590 void setBackground (float [] color) { |
591 NSColor nsColor; | 591 NSColor nsColor; |
592 if (color is null) { | 592 if (color is null) { |
593 return; // TODO set to OS default | 593 return; // TODO set to OS default |
594 } else { | 594 } else { |
595 nsColor = NSColor.colorWithDeviceRed(cast(CGFloat) color[0], cast(CGFloat) color[1], cast(CGFloat) color[2], 1); | 595 nsColor = NSColor.colorWithDeviceRed(cast(Carbon.CGFloat) color[0], cast(Carbon.CGFloat) color[1], cast(Carbon.CGFloat) color[2], 1); |
596 } | 596 } |
597 NSButtonCell cell = new NSButtonCell((cast(NSButton)view).cell()); | 597 NSButtonCell cell = new NSButtonCell((cast(NSButton)view).cell()); |
598 cell.setBackgroundColor(nsColor); | 598 cell.setBackgroundColor(nsColor); |
599 } | 599 } |
600 | 600 |