File: PageSetup.chs

package info (click to toggle)
haskell-gtk 0.15.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,964 kB
  • sloc: haskell: 3,346; ansic: 826; makefile: 161
file content (397 lines) | stat: -rw-r--r-- 12,154 bytes parent folder | download | duplicates (9)
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
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
--  GIMP Toolkit (GTK) Widget PageSetup
--
--  Author : Andy Stewart
--
--  Created: 28 Mar 2010
--
--  Copyright (C) 2010 Andy Stewart
--
--  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)
--
-- Stores page setup information
--
-- * Module available since Gtk+ version 2.10
--
module Graphics.UI.Gtk.Printing.PageSetup (

-- * Detail
--
-- | A 'PageSetup' object stores the page size, orientation and margins. The
-- idea is that you can get one of these from the page setup dialog and then
-- pass it to the 'PrintOperation' when printing. The benefit of splitting this
-- out of the 'PrintSettings' is that these affect the actual layout of the
-- page, and thus need to be set long before user prints.
--
-- The margins specified in this object are the \"print margins\", i.e. the
-- parts of the page that the printer cannot print on. These are different from
-- the layout margins that a word processor uses; they are typically used to
-- determine the /minimal/ size for the layout margins.
--
-- To obtain a 'PageSetup' use 'pageSetupNew' to get the defaults, or use
-- 'printRunPageSetupDialog' to show the page setup dialog and receive the
-- resulting page setup.
--
-- Printing support was added in Gtk+ 2.10.
--

-- * Class Hierarchy
--
-- |
-- @
-- |  'GObject'
-- |   +----PageSetup
-- @

#if GTK_CHECK_VERSION(2,10,0)
-- * Types
  PageSetup,
  PageSetupClass,
  castToPageSetup,
  toPageSetup,

-- * Constructors
  pageSetupNew,
#if GTK_CHECK_VERSION(2,12,0)
  pageSetupNewFromFile,
#endif

-- * Methods
  pageSetupCopy,
  pageSetupGetTopMargin,
  pageSetupSetTopMargin,
  pageSetupGetBottomMargin,
  pageSetupSetBottomMargin,
  pageSetupGetLeftMargin,
  pageSetupSetLeftMargin,
  pageSetupGetRightMargin,
  pageSetupSetRightMargin,
  pageSetupSetPaperSizeAndDefaultMargins,
  pageSetupGetPaperWidth,
  pageSetupGetPaperHeight,
  pageSetupGetPageWidth,
  pageSetupGetPageHeight,
#if GTK_CHECK_VERSION(2,14,0)
  pageSetupLoadFile,
#endif
#if GTK_CHECK_VERSION(2,12,0)
  pageSetupToFile,
#endif

-- * Attributes
  pageSetupOrientation,
  pageSetupPaperSize,
#endif
  ) where

import Control.Monad    (liftM)

