-- GENERATED by C->Haskell Compiler, version 0.13.6 (gtk2hs branch) "Bin IO", 27 May 2012 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./System/Glib/GValueTypes.chs" #-}
-- -*-haskell-*-
--  GIMP Toolkit (GTK) GValueTypes
--
--  Author : Axel Simon
--
--  Created: 1 June 2001
--
--  Copyright (c) 1999..2002 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)
--
-- This is used by the implementation of properties and by the
-- 'Graphics.UI.Gtk.TreeList.TreeModel' and
-- related modules.
--
module System.Glib.GValueTypes (
  valueSetUInt,
  valueGetUInt,
  valueSetInt,
  valueGetInt,
  valueSetUInt64,
  valueGetUInt64,
  valueSetInt64,
  valueGetInt64,
  valueSetBool,
  valueGetBool,
  valueSetPointer,
  valueGetPointer,
  valueSetFloat,
  valueGetFloat,
  valueSetDouble,
  valueGetDouble,
  valueSetEnum,
  valueGetEnum,
  valueSetFlags,
  valueGetFlags,
  valueSetString,
  valueGetString,
  valueSetMaybeString,
  valueGetMaybeString,
  valueSetBoxed,
  valueGetBoxed,
  valueSetGObject,
  valueGetGObject,
  valueSetMaybeGObject,
  valueGetMaybeGObject,
  ) where

import Control.Monad	(liftM)

import System.Glib.FFI
import System.Glib.Flags
import System.Glib.UTFString
import System.Glib.GValue		(GValue(GValue))
import System.Glib.GObject


{-# LINE 70 "./System/Glib/GValueTypes.chs" #-}

valueSetUInt :: GValue -> Word -> IO ()
valueSetUInt gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_uint arg1 arg2) gvalue (fromIntegral value)

valueGetUInt :: GValue -> IO Word
valueGetUInt gvalue =
  liftM fromIntegral $
  (\(GValue arg1) -> g_value_get_uint arg1) gvalue

valueSetInt :: GValue -> Int -> IO ()
valueSetInt gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_int arg1 arg2) gvalue (fromIntegral value)

valueGetInt :: GValue -> IO Int
valueGetInt gvalue =
  liftM fromIntegral $
  (\(GValue arg1) -> g_value_get_int arg1) gvalue

valueSetUInt64 :: GValue -> Word64 -> IO ()
valueSetUInt64 gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_uint64 arg1 arg2) gvalue (fromIntegral value)

valueGetUInt64 :: GValue -> IO Word64
valueGetUInt64 gvalue =
  liftM fromIntegral $
  (\(GValue arg1) -> g_value_get_uint64 arg1) gvalue

valueSetInt64 :: GValue -> Int64 -> IO ()
valueSetInt64 gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_int64 arg1 arg2) gvalue (fromIntegral value)

valueGetInt64 :: GValue -> IO Int64
valueGetInt64 gvalue =
  liftM fromIntegral $
  (\(GValue arg1) -> g_value_get_int64 arg1) gvalue

valueSetBool :: GValue -> Bool -> IO ()
valueSetBool gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_boolean arg1 arg2) gvalue (fromBool value)

valueGetBool :: GValue -> IO Bool
valueGetBool gvalue =
  liftM toBool $
  (\(GValue arg1) -> g_value_get_boolean arg1) gvalue

-- These functions should probably never be used as they are dangerous.
--
valueSetPointer :: GValue -> (Ptr ()) -> IO ()
valueSetPointer gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_pointer arg1 arg2) gvalue value

valueGetPointer :: GValue -> IO (Ptr ())
valueGetPointer gvalue =
  (\(GValue arg1) -> g_value_get_pointer arg1) gvalue

valueSetFloat :: GValue -> Float -> IO ()
valueSetFloat gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_float arg1 arg2) gvalue (realToFrac value)

valueGetFloat :: GValue -> IO Float
valueGetFloat gvalue =
  liftM realToFrac $
  (\(GValue arg1) -> g_value_get_float arg1) gvalue

valueSetDouble :: GValue -> Double -> IO ()
valueSetDouble gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_double arg1 arg2) gvalue (realToFrac value)

valueGetDouble :: GValue -> IO Double
valueGetDouble gvalue =
  liftM realToFrac $
  (\(GValue arg1) -> g_value_get_double arg1) gvalue

valueSetEnum :: Enum enum => GValue -> enum -> IO ()
valueSetEnum gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_enum arg1 arg2) gvalue (fromIntegral $ fromEnum value)

valueGetEnum :: Enum enum => GValue -> IO enum
valueGetEnum gvalue =
  liftM (toEnum . fromIntegral) $
  (\(GValue arg1) -> g_value_get_enum arg1) gvalue

valueSetFlags :: Flags flag => GValue -> [flag] -> IO ()
valueSetFlags gvalue value =
  (\(GValue arg1) arg2 -> g_value_set_flags arg1 arg2) gvalue (fromIntegral $ fromFlags value)

valueGetFlags :: Flags flag => GValue -> IO [flag]
valueGetFlags gvalue =
  liftM (toFlags . fromIntegral) $
  (\(GValue arg1) -> g_value_get_flags arg1) gvalue

valueSetString :: GValue -> String -> IO ()
valueSetString gvalue str =
  withUTFString str $ \strPtr ->
  (\(GValue arg1) arg2 -> g_value_set_string arg1 arg2) gvalue strPtr

valueGetString :: GValue -> IO String
valueGetString gvalue = do
  strPtr <- (\(GValue arg1) -> g_value_get_string arg1) gvalue
  if strPtr == nullPtr
    then return ""
    else peekUTFString strPtr

valueSetMaybeString :: GValue -> Maybe String -> IO ()
valueSetMaybeString gvalue (Just str) =
  withUTFString str $ \strPtr ->
  (\(GValue arg1) arg2 -> g_value_set_string arg1 arg2) gvalue strPtr

valueSetMaybeString gvalue Nothing =
  (\(GValue arg1) arg2 -> g_value_set_static_string arg1 arg2) gvalue nullPtr

valueGetMaybeString :: GValue -> IO (Maybe String)
valueGetMaybeString gvalue =
  (\(GValue arg1) -> g_value_get_string arg1) gvalue
  >>= maybePeek peekUTFString

valueSetBoxed :: (boxed -> (Ptr boxed -> IO ()) -> IO ()) -> GValue -> boxed -> IO ()
valueSetBoxed with gvalue boxed =
  with boxed $ \boxedPtr -> do
  (\(GValue arg1) arg2 -> g_value_set_boxed arg1 arg2) gvalue (castPtr boxedPtr)

valueGetBoxed :: (Ptr boxed -> IO boxed) -> GValue -> IO boxed
valueGetBoxed peek gvalue =
  (\(GValue arg1) -> g_value_get_boxed arg1) gvalue >>= peek . castPtr

-- for some weird reason the API says that gv is a gpointer, not a GObject
--
valueSetGObject :: GObjectClass gobj => GValue -> gobj -> IO ()
valueSetGObject gvalue obj =
  withForeignPtr ((unGObject.toGObject) obj) $ \objPtr ->
    (\(GValue arg1) arg2 -> g_value_set_object arg1 arg2) gvalue (castPtr objPtr)

-- Unsafe because it performs an unchecked downcast. Only for internal use.
--
valueGetGObject :: GObjectClass gobj => GValue -> IO gobj
valueGetGObject gvalue =
  liftM unsafeCastGObject $
  makeNewGObject mkGObject $
  throwIfNull "GValue.valueGetObject: extracting invalid object" $
  liftM castPtr $
  (\(GValue arg1) -> g_value_get_object arg1) gvalue

valueSetMaybeGObject :: GObjectClass gobj => GValue -> (Maybe gobj) -> IO ()
valueSetMaybeGObject gvalue (Just obj) = valueSetGObject gvalue obj
valueSetMaybeGObject gvalue Nothing =
    (\(GValue arg1) arg2 -> g_value_set_object arg1 arg2) gvalue nullPtr

valueGetMaybeGObject :: GObjectClass gobj => GValue -> IO (Maybe gobj)
valueGetMaybeGObject gvalue =
  liftM (liftM unsafeCastGObject) $
  maybeNull (makeNewGObject mkGObject) $
  liftM castPtr $
  (\(GValue arg1) -> g_value_get_object arg1) gvalue


foreign import ccall unsafe "g_value_set_uint"
  g_value_set_uint :: ((Ptr GValue) -> (CUInt -> (IO ())))

foreign import ccall unsafe "g_value_get_uint"
  g_value_get_uint :: ((Ptr GValue) -> (IO CUInt))

foreign import ccall unsafe "g_value_set_int"
  g_value_set_int :: ((Ptr GValue) -> (CInt -> (IO ())))

foreign import ccall unsafe "g_value_get_int"
  g_value_get_int :: ((Ptr GValue) -> (IO CInt))

foreign import ccall unsafe "g_value_set_uint64"
  g_value_set_uint64 :: ((Ptr GValue) -> (CULLong -> (IO ())))

foreign import ccall unsafe "g_value_get_uint64"
  g_value_get_uint64 :: ((Ptr GValue) -> (IO CULLong))

foreign import ccall unsafe "g_value_set_int64"
  g_value_set_int64 :: ((Ptr GValue) -> (CLLong -> (IO ())))

foreign import ccall unsafe "g_value_get_int64"
  g_value_get_int64 :: ((Ptr GValue) -> (IO CLLong))

foreign import ccall unsafe "g_value_set_boolean"
  g_value_set_boolean :: ((Ptr GValue) -> (CInt -> (IO ())))

foreign import ccall unsafe "g_value_get_boolean"
  g_value_get_boolean :: ((Ptr GValue) -> (IO CInt))

foreign import ccall unsafe "g_value_set_pointer"
  g_value_set_pointer :: ((Ptr GValue) -> ((Ptr ()) -> (IO ())))

foreign import ccall unsafe "g_value_get_pointer"
  g_value_get_pointer :: ((Ptr GValue) -> (IO (Ptr ())))

foreign import ccall unsafe "g_value_set_float"
  g_value_set_float :: ((Ptr GValue) -> (CFloat -> (IO ())))

foreign import ccall unsafe "g_value_get_float"
  g_value_get_float :: ((Ptr GValue) -> (IO CFloat))

foreign import ccall unsafe "g_value_set_double"
  g_value_set_double :: ((Ptr GValue) -> (CDouble -> (IO ())))

foreign import ccall unsafe "g_value_get_double"
  g_value_get_double :: ((Ptr GValue) -> (IO CDouble))

foreign import ccall unsafe "g_value_set_enum"
  g_value_set_enum :: ((Ptr GValue) -> (CInt -> (IO ())))

foreign import ccall unsafe "g_value_get_enum"
  g_value_get_enum :: ((Ptr GValue) -> (IO CInt))

foreign import ccall unsafe "g_value_set_flags"
  g_value_set_flags :: ((Ptr GValue) -> (CUInt -> (IO ())))

foreign import ccall unsafe "g_value_get_flags"
  g_value_get_flags :: ((Ptr GValue) -> (IO CUInt))

foreign import ccall unsafe "g_value_set_string"
  g_value_set_string :: ((Ptr GValue) -> ((Ptr CChar) -> (IO ())))

foreign import ccall unsafe "g_value_get_string"
  g_value_get_string :: ((Ptr GValue) -> (IO (Ptr CChar)))

foreign import ccall unsafe "g_value_set_static_string"
  g_value_set_static_string :: ((Ptr GValue) -> ((Ptr CChar) -> (IO ())))

foreign import ccall unsafe "g_value_set_boxed"
  g_value_set_boxed :: ((Ptr GValue) -> ((Ptr ()) -> (IO ())))

foreign import ccall unsafe "g_value_get_boxed"
  g_value_get_boxed :: ((Ptr GValue) -> (IO (Ptr ())))

foreign import ccall unsafe "g_value_set_object"
  g_value_set_object :: ((Ptr GValue) -> ((Ptr ()) -> (IO ())))

foreign import ccall unsafe "g_value_get_object"
  g_value_get_object :: ((Ptr GValue) -> (IO (Ptr ())))