Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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/layout.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>
40 :
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>
57 : #include <IDocumentDeviceAccess.hxx>
58 :
59 : #include <globals.hrc>
60 : #include <view.hrc>
61 : #include <app.hrc>
62 : #include <swwrtshitem.hxx>
63 : #include "swabstdlg.hxx"
64 : #include <svl/slstitm.hxx>
65 :
66 : #include <unomid.h>
67 :
68 : using namespace ::com::sun::star;
69 :
70 : // Hand over the printer to Sfx
71 :
72 8119 : SfxPrinter* SwView::GetPrinter( bool bCreate )
73 : {
74 8119 : const IDocumentDeviceAccess* pIDDA = GetWrtShell().getIDocumentDeviceAccess();
75 8119 : SfxPrinter *pOld = pIDDA->getPrinter( false );
76 8119 : SfxPrinter *pPrt = pIDDA->getPrinter( bCreate );
77 8119 : if ( pOld != pPrt )
78 : {
79 0 : bool bWeb = 0 != dynamic_cast<SwWebView*>(this);
80 0 : ::SetAppPrintOptions( &GetWrtShell(), bWeb );
81 : }
82 8119 : return pPrt;
83 : }
84 :
85 : // Propagate printer change
86 :
87 0 : void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter* pNew, bool bWeb )
88 : {
89 0 : SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb);
90 0 : if( !pOpt)
91 0 : return;
92 :
93 : // Reading Application own printing options from SfxPrinter
94 0 : const SfxItemSet& rSet = pNew->GetOptions();
95 :
96 : const SwAddPrinterItem* pAddPrinterAttr;
97 0 : if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, false,
98 0 : reinterpret_cast<const SfxPoolItem**>(&pAddPrinterAttr) ) )
99 : {
100 0 : if( pIDDA )
101 0 : pIDDA->setPrintData( *pAddPrinterAttr );
102 0 : if( !pAddPrinterAttr->GetFax().isEmpty() )
103 0 : pOpt->SetFaxName(pAddPrinterAttr->GetFax());
104 : }
105 : }
106 :
107 1 : sal_uInt16 SwView::SetPrinter(SfxPrinter* pNew, SfxPrinterChangeFlags nDiffFlags, bool )
108 : {
109 1 : SwWrtShell &rSh = GetWrtShell();
110 1 : SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
111 1 : if ( pOld && pOld->IsPrinting() )
112 0 : return SFX_PRINTERROR_BUSY;
113 :
114 1 : if ( (SfxPrinterChangeFlags::JOBSETUP | SfxPrinterChangeFlags::PRINTER) & nDiffFlags )
115 : {
116 1 : rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
117 1 : if ( nDiffFlags & SfxPrinterChangeFlags::PRINTER )
118 1 : rSh.SetModified();
119 : }
120 1 : bool bWeb = this->ISA(SwWebView);
121 1 : if ( nDiffFlags & SfxPrinterChangeFlags::OPTIONS )
122 0 : ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, bWeb );
123 :
124 1 : const bool bChgOri = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION);
125 1 : const bool bChgSize = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE);
126 1 : if ( bChgOri || bChgSize )
127 : {
128 0 : rSh.StartAllAction();
129 0 : if ( bChgOri )
130 0 : rSh.ChgAllPageOrientation( pNew->GetOrientation() );
131 0 : if ( bChgSize )
132 : {
133 0 : Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
134 0 : rSh.ChgAllPageSize( aSz );
135 : }
136 0 : rSh.SetModified();
137 0 : rSh.EndAllAction();
138 0 : InvalidateRulerPos();
139 : }
140 1 : return 0;
141 : }
142 :
143 0 : bool SwView::HasPrintOptionsPage() const
144 : {
145 0 : return true;
146 : }
147 :
148 : // TabPage for application-specific print options
149 :
150 0 : VclPtr<SfxTabPage> SwView::CreatePrintOptionsPage(vcl::Window* pParent,
151 : const SfxItemSet& rSet)
152 : {
153 0 : return ::CreatePrintOptionsPage( pParent, rSet, false );
154 : }
155 :
156 : // Print dispatcher
157 :
158 0 : void SwView::ExecutePrint(SfxRequest& rReq)
159 : {
160 0 : bool bWeb = 0 != PTR_CAST(SwWebView, this);
161 0 : ::SetAppPrintOptions( &GetWrtShell(), bWeb );
162 0 : switch (rReq.GetSlot())
163 : {
164 : case FN_FAX:
165 : {
166 0 : SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb);
167 0 : OUString sFaxName(pPrintOptions->GetFaxName());
168 0 : if (!sFaxName.isEmpty())
169 : {
170 0 : SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName);
171 0 : SfxBoolItem aSilent( SID_SILENT, true );
172 : GetViewFrame()->GetDispatcher()->Execute( SID_PRINTDOC,
173 : SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
174 0 : &aPrinterName, &aSilent, 0L );
175 : }
176 : else
177 : {
178 0 : ScopedVclPtrInstance< MessageDialog > aInfoBox(&GetEditWin(), SW_RES(STR_ERR_NO_FAX), VCL_MESSAGE_INFO);
179 0 : sal_uInt16 nResNo = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS;
180 0 : aInfoBox->set_primary_text(aInfoBox->get_primary_text().replaceFirst("%1", OUString(SW_RES(nResNo))));
181 0 : aInfoBox->Execute();
182 0 : SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE);
183 : GetViewFrame()->GetDispatcher()->Execute(SID_SW_EDITOPTIONS,
184 : SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
185 0 : &aDefPage, 0L );
186 0 : }
187 : }
188 0 : break;
189 : case SID_PRINTDOC:
190 : case SID_PRINTDOCDIRECT:
191 : {
192 0 : SwWrtShell* pSh = &GetWrtShell();
193 0 : SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, false);
194 0 : bool bSilent = pSilentItem && pSilentItem->GetValue();
195 0 : SFX_REQUEST_ARG(rReq, pPrintFromMergeItem, SfxBoolItem, FN_QRY_MERGE, false);
196 0 : if(pPrintFromMergeItem)
197 0 : rReq.RemoveItem(FN_QRY_MERGE);
198 0 : bool bFromMerge = pPrintFromMergeItem && pPrintFromMergeItem->GetValue();
199 0 : SwMiscConfig aMiscConfig;
200 0 : bool bPrintSelection = false;
201 0 : if(!bSilent && !bFromMerge &&
202 0 : SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc())
203 : {
204 0 : ScopedVclPtrInstance<MessageDialog> aBox(&GetEditWin(), "PrintMergeDialog",
205 0 : "modules/swriter/ui/printmergedialog.ui");
206 0 : short nRet = aBox->Execute();
207 0 : if(RET_YES == nRet)
208 : {
209 0 : SfxBoolItem aBool(FN_QRY_MERGE, true);
210 : GetViewFrame()->GetDispatcher()->Execute(
211 0 : FN_QRY_MERGE, SfxCallMode::ASYNCHRON, &aBool, 0L);
212 0 : rReq.Ignore();
213 0 : return;
214 0 : }
215 : }
216 0 : else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent )
217 : {
218 0 : if( ( pSh->IsSelection() || pSh->IsFrmSelected() || pSh->IsObjSelected() ) )
219 : {
220 0 : short nBtn = ScopedVclPtr<SvxPrtQryBox>::Create(&GetEditWin())->Execute();
221 0 : if( RET_CANCEL == nBtn )
222 0 : return;
223 :
224 0 : if( RET_OK == nBtn )
225 0 : bPrintSelection = true;
226 : }
227 : }
228 :
229 : //#i61455# if master documentes are printed silently without loaded links then update the links now
230 0 : if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() )
231 : {
232 0 : pSh->GetLinkManager().UpdateAllLinks( false, false, false, 0 );
233 : }
234 0 : SfxRequest aReq( rReq );
235 0 : SfxBoolItem aBool(SID_SELECTION, bPrintSelection);
236 0 : aReq.AppendItem( aBool );
237 0 : SfxViewShell::ExecuteSlot( aReq, SfxViewShell::GetInterface() );
238 0 : return;
239 : }
240 : default:
241 : OSL_ENSURE(false, "wrong dispatcher");
242 0 : return;
243 : }
244 : }
245 :
246 : // Create page printer/additions for SwView and SwPagePreview
247 :
248 0 : VclPtr<SfxTabPage> CreatePrintOptionsPage( vcl::Window *pParent,
249 : const SfxItemSet &rOptions,
250 : bool bPreview )
251 : {
252 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
253 : OSL_ENSURE(pFact, "No Print Dialog");
254 0 : if (!pFact)
255 0 : return NULL;
256 :
257 0 : ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc(TP_OPTPRINT_PAGE);
258 : OSL_ENSURE(pFact, "No Page Creator");
259 0 : if (!fnCreatePage)
260 0 : return NULL;
261 :
262 0 : VclPtr<SfxTabPage> pPage = fnCreatePage(pParent, &rOptions);
263 : OSL_ENSURE(pPage, "No page");
264 0 : if (!pPage)
265 0 : return NULL;
266 :
267 0 : SfxAllItemSet aSet(*(rOptions.GetPool()));
268 0 : aSet.Put(SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview));
269 0 : aSet.Put(SfxBoolItem(SID_FAX_LIST, true));
270 0 : pPage->PageCreated(aSet);
271 0 : return pPage;
272 : }
273 :
274 0 : void SetAppPrintOptions( SwViewShell* pSh, bool bWeb )
275 : {
276 0 : const IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
277 0 : SwPrintData aPrtData = pIDDA->getPrintData();
278 :
279 0 : if( pIDDA->getPrinter( false ) )
280 : {
281 : // Close application own printing options in SfxPrinter.
282 0 : SwAddPrinterItem aAddPrinterItem (FN_PARAM_ADDPRINTER, aPrtData);
283 0 : SfxItemSet aSet( pSh->GetAttrPool(),
284 : FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
285 : SID_HTML_MODE, SID_HTML_MODE,
286 : SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
287 : SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
288 0 : 0 );
289 :
290 0 : utl::MiscCfg aMisc;
291 :
292 0 : if(bWeb)
293 : aSet.Put(SfxUInt16Item(SID_HTML_MODE,
294 0 : ::GetHtmlMode(static_cast<SwWrtShell*>(pSh)->GetView().GetDocShell())));
295 : aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN,
296 0 : aMisc.IsNotFoundWarning() ));
297 0 : aSet.Put(aAddPrinterItem);
298 : aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC,
299 0 : static_cast<int>(aMisc.IsPaperSizeWarning() ? SfxPrinterChangeFlags::CHG_SIZE : SfxPrinterChangeFlags::NONE) |
300 0 : static_cast<int>(aMisc.IsPaperOrientationWarning() ? SfxPrinterChangeFlags::CHG_ORIENTATION : SfxPrinterChangeFlags::NONE )));
301 :
302 0 : pIDDA->getPrinter( true )->SetOptions( aSet );
303 0 : }
304 :
305 177 : }
306 :
307 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|