[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - sdext/source

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Fri Jun 7 01:08:36 UTC 2019


 sdext/source/minimizer/informationdialog.cxx  |    7 ---
 sdext/source/minimizer/optimizerdialog.cxx    |   24 ++++--------
 sdext/source/minimizer/pppoptimizerdialog.cxx |    5 +-
 sdext/source/minimizer/pppoptimizeruno.cxx    |   49 ++++++++------------------
 sdext/source/minimizer/unodialog.cxx          |   32 ++++++----------
 sdext/source/minimizer/unodialog.hxx          |   16 +++++---
 6 files changed, 51 insertions(+), 82 deletions(-)

New commits:
commit 94adb80e6d5ec9d6c6b149ca98755d3a5a86531a
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Wed Jun 5 02:14:30 2019 +0000
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Fri Jun 7 03:08:02 2019 +0200

    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: Jan-Marek Glogowski <glogow at fbihome.de>
    (cherry picked from commit e2cb51bfbdc4b83ace14a5984f242c252ddd11b7)
    Reviewed-on: https://gerrit.libreoffice.org/73621

diff --git a/sdext/source/minimizer/informationdialog.cxx b/sdext/source/minimizer/informationdialog.cxx
index 4f3de61a2075..c7e136a2345b 100644
--- a/sdext/source/minimizer/informationdialog.cxx
+++ b/sdext/source/minimizer/informationdialog.cxx
@@ -232,7 +232,7 @@ void InformationDialog::InitDialog()
     Sequence< OUString >   aNames( pNames, nCount );
     Sequence< Any >             aValues( pValues, nCount );
 
-    mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues );
+    setPropertyValues(aNames, aValues);
 
     sal_Int64 nSource = mnSourceSize;
     sal_Int64 nDest   = mnDestSize;
@@ -315,11 +315,6 @@ InformationDialog::InformationDialog( const Reference< XComponentContext > &rxCo
     mrbOpenNewDocument( rbOpenNewDocument ),
     maSaveAsURL( rSaveAsURL )
 {
-    Reference< XFrame > xFrame( mxController->getFrame() );
-    Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
-    Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW );
-    createWindowPeer( xWindowPeer );
-
     InitDialog();
 }
 
diff --git a/sdext/source/minimizer/optimizerdialog.cxx b/sdext/source/minimizer/optimizerdialog.cxx
index 9df50284a29b..9746ba067a92 100644
--- a/sdext/source/minimizer/optimizerdialog.cxx
+++ b/sdext/source/minimizer/optimizerdialog.cxx
@@ -77,7 +77,7 @@ void OptimizerDialog::InitDialog()
     Sequence< OUString >   aNames( pNames, nCount );
     Sequence< Any >             aValues( pValues, nCount );
 
-    mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues );
+    setPropertyValues(aNames, aValues);
 }
 
 
@@ -111,7 +111,7 @@ void OptimizerDialog::InitRoadmap()
 
         Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW );
         xPropertySet->setPropertyValue( "Name", Any( OUString("rdmNavi") ) );
-        mxRoadmapControl = mxDialog->getControl( "rdmNavi" );
+        mxRoadmapControl = getControl( "rdmNavi" );
         InsertRoadmapItem( 0, getString( STR_INTRODUCTION ), ITEM_ID_INTRODUCTION );
         InsertRoadmapItem( 1, getString( STR_SLIDES ), ITEM_ID_SLIDES );
         InsertRoadmapItem( 2, getString( STR_IMAGE_OPTIMIZATION ), ITEM_ID_GRAPHIC_OPTIMIZATION );
@@ -234,7 +234,7 @@ OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxContex
 OptimizerDialog::~OptimizerDialog()
 {
     // not saving configuration if the dialog has been finished via cancel or close window
-    if ( mbStatus )
+    if ( endStatus() )
         SaveConfiguration();
 }
 
@@ -317,9 +317,6 @@ OUString OptimizerDialog::GetSelectedString( OUString const & token )
 
 void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::PropertyValue >& rStatus )
 {
-    if ( !mxReschedule.is() )
-        return;
-
     maStats.InitializeStatusValues( rStatus );
     const Any* pVal( maStats.GetStatusValue( TK_Status ) );
     if ( pVal )
@@ -342,7 +339,7 @@ void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::Proper
     if ( pVal )
         SetConfigProperty( TK_OpenNewDocument, *pVal );
 
-    mxReschedule->reschedule();
+    reschedule();
 }
 
 
@@ -507,7 +504,7 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent )
 
                 // generating default file name
                 OUString aName;
-                Reference< XStorable > xStorable( mrOptimizerDialog.mxController->getModel(), UNO_QUERY );
+                Reference< XStorable > xStorable( mrOptimizerDialog.controller()->getModel(), UNO_QUERY );
                 if ( xStorable.is() && xStorable->hasLocation() )
                 {
                     INetURLObject aURLObj( xStorable->getLocation() );
@@ -547,17 +544,14 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent )
                 }
 
                 // waiting for 500ms
-                if ( mrOptimizerDialog.mxReschedule.is() )
-                {
-                    mrOptimizerDialog.mxReschedule->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.reschedule();
             }
             else
             {
                 // Apply changes to current presentation
-                Reference<XModifiable> xModifiable(mrOptimizerDialog.mxController->getModel(),
+                Reference<XModifiable> xModifiable(mrOptimizerDialog.controller()->getModel(),
                                                    UNO_QUERY_THROW );
                 if ( xModifiable->isModified() )
                 {
diff --git a/sdext/source/minimizer/pppoptimizerdialog.cxx b/sdext/source/minimizer/pppoptimizerdialog.cxx
index 90baad21091b..1c8cf4b2c6b0 100644
--- a/sdext/source/minimizer/pppoptimizerdialog.cxx
+++ b/sdext/source/minimizer/pppoptimizerdialog.cxx
@@ -123,13 +123,12 @@ void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
                 OUString sResult( sBuf.makeStringAndClear() );
                 SAL_INFO("sdext.minimizer", sResult );
             }
-            delete mpOptimizerDialog;
-            mpOptimizerDialog = nullptr;
         }
         catch( ... )
         {
-
         }
+        delete mpOptimizerDialog;
+        mpOptimizerDialog = nullptr;
     }
     else if ( rURL.Path == "statusupdate" )
     {
diff --git a/sdext/source/minimizer/pppoptimizeruno.cxx b/sdext/source/minimizer/pppoptimizeruno.cxx
index 361291d8e85d..d972ab716060 100644
--- a/sdext/source/minimizer/pppoptimizeruno.cxx
+++ b/sdext/source/minimizer/pppoptimizeruno.cxx
@@ -17,44 +17,27 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-
-#include <osl/thread.h>
 #include <cppuhelper/factory.hxx>
-#include <com/sun/star/lang/XSingleComponentFactory.hpp>
+#include <cppuhelper/implementationentry.hxx>
 #include "pppoptimizerdialog.hxx"
 
-using namespace ::cppu;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::registry;
-
-extern "C"
+namespace
 {
-    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 )
-        {
-            Reference< XSingleComponentFactory > xFactory;
-            if( aImplName == PPPOptimizerDialog_getImplementationName() )
-            {
-                xFactory = createSingleComponentFactory(
-                        PPPOptimizerDialog_createInstance,
-                        OUString::createFromAscii( pImplName ),
-                        PPPOptimizerDialog_getSupportedServiceNames() );
-            }
-            if( xFactory.is() )
-            {
-                xFactory->acquire();
-                pRet = xFactory.get();
-            }
-        }
-        return pRet;
-    }
+static cppu::ImplementationEntry const services[] = {
+    { &PPPOptimizerDialog_createInstance,
+      &PPPOptimizerDialog_getImplementationName,
+      &PPPOptimizerDialog_getSupportedServiceNames,
+      &cppu::createSingleComponentFactory, nullptr, 0 },
+    { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } };
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT void * pptminimizer_component_getFactory(
+    char const * pImplName, void * pServiceManager, void * pRegistryKey)
+{
+    return cppu::component_getFactoryHelper(
+        pImplName, pServiceManager, pRegistryKey, services);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/minimizer/unodialog.cxx b/sdext/source/minimizer/unodialog.cxx
index a99240926614..878395e26ec3 100644
--- a/sdext/source/minimizer/unodialog.cxx
+++ b/sdext/source/minimizer/unodialog.cxx
@@ -19,6 +19,7 @@
 
 
 #include "unodialog.hxx"
+
 #include <com/sun/star/awt/MessageBoxButtons.hpp>
 #include <com/sun/star/awt/Toolkit.hpp>
 #include <com/sun/star/awt/UnoControlDialog.hpp>
@@ -56,17 +57,24 @@ UnoDialog::UnoDialog( const Reference< XComponentContext > &rxContext, Reference
 
     Reference< XFrame > xFrame( mxController->getFrame() );
     Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
-    mxWindowPeer.set( xContainerWindow, UNO_QUERY_THROW );
-    createWindowPeer( mxWindowPeer );
-}
+    Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW );
+
+    // 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()
 {
-
+    // free the resources
+    Reference<XComponent> xDialogComponent(mxDialog, UNO_QUERY_THROW);
+    xDialogComponent->dispose();
 }
 
-
 void UnoDialog::execute()
 {
     mxDialog->setEnable( true );
@@ -80,20 +88,6 @@ void UnoDialog::endExecute( bool bStatus )
     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,
                                                         const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
 {
diff --git a/sdext/source/minimizer/unodialog.hxx b/sdext/source/minimizer/unodialog.hxx
index 1903f2da7fdb..0022932f2416 100644
--- a/sdext/source/minimizer/unodialog.hxx
+++ b/sdext/source/minimizer/unodialog.hxx
@@ -59,9 +59,6 @@ public:
     void execute();
     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,
         const css::uno::Sequence< OUString >& rPropertyNames, const css::uno::Sequence< css::uno::Any >& rPropertyValues );
 
@@ -98,10 +95,19 @@ public:
     void enableControl( 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::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::beans::XMultiPropertySet >      mxDialogModelMultiPropertySet;
     css::uno::Reference< css::lang::XMultiServiceFactory >    mxDialogModelMSF;
@@ -112,8 +118,6 @@ public:
 
     css::uno::Reference< css::awt::XUnoControlDialog >        mxDialog;
     css::uno::Reference< css::awt::XControl >                 mxControl;
-    css::uno::Reference< css::awt::XWindowPeer >              mxWindowPeer;
-
     bool                                                                        mbStatus;
 };
 


More information about the Libreoffice-commits mailing list