view dwt/internal/cocoa/NSMenu.d @ 13:f565d3a95c0a

Ported dwt.internal
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Fri, 22 Aug 2008 16:46:34 +0200
parents 8b48be5454ce
children d8635bb48c7c
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     
 * Port to the D programming language:
 *     Jacob Carlborg <jacob.carlborg@gmail.com>
 *******************************************************************************/
module dwt.internal.cocoa.NSMenu;

import dwt.internal.cocoa.CGFloat;
import dwt.internal.cocoa.id;
import dwt.internal.cocoa.NSArray;
import dwt.internal.cocoa.NSEvent;
import dwt.internal.cocoa.NSFont;
import dwt.internal.cocoa.NSInteger;
import dwt.internal.cocoa.NSMenuItem;
import dwt.internal.cocoa.NSObject;
import dwt.internal.cocoa.NSPoint;
import dwt.internal.cocoa.NSString;
import dwt.internal.cocoa.NSView;
import dwt.internal.cocoa.NSZone;
import dwt.internal.cocoa.OS;
import objc = dwt.internal.objc.runtime;

public class NSMenu : NSObject
{

    public this ()
    {
        super();
    }

    public this (objc.id id)
    {
        super(id);
    }

    public void addItem (NSMenuItem newItem)
    {
        OS.objc_msgSend(this.id_, OS.sel_addItem_1, newItem !is null ? newItem.id_ : null);
    }

    public NSMenuItem addItemWithTitle (NSString aString, objc.SEL aSelector, NSString charCode)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_addItemWithTitle_1action_1keyEquivalent_1, aString !is null ? aString.id_ : null, aSelector,
                charCode !is null ? charCode.id_ : null);
        return result !is null ? new NSMenuItem(result) : null;
    }

    public NSMenu attachedMenu ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_attachedMenu);
        return result is this.id_ ? this : (result !is null ? new NSMenu(result) : null);
    }

    public bool autoenablesItems ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_autoenablesItems) !is null;
    }

    public void cancelTracking ()
    {
        OS.objc_msgSend(this.id_, OS.sel_cancelTracking);
    }

    public id contextMenuRepresentation ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_contextMenuRepresentation);
        return result !is null ? new id(result) : null;
    }

    public id delegatee ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_delegate);
        return result !is null ? new id(result) : null;
    }

    public void helpRequested (NSEvent eventPtr)
    {
        OS.objc_msgSend(this.id_, OS.sel_helpRequested_1, eventPtr !is null ? eventPtr.id_ : null);
    }

    public NSMenuItem highlightedItem ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_highlightedItem);
        return result !is null ? new NSMenuItem(result) : null;
    }

    public NSInteger indexOfItem (NSMenuItem index)
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfItem_1, index !is null ? index.id_ : null);
    }

    public NSInteger indexOfItemWithRepresentedObject (id object)
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfItemWithRepresentedObject_1, object !is null ? object.id_ : null);
    }

    public NSInteger indexOfItemWithSubmenu (NSMenu submenu)
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfItemWithSubmenu_1, submenu !is null ? submenu.id_ : null);
    }

    public NSInteger indexOfItemWithTag (NSInteger aTag)
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfItemWithTag_1, aTag);
    }

    public NSInteger indexOfItemWithTarget (id target, objc.SEL actionSelector)
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfItemWithTarget_1andAction_1, target !is null ? target.id_ : null, actionSelector);
    }

    public NSInteger indexOfItemWithTitle (NSString aTitle)
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfItemWithTitle_1, aTitle !is null ? aTitle.id_ : null);
    }

    public NSMenu initWithTitle (NSString aTitle)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithTitle_1, aTitle !is null ? aTitle.id_ : null);
        return result !is null ? this : null;
    }

    public void insertItem (NSMenuItem newItem, NSInteger index)
    {
        OS.objc_msgSend(this.id_, OS.sel_insertItem_1atIndex_1, newItem !is null ? newItem.id_ : null, index);
    }

    public NSMenuItem insertItemWithTitle (NSString aString, objc.SEL aSelector, NSString charCode, NSInteger index)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_insertItemWithTitle_1action_1keyEquivalent_1atIndex_1, aString !is null ? aString.id_ : null,
                aSelector, charCode !is null ? charCode.id_ : null, index);
        return result !is null ? new NSMenuItem(result) : null;
    }

    public bool isAttached ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isAttached) !is null;
    }

    public bool isTornOff ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isTornOff) !is null;
    }

    public NSArray itemArray ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_itemArray);
        return result !is null ? new NSArray(result) : null;
    }

    public NSMenuItem itemAtIndex (NSInteger index)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_itemAtIndex_1, index);
        return result !is null ? new NSMenuItem(result) : null;
    }

    public void itemChanged (NSMenuItem item)
    {
        OS.objc_msgSend(this.id_, OS.sel_itemChanged_1, item !is null ? item.id_ : null);
    }

    public NSMenuItem itemWithTag (NSInteger tag)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_itemWithTag_1, tag);
        return result !is null ? new NSMenuItem(result) : null;
    }

    public NSMenuItem itemWithTitle (NSString aTitle)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_itemWithTitle_1, aTitle !is null ? aTitle.id_ : null);
        return result !is null ? new NSMenuItem(result) : null;
    }

    public NSPoint locationForSubmenu (NSMenu aSubmenu)
    {
        NSPoint result;
        OS.objc_msgSend_stret(&result, this.id_, OS.sel_locationForSubmenu_1, aSubmenu !is null ? aSubmenu.id_ : null);
        return result;
    }

    public CGFloat menuBarHeight ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_menuBarHeight);
    }

    public static bool menuBarVisible ()
    {
        return OS.objc_msgSend(OS.class_NSMenu, OS.sel_menuBarVisible) !is null;
    }

    public bool menuChangedMessagesEnabled ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_menuChangedMessagesEnabled) !is null;
    }

    public id menuRepresentation ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_menuRepresentation);
        return result !is null ? new id(result) : null;
    }

    public static NSZone* menuZone ()
    {
        return cast(NSZone*) OS.objc_msgSend(OS.class_NSMenu, OS.sel_menuZone);
    }

    public NSInteger numberOfItems ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_numberOfItems);
    }

    public void performActionForItemAtIndex (NSInteger index)
    {
        OS.objc_msgSend(this.id_, OS.sel_performActionForItemAtIndex_1, index);
    }

    public bool performKeyEquivalent (NSEvent theEvent)
    {
        return OS.objc_msgSend(this.id_, OS.sel_performKeyEquivalent_1, theEvent !is null ? theEvent.id_ : null) !is null;
    }

    public static void static_popUpContextMenu_withEvent_forView_ (NSMenu menu, NSEvent event, NSView view)
    {
        OS.objc_msgSend(OS.class_NSMenu, OS.sel_popUpContextMenu_1withEvent_1forView_1, menu !is null ? menu.id_ : null,
                event !is null ? event.id_ : null, view !is null ? view.id_ : null);
    }

    public static void static_popUpContextMenu_withEvent_forView_withFont_ (NSMenu menu, NSEvent event, NSView view, NSFont font)
    {
        OS.objc_msgSend(OS.class_NSMenu, OS.sel_popUpContextMenu_1withEvent_1forView_1withFont_1, menu !is null ? menu.id_ : null,
                event !is null ? event.id_ : null, view !is null ? view.id_ : null, font !is null ? font.id_ : null);
    }

    public void removeItem (NSMenuItem item)
    {
        OS.objc_msgSend(this.id_, OS.sel_removeItem_1, item !is null ? item.id_ : null);
    }

    public void removeItemAtIndex (NSInteger index)
    {
        OS.objc_msgSend(this.id_, OS.sel_removeItemAtIndex_1, index);
    }

    public void setAutoenablesItems (bool flag)
    {
        OS.objc_msgSend(this.id_, OS.sel_setAutoenablesItems_1, flag);
    }

    public void setContextMenuRepresentation (id menuRep)
    {
        OS.objc_msgSend(this.id_, OS.sel_setContextMenuRepresentation_1, menuRep !is null ? menuRep.id_ : null);
    }

    public void setDelegate (id anObject)
    {
        OS.objc_msgSend(this.id_, OS.sel_setDelegate_1, anObject !is null ? anObject.id_ : null);
    }

    public static void setMenuBarVisible (bool visible)
    {
        OS.objc_msgSend(OS.class_NSMenu, OS.sel_setMenuBarVisible_1, visible);
    }

    public void setMenuChangedMessagesEnabled (bool flag)
    {
        OS.objc_msgSend(this.id_, OS.sel_setMenuChangedMessagesEnabled_1, flag);
    }

    public void setMenuRepresentation (id menuRep)
    {
        OS.objc_msgSend(this.id_, OS.sel_setMenuRepresentation_1, menuRep !is null ? menuRep.id_ : null);
    }

    public static void setMenuZone (NSZone* aZone)
    {
        OS.objc_msgSend(OS.class_NSMenu, OS.sel_setMenuZone_1, aZone);
    }

    public void setShowsStateColumn (bool showsState)
    {
        OS.objc_msgSend(this.id_, OS.sel_setShowsStateColumn_1, showsState);
    }

    public void setSubmenu (NSMenu aMenu, NSMenuItem anItem)
    {
        OS.objc_msgSend(this.id_, OS.sel_setSubmenu_1forItem_1, aMenu !is null ? aMenu.id_ : null, anItem !is null ? anItem.id_ : null);
    }

    public void setSupermenu (NSMenu supermenu)
    {
        OS.objc_msgSend(this.id_, OS.sel_setSupermenu_1, supermenu !is null ? supermenu.id_ : null);
    }

    public void setTearOffMenuRepresentation (id menuRep)
    {
        OS.objc_msgSend(this.id_, OS.sel_setTearOffMenuRepresentation_1, menuRep !is null ? menuRep.id_ : null);
    }

    public void setTitle (NSString aString)
    {
        OS.objc_msgSend(this.id_, OS.sel_setTitle_1, aString !is null ? aString.id_ : null);
    }

    public bool showsStateColumn ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_showsStateColumn) !is null;
    }

    public void sizeToFit ()
    {
        OS.objc_msgSend(this.id_, OS.sel_sizeToFit);
    }

    public void submenuAction (id sender)
    {
        OS.objc_msgSend(this.id_, OS.sel_submenuAction_1, sender !is null ? sender.id_ : null);
    }

    public NSMenu supermenu ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_supermenu);
        return result is this.id_ ? this : (result !is null ? new NSMenu(result) : null);
    }

    public id tearOffMenuRepresentation ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_tearOffMenuRepresentation);
        return result !is null ? new id(result) : null;
    }

    public NSString title ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_title);
        return result !is null ? new NSString(result) : null;
    }

    public void update ()
    {
        OS.objc_msgSend(this.id_, OS.sel_update);
    }

}