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