Line data Source code
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 <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>
26 :
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"
35 :
36 : // struct SfxPrinter_Impl ------------------------------------------------
37 :
38 : struct SfxPrinter_Impl
39 : {
40 : bool mbAll;
41 : bool mbSelection;
42 : bool mbFromTo;
43 : bool mbRange;
44 :
45 626 : SfxPrinter_Impl() :
46 : mbAll ( true ),
47 : mbSelection ( true ),
48 : mbFromTo ( true ),
49 626 : mbRange ( true ) {}
50 623 : ~SfxPrinter_Impl() {}
51 : };
52 :
53 : struct SfxPrintOptDlg_Impl
54 : {
55 : bool mbHelpDisabled;
56 :
57 0 : SfxPrintOptDlg_Impl() :
58 0 : mbHelpDisabled ( false ) {}
59 : };
60 :
61 : // class SfxPrinter ------------------------------------------------------
62 :
63 184 : SfxPrinter* SfxPrinter::Create( SvStream& rStream, SfxItemSet* pOptions )
64 :
65 : /* [Description]
66 :
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.
71 :
72 : The 'pOptions' are taken over in the generated SfxPrinter, the return
73 : value belongs to the caller.
74 : */
75 :
76 : {
77 : // Load JobSetup
78 184 : JobSetup aFileJobSetup;
79 184 : ReadJobSetup( rStream, aFileJobSetup );
80 :
81 : // Get printers
82 184 : SfxPrinter *pPrinter = new SfxPrinter( pOptions, aFileJobSetup );
83 184 : return pPrinter;
84 : }
85 :
86 :
87 :
88 40 : SvStream& SfxPrinter::Store( SvStream& rStream ) const
89 :
90 : /* [Description]
91 :
92 : Saves the used JobSetup of <SfxPrinter>s.
93 : */
94 :
95 : {
96 40 : return WriteJobSetup( rStream, GetJobSetup() );
97 : }
98 :
99 :
100 :
101 412 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
102 :
103 : /* [Description]
104 :
105 : This constructor creates a default printer.
106 : */
107 :
108 : pOptions( pTheOptions ),
109 412 : bKnown(true)
110 :
111 : {
112 : assert(pOptions);
113 412 : pImpl = new SfxPrinter_Impl;
114 412 : }
115 :
116 :
117 :
118 184 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
119 : const JobSetup& rTheOrigJobSetup ) :
120 :
121 : Printer ( rTheOrigJobSetup.GetPrinterName() ),
122 184 : pOptions ( pTheOptions )
123 :
124 : {
125 : assert(pOptions);
126 184 : pImpl = new SfxPrinter_Impl;
127 184 : bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
128 :
129 184 : if ( bKnown )
130 100 : SetJobSetup( rTheOrigJobSetup );
131 184 : }
132 :
133 :
134 :
135 30 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
136 : const OUString& rPrinterName ) :
137 :
138 : Printer ( rPrinterName ),
139 : pOptions ( pTheOptions ),
140 30 : bKnown ( GetName() == rPrinterName )
141 :
142 : {
143 : assert(pOptions);
144 30 : pImpl = new SfxPrinter_Impl;
145 30 : }
146 :
147 :
148 :
149 0 : SfxPrinter::SfxPrinter( const SfxPrinter& rPrinter ) :
150 :
151 0 : Printer ( rPrinter.GetName() ),
152 0 : pOptions( rPrinter.GetOptions().Clone() ),
153 0 : bKnown ( rPrinter.IsKnown() )
154 : {
155 : assert(pOptions);
156 0 : SetJobSetup( rPrinter.GetJobSetup() );
157 0 : SetPrinterProps( &rPrinter );
158 0 : SetMapMode( rPrinter.GetMapMode() );
159 :
160 0 : pImpl = new SfxPrinter_Impl;
161 0 : pImpl->mbAll = rPrinter.pImpl->mbAll;
162 0 : pImpl->mbSelection = rPrinter.pImpl->mbSelection;
163 0 : pImpl->mbFromTo = rPrinter.pImpl->mbFromTo;
164 0 : pImpl->mbRange = rPrinter.pImpl->mbRange;
165 0 : }
166 :
167 :
168 :
169 0 : SfxPrinter* SfxPrinter::Clone() const
170 : {
171 0 : if ( IsDefPrinter() )
172 : {
173 : SfxPrinter *pNewPrinter;
174 0 : pNewPrinter = new SfxPrinter( GetOptions().Clone() );
175 0 : pNewPrinter->SetJobSetup( GetJobSetup() );
176 0 : pNewPrinter->SetPrinterProps( this );
177 0 : pNewPrinter->SetMapMode( GetMapMode() );
178 0 : pNewPrinter->pImpl->mbAll = pImpl->mbAll;
179 0 : pNewPrinter->pImpl->mbSelection =pImpl->mbSelection;
180 0 : pNewPrinter->pImpl->mbFromTo = pImpl->mbFromTo;
181 0 : pNewPrinter->pImpl->mbRange =pImpl->mbRange;
182 0 : return pNewPrinter;
183 : }
184 : else
185 0 : return new SfxPrinter( *this );
186 : }
187 :
188 :
189 :
190 1869 : SfxPrinter::~SfxPrinter()
191 : {
192 623 : delete pOptions;
193 623 : delete pImpl;
194 1246 : }
195 :
196 :
197 :
198 336 : void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
199 : {
200 336 : pOptions->Set(rNewOptions);
201 336 : }
202 :
203 :
204 :
205 0 : SfxPrintOptionsDialog::SfxPrintOptionsDialog(vcl::Window *pParent,
206 : SfxViewShell *pViewShell,
207 : const SfxItemSet *pSet)
208 :
209 : : ModalDialog(pParent, "PrinterOptionsDialog",
210 : "sfx/ui/printeroptionsdialog.ui")
211 0 : , pDlgImpl(new SfxPrintOptDlg_Impl)
212 : , pViewSh(pViewShell)
213 0 : , pOptions(pSet->Clone())
214 : {
215 0 : VclContainer *pVBox = get_content_area();
216 :
217 : // Insert TabPage
218 0 : pPage = pViewSh->CreatePrintOptionsPage(pVBox, *pOptions);
219 : DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
220 0 : if( pPage )
221 : {
222 0 : pPage->Reset( pOptions );
223 0 : SetHelpId( pPage->GetHelpId() );
224 0 : pPage->Show();
225 : }
226 0 : }
227 :
228 :
229 :
230 0 : SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
231 : {
232 0 : delete pDlgImpl;
233 0 : delete pPage;
234 0 : delete pOptions;
235 0 : }
236 :
237 :
238 :
239 0 : short SfxPrintOptionsDialog::Execute()
240 : {
241 0 : if( ! pPage )
242 0 : return RET_CANCEL;
243 :
244 0 : short nRet = ModalDialog::Execute();
245 0 : if ( nRet == RET_OK )
246 0 : pPage->FillItemSet( pOptions );
247 : else
248 0 : pPage->Reset( pOptions );
249 0 : return nRet;
250 : }
251 :
252 :
253 :
254 0 : bool SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
255 : {
256 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
257 : {
258 0 : if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
259 0 : return true; // help disabled -> <F1> does nothing
260 : }
261 :
262 0 : return ModalDialog::Notify( rNEvt );
263 : }
264 :
265 :
266 :
267 0 : void SfxPrintOptionsDialog::DisableHelp()
268 : {
269 0 : pDlgImpl->mbHelpDisabled = true;
270 :
271 0 : get<HelpButton>("help")->Disable();
272 951 : }
273 :
274 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|