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