[archived content]

About

Menus are fairly explanatory in name, they hold options and fold out. Currently there is no way to add the Menu as a simple control and only the MainMenu? and ContextMenu? exist.

Usage

Menus are all about their MenuItems?. A Menu merely contains all the menuItems, it does not represent text or anything else. Luckily there are good things to Menus thanks to DFL. Mainly, things just work. All MenuItems? are Menus and as such you can add other MenuItems? to their menuItems collection and it makes the MenuItem? into a Menu with options inside of it. This makes sense to have MenuItems? represent Menus since the Menu itself may need to be clicked.

Shortcuts

To add mnemonics just put '&' in front of the character to use as a mnemonic in the MenuItem?'s text. In order to use Accelerators (eg. "Ctrl+S") please refer to Form.addShortcut.

Breaks

To introduce a bar break do not set the text, set the text to "-", or set barBreak to true.

Example

import dfl.all;

public void main() {
        auto form = new Form();
        form.text = "Menu Example";

        auto menu = new MainMenu();
        form.menu = menu;

        auto currentMenu = new MenuItem("File");
        menu.menuItems.add(currentMenu);

        auto currentItem = new MenuItem("&New");
        currentMenu.menuItems.add(currentItem);

        currentItem = new MenuItem("Recent");
        currentMenu.menuItems.add(currentItem);

        currentMenu = currentItem;

        currentItem = new MenuItem("File");
        currentMenu.menuItems.add(currentItem);

        currentItem = new MenuItem("Project");
        currentMenu.menuItems.add(currentItem);

        currentMenu = cast(MenuItem)currentMenu.parent;

        currentItem = new MenuItem();
        currentItem.barBreak = true;
        currentMenu.menuItems.add(currentItem);

        currentItem = new MenuItem("Exit");
        currentMenu.menuItems.add(currentItem);

        currentItem = new MenuItem("Side Option");
        currentItem.breakItem = true;
        currentItem.checked = true;
        currentMenu.menuItems.add(currentItem);

        Application.run(form);
}

module dfl.menu;
public class ContextMenu: Menu
{
protected void onReflectedMessage(ref Message m);
public Event popup(ContextMenu,EventArgs);
public final void show(Control control,Point pos);
[+] Inherited members
}
public static class ContextMenu.MenuItemCollection
{
public void add(char[] value);
public void add(MenuItem mi);
public void add(char[] s);
public void addRange(char[][] items);
public void addRange(MenuItem[] items);
public bool contains(char[] s);
public int indexOf(char[] s);
public void insert(int index,char[] s);
public void remove(char[] s);
}
public class MainMenu: Menu
{
[+] Inherited members
}
public static class MainMenu.MenuItemCollection
{
public void add(char[] value);
public void add(MenuItem mi);
public void add(char[] s);
public void addRange(char[][] items);
public void addRange(MenuItem[] items);
public bool contains(char[] s);
public int indexOf(char[] s);
public void insert(int index,char[] s);
public void remove(char[] s);
}
public class Menu
{
public final HMENU handle; [property getter]
public bool isParent; [property getter]
public final MenuItemCollection menuItems; [property getter]
protected void onReflectedMessage(ref Message m);
public final Object tag; [property getter]
public final Object tag; [property setter]
}
public static class Menu.MenuItemCollection
{
public void add(char[] value);
public void add(MenuItem mi);
public void add(char[] s);
public void addRange(char[][] items);
public void addRange(MenuItem[] items);
public bool contains(char[] s);
public int indexOf(char[] s);
public void insert(int index,char[] s);
public void remove(char[] s);
}
public class MenuItem: Menu
{
public final bool barBreak; [property setter]
public final bool barBreak; [property getter]
public final bool breakItem; [property setter]
public final bool breakItem; [property getter]
public final bool checked; [property getter]
public final bool checked; [property setter]
public Event click(MenuItem,EventArgs);
public final bool defaultItem; [property getter]
public final bool defaultItem; [property setter]
public final bool enabled; [property setter]
public final bool enabled; [property getter]
public final int index; [property setter]
public final int index; [property getter]
public bool isParent; [property getter]
protected final int menuID; [property getter]
public final char mnemonic; [property getter]
protected void onClick(EventArgs ea);
protected void onPopup(EventArgs ea);
protected void onReflectedMessage(ref Message m);
protected void onSelect(EventArgs ea);
public int opCmp(char[] val);
public int opCmp(Object o);
public int opEquals(Object o);
public int opEquals(char[] val);
public final Menu parent; [property setter]
public final Menu parent; [property getter]
public final void performClick();
public final void performSelect();
public Event popup(MenuItem,EventArgs);
public final bool radioCheck; [property setter]
public final bool radioCheck; [property getter]
public Event select(MenuItem,EventArgs);
public final char[] text; [property getter]
public final char[] text; [property setter]
public char[] toString();
[+] Inherited members
}
public static class MenuItem.MenuItemCollection
{
public void add(char[] value);
public void add(MenuItem mi);
public void add(char[] s);
public void addRange(char[][] items);
public void addRange(MenuItem[] items);
public bool contains(char[] s);
public int indexOf(char[] s);
public void insert(int index,char[] s);
public void remove(char[] s);
}

Page last modified on June 29, 2008, at 07:38 PM