1f8e07b45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f8e07b45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f8e07b45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f8e07b45SAndrew Rist  * distributed with this work for additional information
6f8e07b45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f8e07b45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f8e07b45SAndrew Rist  * "License"); you may not use this file except in compliance
9f8e07b45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f8e07b45SAndrew Rist  *
11f8e07b45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f8e07b45SAndrew Rist  *
13f8e07b45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f8e07b45SAndrew Rist  * software distributed under the License is distributed on an
15f8e07b45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f8e07b45SAndrew Rist  * KIND, either express or implied.  See the License for the
17f8e07b45SAndrew Rist  * specific language governing permissions and limitations
18f8e07b45SAndrew Rist  * under the License.
19f8e07b45SAndrew Rist  *
20f8e07b45SAndrew Rist  *************************************************************/
21f8e07b45SAndrew Rist 
22f8e07b45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __FRAMEWORK_UICONFIGURATION_IMAGEMANAGERIMPL_HXX_
25cdf0e10cSrcweir #define __FRAMEWORK_UICONFIGURATION_IMAGEMANAGERIMPL_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28*15289133Smseidel /** Attention: stl headers must(!) be included at first. Otherwise it can make trouble
29cdf0e10cSrcweir                with solaris headers ...
30cdf0e10cSrcweir */
31cdf0e10cSrcweir #include <vector>
32cdf0e10cSrcweir #include <list>
33cdf0e10cSrcweir #include <hash_map>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36cdf0e10cSrcweir //	my own includes
37cdf0e10cSrcweir //_________________________________________________________________________________________________________________
38cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx>
39cdf0e10cSrcweir #include <macros/generic.hxx>
40cdf0e10cSrcweir #include <macros/xinterface.hxx>
41cdf0e10cSrcweir #include <macros/xtypeprovider.hxx>
42cdf0e10cSrcweir #include <macros/xserviceinfo.hxx>
43cdf0e10cSrcweir #include <stdtypes.h>
44cdf0e10cSrcweir #include <uiconfiguration/imagetype.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //_________________________________________________________________________________________________________________
47cdf0e10cSrcweir //	interface includes
48cdf0e10cSrcweir //_________________________________________________________________________________________________________________
49cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
50cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
51cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
52cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
53cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
54cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfiguration.hpp>
55cdf0e10cSrcweir #include <com/sun/star/ui/XImageManager.hpp>
56cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
57cdf0e10cSrcweir #include <com/sun/star/ui/ConfigurationEvent.hpp>
58cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
59cdf0e10cSrcweir #include <com/sun/star/ui/XImageManager.hpp>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62cdf0e10cSrcweir //	other includes
63cdf0e10cSrcweir //_________________________________________________________________________________________________________________
64cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
65cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
66cdf0e10cSrcweir #include <rtl/ustring.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #include <vcl/image.hxx>
69cdf0e10cSrcweir #include <tools/color.hxx>
70cdf0e10cSrcweir #include <rtl/ref.hxx>
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #include <vector>
73cdf0e10cSrcweir 
74cdf0e10cSrcweir namespace framework
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     class CmdImageList
77cdf0e10cSrcweir     {
78cdf0e10cSrcweir         public:
79cdf0e10cSrcweir             CmdImageList( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager,
80cdf0e10cSrcweir                           const ::rtl::OUString& aModuleIdentifier );
81cdf0e10cSrcweir 		    virtual ~CmdImageList();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir             virtual Image                           getImageFromCommandURL( sal_Int16 nImageType, const rtl::OUString& rCommandURL );
84cdf0e10cSrcweir             virtual bool                            hasImage( sal_Int16 nImageType, const rtl::OUString& rCommandURL );
85cdf0e10cSrcweir             virtual ::std::vector< rtl::OUString >& getImageNames();
86cdf0e10cSrcweir             virtual ::std::vector< rtl::OUString >& getImageCommandNames();
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         protected:
89cdf0e10cSrcweir             void                            impl_fillCommandToImageNameMap();
90cdf0e10cSrcweir             ImageList*                      impl_getImageList( sal_Int16 nImageType );
91cdf0e10cSrcweir             std::vector< ::rtl::OUString >& impl_getImageNameVector();
92cdf0e10cSrcweir             std::vector< ::rtl::OUString >& impl_getImageCommandNameVector();
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         private:
95cdf0e10cSrcweir             sal_Bool                                                                         m_bVectorInit;
96cdf0e10cSrcweir             rtl::OUString                                                                    m_aModuleIdentifier;
97cdf0e10cSrcweir             ImageList*                                                                       m_pImageList[ImageType_COUNT];
98cdf0e10cSrcweir             CommandToImageNameMap                                                            m_aCommandToImageNameMap;
99cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
100cdf0e10cSrcweir             ::std::vector< rtl::OUString >                                                   m_aImageNameVector;
101cdf0e10cSrcweir             ::std::vector< rtl::OUString >                                                   m_aImageCommandNameVector;
102cdf0e10cSrcweir             sal_Int16                                                                        m_nSymbolsStyle;
103cdf0e10cSrcweir     };
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     class GlobalImageList : public CmdImageList, public rtl::IReference
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         public:
108cdf0e10cSrcweir             GlobalImageList( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager );
109cdf0e10cSrcweir             virtual ~GlobalImageList();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir             virtual Image                           getImageFromCommandURL( sal_Int16 nImageType, const rtl::OUString& rCommandURL );
112cdf0e10cSrcweir             virtual bool                            hasImage( sal_Int16 nImageType, const rtl::OUString& rCommandURL );
113cdf0e10cSrcweir             virtual ::std::vector< rtl::OUString >& getImageNames();
114cdf0e10cSrcweir             virtual ::std::vector< rtl::OUString >& getImageCommandNames();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir             // �Reference
117cdf0e10cSrcweir             virtual oslInterlockedCount SAL_CALL acquire();
118cdf0e10cSrcweir 	        virtual oslInterlockedCount SAL_CALL release();
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         private:
121cdf0e10cSrcweir             oslInterlockedCount                                                              m_nRefCount;
122cdf0e10cSrcweir     };
123cdf0e10cSrcweir 
12430acf5e8Spfg     class ImageManagerImpl : public ThreadHelpBase	// Struct for right initialization of mutex member! Must be first of baseclasses.
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         public:
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             ImageManagerImpl(const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager
129cdf0e10cSrcweir                 ,const  com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& _xOwner
130cdf0e10cSrcweir                 ,bool _bUseGlobal);
131cdf0e10cSrcweir             ~ImageManagerImpl();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir             void dispose();
134cdf0e10cSrcweir             void initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments );
135cdf0e10cSrcweir             void addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
136cdf0e10cSrcweir             void removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             // XImageManager
139cdf0e10cSrcweir             void reset() throw (::com::sun::star::uno::RuntimeException);
140cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::rtl::OUString > getAllImageNames( ::sal_Int16 nImageType ) throw (::com::sun::star::uno::RuntimeException);
141cdf0e10cSrcweir             ::sal_Bool hasImage( ::sal_Int16 nImageType, const ::rtl::OUString& aCommandURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
142cdf0e10cSrcweir             ::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);
143cdf0e10cSrcweir             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);
144cdf0e10cSrcweir             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);
145cdf0e10cSrcweir             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);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir             // XUIConfiguration
148cdf0e10cSrcweir             void addConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
149cdf0e10cSrcweir             void removeConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             // XUIConfigurationPersistence
152cdf0e10cSrcweir             void reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
153cdf0e10cSrcweir             void store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
154cdf0e10cSrcweir             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);
155cdf0e10cSrcweir             sal_Bool isModified() throw (::com::sun::star::uno::RuntimeException);
156cdf0e10cSrcweir             sal_Bool isReadOnly() throw (::com::sun::star::uno::RuntimeException);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             void clear();
159cdf0e10cSrcweir 
160cdf0e10cSrcweir             typedef std::hash_map< rtl::OUString,
161cdf0e10cSrcweir                                    sal_Bool,
1625758ad8cSAriel Constenla-Haile                                    rtl::OUStringHash,
163cdf0e10cSrcweir                                    ::std::equal_to< ::rtl::OUString > > ImageNameMap;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir             enum Layer
166cdf0e10cSrcweir             {
167cdf0e10cSrcweir                 LAYER_DEFAULT,
168cdf0e10cSrcweir                 LAYER_USERDEFINED,
169cdf0e10cSrcweir                 LAYER_COUNT
170cdf0e10cSrcweir             };
171cdf0e10cSrcweir 
172cdf0e10cSrcweir             enum NotifyOp
173cdf0e10cSrcweir             {
174cdf0e10cSrcweir                 NotifyOp_Remove,
175cdf0e10cSrcweir                 NotifyOp_Insert,
176cdf0e10cSrcweir                 NotifyOp_Replace
177cdf0e10cSrcweir             };
178cdf0e10cSrcweir 
179cdf0e10cSrcweir             typedef ::std::vector< ::com::sun::star::ui::ConfigurationEvent > ConfigEventNotifyContainer;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir             // private methods
182cdf0e10cSrcweir             void                                      implts_initialize();
183cdf0e10cSrcweir             void                                      implts_notifyContainerListener( const ::com::sun::star::ui::ConfigurationEvent& aEvent, NotifyOp eOp );
184cdf0e10cSrcweir             ImageList*                                implts_getUserImageList( ImageType nImageType );
185cdf0e10cSrcweir             sal_Bool                                  implts_loadUserImages( ImageType nImageType,
186cdf0e10cSrcweir                                                                              const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xUserImageStorage,
187cdf0e10cSrcweir                                                                              const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xUserBitmapsStorage );
188cdf0e10cSrcweir             sal_Bool                                  implts_storeUserImages( ImageType nImageType,
189cdf0e10cSrcweir                                                                               const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xUserImageStorage,
190cdf0e10cSrcweir                                                                               const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xUserBitmapsStorage );
191cdf0e10cSrcweir             const rtl::Reference< GlobalImageList >&  implts_getGlobalImageList();
192cdf0e10cSrcweir             CmdImageList*                             implts_getDefaultImageList();
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 
195cdf0e10cSrcweir             com::sun::star::uno::Reference< com::sun::star::embed::XStorage >               m_xUserConfigStorage;
196cdf0e10cSrcweir             com::sun::star::uno::Reference< com::sun::star::embed::XStorage >               m_xUserImageStorage;
197cdf0e10cSrcweir             com::sun::star::uno::Reference< com::sun::star::embed::XStorage >               m_xUserBitmapsStorage;
198cdf0e10cSrcweir             com::sun::star::uno::Reference< com::sun::star::embed::XTransactedObject >      m_xUserRootCommit;
199cdf0e10cSrcweir             com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >    m_xServiceManager;
200cdf0e10cSrcweir             com::sun::star::uno::Reference< com::sun::star::uno::XInterface >               m_xOwner;
201cdf0e10cSrcweir             rtl::Reference< GlobalImageList >                                               m_pGlobalImageList;
202cdf0e10cSrcweir             CmdImageList*                                                                   m_pDefaultImageList;
203cdf0e10cSrcweir             rtl::OUString                                                                   m_aXMLPostfix;
204cdf0e10cSrcweir             rtl::OUString                                                                   m_aModuleIdentifier;
205cdf0e10cSrcweir             rtl::OUString                                                                   m_aResourceString;
206cdf0e10cSrcweir             ::cppu::OMultiTypeInterfaceContainerHelper                                      m_aListenerContainer;   /// container for ALL Listener
207cdf0e10cSrcweir             ImageList*                                                                      m_pUserImageList[ImageType_COUNT];
208cdf0e10cSrcweir             bool                                                                            m_bUserImageListModified[ImageType_COUNT];
209cdf0e10cSrcweir             bool                                                                            m_bUseGlobal;
210cdf0e10cSrcweir             bool                                                                            m_bReadOnly;
211cdf0e10cSrcweir             bool                                                                            m_bInitialized;
212cdf0e10cSrcweir             bool                                                                            m_bModified;
213cdf0e10cSrcweir             bool                                                                            m_bConfigRead;
214cdf0e10cSrcweir             bool                                                                            m_bDisposed;
215cdf0e10cSrcweir    };
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir #endif // __FRAMEWORK_UICONFIGURATION_IMAGEMANAGERIMPL_HXX_
219