diff dstep/appkit/NSMenu.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents
children b9de51448c6b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstep/appkit/NSMenu.d	Sun Jan 03 22:06:11 2010 +0100
@@ -0,0 +1,480 @@
+/**
+ * Copyright: Copyright (c) 2009 Jacob Carlborg.
+ * Authors: Jacob Carlborg
+ * Version: Initial created: Sep 24, 2009 
+ * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
+ */
+module dstep.appkit.NSMenu;
+
+import dstep.appkit.AppKitDefines;
+import dstep.appkit.NSEvent;
+import dstep.appkit.NSFont;
+import dstep.appkit.NSMenuItem;
+import dstep.appkit.NSView;
+import dstep.applicationservices.coregraphics.CGBase;
+import dstep.foundation.NSArray;
+import dstep.foundation.NSCoder;
+import dstep.foundation.NSGeometry;
+import dstep.foundation.NSObjCRuntime;
+import dstep.foundation.NSObject;
+import dstep.foundation.NSString;
+import dstep.foundation.NSZone;
+import dstep.objc.bridge.Bridge;
+import dstep.objc.objc;
+
+import bindings = dstep.appkit.NSMenu_bindings;
+
+private
+{
+	NSString NSMenuWillSendActionNotification_;
+	NSString NSMenuDidSendActionNotification_;
+	NSString NSMenuDidAddItemNotification_;
+	NSString NSMenuDidRemoveItemNotification_;
+	NSString NSMenuDidChangeItemNotification_;
+	NSString NSMenuDidBeginTrackingNotification_;
+	NSString NSMenuDidEndTrackingNotification_;
+}
+
+NSString NSMenuWillSendActionNotification ()
+{
+	if (NSMenuWillSendActionNotification_)
+		return NSMenuWillSendActionNotification_;
+
+	return NSMenuWillSendActionNotification_ = new NSString(bindings.NSMenuWillSendActionNotification);
+}
+
+NSString NSMenuDidSendActionNotification ()
+{
+	if (NSMenuDidSendActionNotification_)
+		return NSMenuDidSendActionNotification_;
+
+	return NSMenuDidSendActionNotification_ = new NSString(bindings.NSMenuDidSendActionNotification);
+}
+
+NSString NSMenuDidAddItemNotification ()
+{
+	if (NSMenuDidAddItemNotification_)
+		return NSMenuDidAddItemNotification_;
+
+	return NSMenuDidAddItemNotification_ = new NSString(bindings.NSMenuDidAddItemNotification);
+}
+
+NSString NSMenuDidRemoveItemNotification ()
+{
+	if (NSMenuDidRemoveItemNotification_)
+		return NSMenuDidRemoveItemNotification_;
+
+	return NSMenuDidRemoveItemNotification_ = new NSString(bindings.NSMenuDidRemoveItemNotification);
+}
+
+NSString NSMenuDidChangeItemNotification ()
+{
+	if (NSMenuDidChangeItemNotification_)
+		return NSMenuDidChangeItemNotification_;
+
+	return NSMenuDidChangeItemNotification_ = new NSString(bindings.NSMenuDidChangeItemNotification);
+}
+
+NSString NSMenuDidBeginTrackingNotification ()
+{
+	if (NSMenuDidBeginTrackingNotification_)
+		return NSMenuDidBeginTrackingNotification_;
+
+	return NSMenuDidBeginTrackingNotification_ = new NSString(bindings.NSMenuDidBeginTrackingNotification);
+}
+
+NSString NSMenuDidEndTrackingNotification ()
+{
+	if (NSMenuDidEndTrackingNotification_)
+		return NSMenuDidEndTrackingNotification_;
+
+	return NSMenuDidEndTrackingNotification_ = new NSString(bindings.NSMenuDidEndTrackingNotification);
+}
+
+const TNSMenuDelegate = `
+
+	void menuNeedsUpdate (NSMenu menu)
+	{
+		return invokeObjcSelf!(void, "menuNeedsUpdate:", NSMenu)(menu);
+	}
+
+	NSInteger numberOfItemsInMenu (NSMenu menu)
+	{
+		return invokeObjcSelf!(NSInteger, "numberOfItemsInMenu:", NSMenu)(menu);
+	}
+
+	bool menu (NSMenu menu, NSMenuItem item, NSInteger index, bool shouldCancel)
+	{
+		return invokeObjcSelf!(bool, "menu:updateItem:atIndex:shouldCancel:", NSMenu, NSMenuItem, NSInteger, bool)(menu, item, index, shouldCancel);
+	}
+
+	bool menuHasKeyEquivalent (NSMenu menu, NSEvent event, id* target, SEL* action)
+	{
+		return invokeObjcSelf!(bool, "menuHasKeyEquivalent:forEvent:target:action:", NSMenu, NSEvent, id*, SEL*)(menu, event, target, action);
+	}
+
+	void menuWillOpen (NSMenu menu)
+	{
+		return invokeObjcSelf!(void, "menuWillOpen:", NSMenu)(menu);
+	}
+
+	void menuDidClose (NSMenu menu)
+	{
+		return invokeObjcSelf!(void, "menuDidClose:", NSMenu)(menu);
+	}
+
+	void menu (NSMenu menu, NSMenuItem item)
+	{
+		return invokeObjcSelf!(void, "menu:willHighlightItem:", NSMenu, NSMenuItem)(menu, item);
+	}
+
+	//mixin ObjcBindMethod!(menuNeedsUpdate, "menuNeedsUpdate:");
+	//mixin ObjcBindMethod!(numberOfItemsInMenu, "numberOfItemsInMenu:");
+	//mixin ObjcBindMethod!(menu, "menu:updateItem:atIndex:shouldCancel:");
+	//mixin ObjcBindMethod!(menuHasKeyEquivalent, "menuHasKeyEquivalent:forEvent:target:action:");
+	//mixin ObjcBindMethod!(menuWillOpen, "menuWillOpen:");
+	//mixin ObjcBindMethod!(menuDidClose, "menuDidClose:");
+	//mixin ObjcBindMethod!(menu, "menu:willHighlightItem:");
+
+`;
+
+const TNSSubmenuAction = `
+
+	void submenuAction (Object sender)
+	{
+		return invokeObjcSelf!(void, "submenuAction:", Object)(sender);
+	}
+
+	//mixin ObjcBindMethod!(submenuAction, "submenuAction:");
+
+`;
+
+const TNSMenuValidation = `
+
+	bool validateMenuItem (NSMenuItem menuItem)
+	{
+		return invokeObjcSelf!(bool, "validateMenuItem:", NSMenuItem)(menuItem);
+	}
+
+	//mixin ObjcBindMethod!(validateMenuItem, "validateMenuItem:");
+
+`;
+
+class NSMenu : NSObject, INSCopying, INSCoding
+{
+	mixin (ObjcWrap);
+	
+	this (NSCoder aDecoder)
+	{
+		super(typeof(this).alloc.initWithCoder(aDecoder).objcObject);
+	}
+	
+	void encodeWithCoder (NSCoder aCoder)
+	{
+		return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
+	}
+	
+	typeof(this) initWithCoder (NSCoder aDecoder)
+	{
+		return invokeObjcSelf!(typeof(this), "initWithCoder:", NSCoder)(aDecoder);
+	}
+	
+	typeof(this) copyWithZone (NSZone* zone)
+	{
+		return invokeObjcSelf!(typeof(this), "copyWithZone:", NSZone*)(zone);
+	}
+
+	static void setMenuZone (NSZone* aZone)
+	{
+		return invokeObjcSelfClass!(void, "setMenuZone:", NSZone*)(aZone);
+	}
+
+	static NSZone* menuZone ()
+	{
+		return invokeObjcSelfClass!(NSZone*, "menuZone");
+	}
+
+	static void popUpContextMenu (NSMenu menu, NSEvent event, NSView view)
+	{
+		return invokeObjcSelfClass!(void, "popUpContextMenu:withEvent:forView:", NSMenu, NSEvent, NSView)(menu, event, view);
+	}
+
+	static void popUpContextMenu (NSMenu menu, NSEvent event, NSView view, NSFont font)
+	{
+		return invokeObjcSelfClass!(void, "popUpContextMenu:withEvent:forView:withFont:", NSMenu, NSEvent, NSView, NSFont)(menu, event, view, font);
+	}
+
+	static void setMenuBarVisible (bool visible)
+	{
+		return invokeObjcSelfClass!(void, "setMenuBarVisible:", bool)(visible);
+	}
+
+	static bool menuBarVisible ()
+	{
+		return invokeObjcSelfClass!(bool, "menuBarVisible");
+	}
+
+	NSMenu initWithTitle (NSString aTitle)
+	{
+		id result = invokeObjcSelf!(id, "initWithTitle:", NSString)(aTitle);
+		return result is this.objcObject ? this : (result !is null ? new NSMenu(result) : null);
+	}
+
+	this (NSString aTitle)
+	{
+		super(NSMenu.alloc.initWithTitle(aTitle).objcObject);
+	}
+
+	void setTitle (NSString aString)
+	{
+		return invokeObjcSelf!(void, "setTitle:", NSString)(aString);
+	}
+
+	NSString title ()
+	{
+		return invokeObjcSelf!(NSString, "title");
+	}
+
+	void setSupermenu (NSMenu supermenu)
+	{
+		return invokeObjcSelf!(void, "setSupermenu:", NSMenu)(supermenu);
+	}
+
+	NSMenu supermenu ()
+	{
+		id result = invokeObjcSelf!(id, "supermenu");
+		return result is this.objcObject ? this : (result !is null ? new NSMenu(result) : null);
+	}
+
+	void insertItem (NSMenuItem newItem, NSInteger index)
+	{
+		return invokeObjcSelf!(void, "insertItem:atIndex:", NSMenuItem, NSInteger)(newItem, index);
+	}
+
+	void addItem (NSMenuItem newItem)
+	{
+		return invokeObjcSelf!(void, "addItem:", NSMenuItem)(newItem);
+	}
+
+	NSMenuItem insertItemWithTitle (NSString aString, SEL aSelector, NSString charCode, NSInteger index)
+	{
+		return invokeObjcSelf!(NSMenuItem, "insertItemWithTitle:action:keyEquivalent:atIndex:", NSString, SEL, NSString, NSInteger)(aString, aSelector, charCode, index);
+	}
+
+	NSMenuItem addItemWithTitle (NSString aString, SEL aSelector, NSString charCode)
+	{
+		return invokeObjcSelf!(NSMenuItem, "addItemWithTitle:action:keyEquivalent:", NSString, SEL, NSString)(aString, aSelector, charCode);
+	}
+
+	void removeItemAtIndex (NSInteger index)
+	{
+		return invokeObjcSelf!(void, "removeItemAtIndex:", NSInteger)(index);
+	}
+
+	void removeItem (NSMenuItem item)
+	{
+		return invokeObjcSelf!(void, "removeItem:", NSMenuItem)(item);
+	}
+
+	void setSubmenu (NSMenu aMenu, NSMenuItem anItem)
+	{
+		return invokeObjcSelf!(void, "setSubmenu:forItem:", NSMenu, NSMenuItem)(aMenu, anItem);
+	}
+
+	NSArray itemArray ()
+	{
+		return invokeObjcSelf!(NSArray, "itemArray");
+	}
+
+	NSInteger numberOfItems ()
+	{
+		return invokeObjcSelf!(NSInteger, "numberOfItems");
+	}
+
+	NSInteger indexOfItem (NSMenuItem index)
+	{
+		return invokeObjcSelf!(NSInteger, "indexOfItem:", NSMenuItem)(index);
+	}
+
+	NSInteger indexOfItemWithTitle (NSString aTitle)
+	{
+		return invokeObjcSelf!(NSInteger, "indexOfItemWithTitle:", NSString)(aTitle);
+	}
+
+	NSInteger indexOfItemWithTag (NSInteger aTag)
+	{
+		return invokeObjcSelf!(NSInteger, "indexOfItemWithTag:", NSInteger)(aTag);
+	}
+
+	NSInteger indexOfItemWithRepresentedObject (Object object)
+	{
+		return invokeObjcSelf!(NSInteger, "indexOfItemWithRepresentedObject:", Object)(object);
+	}
+
+	NSInteger indexOfItemWithSubmenu (NSMenu submenu)
+	{
+		return invokeObjcSelf!(NSInteger, "indexOfItemWithSubmenu:", NSMenu)(submenu);
+	}
+
+	NSInteger indexOfItemWithTarget (Object target, SEL actionSelector)
+	{
+		return invokeObjcSelf!(NSInteger, "indexOfItemWithTarget:andAction:", Object, SEL)(target, actionSelector);
+	}
+
+	NSMenuItem itemAtIndex (NSInteger index)
+	{
+		return invokeObjcSelf!(NSMenuItem, "itemAtIndex:", NSInteger)(index);
+	}
+
+	NSMenuItem itemWithTitle (NSString aTitle)
+	{
+		return invokeObjcSelf!(NSMenuItem, "itemWithTitle:", NSString)(aTitle);
+	}
+
+	NSMenuItem itemWithTag (NSInteger tag)
+	{
+		return invokeObjcSelf!(NSMenuItem, "itemWithTag:", NSInteger)(tag);
+	}
+
+	void setAutoenablesItems (bool flag)
+	{
+		return invokeObjcSelf!(void, "setAutoenablesItems:", bool)(flag);
+	}
+
+	bool autoenablesItems ()
+	{
+		return invokeObjcSelf!(bool, "autoenablesItems");
+	}
+
+	bool performKeyEquivalent (NSEvent theEvent)
+	{
+		return invokeObjcSelf!(bool, "performKeyEquivalent:", NSEvent)(theEvent);
+	}
+
+	void update ()
+	{
+		return invokeObjcSelf!(void, "update");
+	}
+
+	void setMenuChangedMessagesEnabled (bool flag)
+	{
+		return invokeObjcSelf!(void, "setMenuChangedMessagesEnabled:", bool)(flag);
+	}
+
+	bool menuChangedMessagesEnabled ()
+	{
+		return invokeObjcSelf!(bool, "menuChangedMessagesEnabled");
+	}
+
+	void itemChanged (NSMenuItem item)
+	{
+		return invokeObjcSelf!(void, "itemChanged:", NSMenuItem)(item);
+	}
+
+	void helpRequested (NSEvent eventPtr)
+	{
+		return invokeObjcSelf!(void, "helpRequested:", NSEvent)(eventPtr);
+	}
+
+	void setMenuRepresentation (Object menuRep)
+	{
+		return invokeObjcSelf!(void, "setMenuRepresentation:", Object)(menuRep);
+	}
+
+	Object menuRepresentation ()
+	{
+		return invokeObjcSelf!(Object, "menuRepresentation");
+	}
+
+	void setContextMenuRepresentation (Object menuRep)
+	{
+		return invokeObjcSelf!(void, "setContextMenuRepresentation:", Object)(menuRep);
+	}
+
+	Object contextMenuRepresentation ()
+	{
+		return invokeObjcSelf!(Object, "contextMenuRepresentation");
+	}
+
+	void setTearOffMenuRepresentation (Object menuRep)
+	{
+		return invokeObjcSelf!(void, "setTearOffMenuRepresentation:", Object)(menuRep);
+	}
+
+	Object tearOffMenuRepresentation ()
+	{
+		return invokeObjcSelf!(Object, "tearOffMenuRepresentation");
+	}
+
+	bool isTornOff ()
+	{
+		return invokeObjcSelf!(bool, "isTornOff");
+	}
+
+	NSMenu attachedMenu ()
+	{
+		id result = invokeObjcSelf!(id, "attachedMenu");
+		return result is this.objcObject ? this : (result !is null ? new NSMenu(result) : null);
+	}
+
+	bool isAttached ()
+	{
+		return invokeObjcSelf!(bool, "isAttached");
+	}
+
+	void sizeToFit ()
+	{
+		return invokeObjcSelf!(void, "sizeToFit");
+	}
+
+	NSPoint locationForSubmenu (NSMenu aSubmenu)
+	{
+		return invokeObjcSelf!(NSPoint, "locationForSubmenu:", NSMenu)(aSubmenu);
+	}
+
+	void performActionForItemAtIndex (NSInteger index)
+	{
+		return invokeObjcSelf!(void, "performActionForItemAtIndex:", NSInteger)(index);
+	}
+
+	void setDelegate (Object anObject)
+	{
+		return invokeObjcSelf!(void, "setDelegate:", Object)(anObject);
+	}
+
+	Object delegate_ ()
+	{
+		return invokeObjcSelf!(Object, "delegate");
+	}
+
+	CGFloat menuBarHeight ()
+	{
+		return invokeObjcSelf!(CGFloat, "menuBarHeight");
+	}
+
+	void cancelTracking ()
+	{
+		return invokeObjcSelf!(void, "cancelTracking");
+	}
+
+	NSMenuItem highlightedItem ()
+	{
+		return invokeObjcSelf!(NSMenuItem, "highlightedItem");
+	}
+
+	void setShowsStateColumn (bool showsState)
+	{
+		return invokeObjcSelf!(void, "setShowsStateColumn:", bool)(showsState);
+	}
+
+	bool showsStateColumn ()
+	{
+		return invokeObjcSelf!(bool, "showsStateColumn");
+	}
+
+	// NSSubmenuAction
+	void submenuAction (Object sender)
+	{
+		return invokeObjcSelf!(void, "submenuAction:", Object)(sender);
+	}
+}
\ No newline at end of file