summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Voitenko <mav@openoffice.org>2003-03-19 07:35:38 +0000
committerMikhail Voitenko <mav@openoffice.org>2003-03-19 07:35:38 +0000
commitb9dc9f9a522ffa816fc3dcef9a0b4f24fa2c8c76 (patch)
treecd33a13f69ea0db4d7ef597b55c3c8bd8448758b
parent0744f579c54cf02c7e581eab49ded1e184919140 (diff)
#i2822# office termination
-rw-r--r--embedserv/source/embed/docholder.cxx74
-rwxr-xr-xembedserv/source/embed/ed_ipersiststr.cxx7
-rw-r--r--embedserv/source/inc/docholder.hxx22
3 files changed, 92 insertions, 11 deletions
diff --git a/embedserv/source/embed/docholder.cxx b/embedserv/source/embed/docholder.cxx
index 8e91d4a1c631..bcf19ef457c0 100644
--- a/embedserv/source/embed/docholder.cxx
+++ b/embedserv/source/embed/docholder.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: docholder.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: mav $ $Date: 2003-03-12 15:37:57 $
+ * last change: $Author: mav $ $Date: 2003-03-19 08:35:37 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -61,6 +61,9 @@
#include "docholder.hxx"
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
#ifndef _COM_SUN_STAR_UTIL_XCLOSEBROADCASTER_HPP_
#include <com/sun/star/util/XCloseBroadcaster.hpp>
#endif
@@ -70,20 +73,68 @@
#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
#include <com/sun/star/frame/XModel.hpp>
#endif
+#ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_
+#include <com/sun/star/frame/XDesktop.hpp>
+#endif
+#ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPPLIER_HPP_
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#endif
+#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#endif
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
using namespace ::com::sun::star;
// add mutex locking ???
-DocumentHolder::DocumentHolder()
+DocumentHolder::DocumentHolder( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+: m_xFactory( xFactory )
{
+ const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
+ uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
+ if ( xDesktop.is() )
+ xDesktop->addTerminateListener( (frame::XTerminateListener*)this );
}
DocumentHolder::~DocumentHolder()
{
if ( m_xDocument.is() )
CloseDocument();
+
+ if ( m_xFactory.is() )
+ FreeOffice();
+}
+
+void DocumentHolder::FreeOffice()
+{
+ const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
+ uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
+ if ( xDesktop.is() )
+ {
+ xDesktop->removeTerminateListener( (frame::XTerminateListener*)this );
+
+ uno::Reference< frame::XFramesSupplier > xFramesSupplier( xDesktop, uno::UNO_QUERY );
+ if ( xFramesSupplier.is() )
+ {
+ uno::Reference< frame::XFrames > xFrames = xFramesSupplier->getFrames();
+ if ( xFrames.is() && !xFrames->hasElements() )
+ {
+ try
+ {
+ xDesktop->terminate();
+ }
+ catch( uno::Exception & )
+ {}
+ }
+ }
+
+ m_xFactory = uno::Reference< lang::XMultiServiceFactory >();
+ }
}
void DocumentHolder::CloseDocument()
@@ -143,3 +194,20 @@ void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource )
m_xDocument = uno::Reference< frame::XModel >();
}
+void SAL_CALL DocumentHolder::queryTermination( const lang::EventObject& aSource )
+ throw( frame::TerminationVetoException )
+{
+ if ( m_xDocument.is() )
+ throw frame::TerminationVetoException();
+}
+
+void SAL_CALL DocumentHolder::notifyTermination( const lang::EventObject& aSource )
+{
+ OSL_ENSURE( !m_xDocument.is(), "Just a disaster..." );
+
+ uno::Reference< frame::XDesktop > xDesktop( aSource.Source, uno::UNO_QUERY );
+
+ if ( xDesktop.is() )
+ xDesktop->removeTerminateListener( (frame::XTerminateListener*)this );
+}
+
diff --git a/embedserv/source/embed/ed_ipersiststr.cxx b/embedserv/source/embed/ed_ipersiststr.cxx
index 4fd5ff5ba033..69cc8ebb08e4 100755
--- a/embedserv/source/embed/ed_ipersiststr.cxx
+++ b/embedserv/source/embed/ed_ipersiststr.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ed_ipersiststr.cxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: mav $ $Date: 2003-03-17 11:02:34 $
+ * last change: $Author: mav $ $Date: 2003-03-19 08:35:37 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -227,13 +227,14 @@ EmbedDocument_Impl::EmbedDocument_Impl( const uno::Reference< lang::XMultiServic
, m_bIsDirty( sal_False )
, m_nAdviseNum( 0 )
{
- m_pDocHolder = new DocumentHolder();
+ m_pDocHolder = new DocumentHolder( xFactory );
m_pDocHolder->acquire();
}
EmbedDocument_Impl::~EmbedDocument_Impl()
{
m_pDocHolder->CloseDocument();
+ m_pDocHolder->FreeOffice();
m_pDocHolder->release();
}
diff --git a/embedserv/source/inc/docholder.hxx b/embedserv/source/inc/docholder.hxx
index c1efb278a093..a24f1c7145fb 100644
--- a/embedserv/source/inc/docholder.hxx
+++ b/embedserv/source/inc/docholder.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: docholder.hxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: mav $ $Date: 2003-03-12 15:37:59 $
+ * last change: $Author: mav $ $Date: 2003-03-19 08:35:38 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -67,21 +67,27 @@
#ifndef _COM_SUN_STAR_UTIL_XCLOSELISTENER_HPP_
#include <com/sun/star/util/XCloseListener.hpp>
#endif
+#ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_
+#include <com/sun/star/frame/XTerminateListener.hpp>
+#endif
#ifndef _CPPUHELPER_IMPLBASE1_HXX_
-#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase2.hxx>
#endif
-class DocumentHolder : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
+class DocumentHolder : public ::cppu::WeakImplHelper2< ::com::sun::star::util::XCloseListener,
+ ::com::sun::star::frame::XTerminateListener >
{
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xDocument;
public:
- DocumentHolder();
+ DocumentHolder( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory );
~DocumentHolder();
void SetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xDoc );
void CloseDocument();
+ void FreeOffice();
::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > GetDocument() { return m_xDocument; }
@@ -94,6 +100,12 @@ public:
virtual void SAL_CALL notifyClosing( const com::sun::star::lang::EventObject& aSource );
+// XTerminateListener
+ virtual void SAL_CALL queryTermination( const com::sun::star::lang::EventObject& aSource )
+ throw( ::com::sun::star::frame::TerminationVetoException );
+
+ virtual void SAL_CALL notifyTermination( const com::sun::star::lang::EventObject& aSource );
+
};
#endif