1*50e6b072SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*50e6b072SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*50e6b072SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*50e6b072SAndrew Rist * distributed with this work for additional information 6*50e6b072SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*50e6b072SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*50e6b072SAndrew Rist * "License"); you may not use this file except in compliance 9*50e6b072SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*50e6b072SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*50e6b072SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*50e6b072SAndrew Rist * software distributed under the License is distributed on an 15*50e6b072SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*50e6b072SAndrew Rist * KIND, either express or implied. See the License for the 17*50e6b072SAndrew Rist * specific language governing permissions and limitations 18*50e6b072SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*50e6b072SAndrew Rist *************************************************************/ 21*50e6b072SAndrew Rist 22*50e6b072SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef LAYOUT_CORE_IMPORT_HXX 25cdf0e10cSrcweir #define LAYOUT_CORE_IMPORT_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <map> 28cdf0e10cSrcweir #include <list> 29cdf0e10cSrcweir #define _BACKWARD_BACKWARD_WARNING_H 1 30cdf0e10cSrcweir #include <hash_map> 31cdf0e10cSrcweir 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <com/sun/star/xml/input/XRoot.hpp> 34cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 35cdf0e10cSrcweir #include <com/sun/star/awt/XButton.hpp> 36cdf0e10cSrcweir #include <com/sun/star/awt/XRadioButton.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace layoutimpl 39cdf0e10cSrcweir { 40cdf0e10cSrcweir class LayoutRoot; 41cdf0e10cSrcweir class LayoutWidget; 42cdf0e10cSrcweir namespace css = ::com::sun::star; 43cdf0e10cSrcweir 44cdf0e10cSrcweir class RadioGroups 45cdf0e10cSrcweir { 46cdf0e10cSrcweir public: 47cdf0e10cSrcweir RadioGroups(); 48cdf0e10cSrcweir 49cdf0e10cSrcweir void addItem( rtl::OUString id, css::uno::Reference< css::awt::XRadioButton > xRadio ) 50cdf0e10cSrcweir throw (css::uno::RuntimeException); 51cdf0e10cSrcweir 52cdf0e10cSrcweir private: 53cdf0e10cSrcweir class RadioGroup : public ::cppu::WeakImplHelper1< css::awt::XItemListener > 54cdf0e10cSrcweir , public ::cppu::WeakImplHelper1< css::awt::XActionListener > 55cdf0e10cSrcweir { 56cdf0e10cSrcweir public: 57cdf0e10cSrcweir RadioGroup(); 58cdf0e10cSrcweir void addItem( css::uno::Reference< css::awt::XRadioButton > xRadio ); 59cdf0e10cSrcweir 60cdf0e10cSrcweir private: 61cdf0e10cSrcweir typedef std::list< css::uno::Reference< css::awt::XRadioButton > > RadioButtonsList; 62cdf0e10cSrcweir RadioButtonsList mxRadios; 63cdf0e10cSrcweir css::uno::Reference< css::awt::XRadioButton > mxSelectedRadio; 64cdf0e10cSrcweir 65cdf0e10cSrcweir void handleSelected () 66cdf0e10cSrcweir throw (css::uno::RuntimeException); 67cdf0e10cSrcweir 68cdf0e10cSrcweir // awt::XItemListener 69cdf0e10cSrcweir void SAL_CALL itemStateChanged( const css::awt::ItemEvent& e ) 70cdf0e10cSrcweir throw (css::uno::RuntimeException); 71cdf0e10cSrcweir 72cdf0e10cSrcweir // awt::XActionListener 73cdf0e10cSrcweir void SAL_CALL actionPerformed( const css::awt::ActionEvent& e ) 74cdf0e10cSrcweir throw (css::uno::RuntimeException); 75cdf0e10cSrcweir 76cdf0e10cSrcweir // lang::XEventListener 77cdf0e10cSrcweir void SAL_CALL disposing( const css::lang::EventObject& ) 78cdf0e10cSrcweir throw (css::uno::RuntimeException); 79cdf0e10cSrcweir }; 80cdf0e10cSrcweir 81cdf0e10cSrcweir // each RadioGroup will stay alive after RadioGroups die with the ImportContext 82cdf0e10cSrcweir // because they are referenced by every XRadioButton through the listener 83cdf0e10cSrcweir typedef std::map< rtl::OUString, css::uno::Reference< RadioGroup > > RadioGroupsMap; 84cdf0e10cSrcweir RadioGroupsMap mxRadioGroups; 85cdf0e10cSrcweir }; 86cdf0e10cSrcweir 87cdf0e10cSrcweir #if 0 88cdf0e10cSrcweir // generator 89cdf0e10cSrcweir class Widget 90cdf0e10cSrcweir { 91cdf0e10cSrcweir public: 92cdf0e10cSrcweir Widget( css::uno::Reference< css::awt::XToolkit > xToolkit, 93cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xToplevel, 94cdf0e10cSrcweir rtl::OUString unoName, long attrbs ); 95cdf0e10cSrcweir virtual ~Widget(); 96cdf0e10cSrcweir 97cdf0e10cSrcweir virtual void setProperties( const PropList &rProps ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir virtual bool addChild( Widget *pChild ); 100cdf0e10cSrcweir virtual void setChildProperties( Widget *pChild, const PropList &rProps ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir inline css::uno::Reference< css::awt::XLayoutConstrains > getPeer() 103cdf0e10cSrcweir { return mxWidget; } 104cdf0e10cSrcweir 105cdf0e10cSrcweir inline css::uno::Reference< css::awt::XLayoutConstrains > getContainer() 106cdf0e10cSrcweir { return mxContainer; } 107cdf0e10cSrcweir 108cdf0e10cSrcweir protected: 109cdf0e10cSrcweir css::uno::Reference< css::awt::XLayoutConstrains > mxWidget; 110cdf0e10cSrcweir css::uno::Reference< css::awt::XLayoutContainer > mxContainer; 111cdf0e10cSrcweir }; 112cdf0e10cSrcweir 113cdf0e10cSrcweir class Root 114cdf0e10cSrcweir { 115cdf0e10cSrcweir public: 116cdf0e10cSrcweir Root( css::uno::Reference< css::awt::XToolkit > xToolkit ) 117cdf0e10cSrcweir : mxToolkit( xToolkit ) {} 118cdf0e10cSrcweir ~Root(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir virtual Widget *create( rtl::OUString id, const rtl::OUString unoName, long attrbs ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir css::uno::Reference< css::awt::XLayoutConstrains > getById( rtl::OUString id ); 123cdf0e10cSrcweir inline css::uno::Reference< css::awt::XLayoutConstrains > getToplevel(); 124cdf0e10cSrcweir 125cdf0e10cSrcweir protected: 126cdf0e10cSrcweir css::uno::Reference< css::awt::XToolkit > mxToolkit; 127cdf0e10cSrcweir Widget *mpToplevel; 128cdf0e10cSrcweir 129cdf0e10cSrcweir typedef std::hash_map< rtl::OUString, css::uno::Reference< css::awt::XLayoutConstrains >, 130cdf0e10cSrcweir rtl::OUStringHash > ItemHash; 131cdf0e10cSrcweir ItemHash maItems; 132cdf0e10cSrcweir }; 133cdf0e10cSrcweir #endif 134cdf0e10cSrcweir 135cdf0e10cSrcweir // parser 136cdf0e10cSrcweir class ImportContext : public ::cppu::WeakImplHelper1< css::xml::input::XRoot > 137cdf0e10cSrcweir { 138cdf0e10cSrcweir public: 139cdf0e10cSrcweir sal_Int32 XMLNS_LAYOUT_UID, XMLNS_CONTAINER_UID; 140cdf0e10cSrcweir LayoutRoot &mrRoot; // switch to XNameContainer ref ? 141cdf0e10cSrcweir RadioGroups mxRadioGroups; 142cdf0e10cSrcweir 143cdf0e10cSrcweir inline ImportContext( LayoutRoot &rRoot ) SAL_THROW( () ) 144cdf0e10cSrcweir : mrRoot( rRoot ) {} ~ImportContext()145cdf0e10cSrcweir virtual ~ImportContext() {} 146cdf0e10cSrcweir 147cdf0e10cSrcweir // XRoot 148cdf0e10cSrcweir virtual void SAL_CALL startDocument( 149cdf0e10cSrcweir css::uno::Reference< css::xml::input::XNamespaceMapping > 150cdf0e10cSrcweir const & xNamespaceMapping ) 151cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException); endDocument()152cdf0e10cSrcweir virtual void SAL_CALL endDocument() 153cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException) 154cdf0e10cSrcweir { /* ignore */ } processingInstruction(::rtl::OUString const &,::rtl::OUString const &)155cdf0e10cSrcweir virtual void SAL_CALL processingInstruction( 156cdf0e10cSrcweir ::rtl::OUString const & /* rTarget */, ::rtl::OUString const & /* rData */ ) 157cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException) 158cdf0e10cSrcweir { /* ignore */ } setDocumentLocator(css::uno::Reference<css::xml::sax::XLocator> const &)159cdf0e10cSrcweir virtual void SAL_CALL setDocumentLocator( 160cdf0e10cSrcweir css::uno::Reference< css::xml::sax::XLocator > const & /* xLocator */ ) 161cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException) 162cdf0e10cSrcweir { /* ignore */ } 163cdf0e10cSrcweir virtual css::uno::Reference< css::xml::input::XElement > 164cdf0e10cSrcweir SAL_CALL startRootElement( 165cdf0e10cSrcweir sal_Int32 nUid, ::rtl::OUString const & rLocalName, 166cdf0e10cSrcweir css::uno::Reference<css::xml::input::XAttributes > const & xAttributes ) 167cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException); 168cdf0e10cSrcweir }; 169cdf0e10cSrcweir 170cdf0e10cSrcweir class ElementBase : public ::cppu::WeakImplHelper1< css::xml::input::XElement > 171cdf0e10cSrcweir { 172cdf0e10cSrcweir protected: 173cdf0e10cSrcweir ImportContext *mpImport; 174cdf0e10cSrcweir /* TODO: check if all this memebers are needed. */ 175cdf0e10cSrcweir ElementBase *mpParent; 176cdf0e10cSrcweir sal_Int32 mnUid; 177cdf0e10cSrcweir 178cdf0e10cSrcweir ::rtl::OUString maLocalName; 179cdf0e10cSrcweir css::uno::Reference< css::xml::input::XAttributes > mxAttributes; 180cdf0e10cSrcweir public: 181cdf0e10cSrcweir ElementBase( 182cdf0e10cSrcweir sal_Int32 nUid, ::rtl::OUString const & rLocalName, 183cdf0e10cSrcweir css::uno::Reference< css::xml::input::XAttributes > const & xAttributes, 184cdf0e10cSrcweir ElementBase * pParent, ImportContext * pImport ) 185cdf0e10cSrcweir SAL_THROW( () ); 186cdf0e10cSrcweir virtual ~ElementBase() SAL_THROW(()); 187cdf0e10cSrcweir 188cdf0e10cSrcweir // XElement getParent()189cdf0e10cSrcweir virtual css::uno::Reference<css::xml::input::XElement> SAL_CALL getParent() 190cdf0e10cSrcweir throw (css::uno::RuntimeException) 191cdf0e10cSrcweir { return static_cast< css::xml::input::XElement * >( mpParent ); } getLocalName()192cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getLocalName() throw (css::uno::RuntimeException) 193cdf0e10cSrcweir { return maLocalName; } getUid()194cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getUid() throw (css::uno::RuntimeException) 195cdf0e10cSrcweir { return mnUid; } 196cdf0e10cSrcweir virtual css::uno::Reference< css::xml::input::XAttributes > getAttributes()197cdf0e10cSrcweir SAL_CALL getAttributes() throw (css::uno::RuntimeException) 198cdf0e10cSrcweir { return mxAttributes; } 199cdf0e10cSrcweir ignorableWhitespace(::rtl::OUString const &)200cdf0e10cSrcweir virtual void SAL_CALL ignorableWhitespace( 201cdf0e10cSrcweir ::rtl::OUString const & /* rWhitespaces */ ) 202cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException) 203cdf0e10cSrcweir { /* ignore */ } characters(::rtl::OUString const &)204cdf0e10cSrcweir virtual void SAL_CALL characters( ::rtl::OUString const & /* rChars */ ) 205cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException) 206cdf0e10cSrcweir { /* ignore */ } processingInstruction(::rtl::OUString const &,::rtl::OUString const &)207cdf0e10cSrcweir virtual void SAL_CALL processingInstruction( 208cdf0e10cSrcweir ::rtl::OUString const & /* Target */, ::rtl::OUString const & /* Data */ ) 209cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException) 210cdf0e10cSrcweir { /* ignore */ } 211cdf0e10cSrcweir 212cdf0e10cSrcweir virtual css::uno::Reference< css::xml::input::XElement > 213cdf0e10cSrcweir SAL_CALL startChildElement( 214cdf0e10cSrcweir sal_Int32 nUid, ::rtl::OUString const & rLocalName, 215cdf0e10cSrcweir css::uno::Reference<css::xml::input::XAttributes > const & xAttributes ) 216cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException) = 0; endElement()217cdf0e10cSrcweir virtual void SAL_CALL endElement() 218cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException) 219cdf0e10cSrcweir { /* ignore */ } 220cdf0e10cSrcweir }; 221cdf0e10cSrcweir 222cdf0e10cSrcweir class WidgetElement : public ElementBase 223cdf0e10cSrcweir { 224cdf0e10cSrcweir protected: 225cdf0e10cSrcweir LayoutWidget *mpWidget; 226cdf0e10cSrcweir 227cdf0e10cSrcweir public: 228cdf0e10cSrcweir WidgetElement( sal_Int32 nUid, rtl::OUString const &name, 229cdf0e10cSrcweir css::uno::Reference< css::xml::input::XAttributes > const &attributes, 230cdf0e10cSrcweir ElementBase *parent, ImportContext *import ) SAL_THROW (()); 231cdf0e10cSrcweir 232cdf0e10cSrcweir ~WidgetElement(); 233cdf0e10cSrcweir 234cdf0e10cSrcweir 235cdf0e10cSrcweir virtual css::uno::Reference< css::xml::input::XElement> SAL_CALL 236cdf0e10cSrcweir startChildElement (sal_Int32 id, rtl::OUString const &name, 237cdf0e10cSrcweir css::uno::Reference< css::xml::input::XAttributes > const &attributes) 238cdf0e10cSrcweir throw( css::xml::sax::SAXException, css::uno::RuntimeException ); 239cdf0e10cSrcweir virtual void SAL_CALL characters( ::rtl::OUString const & /* rChars */ ) 240cdf0e10cSrcweir throw (css::xml::sax::SAXException, css::uno::RuntimeException); 241cdf0e10cSrcweir }; 242cdf0e10cSrcweir 243cdf0e10cSrcweir class ToplevelElement : public WidgetElement 244cdf0e10cSrcweir { 245cdf0e10cSrcweir public: 246cdf0e10cSrcweir ToplevelElement( rtl::OUString const &name, 247cdf0e10cSrcweir css::uno::Reference< css::xml::input::XAttributes > const &attributes, 248cdf0e10cSrcweir ImportContext *import ) SAL_THROW (()); 249cdf0e10cSrcweir ~ToplevelElement(); 250cdf0e10cSrcweir }; 251cdf0e10cSrcweir 252cdf0e10cSrcweir 253cdf0e10cSrcweir } // namespace layoutimpl 254cdf0e10cSrcweir 255cdf0e10cSrcweir #endif /* LAYOUT_CORE_IMPORT_HXX */ 256