1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <sfx2/printer.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <sfx2/tabdlg.hxx>
29 // class SfxPrinter ------------------------------------------------------
31 VclPtr
<SfxPrinter
> SfxPrinter::Create( SvStream
& rStream
, std::unique_ptr
<SfxItemSet
>&& pOptions
)
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
40 The 'pOptions' are taken over in the generated SfxPrinter, the return
41 value belongs to the caller.
46 JobSetup aFileJobSetup
;
47 ReadJobSetup( rStream
, aFileJobSetup
);
50 VclPtr
<SfxPrinter
> pPrinter
= VclPtr
<SfxPrinter
>::Create( std::move(pOptions
), aFileJobSetup
);
55 void SfxPrinter::Store( SvStream
& rStream
) const
59 Saves the used JobSetup of <SfxPrinter>s.
63 WriteJobSetup( rStream
, GetJobSetup() );
67 SfxPrinter::SfxPrinter( std::unique_ptr
<SfxItemSet
>&& pTheOptions
) :
71 This constructor creates a default printer.
73 pOptions( std::move(pTheOptions
) ),
80 SfxPrinter::SfxPrinter( std::unique_ptr
<SfxItemSet
>&& pTheOptions
,
81 const JobSetup
& rTheOrigJobSetup
) :
82 Printer( rTheOrigJobSetup
.GetPrinterName() ),
83 pOptions( std::move(pTheOptions
) )
86 bKnown
= GetName() == rTheOrigJobSetup
.GetPrinterName();
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
)
103 SfxPrinter::SfxPrinter( const SfxPrinter
& rPrinter
) :
105 Printer( rPrinter
.GetName() ),
106 pOptions( rPrinter
.GetOptions().Clone() ),
107 bKnown( rPrinter
.IsKnown() )
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() );
127 return VclPtr
<SfxPrinter
>::Create( *this );
131 SfxPrinter::~SfxPrinter()
136 void SfxPrinter::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" );
161 m_xPage
->Reset( pOptions
.get() );
162 m_xDialog
->set_help_id(m_xPage
->GetHelpId());
166 SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
170 short SfxPrintOptionsDialog::run()
175 short nRet
= GenericDialogController::run();
178 m_xPage
->FillItemSet( pOptions
.get() );
180 m_xPage
->Reset( pOptions
.get() );
184 void SfxPrintOptionsDialog::DisableHelp()
186 m_xHelpBtn
->set_sensitive(false);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */