[Libreoffice-commits] .: Branch 'feature/unitymenus' - vcl/inc vcl/unx
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Sep 25 07:10:31 PDT 2012
vcl/inc/unx/gtk/gtksalmenu.hxx | 13 ++--
vcl/unx/gtk/window/gtksalmenu.cxx | 107 +++++++++++++++++++++++++++++++++-----
2 files changed, 99 insertions(+), 21 deletions(-)
New commits:
commit 3bb9393f62bf12d4e5423ab573d895ca04023da6
Author: Antonio Fernandez <antonio.fernandez at aentos.es>
Date: Tue Sep 25 15:08:57 2012 +0100
Spare items and its actions are now removed.
Change-Id: Idb46b5dec4351e16c5c49a355c7d3cde3aab0789
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index 729eafc..6e8a465 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -24,15 +24,14 @@
#ifndef GTKSALMENU_HXX
#define GTKSALMENU_HXX
-#include <vcl/sv.h>
-#include <vcl/bitmap.hxx>
-#include <unx/gtk/gtkframe.hxx>
-#include <unx/salmenu.h>
-
+#include <vector>
#include <gio/gio.h>
-#include "glomenu.h"
-#include "gloactiongroup.h"
+#include <unx/salmenu.h>
+#include <unx/gtk/gtkframe.hxx>
+#include <unx/gtk/glomenu.h>
+#include <unx/gtk/gloactiongroup.h>
+#include <vcl/sv.h>
class MenuItemList;
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx
index b3976ec..fa80ec4 100644
--- a/vcl/unx/gtk/window/gtksalmenu.cxx
+++ b/vcl/unx/gtk/window/gtksalmenu.cxx
@@ -459,6 +459,78 @@ static void NativeSetItemCommand( GLOMenu* pMenu,
* Menu updating methods
*/
+void RemoveSpareItemsFromNativeMenu( GLOMenu* pMenu, GList** pOldCommandList, unsigned nSection, unsigned nValidItems )
+{
+ sal_Int32 nSectionItems = g_lo_menu_get_n_items_from_section( pMenu, nSection );
+
+ while ( nSectionItems > (sal_Int32) nValidItems )
+ {
+ gchar* aCommand = g_lo_menu_get_command_from_item_in_section( pMenu, nSection, --nSectionItems );
+
+ if ( aCommand != NULL && pOldCommandList != NULL )
+ *pOldCommandList = g_list_append( *pOldCommandList, g_strdup( aCommand ) );
+
+ g_free( aCommand );
+
+ g_lo_menu_remove_from_section( pMenu, nSection, nSectionItems );
+ }
+}
+
+void RemoveSpareSectionsFromNativeMenu( GLOMenu* pMenu, GList** pOldCommandList, unsigned nLastSection )
+{
+ if ( pMenu == NULL || pOldCommandList == NULL )
+ return;
+
+ sal_Int32 n = g_menu_model_get_n_items( G_MENU_MODEL( pMenu ) ) - 1;
+
+ for ( ; n > (sal_Int32) nLastSection; n-- )
+ {
+ RemoveSpareItemsFromNativeMenu( pMenu, pOldCommandList, n, 0 );
+ g_lo_menu_remove( pMenu, n );
+ }
+}
+
+gint CompareStr( gpointer str1, gpointer str2 )
+{
+ return g_strcmp0( (const gchar*) str1, (const gchar*) str2 );
+}
+
+void RemoveUnusedCommands( GLOActionGroup* pActionGroup, GList* pOldCommandList, GList* pNewCommandList )
+{
+ if ( pActionGroup == NULL || pOldCommandList == NULL )
+ return;
+
+ while ( pNewCommandList != NULL )
+ {
+ GList* pNewCommand = g_list_first( pNewCommandList );
+ pNewCommandList = g_list_remove_link( pNewCommandList, pNewCommand );
+
+ gpointer aCommand = g_list_nth_data( pNewCommand, 0 );
+
+ GList* pOldCommand = g_list_find_custom( pOldCommandList, aCommand, (GCompareFunc) CompareStr );
+
+ if ( pOldCommand != NULL )
+ {
+ pOldCommandList = g_list_remove_link( pOldCommandList, pOldCommand );
+ g_list_free_full( pOldCommand, g_free );
+ }
+
+ g_list_free_full( pNewCommand, g_free );
+ }
+
+ while ( pOldCommandList != NULL )
+ {
+ GList* pCommand = g_list_first( pOldCommandList );
+ pOldCommandList = g_list_remove_link( pOldCommandList, pCommand );
+
+ gchar* aCommand = (gchar*) g_list_nth_data( pCommand, 0 );
+
+ g_lo_action_group_remove( pActionGroup, aCommand );
+
+ g_list_free_full( pCommand, g_free );
+ }
+}
+
static void UpdateNativeSubMenu( GtkSalMenu *pMenu )
{
if ( pMenu == NULL )
@@ -469,6 +541,8 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu )
Menu* pVCLMenu = pMenu->GetMenu();
GLOMenu* pLOMenu = G_LO_MENU( pMenu->GetMenuModel() );
GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( pMenu->GetActionGroup() );
+ GList *pOldCommandList = NULL;
+ GList *pNewCommandList = NULL;
sal_uInt16 nLOMenuSize = g_menu_model_get_n_items( G_MENU_MODEL( pLOMenu ) );
@@ -490,11 +564,7 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu )
if ( pSalMenuItem->mnType == MENUITEM_SEPARATOR )
{
// Delete extra items from current section.
- sal_uInt16 nSectionItems = g_lo_menu_get_n_items_from_section( pLOMenu, nSection );
-
- while ( nSectionItems > validItems )
- // FIXME Remove associated command if needed.
- g_lo_menu_remove_from_section( pLOMenu, nSection, --nSectionItems );
+ RemoveSpareItemsFromNativeMenu( pLOMenu, &pOldCommandList, nSection, validItems );
nSection++;
nItemPos = 0;
@@ -525,6 +595,12 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu )
gboolean bEnabled = ( itemEnabled == sal_True ) ? TRUE : FALSE;
gchar* aNativeCommand = g_strdup( rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() );
+ // Store current item command in command list.
+ gchar *aCurrentCommand = g_lo_menu_get_command_from_item_in_section( pLOMenu, nSection, nItemPos );
+
+ if ( aCurrentCommand != NULL )
+ pOldCommandList = g_list_append( pOldCommandList, aCurrentCommand );
+
// Force updating of native menu labels.
NativeSetItemText( pLOMenu, nSection, nItemPos, aText );
NativeSetAccelerator( pLOMenu, nSection, nItemPos, nAccelKey, nAccelKey.GetName( pMenu->GetFrame()->GetWindow() ) );
@@ -546,6 +622,8 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu )
NativeSetItemCommand( pLOMenu, pActionGroup, nSection, nItemPos, nId, aNativeCommand, itemBits, bChecked, FALSE );
NativeCheckItem( pLOMenu, pActionGroup, nSection, nItemPos, itemBits, bChecked );
NativeSetEnableItem( pActionGroup, aNativeCommand, bEnabled );
+
+ pNewCommandList = g_list_append( pNewCommandList, g_strdup( aNativeCommand ) );
}
GtkSalMenu* pSubmenu = pSalMenuItem->mpSubMenu;
@@ -553,6 +631,7 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu )
if ( pSubmenu && pSubmenu->GetMenu() )
{
NativeSetItemCommand( pLOMenu, pActionGroup, nSection, nItemPos, nId, aNativeCommand, itemBits, FALSE, TRUE );
+ pNewCommandList = g_list_append( pNewCommandList, g_strdup( aNativeCommand ) );
GLOMenu* pSubMenuModel = g_lo_menu_get_submenu_from_item_in_section( pLOMenu, nSection, nItemPos );
@@ -575,15 +654,13 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu )
}
// Delete extra items in last section.
- sal_Int32 nSectionItems = (sal_Int32) g_lo_menu_get_n_items_from_section( pLOMenu, nSection );
-
- while ( nSectionItems > validItems )
- g_lo_menu_remove_from_section( pLOMenu, nSection, --nSectionItems );
+ RemoveSpareItemsFromNativeMenu( pLOMenu, &pOldCommandList, nSection, validItems );
// Delete extra sections.
- for ( sal_Int32 n = nLOMenuSize - 1; n > nSection; )
- // FIXME Remove associated command if needed.
- g_lo_menu_remove( pLOMenu, n-- );
+ RemoveSpareSectionsFromNativeMenu( pLOMenu, &pOldCommandList, nSection );
+
+ // Delete unused commands.
+ RemoveUnusedCommands( pActionGroup, pOldCommandList, pNewCommandList );
}
static void UpdateNativeMenu( GtkSalMenu* pMenu )
@@ -805,7 +882,8 @@ void GtkSalMenu::Activate( const gchar* aMenuCommand )
GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( (gchar*) aMenuCommand, TRUE );
if ( pSalSubMenu != NULL ) {
- pSalSubMenu->mpVCLMenu->Activate();
+ MenuBar* pMenuBar = static_cast< MenuBar* >( mpVCLMenu );
+ pMenuBar->HandleMenuActivateEvent( pSalSubMenu->mpVCLMenu );
UpdateNativeSubMenu( pSalSubMenu );
}
}
@@ -818,7 +896,8 @@ void GtkSalMenu::Deactivate( const gchar* aMenuCommand )
GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( (gchar*) aMenuCommand, TRUE );
if ( pSalSubMenu != NULL ) {
- pSalSubMenu->mpVCLMenu->Deactivate();
+ MenuBar* pMenuBar = static_cast< MenuBar* >( mpVCLMenu );
+ pMenuBar->HandleMenuDeActivateEvent( pSalSubMenu->mpVCLMenu );
}
}
More information about the Libreoffice-commits
mailing list