{-# LINE 2 "./Graphics/UI/Gtk/ActionMenuToolbar/RadioAction.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget RadioAction
--
-- 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.
--
-- TODO
-- I don't know what the element type of the group GSList is for
-- radioActionSetGroup / radioActionGetGroup
--
-- Also, the signals clash with those from other modules
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- An action of which only one in a group can be active
--
-- * Module available since Gtk+ version 2.4
--
module Graphics.UI.Gtk.ActionMenuToolbar.RadioAction (
-- * Detail
--
-- | A 'RadioAction' is similar to 'RadioMenuItem'. A number of radio actions
-- can be linked together so that only one may be active at any one time.

-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Action'
-- | +----'ToggleAction'
-- | +----RadioAction
-- @


-- * Types
  RadioAction,
  RadioActionClass,
  castToRadioAction, gTypeRadioAction,
  toRadioAction,

-- * Constructors
  radioActionNew,

-- * Methods
  radioActionGetGroup,
  radioActionSetGroup,
  radioActionGetCurrentValue,

-- * Attributes
  radioActionValueAttr,
  radioActionGroup,

  radioActionCurrentValue,


-- * Signals
  radioActionChanged,


-- * Deprecated
  onRadioActionChanged,
  afterRadioActionChanged,


  ) 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 Graphics.UI.Gtk.Types
{-# LINE 92 "./Graphics/UI/Gtk/ActionMenuToolbar/RadioAction.chs" #-}
import Graphics.UI.Gtk.Signals
{-# LINE 93 "./Graphics/UI/Gtk/ActionMenuToolbar/RadioAction.chs" #-}
import Graphics.UI.Gtk.General.StockItems


{-# LINE 96 "./Graphics/UI/Gtk/ActionMenuToolbar/RadioAction.chs" #-}


--------------------
-- Constructors

-- | Creates a new 'RadioAction' object. To add the action to a 'ActionGroup'
-- and set the accelerator for the action, call
-- 'Graphics.UI.Gtk.ActionMenuToolbar.ActionGroup.actionGroupAddActionWithAccel'.
--
radioActionNew :: GlibString string
 => 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 this action
 -> Maybe StockId -- ^ @stockId@ - The stock icon to display in widgets
                   -- representing this action
 -> Int -- ^ @value@ - The value which 'radioActionGetCurrentValue'
                   -- should return if this action is selected.
 -> IO RadioAction
radioActionNew :: forall string.
GlibString string =>
string
-> string -> Maybe string -> Maybe StockId -> Int -> IO RadioAction
radioActionNew string
name string
label Maybe string
tooltip Maybe StockId
stockId Int
value =
  (ForeignPtr RadioAction -> RadioAction, FinalizerPtr RadioAction)
-> IO (Ptr RadioAction) -> IO RadioAction
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
wrapNewGObject (ForeignPtr RadioAction -> RadioAction, FinalizerPtr RadioAction)
forall {a}. (ForeignPtr RadioAction -> RadioAction, FinalizerPtr a)
mkRadioAction (IO (Ptr RadioAction) -> IO RadioAction)
-> IO (Ptr RadioAction) -> IO RadioAction
forall a b. (a -> b) -> a -> b
$
  (StockId
 -> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction))
-> Maybe StockId
-> (Ptr CChar -> IO (Ptr RadioAction))
-> IO (Ptr RadioAction)
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith StockId
-> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction)
forall s a. GlibString s => s -> (Ptr CChar -> IO a) -> IO a
forall a. StockId -> (Ptr CChar -> IO a) -> IO a
withUTFString Maybe StockId
stockId ((Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction))
-> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction)
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
stockIdPtr ->
  (string
 -> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction))
-> Maybe string
-> (Ptr CChar -> IO (Ptr RadioAction))
-> IO (Ptr RadioAction)
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith string
-> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction)
forall a. string -> (Ptr CChar -> IO a) -> IO a
forall s a. GlibString s => s -> (Ptr CChar -> IO a) -> IO a
withUTFString Maybe string
tooltip ((Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction))
-> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction)
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
tooltipPtr ->
  string
-> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction)
forall a. string -> (Ptr CChar -> IO a) -> IO a
forall s a. GlibString s => s -> (Ptr CChar -> IO a) -> IO a
withUTFString string
label ((Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction))
-> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction)
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
labelPtr ->
  string
-> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction)
forall a. string -> (Ptr CChar -> IO a) -> IO a
forall s a. GlibString s => s -> (Ptr CChar -> IO a) -> IO a
withUTFString string
name ((Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction))
-> (Ptr CChar -> IO (Ptr RadioAction)) -> IO (Ptr RadioAction)
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
namePtr ->
  Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> CInt
