/src/libreoffice/sw/source/uibase/uiview/viewdlg2.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
28 | | |
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> |
38 | | |
39 | | #include <swabstdlg.hxx> |
40 | | |
41 | | #include <strings.hrc> |
42 | | |
43 | | #include <memory> |
44 | | |
45 | | #include <svl/stritem.hxx> |
46 | | |
47 | | using namespace css; |
48 | | |
49 | | void SwView::ExecDlgExt(SfxRequest& rReq) |
50 | 0 | { |
51 | 0 | switch (rReq.GetSlot()) |
52 | 0 | { |
53 | 0 | case FN_INSERT_CAPTION: |
54 | 0 | { |
55 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
56 | 0 | VclPtr<VclAbstractDialog> pDialog( |
57 | 0 | pFact->CreateSwCaptionDialog(GetFrameWeld(), *this)); |
58 | 0 | pDialog->StartExecuteAsync([pDialog](sal_Int32) { |
59 | 0 | pDialog->disposeOnce(); |
60 | 0 | }); |
61 | 0 | break; |
62 | 0 | } |
63 | 0 | case SID_INSERT_SIGNATURELINE: |
64 | 0 | case SID_EDIT_SIGNATURELINE: |
65 | 0 | { |
66 | 0 | VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create(); |
67 | 0 | const uno::Reference<frame::XModel> xModel(GetCurrentDocument()); |
68 | 0 | VclPtr<AbstractSignatureLineDialog> pDialog(pFact->CreateSignatureLineDialog( |
69 | 0 | GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_SIGNATURELINE)); |
70 | 0 | auto xRequest = std::make_shared<SfxRequest>(rReq); |
71 | 0 | rReq.Ignore(); // the 'old' request is not relevant any more |
72 | 0 | pDialog->StartExecuteAsync( |
73 | 0 | [pDialog, xRequest=std::move(xRequest)] (sal_Int32 nResult)->void |
74 | 0 | { |
75 | 0 | if (nResult == RET_OK) |
76 | 0 | pDialog->Apply(); |
77 | 0 | pDialog->disposeOnce(); |
78 | 0 | xRequest->Done(); |
79 | 0 | } |
80 | 0 | ); |
81 | 0 | break; |
82 | 0 | } |
83 | 0 | case SID_INSERT_QRCODE: |
84 | 0 | case SID_EDIT_QRCODE: |
85 | 0 | { |
86 | 0 | VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create(); |
87 | 0 | const uno::Reference<frame::XModel> xModel(GetCurrentDocument()); |
88 | 0 | VclPtr<AbstractQrCodeGenDialog> pDialog(pFact->CreateQrCodeGenDialog( |
89 | 0 | GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_QRCODE)); |
90 | 0 | pDialog->StartExecuteAsync([pDialog](sal_Int32) { |
91 | 0 | pDialog->disposeOnce(); |
92 | 0 | }); |
93 | 0 | break; |
94 | 0 | } |
95 | | |
96 | 0 | case SID_SIGN_SIGNATURELINE: |
97 | 0 | { |
98 | 0 | VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create(); |
99 | 0 | const uno::Reference<frame::XModel> xModel(GetCurrentDocument()); |
100 | 0 | VclPtr<AbstractSignSignatureLineDialog> pDialog( |
101 | 0 | pFact->CreateSignSignatureLineDialog(GetFrameWeld(), xModel)); |
102 | 0 | pDialog->StartExecuteAsync( |
103 | 0 | [pDialog] (sal_Int32 nResult)->void |
104 | 0 | { |
105 | 0 | if (nResult == RET_OK) |
106 | 0 | pDialog->Apply(); |
107 | 0 | pDialog->disposeOnce(); |
108 | 0 | } |
109 | 0 | ); |
110 | 0 | break; |
111 | 0 | } |
112 | 0 | case FN_EDIT_FOOTNOTE: |
113 | 0 | { |
114 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
115 | 0 | VclPtr<AbstractInsFootNoteDlg> pDlg(pFact->CreateInsFootNoteDlg( |
116 | 0 | GetFrameWeld(), *m_pWrtShell, true)); |
117 | |
|
118 | 0 | pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand()); |
119 | 0 | pDlg->SetText( SwResId(STR_EDIT_FOOTNOTE) ); |
120 | 0 | pDlg->StartExecuteAsync( |
121 | 0 | [pDlg] (sal_Int32 nResult)->void |
122 | 0 | { |
123 | 0 | if (nResult == RET_OK) |
124 | 0 | pDlg->Apply(); |
125 | 0 | pDlg->disposeOnce(); |
126 | 0 | } |
127 | 0 | ); |
128 | 0 | break; |
129 | 0 | } |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | | bool SwView::isSignatureLineSelected() const |
134 | 0 | { |
135 | 0 | SwWrtShell& rSh = GetWrtShell(); |
136 | 0 | SdrView* pSdrView = rSh.GetDrawView(); |
137 | 0 | if (!pSdrView) |
138 | 0 | return false; |
139 | | |
140 | 0 | if (pSdrView->GetMarkedObjectList().GetMarkCount() != 1) |
141 | 0 | return false; |
142 | | |
143 | 0 | SdrObject* pPickObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(); |
144 | 0 | if (!pPickObj) |
145 | 0 | return false; |
146 | | |
147 | 0 | SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj); |
148 | 0 | if (!pGraphic) |
149 | 0 | return false; |
150 | | |
151 | 0 | return pGraphic->isSignatureLine(); |
152 | 0 | } |
153 | | |
154 | | bool SwView::isSignatureLineSigned() const |
155 | 0 | { |
156 | 0 | SwWrtShell& rSh = GetWrtShell(); |
157 | 0 | SdrView* pSdrView = rSh.GetDrawView(); |
158 | 0 | if (!pSdrView) |
159 | 0 | return false; |
160 | | |
161 | 0 | if (pSdrView->GetMarkedObjectList().GetMarkCount() != 1) |
162 | 0 | return false; |
163 | | |
164 | 0 | SdrObject* pPickObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(); |
165 | 0 | if (!pPickObj) |
166 | 0 | return false; |
167 | | |
168 | 0 | SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj); |
169 | 0 | if (!pGraphic) |
170 | 0 | return false; |
171 | | |
172 | 0 | return pGraphic->isSignatureLineSigned(); |
173 | 0 | } |
174 | | |
175 | | bool SwView::isQRCodeSelected() const |
176 | 0 | { |
177 | 0 | SwWrtShell& rSh = GetWrtShell(); |
178 | 0 | SdrView* pSdrView = rSh.GetDrawView(); |
179 | 0 | if (!pSdrView) |
180 | 0 | return false; |
181 | | |
182 | 0 | if (pSdrView->GetMarkedObjectList().GetMarkCount() != 1) |
183 | 0 | return false; |
184 | | |
185 | 0 | SdrObject* pPickObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(); |
186 | 0 | if (!pPickObj) |
187 | 0 | return false; |
188 | | |
189 | 0 | SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj); |
190 | 0 | if (!pGraphic) |
191 | 0 | return false; |
192 | | |
193 | 0 | return pGraphic->getQrCode() != nullptr; |
194 | 0 | } |
195 | | |
196 | | void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId) |
197 | 0 | { |
198 | 0 | SwModuleOptions* pModOpt = SwModule::get()->GetModuleConfig(); |
199 | |
|
200 | 0 | bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr; |
201 | 0 | if (pModOpt->IsInsWithCaption(bWeb)) |
202 | 0 | { |
203 | 0 | const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, static_cast<SwCapObjType>(nType), pOleId); |
204 | 0 | if (pOpt && pOpt->UseCaption()) |
205 | 0 | InsertCaption(pOpt); |
206 | 0 | } |
207 | 0 | } |
208 | | |
209 | | void SwView::InsertCaption(const InsCaptionOpt *pOpt) |
210 | 0 | { |
211 | 0 | if (!pOpt) |
212 | 0 | return; |
213 | | |
214 | 0 | const OUString &rName = pOpt->GetCategory(); |
215 | | |
216 | | // Is there a pool template with the same name? |
217 | 0 | SwWrtShell &rSh = GetWrtShell(); |
218 | 0 | if(!rName.isEmpty()) |
219 | 0 | { |
220 | 0 | sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName(UIName(rName), SwGetPoolIdFromName::TxtColl); |
221 | 0 | if( USHRT_MAX != nPoolId ) |
222 | 0 | rSh.GetTextCollFromPool(nPoolId); |
223 | | // Pool template does not exist: Does it exist on the document? |
224 | 0 | else if( !rSh.GetParaStyle(UIName(rName)) ) |
225 | 0 | { |
226 | | // It also does not exist in the document: generate |
227 | 0 | SwTextFormatColl* pDerivedFrom = rSh.GetTextCollFromPool(RES_POOLCOLL_LABEL); |
228 | 0 | rSh.MakeTextFormatColl(UIName(rName), pDerivedFrom); |
229 | 0 | } |
230 | 0 | } |
231 | |
|
232 | 0 | SelectionType eType = rSh.GetSelectionType(); |
233 | 0 | if (eType & SelectionType::Ole) |
234 | 0 | eType = SelectionType::Graphic; |
235 | |
|
236 | 0 | const SwLabelType eT = (eType & SelectionType::Table) ? SwLabelType::Table : |
237 | 0 | (eType & SelectionType::Frame) ? SwLabelType::Fly : |
238 | 0 | (eType == SelectionType::Text) ? SwLabelType::Fly : |
239 | 0 | (eType & SelectionType::DrawObject) ? SwLabelType::Draw : |
240 | 0 | SwLabelType::Object; |
241 | |
|
242 | 0 | SwFieldMgr aMgr(&rSh); |
243 | 0 | SwSetExpFieldType* pFieldType = |
244 | 0 | static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName)); |
245 | 0 | if (!pFieldType && !rName.isEmpty() ) |
246 | 0 | { |
247 | | // Create new field types |
248 | 0 | SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), UIName(rName), SwGetSetExpType::Sequence); |
249 | 0 | aMgr.InsertFieldType(aSwSetExpFieldType); |
250 | 0 | pFieldType = static_cast<SwSetExpFieldType*>(aMgr.GetFieldType(SwFieldIds::SetExp, rName)); |
251 | 0 | } |
252 | |
|
253 | 0 | if (!pOpt->IgnoreSeqOpts()) |
254 | 0 | { |
255 | 0 | if (pFieldType) |
256 | 0 | { |
257 | 0 | pFieldType->SetDelimiter(pOpt->GetSeparator()); |
258 | 0 | pFieldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) ); |
259 | 0 | } |
260 | 0 | } |
261 | |
|
262 | 0 | sal_uInt16 nID = USHRT_MAX; |
263 | 0 | SwFieldType* pType = nullptr; |
264 | 0 | const size_t nCount = aMgr.GetFieldTypeCount(); |
265 | 0 | if( !rName.isEmpty() ) |
266 | 0 | { |
267 | 0 | for (size_t i = 0; i < nCount; ++i) |
268 | 0 | { |
269 | 0 | pType = aMgr.GetFieldType(SwFieldIds::Unknown, i); |
270 | 0 | UIName aTmpName( pType->GetName() ); |
271 | 0 | if (aTmpName == rName && pType->Which() == SwFieldIds::SetExp) |
272 | 0 | { |
273 | 0 | nID = i; |
274 | 0 | OSL_ENSURE(nID==i, "Downcasting to sal_uInt16 lost information!"); |
275 | 0 | break; |
276 | 0 | } |
277 | 0 | } |
278 | 0 | } |
279 | 0 | rSh.StartAllAction(); |
280 | |
|
281 | 0 | GetWrtShell().InsertLabel( eT, |
282 | 0 | pOpt->GetCaption(), |
283 | 0 | !pOpt->IgnoreSeqOpts() ? OUString() : pOpt->GetSeparator(), |
284 | 0 | pOpt->GetNumSeparator(), |
285 | 0 | !pOpt->GetPos(), |
286 | 0 | nID, |
287 | 0 | pOpt->GetCharacterStyle(), |
288 | 0 | pOpt->CopyAttributes() ); |
289 | | // Set Number Format |
290 | 0 | if(pType) |
291 | 0 | static_cast<SwSetExpFieldType*>(pType)->SetSeqFormat(pOpt->GetNumType()); |
292 | |
|
293 | 0 | rSh.UpdateExpFields( true ); |
294 | |
|
295 | 0 | rSh.EndAllAction(); |
296 | |
|
297 | 0 | if ( rSh.IsFrameSelected() ) |
298 | 0 | { |
299 | 0 | GetEditWin().StopInsFrame(); |
300 | 0 | rSh.EnterSelFrameMode(); |
301 | 0 | } |
302 | | |
303 | | // remember category |
304 | 0 | if (eType & SelectionType::Graphic) |
305 | 0 | SetOldGrfCat(rName); |
306 | 0 | else if( eType & SelectionType::Table) |
307 | 0 | SetOldTabCat(rName); |
308 | 0 | else if( eType & SelectionType::Frame) |
309 | 0 | SetOldFrameCat(rName); |
310 | 0 | else if( eType == SelectionType::Text) |
311 | 0 | SetOldFrameCat(rName); |
312 | 0 | else if( eType & SelectionType::DrawObject) |
313 | 0 | SetOldDrwCat(rName); |
314 | 0 | } |
315 | | |
316 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |