1
#include "MenuItemStatusListener.h"
2
#include "MenuItemInfo.h"
1
#include "MenuItemStatusListener.hxx"
2
#include "MenuItemInfo.hxx"
4
4
#include <com/sun/star/frame/status/Visibility.hpp>
6
6
using com::sun::star::frame::status::Visibility;
8
8
MenuItemStatusListener::MenuItemStatusListener (FrameHelper *helper)
10
if (!helper) throw ("FrameHelper cannot be NULL");
11
this->helper = helper;
11
OSL_ENSURE(m_helper, "FrameHelper cannot be NULL");
15
15
MenuItemStatusListener::statusChanged(const FeatureStateEvent& Event)
16
16
throw (RuntimeException)
20
OUString url = Event.FeatureURL.Complete;
23
gchar* c_url = g_utf16_to_utf8 (url.getStr(),
27
GHashTable *commandsInfo = helper->getCommandsInfo ();
28
MenuItemInfo *info = (MenuItemInfo*)g_hash_table_lookup (commandsInfo, (gpointer)c_url);
31
info = new MenuItemInfo ();
32
g_hash_table_insert (commandsInfo, c_url, info);
34
//Set the default label
35
oULabel = helper->getLabelFromCommandURL(url);
36
// Replace tilde with underscore for Dbusmenu Alt accelerators
37
oULabel = oULabel.replace ((sal_Unicode)0x007e, (sal_Unicode)0x005f);
39
// GLib behaves better than OUStringToOString wrt encoding transformation
40
gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
43
info->setLabel (label);
48
//Since we're not introducing it in the hash table, we get rid of this string
52
//We set the enabled/disabled state
53
info->setEnabled ((gboolean)Event.IsEnabled);
55
//We find out what the new state is by casting
57
//For some reason, URLs can slip through as labels, we make sure
58
//this doesn't happen.
59
if ((Event.State >>= oULabel) &&
60
!oULabel.matchAsciiL ("private:", 8, 0) &&
61
!oULabel.matchAsciiL (".uno:", 5, 0) &&
62
!oULabel.matchAsciiL ("slot:", 5, 0) &&
63
!oULabel.matchAsciiL ("service:", 8, 0) &&
64
!oULabel.matchAsciiL (".cmd:", 5, 0) &&
65
!oULabel.matchAsciiL ("macro:///", 5, 0))
67
oULabel = oULabel.replace ((sal_Unicode)0x007e, (sal_Unicode)0x005f);
68
gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
71
info->setLabel (label);
74
else if (Event.State >>= isChecked)
76
info->setCheckState (isChecked);
78
else if (Event.State >>= visible)
80
info->setVisible (visible.bVisible);
20
OUString url = Event.FeatureURL.Complete;
23
gchar* c_url = g_utf16_to_utf8 (url.getStr(),
27
GHashTable *commandsInfo = m_helper->getCommandsInfo ();
28
MenuItemInfo *info = (MenuItemInfo*)g_hash_table_lookup (commandsInfo, (gpointer)c_url);
31
info = new MenuItemInfo ();
32
g_hash_table_insert (commandsInfo, c_url, info);
34
//Set the default label
35
oULabel = m_helper->getLabelFromCommandURL(url);
36
// Replace tilde with underscore for Dbusmenu Alt accelerators
37
oULabel = oULabel.replace ((sal_Unicode)0x007e, (sal_Unicode)0x005f);
39
// GLib behaves better than OUStringToOString wrt encoding transformation
40
gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
43
info->setLabel (label);
48
//Since we're not introducing it in the hash table, we get rid of this string
52
//We set the enabled/disabled state
53
info->setEnabled ((gboolean)Event.IsEnabled);
55
//We find out what the new state is by casting
57
//For some reason, URLs can slip through as labels, we make sure
58
//this doesn't happen.
59
if ((Event.State >>= oULabel) &&
60
!oULabel.matchAsciiL ("private:", 8, 0) &&
61
!oULabel.matchAsciiL (".uno:", 5, 0) &&
62
!oULabel.matchAsciiL ("slot:", 5, 0) &&
63
!oULabel.matchAsciiL ("service:", 8, 0) &&
64
!oULabel.matchAsciiL (".cmd:", 5, 0) &&
65
!oULabel.matchAsciiL ("macro:///", 5, 0))
67
oULabel = oULabel.replace ((sal_Unicode)0x007e, (sal_Unicode)0x005f);
68
gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
71
info->setLabel (label);
74
else if (Event.State >>= isChecked)
76
info->setCheckState (isChecked);
78
else if (Event.State >>= visible)
80
info->setVisible (visible.bVisible);