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 #include <svl/stritem.hxx>
45 
46 using namespace css;
47 
48 void SwView::ExecDlgExt(SfxRequest const &rReq)
49 {
50  switch ( rReq.GetSlot() )
51  {
52  case FN_INSERT_CAPTION:
53  {
56  pDialog->Execute();
57  break;
58  }
59  case SID_INSERT_SIGNATURELINE:
60  case SID_EDIT_SIGNATURELINE:
61  {
63  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
65  GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_SIGNATURELINE));
66  pDialog->Execute();
67  break;
68  }
69  case SID_INSERT_QRCODE:
70  case SID_EDIT_QRCODE:
71  {
73  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
75  GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_QRCODE));
76  pDialog->Execute();
77  break;
78  }
79  case SID_ADDITIONS_DIALOG:
80  {
81  OUString sAdditionsTag = "";
82 
83  const SfxStringItem* pStringArg = rReq.GetArg<SfxStringItem>(SID_ADDITIONS_TAG);
84  if (pStringArg)
85  sAdditionsTag = pStringArg->GetValue();
86 
89  pFact->CreateAdditionsDialog(GetFrameWeld(), sAdditionsTag));
90  pDialog->Execute();
91  break;
92  }
93  case SID_SIGN_SIGNATURELINE:
94  {
96  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
99  pDialog->Execute();
100  break;
101  }
102  case FN_EDIT_FOOTNOTE:
103  {
106  GetFrameWeld(), *m_pWrtShell, true));
107 
108  pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
109  pDlg->SetText( SwResId(STR_EDIT_FOOTNOTE) );
110  pDlg->Execute();
111  break;
112  }
113  }
114 }
115 
117 {
118  SwWrtShell& rSh = GetWrtShell();
119  SdrView* pSdrView = rSh.GetDrawView();
120  if (!pSdrView)
121  return false;
122 
123  if (pSdrView->GetMarkedObjectCount() != 1)
124  return false;
125 
126  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
127  if (!pPickObj)
128  return false;
129 
130  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
131  if (!pGraphic)
132  return false;
133 
134  return pGraphic->isSignatureLine();
135 }
136 
138 {
139  SwWrtShell& rSh = GetWrtShell();
140  SdrView* pSdrView = rSh.GetDrawView();
141  if (!pSdrView)
142  return false;
143 
144  if (pSdrView->GetMarkedObjectCount() != 1)
145  return false;
146 
147  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
148  if (!pPickObj)
149  return false;
150 
151  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
152  if (!pGraphic)
153  return false;
154 
155  return pGraphic->isSignatureLineSigned();
156 }
157 
159 {
160  SwWrtShell& rSh = GetWrtShell();
161  SdrView* pSdrView = rSh.GetDrawView();
162  if (!pSdrView)
163  return false;
164 
165  if (pSdrView->GetMarkedObjectCount() != 1)
166  return false;
167 
168  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
169  if (!pPickObj)
170  return false;
171 
172  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
173  if (!pGraphic)
174  return false;
175 
176  return pGraphic->getQrCode() != nullptr;
177 }
178 
179 void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
180 {
181  SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
182 
183  bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
184  if (pModOpt->IsInsWithCaption(bWeb))
185  {
186  const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, static_cast<SwCapObjType>(nType), pOleId);
187  if (pOpt && pOpt->UseCaption())
188  InsertCaption(pOpt);
189  }
190 }
191 
193 {
194  if (!pOpt)
195  return;
196 
197  const OUString &rName = pOpt->GetCategory();
198 
199  // Is there a pool template with the same name?
200  SwWrtShell &rSh = GetWrtShell();
201  if(!rName.isEmpty())
202  {
204  if( USHRT_MAX != nPoolId )
205  rSh.GetTextCollFromPool(nPoolId);
206  // Pool template does not exist: Does it exist on the document?
207  else if( !rSh.GetParaStyle(rName) )
208  {
209  // It also does not exist in the document: generate
211  rSh.MakeTextFormatColl(rName, pDerivedFrom);
212  }
213  }
214 
216  if (eType & SelectionType::Ole)
217  eType = SelectionType::Graphic;
218 
219  const SwLabelType eT = (eType & SelectionType::Table) ? SwLabelType::Table :
224 
225  SwFieldMgr aMgr(&rSh);
226  SwSetExpFieldType* pFieldType =
227  static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
228  if (!pFieldType && !rName.isEmpty() )
229  {
230  // Create new field types
231  SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
232  aMgr.InsertFieldType(aSwSetExpFieldType);
233  pFieldType = static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
234  }
235 
236  if (!pOpt->IgnoreSeqOpts())
237  {
238  if (pFieldType)
239  {
240  pFieldType->SetDelimiter(pOpt->GetSeparator());
241  pFieldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
242  }
243  }
244 
245  sal_uInt16 nID = USHRT_MAX;
246  SwFieldType* pType = nullptr;
247  const size_t nCount = aMgr.GetFieldTypeCount();
248  if( !rName.isEmpty() )
249  {
250  for (size_t i = 0; i < nCount; ++i)
251  {
252  pType = aMgr.GetFieldType(SwFieldIds::Unknown, i);
253  OUString aTmpName( pType->GetName() );
254  if (aTmpName == rName && pType->Which() == SwFieldIds::SetExp)
255  {
256  nID = i;
257  OSL_ENSURE(nID==i, "Downcasting to sal_uInt16 lost information!");
258  break;
259  }
260  }
261  }
262  rSh.StartAllAction();
263 
264  GetWrtShell().InsertLabel( eT,
265  pOpt->GetCaption(),
266  !pOpt->IgnoreSeqOpts() ? OUString() : pOpt->GetSeparator(),
267  pOpt->GetNumSeparator(),
268  !pOpt->GetPos(),
269  nID,
270  pOpt->GetCharacterStyle(),
271  pOpt->CopyAttributes() );
272  // Set Number Format
273  if(pType)
274  static_cast<SwSetExpFieldType*>(pType)->SetSeqFormat(pOpt->GetNumType());
275 
276  rSh.UpdateExpFields( true );
277 
278  rSh.EndAllAction();
279 
280  if ( rSh.IsFrameSelected() )
281  {
282  GetEditWin().StopInsFrame();
283  rSh.EnterSelFrameMode();
284  }
285 
286  // remember category
287  if (eType & SelectionType::Graphic)
288  SetOldGrfCat(rName);
289  else if( eType & SelectionType::Table)
290  SetOldTabCat(rName);
291  else if( eType & SelectionType::Frame)
292  SetOldFrameCat(rName);
293  else if( eType == SelectionType::Text)
294  SetOldFrameCat(rName);
295  else if( eType & SelectionType::DrawObject)
296  SetOldDrwCat(rName);
297 }
298 
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFieldType * GetFieldType(SwFieldIds nResId, size_t nField=0) const
Definition: fldmgr.cxx:410
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
Subgroup labels.
Definition: poolfmt.hxx:344
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:179
#define FN_EDIT_FOOTNOTE
Definition: cmdid.h:106
void SetOutlineLvl(sal_uInt8 n)
Definition: expfld.hxx:181
#define FN_INSERT_CAPTION
Definition: cmdid.h:201
bool & CopyAttributes()
Definition: caption.hxx:83
virtual short Execute()=0
void EndAllAction()
Definition: edws.cxx:97
bool isSignatureLineSigned() const
Definition: viewdlg2.cxx:137
const InsCaptionOpt * GetCapOption(bool bHTML, const SwCapObjType eType, const SvGlobalName *pOleId)
Definition: modcfg.cxx:61
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:403
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:192
DocumentType eType
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
#define SW_MOD()
Definition: swmodule.hxx:255
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:48
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: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:317
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:116
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:2246
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:1157
void InsertFieldType(SwFieldType const &rType)
Definition: fldmgr.cxx:875
bool isQRCodeSelected() const
Definition: viewdlg2.cxx:158
SwTextFormatColl * GetParaStyle(const OUString &rCollName, GetStyle eCreate=GETSTYLE_NOCREATE)
Definition: wrtsh1.cxx:1495