summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@canonical.com>2011-04-27 12:50:43 +0200
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2011-04-28 01:44:12 +0200
commit45799b46a56f6da88817ef768dbb8364c3bf93b5 (patch)
treefedbd4e53ed22f9bd53b841e6c82f0aadcf4019a
parent4f8fa401f2d8481f0fd6dba2b9d03b1d1c3cf353 (diff)
lp#754562: remove status listener upon exit
* use initialization lists * more const goodness
-rw-r--r--framework/source/lomenubar/FrameHelper.cxx116
-rw-r--r--framework/source/lomenubar/FrameHelper.hxx51
-rw-r--r--framework/source/lomenubar/MenuItemStatusListener.cxx4
-rw-r--r--framework/source/lomenubar/MenuItemStatusListener.hxx2
4 files changed, 109 insertions, 64 deletions
diff --git a/framework/source/lomenubar/FrameHelper.cxx b/framework/source/lomenubar/FrameHelper.cxx
index 8dd16f4d39..4e3e515cb8 100644
--- a/framework/source/lomenubar/FrameHelper.cxx
+++ b/framework/source/lomenubar/FrameHelper.cxx
@@ -26,6 +26,8 @@
#include "MenuItemInfo.hxx"
#include "MenuItemStatusListener.hxx"
+#include <boost/foreach.hpp>
+
#include <com/sun/star/awt/KeyEvent.hpp>
#include <com/sun/star/awt/SystemDependentXWindow.hpp>
#include <com/sun/star/awt/XSystemDependentWindowPeer.hpp>
@@ -113,6 +115,62 @@ using com::sun::star::ui::XModuleUIConfigurationManagerSupplier;
using com::sun::star::util::URL;
using com::sun::star::util::XURLTransformer;
+
+namespace
+{
+ static Sequence<Any> lcl_initArgs(const OUString& sModuleName, const Reference<XFrame> xFrame)
+ {
+ // These are the arguments needed for the XPopupMenuController
+ Sequence<Any> aResult(2);
+ PropertyValue item;
+
+ item.Name = OUString(RTL_CONSTASCII_USTRINGPARAM("ModuleName"));
+ item.Value <<= sModuleName;
+ aResult[0] <<= item;
+
+ item.Name = OUString(RTL_CONSTASCII_USTRINGPARAM("Frame"));
+ item.Value <<= xFrame;
+ aResult[1] <<= item;
+ return aResult;
+ };
+
+ struct DispatchConnection
+ {
+ Reference<XDispatch> m_xDispatch;
+ URL m_aUrl;
+ DispatchConnection(Reference<XDispatch> xDispatch, URL aUrl)
+ : m_xDispatch(xDispatch), m_aUrl(aUrl)
+ {}
+ };
+}
+
+namespace framework { namespace lomenubar
+{
+ class DispatchRegistry
+ {
+ private:
+ ::std::vector<DispatchConnection> m_vDispatchConnections;
+ const Reference<XStatusListener> m_xStatusListener;
+ public:
+ DispatchRegistry(const Reference<XStatusListener> xStatusListener)
+ : m_xStatusListener(xStatusListener)
+ {}
+ ~DispatchRegistry()
+ {
+ BOOST_FOREACH(const DispatchConnection& rConnection, m_vDispatchConnections)
+ {
+ rConnection.m_xDispatch->removeStatusListener(m_xStatusListener, rConnection.m_aUrl);
+ }
+ }
+ void Connect(Reference<XDispatch> xDispatch, URL aURL)
+ {
+ const DispatchConnection connection(xDispatch, aURL);
+ m_vDispatchConnections.push_back(connection);
+ xDispatch->addStatusListener(m_xStatusListener, aURL);
+ }
+ };
+}}
+
// ------------------------ Item callbacks ---------------------------
// Item activated. It distpatches the command associated to a given menu item.
void
@@ -198,31 +256,30 @@ destroy_menu_item_info (gpointer data)
FrameHelper::FrameHelper(const Reference< XMultiServiceFactory >& rServiceManager,
const Reference< XFrame >& xFrame,
DbusmenuServer* server)
+ : m_xStatusListener(new MenuItemStatusListener(this))
+ , m_pDispatchRegistry(new framework::lomenubar::DispatchRegistry(m_xStatusListener))
+ , m_xMSF(rServiceManager)
+ , m_xTrans(m_xMSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer" ))), UNO_QUERY)
+ , m_xMM(m_xMSF->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.ModuleManager"))),UNO_QUERY)
+ , m_xPCF(m_xMSF->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.PopupMenuControllerFactory"))), UNO_QUERY)
+ , m_xFrame(xFrame)
+ , m_xdp(xFrame, UNO_QUERY)
+ , m_args(lcl_initArgs(m_xMM->identify(xFrame), xFrame))
+ , m_server(server)
+ , m_root(NULL)
+ , m_watcher_set(FALSE)
+ , m_blockDetach(FALSE)
{
- m_xMSF = rServiceManager;
- this->m_xFrame = xFrame;
- this->m_server = server;
//Get xUICommands database (to retrieve labels, see FrameJob::getLabelFromCommandURL ())
Reference < XNameAccess > xNameAccess (m_xMSF->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.UICommandDescription"))),
UNO_QUERY);
- m_xMM = Reference < XModuleManager> (m_xMSF->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.ModuleManager"))),
- UNO_QUERY);
xNameAccess->getByName(m_xMM->identify(xFrame)) >>= m_xUICommands;
- m_xdp = Reference < XDispatchProvider > (xFrame, UNO_QUERY);
- m_xTrans = Reference < XURLTransformer > (m_xMSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer" ))), UNO_QUERY);
- m_xSL = (XStatusListener*)new MenuItemStatusListener (this);
-
// This initializes the shortcut database
getAcceleratorConfigurations (xFrame->getController()->getModel (), m_xMM);
- // This information is needed for the dynamic submenus
- m_xPCF = Reference < XMultiComponentFactory > (m_xMSF->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.PopupMenuControllerFactory"))),
- UNO_QUERY);
-
-
// This is a hash table that maps Command URLs to MenuItemInfo classes
// to cache command information
m_commandsInfo = g_hash_table_new_full (g_str_hash,
@@ -230,24 +287,6 @@ FrameHelper::FrameHelper(const Reference< XMultiServiceFactory >& rServiceManag
g_free,
destroy_menu_item_info);
- // These are the arguments needed for the XPopupMenuController
- m_args = Sequence < Any > (2);
- PropertyValue item;
-
- item.Name = OUString(RTL_CONSTASCII_USTRINGPARAM("ModuleName"));
- item.Value <<= m_xMM->identify (xFrame);
- m_args[0] <<= item;
-
- item.Name = OUString(RTL_CONSTASCII_USTRINGPARAM("Frame"));
- item.Value <<= xFrame;
- m_args[1] <<= item;
-
- m_root = NULL;
- m_watcher_set = FALSE;
-
- //This variable prevents the helper from being disconnected from the frame
- //for special cases of component dettaching like print preview
- m_blockDetach = FALSE;
}
void SAL_CALL
@@ -256,6 +295,7 @@ FrameHelper::disposing (const EventObject& /*aEvent*/ ) throw (RuntimeException)
FrameHelper::~FrameHelper()
{
+ ::boost::scoped_ptr< ::framework::lomenubar::DispatchRegistry>().swap(m_pDispatchRegistry);
if (m_server)
g_object_unref (m_server);
@@ -291,12 +331,6 @@ FrameHelper::getFrame ()
return m_xFrame;
}
-XStatusListener*
-FrameHelper::getStatusListener ()
-{
- return m_xSL;
-}
-
GHashTable*
FrameHelper::getCommandsInfo ()
{
@@ -540,9 +574,9 @@ FrameHelper::rebuildMenu (Reference < XMenu > xMenu,
commandURL.Complete = oUCommand;
m_xTrans->parseStrict (commandURL);
- Reference < XDispatch > xDispatch = m_xdp->queryDispatch (commandURL, OUString(), 0);
- if (xDispatch.is())
- xDispatch->addStatusListener (m_xSL, commandURL);
+ Reference < XDispatch > xDispatch = m_xdp->queryDispatch (commandURL, OUString(), 0);
+ if(xDispatch.is())
+ m_pDispatchRegistry->Connect(xDispatch, commandURL);
Reference < XPopupMenu > subPopMenu (xMenu->getPopupMenu (id), UNO_QUERY);
diff --git a/framework/source/lomenubar/FrameHelper.hxx b/framework/source/lomenubar/FrameHelper.hxx
index 9c37a08020..478ccdf8a1 100644
--- a/framework/source/lomenubar/FrameHelper.hxx
+++ b/framework/source/lomenubar/FrameHelper.hxx
@@ -24,24 +24,28 @@
#ifndef __FRAME_HELPER_HXX__
#define __FRAME_HELPER_HXX__
+#include <vector>
+
+#include <boost/scoped_ptr.hpp>
+
#include <com/sun/star/awt/KeyEvent.hpp>
#include <com/sun/star/awt/XMenu.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
-#include <com/sun/star/frame/XFrame.hpp>
-#include <com/sun/star/frame/XFramesSupplier.hpp>
-#include <com/sun/star/frame/FrameSearchFlag.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/frame/XFrameActionListener.hpp>
-#include <com/sun/star/frame/XStatusListener.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/frame/FrameAction.hpp>
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
-#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XFrameActionListener.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
#include <com/sun/star/frame/XModel.hpp>
-#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/frame/XStatusListener.hpp>
#include <com/sun/star/lang/EventObject.hpp>
-#include <com/sun/star/container/XNameAccess.hpp>
-#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <cppuhelper/implbase1.hxx>
//#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
@@ -73,6 +77,12 @@ using com::sun::star::util::XURLTransformer;
using com::sun::star::ui::XAcceleratorConfiguration;
using rtl::OUString;
+
+namespace framework { namespace lomenubar
+{
+ class DispatchRegistry;
+}}
+
/* This class is a helper in charge of closing the dbusmenu server when a frame is closed,
* and also allows the menuitem callbacks to dispatch commands.
*/
@@ -80,23 +90,25 @@ using rtl::OUString;
class FrameHelper : public cppu::WeakImplHelper1 < XFrameActionListener >
{
private:
- Reference < XFrame > m_xFrame;
- Reference < XMultiServiceFactory > m_xMSF;
+ const Reference < XStatusListener > m_xStatusListener;
+ ::boost::scoped_ptr< ::framework::lomenubar::DispatchRegistry> m_pDispatchRegistry;
+ const Reference < XMultiServiceFactory > m_xMSF;
+ const Reference < XURLTransformer > m_xTrans;
+ const Reference < XModuleManager> m_xMM;
+ const Reference < XMultiComponentFactory > m_xPCF;
+ const Reference < XFrame > m_xFrame;
+ const Reference < XDispatchProvider > m_xdp;
+ const Sequence < Any > m_args;
Reference < XNameAccess > m_xUICommands;
DbusmenuServer *m_server;
DbusmenuMenuitem *m_root;
gboolean m_watcher_set;
guint m_watcher;
- XStatusListener *m_xSL;
- Reference < XURLTransformer > m_xTrans;
- Reference < XDispatchProvider > m_xdp;
GHashTable *m_commandsInfo;
+ //This variable prevents the helper from being disconnected from the frame
+ //for special cases of component dettaching like print preview
gboolean m_blockDetach;
- //These object/methods are used to recreate dynamic popupmenus
- Reference < XMultiComponentFactory > m_xPCF;
- Reference < XModuleManager> m_xMM;
- Sequence < Any > m_args;
gboolean isSpecialSubmenu (OUString command);
@@ -131,7 +143,6 @@ class FrameHelper : public cppu::WeakImplHelper1 < XFrameActionListener >
Reference < XFrame > getFrame ();
unsigned long getXID ();
GHashTable* getCommandsInfo ();
- XStatusListener* getStatusListener ();
::rtl::OUString getLabelFromCommandURL (::rtl::OUString);
//Menu Related actions
diff --git a/framework/source/lomenubar/MenuItemStatusListener.cxx b/framework/source/lomenubar/MenuItemStatusListener.cxx
index 7989c9b111..5ff67db460 100644
--- a/framework/source/lomenubar/MenuItemStatusListener.cxx
+++ b/framework/source/lomenubar/MenuItemStatusListener.cxx
@@ -6,9 +6,9 @@
using com::sun::star::frame::status::Visibility;
MenuItemStatusListener::MenuItemStatusListener (FrameHelper *helper)
+ : m_helper(helper)
{
- if (!helper) throw ("FrameHelper cannot be NULL");
- this->m_helper = helper;
+ OSL_ENSURE(m_helper, "FrameHelper cannot be NULL");
}
void SAL_CALL
diff --git a/framework/source/lomenubar/MenuItemStatusListener.hxx b/framework/source/lomenubar/MenuItemStatusListener.hxx
index df0353739c..7fdab64ad2 100644
--- a/framework/source/lomenubar/MenuItemStatusListener.hxx
+++ b/framework/source/lomenubar/MenuItemStatusListener.hxx
@@ -19,7 +19,7 @@ class MenuItemStatusListener : public cppu::WeakImplHelper1 < XStatusListener >
{
private:
guint16 m_id;
- FrameHelper *m_helper;
+ FrameHelper* const m_helper;
public:
MenuItemStatusListener (FrameHelper *helper);