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 #ifndef OOX_SHAPE_SHAPE_CONTEXT_HANDLER_HXX
24 #define OOX_SHAPE_SHAPE_CONTEXT_HANDLER_HXX
25 
26 #include <boost/shared_ptr.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <cppuhelper/implbase1.hxx>
29 #include <com/sun/star/xml/sax/XFastShapeContextHandler.hpp>
30 #include "oox/drawingml/graphicshapecontext.hxx"
31 #include "oox/drawingml/shape.hxx"
32 #include "oox/drawingml/theme.hxx"
33 #include "oox/core/fragmenthandler.hxx"
34 #include "oox/core/xmlfilterbase.hxx"
35 #include "ShapeFilterBase.hxx"
36 
37 namespace css = ::com::sun::star;
38 
39 namespace oox { namespace shape {
40 
41 class ShapeFragmentHandler : public core::FragmentHandler
42 {
43 public:
44     typedef boost::shared_ptr<ShapeFragmentHandler> Pointer_t;
45 
ShapeFragmentHandler(core::XmlFilterBase & rFilter,const::rtl::OUString & rFragmentPath)46     explicit ShapeFragmentHandler(core::XmlFilterBase& rFilter,
47                                   const ::rtl::OUString& rFragmentPath )
48     : FragmentHandler(rFilter, rFragmentPath)
49     {
50     }
51 };
52 
53 class ShapeContextHandler:
54     public ::cppu::WeakImplHelper1<
55         css::xml::sax::XFastShapeContextHandler>
56 {
57 public:
58     explicit ShapeContextHandler
59     (css::uno::Reference< css::uno::XComponentContext > const & context);
60 
61     virtual ~ShapeContextHandler();
62 
63     // ::com::sun::star::lang::XServiceInfo:
64     virtual ::rtl::OUString SAL_CALL getImplementationName()
65         throw (css::uno::RuntimeException);
66 
67     virtual ::sal_Bool SAL_CALL supportsService
68     (const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException);
69 
70     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL
71     getSupportedServiceNames() throw (css::uno::RuntimeException);
72 
73     // ::com::sun::star::xml::sax::XFastContextHandler:
74     virtual void SAL_CALL startFastElement
75     (::sal_Int32 Element,
76      const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
77         throw (css::uno::RuntimeException, css::xml::sax::SAXException);
78 
79     virtual void SAL_CALL startUnknownElement
80     (const ::rtl::OUString & Namespace,
81      const ::rtl::OUString & Name,
82      const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
83         throw (css::uno::RuntimeException, css::xml::sax::SAXException);
84 
85     virtual void SAL_CALL endFastElement(::sal_Int32 Element)
86         throw (css::uno::RuntimeException, css::xml::sax::SAXException);
87 
88     virtual void SAL_CALL endUnknownElement
89     (const ::rtl::OUString & Namespace,
90      const ::rtl::OUString & Name)
91         throw (css::uno::RuntimeException, css::xml::sax::SAXException);
92 
93     virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
94     createFastChildContext
95     (::sal_Int32 Element,
96      const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
97         throw (css::uno::RuntimeException, css::xml::sax::SAXException);
98 
99     virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
100     createUnknownChildContext
101     (const ::rtl::OUString & Namespace,
102      const ::rtl::OUString & Name,
103      const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
104         throw (css::uno::RuntimeException, css::xml::sax::SAXException);
105 
106     virtual void SAL_CALL characters(const ::rtl::OUString & aChars)
107         throw (css::uno::RuntimeException, css::xml::sax::SAXException);
108 
109     // ::com::sun::star::xml::sax::XFastShapeContextHandler:
110     virtual css::uno::Reference< css::drawing::XShape > SAL_CALL getShape()
111         throw (css::uno::RuntimeException);
112 
113     virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL getDrawPage()
114         throw (css::uno::RuntimeException);
115 
116     virtual void SAL_CALL setDrawPage
117     (const css::uno::Reference< css::drawing::XDrawPage > & the_value)
118         throw (css::uno::RuntimeException);
119 
120     virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel()
121         throw (css::uno::RuntimeException);
122 
123     virtual void SAL_CALL setModel
124     (const css::uno::Reference< css::frame::XModel > & the_value)
125         throw (css::uno::RuntimeException);
126 
127     virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
128     getInputStream() throw (css::uno::RuntimeException);
129 
130     virtual void SAL_CALL setInputStream
131     (const css::uno::Reference< css::io::XInputStream > & the_value)
132         throw (css::uno::RuntimeException);
133 
134     virtual ::rtl::OUString SAL_CALL getRelationFragmentPath()
135         throw (css::uno::RuntimeException);
136     virtual void SAL_CALL setRelationFragmentPath
137     (const ::rtl::OUString & the_value)
138         throw (css::uno::RuntimeException);
139 
140     virtual ::sal_Int32 SAL_CALL getStartToken() throw (::com::sun::star::uno::RuntimeException);
141     virtual void SAL_CALL setStartToken( ::sal_Int32 _starttoken ) throw (::com::sun::star::uno::RuntimeException);
142 
143 private:
144     ShapeContextHandler(ShapeContextHandler &); // not defined
145     void operator =(ShapeContextHandler &); // not defined
146 
147     ::sal_uInt32 mnStartToken;
148 
149     css::uno::Reference< css::uno::XComponentContext > m_xContext;
150     drawingml::ShapePtr mpShape;
151     ::boost::shared_ptr< vml::Drawing > mpDrawing;
152 
153     typedef boost::shared_ptr<drawingml::GraphicShapeContext>
154     GraphicShapeContextPtr;
155 	css::uno::Reference<XFastContextHandler> mxDrawingFragmentHandler;
156     css::uno::Reference<XFastContextHandler> mxGraphicShapeContext;
157 
158     core::XmlFilterRef mxFilterBase;
159     drawingml::ThemePtr mpThemePtr;
160     css::uno::Reference<css::drawing::XDrawPage> mxDrawPage;
161     css::uno::Reference<css::io::XInputStream> mxInputStream;
162     ::rtl::OUString msRelationFragmentPath;
163 
164     css::uno::Reference<XFastContextHandler> getGraphicShapeContext(::sal_Int32 Element);
165     css::uno::Reference<XFastContextHandler> getDrawingShapeContext();
166     css::uno::Reference<XFastContextHandler> getContextHandler();
167 };
168 
169 }}
170 
171 #endif // OOX_SHAPE_SHAPE_CONTEXT_HANDLER_HXX
172