{-# LINE 2 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widgets Switch
--
-- Author : Warlock <internalmike@gmail.com>
--
-- Created: 10 November 2017
--
-- Copyright (C) 2017 Warlock
--
-- 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)
--
-- A "light switch" style toggle
--
module Graphics.UI.Gtk.Misc.Switch (
-- * Detail
--
-- [...]
--
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Switch'
-- @

-- * Types

    Switch
  , castToSwitch
  , gTypeSwitch
  , toSwitch

-- * Constructors
  , switchNew

-- * Methods
  , switchSetActive
  , switchGetActive

  , switchSetState
  , switchGetState


-- * Attributes
  , switchActive

  , switchState


-- * Signals
  , switchActivate

  , stateSet


) where



import Control.Monad (liftM)

import System.Glib.FFI
import System.Glib.Attributes
import System.Glib.Properties
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
import Graphics.UI.Gtk.Types
{-# LINE 83 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}
import Graphics.UI.Gtk.Signals
{-# LINE 84 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}


{-# LINE 86 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}

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

-- | Creates a new 'Switch'.
--
switchNew :: IO Switch
switchNew :: IO Switch
switchNew =
  (ForeignPtr Switch -> Switch, FinalizerPtr Switch)
-> IO (Ptr Switch) -> IO Switch
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr Switch -> Switch, FinalizerPtr Switch)
forall {a}. (ForeignPtr Switch -> Switch, FinalizerPtr a)
mkSwitch (IO (Ptr Switch) -> IO Switch) -> IO (Ptr Switch) -> IO Switch
forall a b. (a -> b) -> a -> b
$
  (Ptr Widget -> Ptr Switch) -> IO (Ptr Widget) -> IO (Ptr Switch)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Ptr Widget -> Ptr Switch
forall a b. Ptr a -> Ptr b
castPtr :: Ptr Widget -> Ptr Switch) (IO (Ptr Widget) -> IO (Ptr Switch))
-> IO (Ptr Widget) -> IO (Ptr Switch)
forall a b. (a -> b) -> a -> b
$
  IO (Ptr Widget)
gtk_switch_new
{-# LINE 97 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}

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

-- | Changes the state of control to the desired one.
-- See 'switchGetActive'.
switchSetActive :: SwitchClass self => self
 -> Bool
 -> IO ()
switchSetActive :: forall self. SwitchClass self => self -> Bool -> IO ()
switchSetActive self
self Bool
is_active =
  (\(Switch ForeignPtr Switch
arg1) CInt
arg2 -> ForeignPtr Switch -> (Ptr Switch -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Switch
arg1 ((Ptr Switch -> IO ()) -> IO ()) -> (Ptr Switch -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Switch
argPtr1 ->Ptr Switch -> CInt -> IO ()
gtk_switch_set_active Ptr Switch
argPtr1 CInt
arg2)
{-# LINE 108 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}
    (toSwitch self)
    (Bool -> CInt
forall a. Num a => Bool -> a
fromBool Bool
is_active)

-- | Gets whether the GtkSwitch is in its on or off state.
switchGetActive :: SwitchClass self => self
 -> IO Bool
switchGetActive :: forall self. SwitchClass self => self -> IO Bool
switchGetActive self
self =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
  (\(Switch ForeignPtr Switch
arg1) -> ForeignPtr Switch -> (Ptr Switch -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Switch
arg1 ((Ptr Switch -> IO CInt) -> IO CInt)
-> (Ptr Switch -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Switch
argPtr1 ->Ptr Switch -> IO CInt
gtk_switch_get_active Ptr Switch
argPtr1)
{-# LINE 117 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}
    (toSwitch self)


-- | Sets the underlying state of the GtkSwitch.
-- Normally, this is the same as 'switchActive', unless the switch is set up for
-- delayed state changes. This function is typically called
-- from a 'stateSet' signal handler.
--
-- See 'stateSet' for details.
switchSetState :: SwitchClass self => self
 -> Bool
 -> IO ()
switchSetState :: forall self. SwitchClass self => self -> Bool -> IO ()
switchSetState self
self Bool
state =
  (\(Switch ForeignPtr Switch
arg1) CInt
arg2 -> ForeignPtr Switch -> (Ptr Switch -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Switch
arg1 ((Ptr Switch -> IO ()) -> IO ()) -> (Ptr Switch -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Switch
argPtr1 ->Ptr Switch -> CInt -> IO ()
gtk_switch_set_state Ptr Switch
argPtr1 CInt
arg2)
{-# LINE 131 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}
    (toSwitch self)
    (Bool -> CInt
forall a. Num a => Bool -> a
fromBool Bool
state)

-- | Gets the underlying state of the GtkSwitch.
-- Set 'switchSetState'.
switchGetState :: SwitchClass self => self
 -> IO Bool
switchGetState :: forall self. SwitchClass self => self -> IO Bool
switchGetState self
self =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
  (\(Switch ForeignPtr Switch
arg1) -> ForeignPtr Switch -> (Ptr Switch -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Switch
arg1 ((Ptr Switch -> IO CInt) -> IO CInt)
-> (Ptr Switch -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Switch
argPtr1 ->Ptr Switch -> IO CInt
gtk_switch_get_state Ptr Switch
argPtr1)
{-# LINE 141 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}
    (toSwitch self)


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

-- | Whether the switch is in its on or off state.
--
-- Default value: @False@
--
switchActive :: SwitchClass self => Attr self Bool
switchActive :: forall self. SwitchClass self => Attr self Bool
switchActive = (self -> IO Bool)
-> (self -> Bool -> IO ()) -> ReadWriteAttr self Bool Bool
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Bool
forall self. SwitchClass self => self -> IO Bool
switchGetActive
  self -> Bool -> IO ()
forall self. SwitchClass self => self -> Bool -> IO ()
switchSetActive


-- | The backend state that is controlled by the switch. See 'stateSet' for details.
--
-- Default value: @False@
--
switchState :: SwitchClass self => Attr self Bool
switchState :: forall self. SwitchClass self => Attr self Bool
switchState = (self -> IO Bool)
-> (self -> Bool -> IO ()) -> ReadWriteAttr self Bool Bool
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Bool
forall self. SwitchClass self => self -> IO Bool
switchGetState
  self -> Bool -> IO ()
forall self. SwitchClass self => self -> Bool -> IO ()
switchSetState


--------------------
-- Signals


-- | This signal on GtkSwitch is an action signal and emitting it causes
-- the switch to animate. Applications should never connect to this signal,
-- but use the notify::active signal.
--
switchActivate :: SwitchClass self => Signal self (IO ())
switchActivate :: forall self. SwitchClass self => Signal self (IO ())
switchActivate = (Bool -> self -> IO () -> IO (ConnectId self))
-> Signal self (IO ())
forall object handler.
(Bool -> object -> handler -> IO (ConnectId object))
-> Signal object handler
Signal (SignalName -> Bool -> self -> IO () -> IO (ConnectId self)
forall obj.
GObjectClass obj =>
SignalName -> Bool -> obj -> IO () -> IO (ConnectId obj)
connect_NONE__NONE SignalName
"activate")


-- | This signal on GtkSwitch is emitted to change the underlying state.
-- It is emitted when the user changes the switch position.
-- The default handler keeps the state in sync with the 'switchActive' property.
--
-- To implement delayed state change, applications can connect to this signal,
-- initiate the change of the underlying state, and call 'switchSetState'
-- when the underlying state change is complete.
-- The signal handler should return @True@ to prevent the default handler from running.
--
-- Visually, the underlying state is represented by the through color of the switch,
-- while the 'switchActive' property is represented by the position of the switch.
--
stateSet :: SwitchClass self => Signal self (Bool -> IO Bool)
stateSet :: forall self. SwitchClass self => Signal self (Bool -> IO Bool)
stateSet = (Bool -> self -> (Bool -> IO Bool) -> IO (ConnectId self))
-> Signal self (Bool -> IO Bool)
forall object handler.
(Bool -> object -> handler -> IO (ConnectId object))
-> Signal object handler
Signal (SignalName
-> Bool -> self -> (Bool -> IO Bool) -> IO (ConnectId self)
forall obj.
GObjectClass obj =>
SignalName
-> Bool -> obj -> (Bool -> IO Bool) -> IO (ConnectId obj)
connect_BOOL__BOOL SignalName
"state-set")

foreign import ccall unsafe "gtk_switch_new"
  gtk_switch_new :: (IO (Ptr Widget))

foreign import ccall safe "gtk_switch_set_active"
  gtk_switch_set_active :: ((Ptr Switch) -> (CInt -> (IO ())))

foreign import ccall safe "gtk_switch_get_active"
  gtk_switch_get_active :: ((Ptr Switch) -> (IO CInt))

foreign import ccall safe "gtk_switch_set_state"
  gtk_switch_set_state :: ((Ptr Switch) -> (CInt -> (IO ())))

foreign import ccall safe "gtk_switch_get_state"
  gtk_switch_get_state :: ((Ptr Switch) -> (IO CInt))