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