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