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