/* -*- 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 .
*/
OButtonModel::OButtonModel(const Reference<XComponentContext>& _rxFactory)
:OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_COMMANDBUTTON, FRM_SUN_CONTROL_COMMANDBUTTON ) // use the old control name for compatibility reasons
,m_aResetHelper( *this, m_aMutex )
,m_eDefaultState( TRISTATE_FALSE )
{
m_nClassId = FormComponentType::COMMANDBUTTON;
}
Any SAL_CALL OButtonModel::queryAggregation( const Type& _type )
{
Any aReturn = OClickableImageBaseModel::queryAggregation( _type ); if ( !aReturn.hasValue() )
aReturn = OButtonModel_Base::queryInterface( _type ); return aReturn;
}
OButtonControl::OButtonControl(const Reference<XComponentContext>& _rxFactory)
:OClickableImageBaseControl(_rxFactory, VCL_CONTROL_COMMANDBUTTON)
,OFormNavigationHelper( _rxFactory )
,m_nClickEvent( nullptr )
,m_nTargetUrlFeatureId( -1 )
,m_bEnabledByPropertyValue( false )
{
osl_atomic_increment(&m_refCount);
{
// Register as ActionListener
if (auto xButton = query_aggregation<XButton>(m_xAggregate))
xButton->addActionListener(this);
}
// For Listener: refcount at one
osl_atomic_decrement(&m_refCount);
}
OButtonControl::~OButtonControl()
{
if (m_nClickEvent)
Application::RemoveUserEvent(m_nClickEvent);
}
// UNO binding
Any SAL_CALL OButtonControl::queryAggregation(const Type& _rType)
{
// if asked for the XTypeProvider, don't let OButtonControl_BASE do this
Any aReturn;
if ( !_rType.equals( cppu::UnoType<XTypeProvider>::get() ) )
aReturn = OButtonControl_BASE::queryInterface( _rType );
if ( !aReturn.hasValue() )
aReturn = OClickableImageBaseControl::queryAggregation( _rType );
if ( !aReturn.hasValue() )
aReturn = OFormNavigationHelper::queryInterface( _rType );
if (m_aApproveActionListeners.getLength())
{
// if there are listeners, start the action in an own thread, to not allow
// them to block us here (we're in the application's main thread)
getImageProducerThread()->addEvent();
}
else
{
// Else, don't. We then must not notify the Listeners in any case,
// not even if added later on.
aGuard.clear();
// recognize the button type
Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
if (!xSet.is())
return;
if (FormButtonType_PUSH == *o3tl::doAccess<FormButtonType>(xSet->getPropertyValue(PROPERTY_BUTTONTYPE)))
{
// notify the action listeners for a push button
::comphelper::OInterfaceIteratorHelper3 aIter(m_aActionListeners);
ActionEvent aEvt(static_cast<XWeak*>(this), m_aActionCommand);
while(aIter.hasMoreElements() )
{
// catch exceptions
// and catch them on a per-listener basis - if one listener fails, the others still need
// to get notified
try
{
aIter.next()->actionPerformed(aEvt);
}
#ifdef DBG_UTIL
catch( const RuntimeException& )
{
// silence this
}
#endif
catch( const Exception& )
{
TOOLS_WARN_EXCEPTION( "forms.component", "OButtonControl::OnClick: caught an exception other than RuntimeException!" );
}
}
}
else
actionPerformed_Impl( false, css::awt::MouseEvent() );
}
}
// Do we have another TargetURL now? If so, we need to update our dispatches
m_nTargetUrlFeatureId = getModelUrlFeatureId( );
if ( nOldUrlFeatureId != m_nTargetUrlFeatureId )
{
invalidateSupportedFeaturesSet();
if ( !isDesignMode() )
updateDispatches( );
}
}
// are we a URL button?
if ( eButtonType == FormButtonType_URL )
{
// is it a feature URL?
if ( isFormControllerURL( sUrl ) )
{
nFeatureId = OFormNavigationMapper::getFeatureId( sUrl );
}
}
void OButtonControl::featureStateChanged( sal_Int16 _nFeatureId, bool _bEnabled )
{
if ( _nFeatureId == m_nTargetUrlFeatureId )
{
// enable or disable our peer, according to the new state
Reference< XVclWindowPeer > xPeer( getPeer(), UNO_QUERY );
if ( xPeer.is() )
xPeer->setProperty( PROPERTY_ENABLED, Any( m_bEnabledByPropertyValue && _bEnabled ) );
// if we're disabled according to our model's property, then
// we don't care for the feature state, but *are* disabled.
// If the model's property states that we're enabled, then we *do*
// care for the feature state
}
// base class
OFormNavigationHelper::featureStateChanged( _nFeatureId, _bEnabled );
}
void OButtonControl::allFeatureStatesChanged( )
{
if ( -1 != m_nTargetUrlFeatureId )
// we have only one supported feature, so simulate it has changed ...
featureStateChanged( m_nTargetUrlFeatureId, isEnabled( m_nTargetUrlFeatureId ) );
// base class
OFormNavigationHelper::allFeatureStatesChanged( );
}
bool OButtonControl::isEnabled( sal_Int16 _nFeatureId ) const
{
if ( const_cast< OButtonControl* >( this )->isDesignMode() )
// TODO: the model property?
return true;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.