Kaydet (Commit) be9b8344 authored tarafından Michael Meeks's avatar Michael Meeks

oovbaapi: hack Excel / OptionButton compatibility into Button for now.

Change-Id: I22d2d545a6201cbb89d430c65f66e0fea8794d83
Reviewed-on: https://gerrit.libreoffice.org/60541Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 694a433d
......@@ -29,8 +29,6 @@
module ooo { module vba { module excel {
/** Additional attributes for a push button drawing control (this interface
does not belong to ActiveX form controls).
*/
......@@ -52,12 +50,16 @@ interface XButton : com::sun::star::uno::XInterface
ooo::vba::excel::XlOrientation. */
[attribute] long Orientation;
/** OptionButton only hack - are we checked */
[attribute] any Value;
/** OptionButton only hack - another way to get the text */
[attribute] string Text;
/** Access to text and text formatting of the button caption. */
XCharacters Characters( [in] any Start, [in] any Length );
};
}; }; };
#endif
......
......@@ -504,6 +504,26 @@ void SAL_CALL ScVbaButton::setOrientation( sal_Int32 /*nOrientation*/ )
// not supported
}
uno::Any SAL_CALL ScVbaButton::getValue()
{
return mxControlProps->getPropertyValue( "State" );
}
void SAL_CALL ScVbaButton::setValue( const uno::Any &nValue )
{
return mxControlProps->setPropertyValue( "State", nValue );
}
OUString SAL_CALL ScVbaButton::getText()
{
return mxControlProps->getPropertyValue( "Label" ).get< OUString >();
}
void SAL_CALL ScVbaButton::setText( const OUString &aText )
{
return mxControlProps->setPropertyValue( "Label", uno::Any( aText ) );
}
// XButton methods
uno::Reference< excel::XCharacters > SAL_CALL ScVbaButton::Characters( const uno::Any& rStart, const uno::Any& rLength )
......
......@@ -199,6 +199,10 @@ public:
virtual void SAL_CALL setVerticalAlignment( sal_Int32 nAlign ) override;
virtual sal_Int32 SAL_CALL getOrientation() override;
virtual void SAL_CALL setOrientation( sal_Int32 nOrientation ) override;
virtual css::uno::Any SAL_CALL getValue() override;
virtual void SAL_CALL setValue( const css::uno::Any &nValue ) override;
virtual OUString SAL_CALL getText() override;
virtual void SAL_CALL setText( const OUString &aText ) override;
// XButton methods
css::uno::Reference< ov::excel::XCharacters > SAL_CALL Characters(
......
......@@ -371,7 +371,8 @@ public:
const uno::Reference< frame::XModel >& rxModel,
const uno::Reference< sheet::XSpreadsheet >& rxSheet,
const uno::Type& rVbaType,
const OUString& rModelServiceName );
const OUString& rModelServiceName,
sal_Int16 /* css::form::FormComponentType */ eType );
protected:
/// @throws uno::RuntimeException
......@@ -386,6 +387,7 @@ protected:
protected:
uno::Reference< container::XIndexContainer > mxFormIC;
OUString maModelServiceName;
sal_Int16 /* css::form::FormComponentType */ meType;
};
ScVbaControlContainer::ScVbaControlContainer(
......@@ -394,9 +396,11 @@ ScVbaControlContainer::ScVbaControlContainer(
const uno::Reference< frame::XModel >& rxModel,
const uno::Reference< sheet::XSpreadsheet >& rxSheet,
const uno::Type& rVbaType,
const OUString& rModelServiceName ) :
const OUString& rModelServiceName,
sal_Int16 /* css::form::FormComponentType */ eType ) :
ScVbaObjectContainer( rxParent, rxContext, rxModel, rxSheet, rVbaType ),
maModelServiceName( rModelServiceName )
maModelServiceName( rModelServiceName ),
meType( eType )
{
}
......@@ -429,7 +433,7 @@ bool ScVbaControlContainer::implPickShape( const uno::Reference< drawing::XShape
uno::Reference< beans::XPropertySet > xModelProps( xControlShape->getControl(), uno::UNO_QUERY_THROW );
sal_Int16 nClassId = -1;
return lclGetProperty( nClassId, xModelProps, "ClassId" ) &&
(nClassId == form::FormComponentType::COMMANDBUTTON) && implCheckProperties( xModelProps );
(nClassId == meType) && implCheckProperties( xModelProps );
}
catch( uno::Exception& )
{
......@@ -472,13 +476,15 @@ void ScVbaControlContainer::implOnShapeCreated( const uno::Reference< drawing::X
class ScVbaButtonContainer : public ScVbaControlContainer
{
bool mbOptionButtons;
public:
/// @throws uno::RuntimeException
explicit ScVbaButtonContainer(
const uno::Reference< XHelperInterface >& rxParent,
const uno::Reference< uno::XComponentContext >& rxContext,
const uno::Reference< frame::XModel >& rxModel,
const uno::Reference< sheet::XSpreadsheet >& rxSheet );
const uno::Reference< sheet::XSpreadsheet >& rxSheet,
bool bOptionButtons);
protected:
virtual ScVbaSheetObjectBase* implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) override;
......@@ -489,11 +495,18 @@ ScVbaButtonContainer::ScVbaButtonContainer(
const uno::Reference< XHelperInterface >& rxParent,
const uno::Reference< uno::XComponentContext >& rxContext,
const uno::Reference< frame::XModel >& rxModel,
const uno::Reference< sheet::XSpreadsheet >& rxSheet ) :
const uno::Reference< sheet::XSpreadsheet >& rxSheet,
bool bOptionButtons ) :
ScVbaControlContainer(
rxParent, rxContext, rxModel, rxSheet,
cppu::UnoType<excel::XButton>::get(),
"com.sun.star.form.component.CommandButton" )
( bOptionButtons ?
OUString( "com.sun.star.form.component.RadioButton" ) :
OUString( "com.sun.star.form.component.CommandButton" ) ),
( bOptionButtons ?
form::FormComponentType::RADIOBUTTON :
form::FormComponentType::COMMANDBUTTON) ),
mbOptionButtons(bOptionButtons)
{
}
......@@ -505,6 +518,9 @@ ScVbaSheetObjectBase* ScVbaButtonContainer::implCreateVbaObject( const uno::Refe
bool ScVbaButtonContainer::implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const
{
if (mbOptionButtons)
return true;
// do not insert toggle buttons into the 'Buttons' collection
bool bToggle = false;
return lclGetProperty( bToggle, rxModelProps, "Toggle" ) && !bToggle;
......@@ -514,8 +530,9 @@ ScVbaButtons::ScVbaButtons(
const uno::Reference< XHelperInterface >& rxParent,
const uno::Reference< uno::XComponentContext >& rxContext,
const uno::Reference< frame::XModel >& rxModel,
const uno::Reference< sheet::XSpreadsheet >& rxSheet ) :
ScVbaGraphicObjectsBase( new ScVbaButtonContainer( rxParent, rxContext, rxModel, rxSheet ) )
const uno::Reference< sheet::XSpreadsheet >& rxSheet,
bool bOptionButtons) :
ScVbaGraphicObjectsBase( new ScVbaButtonContainer( rxParent, rxContext, rxModel, rxSheet, bOptionButtons ) )
{
}
......
......@@ -94,7 +94,8 @@ public:
const css::uno::Reference< ov::XHelperInterface >& rxParent,
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
const css::uno::Reference< css::frame::XModel >& rxModel,
const css::uno::Reference< css::sheet::XSpreadsheet >& rxSheet );
const css::uno::Reference< css::sheet::XSpreadsheet >& rxSheet,
bool bOptionButtons);
VBAHELPER_DECL_XHELPERINTERFACE
};
......
......@@ -809,16 +809,24 @@ ScVbaWorksheet::Shapes( const uno::Any& aIndex )
return uno::makeAny( xVbaShapes );
}
uno::Any SAL_CALL
ScVbaWorksheet::Buttons( const uno::Any& rIndex )
uno::Any
ScVbaWorksheet::getButtons( const uno::Any &rIndex, bool bOptionButtons )
{
if( !mxButtons.is() )
mxButtons.set( new ScVbaButtons( this, mxContext, mxModel, mxSheet ) );
::rtl::Reference< ScVbaSheetObjectsBase > &rxButtons = bOptionButtons ? mxButtons[0] : mxButtons[1];
if( !rxButtons.is() )
rxButtons.set( new ScVbaButtons( this, mxContext, mxModel, mxSheet, bOptionButtons ) );
else
mxButtons->collectShapes();
rxButtons->collectShapes();
if( rIndex.hasValue() )
return mxButtons->Item( rIndex, uno::Any() );
return uno::Any( uno::Reference< XCollection >( mxButtons.get() ) );
return rxButtons->Item( rIndex, uno::Any() );
return uno::Any( uno::Reference< XCollection >( rxButtons.get() ) );
}
uno::Any SAL_CALL
ScVbaWorksheet::Buttons( const uno::Any& rIndex )
{
return getButtons( rIndex, false );
}
uno::Any SAL_CALL
......@@ -852,9 +860,9 @@ ScVbaWorksheet::ListBoxes( const uno::Any& /*rIndex*/ )
}
uno::Any SAL_CALL
ScVbaWorksheet::OptionButtons( const uno::Any& /*rIndex*/ )
ScVbaWorksheet::OptionButtons( const uno::Any& rIndex )
{
throw uno::RuntimeException();
return getButtons( rIndex, true );
}
uno::Any SAL_CALL
......
......@@ -51,7 +51,7 @@ class ScVbaWorksheet : public WorksheetImpl_BASE
css::uno::Reference< css::frame::XModel > mxModel;
css::uno::Reference< ov::excel::XChartObjects > mxCharts;
css::uno::Reference< ov::excel::XHyperlinks > mxHlinks;
::rtl::Reference< ScVbaSheetObjectsBase > mxButtons;
::rtl::Reference< ScVbaSheetObjectsBase > mxButtons[2];
bool mbVeryHidden;
/// @throws css::uno::RuntimeException
......@@ -62,6 +62,8 @@ class ScVbaWorksheet : public WorksheetImpl_BASE
css::uno::Reference< css::container::XNameAccess > getFormControls();
css::uno::Any getControlShape( const OUString& sName );
css::uno::Any getButtons( const css::uno::Any &rIndex, bool bOptionButtons );
public:
/// @throws css::uno::RuntimeException
ScVbaWorksheet( const css::uno::Reference< ov::XHelperInterface >& xParent,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment