diff options
Diffstat (limited to 'UnoControls/source/controls')
-rw-r--r-- | UnoControls/source/controls/OConnectionPointContainerHelper.cxx | 141 | ||||
-rw-r--r-- | UnoControls/source/controls/OConnectionPointHelper.cxx | 228 | ||||
-rw-r--r-- | UnoControls/source/controls/framecontrol.cxx | 462 | ||||
-rw-r--r-- | UnoControls/source/controls/progressbar.cxx | 400 | ||||
-rw-r--r-- | UnoControls/source/controls/progressmonitor.cxx | 854 | ||||
-rw-r--r-- | UnoControls/source/controls/statusindicator.cxx | 455 |
6 files changed, 2540 insertions, 0 deletions
diff --git a/UnoControls/source/controls/OConnectionPointContainerHelper.cxx b/UnoControls/source/controls/OConnectionPointContainerHelper.cxx new file mode 100644 index 000000000..bf687a0df --- /dev/null +++ b/UnoControls/source/controls/OConnectionPointContainerHelper.cxx @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <OConnectionPointContainerHelper.hxx> + +#include <OConnectionPointHelper.hxx> + +#include <cppuhelper/queryinterface.hxx> +#include <comphelper/sequence.hxx> + +// namespaces + +using namespace ::osl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + +namespace unocontrols { + +// construct/destruct + +OConnectionPointContainerHelper::OConnectionPointContainerHelper( Mutex& aMutex ) + : m_aSharedMutex ( aMutex ) + , m_aMultiTypeContainer ( aMutex ) +{ +} + +OConnectionPointContainerHelper::~OConnectionPointContainerHelper() +{ +} + +// XInterface + +Any SAL_CALL OConnectionPointContainerHelper::queryInterface( const Type& aType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Ask for my own supported interfaces ... + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XConnectionPointContainer* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = OWeakObject::queryInterface( aType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL OConnectionPointContainerHelper::acquire() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::acquire(); +} + +// XInterface + +void SAL_CALL OConnectionPointContainerHelper::release() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::release(); +} + +// XConnectionPointContainer + +Sequence< Type > SAL_CALL OConnectionPointContainerHelper::getConnectionPointTypes() +{ + // Container is threadsafe himself ! + return comphelper::containerToSequence(m_aMultiTypeContainer.getContainedTypes()); +} + +// XConnectionPointContainer + +Reference< XConnectionPoint > SAL_CALL OConnectionPointContainerHelper::queryConnectionPoint( const Type& aType ) +{ + // Set default return value, if method failed. + Reference< XConnectionPoint > xConnectionPoint; + + // Get all elements of the container, which have the searched type. + comphelper::OInterfaceContainerHelper2* pSpecialContainer = m_aMultiTypeContainer.getContainer( aType ); + if ( pSpecialContainer && pSpecialContainer->getLength() > 0 ) + { + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + // If this container contains elements, build a connectionpoint-instance. + xConnectionPoint = new OConnectionPointHelper( m_aSharedMutex, this, aType ); + } + + return xConnectionPoint; +} + +// XConnectionPointContainer + +void SAL_CALL OConnectionPointContainerHelper::advise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + // Container is threadsafe himself ! + m_aMultiTypeContainer.addInterface( aType, xListener ); +} + +// XConnectionPointContainer + +void SAL_CALL OConnectionPointContainerHelper::unadvise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + // Container is threadsafe himself ! + m_aMultiTypeContainer.removeInterface( aType, xListener ); +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/OConnectionPointHelper.cxx b/UnoControls/source/controls/OConnectionPointHelper.cxx new file mode 100644 index 000000000..b6ddaaa51 --- /dev/null +++ b/UnoControls/source/controls/OConnectionPointHelper.cxx @@ -0,0 +1,228 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <OConnectionPointHelper.hxx> + +#include <OConnectionPointContainerHelper.hxx> + +#include <com/sun/star/lang/InvalidListenerException.hpp> +#include <cppuhelper/queryinterface.hxx> +#include <comphelper/sequence.hxx> + +// namespaces + +using namespace ::osl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + +namespace unocontrols { + +// construct/destruct + +OConnectionPointHelper::OConnectionPointHelper( + Mutex& aMutex , + OConnectionPointContainerHelper* pContainerImplementation , + Type const & aType +) : m_aSharedMutex ( aMutex ) + , m_oContainerWeakReference ( pContainerImplementation ) + , m_pContainerImplementation ( pContainerImplementation ) + , m_aInterfaceType ( aType ) +{ +} + +OConnectionPointHelper::~OConnectionPointHelper() +{ +} + +// XInterface + +Any SAL_CALL OConnectionPointHelper::queryInterface( const Type& aType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Ask for my own supported interfaces ... + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XConnectionPoint* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = OWeakObject::queryInterface( aType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL OConnectionPointHelper::acquire() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::acquire(); +} + +// XInterface + +void SAL_CALL OConnectionPointHelper::release() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::release(); +} + +// XConnectionPoint + +Type SAL_CALL OConnectionPointHelper::getConnectionType() +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + + // Set default return value, if method failed. + if ( !impl_LockContainer() ) + { + throw RuntimeException("Container does not exist!"); + } + + // If container reference valid, return right type of supported interfaces of THIS connectionpoint. + Type aReturnType = m_aInterfaceType; + // Don't forget this! + impl_UnlockContainer(); + + return aReturnType; +} + +// XConnectionPoint + +Reference< XConnectionPointContainer > SAL_CALL OConnectionPointHelper::getConnectionPointContainer() +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + // Convert weakreference to correct uno3-reference and return value. It can be NULL, if container destroyed! + return Reference< XConnectionPointContainer >( m_oContainerWeakReference.get(), UNO_QUERY ); +} + +// XConnectionPoint + +void SAL_CALL OConnectionPointHelper::advise( const Reference< XInterface >& xListener ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + + // If type of listener not the same for this special container ... + Any aCheckType = xListener->queryInterface( m_aInterfaceType ); + if ( aCheckType.hasValue() ) + { + // ... throw an exception. + throw InvalidListenerException(); + } + + // ListenerExistException is obsolete!? + // It's the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!? + // You can add a listener more than one time at XConnectionPointContainer, but here only one ... + + // Operation is permitted only, if reference to container is valid! + if ( !impl_LockContainer() ) + { + throw RuntimeException("Container does not exist!"); + } + // Forward it to OConnectionPointHelperContainer! + m_pContainerImplementation->advise( m_aInterfaceType, xListener ); + // Don't forget this! + impl_UnlockContainer(); +} + +// XConnectionPoint + +void SAL_CALL OConnectionPointHelper::unadvise( const Reference< XInterface >& xListener ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + // Operation is permitted only, if reference to container is valid! + if ( !impl_LockContainer() ) + { + throw RuntimeException("Container does not exist!"); + + } + // Forward it to OConnectionPointHelperContainer! + m_pContainerImplementation->unadvise( m_aInterfaceType, xListener ); + // Don't forget this! + impl_UnlockContainer(); +} + +// XConnectionPoint + +Sequence< Reference< XInterface > > SAL_CALL OConnectionPointHelper::getConnections() +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + // Operation is permitted only, if reference to container is valid! + if ( !impl_LockContainer() ) + { + throw RuntimeException("Container does not exist!"); + } + // Set default return value, if method failed. + Sequence< Reference< XInterface > > seqReturnConnections; + // Get reference to private member of OConnectionPointHelperContainer! + comphelper::OMultiTypeInterfaceContainerHelper2& aSharedContainer = m_pContainerImplementation->impl_getMultiTypeContainer(); + // Get pointer to specialized container which hold all interfaces of searched type. + comphelper::OInterfaceContainerHelper2* pSpecialContainer = aSharedContainer.getContainer( m_aInterfaceType ); + // Get elements of searched type, if some else exist. + if ( pSpecialContainer != nullptr ) + { + seqReturnConnections = comphelper::containerToSequence(pSpecialContainer->getElements()); + } + // Don't forget this! + impl_UnlockContainer(); + + return seqReturnConnections; +} + +// private method + +bool OConnectionPointHelper::impl_LockContainer() +{ + // Convert weakreference to hard uno3-reference and return state. + // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed. + // Don't forget to "unlock" this reference! + m_xLock = m_oContainerWeakReference.get(); + return m_xLock.is(); +} + +// private method + +void OConnectionPointHelper::impl_UnlockContainer() +{ + // Free hard uno3-reference to container. + // see also "impl_LockContainer()" + m_xLock.clear(); +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/framecontrol.cxx b/UnoControls/source/controls/framecontrol.cxx new file mode 100644 index 000000000..73decca46 --- /dev/null +++ b/UnoControls/source/controls/framecontrol.cxx @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <framecontrol.hxx> +#include <OConnectionPointContainerHelper.hxx> + +#include <com/sun/star/awt/XControlContainer.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/frame/Frame.hpp> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/frame/XDispatch.hpp> +#include <com/sun/star/util/URLTransformer.hpp> +#include <com/sun/star/util/XURLTransformer.hpp> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <osl/diagnose.h> + +// namespaces + +using namespace ::osl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::util; + +namespace unocontrols { + +namespace { + +enum PropertyHandle // values represent index in PropertyArray +{ // for FrameControl + Componenturl = 0, + Frame = 1, + Loaderarguments = 2 +}; + +} + +// construct/destruct + +FrameControl::FrameControl( const Reference< XComponentContext >& rxContext) + : BaseControl ( rxContext ) + , OBroadcastHelper ( m_aMutex ) + , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) ) + , m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex) ) +{ +} + +FrameControl::~FrameControl() +{ +} + +// XInterface + +Any SAL_CALL FrameControl::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + Reference< XInterface > xDel = BaseControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL FrameControl::acquire() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::acquire(); +} + +// XInterface + +void SAL_CALL FrameControl::release() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::release(); +} + +// XTypeProvider + +Sequence< Type > SAL_CALL FrameControl::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XControlModel>::get(), + cppu::UnoType<XControlContainer>::get(), + cppu::UnoType<XConnectionPointContainer>::get(), + BaseControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation + +Any SAL_CALL FrameControl::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XControlModel* > ( this ) , + static_cast< XConnectionPointContainer* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = OPropertySetHelper::queryInterface( aType ); + if ( !aReturn.hasValue() ) + { + aReturn = BaseControl::queryAggregation( aType ); + } + } + + return aReturn; +} + +OUString FrameControl::getImplementationName() +{ + return "stardiv.UnoControls.FrameControl"; +} + +css::uno::Sequence<OUString> FrameControl::getSupportedServiceNames() +{ + return { "com.sun.star.frame.FrameControl" }; +} + +// XControl + +void SAL_CALL FrameControl::createPeer( const Reference< XToolkit >& xToolkit , + const Reference< XWindowPeer >& xParentPeer ) +{ + BaseControl::createPeer( xToolkit, xParentPeer ); + if ( impl_getPeerWindow().is() ) + { + if( !m_sComponentURL.isEmpty() ) + { + impl_createFrame( getPeer(), m_sComponentURL, m_seqLoaderArguments ); + } + } +} + +// XControl + +sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ ) +{ + // We have no model. + return false; +} + +// XControl + +Reference< XControlModel > SAL_CALL FrameControl::getModel() +{ + // We have no model. + return Reference< XControlModel >(); +} + +// XControl + +void SAL_CALL FrameControl::dispose() +{ + impl_deleteFrame(); + BaseControl::dispose(); +} + +// XView + +sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ ) +{ + // it is not possible to print this control + return false; +} + +// XView + +Reference< XGraphics > SAL_CALL FrameControl::getGraphics() +{ + // when it's not possible to set graphics ! then it's possible to return null + return Reference< XGraphics >(); +} + +// XConnectionPointContainer + +Sequence< Type > SAL_CALL FrameControl::getConnectionPointTypes() +{ + // Forwarded to helper class + return m_aConnectionPointContainer->getConnectionPointTypes(); +} + +// XConnectionPointContainer + +Reference< XConnectionPoint > SAL_CALL FrameControl::queryConnectionPoint( const Type& aType ) +{ + // Forwarded to helper class + return m_aConnectionPointContainer->queryConnectionPoint( aType ); +} + +// XConnectionPointContainer + +void SAL_CALL FrameControl::advise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + // Forwarded to helper class + m_aConnectionPointContainer->advise( aType, xListener ); +} + +// XConnectionPointContainer + +void SAL_CALL FrameControl::unadvise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + // Forwarded to helper class + m_aConnectionPointContainer->unadvise( aType, xListener ); +} + +// OPropertySetHelper + +sal_Bool FrameControl::convertFastPropertyValue( Any& rConvertedValue , + Any& rOldValue , + sal_Int32 nHandle , + const Any& rValue ) +{ + bool bReturn = false; + switch (nHandle) + { + case PropertyHandle::Componenturl : rConvertedValue = rValue; + rOldValue <<= m_sComponentURL; + bReturn = true; + break; + + case PropertyHandle::Loaderarguments : rConvertedValue = rValue; + rOldValue <<= m_seqLoaderArguments; + bReturn = true; + break; + } + + if ( !bReturn ) + { + throw IllegalArgumentException("unknown handle " + OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this), 1); + } + + return bReturn; +} + +// OPropertySetHelper + +void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle , + const Any& rValue ) +{ + // this method only set the value + MutexGuard aGuard (m_aMutex); + switch (nHandle) + { + case PropertyHandle::Componenturl : rValue >>= m_sComponentURL; + if (getPeer().is()) + { + impl_createFrame ( getPeer(), m_sComponentURL, m_seqLoaderArguments ); + } + break; + + case PropertyHandle::Loaderarguments : rValue >>= m_seqLoaderArguments; + break; + + default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." ); + } +} + +// OPropertySetHelper + +void FrameControl::getFastPropertyValue( Any& rRet , + sal_Int32 nHandle ) const +{ + MutexGuard aGuard ( Mutex::getGlobalMutex() ); + + switch (nHandle) + { + case PropertyHandle::Componenturl : rRet <<= m_sComponentURL; + break; + + case PropertyHandle::Loaderarguments : rRet <<= m_seqLoaderArguments; + break; + + case PropertyHandle::Frame : rRet <<= m_xFrame; + break; + + default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." ); + } +} + +// OPropertySetHelper + +IPropertyArrayHelper& FrameControl::getInfoHelper() +{ + // Create a table that map names to index values. + // attention: properties need to be sorted by name! + static OPropertyArrayHelper ourPropertyInfo( + { + Property( "ComponentUrl", PropertyHandle::Componenturl, cppu::UnoType<OUString>::get(), + PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ), + Property( "Frame", PropertyHandle::Frame, cppu::UnoType<XFrame>::get(), + PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT ), + Property( "LoaderArguments", PropertyHandle::Loaderarguments, cppu::UnoType<Sequence<PropertyValue>>::get(), + PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ) + }, + true ); + + return ourPropertyInfo; +} + +// OPropertySetHelper + +Reference< XPropertySetInfo > SAL_CALL FrameControl::getPropertySetInfo() +{ + // Create structure of propertysetinfo for baseclass "OPropertySetHelper". + // (Use method "getInfoHelper()".) + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + + return xInfo; +} + +// BaseControl + +WindowDescriptor FrameControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer ) +{ + WindowDescriptor aDescriptor; + + aDescriptor.Type = WindowClass_CONTAINER; + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = xParentPeer; + aDescriptor.Bounds = getPosSize (); + aDescriptor.WindowAttributes = 0; + + return aDescriptor; +} + +// private method + +void FrameControl::impl_createFrame( const Reference< XWindowPeer >& xPeer , + const OUString& rURL , + const Sequence< PropertyValue >& rArguments ) +{ + Reference< XFrame2 > xOldFrame; + Reference< XFrame2 > xNewFrame; + + { + MutexGuard aGuard ( m_aMutex ); + xOldFrame = m_xFrame; + } + + xNewFrame = Frame::create( impl_getComponentContext() ); + + Reference< XWindow > xWP ( xPeer, UNO_QUERY ); + xNewFrame->initialize ( xWP ); + + // option + //xFrame->setName( "WhatYouWant" ); + + Reference< XURLTransformer > xTrans = URLTransformer::create( impl_getComponentContext() ); + // load file + URL aURL; + aURL.Complete = rURL; + xTrans->parseStrict( aURL ); + + Reference< XDispatch > xDisp = xNewFrame->queryDispatch ( aURL, OUString (), FrameSearchFlag::SELF ); + if (xDisp.is()) + { + xDisp->dispatch ( aURL, rArguments ); + } + + // set the frame + { + MutexGuard aGuard ( m_aMutex ); + m_xFrame = xNewFrame; + } + + // notify the listeners + sal_Int32 nFrameId = PropertyHandle::Frame; + Any aNewFrame ( &xNewFrame, cppu::UnoType<XFrame>::get()); + Any aOldFrame ( &xOldFrame, cppu::UnoType<XFrame>::get()); + + fire ( &nFrameId, &aNewFrame, &aOldFrame, 1, false ); + + if (xOldFrame.is()) + { + xOldFrame->dispose (); + } +} + +// private method + +void FrameControl::impl_deleteFrame() +{ + Reference< XFrame2 > xOldFrame; + Reference< XFrame2 > xNullFrame; + + { + // do not dispose the frame in this guarded section (deadlock?) + MutexGuard aGuard( m_aMutex ); + xOldFrame = m_xFrame; + m_xFrame.clear(); + } + + // notify the listeners + sal_Int32 nFrameId = PropertyHandle::Frame; + Any aNewFrame( &xNullFrame, cppu::UnoType<XFrame2>::get()); + Any aOldFrame( &xOldFrame, cppu::UnoType<XFrame2>::get()); + fire( &nFrameId, &aNewFrame, &aOldFrame, 1, false ); + + // dispose the frame + if( xOldFrame.is() ) + xOldFrame->dispose(); +} + + +} // namespace unocontrols + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +stardiv_UnoControls_FrameControl_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new unocontrols::FrameControl(context)); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/progressbar.cxx b/UnoControls/source/controls/progressbar.cxx new file mode 100644 index 000000000..fbb0b1342 --- /dev/null +++ b/UnoControls/source/controls/progressbar.cxx @@ -0,0 +1,400 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <progressbar.hxx> + +#include <com/sun/star/awt/XGraphics.hpp> +#include <tools/debug.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; + +namespace unocontrols { + +// construct/destruct + +ProgressBar::ProgressBar( const Reference< XComponentContext >& rxContext ) + : BaseControl ( rxContext ) + , m_bHorizontal ( PROGRESSBAR_DEFAULT_HORIZONTAL ) + , m_aBlockSize ( PROGRESSBAR_DEFAULT_BLOCKDIMENSION ) + , m_nForegroundColor ( PROGRESSBAR_DEFAULT_FOREGROUNDCOLOR ) + , m_nBackgroundColor ( PROGRESSBAR_DEFAULT_BACKGROUNDCOLOR ) + , m_nMinRange ( PROGRESSBAR_DEFAULT_MINRANGE ) + , m_nMaxRange ( PROGRESSBAR_DEFAULT_MAXRANGE ) + , m_nBlockValue ( PROGRESSBAR_DEFAULT_BLOCKVALUE ) + , m_nValue ( PROGRESSBAR_DEFAULT_VALUE ) +{ +} + +ProgressBar::~ProgressBar() +{ +} + +// XInterface + +Any SAL_CALL ProgressBar::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + Reference< XInterface > xDel = BaseControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL ProgressBar::acquire() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::acquire(); +} + +// XInterface + +void SAL_CALL ProgressBar::release() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::release(); +} + +// XTypeProvider + +Sequence< Type > SAL_CALL ProgressBar::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XControlModel>::get(), + cppu::UnoType<XProgressBar>::get(), + BaseControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation + +Any SAL_CALL ProgressBar::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XControlModel* > ( this ) , + static_cast< XProgressBar* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = BaseControl::queryAggregation( aType ); + } + + return aReturn; +} + +// XProgressBar + +void SAL_CALL ProgressBar::setForegroundColor( sal_Int32 nColor ) +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // Safe color for later use. + m_nForegroundColor = Color(ColorTransparency, nColor); + + // Repaint control + impl_paint ( 0, 0, impl_getGraphicsPeer() ); +} + +// XProgressBar + +void SAL_CALL ProgressBar::setBackgroundColor ( sal_Int32 nColor ) +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // Safe color for later use. + m_nBackgroundColor = Color(ColorTransparency, nColor); + + // Repaint control + impl_paint ( 0, 0, impl_getGraphicsPeer() ); +} + +// XProgressBar + +void SAL_CALL ProgressBar::setValue ( sal_Int32 nValue ) +{ + // This method is defined for follow things: + // 1) Values >= _nMinRange + // 2) Values <= _nMaxRange + + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // save impossible cases + // This method is only defined for valid values + DBG_ASSERT ( (( nValue >= m_nMinRange ) && ( nValue <= m_nMaxRange )), "ProgressBar::setValue()\nNot valid value.\n" ); + + // If new value not valid ... do nothing in release version! + if ( + ( nValue >= m_nMinRange ) && + ( nValue <= m_nMaxRange ) + ) + { + // New value is ok => save this + m_nValue = nValue; + + // Repaint to display changes + impl_paint ( 0, 0, impl_getGraphicsPeer() ); + } +} + +// XProgressBar + +void SAL_CALL ProgressBar::setRange ( sal_Int32 nMin, sal_Int32 nMax ) +{ + // This method is defined for follow things: + // 1) All values of sal_Int32 + // 2) Min < Max + // 3) Min > Max + + // save impossible cases + // This method is only defined for valid values + // If you ignore this, the release version will produce an error "division by zero" in "ProgressBar::setValue()"! + DBG_ASSERT ( ( nMin != nMax ) , "ProgressBar::setRange()\nValues for MIN and MAX are the same. This is not allowed!\n" ); + + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // control the values for min and max + if ( nMin < nMax ) + { + // Take correct Min and Max + m_nMinRange = nMin; + m_nMaxRange = nMax; + } + else + { + // Change Min and Max automatically + m_nMinRange = nMax; + m_nMaxRange = nMin; + } + + // assure that m_nValue is within the range + if (m_nMinRange >= m_nValue || m_nValue >= m_nMaxRange) + m_nValue = m_nMinRange; + + impl_recalcRange (); + + // Do not repaint the control at this place!!! + // An old "m_nValue" is set and can not be correct for this new range. + // Next call of "ProgressBar::setValue()" do this. +} + +// XProgressBar + +sal_Int32 SAL_CALL ProgressBar::getValue () +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + return m_nValue; +} + +// XWindow + +void SAL_CALL ProgressBar::setPosSize ( + sal_Int32 nX, + sal_Int32 nY, + sal_Int32 nWidth, + sal_Int32 nHeight, + sal_Int16 nFlags +) +{ + // Take old size BEFORE you set the new values at baseclass! + // You will control changes. At the other way, the values are the same! + Rectangle aBasePosSize = getPosSize (); + BaseControl::setPosSize (nX, nY, nWidth, nHeight, nFlags); + + // Do only, if size has changed. + if ( + ( nWidth != aBasePosSize.Width ) || + ( nHeight != aBasePosSize.Height ) + ) + { + impl_recalcRange ( ); + impl_paint ( 0, 0, impl_getGraphicsPeer () ); + } +} + +// XControl + +sal_Bool SAL_CALL ProgressBar::setModel( const Reference< XControlModel >& /*xModel*/ ) +{ + // A model is not possible for this control. + return false; +} + +// XControl + +Reference< XControlModel > SAL_CALL ProgressBar::getModel() +{ + // A model is not possible for this control. + return Reference< XControlModel >(); +} + +// protected method + +void ProgressBar::impl_paint ( sal_Int32 nX, sal_Int32 nY, const Reference< XGraphics > & rGraphics ) +{ + // save impossible cases + DBG_ASSERT ( rGraphics.is(), "ProgressBar::paint()\nCalled with invalid Reference< XGraphics > ." ); + + // This paint method is not buffered !! + // Every request paint the completely control. ( but only, if peer exist ) + if ( !rGraphics.is () ) + return; + + MutexGuard aGuard (m_aMutex); + + // Clear background + // (same color for line and fill) + rGraphics->setFillColor ( sal_Int32(m_nBackgroundColor) ); + rGraphics->setLineColor ( sal_Int32(m_nBackgroundColor) ); + rGraphics->drawRect ( nX, nY, impl_getWidth(), impl_getHeight() ); + + // same color for line and fill for blocks + rGraphics->setFillColor ( sal_Int32(m_nForegroundColor) ); + rGraphics->setLineColor ( sal_Int32(m_nForegroundColor) ); + + sal_Int32 nBlockStart = 0; // = left site of new block + sal_Int32 nBlockCount = m_nBlockValue!=0.00 ? static_cast<sal_Int32>((m_nValue-m_nMinRange)/m_nBlockValue) : 0; // = number of next block + + // Draw horizontal progressbar + // decision in "recalcRange()" + if (m_bHorizontal) + { + // Step to left side of window + nBlockStart = nX; + + for ( sal_Int32 i=1; i<=nBlockCount; ++i ) + { + // step free field + nBlockStart += PROGRESSBAR_FREESPACE; + // paint block + rGraphics->drawRect (nBlockStart, nY+PROGRESSBAR_FREESPACE, m_aBlockSize.Width, m_aBlockSize.Height); + // step next free field + nBlockStart += m_aBlockSize.Width; + } + } + // draw vertical progressbar + // decision in "recalcRange()" + else + { + // step to bottom side of window + nBlockStart = nY+impl_getHeight(); + nBlockStart -= m_aBlockSize.Height; + + for ( sal_Int32 i=1; i<=nBlockCount; ++i ) + { + // step free field + nBlockStart -= PROGRESSBAR_FREESPACE; + // paint block + rGraphics->drawRect (nX+PROGRESSBAR_FREESPACE, nBlockStart, m_aBlockSize.Width, m_aBlockSize.Height); + // step next free field + nBlockStart -= m_aBlockSize.Height; + } + } + + // Paint shadow border around the progressbar + rGraphics->setLineColor ( PROGRESSBAR_LINECOLOR_SHADOW ); + rGraphics->drawLine ( nX, nY, impl_getWidth(), nY ); + rGraphics->drawLine ( nX, nY, nX , impl_getHeight() ); + + rGraphics->setLineColor ( PROGRESSBAR_LINECOLOR_BRIGHT ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX , impl_getHeight()-1 ); +} + +// protected method + +void ProgressBar::impl_recalcRange () +{ + MutexGuard aGuard (m_aMutex); + + sal_Int32 nWindowWidth = impl_getWidth(); + sal_Int32 nWindowHeight = impl_getHeight(); + double fBlockHeight; + double fBlockWidth; + double fMaxBlocks; + + if( nWindowWidth > nWindowHeight ) + { + m_bHorizontal = true; + fBlockHeight = (nWindowHeight-(2*PROGRESSBAR_FREESPACE)); + fBlockWidth = fBlockHeight; + fMaxBlocks = nWindowWidth/(fBlockWidth+PROGRESSBAR_FREESPACE); + } + else + { + m_bHorizontal = false; + fBlockWidth = (nWindowWidth-(2*PROGRESSBAR_FREESPACE)); + fBlockHeight = fBlockWidth; + fMaxBlocks = nWindowHeight/(fBlockHeight+PROGRESSBAR_FREESPACE); + } + + double fRange = m_nMaxRange-m_nMinRange; + double fBlockValue = fRange/fMaxBlocks; + + m_nBlockValue = fBlockValue; + m_aBlockSize.Height = static_cast<sal_Int32>(fBlockHeight); + m_aBlockSize.Width = static_cast<sal_Int32>(fBlockWidth); +} + +} // namespace unocontrols + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +stardiv_UnoControls_ProgressBar_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new unocontrols::ProgressBar(context)); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/progressmonitor.cxx b/UnoControls/source/controls/progressmonitor.cxx new file mode 100644 index 000000000..cf9160ee4 --- /dev/null +++ b/UnoControls/source/controls/progressmonitor.cxx @@ -0,0 +1,854 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <progressmonitor.hxx> + +#include <com/sun/star/awt/XFixedText.hpp> +#include <com/sun/star/awt/XGraphics.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <rtl/ustrbuf.hxx> +#include <tools/debug.hxx> +#include <algorithm> + +#include <progressbar.hxx> + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; + +using ::std::vector; + +constexpr OUStringLiteral FIXEDTEXT_SERVICENAME = u"com.sun.star.awt.UnoControlFixedText"; +constexpr OUStringLiteral FIXEDTEXT_MODELNAME = u"com.sun.star.awt.UnoControlFixedTextModel"; +constexpr OUStringLiteral CONTROLNAME_TEXT = u"Text"; // identifier the control in container +constexpr OUStringLiteral CONTROLNAME_PROGRESSBAR = u"ProgressBar"; +constexpr OUStringLiteral BUTTON_SERVICENAME = u"com.sun.star.awt.UnoControlButton"; +constexpr OUStringLiteral CONTROLNAME_BUTTON = u"Button"; +constexpr OUStringLiteral BUTTON_MODELNAME = u"com.sun.star.awt.UnoControlButtonModel"; +constexpr OUStringLiteral DEFAULT_BUTTONLABEL = u"Abbrechen"; + +namespace unocontrols { + +ProgressMonitor::ProgressMonitor( const css::uno::Reference< XComponentContext >& rxContext ) + : BaseContainerControl ( rxContext ) +{ + // It's not allowed to work with member in this method (refcounter !!!) + // But with a HACK (++refcount) its "OK" :-( + osl_atomic_increment(&m_refCount); + + // Create instances for fixedtext, button and progress ... + + m_xTopic_Top.set ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xText_Top.set ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xTopic_Bottom.set( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xText_Bottom.set ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xButton.set ( rxContext->getServiceManager()->createInstanceWithContext( BUTTON_SERVICENAME, rxContext ), UNO_QUERY ); + m_xProgressBar = new ProgressBar(rxContext); + + // ... cast controls to Reference< XControl > (for "setModel"!) ... + css::uno::Reference< XControl > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Text_Top ( m_xText_Top , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Button ( m_xButton , UNO_QUERY ); + + // ... set models ... + xRef_Topic_Top->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + xRef_Text_Top->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + xRef_Topic_Bottom->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + xRef_Text_Bottom->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + xRef_Button->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( BUTTON_MODELNAME, rxContext ), UNO_QUERY ) ); + // ProgressBar has no model !!! + + // ... and add controls to basecontainercontrol! + addControl ( CONTROLNAME_TEXT, xRef_Topic_Top ); + addControl ( CONTROLNAME_TEXT, xRef_Text_Top ); + addControl ( CONTROLNAME_TEXT, xRef_Topic_Bottom ); + addControl ( CONTROLNAME_TEXT, xRef_Text_Bottom ); + addControl ( CONTROLNAME_BUTTON, xRef_Button ); + addControl ( CONTROLNAME_PROGRESSBAR, m_xProgressBar ); + + // FixedText make it automatically visible by himself ... but not the progressbar !!! + // it must be set explicitly + m_xProgressBar->setVisible( true ); + + // Reset to defaults !!! + // (progressbar take automatically its own defaults) + m_xButton->setLabel ( DEFAULT_BUTTONLABEL ); + m_xTopic_Top->setText ( PROGRESSMONITOR_DEFAULT_TOPIC ); + m_xText_Top->setText ( PROGRESSMONITOR_DEFAULT_TEXT ); + m_xTopic_Bottom->setText ( PROGRESSMONITOR_DEFAULT_TOPIC ); + m_xText_Bottom->setText ( PROGRESSMONITOR_DEFAULT_TEXT ); + + osl_atomic_decrement(&m_refCount); +} + +ProgressMonitor::~ProgressMonitor() +{ + impl_cleanMemory (); +} + +// XInterface +Any SAL_CALL ProgressMonitor::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + css::uno::Reference< XInterface > xDel = BaseContainerControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface +void SAL_CALL ProgressMonitor::acquire() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::acquire(); +} + +// XInterface +void SAL_CALL ProgressMonitor::release() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::release(); +} + +// XTypeProvider +Sequence< Type > SAL_CALL ProgressMonitor::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XLayoutConstrains>::get(), + cppu::UnoType<XButton>::get(), + cppu::UnoType<XProgressMonitor>::get(), + BaseContainerControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation +Any SAL_CALL ProgressMonitor::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XLayoutConstrains* > ( this ) , + static_cast< XButton* > ( this ) , + static_cast< XProgressMonitor* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = BaseControl::queryAggregation( aType ); + } + + return aReturn; +} + +// XProgressMonitor +void SAL_CALL ProgressMonitor::addText( + const OUString& rTopic, + const OUString& rText, + sal_Bool bbeforeProgress +) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // Safe impossible cases + // Check valid call of this method. + DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText ), "ProgressMonitor::addText()\nCall without valid parameters!\n"); + DBG_ASSERT ( !(impl_searchTopic ( rTopic, bbeforeProgress ) != nullptr ), "ProgressMonitor::addText()\nThe text already exist.\n" ); + + // Do nothing (in Release), if topic already exist. + if ( impl_searchTopic ( rTopic, bbeforeProgress ) != nullptr ) + { + return; + } + + // Else ... take memory for new item ... + IMPL_TextlistItem aTextItem; + + // Set values ... + aTextItem.sTopic = rTopic; + aTextItem.sText = rText; + + // ... and insert it in right list. + if ( bbeforeProgress ) + { + maTextlist_Top.push_back( aTextItem ); + } + else + { + maTextlist_Bottom.push_back( aTextItem ); + } + + // ... update window + impl_rebuildFixedText (); + impl_recalcLayout (); +} + +// XProgressMonitor +void SAL_CALL ProgressMonitor::removeText ( const OUString& rTopic, sal_Bool bbeforeProgress ) +{ + // Safe impossible cases + // Check valid call of this method. + DBG_ASSERT ( impl_debug_checkParameter ( rTopic ), "ProgressMonitor::removeText()\nCall without valid parameters!" ); + + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // Search the topic ... + IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress ); + + if ( pSearchItem == nullptr ) + return; + + // ... delete item from right list ... + if ( bbeforeProgress ) + { + auto itr = std::find_if( maTextlist_Top.begin(), maTextlist_Top.end(), + [&] (IMPL_TextlistItem const &p) + { return &p == pSearchItem; } ); + if (itr != maTextlist_Top.end()) + maTextlist_Top.erase(itr); + } + else + { + auto itr = std::find_if( maTextlist_Bottom.begin(), maTextlist_Bottom.end(), + [&] (IMPL_TextlistItem const &p) + { return &p == pSearchItem; } ); + if (itr != maTextlist_Bottom.end()) + maTextlist_Bottom.erase(itr); + } + + // ... and update window. + impl_rebuildFixedText (); + impl_recalcLayout (); +} + +// XProgressMonitor +void SAL_CALL ProgressMonitor::updateText ( + const OUString& rTopic, + const OUString& rText, + sal_Bool bbeforeProgress +) +{ + // Safe impossible cases + // Check valid call of this method. + DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText ), "ProgressMonitor::updateText()\nCall without valid parameters!\n" ); + + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // Search topic ... + IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress ); + + if ( pSearchItem != nullptr ) + { + // ... update text ... + pSearchItem->sText = rText; + + // ... and update window. + impl_rebuildFixedText (); + impl_recalcLayout (); + } +} + +// XProgressBar +void SAL_CALL ProgressMonitor::setForegroundColor ( sal_Int32 nColor ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + m_xProgressBar->setForegroundColor ( nColor ); +} + +// XProgressBar +void SAL_CALL ProgressMonitor::setBackgroundColor ( sal_Int32 nColor ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + m_xProgressBar->setBackgroundColor ( nColor ); +} + +// XProgressBar +void SAL_CALL ProgressMonitor::setValue ( sal_Int32 nValue ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + m_xProgressBar->setValue ( nValue ); +} + +// XProgressBar +void SAL_CALL ProgressMonitor::setRange ( sal_Int32 nMin, sal_Int32 nMax ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + m_xProgressBar->setRange ( nMin, nMax ); +} + +// XProgressBar +sal_Int32 SAL_CALL ProgressMonitor::getValue () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + return m_xProgressBar->getValue (); +} + +// XButton +void SAL_CALL ProgressMonitor::addActionListener ( const css::uno::Reference< XActionListener > & rListener ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + if ( m_xButton.is () ) + { + m_xButton->addActionListener ( rListener ); + } +} + +// XButton +void SAL_CALL ProgressMonitor::removeActionListener ( const css::uno::Reference< XActionListener > & rListener ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + if ( m_xButton.is () ) + { + m_xButton->removeActionListener ( rListener ); + } +} + +// XButton +void SAL_CALL ProgressMonitor::setLabel ( const OUString& rLabel ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + if ( m_xButton.is () ) + { + m_xButton->setLabel ( rLabel ); + } +} + +// XButton +void SAL_CALL ProgressMonitor::setActionCommand ( const OUString& rCommand ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + if ( m_xButton.is () ) + { + m_xButton->setActionCommand ( rCommand ); + } +} + +// XLayoutConstrains +Size SAL_CALL ProgressMonitor::getMinimumSize () +{ + return Size (PROGRESSMONITOR_DEFAULT_WIDTH, PROGRESSMONITOR_DEFAULT_HEIGHT); +} + +// XLayoutConstrains +Size SAL_CALL ProgressMonitor::getPreferredSize () +{ + // Ready for multithreading + ClearableMutexGuard aGuard ( m_aMutex ); + + // get information about required place of child controls + css::uno::Reference< XLayoutConstrains > xTopicLayout_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xTopicLayout_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xButtonLayout ( m_xButton , UNO_QUERY ); + + Size aTopicSize_Top = xTopicLayout_Top->getPreferredSize (); + Size aTopicSize_Bottom = xTopicLayout_Bottom->getPreferredSize (); + Size aButtonSize = xButtonLayout->getPreferredSize (); + Rectangle aTempRectangle = m_xProgressBar->getPosSize(); + Size aProgressBarSize( aTempRectangle.Width, aTempRectangle.Height ); + + aGuard.clear (); + + // calc preferred size of progressmonitor + sal_Int32 nWidth = 3 * PROGRESSMONITOR_FREEBORDER; + nWidth += aProgressBarSize.Width; + + sal_Int32 nHeight = 6 * PROGRESSMONITOR_FREEBORDER; + nHeight += aTopicSize_Top.Height; + nHeight += aProgressBarSize.Height; + nHeight += aTopicSize_Bottom.Height; + nHeight += 2; // 1 for black line, 1 for white line = 3D-Line! + nHeight += aButtonSize.Height; + + // norm to minimum + if ( nWidth < PROGRESSMONITOR_DEFAULT_WIDTH ) + { + nWidth = PROGRESSMONITOR_DEFAULT_WIDTH; + } + if ( nHeight < PROGRESSMONITOR_DEFAULT_HEIGHT ) + { + nHeight = PROGRESSMONITOR_DEFAULT_HEIGHT; + } + + // return to caller + return Size ( nWidth, nHeight ); +} + +// XLayoutConstrains +Size SAL_CALL ProgressMonitor::calcAdjustedSize ( const Size& /*rNewSize*/ ) +{ + return getPreferredSize (); +} + +// XControl +void SAL_CALL ProgressMonitor::createPeer ( const css::uno::Reference< XToolkit > & rToolkit, const css::uno::Reference< XWindowPeer > & rParent ) +{ + if (!getPeer().is()) + { + BaseContainerControl::createPeer ( rToolkit, rParent ); + + // If user forget to call "setPosSize()", we have still a correct size. + // And a "MinimumSize" IS A "MinimumSize"! + // We change not the position of control at this point. + Size aDefaultSize = getMinimumSize (); + setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE ); + } +} + +// XControl +sal_Bool SAL_CALL ProgressMonitor::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ ) +{ + // We have no model. + return false; +} + +// XControl +css::uno::Reference< XControlModel > SAL_CALL ProgressMonitor::getModel () +{ + // We have no model. + // return (XControlModel*)this; + return css::uno::Reference< XControlModel > (); +} + +// XComponent +void SAL_CALL ProgressMonitor::dispose () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // "removeControl()" control the state of a reference + css::uno::Reference< XControl > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Text_Top ( m_xText_Top , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Button ( m_xButton , UNO_QUERY ); + + removeControl ( xRef_Topic_Top ); + removeControl ( xRef_Text_Top ); + removeControl ( xRef_Topic_Bottom ); + removeControl ( xRef_Text_Bottom ); + removeControl ( xRef_Button ); + removeControl ( m_xProgressBar ); + + // don't use "...->clear ()" or "... = XFixedText ()" + // when other hold a reference at this object !!! + xRef_Topic_Top->dispose (); + xRef_Text_Top->dispose (); + xRef_Topic_Bottom->dispose (); + xRef_Text_Bottom->dispose (); + xRef_Button->dispose (); + m_xProgressBar->dispose(); + + BaseContainerControl::dispose (); +} + +// XWindow +void SAL_CALL ProgressMonitor::setPosSize ( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags ) +{ + Rectangle aBasePosSize = getPosSize (); + BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags); + + // if position or size changed + if ( + ( nWidth != aBasePosSize.Width ) || + ( nHeight != aBasePosSize.Height) + ) + { + // calc new layout for controls + impl_recalcLayout (); + // clear background (!) + // [Children were repainted in "recalcLayout" by setPosSize() automatically!] + getPeer()->invalidate(2); + // and repaint the control + impl_paint ( 0, 0, impl_getGraphicsPeer() ); + } +} + +// protected method +void ProgressMonitor::impl_paint ( sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< XGraphics > & rGraphics ) +{ + if (!rGraphics.is()) + return; + + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // paint shadowed border around the progressmonitor + rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX , impl_getHeight()-1 ); + + rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT ); + rGraphics->drawLine ( nX, nY, impl_getWidth(), nY ); + rGraphics->drawLine ( nX, nY, nX , impl_getHeight() ); + + // Paint 3D-line + rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW ); + rGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y ); + + rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT ); + rGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y+1, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y+1 ); +} + +// private method +void ProgressMonitor::impl_recalcLayout () +{ + sal_Int32 nX_Button; + sal_Int32 nY_Button; + sal_Int32 nWidth_Button; + sal_Int32 nHeight_Button; + + sal_Int32 nX_ProgressBar; + sal_Int32 nY_ProgressBar; + sal_Int32 nWidth_ProgressBar; + sal_Int32 nHeight_ProgressBar; + + sal_Int32 nX_Text_Top; + sal_Int32 nY_Text_Top; + sal_Int32 nWidth_Text_Top; + sal_Int32 nHeight_Text_Top; + + sal_Int32 nX_Topic_Top; + sal_Int32 nY_Topic_Top; + sal_Int32 nWidth_Topic_Top; + sal_Int32 nHeight_Topic_Top; + + sal_Int32 nX_Text_Bottom; + sal_Int32 nY_Text_Bottom; + sal_Int32 nWidth_Text_Bottom; + sal_Int32 nHeight_Text_Bottom; + + sal_Int32 nX_Topic_Bottom; + sal_Int32 nY_Topic_Bottom; + sal_Int32 nWidth_Topic_Bottom; + sal_Int32 nHeight_Topic_Bottom; + + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // get information about required place of child controls + css::uno::Reference< XLayoutConstrains > xTopicLayout_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xTextLayout_Top ( m_xText_Top , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xTopicLayout_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xTextLayout_Bottom ( m_xText_Bottom , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xButtonLayout ( m_xButton , UNO_QUERY ); + + Size aTopicSize_Top = xTopicLayout_Top->getPreferredSize (); + Size aTextSize_Top = xTextLayout_Top->getPreferredSize (); + Size aTopicSize_Bottom = xTopicLayout_Bottom->getPreferredSize (); + Size aTextSize_Bottom = xTextLayout_Bottom->getPreferredSize (); + Size aButtonSize = xButtonLayout->getPreferredSize (); + + // calc position and size of child controls + // Button has preferred size! + nWidth_Button = aButtonSize.Width; + nHeight_Button = aButtonSize.Height; + + // Left column before progressbar has preferred size and fixed position. + // But "Width" is oriented on left column below progressbar to!!! "max(...)" + nX_Topic_Top = PROGRESSMONITOR_FREEBORDER; + nY_Topic_Top = PROGRESSMONITOR_FREEBORDER; + nWidth_Topic_Top = std::max( aTopicSize_Top.Width, aTopicSize_Bottom.Width ); + nHeight_Topic_Top = aTopicSize_Top.Height; + + // Right column before progressbar has relative position to left column ... + // ... and a size as rest of dialog size! + nX_Text_Top = nX_Topic_Top+nWidth_Topic_Top+PROGRESSMONITOR_FREEBORDER; + nY_Text_Top = nY_Topic_Top; + nWidth_Text_Top = std::max ( aTextSize_Top.Width, aTextSize_Bottom.Width ); + // Fix size of this column to minimum! + sal_Int32 nSummaryWidth = nWidth_Text_Top+nWidth_Topic_Top+(3*PROGRESSMONITOR_FREEBORDER); + if ( nSummaryWidth < PROGRESSMONITOR_DEFAULT_WIDTH ) + nWidth_Text_Top = PROGRESSMONITOR_DEFAULT_WIDTH-nWidth_Topic_Top-(3*PROGRESSMONITOR_FREEBORDER); + // Fix size of column to maximum! + if ( nSummaryWidth > impl_getWidth() ) + nWidth_Text_Top = impl_getWidth()-nWidth_Topic_Top-(3*PROGRESSMONITOR_FREEBORDER); + nHeight_Text_Top = nHeight_Topic_Top; + + // Position of progressbar is relative to columns before. + // Progressbar.Width = Dialog.Width !!! + // Progressbar.Height = Button.Height + nX_ProgressBar = nX_Topic_Top; + nY_ProgressBar = nY_Topic_Top+nHeight_Topic_Top+PROGRESSMONITOR_FREEBORDER; + nWidth_ProgressBar = PROGRESSMONITOR_FREEBORDER+nWidth_Topic_Top+nWidth_Text_Top; + nHeight_ProgressBar = nHeight_Button; + + // Oriented by left column before progressbar. + nX_Topic_Bottom = nX_Topic_Top; + nY_Topic_Bottom = nY_ProgressBar+nHeight_ProgressBar+PROGRESSMONITOR_FREEBORDER; + nWidth_Topic_Bottom = nWidth_Topic_Top; + nHeight_Topic_Bottom = aTopicSize_Bottom.Height; + + // Oriented by right column before progressbar. + nX_Text_Bottom = nX_Topic_Bottom+nWidth_Topic_Bottom+PROGRESSMONITOR_FREEBORDER; + nY_Text_Bottom = nY_Topic_Bottom; + nWidth_Text_Bottom = nWidth_Text_Top; + nHeight_Text_Bottom = nHeight_Topic_Bottom; + + // Oriented by progressbar. + nX_Button = nX_ProgressBar+nWidth_ProgressBar-nWidth_Button; + nY_Button = nY_Topic_Bottom+nHeight_Topic_Bottom+PROGRESSMONITOR_FREEBORDER; + + // Calc offsets to center controls + sal_Int32 nDx; + sal_Int32 nDy; + + nDx = ( (2*PROGRESSMONITOR_FREEBORDER)+nWidth_ProgressBar ); + nDy = ( (6*PROGRESSMONITOR_FREEBORDER)+nHeight_Topic_Top+nHeight_ProgressBar+nHeight_Topic_Bottom+2+nHeight_Button ); + + // At this point use original dialog size to center controls! + nDx = (impl_getWidth ()/2)-(nDx/2); + nDy = (impl_getHeight()/2)-(nDy/2); + + if ( nDx<0 ) + { + nDx=0; + } + if ( nDy<0 ) + { + nDy=0; + } + + // Set new position and size on all controls + css::uno::Reference< XWindow > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XWindow > xRef_Text_Top ( m_xText_Top , UNO_QUERY ); + css::uno::Reference< XWindow > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XWindow > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY ); + css::uno::Reference< XWindow > xRef_Button ( m_xButton , UNO_QUERY ); + + xRef_Topic_Top->setPosSize ( nDx+nX_Topic_Top , nDy+nY_Topic_Top , nWidth_Topic_Top , nHeight_Topic_Top , 15 ); + xRef_Text_Top->setPosSize ( nDx+nX_Text_Top , nDy+nY_Text_Top , nWidth_Text_Top , nHeight_Text_Top , 15 ); + xRef_Topic_Bottom->setPosSize ( nDx+nX_Topic_Bottom , nDy+nY_Topic_Bottom , nWidth_Topic_Bottom , nHeight_Topic_Bottom , 15 ); + xRef_Text_Bottom->setPosSize ( nDx+nX_Text_Bottom , nDy+nY_Text_Bottom , nWidth_Text_Bottom , nHeight_Text_Bottom , 15 ); + xRef_Button->setPosSize ( nDx+nX_Button , nDy+nY_Button , nWidth_Button , nHeight_Button , 15 ); + m_xProgressBar->setPosSize( nDx+nX_ProgressBar, nDy+nY_ProgressBar, nWidth_ProgressBar, nHeight_ProgressBar, 15 ); + + m_a3DLine.X = nDx+nX_Topic_Top; + m_a3DLine.Y = nDy+nY_Topic_Bottom+nHeight_Topic_Bottom+(PROGRESSMONITOR_FREEBORDER/2); + m_a3DLine.Width = nWidth_ProgressBar; + m_a3DLine.Height = nHeight_ProgressBar; + + // All childcontrols make an implicit repaint in setPosSize()! + // Make it also for this 3D-line ... + css::uno::Reference< XGraphics > xGraphics = impl_getGraphicsPeer (); + + xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW ); + xGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y ); + + xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT ); + xGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y+1, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y+1 ); +} + +// private method +void ProgressMonitor::impl_rebuildFixedText () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // Rebuild fixedtext before progress + + // Rebuild left site of text + if (m_xTopic_Top.is()) + { + OUStringBuffer aCollectString; + + // Collect all topics from list and format text. + // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! + for (auto const & rSearchItem : maTextlist_Top) + { + aCollectString.append(rSearchItem.sTopic + "\n"); + } + + m_xTopic_Top->setText ( aCollectString.makeStringAndClear() ); + } + + // Rebuild right site of text + if (m_xText_Top.is()) + { + OUStringBuffer aCollectString; + + // Collect all topics from list and format text. + // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! + for (auto const & rSearchItem : maTextlist_Top) + { + aCollectString.append(rSearchItem.sText + "\n"); + } + + m_xText_Top->setText ( aCollectString.makeStringAndClear() ); + } + + // Rebuild fixedtext below progress + + // Rebuild left site of text + if (m_xTopic_Bottom.is()) + { + OUStringBuffer aCollectString; + + // Collect all topics from list and format text. + // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! + for (auto const & rSearchItem : maTextlist_Bottom) + { + aCollectString.append(rSearchItem.sTopic + "\n"); + } + + m_xTopic_Bottom->setText ( aCollectString.makeStringAndClear() ); + } + + // Rebuild right site of text + if (!m_xText_Bottom.is()) + return; + + OUStringBuffer aCollectString; + + // Collect all topics from list and format text. + // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! + for (auto const & rSearchItem : maTextlist_Bottom) + { + aCollectString.append(rSearchItem.sText + "\n"); + } + + m_xText_Bottom->setText ( aCollectString.makeStringAndClear() ); +} + +// private method +void ProgressMonitor::impl_cleanMemory () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // Delete all of lists. + maTextlist_Top.clear(); + maTextlist_Bottom.clear(); +} + +// private method +IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( std::u16string_view rTopic, bool bbeforeProgress ) +{ + // Get right textlist for following operations. + ::std::vector< IMPL_TextlistItem >* pTextList; + + if (bbeforeProgress) + { + pTextList = &maTextlist_Top; + } + else + { + pTextList = &maTextlist_Bottom; + } + + // Search the topic in textlist. + size_t nPosition = 0; + size_t nCount = pTextList->size(); + + for ( nPosition = 0; nPosition < nCount; ++nPosition ) + { + auto& rSearchItem = pTextList->at( nPosition ); + + if ( rSearchItem.sTopic == rTopic ) + { + // We have found this topic... return a valid pointer. + return &rSearchItem; + } + } + + // We haven't found this topic... return a nonvalid pointer. + return nullptr; +} + +// debug methods + +// addText, updateText +bool ProgressMonitor::impl_debug_checkParameter ( + std::u16string_view rTopic, + std::u16string_view rText +) { + if ( rTopic.empty() ) return false; // "" + + if ( rText.empty() ) return false; // "" + + // Parameter OK ... return true. + return true; +} + +// removeText +bool ProgressMonitor::impl_debug_checkParameter ( std::u16string_view rTopic ) +{ + if ( rTopic.empty() ) return false; // "" + + // Parameter OK ... return true. + return true; +} + +} // namespace unocontrols + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +stardiv_UnoControls_ProgressMonitor_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new unocontrols::ProgressMonitor(context)); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/statusindicator.cxx b/UnoControls/source/controls/statusindicator.cxx new file mode 100644 index 000000000..6e5f09798 --- /dev/null +++ b/UnoControls/source/controls/statusindicator.cxx @@ -0,0 +1,455 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <statusindicator.hxx> + +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/XFixedText.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> + +#include <progressbar.hxx> + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::task; + +constexpr OUStringLiteral FIXEDTEXT_SERVICENAME = u"com.sun.star.awt.UnoControlFixedText"; +constexpr OUStringLiteral FIXEDTEXT_MODELNAME = u"com.sun.star.awt.UnoControlFixedTextModel"; +constexpr OUStringLiteral CONTROLNAME_TEXT = u"Text"; // identifier the control in container +constexpr OUStringLiteral CONTROLNAME_PROGRESSBAR = u"ProgressBar"; // -||- + +namespace unocontrols { + +// construct/destruct + +StatusIndicator::StatusIndicator( const css::uno::Reference< XComponentContext >& rxContext ) + : BaseContainerControl ( rxContext ) +{ + // It's not allowed to work with member in this method (refcounter !!!) + // But with a HACK (++refcount) its "OK" :-( + osl_atomic_increment(&m_refCount); + + // Create instances for fixedtext and progress ... + m_xText.set( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xProgressBar = new ProgressBar(rxContext); + // ... cast controls to css::uno::Reference< XControl > and set model ... + // ( ProgressBar has no model !!! ) + css::uno::Reference< XControl > xTextControl ( m_xText , UNO_QUERY ); + xTextControl->setModel( css::uno::Reference< XControlModel >( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + // ... and add controls to basecontainercontrol! + addControl( CONTROLNAME_TEXT, xTextControl ); + addControl( CONTROLNAME_PROGRESSBAR, m_xProgressBar ); + // FixedText make it automatically visible by himself ... but not the progressbar !!! + // it must be set explicitly + m_xProgressBar->setVisible( true ); + // Reset to defaults !!! + // (progressbar take automatically its own defaults) + m_xText->setText( "" ); + + osl_atomic_decrement(&m_refCount); +} + +StatusIndicator::~StatusIndicator() {} + +// XInterface + +Any SAL_CALL StatusIndicator::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + css::uno::Reference< XInterface > xDel = BaseContainerControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL StatusIndicator::acquire() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::acquire(); +} + +// XInterface + +void SAL_CALL StatusIndicator::release() noexcept +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::release(); +} + +// XTypeProvider + +Sequence< Type > SAL_CALL StatusIndicator::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XLayoutConstrains>::get(), + cppu::UnoType<XStatusIndicator>::get(), + BaseContainerControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation + +Any SAL_CALL StatusIndicator::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XLayoutConstrains* > ( this ) , + static_cast< XStatusIndicator* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = BaseControl::queryAggregation( aType ); + } + + return aReturn; +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::start( const OUString& sText, sal_Int32 nRange ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Initialize status controls with given values. + m_xText->setText( sText ); + m_xProgressBar->setRange( 0, nRange ); + // force repaint ... fixedtext has changed ! + impl_recalcLayout ( WindowEvent(static_cast< OWeakObject* >(this),0,0,impl_getWidth(),impl_getHeight(),0,0,0,0) ); +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::end() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Clear values of status controls. + m_xText->setText( OUString() ); + m_xProgressBar->setValue( 0 ); + setVisible( false ); +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::setText( const OUString& sText ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Take text on right control + m_xText->setText( sText ); +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::setValue( sal_Int32 nValue ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Take value on right control + m_xProgressBar->setValue( nValue ); +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::reset() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Clear values of status controls. + // (Don't hide the window! User will reset current values ... but he will not finish using of indicator!) + m_xText->setText( OUString() ); + m_xProgressBar->setValue( 0 ); +} + +// XLayoutConstrains + +Size SAL_CALL StatusIndicator::getMinimumSize () +{ + return Size (STATUSINDICATOR_DEFAULT_WIDTH, STATUSINDICATOR_DEFAULT_HEIGHT); +} + +// XLayoutConstrains + +Size SAL_CALL StatusIndicator::getPreferredSize () +{ + // Ready for multithreading + ClearableMutexGuard aGuard ( m_aMutex ); + + // get information about required place of child controls + css::uno::Reference< XLayoutConstrains > xTextLayout ( m_xText, UNO_QUERY ); + Size aTextSize = xTextLayout->getPreferredSize(); + + aGuard.clear (); + + // calc preferred size of status indicator + sal_Int32 nWidth = impl_getWidth(); + sal_Int32 nHeight = (2*STATUSINDICATOR_FREEBORDER)+aTextSize.Height; + + // norm to minimum + if ( nWidth<STATUSINDICATOR_DEFAULT_WIDTH ) + { + nWidth = STATUSINDICATOR_DEFAULT_WIDTH; + } + if ( nHeight<STATUSINDICATOR_DEFAULT_HEIGHT ) + { + nHeight = STATUSINDICATOR_DEFAULT_HEIGHT; + } + + // return to caller + return Size ( nWidth, nHeight ); +} + +// XLayoutConstrains + +Size SAL_CALL StatusIndicator::calcAdjustedSize ( const Size& /*rNewSize*/ ) +{ + return getPreferredSize (); +} + +// XControl + +void SAL_CALL StatusIndicator::createPeer ( + const css::uno::Reference< XToolkit > & rToolkit, + const css::uno::Reference< XWindowPeer > & rParent +) +{ + if( !getPeer().is() ) + { + BaseContainerControl::createPeer( rToolkit, rParent ); + + // If user forget to call "setPosSize()", we have still a correct size. + // And a "MinimumSize" IS A "MinimumSize"! + // We change not the position of control at this point. + Size aDefaultSize = getMinimumSize (); + setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE ); + } +} + +// XControl + +sal_Bool SAL_CALL StatusIndicator::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ ) +{ + // We have no model. + return false; +} + +// XControl + +css::uno::Reference< XControlModel > SAL_CALL StatusIndicator::getModel () +{ + // We have no model. + // return (XControlModel*)this; + return css::uno::Reference< XControlModel > (); +} + +// XComponent + +void SAL_CALL StatusIndicator::dispose () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // "removeControl()" control the state of a reference + css::uno::Reference< XControl > xTextControl ( m_xText , UNO_QUERY ); + + removeControl( xTextControl ); + removeControl( m_xProgressBar ); + + // don't use "...->clear ()" or "... = XFixedText ()" + // when other hold a reference at this object !!! + xTextControl->dispose(); + m_xProgressBar->dispose(); + BaseContainerControl::dispose(); +} + +// XWindow + +void SAL_CALL StatusIndicator::setPosSize ( + sal_Int32 nX, + sal_Int32 nY, + sal_Int32 nWidth, + sal_Int32 nHeight, + sal_Int16 nFlags +) +{ + Rectangle aBasePosSize = getPosSize (); + BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags); + + // if position or size changed + if ( + ( nWidth != aBasePosSize.Width ) || + ( nHeight != aBasePosSize.Height) + ) + { + // calc new layout for controls + impl_recalcLayout ( WindowEvent(static_cast< OWeakObject* >(this),0,0,nWidth,nHeight,0,0,0,0) ); + // clear background (!) + // [Children were repainted in "recalcLayout" by setPosSize() automatically!] + getPeer()->invalidate(2); + // and repaint the control + impl_paint ( 0, 0, impl_getGraphicsPeer() ); + } +} + +// protected method + +WindowDescriptor StatusIndicator::impl_getWindowDescriptor( const css::uno::Reference< XWindowPeer >& xParentPeer ) +{ + WindowDescriptor aDescriptor; + + aDescriptor.Type = WindowClass_SIMPLE; + aDescriptor.WindowServiceName = "floatingwindow"; + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = xParentPeer; + aDescriptor.Bounds = getPosSize (); + + return aDescriptor; +} + +// protected method + +void StatusIndicator::impl_paint ( sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< XGraphics > & rGraphics ) +{ + // This paint method is not buffered! + // Every request paint the completely control. (But only, if peer exist) + if ( !rGraphics.is () ) + return; + + MutexGuard aGuard (m_aMutex); + + // background = gray + css::uno::Reference< XWindowPeer > xPeer( impl_getPeerWindow(), UNO_QUERY ); + if( xPeer.is() ) + xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR ); + + // FixedText background = gray + css::uno::Reference< XControl > xTextControl( m_xText, UNO_QUERY ); + xPeer = xTextControl->getPeer(); + if( xPeer.is() ) + xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR ); + + // Progress background = gray + xPeer = m_xProgressBar->getPeer(); + if( xPeer.is() ) + xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR ); + + // paint shadow border + rGraphics->setLineColor ( STATUSINDICATOR_LINECOLOR_BRIGHT ); + rGraphics->drawLine ( nX, nY, impl_getWidth(), nY ); + rGraphics->drawLine ( nX, nY, nX , impl_getHeight() ); + + rGraphics->setLineColor ( STATUSINDICATOR_LINECOLOR_SHADOW ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX , impl_getHeight()-1 ); +} + +// protected method + +void StatusIndicator::impl_recalcLayout ( const WindowEvent& aEvent ) +{ + sal_Int32 nX_ProgressBar; + sal_Int32 nY_ProgressBar; + sal_Int32 nWidth_ProgressBar; + sal_Int32 nHeight_ProgressBar; + sal_Int32 nX_Text; + sal_Int32 nY_Text; + sal_Int32 nWidth_Text; + sal_Int32 nHeight_Text; + + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // get information about required place of child controls + Size aWindowSize ( aEvent.Width, aEvent.Height ); + css::uno::Reference< XLayoutConstrains > xTextLayout ( m_xText, UNO_QUERY ); + Size aTextSize = xTextLayout->getPreferredSize(); + + if( aWindowSize.Width < STATUSINDICATOR_DEFAULT_WIDTH ) + { + aWindowSize.Width = STATUSINDICATOR_DEFAULT_WIDTH; + } + if( aWindowSize.Height < STATUSINDICATOR_DEFAULT_HEIGHT ) + { + aWindowSize.Height = STATUSINDICATOR_DEFAULT_HEIGHT; + } + + // calc position and size of child controls + nX_Text = STATUSINDICATOR_FREEBORDER; + nY_Text = STATUSINDICATOR_FREEBORDER; + nWidth_Text = aTextSize.Width; + nHeight_Text = aTextSize.Height; + + nX_ProgressBar = nX_Text+nWidth_Text+STATUSINDICATOR_FREEBORDER; + nY_ProgressBar = nY_Text; + nWidth_ProgressBar = aWindowSize.Width-nWidth_Text-(3*STATUSINDICATOR_FREEBORDER); + nHeight_ProgressBar = nHeight_Text; + + // Set new position and size on all controls + css::uno::Reference< XWindow > xTextWindow ( m_xText , UNO_QUERY ); + + xTextWindow->setPosSize ( nX_Text , nY_Text , nWidth_Text , nHeight_Text , 15 ); + m_xProgressBar->setPosSize( nX_ProgressBar, nY_ProgressBar, nWidth_ProgressBar, nHeight_ProgressBar, 15 ); +} + +} // namespace unocontrols + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +stardiv_UnoControls_StatusIndicator_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new unocontrols::StatusIndicator(context)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |