build fix
[LibreOffice.git] / sfx2 / source / view / printer.cxx
blob45f98ad99757277ec27c816e5b143c8f0a08ca12
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;
87 void SfxPrinter::Store( SvStream& rStream ) const
89 /* [Description]
91 Saves the used JobSetup of <SfxPrinter>s.
95 WriteJobSetup( rStream, GetJobSetup() );
99 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
101 /* [Description]
103 This constructor creates a default printer.
105 pOptions( pTheOptions ),
106 pImpl( new SfxPrinter_Impl ),
107 bKnown( true )
109 assert(pOptions);
113 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
114 const JobSetup& rTheOrigJobSetup ) :
115 Printer( rTheOrigJobSetup.GetPrinterName() ),
116 pOptions( pTheOptions ),
117 pImpl( new SfxPrinter_Impl )
119 assert(pOptions);
120 bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
122 if ( bKnown )
123 SetJobSetup( rTheOrigJobSetup );
127 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
128 const OUString& rPrinterName ) :
129 Printer( rPrinterName ),
130 pOptions( pTheOptions ),
131 pImpl( new SfxPrinter_Impl ),
132 bKnown( GetName() == rPrinterName )
134 assert(pOptions);
138 SfxPrinter::SfxPrinter( const SfxPrinter& rPrinter ) :
139 VclReferenceBase(),
140 Printer( rPrinter.GetName() ),
141 pOptions( rPrinter.GetOptions().Clone() ),
142 pImpl( new SfxPrinter_Impl ),
143 bKnown( rPrinter.IsKnown() )
145 assert(pOptions);
146 SetJobSetup( rPrinter.GetJobSetup() );
147 SetPrinterProps( &rPrinter );
148 SetMapMode( rPrinter.GetMapMode() );
150 pImpl->mbAll = rPrinter.pImpl->mbAll;
151 pImpl->mbSelection = rPrinter.pImpl->mbSelection;
152 pImpl->mbFromTo = rPrinter.pImpl->mbFromTo;
153 pImpl->mbRange = rPrinter.pImpl->mbRange;
157 VclPtr<SfxPrinter> SfxPrinter::Clone() const
159 if ( IsDefPrinter() )
161 VclPtr<SfxPrinter> pNewPrinter = VclPtr<SfxPrinter>::Create( GetOptions().Clone() );
162 pNewPrinter->SetJobSetup( GetJobSetup() );
163 pNewPrinter->SetPrinterProps( this );
164 pNewPrinter->SetMapMode( GetMapMode() );
165 pNewPrinter->pImpl->mbAll = pImpl->mbAll;
166 pNewPrinter->pImpl->mbSelection =pImpl->mbSelection;
167 pNewPrinter->pImpl->mbFromTo = pImpl->mbFromTo;
168 pNewPrinter->pImpl->mbRange =pImpl->mbRange;
169 return pNewPrinter;
171 else
172 return VclPtr<SfxPrinter>::Create( *this );
176 SfxPrinter::~SfxPrinter()
178 disposeOnce();
181 void SfxPrinter::dispose()
183 delete pOptions;
184 pImpl.reset();
185 Printer::dispose();
189 void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
191 pOptions->Set(rNewOptions);
195 SfxPrintOptionsDialog::SfxPrintOptionsDialog(vcl::Window *pParent,
196 SfxViewShell *pViewShell,
197 const SfxItemSet *pSet)
199 : ModalDialog(pParent, "PrinterOptionsDialog",
200 "sfx/ui/printeroptionsdialog.ui")
201 , pDlgImpl(new SfxPrintOptDlg_Impl)
202 , pViewSh(pViewShell)
203 , pOptions(pSet->Clone())
205 VclContainer *pVBox = get_content_area();
207 // Insert TabPage
208 pPage.reset(pViewSh->CreatePrintOptionsPage(pVBox, *pOptions));
209 DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
210 if( pPage )
212 pPage->Reset( pOptions );
213 SetHelpId( pPage->GetHelpId() );
214 pPage->Show();
219 SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
221 disposeOnce();
224 void SfxPrintOptionsDialog::dispose()
226 pDlgImpl.reset();
227 pPage.disposeAndClear();
228 delete pOptions;
229 ModalDialog::dispose();
233 short SfxPrintOptionsDialog::Execute()
235 if( ! pPage )
236 return RET_CANCEL;
238 short nRet = ModalDialog::Execute();
239 if ( nRet == RET_OK )
240 pPage->FillItemSet( pOptions );
241 else
242 pPage->Reset( pOptions );
243 return nRet;
247 bool SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
249 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
251 if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
252 return true; // help disabled -> <F1> does nothing
255 return ModalDialog::Notify( rNEvt );
259 void SfxPrintOptionsDialog::DisableHelp()
261 pDlgImpl->mbHelpDisabled = true;
263 get<HelpButton>("help")->Disable();
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */