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