xref: /AOO41X/main/forms/source/component/ImageControl.hxx (revision 2d785d7ea953737df3731803a26e291d82066c5a)
1*2d785d7eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2d785d7eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2d785d7eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2d785d7eSAndrew Rist  * distributed with this work for additional information
6*2d785d7eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2d785d7eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2d785d7eSAndrew Rist  * "License"); you may not use this file except in compliance
9*2d785d7eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2d785d7eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2d785d7eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2d785d7eSAndrew Rist  * software distributed under the License is distributed on an
15*2d785d7eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2d785d7eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2d785d7eSAndrew Rist  * specific language governing permissions and limitations
18*2d785d7eSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2d785d7eSAndrew Rist  *************************************************************/
21*2d785d7eSAndrew Rist 
22*2d785d7eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _FRM_IMAGE_CONTROL_HXX_
25cdf0e10cSrcweir #define _FRM_IMAGE_CONTROL_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "FormComponent.hxx"
28cdf0e10cSrcweir #include "imgprod.hxx"
29cdf0e10cSrcweir #include <com/sun/star/form/XImageProducerSupplier.hpp>
30cdf0e10cSrcweir #include <com/sun/star/awt/XMouseListener.hpp>
31cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
32cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicObject.hpp>
33cdf0e10cSrcweir #include <comphelper/propmultiplex.hxx>
34cdf0e10cSrcweir #include <comphelper/implementationreference.hxx>
35cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace comphelper;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //.........................................................................
40cdf0e10cSrcweir namespace frm
41cdf0e10cSrcweir {
42cdf0e10cSrcweir //.........................................................................
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //==================================================================
45cdf0e10cSrcweir // OImageControlModel
46cdf0e10cSrcweir //==================================================================
47cdf0e10cSrcweir typedef ::cppu::ImplHelper2 <   ::com::sun::star::form::XImageProducerSupplier
48cdf0e10cSrcweir                             ,   ::com::sun::star::awt::XImageProducer
49cdf0e10cSrcweir                             >   OImageControlModel_Base;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir class OImageControlModel
52cdf0e10cSrcweir 				:public OImageControlModel_Base
53cdf0e10cSrcweir 				,public OBoundControlModel
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> 	m_xImageProducer;
56cdf0e10cSrcweir 	ImageProducer*									m_pImageProducer;
57cdf0e10cSrcweir     bool                                            m_bExternalGraphic;
58cdf0e10cSrcweir 	sal_Bool										m_bReadOnly;
59cdf0e10cSrcweir     ::rtl::OUString                                 m_sImageURL;
60cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicObject >
61cdf0e10cSrcweir                                                     m_xGraphicObject;
62cdf0e10cSrcweir     ::rtl::OUString                                 m_sDocumentURL;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir protected:
65cdf0e10cSrcweir 	// UNO Anbindung
66cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
67cdf0e10cSrcweir 
GetImageProducer()68cdf0e10cSrcweir 	inline ImageProducer* GetImageProducer() { return m_pImageProducer; }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir public:
71cdf0e10cSrcweir 	DECLARE_DEFAULT_LEAF_XTOR( OImageControlModel );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
74cdf0e10cSrcweir 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue) throw ( ::com::sun::star::uno::Exception);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	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 )
77cdf0e10cSrcweir 		throw(::com::sun::star::lang::IllegalArgumentException);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	// UNO Anbindung
80cdf0e10cSrcweir 	DECLARE_UNO3_AGG_DEFAULTS(OImageControlModel, OBoundControlModel);
81cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     // XServiceInfo
84cdf0e10cSrcweir 	IMPLEMENTATION_NAME(OImageControlModel);
85cdf0e10cSrcweir 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     // OComponentHelper
88cdf0e10cSrcweir 	virtual void SAL_CALL disposing();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     // XPersistObject
91cdf0e10cSrcweir 	virtual ::rtl::OUString SAL_CALL getServiceName() throw ( ::com::sun::star::uno::RuntimeException);
92cdf0e10cSrcweir 	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);
93cdf0e10cSrcweir 	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);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     // XImageProducerSupplier
96cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> SAL_CALL getImageProducer() throw ( ::com::sun::star::uno::RuntimeException);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     // XImageProducer
99cdf0e10cSrcweir     virtual void SAL_CALL addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException);
100cdf0e10cSrcweir     virtual void SAL_CALL removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException);
101cdf0e10cSrcweir     virtual void SAL_CALL startProduction(  ) throw (::com::sun::star::uno::RuntimeException);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     // OControlModel's property handling
104cdf0e10cSrcweir     virtual void describeAggregateProperties(
105cdf0e10cSrcweir 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
106cdf0e10cSrcweir     ) const;
107cdf0e10cSrcweir 	virtual void describeFixedProperties(
108cdf0e10cSrcweir 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
109cdf0e10cSrcweir     ) const;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     // prevent method hiding
112cdf0e10cSrcweir     using OBoundControlModel::disposing;
113cdf0e10cSrcweir     using OBoundControlModel::getFastPropertyValue;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir protected:
116cdf0e10cSrcweir     // OBoundControlModel overridables
117cdf0e10cSrcweir 	virtual void            onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
118cdf0e10cSrcweir 	virtual void            onDisconnectedDbColumn();
119cdf0e10cSrcweir     virtual ::com::sun::star::uno::Any
120cdf0e10cSrcweir                             translateDbColumnToControlValue( );
121cdf0e10cSrcweir     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     virtual ::com::sun::star::uno::Any
124cdf0e10cSrcweir                             getControlValue( ) const;
125cdf0e10cSrcweir     virtual void            doSetControlValue( const ::com::sun::star::uno::Any& _rValue );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     virtual sal_Bool		approveDbColumnType(sal_Int32 _nColumnType);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	virtual void            resetNoBroadcast();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir protected:
132cdf0e10cSrcweir 	DECLARE_XCLONEABLE();
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	void implConstruct();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     /** displays the image described by the given URL
137cdf0e10cSrcweir         @precond
138cdf0e10cSrcweir             our own mutex is locked
139cdf0e10cSrcweir     */
140cdf0e10cSrcweir     sal_Bool    impl_handleNewImageURL_lck( ValueChangeInstigator _eInstigator );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     /** updates the binary stream, created from loading the file which the given URL points to, into our
143cdf0e10cSrcweir         bound field, or the control itself if there is no bound field
144cdf0e10cSrcweir     */
145cdf0e10cSrcweir     sal_Bool    impl_updateStreamForURL_lck( const ::rtl::OUString& _rURL, ValueChangeInstigator _eInstigator );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     DECL_LINK( OnImageImportDone, ::Graphic* );
148cdf0e10cSrcweir };
149cdf0e10cSrcweir 
150cdf0e10cSrcweir //==================================================================
151cdf0e10cSrcweir //= OImageControlControl
152cdf0e10cSrcweir //==================================================================
153cdf0e10cSrcweir typedef ::cppu::ImplHelper2 <   ::com::sun::star::awt::XMouseListener
154cdf0e10cSrcweir                             ,   ::com::sun::star::util::XModifyBroadcaster
155cdf0e10cSrcweir                             >   OImageControlControl_Base;
156cdf0e10cSrcweir class OImageControlControl  : public OBoundControl
157cdf0e10cSrcweir                             , public OImageControlControl_Base
158cdf0e10cSrcweir {
159cdf0e10cSrcweir private:
160cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper   m_aModifyListeners;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     // XTypeProvider
163cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
164cdf0e10cSrcweir 
165cdf0e10cSrcweir public:
166cdf0e10cSrcweir 	OImageControlControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     // UNO
169cdf0e10cSrcweir 	DECLARE_UNO3_AGG_DEFAULTS( OImageControlControl, OBoundControl );
170cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(::com::sun::star::uno::RuntimeException);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     // XEventListener
173cdf0e10cSrcweir 	virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException);
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     // XServiceInfo
176cdf0e10cSrcweir 	IMPLEMENTATION_NAME(OImageControlControl);
177cdf0e10cSrcweir 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     // XMouseListener
180cdf0e10cSrcweir 	virtual void SAL_CALL mousePressed(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
181cdf0e10cSrcweir 	virtual void SAL_CALL mouseReleased(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
182cdf0e10cSrcweir 	virtual void SAL_CALL mouseEntered(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
183cdf0e10cSrcweir 	virtual void SAL_CALL mouseExited(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     // XModifyBroadcaster
186cdf0e10cSrcweir     virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
187cdf0e10cSrcweir     virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     // OComponentHelper
190cdf0e10cSrcweir     virtual void SAL_CALL disposing();
191cdf0e10cSrcweir 
192cdf0e10cSrcweir private:
193cdf0e10cSrcweir 	void	implClearGraphics( sal_Bool _bForce );
194cdf0e10cSrcweir 	bool    implInsertGraphics();
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     /** determines whether the control does currently have an empty grahic set
197cdf0e10cSrcweir     */
198cdf0e10cSrcweir     bool    impl_isEmptyGraphics_nothrow() const;
199cdf0e10cSrcweir };
200cdf0e10cSrcweir 
201cdf0e10cSrcweir //.........................................................................
202cdf0e10cSrcweir }	// namespace frm
203cdf0e10cSrcweir //.........................................................................
204cdf0e10cSrcweir 
205cdf0e10cSrcweir #endif // _FRM_IMAGE_CONTROL_HXX_
206cdf0e10cSrcweir 
207