comparison dwt/widgets/MenuItem.d @ 35:7d135fe0caf2

Ported dwt.graphics.Cursor and dwt.widgets.MenuItem
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sun, 14 Sep 2008 23:32:29 +0200
parents e831403a80a9
children 642f460a0908
comparison
equal deleted inserted replaced
34:5123b17c98ef 35:7d135fe0caf2
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.MenuItem; 14 module dwt.widgets.MenuItem;
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.ArmListener; 19 import dwt.events.ArmListener;
24 import dwt.internal.cocoa.NSMenuItem; 25 import dwt.internal.cocoa.NSMenuItem;
25 import dwt.internal.cocoa.NSString; 26 import dwt.internal.cocoa.NSString;
26 import dwt.internal.cocoa.OS; 27 import dwt.internal.cocoa.OS;
27 import dwt.internal.cocoa.SWTMenu; 28 import dwt.internal.cocoa.SWTMenu;
28 29
30 import dwt.dwthelper.utils;
31 import dwt.internal.cocoa.NSInteger;
32 import dwt.widgets.Decorations;
33 import dwt.widgets.Display;
34 import dwt.widgets.Event;
35 import dwt.widgets.Item;
36 import dwt.widgets.Menu;
37 import dwt.widgets.TypedListener;
38
29 /** 39 /**
30 * Instances of this class represent a selectable user interface object 40 * Instances of this class represent a selectable user interface object
31 * that issues notification when pressed and released. 41 * that issues notification when pressed and released.
32 * <dl> 42 * <dl>
33 * <dt><b>Styles:</b></dt> 43 * <dt><b>Styles:</b></dt>
222 return checkBits (style, DWT.PUSH, DWT.CHECK, DWT.RADIO, DWT.SEPARATOR, DWT.CASCADE, 0); 232 return checkBits (style, DWT.PUSH, DWT.CHECK, DWT.RADIO, DWT.SEPARATOR, DWT.CASCADE, 0);
223 } 233 }
224 234
225 NSMenu createEmptyMenu () { 235 NSMenu createEmptyMenu () {
226 if ((parent.style & DWT.BAR) !is 0) { 236 if ((parent.style & DWT.BAR) !is 0) {
227 return cast(NSMenu) new SWTMenu ().alloc ().init (); 237 return cast(NSMenu) (new SWTMenu ()).alloc ().init ();
228 } 238 }
229 return null; 239 return null;
230 } 240 }
231 241
232 void destroyWidget () { 242 void destroyWidget () {
553 public void setAccelerator (int accelerator) { 563 public void setAccelerator (int accelerator) {
554 checkWidget (); 564 checkWidget ();
555 this.accelerator = accelerator; 565 this.accelerator = accelerator;
556 int key = accelerator & DWT.KEY_MASK; 566 int key = accelerator & DWT.KEY_MASK;
557 int virtualKey = Display.untranslateKey (key); 567 int virtualKey = Display.untranslateKey (key);
558 NSString string = null; 568 NSString str = null;
559 if (virtualKey !is 0) { 569 if (virtualKey !is 0) {
560 string = NSString.stringWith (cast(wchar)virtualKey + ""); 570 str = NSString.stringWith (Integer.toString(virtualKey));
561 } else { 571 } else {
562 string = NSString.stringWith (cast(wchar)key + "").lowercaseString(); 572 str = NSString.stringWith (Integer.toString(key)).lowercaseString();
563 } 573 }
564 nsItem.setKeyEquivalent (string); 574 nsItem.setKeyEquivalent (string);
565 int mask = 0; 575 int mask = 0;
566 if ((accelerator & DWT.SHIFT) !is 0) mask |= OS.NSShiftKeyMask; 576 if ((accelerator & DWT.SHIFT) !is 0) mask |= OS.NSShiftKeyMask;
567 if ((accelerator & DWT.CONTROL) !is 0) mask |= OS.NSControlKeyMask; 577 if ((accelerator & DWT.CONTROL) !is 0) mask |= OS.NSControlKeyMask;
568 // if ((accelerator & DWT.COMMAND) !is 0) mask &= ~OS.kMenuNoCommandModifier; 578 // if ((accelerator & DWT.COMMAND) !is 0) mask &= ~OS.kMenuNoCommandModifier;
569 if ((accelerator & DWT.COMMAND) !is 0) mask |= OS.NSCommandKeyMask; 579 if ((accelerator & DWT.COMMAND) !is 0) mask |= OS.NSCommandKeyMask;
570 if ((accelerator & DWT.ALT) !is 0) mask |= OS.NSAlternateKeyMask; 580 if ((accelerator & DWT.ALT) !is 0) mask |= OS.NSAlternateKeyMask;
571 nsItem.setKeyEquivalentModifierMask (mask); 581 nsItem.setKeyEquivalentModifierMask (cast(NSUInteger) mask);
572 if ((this.accelerator is 0 && accelerator !is 0) || (this.accelerator !is 0 && accelerator is 0)) { 582 if ((this.accelerator is 0 && accelerator !is 0) || (this.accelerator !is 0 && accelerator is 0)) {
573 updateText (); 583 updateText ();
574 } 584 }
575 } 585 }
576 586
758 if (i is buffer.length) {continue;} 768 if (i is buffer.length) {continue;}
759 if (buffer [i] is '&') {i++; continue;} 769 if (buffer [i] is '&') {i++; continue;}
760 j--; 770 j--;
761 } 771 }
762 } 772 }
763 String text = new String (buffer, 0, j); 773 String text = new_String (buffer, 0, j);
764 NSMenu submenu = nsItem.submenu (); 774 NSMenu submenu = nsItem.submenu ();
765 NSString label = NSString.stringWith (text); 775 NSString label = NSString.stringWith (text);
766 if(submenu !is null && (parent.getStyle () & DWT.BAR) !is 0) { 776 if(submenu !is null && (parent.getStyle () & DWT.BAR) !is 0) {
767 submenu.setTitle (label); 777 submenu.setTitle (label);
768 } else { 778 } else {