Kaydet (Commit) 2b242efd authored tarafından Alberto Ruiz's avatar Alberto Ruiz Kaydeden (comit) Bjoern Michaelsen

initial import of lomenubar

* from http://bazaar.launchpad.net/~lo-menubar-team/lo-menubar/trunk/changes
* fixed indent to keep git hooks happy, otherwise a vanilla copy
üst 41434439
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#define XK_MISCELLANY
#define XK_LATIN1
#define XK_PUBLISHING
#include <X11/Xlib.h>
#include <X11/keysymdef.h>
#include <glib.h>
#include <com/sun/star/awt/Key.hpp>
using namespace ::com::sun::star;
KeySym MapAwtToXKey (guint16 aKeyCode);
gchar*
AwtKeyToDbusmenuString (guint16 aKeyCode)
{
KeySym code = (KeySym)0;
if (!aKeyCode)
return NULL;
//We try the consecutive ranges first, if the code is not there
//we use MapAwtToXKey(), se below
if (aKeyCode >= awt::Key::A && aKeyCode <= awt::Key::Z)
code = (KeySym)aKeyCode - (KeySym)awt::Key::A + XK_A;
else if (aKeyCode >= awt::Key::F1 && aKeyCode <= awt::Key::F26)
code = (KeySym)aKeyCode - (KeySym)awt::Key::F1 + XK_F1;
else if (aKeyCode >= awt::Key::NUM0 && aKeyCode <= awt::Key::NUM9)
code = (KeySym)aKeyCode - (KeySym)awt::Key::NUM0 + XK_0;
else
code = MapAwtToXKey (aKeyCode);
if (code == 0)
return NULL;
return XKeysymToString (code);;
}
//This is a 1-1 mapper between com::sun::star::awt:Key values and X11 KeySyms
//note that some symbols are missing
KeySym
MapAwtToXKey (guint16 aKeyCode)
{
switch (aKeyCode)
{
case awt::Key::UP:
return XK_Up;
case awt::Key::DOWN:
return XK_Down;
case awt::Key::LEFT:
return XK_Left;
case awt::Key::RIGHT:
return XK_Right;
case awt::Key::HOME:
return XK_Home;
case awt::Key::END:
return XK_End;
case awt::Key::PAGEUP:
return XK_Page_Up;
case awt::Key::PAGEDOWN:
return XK_Page_Down;
case awt::Key::RETURN:
return XK_Return;
case awt::Key::ESCAPE:
return XK_Escape;
case awt::Key::TAB:
return XK_Tab;
case awt::Key::BACKSPACE:
return XK_BackSpace;
case awt::Key::SPACE:
return XK_space;
case awt::Key::INSERT:
return XK_Insert;
case awt::Key::DELETE:
return XK_Delete;
case awt::Key::ADD:
return XK_plus;
case awt::Key::SUBTRACT:
return XK_minus;
case awt::Key::MULTIPLY:
return XK_asterisk;
case awt::Key::DIVIDE:
return XK_slash;
case awt::Key::POINT:
return XK_period;
case awt::Key::COMMA:
return XK_comma;
case awt::Key::LESS:
return XK_less;
case awt::Key::GREATER:
return XK_greater;
case awt::Key::EQUAL:
return XK_equal;
case awt::Key::UNDO:
return XK_Undo;
case awt::Key::REPEAT:
return XK_Redo;
case awt::Key::FIND:
return XK_Find;
case awt::Key::DECIMAL:
return XK_decimalpoint;
case awt::Key::TILDE:
return XK_asciitilde;
case awt::Key::QUOTELEFT:
return XK_leftsinglequotemark;
//Sun keys and other unsupported symbols
case awt::Key::OPEN:
case awt::Key::CUT:
case awt::Key::COPY:
case awt::Key::PASTE:
case awt::Key::PROPERTIES:
case awt::Key::FRONT:
case awt::Key::CONTEXTMENU:
case awt::Key::HELP:
case awt::Key::MENU:
default:
return 0;
}
}
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __AWT_KEY_TO_DBUSMENU_STRING_H__
#define __AWT_KEY_TO_DBUSMENU_STRING_H__
#include <X11/X.h>
#include <glib.h>
gchar*
AwtKeyToDbusmenuString (guint16 aKeyCode);
#endif //__AWT_KEY_TO_DBUSMENU_STRING_H__
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#include "DesktopJob.h"
#include "FrameJob.h"
#include <gio/gio.h>
#include <libdbusmenu-glib/server.h>
#include <rtl/process.h>
#include <osl/diagnose.h>
#include <cppuhelper/implbase1.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/document/XEventBroadcaster.hpp>
#include <com/sun/star/document/XEventListener.hpp>
#include <com/sun/star/document/EventObject.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/EventObject.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#include <com/sun/star/frame/XFramesSupplier.hpp>
#include <com/sun/star/frame/XFrameActionListener.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XLayoutManager.hpp>
using rtl::OUString;
using com::sun::star::beans::XPropertySet;
using com::sun::star::beans::NamedValue;
using com::sun::star::document::XEventListener;
using com::sun::star::document::XEventBroadcaster;
using com::sun::star::frame::XFrame;
using com::sun::star::frame::XFramesSupplier;
using com::sun::star::frame::XFrameActionListener;
using com::sun::star::frame::XModel;
using com::sun::star::frame::XLayoutManager;
using com::sun::star::frame::FrameActionEvent;
using com::sun::star::frame::XFrameActionListener;
using com::sun::star::lang::IllegalArgumentException;
using com::sun::star::lang::XMultiServiceFactory;
using com::sun::star::lang::EventObject;
using com::sun::star::uno::Any;
using com::sun::star::uno::Exception;
using com::sun::star::uno::Reference;
using com::sun::star::uno::RuntimeException;
using com::sun::star::uno::Sequence;
using com::sun::star::uno::UNO_QUERY;
using com::sun::star::uno::UNO_QUERY_THROW;
using com::sun::star::uno::XInterface;
//-------------------------- D-Bus Callbacks ----------------------------------
static void
on_bus (GDBusConnection * connection,
const gchar * name,
gpointer user_data)
{
//TODO: Should we actually do something here?
return;
}
static void
name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data)
{
g_error ("Unable to get name '%s' on DBus", name);
return;
}
// --------------------------- DesktopJob ----------------------------------
Any SAL_CALL DesktopJob::execute( const Sequence< NamedValue >& aArguments )
throw ( IllegalArgumentException, Exception, RuntimeException )
{
g_type_init ();
g_bus_own_name(G_BUS_TYPE_SESSION,
LIBREOFFICE_BUSNAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
on_bus,
NULL,
name_lost,
NULL,
NULL);
return Any ();
}
OUString
DesktopJob_getImplementationName ()
throw (RuntimeException)
{
return OUString ( RTL_CONSTASCII_USTRINGPARAM ( DESKTOPJOB_IMPLEMENTATION_NAME ) );
}
sal_Bool SAL_CALL
DesktopJob_supportsService( const OUString& ServiceName )
throw (RuntimeException)
{
return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( DESKTOPJOB_SERVICE_NAME ) );
}
Sequence< OUString > SAL_CALL
DesktopJob_getSupportedServiceNames( )
throw (RuntimeException)
{
Sequence < OUString > aRet(1);
OUString* pArray = aRet.getArray();
pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( DESKTOPJOB_SERVICE_NAME ) );
return aRet;
}
Reference< XInterface > SAL_CALL
DesktopJob_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
throw( Exception )
{
return (cppu::OWeakObject*) new DesktopJob(rSMgr);
}
// XServiceInfo
OUString SAL_CALL
DesktopJob::getImplementationName()
throw (RuntimeException)
{
return DesktopJob_getImplementationName();
}
sal_Bool SAL_CALL
DesktopJob::supportsService( const OUString& rServiceName )
throw (RuntimeException)
{
return DesktopJob_supportsService( rServiceName );
}
Sequence< OUString > SAL_CALL
DesktopJob::getSupportedServiceNames()
throw (RuntimeException)
{
return DesktopJob_getSupportedServiceNames();
}
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __DESKTOP_JOB_H__
#define __DESKTOP_JOB_H__
#include <glib.h>
#include <libdbusmenu-glib/menuitem.h>
#include <com/sun/star/task/XJob.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <cppuhelper/implbase2.hxx>
#define LIBREOFFICE_BUSNAME "org.libreoffice.dbusmenu"
#define DESKTOPJOB_IMPLEMENTATION_NAME "org.libreoffice.desktop.AppMenuJob"
#define DESKTOPJOB_SERVICE_NAME "org.libreoffice.desktop.AppMenuJob"
namespace css = ::com::sun::star;
using css::uno::Reference;
using css::uno::Sequence;
using css::uno::Any;
using css::uno::Exception;
using css::uno::RuntimeException;
using css::lang::IllegalArgumentException;
class DesktopJob : public cppu::WeakImplHelper2 < css::task::XJob, css::lang::XServiceInfo >
{
private:
Reference< css::lang::XMultiServiceFactory > mxMSF;
public:
DesktopJob( const Reference< css::lang::XMultiServiceFactory > &rxMSF)
: mxMSF( rxMSF ) {}
virtual ~DesktopJob() {}
// XJob
virtual Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& Arguments)
throw (IllegalArgumentException, Exception, RuntimeException);
// XServiceInfo
virtual ::rtl::OUString SAL_CALL getImplementationName()
throw (RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
throw (RuntimeException);
virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
throw (RuntimeException);
};
::rtl::OUString
DesktopJob_getImplementationName()
throw ( RuntimeException );
sal_Bool SAL_CALL
DesktopJob_supportsService( const ::rtl::OUString& ServiceName )
throw ( RuntimeException );
Sequence< ::rtl::OUString > SAL_CALL
DesktopJob_getSupportedServiceNames()
throw ( RuntimeException );
Reference< css::uno::XInterface >
SAL_CALL DesktopJob_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory > & rSMgr)
throw ( Exception );
#endif //__DESKTOP_JOB_H__
This diff is collapsed.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __FRAME_HELPER_H__
#define __FRAME_HELPER_H__
#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/frame/FrameAction.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/frame/XModuleManager.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <cppuhelper/implbase1.hxx>
#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/ui/XAcceleratorConfiguration.hpp>
#include <libdbusmenu-glib/server.h>
#include <libdbusmenu-glib/menuitem.h>
using com::sun::star::awt::KeyEvent;
using com::sun::star::awt::XMenu;
using com::sun::star::beans::PropertyValue;
using com::sun::star::container::XNameAccess;
using com::sun::star::frame::FrameActionEvent;
using com::sun::star::frame::XFrame;
using com::sun::star::frame::XFramesSupplier;
using com::sun::star::frame::XFrameActionListener;
using com::sun::star::frame::XStatusListener;
using com::sun::star::frame::XDispatchProvider;
using com::sun::star::frame::XModuleManager;
using com::sun::star::frame::XModel;
using com::sun::star::lang::EventObject;
using com::sun::star::lang::XMultiServiceFactory;
using com::sun::star::lang::XMultiComponentFactory;
using com::sun::star::uno::Any;
using com::sun::star::uno::Reference;
using com::sun::star::uno::Sequence;
using com::sun::star::uno::RuntimeException;
using com::sun::star::util::XURLTransformer;
using com::sun::star::ui::XAcceleratorConfiguration;
using rtl::OUString;
/* 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.
*/
class FrameHelper : public cppu::WeakImplHelper1 < XFrameActionListener >
{
private:
Reference < XFrame > xFrame;
Reference < XMultiServiceFactory > xMSF;
Reference < XNameAccess > xUICommands;
DbusmenuServer *server;
DbusmenuMenuitem *root;
gboolean watcher_set;
guint watcher;
XStatusListener *xSL;
Reference < XURLTransformer > xTrans;
Reference < XDispatchProvider > xdp;
GHashTable *commandsInfo;
gboolean blockDetach;
//These object/methods are used to recreate dynamic popupmenus
Reference < XMultiComponentFactory > xPCF;
Reference < XModuleManager> xMM;
Sequence < Any > args;
gboolean isSpecialSubmenu (OUString command);
//This is to build the shortcut database
Reference< XAcceleratorConfiguration > docAccelConf;
Reference< XAcceleratorConfiguration > modAccelConf;
Reference< XAcceleratorConfiguration > globAccelConf;
void getAcceleratorConfigurations (Reference < XModel >,
Reference < XModuleManager>);
KeyEvent findShortcutForCommand (OUString);
public:
FrameHelper(const Reference< XMultiServiceFactory >&,
const Reference< XFrame >&,
DbusmenuServer*);
virtual ~FrameHelper();
virtual void SAL_CALL frameAction(const FrameActionEvent& action)
throw (RuntimeException);
virtual void SAL_CALL disposing(const EventObject& aEvent)
throw (RuntimeException);
//Setters
void setRootItem (DbusmenuMenuitem *);
void setRegistrarWatcher (guint watcher);
void setServer (DbusmenuServer *);
//Getters
Reference < XFrame > getFrame ();
unsigned long getXID ();
GHashTable* getCommandsInfo ();
XStatusListener* getStatusListener ();
::rtl::OUString getLabelFromCommandURL (::rtl::OUString);
//Menu Related actions
void dispatchCommand (OUString);
void rebuildMenu (Reference < XMenu >, DbusmenuMenuitem*);
void rebuildMenuFromRoot ();
void populateWindowList (DbusmenuMenuitem *);
};
#endif // __FRAME_HELPER_H__
This diff is collapsed.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __FRAME_JOB_HXX__
#define __MRAME_JOB_HXX__
#include <com/sun/star/task/XJob.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <cppuhelper/implbase2.hxx>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XModuleManager.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
#include <com/sun/star/awt/XMenu.hpp>
#include <com/sun/star/awt/KeyEvent.hpp>
#include <glib.h>
#include <libdbusmenu-glib/menuitem.h>
#define FRAMEJOB_IMPLEMENTATION_NAME "com.sun.star.comp.Office.MyJob"
#define FRAMEJOB_SERVICE_NAME "com.sun.star.task.Job"
namespace css = ::com::sun::star;
using css::uno::Reference;
class FrameJob : public cppu::WeakImplHelper2 < css::task::XJob, css::lang::XServiceInfo >
{
private:
Reference < css::lang::XMultiServiceFactory > mxMSF;
Reference < css::container::XNameAccess > xUICommands;
Reference < css::frame::XFrame > xFrame;
unsigned long xid;
//Private methods
unsigned long getXID (Reference < css::frame::XFrame >);
DbusmenuMenuitem* getRootMenuitem (Reference < css::awt::XMenu >,
gpointer);
public:
FrameJob( const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF)
: mxMSF( rxMSF ) {};
void exportMenus (Reference < css::frame::XFrame > xFrame);
virtual ~FrameJob() {}
// XJob
virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& Arguments)
throw (css::lang::IllegalArgumentException, css::uno::Exception, css::uno::RuntimeException);
// XServiceInfo
virtual ::rtl::OUString SAL_CALL getImplementationName()
throw (css::uno::RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
throw (css::uno::RuntimeException);
virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
throw (css::uno::RuntimeException);
};
::rtl::OUString FrameJob_getImplementationName()
throw ( css::uno::RuntimeException );
sal_Bool SAL_CALL FrameJob_supportsService( const ::rtl::OUString& ServiceName )
throw ( css::uno::RuntimeException );
css::uno::Sequence< ::rtl::OUString > SAL_CALL FrameJob_getSupportedServiceNames()
throw ( css::uno::RuntimeException );
css::uno::Reference< css::uno::XInterface >
SAL_CALL FrameJob_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory > & rSMgr)
throw ( css::uno::Exception );
#endif
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#include "MenuItemInfo.h"
#include <libdbusmenu-gtk/menuitem.h>
MenuItemInfo::MenuItemInfo ()
{
label = NULL;
check_state = DBUSMENU_MENUITEM_TOGGLE_STATE_UNKNOWN;
check_type = (gchar*)DBUSMENU_MENUITEM_TOGGLE_CHECK;
is_visible = TRUE;
is_enabled = TRUE;
}
MenuItemInfo::~MenuItemInfo ()
{
if (label)
g_free(label);
}
//Setters
void
MenuItemInfo::setLabel (gchar* label)
{
this->label = g_strdup (label);
}
void
MenuItemInfo::setEnabled (gboolean is_enabled)
{
this->is_enabled = is_enabled;
}
void
MenuItemInfo::setCheckState (gint check_state)
{
this->check_state = check_state;
}
void
MenuItemInfo::setCheckType (const gchar* check_type)
{
this->check_type = (gchar*)check_type;
}
void
MenuItemInfo::setVisible (gboolean is_visible)
{
this->is_visible = is_visible;
}
//Getters
gchar*
MenuItemInfo::getLabel ()
{
return label;
}
gboolean
MenuItemInfo::getEnabled ()
{
return is_enabled;
}
gint
MenuItemInfo::getCheckState ()
{
return check_state;
}
const gchar*
MenuItemInfo::getCheckType ()
{
return check_type;
}
gboolean
MenuItemInfo::getVisible ()
{
return is_visible;
}
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __MENU_ITEM_INFO_H__
#define __MENU_ITEM_INFO_H__
#include <glib.h>
// This is used in a hash table with commandurls as keys
class MenuItemInfo {
gchar* label; //Label text in UTF-8 with tildes subst by underscores
gint check_state;
gchar* check_type;
gboolean is_enabled;
gboolean is_visible;
public:
MenuItemInfo ();
~MenuItemInfo ();
//Setters
void setLabel (gchar* label);
void setEnabled (gboolean is_enabled);
void setCheckState (gint check_state);
void setCheckType (const gchar* check_type);
void setVisible (gboolean is_visible);
//Getters
gchar* getLabel ();
gboolean getEnabled ();
gint getCheckState ();
const gchar* getCheckType ();
gboolean getVisible ();
};
#endif // __MENU_ITEM_INFO_H__
#include "MenuItemStatusListener.h"
#include "MenuItemInfo.h"
#include <com/sun/star/frame/status/Visibility.hpp>
using com::sun::star::frame::status::Visibility;
MenuItemStatusListener::MenuItemStatusListener (FrameHelper *helper)
{
if (!helper) throw ("FrameHelper cannot be NULL");
this->helper = helper;
}
void SAL_CALL
MenuItemStatusListener::statusChanged(const FeatureStateEvent& Event)
throw (RuntimeException)
{
sal_Bool isChecked;
Visibility visible;
OUString url = Event.FeatureURL.Complete;
OUString oULabel;
gchar* c_url = g_utf16_to_utf8 (url.getStr(),
url.getLength(),
NULL, NULL, NULL);
GHashTable *commandsInfo = helper->getCommandsInfo ();
MenuItemInfo *info = (MenuItemInfo*)g_hash_table_lookup (commandsInfo, (gpointer)c_url);
if (!info)
{
info = new MenuItemInfo ();
g_hash_table_insert (commandsInfo, c_url, info);
//Set the default label
oULabel = helper->getLabelFromCommandURL(url);
// Replace tilde with underscore for Dbusmenu Alt accelerators
oULabel = oULabel.replace ((sal_Unicode)0x007e, (sal_Unicode)0x005f);
// GLib behaves better than OUStringToOString wrt encoding transformation
gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
oULabel.getLength(),
NULL, NULL, NULL);
info->setLabel (label);
g_free (label);
}
else
{
//Since we're not introducing it in the hash table, we get rid of this string
g_free (c_url);
}
//We set the enabled/disabled state
info->setEnabled ((gboolean)Event.IsEnabled);
//We find out what the new state is by casting
//For some reason, URLs can slip through as labels, we make sure
//this doesn't happen.
if ((Event.State >>= oULabel) &&
!oULabel.matchAsciiL ("private:", 8, 0) &&
!oULabel.matchAsciiL (".uno:", 5, 0) &&
!oULabel.matchAsciiL ("slot:", 5, 0) &&
!oULabel.matchAsciiL ("service:", 8, 0) &&
!oULabel.matchAsciiL (".cmd:", 5, 0) &&
!oULabel.matchAsciiL ("macro:///", 5, 0))
{
oULabel = oULabel.replace ((sal_Unicode)0x007e, (sal_Unicode)0x005f);
gchar* label = g_utf16_to_utf8 (oULabel.getStr(),
oULabel.getLength(),
NULL, NULL, NULL);
info->setLabel (label);
g_free (label);
}
else if (Event.State >>= isChecked)
{
info->setCheckState (isChecked);
}
else if (Event.State >>= visible)
{
info->setVisible (visible.bVisible);
}
}
#ifndef __MENU_ITEM_STATUS_LISTENER_H__
#define __MENU_ITEM_STATUS_LISTENER_H__
#include "FrameHelper.h"
#include <glib.h>
#include <com/sun/star/frame/XStatusListener.hpp>
#include <cppuhelper/implbase1.hxx>
#include <rtl/process.h>
using com::sun::star::frame::FeatureStateEvent;
using com::sun::star::frame::XStatusListener;
using com::sun::star::lang::EventObject;
// This class listens for changes in each menuitem and notifies FrameHelper about it
class MenuItemStatusListener : public cppu::WeakImplHelper1 < XStatusListener >
{
private:
guint16 id;
FrameHelper *helper;
public:
MenuItemStatusListener (FrameHelper *helper);
~MenuItemStatusListener () {}
virtual void SAL_CALL
statusChanged(const FeatureStateEvent& Event)
throw (RuntimeException);
virtual void SAL_CALL disposing(const EventObject& aEvent)
throw (RuntimeException) {}
};
#endif
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* A LibreOffice extension to send the menubar structure through DBusMenu
*
* Copyright 2011 Canonical, Ltd.
* Authors:
* Alberto Ruiz <alberto.ruiz@codethink.co.uk>
*
* This program is free software: you can redistribute it and/or modify it under
* the the GNU Lesser General Public License version 3, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable
* version of the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#include <stdio.h>
#include <osl/mutex.hxx>
#include <osl/thread.h>
#include <cppuhelper/factory.hxx>
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/types.h>
#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#endif
#include "DesktopJob.h"
#include "FrameJob.h"
namespace css = ::com::sun::star;
static void writeInfo(const css::uno::Reference< css::registry::XRegistryKey >& xRegistryKey ,
const char* pImplementationName,
const char* pServiceName )
{
::rtl::OUStringBuffer sKey(256);
sKey.append (::rtl::OUString::createFromAscii(pImplementationName));
sKey.appendAscii("/UNO/SERVICES/");
sKey.append (::rtl::OUString::createFromAscii(pServiceName));
xRegistryKey->createKey(sKey.makeStringAndClear());
}
extern "C"
{
//==================================================================================================
SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char** ppEnvTypeName,
uno_Environment** ppEnv )
{
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}
//==================================================================================================
SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void* pServiceManager,
void* pRegistryKey )
{
if (!pRegistryKey)
return sal_False;
try
{
css::uno::Reference< css::registry::XRegistryKey > xKey(reinterpret_cast< css::registry::XRegistryKey* >(pRegistryKey), css::uno::UNO_QUERY);
writeInfo( xKey, DESKTOPJOB_IMPLEMENTATION_NAME, DESKTOPJOB_SERVICE_NAME);
writeInfo( xKey, FRAMEJOB_IMPLEMENTATION_NAME, FRAMEJOB_SERVICE_NAME);
return sal_True;
}
catch(const css::registry::InvalidRegistryException&)
{ OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); }
return sal_False;
}
//==================================================================================================
SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* pImplName ,
void* pServiceManager,
void* pRegistryKey )
{
if ( !pServiceManager || !pImplName )
return 0;
css::uno::Reference< css::lang::XSingleServiceFactory > xFactory ;
css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager), css::uno::UNO_QUERY);
::rtl::OUString sImplName = ::rtl::OUString::createFromAscii(pImplName);
if (sImplName.equalsAscii(DESKTOPJOB_IMPLEMENTATION_NAME))
{
css::uno::Sequence< ::rtl::OUString > lNames(1);
lNames[0] = ::rtl::OUString::createFromAscii(DESKTOPJOB_IMPLEMENTATION_NAME);
xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, DesktopJob_createInstance, lNames);
}
if (sImplName.equalsAscii(FRAMEJOB_IMPLEMENTATION_NAME))
{
css::uno::Sequence< ::rtl::OUString > lNames(1);
lNames[0] = ::rtl::OUString::createFromAscii(FRAMEJOB_IMPLEMENTATION_NAME);
xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, FrameJob_createInstance, lNames);
}
if (!xFactory.is())
return 0;
xFactory->acquire();
return xFactory.get();
}
} // extern C
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment