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
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget ToggleButton
--
-- 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.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- Create buttons which retain their state
--
module Graphics.UI.Gtk.Buttons.ToggleButton (
-- * Detail
--
-- | A 'ToggleButton' is a 'Button' which will remain \'pressed-in\' when
-- clicked. Clicking again will cause the toggle button to return to its normal
-- state.
--
-- A toggle button is created by calling either 'toggleButtonNew' or
-- 'toggleButtonNewWithLabel'. If using the former, it is advisable to pack a
-- widget, (such as a 'Label' and\/or a 'Pixmap'), into the toggle button's
-- container. (See 'Button' for more information).
--
-- The state of a 'ToggleButton' can be set specifically using
-- 'toggleButtonSetActive', and retrieved using 'toggleButtonGetActive'.
--
-- To simply switch the state of a toggle button, use 'toggleButtonToggled'.
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Container'
-- | +----'Bin'
-- | +----'Button'
-- | +----ToggleButton
-- | +----'CheckButton'
-- @
-- * Types
ToggleButton,
ToggleButtonClass,
castToToggleButton, gTypeToggleButton,
toToggleButton,
-- * Constructors
toggleButtonNew,
toggleButtonNewWithLabel,
toggleButtonNewWithMnemonic,
-- * Methods
toggleButtonSetMode,
toggleButtonGetMode,
toggleButtonToggled,
toggleButtonGetActive,
toggleButtonSetActive,
toggleButtonGetInconsistent,
toggleButtonSetInconsistent,
-- * Attributes
toggleButtonActive,
toggleButtonInconsistent,
toggleButtonDrawIndicator,
toggleButtonMode,
-- * Signals
toggled,
-- * Deprecated
#ifndef DISABLE_DEPRECATED
-- * Signals
onToggled,
afterToggled,
#endif
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Attributes
import System.Glib.Properties
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 toggle button. A widget should be packed into the button,
-- as in 'Graphics.UI.Gtk.Buttons.Button.buttonNew'.
--
toggleButtonNew :: IO ToggleButton
toggleButtonNew =
makeNewObject mkToggleButton $
liftM (castPtr :: Ptr Widget -> Ptr ToggleButton) $
{# call unsafe toggle_button_new #}
-- | Creates a new toggle button with a text label.
--
toggleButtonNewWithLabel ::
String -- ^ @label@ - a string containing the message to be
-- placed in the toggle button.
-> IO ToggleButton
toggleButtonNewWithLabel label =
makeNewObject mkToggleButton $
liftM (castPtr :: Ptr Widget -> Ptr ToggleButton) $
withUTFString label $ \labelPtr ->
{# call unsafe toggle_button_new_with_label #}
labelPtr
-- | Creates a new 'ToggleButton' containing a label. The label will be
-- created using 'Graphics.UI.Gtk.Display.Label.labelNewWithMnemonic',
-- so underscores in @label@ indicate the
-- mnemonic for the button.
--
toggleButtonNewWithMnemonic ::
String -- ^ @label@ - the text of the button, with an underscore
-- in front of the mnemonic character
-> IO ToggleButton
toggleButtonNewWithMnemonic label =
makeNewObject mkToggleButton $
liftM (castPtr :: Ptr Widget -> Ptr ToggleButton) $
withUTFString label $ \labelPtr ->
{# call unsafe toggle_button_new_with_mnemonic #}
labelPtr
--------------------
-- Methods
-- | Sets whether the button is displayed as a separate indicator and label.
-- You can call this function on a 'CheckButton' or a 'RadioButton' with @False@
-- to make the button look like a normal button.
--
-- This function only affects instances of classes like 'CheckButton' and
-- 'RadioButton' that derive from 'ToggleButton', not instances of
-- 'ToggleButton' itself.
--
toggleButtonSetMode :: ToggleButtonClass self => self
-> Bool -- ^ @drawIndicator@ - if @True@, draw the button as a separate
-- indicator and label; if @False@, draw the button like a normal
-- button
-> IO ()
toggleButtonSetMode self drawIndicator =
{# call toggle_button_set_mode #}
(toToggleButton self)
(fromBool drawIndicator)
-- | Retrieves whether the button is displayed as a separate indicator and
-- label. See 'toggleButtonSetMode'.
--
toggleButtonGetMode :: ToggleButtonClass self => self
-> IO Bool -- ^ returns @True@ if the togglebutton is drawn as a separate
-- indicator and label.
toggleButtonGetMode self =
liftM toBool $
{# call unsafe toggle_button_get_mode #}
(toToggleButton self)
-- | Emits the toggled signal on the 'ToggleButton'. There is no good reason
-- for an application ever to call this function.
--
toggleButtonToggled :: ToggleButtonClass self => self -> IO ()
toggleButtonToggled self =
{# call toggle_button_toggled #}
(toToggleButton self)
-- | Queries a 'ToggleButton' and returns its current state. Returns @True@ if
-- the toggle button is pressed in and @False@ if it is raised.
--
toggleButtonGetActive :: ToggleButtonClass self => self -> IO Bool
toggleButtonGetActive self =
liftM toBool $
{# call unsafe toggle_button_get_active #}
(toToggleButton self)
-- | Sets the status of the toggle button. Set to @True@ if you want the
-- 'ToggleButton' to be \'pressed in\', and @False@ to raise it. This action
-- causes the toggled signal to be emitted.
--
toggleButtonSetActive :: ToggleButtonClass self => self
-> Bool -- ^ @isActive@ - @True@ or @False@.
-> IO ()
toggleButtonSetActive self isActive =
{# call toggle_button_set_active #}
(toToggleButton self)
(fromBool isActive)
-- | Gets the value set by 'toggleButtonSetInconsistent'.
--
toggleButtonGetInconsistent :: ToggleButtonClass self => self
-> IO Bool -- ^ returns @True@ if the button is displayed as inconsistent,
-- @False@ otherwise
toggleButtonGetInconsistent self =
liftM toBool $
{# call unsafe toggle_button_get_inconsistent #}
(toToggleButton self)
-- | If the user has selected a range of elements (such as some text or
-- spreadsheet cells) that are affected by a toggle button, and the current
-- values in that range are inconsistent, you may want to display the toggle in
-- an \"in between\" state. This function turns on \"in between\" display.
-- Normally you would turn off the inconsistent state again if the user toggles
-- the toggle button. This has to be done manually,
-- 'toggleButtonSetInconsistent' only affects visual appearance, it doesn't
-- affect the semantics of the button.
--
toggleButtonSetInconsistent :: ToggleButtonClass self => self
-> Bool -- ^ @setting@ - @True@ if state is inconsistent
-> IO ()
toggleButtonSetInconsistent self setting =
{# call toggle_button_set_inconsistent #}
(toToggleButton self)
(fromBool setting)
--------------------
-- Attributes
-- | If the toggle button should be pressed in or not.
--
-- Default value: @False@
--
toggleButtonActive :: ToggleButtonClass self => Attr self Bool
toggleButtonActive = newAttr
toggleButtonGetActive
toggleButtonSetActive
-- | If the toggle button is in an \"in between\" state.
--
-- Default value: @False@
--
toggleButtonInconsistent :: ToggleButtonClass self => Attr self Bool
toggleButtonInconsistent = newAttr
toggleButtonGetInconsistent
toggleButtonSetInconsistent
-- | If the toggle part of the button is displayed.
--
-- Default value: @False@
--
toggleButtonDrawIndicator :: ToggleButtonClass self => Attr self Bool
toggleButtonDrawIndicator = newAttrFromBoolProperty "draw-indicator"
-- | \'mode\' property. See 'toggleButtonGetMode' and 'toggleButtonSetMode'
--
toggleButtonMode :: ToggleButtonClass self => Attr self Bool
toggleButtonMode = newAttr
toggleButtonGetMode
toggleButtonSetMode
--------------------
-- Signals
-- %hash c:467 d:227e
-- | Should be connected if you wish to perform an action whenever the
-- 'ToggleButton''s state is changed.
--
toggled :: ToggleButtonClass self => Signal self (IO ())
toggled = Signal (connect_NONE__NONE "toggled")
--------------------
-- Deprecated Signals
#ifndef DISABLE_DEPRECATED
-- | Whenever the state of the button is changed, the toggled signal is
-- emitted.
--
onToggled, afterToggled :: ToggleButtonClass self => self
-> IO ()
-> IO (ConnectId self)
onToggled = connect_NONE__NONE "toggled" False
afterToggled = connect_NONE__NONE "toggled" True
#endif
|