Maintainer | gtk2hs-users@lists.sourceforge.net |
---|---|
Stability | provisional |
Portability | portable (depends on GHC) |
Safe Haskell | None |
Language | Haskell98 |
Looking up icons by name
- Module available since Gtk+ version 2.4
- data IconTheme
- class GObjectClass o => IconThemeClass o
- castToIconTheme :: GObjectClass obj => obj -> IconTheme
- toIconTheme :: IconThemeClass o => o -> IconTheme
- data IconInfo
- data IconLookupFlags
- data IconThemeError
- iconThemeNew :: IO IconTheme
- iconInfoNewForPixbuf :: IconThemeClass iconTheme => iconTheme -> Pixbuf -> IO IconInfo
- iconThemeGetDefault :: IO IconTheme
- iconThemeGetForScreen :: Screen -> IO IconTheme
- iconThemeSetScreen :: IconThemeClass self => self -> Screen -> IO ()
- iconThemeSetSearchPath :: (IconThemeClass self, GlibFilePath fp) => self -> [fp] -> Int -> IO ()
- iconThemeGetSearchPath :: (IconThemeClass self, GlibFilePath fp) => self -> IO ([fp], Int)
- iconThemeAppendSearchPath :: (IconThemeClass self, GlibFilePath fp) => self -> fp -> IO ()
- iconThemePrependSearchPath :: (IconThemeClass self, GlibFilePath fp) => self -> fp -> IO ()
- iconThemeSetCustomTheme :: (IconThemeClass self, GlibString string) => self -> Maybe string -> IO ()
- iconThemeHasIcon :: (IconThemeClass self, GlibString string) => self -> string -> IO Bool
- iconThemeLookupIcon :: (IconThemeClass self, GlibString string) => self -> string -> Int -> IconLookupFlags -> IO (Maybe IconInfo)
- iconThemeChooseIcon :: (IconThemeClass self, GlibString string) => self -> [string] -> Int -> IconLookupFlags -> IO (Maybe IconInfo)
- iconThemeLookupByGIcon :: (IconThemeClass self, IconClass icon) => self -> icon -> Int -> IconLookupFlags -> IO (Maybe IconInfo)
- iconThemeLoadIcon :: (IconThemeClass self, GlibString string) => self -> string -> Int -> IconLookupFlags -> IO (Maybe Pixbuf)
- iconThemeListContexts :: (IconThemeClass self, GlibString string) => self -> IO [string]
- iconThemeListIcons :: (IconThemeClass self, GlibString string) => self -> Maybe string -> IO [string]
- iconThemeGetIconSizes :: (IconThemeClass self, GlibString string) => self -> string -> IO [Int]
- iconThemeGetExampleIconName :: (IconThemeClass self, GlibString string) => self -> IO (Maybe string)
- iconThemeRescanIfNeeded :: IconThemeClass self => self -> IO Bool
- iconThemeAddBuiltinIcon :: GlibString string => string -> Int -> Pixbuf -> IO ()
- iconThemeErrorQuark :: IO Quark
- iconInfoCopy :: IconInfo -> IO IconInfo
- iconInfoGetAttachPoints :: IconInfo -> IO (Maybe [Point])
- iconInfoGetBaseSize :: IconInfo -> IO Int
- iconInfoGetBuiltinPixbuf :: IconInfo -> IO (Maybe Pixbuf)
- iconInfoGetDisplayName :: GlibString string => IconInfo -> IO (Maybe string)
- iconInfoGetEmbeddedRect :: IconInfo -> IO (Maybe Rectangle)
- iconInfoGetFilename :: GlibString string => IconInfo -> IO (Maybe string)
- iconInfoLoadIcon :: IconInfo -> IO Pixbuf
- iconInfoSetRawCoordinates :: IconInfo -> Bool -> IO ()
- iconThemeChanged :: IconThemeClass self => Signal self (IO ())
Detail
IconTheme
provides a facility for looking up icons by name and size. The main reason for using a
name rather than simply providing a filename is to allow different icons to be used depending on
what icon theme is selecetd by the user. The operation of icon themes on Linux and Unix follows the
Icon Theme Specification. There is a default icon theme, named hicolor where applications should
install their icons, but more additional application themes can be installed as operating system
vendors and users choose.
Named icons are similar to the Themeable Stock Images facility, and the distinction between the two may be a bit confusing. A few things to keep in mind:
- Stock images usually are used in conjunction with Stock Items, such as '
StockOk'
or 'StockOpen'
. Named icons are easier to set up and therefore are more useful for new icons that an application wants to add, such as application icons or window icons. - Stock images can only be loaded at the symbolic sizes defined by the
IconSize
enumeration, or by custom sizes defined byiconSizeRegister
, while named icons are more flexible and any pixel size can be specified. - Because stock images are closely tied to stock items, and thus to actions in the user interface, stock images may come in multiple variants for different widget states or writing directions.
A good rule of thumb is that if there is a stock image for what you want to use, use it, otherwise
use a named icon. It turns out that internally stock images are generally defined in terms of one or
more named icons. (An example of the more than one case is icons that depend on writing direction;
'StockGoForward'
uses the two themed icons gtkStockGoForwardLtr
and
gtkStockGoForwardRtl
.)
In many cases, named themes are used indirectly, via Image
or stock items, rather than directly,
but looking up icons directly is also simple. The IconTheme
object acts as a database of all the
icons in the current theme. You can create new IconTheme
objects, but its much more efficient to
use the standard icon theme for the Screen
so that the icon information is shared with other
people looking up icons. In the case where the default screen is being used, looking up an icon can
be as simple as:
Class Hierarchy
| GObject
| +----IconTheme
Types
class GObjectClass o => IconThemeClass o Source #
castToIconTheme :: GObjectClass obj => obj -> IconTheme Source #
toIconTheme :: IconThemeClass o => o -> IconTheme Source #
Enums
data IconLookupFlags Source #
data IconThemeError Source #
Constructors
iconThemeNew :: IO IconTheme Source #
Creates a new icon theme object. Icon theme objects are used to lookup up
an icon by name in a particular icon theme. Usually, you'll want to use
iconThemeGetDefault
or iconThemeGetForScreen
rather than creating a new
icon theme object for scratch.
iconInfoNewForPixbuf :: IconThemeClass iconTheme => iconTheme -> Pixbuf -> IO IconInfo Source #
Methods
:: IO IconTheme | returns A unique |
Gets the icon theme for the default screen. See iconThemeGetForScreen
.
iconThemeGetForScreen Source #
:: Screen |
|
-> IO IconTheme | returns A unique |
Gets the icon theme object associated with screen
; if this function has
not previously been called for the given screen, a new icon theme object
will be created and associated with the screen. Icon theme objects are
fairly expensive to create, so using this function is usually a better
choice than calling than iconThemeNew
and setting the screen yourself; by
using this function a single icon theme object will be shared between users.
:: IconThemeClass self | |
=> self | |
-> Screen |
|
-> IO () |
Sets the screen for an icon theme; the screen is used to track the user's currently configured icon theme, which might be different for different screens.
iconThemeSetSearchPath Source #
:: (IconThemeClass self, GlibFilePath fp) | |
=> self | |
-> [fp] |
|
-> Int |
|
-> IO () |
Sets the search path for the icon theme object. When looking for an icon
theme, Gtk+ will search for a subdirectory of one or more of the directories
in path
with the same name as the icon theme. (Themes from multiple of the
path elements are combined to allow themes to be extended by adding icons in
the user's home directory.)
In addition if an icon found isn't found either in the current icon theme
or the default icon theme, and an image file with the right name is found
directly in one of the elements of path
, then that image will be used for
the icon name. (This is legacy feature, and new icons should be put into the
default icon theme, which is called DEFAULT_THEME_NAME, rather than directly
on the icon path.)
iconThemeGetSearchPath Source #
:: (IconThemeClass self, GlibFilePath fp) | |
=> self | |
-> IO ([fp], Int) |
|
Gets the current search path. See iconThemeSetSearchPath
.
iconThemeAppendSearchPath Source #
:: (IconThemeClass self, GlibFilePath fp) | |
=> self | |
-> fp |
|
-> IO () |
Appends a directory to the search path. See iconThemeSetSearchPath
.
iconThemePrependSearchPath Source #
:: (IconThemeClass self, GlibFilePath fp) | |
=> self | |
-> fp |
|
-> IO () |
Prepends a directory to the search path. See iconThemeSetSearchPath
.
iconThemeSetCustomTheme Source #
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> Maybe string |
|
-> IO () |
Sets the name of the icon theme that the IconTheme
object uses
overriding system configuration. This function cannot be called on the icon
theme objects returned from iconThemeGetDefault
and
iconThemeGetForScreen
.
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> string |
|
-> IO Bool | returns |
Checks whether an icon theme includes an icon for a particular name.
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> string |
|
-> Int |
|
-> IconLookupFlags |
|
-> IO (Maybe IconInfo) | returns a |
Looks up a named icon and returns a structure containing information such
as the filename of the icon. The icon can then be rendered into a pixbuf
using iconInfoLoadIcon
. (iconThemeLoadIcon
combines these two steps if
all you need is the pixbuf.)
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> [string] |
|
-> Int |
|
-> IconLookupFlags |
|
-> IO (Maybe IconInfo) | returns a |
Looks up a named icon and returns a structure containing information such
as the filename of the icon. The icon can then be rendered into a pixbuf
using iconInfoLoadIcon
. (iconThemeLoadIcon
combines these two steps if
all you need is the pixbuf.)
If iconNames
contains more than one name, this function tries them all
in the given order before falling back to inherited icon themes.
- Available since Gtk+ version 2.12
iconThemeLookupByGIcon Source #
:: (IconThemeClass self, IconClass icon) | |
=> self | |
-> icon |
|
-> Int |
|
-> IconLookupFlags |
|
-> IO (Maybe IconInfo) | returns a |
Looks up an icon and returns a structure containing information such as
the filename of the icon. The icon can then be rendered into a pixbuf using
iconInfoLoadIcon
.
- Available since Gtk+ version 2.14
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> string |
|
-> Int |
|
-> IconLookupFlags |
|
-> IO (Maybe Pixbuf) | returns the rendered icon; this may be a newly
created icon or a new reference to an internal icon,
so you must not modify the icon.
|
Looks up an icon in an icon theme, scales it to the given size and
renders it into a pixbuf. This is a convenience function; if more details
about the icon are needed, use iconThemeLookupIcon
followed by
iconInfoLoadIcon
.
Note that you probably want to listen for icon theme changes and update
the icon. This is usually done by connecting to the Widget
::style-set
signal. If for some reason you do not want to update the icon when the icon
theme changes, you should consider using pixbufCopy
to make a private copy
of the pixbuf returned by this function. Otherwise Gtk+ may need to keep the
old icon theme loaded, which would be a waste of memory.
iconThemeListContexts Source #
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> IO [string] | returns a String list holding the names of all the contexts in the theme. |
Gets the list of contexts available within the current hierarchy of icon themes
- Available since Gtk+ version 2.12
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> Maybe string |
|
-> IO [string] | returns a String list holding the names of all the icons in the theme. |
Lists the icons in the current icon theme. Only a subset of the icons can be listed by providing a context string. The set of values for the context string is system dependent, but will typically include such values as "Applications" and "MimeTypes".
iconThemeGetIconSizes Source #
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> string |
|
-> IO [Int] | returns An newly allocated list describing the sizes at which the icon is available. |
Returns an list of integers describing the sizes at which the icon is available without scaling. A size of -1 means that the icon is available in a scalable format. The list is zero-terminated.
- Available since Gtk+ version 2.6
iconThemeGetExampleIconName Source #
:: (IconThemeClass self, GlibString string) | |
=> self | |
-> IO (Maybe string) | returns the name of an example icon or |
Gets the name of an icon that is representative of the current theme (for instance, to use when presenting a list of themes to the user.)
iconThemeRescanIfNeeded Source #
:: IconThemeClass self | |
=> self | |
-> IO Bool | returns |
Checks to see if the icon theme has changed; if it has, any currently
cached information is discarded and will be reloaded next time iconTheme
is accessed.
iconThemeAddBuiltinIcon Source #
:: GlibString string | |
=> string |
|
-> Int |
|
-> Pixbuf |
|
-> IO () |
Registers a built-in icon for icon theme lookups. The idea of built-in icons is to allow an application or library that uses themed icons to function requiring files to be present in the file system. For instance, the default images for all of Gtk+'s stock icons are registered as built-icons.
In general, if you use iconThemeAddBuiltinIcon
you should also install
the icon in the icon theme, so that the icon is generally available.
This function will generally be used with pixbufs loaded via
pixbufNewFromInline
.
iconInfoGetAttachPoints :: IconInfo -> IO (Maybe [Point]) Source #
Fetches the set of attach points for an icon. An attach point is a location in the icon that can be used as anchor points for attaching emblems or overlays to the icon.
iconInfoGetBaseSize :: IconInfo -> IO Int Source #
Gets the base size for the icon. The base size is a size for the icon that was specified by the icon theme creator. This may be different than the actual size of image; an example of this is small emblem icons that can be attached to a larger icon. These icons will be given the same base size as the larger icons to which they are attached.
iconInfoGetBuiltinPixbuf Source #
Gets the built-in image for this icon, if any. To allow GTK+ to use built in icon images, you must
pass the 'IconLookupUseBuiltin'
to iconThemeLookupIcon
.
iconInfoGetDisplayName Source #
:: GlibString string | |
=> IconInfo | |
-> IO (Maybe string) | returns the display name for the icon or |
Gets the display name for an icon. A display name is a string to be used in place of the icon name in a user visible context like a list of icons.
iconInfoGetEmbeddedRect Source #
:: IconInfo | |
-> IO (Maybe Rectangle) |
|
Gets the coordinates of a rectangle within the icon that can be used for display of information such
as a preview of the contents of a text file. See iconInfoSetRawCoordinates
for further
information about the coordinate system.
:: GlibString string | |
=> IconInfo | |
-> IO (Maybe string) | returns the filename for the icon,
or |
Gets the filename for the icon. If the 'IconLookupUseBuiltin'
flag was passed to
iconThemeLookupIcon
, there may be no filename if a builtin icon is returned; in this case,
you should use iconInfoGetBuiltinPixbuf
.
iconInfoLoadIcon :: IconInfo -> IO Pixbuf Source #
Looks up an icon in an icon theme, scales it to the given size and renders it into a pixbuf. This is
a convenience function; if more details about the icon are needed, use iconThemeLookupIcon
followed by iconInfoLoadIcon
.
Note that you probably want to listen for icon theme changes and update the icon. This is usually
done by connecting to the styleSet
signal. If for some reason you do not want to update
the icon when the icon theme changes, you should consider using pixbufCopy
to make a private
copy of the pixbuf returned by this function. Otherwise GTK+ may need to keep the old icon theme
loaded, which would be a waste of memory.
iconInfoSetRawCoordinates Source #
:: IconInfo | |
-> Bool |
|
-> IO () |
Sets whether the coordinates returned by iconInfoGetEmbeddedRect
and
iconInfoGetAttachPoints
should be returned in their original form as specified in the icon
theme, instead of scaled appropriately for the pixbuf returned by iconInfoLoadIcon
.
Raw coordinates are somewhat strange; they are specified to be with respect to the unscaled pixmap
for PNG and XPM icons, but for SVG icons, they are in a 1000x1000 coordinate space that is scaled to
the final size of the icon. You can determine if the icon is an SVG icon by using
iconInfoGetFilename
, and seeing if it is non-Nothing
and ends in '.svg'.
This function is provided primarily to allow compatibility wrappers for older API's, and is not expected to be useful for applications.
Signals
iconThemeChanged :: IconThemeClass self => Signal self (IO ()) Source #
Emitted when the current icon theme is switched or Gtk+ detects that a change has occurred in the contents of the current icon theme.