view dwt/internal/cocoa/NSMenuView.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
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.NSMenuView;

import dwt.internal.cocoa.CGFloat;
import dwt.internal.cocoa.NSEvent;
import dwt.internal.cocoa.NSFont;
import dwt.internal.cocoa.NSInteger;
import dwt.internal.cocoa.NSMenu;
import dwt.internal.cocoa.NSMenuItemCell;
import dwt.internal.cocoa.NSNotification;
import dwt.internal.cocoa.NSPoint;
import dwt.internal.cocoa.NSRect;
import dwt.internal.cocoa.NSScreen;
import dwt.internal.cocoa.NSView;
import dwt.internal.cocoa.OS;
import objc = dwt.internal.objc.runtime;

public class NSMenuView : NSView
{

    public this ()
    {
        super();
    }

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

    public void attachSubmenuForItemAtIndex (NSInteger index)
    {
        OS.objc_msgSend(this.id_, OS.sel_attachSubmenuForItemAtIndex_1, index);
    }

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

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

    public void detachSubmenu ()
    {
        OS.objc_msgSend(this.id_, OS.sel_detachSubmenu);
    }

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

    public NSInteger highlightedItemIndex ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_highlightedItemIndex);
    }

    public CGFloat horizontalEdgePadding ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_horizontalEdgePadding);
    }

    public CGFloat imageAndTitleOffset ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_imageAndTitleOffset);
    }

    public CGFloat imageAndTitleWidth ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_imageAndTitleWidth);
    }

    public NSInteger indexOfItemAtPoint (NSPoint point)
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfItemAtPoint_1, point);
    }

    public NSMenuView initAsTearOff ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_initAsTearOff);
        return result !is null ? this : null;
    }

    public NSRect innerRect ()
    {
        NSRect result;
        OS.objc_msgSend_stret(&result, this.id_, OS.sel_innerRect);
        return result;
    }

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

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

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

    public void itemAdded (NSNotification notification)
    {
        OS.objc_msgSend(this.id_, OS.sel_itemAdded_1, notification !is null ? notification.id_ : null);
    }

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

    public void itemRemoved (NSNotification notification)
    {
        OS.objc_msgSend(this.id_, OS.sel_itemRemoved_1, notification !is null ? notification.id_ : null);
    }

    public CGFloat keyEquivalentOffset ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_keyEquivalentOffset);
    }

    public CGFloat keyEquivalentWidth ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_keyEquivalentWidth);
    }

    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 NSMenu menu ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_menu);
        return result !is null ? new NSMenu(result) : null;
    }

    public static CGFloat menuBarHeight ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(OS.class_NSMenuView, OS.sel_menuBarHeight);
    }

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

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

    public void performActionWithHighlightingForItemAtIndex (NSInteger index)
    {
        OS.objc_msgSend(this.id_, OS.sel_performActionWithHighlightingForItemAtIndex_1, index);
    }

    public NSRect rectOfItemAtIndex (NSInteger index)
    {
        NSRect result;
        OS.objc_msgSend_stret(&result, this.id_, OS.sel_rectOfItemAtIndex_1, index);
        return result;
    }

    public void setFont (NSFont font)
    {
        OS.objc_msgSend(this.id_, OS.sel_setFont_1, font !is null ? font.id_ : null);
    }

    public void setHighlightedItemIndex (NSInteger index)
    {
        OS.objc_msgSend(this.id_, OS.sel_setHighlightedItemIndex_1, index);
    }

    public void setHorizontal (bool flag)
    {
        OS.objc_msgSend(this.id_, OS.sel_setHorizontal_1, flag);
    }

    public void setHorizontalEdgePadding (CGFloat pad)
    {
        OS.objc_msgSend(this.id_, OS.sel_setHorizontalEdgePadding_1, pad);
    }

    public void setMenu (NSMenu menu)
    {
        OS.objc_msgSend(this.id_, OS.sel_setMenu_1, menu !is null ? menu.id_ : null);
    }

    public void setMenuItemCell (NSMenuItemCell cell, NSInteger index)
    {
        OS.objc_msgSend(this.id_, OS.sel_setMenuItemCell_1forItemAtIndex_1, cell !is null ? cell.id_ : null, index);
    }

    public void setNeedsDisplayForItemAtIndex (NSInteger index)
    {
        OS.objc_msgSend(this.id_, OS.sel_setNeedsDisplayForItemAtIndex_1, index);
    }

    public void setNeedsSizing (bool flag)
    {
        OS.objc_msgSend(this.id_, OS.sel_setNeedsSizing_1, flag);
    }

    public void setWindowFrameForAttachingToRect (NSRect screenRect, NSScreen screen, NSRectEdge edge, NSInteger selectedItemIndex)
    {
        OS.objc_msgSend(this.id_, OS.sel_setWindowFrameForAttachingToRect_1onScreen_1preferredEdge_1popUpSelectedItem_1, screenRect,
                screen !is null ? screen.id_ : null, edge, selectedItemIndex);
    }

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

    public CGFloat stateImageOffset ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_stateImageOffset);
    }

    public CGFloat stateImageWidth ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_stateImageWidth);
    }

    public bool trackWithEvent (NSEvent event)
    {
        return OS.objc_msgSend(this.id_, OS.sel_trackWithEvent_1, event !is null ? event.id_ : null) !is null;
    }

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

}