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 <fldmgr.hxx>
25 #include <expfld.hxx>
26 #include <modcfg.hxx>
27 
28 #include <swmodule.hxx>
29 #include <view.hxx>
30 #include <wview.hxx>
31 #include <wrtsh.hxx>
32 #include <cmdid.h>
33 #include <caption.hxx>
34 #include <poolfmt.hxx>
35 #include <edtwin.hxx>
36 #include <SwStyleNameMapper.hxx>
37 
38 #include <swabstdlg.hxx>
39 
40 #include <strings.hrc>
41 
42 #include <memory>
43 
44 using namespace css;
45 
46 void SwView::ExecDlgExt(SfxRequest const &rReq)
47 {
48  switch ( rReq.GetSlot() )
49  {
50  case FN_INSERT_CAPTION:
51  {
54  pDialog->Execute();
55  break;
56  }
57  case SID_INSERT_SIGNATURELINE:
58  case SID_EDIT_SIGNATURELINE:
59  {
61  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
63  GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_SIGNATURELINE));
64  pDialog->Execute();
65  break;
66  }
67  case SID_INSERT_QRCODE:
68  case SID_EDIT_QRCODE:
69  {
71  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
73  GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_QRCODE));
74  pDialog->Execute();
75  break;
76  }
77  case SID_SIGN_SIGNATURELINE:
78  {
80  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
83  pDialog->Execute();
84  break;
85  }
86  case FN_EDIT_FOOTNOTE:
87  {
90  GetFrameWeld(), *m_pWrtShell, true));
91 
92  pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
93  pDlg->SetText( SwResId(STR_EDIT_FOOTNOTE) );
94  pDlg->Execute();
95  break;
96  }
97  }
98 }
99 
101 {
102  SwWrtShell& rSh = GetWrtShell();
103  SdrView* pSdrView = rSh.GetDrawView();
104  if (!pSdrView)
105  return false;
106 
107  if (pSdrView->GetMarkedObjectCount() != 1)
108  return false;
109 
110  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
111  if (!pPickObj)
112  return false;
113 
114  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
115  if (!pGraphic)
116  return false;
117 
118  return pGraphic->isSignatureLine();
119 }
120 
122 {
123  SwWrtShell& rSh = GetWrtShell();
124  SdrView* pSdrView = rSh.GetDrawView();
125  if (!pSdrView)
126  return false;
127 
128  if (pSdrView->GetMarkedObjectCount() != 1)
129  return false;
130 
131  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
132  if (!pPickObj)
133  return false;
134 
135  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
136  if (!pGraphic)
137  return false;
138 
139  return pGraphic->isSignatureLineSigned();
140 }
141 
143 {
144  SwWrtShell& rSh = GetWrtShell();
145  SdrView* pSdrView = rSh.GetDrawView();
146  if (!pSdrView)
147  return false;
148 
149  if (pSdrView->GetMarkedObjectCount() != 1)
150  return false;
151 
152  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
153  if (!pPickObj)
154  return false;
155 
156  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
157  if (!pGraphic)
158  return false;
159 
160  return pGraphic->getQrCode() != nullptr;
161 }
162 
163 void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
164 {
165  SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
166 
167  bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
168  if (pModOpt->IsInsWithCaption(bWeb))
169  {
170  const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, static_cast<SwCapObjType>(nType), pOleId);
171  if (pOpt && pOpt->UseCaption())
172  InsertCaption(pOpt);
173  }
174 }
175 
177 {
178  if (!pOpt)
179  return;
180 
181  const OUString &rName = pOpt->GetCategory();
182 
183  // Is there a pool template with the same name?
184  SwWrtShell &rSh = GetWrtShell();
185  if(!rName.isEmpty())
186  {
188  if( USHRT_MAX != nPoolId )
189  rSh.GetTextCollFromPool(nPoolId);
190  // Pool template does not exist: Does it exist on the document?
191  else if( !rSh.GetParaStyle(rName) )
192  {
193  // It also does not exist in the document: generate
195  rSh.MakeTextFormatColl(rName, pDerivedFrom);
196  }
197  }
198 
200  if (eType & SelectionType::Ole)
201  eType = SelectionType::Graphic;
202 
203  const SwLabelType eT = (eType & SelectionType::Table) ? SwLabelType::Table :
208 
209  SwFieldMgr aMgr(&rSh);
210  SwSetExpFieldType* pFieldType =
211  static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
212  if (!pFieldType && !rName.isEmpty() )
213  {
214  // Create new field types
215  SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
216  aMgr.InsertFieldType(aSwSetExpFieldType);
217  pFieldType = static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
218  }
219 
220  if (!pOpt->IgnoreSeqOpts())
221  {
222  if (pFieldType)
223  {
224  pFieldType->SetDelimiter(pOpt->GetSeparator());
225  pFieldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
226  }
227  }
228 
229  sal_uInt16 nID = USHRT_MAX;
230  SwFieldType* pType = nullptr;
231  const size_t nCount = aMgr.GetFieldTypeCount();
232  if( !rName.isEmpty() )
233  {
234  for (size_t i = 0; i < nCount; ++i)
235  {
236  pType = aMgr.GetFieldType(SwFieldIds::Unknown, i);
237  OUString aTmpName( pType->GetName() );
238  if (aTmpName == rName && pType->Which() == SwFieldIds::SetExp)
239  {
240  nID = i;
241  OSL_ENSURE(nID==i, "Downcasting to sal_uInt16 lost information!");
242  break;
243  }
244  }
245  }
246  rSh.StartAllAction();
247 
248  GetWrtShell().InsertLabel( eT,
249  pOpt->GetCaption(),
250  !pOpt->IgnoreSeqOpts() ? OUString() : pOpt->GetSeparator(),
251  pOpt->GetNumSeparator(),
252  !pOpt->GetPos(),
253  nID,
254  pOpt->GetCharacterStyle(),
255  pOpt->CopyAttributes() );
256  // Set Number Format
257  if(pType)
258  static_cast<SwSetExpFieldType*>(pType)->SetSeqFormat(pOpt->GetNumType());
259 
260  rSh.UpdateExpFields( true );
261 
262  rSh.EndAllAction();
263 
264  if ( rSh.IsFrameSelected() )
265  {
266  GetEditWin().StopInsFrame();
267  rSh.EnterSelFrameMode();
268  }
269 
270  // remember category
271  if (eType & SelectionType::Graphic)
272  SetOldGrfCat(rName);
273  else if( eType & SelectionType::Table)
274  SetOldTabCat(rName);
275  else if( eType & SelectionType::Frame)
276  SetOldFrameCat(rName);
277  else if( eType == SelectionType::Text)
278  SetOldFrameCat(rName);
279  else if( eType & SelectionType::DrawObject)
280  SetOldDrwCat(rName);
281 }
282 
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFieldType * GetFieldType(SwFieldIds nResId, size_t nField=0) const
Definition: fldmgr.cxx:409
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:179
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:55
const OUString & GetNumSeparator() const
Definition: caption.hxx:61
SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId)
Definition: edfmt.cxx:123
SdrView * GetDrawView()
Definition: vnew.cxx:375
void AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId=nullptr)
Definition: viewdlg2.cxx:163
#define FN_EDIT_FOOTNOTE
Definition: cmdid.h:106
void SetOutlineLvl(sal_uInt8 n)
Definition: expfld.hxx:181
#define FN_INSERT_CAPTION
Definition: cmdid.h:198
bool & CopyAttributes()
Definition: caption.hxx:83
virtual short Execute()=0
void EndAllAction()
Definition: edws.cxx:97
bool isSignatureLineSigned() const
Definition: viewdlg2.cxx:121
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:90
const OUString & GetCaption() const
Definition: caption.hxx:64
size_t GetFieldTypeCount() const
Definition: fldmgr.cxx:402
int nCount
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
bool isSignatureLine() const
bool IsInsWithCaption(bool bHTML) const
Definition: modcfg.hxx:263
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
void InsertCaption(const InsCaptionOpt *pOpt)
Definition: viewdlg2.cxx:176
DocumentType eType
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
#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:46
virtual VclPtr< VclAbstractDialog > CreateSwCaptionDialog(weld::Window *pParent, SwView &rV)=0
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:178
sal_uInt16 GetPos() const
Definition: caption.hxx:67
SelectionType
Definition: wrtsh.hxx:58
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:322
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:204
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:135
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:253
css::drawing::QRCode * getQrCode() const
bool isSignatureLineSelected() const
Definition: viewdlg2.cxx:100
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:701
sal_uInt16 GetNumType() const
Definition: caption.hxx:58
SwTextFormatColl * MakeTextFormatColl(const OUString &rFormatCollName, SwTextFormatColl *pDerivedFrom=nullptr)
Definition: edfcol.cxx:2228
const OUString & GetSeparator() const
Definition: caption.hxx:73
SelectionType GetSelectionType() const
Definition: wrtsh1.cxx:1388
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< AbstractInsFootNoteDlg > CreateInsFootNoteDlg(weld::Window *pParent, SwWrtShell &rSh, bool bEd=false)=0
bool IsFrameSelected() const
Definition: feshview.cxx:1158
void InsertFieldType(SwFieldType const &rType)
Definition: fldmgr.cxx:874
bool isQRCodeSelected() const
Definition: viewdlg2.cxx:142
SwTextFormatColl * GetParaStyle(const OUString &rCollName, GetStyle eCreate=GETSTYLE_NOCREATE)
Definition: wrtsh1.cxx:1488