bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / view / printer.cxx
blobee07c7850f21cd6076dd6192a9ebdf0ae92619ab
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 <vcl/virdev.hxx>
21 #include <vcl/metric.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <unotools/printwarningoptions.hxx>
24 #include <svtools/printoptions.hxx>
25 #include <vector>
27 #include <sfx2/printer.hxx>
28 #include <sfx2/printopt.hxx>
29 #include "sfxtypes.hxx"
30 #include <sfx2/prnmon.hxx>
31 #include <sfx2/viewsh.hxx>
32 #include <sfx2/tabdlg.hxx>
33 #include <sfx2/sfxresid.hxx>
34 #include "view.hrc"
36 // struct SfxPrinter_Impl ------------------------------------------------
38 struct SfxPrinter_Impl
40 bool mbAll;
41 bool mbSelection;
42 bool mbFromTo;
43 bool mbRange;
45 SfxPrinter_Impl() :
46 mbAll ( true ),
47 mbSelection ( true ),
48 mbFromTo ( true ),
49 mbRange ( true ) {}
50 ~SfxPrinter_Impl() {}
53 struct SfxPrintOptDlg_Impl
55 bool mbHelpDisabled;
57 SfxPrintOptDlg_Impl() :
58 mbHelpDisabled ( false ) {}
61 // class SfxPrinter ------------------------------------------------------
63 VclPtr<SfxPrinter> SfxPrinter::Create( SvStream& rStream, SfxItemSet* pOptions )
65 /* [Description]
67 Creates a <SfxPrinter> from the stream. Loading is really only a jobsetup.
68 If such a printer is not available on the system, then the original is
69 marked as the original Job-setup and a comparable printer is selected from
70 existing ones.
72 The 'pOptions' are taken over in the generated SfxPrinter, the return
73 value belongs to the caller.
77 // Load JobSetup
78 JobSetup aFileJobSetup;
79 ReadJobSetup( rStream, aFileJobSetup );
81 // Get printers
82 VclPtr<SfxPrinter> pPrinter = VclPtr<SfxPrinter>::Create( pOptions, aFileJobSetup );
83 return pPrinter;
88 SvStream& SfxPrinter::Store( SvStream& rStream ) const
90 /* [Description]
92 Saves the used JobSetup of <SfxPrinter>s.
96 return WriteJobSetup( rStream, GetJobSetup() );
101 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
103 /* [Description]
105 This constructor creates a default printer.
108 pOptions( pTheOptions ),
109 bKnown(true)
112 assert(pOptions);
113 pImpl = new SfxPrinter_Impl;
118 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
119 const JobSetup& rTheOrigJobSetup ) :
121 Printer ( rTheOrigJobSetup.GetPrinterName() ),
122 pOptions ( pTheOptions )
125 assert(pOptions);
126 pImpl = new SfxPrinter_Impl;
127 bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
129 if ( bKnown )
130 SetJobSetup( rTheOrigJobSetup );
135 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
136 const OUString& rPrinterName ) :
138 Printer ( rPrinterName ),
139 pOptions ( pTheOptions ),
140 bKnown ( GetName() == rPrinterName )
143 assert(pOptions);
144 pImpl = new SfxPrinter_Impl;
149 SfxPrinter::SfxPrinter( const SfxPrinter& rPrinter ) :
151 Printer ( rPrinter.GetName() ),
152 pOptions( rPrinter.GetOptions().Clone() ),
153 bKnown ( rPrinter.IsKnown() )
155 assert(pOptions);
156 SetJobSetup( rPrinter.GetJobSetup() );
157 SetPrinterProps( &rPrinter );
158 SetMapMode( rPrinter.GetMapMode() );
160 pImpl = new SfxPrinter_Impl;
161 pImpl->mbAll = rPrinter.pImpl->mbAll;
162 pImpl->mbSelection = rPrinter.pImpl->mbSelection;
163 pImpl->mbFromTo = rPrinter.pImpl->mbFromTo;
164 pImpl->mbRange = rPrinter.pImpl->mbRange;
169 VclPtr<SfxPrinter> SfxPrinter::Clone() const
171 if ( IsDefPrinter() )
173 VclPtr<SfxPrinter> pNewPrinter = VclPtr<SfxPrinter>::Create( GetOptions().Clone() );
174 pNewPrinter->SetJobSetup( GetJobSetup() );
175 pNewPrinter->SetPrinterProps( this );
176 pNewPrinter->SetMapMode( GetMapMode() );
177 pNewPrinter->pImpl->mbAll = pImpl->mbAll;
178 pNewPrinter->pImpl->mbSelection =pImpl->mbSelection;
179 pNewPrinter->pImpl->mbFromTo = pImpl->mbFromTo;
180 pNewPrinter->pImpl->mbRange =pImpl->mbRange;
181 return pNewPrinter;
183 else
184 return VclPtr<SfxPrinter>::Create( *this );
189 SfxPrinter::~SfxPrinter()
191 disposeOnce();
194 void SfxPrinter::dispose()
196 delete pOptions;
197 delete pImpl;
198 Printer::dispose();
203 void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
205 pOptions->Set(rNewOptions);
210 SfxPrintOptionsDialog::SfxPrintOptionsDialog(vcl::Window *pParent,
211 SfxViewShell *pViewShell,
212 const SfxItemSet *pSet)
214 : ModalDialog(pParent, "PrinterOptionsDialog",
215 "sfx/ui/printeroptionsdialog.ui")
216 , pDlgImpl(new SfxPrintOptDlg_Impl)
217 , pViewSh(pViewShell)
218 , pOptions(pSet->Clone())
220 VclContainer *pVBox = get_content_area();
222 // Insert TabPage
223 pPage.reset(pViewSh->CreatePrintOptionsPage(pVBox, *pOptions));
224 DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
225 if( pPage )
227 pPage->Reset( pOptions );
228 SetHelpId( pPage->GetHelpId() );
229 pPage->Show();
235 SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
237 disposeOnce();
240 void SfxPrintOptionsDialog::dispose()
242 delete pDlgImpl;
243 pPage.disposeAndClear();
244 delete pOptions;
245 ModalDialog::dispose();
250 short SfxPrintOptionsDialog::Execute()
252 if( ! pPage )
253 return RET_CANCEL;
255 short nRet = ModalDialog::Execute();
256 if ( nRet == RET_OK )
257 pPage->FillItemSet( pOptions );
258 else
259 pPage->Reset( pOptions );
260 return nRet;
265 bool SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
267 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
269 if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
270 return true; // help disabled -> <F1> does nothing
273 return ModalDialog::Notify( rNEvt );
278 void SfxPrintOptionsDialog::DisableHelp()
280 pDlgImpl->mbHelpDisabled = true;
282 get<HelpButton>("help")->Disable();
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */