{-# 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 =
  makeNewObject mkSwitch $
  liftM (castPtr :: Ptr Widget -> Ptr Switch) $
  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 self is_active =
  (\(Switch arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_switch_set_active argPtr1 arg2)
{-# LINE 108 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}
    (toSwitch self)
    (fromBool is_active)

-- | Gets whether the GtkSwitch is in its on or off state.
switchGetActive :: SwitchClass self => self
 -> IO Bool
switchGetActive self =
  liftM toBool $
  (\(Switch arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_switch_get_active 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 self state =
  (\(Switch arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_switch_set_state argPtr1 arg2)
{-# LINE 131 "./Graphics/UI/Gtk/Misc/Switch.chs" #-}
    (toSwitch self)
    (fromBool state)

-- | Gets the underlying state of the GtkSwitch.
-- Set 'switchSetState'.
switchGetState :: SwitchClass self => self
 -> IO Bool
switchGetState self =
  liftM toBool $
  (\(Switch arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_switch_get_state 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 = newAttr
  switchGetActive
  switchSetActive


-- | The backend state that is controlled by the switch. See 'stateSet' for details.
--
-- Default value: @False@
--
switchState :: SwitchClass self => Attr self Bool
switchState = newAttr
  switchGetState
  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 = Signal (connect_NONE__NONE "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 trough 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 = Signal (connect_BOOL__BOOL "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))