-> IO (Ptr RadioAction)
gtk_radio_action_new
{-# LINE 122 "./Graphics/UI/Gtk/ActionMenuToolbar/RadioAction.chs" #-}
    namePtr
    Ptr CChar
labelPtr
    Ptr CChar
tooltipPtr
    Ptr CChar
stockIdPtr
    (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
value)

--------------------
-- Methods

-- | Returns the list representing the radio group for this object
--
radioActionGetGroup :: RadioActionClass self => self
 -> IO [RadioAction] -- ^ returns the members of the radio group
radioActionGetGroup :: forall self. RadioActionClass self => self -> IO [RadioAction]
radioActionGetGroup self
self =
  (\(RadioAction ForeignPtr RadioAction
arg1) -> ForeignPtr RadioAction
-> (Ptr RadioAction -> IO (Ptr ())) -> IO (Ptr ())
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr RadioAction
arg1 ((Ptr RadioAction -> IO (Ptr ())) -> IO (Ptr ()))
-> (Ptr RadioAction -> IO (Ptr ())) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ \Ptr RadioAction
argPtr1 ->Ptr RadioAction -> IO (Ptr ())
gtk_radio_action_get_group Ptr RadioAction
argPtr1)
{-# LINE 137 "./Graphics/UI/Gtk/ActionMenuToolbar/RadioAction.chs" #-}
    (toRadioAction self)
  IO (Ptr ())
-> (Ptr () -> IO [Ptr RadioAction]) -> IO [Ptr RadioAction]
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr () -> IO [Ptr RadioAction]
forall a. Ptr () -> IO [Ptr a]
readGSList
  IO [Ptr RadioAction]
-> ([Ptr RadioAction] -> IO [RadioAction]) -> IO [RadioAction]
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Ptr RadioAction -> IO RadioAction)
-> [Ptr RadioAction] -> IO [RadioAction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\Ptr RadioAction
elemPtr -> (ForeignPtr RadioAction -> RadioAction, FinalizerPtr RadioAction)
-> IO (Ptr RadioAction) -> IO RadioAction
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewGObject (ForeignPtr RadioAction -> RadioAction, FinalizerPtr RadioAction)
forall {a}. (ForeignPtr RadioAction -> RadioAction, FinalizerPtr a)
mkRadioAction (Ptr RadioAction -> IO (Ptr RadioAction)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr RadioAction
elemPtr))

-- | Sets the radio group for the radio action object.
--
radioActionSetGroup :: (RadioActionClass self, RadioActionClass groupMember) => self
 -> groupMember -- ^ @groupMember@ - an existing member of the radio group
 -> IO ()
radioActionSetGroup :: forall self groupMember.
(RadioActionClass self, RadioActionClass groupMember) =>
self -> groupMember -> IO ()
radioActionSetGroup self
self groupMember
group = do
  Ptr ()
groupPtr <- (\(RadioAction ForeignPtr RadioAction
arg1) -> ForeignPtr RadioAction
-> (Ptr RadioAction -> IO (Ptr ())) -> IO (Ptr ())
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr RadioAction
arg1 ((Ptr RadioAction -> IO (Ptr ())) -> IO (Ptr ()))
-> (Ptr RadioAction -> IO (Ptr ())) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ \Ptr RadioAction
argPtr1 ->Ptr RadioAction -> IO (Ptr ())
gtk_radio_action_get_group Ptr RadioAction
argPtr1) (groupMember -> RadioAction
forall o. RadioActionClass o => o -> RadioAction
toRadioAction groupMember
group)
  (\(RadioAction ForeignPtr RadioAction
arg1) Ptr ()
arg2 -> ForeignPtr RadioAction -> (Ptr RadioAction -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr RadioAction
arg1 ((Ptr RadioAction -> IO ()) -> IO ())
-> (Ptr RadioAction -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr RadioAction
argPtr1 ->Ptr RadioAction -> Ptr () -> IO ()
gtk_radio_action_set_group Ptr RadioAction
argPtr1 Ptr ()
arg2)
{-# LINE 149 "./Graphics/UI/Gtk/ActionMenuToolbar/RadioAction.chs" #-}
    (toRadioAction self)
    Ptr ()
groupPtr

-- | Obtains the value property of the currently active member of the group to
-- which the action belongs.
--
radioActionGetCurrentValue :: RadioActionClass self => self
 -> IO Int -- ^ returns the value of the currently active group member
radioActionGetCurrentValue :: forall self. RadioActionClass self => self -> IO Int
radioActionGetCurrentValue self
self =
  (CInt -> Int) -> IO CInt -> IO Int
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (IO CInt -> IO Int) -> IO CInt -> IO Int
forall a b. (a -> b) -> a -> b
$
  (\(RadioAction ForeignPtr RadioAction
arg1) -> ForeignPtr RadioAction -> (Ptr RadioAction -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr RadioAction
arg1 ((Ptr RadioAction -> IO CInt) -> IO CInt)
-> (Ptr RadioAction -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr RadioAction
argPtr1 ->Ptr RadioAction -> IO CInt
gtk_radio_action_get_current_value Ptr RadioAction
argPtr1)
{-# LINE 160 "./Graphics/UI/Gtk/ActionMenuToolbar/RadioAction.chs" #-}
    (toRadioAction self)

--------------------
-- Attributes

-- %hash d:1bcf
-- | The value is an arbitrary integer which can be used as a convenient way
-- to determine which action in the group is currently active in an ::activate
-- or ::changed signal handler. See 'radioActionGetCurrentValue' and
-- 'RadioActionEntry' for convenient ways to get and set
-- this property.
--
-- Default value: 0
--
radioActionValueAttr :: RadioActionClass self => Attr self Int
radioActionValueAttr :: forall self. RadioActionClass self => Attr self Int
radioActionValueAttr = String -> Attr self Int
forall gobj. GObjectClass gobj => String -> Attr gobj Int
newAttrFromIntProperty String
"value"

-- %hash c:a380
-- | Sets a new group for a radio action.
--
radioActionGroup :: RadioActionClass self => ReadWriteAttr self [RadioAction] RadioAction
radioActionGroup :: forall self.
RadioActionClass self =>
ReadWriteAttr self [RadioAction] RadioAction
radioActionGroup = (self -> IO [RadioAction])
-> (self -> RadioAction -> IO ())
-> ReadWriteAttr self [RadioAction] RadioAction
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO [RadioAction]
forall self. RadioActionClass self => self -> IO [RadioAction]
radioActionGetGroup
  self -> RadioAction -> IO ()
forall self groupMember.
(RadioActionClass self, RadioActionClass groupMember) =>
self -> groupMember -> IO ()
radioActionSetGroup


-- %hash c:4cec d:1710
-- | The value property of the currently active member of the group to which
-- this action belongs.
--
-- Default value: 0
--
-- * Available since Gtk+ version 2.10
--
radioActionCurrentValue :: RadioActionClass self => Attr self Int
radioActionCurrentValue :: forall self. RadioActionClass self => Attr self Int
radioActionCurrentValue = String -> Attr self Int
forall gobj. GObjectClass gobj => String -> Attr gobj Int
newAttrFromIntProperty String
"current-value"


-- | The 'radioActionChanged' signal is emitted on every member of a radio group when the
-- active member is changed. The signal gets emitted after the 'actionActivated' signals for the
-- previous and current active members.
--
radioActionChanged :: RadioActionClass self => Signal self (RadioAction -> IO ())
radioActionChanged :: forall self.
RadioActionClass self =>
Signal self (RadioAction -> IO ())
radioActionChanged = (Bool -> self -> (RadioAction -> IO ()) -> IO (ConnectId self))
-> Signal self (RadioAction -> IO ())
forall object handler.
(Bool -> object -> handler -> IO (ConnectId object))
-> Signal object handler
Signal (String
-> Bool -> self -> (RadioAction -> IO ()) -> IO (ConnectId self)
forall a' obj.
(GObjectClass a', GObjectClass obj) =>
String -> Bool -> obj -> (a' -> IO ()) -> IO (ConnectId obj)
connect_OBJECT__NONE String
"changed")

--------------------
-- Deprecated Signals


-- | The changed signal is emitted on every member of a radio group when the
-- active member is changed. The signal gets emitted after the activate
-- signals for the previous and current active members.
--
onRadioActionChanged, afterRadioActionChanged :: RadioActionClass self => self
 -> (RadioAction -> IO ())
 -> IO (ConnectId self)
onRadioActionChanged :: forall self.
RadioActionClass self =>
self -> (RadioAction -> IO ()) -> IO (ConnectId self)
onRadioActionChanged = String
-> Bool -> self -> (RadioAction -> IO ()) -> IO (ConnectId self)
forall a' obj.
(GObjectClass a', GObjectClass obj) =>
String -> Bool -> obj -> (a' -> IO ()) -> IO (ConnectId obj)
connect_OBJECT__NONE String
"changed" Bool
False
afterRadioActionChanged :: forall self.
RadioActionClass self =>
self -> (RadioAction -> IO ()) -> IO (ConnectId self)
afterRadioActionChanged = String
-> Bool -> self -> (RadioAction -> IO ()) -> IO (ConnectId self)
forall a' obj.
(GObjectClass a', GObjectClass obj) =>
String -> Bool -> obj -> (a' -> IO ()) -> IO (ConnectId obj)
connect_OBJECT__NONE String
"changed" Bool
True

foreign import ccall safe "gtk_radio_action_new"
  gtk_radio_action_new :: ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> (CInt -> (IO (Ptr RadioAction)))))))

foreign import ccall unsafe "gtk_radio_action_get_group"
  gtk_radio_action_get_group :: ((Ptr RadioAction) -> (IO (Ptr ())))

foreign import ccall safe "gtk_radio_action_set_group"
  gtk_radio_action_set_group :: ((Ptr RadioAction) -> ((Ptr ()) -> (IO ())))

foreign import ccall safe "gtk_radio_action_get_current_value"
  gtk_radio_action_get_current_value :: ((Ptr RadioAction) -> (IO CInt))