Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/shells/annotsh.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 <hintids.hxx>
21
22
#include <com/sun/star/i18n/TextConversionOption.hpp>
23
#include <com/sun/star/lang/XInitialization.hpp>
24
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
25
#include <com/sun/star/awt/XWindow.hpp>
26
#include <com/sun/star/uno/XComponentContext.hpp>
27
#include <com/sun/star/beans/XPropertySet.hpp>
28
#include <com/sun/star/linguistic2/XThesaurus.hpp>
29
30
#include <i18nutil/transliteration.hxx>
31
#include <sfx2/namedcolor.hxx>
32
#include <sfx2/toolbarids.hxx>
33
#include <sfx2/objface.hxx>
34
#include <sfx2/viewfrm.hxx>
35
#include <sfx2/bindings.hxx>
36
#include <sfx2/dispatch.hxx>
37
#include <sfx2/request.hxx>
38
#include <editeng/colritem.hxx>
39
#include <editeng/editund2.hxx>
40
#include <editeng/eeitem.hxx>
41
#include <editeng/flstitem.hxx>
42
#include <editeng/spltitem.hxx>
43
#include <editeng/lrspitem.hxx>
44
#include <editeng/ulspitem.hxx>
45
#include <editeng/orphitem.hxx>
46
#include <editeng/formatbreakitem.hxx>
47
#include <editeng/widwitem.hxx>
48
#include <editeng/kernitem.hxx>
49
#include <editeng/escapementitem.hxx>
50
#include <editeng/lspcitem.hxx>
51
#include <editeng/adjustitem.hxx>
52
#include <editeng/hyphenzoneitem.hxx>
53
#include <editeng/udlnitem.hxx>
54
#include <editeng/fontitem.hxx>
55
#include <svx/clipfmtitem.hxx>
56
#include <svx/chinese_translation_unodialog.hxx>
57
#include <svl/stritem.hxx>
58
#include <svl/slstitm.hxx>
59
#include <editeng/frmdiritem.hxx>
60
#include <svl/whiter.hxx>
61
#include <svl/cjkoptions.hxx>
62
#include <svl/ctloptions.hxx>
63
#include <unotools/fontdefs.hxx>
64
#include <unotools/useroptions.hxx>
65
#include <editeng/flditem.hxx>
66
#include <svx/hlnkitem.hxx>
67
#include <sfx2/htmlmode.hxx>
68
#include <editeng/langitem.hxx>
69
#include <editeng/scriptsetitem.hxx>
70
#include <swundo.hxx>
71
#include <doc.hxx>
72
#include <viewopt.hxx>
73
#include <wrtsh.hxx>
74
#include <chrdlgmodes.hxx>
75
#include <edtwin.hxx>
76
#include <SwRewriter.hxx>
77
78
#include <cmdid.h>
79
#include <strings.hrc>
80
#include <breakit.hxx>
81
#include <annotsh.hxx>
82
#include <view.hxx>
83
#include <PostItMgr.hxx>
84
#include <AnnotationWin.hxx>
85
86
#include <swtypes.hxx>
87
88
#include <svx/svxdlg.hxx>
89
90
#include <vcl/EnumContext.hxx>
91
#include <vcl/rendercontext/GetDefaultFontFlags.hxx>
92
#include <svl/itempool.hxx>
93
#include <editeng/outliner.hxx>
94
#include <editeng/editview.hxx>
95
#include <osl/diagnose.h>
96
97
#include <svl/languageoptions.hxx>
98
99
#include <svl/undo.hxx>
100
#include <vcl/weld/Window.hxx>
101
#include <swabstdlg.hxx>
102
103
#include <comphelper/string.hxx>
104
#include <comphelper/processfactory.hxx>
105
#include <comphelper/propertysequence.hxx>
106
107
#include <langhelper.hxx>
108
109
#include <memory>
110
111
using namespace ::com::sun::star;
112
using namespace ::com::sun::star::uno;
113
using namespace ::com::sun::star::beans;
114
using namespace ::com::sun::star::i18n;
115
116
#define ShellClass_SwAnnotationShell
117
118
#include <sfx2/msg.hxx>
119
#include <swslots.hxx>
120
121
SFX_IMPL_INTERFACE(SwAnnotationShell, SfxShell)
122
123
void SwAnnotationShell::InitInterface_Impl()
124
9
{
125
9
    GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw);
126
127
9
    GetStaticInterface()->RegisterPopupMenu(u"annotation"_ustr);
128
9
}
129
130
131
SfxItemPool* SwAnnotationShell::GetAnnotationPool(SwView const & rV)
132
0
{
133
0
    SwWrtShell &rSh = rV.GetWrtShell();
134
0
    return rSh.GetAttrPool().GetSecondaryPool();
135
0
}
136
137
SwAnnotationShell::SwAnnotationShell( SwView& r )
138
0
    : m_rView(r)
139
0
{
140
0
    SetPool(SwAnnotationShell::GetAnnotationPool(m_rView));
141
0
    SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Annotation));
142
0
}
143
144
SwAnnotationShell::~SwAnnotationShell()
145
0
{
146
0
    if (m_rView.GetWrtShell().CanInsert())
147
0
        m_rView.ShowCursor(true);
148
0
}
149
150
SfxUndoManager* SwAnnotationShell::GetUndoManager()
151
0
{
152
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
153
0
    if ( !pPostItMgr ||
154
0
         !pPostItMgr->HasActiveSidebarWin() )
155
0
    {
156
0
        OSL_ENSURE(pPostItMgr,"PostItMgr::Layout(): We are looping forever");
157
0
        return nullptr;
158
0
    }
159
0
    return &pPostItMgr->GetActiveSidebarWin()->GetOutlinerView()->GetOutliner().GetUndoManager();
160
0
}
161
162
void SwAnnotationShell::Exec( SfxRequest &rReq )
163
0
{
164
    //TODO: clean this up!!!!
165
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
166
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
167
0
        return;
168
169
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
170
0
    SfxItemSet aEditAttr(pOLV->GetAttribs());
171
0
    SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
172
173
0
    const sal_uInt16 nSlot = rReq.GetSlot();
174
0
    const sal_uInt16 nWhich = GetPool().GetWhichIDFromSlotID(nSlot);
175
0
    const SfxItemSet *pNewAttrs = rReq.GetArgs();
176
0
    sal_uInt16 nEEWhich = 0;
177
0
    switch (nSlot)
178
0
    {
179
0
        case SID_PARASPACE_INCREASE:
180
0
        case SID_PARASPACE_DECREASE:
181
0
        {
182
0
            SvxULSpaceItem aULSpace( aEditAttr.Get( EE_PARA_ULSPACE ) );
183
0
            sal_uInt16 nUpper = aULSpace.GetUpper();
184
0
            sal_uInt16 nLower = aULSpace.GetLower();
185
186
0
            if ( nSlot == SID_PARASPACE_INCREASE )
187
0
            {
188
0
                nUpper = std::min< sal_uInt16 >( nUpper + 57, 5670 );
189
0
                nLower = std::min< sal_uInt16 >( nLower + 57, 5670 );
190
0
            }
191
0
            else
192
0
            {
193
0
                nUpper = std::max< sal_Int16 >( nUpper - 57, 0 );
194
0
                nLower = std::max< sal_Int16 >( nLower - 57, 0 );
195
0
            }
196
197
0
            aULSpace.SetUpper( nUpper );
198
0
            aULSpace.SetLower( nLower );
199
0
            aNewAttr.Put( aULSpace );
200
0
            rReq.Done();
201
0
        }
202
0
        break;
203
0
        case SID_ATTR_PARA_LRSPACE:
204
0
            {
205
0
                SvxLRSpaceItem aParaMargin(static_cast<const SvxLRSpaceItem&>(rReq.
206
0
                                        GetArgs()->Get(nSlot)));
207
0
                aParaMargin.SetWhich( EE_PARA_LRSPACE );
208
209
0
                aNewAttr.Put(aParaMargin);
210
0
                rReq.Done();
211
0
                break;
212
0
            }
213
0
        case SID_ATTR_PARA_LINESPACE:
214
0
            {
215
0
                SvxLineSpacingItem aParaMargin = static_cast<const SvxLineSpacingItem&>(pNewAttrs->Get(
216
0
                                                            GetPool().GetWhichIDFromSlotID(nSlot)));
217
0
                aParaMargin.SetWhich( EE_PARA_SBL );
218
219
0
                aNewAttr.Put(aParaMargin);
220
0
                rReq.Done();
221
0
                break;
222
0
            }
223
0
        case SID_ATTR_PARA_ULSPACE:
224
0
            {
225
0
                SvxULSpaceItem aULSpace = static_cast<const SvxULSpaceItem&>(pNewAttrs->Get(
226
0
                    GetPool().GetWhichIDFromSlotID(nSlot)));
227
0
                aULSpace.SetWhich( EE_PARA_ULSPACE );
228
0
                aNewAttr.Put( aULSpace );
229
0
                rReq.Done();
230
0
            }
231
0
            break;
232
0
        case FN_GROW_FONT_SIZE:
233
0
        case FN_SHRINK_FONT_SIZE:
234
0
        {
235
0
            const SfxObjectShell* pObjSh = SfxObjectShell::Current();
236
0
            const SvxFontListItem* pFontListItem = (pObjSh ? pObjSh->GetItem(SID_ATTR_CHAR_FONTLIST) : nullptr);
237
0
            const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
238
0
            pOLV->GetEditView().ChangeFontSize( nSlot == FN_GROW_FONT_SIZE, pFontList );
239
0
        }
240
0
        break;
241
242
0
        case SID_ATTR_CHAR_FONT:
243
0
        case SID_ATTR_CHAR_FONTHEIGHT:
244
0
        case SID_ATTR_CHAR_WEIGHT:
245
0
        case SID_ATTR_CHAR_POSTURE:
246
0
            {
247
0
                SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
248
0
                if( !pSecondPool )
249
0
                    pSecondPool = aEditAttr.GetPool();
250
0
                SvxScriptSetItem aSetItem( nSlot, *pSecondPool );
251
0
                aSetItem.PutItemForScriptType( pOLV->GetSelectedScriptType(), pNewAttrs->Get( nWhich ));
252
0
                aNewAttr.Put( aSetItem.GetItemSet() );
253
0
                rReq.Done();
254
0
                break;
255
0
            }
256
0
        case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
257
258
0
        case SID_ATTR_CHAR_COLOR2:
259
0
        {
260
0
            if (!rReq.GetArgs())
261
0
            {
262
0
                const std::optional<NamedColor> oColor
263
0
                    = m_rView.GetDocShell()->GetRecentColor(SID_ATTR_CHAR_COLOR);
264
0
                if (oColor.has_value())
265
0
                {
266
0
                    nEEWhich = GetPool().GetWhichIDFromSlotID(SID_ATTR_CHAR_COLOR);
267
0
                    const model::ComplexColor aCol = (*oColor).getComplexColor();
268
0
                    aNewAttr.Put(SvxColorItem(aCol.getFinalColor(), aCol, nEEWhich));
269
0
                    rReq.SetArgs(aNewAttr);
270
0
                    rReq.SetSlot(SID_ATTR_CHAR_COLOR);
271
0
                }
272
0
            }
273
0
            break;
274
0
        }
275
0
        case SID_ATTR_CHAR_BACK_COLOR:
276
0
        {
277
0
            nEEWhich = GetPool().GetWhichIDFromSlotID(nSlot);
278
0
            if (!rReq.GetArgs())
279
0
            {
280
0
                const std::optional<NamedColor> oColor
281
0
                    = m_rView.GetDocShell()->GetRecentColor(nSlot);
282
0
                if (oColor.has_value())
283
0
                {
284
0
                    const model::ComplexColor aCol = (*oColor).getComplexColor();
285
0
                    aNewAttr.Put(SvxColorItem(aCol.getFinalColor(), aCol, nEEWhich));
286
0
                }
287
0
            }
288
0
            break;
289
0
        }
290
0
        case SID_ATTR_CHAR_UNDERLINE:
291
0
        {
292
0
            if( rReq.GetArgs() )
293
0
            {
294
0
                const SvxUnderlineItem* pItem = rReq.GetArg(SID_ATTR_CHAR_UNDERLINE);
295
0
                if (pItem)
296
0
                {
297
0
                    aNewAttr.Put(*pItem);
298
0
                }
299
0
                else
300
0
                {
301
0
                    FontLineStyle eFU = aEditAttr.Get( EE_CHAR_UNDERLINE ).GetLineStyle();
302
0
                    aNewAttr.Put( SvxUnderlineItem( eFU != LINESTYLE_NONE ?LINESTYLE_NONE : LINESTYLE_SINGLE,  EE_CHAR_UNDERLINE ) );
303
0
                }
304
0
            }
305
0
            break;
306
0
        }
307
0
        case SID_ATTR_CHAR_OVERLINE:
308
0
        {
309
0
            FontLineStyle eFO = aEditAttr.Get(EE_CHAR_OVERLINE).GetLineStyle();
310
0
            aNewAttr.Put(SvxOverlineItem(eFO == LINESTYLE_SINGLE ? LINESTYLE_NONE : LINESTYLE_SINGLE, EE_CHAR_OVERLINE));
311
0
            break;
312
0
        }
313
0
        case SID_ATTR_CHAR_CONTOUR:     nEEWhich = EE_CHAR_OUTLINE; break;
314
0
        case SID_ATTR_CHAR_SHADOWED:    nEEWhich = EE_CHAR_SHADOW; break;
315
0
        case SID_ATTR_CHAR_STRIKEOUT:   nEEWhich = EE_CHAR_STRIKEOUT; break;
316
0
        case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
317
0
        case SID_ATTR_CHAR_RELIEF      : nEEWhich = EE_CHAR_RELIEF;  break;
318
0
        case SID_ATTR_CHAR_LANGUAGE    : nEEWhich = EE_CHAR_LANGUAGE;break;
319
0
        case SID_ATTR_CHAR_KERNING     : nEEWhich = EE_CHAR_KERNING; break;
320
0
        case SID_ATTR_CHAR_SCALEWIDTH:   nEEWhich = EE_CHAR_FONTWIDTH; break;
321
0
        case SID_ATTR_CHAR_AUTOKERN  :   nEEWhich = EE_CHAR_PAIRKERNING; break;
322
0
        case SID_ATTR_CHAR_ESCAPEMENT:   nEEWhich = EE_CHAR_ESCAPEMENT; break;
323
0
        case SID_ATTR_PARA_AUTOFRAMEDIRECTION: nEEWhich = EE_PARA_AUTOWRITINGDIR; break;
324
0
        case SID_ATTR_PARA_ADJUST_LEFT:
325
0
            aNewAttr.Put(SvxAdjustItem(SvxAdjust::Left, EE_PARA_JUST));
326
0
        break;
327
0
        case SID_ATTR_PARA_ADJUST_CENTER:
328
0
            aNewAttr.Put(SvxAdjustItem(SvxAdjust::Center, EE_PARA_JUST));
329
0
        break;
330
0
        case SID_ATTR_PARA_ADJUST_RIGHT:
331
0
            aNewAttr.Put(SvxAdjustItem(SvxAdjust::Right, EE_PARA_JUST));
332
0
        break;
333
0
        case SID_ATTR_PARA_ADJUST_BLOCK:
334
0
            aNewAttr.Put(SvxAdjustItem(SvxAdjust::Block, EE_PARA_JUST));
335
0
        break;
336
0
        case SID_ATTR_PARA_ADJUST_START:
337
0
            aNewAttr.Put(SvxAdjustItem(SvxAdjust::ParaStart, EE_PARA_JUST));
338
0
        break;
339
0
        case SID_ATTR_PARA_ADJUST_END:
340
0
            aNewAttr.Put(SvxAdjustItem(SvxAdjust::ParaEnd, EE_PARA_JUST));
341
0
        break;
342
343
0
        case SID_ATTR_PARA_LINESPACE_10:
344
0
        {
345
0
            SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
346
0
            aItem.SetPropLineSpace(100);
347
0
            aNewAttr.Put(aItem);
348
0
        }
349
0
        break;
350
0
        case SID_ATTR_PARA_LINESPACE_115:
351
0
        {
352
0
            SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
353
0
            aItem.SetPropLineSpace(115);
354
0
            aNewAttr.Put(aItem);
355
0
        }
356
0
        break;
357
0
        case SID_ATTR_PARA_LINESPACE_15:
358
0
        {
359
0
            SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
360
0
            aItem.SetPropLineSpace(150);
361
0
            aNewAttr.Put(aItem);
362
0
        }
363
0
        break;
364
0
        case SID_ATTR_PARA_LINESPACE_20:
365
0
        {
366
0
            SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
367
0
            aItem.SetPropLineSpace(200);
368
0
            aNewAttr.Put(aItem);
369
0
        }
370
0
        break;
371
0
        case SID_SELECTALL:
372
0
        {
373
0
            Outliner& rOutliner = pOLV->GetOutliner();
374
0
            sal_Int32 nParaCount = rOutliner.GetParagraphCount();
375
0
            if (nParaCount > 0)
376
0
                pOLV->SelectRange(0, nParaCount );
377
0
            break;
378
0
        }
379
0
        case FN_FORMAT_RESET:
380
0
        {
381
0
            pPostItMgr->GetActiveSidebarWin()->ResetAttributes();
382
0
            rReq.Done();
383
0
            break;
384
0
        }
385
0
        case FN_SET_SUPER_SCRIPT:
386
0
        {
387
0
            SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
388
0
            SvxEscapement eEsc = aEditAttr.Get(EE_CHAR_ESCAPEMENT).GetEscapement();
389
390
0
            if( eEsc == SvxEscapement::Superscript )
391
0
                aItem.SetEscapement( SvxEscapement::Off );
392
0
            else
393
0
                aItem.SetEscapement( SvxEscapement::Superscript );
394
0
            aNewAttr.Put( aItem );
395
0
        }
396
0
        break;
397
0
        case FN_SET_SUB_SCRIPT:
398
0
        {
399
0
            SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
400
0
            SvxEscapement eEsc = aEditAttr.Get(EE_CHAR_ESCAPEMENT).GetEscapement();
401
402
0
            if( eEsc == SvxEscapement::Subscript )
403
0
                aItem.SetEscapement( SvxEscapement::Off );
404
0
            else
405
0
                aItem.SetEscapement( SvxEscapement::Subscript );
406
0
            aNewAttr.Put( aItem );
407
0
        }
408
0
        break;
409
0
        case SID_HYPERLINK_SETLINK:
410
0
        {
411
0
            const SfxPoolItem* pItem = nullptr;
412
0
            if(pNewAttrs)
413
0
                pNewAttrs->GetItemState(nSlot, false, &pItem);
414
415
0
            if(pItem)
416
0
            {
417
0
                const SvxHyperlinkItem& rHLinkItem = *static_cast<const SvxHyperlinkItem *>(pItem);
418
0
                SvxURLField aField(rHLinkItem.GetURL(), rHLinkItem.GetName(), SvxURLFormat::AppDefault);
419
0
                aField.SetTargetFrame(rHLinkItem.GetTargetFrame());
420
421
0
                const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
422
423
0
                if (pFieldItem && dynamic_cast<const SvxURLField *>(pFieldItem->GetField()) != nullptr)
424
0
                {
425
                    // Select the field so that it will be deleted during insert
426
0
                    ESelection aSel = pOLV->GetSelection();
427
0
                    aSel.end.nIndex++;
428
0
                    pOLV->SetSelection(aSel);
429
0
                }
430
0
                if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
431
0
                    pOLV->InsertField(SvxFieldItem(aField, EE_FEATURE_FIELD));
432
0
            }
433
0
            break;
434
0
        }
435
0
        case FN_INSERT_SOFT_HYPHEN:
436
0
        case FN_INSERT_HARDHYPHEN:
437
0
        case FN_INSERT_HARD_SPACE:
438
0
        case FN_INSERT_NNBSP:
439
0
        case SID_INSERT_RLM :
440
0
        case SID_INSERT_LRM :
441
0
        case SID_INSERT_WJ :
442
0
        case SID_INSERT_ZWSP:
443
0
        {
444
0
            sal_Unicode cIns = 0;
445
0
            switch(rReq.GetSlot())
446
0
            {
447
0
                case FN_INSERT_SOFT_HYPHEN: cIns = CHAR_SOFTHYPHEN; break;
448
0
                case FN_INSERT_HARDHYPHEN: cIns = CHAR_HARDHYPHEN; break;
449
0
                case FN_INSERT_HARD_SPACE: cIns = CHAR_HARDBLANK; break;
450
0
                case FN_INSERT_NNBSP: cIns = CHAR_NNBSP; break;
451
0
                case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
452
0
                case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
453
0
                case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
454
0
                case SID_INSERT_WJ: cIns = CHAR_WJ; break;
455
0
            }
456
0
            pOLV->InsertText( OUString(cIns));
457
0
            rReq.Done();
458
0
            break;
459
0
        }
460
0
        case SID_CHARMAP:
461
0
        {
462
0
            if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
463
0
                InsertSymbol(rReq);
464
0
            break;
465
0
        }
466
0
        case FN_INSERT_STRING:
467
0
        {
468
0
            const SfxPoolItem* pItem = nullptr;
469
0
            if (pNewAttrs)
470
0
                pNewAttrs->GetItemState(nSlot, false, &pItem );
471
0
            if (pItem && pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
472
0
                pOLV->InsertText(static_cast<const SfxStringItem *>(pItem)->GetValue());
473
0
            break;
474
0
        }
475
0
        case FN_FORMAT_FOOTNOTE_DLG:
476
0
        {
477
0
            m_rView.ExecFormatFootnote();
478
0
            break;
479
0
        }
480
0
        case FN_NUMBERING_OUTLINE_DLG:
481
0
        {
482
0
            m_rView.ExecNumberingOutline(GetPool());
483
0
            rReq.Done();
484
0
        }
485
0
        break;
486
0
        case SID_OPEN_XML_FILTERSETTINGS:
487
0
        {
488
0
            HandleOpenXmlFilterSettings(rReq);
489
0
        }
490
0
        break;
491
0
        case FN_WORDCOUNT_DIALOG:
492
0
        {
493
0
            m_rView.UpdateWordCount(this, nSlot);
494
0
            break;
495
0
        }
496
0
        case SID_CHAR_DLG_EFFECT:
497
0
        case SID_CHAR_DLG_POSITION:
498
0
        case SID_CHAR_DLG:
499
0
        {
500
0
            const SfxItemSet* pArgs = rReq.GetArgs();
501
0
            const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
502
503
0
            if( !pArgs || pItem )
504
0
            {
505
                /* mod
506
                SwView* pView = &GetView();
507
                FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( pView) !=  nullptr );
508
                SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
509
                */
510
0
                SfxItemSet aDlgAttr(SfxItemSet::makeFixedSfxItemSet<XATTR_FILLSTYLE, XATTR_FILLCOLOR, EE_ITEMS_START, EE_ITEMS_END>(GetPool()));
511
512
                // util::Language does not exist in the EditEngine! Therefore not included in the set.
513
514
0
                aDlgAttr.Put( aEditAttr );
515
0
                aDlgAttr.Put( SvxKerningItem(0, RES_CHRATR_KERNING) );
516
517
0
                SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
518
0
                VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSwCharDlg(m_rView.GetFrameWeld(), m_rView, aDlgAttr, SwCharDlgMode::Ann));
519
0
                if (nSlot == SID_CHAR_DLG_EFFECT)
520
0
                {
521
0
                    pDlg->SetCurPageId(u"fonteffects"_ustr);
522
0
                }
523
0
                if (nSlot == SID_CHAR_DLG_POSITION)
524
0
                {
525
0
                    pDlg->SetCurPageId(u"position"_ustr);
526
0
                }
527
0
                else if (pItem)
528
0
                {
529
0
                    pDlg->SetCurPageId(pItem->GetValue());
530
0
                }
531
532
0
                auto xRequest = std::make_shared<SfxRequest>(rReq);
533
0
                rReq.Ignore(); // the 'old' request is not relevant any more
534
0
                pDlg->StartExecuteAsync(
535
0
                    [this, pDlg, xRequest=std::move(xRequest), nEEWhich,
536
0
                     aNewAttr2=std::move(aNewAttr), pOLV] (sal_Int32 nResult) mutable ->void
537
0
                    {
538
0
                        if (nResult == RET_OK)
539
0
                        {
540
0
                            xRequest->Done( *( pDlg->GetOutputItemSet() ) );
541
0
                            aNewAttr2.Put(*pDlg->GetOutputItemSet());
542
0
                            ExecPost(*xRequest, nEEWhich, aNewAttr2, pOLV);
543
0
                        }
544
0
                        pDlg->disposeOnce();
545
0
                    }
546
0
                );
547
0
                return;
548
0
            }
549
0
            else
550
0
                aNewAttr.Put(*pArgs);
551
0
            break;
552
0
        }
553
0
        case SID_PARA_DLG:
554
0
        {
555
0
            const SfxItemSet* pArgs = rReq.GetArgs();
556
557
0
            if (!pArgs)
558
0
            {
559
                /* mod todo ???
560
                SwView* pView = &GetView();
561
                FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( pView) !=  nullptr );
562
                SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
563
                */
564
0
                SfxItemSet aDlgAttr(SfxItemSet::makeFixedSfxItemSet<
565
0
                    EE_ITEMS_START, EE_ITEMS_END,
566
0
                    SID_ATTR_PARA_HYPHENZONE, SID_ATTR_PARA_WIDOWS>(GetPool()));
567
568
0
                aDlgAttr.Put(aEditAttr);
569
570
0
                aDlgAttr.Put( SvxHyphenZoneItem( false, RES_PARATR_HYPHENZONE) );
571
0
                aDlgAttr.Put( SvxFormatBreakItem( SvxBreak::NONE, RES_BREAK ) );
572
0
                aDlgAttr.Put( SvxFormatSplitItem( true, RES_PARATR_SPLIT ) );
573
0
                aDlgAttr.Put( SvxWidowsItem( 0, RES_PARATR_WIDOWS ) );
574
0
                aDlgAttr.Put( SvxOrphansItem( 0, RES_PARATR_ORPHANS ) );
575
576
0
                SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
577
0
                ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSwParaDlg(m_rView.GetFrameWeld(), m_rView, aDlgAttr, true));
578
0
                sal_uInt16 nRet = pDlg->Execute();
579
0
                if(RET_OK == nRet)
580
0
                {
581
0
                    rReq.Done( *( pDlg->GetOutputItemSet() ) );
582
0
                    aNewAttr.Put(*pDlg->GetOutputItemSet());
583
0
                }
584
0
                if(RET_OK != nRet)
585
0
                    return;
586
0
            }
587
0
            else
588
0
                aNewAttr.Put(*pArgs);
589
0
            break;
590
0
        }
591
592
0
        case SID_AUTOSPELL_CHECK:
593
0
        {
594
0
            m_rView.ExecuteSlot(rReq);
595
0
            break;
596
0
        }
597
0
        case SID_ATTR_PARA_LEFT_TO_RIGHT:
598
0
        case SID_ATTR_PARA_RIGHT_TO_LEFT:
599
0
        {
600
0
            bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
601
602
0
            const SfxPoolItem* pPoolItem;
603
0
            if( pNewAttrs && SfxItemState::SET == pNewAttrs->GetItemState( nSlot, true, &pPoolItem ) )
604
0
            {
605
0
                if (bLeftToRight)
606
0
                {
607
0
                    if( !pPoolItem->StaticWhichCast(SID_ATTR_PARA_LEFT_TO_RIGHT).GetValue() )
608
0
                        bLeftToRight = !bLeftToRight;
609
0
                }
610
0
                else
611
0
                {
612
0
                    if( !pPoolItem->StaticWhichCast(SID_ATTR_PARA_RIGHT_TO_LEFT).GetValue() )
613
0
                        bLeftToRight = !bLeftToRight;
614
0
                }
615
0
            }
616
0
            SfxItemSet aAttr(SfxItemSet::makeFixedSfxItemSet<
617
0
                EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
618
0
                EE_PARA_AUTOWRITINGDIR, EE_PARA_AUTOWRITINGDIR>(*aNewAttr.GetPool()));
619
620
0
            auto eFrameDirection = bLeftToRight ? SvxFrameDirection::Horizontal_LR_TB
621
0
                                                : SvxFrameDirection::Horizontal_RL_TB;
622
0
            aAttr.Put(SvxFrameDirectionItem{ eFrameDirection, EE_PARA_WRITINGDIR });
623
624
            // tdf#162120: The paragraph direction has been manually set by the user.
625
            // Don't automatically adjust the paragraph direction anymore.
626
0
            aAttr.Put(SvxAutoFrameDirectionItem{ false, EE_PARA_AUTOWRITINGDIR });
627
628
0
            pOLV->SetAttribs(aAttr);
629
0
            break;
630
0
        }
631
0
    }
632
633
0
    ExecPost(rReq, nEEWhich, aNewAttr, pOLV );
634
0
}
635
636
void SwAnnotationShell::ExecPost( const SfxRequest& rReq, sal_uInt16 nEEWhich, SfxItemSet& rNewAttr, OutlinerView* pOLV )
637
0
{
638
0
    const SfxItemSet *pNewAttrs = rReq.GetArgs();
639
0
    const sal_uInt16 nSlot = rReq.GetSlot();
640
0
    const sal_uInt16 nWhich = GetPool().GetWhichIDFromSlotID(nSlot);
641
642
0
    if(nEEWhich && pNewAttrs)
643
0
    {
644
0
        rNewAttr.Put(pNewAttrs->Get(nWhich).CloneSetWhich(nEEWhich));
645
0
    }
646
0
    else if (nEEWhich == EE_CHAR_COLOR)
647
0
    {
648
0
        m_rView.GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG_EFFECT);
649
0
    }
650
0
    else if (nEEWhich == EE_CHAR_KERNING)
651
0
    {
652
0
        m_rView.GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG_POSITION);
653
0
    }
654
655
656
0
    tools::Rectangle aOutRect = pOLV->GetOutputArea();
657
0
    if (tools::Rectangle() != aOutRect && rNewAttr.Count())
658
0
        pOLV->SetAttribs(rNewAttr);
659
660
0
    m_rView.GetViewFrame().GetBindings().InvalidateAll(false);
661
0
    if ( pOLV->GetOutliner().IsModified() )
662
0
        m_rView.GetWrtShell().SetModified();
663
0
}
664
665
void SwAnnotationShell::GetState(SfxItemSet& rSet)
666
0
{
667
    //TODO: clean this up!!!
668
    // FN_SET_SUPER_SCRIPT
669
    //SID_ATTR_PARA_ADJUST
670
    //SID_ATTR_PARA_ADJUST_BLOCK
671
672
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
673
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
674
0
        return;
675
676
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
677
0
    SfxItemSet aEditAttr(pOLV->GetAttribs());
678
679
0
    SfxWhichIter aIter(rSet);
680
0
    sal_uInt16 nWhich = aIter.FirstWhich();
681
0
    while(nWhich)
682
0
    {
683
0
        sal_uInt16 nEEWhich = 0;
684
0
        sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
685
0
        switch( nSlotId )
686
0
        {
687
0
            case SID_ATTR_PARA_LRSPACE:
688
0
            case SID_ATTR_PARA_LEFTSPACE:
689
0
            case SID_ATTR_PARA_RIGHTSPACE:
690
0
            case SID_ATTR_PARA_FIRSTLINESPACE:
691
0
            {
692
0
                SfxItemState eState = aEditAttr.GetItemState( EE_PARA_LRSPACE );
693
0
                if( eState >= SfxItemState::DEFAULT )
694
0
                {
695
0
                    SvxLRSpaceItem aLR = aEditAttr.Get( EE_PARA_LRSPACE );
696
0
                    aLR.SetWhich(nSlotId);
697
0
                    rSet.Put(aLR);
698
0
                }
699
0
                else
700
0
                    rSet.InvalidateItem(nSlotId);
701
0
            }
702
0
            break;
703
0
            case SID_ATTR_PARA_LINESPACE:
704
0
            {
705
0
                SfxItemState eState = aEditAttr.GetItemState( EE_PARA_SBL );
706
0
                if( eState >= SfxItemState::DEFAULT )
707
0
                {
708
0
                    const SvxLineSpacingItem& aLR = aEditAttr.Get( EE_PARA_SBL );
709
0
                    rSet.Put(aLR);
710
0
                }
711
0
                else
712
0
                    rSet.InvalidateItem(nSlotId);
713
0
            }
714
0
            break;
715
0
            case SID_ATTR_PARA_ULSPACE:
716
0
            case SID_ATTR_PARA_ABOVESPACE:
717
0
            case SID_ATTR_PARA_BELOWSPACE:
718
0
            case SID_PARASPACE_INCREASE:
719
0
            case SID_PARASPACE_DECREASE:
720
0
                {
721
0
                    SfxItemState eState = aEditAttr.GetItemState( EE_PARA_ULSPACE );
722
0
                    if( eState >= SfxItemState::DEFAULT )
723
0
                    {
724
0
                        SvxULSpaceItem aULSpace = aEditAttr.Get( EE_PARA_ULSPACE );
725
0
                        if ( !aULSpace.GetUpper() && !aULSpace.GetLower() )
726
0
                            rSet.DisableItem( SID_PARASPACE_DECREASE );
727
0
                        else if ( aULSpace.GetUpper() >= 5670 && aULSpace.GetLower() >= 5670 )
728
0
                            rSet.DisableItem( SID_PARASPACE_INCREASE );
729
0
                        if ( nSlotId == SID_ATTR_PARA_ULSPACE
730
0
                            || nSlotId == SID_ATTR_PARA_BELOWSPACE
731
0
                            || nSlotId == SID_ATTR_PARA_ABOVESPACE
732
0
                        )
733
0
                        {
734
0
                            aULSpace.SetWhich(nSlotId);
735
0
                            rSet.Put(aULSpace);
736
0
                        }
737
0
                    }
738
0
                    else
739
0
                    {
740
0
                        rSet.DisableItem( SID_PARASPACE_INCREASE );
741
0
                        rSet.DisableItem( SID_PARASPACE_DECREASE );
742
0
                        rSet.InvalidateItem( SID_ATTR_PARA_ULSPACE );
743
0
                        rSet.InvalidateItem( SID_ATTR_PARA_ABOVESPACE );
744
0
                        rSet.InvalidateItem( SID_ATTR_PARA_BELOWSPACE );
745
0
                    }
746
0
                }
747
0
                break;
748
0
            case SID_ATTR_CHAR_FONT:
749
0
            case SID_ATTR_CHAR_FONTHEIGHT:
750
0
            case SID_ATTR_CHAR_WEIGHT:
751
0
            case SID_ATTR_CHAR_POSTURE:
752
0
                {
753
0
                    SvtScriptType nScriptType = pOLV->GetSelectedScriptType();
754
0
                    SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
755
0
                    if( !pSecondPool )
756
0
                        pSecondPool = aEditAttr.GetPool();
757
0
                    SvxScriptSetItem aSetItem( nSlotId, *pSecondPool );
758
0
                    aSetItem.GetItemSet().Put( aEditAttr, false );
759
0
                    const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
760
0
                    if( pI )
761
0
                    {
762
0
                        rSet.Put(pI->CloneSetWhich(nWhich));
763
0
                    }
764
0
                    else
765
0
                        rSet.InvalidateItem( nWhich );
766
0
                }
767
0
                break;
768
0
            case SID_ATTR_CHAR_COLOR2:
769
0
            case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
770
0
            case SID_ATTR_CHAR_BACK_COLOR: nEEWhich = EE_CHAR_BKGCOLOR; break;
771
0
            case SID_ATTR_CHAR_UNDERLINE: nEEWhich = EE_CHAR_UNDERLINE;break;
772
0
            case SID_ATTR_CHAR_OVERLINE: nEEWhich = EE_CHAR_OVERLINE;break;
773
0
            case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
774
0
            case SID_ATTR_CHAR_SHADOWED:  nEEWhich = EE_CHAR_SHADOW;break;
775
0
            case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT;break;
776
0
            case SID_ATTR_CHAR_LANGUAGE    : nEEWhich = EE_CHAR_LANGUAGE;break;
777
0
            case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT;break;
778
0
            case SID_ATTR_CHAR_KERNING:  nEEWhich = EE_CHAR_KERNING;break;
779
0
            case FN_SET_SUPER_SCRIPT:
780
0
            case FN_SET_SUB_SCRIPT:
781
0
            {
782
0
                SvxEscapement nEsc;
783
0
                if (nWhich==FN_SET_SUPER_SCRIPT)
784
0
                    nEsc = SvxEscapement::Superscript;
785
0
                else
786
0
                    nEsc = SvxEscapement::Subscript;
787
788
0
                const SfxPoolItem *pEscItem = &aEditAttr.Get( EE_CHAR_ESCAPEMENT );
789
0
                if( nEsc == static_cast<const SvxEscapementItem*>(pEscItem)->GetEscapement() )
790
0
                    rSet.Put( SfxBoolItem( nWhich, true ));
791
0
                else
792
0
                    rSet.InvalidateItem( nWhich );
793
0
                break;
794
0
            }
795
0
            case SID_ATTR_PARA_ADJUST_LEFT:
796
0
            case SID_ATTR_PARA_ADJUST_RIGHT:
797
0
            case SID_ATTR_PARA_ADJUST_CENTER:
798
0
            case SID_ATTR_PARA_ADJUST_BLOCK:
799
0
            case SID_ATTR_PARA_ADJUST_START:
800
0
            case SID_ATTR_PARA_ADJUST_END:
801
0
                {
802
0
                    SvxAdjust eAdjust = SvxAdjust::Left;
803
0
                    if (nWhich==SID_ATTR_PARA_ADJUST_LEFT)
804
0
                        eAdjust = SvxAdjust::Left;
805
0
                    else if (nWhich==SID_ATTR_PARA_ADJUST_RIGHT)
806
0
                        eAdjust = SvxAdjust::Right;
807
0
                    else if (nWhich==SID_ATTR_PARA_ADJUST_CENTER)
808
0
                        eAdjust = SvxAdjust::Center;
809
0
                    else if (nWhich==SID_ATTR_PARA_ADJUST_BLOCK)
810
0
                        eAdjust = SvxAdjust::Block;
811
0
                    else if (nWhich==SID_ATTR_PARA_ADJUST_START)
812
0
                        eAdjust = SvxAdjust::ParaStart;
813
0
                    else if (nWhich==SID_ATTR_PARA_ADJUST_END)
814
0
                        eAdjust = SvxAdjust::ParaEnd;
815
816
0
                    const SvxAdjustItem *pAdjust = aEditAttr.GetItemIfSet( EE_PARA_JUST, false );
817
818
0
                    if( !pAdjust || IsInvalidItem( pAdjust ))
819
0
                    {
820
0
                        rSet.InvalidateItem( nSlotId );
821
0
                    }
822
0
                    else
823
0
                    {
824
0
                        if ( eAdjust == pAdjust->GetAdjust())
825
0
                            rSet.Put( SfxBoolItem( nWhich, true ));
826
0
                        else
827
0
                            rSet.InvalidateItem( nWhich );
828
0
                    }
829
0
                    break;
830
0
                }
831
0
            case SID_ATTR_PARA_LINESPACE_10:
832
0
            case SID_ATTR_PARA_LINESPACE_115:
833
0
            case SID_ATTR_PARA_LINESPACE_15:
834
0
            case SID_ATTR_PARA_LINESPACE_20:
835
0
                {
836
0
                    int nLSpace = 0;
837
0
                    if (nWhich==SID_ATTR_PARA_LINESPACE_10)
838
0
                        nLSpace = 100;
839
0
                    else if (nWhich==SID_ATTR_PARA_LINESPACE_115)
840
0
                        nLSpace = 115;
841
0
                    else if (nWhich==SID_ATTR_PARA_LINESPACE_15)
842
0
                        nLSpace = 150;
843
0
                    else if (nWhich==SID_ATTR_PARA_LINESPACE_20)
844
0
                        nLSpace = 200;
845
846
0
                    const SvxLineSpacingItem *pLSpace = aEditAttr.GetItemIfSet( EE_PARA_SBL, false );
847
848
0
                    if( !pLSpace || IsInvalidItem( pLSpace ))
849
0
                    {
850
0
                        rSet.InvalidateItem( nSlotId );
851
0
                    }
852
0
                    else
853
0
                    {
854
0
                        if( nLSpace == pLSpace->GetPropLineSpace() )
855
0
                            rSet.Put( SfxBoolItem( nWhich, true ));
856
0
                        else
857
0
                        {
858
                            // tdf#114631 - disable non selected line spacing
859
0
                            rSet.Put(SfxBoolItem(nWhich, false));
860
0
                        }
861
0
                    }
862
0
                    break;
863
0
                }
864
0
            case SID_AUTOSPELL_CHECK:
865
0
            {
866
0
                const SfxPoolItemHolder aResult(m_rView.GetSlotState(nWhich));
867
0
                if (aResult)
868
0
                    rSet.Put(SfxBoolItem(nWhich, static_cast<const SfxBoolItem*>(aResult.getItem())->GetValue()));
869
0
                else
870
0
                    rSet.DisableItem( nWhich );
871
0
                break;
872
0
            }
873
0
            case SID_ATTR_PARA_LEFT_TO_RIGHT:
874
0
            case SID_ATTR_PARA_RIGHT_TO_LEFT:
875
0
            {
876
0
                if ( !SvtCTLOptions::IsCTLFontEnabled() )
877
0
                    rSet.DisableItem( nWhich );
878
0
                else
879
0
                {
880
0
                    if (pOLV->GetOutliner().IsVertical())
881
0
                        rSet.DisableItem( nWhich );
882
0
                    else
883
0
                    {
884
0
                        bool bFlag = false;
885
0
                        switch( aEditAttr.Get( EE_PARA_WRITINGDIR ).GetValue() )
886
0
                        {
887
0
                            case SvxFrameDirection::Horizontal_LR_TB:
888
0
                            {
889
0
                                bFlag = nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT;
890
0
                                rSet.Put( SfxBoolItem( nWhich, bFlag ));
891
0
                                break;
892
0
                            }
893
0
                            case SvxFrameDirection::Horizontal_RL_TB:
894
0
                            {
895
0
                                bFlag = nWhich != SID_ATTR_PARA_LEFT_TO_RIGHT;
896
0
                                rSet.Put( SfxBoolItem( nWhich, bFlag ));
897
0
                                break;
898
0
                            }
899
0
                            default:
900
0
                                break;
901
0
                        }
902
0
                    }
903
0
                }
904
0
            }
905
0
            break;
906
0
            case SID_INSERT_RLM :
907
0
            case SID_INSERT_LRM :
908
0
            {
909
0
                bool bEnabled = SvtCTLOptions::IsCTLFontEnabled();
910
0
                m_rView.GetViewFrame().GetBindings().SetVisibleState( nWhich, bEnabled );
911
0
                if(!bEnabled)
912
0
                    rSet.DisableItem(nWhich);
913
0
            }
914
0
            break;
915
0
            default:
916
0
                rSet.InvalidateItem( nWhich );
917
0
                break;
918
0
        }
919
920
0
        if(nEEWhich)
921
0
        {
922
0
            rSet.Put(aEditAttr.Get(nEEWhich).CloneSetWhich(nWhich));
923
0
            if(nEEWhich == EE_CHAR_KERNING)
924
0
            {
925
0
                SfxItemState eState = aEditAttr.GetItemState( EE_CHAR_KERNING );
926
0
                if ( eState == SfxItemState::INVALID )
927
0
                {
928
0
                    rSet.InvalidateItem(EE_CHAR_KERNING);
929
0
                }
930
0
            }
931
0
        }
932
933
0
        if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
934
0
            rSet.DisableItem( nWhich );
935
936
0
        nWhich = aIter.NextWhich();
937
0
    }
938
0
}
939
940
void SwAnnotationShell::ExecSearch(SfxRequest& rReq)
941
0
{
942
0
    m_rView.ExecSearch(rReq);
943
0
}
944
945
void SwAnnotationShell::StateSearch(SfxItemSet &rSet)
946
0
{
947
0
    m_rView.StateSearch(rSet);
948
0
}
949
950
void SwAnnotationShell::ExecClpbrd(SfxRequest const &rReq)
951
0
{
952
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
953
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
954
0
        return;
955
956
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
957
958
0
    tools::Long aOldHeight = pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight();
959
0
    sal_uInt16 nSlot = rReq.GetSlot();
960
0
    switch (nSlot)
961
0
    {
962
0
        case SID_CUT:
963
0
            if ( (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED) && pOLV->HasSelection() )
964
0
                pOLV->Cut();
965
0
            break;
966
0
        case SID_COPY:
967
0
            if( pOLV->HasSelection() )
968
0
                pOLV->Copy();
969
0
            break;
970
0
        case SID_PASTE:
971
0
            if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
972
0
                pOLV->PasteSpecial();
973
0
            break;
974
0
        case SID_PASTE_UNFORMATTED:
975
0
            if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
976
0
                pOLV->Paste();
977
0
            break;
978
0
        case SID_PASTE_SPECIAL:
979
0
        {
980
0
            if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
981
0
            {
982
0
                SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
983
0
                ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(m_rView.GetEditWin().GetFrameWeld()));
984
985
0
                pDlg->Insert( SotClipboardFormatId::STRING, OUString() );
986
0
                pDlg->Insert( SotClipboardFormatId::RTF,    OUString() );
987
0
                pDlg->Insert( SotClipboardFormatId::RICHTEXT,    OUString() );
988
989
0
                TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &m_rView.GetEditWin() ) );
990
991
0
                SotClipboardFormatId nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
992
993
0
                if (nFormat != SotClipboardFormatId::NONE)
994
0
                {
995
0
                    if (nFormat == SotClipboardFormatId::STRING)
996
0
                        pOLV->Paste();
997
0
                    else
998
0
                        pOLV->PasteSpecial();
999
0
                }
1000
0
            }
1001
0
            break;
1002
0
        }
1003
0
        case SID_CLIPBOARD_FORMAT_ITEMS:
1004
0
        {
1005
0
            SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
1006
0
            const SfxPoolItem* pItem;
1007
0
            if (rReq.GetArgs() && rReq.GetArgs()->GetItemState(nSlot, true, &pItem) == SfxItemState::SET)
1008
0
            {
1009
0
                if (const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item *>(pItem))
1010
0
                    nFormat = static_cast<SotClipboardFormatId>(pUInt32Item->GetValue());
1011
0
            }
1012
1013
0
            if ( nFormat != SotClipboardFormatId::NONE )
1014
0
            {
1015
0
                if (SotClipboardFormatId::STRING == nFormat)
1016
0
                    pOLV->Paste();
1017
0
                else
1018
0
                    pOLV->PasteSpecial();
1019
0
            }
1020
0
            break;
1021
0
        }
1022
0
    }
1023
0
    pPostItMgr->GetActiveSidebarWin()->ResizeIfNecessary(aOldHeight,pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight());
1024
0
}
1025
1026
void SwAnnotationShell::StateClpbrd(SfxItemSet &rSet)
1027
0
{
1028
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1029
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1030
0
        return;
1031
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1032
1033
0
    TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &m_rView.GetEditWin() ) );
1034
0
    bool bPastePossible = ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) || aDataHelper.HasFormat( SotClipboardFormatId::RTF )
1035
0
        || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ));
1036
0
    bPastePossible = bPastePossible &&  (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED);
1037
1038
0
    SfxWhichIter aIter(rSet);
1039
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1040
1041
0
    while(nWhich)
1042
0
    {
1043
0
        switch(nWhich)
1044
0
        {
1045
0
            case SID_CUT:
1046
0
            {
1047
0
                if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus() == SwPostItHelper::DELETED)
1048
0
                    rSet.DisableItem( nWhich );
1049
0
                [[fallthrough]];
1050
0
            }
1051
0
            case SID_COPY:
1052
0
            {
1053
0
                SfxObjectShell* pObjectShell = GetObjectShell();
1054
0
                if (!pOLV->HasSelection() || (pObjectShell && pObjectShell->isContentExtractionLocked()) )
1055
0
                    rSet.DisableItem( nWhich );
1056
0
                break;
1057
0
            }
1058
0
            case SID_PASTE:
1059
0
            case SID_PASTE_UNFORMATTED:
1060
0
            case SID_PASTE_SPECIAL:
1061
0
                {
1062
0
                    if( !bPastePossible )
1063
0
                        rSet.DisableItem( nWhich );
1064
0
                    break;
1065
0
                }
1066
0
            case SID_CLIPBOARD_FORMAT_ITEMS:
1067
0
                {
1068
0
                    if ( bPastePossible )
1069
0
                    {
1070
0
                        SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
1071
0
                        if ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) )
1072
0
                            aFormats.AddClipbrdFormat( SotClipboardFormatId::RTF );
1073
0
                        if ( aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) )
1074
0
                            aFormats.AddClipbrdFormat( SotClipboardFormatId::RICHTEXT );
1075
0
                        aFormats.AddClipbrdFormat( SotClipboardFormatId::STRING );
1076
0
                        rSet.Put( aFormats );
1077
0
                    }
1078
0
                    else
1079
0
                        rSet.DisableItem( nWhich );
1080
0
                    break;
1081
0
                }
1082
0
        }
1083
0
        nWhich = aIter.NextWhich();
1084
0
    }
1085
0
}
1086
1087
void SwAnnotationShell::StateStatusLine(SfxItemSet &rSet)
1088
0
{
1089
0
    SfxWhichIter aIter( rSet );
1090
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1091
1092
0
    while( nWhich )
1093
0
    {
1094
0
        switch( nWhich )
1095
0
        {
1096
0
            case FN_STAT_SELMODE:
1097
0
            {
1098
0
                rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 0));
1099
0
                rSet.DisableItem( nWhich );
1100
0
                break;
1101
0
            }
1102
0
            case FN_STAT_TEMPLATE:
1103
0
            {
1104
0
                rSet.DisableItem( nWhich );
1105
0
                break;
1106
0
            }
1107
0
        }
1108
0
        nWhich = aIter.NextWhich();
1109
0
    }
1110
0
}
1111
1112
void SwAnnotationShell::StateInsert(SfxItemSet &rSet)
1113
0
{
1114
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1115
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1116
0
        return;
1117
1118
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1119
0
    SfxWhichIter aIter(rSet);
1120
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1121
1122
0
    while(nWhich)
1123
0
    {
1124
0
        switch(nWhich)
1125
0
        {
1126
0
            case SID_HYPERLINK_GETLINK:
1127
0
                {
1128
0
                    SvxHyperlinkItem aHLinkItem;
1129
0
                    aHLinkItem.SetShowName(false);
1130
0
                    aHLinkItem.SetShowText(true);
1131
0
                    aHLinkItem.SetInsertMode(HLINK_FIELD);
1132
1133
0
                    const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
1134
1135
0
                    if (pFieldItem)
1136
0
                    {
1137
0
                        if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField *>(pFieldItem->GetField()))
1138
0
                        {
1139
0
                            aHLinkItem.SetName(pURLField->GetRepresentation());
1140
0
                            aHLinkItem.SetURL(pURLField->GetURL());
1141
0
                            aHLinkItem.SetTargetFrame(pURLField->GetTargetFrame());
1142
0
                        }
1143
0
                    }
1144
0
                    else
1145
0
                    {
1146
0
                        OUString sSel(pOLV->GetSelected());
1147
0
                        sSel = sSel.copy(0, std::min<sal_Int32>(255, sSel.getLength()));
1148
0
                        aHLinkItem.SetName(comphelper::string::stripEnd(sSel, ' '));
1149
0
                    }
1150
1151
0
                    sal_uInt16 nHtmlMode = ::GetHtmlMode(m_rView.GetDocShell());
1152
0
                    aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
1153
0
                        ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
1154
1155
0
                    rSet.Put(aHLinkItem);
1156
0
                }
1157
0
                break;
1158
0
        }
1159
1160
0
        if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1161
0
            rSet.DisableItem( nWhich );
1162
1163
0
        nWhich = aIter.NextWhich();
1164
0
    }
1165
0
}
1166
1167
void SwAnnotationShell::NoteExec(SfxRequest const &rReq)
1168
0
{
1169
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1170
0
    if ( !pPostItMgr )
1171
0
        return;
1172
1173
0
    sal_uInt16 nSlot = rReq.GetSlot();
1174
0
    switch (nSlot)
1175
0
    {
1176
0
        case FN_REPLY:
1177
0
        case FN_POSTIT:
1178
0
        case FN_DELETE_COMMENT:
1179
0
        case FN_DELETE_COMMENT_THREAD:
1180
0
        case FN_RESOLVE_NOTE:
1181
0
        case FN_RESOLVE_NOTE_THREAD:
1182
0
        case FN_PROMOTE_COMMENT:
1183
0
            if ( pPostItMgr->HasActiveSidebarWin() )
1184
0
                pPostItMgr->GetActiveSidebarWin()->ExecuteCommand(nSlot);
1185
0
            break;
1186
0
        case FN_DELETE_ALL_NOTES:
1187
0
            pPostItMgr->Delete();
1188
0
            break;
1189
0
        case FN_FORMAT_ALL_NOTES:
1190
0
            pPostItMgr->ExecuteFormatAllDialog(m_rView);
1191
0
            break;
1192
0
        case FN_DELETE_NOTE_AUTHOR:
1193
0
        {
1194
0
            const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot);
1195
0
            if ( pItem )
1196
0
                pPostItMgr->Delete( pItem->GetValue() );
1197
0
            else if ( pPostItMgr->HasActiveSidebarWin() )
1198
0
                pPostItMgr->Delete( pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1199
0
            break;
1200
0
        }
1201
0
        case FN_HIDE_NOTE:
1202
0
            break;
1203
0
        case FN_HIDE_ALL_NOTES:
1204
0
            pPostItMgr->Hide();
1205
0
            break;
1206
0
        case FN_HIDE_NOTE_AUTHOR:
1207
0
        {
1208
0
            const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot);
1209
0
            if ( pItem )
1210
0
                pPostItMgr->Hide( pItem->GetValue() );
1211
0
            else if ( pPostItMgr->HasActiveSidebarWin() )
1212
0
                pPostItMgr->Hide( pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1213
0
        }
1214
0
    }
1215
0
}
1216
1217
void SwAnnotationShell::GetNoteState(SfxItemSet &rSet)
1218
0
{
1219
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1220
0
    SfxWhichIter aIter(rSet);
1221
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1222
0
    while(nWhich)
1223
0
    {
1224
0
        sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
1225
0
        switch( nSlotId )
1226
0
        {
1227
0
        case FN_POSTIT:
1228
0
        case FN_DELETE_ALL_NOTES:
1229
0
        case FN_FORMAT_ALL_NOTES:
1230
0
        case FN_HIDE_NOTE:
1231
0
        case FN_HIDE_ALL_NOTES:
1232
0
        case FN_DELETE_COMMENT:
1233
0
        case FN_DELETE_COMMENT_THREAD:
1234
0
            {
1235
0
                if( !pPostItMgr
1236
0
                    || !pPostItMgr->HasActiveAnnotationWin() )
1237
0
                {
1238
0
                    rSet.DisableItem(nWhich);
1239
0
                }
1240
0
                break;
1241
0
            }
1242
0
        case FN_RESOLVE_NOTE:
1243
0
            {
1244
0
                if( !pPostItMgr
1245
0
                    || !pPostItMgr->HasActiveAnnotationWin() )
1246
0
                {
1247
0
                    rSet.DisableItem(nWhich);
1248
0
                }
1249
0
                else
1250
0
                {
1251
0
                    SfxBoolItem aBool(nWhich, pPostItMgr->GetActiveSidebarWin()->IsResolved());
1252
0
                    rSet.Put( aBool );
1253
0
                }
1254
0
                break;
1255
0
            }
1256
0
        case FN_RESOLVE_NOTE_THREAD:
1257
0
            {
1258
0
                if( !pPostItMgr
1259
0
                    || !pPostItMgr->HasActiveAnnotationWin() )
1260
0
                {
1261
0
                    rSet.DisableItem(nWhich);
1262
0
                }
1263
0
                else
1264
0
                {
1265
0
                    SfxBoolItem aBool(nWhich, pPostItMgr->GetActiveSidebarWin()->IsThreadResolved());
1266
0
                    rSet.Put( aBool );
1267
0
                }
1268
0
                break;
1269
0
            }
1270
0
        case FN_DELETE_NOTE_AUTHOR:
1271
0
        case FN_HIDE_NOTE_AUTHOR:
1272
0
        {
1273
0
            if( !pPostItMgr
1274
0
                || !pPostItMgr->HasActiveAnnotationWin() )
1275
0
            {
1276
0
                rSet.DisableItem(nWhich);
1277
0
            }
1278
0
            else
1279
0
            {
1280
0
                OUString aText( nSlotId == FN_DELETE_NOTE_AUTHOR ?
1281
0
                                SwResId( STR_DELETE_NOTE_AUTHOR ) : SwResId( STR_HIDE_NOTE_AUTHOR ) );
1282
0
                SwRewriter aRewriter;
1283
0
                aRewriter.AddRule( UndoArg1, pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1284
0
                aText = aRewriter.Apply( aText );
1285
0
                SfxStringItem aItem( nSlotId, aText );
1286
0
                rSet.Put( aItem );
1287
0
            }
1288
0
            break;
1289
0
        }
1290
0
        case FN_REPLY:
1291
0
            {
1292
0
                if ( !pPostItMgr ||
1293
0
                     !pPostItMgr->HasActiveAnnotationWin() )
1294
0
                {
1295
0
                    rSet.DisableItem(nWhich);
1296
0
                }
1297
0
                else
1298
0
                {
1299
0
                    SvtUserOptions aUserOpt;
1300
0
                    OUString sAuthor;
1301
0
                    if( (sAuthor = aUserOpt.GetFullName()).isEmpty() &&
1302
0
                        (sAuthor = aUserOpt.GetID()).isEmpty() )
1303
0
                        sAuthor = SwResId( STR_REDLINE_UNKNOWN_AUTHOR );
1304
0
                    if (sAuthor == pPostItMgr->GetActiveSidebarWin()->GetAuthor())
1305
0
                        rSet.DisableItem(nWhich);
1306
0
                }
1307
0
                break;
1308
0
            }
1309
0
        case FN_PROMOTE_COMMENT:
1310
0
            {
1311
0
                if (!pPostItMgr || !pPostItMgr->HasActiveAnnotationWin()
1312
0
                    || pPostItMgr->GetActiveSidebarWin()->IsRootNote())
1313
0
                {
1314
0
                    rSet.DisableItem(nWhich);
1315
0
                }
1316
0
                break;
1317
0
            }
1318
0
            default:
1319
0
                rSet.InvalidateItem( nWhich );
1320
0
                break;
1321
0
        }
1322
1323
0
        if (pPostItMgr && pPostItMgr->HasActiveSidebarWin())
1324
0
        {
1325
0
            if ( (pPostItMgr->GetActiveSidebarWin()->IsReadOnlyOrProtected()) &&
1326
0
                    ( (nSlotId==FN_DELETE_COMMENT) || (nSlotId==FN_REPLY) ) )
1327
0
                rSet.DisableItem( nWhich );
1328
0
        }
1329
0
        nWhich = aIter.NextWhich();
1330
0
    }
1331
0
}
1332
1333
void SwAnnotationShell::ExecLingu(SfxRequest &rReq)
1334
0
{
1335
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1336
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1337
0
        return;
1338
1339
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1340
0
    sal_uInt16 nSlot = rReq.GetSlot();
1341
0
    SwWrtShell &rSh = m_rView.GetWrtShell();
1342
0
    bool bRestoreSelection = false;
1343
0
    ESelection aOldSelection;
1344
1345
0
    switch (nSlot)
1346
0
    {
1347
0
        case SID_LANGUAGE_STATUS:
1348
0
        {
1349
0
            aOldSelection = pOLV->GetSelection();
1350
0
            if (!pOLV->GetEditView().HasSelection())
1351
0
            {
1352
0
                pOLV->GetEditView().SelectCurrentWord();
1353
0
            }
1354
1355
0
            bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,m_rView,rSh);
1356
0
            break;
1357
0
        }
1358
0
        case SID_THES:
1359
0
        {
1360
0
            OUString aReplaceText;
1361
0
            const SfxStringItem* pItem2 = rReq.GetArg(FN_PARAM_THES_WORD_REPLACE);
1362
0
            if (pItem2)
1363
0
                aReplaceText = pItem2->GetValue();
1364
0
            if (!aReplaceText.isEmpty())
1365
0
                ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText );
1366
0
            break;
1367
0
        }
1368
0
        case SID_THESAURUS:
1369
0
        {
1370
0
            pOLV->StartThesaurus(rReq.GetFrameWeld());
1371
0
            break;
1372
0
        }
1373
0
        case SID_HANGUL_HANJA_CONVERSION:
1374
0
            pOLV->StartTextConversion(rReq.GetFrameWeld(), LANGUAGE_KOREAN, LANGUAGE_KOREAN, nullptr,
1375
0
                    i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true, false);
1376
0
            break;
1377
1378
0
        case SID_CHINESE_CONVERSION:
1379
0
        {
1380
            //open ChineseTranslationDialog
1381
0
            rtl::Reference< textconversiondlgs::ChineseTranslation_UnoDialog > xDialog(new textconversiondlgs::ChineseTranslation_UnoDialog({}));
1382
1383
            //execute dialog
1384
0
            sal_Int16 nDialogRet = xDialog->execute();
1385
0
            if( RET_OK == nDialogRet )
1386
0
            {
1387
                //get some parameters from the dialog
1388
0
                bool bToSimplified = xDialog->getIsDirectionToSimplified();
1389
0
                bool bCommonTerms = xDialog->getIsTranslateCommonTerms();
1390
1391
                //execute translation
1392
0
                LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1393
0
                LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1394
0
                sal_Int32 nOptions       = !bCommonTerms ? i18n::TextConversionOption::CHARACTER_BY_CHARACTER : 0;
1395
1396
0
                vcl::Font aTargetFont = OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT,
1397
0
                            nTargetLang, GetDefaultFontFlags::OnlyOne );
1398
1399
0
                pOLV->StartTextConversion(rReq.GetFrameWeld(), nSourceLang, nTargetLang, &aTargetFont, nOptions, false, false);
1400
0
            }
1401
0
        }
1402
0
        break;
1403
0
    }
1404
1405
0
    if (bRestoreSelection)
1406
0
    {
1407
        // restore selection
1408
0
        pOLV->GetEditView().SetSelection( aOldSelection );
1409
0
    }
1410
0
}
1411
1412
void SwAnnotationShell::GetLinguState(SfxItemSet &rSet)
1413
0
{
1414
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1415
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1416
0
        return;
1417
1418
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1419
1420
0
    SfxWhichIter aIter(rSet);
1421
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1422
0
    while(nWhich)
1423
0
    {
1424
0
        switch (nWhich)
1425
0
        {
1426
0
            case SID_LANGUAGE_STATUS:
1427
0
            {
1428
0
                SwLangHelper::GetLanguageStatus(pOLV,rSet);
1429
0
                break;
1430
0
            }
1431
1432
0
            case SID_THES:
1433
0
            {
1434
0
                OUString        aStatusVal;
1435
0
                LanguageType    nLang = LANGUAGE_NONE;
1436
0
                bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() );
1437
0
                rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
1438
1439
                // disable "Thesaurus" context menu entry if there is nothing to look up
1440
0
                uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
1441
0
                if (!bIsLookUpWord ||
1442
0
                    !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( LanguageTag::convertToLocale( nLang ) ))
1443
0
                    rSet.DisableItem( SID_THES );
1444
0
                break;
1445
0
            }
1446
1447
            // disable "Thesaurus" if the language is not supported
1448
0
            case SID_THESAURUS:
1449
0
            {
1450
0
                TypedWhichId<SvxLanguageItem> nLangWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE,
1451
0
                            SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
1452
0
                const SvxLanguageItem &rItem = m_rView.GetWrtShell().GetDoc()->GetDefault(nLangWhich);
1453
0
                LanguageType nLang = rItem.GetLanguage();
1454
0
                uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
1455
0
                if (!xThes.is() || nLang == LANGUAGE_NONE ||
1456
0
                    !xThes->hasLocale( LanguageTag::convertToLocale( nLang ) ))
1457
0
                    rSet.DisableItem( SID_THESAURUS );
1458
0
            }
1459
0
            break;
1460
0
            case SID_HANGUL_HANJA_CONVERSION:
1461
0
            case SID_CHINESE_CONVERSION:
1462
0
            {
1463
0
                if (!SvtCJKOptions::IsAnyEnabled())
1464
0
                {
1465
0
                    m_rView.GetViewFrame().GetBindings().SetVisibleState( nWhich, false );
1466
0
                    rSet.DisableItem(nWhich);
1467
0
                }
1468
0
                else
1469
0
                    m_rView.GetViewFrame().GetBindings().SetVisibleState( nWhich, true );
1470
0
            }
1471
0
            break;
1472
0
        }
1473
1474
0
        if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1475
0
            rSet.DisableItem( nWhich );
1476
1477
0
        nWhich = aIter.NextWhich();
1478
0
    }
1479
0
}
1480
1481
void SwAnnotationShell::ExecTransliteration(SfxRequest const &rReq)
1482
0
{
1483
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1484
0
    if (!pPostItMgr || !pPostItMgr->HasActiveSidebarWin())
1485
0
        return;
1486
1487
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1488
1489
0
    if (!pOLV)
1490
0
        return;
1491
1492
0
    TransliterationFlags nMode = TransliterationFlags::NONE;
1493
1494
0
    switch( rReq.GetSlot() )
1495
0
    {
1496
0
        case SID_TRANSLITERATE_SENTENCE_CASE:
1497
0
            nMode = TransliterationFlags::SENTENCE_CASE;
1498
0
            break;
1499
0
        case SID_TRANSLITERATE_TITLE_CASE:
1500
0
            nMode = TransliterationFlags::TITLE_CASE;
1501
0
            break;
1502
0
        case SID_TRANSLITERATE_TOGGLE_CASE:
1503
0
            nMode = TransliterationFlags::TOGGLE_CASE;
1504
0
            break;
1505
0
        case SID_TRANSLITERATE_UPPER:
1506
0
            nMode = TransliterationFlags::LOWERCASE_UPPERCASE;
1507
0
            break;
1508
0
        case SID_TRANSLITERATE_LOWER:
1509
0
            nMode = TransliterationFlags::UPPERCASE_LOWERCASE;
1510
0
            break;
1511
0
        case SID_TRANSLITERATE_HALFWIDTH:
1512
0
            nMode = TransliterationFlags::FULLWIDTH_HALFWIDTH;
1513
0
            break;
1514
0
        case SID_TRANSLITERATE_FULLWIDTH:
1515
0
            nMode = TransliterationFlags::HALFWIDTH_FULLWIDTH;
1516
0
            break;
1517
0
        case SID_TRANSLITERATE_HIRAGANA:
1518
0
            nMode = TransliterationFlags::KATAKANA_HIRAGANA;
1519
0
            break;
1520
0
        case SID_TRANSLITERATE_KATAKANA:
1521
0
            nMode = TransliterationFlags::HIRAGANA_KATAKANA;
1522
0
            break;
1523
1524
0
        default:
1525
0
            OSL_ENSURE(false, "wrong dispatcher");
1526
0
    }
1527
1528
0
    if( nMode != TransliterationFlags::NONE )
1529
0
        pOLV->TransliterateText( nMode );
1530
0
}
1531
1532
void SwAnnotationShell::ExecRotateTransliteration( SfxRequest const & rReq )
1533
0
{
1534
0
    if( rReq.GetSlot() != SID_TRANSLITERATE_ROTATE_CASE )
1535
0
        return;
1536
1537
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1538
0
    if (!pPostItMgr || !pPostItMgr->HasActiveSidebarWin())
1539
0
        return;
1540
1541
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1542
1543
0
    if (!pOLV)
1544
0
        return;
1545
1546
0
    pOLV->TransliterateText(m_aRotateCase.getNextMode());
1547
0
}
1548
1549
void SwAnnotationShell::ExecUndo(SfxRequest &rReq)
1550
0
{
1551
0
    const SfxItemSet* pArgs = rReq.GetArgs();
1552
0
    SfxUndoManager* pUndoManager = GetUndoManager();
1553
0
    SwWrtShell &rSh = m_rView.GetWrtShell();
1554
0
    SwUndoId nUndoId(SwUndoId::EMPTY);
1555
1556
    // tdf#147928 get these before "undo" which may delete this SwAnnotationShell
1557
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1558
0
    SfxBindings& rBindings = m_rView.GetViewFrame().GetBindings();
1559
1560
0
    tools::Long aOldHeight = pPostItMgr->HasActiveSidebarWin()
1561
0
                      ? pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight()
1562
0
                      : 0;
1563
1564
0
    sal_uInt16 nId = rReq.GetSlot();
1565
0
    sal_uInt16 nCnt = 1;
1566
0
    const SfxPoolItem* pItem=nullptr;
1567
0
    if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ) )
1568
0
        nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1569
0
    switch( nId )
1570
0
    {
1571
0
        case SID_UNDO:
1572
0
        {
1573
0
            rSh.GetLastUndoInfo(nullptr, &nUndoId);
1574
0
            if (nUndoId == SwUndoId::CONFLICT)
1575
0
            {
1576
0
                rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1577
0
                break;
1578
0
            }
1579
1580
0
            if ( pUndoManager )
1581
0
            {
1582
0
                sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1583
0
                sal_uInt16 nSteps = nCnt;
1584
0
                if ( nCount < nCnt )
1585
0
                {
1586
0
                    nCnt = nCnt - nCount;
1587
0
                    nSteps = nCount;
1588
0
                }
1589
0
                else
1590
0
                    nCnt = 0;
1591
1592
0
                while( nSteps-- )
1593
0
                    pUndoManager->Undo();
1594
0
            }
1595
1596
0
            if ( nCnt )
1597
0
                rSh.Do( SwWrtShell::UNDO, nCnt );
1598
1599
0
            break;
1600
0
        }
1601
1602
0
        case SID_REDO:
1603
0
        {
1604
0
            (void)rSh.GetFirstRedoInfo(nullptr, &nUndoId);
1605
0
            if (nUndoId == SwUndoId::CONFLICT)
1606
0
            {
1607
0
                rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1608
0
                break;
1609
0
            }
1610
1611
0
            if ( pUndoManager )
1612
0
            {
1613
0
                sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1614
0
                sal_uInt16 nSteps = nCnt;
1615
0
                if ( nCount < nCnt )
1616
0
                {
1617
0
                    nCnt = nCnt - nCount;
1618
0
                    nSteps = nCount;
1619
0
                }
1620
0
                else
1621
0
                    nCnt = 0;
1622
1623
0
                while( nSteps-- )
1624
0
                    pUndoManager->Redo();
1625
0
            }
1626
1627
0
            if ( nCnt )
1628
0
                rSh.Do( SwWrtShell::REDO, nCnt );
1629
1630
0
            break;
1631
0
        }
1632
0
    }
1633
1634
0
    rBindings.InvalidateAll(false);
1635
1636
0
    if (pPostItMgr->HasActiveSidebarWin())
1637
0
        pPostItMgr->GetActiveSidebarWin()->ResizeIfNecessary(aOldHeight, pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight());
1638
0
}
1639
1640
void SwAnnotationShell::StateUndo(SfxItemSet &rSet)
1641
0
{
1642
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1643
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1644
0
        return;
1645
1646
0
    SfxWhichIter aIter(rSet);
1647
0
    SwUndoId nUndoId(SwUndoId::EMPTY);
1648
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1649
0
    SfxUndoManager* pUndoManager = GetUndoManager();
1650
0
    SfxViewFrame& rSfxViewFrame = m_rView.GetViewFrame();
1651
0
    SwWrtShell &rSh = m_rView.GetWrtShell();
1652
1653
0
    while( nWhich )
1654
0
    {
1655
0
        switch ( nWhich )
1656
0
        {
1657
0
        case SID_UNDO:
1658
0
            {
1659
0
                sal_uInt16 nCount = pUndoManager ? pUndoManager->GetUndoActionCount() : 0;
1660
0
                if ( nCount )
1661
0
                    rSfxViewFrame.GetSlotState( nWhich, rSfxViewFrame.GetInterface(), &rSet );
1662
0
                else if (rSh.GetLastUndoInfo(nullptr, &nUndoId))
1663
0
                {
1664
0
                    rSet.Put( SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::UNDO)) );
1665
0
                }
1666
0
                else if (nUndoId == SwUndoId::CONFLICT)
1667
0
                {
1668
0
                    rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1669
0
                }
1670
0
                else
1671
0
                    rSet.DisableItem(nWhich);
1672
0
                break;
1673
0
            }
1674
0
        case SID_REDO:
1675
0
            {
1676
0
                sal_uInt16 nCount = pUndoManager ? pUndoManager->GetRedoActionCount() : 0;
1677
0
                if ( nCount )
1678
0
                    rSfxViewFrame.GetSlotState( nWhich, rSfxViewFrame.GetInterface(), &rSet );
1679
0
                else if (rSh.GetFirstRedoInfo(nullptr, &nUndoId))
1680
0
                {
1681
0
                    rSet.Put(SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::REDO)) );
1682
0
                }
1683
0
                else if (nUndoId == SwUndoId::CONFLICT)
1684
0
                {
1685
0
                    rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1686
0
                }
1687
0
                else
1688
0
                    rSet.DisableItem(nWhich);
1689
0
                break;
1690
0
            }
1691
0
        case SID_GETUNDOSTRINGS:
1692
0
        case SID_GETREDOSTRINGS:
1693
0
            {
1694
0
                if( pUndoManager )
1695
0
                {
1696
0
                    OUString (SfxUndoManager::*fnGetComment)( size_t, bool const ) const;
1697
1698
0
                    sal_uInt16 nCount;
1699
0
                    if( SID_GETUNDOSTRINGS == nWhich )
1700
0
                    {
1701
0
                        nCount = pUndoManager->GetUndoActionCount();
1702
0
                        fnGetComment = &SfxUndoManager::GetUndoActionComment;
1703
0
                    }
1704
0
                    else
1705
0
                    {
1706
0
                        nCount = pUndoManager->GetRedoActionCount();
1707
0
                        fnGetComment = &SfxUndoManager::GetRedoActionComment;
1708
0
                    }
1709
1710
0
                    OUStringBuffer sList;
1711
0
                    if( nCount )
1712
0
                    {
1713
0
                        for( sal_uInt16 n = 0; n < nCount; ++n )
1714
0
                            sList.append( (pUndoManager->*fnGetComment)( n, SfxUndoManager::TopLevel ) + "\n");
1715
0
                    }
1716
1717
0
                    SfxStringListItem aItem( nWhich );
1718
0
                    if ((nWhich == SID_GETUNDOSTRINGS) &&
1719
0
                        rSh.GetLastUndoInfo(nullptr, nullptr))
1720
0
                    {
1721
0
                        rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1722
0
                    }
1723
0
                    else if ((nWhich == SID_GETREDOSTRINGS) &&
1724
0
                             (rSh.GetFirstRedoInfo(nullptr, nullptr)))
1725
0
                    {
1726
0
                        rSh.GetDoStrings( SwWrtShell::REDO, aItem );
1727
0
                    }
1728
1729
0
                    sList.append(aItem.GetString());
1730
0
                    aItem.SetString( sList.makeStringAndClear() );
1731
0
                    rSet.Put( aItem );
1732
0
                }
1733
0
                else
1734
0
                    rSet.DisableItem( nWhich );
1735
0
            }
1736
0
            break;
1737
1738
0
        default:
1739
0
            {
1740
0
                rSfxViewFrame.GetSlotState( nWhich, rSfxViewFrame.GetInterface(), &rSet );
1741
0
                break;
1742
0
            }
1743
1744
0
        }
1745
1746
0
        if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1747
0
            rSet.DisableItem( nWhich );
1748
1749
0
        nWhich = aIter.NextWhich();
1750
0
    }
1751
0
}
1752
1753
void SwAnnotationShell::StateDisableItems( SfxItemSet &rSet )
1754
0
{
1755
0
    SfxWhichIter aIter(rSet);
1756
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1757
0
    while (nWhich)
1758
0
    {
1759
0
        rSet.DisableItem( nWhich );
1760
0
        nWhich = aIter.NextWhich();
1761
0
    }
1762
0
}
1763
1764
void SwAnnotationShell::InsertSymbol(SfxRequest& rReq)
1765
0
{
1766
0
    SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1767
0
    if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1768
0
        return;
1769
1770
0
    OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1771
1772
0
    const SfxItemSet *pArgs = rReq.GetArgs();
1773
0
    const SfxStringItem* pCharMapItem = nullptr;
1774
0
    if( pArgs )
1775
0
        pCharMapItem = pArgs->GetItemIfSet(SID_CHARMAP, false);
1776
1777
0
    OUString sSym;
1778
0
    OUString sFontName;
1779
0
    if ( pCharMapItem )
1780
0
    {
1781
0
        sSym = pCharMapItem->GetValue();
1782
0
        const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false);
1783
0
        if (pFontItem)
1784
0
            sFontName = pFontItem->GetValue();
1785
0
    }
1786
1787
0
    SfxItemSet aSet(pOLV->GetAttribs());
1788
0
    SvtScriptType nScript = pOLV->GetSelectedScriptType();
1789
0
    std::shared_ptr<SvxFontItem> aSetDlgFont(std::make_shared<SvxFontItem>(RES_CHRATR_FONT));
1790
0
    {
1791
0
        SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1792
0
        aSetItem.GetItemSet().Put( aSet, false );
1793
0
        const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1794
0
        if( pI )
1795
0
        {
1796
0
            aSetDlgFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
1797
0
        }
1798
0
        else
1799
0
        {
1800
0
            TypedWhichId<SvxFontItem> nFontWhich =
1801
0
                GetWhichOfScript(
1802
0
                        SID_ATTR_CHAR_FONT,
1803
0
                        SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
1804
0
            aSetDlgFont.reset(aSet.Get(nFontWhich).Clone());
1805
0
        }
1806
1807
0
        if (sFontName.isEmpty())
1808
0
            sFontName = aSetDlgFont->GetFamilyName();
1809
0
    }
1810
1811
0
    vcl::Font aFont(sFontName, Size(1,1));
1812
0
    if( sSym.isEmpty() )
1813
0
    {
1814
0
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1815
1816
0
        SfxAllItemSet aAllSet( GetPool() );
1817
0
        aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
1818
1819
0
        SwViewOption aOpt(*m_rView.GetWrtShell().GetViewOptions());
1820
0
        const OUString& sSymbolFont = aOpt.GetSymbolFont();
1821
0
        if( !sSymbolFont.isEmpty() )
1822
0
            aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
1823
0
        else
1824
0
            aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont->GetFamilyName() ) );
1825
1826
        // If character is selected then it can be shown.
1827
0
        auto xFrame = m_rView.GetViewFrame().GetFrame().GetFrameInterface();
1828
0
        VclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(m_rView.GetFrameWeld(), aAllSet, xFrame));
1829
0
        pDlg->StartExecuteAsync(
1830
0
            [pDlg] (sal_Int32 /*nResult*/)->void
1831
0
            {
1832
0
                pDlg->disposeOnce();
1833
0
            }
1834
0
        );
1835
0
        return;
1836
0
    }
1837
1838
    // do not flicker
1839
0
    pOLV->HideCursor();
1840
0
    Outliner& rOutliner = pOLV->GetOutliner();
1841
0
    rOutliner.SetUpdateLayout(false);
1842
1843
0
    SfxItemSet aOldSet( pOLV->GetAttribs() );
1844
0
    SfxItemSet aFontSet(SfxItemSet::makeFixedSfxItemSet<
1845
0
        EE_CHAR_FONTINFO, EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
1846
0
        EE_CHAR_FONTINFO_CTL>(*aOldSet.GetPool()));
1847
0
    aFontSet.Set( aOldSet );
1848
1849
    // Insert string
1850
0
    pOLV->InsertText( sSym);
1851
1852
    // Attributing (set font)
1853
0
    SfxItemSet aSetFont( *aFontSet.GetPool(), aFontSet.GetRanges() );
1854
0
    SvxFontItem aFontItem (aFont.GetFamilyTypeMaybeAskConfig(), aFont.GetFamilyName(),
1855
0
                            aFont.GetStyleName(), aFont.GetPitchMaybeAskConfig(),
1856
0
                            aFont.GetCharSet(),
1857
0
                            EE_CHAR_FONTINFO );
1858
0
    SvtScriptType nScriptBreak = g_pBreakIt->GetAllScriptsOfText( sSym );
1859
0
    if( SvtScriptType::LATIN & nScriptBreak )
1860
0
        aSetFont.Put( aFontItem );
1861
0
    if( SvtScriptType::ASIAN & nScriptBreak )
1862
0
    {
1863
0
        aFontItem.SetWhich(EE_CHAR_FONTINFO_CJK);
1864
0
        aSetFont.Put( aFontItem );
1865
0
    }
1866
0
    if( SvtScriptType::COMPLEX & nScriptBreak )
1867
0
    {
1868
0
        aFontItem.SetWhich(EE_CHAR_FONTINFO_CTL);
1869
0
        aSetFont.Put( aFontItem );
1870
0
    }
1871
0
    pOLV->SetAttribs(aSetFont);
1872
1873
    // Erase selection
1874
0
    ESelection aSel(pOLV->GetSelection());
1875
0
    aSel.CollapseToEnd();
1876
0
    pOLV->SetSelection(aSel);
1877
1878
    // Restore old font
1879
0
    pOLV->SetAttribs( aFontSet );
1880
1881
    // From now on show it again
1882
0
    rOutliner.SetUpdateLayout(true);
1883
0
    pOLV->ShowCursor();
1884
1885
0
    rReq.AppendItem( SfxStringItem( SID_CHARMAP, sSym ) );
1886
0
    if(!aFont.GetFamilyName().isEmpty())
1887
0
        rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetFamilyName() ) );
1888
0
    rReq.Done();
1889
1890
0
}
1891
1892
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */