1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "buttonnavigationhandler.hxx"
21 #include "formstrings.hxx"
22 #include "formmetadata.hxx"
23 #include "pushbuttonnavigation.hxx"
25 #include <com/sun/star/form/inspection/FormComponentPropertyHandler.hpp>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::com::sun::star::inspection
;
35 ButtonNavigationHandler::ButtonNavigationHandler( const Reference
< XComponentContext
>& _rxContext
)
36 :PropertyHandlerComponent( _rxContext
)
39 m_xSlaveHandler
= css::form::inspection::FormComponentPropertyHandler::create( m_xContext
);
43 ButtonNavigationHandler::~ButtonNavigationHandler( )
48 OUString
ButtonNavigationHandler::getImplementationName( )
50 return u
"com.sun.star.comp.extensions.ButtonNavigationHandler"_ustr
;
54 Sequence
< OUString
> ButtonNavigationHandler::getSupportedServiceNames( )
56 return { u
"com.sun.star.form.inspection.ButtonNavigationHandler"_ustr
};
60 void SAL_CALL
ButtonNavigationHandler::inspect( const Reference
< XInterface
>& _rxIntrospectee
)
62 PropertyHandlerComponent::inspect( _rxIntrospectee
);
63 m_xSlaveHandler
->inspect( _rxIntrospectee
);
67 PropertyState SAL_CALL
ButtonNavigationHandler::getPropertyState( const OUString
& _rPropertyName
)
69 ::osl::MutexGuard
aGuard( m_aMutex
);
70 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
71 PropertyState eState
= PropertyState_DIRECT_VALUE
;
74 case PROPERTY_ID_BUTTONTYPE
:
76 PushButtonNavigation
aHelper( m_xComponent
);
77 eState
= aHelper
.getCurrentButtonTypeState();
80 case PROPERTY_ID_TARGET_URL
:
82 PushButtonNavigation
aHelper( m_xComponent
);
83 eState
= aHelper
.getCurrentTargetURLState();
88 OSL_FAIL( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" );
96 Any SAL_CALL
ButtonNavigationHandler::getPropertyValue( const OUString
& _rPropertyName
)
98 ::osl::MutexGuard
aGuard( m_aMutex
);
99 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
104 case PROPERTY_ID_BUTTONTYPE
:
106 PushButtonNavigation
aHelper( m_xComponent
);
107 aReturn
= aHelper
.getCurrentButtonType();
111 case PROPERTY_ID_TARGET_URL
:
113 PushButtonNavigation
aHelper( m_xComponent
);
114 aReturn
= aHelper
.getCurrentTargetURL();
119 OSL_FAIL( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" );
127 void SAL_CALL
ButtonNavigationHandler::setPropertyValue( const OUString
& _rPropertyName
, const Any
& _rValue
)
129 ::osl::MutexGuard
aGuard( m_aMutex
);
130 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
133 case PROPERTY_ID_BUTTONTYPE
:
135 PushButtonNavigation
aHelper( m_xComponent
);
136 aHelper
.setCurrentButtonType( _rValue
);
140 case PROPERTY_ID_TARGET_URL
:
142 PushButtonNavigation
aHelper( m_xComponent
);
143 aHelper
.setCurrentTargetURL( _rValue
);
148 OSL_FAIL( "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" );
153 bool ButtonNavigationHandler::isNavigationCapableButton( const Reference
< XPropertySet
>& _rxComponent
)
155 Reference
< XPropertySetInfo
> xPSI
;
156 if ( _rxComponent
.is() )
157 xPSI
= _rxComponent
->getPropertySetInfo();
160 && xPSI
->hasPropertyByName( PROPERTY_TARGET_URL
)
161 && xPSI
->hasPropertyByName( PROPERTY_BUTTONTYPE
);
165 Sequence
< Property
> ButtonNavigationHandler::doDescribeSupportedProperties() const
167 std::vector
< Property
> aProperties
;
169 if ( isNavigationCapableButton( m_xComponent
) )
171 addStringPropertyDescription( aProperties
, PROPERTY_TARGET_URL
);
172 implAddPropertyDescription( aProperties
, PROPERTY_BUTTONTYPE
, ::cppu::UnoType
<sal_Int32
>::get() );
175 if ( aProperties
.empty() )
176 return Sequence
< Property
>();
177 return comphelper::containerToSequence(aProperties
);
181 Sequence
< OUString
> SAL_CALL
ButtonNavigationHandler::getActuatingProperties( )
183 Sequence
< OUString
> aActuating
{ PROPERTY_BUTTONTYPE
, PROPERTY_TARGET_URL
};
188 InteractiveSelectionResult SAL_CALL
ButtonNavigationHandler::onInteractivePropertySelection( const OUString
& _rPropertyName
, sal_Bool _bPrimary
, Any
& _rData
, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
)
190 ::osl::MutexGuard
aGuard( m_aMutex
);
191 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
193 InteractiveSelectionResult
eReturn( InteractiveSelectionResult_Cancelled
);
197 case PROPERTY_ID_TARGET_URL
:
198 eReturn
= m_xSlaveHandler
->onInteractivePropertySelection( _rPropertyName
, _bPrimary
, _rData
, _rxInspectorUI
);
201 eReturn
= PropertyHandlerComponent::onInteractivePropertySelection( _rPropertyName
, _bPrimary
, _rData
, _rxInspectorUI
);
209 void SAL_CALL
ButtonNavigationHandler::actuatingPropertyChanged( const OUString
& _rActuatingPropertyName
, const Any
& /*_rNewValue*/, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
/*_bFirstTimeInit*/ )
211 ::osl::MutexGuard
aGuard( m_aMutex
);
212 PropertyId
nPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName
) );
215 case PROPERTY_ID_BUTTONTYPE
:
217 PushButtonNavigation
aHelper( m_xComponent
);
218 _rxInspectorUI
->enablePropertyUI( PROPERTY_TARGET_URL
, aHelper
.currentButtonTypeIsOpenURL() );
222 case PROPERTY_ID_TARGET_URL
:
224 PushButtonNavigation
aHelper( m_xComponent
);
225 _rxInspectorUI
->enablePropertyUI( PROPERTY_TARGET_FRAME
, aHelper
.hasNonEmptyCurrentTargetURL() );
230 OSL_FAIL( "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" );
235 LineDescriptor SAL_CALL
ButtonNavigationHandler::describePropertyLine( const OUString
& _rPropertyName
, const Reference
< XPropertyControlFactory
>& _rxControlFactory
)
237 ::osl::MutexGuard
aGuard( m_aMutex
);
238 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
240 LineDescriptor aReturn
;
244 case PROPERTY_ID_TARGET_URL
:
245 aReturn
= m_xSlaveHandler
->describePropertyLine( _rPropertyName
, _rxControlFactory
);
248 aReturn
= PropertyHandlerComponent::describePropertyLine( _rPropertyName
, _rxControlFactory
);
258 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
259 extensions_propctrlr_ButtonNavigationHandler_get_implementation(
260 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
262 return cppu::acquire(new pcr::ButtonNavigationHandler(context
));
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */