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