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