1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef INCLUDED_SLIDESHOW_SHAPEIMPORTER_HXX
28 #define INCLUDED_SLIDESHOW_SHAPEIMPORTER_HXX
29 
30 #include <com/sun/star/drawing/XDrawPage.hpp>
31 #include <com/sun/star/drawing/XShapes.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/drawing/XLayer.hpp>
34 #include "unoviewcontainer.hxx"
35 #include "unoview.hxx"
36 
37 #include "shape.hxx"
38 
39 #include <stack>
40 
41 namespace slideshow {
42 namespace internal {
43 
44 struct SlideShowContext;
45 
46 typedef ::std::vector< ::cppcanvas::PolyPolygonSharedPtr> PolyPolygonVector;
47 typedef ::boost::shared_ptr< UnoView > 		UnoViewSharedPtr;
48 typedef ::std::vector< UnoViewSharedPtr >	UnoViewVector;
49 
50 /** This class imports all shapes from a given XShapes object
51  */
52 class ShapeImporter
53 {
54 public:
55     /** Create shape importer.
56 
57         @param xPage
58         Page containing the shapes
59 
60         @param xActualPage
61         Actual page that's imported - if xPage is a master
62         page, this argument must refer to the using, i.e the
63         page that embeds this specific masterpage. Otherwise,
64         this argument is probably equal to xPage.
65 
66         @param nOrdNumStart
67         Each shape receives a z order number, in order of
68         import (which relies on the fact that the API returns
69         the shapes in draw order - which it does,
70         currently). Since we might mix several pages on screen
71         (e.g. master page and foreground page), this value can
72         be used as an offset to distinguish those pages.
73 
74         @param bConvertingMasterPage
75         When true, then the master page is imported. Otherwise, this
76         object imports the draw page.
77     */
78     ShapeImporter( const ::com::sun::star::uno::Reference<
79                          ::com::sun::star::drawing::XDrawPage >& xPage,
80                    const ::com::sun::star::uno::Reference<
81                          ::com::sun::star::drawing::XDrawPage >& xActualPage,
82                    const ::com::sun::star::uno::Reference<
83                          ::com::sun::star::drawing::XDrawPagesSupplier>& xPagesSupplier,
84                    const SlideShowContext&                       rContext,
85                    sal_Int32                                     nOrdNumStart,
86                    bool                                          bConvertingMasterPage );
87 
88     /** This method imports the presentation background shape
89      */
90     ShapeSharedPtr importBackgroundShape(); // throw (ShapeLoadFailedException)
91 
92     /** This method imports presentation-visible shapes (and skips all others).
93 
94         @return the generated Shape, or NULL for no more shapes.
95     */
96     ShapeSharedPtr importShape(); // throw (ConversionFailedException)
97 
98     /** Test whether import is done.
99 
100         @return true, if all shapes are imported via the
101         importShape() call.
102     */
103     bool isImportDone() const;
104     PolyPolygonVector getPolygons();
105 private:
106     bool isSkip( ::com::sun::star::uno::Reference<
107                  ::com::sun::star::beans::XPropertySet> const& xPropSet,
108                  ::rtl::OUString const& shapeType,
109              ::com::sun::star::uno::Reference<
110              ::com::sun::star::drawing::XLayer> const& xLayer);
111 
112     ShapeSharedPtr createShape(
113         ::com::sun::star::uno::Reference<
114         ::com::sun::star::drawing::XShape> const& xCurrShape,
115         ::com::sun::star::uno::Reference<
116         ::com::sun::star::beans::XPropertySet> const& xPropSet,
117         ::rtl::OUString const& shapeType ) const;
118 
119     void importPolygons(::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > const& xPropSet) ;
120 
121     struct XShapesEntry
122     {
123         ShapeSharedPtr const mpGroupShape;
124         ::com::sun::star::uno::Reference<
125             ::com::sun::star::drawing::XShapes> const mxShapes;
126         sal_Int32 const mnCount;
127         sal_Int32 mnPos;
128 
129         explicit XShapesEntry( ShapeSharedPtr const& pGroupShape )
130             : mpGroupShape(pGroupShape),
131               mxShapes( pGroupShape->getXShape(),
132                         ::com::sun::star::uno::UNO_QUERY_THROW ),
133               mnCount(mxShapes->getCount()), mnPos(0) {}
134         explicit XShapesEntry( ::com::sun::star::uno::Reference<
135                       ::com::sun::star::drawing::XShapes> const& xShapes )
136             : mpGroupShape(), mxShapes(xShapes),
137               mnCount(xShapes->getCount()), mnPos(0) {}
138     };
139     typedef ::std::stack<XShapesEntry> XShapesStack;
140 
141     ::com::sun::star::uno::Reference<
142         ::com::sun::star::drawing::XDrawPage> mxPage;
143     ::com::sun::star::uno::Reference<
144         ::com::sun::star::drawing::XDrawPagesSupplier> mxPagesSupplier;
145     const SlideShowContext&                   mrContext;
146     PolyPolygonVector                         maPolygons;
147     XShapesStack                              maShapesStack;
148     double                                    mnAscendingPrio;
149     bool                                      mbConvertingMasterPage;
150 };
151 
152 } // namespace internal
153 } // namespace presentation
154 
155 #endif
156