1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_framework.hxx"
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski #include <uiconfiguration/imagemanager.hxx>
28*b1cdbd2cSJim Jagielski #include <threadhelp/resetableguard.hxx>
29*b1cdbd2cSJim Jagielski #include <xml/imagesconfiguration.hxx>
30*b1cdbd2cSJim Jagielski #include <uiconfiguration/graphicnameaccess.hxx>
31*b1cdbd2cSJim Jagielski #include <services.h>
32*b1cdbd2cSJim Jagielski #include "imagemanagerimpl.hxx"
33*b1cdbd2cSJim Jagielski 
34*b1cdbd2cSJim Jagielski #include "properties.h"
35*b1cdbd2cSJim Jagielski 
36*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
37*b1cdbd2cSJim Jagielski //	interface includes
38*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
39*b1cdbd2cSJim Jagielski #include <com/sun/star/ui/UIElementType.hpp>
40*b1cdbd2cSJim Jagielski #include <com/sun/star/ui/ConfigurationEvent.hpp>
41*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/DisposedException.hpp>
42*b1cdbd2cSJim Jagielski #include <com/sun/star/beans/XPropertySet.hpp>
43*b1cdbd2cSJim Jagielski #include <com/sun/star/beans/PropertyValue.hpp>
44*b1cdbd2cSJim Jagielski #include <com/sun/star/embed/ElementModes.hpp>
45*b1cdbd2cSJim Jagielski #include <com/sun/star/io/XStream.hpp>
46*b1cdbd2cSJim Jagielski #include <com/sun/star/ui/ImageType.hpp>
47*b1cdbd2cSJim Jagielski 
48*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
49*b1cdbd2cSJim Jagielski //	other includes
50*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
51*b1cdbd2cSJim Jagielski 
52*b1cdbd2cSJim Jagielski #include <vcl/svapp.hxx>
53*b1cdbd2cSJim Jagielski #include <rtl/ustrbuf.hxx>
54*b1cdbd2cSJim Jagielski #include <osl/mutex.hxx>
55*b1cdbd2cSJim Jagielski #include <comphelper/sequence.hxx>
56*b1cdbd2cSJim Jagielski #include <tools/urlobj.hxx>
57*b1cdbd2cSJim Jagielski #include <unotools/ucbstreamhelper.hxx>
58*b1cdbd2cSJim Jagielski #include <vcl/pngread.hxx>
59*b1cdbd2cSJim Jagielski #include <vcl/pngwrite.hxx>
60*b1cdbd2cSJim Jagielski #include <rtl/logfile.hxx>
61*b1cdbd2cSJim Jagielski 
62*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
63*b1cdbd2cSJim Jagielski //	namespaces
64*b1cdbd2cSJim Jagielski //_________________________________________________________________________________________________________________
65*b1cdbd2cSJim Jagielski 
66*b1cdbd2cSJim Jagielski using ::rtl::OUString;
67*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::Sequence;
68*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::XInterface;
69*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::Exception;
70*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::RuntimeException;
71*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::UNO_QUERY;
72*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::Any;
73*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::makeAny;
74*b1cdbd2cSJim Jagielski using ::com::sun::star::graphic::XGraphic;
75*b1cdbd2cSJim Jagielski using namespace ::com::sun::star;
76*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::io;
77*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::embed;
78*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::lang;
79*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::container;
80*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::beans;
81*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::ui;
82*b1cdbd2cSJim Jagielski 
83*b1cdbd2cSJim Jagielski // Image sizes for our toolbars/menus
84*b1cdbd2cSJim Jagielski const sal_Int32 IMAGE_SIZE_NORMAL         = 16;
85*b1cdbd2cSJim Jagielski const sal_Int32 IMAGE_SIZE_LARGE          = 26;
86*b1cdbd2cSJim Jagielski const sal_Int16 MAX_IMAGETYPE_VALUE       = ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST|
87*b1cdbd2cSJim Jagielski                                             ::com::sun::star::ui::ImageType::SIZE_LARGE;
88*b1cdbd2cSJim Jagielski 
89*b1cdbd2cSJim Jagielski namespace framework
90*b1cdbd2cSJim Jagielski {
91*b1cdbd2cSJim Jagielski 
92*b1cdbd2cSJim Jagielski typedef GraphicNameAccess CmdToXGraphicNameAccess;
93*b1cdbd2cSJim Jagielski 
94*b1cdbd2cSJim Jagielski //*****************************************************************************************************************
95*b1cdbd2cSJim Jagielski //	XInterface, XTypeProvider, XServiceInfo
96*b1cdbd2cSJim Jagielski //*****************************************************************************************************************
DEFINE_XSERVICEINFO_MULTISERVICE(ImageManager,::cppu::OWeakObject,SERVICENAME_IMAGEMANAGER,IMPLEMENTATIONNAME_IMAGEMANAGER)97*b1cdbd2cSJim Jagielski DEFINE_XSERVICEINFO_MULTISERVICE        (   ImageManager						,
98*b1cdbd2cSJim Jagielski                                             ::cppu::OWeakObject                 ,
99*b1cdbd2cSJim Jagielski                                             SERVICENAME_IMAGEMANAGER			,
100*b1cdbd2cSJim Jagielski 											IMPLEMENTATIONNAME_IMAGEMANAGER
101*b1cdbd2cSJim Jagielski 										)
102*b1cdbd2cSJim Jagielski 
103*b1cdbd2cSJim Jagielski DEFINE_INIT_SERVICE                     (   ImageManager, {} )
104*b1cdbd2cSJim Jagielski 
105*b1cdbd2cSJim Jagielski ImageManager::ImageManager( uno::Reference< XMultiServiceFactory > xServiceManager ) :
106*b1cdbd2cSJim Jagielski     ThreadHelpBase( &Application::GetSolarMutex() )
107*b1cdbd2cSJim Jagielski     , m_pImpl( new ImageManagerImpl(xServiceManager,static_cast< OWeakObject* >(this),false) )
108*b1cdbd2cSJim Jagielski {
109*b1cdbd2cSJim Jagielski }
110*b1cdbd2cSJim Jagielski 
~ImageManager()111*b1cdbd2cSJim Jagielski ImageManager::~ImageManager()
112*b1cdbd2cSJim Jagielski {
113*b1cdbd2cSJim Jagielski     m_pImpl->clear();
114*b1cdbd2cSJim Jagielski }
115*b1cdbd2cSJim Jagielski 
116*b1cdbd2cSJim Jagielski // XComponent
dispose()117*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::dispose() throw (::com::sun::star::uno::RuntimeException)
118*b1cdbd2cSJim Jagielski {
119*b1cdbd2cSJim Jagielski     m_pImpl->dispose();
120*b1cdbd2cSJim Jagielski }
121*b1cdbd2cSJim Jagielski 
addEventListener(const uno::Reference<XEventListener> & xListener)122*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::addEventListener( const uno::Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
123*b1cdbd2cSJim Jagielski {
124*b1cdbd2cSJim Jagielski     m_pImpl->addEventListener(xListener);
125*b1cdbd2cSJim Jagielski }
126*b1cdbd2cSJim Jagielski 
removeEventListener(const uno::Reference<XEventListener> & xListener)127*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::removeEventListener( const uno::Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
128*b1cdbd2cSJim Jagielski {
129*b1cdbd2cSJim Jagielski     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
130*b1cdbd2cSJim Jagielski     m_pImpl->removeEventListener(xListener);
131*b1cdbd2cSJim Jagielski }
132*b1cdbd2cSJim Jagielski 
133*b1cdbd2cSJim Jagielski // Non-UNO methods
setStorage(const uno::Reference<XStorage> & Storage)134*b1cdbd2cSJim Jagielski void ImageManager::setStorage( const uno::Reference< XStorage >& Storage )
135*b1cdbd2cSJim Jagielski throw (::com::sun::star::uno::RuntimeException)
136*b1cdbd2cSJim Jagielski {
137*b1cdbd2cSJim Jagielski     ResetableGuard aLock( m_pImpl->m_aLock );
138*b1cdbd2cSJim Jagielski 
139*b1cdbd2cSJim Jagielski     m_pImpl->m_xUserConfigStorage = Storage;
140*b1cdbd2cSJim Jagielski     m_pImpl->implts_initialize();
141*b1cdbd2cSJim Jagielski }
142*b1cdbd2cSJim Jagielski 
143*b1cdbd2cSJim Jagielski // XInitialization
initialize(const Sequence<Any> & aArguments)144*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
145*b1cdbd2cSJim Jagielski {
146*b1cdbd2cSJim Jagielski     m_pImpl->initialize(aArguments);
147*b1cdbd2cSJim Jagielski }
148*b1cdbd2cSJim Jagielski 
149*b1cdbd2cSJim Jagielski // XImageManager
reset()150*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::reset()
151*b1cdbd2cSJim Jagielski throw (::com::sun::star::uno::RuntimeException)
152*b1cdbd2cSJim Jagielski {
153*b1cdbd2cSJim Jagielski 
154*b1cdbd2cSJim Jagielski     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
155*b1cdbd2cSJim Jagielski     m_pImpl->reset();
156*b1cdbd2cSJim Jagielski }
157*b1cdbd2cSJim Jagielski 
getAllImageNames(::sal_Int16 nImageType)158*b1cdbd2cSJim Jagielski Sequence< ::rtl::OUString > SAL_CALL ImageManager::getAllImageNames( ::sal_Int16 nImageType )
159*b1cdbd2cSJim Jagielski throw (::com::sun::star::uno::RuntimeException)
160*b1cdbd2cSJim Jagielski {
161*b1cdbd2cSJim Jagielski     return m_pImpl->getAllImageNames( nImageType );
162*b1cdbd2cSJim Jagielski }
163*b1cdbd2cSJim Jagielski 
hasImage(::sal_Int16 nImageType,const::rtl::OUString & aCommandURL)164*b1cdbd2cSJim Jagielski ::sal_Bool SAL_CALL ImageManager::hasImage( ::sal_Int16 nImageType, const ::rtl::OUString& aCommandURL )
165*b1cdbd2cSJim Jagielski throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
166*b1cdbd2cSJim Jagielski {
167*b1cdbd2cSJim Jagielski     return m_pImpl->hasImage(nImageType,aCommandURL);
168*b1cdbd2cSJim Jagielski }
169*b1cdbd2cSJim Jagielski 
getImages(::sal_Int16 nImageType,const Sequence<::rtl::OUString> & aCommandURLSequence)170*b1cdbd2cSJim Jagielski Sequence< uno::Reference< XGraphic > > SAL_CALL ImageManager::getImages(
171*b1cdbd2cSJim Jagielski     ::sal_Int16 nImageType,
172*b1cdbd2cSJim Jagielski     const Sequence< ::rtl::OUString >& aCommandURLSequence )
173*b1cdbd2cSJim Jagielski throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
174*b1cdbd2cSJim Jagielski {
175*b1cdbd2cSJim Jagielski     return m_pImpl->getImages(nImageType,aCommandURLSequence);
176*b1cdbd2cSJim Jagielski }
177*b1cdbd2cSJim Jagielski 
replaceImages(::sal_Int16 nImageType,const Sequence<::rtl::OUString> & aCommandURLSequence,const Sequence<uno::Reference<XGraphic>> & aGraphicsSequence)178*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::replaceImages(
179*b1cdbd2cSJim Jagielski     ::sal_Int16 nImageType,
180*b1cdbd2cSJim Jagielski     const Sequence< ::rtl::OUString >& aCommandURLSequence,
181*b1cdbd2cSJim Jagielski     const Sequence< uno::Reference< XGraphic > >& aGraphicsSequence )
182*b1cdbd2cSJim Jagielski throw ( ::com::sun::star::lang::IllegalArgumentException,
183*b1cdbd2cSJim Jagielski         ::com::sun::star::lang::IllegalAccessException,
184*b1cdbd2cSJim Jagielski         ::com::sun::star::uno::RuntimeException)
185*b1cdbd2cSJim Jagielski {
186*b1cdbd2cSJim Jagielski     m_pImpl->replaceImages(nImageType,aCommandURLSequence,aGraphicsSequence);
187*b1cdbd2cSJim Jagielski }
188*b1cdbd2cSJim Jagielski 
removeImages(::sal_Int16 nImageType,const Sequence<::rtl::OUString> & aCommandURLSequence)189*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::removeImages( ::sal_Int16 nImageType, const Sequence< ::rtl::OUString >& aCommandURLSequence )
190*b1cdbd2cSJim Jagielski throw ( ::com::sun::star::lang::IllegalArgumentException,
191*b1cdbd2cSJim Jagielski         ::com::sun::star::lang::IllegalAccessException,
192*b1cdbd2cSJim Jagielski         ::com::sun::star::uno::RuntimeException)
193*b1cdbd2cSJim Jagielski {
194*b1cdbd2cSJim Jagielski     m_pImpl->removeImages(nImageType,aCommandURLSequence);
195*b1cdbd2cSJim Jagielski }
196*b1cdbd2cSJim Jagielski 
insertImages(::sal_Int16 nImageType,const Sequence<::rtl::OUString> & aCommandURLSequence,const Sequence<uno::Reference<XGraphic>> & aGraphicSequence)197*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::insertImages( ::sal_Int16 nImageType, const Sequence< ::rtl::OUString >& aCommandURLSequence, const Sequence< uno::Reference< XGraphic > >& aGraphicSequence )
198*b1cdbd2cSJim Jagielski throw ( ::com::sun::star::container::ElementExistException,
199*b1cdbd2cSJim Jagielski         ::com::sun::star::lang::IllegalArgumentException,
200*b1cdbd2cSJim Jagielski         ::com::sun::star::lang::IllegalAccessException,
201*b1cdbd2cSJim Jagielski         ::com::sun::star::uno::RuntimeException)
202*b1cdbd2cSJim Jagielski {
203*b1cdbd2cSJim Jagielski     m_pImpl->insertImages(nImageType,aCommandURLSequence,aGraphicSequence);
204*b1cdbd2cSJim Jagielski }
205*b1cdbd2cSJim Jagielski 
206*b1cdbd2cSJim Jagielski // XUIConfiguration
addConfigurationListener(const uno::Reference<::com::sun::star::ui::XUIConfigurationListener> & xListener)207*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::addConfigurationListener( const uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener )
208*b1cdbd2cSJim Jagielski throw (::com::sun::star::uno::RuntimeException)
209*b1cdbd2cSJim Jagielski {
210*b1cdbd2cSJim Jagielski     m_pImpl->addConfigurationListener(xListener);
211*b1cdbd2cSJim Jagielski }
212*b1cdbd2cSJim Jagielski 
removeConfigurationListener(const uno::Reference<::com::sun::star::ui::XUIConfigurationListener> & xListener)213*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::removeConfigurationListener( const uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener )
214*b1cdbd2cSJim Jagielski throw (::com::sun::star::uno::RuntimeException)
215*b1cdbd2cSJim Jagielski {
216*b1cdbd2cSJim Jagielski     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
217*b1cdbd2cSJim Jagielski     m_pImpl->removeConfigurationListener(xListener);
218*b1cdbd2cSJim Jagielski }
219*b1cdbd2cSJim Jagielski 
220*b1cdbd2cSJim Jagielski // XUIConfigurationPersistence
reload()221*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::reload()
222*b1cdbd2cSJim Jagielski throw ( ::com::sun::star::uno::Exception,
223*b1cdbd2cSJim Jagielski         ::com::sun::star::uno::RuntimeException )
224*b1cdbd2cSJim Jagielski {
225*b1cdbd2cSJim Jagielski     m_pImpl->reload();
226*b1cdbd2cSJim Jagielski }
227*b1cdbd2cSJim Jagielski 
store()228*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::store()
229*b1cdbd2cSJim Jagielski throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
230*b1cdbd2cSJim Jagielski {
231*b1cdbd2cSJim Jagielski     m_pImpl->store();
232*b1cdbd2cSJim Jagielski }
233*b1cdbd2cSJim Jagielski 
storeToStorage(const uno::Reference<XStorage> & Storage)234*b1cdbd2cSJim Jagielski void SAL_CALL ImageManager::storeToStorage( const uno::Reference< XStorage >& Storage )
235*b1cdbd2cSJim Jagielski throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
236*b1cdbd2cSJim Jagielski {
237*b1cdbd2cSJim Jagielski     m_pImpl->storeToStorage(Storage);
238*b1cdbd2cSJim Jagielski }
239*b1cdbd2cSJim Jagielski 
isModified()240*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL ImageManager::isModified()
241*b1cdbd2cSJim Jagielski throw (::com::sun::star::uno::RuntimeException)
242*b1cdbd2cSJim Jagielski {
243*b1cdbd2cSJim Jagielski     return m_pImpl->isModified();
244*b1cdbd2cSJim Jagielski }
245*b1cdbd2cSJim Jagielski 
isReadOnly()246*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL ImageManager::isReadOnly() throw (::com::sun::star::uno::RuntimeException)
247*b1cdbd2cSJim Jagielski {
248*b1cdbd2cSJim Jagielski     return m_pImpl->isReadOnly();
249*b1cdbd2cSJim Jagielski }
250*b1cdbd2cSJim Jagielski 
251*b1cdbd2cSJim Jagielski } // namespace framework
252