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