File: Adjustment.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 (300 lines) | stat: -rw-r--r-- 9,213 bytes parent folder | download | duplicates (3)
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
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
--  GIMP Toolkit (GTK) Widget Adjustment
--
--  Author : Axel Simon
--
--  Created: 23 May 2001
--
--  Copyright (C) 1999-2005 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 'Object' representing an adjustable bounded value
--
module Graphics.UI.Gtk.Misc.Adjustment (
-- * Detail
-- 
-- | The 'Adjustment' object represents a value which has an associated lower
-- and upper bound, together with step and page increments, and a page size. It
-- is used within several Gtk+ widgets, including 'SpinButton', 'Viewport', and
-- 'Range' (which is a base class for 'HScrollbar', 'VScrollbar', 'HScale', and
-- 'VScale').
--
-- The 'Adjustment' object does not update the value itself. Instead it is
-- left up to the owner of the 'Adjustment' to control the value.
--
-- The owner of the 'Adjustment' typically calls the
-- 'adjustmentValueChanged' and 'adjustmentChanged' functions after changing
-- the value and its bounds. This results in the emission of the
-- \"value_changed\" or \"changed\" signal respectively.

-- * Class Hierarchy
-- |
-- @
-- |  'GObject'
-- |   +----'Object'
-- |         +----Adjustment
-- @

-- * Types
  Adjustment,
  AdjustmentClass,
  castToAdjustment, gTypeAdjustment,
  toAdjustment,

-- * Constructors
  adjustmentNew,

-- * Methods
  adjustmentSetLower,
  adjustmentGetLower,
  adjustmentSetPageIncrement,
  adjustmentGetPageIncrement,
  adjustmentSetPageSize,
  adjustmentGetPageSize,
  adjustmentSetStepIncrement,
  adjustmentGetStepIncrement,
  adjustmentSetUpper,
  adjustmentGetUpper,
  adjustmentSetValue,
  adjustmentGetValue,
  adjustmentClampPage,
  adjustmentAdjChanged,
  adjustmentValueChanged,

-- * Attributes
#if GTK_CHECK_VERSION(2,4,0)
  adjustmentValue,
  adjustmentLower,
  adjustmentUpper,
  adjustmentStepIncrement,
  adjustmentPageIncrement,
  adjustmentPageSize,
#endif

-- * Signals
  onAdjChanged,
  afterAdjChanged,
  onValueChanged,
  afterValueChanged,
  ) where

import Control.Monad	(liftM)

import System.Glib.FFI
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" #}

--------------------
-- Constructors

-- | Creates a new 'Adjustment'.
--
-- The creation function take every value that is contained in the object:
-- @value@ is the initial value and should be between the @upper@ and @lower@
-- bounds of the slider. Clicking on the arrows increases this value by
-- @stepIncrement@. Clicking in the slider advances by @pageIncrement@. The
-- @pageSize@ is needed to determine if the end of the slider is still in the
-- range.
--
adjustmentNew :: 
    Double        -- ^ @value@ - the initial value.
 -> Double        -- ^ @lower@ - the minimum value.
 -> Double        -- ^ @upper@ - the maximum value.
 -> Double        -- ^ @stepIncrement@ - the step increment.
 -> Double        -- ^ @pageIncrement@ - the page increment.
 -> Double        -- ^ @pageSize@ - the page size.
 -> IO Adjustment
