1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <FormComponent.hxx>
23 #include "imgprod.hxx"
24 #include <com/sun/star/form/XImageProducerSupplier.hpp>
25 #include <com/sun/star/awt/XMouseListener.hpp>
26 #include <com/sun/star/util/XModifyBroadcaster.hpp>
27 #include <com/sun/star/graphic/XGraphicObject.hpp>
28 #include <comphelper/interfacecontainer3.hxx>
29 #include <cppuhelper/implbase2.hxx>
30 #include <rtl/ref.hxx>
39 typedef ::cppu::ImplHelper2
< css::form::XImageProducerSupplier
40 , css::awt::XImageProducer
41 > OImageControlModel_Base
;
43 class OImageControlModel final
44 :public OImageControlModel_Base
45 ,public OBoundControlModel
47 rtl::Reference
<ImageProducer
> m_xImageProducer
;
48 bool m_bExternalGraphic
;
51 css::uno::Reference
< css::graphic::XGraphicObject
>
53 OUString m_sDocumentURL
;
56 virtual css::uno::Sequence
< css::uno::Type
> _getTypes() override
;
58 ImageProducer
* GetImageProducer() { return m_xImageProducer
.get(); }
62 const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
65 const OImageControlModel
* _pOriginal
,
66 const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
68 virtual ~OImageControlModel() override
;
70 virtual void SAL_CALL
getFastPropertyValue(css::uno::Any
& rValue
, sal_Int32 nHandle
) const override
;
71 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
73 virtual sal_Bool SAL_CALL
convertFastPropertyValue(css::uno::Any
& rConvertedValue
, css::uno::Any
& rOldValue
, sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
76 DECLARE_UNO3_AGG_DEFAULTS(OImageControlModel
, OBoundControlModel
)
77 virtual css::uno::Any SAL_CALL
queryAggregation(const css::uno::Type
& _rType
) override
;
80 OUString SAL_CALL
getImplementationName() override
81 { return "com.sun.star.form.OImageControlModel"; }
83 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
86 virtual OUString SAL_CALL
getServiceName() override
;
87 virtual void SAL_CALL
write(const css::uno::Reference
< css::io::XObjectOutputStream
>& _rxOutStream
) override
;
88 virtual void SAL_CALL
read(const css::uno::Reference
< css::io::XObjectInputStream
>& _rxInStream
) override
;
90 // XImageProducerSupplier
91 virtual css::uno::Reference
< css::awt::XImageProducer
> SAL_CALL
getImageProducer() override
;
94 virtual void SAL_CALL
addConsumer( const css::uno::Reference
< css::awt::XImageConsumer
>& xConsumer
) override
;
95 virtual void SAL_CALL
removeConsumer( const css::uno::Reference
< css::awt::XImageConsumer
>& xConsumer
) override
;
96 virtual void SAL_CALL
startProduction( ) override
;
98 // OControlModel's property handling
99 virtual void describeAggregateProperties(
100 css::uno::Sequence
< css::beans::Property
>& /* [out] */ _rAggregateProps
102 virtual void describeFixedProperties(
103 css::uno::Sequence
< css::beans::Property
>& /* [out] */ _rProps
106 // prevent method hiding
107 using OBoundControlModel::disposing
;
108 using OBoundControlModel::getFastPropertyValue
;
111 // OBoundControlModel overridables
112 virtual void onConnectedDbColumn( const css::uno::Reference
< css::uno::XInterface
>& _rxForm
) override
;
113 virtual void onDisconnectedDbColumn() override
;
114 virtual css::uno::Any
translateDbColumnToControlValue( ) override
;
115 virtual bool commitControlValueToDbColumn( bool _bPostReset
) override
;
117 virtual css::uno::Any
getControlValue( ) const override
;
118 virtual void doSetControlValue( const css::uno::Any
& _rValue
) override
;
120 virtual bool approveDbColumnType(sal_Int32 _nColumnType
) override
;
122 virtual void resetNoBroadcast() override
;
124 virtual css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone( ) override
;
126 void implConstruct();
128 /** displays the image described by the given URL
130 our own mutex is locked
132 void impl_handleNewImageURL_lck( ValueChangeInstigator _eInstigator
);
134 /** updates the binary stream, created from loading the file which the given URL points to, into our
135 bound field, or the control itself if there is no bound field
137 bool impl_updateStreamForURL_lck( const OUString
& _rURL
, ValueChangeInstigator _eInstigator
);
139 DECL_LINK( OnImageImportDone
, ::Graphic
*, void );
142 typedef ::cppu::ImplHelper2
< css::awt::XMouseListener
143 , css::util::XModifyBroadcaster
144 > OImageControlControl_Base
;
145 class OImageControlControl
: public OBoundControl
146 , public OImageControlControl_Base
149 ::comphelper::OInterfaceContainerHelper3
<css::util::XModifyListener
> m_aModifyListeners
;
152 virtual css::uno::Sequence
< css::uno::Type
> _getTypes() override
;
155 explicit OImageControlControl(const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
);
158 DECLARE_UNO3_AGG_DEFAULTS( OImageControlControl
, OBoundControl
)
159 virtual css::uno::Any SAL_CALL
queryAggregation( const css::uno::Type
& _rType
) override
;
162 virtual void SAL_CALL
disposing(const css::lang::EventObject
& _rSource
) override
;
165 OUString SAL_CALL
getImplementationName() override
166 { return "com.sun.star.form.OImageControlControl"; }
168 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
171 virtual void SAL_CALL
mousePressed(const css::awt::MouseEvent
& e
) override
;
172 virtual void SAL_CALL
mouseReleased(const css::awt::MouseEvent
& e
) override
;
173 virtual void SAL_CALL
mouseEntered(const css::awt::MouseEvent
& e
) override
;
174 virtual void SAL_CALL
mouseExited(const css::awt::MouseEvent
& e
) override
;
176 // XModifyBroadcaster
177 virtual void SAL_CALL
addModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
178 virtual void SAL_CALL
removeModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
181 virtual void SAL_CALL
disposing() override
;
184 void implClearGraphics( bool _bForce
);
185 bool implInsertGraphics();
187 /** determines whether the control does currently have an empty graphic set
189 bool impl_isEmptyGraphics_nothrow() const;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */