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 28 #ifndef LAYOUT_CORE_IMPORT_HXX 29 #define LAYOUT_CORE_IMPORT_HXX 30 31 #include <map> 32 #include <list> 33 #define _BACKWARD_BACKWARD_WARNING_H 1 34 #include <hash_map> 35 36 37 #include <com/sun/star/xml/input/XRoot.hpp> 38 #include <cppuhelper/implbase1.hxx> 39 #include <com/sun/star/awt/XButton.hpp> 40 #include <com/sun/star/awt/XRadioButton.hpp> 41 42 namespace layoutimpl 43 { 44 class LayoutRoot; 45 class LayoutWidget; 46 namespace css = ::com::sun::star; 47 48 class RadioGroups 49 { 50 public: 51 RadioGroups(); 52 53 void addItem( rtl::OUString id, css::uno::Reference< css::awt::XRadioButton > xRadio ) 54 throw (css::uno::RuntimeException); 55 56 private: 57 class RadioGroup : public ::cppu::WeakImplHelper1< css::awt::XItemListener > 58 , public ::cppu::WeakImplHelper1< css::awt::XActionListener > 59 { 60 public: 61 RadioGroup(); 62 void addItem( css::uno::Reference< css::awt::XRadioButton > xRadio ); 63 64 private: 65 typedef std::list< css::uno::Reference< css::awt::XRadioButton > > RadioButtonsList; 66 RadioButtonsList mxRadios; 67 css::uno::Reference< css::awt::XRadioButton > mxSelectedRadio; 68 69 void handleSelected () 70 throw (css::uno::RuntimeException); 71 72 // awt::XItemListener 73 void SAL_CALL itemStateChanged( const css::awt::ItemEvent& e ) 74 throw (css::uno::RuntimeException); 75 76 // awt::XActionListener 77 void SAL_CALL actionPerformed( const css::awt::ActionEvent& e ) 78 throw (css::uno::RuntimeException); 79 80 // lang::XEventListener 81 void SAL_CALL disposing( const css::lang::EventObject& ) 82 throw (css::uno::RuntimeException); 83 }; 84 85 // each RadioGroup will stay alive after RadioGroups die with the ImportContext 86 // because they are referenced by every XRadioButton through the listener 87 typedef std::map< rtl::OUString, css::uno::Reference< RadioGroup > > RadioGroupsMap; 88 RadioGroupsMap mxRadioGroups; 89 }; 90 91 #if 0 92 // generator 93 class Widget 94 { 95 public: 96 Widget( css::uno::Reference< css::awt::XToolkit > xToolkit, 97 css::uno::Reference< css::awt::XWindow > xToplevel, 98 rtl::OUString unoName, long attrbs ); 99 virtual ~Widget(); 100 101 virtual void setProperties( const PropList &rProps ); 102 103 virtual bool addChild( Widget *pChild ); 104 virtual void setChildProperties( Widget *pChild, const PropList &rProps ); 105 106 inline css::uno::Reference< css::awt::XLayoutConstrains > getPeer() 107 { return mxWidget; } 108 109 inline css::uno::Reference< css::awt::XLayoutConstrains > getContainer() 110 { return mxContainer; } 111 112 protected: 113 css::uno::Reference< css::awt::XLayoutConstrains > mxWidget; 114 css::uno::Reference< css::awt::XLayoutContainer > mxContainer; 115 }; 116 117 class Root 118 { 119 public: 120 Root( css::uno::Reference< css::awt::XToolkit > xToolkit ) 121 : mxToolkit( xToolkit ) {} 122 ~Root(); 123 124 virtual Widget *create( rtl::OUString id, const rtl::OUString unoName, long attrbs ); 125 126 css::uno::Reference< css::awt::XLayoutConstrains > getById( rtl::OUString id ); 127 inline css::uno::Reference< css::awt::XLayoutConstrains > getToplevel(); 128 129 protected: 130 css::uno::Reference< css::awt::XToolkit > mxToolkit; 131 Widget *mpToplevel; 132 133 typedef std::hash_map< rtl::OUString, css::uno::Reference< css::awt::XLayoutConstrains >, 134 rtl::OUStringHash > ItemHash; 135 ItemHash maItems; 136 }; 137 #endif 138 139 // parser 140 class ImportContext : public ::cppu::WeakImplHelper1< css::xml::input::XRoot > 141 { 142 public: 143 sal_Int32 XMLNS_LAYOUT_UID, XMLNS_CONTAINER_UID; 144 LayoutRoot &mrRoot; // switch to XNameContainer ref ? 145 RadioGroups mxRadioGroups; 146 147 inline ImportContext( LayoutRoot &rRoot ) SAL_THROW( () ) 148 : mrRoot( rRoot ) {} 149 virtual ~ImportContext() {} 150 151 // XRoot 152 virtual void SAL_CALL startDocument( 153 css::uno::Reference< css::xml::input::XNamespaceMapping > 154 const & xNamespaceMapping ) 155 throw (css::xml::sax::SAXException, css::uno::RuntimeException); 156 virtual void SAL_CALL endDocument() 157 throw (css::xml::sax::SAXException, css::uno::RuntimeException) 158 { /* ignore */ } 159 virtual void SAL_CALL processingInstruction( 160 ::rtl::OUString const & /* rTarget */, ::rtl::OUString const & /* rData */ ) 161 throw (css::xml::sax::SAXException, css::uno::RuntimeException) 162 { /* ignore */ } 163 virtual void SAL_CALL setDocumentLocator( 164 css::uno::Reference< css::xml::sax::XLocator > const & /* xLocator */ ) 165 throw (css::xml::sax::SAXException, css::uno::RuntimeException) 166 { /* ignore */ } 167 virtual css::uno::Reference< css::xml::input::XElement > 168 SAL_CALL startRootElement( 169 sal_Int32 nUid, ::rtl::OUString const & rLocalName, 170 css::uno::Reference<css::xml::input::XAttributes > const & xAttributes ) 171 throw (css::xml::sax::SAXException, css::uno::RuntimeException); 172 }; 173 174 class ElementBase : public ::cppu::WeakImplHelper1< css::xml::input::XElement > 175 { 176 protected: 177 ImportContext *mpImport; 178 /* TODO: check if all this memebers are needed. */ 179 ElementBase *mpParent; 180 sal_Int32 mnUid; 181 182 ::rtl::OUString maLocalName; 183 css::uno::Reference< css::xml::input::XAttributes > mxAttributes; 184 public: 185 ElementBase( 186 sal_Int32 nUid, ::rtl::OUString const & rLocalName, 187 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes, 188 ElementBase * pParent, ImportContext * pImport ) 189 SAL_THROW( () ); 190 virtual ~ElementBase() SAL_THROW(()); 191 192 // XElement 193 virtual css::uno::Reference<css::xml::input::XElement> SAL_CALL getParent() 194 throw (css::uno::RuntimeException) 195 { return static_cast< css::xml::input::XElement * >( mpParent ); } 196 virtual ::rtl::OUString SAL_CALL getLocalName() throw (css::uno::RuntimeException) 197 { return maLocalName; } 198 virtual sal_Int32 SAL_CALL getUid() throw (css::uno::RuntimeException) 199 { return mnUid; } 200 virtual css::uno::Reference< css::xml::input::XAttributes > 201 SAL_CALL getAttributes() throw (css::uno::RuntimeException) 202 { return mxAttributes; } 203 204 virtual void SAL_CALL ignorableWhitespace( 205 ::rtl::OUString const & /* rWhitespaces */ ) 206 throw (css::xml::sax::SAXException, css::uno::RuntimeException) 207 { /* ignore */ } 208 virtual void SAL_CALL characters( ::rtl::OUString const & /* rChars */ ) 209 throw (css::xml::sax::SAXException, css::uno::RuntimeException) 210 { /* ignore */ } 211 virtual void SAL_CALL processingInstruction( 212 ::rtl::OUString const & /* Target */, ::rtl::OUString const & /* Data */ ) 213 throw (css::xml::sax::SAXException, css::uno::RuntimeException) 214 { /* ignore */ } 215 216 virtual css::uno::Reference< css::xml::input::XElement > 217 SAL_CALL startChildElement( 218 sal_Int32 nUid, ::rtl::OUString const & rLocalName, 219 css::uno::Reference<css::xml::input::XAttributes > const & xAttributes ) 220 throw (css::xml::sax::SAXException, css::uno::RuntimeException) = 0; 221 virtual void SAL_CALL endElement() 222 throw (css::xml::sax::SAXException, css::uno::RuntimeException) 223 { /* ignore */ } 224 }; 225 226 class WidgetElement : public ElementBase 227 { 228 protected: 229 LayoutWidget *mpWidget; 230 231 public: 232 WidgetElement( sal_Int32 nUid, rtl::OUString const &name, 233 css::uno::Reference< css::xml::input::XAttributes > const &attributes, 234 ElementBase *parent, ImportContext *import ) SAL_THROW (()); 235 236 ~WidgetElement(); 237 238 239 virtual css::uno::Reference< css::xml::input::XElement> SAL_CALL 240 startChildElement (sal_Int32 id, rtl::OUString const &name, 241 css::uno::Reference< css::xml::input::XAttributes > const &attributes) 242 throw( css::xml::sax::SAXException, css::uno::RuntimeException ); 243 virtual void SAL_CALL characters( ::rtl::OUString const & /* rChars */ ) 244 throw (css::xml::sax::SAXException, css::uno::RuntimeException); 245 }; 246 247 class ToplevelElement : public WidgetElement 248 { 249 public: 250 ToplevelElement( rtl::OUString const &name, 251 css::uno::Reference< css::xml::input::XAttributes > const &attributes, 252 ImportContext *import ) SAL_THROW (()); 253 ~ToplevelElement(); 254 }; 255 256 257 } // namespace layoutimpl 258 259 #endif /* LAYOUT_CORE_IMPORT_HXX */ 260