1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is Mozilla Foundation.
18 * Portions created by the Initial Developer are Copyright (C) 2008
19 * the Initial Developer. All Rights Reserved.
22 * Michael Ventnor <m.ventnor@gmail.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsPrintSettingsGTK.h"
39 #include "nsILocalFile.h"
40 #include "nsNetUtil.h"
44 gboolean
ref_printer(GtkPrinter
*aPrinter
, gpointer aData
)
46 ((nsPrintSettingsGTK
*) aData
)->SetGtkPrinter(aPrinter
);
51 gboolean
printer_enumerator(GtkPrinter
*aPrinter
, gpointer aData
)
53 if (gtk_printer_is_default(aPrinter
))
54 return ref_printer(aPrinter
, aData
);
56 return FALSE
; // Keep 'em coming...
60 GtkPaperSize
* moz_gtk_paper_size_copy_to_new_custom(GtkPaperSize
* oldPaperSize
)
62 // We make a "custom-ified" copy of the paper size so it can be changed later.
63 return gtk_paper_size_new_custom(gtk_paper_size_get_name(oldPaperSize
),
64 gtk_paper_size_get_display_name(oldPaperSize
),
65 gtk_paper_size_get_width(oldPaperSize
, GTK_UNIT_INCH
),
66 gtk_paper_size_get_height(oldPaperSize
, GTK_UNIT_INCH
),
70 NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsGTK
,
74 /** ---------------------------------------------------
76 nsPrintSettingsGTK::nsPrintSettingsGTK() :
80 mPrintSelectionOnly(PR_FALSE
)
82 // The aim here is to set up the objects enough that silent printing works well.
83 // These will be replaced anyway if the print dialog is used.
84 mPrintSettings
= gtk_print_settings_new();
85 mPageSetup
= gtk_page_setup_new();
86 InitUnwriteableMargin();
88 SetOutputFormat(nsIPrintSettings::kOutputFormatNative
);
90 GtkPaperSize
* defaultPaperSize
= gtk_paper_size_new(NULL
);
91 mPaperSize
= moz_gtk_paper_size_copy_to_new_custom(defaultPaperSize
);
92 gtk_paper_size_free(defaultPaperSize
);
96 /** ---------------------------------------------------
98 nsPrintSettingsGTK::~nsPrintSettingsGTK()
101 g_object_unref(mPageSetup
);
104 if (mPrintSettings
) {
105 g_object_unref(mPrintSettings
);
106 mPrintSettings
= NULL
;
109 g_object_unref(mGTKPrinter
);
112 gtk_paper_size_free(mPaperSize
);
115 /** ---------------------------------------------------
117 nsPrintSettingsGTK::nsPrintSettingsGTK(const nsPrintSettingsGTK
& aPS
) :
119 mPrintSettings(NULL
),
121 mPrintSelectionOnly(PR_FALSE
)
126 /** ---------------------------------------------------
128 nsPrintSettingsGTK
& nsPrintSettingsGTK::operator=(const nsPrintSettingsGTK
& rhs
)
134 nsPrintSettings::operator=(rhs
);
137 g_object_unref(mPageSetup
);
138 mPageSetup
= gtk_page_setup_copy(rhs
.mPageSetup
);
139 // NOTE: No need to re-initialize mUnwriteableMargin here (even
140 // though mPageSetup is changing). It'll be copied correctly by
141 // nsPrintSettings::operator=.
144 g_object_unref(mPrintSettings
);
145 mPrintSettings
= gtk_print_settings_copy(rhs
.mPrintSettings
);
148 g_object_unref(mGTKPrinter
);
149 mGTKPrinter
= (GtkPrinter
*) g_object_ref(rhs
.mGTKPrinter
);
151 mPrintSelectionOnly
= rhs
.mPrintSelectionOnly
;
156 /** -------------------------------------------
158 nsresult
nsPrintSettingsGTK::_Clone(nsIPrintSettings
**_retval
)
160 NS_ENSURE_ARG_POINTER(_retval
);
163 nsPrintSettingsGTK
*newSettings
= new nsPrintSettingsGTK(*this);
165 return NS_ERROR_FAILURE
;
166 *_retval
= newSettings
;
172 /** -------------------------------------------
175 nsPrintSettingsGTK::_Assign(nsIPrintSettings
*aPS
)
177 nsPrintSettingsGTK
*printSettingsGTK
= static_cast<nsPrintSettingsGTK
*>(aPS
);
178 if (!printSettingsGTK
)
179 return NS_ERROR_UNEXPECTED
;
180 *this = *printSettingsGTK
;
184 /** ---------------------------------------------------
187 nsPrintSettingsGTK::SetGtkPageSetup(GtkPageSetup
*aPageSetup
)
190 g_object_unref(mPageSetup
);
192 mPageSetup
= (GtkPageSetup
*) g_object_ref(aPageSetup
);
193 InitUnwriteableMargin();
195 // We make a custom copy of the GtkPaperSize so it can be mutable. If a
196 // GtkPaperSize wasn't made as custom, its properties are immutable.
197 GtkPaperSize
* newPaperSize
= gtk_page_setup_get_paper_size(aPageSetup
);
198 if (newPaperSize
) { // Yes, this can be null
199 gtk_paper_size_free(mPaperSize
);
200 mPaperSize
= moz_gtk_paper_size_copy_to_new_custom(newPaperSize
);
202 // If newPaperSize was not null, we must update our twin too (GtkPrintSettings).
203 // If newPaperSize was null, we must set this object to use mPaperSize.
207 /** ---------------------------------------------------
210 nsPrintSettingsGTK::SetGtkPrintSettings(GtkPrintSettings
*aPrintSettings
)
213 g_object_unref(mPrintSettings
);
215 mPrintSettings
= (GtkPrintSettings
*) g_object_ref(aPrintSettings
);
217 GtkPaperSize
* newPaperSize
= gtk_print_settings_get_paper_size(aPrintSettings
);
219 gtk_paper_size_free(mPaperSize
);
220 mPaperSize
= moz_gtk_paper_size_copy_to_new_custom(newPaperSize
);
225 /** ---------------------------------------------------
228 nsPrintSettingsGTK::SetGtkPrinter(GtkPrinter
*aPrinter
)
231 g_object_unref(mGTKPrinter
);
233 mGTKPrinter
= (GtkPrinter
*) g_object_ref(aPrinter
);
237 * Reimplementation of nsPrintSettings functions so that we get the values
238 * from the GTK objects rather than our own variables.
241 /* attribute long printRange; */
242 NS_IMETHODIMP
nsPrintSettingsGTK::GetPrintRange(PRInt16
*aPrintRange
)
244 NS_ENSURE_ARG_POINTER(aPrintRange
);
245 if (mPrintSelectionOnly
) {
246 *aPrintRange
= kRangeSelection
;
250 GtkPrintPages gtkRange
= gtk_print_settings_get_print_pages(mPrintSettings
);
251 if (gtkRange
== GTK_PRINT_PAGES_RANGES
)
252 *aPrintRange
= kRangeSpecifiedPageRange
;
254 *aPrintRange
= kRangeAllPages
;
258 NS_IMETHODIMP
nsPrintSettingsGTK::SetPrintRange(PRInt16 aPrintRange
)
260 if (aPrintRange
== kRangeSelection
) {
261 mPrintSelectionOnly
= PR_TRUE
;
265 mPrintSelectionOnly
= PR_FALSE
;
266 if (aPrintRange
== kRangeSpecifiedPageRange
)
267 gtk_print_settings_set_print_pages(mPrintSettings
, GTK_PRINT_PAGES_RANGES
);
269 gtk_print_settings_set_print_pages(mPrintSettings
, GTK_PRINT_PAGES_ALL
);
273 /* attribute long startPageRange; */
275 nsPrintSettingsGTK::GetStartPageRange(PRInt32
*aStartPageRange
)
278 GtkPageRange
* lstRanges
= gtk_print_settings_get_page_ranges(mPrintSettings
, &ctRanges
);
280 // Make sure we got a range.
282 *aStartPageRange
= 1;
284 // GTK supports multiple page ranges; gecko only supports 1. So find
285 // the lowest start page.
286 PRInt32
start(lstRanges
[0].start
);
287 for (gint ii
= 1; ii
< ctRanges
; ii
++) {
288 start
= PR_MIN(lstRanges
[ii
].start
, start
);
290 *aStartPageRange
= start
+ 1;
297 nsPrintSettingsGTK::SetStartPageRange(PRInt32 aStartPageRange
)
300 GetEndPageRange(&endRange
);
302 GtkPageRange gtkRange
;
303 gtkRange
.start
= aStartPageRange
- 1;
304 gtkRange
.end
= endRange
- 1;
306 gtk_print_settings_set_page_ranges(mPrintSettings
, >kRange
, 1);
311 /* attribute long endPageRange; */
313 nsPrintSettingsGTK::GetEndPageRange(PRInt32
*aEndPageRange
)
316 GtkPageRange
* lstRanges
= gtk_print_settings_get_page_ranges(mPrintSettings
, &ctRanges
);
321 PRInt32
end(lstRanges
[0].end
);
322 for (gint ii
= 1; ii
< ctRanges
; ii
++) {
323 end
= PR_MAX(lstRanges
[ii
].end
, end
);
325 *aEndPageRange
= end
+ 1;
332 nsPrintSettingsGTK::SetEndPageRange(PRInt32 aEndPageRange
)
335 GetStartPageRange(&startRange
);
337 GtkPageRange gtkRange
;
338 gtkRange
.start
= startRange
- 1;
339 gtkRange
.end
= aEndPageRange
- 1;
341 gtk_print_settings_set_page_ranges(mPrintSettings
, >kRange
, 1);
346 /* attribute boolean printReversed; */
348 nsPrintSettingsGTK::GetPrintReversed(PRBool
*aPrintReversed
)
350 *aPrintReversed
= gtk_print_settings_get_reverse(mPrintSettings
);
354 nsPrintSettingsGTK::SetPrintReversed(PRBool aPrintReversed
)
356 gtk_print_settings_set_reverse(mPrintSettings
, aPrintReversed
);
360 /* attribute boolean printInColor; */
362 nsPrintSettingsGTK::GetPrintInColor(PRBool
*aPrintInColor
)
364 *aPrintInColor
= gtk_print_settings_get_use_color(mPrintSettings
);
368 nsPrintSettingsGTK::SetPrintInColor(PRBool aPrintInColor
)
370 gtk_print_settings_set_use_color(mPrintSettings
, aPrintInColor
);
374 /* attribute short orientation; */
376 nsPrintSettingsGTK::GetOrientation(PRInt32
*aOrientation
)
378 NS_ENSURE_ARG_POINTER(aOrientation
);
380 GtkPageOrientation gtkOrient
= gtk_page_setup_get_orientation(mPageSetup
);
382 case GTK_PAGE_ORIENTATION_LANDSCAPE
:
383 case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
:
384 *aOrientation
= kLandscapeOrientation
;
387 case GTK_PAGE_ORIENTATION_PORTRAIT
:
388 case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT
:
390 *aOrientation
= kPortraitOrientation
;
395 nsPrintSettingsGTK::SetOrientation(PRInt32 aOrientation
)
397 GtkPageOrientation gtkOrient
;
398 if (aOrientation
== kLandscapeOrientation
)
399 gtkOrient
= GTK_PAGE_ORIENTATION_LANDSCAPE
;
401 gtkOrient
= GTK_PAGE_ORIENTATION_PORTRAIT
;
403 gtk_print_settings_set_orientation(mPrintSettings
, gtkOrient
);
404 gtk_page_setup_set_orientation(mPageSetup
, gtkOrient
);
408 /* attribute wstring toFileName; */
410 nsPrintSettingsGTK::GetToFileName(PRUnichar
* *aToFileName
)
412 // Get the gtk output filename
413 const char* gtk_output_uri
= gtk_print_settings_get(mPrintSettings
, GTK_PRINT_SETTINGS_OUTPUT_URI
);
414 if (!gtk_output_uri
) {
415 *aToFileName
= ToNewUnicode(mToFileName
);
419 // Convert to an nsIFile
420 nsCOMPtr
<nsIFile
> file
;
421 nsresult rv
= NS_GetFileFromURLSpec(nsDependentCString(gtk_output_uri
),
422 getter_AddRefs(file
));
428 rv
= file
->GetPath(path
);
429 NS_ENSURE_SUCCESS(rv
, rv
);
431 *aToFileName
= ToNewUnicode(path
);
436 nsPrintSettingsGTK::SetToFileName(const PRUnichar
* aToFileName
)
438 if (aToFileName
[0] == 0) {
439 mToFileName
.SetLength(0);
440 gtk_print_settings_set(mPrintSettings
, GTK_PRINT_SETTINGS_OUTPUT_URI
, NULL
);
444 if (StringEndsWith(nsDependentString(aToFileName
), NS_LITERAL_STRING(".ps"))) {
445 gtk_print_settings_set(mPrintSettings
, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT
, "ps");
447 gtk_print_settings_set(mPrintSettings
, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT
, "pdf");
450 nsCOMPtr
<nsILocalFile
> file
;
451 nsresult rv
= NS_NewLocalFile(nsDependentString(aToFileName
), PR_TRUE
,
452 getter_AddRefs(file
));
453 NS_ENSURE_SUCCESS(rv
, rv
);
455 // Convert the nsIFile to a URL
457 rv
= NS_GetURLSpecFromFile(file
, url
);
458 NS_ENSURE_SUCCESS(rv
, rv
);
460 gtk_print_settings_set(mPrintSettings
, GTK_PRINT_SETTINGS_OUTPUT_URI
, url
.get());
461 mToFileName
= aToFileName
;
467 nsPrintSettingsGTK::GetPrinterName(PRUnichar
* *aPrinter
)
469 const char* gtkPrintName
= gtk_print_settings_get_printer(mPrintSettings
);
471 if (GTK_IS_PRINTER(mGTKPrinter
)) {
472 gtkPrintName
= gtk_printer_get_name(mGTKPrinter
);
474 // This mimics what nsPrintSettingsImpl does when we try to Get before we Set
475 nsXPIDLString nullPrintName
;
476 *aPrinter
= ToNewUnicode(nullPrintName
);
480 *aPrinter
= ToNewUnicode(nsDependentCString(gtkPrintName
));
485 nsPrintSettingsGTK::SetPrinterName(const PRUnichar
* aPrinter
)
487 NS_ConvertUTF16toUTF8
gtkPrinter(aPrinter
);
489 if (StringBeginsWith(gtkPrinter
, NS_LITERAL_CSTRING("CUPS/"))) {
490 // Strip off "CUPS/"; GTK might recognize the rest
491 gtkPrinter
.Cut(0, strlen("CUPS/"));
494 // Give mPrintSettings the passed-in printer name if either...
495 // - it has no printer name stored yet
496 // - it has an existing printer name that's different from
497 // the name passed to this function.
498 const char* oldPrinterName
= gtk_print_settings_get_printer(mPrintSettings
);
499 if (!oldPrinterName
|| !gtkPrinter
.Equals(oldPrinterName
)) {
500 mIsInitedFromPrinter
= PR_FALSE
;
501 mIsInitedFromPrefs
= PR_FALSE
;
502 gtk_print_settings_set_printer(mPrintSettings
, gtkPrinter
.get());
508 /* attribute long numCopies; */
510 nsPrintSettingsGTK::GetNumCopies(PRInt32
*aNumCopies
)
512 NS_ENSURE_ARG_POINTER(aNumCopies
);
513 *aNumCopies
= gtk_print_settings_get_n_copies(mPrintSettings
);
517 nsPrintSettingsGTK::SetNumCopies(PRInt32 aNumCopies
)
519 gtk_print_settings_set_n_copies(mPrintSettings
, aNumCopies
);
523 /* attribute double scaling; */
525 nsPrintSettingsGTK::GetScaling(double *aScaling
)
527 *aScaling
= gtk_print_settings_get_scale(mPrintSettings
) / 100.0;
532 nsPrintSettingsGTK::SetScaling(double aScaling
)
534 gtk_print_settings_set_scale(mPrintSettings
, aScaling
* 100.0);
538 /* attribute wstring paperName; */
540 nsPrintSettingsGTK::GetPaperName(PRUnichar
* *aPaperName
)
542 NS_ENSURE_ARG_POINTER(aPaperName
);
543 *aPaperName
= ToNewUnicode(NS_ConvertUTF8toUTF16(gtk_paper_size_get_name(mPaperSize
)));
547 nsPrintSettingsGTK::SetPaperName(const PRUnichar
* aPaperName
)
549 NS_ConvertUTF16toUTF8
gtkPaperName(aPaperName
);
551 // Convert these Gecko names to GTK names
552 if (gtkPaperName
.EqualsIgnoreCase("letter"))
553 gtkPaperName
.AssignLiteral(GTK_PAPER_NAME_LETTER
);
554 else if (gtkPaperName
.EqualsIgnoreCase("legal"))
555 gtkPaperName
.AssignLiteral(GTK_PAPER_NAME_LEGAL
);
557 // Try to get the display name from the name so our paper size fits in the Page Setup dialog.
558 GtkPaperSize
* paperSize
= gtk_paper_size_new(gtkPaperName
.get());
559 char* displayName
= strdup(gtk_paper_size_get_display_name(paperSize
));
560 gtk_paper_size_free(paperSize
);
562 paperSize
= gtk_paper_size_new_custom(gtkPaperName
.get(), displayName
,
563 gtk_paper_size_get_width(mPaperSize
, GTK_UNIT_INCH
),
564 gtk_paper_size_get_height(mPaperSize
, GTK_UNIT_INCH
),
568 gtk_paper_size_free(mPaperSize
);
569 mPaperSize
= paperSize
;
575 nsPrintSettingsGTK::GetGTKUnit(PRInt16 aGeckoUnit
)
577 if (aGeckoUnit
== kPaperSizeMillimeters
)
580 return GTK_UNIT_INCH
;
584 nsPrintSettingsGTK::SaveNewPageSize()
586 gtk_print_settings_set_paper_size(mPrintSettings
, mPaperSize
);
587 gtk_page_setup_set_paper_size(mPageSetup
, mPaperSize
);
591 nsPrintSettingsGTK::InitUnwriteableMargin()
593 mUnwriteableMargin
.SizeTo(
594 NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_left_margin(mPageSetup
, GTK_UNIT_INCH
)),
595 NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_top_margin(mPageSetup
, GTK_UNIT_INCH
)),
596 NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_right_margin(mPageSetup
, GTK_UNIT_INCH
)),
597 NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_bottom_margin(mPageSetup
, GTK_UNIT_INCH
))
602 * NOTE: Need a custom set of SetUnwriteableMargin functions, because
603 * whenever we change mUnwriteableMargin, we must pass the change
604 * down to our GTKPageSetup object. (This is needed in order for us
605 * to give the correct default values in nsPrintDialogGTK.)
607 * It's important that the following functions pass
608 * mUnwriteableMargin values rather than aUnwriteableMargin values
609 * to gtk_page_setup_set_[blank]_margin, because the two may not be
610 * the same. (Specifically, negative values of aUnwriteableMargin
611 * are ignored by the nsPrintSettings::SetUnwriteableMargin functions.)
614 nsPrintSettingsGTK::SetUnwriteableMarginInTwips(nsIntMargin
& aUnwriteableMargin
)
616 nsPrintSettings::SetUnwriteableMarginInTwips(aUnwriteableMargin
);
617 gtk_page_setup_set_top_margin(mPageSetup
,
618 NS_TWIPS_TO_INCHES(mUnwriteableMargin
.top
), GTK_UNIT_INCH
);
619 gtk_page_setup_set_left_margin(mPageSetup
,
620 NS_TWIPS_TO_INCHES(mUnwriteableMargin
.left
), GTK_UNIT_INCH
);
621 gtk_page_setup_set_bottom_margin(mPageSetup
,
622 NS_TWIPS_TO_INCHES(mUnwriteableMargin
.bottom
), GTK_UNIT_INCH
);
623 gtk_page_setup_set_right_margin(mPageSetup
,
624 NS_TWIPS_TO_INCHES(mUnwriteableMargin
.right
), GTK_UNIT_INCH
);
628 /* attribute double unwriteableMarginTop; */
630 nsPrintSettingsGTK::SetUnwriteableMarginTop(double aUnwriteableMarginTop
)
632 nsPrintSettings::SetUnwriteableMarginTop(aUnwriteableMarginTop
);
633 gtk_page_setup_set_top_margin(mPageSetup
,
634 NS_TWIPS_TO_INCHES(mUnwriteableMargin
.top
), GTK_UNIT_INCH
);
638 /* attribute double unwriteableMarginLeft; */
640 nsPrintSettingsGTK::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft
)
642 nsPrintSettings::SetUnwriteableMarginLeft(aUnwriteableMarginLeft
);
643 gtk_page_setup_set_left_margin(mPageSetup
,
644 NS_TWIPS_TO_INCHES(mUnwriteableMargin
.left
), GTK_UNIT_INCH
);
648 /* attribute double unwriteableMarginBottom; */
650 nsPrintSettingsGTK::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom
)
652 nsPrintSettings::SetUnwriteableMarginBottom(aUnwriteableMarginBottom
);
653 gtk_page_setup_set_bottom_margin(mPageSetup
,
654 NS_TWIPS_TO_INCHES(mUnwriteableMargin
.bottom
), GTK_UNIT_INCH
);
658 /* attribute double unwriteableMarginRight; */
660 nsPrintSettingsGTK::SetUnwriteableMarginRight(double aUnwriteableMarginRight
)
662 nsPrintSettings::SetUnwriteableMarginRight(aUnwriteableMarginRight
);
663 gtk_page_setup_set_right_margin(mPageSetup
,
664 NS_TWIPS_TO_INCHES(mUnwriteableMargin
.right
), GTK_UNIT_INCH
);
668 /* attribute double paperWidth; */
670 nsPrintSettingsGTK::GetPaperWidth(double *aPaperWidth
)
672 NS_ENSURE_ARG_POINTER(aPaperWidth
);
673 *aPaperWidth
= gtk_paper_size_get_width(mPaperSize
, GetGTKUnit(mPaperSizeUnit
));
677 nsPrintSettingsGTK::SetPaperWidth(double aPaperWidth
)
679 gtk_paper_size_set_size(mPaperSize
,
681 gtk_paper_size_get_height(mPaperSize
, GetGTKUnit(mPaperSizeUnit
)),
682 GetGTKUnit(mPaperSizeUnit
));
687 /* attribute double paperHeight; */
689 nsPrintSettingsGTK::GetPaperHeight(double *aPaperHeight
)
691 NS_ENSURE_ARG_POINTER(aPaperHeight
);
692 *aPaperHeight
= gtk_paper_size_get_height(mPaperSize
, GetGTKUnit(mPaperSizeUnit
));
696 nsPrintSettingsGTK::SetPaperHeight(double aPaperHeight
)
698 gtk_paper_size_set_size(mPaperSize
,
699 gtk_paper_size_get_width(mPaperSize
, GetGTKUnit(mPaperSizeUnit
)),
701 GetGTKUnit(mPaperSizeUnit
));
707 nsPrintSettingsGTK::SetPaperSizeUnit(PRInt16 aPaperSizeUnit
)
709 // Convert units internally. e.g. they might have set the values while we're still in mm but
710 // they change to inch just afterwards, expecting that their sizes are in inches.
711 gtk_paper_size_set_size(mPaperSize
,
712 gtk_paper_size_get_width(mPaperSize
, GetGTKUnit(mPaperSizeUnit
)),
713 gtk_paper_size_get_height(mPaperSize
, GetGTKUnit(mPaperSizeUnit
)),
714 GetGTKUnit(aPaperSizeUnit
));
717 mPaperSizeUnit
= aPaperSizeUnit
;
722 nsPrintSettingsGTK::GetEffectivePageSize(double *aWidth
, double *aHeight
)
724 *aWidth
= NS_INCHES_TO_INT_TWIPS(gtk_paper_size_get_width(mPaperSize
, GTK_UNIT_INCH
));
725 *aHeight
= NS_INCHES_TO_INT_TWIPS(gtk_paper_size_get_height(mPaperSize
, GTK_UNIT_INCH
));
727 GtkPageOrientation gtkOrient
= gtk_page_setup_get_orientation(mPageSetup
);
729 if (gtkOrient
== GTK_PAGE_ORIENTATION_LANDSCAPE
||
730 gtkOrient
== GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE
) {
731 double temp
= *aWidth
;
739 nsPrintSettingsGTK::SetupSilentPrinting()
741 // We have to get a printer here, rather than when the print settings are constructed.
742 // This is because when we request sync, GTK makes us wait in the *event loop* while waiting
743 // for the enumeration to finish. We must do this when event loop runs are expected.
744 gtk_enumerate_printers(printer_enumerator
, this, NULL
, TRUE
);
746 // XXX If no default printer set, get the first one.
747 if (!GTK_IS_PRINTER(mGTKPrinter
))
748 gtk_enumerate_printers(ref_printer
, this, NULL
, TRUE
);