LibreOffice Module sw (master) 1
viewprt.cxx
Go to the documentation of this file.
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/request.hxx>
24#include <sfx2/viewfrm.hxx>
25#include <vcl/svapp.hxx>
26#include <vcl/stdtext.hxx>
27#include <vcl/weld.hxx>
28#include <sfx2/printer.hxx>
29#include <editeng/paperinf.hxx>
30#include <sfx2/dispatch.hxx>
31#include <svx/dialmgr.hxx>
32#include <svx/strings.hrc>
33#include <svl/eitem.hxx>
34#include <svl/stritem.hxx>
35#include <svl/intitem.hxx>
36#include <svl/flagitem.hxx>
37#include <sfx2/linkmgr.hxx>
38#include <osl/diagnose.h>
39#include <svtools/colorcfg.hxx>
40#include <o3tl/unreachable.hxx>
41
42#include <modcfg.hxx>
43#include <edtwin.hxx>
44#include <view.hxx>
45#include <wrtsh.hxx>
46#include <viewopt.hxx>
47#include <prtopt.hxx>
48#include <cfgitems.hxx>
49#include "viewfunc.hxx"
50#include <swmodule.hxx>
51#include <wview.hxx>
53
54#include <globals.hrc>
55#include <strings.hrc>
56#include <swabstdlg.hxx>
57
58#include <uivwimp.hxx>
59
60using namespace ::com::sun::star;
61
62// Hand over the printer to Sfx
63
65{
67 SfxPrinter *pOld = rIDDA.getPrinter( false );
68 SfxPrinter *pPrt = rIDDA.getPrinter( bCreate );
69 if ( pOld != pPrt )
70 {
71 bool bWeb = dynamic_cast<SwWebView*>(this) != nullptr;
73 }
74 return pPrt;
75}
76
77// Propagate printer change
78
79void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter const * pNew, bool bWeb )
80{
81 SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb);
82 if( !pOpt)
83 return;
84
85 // Reading Application own printing options from SfxPrinter
86 const SfxItemSet& rSet = pNew->GetOptions();
87
88 const SwAddPrinterItem* pAddPrinterAttr =
90 if( pAddPrinterAttr )
91 {
92 if( pIDDA )
93 pIDDA->setPrintData( *pAddPrinterAttr );
94 if( !pAddPrinterAttr->GetFaxName().isEmpty() )
95 pOpt->SetFaxName(pAddPrinterAttr->GetFaxName());
96 }
97}
98
100{
101 SwWrtShell &rSh = GetWrtShell();
102 SfxPrinter* pOld = rSh.getIDocumentDeviceAccess().getPrinter( false );
103 if ( pOld && pOld->IsPrinting() )
104 return SFX_PRINTERROR_BUSY;
105
106 if ( (SfxPrinterChangeFlags::JOBSETUP | SfxPrinterChangeFlags::PRINTER) & nDiffFlags )
107 {
108 rSh.getIDocumentDeviceAccess().setPrinter( pNew, true, true );
109 if ( nDiffFlags & SfxPrinterChangeFlags::PRINTER )
110 rSh.SetModified();
111 }
112 bool bWeb = dynamic_cast< const SwWebView *>( this ) != nullptr;
113 if ( nDiffFlags & SfxPrinterChangeFlags::OPTIONS )
114 ::SetPrinter( &rSh.getIDocumentDeviceAccess(), pNew, bWeb );
115
116 const bool bChgOri = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION);
117 const bool bChgSize = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE);
118 if ( bChgOri || bChgSize )
119 {
120 rSh.StartAllAction();
121 if ( bChgOri )
122 rSh.ChgAllPageOrientation( pNew->GetOrientation() );
123 if ( bChgSize )
124 {
125 Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
126 rSh.ChgAllPageSize( aSz );
127 }
128 rSh.SetModified();
129 rSh.EndAllAction();
131 }
132 return 0;
133}
134
136{
137 return true;
138}
139
140namespace
141{
142 class SvxPrtQryBox
143 {
144 private:
145 std::unique_ptr<weld::MessageDialog> m_xQueryBox;
146 public:
147 SvxPrtQryBox(weld::Window* pParent)
148 : m_xQueryBox(Application::CreateMessageDialog(pParent, VclMessageType::Question, VclButtonsType::NONE, SvxResId(RID_SVXSTR_QRY_PRINT_MSG)))
149 {
150 m_xQueryBox->set_title(SvxResId(RID_SVXSTR_QRY_PRINT_TITLE));
151
152 m_xQueryBox->add_button(SvxResId(RID_SVXSTR_QRY_PRINT_SELECTION), RET_OK);
153 m_xQueryBox->add_button(SvxResId(RID_SVXSTR_QRY_PRINT_ALL), 2);
154 m_xQueryBox->add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
155 m_xQueryBox->set_default_response(RET_OK);
156 }
157 short run() { return m_xQueryBox->run(); }
158 };
159}
160
161// TabPage for application-specific print options
162
163std::unique_ptr<SfxTabPage> SwView::CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController,
164 const SfxItemSet& rSet)
165{
166 return ::CreatePrintOptionsPage(pPage, pController, rSet, false);
167}
168
169// Print dispatcher
170
172{
173 bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
175 switch (rReq.GetSlot())
176 {
177 case FN_FAX:
178 {
179 SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb);
180 const OUString& sFaxName(pPrintOptions->GetFaxName());
181 if (!sFaxName.isEmpty())
182 {
183 SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName);
184 SfxBoolItem aSilent( SID_SILENT, true );
185 GetViewFrame().GetDispatcher()->ExecuteList(SID_PRINTDOC,
186 SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
187 { &aPrinterName, &aSilent });
188 }
189 else
190 {
191 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetEditWin().GetFrameWeld(),
192 VclMessageType::Info, VclButtonsType::Ok,
193 SwResId(STR_ERR_NO_FAX)));
194 TranslateId pResId = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS;
195 xInfoBox->set_primary_text(xInfoBox->get_primary_text().replaceFirst("%1", SwResId(pResId)));
196 xInfoBox->run();
197 SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE);
198 GetViewFrame().GetDispatcher()->ExecuteList(SID_SW_EDITOPTIONS,
199 SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
200 { &aDefPage });
201 }
202 }
203 break;
204 case SID_PRINTDOC:
205 case SID_PRINTDOCDIRECT:
206 {
207 SwWrtShell* pSh = &GetWrtShell();
208 const SfxBoolItem* pSilentItem = rReq.GetArg<SfxBoolItem>(SID_SILENT);
209 bool bSilent = pSilentItem && pSilentItem->GetValue();
210 const SfxBoolItem* pPrintFromMergeItem = rReq.GetArg<SfxBoolItem>(FN_QRY_MERGE);
211 if(pPrintFromMergeItem)
213 bool bFromMerge = pPrintFromMergeItem && pPrintFromMergeItem->GetValue();
214 bool bPrintSelection = false;
215 if(!bSilent && !bFromMerge &&
216 SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc())
217 {
218 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetEditWin().GetFrameWeld(), "modules/swriter/ui/printmergedialog.ui"));
219 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("PrintMergeDialog"));
220 short nRet = xBox->run();
221 if(RET_NO != nRet)
222 {
223 if(RET_YES == nRet)
224 {
225 SfxBoolItem aBool(FN_QRY_MERGE, true);
227 FN_QRY_MERGE, SfxCallMode::ASYNCHRON,
228 { &aBool });
229 rReq.Ignore();
230 }
231 return;
232 }
233 }
234 else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent )
235 {
236 if( pSh->IsSelection() || pSh->IsFrameSelected() || pSh->IsObjSelected() )
237 {
238 SvxPrtQryBox aBox(GetEditWin().GetFrameWeld());
239 short nBtn = aBox.run();
240 if( RET_CANCEL == nBtn )
241 return;
242
243 if( RET_OK == nBtn )
244 bPrintSelection = true;
245 }
246 }
247
248 //#i61455# if master documents are printed silently without loaded links then update the links now
249 if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() )
250 {
251 pSh->GetLinkManager().UpdateAllLinks( false, false, nullptr );
252 }
253 SfxRequest aReq( rReq );
254 SfxBoolItem aBool(SID_SELECTION, bPrintSelection);
255 aReq.AppendItem( aBool );
257 return;
258 }
259 default:
260 OSL_ENSURE(false, "wrong dispatcher");
261 return;
262 }
263}
264
266{
267 return 0;
268}
269
271{
272 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwView"));
274 if (m_pWrtShell)
275 m_pWrtShell->dumpAsXml(pWriter);
276 (void)xmlTextWriterEndElement(pWriter);
277}
278
279void SwView::SetRedlineAuthor(const OUString& rAuthor)
280{
281 m_pViewImpl->m_sRedlineAuthor = rAuthor;
282}
283
284const OUString& SwView::GetRedlineAuthor() const
285{
286 return m_pViewImpl->m_sRedlineAuthor;
287}
288
289void SwView::NotifyCursor(SfxViewShell* pViewShell) const
290{
291 m_pWrtShell->NotifyCursor(pViewShell);
292}
293
295{
296 if (const SwViewOption* pViewOptions = GetWrtShell().GetViewOptions())
297 {
298 switch (nColorType)
299 {
300 case svtools::ColorConfigEntry::DOCCOLOR:
301 {
302 return pViewOptions->GetDocColor();
303 }
304 // Should never be called for an unimplemented color type
305 default:
306 {
308 }
309 }
310 }
311 else
312 {
313 SAL_WARN("sw", "GetViewOptions() returned nullptr");
314 }
315
316 return {};
317}
318
320{
321 if (const SwViewOption* pViewOptions = GetWrtShell().GetViewOptions())
322 {
323 return pViewOptions->GetThemeName();
324 }
325 else
326 {
327 SAL_WARN("sw", "GetViewOptions() returned nullptr");
328 }
329
330 return {};
331}
332
333// Create page printer/additions for SwView and SwPagePreview
334
335std::unique_ptr<SfxTabPage> CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController,
336 const SfxItemSet &rOptions,
337 bool bPreview)
338{
340
341 ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc(TP_OPTPRINT_PAGE);
342 OSL_ENSURE(pFact, "No Page Creator");
343 if (!fnCreatePage)
344 return nullptr;
345
346 std::unique_ptr<SfxTabPage> xSfxPage = fnCreatePage(pPage, pController, &rOptions);
347 OSL_ENSURE(xSfxPage, "No page");
348 if (!xSfxPage)
349 return nullptr;
350
351 SfxAllItemSet aSet(*(rOptions.GetPool()));
352 aSet.Put(SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview));
353 aSet.Put(SfxBoolItem(SID_FAX_LIST, true));
354 xSfxPage->PageCreated(aSet);
355 return xSfxPage;
356}
357
358void SetAppPrintOptions( SwViewShell* pSh, bool bWeb )
359{
361 const SwPrintData& aPrtData = rIDDA.getPrintData();
362
363 if( !rIDDA.getPrinter( false ) )
364 return;
365
366 // Close application own printing options in SfxPrinter.
367 SwAddPrinterItem aAddPrinterItem(aPrtData);
369 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
370 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
371 SID_HTML_MODE, SID_HTML_MODE,
373
374 if(bWeb)
375 aSet.Put(SfxUInt16Item(SID_HTML_MODE,
376 ::GetHtmlMode(static_cast<SwWrtShell*>(pSh)->GetView().GetDocShell())));
377 aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN,
379 aSet.Put(aAddPrinterItem);
380 aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC,
382 ? SfxPrinterChangeFlags::CHG_SIZE : SfxPrinterChangeFlags::NONE) |
384 ? SfxPrinterChangeFlags::CHG_ORIENTATION : SfxPrinterChangeFlags::NONE )));
385
386 rIDDA.getPrinter( true )->SetOptions( aSet );
387
388}
389
390/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::MessageDialog > m_xQueryBox
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
Provides access to the formatting devices of a document.
virtual SfxPrinter * getPrinter(bool bCreate) const =0
Return the printer set at the document.
virtual void setPrintData(const SwPrintData &rPrtData)=0
Sets the PrintData.
virtual void setPrinter(SfxPrinter *pP, bool bDeleteOld, bool bCallPrtDataChanged)=0
Set the printer at the document.
virtual const SwPrintData & getPrintData() const =0
Returns the PrintData.
bool GetValue() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SfxItemPool * GetPool() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetOptions(const SfxItemSet &rNewOptions)
const SfxItemSet & GetOptions() const
sal_uInt16 GetSlot() const
void RemoveItem(sal_uInt16 nSlotId)
void Ignore()
const T * GetArg(sal_uInt16 nSlotId) const
void AppendItem(const SfxPoolItem &)
virtual SfxInterface * GetInterface() const
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
SfxDispatcher * GetDispatcher()
weld::Window * GetFrameWeld() const
SfxViewFrame & GetViewFrame() const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
static Size GetPaperSize(Paper ePaper, MapUnit eUnit=MapUnit::MapTwip)
virtual CreateTabPage GetTabPageCreatorFunc(sal_uInt16 nId)=0
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
bool IsSelection() const
Definition: crsrsh.hxx:910
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
bool IsAnyDatabaseFieldInDoc() const
Definition: edfld.cxx:384
bool IsGlblDocSaveLinks() const
Definition: edglbldc.cxx:48
void SetModified()
Definition: edws.cxx:70
sfx2::LinkManager & GetLinkManager()
Definition: editsh.cxx:592
bool IsGlobalDoc() const
Interfaces for GlobalDocument.
Definition: edglbldc.cxx:33
void EndAllAction()
Definition: edws.cxx:97
bool IsFrameSelected() const
Definition: feshview.cxx:1133
size_t IsObjSelected() const
Definition: feshview.cxx:1125
void SetFaxName(const OUString &rSet)
Definition: printdata.hxx:165
const OUString & GetFaxName() const
Definition: printdata.hxx:146
void ChgAllPageOrientation(Orientation eOri)
Definition: vprint.cxx:203
const IDocumentDeviceAccess & getIDocumentDeviceAccess() const
Provides access to the document device interface.
Definition: viewsh.cxx:2819
void ChgAllPageSize(Size const &rSz)
Definition: vprint.cxx:242
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:648
int getPart() const override
See SfxViewShell::getPart().
Definition: viewprt.cxx:265
SwWrtShell & GetWrtShell() const
Definition: view.hxx:423
OUString GetColorConfigName() const override
See SfxViewShell::GetColorConfigName().
Definition: viewprt.cxx:319
std::unique_ptr< SwView_Impl > m_pViewImpl
Definition: view.hxx:200
std::unique_ptr< SwWrtShell > m_pWrtShell
Definition: view.hxx:194
virtual SAL_DLLPRIVATE std::unique_ptr< SfxTabPage > CreatePrintOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet) override
Definition: viewprt.cxx:163
::Color GetColorConfigColor(svtools::ColorConfigEntry nColorType) const override
See SfxViewShell::GetColorConfigColor().
Definition: viewprt.cxx:294
virtual sal_uInt16 SetPrinter(SfxPrinter *pNew, SfxPrinterChangeFlags nDiff=SFX_PRINTER_ALL) override
Definition: viewprt.cxx:99
void NotifyCursor(SfxViewShell *pViewShell) const override
See SfxViewShell::NotifyCursor().
Definition: viewprt.cxx:289
void SetRedlineAuthor(const OUString &rAuthor)
Definition: viewprt.cxx:279
void ExecutePrint(SfxRequest &)
Definition: viewprt.cxx:171
virtual SAL_DLLPRIVATE SfxPrinter * GetPrinter(bool bCreate=false) override
Definition: viewprt.cxx:64
virtual SAL_DLLPRIVATE bool HasPrintOptionsPage() const override
Definition: viewprt.cxx:135
SwEditWin & GetEditWin()
Definition: view.hxx:426
const OUString & GetRedlineAuthor() const
Definition: viewprt.cxx:284
void dumpAsXml(xmlTextWriterPtr pWriter) const override
See SfxViewShell::dumpAsXml().
Definition: viewprt.cxx:270
void InvalidateRulerPos()
Definition: viewport.cxx:107
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void UpdateAllLinks(bool bAskUpdate, bool bUpdateGrfLinks, weld::Window *pParentWin)
#define FN_PARAM_ADDPRINTER
Definition: cmdid.h:803
#define FN_QRY_MERGE
Definition: cmdid.h:250
struct _xmlTextWriter * xmlTextWriterPtr
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
#define SAL_WARN(area, stream)
def run(arg=None, arg2=-1)
NONE
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
static SfxItemSet & rSet
OUString VCL_DLLPUBLIC GetStandardText(StandardButtonType eButton)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
#define SW_MOD()
Definition: swmodule.hxx:254
#define O3TL_UNREACHABLE
RET_OK
RET_CANCEL
RET_NO
RET_YES
VclMessageType
VclButtonsType
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:415
std::unique_ptr< SfxTabPage > CreatePrintOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rOptions, bool bPreview)
Definition: viewprt.cxx:335
void SetPrinter(IDocumentDeviceAccess *pIDDA, SfxPrinter const *pNew, bool bWeb)
Definition: viewprt.cxx:79
void SetAppPrintOptions(SwViewShell *pSh, bool bWeb)
Definition: viewprt.cxx:358
#define SFX_PRINTERROR_BUSY
SfxPrinterChangeFlags