vcl/inc/salmenu.hxx | 4 +- vcl/inc/unx/gtk/gtksalmenu.hxx | 9 +++-- vcl/source/window/menu.cxx | 3 + vcl/unx/gtk/window/gtksalmenu.cxx | 60 +++++++++++++++++++++++++++++++------- 4 files changed, 60 insertions(+), 16 deletions(-)
New commits: commit 548f323d08683ee52cfc6655b93b2a245000105e Author: Antonio Fernandez <antonio.fernan...@aentos.es> Date: Mon Sep 24 16:20:57 2012 +0100 Extra menu items are removed when needed, but not their actions. Change-Id: If817b03cc7b30bfeb751e47fff4aa571fdaaafdc diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index 5b8c46e..b3976ec 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -253,17 +253,14 @@ static void on_registrar_available( GDBusConnection* /*connection*/, pSalMenu->SetActionGroup( pActionGroup ); } -// PublishMenu( gdkWindow ); - g_timeout_add_full( G_PRIORITY_HIGH, 0, PublishMenu, (gpointer) gdkWindow, NULL ); + PublishMenu( gdkWindow ); bDBusIsAvailable = sal_True; if ( pMenuBar ) pMenuBar->SetDisplayable( sal_False ); -// ; -// GenerateMenu( pSalMenu ); - g_timeout_add_full( G_PRIORITY_HIGH, 0, GenerateMenu, pSalMenu, NULL ); + GenerateMenu( pSalMenu ); } } } @@ -478,12 +475,12 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu ) if ( nLOMenuSize == 0 ) g_lo_menu_new_section( pLOMenu, 0, NULL ); - sal_uInt16 nSection = 0; - sal_uInt16 nItemPos = 0; - sal_uInt16 validItems = 0; - sal_uInt16 nItem; + sal_Int32 nSection = 0; + sal_Int32 nItemPos = 0; + sal_Int32 validItems = 0; + sal_Int32 nItem; - for ( nItem = 0; nItem < pMenu->GetItemCount(); nItem++ ) { + for ( nItem = 0; nItem < ( sal_Int32 ) pMenu->GetItemCount(); nItem++ ) { if ( pMenu->IsItemVisible( nItem ) == sal_False ) continue; @@ -492,12 +489,12 @@ 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 ); - sal_Int32 nItemsToDelete = nSectionItems - validItems; - if ( nItemsToDelete > 0 ) - for ( sal_uInt16 i = nSectionItems - 1; i >= validItems; i-- ) - g_lo_menu_remove_from_section( pLOMenu, nSection, i ); + while ( nSectionItems > validItems ) + // FIXME Remove associated command if needed. + g_lo_menu_remove_from_section( pLOMenu, nSection, --nSectionItems ); nSection++; nItemPos = 0; @@ -576,6 +573,17 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu ) nItemPos++; validItems++; } + + // 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 ); + + // Delete extra sections. + for ( sal_Int32 n = nLOMenuSize - 1; n > nSection; ) + // FIXME Remove associated command if needed. + g_lo_menu_remove( pLOMenu, n-- ); } static void UpdateNativeMenu( GtkSalMenu* pMenu ) @@ -684,8 +692,7 @@ GtkSalMenu::~GtkSalMenu() sal_Bool GtkSalMenu::VisibleMenuBar() { -// return bDBusIsAvailable; - return sal_False; + return bDBusIsAvailable; } void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) @@ -732,8 +739,7 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) mpActionGroup = G_ACTION_GROUP( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-action-group" ) ); if ( mpMenuModel == NULL && mpActionGroup == NULL ) -// InitNativeMenu( ( GtkSalFrame* ) pFrame ); - g_idle_add_full( G_PRIORITY_HIGH_IDLE, InitNativeMenu, (gpointer) pFrame, NULL ); + InitNativeMenu( ( GtkSalFrame* ) pFrame ); else // Generate the main menu structure. GenerateMenu( this ); @@ -837,7 +843,7 @@ void GtkSalMenu::EnableItem( unsigned, sal_Bool ) void GtkSalMenu::ShowItem( unsigned nPos, sal_Bool bShow ) { if ( nPos < maItems.size() ) - ( ( GtkSalMenuItem* ) maItems[ nPos ])->mbVisible = bShow; + ( ( GtkSalMenuItem* ) maItems[ nPos ] )->mbVisible = bShow; } void GtkSalMenu::SetItemText( unsigned, SalMenuItem*, const rtl::OUString& ) commit ce402ba79e48f0e62bfd339da9df5a488a1acab0 Author: Antonio Fernandez <antonio.fernan...@aentos.es> Date: Mon Sep 24 13:11:45 2012 +0100 Hidden items are not shown anymore. Change-Id: I957c8c7690321be58e8daaf2fb65ebef136d95bc diff --git a/vcl/inc/salmenu.hxx b/vcl/inc/salmenu.hxx index e09b7ce..3411cb2 100644 --- a/vcl/inc/salmenu.hxx +++ b/vcl/inc/salmenu.hxx @@ -75,7 +75,7 @@ public: virtual ~SalMenu(); virtual sal_Bool VisibleMenuBar() = 0; // must return sal_True to actually DISPLAY native menu bars - // otherwise only menu messages are processed (eg, OLE on Windows) + // otherwise only menu messages are processed (eg, OLE on Windows) virtual void InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) = 0; virtual void RemoveItem( unsigned nPos ) = 0; @@ -91,7 +91,9 @@ public: virtual bool AddMenuBarButton( const SalMenuButtonItem& ); // return false if not implemented or failure virtual void RemoveMenuBarButton( sal_uInt16 nId ); + // FIXME: Make the other VCL native backends to work with these new methods. virtual void SetItemCommand( unsigned, SalMenuItem*, const rtl::OUString& ) {} + virtual void ShowItem( unsigned nPos, sal_Bool bShow ) { EnableItem( nPos, bShow ); } virtual void Freeze() {} // return an empty rectangle if not implemented diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index f2f1c9d..729eafc 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -70,6 +70,7 @@ public: virtual const GtkSalFrame* GetFrame() const; virtual void CheckItem( unsigned nPos, sal_Bool bCheck ); virtual void EnableItem( unsigned nPos, sal_Bool bEnable ); + virtual void ShowItem( unsigned nPos, sal_Bool bShow ); 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 ); @@ -86,6 +87,7 @@ public: virtual GtkSalMenuItem* GetItemAtPos( unsigned nPos ) { return maItems[ nPos ]; } virtual void SetActionGroup( GActionGroup* pActionGroup ) { mpActionGroup = pActionGroup; } virtual GActionGroup* GetActionGroup() { return mpActionGroup; } + virtual sal_Bool IsItemVisible( unsigned nPos ); void DispatchCommand( gint itemId, const gchar* aCommand ); void Activate( const gchar* aMenuCommand ); @@ -100,9 +102,10 @@ public: sal_uInt16 mnId; // Item ID MenuItemType mnType; // Item type - Menu* mpVCLMenu; // VCL Menu into which this MenuItem is inserted - GtkSalMenu* mpParentMenu; // The menu in which this menu item is inserted - GtkSalMenu* mpSubMenu; // Sub menu of this item (if defined) + sal_Bool mbVisible; // Item visibility. + Menu* mpVCLMenu; // VCL Menu into which this menu item is inserted + GtkSalMenu* mpParentMenu; // The menu into which this menu item is inserted + GtkSalMenu* mpSubMenu; // Submenu of this item (if defined) }; #endif // GTKSALMENU_HXX diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index 7fc74e4..bf41af8 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -1811,7 +1811,8 @@ void Menu::ShowItem( sal_uInt16 nItemId, sal_Bool bVisible ) // as long as there is no support to hide native menu entries, we just disable them // TODO: add support to show/hide native menu entries if( ImplGetSalMenu() ) - ImplGetSalMenu()->EnableItem( nPos, bVisible ); +// ImplGetSalMenu()->EnableItem( nPos, bVisible ); + ImplGetSalMenu()->ShowItem( nPos, bVisible ); } } diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index 77ae927..5b8c46e 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -31,6 +31,8 @@ # include <gdk/gdkkeysyms-compat.h> #endif +#include <svtools/menuoptions.hxx> + #include <framework/menuconfiguration.hxx> #include <iostream> @@ -258,6 +260,7 @@ static void on_registrar_available( GDBusConnection* /*connection*/, if ( pMenuBar ) pMenuBar->SetDisplayable( sal_False ); +// ; // GenerateMenu( pSalMenu ); g_timeout_add_full( G_PRIORITY_HIGH, 0, GenerateMenu, pSalMenu, NULL ); @@ -481,13 +484,24 @@ static void UpdateNativeSubMenu( GtkSalMenu *pMenu ) sal_uInt16 nItem; for ( nItem = 0; nItem < pMenu->GetItemCount(); nItem++ ) { + if ( pMenu->IsItemVisible( nItem ) == sal_False ) + continue; + GtkSalMenuItem *pSalMenuItem = pMenu->GetItemAtPos( nItem ); sal_uInt16 nId = pSalMenuItem->mnId; if ( pSalMenuItem->mnType == MENUITEM_SEPARATOR ) { + sal_uInt16 nSectionItems = g_lo_menu_get_n_items_from_section( pLOMenu, nSection ); + sal_Int32 nItemsToDelete = nSectionItems - validItems; + + if ( nItemsToDelete > 0 ) + for ( sal_uInt16 i = nSectionItems - 1; i >= validItems; i-- ) + g_lo_menu_remove_from_section( pLOMenu, nSection, i ); + nSection++; nItemPos = 0; + validItems = 0; if ( nLOMenuSize <= nSection ) { @@ -670,7 +684,8 @@ GtkSalMenu::~GtkSalMenu() sal_Bool GtkSalMenu::VisibleMenuBar() { - return bDBusIsAvailable; +// return bDBusIsAvailable; + return sal_False; } void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) @@ -801,6 +816,16 @@ void GtkSalMenu::Deactivate( const gchar* aMenuCommand ) } } +sal_Bool GtkSalMenu::IsItemVisible( unsigned nPos ) +{ + sal_Bool bVisible = sal_False; + + if ( nPos < maItems.size() ) + bVisible = ( ( GtkSalMenuItem* ) maItems[ nPos ])->mbVisible; + + return bVisible; +} + void GtkSalMenu::CheckItem( unsigned, sal_Bool ) { } @@ -809,6 +834,12 @@ void GtkSalMenu::EnableItem( unsigned, sal_Bool ) { } +void GtkSalMenu::ShowItem( unsigned nPos, sal_Bool bShow ) +{ + if ( nPos < maItems.size() ) + ( ( GtkSalMenuItem* ) maItems[ nPos ])->mbVisible = bShow; +} + void GtkSalMenu::SetItemText( unsigned, SalMenuItem*, const rtl::OUString& ) { } @@ -842,6 +873,7 @@ void GtkSalMenu::Freeze() GtkSalMenuItem::GtkSalMenuItem( const SalItemParams* pItemData ) : mnId( pItemData->nId ), mnType( pItemData->eType ), + mbVisible( sal_True ), mpVCLMenu( pItemData->pMenu ), mpParentMenu( NULL ), mpSubMenu( NULL ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits