~lo-menubar-team/lo-menubar/trunk

« back to all changes in this revision

Viewing changes to src/MenuItemStatusListener.cxx

  • Committer: Bjoern Michaelsen
  • Date: 2011-04-28 08:34:12 UTC
  • Revision ID: bjoern.michaelsen@canonical.com-20110428083412-xbbwou14jl8n14ms
sync back changes from master libs-core repo up to f86bd621dbec0c432d2220f2124c8ef20aa15985

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "MenuItemStatusListener.h"
2
 
#include "MenuItemInfo.h"
 
1
#include "MenuItemStatusListener.hxx"
 
2
#include "MenuItemInfo.hxx"
3
3
 
4
4
#include <com/sun/star/frame/status/Visibility.hpp>
5
5
 
6
6
using com::sun::star::frame::status::Visibility;
7
7
 
8
8
MenuItemStatusListener::MenuItemStatusListener (FrameHelper *helper)
 
9
    : m_helper(helper)
9
10
{
10
 
        if (!helper) throw ("FrameHelper cannot be NULL");
11
 
        this->helper = helper;
 
11
    OSL_ENSURE(m_helper, "FrameHelper cannot be NULL");
12
12
}
13
13
 
14
14
void SAL_CALL
15
15
MenuItemStatusListener::statusChanged(const FeatureStateEvent& Event)
16
16
  throw (RuntimeException)
17
 
{       
18
 
        sal_Bool            isChecked;
19
 
        Visibility          visible;
20
 
        OUString url = Event.FeatureURL.Complete;
21
 
        OUString oULabel;
22
 
 
23
 
        gchar* c_url = g_utf16_to_utf8 (url.getStr(),
24
 
                                            url.getLength(),
25
 
                                            NULL, NULL, NULL);
26
 
 
27
 
        GHashTable *commandsInfo = helper->getCommandsInfo ();
28
 
        MenuItemInfo *info = (MenuItemInfo*)g_hash_table_lookup (commandsInfo, (gpointer)c_url);
29
 
        if (!info)
30
 
        {
31
 
                info = new MenuItemInfo ();
32
 
                g_hash_table_insert (commandsInfo, c_url, info);
33
 
                
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);
38
 
 
39
 
                // GLib behaves better than OUStringToOString wrt encoding transformation
40
 
                gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
41
 
                                                oULabel.getLength(),
42
 
                                                NULL, NULL, NULL);              
43
 
                info->setLabel (label);
44
 
                g_free (label);
45
 
        }
46
 
        else
47
 
        {
48
 
                //Since we're not introducing it in the hash table, we get rid of this string
49
 
                g_free (c_url);
50
 
        }
51
 
        
52
 
        //We set the enabled/disabled state
53
 
        info->setEnabled ((gboolean)Event.IsEnabled);
54
 
        
55
 
        //We find out what the new state is by casting
56
 
        
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))
66
 
        {       
67
 
                oULabel = oULabel.replace ((sal_Unicode)0x007e, (sal_Unicode)0x005f);
68
 
                gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
69
 
                                     oULabel.getLength(),
70
 
                                     NULL, NULL, NULL);         
71
 
                info->setLabel (label);
72
 
                g_free (label);
73
 
        }
74
 
        else if (Event.State >>= isChecked)
75
 
        {
76
 
                info->setCheckState (isChecked);
77
 
        }
78
 
        else if (Event.State >>= visible)
79
 
        {
80
 
                info->setVisible (visible.bVisible);
81
 
        }
 
17
{   
 
18
    sal_Bool            isChecked;
 
19
    Visibility          visible;
 
20
    OUString url = Event.FeatureURL.Complete;
 
21
    OUString oULabel;
 
22
 
 
23
    gchar* c_url = g_utf16_to_utf8 (url.getStr(),
 
24
                                    url.getLength(),
 
25
                                    NULL, NULL, NULL);
 
26
 
 
27
    GHashTable *commandsInfo = m_helper->getCommandsInfo ();
 
28
    MenuItemInfo *info = (MenuItemInfo*)g_hash_table_lookup (commandsInfo, (gpointer)c_url);
 
29
    if (!info)
 
30
    {
 
31
        info = new MenuItemInfo ();
 
32
        g_hash_table_insert (commandsInfo, c_url, info);
 
33
        
 
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);
 
38
 
 
39
        // GLib behaves better than OUStringToOString wrt encoding transformation
 
40
        gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
 
41
                                        oULabel.getLength(),
 
42
                                        NULL, NULL, NULL);      
 
43
        info->setLabel (label);
 
44
        g_free (label);
 
45
    }
 
46
    else
 
47
    {
 
48
        //Since we're not introducing it in the hash table, we get rid of this string
 
49
        g_free (c_url);
 
50
    }
 
51
    
 
52
    //We set the enabled/disabled state
 
53
    info->setEnabled ((gboolean)Event.IsEnabled);
 
54
    
 
55
    //We find out what the new state is by casting
 
56
    
 
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))
 
66
    {   
 
67
        oULabel = oULabel.replace ((sal_Unicode)0x007e, (sal_Unicode)0x005f);
 
68
        gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
 
69
                                 oULabel.getLength(),
 
70
                                 NULL, NULL, NULL);     
 
71
        info->setLabel (label);
 
72
        g_free (label);
 
73
    }
 
74
    else if (Event.State >>= isChecked)
 
75
    {
 
76
        info->setCheckState (isChecked);
 
77
    }
 
78
    else if (Event.State >>= visible)
 
79
    {
 
80
        info->setVisible (visible.bVisible);
 
81
    }
82
82
}