| 1 |
/* Copyright (C) 2006 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <vector> |
| 18 |
|
| 19 |
#include <glibmm/object.h> |
| 20 |
#include <gtkmm/enums.h> |
| 21 |
#include <gtkmm/papersize.h> |
| 22 |
|
| 23 |
_DEFS(gtkmm,gtk) |
| 24 |
_PINCLUDE(glibmm/private/object_p.h) |
| 25 |
|
| 26 |
namespace Gtk |
| 27 |
{ |
| 28 |
|
| 29 |
_WRAP_ENUM(PrintDuplex, GtkPrintDuplex, decl_prefix GTKMM_API) |
| 30 |
_WRAP_ENUM(PrintQuality, GtkPrintQuality, decl_prefix GTKMM_API) |
| 31 |
_WRAP_ENUM(PrintPages, GtkPrintPages, decl_prefix GTKMM_API) |
| 32 |
_WRAP_ENUM(PageSet, GtkPageSet, decl_prefix GTKMM_API) |
| 33 |
_WRAP_ENUM(NumberUpLayout, GtkNumberUpLayout, decl_prefix GTKMM_API) |
| 34 |
|
| 35 |
/** A PrintSettings object represents the settings of a print dialog in a system-independent way. |
| 36 |
* The main use for this object is that once you've printed you can get a settings object that |
| 37 |
* represents the settings the user chose, and the next time you print you can pass that object |
| 38 |
* in so that the user doesn't have to re-set all his settings. |
| 39 |
* |
| 40 |
* It's also possible to enumerate the settings so that you can easily save the settings for the |
| 41 |
* next time your app runs, or even store them in a document. The predefined keys try to use shared |
| 42 |
* values as much as possible so that moving such a document between systems still works. |
| 43 |
* |
| 44 |
* @newin{2,10} |
| 45 |
* |
| 46 |
* @ingroup Printing |
| 47 |
*/ |
| 48 |
class GTKMM_API PrintSettings : public Glib::Object |
| 49 |
{ |
| 50 |
_CLASS_GOBJECT(PrintSettings, GtkPrintSettings, GTK_PRINT_SETTINGS, Glib::Object, GObject, , , GTKMM_API) |
| 51 |
protected: |
| 52 |
_CTOR_DEFAULT |
| 53 |
|
| 54 |
public: |
| 55 |
_WRAP_CREATE() |
| 56 |
|
| 57 |
/** Reads the print settings from the @a key_file. |
| 58 |
* Returns a new PrintSettings object with the restored settings, |
| 59 |
* or an empty RefPtr if an error occurred. |
| 60 |
* See save_to_key_file(). |
| 61 |
* |
| 62 |
* @param key_file The KeyFile to retrieve the settings from. |
| 63 |
* @result the restored PrintSettings |
| 64 |
* |
| 65 |
* @throws KeyFileError, FileError |
| 66 |
* |
| 67 |
* @newin{2,14} |
| 68 |
*/ |
| 69 |
static Glib::RefPtr<PrintSettings> create_from_key_file(const Glib::KeyFile& key_file); |
| 70 |
|
| 71 |
/** Reads the print settings from the group @a group_name in @a key_file. |
| 72 |
* Returns a new PrintSettings object with the restored settings, |
| 73 |
* or an empty RefPtr if an error occurred. |
| 74 |
* See save_to_key_file(). |
| 75 |
* |
| 76 |
* @param key_file The KeyFile to retrieve the settings from. |
| 77 |
* @param group_name The name of the group to use. |
| 78 |
* @result the restored PrintSettings |
| 79 |
* |
| 80 |
* @throws KeyFileError, FileError |
| 81 |
* |
| 82 |
* @newin{2,14} |
| 83 |
*/ |
| 84 |
static Glib::RefPtr<PrintSettings> create_from_key_file(const Glib::KeyFile& key_file, const Glib::ustring& group_name); |
| 85 |
_IGNORE(gtk_print_settings_new_from_key_file) |
| 86 |
|
| 87 |
/** Reads the print settings from @a file_name. Returns a new PrintSettings |
| 88 |
* object with the restored settings, or an empty RefPtr if an error occurred. |
| 89 |
* See save_to_file(). |
| 90 |
* |
| 91 |
* @param file_name The filename to read the settings from. |
| 92 |
* @result the restored PrintSettings |
| 93 |
* |
| 94 |
* @throws KeyFileError, FileError |
| 95 |
* |
| 96 |
* @newin{2,14} |
| 97 |
*/ |
| 98 |
static Glib::RefPtr<PrintSettings> create_from_file(const std::string& file_name); |
| 99 |
_IGNORE(gtk_print_settings_new_from_file) |
| 100 |
|
| 101 |
/** Print settings keys. |
| 102 |
*/ |
| 103 |
class Keys |
| 104 |
{ |
| 105 |
public: |
| 106 |
static const Glib::ustring PRINTER; |
| 107 |
static const Glib::ustring ORIENTATION; |
| 108 |
static const Glib::ustring PAPER_FORMAT; |
| 109 |
static const Glib::ustring PAPER_WIDTH; |
| 110 |
static const Glib::ustring PAPER_HEIGHT; |
| 111 |
static const Glib::ustring NUM_COPIES; |
| 112 |
static const Glib::ustring DEFAULT_SOURCE; |
| 113 |
static const Glib::ustring QUALITY; |
| 114 |
static const Glib::ustring RESOLUTION; |
| 115 |
static const Glib::ustring USE_COLOR; |
| 116 |
static const Glib::ustring DUPLEX; |
| 117 |
static const Glib::ustring COLLATE; |
| 118 |
static const Glib::ustring REVERSE; |
| 119 |
static const Glib::ustring MEDIA_TYPE; |
| 120 |
static const Glib::ustring DITHER; |
| 121 |
static const Glib::ustring SCALE; |
| 122 |
static const Glib::ustring PRINT_PAGES; |
| 123 |
static const Glib::ustring PAGE_RANGES; |
| 124 |
static const Glib::ustring PAGE_SET; |
| 125 |
static const Glib::ustring FINISHINGS; |
| 126 |
static const Glib::ustring NUMBER_UP; |
| 127 |
static const Glib::ustring NUMBER_UP_LAYOUT; |
| 128 |
static const Glib::ustring OUTPUT_BIN; |
| 129 |
|
| 130 |
static const Glib::ustring OUTPUT_FILE_FORMAT; |
| 131 |
static const Glib::ustring OUTPUT_URI; |
| 132 |
|
| 133 |
static const Glib::ustring WIN32_DRIVER_VERSION; |
| 134 |
static const Glib::ustring WIN32_DRIVER_EXTRA; |
| 135 |
}; |
| 136 |
|
| 137 |
_WRAP_METHOD(Glib::RefPtr<PrintSettings> copy() const, gtk_print_settings_copy) |
| 138 |
|
| 139 |
//The from_ infix was added to these functions to make them clearer. GTK+ didn't want to change them. |
| 140 |
_WRAP_METHOD(bool load_from_file(const std::string& file_name), gtk_print_settings_load_file, errthrow) |
| 141 |
|
| 142 |
#m4 _CONVERSION(`const Glib::KeyFile&', `GKeyFile*', __FCR2P) |
| 143 |
_WRAP_METHOD(bool load_from_key_file(const Glib::KeyFile& key_file, const Glib::ustring& group_name), gtk_print_settings_load_key_file, errthrow) |
| 144 |
|
| 145 |
/** Reads the print settings from the @a key_file. |
| 146 |
* See save_to_key_file(). |
| 147 |
* |
| 148 |
* @param key_file The KeyFile to retrieve the settings from. |
| 149 |
* @result true on success. |
| 150 |
* |
| 151 |
* @throws KeyFileError, FileError |
| 152 |
* |
| 153 |
* @newin{2,14} |
| 154 |
*/ |
| 155 |
bool load_from_key_file(const Glib::KeyFile& key_file); |
| 156 |
|
| 157 |
|
| 158 |
//The save_ prefix was added to these functions to make them clearer. GTK+ didn't want to change them. |
| 159 |
_WRAP_METHOD(bool save_to_file(const std::string& file_name) const, gtk_print_settings_to_file, errthrow) |
| 160 |
|
| 161 |
#m4 _CONVERSION(`Glib::KeyFile&', `GKeyFile*', __FR2P) |
| 162 |
_WRAP_METHOD(void save_to_key_file(Glib::KeyFile& key_file, const Glib::ustring& group_name) const, gtk_print_settings_to_key_file) |
| 163 |
|
| 164 |
/** This function adds the print settings from @a settings to @a key_file, |
| 165 |
* in the "Print Settings" group. |
| 166 |
* |
| 167 |
* @newin{2,12} |
| 168 |
* |
| 169 |
* @param key_file The Glib::KeyFile to save the print settings to. |
| 170 |
*/ |
| 171 |
void save_to_key_file(Glib::KeyFile& key_file) const; |
| 172 |
|
| 173 |
//TODO: add a @see link? |
| 174 |
_WRAP_METHOD(bool has_key(const Glib::ustring& key) const, gtk_print_settings_has_key) |
| 175 |
|
| 176 |
_WRAP_METHOD(Glib::ustring get(const Glib::ustring& key) const, gtk_print_settings_get) |
| 177 |
|
| 178 |
_WRAP_METHOD(void set(const Glib::ustring& key, const Glib::ustring& value), gtk_print_settings_set) |
| 179 |
_WRAP_METHOD(void unset(const Glib::ustring& key), gtk_print_settings_unset) |
| 180 |
|
| 181 |
/** For example, |
| 182 |
* void on_foreach_setting(const Glib::ustring& key, const Glib::ustring& value); |
| 183 |
*/ |
| 184 |
typedef sigc::slot<void, const Glib::ustring&, const Glib::ustring&> SlotForeach; |
| 185 |
|
| 186 |
/** Calls a function for each print setting. |
| 187 |
* @param slot The callback to call for each print setting. |
| 188 |
*/ |
| 189 |
void setting_foreach(const SlotForeach& slot); |
| 190 |
|
| 191 |
_IGNORE(gtk_print_settings_foreach) |
| 192 |
|
| 193 |
_WRAP_METHOD(bool get_bool(const Glib::ustring& key) const, gtk_print_settings_get_bool) |
| 194 |
_WRAP_METHOD(void set_bool(const Glib::ustring& key, bool value = true), gtk_print_settings_set_bool) |
| 195 |
|
| 196 |
_WRAP_METHOD(double get_double(const Glib::ustring& key) const, gtk_print_settings_get_double) |
| 197 |
_WRAP_METHOD(double get_double_with_default(const Glib::ustring& key, double def) const, |
| 198 |
gtk_print_settings_get_double_with_default) |
| 199 |
_WRAP_METHOD(void set_double(const Glib::ustring& key, double value), gtk_print_settings_set_double) |
| 200 |
|
| 201 |
_WRAP_METHOD(double get_length(const Glib::ustring& key, Unit unit) const, gtk_print_settings_get_length) |
| 202 |
_WRAP_METHOD(void set_length(const Glib::ustring& key, double value, Unit unit), gtk_print_settings_set_length) |
| 203 |
|
| 204 |
_WRAP_METHOD(int get_int(const Glib::ustring& key) const, gtk_print_settings_get_int) |
| 205 |
_WRAP_METHOD(int get_int_with_default(const Glib::ustring& key, int def) const, |
| 206 |
gtk_print_settings_get_int_with_default) |
| 207 |
_WRAP_METHOD(void set_int(const Glib::ustring& key, int value), gtk_print_settings_set_int) |
| 208 |
|
| 209 |
// helpers: |
| 210 |
|
| 211 |
_WRAP_METHOD(Glib::ustring get_printer() const, gtk_print_settings_get_printer) |
| 212 |
_WRAP_METHOD(void set_printer(const Glib::ustring& printer), gtk_print_settings_set_printer) |
| 213 |
|
| 214 |
_WRAP_METHOD(PageOrientation get_orientation() const, gtk_print_settings_get_orientation) |
| 215 |
_WRAP_METHOD(void set_orientation(PageOrientation orientation), gtk_print_settings_set_orientation) |
| 216 |
|
| 217 |
_WRAP_METHOD(PaperSize get_paper_size(), gtk_print_settings_get_paper_size) |
| 218 |
_WRAP_METHOD(const PaperSize get_paper_size() const, gtk_print_settings_get_paper_size, constversion) |
| 219 |
_WRAP_METHOD(void set_paper_size(const PaperSize& paper_size), gtk_print_settings_set_paper_size) |
| 220 |
|
| 221 |
_WRAP_METHOD(double get_paper_width(Unit unit) const, gtk_print_settings_get_paper_width) |
| 222 |
_WRAP_METHOD(void set_paper_width(double width, Unit unit), gtk_print_settings_set_paper_width) |
| 223 |
_WRAP_METHOD(double get_paper_height(Unit unit) const, gtk_print_settings_get_paper_height) |
| 224 |
_WRAP_METHOD(void set_paper_height(double height, Unit unit), gtk_print_settings_set_paper_height) |
| 225 |
|
| 226 |
_WRAP_METHOD(bool get_use_color() const, gtk_print_settings_get_use_color) |
| 227 |
_WRAP_METHOD(void set_use_color(bool use_color = true), gtk_print_settings_set_use_color) |
| 228 |
|
| 229 |
_WRAP_METHOD(bool get_collate() const, gtk_print_settings_get_collate) |
| 230 |
_WRAP_METHOD(void set_collate(bool collate = true), gtk_print_settings_set_collate) |
| 231 |
|
| 232 |
_WRAP_METHOD(bool get_reverse() const, gtk_print_settings_get_reverse) |
| 233 |
_WRAP_METHOD(void set_reverse(bool reverse = true), gtk_print_settings_set_reverse) |
| 234 |
|
| 235 |
_WRAP_METHOD(PrintDuplex get_duplex() const, gtk_print_settings_get_duplex) |
| 236 |
_WRAP_METHOD(void set_duplex(PrintDuplex duplex), gtk_print_settings_set_duplex) |
| 237 |
|
| 238 |
_WRAP_METHOD(PrintQuality get_quality() const, gtk_print_settings_get_quality) |
| 239 |
_WRAP_METHOD(void set_quality(PrintQuality quality), gtk_print_settings_set_quality) |
| 240 |
|
| 241 |
_WRAP_METHOD(int get_n_copies() const, gtk_print_settings_get_n_copies) |
| 242 |
_WRAP_METHOD(void set_n_copies(int num_copies), gtk_print_settings_set_n_copies) |
| 243 |
|
| 244 |
_WRAP_METHOD(int get_number_up() const, gtk_print_settings_get_number_up) |
| 245 |
_WRAP_METHOD(void set_number_up(int number_up), gtk_print_settings_set_number_up) |
| 246 |
|
| 247 |
_WRAP_METHOD(NumberUpLayout get_number_up_layout() const, gtk_print_settings_get_number_up_layout) |
| 248 |
_WRAP_METHOD(void set_number_up(NumberUpLayout number_up_layout), gtk_print_settings_set_number_up_layout) |
| 249 |
|
| 250 |
_WRAP_METHOD(int get_resolution() const, gtk_print_settings_get_resolution) |
| 251 |
_WRAP_METHOD(void set_resolution(int resolution), gtk_print_settings_set_resolution) |
| 252 |
|
| 253 |
_WRAP_METHOD(int get_resolution_x() const, gtk_print_settings_get_resolution_x) |
| 254 |
_WRAP_METHOD(int get_resolution_y() const, gtk_print_settings_get_resolution_y) |
| 255 |
_WRAP_METHOD(void set_resolution_xy(int resolution_x, int resolution_y), gtk_print_settings_set_resolution_xy) |
| 256 |
_WRAP_METHOD(double get_printer_lpi() const, gtk_print_settings_get_printer_lpi) |
| 257 |
_WRAP_METHOD(void set_printer_lpi(double lpi), gtk_print_settings_set_printer_lpi) |
| 258 |
|
| 259 |
_WRAP_METHOD(double get_scale() const, gtk_print_settings_get_scale) |
| 260 |
_WRAP_METHOD(void set_scale(double scale), gtk_print_settings_set_scale) |
| 261 |
|
| 262 |
_WRAP_METHOD(PrintPages get_print_pages() const, gtk_print_settings_get_print_pages) |
| 263 |
_WRAP_METHOD(void set_print_pages(PrintPages pages), gtk_print_settings_set_print_pages) |
| 264 |
|
| 265 |
//TODO: Move this out of the class when we can break ABI, |
| 266 |
//because this is also used in PringJob. |
| 267 |
//This corresponds to GtkPageRange. |
| 268 |
class PageRange |
| 269 |
{ |
| 270 |
public: |
| 271 |
PageRange(); |
| 272 |
PageRange(int start, int end); |
| 273 |
|
| 274 |
int start; |
| 275 |
int end; |
| 276 |
}; |
| 277 |
|
| 278 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 279 |
struct PageRangeTraits |
| 280 |
{ |
| 281 |
typedef PageRange CppType; |
| 282 |
typedef GtkPageRange CType; |
| 283 |
typedef GtkPageRange CTypeNonConst; |
| 284 |
|
| 285 |
static CType to_c_type (CType c_obj) { return c_obj; } |
| 286 |
static void release_c_type (CType) {} |
| 287 |
static CType to_c_type (const CppType& cpp_obj) { CTypeNonConst c_obj = {cpp_obj.start, cpp_obj.end}; return c_obj; } |
| 288 |
static CppType to_cpp_type (CType c_obj) { return CppType (c_obj.start, c_obj.end); } |
| 289 |
}; |
| 290 |
#endif // DOXYGEN_SHOULD_SKIP_THIS |
| 291 |
|
| 292 |
std::vector<PageRange> get_page_ranges() const; |
| 293 |
void set_page_ranges(const std::vector<PageRange>& page_ranges); |
| 294 |
|
| 295 |
_IGNORE(gtk_print_settings_get_page_ranges, gtk_print_settings_set_page_ranges) |
| 296 |
|
| 297 |
_WRAP_METHOD(PageSet get_page_set() const, gtk_print_settings_get_page_set) |
| 298 |
_WRAP_METHOD(void set_page_set(PageSet page_set), gtk_print_settings_set_page_set) |
| 299 |
|
| 300 |
_WRAP_METHOD(Glib::ustring get_default_source() const, gtk_print_settings_get_default_source) |
| 301 |
_WRAP_METHOD(void set_default_source(const Glib::ustring& default_source), gtk_print_settings_set_default_source) |
| 302 |
|
| 303 |
_WRAP_METHOD(Glib::ustring get_media_type() const, gtk_print_settings_get_media_type) |
| 304 |
_WRAP_METHOD(void set_media_type(const Glib::ustring& media_type), gtk_print_settings_set_media_type) |
| 305 |
|
| 306 |
_WRAP_METHOD(Glib::ustring get_dither() const, gtk_print_settings_get_dither) |
| 307 |
_WRAP_METHOD(void set_dither(const Glib::ustring& dither), gtk_print_settings_set_dither) |
| 308 |
|
| 309 |
_WRAP_METHOD(Glib::ustring get_finishings() const, gtk_print_settings_get_finishings) |
| 310 |
_WRAP_METHOD(void set_finishings(const Glib::ustring& finishings), gtk_print_settings_set_finishings) |
| 311 |
|
| 312 |
_WRAP_METHOD(Glib::ustring get_output_bin() const, gtk_print_settings_get_output_bin) |
| 313 |
_WRAP_METHOD(void set_output_bin(const Glib::ustring& output_bin), gtk_print_settings_set_output_bin) |
| 314 |
|
| 315 |
//There are no properties. |
| 316 |
}; |
| 317 |
|
| 318 |
} // namespace Gtk |