Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / view / printer.cxx
blob7439760e11787604763ffe7f37636735b76fe306
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 sal_Bool mbAll;
41 sal_Bool mbSelection;
42 sal_Bool mbFromTo;
43 sal_Bool mbRange;
45 SfxPrinter_Impl() :
46 mbAll ( sal_True ),
47 mbSelection ( sal_True ),
48 mbFromTo ( sal_True ),
49 mbRange ( sal_True ) {}
50 ~SfxPrinter_Impl() {}
53 struct SfxPrintOptDlg_Impl
55 sal_Bool mbHelpDisabled;
57 SfxPrintOptDlg_Impl() :
58 mbHelpDisabled ( sal_False ) {}
61 // class SfxPrinter ------------------------------------------------------
63 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 rStream >> aFileJobSetup;
81 // Get printers
82 SfxPrinter *pPrinter = new SfxPrinter( pOptions, aFileJobSetup );
83 return pPrinter;
86 //--------------------------------------------------------------------
88 SvStream& SfxPrinter::Store( SvStream& rStream ) const
90 /* [Description]
92 Saves the used JobSetup of <SfxPrinter>s.
96 return ( rStream << GetJobSetup() );
99 //--------------------------------------------------------------------
101 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
103 /* [Description]
105 This constructor creates a default printer.
108 pOptions( pTheOptions ),
109 bKnown(sal_True)
112 pImpl = new SfxPrinter_Impl;
115 //--------------------------------------------------------------------
117 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
118 const JobSetup& rTheOrigJobSetup ) :
120 Printer ( rTheOrigJobSetup.GetPrinterName() ),
121 pOptions ( pTheOptions )
124 pImpl = new SfxPrinter_Impl;
125 bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
127 if ( bKnown )
128 SetJobSetup( rTheOrigJobSetup );
131 //--------------------------------------------------------------------
133 SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
134 const String& rPrinterName ) :
136 Printer ( rPrinterName ),
137 pOptions ( pTheOptions ),
138 bKnown ( String( GetName() ) == rPrinterName )
141 pImpl = new SfxPrinter_Impl;
144 //--------------------------------------------------------------------
146 SfxPrinter::SfxPrinter( const SfxPrinter& rPrinter ) :
148 Printer ( rPrinter.GetName() ),
149 pOptions( rPrinter.GetOptions().Clone() ),
150 bKnown ( rPrinter.IsKnown() )
152 SetJobSetup( rPrinter.GetJobSetup() );
153 SetPrinterProps( &rPrinter );
154 SetMapMode( rPrinter.GetMapMode() );
156 pImpl = new SfxPrinter_Impl;
157 pImpl->mbAll = rPrinter.pImpl->mbAll;
158 pImpl->mbSelection = rPrinter.pImpl->mbSelection;
159 pImpl->mbFromTo = rPrinter.pImpl->mbFromTo;
160 pImpl->mbRange = rPrinter.pImpl->mbRange;
163 //--------------------------------------------------------------------
165 SfxPrinter* SfxPrinter::Clone() const
167 if ( IsDefPrinter() )
169 SfxPrinter *pNewPrinter;
170 pNewPrinter = new SfxPrinter( GetOptions().Clone() );
171 pNewPrinter->SetJobSetup( GetJobSetup() );
172 pNewPrinter->SetPrinterProps( this );
173 pNewPrinter->SetMapMode( GetMapMode() );
174 pNewPrinter->pImpl->mbAll = pImpl->mbAll;
175 pNewPrinter->pImpl->mbSelection =pImpl->mbSelection;
176 pNewPrinter->pImpl->mbFromTo = pImpl->mbFromTo;
177 pNewPrinter->pImpl->mbRange =pImpl->mbRange;
178 return pNewPrinter;
180 else
181 return new SfxPrinter( *this );
184 //--------------------------------------------------------------------
186 SfxPrinter::~SfxPrinter()
188 delete pOptions;
189 delete pImpl;
192 //--------------------------------------------------------------------
194 void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
196 pOptions->Set(rNewOptions);
199 //--------------------------------------------------------------------
201 SfxPrintOptionsDialog::SfxPrintOptionsDialog(Window *pParent,
202 SfxViewShell *pViewShell,
203 const SfxItemSet *pSet)
205 : ModalDialog(pParent, "PrinterOptionsDialog",
206 "sfx/ui/printeroptionsdialog.ui")
207 , pDlgImpl(new SfxPrintOptDlg_Impl)
208 , pViewSh(pViewShell)
209 , pOptions(pSet->Clone())
211 VclContainer *pVBox = get_content_area();
213 // Insert TabPage
214 pPage = pViewSh->CreatePrintOptionsPage(pVBox, *pOptions);
215 DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
216 if( pPage )
218 pPage->Reset( *pOptions );
219 SetHelpId( pPage->GetHelpId() );
220 pPage->Show();
224 //--------------------------------------------------------------------
226 SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
228 delete pDlgImpl;
229 delete pPage;
230 delete pOptions;
233 //--------------------------------------------------------------------
235 short SfxPrintOptionsDialog::Execute()
237 if( ! pPage )
238 return RET_CANCEL;
240 short nRet = ModalDialog::Execute();
241 if ( nRet == RET_OK )
242 pPage->FillItemSet( *pOptions );
243 else
244 pPage->Reset( *pOptions );
245 return nRet;
248 //--------------------------------------------------------------------
250 long SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
252 if ( rNEvt.GetType() == EVENT_KEYINPUT )
254 if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
255 return 1; // help disabled -> <F1> does nothing
258 return ModalDialog::Notify( rNEvt );
261 //--------------------------------------------------------------------
263 void SfxPrintOptionsDialog::DisableHelp()
265 pDlgImpl->mbHelpDisabled = sal_True;
267 get<HelpButton>("help")->Disable();
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */