File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <com/sun/star/i18n/WordType.hpp> | |||
21 | #include <com/sun/star/linguistic2/XThesaurus.hpp> | |||
22 | ||||
23 | #include <hintids.hxx> | |||
24 | #include <cmdid.h> | |||
25 | #include <comphelper/lok.hxx> | |||
26 | ||||
27 | #include <i18nutil/unicode.hxx> | |||
28 | #include <i18nlangtag/languagetag.hxx> | |||
29 | #include <svtools/langtab.hxx> | |||
30 | #include <svl/slstitm.hxx> | |||
31 | #include <svl/stritem.hxx> | |||
32 | #include <sfx2/htmlmode.hxx> | |||
33 | #include <svl/whiter.hxx> | |||
34 | #include <sfx2/bindings.hxx> | |||
35 | #include <sfx2/viewfrm.hxx> | |||
36 | #include <vcl/unohelp2.hxx> | |||
37 | #include <vcl/weld.hxx> | |||
38 | #include <sfx2/request.hxx> | |||
39 | #include <svl/eitem.hxx> | |||
40 | #include <editeng/lrspitem.hxx> | |||
41 | #include <editeng/colritem.hxx> | |||
42 | #include <editeng/tstpitem.hxx> | |||
43 | #include <editeng/brushitem.hxx> | |||
44 | #include <editeng/svxacorr.hxx> | |||
45 | #include <svl/cjkoptions.hxx> | |||
46 | #include <svl/ctloptions.hxx> | |||
47 | #include <IDocumentDrawModelAccess.hxx> | |||
48 | #include <IDocumentSettingAccess.hxx> | |||
49 | #include <charfmt.hxx> | |||
50 | #include <svx/SmartTagItem.hxx> | |||
51 | #include <fmtinfmt.hxx> | |||
52 | #include <wrtsh.hxx> | |||
53 | #include <wview.hxx> | |||
54 | #include <swmodule.hxx> | |||
55 | #include <viewopt.hxx> | |||
56 | #include <uitool.hxx> | |||
57 | #include <textsh.hxx> | |||
58 | #include <IMark.hxx> | |||
59 | #include <swdtflvr.hxx> | |||
60 | #include <swundo.hxx> | |||
61 | #include <reffld.hxx> | |||
62 | #include <docsh.hxx> | |||
63 | #include <inputwin.hxx> | |||
64 | #include <chrdlgmodes.hxx> | |||
65 | #include <fmtcol.hxx> | |||
66 | #include <cellatr.hxx> | |||
67 | #include <edtwin.hxx> | |||
68 | #include <fldmgr.hxx> | |||
69 | #include <strings.hrc> | |||
70 | #include <paratr.hxx> | |||
71 | #include <vcl/svapp.hxx> | |||
72 | #include <sfx2/app.hxx> | |||
73 | #include <breakit.hxx> | |||
74 | #include <SwSmartTagMgr.hxx> | |||
75 | #include <editeng/acorrcfg.hxx> | |||
76 | #include <swabstdlg.hxx> | |||
77 | #include <sfx2/sfxdlg.hxx> | |||
78 | #include <com/sun/star/container/XNameContainer.hpp> | |||
79 | #include <com/sun/star/beans/XPropertySet.hpp> | |||
80 | #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> | |||
81 | #include <com/sun/star/uno/Any.hxx> | |||
82 | #include <com/sun/star/linguistic2/ProofreadingResult.hpp> | |||
83 | #include <com/sun/star/linguistic2/XDictionary.hpp> | |||
84 | #include <com/sun/star/linguistic2/XSpellAlternatives.hpp> | |||
85 | #include <editeng/unolingu.hxx> | |||
86 | #include <doc.hxx> | |||
87 | #include <drawdoc.hxx> | |||
88 | #include <view.hxx> | |||
89 | #include <pam.hxx> | |||
90 | #include <sfx2/objface.hxx> | |||
91 | #include <langhelper.hxx> | |||
92 | #include <uiitems.hxx> | |||
93 | #include <svx/nbdtmgfact.hxx> | |||
94 | #include <svx/nbdtmg.hxx> | |||
95 | #include <SwRewriter.hxx> | |||
96 | #include <svx/drawitem.hxx> | |||
97 | #include <numrule.hxx> | |||
98 | #include <memory> | |||
99 | #include <xmloff/odffields.hxx> | |||
100 | #include <bookmrk.hxx> | |||
101 | #include <linguistic/misc.hxx> | |||
102 | #include <editeng/splwrap.hxx> | |||
103 | #include <LibreOfficeKit/LibreOfficeKitEnums.h> | |||
104 | ||||
105 | using namespace ::com::sun::star; | |||
106 | using namespace com::sun::star::beans; | |||
107 | using namespace ::com::sun::star::container; | |||
108 | using namespace com::sun::star::style; | |||
109 | using namespace svx::sidebar; | |||
110 | ||||
111 | static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> const & pCoreSet, bool bSel, bool bSelectionPut, SfxRequest *pReq); | |||
112 | ||||
113 | static void sw_CharDialog(SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot, const SfxItemSet *pArgs, SfxRequest *pReq ) | |||
114 | { | |||
115 | FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &rWrtSh.GetView()) != nullptr ); | |||
116 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->PutItem(SfxUInt16Item(SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499 ) + 1) + 8), static_cast< sal_uInt16 >(eMetric))); | |||
117 | auto pCoreSet = std::make_shared<SfxItemSet>( | |||
118 | rWrtSh.GetView().GetPool(), | |||
119 | svl::Items< | |||
120 | RES_CHRATR_BEGIN, RES_CHRATR_END - 1, | |||
121 | RES_TXTATR_INETFMT, RES_TXTATR_INETFMT, | |||
122 | RES_BACKGROUND, RES_SHADOW, | |||
123 | XATTR_FILLSTYLE, XATTR_FILLCOLOR, | |||
124 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), | |||
125 | SID_HTML_MODE(10000 + 414), SID_HTML_MODE(10000 + 414), | |||
126 | SID_ATTR_CHAR_WIDTH_FIT_TO_LINE( 10000 + 919 ), SID_ATTR_CHAR_WIDTH_FIT_TO_LINE( 10000 + 919 ), | |||
127 | FN_PARAM_SELECTION((20000 + 2400)+2), FN_PARAM_SELECTION((20000 + 2400)+2)>{}); | |||
128 | rWrtSh.GetCurAttr(*pCoreSet); | |||
129 | ||||
130 | bool bSel = rWrtSh.HasSelection(); | |||
131 | bool bSelectionPut = false; | |||
132 | if(bSel || rWrtSh.IsInWord()) | |||
133 | { | |||
134 | if(!bSel) | |||
135 | { | |||
136 | rWrtSh.StartAction(); | |||
137 | rWrtSh.Push(); | |||
138 | if(!rWrtSh.SelectTextAttr( RES_TXTATR_INETFMT )) | |||
139 | rWrtSh.SelWrd(); | |||
140 | } | |||
141 | pCoreSet->Put(SfxStringItem(FN_PARAM_SELECTION((20000 + 2400)+2), rWrtSh.GetSelText())); | |||
142 | bSelectionPut = true; | |||
143 | if(!bSel) | |||
144 | { | |||
145 | rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent); | |||
146 | rWrtSh.EndAction(); | |||
147 | } | |||
148 | } | |||
149 | pCoreSet->Put(SfxUInt16Item(SID_ATTR_CHAR_WIDTH_FIT_TO_LINE( 10000 + 919 ), rWrtSh.GetScalingOfSelectedText())); | |||
150 | ||||
151 | ::ConvertAttrCharToGen(*pCoreSet); | |||
152 | ||||
153 | // Setting the BoxInfo | |||
154 | ::PrepareBoxInfo(*pCoreSet, rWrtSh); | |||
155 | ||||
156 | pCoreSet->Put(SfxUInt16Item(SID_HTML_MODE(10000 + 414), ::GetHtmlMode(rWrtSh.GetView().GetDocShell()))); | |||
157 | VclPtr<SfxAbstractTabDialog> pDlg; | |||
158 | if ( bUseDialog && GetActiveView() ) | |||
159 | { | |||
160 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
161 | pDlg.reset(pFact->CreateSwCharDlg(rWrtSh.GetView().GetFrameWeld(), rWrtSh.GetView(), *pCoreSet, SwCharDlgMode::Std)); | |||
162 | ||||
163 | if (nSlot == FN_INSERT_HYPERLINK((20000 + 300) + 14)) | |||
164 | pDlg->SetCurPageId("hyperlink"); | |||
165 | else if (nSlot == SID_CHAR_DLG_EFFECT( 10000 + 1133 )) | |||
166 | pDlg->SetCurPageId("fonteffects"); | |||
167 | else if (nSlot == SID_CHAR_DLG_FOR_PARAGRAPH( 10000 + 1068 )) | |||
168 | pDlg->SetCurPageId("font"); | |||
169 | else if (pReq) | |||
170 | { | |||
171 | const SfxStringItem* pItem = (*pReq).GetArg<SfxStringItem>(FN_PARAM_1((20000 + 1100)+60)); | |||
172 | if (pItem) | |||
173 | pDlg->SetCurPageId(OUStringToOString(pItem->GetValue(), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)))); | |||
174 | } | |||
175 | } | |||
176 | ||||
177 | if (bUseDialog) | |||
178 | { | |||
179 | std::shared_ptr<SfxRequest> pRequest; | |||
180 | if (pReq) | |||
181 | { | |||
182 | pRequest = std::make_shared<SfxRequest>(*pReq); | |||
183 | pReq->Ignore(); // the 'old' request is not relevant any more | |||
184 | } | |||
185 | pDlg->StartExecuteAsync([pDlg, &rWrtSh, pCoreSet, bSel, bSelectionPut, pRequest](sal_Int32 nResult){ | |||
186 | if (nResult == RET_OK) | |||
187 | { | |||
188 | sw_CharDialogResult(pDlg->GetOutputItemSet(), rWrtSh, pCoreSet, bSel, bSelectionPut, pRequest.get()); | |||
189 | } | |||
190 | pDlg->disposeOnce(); | |||
191 | }); | |||
192 | } | |||
193 | else if (pArgs) | |||
194 | { | |||
195 | sw_CharDialogResult(pArgs, rWrtSh, pCoreSet, bSel, bSelectionPut, pReq); | |||
196 | } | |||
197 | } | |||
198 | ||||
199 | static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> const & pCoreSet, bool bSel, bool bSelectionPut, SfxRequest *pReq) | |||
200 | { | |||
201 | SfxItemSet aTmpSet( *pSet ); | |||
202 | ::ConvertAttrGenToChar(aTmpSet, *pCoreSet); | |||
203 | ||||
204 | const SfxPoolItem* pSelectionItem; | |||
205 | bool bInsert = false; | |||
206 | sal_Int32 nInsert = 0; | |||
207 | ||||
208 | // The old item is for unknown reasons back in the set again. | |||
209 | if( !bSelectionPut && SfxItemState::SET == aTmpSet.GetItemState(FN_PARAM_SELECTION((20000 + 2400)+2), false, &pSelectionItem) ) | |||
210 | { | |||
211 | OUString sInsert = static_cast<const SfxStringItem*>(pSelectionItem)->GetValue(); | |||
212 | bInsert = !sInsert.isEmpty(); | |||
213 | if(bInsert) | |||
214 | { | |||
215 | nInsert = sInsert.getLength(); | |||
216 | rWrtSh.StartAction(); | |||
217 | rWrtSh.Insert( sInsert ); | |||
218 | rWrtSh.SetMark(); | |||
219 | rWrtSh.ExtendSelection(false, sInsert.getLength()); | |||
220 | SfxRequest aReq( rWrtSh.GetView().GetViewFrame(), FN_INSERT_STRING((20000 + 300)+31) ); | |||
221 | aReq.AppendItem( SfxStringItem( FN_INSERT_STRING((20000 + 300)+31), sInsert ) ); | |||
222 | aReq.Done(); | |||
223 | SfxRequest aReq1( rWrtSh.GetView().GetViewFrame(), FN_CHAR_LEFT((20000 + 900) + 1 ) ); | |||
224 | aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT((20000 + 1100)+2), nInsert) ); | |||
225 | aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION((20000 + 1100)+3), true) ); | |||
226 | aReq1.Done(); | |||
227 | } | |||
228 | } | |||
229 | aTmpSet.ClearItem(FN_PARAM_SELECTION((20000 + 2400)+2)); | |||
230 | ||||
231 | SwTextFormatColl* pColl = rWrtSh.GetCurTextFormatColl(); | |||
232 | if(bSel && rWrtSh.IsSelFullPara() && pColl && pColl->IsAutoUpdateFormat()) | |||
233 | { | |||
234 | rWrtSh.AutoUpdatePara(pColl, aTmpSet); | |||
235 | } | |||
236 | else | |||
237 | rWrtSh.SetAttrSet( aTmpSet ); | |||
238 | if (pReq) | |||
239 | pReq->Done(aTmpSet); | |||
240 | if(bInsert) | |||
241 | { | |||
242 | SfxRequest aReq1( rWrtSh.GetView().GetViewFrame(), FN_CHAR_RIGHT((20000 + 900) + 2 ) ); | |||
243 | aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT((20000 + 1100)+2), nInsert) ); | |||
244 | aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION((20000 + 1100)+3), false) ); | |||
245 | aReq1.Done(); | |||
246 | rWrtSh.SwapPam(); | |||
247 | rWrtSh.ClearMark(); | |||
248 | rWrtSh.DontExpandFormat(); | |||
249 | rWrtSh.EndAction(); | |||
250 | } | |||
251 | ||||
252 | } | |||
253 | ||||
254 | static short lcl_AskRedlineFlags(weld::Window *pWin) | |||
255 | { | |||
256 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pWin, "modules/swriter/ui/queryredlinedialog.ui")); | |||
257 | std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog("QueryRedlineDialog")); | |||
258 | return xQBox->run(); | |||
259 | } | |||
260 | ||||
261 | static void sw_ParagraphDialogResult(SfxItemSet* pSet, SwWrtShell &rWrtSh, SfxRequest& rReq, SwPaM* pPaM) | |||
262 | { | |||
263 | if (!pSet) | |||
264 | return; | |||
265 | ||||
266 | rReq.Done( *pSet ); | |||
267 | ::SfxToSwPageDescAttr( rWrtSh, *pSet ); | |||
268 | // #i56253# | |||
269 | // enclose all undos. | |||
270 | // Thus, check conditions, if actions will be performed. | |||
271 | const bool bUndoNeeded( pSet->Count() || | |||
272 | SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART((20000 + 1600) + 138)) || | |||
273 | SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART_AT((20000 + 1600) + 139)) ); | |||
274 | if ( bUndoNeeded ) | |||
275 | { | |||
276 | rWrtSh.StartUndo( SwUndoId::INSATTR ); | |||
277 | } | |||
278 | if( pSet->Count() ) | |||
279 | { | |||
280 | rWrtSh.StartAction(); | |||
281 | const SfxPoolItem* pItem = nullptr; | |||
282 | if ( SfxItemState::SET == pSet->GetItemState(FN_DROP_TEXT((20000 + 2400)+18), false, &pItem) ) | |||
283 | { | |||
284 | if ( !static_cast<const SfxStringItem*>(pItem)->GetValue().isEmpty() ) | |||
285 | rWrtSh.ReplaceDropText(static_cast<const SfxStringItem*>(pItem)->GetValue(), pPaM); | |||
286 | } | |||
287 | rWrtSh.SetAttrSet(*pSet, SetAttrMode::DEFAULT, pPaM); | |||
288 | rWrtSh.EndAction(); | |||
289 | SwTextFormatColl* pColl = rWrtSh.GetPaMTextFormatColl(pPaM); | |||
290 | if(pColl && pColl->IsAutoUpdateFormat()) | |||
291 | { | |||
292 | rWrtSh.AutoUpdatePara(pColl, *pSet, pPaM); | |||
293 | } | |||
294 | } | |||
295 | ||||
296 | if( SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART((20000 + 1600) + 138)) ) | |||
297 | { | |||
298 | //SetNumRuleStart(true) restarts the numbering at the value | |||
299 | //that is defined at the starting point of the numbering level | |||
300 | //otherwise the SetNodeNumStart() value determines the start | |||
301 | //if it's set to something different than USHRT_MAX | |||
302 | ||||
303 | bool bStart = static_cast<const SfxBoolItem&>(pSet->Get(FN_NUMBER_NEWSTART((20000 + 1600) + 138))).GetValue(); | |||
304 | ||||
305 | // Default value for restart value has to be USHRT_MAX | |||
306 | // in order to indicate that the restart value of the list | |||
307 | // style has to be used on restart. | |||
308 | sal_uInt16 nNumStart = USHRT_MAX(32767 *2 +1); | |||
309 | if( SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART_AT((20000 + 1600) + 139)) ) | |||
310 | { | |||
311 | nNumStart = static_cast<const SfxUInt16Item&>(pSet->Get(FN_NUMBER_NEWSTART_AT((20000 + 1600) + 139))).GetValue(); | |||
312 | } | |||
313 | rWrtSh.SetNumRuleStart(bStart, pPaM); | |||
314 | rWrtSh.SetNodeNumStart(nNumStart); | |||
315 | } | |||
316 | else if( SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART_AT((20000 + 1600) + 139)) ) | |||
317 | { | |||
318 | rWrtSh.SetNodeNumStart(static_cast<const SfxUInt16Item&>(pSet->Get(FN_NUMBER_NEWSTART_AT((20000 + 1600) + 139))).GetValue()); | |||
319 | rWrtSh.SetNumRuleStart(false, pPaM); | |||
320 | } | |||
321 | // #i56253# | |||
322 | if ( bUndoNeeded ) | |||
323 | { | |||
324 | rWrtSh.EndUndo( SwUndoId::INSATTR ); | |||
325 | } | |||
326 | } | |||
327 | ||||
328 | namespace { | |||
329 | ||||
330 | void InsertBreak(SwWrtShell& rWrtSh, | |||
331 | sal_uInt16 nKind, | |||
332 | ::std::optional<sal_uInt16> oPageNumber, | |||
333 | const OUString& rTemplateName) | |||
334 | { | |||
335 | switch ( nKind ) | |||
336 | { | |||
337 | case 1 : | |||
338 | rWrtSh.InsertLineBreak(); break; | |||
339 | case 2 : | |||
340 | rWrtSh.InsertColumnBreak(); break; | |||
341 | case 3 : | |||
342 | { | |||
343 | rWrtSh.StartAllAction(); | |||
344 | if( !rTemplateName.isEmpty() ) | |||
345 | rWrtSh.InsertPageBreak( &rTemplateName, oPageNumber ); | |||
346 | else | |||
347 | rWrtSh.InsertPageBreak(); | |||
348 | rWrtSh.EndAllAction(); | |||
349 | } | |||
350 | } | |||
351 | } | |||
352 | ||||
353 | } | |||
354 | ||||
355 | void SwTextShell::Execute(SfxRequest &rReq) | |||
356 | { | |||
357 | bool bUseDialog = true; | |||
358 | const SfxItemSet *pArgs = rReq.GetArgs(); | |||
359 | SwWrtShell& rWrtSh = GetShell(); | |||
360 | const SfxPoolItem* pItem = nullptr; | |||
361 | const sal_uInt16 nSlot = rReq.GetSlot(); | |||
362 | if(pArgs) | |||
| ||||
363 | pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem); | |||
364 | switch( nSlot ) | |||
365 | { | |||
366 | case SID_UNICODE_NOTATION_TOGGLE(5000 + 792): | |||
367 | { | |||
368 | long nMaxUnits = 256; | |||
369 | sal_Int32 nSelLength = rWrtSh.GetSelText().getLength(); | |||
370 | if( rWrtSh.IsSelection() && !rWrtSh.IsMultiSelection() && (nSelLength < nMaxUnits) ) | |||
371 | nMaxUnits = nSelLength; | |||
372 | ||||
373 | long index = 0; | |||
374 | ToggleUnicodeCodepoint aToggle; | |||
375 | while( nMaxUnits-- && aToggle.AllowMoreInput(rWrtSh.GetChar(true, index-1)) ) | |||
376 | --index; | |||
377 | ||||
378 | OUString sReplacement = aToggle.ReplacementString(); | |||
379 | if( !sReplacement.isEmpty() ) | |||
380 | { | |||
381 | if (rWrtSh.HasReadonlySel() && !rWrtSh.CursorInsideInputField()) | |||
382 | { | |||
383 | // Only break if there's something to do; don't nag with the dialog otherwise | |||
384 | auto xInfo(std::make_unique<weld::GenericDialogController>( | |||
385 | rWrtSh.GetView().GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui", | |||
386 | "InfoReadonlyDialog")); | |||
387 | xInfo->run(); | |||
388 | break; | |||
389 | } | |||
390 | SwRewriter aRewriter; | |||
391 | aRewriter.AddRule( UndoArg1, aToggle.StringToReplace() ); | |||
392 | aRewriter.AddRule( UndoArg2, SwResId(STR_YIELDSreinterpret_cast<char const *>("STR_YIELDS" "\004" u8"→" )) ); | |||
393 | aRewriter.AddRule( UndoArg3, sReplacement ); | |||
394 | rWrtSh.StartUndo(SwUndoId::REPLACE, &aRewriter); | |||
395 | rWrtSh.GetCursor()->Normalize(false); | |||
396 | ||||
397 | rWrtSh.ClearMark(); | |||
398 | if( rWrtSh.IsInSelect() ) // cancel any in-progress keyboard selection as well | |||
399 | rWrtSh.EndSelect(); | |||
400 | ||||
401 | for( sal_uInt32 i=aToggle.CharsToDelete(); i > 0; --i ) | |||
402 | rWrtSh.DelLeft(); | |||
403 | rWrtSh.Insert2( sReplacement ); | |||
404 | rWrtSh.EndUndo(SwUndoId::REPLACE, &aRewriter); | |||
405 | } | |||
406 | } | |||
407 | break; | |||
408 | ||||
409 | case SID_LANGUAGE_STATUS( 10000 + 1067 ): | |||
410 | { | |||
411 | // get the language | |||
412 | OUString aNewLangText; | |||
413 | const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(SID_LANGUAGE_STATUS( 10000 + 1067 )); | |||
414 | if (pItem2) | |||
415 | aNewLangText = pItem2->GetValue(); | |||
416 | ||||
417 | //!! Remember the view frame right now... | |||
418 | //!! (call to GetView().GetViewFrame() will break if the | |||
419 | //!! SwTextShell got destroyed meanwhile.) | |||
420 | SfxViewFrame *pViewFrame = GetView().GetViewFrame(); | |||
421 | ||||
422 | if (aNewLangText == "*") | |||
423 | { | |||
424 | // open the dialog "Tools/Options/Language Settings - Language" | |||
425 | // to set the documents default language | |||
426 | SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); | |||
427 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateVclDialog(GetView().GetFrameWeld(), SID_LANGUAGE_OPTIONS( 10000 + 921 ))); | |||
428 | pDlg->Execute(); | |||
429 | } | |||
430 | else | |||
431 | { | |||
432 | //!! We have to use StartAction / EndAction bracketing in | |||
433 | //!! order to prevent possible destruction of the SwTextShell | |||
434 | //!! due to the selection changes coming below. | |||
435 | rWrtSh.StartAction(); | |||
436 | // prevent view from jumping because of (temporary) selection changes | |||
437 | rWrtSh.LockView( true ); | |||
438 | ||||
439 | // setting the new language... | |||
440 | if (!aNewLangText.isEmpty()) | |||
441 | { | |||
442 | const OUString aSelectionLangPrefix("Current_"); | |||
443 | const OUString aParagraphLangPrefix("Paragraph_"); | |||
444 | const OUString aDocumentLangPrefix("Default_"); | |||
445 | ||||
446 | SfxItemSet aCoreSet( GetPool(), | |||
447 | svl::Items<RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE, | |||
448 | RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, | |||
449 | RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE>{} ); | |||
450 | ||||
451 | sal_Int32 nPos = 0; | |||
452 | bool bForSelection = true; | |||
453 | bool bForParagraph = false; | |||
454 | if (-1 != (nPos = aNewLangText.indexOf( aSelectionLangPrefix ))) | |||
455 | { | |||
456 | // ... for the current selection | |||
457 | aNewLangText = aNewLangText.replaceAt(nPos, aSelectionLangPrefix.getLength(), ""); | |||
458 | bForSelection = true; | |||
459 | } | |||
460 | else if (-1 != (nPos = aNewLangText.indexOf(aParagraphLangPrefix))) | |||
461 | { | |||
462 | // ... for the current paragraph language | |||
463 | aNewLangText = aNewLangText.replaceAt(nPos, aParagraphLangPrefix.getLength(), ""); | |||
464 | bForSelection = true; | |||
465 | bForParagraph = true; | |||
466 | } | |||
467 | else if (-1 != (nPos = aNewLangText.indexOf(aDocumentLangPrefix))) | |||
468 | { | |||
469 | // ... as default document language | |||
470 | aNewLangText = aNewLangText.replaceAt(nPos, aDocumentLangPrefix.getLength(), ""); | |||
471 | bForSelection = false; | |||
472 | } | |||
473 | ||||
474 | if (bForParagraph || !bForSelection) | |||
475 | { | |||
476 | rWrtSh.Push(); // save selection for later restoration | |||
477 | rWrtSh.ClearMark(); // fdo#67796: invalidate table crsr | |||
478 | } | |||
479 | ||||
480 | if (bForParagraph) | |||
481 | SwLangHelper::SelectCurrentPara( rWrtSh ); | |||
482 | ||||
483 | if (!bForSelection) // document language to be changed... | |||
484 | { | |||
485 | rWrtSh.SelAll(); | |||
486 | rWrtSh.ExtendedSelectAll(); | |||
487 | } | |||
488 | ||||
489 | rWrtSh.StartUndo( ( !bForParagraph && !bForSelection ) ? SwUndoId::SETDEFTATTR : SwUndoId::EMPTY ); | |||
490 | if (aNewLangText == "LANGUAGE_NONE") | |||
491 | SwLangHelper::SetLanguage_None( rWrtSh, bForSelection, aCoreSet ); | |||
492 | else if (aNewLangText == "RESET_LANGUAGES") | |||
493 | SwLangHelper::ResetLanguages( rWrtSh ); | |||
494 | else | |||
495 | SwLangHelper::SetLanguage( rWrtSh, aNewLangText, bForSelection, aCoreSet ); | |||
496 | rWrtSh.EndUndo(); | |||
497 | ||||
498 | if (bForParagraph || !bForSelection) | |||
499 | { | |||
500 | rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent); // restore selection... | |||
501 | } | |||
502 | } | |||
503 | ||||
504 | rWrtSh.LockView( false ); | |||
505 | rWrtSh.EndAction(); | |||
506 | } | |||
507 | ||||
508 | // invalidate slot to get the new language displayed | |||
509 | pViewFrame->GetBindings().Invalidate( nSlot ); | |||
510 | ||||
511 | rReq.Done(); | |||
512 | break; | |||
513 | } | |||
514 | ||||
515 | case SID_THES(5000 + 698): | |||
516 | { | |||
517 | // replace word/selection with text from selected sub menu entry | |||
518 | OUString aReplaceText; | |||
519 | const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(SID_THES(5000 + 698)); | |||
520 | if (pItem2) | |||
521 | aReplaceText = pItem2->GetValue(); | |||
522 | if (!aReplaceText.isEmpty()) | |||
523 | { | |||
524 | SwView &rView2 = rWrtSh.GetView(); | |||
525 | const bool bSelection = rWrtSh.HasSelection(); | |||
526 | const OUString aLookUpText = rView2.GetThesaurusLookUpText( bSelection ); | |||
527 | rView2.InsertThesaurusSynonym( aReplaceText, aLookUpText, bSelection ); | |||
528 | } | |||
529 | } | |||
530 | break; | |||
531 | ||||
532 | case SID_CHARMAP((10000 + 500) + 3): | |||
533 | { | |||
534 | InsertSymbol( rReq ); | |||
535 | } | |||
536 | break; | |||
537 | case FN_INSERT_FOOTNOTE((20000 + 300) + 99): | |||
538 | case FN_INSERT_ENDNOTE((20000 + 1400) + 18): | |||
539 | { | |||
540 | OUString aStr; | |||
541 | const SfxStringItem* pFont = rReq.GetArg<SfxStringItem>(FN_PARAM_1((20000 + 1100)+60)); | |||
542 | const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(nSlot); | |||
543 | if ( pNameItem ) | |||
544 | aStr = pNameItem->GetValue(); | |||
545 | bool bFont = pFont && !pFont->GetValue().isEmpty(); | |||
546 | rWrtSh.StartUndo( SwUndoId::UI_INSERT_FOOTNOTE ); | |||
547 | rWrtSh.InsertFootnote( aStr, nSlot == FN_INSERT_ENDNOTE((20000 + 1400) + 18), !bFont ); | |||
548 | if ( bFont ) | |||
549 | { | |||
550 | rWrtSh.Left( CRSR_SKIP_CHARS, true, 1, false ); | |||
551 | SfxItemSet aSet( rWrtSh.GetAttrPool(), svl::Items<RES_CHRATR_FONT, RES_CHRATR_FONT>{} ); | |||
552 | rWrtSh.GetCurAttr( aSet ); | |||
553 | rWrtSh.SetAttrSet( aSet, SetAttrMode::DONTEXPAND ); | |||
554 | rWrtSh.ResetSelect(nullptr, false); | |||
555 | rWrtSh.EndSelect(); | |||
556 | rWrtSh.GotoFootnoteText(); | |||
557 | } | |||
558 | rWrtSh.EndUndo( SwUndoId::UI_INSERT_FOOTNOTE ); | |||
559 | rReq.Done(); | |||
560 | } | |||
561 | break; | |||
562 | case FN_INSERT_FOOTNOTE_DLG((20000 + 300) + 12): | |||
563 | { | |||
564 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
565 | ScopedVclPtr<AbstractInsFootNoteDlg> pDlg(pFact->CreateInsFootNoteDlg( | |||
566 | GetView().GetFrameWeld(), rWrtSh)); | |||
567 | pDlg->SetHelpId(GetStaticInterface()->GetSlot(nSlot)->GetCommand()); | |||
568 | if ( pDlg->Execute() == RET_OK ) | |||
569 | { | |||
570 | const sal_uInt16 nId = pDlg->IsEndNote() ? FN_INSERT_ENDNOTE((20000 + 1400) + 18) : FN_INSERT_FOOTNOTE((20000 + 300) + 99); | |||
571 | SfxRequest aReq( GetView().GetViewFrame(), nId ); | |||
572 | if ( !pDlg->GetStr().isEmpty() ) | |||
573 | aReq.AppendItem( SfxStringItem( nId, pDlg->GetStr() ) ); | |||
574 | if ( !pDlg->GetFontName().isEmpty() ) | |||
575 | aReq.AppendItem( SfxStringItem( FN_PARAM_1((20000 + 1100)+60), pDlg->GetFontName() ) ); | |||
576 | ExecuteSlot( aReq ); | |||
577 | } | |||
578 | ||||
579 | rReq.Ignore(); | |||
580 | } | |||
581 | break; | |||
582 | case FN_FORMAT_FOOTNOTE_DLG((20000 + 400) + 68): | |||
583 | case FN_FORMAT_CURRENT_FOOTNOTE_DLG((20000 + 400) + 64): | |||
584 | { | |||
585 | GetView().ExecFormatFootnote(); | |||
586 | break; | |||
587 | } | |||
588 | case SID_INSERTDOC(5000 + 532): | |||
589 | { | |||
590 | GetView().ExecuteInsertDoc( rReq, pItem ); | |||
591 | break; | |||
592 | } | |||
593 | case FN_FORMAT_RESET((20000 + 400) + 69): | |||
594 | { | |||
595 | // #i78856, reset all attributes but not the language attributes | |||
596 | // (for this build an array of all relevant attributes and | |||
597 | // remove the languages from that) | |||
598 | std::set<sal_uInt16> aAttribs; | |||
599 | ||||
600 | sal_uInt16 aResetableSetRange[] = { | |||
601 | RES_FRMATR_BEGIN, RES_FRMATR_END-1, | |||
602 | RES_CHRATR_BEGIN, RES_CHRATR_LANGUAGE - 1, | |||
603 | RES_CHRATR_LANGUAGE + 1, RES_CHRATR_CJK_LANGUAGE - 1, | |||
604 | RES_CHRATR_CJK_LANGUAGE + 1, RES_CHRATR_CTL_LANGUAGE - 1, | |||
605 | RES_CHRATR_CTL_LANGUAGE + 1, RES_CHRATR_END-1, | |||
606 | RES_PARATR_BEGIN, RES_PARATR_END-1, | |||
607 | RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER, | |||
608 | RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1, | |||
609 | 0 | |||
610 | }; | |||
611 | const sal_uInt16 *pUShorts = aResetableSetRange; | |||
612 | while (*pUShorts) | |||
613 | { | |||
614 | for (sal_uInt16 i = pUShorts[0]; i <= pUShorts[1]; ++i) | |||
615 | aAttribs.insert( aAttribs.end(), i ); | |||
616 | pUShorts += 2; | |||
617 | } | |||
618 | // we don't want to change writing direction. | |||
619 | aAttribs.erase( RES_FRAMEDIR ); | |||
620 | rWrtSh.ResetAttr( aAttribs ); | |||
621 | ||||
622 | // also clear the direct formatting flag inside SwTableBox(es) | |||
623 | GetView().GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(nullptr, true); | |||
624 | ||||
625 | rReq.Done(); | |||
626 | break; | |||
627 | } | |||
628 | case FN_INSERT_BREAK_DLG((20000 + 300) + 4 ): | |||
629 | { | |||
630 | if ( pItem ) | |||
631 | { | |||
632 | ::std::optional<sal_uInt16> oPageNumber; | |||
633 | OUString aTemplateName; | |||
634 | sal_uInt16 nKind = static_cast<const SfxInt16Item*>(pItem)->GetValue(); | |||
635 | const SfxStringItem* pTemplate = rReq.GetArg<SfxStringItem>(FN_PARAM_1((20000 + 1100)+60)); | |||
636 | const SfxUInt16Item* pNumber = rReq.GetArg<SfxUInt16Item>(FN_PARAM_2((20000 + 1100)+61)); | |||
637 | const SfxBoolItem* pIsNumberFilled = rReq.GetArg<SfxBoolItem>(FN_PARAM_3((20000 + 1100)+62)); | |||
638 | if ( pTemplate ) | |||
639 | aTemplateName = pTemplate->GetValue(); | |||
640 | if ( pNumber && pIsNumberFilled && pIsNumberFilled->GetValue() ) | |||
641 | oPageNumber = pNumber->GetValue(); | |||
642 | ||||
643 | InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName); | |||
644 | } | |||
645 | else | |||
646 | { | |||
647 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
648 | ||||
649 | std::shared_ptr<AbstractSwBreakDlg> pAbstractDialog(pFact->CreateSwBreakDlg(GetView().GetFrameWeld(), rWrtSh)); | |||
650 | std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController()); | |||
651 | ||||
652 | weld::DialogController::runAsync(pDialogController, | |||
653 | [pAbstractDialog, &rWrtSh] (sal_Int32 nResult) { | |||
654 | if( RET_OK == nResult ) | |||
655 | { | |||
656 | sal_uInt16 nKind = pAbstractDialog->GetKind(); | |||
657 | OUString aTemplateName = pAbstractDialog->GetTemplateName(); | |||
658 | ::std::optional<sal_uInt16> oPageNumber = pAbstractDialog->GetPageNumber(); | |||
659 | ||||
660 | InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName); | |||
661 | } | |||
662 | }); | |||
663 | } | |||
664 | ||||
665 | break; | |||
666 | } | |||
667 | case FN_INSERT_BOOKMARK((20000 + 300) + 2 ): | |||
668 | { | |||
669 | if ( pItem ) | |||
670 | { | |||
671 | OUString sName = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
672 | rWrtSh.SetBookmark( vcl::KeyCode(), sName ); | |||
673 | } | |||
674 | else | |||
675 | { | |||
676 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
677 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwInsertBookmarkDlg(GetView().GetFrameWeld(), rWrtSh)); | |||
678 | VclAbstractDialog::AsyncContext aContext; | |||
679 | aContext.maEndDialogFn = [](sal_Int32){}; | |||
680 | pDlg->StartExecuteAsync(aContext); | |||
681 | } | |||
682 | ||||
683 | break; | |||
684 | } | |||
685 | case FN_DELETE_BOOKMARK((20000 + 300) + 1): | |||
686 | { | |||
687 | if (pItem && !rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS)) | |||
688 | { | |||
689 | IDocumentMarkAccess* const pMarkAccess = rWrtSh.getIDocumentMarkAccess(); | |||
690 | pMarkAccess->deleteMark( pMarkAccess->findMark(static_cast<const SfxStringItem*>(pItem)->GetValue()) ); | |||
691 | } | |||
692 | break; | |||
693 | } | |||
694 | case FN_SET_REMINDER((20000 + 300) + 100): | |||
695 | { | |||
696 | // collect and sort navigator reminder names | |||
697 | IDocumentMarkAccess* const pMarkAccess = rWrtSh.getIDocumentMarkAccess(); | |||
698 | std::vector< OUString > vNavMarkNames; | |||
699 | for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin(); | |||
700 | ppMark != pMarkAccess->getAllMarksEnd(); | |||
701 | ++ppMark) | |||
702 | { | |||
703 | if( IDocumentMarkAccess::GetType(**ppMark) == IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER ) | |||
704 | vNavMarkNames.push_back((*ppMark)->GetName()); | |||
705 | } | |||
706 | std::sort(vNavMarkNames.begin(), vNavMarkNames.end()); | |||
707 | ||||
708 | // we are maxed out so delete the first one | |||
709 | // this assumes that IDocumentMarkAccess generates Names in ascending order | |||
710 | if(vNavMarkNames.size() == MAX_MARKS5) | |||
711 | pMarkAccess->deleteMark(pMarkAccess->findMark(vNavMarkNames[0])); | |||
712 | ||||
713 | rWrtSh.SetBookmark(vcl::KeyCode(), OUString(), IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER); | |||
714 | SwView::SetActMark(vNavMarkNames.size() < MAX_MARKS5 ? vNavMarkNames.size() : MAX_MARKS5-1); | |||
715 | ||||
716 | break; | |||
717 | } | |||
718 | case FN_AUTOFORMAT_REDLINE_APPLY((20000 + 400) + 5 ): | |||
719 | { | |||
720 | SvxSwAutoFormatFlags aFlags(SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags()); | |||
721 | // This must always be false for the postprocessing. | |||
722 | aFlags.bAFormatByInput = false; | |||
723 | aFlags.bWithRedlining = true; | |||
724 | rWrtSh.AutoFormat( &aFlags ); | |||
725 | aFlags.bWithRedlining = false; | |||
726 | ||||
727 | SfxViewFrame* pVFrame = GetView().GetViewFrame(); | |||
728 | if (pVFrame->HasChildWindow(FN_REDLINE_ACCEPT((20000 + 1800) + 29))) | |||
729 | pVFrame->ToggleChildWindow(FN_REDLINE_ACCEPT((20000 + 1800) + 29)); | |||
730 | ||||
731 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
732 | ScopedVclPtr<AbstractSwModalRedlineAcceptDlg> xDlg(pFact->CreateSwModalRedlineAcceptDlg(GetView().GetEditWin().GetFrameWeld())); | |||
733 | ||||
734 | switch (lcl_AskRedlineFlags(GetView().GetFrameWeld())) | |||
735 | { | |||
736 | case RET_OK: | |||
737 | { | |||
738 | xDlg->AcceptAll(true); | |||
739 | SfxRequest aReq( pVFrame, FN_AUTOFORMAT_APPLY((20000 + 400) + 1 ) ); | |||
740 | aReq.Done(); | |||
741 | rReq.Ignore(); | |||
742 | break; | |||
743 | } | |||
744 | ||||
745 | case RET_CANCEL: | |||
746 | xDlg->AcceptAll(false); | |||
747 | rReq.Ignore(); | |||
748 | break; | |||
749 | ||||
750 | case 102: | |||
751 | xDlg->Execute(); | |||
752 | rReq.Done(); | |||
753 | break; | |||
754 | } | |||
755 | } | |||
756 | break; | |||
757 | ||||
758 | case FN_AUTOFORMAT_APPLY((20000 + 400) + 1 ): | |||
759 | { | |||
760 | SvxSwAutoFormatFlags aFlags(SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags()); | |||
761 | // This must always be false for the postprocessing. | |||
762 | aFlags.bAFormatByInput = false; | |||
763 | rWrtSh.AutoFormat( &aFlags ); | |||
764 | rReq.Done(); | |||
765 | } | |||
766 | break; | |||
767 | case FN_AUTOFORMAT_AUTO((20000 + 400) + 2 ): | |||
768 | { | |||
769 | SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get(); | |||
770 | bool bSet = pItem ? static_cast<const SfxBoolItem*>(pItem)->GetValue() : !rACfg.IsAutoFormatByInput(); | |||
771 | if( bSet != rACfg.IsAutoFormatByInput() ) | |||
772 | { | |||
773 | rACfg.SetAutoFormatByInput( bSet ); | |||
774 | rACfg.Commit(); | |||
775 | GetView().GetViewFrame()->GetBindings().Invalidate( nSlot ); | |||
776 | if ( !pItem ) | |||
777 | rReq.AppendItem( SfxBoolItem( GetPool().GetWhich(nSlot), bSet ) ); | |||
778 | rReq.Done(); | |||
779 | } | |||
780 | } | |||
781 | break; | |||
782 | case FN_AUTO_CORRECT((20000 + 600) + 49 ): | |||
783 | { | |||
784 | // At first set to blank as default. | |||
785 | rWrtSh.AutoCorrect( *SvxAutoCorrCfg::Get().GetAutoCorrect(), ' ' ); | |||
786 | rReq.Done(); | |||
787 | } | |||
788 | break; | |||
789 | case FN_TABLE_SORT_DIALOG((20000 + 400) + 133): | |||
790 | case FN_SORTING_DLG((20000 + 600) + 14): | |||
791 | { | |||
792 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
793 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwSortingDialog(GetView().GetFrameWeld(), rWrtSh)); | |||
794 | pDlg->Execute(); | |||
795 | rReq.Done(); | |||
796 | } | |||
797 | break; | |||
798 | case FN_NUMBERING_OUTLINE_DLG((20000 + 600) + 12): | |||
799 | { | |||
800 | GetView().ExecNumberingOutline(GetPool()); | |||
801 | rReq.Done(); | |||
802 | } | |||
803 | break; | |||
804 | case FN_CALCULATE((20000 + 600) + 15): | |||
805 | { | |||
806 | rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rWrtSh ); | |||
807 | pTransfer->CalculateAndCopy(); | |||
808 | rReq.Done(); | |||
809 | } | |||
810 | break; | |||
811 | case FN_GOTO_REFERENCE((20000 + 100) + 66): | |||
812 | { | |||
813 | SwField *pField = rWrtSh.GetCurField(); | |||
814 | if(pField && pField->GetTypeId() == SwFieldTypesEnum::GetRef) | |||
815 | { | |||
816 | rWrtSh.StartAllAction(); | |||
817 | rWrtSh.SwCursorShell::GotoRefMark( static_cast<SwGetRefField*>(pField)->GetSetRefName(), | |||
818 | static_cast<SwGetRefField*>(pField)->GetSubType(), | |||
819 | static_cast<SwGetRefField*>(pField)->GetSeqNo() ); | |||
820 | rWrtSh.EndAllAction(); | |||
821 | rReq.Done(); | |||
822 | } | |||
823 | } | |||
824 | break; | |||
825 | case FN_EDIT_FORMULA((20000 + 100) + 28): | |||
826 | { | |||
827 | const sal_uInt16 nId = SwInputChild::GetChildWindowId(); | |||
828 | SfxViewFrame* pVFrame = GetView().GetViewFrame(); | |||
829 | if(pItem) | |||
830 | { | |||
831 | //if the ChildWindow is active it has to be removed | |||
832 | if( pVFrame->HasChildWindow( nId ) ) | |||
833 | { | |||
834 | pVFrame->ToggleChildWindow( nId ); | |||
835 | pVFrame->GetBindings().InvalidateAll( true ); | |||
836 | } | |||
837 | ||||
838 | OUString sFormula(static_cast<const SfxStringItem*>(pItem)->GetValue()); | |||
839 | SwFieldMgr aFieldMgr; | |||
840 | rWrtSh.StartAllAction(); | |||
841 | bool bDelSel = rWrtSh.HasSelection(); | |||
842 | if( bDelSel ) | |||
843 | { | |||
844 | rWrtSh.StartUndo( SwUndoId::START ); | |||
845 | rWrtSh.DelRight(); | |||
846 | } | |||
847 | else | |||
848 | { | |||
849 | rWrtSh.EnterStdMode(); | |||
850 | } | |||
851 | ||||
852 | if( !bDelSel && aFieldMgr.GetCurField() && SwFieldTypesEnum::Formel == aFieldMgr.GetCurTypeId() ) | |||
853 | aFieldMgr.UpdateCurField( aFieldMgr.GetCurField()->GetFormat(), OUString(), sFormula ); | |||
854 | else if( !sFormula.isEmpty() ) | |||
855 | { | |||
856 | if( rWrtSh.IsCursorInTable() ) | |||
857 | { | |||
858 | SfxItemSet aSet( rWrtSh.GetAttrPool(), svl::Items<RES_BOXATR_FORMULA, RES_BOXATR_FORMULA>{} ); | |||
859 | aSet.Put( SwTableBoxFormula( sFormula )); | |||
860 | rWrtSh.SetTableBoxFormulaAttrs( aSet ); | |||
861 | rWrtSh.UpdateTable(); | |||
862 | } | |||
863 | else | |||
864 | { | |||
865 | SvNumberFormatter* pFormatter = rWrtSh.GetNumberFormatter(); | |||
866 | const sal_uInt32 nSysNumFormat = pFormatter->GetFormatIndex( NF_NUMBER_STANDARD, LANGUAGE_SYSTEMLanguageType(0x0000)); | |||
867 | SwInsertField_Data aData(SwFieldTypesEnum::Formel, nsSwGetSetExpType::GSE_FORMULA, OUString(), sFormula, nSysNumFormat); | |||
868 | aFieldMgr.InsertField(aData); | |||
869 | } | |||
870 | } | |||
871 | ||||
872 | if( bDelSel ) | |||
873 | rWrtSh.EndUndo( SwUndoId::END ); | |||
874 | rWrtSh.EndAllAction(); | |||
875 | rReq.Done(); | |||
876 | } | |||
877 | else | |||
878 | { | |||
879 | rWrtSh.EndAllTableBoxEdit(); | |||
880 | pVFrame->ToggleChildWindow( nId ); | |||
881 | if( !pVFrame->HasChildWindow( nId ) ) | |||
882 | pVFrame->GetBindings().InvalidateAll( true ); | |||
883 | rReq.Ignore(); | |||
884 | } | |||
885 | } | |||
886 | ||||
887 | break; | |||
888 | case FN_TABLE_UNSET_READ_ONLY((20000 + 400) + 159): | |||
889 | { | |||
890 | rWrtSh.UnProtectTables(); | |||
891 | } | |||
892 | break; | |||
893 | case SID_EDIT_HYPERLINK( 10000 + 978 ): | |||
894 | GetView().GetViewFrame()->SetChildWindow(SID_HYPERLINK_DIALOG(5000 + 678), true); | |||
895 | break; | |||
896 | case SID_REMOVE_HYPERLINK( 10000 + 459 ): | |||
897 | { | |||
898 | bool bSel = rWrtSh.HasSelection(); | |||
899 | if(!bSel) | |||
900 | { | |||
901 | rWrtSh.StartAction(); | |||
902 | rWrtSh.Push(); | |||
903 | if(!rWrtSh.SelectTextAttr( RES_TXTATR_INETFMT )) | |||
904 | rWrtSh.SelWrd(); | |||
905 | } | |||
906 | //now remove the attribute | |||
907 | std::set<sal_uInt16> aAttribs; | |||
908 | aAttribs.insert( RES_TXTATR_INETFMT ); | |||
909 | rWrtSh.ResetAttr( aAttribs ); | |||
910 | if(!bSel) | |||
911 | { | |||
912 | rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent); | |||
913 | rWrtSh.EndAction(); | |||
914 | } | |||
915 | } | |||
916 | break; | |||
917 | case SID_ATTR_BRUSH_CHAR( 10000 + 591 ) : | |||
918 | case SID_ATTR_CHAR_SCALEWIDTH( 10000 + 911 ) : | |||
919 | case SID_ATTR_CHAR_ROTATED( 10000 + 910 ) : | |||
920 | case FN_TXTATR_INET((20000 + 1000) +29) : | |||
921 | case FN_INSERT_HYPERLINK((20000 + 300) + 14): | |||
922 | { | |||
923 | const sal_uInt16 nWhich = GetPool().GetWhich( nSlot ); | |||
924 | if ( pArgs && pArgs->GetItemState( nWhich ) == SfxItemState::SET ) | |||
925 | bUseDialog = false; | |||
926 | [[fallthrough]]; | |||
927 | } | |||
928 | case SID_CHAR_DLG( 10000 + 296 ): | |||
929 | case SID_CHAR_DLG_EFFECT( 10000 + 1133 ): | |||
930 | { | |||
931 | sw_CharDialog( rWrtSh, bUseDialog, nSlot, pArgs, &rReq ); | |||
932 | } | |||
933 | break; | |||
934 | case SID_CHAR_DLG_FOR_PARAGRAPH( 10000 + 1068 ): | |||
935 | { | |||
936 | rWrtSh.Push(); //save current cursor | |||
937 | SwLangHelper::SelectCurrentPara( rWrtSh ); | |||
938 | sw_CharDialog( rWrtSh, bUseDialog, nSlot, pArgs, &rReq ); | |||
939 | rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent); // restore old cursor | |||
940 | } | |||
941 | break; | |||
942 | case SID_ATTR_LRSPACE( 10000 + 48 ) : | |||
943 | case SID_ATTR_ULSPACE( 10000 + 49 ) : | |||
944 | case SID_ATTR_BRUSH( 10000 + 1 ) : | |||
945 | case SID_PARA_VERTALIGN( 10000 + 925 ) : | |||
946 | case SID_ATTR_PARA_NUMRULE( 10000 + 587 ) : | |||
947 | case SID_ATTR_PARA_REGISTER( 10000 + 413 ) : | |||
948 | case SID_ATTR_PARA_PAGENUM( 10000 + 457 ) : | |||
949 | case FN_FORMAT_LINENUMBER((20000 + 1600) + 144) : | |||
950 | case FN_NUMBER_NEWSTART((20000 + 1600) + 138) : | |||
951 | case FN_NUMBER_NEWSTART_AT((20000 + 1600) + 139) : | |||
952 | case FN_FORMAT_DROPCAPS((20000 + 400) + 54) : | |||
953 | case FN_DROP_TEXT((20000 + 2400)+18): | |||
954 | case SID_ATTR_PARA_LRSPACE( 10000 + 43 ): | |||
955 | { | |||
956 | const sal_uInt16 nWhich = GetPool().GetWhich( nSlot ); | |||
957 | if ( pArgs && pArgs->GetItemState( nWhich ) == SfxItemState::SET ) | |||
958 | bUseDialog = false; | |||
959 | [[fallthrough]]; | |||
960 | } | |||
961 | case SID_PARA_DLG( 10000 + 297 ): | |||
962 | { | |||
963 | SwPaM* pPaM = nullptr; | |||
964 | ||||
965 | if ( pArgs ) | |||
966 | { | |||
967 | const SfxPoolItem* pPaMItem = nullptr; | |||
968 | pArgs->GetItemState( GetPool().GetWhich( FN_PARAM_PAM((20000 + 2400)+27) ), false, &pPaMItem ); | |||
969 | if ( pPaMItem ) | |||
970 | pPaM = static_cast< const SwPaMItem* >( pPaMItem )->GetValue( ); | |||
971 | } | |||
972 | ||||
973 | if ( !pPaM ) | |||
974 | pPaM = rWrtSh.GetCursor(); | |||
975 | ||||
976 | FieldUnit eMetric = ::GetDfltMetric( dynamic_cast<SwWebView*>( &GetView()) != nullptr ); | |||
977 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->PutItem(SfxUInt16Item(SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499 ) + 1) + 8), static_cast< sal_uInt16 >(eMetric))); | |||
978 | ||||
979 | bool bApplyCharUnit = ::HasCharUnit( dynamic_cast<SwWebView*>( &GetView()) != nullptr ); | |||
980 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->PutItem(SfxBoolItem(SID_ATTR_APPLYCHARUNIT(((((10000 + 1499) + 1) + 499) + 1) + 88), bApplyCharUnit)); | |||
981 | ||||
982 | SfxItemSet aCoreSet( | |||
983 | GetPool(), | |||
984 | svl::Items< | |||
985 | RES_PARATR_BEGIN, RES_FRMATR_END - 1, | |||
986 | // FillAttribute support: | |||
987 | XATTR_FILL_FIRST, XATTR_FILL_LAST, | |||
988 | // Includes SID_ATTR_TABSTOP_POS: | |||
989 | SID_ATTR_TABSTOP_DEFAULTS( 10000 + 3 ), SID_ATTR_TABSTOP_OFFSET( 10000 + 5 ), | |||
990 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), | |||
991 | SID_ATTR_PARA_MODEL( 10000 + 65 ), SID_ATTR_PARA_KEEP( 10000 + 66 ), | |||
992 | // Items to hand over XPropertyList things like XColorList, | |||
993 | // XHatchList, XGradientList, and XBitmapList to the Area | |||
994 | // TabPage: | |||
995 | SID_COLOR_TABLETypedWhichId<SvxColorListItem>( 10000 + 179 ), SID_PATTERN_LISTTypedWhichId<SvxPatternListItem>( 10000 + 183 ), | |||
996 | SID_HTML_MODE(10000 + 414), SID_HTML_MODE(10000 + 414), | |||
997 | SID_ATTR_PARA_PAGENUM( 10000 + 457 ), SID_ATTR_PARA_PAGENUM( 10000 + 457 ), | |||
998 | FN_PARAM_1((20000 + 1100)+60), FN_PARAM_1((20000 + 1100)+60), | |||
999 | FN_NUMBER_NEWSTART((20000 + 1600) + 138), FN_NUMBER_NEWSTART_AT((20000 + 1600) + 139), | |||
1000 | FN_DROP_TEXT((20000 + 2400)+18), FN_DROP_CHAR_STYLE_NAME((20000 + 2400)+19)>{}); | |||
1001 | ||||
1002 | // get also the list level indent values merged as LR-SPACE item, if needed. | |||
1003 | rWrtSh.GetPaMAttr( pPaM, aCoreSet, true ); | |||
1004 | ||||
1005 | // create needed items for XPropertyList entries from the DrawModel so that | |||
1006 | // the Area TabPage can access them | |||
1007 | // Do this after GetCurAttr, this resets the ItemSet content again | |||
1008 | const SwDrawModel* pDrawModel = GetView().GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel(); | |||
1009 | ||||
1010 | aCoreSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLETypedWhichId<SvxColorListItem>( 10000 + 179 ))); | |||
1011 | aCoreSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LISTTypedWhichId<SvxGradientListItem>( 10000 + 180 ))); | |||
1012 | aCoreSet.Put(SvxHatchListItem(pDrawModel->GetHatchList(), SID_HATCH_LISTTypedWhichId<SvxHatchListItem>( 10000 + 181 ))); | |||
1013 | aCoreSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), SID_BITMAP_LISTTypedWhichId<SvxBitmapListItem>( 10000 + 182 ))); | |||
1014 | aCoreSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LISTTypedWhichId<SvxPatternListItem>( 10000 + 183 ))); | |||
1015 | aCoreSet.Put(SfxUInt16Item(SID_HTML_MODE(10000 + 414), | |||
1016 | ::GetHtmlMode(GetView().GetDocShell()))); | |||
1017 | ||||
1018 | // Tabulators: Put DefaultTabs into ItemSet | |||
1019 | const SvxTabStopItem& rDefTabs = | |||
1020 | GetPool().GetDefaultItem(RES_PARATR_TABSTOP); | |||
1021 | ||||
1022 | const sal_uInt16 nDefDist = static_cast<sal_uInt16>(::GetTabDist( rDefTabs )); | |||
1023 | SfxUInt16Item aDefDistItem( SID_ATTR_TABSTOP_DEFAULTS( 10000 + 3 ), nDefDist ); | |||
1024 | aCoreSet.Put( aDefDistItem ); | |||
1025 | ||||
1026 | // Current tabulator | |||
1027 | SfxUInt16Item aTabPos( SID_ATTR_TABSTOP_POS( 10000 + 4 ), 0 ); | |||
1028 | aCoreSet.Put( aTabPos ); | |||
1029 | ||||
1030 | // Left border as offset | |||
1031 | //#i24363# tab stops relative to indent | |||
1032 | const long nOff = rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::TABS_RELATIVE_TO_INDENT) ? | |||
1033 | aCoreSet.Get( RES_LR_SPACE ).GetTextLeft() : 0; | |||
1034 | SfxInt32Item aOff( SID_ATTR_TABSTOP_OFFSET( 10000 + 5 ), nOff ); | |||
1035 | aCoreSet.Put( aOff ); | |||
1036 | ||||
1037 | // Setting the BoxInfo | |||
1038 | ::PrepareBoxInfo( aCoreSet, rWrtSh ); | |||
1039 | ||||
1040 | // Current page format | |||
1041 | ::SwToSfxPageDescAttr( aCoreSet ); | |||
1042 | ||||
1043 | // Properties of numbering | |||
1044 | if (rWrtSh.GetNumRuleAtCurrCursorPos()) | |||
1045 | { | |||
1046 | SfxBoolItem aStart( FN_NUMBER_NEWSTART((20000 + 1600) + 138), rWrtSh.IsNumRuleStart( pPaM ) ); | |||
1047 | aCoreSet.Put(aStart); | |||
1048 | SfxUInt16Item aStartAt( FN_NUMBER_NEWSTART_AT((20000 + 1600) + 139), | |||
1049 | rWrtSh.GetNodeNumStart( pPaM ) ); | |||
1050 | aCoreSet.Put(aStartAt); | |||
1051 | } | |||
1052 | VclPtr<SfxAbstractTabDialog> pDlg; | |||
1053 | ||||
1054 | if ( bUseDialog && GetActiveView() ) | |||
1055 | { | |||
1056 | OString sDefPage; | |||
1057 | if (pItem) | |||
1058 | sDefPage = OUStringToOString(static_cast<const SfxStringItem*>(pItem)->GetValue(), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))); | |||
1059 | ||||
1060 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
1061 | pDlg.reset(pFact->CreateSwParaDlg(GetView().GetFrameWeld(), GetView(), aCoreSet, false, sDefPage)); | |||
1062 | } | |||
1063 | ||||
1064 | if ( !bUseDialog ) | |||
1065 | { | |||
1066 | if ( nSlot == SID_ATTR_PARA_LRSPACE( 10000 + 43 )) | |||
1067 | { | |||
1068 | SvxLRSpaceItem aParaMargin(static_cast<const SvxLRSpaceItem&>(pArgs->Get(nSlot))); | |||
1069 | aParaMargin.SetWhich( RES_LR_SPACE); | |||
1070 | aCoreSet.Put(aParaMargin); | |||
1071 | ||||
1072 | sw_ParagraphDialogResult(&aCoreSet, rWrtSh, rReq, pPaM); | |||
1073 | } | |||
1074 | else | |||
1075 | sw_ParagraphDialogResult(const_cast<SfxItemSet*>(pArgs), rWrtSh, rReq, pPaM); | |||
1076 | } | |||
1077 | else if (pDlg) | |||
1078 | { | |||
1079 | auto pRequest = std::make_shared<SfxRequest>(rReq); | |||
1080 | rReq.Ignore(); // the 'old' request is not relevant any more | |||
1081 | ||||
1082 | auto xPaM(std::make_shared<SwPaM>(*pPaM, nullptr)); // tdf#134439 make a copy to use at later apply | |||
1083 | pDlg->StartExecuteAsync([pDlg, &rWrtSh, pRequest, nDefDist, xPaM](sal_Int32 nResult){ | |||
1084 | if (nResult == RET_OK) | |||
1085 | { | |||
1086 | // Apply defaults if necessary. | |||
1087 | SfxItemSet* pSet = const_cast<SfxItemSet*>(pDlg->GetOutputItemSet()); | |||
1088 | sal_uInt16 nNewDist; | |||
1089 | const SfxPoolItem* pItem2 = nullptr; | |||
1090 | if (SfxItemState::SET == pSet->GetItemState(SID_ATTR_TABSTOP_DEFAULTS( 10000 + 3 ), false, &pItem2) && | |||
1091 | nDefDist != (nNewDist = static_cast<const SfxUInt16Item*>(pItem2)->GetValue()) ) | |||
1092 | { | |||
1093 | SvxTabStopItem aDefTabs( 0, 0, SvxTabAdjust::Default, RES_PARATR_TABSTOP ); | |||
1094 | MakeDefTabs( nNewDist, aDefTabs ); | |||
1095 | rWrtSh.SetDefault( aDefTabs ); | |||
1096 | pSet->ClearItem( SID_ATTR_TABSTOP_DEFAULTS( 10000 + 3 ) ); | |||
1097 | } | |||
1098 | ||||
1099 | if (SfxItemState::SET == pSet->GetItemState(FN_PARAM_1((20000 + 1100)+60), false, &pItem2)) | |||
1100 | { | |||
1101 | pSet->Put(SfxStringItem(FN_DROP_TEXT((20000 + 2400)+18), static_cast<const SfxStringItem*>(pItem2)->GetValue())); | |||
1102 | pSet->ClearItem(FN_PARAM_1((20000 + 1100)+60)); | |||
1103 | } | |||
1104 | ||||
1105 | if (SfxItemState::SET == pSet->GetItemState(RES_PARATR_DROP, false, &pItem2)) | |||
1106 | { | |||
1107 | OUString sCharStyleName; | |||
1108 | if (static_cast<const SwFormatDrop*>(pItem2)->GetCharFormat()) | |||
1109 | sCharStyleName = static_cast<const SwFormatDrop*>(pItem2)->GetCharFormat()->GetName(); | |||
1110 | pSet->Put(SfxStringItem(FN_DROP_CHAR_STYLE_NAME((20000 + 2400)+19), sCharStyleName)); | |||
1111 | } | |||
1112 | ||||
1113 | sw_ParagraphDialogResult(pSet, rWrtSh, *pRequest, xPaM.get()); | |||
1114 | } | |||
1115 | pDlg->disposeOnce(); | |||
1116 | }); | |||
1117 | } | |||
1118 | } | |||
1119 | break; | |||
1120 | case FN_NUM_CONTINUE((20000 + 1800) + 36): | |||
1121 | { | |||
1122 | OUString sContinuedListId; | |||
1123 | const SwNumRule* pRule = | |||
1124 | rWrtSh.SearchNumRule( true, sContinuedListId ); | |||
1125 | // #i86492# | |||
1126 | // Search also for bullet list | |||
1127 | if ( !pRule ) | |||
1128 | { | |||
1129 | pRule = rWrtSh.SearchNumRule( false, sContinuedListId ); | |||
1130 | } | |||
1131 | if ( pRule ) | |||
1132 | { | |||
1133 | rWrtSh.SetCurNumRule( *pRule, false, sContinuedListId ); | |||
1134 | } | |||
1135 | } | |||
1136 | break; | |||
1137 | ||||
1138 | case FN_SELECT_PARA((20000 + 100) + 97): | |||
1139 | { | |||
1140 | if ( !rWrtSh.IsSttOfPara() ) | |||
1141 | rWrtSh.SttPara(); | |||
1142 | else | |||
1143 | rWrtSh.EnterStdMode(); | |||
1144 | rWrtSh.EndPara( true ); | |||
1145 | } | |||
1146 | break; | |||
1147 | ||||
1148 | case SID_DEC_INDENT( 10000 + 461 ): | |||
1149 | case SID_INC_INDENT( 10000 + 462 ): | |||
1150 | //According to the requirement, modified the behavior when user | |||
1151 | //using the indent button on the toolbar. Now if we increase/decrease indent for a | |||
1152 | //paragraph which has bullet style it will increase/decrease the bullet level. | |||
1153 | { | |||
1154 | //If the current paragraph has bullet call the function to | |||
1155 | //increase or decrease the bullet level. | |||
1156 | //Why could I know whether a paragraph has bullet or not by checking the below conditions? | |||
1157 | //Please refer to the "case KEY_TAB:" section in SwEditWin::KeyInput(..) : | |||
1158 | // if( rSh.GetCurNumRule() && rSh.IsSttOfPara() && | |||
1159 | // !rSh.HasReadonlySel() ) | |||
1160 | // eKeyState = KS_NumDown; | |||
1161 | //Above code demonstrates that when the cursor is at the start of a paragraph which has bullet, | |||
1162 | //press TAB will increase the bullet level. | |||
1163 | //So I copied from that ^^ | |||
1164 | if ( rWrtSh.GetNumRuleAtCurrCursorPos() && !rWrtSh.HasReadonlySel() ) | |||
1165 | { | |||
1166 | rWrtSh.NumUpDown( SID_INC_INDENT( 10000 + 462 ) == nSlot ); | |||
1167 | } | |||
1168 | else //execute the original processing functions | |||
1169 | { | |||
1170 | //below is copied of the old codes | |||
1171 | rWrtSh.MoveLeftMargin( SID_INC_INDENT( 10000 + 462 ) == nSlot, rReq.GetModifier() != KEY_MOD1 ); | |||
1172 | } | |||
1173 | } | |||
1174 | rReq.Done(); | |||
1175 | break; | |||
1176 | ||||
1177 | case FN_DEC_INDENT_OFFSET((20000 + 1600) + 151): | |||
1178 | case FN_INC_INDENT_OFFSET((20000 + 1600) + 150): | |||
1179 | rWrtSh.MoveLeftMargin( FN_INC_INDENT_OFFSET((20000 + 1600) + 150) == nSlot, rReq.GetModifier() == KEY_MOD1 ); | |||
1180 | rReq.Done(); | |||
1181 | break; | |||
1182 | ||||
1183 | case SID_ATTR_CHAR_COLOR2(10000 + 537): | |||
1184 | { | |||
1185 | Color aSet; | |||
1186 | const SfxPoolItem* pColorStringItem = nullptr; | |||
1187 | bool bHasItem = false; | |||
1188 | ||||
1189 | if(pItem) | |||
1190 | { | |||
1191 | aSet = static_cast<const SvxColorItem*>(pItem)->GetValue(); | |||
1192 | bHasItem = true; | |||
1193 | } | |||
1194 | else if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR(10000 + 540), false, &pColorStringItem)) | |||
1195 | { | |||
1196 | OUString sColor = static_cast<const SfxStringItem*>(pColorStringItem)->GetValue(); | |||
1197 | aSet = Color(sColor.toInt32(16)); | |||
1198 | bHasItem = true; | |||
1199 | } | |||
1200 | ||||
1201 | if (bHasItem) | |||
1202 | { | |||
1203 | SwEditWin& rEditWin = GetView().GetEditWin(); | |||
1204 | rEditWin.SetWaterCanTextColor(aSet); | |||
1205 | SwApplyTemplate* pApply = rEditWin.GetApplyTemplate(); | |||
1206 | ||||
1207 | // If there is a selection, then set the color on it | |||
1208 | // otherwise, it'll be the color for the next text to be typed | |||
1209 | if(!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT(10000 + 488)) | |||
1210 | { | |||
1211 | rWrtSh.SetAttrItem(SvxColorItem (aSet, RES_CHRATR_COLOR)); | |||
1212 | } | |||
1213 | ||||
1214 | rReq.Done(); | |||
1215 | } | |||
1216 | } | |||
1217 | break; | |||
1218 | case SID_ATTR_CHAR_COLOR_BACKGROUND(10000 + 489): | |||
1219 | case SID_ATTR_CHAR_COLOR_BACKGROUND_EXT(10000 + 490): | |||
1220 | case SID_ATTR_CHAR_COLOR_EXT(10000 + 488): | |||
1221 | { | |||
1222 | Color aSet; | |||
1223 | const SfxPoolItem* pColorStringItem = nullptr; | |||
1224 | ||||
1225 | if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR(10000 + 540), false, &pColorStringItem)) | |||
1226 | { | |||
1227 | OUString sColor = static_cast<const SfxStringItem*>(pColorStringItem)->GetValue(); | |||
1228 | if (sColor == "transparent") | |||
1229 | aSet = COL_TRANSPARENT; | |||
1230 | else | |||
1231 | aSet = Color(sColor.toInt32(16)); | |||
1232 | } | |||
1233 | else if (pItem) | |||
1234 | aSet = static_cast<const SvxColorItem*>(pItem)->GetValue(); | |||
1235 | else | |||
1236 | aSet = COL_TRANSPARENT; | |||
1237 | ||||
1238 | SwEditWin& rEdtWin = GetView().GetEditWin(); | |||
1239 | if (nSlot != SID_ATTR_CHAR_COLOR_EXT(10000 + 488)) | |||
1240 | rEdtWin.SetWaterCanTextBackColor(aSet); | |||
1241 | else if (pItem) | |||
1242 | rEdtWin.SetWaterCanTextColor(aSet); | |||
1243 | ||||
1244 | SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate(); | |||
1245 | SwApplyTemplate aTempl; | |||
1246 | if (!pApply && (rWrtSh.HasSelection() || rReq.IsAPI())) | |||
1247 | { | |||
1248 | if (nSlot != SID_ATTR_CHAR_COLOR_EXT(10000 + 488)) | |||
1249 | { | |||
1250 | SfxItemSet aCoreSet( rWrtSh.GetView().GetPool(), svl::Items< | |||
1251 | RES_CHRATR_BACKGROUND, RES_CHRATR_BACKGROUND>{} ); | |||
1252 | ||||
1253 | rWrtSh.GetCurAttr( aCoreSet ); | |||
1254 | ||||
1255 | // Remove highlight if already set of the same color | |||
1256 | const SvxBrushItem& rBrushItem = aCoreSet.Get(RES_CHRATR_BACKGROUND); | |||
1257 | if ( aSet == rBrushItem.GetColor() ) | |||
1258 | aSet = COL_TRANSPARENT; | |||
1259 | ||||
1260 | ApplyCharBackground(aSet, rWrtSh); | |||
1261 | } | |||
1262 | else | |||
1263 | rWrtSh.SetAttrItem( | |||
1264 | SvxColorItem(aSet, RES_CHRATR_COLOR) ); | |||
1265 | } | |||
1266 | else if (nSlot == SID_ATTR_CHAR_COLOR_BACKGROUND(10000 + 489)) | |||
1267 | { | |||
1268 | if (!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_BACKGROUND_EXT(10000 + 490)) | |||
1269 | { | |||
1270 | aTempl.nColor = SID_ATTR_CHAR_COLOR_BACKGROUND_EXT(10000 + 490); | |||
1271 | rEdtWin.SetApplyTemplate(aTempl); | |||
1272 | } | |||
1273 | } | |||
1274 | else | |||
1275 | { | |||
1276 | if(!pApply || pApply->nColor != nSlot) | |||
1277 | aTempl.nColor = nSlot; | |||
1278 | rEdtWin.SetApplyTemplate(aTempl); | |||
1279 | } | |||
1280 | ||||
1281 | rReq.Done(); | |||
1282 | } | |||
1283 | break; | |||
1284 | ||||
1285 | case FN_NUM_BULLET_MOVEDOWN((20000 + 100) + 35): | |||
1286 | if (!rWrtSh.IsAddMode()) | |||
1287 | rWrtSh.MoveParagraph(); | |||
1288 | rReq.Done(); | |||
1289 | break; | |||
1290 | ||||
1291 | case FN_NUM_BULLET_MOVEUP((20000 + 100) + 34): | |||
1292 | if (!rWrtSh.IsAddMode()) | |||
1293 | rWrtSh.MoveParagraph(-1); | |||
1294 | rReq.Done(); | |||
1295 | break; | |||
1296 | case SID_RUBY_DIALOG(5000 + 1656): | |||
1297 | case SID_HYPERLINK_DIALOG(5000 + 678): | |||
1298 | { | |||
1299 | SfxRequest aReq(nSlot, SfxCallMode::SLOT, SfxGetpApp()->GetPool()); | |||
1300 | GetView().GetViewFrame()->ExecuteSlot( aReq); | |||
1301 | rReq.Ignore(); | |||
1302 | } | |||
1303 | break; | |||
1304 | case FN_INSERT_PAGEHEADER((20000 + 1400) + 13): | |||
1305 | case FN_INSERT_PAGEFOOTER((20000 + 1400) + 14): | |||
1306 | if(pArgs && pArgs->Count()) | |||
1307 | { | |||
1308 | OUString sStyleName; | |||
1309 | if(pItem) | |||
1310 | sStyleName = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
1311 | bool bOn = true; | |||
1312 | if( SfxItemState::SET == pArgs->GetItemState(FN_PARAM_1((20000 + 1100)+60), false, &pItem)) | |||
1313 | bOn = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
1314 | rWrtSh.ChangeHeaderOrFooter(sStyleName, FN_INSERT_PAGEHEADER((20000 + 1400) + 13) == nSlot, bOn, !rReq.IsAPI()); | |||
1315 | rReq.Done(); | |||
1316 | } | |||
1317 | break; | |||
1318 | case FN_READONLY_SELECTION_MODE((20000 + 900) + 89) : | |||
1319 | if(GetView().GetDocShell()->IsReadOnly()) | |||
1320 | { | |||
1321 | rWrtSh.SetReadonlySelectionOption( | |||
1322 | !rWrtSh.GetViewOptions()->IsSelectionInReadonly()); | |||
1323 | rWrtSh.ShowCursor(); | |||
1324 | } | |||
1325 | break; | |||
1326 | case FN_SELECTION_MODE_DEFAULT((20000 + 900) + 90): | |||
1327 | case FN_SELECTION_MODE_BLOCK((20000 + 900) + 91) : | |||
1328 | { | |||
1329 | bool bSetBlockMode = !rWrtSh.IsBlockMode(); | |||
1330 | if( pArgs && SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem)) | |||
1331 | bSetBlockMode = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
1332 | if( ( nSlot == FN_SELECTION_MODE_DEFAULT((20000 + 900) + 90) ) != bSetBlockMode ) | |||
1333 | rWrtSh.EnterBlockMode(); | |||
1334 | else | |||
1335 | rWrtSh.EnterStdMode(); | |||
1336 | SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings(); | |||
1337 | rBnd.Invalidate(FN_STAT_SELMODE((20000 + 1180) + 5)); | |||
1338 | rBnd.Update(FN_STAT_SELMODE((20000 + 1180) + 5)); | |||
1339 | } | |||
1340 | break; | |||
1341 | case SID_OPEN_HYPERLINK( 10000 + 955 ): | |||
1342 | case SID_COPY_HYPERLINK_LOCATION( 10000 + 1193 ): | |||
1343 | { | |||
1344 | SfxItemSet aSet(GetPool(), | |||
1345 | svl::Items<RES_TXTATR_INETFMT, | |||
1346 | RES_TXTATR_INETFMT>{}); | |||
1347 | rWrtSh.GetCurAttr(aSet); | |||
1348 | if(SfxItemState::SET <= aSet.GetItemState( RES_TXTATR_INETFMT )) | |||
1349 | { | |||
1350 | const SwFormatINetFormat& rINetFormat = dynamic_cast<const SwFormatINetFormat&>( aSet.Get(RES_TXTATR_INETFMT) ); | |||
1351 | if( nSlot == SID_COPY_HYPERLINK_LOCATION( 10000 + 1193 ) ) | |||
1352 | { | |||
1353 | OUString hyperlinkLocation = rINetFormat.GetValue(); | |||
1354 | ::uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetView().GetEditWin().GetClipboard(); | |||
1355 | ||||
1356 | if (comphelper::LibreOfficeKit::isActive()) | |||
1357 | { | |||
1358 | std::function<void (int, const char*)> callback = [&] (int callbackType, const char* text) { GetView().libreOfficeKitViewCallback(callbackType, text); } ; | |||
1359 | vcl::unohelper::TextDataObject::CopyStringTo(hyperlinkLocation, xClipboard, &callback ); | |||
1360 | } | |||
1361 | else | |||
1362 | vcl::unohelper::TextDataObject::CopyStringTo(hyperlinkLocation, xClipboard, nullptr ); | |||
1363 | } | |||
1364 | else | |||
1365 | rWrtSh.ClickToINetAttr(rINetFormat); | |||
1366 | } | |||
1367 | } | |||
1368 | break; | |||
1369 | case SID_OPEN_XML_FILTERSETTINGS( 10000 + 958 ): | |||
1370 | { | |||
1371 | HandleOpenXmlFilterSettings(rReq); | |||
1372 | } | |||
1373 | break; | |||
1374 | case FN_FORMAT_APPLY_HEAD1((20000 + 1600) + 154): | |||
1375 | { | |||
1376 | } | |||
1377 | break; | |||
1378 | case FN_FORMAT_APPLY_HEAD2((20000 + 1600) + 155): | |||
1379 | { | |||
1380 | } | |||
1381 | break; | |||
1382 | case FN_FORMAT_APPLY_HEAD3((20000 + 1600) + 156): | |||
1383 | { | |||
1384 | } | |||
1385 | break; | |||
1386 | case FN_FORMAT_APPLY_DEFAULT((20000 + 1600) + 157): | |||
1387 | { | |||
1388 | } | |||
1389 | break; | |||
1390 | case FN_FORMAT_APPLY_TEXTBODY((20000 + 1600) + 158): | |||
1391 | { | |||
1392 | } | |||
1393 | break; | |||
1394 | case FN_WORDCOUNT_DIALOG((20000 + 2200) + 98): | |||
1395 | { | |||
1396 | GetView().UpdateWordCount(this, nSlot); | |||
1397 | } | |||
1398 | break; | |||
1399 | case FN_PROTECT_FIELDS((20000 + 1400) + 26): | |||
1400 | case FN_PROTECT_BOOKMARKS((20000 + 1400) + 27): | |||
1401 | { | |||
1402 | IDocumentSettingAccess& rIDSA = rWrtSh.getIDocumentSettingAccess(); | |||
1403 | DocumentSettingId aSettingId = nSlot == FN_PROTECT_FIELDS((20000 + 1400) + 26) | |||
1404 | ? DocumentSettingId::PROTECT_FIELDS | |||
1405 | : DocumentSettingId::PROTECT_BOOKMARKS; | |||
1406 | rIDSA.set(aSettingId, !rIDSA.get(aSettingId)); | |||
1407 | // Invalidate so that toggle state gets updated | |||
1408 | SfxViewFrame* pViewFrame = GetView().GetViewFrame(); | |||
1409 | pViewFrame->GetBindings().Invalidate(nSlot); | |||
1410 | pViewFrame->GetBindings().Update(nSlot); | |||
1411 | } | |||
1412 | break; | |||
1413 | case SID_FM_CTL_PROPERTIES( 10000 + 613 ): | |||
1414 | { | |||
1415 | SwPosition aPos(*GetShell().GetCursor()->GetPoint()); | |||
1416 | sw::mark::IFieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos); | |||
1417 | if ( !pFieldBM ) | |||
1418 | { | |||
1419 | --aPos.nContent; | |||
1420 | pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos); | |||
1421 | } | |||
1422 | ||||
1423 | if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN"vnd.oasis.opendocument.field.FORMDROPDOWN" ) | |||
1424 | { | |||
1425 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
1426 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateDropDownFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), pFieldBM)); | |||
1427 | if (pDlg->Execute() == RET_OK) | |||
1428 | { | |||
1429 | pFieldBM->Invalidate(); | |||
1430 | rWrtSh.InvalidateWindows( rWrtSh.GetView().GetVisArea() ); | |||
1431 | rWrtSh.UpdateCursor(); // cursor position might be invalid | |||
1432 | // Hide the button here and make it visible later, to make transparent background work with SAL_USE_VCLPLUGIN=gen | |||
1433 | dynamic_cast<::sw::mark::DropDownFieldmark&>(*pFieldBM).HideButton(); | |||
1434 | } | |||
1435 | } | |||
1436 | else if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDATE"vnd.oasis.opendocument.field.FORMDATE" ) | |||
1437 | { | |||
1438 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
1439 | sw::mark::DateFieldmark& rDateField = dynamic_cast<sw::mark::DateFieldmark&>(*pFieldBM); | |||
1440 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateDateFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), &rDateField, *GetView().GetDocShell()->GetDoc())); | |||
1441 | if (pDlg->Execute() == RET_OK) | |||
1442 | { | |||
1443 | rDateField.Invalidate(); | |||
1444 | rWrtSh.InvalidateWindows( rWrtSh.GetView().GetVisArea() ); | |||
1445 | rWrtSh.UpdateCursor(); // cursor position might be invalid | |||
1446 | // Hide the button here and make it visible later, to make transparent background work with SAL_USE_VCLPLUGIN=gen | |||
1447 | rDateField.HideButton(); | |||
1448 | } | |||
1449 | } | |||
1450 | else | |||
1451 | { | |||
1452 | SfxRequest aReq( GetView().GetViewFrame(), SID_FM_CTL_PROPERTIES( 10000 + 613 ) ); | |||
1453 | aReq.AppendItem( SfxBoolItem( SID_FM_CTL_PROPERTIES( 10000 + 613 ), true ) ); | |||
1454 | rWrtSh.GetView().GetFormShell()->Execute( aReq ); | |||
1455 | } | |||
1456 | } | |||
1457 | break; | |||
1458 | case SID_SPELLCHECK_IGNORE( 10000 + 246 ): | |||
1459 | { | |||
1460 | SwPaM *pPaM = rWrtSh.GetCursor(); | |||
1461 | if (pPaM) | |||
1462 | SwEditShell::IgnoreGrammarErrorAt( *pPaM ); | |||
1463 | } | |||
1464 | break; | |||
1465 | case SID_SPELLCHECK_IGNORE_ALL( 10000 + 247 ): | |||
1466 | { | |||
1467 | OUString sApplyText; | |||
1468 | const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1((20000 + 1100)+60)); | |||
1469 | if (pItem2) | |||
1470 | sApplyText = pItem2->GetValue(); | |||
1471 | ||||
1472 | if(sApplyText == "Grammar") | |||
1473 | { | |||
1474 | linguistic2::ProofreadingResult aGrammarCheckRes; | |||
1475 | sal_Int32 nErrorInResult = -1; | |||
1476 | uno::Sequence< OUString > aSuggestions; | |||
1477 | sal_Int32 nErrorPosInText = -1; | |||
1478 | SwRect aToFill; | |||
1479 | bool bCorrectionRes = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill ); | |||
1480 | if(bCorrectionRes) | |||
1481 | { | |||
1482 | try { | |||
1483 | uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList(); | |||
1484 | aGrammarCheckRes.xProofreader->ignoreRule( | |||
1485 | aGrammarCheckRes.aErrors[ nErrorInResult ].aRuleIdentifier, | |||
1486 | aGrammarCheckRes.aLocale ); | |||
1487 | // refresh the layout of the actual paragraph (faster) | |||
1488 | SwPaM *pPaM = rWrtSh.GetCursor(); | |||
1489 | if (pPaM) | |||
1490 | SwEditShell::IgnoreGrammarErrorAt( *pPaM ); | |||
1491 | // refresh the layout of all paragraphs (workaround to launch a dictionary event) | |||
1492 | xDictionary->setActive(false); | |||
1493 | xDictionary->setActive(true); | |||
1494 | } | |||
1495 | catch( const uno::Exception& ) | |||
1496 | { | |||
1497 | } | |||
1498 | } | |||
1499 | } | |||
1500 | else if (sApplyText == "Spelling") | |||
1501 | { | |||
1502 | SwRect aToFill; | |||
1503 | uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt( rWrtSh.GetCorrection(nullptr, aToFill) ); | |||
1504 | uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList(); | |||
1505 | OUString sWord(xSpellAlt->getWord()); | |||
1506 | linguistic::DictionaryError nAddRes = linguistic::AddEntryToDic( xDictionary, | |||
1507 | sWord, false, OUString() ); | |||
1508 | if (linguistic::DictionaryError::NONE != nAddRes && !xDictionary->getEntry(sWord).is()) | |||
1509 | { | |||
1510 | SvxDicError(rWrtSh.GetView().GetFrameWeld(), nAddRes); | |||
1511 | } | |||
1512 | } | |||
1513 | } | |||
1514 | break; | |||
1515 | case SID_SPELLCHECK_APPLY_SUGGESTION( 10000 + 248 ): | |||
1516 | { | |||
1517 | OUString sApplyText; | |||
1518 | const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1((20000 + 1100)+60)); | |||
1519 | if (pItem2) | |||
1520 | sApplyText = pItem2->GetValue(); | |||
1521 | ||||
1522 | const OUString sSpellingRule("Spelling_"); | |||
1523 | const OUString sGrammarRule("Grammar_"); | |||
1524 | ||||
1525 | bool bGrammar = false; | |||
1526 | sal_Int32 nPos = 0; | |||
1527 | uno::Reference< linguistic2::XSpellAlternatives > xSpellAlt; | |||
1528 | if(-1 != (nPos = sApplyText.indexOf( sGrammarRule ))) | |||
1529 | { | |||
1530 | sApplyText = sApplyText.replaceAt(nPos, sGrammarRule.getLength(), ""); | |||
1531 | bGrammar = true; | |||
1532 | } | |||
1533 | else if (-1 != (nPos = sApplyText.indexOf( sSpellingRule ))) | |||
1534 | { | |||
1535 | sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), ""); | |||
1536 | SwRect aToFill; | |||
1537 | xSpellAlt.set(rWrtSh.GetCorrection(nullptr, aToFill)); | |||
1538 | bGrammar = false; | |||
1539 | } | |||
1540 | ||||
1541 | if (!bGrammar && !xSpellAlt.is()) | |||
1542 | return; | |||
1543 | ||||
1544 | bool bOldIns = rWrtSh.IsInsMode(); | |||
1545 | rWrtSh.SetInsMode(); | |||
1546 | ||||
1547 | OUString aTmp( sApplyText ); | |||
1548 | OUString aOrig( bGrammar ? OUString() : xSpellAlt->getWord() ); | |||
1549 | ||||
1550 | // if original word has a trailing . (likely the end of a sentence) | |||
1551 | // and the replacement text hasn't, then add it to the replacement | |||
1552 | if (!aTmp.isEmpty() && !aOrig.isEmpty() && | |||
1553 | aOrig.endsWith(".") && /* !IsAlphaNumeric ??*/ | |||
1554 | !aTmp.endsWith(".")) | |||
1555 | { | |||
1556 | aTmp += "."; | |||
1557 | } | |||
1558 | ||||
1559 | SwRewriter aRewriter; | |||
1560 | ||||
1561 | aRewriter.AddRule(UndoArg1, rWrtSh.GetCursorDescr()); | |||
1562 | aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDSreinterpret_cast<char const *>("STR_YIELDS" "\004" u8"→" ))); | |||
1563 | ||||
1564 | OUString aTmpStr = SwResId(STR_START_QUOTEreinterpret_cast<char const *>("STR_START_QUOTE" "\004" u8"“")) + | |||
1565 | aTmp + SwResId(STR_END_QUOTEreinterpret_cast<char const *>("STR_END_QUOTE" "\004" u8"”" )); | |||
1566 | aRewriter.AddRule(UndoArg3, aTmpStr); | |||
1567 | ||||
1568 | rWrtSh.StartUndo(SwUndoId::UI_REPLACE, &aRewriter); | |||
1569 | rWrtSh.StartAction(); | |||
1570 | ||||
1571 | rWrtSh.Replace(aTmp, false); | |||
1572 | ||||
1573 | rWrtSh.EndAction(); | |||
1574 | rWrtSh.EndUndo(); | |||
1575 | ||||
1576 | rWrtSh.SetInsMode( bOldIns ); | |||
1577 | } | |||
1578 | break; | |||
1579 | default: | |||
1580 | OSL_ENSURE(false, "wrong dispatcher")do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/textsh1.cxx" ":" "1580" ": "), "%s", "wrong dispatcher"); } } while (false ); | |||
1581 | return; | |||
1582 | } | |||
1583 | } | |||
1584 | ||||
1585 | void SwTextShell::GetState( SfxItemSet &rSet ) | |||
1586 | { | |||
1587 | SwWrtShell &rSh = GetShell(); | |||
1588 | SfxWhichIter aIter( rSet ); | |||
1589 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
1590 | while ( nWhich ) | |||
1591 | { | |||
1592 | switch ( nWhich ) | |||
1593 | { | |||
1594 | case FN_FORMAT_CURRENT_FOOTNOTE_DLG((20000 + 400) + 64): | |||
1595 | if( !rSh.IsCursorInFootnote() ) | |||
1596 | rSet.DisableItem( nWhich ); | |||
1597 | break; | |||
1598 | ||||
1599 | case SID_LANGUAGE_STATUS( 10000 + 1067 ): | |||
1600 | { | |||
1601 | // the value of used script types | |||
1602 | OUString aScriptTypesInUse( OUString::number( static_cast<int>(rSh.GetScriptType()) ) ); | |||
1603 | ||||
1604 | // get keyboard language | |||
1605 | OUString aKeyboardLang; | |||
1606 | SwEditWin& rEditWin = GetView().GetEditWin(); | |||
1607 | LanguageType nLang = rEditWin.GetInputLanguage(); | |||
1608 | if (nLang != LANGUAGE_DONTKNOWLanguageType(0x03FF) && nLang != LANGUAGE_SYSTEMLanguageType(0x0000)) | |||
1609 | aKeyboardLang = SvtLanguageTable::GetLanguageString( nLang ); | |||
1610 | ||||
1611 | // get the language that is in use | |||
1612 | OUString aCurrentLang = "*"; | |||
1613 | nLang = SwLangHelper::GetCurrentLanguage( rSh ); | |||
1614 | if (nLang != LANGUAGE_DONTKNOWLanguageType(0x03FF)) | |||
1615 | { | |||
1616 | aCurrentLang = SvtLanguageTable::GetLanguageString( nLang ); | |||
1617 | if (comphelper::LibreOfficeKit::isActive()) | |||
1618 | { | |||
1619 | if (nLang == LANGUAGE_NONELanguageType(0x00FF)) | |||
1620 | { | |||
1621 | aCurrentLang += ";-"; | |||
1622 | } | |||
1623 | else | |||
1624 | { | |||
1625 | aCurrentLang += ";" + LanguageTag(nLang).getBcp47(false); | |||
1626 | } | |||
1627 | } | |||
1628 | } | |||
1629 | ||||
1630 | // build sequence for status value | |||
1631 | uno::Sequence< OUString > aSeq( 4 ); | |||
1632 | aSeq[0] = aCurrentLang; | |||
1633 | aSeq[1] = aScriptTypesInUse; | |||
1634 | aSeq[2] = aKeyboardLang; | |||
1635 | aSeq[3] = SwLangHelper::GetTextForLanguageGuessing( rSh ); | |||
1636 | ||||
1637 | // set sequence as status value | |||
1638 | SfxStringListItem aItem( SID_LANGUAGE_STATUS( 10000 + 1067 ) ); | |||
1639 | aItem.SetStringList( aSeq ); | |||
1640 | rSet.Put( aItem ); | |||
1641 | } | |||
1642 | break; | |||
1643 | ||||
1644 | case SID_THES(5000 + 698): | |||
1645 | { | |||
1646 | // is there a valid selection to get text from? | |||
1647 | OUString aText; | |||
1648 | bool bValid = !rSh.HasSelection() || | |||
1649 | (rSh.IsSelOnePara() && !rSh.IsMultiSelection()); | |||
1650 | // prevent context menu from showing when cursor is not in or at the end of a word | |||
1651 | // (GetCurWord will return the next word if there is none at the current position...) | |||
1652 | const sal_Int16 nWordType = ::i18n::WordType::DICTIONARY_WORD; | |||
1653 | bool bWord = rSh.IsInWord( nWordType ) || rSh.IsStartWord( nWordType ) || rSh.IsEndWord( nWordType ); | |||
1654 | if (bValid && bWord) | |||
1655 | aText = rSh.HasSelection()? rSh.GetSelText() : rSh.GetCurWord(); | |||
1656 | ||||
1657 | LanguageType nLang = rSh.GetCurLang(); | |||
1658 | LanguageTag aLanguageTag( nLang); | |||
1659 | const lang::Locale& aLocale( aLanguageTag.getLocale()); | |||
1660 | ||||
1661 | // disable "Thesaurus" context menu entry if there is nothing to look up | |||
1662 | uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() ); | |||
1663 | if (aText.isEmpty() || | |||
1664 | !xThes.is() || nLang == LANGUAGE_NONELanguageType(0x00FF) || !xThes->hasLocale( aLocale )) | |||
1665 | rSet.DisableItem( SID_THES(5000 + 698) ); | |||
1666 | else | |||
1667 | { | |||
1668 | // set word and locale to look up as status value | |||
1669 | OUString aStatusVal = aText + "#" + aLanguageTag.getBcp47(); | |||
1670 | rSet.Put( SfxStringItem( SID_THES(5000 + 698), aStatusVal ) ); | |||
1671 | } | |||
1672 | } | |||
1673 | break; | |||
1674 | ||||
1675 | case FN_NUMBER_NEWSTART((20000 + 1600) + 138) : | |||
1676 | if(!rSh.GetNumRuleAtCurrCursorPos()) | |||
1677 | rSet.DisableItem(nWhich); | |||
1678 | else | |||
1679 | rSet.Put(SfxBoolItem(FN_NUMBER_NEWSTART((20000 + 1600) + 138), | |||
1680 | rSh.IsNumRuleStart())); | |||
1681 | break; | |||
1682 | ||||
1683 | case FN_EDIT_FORMULA((20000 + 100) + 28): | |||
1684 | case SID_CHARMAP((10000 + 500) + 3): | |||
1685 | case SID_EMOJI_CONTROL(5000 + 405): | |||
1686 | case SID_CHARMAP_CONTROL(5000 + 406): | |||
1687 | { | |||
1688 | const SelectionType nType = rSh.GetSelectionType(); | |||
1689 | if (!(nType & SelectionType::Text) && | |||
1690 | !(nType & SelectionType::Table) && | |||
1691 | !(nType & SelectionType::NumberList)) | |||
1692 | { | |||
1693 | rSet.DisableItem(nWhich); | |||
1694 | } | |||
1695 | else if ( nWhich == FN_EDIT_FORMULA((20000 + 100) + 28) | |||
1696 | && rSh.CursorInsideInputField() ) | |||
1697 | { | |||
1698 | rSet.DisableItem( nWhich ); | |||
1699 | } | |||
1700 | } | |||
1701 | break; | |||
1702 | ||||
1703 | case FN_INSERT_ENDNOTE((20000 + 1400) + 18): | |||
1704 | case FN_INSERT_FOOTNOTE((20000 + 300) + 99): | |||
1705 | case FN_INSERT_FOOTNOTE_DLG((20000 + 300) + 12): | |||
1706 | { | |||
1707 | const FrameTypeFlags nNoType = | |||
1708 | FrameTypeFlags::FLY_ANY | FrameTypeFlags::HEADER | FrameTypeFlags::FOOTER | FrameTypeFlags::FOOTNOTE; | |||
1709 | if ( rSh.GetFrameType(nullptr,true) & nNoType ) | |||
1710 | rSet.DisableItem(nWhich); | |||
1711 | ||||
1712 | if ( rSh.CursorInsideInputField() ) | |||
1713 | { | |||
1714 | rSet.DisableItem( nWhich ); | |||
1715 | } | |||
1716 | } | |||
1717 | break; | |||
1718 | ||||
1719 | case FN_INSERT_HYPERLINK((20000 + 300) + 14): | |||
1720 | case SID_INSERTDOC(5000 + 532): | |||
1721 | case FN_INSERT_GLOSSARY((20000 + 2200) + 89): | |||
1722 | case FN_EXPAND_GLOSSARY((20000 + 600) + 28): | |||
1723 | if ( rSh.CursorInsideInputField() ) | |||
1724 | { | |||
1725 | rSet.DisableItem( nWhich ); | |||
1726 | } | |||
1727 | break; | |||
1728 | ||||
1729 | case FN_INSERT_TABLE((20000 + 300) + 30): | |||
1730 | if ( rSh.CursorInsideInputField() | |||
1731 | || rSh.GetTableFormat() | |||
1732 | || (rSh.GetFrameType(nullptr,true) & FrameTypeFlags::FOOTNOTE) ) | |||
1733 | { | |||
1734 | rSet.DisableItem( nWhich ); | |||
1735 | } | |||
1736 | break; | |||
1737 | ||||
1738 | case FN_CALCULATE((20000 + 600) + 15): | |||
1739 | if ( !rSh.IsSelection() ) | |||
1740 | rSet.DisableItem(nWhich); | |||
1741 | break; | |||
1742 | case FN_GOTO_REFERENCE((20000 + 100) + 66): | |||
1743 | { | |||
1744 | SwField *pField = rSh.GetCurField(); | |||
1745 | if ( !pField || (pField->GetTypeId() != SwFieldTypesEnum::GetRef) ) | |||
1746 | rSet.DisableItem(nWhich); | |||
1747 | } | |||
1748 | break; | |||
1749 | case FN_AUTOFORMAT_AUTO((20000 + 400) + 2 ): | |||
1750 | { | |||
1751 | rSet.Put( SfxBoolItem( nWhich, SvxAutoCorrCfg::Get().IsAutoFormatByInput() )); | |||
1752 | } | |||
1753 | break; | |||
1754 | ||||
1755 | case SID_DEC_INDENT( 10000 + 461 ): | |||
1756 | case SID_INC_INDENT( 10000 + 462 ): | |||
1757 | { | |||
1758 | //if the paragraph has bullet we'll do the following things: | |||
1759 | //1: if the bullet level is the first level, disable the decrease-indent button | |||
1760 | //2: if the bullet level is the last level, disable the increase-indent button | |||
1761 | if ( rSh.GetNumRuleAtCurrCursorPos() && !rSh.HasReadonlySel() ) | |||
1762 | { | |||
1763 | const sal_uInt8 nLevel = rSh.GetNumLevel(); | |||
1764 | if ( ( nLevel == ( MAXLEVEL - 1 ) && nWhich == SID_INC_INDENT( 10000 + 462 ) ) | |||
1765 | || ( nLevel == 0 && nWhich == SID_DEC_INDENT( 10000 + 461 ) ) ) | |||
1766 | { | |||
1767 | rSet.DisableItem( nWhich ); | |||
1768 | } | |||
1769 | } | |||
1770 | else | |||
1771 | { | |||
1772 | sal_uInt16 nHtmlMode = ::GetHtmlMode( GetView().GetDocShell() ); | |||
1773 | nHtmlMode &= HTMLMODE_ON | HTMLMODE_SOME_STYLES; | |||
1774 | if ( ( nHtmlMode == HTMLMODE_ON ) | |||
1775 | || !rSh.IsMoveLeftMargin( SID_INC_INDENT( 10000 + 462 ) == nWhich ) ) | |||
1776 | { | |||
1777 | rSet.DisableItem( nWhich ); | |||
1778 | } | |||
1779 | } | |||
1780 | } | |||
1781 | break; | |||
1782 | ||||
1783 | case FN_DEC_INDENT_OFFSET((20000 + 1600) + 151): | |||
1784 | case FN_INC_INDENT_OFFSET((20000 + 1600) + 150): | |||
1785 | { | |||
1786 | sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell()); | |||
1787 | nHtmlMode &= HTMLMODE_ON|HTMLMODE_SOME_STYLES; | |||
1788 | if( (nHtmlMode == HTMLMODE_ON) || | |||
1789 | !rSh.IsMoveLeftMargin( FN_INC_INDENT_OFFSET((20000 + 1600) + 150) == nWhich, | |||
1790 | false )) | |||
1791 | rSet.DisableItem( nWhich ); | |||
1792 | } | |||
1793 | break; | |||
1794 | ||||
1795 | case SID_ATTR_CHAR_COLOR2(10000 + 537): | |||
1796 | { | |||
1797 | SfxItemSet aSet( GetPool() ); | |||
1798 | rSh.GetCurAttr( aSet ); | |||
1799 | const SvxColorItem& aColorItem = aSet.Get(RES_CHRATR_COLOR); | |||
1800 | rSet.Put( aColorItem.CloneSetWhich(SID_ATTR_CHAR_COLOR2(10000 + 537)) ); | |||
1801 | } | |||
1802 | break; | |||
1803 | case SID_ATTR_CHAR_COLOR_BACKGROUND(10000 + 489): | |||
1804 | { | |||
1805 | // Always use the visible background | |||
1806 | SfxItemSet aSet( GetPool() ); | |||
1807 | rSh.GetCurAttr( aSet ); | |||
1808 | const SvxBrushItem& aBrushItem = aSet.Get(RES_CHRATR_HIGHLIGHT); | |||
1809 | if( aBrushItem.GetColor() != COL_TRANSPARENT ) | |||
1810 | { | |||
1811 | rSet.Put( SvxColorItem(aBrushItem.GetColor(), nWhich) ); | |||
1812 | } | |||
1813 | else | |||
1814 | { | |||
1815 | const SvxBrushItem& aBrushItem2 = aSet.Get(RES_CHRATR_BACKGROUND); | |||
1816 | rSet.Put( SvxColorItem(aBrushItem2.GetColor(), nWhich) ); | |||
1817 | } | |||
1818 | } | |||
1819 | break; | |||
1820 | case SID_ATTR_CHAR_COLOR_BACKGROUND_EXT(10000 + 490): | |||
1821 | case SID_ATTR_CHAR_COLOR_EXT(10000 + 488): | |||
1822 | { | |||
1823 | SwEditWin& rEdtWin = GetView().GetEditWin(); | |||
1824 | SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate(); | |||
1825 | rSet.Put(SfxBoolItem(nWhich, pApply && pApply->nColor == nWhich)); | |||
1826 | } | |||
1827 | break; | |||
1828 | case FN_SET_REMINDER((20000 + 300) + 100): | |||
1829 | case FN_INSERT_BOOKMARK((20000 + 300) + 2 ): | |||
1830 | if( rSh.IsTableMode() | |||
1831 | || rSh.CursorInsideInputField() ) | |||
1832 | { | |||
1833 | rSet.DisableItem( nWhich ); | |||
1834 | } | |||
1835 | break; | |||
1836 | ||||
1837 | case FN_INSERT_BREAK((20000 + 300) + 3): | |||
1838 | if ( rSh.HasReadonlySel() | |||
1839 | && !rSh.CursorInsideInputField() ) | |||
1840 | { | |||
1841 | rSet.DisableItem( nWhich ); | |||
1842 | } | |||
1843 | break; | |||
1844 | ||||
1845 | case FN_INSERT_BREAK_DLG((20000 + 300) + 4 ): | |||
1846 | case FN_INSERT_COLUMN_BREAK((20000 + 300) + 5 ): | |||
1847 | case FN_INSERT_PAGEBREAK((20000 + 300) + 23): | |||
1848 | if( rSh.CursorInsideInputField() ) | |||
1849 | { | |||
1850 | rSet.DisableItem( nWhich ); | |||
1851 | } | |||
1852 | break; | |||
1853 | ||||
1854 | case FN_INSERT_PAGEHEADER((20000 + 1400) + 13): | |||
1855 | case FN_INSERT_PAGEFOOTER((20000 + 1400) + 14): | |||
1856 | if (comphelper::LibreOfficeKit::isActive()) | |||
1857 | { | |||
1858 | bool bState = false; | |||
1859 | bool bAllState = true; | |||
1860 | bool bIsPhysical = false; | |||
1861 | ||||
1862 | OUString aStyleName; | |||
1863 | std::vector<OUString> aList; | |||
1864 | const OUString sPhysical("IsPhysical"); | |||
1865 | const OUString sDisplay("DisplayName"); | |||
1866 | const OUString sHeaderOn(nWhich == FN_INSERT_PAGEHEADER((20000 + 1400) + 13) ? OUString("HeaderIsOn") : OUString("FooterIsOn")); | |||
1867 | ||||
1868 | uno::Reference< XStyleFamiliesSupplier > xSupplier(GetView().GetDocShell()->GetBaseModel(), uno::UNO_QUERY); | |||
1869 | if (xSupplier.is()) | |||
1870 | { | |||
1871 | uno::Reference< XNameContainer > xContainer; | |||
1872 | uno::Reference< XNameAccess > xFamilies = xSupplier->getStyleFamilies(); | |||
1873 | if (xFamilies->getByName("PageStyles") >>= xContainer) | |||
1874 | { | |||
1875 | const uno::Sequence< OUString > aSeqNames = xContainer->getElementNames(); | |||
1876 | for (const auto& rName : aSeqNames) | |||
1877 | { | |||
1878 | aStyleName = rName; | |||
1879 | uno::Reference<XPropertySet> xPropSet(xContainer->getByName(aStyleName), uno::UNO_QUERY); | |||
1880 | if (xPropSet.is() && (xPropSet->getPropertyValue(sPhysical) >>= bIsPhysical) && bIsPhysical) | |||
1881 | { | |||
1882 | xPropSet->getPropertyValue(sDisplay) >>= aStyleName; | |||
1883 | if ((xPropSet->getPropertyValue(sHeaderOn)>>= bState) && bState) | |||
1884 | aList.push_back(aStyleName); | |||
1885 | else | |||
1886 | bState = false; | |||
1887 | ||||
1888 | // Check if all entries have the same state | |||
1889 | bAllState &= bState; | |||
1890 | } | |||
1891 | else | |||
1892 | bIsPhysical = false; | |||
1893 | } | |||
1894 | } | |||
1895 | } | |||
1896 | ||||
1897 | if (bAllState && aList.size() > 1) | |||
1898 | aList.push_back("_ALL_"); | |||
1899 | ||||
1900 | rSet.Put(SfxStringListItem(nWhich, &aList)); | |||
1901 | } | |||
1902 | else | |||
1903 | { | |||
1904 | rSet.Put( SfxObjectShellItem( nWhich, GetView().GetDocShell() )); | |||
1905 | } | |||
1906 | break; | |||
1907 | case FN_TABLE_SORT_DIALOG((20000 + 400) + 133): | |||
1908 | case FN_SORTING_DLG((20000 + 600) + 14): | |||
1909 | if(!rSh.HasSelection() || | |||
1910 | (FN_TABLE_SORT_DIALOG((20000 + 400) + 133) == nWhich && !rSh.GetTableFormat())) | |||
1911 | rSet.DisableItem( nWhich ); | |||
1912 | break; | |||
1913 | ||||
1914 | case SID_RUBY_DIALOG(5000 + 1656): | |||
1915 | { | |||
1916 | SvtCJKOptions aCJKOptions; | |||
1917 | if( !aCJKOptions.IsRubyEnabled() | |||
1918 | || rSh.CursorInsideInputField() ) | |||
1919 | { | |||
1920 | GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, false ); | |||
1921 | rSet.DisableItem(nWhich); | |||
1922 | } | |||
1923 | else | |||
1924 | GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, true ); | |||
1925 | } | |||
1926 | break; | |||
1927 | ||||
1928 | case SID_HYPERLINK_DIALOG(5000 + 678): | |||
1929 | if( GetView().GetDocShell()->IsReadOnly() | |||
1930 | || ( !GetView().GetViewFrame()->HasChildWindow(nWhich) | |||
1931 | && rSh.HasReadonlySel() ) | |||
1932 | || rSh.CursorInsideInputField() ) | |||
1933 | { | |||
1934 | rSet.DisableItem(nWhich); | |||
1935 | } | |||
1936 | else | |||
1937 | { | |||
1938 | rSet.Put(SfxBoolItem( nWhich, nullptr != GetView().GetViewFrame()->GetChildWindow( nWhich ) )); | |||
1939 | } | |||
1940 | break; | |||
1941 | ||||
1942 | case SID_EDIT_HYPERLINK( 10000 + 978 ): | |||
1943 | case SID_COPY_HYPERLINK_LOCATION( 10000 + 1193 ): | |||
1944 | { | |||
1945 | SfxItemSet aSet(GetPool(), | |||
1946 | svl::Items<RES_TXTATR_INETFMT, | |||
1947 | RES_TXTATR_INETFMT>{}); | |||
1948 | rSh.GetCurAttr(aSet); | |||
1949 | if(SfxItemState::SET > aSet.GetItemState( RES_TXTATR_INETFMT ) || rSh.HasReadonlySel()) | |||
1950 | { | |||
1951 | rSet.DisableItem(nWhich); | |||
1952 | } | |||
1953 | } | |||
1954 | break; | |||
1955 | case SID_REMOVE_HYPERLINK( 10000 + 459 ): | |||
1956 | { | |||
1957 | SfxItemSet aSet(GetPool(), | |||
1958 | svl::Items<RES_TXTATR_INETFMT, | |||
1959 | RES_TXTATR_INETFMT>{}); | |||
1960 | rSh.GetCurAttr(aSet); | |||
1961 | ||||
1962 | // If a hyperlink is selected, either alone or along with other text... | |||
1963 | if ((aSet.GetItemState(RES_TXTATR_INETFMT) < SfxItemState::SET && | |||
1964 | aSet.GetItemState(RES_TXTATR_INETFMT) != SfxItemState::DONTCARE) || | |||
1965 | rSh.HasReadonlySel()) | |||
1966 | { | |||
1967 | rSet.DisableItem(nWhich); | |||
1968 | } | |||
1969 | } | |||
1970 | break; | |||
1971 | case SID_TRANSLITERATE_HALFWIDTH( 10000 + 914 ): | |||
1972 | case SID_TRANSLITERATE_FULLWIDTH( 10000 + 915 ): | |||
1973 | case SID_TRANSLITERATE_HIRAGANA( 10000 + 916 ): | |||
1974 | case SID_TRANSLITERATE_KATAKANA( 10000 + 917 ): | |||
1975 | { | |||
1976 | SvtCJKOptions aCJKOptions; | |||
1977 | if(!aCJKOptions.IsChangeCaseMapEnabled()) | |||
1978 | { | |||
1979 | GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, false ); | |||
1980 | rSet.DisableItem(nWhich); | |||
1981 | } | |||
1982 | else | |||
1983 | GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, true ); | |||
1984 | } | |||
1985 | break; | |||
1986 | case FN_READONLY_SELECTION_MODE((20000 + 900) + 89) : | |||
1987 | if(!GetView().GetDocShell()->IsReadOnly()) | |||
1988 | rSet.DisableItem( nWhich ); | |||
1989 | else | |||
1990 | { | |||
1991 | rSet.Put(SfxBoolItem(nWhich, rSh.GetViewOptions()->IsSelectionInReadonly())); | |||
1992 | } | |||
1993 | break; | |||
1994 | case FN_SELECTION_MODE_DEFAULT((20000 + 900) + 90): | |||
1995 | case FN_SELECTION_MODE_BLOCK((20000 + 900) + 91) : | |||
1996 | rSet.Put(SfxBoolItem(nWhich, (nWhich == FN_SELECTION_MODE_DEFAULT((20000 + 900) + 90)) != rSh.IsBlockMode())); | |||
1997 | break; | |||
1998 | case SID_OPEN_HYPERLINK( 10000 + 955 ): | |||
1999 | { | |||
2000 | SfxItemSet aSet(GetPool(), | |||
2001 | svl::Items<RES_TXTATR_INETFMT, | |||
2002 | RES_TXTATR_INETFMT>{}); | |||
2003 | rSh.GetCurAttr(aSet); | |||
2004 | if(SfxItemState::SET > aSet.GetItemState( RES_TXTATR_INETFMT, false )) | |||
2005 | rSet.DisableItem(nWhich); | |||
2006 | } | |||
2007 | break; | |||
2008 | case SID_OPEN_SMARTTAGMENU( 10000 + 1061 ): | |||
2009 | { | |||
2010 | std::vector< OUString > aSmartTagTypes; | |||
2011 | uno::Sequence< uno::Reference< container::XStringKeyMap > > aStringKeyMaps; | |||
2012 | uno::Reference<text::XTextRange> xRange; | |||
2013 | ||||
2014 | rSh.GetSmartTagTerm( aSmartTagTypes, aStringKeyMaps, xRange ); | |||
2015 | ||||
2016 | if ( xRange.is() && !aSmartTagTypes.empty() ) | |||
2017 | { | |||
2018 | uno::Sequence < uno::Sequence< uno::Reference< smarttags::XSmartTagAction > > > aActionComponentsSequence; | |||
2019 | uno::Sequence < uno::Sequence< sal_Int32 > > aActionIndicesSequence; | |||
2020 | ||||
2021 | const SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get(); | |||
2022 | rSmartTagMgr.GetActionSequences( aSmartTagTypes, | |||
2023 | aActionComponentsSequence, | |||
2024 | aActionIndicesSequence ); | |||
2025 | ||||
2026 | uno::Reference <frame::XController> xController = GetView().GetController(); | |||
2027 | const lang::Locale aLocale( SW_BREAKITER()SwBreakIt::Get()->GetLocale( GetAppLanguageTag() ) ); | |||
2028 | const OUString& aApplicationName( rSmartTagMgr.GetApplicationName() ); | |||
2029 | const OUString aRangeText = xRange->getString(); | |||
2030 | ||||
2031 | const SvxSmartTagItem aItem( nWhich, | |||
2032 | aActionComponentsSequence, | |||
2033 | aActionIndicesSequence, | |||
2034 | aStringKeyMaps, | |||
2035 | xRange, | |||
2036 | xController, | |||
2037 | aLocale, | |||
2038 | aApplicationName, | |||
2039 | aRangeText ); | |||
2040 | ||||
2041 | rSet.Put( aItem ); | |||
2042 | } | |||
2043 | else | |||
2044 | rSet.DisableItem(nWhich); | |||
2045 | } | |||
2046 | break; | |||
2047 | ||||
2048 | case FN_NUM_NUMBERING_ON((20000 + 100) + 44): | |||
2049 | rSet.Put(SfxBoolItem(FN_NUM_NUMBERING_ON((20000 + 100) + 44),rSh.SelectionHasNumber())); | |||
2050 | break; | |||
2051 | ||||
2052 | case FN_NUM_BULLET_ON((20000 + 100) + 38): | |||
2053 | rSet.Put(SfxBoolItem(FN_NUM_BULLET_ON((20000 + 100) + 38),rSh.SelectionHasBullet())); | |||
2054 | break; | |||
2055 | ||||
2056 | case FN_BUL_NUM_RULE_INDEX((20000 + 100) + 120): | |||
2057 | case FN_NUM_NUM_RULE_INDEX((20000 + 100) + 121): | |||
2058 | case FN_OUTLINE_RULE_INDEX((20000 + 100) + 122): | |||
2059 | { | |||
2060 | SwNumRule* pCurRule = const_cast<SwNumRule*>(GetShell().GetNumRuleAtCurrCursorPos()); | |||
2061 | if( pCurRule ) | |||
2062 | { | |||
2063 | sal_uInt16 nActNumLvl = GetShell().GetNumLevel(); | |||
2064 | if( nActNumLvl < MAXLEVEL ) | |||
2065 | { | |||
2066 | nActNumLvl = 1<<nActNumLvl; | |||
2067 | } | |||
2068 | SvxNumRule aSvxRule = pCurRule->MakeSvxNumRule(); | |||
2069 | if ( GetShell().HasBullet()) | |||
2070 | { | |||
2071 | rSet.Put(SfxUInt16Item(FN_BUL_NUM_RULE_INDEX((20000 + 100) + 120), USHRT_MAX(32767 *2 +1))); | |||
2072 | rSet.Put(SfxUInt16Item(FN_NUM_NUM_RULE_INDEX((20000 + 100) + 121), USHRT_MAX(32767 *2 +1))); | |||
2073 | NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(NBOType::Bullets); | |||
2074 | if ( pBullets ) | |||
2075 | { | |||
2076 | const sal_uInt16 nBulIndex = pBullets->GetNBOIndexForNumRule(aSvxRule,nActNumLvl); | |||
2077 | rSet.Put(SfxUInt16Item(FN_BUL_NUM_RULE_INDEX((20000 + 100) + 120),nBulIndex)); | |||
2078 | } | |||
2079 | }else if ( GetShell().HasNumber() ) | |||
2080 | { | |||
2081 | rSet.Put(SfxUInt16Item(FN_BUL_NUM_RULE_INDEX((20000 + 100) + 120), USHRT_MAX(32767 *2 +1))); | |||
2082 | rSet.Put(SfxUInt16Item(FN_NUM_NUM_RULE_INDEX((20000 + 100) + 121), USHRT_MAX(32767 *2 +1))); | |||
2083 | NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(NBOType::Numbering); | |||
2084 | if ( pNumbering ) | |||
2085 | { | |||
2086 | const sal_uInt16 nBulIndex = pNumbering->GetNBOIndexForNumRule(aSvxRule,nActNumLvl); | |||
2087 | rSet.Put(SfxUInt16Item(FN_NUM_NUM_RULE_INDEX((20000 + 100) + 121),nBulIndex)); | |||
2088 | } | |||
2089 | } | |||
2090 | ||||
2091 | if ( nWhich == FN_OUTLINE_RULE_INDEX((20000 + 100) + 122) ) | |||
2092 | { | |||
2093 | rSet.Put(SfxUInt16Item(FN_OUTLINE_RULE_INDEX((20000 + 100) + 122), USHRT_MAX(32767 *2 +1))); | |||
2094 | NBOTypeMgrBase* pOutline = NBOutlineTypeMgrFact::CreateInstance(NBOType::Outline); | |||
2095 | if ( pOutline ) | |||
2096 | { | |||
2097 | const sal_uInt16 nIndex = pOutline->GetNBOIndexForNumRule(aSvxRule,nActNumLvl); | |||
2098 | rSet.Put(SfxUInt16Item(FN_OUTLINE_RULE_INDEX((20000 + 100) + 122),nIndex)); | |||
2099 | } | |||
2100 | } | |||
2101 | } | |||
2102 | } | |||
2103 | break; | |||
2104 | case FN_NUM_CONTINUE((20000 + 1800) + 36): | |||
2105 | { | |||
2106 | // #i86492# | |||
2107 | // Search also for bullet list | |||
2108 | OUString aDummy; | |||
2109 | const SwNumRule* pRule = | |||
2110 | rSh.SearchNumRule( true, aDummy ); | |||
2111 | if ( !pRule ) | |||
2112 | { | |||
2113 | pRule = rSh.SearchNumRule( false, aDummy ); | |||
2114 | } | |||
2115 | if ( !pRule ) | |||
2116 | rSet.DisableItem(nWhich); | |||
2117 | } | |||
2118 | break; | |||
2119 | case SID_INSERT_RLM( 10000 + 1056 ) : | |||
2120 | case SID_INSERT_LRM( 10000 + 1057 ) : | |||
2121 | { | |||
2122 | SvtCTLOptions aCTLOptions; | |||
2123 | bool bEnabled = aCTLOptions.IsCTLFontEnabled(); | |||
2124 | GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, bEnabled ); | |||
2125 | if(!bEnabled) | |||
2126 | rSet.DisableItem(nWhich); | |||
2127 | } | |||
2128 | break; | |||
2129 | case SID_FM_CTL_PROPERTIES( 10000 + 613 ): | |||
2130 | { | |||
2131 | bool bDisable = false; | |||
2132 | ||||
2133 | // First get the state from the form shell | |||
2134 | SfxItemSet aSet(GetShell().GetAttrPool(), svl::Items<SID_FM_CTL_PROPERTIES( 10000 + 613 ), SID_FM_CTL_PROPERTIES( 10000 + 613 )>{}); | |||
2135 | aSet.Put(SfxBoolItem( SID_FM_CTL_PROPERTIES( 10000 + 613 ), true )); | |||
2136 | GetShell().GetView().GetFormShell()->GetState( aSet ); | |||
2137 | ||||
2138 | if(SfxItemState::DISABLED == aSet.GetItemState(SID_FM_CTL_PROPERTIES( 10000 + 613 ))) | |||
2139 | { | |||
2140 | bDisable = true; | |||
2141 | } | |||
2142 | ||||
2143 | // Enable it if we have a valid object other than what form shell knows | |||
2144 | SwPosition aPos(*GetShell().GetCursor()->GetPoint()); | |||
2145 | sw::mark::IFieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos); | |||
2146 | if ( !pFieldBM && aPos.nContent.GetIndex() > 0) | |||
2147 | { | |||
2148 | --aPos.nContent; | |||
2149 | pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos); | |||
2150 | } | |||
2151 | if ( pFieldBM && (pFieldBM->GetFieldname() == ODF_FORMDROPDOWN"vnd.oasis.opendocument.field.FORMDROPDOWN" || pFieldBM->GetFieldname() == ODF_FORMDATE"vnd.oasis.opendocument.field.FORMDATE") ) | |||
2152 | { | |||
2153 | bDisable = false; | |||
2154 | } | |||
2155 | ||||
2156 | if(bDisable) | |||
2157 | rSet.DisableItem(nWhich); | |||
2158 | } | |||
2159 | break; | |||
2160 | case SID_COPY(5000 + 711): | |||
2161 | case SID_CUT(5000 + 710): | |||
2162 | { | |||
2163 | if (GetObjectShell()->isContentExtractionLocked()) | |||
2164 | rSet.DisableItem(nWhich); | |||
2165 | break; | |||
2166 | } | |||
2167 | case FN_PROTECT_FIELDS((20000 + 1400) + 26): | |||
2168 | case FN_PROTECT_BOOKMARKS((20000 + 1400) + 27): | |||
2169 | { | |||
2170 | DocumentSettingId aSettingId = nWhich == FN_PROTECT_FIELDS((20000 + 1400) + 26) | |||
2171 | ? DocumentSettingId::PROTECT_FIELDS | |||
2172 | : DocumentSettingId::PROTECT_BOOKMARKS; | |||
2173 | bool bProtected = rSh.getIDocumentSettingAccess().get(aSettingId); | |||
2174 | rSet.Put(SfxBoolItem(nWhich, bProtected)); | |||
2175 | } | |||
2176 | break; | |||
2177 | } | |||
2178 | nWhich = aIter.NextWhich(); | |||
2179 | } | |||
2180 | } | |||
2181 | ||||
2182 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody
| ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody) | ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |