File: CellRenderer.chs

package info (click to toggle)
haskell-gtk 0.11.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,920 kB
  • ctags: 82
  • sloc: haskell: 1,929; ansic: 714; sh: 5; makefile: 3
file content (365 lines) | stat: -rw-r--r-- 10,925 bytes parent folder | download | duplicates (2)
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
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
--  GIMP Toolkit (GTK) CellRenderer 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)
--
-- An object for rendering a cell in a list, icon or combo box widget.
--
module Graphics.UI.Gtk.ModelView.CellRenderer (
-- * Detail
--	 
-- | The 'CellRenderer' is a base class of a set of objects used for rendering
-- a cell to a 'Drawable'. These objects are used primarily by the 'TreeView'
-- widget, though they aren't tied to them in any specific way. It is worth
-- noting that 'CellRenderer' is not a 'Widget' and cannot be treated as such.
--
-- The primary use of a 'CellRenderer' is for drawing a certain graphical
-- elements on a 'Drawable'. Typically, one cell renderer is used to draw many
-- cells on the screen. To this extent, it isn't expected that a
-- 'CellRenderer' keep any permanent state around. Instead, any state is set
-- just prior to use by changing the attributes of the cell. Then, the cell is
-- measured and rendered in the correct location.
--
-- Beyond merely rendering a cell, cell renderers can optionally provide
-- active user interface elements. A cell renderer can be activatable like
-- 'Graphics.UI.Gtk.ModelView.CellRendererToggle', which toggles when it gets
-- activated by a mouse click, or it can be editable like
-- 'Graphics.UI.Gtk.ModelView.CellRendererText', which allows the user to edit
-- the text using a 'Graphics.UI.Gtk.Entry.Entry'.

-- * Class Hierarchy
-- |
-- @
-- |  'GObject'
-- |   +----'Object'
-- |         +----CellRenderer
-- |               +----'CellRendererText'
-- |               +----'CellRendererPixbuf'
-- |               +----'CellRendererProgress'
-- |               +----'CellRendererCombo'
-- |               +----'CellRendererToggle'
-- @

-- * Types
  CellRenderer,
  CellRendererClass,
  castToCellRenderer, gTypeCellRenderer,
  toCellRenderer,
  CellRendererMode,

-- * Methods
#if GTK_CHECK_VERSION(2,6,0)
  cellRendererStopEditing,
#endif
  cellRendererGetFixedSize,
  cellRendererSetFixedSize,

-- * Attributes
  cellMode,
  cellVisible,
  cellSensitive,
  cellXAlign,
  cellYAlign,
  cellXPad,
  cellYPad,
  cellWidth,
  cellHeight,
  cellIsExpander,
  cellIsExpanded,
  cellBackground,
  cellBackgroundColor,
  cellBackgroundSet,

-- * Signals
#if GTK_CHECK_VERSION(2,6,0)
  editingStarted,
#endif
#if GTK_CHECK_VERSION(2,4,0)
  editingCanceled,
#endif

-- * Deprecated
#ifndef DISABLE_DEPRECATED
#if GTK_CHECK_VERSION(2,6,0)
  onEditingStarted,
  afterEditingStarted,
#endif
#if GTK_CHECK_VERSION(2,4,0)
  onEditingCanceled,
  afterEditingCanceled,
#endif
#endif
  ) where

import System.Glib.FFI
import System.Glib.Attributes ( Attr, WriteAttr )
import System.Glib.Properties
{#import Graphics.UI.Gtk.Types#}
import Graphics.UI.Gtk.Gdk.GC		(Color)
{#import Graphics.UI.Gtk.Signals#}
{#import Graphics.UI.Gtk.ModelView.Types#}

{#context lib="gtk" prefix ="gtk"#}

{# enum CellRendererMode {underscoreToCase} deriving (Eq) #}


#if GTK_CHECK_VERSION(2,6,0)
-- %hash c:75b3 d:45ca
-- | Informs the cell renderer that the editing is stopped. If @canceled@ is
-- @True@, the cell renderer will emit the 'editingCanceled' signal.
--
-- * Available since Gtk+ version 2.6
--
cellRendererStopEditing :: CellRendererClass self => self
 -> Bool -- ^ @canceled@ - @True@ if the editing has been canceled
 -> IO ()
cellRendererStopEditing self canceled =
  {# call gtk_cell_renderer_stop_editing #}
    (toCellRenderer self)
    (fromBool canceled)
#endif

-- %hash c:6d51 d:dc3e
-- | Returns	@(width, height)@	denoting the size of the fixed size of
-- @cell@. If no fixed size is set, returns @-1@ for that value.
--
cellRendererGetFixedSize :: CellRendererClass self => self
 -> IO (Int, Int) -- ^ @(width, height)@
cellRendererGetFixedSize self =
  alloca $ \widthPtr ->
  alloca $ \heightPtr ->
  {# call gtk_cell_renderer_get_fixed_size #}
    (toCellRenderer self)
    widthPtr
    heightPtr >>
  peek widthPtr >>= \width ->
  peek heightPtr >>= \height ->
  return (fromIntegral width, fromIntegral height)

-- %hash c:85dc d:5fd4
-- | Sets the renderer size to be explicit, independent of the properties set.
--
cellRendererSetFixedSize :: CellRendererClass self => self
 -> Int -- ^ @width@ - the width of the cell renderer, or -1
 -> Int -- ^ @height@ - the height of the cell renderer, or -1
 -> IO ()
cellRendererSetFixedSize self width height =
  {# call gtk_cell_renderer_set_fixed_size #}
    (toCellRenderer self)
    (fromIntegral width)
    (fromIntegral height)

--------------------
-- Attributes

-- | Editable mode of the CellRenderer.
--
-- Default value: 'CellRendererModeInert'
--
cellMode :: CellRendererClass self => Attr self CellRendererMode
cellMode = newAttrFromEnumProperty "mode"
  {# call pure unsafe gtk_cell_renderer_mode_get_type #}

-- | Display the cell.
--
-- Default value: @True@
--
cellVisible :: CellRendererClass self => Attr self Bool
cellVisible = newAttrFromBoolProperty "visible"

-- | Display the cell sensitive.
--
-- Default value: @True@
--
cellSensitive :: CellRendererClass self => Attr self Bool
cellSensitive = newAttrFromBoolProperty "sensitive"

-- | The x-align.
--
-- Allowed values: @[0,1]@
--
-- Default value: @0.5@
--
cellXAlign :: CellRendererClass self => Attr self Float
cellXAlign = newAttrFromFloatProperty "xalign"

-- | The y-align.
--
-- Allowed values: @[0,1]@
--
-- Default value: @0.5@
--
cellYAlign :: CellRendererClass self => Attr self Float
cellYAlign = newAttrFromFloatProperty "yalign"

-- | The xpad.
--
-- Default value: @0@
--
cellXPad :: CellRendererClass self => Attr self Int
cellXPad = newAttrFromUIntProperty "xpad"

-- | The ypad.
--
-- Default value: @0@
--
cellYPad :: CellRendererClass self => Attr self Int
cellYPad = newAttrFromUIntProperty "ypad"

-- | The fixed width.
--
-- Allowed values: @>= -1@
--
-- Default value: @-1@
--
cellWidth :: CellRendererClass self => Attr self Int
cellWidth = newAttrFromIntProperty "width"

-- | The fixed height.
--
-- Allowed values: @>= -1@
--
-- Default value: @-1@
--
cellHeight :: CellRendererClass self => Attr self Int
cellHeight = newAttrFromIntProperty "height"

-- | Row has children.
--
-- Default value: @False@
--
cellIsExpander :: CellRendererClass self => Attr self Bool
cellIsExpander = newAttrFromBoolProperty "is-expander"

-- | Row is an expander row, and is expanded.
--
-- Default value: @False@
--
cellIsExpanded :: CellRendererClass self => Attr self Bool
cellIsExpanded = newAttrFromBoolProperty "is-expanded"

-- | Cell background color as a string.
--
-- Default value: @\"\"@
--
cellBackground :: CellRendererClass self => WriteAttr self String
cellBackground = writeAttrFromStringProperty "cell-background"

-- | Cell background color as a 'Color'.
--
cellBackgroundColor :: CellRendererClass self => Attr self Color
cellBackgroundColor = newAttrFromBoxedStorableProperty "cell-background-gdk"
  {# call pure unsafe gdk_color_get_type #}

-- | Whether the 'cellBackground' \/ 'cellBackgroundColor' attribute is set.
--
-- You can use this to reset the attribute to its default.
--
-- Default value: @False@
--
cellBackgroundSet :: CellRendererClass self => Attr self Bool
cellBackgroundSet = newAttrFromBoolProperty "cell-background-set"


--------------------
-- Signals

#if GTK_CHECK_VERSION(2,4,0)
-- %hash c:eff4 d:fc12
-- | This signal gets emitted when the user cancels the process of editing a
-- cell. For example, an editable cell renderer could be written to cancel
-- editing when the user presses Escape.
--
-- * Available since Gtk+ version 2.4
--
editingCanceled :: CellRendererClass self => Signal self (IO ())
editingCanceled = Signal (connect_NONE__NONE "editing-canceled")

#if GTK_CHECK_VERSION(2,6,0)
-- %hash c:41f0 d:49f
-- | This signal gets emitted when a cell starts to be edited. The indended
-- use of this signal is to do special setup on @editable@, e.g. adding a
-- 'EntryCompletion' or setting up additional columns in a 'ComboBox'.
--
-- * The widget that is passed to the handler contains the widget that is used
--   by the 'CellRenderer' to interact with the user. The widget must be
--   casted to the appropriate widget. For instance, a
--   'Graphics.UI.Gtk.ModelView.CellRendererText' uses an
--   'Graphics.UI.Gtk.Entry.Entry' widget, while a
--   'Graphics.UI.Gtk.ModelView.CellRendererCombo' uses a
--   'Graphics.UI.Gtk.ModelView.ComboBox.ComboBox' (if
--   'Graphics.UI.Gtk.ModelView.CellRendererCombo.cellComboHasEntry' is
--   @False@) or a 'Graphics.UI.Gtk.ModelView.ComboBoxEntry.ComboBoxEntry' (if
--   'Graphics.UI.Gtk.ModelView.CellRendererCombo.cellComboHasEntry' is
--   @True@).
--
-- * Available since Gtk+ version 2.6
--
editingStarted :: CellRendererClass self =>
		  Signal self (Widget -> TreePath -> IO ())
editingStarted = Signal editingStartedInternal

editingStartedInternal after cr act =
 connect_OBJECT_STRING__NONE "editing-started" after cr
 $ \ce path -> act ce (stringToTreePath path)
#endif
#endif

--------------------
-- Deprecated Signals

#ifndef DISABLE_DEPRECATED

#if GTK_CHECK_VERSION(2,4,0)
-- %hash c:b10f
onEditingCanceled :: CellRendererClass self => self
 -> IO ()
 -> IO (ConnectId self)
onEditingCanceled = connect_NONE__NONE "editing-canceled" False
{-# DEPRECATED onEditingCanceled "instead of 'onEditingCanceled obj' use 'on obj editingCanceled'" #-}

-- %hash c:808e
afterEditingCanceled :: CellRendererClass self => self
 -> IO ()
 -> IO (ConnectId self)
afterEditingCanceled = connect_NONE__NONE "editing-canceled" True
{-# DEPRECATED afterEditingCanceled "instead of 'afterEditingCanceled obj' use 'after obj editingCanceled'" #-}

#if GTK_CHECK_VERSION(2,6,0)
-- %hash c:6d9c
onEditingStarted :: CellRendererClass self => self
 -> (Widget -> TreePath -> IO ())
 -> IO (ConnectId self)
onEditingStarted = editingStartedInternal False
{-# DEPRECATED onEditingStarted "instead of 'onEditingStarted obj' use 'on obj editingStarted'" #-}

-- %hash c:ef1b
afterEditingStarted :: CellRendererClass self => self
 -> (Widget -> TreePath -> IO ())
 -> IO (ConnectId self)
afterEditingStarted = editingStartedInternal True
{-# DEPRECATED afterEditingStarted "instead of 'afterEditingStarted obj' use 'after obj editingStarted'" #-}
#endif
#endif
#endif