{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

module GI.Gtk.Interfaces.ColorChooser
    ( 

-- * Exported types
    ColorChooser(..)                        ,
    noColorChooser                          ,
    ColorChooserK                           ,
    toColorChooser                          ,


 -- * Methods
-- ** colorChooserAddPalette
    colorChooserAddPalette                  ,


-- ** colorChooserGetRgba
    colorChooserGetRgba                     ,


-- ** colorChooserGetUseAlpha
    colorChooserGetUseAlpha                 ,


-- ** colorChooserSetRgba
    colorChooserSetRgba                     ,


-- ** colorChooserSetUseAlpha
    colorChooserSetUseAlpha                 ,




 -- * Properties
-- ** Rgba
    ColorChooserRgbaPropertyInfo            ,
    constructColorChooserRgba               ,
    getColorChooserRgba                     ,
    setColorChooserRgba                     ,


-- ** UseAlpha
    ColorChooserUseAlphaPropertyInfo        ,
    constructColorChooserUseAlpha           ,
    getColorChooserUseAlpha                 ,
    setColorChooserUseAlpha                 ,




 -- * Signals
-- ** ColorActivated
    ColorChooserColorActivatedCallback      ,
    ColorChooserColorActivatedCallbackC     ,
    ColorChooserColorActivatedSignalInfo    ,
    afterColorChooserColorActivated         ,
    colorChooserColorActivatedCallbackWrapper,
    colorChooserColorActivatedClosure       ,
    mkColorChooserColorActivatedCallback    ,
    noColorChooserColorActivatedCallback    ,
    onColorChooserColorActivated            ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Gtk.Types
import GI.Gtk.Callbacks
import qualified GI.GObject as GObject
import qualified GI.Gdk as Gdk

-- interface ColorChooser 

newtype ColorChooser = ColorChooser (ForeignPtr ColorChooser)
noColorChooser :: Maybe ColorChooser
noColorChooser = Nothing

-- signal ColorChooser::color-activated
type ColorChooserColorActivatedCallback =
    Gdk.RGBA ->
    IO ()

noColorChooserColorActivatedCallback :: Maybe ColorChooserColorActivatedCallback
noColorChooserColorActivatedCallback = Nothing

type ColorChooserColorActivatedCallbackC =
    Ptr () ->                               -- object
    Ptr Gdk.RGBA ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkColorChooserColorActivatedCallback :: ColorChooserColorActivatedCallbackC -> IO (FunPtr ColorChooserColorActivatedCallbackC)

colorChooserColorActivatedClosure :: ColorChooserColorActivatedCallback -> IO Closure
colorChooserColorActivatedClosure cb = newCClosure =<< mkColorChooserColorActivatedCallback wrapped
    where wrapped = colorChooserColorActivatedCallbackWrapper cb

colorChooserColorActivatedCallbackWrapper ::
    ColorChooserColorActivatedCallback ->
    Ptr () ->
    Ptr Gdk.RGBA ->
    Ptr () ->
    IO ()
colorChooserColorActivatedCallbackWrapper _cb _ color _ = do
    color' <- (newBoxed Gdk.RGBA) color
    _cb  color'

onColorChooserColorActivated :: (GObject a, MonadIO m) => a -> ColorChooserColorActivatedCallback -> m SignalHandlerId
onColorChooserColorActivated obj cb = liftIO $ connectColorChooserColorActivated obj cb SignalConnectBefore
afterColorChooserColorActivated :: (GObject a, MonadIO m) => a -> ColorChooserColorActivatedCallback -> m SignalHandlerId
afterColorChooserColorActivated obj cb = connectColorChooserColorActivated obj cb SignalConnectAfter

connectColorChooserColorActivated :: (GObject a, MonadIO m) =>
                                     a -> ColorChooserColorActivatedCallback -> SignalConnectMode -> m SignalHandlerId
connectColorChooserColorActivated obj cb after = liftIO $ do
    cb' <- mkColorChooserColorActivatedCallback (colorChooserColorActivatedCallbackWrapper cb)
    connectSignalFunPtr obj "color-activated" cb' after

-- VVV Prop "rgba"
   -- Type: TInterface "Gdk" "RGBA"
   -- Flags: [PropertyReadable,PropertyWritable]

getColorChooserRgba :: (MonadIO m, ColorChooserK o) => o -> m Gdk.RGBA
getColorChooserRgba obj = liftIO $ getObjectPropertyBoxed obj "rgba" Gdk.RGBA

setColorChooserRgba :: (MonadIO m, ColorChooserK o) => o -> Gdk.RGBA -> m ()
setColorChooserRgba obj val = liftIO $ setObjectPropertyBoxed obj "rgba" val

constructColorChooserRgba :: Gdk.RGBA -> IO ([Char], GValue)
constructColorChooserRgba val = constructObjectPropertyBoxed "rgba" val

data ColorChooserRgbaPropertyInfo
instance AttrInfo ColorChooserRgbaPropertyInfo where
    type AttrAllowedOps ColorChooserRgbaPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint ColorChooserRgbaPropertyInfo = (~) Gdk.RGBA
    type AttrBaseTypeConstraint ColorChooserRgbaPropertyInfo = ColorChooserK
    type AttrGetType ColorChooserRgbaPropertyInfo = Gdk.RGBA
    type AttrLabel ColorChooserRgbaPropertyInfo = "ColorChooser::rgba"
    attrGet _ = getColorChooserRgba
    attrSet _ = setColorChooserRgba
    attrConstruct _ = constructColorChooserRgba

-- VVV Prop "use-alpha"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable,PropertyWritable]

getColorChooserUseAlpha :: (MonadIO m, ColorChooserK o) => o -> m Bool
getColorChooserUseAlpha obj = liftIO $ getObjectPropertyBool obj "use-alpha"

setColorChooserUseAlpha :: (MonadIO m, ColorChooserK o) => o -> Bool -> m ()
setColorChooserUseAlpha obj val = liftIO $ setObjectPropertyBool obj "use-alpha" val

constructColorChooserUseAlpha :: Bool -> IO ([Char], GValue)
constructColorChooserUseAlpha val = constructObjectPropertyBool "use-alpha" val

data ColorChooserUseAlphaPropertyInfo
instance AttrInfo ColorChooserUseAlphaPropertyInfo where
    type AttrAllowedOps ColorChooserUseAlphaPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint ColorChooserUseAlphaPropertyInfo = (~) Bool
    type AttrBaseTypeConstraint ColorChooserUseAlphaPropertyInfo = ColorChooserK
    type AttrGetType ColorChooserUseAlphaPropertyInfo = Bool
    type AttrLabel ColorChooserUseAlphaPropertyInfo = "ColorChooser::use-alpha"
    attrGet _ = getColorChooserUseAlpha
    attrSet _ = setColorChooserUseAlpha
    attrConstruct _ = constructColorChooserUseAlpha

type instance AttributeList ColorChooser = ColorChooserAttributeList
type ColorChooserAttributeList = ('[ '("rgba", ColorChooserRgbaPropertyInfo), '("use-alpha", ColorChooserUseAlphaPropertyInfo)] :: [(Symbol, *)])

data ColorChooserColorActivatedSignalInfo
instance SignalInfo ColorChooserColorActivatedSignalInfo where
    type HaskellCallbackType ColorChooserColorActivatedSignalInfo = ColorChooserColorActivatedCallback
    connectSignal _ = connectColorChooserColorActivated

type instance SignalList ColorChooser = ColorChooserSignalList
type ColorChooserSignalList = ('[ '("color-activated", ColorChooserColorActivatedSignalInfo), '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

foreign import ccall "gtk_color_chooser_get_type"
    c_gtk_color_chooser_get_type :: IO GType

type instance ParentTypes ColorChooser = ColorChooserParentTypes
type ColorChooserParentTypes = '[GObject.Object]

instance GObject ColorChooser where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_gtk_color_chooser_get_type
    

class GObject o => ColorChooserK o
instance (GObject o, IsDescendantOf ColorChooser o) => ColorChooserK o

toColorChooser :: ColorChooserK o => o -> IO ColorChooser
toColorChooser = unsafeCastTo ColorChooser

-- method ColorChooser::add_palette
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "orientation", argType = TInterface "Gtk" "Orientation", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "colors_per_line", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "n_colors", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "colors", argType = TCArray False (-1) 3 (TInterface "Gdk" "RGBA"), direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : [Arg {argName = "n_colors", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "orientation", argType = TInterface "Gtk" "Orientation", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "colors_per_line", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "colors", argType = TCArray False (-1) 3 (TInterface "Gdk" "RGBA"), direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_color_chooser_add_palette" gtk_color_chooser_add_palette :: 
    Ptr ColorChooser ->                     -- _obj : TInterface "Gtk" "ColorChooser"
    CUInt ->                                -- orientation : TInterface "Gtk" "Orientation"
    Int32 ->                                -- colors_per_line : TBasicType TInt32
    Int32 ->                                -- n_colors : TBasicType TInt32
    Ptr Gdk.RGBA ->                         -- colors : TCArray False (-1) 3 (TInterface "Gdk" "RGBA")
    IO ()


colorChooserAddPalette ::
    (MonadIO m, ColorChooserK a) =>
    a ->                                    -- _obj
    Orientation ->                          -- orientation
    Int32 ->                                -- colors_per_line
    Maybe ([Gdk.RGBA]) ->                   -- colors
    m ()
colorChooserAddPalette _obj orientation colors_per_line colors = liftIO $ do
    let n_colors = case colors of
            Nothing -> 0
            Just jColors -> fromIntegral $ length jColors
    let _obj' = unsafeManagedPtrCastPtr _obj
    let orientation' = (fromIntegral . fromEnum) orientation
    maybeColors <- case colors of
        Nothing -> return nullPtr
        Just jColors -> do
            let jColors' = map unsafeManagedPtrGetPtr jColors
            jColors'' <- packBlockArray 32 jColors'
            return jColors''
    gtk_color_chooser_add_palette _obj' orientation' colors_per_line n_colors maybeColors
    touchManagedPtr _obj
    whenJust colors (mapM_ touchManagedPtr)
    freeMem maybeColors
    return ()

-- method ColorChooser::get_rgba
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "color", argType = TInterface "Gdk" "RGBA", direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_color_chooser_get_rgba" gtk_color_chooser_get_rgba :: 
    Ptr ColorChooser ->                     -- _obj : TInterface "Gtk" "ColorChooser"
    Ptr Gdk.RGBA ->                         -- color : TInterface "Gdk" "RGBA"
    IO ()


colorChooserGetRgba ::
    (MonadIO m, ColorChooserK a) =>
    a ->                                    -- _obj
    m (Gdk.RGBA)
colorChooserGetRgba _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    color <- callocBoxedBytes 32 :: IO (Ptr Gdk.RGBA)
    gtk_color_chooser_get_rgba _obj' color
    color' <- (wrapBoxed Gdk.RGBA) color
    touchManagedPtr _obj
    return color'

-- method ColorChooser::get_use_alpha
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "gtk_color_chooser_get_use_alpha" gtk_color_chooser_get_use_alpha :: 
    Ptr ColorChooser ->                     -- _obj : TInterface "Gtk" "ColorChooser"
    IO CInt


colorChooserGetUseAlpha ::
    (MonadIO m, ColorChooserK a) =>
    a ->                                    -- _obj
    m Bool
colorChooserGetUseAlpha _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- gtk_color_chooser_get_use_alpha _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

-- method ColorChooser::set_rgba
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "color", argType = TInterface "Gdk" "RGBA", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "color", argType = TInterface "Gdk" "RGBA", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_color_chooser_set_rgba" gtk_color_chooser_set_rgba :: 
    Ptr ColorChooser ->                     -- _obj : TInterface "Gtk" "ColorChooser"
    Ptr Gdk.RGBA ->                         -- color : TInterface "Gdk" "RGBA"
    IO ()


colorChooserSetRgba ::
    (MonadIO m, ColorChooserK a) =>
    a ->                                    -- _obj
    Gdk.RGBA ->                             -- color
    m ()
colorChooserSetRgba _obj color = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let color' = unsafeManagedPtrGetPtr color
    gtk_color_chooser_set_rgba _obj' color'
    touchManagedPtr _obj
    touchManagedPtr color
    return ()

-- method ColorChooser::set_use_alpha
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "use_alpha", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "ColorChooser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "use_alpha", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_color_chooser_set_use_alpha" gtk_color_chooser_set_use_alpha :: 
    Ptr ColorChooser ->                     -- _obj : TInterface "Gtk" "ColorChooser"
    CInt ->                                 -- use_alpha : TBasicType TBoolean
    IO ()


colorChooserSetUseAlpha ::
    (MonadIO m, ColorChooserK a) =>
    a ->                                    -- _obj
    Bool ->                                 -- use_alpha
    m ()
colorChooserSetUseAlpha _obj use_alpha = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let use_alpha' = (fromIntegral . fromEnum) use_alpha
    gtk_color_chooser_set_use_alpha _obj' use_alpha'
    touchManagedPtr _obj
    return ()