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 __FRAMEWORK_UICONFIGURATION_IMAGEMANAGERIMPL_HXX_ 25 #define __FRAMEWORK_UICONFIGURATION_IMAGEMANAGERIMPL_HXX_ 26 27 28 /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble 29 with solaris headers ... 30 */ 31 #include <vector> 32 #include <list> 33 #include <hash_map> 34 35 //_________________________________________________________________________________________________________________ 36 // my own includes 37 //_________________________________________________________________________________________________________________ 38 #include <threadhelp/threadhelpbase.hxx> 39 #include <macros/generic.hxx> 40 #include <macros/xinterface.hxx> 41 #include <macros/xtypeprovider.hxx> 42 #include <macros/xserviceinfo.hxx> 43 #include <stdtypes.h> 44 #include <uiconfiguration/imagetype.hxx> 45 46 //_________________________________________________________________________________________________________________ 47 // interface includes 48 //_________________________________________________________________________________________________________________ 49 #include <com/sun/star/lang/XServiceInfo.hpp> 50 #include <com/sun/star/lang/XTypeProvider.hpp> 51 #include <com/sun/star/lang/XComponent.hpp> 52 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp> 53 #include <com/sun/star/ui/XUIConfigurationStorage.hpp> 54 #include <com/sun/star/ui/XUIConfiguration.hpp> 55 #include <com/sun/star/ui/XImageManager.hpp> 56 #include <com/sun/star/lang/XInitialization.hpp> 57 #include <com/sun/star/ui/ConfigurationEvent.hpp> 58 #include <com/sun/star/embed/XTransactedObject.hpp> 59 #include <com/sun/star/ui/XImageManager.hpp> 60 61 //_________________________________________________________________________________________________________________ 62 // other includes 63 //_________________________________________________________________________________________________________________ 64 #include <cppuhelper/weak.hxx> 65 #include <cppuhelper/interfacecontainer.hxx> 66 #include <rtl/ustring.hxx> 67 68 #include <vcl/image.hxx> 69 #include <tools/color.hxx> 70 #include <rtl/ref.hxx> 71 72 #include <vector> 73 74 namespace framework 75 { 76 class CmdImageList 77 { 78 public: 79 CmdImageList( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager, 80 const ::rtl::OUString& aModuleIdentifier ); 81 virtual ~CmdImageList(); 82 83 virtual Image getImageFromCommandURL( sal_Int16 nImageType, const rtl::OUString& rCommandURL ); 84 virtual bool hasImage( sal_Int16 nImageType, const rtl::OUString& rCommandURL ); 85 virtual ::std::vector< rtl::OUString >& getImageNames(); 86 virtual ::std::vector< rtl::OUString >& getImageCommandNames(); 87 88 protected: 89 void impl_fillCommandToImageNameMap(); 90 ImageList* impl_getImageList( sal_Int16 nImageType ); 91 std::vector< ::rtl::OUString >& impl_getImageNameVector(); 92 std::vector< ::rtl::OUString >& impl_getImageCommandNameVector(); 93 94 private: 95 sal_Bool m_bVectorInit; 96 rtl::OUString m_aModuleIdentifier; 97 ImageList* m_pImageList[ImageType_COUNT]; 98 CommandToImageNameMap m_aCommandToImageNameMap; 99 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager; 100 ::std::vector< rtl::OUString > m_aImageNameVector; 101 ::std::vector< rtl::OUString > m_aImageCommandNameVector; 102 sal_Int16 m_nSymbolsStyle; 103 }; 104 105 class GlobalImageList : public CmdImageList, public rtl::IReference 106 { 107 public: 108 GlobalImageList( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager ); 109 virtual ~GlobalImageList(); 110 111 virtual Image getImageFromCommandURL( sal_Int16 nImageType, const rtl::OUString& rCommandURL ); 112 virtual bool hasImage( sal_Int16 nImageType, const rtl::OUString& rCommandURL ); 113 virtual ::std::vector< rtl::OUString >& getImageNames(); 114 virtual ::std::vector< rtl::OUString >& getImageCommandNames(); 115 116 // �Reference 117 virtual oslInterlockedCount SAL_CALL acquire(); 118 virtual oslInterlockedCount SAL_CALL release(); 119 120 private: 121 oslInterlockedCount m_nRefCount; 122 }; 123 124 class ImageManagerImpl : public ThreadHelpBase // Struct for right initalization of mutex member! Must be first of baseclasses. 125 { 126 public: 127 128 ImageManagerImpl(const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager 129 ,const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& _xOwner 130 ,bool _bUseGlobal); 131 ~ImageManagerImpl(); 132 133 void dispose(); 134 void initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ); 135 void addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 136 void removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 137 138 // XImageManager 139 void reset() throw (::com::sun::star::uno::RuntimeException); 140 ::com::sun::star::uno::Sequence< ::rtl::OUString > getAllImageNames( ::sal_Int16 nImageType ) throw (::com::sun::star::uno::RuntimeException); 141 ::sal_Bool hasImage( ::sal_Int16 nImageType, const ::rtl::OUString& aCommandURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 142 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > > getImages( ::sal_Int16 nImageType, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aCommandURLSequence ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 143 void replaceImages( ::sal_Int16 nImageType, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aCommandURLSequence, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > >& aGraphicsSequence ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 144 void removeImages( ::sal_Int16 nImageType, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aResourceURLSequence ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 145 void insertImages( ::sal_Int16 nImageType, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aCommandURLSequence, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > >& aGraphicSequence ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 146 147 // XUIConfiguration 148 void addConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 149 void removeConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 150 151 // XUIConfigurationPersistence 152 void reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 153 void store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 154 void storeToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 155 sal_Bool isModified() throw (::com::sun::star::uno::RuntimeException); 156 sal_Bool isReadOnly() throw (::com::sun::star::uno::RuntimeException); 157 158 void clear(); 159 160 typedef std::hash_map< rtl::OUString, 161 sal_Bool, 162 OUStringHashCode, 163 ::std::equal_to< ::rtl::OUString > > ImageNameMap; 164 165 enum Layer 166 { 167 LAYER_DEFAULT, 168 LAYER_USERDEFINED, 169 LAYER_COUNT 170 }; 171 172 enum NotifyOp 173 { 174 NotifyOp_Remove, 175 NotifyOp_Insert, 176 NotifyOp_Replace 177 }; 178 179 typedef ::std::vector< ::com::sun::star::ui::ConfigurationEvent > ConfigEventNotifyContainer; 180 181 // private methods 182 void implts_initialize(); 183 void implts_notifyContainerListener( const ::com::sun::star::ui::ConfigurationEvent& aEvent, NotifyOp eOp ); 184 ImageList* implts_getUserImageList( ImageType nImageType ); 185 sal_Bool implts_loadUserImages( ImageType nImageType, 186 const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xUserImageStorage, 187 const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xUserBitmapsStorage ); 188 sal_Bool implts_storeUserImages( ImageType nImageType, 189 const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xUserImageStorage, 190 const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xUserBitmapsStorage ); 191 const rtl::Reference< GlobalImageList >& implts_getGlobalImageList(); 192 CmdImageList* implts_getDefaultImageList(); 193 194 195 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xUserConfigStorage; 196 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xUserImageStorage; 197 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xUserBitmapsStorage; 198 com::sun::star::uno::Reference< com::sun::star::embed::XTransactedObject > m_xUserRootCommit; 199 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xServiceManager; 200 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > m_xOwner; 201 rtl::Reference< GlobalImageList > m_pGlobalImageList; 202 CmdImageList* m_pDefaultImageList; 203 rtl::OUString m_aXMLPostfix; 204 rtl::OUString m_aModuleIdentifier; 205 rtl::OUString m_aResourceString; 206 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener 207 ImageList* m_pUserImageList[ImageType_COUNT]; 208 bool m_bUserImageListModified[ImageType_COUNT]; 209 bool m_bUseGlobal; 210 bool m_bReadOnly; 211 bool m_bInitialized; 212 bool m_bModified; 213 bool m_bConfigRead; 214 bool m_bDisposed; 215 }; 216 } 217 218 #endif // __FRAMEWORK_UICONFIGURATION_IMAGEMANAGERIMPL_HXX_ 219