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 
30 #include <swmodule.hxx>
31 #include <view.hxx>
32 #include <wview.hxx>
33 #include <wrtsh.hxx>
34 #include <cmdid.h>
35 #include <caption.hxx>
36 #include <poolfmt.hxx>
37 #include <edtwin.hxx>
38 #include <SwStyleNameMapper.hxx>
39 
40 #include <initui.hxx>
41 #include <swabstdlg.hxx>
42 
43 #include <strings.hrc>
44 
45 #include <memory>
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_SIGN_SIGNATURELINE:
71  {
73  const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
76  pDialog->Execute();
77  break;
78  }
79  case FN_EDIT_FOOTNOTE:
80  {
83  GetFrameWeld(), *m_pWrtShell, true));
84 
85  pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
86  pDlg->SetText( SwResId(STR_EDIT_FOOTNOTE) );
87  pDlg->Execute();
88  break;
89  }
90  }
91 }
92 
94 {
95  SwWrtShell& rSh = GetWrtShell();
96  SdrView* pSdrView = rSh.GetDrawView();
97  if (!pSdrView)
98  return false;
99 
100  if (pSdrView->GetMarkedObjectCount() != 1)
101  return false;
102 
103  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
104  if (!pPickObj)
105  return false;
106 
107  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
108  if (!pGraphic)
109  return false;
110 
111  return pGraphic->isSignatureLine();
112 }
113 
115 {
116  SwWrtShell& rSh = GetWrtShell();
117  SdrView* pSdrView = rSh.GetDrawView();
118  if (!pSdrView)
119  return false;
120 
121  if (pSdrView->GetMarkedObjectCount() != 1)
122  return false;
123 
124  SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
125  if (!pPickObj)
126  return false;
127 
128  SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
129  if (!pGraphic)
130  return false;
131 
132  return pGraphic->isSignatureLineSigned();
133 }
134 
135 void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
136 {
137  SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
138 
139  bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
140  if (pModOpt->IsInsWithCaption(bWeb))
141  {
142  const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, static_cast<SwCapObjType>(nType), pOleId);
143  if (pOpt && pOpt->UseCaption())
144  InsertCaption(pOpt);
145  }
146 }
147 
149 {
150  if (!pOpt)
151  return;
152 
153  const OUString &rName = pOpt->GetCategory();
154 
155  // Is there a pool template with the same name?
156  SwWrtShell &rSh = GetWrtShell();
157  if(!rName.isEmpty())
158  {
160  if( USHRT_MAX != nPoolId )
161  rSh.GetTextCollFromPool(nPoolId);
162  // Pool template does not exist: Does it exist on the document?
163  else if( !rSh.GetParaStyle(rName) )
164  {
165  // It also does not exist in the document: generate
167  rSh.MakeTextFormatColl(rName, pDerivedFrom);
168  }
169  }
170 
172  if (eType & SelectionType::Ole)
173  eType = SelectionType::Graphic;
174 
175  const SwLabelType eT = (eType & SelectionType::Table) ? LTYPE_TABLE :
176  (eType & SelectionType::Frame) ? LTYPE_FLY :
177  (eType == SelectionType::Text) ? LTYPE_FLY :
179  LTYPE_OBJECT;
180 
181  SwFieldMgr aMgr(&rSh);
182  SwSetExpFieldType* pFieldType =
183  static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
184  if (!pFieldType && !rName.isEmpty() )
185  {
186  // Create new field types
187  SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
188  aMgr.InsertFieldType(aSwSetExpFieldType);
189  pFieldType = static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
190  }
191 
192  if (!pOpt->IgnoreSeqOpts())
193  {
194  if (pFieldType)
195  {
196  pFieldType->SetDelimiter(pOpt->GetSeparator());
197  pFieldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
198  }
199  }
200 
201  sal_uInt16 nID = USHRT_MAX;
202  SwFieldType* pType = nullptr;
203  const size_t nCount = aMgr.GetFieldTypeCount();
204  if( !rName.isEmpty() )
205  {
206  for (size_t i = 0; i < nCount; ++i)
207  {
208  pType = aMgr.GetFieldType(SwFieldIds::Unknown, i);
209  OUString aTmpName( pType->GetName() );
210  if (aTmpName == rName && pType->Which() == SwFieldIds::SetExp)
211  {
212  nID = i;
213  OSL_ENSURE(nID==i, "Downcasting to sal_uInt16 lost information!");
214  break;
215  }
216  }
217  }
218  rSh.StartAllAction();
219 
220  GetWrtShell().InsertLabel( eT,
221  pOpt->GetCaption(),
222  !pOpt->IgnoreSeqOpts() ? OUString() : pOpt->GetSeparator(),
223  pOpt->GetNumSeparator(),
224  !pOpt->GetPos(),
225  nID,
226  pOpt->GetCharacterStyle(),
227  pOpt->CopyAttributes() );
228  // Set Number Format
229  if(pType)
230  static_cast<SwSetExpFieldType*>(pType)->SetSeqFormat(pOpt->GetNumType());
231 
232  rSh.UpdateExpFields( true );
233 
234  rSh.EndAllAction();
235 
236  if ( rSh.IsFrameSelected() )
237  {
238  GetEditWin().StopInsFrame();
239  rSh.EnterSelFrameMode();
240  }
241 
242  // remember category
243  if (eType & SelectionType::Graphic)
244  SetOldGrfCat(rName);
245  else if( eType & SelectionType::Table)
246  SetOldTabCat(rName);
247  else if( eType & SelectionType::Frame)
248  SetOldFrameCat(rName);
249  else if( eType == SelectionType::Text)
250  SetOldFrameCat(rName);
251  else if( eType & SelectionType::DrawObject)
252  SetOldDrwCat(rName);
253 }
254 
255 /* 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:135
#define FN_EDIT_FOOTNOTE
Definition: cmdid.h:105
void SetOutlineLvl(sal_uInt8 n)
Definition: expfld.hxx:181
#define FN_INSERT_CAPTION
Definition: cmdid.h:194
bool & CopyAttributes()
Definition: caption.hxx:83
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:86
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:262
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
void InsertCaption(const InsCaptionOpt *pOpt)
Definition: viewdlg2.cxx:148
#define SW_MOD()
Definition: swmodule.hxx:255
sal_uInt16 GetLevel() const
Definition: caption.hxx:70
bool isSignatureLineSigned()
Definition: viewdlg2.cxx:114
size_t GetMarkedObjectCount() const
void ExecDlgExt(SfxRequest const &)
Definition: viewdlg2.cxx:49
int i
bool isSignatureLineSelected()
Definition: viewdlg2.cxx:93
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:56
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:259
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:1373
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:891
SwTextFormatColl * GetParaStyle(const OUString &rCollName, GetStyle eCreate=GETSTYLE_NOCREATE)
Definition: wrtsh1.cxx:1466