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