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