Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "formatclipboard.hxx"
31 : :
32 : :
33 : : #include <hintids.hxx>
34 : : #include <svx/svxids.hrc>
35 : : #include <cmdid.h>
36 : : #include <format.hxx>
37 : : #include <charfmt.hxx>
38 : : #include <fmtcol.hxx>
39 : : #include <frmfmt.hxx>
40 : : #include <docstyle.hxx>
41 : : #include <fchrfmt.hxx>
42 : : #include <pam.hxx>
43 : : // header for class SdrView
44 : : #include <svx/svdview.hxx>
45 : : //SvxBrushItem
46 : : #include <editeng/brshitem.hxx>
47 : : #include <editeng/shaditem.hxx>
48 : : #include <frmatr.hxx>
49 : : // header for class SvxBoxInfoItem
50 : : #include <editeng/boxitem.hxx>
51 : : // header for class SvxFmtBreakItem
52 : : #include <editeng/brkitem.hxx>
53 : : // header for class SwFmtLayoutSplit
54 : : #include <fmtlsplt.hxx>
55 : : // header for class SvxFmtKeepItem
56 : : #include <editeng/keepitem.hxx>
57 : : // header for class SvxFrameDirectionItem
58 : : #include <editeng/frmdiritem.hxx>
59 : : #include <paratr.hxx>
60 : : #include <fmtpdsc.hxx>
61 : : #include <fmtrowsplt.hxx>
62 : : #include <swundo.hxx> // fuer die UndoIds
63 : : #include <boost/shared_ptr.hpp>
64 : :
65 : :
66 : :
67 : : namespace
68 : : {
69 : : #define FORMAT_PAINTBRUSH_FRAME_IDS \
70 : : RES_FRMATR_BEGIN, RES_FILL_ORDER, \
71 : : /* no RES_FRM_SIZE */ \
72 : : RES_PAPER_BIN, RES_SURROUND, \
73 : : /* no RES_VERT_ORIENT */ \
74 : : /* no RES_HORI_ORIENT */ \
75 : : /* no RES_ANCHOR */ \
76 : : RES_BACKGROUND, RES_SHADOW, \
77 : : /* no RES_FRMMACRO */ \
78 : : RES_COL, RES_KEEP, \
79 : : /* no RES_URL */ \
80 : : RES_EDIT_IN_READONLY, RES_LAYOUT_SPLIT, \
81 : : /* no RES_CHAIN */ \
82 : : RES_TEXTGRID, RES_FRMATR_END-1,
83 : :
84 : : #define FORMAT_PAINTBRUSH_PARAGRAPH_IDS \
85 : : RES_PARATR_BEGIN, RES_PARATR_END -1, \
86 : : RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END -1, \
87 : : FORMAT_PAINTBRUSH_FRAME_IDS
88 : :
89 : 0 : SfxItemSet* lcl_CreateEmptyItemSet( int nSelectionType, SfxItemPool& rPool, bool bNoParagraphFormats = false )
90 : : {
91 : 0 : SfxItemSet* pItemSet = 0;
92 [ # # ]: 0 : if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
93 : : {
94 : : pItemSet = new SfxItemSet(rPool,
95 : : FORMAT_PAINTBRUSH_FRAME_IDS
96 [ # # ]: 0 : 0);
97 : : }
98 [ # # ]: 0 : else if( nSelectionType & nsSelectionType::SEL_DRW )
99 : : {
100 : : //is handled different
101 : : }
102 [ # # ]: 0 : else if( nSelectionType & nsSelectionType::SEL_TXT )
103 : : {
104 [ # # ]: 0 : if( bNoParagraphFormats )
105 : : pItemSet = new SfxItemSet(rPool,
106 : : RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
107 [ # # ]: 0 : 0);
108 : : else
109 : : pItemSet = new SfxItemSet(rPool,
110 : : RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
111 : : FORMAT_PAINTBRUSH_PARAGRAPH_IDS
112 [ # # ]: 0 : 0);
113 : : }
114 : 0 : return pItemSet;
115 : : }
116 : :
117 : 0 : void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
118 : : {
119 [ # # ]: 0 : SvxBrushItem aBrush( RES_BACKGROUND );
120 [ # # ]: 0 : rSh.GetBoxBackground(aBrush);
121 [ # # ]: 0 : rSet.Put( aBrush );
122 [ # # ][ # # ]: 0 : if(rSh.GetRowBackground(aBrush))
123 [ # # ]: 0 : rSet.Put( aBrush, SID_ATTR_BRUSH_ROW );
124 : : else
125 [ # # ]: 0 : rSet.InvalidateItem(SID_ATTR_BRUSH_ROW);
126 [ # # ]: 0 : rSh.GetTabBackground(aBrush);
127 [ # # ]: 0 : rSet.Put( aBrush, SID_ATTR_BRUSH_TABLE );
128 : :
129 [ # # ]: 0 : SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
130 [ # # ]: 0 : rSet.Put(aBoxInfo);
131 [ # # ]: 0 : rSh.GetTabBorders( rSet );
132 : :
133 [ # # ]: 0 : SvxFrameDirectionItem aBoxDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
134 [ # # ][ # # ]: 0 : if(rSh.GetBoxDirection( aBoxDirection ))
135 [ # # ]: 0 : rSet.Put(aBoxDirection, FN_TABLE_BOX_TEXTORIENTATION);
136 : :
137 [ # # ][ # # ]: 0 : rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, rSh.GetBoxAlign()));
[ # # ][ # # ]
138 : :
139 [ # # ][ # # ]: 0 : rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, rSh.GetRowsToRepeat() ) );
[ # # ][ # # ]
140 : :
141 [ # # ]: 0 : SwFrmFmt *pFrmFmt = rSh.GetTableFmt();
142 [ # # ]: 0 : if(pFrmFmt)
143 : : {
144 [ # # ][ # # ]: 0 : rSet.Put( pFrmFmt->GetShadow() );
145 [ # # ][ # # ]: 0 : rSet.Put( pFrmFmt->GetBreak() );
146 [ # # ][ # # ]: 0 : rSet.Put( pFrmFmt->GetPageDesc() );
147 [ # # ][ # # ]: 0 : rSet.Put( pFrmFmt->GetLayoutSplit() );
148 [ # # ][ # # ]: 0 : rSet.Put( pFrmFmt->GetKeep() );
149 [ # # ][ # # ]: 0 : rSet.Put( pFrmFmt->GetFrmDir() );
150 : : }
151 : :
152 : 0 : SwFmtRowSplit* pSplit = 0;
153 [ # # ]: 0 : rSh.GetRowSplit(pSplit);
154 [ # # ]: 0 : if(pSplit)
155 [ # # ][ # # ]: 0 : rSet.Put(*pSplit);
[ # # ][ # # ]
156 : 0 : }
157 : :
158 : 0 : void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
159 : : {
160 : 0 : const SfxPoolItem* pItem = 0;
161 [ # # ]: 0 : sal_Bool bBorder = ( SFX_ITEM_SET == rSet.GetItemState( RES_BOX ) ||
162 [ # # ][ # # ]: 0 : SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER ) );
[ # # ]
163 : 0 : pItem = 0;
164 [ # # ]: 0 : sal_Bool bBackground = SFX_ITEM_SET == rSet.GetItemState( RES_BACKGROUND, sal_False, &pItem );
165 : 0 : const SfxPoolItem* pRowItem = 0, *pTableItem = 0;
166 [ # # ]: 0 : bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_ROW, sal_False, &pRowItem );
167 [ # # ]: 0 : bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_TABLE, sal_False, &pTableItem );
168 : :
169 [ # # ]: 0 : if(bBackground)
170 : : {
171 [ # # ]: 0 : if(pItem)
172 [ # # ]: 0 : rSh.SetBoxBackground( *(const SvxBrushItem*)pItem );
173 [ # # ]: 0 : if(pRowItem)
174 : : {
175 [ # # ]: 0 : SvxBrushItem aBrush(*(const SvxBrushItem*)pRowItem);
176 : 0 : aBrush.SetWhich(RES_BACKGROUND);
177 [ # # ][ # # ]: 0 : rSh.SetRowBackground(aBrush);
178 : : }
179 [ # # ]: 0 : if(pTableItem)
180 : : {
181 [ # # ]: 0 : SvxBrushItem aBrush(*(const SvxBrushItem*)pTableItem);
182 : 0 : aBrush.SetWhich(RES_BACKGROUND);
183 [ # # ][ # # ]: 0 : rSh.SetTabBackground( aBrush );
184 : : }
185 : : }
186 [ # # ]: 0 : if(bBorder)
187 [ # # ]: 0 : rSh.SetTabBorders( rSet );
188 : :
189 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, sal_False, &pItem) )
190 [ # # ]: 0 : rSh.SetRowsToRepeat( ((SfxUInt16Item*)pItem)->GetValue() );
191 : :
192 [ # # ]: 0 : SwFrmFmt* pFrmFmt = rSh.GetTableFmt();
193 [ # # ]: 0 : if(pFrmFmt)
194 : : {
195 : : //RES_SHADOW
196 : 0 : pItem=0;
197 [ # # ][ # # ]: 0 : rSet.GetItemState(rSet.GetPool()->GetWhich(RES_SHADOW), sal_False, &pItem);
198 [ # # ]: 0 : if(pItem)
199 [ # # ]: 0 : pFrmFmt->SetFmtAttr( *pItem );
200 : :
201 : : //RES_BREAK
202 : 0 : pItem=0;
203 [ # # ][ # # ]: 0 : rSet.GetItemState(rSet.GetPool()->GetWhich(RES_BREAK), sal_False, &pItem);
204 [ # # ]: 0 : if(pItem)
205 [ # # ]: 0 : pFrmFmt->SetFmtAttr( *pItem );
206 : :
207 : : //RES_PAGEDESC
208 : 0 : pItem=0;
209 [ # # ][ # # ]: 0 : rSet.GetItemState(rSet.GetPool()->GetWhich(RES_PAGEDESC), sal_False, &pItem);
210 [ # # ]: 0 : if(pItem)
211 [ # # ]: 0 : pFrmFmt->SetFmtAttr( *pItem );
212 : :
213 : : //RES_LAYOUT_SPLIT
214 : 0 : pItem=0;
215 [ # # ][ # # ]: 0 : rSet.GetItemState(rSet.GetPool()->GetWhich(RES_LAYOUT_SPLIT), sal_False, &pItem);
216 [ # # ]: 0 : if(pItem)
217 [ # # ]: 0 : pFrmFmt->SetFmtAttr( *pItem );
218 : :
219 : : //RES_KEEP
220 : 0 : pItem=0;
221 [ # # ][ # # ]: 0 : rSet.GetItemState(rSet.GetPool()->GetWhich(RES_KEEP), sal_False, &pItem);
222 [ # # ]: 0 : if(pItem)
223 [ # # ]: 0 : pFrmFmt->SetFmtAttr( *pItem );
224 : :
225 : : //RES_FRAMEDIR
226 : 0 : pItem=0;
227 [ # # ][ # # ]: 0 : rSet.GetItemState(rSet.GetPool()->GetWhich(RES_FRAMEDIR), sal_False, &pItem);
228 [ # # ]: 0 : if(pItem)
229 [ # # ]: 0 : pFrmFmt->SetFmtAttr( *pItem );
230 : : }
231 : :
232 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_BOX_TEXTORIENTATION, sal_False, &pItem) )
233 : : {
234 [ # # ]: 0 : SvxFrameDirectionItem aDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
235 : 0 : aDirection.SetValue(static_cast< const SvxFrameDirectionItem* >(pItem)->GetValue());
236 [ # # ][ # # ]: 0 : rSh.SetBoxDirection(aDirection);
237 : : }
238 : :
239 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_SET_VERT_ALIGN, sal_False, &pItem))
240 [ # # ]: 0 : rSh.SetBoxAlign(((SfxUInt16Item*)(pItem))->GetValue());
241 : :
242 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, sal_False, &pItem) )
243 [ # # ]: 0 : rSh.SetRowSplit(*static_cast<const SwFmtRowSplit*>(pItem));
244 : 0 : }
245 : : }//end anonymous namespace
246 : :
247 : 1318 : SwFormatClipboard::SwFormatClipboard()
248 : : : m_nSelectionType(0)
249 : : , m_pItemSet_TxtAttr(0)
250 : : , m_pItemSet_ParAttr(0)
251 : : , m_pTableItemSet(0)
252 [ + - ]: 1318 : , m_bPersistentCopy(false)
253 : : {
254 : 1318 : }
255 [ + - ]: 1231 : SwFormatClipboard::~SwFormatClipboard()
256 : : {
257 [ - + ][ # # ]: 1231 : delete m_pItemSet_TxtAttr;
258 [ - + ][ # # ]: 1231 : delete m_pItemSet_ParAttr;
259 [ - + ][ # # ]: 1231 : delete m_pTableItemSet;
260 : 1231 : }
261 : :
262 : 1343 : bool SwFormatClipboard::HasContent() const
263 : : {
264 : : return m_pItemSet_TxtAttr!=0
265 : : || m_pItemSet_ParAttr!=0
266 : : || m_pTableItemSet != 0
267 : 1343 : || m_aCharStyle.Len()
268 [ + - ][ + - ]: 2686 : || m_aParaStyle.Len()
[ + - + - ]
[ - + ]
269 : : ;
270 : : }
271 : 0 : bool SwFormatClipboard::HasContentForThisType( int nSelectionType ) const
272 : : {
273 [ # # ]: 0 : if( !HasContent() )
274 : 0 : return false;
275 : :
276 [ # # ]: 0 : if( m_nSelectionType == nSelectionType )
277 : 0 : return true;
278 : :
279 [ # # ][ # # ]: 0 : if( ( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
280 : : &&
281 : : ( m_nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
282 : : )
283 : 0 : return true;
284 : :
285 [ # # ][ # # ]: 0 : if( nSelectionType & nsSelectionType::SEL_TXT && m_nSelectionType & nsSelectionType::SEL_TXT )
286 : 0 : return true;
287 : :
288 : 0 : return false;
289 : : }
290 : :
291 : 1343 : bool SwFormatClipboard::CanCopyThisType( int nSelectionType ) const
292 : : {
293 [ + - ]: 1343 : if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF
294 : : | nsSelectionType::SEL_TXT | nsSelectionType::SEL_DRW | nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS ) )
295 : 1343 : return true;
296 : 1343 : return false;
297 : : }
298 : :
299 : 0 : void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bPersistentCopy )
300 : : {
301 : : // first clear the previously stored attributes
302 : 0 : this->Erase();
303 : 0 : m_bPersistentCopy = bPersistentCopy;
304 : :
305 : 0 : int nSelectionType = rWrtShell.GetSelectionType();
306 : 0 : SfxItemSet* pItemSet_TxtAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, true );
307 : 0 : SfxItemSet* pItemSet_ParAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, false );
308 : :
309 : 0 : rWrtShell.StartAction();
310 : 0 : rWrtShell.Push();
311 : :
312 : : // modify the "Point and Mark" of the cursor
313 : : // in order to select only the last character of the
314 : : // selection(s) and then to get the attributes of this single character
315 [ # # ]: 0 : if( nSelectionType == nsSelectionType::SEL_TXT )
316 : : {
317 : : // get the current PaM, the cursor
318 : : // if there several selection it curently point
319 : : // on the last (sort by there creation time) selection
320 : 0 : SwPaM* pCrsr = rWrtShell.GetCrsr();
321 : :
322 : 0 : sal_Bool bHasSelection = pCrsr->HasMark();
323 : 0 : sal_Bool bForwardSelection = sal_False;
324 : :
325 [ # # ][ # # ]: 0 : if(!bHasSelection && pCrsr->GetPrev() != pCrsr && pCrsr->GetPrev() != 0)
[ # # ][ # # ]
326 : : {
327 : : // if cursor has multiple selections
328 : :
329 : : // clear all the selections except the last
330 : 0 : rWrtShell.KillPams();
331 : :
332 : : // reset the cursor to the remaining selection
333 : 0 : pCrsr = rWrtShell.GetCrsr();
334 : 0 : bHasSelection = true;
335 : : }
336 : :
337 : 0 : bool dontMove = false;
338 [ # # ]: 0 : if (bHasSelection)
339 : : {
340 : 0 : bForwardSelection = (*pCrsr->GetPoint()) > (*pCrsr->GetMark());
341 : :
342 : : // clear the selection leaving just the cursor
343 : 0 : pCrsr->DeleteMark();
344 : 0 : pCrsr->SetMark();
345 : : }
346 : : else
347 : : {
348 : 0 : bool rightToLeft = rWrtShell.IsInRightToLeftText();
349 : : // if there were no selection (only a cursor) and the cursor was at
350 : : // the end of the paragraph then don't move
351 [ # # ][ # # ]: 0 : if ( rWrtShell.IsEndPara() && !rightToLeft )
[ # # ]
352 : 0 : dontMove = true;
353 : :
354 : : // revert left and right
355 [ # # ]: 0 : if ( rightToLeft )
356 : : {
357 [ # # ]: 0 : if (pCrsr->GetPoint()->nContent == 0)
358 : 0 : dontMove = true;
359 : : else
360 : 0 : bForwardSelection = !bForwardSelection;
361 : : }
362 : : }
363 : :
364 : : // move the cursor in order to select one character
365 [ # # ]: 0 : if (!dontMove)
366 [ # # ]: 0 : pCrsr->Move( bForwardSelection ? fnMoveBackward : fnMoveForward );
367 : : }
368 : :
369 [ # # ]: 0 : if(pItemSet_TxtAttr)
370 : : {
371 [ # # ]: 0 : if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
372 : 0 : rWrtShell.GetFlyFrmAttr(*pItemSet_TxtAttr);
373 : : else
374 : : {
375 : : // get the text attributes from named and automatic formatting
376 : 0 : rWrtShell.GetCurAttr(*pItemSet_TxtAttr);
377 : :
378 [ # # ]: 0 : if( nSelectionType & nsSelectionType::SEL_TXT )
379 : : {
380 : : // get the paragraph attributes (could be character properties)
381 : : // from named and automatic formatting
382 : 0 : rWrtShell.GetCurParAttr(*pItemSet_ParAttr);
383 : : }
384 : : }
385 : : }
386 [ # # ]: 0 : else if ( nSelectionType & nsSelectionType::SEL_DRW )
387 : : {
388 : 0 : SdrView* pDrawView = rWrtShell.GetDrawView();
389 [ # # ]: 0 : if(pDrawView)
390 : : {
391 : 0 : sal_Bool bOnlyHardAttr = sal_True;
392 [ # # ]: 0 : if( pDrawView->AreObjectsMarked() )
393 : : {
394 [ # # ]: 0 : pItemSet_TxtAttr = new SfxItemSet( pDrawView->GetAttrFromMarked(bOnlyHardAttr) );
395 : : //remove attributes defining the type/data of custom shapes
396 : 0 : pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE);
397 : 0 : pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_DATA);
398 : 0 : pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_GEOMETRY);
399 : 0 : pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL);
400 : : }
401 : : }
402 : : }
403 : :
404 [ # # ]: 0 : if( nSelectionType & nsSelectionType::SEL_TBL_CELLS )//only copy table attributes if really cells are selected (not only text in tables)
405 : : {
406 : : m_pTableItemSet = new SfxItemSet(rPool,
407 : : SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW, //SID_ATTR_BORDER_OUTER is inbetween
408 : : RES_BACKGROUND, RES_SHADOW, //RES_BOX is inbetween
409 : : SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE,
410 : : RES_BREAK, RES_BREAK,
411 : : RES_PAGEDESC, RES_PAGEDESC,
412 : : RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT,
413 : : RES_ROW_SPLIT, RES_ROW_SPLIT,
414 : : RES_KEEP, RES_KEEP,
415 : : RES_FRAMEDIR, RES_FRAMEDIR,
416 : : FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE,
417 : : FN_TABLE_BOX_TEXTORIENTATION, FN_TABLE_BOX_TEXTORIENTATION,
418 : : FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
419 [ # # ]: 0 : 0);
420 : 0 : lcl_getTableAttributes( *m_pTableItemSet, rWrtShell );
421 : : }
422 : :
423 : 0 : m_nSelectionType = nSelectionType;
424 : 0 : m_pItemSet_TxtAttr = pItemSet_TxtAttr;
425 : 0 : m_pItemSet_ParAttr = pItemSet_ParAttr;
426 : :
427 [ # # ]: 0 : if( nSelectionType & nsSelectionType::SEL_TXT )
428 : : {
429 : : // if text is selected save the named character format
430 : 0 : SwFmt* pFmt = rWrtShell.GetCurCharFmt();
431 [ # # ]: 0 : if( pFmt )
432 : 0 : m_aCharStyle = pFmt->GetName();
433 : :
434 : : // and the named paragraph format
435 : 0 : pFmt = rWrtShell.GetCurTxtFmtColl();
436 [ # # ]: 0 : if( pFmt )
437 : 0 : m_aParaStyle = pFmt->GetName();
438 : : }
439 : :
440 : 0 : rWrtShell.Pop(sal_False);
441 : 0 : rWrtShell.EndAction();
442 : 0 : }
443 : :
444 : : typedef boost::shared_ptr< SfxPoolItem > SfxPoolItemSharedPtr;
445 : : typedef std::vector< SfxPoolItemSharedPtr > ItemVector;
446 : : // collect all PoolItems from the applied styles
447 : 0 : void lcl_AppendSetItems( ItemVector& rItemVector, const SfxItemSet& rStyleAttrSet )
448 : : {
449 : 0 : const sal_uInt16* pRanges = rStyleAttrSet.GetRanges();
450 [ # # ]: 0 : while( *pRanges )
451 : : {
452 [ # # ]: 0 : for ( sal_uInt16 nWhich = *pRanges; nWhich <= *(pRanges+1); ++nWhich )
453 : : {
454 : : const SfxPoolItem* pItem;
455 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rStyleAttrSet.GetItemState( nWhich, sal_False, &pItem ) )
456 : : {
457 [ # # ][ # # ]: 0 : rItemVector.push_back( SfxPoolItemSharedPtr( pItem->Clone() ) );
[ # # ][ # # ]
458 : : }
459 : : }
460 : 0 : pRanges += 2;
461 : : }
462 : 0 : }
463 : : // remove all items that are inherited from the styles
464 : 0 : void lcl_RemoveEqualItems( SfxItemSet& rTemplateItemSet, const ItemVector& rItemVector )
465 : : {
466 : 0 : ItemVector::const_iterator aEnd = rItemVector.end();
467 : 0 : ItemVector::const_iterator aIter = rItemVector.begin();
468 [ # # ][ # # ]: 0 : while( aIter != aEnd )
469 : : {
470 : : const SfxPoolItem* pItem;
471 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rTemplateItemSet.GetItemState( (*aIter)->Which(), sal_True, &pItem ) &&
[ # # ][ # # ]
472 [ # # ]: 0 : *pItem == *(*aIter) )
473 : : {
474 [ # # ]: 0 : rTemplateItemSet.ClearItem( (*aIter)->Which() );
475 : : }
476 : 0 : ++aIter;
477 : : }
478 : 0 : }
479 : :
480 : 0 : void SwFormatClipboard::Paste( SwWrtShell& rWrtShell, SfxStyleSheetBasePool* pPool
481 : : , bool bNoCharacterFormats, bool bNoParagraphFormats )
482 : : {
483 [ # # ]: 0 : int nSelectionType = rWrtShell.GetSelectionType();
484 [ # # ]: 0 : if( !this->HasContentForThisType(nSelectionType) )
485 : : {
486 [ # # ]: 0 : if(!m_bPersistentCopy)
487 [ # # ]: 0 : this->Erase();
488 : 0 : return;
489 : : }
490 : :
491 [ # # ]: 0 : rWrtShell.StartAction();
492 [ # # ]: 0 : rWrtShell.StartUndo(UNDO_INSATTR);
493 : :
494 [ # # ]: 0 : ItemVector aItemVector;
495 : :
496 [ # # ]: 0 : if( nSelectionType & nsSelectionType::SEL_TXT )
497 : : {
498 : : // apply the named text and paragraph formatting
499 [ # # ]: 0 : if( pPool )
500 : : {
501 : : // if there is a named text format recorded and the user wants to apply it
502 [ # # ][ # # ]: 0 : if(m_aCharStyle.Len() && !bNoCharacterFormats )
[ # # ]
503 : : {
504 : : // look for the named text format in the pool
505 [ # # ]: 0 : SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aCharStyle, SFX_STYLE_FAMILY_CHAR));
506 : :
507 : : // if the style is found
508 [ # # ]: 0 : if( pStyle )
509 : : {
510 [ # # ][ # # ]: 0 : SwFmtCharFmt aFmt(pStyle->GetCharFmt());
511 : : // store the attributes from this style in aItemVector in order
512 : : // not to apply them as automatic formatting attributes later in the code
513 [ # # ]: 0 : lcl_AppendSetItems( aItemVector, aFmt.GetCharFmt()->GetAttrSet());
514 : :
515 : : // apply the named format
516 [ # # ][ # # ]: 0 : rWrtShell.SetAttr( aFmt );
517 : : }
518 : : }
519 : :
520 : : // if there is a named paragraph format recorded and the user wants to apply it
521 [ # # ][ # # ]: 0 : if(m_aParaStyle.Len() && !bNoParagraphFormats )
[ # # ]
522 : : {
523 : : // look for the named pragraph format in the pool
524 [ # # ]: 0 : SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aParaStyle, SFX_STYLE_FAMILY_PARA));
525 [ # # ]: 0 : if( pStyle )
526 : : {
527 : : // store the attributes from this style in aItemVector in order
528 : : // not to apply them as automatic formatting attributes later in the code
529 [ # # ][ # # ]: 0 : lcl_AppendSetItems( aItemVector, pStyle->GetCollection()->GetAttrSet());
530 : :
531 : : // apply the named format
532 [ # # ][ # # ]: 0 : rWrtShell.SetTxtFmtColl( pStyle->GetCollection() );
533 : : }
534 : : }
535 : : }
536 : :
537 : : // apply the paragraph automatic attributes
538 [ # # ][ # # ]: 0 : if ( m_pItemSet_ParAttr && m_pItemSet_ParAttr->Count() != 0 && !bNoParagraphFormats )
[ # # ][ # # ]
539 : : {
540 : : // temporary SfxItemSet
541 : : SfxItemSet* pTemplateItemSet = lcl_CreateEmptyItemSet(
542 [ # # ]: 0 : nSelectionType, *m_pItemSet_ParAttr->GetPool(), false);
543 : : // no need to verify the existance 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 : : // it can't be a multiple selection
552 [ # # ]: 0 : SwPaM* pCrsr = rWrtShell.GetCrsr();
553 : :
554 : : // apply the paragraph automatic attributes
555 [ # # ]: 0 : pCrsr->GetCntntNode()->SetAttr( *pTemplateItemSet );
556 : :
557 : : // store the attributes in aItemVector in order not to apply them as
558 : : // text automatic formating attributes later in the code
559 [ # # ]: 0 : lcl_AppendSetItems( aItemVector, *pTemplateItemSet);
560 : :
561 [ # # ][ # # ]: 0 : delete pTemplateItemSet;
562 : : }
563 : : }
564 : :
565 [ # # ]: 0 : if(m_pItemSet_TxtAttr)
566 : : {
567 [ # # ]: 0 : if( nSelectionType & nsSelectionType::SEL_DRW )
568 : : {
569 [ # # ]: 0 : SdrView* pDrawView = rWrtShell.GetDrawView();
570 [ # # ]: 0 : if(pDrawView)
571 : : {
572 : 0 : sal_Bool bReplaceAll = sal_True;
573 [ # # ]: 0 : pDrawView->SetAttrToMarked(*m_pItemSet_TxtAttr, bReplaceAll);
574 : : }
575 : : }
576 : : else
577 : : {
578 : : // temporary SfxItemSet
579 : : SfxItemSet* pTemplateItemSet = lcl_CreateEmptyItemSet(
580 [ # # ]: 0 : nSelectionType, *m_pItemSet_TxtAttr->GetPool(), true );
581 : :
582 [ # # ]: 0 : if(pTemplateItemSet)
583 : : {
584 : : // copy the stored automatic text attributes in a temporary SfxItemSet
585 [ # # ]: 0 : pTemplateItemSet->Put( *m_pItemSet_TxtAttr );
586 : :
587 : : // only attributes that were not apply by named style attributes and automatic
588 : : // paragraph attributes should be applied
589 [ # # ]: 0 : lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
590 : :
591 : : // apply the character automatic attributes
592 [ # # ]: 0 : if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
593 [ # # ]: 0 : rWrtShell.SetFlyFrmAttr(*pTemplateItemSet);
594 [ # # ]: 0 : else if ( !bNoCharacterFormats )
595 [ # # ]: 0 : rWrtShell.SetAttr(*pTemplateItemSet);
596 : :
597 [ # # ][ # # ]: 0 : delete pTemplateItemSet;
598 : : }
599 : : }
600 : : }
601 : :
602 [ # # ][ # # ]: 0 : if( m_pTableItemSet && nSelectionType & (nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS) )
603 [ # # ]: 0 : lcl_setTableAttributes( *m_pTableItemSet, rWrtShell );
604 : :
605 [ # # ]: 0 : rWrtShell.EndUndo(UNDO_INSATTR);
606 [ # # ]: 0 : rWrtShell.EndAction();
607 : :
608 [ # # ]: 0 : if(!m_bPersistentCopy)
609 [ # # ]: 0 : this->Erase();
610 : : }
611 : :
612 : 0 : void SwFormatClipboard::Erase()
613 : : {
614 : 0 : m_nSelectionType = 0;
615 : :
616 [ # # ]: 0 : delete m_pItemSet_TxtAttr;
617 : 0 : m_pItemSet_TxtAttr = 0;
618 : :
619 [ # # ]: 0 : delete m_pItemSet_ParAttr;
620 : 0 : m_pItemSet_ParAttr = 0;
621 : :
622 [ # # ]: 0 : delete m_pTableItemSet;
623 : 0 : m_pTableItemSet = 0;
624 : :
625 [ # # ]: 0 : if( m_aCharStyle.Len() )
626 : 0 : m_aCharStyle.Erase();
627 [ # # ]: 0 : if( m_aParaStyle.Len() )
628 : 0 : m_aParaStyle.Erase();
629 : :
630 : 0 : m_bPersistentCopy = false;
631 : 0 : }
632 : :
633 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|