xref: /AOO41X/main/forms/source/component/ImageControl.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _FRM_IMAGE_CONTROL_HXX_
29*cdf0e10cSrcweir #define _FRM_IMAGE_CONTROL_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "FormComponent.hxx"
32*cdf0e10cSrcweir #include "imgprod.hxx"
33*cdf0e10cSrcweir #include <com/sun/star/form/XImageProducerSupplier.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/awt/XMouseListener.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicObject.hpp>
37*cdf0e10cSrcweir #include <comphelper/propmultiplex.hxx>
38*cdf0e10cSrcweir #include <comphelper/implementationreference.hxx>
39*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace comphelper;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //.........................................................................
44*cdf0e10cSrcweir namespace frm
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir //.........................................................................
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //==================================================================
49*cdf0e10cSrcweir // OImageControlModel
50*cdf0e10cSrcweir //==================================================================
51*cdf0e10cSrcweir typedef ::cppu::ImplHelper2 <   ::com::sun::star::form::XImageProducerSupplier
52*cdf0e10cSrcweir                             ,   ::com::sun::star::awt::XImageProducer
53*cdf0e10cSrcweir                             >   OImageControlModel_Base;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir class OImageControlModel
56*cdf0e10cSrcweir 				:public OImageControlModel_Base
57*cdf0e10cSrcweir 				,public OBoundControlModel
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> 	m_xImageProducer;
60*cdf0e10cSrcweir 	ImageProducer*									m_pImageProducer;
61*cdf0e10cSrcweir     bool                                            m_bExternalGraphic;
62*cdf0e10cSrcweir 	sal_Bool										m_bReadOnly;
63*cdf0e10cSrcweir     ::rtl::OUString                                 m_sImageURL;
64*cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicObject >
65*cdf0e10cSrcweir                                                     m_xGraphicObject;
66*cdf0e10cSrcweir     ::rtl::OUString                                 m_sDocumentURL;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir protected:
69*cdf0e10cSrcweir 	// UNO Anbindung
70*cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	inline ImageProducer* GetImageProducer() { return m_pImageProducer; }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir public:
75*cdf0e10cSrcweir 	DECLARE_DEFAULT_LEAF_XTOR( OImageControlModel );
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
78*cdf0e10cSrcweir 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue) throw ( ::com::sun::star::uno::Exception);
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL convertFastPropertyValue(::com::sun::star::uno::Any& rConvertedValue, ::com::sun::star::uno::Any& rOldValue, sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
81*cdf0e10cSrcweir 		throw(::com::sun::star::lang::IllegalArgumentException);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	// UNO Anbindung
84*cdf0e10cSrcweir 	DECLARE_UNO3_AGG_DEFAULTS(OImageControlModel, OBoundControlModel);
85*cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     // XServiceInfo
88*cdf0e10cSrcweir 	IMPLEMENTATION_NAME(OImageControlModel);
89*cdf0e10cSrcweir 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     // OComponentHelper
92*cdf0e10cSrcweir 	virtual void SAL_CALL disposing();
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     // XPersistObject
95*cdf0e10cSrcweir 	virtual ::rtl::OUString SAL_CALL getServiceName() throw ( ::com::sun::star::uno::RuntimeException);
96*cdf0e10cSrcweir 	virtual void SAL_CALL write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
97*cdf0e10cSrcweir 	virtual void SAL_CALL read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     // XImageProducerSupplier
100*cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> SAL_CALL getImageProducer() throw ( ::com::sun::star::uno::RuntimeException);
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     // XImageProducer
103*cdf0e10cSrcweir     virtual void SAL_CALL addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException);
104*cdf0e10cSrcweir     virtual void SAL_CALL removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException);
105*cdf0e10cSrcweir     virtual void SAL_CALL startProduction(  ) throw (::com::sun::star::uno::RuntimeException);
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     // OControlModel's property handling
108*cdf0e10cSrcweir     virtual void describeAggregateProperties(
109*cdf0e10cSrcweir 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
110*cdf0e10cSrcweir     ) const;
111*cdf0e10cSrcweir 	virtual void describeFixedProperties(
112*cdf0e10cSrcweir 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
113*cdf0e10cSrcweir     ) const;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     // prevent method hiding
116*cdf0e10cSrcweir     using OBoundControlModel::disposing;
117*cdf0e10cSrcweir     using OBoundControlModel::getFastPropertyValue;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir protected:
120*cdf0e10cSrcweir     // OBoundControlModel overridables
121*cdf0e10cSrcweir 	virtual void            onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
122*cdf0e10cSrcweir 	virtual void            onDisconnectedDbColumn();
123*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Any
124*cdf0e10cSrcweir                             translateDbColumnToControlValue( );
125*cdf0e10cSrcweir     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Any
128*cdf0e10cSrcweir                             getControlValue( ) const;
129*cdf0e10cSrcweir     virtual void            doSetControlValue( const ::com::sun::star::uno::Any& _rValue );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     virtual sal_Bool		approveDbColumnType(sal_Int32 _nColumnType);
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	virtual void            resetNoBroadcast();
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir protected:
136*cdf0e10cSrcweir 	DECLARE_XCLONEABLE();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	void implConstruct();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     /** displays the image described by the given URL
141*cdf0e10cSrcweir         @precond
142*cdf0e10cSrcweir             our own mutex is locked
143*cdf0e10cSrcweir     */
144*cdf0e10cSrcweir     sal_Bool    impl_handleNewImageURL_lck( ValueChangeInstigator _eInstigator );
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     /** updates the binary stream, created from loading the file which the given URL points to, into our
147*cdf0e10cSrcweir         bound field, or the control itself if there is no bound field
148*cdf0e10cSrcweir     */
149*cdf0e10cSrcweir     sal_Bool    impl_updateStreamForURL_lck( const ::rtl::OUString& _rURL, ValueChangeInstigator _eInstigator );
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     DECL_LINK( OnImageImportDone, ::Graphic* );
152*cdf0e10cSrcweir };
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir //==================================================================
155*cdf0e10cSrcweir //= OImageControlControl
156*cdf0e10cSrcweir //==================================================================
157*cdf0e10cSrcweir typedef ::cppu::ImplHelper2 <   ::com::sun::star::awt::XMouseListener
158*cdf0e10cSrcweir                             ,   ::com::sun::star::util::XModifyBroadcaster
159*cdf0e10cSrcweir                             >   OImageControlControl_Base;
160*cdf0e10cSrcweir class OImageControlControl  : public OBoundControl
161*cdf0e10cSrcweir                             , public OImageControlControl_Base
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir private:
164*cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper   m_aModifyListeners;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     // XTypeProvider
167*cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir public:
170*cdf0e10cSrcweir 	OImageControlControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     // UNO
173*cdf0e10cSrcweir 	DECLARE_UNO3_AGG_DEFAULTS( OImageControlControl, OBoundControl );
174*cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(::com::sun::star::uno::RuntimeException);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     // XEventListener
177*cdf0e10cSrcweir 	virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException);
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir     // XServiceInfo
180*cdf0e10cSrcweir 	IMPLEMENTATION_NAME(OImageControlControl);
181*cdf0e10cSrcweir 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     // XMouseListener
184*cdf0e10cSrcweir 	virtual void SAL_CALL mousePressed(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
185*cdf0e10cSrcweir 	virtual void SAL_CALL mouseReleased(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
186*cdf0e10cSrcweir 	virtual void SAL_CALL mouseEntered(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
187*cdf0e10cSrcweir 	virtual void SAL_CALL mouseExited(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     // XModifyBroadcaster
190*cdf0e10cSrcweir     virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
191*cdf0e10cSrcweir     virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     // OComponentHelper
194*cdf0e10cSrcweir     virtual void SAL_CALL disposing();
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir private:
197*cdf0e10cSrcweir 	void	implClearGraphics( sal_Bool _bForce );
198*cdf0e10cSrcweir 	bool    implInsertGraphics();
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     /** determines whether the control does currently have an empty grahic set
201*cdf0e10cSrcweir     */
202*cdf0e10cSrcweir     bool    impl_isEmptyGraphics_nothrow() const;
203*cdf0e10cSrcweir };
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir //.........................................................................
206*cdf0e10cSrcweir }	// namespace frm
207*cdf0e10cSrcweir //.........................................................................
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir #endif // _FRM_IMAGE_CONTROL_HXX_
210*cdf0e10cSrcweir 
211