LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / view / printer.cxx
blob7b774534951a0e65bd34b5ab40db079be24e29c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
22 #include <utility>
24 #include <sfx2/printer.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <sfx2/tabdlg.hxx>
27 #include "prnmon.hxx"
29 // class SfxPrinter ------------------------------------------------------
31 VclPtr<SfxPrinter> SfxPrinter::Create( SvStream& rStream, std::unique_ptr<SfxItemSet>&& pOptions )
33 /* [Description]
35 Creates a <SfxPrinter> from the stream. Loading is really only a jobsetup.
36 If such a printer is not available on the system, then the original is
37 marked as the original Job-setup and a comparable printer is selected from
38 existing ones.
40 The 'pOptions' are taken over in the generated SfxPrinter, the return
41 value belongs to the caller.
45 // Load JobSetup
46 JobSetup aFileJobSetup;
47 ReadJobSetup( rStream, aFileJobSetup );
49 // Get printers
50 VclPtr<SfxPrinter> pPrinter = VclPtr<SfxPrinter>::Create( std::move(pOptions), aFileJobSetup );
51 return pPrinter;
55 void SfxPrinter::Store( SvStream& rStream ) const
57 /* [Description]
59 Saves the used JobSetup of <SfxPrinter>s.
63 WriteJobSetup( rStream, GetJobSetup() );
67 SfxPrinter::SfxPrinter( std::unique_ptr<SfxItemSet>&& pTheOptions ) :
69 /* [Description]
71 This constructor creates a default printer.
73 pOptions( std::move(pTheOptions) ),
74 bKnown( true )
76 assert(pOptions);
80 SfxPrinter::SfxPrinter( std::unique_ptr<SfxItemSet>&& pTheOptions,
81 const JobSetup& rTheOrigJobSetup ) :
82 Printer( rTheOrigJobSetup.GetPrinterName() ),
83 pOptions( std::move(pTheOptions) )
85 assert(pOptions);
86 bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
88 if ( bKnown )
89 SetJobSetup( rTheOrigJobSetup );
93 SfxPrinter::SfxPrinter( std::unique_ptr<SfxItemSet>&& pTheOptions,
94 const OUString& rPrinterName ) :
95 Printer( rPrinterName ),
96 pOptions( std::move(pTheOptions) ),
97 bKnown( GetName() == rPrinterName )
99 assert(pOptions);
103 SfxPrinter::SfxPrinter( const SfxPrinter& rPrinter ) :
104 VclReferenceBase(),
105 Printer( rPrinter.GetName() ),
106 pOptions( rPrinter.GetOptions().Clone() ),
107 bKnown( rPrinter.IsKnown() )
109 assert(pOptions);
110 SetJobSetup( rPrinter.GetJobSetup() );
111 SetPrinterProps( &rPrinter );
112 SetMapMode( rPrinter.GetMapMode() );
116 VclPtr<SfxPrinter> SfxPrinter::Clone() const
118 if ( IsDefPrinter() )
120 VclPtr<SfxPrinter> pNewPrinter = VclPtr<SfxPrinter>::Create( GetOptions().Clone() );
121 pNewPrinter->SetJobSetup( GetJobSetup() );
122 pNewPrinter->SetPrinterProps( this );
123 pNewPrinter->SetMapMode( GetMapMode() );
124 return pNewPrinter;
126 else
127 return VclPtr<SfxPrinter>::Create( *this );
131 SfxPrinter::~SfxPrinter()
133 disposeOnce();
136 void SfxPrinter::dispose()
138 pOptions.reset();
139 Printer::dispose();
143 void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
145 pOptions->Set(rNewOptions);
149 SfxPrintOptionsDialog::SfxPrintOptionsDialog(weld::Window *pParent,
150 SfxViewShell *pViewShell,
151 const SfxItemSet *pSet)
152 : GenericDialogController(pParent, "sfx/ui/printeroptionsdialog.ui", "PrinterOptionsDialog")
153 , pOptions(pSet->Clone())
154 , m_xHelpBtn(m_xBuilder->weld_widget("help"))
155 , m_xContainer(m_xDialog->weld_content_area())
156 , m_xPage(pViewShell->CreatePrintOptionsPage(m_xContainer.get(), this, *pOptions)) // Insert TabPage
158 DBG_ASSERT( m_xPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
159 if (m_xPage)
161 m_xPage->Reset( pOptions.get() );
162 m_xDialog->set_help_id(m_xPage->GetHelpId());
166 SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
170 short SfxPrintOptionsDialog::run()
172 if (!m_xPage)
173 return RET_CANCEL;
175 short nRet = GenericDialogController::run();
177 if (nRet == RET_OK)
178 m_xPage->FillItemSet( pOptions.get() );
179 else
180 m_xPage->Reset( pOptions.get() );
181 return nRet;
184 void SfxPrintOptionsDialog::DisableHelp()
186 m_xHelpBtn->set_sensitive(false);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */