1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "formatclipboard.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <hintids.hxx>
31cdf0e10cSrcweir #ifndef _SVX_SVXIDS_HRC
32cdf0e10cSrcweir #include <svx/svxids.hrc>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #ifndef _CMDID_H
35cdf0e10cSrcweir #include <cmdid.h>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <format.hxx>
38cdf0e10cSrcweir #include <charfmt.hxx>
39cdf0e10cSrcweir #include <fmtcol.hxx>
40cdf0e10cSrcweir #include <frmfmt.hxx>
41cdf0e10cSrcweir #include <docstyle.hxx>
42cdf0e10cSrcweir #include <fchrfmt.hxx>
43cdf0e10cSrcweir #include <pam.hxx>
44cdf0e10cSrcweir // header for class SdrView
45cdf0e10cSrcweir #include <svx/svdview.hxx>
46cdf0e10cSrcweir //SvxBrushItem
47cdf0e10cSrcweir #include <editeng/brshitem.hxx>
48cdf0e10cSrcweir #include <editeng/shaditem.hxx>
49cdf0e10cSrcweir #include <frmatr.hxx>
50cdf0e10cSrcweir // header for class SvxBoxInfoItem
51cdf0e10cSrcweir #include <editeng/boxitem.hxx>
52cdf0e10cSrcweir // header for class SvxFmtBreakItem
53cdf0e10cSrcweir #include <editeng/brkitem.hxx>
54cdf0e10cSrcweir // header for class SwFmtLayoutSplit
55cdf0e10cSrcweir #include <fmtlsplt.hxx>
56cdf0e10cSrcweir // header for class SvxFmtKeepItem
57cdf0e10cSrcweir #include <editeng/keepitem.hxx>
58cdf0e10cSrcweir // header for class SvxFrameDirectionItem
59cdf0e10cSrcweir #include <editeng/frmdiritem.hxx>
60cdf0e10cSrcweir #include <paratr.hxx>
61cdf0e10cSrcweir #include <fmtpdsc.hxx>
62cdf0e10cSrcweir #include <fmtrowsplt.hxx>
63cdf0e10cSrcweir #include <swundo.hxx>			// fuer die UndoIds
64cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //#define FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES 1
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #ifdef FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES
69cdf0e10cSrcweir #include <cellatr.hxx>
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir 
72cdf0e10cSrcweir /*--------------------------------------------------------------------
73cdf0e10cSrcweir  --------------------------------------------------------------------*/
74cdf0e10cSrcweir 
75cdf0e10cSrcweir namespace
76cdf0e10cSrcweir {
77cdf0e10cSrcweir #define FORMAT_PAINTBRUSH_FRAME_IDS \
78cdf0e10cSrcweir RES_FRMATR_BEGIN, RES_FILL_ORDER, \
79cdf0e10cSrcweir /* no RES_FRM_SIZE */ \
80cdf0e10cSrcweir RES_PAPER_BIN, RES_SURROUND, \
81cdf0e10cSrcweir /* no RES_VERT_ORIENT */ \
82cdf0e10cSrcweir /* no RES_HORI_ORIENT */ \
83cdf0e10cSrcweir /* no RES_ANCHOR */ \
84cdf0e10cSrcweir RES_BACKGROUND, RES_SHADOW, \
85cdf0e10cSrcweir /* no RES_FRMMACRO */ \
86cdf0e10cSrcweir RES_COL, RES_KEEP, \
87cdf0e10cSrcweir /* no RES_URL */ \
88cdf0e10cSrcweir RES_EDIT_IN_READONLY, RES_LAYOUT_SPLIT, \
89cdf0e10cSrcweir /* no RES_CHAIN */ \
90cdf0e10cSrcweir RES_TEXTGRID, RES_FRMATR_END-1,
91cdf0e10cSrcweir 
92cdf0e10cSrcweir #define FORMAT_PAINTBRUSH_PARAGRAPH_IDS \
93cdf0e10cSrcweir RES_PARATR_BEGIN, RES_PARATR_END -1, \
94cdf0e10cSrcweir RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END -1, \
95cdf0e10cSrcweir FORMAT_PAINTBRUSH_FRAME_IDS \
96cdf0e10cSrcweir FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART, \
97cdf0e10cSrcweir FN_NUMBER_NEWSTART_AT, FN_NUMBER_NEWSTART_AT,
98cdf0e10cSrcweir 
lcl_CreateEmptyItemSet(int nSelectionType,SfxItemPool & rPool,bool bNoCharacterFormats=false,bool bNoParagraphFormats=false)99cdf0e10cSrcweir SfxItemSet* lcl_CreateEmptyItemSet( int nSelectionType, SfxItemPool& rPool
100cdf0e10cSrcweir             , bool bNoCharacterFormats = false, bool bNoParagraphFormats = false )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     SfxItemSet* pItemSet = 0;
103cdf0e10cSrcweir     if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         pItemSet = new SfxItemSet(rPool,
106cdf0e10cSrcweir                         FORMAT_PAINTBRUSH_FRAME_IDS
107cdf0e10cSrcweir                         0);
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir     else if( nSelectionType & nsSelectionType::SEL_DRW )
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         //is handled different
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir     else if( nSelectionType == nsSelectionType::SEL_TBL )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         pItemSet = new SfxItemSet(rPool,
116cdf0e10cSrcweir                         SID_ATTR_BORDER_INNER,	SID_ATTR_BORDER_SHADOW, //SID_ATTR_BORDER_OUTER is inbetween
117cdf0e10cSrcweir 	                    RES_BACKGROUND,         RES_SHADOW, //RES_BOX is inbetween
118cdf0e10cSrcweir 	                    SID_ATTR_BRUSH_ROW, 	SID_ATTR_BRUSH_TABLE,
119cdf0e10cSrcweir                         RES_BREAK,              RES_BREAK,
120cdf0e10cSrcweir                         RES_PAGEDESC,           RES_PAGEDESC,
121cdf0e10cSrcweir                         RES_LAYOUT_SPLIT,       RES_LAYOUT_SPLIT,
122cdf0e10cSrcweir                         RES_ROW_SPLIT,          RES_ROW_SPLIT,
123cdf0e10cSrcweir                         RES_KEEP,               RES_KEEP,
124cdf0e10cSrcweir                         RES_FRAMEDIR,           RES_FRAMEDIR,
125cdf0e10cSrcweir                         FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE,
126cdf0e10cSrcweir                         FN_TABLE_BOX_TEXTDIRECTION, FN_TABLE_BOX_TEXTDIRECTION,
127cdf0e10cSrcweir                         FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
128cdf0e10cSrcweir #ifdef FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES
129cdf0e10cSrcweir                         RES_BOXATR_FORMAT,      RES_BOXATR_FORMAT,
130cdf0e10cSrcweir #endif
131cdf0e10cSrcweir                         0);
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir     else if( nSelectionType & nsSelectionType::SEL_TXT )
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         if( bNoCharacterFormats )
136cdf0e10cSrcweir             pItemSet = new SfxItemSet(rPool,
137cdf0e10cSrcweir                     FORMAT_PAINTBRUSH_PARAGRAPH_IDS
138cdf0e10cSrcweir                     0);
139cdf0e10cSrcweir         else if( bNoParagraphFormats )
140cdf0e10cSrcweir             pItemSet = new SfxItemSet(rPool,
141cdf0e10cSrcweir                     RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
142cdf0e10cSrcweir                     0);
143cdf0e10cSrcweir         else
144cdf0e10cSrcweir             pItemSet = new SfxItemSet(rPool,
145cdf0e10cSrcweir                     RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
146cdf0e10cSrcweir                     FORMAT_PAINTBRUSH_PARAGRAPH_IDS
147cdf0e10cSrcweir                     0);
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir     return pItemSet;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
lcl_getTableAttributes(SfxItemSet & rSet,SwWrtShell & rSh)152cdf0e10cSrcweir void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     SvxBrushItem aBrush( RES_BACKGROUND );
155cdf0e10cSrcweir  	rSh.GetBoxBackground(aBrush);
156cdf0e10cSrcweir 	rSet.Put( aBrush );
157cdf0e10cSrcweir 	if(rSh.GetRowBackground(aBrush))
158cdf0e10cSrcweir 		rSet.Put( aBrush, SID_ATTR_BRUSH_ROW );
159cdf0e10cSrcweir 	else
160cdf0e10cSrcweir 		rSet.InvalidateItem(SID_ATTR_BRUSH_ROW);
161cdf0e10cSrcweir 	rSh.GetTabBackground(aBrush);
162cdf0e10cSrcweir 	rSet.Put( aBrush, SID_ATTR_BRUSH_TABLE );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
165cdf0e10cSrcweir     rSet.Put(aBoxInfo);
166cdf0e10cSrcweir     rSh.GetTabBorders( rSet );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     SvxFrameDirectionItem aBoxDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
169cdf0e10cSrcweir     if(rSh.GetBoxDirection( aBoxDirection ))
170cdf0e10cSrcweir         rSet.Put(aBoxDirection, FN_TABLE_BOX_TEXTDIRECTION);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, rSh.GetBoxAlign()));
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, rSh.GetRowsToRepeat() ) );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     SwFrmFmt *pFrmFmt = rSh.GetTableFmt();
177cdf0e10cSrcweir     if(pFrmFmt)
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         rSet.Put( pFrmFmt->GetShadow() );
180cdf0e10cSrcweir         rSet.Put( pFrmFmt->GetBreak() );
181cdf0e10cSrcweir         rSet.Put( pFrmFmt->GetPageDesc() );
182cdf0e10cSrcweir         rSet.Put( pFrmFmt->GetLayoutSplit() );
183cdf0e10cSrcweir         rSet.Put( pFrmFmt->GetKeep() );
184cdf0e10cSrcweir         rSet.Put( pFrmFmt->GetFrmDir() );
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     SwFmtRowSplit* pSplit = 0;
188cdf0e10cSrcweir     rSh.GetRowSplit(pSplit);
189cdf0e10cSrcweir     if(pSplit)
190cdf0e10cSrcweir         rSet.Put(*pSplit);
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     //-- numberformat in cells
193cdf0e10cSrcweir #ifdef FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES
194cdf0e10cSrcweir 	rSh.GetTblBoxFormulaAttrs( rSet ); //RES_BOXATR_FORMAT
195cdf0e10cSrcweir #endif
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
lcl_setTableAttributes(const SfxItemSet & rSet,SwWrtShell & rSh)198cdf0e10cSrcweir void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     const SfxPoolItem* pItem = 0;
201cdf0e10cSrcweir     sal_Bool bBorder = ( SFX_ITEM_SET == rSet.GetItemState( RES_BOX ) ||
202cdf0e10cSrcweir 			SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER ) );
203cdf0e10cSrcweir 	pItem = 0;
204cdf0e10cSrcweir 	sal_Bool bBackground = SFX_ITEM_SET == rSet.GetItemState( RES_BACKGROUND, sal_False, &pItem );
205cdf0e10cSrcweir 	const SfxPoolItem* pRowItem = 0, *pTableItem = 0;
206cdf0e10cSrcweir 	bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_ROW, sal_False, &pRowItem );
207cdf0e10cSrcweir 	bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_TABLE, sal_False, &pTableItem );
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     if(bBackground)
210cdf0e10cSrcweir 	{
211cdf0e10cSrcweir 		if(pItem)
212cdf0e10cSrcweir 			rSh.SetBoxBackground( *(const SvxBrushItem*)pItem );
213cdf0e10cSrcweir 		if(pRowItem)
214cdf0e10cSrcweir 		{
215cdf0e10cSrcweir 			SvxBrushItem aBrush(*(const SvxBrushItem*)pRowItem);
216cdf0e10cSrcweir 			aBrush.SetWhich(RES_BACKGROUND);
217cdf0e10cSrcweir 			rSh.SetRowBackground(aBrush);
218cdf0e10cSrcweir 		}
219cdf0e10cSrcweir 		if(pTableItem)
220cdf0e10cSrcweir 		{
221cdf0e10cSrcweir 			SvxBrushItem aBrush(*(const SvxBrushItem*)pTableItem);
222cdf0e10cSrcweir 			aBrush.SetWhich(RES_BACKGROUND);
223cdf0e10cSrcweir 			rSh.SetTabBackground( aBrush );
224cdf0e10cSrcweir 		}
225cdf0e10cSrcweir 	}
226cdf0e10cSrcweir     if(bBorder)
227cdf0e10cSrcweir         rSh.SetTabBorders( rSet );
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, sal_False, &pItem) )
230cdf0e10cSrcweir         rSh.SetRowsToRepeat( ((SfxUInt16Item*)pItem)->GetValue() );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     SwFrmFmt* pFrmFmt = rSh.GetTableFmt();
233cdf0e10cSrcweir     if(pFrmFmt)
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         //RES_SHADOW
236cdf0e10cSrcweir         pItem=0;
237cdf0e10cSrcweir         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_SHADOW), sal_False, &pItem);
238cdf0e10cSrcweir 	    if(pItem)
239cdf0e10cSrcweir             pFrmFmt->SetFmtAttr( *pItem );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         //RES_BREAK
242cdf0e10cSrcweir         pItem=0;
243cdf0e10cSrcweir         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_BREAK), sal_False, &pItem);
244cdf0e10cSrcweir 	    if(pItem)
245cdf0e10cSrcweir             pFrmFmt->SetFmtAttr( *pItem );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         //RES_PAGEDESC
248cdf0e10cSrcweir         pItem=0;
249cdf0e10cSrcweir         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_PAGEDESC), sal_False, &pItem);
250cdf0e10cSrcweir 	    if(pItem)
251cdf0e10cSrcweir             pFrmFmt->SetFmtAttr( *pItem );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir         //RES_LAYOUT_SPLIT
254cdf0e10cSrcweir         pItem=0;
255cdf0e10cSrcweir         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_LAYOUT_SPLIT), sal_False, &pItem);
256cdf0e10cSrcweir 	    if(pItem)
257cdf0e10cSrcweir             pFrmFmt->SetFmtAttr( *pItem );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         //RES_KEEP
260cdf0e10cSrcweir         pItem=0;
261cdf0e10cSrcweir         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_KEEP), sal_False, &pItem);
262cdf0e10cSrcweir 	    if(pItem)
263cdf0e10cSrcweir             pFrmFmt->SetFmtAttr( *pItem );
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         //RES_FRAMEDIR
266cdf0e10cSrcweir         pItem=0;
267cdf0e10cSrcweir         rSet.GetItemState(rSet.GetPool()->GetWhich(RES_FRAMEDIR), sal_False, &pItem);
268cdf0e10cSrcweir 	    if(pItem)
269cdf0e10cSrcweir             pFrmFmt->SetFmtAttr( *pItem );
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_BOX_TEXTDIRECTION, sal_False, &pItem) )
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         SvxFrameDirectionItem aDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
275cdf0e10cSrcweir         aDirection.SetValue(static_cast< const SvxFrameDirectionItem* >(pItem)->GetValue());
276cdf0e10cSrcweir         rSh.SetBoxDirection(aDirection);
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_SET_VERT_ALIGN, sal_False, &pItem))
280cdf0e10cSrcweir 		rSh.SetBoxAlign(((SfxUInt16Item*)(pItem))->GetValue());
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     if( SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, sal_False, &pItem) )
283cdf0e10cSrcweir         rSh.SetRowSplit(*static_cast<const SwFmtRowSplit*>(pItem));
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     //-- numberformat in cells
286cdf0e10cSrcweir #ifdef FORMAT_PAINTBRUSH_ALSO_COPY_NUMBERFORMAT_FOR_TABLES
287cdf0e10cSrcweir     if( SFX_ITEM_SET == rSet.GetItemState( RES_BOXATR_FORMAT, sal_False, &pItem ))
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir 	    SfxItemSet aBoxSet( *rSet.GetPool(), RES_BOXATR_FORMAT, RES_BOXATR_FORMAT );
290cdf0e10cSrcweir 	    aBoxSet.Put( SwTblBoxNumFormat( ((SfxUInt32Item*)pItem)->GetValue() ));
291cdf0e10cSrcweir 	    rSh.SetTblBoxFormulaAttrs( aBoxSet );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir     }
294cdf0e10cSrcweir #endif
295cdf0e10cSrcweir }
296cdf0e10cSrcweir }//end anonymous namespace
297cdf0e10cSrcweir 
SwFormatClipboard()298cdf0e10cSrcweir SwFormatClipboard::SwFormatClipboard()
299cdf0e10cSrcweir         : m_nSelectionType(0)
300cdf0e10cSrcweir         , m_pItemSet(0)
301cdf0e10cSrcweir         , m_pTableItemSet(0)
302cdf0e10cSrcweir         , m_bPersistentCopy(false)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir }
~SwFormatClipboard()305cdf0e10cSrcweir SwFormatClipboard::~SwFormatClipboard()
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     if(m_pItemSet)
308cdf0e10cSrcweir         delete m_pItemSet;
309cdf0e10cSrcweir     if(m_pTableItemSet)
310cdf0e10cSrcweir         delete m_pTableItemSet;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
HasContent() const313cdf0e10cSrcweir bool SwFormatClipboard::HasContent() const
314cdf0e10cSrcweir {
315cdf0e10cSrcweir     return m_pItemSet!=0
316cdf0e10cSrcweir         || m_pTableItemSet != 0
317cdf0e10cSrcweir         || m_aCharStyle.Len()
318cdf0e10cSrcweir         || m_aParaStyle.Len()
319cdf0e10cSrcweir         ;
320cdf0e10cSrcweir }
HasContentForThisType(int nSelectionType) const321cdf0e10cSrcweir bool SwFormatClipboard::HasContentForThisType( int nSelectionType ) const
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     if( !HasContent() )
324cdf0e10cSrcweir         return false;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     if( m_nSelectionType == nSelectionType )
327cdf0e10cSrcweir         return true;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     if(   ( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
330cdf0e10cSrcweir         &&
331cdf0e10cSrcweir         ( m_nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
332cdf0e10cSrcweir         )
333cdf0e10cSrcweir         return true;
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     if( nSelectionType & nsSelectionType::SEL_TXT && m_nSelectionType & nsSelectionType::SEL_TXT )
336cdf0e10cSrcweir         return true;
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     return false;
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
CanCopyThisType(int nSelectionType) const341cdf0e10cSrcweir bool SwFormatClipboard::CanCopyThisType( int nSelectionType ) const
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF
344cdf0e10cSrcweir          | nsSelectionType::SEL_TXT | nsSelectionType::SEL_DRW | nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS ) )
345cdf0e10cSrcweir          return true;
346cdf0e10cSrcweir     return false;
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
Copy(SwWrtShell & rWrtShell,SfxItemPool & rPool,bool bPersistentCopy)349cdf0e10cSrcweir void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bPersistentCopy )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     this->Erase();
352cdf0e10cSrcweir     m_bPersistentCopy = bPersistentCopy;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     int nSelectionType = rWrtShell.GetSelectionType();
355cdf0e10cSrcweir     SfxItemSet* pItemSet = lcl_CreateEmptyItemSet( nSelectionType, rPool );
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     rWrtShell.StartAction();
358cdf0e10cSrcweir     rWrtShell.Push();
359cdf0e10cSrcweir     if( nSelectionType == nsSelectionType::SEL_TXT )
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir         SwPaM* pCrsr = rWrtShell.GetCrsr();
362cdf0e10cSrcweir         //select one character only to get the attributes of this single character only
363cdf0e10cSrcweir         sal_Bool bHasSelection = pCrsr->HasMark();
364cdf0e10cSrcweir         sal_Bool bForwardSelection = sal_False;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir         if(!bHasSelection) //check for and handle multiselections
367cdf0e10cSrcweir         {
368cdf0e10cSrcweir             if( pCrsr->GetPrev() != pCrsr && pCrsr->GetPrev() != 0)
369cdf0e10cSrcweir             {
370cdf0e10cSrcweir                 pCrsr = (SwPaM*)pCrsr->GetPrev();
371cdf0e10cSrcweir                 bForwardSelection = (*pCrsr->GetPoint()) > (*pCrsr->GetMark());
372cdf0e10cSrcweir                 bHasSelection = true;
373cdf0e10cSrcweir                 pCrsr->DeleteMark();
374cdf0e10cSrcweir                 pCrsr->SetMark();
375cdf0e10cSrcweir                 rWrtShell.KillPams();
376cdf0e10cSrcweir                 pCrsr = rWrtShell.GetCrsr();
377cdf0e10cSrcweir             }
378cdf0e10cSrcweir         }
379cdf0e10cSrcweir         else
380cdf0e10cSrcweir             bForwardSelection = (*pCrsr->GetPoint()) > (*pCrsr->GetMark());
381cdf0e10cSrcweir 	    pCrsr->DeleteMark();
382cdf0e10cSrcweir         pCrsr->SetMark();
383cdf0e10cSrcweir 
384cdf0e10cSrcweir         if( !bHasSelection && rWrtShell.IsInRightToLeftText() )
385cdf0e10cSrcweir             bForwardSelection = !bForwardSelection;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir         if( !( !bHasSelection && rWrtShell.IsEndPara() ) )
388cdf0e10cSrcweir             pCrsr->Move( bForwardSelection ? fnMoveBackward : fnMoveForward );
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     if(pItemSet)
392cdf0e10cSrcweir     {
393cdf0e10cSrcweir         if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
394cdf0e10cSrcweir             rWrtShell.GetFlyFrmAttr(*pItemSet);
395cdf0e10cSrcweir         else
396cdf0e10cSrcweir         {
397cdf0e10cSrcweir             rWrtShell.GetCurAttr(*pItemSet);
398cdf0e10cSrcweir 
399cdf0e10cSrcweir             // additional numbering properties for paragraph styles
400cdf0e10cSrcweir             if( nSelectionType & nsSelectionType::SEL_TXT && rWrtShell.GetCurNumRule() )
401cdf0e10cSrcweir             {
402cdf0e10cSrcweir                 SfxBoolItem aStart(FN_NUMBER_NEWSTART, rWrtShell.IsNumRuleStart());
403cdf0e10cSrcweir                 pItemSet->Put(aStart);
404cdf0e10cSrcweir                 SfxUInt16Item aStartAt(FN_NUMBER_NEWSTART_AT, rWrtShell.GetNodeNumStart());
405cdf0e10cSrcweir                 pItemSet->Put(aStartAt);
406cdf0e10cSrcweir             }
407cdf0e10cSrcweir         }
408cdf0e10cSrcweir     }
409cdf0e10cSrcweir     else if ( nSelectionType & nsSelectionType::SEL_DRW )
410cdf0e10cSrcweir     {
411cdf0e10cSrcweir         SdrView* pDrawView = rWrtShell.GetDrawView();
412cdf0e10cSrcweir         if(pDrawView)
413cdf0e10cSrcweir         {
414cdf0e10cSrcweir             sal_Bool bOnlyHardAttr = sal_True;
415cdf0e10cSrcweir             if( pDrawView->AreObjectsMarked() )
416cdf0e10cSrcweir             {
417cdf0e10cSrcweir                 pItemSet = new SfxItemSet( pDrawView->GetAttrFromMarked(bOnlyHardAttr) );
418cdf0e10cSrcweir                 //remove attributes defining the type/data of custom shapes
419cdf0e10cSrcweir                 pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE);
420cdf0e10cSrcweir                 pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_DATA);
421cdf0e10cSrcweir                 pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_GEOMETRY);
422cdf0e10cSrcweir                 pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL);
423cdf0e10cSrcweir             }
424cdf0e10cSrcweir         }
425cdf0e10cSrcweir     }
426cdf0e10cSrcweir     if( nSelectionType & nsSelectionType::SEL_TBL_CELLS )//only copy table attributes if really cells are selected (not only text in tables)
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir         m_pTableItemSet = lcl_CreateEmptyItemSet( nsSelectionType::SEL_TBL, rPool );
429cdf0e10cSrcweir         lcl_getTableAttributes( *m_pTableItemSet, rWrtShell );
430cdf0e10cSrcweir     }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     m_nSelectionType = nSelectionType;
433cdf0e10cSrcweir     m_pItemSet = pItemSet;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     if( nSelectionType & nsSelectionType::SEL_TXT )
436cdf0e10cSrcweir     {
437cdf0e10cSrcweir         SwFmt* pFmt = rWrtShell.GetCurCharFmt();
438cdf0e10cSrcweir         if( pFmt )
439cdf0e10cSrcweir             m_aCharStyle = pFmt->GetName();
440cdf0e10cSrcweir 
441cdf0e10cSrcweir         pFmt = rWrtShell.GetCurTxtFmtColl();
442cdf0e10cSrcweir         if( pFmt )
443cdf0e10cSrcweir             m_aParaStyle = pFmt->GetName();
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir     rWrtShell.Pop(sal_False);
446cdf0e10cSrcweir     rWrtShell.EndAction();
447cdf0e10cSrcweir }
448cdf0e10cSrcweir typedef boost::shared_ptr< SfxPoolItem > SfxPoolItemSharedPtr;
449cdf0e10cSrcweir typedef std::vector< SfxPoolItemSharedPtr > ItemVector;
450cdf0e10cSrcweir // #144857# collect all PoolItems from the applied styles
lcl_AppendSetItems(ItemVector & rItemVector,const SfxItemSet & rStyleAttrSet)451cdf0e10cSrcweir void lcl_AppendSetItems( ItemVector& rItemVector, const SfxItemSet& rStyleAttrSet )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir     const sal_uInt16*  pRanges = rStyleAttrSet.GetRanges();
454cdf0e10cSrcweir     while( *pRanges )
455cdf0e10cSrcweir     {
456cdf0e10cSrcweir         for ( sal_uInt16 nWhich = *pRanges; nWhich <= *(pRanges+1); ++nWhich )
457cdf0e10cSrcweir         {
458cdf0e10cSrcweir             const SfxPoolItem* pItem;
459cdf0e10cSrcweir             if( SFX_ITEM_SET == rStyleAttrSet.GetItemState( nWhich, sal_False, &pItem ) )
460cdf0e10cSrcweir             {
461cdf0e10cSrcweir                 rItemVector.push_back( SfxPoolItemSharedPtr( pItem->Clone() ) );
462cdf0e10cSrcweir             }
463cdf0e10cSrcweir         }
464cdf0e10cSrcweir         pRanges += 2;
465cdf0e10cSrcweir     }
466cdf0e10cSrcweir }
467cdf0e10cSrcweir // #144857# remove all items that are inherited from the styles
lcl_RemoveEqualItems(SfxItemSet & rTemplateItemSet,ItemVector & rItemVector)468cdf0e10cSrcweir void lcl_RemoveEqualItems( SfxItemSet& rTemplateItemSet, ItemVector& rItemVector )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     ItemVector::iterator aEnd = rItemVector.end();
471cdf0e10cSrcweir     ItemVector::iterator aIter = rItemVector.begin();
472cdf0e10cSrcweir     while( aIter != aEnd )
473cdf0e10cSrcweir     {
474cdf0e10cSrcweir         const SfxPoolItem* pItem;
475cdf0e10cSrcweir         if( SFX_ITEM_SET == rTemplateItemSet.GetItemState( (*aIter)->Which(), sal_True, &pItem ) &&
476cdf0e10cSrcweir             *pItem == *(*aIter) )
477cdf0e10cSrcweir         {
478cdf0e10cSrcweir             rTemplateItemSet.ClearItem( (*aIter)->Which() );
479cdf0e10cSrcweir         }
480cdf0e10cSrcweir         ++aIter;
481cdf0e10cSrcweir     }
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
Paste(SwWrtShell & rWrtShell,SfxStyleSheetBasePool * pPool,bool bNoCharacterFormats,bool bNoParagraphFormats)484cdf0e10cSrcweir void SwFormatClipboard::Paste( SwWrtShell& rWrtShell, SfxStyleSheetBasePool* pPool
485cdf0e10cSrcweir                               , bool bNoCharacterFormats, bool bNoParagraphFormats )
486cdf0e10cSrcweir {
487cdf0e10cSrcweir     int nSelectionType = rWrtShell.GetSelectionType();
488cdf0e10cSrcweir     if( !this->HasContentForThisType(nSelectionType) )
489cdf0e10cSrcweir     {
490cdf0e10cSrcweir         if(!m_bPersistentCopy)
491cdf0e10cSrcweir             this->Erase();
492cdf0e10cSrcweir         return;
493cdf0e10cSrcweir     }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir     rWrtShell.StartAction();
496cdf0e10cSrcweir     rWrtShell.StartUndo(UNDO_INSATTR);
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     ItemVector aItemVector;
499cdf0e10cSrcweir     if(pPool) //to find the styles we need the pool
500cdf0e10cSrcweir     {
501cdf0e10cSrcweir         if( nSelectionType & nsSelectionType::SEL_TXT )
502cdf0e10cSrcweir         {
503cdf0e10cSrcweir             if(m_aCharStyle.Len() && !bNoCharacterFormats )
504cdf0e10cSrcweir             {
505cdf0e10cSrcweir                 SwDocStyleSheet* pStyle = (SwDocStyleSheet*)pPool->Find(m_aCharStyle, SFX_STYLE_FAMILY_CHAR);
506cdf0e10cSrcweir                 if( pStyle )
507cdf0e10cSrcweir                 {
508cdf0e10cSrcweir                     SwFmtCharFmt aFmt(pStyle->GetCharFmt());
509cdf0e10cSrcweir                     // #144857# collect items from character style
510cdf0e10cSrcweir                     lcl_AppendSetItems( aItemVector, aFmt.GetCharFmt()->GetAttrSet());
511cdf0e10cSrcweir                     sal_uInt16 nFlags=0; //(nMode & KEY_SHIFT) ? SETATTR_DONTREPLACE : SETATTR_DEFAULT;
512*69a74367SOliver-Rainer Wittmann                     rWrtShell.SetAttrItem( aFmt, nFlags );
513cdf0e10cSrcweir                 }
514cdf0e10cSrcweir             }
515cdf0e10cSrcweir             if(m_aParaStyle.Len() && !bNoParagraphFormats )
516cdf0e10cSrcweir             {
517cdf0e10cSrcweir                 SwDocStyleSheet* pStyle = (SwDocStyleSheet*)pPool->Find(m_aParaStyle, SFX_STYLE_FAMILY_PARA);
518cdf0e10cSrcweir                 if( pStyle )
519cdf0e10cSrcweir                 {
520cdf0e10cSrcweir                     // #144857# collect items from paragraph style
521cdf0e10cSrcweir                     lcl_AppendSetItems( aItemVector, pStyle->GetCollection()->GetAttrSet());
522cdf0e10cSrcweir 		            rWrtShell.SetTxtFmtColl( pStyle->GetCollection() );
523cdf0e10cSrcweir                 }
524cdf0e10cSrcweir             }
525cdf0e10cSrcweir         }
526cdf0e10cSrcweir     }
527cdf0e10cSrcweir     if(m_pItemSet)
528cdf0e10cSrcweir     {
529cdf0e10cSrcweir         if( nSelectionType & nsSelectionType::SEL_DRW )
530cdf0e10cSrcweir         {
531cdf0e10cSrcweir             SdrView* pDrawView = rWrtShell.GetDrawView();
532cdf0e10cSrcweir             if(pDrawView)
533cdf0e10cSrcweir             {
534cdf0e10cSrcweir                 sal_Bool bReplaceAll = sal_True;
535cdf0e10cSrcweir 	            pDrawView->SetAttrToMarked(*m_pItemSet, bReplaceAll);
536cdf0e10cSrcweir             }
537cdf0e10cSrcweir         }
538cdf0e10cSrcweir         else
539cdf0e10cSrcweir         {
540cdf0e10cSrcweir             SfxItemSet* pTemplateItemSet = lcl_CreateEmptyItemSet(
541cdf0e10cSrcweir                               nSelectionType, *m_pItemSet->GetPool()
542cdf0e10cSrcweir                               , bNoCharacterFormats, bNoParagraphFormats );
543cdf0e10cSrcweir             if(pTemplateItemSet)
544cdf0e10cSrcweir             {
545cdf0e10cSrcweir                 pTemplateItemSet->Put( *m_pItemSet );
546cdf0e10cSrcweir                 // #144857# only _set_ attributes that differ from style attributes should be applied - the style is applied anyway
547cdf0e10cSrcweir                 lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir                 if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) )
550cdf0e10cSrcweir                     rWrtShell.SetFlyFrmAttr(*pTemplateItemSet);
551cdf0e10cSrcweir                 else
552cdf0e10cSrcweir                 {
553*69a74367SOliver-Rainer Wittmann                     rWrtShell.SetAttrSet(*pTemplateItemSet);
554cdf0e10cSrcweir 
555cdf0e10cSrcweir                     // additional numbering properties for paragraph styles
556cdf0e10cSrcweir                     if( nSelectionType & nsSelectionType::SEL_TXT && rWrtShell.GetCurNumRule() )
557cdf0e10cSrcweir                     {
558cdf0e10cSrcweir                         if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART) )
559cdf0e10cSrcweir                         {
560cdf0e10cSrcweir                             sal_Bool bStart = ((SfxBoolItem&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART)).GetValue();
561cdf0e10cSrcweir                             sal_uInt16 nNumStart = USHRT_MAX;
562cdf0e10cSrcweir 		                    if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART_AT) )
563cdf0e10cSrcweir                             {
564cdf0e10cSrcweir                                 nNumStart = ((SfxUInt16Item&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
565cdf0e10cSrcweir                                 if(USHRT_MAX != nNumStart)
566cdf0e10cSrcweir                                     bStart = sal_False;
567cdf0e10cSrcweir                             }
568cdf0e10cSrcweir                             rWrtShell.SetNumRuleStart(bStart);
569cdf0e10cSrcweir                             rWrtShell.SetNodeNumStart(nNumStart);
570cdf0e10cSrcweir                         }
571cdf0e10cSrcweir                         else if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART_AT) )
572cdf0e10cSrcweir                         {
573cdf0e10cSrcweir                             sal_uInt16 nNumStart = ((SfxUInt16Item&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
574cdf0e10cSrcweir                             rWrtShell.SetNodeNumStart(nNumStart);
575cdf0e10cSrcweir                             rWrtShell.SetNumRuleStart(sal_False);
576cdf0e10cSrcweir                         }
577cdf0e10cSrcweir                     }
578cdf0e10cSrcweir                 }
579cdf0e10cSrcweir                 delete pTemplateItemSet;
580cdf0e10cSrcweir             }
581cdf0e10cSrcweir         }
582cdf0e10cSrcweir     }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir     if( m_pTableItemSet && nSelectionType & (nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS) )
585cdf0e10cSrcweir         lcl_setTableAttributes( *m_pTableItemSet, rWrtShell );
586cdf0e10cSrcweir 
587cdf0e10cSrcweir     rWrtShell.EndUndo(UNDO_INSATTR);
588cdf0e10cSrcweir     rWrtShell.EndAction();
589cdf0e10cSrcweir 
590cdf0e10cSrcweir     if(!m_bPersistentCopy)
591cdf0e10cSrcweir         this->Erase();
592cdf0e10cSrcweir }
593cdf0e10cSrcweir 
Erase()594cdf0e10cSrcweir void SwFormatClipboard::Erase()
595cdf0e10cSrcweir {
596cdf0e10cSrcweir     m_nSelectionType = 0;
597cdf0e10cSrcweir     if(m_pItemSet)
598cdf0e10cSrcweir     {
599cdf0e10cSrcweir         delete m_pItemSet;
600cdf0e10cSrcweir         m_pItemSet = 0;
601cdf0e10cSrcweir     }
602cdf0e10cSrcweir     if(m_pTableItemSet)
603cdf0e10cSrcweir     {
604cdf0e10cSrcweir         delete m_pTableItemSet;
605cdf0e10cSrcweir         m_pTableItemSet = 0;
606cdf0e10cSrcweir     }
607cdf0e10cSrcweir     if( m_aCharStyle.Len() )
608cdf0e10cSrcweir         m_aCharStyle.Erase();
609cdf0e10cSrcweir     if( m_aParaStyle.Len() )
610cdf0e10cSrcweir         m_aParaStyle.Erase();
611cdf0e10cSrcweir 
612cdf0e10cSrcweir     m_bPersistentCopy = false;
613cdf0e10cSrcweir }
614