{-# LINE 2 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget ColorButton
--
-- Author : Duncan Coutts
--
-- Created: 5 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.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- A button to launch a color selection dialog
--
-- * Module available since Gtk+ version 2.4
--
module Graphics.UI.Gtk.Selectors.ColorButton (
-- * Detail
--
-- | The 'ColorButton' is a button which displays the currently selected color
-- an allows to open a color selection dialog to change the color. It is
-- suitable widget for selecting a color in a preference dialog.

-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Container'
-- | +----'Bin'
-- | +----'Button'
-- | +----ColorButton
-- @


-- * Types
  ColorButton,
  ColorButtonClass,
  castToColorButton, gTypeColorButton,
  toColorButton,

-- * Constructors
  colorButtonNew,
  colorButtonNewWithColor,

-- * Methods
  colorButtonSetColor,
  colorButtonGetColor,
  colorButtonSetAlpha,
  colorButtonGetAlpha,
  colorButtonSetUseAlpha,
  colorButtonGetUseAlpha,
  colorButtonSetTitle,
  colorButtonGetTitle,

-- * Attributes
  colorButtonUseAlpha,
  colorButtonTitle,
  colorButtonAlpha,

-- * Signals
  onColorSet,
  afterColorSet,

  ) where

import Control.Monad (liftM)

import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Attributes
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
import Graphics.UI.Gtk.Types
{-# LINE 88 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
import Graphics.UI.Gtk.Signals
{-# LINE 89 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
import Graphics.UI.Gtk.General.Structs (Color)


{-# LINE 92 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}


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

-- | Creates a new color button. This returns a widget in the form of a small
-- button containing a swatch representing the current selected color. When the
-- button is clicked, a color-selection dialog will open, allowing the user to
-- select a color. The swatch will be updated to reflect the new color when the
-- user finishes.
--
colorButtonNew :: IO ColorButton
colorButtonNew :: IO ColorButton
colorButtonNew =
  (ForeignPtr ColorButton -> ColorButton, FinalizerPtr ColorButton)
-> IO (Ptr ColorButton) -> IO ColorButton
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr ColorButton -> ColorButton, FinalizerPtr ColorButton)
forall {a}. (ForeignPtr ColorButton -> ColorButton, FinalizerPtr a)
mkColorButton (IO (Ptr ColorButton) -> IO ColorButton)
-> IO (Ptr ColorButton) -> IO ColorButton
forall a b. (a -> b) -> a -> b
$
  (Ptr Widget -> Ptr ColorButton)
-> IO (Ptr Widget) -> IO (Ptr ColorButton)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Ptr Widget -> Ptr ColorButton
forall a b. Ptr a -> Ptr b
castPtr :: Ptr Widget -> Ptr ColorButton) (IO (Ptr Widget) -> IO (Ptr ColorButton))
-> IO (Ptr Widget) -> IO (Ptr ColorButton)
forall a b. (a -> b) -> a -> b
$
  IO (Ptr Widget)
gtk_color_button_new
{-# LINE 108 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}

-- | Creates a new color button.
--
colorButtonNewWithColor ::
    Color -- ^ @color@ - A 'Color' to set the current color with.
 -> IO ColorButton
colorButtonNewWithColor :: Color -> IO ColorButton
colorButtonNewWithColor Color
color =
  (ForeignPtr ColorButton -> ColorButton, FinalizerPtr ColorButton)
-> IO (Ptr ColorButton) -> IO ColorButton
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr ColorButton -> ColorButton, FinalizerPtr ColorButton)
forall {a}. (ForeignPtr ColorButton -> ColorButton, FinalizerPtr a)
mkColorButton (IO (Ptr ColorButton) -> IO ColorButton)
-> IO (Ptr ColorButton) -> IO ColorButton
forall a b. (a -> b) -> a -> b
$
  (Ptr Widget -> Ptr ColorButton)
-> IO (Ptr Widget) -> IO (Ptr ColorButton)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Ptr Widget -> Ptr ColorButton
forall a b. Ptr a -> Ptr b
castPtr :: Ptr Widget -> Ptr ColorButton) (IO (Ptr Widget) -> IO (Ptr ColorButton))
-> IO (Ptr Widget) -> IO (Ptr ColorButton)
forall a b. (a -> b) -> a -> b
$
  Color -> (Ptr Color -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Color
color ((Ptr Color -> IO (Ptr Widget)) -> IO (Ptr Widget))
-> (Ptr Color -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. (a -> b) -> a -> b
$ \Ptr Color
colorPtr ->
  Ptr () -> IO (Ptr Widget)
gtk_color_button_new_with_color
{-# LINE 119 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (castPtr colorPtr)

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

-- | Sets the current color to be @color@.
--
colorButtonSetColor :: ColorButtonClass self => self
 -> Color -- ^ @color@ - A 'Color' to set the current color with.
 -> IO ()
colorButtonSetColor :: forall self. ColorButtonClass self => self -> Color -> IO ()
colorButtonSetColor self
self Color
color =
  Color -> (Ptr Color -> IO ()) -> IO ()
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Color
color ((Ptr Color -> IO ()) -> IO ()) -> (Ptr Color -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Color
colorPtr ->
  (\(ColorButton ForeignPtr ColorButton
arg1) Ptr ()
arg2 -> ForeignPtr ColorButton -> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ColorButton
arg1 ((Ptr ColorButton -> IO ()) -> IO ())
-> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr ColorButton
argPtr1 ->Ptr ColorButton -> Ptr () -> IO ()
gtk_color_button_set_color Ptr ColorButton
argPtr1 Ptr ()
arg2)
{-# LINE 132 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (toColorButton self)
    (Ptr Color -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr Color
colorPtr)

-- | Returns the current color value.
--
colorButtonGetColor :: ColorButtonClass self => self -> IO Color
colorButtonGetColor :: forall self. ColorButtonClass self => self -> IO Color
colorButtonGetColor self
self =
  (Ptr Color -> IO Color) -> IO Color
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Color -> IO Color) -> IO Color)
-> (Ptr Color -> IO Color) -> IO Color
forall a b. (a -> b) -> a -> b
$ \Ptr Color
colorPtr ->
  (\(ColorButton ForeignPtr ColorButton
arg1) Ptr ()
arg2 -> ForeignPtr ColorButton -> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ColorButton
arg1 ((Ptr ColorButton -> IO ()) -> IO ())
-> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr ColorButton
argPtr1 ->Ptr ColorButton -> Ptr () -> IO ()
gtk_color_button_get_color Ptr ColorButton
argPtr1 Ptr ()
arg2)
{-# LINE 141 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (toColorButton self)
    (Ptr Color -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr Color
colorPtr)
  IO () -> IO Color -> IO Color
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr Color -> IO Color
forall a. Storable a => Ptr a -> IO a
peek Ptr Color
colorPtr IO Color -> (Color -> IO Color) -> IO Color
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Color
color ->
  Color -> IO Color
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Color
color

-- | Sets the current opacity to be @alpha@.
--
colorButtonSetAlpha :: ColorButtonClass self => self
 -> Word16 -- ^ @alpha@ - an integer between 0 and 65535.
 -> IO ()
colorButtonSetAlpha :: forall self. ColorButtonClass self => self -> Word16 -> IO ()
colorButtonSetAlpha self
self Word16
alpha =
  (\(ColorButton ForeignPtr ColorButton
arg1) CUShort
arg2 -> ForeignPtr ColorButton -> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ColorButton
arg1 ((Ptr ColorButton -> IO ()) -> IO ())
-> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr ColorButton
argPtr1 ->Ptr ColorButton -> CUShort -> IO ()
gtk_color_button_set_alpha Ptr ColorButton
argPtr1 CUShort
arg2)
{-# LINE 153 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (toColorButton self)
    (Word16 -> CUShort
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
alpha)

-- | Returns the current alpha value.
--
colorButtonGetAlpha :: ColorButtonClass self => self
 -> IO Word16 -- ^ returns an integer between 0 and 65535.
colorButtonGetAlpha :: forall self. ColorButtonClass self => self -> IO Word16
colorButtonGetAlpha self
self =
  (CUShort -> Word16) -> IO CUShort -> IO Word16
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CUShort -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (IO CUShort -> IO Word16) -> IO CUShort -> IO Word16
forall a b. (a -> b) -> a -> b
$
  (\(ColorButton ForeignPtr ColorButton
arg1) -> ForeignPtr ColorButton
-> (Ptr ColorButton -> IO CUShort) -> IO CUShort
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ColorButton
arg1 ((Ptr ColorButton -> IO CUShort) -> IO CUShort)
-> (Ptr ColorButton -> IO CUShort) -> IO CUShort
forall a b. (a -> b) -> a -> b
$ \Ptr ColorButton
argPtr1 ->Ptr ColorButton -> IO CUShort
gtk_color_button_get_alpha Ptr ColorButton
argPtr1)
{-# LINE 163 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (toColorButton self)

-- | Sets whether or not the color button should use the alpha channel.
--
colorButtonSetUseAlpha :: ColorButtonClass self => self
 -> Bool -- ^ @useAlpha@ - @True@ if color button should use alpha channel,
          -- @False@ if not.
 -> IO ()
colorButtonSetUseAlpha :: forall self. ColorButtonClass self => self -> Bool -> IO ()
colorButtonSetUseAlpha self
self Bool
useAlpha =
  (\(ColorButton ForeignPtr ColorButton
arg1) CInt
arg2 -> ForeignPtr ColorButton -> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ColorButton
arg1 ((Ptr ColorButton -> IO ()) -> IO ())
-> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr ColorButton
argPtr1 ->Ptr ColorButton -> CInt -> IO ()
gtk_color_button_set_use_alpha Ptr ColorButton
argPtr1 CInt
arg2)
{-# LINE 173 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (toColorButton self)
    (Bool -> CInt
forall a. Num a => Bool -> a
fromBool Bool
useAlpha)

-- | Does the color selection dialog use the alpha channel?
--
colorButtonGetUseAlpha :: ColorButtonClass self => self
 -> IO Bool -- ^ returns @True@ if the color sample uses alpha channel,
            -- @False@ if not.
colorButtonGetUseAlpha :: forall self. ColorButtonClass self => self -> IO Bool
colorButtonGetUseAlpha 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
$
  (\(ColorButton ForeignPtr ColorButton
arg1) -> ForeignPtr ColorButton -> (Ptr ColorButton -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ColorButton
arg1 ((Ptr ColorButton -> IO CInt) -> IO CInt)
-> (Ptr ColorButton -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr ColorButton
argPtr1 ->Ptr ColorButton -> IO CInt
gtk_color_button_get_use_alpha Ptr ColorButton
argPtr1)
{-# LINE 184 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (toColorButton self)

-- | Sets the title for the color selection dialog.
--
colorButtonSetTitle :: (ColorButtonClass self, GlibString string) => self
 -> string -- ^ @title@ - String containing new window title.
 -> IO ()
colorButtonSetTitle :: forall self string.
(ColorButtonClass self, GlibString string) =>
self -> string -> IO ()
colorButtonSetTitle self
self string
title =
  string -> (CString -> IO ()) -> IO ()
forall a. string -> (CString -> IO a) -> IO a
forall s a. GlibString s => s -> (CString -> IO a) -> IO a
withUTFString string
title ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
titlePtr ->
  (\(ColorButton ForeignPtr ColorButton
arg1) CString
arg2 -> ForeignPtr ColorButton -> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ColorButton
arg1 ((Ptr ColorButton -> IO ()) -> IO ())
-> (Ptr ColorButton -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr ColorButton
argPtr1 ->Ptr ColorButton -> CString -> IO ()
gtk_color_button_set_title Ptr ColorButton
argPtr1 CString
arg2)
{-# LINE 194 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (toColorButton self)
    CString
titlePtr

-- | Gets the title of the color selection dialog.
--
colorButtonGetTitle :: (ColorButtonClass self, GlibString string) => self
 -> IO string -- ^ returns An internal string, do not free the return value
colorButtonGetTitle :: forall self string.
(ColorButtonClass self, GlibString string) =>
self -> IO string
colorButtonGetTitle self
self =
  (\(ColorButton ForeignPtr ColorButton
arg1) -> ForeignPtr ColorButton
-> (Ptr ColorButton -> IO CString) -> IO CString
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ColorButton
arg1 ((Ptr ColorButton -> IO CString) -> IO CString)
-> (Ptr ColorButton -> IO CString) -> IO CString
forall a b. (a -> b) -> a -> b
$ \Ptr ColorButton
argPtr1 ->Ptr ColorButton -> IO CString
gtk_color_button_get_title Ptr ColorButton
argPtr1)
{-# LINE 203 "./Graphics/UI/Gtk/Selectors/ColorButton.chs" #-}
    (toColorButton self)
  IO CString -> (CString -> IO string) -> IO string
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CString -> IO string
forall s. GlibString s => CString -> IO s
peekUTFString

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

-- | If this property is set to @True@, the color swatch on the button is
-- rendered against a checkerboard background to show its opacity and the
-- opacity slider is displayed in the color selection dialog.
--
-- Default value: @False@
--
colorButtonUseAlpha :: ColorButtonClass self => Attr self Bool
colorButtonUseAlpha :: forall self. ColorButtonClass self => Attr self Bool
colorButtonUseAlpha = (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. ColorButtonClass self => self -> IO Bool
colorButtonGetUseAlpha
  self -> Bool -> IO ()
forall self. ColorButtonClass self => self -> Bool -> IO ()
colorButtonSetUseAlpha

-- | The title of the color selection dialog
--
-- Default value: \"Pick a Color\"
--
colorButtonTitle :: (ColorButtonClass self, GlibString string) => Attr self string
colorButtonTitle :: forall self string.
(ColorButtonClass self, GlibString string) =>
Attr self string
colorButtonTitle = (self -> IO string)
-> (self -> string -> IO ()) -> ReadWriteAttr self string string
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO string
forall self string.
(ColorButtonClass self, GlibString string) =>
self -> IO string
colorButtonGetTitle
  self -> string -> IO ()
forall self string.
(ColorButtonClass self, GlibString string) =>
self -> string -> IO ()
colorButtonSetTitle

-- | The selected opacity value (0 fully transparent, 65535 fully opaque).
--
-- Allowed values: \<= 65535
--
-- Default value: 65535
--
colorButtonAlpha :: ColorButtonClass self => Attr self Word16
colorButtonAlpha :: forall self. ColorButtonClass self => Attr self Word16
colorButtonAlpha = (self -> IO Word16)
-> (self -> Word16 -> IO ()) -> ReadWriteAttr self Word16 Word16
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Word16
forall self. ColorButtonClass self => self -> IO Word16
colorButtonGetAlpha
  self -> Word16 -> IO ()
forall self. ColorButtonClass self => self -> Word16 -> IO ()
colorButtonSetAlpha

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

-- | The 'colorSet' signal is emitted when the user selects a color. When
-- handling this signal, use 'colorButtonGetColor' and 'colorButtonGetAlpha' to
-- find out which color was just selected.
--
onColorSet, afterColorSet :: ColorButtonClass self => self
 -> IO ()
 -> IO (ConnectId self)
onColorSet :: forall self.
ColorButtonClass self =>
self -> IO () -> IO (ConnectId self)
onColorSet = SignalName -> Bool -> self -> IO () -> IO (ConnectId self)
forall obj.
GObjectClass obj =>
SignalName -> Bool -> obj -> IO () -> IO (ConnectId obj)
connect_NONE__NONE SignalName
"color_set" Bool
False
afterColorSet :: forall self.
ColorButtonClass self =>
self -> IO () -> IO (ConnectId self)
afterColorSet = SignalName -> Bool -> self -> IO () -> IO (ConnectId self)
forall obj.
GObjectClass obj =>
SignalName -> Bool -> obj -> IO () -> IO (ConnectId obj)
connect_NONE__NONE SignalName
"color_set" Bool
True

foreign import ccall safe "gtk_color_button_new"
  gtk_color_button_new :: (IO (Ptr Widget))

foreign import ccall safe "gtk_color_button_new_with_color"
  gtk_color_button_new_with_color :: ((Ptr ()) -> (IO (Ptr Widget)))

foreign import ccall safe "gtk_color_button_set_color"
  gtk_color_button_set_color :: ((Ptr ColorButton) -> ((Ptr ()) -> (IO ())))

foreign import ccall safe "gtk_color_button_get_color"
  gtk_color_button_get_color :: ((Ptr ColorButton) -> ((Ptr ()) -> (IO ())))

foreign import ccall safe "gtk_color_button_set_alpha"
  gtk_color_button_set_alpha :: ((Ptr ColorButton) -> (CUShort -> (IO ())))

foreign import ccall safe "gtk_color_button_get_alpha"
  gtk_color_button_get_alpha :: ((Ptr ColorButton) -> (IO CUShort))

foreign import ccall safe "gtk_color_button_set_use_alpha"
  gtk_color_button_set_use_alpha :: ((Ptr ColorButton) -> (CInt -> (IO ())))

foreign import ccall safe "gtk_color_button_get_use_alpha"
  gtk_color_button_get_use_alpha :: ((Ptr ColorButton) -> (IO CInt))

foreign import ccall safe "gtk_color_button_set_title"
  gtk_color_button_set_title :: ((Ptr ColorButton) -> ((Ptr CChar) -> (IO ())))

foreign import ccall safe "gtk_color_button_get_title"
  gtk_color_button_get_title :: ((Ptr ColorButton) -> (IO (Ptr CChar)))