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 #ifndef INCLUDED_BASEGFX_UNOPOLYPOLYGON_HXX
25 #define INCLUDED_BASEGFX_UNOPOLYPOLYGON_HXX
26 
27 #include <cppuhelper/basemutex.hxx>
28 #include <cppuhelper/compbase3.hxx>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/rendering/FillRule.hpp>
31 #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp>
32 #include <com/sun/star/rendering/XBezierPolyPolygon2D.hpp>
33 #include <basegfx/polygon/b2dpolypolygon.hxx>
34 
35 
36 namespace basegfx
37 {
38 namespace unotools
39 {
40     typedef ::cppu::WeakComponentImplHelper3<
41        	  ::com::sun::star::rendering::XLinePolyPolygon2D,
42           ::com::sun::star::rendering::XBezierPolyPolygon2D,
43           ::com::sun::star::lang::XServiceInfo > UnoPolyPolygonBase;
44 
45     class UnoPolyPolygon : private cppu::BaseMutex,
46                            public UnoPolyPolygonBase
47     {
48     public:
49         explicit UnoPolyPolygon( const B2DPolyPolygon& );
50 
51         // XPolyPolygon2D
52         virtual void SAL_CALL addPolyPolygon( const ::com::sun::star::geometry::RealPoint2D& position, const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& polyPolygon ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
53         virtual ::sal_Int32 SAL_CALL getNumberOfPolygons(  ) throw (::com::sun::star::uno::RuntimeException);
54         virtual ::sal_Int32 SAL_CALL getNumberOfPolygonPoints( ::sal_Int32 polygon ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
55         virtual ::com::sun::star::rendering::FillRule SAL_CALL getFillRule(  ) throw (::com::sun::star::uno::RuntimeException);
56         virtual void SAL_CALL setFillRule( ::com::sun::star::rendering::FillRule fillRule ) throw (::com::sun::star::uno::RuntimeException);
57         virtual ::sal_Bool SAL_CALL isClosed( ::sal_Int32 index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
58         virtual void SAL_CALL setClosed( ::sal_Int32 index, ::sal_Bool closedState ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
59 
60         // XLinePolyPolygon2D
61         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > > SAL_CALL getPoints( ::sal_Int32 nPolygonIndex, ::sal_Int32 nNumberOfPolygons, ::sal_Int32 nPointIndex, ::sal_Int32 nNumberOfPoints ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
62         virtual void SAL_CALL setPoints( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& points, ::sal_Int32 nPolygonIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
63         virtual ::com::sun::star::geometry::RealPoint2D SAL_CALL getPoint( ::sal_Int32 nPolygonIndex, ::sal_Int32 nPointIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
64         virtual void SAL_CALL setPoint( const ::com::sun::star::geometry::RealPoint2D& point, ::sal_Int32 nPolygonIndex, ::sal_Int32 nPointIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
65 
66         // XBezierPolyPolygon2D
67         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > > SAL_CALL getBezierSegments( ::sal_Int32 nPolygonIndex, ::sal_Int32 nNumberOfPolygons, ::sal_Int32 nPointIndex, ::sal_Int32 nNumberOfPoints ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
68         virtual void SAL_CALL setBezierSegments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > >& points, ::sal_Int32 nPolygonIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
69         virtual ::com::sun::star::geometry::RealBezierSegment2D SAL_CALL getBezierSegment( ::sal_Int32 nPolygonIndex, ::sal_Int32 nPointIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
70         virtual void SAL_CALL setBezierSegment( const ::com::sun::star::geometry::RealBezierSegment2D& point, ::sal_Int32 nPolygonIndex, ::sal_Int32 nPointIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
71 
72         // XServiceInfo
73         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
74         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
75         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw( ::com::sun::star::uno::RuntimeException );
76 
77         B2DPolyPolygon getPolyPolygon() const;
78 
79     protected:
80         /// Check whether index is a valid polygon index
checkIndex(sal_Int32 nIndex) const81         void checkIndex( sal_Int32 nIndex ) const // throw (::com::sun::star::lang::IndexOutOfBoundsException);
82         {
83             if( nIndex < 0 || nIndex >= static_cast<sal_Int32>(maPolyPoly.count()) )
84                 throw ::com::sun::star::lang::IndexOutOfBoundsException();
85         }
86 
87         B2DPolyPolygon getSubsetPolyPolygon( sal_Int32 nPolygonIndex,
88                                              sal_Int32 nNumberOfPolygons,
89                                              sal_Int32 nPointIndex,
90                                              sal_Int32 nNumberOfPoints ) const;
91 
92         /// Get cow copy of internal polygon. not thread-safe outside this object.
93         B2DPolyPolygon getPolyPolygonUnsafe() const;
94 
95         /// Called whenever internal polypolygon gets modified
modifying() const96         virtual void modifying() const {}
97 
98     private:
99         UnoPolyPolygon( const UnoPolyPolygon& );
100         UnoPolyPolygon& operator=( const UnoPolyPolygon& );
101 
102         B2DPolyPolygon                        maPolyPoly;
103         ::com::sun::star::rendering::FillRule meFillRule;
104     };
105 }
106 }
107 
108 #endif /* INCLUDED_BASEGFX_UNOPOLYPOLYGON_HXX */
109