diff options
author | Antonio Fernandez <antonio.fernandez@aentos.es> | 2012-10-22 10:52:58 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2012-11-14 13:52:57 +0100 |
commit | 23395948b9fdd25fa077bc4a89755ce225739689 (patch) | |
tree | 4608c68011bfd2411349351c236387fa7a301b3e /vcl/unx/gtk/window/gtksalmenu.cxx | |
parent | 865b765065f631aa97a8139a0edaedda7d509547 (diff) |
Only activated submenus are generated when activating them. (Broken)
Change-Id: I9548a2c8dfec114de3133d55ca00362793b71a6c
Diffstat (limited to 'vcl/unx/gtk/window/gtksalmenu.cxx')
-rw-r--r-- | vcl/unx/gtk/window/gtksalmenu.cxx | 140 |
1 files changed, 138 insertions, 2 deletions
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index 8c488730db02..d094a4f7f841 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -358,6 +358,141 @@ void GtkSalMenu::UpdateNativeMenu() } g_object_unref( pSubMenuModel ); + } + + g_free( aNativeCommand ); + + ++nItemPos; + ++validItems; + } + + // Delete extra items in last section. + RemoveSpareItemsFromNativeMenu( pLOMenu, &pOldCommandList, nSection, validItems ); + + // Delete extra sections. + RemoveSpareSectionsFromNativeMenu( pLOMenu, &pOldCommandList, nSection ); + + // Delete unused commands. + RemoveUnusedCommands( pActionGroup, pOldCommandList, pNewCommandList ); +} + +static void GenerateFullMenu( GtkSalMenu* pSalMenu ) +{ + SolarMutexGuard aGuard; + //GTK_YIELD_GRAB(); + + if( !pSalMenu || !pSalMenu->PrepUpdate() ) + return; + + Menu* pVCLMenu = pSalMenu->GetMenu(); + GLOMenu* pLOMenu = G_LO_MENU( pSalMenu->GetMenuModel() ); + GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( pSalMenu->GetActionGroup() ); + GList *pOldCommandList = NULL; + GList *pNewCommandList = NULL; + + sal_uInt16 nLOMenuSize = g_menu_model_get_n_items( G_MENU_MODEL( pLOMenu ) ); + + if ( nLOMenuSize == 0 ) + g_lo_menu_new_section( pLOMenu, 0, NULL ); + + sal_Int32 nSection = 0; + sal_Int32 nItemPos = 0; + sal_Int32 validItems = 0; + sal_Int32 nItem; + + for ( nItem = 0; nItem < ( sal_Int32 ) pSalMenu->GetItemCount(); nItem++ ) { + if ( pSalMenu->IsItemVisible( nItem ) == sal_False ) + continue; + + GtkSalMenuItem *pSalMenuItem = pSalMenu->GetItemAtPos( nItem ); + sal_uInt16 nId = pSalMenuItem->mnId; + + if ( pSalMenuItem->mnType == MENUITEM_SEPARATOR ) + { + // Delete extra items from current section. + RemoveSpareItemsFromNativeMenu( pLOMenu, &pOldCommandList, nSection, validItems ); + + nSection++; + nItemPos = 0; + validItems = 0; + + if ( nLOMenuSize <= nSection ) + { + g_lo_menu_new_section( pLOMenu, nSection, NULL ); + nLOMenuSize++; + } + + continue; + } + + if ( nItemPos >= g_lo_menu_get_n_items_from_section( pLOMenu, nSection ) ) + g_lo_menu_insert_in_section( pLOMenu, nSection, nItemPos, "EMPTY STRING" ); + + // Get internal menu item values. + String aText = pVCLMenu->GetItemText( nId ); + rtl::OUString aCommand( pVCLMenu->GetItemCommand( nId ) ); + sal_Bool itemEnabled = pVCLMenu->IsItemEnabled( nId ); + KeyCode nAccelKey = pVCLMenu->GetAccelKey( nId ); + sal_Bool itemChecked = pVCLMenu->IsItemChecked( nId ); + MenuItemBits itemBits = pVCLMenu->GetItemBits( nId ); + + // Convert internal values to native values. + gboolean bChecked = ( itemChecked == sal_True ) ? TRUE : FALSE; + gboolean bEnabled = ( itemEnabled == sal_True ) ? TRUE : FALSE; +// gchar* aNativeCommand = g_strdup( rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() ); + gchar* aNativeCommand = pSalMenu->GetCommandForSpecialItem( pSalMenuItem ); + + // 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. + pSalMenu->NativeSetItemText( nSection, nItemPos, aText ); + pSalMenu->NativeSetAccelerator( nSection, nItemPos, nAccelKey, nAccelKey.GetName( GetFrame()->GetWindow() ) ); + + // Some items are special, so they have different commands. +// if ( g_strcmp0( aNativeCommand, "" ) == 0 ) + if ( !aNativeCommand ) + { +// gchar *aSpecialItemCmd = GetCommandForSpecialItem( pSalMenuItem ); + aNativeCommand = g_strdup( rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() ); + +// if ( aSpecialItemCmd != NULL ) +// { +// g_free( aNativeCommand ); +// aNativeCommand = aSpecialItemCmd; +// } + } + + if ( g_strcmp0( aNativeCommand, "" ) != 0 && pSalMenuItem->mpSubMenu == NULL ) + { + pSalMenu->NativeSetItemCommand( nSection, nItemPos, nId, aNativeCommand, itemBits, bChecked, FALSE ); + pSalMenu->NativeCheckItem( nSection, nItemPos, itemBits, bChecked ); + pSalMenu->NativeSetEnableItem( aNativeCommand, bEnabled ); + + pNewCommandList = g_list_append( pNewCommandList, g_strdup( aNativeCommand ) ); + } + + GtkSalMenu* pSubmenu = pSalMenuItem->mpSubMenu; + + if ( pSubmenu && pSubmenu->GetMenu() ) + { + pSalMenu->NativeSetItemCommand( 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 ); + + if ( pSubMenuModel == NULL ) + { + //pSubMenuModel = g_lo_menu_new(); + //g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, G_MENU_MODEL( pSubMenuModel ) ); + g_lo_menu_new_submenu_in_item_in_section( pLOMenu, nSection, nItemPos ); + pSubMenuModel = g_lo_menu_get_submenu_from_item_in_section( pLOMenu, nSection, nItemPos ); + } + + g_object_unref( pSubMenuModel ); pSubmenu->SetMenuModel( G_MENU_MODEL( pSubMenuModel ) ); pSubmenu->SetActionGroup( G_ACTION_GROUP( pActionGroup ) ); @@ -365,7 +500,8 @@ void GtkSalMenu::UpdateNativeMenu() pSubmenu->GetMenu()->Activate(); pSubmenu->GetMenu()->Deactivate(); - pSubmenu->UpdateNativeMenu(); + GenerateFullMenu( pSubmenu ); + //pSubmenu->UpdateNativeMenu(); } g_free( aNativeCommand ); @@ -707,7 +843,7 @@ void GtkSalMenu::Activate( const gchar* aMenuCommand ) if ( pSalSubMenu != NULL ) { MenuBar* pMenuBar = static_cast< MenuBar* >( mpVCLMenu ); pMenuBar->HandleMenuActivateEvent( pSalSubMenu->mpVCLMenu ); - pSalSubMenu->UpdateNativeMenu(); + pSalSubMenu->UpdateNativeMenu2(); } } |