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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget Action
--
-- Author : Duncan Coutts
--
-- Created: 6 April 2005
--
-- Copyright (C) 2005 Duncan Coutts
--
-- 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.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- An action which can be triggered by a menu or toolbar item
--
-- * Module available since Gtk+ version 2.4
--
module Graphics.UI.Gtk.ActionMenuToolbar.Action (
-- * Detail
--
-- | Actions represent operations that the user can be perform, along with
-- some information how it should be presented in the interface. Each action
-- provides methods to create icons, menu items and toolbar items representing
-- itself.
--
-- As well as the callback that is called when the action gets activated,
-- the following also gets associated with the action:
--
-- * a name (not translated, for path lookup)
--
-- * a label (translated, for display)
--
-- * an accelerator
--
-- * whether label indicates a stock id
--
-- * a tooltip (optional, translated)
--
-- * a toolbar label (optional, shorter than label)
--
-- The action will also have some state information:
--
-- * visible (shown\/hidden)
--
-- * sensitive (enabled\/disabled)
--
-- Apart from regular actions, there are toggle actions, which can be
-- toggled between two states and radio actions, of which only one in a group
-- can be in the \"active\" state. Other actions can be implemented as 'Action'
-- subclasses.
--
-- Each action can have one or more proxy menu item, toolbar button or other
-- proxy widgets. Proxies mirror the state of the action (text label, tooltip,
-- icon, visible, sensitive, etc), and should change when the action's state
-- changes. When the proxy is activated, it should activate its action.
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----Action
-- | +----'ToggleAction'
-- @
#if GTK_CHECK_VERSION(2,4,0)
-- * Types
Action,
ActionClass,
castToAction, gTypeAction,
toAction,
-- * Constructors
actionNew,
-- * Methods
actionGetName,
actionIsSensitive,
actionGetSensitive,
#if GTK_CHECK_VERSION(2,6,0)
actionSetSensitive,
#endif
actionIsVisible,
actionGetVisible,
#if GTK_CHECK_VERSION(2,6,0)
actionSetVisible,
#endif
actionActivate,
actionCreateMenuItem,
actionCreateToolItem,
actionConnectProxy,
actionDisconnectProxy,
actionGetProxies,
actionConnectAccelerator,
actionDisconnectAccelerator,
#if GTK_CHECK_VERSION(2,6,0)
actionGetAccelPath,
#endif
actionSetAccelPath,
actionSetAccelGroup,
-- * Attributes
actionName,
actionLabel,
actionShortLabel,
actionTooltip,
actionStockId,
actionVisibleHorizontal,
#if GTK_CHECK_VERSION(2,6,0)
actionVisibleOverflown,
#endif
actionVisibleVertical,
actionIsImportant,
actionHideIfEmpty,
#if GTK_CHECK_VERSION(2,6,0)
actionSensitive,
actionVisible,
actionAccelPath,
#endif
-- * Signals
actionActivated,
-- * Deprecated
#ifndef DISABLE_DEPRECATED
onActionActivate,
afterActionActivate,
#endif
#endif
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.GList
import System.Glib.Attributes
import System.Glib.Properties
import System.Glib.GObject (constructNewGObject)
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
{#import Graphics.UI.Gtk.Types#}
{#import Graphics.UI.Gtk.Signals#}
import Graphics.UI.Gtk.General.StockItems
{# context lib="gtk" prefix="gtk" #}
#if GTK_CHECK_VERSION(2,4,0)
--------------------
-- Constructors
-- | Creates a new 'Action' object. To add the action to a 'ActionGroup' and
-- set the accelerator for the action, call
-- 'Graphics.UI.Gtk.ActionMenuToolbar.ActionGroup.actionGroupAddActionWithAccel'.
-- See "Graphics.UI.Gtk.ActionMenuToolbar.UIManager#XML-UI" for information on
-- allowed action names.
--
actionNew ::
String -- ^ @name@ - A unique name for the action
-> String -- ^ @label@ - the label displayed in menu items and on
-- buttons
-> Maybe String -- ^ @tooltip@ - a tooltip for the action
-> Maybe StockId -- ^ @stockId@ - the stock icon to display in widgets
-- representing the action
-> IO Action
actionNew name label tooltip stockId =
constructNewGObject mkAction $
maybeWith withUTFString stockId $ \stockIdPtr ->
maybeWith withUTFString tooltip $ \tooltipPtr ->
withUTFString label $ \labelPtr ->
withUTFString name $ \namePtr ->
{# call gtk_action_new #}
namePtr
labelPtr
tooltipPtr
stockIdPtr
--------------------
-- Methods
-- | Returns the name of the action.
--
actionGetName :: ActionClass self => self -> IO String
actionGetName self =
{# call gtk_action_get_name #}
(toAction self)
>>= peekUTFString
-- | Returns whether the action is effectively sensitive.
--
actionIsSensitive :: ActionClass self => self
-> IO Bool -- ^ returns @True@ if the action and its associated action group
-- are both sensitive.
actionIsSensitive self =
liftM toBool $
{# call gtk_action_is_sensitive #}
(toAction self)
-- | Returns whether the action itself is sensitive. Note that this doesn't
-- necessarily mean effective sensitivity. See 'actionIsSensitive' for that.
--
actionGetSensitive :: ActionClass self => self
-> IO Bool -- ^ returns @True@ if the action itself is sensitive.
actionGetSensitive self =
liftM toBool $
{# call gtk_action_get_sensitive #}
(toAction self)
#if GTK_CHECK_VERSION(2,6,0)
-- | Sets the sensitive property of the action to @sensitive@. Note that
-- this doesn't necessarily mean effective sensitivity. See 'actionIsSensitive'
-- for that.
--
-- * Available since Gtk+ version 2.6
--
actionSetSensitive :: ActionClass self => self
-> Bool -- ^ @sensitive@ - @True@ to make the action sensitive
-> IO ()
actionSetSensitive self sensitive =
{# call gtk_action_set_sensitive #}
(toAction self)
(fromBool sensitive)
#endif
-- | Returns whether the action is effectively visible.
--
actionIsVisible :: ActionClass self => self
-> IO Bool -- ^ returns @True@ if the action and its associated action group
-- are both visible.
actionIsVisible self =
liftM toBool $
{# call gtk_action_is_visible #}
(toAction self)
-- | Returns whether the action itself is visible. Note that this doesn't
-- necessarily mean effective visibility. See 'actionIsSensitive' for that.
--
actionGetVisible :: ActionClass self => self
-> IO Bool -- ^ returns @True@ if the action itself is visible.
actionGetVisible self =
liftM toBool $
{# call gtk_action_get_visible #}
(toAction self)
#if GTK_CHECK_VERSION(2,6,0)
-- | Sets the visible property of the action to @visible@. Note that this
-- doesn't necessarily mean effective visibility. See 'actionIsVisible' for
-- that.
--
-- * Available since Gtk+ version 2.6
--
actionSetVisible :: ActionClass self => self
-> Bool -- ^ @visible@ - @True@ to make the action visible
-> IO ()
actionSetVisible self visible =
{# call gtk_action_set_visible #}
(toAction self)
(fromBool visible)
#endif
-- | Emits the \"activate\" signal on the specified action, if it isn't
-- insensitive. This gets called by the proxy widgets when they get activated.
--
-- It can also be used to manually activate an action.
--
actionActivate :: ActionClass self => self -> IO ()
actionActivate self =
{# call gtk_action_activate #}
(toAction self)
-- | Creates a menu item widget that proxies for the given action.
--
actionCreateMenuItem :: ActionClass self => self
-> IO Widget -- ^ returns a menu item connected to the action.
actionCreateMenuItem self =
makeNewObject mkWidget $
{# call gtk_action_create_menu_item #}
(toAction self)
-- | Creates a toolbar item widget that proxies for the given action.
--
actionCreateToolItem :: ActionClass self => self
-> IO Widget -- ^ returns a toolbar item connected to the action.
actionCreateToolItem self =
makeNewObject mkWidget $
{# call gtk_action_create_tool_item #}
(toAction self)
-- | Connects a widget to an action object as a proxy. Synchronises various
-- properties of the action with the widget (such as label text, icon, tooltip,
-- etc), and attaches a callback so that the action gets activated when the
-- proxy widget does.
--
-- If the widget is already connected to an action, it is disconnected
-- first.
--
actionConnectProxy :: (ActionClass self, WidgetClass proxy) => self
-> proxy -- ^ @proxy@ - the proxy widget
-> IO ()
actionConnectProxy self proxy =
{# call gtk_action_connect_proxy #}
(toAction self)
(toWidget proxy)
-- | Disconnects a proxy widget from an action.
--
actionDisconnectProxy :: (ActionClass self, WidgetClass proxy) => self
-> proxy -- ^ @proxy@ - the proxy widget
-> IO ()
actionDisconnectProxy self proxy =
{# call gtk_action_disconnect_proxy #}
(toAction self)
(toWidget proxy)
-- | Returns the proxy widgets for an action.
--
actionGetProxies :: ActionClass self => self -> IO [Widget]
actionGetProxies self =
{# call gtk_action_get_proxies #}
(toAction self)
>>= readGSList
>>= mapM (\elemPtr -> makeNewObject mkWidget (return elemPtr))
-- | Installs the accelerator for @action@ if @action@ has an accel path and
-- group. See 'actionSetAccelPath' and 'actionSetAccelGroup'
--
-- Since multiple proxies may independently trigger the installation of the
-- accelerator, the @action@ counts the number of times this function has been
-- called and doesn't remove the accelerator until
-- 'actionDisconnectAccelerator' has been called as many times.
--
actionConnectAccelerator :: ActionClass self => self -> IO ()
actionConnectAccelerator self =
{# call gtk_action_connect_accelerator #}
(toAction self)
-- | Undoes the effect of one call to 'actionConnectAccelerator'.
--
actionDisconnectAccelerator :: ActionClass self => self -> IO ()
actionDisconnectAccelerator self =
{# call gtk_action_disconnect_accelerator #}
(toAction self)
#if GTK_CHECK_VERSION(2,6,0)
-- | Returns the accel path for this action.
--
-- * Available since Gtk+ version 2.6
--
actionGetAccelPath :: ActionClass self => self
-> IO (Maybe String) -- ^ returns the accel path for this action, or
-- @Nothing@ if none is set.
actionGetAccelPath self =
{# call gtk_action_get_accel_path #}
(toAction self)
>>= maybePeek peekUTFString
#endif
-- | Sets the accel path for this action. All proxy widgets associated with
-- the action will have this accel path, so that their accelerators are
-- consistent.
--
actionSetAccelPath :: ActionClass self => self
-> String -- ^ @accelPath@ - the accelerator path
-> IO ()
actionSetAccelPath self accelPath =
withUTFString accelPath $ \accelPathPtr ->
{# call gtk_action_set_accel_path #}
(toAction self)
accelPathPtr
-- | Sets the 'AccelGroup' in which the accelerator for this action will be
-- installed.
--
actionSetAccelGroup :: ActionClass self => self -> AccelGroup -> IO ()
actionSetAccelGroup self accelGroup =
{# call gtk_action_set_accel_group #}
(toAction self)
accelGroup
--------------------
-- Attributes
-- | A unique name for the action.
--
-- Default value: \"\"
--
actionName :: ActionClass self => Attr self String
actionName = newAttrFromStringProperty "name"
-- | The label used for menu items and buttons that activate this action.
--
-- Default value: \"\"
--
actionLabel :: ActionClass self => Attr self String
actionLabel = newAttrFromStringProperty "label"
-- | A shorter label that may be used on toolbar buttons.
--
-- Default value: \"\"
--
actionShortLabel :: ActionClass self => Attr self String
actionShortLabel = newAttrFromStringProperty "short-label"
-- | A tooltip for this action.
--
-- Default value: @Nothing@
--
actionTooltip :: ActionClass self => Attr self (Maybe String)
actionTooltip = newAttrFromMaybeStringProperty "tooltip"
-- | The stock icon displayed in widgets representing this action.
--
-- Default value: @Nothing@
--
actionStockId :: ActionClass self => Attr self (Maybe String)
actionStockId = newAttrFromMaybeStringProperty "stock_id"
-- | Whether the toolbar item is visible when the toolbar is in a horizontal
-- orientation.
--
-- Default value: @True@
--
actionVisibleHorizontal :: ActionClass self => Attr self Bool
actionVisibleHorizontal = newAttrFromBoolProperty "visible-horizontal"
#if GTK_CHECK_VERSION(2,6,0)
-- | When @True@, toolitem proxies for this action are represented in the
-- toolbar overflow menu.
--
-- Default value: @True@
--
-- * Available since Gtk+ version 2.6
--
actionVisibleOverflown :: ActionClass self => Attr self Bool
actionVisibleOverflown = newAttrFromBoolProperty "visible-overflown"
#endif
-- | Whether the toolbar item is visible when the toolbar is in a vertical
-- orientation.
--
-- Default value: @True@
--
actionVisibleVertical :: ActionClass self => Attr self Bool
actionVisibleVertical = newAttrFromBoolProperty "visible-vertical"
-- | Whether the action is considered important. When @True@, toolitem proxies
-- for this action show text in
-- 'Graphics.UI.Gtk.MenuComboToolbar.Toolbar.ToolbarBothHoriz' mode.
--
-- Default value: @False@
--
actionIsImportant :: ActionClass self => Attr self Bool
actionIsImportant = newAttrFromBoolProperty "is-important"
-- | When @True@, empty menu proxies for this action are hidden.
--
-- Default value: @True@
--
actionHideIfEmpty :: ActionClass self => Attr self Bool
actionHideIfEmpty = newAttrFromBoolProperty "hide-if-empty"
#if GTK_CHECK_VERSION(2,6,0)
-- | Whether the action is enabled.
--
-- Default value: @True@
--
-- * Available since Gtk+ version 2.6
--
actionSensitive :: ActionClass self => Attr self Bool
actionSensitive = newAttr
actionGetSensitive
actionSetSensitive
-- | Whether the action is visible.
--
-- Default value: @True@
--
-- * Available since Gtk+ version 2.6
--
actionVisible :: ActionClass self => Attr self Bool
actionVisible = newAttr
actionGetVisible
actionSetVisible
-- | \'accelPath\' property. See 'actionGetAccelPath' and 'actionSetAccelPath'
--
-- * Available since Gtk+ version 2.6
--
actionAccelPath :: ActionClass self => ReadWriteAttr self (Maybe String) String
actionAccelPath = newAttr
actionGetAccelPath
actionSetAccelPath
#endif
--------------------
-- Signals
-- %hash c:4608 d:49a3
-- | The \"activate\" signal is emitted when the action is activated.
--
actionActivated :: ActionClass self => Signal self (IO ())
actionActivated = Signal (connect_NONE__NONE "activate")
--------------------
-- Deprecated Signals
#ifndef DISABLE_DEPRECATED
-- | The \"activate\" signal is emitted when the action is activated.
--
onActionActivate, afterActionActivate :: ActionClass self => self
-> IO ()
-> IO (ConnectId self)
onActionActivate = connect_NONE__NONE "activate" False
afterActionActivate = connect_NONE__NONE "activate" True
#endif
#endif
|