vcl/inc/unx/gtk/gtksalmenu.hxx | 78 ++++++++++++++++-------------- vcl/unx/gtk/app/gtkinst.cxx | 2 vcl/unx/gtk/window/gtksalmenu.cxx | 97 ++++++++------------------------------ 3 files changed, 63 insertions(+), 114 deletions(-)
New commits: commit 376df92806d3ae1138529bccae2820428c7fc92c Author: Antonio Fernandez <antonio.fernan...@aentos.es> Date: Tue Aug 14 10:20:01 2012 +0100 Cleaned up some code and did a small refactoring. Change-Id: I06b987a06ccadd00ee67db8e781ec5a9e42fc89e diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index 67adec4..d0ce612 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -47,53 +47,57 @@ class GtkSalMenuItem; class GtkSalMenu : public SalMenu { private: - sal_Bool mbMenuBar; + sal_Bool mbMenuBar; + Menu* mpVCLMenu; + GtkSalMenu* mpParentSalMenu; + const GtkSalFrame* mpFrame; - virtual void publishMenu( GMenuModel*, GActionGroup* ); - - GtkSalMenuItem* GetSalMenuItem( sal_uInt16 nId ); - -public: std::vector< GMenuModel* > maSections; std::vector< GtkSalMenuItem* > maItems; - Menu* mpVCLMenu; - GtkSalMenu* mpParentSalMenu; - const GtkSalFrame* mpFrame; - - // DBus variables - gchar* aDBusPath; - gchar* aDBusMenubarPath; - GDBusConnection* pSessionBus; - sal_Int32 mBusId; - sal_Int32 mMenubarId; - sal_Int32 mActionGroupId; + // DBus attributes + gchar* aDBusPath; + gchar* aDBusMenubarPath; + GDBusConnection* pSessionBus; + sal_Int32 mMenubarId; + sal_Int32 mActionGroupId; // GMenuModel attributes - GMenuModel* mpMenuModel; - GMenuModel* mpCurrentSection; + GMenuModel* mpMenuModel; + GMenuModel* mpCurrentSection; + + virtual void publishMenu( GMenuModel*, GActionGroup* ); + GtkSalMenuItem* GetSalMenuItem( sal_uInt16 nId ); +public: GtkSalMenu( sal_Bool bMenuBar ); virtual ~GtkSalMenu(); - virtual sal_Bool VisibleMenuBar(); // must return TRUE to actually DISPLAY native menu bars - // otherwise only menu messages are processed (eg, OLE on Windows) - - virtual void InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ); - virtual void RemoveItem( unsigned nPos ); - virtual void SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ); - virtual void SetFrame( const SalFrame* pFrame ); - virtual void CheckItem( unsigned nPos, sal_Bool bCheck ); - virtual void EnableItem( unsigned nPos, sal_Bool bEnable ); - virtual void SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& rText ); - virtual void SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage); - virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const rtl::OUString& rKeyName ); - virtual void GetSystemMenuData( SystemMenuData* pData ); - virtual void SetItemCommand( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& aCommandStr ); - virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, sal_uLong nFlags); - virtual void Freeze(); - - virtual const GtkSalFrame* getFrame() const; + virtual sal_Bool VisibleMenuBar(); // must return TRUE to actually DISPLAY native menu bars + // otherwise only menu messages are processed (eg, OLE on Windows) + + virtual void InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ); + virtual void RemoveItem( unsigned nPos ); + virtual void SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ); + virtual void SetFrame( const SalFrame* pFrame ); + virtual const GtkSalFrame* GetFrame() const; + virtual void CheckItem( unsigned nPos, sal_Bool bCheck ); + virtual void EnableItem( unsigned nPos, sal_Bool bEnable ); + virtual void SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& rText ); + virtual void SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage); + virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const rtl::OUString& rKeyName ); + virtual void GetSystemMenuData( SystemMenuData* pData ); + virtual void SetItemCommand( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& aCommandStr ); + virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, sal_uLong nFlags); + virtual void Freeze(); + + virtual void SetMenu( Menu* pMenu ) { mpVCLMenu = pMenu; } + virtual Menu* GetMenu() { return mpVCLMenu; } + virtual GtkSalMenu* GetParentSalMenu() { return mpParentSalMenu; } + virtual GMenuModel* GetMenuModel() { return mpMenuModel; } + virtual GMenuModel* GetCurrentSection() { return mpCurrentSection; } + virtual unsigned GetItemCount() { return maItems.size(); } + virtual GtkSalMenuItem* GetItemAtPos( unsigned nPos ) { return maItems[ nPos ]; } }; class GtkSalMenuItem : public SalMenuItem diff --git a/vcl/unx/gtk/app/gtkinst.cxx b/vcl/unx/gtk/app/gtkinst.cxx index 103eb70..3239ad7 100644 --- a/vcl/unx/gtk/app/gtkinst.cxx +++ b/vcl/unx/gtk/app/gtkinst.cxx @@ -522,7 +522,7 @@ SalBitmap* GtkInstance::CreateSalBitmap() SalMenu* GtkInstance::CreateMenu( sal_Bool bMenuBar, Menu* pVCLMenu ) { GtkSalMenu *pSalMenu = new GtkSalMenu( bMenuBar ); - pSalMenu->mpVCLMenu = pVCLMenu; + pSalMenu->SetMenu( pVCLMenu ); return static_cast<SalMenu*>( pSalMenu ); } diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index 163564a..0c78997 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -11,9 +11,6 @@ using namespace std; -#define GTK_MENU_BUS_NAME_PREFIX "org.libreoffice" -#define GTK_MENU_OBJ_PATH_PREFIX "/org/libreoffice" - //Some menus are special, this is the list of them gboolean isSpecialSubmenu (OUString command) @@ -43,14 +40,13 @@ dispatchAction (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - cout << "ACTION: " << g_action_get_name( G_ACTION( action ) ) << " triggered." << endl; GTK_YIELD_GRAB(); if ( user_data ) { GtkSalMenuItem *pSalMenuItem = static_cast< GtkSalMenuItem* >( user_data ); if ( !pSalMenuItem->mpSubMenu ) { - const GtkSalFrame *pFrame = pSalMenuItem->mpParentMenu ? pSalMenuItem->mpParentMenu->getFrame() : NULL; + const GtkSalFrame *pFrame = pSalMenuItem->mpParentMenu ? pSalMenuItem->mpParentMenu->GetFrame() : NULL; if ( pFrame && !pFrame->GetParent() ) { ((PopupMenu*) pSalMenuItem->mpVCLMenu)->SetSelectedEntry( pSalMenuItem->mnId ); @@ -76,51 +72,29 @@ dispatchAction (GSimpleAction *action, // get started from hierarchy in vcl menus GtkSalMenu* pParentMenu = pSalMenuItem->mpParentMenu; Menu* pCurMenu = pSalMenuItem->mpVCLMenu; - while( pParentMenu && pParentMenu->mpVCLMenu ) + while( pParentMenu && pParentMenu->GetMenu() ) { - pCurMenu = pParentMenu->mpVCLMenu; - pParentMenu = pParentMenu->mpParentSalMenu; + pCurMenu = pParentMenu->GetMenu(); + pParentMenu = pParentMenu->GetParentSalMenu(); } -// pPopupMenu->SetSelectedEntry( pSalMenuItem->mnId ); -// pPopupMenu->ImplSelectWithStart( pCurMenu ); - ((MenuBar*) pCurMenu)->HandleMenuCommandEvent( pCurMenu, pSalMenuItem->mnId ); + pPopupMenu->SetSelectedEntry( pSalMenuItem->mnId ); + pPopupMenu->ImplSelectWithStart( pCurMenu ); } else OSL_FAIL( "menubar item without frame !" ); } - } else { - rtl::OUString aActionName = rtl::OUString::createFromAscii( g_action_get_name( G_ACTION( action ) ) ); - - if ( isSpecialSubmenu( aActionName ) ) { - PopupMenu * pPopupMenu = dynamic_cast<PopupMenu *>(pSalMenuItem->mpVCLMenu); - if( pPopupMenu ) - { - GtkSalMenu* pParentMenu = pSalMenuItem->mpParentMenu; - Menu* pCurMenu = pSalMenuItem->mpVCLMenu; - while( pParentMenu && pParentMenu->mpVCLMenu ) - { - pCurMenu = pParentMenu->mpVCLMenu; - pParentMenu = pParentMenu->mpParentSalMenu; - } - - ((MenuBar*) pCurMenu)->HandleMenuActivateEvent( pSalMenuItem->mpVCLMenu ); -// pPopupMenu->SetSelectedEntry( pSalMenuItem->mnId ); -// pPopupMenu->ImplActivateWithStart( pCurMenu ); -// // pSalMenuItem->mpVCLMenu->Activate(); - } - } } } } void generateActions( GtkSalMenu* pMenu, GLOActionGroup* pActionGroup ) { - if ( !pMenu || !pMenu->mpMenuModel ) + if ( !pMenu || !pMenu->GetMenuModel() ) return; - for (sal_uInt16 i = 0; i < pMenu->maItems.size(); i++) { - GtkSalMenuItem *pSalMenuItem = pMenu->maItems[ i ]; + for (sal_uInt16 i = 0; i < pMenu->GetItemCount(); i++) { + GtkSalMenuItem *pSalMenuItem = pMenu->GetItemAtPos( i ); if ( pSalMenuItem->mpAction ) { g_lo_action_group_insert( pActionGroup, pSalMenuItem->mpAction ); @@ -181,7 +155,6 @@ void GtkSalMenu::publishMenu( GMenuModel *pMenu, GActionGroup *pActionGroup ) } -// FIXME: HIGHLY IMPROVABLE CODE GtkSalMenuItem* GtkSalMenu::GetSalMenuItem( sal_uInt16 nId ) { for ( sal_uInt16 i = 0; i < maItems.size(); i++ ) @@ -212,7 +185,6 @@ GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) : aDBusPath( NULL ), aDBusMenubarPath( NULL ), pSessionBus( NULL ), - mBusId( 0 ), mMenubarId( 0 ), mActionGroupId ( 0 ) { @@ -225,9 +197,6 @@ GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) : if (bMenuBar) { pSessionBus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); if(!pSessionBus) puts ("Fail bus get"); - -// mBusId = g_bus_own_name_on_connection (pSessionBus, "", G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); -// if(!mBusId) puts ("Fail own name"); } } @@ -258,19 +227,11 @@ GtkSalMenu::~GtkSalMenu() g_dbus_connection_flush_sync( pSessionBus, NULL, NULL ); } -// if ( mBusId ) { -// g_bus_unown_name( mBusId ); -// } - -// if ( pSessionBus ) { -// g_dbus_connection_close_sync( pSessionBus, NULL, NULL ); -// pSessionBus = NULL; -// mMenubarId = 0; -// mActionGroupId = 0; -// } - pSessionBus = NULL; + g_free( aDBusPath ); + g_free( aDBusMenubarPath ); + maSections.clear(); maItems.clear(); @@ -288,7 +249,6 @@ void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) GtkSalMenuItem *pGtkSalMenuItem = static_cast<GtkSalMenuItem*>( pSalMenuItem ); if ( pGtkSalMenuItem->mpMenuItem ) { - sal_uInt16 position = pGtkSalMenuItem->mpVCLMenu->GetItemPos( pGtkSalMenuItem->mnId ); pGtkSalMenuItem->mpParentSection = mpCurrentSection; pGtkSalMenuItem->mnPos = g_menu_model_get_n_items( mpCurrentSection ); @@ -307,7 +267,6 @@ void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) void GtkSalMenu::RemoveItem( unsigned nPos ) { -// cout << __FUNCTION__ << " Item: " << nPos << endl; } void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ) @@ -327,8 +286,6 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig void GtkSalMenu::SetFrame( const SalFrame* pFrame ) { - cout << __FUNCTION__ << endl; - mpFrame = static_cast<const GtkSalFrame*>( pFrame ); GtkWidget *widget = GTK_WIDGET( mpFrame->getWindow() ); @@ -338,22 +295,12 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) if (gdkWindow) { XLIB_Window windowId = GDK_WINDOW_XID( gdkWindow ); -// gchar* aGtkMenuObjPath = GTK_MENU_OBJ_PATH_PREFIX; -// gchar* aGtkMenuObjPath = (gchar*) g_dbus_connection_get_unique_name( pSessionBus ); - gchar *aGtkMenuObjPath = ""; - - aDBusPath = g_strdup_printf("%s/window/%lu", aGtkMenuObjPath, windowId); - gchar* aDBusWindowPath = g_strdup_printf( "%s/window/%lu", aGtkMenuObjPath, windowId ); - aDBusMenubarPath = g_strdup_printf( "%s/window/%lu/menus/menubar", aGtkMenuObjPath, windowId ); - - puts(aDBusPath); - puts(aDBusWindowPath); - puts(aDBusMenubarPath); - - puts(g_dbus_connection_get_unique_name( pSessionBus )); + aDBusPath = g_strdup_printf("/window/%lu", windowId); + gchar* aDBusWindowPath = g_strdup_printf( "/window/%lu", windowId ); + aDBusMenubarPath = g_strdup_printf( "/window/%lu/menus/menubar", windowId ); gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name( pSessionBus ) ); - gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_APPLICATION_OBJECT_PATH", aGtkMenuObjPath ); + gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_APPLICATION_OBJECT_PATH", "" ); gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_WINDOW_OBJECT_PATH", aDBusWindowPath ); gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_MENUBAR_OBJECT_PATH", aDBusMenubarPath ); @@ -362,7 +309,7 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) } } -const GtkSalFrame* GtkSalMenu::getFrame() const +const GtkSalFrame* GtkSalMenu::GetFrame() const { const GtkSalMenu* pMenu = this; while( pMenu && ! pMenu->mpFrame ) @@ -392,8 +339,6 @@ void GtkSalMenu::SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const rt rtl::OUString aText = rText.replace( '~', '_' ); rtl::OString aConvertedText = OUStringToOString(aText, RTL_TEXTENCODING_UTF8); -// cout << "Setting label: " << aConvertedText.getStr() << endl; - GtkSalMenuItem *pGtkSalMenuItem = static_cast<GtkSalMenuItem*>( pSalMenuItem ); GLOMenuItem *pMenuItem = G_LO_MENU_ITEM( pGtkSalMenuItem->mpMenuItem ); @@ -453,15 +398,15 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRe void updateNativeMenu( GtkSalMenu* pMenu ) { if ( pMenu ) { - for (int i=0; i < pMenu->maItems.size(); i++) { - GtkSalMenuItem* pSalMenuItem = pMenu->maItems[ i ]; + for ( sal_uInt16 i = 0; i < pMenu->GetItemCount(); i++ ) { + GtkSalMenuItem* pSalMenuItem = pMenu->GetItemAtPos( i ); String aText = pSalMenuItem->mpVCLMenu->GetItemText( pSalMenuItem->mnId ); // Force updating of native menu labels. pMenu->SetItemText( i, pSalMenuItem, aText ); - if ( pSalMenuItem->mpSubMenu && pSalMenuItem->mpSubMenu->mpVCLMenu ) { - pSalMenuItem->mpSubMenu->mpVCLMenu->Activate(); + if ( pSalMenuItem->mpSubMenu && pSalMenuItem->mpSubMenu->GetMenu() ) { + pSalMenuItem->mpSubMenu->GetMenu()->Activate(); updateNativeMenu( pSalMenuItem->mpSubMenu ); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits