/src/libreoffice/sw/source/uibase/uiview/viewprt.cxx
Line | Count | Source |
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 <libxml/xmlwriter.h> |
21 | | #include <cmdid.h> |
22 | | #include <officecfg/Office/Common.hxx> |
23 | | #include <sfx2/docfile.hxx> |
24 | | #include <sfx2/request.hxx> |
25 | | #include <sfx2/viewfrm.hxx> |
26 | | #include <vcl/svapp.hxx> |
27 | | #include <vcl/stdtext.hxx> |
28 | | #include <vcl/weld/weld.hxx> |
29 | | #include <sfx2/printer.hxx> |
30 | | #include <editeng/paperinf.hxx> |
31 | | #include <sfx2/dispatch.hxx> |
32 | | #include <svx/dialmgr.hxx> |
33 | | #include <svx/strings.hrc> |
34 | | #include <svl/eitem.hxx> |
35 | | #include <svl/stritem.hxx> |
36 | | #include <svl/intitem.hxx> |
37 | | #include <svl/flagitem.hxx> |
38 | | #include <sfx2/linkmgr.hxx> |
39 | | #include <osl/diagnose.h> |
40 | | #include <svtools/colorcfg.hxx> |
41 | | #include <o3tl/unreachable.hxx> |
42 | | |
43 | | #include <modcfg.hxx> |
44 | | #include <edtwin.hxx> |
45 | | #include <view.hxx> |
46 | | #include <wrtsh.hxx> |
47 | | #include <viewopt.hxx> |
48 | | #include <prtopt.hxx> |
49 | | #include <cfgitems.hxx> |
50 | | #include "viewfunc.hxx" |
51 | | #include <swmodule.hxx> |
52 | | #include <wview.hxx> |
53 | | #include <IDocumentDeviceAccess.hxx> |
54 | | |
55 | | #include <globals.hrc> |
56 | | #include <strings.hrc> |
57 | | #include <swabstdlg.hxx> |
58 | | |
59 | | #include <uivwimp.hxx> |
60 | | |
61 | | using namespace ::com::sun::star; |
62 | | |
63 | | // Hand over the printer to Sfx |
64 | | |
65 | | SfxPrinter* SwView::GetPrinter( bool bCreate ) |
66 | 9.15k | { |
67 | 9.15k | const IDocumentDeviceAccess& rIDDA = GetWrtShell().getIDocumentDeviceAccess(); |
68 | 9.15k | SfxPrinter *pOld = rIDDA.getPrinter( false ); |
69 | 9.15k | SfxPrinter *pPrt = rIDDA.getPrinter( bCreate ); |
70 | 9.15k | if ( pOld != pPrt ) |
71 | 0 | { |
72 | 0 | bool bWeb = dynamic_cast<SwWebView*>(this) != nullptr; |
73 | 0 | ::SetAppPrintOptions( &GetWrtShell(), bWeb ); |
74 | 0 | } |
75 | 9.15k | return pPrt; |
76 | 9.15k | } |
77 | | |
78 | | // Propagate printer change |
79 | | |
80 | | void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter const * pNew, bool bWeb ) |
81 | 0 | { |
82 | 0 | SwPrintOptions* pOpt = SwModule::get()->GetPrtOptions(bWeb); |
83 | 0 | if( !pOpt) |
84 | 0 | return; |
85 | | |
86 | | // Reading Application own printing options from SfxPrinter |
87 | 0 | const SfxItemSet& rSet = pNew->GetOptions(); |
88 | |
|
89 | 0 | const SwAddPrinterItem* pAddPrinterAttr = |
90 | 0 | rSet.GetItemIfSet( FN_PARAM_ADDPRINTER, false ); |
91 | 0 | if( pAddPrinterAttr ) |
92 | 0 | { |
93 | 0 | if( pIDDA ) |
94 | 0 | pIDDA->setPrintData( *pAddPrinterAttr ); |
95 | 0 | if( !pAddPrinterAttr->GetFaxName().isEmpty() ) |
96 | 0 | pOpt->SetFaxName(pAddPrinterAttr->GetFaxName()); |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | sal_uInt16 SwView::SetPrinter(SfxPrinter* pNew, SfxPrinterChangeFlags nDiffFlags ) |
101 | 106 | { |
102 | 106 | SwWrtShell &rSh = GetWrtShell(); |
103 | 106 | SfxPrinter* pOld = rSh.getIDocumentDeviceAccess().getPrinter( false ); |
104 | 106 | if ( pOld && pOld->IsPrinting() ) |
105 | 0 | return SFX_PRINTERROR_BUSY; |
106 | | |
107 | 106 | if ( (SfxPrinterChangeFlags::JOBSETUP | SfxPrinterChangeFlags::PRINTER) & nDiffFlags ) |
108 | 106 | { |
109 | 106 | rSh.getIDocumentDeviceAccess().setPrinter( pNew, true, true ); |
110 | 106 | if ( nDiffFlags & SfxPrinterChangeFlags::PRINTER ) |
111 | 106 | rSh.SetModified(); |
112 | 106 | } |
113 | 106 | bool bWeb = dynamic_cast< const SwWebView *>( this ) != nullptr; |
114 | 106 | if ( nDiffFlags & SfxPrinterChangeFlags::OPTIONS ) |
115 | 0 | ::SetPrinter( &rSh.getIDocumentDeviceAccess(), pNew, bWeb ); |
116 | | |
117 | 106 | const bool bChgOri = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION); |
118 | 106 | const bool bChgSize = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE); |
119 | 106 | if ( bChgOri || bChgSize ) |
120 | 0 | { |
121 | 0 | rSh.StartAllAction(); |
122 | 0 | if ( bChgOri ) |
123 | 0 | rSh.ChgAllPageOrientation( pNew->GetOrientation() ); |
124 | 0 | if ( bChgSize ) |
125 | 0 | { |
126 | 0 | Size aSz( SvxPaperInfo::GetPaperSize( pNew ) ); |
127 | 0 | rSh.ChgAllPageSize( aSz ); |
128 | 0 | } |
129 | 0 | rSh.SetModified(); |
130 | 0 | rSh.EndAllAction(); |
131 | 0 | InvalidateRulerPos(); |
132 | 0 | } |
133 | 106 | return 0; |
134 | 106 | } |
135 | | |
136 | | bool SwView::HasPrintOptionsPage() const |
137 | 0 | { |
138 | 0 | return true; |
139 | 0 | } |
140 | | |
141 | | namespace |
142 | | { |
143 | | class SvxPrtQryBox |
144 | | { |
145 | | private: |
146 | | std::unique_ptr<weld::MessageDialog> m_xQueryBox; |
147 | | public: |
148 | | SvxPrtQryBox(weld::Window* pParent) |
149 | 0 | : m_xQueryBox(Application::CreateMessageDialog(pParent, VclMessageType::Question, VclButtonsType::NONE, SvxResId(RID_SVXSTR_QRY_PRINT_MSG))) |
150 | 0 | { |
151 | 0 | m_xQueryBox->set_title(SvxResId(RID_SVXSTR_QRY_PRINT_TITLE)); |
152 | |
|
153 | 0 | m_xQueryBox->add_button(SvxResId(RID_SVXSTR_QRY_PRINT_SELECTION), RET_OK); |
154 | 0 | m_xQueryBox->add_button(SvxResId(RID_SVXSTR_QRY_PRINT_ALL), 2); |
155 | 0 | m_xQueryBox->add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL); |
156 | 0 | m_xQueryBox->set_default_response(RET_OK); |
157 | 0 | } |
158 | 0 | short run() { return m_xQueryBox->run(); } |
159 | | }; |
160 | | } |
161 | | |
162 | | // TabPage for application-specific print options |
163 | | |
164 | | std::unique_ptr<SfxTabPage> SwView::CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController, |
165 | | const SfxItemSet& rSet) |
166 | 0 | { |
167 | 0 | return ::CreatePrintOptionsPage(pPage, pController, rSet, false); |
168 | 0 | } |
169 | | |
170 | | // Print dispatcher |
171 | | |
172 | | void SwView::ExecutePrint(SfxRequest& rReq) |
173 | 0 | { |
174 | 0 | bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr; |
175 | 0 | ::SetAppPrintOptions( &GetWrtShell(), bWeb ); |
176 | 0 | switch (rReq.GetSlot()) |
177 | 0 | { |
178 | 0 | case FN_FAX: |
179 | 0 | { |
180 | 0 | SwPrintOptions* pPrintOptions = SwModule::get()->GetPrtOptions(bWeb); |
181 | 0 | const OUString& sFaxName(pPrintOptions->GetFaxName()); |
182 | 0 | if (!sFaxName.isEmpty()) |
183 | 0 | { |
184 | 0 | SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName); |
185 | 0 | SfxBoolItem aSilent( SID_SILENT, true ); |
186 | 0 | GetViewFrame().GetDispatcher()->ExecuteList(SID_PRINTDOC, |
187 | 0 | SfxCallMode::SYNCHRON|SfxCallMode::RECORD, |
188 | 0 | { &aPrinterName, &aSilent }); |
189 | 0 | } |
190 | 0 | else |
191 | 0 | { |
192 | 0 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetEditWin().GetFrameWeld(), |
193 | 0 | VclMessageType::Info, VclButtonsType::Ok, |
194 | 0 | SwResId(STR_ERR_NO_FAX))); |
195 | 0 | TranslateId pResId = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS; |
196 | 0 | xInfoBox->set_primary_text(xInfoBox->get_primary_text().replaceFirst("%1", SwResId(pResId))); |
197 | 0 | xInfoBox->run(); |
198 | 0 | SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE); |
199 | 0 | GetViewFrame().GetDispatcher()->ExecuteList(SID_SW_EDITOPTIONS, |
200 | 0 | SfxCallMode::SYNCHRON|SfxCallMode::RECORD, |
201 | 0 | { &aDefPage }); |
202 | 0 | } |
203 | 0 | } |
204 | 0 | break; |
205 | 0 | case SID_PRINTDOC: |
206 | 0 | case SID_PRINTDOCDIRECT: |
207 | 0 | { |
208 | 0 | SwWrtShell* pSh = &GetWrtShell(); |
209 | 0 | const SfxBoolItem* pSilentItem = rReq.GetArg(SID_SILENT); |
210 | 0 | bool bSilent = pSilentItem && pSilentItem->GetValue(); |
211 | 0 | const SfxBoolItem* pPrintFromMergeItem = rReq.GetArg<SfxBoolItem>(FN_QRY_MERGE); |
212 | 0 | if(pPrintFromMergeItem) |
213 | 0 | rReq.RemoveItem(FN_QRY_MERGE); |
214 | 0 | bool bFromMerge = pPrintFromMergeItem && pPrintFromMergeItem->GetValue(); |
215 | 0 | bool bPrintSelection = false; |
216 | 0 | if(!bSilent && !bFromMerge && |
217 | 0 | SwModule::get()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc()) |
218 | 0 | { |
219 | 0 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetEditWin().GetFrameWeld(), u"modules/swriter/ui/printmergedialog.ui"_ustr)); |
220 | 0 | std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog(u"PrintMergeDialog"_ustr)); |
221 | 0 | short nRet = xBox->run(); |
222 | 0 | if(RET_NO != nRet) |
223 | 0 | { |
224 | 0 | if(RET_YES == nRet) |
225 | 0 | { |
226 | 0 | SfxBoolItem aBool(FN_QRY_MERGE, true); |
227 | 0 | GetViewFrame().GetDispatcher()->ExecuteList( |
228 | 0 | FN_QRY_MERGE, SfxCallMode::ASYNCHRON, |
229 | 0 | { &aBool }); |
230 | 0 | rReq.Ignore(); |
231 | 0 | } |
232 | 0 | return; |
233 | 0 | } |
234 | 0 | } |
235 | 0 | else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent ) |
236 | 0 | { |
237 | 0 | if( pSh->IsSelection() || pSh->IsFrameSelected() || pSh->GetSelectedObjCount() ) |
238 | 0 | { |
239 | 0 | SvxPrtQryBox aBox(GetEditWin().GetFrameWeld()); |
240 | 0 | short nBtn = aBox.run(); |
241 | 0 | if( RET_CANCEL == nBtn ) |
242 | 0 | return; |
243 | | |
244 | 0 | if( RET_OK == nBtn ) |
245 | 0 | bPrintSelection = true; |
246 | 0 | } |
247 | 0 | } |
248 | | |
249 | | //#i61455# if master documents are printed silently without loaded links then update the links now |
250 | 0 | if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() ) |
251 | 0 | { |
252 | 0 | SfxMedium * medium = nullptr; |
253 | 0 | if (auto const sh = pSh->GetDoc()->GetDocShell()) { |
254 | 0 | medium = sh->GetMedium(); |
255 | 0 | } |
256 | 0 | pSh->GetLinkManager().UpdateAllLinks( |
257 | 0 | false, false, nullptr, medium == nullptr ? OUString() : medium->GetName() ); |
258 | 0 | } |
259 | 0 | SfxRequest aReq( rReq ); |
260 | 0 | SfxBoolItem aBool(SID_SELECTION, bPrintSelection); |
261 | 0 | aReq.AppendItem( aBool ); |
262 | 0 | SfxViewShell::ExecuteSlot( aReq, SfxViewShell::GetInterface() ); |
263 | 0 | return; |
264 | 0 | } |
265 | 0 | default: |
266 | 0 | OSL_ENSURE(false, "wrong dispatcher"); |
267 | 0 | return; |
268 | 0 | } |
269 | 0 | } |
270 | | |
271 | | int SwView::getPart() const |
272 | 0 | { |
273 | 0 | return 0; |
274 | 0 | } |
275 | | |
276 | | void SwView::dumpAsXml(xmlTextWriterPtr pWriter) const |
277 | 0 | { |
278 | 0 | (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwView")); |
279 | 0 | SfxViewShell::dumpAsXml(pWriter); |
280 | 0 | if (m_pWrtShell) |
281 | 0 | m_pWrtShell->dumpAsXml(pWriter); |
282 | 0 | (void)xmlTextWriterEndElement(pWriter); |
283 | 0 | } |
284 | | |
285 | | void SwView::SetRedlineAuthor(const OUString& rAuthor) |
286 | 0 | { |
287 | 0 | m_pViewImpl->m_sRedlineAuthor = rAuthor; |
288 | 0 | } |
289 | | |
290 | | const OUString& SwView::GetRedlineAuthor() const |
291 | 9.15k | { |
292 | 9.15k | return m_pViewImpl->m_sRedlineAuthor; |
293 | 9.15k | } |
294 | | |
295 | | void SwView::NotifyCursor(SfxViewShell* pViewShell) const |
296 | 0 | { |
297 | 0 | m_pWrtShell->NotifyCursor(pViewShell); |
298 | 0 | } |
299 | | |
300 | | ::Color SwView::GetColorConfigColor(svtools::ColorConfigEntry nColorType) const |
301 | 251k | { |
302 | 251k | if (const SwViewOption* pViewOptions = GetWrtShell().GetViewOptions()) |
303 | 251k | { |
304 | 251k | switch (nColorType) |
305 | 251k | { |
306 | 251k | case svtools::ColorConfigEntry::DOCCOLOR: |
307 | 251k | { |
308 | 251k | return pViewOptions->GetDocColor(); |
309 | 0 | } |
310 | | // Should never be called for an unimplemented color type |
311 | 0 | default: |
312 | 0 | { |
313 | 0 | O3TL_UNREACHABLE; |
314 | 0 | } |
315 | 251k | } |
316 | 251k | } |
317 | 0 | else |
318 | 0 | { |
319 | 0 | SAL_WARN("sw", "GetViewOptions() returned nullptr"); |
320 | 0 | } |
321 | | |
322 | 0 | return {}; |
323 | 251k | } |
324 | | |
325 | | // Create page printer/additions for SwView and SwPagePreview |
326 | | |
327 | | std::unique_ptr<SfxTabPage> CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController, |
328 | | const SfxItemSet &rOptions, |
329 | | bool bPreview) |
330 | 0 | { |
331 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
332 | |
|
333 | 0 | ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc(TP_OPTPRINT_PAGE); |
334 | 0 | OSL_ENSURE(pFact, "No Page Creator"); |
335 | 0 | if (!fnCreatePage) |
336 | 0 | return nullptr; |
337 | | |
338 | 0 | std::unique_ptr<SfxTabPage> xSfxPage = fnCreatePage(pPage, pController, &rOptions); |
339 | 0 | OSL_ENSURE(xSfxPage, "No page"); |
340 | 0 | if (!xSfxPage) |
341 | 0 | return nullptr; |
342 | | |
343 | 0 | SfxAllItemSet aSet(*(rOptions.GetPool())); |
344 | 0 | aSet.Put(SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview)); |
345 | 0 | aSet.Put(SfxBoolItem(SID_FAX_LIST, true)); |
346 | 0 | xSfxPage->PageCreated(aSet); |
347 | 0 | return xSfxPage; |
348 | 0 | } |
349 | | |
350 | | void SetAppPrintOptions( SwViewShell* pSh, bool bWeb ) |
351 | 0 | { |
352 | 0 | const IDocumentDeviceAccess& rIDDA = pSh->getIDocumentDeviceAccess(); |
353 | 0 | const SwPrintData& aPrtData = rIDDA.getPrintData(); |
354 | |
|
355 | 0 | if( !rIDDA.getPrinter( false ) ) |
356 | 0 | return; |
357 | | |
358 | | // Close application own printing options in SfxPrinter. |
359 | 0 | SwAddPrinterItem aAddPrinterItem(aPrtData); |
360 | 0 | SfxItemSetFixed< |
361 | 0 | SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN, |
362 | 0 | SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC, |
363 | 0 | SID_HTML_MODE, SID_HTML_MODE, |
364 | 0 | FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER> aSet( pSh->GetAttrPool() ); |
365 | |
|
366 | 0 | if(bWeb) |
367 | 0 | aSet.Put(SfxUInt16Item(SID_HTML_MODE, |
368 | 0 | ::GetHtmlMode(static_cast<SwWrtShell*>(pSh)->GetView().GetDocShell()))); |
369 | 0 | aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN, |
370 | 0 | officecfg::Office::Common::Print::Warning::NotFound::get() )); |
371 | 0 | aSet.Put(aAddPrinterItem); |
372 | 0 | aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC, |
373 | 0 | static_cast<int>(officecfg::Office::Common::Print::Warning::PaperSize::get() |
374 | 0 | ? SfxPrinterChangeFlags::CHG_SIZE : SfxPrinterChangeFlags::NONE) | |
375 | 0 | static_cast<int>(officecfg::Office::Common::Print::Warning::PaperOrientation::get() |
376 | 0 | ? SfxPrinterChangeFlags::CHG_ORIENTATION : SfxPrinterChangeFlags::NONE ))); |
377 | |
|
378 | 0 | rIDDA.getPrinter( true )->SetOptions( aSet ); |
379 | |
|
380 | 0 | } |
381 | | |
382 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |