1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 #include <swmodule.hxx>
34 #include <caption.hxx>
35 #include <poolfmt.hxx>
37 #include <SwStyleNameMapper.hxx>
39 #include <swabstdlg.hxx>
41 #include <strings.hrc>
45 #include <svl/stritem.hxx>
49 void SwView::ExecDlgExt(SfxRequest
& 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();
63 case SID_INSERT_SIGNATURELINE
:
64 case SID_EDIT_SIGNATURELINE
:
66 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
67 const uno::Reference
<frame::XModel
> xModel(GetCurrentDocument());
68 VclPtr
<AbstractSignatureLineDialog
> pDialog(pFact
->CreateSignatureLineDialog(
69 GetFrameWeld(), xModel
, rReq
.GetSlot() == SID_EDIT_SIGNATURELINE
));
70 auto xRequest
= std::make_shared
<SfxRequest
>(rReq
);
71 rReq
.Ignore(); // the 'old' request is not relevant any more
72 pDialog
->StartExecuteAsync(
73 [pDialog
, xRequest
=std::move(xRequest
)] (sal_Int32 nResult
)->void
75 if (nResult
== RET_OK
)
77 pDialog
->disposeOnce();
83 case SID_INSERT_QRCODE
:
86 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
87 const uno::Reference
<frame::XModel
> xModel(GetCurrentDocument());
88 VclPtr
<AbstractQrCodeGenDialog
> pDialog(pFact
->CreateQrCodeGenDialog(
89 GetFrameWeld(), xModel
, rReq
.GetSlot() == SID_EDIT_QRCODE
));
90 pDialog
->StartExecuteAsync([pDialog
](sal_Int32
) {
91 pDialog
->disposeOnce();
96 case SID_SIGN_SIGNATURELINE
:
98 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
99 const uno::Reference
<frame::XModel
> xModel(GetCurrentDocument());
100 VclPtr
<AbstractSignSignatureLineDialog
> pDialog(
101 pFact
->CreateSignSignatureLineDialog(GetFrameWeld(), xModel
));
102 pDialog
->StartExecuteAsync(
103 [pDialog
] (sal_Int32 nResult
)->void
105 if (nResult
== RET_OK
)
107 pDialog
->disposeOnce();
112 case FN_EDIT_FOOTNOTE
:
114 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
115 VclPtr
<AbstractInsFootNoteDlg
> pDlg(pFact
->CreateInsFootNoteDlg(
116 GetFrameWeld(), *m_pWrtShell
, true));
118 pDlg
->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE
)->GetCommand());
119 pDlg
->SetText( SwResId(STR_EDIT_FOOTNOTE
) );
120 pDlg
->StartExecuteAsync(
121 [pDlg
] (sal_Int32 nResult
)->void
123 if (nResult
== RET_OK
)
133 bool SwView::isSignatureLineSelected() const
135 SwWrtShell
& rSh
= GetWrtShell();
136 SdrView
* pSdrView
= rSh
.GetDrawView();
140 if (pSdrView
->GetMarkedObjectList().GetMarkCount() != 1)
143 SdrObject
* pPickObj
= pSdrView
->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
147 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
151 return pGraphic
->isSignatureLine();
154 bool SwView::isSignatureLineSigned() const
156 SwWrtShell
& rSh
= GetWrtShell();
157 SdrView
* pSdrView
= rSh
.GetDrawView();
161 if (pSdrView
->GetMarkedObjectList().GetMarkCount() != 1)
164 SdrObject
* pPickObj
= pSdrView
->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
168 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
172 return pGraphic
->isSignatureLineSigned();
175 bool SwView::isQRCodeSelected() const
177 SwWrtShell
& rSh
= GetWrtShell();
178 SdrView
* pSdrView
= rSh
.GetDrawView();
182 if (pSdrView
->GetMarkedObjectList().GetMarkCount() != 1)
185 SdrObject
* pPickObj
= pSdrView
->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
189 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
193 return pGraphic
->getQrCode() != nullptr;
196 void SwView::AutoCaption(const sal_uInt16 nType
, const SvGlobalName
*pOleId
)
198 SwModuleOptions
* pModOpt
= SwModule::get()->GetModuleConfig();
200 bool bWeb
= dynamic_cast<SwWebView
*>( this ) != nullptr;
201 if (pModOpt
->IsInsWithCaption(bWeb
))
203 const InsCaptionOpt
*pOpt
= pModOpt
->GetCapOption(bWeb
, static_cast<SwCapObjType
>(nType
), pOleId
);
204 if (pOpt
&& pOpt
->UseCaption())
209 void SwView::InsertCaption(const InsCaptionOpt
*pOpt
)
214 const OUString
&rName
= pOpt
->GetCategory();
216 // Is there a pool template with the same name?
217 SwWrtShell
&rSh
= GetWrtShell();
220 sal_uInt16 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName(rName
, SwGetPoolIdFromName::TxtColl
);
221 if( USHRT_MAX
!= nPoolId
)
222 rSh
.GetTextCollFromPool(nPoolId
);
223 // Pool template does not exist: Does it exist on the document?
224 else if( !rSh
.GetParaStyle(rName
) )
226 // It also does not exist in the document: generate
227 SwTextFormatColl
* pDerivedFrom
= rSh
.GetTextCollFromPool(RES_POOLCOLL_LABEL
);
228 rSh
.MakeTextFormatColl(rName
, pDerivedFrom
);
232 SelectionType eType
= rSh
.GetSelectionType();
233 if (eType
& SelectionType::Ole
)
234 eType
= SelectionType::Graphic
;
236 const SwLabelType eT
= (eType
& SelectionType::Table
) ? SwLabelType::Table
:
237 (eType
& SelectionType::Frame
) ? SwLabelType::Fly
:
238 (eType
== SelectionType::Text
) ? SwLabelType::Fly
:
239 (eType
& SelectionType::DrawObject
) ? SwLabelType::Draw
:
242 SwFieldMgr
aMgr(&rSh
);
243 SwSetExpFieldType
* pFieldType
=
244 static_cast<SwSetExpFieldType
*>(aMgr
.GetFieldType(SwFieldIds::SetExp
, rName
));
245 if (!pFieldType
&& !rName
.isEmpty() )
247 // Create new field types
248 SwSetExpFieldType
aSwSetExpFieldType(rSh
.GetDoc(), rName
, nsSwGetSetExpType::GSE_SEQ
);
249 aMgr
.InsertFieldType(aSwSetExpFieldType
);
250 pFieldType
= static_cast<SwSetExpFieldType
*>(aMgr
.GetFieldType(SwFieldIds::SetExp
, rName
));
253 if (!pOpt
->IgnoreSeqOpts())
257 pFieldType
->SetDelimiter(pOpt
->GetSeparator());
258 pFieldType
->SetOutlineLvl( static_cast< sal_uInt8
>(pOpt
->GetLevel()) );
262 sal_uInt16 nID
= USHRT_MAX
;
263 SwFieldType
* pType
= nullptr;
264 const size_t nCount
= aMgr
.GetFieldTypeCount();
265 if( !rName
.isEmpty() )
267 for (size_t i
= 0; i
< nCount
; ++i
)
269 pType
= aMgr
.GetFieldType(SwFieldIds::Unknown
, i
);
270 OUString
aTmpName( pType
->GetName() );
271 if (aTmpName
== rName
&& pType
->Which() == SwFieldIds::SetExp
)
274 OSL_ENSURE(nID
==i
, "Downcasting to sal_uInt16 lost information!");
279 rSh
.StartAllAction();
281 GetWrtShell().InsertLabel( eT
,
283 !pOpt
->IgnoreSeqOpts() ? OUString() : pOpt
->GetSeparator(),
284 pOpt
->GetNumSeparator(),
287 pOpt
->GetCharacterStyle(),
288 pOpt
->CopyAttributes() );
291 static_cast<SwSetExpFieldType
*>(pType
)->SetSeqFormat(pOpt
->GetNumType());
293 rSh
.UpdateExpFields( true );
297 if ( rSh
.IsFrameSelected() )
299 GetEditWin().StopInsFrame();
300 rSh
.EnterSelFrameMode();
304 if (eType
& SelectionType::Graphic
)
306 else if( eType
& SelectionType::Table
)
308 else if( eType
& SelectionType::Frame
)
309 SetOldFrameCat(rName
);
310 else if( eType
== SelectionType::Text
)
311 SetOldFrameCat(rName
);
312 else if( eType
& SelectionType::DrawObject
)
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */