xref: /trunk/main/forms/source/component/ImageControl.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 _FRM_IMAGE_CONTROL_HXX_
29 #define _FRM_IMAGE_CONTROL_HXX_
30 
31 #include "FormComponent.hxx"
32 #include "imgprod.hxx"
33 #include <com/sun/star/form/XImageProducerSupplier.hpp>
34 #include <com/sun/star/awt/XMouseListener.hpp>
35 #include <com/sun/star/util/XModifyBroadcaster.hpp>
36 #include <com/sun/star/graphic/XGraphicObject.hpp>
37 #include <comphelper/propmultiplex.hxx>
38 #include <comphelper/implementationreference.hxx>
39 #include <cppuhelper/implbase2.hxx>
40 
41 using namespace comphelper;
42 
43 //.........................................................................
44 namespace frm
45 {
46 //.........................................................................
47 
48 //==================================================================
49 // OImageControlModel
50 //==================================================================
51 typedef ::cppu::ImplHelper2 <   ::com::sun::star::form::XImageProducerSupplier
52                             ,   ::com::sun::star::awt::XImageProducer
53                             >   OImageControlModel_Base;
54 
55 class OImageControlModel
56                 :public OImageControlModel_Base
57                 ,public OBoundControlModel
58 {
59     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer>    m_xImageProducer;
60     ImageProducer*                                  m_pImageProducer;
61     bool                                            m_bExternalGraphic;
62     sal_Bool                                        m_bReadOnly;
63     ::rtl::OUString                                 m_sImageURL;
64     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicObject >
65                                                     m_xGraphicObject;
66     ::rtl::OUString                                 m_sDocumentURL;
67 
68 protected:
69     // UNO Anbindung
70     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
71 
72     inline ImageProducer* GetImageProducer() { return m_pImageProducer; }
73 
74 public:
75     DECLARE_DEFAULT_LEAF_XTOR( OImageControlModel );
76 
77     virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
78     virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue) throw ( ::com::sun::star::uno::Exception);
79 
80     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         throw(::com::sun::star::lang::IllegalArgumentException);
82 
83     // UNO Anbindung
84     DECLARE_UNO3_AGG_DEFAULTS(OImageControlModel, OBoundControlModel);
85     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
86 
87     // XServiceInfo
88     IMPLEMENTATION_NAME(OImageControlModel);
89     virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
90 
91     // OComponentHelper
92     virtual void SAL_CALL disposing();
93 
94     // XPersistObject
95     virtual ::rtl::OUString SAL_CALL getServiceName() throw ( ::com::sun::star::uno::RuntimeException);
96     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     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 
99     // XImageProducerSupplier
100     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> SAL_CALL getImageProducer() throw ( ::com::sun::star::uno::RuntimeException);
101 
102     // XImageProducer
103     virtual void SAL_CALL addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException);
104     virtual void SAL_CALL removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException);
105     virtual void SAL_CALL startProduction(  ) throw (::com::sun::star::uno::RuntimeException);
106 
107     // OControlModel's property handling
108     virtual void describeAggregateProperties(
109         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
110     ) const;
111     virtual void describeFixedProperties(
112         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
113     ) const;
114 
115     // prevent method hiding
116     using OBoundControlModel::disposing;
117     using OBoundControlModel::getFastPropertyValue;
118 
119 protected:
120     // OBoundControlModel overridables
121     virtual void            onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
122     virtual void            onDisconnectedDbColumn();
123     virtual ::com::sun::star::uno::Any
124                             translateDbColumnToControlValue( );
125     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
126 
127     virtual ::com::sun::star::uno::Any
128                             getControlValue( ) const;
129     virtual void            doSetControlValue( const ::com::sun::star::uno::Any& _rValue );
130 
131     virtual sal_Bool        approveDbColumnType(sal_Int32 _nColumnType);
132 
133     virtual void            resetNoBroadcast();
134 
135 protected:
136     DECLARE_XCLONEABLE();
137 
138     void implConstruct();
139 
140     /** displays the image described by the given URL
141         @precond
142             our own mutex is locked
143     */
144     sal_Bool    impl_handleNewImageURL_lck( ValueChangeInstigator _eInstigator );
145 
146     /** updates the binary stream, created from loading the file which the given URL points to, into our
147         bound field, or the control itself if there is no bound field
148     */
149     sal_Bool    impl_updateStreamForURL_lck( const ::rtl::OUString& _rURL, ValueChangeInstigator _eInstigator );
150 
151     DECL_LINK( OnImageImportDone, ::Graphic* );
152 };
153 
154 //==================================================================
155 //= OImageControlControl
156 //==================================================================
157 typedef ::cppu::ImplHelper2 <   ::com::sun::star::awt::XMouseListener
158                             ,   ::com::sun::star::util::XModifyBroadcaster
159                             >   OImageControlControl_Base;
160 class OImageControlControl  : public OBoundControl
161                             , public OImageControlControl_Base
162 {
163 private:
164     ::cppu::OInterfaceContainerHelper   m_aModifyListeners;
165 
166     // XTypeProvider
167     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
168 
169 public:
170     OImageControlControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
171 
172     // UNO
173     DECLARE_UNO3_AGG_DEFAULTS( OImageControlControl, OBoundControl );
174     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(::com::sun::star::uno::RuntimeException);
175 
176     // XEventListener
177     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException);
178 
179     // XServiceInfo
180     IMPLEMENTATION_NAME(OImageControlControl);
181     virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
182 
183     // XMouseListener
184     virtual void SAL_CALL mousePressed(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
185     virtual void SAL_CALL mouseReleased(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
186     virtual void SAL_CALL mouseEntered(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
187     virtual void SAL_CALL mouseExited(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException);
188 
189     // XModifyBroadcaster
190     virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
191     virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
192 
193     // OComponentHelper
194     virtual void SAL_CALL disposing();
195 
196 private:
197     void    implClearGraphics( sal_Bool _bForce );
198     bool    implInsertGraphics();
199 
200     /** determines whether the control does currently have an empty grahic set
201     */
202     bool    impl_isEmptyGraphics_nothrow() const;
203 };
204 
205 //.........................................................................
206 }   // namespace frm
207 //.........................................................................
208 
209 #endif // _FRM_IMAGE_CONTROL_HXX_
210 
211