Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/uiview/formatclipboard.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 <memory>
21
#include <utility>
22
23
#include <formatclipboard.hxx>
24
25
#include <cmdid.h>
26
#include <cellatr.hxx>
27
#include <charfmt.hxx>
28
#include <frmfmt.hxx>
29
#include <docstyle.hxx>
30
#include <fchrfmt.hxx>
31
#include <svx/svdview.hxx>
32
#include <editeng/brushitem.hxx>
33
#include <editeng/shaditem.hxx>
34
#include <editeng/boxitem.hxx>
35
#include <editeng/formatbreakitem.hxx>
36
#include <fmtlsplt.hxx>
37
#include <editeng/keepitem.hxx>
38
#include <editeng/frmdiritem.hxx>
39
#include <fmtpdsc.hxx>
40
#include <fmtrowsplt.hxx>
41
#include <frmatr.hxx>
42
43
namespace
44
{
45
46
std::unique_ptr<SfxItemSet> lcl_CreateEmptyItemSet( SelectionType nSelectionType, SfxItemPool& rPool, bool bNoParagraphFormats = false )
47
0
{
48
0
    std::unique_ptr<SfxItemSet> pItemSet;
49
0
    if( nSelectionType & (SelectionType::Frame | SelectionType::Ole | SelectionType::Graphic) )
50
0
    {
51
0
        pItemSet = std::make_unique<SfxItemSetFixed<
52
0
                RES_FRMATR_BEGIN, RES_FILL_ORDER,
53
                // no RES_FRM_SIZE
54
0
                RES_PAPER_BIN, RES_SURROUND,
55
                // no RES_VERT_ORIENT
56
                // no RES_HORI_ORIENT
57
                // no RES_ANCHOR
58
0
                RES_BACKGROUND, RES_SHADOW,
59
                // no RES_FRMMACRO
60
0
                RES_COL, RES_KEEP,
61
                // no RES_URL
62
0
                RES_EDIT_IN_READONLY, RES_LAYOUT_SPLIT,
63
                // no RES_CHAIN
64
0
                RES_TEXTGRID, RES_FRMATR_END - 1>>(rPool);
65
0
    }
66
0
    else if( nSelectionType & SelectionType::DrawObject )
67
0
    {
68
        //is handled different
69
0
    }
70
0
    else if( nSelectionType & SelectionType::Text )
71
0
    {
72
0
        if( bNoParagraphFormats )
73
0
            pItemSet = std::make_unique<SfxItemSetFixed
74
0
                    <RES_CHRATR_BEGIN, RES_CHRATR_END - 1>>(rPool);
75
0
        else
76
0
            pItemSet = std::make_unique<SfxItemSetFixed<
77
0
                    RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
78
0
                    RES_PARATR_BEGIN, RES_FILL_ORDER,
79
                    // no RES_FRM_SIZE
80
0
                    RES_PAPER_BIN, RES_SURROUND,
81
                    // no RES_VERT_ORIENT
82
                    // no RES_HORI_ORIENT
83
                    // no RES_ANCHOR
84
0
                    RES_BACKGROUND, RES_SHADOW,
85
                    // no RES_FRMMACRO
86
0
                    RES_COL, RES_KEEP,
87
                    // no RES_URL
88
0
                    RES_EDIT_IN_READONLY, RES_LAYOUT_SPLIT,
89
                    // no RES_CHAIN
90
0
                    RES_TEXTGRID, RES_FRMATR_END - 1>>(rPool);
91
0
    }
92
0
    return pItemSet;
93
0
}
94
95
void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh, bool bAllCellAttrs )
96
0
{
97
0
    if (bAllCellAttrs)
98
0
    {
99
0
        std::unique_ptr<SvxBrushItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
100
0
        rSh.GetBoxBackground(aBrush);
101
0
        rSet.Put( *aBrush );
102
0
        if(rSh.GetRowBackground(aBrush))
103
0
        {
104
0
            aBrush->SetWhich(SID_ATTR_BRUSH_ROW);
105
0
            rSet.Put( *aBrush );
106
0
        }
107
0
        else
108
0
            rSet.InvalidateItem(SID_ATTR_BRUSH_ROW);
109
0
        rSh.GetTabBackground(aBrush);
110
0
        aBrush->SetWhich(SID_ATTR_BRUSH_TABLE);
111
0
        rSet.Put( *aBrush );
112
113
0
        SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
114
0
        rSet.Put(aBoxInfo);
115
0
        rSh.GetTabBorders( rSet );
116
117
0
        std::unique_ptr<SvxFrameDirectionItem> aBoxDirection(std::make_unique<SvxFrameDirectionItem>(SvxFrameDirection::Environment, RES_FRAMEDIR));
118
0
        if(rSh.GetBoxDirection( aBoxDirection ))
119
0
        {
120
0
            aBoxDirection->SetWhich(FN_TABLE_BOX_TEXTORIENTATION);
121
0
            rSet.Put(std::move(aBoxDirection));
122
0
        }
123
124
0
        rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, rSh.GetBoxAlign()));
125
126
0
        rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, rSh.GetRowsToRepeat() ) );
127
128
0
        SwFrameFormat *pFrameFormat = rSh.GetTableFormat();
129
0
        if(pFrameFormat)
130
0
        {
131
0
            rSet.Put( pFrameFormat->GetShadow() );
132
0
            rSet.Put( pFrameFormat->GetBreak() );
133
0
            rSet.Put( pFrameFormat->GetPageDesc() );
134
0
            rSet.Put( pFrameFormat->GetLayoutSplit() );
135
0
            rSet.Put( pFrameFormat->GetKeep() );
136
0
            rSet.Put( pFrameFormat->GetFrameDir() );
137
0
        }
138
139
0
        std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
140
0
        if(pSplit)
141
0
            rSet.Put(std::move(pSplit));
142
0
    }
143
144
0
    SfxItemSetFixed<RES_BOXATR_FORMAT, RES_BOXATR_FORMAT, RES_BOXATR_VALUE, RES_BOXATR_VALUE>
145
0
        aBoxSet(*rSet.GetPool());
146
0
    rSh.GetTableBoxFormulaAttrs(aBoxSet);
147
0
    rSet.Put(aBoxSet);
148
0
}
149
150
void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
151
0
{
152
0
    bool bBorder = ( SfxItemState::SET == rSet.GetItemState( RES_BOX ) ||
153
0
            SfxItemState::SET == rSet.GetItemState( SID_ATTR_BORDER_INNER ) );
154
0
    const SvxBrushItem* pBackgroundItem = rSet.GetItemIfSet( RES_BACKGROUND, false );
155
0
    const SvxBrushItem* pRowItem = rSet.GetItemIfSet( SID_ATTR_BRUSH_ROW, false );
156
0
    const SvxBrushItem* pTableItem = rSet.GetItemIfSet( SID_ATTR_BRUSH_TABLE, false );
157
0
    bool bBackground = pBackgroundItem || pRowItem || pTableItem;
158
159
0
    if(bBackground)
160
0
    {
161
0
        if(pBackgroundItem)
162
0
            rSh.SetBoxBackground( *pBackgroundItem );
163
0
        if(pRowItem)
164
0
        {
165
0
            std::unique_ptr<SvxBrushItem> aBrush(pRowItem->Clone());
166
0
            aBrush->SetWhich(RES_BACKGROUND);
167
0
            rSh.SetRowBackground(*aBrush);
168
0
        }
169
0
        if(pTableItem)
170
0
        {
171
0
            std::unique_ptr<SvxBrushItem> aBrush(pTableItem->Clone());
172
0
            aBrush->SetWhich(RES_BACKGROUND);
173
0
            rSh.SetTabBackground(*aBrush);
174
0
        }
175
0
    }
176
0
    if(bBorder)
177
0
        rSh.SetTabBorders( rSet );
178
179
0
    if( const SfxUInt16Item* pHeadlineItem = rSet.GetItemIfSet( FN_PARAM_TABLE_HEADLINE, false) )
180
0
        rSh.SetRowsToRepeat( pHeadlineItem->GetValue() );
181
182
0
    SwFrameFormat* pFrameFormat = rSh.GetTableFormat();
183
0
    if(pFrameFormat)
184
0
    {
185
        //RES_SHADOW
186
0
        const SfxPoolItem* pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhichIDFromSlotID(RES_SHADOW), false);
187
0
        if(pItem)
188
0
            pFrameFormat->SetFormatAttr( *pItem );
189
190
        //RES_BREAK
191
0
        pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhichIDFromSlotID(RES_BREAK), false);
192
0
        if(pItem)
193
0
            pFrameFormat->SetFormatAttr( *pItem );
194
195
        //RES_PAGEDESC
196
0
        pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhichIDFromSlotID(RES_PAGEDESC), false);
197
0
        if(pItem)
198
0
            pFrameFormat->SetFormatAttr( *pItem );
199
200
        //RES_LAYOUT_SPLIT
201
0
        pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhichIDFromSlotID(RES_LAYOUT_SPLIT), false);
202
0
        if(pItem)
203
0
            pFrameFormat->SetFormatAttr( *pItem );
204
205
        //RES_KEEP
206
0
        pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhichIDFromSlotID(RES_KEEP), false);
207
0
        if(pItem)
208
0
            pFrameFormat->SetFormatAttr( *pItem );
209
210
        //RES_FRAMEDIR
211
0
        pItem = rSet.GetItemIfSet(rSet.GetPool()->GetWhichIDFromSlotID(RES_FRAMEDIR), false);
212
0
        if(pItem)
213
0
            pFrameFormat->SetFormatAttr( *pItem );
214
0
    }
215
216
0
    if( const SvxFrameDirectionItem* pTextOriItem = rSet.GetItemIfSet( FN_TABLE_BOX_TEXTORIENTATION, false ) )
217
0
    {
218
0
        SvxFrameDirectionItem aDirection( SvxFrameDirection::Environment, RES_FRAMEDIR );
219
0
        aDirection.SetValue(pTextOriItem->GetValue());
220
0
        rSh.SetBoxDirection(aDirection);
221
0
    }
222
223
0
    if( const SfxUInt16Item* pVertAlignItem = rSet.GetItemIfSet( FN_TABLE_SET_VERT_ALIGN, false ))
224
0
        rSh.SetBoxAlign(pVertAlignItem->GetValue());
225
226
0
    if( const SwFormatRowSplit* pSplitItem = rSet.GetItemIfSet( RES_ROW_SPLIT, false ) )
227
0
        rSh.SetRowSplit(*pSplitItem);
228
229
0
    if (rSet.GetItemIfSet( RES_BOXATR_FORMAT, false ))
230
0
        rSh.SetTableBoxFormulaAttrs(rSet);
231
232
0
}
233
}//end anonymous namespace
234
235
SwFormatClipboard::SwFormatClipboard()
236
3.67k
        : m_nSelectionType(SelectionType::NONE)
237
3.67k
        , m_bPersistentCopy(false)
238
3.67k
{
239
3.67k
}
240
241
bool SwFormatClipboard::HasContent() const
242
0
{
243
0
    return m_pItemSet_TextAttr!=nullptr
244
0
        || m_pItemSet_ParAttr!=nullptr
245
0
        || m_pTableItemSet != nullptr
246
0
        || !m_aCharStyle.isEmpty()
247
0
        || !m_aParaStyle.isEmpty()
248
0
        ;
249
0
}
250
bool SwFormatClipboard::HasContentForThisType( SelectionType nSelectionType ) const
251
0
{
252
0
    if( !HasContent() )
253
0
        return false;
254
255
0
    if( m_nSelectionType == nSelectionType )
256
0
        return true;
257
258
0
    if(   ( nSelectionType   & (SelectionType::Frame | SelectionType::Ole | SelectionType::Graphic) )
259
0
        &&
260
0
          ( m_nSelectionType & (SelectionType::Frame | SelectionType::Ole | SelectionType::Graphic) )
261
0
        )
262
0
        return true;
263
264
0
    if( nSelectionType & SelectionType::Text && m_nSelectionType & SelectionType::Text )
265
0
        return true;
266
267
0
    return false;
268
0
}
269
270
bool SwFormatClipboard::CanCopyThisType( SelectionType nSelectionType )
271
0
{
272
0
    return bool(nSelectionType
273
0
                & (SelectionType::Frame | SelectionType::Ole | SelectionType::Graphic
274
0
                   | SelectionType::Text | SelectionType::DrawObject | SelectionType::Table | SelectionType::TableCell ));
275
0
}
276
277
void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bPersistentCopy )
278
0
{
279
    // first clear the previously stored attributes
280
0
    Erase();
281
0
    m_bPersistentCopy = bPersistentCopy;
282
283
0
    SelectionType nSelectionType = rWrtShell.GetSelectionType();
284
0
    auto pItemSet_TextAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, true );
285
0
    auto pItemSet_ParAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool );
286
287
0
    rWrtShell.StartAction();
288
0
    rWrtShell.Push();
289
290
    // modify the "Point and Mark" of the cursor
291
    // in order to select only the last character of the
292
    // selection(s) and then to get the attributes of this single character
293
0
    if( nSelectionType == SelectionType::Text )
294
0
    {
295
        // get the current PaM, the cursor
296
        // if there several selection it currently point
297
        // on the last (sort by there creation time) selection
298
0
        SwPaM* pCursor = rWrtShell.GetCursor();
299
300
0
        bool bHasSelection = pCursor->HasMark();
301
0
        bool bForwardSelection = false;
302
303
0
        if(!bHasSelection && pCursor->IsMultiSelection())
304
0
        {
305
            // if cursor has multiple selections
306
307
            // clear all the selections except the last
308
0
            rWrtShell.KillPams();
309
310
            // reset the cursor to the remaining selection
311
0
            pCursor = rWrtShell.GetCursor();
312
0
            bHasSelection = true;
313
0
        }
314
315
0
        bool dontMove = false;
316
0
        if (bHasSelection)
317
0
        {
318
0
            bForwardSelection = (*pCursor->GetPoint()) > (*pCursor->GetMark());
319
320
            // clear the selection leaving just the cursor
321
0
            pCursor->DeleteMark();
322
0
            pCursor->SetMark();
323
0
        }
324
0
        else
325
0
        {
326
0
            bool rightToLeft = rWrtShell.IsInRightToLeftText();
327
            // if there were no selection (only a cursor) and the cursor was at
328
            // the end of the paragraph then don't move
329
0
            if ( rWrtShell.IsEndPara() && !rightToLeft )
330
0
                dontMove = true;
331
332
            // revert left and right
333
0
            if ( rightToLeft )
334
0
            {
335
0
                if (pCursor->GetPoint()->GetContentIndex() == 0)
336
0
                    dontMove = true;
337
0
                else
338
0
                    bForwardSelection = !bForwardSelection;
339
0
            }
340
0
        }
341
342
        // move the cursor in order to select one character
343
0
        if (!dontMove)
344
0
            pCursor->Move( bForwardSelection ? fnMoveBackward : fnMoveForward );
345
0
    }
346
347
0
    if(pItemSet_TextAttr)
348
0
    {
349
0
        if( nSelectionType & (SelectionType::Frame | SelectionType::Ole | SelectionType::Graphic) )
350
0
            rWrtShell.GetFlyFrameAttr(*pItemSet_TextAttr);
351
0
        else
352
0
        {
353
            // get the text attributes from named and automatic formatting
354
0
            rWrtShell.GetCurAttr(*pItemSet_TextAttr);
355
356
0
            if( nSelectionType & SelectionType::Text )
357
0
            {
358
                // get the paragraph attributes (could be character properties)
359
                // from named and automatic formatting
360
0
                rWrtShell.GetCurParAttr(*pItemSet_ParAttr);
361
0
            }
362
0
        }
363
0
    }
364
0
    else if ( nSelectionType & SelectionType::DrawObject )
365
0
    {
366
0
        SdrView* pDrawView = rWrtShell.GetDrawView();
367
0
        if(pDrawView)
368
0
        {
369
0
            if( pDrawView->GetMarkedObjectList().GetMarkCount() != 0 )
370
0
            {
371
0
                pItemSet_TextAttr = std::make_unique<SfxItemSet>( pDrawView->GetAttrFromMarked(true/*bOnlyHardAttr*/) );
372
                //remove attributes defining the type/data of custom shapes
373
0
                pItemSet_TextAttr->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE);
374
0
                pItemSet_TextAttr->ClearItem(SDRATTR_CUSTOMSHAPE_DATA);
375
0
                pItemSet_TextAttr->ClearItem(SDRATTR_CUSTOMSHAPE_GEOMETRY);
376
0
            }
377
0
        }
378
0
    }
379
380
0
    if(nSelectionType & (SelectionType::Table | SelectionType::TableCell))
381
0
    {
382
0
        if (nSelectionType & SelectionType::TableCell)
383
0
        {
384
            //only copy all table attributes if really cells are selected (not only text in tables)
385
0
            m_pTableItemSet = std::make_unique<SfxItemSetFixed<
386
0
                RES_PAGEDESC, RES_BREAK,
387
0
                RES_BACKGROUND, RES_SHADOW, // RES_BOX is inbetween
388
0
                RES_KEEP, RES_KEEP,
389
0
                RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT,
390
0
                RES_FRAMEDIR, RES_FRAMEDIR,
391
0
                RES_ROW_SPLIT, RES_ROW_SPLIT,
392
0
                RES_BOXATR_FORMAT, RES_BOXATR_FORMAT,
393
0
                SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW,
394
                    // SID_ATTR_BORDER_OUTER is inbetween
395
0
                SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE,
396
0
                FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
397
0
                FN_TABLE_BOX_TEXTORIENTATION, FN_TABLE_BOX_TEXTORIENTATION,
398
0
                FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE>>(rPool);
399
0
        }
400
0
        else
401
0
        {
402
            //selection in table should copy number format
403
0
            m_pTableItemSet = std::make_unique<SfxItemSetFixed<
404
0
                RES_BOXATR_FORMAT, RES_BOXATR_FORMAT>>(rPool);
405
0
        }
406
407
0
        lcl_getTableAttributes( *m_pTableItemSet, rWrtShell, nSelectionType & SelectionType::TableCell ? true : false);
408
0
    }
409
410
0
    m_nSelectionType = nSelectionType;
411
0
    m_pItemSet_TextAttr = std::move(pItemSet_TextAttr);
412
0
    m_pItemSet_ParAttr = std::move(pItemSet_ParAttr);
413
414
0
    if( nSelectionType & SelectionType::Text )
415
0
    {
416
        // if text is selected save the named character format
417
0
        SwFormat* pFormat = rWrtShell.GetCurCharFormat();
418
0
        if( pFormat )
419
0
            m_aCharStyle = pFormat->GetName();
420
421
        // and the named paragraph format
422
0
        pFormat = rWrtShell.GetCurTextFormatColl();
423
0
        if( pFormat )
424
0
            m_aParaStyle = pFormat->GetName();
425
0
    }
426
427
0
    rWrtShell.Pop(SwCursorShell::PopMode::DeleteCurrent);
428
0
    rWrtShell.EndAction();
429
0
}
430
431
typedef std::vector< std::unique_ptr< SfxPoolItem > > ItemVector;
432
// collect all PoolItems from the applied styles
433
static void lcl_AppendSetItems( ItemVector& rItemVector, const SfxItemSet& rStyleAttrSet )
434
0
{
435
0
    const WhichRangesContainer& pRanges = rStyleAttrSet.GetRanges();
436
0
    for(const auto & rPair : pRanges)
437
0
    {
438
0
        for ( sal_uInt16 nWhich = rPair.first; nWhich <= rPair.second; ++nWhich )
439
0
        {
440
0
            const SfxPoolItem* pItem;
441
0
            if( SfxItemState::SET == rStyleAttrSet.GetItemState( nWhich, false, &pItem ) )
442
0
            {
443
0
                rItemVector.emplace_back( pItem->Clone() );
444
0
            }
445
0
        }
446
0
    }
447
0
}
448
// remove all items that are inherited from the styles
449
static void lcl_RemoveEqualItems( SfxItemSet& rTemplateItemSet, const ItemVector& rItemVector )
450
0
{
451
0
    for( const auto& rItem : rItemVector )
452
0
    {
453
0
        const SfxPoolItem* pItem;
454
0
        if( SfxItemState::SET == rTemplateItemSet.GetItemState( rItem->Which(), true, &pItem ) &&
455
0
            *pItem == *rItem )
456
0
        {
457
0
            rTemplateItemSet.ClearItem( rItem->Which() );
458
0
        }
459
0
    }
460
0
}
461
462
void SwFormatClipboard::Paste( SwWrtShell& rWrtShell, SfxStyleSheetBasePool* pPool
463
                              , bool bNoCharacterFormats, bool bNoParagraphFormats )
464
0
{
465
0
    SelectionType nSelectionType = rWrtShell.GetSelectionType();
466
0
    if( !HasContentForThisType(nSelectionType) )
467
0
    {
468
0
        if(!m_bPersistentCopy)
469
0
            Erase();
470
0
        return;
471
0
    }
472
473
0
    rWrtShell.StartAction();
474
0
    rWrtShell.StartUndo(SwUndoId::INSATTR);
475
476
0
    ItemVector aItemVector;
477
478
0
    if (m_pItemSet_TextAttr && !( nSelectionType & SelectionType::DrawObject))
479
0
    {
480
        // reset all direct formatting before applying anything
481
0
        o3tl::sorted_vector<sal_uInt16> aAttrs;
482
0
        for (sal_uInt16 nWhich = RES_CHRATR_BEGIN; nWhich < RES_CHRATR_END; nWhich++)
483
0
            aAttrs.insert(nWhich);
484
0
        rWrtShell.ResetAttr({ aAttrs });
485
0
    }
486
487
0
    if( nSelectionType & SelectionType::Text )
488
0
    {
489
        // apply the named text and paragraph formatting
490
0
        if( pPool )
491
0
        {
492
            // if there is a named text format recorded and the user wants to apply it
493
0
            if(!m_aCharStyle.isEmpty() && !bNoCharacterFormats )
494
0
            {
495
                // look for the named text format in the pool
496
0
                SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aCharStyle.toString(), SfxStyleFamily::Char));
497
498
                // if the style is found
499
0
                if( pStyle )
500
0
                {
501
0
                    SwFormatCharFormat aFormat(pStyle->GetCharFormat());
502
                    // store the attributes from this style in aItemVector in order
503
                    // not to apply them as automatic formatting attributes later in the code
504
0
                    lcl_AppendSetItems( aItemVector, aFormat.GetCharFormat()->GetAttrSet());
505
506
                    // apply the named format
507
0
                    rWrtShell.SetAttrItem( aFormat );
508
0
                }
509
0
            }
510
511
0
            if (!bNoParagraphFormats)
512
0
            {
513
0
                const SwNumRule* pNumRule
514
0
                    = rWrtShell.GetNumRuleAtCurrCursorPos();
515
0
                if (pNumRule && !pNumRule->IsOutlineRule())
516
0
                {
517
0
                    rWrtShell.NumOrBulletOff();
518
0
                }
519
                // if there is a named paragraph format recorded and the user wants to apply it
520
0
                if(!m_aParaStyle.isEmpty())
521
0
                {
522
                    // look for the named paragraph format in the pool
523
0
                    SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aParaStyle.toString(), SfxStyleFamily::Para));
524
0
                    if( pStyle )
525
0
                    {
526
                        // store the attributes from this style in aItemVector in order
527
                        // not to apply them as automatic formatting attributes later in the code
528
0
                        lcl_AppendSetItems( aItemVector, pStyle->GetCollection()->GetAttrSet());
529
530
                        // apply the named format
531
0
                        rWrtShell.SetTextFormatColl( pStyle->GetCollection() );
532
0
                    }
533
0
                }
