xref: /trunk/main/forms/source/component/ImageControl.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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);
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 
78     // UNO Anbindung
79     DECLARE_UNO3_AGG_DEFAULTS(OImageControlModel, OBoundControlModel);
80     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType);
81 
82     // XServiceInfo
83     IMPLEMENTATION_NAME(OImageControlModel);
84     virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
85 
86     // OComponentHelper
87     virtual void SAL_CALL disposing();
88 
89     // XPersistObject
90     virtual ::rtl::OUString SAL_CALL getServiceName();
91     virtual void SAL_CALL write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream);
92     virtual void SAL_CALL read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream);
93 
94     // XImageProducerSupplier
95     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> SAL_CALL getImageProducer();
96 
97     // XImageProducer
98     virtual void SAL_CALL addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer );
99     virtual void SAL_CALL removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer );
100     virtual void SAL_CALL startProduction(  );
101 
102     // OControlModel's property handling
103     virtual void describeAggregateProperties(
104         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
105     ) const;
106     virtual void describeFixedProperties(
107         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
108     ) const;
109 
110     // prevent method hiding
111     using OBoundControlModel::disposing;
112     using OBoundControlModel::getFastPropertyValue;
113 
114 protected:
115     // OBoundControlModel overridables
116     virtual void            onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
117     virtual void            onDisconnectedDbColumn();
118     virtual ::com::sun::star::uno::Any
119                             translateDbColumnToControlValue( );
120     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
121 
122     virtual ::com::sun::star::uno::Any
123                             getControlValue( ) const;
124     virtual void            doSetControlValue( const ::com::sun::star::uno::Any& _rValue );
125 
126     virtual sal_Bool        approveDbColumnType(sal_Int32 _nColumnType);
127 
128     virtual void            resetNoBroadcast();
129 
130 protected:
131     DECLARE_XCLONEABLE();
132 
133     void implConstruct();
134 
135     /** displays the image described by the given URL
136         @precond
137             our own mutex is locked
138     */
139     sal_Bool    impl_handleNewImageURL_lck( ValueChangeInstigator _eInstigator );
140 
141     /** updates the binary stream, created from loading the file which the given URL points to, into our
142         bound field, or the control itself if there is no bound field
143     */
144     sal_Bool    impl_updateStreamForURL_lck( const ::rtl::OUString& _rURL, ValueChangeInstigator _eInstigator );
145 
146     DECL_LINK( OnImageImportDone, ::Graphic* );
147 };
148 
149 //==================================================================
150 //= OImageControlControl
151 //==================================================================
152 typedef ::cppu::ImplHelper2 <   ::com::sun::star::awt::XMouseListener
153                             ,   ::com::sun::star::util::XModifyBroadcaster
154                             >   OImageControlControl_Base;
155 class OImageControlControl  : public OBoundControl
156                             , public OImageControlControl_Base
157 {
158 private:
159     ::cppu::OInterfaceContainerHelper   m_aModifyListeners;
160 
161     // XTypeProvider
162     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
163 
164 public:
165     OImageControlControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
166 
167     // UNO
168     DECLARE_UNO3_AGG_DEFAULTS( OImageControlControl, OBoundControl );
169     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType );
170 
171     // XEventListener
172     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource);
173 
174     // XServiceInfo
175     IMPLEMENTATION_NAME(OImageControlControl);
176     virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
177 
178     // XMouseListener
179     virtual void SAL_CALL mousePressed(const ::com::sun::star::awt::MouseEvent& e);
180     virtual void SAL_CALL mouseReleased(const ::com::sun::star::awt::MouseEvent& e);
181     virtual void SAL_CALL mouseEntered(const ::com::sun::star::awt::MouseEvent& e);
182     virtual void SAL_CALL mouseExited(const ::com::sun::star::awt::MouseEvent& e);
183 
184     // XModifyBroadcaster
185     virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener );
186     virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener );
187 
188     // OComponentHelper
189     virtual void SAL_CALL disposing();
190 
191 private:
192     void    implClearGraphics( sal_Bool _bForce );
193     bool    implInsertGraphics();
194 
195     /** determines whether the control does currently have an empty grahic set
196     */
197     bool    impl_isEmptyGraphics_nothrow() const;
198 };
199 
200 //.........................................................................
201 }   // namespace frm
202 //.........................................................................
203 
204 #endif // _FRM_IMAGE_CONTROL_HXX_
205