xref: /trunk/main/sfx2/source/view/printer.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir #include <vcl/virdev.hxx>
27cdf0e10cSrcweir #include <vcl/metric.hxx>
28cdf0e10cSrcweir #include <vcl/msgbox.hxx>
29cdf0e10cSrcweir #include <unotools/printwarningoptions.hxx>
30cdf0e10cSrcweir #include <svtools/printoptions.hxx>
31cdf0e10cSrcweir #include <vector>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #ifndef GCC
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <sfx2/printer.hxx>
37cdf0e10cSrcweir #include <sfx2/printopt.hxx>
38cdf0e10cSrcweir #include "sfxtypes.hxx"
39cdf0e10cSrcweir #include <sfx2/prnmon.hxx>
40cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
41cdf0e10cSrcweir #include <sfx2/tabdlg.hxx>
42cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
43cdf0e10cSrcweir #include "view.hrc"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir // struct SfxPrinter_Impl ------------------------------------------------
46cdf0e10cSrcweir 
47cdf0e10cSrcweir struct SfxPrinter_Impl
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     sal_Bool            mbAll;
50cdf0e10cSrcweir     sal_Bool            mbSelection;
51cdf0e10cSrcweir     sal_Bool            mbFromTo;
52cdf0e10cSrcweir     sal_Bool            mbRange;
53cdf0e10cSrcweir 
SfxPrinter_ImplSfxPrinter_Impl54cdf0e10cSrcweir     SfxPrinter_Impl() :
55cdf0e10cSrcweir         mbAll       ( sal_True ),
56cdf0e10cSrcweir         mbSelection ( sal_True ),
57cdf0e10cSrcweir         mbFromTo    ( sal_True ),
58cdf0e10cSrcweir         mbRange     ( sal_True ) {}
~SfxPrinter_ImplSfxPrinter_Impl59cdf0e10cSrcweir     ~SfxPrinter_Impl() {}
60cdf0e10cSrcweir };
61cdf0e10cSrcweir 
62cdf0e10cSrcweir struct SfxPrintOptDlg_Impl
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     sal_Bool        mbHelpDisabled;
65cdf0e10cSrcweir 
SfxPrintOptDlg_ImplSfxPrintOptDlg_Impl66cdf0e10cSrcweir     SfxPrintOptDlg_Impl() :
67cdf0e10cSrcweir         mbHelpDisabled  ( sal_False ) {}
68cdf0e10cSrcweir };
69cdf0e10cSrcweir 
70cdf0e10cSrcweir // class SfxPrinter ------------------------------------------------------
71cdf0e10cSrcweir 
Create(SvStream & rStream,SfxItemSet * pOptions)72cdf0e10cSrcweir SfxPrinter* SfxPrinter::Create( SvStream& rStream, SfxItemSet* pOptions )
73cdf0e10cSrcweir 
74cdf0e10cSrcweir /*  [Beschreibung]
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     Erzeugt einen <SfxPrinter> aus dem Stream. Geladen wird genaugenommen
77cdf0e10cSrcweir     nur ein JobSetup. Falls ein solcher Drucker auf dem System nicht
78cdf0e10cSrcweir     verf"augbar ist, wird das Original als Orig-JobSetup gemerkt und
79cdf0e10cSrcweir     ein "anhlicher exisitierender Drucker genommen.
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     Die 'pOptions' werden in den erzeugten SfxPrinter "ubernommen,
82cdf0e10cSrcweir     der Returnwert geh"ort dem Caller.
83cdf0e10cSrcweir */
84cdf0e10cSrcweir 
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     // JobSetup laden
87cdf0e10cSrcweir     JobSetup aFileJobSetup;
88cdf0e10cSrcweir     rStream >> aFileJobSetup;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     // Drucker erzeugen
91cdf0e10cSrcweir     SfxPrinter *pPrinter = new SfxPrinter( pOptions, aFileJobSetup );
92cdf0e10cSrcweir     return pPrinter;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //--------------------------------------------------------------------
96cdf0e10cSrcweir 
Store(SvStream & rStream) const97cdf0e10cSrcweir SvStream& SfxPrinter::Store( SvStream& rStream ) const
98cdf0e10cSrcweir 
99cdf0e10cSrcweir /*  [Beschreibung]
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     Speichert das verwendete JobSetup des <SfxPrinter>s.
102cdf0e10cSrcweir */
103cdf0e10cSrcweir 
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     return ( rStream << GetJobSetup() );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir //--------------------------------------------------------------------
109cdf0e10cSrcweir 
SfxPrinter(SfxItemSet * pTheOptions)110cdf0e10cSrcweir SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
111cdf0e10cSrcweir 
112cdf0e10cSrcweir /*  [Beschreibung]
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     Dieser Ctor erzeugt einen Standard-Drucker.
115cdf0e10cSrcweir */
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     pOptions( pTheOptions ),
118cdf0e10cSrcweir     bKnown(sal_True)
119cdf0e10cSrcweir 
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     pImpl = new SfxPrinter_Impl;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir //--------------------------------------------------------------------
125cdf0e10cSrcweir 
SfxPrinter(SfxItemSet * pTheOptions,const JobSetup & rTheOrigJobSetup)126cdf0e10cSrcweir SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
127cdf0e10cSrcweir                         const JobSetup& rTheOrigJobSetup ) :
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     Printer         ( rTheOrigJobSetup.GetPrinterName() ),
130cdf0e10cSrcweir     pOptions        ( pTheOptions )
131cdf0e10cSrcweir 
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     pImpl = new SfxPrinter_Impl;
134cdf0e10cSrcweir     bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     if ( bKnown )
137cdf0e10cSrcweir         SetJobSetup( rTheOrigJobSetup );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //--------------------------------------------------------------------
141cdf0e10cSrcweir 
SfxPrinter(SfxItemSet * pTheOptions,const String & rPrinterName)142cdf0e10cSrcweir SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
143cdf0e10cSrcweir                         const String& rPrinterName ) :
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     Printer         ( rPrinterName ),
146cdf0e10cSrcweir     pOptions        ( pTheOptions ),
147cdf0e10cSrcweir     bKnown          ( GetName() == rPrinterName )
148cdf0e10cSrcweir 
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     pImpl = new SfxPrinter_Impl;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir //--------------------------------------------------------------------
154cdf0e10cSrcweir 
SfxPrinter(const SfxPrinter & rPrinter)155cdf0e10cSrcweir SfxPrinter::SfxPrinter( const SfxPrinter& rPrinter ) :
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     Printer ( rPrinter.GetName() ),
158cdf0e10cSrcweir     pOptions( rPrinter.GetOptions().Clone() ),
159cdf0e10cSrcweir     bKnown  ( rPrinter.IsKnown() )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     SetJobSetup( rPrinter.GetJobSetup() );
162cdf0e10cSrcweir     SetPrinterProps( &rPrinter );
163cdf0e10cSrcweir     SetMapMode( rPrinter.GetMapMode() );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     pImpl = new SfxPrinter_Impl;
166cdf0e10cSrcweir     pImpl->mbAll = rPrinter.pImpl->mbAll;
167cdf0e10cSrcweir     pImpl->mbSelection = rPrinter.pImpl->mbSelection;
168cdf0e10cSrcweir     pImpl->mbFromTo = rPrinter.pImpl->mbFromTo;
169cdf0e10cSrcweir     pImpl->mbRange = rPrinter.pImpl->mbRange;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir //--------------------------------------------------------------------
173cdf0e10cSrcweir 
Clone() const174cdf0e10cSrcweir SfxPrinter* SfxPrinter::Clone() const
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     if ( IsDefPrinter() )
177cdf0e10cSrcweir     {
178cdf0e10cSrcweir         SfxPrinter *pNewPrinter;
179cdf0e10cSrcweir         pNewPrinter = new SfxPrinter( GetOptions().Clone() );
180cdf0e10cSrcweir         pNewPrinter->SetJobSetup( GetJobSetup() );
181cdf0e10cSrcweir         pNewPrinter->SetPrinterProps( this );
182cdf0e10cSrcweir         pNewPrinter->SetMapMode( GetMapMode() );
183cdf0e10cSrcweir         pNewPrinter->pImpl->mbAll = pImpl->mbAll;
184cdf0e10cSrcweir         pNewPrinter->pImpl->mbSelection =pImpl->mbSelection;
185cdf0e10cSrcweir         pNewPrinter->pImpl->mbFromTo = pImpl->mbFromTo;
186cdf0e10cSrcweir         pNewPrinter->pImpl->mbRange =pImpl->mbRange;
187cdf0e10cSrcweir         return pNewPrinter;
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir     else
190cdf0e10cSrcweir         return new SfxPrinter( *this );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir //--------------------------------------------------------------------
194cdf0e10cSrcweir 
~SfxPrinter()195cdf0e10cSrcweir SfxPrinter::~SfxPrinter()
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     delete pOptions;
198cdf0e10cSrcweir     delete pImpl;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir //--------------------------------------------------------------------
202cdf0e10cSrcweir 
SetOptions(const SfxItemSet & rNewOptions)203cdf0e10cSrcweir void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     pOptions->Set(rNewOptions);
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir //--------------------------------------------------------------------
209cdf0e10cSrcweir 
SfxPrintOptionsDialog(Window * pParent,SfxViewShell * pViewShell,const SfxItemSet * pSet)210cdf0e10cSrcweir SfxPrintOptionsDialog::SfxPrintOptionsDialog( Window *pParent,
211cdf0e10cSrcweir                                               SfxViewShell *pViewShell,
212cdf0e10cSrcweir                                               const SfxItemSet *pSet ) :
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     ModalDialog( pParent, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     aOkBtn      ( this ),
217cdf0e10cSrcweir     aCancelBtn  ( this ),
218cdf0e10cSrcweir     aHelpBtn    ( this ),
219cdf0e10cSrcweir     pDlgImpl    ( new SfxPrintOptDlg_Impl ),
220cdf0e10cSrcweir     pViewSh     ( pViewShell ),
221cdf0e10cSrcweir     pOptions    ( pSet->Clone() ),
222cdf0e10cSrcweir     pPage       ( NULL )
223cdf0e10cSrcweir 
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     SetText( SfxResId( STR_PRINT_OPTIONS_TITLE ) );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     // TabPage einh"angen
228cdf0e10cSrcweir     pPage = pViewSh->CreatePrintOptionsPage( this, *pOptions );
229cdf0e10cSrcweir     DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
230cdf0e10cSrcweir     if( pPage )
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         pPage->Reset( *pOptions );
233cdf0e10cSrcweir         SetHelpId( pPage->GetHelpId() );
234cdf0e10cSrcweir         pPage->Show();
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     // Dialoggr"o\se bestimmen
238cdf0e10cSrcweir     Size a6Sz = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
239cdf0e10cSrcweir     Size aBtnSz = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
240cdf0e10cSrcweir     Size aOutSz( pPage ? pPage->GetSizePixel() : Size() );
241cdf0e10cSrcweir     aOutSz.Height() += 6;
242cdf0e10cSrcweir     long nWidth = aBtnSz.Width();
243cdf0e10cSrcweir     nWidth += a6Sz.Width();
244cdf0e10cSrcweir     aOutSz.Width() += nWidth;
245cdf0e10cSrcweir     if ( aOutSz.Height() < 90 )
246cdf0e10cSrcweir         // mindestens die H"ohe der 3 Buttons
247cdf0e10cSrcweir         aOutSz.Height() = 90;
248cdf0e10cSrcweir     SetOutputSizePixel( aOutSz );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     // set position and size of the buttons
251cdf0e10cSrcweir     Point aBtnPos( aOutSz.Width() - aBtnSz.Width() - a6Sz.Width(), a6Sz.Height() );
252cdf0e10cSrcweir     aOkBtn.SetPosSizePixel( aBtnPos, aBtnSz );
253cdf0e10cSrcweir     aBtnPos.Y() += aBtnSz.Height() + ( a6Sz.Height() / 2 );
254cdf0e10cSrcweir     aCancelBtn.SetPosSizePixel( aBtnPos, aBtnSz );
255cdf0e10cSrcweir     aBtnPos.Y() += aBtnSz.Height() + a6Sz.Height();
256cdf0e10cSrcweir     aHelpBtn.SetPosSizePixel( aBtnPos, aBtnSz );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     aCancelBtn.Show();
259cdf0e10cSrcweir     aOkBtn.Show();
260cdf0e10cSrcweir     aHelpBtn.Show();
261cdf0e10cSrcweir }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir //--------------------------------------------------------------------
264cdf0e10cSrcweir 
~SfxPrintOptionsDialog()265cdf0e10cSrcweir SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
266cdf0e10cSrcweir {
267cdf0e10cSrcweir     delete pDlgImpl;
268cdf0e10cSrcweir     delete pPage;
269cdf0e10cSrcweir     delete pOptions;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir //--------------------------------------------------------------------
273cdf0e10cSrcweir 
Execute()274cdf0e10cSrcweir short SfxPrintOptionsDialog::Execute()
275cdf0e10cSrcweir {
276cdf0e10cSrcweir     if( ! pPage )
277cdf0e10cSrcweir         return RET_CANCEL;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     short nRet = ModalDialog::Execute();
280cdf0e10cSrcweir     if ( nRet == RET_OK )
281cdf0e10cSrcweir         pPage->FillItemSet( *pOptions );
282cdf0e10cSrcweir     else
283cdf0e10cSrcweir         pPage->Reset( *pOptions );
284cdf0e10cSrcweir     return nRet;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir //--------------------------------------------------------------------
288cdf0e10cSrcweir 
Notify(NotifyEvent & rNEvt)289cdf0e10cSrcweir long SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     if ( rNEvt.GetType() == EVENT_KEYINPUT )
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
294cdf0e10cSrcweir             return 1; // help disabled -> <F1> does nothing
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     return ModalDialog::Notify( rNEvt );
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir //--------------------------------------------------------------------
301cdf0e10cSrcweir 
DisableHelp()302cdf0e10cSrcweir void SfxPrintOptionsDialog::DisableHelp()
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     pDlgImpl->mbHelpDisabled = sal_True;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir     aHelpBtn.Disable();
307cdf0e10cSrcweir }
308