Update ooo320-m1
[ooovba.git] / toolkit / source / layout / core / import.hxx
blob7968f323e12cb01e7979f3116ae7fb6d99abf7d8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile$
11 * $Revision$
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef LAYOUT_CORE_IMPORT_HXX
33 #define LAYOUT_CORE_IMPORT_HXX
35 #include <map>
36 #include <list>
37 #define _BACKWARD_BACKWARD_WARNING_H 1
38 #include <hash_map>
41 #include <com/sun/star/xml/input/XRoot.hpp>
42 #include <cppuhelper/implbase1.hxx>
43 #include <com/sun/star/awt/XButton.hpp>
44 #include <com/sun/star/awt/XRadioButton.hpp>
46 namespace layoutimpl
48 class LayoutRoot;
49 class LayoutWidget;
50 namespace css = ::com::sun::star;
52 class RadioGroups
54 public:
55 RadioGroups();
57 void addItem( rtl::OUString id, css::uno::Reference< css::awt::XRadioButton > xRadio )
58 throw (css::uno::RuntimeException);
60 private:
61 class RadioGroup : public ::cppu::WeakImplHelper1< css::awt::XItemListener >
62 , public ::cppu::WeakImplHelper1< css::awt::XActionListener >
64 public:
65 RadioGroup();
66 void addItem( css::uno::Reference< css::awt::XRadioButton > xRadio );
68 private:
69 typedef std::list< css::uno::Reference< css::awt::XRadioButton > > RadioButtonsList;
70 RadioButtonsList mxRadios;
71 css::uno::Reference< css::awt::XRadioButton > mxSelectedRadio;
73 void handleSelected ()
74 throw (css::uno::RuntimeException);
76 // awt::XItemListener
77 void SAL_CALL itemStateChanged( const css::awt::ItemEvent& e )
78 throw (css::uno::RuntimeException);
80 // awt::XActionListener
81 void SAL_CALL actionPerformed( const css::awt::ActionEvent& e )
82 throw (css::uno::RuntimeException);
84 // lang::XEventListener
85 void SAL_CALL disposing( const css::lang::EventObject& )
86 throw (css::uno::RuntimeException);
89 // each RadioGroup will stay alive after RadioGroups die with the ImportContext
90 // because they are referenced by every XRadioButton through the listener
91 typedef std::map< rtl::OUString, css::uno::Reference< RadioGroup > > RadioGroupsMap;
92 RadioGroupsMap mxRadioGroups;
95 #if 0
96 // generator
97 class Widget
99 public:
100 Widget( css::uno::Reference< css::awt::XToolkit > xToolkit,
101 css::uno::Reference< css::awt::XWindow > xToplevel,
102 rtl::OUString unoName, long attrbs );
103 virtual ~Widget();
105 virtual void setProperties( const PropList &rProps );
107 virtual bool addChild( Widget *pChild );
108 virtual void setChildProperties( Widget *pChild, const PropList &rProps );
110 inline css::uno::Reference< css::awt::XLayoutConstrains > getPeer()
111 { return mxWidget; }
113 inline css::uno::Reference< css::awt::XLayoutConstrains > getContainer()
114 { return mxContainer; }
116 protected:
117 css::uno::Reference< css::awt::XLayoutConstrains > mxWidget;
118 css::uno::Reference< css::awt::XLayoutContainer > mxContainer;
121 class Root
123 public:
124 Root( css::uno::Reference< css::awt::XToolkit > xToolkit )
125 : mxToolkit( xToolkit ) {}
126 ~Root();
128 virtual Widget *create( rtl::OUString id, const rtl::OUString unoName, long attrbs );
130 css::uno::Reference< css::awt::XLayoutConstrains > getById( rtl::OUString id );
131 inline css::uno::Reference< css::awt::XLayoutConstrains > getToplevel();
133 protected:
134 css::uno::Reference< css::awt::XToolkit > mxToolkit;
135 Widget *mpToplevel;
137 typedef std::hash_map< rtl::OUString, css::uno::Reference< css::awt::XLayoutConstrains >,
138 rtl::OUStringHash > ItemHash;
139 ItemHash maItems;
141 #endif
143 // parser
144 class ImportContext : public ::cppu::WeakImplHelper1< css::xml::input::XRoot >
146 public:
147 sal_Int32 XMLNS_LAYOUT_UID, XMLNS_CONTAINER_UID;
148 LayoutRoot &mrRoot; // switch to XNameContainer ref ?
149 RadioGroups mxRadioGroups;
151 inline ImportContext( LayoutRoot &rRoot ) SAL_THROW( () )
152 : mrRoot( rRoot ) {}
153 virtual ~ImportContext() {}
155 // XRoot
156 virtual void SAL_CALL startDocument(
157 css::uno::Reference< css::xml::input::XNamespaceMapping >
158 const & xNamespaceMapping )
159 throw (css::xml::sax::SAXException, css::uno::RuntimeException);
160 virtual void SAL_CALL endDocument()
161 throw (css::xml::sax::SAXException, css::uno::RuntimeException)
162 { /* ignore */ }
163 virtual void SAL_CALL processingInstruction(
164 ::rtl::OUString const & /* rTarget */, ::rtl::OUString const & /* rData */ )
165 throw (css::xml::sax::SAXException, css::uno::RuntimeException)
166 { /* ignore */ }
167 virtual void SAL_CALL setDocumentLocator(
168 css::uno::Reference< css::xml::sax::XLocator > const & /* xLocator */ )
169 throw (css::xml::sax::SAXException, css::uno::RuntimeException)
170 { /* ignore */ }
171 virtual css::uno::Reference< css::xml::input::XElement >
172 SAL_CALL startRootElement(
173 sal_Int32 nUid, ::rtl::OUString const & rLocalName,
174 css::uno::Reference<css::xml::input::XAttributes > const & xAttributes )
175 throw (css::xml::sax::SAXException, css::uno::RuntimeException);
178 class ElementBase : public ::cppu::WeakImplHelper1< css::xml::input::XElement >
180 protected:
181 ImportContext *mpImport;
182 /* TODO: check if all this memebers are needed. */
183 ElementBase *mpParent;
184 sal_Int32 mnUid;
186 ::rtl::OUString maLocalName;
187 css::uno::Reference< css::xml::input::XAttributes > mxAttributes;
188 public:
189 ElementBase(
190 sal_Int32 nUid, ::rtl::OUString const & rLocalName,
191 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes,
192 ElementBase * pParent, ImportContext * pImport )
193 SAL_THROW( () );
194 virtual ~ElementBase() SAL_THROW(());
196 // XElement
197 virtual css::uno::Reference<css::xml::input::XElement> SAL_CALL getParent()
198 throw (css::uno::RuntimeException)
199 { return static_cast< css::xml::input::XElement * >( mpParent ); }
200 virtual ::rtl::OUString SAL_CALL getLocalName() throw (css::uno::RuntimeException)
201 { return maLocalName; }
202 virtual sal_Int32 SAL_CALL getUid() throw (css::uno::RuntimeException)
203 { return mnUid; }
204 virtual css::uno::Reference< css::xml::input::XAttributes >
205 SAL_CALL getAttributes() throw (css::uno::RuntimeException)
206 { return mxAttributes; }
208 virtual void SAL_CALL ignorableWhitespace(
209 ::rtl::OUString const & /* rWhitespaces */ )
210 throw (css::xml::sax::SAXException, css::uno::RuntimeException)
211 { /* ignore */ }
212 virtual void SAL_CALL characters( ::rtl::OUString const & /* rChars */ )
213 throw (css::xml::sax::SAXException, css::uno::RuntimeException)
214 { /* ignore */ }
215 virtual void SAL_CALL processingInstruction(
216 ::rtl::OUString const & /* Target */, ::rtl::OUString const & /* Data */ )
217 throw (css::xml::sax::SAXException, css::uno::RuntimeException)
218 { /* ignore */ }
220 virtual css::uno::Reference< css::xml::input::XElement >
221 SAL_CALL startChildElement(
222 sal_Int32 nUid, ::rtl::OUString const & rLocalName,
223 css::uno::Reference<css::xml::input::XAttributes > const & xAttributes )
224 throw (css::xml::sax::SAXException, css::uno::RuntimeException) = 0;
225 virtual void SAL_CALL endElement()
226 throw (css::xml::sax::SAXException, css::uno::RuntimeException)
227 { /* ignore */ }
230 class WidgetElement : public ElementBase
232 protected:
233 LayoutWidget *mpWidget;
235 public:
236 WidgetElement( sal_Int32 nUid, rtl::OUString const &name,
237 css::uno::Reference< css::xml::input::XAttributes > const &attributes,
238 ElementBase *parent, ImportContext *import ) SAL_THROW (());
240 ~WidgetElement();
243 virtual css::uno::Reference< css::xml::input::XElement> SAL_CALL
244 startChildElement (sal_Int32 id, rtl::OUString const &name,
245 css::uno::Reference< css::xml::input::XAttributes > const &attributes)
246 throw( css::xml::sax::SAXException, css::uno::RuntimeException );
247 virtual void SAL_CALL characters( ::rtl::OUString const & /* rChars */ )
248 throw (css::xml::sax::SAXException, css::uno::RuntimeException);
251 class ToplevelElement : public WidgetElement
253 public:
254 ToplevelElement( rtl::OUString const &name,
255 css::uno::Reference< css::xml::input::XAttributes > const &attributes,
256 ImportContext *import ) SAL_THROW (());
257 ~ToplevelElement();
261 } // namespace layoutimpl
263 #endif /* LAYOUT_CORE_IMPORT_HXX */