{-# LINE 2 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Styles
--
-- Author : Axel Simon
--
-- Created: 13 February 2003
--
-- Copyright (C) 1999-2005 Axel Simon
--
-- 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)
--
-- CSS-like styling for widgets.
--
module Graphics.UI.Gtk.General.CssProvider (
-- * Description
--
-- | @CssProvider@ is an object implementing the @StyleProvider@ interface.
-- It is able to parse CSS-like input in order to style widgets.
--


-- * Types
  CssProvider,
  CssProviderClass,
  castToCssProvider, gTypeCssProvider,
  toCssProvider,

-- * Enums
  CssProviderError(..),

-- * Constructors
  cssProviderNew,

-- * Methods
  cssProviderGetDefault,
  cssProviderGetNamed,
  cssProviderLoadFromData,
  cssProviderLoadFromString,
  cssProviderLoadFromPath,

  cssProviderToString,



  ) where



{-# LINE 63 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}

import System.Glib.FFI
import System.Glib.UTFString
import Graphics.UI.Gtk.Types
{-# LINE 67 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}
import System.Glib.GError (propagateGError)

data CssProviderError = CssProviderErrorFailed
                      | CssProviderErrorSyntax
                      | CssProviderErrorImport
                      | CssProviderErrorName
                      | CssProviderErrorDeprecated
                      | CssProviderErrorUnknownValue
                      deriving (Enum,Bounded,Eq,Show)

{-# LINE 70 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}

--------------------
-- Interfaces

instance StyleProviderClass CssProvider

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

-- | Returns a newly created CssProvider
cssProviderNew :: IO CssProvider -- ^ A new CssProvider
cssProviderNew =
  wrapNewGObject mkCssProvider gtk_css_provider_new
{-# LINE 83 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}

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

-- | Returns the provider containing the style settings used as a fallback for all widgets.
cssProviderGetDefault :: IO CssProvider -- ^ The provider used for fallback styling
cssProviderGetDefault =
  makeNewGObject mkCssProvider gtk_css_provider_get_default
{-# LINE 91 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}

-- | Loads a theme from the usual theme paths
cssProviderGetNamed :: GlibString string
                    => string -- ^ @name@ : A theme name
                    -> Maybe string -- ^ @variant@ to load, for example, "dark"
                    -> IO (Maybe CssProvider) -- ^ a @CssProvider@ with the theme loaded
cssProviderGetNamed name variant =
  maybeNull (makeNewGObject mkCssProvider) $
  withUTFString name $ \namePtr ->
  maybeWith withUTFString variant $ \variantPtr ->
  gtk_css_provider_get_named namePtr variantPtr

-- | Loads @_data@ into @cssProvider@, making it clear any previously loaded information.
cssProviderLoadFromData :: CssProviderClass cssProvider
                      => cssProvider -- ^ @cssProvider@ : a @CssProvider@
                      -> Ptr CChar -- ^ @_data@ : CSS data loaded in memory. [array length=length][element-type guint8]
                      -> Int -- ^ @length@ : the length of @_data@ in bytes, or -1 for NUL terminated
                                     -- strings. If @length@ is not -1, the code will assume it is
                                     -- not NUL terminated and will potentially do a copy.
                      -> IO ()
cssProviderLoadFromData cssProvider _data length =
  propagateGError $ \errPtrPtr ->
  (\(CssProvider arg1) arg2 arg3 arg4 -> withForeignPtr arg1 $ \argPtr1 ->gtk_css_provider_load_from_data argPtr1 arg2 arg3 arg4)
{-# LINE 114 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}
  (toCssProvider cssProvider)
  _data
  (fromIntegral length)
  errPtrPtr >> return ()

-- | Loads @css@ into @cssProvider@, making it clear any previously loaded information.
cssProviderLoadFromString :: (CssProviderClass cssProvider, GlibString string)
                          => cssProvider -- ^ @cssProvider@ : a @CssProvider@
                          -> string -- ^ @css@ : CSS data loaded in memory.
                          -> IO ()
cssProviderLoadFromString cssProvider css =
  withUTFStringLen css $ \(cssPtr, len) ->
  cssProviderLoadFromData cssProvider cssPtr len

-- |Loads the data contained in @path@ into @cssProvider@, making it clear any previously
-- loaded information
cssProviderLoadFromPath :: (CssProviderClass cssProvider, GlibFilePath fp)
                        => cssProvider -- ^ @cssProvider@ a @CssProvider@
                        -> fp -- ^ the path of a filename to load
                        -> IO ()
cssProviderLoadFromPath cssProvider path =
  propagateGError $ \errPtrPtr ->
  withUTFFilePath path $ \pathPtr ->
  (\(CssProvider arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gtk_css_provider_load_from_path argPtr1 arg2 arg3)
{-# LINE 138 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}
  (toCssProvider cssProvider)
  pathPtr
  errPtrPtr >> return ()


-- | Convertes the @provider@ into a string representation in CSS format.
--
-- Using @cssProviderLoadFromString@ with the return value from this function
-- on a new provider created with @cssProviderNew@ will basically create a
-- duplicate of this @provider@.
cssProviderToString :: (CssProviderClass cssProvider, GlibString string)
                    => cssProvider -- ^ @provider@ a @CssProvider@
                    -> IO string
cssProviderToString provider =
  (\(CssProvider arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_css_provider_to_string argPtr1)
{-# LINE 153 "./Graphics/UI/Gtk/General/CssProvider.chs" #-}
  (toCssProvider provider) >>= peekUTFString

foreign import ccall safe "gtk_css_provider_new"
  gtk_css_provider_new :: (IO (Ptr CssProvider))

foreign import ccall safe "gtk_css_provider_get_default"
  gtk_css_provider_get_default :: (IO (Ptr CssProvider))

foreign import ccall safe "gtk_css_provider_get_named"
  gtk_css_provider_get_named :: ((Ptr CChar) -> ((Ptr CChar) -> (IO (Ptr CssProvider))))

foreign import ccall safe "gtk_css_provider_load_from_data"
  gtk_css_provider_load_from_data :: ((Ptr CssProvider) -> ((Ptr CChar) -> (CLong -> ((Ptr (Ptr ())) -> (IO CInt)))))

foreign import ccall safe "gtk_css_provider_load_from_path"
  gtk_css_provider_load_from_path :: ((Ptr CssProvider) -> ((Ptr CChar) -> ((Ptr (Ptr ())) -> (IO CInt))))

foreign import ccall safe "gtk_css_provider_to_string"
  gtk_css_provider_to_string :: ((Ptr CssProvider) -> (IO (Ptr CChar)))