Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sw / source / uibase / uiview / viewdlg2.cxx
blob41bec30c802338c5ee5696ff416017b7b743d80c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/request.hxx>
21 #include <sfx2/viewfrm.hxx>
22 #include <sfx2/objface.hxx>
23 #include <svx/svdograf.hxx>
24 #include <fldmgr.hxx>
25 #include <expfld.hxx>
26 #include <modcfg.hxx>
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>
38 #include <initui.hxx>
39 #include <swabstdlg.hxx>
41 #include <strings.hrc>
43 #include <memory>
45 using namespace css;
47 void SwView::ExecDlgExt(SfxRequest const &rReq)
49 vcl::Window& rMDI = GetViewFrame()->GetWindow();
51 switch ( rReq.GetSlot() )
53 case FN_INSERT_CAPTION:
55 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
56 assert(pFact && "SwAbstractDialogFactory fail!");
58 ScopedVclPtr<VclAbstractDialog> pDialog(pFact->CreateSwCaptionDialog( &rMDI, *this ));
59 assert(pDialog && "Dialog creation failed!");
60 if ( pDialog )
62 pDialog->Execute();
64 break;
66 case SID_INSERT_SIGNATURELINE:
67 case SID_EDIT_SIGNATURELINE:
69 VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
70 assert(pFact && "VclAbstractDialogFactory fail!");
72 const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
73 ScopedVclPtr<AbstractSignatureLineDialog> pDialog(pFact->CreateSignatureLineDialog(
74 GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_SIGNATURELINE));
75 assert(pDialog && "Dialog creation failed!");
77 if (pDialog)
78 pDialog->Execute();
79 break;
81 case SID_SIGN_SIGNATURELINE:
83 VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
84 assert(pFact && "VclAbstractDialogFactory fail!");
86 const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
87 VclPtr<AbstractSignSignatureLineDialog> pDialog
88 = pFact->CreateSignSignatureLineDialog(GetFrameWeld(), xModel);
89 assert(pDialog && "Dialog creation failed!");
91 if (pDialog)
92 pDialog->Execute();
93 break;
95 case FN_EDIT_FOOTNOTE:
97 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
98 assert(pFact && "Dialog creation failed!");
99 ScopedVclPtr<AbstractInsFootNoteDlg> pDlg(pFact->CreateInsFootNoteDlg(
100 GetFrameWeld(), *m_pWrtShell, true));
101 assert(pDlg && "Dialog creation failed!");
103 pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
104 pDlg->SetText( SwResId(STR_EDIT_FOOTNOTE) );
105 pDlg->Execute();
106 break;
111 bool SwView::isSignatureLineSelected()
113 SwWrtShell& rSh = GetWrtShell();
114 SdrView* pSdrView = rSh.GetDrawView();
115 if (!pSdrView)
116 return false;
118 if (pSdrView->GetMarkedObjectCount() != 1)
119 return false;
121 SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
122 if (!pPickObj)
123 return false;
125 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
126 if (!pGraphic)
127 return false;
129 return pGraphic->isSignatureLine();
132 void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
134 SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
136 bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
137 if (pModOpt->IsInsWithCaption(bWeb))
139 const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, static_cast<SwCapObjType>(nType), pOleId);
140 if (pOpt && pOpt->UseCaption())
141 InsertCaption(pOpt);
145 void SwView::InsertCaption(const InsCaptionOpt *pOpt)
147 if (!pOpt)
148 return;
150 const OUString &rName = pOpt->GetCategory();
152 // Is there a pool template with the same name?
153 SwWrtShell &rSh = GetWrtShell();
154 if(!rName.isEmpty())
156 sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName(rName, SwGetPoolIdFromName::TxtColl);
157 if( USHRT_MAX != nPoolId )
158 rSh.GetTextCollFromPool(nPoolId);
159 // Pool template does not exist: Does it exist on the document?
160 else if( !rSh.GetParaStyle(rName) )
162 // It also does not exist in the document: generate
163 SwTextFormatColl* pDerivedFrom = rSh.GetTextCollFromPool(RES_POOLCOLL_LABEL);
164 rSh.MakeTextFormatColl(rName, pDerivedFrom);
168 SelectionType eType = rSh.GetSelectionType();
169 if (eType & SelectionType::Ole)
170 eType = SelectionType::Graphic;
172 const SwLabelType eT = (eType & SelectionType::Table) ? LTYPE_TABLE :
173 (eType & SelectionType::Frame) ? LTYPE_FLY :
174 (eType == SelectionType::Text) ? LTYPE_FLY :
175 (eType & SelectionType::DrawObject) ? LTYPE_DRAW :
176 LTYPE_OBJECT;
178 SwFieldMgr aMgr(&rSh);
179 SwSetExpFieldType* pFieldType =
180 static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
181 if (!pFieldType && !rName.isEmpty() )
183 // Create new field types
184 SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
185 aMgr.InsertFieldType(aSwSetExpFieldType);
186 pFieldType = static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
189 if (!pOpt->IgnoreSeqOpts())
191 if (pFieldType)
193 pFieldType->SetDelimiter(pOpt->GetSeparator());
194 pFieldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
198 sal_uInt16 nID = USHRT_MAX;
199 SwFieldType* pType = nullptr;
200 const size_t nCount = aMgr.GetFieldTypeCount();
201 if( !rName.isEmpty() )
203 for (size_t i = 0; i < nCount; ++i)
205 pType = aMgr.GetFieldType(SwFieldIds::Unknown, i);
206 OUString aTmpName( pType->GetName() );
207 if (aTmpName == rName && pType->Which() == SwFieldIds::SetExp)
209 nID = i;
210 OSL_ENSURE(nID==i, "Downcasting to sal_uInt16 lost information!");
211 break;
215 rSh.StartAllAction();
217 GetWrtShell().InsertLabel( eT,
218 pOpt->GetCaption(),
219 !pOpt->IgnoreSeqOpts() ? OUString() : pOpt->GetSeparator(),
220 pOpt->GetNumSeparator(),
221 !pOpt->GetPos(),
222 nID,
223 pOpt->GetCharacterStyle(),
224 pOpt->CopyAttributes() );
225 // Set Number Format
226 if(pType)
227 static_cast<SwSetExpFieldType*>(pType)->SetSeqFormat(pOpt->GetNumType());
229 rSh.UpdateExpFields( true );
231 rSh.EndAllAction();
233 if ( rSh.IsFrameSelected() )
235 GetEditWin().StopInsFrame();
236 rSh.EnterSelFrameMode();
239 // remember category
240 if (eType & SelectionType::Graphic)
241 SetOldGrfCat(rName);
242 else if( eType & SelectionType::Table)
243 SetOldTabCat(rName);
244 else if( eType & SelectionType::Frame)
245 SetOldFrameCat(rName);
246 else if( eType == SelectionType::Text)
247 SetOldFrameCat(rName);
248 else if( eType & SelectionType::DrawObject)
249 SetOldDrwCat(rName);
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */