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
40#include <modcfg.hxx>
41#include <edtwin.hxx>
42#include <view.hxx>
43#include <wrtsh.hxx>
44#include <viewopt.hxx>
45#include <prtopt.hxx>
46#include <cfgitems.hxx>
47#include "viewfunc.hxx"
48#include <swmodule.hxx>
49#include <wview.hxx>
51
52#include <globals.hrc>
53#include <strings.hrc>
54#include <swabstdlg.hxx>
55
56#include <uivwimp.hxx>
57
58using namespace ::com::sun::star;
59
60// Hand over the printer to Sfx
61
63{
65 SfxPrinter *pOld = rIDDA.getPrinter( false );
66 SfxPrinter *pPrt = rIDDA.getPrinter( bCreate );
67 if ( pOld != pPrt )
68 {
69 bool bWeb = dynamic_cast<SwWebView*>(this) != nullptr;
71 }
72 return pPrt;
73}
74
75// Propagate printer change
76
77void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter const * pNew, bool bWeb )
78{
79 SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb);
80 if( !pOpt)
81 return;
82
83 // Reading Application own printing options from SfxPrinter
84 const SfxItemSet& rSet = pNew->GetOptions();
85
86 const SwAddPrinterItem* pAddPrinterAttr =
88 if( pAddPrinterAttr )
89 {
90 if( pIDDA )
91 pIDDA->setPrintData( *pAddPrinterAttr );
92 if( !pAddPrinterAttr->GetFaxName().isEmpty() )
93 pOpt->SetFaxName(pAddPrinterAttr->GetFaxName());
94 }
95}
96
98{
99 SwWrtShell &rSh = GetWrtShell();
100 SfxPrinter* pOld = rSh.getIDocumentDeviceAccess().getPrinter( false );
101 if ( pOld && pOld->IsPrinting() )
102 return SFX_PRINTERROR_BUSY;
103
104 if ( (SfxPrinterChangeFlags::JOBSETUP | SfxPrinterChangeFlags::PRINTER) & nDiffFlags )
105 {
106 rSh.getIDocumentDeviceAccess().setPrinter( pNew, true, true );
107 if ( nDiffFlags & SfxPrinterChangeFlags::PRINTER )
108 rSh.SetModified();
109 }
110 bool bWeb = dynamic_cast< const SwWebView *>( this ) != nullptr;
111 if ( nDiffFlags & SfxPrinterChangeFlags::OPTIONS )
112 ::SetPrinter( &rSh.getIDocumentDeviceAccess(), pNew, bWeb );
113
114 const bool bChgOri = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION);
115 const bool bChgSize = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE);
116 if ( bChgOri || bChgSize )
117 {
118 rSh.StartAllAction();
119 if ( bChgOri )
120 rSh.ChgAllPageOrientation( pNew->GetOrientation() );
121 if ( bChgSize )
122 {
123 Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
124 rSh.ChgAllPageSize( aSz );
125 }
126 rSh.SetModified();
127 rSh.EndAllAction();
129 }
130 return 0;
131}
132
134{
135 return true;
136}
137
138namespace
139{
140 class SvxPrtQryBox
141 {
142 private:
143 std::unique_ptr<weld::MessageDialog> m_xQueryBox;
144 public:
145 SvxPrtQryBox(weld::Window* pParent)
146 : m_xQueryBox(Application::CreateMessageDialog(pParent, VclMessageType::Question, VclButtonsType::NONE, SvxResId(RID_SVXSTR_QRY_PRINT_MSG)))
147 {
148 m_xQueryBox->set_title(SvxResId(RID_SVXSTR_QRY_PRINT_TITLE));
149
150 m_xQueryBox->add_button(SvxResId(RID_SVXSTR_QRY_PRINT_SELECTION), RET_OK);
151 m_xQueryBox->add_button(SvxResId(RID_SVXSTR_QRY_PRINT_ALL), 2);
152 m_xQueryBox->add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
153 m_xQueryBox->set_default_response(RET_OK);
154 }
155 short run() { return m_xQueryBox->run(); }
156 };
157}
158
159// TabPage for application-specific print options
160
161std::unique_ptr<SfxTabPage> SwView::CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController,
162 const SfxItemSet& rSet)
163{
164 return ::CreatePrintOptionsPage(pPage, pController, rSet, false);
165}
166
167// Print dispatcher
168
170{
171 bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
173 switch (rReq.GetSlot())
174 {
175 case FN_FAX:
176 {
177 SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb);
178 const OUString& sFaxName(pPrintOptions->GetFaxName());
179 if (!sFaxName.isEmpty())
180 {
181 SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName);
182 SfxBoolItem aSilent( SID_SILENT, true );
183 GetViewFrame()->GetDispatcher()->ExecuteList(SID_PRINTDOC,
184 SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
185 { &aPrinterName, &aSilent });
186 }
187 else
188 {
189 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetEditWin().GetFrameWeld(),
190 VclMessageType::Info, VclButtonsType::Ok,
191 SwResId(STR_ERR_NO_FAX)));
192 TranslateId pResId = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS;
193 xInfoBox->set_primary_text(xInfoBox->get_primary_text().replaceFirst("%1", SwResId(pResId)));
194 xInfoBox->run();
195 SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE);
196 GetViewFrame()->GetDispatcher()->ExecuteList(SID_SW_EDITOPTIONS,
197 SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
198 { &aDefPage });
199 }
200 }
201 break;
202 case SID_PRINTDOC:
203 case SID_PRINTDOCDIRECT:
204 {
205 SwWrtShell* pSh = &GetWrtShell();
206 const SfxBoolItem* pSilentItem = rReq.GetArg<SfxBoolItem>(SID_SILENT);
207 bool bSilent = pSilentItem && pSilentItem->GetValue();
208 const SfxBoolItem* pPrintFromMergeItem = rReq.GetArg<SfxBoolItem>(FN_QRY_MERGE);
209 if(pPrintFromMergeItem)
211 bool bFromMerge = pPrintFromMergeItem && pPrintFromMergeItem->GetValue();
212 bool bPrintSelection = false;
213 if(!bSilent && !bFromMerge &&
214 SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc())
215 {
216 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetEditWin().GetFrameWeld(), "modules/swriter/ui/printmergedialog.ui"));
217 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("PrintMergeDialog"));
218 short nRet = xBox->run();
219 if(RET_NO != nRet)
220 {
221 if(RET_YES == nRet)
222 {
223 SfxBoolItem aBool(FN_QRY_MERGE, true);
225 FN_QRY_MERGE, SfxCallMode::ASYNCHRON,
226 { &aBool });
227 rReq.Ignore();
228 }
229 return;
230 }
231 }
232 else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent )
233 {
234 if( pSh->IsSelection() || pSh->IsFrameSelected() || pSh->IsObjSelected() )
235 {
236 SvxPrtQryBox aBox(GetEditWin().GetFrameWeld());
237 short nBtn = aBox.run();
238 if( RET_CANCEL == nBtn )
239 return;
240
241 if( RET_OK == nBtn )
242 bPrintSelection = true;
243 }
244 }
245
246 //#i61455# if master documents are printed silently without loaded links then update the links now
247 if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() )
248 {
249 pSh->GetLinkManager().UpdateAllLinks( false, false, nullptr );
250 }
251 SfxRequest aReq( rReq );
252 SfxBoolItem aBool(SID_SELECTION, bPrintSelection);
253 aReq.AppendItem( aBool );
255 return;
256 }
257 default:
258 OSL_ENSURE(false, "wrong dispatcher");
259 return;
260 }
261}
262
264{
265 return 0;
266}
267
269{
270 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwView"));
272 if (m_pWrtShell)
273 m_pWrtShell->dumpAsXml(pWriter);
274 (void)xmlTextWriterEndElement(pWriter);
275}
276
277void SwView::SetRedlineAuthor(const OUString& rAuthor)
278{
279 m_pViewImpl->m_sRedlineAuthor = rAuthor;
280}
281
282const OUString& SwView::GetRedlineAuthor() const
283{
284 return m_pViewImpl->m_sRedlineAuthor;
285}
286
287void SwView::NotifyCursor(SfxViewShell* pViewShell) const
288{
289 m_pWrtShell->NotifyCursor(pViewShell);
290}
291
292// Create page printer/additions for SwView and SwPagePreview
293
294std::unique_ptr<SfxTabPage> CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController,
295 const SfxItemSet &rOptions,
296 bool bPreview)
297{
299
300 ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc(TP_OPTPRINT_PAGE);
301 OSL_ENSURE(pFact, "No Page Creator");
302 if (!fnCreatePage)
303 return nullptr;
304
305 std::unique_ptr<SfxTabPage> xSfxPage = fnCreatePage(pPage, pController, &rOptions);
306 OSL_ENSURE(xSfxPage, "No page");
307 if (!xSfxPage)
308 return nullptr;
309
310 SfxAllItemSet aSet(*(rOptions.GetPool()));
311 aSet.Put(SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview));
312 aSet.Put(SfxBoolItem(SID_FAX_LIST, true));
313 xSfxPage->PageCreated(aSet);
314 return xSfxPage;
315}
316
317void SetAppPrintOptions( SwViewShell* pSh, bool bWeb )
318{
320 const SwPrintData& aPrtData = rIDDA.getPrintData();
321
322 if( !rIDDA.getPrinter( false ) )
323 return;
324
325 // Close application own printing options in SfxPrinter.
326 SwAddPrinterItem aAddPrinterItem(aPrtData);
328 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
329 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
330 SID_HTML_MODE, SID_HTML_MODE,
332
333 if(bWeb)
334 aSet.Put(SfxUInt16Item(SID_HTML_MODE,
335 ::GetHtmlMode(static_cast<SwWrtShell*>(pSh)->GetView().GetDocShell())));
336 aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN,
338 aSet.Put(aAddPrinterItem);
339 aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC,
341 ? SfxPrinterChangeFlags::CHG_SIZE : SfxPrinterChangeFlags::NONE) |
343 ? SfxPrinterChangeFlags::CHG_ORIENTATION : SfxPrinterChangeFlags::NONE )));
344
345 rIDDA.getPrinter( true )->SetOptions( aSet );
346
347}
348
349/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
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, bool bMobile=false)
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:899
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
bool IsAnyDatabaseFieldInDoc() const
Definition: edfld.cxx:383
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:1253
size_t IsObjSelected() const
Definition: feshview.cxx:1245
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:2805
void ChgAllPageSize(Size const &rSz)
Definition: vprint.cxx:242
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:624
int getPart() const override
See SfxViewShell::getPart().
Definition: viewprt.cxx:263
SwWrtShell & GetWrtShell() const
Definition: view.hxx:416
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:161
virtual sal_uInt16 SetPrinter(SfxPrinter *pNew, SfxPrinterChangeFlags nDiff=SFX_PRINTER_ALL) override
Definition: viewprt.cxx:97
void NotifyCursor(SfxViewShell *pViewShell) const override
See SfxViewShell::NotifyCursor().
Definition: viewprt.cxx:287
void SetRedlineAuthor(const OUString &rAuthor)
Definition: viewprt.cxx:277
void ExecutePrint(SfxRequest &)
Definition: viewprt.cxx:169
virtual SAL_DLLPRIVATE SfxPrinter * GetPrinter(bool bCreate=false) override
Definition: viewprt.cxx:62
virtual SAL_DLLPRIVATE bool HasPrintOptionsPage() const override
Definition: viewprt.cxx:133
SwEditWin & GetEditWin()
Definition: view.hxx:419
const OUString & GetRedlineAuthor() const
Definition: viewprt.cxx:282
void dumpAsXml(xmlTextWriterPtr pWriter) const override
See SfxViewShell::dumpAsXml().
Definition: viewprt.cxx:268
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:786
#define FN_QRY_MERGE
Definition: cmdid.h:243
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
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:165
#define SW_MOD()
Definition: swmodule.hxx:256
RET_OK
RET_CANCEL
RET_NO
RET_YES
VclMessageType
VclButtonsType
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:332
std::unique_ptr< SfxTabPage > CreatePrintOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rOptions, bool bPreview)
Definition: viewprt.cxx:294
void SetPrinter(IDocumentDeviceAccess *pIDDA, SfxPrinter const *pNew, bool bWeb)
Definition: viewprt.cxx:77
void SetAppPrintOptions(SwViewShell *pSh, bool bWeb)
Definition: viewprt.cxx:317
#define SFX_PRINTERROR_BUSY
SfxPrinterChangeFlags