Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uiview / viewdlg2.cxx
blob19678d38fdcbc71d36794c2613e9fd1721c5de33
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/objface.hxx>
22 #include <svx/svdograf.hxx>
23 #include <svx/svdview.hxx>
24 #include <osl/diagnose.h>
25 #include <fldmgr.hxx>
26 #include <expfld.hxx>
27 #include <modcfg.hxx>
29 #include <swmodule.hxx>
30 #include <view.hxx>
31 #include <wview.hxx>
32 #include <wrtsh.hxx>
33 #include <cmdid.h>
34 #include <caption.hxx>
35 #include <poolfmt.hxx>
36 #include <edtwin.hxx>
37 #include <SwStyleNameMapper.hxx>
39 #include <swabstdlg.hxx>
41 #include <strings.hrc>
43 #include <memory>
45 #include <svl/stritem.hxx>
47 using namespace css;
49 void SwView::ExecDlgExt(SfxRequest const& rReq)
51 switch (rReq.GetSlot())
53 case FN_INSERT_CAPTION:
55 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
56 VclPtr<VclAbstractDialog> pDialog(
57 pFact->CreateSwCaptionDialog(GetFrameWeld(), *this));
58 pDialog->StartExecuteAsync([pDialog](sal_Int32) {
59 pDialog->disposeOnce();
60 });
61 break;
63 case SID_INSERT_SIGNATURELINE:
64 case SID_EDIT_SIGNATURELINE:
66 VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
67 const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
68 ScopedVclPtr<AbstractSignatureLineDialog> pDialog(pFact->CreateSignatureLineDialog(
69 GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_SIGNATURELINE));
70 pDialog->Execute();
71 break;
73 case SID_INSERT_QRCODE:
74 case SID_EDIT_QRCODE:
76 VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
77 const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
78 ScopedVclPtr<AbstractQrCodeGenDialog> pDialog(pFact->CreateQrCodeGenDialog(
79 GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_QRCODE));
80 pDialog->Execute();
81 break;
83 case SID_ADDITIONS_DIALOG:
85 OUString sAdditionsTag = "";
87 const SfxStringItem* pStringArg = rReq.GetArg<SfxStringItem>(FN_PARAM_ADDITIONS_TAG);
88 if (pStringArg)
89 sAdditionsTag = pStringArg->GetValue();
91 VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
92 ScopedVclPtr<AbstractAdditionsDialog> pDialog(
93 pFact->CreateAdditionsDialog(GetFrameWeld(), sAdditionsTag));
94 pDialog->Execute();
95 break;
97 case SID_SIGN_SIGNATURELINE:
99 VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
100 const uno::Reference<frame::XModel> xModel(GetCurrentDocument());
101 ScopedVclPtr<AbstractSignSignatureLineDialog> pDialog(
102 pFact->CreateSignSignatureLineDialog(GetFrameWeld(), xModel));
103 pDialog->Execute();
104 break;
106 case FN_EDIT_FOOTNOTE:
108 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
109 ScopedVclPtr<AbstractInsFootNoteDlg> pDlg(pFact->CreateInsFootNoteDlg(
110 GetFrameWeld(), *m_pWrtShell, true));
112 pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
113 pDlg->SetText( SwResId(STR_EDIT_FOOTNOTE) );
114 pDlg->Execute();
115 break;
120 bool SwView::isSignatureLineSelected() const
122 SwWrtShell& rSh = GetWrtShell();
123 SdrView* pSdrView = rSh.GetDrawView();
124 if (!pSdrView)
125 return false;
127 if (pSdrView->GetMarkedObjectCount() != 1)
128 return false;
130 SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
131 if (!pPickObj)
132 return false;
134 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
135 if (!pGraphic)
136 return false;
138 return pGraphic->isSignatureLine();
141 bool SwView::isSignatureLineSigned() const
143 SwWrtShell& rSh = GetWrtShell();
144 SdrView* pSdrView = rSh.GetDrawView();
145 if (!pSdrView)
146 return false;
148 if (pSdrView->GetMarkedObjectCount() != 1)
149 return false;
151 SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
152 if (!pPickObj)
153 return false;
155 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
156 if (!pGraphic)
157 return false;
159 return pGraphic->isSignatureLineSigned();
162 bool SwView::isQRCodeSelected() const
164 SwWrtShell& rSh = GetWrtShell();
165 SdrView* pSdrView = rSh.GetDrawView();
166 if (!pSdrView)
167 return false;
169 if (pSdrView->GetMarkedObjectCount() != 1)
170 return false;
172 SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
173 if (!pPickObj)
174 return false;
176 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
177 if (!pGraphic)
178 return false;
180 return pGraphic->getQrCode() != nullptr;
183 void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
185 SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
187 bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
188 if (pModOpt->IsInsWithCaption(bWeb))
190 const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, static_cast<SwCapObjType>(nType), pOleId);
191 if (pOpt && pOpt->UseCaption())
192 InsertCaption(pOpt);
196 void SwView::InsertCaption(const InsCaptionOpt *pOpt)
198 if (!pOpt)
199 return;
201 const OUString &rName = pOpt->GetCategory();
203 // Is there a pool template with the same name?
204 SwWrtShell &rSh = GetWrtShell();
205 if(!rName.isEmpty())
207 sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName(rName, SwGetPoolIdFromName::TxtColl);
208 if( USHRT_MAX != nPoolId )
209 rSh.GetTextCollFromPool(nPoolId);
210 // Pool template does not exist: Does it exist on the document?
211 else if( !rSh.GetParaStyle(rName) )
213 // It also does not exist in the document: generate
214 SwTextFormatColl* pDerivedFrom = rSh.GetTextCollFromPool(RES_POOLCOLL_LABEL);
215 rSh.MakeTextFormatColl(rName, pDerivedFrom);
219 SelectionType eType = rSh.GetSelectionType();
220 if (eType & SelectionType::Ole)
221 eType = SelectionType::Graphic;
223 const SwLabelType eT = (eType & SelectionType::Table) ? SwLabelType::Table :
224 (eType & SelectionType::Frame) ? SwLabelType::Fly :
225 (eType == SelectionType::Text) ? SwLabelType::Fly :
226 (eType & SelectionType::DrawObject) ? SwLabelType::Draw :
227 SwLabelType::Object;
229 SwFieldMgr aMgr(&rSh);
230 SwSetExpFieldType* pFieldType =
231 static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
232 if (!pFieldType && !rName.isEmpty() )
234 // Create new field types
235 SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
236 aMgr.InsertFieldType(aSwSetExpFieldType);
237 pFieldType = static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName));
240 if (!pOpt->IgnoreSeqOpts())
242 if (pFieldType)
244 pFieldType->SetDelimiter(pOpt->GetSeparator());
245 pFieldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
249 sal_uInt16 nID = USHRT_MAX;
250 SwFieldType* pType = nullptr;
251 const size_t nCount = aMgr.GetFieldTypeCount();
252 if( !rName.isEmpty() )
254 for (size_t i = 0; i < nCount; ++i)
256 pType = aMgr.GetFieldType(SwFieldIds::Unknown, i);
257 OUString aTmpName( pType->GetName() );
258 if (aTmpName == rName && pType->Which() == SwFieldIds::SetExp)
260 nID = i;
261 OSL_ENSURE(nID==i, "Downcasting to sal_uInt16 lost information!");
262 break;
266 rSh.StartAllAction();
268 GetWrtShell().InsertLabel( eT,
269 pOpt->GetCaption(),
270 !pOpt->IgnoreSeqOpts() ? OUString() : pOpt->GetSeparator(),
271 pOpt->GetNumSeparator(),
272 !pOpt->GetPos(),
273 nID,
274 pOpt->GetCharacterStyle(),
275 pOpt->CopyAttributes() );
276 // Set Number Format
277 if(pType)
278 static_cast<SwSetExpFieldType*>(pType)->SetSeqFormat(pOpt->GetNumType());
280 rSh.UpdateExpFields( true );
282 rSh.EndAllAction();
284 if ( rSh.IsFrameSelected() )
286 GetEditWin().StopInsFrame();
287 rSh.EnterSelFrameMode();
290 // remember category
291 if (eType & SelectionType::Graphic)
292 SetOldGrfCat(rName);
293 else if( eType & SelectionType::Table)
294 SetOldTabCat(rName);
295 else if( eType & SelectionType::Frame)
296 SetOldFrameCat(rName);
297 else if( eType == SelectionType::Text)
298 SetOldFrameCat(rName);
299 else if( eType & SelectionType::DrawObject)
300 SetOldDrwCat(rName);
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */