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
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();
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
));
73 case SID_INSERT_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
));
83 case SID_ADDITIONS_DIALOG
:
85 OUString sAdditionsTag
= "";
87 const SfxStringItem
* pStringArg
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_ADDITIONS_TAG
);
89 sAdditionsTag
= pStringArg
->GetValue();
91 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
92 ScopedVclPtr
<AbstractAdditionsDialog
> pDialog(
93 pFact
->CreateAdditionsDialog(GetFrameWeld(), sAdditionsTag
));
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
));
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
) );
120 bool SwView::isSignatureLineSelected() const
122 SwWrtShell
& rSh
= GetWrtShell();
123 SdrView
* pSdrView
= rSh
.GetDrawView();
127 if (pSdrView
->GetMarkedObjectCount() != 1)
130 SdrObject
* pPickObj
= pSdrView
->GetMarkedObjectByIndex(0);
134 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
138 return pGraphic
->isSignatureLine();
141 bool SwView::isSignatureLineSigned() const
143 SwWrtShell
& rSh
= GetWrtShell();
144 SdrView
* pSdrView
= rSh
.GetDrawView();
148 if (pSdrView
->GetMarkedObjectCount() != 1)
151 SdrObject
* pPickObj
= pSdrView
->GetMarkedObjectByIndex(0);
155 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
159 return pGraphic
->isSignatureLineSigned();
162 bool SwView::isQRCodeSelected() const
164 SwWrtShell
& rSh
= GetWrtShell();
165 SdrView
* pSdrView
= rSh
.GetDrawView();
169 if (pSdrView
->GetMarkedObjectCount() != 1)
172 SdrObject
* pPickObj
= pSdrView
->GetMarkedObjectByIndex(0);
176 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
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())
196 void SwView::InsertCaption(const InsCaptionOpt
*pOpt
)
201 const OUString
&rName
= pOpt
->GetCategory();
203 // Is there a pool template with the same name?
204 SwWrtShell
&rSh
= GetWrtShell();
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
:
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())
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
)
261 OSL_ENSURE(nID
==i
, "Downcasting to sal_uInt16 lost information!");
266 rSh
.StartAllAction();
268 GetWrtShell().InsertLabel( eT
,
270 !pOpt
->IgnoreSeqOpts() ? OUString() : pOpt
->GetSeparator(),
271 pOpt
->GetNumSeparator(),
274 pOpt
->GetCharacterStyle(),
275 pOpt
->CopyAttributes() );
278 static_cast<SwSetExpFieldType
*>(pType
)->SetSeqFormat(pOpt
->GetNumType());
280 rSh
.UpdateExpFields( true );
284 if ( rSh
.IsFrameSelected() )
286 GetEditWin().StopInsFrame();
287 rSh
.EnterSelFrameMode();
291 if (eType
& SelectionType::Graphic
)
293 else if( eType
& SelectionType::Table
)
295 else if( eType
& SelectionType::Frame
)
296 SetOldFrameCat(rName
);
297 else if( eType
== SelectionType::Text
)
298 SetOldFrameCat(rName
);
299 else if( eType
& SelectionType::DrawObject
)
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */