Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/shells/textsh1.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sal/config.h>
21
22
#include <config_features.h>
23
24
#include <com/sun/star/i18n/WordType.hpp>
25
#include <com/sun/star/frame/XStorable.hpp>
26
#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
27
#include <com/sun/star/linguistic2/XThesaurus.hpp>
28
#include <com/sun/star/text/XContentControlsSupplier.hpp>
29
30
#include <hintids.hxx>
31
#include <cmdid.h>
32
#include <comphelper/lok.hxx>
33
#include <comphelper/propertysequence.hxx>
34
35
#include <i18nutil/unicode.hxx>
36
#include <i18nlangtag/languagetag.hxx>
37
#include <svtools/langtab.hxx>
38
#include <svl/numformat.hxx>
39
#include <svl/slstitm.hxx>
40
#include <svl/stritem.hxx>
41
#include <sfx2/htmlmode.hxx>
42
#include <svl/whiter.hxx>
43
#include <sfx2/bindings.hxx>
44
#include <sfx2/namedcolor.hxx>
45
#include <sfx2/viewfrm.hxx>
46
#include <vcl/unohelp2.hxx>
47
#include <vcl/weld.hxx>
48
#include <sfx2/lokhelper.hxx>
49
#include <sfx2/request.hxx>
50
#include <svl/eitem.hxx>
51
#include <editeng/lrspitem.hxx>
52
#include <editeng/colritem.hxx>
53
#include <editeng/tstpitem.hxx>
54
#include <editeng/brushitem.hxx>
55
#include <editeng/svxacorr.hxx>
56
#include <svl/cjkoptions.hxx>
57
#include <svl/ctloptions.hxx>
58
#include <IDocumentDrawModelAccess.hxx>
59
#include <IDocumentSettingAccess.hxx>
60
#include <charfmt.hxx>
61
#include <svx/SmartTagItem.hxx>
62
#include <svx/xflgrit.hxx>
63
#include <svx/xflhtit.hxx>
64
#include <svx/xfillit0.hxx>
65
#include <fmtinfmt.hxx>
66
#include <wrtsh.hxx>
67
#include <wview.hxx>
68
#include <swmodule.hxx>
69
#include <viewopt.hxx>
70
#include <uitool.hxx>
71
#include <textsh.hxx>
72
#include <IMark.hxx>
73
#include <swdtflvr.hxx>
74
#include <swundo.hxx>
75
#include <reffld.hxx>
76
#include <textcontentcontrol.hxx>
77
#include <txatbase.hxx>
78
#include <docsh.hxx>
79
#include <inputwin.hxx>
80
#include <chrdlgmodes.hxx>
81
#include <fmtcol.hxx>
82
#include <cellatr.hxx>
83
#include <edtwin.hxx>
84
#include <fldmgr.hxx>
85
#include <ndtxt.hxx>
86
#include <strings.hrc>
87
#include <paratr.hxx>
88
#include <vcl/svapp.hxx>
89
#include <sfx2/app.hxx>
90
#include <breakit.hxx>
91
#include <SwSmartTagMgr.hxx>
92
#include <editeng/acorrcfg.hxx>
93
#include <swabstdlg.hxx>
94
#include <sfx2/sfxdlg.hxx>
95
#include <com/sun/star/container/XNameContainer.hpp>
96
#include <com/sun/star/beans/XPropertySet.hpp>
97
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
98
#include <com/sun/star/uno/Any.hxx>
99
#include <com/sun/star/linguistic2/ProofreadingResult.hpp>
100
#include <com/sun/star/linguistic2/XDictionary.hpp>
101
#include <com/sun/star/linguistic2/XSpellAlternatives.hpp>
102
#include <editeng/unolingu.hxx>
103
#include <doc.hxx>
104
#include <drawdoc.hxx>
105
#include <view.hxx>
106
#include <pam.hxx>
107
#include <sfx2/objface.hxx>
108
#include <langhelper.hxx>
109
#include <uiitems.hxx>
110
#include <svx/nbdtmgfact.hxx>
111
#include <svx/nbdtmg.hxx>
112
#include <SwRewriter.hxx>
113
#include <svx/drawitem.hxx>
114
#include <numrule.hxx>
115
#include <memory>
116
#include <xmloff/odffields.hxx>
117
#include <bookmark.hxx>
118
#include <linguistic/misc.hxx>
119
#include <comphelper/sequenceashashmap.hxx>
120
#include <comphelper/scopeguard.hxx>
121
#include <authfld.hxx>
122
#include <config_wasm_strip.h>
123
#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
124
#include <officecfg/Office/Common.hxx>
125
#include <officecfg/Office/Linguistic.hxx>
126
#include <svl/visitem.hxx>
127
#include <translatelangselect.hxx>
128
#endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA
129
#include <translatehelper.hxx>
130
#include <IDocumentContentOperations.hxx>
131
#include <IDocumentUndoRedo.hxx>
132
#include <fmtcntnt.hxx>
133
#include <fmtrfmrk.hxx>
134
#include <cntfrm.hxx>
135
#include <flyfrm.hxx>
136
#include <unoprnms.hxx>
137
#include <boost/property_tree/json_parser.hpp>
138
#include <formatcontentcontrol.hxx>
139
#include <rtl/uri.hxx>
140
#include <unotxdoc.hxx>
141
#include <expfld.hxx>
142
#include <sax/tools/converter.hxx>
143
144
#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
145
#include <com/sun/star/chart2/XInternalDataProvider.hpp>
146
#include <com/sun/star/chart2/XChartDocument.hpp>
147
#include <com/sun/star/chart/XChartDocument.hpp>
148
#include <com/sun/star/chart/XChartDataArray.hpp>
149
#include <com/sun/star/chart2/XTitle.hpp>
150
#include <com/sun/star/chart2/XTitled.hpp>
151
#include <com/sun/star/chart/ChartDataRowSource.hpp>
152
#include <com/sun/star/util/XModifiable.hpp>
153
154
#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
155
#include <com/sun/star/chart2/XChartTypeContainer.hpp>
156
#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
157
#include <com/sun/star/util/XCloneable.hpp>
158
159
#include <com/sun/star/util/SearchAlgorithms2.hpp>
160
#include <com/sun/star/document/XDocumentProperties2.hpp>
161
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
162
163
#include <com/sun/star/beans/XPropertyAccess.hpp>
164
#include <com/sun/star/beans/PropertyAttribute.hpp>
165
166
using namespace ::com::sun::star;
167
using namespace com::sun::star::beans;
168
using namespace ::com::sun::star::container;
169
using namespace com::sun::star::style;
170
using namespace svx::sidebar;
171
172
static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> const & pCoreSet, bool bSel,
173
                                bool bSelectionPut, bool bApplyToParagraph, SfxRequest *pReq);
174
175
static void sw_CharDialog(SwWrtShell& rWrtSh, bool bUseDialog, bool bApplyToParagraph,
176
                          sal_uInt16 nSlot, const SfxItemSet* pArgs, SfxRequest* pReq)
177
0
{
178
0
    FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &rWrtSh.GetView()) != nullptr );
179
0
    SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast<sal_uInt16>(eMetric)));
180
0
    auto pCoreSet = std::make_shared<SfxItemSetFixed<
181
0
            RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
182
0
            RES_TXTATR_INETFMT, RES_TXTATR_INETFMT,
183
0
            RES_BACKGROUND, RES_SHADOW,
184
0
            SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
185
0
            SID_HTML_MODE, SID_HTML_MODE,
186
0
            SID_ATTR_CHAR_WIDTH_FIT_TO_LINE, SID_ATTR_CHAR_WIDTH_FIT_TO_LINE,
187
0
            FN_PARAM_SELECTION, FN_PARAM_SELECTION>> ( rWrtSh.GetView().GetPool() );
188
0
    rWrtSh.GetCurAttr(*pCoreSet);
189
190
0
    bool bSel = rWrtSh.HasSelection();
191
0
    bool bSelectionPut = false;
192
0
    if(bSel || rWrtSh.IsInWord())
193
0
    {
194
0
        if(!bSel)
195
0
        {
196
0
            rWrtSh.StartAction();
197
0
            rWrtSh.Push();
198
0
            if(!rWrtSh.SelectTextAttr( RES_TXTATR_INETFMT ))
199
0
                rWrtSh.SelWrd();
200
0
        }
201
0
        pCoreSet->Put(SfxStringItem(FN_PARAM_SELECTION, rWrtSh.GetSelText()));
202
0
        bSelectionPut = true;
203
0
        if(!bSel)
204
0
        {
205
0
            rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
206
0
            rWrtSh.EndAction();
207
0
        }
208
0
    }
209
0
    pCoreSet->Put(SfxUInt16Item(SID_ATTR_CHAR_WIDTH_FIT_TO_LINE, rWrtSh.GetScalingOfSelectedText()));
210
211
0
    ::ConvertAttrCharToGen(*pCoreSet);
212
213
    // Setting the BoxInfo
214
0
    ::PrepareBoxInfo(*pCoreSet, rWrtSh);
215
216
0
    pCoreSet->Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(rWrtSh.GetView().GetDocShell())));
217
0
    VclPtr<SfxAbstractTabDialog> pDlg;
218
0
    if ( bUseDialog && GetActiveView() )
219
0
    {
220
0
        SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
221
0
        pDlg.reset(pFact->CreateSwCharDlg(rWrtSh.GetView().GetFrameWeld(), rWrtSh.GetView(), *pCoreSet, SwCharDlgMode::Std));
222
223
0
        if (nSlot == SID_CHAR_DLG_EFFECT)
224
0
            pDlg->SetCurPageId(u"fonteffects"_ustr);
225
0
        else if (nSlot == SID_CHAR_DLG_POSITION)
226
0
            pDlg->SetCurPageId(u"position"_ustr);
227
0
        else if (nSlot == SID_CHAR_DLG_FOR_PARAGRAPH)
228
0
            pDlg->SetCurPageId(u"font"_ustr);
229
0
        else if (pReq)
230
0
        {
231
0
            const SfxStringItem* pItem = (*pReq).GetArg<SfxStringItem>(FN_PARAM_1);
232
0
            if (pItem)
233
0
                pDlg->SetCurPageId(pItem->GetValue());
234
0
        }
235
0
    }
236
237
0
    if (bUseDialog)
238
0
    {
239
0
        std::shared_ptr<SfxRequest> pRequest;
240
0
        if (pReq)
241
0
        {
242
0
            pRequest = std::make_shared<SfxRequest>(*pReq);
243
0
            pReq->Ignore(); // the 'old' request is not relevant any more
244
0
        }
245
0
        pDlg->StartExecuteAsync([pDlg, &rWrtSh, pCoreSet=std::move(pCoreSet), bSel,
246
0
                                 bSelectionPut, bApplyToParagraph,
247
0
                                 pRequest=std::move(pRequest)](sal_Int32 nResult){
248
0
            if (nResult == RET_OK)
249
0
            {
250
0
                sw_CharDialogResult(pDlg->GetOutputItemSet(), rWrtSh, pCoreSet, bSel, bSelectionPut,
251
0
                                    bApplyToParagraph, pRequest.get());
252
0
            }
253
0
            pDlg->disposeOnce();
254
0
        });
255
0
    }
256
0
    else if (pArgs)
257
0
    {
258
0
        sw_CharDialogResult(pArgs, rWrtSh, pCoreSet, bSel, bSelectionPut, bApplyToParagraph, pReq);
259
0
    }
260
0
}
261
262
static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell& rWrtSh, std::shared_ptr<SfxItemSet> const & pCoreSet, bool bSel,
263
                                bool bSelectionPut, bool bApplyToParagraph, SfxRequest* pReq)
264
0
{
265
0
    SfxItemSet aTmpSet( *pSet );
266
0
    ::ConvertAttrGenToChar(aTmpSet, *pCoreSet);
267
268
0
    const bool bWasLocked = rWrtSh.IsViewLocked();
269
0
    if (bApplyToParagraph)
270
0
    {
271
0
        rWrtSh.StartAction();
272
0
        rWrtSh.LockView(true);
273
0
        rWrtSh.Push();
274
0
        SwLangHelper::SelectCurrentPara(rWrtSh);
275
0
    }
276
277
0
    const SfxStringItem* pSelectionItem;
278
0
    bool bInsert = false;
279
0
    sal_Int32 nInsert = 0;
280
281
    // The old item is for unknown reasons back in the set again.
282
0
    if( !bSelectionPut && (pSelectionItem = aTmpSet.GetItemIfSet(FN_PARAM_SELECTION, false)) )
283
0
    {
284
0
        const OUString& sInsert = pSelectionItem->GetValue();
285
0
        bInsert = !sInsert.isEmpty();
286
0
        if(bInsert)
287
0
        {
288
0
            nInsert = sInsert.getLength();
289
0
            rWrtSh.StartAction();
290
0
            rWrtSh.Insert( sInsert );
291
0
            rWrtSh.SetMark();
292
0
            rWrtSh.ExtendSelection(false, sInsert.getLength());
293
0
            SfxRequest aReq(rWrtSh.GetView().GetViewFrame(), FN_INSERT_STRING);
294
0
            aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, sInsert ) );
295
0
            aReq.Done();
296
0
            SfxRequest aReq1(rWrtSh.GetView().GetViewFrame(), FN_CHAR_LEFT);
297
0
            aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nInsert) );
298
0
            aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, true) );
299
0
            aReq1.Done();
300
0
        }
301
0
    }
302
0
    aTmpSet.ClearItem(FN_PARAM_SELECTION);
303
304
0
    SwTextFormatColl* pColl = rWrtSh.GetCurTextFormatColl();
305
0
    if(bSel && rWrtSh.IsSelFullPara() && pColl && pColl->IsAutoUpdateOnDirectFormat())
306
0
    {
307
0
        rWrtSh.AutoUpdatePara(pColl, aTmpSet);
308
0
    }
309
0
    else
310
0
        rWrtSh.SetAttrSet( aTmpSet );
311
0
    if (pReq)
312
0
        pReq->Done(aTmpSet);
313
0
    if(bInsert)
314
0
    {
315
0
        SfxRequest aReq1(rWrtSh.GetView().GetViewFrame(), FN_CHAR_RIGHT);
316
0
        aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nInsert) );
317
0
        aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, false) );
318
0
        aReq1.Done();
319
0
        rWrtSh.SwapPam();
320
0
        rWrtSh.ClearMark();
321
0
        rWrtSh.DontExpandFormat();
322
0
        rWrtSh.EndAction();
323
0
    }
324
325
0
    if (bApplyToParagraph)
326
0
    {
327
0
        rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
328
0
        rWrtSh.LockView(bWasLocked);
329
0
        rWrtSh.EndAction();
330
0
    }
331
0
}
332
333
334
static void sw_ParagraphDialogResult(SfxItemSet* pSet, SwWrtShell &rWrtSh, SfxRequest& rReq, SwPaM* pPaM)
335
0
{
336
0
    if (!pSet)
337
0
        return;
338
339
0
    rReq.Done( *pSet );
340
0
    ::SfxToSwPageDescAttr( rWrtSh, *pSet );
341
    // #i56253#
342
    // enclose all undos.
343
    // Thus, check conditions, if actions will be performed.
344
0
    const bool bUndoNeeded( pSet->Count() ||
345
0
            SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART) ||
346
0
            SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART_AT) );
347
0
    if ( bUndoNeeded )
348
0
    {
349
0
        rWrtSh.StartUndo( SwUndoId::INSATTR );
350
0
    }
351
0
    if( pSet->Count() )
352
0
    {
353
0
        rWrtSh.StartAction();
354
0
        if ( const SfxStringItem* pDropTextItem = pSet->GetItemIfSet(FN_DROP_TEXT, false) )
355
0
        {
356
0
            if ( !pDropTextItem->GetValue().isEmpty() )
357
0
                rWrtSh.ReplaceDropText(pDropTextItem->GetValue(), pPaM);
358
0
        }
359
0
        rWrtSh.SetAttrSet(*pSet, SetAttrMode::DEFAULT, pPaM);
360
0
        rWrtSh.EndAction();
361
0
        SwTextFormatColl* pColl = rWrtSh.GetPaMTextFormatColl(pPaM);
362
0
        if(pColl && pColl->IsAutoUpdateOnDirectFormat())
363
0
        {
364
0
            rWrtSh.AutoUpdatePara(pColl, *pSet, pPaM);
365
0
        }
366
0
    }
367
368
0
    if( SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART) )
369
0
    {
370
        //SetNumRuleStart(true) restarts the numbering at the value
371
        //that is defined at the starting point of the numbering level
372
        //otherwise the SetNodeNumStart() value determines the start
373
        //if it's set to something different than USHRT_MAX
374
375
0
        bool bStart = static_cast<const SfxBoolItem&>(pSet->Get(FN_NUMBER_NEWSTART)).GetValue();
376
377
        // Default value for restart value has to be USHRT_MAX
378
        // in order to indicate that the restart value of the list
379
        // style has to be used on restart.
380
0
        sal_uInt16 nNumStart = USHRT_MAX;
381
0
        if( SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART_AT) )
382
0
        {
383
0
            nNumStart = pSet->Get(FN_NUMBER_NEWSTART_AT).GetValue();
384
0
        }
385
0
        rWrtSh.SetNumRuleStart(bStart, pPaM);
386
0
        rWrtSh.SetNodeNumStart(nNumStart);
387
0
    }
388
0
    else if( SfxItemState::SET == pSet->GetItemState(FN_NUMBER_NEWSTART_AT) )
389
0
    {
390
0
        rWrtSh.SetNodeNumStart(pSet->Get(FN_NUMBER_NEWSTART_AT).GetValue());
391
0
        rWrtSh.SetNumRuleStart(false, pPaM);
392
0
    }
393
    // #i56253#
394
0
    if ( bUndoNeeded )
395
0
    {
396
0
        rWrtSh.EndUndo( SwUndoId::INSATTR );
397
0
    }
398
0
}
399
400
namespace {
401
402
void InsertBreak(SwWrtShell& rWrtSh,
403
                 sal_uInt16 nKind,
404
                 ::std::optional<sal_uInt16> oPageNumber,
405
                 const UIName& rTemplateName, std::optional<SwLineBreakClear> oClear)
406
0
{
407
0
    switch ( nKind )
408
0
    {
409
0
        case 1 :
410
0
            rWrtSh.InsertLineBreak(oClear);
411
0
            break;
412
0
        case 2 :
413
0
            rWrtSh.InsertColumnBreak(); break;
414
0
        case 3 :
415
0
        {
416
0
            rWrtSh.StartAllAction();
417
0
            if( !rTemplateName.isEmpty() )
418
0
                rWrtSh.InsertPageBreak( &rTemplateName, oPageNumber );
419
0
            else
420
0
                rWrtSh.InsertPageBreak();
421
0
            rWrtSh.EndAllAction();
422
0
        }
423
0
    }
424
0
}
425
426
OUString GetLocalURL(const SwWrtShell& rSh)
427
0
{
428
0
    SwField* pField = rSh.GetCurField();
429
0
    if (!pField)
430
0
    {
431
0
        return OUString();
432
0
    }
433
434
0
    if (pField->GetTyp()->Which() != SwFieldIds::TableOfAuthorities)
435
0
    {
436
0
        return OUString();
437
0
    }
438
439
0
    const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
440
0
    SwAuthEntry* pAuthEntry = rAuthorityField.GetAuthEntry();
441
0
    if (!pAuthEntry)
442
0
    {
443
0
        return OUString();
444
0
    }
445
446
0
    const OUString& rLocalURL = pAuthEntry->GetAuthorField(AUTH_FIELD_LOCAL_URL);
447
0
    return rLocalURL;
448
0
}
449
450
void UpdateSections(const SfxRequest& rReq, SwWrtShell& rWrtSh)
451
0
{
452
0
    OUString aSectionNamePrefix;
453
0
    const SfxStringItem* pSectionNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
454
0
    if (pSectionNamePrefix)
455
0
    {
456
0
        aSectionNamePrefix = pSectionNamePrefix->GetValue();
457
0
    }
458
459
0
    uno::Sequence<beans::PropertyValues> aSections;
460
0
    const SfxUnoAnyItem* pSections = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_2);
461
0
    if (pSections)
462
0
    {
463
0
        pSections->GetValue() >>= aSections;
464
0
    }
465
466
0
    rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_SECTIONS, nullptr);
467
0
    rWrtSh.StartAction();
468
469
0
    SwDoc* pDoc = rWrtSh.GetDoc();
470
0
    sal_Int32 nSectionIndex = 0;
471
0
    const SwSectionFormats& rFormats = pDoc->GetSections();
472
0
    IDocumentContentOperations& rIDCO = pDoc->getIDocumentContentOperations();
473
0
    for (size_t i = 0; i < rFormats.size(); ++i)
474
0
    {
475
0
        const SwSectionFormat* pFormat = rFormats[i];
476
0
        if (!pFormat->GetName().toString().startsWith(aSectionNamePrefix))
477
0
        {
478
0
            continue;
479
0
        }
480
481
0
        if (nSectionIndex >= aSections.getLength())
482
0
        {
483
0
            break;
484
0
        }
485
486
0
        comphelper::SequenceAsHashMap aMap(aSections[nSectionIndex++]);
487
0
        UIName aSectionName( aMap[u"RegionName"_ustr].get<OUString>() );
488
0
        if (aSectionName != pFormat->GetName())
489
0
        {
490
0
            const_cast<SwSectionFormat*>(pFormat)->SetFormatName(aSectionName, /*bBroadcast=*/true);
491
0
            SwSectionData aSectionData(*pFormat->GetSection());
492
0
            aSectionData.SetSectionName(aSectionName);
493
0
            pDoc->UpdateSection(i, aSectionData);
494
0
        }
495
496
0
        const SwFormatContent& rContent = pFormat->GetContent();
497
0
        const SwNodeIndex* pContentNodeIndex = rContent.GetContentIdx();
498
0
        if (pContentNodeIndex)
499
0
        {
500
0
            SwPaM aSectionStart(SwPosition{*pContentNodeIndex});
501
0
            aSectionStart.Move(fnMoveForward, GoInContent);
502
0
            SwPaM* pCursorPos = rWrtSh.GetCursor();
503
0
            *pCursorPos = aSectionStart;
504
0
            rWrtSh.EndOfSection(/*bSelect=*/true);
505
0
            rIDCO.DeleteAndJoin(*pCursorPos);
506
0
            rWrtSh.EndSelect();
507
508
0
            OUString aSectionText = aMap[u"Content"_ustr].get<OUString>();
509
0
            SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aSectionText.toUtf8());
510
0
        }
511
0
    }
512
513
0
    rWrtSh.EndAction();
514
0
    rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_SECTIONS, nullptr);
515
0
}
516
517
void DeleteSections(const SfxRequest& rReq, SwWrtShell& rWrtSh)
518
0
{
519
0
    OUString aSectionNamePrefix;
520
0
    const SfxStringItem* pSectionNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
521
0
    if (pSectionNamePrefix)
522
0
    {
523
0
        aSectionNamePrefix = pSectionNamePrefix->GetValue();
524
0
    }
525
526
0
    rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::DELETE_SECTIONS, nullptr);
527
0
    rWrtSh.StartAction();
528
0
    comphelper::ScopeGuard g(
529
0
        [&rWrtSh]
530
0
        {
531
0
            rWrtSh.EndAction();
532
0
            rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::DELETE_SECTIONS, nullptr);
533
0
        });
534
535
0
    SwDoc* pDoc = rWrtSh.GetDoc();
536
0
    std::vector<SwSectionFormat*> aRemovals;
537
0
    for (SwSectionFormat* pFormat : pDoc->GetSections())
538
0
        if (aSectionNamePrefix.isEmpty() || pFormat->GetName().toString().startsWith(aSectionNamePrefix))
539
0
            aRemovals.push_back(pFormat);
540
541
0
    for (const auto& pFormat : aRemovals)
542
0
    {
543
        // Just delete the format, not the content of the section.
544
0
        pDoc->DelSectionFormat(pFormat);
545
0
    }
546
0
}
547
548
void DeleteContentControl( const SwWrtShell& rWrtSh )
549
0
{
550
0
    SwTextContentControl* pTextContentControl = rWrtSh.CursorInsideContentControl();
551
0
    if (pTextContentControl) {
552
0
        const SwFormatContentControl& rFormatContentControl = pTextContentControl->GetContentControl();
553
0
        const std::shared_ptr<SwContentControl>& pContentControl = rFormatContentControl.GetContentControl();
554
0
        pContentControl->SetReadWrite(true);
555
0
        pTextContentControl->Delete(true);
556
0
    }
557
0
}
558
559
560
void UpdateBookmarks(const SfxRequest& rReq, SwWrtShell& rWrtSh)
561
0
{
562
0
    if (rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
563
0
    {
564
0
        return;
565
0
    }
566
567
0
    OUString aBookmarkNamePrefix;
568
0
    const SfxStringItem* pBookmarkNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
569
0
    if (pBookmarkNamePrefix)
570
0
    {
571
0
        aBookmarkNamePrefix = pBookmarkNamePrefix->GetValue();
572
0
    }
573
574
0
    uno::Sequence<beans::PropertyValues> aBookmarks;
575
0
    const SfxUnoAnyItem* pBookmarks = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_2);
576
0
    if (pBookmarks)
577
0
    {
578
0
        pBookmarks->GetValue() >>= aBookmarks;
579
0
    }
580
581
0
    rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_BOOKMARKS, nullptr);
582
0
    rWrtSh.StartAction();
583
584
0
    IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess();
585
0
    sal_Int32 nBookmarkIndex = 0;
586
0
    bool bSortMarks = false;
587
0
    for (auto it = rIDMA.getBookmarksBegin(); it != rIDMA.getBookmarksEnd(); ++it)
588
0
    {
589
0
        sw::mark::Bookmark* pMark = *it;
590
0
        assert(pMark);
591
0
        if (!pMark->GetName().toString().startsWith(aBookmarkNamePrefix))
592
0
        {
593
0
            continue;
594
0
        }
595
596
0
        if (aBookmarks.getLength() <= nBookmarkIndex)
597
0
        {
598
0
            continue;
599
0
        }
600
601
0
        comphelper::SequenceAsHashMap aMap(aBookmarks[nBookmarkIndex++]);
602
0
        if (aMap[u"Bookmark"_ustr].get<OUString>() != pMark->GetName())
603
0
        {
604
0
            rIDMA.renameMark(pMark, SwMarkName(aMap[u"Bookmark"_ustr].get<OUString>()));
605
0
        }
606
607
0
        OUString aBookmarkText = aMap[u"BookmarkText"_ustr].get<OUString>();
608
609
        // Insert markers to remember where the paste positions are.
610
0
        SwPaM aMarkers(pMark->GetMarkEnd());
611
0
        IDocumentContentOperations& rIDCO = rWrtSh.GetDoc()->getIDocumentContentOperations();
612
0
        bool bSuccess = rIDCO.InsertString(aMarkers, u"XY"_ustr);
613
0
        if (bSuccess)
614
0
        {
615
0
            SwPaM aPasteEnd(pMark->GetMarkEnd());
616
0
            aPasteEnd.Move(fnMoveForward, GoInContent);
617
618
            // Paste HTML content.
619
0
            SwPaM* pCursorPos = rWrtSh.GetCursor();
620
0
            *pCursorPos = aPasteEnd;
621
0
            SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8());
622
623
            // Update the bookmark to point to the new content.
624
0
            SwPaM aPasteStart(pMark->GetMarkEnd());
625
0
            aPasteStart.Move(fnMoveForward, GoInContent);
626
0
            SwPaM aStartMarker(pMark->GetMarkStart(), *aPasteStart.GetPoint());
627
0
            SwPaM aEndMarker(*aPasteEnd.GetPoint(), *aPasteEnd.GetPoint());
628
0
            aEndMarker.GetMark()->AdjustContent(1);
629
0
            pMark->SetMarkPos(*aPasteStart.GetPoint());
630
0
            pMark->SetOtherMarkPos(*aPasteEnd.GetPoint());
631
0
            bSortMarks = true;
632
633
            // Remove markers. the start marker includes the old content as well.
634
0
            rIDCO.DeleteAndJoin(aStartMarker);
635
0
            rIDCO.DeleteAndJoin(aEndMarker);
636
0
        }
637
0
    }
638
0
    if (bSortMarks)
639
0
    {
640
0
        rIDMA.assureSortedMarkContainers();
641
0
    }
642
643
0
    rWrtSh.EndAction();
644
0
    rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_BOOKMARKS, nullptr);
645
0
}
646
647
void UpdateBookmark(const SfxRequest& rReq, SwWrtShell& rWrtSh)
648
0
{
649
0
    if (rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
650
0
    {
651
0
        return;
652
0
    }
653
654
0
    OUString aBookmarkNamePrefix;
655
0
    const SfxStringItem* pBookmarkNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
656
0
    if (pBookmarkNamePrefix)
657
0
    {
658
0
        aBookmarkNamePrefix = pBookmarkNamePrefix->GetValue();
659
0
    }
660
661
0
    uno::Sequence<beans::PropertyValue> aBookmark;
662
0
    const SfxUnoAnyItem* pBookmarks = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_2);
663
0
    if (pBookmarks)
664
0
    {
665
0
        pBookmarks->GetValue() >>= aBookmark;
666
0
    }
667
668
0
    IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess();
669
0
    SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint();
670
0
    sw::mark::Bookmark* pBookmark = rIDMA.getOneInnermostBookmarkFor(rCursor);
671
0
    if (!pBookmark || !pBookmark->GetName().toString().startsWith(aBookmarkNamePrefix))
672
0
    {
673
0
        return;
674
0
    }
675
676
0
    SwRewriter aRewriter;
677
0
    aRewriter.AddRule(UndoArg1, pBookmark->GetName());
678
0
    rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_BOOKMARK, &aRewriter);
679
0
    rWrtSh.StartAction();
680
0
    comphelper::ScopeGuard g(
681
0
        [&rWrtSh, &aRewriter]
682
0
        {
683
0
            rWrtSh.EndAction();
684
0
            rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_BOOKMARK, &aRewriter);
685
0
        });
686
687
688
0
    comphelper::SequenceAsHashMap aMap(aBookmark);
689
0
    if (aMap[u"Bookmark"_ustr].get<OUString>() != pBookmark->GetName())
690
0
    {
691
0
        rIDMA.renameMark(pBookmark, SwMarkName(aMap[u"Bookmark"_ustr].get<OUString>()));
692
0
    }
693
694
    // Insert markers to remember where the paste positions are.
695
0
    SwPaM aMarkers(pBookmark->GetMarkEnd());
696
0
    IDocumentContentOperations& rIDCO = rWrtSh.GetDoc()->getIDocumentContentOperations();
697
0
    if (!rIDCO.InsertString(aMarkers, u"XY"_ustr))
698
0
    {
699
0
        return;
700
0
    }
701
702
0
    SwPaM aPasteEnd(pBookmark->GetMarkEnd());
703
0
    aPasteEnd.Move(fnMoveForward, GoInContent);
704
705
0
    OUString aBookmarkText = aMap[u"BookmarkText"_ustr].get<OUString>();
706
707
    // Paste HTML content.
708
0
    SwPaM* pCursorPos = rWrtSh.GetCursor();
709
0
    *pCursorPos = aPasteEnd;
710
0
    SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8());
711
712
    // Update the bookmark to point to the new content.
713
0
    SwPaM aPasteStart(pBookmark->GetMarkEnd());
714
0
    aPasteStart.Move(fnMoveForward, GoInContent);
715
0
    SwPaM aStartMarker(pBookmark->GetMarkStart(), *aPasteStart.GetPoint());
716
0
    SwPaM aEndMarker(*aPasteEnd.GetPoint(), *aPasteEnd.GetPoint());
717
0
    aEndMarker.GetMark()->AdjustContent(1);
718
0
    pBookmark->SetMarkPos(*aPasteStart.GetPoint());
719
0
    pBookmark->SetOtherMarkPos(*aPasteEnd.GetPoint());
720
721
    // Remove markers. the start marker includes the old content as well.
722
0
    rIDCO.DeleteAndJoin(aStartMarker);
723
0
    rIDCO.DeleteAndJoin(aEndMarker);
724
0
    rIDMA.assureSortedMarkContainers();
725
0
}
726
727
void DeleteBookmarks(const SfxRequest& rReq, SwWrtShell& rWrtSh)
728
0
{
729
0
    if (rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
730
0
    {
731
0
        return;
732
0
    }
733
734
0
    OUString aBookmarkNamePrefix;
735
0
    const SfxStringItem* pBookmarkNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
736
0
    if (pBookmarkNamePrefix)
737
0
    {
738
0
        aBookmarkNamePrefix = pBookmarkNamePrefix->GetValue();
739
0
    }
740
741
0
    rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::DELETE_BOOKMARKS, nullptr);
742
0
    rWrtSh.StartAction();
743
0
    comphelper::ScopeGuard g(
744
0
        [&rWrtSh]
745
0
        {
746
0
            rWrtSh.EndAction();
747
0
            rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::DELETE_BOOKMARKS, nullptr);
748
0
        });
749
750
0
    IDocumentMarkAccess* pMarkAccess = rWrtSh.GetDoc()->getIDocumentMarkAccess();
751
0
    std::vector<sw::mark::MarkBase*> aRemovals;
752
0
    for (auto it = pMarkAccess->getBookmarksBegin(); it != pMarkAccess->getBookmarksEnd(); ++it)
753
0
    {
754
0
        sw::mark::Bookmark* pBookmark = *it;
755
0
        assert(pBookmark);
756
757
0
        if (!aBookmarkNamePrefix.isEmpty())
758
0
        {
759
0
            if (!pBookmark->GetName().toString().startsWith(aBookmarkNamePrefix))
760
0
            {
761
0
                continue;
762
0
            }
763
0
        }
764
765
0
        aRemovals.push_back(pBookmark);
766
0
    }
767
768
0
    for (const auto& pMark : aRemovals)
769
0
    {
770
0
        pMarkAccess->deleteMark(pMark);
771
0
    }
772
0
}
773
774
void DeleteFields(const SfxRequest& rReq, SwWrtShell& rWrtSh)
775
0
{
776
0
    const SfxStringItem* pTypeName = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
777
0
    if (!pTypeName || pTypeName->GetValue() != "SetRef")
778
0
    {
779
        // This is implemented so far only for reference marks.
780
0
        return;
781
0
    }
782
783
0
    OUString aNamePrefix;
784
0
    const SfxStringItem* pNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
785
0
    if (pNamePrefix)
786
0
    {
787
0
        aNamePrefix = pNamePrefix->GetValue();
788
0
    }
789
790
0
    SwDoc* pDoc = rWrtSh.GetDoc();
791
0
    pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::DELETE_FIELDS, nullptr);
792
0
    rWrtSh.StartAction();
793
0
    comphelper::ScopeGuard g(
794
0
        [&rWrtSh]
795
0
        {
796
0
            rWrtSh.EndAction();
797
0
            rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::DELETE_FIELDS, nullptr);
798
0
        });
799
800
0
    std::vector<const SwFormatRefMark*> aRemovals;
801
0
    for (sal_uInt16 i = 0; i < pDoc->GetRefMarks(); ++i)
802
0
    {
803
0
        const SwFormatRefMark* pRefMark = pDoc->GetRefMark(i);
804
0
        if (!aNamePrefix.isEmpty())
805
0
        {
806
0
            if (!pRefMark->GetRefName().toString().startsWith(aNamePrefix))
807
0
            {
808
0
                continue;
809
0
            }
810
0
        }
811
812
0
        aRemovals.push_back(pRefMark);
813
0
    }
814
815
0
    for (const auto& pMark : aRemovals)
816
0
    {
817
0
        pDoc->DeleteFormatRefMark(pMark);
818
0
    }
819
0
}
820
821
void lcl_LogWarning(std::string sWarning)
822
0
{
823
0
    LOK_WARN("sw.transform",  sWarning);
824
0
}
825
826
bool lcl_ChangeChartColumnCount(const uno::Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nId,
827
                                bool bInsert, bool bResize = false)
828
0
{
829
0
    uno::Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram();
830
0
    if (!xDiagram.is())
831
0
        return false;
832
0
    uno::Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(xDiagram, uno::UNO_QUERY);
833
0
    if (!xCooSysContainer.is())
834
0
        return false;
835
0
    uno::Sequence<uno::Reference<chart2::XCoordinateSystem>> xCooSysSequence(
836
0
        xCooSysContainer->getCoordinateSystems());
837
0
    if (xCooSysSequence.getLength() <= 0)
838
0
        return false;
839
0
    uno::Reference<chart2::XChartTypeContainer> xChartTypeContainer(xCooSysSequence[0],
840
0
                                                                    uno::UNO_QUERY);
841
0
    if (!xChartTypeContainer.is())
842
0
        return false;
843
0
    uno::Sequence<uno::Reference<chart2::XChartType>> xChartTypeSequence(
844
0
        xChartTypeContainer->getChartTypes());
845
0
    if (xChartTypeSequence.getLength() <= 0)
846
0
        return false;
847
0
    uno::Reference<chart2::XDataSeriesContainer> xDSContainer(xChartTypeSequence[0],
848
0
                                                              uno::UNO_QUERY);
849
0
    if (!xDSContainer.is())
850
0
        return false;
851
852
0
    uno::Reference<chart2::XInternalDataProvider> xIDataProvider(xChartDoc->getDataProvider(),
853
0
                                                                 uno::UNO_QUERY);
854
0
    if (!xIDataProvider.is())
855
0
        return false;
856
857
0
    uno::Sequence<uno::Reference<chart2::XDataSeries>> aSeriesSeq(xDSContainer->getDataSeries());
858
859
0
    int nSeriesCount = aSeriesSeq.getLength();
860
861
0
    if (bResize)
862
0
    {
863
        // Resize is actually some inserts, or deletes
864
0
        if (nId > nSeriesCount)
865
0
        {
866
0
            bInsert = true;
867
0
        }
868
0
        else if (nId < nSeriesCount)
869
0
        {
870
0
            bInsert = false;
871
0
        }
872
0
        else
873
0
        {
874
            // Resize to the same size. No change needed
875
0
            return true;
876
0
        }
877
0
    }
878
879
    // insert or delete
880
0
    if (bInsert)
881
0
    {
882
        // insert
883
0
        if (nId > nSeriesCount && !bResize)
884
0
            return false;
885
886
0
        int nInsertCount = bResize ? nId - nSeriesCount : 1;
887
888
        // call dialog code
889
0
        if (bResize)
890
0
        {
891
0
            for (int i = 0; i < nInsertCount; i++)
892
0
            {
893
0
                xIDataProvider->insertDataSeries(nSeriesCount);
894
0
            }
895
0
            return true;
896
0
        }
897
898
0
        xIDataProvider->insertDataSeries(nId);
899
0
    }
900
0
    else
901
0
    {
902
        // delete 1 or more columns
903
0
        if (nId >= nSeriesCount)
904
0
            return false;
905
0
        int nDeleteCount = bResize ? nSeriesCount - nId : 1;
906
0
        for (int i = 0; i < nDeleteCount; i++)
907
0
        {
908
0
            xDSContainer->removeDataSeries(aSeriesSeq[nId]);
909
0
        }
910
0
    }
911
0
    return true;
912
0
}
913
914
bool lcl_ResizeChartColumns(const uno::Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nSize)
915
0
{
916
0
    return lcl_ChangeChartColumnCount(xChartDoc, nSize, false, true);
917
0
}
918
919
bool lcl_InsertChartColumns(const uno::Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nId)
920
0
{
921
0
    return lcl_ChangeChartColumnCount(xChartDoc, nId, true);
922
0
}
923
924
bool lcl_DeleteChartColumns(const uno::Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nId)
925
0
{
926
0
    return lcl_ChangeChartColumnCount(xChartDoc, nId, false);
927
0
}
928
}
929
930
static bool AddWordToWordbook(const uno::Reference<linguistic2::XDictionary>& xDictionary, SwWrtShell &rWrtSh)
931
0
{
932
0
    if (!xDictionary)
933
0
        return false;
934
935
0
    SwRect aToFill;
936
0
    uno::Reference<linguistic2::XSpellAlternatives>  xSpellAlt(rWrtSh.GetCorrection(nullptr, aToFill));
937
0
    if (!xSpellAlt.is())
938
0
        return false;
939
940
0
    OUString sWord = xSpellAlt->getWord();
941
0
    linguistic::DictionaryError nAddRes = linguistic::AddEntryToDic(xDictionary, sWord, false, OUString());
942
0
    if (linguistic::DictionaryError::NONE != nAddRes && xDictionary.is() && !xDictionary->getEntry(sWord).is())
943
0
    {
944
0
        SvxDicError(rWrtSh.GetView().GetFrameWeld(), nAddRes);
945
0
        return false;
946
0
    }
947
0
    return true;
948
0
}
949
950
void SwTextShell::Execute(SfxRequest &rReq)
951
0
{
952
0
    bool bUseDialog = true;
953
0
    const SfxItemSet *pArgs = rReq.GetArgs();
954
0
    SwWrtShell& rWrtSh = GetShell();
955
0
    const SfxPoolItem* pItem = nullptr;
956
0
    const sal_uInt16 nSlot = rReq.GetSlot();
957
0
    if(pArgs)
958
0
        pArgs->GetItemState(GetPool().GetWhichIDFromSlotID(nSlot), false, &pItem);
959
0
    switch( nSlot )
960
0
    {
961
0
        case SID_UNICODE_NOTATION_TOGGLE:
962
0
        {
963
0
            tools::Long nMaxUnits = 256;
964
0
            sal_Int32 nSelLength = rWrtSh.GetSelText().getLength();
965
0
            if( rWrtSh.IsSelection() && !rWrtSh.IsMultiSelection() && (nSelLength < nMaxUnits) )
966
0
                nMaxUnits = nSelLength;
967
968
0
            tools::Long index = 0;
969
0
            ToggleUnicodeCodepoint aToggle;
970
0
            while( nMaxUnits-- && aToggle.AllowMoreInput(rWrtSh.GetChar(true, index-1)) )
971
0
                --index;
972
973
0
            OUString sReplacement = aToggle.ReplacementString();
974
0
            if( !sReplacement.isEmpty() )
975
0
            {
976
0
                if (rWrtSh.HasReadonlySel() && !rWrtSh.CursorInsideInputField())
977
0
                {
978
                    // Only break if there's something to do; don't nag with the dialog otherwise
979
0
                    rWrtSh.InfoReadOnlyDialog(false);
980
0
                    break;
981
0
                }
982
0
                OUString stringToReplace = aToggle.StringToReplace();
983
0
                SwRewriter aRewriter;
984
0
                aRewriter.AddRule( UndoArg1, stringToReplace );
985
0
                aRewriter.AddRule( UndoArg2, SwResId(STR_YIELDS) );
986
0
                aRewriter.AddRule( UndoArg3, sReplacement );
987
0
                rWrtSh.StartUndo(SwUndoId::REPLACE, &aRewriter);
988
0
                rWrtSh.GetCursor()->Normalize(false);
989
990
0
                rWrtSh.ClearMark();
991
0
                if( rWrtSh.IsInSelect() )  // cancel any in-progress keyboard selection as well
992
0
                    rWrtSh.EndSelect();
993
                // Select exactly what was chosen for replacement
994
0
                rWrtSh.GetCursor()->SetMark();
995
0
                rWrtSh.GetCursor()->GetPoint()->AdjustContent(-stringToReplace.getLength());
996
0
                rWrtSh.DelLeft();
997
0
                rWrtSh.Insert2( sReplacement );
998
0
                rWrtSh.EndUndo(SwUndoId::REPLACE, &aRewriter);
999
0
            }
1000
0
        }
1001
0
        break;
1002
1003
0
        case SID_LANGUAGE_STATUS:
1004
0
        {
1005
            // get the language
1006
0
            OUString aNewLangText;
1007
0
            const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(SID_LANGUAGE_STATUS);
1008
0
            if (pItem2)
1009
0
                aNewLangText = pItem2->GetValue();
1010
1011
            //!! Remember the view frame right now...
1012
            //!! (call to GetView().GetViewFrame() will break if the
1013
            //!! SwTextShell got destroyed meanwhile.)
1014
0
            SfxViewFrame& rViewFrame = GetView().GetViewFrame();
1015
1016
0
            if (aNewLangText == "*")
1017
0
            {
1018
                // open the dialog "Tools/Options/Languages and Locales - General"
1019
                // to set the documents default language
1020
0
                SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1021
0
                ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateVclDialog(GetView().GetFrameWeld(), SID_LANGUAGE_OPTIONS));
1022
0
                pDlg->Execute();
1023
0
            }
1024
0
            else
1025
0
            {
1026
                //!! We have to use StartAction / EndAction bracketing in
1027
                //!! order to prevent possible destruction of the SwTextShell
1028
                //!! due to the selection changes coming below.
1029
0
                rWrtSh.StartAction();
1030
                // prevent view from jumping because of (temporary) selection changes
1031
0
                rWrtSh.LockView( true );
1032
1033
                // setting the new language...
1034
0
                if (!aNewLangText.isEmpty())
1035
0
                {
1036
0
                    static constexpr OUString aSelectionLangPrefix(u"Current_"_ustr);
1037
0
                    static constexpr OUString aParagraphLangPrefix(u"Paragraph_"_ustr);
1038
0
                    static constexpr OUString aDocumentLangPrefix(u"Default_"_ustr);
1039
1040
0
                    SfxItemSetFixed<RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
1041
0
                                    RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
1042
0
                                    RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
1043
0
                                    RES_CHRATR_SCRIPT_HINT, RES_CHRATR_SCRIPT_HINT>
1044
0
                        aCoreSet(GetPool());
1045
1046
0
                    sal_Int32 nPos = 0;
1047
0
                    bool bForSelection = true;
1048
0
                    bool bForParagraph = false;
1049
0
                    if (-1 != (nPos = aNewLangText.indexOf( aSelectionLangPrefix )))
1050
0
                    {
1051
                        // ... for the current selection
1052
0
                        aNewLangText = aNewLangText.replaceAt(nPos, aSelectionLangPrefix.getLength(), u"");
1053
0
                        bForSelection = true;
1054
0
                    }
1055
0
                    else if (-1 != (nPos = aNewLangText.indexOf(aParagraphLangPrefix)))
1056
0
                    {
1057
                        // ... for the current paragraph language
1058
0
                        aNewLangText = aNewLangText.replaceAt(nPos, aParagraphLangPrefix.getLength(), u"");
1059
0
                        bForSelection = true;
1060
0
                        bForParagraph = true;
1061
0
                    }
1062
0
                    else if (-1 != (nPos = aNewLangText.indexOf(aDocumentLangPrefix)))
1063
0
                    {
1064
                        // ... as default document language
1065
0
                        aNewLangText = aNewLangText.replaceAt(nPos, aDocumentLangPrefix.getLength(), u"");
1066
0
                        bForSelection = false;
1067
0
                    }
1068
1069
0
                    if (bForParagraph || !bForSelection)
1070
0
                    {
1071
0
                        rWrtSh.Push(); // save selection for later restoration
1072
0
                        rWrtSh.ClearMark(); // fdo#67796: invalidate table crsr
1073
0
                    }
1074
1075
0
                    if (bForParagraph)
1076
0
                        SwLangHelper::SelectCurrentPara( rWrtSh );
1077
1078
0
                    if (!bForSelection) // document language to be changed...
1079
0
                    {
1080
0
                        rWrtSh.SelAll();
1081
0
                        rWrtSh.ExtendedSelectAll();
1082
0
                    }
1083
1084
0
                    rWrtSh.StartUndo( ( !bForParagraph && !bForSelection ) ? SwUndoId::SETDEFTATTR : SwUndoId::EMPTY );
1085
0
                    if (aNewLangText == "LANGUAGE_NONE")
1086
0
                        SwLangHelper::SetLanguage_None( rWrtSh, bForSelection, aCoreSet );
1087
0
                    else if (aNewLangText == "RESET_LANGUAGES")
1088
0
                        SwLangHelper::ResetLanguages( rWrtSh );
1089
0
                    else
1090
0
                        SwLangHelper::SetLanguage( rWrtSh, aNewLangText, bForSelection, aCoreSet );
1091
0
                    rWrtSh.EndUndo();
1092
1093
0
                    if (bForParagraph || !bForSelection)
1094
0
                    {
1095
0
                        rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent); // restore selection...
1096
0
                    }
1097
0
                }
1098
1099
0
                rWrtSh.LockView( false );
1100
0
                rWrtSh.EndAction();
1101
0
            }
1102
1103
            // invalidate slot to get the new language displayed
1104
0
            rViewFrame.GetBindings().Invalidate( nSlot );
1105
1106
0
            rReq.Done();
1107
0
            break;
1108
0
        }
1109
1110
0
        case SID_THES:
1111
0
        {
1112
            // replace word/selection with text from selected sub menu entry
1113
0
            OUString aReplaceText;
1114
0
            const SfxStringItem* pItem2 = rReq.GetArg(FN_PARAM_THES_WORD_REPLACE);
1115
0
            if (pItem2)
1116
0
                aReplaceText = pItem2->GetValue();
1117
0
            if (!aReplaceText.isEmpty())
1118
0
            {
1119
0
                SwView &rView2 = rWrtSh.GetView();
1120
0
                const bool bSelection = rWrtSh.HasSelection();
1121
0
                const OUString aLookUpText = rView2.GetThesaurusLookUpText( bSelection );
1122
0
                rView2.InsertThesaurusSynonym( aReplaceText, aLookUpText, bSelection );
1123
0
            }
1124
0
        }
1125
0
        break;
1126
1127
0
        case SID_CHARMAP:
1128
0
        {
1129
0
            InsertSymbol( rReq );
1130
0
        }
1131
0
        break;
1132
0
        case FN_INSERT_FOOTNOTE:
1133
0
        case FN_INSERT_ENDNOTE:
1134
0
        {
1135
0
            OUString aStr;
1136
0
            const SfxStringItem* pFont = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
1137
0
            const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(nSlot);
1138
0
            if ( pNameItem )
1139
0
                aStr = pNameItem->GetValue();
1140
0
            bool bFont = pFont && !pFont->GetValue().isEmpty();
1141
0
            rWrtSh.StartUndo( SwUndoId::UI_INSERT_FOOTNOTE );
1142
0
            rWrtSh.InsertFootnote( aStr, nSlot == FN_INSERT_ENDNOTE, !bFont );
1143
0
            if ( bFont )
1144
0
            {
1145
0
                rWrtSh.Left( SwCursorSkipMode::Chars, true, 1, false );
1146
0
                SfxItemSetFixed<RES_CHRATR_FONT, RES_CHRATR_FONT> aSet( rWrtSh.GetAttrPool() );
1147
0
                rWrtSh.GetCurAttr( aSet );
1148
0
                rWrtSh.SetAttrSet( aSet, SetAttrMode::DONTEXPAND );
1149
0
                rWrtSh.ResetSelect(nullptr, false, ScrollSizeMode::ScrollSizeDefault);
1150
0
                rWrtSh.EndSelect();
1151
0
                rWrtSh.GotoFootnoteText();
1152
0
            }
1153
0
            rWrtSh.EndUndo( SwUndoId::UI_INSERT_FOOTNOTE );
1154
0
            rReq.Done();
1155
0
        }
1156
0
        break;
1157
0
        case FN_INSERT_FOOTNOTE_DLG:
1158
0
        {
1159
0
            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1160
0
            VclPtr<AbstractInsFootNoteDlg> pDlg(pFact->CreateInsFootNoteDlg(
1161
0
                GetView().GetFrameWeld(), rWrtSh));
1162
0
            pDlg->SetHelpId(GetStaticInterface()->GetSlot(nSlot)->GetCommand());
1163
0
            pDlg->StartExecuteAsync(
1164
0
                [this, pDlg] (sal_Int32 nResult)->void
1165
0
                {
1166
0
                    if ( nResult == RET_OK )
1167
0
                    {
1168
0
                        pDlg->Apply();
1169
0
                        const sal_uInt16 nId = pDlg->IsEndNote() ? FN_INSERT_ENDNOTE : FN_INSERT_FOOTNOTE;
1170
0
                        SfxRequest aReq(GetView().GetViewFrame(), nId);
1171
0
                        if ( !pDlg->GetStr().isEmpty() )
1172
0
                            aReq.AppendItem( SfxStringItem( nId, pDlg->GetStr() ) );
1173
0
                        if ( !pDlg->GetFontName().isEmpty() )
1174
0
                            aReq.AppendItem( SfxStringItem( FN_PARAM_1, pDlg->GetFontName() ) );
1175
0
                        ExecuteSlot( aReq );
1176
0
                    }
1177
0
                    pDlg->disposeOnce();
1178
0
                }
1179
0
            );
1180
0
            rReq.Ignore();
1181
0
        }
1182
0
        break;
1183
0
        case FN_FORMAT_FOOTNOTE_DLG:
1184
0
        case FN_FORMAT_CURRENT_FOOTNOTE_DLG:
1185
0
        {
1186
0
            GetView().ExecFormatFootnote();
1187
0
            break;
1188
0
        }
1189
0
        case SID_INSERTDOC:
1190
0
        {
1191
0
            GetView().ExecuteInsertDoc( rReq, pItem );
1192
0
            break;
1193
0
        }
1194
0
        case FN_FORMAT_RESET:
1195
0
        {
1196
            // Assure the folded outline button does not remain after resetting
1197
            // RES_PARATTR_OUTLINELEVEL and that folded outline content that becomes unfolded due to
1198
            // RES_PARATR_GRABBAG "OutlineContentVisibleAttr" being reset is shown for outlines set by
1199
            // a style.
1200
0
            MakeAllOutlineContentTemporarilyVisible a(rWrtSh.GetDoc());
1201
1202
            // #i78856, reset all attributes but not the language attributes
1203
            // (for this build an array of all relevant attributes and
1204
            // remove the languages from that)
1205
0
            o3tl::sorted_vector<sal_uInt16> aAttribs;
1206
1207
0
            static constexpr std::pair<sal_uInt16, sal_uInt16> aResetableSetRange[] = {
1208
                // tdf#40496: we don't want to change writing direction, so exclude RES_FRAMEDIR:
1209
0
                { RES_FRMATR_BEGIN, RES_FRAMEDIR - 1 },
1210
0
                { RES_FRAMEDIR + 1, RES_FRMATR_END - 1 },
1211
0
                { RES_CHRATR_BEGIN, RES_CHRATR_LANGUAGE - 1 },
1212
0
                { RES_CHRATR_LANGUAGE + 1, RES_CHRATR_CJK_LANGUAGE - 1 },
1213
0
                { RES_CHRATR_CJK_LANGUAGE + 1, RES_CHRATR_CTL_LANGUAGE - 1 },
1214
0
                { RES_CHRATR_CTL_LANGUAGE + 1, RES_CHRATR_END - 1 },
1215
0
                { RES_PARATR_BEGIN, RES_PARATR_END - 1 },
1216
0
                { RES_PARATR_LIST_AUTOFMT, RES_PARATR_LIST_AUTOFMT },
1217
0
                { RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER },
1218
0
                { RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END - 1 },
1219
0
            };
1220
0
            for (const auto& [nBegin, nEnd] : aResetableSetRange)
1221
0
            {
1222
0
                for (sal_uInt16 i = nBegin; i <= nEnd; ++i)
1223
0
                    aAttribs.insert( i );
1224
0
            }
1225
1226
            // also clear the direct formatting flag inside SwTableBox(es)
1227
0
            if (SwFEShell* pFEShell = GetView().GetDocShell()->GetFEShell())
1228
0
                pFEShell->UpdateTableStyleFormatting(nullptr, true);
1229
1230
            // tdf#160801 fix crash by delaying resetting of attributes
1231
            // Calling SwWrtShell::ResetAttr() will sometimes delete the
1232
            // current SwTextShell instance so call it after clearing the
1233
            // direct formatting flag.
1234
0
            rWrtSh.ResetAttr( aAttribs );
1235
1236
0
            rReq.Done();
1237
0
            break;
1238
0
        }
1239
0
        case FN_INSERT_BREAK_DLG:
1240
0
        {
1241
0
            if ( pItem )
1242
0
            {
1243
0
                ::std::optional<sal_uInt16> oPageNumber;
1244
0
                std::optional<SwLineBreakClear> oClear;
1245
0
                UIName aTemplateName;
1246
0
                sal_uInt16 nKind = static_cast<const SfxInt16Item*>(pItem)->GetValue();
1247
0
                const SfxStringItem* pTemplate = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
1248
0
                const SfxUInt16Item* pNumber = rReq.GetArg<SfxUInt16Item>(FN_PARAM_2);
1249
0
                const SfxBoolItem* pIsNumberFilled = rReq.GetArg<SfxBoolItem>(FN_PARAM_3);
1250
0
                if ( pTemplate )
1251
0
                    aTemplateName = UIName(pTemplate->GetValue());
1252
0
                if ( pNumber && pIsNumberFilled && pIsNumberFilled->GetValue() )
1253
0
                    oPageNumber = pNumber->GetValue();
1254
1255
0
                InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName, oClear);
1256
0
            }
1257
0
            else
1258
0
            {
1259
0
                SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1260
1261
0
                std::shared_ptr<AbstractSwBreakDlg> pAbstractDialog(pFact->CreateSwBreakDlg(GetView().GetFrameWeld(), rWrtSh));
1262
0
                std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController());
1263
1264
0
                weld::DialogController::runAsync(pDialogController,
1265
0
                    [pAbstractDialog=std::move(pAbstractDialog), &rWrtSh] (sal_Int32 nResult) {
1266
0
                        if( RET_OK == nResult )
1267
0
                        {
1268
0
                            sal_uInt16 nKind = pAbstractDialog->GetKind();
1269
0
                            OUString aTemplateName = pAbstractDialog->GetTemplateName();
1270
0
                            ::std::optional<sal_uInt16> oPageNumber = pAbstractDialog->GetPageNumber();
1271
0
                            std::optional<SwLineBreakClear> oClear = pAbstractDialog->GetClear();
1272
1273
0
                            InsertBreak(rWrtSh, nKind, oPageNumber, UIName(aTemplateName), oClear);
1274
0
                        }
1275
0
                    });
1276
0
            }
1277
1278
0
            break;
1279
0
        }
1280
0
        case FN_INSERT_BOOKMARK:
1281
0
        {
1282
0
            const SfxStringItem* pBookmarkText = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
1283
0
            SwPaM* pCursorPos = rWrtSh.GetCursor();
1284
0
            if ( pItem )
1285
0
            {
1286
0
                rWrtSh.StartAction();
1287
0
                OUString sName = static_cast<const SfxStringItem*>(pItem)->GetValue();
1288
1289
0
                if (pBookmarkText)
1290
0
                {
1291
0
                    OUString aBookmarkText = pBookmarkText->GetValue();
1292
                    // Split node to remember where the start position is.
1293
0
                    bool bSuccess = rWrtSh.GetDoc()->getIDocumentContentOperations().SplitNode(
1294
0
                        *pCursorPos->GetPoint(), /*bChkTableStart=*/false);
1295
0
                    if (bSuccess)
1296
0
                    {
1297
0
                        SwPaM aBookmarkPam(*pCursorPos->GetPoint());
1298
0
                        aBookmarkPam.Move(fnMoveBackward, GoInContent);
1299
1300
                        // Paste HTML content.
1301
0
                        SwTranslateHelper::PasteHTMLToPaM(
1302
0
                            rWrtSh, pCursorPos, aBookmarkText.toUtf8());
1303
0
                        if (pCursorPos->GetPoint()->GetContentIndex() == 0)
1304
0
                        {
1305
                            // The paste created a last empty text node, remove it.
1306
0
                            SwPaM aPam(*pCursorPos->GetPoint());
1307
0
                            aPam.SetMark();
1308
0
                            aPam.Move(fnMoveBackward, GoInContent);
1309
0
                            rWrtSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPam);
1310
0
                        }
1311
1312
                        // Undo the above SplitNode().
1313
0
                        aBookmarkPam.SetMark();
1314
0
                        aBookmarkPam.Move(fnMoveForward, GoInContent);
1315
0
                        rWrtSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(
1316
0
                            aBookmarkPam);
1317
0
                        *aBookmarkPam.GetMark() = *pCursorPos->GetPoint();
1318
0
                        *pCursorPos = aBookmarkPam;
1319
0
                    }
1320
0
                }
1321
1322
0
                rWrtSh.SetBookmark( vcl::KeyCode(), SwMarkName(sName) );
1323
0
                if (pBookmarkText)
1324
0
                {
1325
0
                    pCursorPos->DeleteMark();
1326
0
                }
1327
0
                rWrtSh.EndAction();
1328
0
                break;
1329
0
            }
1330
0
            [[fallthrough]];
1331
0
        }
1332
0
        case FN_EDIT_BOOKMARK:
1333
0
        {
1334
0
            ::std::optional<OUString> oName;
1335
0
            if (pItem)
1336
0
                oName.emplace(static_cast<const SfxStringItem*>(pItem)->GetValue());
1337
1338
0
            {
1339
0
                SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1340
0
                ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwInsertBookmarkDlg(GetView().GetFrameWeld(), rWrtSh, oName ? &*oName : nullptr));
1341
0
                VclAbstractDialog::AsyncContext aContext;
1342
0
                aContext.maEndDialogFn = [](sal_Int32){};
1343
0
                pDlg->StartExecuteAsync(aContext);
1344
0
            }
1345
1346
0
            break;
1347
0
        }
1348
0
        case FN_UPDATE_BOOKMARKS:
1349
0
        {
1350
            // This updates all bookmarks in the document that match the conditions specified in
1351
            // rReq.
1352
0
            UpdateBookmarks(rReq, rWrtSh);
1353
0
            break;
1354
0
        }
1355
0
        case FN_UPDATE_BOOKMARK:
1356
0
        {
1357
            // This updates the bookmark under the cursor.
1358
0
            UpdateBookmark(rReq, rWrtSh);
1359
0
            break;
1360
0
        }
1361
0
        case FN_DELETE_BOOKMARK:
1362
0
        {
1363
            // This deletes a bookmark with the specified name.
1364
0
            if (pItem && !rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
1365
0
            {
1366
0
                IDocumentMarkAccess* const pMarkAccess = rWrtSh.getIDocumentMarkAccess();
1367
0
                pMarkAccess->deleteMark(pMarkAccess->findMark(SwMarkName(static_cast<const SfxStringItem*>(pItem)->GetValue())), false);
1368
0
            }
1369
0
            break;
1370
0
        }
1371
0
        case FN_DELETE_BOOKMARKS:
1372
0
        {
1373
            // This deletes all bookmarks in the document matching a specified prefix.
1374
0
            DeleteBookmarks(rReq, rWrtSh);
1375
0
            break;
1376
0
        }
1377
0
        case FN_DELETE_FIELDS:
1378
0
        {
1379
            // This deletes all fields in the document matching a specified type & prefix.
1380
0
            DeleteFields(rReq, rWrtSh);
1381
0
            break;
1382
0
        }
1383
0
        case FN_UPDATE_SECTIONS:
1384
0
        {
1385
0
            UpdateSections(rReq, rWrtSh);
1386
0
            break;
1387
0
        }
1388
0
        case FN_DELETE_SECTIONS:
1389
0
        {
1390
            // This deletes all sections in the document matching a specified prefix. Note that the
1391
            // section is deleted, but not its contents.
1392
0
            DeleteSections(rReq, rWrtSh);
1393
0
            break;
1394
0
        }
1395
0
        case FN_DELETE_CONTENT_CONTROL:
1396
0
        {
1397
0
            DeleteContentControl( rWrtSh );
1398
0
            break;
1399
0
        }
1400
0
        case FN_SET_REMINDER:
1401
0
        {
1402
            // collect and sort navigator reminder names
1403
0
            IDocumentMarkAccess* const pMarkAccess = rWrtSh.getIDocumentMarkAccess();
1404
0
            std::vector< SwMarkName > vNavMarkNames;
1405
0
            for(auto ppMark = pMarkAccess->getAllMarksBegin();
1406
0
                ppMark != pMarkAccess->getAllMarksEnd();
1407
0
                ++ppMark)
1408
0
            {
1409
0
                if( IDocumentMarkAccess::GetType(**ppMark) == IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER )
1410
0
                    vNavMarkNames.push_back((*ppMark)->GetName());
1411
0
            }
1412
0
            std::sort(vNavMarkNames.begin(), vNavMarkNames.end());
1413
1414
            // we are maxed out so delete the first one
1415
            // this assumes that IDocumentMarkAccess generates Names in ascending order
1416
0
            if(vNavMarkNames.size() == MAX_MARKS)
1417
0
                pMarkAccess->deleteMark(pMarkAccess->findMark(vNavMarkNames[0]), false);
1418
1419
0
            rWrtSh.SetBookmark(vcl::KeyCode(), SwMarkName(), IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER);
1420
0
            SwView::SetActMark(vNavMarkNames.size() < MAX_MARKS ? vNavMarkNames.size() : MAX_MARKS-1);
1421
1422
0
            break;
1423
0
        }
1424
0
        case FN_AUTOFORMAT_REDLINE_APPLY:
1425
0
        {
1426
0
            SvxSwAutoFormatFlags aFlags(SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags());
1427
            // This must always be false for the postprocessing.
1428
0
            aFlags.bAFormatByInput = false;
1429
0
            aFlags.bWithRedlining = true;
1430
0
            rWrtSh.AutoFormat( &aFlags, false );
1431
0
            aFlags.bWithRedlining = false;
1432
1433
0
            SfxViewFrame& rVFrame = GetView().GetViewFrame();
1434
0
            if (rVFrame.HasChildWindow(FN_REDLINE_ACCEPT))
1435
0
                rVFrame.ToggleChildWindow(FN_REDLINE_ACCEPT);
1436
1437
0
            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1438
0
            auto xRequest = std::make_shared<SfxRequest>(rReq);
1439
0
            rReq.Ignore(); // the 'old' request is not relevant any more
1440
0
            VclPtr<AbstractSwModalRedlineAcceptDlg> pDlg(pFact->CreateSwModalRedlineAcceptDlg(GetView().GetEditWin().GetFrameWeld()));
1441
0
            pDlg->StartExecuteAsync(
1442
0
                [pDlg, xRequest=std::move(xRequest)] (sal_Int32 /*nResult*/)->void
1443
0
                {
1444
0
                    pDlg->disposeOnce();
1445
0
                    xRequest->Done();
1446
0
                }
1447
0
            );
1448
0
        }
1449
0
        break;
1450
1451
0
        case FN_AUTOFORMAT_APPLY:
1452
0
        {
1453
0
            SvxSwAutoFormatFlags aFlags(SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags());
1454
            // This must always be false for the postprocessing.
1455
0
            aFlags.bAFormatByInput = false;
1456
0
            rWrtSh.AutoFormat( &aFlags, false );
1457
0
            rReq.Done();
1458
0
        }
1459
0
        break;
1460
0
        case FN_AUTOFORMAT_AUTO:
1461
0
        {
1462
0
            SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get();
1463
0
            bool bSet = pItem ? static_cast<const SfxBoolItem*>(pItem)->GetValue() : !rACfg.IsAutoFormatByInput();
1464
0
            if( bSet != rACfg.IsAutoFormatByInput() )
1465
0
            {
1466
0
                rACfg.SetAutoFormatByInput( bSet );
1467
0
                rACfg.Commit();
1468
0
                GetView().GetViewFrame().GetBindings().Invalidate( nSlot );
1469
0
                if ( !pItem )
1470
0
                    rReq.AppendItem( SfxBoolItem( GetPool().GetWhichIDFromSlotID(nSlot), bSet ) );
1471
0
                rReq.Done();
1472
0
            }
1473
0
        }
1474
0
        break;
1475
0
        case FN_AUTO_CORRECT:
1476
0
        {
1477
            // At first set to blank as default.
1478
0
            rWrtSh.AutoCorrect( *SvxAutoCorrCfg::Get().GetAutoCorrect(), ' ' );
1479
0
            rReq.Done();
1480
0
        }
1481
0
        break;
1482
0
        case FN_TABLE_SORT_DIALOG:
1483
0
        case FN_SORTING_DLG:
1484
0
        {
1485
0
            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1486
0
            VclPtr<AbstractSwSortDlg> pDlg(pFact->CreateSwSortingDialog(GetView().GetFrameWeld(), rWrtSh));
1487
0
            auto xRequest = std::make_shared<SfxRequest>(rReq);
1488
0
            rReq.Ignore(); // the 'old' request is not relevant any more
1489
0
            pDlg->StartExecuteAsync(
1490
0
                [pDlg, xRequest=std::move(xRequest)] (sal_Int32 nResult)->void
1491
0
                {
1492
0
                    if (nResult == RET_OK)
1493
0
                        pDlg->Apply();
1494
0
                    pDlg->disposeOnce();
1495
0
                    xRequest->Done();
1496
0
                }
1497
0
            );
1498
0
        }
1499
0
        break;
1500
0
        case FN_NUMBERING_OUTLINE_DLG:
1501
0
        {
1502
0
            GetView().ExecNumberingOutline(GetPool());
1503
0
            rReq.Done();
1504
0
        }
1505
0
            break;
1506
0
        case FN_CALCULATE:
1507
0
            {
1508
0
                rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rWrtSh );
1509
0
                pTransfer->CalculateAndCopy();
1510
0
                rReq.Done();
1511
0
            }
1512
0
            break;
1513
0
        case FN_GOTO_REFERENCE:
1514
0
        {
1515
0
            SwField *pField = rWrtSh.GetCurField();
1516
0
            if(pField && pField->GetTypeId() == SwFieldTypesEnum::GetRef)
1517
0
            {
1518
0
                rWrtSh.StartAllAction();
1519
0
                rWrtSh.SwCursorShell::GotoRefMark( static_cast<SwGetRefField*>(pField)->GetSetRefName(),
1520
0
                                    static_cast<SwGetRefField*>(pField)->GetSubType(),
1521
0
                                    static_cast<SwGetRefField*>(pField)->GetSeqNo(),
1522
0
                                    static_cast<SwGetRefField*>(pField)->GetFlags() );
1523
0
                rWrtSh.EndAllAction();
1524
0
                rReq.Done();
1525
0
            }
1526
0
        }
1527
0
            break;
1528
0
        case FN_EDIT_FORMULA:
1529
0
        {
1530
0
            const sal_uInt16 nId = SwInputChild::GetChildWindowId();
1531
0
            SfxViewFrame& rVFrame = GetView().GetViewFrame();
1532
0
            if(pItem)
1533
0
            {
1534
                //if the ChildWindow is active it has to be removed
1535
0
                if( rVFrame.HasChildWindow( nId ) )
1536
0
                {
1537
0
                    rVFrame.ToggleChildWindow( nId );
1538
0
                    rVFrame.GetBindings().InvalidateAll( true );
1539
0
                }
1540
1541
0
                OUString sFormula(static_cast<const SfxStringItem*>(pItem)->GetValue());
1542
0
                SwFieldMgr aFieldMgr;
1543
0
                rWrtSh.StartAllAction();
1544
0
                bool bDelSel = rWrtSh.HasSelection();
1545
0
                if( bDelSel )
1546
0
                {
1547
0
                    rWrtSh.StartUndo( SwUndoId::START );
1548
0
                    rWrtSh.DelRight();
1549
0
                }
1550
0
                else
1551
0
                {
1552
0
                    rWrtSh.EnterStdMode();
1553
0
                }
1554
1555
0
                if( !bDelSel && aFieldMgr.GetCurField() && SwFieldTypesEnum::Formel == aFieldMgr.GetCurTypeId() )
1556
0
                    aFieldMgr.UpdateCurField( static_cast<SwGetExpField*>(aFieldMgr.GetCurField())->GetFormat(), OUString(), sFormula );
1557
0
                else if( !sFormula.isEmpty() )
1558
0
                {
1559
0
                    if( rWrtSh.IsCursorInTable() )
1560
0
                    {
1561
0
                        SfxItemSetFixed<RES_BOXATR_FORMULA, RES_BOXATR_FORMULA> aSet( rWrtSh.GetAttrPool() );
1562
0
                        aSet.Put( SwTableBoxFormula( sFormula ));
1563
0
                        rWrtSh.SetTableBoxFormulaAttrs( aSet );
1564
0
                        rWrtSh.UpdateTable();
1565
0
                    }
1566
0
                    else
1567
0
                    {
1568
0
                        SvNumberFormatter* pFormatter = rWrtSh.GetNumberFormatter();
1569
0
                        const sal_uInt32 nSysNumFormat = pFormatter->GetFormatIndex( NF_NUMBER_STANDARD, LANGUAGE_SYSTEM);
1570
0
                        SwInsertField_Data aData(SwFieldTypesEnum::Formel, static_cast<sal_uInt16>(SwGetSetExpType::Formula), OUString(), sFormula, nSysNumFormat);
1571
0
                        aFieldMgr.InsertField(aData);
1572
0
                    }
1573
0
                }
1574
1575
0
                if( bDelSel )
1576
0
                    rWrtSh.EndUndo( SwUndoId::END );
1577
0
                rWrtSh.EndAllAction();
1578
0
                rReq.Done();
1579
0
            }
1580
0
            else
1581
0
            {
1582
0
                rWrtSh.EndAllTableBoxEdit();
1583
0
                rVFrame.ToggleChildWindow( nId );
1584
0
                if( !rVFrame.HasChildWindow( nId ) )
1585
0
                    rVFrame.GetBindings().InvalidateAll( true );
1586
0
                rReq.Ignore();
1587
0
            }
1588
0
        }
1589
1590
0
        break;
1591
0
        case FN_TABLE_UNSET_READ_ONLY:
1592
0
        {
1593
0
            rWrtSh.UnProtectTables();
1594
0
        }
1595
0
        break;
1596
0
        case SID_EDIT_HYPERLINK:
1597
0
        {
1598
0
            if (!rWrtSh.HasSelection())
1599
0
            {
1600
0
                SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
1601
0
                rWrtSh.GetCurAttr(aSet);
1602
0
                if (SfxItemState::SET > aSet.GetItemState(RES_TXTATR_INETFMT))
1603
0
                {
1604
                    // Didn't find a hyperlink to edit yet.
1605
1606
                    // If the cursor is just before an unselected hyperlink,
1607
                    // the dialog will not know that it should edit that hyperlink,
1608
                    // so in this case, first select it so the dialog will find the hyperlink.
1609
                    // The dialog would leave the hyperlink selected anyway after a successful edit
1610
                    // (although it isn't normally selected after a cancel, but oh well).
1611
0
                    if (!rWrtSh.SelectTextAttr(RES_TXTATR_INETFMT))
1612
0
                        break;
1613
0
                }
1614
0
            }
1615
1616
0
            GetView().GetViewFrame().SetChildWindow(SID_HYPERLINK_DIALOG, true);
1617
0
        }
1618
0
        break;
1619
0
        case SID_REMOVE_HYPERLINK:
1620
0
        {
1621
0
            bool bSel = rWrtSh.HasSelection();
1622
0
            if(!bSel)
1623
0
            {
1624
0
                rWrtSh.StartAction();
1625
0
                rWrtSh.Push();
1626
0
                if(!rWrtSh.SelectTextAttr( RES_TXTATR_INETFMT ))
1627
0
                    rWrtSh.SelWrd();
1628
0
            }
1629
            //now remove the attribute
1630
0
            rWrtSh.ResetAttr({ RES_TXTATR_INETFMT });
1631
0
            if(!bSel)
1632
0
            {
1633
0
                rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
1634
0
                rWrtSh.EndAction();
1635
0
            }
1636
0
        }
1637
0
        break;
1638
0
        case SID_ATTR_BRUSH_CHAR :
1639
0
        case SID_ATTR_CHAR_SCALEWIDTH :
1640
0
        case SID_ATTR_CHAR_ROTATED :
1641
0
        case FN_TXTATR_INET :
1642
0
        {
1643
0
            const sal_uInt16 nWhich = GetPool().GetWhichIDFromSlotID( nSlot );
1644
0
            if ( pArgs && pArgs->GetItemState( nWhich ) == SfxItemState::SET )
1645
0
                bUseDialog = false;
1646
0
            [[fallthrough]];
1647
0
        }
1648
0
        case SID_CHAR_DLG:
1649
0
        case SID_CHAR_DLG_EFFECT:
1650
0
        case SID_CHAR_DLG_POSITION:
1651
0
        {
1652
0
            sw_CharDialog(rWrtSh, bUseDialog, /*ApplyToParagraph*/false, nSlot, pArgs, &rReq);
1653
0
        }
1654
0
        break;
1655
0
        case SID_CHAR_DLG_FOR_PARAGRAPH:
1656
0
        {
1657
0
            sw_CharDialog(rWrtSh, /*UseDialog*/true, /*ApplyToParagraph*/true, nSlot, pArgs, &rReq);
1658
0
        }
1659
0
        break;
1660
0
        case SID_ATTR_LRSPACE :
1661
0
        case SID_ATTR_ULSPACE :
1662
0
        case SID_ATTR_BRUSH :
1663
0
        case SID_PARA_VERTALIGN :
1664
0
        case SID_ATTR_PARA_NUMRULE :
1665
0
        case SID_ATTR_PARA_REGISTER :
1666
0
        case SID_ATTR_PARA_PAGENUM :
1667
0
        case FN_FORMAT_LINENUMBER :
1668
0
        case FN_NUMBER_NEWSTART :
1669
0
        case FN_NUMBER_NEWSTART_AT :
1670
0
        case FN_FORMAT_DROPCAPS :
1671
0
        case FN_DROP_TEXT:
1672
0
        case SID_ATTR_PARA_LRSPACE:
1673
0
        {
1674
0
            const sal_uInt16 nWhich = GetPool().GetWhichIDFromSlotID( nSlot );
1675
0
            if ( pArgs && pArgs->GetItemState( nWhich ) == SfxItemState::SET )
1676
0
                bUseDialog = false;
1677
0
            [[fallthrough]];
1678
0
        }
1679
0
        case SID_PARA_DLG:
1680
0
        {
1681
0
            SwPaM* pPaM = nullptr;
1682
1683
0
            if ( pArgs )
1684
0
            {
1685
0
                const SwPaMItem* pPaMItem = pArgs->GetItemIfSet( GetPool().GetWhichIDFromSlotID( FN_PARAM_PAM ), false );
1686
0
                if ( pPaMItem )
1687
0
                    pPaM = pPaMItem->GetValue( );
1688
0
            }
1689
1690
0
            if ( !pPaM )
1691
0
                pPaM = rWrtSh.GetCursor();
1692
1693
0
            FieldUnit eMetric = ::GetDfltMetric( dynamic_cast<SwWebView*>( &GetView()) != nullptr );
1694
0
            SwModule* mod = SwModule::get();
1695
0
            mod->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast<sal_uInt16>(eMetric)));
1696
1697
0
            bool bApplyCharUnit = ::HasCharUnit( dynamic_cast<SwWebView*>( &GetView()) != nullptr  );
1698
0
            mod->PutItem(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, bApplyCharUnit));
1699
1700
0
            SfxItemSetFixed<
1701
0
                    RES_PARATR_BEGIN, RES_FRMATR_END - 1,
1702
                    // FillAttribute support:
1703
0
                    XATTR_FILL_FIRST, XATTR_FILL_LAST,
1704
                    // Includes SID_ATTR_TABSTOP_POS:
1705
0
                    SID_ATTR_TABSTOP_DEFAULTS, SID_ATTR_TABSTOP_OFFSET,
1706
0
                    SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
1707
0
                    SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
1708
                    // Items to hand over XPropertyList things like XColorList,
1709
                    // XHatchList, XGradientList, and XBitmapList to the Area
1710
                    // TabPage:
1711
0
                    SID_COLOR_TABLE, SID_PATTERN_LIST,
1712
0
                    SID_HTML_MODE, SID_HTML_MODE,
1713
0
                    SID_ATTR_PARA_PAGENUM, SID_ATTR_PARA_PAGENUM,
1714
0
                    FN_PARAM_1, FN_PARAM_1,
1715
0
                    FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT,
1716
0
                    FN_DROP_TEXT, FN_DROP_CHAR_STYLE_NAME>  aCoreSet( GetPool() );
1717
1718
            // get also the list level indent values merged as LR-SPACE item, if needed.
1719
0
            rWrtSh.GetPaMAttr( pPaM, aCoreSet, true );
1720
1721
            // create needed items for XPropertyList entries from the DrawModel so that
1722
            // the Area TabPage can access them
1723
            // Do this after GetCurAttr, this resets the ItemSet content again
1724
0
            SwDrawModel* pDrawModel = GetView().GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
1725
1726
0
            aCoreSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLE));
1727
0
            aCoreSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LIST));
1728
0
            aCoreSet.Put(SvxHatchListItem(pDrawModel->GetHatchList(), SID_HATCH_LIST));
1729
0
            aCoreSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), SID_BITMAP_LIST));
1730
0
            aCoreSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LIST));
1731
0
            aCoreSet.Put(SfxUInt16Item(SID_HTML_MODE,
1732
0
                            ::GetHtmlMode(GetView().GetDocShell())));
1733
1734
            // Tabulators: Put DefaultTabs into ItemSet
1735
0
            const SvxTabStopItem& rDefTabs =
1736
0
                            GetPool().GetUserOrPoolDefaultItem(RES_PARATR_TABSTOP);
1737
1738
0
            const sal_uInt16 nDefDist = o3tl::narrowing<sal_uInt16>(::GetTabDist( rDefTabs ));
1739
0
            SfxUInt16Item aDefDistItem( SID_ATTR_TABSTOP_DEFAULTS, nDefDist );
1740
0
            aCoreSet.Put( aDefDistItem );
1741
1742
            // Current tabulator
1743
0
            SfxUInt16Item aTabPos( SID_ATTR_TABSTOP_POS, 0 );
1744
0
            aCoreSet.Put( aTabPos );
1745
1746
            // Left border as offset
1747
            //#i24363# tab stops relative to indent
1748
0
            const tools::Long nOff
1749
0
                = rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::TABS_RELATIVE_TO_INDENT)
1750
0
                      ? aCoreSet.Get(RES_MARGIN_TEXTLEFT).ResolveTextLeft({})
1751
0
                      : 0;
1752
0
            SfxInt32Item aOff( SID_ATTR_TABSTOP_OFFSET, nOff );
1753
0
            aCoreSet.Put( aOff );
1754
1755
            // Setting the BoxInfo
1756
0
            ::PrepareBoxInfo( aCoreSet, rWrtSh );
1757
1758
            // Current page format
1759
0
            ::SwToSfxPageDescAttr( aCoreSet );
1760
1761
            // Properties of numbering
1762
0
            if (rWrtSh.GetNumRuleAtCurrCursorPos())
1763
0
            {
1764
0
                SfxBoolItem aStart( FN_NUMBER_NEWSTART, rWrtSh.IsNumRuleStart( pPaM ) );
1765
0
                aCoreSet.Put(aStart);
1766
0
                SfxUInt16Item aStartAt( FN_NUMBER_NEWSTART_AT,
1767
0
                                        rWrtSh.GetNodeNumStart( pPaM ) );
1768
0
                aCoreSet.Put(aStartAt);
1769
0
            }
1770
0
            VclPtr<SfxAbstractTabDialog> pDlg;
1771
1772
0
            if ( bUseDialog && GetActiveView() )
1773
0
            {
1774
0
                OUString sDefPage;
1775
0
                if (pItem)
1776
0
                    sDefPage = static_cast<const SfxStringItem*>(pItem)->GetValue();
1777
1778
0
                SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1779
0
                pDlg.reset(pFact->CreateSwParaDlg(GetView().GetFrameWeld(), GetView(), aCoreSet, false, sDefPage));
1780
0
            }
1781
1782
0
            if ( !bUseDialog )
1783
0
            {
1784
0
                if ( nSlot == SID_ATTR_PARA_LRSPACE)
1785
0
                {
1786
0
                    SvxLRSpaceItem aParaMargin(static_cast<const SvxLRSpaceItem&>(pArgs->Get(nSlot)));
1787
0
                    SvxFirstLineIndentItem firstLine(RES_MARGIN_FIRSTLINE);
1788
0
                    SvxTextLeftMarginItem leftMargin(RES_MARGIN_TEXTLEFT);
1789
0
                    SvxRightMarginItem rightMargin(RES_MARGIN_RIGHT);
1790
0
                    firstLine.SetTextFirstLineOffset(aParaMargin.GetTextFirstLineOffset(),
1791
0
                                                     aParaMargin.GetPropTextFirstLineOffset());
1792
0
                    firstLine.SetAutoFirst(aParaMargin.IsAutoFirst());
1793
0
                    leftMargin.SetTextLeft(aParaMargin.GetTextLeft(), aParaMargin.GetPropLeft());
1794
0
                    rightMargin.SetRight(aParaMargin.GetRight(), aParaMargin.GetPropRight());
1795
0
                    aCoreSet.Put(firstLine);
1796
0
                    aCoreSet.Put(leftMargin);
1797
0
                    aCoreSet.Put(rightMargin);
1798
1799
0
                    sw_ParagraphDialogResult(&aCoreSet, rWrtSh, rReq, pPaM);
1800
0
                }
1801
0
                else
1802
0
                    sw_ParagraphDialogResult(const_cast<SfxItemSet*>(pArgs), rWrtSh, rReq, pPaM);
1803
0
            }
1804
0
            else if (pDlg)
1805
0
            {
1806
0
                auto pRequest = std::make_shared<SfxRequest>(rReq);
1807
0
                rReq.Ignore(); // the 'old' request is not relevant any more
1808
1809
0
                auto vCursors = CopyPaMRing(*pPaM); // tdf#134439 make a copy to use at later apply
1810
0
                pDlg->StartExecuteAsync([pDlg, &rWrtSh, pDrawModel, pRequest=std::move(pRequest), nDefDist, vCursors=std::move(vCursors)](sal_Int32 nResult){
1811
0
                    if (nResult == RET_OK)
1812
0
                    {
1813
                        // Apply defaults if necessary.
1814
0
                        SfxItemSet* pSet = const_cast<SfxItemSet*>(pDlg->GetOutputItemSet());
1815
0
                        sal_uInt16 nNewDist;
1816
0
                        const SfxUInt16Item* pDefaultsItem = pSet->GetItemIfSet(SID_ATTR_TABSTOP_DEFAULTS, false);
1817
0
                        if (pDefaultsItem && nDefDist != (nNewDist = pDefaultsItem->GetValue()) )
1818
0
                        {
1819
0
                            SvxTabStopItem aDefTabs( 0, 0, SvxTabAdjust::Default, RES_PARATR_TABSTOP );
1820
0
                            MakeDefTabs( nNewDist, aDefTabs );
1821
0
                            rWrtSh.SetDefault( aDefTabs );
1822
0
                            pSet->ClearItem( SID_ATTR_TABSTOP_DEFAULTS );
1823
0
                        }
1824
1825
0
                        const SfxPoolItem* pItem2 = nullptr;
1826
0
                        if (SfxItemState::SET == pSet->GetItemState(FN_PARAM_1, false, &pItem2))
1827
0
                        {
1828
0
                            pSet->Put(SfxStringItem(FN_DROP_TEXT, static_cast<const SfxStringItem*>(pItem2)->GetValue()));
1829
0
                            pSet->ClearItem(FN_PARAM_1);
1830
0
                        }
1831
1832
0
                        if (const SwFormatDrop* pDropItem = pSet->GetItemIfSet(RES_PARATR_DROP, false))
1833
0
                        {
1834
0
                            UIName sCharStyleName;
1835
0
                            if (pDropItem->GetCharFormat())
1836
0
                                sCharStyleName = pDropItem->GetCharFormat()->GetName();
1837
0
                            pSet->Put(SfxStringItem(FN_DROP_CHAR_STYLE_NAME, sCharStyleName.toString()));
1838
0
                        }
1839
1840
0
                        const XFillStyleItem* pFS = pSet->GetItem<XFillStyleItem>(XATTR_FILLSTYLE);
1841
0
                        bool bSet = pFS && pFS->GetValue() == drawing::FillStyle_GRADIENT;
1842
0
                        const XFillGradientItem* pTempGradItem
1843
0
                            = bSet ? pSet->GetItem<XFillGradientItem>(XATTR_FILLGRADIENT) : nullptr;
1844
0
                        if (pTempGradItem && pTempGradItem->GetName().isEmpty())
1845
0
                        {
1846
                            // MigrateItemSet guarantees unique gradient names
1847
0
                            SfxItemSetFixed<XATTR_FILLGRADIENT, XATTR_FILLGRADIENT> aMigrateSet(rWrtSh.GetView().GetPool());
1848
0
                            aMigrateSet.Put(XFillGradientItem(u"gradient"_ustr, pTempGradItem->GetGradientValue()));
1849
0
                            SdrModel::MigrateItemSet(&aMigrateSet, pSet, *pDrawModel);
1850
0
                        }
1851
1852
0
                        bSet = pFS && pFS->GetValue() == drawing::FillStyle_HATCH;
1853
0
                        const XFillHatchItem* pTempHatchItem
1854
0
                            = bSet ? pSet->GetItem<XFillHatchItem>(XATTR_FILLHATCH) : nullptr;
1855
0
                        if (pTempHatchItem && pTempHatchItem->GetName().isEmpty())
1856
0
                        {
1857
0
                            SfxItemSetFixed<XATTR_FILLHATCH, XATTR_FILLHATCH> aMigrateSet(rWrtSh.GetView().GetPool());
1858
0
                            aMigrateSet.Put(XFillHatchItem(u"hatch"_ustr, pTempHatchItem->GetHatchValue()));
1859
0
                            SdrModel::MigrateItemSet(&aMigrateSet, pSet, *pDrawModel);
1860
0
                        }
1861
1862
0
                        sw_ParagraphDialogResult(pSet, rWrtSh, *pRequest, vCursors->front().get());
1863
0
                    }
1864
0
                    pDlg->disposeOnce();
1865
0
                });
1866
0
            }
1867
0
        }
1868
0
        break;
1869
0
        case FN_NUM_CONTINUE:
1870
0
        {
1871
0
            OUString sContinuedListId;
1872
0
            const SwNumRule* pRule =
1873
0
                rWrtSh.SearchNumRule( true, sContinuedListId );
1874
            // #i86492#
1875
            // Search also for bullet list
1876
0
            if ( !pRule )
1877
0
            {
1878
0
                pRule = rWrtSh.SearchNumRule( false, sContinuedListId );
1879
0
            }
1880
0
            if ( pRule )
1881
0
            {
1882
0
                rWrtSh.StartUndo(SwUndoId::INSATTR);
1883
1884
                // When merging with a different list, also helpfully remove any restart-numbering
1885
0
                if (!rReq.IsAPI()) // no need to be "helpful" like this for a macro
1886
0
                {
1887
0
                    for(SwPaM& rPaM : rWrtSh.GetCursor()->GetRingContainer())
1888
0
                    {
1889
                        // check each selected paragraph separately
1890
0
                        const SwNodeIndex nEnd = rPaM.End()->nNode;
1891
0
                        for (SwNodeIndex nPara = rPaM.Start()->nNode; nPara <= nEnd; ++nPara)
1892
0
                        {
1893
0
                            SwPaM aPaM(nPara);
1894
0
                            if (!rWrtSh.IsNumRuleStart(&aPaM))
1895
0
                                continue;
1896
                            // Only remove restart-numbering if the rule is actually going to change
1897
0
                            if (SwDoc::GetNumRuleAtPos(*aPaM.Start(), rWrtSh.GetLayout()) != pRule)
1898
0
                                rWrtSh.SetNumRuleStart(false, &aPaM);
1899
0
                        }
1900
0
                    }
1901
0
                }
1902
1903
0
                rWrtSh.SetCurNumRule( *pRule, false, sContinuedListId );
1904
0
                rWrtSh.EndUndo(SwUndoId::INSATTR);
1905
0
            }
1906
0
        }
1907
0
        break;
1908
1909
0
        case FN_SELECT_PARA:
1910
0
        {
1911
0
            if ( !rWrtSh.IsSttOfPara() )
1912
0
                rWrtSh.SttPara();
1913
0
            else
1914
0
                rWrtSh.EnterStdMode();
1915
0
            rWrtSh.EndPara( true );
1916
0
        }
1917
0
        break;
1918
1919
0
        case SID_DEC_INDENT:
1920
0
        case SID_INC_INDENT:
1921
        //According to the requirement, modified the behavior when user
1922
        //using the indent button on the toolbar. Now if we increase/decrease indent for a
1923
        //paragraph which has bullet style it will increase/decrease the bullet level.
1924
0
        {
1925
            //If the current paragraph has bullet call the function to
1926
            //increase or decrease the bullet level.
1927
            //Why could I know whether a paragraph has bullet or not by checking the below conditions?
1928
            //Please refer to the "case KEY_TAB:" section in SwEditWin::KeyInput(..) :
1929
            //      if( rSh.GetCurNumRule() && rSh.IsSttOfPara() &&
1930
            //                  !rSh.HasReadonlySel() )
1931
            //              eKeyState = KS_NumDown;
1932
            //Above code demonstrates that when the cursor is at the start of a paragraph which has bullet,
1933
            //press TAB will increase the bullet level.
1934
            //So I copied from that ^^
1935
0
            if ( rWrtSh.GetNumRuleAtCurrCursorPos() && !rWrtSh.HasReadonlySel() )
1936
0
            {
1937
0
                rWrtSh.NumUpDown( SID_INC_INDENT == nSlot );
1938
0
            }
1939
0
            else                //execute the original processing functions
1940
0
            {
1941
                //below is copied of the old codes
1942
0
                rWrtSh.MoveLeftMargin( SID_INC_INDENT == nSlot, rReq.GetModifier() != KEY_MOD1 );
1943
0
            }
1944
0
        }
1945
0
        rReq.Done();
1946
0
        break;
1947
1948
0
        case FN_DEC_INDENT_OFFSET:
1949
0
        case FN_INC_INDENT_OFFSET:
1950
0
            rWrtSh.MoveLeftMargin( FN_INC_INDENT_OFFSET == nSlot, rReq.GetModifier() == KEY_MOD1 );
1951
0
            rReq.Done();
1952
0
            break;
1953
1954
0
        case SID_ATTR_CHAR_COLOR2:
1955
0
        {
1956
0
            std::unique_ptr<const SvxColorItem> pRecentColor; // manage lifecycle scope
1957
0
            if (!pItem)
1958
0
            {
1959
                // no color provided: use the pre-selected color shown in the toolbar/sidebar
1960
0
                const std::optional<NamedColor> oColor
1961
0
                    = GetView().GetDocShell()->GetRecentColor(SID_ATTR_CHAR_COLOR);
1962
0
                if (oColor.has_value())
1963
0
                {
1964
0
                    const model::ComplexColor aCol = (*oColor).getComplexColor();
1965
0
                    pRecentColor = std::make_unique<const SvxColorItem>(
1966
0
                        aCol.getFinalColor(), aCol, RES_CHRATR_COLOR);
1967
0
                    pItem = pRecentColor.get();
1968
0
                }
1969
0
            }
1970
1971
0
            if (pItem)
1972
0
            {
1973
0
                auto* pColorItem = static_cast<const SvxColorItem*>(pItem);
1974
0
                SwEditWin& rEditWin = GetView().GetEditWin();
1975
0
                rEditWin.SetWaterCanTextColor(pColorItem->GetValue());
1976
0
                SwApplyTemplate* pApply = rEditWin.GetApplyTemplate();
1977
1978
                // If there is a selection, then set the color on it
1979
                // otherwise, it'll be the color for the next text to be typed
1980
0
                if (!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT)
1981
0
                {
1982
0
                    rWrtSh.SetAttrItem(SvxColorItem(pColorItem->GetValue(), pColorItem->getComplexColor(), RES_CHRATR_COLOR));
1983
0
                }
1984
1985
0
                rReq.Done();
1986
0
            }
1987
0
        }
1988
0
        break;
1989
0
        case SID_ATTR_CHAR_BACK_COLOR:
1990
0
        case SID_ATTR_CHAR_COLOR_BACKGROUND: // deprecated
1991
0
        case SID_ATTR_CHAR_COLOR_EXT:
1992
0
        {
1993
0
            Color aColor = COL_TRANSPARENT;
1994
0
            model::ComplexColor aComplexColor;
1995
1996
0
            if (pItem)
1997
0
            {
1998
0
                auto* pColorItem = static_cast<const SvxColorItem*>(pItem);
1999
0
                aColor = pColorItem->GetValue();
2000
0
                aComplexColor = pColorItem->getComplexColor();
2001
0
            }
2002
0
            else if (nSlot == SID_ATTR_CHAR_BACK_COLOR)
2003
0
            {
2004
                // no color provided: use the pre-selected color shown in the toolbar/sidebar
2005
0
                const std::optional<NamedColor> oColor
2006
0
                    = GetView().GetDocShell()->GetRecentColor(nSlot);
2007
0
                if (oColor.has_value())
2008
0
                {
2009
0
                    aComplexColor = (*oColor).getComplexColor();
2010
0
                    aColor = aComplexColor.getFinalColor();
2011
0
                }
2012
0
            }
2013
2014
0
            SwEditWin& rEdtWin = GetView().GetEditWin();
2015
0
            if (nSlot != SID_ATTR_CHAR_COLOR_EXT)
2016
0
                rEdtWin.SetWaterCanTextBackColor(aColor);
2017
0
            else if (pItem)
2018
0
                rEdtWin.SetWaterCanTextColor(aColor);
2019
2020
0
            SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
2021
0
            SwApplyTemplate aTempl;
2022
0
            if (!pApply && (rWrtSh.HasSelection() || rReq.IsAPI()))
2023
0
            {
2024
0
                if (nSlot != SID_ATTR_CHAR_COLOR_EXT)
2025
0
                {
2026
0
                    SfxItemSetFixed<RES_CHRATR_BACKGROUND, RES_CHRATR_BACKGROUND> aCoreSet( rWrtSh.GetView().GetPool() );
2027
2028
0
                    rWrtSh.GetCurAttr(aCoreSet);
2029
2030
                    // Remove highlight if already set of the same color
2031
0
                    const SvxBrushItem& rBrushItem = aCoreSet.Get(RES_CHRATR_BACKGROUND);
2032
0
                    if (aColor == rBrushItem.GetColor())
2033
0
                    {
2034
0
                        aComplexColor = model::ComplexColor();
2035
0
                        aColor = COL_TRANSPARENT;
2036
0
                    }
2037
0
                    ApplyCharBackground(aColor, aComplexColor, rWrtSh);
2038
0
                }
2039
0
                else
2040
0
                    rWrtSh.SetAttrItem(SvxColorItem(aColor, aComplexColor, RES_CHRATR_COLOR));
2041
0
            }
2042
0
            else
2043
0
            {
2044
0
                if(!pApply || pApply->nColor != nSlot)
2045
0
                    aTempl.nColor = nSlot;
2046
0
                rEdtWin.SetApplyTemplate(aTempl);
2047
0
            }
2048
2049
0
            rReq.Done();
2050
0
        }
2051
0
        break;
2052
2053
0
        case FN_NUM_BULLET_MOVEDOWN:
2054
0
            if (!rWrtSh.IsAddMode())
2055
0
                rWrtSh.MoveParagraph();
2056
0
            rReq.Done();
2057
0
            break;
2058
2059
0
        case FN_NUM_BULLET_MOVEUP:
2060
0
            if (!rWrtSh.IsAddMode())
2061
0
                rWrtSh.MoveParagraph(SwNodeOffset(-1));
2062
0
            rReq.Done();
2063
0
            break;
2064
0
        case SID_INSERT_HYPERLINK:
2065
0
        {
2066
0
            SfxRequest aReq(SID_HYPERLINK_DIALOG, SfxCallMode::SLOT, SfxGetpApp()->GetPool());
2067
0
            GetView().GetViewFrame().ExecuteSlot( aReq);
2068
0
            rReq.Ignore();
2069
0
        }
2070
0
        break;
2071
0
        case SID_RUBY_DIALOG:
2072
0
        case SID_HYPERLINK_DIALOG:
2073
0
        {
2074
0
            SfxRequest aReq(nSlot, SfxCallMode::SLOT, SfxGetpApp()->GetPool());
2075
0
            GetView().GetViewFrame().ExecuteSlot( aReq);
2076
0
            rReq.Ignore();
2077
0
        }
2078
0
        break;
2079
0
    case FN_INSERT_PAGEHEADER:
2080
0
    case FN_INSERT_PAGEFOOTER:
2081
0
    if(pArgs && pArgs->Count())
2082
0
    {
2083
0
        OUString sStyleName;
2084
0
        if(pItem)
2085
0
            sStyleName = static_cast<const SfxStringItem*>(pItem)->GetValue();
2086
0
        bool bOn = true;
2087
0
        if( SfxItemState::SET == pArgs->GetItemState(FN_PARAM_1, false, &pItem))
2088
0
            bOn = static_cast<const SfxBoolItem*>(pItem)->GetValue();
2089
0
        rWrtSh.ChangeHeaderOrFooter(UIName(sStyleName), FN_INSERT_PAGEHEADER == nSlot, bOn, !rReq.IsAPI());
2090
0
        rReq.Done();
2091
0
    }
2092
0
    break;
2093
0
    case FN_READONLY_SELECTION_MODE :
2094
0
        if(GetView().GetDocShell()->IsReadOnly())
2095
0
        {
2096
0
            rWrtSh.SetReadonlySelectionOption(
2097
0
                !rWrtSh.GetViewOptions()->IsSelectionInReadonly());
2098
0
            rWrtSh.ShowCursor();
2099
0
        }
2100
0
    break;
2101
0
    case FN_SELECTION_MODE_DEFAULT:
2102
0
    case FN_SELECTION_MODE_BLOCK :
2103
0
    {
2104
0
        bool bSetBlockMode = !rWrtSh.IsBlockMode();
2105
0
        if( pArgs && SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem))
2106
0
            bSetBlockMode = static_cast<const SfxBoolItem*>(pItem)->GetValue();
2107
0
        if( ( nSlot == FN_SELECTION_MODE_DEFAULT ) != bSetBlockMode )
2108
0
            rWrtSh.EnterBlockMode();
2109
0
        else
2110
0
            rWrtSh.EnterStdMode();
2111
0
        SfxBindings &rBnd = GetView().GetViewFrame().GetBindings();
2112
0
        rBnd.Invalidate(FN_STAT_SELMODE);
2113
0
        rBnd.Update(FN_STAT_SELMODE);
2114
0
    }
2115
0
    break;
2116
0
    case SID_OPEN_HYPERLINK:
2117
0
    case SID_COPY_HYPERLINK_LOCATION:
2118
0
    {
2119
0
        SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
2120
0
        rWrtSh.GetCurAttr(aSet);
2121
2122
0
        const SwFormatINetFormat* pINetFormat = nullptr;
2123
0
        if(SfxItemState::SET <= aSet.GetItemState( RES_TXTATR_INETFMT ))
2124
0
            pINetFormat = &aSet.Get(RES_TXTATR_INETFMT);
2125
0
        else if (!rWrtSh.HasSelection())
2126
0
        {
2127
            // is the cursor at the beginning of a hyperlink?
2128
0
            const SwTextNode* pTextNd = rWrtSh.GetCursor()->GetPointNode().GetTextNode();
2129
0
            if (pTextNd)
2130
0
            {
2131
0
                const sal_Int32 nIndex = rWrtSh.GetCursor()->Start()->GetContentIndex();
2132
0
                const SwTextAttr* pINetFmt = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
2133
0
                if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
2134
0
                    pINetFormat = &pINetFmt->GetINetFormat();
2135
0
            }
2136
0
        }
2137
2138
0
        if (pINetFormat)
2139
0
        {
2140
0
            if (nSlot == SID_OPEN_HYPERLINK)
2141
0
            {
2142
0
                rWrtSh.ClickToINetAttr(*pINetFormat);
2143
0
            }
2144
0
            else if (nSlot == SID_COPY_HYPERLINK_LOCATION)
2145
0
            {
2146
0
                OUString hyperlinkLocation = pINetFormat->GetValue();
2147
0
                ::uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetView().GetEditWin().GetClipboard();
2148
0
                vcl::unohelper::TextDataObject::CopyStringTo(hyperlinkLocation, xClipboard, SfxViewShell::Current());
2149
0
            }
2150
0
        }
2151
0
        else
2152
0
        {
2153
0
            SwField* pField = rWrtSh.GetCurField();
2154
0
            if (pField && pField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities)
2155
0
            {
2156
0
                const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
2157
0
                OUString targetURL = u""_ustr;
2158
2159
0
                if (auto targetType = rAuthorityField.GetTargetType();
2160
0
                    targetType == SwAuthorityField::TargetType::UseDisplayURL
2161
0
                    || targetType == SwAuthorityField::TargetType::UseTargetURL)
2162
0
                {
2163
                    // Bibliography entry with URL also provides a hyperlink.
2164
0
                    targetURL = rAuthorityField.GetAbsoluteURL();
2165
0
                }
2166
2167
0
                if (targetURL.getLength() > 0)
2168
0
                {
2169
0
                    if (nSlot == SID_OPEN_HYPERLINK)
2170
0
                    {
2171
0
                        ::LoadURL(rWrtSh, targetURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
2172
0
                    }
2173
0
                    else if (nSlot == SID_COPY_HYPERLINK_LOCATION)
2174
0
                    {
2175
0
                        ::uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetView().GetEditWin().GetClipboard();
2176
0
                        vcl::unohelper::TextDataObject::CopyStringTo(targetURL, xClipboard, SfxViewShell::Current());
2177
0
                    }
2178
0
                }
2179
0
            }
2180
0
        }
2181
0
    }
2182
0
    break;
2183
0
    case FN_OPEN_LOCAL_URL:
2184
0
    {
2185
0
        OUString aLocalURL = GetLocalURL(rWrtSh);
2186
0
        if (!aLocalURL.isEmpty())
2187
0
        {
2188
0
            ::LoadURL(rWrtSh, aLocalURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
2189
0
        }
2190
0
    }
2191
0
    break;
2192
0
    case SID_OPEN_XML_FILTERSETTINGS:
2193
0
    {
2194
0
        HandleOpenXmlFilterSettings(rReq);
2195
0
    }
2196
0
    break;
2197
0
    case FN_FORMAT_APPLY_HEAD1:
2198
0
    {
2199
0
    }
2200
0
    break;
2201
0
    case FN_FORMAT_APPLY_HEAD2:
2202
0
    {
2203
0
    }
2204
0
    break;
2205
0
    case FN_FORMAT_APPLY_HEAD3:
2206
0
    {
2207
0
    }
2208
0
    break;
2209
0
    case FN_FORMAT_APPLY_DEFAULT:
2210
0
    {
2211
0
    }
2212
0
    break;
2213
0
    case FN_FORMAT_APPLY_TEXTBODY:
2214
0
    {
2215
0
    }
2216
0
    break;
2217
0
    case FN_WORDCOUNT_DIALOG:
2218
0
    {
2219
0
        GetView().UpdateWordCount(this, nSlot);
2220
0
    }
2221
0
    break;
2222
0
    case FN_PROTECT_FIELDS:
2223
0
    case FN_PROTECT_BOOKMARKS:
2224
0
    {
2225
0
        IDocumentSettingAccess& rIDSA = rWrtSh.getIDocumentSettingAccess();
2226
0
        DocumentSettingId aSettingId = nSlot == FN_PROTECT_FIELDS
2227
0
                                           ? DocumentSettingId::PROTECT_FIELDS
2228
0
                                           : DocumentSettingId::PROTECT_BOOKMARKS;
2229
0
        rIDSA.set(aSettingId, !rIDSA.get(aSettingId));
2230
        // Invalidate so that toggle state gets updated
2231
0
        SfxViewFrame& rViewFrame = GetView().GetViewFrame();
2232
0
        rViewFrame.GetBindings().Invalidate(nSlot);
2233
0
        rViewFrame.GetBindings().Update(nSlot);
2234
0
    }
2235
0
    break;
2236
0
    case SID_FM_CTL_PROPERTIES:
2237
0
    {
2238
0
        SwPosition aPos(*GetShell().GetCursor()->GetPoint());
2239
0
        sw::mark::Fieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
2240
0
        if ( !pFieldBM )
2241
0
        {
2242
0
            aPos.AdjustContent(-1);
2243
0
            pFieldBM = GetShell().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
2244
0
        }
2245
2246
0
        if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN
2247
0
             && !(rWrtSh.GetCurrSection() && rWrtSh.GetCurrSection()->IsProtect()) )
2248
0
        {
2249
0
            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2250
0
            VclPtr<AbstractDropDownFormFieldDialog> pDlg(pFact->CreateDropDownFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), pFieldBM));
2251
0
            auto xRequest = std::make_shared<SfxRequest>(rReq);
2252
0
            rReq.Ignore(); // the 'old' request is not relevant any more
2253
0
            auto pWrtSh = &rWrtSh;
2254
0
            pDlg->StartExecuteAsync(
2255
0
                [pDlg, pFieldBM, pWrtSh, xRequest=std::move(xRequest)] (sal_Int32 nResult)->void
2256
0
                {
2257
0
                    if (nResult == RET_OK)
2258
0
                    {
2259
0
                        pDlg->Apply();
2260
0
                        pFieldBM->Invalidate();
2261
0
                        pWrtSh->InvalidateWindows( SwRect(pWrtSh->GetView().GetVisArea()) );
2262
0
                        pWrtSh->UpdateCursor(); // cursor position might be invalid
2263
0
                    }
2264
0
                    pDlg->disposeOnce();
2265
0
                    xRequest->Done();
2266
0
                }
2267
0
            );
2268
0
        }
2269
0
        else if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDATE )
2270
0
        {
2271
0
            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2272
0
            sw::mark::DateFieldmark* pDateField = &dynamic_cast<sw::mark::DateFieldmark&>(*pFieldBM);
2273
0
            VclPtr<AbstractDateFormFieldDialog> pDlg(pFact->CreateDateFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), pDateField, *GetView().GetDocShell()->GetDoc()));
2274
0
            auto pWrtSh = &rWrtSh;
2275
0
            auto xRequest = std::make_shared<SfxRequest>(rReq);
2276
0
            rReq.Ignore(); // the 'old' request is not relevant any more
2277
0
            pDlg->StartExecuteAsync(
2278
0
                [pDlg, pWrtSh, pDateField, xRequest=std::move(xRequest)] (sal_Int32 nResult)->void
2279
0
                {
2280
0
                    if (nResult == RET_OK)
2281
0
                    {
2282
0
                        pDlg->Apply();
2283
0
                        pDateField->Invalidate();
2284
0
                        pWrtSh->InvalidateWindows( SwRect(pWrtSh->GetView().GetVisArea()) );
2285
0
                        pWrtSh->UpdateCursor(); // cursor position might be invalid
2286
0
                    }
2287
0
                    pDlg->disposeOnce();
2288
0
                    xRequest->Done();
2289
0
                }
2290
0
            );
2291
0
        }
2292
0
        else
2293
0
        {
2294
0
            SfxRequest aReq(GetView().GetViewFrame(), SID_FM_CTL_PROPERTIES);
2295
0
            aReq.AppendItem( SfxBoolItem( SID_FM_CTL_PROPERTIES, true ) );
2296
0
            rWrtSh.GetView().GetFormShell()->Execute( aReq );
2297
0
        }
2298
0
    }
2299
0
    break;
2300
0
    case SID_FM_TRANSLATE:
2301
0
    {
2302
0
#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
2303
0
        const SfxPoolItem* pTargetLangStringItem = nullptr;
2304
0
        if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TARGETLANG_STR, false, &pTargetLangStringItem))
2305
0
        {
2306
0
            std::optional<OUString> oDeeplAPIUrl = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get();
2307
0
            std::optional<OUString> oDeeplKey = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get();
2308
0
            if (!oDeeplAPIUrl || oDeeplAPIUrl->isEmpty() || !oDeeplKey || oDeeplKey->isEmpty())
2309
0
            {
2310
0
                SAL_WARN("sw.ui", "SID_FM_TRANSLATE: API options are not set");
2311
0
                break;
2312
0
            }
2313
0
            const OString aAPIUrl = OUStringToOString(rtl::Concat2View(*oDeeplAPIUrl + "?tag_handling=html"), RTL_TEXTENCODING_UTF8).trim();
2314
0
            const OString aAuthKey = OUStringToOString(*oDeeplKey, RTL_TEXTENCODING_UTF8).trim();
2315
0
            OString aTargetLang = OUStringToOString(static_cast<const SfxStringItem*>(pTargetLangStringItem)->GetValue(), RTL_TEXTENCODING_UTF8);
2316
0
            SwTranslateHelper::TranslateAPIConfig aConfig({aAPIUrl, aAuthKey, aTargetLang});
2317
0
            SwTranslateHelper::TranslateDocument(rWrtSh, aConfig);
2318
0
        }
2319
0
        else
2320
0
        {
2321
0
            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2322
0
            std::shared_ptr<AbstractSwTranslateLangSelectDlg> pAbstractDialog(pFact->CreateSwTranslateLangSelectDlg(GetView().GetFrameWeld(), rWrtSh));
2323
0
            std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController());
2324
0
            weld::DialogController::runAsync(pDialogController, [] (sal_Int32 /*nResult*/) { });
2325
0
        }
2326
0
#endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA
2327
0
    }
2328
0
    break;
2329
0
    case SID_SPELLCHECK_IGNORE:
2330
0
    {
2331
0
        SwPaM *pPaM = rWrtSh.GetCursor();
2332
0
        if (pPaM)
2333
0
            SwEditShell::IgnoreGrammarErrorAt( *pPaM );
2334
0
    }
2335
0
    break;
2336
0
    case SID_SPELLCHECK_IGNORE_ALL:
2337
0
    {
2338
0
        OUString sApplyText;
2339
0
        const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
2340
0
        if (pItem2)
2341
0
            sApplyText = pItem2->GetValue();
2342
2343
0
        if(sApplyText == "Grammar")
2344
0
        {
2345
0
            linguistic2::ProofreadingResult aGrammarCheckRes;
2346
0
            sal_Int32 nErrorInResult = -1;
2347
0
            uno::Sequence< OUString > aSuggestions;
2348
0
            sal_Int32 nErrorPosInText = -1;
2349
0
            SwRect aToFill;
2350
0
            bool bCorrectionRes = rWrtSh.GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, nullptr, aToFill );
2351
0
            if(bCorrectionRes)
2352
0
            {
2353
0
                try {
2354
0
                    uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList();
2355
0
                    aGrammarCheckRes.xProofreader->ignoreRule(
2356
0
                        aGrammarCheckRes.aErrors[ nErrorInResult ].aRuleIdentifier,
2357
0
                            aGrammarCheckRes.aLocale );
2358
                    // refresh the layout of the actual paragraph (faster)
2359
0
                    SwPaM *pPaM = rWrtSh.GetCursor();
2360
0
                    if (pPaM)
2361
0
                        SwEditShell::IgnoreGrammarErrorAt( *pPaM );
2362
0
                    if (xDictionary.is() && pPaM)
2363
0
                    {
2364
0
                        linguistic::AddEntryToDic( xDictionary, pPaM->GetText(), false, OUString() );
2365
                        // refresh the layout of all paragraphs (workaround to launch a dictionary event)
2366
0
                        xDictionary->setActive(false);
2367
0
                        xDictionary->setActive(true);
2368
0
                    }
2369
0
                }
2370
0
                catch( const uno::Exception& )
2371
0
                {
2372
0
                }
2373
0
            }
2374
0
        }
2375
0
        else if (sApplyText == "Spelling")
2376
0
        {
2377
0
            AddWordToWordbook(LinguMgr::GetIgnoreAllList(), rWrtSh);
2378
0
        }
2379
0
    }
2380
0
    break;
2381
0
    case SID_ADD_TO_WORDBOOK:
2382
0
    {
2383
0
        OUString aDicName;
2384
0
        if (const SfxStringItem* pItem1 = rReq.GetArg<SfxStringItem>(FN_PARAM_1))
2385
0
            aDicName = pItem1->GetValue();
2386
2387
0
        uno::Reference<linguistic2::XSearchableDictionaryList> xDicList(LinguMgr::GetDictionaryList());
2388
0
        uno::Reference<linguistic2::XDictionary> xDic = xDicList.is() ? xDicList->getDictionaryByName(aDicName) : nullptr;
2389
0
        if (AddWordToWordbook(xDic, rWrtSh))
2390
0
        {
2391
            // save modified user-dictionary if it is persistent
2392
0
            uno::Reference<frame::XStorable> xSavDic(xDic, uno::UNO_QUERY);
2393
0
            if (xSavDic.is())
2394
0
                xSavDic->store();
2395
0
        }
2396
0
        break;
2397
0
    }
2398
0
    break;
2399
0
    case SID_SPELLCHECK_APPLY_SUGGESTION:
2400
0
    {
2401
0
        OUString sApplyText;
2402
0
        const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
2403
0
        if (pItem2)
2404
0
            sApplyText = pItem2->GetValue();
2405
2406
0
        static constexpr OUString sSpellingRule(u"Spelling_"_ustr);
2407
0
        static constexpr OUString sGrammarRule(u"Grammar_"_ustr);
2408
2409
0
        bool bGrammar = false;
2410
0
        sal_Int32 nPos = 0;
2411
0
        uno::Reference< linguistic2::XSpellAlternatives >  xSpellAlt;
2412
0
        if(-1 != (nPos = sApplyText.indexOf( sGrammarRule )))
2413
0
        {
2414
0
            sApplyText = sApplyText.replaceAt(nPos, sGrammarRule.getLength(), u"");
2415
0
            bGrammar = true;
2416
0
        }
2417
0
        else if (-1 != (nPos = sApplyText.indexOf( sSpellingRule )))
2418
0
        {
2419
0
            sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), u"");
2420
0
            SwRect aToFill;
2421
0
            xSpellAlt.set(rWrtSh.GetCorrection(nullptr, aToFill));
2422
0
            bGrammar = false;
2423
0
        }
2424
2425
0
        if (!bGrammar && !xSpellAlt.is())
2426
0
            return;
2427
2428
0
        bool bOldIns = rWrtSh.IsInsMode();
2429
0
        rWrtSh.SetInsMode();
2430
2431
0
        OUString aTmp( sApplyText );
2432
0
        OUString aOrig( bGrammar ? OUString() : xSpellAlt->getWord() );
2433
2434
        // if original word has a trailing . (likely the end of a sentence)
2435
        // and the replacement text hasn't, then add it to the replacement
2436
0
        if (!aTmp.isEmpty() && !aOrig.isEmpty() &&
2437
0
            aOrig.endsWith(".") && /* !IsAlphaNumeric ??*/
2438
0
            !aTmp.endsWith("."))
2439
0
        {
2440
0
            aTmp += ".";
2441
0
        }
2442
2443
0
        SwRewriter aRewriter;
2444
2445
0
        aRewriter.AddRule(UndoArg1, rWrtSh.GetCursorDescr()
2446
            // don't show the hidden control character of the comment
2447
0
            .replaceAll(OUStringChar(CH_TXTATR_INWORD), "") );
2448
0
        aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
2449
2450
0
        OUString aTmpStr = SwResId(STR_START_QUOTE) +
2451
0
            aTmp + SwResId(STR_END_QUOTE);
2452
0
        aRewriter.AddRule(UndoArg3, aTmpStr);
2453
2454
0
        rWrtSh.StartUndo(SwUndoId::UI_REPLACE, &aRewriter);
2455
0
        rWrtSh.StartAction();
2456
2457
        // keep comments at the end of the replacement in case spelling correction is
2458
        // invoked via the context menu. The spell check dialog does the correction in edlingu.cxx.
2459
0
        rWrtSh.ReplaceKeepComments(aTmp);
2460
2461
0
        rWrtSh.EndAction();
2462
0
        rWrtSh.EndUndo();
2463
2464
0
        rWrtSh.SetInsMode( bOldIns );
2465
0
    }
2466
0
    break;
2467
0
        case FN_TRANSFORM_DOCUMENT_STRUCTURE:
2468
0
        {
2469
            // get the parameter, what to transform
2470
0
            OUString aDataJson;
2471
0
            const SfxStringItem* pDataJson = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
2472
0
            if (pDataJson)
2473
0
            {
2474
0
                aDataJson = pDataJson->GetValue();
2475
0
                aDataJson = rtl::Uri::decode(aDataJson, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8);
2476
0
            }
2477
2478
            // parse the JSON got prom parameter
2479
0
            boost::property_tree::ptree aTree;
2480
0
            std::stringstream aStream(
2481
0
                (std::string(OUStringToOString(aDataJson, RTL_TEXTENCODING_UTF8))));
2482
0
            try
2483
0
            {
2484
0
                boost::property_tree::read_json(aStream, aTree);
2485
0
            }
2486
0
            catch (...)
2487
0
            {
2488
0
                lcl_LogWarning("FillApi Transform parameter, Wrong JSON format. ");
2489
0
                throw;
2490
0
            }
2491
2492
            // get the loaded content controls
2493
0
            uno::Reference<text::XContentControlsSupplier> xCCSupplier(
2494
0
                GetView().GetDocShell()->GetModel(), uno::UNO_QUERY);
2495
0
            if (!xCCSupplier.is())
2496
0
                break;
2497
2498
0
            uno::Reference<container::XIndexAccess> xContentControls
2499
0
                = xCCSupplier->getContentControls();
2500
0
            int iCCcount = xContentControls->getCount();
2501
2502
0
            enum class ContentFilterType
2503
0
            {
2504
0
                ERROR = -1,
2505
0
                INDEX,
2506
0
                TAG,
2507
0
                ALIAS,
2508
0
                ID
2509
0
            };
2510
0
            std::vector<std::string> aIdTexts = { ".ByIndex.", ".ByTag.", ".ByAlias.", ".ById." };
2511
2512
            // get charts
2513
0
            uno::Reference<text::XTextEmbeddedObjectsSupplier> xEOS(
2514
0
                GetView().GetDocShell()->GetModel(), uno::UNO_QUERY);
2515
0
            if (!xEOS.is())
2516
0
                break;
2517
0
            uno::Reference<container::XIndexAccess> xEmbeddeds(xEOS->getEmbeddedObjects(),
2518
0
                                                               uno::UNO_QUERY);
2519
0
            if (!xEmbeddeds.is())
2520
0
                break;
2521
2522
0
            sal_Int32 nEOcount = xEmbeddeds->getCount();
2523
2524
0
            enum class ChartFilterType
2525
0
            {
2526
0
                ERROR = -1,
2527
0
                INDEX,
2528
0
                NAME,
2529
0
                TITLE,
2530
0
                SUBTITLE
2531
0
            };
2532
0
            std::vector<std::string> aIdChartTexts
2533
0
                = { ".ByEmbedIndex.", ".ByEmbedName.", ".ByTitle.", ".BySubTitle." };
2534
2535
            // Iterate through the JSON data loaded into a tree structure
2536
0
            for (const auto& aItem : aTree)
2537
0
            {
2538
0
                if (aItem.first == "Transforms")
2539
0
                {
2540
                    // Handle all transformations
2541
0
                    for (const auto& aItem2Obj : aItem.second)
2542
0
                    {
2543
                        // handle `"Transforms": { `  and `"Transforms": [` cases as well
2544
                        // if an element is an object `{...}`, then get the first element of the object
2545
0
                        const auto& aItem2
2546
0
                            = aItem2Obj.first == "" ? *aItem2Obj.second.ordered_begin() : aItem2Obj;
2547
2548
0
                        if (aItem2.first == "DocumentProperties")
2549
0
                        {
2550
0
                            uno::Reference<document::XDocumentPropertiesSupplier>
2551
0
                                xDocumentPropsSupplier(GetView().GetDocShell()->GetModel(),
2552
0
                                                       uno::UNO_QUERY);
2553
0
                            if (!xDocumentPropsSupplier.is())
2554
0
                                continue;
2555
0
                            uno::Reference<document::XDocumentProperties2> xDocProps(
2556
0
                                xDocumentPropsSupplier->getDocumentProperties(), uno::UNO_QUERY);
2557
0
                            if (!xDocProps.is())
2558
0
                                continue;
2559
2560
0
                            for (const auto& aItem3 : aItem2.second)
2561
0
                            {
2562
0
                                if (aItem3.first == "Author")
2563
0
                                {
2564
0
                                    xDocProps->setAuthor(
2565
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2566
0
                                                          RTL_TEXTENCODING_UTF8));
2567
0
                                }
2568
0
                                else if (aItem3.first == "Generator")
2569
0
                                {
2570
0
                                    xDocProps->setGenerator(
2571
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2572
0
                                                          RTL_TEXTENCODING_UTF8));
2573
0
                                }
2574
0
                                else if (aItem3.first == "CreationDate")
2575
0
                                {
2576
0
                                    util::DateTime aDateTime;
2577
0
                                    sax::Converter::parseDateTime(
2578
0
                                        aDateTime,
2579
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2580
0
                                                          RTL_TEXTENCODING_UTF8));
2581
0
                                    xDocProps->setCreationDate(aDateTime);
2582
0
                                }
2583
0
                                else if (aItem3.first == "Title")
2584
0
                                {
2585
0
                                    xDocProps->setTitle(
2586
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2587
0
                                                          RTL_TEXTENCODING_UTF8));
2588
0
                                }
2589
0
                                else if (aItem3.first == "Subject")
2590
0
                                {
2591
0
                                    xDocProps->setSubject(
2592
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2593
0
                                                          RTL_TEXTENCODING_UTF8));
2594
0
                                }
2595
0
                                else if (aItem3.first == "Description")
2596
0
                                {
2597
0
                                    xDocProps->setDescription(
2598
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2599
0
                                                          RTL_TEXTENCODING_UTF8));
2600
0
                                }
2601
0
                                else if (aItem3.first == "Keywords")
2602
0
                                {
2603
0
                                    uno::Sequence<OUString> aStringSeq(aItem3.second.size());
2604
0
                                    auto aStringArray = aStringSeq.getArray();
2605
0
                                    int nId = 0;
2606
0
                                    for (const auto& aItem4 : aItem3.second)
2607
0
                                    {
2608
0
                                        aStringArray[nId++] = OStringToOUString(aItem4.second.get_value<std::string>(),
2609
0
                                                          RTL_TEXTENCODING_UTF8);
2610
0
                                    }
2611
0
                                    xDocProps->setKeywords(aStringSeq);
2612
0
                                }
2613
0
                                else if (aItem3.first == "Language")
2614
0
                                {
2615
0
                                    OUString aLanguageStr
2616
0
                                        = OStringToOUString(aItem3.second.get_value<std::string>(),
2617
0
                                                            RTL_TEXTENCODING_UTF8);
2618
0
                                    lang::Locale aLanguageLang
2619
0
                                        = LanguageTag::convertToLocale(aLanguageStr);
2620
0
                                    xDocProps->setLanguage(aLanguageLang);
2621
0
                                }
2622
0
                                else if (aItem3.first == "ModifiedBy")
2623
0
                                {
2624
0
                                    xDocProps->setModifiedBy(
2625
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2626
0
                                                          RTL_TEXTENCODING_UTF8));
2627
0
                                }
2628
0
                                else if (aItem3.first == "ModificationDate")
2629
0
                                {
2630
0
                                    util::DateTime aDateTime;
2631
0
                                    sax::Converter::parseDateTime(
2632
0
                                        aDateTime,
2633
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2634
0
                                                          RTL_TEXTENCODING_UTF8));
2635
0
                                    xDocProps->setModificationDate(aDateTime);
2636
0
                                }
2637
0
                                else if (aItem3.first == "PrintedBy")
2638
0
                                {
2639
0
                                    xDocProps->setPrintedBy(
2640
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2641
0
                                                          RTL_TEXTENCODING_UTF8));
2642
0
                                }
2643
0
                                else if (aItem3.first == "PrintDate")
2644
0
                                {
2645
0
                                    util::DateTime aDateTime;
2646
0
                                    sax::Converter::parseDateTime(
2647
0
                                        aDateTime,
2648
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2649
0
                                                          RTL_TEXTENCODING_UTF8));
2650
0
                                    xDocProps->setPrintDate(aDateTime);
2651
0
                                }
2652
0
                                else if (aItem3.first == "TemplateName")
2653
0
                                {
2654
0
                                    xDocProps->setTemplateName(
2655
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2656
0
                                                          RTL_TEXTENCODING_UTF8));
2657
0
                                }
2658
0
                                else if (aItem3.first == "TemplateURL")
2659
0
                                {
2660
0
                                    xDocProps->setTemplateURL(
2661
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2662
0
                                                          RTL_TEXTENCODING_UTF8));
2663
0
                                }
2664
0
                                else if (aItem3.first == "TemplateDate")
2665
0
                                {
2666
0
                                    util::DateTime aDateTime;
2667
0
                                    sax::Converter::parseDateTime(
2668
0
                                        aDateTime,
2669
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2670
0
                                                          RTL_TEXTENCODING_UTF8));
2671
0
                                    xDocProps->setTemplateDate(aDateTime);
2672
0
                                }
2673
0
                                else if (aItem3.first == "AutoloadURL")
2674
0
                                {
2675
                                    // Warning: wrong data here, can freeze LO.
2676
0
                                    xDocProps->setAutoloadURL(
2677
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2678
0
                                                          RTL_TEXTENCODING_UTF8));
2679
0
                                }
2680
0
                                else if (aItem3.first == "AutoloadSecs")
2681
0
                                {
2682
                                    //sal_Int32
2683
0
                                    xDocProps->setAutoloadSecs(aItem3.second.get_value<int>());
2684
0
                                }
2685
0
                                else if (aItem3.first == "DefaultTarget")
2686
0
                                {
2687
0
                                    xDocProps->setDefaultTarget(
2688
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2689
0
                                                          RTL_TEXTENCODING_UTF8));
2690
0
                                }
2691
0
                                else if (aItem3.first == "DocumentStatistics")
2692
0
                                {
2693
0
                                    uno::Sequence<beans::NamedValue> aNamedValueSeq(
2694
0
                                        aItem3.second.size());
2695
0
                                    auto aNamedValueArray = aNamedValueSeq.getArray();
2696
0
                                    int nId = 0;
2697
0
                                    for (const auto& aItem4 : aItem3.second)
2698
0
                                    {
2699
0
                                        OUString aName = OStringToOUString(aItem4.first,
2700
0
                                                                           RTL_TEXTENCODING_UTF8);
2701
0
                                        sal_Int32 nValue = aItem4.second.get_value<int>();
2702
0
                                        aNamedValueArray[nId].Name = aName;
2703
0
                                        aNamedValueArray[nId].Value <<= nValue;
2704
0
                                        nId++;
2705
0
                                    }
2706
0
                                    xDocProps->setDocumentStatistics(aNamedValueSeq);
2707
0
                                }
2708
0
                                else if (aItem3.first == "EditingCycles")
2709
0
                                {
2710
                                    //sal_Int16
2711
0
                                    xDocProps->setEditingCycles(aItem3.second.get_value<int>());
2712
0
                                }
2713
0
                                else if (aItem3.first == "EditingDuration")
2714
0
                                {
2715
                                    //sal_Int32
2716
0
                                    xDocProps->setEditingDuration(aItem3.second.get_value<int>());
2717
0
                                }
2718
0
                                else if (aItem3.first == "Contributor")
2719
0
                                {
2720
0
                                    uno::Sequence<OUString> aStringSeq(aItem3.second.size());
2721
0
                                    auto aStringArray = aStringSeq.getArray();
2722
0
                                    int nId = 0;
2723
0
                                    for (const auto& aItem4 : aItem3.second)
2724
0
                                    {
2725
0
                                        aStringArray[nId++] = OStringToOUString(
2726
0
                                            aItem4.second.get_value<std::string>(),
2727
0
                                            RTL_TEXTENCODING_UTF8);
2728
0
                                    }
2729
0
                                    xDocProps->setContributor(aStringSeq);
2730
0
                                }
2731
0
                                else if (aItem3.first == "Coverage")
2732
0
                                {
2733
0
                                    xDocProps->setCoverage(
2734
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2735
0
                                                          RTL_TEXTENCODING_UTF8));
2736
0
                                }
2737
0
                                else if (aItem3.first == "Identifier")
2738
0
                                {
2739
0
                                    xDocProps->setIdentifier(
2740
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2741
0
                                                          RTL_TEXTENCODING_UTF8));
2742
0
                                }
2743
0
                                else if (aItem3.first == "Publisher")
2744
0
                                {
2745
0
                                    uno::Sequence<OUString> aStringSeq(aItem3.second.size());
2746
0
                                    auto aStringArray = aStringSeq.getArray();
2747
0
                                    int nId = 0;
2748
0
                                    for (const auto& aItem4 : aItem3.second)
2749
0
                                    {
2750
0
                                        aStringArray[nId++] = OStringToOUString(
2751
0
                                            aItem4.second.get_value<std::string>(),
2752
0
                                            RTL_TEXTENCODING_UTF8);
2753
0
                                    }
2754
0
                                    xDocProps->setPublisher(aStringSeq);
2755
0
                                }
2756
0
                                else if (aItem3.first == "Relation")
2757
0
                                {
2758
0
                                    uno::Sequence<OUString> aStringSeq(aItem3.second.size());
2759
0
                                    auto aStringArray = aStringSeq.getArray();
2760
0
                                    int nId = 0;
2761
0
                                    for (const auto& aItem4 : aItem3.second)
2762
0
                                    {
2763
0
                                        aStringArray[nId++] = OStringToOUString(
2764
0
                                            aItem4.second.get_value<std::string>(),
2765
0
                                            RTL_TEXTENCODING_UTF8);
2766
0
                                    }
2767
0
                                    xDocProps->setRelation(aStringSeq);
2768
0
                                }
2769
0
                                else if (aItem3.first == "Rights")
2770
0
                                {
2771
0
                                    xDocProps->setRights(
2772
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2773
0
                                                          RTL_TEXTENCODING_UTF8));
2774
0
                                }
2775
0
                                else if (aItem3.first == "Source")
2776
0
                                {
2777
0
                                    xDocProps->setSource(
2778
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2779
0
                                                          RTL_TEXTENCODING_UTF8));
2780
0
                                }
2781
0
                                else if (aItem3.first == "Type")
2782
0
                                {
2783
0
                                    xDocProps->setType(
2784
0
                                        OStringToOUString(aItem3.second.get_value<std::string>(),
2785
0
                                                          RTL_TEXTENCODING_UTF8));
2786
0
                                }
2787
0
                                else if (aItem3.first == "UserDefinedProperties")
2788
0
                                {
2789
0
                                    const uno::Reference<beans::XPropertyContainer> xUserProps
2790
0
                                        = xDocProps->getUserDefinedProperties();
2791
0
                                    if (!xUserProps.is())
2792
0
                                        continue;
2793
0
                                    uno::Reference<beans::XPropertyAccess> xUserPropsAccess(
2794
0
                                        xDocProps->getUserDefinedProperties(), uno::UNO_QUERY);
2795
0
                                    if (!xUserPropsAccess.is())
2796
0
                                        continue;
2797
2798
0
                                    for (const auto& aItem4Obj : aItem3.second)
2799
0
                                    {
2800
                                        // handle [{},{}...] case as well as {}...}
2801
0
                                        const auto& aItem4 = aItem4Obj.first == ""
2802
0
                                                                 ? *aItem4Obj.second.ordered_begin()
2803
0
                                                                 : aItem4Obj;
2804
2805
0
                                        if (aItem4.first == "Delete")
2806
0
                                        {
2807
0
                                            std::string aPropName
2808
0
                                                = aItem4.second.get_value<std::string>();
2809
0
                                            try
2810
0
                                            {
2811
0
                                                xUserProps->removeProperty(OStringToOUString(
2812
0
                                                    aPropName, RTL_TEXTENCODING_UTF8));
2813
0
                                            }
2814
0
                                            catch (...)
2815
0
                                            {
2816
0
                                                lcl_LogWarning("FillApi DocumentProperties "
2817
0
                                                               "UserDefinedPropertieschart, failed "
2818
0
                                                               "to delete property: '"
2819
0
                                                               + aPropName + "'");
2820
0
                                            }
2821
0
                                        }
2822
0
                                        else if (aItem4.first.starts_with("Add."))
2823
0
                                        {
2824
0
                                            std::string aPropName = aItem4.first.substr(4);
2825
2826
0
                                            comphelper::SequenceAsHashMap aUserDefinedProperties(
2827
0
                                                xUserPropsAccess->getPropertyValues());
2828
0
                                            comphelper::SequenceAsHashMap::iterator it
2829
0
                                                = aUserDefinedProperties.find(OStringToOUString(
2830
0
                                                    aPropName, RTL_TEXTENCODING_UTF8));
2831
0
                                            bool bToDelete = (it != aUserDefinedProperties.end());
2832
2833
0
                                            try
2834
0
                                            {
2835
0
                                                std::stringstream aStreamPart;
2836
0
                                                aStreamPart << "{\n\"" << aPropName << "\" : ";
2837
0
                                                boost::property_tree::json_parser::write_json(
2838
0
                                                    aStreamPart, aItem4.second);
2839
0
                                                aStreamPart << "}";
2840
2841
0
                                                OString aJSONPart(aStreamPart.str());
2842
0
                                                std::vector<beans::PropertyValue> aPropVec
2843
0
                                                    = comphelper::JsonToPropertyValues(aJSONPart);
2844
2845
0
                                                if (bToDelete)
2846
0
                                                    xUserProps->removeProperty(aPropVec[0].Name);
2847
2848
0
                                                xUserProps->addProperty(
2849
0
                                                    aPropVec[0].Name,
2850
0
                                                    beans::PropertyAttribute::REMOVABLE,
2851
0
                                                    aPropVec[0].Value);
2852
0
                                            }
2853
0
                                            catch(...)
2854
0
                                            {
2855
0
                                                lcl_LogWarning("FillApi DocumentProperties "
2856
0
                                                               "UserDefinedPropertieschart, failed "
2857
0
                                                               "to add property: '"
2858
0
                                                               + aPropName + "'");
2859
0
                                            }
2860
0
                                        }
2861
0
                                    }
2862
0
                                }
2863
0
                            }
2864
0
                        }
2865
0
                        if (aItem2.first.starts_with("Charts"))
2866
0
                        {
2867
0
                            std::string aTextEnd = aItem2.first.substr(6);
2868
0
                            std::string aValue = "";
2869
0
                            ChartFilterType iKeyId = ChartFilterType::ERROR;
2870
                            // Find how the chart is identified: ByIndex, ByTitle...
2871
0
                            for (size_t i = 0; i < aIdChartTexts.size(); i++)
2872
0
                            {
2873
0
                                if (aTextEnd.starts_with(aIdChartTexts[i]))
2874
0
                                {
2875
0
                                    iKeyId = static_cast<ChartFilterType>(i);
2876
0
                                    aValue = aTextEnd.substr(aIdChartTexts[i].length());
2877
0
                                    break;
2878
0
                                }
2879
0
                            }
2880
0
                            if (iKeyId != ChartFilterType::ERROR)
2881
0
                            {
2882
                                // A chart transformation filter can match multiple charts
2883
                                // In that case every matching charts will be transformed
2884
                                // If no chart match to the filter, then we show warning
2885
0
                                bool bChartFound = false;
2886
0
                                for (int i = 0; i < nEOcount; ++i)
2887
0
                                {
2888
0
                                    uno::Reference<beans::XPropertySet> xShapeProps(
2889
0
                                        xEmbeddeds->getByIndex(i), uno::UNO_QUERY);
2890
0
                                    if (!xShapeProps.is())
2891
0
                                        continue;
2892
2893
0
                                    uno::Reference<frame::XModel> xDocModel;
2894
0
                                    xShapeProps->getPropertyValue(u"Model"_ustr) >>= xDocModel;
2895
0
                                    if (!xDocModel.is())
2896
0
                                        continue;
2897
2898
0
                                    uno::Reference<chart2::XChartDocument> xChartDoc(
2899
0
                                        xDocModel, uno::UNO_QUERY);
2900
0
                                    if (!xChartDoc.is())
2901
0
                                        continue;
2902
2903
0
                                    uno::Reference<chart2::data::XDataProvider> xDataProvider(
2904
0
                                        xChartDoc->getDataProvider());
2905
0
                                    if (!xDataProvider.is())
2906
0
                                        continue;
2907
2908
0
                                    uno::Reference<chart::XChartDataArray> xDataArray(
2909
0
                                        xChartDoc->getDataProvider(), uno::UNO_QUERY);
2910
0
                                    if (!xDataArray.is())
2911
0
                                        continue;
2912
2913
0
                                    uno::Reference<chart2::XInternalDataProvider> xIDataProvider(
2914
0
                                        xChartDoc->getDataProvider(), uno::UNO_QUERY);
2915
0
                                    if (!xIDataProvider.is())
2916
0
                                        continue;
2917
2918
0
                                    uno::Reference<util::XModifiable> xModi(xDocModel,
2919
0
                                                                            uno::UNO_QUERY);
2920
0
                                    if (!xModi.is())
2921
0
                                        continue;
2922
2923
0
                                    switch (iKeyId)
2924
0
                                    {
2925
0
                                        case ChartFilterType::INDEX:
2926
0
                                        {
2927
0
                                            if (stoi(aValue) != i)
2928
0
                                                continue;
2929
0
                                        }
2930
0
                                        break;
2931
0
                                        case ChartFilterType::NAME:
2932
0
                                        {
2933
0
                                            uno::Reference<container::XNamed> xNamedShape(
2934
0
                                                xEmbeddeds->getByIndex(i), uno::UNO_QUERY);
2935
0
                                            if (xNamedShape.is())
2936
0
                                            {
2937
0
                                                OUString aName;
2938
0
                                                aName = xNamedShape->getName();
2939
0
                                                if (OStringToOUString(aValue, RTL_TEXTENCODING_UTF8)
2940
0
                                                    != aName)
2941
0
                                                    continue;
2942
0
                                            }
2943
0
                                        }
2944
0
                                        break;
2945
0
                                        case ChartFilterType::TITLE:
2946
0
                                        {
2947
0
                                            uno::Reference<chart2::XTitled> xTitled(
2948
0
                                                xChartDoc, uno::UNO_QUERY_THROW);
2949
0
                                            if (!xTitled.is())
2950
0
                                                continue;
2951
0
                                            uno::Reference<chart2::XTitle> xTitle
2952
0
                                                = xTitled->getTitleObject();
2953
0
                                            if (!xTitle.is())
2954
0
                                                continue;
2955
2956
0
                                            OUString aTitle;
2957
0
                                            const uno::Sequence<
2958
0
                                                uno::Reference<chart2::XFormattedString>>
2959
0
                                                aFSSeq = xTitle->getText();
2960
0
                                            for (auto const& fs : aFSSeq)
2961
0
                                                aTitle += fs->getString();
2962
0
                                            if (OStringToOUString(aValue, RTL_TEXTENCODING_UTF8)
2963
0
                                                != aTitle)
2964
0
                                                continue;
2965
0
                                        }
2966
0
                                        break;
2967
0
                                        case ChartFilterType::SUBTITLE:
2968
0
                                        {
2969
0
                                            uno::Reference<chart2::XDiagram> xDiagram
2970
0
                                                = xChartDoc->getFirstDiagram();
2971
0
                                            if (!xDiagram.is())
2972
0
                                                continue;
2973
2974
0
                                            uno::Reference<chart2::XTitled> xTitled(
2975
0
                                                xDiagram, uno::UNO_QUERY_THROW);
2976
0
                                            if (!xTitled.is())
2977
0
                                                continue;
2978
2979
0
                                            uno::Reference<chart2::XTitle> xSubTitle(
2980
0
                                                xTitled->getTitleObject());
2981
0
                                            if (!xSubTitle.is())
2982
0
                                                continue;
2983
2984
0
                                            OUString aSubTitle;
2985
0
                                            const uno::Sequence<
2986
0
                                                uno::Reference<chart2::XFormattedString>>
2987
0
                                                aFSSeq = xSubTitle->getText();
2988
0
                                            for (auto const& fs : aFSSeq)
2989
0
                                                aSubTitle += fs->getString();
2990
0
                                            if (OStringToOUString(aValue, RTL_TEXTENCODING_UTF8)
2991
0
                                                != aSubTitle)
2992
0
                                                continue;
2993
0
                                        }
2994
0
                                        break;
2995
0
                                        default:
2996
0
                                            continue;
2997
0
                                    }
2998
2999
                                    // We have a match, this chart need to be transformed
3000
                                    // Set all the values (of the chart) what is needed
3001
0
                                    bChartFound = true;
3002
3003
                                    // Check if the InternalDataProvider is row or column based.
3004
0
                                    bool bChartUseColumns = false;
3005
0
                                    uno::Sequence<beans::PropertyValue> aArguments(
3006
0
                                        xDataProvider->detectArguments(nullptr));
3007
0
                                    for (sal_Int32 j = 0; j < aArguments.getLength(); ++j)
3008
0
                                    {
3009
0
                                        if (aArguments[j].Name == "DataRowSource")
3010
0
                                        {
3011
0
                                            css::chart::ChartDataRowSource eRowSource;
3012
0
                                            if (aArguments[j].Value >>= eRowSource)
3013
0
                                                bChartUseColumns
3014
0
                                                    = (eRowSource
3015
0
                                                       == css::chart::ChartDataRowSource_COLUMNS);
3016
0
                                            break;
3017
0
                                        }
3018
0
                                    }
3019
3020
0
                                    for (const auto& aItem3Obj : aItem2.second)
3021
0
                                    {
3022
                                        //handle [] and {} cases
3023
0
                                        const auto& aItem3 = aItem3Obj.first == ""
3024
0
                                                                 ? *aItem3Obj.second.ordered_begin()
3025
0
                                                                 : aItem3Obj;
3026
3027
0
                                        if (aItem3.first.starts_with("deletecolumn.")
3028
0
                                            || aItem3.first.starts_with("deleterow.")
3029
0
                                            || aItem3.first.starts_with("insertcolumn.")
3030
0
                                            || aItem3.first.starts_with("insertrow.")
3031
0
                                            || aItem3.first.starts_with("modifycolumn.")
3032
0
                                            || aItem3.first.starts_with("modifyrow."))
3033
0
                                        {
3034
                                            // delete insert, or modify a row, or column
3035
                                            // column, or row?
3036
0
                                            bool bSetColumn = (aItem3.first[6] == 'c');
3037
0
                                            int nId = stoi(aItem3.first.substr(bSetColumn ? 13 : 10));
3038
0
                                            bool bDelete = aItem3.first.starts_with("delete");
3039
                                            // delete/insert a row/column if needed
3040
0
                                            if (!aItem3.first.starts_with("modify"))
3041
0
                                            {
3042
0
                                                if (bChartUseColumns == bSetColumn)
3043
0
                                                {
3044
0
                                                    if (bDelete)
3045
0
                                                    {
3046
0
                                                        if (!lcl_DeleteChartColumns(xChartDoc, nId))
3047
0
                                                            continue;
3048
0
                                                        xIDataProvider->deleteSequence(nId);
3049
0
                                                    }
3050
0
                                                    else
3051
0
                                                    {
3052
0
                                                        if (!lcl_InsertChartColumns(xChartDoc, nId))
3053
0
                                                            continue;
3054
0
                                                    }
3055
0
                                                }
3056
0
                                                else
3057
0
                                                {
3058
0
                                                    if (bDelete)
3059
0
                                                    {
3060
0
                                                        xIDataProvider
3061
0
                                                            ->deleteDataPointForAllSequences(nId);
3062
0
                                                    }
3063
0
                                                    else
3064
0
                                                    {
3065
0
                                                        xIDataProvider
3066
0
                                                            ->insertDataPointForAllSequences(nId
3067
0
                                                                                             - 1);
3068
0
                                                    }
3069
0
                                                }
3070
0
                                            }
3071
                                            // set values also, if needed
3072
0
                                            if (!bDelete && aItem3.second.size() > 0)
3073
0
                                            {
3074
0
                                                uno::Sequence<uno::Sequence<double>> aData
3075
0
                                                    = xDataArray->getData();
3076
0
                                                uno::Sequence<double>* pRows = aData.getArray();
3077
3078
0
                                                int nIndex = 0;
3079
0
                                                int nX = nId;
3080
0
                                                int nY = nId;
3081
0
                                                bool bIndexWarning = false;
3082
0
                                                for (const auto& aItem4 : aItem3.second)
3083
0
                                                {
3084
0
                                                    if (bSetColumn)
3085
0
                                                    {
3086
0
                                                        nY = nIndex;
3087
0
                                                    }
3088
0
                                                    else
3089
0
                                                    {
3090
0
                                                        nX = nIndex;
3091
0
                                                    }
3092
0
                                                    if (nY < aData.getLength() && nY >= 0
3093
0
                                                        && nX < pRows[nY].getLength() && nX >= 0)
3094
0
                                                    {
3095
0
                                                        double* pCols = pRows[nY].getArray();
3096
0
                                                        pCols[nX]
3097
0
                                                            = aItem4.second.get_value<double>();
3098
0
                                                    }
3099
0
                                                    else
3100
0
                                                    {
3101
0
                                                        bIndexWarning = true;
3102
0
                                                    }
3103
3104
0
                                                    nIndex++;
3105
0
                                                }
3106
0
                                                if (bIndexWarning)
3107
0
                                                {
3108
0
                                                    std::string sValues = "";
3109
0
                                                    for (const auto& atemp : aItem3.second)
3110
0
                                                    {
3111
0
                                                        if (sValues != "")
3112
0
                                                        {
3113
0
                                                            sValues += ", ";
3114
0
                                                        }
3115
0
                                                        sValues += atemp.second
3116
0
                                                                       .get_value<std::string>();
3117
0
                                                    }
3118
0
                                                    lcl_LogWarning(
3119
0
                                                        "FillApi chart: Invalid Cell Index at: '"
3120
0
                                                        + aItem3.first + ": " + sValues
3121
0
                                                        + "' (probably too many parameters)");
3122
0
                                                }
3123
3124
0
                                                xDataArray->setData(aData);
3125
0
                                            }
3126
0
                                        }
3127
0
                                        else if (aItem3.first.starts_with("setrowdesc"))
3128
0
                                        {
3129
                                            // set row descriptions
3130
0
                                            uno::Sequence<OUString> aRowDesc
3131
0
                                                = xDataArray->getRowDescriptions();
3132
0
                                            OUString* aRowdata = aRowDesc.getArray();
3133
3134
0
                                            if (aItem3.first.starts_with("setrowdesc."))
3135
0
                                            {
3136
                                                // set only 1 description
3137
0
                                                int nValue = stoi(aItem3.first.substr(11));
3138
0
                                                if (nValue >= 0 && nValue < aRowDesc.getLength())
3139
0
                                                {
3140
0
                                                    aRowdata[nValue] = OStringToOUString(
3141
0
                                                        aItem3.second.get_value<std::string>(),
3142
0
                                                        RTL_TEXTENCODING_UTF8);
3143
0
                                                }
3144
0
                                                else
3145
0
                                                {
3146
0
                                                    lcl_LogWarning("FillApi chart setrowdesc: "
3147
0
                                                                   "invalid Index at: '"
3148
0
                                                                   + aItem3.first + "'");
3149
0
                                                }
3150
0
                                            }
3151
0
                                            else
3152
0
                                            {
3153
                                                // set an array of description at once
3154
0
                                                int nIndex = 0;
3155
0
                                                for (const auto& aItem4 : aItem3.second)
3156
0
                                                {
3157
0
                                                    if (nIndex >= aRowDesc.getLength())
3158
0
                                                    {
3159
0
                                                        lcl_LogWarning("FillApi chart setrowdesc: "
3160
0
                                                                       "too many params");
3161
0
                                                        break;
3162
0
                                                    }
3163
0
                                                    aRowdata[nIndex] = OStringToOUString(
3164
0
                                                        aItem4.second.get_value<std::string>(),
3165
0
                                                        RTL_TEXTENCODING_UTF8);
3166
0
                                                    nIndex++;
3167
0
                                                }
3168
0
                                            }
3169
0
                                            xDataArray->setRowDescriptions(aRowDesc);
3170
0
                                        }
3171
0
                                        else if (aItem3.first.starts_with("setcolumndesc"))
3172
0
                                        {
3173
                                            // set column descriptions
3174
0
                                            uno::Sequence<OUString> aColDesc
3175
0
                                                = xDataArray->getColumnDescriptions();
3176
0
                                            OUString* aColdata = aColDesc.getArray();
3177
3178
0
                                            if (aItem3.first.starts_with("setcolumndesc."))
3179
0
                                            {
3180
0
                                                int nValue = stoi(aItem3.first.substr(14));
3181
0
                                                if (nValue >= 0 && nValue < aColDesc.getLength())
3182
0
                                                {
3183
0
                                                    aColdata[nValue] = OStringToOUString(
3184
0
                                                        aItem3.second.get_value<std::string>(),
3185
0
                                                        RTL_TEXTENCODING_UTF8);
3186
0
                                                }
3187
0
                                                else
3188
0
                                                {
3189
0
                                                    lcl_LogWarning("FillApi chart setcolumndesc: "
3190
0
                                                                   "invalid Index at: '"
3191
0
                                                                   + aItem3.first + "'");
3192
0
                                                }
3193
0
                                            }
3194
0
                                            else
3195
0
                                            {
3196
0
                                                int nIndex = 0;
3197
0
                                                for (const auto& aItem4 : aItem3.second)
3198
0
                                                {
3199
0
                                                    if (nIndex >= aColDesc.getLength())
3200
0
                                                    {
3201
0
                                                        lcl_LogWarning(
3202
0
                                                            "FillApi chart setcolumndesc:"
3203
0
                                                            " too many parameters");
3204
0
                                                        break;
3205
0
                                                    }
3206
0
                                                    aColdata[nIndex] = OStringToOUString(
3207
0
                                                        aItem4.second.get_value<std::string>(),
3208
0
                                                        RTL_TEXTENCODING_UTF8);
3209
0
                                                    nIndex++;
3210
0
                                                }
3211
0
                                            }
3212
0
                                            xDataArray->setColumnDescriptions(aColDesc);
3213
0
                                        }
3214
0
                                        else if (aItem3.first.starts_with("resize"))
3215
0
                                        {
3216
0
                                            if (aItem3.second.size() >= 2)
3217
0
                                            {
3218
0
                                                auto aItem4 = aItem3.second.begin();
3219
0
                                                int nY = aItem4->second.get_value<int>();
3220
0
                                                int nX = (++aItem4)->second.get_value<int>();
3221
3222
0
                                                if (nX < 1 || nY < 1)
3223
0
                                                {
3224
0
                                                    lcl_LogWarning(
3225
0
                                                        "FillApi chart resize: wrong param"
3226
0
                                                        " (Needed: x,y >= 1)");
3227
0
                                                    continue;
3228
0
                                                }
3229
                                                // here we need to use the new insert column thing
3230
0
                                                if (!lcl_ResizeChartColumns(xChartDoc, nX))
3231
0
                                                    continue;
3232
3233
0
                                                uno::Sequence<uno::Sequence<double>> aData
3234
0
                                                    = xDataArray->getData();
3235
0
                                                if (aData.getLength() != nY)
3236
0
                                                    aData.realloc(nY);
3237
3238
0
                                                for (sal_Int32 j = 0; j < nY; ++j)
3239
0
                                                {
3240
0
                                                    uno::Sequence<double>* pRows = aData.getArray();
3241
                                                    // resize row if needed
3242
0
                                                    if (pRows[j].getLength() != nX)
3243
0
                                                    {
3244
0
                                                        pRows[j].realloc(nX);
3245
0
                                                    }
3246
0
                                                }
3247
0
                                                xDataArray->setData(aData);
3248
0
                                            }
3249
0
                                            else
3250
0
                                            {
3251
0
                                                lcl_LogWarning(
3252
0
                                                    "FillApi chart resize: not enough parameters"
3253
0
                                                    " (x,y is needed)");
3254
0
                                            }
3255
0
                                        }
3256
0
                                        else if (aItem3.first.starts_with("data"))
3257
0
                                        {
3258
                                            // set table data values
3259
0
                                            uno::Sequence<uno::Sequence<double>> aData
3260
0
                                                = xDataArray->getData();
3261
3262
                                            // set only 1 cell data
3263
0
                                            if (aItem3.first.starts_with("datayx."))
3264
0
                                            {
3265
0
                                                int nPoint = aItem3.first.find('.', 7);
3266
0
                                                int nY = stoi(aItem3.first.substr(7, nPoint - 7));
3267
0
                                                int nX = stoi(aItem3.first.substr(nPoint + 1));
3268
0
                                                bool bValidIndex = false;
3269
0
                                                if (nY < aData.getLength() && nY >= 0)
3270
0
                                                {
3271
0
                                                    uno::Sequence<double>* pRows = aData.getArray();
3272
0
                                                    if (nX < pRows[nY].getLength() && nX >= 0)
3273
0
                                                    {
3274
0
                                                        double* pCols = pRows[nY].getArray();
3275
0
                                                        pCols[nX]
3276
0
                                                            = aItem3.second.get_value<double>();
3277
0
                                                        bValidIndex = true;
3278
0
                                                    }
3279
0
                                                }
3280
0
                                                if (!bValidIndex)
3281
0
                                                {
3282
0
                                                    lcl_LogWarning(
3283
0
                                                        "FillApi chart datayx: invalid Index at: '"
3284
0
                                                        + aItem3.first + "'");
3285
0
                                                }
3286
0
                                            }
3287
0
                                            else
3288
0
                                            {
3289
                                                // set the whole data table
3290
                                                // resize if needed
3291
0
                                                int nRowsCount = aItem3.second.size();
3292
0
                                                int nColsCount = 0;
3293
3294
0
                                                for (const auto& aItem4 : aItem3.second)
3295
0
                                                {
3296
0
                                                    if (nColsCount
3297
0
                                                        < static_cast<int>(aItem4.second.size()))
3298
0
                                                    {
3299
0
                                                        nColsCount = aItem4.second.size();
3300
0
                                                    }
3301
0
                                                }
3302
3303
0
                                                if (nColsCount > 0)
3304
0
                                                {
3305
                                                    // here we need to use the new insert column thing
3306
0
                                                    if(!lcl_ResizeChartColumns(xChartDoc, nColsCount))
3307
0
                                                        continue;
3308
3309
0
                                                    if (aData.getLength() != nRowsCount)
3310
0
                                                        aData.realloc(nRowsCount);
3311
3312
                                                    // set all the rows
3313
0
                                                    sal_Int32 nY = 0;
3314
0
                                                    for (const auto& aItem4 : aItem3.second)
3315
0
                                                    {
3316
0
                                                        uno::Sequence<double>* pRows
3317
0
                                                            = aData.getArray();
3318
                                                        // resize row if needed
3319
0
                                                        if (pRows[nY].getLength() != nColsCount)
3320
0
                                                        {
3321
0
                                                            pRows[nY].realloc(nColsCount);
3322
0
                                                        }
3323
0
                                                        double* pCols = pRows[nY].getArray();
3324
                                                        // set all values in the row
3325
0
                                                        sal_Int32 nX = 0;
3326
0
                                                        for (const auto& aItem5 : aItem4.second)
3327
0
                                                        {
3328
0
                                                            if (nX >= nColsCount)
3329
0
                                                            {
3330
                                                                // This should never happen
3331
0
                                                                break;
3332
0
                                                            }
3333
0
                                                            pCols[nX]
3334
0
                                                                = aItem5.second.get_value<double>();
3335
0
                                                            nX++;
3336
0
                                                        }
3337
0
                                                        nY++;
3338
0
                                                    }
3339
0
                                                }
3340
0
                                            }
3341
0
                                            xDataArray->setData(aData);
3342
0
                                        }
3343
0
                                        else
3344
0
                                        {
3345
0
                                            lcl_LogWarning("FillApi chart command not recognised: '"
3346
0
                                                           + aItem3.first + "'");
3347
0
                                        }
3348
0
                                        xModi->setModified(true);
3349
0
                                    }
3350
0
                                }
3351
0
                                if (!bChartFound)
3352
0
                                {
3353
0
                                    lcl_LogWarning("FillApi: No chart match the filter: '"
3354
0
                                                   + aItem2.first + "'");
3355
0
                                }
3356
0
                            }
3357
0
                            else
3358
0
                            {
3359
0
                                lcl_LogWarning("FillApi chart filter type not recognised: '"
3360
0
                                               + aItem2.first + "'");
3361
0
                            }
3362
0
                        }
3363
3364
0
                        if (aItem2.first.starts_with("ContentControls"))
3365
0
                        {
3366
0
                            std::string aTextEnd = aItem2.first.substr(15);
3367
0
                            std::string aValue = "";
3368
0
                            ContentFilterType iKeyId = ContentFilterType::ERROR;
3369
                            // Find how the content control is identified: ByIndex, ByAlias...
3370
0
                            for (size_t i = 0; i < aIdTexts.size(); i++)
3371
0
                            {
3372
0
                                if (aTextEnd.starts_with(aIdTexts[i]))
3373
0
                                {
3374
0
                                    iKeyId = static_cast<ContentFilterType>(i);
3375
0
                                    aValue = aTextEnd.substr(aIdTexts[i].length());
3376
0
                                    break;
3377
0
                                }
3378
0
                            }
3379
0
                            if (iKeyId != ContentFilterType::ERROR)
3380
0
                            {
3381
                                // Check all the content controls, if they match
3382
0
                                bool bCCFound = false;
3383
0
                                for (int i = 0; i < iCCcount; ++i)
3384
0
                                {
3385
0
                                    uno::Reference<text::XTextContent> xContentControl;
3386
0
                                    xContentControls->getByIndex(i) >>= xContentControl;
3387
3388
0
                                    uno::Reference<beans::XPropertySet> xContentControlProps(
3389
0
                                        xContentControl, uno::UNO_QUERY);
3390
0
                                    if (!xContentControlProps.is())
3391
0
                                        continue;
3392
3393
                                    // Compare the loaded and the actual identifier
3394
0
                                    switch (iKeyId)
3395
0
                                    {
3396
0
                                        case ContentFilterType::INDEX:
3397
0
                                        {
3398
0
                                            if (stoi(aValue) != i)
3399
0
                                                continue;
3400
0
                                        }
3401
0
                                        break;
3402
0
                                        case ContentFilterType::ID:
3403
0
                                        {
3404
0
                                            sal_Int32 iID = -1;
3405
0
                                            xContentControlProps->getPropertyValue(UNO_NAME_ID)
3406
0
                                                >>= iID;
3407
0
                                            if (stoi(aValue) != iID)
3408
0
                                                continue;
3409
0
                                        }
3410
0
                                        break;
3411
0
                                        case ContentFilterType::ALIAS:
3412
0
                                        {
3413
0
                                            OUString aAlias;
3414
0
                                            xContentControlProps->getPropertyValue(UNO_NAME_ALIAS)
3415
0
                                                >>= aAlias;
3416
0
                                            if (OStringToOUString(aValue, RTL_TEXTENCODING_UTF8)
3417
0
                                                != aAlias)
3418
0
                                                continue;
3419
0
                                        }
3420
0
                                        break;
3421
0
                                        case ContentFilterType::TAG:
3422
0
                                        {
3423
0
                                            OUString aTag;
3424
0
                                            xContentControlProps->getPropertyValue(UNO_NAME_TAG)
3425
0
                                                >>= aTag;
3426
0
                                            if (OStringToOUString(aValue, RTL_TEXTENCODING_UTF8)
3427
0
                                                != aTag)
3428
0
                                                continue;
3429
0
                                        }
3430
0
                                        break;
3431
0
                                        default:
3432
0
                                            continue;
3433
0
                                    }
3434
3435
                                    // We have a match, this content control need to be transformed
3436
                                    // Set all the values (of the content control) what is needed
3437
0
                                    bCCFound = true;
3438
0
                                    for (const auto& aItem3 : aItem2.second)
3439
0
                                    {
3440
0
                                        if (aItem3.first == "content")
3441
0
                                        {
3442
0
                                            std::string aContent
3443
0
                                                = aItem3.second.get_value<std::string>();
3444
3445
0
                                            uno::Reference<text::XText> xContentControlText(
3446
0
                                                xContentControl, uno::UNO_QUERY);
3447
0
                                            if (!xContentControlText.is())
3448
0
                                                continue;
3449
3450
0
                                            xContentControlText->setString(
3451
0
                                                OStringToOUString(aContent, RTL_TEXTENCODING_UTF8));
3452
3453
0
                                            sal_Int32 iType = 0;
3454
0
                                            xContentControlProps->getPropertyValue(
3455
0
                                                UNO_NAME_CONTENT_CONTROL_TYPE)
3456
0
                                                >>= iType;
3457
0
                                            SwContentControlType aType
3458
0
                                                = static_cast<SwContentControlType>(iType);
3459
3460
                                            // if we set the content of a checkbox, then we
3461
                                            // also set the checked state based on the content
3462
0
                                            if (aType == SwContentControlType::CHECKBOX)
3463
0
                                            {
3464
0
                                                OUString aCheckedContent;
3465
0
                                                xContentControlProps->getPropertyValue(
3466
0
                                                    UNO_NAME_CHECKED_STATE)
3467
0
                                                    >>= aCheckedContent;
3468
0
                                                bool bChecked = false;
3469
0
                                                if (aCheckedContent
3470
0
                                                    == OStringToOUString(
3471
0
                                                        aItem3.second.get_value<std::string>(),
3472
0
                                                        RTL_TEXTENCODING_UTF8))
3473
0
                                                    bChecked = true;
3474
0
                                                xContentControlProps->setPropertyValue(
3475
0
                                                    UNO_NAME_CHECKED, uno::Any(bChecked));
3476
0
                                            }
3477
0
                                            else if (aType == SwContentControlType::PLAIN_TEXT
3478
0
                                                     || aType == SwContentControlType::RICH_TEXT
3479
0
                                                     || aType == SwContentControlType::DATE
3480
0
                                                     || aType == SwContentControlType::COMBO_BOX
3481
0
                                                     || aType
3482
0
                                                            == SwContentControlType::DROP_DOWN_LIST)
3483
0
                                            {
3484
                                                // Set the placeholder
3485
0
                                                bool bPlaceHolder = aContent == "" ? true : false;
3486
0
                                                xContentControlProps->setPropertyValue(
3487
0
                                                    UNO_NAME_SHOWING_PLACE_HOLDER,
3488
0
                                                    uno::Any(bPlaceHolder));
3489
0
                                                if (bPlaceHolder)
3490
0
                                                {
3491
0
                                                    OUString aPlaceHolderText;
3492
0
                                                    switch (aType)
3493
0
                                                    {
3494
0
                                                        case SwContentControlType::PLAIN_TEXT:
3495
0
                                                        case SwContentControlType::RICH_TEXT:
3496
0
                                                        {
3497
0
                                                            aPlaceHolderText = SwResId(
3498
0
                                                                STR_CONTENT_CONTROL_PLACEHOLDER);
3499
0
                                                        }
3500
0
                                                        break;
3501
0
                                                        case SwContentControlType::COMBO_BOX:
3502
0
                                                        case SwContentControlType::DROP_DOWN_LIST:
3503
0
                                                        {
3504
0
                                                            aPlaceHolderText = SwResId(
3505
0
                                                                STR_DROPDOWN_CONTENT_CONTROL_PLACEHOLDER);
3506
0
                                                        }
3507
0
                                                        break;
3508
0
                                                        case SwContentControlType::DATE:
3509
0
                                                        {
3510
0
                                                            aPlaceHolderText = SwResId(
3511
0
                                                                STR_DATE_CONTENT_CONTROL_PLACEHOLDER);
3512
0
                                                        }
3513
0
                                                        break;
3514
0
                                                        default: // do nothing for picture and checkbox
3515
0
                                                        break;
3516
0
                                                    }
3517
0
                                                    if (!aPlaceHolderText.isEmpty())
3518
0
                                                        xContentControlText->setString(
3519
0
                                                            aPlaceHolderText);
3520
0
                                                }
3521
0
                                            }
3522
0
                                        }
3523
0
                                        else if (aItem3.first == "checked")
3524
0
                                        {
3525
0
                                            bool bChecked
3526
0
                                                = (aItem3.second.get_value<std::string>() == "true")
3527
0
                                                      ? true
3528
0
                                                      : false;
3529
0
                                            xContentControlProps->setPropertyValue(
3530
0
                                                UNO_NAME_CHECKED,
3531
0
                                                uno::Any(bChecked));
3532
3533
0
                                            OUString aCheckContent;
3534
0
                                            xContentControlProps->getPropertyValue(
3535
0
                                                bChecked ? UNO_NAME_CHECKED_STATE
3536
0
                                                         : UNO_NAME_UNCHECKED_STATE)
3537
0
                                                >>= aCheckContent;
3538
0
                                            uno::Reference<text::XText> xContentControlText(
3539
0
                                                xContentControl, uno::UNO_QUERY);
3540
0
                                            if (!xContentControlText.is())
3541
0
                                                continue;
3542
0
                                            xContentControlText->setString(aCheckContent);
3543
0
                                        }
3544
0
                                        else if (aItem3.first == "date")
3545
0
                                        {
3546
0
                                            std::string aDate
3547
0
                                                = aItem3.second.get_value<std::string>();
3548
0
                                            xContentControlProps->setPropertyValue(
3549
0
                                                UNO_NAME_CURRENT_DATE,
3550
0
                                                uno::Any(OStringToOUString(aDate,
3551
0
                                                                           RTL_TEXTENCODING_UTF8)));
3552
0
                                        }
3553
0
                                        else if (aItem3.first == "alias")
3554
0
                                        {
3555
0
                                            xContentControlProps->setPropertyValue(
3556
0
                                                UNO_NAME_ALIAS,
3557
0
                                                uno::Any(OStringToOUString(
3558
0
                                                    aItem3.second.get_value<std::string>(),
3559
0
                                                    RTL_TEXTENCODING_UTF8)));
3560
0
                                        }
3561
0
                                        else
3562
0
                                        {
3563
0
                                            lcl_LogWarning(
3564
0
                                                "FillApi contentControl command not recognised: '"
3565
0
                                                + aItem3.first + "'");
3566
0
                                        }
3567
0
                                    }
3568
0
                                }
3569
0
                                if (!bCCFound)
3570
0
                                {
3571
0
                                    lcl_LogWarning("FillApi: No contentControl match the filter: '"
3572
0
                                                   + aItem2.first + "'");
3573
0
                                }
3574
0
                            }
3575
0
                            else
3576
0
                            {
3577
0
                                lcl_LogWarning(
3578
0
                                    "FillApi contentControl filter type not recognised: '"
3579
0
                                    + aItem2.first + "'");
3580
0
                            }
3581
0
                        }
3582
0
                    }
3583
0
                }
3584
0
                else if (aItem.first == "UnoCommand")
3585
0
                {
3586
0
                    SfxLokHelper::dispatchUnoCommand(aItem.second);
3587
0
                }
3588
0
            }
3589
0
        }
3590
0
        break;
3591
0
    default:
3592
0
        OSL_ENSURE(false, "wrong dispatcher");
3593
0
        return;
3594
0
    }
3595
0
}
3596
3597
void SwTextShell::GetState( SfxItemSet &rSet )
3598
0
{
3599
0
    SwWrtShell &rSh = GetShell();
3600
0
    SfxWhichIter aIter( rSet );
3601
0
    sal_uInt16 nWhich = aIter.FirstWhich();
3602
0
    while ( nWhich )
3603
0
    {
3604
0
        const sal_uInt16 nSlotId = GetPool().GetSlotId(nWhich);
3605
0
        switch (nSlotId)
3606
0
        {
3607
0
        case FN_FORMAT_CURRENT_FOOTNOTE_DLG:
3608
0
            if( !rSh.IsCursorInFootnote() )
3609
0
                rSet.DisableItem( nWhich );
3610
0
        break;
3611
3612
0
        case SID_LANGUAGE_STATUS:
3613
0
            {
3614
                // the value of used script types
3615
0
                OUString aScriptTypesInUse( OUString::number( static_cast<int>(rSh.GetScriptType()) ) );
3616
3617
                // get keyboard language
3618
0
                OUString aKeyboardLang;
3619
0
                SwEditWin& rEditWin = GetView().GetEditWin();
3620
0
                LanguageType nLang = rEditWin.GetInputLanguage();
3621
0
                if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3622
0
                    aKeyboardLang = SvtLanguageTable::GetLanguageString( nLang );
3623
3624
                // get the language that is in use
3625
0
                OUString aCurrentLang = u"*"_ustr;
3626
0
                nLang = SwLangHelper::GetCurrentLanguage( rSh );
3627
0
                if (nLang != LANGUAGE_DONTKNOW)
3628
0
                {
3629
0
                    aCurrentLang = SvtLanguageTable::GetLanguageString( nLang );
3630
0
                    if (comphelper::LibreOfficeKit::isActive())
3631
0
                    {
3632
0
                        if (nLang == LANGUAGE_NONE)
3633
0
                        {
3634
0
                            aCurrentLang += ";-";
3635
0
                        }
3636
0
                        else
3637
0
                        {
3638
0
                            aCurrentLang += ";" + LanguageTag(nLang).getBcp47(false);
3639
0
                        }
3640
0
                    }
3641
0
                }
3642
3643
                // build sequence for status value
3644
0
                uno::Sequence< OUString > aSeq{ aCurrentLang,
3645
0
                                                aScriptTypesInUse,
3646
0
                                                aKeyboardLang,
3647
0
                                                SwLangHelper::GetTextForLanguageGuessing( rSh ) };
3648
3649
                // set sequence as status value
3650
0
                SfxStringListItem aItem( SID_LANGUAGE_STATUS );
3651
0
                aItem.SetStringList( aSeq );
3652
0
                rSet.Put( aItem );
3653
0
            }
3654
0
        break;
3655
3656
0
        case SID_THES:
3657
0
        {
3658
            // is there a valid selection to get text from?
3659
0
            OUString aText;
3660
0
            bool bValid = !rSh.HasSelection() ||
3661
0
                    (rSh.IsSelOnePara() && !rSh.IsMultiSelection());
3662
            // prevent context menu from showing when cursor is not in or at the end of a word
3663
            // (GetCurWord will return the next word if there is none at the current position...)
3664
0
            const sal_Int16 nWordType = ::i18n::WordType::DICTIONARY_WORD;
3665
0
            bool bWord = rSh.IsInWord( nWordType ) || rSh.IsStartWord( nWordType ) || rSh.IsEndWord( nWordType );
3666
0
            if (bValid && bWord)
3667
0
               aText = rSh.HasSelection()? rSh.GetSelText() : rSh.GetCurWord();
3668
3669
0
            LanguageType nLang = rSh.GetCurLang();
3670
0
            LanguageTag aLanguageTag( nLang);
3671
0
            const lang::Locale& aLocale( aLanguageTag.getLocale());
3672
3673
            // disable "Thesaurus" context menu entry if there is nothing to look up
3674
0
            uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
3675
0
            if (aText.isEmpty() ||
3676
0
                !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( aLocale ))
3677
0
                rSet.DisableItem( SID_THES );
3678
0
            else
3679
0
            {
3680
                // set word and locale to look up as status value
3681
0
                OUString aStatusVal = aText + "#" + aLanguageTag.getBcp47();
3682
0
                rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
3683
0
            }
3684
0
        }
3685
0
        break;
3686
3687
0
        case FN_NUMBER_NEWSTART :
3688
0
            if(!rSh.GetNumRuleAtCurrCursorPos())
3689
0
                    rSet.DisableItem(nWhich);
3690
0
            else
3691
0
                rSet.Put(SfxBoolItem(FN_NUMBER_NEWSTART,
3692
0
                    rSh.IsNumRuleStart()));
3693
0
        break;
3694
3695
0
        case FN_EDIT_FORMULA:
3696
0
        case SID_CHARMAP:
3697
0
        case SID_CHARMAP_CONTROL:
3698
0
            {
3699
0
                const SelectionType nType = rSh.GetSelectionType();
3700
0
                if (!(nType & SelectionType::Text) &&
3701
0
                    !(nType & SelectionType::Table) &&
3702
0
                    !(nType & SelectionType::NumberList))
3703
0
                {
3704
0
                    rSet.DisableItem(nWhich);
3705
0
                }
3706
0
                else if ( nWhich == FN_EDIT_FORMULA
3707
0
                          && rSh.CursorInsideInputField() )
3708
0
                {
3709
0
                    rSet.DisableItem( nWhich );
3710
0
                }
3711
0
            }
3712
0
            break;
3713
3714
0
        case FN_INSERT_ENDNOTE:
3715
0
        case FN_INSERT_FOOTNOTE:
3716
0
        case FN_INSERT_FOOTNOTE_DLG:
3717
0
            {
3718
0
                const FrameTypeFlags nNoType =
3719
0
                    FrameTypeFlags::FLY_ANY | FrameTypeFlags::HEADER | FrameTypeFlags::FOOTER | FrameTypeFlags::FOOTNOTE;
3720
0
                FrameTypeFlags eType = rSh.GetFrameType(nullptr, true);
3721
0
                bool bSplitFly = false;
3722
0
                if (eType & FrameTypeFlags::FLY_ATCNT)
3723
0
                {
3724
0
                    SwContentFrame* pContentFrame = rSh.GetCurrFrame(/*bCalcFrame=*/false);
3725
0
                    if (pContentFrame)
3726
0
                    {
3727
0
                        SwFlyFrame* pFlyFrame = pContentFrame->FindFlyFrame();
3728
0
                        bSplitFly = pFlyFrame && pFlyFrame->IsFlySplitAllowed();
3729
0
                    }
3730
0
                }
3731
0
                if (eType & nNoType && !bSplitFly)
3732
0
                    rSet.DisableItem(nWhich);
3733
3734
0
                if ( rSh.CursorInsideInputField() )
3735
0
                {
3736
0
                    rSet.DisableItem( nWhich );
3737
0
                }
3738
0
            }
3739
0
            break;
3740
3741
0
        case SID_INSERTDOC:
3742
0
        case FN_INSERT_GLOSSARY:
3743
0
        case FN_EXPAND_GLOSSARY:
3744
0
            if ( rSh.CursorInsideInputField() )
3745
0
            {
3746
0
                rSet.DisableItem( nWhich );
3747
0
            }
3748
0
            break;
3749
3750
0
        case FN_INSERT_TABLE:
3751
0
            if ( rSh.CursorInsideInputField()
3752
0
                 || rSh.GetTableFormat()
3753
0
                 || (rSh.GetFrameType(nullptr,true) & FrameTypeFlags::FOOTNOTE) )
3754
0
            {
3755
0
                rSet.DisableItem( nWhich );
3756
0
            }
3757
0
            break;
3758
3759
0
        case FN_CALCULATE:
3760
0
            if ( !rSh.IsSelection() )
3761
0
                rSet.DisableItem(nWhich);
3762
0
            break;
3763
0
        case FN_GOTO_REFERENCE:
3764
0
            {
3765
0
                SwField *pField = rSh.GetCurField();
3766
0
                if ( !pField || (pField->GetTypeId() != SwFieldTypesEnum::GetRef) )
3767
0
                    rSet.DisableItem(nWhich);
3768
0
            }
3769
0
            break;
3770
0
        case FN_AUTOFORMAT_AUTO:
3771
0
            {
3772
0
                rSet.Put( SfxBoolItem( nWhich, SvxAutoCorrCfg::Get().IsAutoFormatByInput() ));
3773
0
            }
3774
0
            break;
3775
3776
0
        case SID_DEC_INDENT:
3777
0
        case SID_INC_INDENT:
3778
0
        {
3779
            //if the paragraph has bullet we'll do the following things:
3780
            //1: if the bullet level is the first level, disable the decrease-indent button
3781
            //2: if the bullet level is the last level, disable the increase-indent button
3782
0
            if ( rSh.GetNumRuleAtCurrCursorPos() && !rSh.HasReadonlySel() )
3783
0
            {
3784
0
                const sal_uInt8 nLevel = rSh.GetNumLevel();
3785
0
                if ( ( nLevel == ( MAXLEVEL - 1 ) && nWhich == SID_INC_INDENT )
3786
0
                     || ( nLevel == 0 && nWhich == SID_DEC_INDENT ) )
3787
0
                {
3788
0
                    rSet.DisableItem( nWhich );
3789
0
                }
3790
0
            }
3791
0
            else
3792
0
            {
3793
0
                sal_uInt16 nHtmlMode = ::GetHtmlMode( GetView().GetDocShell() );
3794
0
                nHtmlMode &= HTMLMODE_ON | HTMLMODE_SOME_STYLES;
3795
0
                if ( ( nHtmlMode == HTMLMODE_ON )
3796
0
                     || !rSh.IsMoveLeftMargin( SID_INC_INDENT == nWhich ) )
3797
0
                {
3798
0
                    rSet.DisableItem( nWhich );
3799
0
                }
3800
0
            }
3801
0
        }
3802
0
        break;
3803
3804
0
        case FN_DEC_INDENT_OFFSET:
3805
0
        case FN_INC_INDENT_OFFSET:
3806
0
            {
3807
0
                sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
3808
0
                nHtmlMode &= HTMLMODE_ON|HTMLMODE_SOME_STYLES;
3809
0
                if( (nHtmlMode == HTMLMODE_ON) ||
3810
0
                    !rSh.IsMoveLeftMargin( FN_INC_INDENT_OFFSET == nWhich,
3811
0
                                            false ))
3812
0
                    rSet.DisableItem( nWhich );
3813
0
            }
3814
0
            break;
3815
3816
0
        case SID_ATTR_CHAR_COLOR2:
3817
0
            {
3818
0
                SfxItemSet aSet( GetPool() );
3819
0
                rSh.GetCurAttr( aSet );
3820
0
                const SvxColorItem& aColorItem = aSet.Get(RES_CHRATR_COLOR);
3821
0
                rSet.Put( aColorItem.CloneSetWhich(SID_ATTR_CHAR_COLOR2) );
3822
0
            }
3823
0
            break;
3824
0
        case SID_ATTR_CHAR_BACK_COLOR:
3825
0
        case SID_ATTR_CHAR_COLOR_BACKGROUND:
3826
0
            {
3827
                // Always use the visible background
3828
0
                SfxItemSet aSet( GetPool() );
3829
0
                rSh.GetCurAttr( aSet );
3830
0
                const SvxBrushItem& aBrushItem = aSet.Get(RES_CHRATR_HIGHLIGHT);
3831
0
                if( aBrushItem.GetColor() != COL_TRANSPARENT )
3832
0
                {
3833
0
                    rSet.Put(SvxColorItem(aBrushItem.GetColor(), aBrushItem.getComplexColor(), nWhich));
3834
0
                }
3835
0
                else
3836
0
                {
3837
0
                    const SvxBrushItem& aBrushItem2 = aSet.Get(RES_CHRATR_BACKGROUND);
3838
0
                    rSet.Put(SvxColorItem(aBrushItem2.GetColor(), aBrushItem2.getComplexColor(), nWhich));
3839
0
                }
3840
0
            }
3841
0
            break;
3842
0
        case SID_ATTR_CHAR_COLOR_BACKGROUND_EXT:
3843
0
            {
3844
0
                SwEditWin& rEdtWin = GetView().GetEditWin();
3845
0
                SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
3846
0
                const sal_uInt32 nColWhich = pApply ? pApply->nColor : 0;
3847
0
                const bool bUseTemplate = nColWhich == SID_ATTR_CHAR_BACK_COLOR
3848
0
                                          || nColWhich == SID_ATTR_CHAR_COLOR_BACKGROUND;
3849
0
                rSet.Put(SfxBoolItem(nWhich, bUseTemplate));
3850
0
            }
3851
0
            break;
3852
0
        case SID_ATTR_CHAR_COLOR_EXT:
3853
0
            {
3854
0
                SwEditWin& rEdtWin = GetView().GetEditWin();
3855
0
                SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
3856
0
                rSet.Put(SfxBoolItem(nWhich, pApply && pApply->nColor == nWhich));
3857
0
            }
3858
0
            break;
3859
0
        case FN_SET_REMINDER:
3860
0
        case FN_INSERT_BOOKMARK:
3861
0
            if( rSh.IsTableMode()
3862
0
                || rSh.CursorInsideInputField() )
3863
0
            {
3864
0
                rSet.DisableItem( nWhich );
3865
0
            }
3866
0
            break;
3867
3868
0
        case FN_INSERT_BREAK:
3869
0
            if ( rSh.HasReadonlySel()
3870
0
                 && !rSh.CursorInsideInputField() )
3871
0
            {
3872
0
                rSet.DisableItem( nWhich );
3873
0
            }
3874
0
            break;
3875
3876
0
        case FN_INSERT_BREAK_DLG:
3877
0
        case FN_INSERT_COLUMN_BREAK:
3878
0
        case FN_INSERT_PAGEBREAK:
3879
0
            if( rSh.CursorInsideInputField() || rSh.CursorInsideContentControl() )
3880
0
            {
3881
0
                rSet.DisableItem( nWhich );
3882
0
            }
3883
0
            break;
3884
3885
0
        case FN_INSERT_PAGEHEADER:
3886
0
        case FN_INSERT_PAGEFOOTER:
3887
0
            if (comphelper::LibreOfficeKit::isActive())
3888
0
            {
3889
0
                bool bState = false;
3890
0
                bool bAllState = true;
3891
0
                bool bIsPhysical = false;
3892
3893
0
                OUString aStyleName;
3894
0
                std::vector<OUString> aList;
3895
0
                static constexpr OUStringLiteral sPhysical(u"IsPhysical");
3896
0
                static constexpr OUStringLiteral sDisplay(u"DisplayName");
3897
0
                const OUString sHeaderOn(nWhich == FN_INSERT_PAGEHEADER ? u"HeaderIsOn"_ustr : u"FooterIsOn"_ustr);
3898
3899
0
                rtl::Reference< SwXTextDocument > xSupplier(GetView().GetDocShell()->GetBaseModel());
3900
0
                if (xSupplier.is())
3901
0
                {
3902
0
                    uno::Reference< XNameContainer > xContainer;
3903
0
                    uno::Reference< XNameAccess > xFamilies = xSupplier->getStyleFamilies();
3904
0
                    if (xFamilies->getByName(u"PageStyles"_ustr) >>= xContainer)
3905
0
                    {
3906
0
                        const uno::Sequence< OUString > aSeqNames = xContainer->getElementNames();
3907
0
                        for (const auto& rName : aSeqNames)
3908
0
                        {
3909
0
                            aStyleName = rName;
3910
0
                            uno::Reference<XPropertySet> xPropSet(xContainer->getByName(aStyleName), uno::UNO_QUERY);
3911
0
                            if (xPropSet.is() && (xPropSet->getPropertyValue(sPhysical) >>= bIsPhysical) && bIsPhysical)
3912
0
                            {
3913
0
                                xPropSet->getPropertyValue(sDisplay) >>= aStyleName;
3914
0
                                if ((xPropSet->getPropertyValue(sHeaderOn)>>= bState) && bState)
3915
0
                                    aList.push_back(aStyleName);
3916
0
                                else
3917
0
                                    bState = false;
3918
3919
                                // Check if all entries have the same state
3920
0
                                bAllState &= bState;
3921
0
                            }
3922
0
                            else
3923
0
                                bIsPhysical = false;
3924
0
                        }
3925
0
                    }
3926
0
                }
3927
3928
0
                if (bAllState && aList.size() > 1)
3929
0
                    aList.push_back(u"_ALL_"_ustr);
3930
3931
0
                rSet.Put(SfxStringListItem(nWhich, &aList));
3932
0
            }
3933
0
            else
3934
0
            {
3935
0
                rSet.Put( SfxObjectShellItem( nWhich, GetView().GetDocShell() ));
3936
0
            }
3937
0
            break;
3938
0
            case FN_TABLE_SORT_DIALOG:
3939
0
            case FN_SORTING_DLG:
3940
0
                if(!rSh.HasSelection() ||
3941
0
                        (FN_TABLE_SORT_DIALOG == nWhich && !rSh.GetTableFormat()))
3942
0
                    rSet.DisableItem( nWhich );
3943
0
            break;
3944
3945
0
            case SID_RUBY_DIALOG:
3946
0
                {
3947
0
                    if( !SvtCJKOptions::IsRubyEnabled()
3948
0
                        || rSh.CursorInsideInputField() )
3949
0
                    {
3950
0
                        GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, false );
3951
0
                        rSet.DisableItem(nWhich);
3952
0
                    }
3953
0
                    else
3954
0
                        GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, true );
3955
0
                }
3956
0
                break;
3957
3958
0
            case SID_FM_TRANSLATE:
3959
0
                {
3960
0
#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
3961
0
                    if (!officecfg::Office::Common::Misc::ExperimentalMode::get()
3962
0
                        && !comphelper::LibreOfficeKit::isActive())
3963
0
                    {
3964
0
                        rSet.Put(SfxVisibilityItem(nWhich, false));
3965
0
                        break;
3966
0
                    }
3967
0
                    std::optional<OUString> oDeeplAPIUrl = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get();
3968
0
                    std::optional<OUString> oDeeplKey = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get();
3969
0
                    if (!oDeeplAPIUrl || oDeeplAPIUrl->isEmpty() || !oDeeplKey || oDeeplKey->isEmpty())
3970
0
                    {
3971
0
                        rSet.DisableItem(nWhich);
3972
0
                    }
3973
0
#endif
3974
0
                }
3975
0
                break;
3976
3977
0
            case SID_HYPERLINK_DIALOG:
3978
0
                if( GetView().GetDocShell()->IsReadOnly()
3979
0
                    || ( !GetView().GetViewFrame().HasChildWindow(nWhich)
3980
0
                         && rSh.HasReadonlySel() )
3981
0
                    || rSh.CursorInsideInputField() )
3982
0
                {
3983
0
                    rSet.DisableItem(nWhich);
3984
0
                }
3985
0
                else
3986
0
                {
3987
0
                    rSet.Put(SfxBoolItem( nWhich, nullptr != GetView().GetViewFrame().GetChildWindow( nWhich ) ));
3988
0
                }
3989
0
                break;
3990
3991
0
            case SID_EDIT_HYPERLINK:
3992
0
                {
3993
0
                    if (!rSh.HasReadonlySel())
3994
0
                    {
3995
0
                        SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
3996
0
                        rSh.GetCurAttr(aSet);
3997
0
                        if (SfxItemState::SET <= aSet.GetItemState(RES_TXTATR_INETFMT))
3998
0
                            break;
3999
4000
                        // is the cursor at the beginning of a hyperlink?
4001
0
                        const SwTextNode* pTextNd = rSh.GetCursor()->GetPointNode().GetTextNode();
4002
0
                        if (pTextNd && !rSh.HasSelection())
4003
0
                        {
4004
0
                            const sal_Int32 nIndex = rSh.GetCursor()->Start()->GetContentIndex();
4005
0
                            const SwTextAttr* pINetFmt
4006
0
                                = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
4007
0
                            if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
4008
0
                                break;
4009
0
                        }
4010
0
                    }
4011
0
                    rSet.DisableItem(nWhich);
4012
0
                }
4013
0
            break;
4014
0
            case SID_INSERT_HYPERLINK:
4015
0
            {
4016
0
                if (!rSh.HasSelection())
4017
0
                {
4018
0
                    rSet.DisableItem(nWhich);
4019
0
                    break;
4020
0
                }
4021
0
                if (!rSh.HasReadonlySel())
4022
0
                {
4023
0
                    SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
4024
0
                    rSh.GetCurAttr(aSet);
4025
4026
                    // If a hyperlink is selected, either alone or along with other text...
4027
0
                    if (SfxItemState::SET <= aSet.GetItemState(RES_TXTATR_INETFMT)
4028
0
                        || aSet.GetItemState(RES_TXTATR_INETFMT) == SfxItemState::INVALID)
4029
0
                    {
4030
0
                        rSet.DisableItem(nWhich);
4031
0
                    }
4032
4033
                    // is the cursor at the beginning of a hyperlink?
4034
0
                    const SwTextNode* pTextNd = rSh.GetCursor()->GetPointNode().GetTextNode();
4035
0
                    if (pTextNd && !rSh.HasSelection())
4036
0
                    {
4037
0
                        const sal_Int32 nIndex = rSh.GetCursor()->Start()->GetContentIndex();
4038
0
                        const SwTextAttr* pINetFmt
4039
0
                            = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
4040
0
                        if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
4041
0
                            rSet.DisableItem(nWhich);
4042
0
                    }
4043
0
                }
4044
0
            }
4045
0
            break;
4046
0
            case SID_REMOVE_HYPERLINK:
4047
0
            {
4048
0
                if (!rSh.HasReadonlySel())
4049
0
                {
4050
0
                    SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
4051
0
                    rSh.GetCurAttr(aSet);
4052
4053
                    // If a hyperlink is selected, either alone or along with other text...
4054
0
                    if (SfxItemState::SET <= aSet.GetItemState(RES_TXTATR_INETFMT)
4055
0
                        || aSet.GetItemState(RES_TXTATR_INETFMT) == SfxItemState::INVALID)
4056
0
                    {
4057
0
                        break;
4058
0
                    }
4059
4060
                    // is the cursor at the beginning of a hyperlink?
4061
0
                    const SwTextNode* pTextNd = rSh.GetCursor()->GetPointNode().GetTextNode();
4062
0
                    if (pTextNd && !rSh.HasSelection())
4063
0
                    {
4064
0
                        const sal_Int32 nIndex = rSh.GetCursor()->Start()->GetContentIndex();
4065
0
                        const SwTextAttr* pINetFmt
4066
0
                            = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
4067
0
                        if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
4068
0
                            break;
4069
0
                    }
4070
0
                }
4071
0
                rSet.DisableItem(nWhich);
4072
0
            }
4073
0
            break;
4074
0
            case SID_TRANSLITERATE_HALFWIDTH:
4075
0
            case SID_TRANSLITERATE_FULLWIDTH:
4076
0
            case SID_TRANSLITERATE_HIRAGANA:
4077
0
            case SID_TRANSLITERATE_KATAKANA:
4078
0
            {
4079
0
                if(!SvtCJKOptions::IsChangeCaseMapEnabled())
4080
0
                {
4081
0
                    GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, false );
4082
0
                    rSet.DisableItem(nWhich);
4083
0
                }
4084
0
                else
4085
0
                    GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, true );
4086
0
            }
4087
0
            break;
4088
0
            case FN_READONLY_SELECTION_MODE :
4089
0
                if(!GetView().GetDocShell()->IsReadOnly())
4090
0
                    rSet.DisableItem( nWhich );
4091
0
                else
4092
0
                {
4093
0
                    rSet.Put(SfxBoolItem(nWhich, rSh.GetViewOptions()->IsSelectionInReadonly()));
4094
0
                }
4095
0
            break;
4096
0
            case FN_SELECTION_MODE_DEFAULT:
4097
0
            case FN_SELECTION_MODE_BLOCK :
4098
0
                    rSet.Put(SfxBoolItem(nWhich, (nWhich == FN_SELECTION_MODE_DEFAULT) != rSh.IsBlockMode()));
4099
0
            break;
4100
0
            case SID_COPY_HYPERLINK_LOCATION:
4101
0
            case SID_OPEN_HYPERLINK:
4102
0
            {
4103
0
                SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> aSet(GetPool());
4104
0
                rSh.GetCurAttr(aSet);
4105
0
                if (SfxItemState::SET <= aSet.GetItemState(RES_TXTATR_INETFMT, false))
4106
0
                    break;
4107
4108
                // is the cursor at the beginning of a hyperlink?
4109
0
                const SwTextNode* pTextNd = rSh.GetCursor()->GetPointNode().GetTextNode();
4110
0
                if (pTextNd && !rSh.HasSelection())
4111
0
                {
4112
0
                    const sal_Int32 nIndex = rSh.GetCursor()->Start()->GetContentIndex();
4113
0
                    const SwTextAttr* pINetFmt = pTextNd->GetTextAttrAt(nIndex, RES_TXTATR_INETFMT);
4114
0
                    if (pINetFmt && !pINetFmt->GetINetFormat().GetValue().isEmpty())
4115
0
                        break;
4116
0
                }
4117
4118
0
                SwField* pField = rSh.GetCurField();
4119
0
                if (pField && pField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities)
4120
0
                {
4121
0
                    const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
4122
0
                    if (auto targetType = rAuthorityField.GetTargetType();
4123
0
                        targetType == SwAuthorityField::TargetType::UseDisplayURL
4124
0
                        || targetType == SwAuthorityField::TargetType::UseTargetURL)
4125
0
                    {
4126
                        // Check if the Bibliography entry has a target URL
4127
0
                        if (rAuthorityField.GetAbsoluteURL().getLength() > 0)
4128
0
                            break;
4129
0
                    }
4130
0
                }
4131
4132
0
                rSet.DisableItem(nWhich);
4133
0
            }
4134
0
            break;
4135
0
            case FN_OPEN_LOCAL_URL:
4136
0
            {
4137
0
                if (GetLocalURL(rSh).isEmpty())
4138
0
                {
4139
0
                    rSet.DisableItem(nWhich);
4140
0
                }
4141
0
            }
4142
0
            break;
4143
0
            case  SID_OPEN_SMARTTAGMENU:
4144
0
            {
4145
0
                 std::vector< OUString > aSmartTagTypes;
4146
0
                 uno::Sequence< uno::Reference< container::XStringKeyMap > > aStringKeyMaps;
4147
0
                 uno::Reference<text::XTextRange> xRange;
4148
4149
0
                 rSh.GetSmartTagTerm( aSmartTagTypes, aStringKeyMaps, xRange );
4150
4151
0
                 if ( xRange.is() && !aSmartTagTypes.empty() )
4152
0
                 {
4153
0
                     uno::Sequence < uno::Sequence< uno::Reference< smarttags::XSmartTagAction > > > aActionComponentsSequence;
4154
0
                     uno::Sequence < uno::Sequence< sal_Int32 > > aActionIndicesSequence;
4155
4156
0
                     const SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get();
4157
0
                     rSmartTagMgr.GetActionSequences( aSmartTagTypes,
4158
0
                                                      aActionComponentsSequence,
4159
0
                                                      aActionIndicesSequence );
4160
4161
0
                     uno::Reference <frame::XController> xController = GetView().GetController();
4162
0
                     lang::Locale aLocale( SW_BREAKITER()->GetLocale( GetAppLanguageTag() ) );
4163
0
                     const OUString& aApplicationName( rSmartTagMgr.GetApplicationName() );
4164
0
                     const OUString aRangeText = xRange->getString();
4165
4166
0
                     const SvxSmartTagItem aItem( SID_OPEN_SMARTTAGMENU,
4167
0
                                                  aActionComponentsSequence,
4168
0
                                                  aActionIndicesSequence,
4169
0
                                                  aStringKeyMaps,
4170
0
                                                  xRange,
4171
0
                                                  std::move(xController),
4172
0
                                                  std::move(aLocale),
4173
0
                                                  aApplicationName,
4174
0
                                                  aRangeText );
4175
4176
0
                     rSet.Put( aItem );
4177
0
                 }
4178
0
                 else
4179
0
                     rSet.DisableItem(nWhich);
4180
0
            }
4181
0
            break;
4182
4183
0
            case FN_NUM_NUMBERING_ON:
4184
0
                rSet.Put(SfxBoolItem(FN_NUM_NUMBERING_ON,rSh.SelectionHasNumber()));
4185
0
            break;
4186
4187
0
            case FN_NUM_BULLET_ON:
4188
0
                rSet.Put(SfxBoolItem(FN_NUM_BULLET_ON,rSh.SelectionHasBullet()));
4189
0
            break;
4190
4191
0
            case FN_NUM_BULLET_OFF:
4192
0
                rSet.Put(SfxBoolItem(FN_NUM_BULLET_OFF, !rSh.GetNumRuleAtCurrCursorPos() &&
4193
0
                                     !rSh.GetNumRuleAtCurrentSelection()));
4194
0
            break;
4195
4196
0
            case FN_SVX_SET_OUTLINE:
4197
0
            {
4198
0
                NBOTypeMgrBase* pOutline = NBOutlineTypeMgrFact::CreateInstance(NBOType::Outline);
4199
0
                auto pCurRule = const_cast<SwNumRule*>(rSh.GetNumRuleAtCurrCursorPos());
4200
0
                if (pOutline && pCurRule)
4201
0
                {
4202
0
                    SvxNumRule aSvxRule = pCurRule->MakeSvxNumRule();
4203
0
                    const sal_uInt16 nIndex = pOutline->GetNBOIndexForNumRule(aSvxRule, 0);
4204
0
                    rSet.Put(SfxBoolItem(FN_SVX_SET_OUTLINE, nIndex < USHRT_MAX));
4205
0
                }
4206
0
                break;
4207
0
            }
4208
0
            case FN_BUL_NUM_RULE_INDEX:
4209
0
            case FN_NUM_NUM_RULE_INDEX:
4210
0
            case FN_OUTLINE_RULE_INDEX:
4211
0
        {
4212
0
            SwNumRule* pCurRule = const_cast<SwNumRule*>(GetShell().GetNumRuleAtCurrCursorPos());
4213
0
            if( pCurRule )
4214
0
            {
4215
0
                sal_uInt16 nActNumLvl = GetShell().GetNumLevel();
4216
0
                if( nActNumLvl < MAXLEVEL )
4217
0
                {
4218
0
                    nActNumLvl = 1<<nActNumLvl;
4219
0
                }
4220
0
                SvxNumRule aSvxRule = pCurRule->MakeSvxNumRule();
4221
0
                if ( GetShell().HasBullet())
4222
0
                {
4223
0
                    rSet.Put(SfxUInt16Item(FN_BUL_NUM_RULE_INDEX, USHRT_MAX));
4224
0
                    rSet.Put(SfxUInt16Item(FN_NUM_NUM_RULE_INDEX, USHRT_MAX));
4225
0
                    NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(NBOType::Bullets);
4226
0
                    if ( pBullets )
4227
0
                    {
4228
0
                        const sal_uInt16 nBulIndex = pBullets->GetNBOIndexForNumRule(aSvxRule,nActNumLvl);
4229
0
                        rSet.Put(SfxUInt16Item(FN_BUL_NUM_RULE_INDEX,nBulIndex));
4230
0
                    }
4231
0
                }else if ( GetShell().HasNumber() )
4232
0
                {
4233
0
                    rSet.Put(SfxUInt16Item(FN_BUL_NUM_RULE_INDEX, USHRT_MAX));
4234
0
                    rSet.Put(SfxUInt16Item(FN_NUM_NUM_RULE_INDEX, USHRT_MAX));
4235
0
                    NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(NBOType::Numbering);
4236
0
                    if ( pNumbering )
4237
0
                    {
4238
0
                        const sal_uInt16 nBulIndex = pNumbering->GetNBOIndexForNumRule(aSvxRule,nActNumLvl);
4239
0
                        rSet.Put(SfxUInt16Item(FN_NUM_NUM_RULE_INDEX,nBulIndex));
4240
0
                    }
4241
0
                }
4242
4243
0
                if ( nWhich == FN_OUTLINE_RULE_INDEX )
4244
0
                {
4245
0
                    rSet.Put(SfxUInt16Item(FN_OUTLINE_RULE_INDEX, USHRT_MAX));
4246
0
                    NBOTypeMgrBase* pOutline = NBOutlineTypeMgrFact::CreateInstance(NBOType::Outline);
4247
0
                    if ( pOutline )
4248
0
                    {
4249
0
                        const sal_uInt16 nIndex = pOutline->GetNBOIndexForNumRule(aSvxRule,nActNumLvl);
4250
0
                        rSet.Put(SfxUInt16Item(FN_OUTLINE_RULE_INDEX,nIndex));
4251
0
                    }
4252
0
                }
4253
0
            }
4254
0
        }
4255
0
            break;
4256
0
            case FN_BUL_GET_DOC_BULLETS:
4257
0
            {
4258
0
                std::set<OUString> aBulletsSet = rSh.GetUsedBullets();
4259
0
                std::vector<OUString> aBullets;
4260
0
                std::copy(aBulletsSet.begin(), aBulletsSet.end(), std::back_inserter(aBullets));
4261
0
                SfxStringListItem aItem(FN_BUL_GET_DOC_BULLETS);
4262
0
                uno::Sequence<OUString> aSeq(aBullets.data(),
4263
0
                                             static_cast<sal_Int32>(aBullets.size()));
4264
0
                aItem.SetStringList(aSeq);
4265
0
                rSet.Put(aItem);
4266
0
            }
4267
0
            break;
4268
0
            case FN_NUM_CONTINUE:
4269
0
            {
4270
                // #i86492#
4271
                // Search also for bullet list
4272
0
                OUString aDummy;
4273
0
                const SwNumRule* pRule =
4274
0
                        rSh.SearchNumRule( true, aDummy );
4275
0
                if ( !pRule )
4276
0
                {
4277
0
                    pRule = rSh.SearchNumRule( false, aDummy );
4278
0
                }
4279
0
                if ( !pRule )
4280
0
                    rSet.DisableItem(nWhich);
4281
0
            }
4282
0
            break;
4283
0
            case SID_INSERT_RLM :
4284
0
            case SID_INSERT_LRM :
4285
0
            {
4286
0
                bool bEnabled = SvtCTLOptions::IsCTLFontEnabled();
4287
0
                GetView().GetViewFrame().GetBindings().SetVisibleState( nWhich, bEnabled );
4288
0
                if(!bEnabled)
4289
0
                    rSet.DisableItem(nWhich);
4290
0
            }
4291
0
            break;
4292
0
            case SID_FM_CTL_PROPERTIES:
4293
0
            {
4294
0
                bool bDisable = false;
4295
4296
                // First get the state from the form shell
4297
0
                SfxItemSetFixed<SID_FM_CTL_PROPERTIES, SID_FM_CTL_PROPERTIES> aSet(GetShell().GetAttrPool());
4298
0
                aSet.Put(SfxBoolItem( SID_FM_CTL_PROPERTIES, true ));
4299
0
                GetShell().GetView().GetFormShell()->GetState( aSet );
4300
4301
0
                if(SfxItemState::DISABLED == aSet.GetItemState(SID_FM_CTL_PROPERTIES))
4302
0
                {
4303
0
                    bDisable = true;
4304
0
                }
4305
4306
                // Enable it if we have a valid object other than what form shell knows
4307
0
                SwPosition aPos(*GetShell().GetCursor()->GetPoint());
4308
0
                sw::mark::Fieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
4309
0
                if ( !pFieldBM && aPos.GetContentIndex() > 0)
4310
0
                {
4311
0
                    aPos.AdjustContent(-1);
4312
0
                    pFieldBM = GetShell().getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
4313
0
                }
4314
0
                if ( pFieldBM && (pFieldBM->GetFieldname() == ODF_FORMDROPDOWN || pFieldBM->GetFieldname() == ODF_FORMDATE) )
4315
0
                {
4316
0
                    bDisable = false;
4317
0
                }
4318
4319
0
                if(bDisable)
4320
0
                    rSet.DisableItem(nWhich);
4321
0
            }
4322
0
            break;
4323
0
            case SID_COPY:
4324
0
            case SID_CUT:
4325
0
            {
4326
0
                if (GetObjectShell()->isContentExtractionLocked())
4327
0
                    rSet.DisableItem(nWhich);
4328
0
                break;
4329
0
            }
4330
0
            case FN_PROTECT_FIELDS:
4331
0
            case FN_PROTECT_BOOKMARKS:
4332
0
            {
4333
0
                DocumentSettingId aSettingId = nWhich == FN_PROTECT_FIELDS
4334
0
                                                   ? DocumentSettingId::PROTECT_FIELDS
4335
0
                                                   : DocumentSettingId::PROTECT_BOOKMARKS;
4336
0
                bool bProtected = rSh.getIDocumentSettingAccess().get(aSettingId);
4337
0
                rSet.Put(SfxBoolItem(nWhich, bProtected));
4338
0
            }
4339
0
            break;
4340
0
            case FN_DELETE_CONTENT_CONTROL:
4341
0
            case FN_CONTENT_CONTROL_PROPERTIES:
4342
0
            {
4343
0
                if (!GetShell().CursorInsideContentControl())
4344
0
                {
4345
0
                    rSet.DisableItem(nWhich);
4346
0
                }
4347
0
            }
4348
0
            break;
4349
0
        }
4350
0
        nWhich = aIter.NextWhich();
4351
0
    }
4352
0
}
4353
4354
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */