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