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