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 403 : SfxPrinter_Impl() :
46 : mbAll ( true ),
47 : mbSelection ( true ),
48 : mbFromTo ( true ),
49 403 : mbRange ( true ) {}
50 397 : ~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 145 : VclPtr<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 145 : JobSetup aFileJobSetup;
79 145 : ReadJobSetup( rStream, aFileJobSetup );
80 :
81 : // Get printers
82 145 : VclPtr<SfxPrinter> pPrinter = VclPtr<SfxPrinter>::Create( pOptions, aFileJobSetup );
83 145 : return pPrinter;
84 : }
85 :
86 :
87 :
88 30 : SvStream& SfxPrinter::Store( SvStream& rStream ) const
89 :
90 : /* [Description]
91 :
92 : Saves the used JobSetup of <SfxPrinter>s.
93 : */
94 :
95 : {
96 30 : return WriteJobSetup( rStream, GetJobSetup() );
97 : }
98 :
99 :
100 :
101 224 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
102 :
103 : /* [Description]
104 :
105 : This constructor creates a default printer.
106 : */
107 :
108 : pOptions( pTheOptions ),
109 224 : bKnown(true)
110 :
111 : {
112 : assert(pOptions);
113 224 : pImpl = new SfxPrinter_Impl;
114 224 : }
115 :
116 :
117 :
118 145 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
119 : const JobSetup& rTheOrigJobSetup ) :
120 :
121 : Printer ( rTheOrigJobSetup.GetPrinterName() ),
122 145 : pOptions ( pTheOptions )
123 :
124 : {
125 : assert(pOptions);
126 145 : pImpl = new SfxPrinter_Impl;
127 145 : bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
128 :
129 145 : if ( bKnown )
130 65 : SetJobSetup( rTheOrigJobSetup );
131 145 : }
132 :
133 :
134 :
135 34 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
136 : const OUString& rPrinterName ) :
137 :
138 : Printer ( rPrinterName ),
139 : pOptions ( pTheOptions ),
140 34 : bKnown ( GetName() == rPrinterName )
141 :
142 : {
143 : assert(pOptions);
144 34 : pImpl = new SfxPrinter_Impl;
145 34 : }
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 : VclPtr<SfxPrinter> SfxPrinter::Clone() const
170 : {
171 0 : if ( IsDefPrinter() )
172 : {
173 0 : VclPtr<SfxPrinter> pNewPrinter = VclPtr<SfxPrinter>::Create( GetOptions().Clone() );
174 0 : pNewPrinter->SetJobSetup( GetJobSetup() );
175 0 : pNewPrinter->SetPrinterProps( this );
176 0 : pNewPrinter->SetMapMode( GetMapMode() );
177 0 : pNewPrinter->pImpl->mbAll = pImpl->mbAll;
178 0 : pNewPrinter->pImpl->mbSelection =pImpl->mbSelection;
179 0 : pNewPrinter->pImpl->mbFromTo = pImpl->mbFromTo;
180 0 : pNewPrinter->pImpl->mbRange =pImpl->mbRange;
181 0 : return pNewPrinter;
182 : }
183 : else
184 0 : return VclPtr<SfxPrinter>::Create( *this );
185 : }
186 :
187 :
188 :
189 1191 : SfxPrinter::~SfxPrinter()
190 : {
191 397 : disposeOnce();
192 794 : }
193 :
194 397 : void SfxPrinter::dispose()
195 : {
196 397 : delete pOptions;
197 397 : delete pImpl;
198 397 : Printer::dispose();
199 397 : }
200 :
201 :
202 :
203 238 : void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
204 : {
205 238 : pOptions->Set(rNewOptions);
206 238 : }
207 :
208 :
209 :
210 0 : SfxPrintOptionsDialog::SfxPrintOptionsDialog(vcl::Window *pParent,
211 : SfxViewShell *pViewShell,
212 : const SfxItemSet *pSet)
213 :
214 : : ModalDialog(pParent, "PrinterOptionsDialog",
215 : "sfx/ui/printeroptionsdialog.ui")
216 0 : , pDlgImpl(new SfxPrintOptDlg_Impl)
217 : , pViewSh(pViewShell)
218 0 : , pOptions(pSet->Clone())
219 : {
220 0 : VclContainer *pVBox = get_content_area();
221 :
222 : // Insert TabPage
223 0 : pPage.reset(pViewSh->CreatePrintOptionsPage(pVBox, *pOptions));
224 : DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
225 0 : if( pPage )
226 : {
227 0 : pPage->Reset( pOptions );
228 0 : SetHelpId( pPage->GetHelpId() );
229 0 : pPage->Show();
230 : }
231 0 : }
232 :
233 :
234 :
235 0 : SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
236 : {
237 0 : disposeOnce();
238 0 : }
239 :
240 0 : void SfxPrintOptionsDialog::dispose()
241 : {
242 0 : delete pDlgImpl;
243 0 : pPage.disposeAndClear();
244 0 : delete pOptions;
245 0 : ModalDialog::dispose();
246 0 : }
247 :
248 :
249 :
250 0 : short SfxPrintOptionsDialog::Execute()
251 : {
252 0 : if( ! pPage )
253 0 : return RET_CANCEL;
254 :
255 0 : short nRet = ModalDialog::Execute();
256 0 : if ( nRet == RET_OK )
257 0 : pPage->FillItemSet( pOptions );
258 : else
259 0 : pPage->Reset( pOptions );
260 0 : return nRet;
261 : }
262 :
263 :
264 :
265 0 : bool SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
266 : {
267 0 : if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
268 : {
269 0 : if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
270 0 : return true; // help disabled -> <F1> does nothing
271 : }
272 :
273 0 : return ModalDialog::Notify( rNEvt );
274 : }
275 :
276 :
277 :
278 0 : void SfxPrintOptionsDialog::DisableHelp()
279 : {
280 0 : pDlgImpl->mbHelpDisabled = true;
281 :
282 0 : get<HelpButton>("help")->Disable();
283 648 : }
284 :
285 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|