Kaydet (Commit) 94adb80e authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

Refactor a bit of the presentation minimizer

This was originally just about getting rid of the resource leak.
Turned out to include a little refactoring to hide most of the
UnoDialog member variables.

* use cppu::component_getFactoryHelper
* free leaked createPeer resources in destructor

Change-Id: I45449c49e32af4935908b801ed9bd9732af944d3
Reviewed-on: https://gerrit.libreoffice.org/73565
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
(cherry picked from commit e2cb51bf)
Reviewed-on: https://gerrit.libreoffice.org/73621
üst 47caedee
...@@ -232,7 +232,7 @@ void InformationDialog::InitDialog() ...@@ -232,7 +232,7 @@ void InformationDialog::InitDialog()
Sequence< OUString > aNames( pNames, nCount ); Sequence< OUString > aNames( pNames, nCount );
Sequence< Any > aValues( pValues, nCount ); Sequence< Any > aValues( pValues, nCount );
mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues ); setPropertyValues(aNames, aValues);
sal_Int64 nSource = mnSourceSize; sal_Int64 nSource = mnSourceSize;
sal_Int64 nDest = mnDestSize; sal_Int64 nDest = mnDestSize;
...@@ -315,11 +315,6 @@ InformationDialog::InformationDialog( const Reference< XComponentContext > &rxCo ...@@ -315,11 +315,6 @@ InformationDialog::InformationDialog( const Reference< XComponentContext > &rxCo
mrbOpenNewDocument( rbOpenNewDocument ), mrbOpenNewDocument( rbOpenNewDocument ),
maSaveAsURL( rSaveAsURL ) maSaveAsURL( rSaveAsURL )
{ {
Reference< XFrame > xFrame( mxController->getFrame() );
Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW );
createWindowPeer( xWindowPeer );
InitDialog(); InitDialog();
} }
......
...@@ -77,7 +77,7 @@ void OptimizerDialog::InitDialog() ...@@ -77,7 +77,7 @@ void OptimizerDialog::InitDialog()
Sequence< OUString > aNames( pNames, nCount ); Sequence< OUString > aNames( pNames, nCount );
Sequence< Any > aValues( pValues, nCount ); Sequence< Any > aValues( pValues, nCount );
mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues ); setPropertyValues(aNames, aValues);
} }
...@@ -111,7 +111,7 @@ void OptimizerDialog::InitRoadmap() ...@@ -111,7 +111,7 @@ void OptimizerDialog::InitRoadmap()
Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW ); Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW );
xPropertySet->setPropertyValue( "Name", Any( OUString("rdmNavi") ) ); xPropertySet->setPropertyValue( "Name", Any( OUString("rdmNavi") ) );
mxRoadmapControl = mxDialog->getControl( "rdmNavi" ); mxRoadmapControl = getControl( "rdmNavi" );
InsertRoadmapItem( 0, getString( STR_INTRODUCTION ), ITEM_ID_INTRODUCTION ); InsertRoadmapItem( 0, getString( STR_INTRODUCTION ), ITEM_ID_INTRODUCTION );
InsertRoadmapItem( 1, getString( STR_SLIDES ), ITEM_ID_SLIDES ); InsertRoadmapItem( 1, getString( STR_SLIDES ), ITEM_ID_SLIDES );
InsertRoadmapItem( 2, getString( STR_IMAGE_OPTIMIZATION ), ITEM_ID_GRAPHIC_OPTIMIZATION ); InsertRoadmapItem( 2, getString( STR_IMAGE_OPTIMIZATION ), ITEM_ID_GRAPHIC_OPTIMIZATION );
...@@ -234,7 +234,7 @@ OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxContex ...@@ -234,7 +234,7 @@ OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxContex
OptimizerDialog::~OptimizerDialog() OptimizerDialog::~OptimizerDialog()
{ {
// not saving configuration if the dialog has been finished via cancel or close window // not saving configuration if the dialog has been finished via cancel or close window
if ( mbStatus ) if ( endStatus() )
SaveConfiguration(); SaveConfiguration();
} }
...@@ -317,9 +317,6 @@ OUString OptimizerDialog::GetSelectedString( OUString const & token ) ...@@ -317,9 +317,6 @@ OUString OptimizerDialog::GetSelectedString( OUString const & token )
void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::PropertyValue >& rStatus ) void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::PropertyValue >& rStatus )
{ {
if ( !mxReschedule.is() )
return;
maStats.InitializeStatusValues( rStatus ); maStats.InitializeStatusValues( rStatus );
const Any* pVal( maStats.GetStatusValue( TK_Status ) ); const Any* pVal( maStats.GetStatusValue( TK_Status ) );
if ( pVal ) if ( pVal )
...@@ -342,7 +339,7 @@ void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::Proper ...@@ -342,7 +339,7 @@ void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::Proper
if ( pVal ) if ( pVal )
SetConfigProperty( TK_OpenNewDocument, *pVal ); SetConfigProperty( TK_OpenNewDocument, *pVal );
mxReschedule->reschedule(); reschedule();
} }
...@@ -507,7 +504,7 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent ) ...@@ -507,7 +504,7 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent )
// generating default file name // generating default file name
OUString aName; OUString aName;
Reference< XStorable > xStorable( mrOptimizerDialog.mxController->getModel(), UNO_QUERY ); Reference< XStorable > xStorable( mrOptimizerDialog.controller()->getModel(), UNO_QUERY );
if ( xStorable.is() && xStorable->hasLocation() ) if ( xStorable.is() && xStorable->hasLocation() )
{ {
INetURLObject aURLObj( xStorable->getLocation() ); INetURLObject aURLObj( xStorable->getLocation() );
...@@ -547,17 +544,14 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent ) ...@@ -547,17 +544,14 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent )
} }
// waiting for 500ms // waiting for 500ms
if ( mrOptimizerDialog.mxReschedule.is() ) mrOptimizerDialog.reschedule();
{ for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
mrOptimizerDialog.mxReschedule->reschedule(); mrOptimizerDialog.reschedule();
for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
mrOptimizerDialog.mxReschedule->reschedule();
}
} }
else else
{ {
// Apply changes to current presentation // Apply changes to current presentation
Reference<XModifiable> xModifiable(mrOptimizerDialog.mxController->getModel(), Reference<XModifiable> xModifiable(mrOptimizerDialog.controller()->getModel(),
UNO_QUERY_THROW ); UNO_QUERY_THROW );
if ( xModifiable->isModified() ) if ( xModifiable->isModified() )
{ {
......
...@@ -123,13 +123,12 @@ void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL, ...@@ -123,13 +123,12 @@ void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
OUString sResult( sBuf.makeStringAndClear() ); OUString sResult( sBuf.makeStringAndClear() );
SAL_INFO("sdext.minimizer", sResult ); SAL_INFO("sdext.minimizer", sResult );
} }
delete mpOptimizerDialog;
mpOptimizerDialog = nullptr;
} }
catch( ... ) catch( ... )
{ {
} }
delete mpOptimizerDialog;
mpOptimizerDialog = nullptr;
} }
else if ( rURL.Path == "statusupdate" ) else if ( rURL.Path == "statusupdate" )
{ {
......
...@@ -17,44 +17,27 @@ ...@@ -17,44 +17,27 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <osl/thread.h>
#include <cppuhelper/factory.hxx> #include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XSingleComponentFactory.hpp> #include <cppuhelper/implementationentry.hxx>
#include "pppoptimizerdialog.hxx" #include "pppoptimizerdialog.hxx"
using namespace ::cppu; namespace
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::registry;
extern "C"
{ {
SAL_DLLPUBLIC_EXPORT void* pptminimizer_component_getFactory(
const sal_Char * pImplName, void * pServiceManager,
SAL_UNUSED_PARAMETER void * /*pRegistryKey*/ )
{
OUString aImplName( OUString::createFromAscii( pImplName ) );
void* pRet = nullptr;
if( pServiceManager ) static cppu::ImplementationEntry const services[] = {
{ { &PPPOptimizerDialog_createInstance,
Reference< XSingleComponentFactory > xFactory; &PPPOptimizerDialog_getImplementationName,
if( aImplName == PPPOptimizerDialog_getImplementationName() ) &PPPOptimizerDialog_getSupportedServiceNames,
{ &cppu::createSingleComponentFactory, nullptr, 0 },
xFactory = createSingleComponentFactory( { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } };
PPPOptimizerDialog_createInstance,
OUString::createFromAscii( pImplName ), }
PPPOptimizerDialog_getSupportedServiceNames() );
} extern "C" SAL_DLLPUBLIC_EXPORT void * pptminimizer_component_getFactory(
if( xFactory.is() ) char const * pImplName, void * pServiceManager, void * pRegistryKey)
{ {
xFactory->acquire(); return cppu::component_getFactoryHelper(
pRet = xFactory.get(); pImplName, pServiceManager, pRegistryKey, services);
}
}
return pRet;
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "unodialog.hxx" #include "unodialog.hxx"
#include <com/sun/star/awt/MessageBoxButtons.hpp> #include <com/sun/star/awt/MessageBoxButtons.hpp>
#include <com/sun/star/awt/Toolkit.hpp> #include <com/sun/star/awt/Toolkit.hpp>
#include <com/sun/star/awt/UnoControlDialog.hpp> #include <com/sun/star/awt/UnoControlDialog.hpp>
...@@ -56,17 +57,24 @@ UnoDialog::UnoDialog( const Reference< XComponentContext > &rxContext, Reference ...@@ -56,17 +57,24 @@ UnoDialog::UnoDialog( const Reference< XComponentContext > &rxContext, Reference
Reference< XFrame > xFrame( mxController->getFrame() ); Reference< XFrame > xFrame( mxController->getFrame() );
Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() ); Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
mxWindowPeer.set( xContainerWindow, UNO_QUERY_THROW ); Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW );
createWindowPeer( mxWindowPeer );
} // set the main loop handle to update GUI while busy
Reference< XToolkit > xToolkit( Toolkit::create( mxContext ), UNO_QUERY_THROW );
mxReschedule.set( xToolkit, UNO_QUERY );
// allocate the real window resources
mxDialog->createPeer(xToolkit,
xWindowPeer.is() ? xWindowPeer : xToolkit->getDesktopWindow());
}
UnoDialog::~UnoDialog() UnoDialog::~UnoDialog()
{ {
// free the resources
Reference<XComponent> xDialogComponent(mxDialog, UNO_QUERY_THROW);
xDialogComponent->dispose();
} }
void UnoDialog::execute() void UnoDialog::execute()
{ {
mxDialog->setEnable( true ); mxDialog->setEnable( true );
...@@ -80,20 +88,6 @@ void UnoDialog::endExecute( bool bStatus ) ...@@ -80,20 +88,6 @@ void UnoDialog::endExecute( bool bStatus )
mxDialog->endExecute(); mxDialog->endExecute();
} }
Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > const & xParentPeer )
{
mxDialog->setVisible( false );
Reference< XToolkit > xToolkit( Toolkit::create( mxContext ), UNO_QUERY_THROW );
mxReschedule.set( xToolkit, UNO_QUERY );
mxDialog->createPeer(
xToolkit,
xParentPeer.is() ? xParentPeer : xToolkit->getDesktopWindow());
// xWindowPeer = xControl.getPeer();
return mxDialog->getPeer();
}
Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName, Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName,
const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues ) const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
{ {
......
...@@ -59,9 +59,6 @@ public: ...@@ -59,9 +59,6 @@ public:
void execute(); void execute();
void endExecute( bool bStatus ); void endExecute( bool bStatus );
/// @throws css::uno::Exception
css::uno::Reference< css::awt::XWindowPeer > createWindowPeer( css::uno::Reference< css::awt::XWindowPeer > const & xParentPeer );
css::uno::Reference< css::uno::XInterface > insertControlModel( const OUString& rServiceName, const OUString& rName, css::uno::Reference< css::uno::XInterface > insertControlModel( const OUString& rServiceName, const OUString& rName,
const css::uno::Sequence< OUString >& rPropertyNames, const css::uno::Sequence< css::uno::Any >& rPropertyValues ); const css::uno::Sequence< OUString >& rPropertyNames, const css::uno::Sequence< css::uno::Any >& rPropertyValues );
...@@ -98,10 +95,19 @@ public: ...@@ -98,10 +95,19 @@ public:
void enableControl( const OUString& rControlName ); void enableControl( const OUString& rControlName );
void disableControl( const OUString& rControlName ); void disableControl( const OUString& rControlName );
void reschedule() const { mxReschedule->reschedule(); }
bool endStatus() const { return mbStatus; }
css::uno::Reference<css::awt::XControl> getControl(const OUString& rControlName) const { return mxDialog->getControl(rControlName); }
css::uno::Reference<css::frame::XController> controller() const { return mxController; }
void setPropertyValues(const css::uno::Sequence<OUString>& rNameSeq, const css::uno::Sequence<css::uno::Any>& rValueSeq)
{ mxDialogModelMultiPropertySet->setPropertyValues(rNameSeq, rValueSeq); }
protected:
css::uno::Reference< css::uno::XComponentContext > mxContext; css::uno::Reference< css::uno::XComponentContext > mxContext;
css::uno::Reference< css::frame::XController > mxController; css::uno::Reference< css::frame::XController > mxController;
css::uno::Reference< css::awt::XReschedule > mxReschedule;
private:
css::uno::Reference< css::awt::XReschedule > mxReschedule;
css::uno::Reference< css::uno::XInterface > mxDialogModel; css::uno::Reference< css::uno::XInterface > mxDialogModel;
css::uno::Reference< css::beans::XMultiPropertySet > mxDialogModelMultiPropertySet; css::uno::Reference< css::beans::XMultiPropertySet > mxDialogModelMultiPropertySet;
css::uno::Reference< css::lang::XMultiServiceFactory > mxDialogModelMSF; css::uno::Reference< css::lang::XMultiServiceFactory > mxDialogModelMSF;
...@@ -112,8 +118,6 @@ public: ...@@ -112,8 +118,6 @@ public:
css::uno::Reference< css::awt::XUnoControlDialog > mxDialog; css::uno::Reference< css::awt::XUnoControlDialog > mxDialog;
css::uno::Reference< css::awt::XControl > mxControl; css::uno::Reference< css::awt::XControl > mxControl;
css::uno::Reference< css::awt::XWindowPeer > mxWindowPeer;
bool mbStatus; bool mbStatus;
}; };
......
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