1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f6e50924SAndrew Rist * distributed with this work for additional information
6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10*f6e50924SAndrew Rist *
11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist *
13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17*f6e50924SAndrew Rist * specific language governing permissions and limitations
18*f6e50924SAndrew Rist * under the License.
19*f6e50924SAndrew Rist *
20*f6e50924SAndrew Rist *************************************************************/
21*f6e50924SAndrew Rist
22*f6e50924SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <com/sun/star/container/XIdentifierContainer.hpp>
27cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
28cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DRAWING_GLUEPOINT2_HDL_
29cdf0e10cSrcweir #include <com/sun/star/drawing/GluePoint2.hpp>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <svx/svdmodel.hxx>
35cdf0e10cSrcweir #include <svx/svdobj.hxx>
36cdf0e10cSrcweir #include <svx/svdglue.hxx>
37cdf0e10cSrcweir #include <svx/svdpage.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir using namespace ::rtl;
41cdf0e10cSrcweir using namespace ::cppu;
42cdf0e10cSrcweir
43cdf0e10cSrcweir const sal_uInt16 NON_USER_DEFINED_GLUE_POINTS = 4;
44cdf0e10cSrcweir
45cdf0e10cSrcweir class SvxUnoGluePointAccess : public WeakImplHelper2< container::XIndexContainer, container::XIdentifierContainer >
46cdf0e10cSrcweir {
47cdf0e10cSrcweir private:
48cdf0e10cSrcweir SdrObjectWeakRef mpObject;
49cdf0e10cSrcweir
50cdf0e10cSrcweir public:
51cdf0e10cSrcweir SvxUnoGluePointAccess( SdrObject* pObject ) throw();
52cdf0e10cSrcweir virtual ~SvxUnoGluePointAccess() throw();
53cdf0e10cSrcweir
54cdf0e10cSrcweir // XIdentifierContainer
55cdf0e10cSrcweir virtual sal_Int32 SAL_CALL insert( const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException);
56cdf0e10cSrcweir virtual void SAL_CALL removeByIdentifier( sal_Int32 Identifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
57cdf0e10cSrcweir
58cdf0e10cSrcweir // XIdentifierReplace
59cdf0e10cSrcweir virtual void SAL_CALL replaceByIdentifer( sal_Int32 Identifier, const uno::Any& aElement ) throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
60cdf0e10cSrcweir
61cdf0e10cSrcweir // XIdentifierReplace
62cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIdentifier( sal_Int32 Identifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
63cdf0e10cSrcweir virtual uno::Sequence< sal_Int32 > SAL_CALL getIdentifiers( ) throw (uno::RuntimeException);
64cdf0e10cSrcweir
65cdf0e10cSrcweir /* deprecated */
66cdf0e10cSrcweir // XIndexContainer
67cdf0e10cSrcweir virtual void SAL_CALL insertByIndex( sal_Int32 Index, const uno::Any& Element ) throw(lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException);
68cdf0e10cSrcweir virtual void SAL_CALL removeByIndex( sal_Int32 Index ) throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException);
69cdf0e10cSrcweir
70cdf0e10cSrcweir /* deprecated */
71cdf0e10cSrcweir // XIndexReplace
72cdf0e10cSrcweir virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const uno::Any& Element ) throw(lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException);
73cdf0e10cSrcweir
74cdf0e10cSrcweir /* deprecated */
75cdf0e10cSrcweir // XIndexAccess
76cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getCount( ) throw(uno::RuntimeException);
77cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException);
78cdf0e10cSrcweir
79cdf0e10cSrcweir // XElementAccess
80cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw( uno::RuntimeException);
81cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements( ) throw( uno::RuntimeException);
82cdf0e10cSrcweir };
83cdf0e10cSrcweir
convert(const SdrGluePoint & rSdrGlue,drawing::GluePoint2 & rUnoGlue)84cdf0e10cSrcweir static void convert( const SdrGluePoint& rSdrGlue, drawing::GluePoint2& rUnoGlue ) throw()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir rUnoGlue.Position.X = rSdrGlue.GetPos().X();
87cdf0e10cSrcweir rUnoGlue.Position.Y = rSdrGlue.GetPos().Y();
88cdf0e10cSrcweir rUnoGlue.IsRelative = rSdrGlue.IsPercent();
89cdf0e10cSrcweir
90cdf0e10cSrcweir switch( rSdrGlue.GetAlign() )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir case SDRVERTALIGN_TOP|SDRHORZALIGN_LEFT:
93cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_TOP_LEFT;
94cdf0e10cSrcweir break;
95cdf0e10cSrcweir case SDRHORZALIGN_CENTER|SDRVERTALIGN_TOP:
96cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_TOP;
97cdf0e10cSrcweir break;
98cdf0e10cSrcweir case SDRVERTALIGN_TOP|SDRHORZALIGN_RIGHT:
99cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_TOP_RIGHT;
100cdf0e10cSrcweir break;
101cdf0e10cSrcweir case SDRHORZALIGN_CENTER|SDRVERTALIGN_CENTER:
102cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_CENTER;
103cdf0e10cSrcweir break;
104cdf0e10cSrcweir case SDRHORZALIGN_RIGHT|SDRVERTALIGN_CENTER:
105cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_RIGHT;
106cdf0e10cSrcweir break;
107cdf0e10cSrcweir case SDRHORZALIGN_LEFT|SDRVERTALIGN_BOTTOM:
108cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_BOTTOM_LEFT;
109cdf0e10cSrcweir break;
110cdf0e10cSrcweir case SDRHORZALIGN_CENTER|SDRVERTALIGN_BOTTOM:
111cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_BOTTOM;
112cdf0e10cSrcweir break;
113cdf0e10cSrcweir case SDRHORZALIGN_RIGHT|SDRVERTALIGN_BOTTOM:
114cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_BOTTOM_RIGHT;
115cdf0e10cSrcweir break;
116cdf0e10cSrcweir // case SDRHORZALIGN_LEFT:
117cdf0e10cSrcweir default:
118cdf0e10cSrcweir rUnoGlue.PositionAlignment = drawing::Alignment_LEFT;
119cdf0e10cSrcweir break;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
122cdf0e10cSrcweir switch( rSdrGlue.GetEscDir() )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir case SDRESC_LEFT:
125cdf0e10cSrcweir rUnoGlue.Escape = drawing::EscapeDirection_LEFT;
126cdf0e10cSrcweir break;
127cdf0e10cSrcweir case SDRESC_RIGHT:
128cdf0e10cSrcweir rUnoGlue.Escape = drawing::EscapeDirection_RIGHT;
129cdf0e10cSrcweir break;
130cdf0e10cSrcweir case SDRESC_TOP:
131cdf0e10cSrcweir rUnoGlue.Escape = drawing::EscapeDirection_UP;
132cdf0e10cSrcweir break;
133cdf0e10cSrcweir case SDRESC_BOTTOM:
134cdf0e10cSrcweir rUnoGlue.Escape = drawing::EscapeDirection_DOWN;
135cdf0e10cSrcweir break;
136cdf0e10cSrcweir case SDRESC_HORZ:
137cdf0e10cSrcweir rUnoGlue.Escape = drawing::EscapeDirection_HORIZONTAL;
138cdf0e10cSrcweir break;
139cdf0e10cSrcweir case SDRESC_VERT:
140cdf0e10cSrcweir rUnoGlue.Escape = drawing::EscapeDirection_VERTICAL;
141cdf0e10cSrcweir break;
142cdf0e10cSrcweir // case SDRESC_SMART:
143cdf0e10cSrcweir default:
144cdf0e10cSrcweir rUnoGlue.Escape = drawing::EscapeDirection_SMART;
145cdf0e10cSrcweir break;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
convert(const drawing::GluePoint2 & rUnoGlue,SdrGluePoint & rSdrGlue)149cdf0e10cSrcweir static void convert( const drawing::GluePoint2& rUnoGlue, SdrGluePoint& rSdrGlue ) throw()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir rSdrGlue.SetPos( Point( rUnoGlue.Position.X, rUnoGlue.Position.Y ) );
152cdf0e10cSrcweir rSdrGlue.SetPercent( rUnoGlue.IsRelative );
153cdf0e10cSrcweir
154cdf0e10cSrcweir switch( rUnoGlue.PositionAlignment )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir case drawing::Alignment_TOP_LEFT:
157cdf0e10cSrcweir rSdrGlue.SetAlign( SDRVERTALIGN_TOP|SDRHORZALIGN_LEFT );
158cdf0e10cSrcweir break;
159cdf0e10cSrcweir case drawing::Alignment_TOP:
160cdf0e10cSrcweir rSdrGlue.SetAlign( SDRHORZALIGN_CENTER|SDRVERTALIGN_TOP );
161cdf0e10cSrcweir break;
162cdf0e10cSrcweir case drawing::Alignment_TOP_RIGHT:
163cdf0e10cSrcweir rSdrGlue.SetAlign( SDRVERTALIGN_TOP|SDRHORZALIGN_RIGHT );
164cdf0e10cSrcweir break;
165cdf0e10cSrcweir case drawing::Alignment_CENTER:
166cdf0e10cSrcweir rSdrGlue.SetAlign( SDRHORZALIGN_CENTER|SDRVERTALIGN_CENTER );
167cdf0e10cSrcweir break;
168cdf0e10cSrcweir case drawing::Alignment_RIGHT:
169cdf0e10cSrcweir rSdrGlue.SetAlign( SDRHORZALIGN_RIGHT|SDRVERTALIGN_CENTER );
170cdf0e10cSrcweir break;
171cdf0e10cSrcweir case drawing::Alignment_BOTTOM_LEFT:
172cdf0e10cSrcweir rSdrGlue.SetAlign( SDRHORZALIGN_LEFT|SDRVERTALIGN_BOTTOM );
173cdf0e10cSrcweir break;
174cdf0e10cSrcweir case drawing::Alignment_BOTTOM:
175cdf0e10cSrcweir rSdrGlue.SetAlign( SDRHORZALIGN_CENTER|SDRVERTALIGN_BOTTOM );
176cdf0e10cSrcweir break;
177cdf0e10cSrcweir case drawing::Alignment_BOTTOM_RIGHT:
178cdf0e10cSrcweir rSdrGlue.SetAlign( SDRHORZALIGN_RIGHT|SDRVERTALIGN_BOTTOM );
179cdf0e10cSrcweir break;
180cdf0e10cSrcweir // case SDRHORZALIGN_LEFT:
181cdf0e10cSrcweir default:
182cdf0e10cSrcweir rSdrGlue.SetAlign( SDRHORZALIGN_LEFT );
183cdf0e10cSrcweir break;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir switch( rUnoGlue.Escape )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir case drawing::EscapeDirection_LEFT:
188cdf0e10cSrcweir rSdrGlue.SetEscDir(SDRESC_LEFT);
189cdf0e10cSrcweir break;
190cdf0e10cSrcweir case drawing::EscapeDirection_RIGHT:
191cdf0e10cSrcweir rSdrGlue.SetEscDir(SDRESC_RIGHT);
192cdf0e10cSrcweir break;
193cdf0e10cSrcweir case drawing::EscapeDirection_UP:
194cdf0e10cSrcweir rSdrGlue.SetEscDir(SDRESC_TOP);
195cdf0e10cSrcweir break;
196cdf0e10cSrcweir case drawing::EscapeDirection_DOWN:
197cdf0e10cSrcweir rSdrGlue.SetEscDir(SDRESC_BOTTOM);
198cdf0e10cSrcweir break;
199cdf0e10cSrcweir case drawing::EscapeDirection_HORIZONTAL:
200cdf0e10cSrcweir rSdrGlue.SetEscDir(SDRESC_HORZ);
201cdf0e10cSrcweir break;
202cdf0e10cSrcweir case drawing::EscapeDirection_VERTICAL:
203cdf0e10cSrcweir rSdrGlue.SetEscDir(SDRESC_VERT);
204cdf0e10cSrcweir break;
205cdf0e10cSrcweir // case drawing::EscapeDirection_SMART:
206cdf0e10cSrcweir default:
207cdf0e10cSrcweir rSdrGlue.SetEscDir(SDRESC_SMART);
208cdf0e10cSrcweir break;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
SvxUnoGluePointAccess(SdrObject * pObject)212cdf0e10cSrcweir SvxUnoGluePointAccess::SvxUnoGluePointAccess( SdrObject* pObject ) throw()
213cdf0e10cSrcweir : mpObject( pObject )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
~SvxUnoGluePointAccess()217cdf0e10cSrcweir SvxUnoGluePointAccess::~SvxUnoGluePointAccess() throw()
218cdf0e10cSrcweir {
219cdf0e10cSrcweir }
220cdf0e10cSrcweir
221cdf0e10cSrcweir // XIdentifierContainer
insert(const uno::Any & aElement)222cdf0e10cSrcweir sal_Int32 SAL_CALL SvxUnoGluePointAccess::insert( const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir if( mpObject.is() )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir SdrGluePointList* pList = mpObject->ForceGluePointList();
227cdf0e10cSrcweir if( pList )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir // second, insert the new glue point
230cdf0e10cSrcweir drawing::GluePoint2 aUnoGlue;
231cdf0e10cSrcweir
232cdf0e10cSrcweir if( aElement >>= aUnoGlue )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir SdrGluePoint aSdrGlue;
235cdf0e10cSrcweir convert( aUnoGlue, aSdrGlue );
236cdf0e10cSrcweir sal_uInt16 nId = pList->Insert( aSdrGlue );
237cdf0e10cSrcweir
238cdf0e10cSrcweir // only repaint, no objectchange
239cdf0e10cSrcweir mpObject->ActionChanged();
240cdf0e10cSrcweir // mpObject->BroadcastObjectChange();
241cdf0e10cSrcweir
242cdf0e10cSrcweir return (sal_Int32)((*pList)[nId].GetId() + NON_USER_DEFINED_GLUE_POINTS) - 1;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir throw lang::IllegalArgumentException();
246cdf0e10cSrcweir }
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
249cdf0e10cSrcweir return -1;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
removeByIdentifier(sal_Int32 Identifier)252cdf0e10cSrcweir void SAL_CALL SvxUnoGluePointAccess::removeByIdentifier( sal_Int32 Identifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir if( mpObject.is() && ( Identifier >= NON_USER_DEFINED_GLUE_POINTS ))
255cdf0e10cSrcweir {
256cdf0e10cSrcweir const sal_uInt16 nId = (sal_uInt16)(Identifier - NON_USER_DEFINED_GLUE_POINTS) + 1;
257cdf0e10cSrcweir
258cdf0e10cSrcweir SdrGluePointList* pList = const_cast<SdrGluePointList*>(mpObject->GetGluePointList());
259cdf0e10cSrcweir const sal_uInt16 nCount = pList ? pList->GetCount() : 0;
260cdf0e10cSrcweir sal_uInt16 i;
261cdf0e10cSrcweir
262cdf0e10cSrcweir for( i = 0; i < nCount; i++ )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir if( (*pList)[i].GetId() == nId )
265cdf0e10cSrcweir {
266cdf0e10cSrcweir pList->Delete( i );
267cdf0e10cSrcweir
268cdf0e10cSrcweir // only repaint, no objectchange
269cdf0e10cSrcweir mpObject->ActionChanged();
270cdf0e10cSrcweir // mpObject->BroadcastObjectChange();
271cdf0e10cSrcweir
272cdf0e10cSrcweir return;
273cdf0e10cSrcweir }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir throw container::NoSuchElementException();
278cdf0e10cSrcweir }
279cdf0e10cSrcweir
280cdf0e10cSrcweir // XIdentifierReplace
replaceByIdentifer(sal_Int32 Identifier,const uno::Any & aElement)281cdf0e10cSrcweir void SAL_CALL SvxUnoGluePointAccess::replaceByIdentifer( sal_Int32 Identifier, const uno::Any& aElement ) throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
282cdf0e10cSrcweir {
283cdf0e10cSrcweir if( mpObject.is() && mpObject->IsNode() )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir struct drawing::GluePoint2 aGluePoint;
286cdf0e10cSrcweir if( (Identifier < NON_USER_DEFINED_GLUE_POINTS) || !(aElement >>= aGluePoint))
287cdf0e10cSrcweir throw lang::IllegalArgumentException();
288cdf0e10cSrcweir
289cdf0e10cSrcweir const sal_uInt16 nId = (sal_uInt16)( Identifier - NON_USER_DEFINED_GLUE_POINTS ) + 1;
290cdf0e10cSrcweir
291cdf0e10cSrcweir SdrGluePointList* pList = const_cast< SdrGluePointList* >( mpObject->GetGluePointList() );
292cdf0e10cSrcweir const sal_uInt16 nCount = pList ? pList->GetCount() : 0;
293cdf0e10cSrcweir sal_uInt16 i;
294cdf0e10cSrcweir for( i = 0; i < nCount; i++ )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir if( (*pList)[i].GetId() == nId )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir // change the glue point
299cdf0e10cSrcweir SdrGluePoint& rTempPoint = (*pList)[i];
300cdf0e10cSrcweir convert( aGluePoint, rTempPoint );
301cdf0e10cSrcweir
302cdf0e10cSrcweir // only repaint, no objectchange
303cdf0e10cSrcweir mpObject->ActionChanged();
304cdf0e10cSrcweir // mpObject->BroadcastObjectChange();
305cdf0e10cSrcweir
306cdf0e10cSrcweir return;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir }
309cdf0e10cSrcweir
310cdf0e10cSrcweir throw container::NoSuchElementException();
311cdf0e10cSrcweir }
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
314cdf0e10cSrcweir // XIdentifierAccess
getByIdentifier(sal_Int32 Identifier)315cdf0e10cSrcweir uno::Any SAL_CALL SvxUnoGluePointAccess::getByIdentifier( sal_Int32 Identifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir if( mpObject.is() && mpObject->IsNode() )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir struct drawing::GluePoint2 aGluePoint;
320cdf0e10cSrcweir
321cdf0e10cSrcweir if( Identifier < NON_USER_DEFINED_GLUE_POINTS ) // default glue point?
322cdf0e10cSrcweir {
323cdf0e10cSrcweir SdrGluePoint aTempPoint = mpObject->GetVertexGluePoint( (sal_uInt16)Identifier );
324cdf0e10cSrcweir aGluePoint.IsUserDefined = sal_False;
325cdf0e10cSrcweir convert( aTempPoint, aGluePoint );
326cdf0e10cSrcweir return uno::makeAny( aGluePoint );
327cdf0e10cSrcweir }
328cdf0e10cSrcweir else
329cdf0e10cSrcweir {
330cdf0e10cSrcweir const sal_uInt16 nId = (sal_uInt16)( Identifier - NON_USER_DEFINED_GLUE_POINTS ) + 1;
331cdf0e10cSrcweir
332cdf0e10cSrcweir const SdrGluePointList* pList = mpObject->GetGluePointList();
333cdf0e10cSrcweir const sal_uInt16 nCount = pList ? pList->GetCount() : 0;
334cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nCount; i++ )
335cdf0e10cSrcweir {
336cdf0e10cSrcweir const SdrGluePoint& rTempPoint = (*pList)[i];
337cdf0e10cSrcweir if( rTempPoint.GetId() == nId )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir // #i38892#
340cdf0e10cSrcweir if(rTempPoint.IsUserDefined())
341cdf0e10cSrcweir {
342cdf0e10cSrcweir aGluePoint.IsUserDefined = sal_True;
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
345cdf0e10cSrcweir convert( rTempPoint, aGluePoint );
346cdf0e10cSrcweir return uno::makeAny( aGluePoint );
347cdf0e10cSrcweir }
348cdf0e10cSrcweir }
349cdf0e10cSrcweir }
350cdf0e10cSrcweir }
351cdf0e10cSrcweir
352cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
353cdf0e10cSrcweir }
354cdf0e10cSrcweir
getIdentifiers()355cdf0e10cSrcweir uno::Sequence< sal_Int32 > SAL_CALL SvxUnoGluePointAccess::getIdentifiers() throw (uno::RuntimeException)
356cdf0e10cSrcweir {
357cdf0e10cSrcweir if( mpObject.is() )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir const SdrGluePointList* pList = mpObject->GetGluePointList();
360cdf0e10cSrcweir const sal_uInt16 nCount = pList ? pList->GetCount() : 0;
361cdf0e10cSrcweir
362cdf0e10cSrcweir sal_uInt16 i;
363cdf0e10cSrcweir
364cdf0e10cSrcweir uno::Sequence< sal_Int32 > aIdSequence( nCount + NON_USER_DEFINED_GLUE_POINTS );
365cdf0e10cSrcweir sal_Int32 *pIdentifier = aIdSequence.getArray();
366cdf0e10cSrcweir
367cdf0e10cSrcweir for( i = 0; i < NON_USER_DEFINED_GLUE_POINTS; i++ )
368cdf0e10cSrcweir *pIdentifier++ = (sal_Int32)i;
369cdf0e10cSrcweir
370cdf0e10cSrcweir for( i = 0; i < nCount; i++ )
371cdf0e10cSrcweir *pIdentifier++ = (sal_Int32) ( (*pList)[i].GetId() + NON_USER_DEFINED_GLUE_POINTS ) - 1;
372cdf0e10cSrcweir
373cdf0e10cSrcweir return aIdSequence;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir else
376cdf0e10cSrcweir {
377cdf0e10cSrcweir uno::Sequence< sal_Int32 > aEmpty;
378cdf0e10cSrcweir return aEmpty;
379cdf0e10cSrcweir }
380cdf0e10cSrcweir }
381cdf0e10cSrcweir
382cdf0e10cSrcweir /* deprecated */
383cdf0e10cSrcweir
384cdf0e10cSrcweir // XIndexContainer
insertByIndex(sal_Int32,const uno::Any & Element)385cdf0e10cSrcweir void SAL_CALL SvxUnoGluePointAccess::insertByIndex( sal_Int32, const uno::Any& Element )
386cdf0e10cSrcweir throw(lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
387cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException)
388cdf0e10cSrcweir {
389cdf0e10cSrcweir if( mpObject.is() )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir SdrGluePointList* pList = mpObject->ForceGluePointList();
392cdf0e10cSrcweir if( pList )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir SdrGluePoint aSdrGlue;
395cdf0e10cSrcweir drawing::GluePoint2 aUnoGlue;
396cdf0e10cSrcweir
397cdf0e10cSrcweir if( Element >>= aUnoGlue )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir convert( aUnoGlue, aSdrGlue );
400cdf0e10cSrcweir pList->Insert( aSdrGlue );
401cdf0e10cSrcweir
402cdf0e10cSrcweir // only repaint, no objectchange
403cdf0e10cSrcweir mpObject->ActionChanged();
404cdf0e10cSrcweir // mpObject->BroadcastObjectChange();
405cdf0e10cSrcweir
406cdf0e10cSrcweir return;
407cdf0e10cSrcweir }
408cdf0e10cSrcweir
409cdf0e10cSrcweir throw lang::IllegalArgumentException();
410cdf0e10cSrcweir }
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
413cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
414cdf0e10cSrcweir }
415cdf0e10cSrcweir
removeByIndex(sal_Int32 Index)416cdf0e10cSrcweir void SAL_CALL SvxUnoGluePointAccess::removeByIndex( sal_Int32 Index )
417cdf0e10cSrcweir throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
418cdf0e10cSrcweir {
419cdf0e10cSrcweir if( mpObject.is() )
420cdf0e10cSrcweir {
421cdf0e10cSrcweir SdrGluePointList* pList = mpObject->ForceGluePointList();
422cdf0e10cSrcweir if( pList )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir Index -= 4;
425cdf0e10cSrcweir if( Index >= 0 && Index < pList->GetCount() )
426cdf0e10cSrcweir {
427cdf0e10cSrcweir pList->Delete( (sal_uInt16)Index );
428cdf0e10cSrcweir
429cdf0e10cSrcweir // only repaint, no objectchange
430cdf0e10cSrcweir mpObject->ActionChanged();
431cdf0e10cSrcweir // mpObject->BroadcastObjectChange();
432cdf0e10cSrcweir
433cdf0e10cSrcweir return;
434cdf0e10cSrcweir }
435cdf0e10cSrcweir }
436cdf0e10cSrcweir }
437cdf0e10cSrcweir
438cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
441cdf0e10cSrcweir // XIndexReplace
replaceByIndex(sal_Int32 Index,const uno::Any & Element)442cdf0e10cSrcweir void SAL_CALL SvxUnoGluePointAccess::replaceByIndex( sal_Int32 Index, const uno::Any& Element )
443cdf0e10cSrcweir throw(lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException,
444cdf0e10cSrcweir uno::RuntimeException)
445cdf0e10cSrcweir {
446cdf0e10cSrcweir drawing::GluePoint2 aUnoGlue;
447cdf0e10cSrcweir if(!(Element >>= aUnoGlue))
448cdf0e10cSrcweir throw lang::IllegalArgumentException();
449cdf0e10cSrcweir
450cdf0e10cSrcweir Index -= 4;
451cdf0e10cSrcweir if( mpObject.is() && Index >= 0 )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir SdrGluePointList* pList = const_cast< SdrGluePointList* >( mpObject->GetGluePointList() );
454cdf0e10cSrcweir if( pList && Index < pList->GetCount() )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir SdrGluePoint& rGlue = (*pList)[(sal_uInt16)Index];
457cdf0e10cSrcweir convert( aUnoGlue, rGlue );
458cdf0e10cSrcweir
459cdf0e10cSrcweir // only repaint, no objectchange
460cdf0e10cSrcweir mpObject->ActionChanged();
461cdf0e10cSrcweir // mpObject->BroadcastObjectChange();
462cdf0e10cSrcweir }
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
466cdf0e10cSrcweir }
467cdf0e10cSrcweir
468cdf0e10cSrcweir // XIndexAccess
getCount()469cdf0e10cSrcweir sal_Int32 SAL_CALL SvxUnoGluePointAccess::getCount()
470cdf0e10cSrcweir throw(uno::RuntimeException)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir sal_Int32 nCount = 0;
473cdf0e10cSrcweir if( mpObject.is() )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir // each node has a default of 4 glue points
476cdf0e10cSrcweir // and any number of user defined glue points
477cdf0e10cSrcweir if( mpObject->IsNode() )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir nCount += 4;
480cdf0e10cSrcweir
481cdf0e10cSrcweir const SdrGluePointList* pList = mpObject->GetGluePointList();
482cdf0e10cSrcweir if( pList )
483cdf0e10cSrcweir nCount += pList->GetCount();
484cdf0e10cSrcweir }
485cdf0e10cSrcweir }
486cdf0e10cSrcweir
487cdf0e10cSrcweir return nCount;
488cdf0e10cSrcweir }
489cdf0e10cSrcweir
getByIndex(sal_Int32 Index)490cdf0e10cSrcweir uno::Any SAL_CALL SvxUnoGluePointAccess::getByIndex( sal_Int32 Index )
491cdf0e10cSrcweir throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir if( Index >= 0 && mpObject.is() && mpObject->IsNode() )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir struct drawing::GluePoint2 aGluePoint;
496cdf0e10cSrcweir
497cdf0e10cSrcweir if( Index < 4 ) // default glue point?
498cdf0e10cSrcweir {
499cdf0e10cSrcweir SdrGluePoint aTempPoint = mpObject->GetVertexGluePoint( (sal_uInt16)Index );
500cdf0e10cSrcweir aGluePoint.IsUserDefined = sal_False;
501cdf0e10cSrcweir convert( aTempPoint, aGluePoint );
502cdf0e10cSrcweir uno::Any aAny;
503cdf0e10cSrcweir aAny <<= aGluePoint;
504cdf0e10cSrcweir return aAny;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir else
507cdf0e10cSrcweir {
508cdf0e10cSrcweir Index -= 4;
509cdf0e10cSrcweir const SdrGluePointList* pList = mpObject->GetGluePointList();
510cdf0e10cSrcweir if( pList && Index < pList->GetCount() )
511cdf0e10cSrcweir {
512cdf0e10cSrcweir const SdrGluePoint& rTempPoint = (*pList)[(sal_uInt16)Index];
513cdf0e10cSrcweir aGluePoint.IsUserDefined = sal_True;
514cdf0e10cSrcweir convert( rTempPoint, aGluePoint );
515cdf0e10cSrcweir uno::Any aAny;
516cdf0e10cSrcweir aAny <<= aGluePoint;
517cdf0e10cSrcweir return aAny;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir }
520cdf0e10cSrcweir }
521cdf0e10cSrcweir
522cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
523cdf0e10cSrcweir }
524cdf0e10cSrcweir
525cdf0e10cSrcweir // XElementAccess
getElementType()526cdf0e10cSrcweir uno::Type SAL_CALL SvxUnoGluePointAccess::getElementType()
527cdf0e10cSrcweir throw( uno::RuntimeException)
528cdf0e10cSrcweir {
529cdf0e10cSrcweir return ::getCppuType((const struct drawing::GluePoint2*)0);
530cdf0e10cSrcweir }
531cdf0e10cSrcweir
hasElements()532cdf0e10cSrcweir sal_Bool SAL_CALL SvxUnoGluePointAccess::hasElements()
533cdf0e10cSrcweir throw( uno::RuntimeException)
534cdf0e10cSrcweir {
535cdf0e10cSrcweir return mpObject.is() && mpObject->IsNode();
536cdf0e10cSrcweir }
537cdf0e10cSrcweir
538cdf0e10cSrcweir /**
539cdf0e10cSrcweir * Create a SvxUnoGluePointAccess
540cdf0e10cSrcweir */
SvxUnoGluePointAccess_createInstance(SdrObject * pObject)541cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL SvxUnoGluePointAccess_createInstance( SdrObject* pObject )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir return *new SvxUnoGluePointAccess(pObject);
544cdf0e10cSrcweir }
545