bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uiview / viewprt.cxx
blobad8c60865d1e5a5d2d047dfec67f5dcf6c93c9f2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/text/NotePrintMode.hpp>
21 #include <cstdarg>
22 #include <cmdid.h>
23 #include <sfx2/request.hxx>
24 #include <sfx2/progress.hxx>
25 #include <sfx2/app.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <vcl/oldprintadaptor.hxx>
28 #include <sfx2/printer.hxx>
29 #include <sfx2/prnmon.hxx>
30 #include <editeng/paperinf.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <unotools/misccfg.hxx>
33 #include <svx/prtqry.hxx>
34 #include <svx/svdview.hxx>
35 #include <svl/eitem.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/intitem.hxx>
38 #include <svl/flagitem.hxx>
39 #include <sfx2/linkmgr.hxx>
41 #include <modcfg.hxx>
42 #include <edtwin.hxx>
43 #include <view.hxx>
44 #include <wrtsh.hxx>
45 #include <docsh.hxx>
46 #include <viewopt.hxx>
47 #include <prtopt.hxx>
48 #include <fontcfg.hxx>
49 #include <cfgitems.hxx>
50 #include <dbmgr.hxx>
51 #include <docstat.hxx>
52 #include <viewfunc.hxx>
53 #include <swmodule.hxx>
54 #include <wview.hxx>
55 #include <doc.hxx>
56 #include <fldbas.hxx>
58 #include <globals.hrc>
59 #include <view.hrc>
60 #include <app.hrc>
61 #include <swwrtshitem.hxx>
62 #include "swabstdlg.hxx"
63 #include <svl/slstitm.hxx>
65 #include <unomid.h>
67 using namespace ::com::sun::star;
69 /*--------------------------------------------------------------------
70 Beschreibung: Drucker an Sfx uebergeben
71 --------------------------------------------------------------------*/
72 SfxPrinter* SwView::GetPrinter( sal_Bool bCreate )
74 const IDocumentDeviceAccess* pIDDA = GetWrtShell().getIDocumentDeviceAccess();
75 SfxPrinter *pOld = pIDDA->getPrinter( false );
76 SfxPrinter *pPrt = pIDDA->getPrinter( bCreate );
77 if ( pOld != pPrt )
79 sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
80 ::SetAppPrintOptions( &GetWrtShell(), bWeb );
82 return pPrt;
85 /*--------------------------------------------------------------------
86 Beschreibung: Druckerwechsel weitermelden
87 --------------------------------------------------------------------*/
88 void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter* pNew, sal_Bool bWeb )
90 SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb);
91 if( !pOpt)
92 return;
94 // Applikationseigene Druckoptionen aus SfxPrinter auslesen
95 const SfxItemSet& rSet = pNew->GetOptions();
97 const SwAddPrinterItem* pAddPrinterAttr;
98 if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, sal_False,
99 (const SfxPoolItem**)&pAddPrinterAttr ) )
101 if( pIDDA )
102 pIDDA->setPrintData( *pAddPrinterAttr );
103 if( !pAddPrinterAttr->GetFax().isEmpty() )
104 pOpt->SetFaxName(pAddPrinterAttr->GetFax());
108 sal_uInt16 SwView::SetPrinter(SfxPrinter* pNew, sal_uInt16 nDiffFlags, bool )
110 SwWrtShell &rSh = GetWrtShell();
111 SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
112 if ( pOld && pOld->IsPrinting() )
113 return SFX_PRINTERROR_BUSY;
115 if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags )
117 rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
118 if ( nDiffFlags & SFX_PRINTER_PRINTER )
119 rSh.SetModified();
121 sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
122 if ( nDiffFlags & SFX_PRINTER_OPTIONS )
123 ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, bWeb );
125 const sal_Bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? sal_True : sal_False;
126 const sal_Bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? sal_True : sal_False;
127 if ( bChgOri || bChgSize )
129 rSh.StartAllAction();
130 if ( bChgOri )
131 rSh.ChgAllPageOrientation( sal_uInt16(pNew->GetOrientation()) );
132 if ( bChgSize )
134 Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
135 rSh.ChgAllPageSize( aSz );
137 rSh.SetModified();
138 rSh.EndAllAction();
139 InvalidateRulerPos();
141 return 0;
144 bool SwView::HasPrintOptionsPage() const
146 return true;
149 /*--------------------------------------------------------------------
150 Beschreibung: TabPage fuer applikationsspezifische Druckoptionen
151 --------------------------------------------------------------------*/
152 SfxTabPage* SwView::CreatePrintOptionsPage(Window* pParent,
153 const SfxItemSet& rSet)
155 return ::CreatePrintOptionsPage( pParent, rSet, sal_False );
158 /*--------------------------------------------------------------------
159 Beschreibung: Print-Dispatcher
160 --------------------------------------------------------------------*/
161 void SwView::ExecutePrint(SfxRequest& rReq)
163 sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
164 ::SetAppPrintOptions( &GetWrtShell(), bWeb );
165 switch (rReq.GetSlot())
167 case FN_FAX:
169 SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb);
170 String sFaxName(pPrintOptions->GetFaxName());
171 if (sFaxName.Len())
173 SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName);
174 SfxBoolItem aSilent( SID_SILENT, sal_True );
175 GetViewFrame()->GetDispatcher()->Execute( SID_PRINTDOC,
176 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
177 &aPrinterName, &aSilent, 0L );
179 else
181 InfoBox aInfoBox(&GetEditWin(), SW_RES(MSG_ERR_NO_FAX));
182 String sMsg = aInfoBox.GetMessText();
183 sal_uInt16 nResNo = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS;
184 sMsg.SearchAndReplace(OUString("%1"), String(SW_RES(nResNo)));
185 aInfoBox.SetMessText(sMsg);
186 aInfoBox.Execute();
187 SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE);
188 GetViewFrame()->GetDispatcher()->Execute(SID_SW_EDITOPTIONS,
189 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
190 &aDefPage, 0L );
193 break;
194 case SID_PRINTDOC:
195 case SID_PRINTDOCDIRECT:
197 SwWrtShell* pSh = &GetWrtShell();
198 SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
199 sal_Bool bSilent = pSilentItem ? pSilentItem->GetValue() : sal_False;
200 SFX_REQUEST_ARG(rReq, pPrintFromMergeItem, SfxBoolItem, FN_QRY_MERGE, sal_False);
201 if(pPrintFromMergeItem)
202 rReq.RemoveItem(FN_QRY_MERGE);
203 sal_Bool bFromMerge = pPrintFromMergeItem ? pPrintFromMergeItem->GetValue() : sal_False;
204 SwMiscConfig aMiscConfig;
205 bool bPrintSelection = false;
206 if(!bSilent && !bFromMerge &&
207 SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc())
209 QueryBox aBox( &GetEditWin(), SW_RES( MSG_PRINT_AS_MERGE ));
210 short nRet = aBox.Execute();
211 if(RET_YES == nRet)
213 SfxBoolItem aBool(FN_QRY_MERGE, sal_True);
214 GetViewFrame()->GetDispatcher()->Execute(
215 FN_QRY_MERGE, SFX_CALLMODE_ASYNCHRON, &aBool, 0L);
216 rReq.Ignore();
217 return;
220 else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent )
222 if( ( pSh->IsSelection() || pSh->IsFrmSelected() || pSh->IsObjSelected() ) )
224 short nBtn = SvxPrtQryBox(&GetEditWin()).Execute();
225 if( RET_CANCEL == nBtn )
226 return;
228 if( RET_OK == nBtn )
229 bPrintSelection = true;
233 //#i61455# if master documentes are printed silently without loaded links then update the links now
234 if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() )
236 pSh->GetLinkManager().UpdateAllLinks( false, false, false, 0 );
238 SfxRequest aReq( rReq );
239 SfxBoolItem aBool(SID_SELECTION, bPrintSelection);
240 aReq.AppendItem( aBool );
241 SfxViewShell::ExecuteSlot( aReq, SfxViewShell::GetInterface() );
242 return;
244 default:
245 OSL_ENSURE(!this, "wrong dispatcher");
246 return;
250 /*--------------------------------------------------------------------
251 Beschreibung: Page Drucker/Zusaetze erzeugen fuer SwView und
252 SwPagePreview
253 --------------------------------------------------------------------*/
254 SfxTabPage* CreatePrintOptionsPage( Window *pParent,
255 const SfxItemSet &rOptions, sal_Bool bPreview )
257 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
258 OSL_ENSURE(pFact, "No Print Dialog");
259 if (!pFact)
260 return NULL;
262 ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc(TP_OPTPRINT_PAGE);
263 OSL_ENSURE(pFact, "No Page Creator");
264 if (!fnCreatePage)
265 return NULL;
267 SfxTabPage* pPage = (*fnCreatePage)(pParent, rOptions);
268 OSL_ENSURE(pPage, "No page");
269 if (!pPage)
270 return NULL;
272 SfxAllItemSet aSet(*(rOptions.GetPool()));
273 aSet.Put(SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview));
274 aSet.Put(SfxBoolItem(SID_FAX_LIST, sal_True));
275 pPage->PageCreated(aSet);
276 return pPage;
279 void SetAppPrintOptions( ViewShell* pSh, sal_Bool bWeb )
281 const IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
282 SwPrintData aPrtData = pIDDA->getPrintData();
284 if( pIDDA->getPrinter( false ) )
286 // Applikationseigene Druckoptionen in SfxPrinter schiessen
287 SwAddPrinterItem aAddPrinterItem (FN_PARAM_ADDPRINTER, aPrtData);
288 SfxItemSet aSet( pSh->GetAttrPool(),
289 FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
290 SID_HTML_MODE, SID_HTML_MODE,
291 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
292 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
293 0 );
295 utl::MiscCfg aMisc;
297 if(bWeb)
298 aSet.Put(SfxUInt16Item(SID_HTML_MODE,
299 ::GetHtmlMode(((SwWrtShell*)pSh)->GetView().GetDocShell())));
300 aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN,
301 aMisc.IsNotFoundWarning() ));
302 aSet.Put(aAddPrinterItem);
303 aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC,
304 (aMisc.IsPaperSizeWarning() ? SFX_PRINTER_CHG_SIZE : 0) |
305 (aMisc.IsPaperOrientationWarning() ? SFX_PRINTER_CHG_ORIENTATION : 0 )));
307 pIDDA->getPrinter( true )->SetOptions( aSet );
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */