module Graphics.UI.Gtk.General.IconTheme (
IconTheme,
IconThemeClass,
castToIconTheme,
toIconTheme,
IconInfo,
IconLookupFlags(..),
IconThemeError(..),
iconThemeNew,
iconInfoNewForPixbuf,
iconThemeGetDefault,
iconThemeGetForScreen,
iconThemeSetScreen,
iconThemeSetSearchPath,
iconThemeGetSearchPath,
iconThemeAppendSearchPath,
iconThemePrependSearchPath,
iconThemeSetCustomTheme,
iconThemeHasIcon,
iconThemeLookupIcon,
iconThemeChooseIcon,
iconThemeLookupByGIcon,
iconThemeLoadIcon,
iconThemeListContexts,
iconThemeListIcons,
iconThemeGetIconSizes,
iconThemeGetExampleIconName,
iconThemeRescanIfNeeded,
iconThemeAddBuiltinIcon,
iconThemeErrorQuark,
iconInfoCopy,
iconInfoGetAttachPoints,
iconInfoGetBaseSize,
iconInfoGetBuiltinPixbuf,
iconInfoGetDisplayName,
iconInfoGetEmbeddedRect,
iconInfoGetFilename,
iconInfoLoadIcon,
iconInfoSetRawCoordinates,
iconThemeChanged,
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.GList
import System.Glib.GError (propagateGError)
import Graphics.UI.Gtk.General.Structs (Rectangle, Point)
import Graphics.UI.Gtk.Types
import Graphics.UI.Gtk.Signals
import System.GIO.Types
data IconLookupFlags = IconLookupNoSvg
| IconLookupForceSvg
| IconLookupUseBuiltin
| IconLookupGenericFallback
| IconLookupForceSize
| IconLookupForceRegular
| IconLookupForceSymbolic
| IconLookupDirLtr
| IconLookupDirRtl
deriving (Bounded,Eq,Show)
instance Enum IconLookupFlags where
fromEnum IconLookupNoSvg = 1
fromEnum IconLookupForceSvg = 2
fromEnum IconLookupUseBuiltin = 4
fromEnum IconLookupGenericFallback = 8
fromEnum IconLookupForceSize = 16
fromEnum IconLookupForceRegular = 32
fromEnum IconLookupForceSymbolic = 64
fromEnum IconLookupDirLtr = 128
fromEnum IconLookupDirRtl = 256
toEnum 1 = IconLookupNoSvg
toEnum 2 = IconLookupForceSvg
toEnum 4 = IconLookupUseBuiltin
toEnum 8 = IconLookupGenericFallback
toEnum 16 = IconLookupForceSize
toEnum 32 = IconLookupForceRegular
toEnum 64 = IconLookupForceSymbolic
toEnum 128 = IconLookupDirLtr
toEnum 256 = IconLookupDirRtl
toEnum unmatched = error ("IconLookupFlags.toEnum: Cannot match " ++ show unmatched)
succ IconLookupNoSvg = IconLookupForceSvg
succ IconLookupForceSvg = IconLookupUseBuiltin
succ IconLookupUseBuiltin = IconLookupGenericFallback
succ IconLookupGenericFallback = IconLookupForceSize
succ IconLookupForceSize = IconLookupForceRegular
succ IconLookupForceRegular = IconLookupForceSymbolic
succ IconLookupForceSymbolic = IconLookupDirLtr
succ IconLookupDirLtr = IconLookupDirRtl
succ _ = undefined
pred IconLookupForceSvg = IconLookupNoSvg
pred IconLookupUseBuiltin = IconLookupForceSvg
pred IconLookupGenericFallback = IconLookupUseBuiltin
pred IconLookupForceSize = IconLookupGenericFallback
pred IconLookupForceRegular = IconLookupForceSize
pred IconLookupForceSymbolic = IconLookupForceRegular
pred IconLookupDirLtr = IconLookupForceSymbolic
pred IconLookupDirRtl = IconLookupDirLtr
pred _ = undefined
enumFromTo x y | fromEnum x == fromEnum y = [ y ]
| otherwise = x : enumFromTo (succ x) y
enumFrom x = enumFromTo x IconLookupDirRtl
enumFromThen _ _ = error "Enum IconLookupFlags: enumFromThen not implemented"
enumFromThenTo _ _ _ = error "Enum IconLookupFlags: enumFromThenTo not implemented"
data IconThemeError = IconThemeNotFound
| IconThemeFailed
deriving (Enum,Bounded,Eq,Show)
iconThemeNew :: IO IconTheme
iconThemeNew =
wrapNewGObject mkIconTheme $
gtk_icon_theme_new
iconThemeGetDefault ::
IO IconTheme
iconThemeGetDefault =
makeNewGObject mkIconTheme $
gtk_icon_theme_get_default
iconThemeGetForScreen ::
Screen
-> IO IconTheme
iconThemeGetForScreen screen =
makeNewGObject mkIconTheme $
(\(Screen arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_get_for_screen argPtr1)
screen
iconThemeSetScreen :: IconThemeClass self => self
-> Screen
-> IO ()
iconThemeSetScreen self screen =
(\(IconTheme arg1) (Screen arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_icon_theme_set_screen argPtr1 argPtr2)
(toIconTheme self)
screen
iconThemeSetSearchPath :: (IconThemeClass self, GlibFilePath fp) => self
-> [fp]
-> Int
-> IO ()
iconThemeSetSearchPath self path nElements =
withUTFFilePathArray path $ \pathPtr ->
(\(IconTheme arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_set_search_path argPtr1 arg2 arg3)
(toIconTheme self)
pathPtr
(fromIntegral nElements)
iconThemeGetSearchPath :: (IconThemeClass self, GlibFilePath fp) => self
-> IO ([fp], Int)
iconThemeGetSearchPath self =
alloca $ \nElementsPtr ->
allocaArray 0 $ \pathPtr -> do
(\(IconTheme arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_get_search_path argPtr1 arg2 arg3)
(toIconTheme self)
(castPtr pathPtr)
nElementsPtr
pathStr <- readUTFFilePathArray0 pathPtr
nElements <- peek nElementsPtr
return (pathStr, fromIntegral nElements)
iconThemeAppendSearchPath :: (IconThemeClass self, GlibFilePath fp) => self
-> fp
-> IO ()
iconThemeAppendSearchPath self path =
withUTFFilePath path $ \pathPtr ->
(\(IconTheme arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_append_search_path argPtr1 arg2)
(toIconTheme self)
pathPtr
iconThemePrependSearchPath :: (IconThemeClass self, GlibFilePath fp) => self
-> fp
-> IO ()
iconThemePrependSearchPath self path =
withUTFFilePath path $ \pathPtr ->
(\(IconTheme arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_prepend_search_path argPtr1 arg2)
(toIconTheme self)
pathPtr
iconThemeSetCustomTheme :: (IconThemeClass self, GlibString string) => self
-> (Maybe string)
-> IO ()
iconThemeSetCustomTheme self themeName =
maybeWith withUTFString themeName $ \themeNamePtr ->
(\(IconTheme arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_set_custom_theme argPtr1 arg2)
(toIconTheme self)
themeNamePtr
iconThemeHasIcon :: (IconThemeClass self, GlibString string) => self
-> string
-> IO Bool
iconThemeHasIcon self iconName =
liftM toBool $
withUTFString iconName $ \iconNamePtr ->
(\(IconTheme arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_has_icon argPtr1 arg2)
(toIconTheme self)
iconNamePtr
iconThemeLookupIcon :: (IconThemeClass self, GlibString string) => self
-> string
-> Int
-> IconLookupFlags
-> IO (Maybe IconInfo)
iconThemeLookupIcon self iconName size flags =
withUTFString iconName $ \iconNamePtr -> do
iiPtr <- (\(IconTheme arg1) arg2 arg3 arg4 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_lookup_icon argPtr1 arg2 arg3 arg4)
(toIconTheme self)
iconNamePtr
(fromIntegral size)
((fromIntegral . fromEnum) flags)
if iiPtr == nullPtr
then return Nothing
else liftM Just (mkIconInfo (castPtr iiPtr))
iconThemeChooseIcon :: (IconThemeClass self, GlibString string) => self
-> [string]
-> Int
-> IconLookupFlags
-> IO (Maybe IconInfo)
iconThemeChooseIcon self iconNames size flags =
withUTFStringArray0 iconNames $ \iconNamesPtr -> do
iiPtr <- (\(IconTheme arg1) arg2 arg3 arg4 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_choose_icon argPtr1 arg2 arg3 arg4)
(toIconTheme self)
iconNamesPtr
(fromIntegral size)
((fromIntegral . fromEnum) flags)
if iiPtr == nullPtr
then return Nothing
else liftM Just (mkIconInfo (castPtr iiPtr))
iconThemeLookupByGIcon :: (IconThemeClass self, IconClass icon) => self
-> icon
-> Int
-> IconLookupFlags
-> IO (Maybe IconInfo)
iconThemeLookupByGIcon self icon size flags = do
iiPtr <- (\(IconTheme arg1) (Icon arg2) arg3 arg4 -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_icon_theme_lookup_by_gicon argPtr1 argPtr2 arg3 arg4)
(toIconTheme self)
(toIcon icon)
(fromIntegral size)
((fromIntegral . fromEnum) flags)
if iiPtr == nullPtr
then return Nothing
else liftM Just (mkIconInfo (castPtr iiPtr))
iconThemeLoadIcon :: (IconThemeClass self, GlibString string) => self
-> string
-> Int
-> IconLookupFlags
-> IO (Maybe Pixbuf)
iconThemeLoadIcon self iconName size flags =
maybeNull (wrapNewGObject mkPixbuf) $
propagateGError $ \errorPtr ->
withUTFString iconName $ \iconNamePtr ->
(\(IconTheme arg1) arg2 arg3 arg4 arg5 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_load_icon argPtr1 arg2 arg3 arg4 arg5)
(toIconTheme self)
iconNamePtr
(fromIntegral size)
((fromIntegral . fromEnum) flags)
errorPtr
iconThemeListContexts :: (IconThemeClass self, GlibString string) => self
-> IO [string]
iconThemeListContexts self = do
glistPtr <- (\(IconTheme arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_list_contexts argPtr1) (toIconTheme self)
list <- fromGList glistPtr
result <- mapM readUTFString list
g_list_free (castPtr glistPtr)
return result
iconThemeListIcons :: (IconThemeClass self, GlibString string) => self
-> (Maybe string)
-> IO [string]
iconThemeListIcons self context =
maybeWith withUTFString context $ \contextPtr -> do
glistPtr <- (\(IconTheme arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_list_icons argPtr1 arg2)
(toIconTheme self)
contextPtr
list <- fromGList glistPtr
result <- mapM readUTFString list
g_list_free (castPtr glistPtr)
return result
iconThemeGetIconSizes :: (IconThemeClass self, GlibString string) => self
-> string
-> IO [Int]
iconThemeGetIconSizes self iconName =
withUTFString iconName $ \iconNamePtr -> do
listPtr <- (\(IconTheme arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_get_icon_sizes argPtr1 arg2)
(toIconTheme self)
iconNamePtr
list <- peekArray 0 listPtr
g_free (castPtr listPtr)
return (map fromIntegral list)
iconThemeGetExampleIconName :: (IconThemeClass self, GlibString string) => self
-> IO (Maybe string)
iconThemeGetExampleIconName self = do
namePtr <- (\(IconTheme arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_get_example_icon_name argPtr1) (toIconTheme self)
if namePtr == nullPtr
then return Nothing
else liftM Just $ readUTFString namePtr
iconThemeRescanIfNeeded :: IconThemeClass self => self
-> IO Bool
iconThemeRescanIfNeeded self =
liftM toBool $
(\(IconTheme arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_theme_rescan_if_needed argPtr1)
(toIconTheme self)
iconThemeAddBuiltinIcon :: GlibString string =>
string
-> Int
-> Pixbuf
-> IO ()
iconThemeAddBuiltinIcon iconName size pixbuf =
withUTFString iconName $ \iconNamePtr ->
(\arg1 arg2 (Pixbuf arg3) -> withForeignPtr arg3 $ \argPtr3 ->gtk_icon_theme_add_builtin_icon arg1 arg2 argPtr3)
iconNamePtr
(fromIntegral size)
pixbuf
iconThemeErrorQuark :: IO Quark
iconThemeErrorQuark =
gtk_icon_theme_error_quark
newtype IconInfo = IconInfo (ForeignPtr (IconInfo))
foreign import ccall unsafe ">k_icon_info_free"
icon_info_free :: FinalizerPtr IconInfo
mkIconInfo :: Ptr IconInfo -> IO IconInfo
mkIconInfo infoPtr =
liftM IconInfo $ newForeignPtr infoPtr icon_info_free
iconInfoNewForPixbuf :: IconThemeClass iconTheme => iconTheme -> Pixbuf -> IO IconInfo
iconInfoNewForPixbuf iconTheme pixbuf =
(\(IconTheme arg1) (Pixbuf arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_icon_info_new_for_pixbuf argPtr1 argPtr2)
(toIconTheme iconTheme)
pixbuf
>>= mkIconInfo
iconInfoCopy :: IconInfo -> IO IconInfo
iconInfoCopy self =
(\(IconInfo arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_copy argPtr1) self
>>= mkIconInfo
iconInfoGetAttachPoints :: IconInfo -> IO (Maybe [Point])
iconInfoGetAttachPoints self =
alloca $ \arrPtrPtr ->
alloca $ \nPointsPtr -> do
success <- liftM toBool $
(\(IconInfo arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_get_attach_points argPtr1 arg2 arg3)
self
(castPtr arrPtrPtr)
nPointsPtr
if success
then do
arrPtr <- peek arrPtrPtr
nPoints <- peek nPointsPtr
pointList <- peekArray (fromIntegral nPoints) arrPtr
g_free (castPtr arrPtr)
return $ Just pointList
else return Nothing
iconInfoGetBaseSize :: IconInfo -> IO Int
iconInfoGetBaseSize self =
liftM fromIntegral $
(\(IconInfo arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_get_base_size argPtr1) self
iconInfoGetBuiltinPixbuf :: IconInfo
-> IO (Maybe Pixbuf)
iconInfoGetBuiltinPixbuf self = do
pixbufPtr <- (\(IconInfo arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_get_builtin_pixbuf argPtr1) self
if pixbufPtr == nullPtr
then return Nothing
else liftM Just $ makeNewGObject mkPixbuf (return pixbufPtr)
iconInfoGetDisplayName :: GlibString string => IconInfo
-> IO (Maybe string)
iconInfoGetDisplayName self = do
strPtr <- (\(IconInfo arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_get_display_name argPtr1) self
if strPtr == nullPtr
then return Nothing
else liftM Just $ peekUTFString strPtr
iconInfoGetEmbeddedRect :: IconInfo
-> IO (Maybe Rectangle)
iconInfoGetEmbeddedRect self =
alloca $ \rectPtr -> do
success <- liftM toBool $
(\(IconInfo arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_get_embedded_rect argPtr1 arg2)
self
(castPtr rectPtr)
if success
then liftM Just $ peek rectPtr
else return Nothing
iconInfoGetFilename :: GlibString string => IconInfo
-> IO (Maybe string)
iconInfoGetFilename self = do
namePtr <- (\(IconInfo arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_get_filename argPtr1) self
if namePtr == nullPtr
then return Nothing
else liftM Just $ peekUTFString namePtr
iconInfoLoadIcon :: IconInfo -> IO Pixbuf
iconInfoLoadIcon self =
wrapNewGObject mkPixbuf $
propagateGError $ \errorPtr ->
(\(IconInfo arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_load_icon argPtr1 arg2)
self
errorPtr
iconInfoSetRawCoordinates :: IconInfo
-> Bool
-> IO ()
iconInfoSetRawCoordinates self rawCoordinates =
(\(IconInfo arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_icon_info_set_raw_coordinates argPtr1 arg2)
self
(fromBool rawCoordinates)
iconThemeChanged :: IconThemeClass self => Signal self (IO ())
iconThemeChanged = Signal (connect_NONE__NONE "changed")
foreign import ccall safe "gtk_icon_theme_new"
gtk_icon_theme_new :: (IO (Ptr IconTheme))
foreign import ccall safe "gtk_icon_theme_get_default"
gtk_icon_theme_get_default :: (IO (Ptr IconTheme))
foreign import ccall safe "gtk_icon_theme_get_for_screen"
gtk_icon_theme_get_for_screen :: ((Ptr Screen) -> (IO (Ptr IconTheme)))
foreign import ccall safe "gtk_icon_theme_set_screen"
gtk_icon_theme_set_screen :: ((Ptr IconTheme) -> ((Ptr Screen) -> (IO ())))
foreign import ccall safe "gtk_icon_theme_set_search_path"
gtk_icon_theme_set_search_path :: ((Ptr IconTheme) -> ((Ptr (Ptr CChar)) -> (CInt -> (IO ()))))
foreign import ccall safe "gtk_icon_theme_get_search_path"
gtk_icon_theme_get_search_path :: ((Ptr IconTheme) -> ((Ptr (Ptr (Ptr CChar))) -> ((Ptr CInt) -> (IO ()))))
foreign import ccall safe "gtk_icon_theme_append_search_path"
gtk_icon_theme_append_search_path :: ((Ptr IconTheme) -> ((Ptr CChar) -> (IO ())))
foreign import ccall safe "gtk_icon_theme_prepend_search_path"
gtk_icon_theme_prepend_search_path :: ((Ptr IconTheme) -> ((Ptr CChar) -> (IO ())))
foreign import ccall safe "gtk_icon_theme_set_custom_theme"
gtk_icon_theme_set_custom_theme :: ((Ptr IconTheme) -> ((Ptr CChar) -> (IO ())))
foreign import ccall safe "gtk_icon_theme_has_icon"
gtk_icon_theme_has_icon :: ((Ptr IconTheme) -> ((Ptr CChar) -> (IO CInt)))
foreign import ccall safe "gtk_icon_theme_lookup_icon"
gtk_icon_theme_lookup_icon :: ((Ptr IconTheme) -> ((Ptr CChar) -> (CInt -> (CInt -> (IO (Ptr ()))))))
foreign import ccall safe "gtk_icon_theme_choose_icon"
gtk_icon_theme_choose_icon :: ((Ptr IconTheme) -> ((Ptr (Ptr CChar)) -> (CInt -> (CInt -> (IO (Ptr ()))))))
foreign import ccall safe "gtk_icon_theme_lookup_by_gicon"
gtk_icon_theme_lookup_by_gicon :: ((Ptr IconTheme) -> ((Ptr Icon) -> (CInt -> (CInt -> (IO (Ptr ()))))))
foreign import ccall safe "gtk_icon_theme_load_icon"
gtk_icon_theme_load_icon :: ((Ptr IconTheme) -> ((Ptr CChar) -> (CInt -> (CInt -> ((Ptr (Ptr ())) -> (IO (Ptr Pixbuf)))))))
foreign import ccall safe "gtk_icon_theme_list_contexts"
gtk_icon_theme_list_contexts :: ((Ptr IconTheme) -> (IO (Ptr ())))
foreign import ccall unsafe "g_list_free"
g_list_free :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "gtk_icon_theme_list_icons"
gtk_icon_theme_list_icons :: ((Ptr IconTheme) -> ((Ptr CChar) -> (IO (Ptr ()))))
foreign import ccall safe "gtk_icon_theme_get_icon_sizes"
gtk_icon_theme_get_icon_sizes :: ((Ptr IconTheme) -> ((Ptr CChar) -> (IO (Ptr CInt))))
foreign import ccall unsafe "g_free"
g_free :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "gtk_icon_theme_get_example_icon_name"
gtk_icon_theme_get_example_icon_name :: ((Ptr IconTheme) -> (IO (Ptr CChar)))
foreign import ccall safe "gtk_icon_theme_rescan_if_needed"
gtk_icon_theme_rescan_if_needed :: ((Ptr IconTheme) -> (IO CInt))
foreign import ccall safe "gtk_icon_theme_add_builtin_icon"
gtk_icon_theme_add_builtin_icon :: ((Ptr CChar) -> (CInt -> ((Ptr Pixbuf) -> (IO ()))))
foreign import ccall safe "gtk_icon_theme_error_quark"
gtk_icon_theme_error_quark :: (IO CUInt)
foreign import ccall safe "gtk_icon_info_new_for_pixbuf"
gtk_icon_info_new_for_pixbuf :: ((Ptr IconTheme) -> ((Ptr Pixbuf) -> (IO (Ptr IconInfo))))
foreign import ccall safe "gtk_icon_info_copy"
gtk_icon_info_copy :: ((Ptr IconInfo) -> (IO (Ptr IconInfo)))
foreign import ccall safe "gtk_icon_info_get_attach_points"
gtk_icon_info_get_attach_points :: ((Ptr IconInfo) -> ((Ptr (Ptr ())) -> ((Ptr CInt) -> (IO CInt))))
foreign import ccall safe "gtk_icon_info_get_base_size"
gtk_icon_info_get_base_size :: ((Ptr IconInfo) -> (IO CInt))
foreign import ccall safe "gtk_icon_info_get_builtin_pixbuf"
gtk_icon_info_get_builtin_pixbuf :: ((Ptr IconInfo) -> (IO (Ptr Pixbuf)))
foreign import ccall safe "gtk_icon_info_get_display_name"
gtk_icon_info_get_display_name :: ((Ptr IconInfo) -> (IO (Ptr CChar)))
foreign import ccall safe "gtk_icon_info_get_embedded_rect"
gtk_icon_info_get_embedded_rect :: ((Ptr IconInfo) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "gtk_icon_info_get_filename"
gtk_icon_info_get_filename :: ((Ptr IconInfo) -> (IO (Ptr CChar)))
foreign import ccall safe "gtk_icon_info_load_icon"
gtk_icon_info_load_icon :: ((Ptr IconInfo) -> ((Ptr (Ptr ())) -> (IO (Ptr Pixbuf))))
foreign import ccall safe "gtk_icon_info_set_raw_coordinates"
gtk_icon_info_set_raw_coordinates :: ((Ptr IconInfo) -> (CInt -> (IO ())))