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