Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/shells/txtattr.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 <svl/whiter.hxx>
23
#include <svl/stritem.hxx>
24
#include <svl/ctloptions.hxx>
25
#include <swmodule.hxx>
26
#include <sfx2/bindings.hxx>
27
#include <sfx2/request.hxx>
28
#include <sfx2/viewfrm.hxx>
29
#include <editeng/autodiritem.hxx>
30
#include <editeng/fhgtitem.hxx>
31
#include <editeng/adjustitem.hxx>
32
#include <editeng/lspcitem.hxx>
33
#include <editeng/lrspitem.hxx>
34
#include <editeng/udlnitem.hxx>
35
#include <editeng/escapementitem.hxx>
36
#include <editeng/pmdlitem.hxx>
37
#include <sfx2/htmlmode.hxx>
38
#include <editeng/scriptsetitem.hxx>
39
#include <editeng/frmdiritem.hxx>
40
#include <editeng/cmapitem.hxx>
41
#include <editeng/nhypitem.hxx>
42
#include <osl/diagnose.h>
43
#include <paratr.hxx>
44
45
#include <fmtinfmt.hxx>
46
#include <wrtsh.hxx>
47
#include <view.hxx>
48
#include <viewopt.hxx>
49
#include <uitool.hxx>
50
#include <textsh.hxx>
51
#include <swundo.hxx>
52
#include <fmtcol.hxx>
53
54
#include <cmdid.h>
55
#include <globals.h>
56
#include <SwStyleNameMapper.hxx>
57
#include <swabstdlg.hxx>
58
#include <memory>
59
60
const sal_uInt32 nFontInc = 40;      // 2pt
61
const sal_uInt32 nFontMaxSz = 19998; // 999.9pt
62
63
void SwTextShell::ExecCharAttr(SfxRequest &rReq)
64
0
{
65
0
    SwWrtShell &rSh = GetShell();
66
0
    const SfxItemSet  *pArgs   = rReq.GetArgs();
67
0
    int        eState = STATE_TOGGLE;
68
0
    sal_uInt16 nWhich = rReq.GetSlot();
69
70
0
    if(pArgs )
71
0
    {
72
0
        const SfxPoolItem* pItem;
73
0
        pArgs->GetItemState(nWhich, false, &pItem);
74
0
        eState =  static_cast<const SfxBoolItem &>( pArgs->
75
0
                                Get( nWhich )).GetValue() ? STATE_ON : STATE_OFF;
76
0
    }
77
78
0
    SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_CHRATR_BEGIN, RES_CHRATR_END-1>(GetPool()));
79
0
    if (STATE_TOGGLE == eState)
80
0
        rSh.GetCurAttr( aSet );
81
82
0
    switch ( nWhich )
83
0
    {
84
0
        case FN_SET_SUB_SCRIPT:
85
0
        case FN_SET_SUPER_SCRIPT:
86
0
        {
87
0
            SvxEscapement eEscape = SvxEscapement::Subscript;
88
0
            switch (eState)
89
0
            {
90
0
            case STATE_TOGGLE:
91
0
            {
92
0
                short nTmpEsc = aSet.Get( RES_CHRATR_ESCAPEMENT ).GetEsc();
93
0
                eEscape = nWhich == FN_SET_SUPER_SCRIPT ?
94
0
                                SvxEscapement::Superscript:
95
0
                                SvxEscapement::Subscript;
96
0
                if( (nWhich == FN_SET_SUB_SCRIPT && nTmpEsc < 0) ||
97
0
                            (nWhich == FN_SET_SUPER_SCRIPT && nTmpEsc > 0) )
98
0
                    eEscape = SvxEscapement::Off;
99
100
0
                SfxBindings& rBind = GetView().GetViewFrame().GetBindings();
101
0
                if( nWhich == FN_SET_SUB_SCRIPT )
102
0
                    rBind.SetState( SfxBoolItem( FN_SET_SUPER_SCRIPT,
103
0
                                                                    false ) );
104
0
                else
105
0
                    rBind.SetState( SfxBoolItem( FN_SET_SUB_SCRIPT,
106
0
                                                                    false ) );
107
108
0
            }
109
0
            break;
110
0
            case STATE_ON:
111
0
                eEscape = nWhich == FN_SET_SUPER_SCRIPT ?
112
0
                                SvxEscapement::Superscript:
113
0
                                SvxEscapement::Subscript;
114
0
                break;
115
0
            case STATE_OFF:
116
0
                eEscape = SvxEscapement::Off;
117
0
                break;
118
0
            }
119
0
            SvxEscapementItem aEscape( eEscape, RES_CHRATR_ESCAPEMENT );
120
0
            rSh.SetAttrItem( aEscape );
121
0
            rReq.AppendItem( aEscape );
122
0
            rReq.Done();
123
0
        }
124
0
        break;
125
126
0
        case FN_SET_SMALL_CAPS:
127
0
        {
128
0
            SvxCaseMap eCaseMap = SvxCaseMap::SmallCaps;
129
0
            switch (eState)
130
0
            {
131
0
            case STATE_TOGGLE:
132
0
            {
133
0
                SvxCaseMap eTmpCaseMap = aSet.Get(RES_CHRATR_CASEMAP).GetCaseMap();
134
0
                if (eTmpCaseMap == SvxCaseMap::SmallCaps)
135
0
                    eCaseMap = SvxCaseMap::NotMapped;
136
0
            }
137
0
            break;
138
0
            case STATE_ON:
139
                // Nothing to do, already set.
140
0
                break;
141
0
            case STATE_OFF:
142
0
                eCaseMap = SvxCaseMap::NotMapped;
143
0
                break;
144
0
            }
145
0
            SvxCaseMapItem aCaseMap(eCaseMap, RES_CHRATR_CASEMAP);
146
0
            rSh.SetAttrItem(aCaseMap);
147
0
            rReq.AppendItem(aCaseMap);
148
0
            rReq.Done();
149
0
        }
150
0
        break;
151
152
0
        case FN_UPDATE_STYLE_BY_EXAMPLE:
153
0
            rSh.QuickUpdateStyle();
154
0
            rReq.Done();
155
0
            break;
156
157
0
        case SID_ULINE_VAL_NONE:
158
0
        {
159
0
            SvxUnderlineItem aUnderline(LINESTYLE_NONE, RES_CHRATR_UNDERLINE );
160
0
            rSh.SetAttrItem( aUnderline );
161
0
            rReq.AppendItem( aUnderline );
162
0
            rReq.Done();
163
0
            break;
164
0
        }
165
166
0
        case SID_ULINE_VAL_SINGLE:
167
0
        case SID_ULINE_VAL_DOUBLE:
168
0
        case SID_ULINE_VAL_DOTTED:
169
0
        {
170
0
            FontLineStyle eOld = aSet.Get(RES_CHRATR_UNDERLINE).GetLineStyle();
171
0
            FontLineStyle eNew = eOld;
172
173
0
            switch (nWhich)
174
0
            {
175
0
                case SID_ULINE_VAL_SINGLE:
176
0
                    eNew = ( eOld == LINESTYLE_SINGLE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
177
0
                    break;
178
0
                case SID_ULINE_VAL_DOUBLE:
179
0
                    eNew = ( eOld == LINESTYLE_DOUBLE ) ? LINESTYLE_NONE : LINESTYLE_DOUBLE;
180
0
                    break;
181
0
                case SID_ULINE_VAL_DOTTED:
182
0
                    eNew = ( eOld == LINESTYLE_DOTTED ) ? LINESTYLE_NONE : LINESTYLE_DOTTED;
183
0
                    break;
184
0
            }
185
186
0
            SvxUnderlineItem aUnderline(eNew, RES_CHRATR_UNDERLINE );
187
0
            rSh.SetAttrItem( aUnderline );
188
0
            rReq.AppendItem( aUnderline );
189
0
            rReq.Done();
190
0
        }
191
0
        break;
192
0
        case FN_REMOVE_DIRECT_CHAR_FORMATS:
193
0
            if( !rSh.HasReadonlySel() && rSh.IsEndPara())
194
0
                rSh.DontExpandFormat();
195
0
        break;
196
0
        case FN_NO_BREAK:
197
0
        {
198
0
            bool bNoHyphen = aSet.Get(RES_CHRATR_NOHYPHEN).GetValue();
199
0
            SvxNoHyphenItem aNoHyphen( !bNoHyphen, RES_CHRATR_NOHYPHEN );
200
0
            rSh.SetAttrItem( aNoHyphen );
201
0
        }
202
0
        break;
203
0
        default:
204
0
            OSL_FAIL("wrong  dispatcher");
205
0
            return;
206
0
    }
207
0
}
208
209
void SwTextShell::ExecCharAttrArgs(SfxRequest &rReq)
210
0
{
211
0
    sal_uInt16 nSlot = rReq.GetSlot();
212
0
    const SfxItemSet* pArgs = rReq.GetArgs();
213
0
    bool bArgs = pArgs != nullptr && pArgs->Count() > 0;
214
0
    SwWrtShell& rWrtSh = GetShell();
215
0
    SwTextFormatColl* pColl = nullptr;
216
217
    // Is only set if the whole paragraph is selected and AutoUpdateFormat is set.
218
0
    if (rWrtSh.HasSelection() && rWrtSh.IsSelFullPara())
219
0
    {
220
0
        pColl = rWrtSh.GetCurTextFormatColl();
221
0
        if ( pColl && !pColl->IsAutoUpdateOnDirectFormat() )
222
0
            pColl = nullptr;
223
0
    }
224
0
    SfxItemPool& rPool = GetPool();
225
0
    sal_uInt16 nWhich = rPool.GetWhichIDFromSlotID( nSlot );
226
0
    switch (nSlot)
227
0
    {
228
0
        case FN_TXTATR_INET:
229
        // Special treatment of the PoolId of the SwFormatInetFormat
230
0
        if(bArgs)
231
0
        {
232
0
            const SfxPoolItem& rItem = pArgs->Get( nWhich );
233
234
0
            SwFormatINetFormat aINetFormat( static_cast<const SwFormatINetFormat&>(rItem) );
235
0
            if ( SwPoolFormatId::UNKNOWN == aINetFormat.GetVisitedFormatId() )
236
0
            {
237
0
                OSL_ENSURE( false, "<SwTextShell::ExecCharAttrArgs(..)> - unexpected visited character format ID at hyperlink attribute" );
238
0
                aINetFormat.SetVisitedFormatAndId(
239
0
                        aINetFormat.GetVisitedFormat(),
240
0
                        SwStyleNameMapper::GetPoolIdFromUIName( aINetFormat.GetVisitedFormat(), SwGetPoolIdFromName::ChrFmt ) );
241
0
            }
242
0
            if ( SwPoolFormatId::UNKNOWN == aINetFormat.GetINetFormatId() )
243
0
            {
244
0
                OSL_ENSURE( false, "<SwTextShell::ExecCharAttrArgs(..)> - unexpected unvisited character format ID at hyperlink attribute" );
245
0
                aINetFormat.SetINetFormatAndId(
246
0
                        aINetFormat.GetINetFormat(),
247
0
                        SwStyleNameMapper::GetPoolIdFromUIName( aINetFormat.GetINetFormat(), SwGetPoolIdFromName::ChrFmt ) );
248
0
            }
249
250
0
            if ( pColl )
251
0
                pColl->SetFormatAttr( aINetFormat );
252
0
            else
253
0
                rWrtSh.SetAttrItem( aINetFormat );
254
0
            rReq.Done();
255
0
        }
256
0
        break;
257
258
0
        case FN_GROW_FONT_SIZE:
259
0
        case FN_SHRINK_FONT_SIZE:
260
0
        {
261
0
            SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONTHEIGHT, rPool );
262
0
            rWrtSh.GetCurAttr( aSetItem.GetItemSet() );
263
0
            SfxItemSet aAttrSet( rPool, aSetItem.GetItemSet().GetRanges() );
264
265
0
            SvtScriptType nScriptTypes
266
0
                = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
267
0
            const SvxFontHeightItem* pSize( static_cast<const SvxFontHeightItem*>(
268
0
                                        aSetItem.GetItemOfScript( nScriptTypes ) ) );
269
0
            std::vector<std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >> vItems;
270
            // simple case where selected text has one size and
271
            // (tdf#124919) selection is not multiple table cells
272
0
            if (pSize && !rWrtSh.IsTableMode())
273
0
            {
274
                // must create new one, otherwise document is without pam
275
0
                SwPaM* pPaM = rWrtSh.GetCursor();
276
0
                vItems.emplace_back( pSize, std::make_unique<SwPaM>( *(pPaM->GetMark()), *(pPaM->GetPoint())) );
277
0
            }
278
0
            else
279
0
                vItems = rWrtSh.GetItemWithPaM( RES_CHRATR_FONTSIZE );
280
281
0
            rWrtSh.StartUndo( SwUndoId::INSATTR );
282
0
            for( std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >& iPair : vItems )
283
0
            {
284
0
                std::unique_ptr<SwPaM> pPaM = std::move(iPair.second);
285
0
                const SfxPoolItem* pItem = iPair.first;
286
0
                aSetItem.GetItemSet().ClearItem();
287
0
                rWrtSh.GetPaMAttr( pPaM.get(), aSetItem.GetItemSet() );
288
0
                aAttrSet.SetRanges( aSetItem.GetItemSet().GetRanges() );
289
290
0
                pSize = static_cast<const SvxFontHeightItem*>( pItem );
291
0
                if (pSize)
292
0
                {
293
0
                    SvxFontHeightItem aSize(*pSize);
294
295
0
                    sal_uInt32 nSize = aSize.GetHeight();
296
297
0
                    if ( nSlot == FN_GROW_FONT_SIZE && ( nSize += nFontInc ) > nFontMaxSz )
298
0
                        nSize = nFontMaxSz;
299
0
                    else if ( nSlot == FN_SHRINK_FONT_SIZE && ( nSize -= nFontInc ) < nFontInc )
300
0
                        nSize = nFontInc;
301
302
0
                    aSize.SetHeight( nSize );
303
0
                    aSetItem.PutItemForScriptType( nScriptTypes, aSize );
304
0
                    aAttrSet.Put( aSetItem.GetItemSet() );
305
0
                    if( pColl )
306
0
                        pColl->SetFormatAttr( aAttrSet );
307
0
                    else
308
0
                        rWrtSh.SetAttrSet( aAttrSet, SetAttrMode::DEFAULT, pPaM.get() );
309
0
                }
310
0
            }
311
0
            rWrtSh.EndUndo( SwUndoId::INSATTR );
312
0
            rReq.Done();
313
0
        }
314
0
        break;
315
316
0
        default:
317
0
            OSL_FAIL("wrong  dispatcher");
318
0
            return;
319
0
    }
