office-gobmx/vbahelper/source/msforms/vbauserform.cxx

305 lines
12 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-22 10:25:46 -05:00
/*
* This file is part of the LibreOffice project.
2009-09-18 10:35:47 -05:00
*
2012-06-22 10:25:46 -05:00
* 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/.
2009-09-18 10:35:47 -05:00
*
2012-06-22 10:25:46 -05:00
* This file incorporates work covered by the following license notice:
2009-09-18 10:35:47 -05:00
*
2012-06-22 10:25:46 -05:00
* 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 .
*/
2009-09-18 10:35:47 -05:00
#include <vbahelper/helperdecl.hxx>
#include "vbauserform.hxx"
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/awt/XControlContainer.hpp>
#include <com/sun/star/awt/PosSize.hpp>
2009-09-18 10:35:47 -05:00
#include <com/sun/star/beans/PropertyConcept.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/util/MeasureUnit.hpp>
2009-09-18 10:35:47 -05:00
#include <basic/sbx.hxx>
#include <basic/sbstar.hxx>
#include <basic/sbmeth.hxx>
#include "vbacontrols.hxx"
using namespace ::ooo::vba;
using namespace ::com::sun::star;
// some little notes
// XDialog implementation has the following interesting bits
// a Controls property ( which is an array of the container controls )
// each item in the controls array is a XControl, where the model is
// basically a property bag
// additionally the XDialog instance has itself a model
// this model has a ControlModels ( array of models ) property
// the models in ControlModels can be accessed by name
// also the XDialog is a XControl ( to access the model above
ScVbaUserForm::ScVbaUserForm( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) throw ( lang::IllegalArgumentException ) : ScVbaUserForm_BASE( getXSomethingFromArgs< XHelperInterface >( aArgs, 0 ), xContext, getXSomethingFromArgs< uno::XInterface >( aArgs, 1 ), getXSomethingFromArgs< frame::XModel >( aArgs, 2 ), static_cast< ooo::vba::AbstractGeometryAttributes* >(0) ), mbDispose( true )
{
m_xDialog.set( m_xControl, uno::UNO_QUERY_THROW );
uno::Reference< awt::XControl > xControl( m_xDialog, uno::UNO_QUERY_THROW );
m_xProps.set( xControl->getModel(), uno::UNO_QUERY_THROW );
setGeometryHelper( new UserFormGeometryHelper( xContext, xControl, 0.0, 0.0 ) );
if ( aArgs.getLength() >= 4 )
aArgs[ 3 ] >>= m_sLibName;
2009-09-18 10:35:47 -05:00
}
ScVbaUserForm::~ScVbaUserForm()
{
}
void SAL_CALL
ScVbaUserForm::Show( ) throw (uno::RuntimeException)
{
OSL_TRACE("ScVbaUserForm::Show( )");
short aRet = 0;
mbDispose = true;
2009-09-18 10:35:47 -05:00
if ( m_xDialog.is() )
{
// try to center dialog on model window
if( m_xModel.is() ) try
{
uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_SET_THROW );
uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW );
uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_SET_THROW );
awt::Rectangle aPosSize = xWindow->getPosSize(); // already in pixel
uno::Reference< awt::XControl > xControl( m_xDialog, uno::UNO_QUERY_THROW );
uno::Reference< awt::XWindow > xControlWindow( xControl->getPeer(), uno::UNO_QUERY_THROW );
xControlWindow->setPosSize(static_cast<sal_Int32>((aPosSize.Width - getWidth()) / 2.0), static_cast<sal_Int32>((aPosSize.Height - getHeight()) / 2.0), 0, 0, awt::PosSize::POS );
}
catch( uno::Exception& )
{
}
2009-09-18 10:35:47 -05:00
aRet = m_xDialog->execute();
}
2009-09-18 10:35:47 -05:00
OSL_TRACE("ScVbaUserForm::Show() execute returned %d", aRet);
if ( mbDispose )
{
try
{
uno::Reference< lang::XComponent > xComp( m_xDialog, uno::UNO_QUERY_THROW );
m_xDialog = NULL;
xComp->dispose();
mbDispose = false;
}
catch( uno::Exception& )
{
}
}
}
OUString SAL_CALL
ScVbaUserForm::getCaption() throw (uno::RuntimeException)
2009-09-18 10:35:47 -05:00
{
OUString sCaption;
2012-06-22 10:25:46 -05:00
m_xProps->getPropertyValue( "Title" ) >>= sCaption;
2009-09-18 10:35:47 -05:00
return sCaption;
}
void
ScVbaUserForm::setCaption( const OUString& _caption ) throw (uno::RuntimeException)
2009-09-18 10:35:47 -05:00
{
2012-06-22 10:25:46 -05:00
m_xProps->setPropertyValue( "Title", uno::makeAny( _caption ) );
2009-09-18 10:35:47 -05:00
}
double SAL_CALL ScVbaUserForm::getInnerWidth() throw (uno::RuntimeException)
{
return mpGeometryHelper->getInnerWidth();
}
void SAL_CALL ScVbaUserForm::setInnerWidth( double fInnerWidth ) throw (uno::RuntimeException)
{
mpGeometryHelper->setInnerWidth( fInnerWidth );
}
double SAL_CALL ScVbaUserForm::getInnerHeight() throw (uno::RuntimeException)
{
return mpGeometryHelper->getInnerHeight();
}
void SAL_CALL ScVbaUserForm::setInnerHeight( double fInnerHeight ) throw (uno::RuntimeException)
{
mpGeometryHelper->setInnerHeight( fInnerHeight );
}
2009-09-18 10:35:47 -05:00
void SAL_CALL
ScVbaUserForm::Hide( ) throw (uno::RuntimeException)
{
mbDispose = false; // hide not dispose
if ( m_xDialog.is() )
m_xDialog->endExecute();
}
void SAL_CALL
ScVbaUserForm::RePaint( ) throw (uno::RuntimeException)
{
// #STUB
2009-09-18 10:35:47 -05:00
// do nothing
}
void SAL_CALL
ScVbaUserForm::UnloadObject( ) throw (uno::RuntimeException)
{
mbDispose = true;
if ( m_xDialog.is() )
m_xDialog->endExecute();
}
OUString
2009-09-18 10:35:47 -05:00
ScVbaUserForm::getServiceImplName()
{
return OUString("ScVbaUserForm");
2009-09-18 10:35:47 -05:00
}
uno::Sequence< OUString >
2009-09-18 10:35:47 -05:00
ScVbaUserForm::getServiceNames()
{
static uno::Sequence< OUString > aServiceNames;
2009-09-18 10:35:47 -05:00
if ( aServiceNames.getLength() == 0 )
{
aServiceNames.realloc( 1 );
2012-06-22 10:25:46 -05:00
aServiceNames[ 0 ] = "ooo.vba.excel.UserForm";
2009-09-18 10:35:47 -05:00
}
return aServiceNames;
}
uno::Reference< beans::XIntrospectionAccess > SAL_CALL
ScVbaUserForm::getIntrospection( ) throw (uno::RuntimeException)
{
return uno::Reference< beans::XIntrospectionAccess >();
}
uno::Any SAL_CALL
ScVbaUserForm::invoke( const OUString& /*aFunctionName*/, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ ) throw (lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
2009-09-18 10:35:47 -05:00
{
throw uno::RuntimeException(); // unsupported operation
}
void SAL_CALL
ScVbaUserForm::setValue( const OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
2009-09-18 10:35:47 -05:00
{
uno::Any aObject = getValue( aPropertyName );
// in case the dialog is already closed the VBA implementation should not throw exceptions
if ( aObject.hasValue() )
{
// The Object *must* support XDefaultProperty here because getValue will
// only return properties that are Objects ( e.g. controls )
// e.g. Userform1.aControl = something
// 'aControl' has to support XDefaultProperty to make sense here
uno::Reference< script::XDefaultProperty > xDfltProp( aObject, uno::UNO_QUERY_THROW );
OUString aDfltPropName = xDfltProp->getDefaultPropertyName();
uno::Reference< beans::XIntrospectionAccess > xUnoAccess( getIntrospectionAccess( aObject ) );
uno::Reference< beans::XPropertySet > xPropSet( xUnoAccess->queryAdapter( ::getCppuType( (const uno::Reference< beans::XPropertySet > *)0 ) ), uno::UNO_QUERY_THROW );
xPropSet->setPropertyValue( aDfltPropName, aValue );
}
2009-09-18 10:35:47 -05:00
}
uno::Reference< awt::XControl >
ScVbaUserForm::nestedSearch( const OUString& aPropertyName, uno::Reference< awt::XControlContainer >& xContainer )
{
uno::Reference< awt::XControl > xControl = xContainer->getControl( aPropertyName );
if ( !xControl.is() )
{
uno::Sequence< uno::Reference< awt::XControl > > aControls = xContainer->getControls();
const uno::Reference< awt::XControl >* pCtrl = aControls.getConstArray();
const uno::Reference< awt::XControl >* pCtrlsEnd = pCtrl + aControls.getLength();
for ( ; pCtrl < pCtrlsEnd; ++pCtrl )
{
uno::Reference< awt::XControlContainer > xC( *pCtrl, uno::UNO_QUERY );
if ( xC.is() )
{
xControl.set( nestedSearch( aPropertyName, xC ) );
if ( xControl.is() )
break;
}
}
}
return xControl;
}
2009-09-18 10:35:47 -05:00
uno::Any SAL_CALL
ScVbaUserForm::getValue( const OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException)
2009-09-18 10:35:47 -05:00
{
uno::Any aResult;
// in case the dialog is already closed the VBA implementation should not throw exceptions
if ( m_xDialog.is() )
{
uno::Reference< awt::XControl > xDialogControl( m_xDialog, uno::UNO_QUERY_THROW );
uno::Reference< awt::XControlContainer > xContainer( m_xDialog, uno::UNO_QUERY_THROW );
uno::Reference< awt::XControl > xControl = nestedSearch( aPropertyName, xContainer );
xContainer->getControl( aPropertyName );
if ( xControl.is() )
{
Merge commit 'ooo/DEV300_m106' into integration/dev300_m106 Conflicts: avmedia/source/gstreamer/gstframegrabber.cxx avmedia/source/gstreamer/gstplayer.cxx avmedia/source/gstreamer/gstplayer.hxx basic/inc/basic/sbxdef.hxx basic/source/classes/sbxmod.cxx basic/source/comp/makefile.mk basic/source/comp/sbcomp.cxx basic/source/inc/namecont.hxx basic/source/inc/scriptcont.hxx basic/source/runtime/methods.cxx basic/source/runtime/runtime.cxx basic/source/runtime/stdobj.cxx basic/source/runtime/step1.cxx basic/source/uno/namecont.cxx basic/util/makefile.mk connectivity/source/commontools/predicateinput.cxx connectivity/source/drivers/dbase/DNoException.cxx connectivity/source/drivers/dbase/DTable.cxx connectivity/source/drivers/file/fcomp.cxx connectivity/source/drivers/jdbc/JConnection.cxx connectivity/source/drivers/odbcbase/OResultSet.cxx connectivity/source/drivers/odbcbase/OStatement.cxx connectivity/source/parse/sqlnode.cxx desktop/source/app/app.cxx drawinglayer/inc/drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx drawinglayer/source/processor2d/vclprocessor2d.cxx formula/inc/formula/token.hxx formula/source/core/api/token.cxx fpicker/source/win32/filepicker/VistaFilePickerImpl.hxx fpicker/source/win32/filepicker/platform_vista.h framework/source/helper/persistentwindowstate.cxx framework/source/uielement/menubarmanager.cxx oovbaapi/ooo/vba/XFoundFiles.idl oovbaapi/ooo/vba/excel/XApplication.idl oovbaapi/ooo/vba/msforms/XCheckBox.idl oovbaapi/ooo/vba/msforms/XComboBox.idl oovbaapi/ooo/vba/msforms/XControl.idl oovbaapi/ooo/vba/msforms/XGroupBox.idl oovbaapi/ooo/vba/msforms/XLabel.idl oovbaapi/ooo/vba/msforms/XListBox.idl oovbaapi/ooo/vba/msforms/XNewFont.idl oovbaapi/ooo/vba/msforms/XRadioButton.idl oovbaapi/ooo/vba/msforms/XTextBox.idl oovbaapi/ooo/vba/msforms/XToggleButton.idl scripting/source/dlgprov/dlgevtatt.cxx sfx2/source/control/unoctitm.cxx sfx2/source/doc/objstor.cxx sfx2/source/doc/objxtor.cxx svx/inc/svx/svdograf.hxx svx/source/form/fmpage.cxx svx/source/form/fmpgeimp.cxx svx/source/svdraw/svdedtv.cxx svx/source/svdraw/svdfmtf.cxx svx/source/svdraw/svdograf.cxx svx/source/svdraw/svdouno.cxx svx/source/xml/xmlgrhlp.cxx uui/source/iahndl-ssl.cxx vbahelper/Library_msforms.mk vbahelper/Library_vbahelper.mk vbahelper/inc/vbahelper/vbahelper.hxx vbahelper/prj/build.lst vbahelper/source/msforms/vbacombobox.cxx vbahelper/source/msforms/vbacontrol.cxx vbahelper/source/msforms/vbacontrols.cxx vbahelper/source/msforms/vbaframe.cxx vbahelper/source/msforms/vbaframe.hxx vbahelper/source/msforms/vbalabel.cxx vbahelper/source/msforms/vbalabel.hxx vbahelper/source/msforms/vbalistbox.cxx vbahelper/source/msforms/vbalistbox.hxx vbahelper/source/msforms/vbamultipage.cxx vbahelper/source/msforms/vbatogglebutton.cxx vbahelper/source/msforms/vbauserform.cxx vbahelper/source/vbahelper/vbacommandbar.cxx vbahelper/source/vbahelper/vbacommandbarcontrol.cxx vbahelper/source/vbahelper/vbacommandbarcontrols.hxx vbahelper/source/vbahelper/vbahelper.cxx vbahelper/source/vbahelper/vbawindowbase.cxx xmloff/source/meta/xmlmetai.cxx xmloff/source/style/PageMasterExportPropMapper.cxx xmloff/source/style/PageMasterStyleMap.cxx xmloff/source/text/txtexppr.cxx xmloff/source/text/txtprmap.cxx
2011-04-27 17:12:58 -05:00
uno::Reference< msforms::XControl > xVBAControl = ScVbaControlFactory::createUserformControl( mxContext, xControl, xDialogControl, m_xModel, mpGeometryHelper->getOffsetX(), mpGeometryHelper->getOffsetY() );
ScVbaControl* pControl = dynamic_cast< ScVbaControl* >( xVBAControl.get() );
if ( !m_sLibName.isEmpty() )
pControl->setLibraryAndCodeName( m_sLibName.concat( "." ).concat( getName() ) );
aResult = uno::makeAny( xVBAControl );
}
}
return aResult;
2009-09-18 10:35:47 -05:00
}
::sal_Bool SAL_CALL
ScVbaUserForm::hasMethod( const OUString& /*aName*/ ) throw (uno::RuntimeException)
2009-09-18 10:35:47 -05:00
{
return sal_False;
}
uno::Any SAL_CALL
ScVbaUserForm::Controls( const uno::Any& index ) throw (uno::RuntimeException)
{
2010-07-08 15:10:20 -05:00
// if the dialog already closed we should do nothing, but the VBA will call methods of the Controls objects
// thus we have to provide a dummy object in this case
uno::Reference< awt::XControl > xDialogControl( m_xDialog, uno::UNO_QUERY );
uno::Reference< XCollection > xControls( new ScVbaControls( this, mxContext, xDialogControl, m_xModel, mpGeometryHelper->getOffsetX(), mpGeometryHelper->getOffsetY() ) );
2009-09-18 10:35:47 -05:00
if ( index.hasValue() )
return uno::makeAny( xControls->Item( index, uno::Any() ) );
return uno::makeAny( xControls );
}
::sal_Bool SAL_CALL
ScVbaUserForm::hasProperty( const OUString& aName ) throw (uno::RuntimeException)
2009-09-18 10:35:47 -05:00
{
uno::Reference< awt::XControl > xControl( m_xDialog, uno::UNO_QUERY );
OSL_TRACE("ScVbaUserForm::hasProperty(%s) %d", OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr(), xControl.is() );
2009-09-18 10:35:47 -05:00
if ( xControl.is() )
{
uno::Reference< beans::XPropertySet > xDlgProps( xControl->getModel(), uno::UNO_QUERY );
if ( xDlgProps.is() )
{
uno::Reference< container::XNameContainer > xAllChildren( xDlgProps->getPropertyValue( "AllDialogChildren" ), uno::UNO_QUERY_THROW );
sal_Bool bRes = xAllChildren->hasByName( aName );
OSL_TRACE("ScVbaUserForm::hasProperty(%s) %d ---> %d", OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr(), xAllChildren.is(), bRes );
return bRes;
}
2009-09-18 10:35:47 -05:00
}
return sal_False;
}
namespace userform
{
namespace sdecl = comphelper::service_decl;
sdecl::vba_service_class_<ScVbaUserForm, sdecl::with_args<true> > serviceImpl;
extern sdecl::ServiceDecl const serviceDecl(
serviceImpl,
"ScVbaUserForm",
"ooo.vba.msforms.UserForm" );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */