1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget MenuItem
--
-- Author : Axel Simon
--
-- Created: 15 May 2001
--
-- Copyright (C) 1999-2005 Axel Simon
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- NOTES
--
-- This widget derives from 'Item'. Since CList and CTree are deprecated, it
-- is the only child of that widget. The three signals defined by Item are
-- therefore bound in this module.
--
-- TODO
--
-- figure out what the signals \"toggle-size-allocate\" and
-- \"toggle-size-request\" are good for and bind them if useful
--
-- figure out if the connectToToggle signal is useful at all
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- The widget used for item in menus
--
module Graphics.UI.Gtk.MenuComboToolbar.MenuItem (
-- * Detail
--
-- | The 'MenuItem' widget and the derived widgets are the only valid childs
-- for menus. Their function is to correctly handle highlighting, alignment,
-- events and submenus.
--
-- As it derives from 'Bin' it can hold any valid child widget, altough only
-- a few are really useful.
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Container'
-- | +----'Bin'
-- | +----'Item'
-- | +----MenuItem
-- | +----'CheckMenuItem'
-- | +----'ImageMenuItem'
-- | +----'SeparatorMenuItem'
-- | +----'TearoffMenuItem'
-- @
-- * Types
MenuItem,
MenuItemClass,
castToMenuItem, gTypeMenuItem,
toMenuItem,
-- * Constructors
menuItemNew,
menuItemNewWithLabel,
menuItemNewWithMnemonic,
-- * Methods
menuItemSetSubmenu,
menuItemGetSubmenu,
menuItemRemoveSubmenu,
menuItemSelect,
menuItemDeselect,
menuItemActivate,
menuItemSetRightJustified,
menuItemGetRightJustified,
menuItemSetAccelPath,
-- * Attributes
menuItemSubmenu,
menuItemRightJustified,
-- * Signals
onActivateItem,
afterActivateItem,
onActivateLeaf,
afterActivateLeaf,
onSelect,
afterSelect,
onDeselect,
afterDeselect,
onToggle,
afterToggle
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Attributes
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
{#import Graphics.UI.Gtk.Types#}
{#import Graphics.UI.Gtk.Signals#}
{# context lib="gtk" prefix="gtk" #}
--------------------
-- Constructors
-- | Creates a new 'MenuItem'.
--
menuItemNew :: IO MenuItem
menuItemNew =
makeNewObject mkMenuItem $
liftM (castPtr :: Ptr Widget -> Ptr MenuItem) $
{# call unsafe menu_item_new #}
-- | Creates a new 'MenuItem' whose child is a 'Label'.
--
menuItemNewWithLabel ::
String -- ^ @label@ - the text for the label
-> IO MenuItem
menuItemNewWithLabel label =
makeNewObject mkMenuItem $
liftM (castPtr :: Ptr Widget -> Ptr MenuItem) $
withUTFString label $ \labelPtr ->
{# call unsafe menu_item_new_with_label #}
labelPtr
-- | Creates a new 'MenuItem' containing a label. The label will be created
-- using 'labelNewWithMnemonic', so underscores in @label@ indicate the
-- mnemonic for the menu item.
--
menuItemNewWithMnemonic ::
String -- ^ @label@ - The text of the label, with an underscore in
-- front of the mnemonic character
-> IO MenuItem
menuItemNewWithMnemonic label =
makeNewObject mkMenuItem $
liftM (castPtr :: Ptr Widget -> Ptr MenuItem) $
withUTFString label $ \labelPtr ->
{# call unsafe menu_item_new_with_mnemonic #}
labelPtr
--------------------
-- Methods
-- | Sets the item's submenu, or changes it.
--
menuItemSetSubmenu :: (MenuItemClass self, MenuClass submenu) => self -> submenu -> IO ()
menuItemSetSubmenu self submenu =
{# call menu_item_set_submenu #}
(toMenuItem self)
(toWidget submenu)
-- | Gets the submenu underneath this menu item, if any. See
-- 'menuItemSetSubmenu'.
--
menuItemGetSubmenu :: MenuItemClass self => self
-> IO (Maybe Widget) -- ^ returns submenu for this menu item, or @Nothing@ if
-- none.
menuItemGetSubmenu self =
maybeNull (makeNewObject mkWidget) $
{# call unsafe menu_item_get_submenu #}
(toMenuItem self)
-- | Removes the item's submenu.
--
menuItemRemoveSubmenu :: MenuItemClass self => self -> IO ()
menuItemRemoveSubmenu self =
{# call menu_item_remove_submenu #}
(toMenuItem self)
-- | Select the menu item. Emits the \"select\" signal on the item.
--
menuItemSelect :: MenuItemClass self => self -> IO ()
menuItemSelect self =
{# call menu_item_select #}
(toMenuItem self)
-- | Deselect the menu item. Emits the \"deselect\" signal on the item.
--
menuItemDeselect :: MenuItemClass self => self -> IO ()
menuItemDeselect self =
{# call menu_item_deselect #}
(toMenuItem self)
-- | Simulate a click on the menu item. Emits the \"activate\" signal on the item.
--
menuItemActivate :: MenuItemClass self => self -> IO ()
menuItemActivate self =
{# call menu_item_activate #}
(toMenuItem self)
-- | Sets whether the menu item appears justified at the right side of a menu
-- bar. This was traditionally done for \"Help\" menu items, but is now
-- considered a bad idea. (If the widget layout is reversed for a right-to-left
-- language like Hebrew or Arabic, right-justified-menu-items appear at the
-- left.)
--
menuItemSetRightJustified :: MenuItemClass self => self
-> Bool -- ^ @rightJustified@ - if @True@ the menu item will appear at the
-- far right if added to a menu bar.
-> IO ()
menuItemSetRightJustified self rightJustified =
{# call menu_item_set_right_justified #}
(toMenuItem self)
(fromBool rightJustified)
-- | Gets whether the menu item appears justified at the right side of the
-- menu bar.
--
menuItemGetRightJustified :: MenuItemClass self => self -> IO Bool
menuItemGetRightJustified self =
liftM toBool $
{# call unsafe menu_item_get_right_justified #}
(toMenuItem self)
-- | Set the accelerator path on the menu item, through which runtime changes of
-- the menu item's accelerator caused by the user can be identified and saved
-- to persistant storage (see 'accelMapSave' on this). To setup a default
-- accelerator for this menu item, call 'accelMapAddEntry' with the same accel
-- path. See also 'accelMapAddEntry' on the specifics of accelerator paths, and
-- 'menuSetAccelPath' for a more convenient variant of this function.
--
-- This function is basically a convenience wrapper that handles calling
-- 'widgetSetAccelPath' with the appropriate accelerator group for the menu
-- item.
--
-- Note that you do need to set an accelerator on the parent menu with
-- 'menuSetAccelGroup' for this to work.
--
menuItemSetAccelPath :: MenuItemClass self => self
-> Maybe String -- ^ @accelPath@ - accelerator path, corresponding to this
-- menu item's functionality, or @Nothing@ to unset the
-- current path.
-> IO ()
menuItemSetAccelPath self accelPath =
maybeWith withUTFString accelPath $ \accelPathPtr ->
{# call menu_item_set_accel_path #}
(toMenuItem self)
accelPathPtr
--------------------
-- Attributes
-- | \'submenu\' property. See 'menuItemGetSubmenu' and 'menuItemSetSubmenu'
--
menuItemSubmenu :: (MenuItemClass self, MenuClass submenu) => ReadWriteAttr self (Maybe Widget) submenu
menuItemSubmenu = newAttr
menuItemGetSubmenu
menuItemSetSubmenu
-- | \'rightJustified\' property. See 'menuItemGetRightJustified' and
-- 'menuItemSetRightJustified'
--
menuItemRightJustified :: MenuItemClass self => Attr self Bool
menuItemRightJustified = newAttr
menuItemGetRightJustified
menuItemSetRightJustified
--------------------
-- Signals
-- | The user has chosen the menu item.
--
-- * This is the only function applications normally connect to.
-- It is not emitted if the item has a submenu.
--
onActivateLeaf, afterActivateLeaf :: MenuItemClass self => self
-> IO ()
-> IO (ConnectId self)
onActivateLeaf = connect_NONE__NONE "activate" False
afterActivateLeaf = connect_NONE__NONE "activate" True
-- | Emitted when the user chooses a menu item that has a submenu.
--
-- * This signal is not emitted if the menu item does not have a
-- submenu.
--
onActivateItem, afterActivateItem :: MenuItemClass self => self
-> IO ()
-> IO (ConnectId self)
onActivateItem = connect_NONE__NONE "activate-item" False
afterActivateItem = connect_NONE__NONE "activate-item" True
-- | This signal is emitted when the item is selected.
--
onSelect, afterSelect :: ItemClass i => i
-> IO ()
-> IO (ConnectId i)
onSelect = connect_NONE__NONE "select" False
afterSelect = connect_NONE__NONE "select" True
-- | This signal is emitted when the item is deselected.
--
onDeselect, afterDeselect :: ItemClass i => i
-> IO ()
-> IO (ConnectId i)
onDeselect = connect_NONE__NONE "deselect" False
afterDeselect = connect_NONE__NONE "deselect" True
-- | This signal is emitted when the item is toggled.
--
onToggle, afterToggle :: ItemClass i => i
-> IO ()
-> IO (ConnectId i)
onToggle = connect_NONE__NONE "toggled" False
afterToggle = connect_NONE__NONE "toggled" True
|