LibreOffice Module sfx2 (master) 1
printer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <tools/debug.hxx>
21
22#include <utility>
23
24#include <sfx2/printer.hxx>
25#include <sfx2/viewsh.hxx>
26#include <sfx2/tabdlg.hxx>
27#include "prnmon.hxx"
28
29// class SfxPrinter ------------------------------------------------------
30
31VclPtr<SfxPrinter> SfxPrinter::Create( SvStream& rStream, std::unique_ptr<SfxItemSet>&& pOptions )
32
33/* [Description]
34
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.
39
40 The 'pOptions' are taken over in the generated SfxPrinter, the return
41 value belongs to the caller.
42*/
43
44{
45 // Load JobSetup
46 JobSetup aFileJobSetup;
47 ReadJobSetup( rStream, aFileJobSetup );
48
49 // Get printers
50 VclPtr<SfxPrinter> pPrinter = VclPtr<SfxPrinter>::Create( std::move(pOptions), aFileJobSetup );
51 return pPrinter;
52}
53
54
55void SfxPrinter::Store( SvStream& rStream ) const
56
57/* [Description]
58
59 Saves the used JobSetup of <SfxPrinter>s.
60*/
61
62{
63 WriteJobSetup( rStream, GetJobSetup() );
64}
65
66
67SfxPrinter::SfxPrinter( std::unique_ptr<SfxItemSet>&& pTheOptions ) :
68
69/* [Description]
70
71 This constructor creates a default printer.
72*/
73 pOptions( std::move(pTheOptions) ),
74 bKnown( true )
75{
76 assert(pOptions);
77}
78
79
80SfxPrinter::SfxPrinter( std::unique_ptr<SfxItemSet>&& pTheOptions,
81 const JobSetup& rTheOrigJobSetup ) :
82 Printer( rTheOrigJobSetup.GetPrinterName() ),
83 pOptions( std::move(pTheOptions) )
84{
85 assert(pOptions);
86 bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
87
88 if ( bKnown )
89 SetJobSetup( rTheOrigJobSetup );
90}
91
92
93SfxPrinter::SfxPrinter( std::unique_ptr<SfxItemSet>&& pTheOptions,
94 const OUString& rPrinterName ) :
95 Printer( rPrinterName ),
96 pOptions( std::move(pTheOptions) ),
97 bKnown( GetName() == rPrinterName )
98{
99 assert(pOptions);
100}
101
102
105 Printer( rPrinter.GetName() ),
106 pOptions( rPrinter.GetOptions().Clone() ),
107 bKnown( rPrinter.IsKnown() )
108{
109 assert(pOptions);
110 SetJobSetup( rPrinter.GetJobSetup() );
111 SetPrinterProps( &rPrinter );
112 SetMapMode( rPrinter.GetMapMode() );
113}
114
115
117{
118 if ( IsDefPrinter() )
119 {
121 pNewPrinter->SetJobSetup( GetJobSetup() );
122 pNewPrinter->SetPrinterProps( this );
123 pNewPrinter->SetMapMode( GetMapMode() );
124 return pNewPrinter;
125 }
126 else
127 return VclPtr<SfxPrinter>::Create( *this );
128}
129
130
132{
133 disposeOnce();
134}
135
137{
138 pOptions.reset();
140}
141
142
143void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
144{
145 pOptions->Set(rNewOptions);
146}
147
148
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
157{
158 DBG_ASSERT( m_xPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
159 if (m_xPage)
160 {
161 m_xPage->Reset( pOptions.get() );
162 m_xDialog->set_help_id(m_xPage->GetHelpId());
163 }
164}
165
167{
168}
169
171{
172 if (!m_xPage)
173 return RET_CANCEL;
174
175 short nRet = GenericDialogController::run();
176
177 if (nRet == RET_OK)
178 m_xPage->FillItemSet( pOptions.get() );
179 else
180 m_xPage->Reset( pOptions.get() );
181 return nRet;
182}
183
185{
186 m_xHelpBtn->set_sensitive(false);
187}
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
OUString const & GetPrinterName() const
void SetMapMode()
const MapMode & GetMapMode() const
bool SetPrinterProps(const Printer *pPrinter)
bool IsDefPrinter() const
bool SetJobSetup(const JobSetup &rSetup)
const OUString & GetName() const
const JobSetup & GetJobSetup() const
virtual void dispose() override
std::unique_ptr< SfxItemSet > pOptions
Definition: prnmon.hxx:35
std::unique_ptr< SfxTabPage > m_xPage
Definition: prnmon.hxx:38
std::unique_ptr< weld::Widget > m_xHelpBtn
Definition: prnmon.hxx:36
virtual ~SfxPrintOptionsDialog() override
Definition: printer.cxx:166
virtual short run() override
Definition: printer.cxx:170
SfxPrintOptionsDialog(weld::Window *pParent, SfxViewShell *pViewShell, const SfxItemSet *rOptions)
Definition: printer.cxx:149
SfxPrinter(std::unique_ptr< SfxItemSet > &&pTheOptions)
Definition: printer.cxx:67
virtual void dispose() override
Definition: printer.cxx:136
std::unique_ptr< SfxItemSet > pOptions
Definition: printer.hxx:34
void Store(SvStream &rStream) const
Definition: printer.cxx:55
VclPtr< SfxPrinter > Clone() const
Definition: printer.cxx:116
bool bKnown
Definition: printer.hxx:35
static VclPtr< SfxPrinter > Create(SvStream &rStream, std::unique_ptr< SfxItemSet > &&pOptions)
Definition: printer.cxx:31
virtual ~SfxPrinter() override
Definition: printer.cxx:131
void SetOptions(const SfxItemSet &rNewOptions)
Definition: printer.cxx:143
const SfxItemSet & GetOptions() const
Definition: printer.hxx:54
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
Definition: viewsh.hxx:165
static VclPtr< reference_type > Create(Arg &&... arg)
std::shared_ptr< weld::Dialog > m_xDialog
#define DBG_ASSERT(sCon, aError)
virtual OUString GetName() const override
SvStream & ReadJobSetup(SvStream &rIStream, JobSetup &rJobSetup)
SvStream & WriteJobSetup(SvStream &rOStream, const JobSetup &rJobSetup)
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Reference< XNameAccess > m_xContainer
RET_OK
RET_CANCEL
std::unique_ptr< SfxTabPage > CreatePrintOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rOptions, bool bPreview)