[Libreoffice-commits] .: 7 commits - dbaccess/Library_dbu.mk dbaccess/Library_dbui.mk dbaccess/source sc/source sd/source sfx2/source sw/source unotools/Library_utl.mk unotools/Package_inc.mk unotools/inc unotools/source vcl/Library_vclplug_gtk3.mk vcl/generic vcl/source

Michael Stahl mst at kemper.freedesktop.org
Wed Nov 2 14:02:20 PDT 2011


 dbaccess/Library_dbu.mk                  |    1 
 dbaccess/Library_dbui.mk                 |    1 
 dbaccess/source/ui/app/AppController.cxx |    4 
 dbaccess/source/ui/app/closeveto.cxx     |  183 -------------------------------
 dbaccess/source/ui/app/closeveto.hxx     |   70 -----------
 sc/source/ui/unoobj/docuno.cxx           |   15 ++
 sd/source/ui/view/DocumentRenderer.cxx   |   17 +-
 sfx2/source/view/viewprn.cxx             |   23 +++
 sw/source/ui/uno/unotxdoc.cxx            |   15 ++
 unotools/Library_utl.mk                  |    1 
 unotools/Package_inc.mk                  |    1 
 unotools/inc/unotools/closeveto.hxx      |   70 +++++++++++
 unotools/source/misc/closeveto.cxx       |  183 +++++++++++++++++++++++++++++++
 vcl/Library_vclplug_gtk3.mk              |    2 
 vcl/generic/app/geninst.cxx              |    1 
 vcl/source/gdi/print3.cxx                |   22 +++
 16 files changed, 337 insertions(+), 272 deletions(-)

New commits:
commit 543c57eb87cf3f37c36c0f3d8cf669d9acbb9286
Merge: 75fe0e0... 75f77e6...
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Nov 2 21:58:35 2011 +0100

    Merge branch 'master' of git://anongit.freedesktop.org/libreoffice/core

commit 75fe0e01d9ea7f6c832c75e3d074bea3f17a36ae
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Nov 2 18:12:33 2011 +0100

    Library_vclplug_gtk3.mk: fix typo

diff --git a/vcl/Library_vclplug_gtk3.mk b/vcl/Library_vclplug_gtk3.mk
index 9c589ff..d328e81 100644
--- a/vcl/Library_vclplug_gtk3.mk
+++ b/vcl/Library_vclplug_gtk3.mk
@@ -79,7 +79,7 @@ $(eval $(call gb_Library_add_linked_libs,vclplug_gtk3,\
     $(gb_STDLIBS) \
 ))
 
-$(eval $(call gb_Library_use_externals,vclplug_gtk,\
+$(eval $(call gb_Library_use_externals,vclplug_gtk3,\
 	dbus \
 ))
 
commit 66d9925bb6e9c43aacfe9e4ac6f1ee10a8e25166
Merge: b2254d5... f6f5c89...
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Nov 2 17:49:42 2011 +0100

    Merge branch 'master' of git://anongit.freedesktop.org/libreoffice/core

commit b2254d5d6fde8c28501e99e29bc824e935a25247
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Nov 2 13:21:14 2011 +0100

    rhbz#657394: sd::DocumentRenderer:
    
    Closing an Impress document while it is printing results in the document
    being destroyed, but the DocumentRenderer still retaining views that
    contain SfxItemSets that reference the document's SfxItemPool.
    Prevent the crash by retaining a SfxObjectShellRef.

diff --git a/sd/source/ui/view/DocumentRenderer.cxx b/sd/source/ui/view/DocumentRenderer.cxx
index 9966f6c..0e79d61 100644
--- a/sd/source/ui/view/DocumentRenderer.cxx
+++ b/sd/source/ui/view/DocumentRenderer.cxx
@@ -1198,13 +1198,14 @@ class DocumentRenderer::Implementation
 {
 public:
     Implementation (ViewShellBase& rBase)
-        : mrBase(rBase),
-          mbIsDisposed(false),
-          mpPrinter(NULL),
-          mpOptions(),
-          maPrinterPages(),
-          mpPrintView(),
-          mbHasOrientationWarningBeenShown(false)
+        : mxObjectShell(rBase.GetDocShell())
+        , mrBase(rBase)
+        , mbIsDisposed(false)
+        , mpPrinter(NULL)
+        , mpOptions()
+        , maPrinterPages()
+        , mpPrintView()
+        , mbHasOrientationWarningBeenShown(false)
     {
         DialogCreator aCreator( mrBase.GetDocShell()->GetDocumentType() == DOCUMENT_TYPE_IMPRESS );
         m_aUIProperties = aCreator.GetDialogControls();
@@ -1400,6 +1401,8 @@ public:
 
 
 private:
+    // rhbz#657394: keep the document alive: prevents crash when
+    SfxObjectShellRef mxObjectShell; // destroying mpPrintView
     ViewShellBase& mrBase;
     bool mbIsDisposed;
     Printer* mpPrinter;
commit d33e8d9bfecb7602b65b10d628c807e1ca2dccc2
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Nov 1 19:34:00 2011 +0100

    SalYieldMutex::release(): add assertion

diff --git a/vcl/generic/app/geninst.cxx b/vcl/generic/app/geninst.cxx
index 24f4967..f958ea6 100644
--- a/vcl/generic/app/geninst.cxx
+++ b/vcl/generic/app/geninst.cxx
@@ -65,6 +65,7 @@ void SalYieldMutex::acquire()
 
 void SalYieldMutex::release()
 {
+    OSL_ENSURE(mnCount > 0, "SalYieldMutex::release() called with zero count");
     if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
     {
         if ( mnCount == 1 )
commit 7edb1da8c566c8c17b6bf9dd4f88101c14a07df8
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Oct 31 21:18:24 2011 +0100

    move CloseVeto from dbaccess to unotools

diff --git a/dbaccess/Library_dbu.mk b/dbaccess/Library_dbu.mk
index 0f7ca59..0419c29 100644
--- a/dbaccess/Library_dbu.mk
+++ b/dbaccess/Library_dbu.mk
@@ -107,7 +107,6 @@ $(eval $(call gb_Library_add_exception_objects,dbu,\
     dbaccess/source/ui/app/AppSwapWindow \
     dbaccess/source/ui/app/AppTitleWindow \
     dbaccess/source/ui/app/AppView \
-    dbaccess/source/ui/app/closeveto \
     dbaccess/source/ui/app/subcomponentmanager \
     dbaccess/source/ui/browser/AsyncronousLink \
     dbaccess/source/ui/browser/brwctrlr \
diff --git a/dbaccess/Library_dbui.mk b/dbaccess/Library_dbui.mk
index 7a9117a..3c6bfb2 100644
--- a/dbaccess/Library_dbui.mk
+++ b/dbaccess/Library_dbui.mk
@@ -125,7 +125,6 @@ $(eval $(call gb_Library_add_exception_objects,dbui,\
 	dbaccess/source/ui/app/AppSwapWindow \
 	dbaccess/source/ui/app/AppTitleWindow \
 	dbaccess/source/ui/app/AppView \
-	dbaccess/source/ui/app/closeveto \
 	dbaccess/source/ui/app/subcomponentmanager \
 	dbaccess/source/ui/browser/genericcontroller \
 	dbaccess/source/ui/browser/dsbrowserDnD \
diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx
index e02e187..e530eae 100644
--- a/dbaccess/source/ui/app/AppController.cxx
+++ b/dbaccess/source/ui/app/AppController.cxx
@@ -33,7 +33,6 @@
 #include "dbustrings.hrc"
 #include "advancedsettingsdlg.hxx"
 #include "subcomponentmanager.hxx"
-#include "closeveto.hxx"
 
 /** === begin UNO includes === **/
 #include <com/sun/star/beans/NamedValue.hpp>
@@ -104,6 +103,7 @@
 #include <vcl/menu.hxx>
 #include <vcl/lstbox.hxx>
 
+#include <unotools/closeveto.hxx>
 #include <unotools/pathoptions.hxx>
 #include <unotools/tempfile.hxx>
 #include <unotools/internaloptions.hxx>
@@ -1962,7 +1962,7 @@ IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType )
 // -----------------------------------------------------------------------------
 void OApplicationController::newElementWithPilot( ElementType _eType )
 {
-    CloseVeto aKeepDoc( getFrame() );
+    utl::CloseVeto aKeepDoc( getFrame() );
         // prevent the document being closed while the wizard is open
 
     OSL_ENSURE( getContainer(), "OApplicationController::newElementWithPilot: without a view?" );
diff --git a/dbaccess/source/ui/app/closeveto.cxx b/dbaccess/source/ui/app/closeveto.cxx
deleted file mode 100644
index 588bdae..0000000
--- a/dbaccess/source/ui/app/closeveto.cxx
+++ /dev/null
@@ -1,183 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org.  If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#include "precompiled_dbaccess.hxx"
-
-#include "closeveto.hxx"
-
-/** === begin UNO includes === **/
-#include <com/sun/star/util/XCloseable.hpp>
-/** === end UNO includes === **/
-
-#include <cppuhelper/implbase1.hxx>
-#include <rtl/ref.hxx>
-#include <tools/diagnose_ex.h>
-
-//......................................................................................................................
-namespace dbaui
-{
-//......................................................................................................................
-
-    /** === begin UNO using === **/
-    using ::com::sun::star::uno::Reference;
-    using ::com::sun::star::uno::XInterface;
-    using ::com::sun::star::uno::UNO_QUERY;
-    using ::com::sun::star::uno::UNO_QUERY_THROW;
-    using ::com::sun::star::uno::UNO_SET_THROW;
-    using ::com::sun::star::uno::Exception;
-    using ::com::sun::star::uno::RuntimeException;
-    using ::com::sun::star::uno::Any;
-    using ::com::sun::star::uno::makeAny;
-    using ::com::sun::star::uno::Sequence;
-    using ::com::sun::star::uno::Type;
-    using ::com::sun::star::util::XCloseable;
-    using ::com::sun::star::util::XCloseListener;
-    using ::com::sun::star::util::CloseVetoException;
-    using ::com::sun::star::lang::EventObject;
-    /** === end UNO using === **/
-
-    //==================================================================================================================
-    //= CloseListener_Impl
-    //==================================================================================================================
-    typedef ::cppu::WeakImplHelper1 <   XCloseListener
-                                    >   CloseListener_Base;
-    class DBACCESS_DLLPRIVATE CloseListener_Impl : public CloseListener_Base
-    {
-    public:
-        CloseListener_Impl()
-            :m_bHasOwnership( false )
-        {
-        }
-
-        // XCloseListener
-        virtual void SAL_CALL queryClosing( const EventObject& Source, ::sal_Bool GetsOwnership ) throw (CloseVetoException, RuntimeException);
-        virtual void SAL_CALL notifyClosing( const EventObject& Source ) throw (RuntimeException);
-
-        // XEventListener
-        virtual void SAL_CALL disposing( const EventObject& Source) throw (RuntimeException);
-
-        bool hasOwnership() const { return m_bHasOwnership; }
-
-    protected:
-        ~CloseListener_Impl()
-        {
-        }
-
-    private:
-        bool    m_bHasOwnership;
-    };
-
-    //------------------------------------------------------------------------------------------------------------------
-    void SAL_CALL CloseListener_Impl::queryClosing( const EventObject& i_source, ::sal_Bool i_deliverOwnership ) throw (CloseVetoException, RuntimeException)
-    {
-        (void)i_source;
-
-        if ( !m_bHasOwnership )
-            m_bHasOwnership = i_deliverOwnership;
-
-        throw CloseVetoException();
-    }
-
-    //------------------------------------------------------------------------------------------------------------------
-    void SAL_CALL CloseListener_Impl::notifyClosing( const EventObject& i_source ) throw (RuntimeException)
-    {
-        (void)i_source;
-    }
-
-    //------------------------------------------------------------------------------------------------------------------
-    void SAL_CALL CloseListener_Impl::disposing( const EventObject& i_source ) throw (RuntimeException)
-    {
-        (void)i_source;
-    }
-
-    //==================================================================================================================
-    //= CloseVeto_Data
-    //==================================================================================================================
-    struct DBACCESS_DLLPRIVATE CloseVeto_Data
-    {
-        Reference< XCloseable >                 xCloseable;
-        ::rtl::Reference< CloseListener_Impl >  pListener;
-    };
-
-    //==================================================================================================================
-    //= operations
-    //==================================================================================================================
-    namespace
-    {
-        //--------------------------------------------------------------------------------------------------------------
-        void lcl_init( CloseVeto_Data& i_data, const Reference< XInterface >& i_closeable )
-        {
-            i_data.xCloseable.set( i_closeable, UNO_QUERY );
-            ENSURE_OR_RETURN_VOID( i_data.xCloseable.is(), "CloseVeto: the component is not closeable!" );
-
-            i_data.pListener = new CloseListener_Impl;
-            i_data.xCloseable->addCloseListener( i_data.pListener.get() );
-        }
-
-        //--------------------------------------------------------------------------------------------------------------
-        void lcl_deinit( CloseVeto_Data& i_data )
-        {
-            if ( !i_data.xCloseable.is() )
-                return;
-
-            i_data.xCloseable->removeCloseListener( i_data.pListener.get() );
-            if ( i_data.pListener->hasOwnership() )
-            {
-                try
-                {
-                    i_data.xCloseable->close( sal_True );
-                }
-                catch( const CloseVetoException& ) { }
-                catch( const Exception& )
-                {
-                    DBG_UNHANDLED_EXCEPTION();
-                }
-            }
-        }
-    }
-
-    //==================================================================================================================
-    //= CloseVeto
-    //==================================================================================================================
-    //------------------------------------------------------------------------------------------------------------------
-    CloseVeto::CloseVeto( const Reference< XInterface >& i_closeable )
-        :m_pData( new CloseVeto_Data )
-    {
-        lcl_init( *m_pData, i_closeable );
-    }
-
-    //------------------------------------------------------------------------------------------------------------------
-    CloseVeto::~CloseVeto()
-    {
-        lcl_deinit( *m_pData );
-    }
-
-//......................................................................................................................
-} // namespace dbaui
-//......................................................................................................................
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/ui/app/closeveto.hxx b/dbaccess/source/ui/app/closeveto.hxx
deleted file mode 100644
index a9f1d6b..0000000
--- a/dbaccess/source/ui/app/closeveto.hxx
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org.  If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef DBACCESS_CLOSEVETO_HXX
-#define DBACCESS_CLOSEVETO_HXX
-
-#include "dbaccessdllapi.h"
-
-/** === begin UNO includes === **/
-#include <com/sun/star/uno/XInterface.hpp>
-/** === end UNO includes === **/
-
-#include <boost/scoped_ptr.hpp>
-
-//......................................................................................................................
-namespace dbaui
-{
-//......................................................................................................................
-
-    //==================================================================================================================
-    //= CloseVeto
-    //==================================================================================================================
-    struct CloseVeto_Data;
-    /** will add a XCloseListener to a given component, and veto its closing as long as the <code>CloseVeto</code>
-        instance is alive.
-
-        If closing has been requested and vetoed while the <code>CloseVeto</code> instance is alive, and the ownership
-        went to the <code>CloseVeto</code> instance, then it will close the component in its dtor.
-    */
-    class DBACCESS_DLLPRIVATE CloseVeto
-    {
-    public:
-        CloseVeto( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& i_closeable );
-        ~CloseVeto();
-
-    private:
-        ::boost::scoped_ptr< CloseVeto_Data >   m_pData;
-    };
-
-//......................................................................................................................
-} // namespace dbaui
-//......................................................................................................................
-
-#endif // DBACCESS_CLOSEVETO_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotools/Library_utl.mk b/unotools/Library_utl.mk
index 9d97708..3937493 100644
--- a/unotools/Library_utl.mk
+++ b/unotools/Library_utl.mk
@@ -131,6 +131,7 @@ $(eval $(call gb_Library_add_exception_objects,utl,\
     unotools/source/i18n/textsearch \
     unotools/source/i18n/transliterationwrapper \
     unotools/source/misc/atom \
+    unotools/source/misc/closeveto \
     unotools/source/misc/componentresmodule \
     unotools/source/misc/datetime \
     unotools/source/misc/desktopterminationobserver \
diff --git a/unotools/Package_inc.mk b/unotools/Package_inc.mk
index d1e177d..2c62667 100644
--- a/unotools/Package_inc.mk
+++ b/unotools/Package_inc.mk
@@ -37,6 +37,7 @@ $(eval $(call gb_Package_add_file,unotools_inc,inc/unotools/cacheoptions.hxx,uno
 $(eval $(call gb_Package_add_file,unotools_inc,inc/unotools/calendarwrapper.hxx,unotools/calendarwrapper.hxx))
 $(eval $(call gb_Package_add_file,unotools_inc,inc/unotools/caserotate.hxx,unotools/caserotate.hxx))
 $(eval $(call gb_Package_add_file,unotools_inc,inc/unotools/charclass.hxx,unotools/charclass.hxx))
+$(eval $(call gb_Package_add_file,unotools_inc,inc/unotools/closeveto.hxx,unotools/closeveto.hxx))
 $(eval $(call gb_Package_add_file,unotools_inc,inc/unotools/cmdoptions.hxx,unotools/cmdoptions.hxx))
 $(eval $(call gb_Package_add_file,unotools_inc,inc/unotools/collatorwrapper.hxx,unotools/collatorwrapper.hxx))
 $(eval $(call gb_Package_add_file,unotools_inc,inc/unotools/compatibility.hxx,unotools/compatibility.hxx))
diff --git a/unotools/inc/unotools/closeveto.hxx b/unotools/inc/unotools/closeveto.hxx
new file mode 100644
index 0000000..1fddd43
--- /dev/null
+++ b/unotools/inc/unotools/closeveto.hxx
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef UNOTOOLS_CLOSEVETO_HXX
+#define UNOTOOLS_CLOSEVETO_HXX
+
+#include "unotools/unotoolsdllapi.h"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/uno/XInterface.hpp>
+/** === end UNO includes === **/
+
+#include <boost/scoped_ptr.hpp>
+
+//......................................................................................................................
+namespace utl
+{
+//......................................................................................................................
+
+    //==================================================================================================================
+    //= CloseVeto
+    //==================================================================================================================
+    struct CloseVeto_Data;
+    /** will add a XCloseListener to a given component, and veto its closing as long as the <code>CloseVeto</code>
+        instance is alive.
+
+        If closing has been requested and vetoed while the <code>CloseVeto</code> instance is alive, and the ownership
+        went to the <code>CloseVeto</code> instance, then it will close the component in its dtor.
+    */
+    class UNOTOOLS_DLLPUBLIC CloseVeto
+    {
+    public:
+        CloseVeto( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& i_closeable );
+        ~CloseVeto();
+
+    private:
+        ::boost::scoped_ptr< CloseVeto_Data >   m_pData;
+    };
+
+//......................................................................................................................
+} // namespace dbaui
+//......................................................................................................................
+
+#endif // UNOTOOLS_CLOSEVETO_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotools/source/misc/closeveto.cxx b/unotools/source/misc/closeveto.cxx
new file mode 100644
index 0000000..7a61a89
--- /dev/null
+++ b/unotools/source/misc/closeveto.cxx
@@ -0,0 +1,183 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_unotools.hxx"
+
+#include <unotools/closeveto.hxx>
+
+/** === begin UNO includes === **/
+#include <com/sun/star/util/XCloseable.hpp>
+/** === end UNO includes === **/
+
+#include <cppuhelper/implbase1.hxx>
+#include <rtl/ref.hxx>
+#include <tools/diagnose_ex.h>
+
+//......................................................................................................................
+namespace utl
+{
+//......................................................................................................................
+
+    /** === begin UNO using === **/
+    using ::com::sun::star::uno::Reference;
+    using ::com::sun::star::uno::XInterface;
+    using ::com::sun::star::uno::UNO_QUERY;
+    using ::com::sun::star::uno::UNO_QUERY_THROW;
+    using ::com::sun::star::uno::UNO_SET_THROW;
+    using ::com::sun::star::uno::Exception;
+    using ::com::sun::star::uno::RuntimeException;
+    using ::com::sun::star::uno::Any;
+    using ::com::sun::star::uno::makeAny;
+    using ::com::sun::star::uno::Sequence;
+    using ::com::sun::star::uno::Type;
+    using ::com::sun::star::util::XCloseable;
+    using ::com::sun::star::util::XCloseListener;
+    using ::com::sun::star::util::CloseVetoException;
+    using ::com::sun::star::lang::EventObject;
+    /** === end UNO using === **/
+
+    //==================================================================================================================
+    //= CloseListener_Impl
+    //==================================================================================================================
+    typedef ::cppu::WeakImplHelper1 <   XCloseListener
+                                    >   CloseListener_Base;
+    class SAL_DLLPRIVATE CloseListener_Impl : public CloseListener_Base
+    {
+    public:
+        CloseListener_Impl()
+            :m_bHasOwnership( false )
+        {
+        }
+
+        // XCloseListener
+        virtual void SAL_CALL queryClosing( const EventObject& Source, ::sal_Bool GetsOwnership ) throw (CloseVetoException, RuntimeException);
+        virtual void SAL_CALL notifyClosing( const EventObject& Source ) throw (RuntimeException);
+
+        // XEventListener
+        virtual void SAL_CALL disposing( const EventObject& Source) throw (RuntimeException);
+
+        bool hasOwnership() const { return m_bHasOwnership; }
+
+    protected:
+        ~CloseListener_Impl()
+        {
+        }
+
+    private:
+        bool    m_bHasOwnership;
+    };
+
+    //------------------------------------------------------------------------------------------------------------------
+    void SAL_CALL CloseListener_Impl::queryClosing( const EventObject& i_source, ::sal_Bool i_deliverOwnership ) throw (CloseVetoException, RuntimeException)
+    {
+        (void)i_source;
+
+        if ( !m_bHasOwnership )
+            m_bHasOwnership = i_deliverOwnership;
+
+        throw CloseVetoException();
+    }
+
+    //------------------------------------------------------------------------------------------------------------------
+    void SAL_CALL CloseListener_Impl::notifyClosing( const EventObject& i_source ) throw (RuntimeException)
+    {
+        (void)i_source;
+    }
+
+    //------------------------------------------------------------------------------------------------------------------
+    void SAL_CALL CloseListener_Impl::disposing( const EventObject& i_source ) throw (RuntimeException)
+    {
+        (void)i_source;
+    }
+
+    //==================================================================================================================
+    //= CloseVeto_Data
+    //==================================================================================================================
+    struct SAL_DLLPRIVATE CloseVeto_Data
+    {
+        Reference< XCloseable >                 xCloseable;
+        ::rtl::Reference< CloseListener_Impl >  pListener;
+    };
+
+    //==================================================================================================================
+    //= operations
+    //==================================================================================================================
+    namespace
+    {
+        //--------------------------------------------------------------------------------------------------------------
+        void lcl_init( CloseVeto_Data& i_data, const Reference< XInterface >& i_closeable )
+        {
+            i_data.xCloseable.set( i_closeable, UNO_QUERY );
+            ENSURE_OR_RETURN_VOID( i_data.xCloseable.is(), "CloseVeto: the component is not closeable!" );
+
+            i_data.pListener = new CloseListener_Impl;
+            i_data.xCloseable->addCloseListener( i_data.pListener.get() );
+        }
+
+        //--------------------------------------------------------------------------------------------------------------
+        void lcl_deinit( CloseVeto_Data& i_data )
+        {
+            if ( !i_data.xCloseable.is() )
+                return;
+
+            i_data.xCloseable->removeCloseListener( i_data.pListener.get() );
+            if ( i_data.pListener->hasOwnership() )
+            {
+                try
+                {
+                    i_data.xCloseable->close( sal_True );
+                }
+                catch( const CloseVetoException& ) { }
+                catch( const Exception& )
+                {
+                    DBG_UNHANDLED_EXCEPTION();
+                }
+            }
+        }
+    }
+
+    //==================================================================================================================
+    //= CloseVeto
+    //==================================================================================================================
+    //------------------------------------------------------------------------------------------------------------------
+    CloseVeto::CloseVeto( const Reference< XInterface >& i_closeable )
+        :m_pData( new CloseVeto_Data )
+    {
+        lcl_init( *m_pData, i_closeable );
+    }
+
+    //------------------------------------------------------------------------------------------------------------------
+    CloseVeto::~CloseVeto()
+    {
+        lcl_deinit( *m_pData );
+    }
+
+//......................................................................................................................
+} // namespace utl
+//......................................................................................................................
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 17f1adc78adf3b8b943dc36882855b901259d4c1
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Oct 31 20:07:00 2011 +0100

    rhbz#657394: crash closing document while printing
    
    - XRenderable implementation in SwXTextDocument and ScModelObj
      throw DisposedExceptions instead of RuntimeExceptions
    - SfxPrinterController catches DisposedException and aborts printing
    - vcl::PrinterController checks that the printing was not aborted

diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 4d4d588..7332eda 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -934,7 +934,10 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount( const uno::Any& aSelection,
 {
     SolarMutexGuard aGuard;
     if (!pDocShell)
-        throw uno::RuntimeException();
+    {
+        throw lang::DisposedException( ::rtl::OUString(),
+                static_cast< sheet::XSpreadsheetDocument* >(this) );
+    }
 
     ScMarkData aMark;
     ScPrintSelectionStatus aStatus;
@@ -982,7 +985,10 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
 {
     SolarMutexGuard aGuard;
     if (!pDocShell)
-        throw uno::RuntimeException();
+    {
+        throw lang::DisposedException( ::rtl::OUString(),
+                static_cast< sheet::XSpreadsheetDocument* >(this) );
+    }
 
     ScMarkData aMark;
     ScPrintSelectionStatus aStatus;
@@ -1089,7 +1095,10 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
 {
     SolarMutexGuard aGuard;
     if (!pDocShell)
-        throw uno::RuntimeException();
+    {
+        throw lang::DisposedException( ::rtl::OUString(),
+                static_cast< sheet::XSpreadsheetDocument* >(this) );
+    }
 
     ScMarkData aMark;
     ScPrintSelectionStatus aStatus;
diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index 70c98d6..628c356 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -238,7 +238,16 @@ int SfxPrinterController::getPageCount() const
     if( mxRenderable.is() && pPrinter )
     {
         Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() );
-        nPages = mxRenderable->getRendererCount( getSelectionObject(), aJobOptions );
+        try
+        {
+            nPages = mxRenderable->getRendererCount( getSelectionObject(), aJobOptions );
+        }
+        catch (lang::DisposedException &)
+        {
+            OSL_TRACE("SfxPrinterController: document disposed while printing");
+            const_cast<SfxPrinterController*>(this)->setJobState(
+                    view::PrintableState_JOB_ABORTED);
+        }
     }
     return nPages;
 }
@@ -258,6 +267,12 @@ Sequence< beans::PropertyValue > SfxPrinterController::getPageParameters( int i_
         catch( lang::IllegalArgumentException& )
         {
         }
+        catch (lang::DisposedException &)
+        {
+            OSL_TRACE("SfxPrinterController: document disposed while printing");
+            const_cast<SfxPrinterController*>(this)->setJobState(
+                    view::PrintableState_JOB_ABORTED);
+        }
     }
     return aResult;
 }
@@ -277,6 +292,12 @@ void SfxPrinterController::printPage( int i_nPage ) const
             // don't care enough about nonexistant page here
             // to provoke a crash
         }
+        catch (lang::DisposedException &)
+        {
+            OSL_TRACE("SfxPrinterController: document disposed while printing");
+            const_cast<SfxPrinterController*>(this)->setJobState(
+                    view::PrintableState_JOB_ABORTED);
+        }
     }
 }
 
diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx
index 43f2400..c849fa7 100644
--- a/sw/source/ui/uno/unotxdoc.cxx
+++ b/sw/source/ui/uno/unotxdoc.cxx
@@ -2469,7 +2469,10 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
 {
     SolarMutexGuard aGuard;
     if(!IsValid())
-        throw RuntimeException();
+    {
+        throw DisposedException( ::rtl::OUString(),
+                static_cast< XTextDocument* >(this) );
+    }
 
     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
     bool bIsSwSrcView = false;
@@ -2633,7 +2636,10 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
 {
     SolarMutexGuard aGuard;
     if(!IsValid())
-        throw RuntimeException();
+    {
+        throw DisposedException( ::rtl::OUString(),
+                static_cast< XTextDocument* >(this) );
+    }
 
     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
     bool bIsSwSrcView = false;
@@ -2840,7 +2846,10 @@ void SAL_CALL SwXTextDocument::render(
 {
     SolarMutexGuard aGuard;
     if(!IsValid())
-        throw RuntimeException();
+    {
+        throw DisposedException( ::rtl::OUString(),
+                static_cast< XTextDocument* >(this) );
+    }
 
     // due to #110067# (document page count changes sometimes during
     // PDF export/printing) we can not check for the upper bound properly.
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index 6365b20..c2b0e87 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -626,6 +626,10 @@ bool Printer::StartJob( const rtl::OUString& i_rJobName, boost::shared_ptr<vcl::
                             if( i_pController->isProgressCanceled() )
                             {
                                 i_pController->abortJob();
+                            }
+                            if (i_pController->getJobState() ==
+                                    view::PrintableState_JOB_ABORTED)
+                            {
                                 bAborted = true;
                             }
                         }
@@ -865,6 +869,11 @@ PrinterController::PageSize PrinterController::getPageFile( int i_nUnfilteredPag
     Sequence< PropertyValue > aPageParm( getPageParametersProtected( i_nUnfilteredPage ) );
     const MapMode aMapMode( MAP_100TH_MM );
 
+    if (mpImplData->meJobState != view::PrintableState_JOB_STARTED)
+    {   // rhbz#657394: check that we are still printing...
+        return PrinterController::PageSize();
+    }
+
     mpImplData->mpPrinter->Push();
     mpImplData->mpPrinter->SetMapMode( aMapMode );
 
@@ -951,6 +960,10 @@ PrinterController::PageSize PrinterController::getFilteredPageFile( int i_nFilte
         rMPS.nTopMargin == 0 && rMPS.nBottomMargin == 0 )
     {
         PrinterController::PageSize aPageSize = getPageFile( i_nFilteredPage, o_rMtf, i_bMayUseCache );
+        if (mpImplData->meJobState != view::PrintableState_JOB_STARTED)
+        {   // rhbz#657394: check that we are still printing...
+            return PrinterController::PageSize();
+        }
         Size aPaperSize = mpImplData->getRealPaperSize( aPageSize.aSize, true );
         mpImplData->mpPrinter->SetMapMode( MapMode( MAP_100TH_MM ) );
         mpImplData->mpPrinter->SetPaperSizeUser( aPaperSize, ! mpImplData->isFixedPageSize() );
@@ -996,6 +1009,10 @@ PrinterController::PageSize PrinterController::getFilteredPageFile( int i_nFilte
     o_rMtf.AddAction( new MetaMapModeAction( MapMode( MAP_100TH_MM ) ) );
 
     int nDocPages = getPageCountProtected();
+    if (mpImplData->meJobState != view::PrintableState_JOB_STARTED)
+    {   // rhbz#657394: check that we are still printing...
+        return PrinterController::PageSize();
+    }
     for( int nSubPage = 0; nSubPage < nSubPages; nSubPage++ )
     {
         // map current sub page to real page
@@ -1143,6 +1160,11 @@ void PrinterController::printFilteredPage( int i_nPage )
     GDIMetaFile aPageFile;
     PrinterController::PageSize aPageSize = getFilteredPageFile( i_nPage, aPageFile );
 
+    if (mpImplData->meJobState != view::PrintableState_JOB_STARTED)
+    {   // rhbz#657394: check that we are still printing...
+        return;
+    }
+
     if( mpImplData->mpProgress )
     {
         // do nothing if printing is canceled


More information about the Libreoffice-commits mailing list