From: Duncan C. <dun...@us...> - 2005-04-07 00:14:12
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/Graphics/UI/Gtk/Display In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2146/gtk/Graphics/UI/Gtk/Display Modified Files: Image.chs.pp Label.chs.pp Log Message: Add bindings for a bunch of extra methods and properties. Also, various doc changes. Index: Image.chs.pp =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/Graphics/UI/Gtk/Display/Image.chs.pp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Image.chs.pp 2 Apr 2005 19:38:29 -0000 1.6 +++ Image.chs.pp 7 Apr 2005 00:14:01 -0000 1.7 @@ -39,7 +39,7 @@ -- A widget displaying an image -- module Graphics.UI.Gtk.Display.Image ( --- * Description +-- * Detail -- -- | The 'Image' widget displays an image. Various kinds of object can be -- displayed as an image; most typically, you would load a 'Pixbuf' (\"pixel @@ -58,7 +58,7 @@ -- 'Image' is a subclass of 'Misc', which implies that you can align it -- (center, left, right) and add padding to it, using 'Misc' methods. -- --- 'Image' is a \"no window\" widget (has no \"Gdk Window\" of its own), so by +-- 'Image' is a \"no window\" widget (has no 'DrawWindow' of its own), so by -- default does not receive events. If you want to receive events on the image, -- such as button clicks, place the image inside a 'EventBox', then connect to -- the event signals on the event box. @@ -95,10 +95,21 @@ imageNewFromFile, imageNewFromPixbuf, imageNewFromStock, + imageNew, +#if GTK_CHECK_VERSION(2,6,0) + imageNewFromIconName, +#endif -- * Methods imageGetPixbuf, imageSetFromPixbuf, + imageSetFromFile, + imageSetFromStock, +#if GTK_CHECK_VERSION(2,6,0) + imageSetFromIconName, + imageSetPixelSize, + imageGetPixelSize, +#endif -- * Icon Sizes IconSize, @@ -107,12 +118,18 @@ iconSizeLargeToolbar, iconSizeButton, iconSizeDialog, + +-- * Properties +#if GTK_CHECK_VERSION(2,6,0) + imagePixelSize, +#endif ) where import Monad (liftM) import System.Glib.FFI import System.Glib.UTFString +import System.Glib.Attributes (Attr(..)) import Graphics.UI.Gtk.Abstract.Object (makeNewObject) import System.Glib.GObject (makeNewGObject) {#import Graphics.UI.Gtk.Types#} @@ -179,6 +196,34 @@ stockIdPtr (fromIntegral size) +-- | Creates a new empty 'Image' widget. +-- +imageNew :: IO Image +imageNew = + makeNewObject mkImage $ + liftM (castPtr :: Ptr Widget -> Ptr Image) $ + {# call gtk_image_new #} + +#if GTK_CHECK_VERSION(2,6,0) +-- | Creates a 'Image' displaying an icon from the current icon theme. If the +-- icon name isn't known, a \"broken image\" icon will be displayed instead. If +-- the current icon theme is changed, the icon will be updated appropriately. +-- +-- * Available since Gtk+ version 2.6 +-- +imageNewFromIconName :: + String -- ^ @iconName@ - an icon name + -> IconSize -- ^ @size@ - a stock icon size + -> IO Image +imageNewFromIconName iconName size = + makeNewObject mkImage $ + liftM (castPtr :: Ptr Widget -> Ptr Image) $ + withUTFString iconName $ \iconNamePtr -> + {# call gtk_image_new_from_icon_name #} + iconNamePtr + ((fromIntegral . fromEnum) size) +#endif + -------------------- -- Methods @@ -199,3 +244,83 @@ {# call unsafe gtk_image_set_from_pixbuf #} self pixbuf + +-- | See 'imageNewFromFile' for details. +-- +imageSetFromFile :: Image -> FilePath -> IO () +imageSetFromFile self filename = + withUTFString filename $ \filenamePtr -> + {# call gtk_image_set_from_file #} + self + filenamePtr + +-- | See 'imageNewFromStock' for details. +-- +imageSetFromStock :: Image + -> String -- ^ @stockId@ - a stock icon name + -> IconSize -- ^ @size@ - a stock icon size + -> IO () +imageSetFromStock self stockId size = + withUTFString stockId $ \stockIdPtr -> + {# call gtk_image_set_from_stock #} + self + stockIdPtr + ((fromIntegral . fromEnum) size) + +#if GTK_CHECK_VERSION(2,6,0) +-- | See 'imageNewFromIconName' for details. +-- +-- * Available since Gtk+ version 2.6 +-- +imageSetFromIconName :: Image + -> String -- ^ @iconName@ - an icon name + -> IconSize -- ^ @size@ - an icon size + -> IO () +imageSetFromIconName self iconName size = + withUTFString iconName $ \iconNamePtr -> + {# call gtk_image_set_from_icon_name #} + self + iconNamePtr + ((fromIntegral . fromEnum) size) + +-- | Sets the pixel size to use for named icons. If the pixel size is set to a +-- @value \/= -1@, it is used instead of the icon size set by +-- 'imageSetFromIconName'. +-- +-- * Available since Gtk+ version 2.6 +-- +imageSetPixelSize :: Image + -> Int -- ^ @pixelSize@ - the new pixel size + -> IO () +imageSetPixelSize self pixelSize = + {# call gtk_image_set_pixel_size #} + self + (fromIntegral pixelSize) + +-- | Gets the pixel size used for named icons. +-- +-- * Available since Gtk+ version 2.6 +-- +imageGetPixelSize :: Image -> IO Int +imageGetPixelSize self = + liftM fromIntegral $ + {# call gtk_image_get_pixel_size #} + self +#endif + +-------------------- +-- Properties + +#if GTK_CHECK_VERSION(2,6,0) +-- | The pixel-size property can be used to specify a fixed size overriding +-- the icon-size property for images of type 'ImageIconName'. +-- +-- Allowed values: >= -1 +-- +-- Default value: -1 +-- +imagePixelSize :: Attr Image Int +imagePixelSize = Attr + imageGetPixelSize + imageSetPixelSize +#endif Index: Label.chs.pp =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/Graphics/UI/Gtk/Display/Label.chs.pp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Label.chs.pp 6 Apr 2005 22:20:02 -0000 1.1 +++ Label.chs.pp 7 Apr 2005 00:14:01 -0000 1.2 @@ -149,13 +149,32 @@ labelSelectRegion, labelGetSelectionBounds, labelGetLayoutOffsets, +#if GTK_CHECK_VERSION(2,6,0) + labelSetEllipsize, + labelGetEllipsize, + labelSetWidthChars, + labelGetWidthChars, + labelSetMaxWidthChars, + labelGetMaxWidthChars, + labelSetSingleLineMode, + labelGetSingleLineMode, + labelSetAngle, + labelGetAngle, +#endif -- * Properties labelUseMarkup, labelUseUnderline, labelJustify, labelSelectable, - labelLineWrap +#if GTK_CHECK_VERSION(2,6,0) + labelEllipsize, + labelWidthChars, + labelSingleLineMode, + labelAngle, + labelMaxWidthChars, +#endif + labelLineWrap, ) where import Monad (liftM) @@ -169,6 +188,7 @@ {#import Graphics.UI.Gtk.Signals#} import Graphics.UI.Gtk.General.Enums (Justification(..)) import Graphics.UI.Gtk.Pango.Markup +import Graphics.UI.Gtk.Pango.Enums (EllipsizeMode) {# context lib="gtk" prefix="gtk" #} @@ -304,12 +324,11 @@ {# call unsafe label_get_justify #} (toLabel self) --- | Gets the 'Layout' used to display the label. The layout is useful to e.g. --- convert text positions to pixel positions, in combination with +-- | Gets the 'PangoLayout' used to display the label. The layout is useful to +-- e.g. convert text positions to pixel positions, in combination with -- 'labelGetLayoutOffsets'. -- -labelGetLayout :: LabelClass self => self - -> IO PangoLayout -- ^ returns the 'Layout' for this label +labelGetLayout :: LabelClass self => self -> IO PangoLayout labelGetLayout self = makeNewGObject mkPangoLayout $ {# call unsafe label_get_layout #} @@ -338,10 +357,10 @@ {# call unsafe label_get_line_wrap #} (toLabel self) --- | Obtains the coordinates where the label will draw the 'Layout' +-- | Obtains the coordinates where the label will draw the 'PangoLayout' -- representing the text in the label; useful to convert mouse events into --- coordinates inside the 'Layout', e.g. to take some action if some part of --- the label is clicked. Of course you will need to create a 'EventBox' to +-- coordinates inside the 'PangoLayout', e.g. to take some action if some part +-- of the label is clicked. Of course you will need to create a 'EventBox' to -- receive the events, and pack the label inside it, since labels are a -- \'NoWindow\' widget. -- @@ -531,6 +550,130 @@ (toLabel self) strPtr +#if GTK_CHECK_VERSION(2,6,0) +-- | Sets the mode used to ellipsize (add an ellipsis: \"...\") to the text if +-- there is not enough space to render the entire string. +-- +-- * Available since Gtk+ version 2.6 +-- +labelSetEllipsize :: LabelClass self => self + -> EllipsizeMode -- ^ @mode@ - a 'EllipsizeMode' + -> IO () +labelSetEllipsize self mode = + {# call gtk_label_set_ellipsize #} + (toLabel self) + ((fromIntegral . fromEnum) mode) + +-- | Sets the desired width in characters of @label@ to @nChars@. +-- +-- * Available since Gtk+ version 2.6 +-- +labelSetWidthChars :: LabelClass self => self + -> Int -- ^ @nChars@ - the new desired width, in characters. + -> IO () +labelSetWidthChars self nChars = + {# call gtk_label_set_width_chars #} + (toLabel self) + (fromIntegral nChars) + +-- | Sets the desired maximum width in characters of @label@ to @nChars@. +-- +-- * Available since Gtk+ version 2.6 +-- +labelSetMaxWidthChars :: LabelClass self => self + -> Int -- ^ @nChars@ - the new desired maximum width, in characters. + -> IO () +labelSetMaxWidthChars self nChars = + {# call gtk_label_set_max_width_chars #} + (toLabel self) + (fromIntegral nChars) + +-- | Returns the ellipsizing position of the label. See 'labelSetEllipsize'. +-- +-- * Available since Gtk+ version 2.6 +-- +labelGetEllipsize :: LabelClass self => self + -> IO EllipsizeMode -- ^ returns 'EllipsizeMode' +labelGetEllipsize self = + liftM (toEnum . fromIntegral) $ + {# call gtk_label_get_ellipsize #} + (toLabel self) + +-- | Retrieves the desired width of @label@, in characters. See +-- 'labelSetWidthChars'. +-- +-- * Available since Gtk+ version 2.6 +-- +labelGetWidthChars :: LabelClass self => self + -> IO Int -- ^ returns the width of the label in characters. +labelGetWidthChars self = + liftM fromIntegral $ + {# call gtk_label_get_width_chars #} + (toLabel self) + +-- | Retrieves the desired maximum width of @label@, in characters. See +-- 'labelSetWidthChars'. +-- +-- * Available since Gtk+ version 2.6 +-- +labelGetMaxWidthChars :: LabelClass self => self + -> IO Int -- ^ returns the maximum width of the label in characters. +labelGetMaxWidthChars self = + liftM fromIntegral $ + {# call gtk_label_get_max_width_chars #} + (toLabel self) + +-- | Returns whether the label is in single line mode. +-- +-- * Available since Gtk+ version 2.6 +-- +labelGetSingleLineMode :: LabelClass self => self + -> IO Bool -- ^ returns @True@ when the label is in single line mode. +labelGetSingleLineMode self = + liftM toBool $ + {# call gtk_label_get_single_line_mode #} + (toLabel self) + +-- | Gets the angle of rotation for the label. See gtk_label_set_angle. +-- +-- * Available since Gtk+ version 2.6 +-- +labelGetAngle :: LabelClass self => self + -> IO Double -- ^ returns the angle of rotation for the label +labelGetAngle self = + liftM realToFrac $ + {# call gtk_label_get_angle #} + (toLabel self) + +-- | Sets whether the label is in single line mode. +-- +-- * Available since Gtk+ version 2.6 +-- +labelSetSingleLineMode :: LabelClass self => self + -> Bool -- ^ @singleLineMode@ - @True@ if the label should be in single line + -- mode + -> IO () +labelSetSingleLineMode self singleLineMode = + {# call gtk_label_set_single_line_mode #} + (toLabel self) + (fromBool singleLineMode) + +-- | Sets the angle of rotation for the label. An angle of 90 reads from from +-- bottom to top, an angle of 270, from top to bottom. The angle setting for +-- the label is ignored if the label is selectable, wrapped, or ellipsized. +-- +-- * Available since Gtk+ version 2.6 +-- +labelSetAngle :: LabelClass self => self + -> Double -- ^ @angle@ - the angle that the baseline of the label makes with + -- the horizontal, in degrees, measured counterclockwise + -> IO () +labelSetAngle self angle = + {# call gtk_label_set_angle #} + (toLabel self) + (realToFrac angle) +#endif + -------------------- -- Properties @@ -573,6 +716,76 @@ labelGetSelectable labelSetSelectable +#if GTK_CHECK_VERSION(2,6,0) +-- | The preferred place to ellipsize the string, if the label does not have +-- enough room to display the entire string, specified as a 'EllisizeMode'. +-- +-- Note that setting this property to a value other than 'EllipsizeNone' has +-- the side-effect that the label requests only enough space to display the +-- ellipsis \"...\". In particular, this means that ellipsizing labels don't +-- work well in notebook tabs, unless the tab's tab-expand property is set to +-- @True@. Other means to set a label's width are 'widgetSetSizeRequest' and +-- 'labelSetWidthChars'. +-- +-- Default value: 'EllipsizeNone' +-- +labelEllipsize :: LabelClass self => Attr self EllipsizeMode +labelEllipsize = Attr + labelGetEllipsize + labelSetEllipsize + +-- | The desired width of the label, in characters. If this property is set to +-- -1, the width will be calculated automatically, otherwise the label will +-- request either 3 characters or the property value, whichever is greater. If +-- the width-chars property is set to a positive value, then the +-- max-width-chars property is ignored. +-- +-- Allowed values: >= -1 +-- +-- Default value: -1 +-- +labelWidthChars :: LabelClass self => Attr self Int +labelWidthChars = Attr + labelGetWidthChars + labelSetWidthChars + +-- | +-- +labelSingleLineMode :: LabelClass self => Attr self Bool +labelSingleLineMode = Attr + labelGetSingleLineMode + labelSetSingleLineMode + +-- | The angle that the baseline of the label makes with the horizontal, in +-- degrees, measured counterclockwise. An angle of 90 reads from from bottom to +-- top, an angle of 270, from top to bottom. Ignored if the label is +-- selectable, wrapped, or ellipsized. +-- +-- Allowed values: [0,360] +-- +-- Default value: 0 +-- +labelAngle :: LabelClass self => Attr self Double +labelAngle = Attr + labelGetAngle + labelSetAngle + +-- | The desired maximum width of the label, in characters. If this property +-- is set to -1, the width will be calculated automatically, otherwise the +-- label will request space for no more than the requested number of +-- characters. If the width-chars property is set to a positive value, then the +-- max-width-chars property is ignored. +-- +-- Allowed values: >= -1 +-- +-- Default value: -1 +-- +labelMaxWidthChars :: LabelClass self => Attr self Int +labelMaxWidthChars = Attr + labelGetMaxWidthChars + labelSetMaxWidthChars +#endif + -- | \'lineWrap\' property. See 'labelGetLineWrap' and 'labelSetLineWrap' -- labelLineWrap :: LabelClass self => Attr self Bool |