534
0
            }
535
0
        }
536
537
        // apply the paragraph automatic attributes
538
0
        if ( m_pItemSet_ParAttr && m_pItemSet_ParAttr->Count() != 0 && !bNoParagraphFormats )
539
0
        {
540
            // temporary SfxItemSet
541
0
            std::unique_ptr<SfxItemSet> pTemplateItemSet(lcl_CreateEmptyItemSet(
542
0
                    nSelectionType, *m_pItemSet_ParAttr->GetPool()));
543
            // no need to verify the existence of pTemplateItemSet as we
544
            // know that here the selection type is SEL_TXT
545
546
0
            pTemplateItemSet->Put( *m_pItemSet_ParAttr );
547
548
            // remove attribute that were applied by named text and paragraph formatting
549
0
            lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
550
551
            // apply the paragraph automatic attributes to all the nodes in the selection
552
0
            rWrtShell.SetAttrSet(*pTemplateItemSet);
553
554
            // store the attributes in aItemVector in order not to apply them as
555
            // text automatic formatting attributes later in the code
556
0
            lcl_AppendSetItems( aItemVector, *pTemplateItemSet);
557
0
        }
558
0
    }
559
560
0
    if(m_pItemSet_TextAttr)
561
0
    {
562
0
        if( nSelectionType & SelectionType::DrawObject )
563
0
        {
564
0
            SdrView* pDrawView = rWrtShell.GetDrawView();
565
0
            if(pDrawView)
566
0
            {
567
0
                pDrawView->SetAttrToMarked(*m_pItemSet_TextAttr, true/*bReplaceAll*/);
568
0
            }
569
0
        }
570
0
        else
571
0
        {
572
            // temporary SfxItemSet
573
0
            std::unique_ptr<SfxItemSet> pTemplateItemSet(lcl_CreateEmptyItemSet(
574
0
                    nSelectionType, *m_pItemSet_TextAttr->GetPool(), true ));
575
576
0
            if(pTemplateItemSet)
577
0
            {
578
                // copy the stored automatic text attributes in a temporary SfxItemSet
579
0
                pTemplateItemSet->Put( *m_pItemSet_TextAttr );
580
581
                // only attributes that were not apply by named style attributes and automatic
582
                // paragraph attributes should be applied
583
0
                lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
584
585
                // apply the character automatic attributes
586
0
                if( nSelectionType & (SelectionType::Frame | SelectionType::Ole | SelectionType::Graphic) )
587
0
                    rWrtShell.SetFlyFrameAttr(*pTemplateItemSet);
588
0
                else if ( !bNoCharacterFormats )
589
0
                {
590
0
                    rWrtShell.SetAttrSet(*pTemplateItemSet);
591
0
                }
592
0
            }
593
0
        }
594
0
    }
595
596
0
    if( m_pTableItemSet && nSelectionType & (SelectionType::Table | SelectionType::TableCell) )
597
0
        lcl_setTableAttributes( *m_pTableItemSet, rWrtShell );
598
599
0
    rWrtShell.EndUndo(SwUndoId::INSATTR);
600
0
    rWrtShell.EndAction();
601
602
0
    if(!m_bPersistentCopy)
603
0
        Erase();
604
0
}
605
606
void SwFormatClipboard::Erase()
607
0
{
608
0
    m_nSelectionType = SelectionType::NONE;
609
610
0
    m_pItemSet_TextAttr.reset();
611
612
0
    m_pItemSet_ParAttr.reset();
613
614
0
    m_pTableItemSet.reset();
615
616
0
    if( !m_aCharStyle.isEmpty() )
617
0
        m_aCharStyle = UIName();
618
0
    if( !m_aParaStyle.isEmpty() )
619
0
        m_aParaStyle = UIName();
620
621
0
    m_bPersistentCopy = false;
622
0
}
623
624
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */