module Graphics.UI.Gtk.General.IconFactory (
IconFactory,
IconFactoryClass,
castToIconFactory, gTypeIconFactory,
toIconFactory,
iconFactoryNew,
iconFactoryAdd,
iconFactoryAddDefault,
iconFactoryLookup,
iconFactoryLookupDefault,
iconFactoryRemoveDefault,
IconSet,
iconSetNew,
iconSetNewFromPixbuf,
iconSetAddSource,
iconSetRenderIcon,
iconSetGetSizes,
IconSource,
iconSourceNew,
TextDirection(..),
iconSourceGetDirection,
iconSourceSetDirection,
iconSourceResetDirection,
iconSourceGetFilename,
iconSourceSetFilename,
iconSourceGetPixbuf,
iconSourceSetPixbuf,
iconSourceGetSize,
iconSourceSetSize,
iconSourceResetSize,
StateType(..),
iconSourceGetState,
iconSourceSetState,
iconSourceResetState,
IconSize(..),
iconSizeCheck,
iconSizeRegister,
iconSizeRegisterAlias,
iconSizeFromName,
iconSizeGetName
) where
import Control.Monad (liftM)
import Control.Applicative ((<$>))
import System.Glib.FFI
import System.Glib.UTFString
import Graphics.UI.Gtk.Types
import Graphics.UI.Gtk.General.Enums (TextDirection(..), StateType(..))
import Graphics.UI.Gtk.General.StockItems
import Graphics.UI.Gtk.General.Structs (IconSize(..))
newtype IconSource = IconSource (ForeignPtr (IconSource))
newtype IconSet = IconSet (ForeignPtr (IconSet))
instance Show IconSize where
show i = unsafePerformIO (lookupSizeString (fromEnum i))
where
lookupSizeString n = do
ptr <- gtk_icon_size_get_name (fromIntegral n)
if ptr==nullPtr then return "" else glibToString <$> peekUTFString ptr
iconFactoryNew :: IO IconFactory
iconFactoryNew =
wrapNewGObject mkIconFactory gtk_icon_factory_new
iconFactoryAdd :: IconFactory -> StockId -> IconSet -> IO ()
iconFactoryAdd i stockId iconSet = withUTFString stockId $ \strPtr ->
(\(IconFactory arg1) arg2 (IconSet arg3) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg3 $ \argPtr3 ->gtk_icon_factory_add argPtr1 arg2 argPtr3) i strPtr iconSet
iconFactoryAddDefault :: IconFactory -> IO ()
iconFactoryAddDefault = (\(IconFactory arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_factory_add_default argPtr1)
iconFactoryLookup :: IconFactory -> StockId -> IO (Maybe IconSet)
iconFactoryLookup i stockId =
withUTFString stockId $ \strPtr -> do
iconSetPtr <- (\(IconFactory arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_factory_lookup argPtr1 arg2) i strPtr
if iconSetPtr == nullPtr then return Nothing else liftM (Just . IconSet) $
newForeignPtr iconSetPtr icon_set_unref
iconFactoryLookupDefault :: StockId -> IO (Maybe IconSet)
iconFactoryLookupDefault stockId =
withUTFString stockId $ \strPtr -> do
iconSetPtr <- gtk_icon_factory_lookup_default strPtr
if iconSetPtr == nullPtr then return Nothing else liftM (Just . IconSet) $
newForeignPtr iconSetPtr icon_set_unref
iconFactoryRemoveDefault :: IconFactory -> IO ()
iconFactoryRemoveDefault = (\(IconFactory arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_factory_remove_default argPtr1)
iconSetAddSource :: IconSet -> IconSource -> IO ()
iconSetAddSource set source = (\(IconSet arg1) (IconSource arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_icon_set_add_source argPtr1 argPtr2) set source
iconSetRenderIcon :: WidgetClass widget => IconSet
-> TextDirection
-> StateType
-> IconSize
-> widget
-> IO Pixbuf
iconSetRenderIcon set dir state size widget = wrapNewGObject mkPixbuf $
(\(IconSet arg1) (Style arg2) arg3 arg4 arg5 (Widget arg6) arg7 -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->withForeignPtr arg6 $ \argPtr6 ->gtk_icon_set_render_icon argPtr1 argPtr2 arg3 arg4 arg5 argPtr6 arg7) set (Style nullForeignPtr)
((fromIntegral.fromEnum) dir) ((fromIntegral.fromEnum) state)
((fromIntegral.fromEnum) size) (toWidget widget) nullPtr
iconSetNew :: IO IconSet
iconSetNew = do
isPtr <- gtk_icon_set_new
liftM IconSet $ newForeignPtr isPtr icon_set_unref
iconSetNewFromPixbuf :: Pixbuf -> IO IconSet
iconSetNewFromPixbuf pixbuf = do
isPtr <- (\(Pixbuf arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_set_new_from_pixbuf argPtr1) pixbuf
liftM IconSet $ newForeignPtr isPtr icon_set_unref
iconSetGetSizes :: IconSet -> IO [IconSize]
iconSetGetSizes set =
alloca $ \sizesArrPtr -> alloca $ \lenPtr -> do
(\(IconSet arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_set_get_sizes argPtr1 arg2 arg3) set sizesArrPtr lenPtr
len <- peek lenPtr
sizesArr <- peek sizesArrPtr
list <- peekArray (fromIntegral len) sizesArr
g_free (castPtr sizesArr)
return $ map (toEnum.fromIntegral) list
foreign import ccall unsafe ">k_icon_set_unref"
icon_set_unref :: FinalizerPtr IconSet
iconSizeCheck :: IconSize -> IO Bool
iconSizeCheck size = liftM toBool $
gtk_icon_size_lookup ((fromIntegral . fromEnum) size) nullPtr nullPtr
iconSizeRegister :: GlibString string
=> string
-> Int
-> Int
-> IO IconSize
iconSizeRegister name width height = liftM (toEnum . fromIntegral) $
withUTFString name $ \strPtr -> gtk_icon_size_register
strPtr (fromIntegral width) (fromIntegral height)
iconSizeRegisterAlias :: GlibString string => IconSize -> string -> IO ()
iconSizeRegisterAlias target alias = withUTFString alias $ \strPtr ->
gtk_icon_size_register_alias strPtr ((fromIntegral . fromEnum) target)
iconSizeFromName :: GlibString string => string -> IO IconSize
iconSizeFromName name = liftM (toEnum . fromIntegral) $
withUTFString name gtk_icon_size_from_name
iconSizeGetName :: GlibString string => IconSize -> IO (Maybe string)
iconSizeGetName size = do
strPtr <- gtk_icon_size_get_name ((fromIntegral . fromEnum) size)
if strPtr==nullPtr then return Nothing else liftM Just $ peekUTFString strPtr
iconSourceGetDirection :: IconSource -> IO (Maybe TextDirection)
iconSourceGetDirection is = do
res <- (\(IconSource arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_get_direction_wildcarded argPtr1) is
if (toBool res) then return Nothing else liftM (Just .toEnum.fromIntegral) $
(\(IconSource arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_get_direction argPtr1) is
iconSourceGetFilename :: GlibString string => IconSource -> IO (Maybe string)
iconSourceGetFilename is = do
strPtr <- (\(IconSource arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_get_filename argPtr1) is
if strPtr==nullPtr then return Nothing else liftM Just $ peekUTFString strPtr
iconSourceGetSize :: IconSource -> IO (Maybe IconSize)
iconSourceGetSize is = do
res <- (\(IconSource arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_get_size_wildcarded argPtr1) is
if (toBool res) then return Nothing else liftM (Just . toEnum . fromIntegral) $
(\(IconSource arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_get_size argPtr1) is
iconSourceGetState :: IconSource -> IO (Maybe StateType)
iconSourceGetState is = do
res <- (\(IconSource arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_get_state_wildcarded argPtr1) is
if (toBool res) then return Nothing else liftM (Just .toEnum.fromIntegral) $
(\(IconSource arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_get_state argPtr1) is
iconSourceNew :: IO IconSource
iconSourceNew = do
isPtr <- gtk_icon_source_new
liftM IconSource $ newForeignPtr isPtr icon_source_free
foreign import ccall unsafe ">k_icon_source_free"
icon_source_free :: FinalizerPtr IconSource
iconSourceSetDirection :: IconSource -> TextDirection -> IO ()
iconSourceSetDirection is td = do
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_direction_wildcarded argPtr1 arg2) is (fromBool False)
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_direction argPtr1 arg2) is ((fromIntegral.fromEnum) td)
iconSourceResetDirection :: IconSource -> IO ()
iconSourceResetDirection is =
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_direction_wildcarded argPtr1 arg2) is (fromBool True)
iconSourceSetFilename :: GlibFilePath fp => IconSource -> fp -> IO ()
iconSourceSetFilename is name =
withUTFFilePath name $ (\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_filename argPtr1 arg2) is
iconSourceGetPixbuf :: IconSource -> IO (Maybe Pixbuf)
iconSourceGetPixbuf is = maybeNull (makeNewGObject mkPixbuf) $
(\(IconSource arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_get_pixbuf argPtr1) is
iconSourceSetPixbuf :: IconSource -> Pixbuf -> IO ()
iconSourceSetPixbuf is pb = do
(\(IconSource arg1) (Pixbuf arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_icon_source_set_pixbuf argPtr1 argPtr2) is pb
iconSourceSetSize :: IconSource -> IconSize -> IO ()
iconSourceSetSize is size = do
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_size_wildcarded argPtr1 arg2) is (fromBool False)
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_size argPtr1 arg2) is ((fromIntegral . fromEnum) size)
iconSourceResetSize :: IconSource -> IO ()
iconSourceResetSize is =
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_size_wildcarded argPtr1 arg2) is (fromBool True)
iconSourceSetState :: IconSource -> StateType -> IO ()
iconSourceSetState is state = do
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_state_wildcarded argPtr1 arg2) is (fromBool False)
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_state argPtr1 arg2) is ((fromIntegral.fromEnum) state)
iconSourceResetState :: IconSource -> IO ()
iconSourceResetState is =
(\(IconSource arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_source_set_state_wildcarded argPtr1 arg2) is (fromBool True)
foreign import ccall unsafe "gtk_icon_size_get_name"
gtk_icon_size_get_name :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "gtk_icon_factory_new"
gtk_icon_factory_new :: (IO (Ptr IconFactory))
foreign import ccall unsafe "gtk_icon_factory_add"
gtk_icon_factory_add :: ((Ptr IconFactory) -> ((Ptr CChar) -> ((Ptr IconSet) -> (IO ()))))
foreign import ccall unsafe "gtk_icon_factory_add_default"
gtk_icon_factory_add_default :: ((Ptr IconFactory) -> (IO ()))
foreign import ccall unsafe "gtk_icon_factory_lookup"
gtk_icon_factory_lookup :: ((Ptr IconFactory) -> ((Ptr CChar) -> (IO (Ptr IconSet))))
foreign import ccall unsafe "gtk_icon_factory_lookup_default"
gtk_icon_factory_lookup_default :: ((Ptr CChar) -> (IO (Ptr IconSet)))
foreign import ccall unsafe "gtk_icon_factory_remove_default"
gtk_icon_factory_remove_default :: ((Ptr IconFactory) -> (IO ()))
foreign import ccall unsafe "gtk_icon_set_add_source"
gtk_icon_set_add_source :: ((Ptr IconSet) -> ((Ptr IconSource) -> (IO ())))
foreign import ccall safe "gtk_icon_set_render_icon"
gtk_icon_set_render_icon :: ((Ptr IconSet) -> ((Ptr Style) -> (CInt -> (CInt -> (CInt -> ((Ptr Widget) -> ((Ptr CChar) -> (IO (Ptr Pixbuf)))))))))
foreign import ccall unsafe "gtk_icon_set_new"
gtk_icon_set_new :: (IO (Ptr IconSet))
foreign import ccall unsafe "gtk_icon_set_new_from_pixbuf"
gtk_icon_set_new_from_pixbuf :: ((Ptr Pixbuf) -> (IO (Ptr IconSet)))
foreign import ccall unsafe "gtk_icon_set_get_sizes"
gtk_icon_set_get_sizes :: ((Ptr IconSet) -> ((Ptr (Ptr CInt)) -> ((Ptr CInt) -> (IO ()))))
foreign import ccall unsafe "g_free"
g_free :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "gtk_icon_size_lookup"
gtk_icon_size_lookup :: (CInt -> ((Ptr CInt) -> ((Ptr CInt) -> (IO CInt))))
foreign import ccall unsafe "gtk_icon_size_register"
gtk_icon_size_register :: ((Ptr CChar) -> (CInt -> (CInt -> (IO CInt))))
foreign import ccall unsafe "gtk_icon_size_register_alias"
gtk_icon_size_register_alias :: ((Ptr CChar) -> (CInt -> (IO ())))
foreign import ccall unsafe "gtk_icon_size_from_name"
gtk_icon_size_from_name :: ((Ptr CChar) -> (IO CInt))
foreign import ccall safe "gtk_icon_source_get_direction_wildcarded"
gtk_icon_source_get_direction_wildcarded :: ((Ptr IconSource) -> (IO CInt))
foreign import ccall unsafe "gtk_icon_source_get_direction"
gtk_icon_source_get_direction :: ((Ptr IconSource) -> (IO CInt))
foreign import ccall unsafe "gtk_icon_source_get_filename"
gtk_icon_source_get_filename :: ((Ptr IconSource) -> (IO (Ptr CChar)))
foreign import ccall unsafe "gtk_icon_source_get_size_wildcarded"
gtk_icon_source_get_size_wildcarded :: ((Ptr IconSource) -> (IO CInt))
foreign import ccall unsafe "gtk_icon_source_get_size"
gtk_icon_source_get_size :: ((Ptr IconSource) -> (IO CInt))
foreign import ccall unsafe "gtk_icon_source_get_state_wildcarded"
gtk_icon_source_get_state_wildcarded :: ((Ptr IconSource) -> (IO CInt))
foreign import ccall unsafe "gtk_icon_source_get_state"
gtk_icon_source_get_state :: ((Ptr IconSource) -> (IO CInt))
foreign import ccall unsafe "gtk_icon_source_new"
gtk_icon_source_new :: (IO (Ptr IconSource))
foreign import ccall unsafe "gtk_icon_source_set_direction_wildcarded"
gtk_icon_source_set_direction_wildcarded :: ((Ptr IconSource) -> (CInt -> (IO ())))
foreign import ccall unsafe "gtk_icon_source_set_direction"
gtk_icon_source_set_direction :: ((Ptr IconSource) -> (CInt -> (IO ())))
foreign import ccall unsafe "gtk_icon_source_set_filename"
gtk_icon_source_set_filename :: ((Ptr IconSource) -> ((Ptr CChar) -> (IO ())))
foreign import ccall unsafe "gtk_icon_source_get_pixbuf"
gtk_icon_source_get_pixbuf :: ((Ptr IconSource) -> (IO (Ptr Pixbuf)))
foreign import ccall safe "gtk_icon_source_set_pixbuf"
gtk_icon_source_set_pixbuf :: ((Ptr IconSource) -> ((Ptr Pixbuf) -> (IO ())))
foreign import ccall unsafe "gtk_icon_source_set_size_wildcarded"
gtk_icon_source_set_size_wildcarded :: ((Ptr IconSource) -> (CInt -> (IO ())))
foreign import ccall unsafe "gtk_icon_source_set_size"
gtk_icon_source_set_size :: ((Ptr IconSource) -> (CInt -> (IO ())))
foreign import ccall unsafe "gtk_icon_source_set_state_wildcarded"
gtk_icon_source_set_state_wildcarded :: ((Ptr IconSource) -> (CInt -> (IO ())))
foreign import ccall unsafe "gtk_icon_source_set_state"
gtk_icon_source_set_state :: ((Ptr IconSource) -> (CInt -> (IO ())))