[Xfce4-commits] <xfc:master> More paper size
Bo Lorensen
noreply at xfce.org
Sun Apr 18 21:54:01 CEST 2010
Updating branch refs/heads/master
to 2d1da72894755c1fe5324cfc41c2f4052357450e (commit)
from cd2bace4ccdf894001000963fcb1608cf2611158 (commit)
commit 2d1da72894755c1fe5324cfc41c2f4052357450e
Author: Bo Lorensen <bl at lue.dk>
Date: Sun Apr 18 21:52:03 2010 +0200
More paper size
ChangeLog | 5 +
configure.ac | 2 +-
libXFCcore/xfc/version.hh | 2 +-
libXFCui/xfc/gtk/Makefile.am | 2 -
libXFCui/xfc/gtk/printoperation.hh | 212 +++++++++++++++++++++++++++++++++++-
libXFCui/xfc/gtk/printpagesetup.cc | 14 ++-
libXFCui/xfc/gtk/printpagesetup.hh | 21 +++-
libXFCui/xfc/gtk/printsetting.cc | 29 +++--
libXFCui/xfc/gtk/printsetting.hh | 45 ++++++--
9 files changed, 296 insertions(+), 36 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8bf53e4..04d6572 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-04-17 Bo Lorentsen <bl at lue.dk>
+
+ * Add PaperSize implimentation, to be able to request for non default
+ pages sizes.
+
2009-09-10 Bo Lorentsen <bl at lue.dk>
* Remove xfce-panel build in automake if not Xfce 4.7 or later
diff --git a/configure.ac b/configure.ac
index 190cce0..d0646f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,7 +9,7 @@ dnl --------------------------------------------------------------
m4_define([xfc_major_version], [4])
m4_define([xfc_minor_version], [3])
-m4_define([xfc_micro_version], [3])
+m4_define([xfc_micro_version], [4])
m4_define([xfc_api_version], [xfc_major_version.xfc_minor_version])
m4_define([xfc_version], [xfc_major_version.xfc_minor_version.xfc_micro_version])
diff --git a/libXFCcore/xfc/version.hh b/libXFCcore/xfc/version.hh
index 33bf0c0..a4d4026 100644
--- a/libXFCcore/xfc/version.hh
+++ b/libXFCcore/xfc/version.hh
@@ -29,7 +29,7 @@
#define XFC_MINOR_VERSION (3)
/// Compile time micro version macro.
-#define XFC_MICRO_VERSION (3)
+#define XFC_MICRO_VERSION (4)
/// @name Library Version
/// @{
diff --git a/libXFCui/xfc/gtk/Makefile.am b/libXFCui/xfc/gtk/Makefile.am
index 5261d13..205aafd 100755
--- a/libXFCui/xfc/gtk/Makefile.am
+++ b/libXFCui/xfc/gtk/Makefile.am
@@ -132,7 +132,6 @@ hh_sources = \
printoperation.hh \
printoperationsignals.hh \
printpagesetup.hh \
- printpapersize.hh \
printsetting.hh \
radioaction.hh \
radioactionsignals.hh \
@@ -329,7 +328,6 @@ cc_sources = \
printoperation.cc \
printoperationsignals.cc \
printpagesetup.cc \
- printpapersize.cc \
printsetting.cc \
progressbar.cc \
radioaction.cc \
diff --git a/libXFCui/xfc/gtk/printoperation.hh b/libXFCui/xfc/gtk/printoperation.hh
index 04efbd3..d11c288 100644
--- a/libXFCui/xfc/gtk/printoperation.hh
+++ b/libXFCui/xfc/gtk/printoperation.hh
@@ -51,6 +51,29 @@ namespace Xfc {
FINISHED_ABORTED = GTK_PRINT_STATUS_FINISHED_ABORTED
};
+ /**
+ Gtk::PrintOperation is the high-level, portable printing API.
+ It looks a bit different than other GTK+ dialogs such as the
+ GtkFileChooser, since some platforms don't expose enough infrastructure
+ to implement a good print dialog. On such platforms, Gtk::PrintOperation
+ uses the native print dialog. On platforms which do not
+ provide a native print dialog, GTK+ uses its own
+
+ @see Gtk::PrintUnixDialog.
+
+ The typical way to use the high-level printing API is to create
+ a Gtk::PrintOperation object with construcor
+ when the user selects to print. Then you set some properties
+ on it, e.g. the page size, any Gtk::PrintSettings from previous
+ print operations, the number of pages, the current page, etc.
+
+ Then you start the print operation by calling run(). 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 Gtk::PrintOperation, the main one being
+ draw-page, which you are supposed to catch and render the
+ page on the provided Gtk::PrintContext using Cairo.
+ */
class PrintOperation : public PrintOperationPreview {
friend class G::Object;
@@ -132,21 +155,208 @@ namespace Xfc {
/// @name Methods
/// @{
+ /**
+ Sets whether the run() may return before the print
+ operation is completed.
+
+ @note that some platforms may not allow asynchronous operation.
+
+ @param allow_async true to allow asynchronous operation
+ */
void set_allow_async(bool allow_async);
+
+ /**
+ Makes default_page_setup the default page setup for op.
+
+ This page setup will be used by run(), but it can be
+ overridden on a per-page basis by connecting to the
+ "request-page-setup" signal.
+
+ @param default_page_setup a GtkPageSetup, or NULL. allow-none.
+ */
void set_default_page_setup( PageSetup *default_page_setup);
+
+ /**
+ Returns the default page setup.
+
+ @see set_default_page_setup()
+ @return the default page setup
+ */
PageSetup* get_default_page_setup();
+
+ /**
+ Sets the print settings for op. This is typically used to
+ re-establish print settings from a previous print operation.
+
+ @see gtk_print_operation_run().
+
+ @param print_settings Gtk::PrintSettings. allow-none.
+ */
void set_print_settings( PrintSettings *print_settings );
+
+ /**
+ Returns the current print settings.
+
+ @note that the return value is NULL until either set_print_settings() or run() have been called.
+ @return the current print settings of op.
+ */
PrintSettings* get_print_settings();
+
+ /**
+ 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.
+
+ @param job_name a string that identifies the print job
+ */
void set_job_name( const String &job_name );
+
+ /**
+ 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 "begin-print" signal hander.
+
+ Note that the page numbers passed to the "request-page-setup"
+ and "draw-page" signals are 0-based, i.e. if the user
+ chooses to print all pages, the last ::draw-page signal
+ will be for page n_pages - 1.
+
+ @param n_pages the number of pages
+ */
void set_n_pages( int n_pages );
+
+ /**
+ Returns the number of pages that will be printed.
+
+ Note that this value is set during print preparation phase
+ (GTK_PRINT_STATUS_PREPARING), so this function should
+ never be called before the data generation phase
+ (GTK_PRINT_STATUS_GENERATING_DATA). You can connect to
+ the "status-changed" signal and call get_n_pages_to_print()
+ when print status is GTK_PRINT_STATUS_GENERATING_DATA.
+ This is typically used to track the progress of print operation.
+
+ @eturn the number of pages that will be printed
+ */
+ int get_n_pages_to_print();
+
+ /**
+ Sets the current page.
+
+ If this is called before run(), the user will be able to
+ select to print only the current page.
+
+ @note that this only makes sense for pre-paginated documents.
+
+ @param current_page the current page, 0-based
+ */
void set_current_page( int current_page);
- void set_use_full_page( bool full_page);
+
+ /**
+ If full_page is true, the transformation for the cairo context
+ obtained from GtkPrintContext 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).
+
+ @params full_page true to set up the Gtk::PrintContext for the full page
+ */
+ void set_use_full_page( bool full_page );
+
+ /**
+ Sets up the transformation for the cairo context obtained
+ from Gtk::PrintContext in such a way that distances are
+ measured in units of unit.
+
+ @param unit the unit to use
+ */
void set_unit(Gtk::Unit unit);
+
+ /**
+ Sets up the Gtk::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.
+
+ @param filename the filename for the exported file
+ */
void set_export_filename( const String &filename);
+
+ /**
+ If show_progress is true, the print operation will show a
+ progress dialog during the print operation.
+
+ @param show_progress true to show a progress dialog
+ */
void set_show_progress( bool show_progress);
+
+ /**
+ 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.
+
+ @param track_status true to track status after printing
+ */
void set_track_print_status( bool track_status);
+
+ /**
+ Sets the label for the tab holding custom widgets.
+
+ @param label the label to use, or NULL to use the default label. allow-none.
+ */
void set_custom_tab_label( const String &label);
+
+ /**
+ 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 "status-changed"
+ 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 set_allow_async() or set the "allow-async" 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).
+
+ @note that run() can only be called once on a given GtkPrintOperation.
+
+ @param action the action to start
+ @param parent Transient parent of the dialog. allow-none.
+ @param error Return location for errors, or NULL. allow-none.
+ @return the result of the print operation. A return value of
+ GTK_PRINT_OPERATION_RESULT_APPLY indicates that the printing
+ was completed successfully. In this case, it is a good idea
+ to obtain the used print settings with get_print_settings()
+ and store them for reuse with the next print operation.
+ A value of GTK_PRINT_OPERATION_RESULT_IN_PROGRESS means the
+ operation is running asynchronously, and will emit the "done"
+ signal when done.
+ */
PrintOperationResult run( PrintOperationAction action, Window *parent = NULL);
+
+ /**
+ Cancels a running print operation. This function may be called
+ from a "begin-print", "paginate" or "draw-page" signal handler
+ to stop the currently running print operation.
+ */
void cancel();
/// @}
diff --git a/libXFCui/xfc/gtk/printpagesetup.cc b/libXFCui/xfc/gtk/printpagesetup.cc
index cd0b3cc..3504116 100644
--- a/libXFCui/xfc/gtk/printpagesetup.cc
+++ b/libXFCui/xfc/gtk/printpagesetup.cc
@@ -2,6 +2,8 @@
//#include "private/printpagesetupclass.hh"
#include "atk/object.hh"
+#include <xfc/gtk/printsetting.hh>
+
namespace Xfc {
namespace Gtk {
@@ -16,7 +18,7 @@ PageSetup::PageSetup( GtkPageSetup *ctx, bool owns_reference ) : G::Object((GObj
PageOrientation PageSetup::get_orientation()
{
- gtk_page_setup_get_orientation( gtk_page_setup());
+ return (PageOrientation)gtk_page_setup_get_orientation( gtk_page_setup());
}
void PageSetup::set_orientation( PageOrientation orientation )
@@ -24,17 +26,17 @@ void PageSetup::set_orientation( PageOrientation orientation )
gtk_page_setup_set_orientation( gtk_page_setup(), (GtkPageOrientation)orientation );
}
-#if 0
-PaperSize* PageSetup::get_paper_size()
+PaperSize PageSetup::get_paper_size()
{
+ return PaperSize( gtk_page_setup_get_paper_size( gtk_page_setup()));
}
-void PageSetup::set_paper_size( PaperSize *size)
+void PageSetup::set_paper_size( const PaperSize &size )
{
+ gtk_page_setup_set_paper_size( gtk_page_setup(), (GtkPaperSize*)size );
}
-#endif
-double PageSetup::get_top_margin( Unit unit)
+double PageSetup::get_top_margin( Unit unit )
{
return gtk_page_setup_get_top_margin( gtk_page_setup(), (GtkUnit)unit );
}
diff --git a/libXFCui/xfc/gtk/printpagesetup.hh b/libXFCui/xfc/gtk/printpagesetup.hh
index 07f7dca..e110baa 100644
--- a/libXFCui/xfc/gtk/printpagesetup.hh
+++ b/libXFCui/xfc/gtk/printpagesetup.hh
@@ -40,6 +40,23 @@ namespace Xfc {
PAGE_ORIENTATION_REVERSE_LANDSCAPE = GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
};
+ /**
+ A Gtk::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 Gtk::PrintOperation
+ when printing. The benefit of splitting this out of the Gtk::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.
+
+ use gtk_print_run_page_setup_dialog() to show the page setup
+ dialog and receive the resulting page setup.
+ */
class PageSetup : public G::Object {
public:
PageSetup();
@@ -52,8 +69,8 @@ namespace Xfc {
PageOrientation get_orientation();
void set_orientation( PageOrientation orientation );
- PaperSize* get_paper_size();
- void set_paper_size( PaperSize *size);
+ PaperSize get_paper_size();
+ void set_paper_size( const PaperSize &size);
double get_top_margin( Unit unit);
void set_top_margin( double margin, Unit unit);
double get_bottom_margin( Unit unit);
diff --git a/libXFCui/xfc/gtk/printsetting.cc b/libXFCui/xfc/gtk/printsetting.cc
index 3ff0293..ff46014 100644
--- a/libXFCui/xfc/gtk/printsetting.cc
+++ b/libXFCui/xfc/gtk/printsetting.cc
@@ -55,7 +55,12 @@ Gtk::PaperSize::PaperSize( GtkPaperSize *papersize )
_papersize = papersize;
}
-Gtk::PaperSize::PaperSize( const PaperSize &ps )
+Gtk::PaperSize::PaperSize( const String &name, const String &display_name, double width, double height, Unit unit )
+{
+ _papersize = gtk_paper_size_new_custom(name.c_str(), display_name.c_str(), width, height, (GtkUnit)unit);
+}
+
+Gtk::PaperSize::PaperSize( const Gtk::PaperSize &ps )
{
_papersize = gtk_paper_size_copy( ps._papersize );
}
@@ -66,37 +71,37 @@ Gtk::PaperSize::~PaperSize()
gtk_paper_size_free( _papersize );
}
-bool Gtk::PaperSize::is_equal( const PaperSize &size2)
+bool Gtk::PaperSize::is_equal( const Gtk::PaperSize &size2) const
{
return gtk_paper_size_is_equal( _papersize, size2 );
}
-const String Gtk::PaperSize::get_name()
+const String Gtk::PaperSize::get_name() const
{
return gtk_paper_size_get_name( _papersize );
}
-const String Gtk::PaperSize::get_display_name()
+const String Gtk::PaperSize::get_display_name() const
{
return gtk_paper_size_get_display_name( _papersize );
}
-const String Gtk::PaperSize::get_ppd_name()
+const String Gtk::PaperSize::get_ppd_name() const
{
return gtk_paper_size_get_ppd_name( _papersize );
}
-double Gtk::PaperSize::get_width(Unit unit)
+double Gtk::PaperSize::get_width(Unit unit) const
{
return gtk_paper_size_get_width( _papersize, (GtkUnit)unit );
}
-double Gtk::PaperSize::get_height(Unit unit)
+double Gtk::PaperSize::get_height(Unit unit) const
{
return gtk_paper_size_get_height( _papersize, (GtkUnit)unit );
}
-bool Gtk::PaperSize::is_custom()
+bool Gtk::PaperSize::is_custom() const
{
return gtk_paper_size_is_custom( _papersize );
}
@@ -106,22 +111,22 @@ void Gtk::PaperSize::set_size( double width, double height, Unit unit)
gtk_paper_size_set_size( _papersize, width, height, (GtkUnit)unit );
}
-double Gtk::PaperSize::get_default_top_margin(Unit unit)
+double Gtk::PaperSize::get_default_top_margin(Unit unit) const
{
return gtk_paper_size_get_default_top_margin( _papersize, (GtkUnit)unit );
}
-double Gtk::PaperSize::get_default_bottom_margin(Unit unit)
+double Gtk::PaperSize::get_default_bottom_margin(Unit unit) const
{
return gtk_paper_size_get_default_bottom_margin( _papersize, (GtkUnit)unit );
}
-double Gtk::PaperSize::get_default_left_margin(Unit unit)
+double Gtk::PaperSize::get_default_left_margin(Unit unit) const
{
return gtk_paper_size_get_default_left_margin( _papersize, (GtkUnit)unit );
}
-double Gtk::PaperSize::get_default_right_margin(Unit unit)
+double Gtk::PaperSize::get_default_right_margin(Unit unit) const
{
return gtk_paper_size_get_default_right_margin( _papersize, (GtkUnit)unit );
}
diff --git a/libXFCui/xfc/gtk/printsetting.hh b/libXFCui/xfc/gtk/printsetting.hh
index 2e0e14a..65b73bc 100644
--- a/libXFCui/xfc/gtk/printsetting.hh
+++ b/libXFCui/xfc/gtk/printsetting.hh
@@ -52,11 +52,32 @@ namespace Xfc {
PAGES_CURRENT = GTK_PRINT_PAGES_CURRENT,
PAGES_RANGES = GTK_PRINT_PAGES_RANGES
};
-
+
+ /**
+ 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 gtk_page_setup_new() to get the defaults,
+ or use run_page_setup_dialog() to show the page setup
+ dialog and receive the resulting page setup.
+ */
class PaperSize {
GtkPaperSize *_papersize;
public:
PaperSize( const String &name );
+ PaperSize( const String &name, const String &display_name, double width, double height, Unit unit );
+
+ /// The pointer will be freed when this class are destroyed !
PaperSize( GtkPaperSize * );
PaperSize( const PaperSize & );
@@ -64,18 +85,20 @@ namespace Xfc {
operator GtkPaperSize *() const {return _papersize;}
- bool is_equal( const PaperSize &size2);
- const String get_name();
- const String get_display_name();
- const String get_ppd_name();
- double get_width(Unit unit);
- double get_height(Unit unit);
- bool is_custom();
+ bool is_equal( const PaperSize &size2) const;
+ const String get_name() const;
+ const String get_display_name() const;
+ const String get_ppd_name() const;
+ double get_width(Unit unit) const;
+ double get_height(Unit unit) const;
+ bool is_custom() const;
+ double get_default_top_margin(Unit unit) const;
+ double get_default_bottom_margin(Unit unit) const;
+ double get_default_left_margin(Unit unit) const;
+ double get_default_right_margin(Unit unit) const;
+
void set_size( double width, double height, Unit unit);
- double get_default_top_margin(Unit unit);
- double get_default_bottom_margin(Unit unit);
- double get_default_left_margin(Unit unit);
- double get_default_right_margin(Unit unit);
+
static const String get_default(void);
};
More information about the Xfce4-commits
mailing list