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 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) CellRendererText TreeView
--
-- Author : Axel Simon
--
-- Created: 23 May 2001
--
-- Copyright (C) 1999-2006 Axel Simon
--
-- 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 'CellRenderer' which displays a single-line text.
--
module Graphics.UI.Gtk.ModelView.CellRendererText (
-- * Detail
--
-- | A 'CellRendererText' renders a given text in its cell, using the font,
-- color and style information provided by its attributes. The text will be
-- ellipsized if it is too long and the ellipsize property allows it.
--
-- If the 'cellMode' is 'CellRendererModeEditable', the 'CellRendererText'
-- allows the user to edit its text using an 'Entry' widget.
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'CellRenderer'
-- | +----CellRendererText
-- | +----'CellRendererCombo'
-- @
-- * Types
CellRendererText,
CellRendererTextClass,
castToCellRendererText, gTypeCellRendererText,
toCellRendererText,
-- * Constructors
cellRendererTextNew,
-- * Methods
cellRendererTextSetFixedHeightFromFont,
-- * Attributes
cellText,
cellTextMarkup,
--cellTextAttributes,
cellTextSingleParagraphMode,
cellTextBackground,
cellTextBackgroundColor,
cellTextBackgroundSet,
cellTextForeground,
cellTextForegroundColor,
cellTextForegroundSet,
cellTextEditable,
cellTextEditableSet,
cellTextFont,
cellTextFontDesc,
cellTextFamily,
cellTextFamilySet,
cellTextStyle,
cellTextStyleSet,
cellTextVariant,
cellTextVariantSet,
cellTextWeight,
cellTextWeightSet,
cellTextStretch,
cellTextStretchSet,
cellTextSize,
cellTextSizePoints,
cellTextSizeSet,
cellTextScale,
cellTextScaleSet,
cellTextRise,
cellTextRiseSet,
cellTextStrikethrough,
cellTextStrikethroughSet,
cellTextUnderline,
cellTextUnderlineSet,
cellTextLanguage,
cellTextLanguageSet,
#if GTK_CHECK_VERSION(2,6,0)
cellTextEllipsize,
cellTextEllipsizeSet,
cellTextWidthChars,
#endif
#if GTK_CHECK_VERSION(2,8,0)
cellTextWrapMode,
cellTextWrapWidth,
#endif
#if GTK_CHECK_VERSION(2,10,0)
cellTextAlignment,
#endif
-- * Signals
edited,
-- * Deprecated
#ifndef DISABLE_DEPRECATED
onEdited,
afterEdited
#endif
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.Properties
import System.Glib.Attributes (Attr, WriteAttr)
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
{#import Graphics.UI.Gtk.Types#}
{#import Graphics.UI.Gtk.Signals#}
{#import Graphics.UI.Gtk.ModelView.Types#}
import Graphics.UI.Gtk.General.Structs (Color(..))
import Graphics.Rendering.Pango.Enums
{#import Graphics.Rendering.Pango.BasicTypes#} ( FontDescription(..),
makeNewFontDescription )
{#import Graphics.Rendering.Pango.Layout#} ( LayoutAlignment, LayoutWrapMode )
{# context lib="gtk" prefix="gtk" #}
--------------------
-- Constructors
-- | Create a new CellRendererText object.
--
cellRendererTextNew :: IO CellRendererText
cellRendererTextNew =
makeNewObject mkCellRendererText $
liftM (castPtr :: Ptr CellRenderer -> Ptr CellRendererText) $
{# call unsafe cell_renderer_text_new #}
--------------------
-- Methods
-- | Sets the height of a renderer to explicitly be determined by the
-- 'cellTextFont' and 'Graphics.UI.Gtk.ModelView.CellRenderer.cellYPad'
-- attribute set on it. Further changes in these properties do not affect the
-- height, so they must be accompanied by a subsequent call to this function.
-- Using this function is unflexible, and should really only be used if
-- calculating the size of a cell is too slow (ie, a massive number of cells
-- displayed). If @numberOfRows@ is -1, then the fixed height is unset, and
-- the height is determined by the properties again.
--
cellRendererTextSetFixedHeightFromFont :: CellRendererTextClass self => self
-> Int -- ^ @numberOfRows@ - Number of rows of text each cell renderer is
-- allocated, or -1
-> IO ()
cellRendererTextSetFixedHeightFromFont self numberOfRows =
{# call gtk_cell_renderer_text_set_fixed_height_from_font #}
(toCellRendererText self)
(fromIntegral numberOfRows)
--------------------
-- Properties
-- | Text background color as a string.
--
-- Default value: @\"\"@
--
cellTextBackground :: CellRendererClass self => WriteAttr self String
cellTextBackground = writeAttrFromStringProperty "background"
-- | Text background color as a 'Color'.
--
cellTextBackgroundColor :: CellRendererClass self => Attr self Color
cellTextBackgroundColor = newAttrFromBoxedStorableProperty "background-gdk"
{# call pure unsafe gdk_color_get_type #}
-- | Whether the 'cellTextBackground'\/'cellTextBackgroundColor' attribute is set.
--
-- Default value: @False@
--
cellTextBackgroundSet :: CellRendererClass self => Attr self Bool
cellTextBackgroundSet = newAttrFromBoolProperty "background-set"
-- | Whether the text can be modified by the user.
--
cellTextEditable :: CellRendererTextClass self => Attr self Bool
cellTextEditable = newAttrFromBoolProperty "editable"
-- | Whether the 'cellTextEditable' flag affects text editability.
--
cellTextEditableSet :: CellRendererTextClass self => Attr self Bool
cellTextEditableSet = newAttrFromBoolProperty "editable-set"
#if GTK_CHECK_VERSION(2,6,0)
-- | Specifies the preferred place to ellipsize the string, if the cell
-- renderer does not have enough room to display the entire string.
-- Setting it to 'Graphics.Rendering.Pango.Enums.EllipsizeNone' turns off
-- ellipsizing. See the 'cellTextWrapWidth' property for another way of
-- making the text fit into a given width.
--
-- * Available in Gtk 2.6 or higher.
--
cellTextEllipsize :: CellRendererTextClass self => Attr self EllipsizeMode
cellTextEllipsize = newAttrFromEnumProperty "ellipsize"
{# call pure pango_ellipsize_mode_get_type #}
-- | Whether the 'cellTextEllipsize' tag affects the ellipsize mode.
--
-- * Available in Gtk 2.6 or higher.
--
cellTextEllipsizeSet :: CellRendererTextClass self => Attr self Bool
cellTextEllipsizeSet = newAttrFromBoolProperty "ellipsize-set"
#endif
-- | Name of the font family, e.g. Sans, Helvetica, Times, Monospace.
--
cellTextFamily :: CellRendererTextClass self => Attr self String
cellTextFamily = newAttrFromStringProperty "family"
-- | Determines if 'cellTextFamily' has an effect.
--
cellTextFamilySet :: CellRendererTextClass self => Attr self Bool
cellTextFamilySet = newAttrFromBoolProperty "family-set"
-- | Font description as a string.
--
cellTextFont :: CellRendererTextClass self => Attr self String
cellTextFont = newAttrFromStringProperty "font"
-- | Font description as a 'Graphics.Rendering.Pango.FontDescription'.
--
cellTextFontDesc :: CellRendererTextClass self => Attr self FontDescription
cellTextFontDesc = newAttrFromBoxedOpaqueProperty makeNewFontDescription
(\(FontDescription fd) act -> withForeignPtr fd act) "font-desc"
{# call pure unsafe pango_font_description_get_type #}
-- | Text foreground color as a string.
--
-- Default value: @\"\"@
--
cellTextForeground :: CellRendererClass self => WriteAttr self String
cellTextForeground = writeAttrFromStringProperty "foreground"
-- | Text foreground color as a 'Color'.
--
cellTextForegroundColor :: CellRendererClass self => Attr self Color
cellTextForegroundColor = newAttrFromBoxedStorableProperty "foreground-gdk"
{# call pure unsafe gdk_color_get_type #}
-- | Whether the 'cellTextForeground'\/'cellTextForegroundColor' attribute is set.
--
-- Default value: @False@
--
cellTextForegroundSet :: CellRendererClass self => Attr self Bool
cellTextForegroundSet = newAttrFromBoolProperty "foreground-set"
-- | The language this text is in, as an ISO code. Pango can use this as
-- a hint when rendering the text. If you don't understand this parameter,
-- you probably don't need it.
--
cellTextLanguage :: CellRendererTextClass self => Attr self (Maybe String)
cellTextLanguage = newAttrFromMaybeStringProperty "language"
-- | Whether the 'cellTextLanguage' tag is used, default is @False@.
--
cellTextLanguageSet :: CellRendererTextClass self => Attr self Bool
cellTextLanguageSet = newAttrFromBoolProperty "language-set"
-- | Define a markup string instead of a text. See 'cellText'.
--
cellTextMarkup :: CellRendererTextClass cr => WriteAttr cr (Maybe String)
cellTextMarkup = writeAttrFromMaybeStringProperty "markup"
-- %hash c:4e25 d:f7c6
-- | Offset of text above the baseline (below the baseline if rise is
-- negative).
--
-- Allowed values: >= -2147483647
--
-- Default value: 0
--
cellTextRise :: CellRendererTextClass self => Attr self Int
cellTextRise = newAttrFromIntProperty "rise"
-- | Whether the 'cellTextRise' tag is used, default is @False@.
--
cellTextRiseSet :: CellRendererTextClass self => Attr self Bool
cellTextRiseSet = newAttrFromBoolProperty "rise-set"
-- | Font scaling factor. Default is 1.
--
cellTextScale :: CellRendererTextClass self => Attr self Double
cellTextScale = newAttrFromDoubleProperty "scale"
-- | Whether the 'cellTextScale' tag is used, default is @False@.
--
cellTextScaleSet :: CellRendererTextClass self => Attr self Bool
cellTextScaleSet = newAttrFromBoolProperty "scale-set"
-- %hash c:d85f d:9cfb
-- | Whether or not to keep all text in a single paragraph.
--
-- Default value: @False@
--
cellTextSingleParagraphMode :: CellRendererTextClass self => Attr self Bool
cellTextSingleParagraphMode = newAttrFromBoolProperty "single-paragraph-mode"
-- | Font size in points.
--
cellTextSize :: CellRendererTextClass self => Attr self Double
cellTextSize = newAttrFromDoubleProperty "size-points"
-- %hash c:d281 d:3b0c
-- | Font size in points.
--
-- Allowed values: >= 0
--
-- Default value: 0
--
cellTextSizePoints :: CellRendererTextClass self => Attr self Double
cellTextSizePoints = newAttrFromDoubleProperty "size-points"
-- | Whether the 'cellTextSize' tag is used, default is @False@.
--
cellTextSizeSet :: CellRendererTextClass self => Attr self Bool
cellTextSizeSet = newAttrFromBoolProperty "size-set"
-- | Font stretch.
--
cellTextStretch :: CellRendererTextClass self => Attr self Stretch
cellTextStretch = newAttrFromEnumProperty "stretch"
{# call pure pango_stretch_get_type #}
-- | Whether the 'cellTextStretch' tag is used, default is @False@.
--
cellTextStretchSet :: CellRendererTextClass self => Attr self Bool
cellTextStretchSet = newAttrFromBoolProperty "stretch-set"
-- | Whether to strike through the text.
--
cellTextStrikethrough :: CellRendererTextClass self => Attr self Bool
cellTextStrikethrough = newAttrFromBoolProperty "strikethrough"
-- | Whether the 'cellTextStrikethrough' tag is used, default is @False@.
--
cellTextStrikethroughSet :: CellRendererTextClass self => Attr self Bool
cellTextStrikethroughSet = newAttrFromBoolProperty "strikethrough-set"
-- | Font style (e.g. normal or italics).
--
cellTextStyle :: CellRendererTextClass self => Attr self FontStyle
cellTextStyle = newAttrFromEnumProperty "style"
{# call pure pango_style_get_type #}
-- | Whether the 'cellTextStyle' tag is used, default is @False@.
--
cellTextStyleSet :: CellRendererTextClass self => Attr self Bool
cellTextStyleSet = newAttrFromBoolProperty "style-set"
-- | Define the attribute that specifies the text to be rendered. See
-- also 'cellTextMarkup'.
--
cellText :: CellRendererTextClass cr => Attr cr String
cellText = newAttrFromStringProperty "text"
-- | Style of underline for this text.
--
cellTextUnderline :: CellRendererTextClass self => Attr self Underline
cellTextUnderline = newAttrFromEnumProperty "underline"
{# call pure pango_underline_get_type #}
-- | Whether the 'cellTextUnderline' tag is used, default is @False@.
--
cellTextUnderlineSet :: CellRendererTextClass self => Attr self Bool
cellTextUnderlineSet = newAttrFromBoolProperty "underline-set"
-- | Font variant (e.g. small caps).
--
cellTextVariant :: CellRendererTextClass self => Attr self Variant
cellTextVariant = newAttrFromEnumProperty "variant"
{# call pure pango_variant_get_type #}
-- | Whether the 'cellTextVariant' tag is used, default is @False@.
--
cellTextVariantSet :: CellRendererTextClass self => Attr self Bool
cellTextVariantSet = newAttrFromBoolProperty "variant-set"
-- | Font weight, default: 400.
--
cellTextWeight :: CellRendererTextClass self => Attr self Int
cellTextWeight = newAttrFromIntProperty "weight"
-- | Whether the 'cellTextWeight' tag is used, default is @False@.
--
cellTextWeightSet :: CellRendererTextClass self => Attr self Bool
cellTextWeightSet = newAttrFromBoolProperty "weight-set"
#if GTK_CHECK_VERSION(2,6,0)
-- | The desired width of the cell, in characters. If this property is set
-- to @-1@, the width will be calculated automatically, otherwise the cell
-- will request either 3 characters or the property value, whichever is
-- greater.
--
-- * Available in Gtk 2.6 or higher.
--
cellTextWidthChars :: CellRendererTextClass self => Attr self Int
cellTextWidthChars = newAttrFromIntProperty "width-chars"
#endif
#if GTK_CHECK_VERSION(2,8,0)
-- | Specifies how to break the string into multiple lines, if the cell
-- renderer does not have enough room to display the entire string.
-- This property has no effect unless the 'cellTextWrapWidth' property is set.
--
-- * Available in Gtk 2.8 or higher.
--
cellTextWrapMode :: CellRendererTextClass self => Attr self LayoutWrapMode
cellTextWrapMode = newAttrFromEnumProperty "wrap-mode"
{# call pure pango_wrap_mode_get_type #}
-- | Specifies the width at which the text is wrapped. The wrap-mode
-- property can be used to influence at what character positions the
-- line breaks can be placed. Setting wrap-width to @-1@ turns wrapping off.
--
-- * Available in Gtk 2.8 or higher.
--
cellTextWrapWidth :: CellRendererTextClass self => Attr self Int
cellTextWrapWidth = newAttrFromIntProperty "wrap-width"
#endif
#if GTK_CHECK_VERSION(2,10,0)
-- %hash c:a59c d:a84a
-- | Specifies how to align the lines of text with respect to each other.
--
-- Note that this property describes how to align the lines of text in case
-- there are several of them. The
-- 'Graphics.UI.Gtk.ModelView.CellRenderer.cellXAlign' property of
-- 'CellRenderer', on the other hand, sets the horizontal alignment of the
-- whole text.
--
-- Default value: 'Graphics.Rendering.Pango.Layout.AlignLeft'
--
-- * Available since Gtk+ version 2.10
--
cellTextAlignment :: CellRendererTextClass self => Attr self LayoutAlignment
cellTextAlignment = newAttrFromEnumProperty "alignment"
{# call pure unsafe pango_alignment_get_type #}
#endif
--------------------
-- Signals
-- %hash c:a541 d:18f9
-- | Emitted when the user finished editing a cell.
--
-- Whenever editing is finished successfully, this signal is emitted which
-- indicates that the model should be updated with the supplied value.
-- The value is always a string which matches the 'cellText' attribute of
-- 'CellRendererText' (and its derivates like 'CellRendererCombo').
--
-- * This signal is not emitted when editing is disabled (see
-- 'cellTextEditable') or when the user aborts editing.
--
edited :: CellRendererTextClass self =>
Signal self (TreePath -> String -> IO ())
edited = Signal internalEdited
--------------------
-- Deprecated Signals
#ifndef DISABLE_DEPRECATED
-- %hash c:76ed
onEdited :: CellRendererTextClass self => self
-> (TreePath -> String -> IO ())
-> IO (ConnectId self)
onEdited = internalEdited False
{-# DEPRECATED onEdited "instead of 'onEdited obj' use 'on obj edited'" #-}
-- %hash c:f70c
afterEdited :: CellRendererTextClass self => self
-> (TreePath -> String -> IO ())
-> IO (ConnectId self)
afterEdited = internalEdited True
{-# DEPRECATED afterEdited "instead of 'afterEdited obj' use 'after obj edited'" #-}
#endif
internalEdited :: CellRendererTextClass cr =>
Bool -> cr ->
(TreePath -> String -> IO ()) ->
IO (ConnectId cr)
internalEdited after cr user =
connect_STRING_STRING__NONE "edited" after cr $ \path string -> do
user (stringToTreePath path) string
|