adjustmentNew value lower upper stepIncrement pageIncrement pageSize =
  makeNewObject mkAdjustment $ liftM castPtr $
  {# call unsafe adjustment_new #}
    (realToFrac value)
    (realToFrac lower)
    (realToFrac upper)
    (realToFrac stepIncrement)
    (realToFrac pageIncrement)
    (realToFrac pageSize)

--------------------
-- Methods

-- | Set the lower value.
adjustmentSetLower :: Adjustment -> Double -> IO ()
adjustmentSetLower = objectSetPropertyDouble "lower"

-- | Retrieve the lower value.
adjustmentGetLower :: Adjustment -> IO Double
adjustmentGetLower = objectGetPropertyDouble "lower"

-- | Set the page increment value.
adjustmentSetPageIncrement :: Adjustment -> Double -> IO ()
adjustmentSetPageIncrement = objectSetPropertyDouble "page-increment"

-- | Retrieve the pageincrement value.
adjustmentGetPageIncrement :: Adjustment -> IO Double
adjustmentGetPageIncrement = objectGetPropertyDouble "page-increment"

-- | Set the page size value.
adjustmentSetPageSize :: Adjustment -> Double -> IO ()
adjustmentSetPageSize = objectSetPropertyDouble "page_size"

-- | Retrieve the page size value.
adjustmentGetPageSize :: Adjustment -> IO Double
adjustmentGetPageSize = objectGetPropertyDouble "page_size"

-- | Set the step-increment value.
adjustmentSetStepIncrement :: Adjustment -> Double -> IO ()
adjustmentSetStepIncrement = objectSetPropertyDouble "step-increment"

-- | Retrieve the step-increment value.
adjustmentGetStepIncrement :: Adjustment -> IO Double
adjustmentGetStepIncrement = objectGetPropertyDouble "step-increment"

-- | Set the upper value.
adjustmentSetUpper :: Adjustment -> Double -> IO ()
adjustmentSetUpper = objectSetPropertyDouble "upper"

-- | Retrieve the upper value.
adjustmentGetUpper :: Adjustment -> IO Double
adjustmentGetUpper = objectGetPropertyDouble "upper"

-- | Sets the current value of the Adjustment object. The value is clamped to
-- lie between the adjustment's @lower@ and @upper@ values. See 'adjustmentNew'
-- for details of these properties.
--
-- Note that for adjustments which are used in a 'Scrollbar', the effective
-- range of allowed values goes from @lower@ to @upper - page_size@.
--
adjustmentSetValue :: Adjustment -> Double -> IO ()
adjustmentSetValue self value =
  {# call adjustment_set_value #}
    self
    (realToFrac value)

-- | Gets the current value of the adjustment. See 'adjustmentSetValue'.
--
adjustmentGetValue :: Adjustment -> IO Double
adjustmentGetValue self =
  liftM realToFrac $
  {# call adjustment_get_value #}
    self

-- | Updates the 'Adjustment' @value@ to ensure that the range between @lower@
-- and @upper@ is in the current page (i.e. between @value@ and @value + 
-- pageSize@). If the range is larger than the page size, then only the start
-- of it will be in the current page. A \"changed\" signal will be emitted if
-- the value is changed.
--
adjustmentClampPage :: Adjustment
 -> Double     -- ^ @lower@ - the lower value.
 -> Double     -- ^ @upper@ - the upper value.
 -> IO ()
adjustmentClampPage self lower upper =
  {# call adjustment_clamp_page #}
    self
    (realToFrac lower)
    (realToFrac upper)

-- | Emit the 'onAdjChanged' signal.
--
adjustmentAdjChanged :: Adjustment -> IO ()
adjustmentAdjChanged = {#call adjustment_changed#}

-- | Emit the 'onValueChanged' signal.
--
-- * When adjusting the or bounds, this function can be called to enforce a
--   visual update of the containing widget.
--
adjustmentValueChanged :: Adjustment -> IO ()
adjustmentValueChanged = {#call adjustment_value_changed#}

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

#if GTK_CHECK_VERSION(2,4,0)
-- | The value of the adjustment.
--
-- Default value: 0
--
adjustmentValue :: Attr Adjustment Double
adjustmentValue = newAttr
  adjustmentGetValue
  adjustmentSetValue

-- | The minimum value of the adjustment.
--
-- Default value: 0
--
adjustmentLower :: Attr Adjustment Double
adjustmentLower = newAttrFromDoubleProperty "lower"

-- | The maximum value of the adjustment. Note that values will be restricted
-- by @upper - page-size@ if the page-size property is nonzero.
--
-- Default value: 0
--
adjustmentUpper :: Attr Adjustment Double
adjustmentUpper = newAttrFromDoubleProperty "upper"

-- | The step increment of the adjustment.
--
-- Default value: 0
--
adjustmentStepIncrement :: Attr Adjustment Double
adjustmentStepIncrement = newAttrFromDoubleProperty "step-increment"

-- | The page increment of the adjustment.
--
-- Default value: 0
--
adjustmentPageIncrement :: Attr Adjustment Double
adjustmentPageIncrement = newAttrFromDoubleProperty "page-increment"

-- | The page size of the adjustment. Note that the page-size is irrelevant
-- and should be set to zero if the adjustment is used for a simple scalar
-- value, e.g. in a 'SpinButton'.
--
-- Default value: 0
--
adjustmentPageSize :: Attr Adjustment Double
adjustmentPageSize = newAttrFromDoubleProperty "page-size"
#endif

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

-- | Emitted when one or more of the 'Adjustment' fields have been changed,
-- other than the value field.
--
onAdjChanged, afterAdjChanged :: Adjustment
 -> IO ()
 -> IO (ConnectId Adjustment)
onAdjChanged = connect_NONE__NONE "changed" False
afterAdjChanged = connect_NONE__NONE "changed" True

-- | Emitted when the 'Adjustment' value field has been changed.
--
onValueChanged, afterValueChanged :: Adjustment
 -> IO ()
 -> IO (ConnectId Adjustment)
onValueChanged = connect_NONE__NONE "value-changed" False
afterValueChanged = connect_NONE__NONE "value-changed" True