From e36f83d81c462e1a5959b160886e481a8d449494 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 24 May 2013 22:44:30 +0200 Subject: Revert "fdo#46808, Convert awt::UnoControlDialogModel to new style" This reverts commit 6c61b20a8d4a6dcac28801cde82a211fb7e30654. As discussed at "Re: fdo#46808, Convert awt::UnoControlDialogModel to new style problem" why the odd change in 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again" appears to fix things again: The problem is that the implementation of the css.awt.UnoControlDialogModel involves UNO aggregation (IMPL_CREATE_INSTANCE_WITH_GEOMETRY(UnoControlDialogModel) in toolkit/soruce/helper/registerservices.cxx creating a OGeometryControlModel instance that aggregates a UnoControlDialogModel instance). That means that queryInterface can return a reference to something that is technically a different object, and that's what's happening here, and explains why calling setPropertyValue in two different ways on what logically appears to be a single object can end up calling two different implementations (of two different physical objects). (UNO aggregation is known to be broken and should not be used. Nevertheless, there's still code that does---code that is a horrible mess and hard to clean up.) That all this worked as intended in the past is just sheer luck, but any way of substantially touching it is asking for trouble. I'm going to revert 6c61b20a8d4a6dcac28801cde82a211fb7e30654 again. I wasn't able to revert without also reverting be50ad28f5bbdaeff527f646481ce263843c2401 "fdo#46808, Convert awt::XUnoControlDialog to new style," as the two were tightly dependant. Also reverts all the follow-up fixes cb4b6dde8fda2a5848e11063028bf44d72f85431 "-Werror,-Wuninitialized" (sans the const-ness fix in UpdateHandler::insertControlModel), 697a007c61b9cabceb9767fad87cd5822b300452 "Fix exception specifications," 2ce6828bbbf6ba181bb2276adeec279e74151ef6 "fix awt::UnoControlModelDialog crash," and 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again." Conflicts: basctl/source/dlged/dlged.cxx filter/source/t602/t602filter.cxx xmlscript/test/imexp.cxx Change-Id: I5d133468062f3ca36300db52fbd699be1ac72998 --- sdext/source/minimizer/informationdialog.cxx | 31 ++++++++--- sdext/source/minimizer/optimizerdialog.cxx | 35 +++++++++---- sdext/source/minimizer/unodialog.cxx | 78 ++++++++++++++++------------ sdext/source/minimizer/unodialog.hxx | 20 +++++-- 4 files changed, 109 insertions(+), 55 deletions(-) (limited to 'sdext') diff --git a/sdext/source/minimizer/informationdialog.cxx b/sdext/source/minimizer/informationdialog.cxx index 5c51ae28392b..babba10cfaf1 100644 --- a/sdext/source/minimizer/informationdialog.cxx +++ b/sdext/source/minimizer/informationdialog.cxx @@ -216,13 +216,30 @@ void InformationDialog::InitDialog() nDialogHeight -= 22; // setting the dialog properties - mxDialogModel->setCloseable(sal_True); - mxDialogModel->setHeight(nDialogHeight); - mxDialogModel->setMoveable(sal_True); - mxDialogModel->setPositionX(245); - mxDialogModel->setPositionY(115); - mxDialogModel->setTitle(getString( STR_SUN_OPTIMIZATION_WIZARD2 )); - mxDialogModel->setWidth(sal_Int32( DIALOG_WIDTH ) ); + OUString pNames[] = { + TKGet( TK_Closeable ), + TKGet( TK_Height ), + TKGet( TK_Moveable ), + TKGet( TK_PositionX ), + TKGet( TK_PositionY ), + TKGet( TK_Title ), + TKGet( TK_Width ) }; + + Any pValues[] = { + Any( sal_True ), + Any( nDialogHeight ), + Any( sal_True ), + Any( sal_Int32( 245 ) ), + Any( sal_Int32( 115 ) ), + Any( getString( STR_SUN_OPTIMIZATION_WIZARD2 ) ), + Any( sal_Int32( DIALOG_WIDTH ) ) }; + + sal_Int32 nCount = SAL_N_ELEMENTS( pNames ); + + Sequence< OUString > aNames( pNames, nCount ); + Sequence< Any > aValues( pValues, nCount ); + + mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues ); sal_Int64 nSource = mnSourceSize; sal_Int64 nDest = mnDestSize; diff --git a/sdext/source/minimizer/optimizerdialog.cxx b/sdext/source/minimizer/optimizerdialog.cxx index 0a3ff9551e44..d6c73488725d 100644 --- a/sdext/source/minimizer/optimizerdialog.cxx +++ b/sdext/source/minimizer/optimizerdialog.cxx @@ -52,13 +52,30 @@ using namespace ::com::sun::star::container; void OptimizerDialog::InitDialog() { // setting the dialog properties - mxDialogModel->setCloseable(sal_True); - mxDialogModel->setHeight(sal_Int32( DIALOG_HEIGHT )); - mxDialogModel->setMoveable(sal_True); - mxDialogModel->setPositionX(200); - mxDialogModel->setPositionY(52); - mxDialogModel->setTitle(getString( STR_SUN_OPTIMIZATION_WIZARD2 )); - mxDialogModel->setWidth(sal_Int32( OD_DIALOG_WIDTH ) ); + OUString pNames[] = { + TKGet( TK_Closeable ), + TKGet( TK_Height ), + TKGet( TK_Moveable ), + TKGet( TK_PositionX ), + TKGet( TK_PositionY ), + TKGet( TK_Title ), + TKGet( TK_Width ) }; + + Any pValues[] = { + Any( sal_True ), + Any( sal_Int32( DIALOG_HEIGHT ) ), + Any( sal_True ), + Any( sal_Int32( 200 ) ), + Any( sal_Int32( 52 ) ), + Any( getString( STR_SUN_OPTIMIZATION_WIZARD2 ) ), + Any( sal_Int32( OD_DIALOG_WIDTH ) ) }; + + sal_Int32 nCount = SAL_N_ELEMENTS( pNames ); + + Sequence< OUString > aNames( pNames, nCount ); + Sequence< Any > aValues( pValues, nCount ); + + mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues ); } // ----------------------------------------------------------------------------- @@ -93,7 +110,7 @@ void OptimizerDialog::InitRoadmap() Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW ); xPropertySet->setPropertyValue( TKGet( TK_Name ), Any( TKGet( TK_rdmNavi ) ) ); - mxRoadmapControl = mxDialog->getControl( TKGet( TK_rdmNavi ) ); + mxRoadmapControl = mxDialogControlContainer->getControl( TKGet( TK_rdmNavi ) ); InsertRoadmapItem( 0, sal_True, getString( STR_INTRODUCTION ), ITEM_ID_INTRODUCTION ); InsertRoadmapItem( 1, sal_True, getString( STR_SLIDES ), ITEM_ID_SLIDES ); InsertRoadmapItem( 2, sal_True, getString( STR_IMAGE_OPTIMIZATION ), ITEM_ID_GRAPHIC_OPTIMIZATION ); @@ -505,7 +522,7 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent ) if ( nInt16 ) { OUString aSaveAsURL; - FileOpenDialog aFileOpenDialog( ((UnoDialog&)mrOptimizerDialog).mxContext ); + FileOpenDialog aFileOpenDialog( ((UnoDialog&)mrOptimizerDialog).mxMSF ); // generating default file name Reference< XStorable > xStorable( mrOptimizerDialog.mxController->getModel(), UNO_QUERY ); diff --git a/sdext/source/minimizer/unodialog.cxx b/sdext/source/minimizer/unodialog.cxx index 3bf603c474ba..922527e2a88d 100644 --- a/sdext/source/minimizer/unodialog.cxx +++ b/sdext/source/minimizer/unodialog.cxx @@ -19,17 +19,15 @@ #include "unodialog.hxx" -#include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include #include #include +#include +#include +#include +#include // ------------- // - UnoDialog - @@ -45,14 +43,26 @@ using namespace ::com::sun::star::frame; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::script; -UnoDialog::UnoDialog( const Reference< XComponentContext > &rxContext, Reference< XFrame >& rxFrame ) : - mxContext( rxContext ), +UnoDialog::UnoDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame ) : + mxMSF( rxMSF ), mxController( rxFrame->getController() ), - mxDialogModel( UnoControlDialogModel::create(rxContext) ), - mxDialog( UnoControlDialog::create(rxContext) ), + mxDialogModel( mxMSF->getServiceManager()->createInstanceWithContext( OUString( + "com.sun.star.awt.UnoControlDialogModel" ), mxMSF ), UNO_QUERY_THROW ), + mxDialogModelMultiPropertySet( mxDialogModel, UNO_QUERY_THROW ), + mxDialogModelPropertySet( mxDialogModel, UNO_QUERY_THROW ), + mxDialogModelMSF( mxDialogModel, UNO_QUERY_THROW ), + mxDialogModelNameContainer( mxDialogModel, UNO_QUERY_THROW ), + mxDialogModelNameAccess( mxDialogModel, UNO_QUERY_THROW ), + mxControlModel( mxDialogModel, UNO_QUERY_THROW ), + mxDialog( mxMSF->getServiceManager()->createInstanceWithContext( OUString( + "com.sun.star.awt.UnoControlDialog" ), mxMSF ), UNO_QUERY_THROW ), + mxControl( mxDialog, UNO_QUERY_THROW ), mbStatus( sal_False ) { - mxDialog->setModel( mxDialogModel ); + mxControl->setModel( mxControlModel ); + mxDialogControlContainer = Reference< XControlContainer >( mxDialog, UNO_QUERY_THROW ); + mxDialogComponent = Reference< XComponent >( mxDialog, UNO_QUERY_THROW ); + mxDialogWindow = Reference< XWindow >( mxDialog, UNO_QUERY_THROW ); Reference< XFrame > xFrame( mxController->getFrame() ); Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() ); @@ -71,8 +81,8 @@ UnoDialog::~UnoDialog() void UnoDialog::execute() { - mxDialog->setEnable( sal_True ); - mxDialog->setVisible( sal_True ); + mxDialogWindow->setEnable( sal_True ); + mxDialogWindow->setVisible( sal_True ); mxDialog->execute(); } @@ -87,14 +97,14 @@ void UnoDialog::endExecute( sal_Bool bStatus ) Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > xParentPeer ) throw ( Exception ) { - mxDialog->setVisible( sal_False ); - Reference< XToolkit > xToolkit( Toolkit::create( mxContext ), UNO_QUERY_THROW ); + mxDialogWindow->setVisible( sal_False ); + Reference< XToolkit > xToolkit( Toolkit::create( mxMSF ), UNO_QUERY_THROW ); if ( !xParentPeer.is() ) xParentPeer = xToolkit->getDesktopWindow(); mxReschedule = Reference< XReschedule >( xToolkit, UNO_QUERY ); - mxDialog->createPeer( xToolkit, xParentPeer ); + mxControl->createPeer( xToolkit, xParentPeer ); // xWindowPeer = xControl.getPeer(); - return mxDialog->getPeer(); + return mxControl->getPeer(); } // ----------------------------------------------------------------------------- @@ -105,10 +115,10 @@ Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceN Reference< XInterface > xControlModel; try { - xControlModel = mxDialogModel->createInstance( rServiceName ); + xControlModel = mxDialogModelMSF->createInstance( rServiceName ); Reference< XMultiPropertySet > xMultiPropSet( xControlModel, UNO_QUERY_THROW ); xMultiPropSet->setPropertyValues( rPropertyNames, rPropertyValues ); - mxDialogModel->insertByName( rName, Any( xControlModel ) ); + mxDialogModelNameContainer->insertByName( rName, Any( xControlModel ) ); } catch( Exception& ) { @@ -122,7 +132,7 @@ void UnoDialog::setVisible( const OUString& rName, sal_Bool bVisible ) { try { - Reference< XInterface > xControl( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + Reference< XInterface > xControl( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); Reference< XWindow > xWindow( xControl, UNO_QUERY_THROW ); xWindow->setVisible( bVisible ); } @@ -143,7 +153,7 @@ Reference< XButton > UnoDialog::insertButton( const OUString& rName, Reference< rName, rPropertyNames, rPropertyValues ) ); Reference< XPropertySet > xPropertySet( xButtonModel, UNO_QUERY_THROW ); xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) ); - xButton = Reference< XButton >( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + xButton = Reference< XButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); if ( xActionListener.is() ) { @@ -168,7 +178,7 @@ Reference< XFixedText > UnoDialog::insertFixedText( const OUString& rName, const Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlFixedTextModel" ), rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW ); xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) ); - xFixedText = Reference< XFixedText >( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + xFixedText = Reference< XFixedText >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); } catch ( Exception& ) { @@ -186,7 +196,7 @@ Reference< XCheckBox > UnoDialog::insertCheckBox( const OUString& rName, const S Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlCheckBoxModel" ), rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW ); xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) ); - xCheckBox = Reference< XCheckBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + xCheckBox = Reference< XCheckBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); } catch ( Exception& ) { @@ -204,7 +214,7 @@ Reference< XControl > UnoDialog::insertFormattedField( const OUString& rName, co Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlFormattedFieldModel" ), rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW ); xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) ); - xControl = Reference< XControl >( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); } catch ( Exception& ) { @@ -222,7 +232,7 @@ Reference< XComboBox > UnoDialog::insertComboBox( const OUString& rName, const S Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlComboBoxModel" ), rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW ); xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) ); - xControl = Reference< XComboBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + xControl = Reference< XComboBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); } catch ( Exception& ) { @@ -240,7 +250,7 @@ Reference< XRadioButton > UnoDialog::insertRadioButton( const OUString& rName, c Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlRadioButtonModel" ), rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW ); xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) ); - xControl = Reference< XRadioButton >( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + xControl = Reference< XRadioButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); } catch ( Exception& ) { @@ -258,7 +268,7 @@ Reference< XListBox > UnoDialog::insertListBox( const OUString& rName, const Seq Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlListBoxModel" ), rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW ); xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) ); - xControl = Reference< XListBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + xControl = Reference< XListBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); } catch ( Exception& ) { @@ -276,7 +286,7 @@ Reference< XControl > UnoDialog::insertImage( const OUString& rName, const Seque Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlImageControlModel" ), rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW ); xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) ); - xControl = Reference< XControl >( mxDialog->getControl( rName ), UNO_QUERY_THROW ); + xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW ); } catch ( Exception& ) { @@ -290,9 +300,9 @@ void UnoDialog::setControlProperty( const OUString& rControlName, const OUString { try { - if ( mxDialogModel->hasByName( rControlName ) ) + if ( mxDialogModelNameAccess->hasByName( rControlName ) ) { - Reference< XPropertySet > xPropertySet( mxDialogModel->getByName( rControlName ), UNO_QUERY_THROW ); + Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW ); xPropertySet->setPropertyValue( rPropertyName, rPropertyValue ); } } @@ -308,9 +318,9 @@ Any UnoDialog::getControlProperty( const OUString& rControlName, const OUString& Any aRet; try { - if ( mxDialogModel->hasByName( rControlName ) ) + if ( mxDialogModelNameAccess->hasByName( rControlName ) ) { - Reference< XPropertySet > xPropertySet( mxDialogModel->getByName( rControlName ), UNO_QUERY_THROW ); + Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW ); aRet = xPropertySet->getPropertyValue( rPropertyName ); } } diff --git a/sdext/source/minimizer/unodialog.hxx b/sdext/source/minimizer/unodialog.hxx index 032fe6cf47af..b08ce1e5d8fe 100644 --- a/sdext/source/minimizer/unodialog.hxx +++ b/sdext/source/minimizer/unodialog.hxx @@ -39,12 +39,10 @@ #include #include #include -#include #include #include #include #include -#include #include #include #include @@ -108,15 +106,27 @@ public : void enableControl( const OUString& rControlName ); void disableControl( const OUString& rControlName ); - com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > mxContext; + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > mxMSF; com::sun::star::uno::Reference< com::sun::star::frame::XController > mxController; com::sun::star::uno::Reference< com::sun::star::awt::XReschedule > mxReschedule; - com::sun::star::uno::Reference< com::sun::star::awt::XUnoControlDialogModel > mxDialogModel; + com::sun::star::uno::Reference< com::sun::star::uno::XInterface > mxDialogModel; + com::sun::star::uno::Reference< com::sun::star::beans::XMultiPropertySet > mxDialogModelMultiPropertySet; + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > mxDialogModelPropertySet; + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxDialogModelMSF; + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > mxDialogModelNameContainer; + com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > mxDialogModelNameAccess; - com::sun::star::uno::Reference< com::sun::star::awt::XUnoControlDialog > mxDialog; + com::sun::star::uno::Reference< com::sun::star::awt::XControlModel > mxControlModel; + + com::sun::star::uno::Reference< com::sun::star::awt::XDialog > mxDialog; + com::sun::star::uno::Reference< com::sun::star::awt::XControl > mxControl; com::sun::star::uno::Reference< com::sun::star::awt::XWindowPeer > mxWindowPeer; + com::sun::star::uno::Reference< com::sun::star::awt::XControlContainer > mxDialogControlContainer; + com::sun::star::uno::Reference< com::sun::star::lang::XComponent > mxDialogComponent; + com::sun::star::uno::Reference< com::sun::star::awt::XWindow > mxDialogWindow; + sal_Bool mbStatus; }; -- cgit