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 TOOLKIT_CONTROL_MODEL_CONTAINERBASE_HXX 29 #define TOOLKIT_CONTROL_MODEL_CONTAINERBASE_HXX 30 31 #include <com/sun/star/container/XNameContainer.hpp> 32 #include <com/sun/star/container/XContainer.hpp> 33 #include <com/sun/star/awt/XTabControllerModel.hpp> 34 #include <com/sun/star/util/XChangesNotifier.hpp> 35 #include <com/sun/star/util/XChangesListener.hpp> 36 #include <com/sun/star/util/XModifyListener.hpp> 37 #include <com/sun/star/beans/XPropertyChangeListener.hpp> 38 #include <com/sun/star/resource/XStringResourceResolver.hpp> 39 #include <cppuhelper/implbase8.hxx> 40 #include <cppuhelper/implbase2.hxx> 41 #include <toolkit/helper/listenermultiplexer.hxx> 42 #include <toolkit/controls/unocontrolmodel.hxx> 43 #include <toolkit/controls/unocontrolcontainer.hxx> 44 #include <cppuhelper/propshlp.hxx> 45 #include <cppuhelper/basemutex.hxx> 46 #include <com/sun/star/graphic/XGraphic.hpp> 47 #include <com/sun/star/awt/tab/XTabPageModel.hpp> 48 #include <com/sun/star/uno/XComponentContext.hpp> 49 #include <com/sun/star/lang/XInitialization.hpp> 50 // ---------------------------------------------------- 51 // class ControlModelContainerBase 52 // ---------------------------------------------------- 53 typedef UnoControlModel ControlModel_Base; 54 typedef ::cppu::AggImplInheritanceHelper8 < ControlModel_Base 55 , ::com::sun::star::lang::XMultiServiceFactory 56 , ::com::sun::star::container::XContainer 57 , ::com::sun::star::container::XNameContainer 58 , ::com::sun::star::awt::XTabControllerModel 59 , ::com::sun::star::util::XChangesNotifier 60 , ::com::sun::star::beans::XPropertyChangeListener 61 , ::com::sun::star::awt::tab::XTabPageModel 62 , ::com::sun::star::lang::XInitialization 63 > ControlModelContainer_IBase; 64 65 class ControlModelContainerBase : public ControlModelContainer_IBase 66 { 67 public: 68 // would like to make this typedef private, too, but the Forte 7 compiler does have 69 // problems with this ..... 70 typedef ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >, ::rtl::OUString > 71 UnoControlModelHolder; 72 private: 73 typedef ::std::list< UnoControlModelHolder > UnoControlModelHolderList; 74 75 // for grouping control models (XTabControllerModel::getGroupXXX) 76 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > 77 ModelGroup; 78 typedef ::std::vector< ModelGroup > AllGroups; 79 80 friend struct CloneControlModel; 81 friend struct FindControlModel; 82 friend struct CompareControlModel; 83 84 protected: 85 ContainerListenerMultiplexer maContainerListeners; 86 ::cppu::OInterfaceContainerHelper maChangeListeners; 87 UnoControlModelHolderList maModels; 88 89 AllGroups maGroups; 90 sal_Bool mbGroupsUpToDate; 91 92 bool m_bEnabled; 93 ::rtl::OUString m_sTitle; 94 ::rtl::OUString m_sImageURL; 95 ::rtl::OUString m_sTooltip; 96 sal_Int16 m_nTabPageId; 97 98 void Clone_Impl(ControlModelContainerBase& _rClone) const; 99 100 protected: 101 ::com::sun::star::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const; 102 ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 103 104 UnoControlModelHolderList::iterator ImplFindElement( const ::rtl::OUString& rName ); 105 106 public: 107 ControlModelContainerBase( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory ); 108 ControlModelContainerBase( const ControlModelContainerBase& rModel ); 109 ~ControlModelContainerBase(); 110 111 UnoControlModel* Clone() const; 112 113 // ::com::sun::star::container::XContainer 114 void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException); 115 void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException); 116 117 // ::com::sun::star::container::XElementAcces 118 ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException); 119 sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException); 120 121 // ::com::sun::star::container::XNameContainer, XNameReplace, XNameAccess 122 void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 123 ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 124 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException); 125 sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException); 126 void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 127 void SAL_CALL removeByName( const ::rtl::OUString& Name ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 128 129 // ::com::sun::star::beans::XMultiPropertySet 130 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 131 132 // ::com::sun::star::lang::XMultiServiceFactory 133 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 134 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 135 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 136 137 // XComponent 138 void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException); 139 140 // XTabControllerModel 141 virtual sal_Bool SAL_CALL getGroupControl( ) throw (::com::sun::star::uno::RuntimeException); 142 virtual void SAL_CALL setGroupControl( sal_Bool GroupControl ) throw (::com::sun::star::uno::RuntimeException); 143 virtual void SAL_CALL setControlModels( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Controls ) throw (::com::sun::star::uno::RuntimeException); 144 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > SAL_CALL getControlModels( ) throw (::com::sun::star::uno::RuntimeException); 145 virtual void SAL_CALL setGroup( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Group, const ::rtl::OUString& GroupName ) throw (::com::sun::star::uno::RuntimeException); 146 virtual sal_Int32 SAL_CALL getGroupCount( ) throw (::com::sun::star::uno::RuntimeException); 147 virtual void SAL_CALL getGroup( sal_Int32 nGroup, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Group, ::rtl::OUString& Name ) throw (::com::sun::star::uno::RuntimeException); 148 virtual void SAL_CALL getGroupByName( const ::rtl::OUString& Name, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Group ) throw (::com::sun::star::uno::RuntimeException); 149 150 // XChangesNotifier 151 virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 152 virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 153 154 // XPropertyChangeListener 155 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException); 156 157 // XEventListener 158 using cppu::OPropertySetHelper::disposing; 159 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& evt ) throw (::com::sun::star::uno::RuntimeException); 160 161 // XServiceInfo 162 DECLIMPL_SERVICEINFO_DERIVED(ControlModelContainerBase, ControlModel_Base, "toolkit.ControlModelContainerBase" ) 163 164 // XInitialization 165 virtual void SAL_CALL initialize (const com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rArguments) 166 throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException); 167 168 // ::com::sun::star::awt::tab::XTabPageModel 169 virtual ::sal_Int16 SAL_CALL getTabPageID() throw (::com::sun::star::uno::RuntimeException); 170 virtual ::sal_Bool SAL_CALL getEnabled() throw (::com::sun::star::uno::RuntimeException); 171 virtual void SAL_CALL setEnabled( ::sal_Bool _enabled ) throw (::com::sun::star::uno::RuntimeException); 172 virtual ::rtl::OUString SAL_CALL getTitle() throw (::com::sun::star::uno::RuntimeException); 173 virtual void SAL_CALL setTitle( const ::rtl::OUString& _title ) throw (::com::sun::star::uno::RuntimeException); 174 virtual ::rtl::OUString SAL_CALL getImageURL() throw (::com::sun::star::uno::RuntimeException); 175 virtual void SAL_CALL setImageURL( const ::rtl::OUString& _imageurl ) throw (::com::sun::star::uno::RuntimeException); 176 virtual ::rtl::OUString SAL_CALL getToolTip() throw (::com::sun::star::uno::RuntimeException); 177 virtual void SAL_CALL setToolTip( const ::rtl::OUString& _tooltip ) throw (::com::sun::star::uno::RuntimeException); 178 179 protected: 180 void startControlListening( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxChildModel ); 181 void stopControlListening( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxChildModel ); 182 183 void implNotifyTabModelChange( const ::rtl::OUString& _rAccessor ); 184 185 void implUpdateGroupStructure(); 186 }; 187 188 class ResourceListener :public ::com::sun::star::util::XModifyListener, 189 public ::cppu::OWeakObject, 190 public ::cppu::BaseMutex 191 { 192 public: 193 ResourceListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& xListener ); 194 virtual ~ResourceListener(); 195 196 void startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceResolver >& rResource ); 197 void stopListening(); 198 199 // XInterface 200 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException); 201 virtual void SAL_CALL acquire() throw (); 202 virtual void SAL_CALL release() throw (); 203 204 // XModifyListener 205 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 206 207 // XEventListener 208 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 209 210 private: 211 ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceResolver > m_xResource; 212 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xListener; 213 bool m_bListening; 214 }; 215 216 typedef ::cppu::AggImplInheritanceHelper2 < UnoControlContainer 217 , ::com::sun::star::container::XContainerListener 218 , ::com::sun::star::util::XChangesListener 219 > ContainerControl_IBase; 220 221 class ControlContainerBase : public ContainerControl_IBase 222 { 223 protected: 224 bool mbSizeModified; 225 bool mbPosModified; 226 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController > mxTabController; 227 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > mxListener; 228 229 void ImplInsertControl( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxModel, const ::rtl::OUString& rName ); 230 void ImplRemoveControl( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxModel ); 231 virtual void ImplSetPosSize( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& rxCtrl ); 232 void ImplUpdateResourceResolver(); 233 void ImplStartListingForResourceEvents(); 234 ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > Impl_getGraphicFromURL_nothrow( const ::rtl::OUString& _rURL ); 235 236 ControlContainerBase(); 237 238 public: 239 ControlContainerBase( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory ); 240 ~ControlContainerBase(); 241 242 DECLIMPL_SERVICEINFO_DERIVED( ControlContainerBase, UnoControlBase, "toolkit.ControlContainerBase" ) 243 244 void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 245 void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); 246 247 void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit >& Toolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& Parent ) throw(::com::sun::star::uno::RuntimeException); 248 249 // ::com::sun::star::container::XContainerListener 250 void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); 251 void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); 252 void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); 253 254 // XChangesListener 255 virtual void SAL_CALL changesOccurred( const ::com::sun::star::util::ChangesEvent& Event ) throw (::com::sun::star::uno::RuntimeException); 256 257 // ::com::sun::star::awt::XControl 258 sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& Model ) throw(::com::sun::star::uno::RuntimeException); 259 void SAL_CALL setDesignMode( sal_Bool bOn ) throw(::com::sun::star::uno::RuntimeException); 260 protected: 261 virtual void ImplModelPropertiesChanged( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyChangeEvent >& rEvents ) throw(::com::sun::star::uno::RuntimeException); 262 virtual void removingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl ); 263 virtual void addingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl ); 264 }; 265 #endif 266