1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget FontButton
--
-- Author : Duncan Coutts
--
-- Created: 5 April 2005
--
-- 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 : gtk2hs-users@lists.sourceforge.net
-- 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, gTypeFontButton,
toFontButton,
-- * Constructors
fontButtonNew,
fontButtonNewWithFont,
-- * Methods
fontButtonSetFontName,
fontButtonGetFontName,
fontButtonSetShowStyle,
fontButtonGetShowStyle,
fontButtonSetShowSize,
fontButtonGetShowSize,
fontButtonSetUseFont,
fontButtonGetUseFont,
fontButtonSetUseSize,
fontButtonGetUseSize,
fontButtonSetTitle,
fontButtonGetTitle,
-- * Attributes
fontButtonTitle,
fontButtonFontName,
fontButtonUseFont,
fontButtonUseSize,
fontButtonShowStyle,
fontButtonShowSize,
-- * Signals
onFontSet,
afterFontSet,
#endif
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Attributes
import System.Glib.Properties
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 'Graphics.UI.Gtk.Selectors.FontSelectionDialog.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
--------------------
-- Attributes
-- | The title of the font selection dialog.
--
-- Default value: \"Pick a Font\"
--
fontButtonTitle :: FontButtonClass self => Attr self String
fontButtonTitle = newAttr
fontButtonGetTitle
fontButtonSetTitle
-- | The name of the currently selected font.
--
-- Default value: \"Sans 12\"
--
fontButtonFontName :: FontButtonClass self => Attr self String
fontButtonFontName = newAttrFromStringProperty "font-name"
-- | 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 = newAttr
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 = newAttr
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 = newAttr
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 = newAttr
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
|