1efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5efeef26fSAndrew Rist * distributed with this work for additional information 6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14efeef26fSAndrew Rist * software distributed under the License is distributed on an 15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17efeef26fSAndrew Rist * specific language governing permissions and limitations 18efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20efeef26fSAndrew Rist *************************************************************/ 21efeef26fSAndrew Rist 22efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/text/NotePrintMode.hpp> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <cstdarg> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifndef _CMDID_H 32cdf0e10cSrcweir #include <cmdid.h> 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir 35cdf0e10cSrcweir #ifndef _SVSTDARR_HXX 36cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR 37cdf0e10cSrcweir #include <svl/svstdarr.hxx> 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir #include <sfx2/request.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <sfx2/progress.hxx> 42cdf0e10cSrcweir #include <sfx2/app.hxx> 43cdf0e10cSrcweir #include <svl/flagitem.hxx> 44cdf0e10cSrcweir #include <vcl/msgbox.hxx> 45cdf0e10cSrcweir #include <vcl/oldprintadaptor.hxx> 46cdf0e10cSrcweir #include <sfx2/printer.hxx> 47cdf0e10cSrcweir #include <sfx2/prnmon.hxx> 48cdf0e10cSrcweir #include <editeng/paperinf.hxx> 49cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 50cdf0e10cSrcweir #include <unotools/misccfg.hxx> 51cdf0e10cSrcweir #include <svx/prtqry.hxx> 52cdf0e10cSrcweir #include <svx/svdview.hxx> 53cdf0e10cSrcweir #include <svl/eitem.hxx> 54cdf0e10cSrcweir #include <svl/stritem.hxx> 55cdf0e10cSrcweir #include <svl/intitem.hxx> 56cdf0e10cSrcweir #include <svl/flagitem.hxx> 57cdf0e10cSrcweir #include <sfx2/linkmgr.hxx> 58cdf0e10cSrcweir 59cdf0e10cSrcweir #include <modcfg.hxx> 60cdf0e10cSrcweir #include <edtwin.hxx> 61cdf0e10cSrcweir #include <view.hxx> 62cdf0e10cSrcweir #include <wrtsh.hxx> 63cdf0e10cSrcweir #include <docsh.hxx> 64cdf0e10cSrcweir #include <viewopt.hxx> 65cdf0e10cSrcweir #include <prtopt.hxx> 66cdf0e10cSrcweir #include <fontcfg.hxx> 67cdf0e10cSrcweir #include <cfgitems.hxx> 68cdf0e10cSrcweir #include <dbmgr.hxx> 69cdf0e10cSrcweir #include <docstat.hxx> 70cdf0e10cSrcweir #include <viewfunc.hxx> 71cdf0e10cSrcweir #include <swmodule.hxx> 72cdf0e10cSrcweir #include <wview.hxx> 73cdf0e10cSrcweir #include <doc.hxx> 74cdf0e10cSrcweir #include <fldbas.hxx> 75cdf0e10cSrcweir 76cdf0e10cSrcweir #include <globals.hrc> 77cdf0e10cSrcweir #include <view.hrc> 78cdf0e10cSrcweir #include <app.hrc> 79cdf0e10cSrcweir #include <svl/eitem.hxx> 80cdf0e10cSrcweir #include <swwrtshitem.hxx> 81cdf0e10cSrcweir #include "swabstdlg.hxx" 82cdf0e10cSrcweir #include <svl/slstitm.hxx> 83cdf0e10cSrcweir 84cdf0e10cSrcweir #include <unomid.h> 85cdf0e10cSrcweir 86cdf0e10cSrcweir using namespace ::com::sun::star; 87cdf0e10cSrcweir 88cdf0e10cSrcweir 89cdf0e10cSrcweir /*-------------------------------------------------------------------- 90cdf0e10cSrcweir Beschreibung: Drucker an Sfx uebergeben 91cdf0e10cSrcweir --------------------------------------------------------------------*/ 92cdf0e10cSrcweir 93cdf0e10cSrcweir 94cdf0e10cSrcweir SfxPrinter* __EXPORT SwView::GetPrinter( sal_Bool bCreate ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir const IDocumentDeviceAccess* pIDDA = GetWrtShell().getIDocumentDeviceAccess(); 97cdf0e10cSrcweir SfxPrinter *pOld = pIDDA->getPrinter( false ); 98cdf0e10cSrcweir SfxPrinter *pPrt = pIDDA->getPrinter( bCreate ); 99cdf0e10cSrcweir if ( pOld != pPrt ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this); 102cdf0e10cSrcweir ::SetAppPrintOptions( &GetWrtShell(), bWeb ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir return pPrt; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir /*-------------------------------------------------------------------- 108cdf0e10cSrcweir Beschreibung: Druckerwechsel weitermelden 109cdf0e10cSrcweir --------------------------------------------------------------------*/ 110cdf0e10cSrcweir 111cdf0e10cSrcweir void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter* pNew, sal_Bool bWeb ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb); 114cdf0e10cSrcweir if( !pOpt) 115cdf0e10cSrcweir return; 116cdf0e10cSrcweir 117cdf0e10cSrcweir // Applikationseigene Druckoptionen aus SfxPrinter auslesen 118cdf0e10cSrcweir const SfxItemSet& rSet = pNew->GetOptions(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir const SwAddPrinterItem* pAddPrinterAttr; 121cdf0e10cSrcweir if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, sal_False, 122cdf0e10cSrcweir (const SfxPoolItem**)&pAddPrinterAttr ) ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir if( pIDDA ) 125cdf0e10cSrcweir pIDDA->setPrintData( *pAddPrinterAttr ); 126cdf0e10cSrcweir if( pAddPrinterAttr->GetFax().getLength() ) 127cdf0e10cSrcweir pOpt->SetFaxName(pAddPrinterAttr->GetFax()); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir 132cdf0e10cSrcweir sal_uInt16 __EXPORT SwView::SetPrinter(SfxPrinter* pNew, sal_uInt16 nDiffFlags, bool ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir SwWrtShell &rSh = GetWrtShell(); 135cdf0e10cSrcweir SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false ); 136cdf0e10cSrcweir if ( pOld && pOld->IsPrinting() ) 137cdf0e10cSrcweir return SFX_PRINTERROR_BUSY; 138cdf0e10cSrcweir 139cdf0e10cSrcweir if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true ); 142cdf0e10cSrcweir if ( nDiffFlags & SFX_PRINTER_PRINTER ) 143cdf0e10cSrcweir rSh.SetModified(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this); 146cdf0e10cSrcweir if ( nDiffFlags & SFX_PRINTER_OPTIONS ) 147cdf0e10cSrcweir ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, bWeb ); 148cdf0e10cSrcweir 149cdf0e10cSrcweir const sal_Bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? sal_True : sal_False; 150cdf0e10cSrcweir const sal_Bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? sal_True : sal_False; 151cdf0e10cSrcweir if ( bChgOri || bChgSize ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir rSh.StartAllAction(); 154cdf0e10cSrcweir if ( bChgOri ) 155cdf0e10cSrcweir rSh.ChgAllPageOrientation( sal_uInt16(pNew->GetOrientation()) ); 156cdf0e10cSrcweir if ( bChgSize ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir Size aSz( SvxPaperInfo::GetPaperSize( pNew ) ); 159cdf0e10cSrcweir rSh.ChgAllPageSize( aSz ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir rSh.SetModified(); 162cdf0e10cSrcweir rSh.EndAllAction(); 163cdf0e10cSrcweir InvalidateRulerPos(); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir return 0; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir /*-------------------------------------------------------------------- 169cdf0e10cSrcweir Beschreibung: TabPage fuer applikationsspezifische Druckoptionen 170cdf0e10cSrcweir --------------------------------------------------------------------*/ 171cdf0e10cSrcweir 172cdf0e10cSrcweir SfxTabPage* __EXPORT SwView::CreatePrintOptionsPage(Window* pParent, 173cdf0e10cSrcweir const SfxItemSet& rSet) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir return ::CreatePrintOptionsPage( pParent, rSet, sal_False ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir /*-------------------------------------------------------------------- 179cdf0e10cSrcweir Beschreibung: Print-Dispatcher 180cdf0e10cSrcweir --------------------------------------------------------------------*/ 181cdf0e10cSrcweir 182cdf0e10cSrcweir void __EXPORT SwView::ExecutePrint(SfxRequest& rReq) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this); 185cdf0e10cSrcweir ::SetAppPrintOptions( &GetWrtShell(), bWeb ); 186cdf0e10cSrcweir switch (rReq.GetSlot()) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir case FN_FAX: 189cdf0e10cSrcweir { 190cdf0e10cSrcweir SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb); 191cdf0e10cSrcweir String sFaxName(pPrintOptions->GetFaxName()); 192cdf0e10cSrcweir if (sFaxName.Len()) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName); 195cdf0e10cSrcweir SfxBoolItem aSilent( SID_SILENT, sal_True ); 196cdf0e10cSrcweir GetViewFrame()->GetDispatcher()->Execute( SID_PRINTDOC, 197cdf0e10cSrcweir SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD, 198cdf0e10cSrcweir &aPrinterName, &aSilent, 0L ); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir else 201cdf0e10cSrcweir { 202cdf0e10cSrcweir InfoBox aInfoBox(&GetEditWin(), SW_RES(MSG_ERR_NO_FAX)); 203cdf0e10cSrcweir String sMsg = aInfoBox.GetMessText(); 204cdf0e10cSrcweir sal_uInt16 nResNo = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS; 205cdf0e10cSrcweir sMsg.SearchAndReplace(String::CreateFromAscii("%1"), String(SW_RES(nResNo))); 206cdf0e10cSrcweir aInfoBox.SetMessText(sMsg); 207cdf0e10cSrcweir aInfoBox.Execute(); 208cdf0e10cSrcweir SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE); 209cdf0e10cSrcweir GetViewFrame()->GetDispatcher()->Execute(SID_SW_EDITOPTIONS, 210cdf0e10cSrcweir SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD, 211cdf0e10cSrcweir &aDefPage, 0L ); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir } 214cdf0e10cSrcweir break; 215cdf0e10cSrcweir case SID_PRINTDOC: 216cdf0e10cSrcweir case SID_PRINTDOCDIRECT: 217cdf0e10cSrcweir { 218cdf0e10cSrcweir SwWrtShell* pSh = &GetWrtShell(); 219cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False); 220cdf0e10cSrcweir sal_Bool bSilent = pSilentItem ? pSilentItem->GetValue() : sal_False; 221cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pPrintFromMergeItem, SfxBoolItem, FN_QRY_MERGE, sal_False); 222cdf0e10cSrcweir if(pPrintFromMergeItem) 223cdf0e10cSrcweir rReq.RemoveItem(FN_QRY_MERGE); 224cdf0e10cSrcweir sal_Bool bFromMerge = pPrintFromMergeItem ? pPrintFromMergeItem->GetValue() : sal_False; 225cdf0e10cSrcweir SwMiscConfig aMiscConfig; 226cdf0e10cSrcweir bool bPrintSelection = false; 227cdf0e10cSrcweir if(!bSilent && !bFromMerge && 228cdf0e10cSrcweir SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc()) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir QueryBox aBox( &GetEditWin(), SW_RES( MSG_PRINT_AS_MERGE )); 231cdf0e10cSrcweir short nRet = aBox.Execute(); 232cdf0e10cSrcweir if(RET_YES == nRet) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir SfxBoolItem aBool(FN_QRY_MERGE, sal_True); 235cdf0e10cSrcweir GetViewFrame()->GetDispatcher()->Execute( 236cdf0e10cSrcweir FN_QRY_MERGE, SFX_CALLMODE_ASYNCHRON, &aBool, 0L); 237cdf0e10cSrcweir rReq.Ignore(); 238cdf0e10cSrcweir return; 239cdf0e10cSrcweir } 240cdf0e10cSrcweir } 241cdf0e10cSrcweir else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir if( /*!bIsAPI && */ 244cdf0e10cSrcweir ( pSh->IsSelection() || pSh->IsFrmSelected() || pSh->IsObjSelected() ) ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir short nBtn = SvxPrtQryBox(&GetEditWin()).Execute(); 247cdf0e10cSrcweir if( RET_CANCEL == nBtn ) 248*be099857Smseidel return; 249cdf0e10cSrcweir 250cdf0e10cSrcweir if( RET_OK == nBtn ) 251cdf0e10cSrcweir bPrintSelection = true; 252cdf0e10cSrcweir } 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir //#i61455# if master documentes are printed silently without loaded links then update the links now 256cdf0e10cSrcweir if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir pSh->GetLinkManager().UpdateAllLinks( sal_False, sal_False, sal_False, 0 ); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir SfxRequest aReq( rReq ); 261cdf0e10cSrcweir SfxBoolItem aBool(SID_SELECTION, bPrintSelection); 262cdf0e10cSrcweir aReq.AppendItem( aBool ); 263cdf0e10cSrcweir SfxViewShell::ExecuteSlot( aReq, SfxViewShell::GetInterface() ); 264cdf0e10cSrcweir return; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir default: 267870262e3SDon Lewis ASSERT(sal_False, "wrong dispatcher"); 268cdf0e10cSrcweir return; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir /*-------------------------------------------------------------------- 273cdf0e10cSrcweir Beschreibung: Page Drucker/Zusaetze erzeugen fuer SwView und 274cdf0e10cSrcweir SwPagePreview 275cdf0e10cSrcweir --------------------------------------------------------------------*/ 276cdf0e10cSrcweir 277cdf0e10cSrcweir SfxTabPage* CreatePrintOptionsPage( Window *pParent, 278cdf0e10cSrcweir const SfxItemSet &rOptions, sal_Bool bPreview ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir SfxTabPage* pPage = NULL; 281cdf0e10cSrcweir SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); 282cdf0e10cSrcweir if ( pFact ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( TP_OPTPRINT_PAGE ); 285cdf0e10cSrcweir if ( fnCreatePage ) 286cdf0e10cSrcweir pPage = (*fnCreatePage)( pParent, rOptions ); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir SfxAllItemSet aSet(*(rOptions.GetPool())); 289cdf0e10cSrcweir aSet.Put (SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview)); 290cdf0e10cSrcweir aSet.Put (SfxBoolItem(SID_FAX_LIST, sal_True)); 291cdf0e10cSrcweir pPage->PageCreated(aSet); 292cdf0e10cSrcweir return pPage; 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir 296cdf0e10cSrcweir void SetAppPrintOptions( ViewShell* pSh, sal_Bool bWeb ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir const IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess(); 299cdf0e10cSrcweir SwPrintData aPrtData = pIDDA->getPrintData(); 300cdf0e10cSrcweir 301cdf0e10cSrcweir if( pIDDA->getPrinter( false ) ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir // Applikationseigene Druckoptionen in SfxPrinter schiessen 304cdf0e10cSrcweir SwAddPrinterItem aAddPrinterItem (FN_PARAM_ADDPRINTER, aPrtData); 305cdf0e10cSrcweir SfxItemSet aSet( pSh->GetAttrPool(), 306cdf0e10cSrcweir FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER, 307cdf0e10cSrcweir SID_HTML_MODE, SID_HTML_MODE, 308cdf0e10cSrcweir SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN, 309cdf0e10cSrcweir SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC, 310cdf0e10cSrcweir 0 ); 311cdf0e10cSrcweir 312cdf0e10cSrcweir utl::MiscCfg aMisc; 313cdf0e10cSrcweir 314cdf0e10cSrcweir if(bWeb) 315cdf0e10cSrcweir aSet.Put(SfxUInt16Item(SID_HTML_MODE, 316cdf0e10cSrcweir ::GetHtmlMode(((SwWrtShell*)pSh)->GetView().GetDocShell()))); 317cdf0e10cSrcweir aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN, 318cdf0e10cSrcweir aMisc.IsNotFoundWarning() )); 319cdf0e10cSrcweir aSet.Put(aAddPrinterItem); 320cdf0e10cSrcweir aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC, 321cdf0e10cSrcweir (aMisc.IsPaperSizeWarning() ? SFX_PRINTER_CHG_SIZE : 0) | 322cdf0e10cSrcweir (aMisc.IsPaperOrientationWarning() ? SFX_PRINTER_CHG_ORIENTATION : 0 ))); 323cdf0e10cSrcweir 324cdf0e10cSrcweir pIDDA->getPrinter( true )->SetOptions( aSet ); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir } 328