30#include <com/sun/star/awt/PopupMenu.hpp>
31#include <com/sun/star/awt/XPopupMenu.hpp>
32#include <com/sun/star/awt/PopupMenuDirection.hpp>
33#include <com/sun/star/beans/PropertyAttribute.hpp>
34#include <com/sun/star/form/FormComponentType.hpp>
35#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
36#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
37#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
38#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
39#include <com/sun/star/sdbc/DataType.hpp>
40#include <com/sun/star/awt/MouseButton.hpp>
41#include <com/sun/star/awt/XWindow.hpp>
42#include <com/sun/star/graphic/XGraphic.hpp>
43#include <com/sun/star/graphic/GraphicObject.hpp>
60#define ID_OPEN_GRAPHICS 1
61#define ID_CLEAR_GRAPHICS 2
94 ImageStoreType lcl_getImageStoreType(
const sal_Int32 _nFieldType )
97 if ( ( _nFieldType == DataType::BINARY )
98 || ( _nFieldType == DataType::VARBINARY )
99 || ( _nFieldType == DataType::LONGVARBINARY )
100 || ( _nFieldType == DataType::OTHER )
101 || ( _nFieldType == DataType::OBJECT )
102 || ( _nFieldType == DataType::BLOB )
103 || ( _nFieldType == DataType::LONGVARCHAR )
104 || ( _nFieldType == DataType::CLOB )
106 return ImageStoreBinary;
109 if ( ( _nFieldType == DataType::CHAR )
110 || ( _nFieldType == DataType::VARCHAR )
112 return ImageStoreLink;
114 return ImageStoreInvalid;
133 ,m_bExternalGraphic( true )
144 :OBoundControlModel( _pOriginal, _rxFactory )
146 ,m_bExternalGraphic( true )
148 ,m_sImageURL( _pOriginal->m_sImageURL )
149 ,m_xGraphicObject( _pOriginal->m_xGraphicObject )
156 ::osl::MutexGuard aGuard(
m_aMutex );
172 if (!OComponentHelper::rBHelper.bDisposed)
185 pClone->clonedFrom(
this);
194 aSupported.realloc(aSupported.getLength() + 2);
196 OUString*pArray = aSupported.getArray();
212 || !aReturn.hasValue()
222 return ImageStoreInvalid != lcl_getImageStoreType( _nColumnType );
250 DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN,
"OImageControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
267 Reference< XGraphic > xGraphic;
268 OSL_VERIFY( rValue >>= xGraphic );
269 if ( !xGraphic.is() )
320 sal_Int32 nOldCount = _rProps.getLength();
321 _rProps.realloc( nOldCount + 4);
322 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
324 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::TRANSIENT);
327 css::beans::PropertyAttribute::BOUND);
329 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(),
"<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
355 _rxOutStream->writeShort(0x0003);
369 sal_uInt16
nVersion = _rxInStream->readShort();
385 OSL_FAIL(
"OImageControlModel::read : unknown version !");
402 std::unique_ptr< SvStream > pImageStream;
403 Reference< XInputStream > xImageStream;
405 if ( ::svt::GraphicAccess::isSupportedURL( _rURL ) )
407 xImageStream = ::svt::GraphicAccess::getImageXStream(
getContext(), _rURL );
412 bool bSetNull = (pImageStream ==
nullptr) || (
ERRCODE_NONE != pImageStream->GetErrorCode());
417 sal_uInt64
const nSize = pImageStream->remainingSize();
418 if (pImageStream->GetBufferSize() < 8192)
419 pImageStream->SetBufferSize(8192);
422 xImageStream = new ::utl::OInputStreamHelper(
new SvLockBytes( pImageStream.get(),
false ), nSize );
426 if ( xImageStream.is() )
429 m_xColumnUpdate->updateBinaryStream( xImageStream, xImageStream->available() );
432 xImageStream->closeInput();
444 case ImageStoreBinary:
454 OSL_ENSURE(
m_xColumnUpdate.is(),
"OImageControlModel::impl_handleNewImageURL_lck: no bound field, but ImageStoreLink?!" );
463 case ImageStoreInvalid:
464 OSL_FAIL(
"OImageControlModel::impl_handleNewImageURL_lck: image storage type type!" );
498 bool lcl_isValidDocumentURL( std::u16string_view _rDocURL )
500 return ( !_rDocURL.empty() && _rDocURL != u
"private:object" );
511 Reference< XModel > xDocument(
getXModel( *
this ) );
512 if ( xDocument.is() )
517 Reference< XChild > xAsChild( xDocument, UNO_QUERY );
518 while ( xAsChild.is() && !lcl_isValidDocumentURL(
m_sDocumentURL ) )
520 xDocument.set( xAsChild->getParent(), UNO_QUERY );
521 if ( xDocument.is() )
523 xAsChild.set( xDocument, UNO_QUERY );
547 case ImageStoreBinary:
549 Reference< XInputStream > xImageStream(
m_xColumn->getBinaryStream() );
551 xImageStream.clear();
552 return Any( xImageStream );
556 OUString sImageLink(
m_xColumn->getString() );
559 return Any( sImageLink );
561 case ImageStoreInvalid:
562 OSL_FAIL(
"OImageControlModel::translateDbColumnToControlValue: invalid field type!" );
581 bool bStartProduction =
false;
584 case ImageStoreBinary:
587 Reference< XInputStream > xInStream;
588 _rValue >>= xInStream;
590 bStartProduction =
true;
597 _rValue >>= sImageURL;
599 bStartProduction =
true;
603 case ImageStoreInvalid:
604 OSL_FAIL(
"OImageControlModel::doSetControlValue: invalid field type!" );
609 if ( bStartProduction )
618 xProducer->startProduction();
656 const Reference< XGraphic > xGraphic(i_pGraphic !=
nullptr ? i_pGraphic->GetXGraphic() :
nullptr);
657 m_bExternalGraphic =
false;
666 m_bExternalGraphic =
true;
688 Reference< XWindow > xComp;
691 xComp->addMouseListener(
this );
700 if ( !aReturn.hasValue() )
701 aReturn = ::cppu::queryInterface(
703 static_cast< XMouseListener*
>(
this ),
704 static_cast< XModifyBroadcaster*
>(
this )
714 aSupported.realloc(aSupported.getLength() + 2);
716 OUString*pArray = aSupported.getArray();
737 EventObject
aEvent( *
this );
752 Reference< XPropertySet > xSet(
getModel(), UNO_QUERY );
758 OUString sOldImageURL;
761 if ( sOldImageURL.isEmpty() )
775 Reference< XPropertySet > xSet(
getModel(), UNO_QUERY );
783 Reference< XWindow > xWindow(
static_cast< ::
cppu::OWeakObject*
>(
this ), UNO_QUERY );
790 xController->setValue(ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, css::uno::Any(
true));
792 Reference<XPropertySet> xBoundField;
795 bool bHasField = xBoundField.is();
798 xController->enableControl(ExtendedFilePickerElementIds::CHECKBOX_LINK, !bHasField );
801 bool bImageIsLinked =
true;
804 sal_Int32 nFieldType = DataType::OTHER;
806 bImageIsLinked = ( lcl_getImageStoreType( nFieldType ) == ImageStoreLink );
808 xController->setValue(ExtendedFilePickerElementIds::CHECKBOX_LINK, 0,
Any( bImageIsLinked ) );
815 bool bIsLink =
false;
816 xController->getValue(ExtendedFilePickerElementIds::CHECKBOX_LINK, 0) >>= bIsLink;
821 bIsLink |= bHasField;
836 TOOLS_WARN_EXCEPTION(
"forms.component",
"OImageControlControl::implInsertGraphics: caught an exception while attempting to execute the FilePicker!");
844 bool bIsEmpty =
true;
849 Reference< XGraphic > xGraphic;
850 OSL_VERIFY( xModelProps->getPropertyValue(
"Graphic") >>= xGraphic );
851 bIsEmpty = !xGraphic.is();
867 if (e.Buttons != MouseButton::LEFT)
870 bool bModified =
false;
872 if ( e.PopupTrigger )
874 Reference< XPopupMenu > xMenu( awt::PopupMenu::create(
m_xContext ) );
875 DBG_ASSERT( xMenu.is(),
"OImageControlControl::mousePressed: could not create a popup menu!" );
877 Reference< XWindowPeer > xWindowPeer =
getPeer();
878 DBG_ASSERT( xWindowPeer.is(),
"OImageControlControl::mousePressed: no window!" );
880 if ( xMenu.is() && xWindowPeer.is() )
889 awt::Rectangle aRect( e.X, e.Y, 0, 0 );
890 if ( ( e.X < 0 ) || ( e.Y < 0 ) )
893 Reference< XWindow > xWindow(
static_cast< ::
cppu::OWeakObject*
>(
this ), UNO_QUERY );
894 OSL_ENSURE( xWindow.is(),
"OImageControlControl::mousePressed: me not a window? How this?" );
897 awt::Rectangle aPosSize = xWindow->getPosSize();
898 aRect.X = aPosSize.Width / 2;
899 aRect.Y = aPosSize.Height / 2;
903 const sal_Int16 nResult = xMenu->execute( xWindowPeer, aRect, PopupMenuDirection::EXECUTE_DEFAULT );
923 if (e.ClickCount == 2)
926 Reference<XPropertySet> xSet(
getModel(), UNO_QUERY);
931 Reference<XPropertySet> xBoundField;
935 css::uno::UNO_QUERY);
936 if (!xBoundField.is())
956 EventObject
aEvent( *
this );
978extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
980 css::uno::Sequence<css::uno::Any>
const &)
985extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
987 css::uno::Sequence<css::uno::Any>
const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OImageControlModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OImageControlControl_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
#define ID_CLEAR_GRAPHICS
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
static OUString GetAbsURL(std::u16string_view rTheBaseURIRef, OUString const &rTheRelURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void SAL_CALL removeConsumer(const css::uno::Reference< css::awt::XImageConsumer > &rxConsumer) override
void SAL_CALL startProduction() override
void SAL_CALL addConsumer(const css::uno::Reference< css::awt::XImageConsumer > &rxConsumer) override
void SetImage(const OUString &rPath)
void setImage(css::uno::Reference< css::io::XInputStream > const &rStmRef)
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual void SAL_CALL dispose() SAL_OVERRIDE
oslInterlockedCount m_refCount
class whose instances lock an OControlModel
void writeCommonProperties(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream)
We can't write (new) common properties in this base class, as the file format doesn't allow this (unf...
void defaultCommonProperties()
sal_Int32 getFieldType() const
virtual void onConnectedDbColumn(const css::uno::Reference< css::uno::XInterface > &_rxForm)
called whenever a connection to a database column has been established
void onValuePropertyChange(ControlModelLock &i_rControLock)
(to be) called when the value property changed
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void setControlValue(const css::uno::Any &_rValue, ValueChangeInstigator _eInstigator)
sets the given value as new current value for the control
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
css::uno::Reference< css::sdb::XColumn > m_xColumn
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
virtual void resetNoBroadcast()
called to reset the control to some kind of default.
const OUString & getControlSource() const
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
virtual void SAL_CALL write(const css::uno::Reference< css::io::XObjectOutputStream > &OutStream) override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &_rConvertedValue, css::uno::Any &_rOldValue, sal_Int32 _nHandle, const css::uno::Any &_rValue) override
virtual void SAL_CALL read(const css::uno::Reference< css::io::XObjectInputStream > &InStream) override
void readCommonProperties(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream)
css::uno::Reference< css::sdb::XColumnUpdate > m_xColumnUpdate
virtual void onDisconnectedDbColumn()
called whenever a connection to a database column has been suspended
void initOwnValueProperty(const OUString &i_rValuePropertyName)
initializes the part of the class which is related to the control value.
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual void SAL_CALL disposing() override
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
virtual void describeAggregateProperties(css::uno::Sequence< css::beans::Property > &_rAggregateProps) const
describes the properties of our aggregate
void writeHelpTextCompatibly(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream)
void readHelpTextCompatibly(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream)
css::uno::Reference< css::uno::XAggregation > m_xAggregate
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getPeer() override
virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
OImageControlControl(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
void implClearGraphics(bool _bForce)
::comphelper::OInterfaceContainerHelper3< css::util::XModifyListener > m_aModifyListeners
virtual void SAL_CALL disposing() override
virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent &e) override
bool impl_isEmptyGraphics_nothrow() const
determines whether the control does currently have an empty graphic set
bool implInsertGraphics()
virtual void SAL_CALL mouseExited(const css::awt::MouseEvent &e) override
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL mousePressed(const css::awt::MouseEvent &e) override
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent &e) override
bool impl_updateStreamForURL_lck(const OUString &_rURL, ValueChangeInstigator _eInstigator)
updates the binary stream, created from loading the file which the given URL points to,...
virtual OUString SAL_CALL getServiceName() override
virtual css::uno::Any translateDbColumnToControlValue() override
translates a db column value into a control value.
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
ImageProducer * GetImageProducer()
virtual void SAL_CALL addConsumer(const css::uno::Reference< css::awt::XImageConsumer > &xConsumer) override
virtual ~OImageControlModel() override
virtual void SAL_CALL write(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream) override
virtual void resetNoBroadcast() override
called to reset the control to some kind of default.
virtual css::uno::Any getControlValue() const override
retrieves the current value of the control
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
virtual void doSetControlValue(const css::uno::Any &_rValue) override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
rtl::Reference< ImageProducer > m_xImageProducer
virtual void onDisconnectedDbColumn() override
called whenever a connection to a database column has been suspended
virtual bool commitControlValueToDbColumn(bool _bPostReset) override
commits the current control value to the database column we're bound to @precond we're properly bound...
virtual void describeAggregateProperties(css::uno::Sequence< css::beans::Property > &_rAggregateProps) const override
describes the properties of our aggregate
virtual bool approveDbColumnType(sal_Int32 _nColumnType) override
nFieldType is the type of the field, on which the model will be linked.
virtual void onConnectedDbColumn(const css::uno::Reference< css::uno::XInterface > &_rxForm) override
called whenever a connection to a database column has been established
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
void impl_handleNewImageURL_lck(ValueChangeInstigator _eInstigator)
displays the image described by the given URL @precond our own mutex is locked
virtual css::uno::Reference< css::awt::XImageProducer > SAL_CALL getImageProducer() override
virtual void SAL_CALL removeConsumer(const css::uno::Reference< css::awt::XImageConsumer > &xConsumer) override
virtual void SAL_CALL startProduction() override
OImageControlModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
css::uno::Reference< css::graphic::XGraphicObject > m_xGraphicObject
virtual void SAL_CALL read(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream) override
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
void SetTitle(const OUString &rNewTitle)
void SetContext(Context _eNewContext)
ErrCode GetGraphic(Graphic &rGraphic) const
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
constexpr OUStringLiteral PROPERTY_TABINDEX
constexpr OUStringLiteral PROPERTY_BOUNDFIELD
constexpr OUStringLiteral PROPERTY_CONTROLSOURCE
constexpr OUStringLiteral PROPERTY_READONLY
constexpr OUStringLiteral PROPERTY_IMAGE_URL
constexpr OUStringLiteral PROPERTY_FIELDTYPE
constexpr OUStringLiteral PROPERTY_GRAPHIC
#define LINK(Instance, Class, Member)
SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative(OUString const &baseUriReference, OUString const &uriReference)
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
bool getBOOL(const Any &_rAny)
bool query_aggregation(const css::uno::Reference< css::uno::XAggregation > &_rxAggregate, css::uno::Reference< iface > &_rxOut)
bool tryPropertyValue(Any &_rConvertedValue, Any &_rOldValue, const Any &_rValueToSet, const Any &_rCurrentValue, const Type &_rExpectedType)
void RemoveProperty(Sequence< Property > &_rProps, const OUString &_rPropName)
OUString loadString(TranslateId aResId)
loads the string with the specified resource id from the FormLayer mo file
ListBox is a bit confusing / different from other form components, so here are a few notes:
IMPL_LINK(OClickableImageBaseModel, OnImageImportDone, Graphic *, i_pGraphic, void)
css::uno::Reference< css::frame::XModel > getXModel(const css::uno::Reference< css::uno::XInterface > &_rxComponent)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
#define PROPERTY_ID_READONLY
#define PROPERTY_ID_GRAPHIC
#define PROPERTY_ID_IMAGE_URL
#define PROPERTY_ID_TABINDEX
constexpr OUStringLiteral FRM_COMPONENT_IMAGECONTROL
constexpr OUStringLiteral FRM_SUN_COMPONENT_IMAGECONTROL
constexpr OUStringLiteral VCL_CONTROL_IMAGECONTROL
constexpr OUStringLiteral VCL_CONTROLMODEL_IMAGECONTROL
constexpr OUStringLiteral FRM_SUN_CONTROL_IMAGECONTROL
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_IMAGECONTROL
#define STREAM_SEEK_TO_BEGIN
Reference< XController > xController