import System.Glib.FFI
import System.Glib.GError
import System.Glib.Attributes
import System.Glib.UTFString
{#import Graphics.UI.Gtk.Types#}
{#import Graphics.UI.Gtk.Printing.PaperSize#} (PaperSize(..), mkPaperSize, Unit(..))
{#import Graphics.UI.Gtk.Printing.PrintSettings#} (PageOrientation (..))

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

#if GTK_CHECK_VERSION(2,10,0)
--------------------
-- Constructors

-- | Creates a new 'PageSetup'.
--
pageSetupNew :: IO PageSetup
pageSetupNew =
  wrapNewGObject mkPageSetup $
  {# call gtk_page_setup_new #}

#if GTK_CHECK_VERSION(2,12,0)
-- | Reads the page setup from the file @fileName@. Returns a new 'PageSetup'
-- object with the restored page setup.
--
-- * Available since Gtk+ version 2.12
--
pageSetupNewFromFile :: GlibString string
 => string -- ^ @fileName@ - the filename to read the page setup from
 -> IO PageSetup
pageSetupNewFromFile fileName =
  propagateGError $ \errorPtr ->
  withUTFString fileName $ \fileNamePtr -> do
  setupPtr <- {# call gtk_page_setup_new_from_file #}
             fileNamePtr
             errorPtr
  wrapNewGObject mkPageSetup (return setupPtr)

#endif

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

-- | Copies a 'PageSetup'.
--
pageSetupCopy :: PageSetupClass self => self
 -> IO PageSetup -- ^ returns a copy of @other@
pageSetupCopy self =
  wrapNewGObject mkPageSetup $
  {# call gtk_page_setup_copy #}
    (toPageSetup self)

-- | Gets the page orientation of the 'PageSetup'.
pageSetupGetOrientation :: PageSetupClass self => self
 -> IO PageOrientation -- ^ returns the page orientation
pageSetupGetOrientation self =
  liftM (toEnum . fromIntegral) $
  {# call gtk_page_setup_get_orientation #}
    (toPageSetup self)

-- | Sets the page orientation of the 'PageSetup'.
pageSetupSetOrientation :: PageSetupClass self => self
 -> PageOrientation -- ^ @orientation@ - a 'PageOrientation' value
 -> IO ()
pageSetupSetOrientation self orientation =
  {# call gtk_page_setup_set_orientation #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) orientation)

-- | Gets the paper size of the 'PageSetup'.
pageSetupGetPaperSize :: PageSetupClass self => self
 -> IO PaperSize -- ^ returns the paper size
pageSetupGetPaperSize self =
  {# call gtk_page_setup_get_paper_size #}
    (toPageSetup self)
  >>= mkPaperSize . castPtr

pageSetupSetPaperSize :: PageSetupClass self => self
 -> PaperSize -- ^ @size@ - a 'PaperSize'
 -> IO ()
pageSetupSetPaperSize self size =
  {# call gtk_page_setup_set_paper_size #}
    (toPageSetup self)
    size

-- | Gets the top margin in units of @unit@.
--
pageSetupGetTopMargin :: PageSetupClass self => self
 -> Unit      -- ^ @unit@ - the unit for the return value
 -> IO Double -- ^ returns the top margin
pageSetupGetTopMargin self unit =
  liftM realToFrac $
  {# call gtk_page_setup_get_top_margin #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) unit)

-- | Sets the top margin of the 'PageSetup'.
--
pageSetupSetTopMargin :: PageSetupClass self => self
 -> Double -- ^ @margin@ - the new top margin in units of @unit@
 -> Unit   -- ^ @unit@ - the units for @margin@
 -> IO ()
pageSetupSetTopMargin self margin unit =
  {# call gtk_page_setup_set_top_margin #}
    (toPageSetup self)
    (realToFrac margin)
    ((fromIntegral . fromEnum) unit)

-- | Gets the bottom margin in units of @unit@.
--
pageSetupGetBottomMargin :: PageSetupClass self => self
 -> Unit      -- ^ @unit@ - the unit for the return value
 -> IO Double -- ^ returns the bottom margin
pageSetupGetBottomMargin self unit =
  liftM realToFrac $
  {# call gtk_page_setup_get_bottom_margin #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) unit)

-- | Sets the bottom margin of the 'PageSetup'.
--
pageSetupSetBottomMargin :: PageSetupClass self => self
 -> Double -- ^ @margin@ - the new bottom margin in units of @unit@
 -> Unit   -- ^ @unit@ - the units for @margin@
 -> IO ()
pageSetupSetBottomMargin self margin unit =
  {# call gtk_page_setup_set_bottom_margin #}
    (toPageSetup self)
    (realToFrac margin)
    ((fromIntegral . fromEnum) unit)

-- | Gets the left margin in units of @unit@.
--
pageSetupGetLeftMargin :: PageSetupClass self => self
 -> Unit      -- ^ @unit@ - the unit for the return value
 -> IO Double -- ^ returns the left margin
pageSetupGetLeftMargin self unit =
  liftM realToFrac $
  {# call gtk_page_setup_get_left_margin #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) unit)

-- | Sets the left margin of the 'PageSetup'.
--
pageSetupSetLeftMargin :: PageSetupClass self => self
 -> Double -- ^ @margin@ - the new left margin in units of @unit@
 -> Unit   -- ^ @unit@ - the units for @margin@
 -> IO ()
pageSetupSetLeftMargin self margin unit =
  {# call gtk_page_setup_set_left_margin #}
    (toPageSetup self)
    (realToFrac margin)
    ((fromIntegral . fromEnum) unit)

-- | Gets the right margin in units of @unit@.
--
pageSetupGetRightMargin :: PageSetupClass self => self
 -> Unit      -- ^ @unit@ - the unit for the return value
 -> IO Double -- ^ returns the right margin
pageSetupGetRightMargin self unit =
  liftM realToFrac $
  {# call gtk_page_setup_get_right_margin #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) unit)

-- | Sets the right margin of the 'PageSetup'.
--
pageSetupSetRightMargin :: PageSetupClass self => self
 -> Double -- ^ @margin@ - the new right margin in units of @unit@
 -> Unit   -- ^ @unit@ - the units for @margin@
 -> IO ()
pageSetupSetRightMargin self margin unit =
  {# call gtk_page_setup_set_right_margin #}
    (toPageSetup self)
    (realToFrac margin)
    ((fromIntegral . fromEnum) unit)

-- | Sets the paper size of the 'PageSetup' and modifies the margins according
-- to the new paper size.
--
pageSetupSetPaperSizeAndDefaultMargins :: PageSetupClass self => self
 -> PaperSize -- ^ @size@ - a 'PaperSize'
 -> IO ()
pageSetupSetPaperSizeAndDefaultMargins self size =
  {# call gtk_page_setup_set_paper_size_and_default_margins #}
    (toPageSetup self)
    size

-- | Returns the paper width in units of @unit@.
--
-- Note that this function takes orientation, but not margins into
-- consideration. See 'pageSetupGetPageWidth'.
--
pageSetupGetPaperWidth :: PageSetupClass self => self
 -> Unit      -- ^ @unit@ - the unit for the return value
 -> IO Double -- ^ returns the paper width.
pageSetupGetPaperWidth self unit =
  liftM realToFrac $
  {# call gtk_page_setup_get_paper_width #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) unit)

-- | Returns the paper height in units of @unit@.
--
-- Note that this function takes orientation, but not margins into
-- consideration. See 'pageSetupGetPageHeight'.
--
pageSetupGetPaperHeight :: PageSetupClass self => self
 -> Unit      -- ^ @unit@ - the unit for the return value
 -> IO Double -- ^ returns the paper height.
pageSetupGetPaperHeight self unit =
  liftM realToFrac $
  {# call gtk_page_setup_get_paper_height #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) unit)

-- | Returns the page width in units of @unit@.
--
-- Note that this function takes orientation and margins into consideration.
-- See 'pageSetupGetPaperWidth'.
--
pageSetupGetPageWidth :: PageSetupClass self => self
 -> Unit      -- ^ @unit@ - the unit for the return value
 -> IO Double -- ^ returns the page width.
pageSetupGetPageWidth self unit =
  liftM realToFrac $
  {# call gtk_page_setup_get_page_width #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) unit)

-- | Returns the page height in units of @unit@.
--
-- Note that this function takes orientation and margins into consideration.
-- See 'pageSetupGetPaperHeight'.
--
pageSetupGetPageHeight :: PageSetupClass self => self
 -> Unit      -- ^ @unit@ - the unit for the return value
 -> IO Double -- ^ returns the page height.
pageSetupGetPageHeight self unit =
  liftM realToFrac $
  {# call gtk_page_setup_get_page_height #}
    (toPageSetup self)
    ((fromIntegral . fromEnum) unit)

#if GTK_CHECK_VERSION(2,14,0)
-- | Reads the page setup from the file @fileName@. See 'pageSetupToFile'.
--
-- * Available since Gtk+ version 2.14
--
pageSetupLoadFile :: (PageSetupClass self, GlibString string) => self
 -> string  -- ^ @fileName@ - the filename to read the page setup from
 -> IO Bool -- ^ returns @True@ on success
pageSetupLoadFile self fileName =
  liftM toBool $
  propagateGError $ \errorPtr ->
  withUTFString fileName $ \fileNamePtr ->
  {# call gtk_page_setup_load_file #}
    (toPageSetup self)
    fileNamePtr
    errorPtr

#endif

#if GTK_CHECK_VERSION(2,12,0)
-- | This function saves the information from @setup@ to @fileName@.
--
-- * Available since Gtk+ version 2.12
--
pageSetupToFile :: (PageSetupClass self, GlibString string) => self
 -> string  -- ^ @fileName@ - the file to save to
 -> IO Bool -- ^ returns @True@ on success
pageSetupToFile self fileName =
  liftM toBool $
  propagateGError $ \errorPtr ->
  withUTFString fileName $ \fileNamePtr ->
  {# call gtk_page_setup_to_file #}
    (toPageSetup self)
    fileNamePtr
    errorPtr

#endif
-- | The page orientation of the 'PageSetup'.
pageSetupOrientation :: PageSetupClass self => Attr self PageOrientation
pageSetupOrientation = newAttr
  pageSetupGetOrientation
  pageSetupSetOrientation

-- | The paper size of the 'PageSetup'.
pageSetupPaperSize :: PageSetupClass self => Attr self PaperSize
pageSetupPaperSize = newAttr
  pageSetupGetPaperSize
  pageSetupSetPaperSize

#endif