From: Duncan C. <dun...@us...> - 2005-04-05 18:30:03
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/Graphics/UI/Gtk/Selectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22213/gtk/Graphics/UI/Gtk/Selectors Added Files: ColorButton.chs.pp FontButton.chs.pp FileChooserButton.chs.pp FileFilter.chs.pp Log Message: Add several new modules. This adds ~2.6 Kloc. gtk/Graphics/UI/Gtk.hs: export the new modules. Makefile.am: add the new modules to libHSgtk_a_SOURCES. --- NEW FILE: FontButton.chs.pp --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Widget FontButton -- -- Author : Duncan Coutts -- -- Created: 5 April 2005 -- -- Version $Revision: 1.1 $ from $Date: 2005/04/05 18:29:52 $ -- -- Copyright (C) 2005 Duncan Coutts -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Lesser General Public -- License as published by the Free Software Foundation; either -- version 2.1 of the License, or (at your option) any later version. -- -- This library is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- Lesser General Public License for more details. -- -- | -- Maintainer : gtk...@li... -- Stability : provisional -- Portability : portable (depends on GHC) -- -- A button to launch a font selection dialog -- -- * Module available since Gtk+ version 2.4 -- module Graphics.UI.Gtk.Selectors.FontButton ( -- * Detail -- -- | The 'FontButton' is a button which displays the currently selected font -- an allows to open a font selection dialog to change the font. It is suitable -- widget for selecting a font in a preference dialog. -- * Class Hierarchy -- | -- @ -- | 'GObject' -- | +----'Object' -- | +----'Widget' -- | +----'Container' -- | +----'Bin' -- | +----'Button' -- | +----FontButton -- @ #if GTK_CHECK_VERSION(2,4,0) -- * Types FontButton, FontButtonClass, castToFontButton, -- * Constructors fontButtonNew, fontButtonNewWithFont, -- * Methods fontButtonSetFontName, fontButtonGetFontName, fontButtonSetShowStyle, fontButtonGetShowStyle, fontButtonSetShowSize, fontButtonGetShowSize, fontButtonSetUseFont, fontButtonGetUseFont, fontButtonSetUseSize, fontButtonGetUseSize, fontButtonSetTitle, fontButtonGetTitle, -- * Properties fontButtonTitle, fontButtonUseFont, fontButtonUseSize, fontButtonShowStyle, fontButtonShowSize, -- * Signals onFontSet, afterFontSet, #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 Graphics.UI.Gtk.Types#} {#import Graphics.UI.Gtk.Signals#} {# context lib="gtk" prefix="gtk" #} #if GTK_CHECK_VERSION(2,4,0) -------------------- -- Constructors -- | Creates a new font picker widget. -- fontButtonNew :: IO FontButton fontButtonNew = makeNewObject mkFontButton $ liftM (castPtr :: Ptr Widget -> Ptr FontButton) $ {# call gtk_font_button_new #} -- | Creates a new font picker widget. -- fontButtonNewWithFont :: String -- ^ @fontname@ - Name of font to display in font selection -- dialog -> IO FontButton fontButtonNewWithFont fontname = makeNewObject mkFontButton $ liftM (castPtr :: Ptr Widget -> Ptr FontButton) $ withUTFString fontname $ \fontnamePtr -> {# call gtk_font_button_new_with_font #} fontnamePtr -------------------- -- Methods -- | Sets or updates the currently-displayed font in font picker dialog. -- fontButtonSetFontName :: FontButtonClass self => self -> String -- ^ @fontname@ - Name of font to display in font selection dialog -> IO Bool -- ^ returns Return value of 'fontSelectionDialogSetFontName' if -- the font selection dialog exists, otherwise @False@. fontButtonSetFontName self fontname = liftM toBool $ withUTFString fontname $ \fontnamePtr -> {# call gtk_font_button_set_font_name #} (toFontButton self) fontnamePtr -- | Retrieves the name of the currently selected font. -- fontButtonGetFontName :: FontButtonClass self => self -> IO String -- ^ returns an internal copy of the font name which must not be -- freed. fontButtonGetFontName self = {# call gtk_font_button_get_font_name #} (toFontButton self) >>= peekUTFString -- | If @showStyle@ is @True@, the font style will be displayed along with -- name of the selected font. -- fontButtonSetShowStyle :: FontButtonClass self => self -> Bool -- ^ @showStyle@ - @True@ if font style should be displayed in -- label. -> IO () fontButtonSetShowStyle self showStyle = {# call gtk_font_button_set_show_style #} (toFontButton self) (fromBool showStyle) -- | Returns whether the name of the font style will be shown in the label. -- fontButtonGetShowStyle :: FontButtonClass self => self -> IO Bool -- ^ returns whether the font style will be shown in the label. fontButtonGetShowStyle self = liftM toBool $ {# call gtk_font_button_get_show_style #} (toFontButton self) -- | If @showSize@ is @True@, the font size will be displayed along with the -- name of the selected font. -- fontButtonSetShowSize :: FontButtonClass self => self -> Bool -- ^ @showSize@ - @True@ if font size should be displayed in dialog. -> IO () fontButtonSetShowSize self showSize = {# call gtk_font_button_set_show_size #} (toFontButton self) (fromBool showSize) -- | Returns whether the font size will be shown in the label. -- fontButtonGetShowSize :: FontButtonClass self => self -> IO Bool -- ^ returns whether the font size will be shown in the label. fontButtonGetShowSize self = liftM toBool $ {# call gtk_font_button_get_show_size #} (toFontButton self) -- | If @useFont@ is @True@, the font name will be written using the selected -- font. -- fontButtonSetUseFont :: FontButtonClass self => self -> Bool -- ^ @useFont@ - If @True@, font name will be written using font -- chosen. -> IO () fontButtonSetUseFont self useFont = {# call gtk_font_button_set_use_font #} (toFontButton self) (fromBool useFont) -- | Returns whether the selected font is used in the label. -- fontButtonGetUseFont :: FontButtonClass self => self -> IO Bool -- ^ returns whether the selected font is used in the label. fontButtonGetUseFont self = liftM toBool $ {# call gtk_font_button_get_use_font #} (toFontButton self) -- | If @useSize@ is @True@, the font name will be written using the selected -- size. -- fontButtonSetUseSize :: FontButtonClass self => self -> Bool -- ^ @useSize@ - If @True@, font name will be written using the -- selected size. -> IO () fontButtonSetUseSize self useSize = {# call gtk_font_button_set_use_size #} (toFontButton self) (fromBool useSize) -- | Returns whether the selected size is used in the label. -- fontButtonGetUseSize :: FontButtonClass self => self -> IO Bool -- ^ returns whether the selected size is used in the label. fontButtonGetUseSize self = liftM toBool $ {# call gtk_font_button_get_use_size #} (toFontButton self) -- | Sets the title for the font selection dialog. -- fontButtonSetTitle :: FontButtonClass self => self -> String -- ^ @title@ - a string containing the font selection dialog title -> IO () fontButtonSetTitle self title = withUTFString title $ \titlePtr -> {# call gtk_font_button_set_title #} (toFontButton self) titlePtr -- | Retrieves the title of the font selection dialog. -- fontButtonGetTitle :: FontButtonClass self => self -> IO String -- ^ returns an internal copy of the title string which must not -- be freed. fontButtonGetTitle self = {# call gtk_font_button_get_title #} (toFontButton self) >>= peekUTFString -------------------- -- Properties -- | The title of the font selection dialog. -- -- Default value: \"Pick a Font\" -- fontButtonTitle :: FontButtonClass self => Attr self String fontButtonTitle = Attr fontButtonGetTitle fontButtonSetTitle -- | If this property is set to @True@, the label will be drawn in the -- selected font. -- -- Default value: @False@ -- fontButtonUseFont :: FontButtonClass self => Attr self Bool fontButtonUseFont = Attr fontButtonGetUseFont fontButtonSetUseFont -- | If this property is set to @True@, the label will be drawn with the -- selected font size. -- -- Default value: @False@ -- fontButtonUseSize :: FontButtonClass self => Attr self Bool fontButtonUseSize = Attr fontButtonGetUseSize fontButtonSetUseSize -- | If this property is set to @True@, the name of the selected font style -- will be shown in the label. For a more WYSIWIG way to show the selected -- style, see the ::use-font property. -- -- Default value: @True@ -- fontButtonShowStyle :: FontButtonClass self => Attr self Bool fontButtonShowStyle = Attr fontButtonGetShowStyle fontButtonSetShowStyle -- | If this property is set to @True@, the selected font size will be shown -- in the label. For a more WYSIWIG way to show the selected size, see the -- ::use-size property. -- -- Default value: @True@ -- fontButtonShowSize :: FontButtonClass self => Attr self Bool fontButtonShowSize = Attr fontButtonGetShowSize fontButtonSetShowSize -------------------- -- Signals -- | The ::font-set signal is emitted when the user selects a font. When -- handling this signal, use 'fontButtonGetFontName' to find out which font was -- just selected. -- onFontSet, afterFontSet :: FontButtonClass self => self -> IO () -> IO (ConnectId self) onFontSet = connect_NONE__NONE "font_set" False afterFontSet = connect_NONE__NONE "font_set" True #endif --- NEW FILE: FileFilter.chs.pp --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Widget FileFilter -- -- Author : Duncan Coutts -- -- Created: 26 February 2005 -- -- Version $Revision: 1.1 $ from $Date: 2005/04/05 18:29:52 $ -- -- Copyright (C) 2005 Duncan Coutts -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Lesser General Public -- License as published by the Free Software Foundation; either -- version 2.1 of the License, or (at your option) any later version. -- -- This library is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- Lesser General Public License for more details. -- -- | -- Maintainer : gtk...@li... -- Stability : provisional -- Portability : portable (depends on GHC) -- -- A filter for selecting a file subset -- -- * Module available since Gtk+ version 2.4 -- module Graphics.UI.Gtk.Selectors.FileFilter ( -- * Detail -- -- | A 'FileFilter' can be used to restrict the files being shown in a -- 'FileChooser'. Files can be filtered based on their name (with -- 'fileFilterAddPattern'), on their mime type (with 'fileFilterAddMimeType'), -- or by a custom filter function (with 'fileFilterAddCustom'). -- -- Filtering by mime types handles aliasing and subclassing of mime types; -- e.g. a filter for \"text\/plain\" also matches a file with mime type -- \"application\/rtf\", since \"application\/rtf\" is a subclass of -- \"text\/plain\". Note that 'FileFilter' allows wildcards for the subtype of -- a mime type, so you can e.g. filter for \"image\/\*\". -- -- Normally, filters are used by adding them to a 'FileChooser', see -- 'fileChooserAddFilter', but it is also possible to manually use a filter on -- a file with 'fileFilterFilter'. -- * Class Hierarchy -- | -- @ -- | 'GObject' -- | +----'Object' -- | +----FileFilter -- @ #if GTK_CHECK_VERSION(2,4,0) -- * Types FileFilter, FileFilterClass, castToFileFilter, -- * Constructors fileFilterNew, -- * Methods fileFilterSetName, fileFilterGetName, fileFilterAddMimeType, fileFilterAddPattern, fileFilterAddCustom, #if GTK_CHECK_VERSION(2,6,0) fileFilterAddPixbufFormats, #endif -- * Properties fileFilterName, #endif ) where import Monad (liftM) import System.Glib.FFI import System.Glib.UTFString import System.Glib.Attributes (Attr(..)) import System.Glib.GObject (mkFunPtrDestructor) {#import Graphics.UI.Gtk.Types#} import Graphics.UI.Gtk.Abstract.Object (makeNewObject) import Graphics.UI.Gtk.Gdk.Enums (Flags(..)) {# context lib="gtk" prefix="gtk" #} #if GTK_CHECK_VERSION(2,4,0) {# enum FileFilterFlags {underscoreToCase} deriving(Bounded) #} instance Flags FileFilterFlags -------------------- -- Constructors -- | Creates a new 'FileFilter' with no rules added to it. Such a filter -- doesn't accept any files, so is not particularly useful until you add rules -- with 'fileFilterAddMimeType', 'fileFilterAddPattern', or -- 'fileFilterAddCustom'. -- fileFilterNew :: IO FileFilter fileFilterNew = makeNewObject mkFileFilter $ {# call gtk_file_filter_new #} -------------------- -- Methods -- | Sets the human-readable name of the filter; this is the string that will -- be displayed in the file selector user interface if there is a selectable -- list of filters. -- fileFilterSetName :: FileFilter -> String -- ^ @name@ - the human-readable-name for the filter -> IO () fileFilterSetName self name = withUTFString name $ \namePtr -> {# call gtk_file_filter_set_name #} self namePtr -- | Gets the human-readable name for the filter. See 'fileFilterSetName'. -- fileFilterGetName :: FileFilter -> IO String -- ^ returns The human-readable name of the filter fileFilterGetName self = {# call gtk_file_filter_get_name #} self >>= peekUTFString -- | Adds a rule allowing a given mime type to @filter@. -- fileFilterAddMimeType :: FileFilter -> String -- ^ @mimeType@ - name of a MIME type -> IO () fileFilterAddMimeType self mimeType = withUTFString mimeType $ \mimeTypePtr -> {# call gtk_file_filter_add_mime_type #} self mimeTypePtr -- | Adds a rule allowing a shell style glob to a filter. -- fileFilterAddPattern :: FileFilter -> String -- ^ @pattern@ - a shell style glob -> IO () fileFilterAddPattern self pattern = withUTFString pattern $ \patternPtr -> {# call gtk_file_filter_add_pattern #} self patternPtr -- | Adds rule to a filter that allows files based on a custom callback -- function. The list of flags @needed@ which is passed in provides information -- about what sorts of information that the filter function needs; this allows -- Gtk+ to avoid retrieving expensive information when it isn't needed by the -- filter. -- fileFilterAddCustom :: FileFilter -> [FileFilterFlags] -- ^ @needed@ - list of flags indicating the -- information that the custom filter function needs. -> ( Maybe String -- filename -> Maybe String -- uri -> Maybe String -- display name -> Maybe String -- mime type -> IO Bool) -- ^ @(\filename uri displayName mimeType -> ...)@ - -- filter function; if the function -- returns @True@, then the file will be displayed. -> IO () fileFilterAddCustom self needed func = do hPtr <- mkHandler_GtkFileFilterFunc (\filterInfoPtr _ -> do filenamePtr <- {# get GtkFileFilterInfo->filename #} filterInfoPtr uriPtr <- {# get GtkFileFilterInfo->uri #} filterInfoPtr displayNamePtr <- {# get GtkFileFilterInfo->display_name #} filterInfoPtr mimeTypePtr <- {# get GtkFileFilterInfo->mime_type #} filterInfoPtr filename <- maybePeek peekUTFString filenamePtr uri <- maybePeek peekUTFString uriPtr displayName <- maybePeek peekUTFString displayNamePtr mimeType <- maybePeek peekUTFString mimeTypePtr liftM fromBool $ func filename uri displayName mimeType) dPtr <- mkFunPtrDestructor hPtr {# call gtk_file_filter_add_custom #} self ((fromIntegral . fromFlags) needed) hPtr nullPtr dPtr {#pointer GDestroyNotify#} {#pointer *GtkFileFilterInfo as GtkFileFilterInfoPtr #} foreign import ccall "wrapper" mkDestructor :: IO () -> IO GDestroyNotify type GtkFileFilterFunc = GtkFileFilterInfoPtr -> --GtkFileFilterInfo *filter_info Ptr () -> --gpointer user_data IO CInt foreign import ccall "wrapper" mkHandler_GtkFileFilterFunc :: GtkFileFilterFunc -> IO (FunPtr GtkFileFilterFunc) #if GTK_CHECK_VERSION(2,6,0) -- | Adds a rule allowing image files in the formats supported by 'Pixbuf'. -- -- * Available since Gtk version 2.6 -- fileFilterAddPixbufFormats :: FileFilter -> IO () fileFilterAddPixbufFormats self = {# call gtk_file_filter_add_pixbuf_formats #} self #endif -------------------- -- Properties -- | \'name\' property. See 'fileFilterGetName' and 'fileFilterSetName' -- fileFilterName :: Attr FileFilter String fileFilterName = Attr fileFilterGetName fileFilterSetName #endif --- NEW FILE: ColorButton.chs.pp --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Widget ColorButton -- -- Author : Duncan Coutts -- -- Created: 5 April 2005 -- -- Version $Revision: 1.1 $ from $Date: 2005/04/05 18:29:52 $ -- -- Copyright (C) 2005 Duncan Coutts -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Lesser General Public -- License as published by the Free Software Foundation; either -- version 2.1 of the License, or (at your option) any later version. -- -- This library is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- Lesser General Public License for more details. -- -- | -- Maintainer : gtk...@li... -- Stability : provisional -- Portability : portable (depends on GHC) -- -- A button to launch a color selection dialog -- -- * Module available since Gtk+ version 2.4 -- module Graphics.UI.Gtk.Selectors.ColorButton ( -- * Detail -- -- | The 'ColorButton' is a button which displays the currently selected color -- an allows to open a color selection dialog to change the color. It is -- suitable widget for selecting a color in a preference dialog. -- * Class Hierarchy -- | -- @ -- | 'GObject' -- | +----'Object' -- | +----'Widget' -- | +----'Container' -- | +----'Bin' -- | +----'Button' -- | +----ColorButton -- @ #if GTK_CHECK_VERSION(2,4,0) -- * Types ColorButton, ColorButtonClass, castToColorButton, -- * Constructors colorButtonNew, colorButtonNewWithColor, -- * Methods colorButtonSetColor, colorButtonGetColor, colorButtonSetAlpha, colorButtonGetAlpha, colorButtonSetUseAlpha, colorButtonGetUseAlpha, colorButtonSetTitle, colorButtonGetTitle, -- * Properties colorButtonUseAlpha, colorButtonTitle, colorButtonAlpha, -- * Signals onColorSet, afterColorSet, #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 Graphics.UI.Gtk.Types#} {#import Graphics.UI.Gtk.Signals#} import Graphics.UI.Gtk.General.Structs (Color) {# context lib="gtk" prefix="gtk" #} #if GTK_CHECK_VERSION(2,4,0) -------------------- -- Constructors -- | Creates a new color button. This returns a widget in the form of a small -- button containing a swatch representing the current selected color. When the -- button is clicked, a color-selection dialog will open, allowing the user to -- select a color. The swatch will be updated to reflect the new color when the -- user finishes. -- colorButtonNew :: IO ColorButton colorButtonNew = makeNewObject mkColorButton $ liftM (castPtr :: Ptr Widget -> Ptr ColorButton) $ {# call gtk_color_button_new #} -- | Creates a new color button. -- colorButtonNewWithColor :: Color -- ^ @color@ - A 'Color' to set the current color with. -> IO ColorButton colorButtonNewWithColor color = makeNewObject mkColorButton $ liftM (castPtr :: Ptr Widget -> Ptr ColorButton) $ with color $ \colorPtr -> {# call gtk_color_button_new_with_color #} (castPtr colorPtr) -------------------- -- Methods -- | Sets the current color to be @color@. -- colorButtonSetColor :: ColorButtonClass self => self -> Color -- ^ @color@ - A 'Color' to set the current color with. -> IO () colorButtonSetColor self color = with color $ \colorPtr -> {# call gtk_color_button_set_color #} (toColorButton self) (castPtr colorPtr) -- | Sets @color@ to be the current color in the 'ColorButton' widget. -- colorButtonGetColor :: ColorButtonClass self => self -> IO Color colorButtonGetColor self = alloca $ \colorPtr -> {# call gtk_color_button_get_color #} (toColorButton self) (castPtr colorPtr) >> peek colorPtr >>= \color -> return color -- | Sets the current opacity to be @alpha@. -- colorButtonSetAlpha :: ColorButtonClass self => self -> Word16 -- ^ @alpha@ - an integer between 0 and 65535. -> IO () colorButtonSetAlpha self alpha = {# call gtk_color_button_set_alpha #} (toColorButton self) (fromIntegral alpha) -- | Returns the current alpha value. -- colorButtonGetAlpha :: ColorButtonClass self => self -> IO Word16 -- ^ returns an integer between 0 and 65535. colorButtonGetAlpha self = liftM fromIntegral $ {# call gtk_color_button_get_alpha #} (toColorButton self) -- | Sets whether or not the color button should use the alpha channel. -- colorButtonSetUseAlpha :: ColorButtonClass self => self -> Bool -- ^ @useAlpha@ - @True@ if color button should use alpha channel, -- @False@ if not. -> IO () colorButtonSetUseAlpha self useAlpha = {# call gtk_color_button_set_use_alpha #} (toColorButton self) (fromBool useAlpha) -- | Does the color selection dialog use the alpha channel? -- colorButtonGetUseAlpha :: ColorButtonClass self => self -> IO Bool -- ^ returns @True@ if the color sample uses alpha channel, -- @False@ if not. colorButtonGetUseAlpha self = liftM toBool $ {# call gtk_color_button_get_use_alpha #} (toColorButton self) -- | Sets the title for the color selection dialog. -- colorButtonSetTitle :: ColorButtonClass self => self -> String -- ^ @title@ - String containing new window title. -> IO () colorButtonSetTitle self title = withUTFString title $ \titlePtr -> {# call gtk_color_button_set_title #} (toColorButton self) titlePtr -- | Gets the title of the color selection dialog. -- colorButtonGetTitle :: ColorButtonClass self => self -> IO String -- ^ returns An internal string, do not free the return value colorButtonGetTitle self = {# call gtk_color_button_get_title #} (toColorButton self) >>= peekUTFString -------------------- -- Properties -- | If this property is set to @True@, the color swatch on the button is -- rendered against a checkerboard background to show its opacity and the -- opacity slider is displayed in the color selection dialog. -- -- Default value: @False@ -- colorButtonUseAlpha :: ColorButtonClass self => Attr self Bool colorButtonUseAlpha = Attr colorButtonGetUseAlpha colorButtonSetUseAlpha -- | The title of the color selection dialog -- -- Default value: \"Pick a Color\" -- colorButtonTitle :: ColorButtonClass self => Attr self String colorButtonTitle = Attr colorButtonGetTitle colorButtonSetTitle -- | The selected opacity value (0 fully transparent, 65535 fully opaque). -- -- Allowed values: \<= 65535 -- -- Default value: 65535 -- colorButtonAlpha :: ColorButtonClass self => Attr self Word16 colorButtonAlpha = Attr colorButtonGetAlpha colorButtonSetAlpha -------------------- -- Signals -- | The ::color-set signal is emitted when the user selects a color. When -- handling this signal, use 'colorButtonGetColor' and 'colorButtonGetAlpha' to -- find out which color was just selected. -- onColorSet, afterColorSet :: ColorButtonClass self => self -> IO () -> IO (ConnectId self) onColorSet = connect_NONE__NONE "color_set" False afterColorSet = connect_NONE__NONE "color_set" True #endif --- NEW FILE: FileChooserButton.chs.pp --- -- -*-haskell-*- -- GIMP Toolkit (GTK) Widget FileChooserButton -- -- Author : [Insert your full name here] -- -- Created: 5 April 2005 -- -- Version $Revision: 1.1 $ from $Date: 2005/04/05 18:29:52 $ -- -- Copyright (C) 2005 [Insert your full name here] -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Lesser General Public -- License as published by the Free Software Foundation; either -- version 2.1 of the License, or (at your option) any later version. -- -- This library is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- Lesser General Public License for more details. -- -- | -- Maintainer : gtk...@li... -- Stability : provisional -- Portability : portable (depends on GHC) -- -- A button to launch a file selection dialog -- -- * Module available since Gtk+ version 2.6 -- module Graphics.UI.Gtk.Selectors.FileChooserButton ( -- * Detail -- -- | The 'FileChooserButton' is a widget that lets the user select a file. It -- implements the 'FileChooser' interface. Visually, it is a file name with a -- button to bring up a 'FileChooserDialog'. The user can then use that dialog -- to change the file associated with that button. This widget does not support -- setting the \"select-multiple\" property to @True@. -- -- The 'FileChooserButton' supports the 'FileChooserAction's -- 'FileChooserActionOpen' and 'FileChooserActionSelectFolder'. -- * Class Hierarchy -- | -- @ -- | 'GObject' -- | +----'Object' -- | +----'Widget' -- | +----'Container' -- | +----'Box' -- | +----'HBox' -- | +----FileChooserButton -- @ #if GTK_CHECK_VERSION(2,6,0) -- * Types FileChooserButton, FileChooserButtonClass, castToFileChooserButton, -- * Constructors fileChooserButtonNew, fileChooserButtonNewWithBackend, fileChooserButtonNewWithDialog, -- * Methods fileChooserButtonGetTitle, fileChooserButtonSetTitle, fileChooserButtonGetWidthChars, fileChooserButtonSetWidthChars, -- * Properties fileChooserButtonTitle, fileChooserButtonWidthChars, #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 Graphics.UI.Gtk.Types#} {#import Graphics.UI.Gtk.Selectors.FileChooser#} (FileChooserAction) {# context lib="gtk" prefix="gtk" #} #if GTK_CHECK_VERSION(2,6,0) -------------------- -- Constructors -- | Creates a new file-selecting button widget. -- fileChooserButtonNew :: String -- ^ @title@ - the title of the browse dialog. -> FileChooserAction -- ^ @action@ - the open mode for the widget. -> IO FileChooserButton fileChooserButtonNew title action = makeNewObject mkFileChooserButton $ liftM (castPtr :: Ptr Widget -> Ptr FileChooserButton) $ withUTFString title $ \titlePtr -> {# call gtk_file_chooser_button_new #} titlePtr ((fromIntegral . fromEnum) action) -- | Creates a new file-selecting button widget using @backend@. -- fileChooserButtonNewWithBackend :: String -- ^ @title@ - the title of the browse dialog. -> FileChooserAction -- ^ @action@ - the open mode for the widget. -> String -- ^ @backend@ - the name of the file system backend -- to use. -> IO FileChooserButton fileChooserButtonNewWithBackend title action backend = makeNewObject mkFileChooserButton $ liftM (castPtr :: Ptr Widget -> Ptr FileChooserButton) $ withUTFString backend $ \backendPtr -> withUTFString title $ \titlePtr -> {# call gtk_file_chooser_button_new_with_backend #} titlePtr ((fromIntegral . fromEnum) action) backendPtr -- | Creates a 'FileChooserButton' widget which uses @dialog@ as it's -- file-picking window. -- fileChooserButtonNewWithDialog :: FileChooserDialogClass dialog => dialog -- ^ @dialog@ - the 'FileChooserDialog' widget to -- use. -> IO FileChooserButton fileChooserButtonNewWithDialog dialog = makeNewObject mkFileChooserButton $ liftM (castPtr :: Ptr Widget -> Ptr FileChooserButton) $ {# call gtk_file_chooser_button_new_with_dialog #} (toWidget dialog) -------------------- -- Methods -- | Retrieves the title of the browse dialog used by the button. -- fileChooserButtonGetTitle :: FileChooserButtonClass self => self -> IO String -- ^ returns a pointer to the browse dialog's title. fileChooserButtonGetTitle self = {# call gtk_file_chooser_button_get_title #} (toFileChooserButton self) >>= peekUTFString -- | Modifies the @title@ of the browse dialog used by the button. -- fileChooserButtonSetTitle :: FileChooserButtonClass self => self -> String -- ^ @title@ - the new browse dialog title. -> IO () fileChooserButtonSetTitle self title = withUTFString title $ \titlePtr -> {# call gtk_file_chooser_button_set_title #} (toFileChooserButton self) titlePtr -- | Retrieves the width in characters of the @button@ widget's entry and\/or -- label. -- fileChooserButtonGetWidthChars :: FileChooserButtonClass self => self -> IO Int -- ^ returns an integer width (in characters) that the button will -- use to size itself. fileChooserButtonGetWidthChars self = liftM fromIntegral $ {# call gtk_file_chooser_button_get_width_chars #} (toFileChooserButton self) -- | Sets the width (in characters) that the button will use to @nChars@. -- fileChooserButtonSetWidthChars :: FileChooserButtonClass self => self -> Int -- ^ @nChars@ - the new width, in characters. -> IO () fileChooserButtonSetWidthChars self nChars = {# call gtk_file_chooser_button_set_width_chars #} (toFileChooserButton self) (fromIntegral nChars) -------------------- -- Properties -- | Title to put on the 'FileChooserDialog' associated with the button. -- -- Default value: \"Select A File\" -- fileChooserButtonTitle :: FileChooserButtonClass self => Attr self String fileChooserButtonTitle = Attr fileChooserButtonGetTitle fileChooserButtonSetTitle -- | -- fileChooserButtonWidthChars :: FileChooserButtonClass self => Attr self Int fileChooserButtonWidthChars = Attr fileChooserButtonGetWidthChars fileChooserButtonSetWidthChars #endif |