xref: /aoo41x/main/sw/source/core/unocore/unoframe.cxx (revision 57326f99)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
28 #include <com/sun/star/container/XChild.hpp>
29 #include <com/sun/star/embed/XClassifiedObject.hpp>
30 #include <com/sun/star/embed/XVisualObject.hpp>
31 #include <com/sun/star/embed/XComponentSupplier.hpp>
32 #include <com/sun/star/embed/EmbedStates.hpp>
33 #include <com/sun/star/embed/Aspects.hpp>
34 #include <com/sun/star/graphic/XGraphicProvider.hpp>
35 #include <svx/svxids.hrc>
36 #include <editeng/memberids.hrc>
37 
38 #include <swtypes.hxx>
39 #include <cmdid.h>
40 
41 #include <memory>
42 #include <hints.hxx>
43 #include <doc.hxx>
44 #include <IDocumentUndoRedo.hxx>
45 #include <docsh.hxx>
46 #include <editsh.hxx>
47 #include <swcli.hxx>
48 #include <ndindex.hxx>
49 #include <pam.hxx>
50 #include <ndnotxt.hxx>
51 #include <svx/unomid.hxx>
52 #include <unocrsr.hxx>
53 #include <unocrsrhelper.hxx>
54 #include <docstyle.hxx>
55 #include <dcontact.hxx>
56 #include <fmtcnct.hxx>
57 #include <ndole.hxx>
58 #include <frmfmt.hxx>
59 #include <frame.hxx>
60 #include <unotextrange.hxx>
61 #include <unotextcursor.hxx>
62 #include <unoparagraph.hxx>
63 #include <unomap.hxx>
64 #include <unoprnms.hxx>
65 #include <unoevent.hxx>
66 #include <com/sun/star/table/BorderLine.hpp>
67 #include <com/sun/star/util/XModifyBroadcaster.hpp>
68 #include <com/sun/star/table/ShadowFormat.hpp>
69 #include <com/sun/star/style/GraphicLocation.hpp>
70 #include <com/sun/star/text/GraphicCrop.hpp>
71 #include <com/sun/star/text/TextContentAnchorType.hpp>
72 #include <com/sun/star/text/XTextColumns.hpp>
73 #include <com/sun/star/text/WrapTextMode.hpp>
74 #include <com/sun/star/beans/PropertyAttribute.hpp>
75 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
76 #include <com/sun/star/drawing/PointSequence.hpp>
77 #include <com/sun/star/drawing/ColorMode.hpp>
78 #include <tools/poly.hxx>
79 #include <swundo.hxx>
80 #include <unostyle.hxx>
81 #include <svx/svdmodel.hxx>
82 #include <svx/svdpage.hxx>
83 #include <editeng/brshitem.hxx>
84 #include <editeng/protitem.hxx>
85 #include <fmtornt.hxx>
86 #include <fmturl.hxx>
87 #include <editeng/lrspitem.hxx>
88 #include <editeng/ulspitem.hxx>
89 #include <editeng/boxitem.hxx>
90 #include <editeng/opaqitem.hxx>
91 #include <editeng/prntitem.hxx>
92 #include <editeng/shaditem.hxx>
93 #include <fmtsrnd.hxx>
94 #include <fmtfsize.hxx>
95 #include <grfatr.hxx>
96 #include <unoframe.hxx>
97 #include <fmtanchr.hxx>
98 #include <fmtclds.hxx>
99 #include <fmtcntnt.hxx>
100 #include <frmatr.hxx>
101 #include <ndtxt.hxx>
102 #include <ndgrf.hxx>
103 #include <vos/mutex.hxx>
104 #include <vcl/svapp.hxx>
105 #include <sfx2/printer.hxx>
106 //Begin Bug 119922
107 #include <sfx2/docfile.hxx>
108 #include <sfx2/docfilt.hxx>
109 //End Bug 119922
110 #include <SwStyleNameMapper.hxx>
111 #include <xmloff/xmlcnitm.hxx>
112 #include <poolfmt.hxx>
113 #include <pagedesc.hxx>
114 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
115 #include <tools/urlobj.hxx>
116 #include <editeng/frmdiritem.hxx>
117 #include <fmtfollowtextflow.hxx>
118 #include <fmtwrapinfluenceonobjpos.hxx>
119 #include <toolkit/helper/vclunohelper.hxx>
120 #include <switerator.hxx>
121 
122 // from fefly1.cxx
123 extern sal_Bool lcl_ChkAndSetNewAnchor( SwEditShell& rEditShell, const SwFlyFrm& rFly, SfxItemSet& rSet );
124 
125 using namespace ::com::sun::star;
126 using ::rtl::OUString;
127 
128 using ::com::sun::star::frame::XModel;
129 using ::com::sun::star::container::XNameAccess;
130 using ::com::sun::star::style::XStyleFamiliesSupplier;
131 
132 const sal_Char __FAR_DATA sPackageProtocol[] = "vnd.sun.star.Package:";
133 const sal_Char __FAR_DATA sGraphicObjectProtocol[] = "vnd.sun.star.GraphicObject:";
134 
135 /****************************************************************************
136 	Rahmenbeschreibung
137 ****************************************************************************/
138 class BaseFrameProperties_Impl
139 {
140     SwUnoCursorHelper::SwAnyMapHelper aAnyMap;
141 
142 public:
143     virtual ~BaseFrameProperties_Impl();
144 
145     void            SetProperty(sal_uInt16 nWID, sal_uInt8 nMemberId, const uno::Any& rVal);
146     sal_Bool        GetProperty(sal_uInt16 nWID, sal_uInt8 nMemberId, const uno::Any*& pAny );
147 //    void          GetProperty(const OUString &rPropertyName, const uno::Reference < beans::XPropertySet > &rxPropertySet, uno::Any& rAny );
148 
149 //    const SfxItemPropertyMap*       GetMap() const {return _pMap;}
150 	//Begin Bug 119922:Graphic in header and footer can not be displayed correctly.
151 	//Set default value for "Follow text flow" to false if a previous version didn't support "Follow text flow".
152 	sal_Bool                        FillBaseProperties(SfxItemSet& rToSet,
153 														const SfxItemSet &rFromSet,
154 														sal_Bool& rSizeFound,
155 														const sal_Bool bOasis = sal_False );
156 	//End Bug 119922
157 
158     virtual sal_Bool                AnyToItemSet( SwDoc* pDoc, SfxItemSet& rFrmSet, SfxItemSet& rSet, sal_Bool& rSizeFound) = 0;
159 
160 };
161 
~BaseFrameProperties_Impl()162 BaseFrameProperties_Impl::~BaseFrameProperties_Impl()
163 {
164 }
165 
SetProperty(sal_uInt16 nWID,sal_uInt8 nMemberId,const uno::Any & rVal)166 void BaseFrameProperties_Impl::SetProperty(sal_uInt16 nWID, sal_uInt8 nMemberId, const uno::Any& rVal)
167 {
168     aAnyMap.SetValue( nWID, nMemberId, rVal );
169 }
170 
GetProperty(sal_uInt16 nWID,sal_uInt8 nMemberId,const uno::Any * & rpAny)171 sal_Bool BaseFrameProperties_Impl::GetProperty(sal_uInt16 nWID, sal_uInt8 nMemberId, const uno::Any*& rpAny)
172 {
173     return aAnyMap.FillValue( nWID, nMemberId, rpAny );
174 }
175 
176 //Begin Bug 119922:Graphic in header and footer can not be displayed correctly.
177 //Set default value for "Follow text flow" to false if a previous version didn't support "Follow text flow".
FillBaseProperties(SfxItemSet & rToSet,const SfxItemSet & rFromSet,sal_Bool & rSizeFound,const sal_Bool bOasis)178 sal_Bool BaseFrameProperties_Impl::FillBaseProperties(SfxItemSet& rToSet,
179 													  const SfxItemSet& rFromSet,
180 													  sal_Bool& rSizeFound,
181 													  const sal_Bool bOasis /*sal_False*/ )
182 //End Bug 119922
183 {
184 	sal_Bool bRet = sal_True;
185 	//Anker kommt auf jeden Fall in den Set
186 	SwFmtAnchor aAnchor ( static_cast < const SwFmtAnchor & > ( rFromSet.Get ( RES_ANCHOR ) ) );
187 	{
188         const ::uno::Any* pAnchorPgNo;
189         if(GetProperty(RES_ANCHOR, MID_ANCHOR_PAGENUM, pAnchorPgNo))
190 			bRet &= ((SfxPoolItem&)aAnchor).PutValue(*pAnchorPgNo, MID_ANCHOR_PAGENUM);
191         const ::uno::Any* pAnchorType;
192         if(GetProperty(RES_ANCHOR, MID_ANCHOR_ANCHORTYPE, pAnchorType))
193 			bRet &= ((SfxPoolItem&)aAnchor).PutValue(*pAnchorType, MID_ANCHOR_ANCHORTYPE);
194 	}
195 	rToSet.Put(aAnchor);
196 	{
197         const ::uno::Any* pCol = 0;
198         GetProperty(RES_BACKGROUND, MID_BACK_COLOR, pCol );
199         const ::uno::Any* pRGBCol = 0;
200         GetProperty(RES_BACKGROUND, MID_BACK_COLOR_R_G_B, pRGBCol );
201         const ::uno::Any* pColTrans = 0;
202         GetProperty(RES_BACKGROUND, MID_BACK_COLOR_TRANSPARENCY, pColTrans);
203         const ::uno::Any* pTrans = 0;
204         GetProperty(RES_BACKGROUND, MID_GRAPHIC_TRANSPARENT, pTrans );
205         const ::uno::Any* pGrLoc = 0;
206         GetProperty(RES_BACKGROUND, MID_GRAPHIC_POSITION, pGrLoc );
207         const ::uno::Any* pGrURL = 0;
208         GetProperty(RES_BACKGROUND, MID_GRAPHIC_URL, pGrURL     );
209         const ::uno::Any* pGrFilter = 0;
210         GetProperty(RES_BACKGROUND, MID_GRAPHIC_FILTER, pGrFilter     );
211         const ::uno::Any* pGrTranparency = 0;
212         GetProperty(RES_BACKGROUND, MID_GRAPHIC_TRANSPARENCY, pGrTranparency     );
213 
214         if(pCol || pTrans || pGrURL || pGrFilter || pGrLoc ||
215                             pGrTranparency || pColTrans || pRGBCol)
216 		{
217             SvxBrushItem aBrush ( static_cast < const :: SvxBrushItem & > ( rFromSet.Get ( RES_BACKGROUND ) ) );
218 			if(pCol )
219 				bRet &= ((SfxPoolItem&)aBrush).PutValue(*pCol,MID_BACK_COLOR	);
220             if(pColTrans)
221                 bRet &= ((SfxPoolItem&)aBrush).PutValue(*pColTrans, MID_BACK_COLOR_TRANSPARENCY);
222             if(pRGBCol)
223                 bRet &= ((SfxPoolItem&)aBrush).PutValue(*pRGBCol, MID_BACK_COLOR_R_G_B);
224             if(pTrans)
225             {
226                 // don't overwrite transparency with a non-transparence flag
227                 if(!pColTrans || Any2Bool( *pTrans ))
228                     bRet &= ((SfxPoolItem&)aBrush).PutValue(*pTrans, MID_GRAPHIC_TRANSPARENT);
229             }
230             if(pGrURL)
231 				bRet &= ((SfxPoolItem&)aBrush).PutValue(*pGrURL, MID_GRAPHIC_URL);
232 			if(pGrFilter)
233 				bRet &= ((SfxPoolItem&)aBrush).PutValue(*pGrFilter, MID_GRAPHIC_FILTER);
234 			if(pGrLoc)
235 				bRet &= ((SfxPoolItem&)aBrush).PutValue(*pGrLoc, MID_GRAPHIC_POSITION);
236             if(pGrTranparency)
237                 bRet &= ((SfxPoolItem&)aBrush).PutValue(*pGrTranparency, MID_GRAPHIC_TRANSPARENCY);
238 
239             rToSet.Put(aBrush);
240 		}
241 	}
242 	{
243         const ::uno::Any* pCont = 0;
244         GetProperty(RES_PROTECT, MID_PROTECT_CONTENT, pCont );
245         const ::uno::Any* pPos = 0;
246         GetProperty(RES_PROTECT,MID_PROTECT_POSITION, pPos );
247         const ::uno::Any* pName = 0;
248         GetProperty(RES_PROTECT, MID_PROTECT_SIZE, pName );
249 		if(pCont||pPos||pName)
250 		{
251             SvxProtectItem aProt ( static_cast < const :: SvxProtectItem & > ( rFromSet.Get ( RES_PROTECT ) ) );
252 			if(pCont)
253 				bRet &= ((SfxPoolItem&)aProt).PutValue(*pCont, MID_PROTECT_CONTENT);
254 			if(pPos )
255 				bRet &= ((SfxPoolItem&)aProt).PutValue(*pPos, MID_PROTECT_POSITION);
256 			if(pName)
257 				bRet &= ((SfxPoolItem&)aProt).PutValue(*pName, MID_PROTECT_SIZE);
258 			rToSet.Put(aProt);
259 		}
260 	}
261 	{
262         const ::uno::Any* pHori  = 0;
263         GetProperty(RES_HORI_ORIENT, MID_HORIORIENT_ORIENT, pHori );
264         const ::uno::Any* pHoriP = 0;
265         GetProperty(RES_HORI_ORIENT, MID_HORIORIENT_POSITION|CONVERT_TWIPS, pHoriP );
266         const ::uno::Any* pHoriR = 0;
267         GetProperty(RES_HORI_ORIENT, MID_HORIORIENT_RELATION, pHoriR );
268         const ::uno::Any* pPageT = 0;
269         GetProperty(RES_HORI_ORIENT, MID_HORIORIENT_PAGETOGGLE, pPageT);
270 		if(pHori||pHoriP||pHoriR||pPageT)
271 		{
272             SwFmtHoriOrient aOrient ( static_cast < const :: SwFmtHoriOrient & > ( rFromSet.Get ( RES_HORI_ORIENT ) ) );
273 			if(pHori )
274 				bRet &= ((SfxPoolItem&)aOrient).PutValue(*pHori, MID_HORIORIENT_ORIENT);
275 			if(pHoriP)
276 				bRet &= ((SfxPoolItem&)aOrient).PutValue(*pHoriP, MID_HORIORIENT_POSITION|CONVERT_TWIPS);
277 			if(pHoriR)
278 				bRet &= ((SfxPoolItem&)aOrient).PutValue(*pHoriR, MID_HORIORIENT_RELATION);
279 			if(pPageT)
280 				bRet &= ((SfxPoolItem&)aOrient).PutValue(*pPageT, MID_HORIORIENT_PAGETOGGLE);
281 			rToSet.Put(aOrient);
282 		}
283 	}
284 
285 	{
286         const ::uno::Any* pVert  = 0;
287         GetProperty(RES_VERT_ORIENT, MID_VERTORIENT_ORIENT, pVert);
288         const ::uno::Any* pVertP = 0;
289         GetProperty(RES_VERT_ORIENT, MID_VERTORIENT_POSITION|CONVERT_TWIPS, pVertP );
290         const ::uno::Any* pVertR = 0;
291         GetProperty(RES_VERT_ORIENT, MID_VERTORIENT_RELATION, pVertR );
292 		if(pVert||pVertP||pVertR)
293 		{
294             SwFmtVertOrient aOrient ( static_cast < const :: SwFmtVertOrient & > ( rFromSet.Get ( RES_VERT_ORIENT ) ) );
295 			if(pVert )
296 				bRet &= ((SfxPoolItem&)aOrient).PutValue(*pVert, MID_VERTORIENT_ORIENT);
297 			if(pVertP)
298 				bRet &= ((SfxPoolItem&)aOrient).PutValue(*pVertP, MID_VERTORIENT_POSITION|CONVERT_TWIPS);
299 			if(pVertR)
300 				bRet &= ((SfxPoolItem&)aOrient).PutValue(*pVertR, MID_VERTORIENT_RELATION);
301 			rToSet.Put(aOrient);
302 		}
303 	}
304 	{
305         const ::uno::Any* pURL = 0;
306         GetProperty(RES_URL, MID_URL_URL, pURL );
307         const ::uno::Any* pTarget = 0;
308         GetProperty(RES_URL, MID_URL_TARGET, pTarget );
309         const ::uno::Any* pHyLNm = 0;
310         GetProperty(RES_URL, MID_URL_HYPERLINKNAME, pHyLNm );
311         const ::uno::Any* pHySMp = 0;
312         GetProperty(RES_URL, MID_URL_SERVERMAP, pHySMp );
313 		if(pURL||pTarget||pHyLNm||pHySMp)
314 		{
315             SwFmtURL aURL ( static_cast < const :: SwFmtURL & > ( rFromSet.Get ( RES_URL ) ) );
316 			if(pURL)
317 				bRet &= ((SfxPoolItem&)aURL).PutValue(*pURL, MID_URL_URL);
318 			if(pTarget)
319 				bRet &= ((SfxPoolItem&)aURL).PutValue(*pTarget, MID_URL_TARGET);
320 			if(pHyLNm)
321 				bRet &= ((SfxPoolItem&)aURL).PutValue(*pHyLNm, MID_URL_HYPERLINKNAME  );
322 			if(pHySMp)
323 				bRet &= ((SfxPoolItem&)aURL).PutValue(*pHySMp, MID_URL_SERVERMAP);
324 			rToSet.Put(aURL);
325 		}
326 	}
327     const ::uno::Any* pL = 0;
328     GetProperty(RES_LR_SPACE, MID_L_MARGIN|CONVERT_TWIPS, pL );
329     const ::uno::Any* pR = 0;
330     GetProperty(RES_LR_SPACE, MID_R_MARGIN|CONVERT_TWIPS, pR );
331 	if(pL||pR)
332 	{
333         SvxLRSpaceItem aLR ( static_cast < const :: SvxLRSpaceItem & > ( rFromSet.Get ( RES_LR_SPACE ) ) );
334 		if(pL)
335 			bRet &= ((SfxPoolItem&)aLR).PutValue(*pL, MID_L_MARGIN|CONVERT_TWIPS);
336 		if(pR)
337 			bRet &= ((SfxPoolItem&)aLR).PutValue(*pR, MID_R_MARGIN|CONVERT_TWIPS);
338 		rToSet.Put(aLR);
339 	}
340     const ::uno::Any* pT = 0;
341     GetProperty(RES_UL_SPACE, MID_UP_MARGIN|CONVERT_TWIPS, pT );
342     const ::uno::Any* pB = 0;
343     GetProperty(RES_UL_SPACE, MID_LO_MARGIN|CONVERT_TWIPS, pB );
344 	if(pT||pB)
345 	{
346         SvxULSpaceItem aTB ( static_cast < const :: SvxULSpaceItem &> ( rFromSet.Get ( RES_UL_SPACE ) ) );
347 		if(pT)
348 			bRet &= ((SfxPoolItem&)aTB).PutValue(*pT, MID_UP_MARGIN|CONVERT_TWIPS);
349 		if(pB)
350 			bRet &= ((SfxPoolItem&)aTB).PutValue(*pB, MID_LO_MARGIN|CONVERT_TWIPS);
351 		rToSet.Put(aTB);
352 	}
353     const ::uno::Any* pOp;
354     if(GetProperty(RES_OPAQUE, 0, pOp))
355 	{
356         SvxOpaqueItem aOp ( static_cast < const :: SvxOpaqueItem& > ( rFromSet.Get ( RES_OPAQUE ) ) );
357 		bRet &= ((SfxPoolItem&)aOp).PutValue(*pOp, 0);
358 		rToSet.Put(aOp);
359 	}
360     const ::uno::Any* pPrt;
361     if(GetProperty(RES_PRINT, 0, pPrt))
362 	{
363         SvxPrintItem aPrt ( static_cast < const :: SvxPrintItem & > ( rFromSet.Get ( RES_PRINT ) ) );
364 		bRet &= ((SfxPoolItem&)aPrt).PutValue(*pPrt, 0);
365 		rToSet.Put(aPrt);
366 	}
367     const ::uno::Any* pSh;
368     if(GetProperty(RES_SHADOW, CONVERT_TWIPS, pSh))
369 	{
370         SvxShadowItem aSh ( static_cast < const :: SvxShadowItem& > ( rFromSet.Get ( RES_SHADOW ) ) );
371 		bRet &= ((SfxPoolItem&)aSh).PutValue(*pSh, CONVERT_TWIPS);
372 		rToSet.Put(aSh);
373 	}
374     const ::uno::Any* pSur      = 0;
375     GetProperty(RES_SURROUND, MID_SURROUND_SURROUNDTYPE, pSur);
376     const ::uno::Any* pSurAnch = 0;
377     GetProperty(RES_SURROUND, MID_SURROUND_ANCHORONLY, pSurAnch);
378 	if(pSur || pSurAnch)
379 	{
380         SwFmtSurround aSrnd ( static_cast < const :: SwFmtSurround & > ( rFromSet.Get ( RES_SURROUND ) ) );
381 		if(pSur)
382 			bRet &= ((SfxPoolItem&)aSrnd).PutValue(*pSur, MID_SURROUND_SURROUNDTYPE	);
383 		if(pSurAnch)
384 			bRet &= ((SfxPoolItem&)aSrnd).PutValue(*pSurAnch, MID_SURROUND_ANCHORONLY);
385 		rToSet.Put(aSrnd);
386 	}
387     const ::uno::Any* pLeft        = 0;
388     GetProperty(RES_BOX, LEFT_BORDER  |CONVERT_TWIPS,    pLeft  );
389     const ::uno::Any* pRight       = 0;
390     GetProperty(RES_BOX, CONVERT_TWIPS|RIGHT_BORDER ,    pRight );
391     const ::uno::Any* pTop         = 0;
392     GetProperty(RES_BOX, CONVERT_TWIPS|TOP_BORDER     , pTop   );
393     const ::uno::Any* pBottom  = 0;
394     GetProperty(RES_BOX, CONVERT_TWIPS|BOTTOM_BORDER,    pBottom);
395     const ::uno::Any* pDistance    = 0;
396     GetProperty(RES_BOX, CONVERT_TWIPS|BORDER_DISTANCE,  pDistance);
397     const ::uno::Any* pLeftDistance    = 0;
398     GetProperty(RES_BOX, CONVERT_TWIPS|LEFT_BORDER_DISTANCE, pLeftDistance);
399     const ::uno::Any* pRightDistance   = 0;
400     GetProperty(RES_BOX, CONVERT_TWIPS|RIGHT_BORDER_DISTANCE,    pRightDistance);
401     const ::uno::Any* pTopDistance     = 0;
402     GetProperty(RES_BOX, CONVERT_TWIPS|TOP_BORDER_DISTANCE,  pTopDistance);
403     const ::uno::Any* pBottomDistance  = 0;
404     GetProperty(RES_BOX, CONVERT_TWIPS|BOTTOM_BORDER_DISTANCE,   pBottomDistance);
405 	if(	pLeft || pRight || pTop ||	pBottom || pDistance ||
406 		pLeftDistance  || pRightDistance || pTopDistance || pBottomDistance )
407 	{
408         SvxBoxItem aBox ( static_cast < const :: SvxBoxItem & > ( rFromSet.Get ( RES_BOX ) ) );
409 		if(	pLeft )
410 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pLeft, CONVERT_TWIPS|LEFT_BORDER );
411 		if(	pRight )
412 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pRight, CONVERT_TWIPS|RIGHT_BORDER );
413 		if(	pTop )
414 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pTop, CONVERT_TWIPS|TOP_BORDER);
415 		if(	pBottom )
416 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pBottom, CONVERT_TWIPS|BOTTOM_BORDER);
417 		if( pDistance )
418 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pDistance, CONVERT_TWIPS|BORDER_DISTANCE);
419 		if( pLeftDistance )
420 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pLeftDistance, CONVERT_TWIPS|LEFT_BORDER_DISTANCE);
421 		if( pRightDistance )
422 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pRightDistance, CONVERT_TWIPS|RIGHT_BORDER_DISTANCE);
423 		if( pTopDistance )
424 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pTopDistance, CONVERT_TWIPS|TOP_BORDER_DISTANCE);
425 		if( pBottomDistance )
426 			bRet &= ((SfxPoolItem&)aBox).PutValue(*pBottomDistance, CONVERT_TWIPS|BOTTOM_BORDER_DISTANCE);
427 		rToSet.Put(aBox);
428 	}
429 	{
430         const ::uno::Any* pRelH = 0;
431         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_REL_HEIGHT, pRelH);
432         const ::uno::Any* pRelW = 0;
433         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_REL_WIDTH, pRelW);
434         const ::uno::Any* pSyncWidth = 0;
435         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_IS_SYNC_WIDTH_TO_HEIGHT, pSyncWidth);
436         const ::uno::Any* pSyncHeight = 0;
437         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_IS_SYNC_HEIGHT_TO_WIDTH, pSyncHeight);
438         const ::uno::Any* pWidth = 0;
439         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_WIDTH|CONVERT_TWIPS, pWidth);
440         const ::uno::Any* pHeight = 0;
441         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_HEIGHT|CONVERT_TWIPS, pHeight);
442         const ::uno::Any* pSize = 0;
443         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_SIZE|CONVERT_TWIPS, pSize);
444         const ::uno::Any* pSizeType = 0;
445         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_SIZE_TYPE, pSizeType);
446         const ::uno::Any* pWidthType = 0;
447         GetProperty(RES_FRM_SIZE, MID_FRMSIZE_WIDTH_TYPE, pWidthType);
448         if( pWidth || pHeight ||pRelH || pRelW || pSize ||pSizeType ||
449 			pWidthType ||pSyncWidth || pSyncHeight )
450 		{
451             rSizeFound = sal_True;
452             SwFmtFrmSize aFrmSz ( static_cast < const :: SwFmtFrmSize& > ( rFromSet.Get ( RES_FRM_SIZE ) ) );
453 			if(pWidth)
454 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pWidth, MID_FRMSIZE_WIDTH|CONVERT_TWIPS);
455 			if(pHeight)
456 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pHeight, MID_FRMSIZE_HEIGHT|CONVERT_TWIPS);
457 			if(pRelH )
458 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pRelH, MID_FRMSIZE_REL_HEIGHT);
459 			if(pRelW )
460 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pRelW, MID_FRMSIZE_REL_WIDTH);
461 			if(pSyncWidth)
462 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pSyncWidth, MID_FRMSIZE_IS_SYNC_WIDTH_TO_HEIGHT);
463 			if(pSyncHeight)
464 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pSyncHeight, MID_FRMSIZE_IS_SYNC_HEIGHT_TO_WIDTH);
465 			if(pSize)
466 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pSize, MID_FRMSIZE_SIZE|CONVERT_TWIPS);
467 			if(pSizeType)
468 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pSizeType, MID_FRMSIZE_SIZE_TYPE);
469 			if(pWidthType)
470 				bRet &= ((SfxPoolItem&)aFrmSz).PutValue(*pWidthType, MID_FRMSIZE_WIDTH_TYPE);
471 			if(!aFrmSz.GetWidth())
472 				aFrmSz.SetWidth(MINFLY);
473 			if(!aFrmSz.GetHeight())
474 				aFrmSz.SetHeight(MINFLY);
475 			rToSet.Put(aFrmSz);
476 		}
477 		else
478 		{
479             rSizeFound = sal_False;
480             SwFmtFrmSize aFrmSz;
481 			awt::Size aSize;
482             aSize.Width = 2 * MM50;
483             aSize.Height = 2 * MM50;
484             ::uno::Any aSizeVal;
485 			aSizeVal <<= aSize;
486 			((SfxPoolItem&)aFrmSz).PutValue(aSizeVal, MID_FRMSIZE_SIZE|CONVERT_TWIPS);
487 			rToSet.Put(aFrmSz);
488 		}
489 	}
490     const ::uno::Any* pFrameDirection = 0;
491     GetProperty(RES_FRAMEDIR, 0, pFrameDirection);
492     if(pFrameDirection)
493     {
494         SvxFrameDirectionItem aAttr(FRMDIR_HORI_LEFT_TOP, RES_FRAMEDIR);
495         aAttr.PutValue(*pFrameDirection, 0);
496         rToSet.Put(aAttr);
497     }
498     const ::uno::Any* pUnknown = 0;
499     GetProperty(RES_UNKNOWNATR_CONTAINER, 0, pUnknown);
500     if(pUnknown)
501     {
502         SvXMLAttrContainerItem aAttr(RES_UNKNOWNATR_CONTAINER);
503         aAttr.PutValue(*pUnknown, 0);
504         rToSet.Put(aAttr);
505     }
506 
507     // DVO, OD 01.10.2003 #i18732#
508     const ::uno::Any* pFollowTextFlow = 0;
509     GetProperty(RES_FOLLOW_TEXT_FLOW, 0, pFollowTextFlow);
510     if ( pFollowTextFlow )
511     {
512         SwFmtFollowTextFlow aFmtFollowTextFlow;
513         aFmtFollowTextFlow.PutValue(*pFollowTextFlow, 0);
514         rToSet.Put(aFmtFollowTextFlow);
515     }
516     //Begin Bug 119922
517     else if ( bOasis )
518         rToSet.Put( SwFmtFollowTextFlow() );
519     //End Bug 119922
520 
521     // OD 2004-05-04 #i28701# - RES_WRAP_INFLUENCE_ON_OBJPOS
522     const ::uno::Any* pWrapInfluenceOnObjPos = 0;
523     GetProperty(RES_WRAP_INFLUENCE_ON_OBJPOS, MID_WRAP_INFLUENCE, pWrapInfluenceOnObjPos);
524     if ( pWrapInfluenceOnObjPos )
525     {
526         SwFmtWrapInfluenceOnObjPos aFmtWrapInfluenceOnObjPos;
527         aFmtWrapInfluenceOnObjPos.PutValue( *pWrapInfluenceOnObjPos, MID_WRAP_INFLUENCE );
528         rToSet.Put(aFmtWrapInfluenceOnObjPos);
529     }
530 
531 	return bRet;
532 }
533 
534 class SwFrameProperties_Impl : public BaseFrameProperties_Impl
535 {
536 public:
537     SwFrameProperties_Impl();
~SwFrameProperties_Impl()538     virtual ~SwFrameProperties_Impl(){}
539 
540     virtual sal_Bool        AnyToItemSet( SwDoc* pDoc, SfxItemSet& rFrmSet, SfxItemSet& rSet, sal_Bool& rSizeFound);
541 };
542 
SwFrameProperties_Impl()543 SwFrameProperties_Impl::SwFrameProperties_Impl():
544     BaseFrameProperties_Impl(/*aSwMapProvider.GetPropertyMap(PROPERTY_MAP_TEXT_FRAME)*/ )
545 {
546 }
547 
lcl_FillCol(SfxItemSet & rToSet,const::SfxItemSet & rFromSet,const::uno::Any * pAny)548 inline void lcl_FillCol ( SfxItemSet &rToSet, const :: SfxItemSet &rFromSet, const :: uno::Any *pAny)
549 {
550 	if ( pAny )
551 	{
552         SwFmtCol aCol ( static_cast < const :: SwFmtCol & > ( rFromSet.Get ( RES_COL ) ) );
553 		((SfxPoolItem&)aCol).PutValue( *pAny, MID_COLUMNS);
554 		rToSet.Put(aCol);
555 	}
556 }
AnyToItemSet(SwDoc * pDoc,SfxItemSet & rSet,SfxItemSet &,sal_Bool & rSizeFound)557 sal_Bool    SwFrameProperties_Impl::AnyToItemSet(SwDoc *pDoc, SfxItemSet& rSet, SfxItemSet&, sal_Bool& rSizeFound)
558 {
559 	//Properties fuer alle Frames
560     const ::uno::Any *pStyleName;
561 	SwDocStyleSheet* pStyle = NULL;
562 	sal_Bool bRet;
563 
564 	if ( GetProperty ( FN_UNO_FRAME_STYLE_NAME, 0, pStyleName ) )
565 	{
566 		OUString sStyle;
567 		*pStyleName >>= sStyle;
568 		pStyle = (SwDocStyleSheet*)pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle,
569 													SFX_STYLE_FAMILY_FRAME);
570 	}
571 
572     const ::uno::Any* pColumns = NULL;
573     GetProperty (RES_COL, MID_COLUMNS, pColumns);
574     if ( pStyle )
575     {
576 		rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *pStyle ) );
577         const :: SfxItemSet *pItemSet = &xStyle->GetItemSet();
578    		bRet = FillBaseProperties( rSet, *pItemSet, rSizeFound );
579 		lcl_FillCol ( rSet, *pItemSet, pColumns );
580     }
581 	else
582 	{
583         const :: SfxItemSet *pItemSet = &pDoc->GetFrmFmtFromPool( RES_POOLFRM_FRAME )->GetAttrSet();
584    		bRet = FillBaseProperties( rSet, *pItemSet, rSizeFound );
585 		lcl_FillCol ( rSet, *pItemSet, pColumns );
586 	}
587     const ::uno::Any* pEdit;
588     if(GetProperty(RES_EDIT_IN_READONLY, 0, pEdit))
589 	{
590 		SfxBoolItem aBool(RES_EDIT_IN_READONLY);
591 		((SfxPoolItem&)aBool).PutValue(*pEdit, 0);
592 		rSet.Put(aBool);
593 	}
594 	return bRet;
595 }
596 /****************************************************************************
597 	Grafik-Descriptor
598 ****************************************************************************/
599 class SwGraphicProperties_Impl : public BaseFrameProperties_Impl
600 {
601 public:
602 	SwGraphicProperties_Impl();
~SwGraphicProperties_Impl()603     virtual ~SwGraphicProperties_Impl(){}
604 
605     virtual sal_Bool                AnyToItemSet( SwDoc* pDoc, SfxItemSet& rFrmSet, SfxItemSet& rSet, sal_Bool& rSizeFound);
606 };
607 
SwGraphicProperties_Impl()608 SwGraphicProperties_Impl::SwGraphicProperties_Impl( ) :
609     BaseFrameProperties_Impl(/*aSwMapProvider.GetPropertyMap(PROPERTY_MAP_TEXT_GRAPHIC)*/ )
610 {
611 }
612 
613 
lcl_FillMirror(SfxItemSet & rToSet,const::SfxItemSet & rFromSet,const::uno::Any * pHEvenMirror,const::uno::Any * pHOddMirror,const::uno::Any * pVMirror,sal_Bool & rRet)614 inline void lcl_FillMirror ( SfxItemSet &rToSet, const :: SfxItemSet &rFromSet, const ::uno::Any *pHEvenMirror, const ::uno::Any *pHOddMirror, const ::uno::Any *pVMirror, sal_Bool &rRet )
615 {
616 	if(pHEvenMirror || pHOddMirror || pVMirror )
617 	{
618         SwMirrorGrf aMirror ( static_cast < const :: SwMirrorGrf& > ( rFromSet.Get ( RES_GRFATR_MIRRORGRF ) ) );
619 		if(pHEvenMirror)
620 			rRet &= ((SfxPoolItem&)aMirror).PutValue(*pHEvenMirror, MID_MIRROR_HORZ_EVEN_PAGES);
621 		if(pHOddMirror)
622 			rRet &= ((SfxPoolItem&)aMirror).PutValue(*pHOddMirror, MID_MIRROR_HORZ_ODD_PAGES);
623 		if(pVMirror)
624 			rRet &= ((SfxPoolItem&)aMirror).PutValue(*pVMirror, MID_MIRROR_VERT);
625 		rToSet.Put(aMirror);
626 	}
627 }
628 
AnyToItemSet(SwDoc * pDoc,SfxItemSet & rFrmSet,SfxItemSet & rGrSet,sal_Bool & rSizeFound)629 sal_Bool 	SwGraphicProperties_Impl::AnyToItemSet(
630 			SwDoc* pDoc,
631 			SfxItemSet& rFrmSet,
632             SfxItemSet& rGrSet,
633             sal_Bool& rSizeFound)
634 {
635 	//Properties fuer alle Frames
636 	sal_Bool bRet;
637     const ::uno::Any *pStyleName;
638 	SwDocStyleSheet* pStyle = NULL;
639 
640 	if ( GetProperty ( FN_UNO_FRAME_STYLE_NAME, 0, pStyleName ) )
641 	{
642 		OUString sStyle;
643 		*pStyleName >>= sStyle;
644 		pStyle = (SwDocStyleSheet*)pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle,
645 													SFX_STYLE_FAMILY_FRAME);
646 	}
647 
648     const ::uno::Any* pHEvenMirror = 0;
649     const ::uno::Any* pHOddMirror = 0;
650     const ::uno::Any* pVMirror = 0;
651     GetProperty(RES_GRFATR_MIRRORGRF, MID_MIRROR_HORZ_EVEN_PAGES, pHEvenMirror);
652     GetProperty(RES_GRFATR_MIRRORGRF, MID_MIRROR_HORZ_ODD_PAGES, pHOddMirror);
653     GetProperty(RES_GRFATR_MIRRORGRF, MID_MIRROR_VERT, pVMirror);
654 
655     if ( pStyle )
656     {
657         rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet(*pStyle) );
658         const :: SfxItemSet *pItemSet = &xStyle->GetItemSet();
659         //Begin Bug 119922
660         sal_Bool bOasis = sal_False;
661         {
662             const SfxMedium* pMedium = pDoc->GetDocShell()->GetMedium();
663             const SfxFilter * pFilter = pMedium
664                 ? pMedium->GetFilter()
665                 : NULL;
666             if ( pMedium && pFilter )
667             {
668                 bOasis = pFilter->GetVersion() > SOFFICE_FILEFORMAT_60;
669             }
670         }
671         bRet = FillBaseProperties( rFrmSet, *pItemSet, rSizeFound, bOasis );
672         //End Bug 119922
673         lcl_FillMirror ( rGrSet, *pItemSet, pHEvenMirror, pHOddMirror, pVMirror, bRet );
674     }
675     else
676     {
677         const :: SfxItemSet *pItemSet = &pDoc->GetFrmFmtFromPool( RES_POOLFRM_GRAPHIC )->GetAttrSet();
678         bRet = FillBaseProperties(rFrmSet, *pItemSet, rSizeFound);
679         lcl_FillMirror ( rGrSet, *pItemSet, pHEvenMirror, pHOddMirror, pVMirror, bRet );
680     }
681 
682 
683     static const :: sal_uInt16 nIDs[] =
684 	{
685 		RES_GRFATR_CROPGRF,
686 		RES_GRFATR_ROTATION,
687 		RES_GRFATR_LUMINANCE,
688 		RES_GRFATR_CONTRAST,
689 		RES_GRFATR_CHANNELR,
690 		RES_GRFATR_CHANNELG,
691 		RES_GRFATR_CHANNELB,
692 		RES_GRFATR_GAMMA,
693 		RES_GRFATR_INVERT,
694 		RES_GRFATR_TRANSPARENCY,
695 		RES_GRFATR_DRAWMODE,
696 		0
697 	};
698     const ::uno::Any* pAny;
699 	for(sal_Int16 nIndex = 0; nIDs[nIndex]; nIndex++)
700 	{
701 		sal_uInt8 nMId = RES_GRFATR_CROPGRF == nIDs[nIndex] ? CONVERT_TWIPS : 0;
702         if(GetProperty(nIDs[nIndex], nMId, pAny ))
703 		{
704 			SfxPoolItem* pItem = ::GetDfltAttr( nIDs[nIndex] )->Clone();
705             bRet &= pItem->PutValue(*pAny, nMId );
706 			rGrSet.Put(*pItem);
707 			delete pItem;
708 		}
709 	}
710 
711 	return bRet;
712 }
713 
714 class SwOLEProperties_Impl : public SwFrameProperties_Impl
715 {
716 public:
SwOLEProperties_Impl()717     SwOLEProperties_Impl() :
718         SwFrameProperties_Impl(/*aSwMapProvider.GetPropertyMap(PROPERTY_MAP_EMBEDDED_OBJECT)*/ ){}
~SwOLEProperties_Impl()719     virtual ~SwOLEProperties_Impl(){}
720 
721     virtual sal_Bool        AnyToItemSet( SwDoc* pDoc, SfxItemSet& rFrmSet, SfxItemSet& rSet, sal_Bool& rSizeFound);
722 };
723 
AnyToItemSet(SwDoc * pDoc,SfxItemSet & rFrmSet,SfxItemSet & rSet,sal_Bool & rSizeFound)724 sal_Bool  SwOLEProperties_Impl::AnyToItemSet(
725         SwDoc* pDoc, SfxItemSet& rFrmSet, SfxItemSet& rSet, sal_Bool& rSizeFound)
726 {
727     const ::uno::Any* pTemp;
728     if(!GetProperty(FN_UNO_CLSID, 0, pTemp) && !GetProperty(FN_UNO_STREAM_NAME, 0, pTemp) )
729         return sal_False;
730     SwFrameProperties_Impl::AnyToItemSet( pDoc, rFrmSet, rSet, rSizeFound);
731     //
732     return sal_True;
733 }
734 
735 /******************************************************************
736  *	SwXFrame
737  ******************************************************************/
738 
getUnoTunnelId()739 const :: uno::Sequence< sal_Int8 > & SwXFrame::getUnoTunnelId()
740 {
741     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
742 	return aSeq;
743 }
744 
getSomething(const::uno::Sequence<sal_Int8> & rId)745 sal_Int64 SAL_CALL SwXFrame::getSomething( const :: uno::Sequence< sal_Int8 >& rId )
746 	throw(uno::RuntimeException)
747 {
748     if( rId.getLength() == 16
749         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
750 										rId.getConstArray(), 16 ) )
751     {
752 		return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
753     }
754 	return 0;
755 }
756 
757 TYPEINIT1(SwXFrame, SwClient);
758 
getImplementationName(void)759 OUString SwXFrame::getImplementationName(void) throw( uno::RuntimeException )
760 {
761 	return C2U("SwXFrame");
762 }
763 
supportsService(const::OUString & rServiceName)764 sal_Bool SwXFrame::supportsService(const :: OUString& rServiceName) throw( uno::RuntimeException )
765 {
766 	return !rServiceName.compareToAscii("com.sun.star.text.BaseFrame")||
767 				!rServiceName.compareToAscii("com.sun.star.text.TextContent") ||
768 					!rServiceName.compareToAscii("com.sun.star.document.LinkTarget");
769 }
770 
getSupportedServiceNames(void)771 uno::Sequence< OUString > SwXFrame::getSupportedServiceNames(void) throw( uno::RuntimeException )
772 {
773 	uno::Sequence< OUString > aRet(3);
774 	OUString* pArray = aRet.getArray();
775 	pArray[0] = C2U("com.sun.star.text.BaseFrame");
776 	pArray[1] = C2U("com.sun.star.text.TextContent");
777 	pArray[2] = C2U("com.sun.star.document.LinkTarget");
778 	return aRet;
779 }
780 
781 
SwXFrame(FlyCntType eSet,const::SfxItemPropertySet * pSet,SwDoc * pDoc)782 SwXFrame::SwXFrame(FlyCntType eSet, const :: SfxItemPropertySet* pSet, SwDoc *pDoc) :
783 	aLstnrCntnr( (container::XNamed*)this),
784     m_pPropSet(pSet),
785     m_pDoc ( pDoc ),
786     eType(eSet),
787 	bIsDescriptor(sal_True),
788     m_pCopySource( 0 )
789 {
790 	// Register ourselves as a listener to the document (via the page descriptor)
791     pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
792 	// get the property set for the default style data
793 	// First get the model
794 	uno::Reference < XModel > xModel = pDoc->GetDocShell()->GetBaseModel();
795 	// Ask the model for it's family supplier interface
796 	uno::Reference < XStyleFamiliesSupplier > xFamilySupplier ( xModel, uno::UNO_QUERY );
797 	// Get the style families
798 	uno::Reference < XNameAccess > xFamilies = xFamilySupplier->getStyleFamilies();
799 	// Get the Frame family (and keep it for later)
800     const ::uno::Any aAny = xFamilies->getByName ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "FrameStyles" ) ) );
801 	aAny >>= mxStyleFamily;
802 	// In the derived class, we'll ask mxStyleFamily for the relevant default style
803 	// mxStyleFamily is initialised in the SwXFrame constructor
804 	switch(eType)
805 	{
806 		case FLYCNTTYPE_FRM:
807 		{
808             uno::Any aAny2 = mxStyleFamily->getByName ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Frame" ) ) );
809 			aAny2 >>= mxStyleData;
810 			pProps = new SwFrameProperties_Impl( );
811 		}
812 		break;
813 		case FLYCNTTYPE_GRF:
814 		{
815             uno::Any aAny2 = mxStyleFamily->getByName ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Graphics" ) ) );
816 			aAny2 >>= mxStyleData;
817 			pProps = new SwGraphicProperties_Impl( );
818 		}
819 		break;
820 		case FLYCNTTYPE_OLE:
821 		{
822 			uno::Any aAny2 = mxStyleFamily->getByName ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "OLE" ) ) );
823 			aAny2 >>= mxStyleData;
824             pProps = new SwOLEProperties_Impl( );
825         }
826 		break;
827 
828 		default:
829 			;
830 	}
831 }
832 
833 
SwXFrame(SwFrmFmt & rFrmFmt,FlyCntType eSet,const::SfxItemPropertySet * pSet)834 SwXFrame::SwXFrame(SwFrmFmt& rFrmFmt, FlyCntType eSet, const :: SfxItemPropertySet* pSet) :
835     SwClient( &rFrmFmt ),
836 	aLstnrCntnr( (container::XNamed*)this),
837     m_pPropSet(pSet),
838     m_pDoc( 0 ),
839     eType(eSet),
840     pProps(0),
841 	bIsDescriptor(sal_False),
842     m_pCopySource(0)
843 {
844 
845 }
846 
~SwXFrame()847 SwXFrame::~SwXFrame()
848 {
849     delete m_pCopySource;
850     delete pProps;
851 }
852 
getName(void)853 OUString SwXFrame::getName(void) throw( uno::RuntimeException )
854 {
855 	vos::OGuard aGuard(Application::GetSolarMutex());
856 	String sRet;
857 	SwFrmFmt* pFmt = GetFrmFmt();
858 	if(pFmt)
859 		sRet = pFmt->GetName();
860 	else if(bIsDescriptor)
861 		sRet = sName;
862 	else
863 		throw uno::RuntimeException();
864 	return sRet;
865 }
866 
setName(const::OUString & rName)867 void SwXFrame::setName(const :: OUString& rName) throw( uno::RuntimeException )
868 {
869 	vos::OGuard aGuard(Application::GetSolarMutex());
870 	SwFrmFmt* pFmt = GetFrmFmt();
871 	String sTmpName(rName);
872 	if(pFmt)
873 	{
874 		pFmt->GetDoc()->SetFlyName((SwFlyFrmFmt&)*pFmt, sTmpName);
875 		if(pFmt->GetName() != sTmpName)
876 		{
877 			throw uno::RuntimeException();
878 		}
879 	}
880 	else if(bIsDescriptor)
881 		sName = sTmpName;
882 	else
883 		throw uno::RuntimeException();
884 }
885 
getPropertySetInfo(void)886 uno::Reference< beans::XPropertySetInfo >  SwXFrame::getPropertySetInfo(void) throw( uno::RuntimeException )
887 {
888 	uno::Reference< beans::XPropertySetInfo >  xRef;
889 	static uno::Reference< beans::XPropertySetInfo >  xFrmRef;
890 	static uno::Reference< beans::XPropertySetInfo >  xGrfRef;
891 	static uno::Reference< beans::XPropertySetInfo >  xOLERef;
892 	switch(eType)
893 	{
894 	case FLYCNTTYPE_FRM:
895 		if( !xFrmRef.is() )
896             xFrmRef = m_pPropSet->getPropertySetInfo();
897 		xRef = xFrmRef;
898 		break;
899 	case FLYCNTTYPE_GRF:
900 		if( !xGrfRef.is() )
901             xGrfRef = m_pPropSet->getPropertySetInfo();
902 		xRef = xGrfRef;
903 		break;
904 	case FLYCNTTYPE_OLE:
905 		if( !xOLERef.is() )
906             xOLERef = m_pPropSet->getPropertySetInfo();
907 		xRef = xOLERef;
908 		break;
909 	default:
910 		;
911 	}
912 	return xRef;
913 }
914 
SetSelection(SwPaM & rCopySource)915 void SwXFrame::SetSelection(SwPaM& rCopySource)
916 {
917     if(m_pCopySource)
918         delete m_pCopySource;
919     m_pCopySource = new SwPaM( *rCopySource.Start() );
920     m_pCopySource->SetMark();
921     *m_pCopySource->GetMark() = *rCopySource.End();
922 }
923 
GetOrCreateSdrObject(SwFlyFrmFmt * pFmt)924 SdrObject *SwXFrame::GetOrCreateSdrObject( SwFlyFrmFmt *pFmt )
925 {
926 	SdrObject* pObject = pFmt->FindSdrObject();
927 	if( !pObject )
928 	{
929 		SwDoc *pDoc = pFmt->GetDoc();
930         // --> OD 2005-08-08 #i52858# - method name changed
931         SdrModel *pDrawModel = pDoc->GetOrCreateDrawModel();
932         // <--
933 		SwFlyDrawContact* pContactObject
934 					= new SwFlyDrawContact( pFmt, pDrawModel );
935 		pObject = pContactObject->GetMaster();
936 
937         const :: SwFmtSurround& rSurround = pFmt->GetSurround();
938 		pObject->SetLayer(
939 			( SURROUND_THROUGHT == rSurround.GetSurround() &&
940 			  !pFmt->GetOpaque().GetValue() ) ? pDoc->GetHellId()
941 											 : pDoc->GetHeavenId() );
942 
943 		pDrawModel->GetPage(0)->InsertObject( pObject );
944 	}
945 
946 	return pObject;
947 }
948 
lcl_GetFrmFmt(const::uno::Any & rValue,SwDoc * pDoc)949 SwFrmFmt *lcl_GetFrmFmt( const :: uno::Any& rValue, SwDoc *pDoc )
950 {
951 	SwFrmFmt *pRet = 0;
952 	SwDocShell* pDocSh = pDoc->GetDocShell();
953 	if(pDocSh)
954 	{
955 		OUString uTemp;
956 		rValue >>= uTemp;
957 		String sStyle;
958 		SwStyleNameMapper::FillUIName(String (uTemp), sStyle, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT, sal_True );
959 		SwDocStyleSheet* pStyle =
960 				(SwDocStyleSheet*)pDocSh->GetStyleSheetPool()->Find(sStyle,
961 													SFX_STYLE_FAMILY_FRAME);
962 		if(pStyle)
963 			pRet = pStyle->GetFrmFmt();
964 	}
965 
966 	return pRet;
967 }
968 
setPropertyValue(const::OUString & rPropertyName,const::uno::Any & aValue)969 void SwXFrame::setPropertyValue(const :: OUString& rPropertyName, const :: uno::Any& aValue)
970 	throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
971 {
972 	vos::OGuard aGuard(Application::GetSolarMutex());
973 	SwFrmFmt* pFmt = GetFrmFmt();
974     const :: SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
975 
976     if (!pEntry)
977         throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
978 
979     if(pFmt)
980 	{
981 		sal_Bool bNextFrame = sal_False;
982         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
983             throw beans::PropertyVetoException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
984 
985 		SwDoc* pDoc = pFmt->GetDoc();
986         if ((eType == FLYCNTTYPE_GRF) && isGRFATR(pEntry->nWID) ||
987             (FN_PARAM_COUNTOUR_PP        == pEntry->nWID) ||
988             (FN_UNO_IS_AUTOMATIC_CONTOUR == pEntry->nWID) ||
989             (FN_UNO_IS_PIXEL_CONTOUR     == pEntry->nWID) )
990 		{
991             const :: SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
992 			if(pIdx)
993 			{
994 				SwNodeIndex aIdx(*pIdx, 1);
995 				SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
996                 if(pEntry->nWID == FN_PARAM_COUNTOUR_PP)
997 				{
998 					drawing::PointSequenceSequence aParam;
999 					if(!aValue.hasValue())
1000 						pNoTxt->SetContour(0);
1001 					else if(aValue >>= aParam)
1002 					{
1003 						PolyPolygon aPoly((sal_uInt16)aParam.getLength());
1004 						for(sal_Int32 i = 0; i < aParam.getLength(); i++)
1005 						{
1006                             const :: drawing::PointSequence* pPointSeq = aParam.getConstArray();
1007 							sal_Int32 nPoints = pPointSeq[i].getLength();
1008                             const :: awt::Point* pPoints = pPointSeq[i].getConstArray();
1009 							Polygon aSet( (sal_uInt16)nPoints );
1010 							for(sal_Int32 j = 0; j < nPoints; j++)
1011 							{
1012 								Point aPoint(pPoints[j].X, pPoints[j].Y);
1013 								aSet.SetPoint(aPoint, (sal_uInt16)j);
1014 							}
1015 							// Close polygon if it isn't closed already.
1016 							aSet.Optimize( POLY_OPTIMIZE_CLOSE );
1017 						    aPoly.Insert( aSet );
1018 						}
1019 						pNoTxt->SetContourAPI( &aPoly );
1020 					}
1021 					else
1022 						throw lang::IllegalArgumentException();
1023 				}
1024                 else if(pEntry->nWID == FN_UNO_IS_AUTOMATIC_CONTOUR )
1025 				{
1026 					pNoTxt->SetAutomaticContour( *(sal_Bool *)aValue.getValue() );
1027 				}
1028                 else if(pEntry->nWID == FN_UNO_IS_PIXEL_CONTOUR )
1029 				{
1030 					// The IsPixelContour property can only be set if there
1031 					// is no contour, or if the contour has been set by the
1032 					// API itself (or in other words, if the contour isn't
1033 					// used already).
1034 					if( !pNoTxt->_HasContour() ||
1035 						!pNoTxt->IsContourMapModeValid() )
1036 						pNoTxt->SetPixelContour( *(sal_Bool *)aValue.getValue() );
1037 					else
1038 						throw lang::IllegalArgumentException();
1039 				}
1040 				else
1041 				{
1042 					SfxItemSet aSet(pNoTxt->GetSwAttrSet());
1043                     m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
1044 					pNoTxt->SetAttr(aSet);
1045 				}
1046 			}
1047 		}
1048         // New attribute Title
1049         else if( FN_UNO_TITLE == pEntry->nWID )
1050         {
1051             SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(pFmt);
1052             ASSERT( pFmt,
1053                     "unexpected type of <pFmt> --> crash" );
1054             OUString uTemp;
1055             aValue >>= uTemp;
1056             const String sTitle(uTemp);
1057             // assure that <SdrObject> instance exists.
1058             GetOrCreateSdrObject( pFlyFmt );
1059             pFlyFmt->GetDoc()->SetFlyFrmTitle( *(pFlyFmt), sTitle );
1060         }
1061         // New attribute Description
1062         else if( FN_UNO_DESCRIPTION == pEntry->nWID )
1063         {
1064             SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(pFmt);
1065             ASSERT( pFmt,
1066                     "unexpected type of <pFmt> --> crash" );
1067             OUString uTemp;
1068             aValue >>= uTemp;
1069             const String sDescription(uTemp);
1070             // assure that <SdrObject> instance exists.
1071             GetOrCreateSdrObject( pFlyFmt );
1072             pFlyFmt->GetDoc()->SetFlyFrmDescription( *(pFlyFmt), sDescription );
1073         }
1074         // <--
1075         else if(FN_UNO_FRAME_STYLE_NAME == pEntry->nWID)
1076 		{
1077 			SwFrmFmt *pFrmFmt = lcl_GetFrmFmt( aValue, pFmt->GetDoc() );
1078 			if( pFrmFmt )
1079 			{
1080                 UnoActionContext aAction(pFmt->GetDoc());
1081 
1082                 SfxItemSet* pSet = 0;
1083                 // --> OD 2004-08-13 #i31771#, #i25798# - No adjustment of
1084                 // anchor ( no call of method <::lcl_ChkAndSetNewAnchor(..)> ),
1085                 // if document is currently in reading mode.
1086                 if ( !pFmt->GetDoc()->IsInReading() )
1087                 {
1088                     // see SwFEShell::SetFrmFmt( SwFrmFmt *pNewFmt, sal_Bool bKeepOrient, Point* pDocPos )
1089                     SwFlyFrm *pFly = 0;
1090                     {
1091                         const :: SwFrmFmt* pFmtXX = pFmt;
1092                         if (PTR_CAST(SwFlyFrmFmt, pFmtXX))
1093                             pFly = ((SwFlyFrmFmt*)pFmtXX)->GetFrm();
1094                     }
1095                     if ( pFly )
1096                     {
1097                         const :: SfxPoolItem* pItem;
1098                         if( SFX_ITEM_SET == pFrmFmt->GetItemState( RES_ANCHOR, sal_False, &pItem ))
1099                         {
1100                             pSet = new SfxItemSet( pDoc->GetAttrPool(), aFrmFmtSetRange );
1101                             pSet->Put( *pItem );
1102                             if ( pFmt->GetDoc()->GetEditShell() != NULL
1103                                  && !::lcl_ChkAndSetNewAnchor( *(pFmt->GetDoc()->GetEditShell()), *pFly, *pSet ) )
1104                                 delete pSet, pSet = 0;
1105                         }
1106                     }
1107                 }
1108                 // <--
1109 
1110                 pFmt->GetDoc()->SetFrmFmtToFly( *pFmt, *pFrmFmt, pSet, sal_False );
1111 				delete pSet;
1112 			}
1113 			else
1114 				throw lang::IllegalArgumentException();
1115 		}
1116         else if( FN_UNO_GRAPHIC_U_R_L == pEntry->nWID ||
1117                 FN_UNO_GRAPHIC_FILTER == pEntry->nWID)
1118 		{
1119 			String sGrfName, sFltName;
1120 			GraphicObject *pGrfObj = 0;
1121 			pFmt->GetDoc()->GetGrfNms( *(SwFlyFrmFmt*)pFmt, &sGrfName, &sFltName );
1122 			OUString uTemp;
1123 			aValue >>= uTemp;
1124 			String sTmp(uTemp);
1125 			UnoActionContext aAction(pFmt->GetDoc());
1126             if(FN_UNO_GRAPHIC_U_R_L == pEntry->nWID)
1127 			{
1128 				if( sTmp.EqualsAscii( sPackageProtocol,
1129 									  0, sizeof( sPackageProtocol )-1 ) )
1130 				{
1131 					pGrfObj = new GraphicObject;
1132 					pGrfObj->SetUserData( sTmp );
1133 					pGrfObj->SetSwapState();
1134 					sGrfName.Erase();
1135 				}
1136 				else if( sTmp.EqualsAscii( sGraphicObjectProtocol,
1137 										   0, sizeof(sGraphicObjectProtocol)-1 ) )
1138 				{
1139 					ByteString sId( sTmp.Copy(sizeof(sGraphicObjectProtocol)-1),
1140 									RTL_TEXTENCODING_ASCII_US );
1141 					pGrfObj = new GraphicObject( sId );
1142 					sGrfName.Erase();
1143 				}
1144 				else
1145 				{
1146 					sGrfName = sTmp;
1147 				}
1148 			}
1149 			else
1150 			{
1151 				sFltName = sTmp;
1152 			}
1153 
1154             const :: SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1155 			if(pIdx)
1156 			{
1157 				SwNodeIndex aIdx(*pIdx, 1);
1158 //				SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
1159 				SwGrfNode* pGrfNode = aIdx.GetNode().GetGrfNode();
1160 				if(!pGrfNode)
1161 				{
1162 					delete pGrfObj;
1163 					throw uno::RuntimeException();
1164 				}
1165 				SwPaM aGrfPaM(*pGrfNode);
1166 				pFmt->GetDoc()->ReRead( aGrfPaM, sGrfName, sFltName, 0,
1167 										pGrfObj );
1168 			}
1169 			delete pGrfObj;
1170 		}
1171         else if( FN_UNO_GRAPHIC == pEntry->nWID )
1172         {
1173             uno::Reference< graphic::XGraphic > xGraphic;
1174             aValue >>= xGraphic;
1175             if(xGraphic.is())
1176             {
1177                 const :: SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1178                 if(pIdx)
1179                 {
1180                     SwNodeIndex aIdx(*pIdx, 1);
1181                     SwGrfNode* pGrfNode = aIdx.GetNode().GetGrfNode();
1182                     if(!pGrfNode)
1183                     {
1184                         throw uno::RuntimeException();
1185                     }
1186                     SwPaM aGrfPaM(*pGrfNode);
1187                     Graphic aGraphic( xGraphic );
1188                     pFmt->GetDoc()->ReRead( aGrfPaM, String(), String(), &aGraphic, 0 );
1189                 }
1190             }
1191         }
1192         else if( FN_UNO_REPLACEMENT_GRAPHIC_URL == pEntry->nWID || FN_UNO_REPLACEMENT_GRAPHIC == pEntry->nWID )
1193 		{
1194             bool bURL = FN_UNO_REPLACEMENT_GRAPHIC_URL == pEntry->nWID;
1195             bool bApply = false;
1196             Graphic aGraphic;
1197             if( bURL )
1198             {
1199                 GraphicObject *pGrfObj = 0;
1200                 OUString aGrfUrl;
1201                 aValue >>= aGrfUrl;
1202 
1203                 // the package URL based graphics are handled in different way currently
1204                 // TODO/LATER: actually this is the correct place to handle them
1205                 ::rtl::OUString aGraphicProtocol( RTL_CONSTASCII_USTRINGPARAM( sGraphicObjectProtocol ) );
1206                 if( aGrfUrl.compareTo( aGraphicProtocol, aGraphicProtocol.getLength() ) == 0 )
1207                 {
1208                     ByteString sId( aGrfUrl.copy(sizeof(sGraphicObjectProtocol)-1).getStr(), RTL_TEXTENCODING_ASCII_US );
1209                     pGrfObj = new GraphicObject( sId );
1210                     aGraphic = pGrfObj->GetGraphic();
1211                     bApply = true;
1212                 }
1213             }
1214             else
1215             {
1216                 uno::Reference< graphic::XGraphic > xGraphic;
1217                 aValue >>= xGraphic;
1218                 if( xGraphic.is() )
1219                 {
1220                     aGraphic = Graphic( xGraphic );
1221                     bApply = true;
1222                 }
1223             }
1224 
1225             if ( bApply )
1226 			{
1227                 const :: SwFmtCntnt* pCnt = &pFmt->GetCntnt();
1228             	if ( pCnt->GetCntntIdx() && pDoc->GetNodes()[ pCnt->GetCntntIdx()->GetIndex() + 1 ] )
1229 				{
1230             		SwOLENode* pOleNode =  pDoc->GetNodes()[ pCnt->GetCntntIdx()->GetIndex() + 1 ]->GetOLENode();
1231 
1232 					if ( pOleNode )
1233 					{
1234             			svt::EmbeddedObjectRef xObj = pOleNode->GetOLEObj().GetObject();
1235 
1236 						::rtl::OUString aMediaType;
1237                         xObj.SetGraphic( aGraphic, aMediaType );
1238 					}
1239 				}
1240 			}
1241 		}
1242 		else if(0 != (bNextFrame = (rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_CHAIN_NEXT_NAME))))
1243 			|| rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_CHAIN_PREV_NAME)))
1244 		{
1245 			OUString uTemp;
1246 			aValue >>= uTemp;
1247 			String sChainName(uTemp);
1248 			if(!sChainName.Len())
1249 			{
1250 				if(bNextFrame)
1251 					pDoc->Unchain(*pFmt);
1252 				else
1253 				{
1254 					SwFmtChain aChain( pFmt->GetChain() );
1255 					SwFrmFmt *pPrev = aChain.GetPrev();
1256 					if(pPrev)
1257 						pDoc->Unchain(*pPrev);
1258 				}
1259 			}
1260 			else
1261 			{
1262 				sal_uInt16 nCount = pDoc->GetFlyCount(FLYCNTTYPE_FRM);
1263 
1264 				SwFrmFmt* pChain = 0;
1265 				for( sal_uInt16 i = 0; i < nCount; i++)
1266 				{
1267 					SwFrmFmt* pFmt2 = pDoc->GetFlyNum(i, FLYCNTTYPE_FRM);
1268 					if(sChainName == pFmt2->GetName() )
1269 					{
1270 						pChain = pFmt2;
1271 						break;
1272 					}
1273 				}
1274 				if(pChain)
1275 				{
1276 					SwFrmFmt* pSource = bNextFrame ? pFmt : pChain;
1277 					SwFrmFmt* pDest = bNextFrame ? pChain: pFmt;
1278 					pDoc->Chain(*pSource, *pDest);
1279 				}
1280 			}
1281 		}
1282         else if(FN_UNO_Z_ORDER == pEntry->nWID)
1283 		{
1284 			sal_Int32 nZOrder = - 1;
1285 			aValue >>= nZOrder;
1286 			if( nZOrder >= 0)
1287 			{
1288 				SdrObject* pObject =
1289 					GetOrCreateSdrObject( (SwFlyFrmFmt*)pFmt );
1290 				SdrModel *pDrawModel = pDoc->GetDrawModel();
1291 				pDrawModel->GetPage(0)->
1292 							SetObjectOrdNum(pObject->GetOrdNum(), nZOrder);
1293 			}
1294 		}
1295         else if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORFRAME == pEntry->nMemberId)
1296         {
1297             sal_Bool bDone = sal_False;
1298             uno::Reference<text::XTextFrame> xFrame;
1299             if(aValue >>= xFrame)
1300             {
1301                 uno::Reference<lang::XUnoTunnel> xTunnel(xFrame, uno::UNO_QUERY);
1302                 SwXFrame* pFrame = xTunnel.is() ?
1303                         reinterpret_cast< SwXFrame * >( sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SwXFrame::getUnoTunnelId()) ))
1304 						: 0;
1305                 if(pFrame && this != pFrame && pFrame->GetFrmFmt() && pFrame->GetFrmFmt()->GetDoc() == pDoc)
1306                 {
1307                     SfxItemSet aSet( pDoc->GetAttrPool(),
1308                                 RES_FRMATR_BEGIN, RES_FRMATR_END - 1 );
1309                     aSet.SetParent(&pFmt->GetAttrSet());
1310                     SwFmtAnchor aAnchor = (const :: SwFmtAnchor&)aSet.Get(pEntry->nWID);
1311 
1312 
1313                     SwPosition aPos(*pFrame->GetFrmFmt()->GetCntnt().GetCntntIdx());
1314                     aAnchor.SetAnchor(&aPos);
1315                     aAnchor.SetType(FLY_AT_FLY);
1316                     aSet.Put(aAnchor);
1317                     pDoc->SetFlyFrmAttr( *pFmt, aSet );
1318                     bDone = sal_True;
1319                 }
1320             }
1321             if(!bDone)
1322                 throw lang::IllegalArgumentException();
1323         }
1324 		else
1325 		{
1326 			SfxItemSet aSet( pDoc->GetAttrPool(),
1327 				RES_FRMATR_BEGIN, RES_FRMATR_END - 1,
1328 				RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
1329 				0L);
1330 
1331 			aSet.SetParent(&pFmt->GetAttrSet());
1332             m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
1333             if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
1334             {
1335                 SwFmtAnchor aAnchor = (const :: SwFmtAnchor&)aSet.Get(pEntry->nWID);
1336                 if(aAnchor.GetAnchorId() == FLY_AT_FLY)
1337                 {
1338                     const :: SwPosition* pPosition = aAnchor.GetCntntAnchor();
1339                     SwFrmFmt* pFlyFmt = pPosition ? pPosition->nNode.GetNode().GetFlyFmt() : 0;
1340                     if(!pFlyFmt || pFlyFmt->Which() == RES_DRAWFRMFMT)
1341                     {
1342                         lang::IllegalArgumentException aExcept;
1343                         aExcept.Message = C2U("Anchor to frame: no frame found");
1344                         throw aExcept;
1345                     }
1346 					else
1347 					{
1348                         SwPosition aPos = *pPosition;
1349                         aPos.nNode = *pFlyFmt->GetCntnt().GetCntntIdx();
1350                         aAnchor.SetAnchor(&aPos);
1351                         aSet.Put(aAnchor);
1352 					}
1353                 }
1354                 else if ((aAnchor.GetAnchorId() != FLY_AT_PAGE) &&
1355                          !aAnchor.GetCntntAnchor())
1356                 {
1357                     SwNode& rNode = pDoc->GetNodes().GetEndOfContent();
1358                     SwPaM aPam(rNode);
1359                     aPam.Move( fnMoveBackward, fnGoDoc );
1360                     aAnchor.SetAnchor( aPam.Start() );
1361                     aSet.Put(aAnchor);
1362                 }
1363 
1364                 // --> OD 2004-08-13 #i31771#, #i25798# - No adjustment of
1365                 // anchor ( no call of method <::lcl_ChkAndSetNewAnchor(..)> ),
1366                 // if document is currently in reading mode.
1367                 if ( !pFmt->GetDoc()->IsInReading() )
1368                 {
1369                     // see SwFEShell::SetFlyFrmAttr( SfxItemSet& rSet )
1370                     SwFlyFrm *pFly = 0;
1371                     if (PTR_CAST(SwFlyFrmFmt, pFmt))
1372                         pFly = ((SwFlyFrmFmt*)pFmt)->GetFrm();
1373                     if (pFly)
1374                     {
1375                         const :: SfxPoolItem* pItem;
1376                         if( SFX_ITEM_SET == aSet.GetItemState( RES_ANCHOR, sal_False, &pItem ))
1377                         {
1378                             aSet.Put( *pItem );
1379                             if ( pFmt->GetDoc()->GetEditShell() != NULL )
1380                             {
1381                                 ::lcl_ChkAndSetNewAnchor( *(pFmt->GetDoc()->GetEditShell()), *pFly, aSet );
1382                             }
1383                         }
1384                     }
1385                 }
1386                 // <--
1387 
1388                 pFmt->GetDoc()->SetFlyFrmAttr( *pFmt, aSet );
1389             }
1390             else if(FN_UNO_CLSID == pEntry->nWID || FN_UNO_STREAM_NAME == pEntry->nWID)
1391             {
1392                 throw lang::IllegalArgumentException();
1393             }
1394 			else
1395                 pFmt->SetFmtAttr(aSet);
1396 		}
1397 	}
1398 	else if(IsDescriptor())
1399 	{
1400         pProps->SetProperty(pEntry->nWID, pEntry->nMemberId, aValue);
1401         if( FN_UNO_FRAME_STYLE_NAME == pEntry->nWID )
1402         {
1403             OUString sStyleName;
1404             aValue >>= sStyleName;
1405             try
1406             {
1407                 uno::Any aAny = mxStyleFamily->getByName ( sStyleName );
1408                 aAny >>= mxStyleData;
1409             }
1410             catch ( container::NoSuchElementException const & )
1411             {
1412             }
1413             catch ( lang::WrappedTargetException const  & )
1414             {
1415             }
1416             catch ( uno::RuntimeException const & )
1417             {
1418             }
1419         }
1420     }
1421 	else
1422 		throw uno::RuntimeException();
1423 }
1424 
getPropertyValue(const OUString & rPropertyName)1425 uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName)
1426 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1427 {
1428 	vos::OGuard aGuard(Application::GetSolarMutex());
1429 	uno::Any aAny;
1430 	SwFrmFmt* pFmt = GetFrmFmt();
1431     const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1432     if (!pEntry)
1433         throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1434 
1435     if(FN_UNO_ANCHOR_TYPES == pEntry->nWID)
1436 	{
1437 		uno::Sequence<text::TextContentAnchorType> aTypes(5);
1438 	 	text::TextContentAnchorType* pArray = aTypes.getArray();
1439 		pArray[0] = text::TextContentAnchorType_AT_PARAGRAPH;
1440 		pArray[1] = text::TextContentAnchorType_AS_CHARACTER;
1441 		pArray[2] = text::TextContentAnchorType_AT_PAGE;
1442 		pArray[3] = text::TextContentAnchorType_AT_FRAME;
1443 		pArray[4] = text::TextContentAnchorType_AT_CHARACTER;
1444 		aAny.setValue(&aTypes, ::getCppuType(static_cast<uno::Sequence<text::TextContentAnchorType>*>(0)));
1445 	}
1446 	else if(pFmt)
1447 	{
1448         if( ((eType == FLYCNTTYPE_GRF) || (eType == FLYCNTTYPE_OLE)) &&
1449                 pEntry &&
1450                 (isGRFATR(pEntry->nWID) ||
1451                         pEntry->nWID == FN_PARAM_COUNTOUR_PP ||
1452                         pEntry->nWID == FN_UNO_IS_AUTOMATIC_CONTOUR ||
1453                         pEntry->nWID == FN_UNO_IS_PIXEL_CONTOUR ))
1454 		{
1455             const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1456 			if(pIdx)
1457 			{
1458 				SwNodeIndex aIdx(*pIdx, 1);
1459 				SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
1460                 if(pEntry->nWID == FN_PARAM_COUNTOUR_PP)
1461 				{
1462 					PolyPolygon aContour;
1463 					if( pNoTxt->GetContourAPI( aContour ) )
1464 					{
1465 						drawing::PointSequenceSequence aPtSeq(aContour.Count());
1466 						drawing::PointSequence* pPSeq = aPtSeq.getArray();
1467 						for(sal_uInt16 i = 0; i < aContour.Count(); i++)
1468 						{
1469                             const Polygon& rPoly = aContour.GetObject(i);
1470 							pPSeq[i].realloc(rPoly.GetSize());
1471 							awt::Point* pPoints = pPSeq[i].getArray();
1472 							for(sal_uInt16 j = 0; j < rPoly.GetSize(); j++)
1473 							{
1474                                 const Point& rPoint = rPoly.GetPoint(j);
1475 								pPoints[j].X = rPoint.X();
1476 								pPoints[j].Y = rPoint.Y();
1477 							}
1478 						}
1479 						aAny <<= aPtSeq;
1480 					}
1481 				}
1482                 else if(pEntry->nWID == FN_UNO_IS_AUTOMATIC_CONTOUR )
1483 				{
1484 					sal_Bool bValue = pNoTxt->HasAutomaticContour();
1485 					aAny.setValue( &bValue, ::getBooleanCppuType() );
1486 				}
1487                 else if(pEntry->nWID == FN_UNO_IS_PIXEL_CONTOUR )
1488 				{
1489 					sal_Bool bValue = pNoTxt->IsPixelContour();
1490 					aAny.setValue( &bValue, ::getBooleanCppuType() );
1491 				}
1492 				else
1493 				{
1494 					SfxItemSet aSet(pNoTxt->GetSwAttrSet());
1495                     m_pPropSet->getPropertyValue(*pEntry, aSet, aAny);
1496 				}
1497 			}
1498 		}
1499         else if( FN_UNO_GRAPHIC_U_R_L == pEntry->nWID)
1500         {
1501             String sGrfName;
1502             const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1503             if ( pIdx )
1504             {
1505                 SwNodeIndex aIdx( *pIdx, 1 );
1506                 SwGrfNode* pGrfNode = aIdx.GetNode().GetGrfNode();
1507                 if ( !pGrfNode )
1508                     throw uno::RuntimeException();
1509                 if ( pGrfNode->IsGrfLink() )
1510                 {
1511                     pFmt->GetDoc()->GetGrfNms( *(SwFlyFrmFmt*) pFmt, &sGrfName, 0 );
1512                 }
1513                 else
1514                 {
1515                     String sPrefix( RTL_CONSTASCII_STRINGPARAM( sGraphicObjectProtocol ) );
1516                     String sId( pGrfNode->GetGrfObj().GetUniqueID(),
1517                     RTL_TEXTENCODING_ASCII_US );
1518                     ( sGrfName = sPrefix ) += sId;
1519                 }
1520             }
1521             aAny <<= OUString( sGrfName );
1522         }
1523         else if( FN_UNO_REPLACEMENT_GRAPHIC_U_R_L == pEntry->nWID)
1524         {
1525             String sGrfName;
1526             const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1527 
1528             if(pIdx)
1529             {
1530                 SwNodeIndex aIdx(*pIdx, 1);
1531                 SwGrfNode* pGrfNode = aIdx.GetNode().GetGrfNode();
1532                 if(!pGrfNode)
1533                     throw uno::RuntimeException();
1534 
1535                 const GraphicObject* pGraphicObject = pGrfNode->GetReplacementGrfObj();
1536 
1537                 if(pGraphicObject)
1538                 {
1539                     String sPrefix( RTL_CONSTASCII_STRINGPARAM(sGraphicObjectProtocol) );
1540                     String sId( pGraphicObject->GetUniqueID(), RTL_TEXTENCODING_ASCII_US );
1541                     (sGrfName = sPrefix) += sId;
1542                 }
1543             }
1544 
1545             aAny <<= OUString(sGrfName);
1546         }
1547         else if( FN_UNO_GRAPHIC_FILTER == pEntry->nWID )
1548 		{
1549 			String sFltName;
1550 			pFmt->GetDoc()->GetGrfNms( *(SwFlyFrmFmt*)pFmt, 0, &sFltName );
1551 				aAny <<= OUString(sFltName);
1552 		}
1553         else if( FN_UNO_GRAPHIC == pEntry->nWID )
1554         {
1555             const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1556             if(pIdx)
1557             {
1558                 SwNodeIndex aIdx(*pIdx, 1);
1559                 SwGrfNode* pGrfNode = aIdx.GetNode().GetGrfNode();
1560                 if(!pGrfNode)
1561                     throw uno::RuntimeException();
1562                 aAny <<= pGrfNode->GetGrf().GetXGraphic();
1563             }
1564         }
1565         else if(FN_UNO_FRAME_STYLE_NAME == pEntry->nWID)
1566 		{
1567 			aAny <<= OUString(SwStyleNameMapper::GetProgName(pFmt->DerivedFrom()->GetName(), nsSwGetPoolIdFromName::GET_POOLID_FRMFMT ) );
1568 		}
1569         // --> OD 2009-07-13 #i73249#
1570         // Attribute AlternativeText was never published.
1571         // Now it has been replaced by Attribute Title - valid for all <SwXFrame> instances
1572 //        else if(eType != FLYCNTTYPE_FRM &&
1573 //                FN_UNO_ALTERNATIVE_TEXT == pEntry->nWID)
1574 //        {
1575 //            const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1576 //            if(pIdx)
1577 //            {
1578 //                SwNodeIndex aIdx(*pIdx, 1);
1579 //                SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
1580 //                aAny <<= OUString(pNoTxt->GetAlternateText());
1581 //            }
1582 //        }
1583         else if( FN_UNO_TITLE == pEntry->nWID )
1584         {
1585             SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(pFmt);
1586             ASSERT( pFmt,
1587                     "unexpected type of <pFmt> --> crash" );
1588             // assure that <SdrObject> instance exists.
1589             GetOrCreateSdrObject( pFlyFmt );
1590             aAny <<= OUString(pFlyFmt->GetObjTitle());
1591         }
1592         // New attribute Description
1593         else if( FN_UNO_DESCRIPTION == pEntry->nWID )
1594         {
1595             SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(pFmt);
1596             ASSERT( pFmt,
1597                     "unexpected type of <pFmt> --> crash" );
1598             // assure that <SdrObject> instance exists.
1599             GetOrCreateSdrObject( pFlyFmt );
1600             aAny <<= OUString(pFlyFmt->GetObjDescription());
1601         }
1602         // <--
1603 		else if(eType == FLYCNTTYPE_GRF &&
1604 				(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_ACTUAL_SIZE))))
1605 		{
1606             const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1607 			if(pIdx)
1608 			{
1609 				SwNodeIndex aIdx(*pIdx, 1);
1610                 // --> OD #i85105#
1611 //                SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
1612 //                Size aActSize = ((SwGrfNode*)pNoTxt)->GetTwipSize();
1613                 Size aActSize;
1614                 {
1615                     SwGrfNode* pGrfNode = dynamic_cast<SwGrfNode*>(aIdx.GetNode().GetNoTxtNode());
1616                     if ( pGrfNode )
1617                     {
1618                         aActSize = pGrfNode->GetTwipSize();
1619                         if ( aActSize.Width() == 0 && aActSize.Height() == 0 &&
1620                              pGrfNode->IsLinkedFile() )
1621                         {
1622                             pGrfNode->SwapIn( sal_True );
1623                             aActSize = pGrfNode->GetTwipSize();
1624                         }
1625                     }
1626                 }
1627                 // <--
1628                 awt::Size aTmp;
1629                 aTmp.Width = TWIP_TO_MM100(aActSize.Width());
1630                 aTmp.Height = TWIP_TO_MM100(aActSize.Height());
1631                 aAny.setValue(&aTmp, ::getCppuType(static_cast<const awt::Size*>(0)));
1632 			}
1633 		}
1634         else if(FN_PARAM_LINK_DISPLAY_NAME == pEntry->nWID)
1635 		{
1636 			aAny <<= OUString(pFmt->GetName());
1637 		}
1638         else if(FN_UNO_Z_ORDER == pEntry->nWID)
1639 		{
1640             const SdrObject* pObj = pFmt->FindRealSdrObject();
1641 			if( pObj )
1642 			{
1643 				aAny <<= (sal_Int32)pObj->GetOrdNum();
1644 			}
1645 		}
1646         else if(FN_UNO_CLSID == pEntry->nWID || FN_UNO_MODEL == pEntry->nWID||
1647                 FN_UNO_COMPONENT == pEntry->nWID ||FN_UNO_STREAM_NAME == pEntry->nWID||
1648                 FN_EMBEDDED_OBJECT == pEntry->nWID)
1649         {
1650             SwDoc* pDoc = pFmt->GetDoc();
1651             const SwFmtCntnt* pCnt = &pFmt->GetCntnt();
1652             DBG_ASSERT( pCnt->GetCntntIdx() &&
1653                            pDoc->GetNodes()[ pCnt->GetCntntIdx()->
1654                                             GetIndex() + 1 ]->GetOLENode(), "kein OLE-Node?");
1655 
1656             SwOLENode* pOleNode =  pDoc->GetNodes()[ pCnt->GetCntntIdx()
1657                                             ->GetIndex() + 1 ]->GetOLENode();
1658             uno::Reference < embed::XEmbeddedObject > xIP = pOleNode->GetOLEObj().GetOleRef();
1659             OUString aHexCLSID;
1660             {
1661                 SvGlobalName aClassName( xIP->getClassID() );
1662                 aHexCLSID = aClassName.GetHexName();
1663                 if(FN_UNO_CLSID != pEntry->nWID)
1664                 {
1665                     if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
1666                     {
1667                         uno::Reference < lang::XComponent > xComp( xIP->getComponent(), uno::UNO_QUERY );
1668                         uno::Reference < frame::XModel > xModel( xComp, uno::UNO_QUERY );
1669                         if ( FN_EMBEDDED_OBJECT == pEntry->nWID )
1670                         {
1671                             // ensure the
1672                             ASSERT( pDoc->GetDocShell(), "no doc shell => no client site" );
1673                             if ( pDoc->GetDocShell() )
1674                                 pDoc->GetDocShell()->GetIPClient( svt::EmbeddedObjectRef( xIP, embed::Aspects::MSOLE_CONTENT ) );
1675                             aAny <<= xIP;
1676                         }
1677                         else if ( xModel.is() )
1678                             aAny <<= xModel;
1679                         else if ( FN_UNO_COMPONENT == pEntry->nWID )
1680                             aAny <<= xComp;
1681                     }
1682                 }
1683             }
1684 
1685             if(FN_UNO_CLSID == pEntry->nWID)
1686                 aAny <<= aHexCLSID;
1687             else if(FN_UNO_STREAM_NAME == pEntry->nWID)
1688             {
1689                 aAny <<= ::rtl::OUString(pOleNode->GetOLEObj().GetCurrentPersistName());
1690             }
1691         }
1692         else if(WID_LAYOUT_SIZE == pEntry->nWID)
1693 		{
1694             // format document completely in order to get correct value
1695             pFmt->GetDoc()->GetEditShell()->CalcLayout();
1696 
1697             SwFrm* pTmpFrm = SwIterator<SwFrm,SwFmt>::FirstElement( *pFmt );
1698             if ( pTmpFrm )
1699             {
1700                 DBG_ASSERT( pTmpFrm->IsValid(), "frame not valid" );
1701                 const SwRect &rRect = pTmpFrm->Frm();
1702                 Size aMM100Size = OutputDevice::LogicToLogic(
1703                         Size( rRect.Width(), rRect.Height() ),
1704                         MapMode( MAP_TWIP ), MapMode( MAP_100TH_MM ));
1705                 aAny <<= awt::Size( aMM100Size.Width(), aMM100Size.Height() );
1706             }
1707 		}
1708 		else
1709 		{
1710             const SwAttrSet& rSet = pFmt->GetAttrSet();
1711             m_pPropSet->getPropertyValue(*pEntry, rSet, aAny);
1712 		}
1713 	}
1714 	else if(IsDescriptor())
1715 	{
1716         if ( ! m_pDoc )
1717 			throw uno::RuntimeException();
1718         if(WID_LAYOUT_SIZE != pEntry->nWID)  // there is no LayoutSize in a descriptor
1719 		{
1720             const uno::Any* pAny = 0;
1721             if( !pProps->GetProperty( pEntry->nWID, pEntry->nMemberId, pAny ) )
1722                 aAny = mxStyleData->getPropertyValue( rPropertyName );
1723 			else if ( pAny )
1724 				aAny = *pAny;
1725 		}
1726 	}
1727 	else
1728 		throw uno::RuntimeException();
1729 	return aAny;
1730 }
1731 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1732 void SwXFrame::addPropertyChangeListener(const OUString& /*PropertyName*/,
1733     const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
1734 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1735 {
1736 	DBG_WARNING("not implemented");
1737 }
1738 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1739 void SwXFrame::removePropertyChangeListener(const OUString& /*PropertyName*/,
1740     const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
1741 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1742 {
1743 	DBG_WARNING("not implemented");
1744 }
1745 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1746 void SwXFrame::addVetoableChangeListener(const OUString& /*PropertyName*/,
1747                                 const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
1748 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1749 {
1750 	DBG_WARNING("not implemented");
1751 }
1752 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1753 void SwXFrame::removeVetoableChangeListener(
1754     const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
1755 		throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1756 {
1757 	DBG_WARNING("not implemented");
1758 }
1759 
getPropertyState(const OUString & rPropertyName)1760 beans::PropertyState SwXFrame::getPropertyState( const OUString& rPropertyName )
1761 	throw(beans::UnknownPropertyException, uno::RuntimeException)
1762 {
1763 	vos::OGuard aGuard(Application::GetSolarMutex());
1764 	uno::Sequence< OUString > aPropertyNames(1);
1765 	OUString* pNames = aPropertyNames.getArray();
1766 	pNames[0] = rPropertyName;
1767 	uno::Sequence< beans::PropertyState > aStates = getPropertyStates(aPropertyNames);
1768 	return aStates.getConstArray()[0];
1769 }
1770 
getPropertyStates(const uno::Sequence<OUString> & aPropertyNames)1771 uno::Sequence< beans::PropertyState > SwXFrame::getPropertyStates(
1772     const uno::Sequence< OUString >& aPropertyNames )
1773 		throw(beans::UnknownPropertyException, uno::RuntimeException)
1774 {
1775 	vos::OGuard aGuard(Application::GetSolarMutex());
1776 	uno::Sequence< beans::PropertyState > aStates(aPropertyNames.getLength());
1777 	beans::PropertyState* pStates = aStates.getArray();
1778 	SwFrmFmt* pFmt = GetFrmFmt();
1779 	if(pFmt)
1780 	{
1781         const OUString* pNames = aPropertyNames.getConstArray();
1782         const SwAttrSet& rFmtSet = pFmt->GetAttrSet();
1783 		for(int i = 0; i < aPropertyNames.getLength(); i++)
1784 		{
1785             const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(pNames[i]);
1786             if (!pEntry)
1787 				throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pNames[i], static_cast < cppu::OWeakObject * > ( this ) );
1788 
1789             if(pEntry->nWID == FN_UNO_ANCHOR_TYPES||
1790                 pEntry->nWID == FN_PARAM_LINK_DISPLAY_NAME||
1791                 FN_UNO_FRAME_STYLE_NAME == pEntry->nWID||
1792                 FN_UNO_GRAPHIC_U_R_L == pEntry->nWID||
1793                 FN_UNO_GRAPHIC_FILTER     == pEntry->nWID||
1794                 FN_UNO_ACTUAL_SIZE == pEntry->nWID||
1795                 FN_UNO_ALTERNATIVE_TEXT == pEntry->nWID)
1796             {
1797 				pStates[i] = beans::PropertyState_DIRECT_VALUE;
1798             }
1799             else
1800             {
1801                 if ((eType == FLYCNTTYPE_GRF) &&
1802                         pEntry && isGRFATR(pEntry->nWID))
1803                 {
1804                     const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1805 					if(pIdx)
1806 					{
1807 						SwNodeIndex aIdx(*pIdx, 1);
1808 						SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
1809 						SfxItemSet aSet(pNoTxt->GetSwAttrSet());
1810                         aSet.GetItemState(pEntry->nWID);
1811                         if(SFX_ITEM_SET == aSet.GetItemState( pEntry->nWID, sal_False ))
1812 							pStates[i] = beans::PropertyState_DIRECT_VALUE;
1813 					}
1814 				}
1815 				else
1816 				{
1817                     if(SFX_ITEM_SET == rFmtSet.GetItemState( pEntry->nWID, sal_False ))
1818 						pStates[i] = beans::PropertyState_DIRECT_VALUE;
1819 					else
1820 						pStates[i] = beans::PropertyState_DEFAULT_VALUE;
1821 				}
1822 			}
1823 		}
1824 	}
1825 	else if(IsDescriptor())
1826 	{
1827 		for(int i = 0; i < aPropertyNames.getLength(); i++)
1828 			pStates[i] = beans::PropertyState_DIRECT_VALUE;
1829 	}
1830 	else
1831 		throw uno::RuntimeException();
1832 	return aStates;
1833 }
1834 
setPropertyToDefault(const OUString & rPropertyName)1835 void SwXFrame::setPropertyToDefault( const OUString& rPropertyName )
1836 	throw(beans::UnknownPropertyException, uno::RuntimeException)
1837 {
1838 	vos::OGuard aGuard(Application::GetSolarMutex());
1839 	SwFrmFmt* pFmt = GetFrmFmt();
1840 	if(pFmt)
1841 	{
1842         const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1843         if (!pEntry)
1844 			throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1845         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
1846             throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "setPropertyToDefault: property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1847 
1848 		sal_Bool bNextFrame;
1849         if( pEntry->nWID &&
1850             pEntry->nWID != FN_UNO_ANCHOR_TYPES &&
1851             pEntry->nWID != FN_PARAM_LINK_DISPLAY_NAME)
1852         {
1853             if ( (eType == FLYCNTTYPE_GRF) && isGRFATR(pEntry->nWID) )
1854             {
1855                 const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1856 				if(pIdx)
1857 				{
1858 					SwNodeIndex aIdx(*pIdx, 1);
1859 					SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
1860 					{
1861 						SfxItemSet aSet(pNoTxt->GetSwAttrSet());
1862                         aSet.ClearItem(pEntry->nWID);
1863 						pNoTxt->SetAttr(aSet);
1864 					}
1865 				}
1866 			}
1867             // --> OD 2009-07-13 #i73249#
1868             // Attribute AlternativeText was never published.
1869             // Now it has been replaced by Attribute Title - valid for all <SwXFrame> instances
1870 //            else if( eType != FLYCNTTYPE_FRM && FN_UNO_ALTERNATIVE_TEXT == pEntry->nWID )
1871 //            {
1872 //                const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
1873 //                if(pIdx)
1874 //                {
1875 //                    SwNodeIndex aIdx(*pIdx, 1);
1876 //                    SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
1877 //                    pNoTxt->SetAlternateText(aEmptyStr);
1878 //                }
1879 //            }
1880             // New attribute Title
1881             else if( FN_UNO_TITLE == pEntry->nWID )
1882             {
1883                 SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(pFmt);
1884                 ASSERT( pFmt,
1885                         "unexpected type of <pFmt> --> crash" );
1886                 // assure that <SdrObject> instance exists.
1887                 GetOrCreateSdrObject( pFlyFmt );
1888                 pFlyFmt->GetDoc()->SetFlyFrmTitle( *(pFlyFmt), aEmptyStr );
1889             }
1890             // New attribute Description
1891             else if( FN_UNO_DESCRIPTION == pEntry->nWID )
1892             {
1893                 SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(pFmt);
1894                 ASSERT( pFmt,
1895                         "unexpected type of <pFmt> --> crash" );
1896                 // assure that <SdrObject> instance exists.
1897                 GetOrCreateSdrObject( pFlyFmt );
1898                 pFlyFmt->GetDoc()->SetFlyFrmDescription( *(pFlyFmt), aEmptyStr );
1899             }
1900             // <--
1901 			else
1902 			{
1903 				SwDoc* pDoc = pFmt->GetDoc();
1904 				SfxItemSet aSet( pDoc->GetAttrPool(),
1905 					RES_FRMATR_BEGIN, RES_FRMATR_END - 1 );
1906 				aSet.SetParent(&pFmt->GetAttrSet());
1907                 aSet.ClearItem(pEntry->nWID);
1908 				if(!rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_ANCHOR_TYPE)))
1909                     pFmt->SetFmtAttr(aSet);
1910 			}
1911 		}
1912 		else if(0 != (bNextFrame = (rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_CHAIN_NEXT_NAME))))
1913 				|| rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_CHAIN_PREV_NAME)))
1914 		{
1915 			SwDoc* pDoc = pFmt->GetDoc();
1916 			if(bNextFrame)
1917 				pDoc->Unchain(*pFmt);
1918 			else
1919 			{
1920 				SwFmtChain aChain( pFmt->GetChain() );
1921 				SwFrmFmt *pPrev = aChain.GetPrev();
1922 				if(pPrev)
1923 					pDoc->Unchain(*pPrev);
1924 			}
1925 		}
1926 	}
1927 	else if(!IsDescriptor())
1928 		throw uno::RuntimeException();
1929 
1930 }
1931 
getPropertyDefault(const OUString & rPropertyName)1932 uno::Any SwXFrame::getPropertyDefault( const OUString& rPropertyName )
1933 	throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1934 {
1935 	vos::OGuard aGuard(Application::GetSolarMutex());
1936 	uno::Any aRet;
1937 	SwFrmFmt* pFmt = GetFrmFmt();
1938 	if(pFmt)
1939 	{
1940         const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1941         if(pEntry)
1942 		{
1943             if ( pEntry->nWID < RES_FRMATR_END )
1944 			{
1945                 const SfxPoolItem& rDefItem =
1946                     pFmt->GetDoc()->GetAttrPool().GetDefaultItem(pEntry->nWID);
1947                 rDefItem.QueryValue(aRet, pEntry->nMemberId);
1948 			}
1949 		}
1950 		else
1951         	throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1952 	}
1953 	else if(!IsDescriptor())
1954 		throw uno::RuntimeException();
1955 	return aRet;
1956 }
1957 
addEventListener(const uno::Reference<lang::XEventListener> & aListener)1958 void SwXFrame::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
1959 {
1960 	if(!GetRegisteredIn())
1961 		throw uno::RuntimeException();
1962 	aLstnrCntnr.AddListener(aListener);
1963 }
1964 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)1965 void SwXFrame::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
1966 {
1967 	if(!GetRegisteredIn() || !aLstnrCntnr.RemoveListener(aListener))
1968 		throw uno::RuntimeException();
1969 }
1970 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)1971 void 	SwXFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
1972 {
1973 	ClientModify(this, pOld, pNew);
1974 	if(!GetRegisteredIn())
1975 	{
1976 		mxStyleData.clear();
1977 		mxStyleFamily.clear();
1978         m_pDoc = 0;
1979 		aLstnrCntnr.Disposing();
1980 	}
1981 }
1982 
1983 
dispose(void)1984 void SwXFrame::dispose(void) throw( uno::RuntimeException )
1985 {
1986 	vos::OGuard aGuard(Application::GetSolarMutex());
1987 	SwFrmFmt* pFmt = GetFrmFmt();
1988     if ( pFmt )
1989 	{
1990         SdrObject* pObj = pFmt->FindSdrObject();
1991         // OD 11.09.2003 #112039# - add condition to perform delete of
1992         // format/anchor sign, not only if the object is inserted, but also
1993         // if a contact object is registered, which isn't in the destruction.
1994         if ( pObj &&
1995              ( pObj->IsInserted() ||
1996                ( pObj->GetUserCall() &&
1997                  !static_cast<SwContact*>(pObj->GetUserCall())->IsInDTOR() ) ) )
1998         {
1999             if (pFmt->GetAnchor().GetAnchorId() == FLY_AS_CHAR)
2000             {
2001                 const SwPosition &rPos = *(pFmt->GetAnchor().GetCntntAnchor());
2002 				SwTxtNode *pTxtNode = rPos.nNode.GetNode().GetTxtNode();
2003                 const xub_StrLen nIdx = rPos.nContent.GetIndex();
2004                 pTxtNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx, nIdx );
2005             }
2006 			else
2007 				pFmt->GetDoc()->DelLayoutFmt(pFmt);
2008         }
2009 	}
2010 
2011 }
2012 
getAnchor(void)2013 uno::Reference< text::XTextRange >  SwXFrame::getAnchor(void) throw( uno::RuntimeException )
2014 {
2015 	vos::OGuard aGuard(Application::GetSolarMutex());
2016 	uno::Reference< text::XTextRange >  aRef;
2017 	SwFrmFmt* pFmt = GetFrmFmt();
2018 	if(pFmt)
2019 	{
2020         const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
2021         // return an anchor for non-page bound frames
2022         // and for page bound frames that have a page no == NULL and a content position
2023         if ((rAnchor.GetAnchorId() != FLY_AT_PAGE) ||
2024             (rAnchor.GetCntntAnchor() && !rAnchor.GetPageNum()))
2025 		{
2026             const SwPosition &rPos = *(rAnchor.GetCntntAnchor());
2027             aRef = SwXTextRange::CreateXTextRange(*pFmt->GetDoc(), rPos, 0);
2028 		}
2029 	}
2030 	else
2031 		throw uno::RuntimeException();
2032 	return aRef;
2033 }
2034 
ResetDescriptor()2035 void SwXFrame::ResetDescriptor()
2036 {
2037 	bIsDescriptor = sal_False;
2038 	mxStyleData.clear();
2039 	mxStyleFamily.clear();
2040 	DELETEZ(pProps);
2041 }
2042 
attachToRange(const uno::Reference<text::XTextRange> & xTextRange)2043 void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRange)
2044 			throw( lang::IllegalArgumentException, uno::RuntimeException )
2045 {
2046 	vos::OGuard aGuard(Application::GetSolarMutex());
2047 	if(!IsDescriptor())
2048 		throw uno::RuntimeException();
2049 	uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
2050 	SwXTextRange* pRange = 0;
2051 	OTextCursorHelper* pCursor = 0;
2052 	if(xRangeTunnel.is())
2053 	{
2054 		pRange 	= reinterpret_cast< SwXTextRange * >(
2055 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
2056 		pCursor = reinterpret_cast< OTextCursorHelper * >(
2057 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
2058 	}
2059 
2060 	SwDoc* pDoc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? (SwDoc*)pCursor->GetDoc() : 0;
2061 	if(pDoc)
2062 	{
2063 		SwUnoInternalPaM aIntPam(*pDoc);
2064 		//das muss jetzt sal_True liefern
2065         ::sw::XTextRangeToSwPaM(aIntPam, xTextRange);
2066 
2067 		SwNode& rNode = pDoc->GetNodes().GetEndOfContent();
2068 		SwPaM aPam(rNode);
2069 		aPam.Move( fnMoveBackward, fnGoDoc );
2070 		static sal_uInt16 __READONLY_DATA aFrmAttrRange[] =
2071 		{
2072 			RES_FRMATR_BEGIN, 		RES_FRMATR_END-1,
2073 			SID_ATTR_BORDER_INNER,	SID_ATTR_BORDER_INNER,
2074             RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
2075 			0
2076 		};
2077 		static sal_uInt16 __READONLY_DATA aGrAttrRange[] =
2078 		{
2079 			RES_GRFATR_BEGIN, 		RES_GRFATR_END-1,
2080 			0
2081 		};
2082 		SfxItemSet aGrSet(pDoc->GetAttrPool(), aGrAttrRange );
2083 
2084 		SfxItemSet aFrmSet(pDoc->GetAttrPool(), aFrmAttrRange );
2085 		//jetzt muessen die passenden Items in den Set
2086         sal_Bool bSizeFound;
2087         if(!pProps->AnyToItemSet( pDoc, aFrmSet, aGrSet, bSizeFound))
2088 			throw lang::IllegalArgumentException();
2089 		//der TextRange wird einzeln behandelt
2090 		*aPam.GetPoint() = *aIntPam.GetPoint();
2091 		if(aIntPam.HasMark())
2092 		{
2093 			aPam.SetMark();
2094 			*aPam.GetMark() = *aIntPam.GetMark();
2095 		}
2096 
2097         const SfxPoolItem* pItem;
2098         RndStdIds eAnchorId = FLY_AT_PARA;
2099 		if(SFX_ITEM_SET == aFrmSet.GetItemState(RES_ANCHOR, sal_False, &pItem) )
2100 		{
2101             eAnchorId = ((const SwFmtAnchor*)pItem)->GetAnchorId();
2102             if( FLY_AT_FLY == eAnchorId &&
2103 				!aPam.GetNode()->FindFlyStartNode())
2104 			{
2105 				//rahmengebunden geht nur dort, wo ein Rahmen ist!
2106                 SwFmtAnchor aAnchor(FLY_AT_PARA);
2107 				aFrmSet.Put(aAnchor);
2108 			}
2109             else if ((FLY_AT_PAGE == eAnchorId) &&
2110                      0 == ((const SwFmtAnchor*)pItem)->GetPageNum() )
2111 			{
2112                 SwFmtAnchor aAnchor( *((const SwFmtAnchor*)pItem) );
2113 				aAnchor.SetAnchor( aPam.GetPoint() );
2114 				aFrmSet.Put(aAnchor);
2115 			}
2116 		}
2117 
2118         const ::uno::Any* pStyle;
2119 		SwFrmFmt *pParentFrmFmt = 0;
2120         if(pProps->GetProperty(FN_UNO_FRAME_STYLE_NAME, 0, pStyle))
2121 			pParentFrmFmt = lcl_GetFrmFmt( *pStyle, pDoc );
2122 
2123 		SwFlyFrmFmt* pFmt = 0;
2124 		if( eType == FLYCNTTYPE_FRM)
2125 		{
2126 			UnoActionContext aCont(pDoc);
2127             if(m_pCopySource)
2128             {
2129                 SwFmtAnchor* pAnchorItem = 0;
2130                 // the frame is inserted bound to page
2131                 // to prevent conflicts if the to-be-anchored position is part of the to-be-copied text
2132                 if (eAnchorId != FLY_AT_PAGE)
2133                 {
2134                     pAnchorItem = static_cast<SwFmtAnchor*>(aFrmSet.Get(RES_ANCHOR).Clone());
2135                     aFrmSet.Put( SwFmtAnchor( FLY_AT_PAGE, 1 ));
2136                 }
2137 
2138                 aPam.DeleteMark(); // mark position node will be deleted!
2139                 aIntPam.DeleteMark(); // mark position node will be deleted!
2140                 pFmt = pDoc->MakeFlyAndMove( *m_pCopySource, aFrmSet,
2141                                0,
2142                                pParentFrmFmt );
2143                 if(pAnchorItem && pFmt)
2144                 {
2145                     pFmt->DelFrms();
2146                     pAnchorItem->SetAnchor( m_pCopySource->Start() );
2147                     SfxItemSet aAnchorSet( pDoc->GetAttrPool(), RES_ANCHOR, RES_ANCHOR );
2148                     aAnchorSet.Put( *pAnchorItem );
2149                     pDoc->SetFlyFrmAttr( *pFmt, aAnchorSet );
2150                     delete pAnchorItem;
2151                 }
2152                 DELETEZ( m_pCopySource );
2153             }
2154             else
2155             {
2156                 pFmt = pDoc->MakeFlySection( FLY_AT_PARA, aPam.GetPoint(),
2157                                          &aFrmSet, pParentFrmFmt );
2158             }
2159 			if(pFmt)
2160 			{
2161 				pFmt->Add(this);
2162 				if(sName.Len())
2163 					pDoc->SetFlyName((SwFlyFrmFmt&)*pFmt, sName);
2164 			}
2165 			//den SwXText wecken
2166             ((SwXTextFrame*)this)->SetDoc( bIsDescriptor ? m_pDoc : GetFrmFmt()->GetDoc() );
2167 		}
2168 		else if( eType == FLYCNTTYPE_GRF)
2169 		{
2170 			UnoActionContext aCont(pDoc);
2171             const ::uno::Any* pGraphicURL;
2172 			String sGraphicURL;
2173 			GraphicObject *pGrfObj = 0;
2174             if(pProps->GetProperty(FN_UNO_GRAPHIC_U_R_L, 0, pGraphicURL))
2175 			{
2176 				OUString uTemp;
2177 				(*pGraphicURL) >>= uTemp;
2178 				sGraphicURL = String(uTemp);
2179 				if( sGraphicURL.EqualsAscii( sPackageProtocol,
2180 									  		 0, sizeof( sPackageProtocol )-1 ) )
2181 				{
2182 					pGrfObj = new GraphicObject;
2183 					pGrfObj->SetUserData( sGraphicURL );
2184 					pGrfObj->SetSwapState();
2185 					sGraphicURL.Erase();
2186 				}
2187 				else if( sGraphicURL.EqualsAscii( sGraphicObjectProtocol,
2188 									   0, sizeof(sGraphicObjectProtocol)-1 ) )
2189 				{
2190 					ByteString sId( sGraphicURL.Copy( sizeof(sGraphicObjectProtocol)-1 ),
2191 									RTL_TEXTENCODING_ASCII_US );
2192 					pGrfObj = new GraphicObject( sId );
2193 					sGraphicURL.Erase();
2194 				}
2195 			}
2196             Graphic aGraphic;
2197             const ::uno::Any* pGraphic;
2198             if( pProps->GetProperty( FN_UNO_GRAPHIC, 0, pGraphic ))
2199             {
2200                 uno::Reference< graphic::XGraphic > xGraphic;
2201                 (*pGraphic) >>= xGraphic;
2202                 aGraphic = Graphic( xGraphic );
2203             }
2204 
2205 			String sFltName;
2206             const ::uno::Any* pFilter;
2207             if(pProps->GetProperty(FN_UNO_GRAPHIC_FILTER, 0, pFilter))
2208 			{
2209 				OUString uTemp;
2210 				(*pFilter) >>= uTemp;
2211 				sFltName = String(uTemp);
2212 			}
2213 
2214 			pFmt =
2215 				pGrfObj ? pDoc->Insert( aPam, *pGrfObj, &aFrmSet, &aGrSet,
2216 										pParentFrmFmt )
2217                         : pDoc->Insert( aPam, sGraphicURL, sFltName, &aGraphic,
2218 										&aFrmSet, &aGrSet, pParentFrmFmt  );
2219             delete pGrfObj;
2220 			if(pFmt)
2221 			{
2222                 SwGrfNode *pGrfNd = pDoc->GetNodes()[ pFmt->GetCntnt().GetCntntIdx()
2223                                             ->GetIndex()+1 ]->GetGrfNode();
2224                 pGrfNd->SetChgTwipSize( !bSizeFound );
2225                 pFmt->Add(this);
2226 				if(sName.Len())
2227 					pDoc->SetFlyName((SwFlyFrmFmt&)*pFmt, sName);
2228 
2229 			}
2230             const ::uno::Any* pSurroundContour;
2231             if(pProps->GetProperty(RES_SURROUND, MID_SURROUND_CONTOUR, pSurroundContour))
2232 				setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_SURROUND_CONTOUR)), *pSurroundContour);
2233             const ::uno::Any* pContourOutside;
2234             if(pProps->GetProperty(RES_SURROUND, MID_SURROUND_CONTOUROUTSIDE, pContourOutside))
2235 				setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_CONTOUR_OUTSIDE)), *pContourOutside);
2236             const ::uno::Any* pContourPoly;
2237             if(pProps->GetProperty(FN_PARAM_COUNTOUR_PP, 0, pContourPoly))
2238 				setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_CONTOUR_POLY_POLYGON)), *pContourPoly);
2239             const ::uno::Any* pPixelContour;
2240             if(pProps->GetProperty(FN_UNO_IS_PIXEL_CONTOUR, 0, pPixelContour))
2241 				setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_IS_PIXEL_CONTOUR)), *pPixelContour);
2242             const ::uno::Any* pAutoContour;
2243             if(pProps->GetProperty(FN_UNO_IS_AUTOMATIC_CONTOUR, 0, pAutoContour))
2244 				setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_IS_AUTOMATIC_CONTOUR)), *pAutoContour);
2245 //            const ::uno::Any* pAltText;
2246 //            if(pProps->GetProperty(FN_UNO_ALTERNATIVE_TEXT, 0, pAltText))
2247 //                setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_ALTERNATIVE_TEXT)), *pAltText);
2248 		}
2249 		else
2250 		{
2251             const ::uno::Any* pCLSID = 0;
2252             const ::uno::Any* pStreamName = 0;
2253             if(!pProps->GetProperty(FN_UNO_CLSID, 0, pCLSID) && !pProps->GetProperty( FN_UNO_STREAM_NAME, 0, pStreamName ))
2254                 throw uno::RuntimeException();
2255             if(pCLSID)
2256             {
2257                 OUString aCLSID;
2258                 SvGlobalName aClassName;
2259                 uno::Reference < embed::XEmbeddedObject > xIPObj;
2260                 std::auto_ptr < comphelper::EmbeddedObjectContainer > pCnt;
2261                 if( (*pCLSID) >>= aCLSID )
2262                 {
2263                     if( !aClassName.MakeId( aCLSID ) )
2264                     {
2265                         lang::IllegalArgumentException aExcept;
2266                         aExcept.Message = OUString::createFromAscii("CLSID invalid");
2267                         throw aExcept;
2268                     }
2269 
2270                     pCnt.reset( new comphelper::EmbeddedObjectContainer );
2271                     ::rtl::OUString aName;
2272                     xIPObj = pCnt->CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
2273                 }
2274                 if ( xIPObj.is() )
2275                 {
2276                     //TODO/LATER: MISCSTATUS_RESIZEONPRINTERCHANGE
2277                     //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xIPObj->GetMiscStatus() && pDoc->getPrinter( false ) )
2278                     //    xIPObj->OnDocumentPrinterChanged( pDoc->getPrinter( false ) );
2279 
2280                     UnoActionContext aAction(pDoc);
2281                     pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_INSERT, NULL);
2282                     if(!bSizeFound)
2283                     {
2284                         //TODO/LATER: from where do I get a ViewAspect? And how do I transport it to the OLENode?
2285                         sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
2286 
2287                         // TODO/LEAN: VisualArea still needs running state
2288                         svt::EmbeddedObjectRef::TryRunningState( xIPObj );
2289 
2290                         // set parent to get correct VisArea(in case of object needing parent printer)
2291                         uno::Reference < container::XChild > xChild( xIPObj, uno::UNO_QUERY );
2292                         if ( xChild.is() )
2293                             xChild->setParent( pDoc->GetDocShell()->GetModel() );
2294 
2295                         //The Size should be suggested by the OLE server if not manually set
2296                         MapUnit aRefMap = VCLUnoHelper::UnoEmbed2VCLMapUnit( xIPObj->getMapUnit( nAspect ) );
2297                         awt::Size aSize;
2298                         try
2299                         {
2300                             aSize = xIPObj->getVisualAreaSize( nAspect );
2301                         }
2302                         catch ( embed::NoVisualAreaSizeException& )
2303                         {
2304                             // the default size will be set later
2305                         }
2306 
2307                         Size aSz( aSize.Width, aSize.Height );
2308                         if ( !aSz.Width() || !aSz.Height() )
2309                         {
2310                             aSz.Width() = aSz.Height() = 5000;
2311                             aSz = OutputDevice::LogicToLogic
2312                                                     ( aSz, MapMode( MAP_100TH_MM ), aRefMap );
2313                         }
2314                         MapMode aMyMap( MAP_TWIP );
2315                         aSz = OutputDevice::LogicToLogic( aSz, aRefMap, aMyMap );
2316                         SwFmtFrmSize aFrmSz;
2317                         aFrmSz.SetSize(aSz);
2318                         aFrmSet.Put(aFrmSz);
2319                     }
2320                     SwFlyFrmFmt* pFmt2 = 0;
2321 
2322                     // TODO/LATER: Is it the only possible aspect here?
2323                     sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
2324                     ::svt::EmbeddedObjectRef xObjRef( xIPObj, nAspect );
2325                     pFmt2 = pDoc->Insert(aPam, xObjRef, &aFrmSet, NULL, NULL );
2326                     ASSERT( pFmt2, "Doc->Insert(notxt) failed." );
2327 
2328                     pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL);
2329                     pFmt2->Add(this);
2330                     if(sName.Len())
2331                         pDoc->SetFlyName((SwFlyFrmFmt&)*pFmt2, sName);
2332                 }
2333             }
2334             else if( pStreamName )
2335             {
2336                 ::rtl::OUString sStreamName;
2337                 (*pStreamName) >>= sStreamName;
2338                 pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_INSERT, NULL);
2339 
2340                 SwFlyFrmFmt* pFrmFmt = 0;
2341                 pFrmFmt = pDoc->InsertOLE( aPam, sStreamName, embed::Aspects::MSOLE_CONTENT, &aFrmSet, NULL, NULL );
2342                 pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL);
2343                 pFrmFmt->Add(this);
2344                 if(sName.Len())
2345                     pDoc->SetFlyName((SwFlyFrmFmt&)*pFrmFmt, sName);
2346             }
2347         }
2348 		if( pFmt && pDoc->GetDrawModel() )
2349 			GetOrCreateSdrObject( pFmt );
2350         const ::uno::Any* pOrder;
2351         if( pProps->GetProperty(FN_UNO_Z_ORDER, 0, pOrder) )
2352 			setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_Z_ORDER)), *pOrder);
2353         const ::uno::Any* pReplacement;
2354         if( pProps->GetProperty(FN_UNO_REPLACEMENT_GRAPHIC, 0, pReplacement) )
2355             setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_GRAPHIC)), *pReplacement);
2356         // --> OD 2009-07-13 #i73249#
2357         // new attribute Title
2358         const ::uno::Any* pTitle;
2359         if ( pProps->GetProperty(FN_UNO_TITLE, 0, pTitle) )
2360         {
2361             setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_TITLE)), *pTitle);
2362         }
2363         // new attribute Description
2364         const ::uno::Any* pDescription;
2365         if ( pProps->GetProperty(FN_UNO_DESCRIPTION, 0, pDescription) )
2366         {
2367             setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_DESCRIPTION)), *pDescription);
2368         }
2369         // <--
2370 	}
2371 	else
2372 		throw lang::IllegalArgumentException();
2373 	//setzt das Flag zurueck und loescht den Descriptor-Pointer
2374 	ResetDescriptor();
2375 }
2376 
attach(const uno::Reference<text::XTextRange> & xTextRange)2377 void SwXFrame::attach(const uno::Reference< text::XTextRange > & xTextRange)
2378 	throw( lang::IllegalArgumentException, uno::RuntimeException )
2379 {
2380     SwFrmFmt* pFmt;
2381     if(IsDescriptor())
2382         attachToRange(xTextRange);
2383     else if(0 != (pFmt = GetFrmFmt()))
2384     {
2385         uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
2386         SwXTextRange* pRange = 0;
2387         OTextCursorHelper* pCursor = 0;
2388         if(xRangeTunnel.is())
2389         {
2390             pRange 	= reinterpret_cast< SwXTextRange * >(
2391 					sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
2392             pCursor = reinterpret_cast< OTextCursorHelper * >(
2393 					sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
2394         }
2395         SwDoc* pDoc = pFmt->GetDoc();
2396         SwUnoInternalPaM aIntPam(*pDoc);
2397         if (::sw::XTextRangeToSwPaM(aIntPam, xTextRange))
2398         {
2399             SfxItemSet aSet( pDoc->GetAttrPool(),
2400                         RES_ANCHOR, RES_ANCHOR );
2401             aSet.SetParent(&pFmt->GetAttrSet());
2402             SwFmtAnchor aAnchor = (const SwFmtAnchor&)aSet.Get(RES_ANCHOR);
2403             aAnchor.SetAnchor( aIntPam.Start() );
2404             aSet.Put(aAnchor);
2405             pDoc->SetFlyFrmAttr( *pFmt, aSet );
2406         }
2407         else
2408             throw lang::IllegalArgumentException();
2409     }
2410 }
2411 
getPosition(void)2412 awt::Point SwXFrame::getPosition(void) throw( uno::RuntimeException )
2413 {
2414 	vos::OGuard aGuard(Application::GetSolarMutex());
2415 	uno::RuntimeException aRuntime;
2416 	aRuntime.Message = C2U("position cannot be determined with this method");
2417 	throw aRuntime;
2418 }
2419 
setPosition(const awt::Point &)2420 void SwXFrame::setPosition(const awt::Point& /*aPosition*/) throw( uno::RuntimeException )
2421 {
2422 	vos::OGuard aGuard(Application::GetSolarMutex());
2423 	uno::RuntimeException aRuntime;
2424 	aRuntime.Message = C2U("position cannot be changed with this method");
2425 	throw aRuntime;
2426 }
2427 
getSize(void)2428 awt::Size SwXFrame::getSize(void) throw( uno::RuntimeException )
2429 {
2430     const ::uno::Any aVal = getPropertyValue(C2U("Size"));
2431 	awt::Size* pRet =  (awt::Size*)aVal.getValue();
2432 	return *pRet;
2433 }
2434 
setSize(const awt::Size & aSize)2435 void SwXFrame::setSize(const awt::Size& aSize)
2436 	throw( beans::PropertyVetoException, uno::RuntimeException )
2437 {
2438     const ::uno::Any aVal(&aSize, ::getCppuType(static_cast<const awt::Size*>(0)));
2439 	setPropertyValue(C2U("Size"), aVal);
2440 }
2441 
getShapeType(void)2442 OUString SwXFrame::getShapeType(void) throw( uno::RuntimeException )
2443 {
2444 	return C2U("FrameShape");
2445 }
2446 
2447 
2448 /******************************************************************
2449  *	SwXTextFrame
2450  ******************************************************************/
2451 
SwXTextFrame(SwDoc * _pDoc)2452 SwXTextFrame::SwXTextFrame( SwDoc *_pDoc ) :
2453 	SwXText(0, CURSOR_FRAME),
2454     SwXFrame(FLYCNTTYPE_FRM, aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_FRAME), _pDoc )
2455 {
2456 }
2457 
SwXTextFrame(SwFrmFmt & rFmt)2458 SwXTextFrame::SwXTextFrame(SwFrmFmt& rFmt) :
2459 	SwXText(rFmt.GetDoc(), CURSOR_FRAME),
2460     SwXFrame(rFmt, FLYCNTTYPE_FRM, aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_FRAME))
2461 {
2462 
2463 }
2464 
~SwXTextFrame()2465 SwXTextFrame::~SwXTextFrame()
2466 {
2467 }
2468 
acquire()2469 void SAL_CALL SwXTextFrame::acquire(  )throw()
2470 {
2471 	SwXFrame::acquire();
2472 }
2473 
release()2474 void SAL_CALL SwXTextFrame::release(  )throw()
2475 {
2476 	SwXFrame::release();
2477 }
2478 
queryInterface(const uno::Type & aType)2479 ::uno::Any SAL_CALL SwXTextFrame::queryInterface( const uno::Type& aType )
2480 	throw (uno::RuntimeException)
2481 {
2482     ::uno::Any aRet = SwXFrame::queryInterface(aType);
2483 	if(aRet.getValueType() == ::getCppuVoidType())
2484         aRet = SwXText::queryInterface(aType);
2485 	if(aRet.getValueType() == ::getCppuVoidType())
2486 		aRet = SwXTextFrameBaseClass::queryInterface(aType);
2487 	return aRet;
2488 }
2489 
getTypes()2490 uno::Sequence< uno::Type > SAL_CALL SwXTextFrame::getTypes(  ) throw(uno::RuntimeException)
2491 {
2492 	uno::Sequence< uno::Type > aTextFrameTypes = SwXTextFrameBaseClass::getTypes();
2493 	uno::Sequence< uno::Type > aFrameTypes = SwXFrame::getTypes();
2494 	uno::Sequence< uno::Type > aTextTypes = SwXText::getTypes();
2495 
2496 	long nIndex = aTextFrameTypes.getLength();
2497 	aTextFrameTypes.realloc(
2498 		aTextFrameTypes.getLength() +
2499 		aFrameTypes.getLength() +
2500 		aTextTypes.getLength());
2501 
2502 	uno::Type* pTextFrameTypes = aTextFrameTypes.getArray();
2503     const uno::Type* pFrameTypes = aFrameTypes.getConstArray();
2504 	long nPos;
2505 	for(nPos = 0; nPos <aFrameTypes.getLength(); nPos++)
2506 		pTextFrameTypes[nIndex++] = pFrameTypes[nPos];
2507 
2508     const uno::Type* pTextTypes = aTextTypes.getConstArray();
2509 	for(nPos = 0; nPos <aTextTypes.getLength(); nPos++)
2510 		pTextFrameTypes[nIndex++] = pTextTypes[nPos];
2511 
2512 	return aTextFrameTypes;
2513 }
2514 
getImplementationId()2515 uno::Sequence< sal_Int8 > SAL_CALL SwXTextFrame::getImplementationId(  ) throw(uno::RuntimeException)
2516 {
2517     vos::OGuard aGuard(Application::GetSolarMutex());
2518     static uno::Sequence< sal_Int8 > aId( 16 );
2519     static sal_Bool bInit = sal_False;
2520     if(!bInit)
2521     {
2522         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
2523         bInit = sal_True;
2524     }
2525     return aId;
2526 }
2527 
getText(void)2528 uno::Reference< text::XText >  SwXTextFrame::getText(void) throw( uno::RuntimeException )
2529 {
2530 	return this;
2531 }
2532 
GetStartNode() const2533 const SwStartNode *SwXTextFrame::GetStartNode() const
2534 {
2535     const SwStartNode *pSttNd = 0;
2536 
2537 	SwFrmFmt* pFmt = GetFrmFmt();
2538 	if(pFmt)
2539 	{
2540         const SwFmtCntnt& rFlyCntnt = pFmt->GetCntnt();
2541 		if( rFlyCntnt.GetCntntIdx() )
2542 			pSttNd = rFlyCntnt.GetCntntIdx()->GetNode().GetStartNode();
2543 	}
2544 
2545 	return pSttNd;
2546 }
2547 
2548 uno::Reference< text::XTextCursor >
CreateCursor()2549 SwXTextFrame::CreateCursor() throw (uno::RuntimeException)
2550 {
2551 	return createTextCursor();
2552 }
2553 
createTextCursor(void)2554 uno::Reference< text::XTextCursor >  SwXTextFrame::createTextCursor(void) throw( uno::RuntimeException )
2555 {
2556 	vos::OGuard aGuard(Application::GetSolarMutex());
2557 	uno::Reference< text::XTextCursor >  aRef;
2558 	SwFrmFmt* pFmt = GetFrmFmt();
2559 	if(pFmt)
2560 	{
2561         //save current start node to be able to check if there is content after the table -
2562 		//otherwise the cursor would be in the body text!
2563         const SwNode& rNode = pFmt->GetCntnt().GetCntntIdx()->GetNode();
2564         const SwStartNode* pOwnStartNode = rNode.FindSttNodeByType(SwFlyStartNode);
2565 
2566         SwPaM aPam(rNode);
2567 		aPam.Move(fnMoveForward, fnGoNode);
2568 		SwTableNode* pTblNode = aPam.GetNode()->FindTableNode();
2569 		SwCntntNode* pCont = 0;
2570 		while( pTblNode )
2571 		{
2572 			aPam.GetPoint()->nNode = *pTblNode->EndOfSectionNode();
2573 			pCont = GetDoc()->GetNodes().GoNext(&aPam.GetPoint()->nNode);
2574 			pTblNode = pCont->FindTableNode();
2575 		}
2576 		if(pCont)
2577 			aPam.GetPoint()->nContent.Assign(pCont, 0);
2578 
2579         const SwStartNode* pNewStartNode =
2580             aPam.GetNode()->FindSttNodeByType(SwFlyStartNode);
2581 		if(!pNewStartNode || pNewStartNode != pOwnStartNode)
2582 		{
2583 			uno::RuntimeException aExcept;
2584             aExcept.Message = C2U("no text available");
2585 			throw aExcept;
2586 		}
2587 
2588         SwXTextCursor *const pXCursor = new SwXTextCursor(
2589                  *pFmt->GetDoc(), this, CURSOR_FRAME, *aPam.GetPoint());
2590         aRef =  static_cast<text::XWordCursor*>(pXCursor);
2591 #if OSL_DEBUG_LEVEL > 1
2592         SwUnoCrsr *const pUnoCrsr = pXCursor->GetCursor();
2593         (void) pUnoCrsr;
2594 #endif
2595 	}
2596 	else
2597 		throw uno::RuntimeException();
2598 	return aRef;
2599 }
2600 
createTextCursorByRange(const uno::Reference<text::XTextRange> & aTextPosition)2601 uno::Reference< text::XTextCursor >  SwXTextFrame::createTextCursorByRange(const uno::Reference< text::XTextRange > & aTextPosition) throw( uno::RuntimeException )
2602 {
2603 	vos::OGuard aGuard(Application::GetSolarMutex());
2604 	uno::Reference< text::XTextCursor >  aRef;
2605 	SwFrmFmt* pFmt = GetFrmFmt();
2606 	SwUnoInternalPaM aPam(*GetDoc());
2607     if (pFmt && ::sw::XTextRangeToSwPaM(aPam, aTextPosition))
2608     {
2609 		SwNode& rNode = pFmt->GetCntnt().GetCntntIdx()->GetNode();
2610 #if OSL_DEBUG_LEVEL > 1
2611         const SwStartNode* p1 = aPam.GetNode()->FindFlyStartNode();
2612         const SwStartNode* p2 = rNode.FindFlyStartNode();
2613         (void)p1;
2614         (void)p2;
2615 #endif
2616 		if(aPam.GetNode()->FindFlyStartNode() == rNode.FindFlyStartNode())
2617         {
2618             aRef = static_cast<text::XWordCursor*>(
2619                     new SwXTextCursor(*pFmt->GetDoc(), this, CURSOR_FRAME,
2620                         *aPam.GetPoint(), aPam.GetMark()));
2621         }
2622 	}
2623 	else
2624 		throw uno::RuntimeException();
2625 	return aRef;
2626 }
2627 
createEnumeration(void)2628 uno::Reference< container::XEnumeration >  SwXTextFrame::createEnumeration(void) throw( uno::RuntimeException )
2629 {
2630 	vos::OGuard aGuard(Application::GetSolarMutex());
2631 	uno::Reference< container::XEnumeration >  aRef;
2632 	SwFrmFmt* pFmt = GetFrmFmt();
2633 	if(pFmt)
2634 	{
2635 		SwPosition aPos(pFmt->GetCntnt().GetCntntIdx()->GetNode());
2636         ::std::auto_ptr<SwUnoCrsr> pUnoCursor(
2637                 GetDoc()->CreateUnoCrsr(aPos, sal_False));
2638         pUnoCursor->Move(fnMoveForward, fnGoNode);
2639 //		// no Cursor in protected sections
2640 //		SwCrsrSaveState aSave( *pUnoCrsr );
2641 //		if(pUnoCrsr->IsInProtectTable( sal_True ) ||
2642 //			pUnoCrsr->IsSelOvr( SELOVER_TOGGLE | SELOVER_CHANGEPOS ))
2643 //			throw  uno::RuntimeException() );
2644         aRef = new SwXParagraphEnumeration(this, pUnoCursor, CURSOR_FRAME);
2645 	}
2646 	return aRef;
2647 }
2648 
getElementType(void)2649 uno::Type  SwXTextFrame::getElementType(void) throw( uno::RuntimeException )
2650 {
2651 	return ::getCppuType(static_cast<uno::Reference<text::XTextRange>*>(0));
2652 }
2653 
hasElements(void)2654 sal_Bool SwXTextFrame::hasElements(void) throw( uno::RuntimeException )
2655 {
2656 	return sal_True;
2657 }
2658 
attach(const uno::Reference<text::XTextRange> & xTextRange)2659 void SwXTextFrame::attach(const uno::Reference< text::XTextRange > & xTextRange)
2660 	throw( lang::IllegalArgumentException, uno::RuntimeException )
2661 {
2662     SwXFrame::attach(xTextRange);
2663 }
2664 
getAnchor(void)2665 uno::Reference< text::XTextRange >  SwXTextFrame::getAnchor(void) throw( uno::RuntimeException )
2666 {
2667 	vos::OGuard aGuard(Application::GetSolarMutex());
2668 	return SwXFrame::getAnchor();
2669 }
2670 
dispose(void)2671 void SwXTextFrame::dispose(void) throw( uno::RuntimeException )
2672 {
2673 	vos::OGuard aGuard(Application::GetSolarMutex());
2674 	SwXFrame::dispose();
2675 }
2676 
addEventListener(const uno::Reference<lang::XEventListener> & aListener)2677 void SwXTextFrame::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
2678 {
2679 	SwXFrame::addEventListener(aListener);
2680 }
2681 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)2682 void SwXTextFrame::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
2683 {
2684 	SwXFrame::removeEventListener(aListener);
2685 }
2686 
getImplementationName(void)2687 OUString SwXTextFrame::getImplementationName(void) throw( uno::RuntimeException )
2688 {
2689 	return C2U("SwXTextFrame");
2690 }
2691 
supportsService(const OUString & rServiceName)2692 sal_Bool SwXTextFrame::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
2693 {
2694 	return COMPARE_EQUAL == rServiceName.compareToAscii("com.sun.star.text.Text")||
2695 			COMPARE_EQUAL == rServiceName.compareToAscii("com.sun.star.text.TextFrame")||
2696 					SwXFrame::supportsService(rServiceName);
2697 }
2698 
getSupportedServiceNames(void)2699 uno::Sequence< OUString > SwXTextFrame::getSupportedServiceNames(void) throw( uno::RuntimeException )
2700 {
2701 	uno::Sequence < OUString > aRet = SwXFrame::getSupportedServiceNames();
2702 	aRet.realloc(aRet.getLength() + 2);
2703 	OUString* pArray = aRet.getArray();
2704 	pArray[aRet.getLength() - 2] = C2U("com.sun.star.text.TextFrame");
2705 	pArray[aRet.getLength() - 1] = C2U("com.sun.star.text.Text");
2706 	return aRet;
2707 }
2708 
operator new(size_t t)2709 void * SAL_CALL SwXTextFrame::operator new( size_t t) throw()
2710 {
2711 	return SwXTextFrameBaseClass::operator new( t);
2712 }
2713 
operator delete(void * p)2714 void SAL_CALL SwXTextFrame::operator delete( void * p) throw()
2715 {
2716 	SwXTextFrameBaseClass::operator delete(p);
2717 }
2718 
getEvents()2719 uno::Reference<container::XNameReplace > SAL_CALL SwXTextFrame::getEvents()
2720 	throw(uno::RuntimeException)
2721 {
2722 	return new SwFrameEventDescriptor( *this );
2723 }
2724 
getSomething(const uno::Sequence<sal_Int8> & rId)2725 sal_Int64 SAL_CALL SwXTextFrame::getSomething( const uno::Sequence< sal_Int8 >& rId )
2726 	throw(uno::RuntimeException)
2727 {
2728 	sal_Int64 nRet = SwXFrame::getSomething( rId );
2729 	if( !nRet )
2730 		nRet = SwXText::getSomething( rId );
2731 
2732 	return nRet;
2733 }
2734 
getPropertyValue(const OUString & rPropertyName)2735 ::uno::Any SwXTextFrame::getPropertyValue(const OUString& rPropertyName)
2736 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2737 {
2738     vos::OGuard aGuard(Application::GetSolarMutex());
2739     ::uno::Any aRet;
2740     if(rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_START_REDLINE))||
2741             rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_END_REDLINE)))
2742     {
2743         //redline can only be returned if it's a living object
2744         if(!IsDescriptor())
2745             aRet = SwXText::getPropertyValue(rPropertyName);
2746     }
2747     else
2748         aRet = SwXFrame::getPropertyValue(rPropertyName);
2749     return aRet;
2750 }
2751 /******************************************************************
2752  *	SwXTextGraphicObject
2753  ******************************************************************/
2754 
SwXTextGraphicObject(SwDoc * pDoc)2755 SwXTextGraphicObject::SwXTextGraphicObject( SwDoc *pDoc ) :
2756     SwXFrame(FLYCNTTYPE_GRF, aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_GRAPHIC), pDoc)
2757 {
2758 }
2759 
SwXTextGraphicObject(SwFrmFmt & rFmt)2760 SwXTextGraphicObject::SwXTextGraphicObject(SwFrmFmt& rFmt) :
2761     SwXFrame(rFmt, FLYCNTTYPE_GRF, aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_GRAPHIC))
2762 {
2763 
2764 }
2765 
~SwXTextGraphicObject()2766 SwXTextGraphicObject::~SwXTextGraphicObject()
2767 {
2768 
2769 }
2770 
acquire()2771 void SAL_CALL SwXTextGraphicObject::acquire(  )throw()
2772 {
2773 	SwXFrame::acquire();
2774 }
2775 
release()2776 void SAL_CALL SwXTextGraphicObject::release(  )throw()
2777 {
2778 	SwXFrame::release();
2779 }
2780 
queryInterface(const uno::Type & aType)2781 ::uno::Any SAL_CALL SwXTextGraphicObject::queryInterface( const uno::Type& aType )
2782 	throw(uno::RuntimeException)
2783 {
2784     ::uno::Any aRet = SwXFrame::queryInterface(aType);
2785 	if(aRet.getValueType() == ::getCppuVoidType())
2786 		aRet = SwXTextGraphicObjectBaseClass::queryInterface(aType);
2787 	return aRet;
2788 }
2789 
2790 uno::Sequence< uno::Type > SAL_CALL
getTypes()2791 	SwXTextGraphicObject::getTypes(  ) throw(uno::RuntimeException)
2792 {
2793 	uno::Sequence< uno::Type > aGraphicTypes = SwXTextGraphicObjectBaseClass::getTypes();
2794 	uno::Sequence< uno::Type > aFrameTypes = SwXFrame::getTypes();
2795 
2796 	long nIndex = aGraphicTypes.getLength();
2797 	aGraphicTypes.realloc(
2798 		aGraphicTypes.getLength() +
2799 		aFrameTypes.getLength());
2800 
2801 	uno::Type* pGraphicTypes = aGraphicTypes.getArray();
2802     const uno::Type* pFrameTypes = aFrameTypes.getConstArray();
2803 	long nPos;
2804 	for(nPos = 0; nPos <aFrameTypes.getLength(); nPos++)
2805 		pGraphicTypes[nIndex++] = pFrameTypes[nPos];
2806 
2807 	return aGraphicTypes;
2808 }
2809 
getImplementationId()2810 uno::Sequence< sal_Int8 > SAL_CALL SwXTextGraphicObject::getImplementationId(  ) throw(uno::RuntimeException)
2811 {
2812     vos::OGuard aGuard(Application::GetSolarMutex());
2813     static uno::Sequence< sal_Int8 > aId( 16 );
2814     static sal_Bool bInit = sal_False;
2815     if(!bInit)
2816     {
2817         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
2818         bInit = sal_True;
2819     }
2820     return aId;
2821 }
2822 
attach(const uno::Reference<text::XTextRange> & xTextRange)2823 void SwXTextGraphicObject::attach(const uno::Reference< text::XTextRange > & xTextRange) throw( lang::IllegalArgumentException, uno::RuntimeException )
2824 {
2825     SwXFrame::attach(xTextRange);
2826 }
2827 
getAnchor(void)2828 uno::Reference< text::XTextRange >  SwXTextGraphicObject::getAnchor(void) throw( uno::RuntimeException )
2829 {
2830 	vos::OGuard aGuard(Application::GetSolarMutex());
2831 	return SwXFrame::getAnchor();
2832 }
2833 
dispose(void)2834 void SwXTextGraphicObject::dispose(void) throw( uno::RuntimeException )
2835 {
2836 	vos::OGuard aGuard(Application::GetSolarMutex());
2837 	SwXFrame::dispose();
2838 }
2839 
addEventListener(const uno::Reference<lang::XEventListener> & aListener)2840 void SwXTextGraphicObject::addEventListener(const uno::Reference< lang::XEventListener > & aListener)
2841 													throw( uno::RuntimeException )
2842 {
2843 	SwXFrame::addEventListener(aListener);
2844 }
2845 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)2846 void SwXTextGraphicObject::removeEventListener(const uno::Reference< lang::XEventListener > & aListener)
2847 													throw( uno::RuntimeException )
2848 {
2849 	SwXFrame::removeEventListener(aListener);
2850 }
2851 
getImplementationName(void)2852 OUString SwXTextGraphicObject::getImplementationName(void) throw( uno::RuntimeException )
2853 {
2854 	return C2U("SwXTextGraphicObject");
2855 }
2856 
supportsService(const OUString & rServiceName)2857 sal_Bool SwXTextGraphicObject::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
2858 {
2859 	return COMPARE_EQUAL == rServiceName.compareToAscii("com.sun.star.text.TextGraphicObject") ||
2860 					SwXFrame::supportsService(rServiceName);
2861 }
2862 
getSupportedServiceNames(void)2863 uno::Sequence< OUString > SwXTextGraphicObject::getSupportedServiceNames(void)
2864 		throw( uno::RuntimeException )
2865 {
2866 	uno::Sequence < OUString > aRet = SwXFrame::getSupportedServiceNames();
2867 	aRet.realloc(aRet.getLength() + 1);
2868 	OUString* pArray = aRet.getArray();
2869 	pArray[aRet.getLength() - 1] = C2U("com.sun.star.text.TextGraphicObject");
2870 	return aRet;
2871 }
2872 
operator new(size_t t)2873 void * SAL_CALL SwXTextGraphicObject::operator new( size_t t) throw()
2874 {
2875 	return SwXTextGraphicObjectBaseClass::operator new(t);
2876 }
2877 
operator delete(void * p)2878 void SAL_CALL SwXTextGraphicObject::operator delete( void * p) throw()
2879 {
2880 	SwXTextGraphicObjectBaseClass::operator delete(p);
2881 }
2882 
2883 uno::Reference<container::XNameReplace> SAL_CALL
getEvents()2884 	SwXTextGraphicObject::getEvents()
2885 		throw(uno::RuntimeException)
2886 {
2887 	return new SwFrameEventDescriptor( *this );
2888 }
2889 
2890 /******************************************************************
2891  *
2892  ******************************************************************/
2893 
SwXTextEmbeddedObject(SwDoc * pDoc)2894 SwXTextEmbeddedObject::SwXTextEmbeddedObject( SwDoc *pDoc ) :
2895     SwXFrame(FLYCNTTYPE_OLE, aSwMapProvider.GetPropertySet(PROPERTY_MAP_EMBEDDED_OBJECT), pDoc)
2896 {
2897 }
2898 
SwXTextEmbeddedObject(SwFrmFmt & rFmt)2899 SwXTextEmbeddedObject::SwXTextEmbeddedObject(SwFrmFmt& rFmt) :
2900     SwXFrame(rFmt, FLYCNTTYPE_OLE, aSwMapProvider.GetPropertySet(PROPERTY_MAP_EMBEDDED_OBJECT))
2901 {
2902 
2903 }
2904 
~SwXTextEmbeddedObject()2905 SwXTextEmbeddedObject::~SwXTextEmbeddedObject()
2906 {
2907 
2908 }
2909 
acquire()2910 void SAL_CALL SwXTextEmbeddedObject::acquire()throw()
2911 {
2912 	SwXFrame::acquire();
2913 }
2914 
release()2915 void SAL_CALL SwXTextEmbeddedObject::release()throw()
2916 {
2917 	SwXFrame::release();
2918 }
2919 
queryInterface(const uno::Type & aType)2920 ::uno::Any SAL_CALL SwXTextEmbeddedObject::queryInterface( const uno::Type& aType )
2921 	throw( uno::RuntimeException)
2922 {
2923     ::uno::Any aRet = SwXFrame::queryInterface(aType);;
2924 	if(aRet.getValueType() == ::getCppuVoidType())
2925 		aRet = SwXTextEmbeddedObjectBaseClass::queryInterface(aType);
2926 	return aRet;
2927 }
2928 
getTypes()2929 uno::Sequence< uno::Type > SAL_CALL SwXTextEmbeddedObject::getTypes(  ) throw(uno::RuntimeException)
2930 {
2931 	uno::Sequence< uno::Type > aTextEmbeddedTypes = SwXTextEmbeddedObjectBaseClass::getTypes();
2932 	uno::Sequence< uno::Type > aFrameTypes = SwXFrame::getTypes();
2933 
2934 	long nIndex = aTextEmbeddedTypes.getLength();
2935 	aTextEmbeddedTypes.realloc(
2936 		aTextEmbeddedTypes.getLength() +
2937 		aFrameTypes.getLength());
2938 
2939 	uno::Type* pTextEmbeddedTypes = aTextEmbeddedTypes.getArray();
2940 
2941     const uno::Type* pFrameTypes = aFrameTypes.getConstArray();
2942 	long nPos;
2943 	for(nPos = 0; nPos <aFrameTypes.getLength(); nPos++)
2944 		pTextEmbeddedTypes[nIndex++] = pFrameTypes[nPos];
2945 
2946 	return aTextEmbeddedTypes;
2947 }
2948 
getImplementationId()2949 uno::Sequence< sal_Int8 > SAL_CALL SwXTextEmbeddedObject::getImplementationId(  ) throw(uno::RuntimeException)
2950 {
2951     vos::OGuard aGuard(Application::GetSolarMutex());
2952     static uno::Sequence< sal_Int8 > aId( 16 );
2953     static sal_Bool bInit = sal_False;
2954     if(!bInit)
2955     {
2956         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
2957         bInit = sal_True;
2958     }
2959     return aId;
2960 }
2961 
attach(const uno::Reference<text::XTextRange> & xTextRange)2962 void SwXTextEmbeddedObject::attach(const uno::Reference< text::XTextRange > & xTextRange) throw( lang::IllegalArgumentException, uno::RuntimeException )
2963 {
2964     SwXFrame::attach(xTextRange);
2965 }
2966 
getAnchor(void)2967 uno::Reference< text::XTextRange >  SwXTextEmbeddedObject::getAnchor(void) throw( uno::RuntimeException )
2968 {
2969 	vos::OGuard aGuard(Application::GetSolarMutex());
2970 	return SwXFrame::getAnchor();
2971 }
2972 
dispose(void)2973 void SwXTextEmbeddedObject::dispose(void) throw( uno::RuntimeException )
2974 {
2975 	vos::OGuard aGuard(Application::GetSolarMutex());
2976 	SwXFrame::dispose();
2977 }
2978 
addEventListener(const uno::Reference<lang::XEventListener> & aListener)2979 void SwXTextEmbeddedObject::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
2980 {
2981 	SwXFrame::addEventListener(aListener);
2982 }
2983 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)2984 void SwXTextEmbeddedObject::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
2985 {
2986 	SwXFrame::removeEventListener(aListener);
2987 }
2988 
getEmbeddedObject(void)2989 uno::Reference< lang::XComponent >  SwXTextEmbeddedObject::getEmbeddedObject(void) throw( uno::RuntimeException )
2990 {
2991 	uno::Reference< lang::XComponent >  xRet;
2992 	SwFrmFmt* 	pFmt = GetFrmFmt();
2993 	if(pFmt)
2994 	{
2995 		SwDoc* pDoc = pFmt->GetDoc();
2996         const SwFmtCntnt* pCnt = &pFmt->GetCntnt();
2997 		DBG_ASSERT(	pCnt->GetCntntIdx() &&
2998 					   pDoc->GetNodes()[ pCnt->GetCntntIdx()->
2999 										GetIndex() + 1 ]->GetOLENode(), "kein OLE-Node?");
3000 
3001 		SwOLENode* pOleNode =  pDoc->GetNodes()[ pCnt->GetCntntIdx()
3002 										->GetIndex() + 1 ]->GetOLENode();
3003         uno::Reference < embed::XEmbeddedObject > xIP = pOleNode->GetOLEObj().GetOleRef();
3004         if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
3005 		{
3006             // TODO/LATER: the listener registered after client creation should be able to handle scaling, after that the client is not necessary here
3007             if ( pDoc->GetDocShell() )
3008                 pDoc->GetDocShell()->GetIPClient( svt::EmbeddedObjectRef( xIP, embed::Aspects::MSOLE_CONTENT ) );
3009 
3010             xRet = uno::Reference < lang::XComponent >( xIP->getComponent(), uno::UNO_QUERY );
3011             uno::Reference< util::XModifyBroadcaster >  xBrdcst( xRet, uno::UNO_QUERY);
3012             uno::Reference< frame::XModel > xModel( xRet, uno::UNO_QUERY);
3013             if( xBrdcst.is() && xModel.is() )
3014             {
3015                 SwXOLEListener* pListener = SwIterator<SwXOLEListener,SwFmt>::FirstElement( *pFmt );
3016                 //create a new one if the OLE object doesn't have one already
3017                 if( !pListener )
3018                 {
3019                     uno::Reference< util::XModifyListener > xOLEListener = new SwXOLEListener(*pFmt, xModel);
3020                     xBrdcst->addModifyListener( xOLEListener );
3021                 }
3022             }
3023 		}
3024 	}
3025 	return xRet;
3026 }
3027 
getExtendedControlOverEmbeddedObject()3028 uno::Reference< embed::XEmbeddedObject > SAL_CALL SwXTextEmbeddedObject::getExtendedControlOverEmbeddedObject()
3029 		throw( uno::RuntimeException )
3030 {
3031 	uno::Reference< embed::XEmbeddedObject > xResult;
3032 	SwFrmFmt* 	pFmt = GetFrmFmt();
3033 	if(pFmt)
3034 	{
3035 		SwDoc* pDoc = pFmt->GetDoc();
3036         const SwFmtCntnt* pCnt = &pFmt->GetCntnt();
3037 		DBG_ASSERT(	pCnt->GetCntntIdx() &&
3038 					   pDoc->GetNodes()[ pCnt->GetCntntIdx()->
3039 										GetIndex() + 1 ]->GetOLENode(), "kein OLE-Node?");
3040 
3041 		SwOLENode* pOleNode =  pDoc->GetNodes()[ pCnt->GetCntntIdx()
3042 										->GetIndex() + 1 ]->GetOLENode();
3043         xResult = pOleNode->GetOLEObj().GetOleRef();
3044         if ( svt::EmbeddedObjectRef::TryRunningState( xResult ) )
3045 		{
3046             // TODO/LATER: the listener registered after client creation should be able to handle scaling, after that the client is not necessary here
3047             if ( pDoc->GetDocShell() )
3048                 pDoc->GetDocShell()->GetIPClient( svt::EmbeddedObjectRef( xResult, embed::Aspects::MSOLE_CONTENT ) );
3049 
3050             uno::Reference < lang::XComponent > xComp( xResult->getComponent(), uno::UNO_QUERY );
3051             uno::Reference< util::XModifyBroadcaster >  xBrdcst( xComp, uno::UNO_QUERY);
3052             uno::Reference< frame::XModel > xModel( xComp, uno::UNO_QUERY);
3053             if( xBrdcst.is() && xModel.is() )
3054             {
3055                 SwXOLEListener* pListener = SwIterator<SwXOLEListener,SwFmt>::FirstElement( *pFmt );
3056                 //create a new one if the OLE object doesn't have one already
3057                 if( !pListener )
3058                 {
3059                     uno::Reference< util::XModifyListener > xOLEListener = new SwXOLEListener(*pFmt, xModel);
3060                     xBrdcst->addModifyListener( xOLEListener );
3061                 }
3062             }
3063 		}
3064 	}
3065 	return xResult;
3066 }
3067 
getAspect()3068 sal_Int64 SAL_CALL SwXTextEmbeddedObject::getAspect() throw (uno::RuntimeException)
3069 {
3070 	SwFrmFmt* 	pFmt = GetFrmFmt();
3071 	if(pFmt)
3072 	{
3073 		SwDoc* pDoc = pFmt->GetDoc();
3074         const SwFmtCntnt* pCnt = &pFmt->GetCntnt();
3075 		DBG_ASSERT(	pCnt->GetCntntIdx() &&
3076 					   pDoc->GetNodes()[ pCnt->GetCntntIdx()->
3077 										GetIndex() + 1 ]->GetOLENode(), "kein OLE-Node?");
3078 
3079 		return pDoc->GetNodes()[ pCnt->GetCntntIdx()->GetIndex() + 1 ]->GetOLENode()->GetAspect();
3080 	}
3081 
3082 	return embed::Aspects::MSOLE_CONTENT; // return the default value
3083 }
3084 
setAspect(sal_Int64 nAspect)3085 void SAL_CALL SwXTextEmbeddedObject::setAspect( sal_Int64 nAspect ) throw (uno::RuntimeException)
3086 {
3087 	SwFrmFmt* 	pFmt = GetFrmFmt();
3088 	if(pFmt)
3089 	{
3090 		SwDoc* pDoc = pFmt->GetDoc();
3091         const SwFmtCntnt* pCnt = &pFmt->GetCntnt();
3092 		DBG_ASSERT(	pCnt->GetCntntIdx() &&
3093 					   pDoc->GetNodes()[ pCnt->GetCntntIdx()->
3094 										GetIndex() + 1 ]->GetOLENode(), "kein OLE-Node?");
3095 
3096 		pDoc->GetNodes()[ pCnt->GetCntntIdx()->GetIndex() + 1 ]->GetOLENode()->SetAspect( nAspect );
3097 	}
3098 }
3099 
getReplacementGraphic()3100 uno::Reference< graphic::XGraphic > SAL_CALL SwXTextEmbeddedObject::getReplacementGraphic() throw (uno::RuntimeException)
3101 {
3102 	SwFrmFmt* 	pFmt = GetFrmFmt();
3103 	if(pFmt)
3104 	{
3105 		SwDoc* pDoc = pFmt->GetDoc();
3106         const SwFmtCntnt* pCnt = &pFmt->GetCntnt();
3107 		DBG_ASSERT(	pCnt->GetCntntIdx() &&
3108 					   pDoc->GetNodes()[ pCnt->GetCntntIdx()->
3109 										GetIndex() + 1 ]->GetOLENode(), "kein OLE-Node?");
3110 
3111 		Graphic* pGraphic = pDoc->GetNodes()[ pCnt->GetCntntIdx()->GetIndex() + 1 ]->GetOLENode()->GetGraphic();
3112 		if ( pGraphic )
3113 			return pGraphic->GetXGraphic();
3114 	}
3115 
3116 	return uno::Reference< graphic::XGraphic >();
3117 }
3118 
3119 
getImplementationName(void)3120 OUString SwXTextEmbeddedObject::getImplementationName(void) throw( uno::RuntimeException )
3121 
3122 {
3123 	return C2U("SwXTextEmbeddedObject");
3124 }
3125 
supportsService(const OUString & rServiceName)3126 sal_Bool SwXTextEmbeddedObject::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
3127 {
3128 	return  COMPARE_EQUAL == rServiceName.compareToAscii("com.sun.star.text.TextEmbeddedObject")||
3129 					SwXFrame::supportsService(rServiceName);
3130 }
3131 
getSupportedServiceNames(void)3132 uno::Sequence< OUString > SwXTextEmbeddedObject::getSupportedServiceNames(void)
3133 		throw( uno::RuntimeException )
3134 {
3135 	uno::Sequence < OUString > aRet = SwXFrame::getSupportedServiceNames();
3136 	aRet.realloc(aRet.getLength() + 1);
3137 	OUString* pArray = aRet.getArray();
3138 	pArray[aRet.getLength() - 1] = C2U("com.sun.star.text.TextEmbeddedObject");
3139 	return aRet;
3140 }
3141 
operator new(size_t t)3142 void * SAL_CALL SwXTextEmbeddedObject::operator new( size_t t) throw()
3143 {
3144 	return SwXTextEmbeddedObjectBaseClass::operator new(t);
3145 }
3146 
operator delete(void * p)3147 void SAL_CALL SwXTextEmbeddedObject::operator delete( void * p) throw()
3148 {
3149 	SwXTextEmbeddedObjectBaseClass::operator delete(p);
3150 }
3151 
3152 uno::Reference<container::XNameReplace> SAL_CALL
getEvents()3153 	SwXTextEmbeddedObject::getEvents()
3154 		throw(uno::RuntimeException)
3155 {
3156 	return new SwFrameEventDescriptor( *this );
3157 }
3158 
3159 
3160 /******************************************************************
3161  *
3162  ******************************************************************/
3163 TYPEINIT1(SwXOLEListener, SwClient);
3164 
SwXOLEListener(SwFmt & rOLEFmt,uno::Reference<XModel> xOLE)3165 SwXOLEListener::SwXOLEListener( SwFmt& rOLEFmt, uno::Reference< XModel > xOLE) :
3166     SwClient(&rOLEFmt),
3167     xOLEModel(xOLE)
3168 {
3169 }
3170 
~SwXOLEListener()3171 SwXOLEListener::~SwXOLEListener()
3172 {}
3173 
modified(const lang::EventObject &)3174 void SwXOLEListener::modified( const lang::EventObject& /*rEvent*/ )
3175 										throw( uno::RuntimeException )
3176 {
3177 	vos::OGuard aGuard(Application::GetSolarMutex());
3178 
3179     SwOLENode* pNd = 0;
3180     SwFmt* pFmt = GetFmt();
3181     if(pFmt)
3182     {const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
3183         if(pIdx)
3184         {
3185             SwNodeIndex aIdx(*pIdx, 1);
3186             SwNoTxtNode* pNoTxt = aIdx.GetNode().GetNoTxtNode();
3187             pNd = pNoTxt->GetOLENode();
3188         }
3189     }
3190     if(!pNd)
3191         throw uno::RuntimeException();
3192 
3193     uno::Reference < embed::XEmbeddedObject > xIP = pNd->GetOLEObj().GetOleRef();
3194     if ( xIP.is() )
3195     {
3196         sal_Int32 nState = xIP->getCurrentState();
3197         if ( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE )
3198             return;
3199     }
3200 
3201     // if the OLE-Node is UI-Active do nothing
3202     pNd->SetOLESizeInvalid( sal_True );
3203     pNd->GetDoc()->SetOLEObjModified();
3204 }
3205 
3206 /* ---------------------------------------------------------------------------
3207 
3208  ---------------------------------------------------------------------------*/
disposing(const lang::EventObject & rEvent)3209 void SwXOLEListener::disposing( const lang::EventObject& rEvent )
3210 						throw( uno::RuntimeException )
3211 {
3212 	vos::OGuard aGuard(Application::GetSolarMutex());
3213 
3214 	uno::Reference< util::XModifyListener >  xListener( this );
3215 
3216 
3217     uno::Reference< frame::XModel >  xModel( rEvent.Source, uno::UNO_QUERY );
3218     uno::Reference< util::XModifyBroadcaster >  xBrdcst(xModel, uno::UNO_QUERY);
3219 
3220     try
3221     {
3222         if( xBrdcst.is() )
3223 			xBrdcst->removeModifyListener( xListener );
3224     }
3225     catch(uno::Exception const &)
3226     {
3227         DBG_ERROR("OLE Listener couldn't be removed");
3228     }
3229 }
3230 /* ---------------------------------------------------------------------------
3231 
3232  ---------------------------------------------------------------------------*/
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)3233 void SwXOLEListener::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
3234 {
3235     ClientModify(this, pOld, pNew);
3236 	if(!GetRegisteredIn())
3237         xOLEModel = 0;
3238 }
3239 
3240