1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsPrintSettingsServiceX.h"
8 #include "mozilla/embedding/PPrintingTypes.h"
10 #include "nsQueryObject.h"
11 #include "nsPrintSettingsX.h"
12 #include "nsCocoaUtils.h"
14 using namespace mozilla::embedding;
17 nsPrintSettingsServiceX::SerializeToPrintData(nsIPrintSettings* aSettings,
19 nsresult rv = nsPrintSettingsService::SerializeToPrintData(aSettings, data);
20 if (NS_WARN_IF(NS_FAILED(rv))) {
24 RefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aSettings));
25 if (NS_WARN_IF(!settingsX)) {
26 return NS_ERROR_FAILURE;
29 settingsX->GetDisposition(data->disposition());
30 settingsX->GetDestination(&data->destination());
36 nsPrintSettingsServiceX::DeserializeToPrintSettings(
37 const PrintData& data, nsIPrintSettings* settings) {
39 nsPrintSettingsService::DeserializeToPrintSettings(data, settings);
40 if (NS_WARN_IF(NS_FAILED(rv))) {
44 RefPtr<nsPrintSettingsX> settingsX(do_QueryObject(settings));
45 if (NS_WARN_IF(!settingsX)) {
46 return NS_ERROR_FAILURE;
49 settingsX->SetDisposition(data.disposition());
50 settingsX->SetDestination(data.destination());
55 nsresult nsPrintSettingsServiceX::_CreatePrintSettings(
56 nsIPrintSettings** _retval) {
60 nsPrintSettingsX* printSettings =
61 new nsPrintSettingsX; // does not initially ref count
62 NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
63 NS_ADDREF(*_retval = printSettings);
65 rv = printSettings->Init();
71 auto globalPrintSettings = nsIPrintSettings::kGlobalSettings;
73 // XXX Why is Mac special? Why are we copying global print settings here?
74 // nsPrintSettingsService::InitPrintSettingsFromPrefs already gets the few
75 // global defaults that we want, doesn't it?
76 InitPrintSettingsFromPrefs(*_retval, false, globalPrintSettings);