320
0
}
321
322
void SwTextShell::ExecParaAttr(SfxRequest &rReq)
323
0
{
324
0
    SvxAdjust eAdjst;
325
0
    sal_uInt16 ePropL;
326
0
    const SfxItemSet* pArgs = rReq.GetArgs();
327
328
    // Get both attributes immediately isn't more expensive!!
329
0
    SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_PARATR_LINESPACING, RES_PARATR_ADJUST,
330
0
                                                    RES_PARATR_HYPHENZONE, RES_PARATR_HYPHENZONE,
331
0
                                                    RES_PARATR_AUTOFRAMEDIR, RES_PARATR_AUTOFRAMEDIR,
332
0
                                                    RES_FRAMEDIR, RES_FRAMEDIR>(GetPool()));
333
0
    sal_uInt16 nSlot = rReq.GetSlot();
334
0
    switch (nSlot)
335
0
    {
336
0
        case SID_ATTR_PARA_ADJUST:
337
0
        {
338
0
            if( pArgs && SfxItemState::SET == pArgs->GetItemState(RES_PARATR_ADJUST) )
339
0
            {
340
0
                const SvxAdjustItem& rAdj = pArgs->Get(RES_PARATR_ADJUST);
341
0
                SvxAdjustItem aAdj( rAdj.GetAdjust(), RES_PARATR_ADJUST );
342
0
                if ( rAdj.GetAdjust() == SvxAdjust::Block )
343
0
                {
344
0
                    aAdj.SetLastBlock( rAdj.GetLastBlock() );
345
0
                    aAdj.SetOneWord( rAdj.GetOneWord() );
346
0
                }
347
348
0
                aSet.Put(aAdj);
349
0
            }
350
0
        }
351
0
        break;
352
0
        case SID_ATTR_PARA_ADJUST_LEFT:     eAdjst =  SvxAdjust::Left;      goto SET_ADJUST;
353
0
        case SID_ATTR_PARA_ADJUST_RIGHT:    eAdjst =  SvxAdjust::Right;     goto SET_ADJUST;
354
0
        case SID_ATTR_PARA_ADJUST_CENTER:   eAdjst =  SvxAdjust::Center;    goto SET_ADJUST;
355
0
        case SID_ATTR_PARA_ADJUST_BLOCK:    eAdjst =  SvxAdjust::Block;     goto SET_ADJUST;
356
0
        case SID_ATTR_PARA_ADJUST_START:    eAdjst =  SvxAdjust::ParaStart; goto SET_ADJUST;
357
0
        case SID_ATTR_PARA_ADJUST_END:      eAdjst =  SvxAdjust::ParaEnd;   goto SET_ADJUST;
358
0
SET_ADJUST:
359
0
        {
360
0
            aSet.Put(SvxAdjustItem(eAdjst,RES_PARATR_ADJUST));
361
0
            rReq.AppendItem( SfxBoolItem( GetPool().GetWhichIDFromSlotID(nSlot), true ) );
362
0
        }
363
0
        break;
364
365
0
        case SID_ATTR_PARA_LINESPACE:
366
0
            if(pArgs && SfxItemState::SET == pArgs->GetItemState( GetPool().GetWhichIDFromSlotID(nSlot) ))
367
0
            {
368
0
                SvxLineSpacingItem aLineSpace = static_cast<const SvxLineSpacingItem&>( pArgs->Get(
369
0
                                                            GetPool().GetWhichIDFromSlotID(nSlot)));
370
0
                aSet.Put( aLineSpace );
371
0
            }
372
0
        break;
373
0
        case SID_ATTR_PARA_LINESPACE_10:    ePropL = 100;   goto SET_LINESPACE;
374
0
        case SID_ATTR_PARA_LINESPACE_15:    ePropL = 150;   goto SET_LINESPACE;
375
0
        case SID_ATTR_PARA_LINESPACE_115:   ePropL = 115;   goto SET_LINESPACE;
376
0
        case SID_ATTR_PARA_LINESPACE_20:    ePropL = 200;   goto SET_LINESPACE;
377
378
0
SET_LINESPACE:
379
0
        {
380
381
0
            SvxLineSpacingItem aLineSpacing(ePropL, RES_PARATR_LINESPACING );
382
0
            aLineSpacing.SetLineSpaceRule( SvxLineSpaceRule::Auto );
383
0
            if( 100 == ePropL )
384
0
                aLineSpacing.SetInterLineSpaceRule( SvxInterLineSpaceRule::Off );
385
0
            else
386
0
                aLineSpacing.SetPropLineSpace(ePropL);
387
0
            aSet.Put( aLineSpacing );
388
0
        }
389
0
        break;
390
391
0
        case SID_ATTR_PARA_LEFT_TO_RIGHT :
392
0
        case SID_ATTR_PARA_RIGHT_TO_LEFT :
393
0
        {
394
0
            SvxFrameDirection eFrameDirection =
395
0
                    (SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot) ?
396
0
                        SvxFrameDirection::Horizontal_LR_TB : SvxFrameDirection::Horizontal_RL_TB;
397
0
            aSet.Put( SvxFrameDirectionItem( eFrameDirection, RES_FRAMEDIR ) );
398
399
            // tdf#162120: The paragraph direction has been manually set by the user.
400
            // Don't automatically adjust the paragraph direction anymore.
401
0
            aSet.Put(SvxAutoFrameDirectionItem(false, RES_PARATR_AUTOFRAMEDIR));
402
0
        }
403
0
        break;
404
0
        case SID_ATTR_PARA_HYPHENZONE:
405
0
        {
406
0
            SfxItemSet aHyphSet(SfxItemSet::makeFixedSfxItemSet<RES_PARATR_HYPHENZONE, RES_PARATR_HYPHENZONE>(GetPool()));
407
0
            GetShell().GetCurAttr(aHyphSet);
408
0
            SfxItemState eState = aHyphSet.GetItemState(RES_PARATR_HYPHENZONE, false);
409
0
            if ( eState >= SfxItemState::DEFAULT )
410
0
            {
411
0
                SvxHyphenZoneItem aHyphen( pArgs->Get( RES_PARATR_HYPHENZONE ) );
412
0
                aSet.Put( aHyphen );
413
0
            }
414
0
        }
415
0
        break;
416
417
0
        default:
418
0
            OSL_FAIL("wrong  dispatcher");
419
0
            return;
420
0
    }
421
0
    SwWrtShell& rWrtSh = GetShell();
422
0
    SwTextFormatColl* pColl = rWrtSh.GetCurTextFormatColl();
423
0
    if(pColl && pColl->IsAutoUpdateOnDirectFormat())
424
0
    {
425
0
        rWrtSh.AutoUpdatePara(pColl, aSet);
426
0
    }
427
0
    else
428
0
        rWrtSh.SetAttrSet( aSet, SetAttrMode::DEFAULT, nullptr, true);
429
0
    rReq.Done();
430
0
}
431
432
void SwTextShell::ExecParaAttrArgs(SfxRequest &rReq)
433
0
{
434
0
    SwWrtShell &rSh = GetShell();
435
0
    const SfxItemSet *pArgs = rReq.GetArgs();
436
0
    const SfxPoolItem *pItem = nullptr;
437
438
0
    sal_uInt16 nSlot = rReq.GetSlot();
439
0
    if(pArgs)
440
0
        pArgs->GetItemState(GetPool().GetWhichIDFromSlotID(nSlot), false, &pItem);
441
0
    switch ( nSlot )
442
0
    {
443
0
        case FN_DROP_CHAR_STYLE_NAME:
444
0
            if( pItem )
445
0
            {
446
0
                OUString sCharStyleName = static_cast<const SfxStringItem*>(pItem)->GetValue();
447
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_PARATR_DROP, RES_PARATR_DROP>(GetPool()));
448
0
                rSh.GetCurAttr(aSet);
449
0
                SwFormatDrop aDropItem(aSet.Get(RES_PARATR_DROP));
450
0
                SwCharFormat* pFormat = nullptr;
451
0
                if(!sCharStyleName.isEmpty())
452
0
                    pFormat = rSh.FindCharFormatByName( UIName(sCharStyleName) );
453
0
                aDropItem.SetCharFormat( pFormat );
454
0
                aSet.Put(aDropItem);
455
0
                rSh.SetAttrSet(aSet);
456
0
            }
457
0
        break;
458
0
        case FN_FORMAT_DROPCAPS:
459
0
        {
460
0
            if(pItem)
461
0
            {
462
0
                rSh.SetAttrItem(*pItem);
463
0
                rReq.Done();
464
0
            }
465
0
            else
466
0
            {
467
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_PARATR_DROP, RES_PARATR_DROP,
468
0
                                                                HINT_END, HINT_END>(GetPool()));
469
0
                rSh.GetCurAttr(aSet);
470
0
                SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
471
0
                ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateSwDropCapsDialog(GetView().GetFrameWeld(), aSet));
472
0
                if (pDlg->Execute() == RET_OK)
473
0
                {
474
0
                    rSh.StartAction();
475
0
                    rSh.StartUndo( SwUndoId::START );
476
0
                    if ( const SfxStringItem* pHintItem = aSet.GetItemIfSet(HINT_END,false) )
477
0
                    {
478
0
                        if ( !pHintItem->GetValue().isEmpty() )
479
0
                            rSh.ReplaceDropText(pHintItem->GetValue());
480
0
                    }
481
0
                    rSh.SetAttrSet(*pDlg->GetOutputItemSet());
482
0
                    rSh.EndUndo( SwUndoId::END );
483
0
                    rSh.EndAction();
484
0
                    rReq.Done(*pDlg->GetOutputItemSet());
485
0
                }
486
0
            }
487
0
        }
488
0
         break;
489
0
        case SID_ATTR_PARA_PAGEBREAK:
490
0
            if(pItem)
491
0
            {
492
0
                rSh.SetAttrItem( *pItem );
493
0
                rReq.Done();
494
0
            }
495
0
        break;
496
0
        case SID_ATTR_PARA_MODEL:
497
0
        {
498
0
            if(pItem)
499
0
            {
500
0
                SfxItemSet aCoreSet(SfxItemSet::makeFixedSfxItemSet<RES_PAGEDESC, RES_PAGEDESC,
501
0
                                                                    SID_ATTR_PARA_MODEL, SID_ATTR_PARA_MODEL>(GetPool()));
502
0
                aCoreSet.Put(*pItem);
503
0
                SfxToSwPageDescAttr( rSh, aCoreSet);
504
0
                rSh.SetAttrSet(aCoreSet);
505
0
                rReq.Done();
506
0
            }
507
0
        }
508
0
        break;
509
510
0
        default:
511
0
            OSL_FAIL("wrong  dispatcher");
512
0
            return;
513
0
    }
514
0
}
515
516
void SwTextShell::GetAttrState(SfxItemSet &rSet)
517
0
{
518
0
    SwWrtShell &rSh = GetShell();
519
0
    SfxItemPool& rPool = GetPool();
520
0
    SfxItemSet aCoreSet(rPool, aTextFormatCollSetRange);
521
    // Request *all* text attributes from the core.
522
    // fdo#78737: this is called from SvxRuler, which requires the list indents!
523
0
    rSh.GetCurAttr(aCoreSet, /* bMergeIndentValuesOfNumRule = */ true);
524
525
0
    SfxWhichIter aIter(rSet);
526
0
    sal_uInt16 nSlot = aIter.FirstWhich();
527
0
    bool bFlag = false;
528
0
    SfxBoolItem aFlagItem;
529
0
    const SfxPoolItem* pItem = nullptr;
530
0
    SvxAdjust eAdjust = SvxAdjust::Left;
531
0
    bool bAdjustGood = false;
532
0
    SfxItemState eState = aCoreSet.GetItemState(RES_PARATR_ADJUST, false, &pItem);
533
534
0
    if( SfxItemState::DEFAULT == eState )
535
0
        pItem = &rPool.GetUserOrPoolDefaultItem(RES_PARATR_ADJUST);
536
0
    if( SfxItemState::DEFAULT <= eState )
537
0
    {
538
0
        eAdjust = static_cast<const SvxAdjustItem* >( pItem)->GetAdjust();
539
0
        bAdjustGood = true;
540
0
    }
541
542
0
    short nEsc = 0;
543
0
    eState =  aCoreSet.GetItemState(RES_CHRATR_ESCAPEMENT, false, &pItem);
544
0
    if( SfxItemState::DEFAULT == eState )
545
0
        pItem = &rPool.GetUserOrPoolDefaultItem(RES_CHRATR_ESCAPEMENT);
546
0
    if( eState >= SfxItemState::DEFAULT )
547
0
        nEsc = static_cast<const SvxEscapementItem* >(pItem)->GetEsc();
548
549
0
    sal_uInt16 nLineSpace = 0;
550
0
    eState =  aCoreSet.GetItemState(RES_PARATR_LINESPACING, false, &pItem);
551
0
    if( SfxItemState::DEFAULT == eState )
552
0
        pItem = &rPool.GetUserOrPoolDefaultItem(RES_PARATR_LINESPACING);
553
0
    if( SfxItemState::DEFAULT <= eState &&
554
0
            static_cast<const SvxLineSpacingItem* >(pItem)->GetLineSpaceRule() == SvxLineSpaceRule::Auto )
555
0
    {
556
0
        if(SvxInterLineSpaceRule::Off ==
557
0
                    static_cast<const SvxLineSpacingItem* >(pItem)->GetInterLineSpaceRule())
558
0
            nLineSpace = 100;
559
0
        else
560
0
            nLineSpace = static_cast<const SvxLineSpacingItem* >(pItem)->GetPropLineSpace();
561
0
    }
562
563
0
    SvxCaseMap eCaseMap = SvxCaseMap::NotMapped;
564
0
    eState = aCoreSet.GetItemState(RES_CHRATR_CASEMAP, false, &pItem);
565
0
    if (eState == SfxItemState::DEFAULT)
566
0
        pItem = &rPool.GetUserOrPoolDefaultItem(RES_CHRATR_CASEMAP);
567
0
    if (eState >= SfxItemState::DEFAULT)
568
0
        eCaseMap = static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap();
569
570
0
    while (nSlot)
571
0
    {
572
0
        switch(nSlot)
573
0
        {
574
0
            case FN_SET_SUPER_SCRIPT:
575
0
                    bFlag = 0 < nEsc;
576
0
                break;
577
0
            case FN_SET_SUB_SCRIPT:
578
0
                    bFlag = 0 > nEsc;
579
0
                break;
580
0
            case FN_SET_SMALL_CAPS:
581
0
                bFlag = eCaseMap == SvxCaseMap::SmallCaps;
582
0
                break;
583
0
            case SID_ATTR_PARA_ADJUST_LEFT:
584
0
                if (!bAdjustGood)
585
0
                {
586
0
                    rSet.InvalidateItem( nSlot );
587
0
                    nSlot = 0;
588
0
                }
589
0
                else
590
0
                    bFlag = SvxAdjust::Left == eAdjust;
591
0
                break;
592
0
            case SID_ATTR_PARA_ADJUST_RIGHT:
593
0
                if (!bAdjustGood)
594
0
                {
595
0
                    rSet.InvalidateItem( nSlot );
596
0
                    nSlot = 0;
597
0
                }
598
0
                else
599
0
                    bFlag = SvxAdjust::Right == eAdjust;
600
0
                break;
601
0
            case SID_ATTR_PARA_ADJUST_CENTER:
602
0
                if (!bAdjustGood)
603
0
                {
604
0
                    rSet.InvalidateItem( nSlot );
605
0
                    nSlot = 0;
606
0
                }
607
0
                else
608
0
                    bFlag = SvxAdjust::Center == eAdjust;
609
0
                break;
610
0
            case SID_ATTR_PARA_ADJUST_BLOCK:
611
0
            {
612
0
                if (!bAdjustGood)
613
0
                {
614
0
                    rSet.InvalidateItem( nSlot );
615
0
                    nSlot = 0;
616
0
                }
617
0
                else
618
0
                {
619
0
                    bFlag = SvxAdjust::Block == eAdjust;
620
0
                    sal_uInt16 nHtmlMode = GetHtmlMode(rSh.GetView().GetDocShell());
621
0
                    if((nHtmlMode & HTMLMODE_ON) && !(nHtmlMode & HTMLMODE_FULL_STYLES ))
622
0
                    {
623
0
                        rSet.DisableItem( nSlot );
624
0
                        nSlot = 0;
625
0
                    }
626
0
                }
627
0
            }
628
0
            break;
629
0
            case SID_ATTR_PARA_ADJUST_START:
630
0
                if (!bAdjustGood)
631
0
                {
632
0
                    rSet.InvalidateItem( nSlot );
633
0
                    nSlot = 0;
634
0
                }
635
0
                else
636
0
                    bFlag = SvxAdjust::ParaStart == eAdjust;
637
0
                break;
638
0
            case SID_ATTR_PARA_ADJUST_END:
639
0
                if (!bAdjustGood)
640
0
                {
641
0
                    rSet.InvalidateItem( nSlot );
642
0
                    nSlot = 0;
643
0
                }
644
0
                else
645
0
                    bFlag = SvxAdjust::ParaEnd == eAdjust;
646
0
                break;
647
0
            case SID_ATTR_PARA_LINESPACE_10:
648
0
                bFlag = nLineSpace == 100;
649
0
            break;
650
0
            case SID_ATTR_PARA_LINESPACE_115:
651
0
                bFlag = nLineSpace == 115;
652
0
            break;
653
0
            case SID_ATTR_PARA_LINESPACE_15:
654
0
                bFlag = nLineSpace == 150;
655
0
            break;
656
0
            case SID_ATTR_PARA_LINESPACE_20:
657
0
                bFlag = nLineSpace == 200;
658
0
            break;
659
0
            case FN_GROW_FONT_SIZE:
660
0
            case FN_SHRINK_FONT_SIZE:
661
0
            {
662
0
                SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONTHEIGHT,
663
0
                                            *rSet.GetPool() );
664
0
                aSetItem.GetItemSet().Put( aCoreSet, false );
665
0
                const SvxFontHeightItem* pSize( static_cast<const SvxFontHeightItem*>(
666
0
                                            aSetItem.GetItemOfScript( rSh.GetScriptType() ) ) );
667
668
0
                if( pSize ) // selection is of one size
669
0
                {
670
0
                    sal_uInt32 nSize = pSize->GetHeight();
671
0
                    if( nSize == nFontMaxSz )
672
0
                        rSet.DisableItem( FN_GROW_FONT_SIZE );
673
0
                    else if( nSize == nFontInc )
674
0
                        rSet.DisableItem( FN_SHRINK_FONT_SIZE );
675
0
                }
676
0
                else
677
0
                {
678
0
                    std::vector<std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >>
679
0
                        vFontHeight = rSh.GetItemWithPaM( RES_CHRATR_FONTSIZE );
680
0
                    for ( const std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM>>& aIt : vFontHeight )
681
0
                    {
682
0
                        if (!aIt.first)
683
0
                        {
684
0
                            rSet.DisableItem(FN_GROW_FONT_SIZE);
685
0
                            rSet.DisableItem(FN_SHRINK_FONT_SIZE);
686
0
                            break;
687
0
                        }
688
0
                        pSize = static_cast<const SvxFontHeightItem*>( aIt.first );
689
0
                        sal_uInt32 nSize = pSize->GetHeight();
690
0
                        if( nSize == nFontMaxSz )
691
0
                            rSet.DisableItem( FN_GROW_FONT_SIZE );
692
0
                        else if( nSize == nFontInc )
693
0
                            rSet.DisableItem( FN_SHRINK_FONT_SIZE );
694
0
                    }
695
0
                }
696
0
                nSlot = 0;
697
0
            }
698
0
            break;
699
0
            case SID_ULINE_VAL_NONE:
700
0
            case SID_ULINE_VAL_SINGLE:
701
0
            case SID_ULINE_VAL_DOUBLE:
702
0
            case SID_ULINE_VAL_DOTTED:
703
0
            {
704
0
                eState = aCoreSet.GetItemState(RES_CHRATR_UNDERLINE);
705
0
                if( eState >= SfxItemState::DEFAULT )
706
0
                {
707
0
                    FontLineStyle eLineStyle = aCoreSet.Get(RES_CHRATR_UNDERLINE).GetLineStyle();
708
709
0
                    switch (nSlot)
710
0
                    {
711
0
                        case SID_ULINE_VAL_NONE:
712
0
                            rSet.Put(SfxBoolItem(nSlot, eLineStyle == LINESTYLE_NONE));
713
0
                            break;
714
0
                        case SID_ULINE_VAL_SINGLE:
715
0
                            rSet.Put(SfxBoolItem(nSlot, eLineStyle == LINESTYLE_SINGLE));
716
0
                            break;
717
0
                        case SID_ULINE_VAL_DOUBLE:
718
0
                            rSet.Put(SfxBoolItem(nSlot, eLineStyle == LINESTYLE_DOUBLE));
719
0
                            break;
720
0
                        case SID_ULINE_VAL_DOTTED:
721
0
                            rSet.Put(SfxBoolItem(nSlot, eLineStyle == LINESTYLE_DOTTED));
722
0
                            break;
723
0
                    }
724
0
                }
725
0
                else
726
0
                    rSet.InvalidateItem(nSlot);
727
0
                nSlot = 0;
728
0
            }
729
0
            break;
730
0
            case SID_ATTR_PARA_ADJUST:
731
0
                if (!bAdjustGood)
732
0
                    rSet.InvalidateItem( nSlot );
733
0
                else
734
0
                    rSet.Put(SvxAdjustItem(eAdjust, SID_ATTR_PARA_ADJUST ));
735
0
                nSlot = 0;
736
0
            break;
737
0
            case SID_ATTR_PARA_LRSPACE:
738
0
            case SID_ATTR_PARA_LEFTSPACE:
739
0
            case SID_ATTR_PARA_RIGHTSPACE:
740
0
            case SID_ATTR_PARA_FIRSTLINESPACE:
741
0
            {
742
0
                eState = aCoreSet.GetItemState(RES_MARGIN_FIRSTLINE);
743
0
                eState = std::min(aCoreSet.GetItemState(RES_MARGIN_TEXTLEFT), eState);
744
0
                eState = std::min(aCoreSet.GetItemState(RES_MARGIN_RIGHT), eState);
745
0
                if( eState >= SfxItemState::DEFAULT )
746
0
                {
747
0
                    SvxLRSpaceItem aLR(RES_LR_SPACE);
748
0
                    SvxFirstLineIndentItem const& rFirstLine(aCoreSet.Get(RES_MARGIN_FIRSTLINE));
749
0
                    SvxTextLeftMarginItem const& rLeftMargin(aCoreSet.Get(RES_MARGIN_TEXTLEFT));
750
0
                    SvxRightMarginItem const& rRightMargin(aCoreSet.Get(RES_MARGIN_RIGHT));
751
752
0
                    aLR.SetTextFirstLineOffset(rFirstLine.GetTextFirstLineOffset(),
753
0
                                               rFirstLine.GetPropTextFirstLineOffset());
754
0
                    aLR.SetAutoFirst(rFirstLine.IsAutoFirst());
755
0
                    aLR.SetTextLeft(rLeftMargin.GetTextLeft(), rLeftMargin.GetPropLeft());
756
0
                    aLR.SetRight(rRightMargin.GetRight(), rRightMargin.GetPropRight());
757
0
                    aLR.SetWhich(nSlot);
758
0
                    rSet.Put(aLR);
759
0
                }
760
0
                else
761
0
                    rSet.InvalidateItem(nSlot);
762
0
                nSlot = 0;
763
0
            }
764
0
            break;
765
766
0
            case SID_ATTR_PARA_LEFT_TO_RIGHT :
767
0
            case SID_ATTR_PARA_RIGHT_TO_LEFT :
768
0
            {
769
0
                if ( !SvtCTLOptions::IsCTLFontEnabled() )
770
0
                {
771
0
                    rSet.DisableItem( nSlot );
772
0
                    nSlot = 0;
773
0
                }
774
0
                else
775
0
                {
776
                    // is the item set?
777
0
                    sal_uInt16 nHtmlMode = GetHtmlMode(rSh.GetView().GetDocShell());
778
0
                    if((!(nHtmlMode & HTMLMODE_ON) || (0 != (nHtmlMode & HTMLMODE_SOME_STYLES))) &&
779
0
                    aCoreSet.GetItemState( RES_FRAMEDIR, false ) >= SfxItemState::DEFAULT)
780
0
                    {
781
0
                        SvxFrameDirection eFrameDir =
782
0
                                aCoreSet.Get(RES_FRAMEDIR).GetValue();
783
0
                        if (SvxFrameDirection::Environment == eFrameDir)
784
0
                        {
785
0
                            eFrameDir = rSh.IsInRightToLeftText() ?
786
0
                                    SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB;
787
0
                        }
788
0
                        bFlag = (SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot &&
789
0
                                            SvxFrameDirection::Horizontal_LR_TB == eFrameDir) ||
790
0
                                (SID_ATTR_PARA_RIGHT_TO_LEFT == nSlot &&
791
0
                                            SvxFrameDirection::Horizontal_RL_TB == eFrameDir);
792
0
                    }
793
0
                    else
794
0
                    {
795
0
                        rSet.InvalidateItem(nSlot);
796
0
                        nSlot = 0;
797
0
                    }
798
0
                }
799
0
            }
800
0
            break;
801
802
0
            case SID_ATTR_CHAR_LANGUAGE:
803
0
            case SID_ATTR_CHAR_KERNING:
804
0
            case RES_PARATR_DROP:
805
0
            {
806
0
                rSet.Put(aCoreSet.Get( GetPool().GetWhichIDFromSlotID(nSlot)));
807
0
                nSlot = 0;
808
0
            }
809
0
            break;
810
0
            case SID_ATTR_PARA_MODEL:
811
0
            {
812
0
                SfxItemSet aTemp(SfxItemSet::makeFixedSfxItemSet<RES_PAGEDESC, RES_PAGEDESC,
813
0
                                                                 SID_ATTR_PARA_MODEL, SID_ATTR_PARA_MODEL>(GetPool()));
814
0
                aTemp.Put(aCoreSet);
815
0
                ::SwToSfxPageDescAttr(aTemp);
816
0
                rSet.Put(aTemp.Get(SID_ATTR_PARA_MODEL));
817
0
                nSlot = 0;
818
0
            }
819
0
            break;
820
0
            case RES_TXTATR_INETFMT:
821
0
            {
822
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT>(GetPool()));
823
0
                rSh.GetCurAttr(aSet);
824
0
                const SfxPoolItem& rItem = aSet.Get(RES_TXTATR_INETFMT);
825
0
                rSet.Put(rItem);
826
0
                nSlot = 0;
827
0
            }
828
0
            break;
829
0
            case FN_NO_BREAK:
830
0
            {
831
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_CHRATR_NOHYPHEN, RES_CHRATR_NOHYPHEN>(GetPool()));
832
0
                rSh.GetCurAttr(aSet);
833
0
                const SfxPoolItem& rItem = aSet.Get(RES_CHRATR_NOHYPHEN);
834
835
0
                SwWrtShell& rWrtSh = GetShell();
836
                // add "No Break" menu item to the context menu, if the word
837
                // has "no break" setting, or it is hyphenated
838
0
                if ( static_cast<const SvxNoHyphenItem&>(rItem).GetValue() || ( rWrtSh.GetCursor()
839
0
                        && rWrtSh.GetCursor()->IsInHyphenatedWord(*rWrtSh.GetLayout()) ) )
840
0
                {
841
0
                    rSet.Put(rItem);
842
0
                }
843
0
                else
844
0
                    rSet.DisableItem(nSlot);
845
0
                nSlot = 0;
846
0
            }
847
0
            break;
848
0
            default:
849
            // Do nothing
850
0
            nSlot = 0;
851
0
            break;
852
853
0
        }
854
0
        if( nSlot )
855
0
        {
856
0
            aFlagItem.SetWhich( nSlot );
857
0
            aFlagItem.SetValue( bFlag );
858
0
            rSet.Put( aFlagItem );
859
0
        }
860
0
        nSlot = aIter.NextWhich();
861
0
    }
862
863
0
    rSet.Put(aCoreSet,false);
864
0
}
865
866
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */