Portability | portable |
---|---|
Stability | provisional |
Maintainer | wxhaskell-devel@lists.sourceforge.net |
Defines Menus, toolbars, and statusbars.
The function menuPane
is used to create a menu
that can contain menuItem
s. Menu items can contain event handlers
using (on
command
), but they can also be set, using the menu
function, on a frame or (mdi) window so that the menu command is handled
in the context of the active window instead of the context of the
entire application.
do frame <- frame [text := "Demo"] file <- menuPane [text := "&File"] mclose <- menuItem file [text := "&Close\tCtrl+C", help := "Close the document"] set frame [menuBar := [file] ,on (menu mclose) := ...]
- type MenuBar a = EvtHandler (CMenuBar a)
- type Menu a = EvtHandler (CMenu a)
- menuBar :: WriteAttr (Frame a) [Menu ()]
- menuPopup :: Menu b -> Point -> Window a -> IO ()
- menuPane :: [Prop (Menu ())] -> IO (Menu ())
- menuHelp :: [Prop (Menu ())] -> IO (Menu ())
- menuRes :: Window a -> String -> [Prop (Menu ())] -> IO (Menu ())
- menuBarLoadRes :: Window a -> FilePath -> String -> IO (MenuBar ())
- menu :: MenuItem a -> Event (Window w) (IO ())
- menuId :: Id -> Event (Window w) (IO ())
- type MenuItem a = WxObject (CMenuItem a)
- menuItem :: Menu a -> [Prop (MenuItem ())] -> IO (MenuItem ())
- menuQuit :: Menu a -> [Prop (MenuItem ())] -> IO (MenuItem ())
- menuAbout :: Menu a -> [Prop (MenuItem ())] -> IO (MenuItem ())
- menuItemEx :: Menu a -> Id -> String -> Int -> [Prop (MenuItem ())] -> IO (MenuItem ())
- menuItemOnCommandRes :: Window a -> String -> IO () -> IO ()
- menuLine :: Menu a -> IO ()
- menuSub :: Menu b -> Menu a -> [Prop (MenuItem ())] -> IO (MenuItem ())
- menuRadioItem :: Menu a -> [Prop (MenuItem ())] -> IO (MenuItem ())
- type ToolBar a = ToolBarBase (CToolBar a)
- toolBar :: Frame a -> [Prop (ToolBar ())] -> IO (ToolBar ())
- toolBarEx :: Frame a -> Bool -> Bool -> [Prop (ToolBar ())] -> IO (ToolBar ())
- data ToolBarItem
- toolMenu :: ToolBar a -> MenuItem a -> String -> FilePath -> [Prop ToolBarItem] -> IO ToolBarItem
- toolMenuFromBitmap :: ToolBar a -> MenuItem a -> String -> Bitmap b -> [Prop ToolBarItem] -> IO ToolBarItem
- toolItem :: ToolBar a -> String -> Bool -> FilePath -> [Prop ToolBarItem] -> IO ToolBarItem
- toolControl :: ToolBar a -> Control b -> IO ()
- tool :: ToolBarItem -> Event (Window w) (IO ())
- data StatusField
- statusBar :: WriteAttr (Frame a) [StatusField]
- statusField :: [Prop StatusField] -> IO StatusField
- statusWidth :: Attr StatusField Int
- menuList :: [Prop (Menu ())] -> IO (Menu ())
- menubar :: WriteAttr (Frame a) [Menu ()]
- statusbar :: WriteAttr (Frame a) [StatusField]
Menu
Menu containers
type MenuBar a = EvtHandler (CMenuBar a)
Pointer to an object of type MenuBar
, derived from EvtHandler
.
type Menu a = EvtHandler (CMenu a)
Pointer to an object of type Menu
, derived from EvtHandler
.
menuHelp :: [Prop (Menu ())] -> IO (Menu ())Source
Append a help menu item (&Help
). On some platforms,
the help menu is handled specially
menuRes :: Window a -> String -> [Prop (Menu ())] -> IO (Menu ())Source
Complete the construction of a menu which has been loaded from a resource file. | Get a menu by name from a menu loaded from a resource file, given the frame which owns the menu. You can directly set properties on the item as part of the call, which enables simple connection of event handlers (e.g. on command).
menuBarLoadRes :: Window a -> FilePath -> String -> IO (MenuBar ())Source
Retrieve a menu bar instance which has been constructed by loading a resource file for a given top level window.
Menu events
Menu items
menuItem :: Menu a -> [Prop (MenuItem ())] -> IO (MenuItem ())Source
Append a menu item. The label can contain
menu accellerators by using an ampersand. It can also contain keyboard accellerators
after a tab ('\\t'
) character.
menuItem menu [text := "&Open\tCtrl+O", help := "Opens an existing document"]
You can create a checkable menu item by setting checkable
to True
in the
properties of a menu item.
Note: on GTK, it is required to set the text
attribute immediately at creation time.
menuQuit :: Menu a -> [Prop (MenuItem ())] -> IO (MenuItem ())Source
Append an quit menu item (&QuittCtrl+Q
). On some platforms,
the quit menu is handled specially
menuItemEx :: Menu a -> Id -> String -> Int -> [Prop (MenuItem ())] -> IO (MenuItem ())Source
Append a menu item with a specific id, label, and kind (like wxITEM_CHECK
).
menuItemOnCommandRes :: Window a -> String -> IO () -> IO ()Source
When setting event handlers on menu items which have been loaded from XRC resource files, properties cannot be used as the menu item instances are opaque to wxHaskell.
This function offers a convenient way to attach menu item event handlers, given the identity of the window which owns the menu containing the menu item, and the name of the menu item
menuRadioItem :: Menu a -> [Prop (MenuItem ())] -> IO (MenuItem ())Source
Append a radio menu item. These items are checkable
by default.
A sequence of radio menu items form automatically a group.
A different kind of menu item, like a menuLine
, terminates the group.
Note: one sometimes has to set the first selected radio item
specifically after setting the menubar property, or otherwise the
radio item bullet is not displayed on windows.
See menuItem
for other properties of menu radio items.
Tool bar
type ToolBar a = ToolBarBase (CToolBar a)
Pointer to an object of type ToolBar
, derived from ToolBarBase
.
toolBar :: Frame a -> [Prop (ToolBar ())] -> IO (ToolBar ())Source
Create a toolbar window with a divider and text labels.
Normally, you can use toolMenu
to add tools in the toolbar
that behave like normal menu items.
tbar <- toolBar f [] toolMenu tbar open "Open" "open.png" [] toolMenu tbar about "About" "about.png" []
toolBarEx :: Frame a -> Bool -> Bool -> [Prop (ToolBar ())] -> IO (ToolBar ())Source
Create a toolbar window. The second argument specifies whether text labels should be shown, and the third argument whether a divider line is present above the toolbar.
data ToolBarItem Source
A tool in a toolbar.
toolMenu :: ToolBar a -> MenuItem a -> String -> FilePath -> [Prop ToolBarItem] -> IO ToolBarItemSource
Create a tool bar item based on a menu. Takes a a relevant menu
item, a label and an image file (bmp,png,gif,ico,etc.) as arguments. The image
file is normally 16x15 pixels.
The toolbar item will fire the relevant menu items just as if the menu has been selected.
Checkable menus will give a checkable toolbar item. Beware though that checkable tools
normally require a specific on command
handler to keep them synchronised with the
corresponding menu item.
toolMenuFromBitmap :: ToolBar a -> MenuItem a -> String -> Bitmap b -> [Prop ToolBarItem] -> IO ToolBarItemSource
toolItem :: ToolBar a -> String -> Bool -> FilePath -> [Prop ToolBarItem] -> IO ToolBarItemSource
toolControl :: ToolBar a -> Control b -> IO ()Source
Add an arbitrary control to a toolbar (typically a ComboBox
). The control
must be created with the toolbar as the parent.
tool :: ToolBarItem -> Event (Window w) (IO ())Source
React on tool event. (normally handled by menu
though, so only use this
for orphan toolbar items).
Status bar
statusBar :: WriteAttr (Frame a) [StatusField]Source
Specify the statusbar of a frame.
statusField :: [Prop StatusField] -> IO StatusFieldSource
Create a status field.
statusWidth :: Attr StatusField IntSource
The status width attribute determines the width of a status bar field.
A negative width makes the field strechable. The width than determines
the amount of stretch in relation with other fields. The default
status width is -1
, ie. all fields stretch evenly.
Here is an example of a statusbar with three fields, where the last field is 50 pixels wide, the first takes 66% of the remaining space and the second field 33%.
field1 <- statusField [statusWidth := -2] field2 <- statusField [text := "hi"] field3 <- statusField [statusWidth := 50] set frame [statusBar := [field1,field2,field3]]