Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/view/formatsh.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 <com/sun/star/style/XStyleFamiliesSupplier.hpp>
21
22
#include <scitems.hxx>
23
#include <editeng/borderline.hxx>
24
25
#include <sfx2/viewfrm.hxx>
26
#include <sfx2/bindings.hxx>
27
#include <sfx2/namedcolor.hxx>
28
#include <sfx2/objface.hxx>
29
#include <sfx2/request.hxx>
30
#include <sfx2/toolbarids.hxx>
31
#include <svl/whiter.hxx>
32
33
#include <svl/stritem.hxx>
34
#include <svl/numformat.hxx>
35
#include <svl/zformat.hxx>
36
#include <svl/languageoptions.hxx>
37
#include <svl/cjkoptions.hxx>
38
#include <svl/ctloptions.hxx>
39
#include <editeng/boxitem.hxx>
40
#include <editeng/langitem.hxx>
41
#include <editeng/svxenum.hxx>
42
#include <editeng/wghtitem.hxx>
43
#include <editeng/postitem.hxx>
44
#include <editeng/udlnitem.hxx>
45
#include <editeng/lineitem.hxx>
46
#include <editeng/colritem.hxx>
47
#include <editeng/brushitem.hxx>
48
#include <editeng/frmdiritem.hxx>
49
#include <editeng/scriptsetitem.hxx>
50
#include <editeng/shaditem.hxx>
51
#include <editeng/justifyitem.hxx>
52
#include <editeng/fhgtitem.hxx>
53
#include <sal/log.hxx>
54
#include <osl/diagnose.h>
55
#include <comphelper/lok.hxx>
56
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
57
58
#include <formatsh.hxx>
59
#include <sc.hrc>
60
#include <docsh.hxx>
61
#include <patattr.hxx>
62
#include <scmod.hxx>
63
#include <stlpool.hxx>
64
#include <stlsheet.hxx>
65
#include <docpool.hxx>
66
#include <tabvwsh.hxx>
67
#include <attrib.hxx>
68
69
#define ShellClass_ScFormatShell
70
#define ShellClass_TableFont
71
#define ShellClass_FormatForSelection
72
#include <scslots.hxx>
73
74
#include <editeng/fontitem.hxx>
75
#include <sfx2/classificationhelper.hxx>
76
77
#include <memory>
78
79
namespace {
80
81
SvxCellHorJustify lclConvertSlotToHAlign( sal_uInt16 nSlot )
82
0
{
83
0
    SvxCellHorJustify eHJustify = SvxCellHorJustify::Standard;
84
0
    switch( nSlot )
85
0
    {
86
0
        case SID_ALIGN_ANY_HDEFAULT:    eHJustify = SvxCellHorJustify::Standard;   break;
87
0
        case SID_ALIGN_ANY_LEFT:        eHJustify = SvxCellHorJustify::Left;       break;
88
0
        case SID_ALIGN_ANY_HCENTER:     eHJustify = SvxCellHorJustify::Center;     break;
89
0
        case SID_ALIGN_ANY_RIGHT:       eHJustify = SvxCellHorJustify::Right;      break;
90
0
        case SID_ALIGN_ANY_JUSTIFIED:   eHJustify = SvxCellHorJustify::Block;      break;
91
0
        default:    OSL_FAIL( "lclConvertSlotToHAlign - invalid slot" );
92
0
    }
93
0
    return eHJustify;
94
0
}
95
96
SvxCellVerJustify lclConvertSlotToVAlign( sal_uInt16 nSlot )
97
0
{
98
0
    SvxCellVerJustify eVJustify = SvxCellVerJustify::Standard;
99
0
    switch( nSlot )
100
0
    {
101
0
        case SID_ALIGN_ANY_VDEFAULT:    eVJustify = SvxCellVerJustify::Standard;   break;
102
0
        case SID_ALIGN_ANY_TOP:         eVJustify = SvxCellVerJustify::Top;        break;
103
0
        case SID_ALIGN_ANY_VCENTER:     eVJustify = SvxCellVerJustify::Center;     break;
104
0
        case SID_ALIGN_ANY_BOTTOM:      eVJustify = SvxCellVerJustify::Bottom;     break;
105
0
        default:    OSL_FAIL( "lclConvertSlotToVAlign - invalid slot" );
106
0
    }
107
0
    return eVJustify;
108
0
}
109
110
} // namespace
111
112
113
SFX_IMPL_INTERFACE(ScFormatShell, SfxShell)
114
115
void ScFormatShell::InitInterface_Impl()
116
11
{
117
11
    GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT,
118
11
                                            SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server,
119
11
                                            ToolbarId::Objectbar_Format);
120
11
}
121
122
ScFormatShell::ScFormatShell(ScViewData& rData) :
123
0
    SfxShell(rData.GetViewShell()),
124
0
    rViewData(rData)
125
0
{
126
0
    ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
127
128
0
    SetPool( &pTabViewShell->GetPool() );
129
0
    SfxUndoManager* pMgr = rViewData.GetSfxDocShell()->GetUndoManager();
130
0
    SetUndoManager( pMgr );
131
0
    if (pMgr && !rViewData.GetDocument().IsUndoEnabled())
132
0
    {
133
0
        pMgr->SetMaxUndoActionCount( 0 );
134
0
    }
135
0
    SetName(u"Format"_ustr);
136
0
}
137
138
ScFormatShell::~ScFormatShell()
139
0
{
140
0
}
141
142
void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
143
0
{
144
0
    const SfxItemSet* pArgs = rReq.GetArgs();
145
0
    const sal_uInt16  nSlotId = rReq.GetSlot();
146
147
0
    ScDocShell*         pDocSh      = GetViewData().GetDocShell();
148
0
    ScTabViewShell*     pTabViewShell= GetViewData().GetViewShell();
149
0
    ScDocument&         rDoc        = pDocSh->GetDocument();
150
0
    SfxStyleSheetBasePool*  pStylePool  = rDoc.GetStyleSheetPool();
151
152
0
    if (nSlotId == SID_STYLE_PREVIEW)
153
0
    {
154
0
        SfxStyleFamily eFamily = SfxStyleFamily::Para;
155
0
        const SfxUInt16Item* pFamItem;
156
0
        if ( pArgs && (pFamItem = pArgs->GetItemIfSet( SID_STYLE_FAMILY )) )
157
0
            eFamily = static_cast<SfxStyleFamily>(pFamItem->GetValue());
158
0
        const SfxPoolItem* pNameItem;
159
0
        OUString aStyleName;
160
0
        if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem ))
161
0
            aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
162
0
        if ( eFamily == SfxStyleFamily::Para ) // CellStyles
163
0
        {
164
0
            ScMarkData aFuncMark( rViewData.GetMarkData() );
165
0
            ScViewUtil::UnmarkFiltered( aFuncMark, rDoc );
166
0
            aFuncMark.MarkToMulti();
167
168
0
            if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )
169
0
            {
170
0
                SCCOL nCol = rViewData.GetCurX();
171
0
                SCROW nRow = rViewData.GetCurY();
172
0
                SCTAB nTab = rViewData.CurrentTabForData();
173
0
                ScRange aRange( nCol, nRow, nTab );
174
0
                aFuncMark.SetMarkArea( aRange );
175
0
            }
176
0
            rDoc.SetPreviewSelection( aFuncMark );
177
0
            ScStyleSheet* pPreviewStyle = static_cast<ScStyleSheet*>( pStylePool->Find( aStyleName, eFamily ) );
178
0
            rDoc.SetPreviewCellStyle( pPreviewStyle  );
179
0
            ScPatternAttr aAttr( *rDoc.GetSelectionPattern( aFuncMark ) );
180
0
            aAttr.SetStyleSheet( pPreviewStyle );
181
182
0
            SfxItemSet aItemSet( GetPool() );
183
184
0
            ScPatternAttr aNewAttrs(GetViewData().GetDocument().getCellAttributeHelper());
185
0
            SfxItemSet& rNewSet = aNewAttrs.GetItemSetWritable();
186
0
            rNewSet.Put( aItemSet, false );
187
188
0
            rDoc.ApplySelectionPattern( aNewAttrs, rDoc.GetPreviewSelection() );
189
0
            pTabViewShell->UpdateSelectionArea(aFuncMark, &aAttr, /*adjustHeight*/ false);
190
0
        }
191
0
    }
192
0
    else if (nSlotId ==  SID_STYLE_END_PREVIEW)
193
0
    {
194
        // No mark at all happens when creating a new document, in which
195
        // case the selection pattern obtained would be empty (created of
196
        // GetPool()) anyway and nothing needs to be applied.
197
0
        ScMarkData aPreviewMark( rDoc.GetPreviewSelection());
198
0
        if (aPreviewMark.IsMarked() || aPreviewMark.IsMultiMarked())
199
0
        {
200
0
            ScPatternAttr aAttr( *rDoc.GetSelectionPattern( aPreviewMark ) );
201
0
            if ( ScStyleSheet* pPreviewStyle = rDoc.GetPreviewCellStyle() )
202
0
                aAttr.SetStyleSheet( pPreviewStyle );
203
0
            rDoc.SetPreviewCellStyle(nullptr);
204
205
0
            SfxItemSet aItemSet( GetPool() );
206
207
0
            ScPatternAttr aNewAttrs(GetViewData().GetDocument().getCellAttributeHelper());
208
0
            SfxItemSet& rNewSet = aNewAttrs.GetItemSetWritable();
209
0
            rNewSet.Put( aItemSet, false );
210
0
            rDoc.ApplySelectionPattern( aNewAttrs, aPreviewMark );
211
0
            pTabViewShell->UpdateSelectionArea(aPreviewMark, &aAttr, /*adjustHeight*/ false);
212
0
        }
213
0
    }
214
0
    else if (nSlotId == SID_CLASSIFICATION_APPLY)
215
0
    {
216
0
        const SfxPoolItem* pItem = nullptr;
217
0
        if (pArgs && pArgs->GetItemState(nSlotId, false, &pItem) == SfxItemState::SET)
218
0
        {
219
0
            const OUString& rName = static_cast<const SfxStringItem*>(pItem)->GetValue();
220
0
            SfxClassificationHelper aHelper(pDocSh->getDocProperties());
221
0
            auto eType = SfxClassificationPolicyType::IntellectualProperty;
222
0
            if (const SfxStringItem* pNameItem = pArgs->GetItemIfSet(SID_TYPE_NAME, false))
223
0
            {
224
0
                const OUString& rType = pNameItem->GetValue();
225
0
                eType = SfxClassificationHelper::stringToPolicyType(rType);
226
0
            }
227
0
            aHelper.SetBACName(rName, eType);
228
0
        }
229
0
        else
230
0
            SAL_WARN("sc.ui", "missing parameter for SID_CLASSIFICATION_APPLY");
231
0
    }
232
0
    else
233
0
    {
234
0
        OSL_FAIL( "Unknown slot (ScViewShell::ExecuteStyle)" );
235
0
    }
236
0
}
237
238
void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
239
0
{
240
0
    ScModule* pScMod = ScModule::get();
241
0
    ScTabViewShell*     pTabViewShell   = GetViewData().GetViewShell();
242
0
    const SfxItemSet*   pReqArgs        = rReq.GetArgs();
243
0
    sal_uInt16          nSlot           = rReq.GetSlot();
244
0
    SfxBindings&        rBindings       = pTabViewShell->GetViewFrame().GetBindings();
245
246
0
    pTabViewShell->HideListBox();                   // Autofilter-DropDown-Listbox
247
248
    // End input
249
0
    if ( GetViewData().HasEditView( GetViewData().GetActivePart() ) )
250
0
    {
251
0
        switch ( nSlot )
252
0
        {
253
0
            case SID_NUMBER_TYPE_FORMAT:
254
0
            case SID_NUMBER_TWODEC:
255
0
            case SID_NUMBER_SCIENTIFIC:
256
0
            case SID_NUMBER_DATE:
257
0
            case SID_NUMBER_CURRENCY:
258
0
            case SID_NUMBER_PERCENT:
259
0
            case SID_NUMBER_STANDARD:
260
0
            case SID_NUMBER_FORMAT:
261
0
            case SID_NUMBER_INCDEC:
262
0
            case SID_NUMBER_DECDEC:
263
0
            case SID_NUMBER_THOUSANDS:
264
0
            case FID_DEFINE_NAME:
265
0
            case FID_ADD_NAME:
266
0
            case FID_USE_NAME:
267
0
            case FID_INSERT_NAME:
268
0
            case SID_SPELL_DIALOG:
269
0
            case SID_HANGUL_HANJA_CONVERSION:
270
271
0
            pScMod->InputEnterHandler();
272
0
            pTabViewShell->UpdateInputHandler();
273
0
            break;
274
275
0
            default:
276
0
            break;
277
0
        }
278
0
    }
279
280
0
    SvNumFormatType nType = GetCurrentNumberFormatType();
281
0
    switch ( nSlot )
282
0
    {
283
0
        case SID_NUMBER_TWODEC:
284
0
        {
285
0
            const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
286
0
            sal_uInt32 nNumberFormat = rAttrSet.Get(ATTR_VALUE_FORMAT).GetValue();
287
288
0
            if ((nType & SvNumFormatType::NUMBER) && nNumberFormat == 4)
289
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER );
290
0
            else
291
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER, 4 );
292
0
            rBindings.Invalidate( nSlot );
293
0
            rReq.Done();
294
0
        }
295
0
        break;
296
0
        case SID_NUMBER_SCIENTIFIC:
297
0
            if (nType & SvNumFormatType::SCIENTIFIC)
298
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER );
299
0
            else
300
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::SCIENTIFIC );
301
0
            rBindings.Invalidate( nSlot );
302
0
            rReq.Done();
303
0
            break;
304
0
        case SID_NUMBER_DATE:
305
0
            if (nType & SvNumFormatType::DATE)
306
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER );
307
0
            else
308
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::DATE );
309
0
            rBindings.Invalidate( nSlot );
310
0
            rReq.Done();
311
0
            break;
312
0
        case SID_NUMBER_TIME:
313
0
            if (nType & SvNumFormatType::TIME)
314
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER );
315
0
            else
316
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::TIME );
317
0
            rBindings.Invalidate( nSlot );
318
0
            rReq.Done();
319
0
            break;
320
0
        case SID_NUMBER_CURRENCY:
321
0
            if(pReqArgs)
322
0
            {
323
0
                const SfxPoolItem* pItem;
324
0
                if ( pReqArgs->HasItem( SID_NUMBER_CURRENCY, &pItem ) )
325
0
                {
326
0
                    sal_uInt32 nNewFormat = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
327
0
                    ScDocument& rDoc = rViewData.GetDocument();
328
0
                    SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
329
0
                    const SfxItemSet& rOldSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
330
331
0
                    LanguageType eOldLang = rOldSet.Get( ATTR_LANGUAGE_FORMAT ).GetLanguage();
332
0
                    sal_uInt32 nOldFormat = rOldSet.Get( ATTR_VALUE_FORMAT ).GetValue();
333
334
0
                    if ( nOldFormat != nNewFormat )
335
0
                    {
336
0
                        const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewFormat );
337
0
                        ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper());
338
0
                        LanguageType eNewLang = pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW;
339
0
                        if ( eNewLang != eOldLang && eNewLang != LANGUAGE_DONTKNOW )
340
0
                            aNewAttrs.ItemSetPut(SvxLanguageItem(eNewLang, ATTR_LANGUAGE_FORMAT));
341
0
                        aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat));
342
0
                        pTabViewShell->ApplySelectionPattern( aNewAttrs );
343
0
                    }
344
0
                    else
345
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER );
346
0
                }
347
0
            }
348
0
            else
349
0
            {
350
0
                if ( nType & SvNumFormatType::CURRENCY )
351
0
                    pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER );
352
0
                else
353
0
                    pTabViewShell->SetNumberFormat( SvNumFormatType::CURRENCY );
354
0
            }
355
0
            rBindings.Invalidate( nSlot );
356
0
            rReq.Done();
357
0
            break;
358
0
        case SID_NUMBER_PERCENT:
359
0
            if (nType & SvNumFormatType::PERCENT)
360
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER );
361
0
            else
362
0
                pTabViewShell->SetNumberFormat( SvNumFormatType::PERCENT );
363
0
            rBindings.Invalidate( nSlot );
364
0
            rReq.Done();
365
0
            break;
366
0
        case SID_NUMBER_STANDARD:
367
0
            pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER );
368
0
            rReq.Done();
369
0
            break;
370
0
        case SID_NUMBER_INCDEC:
371
0
            pTabViewShell->ChangeNumFmtDecimals( true );
372
0
            rReq.Done();
373
0
            break;
374
0
        case SID_NUMBER_DECDEC:
375
0
            pTabViewShell->ChangeNumFmtDecimals( false );
376
0
            rReq.Done();
377
0
            break;
378
0
        case SID_NUMBER_THOUSANDS:
379
0
        {
380
0
            ScDocument& rDoc = rViewData.GetDocument();
381
0
            SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
382
0
            bool bThousand(false);
383
0
            bool bNegRed(false);
384
0
            sal_uInt16 nPrecision(0);
385
0
            sal_uInt16 nLeadZeroes(0);
386
0
            LanguageType eLanguage = ScGlobal::eLnge;
387
388
0
            sal_uInt32 nCurrentNumberFormat = rDoc.GetNumberFormat(
389
0
                rViewData.GetCurX(), rViewData.GetCurY(), rViewData.CurrentTabForData());
390
0
            const SvNumberformat* pEntry = pFormatter->GetEntry(nCurrentNumberFormat);
391
392
0
            if (pEntry)
393
0
                eLanguage = pEntry->GetLanguage();
394
395
0
            pFormatter->GetFormatSpecialInfo(nCurrentNumberFormat, bThousand, bNegRed, nPrecision, nLeadZeroes);
396
0
            bThousand = !bThousand;
397
0
            OUString aCode = pFormatter->GenerateFormat(
398
0
                nCurrentNumberFormat,
399
0
                eLanguage,
400
0
                bThousand,
401
0
                bNegRed,
402
0
                nPrecision,
403
0
                nLeadZeroes);
404
0
            pTabViewShell->SetNumFmtByStr(aCode);
405
406
0
            rBindings.Invalidate(nSlot);
407
0
            rReq.Done();
408
0
        }
409
0
        break;
410
0
        case SID_NUMBER_FORMAT:
411
            // symphony version with format interpretation
412
0
            if(pReqArgs)
413
0
            {
414
0
                const SfxPoolItem* pItem;
415
0
                ScDocument& rDoc = rViewData.GetDocument();
416
0
                SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
417
418
0
                sal_uInt32 nCurrentNumberFormat = rDoc.GetNumberFormat(
419
0
                    rViewData.GetCurX(), rViewData.GetCurY(), rViewData.CurrentTabForData());
420
0
                const SvNumberformat* pEntry = pFormatter->GetEntry(nCurrentNumberFormat);
421
422
0
                if(!pEntry)
423
0
                    break;
424
425
0
                LanguageType eLanguage = pEntry->GetLanguage();
426
0
                SvNumFormatType eType = pEntry->GetMaskedType();
427
428
                //Just use eType to judge whether the command is fired for NUMBER/PERCENT/CURRENCY/SCIENTIFIC/FRACTION/TIME
429
                //In sidebar, users can fire SID_NUMBER_FORMAT command by operating the related UI controls before they are disable
430
0
                if(!(eType == SvNumFormatType::ALL
431
0
                     || eType == SvNumFormatType::NUMBER
432
0
                     || eType == SvNumFormatType::PERCENT
433
0
                     || eType == SvNumFormatType::CURRENCY
434
0
                     || eType == SvNumFormatType::SCIENTIFIC
435
0
                     || eType == SvNumFormatType::TIME
436
0
                     || eType == SvNumFormatType::FRACTION))
437
0
                    pEntry = nullptr;
438
439
0
                if(SfxItemState::SET == pReqArgs->GetItemState(nSlot, true, &pItem) && pEntry)
440
0
                {
441
0
                    OUString aCode = static_cast<const SfxStringItem*>(pItem)->GetValue();
442
0
                    sal_uInt16 aLen = aCode.getLength();
443
0
                    std::unique_ptr<OUString[]> sFormat( new OUString[4] );
444
0
                    OUStringBuffer sTmpStr;
445
0
                    sal_uInt16 nCount(0);
446
0
                    sal_uInt16 nStrCount(0);
447
448
0
                    while(nCount < aLen)
449
0
                    {
450
0
                        sal_Unicode cChar = aCode[nCount];
451
452
0
                        if(cChar == ',')
453
0
                        {
454
0
                            sFormat[nStrCount] = sTmpStr.makeStringAndClear();
455
0
                            nStrCount++;
456
0
                        }
457
0
                        else
458
0
                        {
459
0
                            sTmpStr.append(cChar);
460
0
                        }
461
462
0
                        nCount++;
463
464
0
                        if(nStrCount > 3)
465
0
                            break;
466
0
                    }
467
468
0
                    const bool bThousand = static_cast<bool>(sFormat[0].toInt32());
469
0
                    const bool bNegRed = static_cast<bool>(sFormat[1].toInt32());
470
0
                    const sal_uInt16 nPrecision = static_cast<sal_uInt16>(sFormat[2].toInt32());
471
0
                    const sal_uInt16 nLeadZeroes = static_cast<sal_uInt16>(sFormat[3].toInt32());
472
473
0
                    aCode = pFormatter->GenerateFormat(
474
0
                        nCurrentNumberFormat,//modify
475
0
                        eLanguage,
476
0
                        bThousand,
477
0
                        bNegRed,
478
0
                        nPrecision,
479
0
                        nLeadZeroes);
480
0
                    pTabViewShell->SetNumFmtByStr(aCode);
481
0
                }
482
0
            }
483
0
            break;
484
485
0
        case SID_ATTR_NUMBERFORMAT_VALUE:
486
0
            if ( pReqArgs )
487
0
            {
488
0
                if ( const SfxUInt32Item* pItem = pReqArgs->GetItemIfSet( ATTR_VALUE_FORMAT ) )
489
0
                {
490
                    // We have to accomplish this using ApplyAttributes()
491
                    // because we also need the language information to be
492
                    // considered.
493
0
                    const SfxItemSet& rOldSet =
494
0
                        pTabViewShell->GetSelectionPattern()->GetItemSet();
495
0
                    SfxItemPool* pDocPool = GetViewData().GetDocument().GetPool();
496
0
                    SfxItemSet aNewSet(SfxItemSet::makeFixedSfxItemSet<ATTR_PATTERN_START, ATTR_PATTERN_END>( *pDocPool ));
497
0
                    aNewSet.Put( *pItem );
498
0
                    pTabViewShell->ApplyAttributes( aNewSet, rOldSet );
499
0
                }
500
0
            }
501
0
            break;
502
503
0
        case SID_NUMBER_TYPE_FORMAT:
504
0
            if ( pReqArgs )
505
0
            {
506
0
                const SfxPoolItem* pItem;
507
0
                if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
508
0
                {
509
0
                    sal_uInt16 nFormat = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
510
0
                    switch(nFormat)
511
0
                    {
512
0
                    case 0:
513
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER); //Modify
514
0
                        break;
515
0
                    case 1:
516
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::NUMBER, 2 ); //Modify
517
0
                        break;
518
0
                    case 2:
519
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::PERCENT );
520
0
                        break;
521
0
                    case 3:
522
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::CURRENCY );
523
0
                        break;
524
0
                    case 4:
525
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::DATE );
526
0
                        break;
527
0
                    case 5:
528
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::TIME );
529
0
                        break;
530
0
                    case 6:
531
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::SCIENTIFIC );
532
0
                        break;
533
0
                    case 7:
534
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::FRACTION );
535
0
                        break;
536
0
                    case 8:
537
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::LOGICAL );
538
0
                        break;
539
0
                    case 9:
540
0
                        pTabViewShell->SetNumberFormat( SvNumFormatType::TEXT );
541
0
                        break;
542
0
                    default:
543
0
                        ;
544
0
                    }
545
0
                    rReq.Done();
546
0
                }
547
0
            }
548
0
            break;
549
550
0
        default:
551
0
            OSL_FAIL("ExecuteEdit: invalid slot");
552
0
            break;
553
0
    }
554
0
}
555
556
void ScFormatShell::ExecuteAlignment( SfxRequest& rReq )
557
0
{
558
0
    ScTabViewShell* pTabViewShell       = GetViewData().GetViewShell();
559
0
    SfxBindings&            rBindings   = rViewData.GetBindings();
560
0
    const SfxItemSet*       pSet        = rReq.GetArgs();
561
0
    sal_uInt16                  nSlot       = rReq.GetSlot();
562
563
0
    pTabViewShell->HideListBox();   // Autofilter-DropDown-Listbox
564
565
0
    switch( nSlot )
566
0
    {
567
        // pseudo slots for Format menu
568
0
        case SID_ALIGN_ANY_HDEFAULT:
569
0
        case SID_ALIGN_ANY_LEFT:
570
0
        case SID_ALIGN_ANY_HCENTER:
571
0
        case SID_ALIGN_ANY_RIGHT:
572
0
        case SID_ALIGN_ANY_JUSTIFIED:
573
0
            pTabViewShell->ApplyAttr( SvxHorJustifyItem( lclConvertSlotToHAlign( nSlot ), ATTR_HOR_JUSTIFY ) );
574
0
        break;
575
0
        case SID_ALIGN_ANY_VDEFAULT:
576
0
        case SID_ALIGN_ANY_TOP:
577
0
        case SID_ALIGN_ANY_VCENTER:
578
0
        case SID_ALIGN_ANY_BOTTOM:
579
0
            pTabViewShell->ApplyAttr( SvxVerJustifyItem( lclConvertSlotToVAlign( nSlot ), ATTR_VER_JUSTIFY ) );
580
0
        break;
581
582
0
        default:
583
0
            if( pSet )
584
0
            {
585
0
                const SfxPoolItem* pItem = nullptr;
586
0
                if( pSet->GetItemState(GetPool().GetWhichIDFromSlotID(nSlot), true, &pItem  ) == SfxItemState::SET )
587
0
                {
588
589
0
                    switch ( nSlot )
590
0
                    {
591
0
                        case SID_ATTR_ALIGN_HOR_JUSTIFY:
592
0
                        case SID_ATTR_ALIGN_VER_JUSTIFY:
593
0
                        case SID_ATTR_ALIGN_INDENT:
594
0
                        case SID_ATTR_ALIGN_HYPHENATION:
595
0
                        case SID_ATTR_ALIGN_DEGREES:
596
0
                        case SID_ATTR_ALIGN_LOCKPOS:
597
0
                        case SID_ATTR_ALIGN_MARGIN:
598
0
                        case SID_ATTR_ALIGN_STACKED:
599
0
                            pTabViewShell->ApplyAttr( *pItem );
600
0
                        break;
601
602
0
                        case SID_H_ALIGNCELL:
603
0
                        {
604
0
                            SvxCellHorJustify eJust = static_cast<const SvxHorJustifyItem*>(pItem)->GetValue();
605
                            // #i78476# update alignment of text in cell edit mode
606
0
                            pTabViewShell->UpdateInputHandlerCellAdjust( eJust );
607
0
                            pTabViewShell->ApplyAttr( SvxHorJustifyItem( eJust, ATTR_HOR_JUSTIFY ) );
608
0
                        }
609
0
                        break;
610
0
                        case SID_V_ALIGNCELL:
611
0
                            pTabViewShell->ApplyAttr( SvxVerJustifyItem( static_cast<const SvxVerJustifyItem*>(pItem)->GetValue(), ATTR_VER_JUSTIFY ) );
612
0
                        break;
613
0
                        default:
614
0
                            OSL_FAIL( "ExecuteAlignment: invalid slot" );
615
0
                            return;
616
0
                    }
617
0
                }
618
0
            }
619
0
    }
620
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_LEFT );
621
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT );
622
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK );
623
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_CENTER);
624
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_START );
625
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_END );
626
0
    rBindings.Invalidate( SID_ALIGNLEFT );
627
0
    rBindings.Invalidate( SID_ALIGNRIGHT );
628
0
    rBindings.Invalidate( SID_ALIGNCENTERHOR );
629
0
    rBindings.Invalidate( SID_ALIGNBLOCK );
630
0
    rBindings.Invalidate( SID_ALIGNTOP );
631
0
    rBindings.Invalidate( SID_ALIGNBOTTOM );
632
0
    rBindings.Invalidate( SID_ALIGNCENTERVER );
633
0
    rBindings.Invalidate( SID_V_ALIGNCELL );
634
0
    rBindings.Invalidate( SID_H_ALIGNCELL );
635
    // pseudo slots for Format menu
636
0
    rBindings.Invalidate( SID_ALIGN_ANY_HDEFAULT );
637
0
    rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
638
0
    rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
639
0
    rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
640
0
    rBindings.Invalidate( SID_ALIGN_ANY_START );
641
0
    rBindings.Invalidate( SID_ALIGN_ANY_END );
642
0
    rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
643
0
    rBindings.Invalidate( SID_ALIGN_ANY_VDEFAULT );
644
0
    rBindings.Invalidate( SID_ALIGN_ANY_TOP );
645
0
    rBindings.Invalidate( SID_ALIGN_ANY_VCENTER );
646
0
    rBindings.Invalidate( SID_ALIGN_ANY_BOTTOM );
647
0
    rBindings.Update();
648
649
0
    if( ! rReq.IsAPI() )
650
0
        rReq.Done();
651
0
}
652
653
void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
654
0
{
655
0
    ScTabViewShell* pTabViewShell       = GetViewData().GetViewShell();
656
0
    SfxBindings&            rBindings   = rViewData.GetBindings();
657
0
    const ScPatternAttr*    pAttrs      = pTabViewShell->GetSelectionPattern();
658
0
    const SfxItemSet*       pSet        = rReq.GetArgs();
659
0
    sal_uInt16                  nSlot       = rReq.GetSlot();
660
0
    std::optional<SfxAllItemSet> pNewSet;
661
662
0
    pTabViewShell->HideListBox();                   // Autofilter-DropDown-Listbox
663
664
0
    if (  (nSlot == SID_ATTR_CHAR_WEIGHT)
665
0
        ||(nSlot == SID_ATTR_CHAR_POSTURE)
666
0
        ||(nSlot == SID_ATTR_CHAR_UNDERLINE)
667
0
        ||(nSlot == SID_ULINE_VAL_NONE)
668
0
        ||(nSlot == SID_ULINE_VAL_SINGLE)
669
0
        ||(nSlot == SID_ULINE_VAL_DOUBLE)
670
0
        ||(nSlot == SID_ULINE_VAL_DOTTED) )
671
0
    {
672
0
        pNewSet.emplace( GetPool() );
673
674
0
        switch ( nSlot )
675
0
        {
676
0
            case SID_ATTR_CHAR_WEIGHT:
677
0
            {
678
                // #i78017 establish the same behaviour as in Writer
679
0
                SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
680
681
0
                SfxItemPool& rPool = GetPool();
682
0
                SvxScriptSetItem aSetItem( nSlot, rPool );
683
0
                if ( pSet )
684
0
                    aSetItem.PutItemForScriptType( nScript, pSet->Get( ATTR_FONT_WEIGHT ) );
685
0
                else
686
0
                {
687
                    //  toggle manually
688
689
0
                    FontWeight eWeight = WEIGHT_BOLD;
690
0
                    SvxScriptSetItem aOldSetItem( nSlot, rPool );
691
0
                    aOldSetItem.GetItemSet().Put( pAttrs->GetItemSet(), false );
692
0
                    const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
693
0
                    if ( pCore && static_cast<const SvxWeightItem*>(pCore)->GetWeight() == WEIGHT_BOLD )
694
0
                        eWeight = WEIGHT_NORMAL;
695
696
0
                    aSetItem.PutItemForScriptType( nScript, SvxWeightItem( eWeight, ATTR_FONT_WEIGHT ) );
697
0
                }
698
0
                pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
699
0
                pNewSet->Put( aSetItem.GetItemSet(), false );
700
0
            }
701
0
            break;
702
703
0
            case SID_ATTR_CHAR_POSTURE:
704
0
            {
705
                // #i78017 establish the same behaviour as in Writer
706
0
                SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
707
708
0
                SfxItemPool& rPool = GetPool();
709
0
                SvxScriptSetItem aSetItem( nSlot, rPool );
710
0
                if ( pSet )
711
0
                    aSetItem.PutItemForScriptType( nScript, pSet->Get( ATTR_FONT_POSTURE ) );
712
0
                else
713
0
                {
714
                    //  toggle manually
715
716
0
                    FontItalic eItalic = ITALIC_NORMAL;
717
0
                    SvxScriptSetItem aOldSetItem( nSlot, rPool );
718
0
                    aOldSetItem.GetItemSet().Put( pAttrs->GetItemSet(), false );
719
0
                    const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
720
0
                    if ( pCore && static_cast<const SvxPostureItem*>(pCore)->GetPosture() == ITALIC_NORMAL )
721
0
                        eItalic = ITALIC_NONE;
722
723
0
                    aSetItem.PutItemForScriptType( nScript, SvxPostureItem( eItalic, ATTR_FONT_POSTURE ) );
724
0
                }
725
0
                pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
726
0
                pNewSet->Put( aSetItem.GetItemSet(), false );
727
0
            }
728
0
            break;
729
730
0
            case SID_ATTR_CHAR_UNDERLINE:
731
0
                {
732
0
                    if( pSet )
733
0
                    {
734
0
                        const SfxPoolItem& rUnderline = pSet->Get( ATTR_FONT_UNDERLINE );
735
736
0
                        if( dynamic_cast<const SvxUnderlineItem*>( &rUnderline) !=  nullptr )
737
0
                        {
738
0
                            pTabViewShell->ApplyAttr( rUnderline );
739
0
                            pNewSet->Put( rUnderline );
740
0
                        }
741
0
                        else if ( auto pTextLineItem = dynamic_cast<const SvxTextLineItem*>( &rUnderline) )
742
0
                        {
743
                            // #i106580# also allow SvxTextLineItem (base class of SvxUnderlineItem)
744
0
                            SvxUnderlineItem aNewItem( pTextLineItem->GetLineStyle(), pTextLineItem->Which() );
745
0
                            aNewItem.SetColor( pTextLineItem->GetColor() );
746
0
                            pTabViewShell->ApplyAttr( aNewItem );
747
0
                            pNewSet->Put( aNewItem );
748
0
                        }
749
0
                    }
750
0
                    else
751
0
                    {
752
0
                        SvxUnderlineItem aUnderline( pAttrs->GetItem( ATTR_FONT_UNDERLINE ) );
753
0
                        FontLineStyle eUnderline = (LINESTYLE_NONE != aUnderline.GetLineStyle())
754
0
                                    ? LINESTYLE_NONE
755
0
                                    : LINESTYLE_SINGLE;
756
0
                        aUnderline.SetLineStyle( eUnderline );
757
0
                        pTabViewShell->ApplyAttr( aUnderline );
758
0
                        pNewSet->Put( aUnderline );
759
0
                    }
760
0
                }
761
0
                break;
762
763
0
            case SID_ULINE_VAL_NONE:
764
0
                pTabViewShell->ApplyAttr( SvxUnderlineItem( LINESTYLE_NONE, ATTR_FONT_UNDERLINE ) );
765
0
                break;
766
0
            case SID_ULINE_VAL_SINGLE:      // Toggles
767
0
            case SID_ULINE_VAL_DOUBLE:
768
0
            case SID_ULINE_VAL_DOTTED:
769
0
                {
770
0
                    FontLineStyle eOld = pAttrs->GetItem(ATTR_FONT_UNDERLINE).GetLineStyle();
771
0
                    FontLineStyle eNew = eOld;
772
0
                    switch (nSlot)
773
0
                    {
774
0
                        case SID_ULINE_VAL_SINGLE:
775
0
                            eNew = ( eOld == LINESTYLE_SINGLE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
776
0
                            break;
777
0
                        case SID_ULINE_VAL_DOUBLE:
778
0
                            eNew = ( eOld == LINESTYLE_DOUBLE ) ? LINESTYLE_NONE : LINESTYLE_DOUBLE;
779
0
                            break;
780
0
                        case SID_ULINE_VAL_DOTTED:
781
0
                            eNew = ( eOld == LINESTYLE_DOTTED ) ? LINESTYLE_NONE : LINESTYLE_DOTTED;
782
0
                            break;
783
0
                    }
784
0
                    pTabViewShell->ApplyAttr( SvxUnderlineItem( eNew, ATTR_FONT_UNDERLINE ) );
785
0
                }
786
0
                break;
787
788
0
            default:
789
0
                break;
790
0
        }
791
0
        rBindings.Invalidate( nSlot );
792
0
    }
793
0
    else
794
0
    {
795
        /*
796
         * "Self-made" functionality of radio buttons
797
         * At the toggle the default state is used, this means
798
         * no button was clicked.
799
         */
800
801
0
        const SfxItemSet&        rAttrSet   = pTabViewShell->GetSelectionPattern()->GetItemSet();
802
0
        const SvxHorJustifyItem* pHorJustify = rAttrSet.GetItemIfSet(ATTR_HOR_JUSTIFY);
803
0
        const SvxVerJustifyItem* pVerJustify = rAttrSet.GetItemIfSet(ATTR_VER_JUSTIFY );
804
0
        SvxCellHorJustify        eHorJustify = SvxCellHorJustify::Standard;
805
0
        SvxCellVerJustify        eVerJustify = SvxCellVerJustify::Standard;
806
807
0
        if (pHorJustify)
808
0
        {
809
0
            eHorJustify = pHorJustify->GetValue();
810
0
        }
811
0
        if (pVerJustify)
812
0
        {
813
0
            eVerJustify = pVerJustify->GetValue();
814
0
        }
815
816
0
        switch ( nSlot )
817
0
        {
818
0
            case SID_ALIGNLEFT:
819
0
                rReq.SetSlot( SID_H_ALIGNCELL );
820
0
                rReq.AppendItem( SvxHorJustifyItem(
821
0
                    !pHorJustify || (eHorJustify != SvxCellHorJustify::Left) ?
822
0
                    SvxCellHorJustify::Left : SvxCellHorJustify::Standard, SID_H_ALIGNCELL ) );
823
0
                ExecuteSlot( rReq, GetInterface() );
824
0
                return;
825
826
0
            case SID_ALIGNRIGHT:
827
0
                rReq.SetSlot( SID_H_ALIGNCELL );
828
0
                rReq.AppendItem( SvxHorJustifyItem(
829
0
                    !pHorJustify || (eHorJustify != SvxCellHorJustify::Right) ?
830
0
                    SvxCellHorJustify::Right : SvxCellHorJustify::Standard, SID_H_ALIGNCELL ) );
831
0
                ExecuteSlot( rReq, GetInterface() );
832
0
                return;
833
834
0
            case SID_ALIGNCENTERHOR:
835
0
                rReq.SetSlot( SID_H_ALIGNCELL );
836
0
                rReq.AppendItem( SvxHorJustifyItem(
837
0
                    !pHorJustify || (eHorJustify != SvxCellHorJustify::Center) ?
838
0
                    SvxCellHorJustify::Center : SvxCellHorJustify::Standard, SID_H_ALIGNCELL ) );
839
0
                ExecuteSlot( rReq, GetInterface() );
840
0
                return;
841
842
0
            case SID_ALIGNBLOCK:
843
0
                rReq.SetSlot( SID_H_ALIGNCELL );
844
0
                rReq.AppendItem( SvxHorJustifyItem(
845
0
                    !pHorJustify || (eHorJustify != SvxCellHorJustify::Block) ?
846
0
                    SvxCellHorJustify::Block : SvxCellHorJustify::Standard, SID_H_ALIGNCELL ) );
847
0
                ExecuteSlot( rReq, GetInterface() );
848
0
                return;
849
850
0
            case SID_ALIGNTOP:
851
0
                rReq.SetSlot( SID_V_ALIGNCELL );
852
0
                rReq.AppendItem( SvxVerJustifyItem(
853
0
                    !pVerJustify || (eVerJustify != SvxCellVerJustify::Top) ?
854
0
                    SvxCellVerJustify::Top : SvxCellVerJustify::Standard, SID_V_ALIGNCELL ) );
855
0
                ExecuteSlot( rReq, GetInterface() );
856
0
                return;
857
858
0
            case SID_ALIGNBOTTOM:
859
0
                rReq.SetSlot( SID_V_ALIGNCELL );
860
0
                rReq.AppendItem( SvxVerJustifyItem(
861
0
                    !pVerJustify || (eVerJustify != SvxCellVerJustify::Bottom) ?
862
0
                    SvxCellVerJustify::Bottom : SvxCellVerJustify::Standard, SID_V_ALIGNCELL ) );
863
0
                ExecuteSlot( rReq, GetInterface() );
864
0
                return;
865
866
0
            case SID_ALIGNCENTERVER:
867
0
                rReq.SetSlot( SID_V_ALIGNCELL );
868
0
                rReq.AppendItem( SvxVerJustifyItem(
869
0
                    !pVerJustify || (eVerJustify != SvxCellVerJustify::Center) ?
870
0
                    SvxCellVerJustify::Center : SvxCellVerJustify::Standard, SID_V_ALIGNCELL ) );
871
0
                ExecuteSlot( rReq, GetInterface() );
872
0
                return;
873
874
0
            default:
875
0
            break;
876
0
        }
877
878
0
    }
879
880
0
    rBindings.Update();
881
882
0
    if( pNewSet )
883
0
    {
884
0
        rReq.Done( *pNewSet );
885
0
        pNewSet.reset();
886
0
    }
887
0
    else
888
0
    {
889
0
        rReq.Done();
890
0
    }
891
892
0
}
893
894
void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
895
0
{
896
0
    ScTabViewShell*     pTabViewShell = GetViewData().GetViewShell();
897
0
    SfxBindings&        rBindings = rViewData.GetBindings();
898
0
    const SfxItemSet*   pNewAttrs = rReq.GetArgs();
899
0
    sal_uInt16          nSlot = rReq.GetSlot();
900
901
0
    pTabViewShell->HideListBox();                   // Autofilter-DropDown-Listbox
902
0
    ScDocument& rDoc = GetViewData().GetDocument();
903
0
    if ( !pNewAttrs )
904
0
    {
905
0
        switch ( nSlot )
906
0
        {
907
0
            case SID_GROW_FONT_SIZE:
908
0
            case SID_SHRINK_FONT_SIZE:
909
0
            {
910
0
                SfxItemPool& rPool = GetPool();
911
0
                SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONTHEIGHT, rPool );
912
0
                aSetItem.GetItemSet().Put( pTabViewShell->GetSelectionPattern()->GetItemSet(), false );
913
914
0
                SvtScriptType nScriptTypes = pTabViewShell->GetSelectionScriptType();
915
0
                const SvxFontHeightItem* pSize( static_cast<const SvxFontHeightItem*>( aSetItem.GetItemOfScript( nScriptTypes ) ) );
916
917
0
                if ( pSize )
918
0
                {
919
0
                    SvxFontHeightItem aSize( *pSize );
920
0
                    sal_uInt32 nSize = aSize.GetHeight();
921
922
0
                    const sal_uInt32 nFontInc = 40;      // 2pt
923
0
                    const sal_uInt32 nFontMaxSz = 19998; // 999.9pt
924
0
                    if ( nSlot == SID_GROW_FONT_SIZE )
925
0
                        nSize = std::min< sal_uInt32 >( nSize + nFontInc, nFontMaxSz );
926
0
                    else
927
0
                        nSize = std::max< sal_Int32 >( nSize - nFontInc, nFontInc );
928
929
0
                    aSize.SetHeight( nSize );
930
0
                    aSetItem.PutItemForScriptType( nScriptTypes, aSize );
931
0
                    pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
932
0
                }
933
0
                rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
934
0
            }
935
0
            break;
936
937
0
            case SID_ATTR_CHAR_ENDPREVIEW_FONT:
938
0
            {
939
0
                rDoc.SetPreviewFont(nullptr);
940
0
                pTabViewShell->UpdateSelectionArea(rDoc.GetPreviewSelection(), nullptr,
941
0
                                                   /*adjustHeight*/ false);
942
0
                break;
943
0
            }
944
0
            case SID_ATTR_CHAR_COLOR:
945
0
                {
946
0
                    Color aColor(COL_TRANSPARENT);
947
0
                    if (auto pObjectShell = pTabViewShell->GetObjectShell())
948
0
                    {
949
0
                        const std::optional<NamedColor> oColor
950
0
                            = pObjectShell->GetRecentColor(SID_ATTR_CHAR_COLOR);
951
0
                        if (oColor.has_value())
952
0
                            aColor = (*oColor).getComplexColor().getFinalColor();
953
0
                    }
954
955
0
                    SvxColorItem aColorItem(
956
0
                        pTabViewShell->GetSelectionPattern()->GetItem(ATTR_FONT_COLOR));
957
0
                    aColorItem.setColor(aColor);
958
0
                    pTabViewShell->ApplyAttr(aColorItem, false);
959
0
                }
960
0
                break;
961
962
0
            case SID_ATTR_CHAR_FONT:
963
0
            case SID_ATTR_CHAR_FONTHEIGHT:
964
0
                pTabViewShell->ExecuteCellFormatDlg(rReq, u"font"_ustr);       // when ToolBar is vertical
965
0
                break;
966
967
0
            case SID_BACKGROUND_COLOR:
968
0
                {
969
0
                    Color aColor(COL_TRANSPARENT);
970
0
                    if (auto pObjectShell = pTabViewShell->GetObjectShell())
971
0
                    {
972
0
                        const std::optional<NamedColor> oColor
973
0
                            = pObjectShell->GetRecentColor(SID_BACKGROUND_COLOR);
974
0
                        if (oColor.has_value())
975
0
                            aColor = (*oColor).getComplexColor().getFinalColor();
976
0
                    }
977
978
0
                    SvxBrushItem aBrushItem(
979
0
                        pTabViewShell->GetSelectionPattern()->GetItem(ATTR_BACKGROUND));
980
0
                    aBrushItem.SetColor(aColor);
981
0
                    pTabViewShell->ApplyAttr(aBrushItem, false);
982
0
                }
983
0
                break;
984
985
0
            case SID_ATTR_ALIGN_LINEBREAK:                  // without parameter as toggle
986
0
                {
987
0
                    const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
988
0
                    bool bOld = pAttrs->GetItem(ATTR_LINEBREAK).GetValue();
989
0
                    ScLineBreakCell aBreakItem(!bOld);
990
0
                    pTabViewShell->ApplyAttr( aBreakItem );
991
992
0
                    SfxAllItemSet aNewSet( GetPool() );
993
0
                    aNewSet.Put( aBreakItem );
994
0
                    rReq.Done( aNewSet );
995
996
0
                    rBindings.Invalidate( nSlot );
997
0
                }
998
0
                break;
999
1000
0
            case SID_SCATTR_CELLPROTECTION:                  // without parameter as toggle
1001
0
                {
1002
0
                    const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
1003
0
                    bool bProtect = pAttrs->GetItem(ATTR_PROTECTION).GetProtection();
1004
0
                    bool bHideFormula = pAttrs->GetItem(ATTR_PROTECTION).GetHideFormula();
1005
0
                    bool bHideCell = pAttrs->GetItem(ATTR_PROTECTION).GetHideCell();
1006
0
                    bool bHidePrint = pAttrs->GetItem(ATTR_PROTECTION).GetHidePrint();
1007
1008
0
                    ScProtectionAttr aProtectionItem( !bProtect, bHideFormula, bHideCell, bHidePrint );
1009
0
                    pTabViewShell->ApplyAttr( aProtectionItem );
1010
1011
0
                    SfxAllItemSet aNewSet( GetPool() );
1012
0
                    aNewSet.Put( aProtectionItem );
1013
0
                    aNewSet.Put( SfxBoolItem( SID_SCATTR_CELLPROTECTION, !bProtect ) );
1014
0
                    rReq.Done( aNewSet );
1015
1016
0
                    rBindings.Invalidate( nSlot );
1017
0
                }
1018
0
                break;
1019
0
        }
1020
0
    }
1021
0
    else
1022
0
    {
1023
0
        switch ( nSlot )
1024
0
        {
1025
0
            case SID_ATTR_CHAR_PREVIEW_FONT:
1026
0
            {
1027
0
                SfxItemPool& rPool = GetPool();
1028
0
                sal_uInt16 nWhich = rPool.GetWhichIDFromSlotID( nSlot );
1029
0
                const SvxFontItem& rFont = static_cast<const SvxFontItem&>(pNewAttrs->Get( nWhich ));
1030
0
                SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, rPool );
1031
0
                SvtScriptType nScript = pTabViewShell->GetSelectionScriptType();
1032
0
                aSetItem.PutItemForScriptType( nScript, rFont );
1033
1034
0
                ScMarkData aFuncMark( rViewData.GetMarkData() );
1035
0
                ScViewUtil::UnmarkFiltered( aFuncMark, rDoc );
1036
0
                rDoc.SetPreviewFont( aSetItem.GetItemSet().Clone() );
1037
0
                aFuncMark.MarkToMulti();
1038
1039
0
                if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )
1040
0
                {
1041
0
                    SCCOL nCol = rViewData.GetCurX();
1042
0
                    SCROW nRow = rViewData.GetCurY();
1043
0
                    SCTAB nTab = rViewData.CurrentTabForData();
1044
0
                    ScRange aRange( nCol, nRow, nTab );
1045
0
                    aFuncMark.SetMarkArea( aRange );
1046
0
                }
1047
0
                rDoc.SetPreviewSelection( aFuncMark );
1048
0
                pTabViewShell->UpdateSelectionArea(aFuncMark, nullptr, /*adjustHeight*/ false);
1049
0
                break;
1050
0
            }
1051
0
            case SID_ATTR_CHAR_OVERLINE:
1052
0
            case SID_ATTR_CHAR_STRIKEOUT:
1053
0
            case SID_ATTR_ALIGN_LINEBREAK:
1054
0
            case SID_ATTR_CHAR_CONTOUR:
1055
0
            case SID_ATTR_CHAR_SHADOWED:
1056
0
            case SID_ATTR_CHAR_RELIEF:
1057
0
                pTabViewShell->ApplyAttr( pNewAttrs->Get( pNewAttrs->GetPool()->GetWhichIDFromSlotID( nSlot ) ) );
1058
0
                rBindings.Invalidate( nSlot );
1059
0
                rBindings.Update( nSlot );
1060
0
                break;
1061
0
            case SID_ATTR_CHAR_COLOR:
1062
0
            case SID_SCATTR_PROTECTION :
1063
0
            {
1064
0
                pTabViewShell->ApplyAttr( pNewAttrs->Get( pNewAttrs->GetPool()->GetWhichIDFromSlotID( nSlot) ), false);
1065
1066
0
                rBindings.Invalidate( nSlot );
1067
0
                rBindings.Update( nSlot );
1068
0
            }
1069
1070
0
            break;
1071
1072
0
            case SID_ATTR_CHAR_FONT:
1073
0
            case SID_ATTR_CHAR_FONTHEIGHT:
1074
0
                {
1075
                    // #i78017 establish the same behaviour as in Writer
1076
0
                    SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
1077
0
                    if (nSlot == SID_ATTR_CHAR_FONT)
1078
0
                        nScript = pTabViewShell->GetSelectionScriptType();
1079
1080
0
                    SfxItemPool& rPool = GetPool();
1081
0
                    SvxScriptSetItem aSetItem( nSlot, rPool );
1082
0
                    sal_uInt16 nWhich = rPool.GetWhichIDFromSlotID( nSlot );
1083
0
                    aSetItem.PutItemForScriptType( nScript, pNewAttrs->Get( nWhich ) );
1084
1085
0
                    pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1086
1087
0
                    rBindings.Invalidate( nSlot );
1088
0
                    rBindings.Update( nSlot );
1089
0
                }
1090
0
                break;
1091
1092
0
            case SID_FRAME_LINESTYLE:
1093
0
                {
1094
                    // Update default line
1095
0
                    ::editeng::SvxBorderLine aLine;
1096
0
                    const ::editeng::SvxBorderLine* pLine = nullptr;
1097
0
                    const SfxPoolItem* pLineStyleItem = nullptr;
1098
0
                    if (pNewAttrs->HasItem(SID_FRAME_LINESTYLE, &pLineStyleItem))
1099
0
                        pLine = static_cast<const SvxLineItem*>(pLineStyleItem)->GetLine();
1100
1101
0
                    const SfxPoolItem *pItem1, *pItem2, *pItem3;
1102
0
                    if (pLine &&
1103
0
                            pNewAttrs->HasItem(FN_PARAM_1, &pItem1) &&
1104
0
                            pNewAttrs->HasItem(FN_PARAM_2, &pItem2) &&
1105
0
                            pNewAttrs->HasItem(FN_PARAM_3, &pItem3))
1106
0
                    {
1107
0
                        sal_uInt16 nInnerLineWidth = static_cast<const SfxUInt16Item*>(pItem1)->GetValue();
1108
0
                        sal_uInt16 nOuterLineWidth = static_cast<const SfxUInt16Item*>(pItem2)->GetValue();
1109
0
                        sal_uInt16 nLineDistanceItem = static_cast<const SfxUInt16Item*>(pItem3)->GetValue();
1110
1111
0
                        aLine.GuessLinesWidths(
1112
0
                            pLine->GetBorderLineStyle(), nInnerLineWidth, nOuterLineWidth, nLineDistanceItem);
1113
1114
0
                        pLine = &aLine;
1115
0
                    }
1116
1117
0
                    if ( pLine )
1118
0
                    {
1119
0
                        ::editeng::SvxBorderLine* pDefLine = pTabViewShell->GetDefaultFrameLine();
1120
1121
0
                        if ( pDefLine )
1122
0
                        {
1123
0
                            pDefLine->SetBorderLineStyle(
1124
0
                                    pLine->GetBorderLineStyle());
1125
0
                            pDefLine->SetWidth( pLine->GetWidth( ) );
1126
0
                            pTabViewShell->SetSelectionFrameLines( pDefLine, false );
1127
0
                        }
1128
0
                        else
1129
0
                        {
1130
0
                            pTabViewShell->SetDefaultFrameLine( pLine );
1131
0
                            pTabViewShell->GetDefaultFrameLine()->SetColor( COL_BLACK );
1132
0
                            pTabViewShell->SetSelectionFrameLines( pLine, false );
1133
0
                        }
1134
0
                    }
1135
0
                    else
1136
0
                    {
1137
0
                        Color           aColorBlack( COL_BLACK );
1138
0
                        ::editeng::SvxBorderLine aDefLine( &aColorBlack, 20,
1139
0
                                SvxBorderLineStyle::SOLID );
1140
0
                        pTabViewShell->SetDefaultFrameLine( &aDefLine );
1141
0
                        pTabViewShell->SetSelectionFrameLines( nullptr, false );
1142
0
                    }
1143
0
                    rReq.Done();
1144
0
                }
1145
0
                break;
1146
1147
0
            case SID_FRAME_LINECOLOR:
1148
0
                {
1149
0
                    ::editeng::SvxBorderLine*  pDefLine = pTabViewShell->GetDefaultFrameLine();
1150
1151
0
                    Color aColor = pNewAttrs->Get( SID_FRAME_LINECOLOR ).GetValue();
1152
1153
                    // Update default line
1154
0
                    if ( pDefLine )
1155
0
                    {
1156
0
                        pDefLine->SetColor( aColor );
1157
0
                        pTabViewShell->SetSelectionFrameLines( pDefLine, true );
1158
0
                    }
1159
0
                    else
1160
0
                    {
1161
0
                        ::editeng::SvxBorderLine aDefLine( &aColor, 20, SvxBorderLineStyle::SOLID );
1162
0
                        pTabViewShell->SetDefaultFrameLine( &aDefLine );
1163
0
                        pTabViewShell->SetSelectionFrameLines( &aDefLine, false );
1164
0
                    }
1165
0
                }
1166
0
                break;
1167
1168
0
            case SID_ATTR_BORDER_OUTER:
1169
0
            case SID_ATTR_BORDER:
1170
0
                {
1171
0
                    ::editeng::SvxBorderLine*          pDefLine = pTabViewShell->GetDefaultFrameLine();
1172
0
                    const ScPatternAttr*    pOldAttrs = pTabViewShell->GetSelectionPattern();
1173
0
                    SfxItemSet aOldSet(SfxItemSet::makeFixedSfxItemSet<ATTR_PATTERN_START, ATTR_PATTERN_END>( *rDoc.GetPool() ));
1174
0
                    SfxItemSet aNewSet(SfxItemSet::makeFixedSfxItemSet<ATTR_PATTERN_START, ATTR_PATTERN_END>( *rDoc.GetPool() ));
1175
0
                    const SfxPoolItem& rBorderAttr = pOldAttrs->GetItemSet().Get(ATTR_BORDER);
1176
1177
                    // Evaluate border items from controller:
1178
1179
0
                    if ( const SvxBoxItem* pBoxItem = pNewAttrs->GetItemIfSet( ATTR_BORDER ) )
1180
0
                    {
1181
                        //  The SvxFrameToolBoxControl toolbox controller uses a default
1182
                        //  SvxBorderLine (all widths 0) to mark the lines that should be set.
1183
                        //  Macro recording uses a SvxBoxItem with the real values (OutWidth > 0)
1184
                        //  or NULL pointers for no lines.
1185
                        //  -> Substitute existing lines with pDefLine only if widths are 0.
1186
0
                        SvxBoxItem aBoxItem ( *pBoxItem );
1187
0
                        if ( aBoxItem.GetTop() && aBoxItem.GetTop()->GetOutWidth() == 0 )
1188
0
                            aBoxItem.SetLine( pDefLine, SvxBoxItemLine::TOP );
1189
0
                        if ( aBoxItem.GetBottom() && aBoxItem.GetBottom()->GetOutWidth() == 0 )
1190
0
                            aBoxItem.SetLine( pDefLine, SvxBoxItemLine::BOTTOM );
1191
0
                        if ( aBoxItem.GetLeft() && aBoxItem.GetLeft()->GetOutWidth() == 0 )
1192
0
                            aBoxItem.SetLine( pDefLine, SvxBoxItemLine::LEFT );
1193
0
                        if ( aBoxItem.GetRight() && aBoxItem.GetRight()->GetOutWidth() == 0 )
1194
0
                            aBoxItem.SetLine( pDefLine, SvxBoxItemLine::RIGHT );
1195
0
                        aNewSet.Put( aBoxItem );
1196
0
                        rReq.AppendItem( aBoxItem );
1197
0
                    }
1198
1199
0
                    if ( const SvxBoxInfoItem* pBoxInfoItem = pNewAttrs->GetItemIfSet( ATTR_BORDER_INNER ) )
1200
0
                    {
1201
0
                        SvxBoxInfoItem aBoxInfoItem( *pBoxInfoItem );
1202
0
                        if ( aBoxInfoItem.GetHori() && aBoxInfoItem.GetHori()->GetOutWidth() == 0 )
1203
0
                            aBoxInfoItem.SetLine( pDefLine, SvxBoxInfoItemLine::HORI );
1204
0
                        if ( aBoxInfoItem.GetVert() && aBoxInfoItem.GetVert()->GetOutWidth() == 0 )
1205
0
                            aBoxInfoItem.SetLine( pDefLine, SvxBoxInfoItemLine::VERT );
1206
0
                        aNewSet.Put( aBoxInfoItem );
1207
0
                        rReq.AppendItem( aBoxInfoItem );
1208
0
                    }
1209
0
                    else
1210
0
                    {
1211
0
                        SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
1212
0
                        aBoxInfoItem.SetLine( nullptr, SvxBoxInfoItemLine::HORI );
1213
0
                        aBoxInfoItem.SetLine( nullptr, SvxBoxInfoItemLine::VERT );
1214
0
                        aNewSet.Put( aBoxInfoItem );
1215
0
                    }
1216
1217
0
                    aOldSet.Put( rBorderAttr );
1218
0
                    pTabViewShell->ApplyAttributes( aNewSet, aOldSet );
1219
0
                }
1220
0
                break;
1221
1222
0
            case SID_ATTR_BORDER_DIAG_TLBR:
1223
0
            case SID_ATTR_BORDER_DIAG_BLTR:
1224
0
                {
1225
0
                    const ScPatternAttr* pOldAttrs = pTabViewShell->GetSelectionPattern();
1226
0
                    SfxItemSet aOldSet(pOldAttrs->GetItemSet());
1227
0
                    SfxItemSet aNewSet(aOldSet);
1228
1229
0
                    if(SID_ATTR_BORDER_DIAG_TLBR == nSlot)
1230
0
                    {
1231
0
                        if(SfxItemState::SET == pNewAttrs->GetItemState(ATTR_BORDER_TLBR))
1232
0
                        {
1233
0
                            SvxLineItem aItem(ATTR_BORDER_TLBR);
1234
0
                            aItem.SetLine(pNewAttrs->Get(ATTR_BORDER_TLBR).GetLine());
1235
0
                            aNewSet.Put(aItem);
1236
0
                            rReq.AppendItem(aItem);
1237
0
                            pTabViewShell->ApplyAttributes(aNewSet, aOldSet);
1238
0
                        }
1239
0
                    }
1240
0
                    else // if( nSlot == SID_ATTR_BORDER_DIAG_BLTR )
1241
0
                    {
1242
0
                        if(SfxItemState::SET == pNewAttrs->GetItemState(ATTR_BORDER_BLTR ))
1243
0
                        {
1244
0
                            SvxLineItem aItem(ATTR_BORDER_BLTR);
1245
0
                            aItem.SetLine(pNewAttrs->Get(ATTR_BORDER_BLTR).GetLine());
1246
0
                            aNewSet.Put(aItem);
1247
0
                            rReq.AppendItem(aItem);
1248
0
                            pTabViewShell->ApplyAttributes(aNewSet, aOldSet);
1249
0
                        }
1250
0
                    }
1251
1252
0
                    rBindings.Invalidate(nSlot);
1253
0
                }
1254
0
                break;
1255
1256
            // ATTR_BACKGROUND (=SID_ATTR_BRUSH) has to be set to two IDs:
1257
0
            case SID_BACKGROUND_COLOR:
1258
0
                {
1259
0
                    const SvxColorItem&  rNewColorItem = pNewAttrs->Get( SID_BACKGROUND_COLOR );
1260
0
                    Color aColor = rNewColorItem.GetValue();
1261
1262
0
                    SvxBrushItem aBrushItem(
1263
0
                        pTabViewShell->GetSelectionPattern()->GetItem( ATTR_BACKGROUND ) );
1264
0
                    aBrushItem.SetColor(aColor);
1265
0
                    aBrushItem.setComplexColor(rNewColorItem.getComplexColor());
1266
1267
0
                    pTabViewShell->ApplyAttr( aBrushItem, false );
1268
0
                }
1269
0
                break;
1270
1271
0
                case SID_ATTR_BRUSH:
1272
0
                {
1273
0
                    SvxBrushItem        aBrushItem( pTabViewShell->GetSelectionPattern()->
1274
0
                                                GetItem( ATTR_BACKGROUND ) );
1275
0
                    const SvxBrushItem& rNewBrushItem = static_cast<const SvxBrushItem&>(
1276
0
                                            pNewAttrs->Get( GetPool().GetWhichIDFromSlotID(nSlot) ) );
1277
0
                    aBrushItem.SetColor(rNewBrushItem.GetColor());
1278
0
                    aBrushItem.setComplexColor(rNewBrushItem.getComplexColor());
1279
0
                    pTabViewShell->ApplyAttr( aBrushItem );
1280
0
                }
1281
0
                break;
1282
1283
0
            case SID_ATTR_BORDER_SHADOW:
1284
0
                {
1285
0
                    const SvxShadowItem& rNewShadowItem =
1286
0
                                            pNewAttrs->Get( ATTR_SHADOW );
1287
0
                    pTabViewShell->ApplyAttr( rNewShadowItem );
1288
0
                }
1289
0
                break;
1290
1291
0
            default:
1292
0
            break;
1293
0
        }
1294
1295
0
        if( ! rReq.IsAPI() && ! rReq.IsDone() )
1296
0
            rReq.Done();
1297
0
    }
1298
0
}
1299
1300
void ScFormatShell::GetAttrState( SfxItemSet& rSet )
1301
0
{
1302
0
    ScTabViewShell* pTabViewShell   = GetViewData().GetViewShell();
1303
0
    const SfxItemSet&    rAttrSet   = pTabViewShell->GetSelectionPattern()->GetItemSet();
1304
0
    const SvxBrushItem&  rBrushItem = rAttrSet.Get( ATTR_BACKGROUND );
1305
0
    SfxWhichIter aIter( rSet );
1306
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1307
1308
0
    rSet.Put( rAttrSet, false );
1309
1310
    //  choose font info according to selection script type
1311
0
    SvtScriptType nScript = SvtScriptType::NONE;      // GetSelectionScriptType never returns 0
1312
0
    if ( rSet.GetItemState( ATTR_FONT ) != SfxItemState::UNKNOWN )
1313
0
    {
1314
0
        nScript = pTabViewShell->GetSelectionScriptType();
1315
0
        ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT, nScript );
1316
0
    }
1317
0
    if ( rSet.GetItemState( ATTR_FONT_HEIGHT ) != SfxItemState::UNKNOWN )
1318
0
    {
1319
0
        if (nScript == SvtScriptType::NONE) nScript = pTabViewShell->GetSelectionScriptType();
1320
0
        ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_HEIGHT, nScript );
1321
0
    }
1322
1323
0
    while ( nWhich )
1324
0
    {
1325
0
        switch(nWhich)
1326
0
        {
1327
0
            case SID_BACKGROUND_COLOR:
1328
0
            {
1329
0
                rSet.Put( SvxColorItem( rBrushItem.GetColor(), SID_BACKGROUND_COLOR ) );
1330
0
                if(SfxItemState::INVALID == rAttrSet.GetItemState(ATTR_BACKGROUND))
1331
0
                {
1332
0
                    rSet.InvalidateItem(SID_BACKGROUND_COLOR);
1333
0
                }
1334
0
            }
1335
0
            break;
1336
0
            case SID_FRAME_LINESTYLE:
1337
0
            case SID_FRAME_LINECOLOR:
1338
0
            {
1339
                // handled together because both need the cell border information for decisions
1340
0
                Color aCol;
1341
0
                editeng::SvxBorderLine aLine(nullptr,0,SvxBorderLineStyle::SOLID);
1342
0
                bool bCol = false;
1343
0
                bool bColDisable = false, bStyleDisable = false;
1344
0
                std::shared_ptr<SvxBoxItem> aBoxItem(std::make_shared<SvxBoxItem>(ATTR_BORDER));
1345
0
                std::shared_ptr<SvxBoxInfoItem> aInfoItem(std::make_shared<SvxBoxInfoItem>(ATTR_BORDER_INNER));
1346
1347
0
                pTabViewShell->GetSelectionFrame(aBoxItem, aInfoItem);
1348
1349
0
                if( aBoxItem->GetTop() )
1350
0
                {
1351
0
                    bCol = true;
1352
0
                    aCol = aBoxItem->GetTop()->GetColor() ;
1353
0
                    aLine.SetColor(aCol);
1354
0
                    aLine.SetWidth( aBoxItem->GetTop()->GetWidth());
1355
0
                    aLine.SetBorderLineStyle( aBoxItem->GetTop()->GetBorderLineStyle());
1356
0
                }
1357
1358
0
                if( aBoxItem->GetBottom() )
1359
0
                {
1360
0
                    if(!bCol)
1361
0
                    {
1362
0
                        bCol = true;
1363
0
                        aCol = aBoxItem->GetBottom()->GetColor() ;
1364
0
                        aLine.SetColor(aCol);
1365
0
                        aLine.SetWidth( aBoxItem->GetBottom()->GetWidth());
1366
0
                        aLine.SetBorderLineStyle( aBoxItem->GetBottom()->GetBorderLineStyle());
1367
0
                    }
1368
0
                    else
1369
0
                    {
1370
0
                        if(aCol != aBoxItem->GetBottom()->GetColor() )
1371
0
                            bColDisable = true;
1372
0
                        if( aLine != *aBoxItem->GetBottom() )
1373
0
                            bStyleDisable = true;
1374
0
                    }
1375
0
                }
1376
1377
0
                if( aBoxItem->GetLeft() )
1378
0
                {
1379
0
                    if(!bCol)
1380
0
                    {
1381
0
                        bCol = true;
1382
0
                        aCol = aBoxItem->GetLeft()->GetColor() ;
1383
0
                        aLine.SetColor(aCol);
1384
0
                        aLine.SetWidth( aBoxItem->GetLeft()->GetWidth());
1385
0
                        aLine.SetBorderLineStyle( aBoxItem->GetLeft()->GetBorderLineStyle());
1386
0
                    }
1387
0
                    else
1388
0
                    {
1389
0
                        if(aCol != aBoxItem->GetLeft()->GetColor() )
1390
0
                            bColDisable = true;
1391
0
                        if( aLine != *aBoxItem->GetLeft() )
1392
0
                            bStyleDisable = true;
1393
0
                    }
1394
0
                }
1395
1396
0
                if( aBoxItem->GetRight() )
1397
0
                {
1398
0
                    if(!bCol)
1399
0
                    {
1400
0
                        bCol = true;
1401
0
                        aCol = aBoxItem->GetRight()->GetColor() ;
1402
0
                        aLine.SetColor(aCol);
1403
0
                        aLine.SetWidth( aBoxItem->GetRight()->GetWidth());
1404
0
                        aLine.SetBorderLineStyle( aBoxItem->GetRight()->GetBorderLineStyle());
1405
0
                    }
1406
0
                    else
1407
0
                    {
1408
0
                        if(aCol != aBoxItem->GetRight()->GetColor() )
1409
0
                            bColDisable = true;
1410
0
                        if( aLine != *aBoxItem->GetRight() )
1411
0
                            bStyleDisable = true;
1412
0
                    }
1413
0
                }
1414
1415
0
                if( aInfoItem->GetVert())
1416
0
                {
1417
0
                    if(!bCol)
1418
0
                    {
1419
0
                        bCol = true;
1420
0
                        aCol = aInfoItem->GetVert()->GetColor() ;
1421
0
                        aLine.SetColor(aCol);
1422
0
                        aLine.SetWidth( aInfoItem->GetVert()->GetWidth());
1423
0
                        aLine.SetBorderLineStyle( aInfoItem->GetVert()->GetBorderLineStyle());
1424
0
                    }
1425
0
                    else
1426
0
                    {
1427
0
                        if(aCol != aInfoItem->GetVert()->GetColor() )
1428
0
                            bColDisable = true;
1429
0
                        if( aLine != *aInfoItem->GetVert() )
1430
0
                            bStyleDisable = true;
1431
0
                    }
1432
0
                }
1433
1434
0
                if( aInfoItem->GetHori())
1435
0
                {
1436
0
                    if(!bCol)
1437
0
                    {
1438
0
                        bCol = true;
1439
0
                        aCol = aInfoItem->GetHori()->GetColor() ;
1440
0
                        aLine.SetColor(aCol);
1441
0
                        aLine.SetWidth( aInfoItem->GetHori()->GetWidth());
1442
0
                        aLine.SetBorderLineStyle( aInfoItem->GetHori()->GetBorderLineStyle());
1443
0
                    }
1444
0
                    else
1445
0
                    {
1446
0
                        if(aCol != aInfoItem->GetHori()->GetColor() )
1447
0
                            bColDisable = true;
1448
0
                        if( aLine != *aInfoItem->GetHori() )
1449
0
                            bStyleDisable = true;
1450
0
                    }
1451
0
                }
1452
1453
0
                if( !aInfoItem->IsValid( SvxBoxInfoItemValidFlags::VERT )
1454
0
                    || !aInfoItem->IsValid( SvxBoxInfoItemValidFlags::HORI )
1455
0
                    || !aInfoItem->IsValid( SvxBoxInfoItemValidFlags::LEFT )
1456
0
                    || !aInfoItem->IsValid( SvxBoxInfoItemValidFlags::RIGHT )
1457
0
                    || !aInfoItem->IsValid( SvxBoxInfoItemValidFlags::TOP )
1458
0
                    || !aInfoItem->IsValid( SvxBoxInfoItemValidFlags::BOTTOM ) )
1459
0
                {
1460
0
                    bColDisable = true;
1461
0
                    bStyleDisable = true;
1462
0
                }
1463
1464
0
                if(SID_FRAME_LINECOLOR == nWhich)
1465
0
                {
1466
0
                    if(bColDisable) // if different lines have different colors
1467
0
                    {
1468
0
                        aCol = COL_TRANSPARENT;
1469
0
                        rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
1470
0
                        rSet.InvalidateItem(SID_FRAME_LINECOLOR);
1471
0
                    }
1472
0
                    else if (!bCol) // if no line available
1473
0
                    {
1474
0
                        aCol = COL_AUTO;
1475
0
                        rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
1476
0
                    }
1477
0
                    else
1478
0
                        rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
1479
0
                }
1480
0
                else // if( nWhich == SID_FRAME_LINESTYLE)
1481
0
                {
1482
0
                    if(bStyleDisable) // if have several lines but don't have same style
1483
0
                    {
1484
0
                        aLine.SetWidth( 1 );
1485
0
                        SvxLineItem aItem(SID_FRAME_LINESTYLE);
1486
0
                        aItem.SetLine(&aLine);
1487
0
                        rSet.Put( aItem );
1488
0
                        rSet.InvalidateItem(SID_FRAME_LINESTYLE);
1489
0
                    }
1490
0
                    else // all the lines have same style or no line available, use initial value (0,0,0,0)
1491
0
                    {
1492
0
                        SvxLineItem aItem(SID_FRAME_LINESTYLE);
1493
0
                        aItem.SetLine(&aLine);
1494
0
                        rSet.Put( aItem );
1495
0
                        if (!aLine.GetWidth())
1496
0
                            rSet.DisableItem(SID_FRAME_LINESTYLE);
1497
0
                    }
1498
0
                }
1499
0
            }
1500
0
            break;
1501
0
            case SID_ATTR_BRUSH:
1502
0
            {
1503
0
                rSet.Put( rBrushItem.CloneSetWhich(GetPool().GetWhichIDFromSlotID(nWhich)) );
1504
0
            }
1505
0
            break;
1506
0
            case SID_SCATTR_CELLPROTECTION:
1507
0
            {
1508
0
                bool bProtect = rAttrSet.Get( ATTR_PROTECTION ).GetProtection();
1509
0
                rSet.Put( SfxBoolItem(SID_SCATTR_CELLPROTECTION, bProtect) );
1510
0
            }
1511
0
            break;
1512
0
        }
1513
0
        nWhich = aIter.NextWhich();
1514
0
    }
1515
1516
    // stuff for sidebar panels
1517
0
    Invalidate(SID_ATTR_ALIGN_DEGREES);
1518
0
    Invalidate(SID_ATTR_ALIGN_LOCKPOS);
1519
0
    Invalidate(SID_ATTR_ALIGN_STACKED);
1520
0
}
1521
1522
void ScFormatShell::GetTextAttrState( SfxItemSet& rSet )
1523
0
{
1524
0
    ScTabViewShell* pTabViewShell   = GetViewData().GetViewShell();
1525
    // tdf#71324 - exclude filtered cells from selection before applying formatting
1526
0
    const SfxItemSet& rAttrSet
1527
0
        = pTabViewShell->GetSelectionPattern(/*bExcludeFiltered=*/true)->GetItemSet();
1528
0
    rSet.Put( rAttrSet, false ); // Include ItemStates in copy
1529
1530
    //  choose font info according to selection script type
1531
0
    SvtScriptType nScript = SvtScriptType::NONE;      // GetSelectionScriptType never returns 0
1532
0
    if ( rSet.GetItemState( ATTR_FONT_WEIGHT ) != SfxItemState::UNKNOWN )
1533
0
    {
1534
0
        nScript = pTabViewShell->GetSelectionScriptType();
1535
0
        ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_WEIGHT, nScript );
1536
0
    }
1537
0
    if ( rSet.GetItemState( ATTR_FONT_POSTURE ) != SfxItemState::UNKNOWN )
1538
0
    {
1539
0
        if (nScript == SvtScriptType::NONE) nScript = pTabViewShell->GetSelectionScriptType();
1540
0
        ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_POSTURE, nScript );
1541
0
    }
1542
1543
0
    SfxItemState eState;
1544
1545
    // own control on radio button functionality:
1546
1547
    // underline
1548
1549
0
    eState = rAttrSet.GetItemState( ATTR_FONT_UNDERLINE );
1550
0
    if ( eState == SfxItemState::INVALID )
1551
0
    {
1552
0
        rSet.InvalidateItem( SID_ULINE_VAL_NONE );
1553
0
        rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1554
0
        rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1555
0
        rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1556
0
    }
1557
0
    else
1558
0
    {
1559
0
        FontLineStyle eUnderline =
1560
0
                    rAttrSet.Get(ATTR_FONT_UNDERLINE).GetLineStyle();
1561
0
        rSet.Put(SfxBoolItem(SID_ULINE_VAL_SINGLE, eUnderline == LINESTYLE_SINGLE));
1562
0
        rSet.Put(SfxBoolItem(SID_ULINE_VAL_DOUBLE, eUnderline == LINESTYLE_DOUBLE));
1563
0
        rSet.Put(SfxBoolItem(SID_ULINE_VAL_DOTTED, eUnderline == LINESTYLE_DOTTED));
1564
0
        rSet.Put(SfxBoolItem(SID_ULINE_VAL_NONE, eUnderline == LINESTYLE_NONE));
1565
0
    }
1566
1567
    // horizontal alignment
1568
1569
0
    const SvxHorJustifyItem* pHorJustify = nullptr;
1570
0
    const SvxVerJustifyItem* pVerJustify = nullptr;
1571
0
    SvxCellVerJustify        eVerJustify = SvxCellVerJustify::Standard;
1572
0
    sal_uInt16                   nWhich      = 0;
1573
0
    bool                     bJustifyStd = false;
1574
0
    SfxBoolItem              aBoolItem   ( 0, true );
1575
1576
0
    eState   = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY, true,
1577
0
                                        reinterpret_cast<const SfxPoolItem**>(&pHorJustify) );
1578
0
    switch ( eState )
1579
0
    {
1580
0
        case SfxItemState::SET:
1581
0
            {
1582
0
                switch ( pHorJustify->GetValue() )
1583
0
                {
1584
0
                    case SvxCellHorJustify::Standard:
1585
0
                        break;
1586
1587
0
                    case SvxCellHorJustify::Left:
1588
0
                        nWhich = SID_ALIGNLEFT;
1589
0
                        break;
1590
1591
0
                    case SvxCellHorJustify::Right:
1592
0
                        nWhich = SID_ALIGNRIGHT;
1593
0
                        break;
1594
1595
0
                    case SvxCellHorJustify::Center:
1596
0
                        nWhich = SID_ALIGNCENTERHOR;
1597
0
                        break;
1598
1599
0
                    case SvxCellHorJustify::Block:
1600
0
                        nWhich = SID_ALIGNBLOCK;
1601
0
                        break;
1602
1603
0
                    case SvxCellHorJustify::Repeat:
1604
0
                    default:
1605
0
                        bJustifyStd = true;
1606
0
                        break;
1607
0
                }
1608
0
            }
1609
0
            break;
1610
1611
0
        case SfxItemState::INVALID:
1612
0
            rSet.InvalidateItem( SID_ALIGNLEFT );
1613
0
            rSet.InvalidateItem( SID_ALIGNRIGHT );
1614
0
            rSet.InvalidateItem( SID_ALIGNCENTERHOR );
1615
0
            rSet.InvalidateItem( SID_ALIGNBLOCK );
1616
0
            break;
1617
1618
0
        default:
1619
0
            bJustifyStd = true;
1620
0
            break;
1621
0
    }
1622
1623
0
    if ( nWhich )
1624
0
    {
1625
0
        aBoolItem.SetWhich( nWhich );
1626
0
        rSet.Put( aBoolItem );
1627
0
    }
1628
0
    else if ( bJustifyStd )
1629
0
    {
1630
0
        aBoolItem.SetValue( false );
1631
0
        aBoolItem.SetWhich( SID_ALIGNLEFT );      rSet.Put( aBoolItem );
1632
0
        aBoolItem.SetWhich( SID_ALIGNRIGHT );     rSet.Put( aBoolItem );
1633
0
        aBoolItem.SetWhich( SID_ALIGNCENTERHOR ); rSet.Put( aBoolItem );
1634
0
        aBoolItem.SetWhich( SID_ALIGNBLOCK );     rSet.Put( aBoolItem );
1635
0
        bJustifyStd = false;
1636
0
    }
1637
1638
    // vertical alignment
1639
1640
0
    nWhich = 0;
1641
0
    aBoolItem.SetValue( true );
1642
1643
0
    eState = rAttrSet.GetItemState( ATTR_VER_JUSTIFY, true,
1644
0
                                    reinterpret_cast<const SfxPoolItem**>(&pVerJustify) );
1645
1646
0
    switch ( eState )
1647
0
    {
1648
0
        case SfxItemState::SET:
1649
0
            {
1650
0
                eVerJustify = pVerJustify->GetValue();
1651
1652
0
                switch ( eVerJustify )
1653
0
                {
1654
0
                    case SvxCellVerJustify::Top:
1655
0
                        nWhich = SID_ALIGNTOP;
1656
0
                        break;
1657
1658
0
                    case SvxCellVerJustify::Bottom:
1659
0
                        nWhich = SID_ALIGNBOTTOM;
1660
0
                        break;
1661
1662
0
                    case SvxCellVerJustify::Center:
1663
0
                        nWhich = SID_ALIGNCENTERVER;
1664
0
                        break;
1665
1666
0
                    case SvxCellVerJustify::Standard:
1667
0
                    default:
1668
0
                        bJustifyStd = true;
1669
0
                        break;
1670
0
                }
1671
0
            }
1672
0
            break;
1673
1674
0
        case SfxItemState::INVALID:
1675
0
            rSet.InvalidateItem( SID_ALIGNTOP );
1676
0
            rSet.InvalidateItem( SID_ALIGNBOTTOM );
1677
0
            rSet.InvalidateItem( SID_ALIGNCENTERVER );
1678
0
            break;
1679
1680
0
        default:
1681
0
            bJustifyStd = true;
1682
0
            break;
1683
0
    }
1684
1685
0
    if ( nWhich )
1686
0
    {
1687
0
        aBoolItem.SetWhich( nWhich );
1688
0
        rSet.Put( aBoolItem );
1689
0
    }
1690
0
    else if ( bJustifyStd )
1691
0
    {
1692
0
        aBoolItem.SetValue( false );
1693
0
        aBoolItem.SetWhich( SID_ALIGNTOP );       rSet.Put( aBoolItem );
1694
0
        aBoolItem.SetWhich( SID_ALIGNBOTTOM );    rSet.Put( aBoolItem );
1695
0
        aBoolItem.SetWhich( SID_ALIGNCENTERVER ); rSet.Put( aBoolItem );
1696
0
    }
1697
0
}
1698
1699
void ScFormatShell::GetBorderState( SfxItemSet& rSet )
1700
0
{
1701
0
    ScTabViewShell* pTabViewShell   = GetViewData().GetViewShell();
1702
0
    std::shared_ptr<SvxBoxItem> aBoxItem(std::make_shared<SvxBoxItem>(ATTR_BORDER));
1703
0
    std::shared_ptr<SvxBoxInfoItem> aInfoItem(std::make_shared<SvxBoxInfoItem>(ATTR_BORDER_INNER));
1704
1705
0
    pTabViewShell->GetSelectionFrame( aBoxItem, aInfoItem );
1706
1707
0
    if ( rSet.GetItemState( ATTR_BORDER ) != SfxItemState::UNKNOWN )
1708
0
        rSet.Put( *aBoxItem );
1709
0
    if ( rSet.GetItemState( ATTR_BORDER_INNER ) != SfxItemState::UNKNOWN )
1710
0
        rSet.Put( *aInfoItem );
1711
0
}
1712
1713
void ScFormatShell::GetAlignState( SfxItemSet& rSet )
1714
0
{
1715
0
    ScTabViewShell* pTabViewShell   = GetViewData().GetViewShell();
1716
0
    const SfxItemSet& rAttrSet    = pTabViewShell->GetSelectionPattern()->GetItemSet();
1717
0
    SfxWhichIter    aIter(rSet);
1718
0
    sal_uInt16          nWhich = aIter.FirstWhich();
1719
1720
0
    SvxCellHorJustify eHAlign = SvxCellHorJustify::Standard;
1721
0
    bool bHasHAlign = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY ) != SfxItemState::INVALID;
1722
0
    if( bHasHAlign )
1723
0
        eHAlign = rAttrSet.Get( ATTR_HOR_JUSTIFY ).GetValue();
1724
1725
0
    SvxCellVerJustify eVAlign = SvxCellVerJustify::Standard;
1726
0
    bool bHasVAlign = rAttrSet.GetItemState( ATTR_VER_JUSTIFY ) != SfxItemState::INVALID;
1727
0
    if( bHasVAlign )
1728
0
        eVAlign = rAttrSet.Get( ATTR_VER_JUSTIFY ).GetValue();
1729
1730
0
    while ( nWhich )
1731
0
    {
1732
0
        switch ( nWhich )
1733
0
        {
1734
0
            case SID_H_ALIGNCELL:
1735
0
                if ( bHasHAlign )
1736
0
                    rSet.Put( SvxHorJustifyItem( eHAlign, nWhich ));
1737
0
            break;
1738
0
            case SID_V_ALIGNCELL:
1739
0
                if ( bHasVAlign )
1740
0
                    rSet.Put( SvxVerJustifyItem( eVAlign, nWhich ));
1741
0
            break;
1742
1743
            // pseudo slots for Format menu
1744
0
            case SID_ALIGN_ANY_HDEFAULT:
1745
0
            case SID_ALIGN_ANY_LEFT:
1746
0
            case SID_ALIGN_ANY_HCENTER:
1747
0
            case SID_ALIGN_ANY_RIGHT:
1748
0
            case SID_ALIGN_ANY_JUSTIFIED:
1749
0
                rSet.Put( SfxBoolItem( nWhich, bHasHAlign && (eHAlign == lclConvertSlotToHAlign( nWhich )) ) );
1750
0
            break;
1751
0
            case SID_ALIGN_ANY_VDEFAULT:
1752
0
            case SID_ALIGN_ANY_TOP:
1753
0
            case SID_ALIGN_ANY_VCENTER:
1754
0
            case SID_ALIGN_ANY_BOTTOM:
1755
0
                rSet.Put( SfxBoolItem( nWhich, bHasVAlign && (eVAlign == lclConvertSlotToVAlign( nWhich )) ) );
1756
0
            break;
1757
0
        }
1758
0
        nWhich = aIter.NextWhich();
1759
0
    }
1760
0
}
1761
1762
void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
1763
0
{
1764
0
    ScTabViewShell* pTabViewShell   = GetViewData().GetViewShell();
1765
0
    ScDocument& rDoc                = rViewData.GetDocument();
1766
0
    const SfxItemSet& rAttrSet      = pTabViewShell->GetSelectionPattern()->GetItemSet();
1767
0
    const SfxItemState eItemState   = rAttrSet.GetItemState( ATTR_VALUE_FORMAT );
1768
0
    sal_uInt32 nNumberFormat        = rAttrSet.Get(ATTR_VALUE_FORMAT).GetValue();
1769
0
    SvNumberFormatter* pFormatter   = rDoc.GetFormatTable();
1770
                                      // If item state is default or set it
1771
                                      // indicates one number format so we
1772
                                      // don't have to iterate over all
1773
                                      // selected cells' attribute ranges to
1774
                                      // determine selected types.
1775
                                      // Does *NOT* include the
1776
                                      // SvNumFormatType::DEFINED bit.
1777
0
    const SvNumFormatType nType     = (eItemState >= SfxItemState::DEFAULT ? pFormatter->GetType( nNumberFormat) :
1778
0
                                       GetCurrentNumberFormatType());
1779
0
    NfIndexTableOffset nOffset      = SvNumberFormatter::GetIndexTableOffset(nNumberFormat);
1780
1781
0
    SfxWhichIter aIter(rSet);
1782
0
    sal_uInt16 nWhich = aIter.FirstWhich();
1783
1784
0
    while ( nWhich )
1785
0
    {
1786
0
        switch ( nWhich )
1787
0
        {
1788
0
            case SID_NUMBER_THOUSANDS:
1789
0
                {
1790
0
                    bool bEnable = (SfxItemState::INVALID != eItemState);
1791
0
                    if (bEnable)
1792
0
                    {
1793
0
                        bEnable = ((nType != SvNumFormatType::ALL) && (nType &
1794
0
                                (SvNumFormatType::NUMBER |
1795
0
                                 SvNumFormatType::PERCENT |
1796
0
                                 SvNumFormatType::CURRENCY |
1797
0
                                 SvNumFormatType::FRACTION)));
1798
0
                        if (bEnable)
1799
0
                        {
1800
0
                            bool bThousand( false );
1801
0
                            bool bNegRed( false );
1802
0
                            sal_uInt16 nPrecision( 0 );
1803
0
                            sal_uInt16 nLeadZeroes( 0 );
1804
0
                            pFormatter->GetFormatSpecialInfo( nNumberFormat, bThousand, bNegRed, nPrecision, nLeadZeroes);
1805
0
                            rSet.Put( SfxBoolItem( nWhich, bThousand));
1806
0
                        }
1807
0
                    }
1808
0
                    if (!bEnable)
1809
0
                    {
1810
0
                        rSet.DisableItem( nWhich );
1811
0
                    }
1812
0
                }
1813
0
                break;
1814
0
            case SID_NUMBER_FORMAT:
1815
                // symphony version with format interpretation
1816
0
                {
1817
0
                    if(SfxItemState::INVALID != eItemState)
1818
0
                    {
1819
0
                        bool bThousand(false);
1820
0
                        bool bNegRed(false);
1821
0
                        sal_uInt16 nPrecision(0);
1822
0
                        sal_uInt16 nLeadZeroes(0);
1823
1824
0
                        pFormatter->GetFormatSpecialInfo(nNumberFormat,bThousand, bNegRed, nPrecision, nLeadZeroes);
1825
1826
0
                        const SvNumberformat* pFormatEntry = pFormatter->GetEntry( nNumberFormat );
1827
0
                        if (pFormatEntry && (pFormatEntry->GetType() & SvNumFormatType::SCIENTIFIC))
1828
0
                        {
1829
                            // if scientific, bThousand is used for engineering notation
1830
0
                            const sal_uInt16 nIntegerDigits = pFormatEntry->GetFormatIntegerDigits();
1831
0
                            bThousand = nIntegerDigits > 0 && ((nIntegerDigits % 3) == 0);
1832
0
                        }
1833
0
                        OUString aFormat;
1834
0
                        static constexpr OUString sBreak = u","_ustr;
1835
0
                        const OUString sThousand = OUString::number(static_cast<sal_Int32>(bThousand));
1836
0
                        const OUString sNegRed = OUString::number(static_cast<sal_Int32>(bNegRed));
1837
0
                        const OUString sPrecision = OUString::number(nPrecision);
1838
0
                        const OUString sLeadZeroes = OUString::number(nLeadZeroes);
1839
0
                        const OUString sNatNum12 = OUString::number( static_cast< sal_Int32 >( pFormatter->IsNatNum12( nNumberFormat ) ) );
1840
1841
0
                        aFormat += sThousand +
1842
0
                            sBreak +
1843
0
                            sNegRed +
1844
0
                            sBreak +
1845
0
                            sPrecision +
1846
0
                            sBreak +
1847
0
                            sLeadZeroes +
1848
0
                            sBreak +
1849
0
                            sNatNum12 +
1850
0
                            sBreak;
1851
1852
0
                        rSet.Put(SfxStringItem(nWhich, aFormat));
1853
1854
0
                        if (comphelper::LibreOfficeKit::isActive())
1855
0
                        {
1856
0
                            OUString sPayload = ".uno:NumberFormat=" + aFormat;
1857
0
                            GetViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED,
1858
0
                                OUStringToOString(sPayload, RTL_TEXTENCODING_ASCII_US));
1859
0
                        }
1860
0
                    }
1861
0
                    else
1862
0
                    {
1863
0
                        rSet.InvalidateItem( nWhich );
1864
0
                    }
1865
0
                }
1866
0
                break;
1867
1868
0
            case SID_NUMBER_TYPE_FORMAT:
1869
0
                {
1870
0
                    sal_Int16 nFormatCategory = -1;
1871
0
                    if ( eItemState >= SfxItemState::DEFAULT ) //Modify for more robust
1872
0
                    {
1873
0
                        switch(nType)
1874
0
                        {
1875
0
                        case SvNumFormatType::NUMBER:
1876
                            // Determine if General format.
1877
0
                            if ((nNumberFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
1878
0
                                nFormatCategory = 0;
1879
0
                            else
1880
0
                                nFormatCategory = 1;
1881
0
                            break;
1882
0
                        case SvNumFormatType::PERCENT:
1883
0
                            nFormatCategory = 2;
1884
0
                            break;
1885
0
                        case SvNumFormatType::CURRENCY:
1886
0
                            nFormatCategory = 3;
1887
0
                            break;
1888
0
                        case SvNumFormatType::DATE:
1889
                            //Add
1890
0
                        case SvNumFormatType::DATETIME:
1891
0
                            nFormatCategory = 4;
1892
0
                            break;
1893
0
                        case SvNumFormatType::TIME:
1894
0
                            nFormatCategory = 5;
1895
0
                            break;
1896
0
                        case SvNumFormatType::SCIENTIFIC:
1897
0
                            nFormatCategory = 6;
1898
0
                            break;
1899
0
                        case SvNumFormatType::FRACTION:
1900
0
                            nFormatCategory = 7;
1901
0
                            break;
1902
0
                        case SvNumFormatType::LOGICAL:
1903
0
                            nFormatCategory = 8;
1904
0
                            break;
1905
0
                        case SvNumFormatType::TEXT:
1906
0
                            nFormatCategory = 9;
1907
0
                            break;
1908
0
                        default:
1909
0
                            nFormatCategory = -1;   //for more robust
1910
0
                        }
1911
0
                        if( nFormatCategory == -1 )
1912
0
                            rSet.InvalidateItem( nWhich );
1913
0
                        else
1914
0
                            rSet.Put( SfxUInt16Item( nWhich, nFormatCategory ) );
1915
0
                    }
1916
0
                    else
1917
0
                    {
1918
0
                        rSet.InvalidateItem( nWhich );
1919
0
                    }
1920
1921
0
                }
1922
0
                break;
1923
0
            case SID_NUMBER_CURRENCY:
1924
0
                rSet.Put( SfxBoolItem(nWhich, bool(nType & SvNumFormatType::CURRENCY)) );
1925
0
                break;
1926
0
            case SID_NUMBER_SCIENTIFIC:
1927
0
                rSet.Put( SfxBoolItem(nWhich, bool(nType & SvNumFormatType::SCIENTIFIC)) );
1928
0
                break;
1929
0
            case SID_NUMBER_DATE:
1930
0
                rSet.Put( SfxBoolItem(nWhich, bool(nType & SvNumFormatType::DATE)) );
1931
0
                break;
1932
0
            case SID_NUMBER_PERCENT:
1933
0
                rSet.Put( SfxBoolItem(nWhich, bool(nType & SvNumFormatType::PERCENT)) );
1934
0
                break;
1935
0
            case SID_NUMBER_TIME:
1936
0
                rSet.Put( SfxBoolItem(nWhich, bool(nType & SvNumFormatType::TIME)) );
1937
0
                break;
1938
0
            case SID_NUMBER_TWODEC:
1939
0
                    rSet.Put( SfxBoolItem(nWhich, (nType & SvNumFormatType::NUMBER) && nOffset == NF_NUMBER_1000DEC2 ) );
1940
0
                break;
1941
0
            case SID_NUMBER_STANDARD:
1942
0
                    rSet.Put( SfxBoolItem(nWhich, (nType & SvNumFormatType::NUMBER) && (nNumberFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0) );
1943
0
                break;
1944
0
        }
1945
0
        nWhich = aIter.NextWhich();
1946
0
    }
1947
0
}
1948
1949
void ScFormatShell::ExecuteTextDirection( const SfxRequest& rReq )
1950
0
{
1951
0
    ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
1952
0
    pTabViewShell->HideListBox();               // Autofilter-DropDown-Listbox
1953
0
    bool bEditMode = false;
1954
0
    if ( GetViewData().HasEditView( GetViewData().GetActivePart() ) )
1955
0
    {
1956
0
        bEditMode=true;
1957
0
        ScModule::get()->InputEnterHandler();
1958
0
        pTabViewShell->UpdateInputHandler();
1959
0
    }
1960
0
    sal_uInt16 nSlot = rReq.GetSlot();
1961
0
    switch( nSlot )
1962
0
    {
1963
0
        case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
1964
0
        case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
1965
0
        {
1966
0
            bool bVert = (nSlot == SID_TEXTDIRECTION_TOP_TO_BOTTOM);
1967
0
            ScPatternAttr aAttr(GetViewData().GetDocument().getCellAttributeHelper());
1968
0
            aAttr.ItemSetPut(ScVerticalStackCell(bVert));
1969
0
            aAttr.ItemSetPut(SfxBoolItem(ATTR_VERTICAL_ASIAN, bVert));
1970
0
            pTabViewShell->ApplySelectionPattern( aAttr );
1971
0
            pTabViewShell->AdjustBlockHeight();
1972
0
        }
1973
0
        break;
1974
1975
0
        case SID_ATTR_PARA_LEFT_TO_RIGHT:
1976
0
        case SID_ATTR_PARA_RIGHT_TO_LEFT:
1977
0
        {
1978
0
            SvxFrameDirection eDirection = ( nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT ) ?
1979
0
                                                SvxFrameDirection::Horizontal_LR_TB : SvxFrameDirection::Horizontal_RL_TB;
1980
0
            pTabViewShell->ApplyAttr( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ) );
1981
0
        }
1982
0
        break;
1983
0
    }
1984
0
    if (bEditMode)
1985
0
        ScModule::get()->SetInputMode(SC_INPUT_TABLE);
1986
0
}
1987
1988
void ScFormatShell::GetTextDirectionState( SfxItemSet& rSet )
1989
0
{
1990
0
    ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
1991
0
    const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
1992
1993
0
    bool bVertDontCare =
1994
0
        (rAttrSet.GetItemState( ATTR_VERTICAL_ASIAN ) == SfxItemState::INVALID) ||
1995
0
        (rAttrSet.GetItemState( ATTR_STACKED ) == SfxItemState::INVALID);
1996
0
    bool bLeftRight = !bVertDontCare &&
1997
0
        !rAttrSet.Get( ATTR_STACKED ).GetValue();
1998
0
    bool bTopBottom = !bVertDontCare && !bLeftRight &&
1999
0
        rAttrSet.Get( ATTR_VERTICAL_ASIAN ).GetValue();
2000
2001
0
    bool bBidiDontCare = (rAttrSet.GetItemState( ATTR_WRITINGDIR ) == SfxItemState::INVALID);
2002
0
    EEHorizontalTextDirection eBidiDir = EEHorizontalTextDirection::Default;
2003
0
    if ( !bBidiDontCare )
2004
0
    {
2005
0
        SvxFrameDirection eCellDir = rAttrSet.Get( ATTR_WRITINGDIR ).GetValue();
2006
0
        if ( eCellDir == SvxFrameDirection::Environment )
2007
0
            eBidiDir = GetViewData().GetDocument().
2008
0
                                GetEditTextDirection( GetViewData().CurrentTabForData() );
2009
0
        else if ( eCellDir == SvxFrameDirection::Horizontal_RL_TB )
2010
0
            eBidiDir = EEHorizontalTextDirection::R2L;
2011
0
        else
2012
0
            eBidiDir = EEHorizontalTextDirection::L2R;
2013
0
    }
2014
2015
0
    bool bDisableCTLFont = !SvtCTLOptions::IsCTLFontEnabled();
2016
0
    bool bDisableVerticalText = !SvtCJKOptions::IsVerticalTextEnabled();
2017
2018
0
    SfxWhichIter aIter( rSet );
2019
0
    sal_uInt16 nWhich = aIter.FirstWhich();
2020
0
    while( nWhich )
2021
0
    {
2022
0
        switch( nWhich )
2023
0
        {
2024
0
            case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
2025
0
            case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
2026
0
                if ( bDisableVerticalText )
2027
0
                    rSet.DisableItem( nWhich );
2028
0
                else
2029
0
                {
2030
0
                    if( bVertDontCare )
2031
0
                        rSet.InvalidateItem( nWhich );
2032
0
                    else if ( nWhich == SID_TEXTDIRECTION_LEFT_TO_RIGHT )
2033
0
                        rSet.Put( SfxBoolItem( nWhich, bLeftRight ) );
2034
0
                    else
2035
0
                        rSet.Put( SfxBoolItem( nWhich, bTopBottom ) );
2036
0
                }
2037
0
            break;
2038
2039
0
            case SID_ATTR_PARA_LEFT_TO_RIGHT:
2040
0
            case SID_ATTR_PARA_RIGHT_TO_LEFT:
2041
0
                if ( bDisableCTLFont )
2042
0
                    rSet.DisableItem( nWhich );
2043
0
                else
2044
0
                {
2045
0
                    if ( bTopBottom )
2046
0
                        rSet.DisableItem( nWhich );
2047
0
                    else if ( bBidiDontCare )
2048
0
                        rSet.InvalidateItem( nWhich );
2049
0
                    else if ( nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT )
2050
0
                        rSet.Put( SfxBoolItem( nWhich, eBidiDir == EEHorizontalTextDirection::L2R ) );
2051
0
                    else
2052
0
                        rSet.Put( SfxBoolItem( nWhich, eBidiDir == EEHorizontalTextDirection::R2L ) );
2053
0
                }
2054
0
        }
2055
0
        nWhich = aIter.NextWhich();
2056
0
    }
2057
0
}
2058
2059
void ScFormatShell::ExecFormatPaintbrush( const SfxRequest& rReq )
2060
0
{
2061
0
    ScViewFunc* pView = rViewData.GetView();
2062
0
    if ( pView->HasPaintBrush() )
2063
0
    {
2064
        // cancel paintbrush mode
2065
0
        pView->ResetBrushDocument();
2066
0
    }
2067
0
    else
2068
0
    {
2069
0
        bool bLock = false;
2070
0
        const SfxItemSet *pArgs = rReq.GetArgs();
2071
0
        if( pArgs && pArgs->Count() >= 1 )
2072
0
            bLock = pArgs->Get(SID_FORMATPAINTBRUSH).GetValue();
2073
2074
        // in case of multi selection, deselect all and use the cursor position
2075
0
        ScRange aDummy;
2076
0
        if ( rViewData.GetSimpleArea(aDummy) != SC_MARK_SIMPLE )
2077
0
            pView->Unmark();
2078
2079
0
        ScDocumentUniquePtr pBrushDoc(new ScDocument( SCDOCMODE_CLIP ));
2080
0
        pView->CopyToClip( pBrushDoc.get(), false, true );
2081
0
        pView->SetBrushDocument( std::move(pBrushDoc), bLock );
2082
0
    }
2083
0
}
2084
2085
void ScFormatShell::StateFormatPaintbrush( SfxItemSet& rSet )
2086
0
{
2087
0
    if ( rViewData.HasEditView( rViewData.GetActivePart() ) )
2088
0
        rSet.DisableItem( SID_FORMATPAINTBRUSH );
2089
0
    else
2090
0
        rSet.Put( SfxBoolItem( SID_FORMATPAINTBRUSH, rViewData.GetView()->HasPaintBrush() ) );
2091
0
}
2092
2093
SvNumFormatType ScFormatShell::GetCurrentNumberFormatType()
2094
0
{
2095
0
    SvNumFormatType nType = SvNumFormatType::ALL;
2096
0
    ScDocument& rDoc = GetViewData().GetDocument();
2097
0
    ScMarkData aMark(GetViewData().GetMarkData());
2098
0
    const SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
2099
0
    if (!pFormatter)
2100
0
        return nType;
2101
2102
    // TODO: Find out how to get a selected table range in case multiple tables
2103
    // are selected.  Currently we only check for the current active table.
2104
2105
0
    if ( aMark.IsMarked() || aMark.IsMultiMarked() )
2106
0
    {
2107
0
        aMark.MarkToMulti();
2108
0
        const ScRange& aRange = aMark.GetMultiMarkArea();
2109
0
        const ScMultiSel& rMultiSel = aMark.GetMultiSelData();
2110
2111
0
        SvNumFormatType nComboType = SvNumFormatType::ALL;
2112
0
        bool bFirstItem = true;
2113
0
        for (SCCOL nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol)
2114
0
        {
2115
0
            if (!rMultiSel.HasMarks(nCol))
2116
0
                continue;
2117
2118
0
            SCROW nRow1, nRow2;
2119
0
            ScMultiSelIter aMultiIter(rMultiSel, nCol);
2120
0
            while (aMultiIter.Next(nRow1, nRow2))
2121
0
            {
2122
0
                ScRange aColRange(nCol, nRow1, aRange.aStart.Tab());
2123
0
                aColRange.aEnd.SetRow(nRow2);
2124
0
                sal_uInt32 nNumFmt = rDoc.GetNumberFormat(aColRange);
2125
0
                SvNumFormatType nThisType = pFormatter->GetType(nNumFmt);
2126
0
                if (bFirstItem)
2127
0
                {
2128
0
                    bFirstItem = false;
2129
0
                    nComboType = nThisType;
2130
0
                }
2131
0
                else if (nComboType != nThisType)
2132
                    // mixed number format type.
2133
0
                    return SvNumFormatType::ALL;
2134
0
            }
2135
0
        }
2136
0
        nType = nComboType;
2137
0
    }
2138
0
    else
2139
0
    {
2140
0
        sal_uInt32 nNumFmt = rDoc.GetNumberFormat( rViewData.GetCurX(), rViewData.GetCurY(),
2141
0
                               rViewData.CurrentTabForData());
2142
0
        nType = pFormatter->GetType( nNumFmt );
2143
0
    }
2144
0
    return nType;
2145
0
}
2146
2147
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */