docthemes: Save themes def. to a file when added to ColorSets
[LibreOffice.git] / sw / source / uibase / uiview / viewdlg2.cxx
blob49112bb7749531c61705993edb4e50aa79006a8f
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& 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 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)
76 pDialog->Apply();
77 pDialog->disposeOnce();
78 xRequest->Done();
81 break;
83 case SID_INSERT_QRCODE:
84 case SID_EDIT_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();
92 });
93 break;
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)
106 pDialog->Apply();
107 pDialog->disposeOnce();
110 break;
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)
124 pDlg->Apply();
125 pDlg->disposeOnce();
128 break;
133 bool SwView::isSignatureLineSelected() const
135 SwWrtShell& rSh = GetWrtShell();
136 SdrView* pSdrView = rSh.GetDrawView();
137 if (!pSdrView)
138 return false;
140 if (pSdrView->GetMarkedObjectList().GetMarkCount() != 1)
141 return false;
143 SdrObject* pPickObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
144 if (!pPickObj)
145 return false;
147 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
148 if (!pGraphic)
149 return false;
151 return pGraphic->isSignatureLine();
154 bool SwView::isSignatureLineSigned() const
156 SwWrtShell& rSh = GetWrtShell();
157 SdrView* pSdrView = rSh.GetDrawView();
158 if (!pSdrView)
159 return false;
161 if (pSdrView->GetMarkedObjectList().GetMarkCount() != 1)
162 return false;
164 SdrObject* pPickObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
165 if (!pPickObj)
166 return false;
168 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
169 if (!pGraphic)
170 return false;
172 return pGraphic->isSignatureLineSigned();
175 bool SwView::isQRCodeSelected() const
177 SwWrtShell& rSh = GetWrtShell();
178 SdrView* pSdrView = rSh.GetDrawView();
179 if (!pSdrView)
180 return false;
182 if (pSdrView->GetMarkedObjectList().GetMarkCount() != 1)
183 return false;
185 SdrObject* pPickObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
186 if (!pPickObj)
187 return false;
189 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
190 if (!pGraphic)
191 return false;
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())
205 InsertCaption(pOpt);
209 void SwView::InsertCaption(const InsCaptionOpt *pOpt)
211 if (!pOpt)
212 return;
214 const OUString &rName = pOpt->GetCategory();
216 // Is there a pool template with the same name?
217 SwWrtShell &rSh = GetWrtShell();
218 if(!rName.isEmpty())
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 :
240 SwLabelType::Object;
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())
255 if (pFieldType)
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)
273 nID = i;
274 OSL_ENSURE(nID==i, "Downcasting to sal_uInt16 lost information!");
275 break;
279 rSh.StartAllAction();
281 GetWrtShell().InsertLabel( eT,
282 pOpt->GetCaption(),
283 !pOpt->IgnoreSeqOpts() ? OUString() : pOpt->GetSeparator(),
284 pOpt->GetNumSeparator(),
285 !pOpt->GetPos(),
286 nID,
287 pOpt->GetCharacterStyle(),
288 pOpt->CopyAttributes() );
289 // Set Number Format
290 if(pType)
291 static_cast<SwSetExpFieldType*>(pType)->SetSeqFormat(pOpt->GetNumType());
293 rSh.UpdateExpFields( true );
295 rSh.EndAllAction();
297 if ( rSh.IsFrameSelected() )
299 GetEditWin().StopInsFrame();
300 rSh.EnterSelFrameMode();
303 // remember category
304 if (eType & SelectionType::Graphic)
305 SetOldGrfCat(rName);
306 else if( eType & SelectionType::Table)
307 SetOldTabCat(rName);
308 else if( eType & SelectionType::Frame)
309 SetOldFrameCat(rName);
310 else if( eType == SelectionType::Text)
311 SetOldFrameCat(rName);
312 else if( eType & SelectionType::DrawObject)
313 SetOldDrwCat(rName);
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */