Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/drawfunc/drtxtob.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 <comphelper/string.hxx>
21
#include <scitems.hxx>
22
23
#include <i18nutil/transliteration.hxx>
24
#include <editeng/adjustitem.hxx>
25
#include <svx/clipfmtitem.hxx>
26
#include <editeng/colritem.hxx>
27
#include <editeng/contouritem.hxx>
28
#include <editeng/crossedoutitem.hxx>
29
#include <editeng/eeitem.hxx>
30
#include <editeng/editeng.hxx>
31
#include <editeng/editview.hxx>
32
#include <editeng/escapementitem.hxx>
33
#include <editeng/flditem.hxx>
34
#include <editeng/flstitem.hxx>
35
#include <editeng/fontitem.hxx>
36
#include <editeng/frmdiritem.hxx>
37
#include <editeng/lrspitem.hxx>
38
#include <editeng/lspcitem.hxx>
39
#include <editeng/ulspitem.hxx>
40
#include <editeng/urlfieldhelper.hxx>
41
#include <editeng/editund2.hxx>
42
#include <svx/hlnkitem.hxx>
43
#include <svx/svdoutl.hxx>
44
#include <svx/sdooitm.hxx>
45
#include <editeng/postitem.hxx>
46
#include <editeng/scriptsetitem.hxx>
47
#include <editeng/shdditem.hxx>
48
#include <editeng/udlnitem.hxx>
49
#include <editeng/wghtitem.hxx>
50
#include <editeng/writingmodeitem.hxx>
51
#include <sfx2/dispatch.hxx>
52
#include <sfx2/namedcolor.hxx>
53
#include <sfx2/objface.hxx>
54
#include <sfx2/objsh.hxx>
55
#include <sfx2/request.hxx>
56
#include <sfx2/viewfrm.hxx>
57
#include <svtools/cliplistener.hxx>
58
#include <vcl/transfer.hxx>
59
#include <svl/stritem.hxx>
60
#include <svl/whiter.hxx>
61
#include <svl/languageoptions.hxx>
62
#include <svl/cjkoptions.hxx>
63
#include <svl/ctloptions.hxx>
64
65
#include <svx/svxdlg.hxx>
66
#include <vcl/EnumContext.hxx>
67
#include <vcl/unohelp2.hxx>
68
69
#include <sc.hrc>
70
#include <globstr.hrc>
71
#include <scresid.hxx>
72
#include <scmod.hxx>
73
#include <drtxtob.hxx>
74
#include <viewdata.hxx>
75
#include <document.hxx>
76
#include <drawview.hxx>
77
#include <viewutil.hxx>
78
#include <tabvwsh.hxx>
79
#include <gridwin.hxx>
80
81
#define ShellClass_ScDrawTextObjectBar
82
#include <scslots.hxx>
83
84
using namespace ::com::sun::star;
85
86
SFX_IMPL_INTERFACE(ScDrawTextObjectBar, SfxShell)
87
88
void ScDrawTextObjectBar::InitInterface_Impl()
89
11
{
90
11
    GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT,
91
11
                                            SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server,
92
11
                                            ToolbarId::Text_Toolbox_Sc);
93
94
11
    GetStaticInterface()->RegisterPopupMenu(u"drawtext"_ustr);
95
96
11
    GetStaticInterface()->RegisterChildWindow(ScGetFontWorkId());
97
11
}
98
99
100
// disable not wanted accelerators
101
102
void ScDrawTextObjectBar::StateDisableItems( SfxItemSet &rSet )
103
0
{
104
0
    SfxWhichIter aIter(rSet);
105
0
    sal_uInt16 nWhich = aIter.FirstWhich();
106
107
0
    while (nWhich)
108
0
    {
109
0
        rSet.DisableItem( nWhich );
110
0
        nWhich = aIter.NextWhich();
111
0
    }
112
0
}
113
114
ScDrawTextObjectBar::ScDrawTextObjectBar(ScViewData& rData) :
115
0
    SfxShell(rData.GetViewShell()),
116
0
    mrViewData(rData),
117
0
    bPastePossible(false)
118
0
{
119
0
    SetPool( mrViewData.GetScDrawView()->GetDefaultAttr().GetPool() );
120
121
    //  At the switching-over the UndoManager is changed to edit mode
122
0
    SfxUndoManager* pMgr = mrViewData.GetSfxDocShell().GetUndoManager();
123
0
    SetUndoManager( pMgr );
124
0
    if ( !mrViewData.GetDocument().IsUndoEnabled() )
125
0
    {
126
0
        pMgr->SetMaxUndoActionCount( 0 );
127
0
    }
128
129
0
    SetName(u"DrawText"_ustr);
130
0
    SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::DrawText));
131
0
}
132
133
ScDrawTextObjectBar::~ScDrawTextObjectBar()
134
0
{
135
0
    if ( mxClipEvtLstnr.is() )
136
0
    {
137
0
        mxClipEvtLstnr->RemoveListener( mrViewData.GetActiveWin() );
138
139
        //  The listener may just now be waiting for the SolarMutex and call the link
140
        //  afterwards, in spite of RemoveListener. So the link has to be reset, too.
141
0
        mxClipEvtLstnr->ClearCallbackLink();
142
0
    }
143
0
}
144
145
//          Functions
146
147
void ScDrawTextObjectBar::Execute( SfxRequest &rReq )
148
0
{
149
0
    ScDrawView* pView = mrViewData.GetScDrawView();
150
0
    OutlinerView* pOutView = pView->GetTextEditOutlinerView();
151
0
    Outliner* pOutliner = pView->GetTextEditOutliner();
152
153
0
    if (!pOutView || !pOutliner)
154
0
    {
155
0
        ExecuteGlobal( rReq );              // on whole objects
156
0
        return;
157
0
    }
158
159
0
    const SfxItemSet* pReqArgs = rReq.GetArgs();
160
0
    sal_uInt16 nSlot = rReq.GetSlot();
161
0
    switch ( nSlot )
162
0
    {
163
0
        case SID_COPY:
164
0
            pOutView->Copy();
165
0
            break;
166
167
0
        case SID_CUT:
168
0
            pOutView->Cut();
169
0
            break;
170
171
0
        case SID_PASTE:
172
0
            pOutView->PasteSpecial();
173
0
            break;
174
175
0
        case SID_CLIPBOARD_FORMAT_ITEMS:
176
0
            {
177
0
                SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
178
0
                const SfxPoolItem* pItem;
179
0
                if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
180
0
                    if (auto pIntItem = dynamic_cast<const SfxUInt32Item*>( pItem))
181
0
                        nFormat = static_cast<SotClipboardFormatId>(pIntItem->GetValue());
182
183
0
                if ( nFormat != SotClipboardFormatId::NONE )
184
0
                {
185
0
                    if (nFormat == SotClipboardFormatId::STRING)
186
0
                        pOutView->Paste();
187
0
                    else
188
0
                        pOutView->PasteSpecial(nFormat);
189
0
                }
190
0
            }
191
0
            break;
192
193
0
        case SID_PASTE_SPECIAL:
194
0
            ExecutePasteContents( rReq );
195
0
            break;
196
197
0
        case SID_PASTE_UNFORMATTED:
198
0
            pOutView->Paste();
199
0
            break;
200
201
0
        case SID_SELECTALL:
202
0
            {
203
0
                sal_Int32 nCount = pOutliner->GetParagraphCount();
204
0
                ESelection aSel( 0,0,nCount,0 );
205
0
                pOutView->SetSelection( aSel );
206
0
            }
207
0
            break;
208
209
0
        case SID_CHARMAP:
210
0
            {
211
0
                auto const attribs = pOutView->GetAttribs();
212
0
                const SvxFontItem& rItem = attribs.Get(EE_CHAR_FONTINFO);
213
214
0
                OUString aString;
215
0
                std::shared_ptr<SvxFontItem> aNewItem(std::make_shared<SvxFontItem>(EE_CHAR_FONTINFO));
216
217
0
                const SfxItemSet *pArgs = rReq.GetArgs();
218
0
                const SfxPoolItem* pItem = nullptr;
219
0
                if( pArgs )
220
0
                    pArgs->GetItemState(SID_CHARMAP, false, &pItem);
221
222
0
                if ( pItem )
223
0
                {
224
0
                    aString = static_cast<const SfxStringItem*>(pItem)->GetValue();
225
0
                    const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false);
226
0
                    if ( pFontItem )
227
0
                    {
228
0
                        const OUString& aFontName(pFontItem->GetValue());
229
0
                        vcl::Font aFont(aFontName, Size(1,1)); // Size only because of CTOR
230
0
                        aNewItem = std::make_shared<SvxFontItem>(
231
0
                            aFont.GetFamilyTypeMaybeAskConfig(), aFont.GetFamilyName(),
232
0
                            aFont.GetStyleName(), aFont.GetPitchMaybeAskConfig(),
233
0
                            aFont.GetCharSet(), ATTR_FONT);
234
0
                    }
235
0
                    else
236
0
                    {
237
0
                        aNewItem.reset(rItem.Clone());
238
0
                    }
239
0
                }
240
0
                else
241
0
                    ScViewUtil::ExecuteCharMap(rItem, *mrViewData.GetViewShell());
242
243
0
                if ( !aString.isEmpty() )
244
0
                {
245
0
                    SfxItemSet aSet( pOutliner->GetEmptyItemSet() );
246
                    // tdf#125054 set and force to needed WhichID
247
0
                    aSet.PutAsTargetWhich( *aNewItem, EE_CHAR_FONTINFO );
248
249
                    //  If nothing is selected, then SetAttribs of the View selects a word
250
0
                    pOutView->GetOutliner().QuickSetAttribs( aSet, pOutView->GetSelection() );
251
0
                    pOutView->InsertText(aString);
252
0
                }
253
254
0
                Invalidate( SID_ATTR_CHAR_FONT );
255
0
            }
256
0
            break;
257
258
0
        case SID_HYPERLINK_SETLINK:
259
0
            if( pReqArgs )
260
0
            {
261
0
                if ( const SvxHyperlinkItem* pHyper = pReqArgs->GetItemIfSet( SID_HYPERLINK_SETLINK) )
262
0
                {
263
0
                    const OUString& rName = pHyper->GetName();
264
0
                    const OUString& rURL      = pHyper->GetURL();
265
0
                    const OUString& rTarget   = pHyper->GetTargetFrame();
266
0
                    SvxLinkInsertMode eMode = pHyper->GetInsertMode();
267
268
0
                    bool bDone = false;
269
0
                    if (eMode == HLINK_DEFAULT || eMode == HLINK_FIELD)
270
0
                    {
271
0
                        pOutView->SelectFieldAtCursor();
272
273
                        //  insert new field
274
0
                        SvxURLField aURLField( rURL, rName, SvxURLFormat::Repr );
275
0
                        aURLField.SetTargetFrame( rTarget );
276
0
                        SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD );
277
0
                        pOutView->InsertField( aURLItem );
278
279
0
                        bDone = true;
280
0
                    }
281
282
0
                    if (!bDone)
283
0
                        ExecuteGlobal( rReq );      // normal at View
284
285
                    //  If "text" is received by InsertURL of ViewShell, then the DrawShell is turned off !!!
286
0
                }
287
0
            }
288
0
            break;
289
290
0
        case SID_OPEN_HYPERLINK:
291
0
            {
292
0
                const SvxFieldItem* pFieldItem
293
0
                    = pOutView->GetFieldAtSelection(/*AlsoCheckBeforeCursor=*/true);
294
0
                const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr;
295
0
                if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
296
0
                {
297
0
                    ScGlobal::OpenURL(pURLField->GetURL(), pURLField->GetTargetFrame(), true);
298
0
                }
299
0
            }
300
0
            break;
301
302
0
        case SID_INSERT_HYPERLINK:
303
0
            mrViewData.GetViewShell()->GetViewFrame().GetDispatcher()->Execute(SID_HYPERLINK_DIALOG);
304
0
            break;
305
306
0
        case SID_EDIT_HYPERLINK:
307
0
            {
308
                // Ensure the field is selected first
309
0
                pOutView->SelectFieldAtCursor();
310
0
                mrViewData.GetViewShell()->GetViewFrame().GetDispatcher()->Execute(SID_HYPERLINK_DIALOG);
311
0
            }
312
0
            break;
313
314
0
        case SID_COPY_HYPERLINK_LOCATION:
315
0
            {
316
0
                const SvxFieldItem* pFieldItem
317
0
                    = pOutView->GetFieldAtSelection(/*AlsoCheckBeforeCursor=*/true);
318
0
                const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr;
319
0
                if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
320
0
                {
321
0
                    uno::Reference<datatransfer::clipboard::XClipboard> xClipboard
322
0
                        = pOutView->GetWindow()->GetClipboard();
323
0
                    vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard);
324
0
                }
325
0
            }
326
0
            break;
327
328
0
        case SID_REMOVE_HYPERLINK:
329
0
            {
330
0
                URLFieldHelper::RemoveURLField(pOutView->GetEditView());
331
0
            }
332
0
            break;
333
334
0
        case SID_ENABLE_HYPHENATION:
335
0
        case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
336
0
        case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
337
0
            pView->ScEndTextEdit(); // end text edit before switching direction
338
0
            ExecuteGlobal( rReq );
339
            // restore consistent state between shells and functions:
340
0
            mrViewData.GetDispatcher().Execute(SID_OBJECT_SELECT, SfxCallMode::SLOT | SfxCallMode::RECORD);
341
0
            break;
342
343
0
        case SID_THES:
344
0
            {
345
0
                OUString aReplaceText;
346
0
                const SfxStringItem* pItem2 = rReq.GetArg(FN_PARAM_THES_WORD_REPLACE);
347
0
                if (pItem2)
348
0
                    aReplaceText = pItem2->GetValue();
349
0
                if (!aReplaceText.isEmpty())
350
0
                    ReplaceTextWithSynonym( pOutView->GetEditView(), aReplaceText );
351
0
            }
352
0
            break;
353
354
0
        case SID_THESAURUS:
355
0
            {
356
0
                pOutView->StartThesaurus(rReq.GetFrameWeld());
357
0
            }
358
0
            break;
359
0
    }
360
0
}
361
362
void ScDrawTextObjectBar::GetState( SfxItemSet& rSet )
363
0
{
364
0
    SfxViewFrame& rViewFrm = mrViewData.GetViewShell()->GetViewFrame();
365
0
    bool bHasFontWork = rViewFrm.HasChildWindow(SID_FONTWORK);
366
0
    bool bDisableFontWork = false;
367
368
0
    if (IsNoteEdit())
369
0
    {
370
        // #i21255# notes now support rich text formatting (#i74140# but not fontwork)
371
0
        bDisableFontWork = true;
372
0
    }
373
374
0
    if ( bDisableFontWork )
375
0
        rSet.DisableItem( SID_FONTWORK  );
376
0
    else
377
0
        rSet.Put(SfxBoolItem(SID_FONTWORK, bHasFontWork));
378
379
0
    if ( rSet.GetItemState( SID_HYPERLINK_GETLINK ) != SfxItemState::UNKNOWN )
380
0
    {
381
0
        SvxHyperlinkItem aHLinkItem;
382
0
        aHLinkItem.SetShowName(false);
383
0
        SdrView* pView = mrViewData.GetScDrawView();
384
0
        OutlinerView* pOutView = pView->GetTextEditOutlinerView();
385
0
        if ( pOutView )
386
0
        {
387
0
            bool bField = false;
388
0
            const SvxFieldItem* pFieldItem = pOutView->GetFieldAtSelection();
389
0
            const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr;
390
0
            if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
391
0
            {
392
0
                aHLinkItem.SetName( pURLField->GetRepresentation() );
393
0
                aHLinkItem.SetURL( pURLField->GetURL() );
394
0
                aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() );
395
0
                bField = true;
396
0
            }
397
398
0
            if (!bField)
399
0
            {
400
                // use selected text as name for urls
401
0
                OUString sReturn = pOutView->GetSelected();
402
0
                sal_Int32 nLen = std::min<sal_Int32>(sReturn.getLength(), 255);
403
0
                sReturn = sReturn.copy(0, nLen);
404
0
                aHLinkItem.SetName(comphelper::string::stripEnd(sReturn, ' '));
405
0
            }
406
0
        }
407
0
        rSet.Put(aHLinkItem);
408
0
    }
409
410
0
    if (rSet.GetItemState(SID_OPEN_HYPERLINK) != SfxItemState::UNKNOWN
411
0
        || rSet.GetItemState(SID_INSERT_HYPERLINK) != SfxItemState::UNKNOWN
412
0
        || rSet.GetItemState(SID_EDIT_HYPERLINK) != SfxItemState::UNKNOWN
413
0
        || rSet.GetItemState(SID_COPY_HYPERLINK_LOCATION) != SfxItemState::UNKNOWN
414
0
        || rSet.GetItemState(SID_REMOVE_HYPERLINK) != SfxItemState::UNKNOWN)
415
0
    {
416
0
        OutlinerView* pOutView = mrViewData.GetScDrawView()->GetTextEditOutlinerView();
417
0
        if (!URLFieldHelper::IsCursorAtURLField(pOutView, /*AlsoCheckBeforeCursor=*/true))
418
0
        {
419
0
            rSet.DisableItem( SID_OPEN_HYPERLINK );
420
0
            rSet.DisableItem( SID_EDIT_HYPERLINK );
421
0
            rSet.DisableItem( SID_COPY_HYPERLINK_LOCATION );
422
0
            rSet.DisableItem( SID_REMOVE_HYPERLINK );
423
0
        }
424
0
        else
425
0
        {
426
0
            rSet.DisableItem( SID_INSERT_HYPERLINK );
427
0
        }
428
0
    }
429
430
0
    if( rSet.GetItemState( SID_TRANSLITERATE_HALFWIDTH ) != SfxItemState::UNKNOWN )
431
0
        ScViewUtil::HideDisabledSlot( rSet, rViewFrm.GetBindings(), SID_TRANSLITERATE_HALFWIDTH );
432
0
    if( rSet.GetItemState( SID_TRANSLITERATE_FULLWIDTH ) != SfxItemState::UNKNOWN )
433
0
        ScViewUtil::HideDisabledSlot( rSet, rViewFrm.GetBindings(), SID_TRANSLITERATE_FULLWIDTH );
434
0
    if( rSet.GetItemState( SID_TRANSLITERATE_HIRAGANA ) != SfxItemState::UNKNOWN )
435
0
        ScViewUtil::HideDisabledSlot( rSet, rViewFrm.GetBindings(), SID_TRANSLITERATE_HIRAGANA );
436
0
    if( rSet.GetItemState( SID_TRANSLITERATE_KATAKANA ) != SfxItemState::UNKNOWN )
437
0
        ScViewUtil::HideDisabledSlot( rSet, rViewFrm.GetBindings(), SID_TRANSLITERATE_KATAKANA );
438
439
0
    if ( rSet.GetItemState( SID_ENABLE_HYPHENATION ) != SfxItemState::UNKNOWN )
440
0
    {
441
0
        SdrView* pView = mrViewData.GetScDrawView();
442
0
        SfxItemSet aAttrs(pView->GetModel().GetItemPool());
443
0
        pView->GetAttributes( aAttrs );
444
0
        if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SfxItemState::DEFAULT )
445
0
        {
446
0
            bool bValue = aAttrs.Get( EE_PARA_HYPHENATE ).GetValue();
447
0
            rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION, bValue ) );
448
0
        }
449
0
    }
450
451
0
    if ( rSet.GetItemState( SID_THES ) != SfxItemState::UNKNOWN  ||
452
0
         rSet.GetItemState( SID_THESAURUS ) != SfxItemState::UNKNOWN )
453
0
    {
454
0
        SdrView * pView = mrViewData.GetScDrawView();
455
0
        OutlinerView* pOutView = pView->GetTextEditOutlinerView();
456
457
0
        OUString        aStatusVal;
458
0
        LanguageType    nLang = LANGUAGE_NONE;
459
0
        bool bIsLookUpWord = false;
460
0
        if ( pOutView )
461
0
        {
462
0
            EditView& rEditView = pOutView->GetEditView();
463
0
            bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, rEditView );
464
0
        }
465
0
        rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
466
467
        // disable thesaurus main menu and context menu entry if there is nothing to look up
468
0
        bool bCanDoThesaurus = ScModule::HasThesaurusLanguage( nLang );
469
0
        if (!bIsLookUpWord || !bCanDoThesaurus)
470
0
            rSet.DisableItem( SID_THES );
471
0
        if (!bCanDoThesaurus)
472
0
            rSet.DisableItem( SID_THESAURUS );
473
0
    }
474
475
0
    if (GetObjectShell()->isContentExtractionLocked())
476
0
    {
477
0
        rSet.DisableItem(SID_COPY);
478
0
        rSet.DisableItem(SID_CUT);
479
0
    }
480
0
}
481
482
IMPL_LINK( ScDrawTextObjectBar, ClipboardChanged, TransferableDataHelper*, pDataHelper, void )
483
0
{
484
0
    bPastePossible = ( pDataHelper->HasFormat( SotClipboardFormatId::STRING ) || pDataHelper->HasFormat( SotClipboardFormatId::RTF )
485
0
        || pDataHelper->HasFormat( SotClipboardFormatId::RICHTEXT ) );
486
487
0
    SfxBindings& rBindings = mrViewData.GetBindings();
488
0
    rBindings.Invalidate( SID_PASTE );
489
0
    rBindings.Invalidate( SID_PASTE_SPECIAL );
490
0
    rBindings.Invalidate( SID_PASTE_UNFORMATTED );
491
0
    rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
492
0
}
493
494
void ScDrawTextObjectBar::GetClipState( SfxItemSet& rSet )
495
0
{
496
0
    SdrView* pView = mrViewData.GetScDrawView();
497
0
    if ( !pView->GetTextEditOutlinerView() )
498
0
    {
499
0
        GetGlobalClipState( rSet );
500
0
        return;
501
0
    }
502
503
0
    if ( !mxClipEvtLstnr.is() )
504
0
    {
505
        // create listener
506
0
        mxClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScDrawTextObjectBar, ClipboardChanged ) );
507
0
        vcl::Window* pWin = mrViewData.GetActiveWin();
508
0
        mxClipEvtLstnr->AddListener( pWin );
509
510
        // get initial state
511
0
        TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mrViewData.GetActiveWin() ) );
512
0
        bPastePossible = ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) || aDataHelper.HasFormat( SotClipboardFormatId::RTF )
513
0
            || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) );
514
0
    }
515
516
0
    SfxWhichIter aIter( rSet );
517
0
    sal_uInt16 nWhich = aIter.FirstWhich();
518
0
    while (nWhich)
519
0
    {
520
0
        switch (nWhich)
521
0
        {
522
0
            case SID_PASTE:
523
0
            case SID_PASTE_SPECIAL:
524
0
            case SID_PASTE_UNFORMATTED:
525
0
                if( !bPastePossible )
526
0
                    rSet.DisableItem( nWhich );
527
0
                break;
528
0
            case SID_CLIPBOARD_FORMAT_ITEMS:
529
0
                if ( bPastePossible )
530
0
                {
531
0
                    SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
532
0
                    TransferableDataHelper aDataHelper(
533
0
                            TransferableDataHelper::CreateFromSystemClipboard( mrViewData.GetActiveWin() ) );
534
535
0
                    if ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) )
536
0
                        aFormats.AddClipbrdFormat( SotClipboardFormatId::STRING );
537
0
                    if ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) )
538
0
                        aFormats.AddClipbrdFormat( SotClipboardFormatId::RTF );
539
0
                    if ( aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) )
540
0
                        aFormats.AddClipbrdFormat( SotClipboardFormatId::RICHTEXT );
541
0
                    if (aDataHelper.HasFormat(SotClipboardFormatId::HTML_SIMPLE))
542
0
                        aFormats.AddClipbrdFormat(SotClipboardFormatId::HTML_SIMPLE);
543
544
0
                    rSet.Put( aFormats );
545
0
                }
546
0
                else
547
0
                    rSet.DisableItem( nWhich );
548
0
                break;
549
0
        }
550
0
        nWhich = aIter.NextWhich();
551
0
    }
552
0
}
553
554
//          Attributes
555
556
void ScDrawTextObjectBar::ExecuteToggle( SfxRequest &rReq )
557
0
{
558
    //  Underline
559
560
0
    SdrView* pView = mrViewData.GetScDrawView();
561
562
0
    sal_uInt16 nSlot = rReq.GetSlot();
563
564
0
    SfxItemSet aSet( pView->GetDefaultAttr() );
565
566
0
    SfxItemSet aViewAttr(pView->GetModel().GetItemPool());
567
0
    pView->GetAttributes(aViewAttr);
568
569
    //  Underline
570
0
    FontLineStyle eOld = aViewAttr.Get(EE_CHAR_UNDERLINE).GetLineStyle();
571
0
    FontLineStyle eNew = eOld;
572
0
    switch (nSlot)
573
0
    {
574
0
        case SID_ULINE_VAL_NONE:
575
0
            eNew = LINESTYLE_NONE;
576
0
            break;
577
0
        case SID_ULINE_VAL_SINGLE:
578
0
            eNew = ( eOld == LINESTYLE_SINGLE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
579
0
            break;
580
0
        case SID_ULINE_VAL_DOUBLE:
581
0
            eNew = ( eOld == LINESTYLE_DOUBLE ) ? LINESTYLE_NONE : LINESTYLE_DOUBLE;
582
0
            break;
583
0
        case SID_ULINE_VAL_DOTTED:
584
0
            eNew = ( eOld == LINESTYLE_DOTTED ) ? LINESTYLE_NONE : LINESTYLE_DOTTED;
585
0
            break;
586
0
        default:
587
0
            break;
588
0
    }
589
0
    aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) );
590
591
0
    pView->SetAttributes( aSet );
592
0
    rReq.Done();
593
0
    mrViewData.GetScDrawView()->InvalidateDrawTextAttrs();
594
0
}
595
596
static void lcl_RemoveFields( OutlinerView& rOutView )
597
0
{
598
    //! Outliner should have RemoveFields with a selection
599
600
0
    Outliner& rOutliner = rOutView.GetOutliner();
601
602
0
    ESelection aOldSel = rOutView.GetSelection();
603
0
    ESelection aSel = aOldSel;
604
0
    aSel.Adjust();
605
0
    sal_Int32 nNewEnd = aSel.end.nIndex;
606
607
0
    bool bUpdate = rOutliner.IsUpdateLayout();
608
0
    bool bChanged = false;
609
610
    //! GetPortions and GetAttribs should be const!
611
0
    EditEngine& rEditEng = const_cast<EditEngine&>(rOutliner.GetEditEngine());
612
613
0
    sal_Int32 nParCount = rOutliner.GetParagraphCount();
614
0
    for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
615
0
        if (nPar >= aSel.start.nPara && nPar <= aSel.end.nPara)
616
0
        {
617
0
            std::vector<sal_Int32> aPortions;
618
0
            rEditEng.GetPortions( nPar, aPortions );
619
620
0
            for ( size_t nPos = aPortions.size(); nPos; )
621
0
            {
622
0
                --nPos;
623
0
                sal_Int32 nEnd = aPortions[ nPos ];
624
0
                sal_Int32 nStart = nPos ? aPortions[ nPos - 1 ] : 0;
625
                // fields are single characters
626
0
                if ( nEnd == nStart+1 &&
627
0
                     ( nPar > aSel.start.nPara || nStart >= aSel.start.nIndex ) &&
628
0
                     ( nPar < aSel.end.nPara   || nEnd   <= aSel.end.nIndex ) )
629
0
                {
630
0
                    ESelection aFieldSel( nPar, nStart, nPar, nEnd );
631
0
                    SfxItemSet aSet = rEditEng.GetAttribs( aFieldSel );
632
0
                    if ( aSet.GetItemState( EE_FEATURE_FIELD ) == SfxItemState::SET )
633
0
                    {
634
0
                        if (!bChanged)
635
0
                        {
636
0
                            if (bUpdate)
637
0
                                rOutliner.SetUpdateLayout( false );
638
0
                            OUString aName = ScResId( STR_UNDO_DELETECONTENTS );
639
0
                            ViewShellId nViewShellId(-1);
640
0
                            if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell())
641
0
                                nViewShellId = pViewSh->GetViewShellId();
642
0
                            rOutliner.GetUndoManager().EnterListAction( aName, aName, 0, nViewShellId );
643
0
                            bChanged = true;
644
0
                        }
645
646
0
                        OUString aFieldText = rEditEng.GetText( aFieldSel );
647
0
                        rOutliner.QuickInsertText( aFieldText, aFieldSel );
648
0
                        if (nPar == aSel.end.nPara)
649
0
                        {
650
0
                            nNewEnd = nNewEnd + aFieldText.getLength();
651
0
                            --nNewEnd;
652
0
                        }
653
0
                    }
654
0
                }
655
0
            }
656
0
        }
657
658
0
    if (bUpdate && bChanged)
659
0
    {
660
0
        rOutliner.GetUndoManager().LeaveListAction();
661
0
        rOutliner.SetUpdateLayout( true );
662
0
    }
663
664
0
    if ( aOldSel == aSel )          // aSel is adjusted
665
0
        aOldSel.end.nIndex = nNewEnd;
666
0
    else
667
0
        aOldSel.start.nIndex = nNewEnd;        // if aOldSel is backwards
668
0
    rOutView.SetSelection( aOldSel );
669
0
}
670
671
void ScDrawTextObjectBar::ExecuteAttr( SfxRequest &rReq )
672
0
{
673
0
    SdrView*            pView = mrViewData.GetScDrawView();
674
0
    const SfxItemSet*   pArgs = rReq.GetArgs();
675
0
    sal_uInt16          nSlot = rReq.GetSlot();
676
677
0
    SfxItemSet aEditAttr( pView->GetModel().GetItemPool() );
678
0
    pView->GetAttributes( aEditAttr );
679
0
    SfxItemSet  aNewAttr( *aEditAttr.GetPool(), aEditAttr.GetRanges() );
680
681
0
    bool bSet = true;
682
0
    switch ( nSlot )
683
0
    {
684
0
        case SID_ALIGNLEFT:
685
0
        case SID_ALIGN_ANY_LEFT:
686
0
        case SID_ATTR_PARA_ADJUST_LEFT:
687
0
            aNewAttr.Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) );
688
0
            break;
689
690
0
        case SID_ALIGNCENTERHOR:
691
0
        case SID_ALIGN_ANY_HCENTER:
692
0
        case SID_ATTR_PARA_ADJUST_CENTER:
693
0
            aNewAttr.Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
694
0
            break;
695
696
0
        case SID_ALIGNRIGHT:
697
0
        case SID_ALIGN_ANY_RIGHT:
698
0
        case SID_ATTR_PARA_ADJUST_RIGHT:
699
0
            aNewAttr.Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
700
0
            break;
701
702
0
        case SID_ALIGNBLOCK:
703
0
        case SID_ALIGN_ANY_JUSTIFIED:
704
0
        case SID_ATTR_PARA_ADJUST_BLOCK:
705
0
            aNewAttr.Put( SvxAdjustItem( SvxAdjust::Block, EE_PARA_JUST ) );
706
0
            break;
707
708
0
        case SID_ATTR_PARA_LINESPACE_10:
709
0
            {
710
0
                SvxLineSpacingItem aItem( LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL );
711
0
                aItem.SetPropLineSpace( 100 );
712
0
                aNewAttr.Put( aItem );
713
0
            }
714
0
            break;
715
716
0
        case SID_ATTR_PARA_LINESPACE_15:
717
0
            {
718
0
                SvxLineSpacingItem aItem( LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL );
719
0
                aItem.SetPropLineSpace( 150 );
720
0
                aNewAttr.Put( aItem );
721
0
            }
722
0
            break;
723
724
0
        case SID_ATTR_PARA_LINESPACE_20:
725
0
            {
726
0
                SvxLineSpacingItem aItem( LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL );
727
0
                aItem.SetPropLineSpace( 200 );
728
0
                aNewAttr.Put( aItem );
729
0
            }
730
0
            break;
731
732
0
        case SID_SET_SUPER_SCRIPT:
733
0
            {
734
0
                SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
735
0
                SvxEscapement eEsc = aEditAttr.Get(EE_CHAR_ESCAPEMENT).GetEscapement();
736
737
0
                if( eEsc == SvxEscapement::Superscript )
738
0
                    aItem.SetEscapement( SvxEscapement::Off );
739
0
                else
740
0
                    aItem.SetEscapement( SvxEscapement::Superscript );
741
0
                aNewAttr.Put( aItem );
742
0
            }
743
0
            break;
744
745
0
        case SID_SET_SUB_SCRIPT:
746
0
            {
747
0
                SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
748
0
                SvxEscapement eEsc = aEditAttr.Get(EE_CHAR_ESCAPEMENT).GetEscapement();
749
750
0
                if( eEsc == SvxEscapement::Subscript )
751
0
                    aItem.SetEscapement( SvxEscapement::Off );
752
0
                else
753
0
                    aItem.SetEscapement( SvxEscapement::Subscript );
754
0
                aNewAttr.Put( aItem );
755
0
            }
756
0
            break;
757
758
0
        case SID_TABLE_VERT_NONE:
759
0
        case SID_TABLE_VERT_CENTER:
760
0
        case SID_TABLE_VERT_BOTTOM:
761
0
            {
762
0
                SdrTextVertAdjust eTVA = SDRTEXTVERTADJUST_TOP;
763
0
                if (nSlot == SID_TABLE_VERT_CENTER)
764
0
                    eTVA = SDRTEXTVERTADJUST_CENTER;
765
0
                else if (nSlot == SID_TABLE_VERT_BOTTOM)
766
0
                    eTVA = SDRTEXTVERTADJUST_BOTTOM;
767
0
                aNewAttr.Put(SdrTextVertAdjustItem(eTVA));
768
0
            }
769
0
            break;
770
771
0
        case SID_PARASPACE_INCREASE:
772
0
        case SID_PARASPACE_DECREASE:
773
0
        {
774
0
            SvxULSpaceItem aULSpace( aEditAttr.Get( EE_PARA_ULSPACE ) );
775
0
            sal_uInt16 nUpper = aULSpace.GetUpper();
776
0
            sal_uInt16 nLower = aULSpace.GetLower();
777
778
0
            if ( nSlot == SID_PARASPACE_INCREASE )
779
0
            {
780
0
                nUpper += 100;
781
0
                nLower += 100;
782
0
            }
783
0
            else
784
0
            {
785
0
                nUpper = std::max< sal_Int16 >( nUpper - 100, 0 );
786
0
                nLower = std::max< sal_Int16 >( nLower - 100, 0 );
787
0
            }
788
789
0
            aULSpace.SetUpper( nUpper );
790
0
            aULSpace.SetLower( nLower );
791
0
            aNewAttr.Put( aULSpace );
792
0
        }
793
0
        break;
794
795
0
        default:
796
0
            bSet = false;
797
0
    }
798
799
0
    bool bDone = true;
800
0
    bool bArgsInReq = ( pArgs != nullptr );
801
802
0
    if ( !bArgsInReq )
803
0
    {
804
0
        switch ( nSlot )
805
0
        {
806
0
            case SID_CELL_FORMAT_RESET:
807
0
            case SID_TEXT_STANDARD:
808
0
            {
809
0
                OutlinerView* pOutView = pView->IsTextEdit() ?
810
0
                                pView->GetTextEditOutlinerView() : nullptr;
811
0
                if ( pOutView )
812
0
                    pOutView->DrawText_ToEditView( tools::Rectangle() );
813
814
0
                SfxItemSetFixed<EE_ITEMS_START, EE_ITEMS_END> aEmptyAttr( *aEditAttr.GetPool() );
815
0
                SfxItemSetFixed<SDRATTR_TEXT_MINFRAMEHEIGHT, SDRATTR_TEXT_MINFRAMEHEIGHT,
816
0
                                SDRATTR_TEXT_MAXFRAMEHEIGHT, SDRATTR_TEXT_MAXFRAMEWIDTH> aSizeAttr(*aEditAttr.GetPool());
817
818
0
                aSizeAttr.Put(pView->GetAttrFromMarked(true));
819
0
                pView->SetAttributes( aEmptyAttr, true );
820
821
0
                if (IsNoteEdit())
822
0
                {
823
0
                    pView->SetAttributes(aSizeAttr, false);
824
0
                    pView->GetTextEditObject()->AdjustTextFrameWidthAndHeight();
825
0
                }
826
827
0
                if ( pOutView )
828
0
                {
829
0
                    lcl_RemoveFields( *pOutView );
830
0
                    pOutView->ShowCursor();
831
0
                }
832
833
0
                rReq.Done( aEmptyAttr );
834
0
                mrViewData.GetScDrawView()->InvalidateDrawTextAttrs();
835
0
                bDone = false; // already happened here
836
0
            }
837
0
            break;
838
839
0
            case SID_GROW_FONT_SIZE:
840
0
            case SID_SHRINK_FONT_SIZE:
841
0
            {
842
0
                OutlinerView* pOutView = pView->IsTextEdit() ?
843
0
                    pView->GetTextEditOutlinerView() : nullptr;
844
0
                if ( pOutView )
845
0
                {
846
0
                    if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
847
0
                    {
848
0
                        const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
849
0
                                ( pObjSh->GetItem( SID_ATTR_CHAR_FONTLIST ) );
850
0
                        const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
851
0
                        pOutView->GetEditView().ChangeFontSize( nSlot == SID_GROW_FONT_SIZE, pFontList );
852
0
                        mrViewData.GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
853
0
                    }
854
0
                    bDone = false;
855
0
                }
856
0
            }
857
0
            break;
858
859
0
            case SID_CHAR_DLG_EFFECT:
860
0
            case SID_CHAR_DLG:                      // dialog button
861
0
            case SID_ATTR_CHAR_FONT:                // Controller not shown
862
0
            case SID_ATTR_CHAR_FONTHEIGHT:
863
0
                bDone = ExecuteCharDlg( aEditAttr, aNewAttr , nSlot);
864
0
                break;
865
866
0
            case SID_PARA_DLG:
867
0
                bDone = ExecuteParaDlg( aEditAttr, aNewAttr );
868
0
                break;
869
870
0
            case SID_ATTR_CHAR_WEIGHT:
871
0
                aNewAttr.Put( aEditAttr.Get( EE_CHAR_WEIGHT ) );
872
0
                break;
873
874
0
            case SID_ATTR_CHAR_POSTURE:
875
0
                aNewAttr.Put( aEditAttr.Get( EE_CHAR_ITALIC ) );
876
0
                break;
877
878
0
            case SID_ATTR_CHAR_UNDERLINE:
879
0
                aNewAttr.Put( aEditAttr.Get( EE_CHAR_UNDERLINE ) );
880
0
                break;
881
882
0
            case SID_ATTR_CHAR_OVERLINE:
883
0
                aNewAttr.Put( aEditAttr.Get( EE_CHAR_OVERLINE ) );
884
0
                break;
885
886
0
            case SID_ATTR_CHAR_CONTOUR:
887
0
                aNewAttr.Put( aEditAttr.Get( EE_CHAR_OUTLINE ) );
888
0
                break;
889
890
0
            case SID_ATTR_CHAR_SHADOWED:
891
0
                aNewAttr.Put( aEditAttr.Get( EE_CHAR_SHADOW ) );
892
0
                break;
893
894
0
            case SID_ATTR_CHAR_STRIKEOUT:
895
0
                aNewAttr.Put( aEditAttr.Get( EE_CHAR_STRIKEOUT ) );
896
0
                break;
897
898
0
            case SID_DRAWTEXT_ATTR_DLG:
899
0
                {
900
0
                    SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
901
0
                    VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(mrViewData.GetDialogParent(), &aEditAttr, pView));
902
0
                    auto xRequest = std::make_shared<SfxRequest>(rReq);
903
0
                    rReq.Ignore(); // the 'old' request is not relevant any more
904
0
                    pDlg->StartExecuteAsync(
905
0
                        [this, pDlg, pArgs, aNewAttr, bSet, xRequest=std::move(xRequest), pView] (sal_Int32 nResult) mutable -> void
906
0
                        {
907
0
                            if ( RET_OK == nResult )
908
0
                                aNewAttr.Put( *pDlg->GetOutputItemSet() );
909
910
0
                            pDlg->disposeOnce();
911
912
0
                            SfxBindings& rBindings = mrViewData.GetBindings();
913
0
                            rBindings.Invalidate( SID_TABLE_VERT_NONE );
914
0
                            rBindings.Invalidate( SID_TABLE_VERT_CENTER );
915
0
                            rBindings.Invalidate( SID_TABLE_VERT_BOTTOM );
916
917
0
                            if ( bSet || RET_OK == nResult )
918
0
                            {
919
0
                                xRequest->Done( aNewAttr );
920
0
                                pArgs = xRequest->GetArgs();
921
0
                            }
922
0
                            if (pArgs)
923
0
                            {
924
                                // use args directly
925
0
                                pView->SetAttributes( *pArgs );
926
0
                                mrViewData.GetScDrawView()->InvalidateDrawTextAttrs();
927
0
                            }
928
0
                        }
929
0
                    );
930
0
                }
931
0
                break;
932
0
            case SID_ATTR_CHAR_COLOR:
933
0
            case SID_ATTR_CHAR_BACK_COLOR:
934
0
            {
935
0
                const sal_uInt16 nEEWhich = GetPool().GetWhichIDFromSlotID(nSlot);
936
0
                const std::optional<NamedColor> oColor
937
0
                    = mrViewData.GetDocShell().GetRecentColor(nSlot);
938
0
                if (oColor.has_value())
939
0
                {
940
0
                    const model::ComplexColor aCol = (*oColor).getComplexColor();
941
0
                    aNewAttr.Put(SvxColorItem(aCol.getFinalColor(), aCol, nEEWhich));
942
0
                }
943
0
                break;
944
0
            }
945
0
        }
946
0
    }
947
948
0
    if ( bSet || bDone )
949
0
    {
950
0
        rReq.Done( aNewAttr );
951
0
        pArgs = rReq.GetArgs();
952
0
    }
953
954
0
    if ( !pArgs )
955
0
        return;
956
957
0
    if ( bArgsInReq &&
958
0
        ( nSlot == SID_ATTR_CHAR_FONT || nSlot == SID_ATTR_CHAR_FONTHEIGHT ||
959
0
          nSlot == SID_ATTR_CHAR_WEIGHT || nSlot == SID_ATTR_CHAR_POSTURE ) )
960
0
    {
961
        // font items from toolbox controller have to be applied for the right script type
962
963
        // #i78017 establish the same behaviour as in Writer
964
0
        SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
965
0
        if (nSlot == SID_ATTR_CHAR_FONT)
966
0
            nScript = pView->GetScriptType();
967
968
0
        SfxItemPool& rPool = GetPool();
969
0
        SvxScriptSetItem aSetItem( nSlot, rPool );
970
0
        sal_uInt16 nWhich = rPool.GetWhichIDFromSlotID( nSlot );
971
0
        aSetItem.PutItemForScriptType( nScript, pArgs->Get( nWhich ) );
972
973
0
        pView->SetAttributes( aSetItem.GetItemSet() );
974
0
    }
975
0
    else if( nSlot == SID_ATTR_PARA_LRSPACE )
976
0
    {
977
0
        sal_uInt16 nId = SID_ATTR_PARA_LRSPACE;
978
0
        const SvxLRSpaceItem& rItem = static_cast<const SvxLRSpaceItem&>(
979
0
            pArgs->Get( nId ));
980
0
        SfxItemSetFixed<EE_PARA_LRSPACE, EE_PARA_LRSPACE> aAttr( GetPool() );
981
0
        nId = EE_PARA_LRSPACE;
982
0
        SvxLRSpaceItem aLRSpaceItem(rItem.GetLeft(), rItem.GetRight(),
983
0
                                    rItem.GetTextFirstLineOffset(), nId);
984
0
        aAttr.Put( aLRSpaceItem );
985
0
        pView->SetAttributes( aAttr );
986
0
    }
987
0
    else if( nSlot == SID_ATTR_PARA_LINESPACE )
988
0
    {
989
0
        SvxLineSpacingItem aLineSpaceItem = static_cast<const SvxLineSpacingItem&>(pArgs->Get(
990
0
                                                            GetPool().GetWhichIDFromSlotID(nSlot)));
991
0
        SfxItemSetFixed<EE_PARA_SBL, EE_PARA_SBL> aAttr( GetPool() );
992
0
        aAttr.Put( aLineSpaceItem );
993
0
        pView->SetAttributes( aAttr );
994
0
    }
995
0
    else if( nSlot == SID_ATTR_PARA_ULSPACE )
996
0
    {
997
0
        SvxULSpaceItem aULSpaceItem = static_cast<const SvxULSpaceItem&>(pArgs->Get(
998
0
                                                            GetPool().GetWhichIDFromSlotID(nSlot)));
999
0
        SfxItemSetFixed<EE_PARA_ULSPACE, EE_PARA_ULSPACE> aAttr( GetPool() );
1000
0
        aULSpaceItem.SetWhich(EE_PARA_ULSPACE);
1001
0
        aAttr.Put( aULSpaceItem );
1002
0
        pView->SetAttributes( aAttr );
1003
0
    }
1004
0
    else
1005
0
    {
1006
        // use args directly
1007
0
        pView->SetAttributes( *pArgs );
1008
0
    }
1009
0
    mrViewData.GetScDrawView()->InvalidateDrawTextAttrs();
1010
0
}
1011
1012
void ScDrawTextObjectBar::GetAttrState( SfxItemSet& rDestSet )
1013
0
{
1014
0
    if ( IsNoteEdit() )
1015
0
    {
1016
        // issue 21255 - Notes now support rich text formatting.
1017
0
    }
1018
1019
0
    bool bDisableCTLFont = !::SvtCTLOptions::IsCTLFontEnabled();
1020
0
    bool bDisableVerticalText = !SvtCJKOptions::IsVerticalTextEnabled();
1021
1022
0
    SdrView* pView = mrViewData.GetScDrawView();
1023
0
    SfxItemSet aAttrSet(pView->GetModel().GetItemPool());
1024
0
    pView->GetAttributes(aAttrSet);
1025
1026
    //  direct attributes
1027
1028
0
    rDestSet.Put( aAttrSet );
1029
1030
    //  choose font info according to selection script type
1031
1032
0
    SvtScriptType nScript = pView->GetScriptType();
1033
1034
    // #i55929# input-language-dependent script type (depends on input language if nothing selected)
1035
0
    SvtScriptType nInputScript = nScript;
1036
0
    OutlinerView* pOutView = pView->GetTextEditOutlinerView();
1037
0
    if (pOutView && !pOutView->GetSelection().HasRange())
1038
0
    {
1039
0
        LanguageType nInputLang = mrViewData.GetActiveWin()->GetInputLanguage();
1040
0
        if (nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
1041
0
            nInputScript = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
1042
0
    }
1043
1044
    // #i55929# according to spec, nInputScript is used for font and font height only
1045
0
    if ( rDestSet.GetItemState( EE_CHAR_FONTINFO ) != SfxItemState::UNKNOWN )
1046
0
        ScViewUtil::PutItemScript( rDestSet, aAttrSet, EE_CHAR_FONTINFO, nInputScript );
1047
0
    if ( rDestSet.GetItemState( EE_CHAR_FONTHEIGHT ) != SfxItemState::UNKNOWN )
1048
0
        ScViewUtil::PutItemScript( rDestSet, aAttrSet, EE_CHAR_FONTHEIGHT, nInputScript );
1049
0
    if ( rDestSet.GetItemState( EE_CHAR_WEIGHT ) != SfxItemState::UNKNOWN )
1050
0
        ScViewUtil::PutItemScript( rDestSet, aAttrSet, EE_CHAR_WEIGHT, nScript );
1051
0
    if ( rDestSet.GetItemState( EE_CHAR_ITALIC ) != SfxItemState::UNKNOWN )
1052
0
        ScViewUtil::PutItemScript( rDestSet, aAttrSet, EE_CHAR_ITALIC, nScript );
1053
    //  Alignment
1054
1055
0
    SvxAdjust eAdj = aAttrSet.Get(EE_PARA_JUST).GetAdjust();
1056
0
    switch( eAdj )
1057
0
    {
1058
0
    case SvxAdjust::Left:
1059
0
        {
1060
0
            rDestSet.Put( SfxBoolItem( SID_ALIGNLEFT, true ) );
1061
0
            rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT, true ) );
1062
0
        }
1063
0
        break;
1064
0
    case SvxAdjust::Center:
1065
0
        {
1066
0
            rDestSet.Put( SfxBoolItem( SID_ALIGNCENTERHOR, true ) );
1067
0
            rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER, true ) );
1068
0
        }
1069
0
        break;
1070
0
    case SvxAdjust::Right:
1071
0
        {
1072
0
            rDestSet.Put( SfxBoolItem( SID_ALIGNRIGHT, true ) );
1073
0
            rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT, true ) );
1074
0
        }
1075
0
        break;
1076
0
    case SvxAdjust::Block:
1077
0
        {
1078
0
            rDestSet.Put( SfxBoolItem( SID_ALIGNBLOCK, true ) );
1079
0
            rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK, true ) );
1080
0
        }
1081
0
        break;
1082
0
        default:
1083
0
        {
1084
            // added to avoid warnings
1085
0
        }
1086
0
    }
1087
    // pseudo slots for Format menu
1088
0
    rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_LEFT,      eAdj == SvxAdjust::Left ) );
1089
0
    rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_HCENTER,   eAdj == SvxAdjust::Center ) );
1090
0
    rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_RIGHT,     eAdj == SvxAdjust::Right ) );
1091
0
    rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_JUSTIFIED, eAdj == SvxAdjust::Block ) );
1092
1093
0
    SvxLRSpaceItem aLR = aAttrSet.Get( EE_PARA_LRSPACE );
1094
0
    aLR.SetWhich(SID_ATTR_PARA_LRSPACE);
1095
0
    rDestSet.Put(aLR);
1096
0
    Invalidate( SID_ATTR_PARA_LRSPACE );
1097
0
    SfxItemState eState = aAttrSet.GetItemState( EE_PARA_LRSPACE );
1098
0
    if ( eState == SfxItemState::INVALID )
1099
0
        rDestSet.InvalidateItem(SID_ATTR_PARA_LRSPACE);
1100
    //xuxu for Line Space
1101
0
    SvxLineSpacingItem aLineSP = aAttrSet.Get( EE_PARA_SBL );
1102
0
    aLineSP.SetWhich(SID_ATTR_PARA_LINESPACE);
1103
0
    rDestSet.Put(aLineSP);
1104
0
    Invalidate(SID_ATTR_PARA_LINESPACE);
1105
0
    eState = aAttrSet.GetItemState( EE_PARA_SBL );
1106
0
    if ( eState == SfxItemState::INVALID )
1107
0
        rDestSet.InvalidateItem(SID_ATTR_PARA_LINESPACE);
1108
    //xuxu for UL Space
1109
0
    SvxULSpaceItem aULSP = aAttrSet.Get( EE_PARA_ULSPACE );
1110
0
    aULSP.SetWhich(SID_ATTR_PARA_ULSPACE);
1111
0
    rDestSet.Put(aULSP);
1112
0
    Invalidate(SID_ATTR_PARA_ULSPACE);
1113
0
    Invalidate(SID_PARASPACE_INCREASE);
1114
0
    Invalidate(SID_PARASPACE_DECREASE);
1115
0
    eState = aAttrSet.GetItemState( EE_PARA_ULSPACE );
1116
0
    if( eState >= SfxItemState::DEFAULT )
1117
0
    {
1118
0
        if ( !aULSP.GetUpper() && !aULSP.GetLower() )
1119
0
            rDestSet.DisableItem( SID_PARASPACE_DECREASE );
1120
0
    }
1121
0
    else
1122
0
    {
1123
0
        rDestSet.DisableItem( SID_PARASPACE_INCREASE );
1124
0
        rDestSet.DisableItem( SID_PARASPACE_DECREASE );
1125
0
        rDestSet.InvalidateItem(SID_ATTR_PARA_ULSPACE);
1126
0
    }
1127
1128
    //  Line spacing
1129
1130
0
    sal_uInt16 nLineSpace = aAttrSet.Get( EE_PARA_SBL ).GetPropLineSpace();
1131
0
    switch( nLineSpace )
1132
0
    {
1133
0
        case 100:
1134
0
            rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_10, true ) );
1135
0
            break;
1136
0
        case 150:
1137
0
            rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_15, true ) );
1138
0
            break;
1139
0
        case 200:
1140
0
            rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_20, true ) );
1141
0
            break;
1142
0
    }
1143
1144
    //  super-/subscript
1145
0
    SvxEscapement eEsc = aAttrSet.Get(EE_CHAR_ESCAPEMENT).GetEscapement();
1146
0
    rDestSet.Put(SfxBoolItem(SID_SET_SUPER_SCRIPT, eEsc == SvxEscapement::Superscript));
1147
0
    rDestSet.Put(SfxBoolItem(SID_SET_SUB_SCRIPT, eEsc == SvxEscapement::Subscript));
1148
1149
    //  Underline
1150
0
    eState = aAttrSet.GetItemState( EE_CHAR_UNDERLINE );
1151
0
    if ( eState == SfxItemState::INVALID )
1152
0
    {
1153
0
        rDestSet.InvalidateItem( SID_ULINE_VAL_NONE );
1154
0
        rDestSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1155
0
        rDestSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1156
0
        rDestSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1157
0
    }
1158
0
    else
1159
0
    {
1160
0
        FontLineStyle eUnderline = aAttrSet.Get(EE_CHAR_UNDERLINE).GetLineStyle();
1161
0
        rDestSet.Put(SfxBoolItem(SID_ULINE_VAL_SINGLE, eUnderline == LINESTYLE_SINGLE));
1162
0
        rDestSet.Put(SfxBoolItem(SID_ULINE_VAL_DOUBLE, eUnderline == LINESTYLE_DOUBLE));
1163
0
        rDestSet.Put(SfxBoolItem(SID_ULINE_VAL_DOTTED, eUnderline == LINESTYLE_DOTTED));
1164
0
        rDestSet.Put(SfxBoolItem(SID_ULINE_VAL_NONE, eUnderline == LINESTYLE_NONE));
1165
0
    }
1166
1167
    //  horizontal / vertical
1168
1169
0
    bool bLeftToRight = true;
1170
1171
0
    SdrOutliner* pOutl = pView->GetTextEditOutliner();
1172
0
    if( pOutl )
1173
0
    {
1174
0
        if( pOutl->IsVertical() )
1175
0
            bLeftToRight = false;
1176
0
    }
1177
0
    else
1178
0
        bLeftToRight = aAttrSet.Get( SDRATTR_TEXTDIRECTION ).GetValue() == css::text::WritingMode_LR_TB;
1179
1180
0
    if ( bDisableVerticalText )
1181
0
    {
1182
0
        rDestSet.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT );
1183
0
        rDestSet.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM );
1184
0
    }
1185
0
    else
1186
0
    {
1187
0
        rDestSet.Put( SfxBoolItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT, bLeftToRight ) );
1188
0
        rDestSet.Put( SfxBoolItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM, !bLeftToRight ) );
1189
0
    }
1190
1191
    //  left-to-right or right-to-left
1192
1193
0
    if ( !bLeftToRight || bDisableCTLFont )
1194
0
    {
1195
        //  disabled if vertical
1196
0
        rDestSet.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT );
1197
0
        rDestSet.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT );
1198
0
    }
1199
0
    else if ( aAttrSet.GetItemState( EE_PARA_WRITINGDIR ) == SfxItemState::INVALID )
1200
0
    {
1201
0
        rDestSet.InvalidateItem( SID_ATTR_PARA_LEFT_TO_RIGHT );
1202
0
        rDestSet.InvalidateItem( SID_ATTR_PARA_RIGHT_TO_LEFT );
1203
0
    }
1204
0
    else
1205
0
    {
1206
0
        SvxFrameDirection eAttrDir = aAttrSet.Get( EE_PARA_WRITINGDIR ).GetValue();
1207
0
        if ( eAttrDir == SvxFrameDirection::Environment )
1208
0
        {
1209
            //  get "environment" direction from page style
1210
0
            if ( mrViewData.GetDocument().GetEditTextDirection( mrViewData.CurrentTabForData() ) == EEHorizontalTextDirection::R2L )
1211
0
                eAttrDir = SvxFrameDirection::Horizontal_RL_TB;
1212
0
            else
1213
0
                eAttrDir = SvxFrameDirection::Horizontal_LR_TB;
1214
0
        }
1215
0
        rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT, ( eAttrDir == SvxFrameDirection::Horizontal_LR_TB ) ) );
1216
0
        rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT, ( eAttrDir == SvxFrameDirection::Horizontal_RL_TB ) ) );
1217
0
    }
1218
0
}
1219
1220
void ScDrawTextObjectBar::ExecuteTrans( const SfxRequest& rReq )
1221
0
{
1222
0
    TransliterationFlags nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
1223
0
    if ( nType == TransliterationFlags::NONE )
1224
0
        return;
1225
1226
0
    ScDrawView* pView = mrViewData.GetScDrawView();
1227
0
    OutlinerView* pOutView = pView->GetTextEditOutlinerView();
1228
0
    if ( pOutView )
1229
0
    {
1230
        //  change selected text in object
1231
0
        pOutView->TransliterateText( nType );
1232
0
    }
1233
0
    else
1234
0
    {
1235
        //! apply to whole objects?
1236
0
    }
1237
0
}
1238
1239
void ScDrawTextObjectBar::GetStatePropPanelAttr(SfxItemSet &rSet)
1240
0
{
1241
0
    SfxWhichIter    aIter( rSet );
1242
0
    sal_uInt16          nWhich = aIter.FirstWhich();
1243
1244
0
    SdrView*            pView = mrViewData.GetScDrawView();
1245
1246
0
    SfxItemSet aEditAttr(pView->GetModel().GetItemPool());
1247
0
    pView->GetAttributes(aEditAttr);
1248
    //SfxItemSet    aAttrs( *aEditAttr.GetPool(), aEditAttr.GetRanges() );
1249
1250
0
    while ( nWhich )
1251
0
    {
1252
0
        sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
1253
0
            ? GetPool().GetSlotId(nWhich)
1254
0
            : nWhich;
1255
0
        switch ( nSlotId )
1256
0
        {
1257
0
            case SID_TABLE_VERT_NONE:
1258
0
            case SID_TABLE_VERT_CENTER:
1259
0
            case SID_TABLE_VERT_BOTTOM:
1260
0
                bool bContour = false;
1261
0
                SfxItemState eConState = aEditAttr.GetItemState( SDRATTR_TEXT_CONTOURFRAME );
1262
0
                if( eConState != SfxItemState::INVALID )
1263
0
                {
1264
0
                    bContour = aEditAttr.Get( SDRATTR_TEXT_CONTOURFRAME ).GetValue();
1265
0
                }
1266
0
                if (bContour) break;
1267
1268
0
                SfxItemState eVState = aEditAttr.GetItemState( SDRATTR_TEXT_VERTADJUST );
1269
                //SfxItemState eHState = aAttrs.GetItemState( SDRATTR_TEXT_HORZADJUST );
1270
1271
                //if(SfxItemState::INVALID != eVState && SfxItemState::INVALID != eHState)
1272
0
                if(SfxItemState::INVALID != eVState)
1273
0
                {
1274
0
                    SdrTextVertAdjust eTVA = aEditAttr.Get(SDRATTR_TEXT_VERTADJUST).GetValue();
1275
0
                    bool bSet = (nSlotId == SID_TABLE_VERT_NONE && eTVA == SDRTEXTVERTADJUST_TOP) ||
1276
0
                            (nSlotId == SID_TABLE_VERT_CENTER && eTVA == SDRTEXTVERTADJUST_CENTER) ||
1277
0
                            (nSlotId == SID_TABLE_VERT_BOTTOM && eTVA == SDRTEXTVERTADJUST_BOTTOM);
1278
0
                    rSet.Put(SfxBoolItem(nSlotId, bSet));
1279
0
                }
1280
0
                else
1281
0
                {
1282
0
                    rSet.Put(SfxBoolItem(nSlotId, false));
1283
0
                }
1284
0
                break;
1285
0
        }
1286
0
        nWhich = aIter.NextWhich();
1287
0
    }
1288
0
}
1289
1290
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */