Mercurial > projects > dwt-mac
comparison dwt/widgets/Button.d @ 52:858e9a565d62
Updated Button to 3.514
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 07 Dec 2008 21:40:42 +0100 |
parents | cfa563df4fdd |
children | 62202ce0039f |
comparison
equal
deleted
inserted
replaced
51:e6f04eb518ae | 52:858e9a565d62 |
---|---|
142 | 142 |
143 if (role !is null) { | 143 if (role !is null) { |
144 if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute)) | 144 if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute)) |
145 return role.id; | 145 return role.id; |
146 else { | 146 else { |
147 int roleDescription = OS.NSAccessibilityRoleDescription(role.id, 0); | 147 objc.id roleDescription = OS.NSAccessibilityRoleDescription(role.id, null); |
148 return roleDescription; | 148 return roleDescription; |
149 } | 149 } |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
227 | 227 |
228 NSTextAlignment alignment; | 228 NSTextAlignment alignment; |
229 if ((style & DWT.CENTER) !is 0) { | 229 if ((style & DWT.CENTER) !is 0) { |
230 alignment = OS.NSCenterTextAlignment; | 230 alignment = OS.NSCenterTextAlignment; |
231 } else if ((style & DWT.LEFT) !is 0) { | 231 } else if ((style & DWT.LEFT) !is 0) { |
232 alignment = NSLeftTextAlignment; | 232 alignment = OS.NSLeftTextAlignment; |
233 } else { | 233 } else { |
234 alignment = NSRightTextAlignment; | 234 alignment = OS.NSRightTextAlignment; |
235 } | 235 } |
236 NSMutableParagraphStyle pStyle = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle()).alloc().init(); | 236 NSMutableParagraphStyle pStyle = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle()).alloc().init(); |
237 pStyle.autorelease(); | 237 pStyle.autorelease(); |
238 pStyle.setAlignment(alignment); | 238 pStyle.setAlignment(alignment); |
239 dict.setObject(pStyle, OS.NSParagraphStyleAttributeName); | 239 dict.setObject(pStyle, OS.NSParagraphStyleAttributeName); |
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(NSRect()); | 251 widget.initWithFrame(new NSRect()); |
252 NSButtonType type = NSMomentaryLightButton; | 252 NSButtonType type = OS.NSMomentaryLightButton; |
253 if ((style & DWT.PUSH) !is 0) { | 253 if ((style & SWT.PUSH) !is 0) { |
254 if ((style & DWT.FLAT) !is 0) { | 254 if ((style & SWT.FLAT) !is 0) { |
255 widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle); | 255 widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle); |
256 // if ((style & DWT.BORDER) is 0) widget.setShowsBorderOnlyWhileMouseInside(true); | 256 // if ((style & SWT.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 & DWT.CHECK) !is 0) { | 260 } else if ((style & SWT.CHECK) !is 0) { |
261 type = NSSwitchButton; | 261 type = OS.NSSwitchButton; |
262 widget.setAllowsMixedState (true); | 262 widget.setAllowsMixedState (true); |
263 } else if ((style & DWT.RADIO) !is 0) { | 263 } else if ((style & SWT.RADIO) !is 0) { |
264 type = NSRadioButton; | 264 type = OS.NSRadioButton; |
265 } else if ((style & DWT.TOGGLE) !is 0) { | 265 } else if ((style & SWT.TOGGLE) !is 0) { |
266 type = NSPushOnPushOffButton; | 266 type = OS.NSPushOnPushOffButton; |
267 widget.setBezelStyle(NSRegularSquareBezelStyle); | 267 if ((style & SWT.FLAT) !is 0) { |
268 widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle); | 268 widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle); |
269 // if ((style & DWT.BORDER) is 0) widget.setShowsBorderOnlyWhileMouseInside(true); | 269 // if ((style & SWT.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 & DWT.ARROW) !is 0) { | 273 } else if ((style & SWT.ARROW) !is 0) { |
274 widget.setBezelStyle(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(NSImageLeft); | 278 widget.setImagePosition(OS.NSImageLeft); |
279 widget.setTarget(widget); | 279 widget.setTarget(widget); |
280 widget.setAction(OS.sel_sendSelection); | 280 widget.setAction(OS.sel_sendSelection); |
281 view = widget; | 281 view = widget; |
282 _setAlignment(style); | 282 _setAlignment(style); |
283 } | 283 } |
284 | 284 |
285 void deregister () { | 285 void deregister () { |
286 super.deregister (); | 286 super.deregister (); |
287 display.removeWidget(((NSControl)view).cell()); | 287 display.removeWidget((cast(NSControl)view).cell()); |
288 } | 288 } |
289 | 289 |
290 void drawWidget (int /*long*/ id, NSRect rect) { | 290 void drawWidget (objc.id id, NSRect rect) { |
291 if ((style & DWT.ARROW) !is 0) { | 291 if ((style & DWT.ARROW) !is 0) { |
292 NSRect frame = view.frame(); | 292 NSRect frame = view.frame(); |
293 int arrowSize = Math.min((int)frame.height, (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 = (float)Math.floor(-arrowSize / 2); | 297 p1.x = cast(CGFloat)Math.floor(-arrowSize / 2); |
298 p1.y = (float)Math.floor(-arrowSize / 2); | 298 p1.y = cast(CGFloat)Math.floor(-arrowSize / 2); |
299 NSPoint p2 = NSPoint(); | 299 NSPoint p2 = NSPoint(); |
300 p2.x = (float)Math.ceil(arrowSize / 2); | 300 p2.x = cast(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 = (float)Math.ceil(arrowSize / 2); | 303 p3.y = cast(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); |
440 return text; | 440 return text; |
441 } | 441 } |
442 | 442 |
443 void register() { | 443 void register() { |
444 super.register(); | 444 super.register(); |
445 display.addWidget(((NSControl)view).cell(), this); | 445 display.addWidget((cast(NSControl)view).cell(), this); |
446 } | 446 } |
447 | 447 |
448 void releaseWidget () { | 448 void releaseWidget () { |
449 super.releaseWidget (); | 449 super.releaseWidget (); |
450 image = null; | 450 image = null; |
608 // window.setDefaultButtonCell(cell); | 608 // window.setDefaultButtonCell(cell); |
609 } | 609 } |
610 | 610 |
611 void setFont (NSFont font) { | 611 void setFont (NSFont font) { |
612 if (text !is null) { | 612 if (text !is null) { |
613 ((NSButton)view).setAttributedTitle(createString()); | 613 (cast(NSButton)view).setAttributedTitle(createString()); |
614 } | 614 } |
615 } | 615 } |
616 | 616 |
617 void setForeground (float [] color) { | 617 void setForeground (float [] color) { |
618 (cast(NSButton)view).setAttributedTitle(createString()); | 618 (cast(NSButton)view).setAttributedTitle(createString()); |