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