From: Andy S. <And...@co...> - 2010-03-31 12:06:26
|
Wed Mar 31 08:05:29 EDT 2010 Andy Stewart <laz...@gm...> * Add new `Printing` modules in Gtk+ 2.18.3 Ignore-this: 2330b4d21bceb5025f66121ad0f103ca hunk ./ApiUpdateTodoList.txt 110 -*** TODO PrintBackend.chs -*** TODO Print.chs +*** NON-PORTABLE PrintBackend.chs +*** NON-PORTABLE Print.chs hunk ./ApiUpdateTodoList.txt 113 -*** TODO Printer.chs -*** TODO PrinterOption.chs -*** TODO PrinterOptionSet.chs -*** TODO PrinterOptionWidget.chs -*** TODO PrintJob.chs -*** TODO PrintOperation.chs -*** TODO PrintOperationPreview.chs +*** NON-PORTABLE Printer.chs +*** DONE PrinterOption.chs +*** DONE PrinterOptionSet.chs +*** DONE PrinterOptionWidget.chs +*** NON-PORTABLE PrintJob.chs +*** DONE PrintOperation.chs +*** DONE PrintOperationPreview.chs hunk ./ApiUpdateTodoList.txt 121 -*** TODO PrintUnixDialog.chs +*** NON-PORTABLE PrintUnixDialog.chs hunk ./Makefile.am 816 + gtk/Graphics/UI/Gtk/Printing/PageSetup.chs.pp \ + gtk/Graphics/UI/Gtk/Printing/PaperSize.chs.pp \ + gtk/Graphics/UI/Gtk/Printing/PrintContext.chs.pp \ + gtk/Graphics/UI/Gtk/Printing/PrintOperation.chs.pp \ + gtk/Graphics/UI/Gtk/Printing/PrintOperationPreview.chs.pp \ + gtk/Graphics/UI/Gtk/Printing/PrintSettings.chs.pp \ hunk ./Makefile.am 905 - gtk/Graphics/UI/Gtk/Recent/RecentFilter_stub.o + gtk/Graphics/UI/Gtk/Recent/RecentFilter_stub.o \ + gtk/Graphics/UI/Gtk/Printing/PrintSettings_stub.o hunk ./gtk/Graphics/UI/Gtk.hs.pp 258 + -- * Printing modules + module Graphics.UI.Gtk.Printing.PageSetup, + module Graphics.UI.Gtk.Printing.PaperSize, + module Graphics.UI.Gtk.Printing.PrintContext, + module Graphics.UI.Gtk.Printing.PrintOperation, + module Graphics.UI.Gtk.Printing.PrintOperationPreview, + module Graphics.UI.Gtk.Printing.PrintSettings, + hunk ./gtk/Graphics/UI/Gtk.hs.pp 528 +-- printing modules +import Graphics.UI.Gtk.Printing.PageSetup +import Graphics.UI.Gtk.Printing.PaperSize +import Graphics.UI.Gtk.Printing.PrintContext +import Graphics.UI.Gtk.Printing.PrintOperation +import Graphics.UI.Gtk.Printing.PrintOperationPreview +import Graphics.UI.Gtk.Printing.PrintSettings + adddir ./gtk/Graphics/UI/Gtk/Printing addfile ./gtk/Graphics/UI/Gtk/Printing/PageSetup.chs.pp hunk ./gtk/Graphics/UI/Gtk/Printing/PageSetup.chs.pp 1 +-- -*-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 : gtk...@li... +-- 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, + -- pageSetupNewFromKeyFile, +#endif + +-- * Methods + pageSetupCopy, + pageSetupGetTopMargin, + pageSetupSetTopMargin, + pageSetupGetBottomMargin, + pageSetupSetBottomMargin, + pageSetupGetLeftMargin, + pageSetupSetLeftMargin, + pageSetupGetRightMargin, + pageSetupSetRightMargin, + -- pageSetupSetPaperSizeAndDefaultMargins, + pageSetupGetPaperWidth, + pageSetupGetPaperHeight, + pageSetupGetPageWidth, + pageSetupGetPageHeight, +#if GTK_CHECK_VERSION(2,14,0) + pageSetupLoadFile, + -- pageSetupLoadKeyFile, +#endif +#if GTK_CHECK_VERSION(2,12,0) + pageSetupToFile, + -- pageSetupToKeyFile, +#endif + + pageSetupGetOrientation, + pageSetupSetOrientation, + pageSetupGetPaperSize, + -- pageSetupSetPaperSize, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.GError +import System.Glib.Attributes +import System.Glib.Properties +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 = + constructNewGObject 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, or 'Nothing' if an error occurred. See +-- 'pageSetupToFile'. +-- +-- * Available since Gtk+ version 2.12 +-- +pageSetupNewFromFile :: + String -- ^ @fileName@ - the filename to read the page setup from + -> IO (Maybe PageSetup) +pageSetupNewFromFile fileName = + propagateGError $ \errorPtr -> + withUTFString fileName $ \fileNamePtr -> do + setupPtr <- {# call gtk_page_setup_new_from_file #} + fileNamePtr + errorPtr + if setupPtr == nullPtr + then return Nothing + else liftM Just (constructNewGObject mkPageSetup (return setupPtr)) [_$_] + +-- | Reads the page setup from the group @groupName@ in the key file +-- @keyFile@. Returns a new 'PageSetup' object with the restored page setup, or +-- {@NULL@, FIXME: this should probably be converted to a Maybe data type} if +-- an error occurred. +-- +-- * Available since Gtk+ version 2.12 +-- +-- pageSetupNewFromKeyFile :: +-- {-GKeyFile*-} -- ^ @keyFile@ - the 'KeyFile' to +-- -- retrieve the page_setup from +-- -> String -- ^ @groupName@ - the name of the group in the key_file to +-- -- read, or {@NULL@, FIXME: this should probably be converted +-- -- to a Maybe data type} to use the default name \"Page +-- -- Setup\" +-- -> IO PageSetup +-- pageSetupNewFromKeyFile keyFile groupName = +-- constructNewGObject mkPageSetup $ +-- propagateGError $ \errorPtr -> +-- withUTFString groupName $ \groupNamePtr -> +-- {# call gtk_page_setup_new_from_key_file #} +-- {-keyFile-} +-- groupNamePtr +-- errorPtr +#endif + +-------------------- +-- Methods + +-- | Copies a 'PageSetup'. +-- +pageSetupCopy :: PageSetupClass self => self + -> IO PageSetup -- ^ returns a copy of @other@ +pageSetupCopy self = + makeNewGObject 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 => 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 + +-- | Reads the page setup from the group @groupName@ in the key file +-- @keyFile@. +-- +-- * Available since Gtk+ version 2.14 +-- +-- pageSetupLoadKeyFile :: PageSetupClass self => self +-- -> {-GKeyFile*-} -- ^ @keyFile@ - the 'KeyFile' to +-- -- retrieve the page_setup from +-- -> String -- ^ @groupName@ - the name of the group in the key_file to +-- -- read, or {@NULL@, FIXME: this should probably be converted +-- -- to a Maybe data type} to use the default name \"Page +-- -- Setup\" +-- -> IO Bool -- ^ returns @True@ on success +-- pageSetupLoadKeyFile self keyFile groupName = +-- liftM toBool $ +-- propagateGError $ \errorPtr -> +-- withUTFString groupName $ \groupNamePtr -> +-- {# call gtk_page_setup_load_key_file #} +-- (toPageSetup self) +-- {-keyFile-} +-- groupNamePtr +-- 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 => 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 + +-- | This function adds the page setup from @setup@ to @keyFile@. +-- +-- * Available since Gtk+ version 2.12 +-- +-- pageSetupToKeyFile :: PageSetupClass self => self +-- -> {-GKeyFile*-} -- ^ @keyFile@ - the 'KeyFile' to save +-- -- the page setup to +-- -> String -- ^ @groupName@ - the group to add the settings to in +-- -- @keyFile@, or {@NULL@, FIXM: Ethis should probably be +-- -- converted to a Maybe data type} to use the default name +-- -- \"Page Setup\" +-- -> IO () +-- pageSetupToKeyFile self keyFile groupName = +-- withUTFString groupName $ \groupNamePtr -> +-- {# call gtk_page_setup_to_key_file #} +-- (toPageSetup self) +-- {-keyFile-} +-- groupNamePtr +#endif +#endif addfile ./gtk/Graphics/UI/Gtk/Printing/PaperSize.chs.pp hunk ./gtk/Graphics/UI/Gtk/Printing/PaperSize.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget PaperSize +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Support for named paper sizes +-- +module Graphics.UI.Gtk.Printing.PaperSize ( + +-- * Detail +-- +-- | 'PaperSize' handles paper sizes. It uses the +-- standard called \"PWG 5101.1-2002 PWG: Standard for Media Standardized +-- Names\" to name the paper sizes (and to get the data for the page sizes). In +-- addition to standard paper sizes, 'PaperSize' allows +-- to construct custom paper sizes with arbitrary dimensions. +-- +-- The 'PaperSize' object stores not only the +-- dimensions (width and height) of a paper size and its name, it also provides +-- default print margins. +-- +-- Printing support has been added in Gtk+ 2.10. + +-- * Types + PaperSize, + mkPaperSize, + +-- * Enums + Unit(..), + +-- * Constructors +#if GTK_CHECK_VERSION(2,10,0) + paperSizeNew, + paperSizeNewFromPpd, + paperSizeNewCustom, +#if GTK_CHECK_VERSION(2,12,0) + -- paperSizeNewFromKeyFile, +#endif +#endif + +-- * Methods +#if GTK_CHECK_VERSION(2,10,0) + paperSizeCopy, + paperSizeFree, + paperSizeIsEqual, +#if GTK_CHECK_VERSION(2,12,0) + paperSizeGetPaperSizes, +#endif + paperSizeGetName, + paperSizeGetDisplayName, + paperSizeGetPpdName, + paperSizeGetWidth, + paperSizeGetHeight, +#endif + paperSizeIsCustom, +#if GTK_CHECK_VERSION(2,10,0) + paperSizeSetSize, + paperSizeGetDefaultTopMargin, + paperSizeGetDefaultBottomMargin, + paperSizeGetDefaultLeftMargin, + paperSizeGetDefaultRightMargin, + paperSizeGetDefault, +#if GTK_CHECK_VERSION(2,12,0) + -- paperSizeToKeyFile, +#endif +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.UTFString +import System.Glib.GList +{#import Graphics.UI.Gtk.Types#} + +{# context lib="gtk" prefix="gtk" #} + +-------------------- +-- Types +{#pointer *PaperSize foreign newtype#} + +-------------------- +-- Enums +{#enum Unit {underscoreToCase} deriving (Bounded,Eq,Show)#} + +-------------------- +-- Constructors + +mkPaperSize :: Ptr PaperSize -> IO PaperSize +mkPaperSize size = liftM PaperSize $ newForeignPtr_ size + +#if GTK_CHECK_VERSION(2,10,0) +-- | Creates a new 'PaperSize' object by parsing a PWG +-- 5101.1-2002 paper name. +-- +-- If @name@ is empty, the default paper size is returned, see 'paperSizeGetDefault'. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeNew :: + String -- ^ @name@ - a paper size name + -> IO PaperSize +paperSizeNew name = + withUTFString name $ \namePtr -> + {# call gtk_paper_size_new #} + namePtr + >>= mkPaperSize + +-- | Creates a new 'PaperSize' object by using PPD +-- information. +-- +-- If @ppdName@ is not a recognized PPD paper name, @ppdDisplayName@, +-- @width@ and @height@ are used to construct a custom 'PaperSize' object. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeNewFromPpd :: + String -- ^ @ppdName@ - a PPD paper name + -> String -- ^ @ppdDisplayName@ - the corresponding human-readable name + -> Double -- ^ @width@ - the paper width, in points + -> Double -- ^ @height@ - the paper height in points + -> IO PaperSize +paperSizeNewFromPpd ppdName ppdDisplayName width height = + withUTFString ppdDisplayName $ \ppdDisplayNamePtr -> + withUTFString ppdName $ \ppdNamePtr -> + {# call gtk_paper_size_new_from_ppd #} + ppdNamePtr + ppdDisplayNamePtr + (realToFrac width) + (realToFrac height) + >>= mkPaperSize + +-- | Creates a new 'PaperSize' object with the given +-- parameters. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeNewCustom :: + String -- ^ @name@ - the paper name + -> String -- ^ @displayName@ - the human-readable name + -> Double -- ^ @width@ - the paper width, in units of @unit@ + -> Double -- ^ @height@ - the paper height, in units of @unit@ + -> Unit -- ^ @unit@ - the unit for @width@ and @height@ + -> IO PaperSize +paperSizeNewCustom name displayName width height unit = + withUTFString displayName $ \displayNamePtr -> + withUTFString name $ \namePtr -> + {# call gtk_paper_size_new_custom #} + namePtr + displayNamePtr + (realToFrac width) + (realToFrac height) + ((fromIntegral . fromEnum) unit) + >>= mkPaperSize + +#if GTK_CHECK_VERSION(2,12,0) +-- | Reads a paper size from the group @groupName@ in the key file @keyFile@. +-- +-- * Available since Gtk+ version 2.12 +-- +-- paperSizeNewFromKeyFile :: +-- {-GKeyFile*-} -- ^ @keyFile@ - the 'KeyFile' to +-- -- retrieve the papersize from +-- -> String -- ^ @groupName@ - the name ofthe group in the key file to +-- -- read, emptry to read the first group +-- -> IO PaperSize +-- paperSizeNewFromKeyFile keyFile groupName = +-- propagateGError $ \errorPtr -> +-- withUTFString groupName $ \groupNamePtr -> +-- {# call gtk_paper_size_new_from_key_file #} +-- {-keyFile-} +-- groupNamePtr +-- errorPtr +#endif +#endif + +-------------------- +-- Methods + +#if GTK_CHECK_VERSION(2,10,0) +-- | Copies an existing 'PaperSize'. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeCopy :: PaperSize + -> IO PaperSize -- ^ returns a copy of @other@ +paperSizeCopy self = + {# call gtk_paper_size_copy #} self >>= mkPaperSize + +-- | Free the given 'PaperSize' object. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeFree :: PaperSize -> IO () +paperSizeFree self = + {# call gtk_paper_size_free #} + self + +-- | Compares two 'PaperSize' objects. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeIsEqual :: PaperSize + -> PaperSize -- ^ @size2@ - another 'PaperSize' + -- object + -> IO Bool -- ^ returns @True@, if @size1@ and @size2@ represent + -- the same paper size +paperSizeIsEqual self size2 = + liftM toBool $ + {# call gtk_paper_size_is_equal #} + self + size2 + +#if GTK_CHECK_VERSION(2,12,0) +-- | Creates a list of known paper sizes. +-- +-- * Available since Gtk+ version 2.12 +-- +paperSizeGetPaperSizes :: + Bool -- ^ @includeCustom@ - whether to include custom + -- paper sizes as defined in the page setup dialog + -> IO [PaperSize] -- ^ returns a newly allocated list of newly + -- allocated 'PaperSize' objects +paperSizeGetPaperSizes includeCustom = do + glist <- {# call gtk_paper_size_get_paper_sizes #} (fromBool includeCustom) + list <- fromGList glist + mapM mkPaperSize list +#endif + +-- | Gets the name of the 'PaperSize'. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetName :: PaperSize + -> IO String -- ^ returns the name of @size@ +paperSizeGetName self = + {# call gtk_paper_size_get_name #} + self + >>= peekUTFString + +-- | Gets the human-readable name of the 'PaperSize'. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetDisplayName :: PaperSize + -> IO String -- ^ returns the human-readable name of @size@ +paperSizeGetDisplayName self = + {# call gtk_paper_size_get_display_name #} + self + >>= peekUTFString + +-- | Gets the PPD name of the 'PaperSize', which may be +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetPpdName :: PaperSize + -> IO String -- ^ returns the PPD name of @size@ +paperSizeGetPpdName self = + {# call gtk_paper_size_get_ppd_name #} + self + >>= peekUTFString + +-- | Gets the paper width of the 'PaperSize', in units +-- of @unit@. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetWidth :: PaperSize + -> Unit -- ^ @unit@ - the unit for the return value + -> IO Double -- ^ returns the paper width +paperSizeGetWidth self unit = + liftM realToFrac $ + {# call gtk_paper_size_get_width #} + self + ((fromIntegral . fromEnum) unit) + +-- | Gets the paper height of the 'PaperSize', in units +-- of @unit@. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetHeight :: PaperSize + -> Unit -- ^ @unit@ - the unit for the return value + -> IO Double -- ^ returns the paper height +paperSizeGetHeight self unit = + liftM realToFrac $ + {# call gtk_paper_size_get_height #} + self + ((fromIntegral . fromEnum) unit) +#endif + +-- | Returns @True@ if @size@ is not a standard paper size. +-- +paperSizeIsCustom :: PaperSize + -> IO Bool -- ^ returns whether @size@ is a custom paper size. +paperSizeIsCustom self = + liftM toBool $ + {# call gtk_paper_size_is_custom #} + self + +#if GTK_CHECK_VERSION(2,10,0) +-- | Changes the dimensions of a @size@ to @width@ x @height@. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeSetSize :: PaperSize + -> Double -- ^ @width@ - the new width in units of @unit@ + -> Double -- ^ @height@ - the new height in units of @unit@ + -> Unit -- ^ @unit@ - the unit for @width@ and @height@ + -> IO () +paperSizeSetSize self width height unit = + {# call gtk_paper_size_set_size #} + self + (realToFrac width) + (realToFrac height) + ((fromIntegral . fromEnum) unit) + +-- | Gets the default top margin for the 'PaperSize'. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetDefaultTopMargin :: PaperSize + -> Unit -- ^ @unit@ - the unit for the return value + -> IO Double -- ^ returns the default top margin +paperSizeGetDefaultTopMargin self unit = + liftM realToFrac $ + {# call gtk_paper_size_get_default_top_margin #} + self + ((fromIntegral . fromEnum) unit) + +-- | Gets the default bottom margin for the 'PaperSize'. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetDefaultBottomMargin :: PaperSize + -> Unit -- ^ @unit@ - the unit for the return value + -> IO Double -- ^ returns the default bottom margin +paperSizeGetDefaultBottomMargin self unit = + liftM realToFrac $ + {# call gtk_paper_size_get_default_bottom_margin #} + self + ((fromIntegral . fromEnum) unit) + +-- | Gets the default left margin for the 'PaperSize'. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetDefaultLeftMargin :: PaperSize + -> Unit -- ^ @unit@ - the unit for the return value + -> IO Double -- ^ returns the default left margin +paperSizeGetDefaultLeftMargin self unit = + liftM realToFrac $ + {# call gtk_paper_size_get_default_left_margin #} + self + ((fromIntegral . fromEnum) unit) + +-- | Gets the default right margin for the 'PaperSize'. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetDefaultRightMargin :: PaperSize + -> Unit -- ^ @unit@ - the unit for the return value + -> IO Double -- ^ returns the default right margin +paperSizeGetDefaultRightMargin self unit = + liftM realToFrac $ + {# call gtk_paper_size_get_default_right_margin #} + self + ((fromIntegral . fromEnum) unit) + +-- | Returns the name of the default paper size, which depends on the current +-- locale. +-- +-- * Available since Gtk+ version 2.10 +-- +paperSizeGetDefault :: + IO String -- ^ returns the name of the default paper size. The string is + -- owned by Gtk+ and should not be modified. +paperSizeGetDefault = + {# call gtk_paper_size_get_default #} + >>= peekUTFString + +#if GTK_CHECK_VERSION(2,12,0) +-- | This function adds the paper size from @size@ to @keyFile@. +-- +-- * Available since Gtk+ version 2.12 +-- +-- paperSizeToKeyFile :: PaperSize +-- -> {-GKeyFile*-} -- ^ @keyFile@ - the 'KeyFile' to save +-- -- the paper size to +-- -> String -- ^ @groupName@ - the group to add the settings to in +-- -- @keyFile@ +-- -> IO () +-- paperSizeToKeyFile self keyFile groupName = +-- withUTFString groupName $ \groupNamePtr -> +-- {# call gtk_paper_size_to_key_file #} +-- self +-- {-keyFile-} +-- groupNamePtr +#endif +#endif addfile ./gtk/Graphics/UI/Gtk/Printing/PrintContext.chs.pp hunk ./gtk/Graphics/UI/Gtk/Printing/PrintContext.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget PrintContext +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Encapsulates context for drawing pages +-- +-- * Module available since Gtk+ version 2.10 +-- +module Graphics.UI.Gtk.Printing.PrintContext ( + +-- * Detail +-- +-- | A 'PrintContext' encapsulates context information that is required when +-- drawing pages for printing, such as the cairo context and important +-- parameters like page size and resolution. It also lets you easily create +-- 'PangoLayout' and 'Context' objects that match the font metrics of the cairo +-- surface. +-- +-- 'PrintContext' objects gets passed to the ::begin-print, ::end-print, +-- ::request-page-setup and ::draw-page signals on the 'PrintOperation'. +-- +-- Printing support was added in Gtk+ 2.10. + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GObject' +-- | +----PrintContext +-- @ + +#if GTK_CHECK_VERSION(2,10,0) +-- * Types + PrintContext, + PrintContextClass, + castToPrintContext, + toPrintContext, + +-- * Methods + -- printContextGetCairoContext, + -- printContextSetCairoContext, + printContextGetPageSetup, + printContextGetWidth, + printContextGetHeight, + printContextGetDpiX, + printContextGetDpiY, + printContextGetPangoFontmap, + printContextCreatePangoContext, + printContextCreatePangoLayout, +#endif + ) where + +import Control.Monad (liftM) +import Data.IORef (newIORef) + +import System.Glib.FFI +{#import Graphics.UI.Gtk.Types#} +{#import Graphics.UI.Gtk.Pango.Types#} + +{# context lib="gtk" prefix="gtk" #} + +#if GTK_CHECK_VERSION(2,10,0) +-------------------- +-- Methods + +-- | Obtains the cairo context that is associated with the 'PrintContext'. +-- +-- printContextGetCairoContext :: PrintContextClass self => self +-- -> IO {-cairo_t*-} -- ^ returns the cairo context of @context@ +-- printContextGetCairoContext self = +-- {# call gtk_print_context_get_cairo_context #} +-- (toPrintContext self) + +-- | Sets a new cairo context on a print context. +-- +-- This function is intended to be used when implementing an internal print +-- preview, it is not needed for printing, since Gtk+ itself creates a suitable +-- cairo context in that case. +-- +-- printContextSetCairoContext :: PrintContextClass self => self +-- -> {-cairo_t*-} -- ^ @cr@ - the cairo context +-- -> Double -- ^ @dpiX@ - the horizontal resolution to use with @cr@ +-- -> Double -- ^ @dpiY@ - the vertical resolution to use with @cr@ +-- -> IO () +-- printContextSetCairoContext self cr dpiX dpiY = +-- {# call gtk_print_context_set_cairo_context #} +-- (toPrintContext self) +-- {-cr-} +-- (realToFrac dpiX) +-- (realToFrac dpiY) + +-- | Obtains the 'PageSetup' that determines the page dimensions of the +-- 'PrintContext'. +-- +printContextGetPageSetup :: PrintContextClass self => self + -> IO PageSetup -- ^ returns the page setup of @context@ +printContextGetPageSetup self = + makeNewGObject mkPageSetup $ + {# call gtk_print_context_get_page_setup #} + (toPrintContext self) + +-- | Obtains the width of the 'PrintContext', in pixels. +-- +printContextGetWidth :: PrintContextClass self => self + -> IO Double -- ^ returns the width of @context@ +printContextGetWidth self = + liftM realToFrac $ + {# call gtk_print_context_get_width #} + (toPrintContext self) + +-- | Obtains the height of the 'PrintContext', in pixels. +-- +printContextGetHeight :: PrintContextClass self => self + -> IO Double -- ^ returns the height of @context@ +printContextGetHeight self = + liftM realToFrac $ + {# call gtk_print_context_get_height #} + (toPrintContext self) + +-- | Obtains the horizontal resolution of the 'PrintContext', in dots per +-- inch. +-- +printContextGetDpiX :: PrintContextClass self => self + -> IO Double -- ^ returns the horizontal resolution of @context@ +printContextGetDpiX self = + liftM realToFrac $ + {# call gtk_print_context_get_dpi_x #} + (toPrintContext self) + +-- | Obtains the vertical resolution of the 'PrintContext', in dots per inch. +-- +printContextGetDpiY :: PrintContextClass self => self + -> IO Double -- ^ returns the vertical resolution of @context@ +printContextGetDpiY self = + liftM realToFrac $ + {# call gtk_print_context_get_dpi_y #} + (toPrintContext self) + +-- | Returns a 'FontMap' that is suitable for use with the 'PrintContext'. +-- +printContextGetPangoFontmap :: PrintContextClass self => self + -> IO FontMap -- ^ returns the font map of @context@ +printContextGetPangoFontmap self = + makeNewGObject mkFontMap $ + {# call gtk_print_context_get_pango_fontmap #} + (toPrintContext self) + +-- | Creates a new 'Context' that can be used with the 'PrintContext'. +-- +printContextCreatePangoContext :: PrintContextClass self => self + -> IO PangoContext -- ^ returns a new Pango context for @context@ +printContextCreatePangoContext self = + makeNewGObject mkPangoContext $ + {# call gtk_print_context_create_pango_context #} + (toPrintContext self) + +-- | Creates a new 'PangoLayout' that is suitable for use with the +-- 'PrintContext'. +-- +printContextCreatePangoLayout :: PrintContextClass self => self + -> IO PangoLayout -- ^ returns a new Pango layout for @context@ +printContextCreatePangoLayout self = do + pl <- constructNewGObject mkPangoLayoutRaw $ + {# call gtk_print_context_create_pango_layout #} + (toPrintContext self) + ps <- makeNewPangoString "" + psRef <- newIORef ps + return (PangoLayout psRef pl) +#endif addfile ./gtk/Graphics/UI/Gtk/Printing/PrintOperation.chs.pp hunk ./gtk/Graphics/UI/Gtk/Printing/PrintOperation.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget PrintOperation +-- +-- 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- High-level Printing API +-- +-- * Module available since Gtk+ version 2.10 +-- +module Graphics.UI.Gtk.Printing.PrintOperation ( + +-- * Detail +-- +-- | 'PrintOperation' is the high-level, portable printing API. It looks a bit +-- different than other Gtk+ dialogs such as the 'FileChooser', since some +-- platforms don't expose enough infrastructure to implement a good print +-- dialog. On such platforms, 'PrintOperation' uses the native print dialog. On +-- platforms which do not provide a native print dialog, Gtk+ uses its own, see +-- 'PrintUnixDialog'. +-- +-- The typical way to use the high-level printing API is to create a +-- 'PrintOperation' object with 'printOperationNew' when the user selects to +-- print. Then you set some properties on it, e.g. the page size, any +-- 'PrintSettings' from previous print operations, the number of pages, the +-- current page, etc. +-- +-- Then you start the print operation by calling 'printOperationRun'. It +-- will then show a dialog, let the user select a printer and options. When the +-- user finished the dialog various signals will be emitted on the +-- 'PrintOperation', the main one being ::draw-page, which you are supposed to +-- catch and render the page on the provided 'PrintContext' using Cairo. +-- +-- By default 'PrintOperation' uses an external application to do print +-- preview. To implement a custom print preview, an application must connect to +-- the preview signal. The functions 'printOperationPrintPreviewRenderPage', +-- 'printOperationPreviewEndPreview' and 'printOperationPreviewIsSelected' are +-- useful when implementing a print preview. +-- +-- Printing support was added in Gtk+ 2.10. +-- +-- The following functions don't bind, use corresponding attributes instead: +-- printOperationSetDefaultPageSetup, +-- printOperationGetDefaultPageSetup, +-- printOperationSetPrintSettings, +-- printOperationGetPrintSettings, +-- printOperationSetSupportSelection, +-- printOperationGetSupportSelection, +-- printOperationSetHasSelection, +-- printOperationGetHasSelection, +-- printOperationSetEmbedPageSetup, +-- printOperationGetEmbedPageSetup, + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GObject' +-- | +----PrintOperation +-- @ + +#if GTK_CHECK_VERSION(2,10,0) +-- * Types + PrintOperation, + PrintOperationClass, + castToPrintOperation, + toPrintOperation, + +-- * Enums + PrintStatus(..), + PrintOperationAction(..), + PrintOperationResult(..), + PrintError(..), + +-- * Constructors + printOperationNew, + +-- * Methods + printOperationSetAllowAsync, + printOperationGetError, + printOperationSetJobName, + printOperationSetNPages, +#if GTK_CHECK_VERSION(2,18,0) + printOperationGetNPagesToPrint, +#endif + printOperationSetCurrentPage, + printOperationSetUseFullPage, + printOperationSetUnit, + printOperationSetExportFilename, + printOperationSetShowProgress, + printOperationSetTrackPrintStatus, + printOperationSetCustomTabLabel, + printOperationRun, + printOperationCancel, +#if GTK_CHECK_VERSION(2,16,0) + printOperationDrawPageFinish, + printOperationSetDeferDrawing, +#endif + printOperationGetStatus, + printOperationGetStatusString, + printOperationIsFinished, + +-- * Attributes + printOperationDefaultPageSetup, + printOperationPrintSettings, + printOperationJobName, + printOperationNPages, + printOperationCurrentPage, + printOperationUseFullPage, + printOperationTrackPrintStatus, + printOperationUnit, + printOperationShowProgress, + printOperationAllowAsync, + printOperationExportFilename, + printOperationStatus, + printOperationStatusString, + printOperationCustomTabLabel, + printOperationSupportSelection, + printOperationHasSelection, + printOperationEmbedPageSetup, + printOperationNPagesToPrint, + +-- * Signals + done, + beginPrint, + paginate, + requestPageSetup, + drawPage, + endPrint, + statusChanged, + createCustomWidget, +#if GTK_CHECK_VERSION(2,18,0) + updateCustomWidget, +#endif + customWidgetApply, + preview, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.Attributes +import System.Glib.Properties +import System.Glib.UTFString +import System.Glib.GError +{#import Graphics.UI.Gtk.Types#} +{#import Graphics.UI.Gtk.Signals#} +import Graphics.UI.Gtk.Printing.PaperSize (Unit(..)) + +{# context lib="gtk" prefix="gtk" #} + +#if GTK_CHECK_VERSION(2,10,0) +-------------------- +-- Interfaces + +instance PrintOperationPreviewClass PrintOperation + +-------------------- +-- Enums +-- | The status gives a rough indication of the completion of a running print operation. +{#enum PrintStatus {underscoreToCase} deriving (Bounded,Eq,Show)#} + +-- | The action parameter to 'printOperationRun' determines what action the print operation should +-- perform. +{#enum PrintOperationAction {underscoreToCase} deriving (Bounded,Eq,Show)#} + +-- | A value of this type is returned by 'printOperationRun'. +{#enum PrintOperationResult {underscoreToCase} deriving (Bounded,Eq,Show)#} + +-- | Error codes that identify various errors that can occur while using the GTK+ printing support. +{#enum PrintError {underscoreToCase} deriving (Bounded,Eq,Show)#} + +-------------------- +-- Constructors + +-- | Creates a new 'PrintOperation'. +-- +printOperationNew :: IO PrintOperation +printOperationNew = + constructNewGObject mkPrintOperation $ + {# call gtk_print_operation_new #} + +-------------------- +-- Methods + +-- | Sets whether the 'printOperationRun' may return before the print +-- operation is completed. Note that some platforms may not allow asynchronous +-- operation. +-- +printOperationSetAllowAsync :: PrintOperationClass self => self + -> Bool -- ^ @allowAsync@ - @True@ to allow asynchronous operation + -> IO () +printOperationSetAllowAsync self allowAsync = + {# call gtk_print_operation_set_allow_async #} + (toPrintOperation self) + (fromBool allowAsync) + +-- | Call this when the result of a print operation is +-- 'PrintOperationResultError', either as returned by 'printOperationRun', or +-- in the 'done' signal handler. The returned +-- 'GError' will contain more details on what went wrong. +-- +printOperationGetError :: PrintOperationClass self => self -> IO () +printOperationGetError self = + propagateGError $ \errorPtr -> + {# call gtk_print_operation_get_error #} + (toPrintOperation self) + errorPtr + +-- | Sets the name of the print job. The name is used to identify the job +-- (e.g. in monitoring applications like eggcups). +-- +-- If you don't set a job name, Gtk+ picks a default one by numbering +-- successive print jobs. +-- +printOperationSetJobName :: PrintOperationClass self => self + -> String -- ^ @jobName@ - a string that identifies the print job + -> IO () +printOperationSetJobName self jobName = + withUTFString jobName $ \jobNamePtr -> + {# call gtk_print_operation_set_job_name #} + (toPrintOperation self) + jobNamePtr + +-- | Sets the number of pages in the document. +-- +-- This /must/ be set to a positive number before the rendering starts. It +-- may be set in a 'beginPrint' signal hander. +-- +-- Note that the page numbers passed to the 'requestPageSetup' [_$_] +-- and 'drawPage' signals +-- are 0-based, i.e. if the user chooses to print all pages, the last +-- ::draw-page signal will be for page @nPages@ - 1. +-- +printOperationSetNPages :: PrintOperationClass self => self + -> Int -- ^ @nPages@ - the number of pages + -> IO () +printOperationSetNPages self nPages = + {# call gtk_print_operation_set_n_pages #} + (toPrintOperation self) + (fromIntegral nPages) + +#if GTK_CHECK_VERSION(2,18,0) +-- | Returns the number of pages that will be printed. +-- +-- Note that this value is set during print preparation phase +-- ('PrintStatusPreparing'), so this function should never be called before the +-- data generation phase ('PrintStatusGeneratingData'). You can connect to the +-- 'statusChanged' signal and call +-- 'printOperationGetNPagesToPrint' when print status is +-- 'PrintStatusGeneratingData'. This is typically used to track the progress of +-- print operation. +-- +-- * Available since Gtk+ version 2.18 +-- +printOperationGetNPagesToPrint :: PrintOperationClass self => self + -> IO Int -- ^ returns the number of pages that will be printed +printOperationGetNPagesToPrint self = + liftM fromIntegral $ + {# call gtk_print_operation_get_n_pages_to_print #} + (toPrintOperation self) +#endif + +-- | Sets the current page. +-- +-- If this is called before 'printOperationRun', the user will be able to +-- select to print only the current page. +-- +-- Note that this only makes sense for pre-paginated documents. +-- +printOperationSetCurrentPage :: PrintOperationClass self => self + -> Int -- ^ @currentPage@ - the current page, 0-based + -> IO () +printOperationSetCurrentPage self currentPage = + {# call gtk_print_operation_set_current_page #} + (toPrintOperation self) + (fromIntegral currentPage) + +-- | If @fullPage@ is @True@, the transformation for the cairo context +-- obtained from 'PrintContext' puts the origin at the top left corner of the +-- page (which may not be the top left corner of the sheet, depending on page +-- orientation and the number of pages per sheet). Otherwise, the origin is at +-- the top left corner of the imageable area (i.e. inside the margins). +-- +printOperationSetUseFullPage :: PrintOperationClass self => self + -> Bool -- ^ @fullPage@ - @True@ to set up the 'PrintContext' for the full + -- page + -> IO () +printOperationSetUseFullPage self fullPage = + {# call gtk_print_operation_set_use_full_page #} + (toPrintOperation self) + (fromBool fullPage) + +-- | Sets up the transformation for the cairo context obtained from +-- 'PrintContext' in such a way that distances are measured in units of @unit@. +-- +printOperationSetUnit :: PrintOperationClass self => self + -> Unit -- ^ @unit@ - the unit to use + -> IO () +printOperationSetUnit self unit = + {# call gtk_print_operation_set_unit #} + (toPrintOperation self) + ((fromIntegral . fromEnum) unit) + +-- | Sets up the 'PrintOperation' to generate a file instead of showing the +-- print dialog. The indended use of this function is for implementing \"Export +-- to PDF\" actions. Currently, PDF is the only supported format. +-- +-- \"Print to PDF\" support is independent of this and is done by letting +-- the user pick the \"Print to PDF\" item from the list of printers in the +-- print dialog. +-- +printOperationSetExportFilename :: PrintOperationClass self => self + -> String -- ^ @filename@ - the filename for the exported file + -> IO () +printOperationSetExportFilename self filename = + withUTFString filename $ \filenamePtr -> + {# call gtk_print_operation_set_export_filename #} + (toPrintOperation self) + filenamePtr + +-- | If @showProgress@ is @True@, the print operation will show a progress +-- dialog during the print operation. +-- +printOperationSetShowProgress :: PrintOperationClass self => self + -> Bool -- ^ @showProgress@ - @True@ to show a progress dialog + -> IO () +printOperationSetShowProgress self showProgress = + {# call gtk_print_operation_set_show_progress #} + (toPrintOperation self) + (fromBool showProgress) + +-- | If track_status is @True@, the print operation will try to continue +-- report on the status of the print job in the printer queues and printer. +-- This can allow your application to show things like \"out of paper\" issues, +-- and when the print job actually reaches the printer. +-- +-- This function is often implemented using some form of polling, so it +-- should not be enabled unless needed. +-- +printOperationSetTrackPrintStatus :: PrintOperationClass self => self + -> Bool -- ^ @trackStatus@ - @True@ to track status after printing + -> IO () +printOperationSetTrackPrintStatus self trackStatus = + {# call gtk_print_operation_set_track_print_status #} + (toPrintOperation self) + (fromBool trackStatus) + +-- | Sets the label for the tab holding custom widgets. +-- +printOperationSetCustomTabLabel :: PrintOperationClass self => self + -> String -- ^ @label@ - the label to use, or empty to use the default + -- label + -> IO () +printOperationSetCustomTabLabel self label = + withUTFString label $ \labelPtr -> + {# call gtk_print_operation_set_custom_tab_label #} + (toPrintOperation self) + labelPtr + +-- | Runs the print operation, by first letting the user modify print settings +-- in the print dialog, and then print the document. +-- +-- Normally that this function does not return until the rendering of all +-- pages is complete. You can connect to the 'statusChanged' signal on @op@ to obtain some information about the +-- progress of the print operation. Furthermore, it may use a recursive +-- mainloop to show the print dialog. +-- +-- If you call 'printOperationSetAllowAsync' or set the 'allowAsync' [_$_] +-- property the operation will run asynchronously +-- if this is supported on the platform. The 'done' signal will be emitted with the result of the operation when +-- the it is done (i.e. when the dialog is canceled, or when the print succeeds +-- or fails). +-- +printOperationRun :: (PrintOperationClass self, WindowClass parent) => self + -> PrintOperationAction -- ^ @action@ - the action to start + -> parent -- ^ @parent@ - Transient parent of the dialog + -> IO PrintOperationResult -- ^ returns the result of the print operation. A + -- return value of 'PrintOperationResultApply' + -- indicates that the printing was completed + -- successfully. In this case, it is a good idea to + -- obtain the used print settings with + -- 'printOperationGetPrintSettings' and store them + -- for reuse with the next print operation. A value + -- of 'PrintOperationResultInProgress' means the + -- operation is running asynchronously, and will + -- emit the 'done' signal when done. +printOperationRun self action parent = + liftM (toEnum . fromIntegral) $ + propagateGError $ \errorPtr -> + {# call gtk_print_operation_run #} + (toPrintOperation self) + ((fromIntegral . fromEnum) action) + (toWindow parent) + errorPtr + +-- | Cancels a running print operation. This function may be called from a +-- 'beginPrint', 'paginate' or 'drawPage' signal handler +-- to stop the currently running print operation. +-- +printOperationCancel :: PrintOperationClass self => self -> IO () +printOperationCancel self = + {# call gtk_print_operation_cancel #} + (toPrintOperation self) + +#if GTK_CHECK_VERSION(2,16,0) +-- | Signalize that drawing of particular page is complete. +-- +-- It is called after completion of page drawing (e.g. drawing in another +-- thread). If 'printOperationSetDeferDrawing' was called before, then this +-- function has to be called by application. In another case it is called by +-- the library itself. +-- +-- * Available since Gtk+ version 2.16 +-- +printOperationDrawPageFinish :: PrintOperationClass self => self -> IO () +printOperationDrawPageFinish self = + {# call gtk_print_operation_draw_page_finish #} + (toPrintOperation self) + +-- | Sets up the 'PrintOperation' to wait for calling of +-- 'printOperationDrawPageFinish' from application. It can be used for drawing +-- page in another thread. +-- +-- This function must be called in the callback of \"draw-page\" signal. +-- +-- * Available since Gtk+ version 2.16 +-- +printOperationSetDeferDrawing :: PrintOperationClass self => self -> IO () +printOperationSetDeferDrawing self = + {# call gtk_print_operation_set_defer_drawing #} + (toPrintOperation self) +#endif + +-- | Returns the status of the print operation. Also see +-- 'printOperationGetStatusString'. +-- +printOperationGetStatus :: PrintOperationClass self => self + -> IO PrintStatus -- ^ returns the status of the print operation +printOperationGetStatus self = + liftM (toEnum . fromIntegral) $ + {# call gtk_print_operation_get_status #} + (toPrintOperation self) + +-- | Returns a string representation of the status of the print operation. The +-- string is translated and suitable for displaying the print status e.g. in a +-- 'Statusbar'. +-- +-- Use 'printOperationGetStatus' to obtain a status value that is suitable +-- for programmatic use. +-- +printOperationGetStatusString :: PrintOperationClass self => self + -> IO String -- ^ returns a string representation of the status of the print + -- operation +printOperationGetStatusString self = + {# call gtk_print_operation_get_status_string #} + (toPrintOperation self) + >>= peekUTFString + +-- | A convenience function to find out if the print operation is finished, +-- either successfu... [truncated message content] |