From: Duncan C. <dun...@us...> - 2004-08-03 02:59:05
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/general In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29523/gtk/general Modified Files: IconFactory.chs Log Message: Add missing functions. Also tidy up documentation a bit. Exclude deprecated and internal radio_menu_item and toolbar functions. Index: IconFactory.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/general/IconFactory.chs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- IconFactory.chs 23 May 2004 15:58:48 -0000 1.6 +++ IconFactory.chs 3 Aug 2004 02:58:26 -0000 1.7 @@ -37,10 +37,15 @@ iconFactoryNew, iconFactoryAdd, iconFactoryAddDefault, + iconFactoryLookup, + iconFactoryLookupDefault, iconFactoryRemoveDefault, IconSet, iconSetNew, + iconSetNewFromPixbuf, iconSetAddSource, + iconSetRenderIcon, + iconSetGetSizes, IconSource, iconSourceNew, TextDirection(..), @@ -49,12 +54,13 @@ iconSourceResetDirection, iconSourceGetFilename, iconSourceSetFilename, + iconSourceGetPixbuf, + iconSourceSetPixbuf, iconSourceGetSize, iconSourceSetSize, iconSourceResetSize, StateType(..), iconSourceGetState, - iconSourceGetState, iconSourceSetState, iconSourceResetState, IconSize, @@ -103,6 +109,33 @@ iconFactoryAddDefault :: IconFactory -> IO () iconFactoryAddDefault = {#call unsafe icon_factory_add_default#} +-- | Looks up the stock id in the icon factory, returning an icon set if found, +-- otherwise Nothing. +-- +-- * For display to the user, you should use 'styleLookupIconSet' on the "Style" +-- for the widget that will display the icon, instead of using this function +-- directly, so that themes are taken into account. +-- +iconFactoryLookup :: IconFactory -> String -> IO (Maybe IconSet) +iconFactoryLookup i stockId = + withUTFString stockId $ \strPtr -> do + iconSetPtr <- {#call unsafe icon_factory_lookup#} i strPtr + if iconSetPtr == nullPtr then return Nothing else liftM (Just . IconSet) $ + newForeignPtr iconSetPtr (icon_set_unref iconSetPtr) + +-- | Looks for an icon in the list of default icon factories. +-- +-- * For display to the user, you should use 'styleLookupIconSet' on the "Style" +-- for the widget that will display the icon, instead of using this function +-- directly, so that themes are taken into account. +-- +iconFactoryLookupDefault :: String -> IO (Maybe IconSet) +iconFactoryLookupDefault stockId = + withUTFString stockId $ \strPtr -> do + iconSetPtr <- {#call unsafe icon_factory_lookup_default#} strPtr + if iconSetPtr == nullPtr then return Nothing else liftM (Just . IconSet) $ + newForeignPtr iconSetPtr (icon_set_unref iconSetPtr) + -- | Create a new IconFactory. -- -- * An application should create a new 'IconFactory' and add all @@ -131,6 +164,17 @@ iconSetAddSource :: IconSet -> IconSource -> IO () iconSetAddSource set source = {#call unsafe icon_set_add_source#} set source +iconSetRenderIcon :: WidgetClass widget => IconSet + -> TextDirection + -> StateType + -> IconSize + -> widget + -> IO Pixbuf +iconSetRenderIcon set dir state size widget = makeNewGObject mkPixbuf $ + {#call icon_set_render_icon#} set (Style nullForeignPtr) + ((fromIntegral.fromEnum) dir) ((fromIntegral.fromEnum) state) + ((fromIntegral.fromEnum) size) (toWidget widget) nullPtr + -- | Create a new IconSet. -- -- * Each icon in an application is contained in an 'IconSet'. The @@ -142,6 +186,29 @@ isPtr <- {#call unsafe icon_set_new#} liftM IconSet $ newForeignPtr isPtr (icon_set_unref isPtr) +-- | Creates a new 'IconSet' with the given pixbuf as the default\/fallback +-- source image. If you don't add any additional "IconSource" to the icon set, +-- all variants of the icon will be created from the pixbuf, using scaling, +-- pixelation, etc. as required to adjust the icon size or make the icon look +-- insensitive\/prelighted. +-- +iconSetNewFromPixbuf :: Pixbuf -> IO IconSet +iconSetNewFromPixbuf pixbuf = do + isPtr <- {#call unsafe icon_set_new_from_pixbuf#} pixbuf + liftM IconSet $ newForeignPtr isPtr (icon_set_unref isPtr) + +-- | Obtains a list of icon sizes this icon set can render. +-- +iconSetGetSizes :: IconSet -> IO [IconSize] +iconSetGetSizes set = + alloca $ \sizesArrPtr -> alloca $ \lenPtr -> do + {#call unsafe icon_set_get_sizes#} set sizesArrPtr lenPtr + len <- peek lenPtr + sizesArr <- peek sizesArrPtr + list <- peekArray (fromIntegral len) sizesArr + {#call unsafe g_free#} (castPtr sizesArr) + return $ map (toEnum.fromIntegral) list + #if __GLASGOW_HASKELL__>=600 foreign import ccall unsafe ">k_icon_set_unref" @@ -301,6 +368,21 @@ iconSourceSetFilename is name = withUTFString name $ {#call unsafe icon_source_set_filename#} is +-- | Retrieves the source pixbuf, or Nothing if none is set. +-- +iconSourceGetPixbuf :: IconSource -> IO (Maybe Pixbuf) +iconSourceGetPixbuf is = do + pixbufPtr <- {#call unsafe icon_source_get_pixbuf#} is + if pixbufPtr==nullPtr then return Nothing else liftM Just $ + makeNewGObject mkPixbuf (return pixbufPtr) + +-- | Sets a pixbuf to use as a base image when creating icon variants for +-- 'IconSet'. +-- +iconSourceSetPixbuf :: IconSource -> Pixbuf -> IO () +iconSourceSetPixbuf is pb = do + {#call icon_source_set_pixbuf#} is pb + -- | Set this 'IconSource' to a specific -- size. -- |