Mercurial > projects > dwt-mac
comparison dwt/widgets/Button.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 1a8b3cb347e0 |
children | dfcc6c4c4317 |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
164 } else if ((style & DWT.LEFT) !is 0) { | 164 } else if ((style & DWT.LEFT) !is 0) { |
165 alignment = OS.NSLeftTextAlignment; | 165 alignment = OS.NSLeftTextAlignment; |
166 } else { | 166 } else { |
167 alignment = OS.NSRightTextAlignment; | 167 alignment = OS.NSRightTextAlignment; |
168 } | 168 } |
169 NSMutableParagraphStyle pStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init(); | 169 NSMutableParagraphStyle pStyle = cast(NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init(); |
170 pStyle.autorelease(); | 170 pStyle.autorelease(); |
171 pStyle.setAlignment(alignment); | 171 pStyle.setAlignment(alignment); |
172 dict.setObject(pStyle, OS.NSParagraphStyleAttributeName()); | 172 dict.setObject(pStyle, OS.NSParagraphStyleAttributeName()); |
173 char [] chars = new char [text.length ()]; | 173 char [] chars = new char [text.length ()]; |
174 text.getChars (0, chars.length, chars, 0); | 174 text.getChars (0, chars.length, chars, 0); |
175 int length = fixMnemonic (chars); | 175 int length = fixMnemonic (chars); |
176 NSString str = NSString.stringWithCharacters(chars, length); | 176 NSString str = NSString.stringWithCharacters(chars, length); |
177 NSAttributedString attribStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict); | 177 NSAttributedString attribStr = (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict); |
178 attribStr.autorelease(); | 178 attribStr.autorelease(); |
179 return attribStr; | 179 return attribStr; |
180 } | 180 } |
181 | 181 |
182 void createHandle () { | 182 void createHandle () { |
183 NSButton widget = (NSButton)new SWTButton().alloc(); | 183 NSButton widget = cast(NSButton)new SWTButton().alloc(); |
184 widget.initWithFrame(new NSRect()); | 184 widget.initWithFrame(new NSRect()); |
185 int type = OS.NSMomentaryPushButton; | 185 int type = OS.NSMomentaryPushButton; |
186 if ((style & DWT.PUSH) !is 0) { | 186 if ((style & DWT.PUSH) !is 0) { |
187 widget.setBezelStyle(OS.NSRoundedBezelStyle); | 187 widget.setBezelStyle(OS.NSRoundedBezelStyle); |
188 } else if ((style & DWT.CHECK) !is 0) { | 188 } else if ((style & DWT.CHECK) !is 0) { |
281 * </ul> | 281 * </ul> |
282 */ | 282 */ |
283 public bool getSelection () { | 283 public bool getSelection () { |
284 checkWidget (); | 284 checkWidget (); |
285 if ((style & (DWT.CHECK | DWT.RADIO | DWT.TOGGLE)) is 0) return false; | 285 if ((style & (DWT.CHECK | DWT.RADIO | DWT.TOGGLE)) is 0) return false; |
286 if ((style & DWT.CHECK) !is 0 && grayed) return ((NSButton)view).state() is OS.NSMixedState; | 286 if ((style & DWT.CHECK) !is 0 && grayed) return (cast(NSButton)view).state() is OS.NSMixedState; |
287 return ((NSButton)view).state() is OS.NSOnState; | 287 return (cast(NSButton)view).state() is OS.NSOnState; |
288 } | 288 } |
289 | 289 |
290 /** | 290 /** |
291 * Returns the receiver's text, which will be an empty | 291 * Returns the receiver's text, which will be an empty |
292 * string if it has never been set or if the receiver is | 292 * string if it has never been set or if the receiver is |
365 if ((parent.getStyle () & DWT.NO_RADIO_GROUP) is 0) { | 365 if ((parent.getStyle () & DWT.NO_RADIO_GROUP) is 0) { |
366 selectRadio (); | 366 selectRadio (); |
367 } | 367 } |
368 } | 368 } |
369 if ((style & DWT.CHECK) !is 0) { | 369 if ((style & DWT.CHECK) !is 0) { |
370 if (grayed && ((NSButton)view).state() is OS.NSOnState) { | 370 if (grayed && (cast(NSButton)view).state() is OS.NSOnState) { |
371 ((NSButton)view).setState(OS.NSOffState); | 371 (cast(NSButton)view).setState(OS.NSOffState); |
372 } | 372 } |
373 if (!grayed && ((NSButton)view).state() is OS.NSMixedState) { | 373 if (!grayed && (cast(NSButton)view).state() is OS.NSMixedState) { |
374 ((NSButton)view).setState(OS.NSOnState); | 374 (cast(NSButton)view).setState(OS.NSOnState); |
375 } | 375 } |
376 } | 376 } |
377 postEvent (DWT.Selection); | 377 postEvent (DWT.Selection); |
378 } | 378 } |
379 | 379 |
415 if ((alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER)) is 0) return; | 415 if ((alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER)) is 0) return; |
416 style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); | 416 style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); |
417 style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER); | 417 style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER); |
418 /* text is still null when this is called from createHandle() */ | 418 /* text is still null when this is called from createHandle() */ |
419 if (text !is null) { | 419 if (text !is null) { |
420 ((NSButton)view).setAttributedTitle(createString()); | 420 (cast(NSButton)view).setAttributedTitle(createString()); |
421 } | 421 } |
422 // /* Alignment not honoured when image and text is visible */ | 422 // /* Alignment not honoured when image and text is visible */ |
423 // bool bothVisible = text !is null && text.length () > 0 && image !is null; | 423 // bool bothVisible = text !is null && text.length () > 0 && image !is null; |
424 // if (bothVisible) { | 424 // if (bothVisible) { |
425 // if ((style & (DWT.RADIO | DWT.CHECK)) !is 0) alignment = DWT.LEFT; | 425 // if ((style & (DWT.RADIO | DWT.CHECK)) !is 0) alignment = DWT.LEFT; |
437 // } | 437 // } |
438 // if ((alignment & DWT.RIGHT) !is 0) { | 438 // if ((alignment & DWT.RIGHT) !is 0) { |
439 // textAlignment = OS.kControlBevelButtonAlignTextFlushRight; | 439 // textAlignment = OS.kControlBevelButtonAlignTextFlushRight; |
440 // graphicAlignment = OS.kControlBevelButtonAlignRight; | 440 // graphicAlignment = OS.kControlBevelButtonAlignRight; |
441 // } | 441 // } |
442 // OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonTextAlignTag, 2, new short [] {(short)textAlignment}); | 442 // OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonTextAlignTag, 2, new short [] {cast(short)textAlignment}); |
443 // OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonGraphicAlignTag, 2, new short [] {(short)graphicAlignment}); | 443 // OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonGraphicAlignTag, 2, new short [] {cast(short)graphicAlignment}); |
444 // if (bothVisible) { | 444 // if (bothVisible) { |
445 // OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonTextPlaceTag, 2, new short [] {(short)OS.kControlBevelButtonPlaceToRightOfGraphic}); | 445 // OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonTextPlaceTag, 2, new short [] {cast(short)OS.kControlBevelButtonPlaceToRightOfGraphic}); |
446 // } | 446 // } |
447 } | 447 } |
448 | 448 |
449 void setBackground (float [] color) { | 449 void setBackground (float [] color) { |
450 NSColor nsColor; | 450 NSColor nsColor; |
451 if (color is null) { | 451 if (color is null) { |
452 return; // TODO set to OS default | 452 return; // TODO set to OS default |
453 } else { | 453 } else { |
454 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); | 454 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); |
455 } | 455 } |
456 NSButtonCell cell = new NSButtonCell(((NSButton)view).cell()); | 456 NSButtonCell cell = new NSButtonCell((cast(NSButton)view).cell()); |
457 cell.setBackgroundColor(nsColor); | 457 cell.setBackgroundColor(nsColor); |
458 } | 458 } |
459 | 459 |
460 void setDefault (bool value) { | 460 void setDefault (bool value) { |
461 if ((style & DWT.PUSH) is 0) return; | 461 if ((style & DWT.PUSH) is 0) return; |
462 // int window = OS.GetControlOwner (handle); | 462 // int window = OS.GetControlOwner (handle); |
463 // OS.SetWindowDefaultButton (window, value ? handle : 0); | 463 // OS.SetWindowDefaultButton (window, value ? handle : 0); |
464 } | 464 } |
465 | 465 |
466 void setForeground (float [] color) { | 466 void setForeground (float [] color) { |
467 ((NSButton)view).setAttributedTitle(createString()); | 467 (cast(NSButton)view).setAttributedTitle(createString()); |
468 } | 468 } |
469 | 469 |
470 public void setGrayed(bool grayed) { | 470 public void setGrayed(bool grayed) { |
471 checkWidget (); | 471 checkWidget (); |
472 if ((style & DWT.CHECK) is 0) return; | 472 if ((style & DWT.CHECK) is 0) return; |
473 bool checked = getSelection (); | 473 bool checked = getSelection (); |
474 this.grayed = grayed; | 474 this.grayed = grayed; |
475 if (checked) { | 475 if (checked) { |
476 if (grayed) { | 476 if (grayed) { |
477 ((NSButton) view).setState (OS.NSMixedState); | 477 (cast(NSButton) view).setState (OS.NSMixedState); |
478 } else { | 478 } else { |
479 ((NSButton) view).setState (OS.NSOnState); | 479 (cast(NSButton) view).setState (OS.NSOnState); |
480 } | 480 } |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 /** | 484 /** |
505 if ((style & DWT.ARROW) !is 0) return; | 505 if ((style & DWT.ARROW) !is 0) return; |
506 if (image !is null && image.isDisposed ()) { | 506 if (image !is null && image.isDisposed ()) { |
507 error (DWT.ERROR_INVALID_ARGUMENT); | 507 error (DWT.ERROR_INVALID_ARGUMENT); |
508 } | 508 } |
509 this.image = image; | 509 this.image = image; |
510 ((NSButton)view).setImage(image.handle); | 510 (cast(NSButton)view).setImage(image.handle); |
511 } | 511 } |
512 | 512 |
513 bool setRadioSelection (bool value){ | 513 bool setRadioSelection (bool value){ |
514 if ((style & DWT.RADIO) is 0) return false; | 514 if ((style & DWT.RADIO) is 0) return false; |
515 if (getSelection () !is value) { | 515 if (getSelection () !is value) { |
537 */ | 537 */ |
538 public void setSelection (bool selected) { | 538 public void setSelection (bool selected) { |
539 checkWidget(); | 539 checkWidget(); |
540 if ((style & (DWT.CHECK | DWT.RADIO | DWT.TOGGLE)) is 0) return; | 540 if ((style & (DWT.CHECK | DWT.RADIO | DWT.TOGGLE)) is 0) return; |
541 if (grayed) { | 541 if (grayed) { |
542 ((NSButton)view).setState (selected ? OS.NSMixedState : OS.NSOffState); | 542 (cast(NSButton)view).setState (selected ? OS.NSMixedState : OS.NSOffState); |
543 } else { | 543 } else { |
544 ((NSButton)view).setState (selected ? OS.NSOnState : OS.NSOffState); | 544 (cast(NSButton)view).setState (selected ? OS.NSOnState : OS.NSOffState); |
545 } | 545 } |
546 } | 546 } |
547 | 547 |
548 /** | 548 /** |
549 * Sets the receiver's text. | 549 * Sets the receiver's text. |
579 public void setText (String string) { | 579 public void setText (String string) { |
580 checkWidget(); | 580 checkWidget(); |
581 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 581 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
582 if ((style & DWT.ARROW) !is 0) return; | 582 if ((style & DWT.ARROW) !is 0) return; |
583 text = string; | 583 text = string; |
584 ((NSButton)view).setAttributedTitle(createString()); | 584 (cast(NSButton)view).setAttributedTitle(createString()); |
585 } | 585 } |
586 | 586 |
587 int traversalCode (int key, NSEvent theEvent) { | 587 int traversalCode (int key, NSEvent theEvent) { |
588 int code = super.traversalCode (key, theEvent); | 588 int code = super.traversalCode (key, theEvent); |
589 if ((style & DWT.RADIO) !is 0) code |= DWT.TRAVERSE_ARROW_NEXT | DWT.TRAVERSE_ARROW_PREVIOUS; | 589 if ((style & DWT.RADIO) !is 0) code |= DWT.TRAVERSE_ARROW_NEXT | DWT.TRAVERSE_ARROW_PREVIOUS; |