LibreOffice Module sw (master)  1
viewdlg2.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 <sfx2/request.hxx>
21 #include <sfx2/objface.hxx>
22 #include <svx/svdograf.hxx>
23 #include <svx/svdview.hxx>
24 #include <osl/diagnose.h>
25 #include <fldmgr.hxx>
26 #include <expfld.hxx>
27 #include <modcfg.hxx>
28 
29 #include <swmodule.hxx>
30 #include <view.hxx>
31 #include <wview.hxx>
32 #include <wrtsh.hxx>
33 #include <cmdid.h>
34 #include <caption.hxx>
35 #include <poolfmt.hxx>
36 #include <edtwin.hxx>
37 #include <SwStyleNameMapper.hxx>
38 
39 #include <swabstdlg.hxx>
40 
41 #include <strings.hrc>
42 
43 #include <memory>
44 
45 #include <svl/stritem.hxx>
46 
47 using namespace css;
48 
49 void SwView::ExecDlgExt(SfxRequest const &rReq)
50 {
51  switch ( rReq.GetSlot() )
52  {
53  case FN_INSERT_CAPTION:
54  {
57  pDialog->Execute();
58  break;
59  }
60  case SID_INSERT_SIGNATURELINE:
61  case SID_EDIT_SIGNATURELINE:
62  {
64  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
66  GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_SIGNATURELINE));
67  pDialog->Execute();
68  break;
69  }
70  case SID_INSERT_QRCODE:
71  case SID_EDIT_QRCODE:
72  {
74  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
76  GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_QRCODE));
77  pDialog->Execute();
78  break;
79  }
80  case SID_ADDITIONS_DIALOG:
81  {
82  OUString sAdditionsTag = "";
83 
84  const SfxStringItem* pStringArg = rReq.GetArg<SfxStringItem>(SID_ADDITIONS_TAG);
85  if (pStringArg)
86  sAdditionsTag = pStringArg->GetValue();
87 
90  pFact->CreateAdditionsDialog(GetFrameWeld(), sAdditionsTag));
91  pDialog->Execute();
92  break;
93  }
94  case SID_SIGN_SIGNATURELINE:
95  {
97  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
100  pDialog->Execute();
101  break;
102  }
103  case FN_EDIT_FOOTNOTE:
104  {
107  GetFrameWeld(), *m_pWrtShell, true));
108 
109  pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
110  pDlg->SetText( SwResId(STR_EDIT_FOOTNOTE) );
111  pDlg->Execute();
112  break;
113  }
114  }
115 }
116 
118 {
119  SwWrtShell& rSh = GetWrtShell();
120  SdrView* pSdrView = rSh.GetDrawView();
121  if (!pSdrView)
122  return false;
123 
124  if (pSdrView->GetMarkedObjectCount() != 1)
125  return false;
126 
127  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
128  if (!pPickObj)
129  return false;
130 
131  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
132  if (!pGraphic)
133  return false;
134 
135  return pGraphic->isSignatureLine();
136 }
137 
139 {
140  SwWrtShell& rSh = GetWrtShell();
141  SdrView* pSdrView = rSh.GetDrawView();
142  if (!pSdrView)
143  return false;
144 
145  if (pSdrView->GetMarkedObjectCount() != 1)
146  return false;
147 
148  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
149  if (!pPickObj)
150  return false;
151 
152  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
153  if (!pGraphic)
154  return false;
155 
156  return pGraphic->isSignatureLineSigned();
157 }
158 
160 {
161  SwWrtShell& rSh = GetWrtShell();
162  SdrView* pSdrView = rSh.GetDrawView();
163  if (!pSdrView)
164  return false;
165 
166  if (pSdrView->GetMarkedObjectCount() != 1)
167  return false;
168 
169  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
170  if (!pPickObj)
171  return false;
172 
173  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
174  if (!pGraphic)
175  return false;
176 
177  return pGraphic->getQrCode() != nullptr;
178 }
179 
180 void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
181 {
182  SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
183 
184  bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
185  if (pModOpt->IsInsWithCaption(bWeb))
186  {
187  const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, static_cast<SwCapObjType>(nType), pOleId);
188  if (pOpt && pOpt->UseCaption())
189  InsertCaption(pOpt);
190  }
191 }
192 
194 {
195  if (!pOpt)
196  return;
197 
198  const OUString &rName = pOpt->GetCategory();
199 
200  // Is there a pool template with the same name?
201  SwWrtShell &rSh = GetWrtShell();
202  if(!rName.isEmpty())
203  {
205  if( USHRT_MAX != nPoolId )
206  rSh.GetTextCollFromPool(nPoolId);
207  // Pool template does not exist: Does it exist on the document?
208  else if( !rSh.GetParaStyle(rName) )
209  {
210  // It also does not exist in the document: generate
212  rSh.MakeTextFormatColl(rName, pDerivedFrom);
213  }
214  }
215 
217  if (eType & SelectionType::Ole)
218  eType = SelectionType::Graphic;
219 
220  const SwLabelType eT = (eType & SelectionType::Table) ? SwLabelType::Table :
225 
226  SwFieldMgr aMgr(&rSh);
227  SwSetExpFieldType* pFieldType =
228  static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
229  if (!pFieldType && !rName.isEmpty() )
230  {
231  // Create new field types
232  SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
233  aMgr.InsertFieldType(aSwSetExpFieldType);
234  pFieldType = static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
235  }
236 
237  if (!pOpt->IgnoreSeqOpts())
238  {
239  if (pFieldType)
240  {
241  pFieldType->SetDelimiter(pOpt->GetSeparator());
242  pFieldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
243  }
244  }
245 
246  sal_uInt16 nID = USHRT_MAX;
247  SwFieldType* pType = nullptr;
248  const size_t nCount = aMgr.GetFieldTypeCount();
249  if( !rName.isEmpty() )
250  {
251  for (size_t i = 0; i < nCount; ++i)
252  {
253  pType = aMgr.GetFieldType(SwFieldIds::Unknown, i);
254  OUString aTmpName( pType->GetName() );
255  if (aTmpName == rName && pType->Which() == SwFieldIds::SetExp)
256  {
257  nID = i;
258  OSL_ENSURE(nID==i, "Downcasting to sal_uInt16 lost information!");
259  break;
260  }
261  }
262  }
263  rSh.StartAllAction();
264 
265  GetWrtShell().InsertLabel( eT,
266  pOpt->GetCaption(),
267  !pOpt->IgnoreSeqOpts() ? OUString() : pOpt->GetSeparator(),
268  pOpt->GetNumSeparator(),
269  !pOpt->GetPos(),
270  nID,
271  pOpt->GetCharacterStyle(),
272  pOpt->CopyAttributes() );
273  // Set Number Format
274  if(pType)
275  static_cast<SwSetExpFieldType*>(pType)->SetSeqFormat(pOpt->GetNumType());
276 
277  rSh.UpdateExpFields( true );
278 
279  rSh.EndAllAction();
280 
281  if ( rSh.IsFrameSelected() )
282  {
283  GetEditWin().StopInsFrame();
284  rSh.EnterSelFrameMode();
285  }
286 
287  // remember category
288  if (eType & SelectionType::Graphic)
289  SetOldGrfCat(rName);
290  else if( eType & SelectionType::Table)
291  SetOldTabCat(rName);
292  else if( eType & SelectionType::Frame)
293  SetOldFrameCat(rName);
294  else if( eType == SelectionType::Text)
295  SetOldFrameCat(rName);
296  else if( eType & SelectionType::DrawObject)
297  SetOldDrwCat(rName);
298 }
299 
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFieldType * GetFieldType(SwFieldIds nResId, size_t nField=0) const
Definition: fldmgr.cxx:412
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
Subgroup labels.
Definition: poolfmt.hxx:345
void SetDelimiter(const OUString &s)
Definition: expfld.hxx:178
const OUString & GetCategory() const
Definition: caption.hxx:55
const OUString & GetCharacterStyle() const
Definition: caption.hxx:76
SwLabelType
Definition: swtypes.hxx:87
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
const OUString & GetNumSeparator() const
Definition: caption.hxx:61
SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId)
Definition: edfmt.cxx:123
SdrView * GetDrawView()
Definition: vnew.cxx:376
void AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId=nullptr)
Definition: viewdlg2.cxx:180
#define FN_EDIT_FOOTNOTE
Definition: cmdid.h:106
void SetOutlineLvl(sal_uInt8 n)
Definition: expfld.hxx:180
#define FN_INSERT_CAPTION
Definition: cmdid.h:203
bool & CopyAttributes()
Definition: caption.hxx:83
virtual short Execute()=0
void EndAllAction()
Definition: edws.cxx:97
bool isSignatureLineSigned() const
Definition: viewdlg2.cxx:138
const InsCaptionOpt * GetCapOption(bool bHTML, const SwCapObjType eType, const SvGlobalName *pOleId)
Definition: modcfg.cxx:60
Used by the UI to modify the document model.
Definition: wrtsh.hxx:91
const OUString & GetCaption() const
Definition: caption.hxx:64
size_t GetFieldTypeCount() const
Definition: fldmgr.cxx:405
int nCount
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
bool isSignatureLine() const
bool IsInsWithCaption(bool bHTML) const
Definition: modcfg.hxx:265
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
void InsertCaption(const InsCaptionOpt *pOpt)
Definition: viewdlg2.cxx:193
DocumentType eType
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
#define SW_MOD()
Definition: swmodule.hxx:256
int i
sal_uInt16 GetLevel() const
Definition: caption.hxx:70
virtual VclPtr< AbstractQrCodeGenDialog > CreateQrCodeGenDialog(weld::Window *pParent, const css::uno::Reference< css::frame::XModel > xModel, bool bEditExisting)=0
size_t GetMarkedObjectCount() const
void ExecDlgExt(SfxRequest const &)
Definition: viewdlg2.cxx:49
const OUString & GetValue() const
virtual VclPtr< VclAbstractDialog > CreateSwCaptionDialog(weld::Window *pParent, SwView &rV)=0
const T * GetArg(sal_uInt16 nSlotId) const
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
virtual VclPtr< AbstractSignatureLineDialog > CreateSignatureLineDialog(weld::Window *pParent, const css::uno::Reference< css::frame::XModel > xModel, bool bEditExisting)=0
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
sal_uInt16 GetPos() const
Definition: caption.hxx:67
SelectionType
Definition: wrtsh.hxx:59
virtual VclPtr< AbstractSignSignatureLineDialog > CreateSignSignatureLineDialog(weld::Window *pParent, const css::uno::Reference< css::frame::XModel > xModel)=0
sal_uInt16 GetSlot() const
void UpdateExpFields(bool bCloseDB=false)
only every expression fields update
Definition: edfld.cxx:312
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:204
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:136
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
css::drawing::QRCode * getQrCode() const
bool isSignatureLineSelected() const
Definition: viewdlg2.cxx:117
bool & IgnoreSeqOpts()
Definition: caption.hxx:80
SdrObject * GetMarkedObjectByIndex(size_t nNum) const
static VclAbstractDialogFactory * Create()
Reference< XModel > xModel
void EnterSelFrameMode(const Point *pStartDrag=nullptr)
Definition: select.cxx:702
sal_uInt16 GetNumType() const
Definition: caption.hxx:58
SwTextFormatColl * MakeTextFormatColl(const OUString &rFormatCollName, SwTextFormatColl *pDerivedFrom=nullptr)
Definition: edfcol.cxx:2249
const OUString & GetSeparator() const
Definition: caption.hxx:73
SelectionType GetSelectionType() const
Definition: wrtsh1.cxx:1395
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
bool & UseCaption()
Definition: caption.hxx:48
SwFieldIds Which() const
Definition: fldbas.hxx:272
bool isSignatureLineSigned() const
virtual VclPtr< AbstractAdditionsDialog > CreateAdditionsDialog(weld::Window *pParent, const OUString &sAdditionsTag)=0
virtual VclPtr< AbstractInsFootNoteDlg > CreateInsFootNoteDlg(weld::Window *pParent, SwWrtShell &rSh, bool bEd=false)=0
bool IsFrameSelected() const
Definition: feshview.cxx:1166
void InsertFieldType(SwFieldType const &rType)
Definition: fldmgr.cxx:877
bool isQRCodeSelected() const
Definition: viewdlg2.cxx:159
SwTextFormatColl * GetParaStyle(const OUString &rCollName, GetStyle eCreate=GETSTYLE_NOCREATE)
Definition: wrtsh1.cxx:1495