vcl/inc/unx/gtk/glomenu.h | 135 +++++++++----------- vcl/inc/unx/gtk/gtksalmenu.hxx | 7 - vcl/unx/gtk/window/gloactiongroup.cxx | 5 vcl/unx/gtk/window/glomenu.cxx | 113 +++++++++-------- vcl/unx/gtk/window/gtksalmenu.cxx | 222 ++++++++++++++++------------------ 5 files changed, 234 insertions(+), 248 deletions(-)
New commits: commit 3218d5bcd47b507cd7611b4cb9354b1c3cd19eaa Author: Antonio Fernandez <antonio.fernan...@aentos.es> Date: Sun Aug 26 20:22:48 2012 +0100 Menu is correctly displayed in all instances, but HUD remains broken. Change-Id: Ia1089150ae9853649754a4de733ca4a7f8c3caae diff --git a/vcl/unx/gtk/window/gloactiongroup.cxx b/vcl/unx/gtk/window/gloactiongroup.cxx index 39ab45e..443c628 100644 --- a/vcl/unx/gtk/window/gloactiongroup.cxx +++ b/vcl/unx/gtk/window/gloactiongroup.cxx @@ -39,9 +39,9 @@ using namespace std; #define G_TYPE_LO_ACTION (g_lo_action_get_type ()) #define G_LO_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ - G_TYPE_LO_ACTION, GLOAction)) + G_TYPE_LO_ACTION, GLOAction)) #define G_IS_LO_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \ - G_TYPE_LO_ACTION)) + G_TYPE_LO_ACTION)) struct _GLOAction { @@ -161,7 +161,6 @@ g_lo_action_group_query_action (GActionGroup *group, GVariant **state_hint, GVariant **state) { -// cout << __FUNCTION__ << " - " << action_name << " - enabled: " << enabled << " - parameter_type: " << parameter_type << " - state_type: " << state_type << " - state_hint: " << state_hint << " - state: " << state << endl; GLOActionGroup *lo_group = G_LO_ACTION_GROUP (group); GLOAction* action; diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index 5cc65eb..507849c 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -249,7 +249,7 @@ GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) : mpActionGroup( NULL ) { if (bMenuBar) { - mpActionGroup = G_ACTION_GROUP( g_lo_action_group_new() ); +// mpActionGroup = G_ACTION_GROUP( g_lo_action_group_new() ); } mpMenuModel = G_MENU_MODEL( g_lo_menu_new() ); @@ -265,8 +265,11 @@ GtkSalMenu::~GtkSalMenu() if ( mbMenuBar ) { g_source_remove_by_user_data( this ); +// GLOMenu* pMainMenu = G_LO_MENU( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ) ); + g_lo_menu_remove( G_LO_MENU( mpMenuModel ), 0 ); - mpMenuModel = NULL; +// g_lo_menu_remove( pMainMenu, 0 ); +// mpMenuModel = NULL; } else { g_object_unref( mpMenuModel ); } @@ -368,18 +371,13 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-action-group" ) ); if ( pMainMenu && pActionGroup ) { - // Merge current action group with the exported one - g_lo_action_group_clear( pActionGroup ); - g_lo_action_group_merge( G_LO_ACTION_GROUP( mpActionGroup ), pActionGroup ); - g_lo_action_group_clear( G_LO_ACTION_GROUP( mpActionGroup ) ); - g_object_unref( mpActionGroup ); - - mpActionGroup = G_ACTION_GROUP( pActionGroup ); + g_lo_menu_remove( pMainMenu, 0 ); } else { pMainMenu = g_lo_menu_new(); + pActionGroup = g_lo_action_group_new(); - g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-menubar", mpMenuModel, ObjectDestroyedNotify ); - g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-action-group", mpActionGroup, ObjectDestroyedNotify ); + g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-menubar", pMainMenu, ObjectDestroyedNotify ); + g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-action-group", pActionGroup, ObjectDestroyedNotify ); XLIB_Window windowId = GDK_WINDOW_XID( gdkWindow ); @@ -398,12 +396,12 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) // Publish the menu. if ( aDBusMenubarPath ) { - sal_uInt16 menubarId = g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, mpMenuModel, NULL); + sal_uInt16 menubarId = g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, G_MENU_MODEL( pMainMenu ), NULL); if(!menubarId) puts("Failed to export menubar"); } if ( aDBusPath ) { - sal_uInt16 actionGroupId = g_dbus_connection_export_action_group( pSessionBus, aDBusPath, mpActionGroup, NULL); + sal_uInt16 actionGroupId = g_dbus_connection_export_action_group( pSessionBus, aDBusPath, G_ACTION_GROUP( pActionGroup ), NULL); if(!actionGroupId) puts("Failed to export action group"); } @@ -413,8 +411,8 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) } // Menubar has only one section, so we put it on the exported menu. -// GMenuModel *pSection = G_MENU_MODEL( g_lo_menu_get_section( G_LO_MENU( mpMenuModel ), 0 ) ); -// g_lo_menu_insert_section( pMainMenu, 0, NULL, pSection ); + g_lo_menu_insert_section( pMainMenu, 0, NULL, mpMenuModel ); + mpActionGroup = G_ACTION_GROUP( pActionGroup ); // UpdateNativeMenu( this ); // UpdateNativeMenu( this ); commit 2c8233f0011ddb2daadd0b78f3b67517c75aeab3 Author: Antonio Fernandez <antonio.fernan...@aentos.es> Date: Sun Aug 26 18:50:35 2012 +0100 Menus are now working. HUD integration is broken. Change-Id: I0f5fef169b2656a713416e28648a3260b22b43b0 diff --git a/vcl/inc/unx/gtk/glomenu.h b/vcl/inc/unx/gtk/glomenu.h index ab43897..9c4801f 100644 --- a/vcl/inc/unx/gtk/glomenu.h +++ b/vcl/inc/unx/gtk/glomenu.h @@ -36,86 +36,71 @@ G_BEGIN_DECLS #define G_IS_LO_MENU(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \ G_TYPE_LO_MENU)) -typedef struct _GLOMenu GLOMenu; +typedef struct _GLOMenu GLOMenu; class GtkSalMenuItem; GLIB_AVAILABLE_IN_2_32 -GType g_lo_menu_get_type (void) G_GNUC_CONST; +GType g_lo_menu_get_type (void) G_GNUC_CONST; GLIB_AVAILABLE_IN_2_32 -GLOMenu * g_lo_menu_new (void); - -void g_lo_menu_insert (GLOMenu *menu, - gint position, - const char *label); - -void g_lo_menu_insert_in_section (GLOMenu *menu, - gint section, - gint position, - const gchar *label); - -void g_lo_menu_insert_section (GLOMenu *menu, - gint position, - const gchar *label); - -void g_lo_menu_remove (GLOMenu *menu, - gint position); - -void g_lo_menu_remove_from_section (GLOMenu *menu, - gint section, - gint position); - -//void g_lo_menu_insert (GLOMenu *menu, -// gint position, -// const gchar *label); - -//void g_lo_menu_append (GLOMenu *menu, -// const gchar *label, -// const gchar *detailed_action); - -//void g_lo_menu_insert_submenu (GLOMenu *menu, -// gint position, -// const gchar *label, -// GMenuModel *submenu); -//void g_lo_menu_prepend_submenu (GLOMenu *menu, -// const gchar *label, -// GMenuModel *submenu); -//void g_lo_menu_append_submenu (GLOMenu *menu, -// const gchar *label, -// GMenuModel *submenu); - -void g_lo_menu_set_label (GLOMenu *menu, - gint position, - const gchar *label); - -void g_lo_menu_set_label_in_section (GLOMenu *menu, - gint section, - gint position, - const gchar *label); - -void g_lo_menu_set_action_and_target_value (GLOMenu *menu, - gint position, - const gchar *command, - GVariant *target_value); - -void g_lo_menu_set_action_and_target_value_to_item_in_section (GLOMenu *menu, - gint section, - gint position, - const gchar *command, - GVariant *target_value); - -void g_lo_menu_set_submenu (GLOMenu *menu, - gint position, - GMenuModel *submenu); - -void g_lo_menu_set_submenu_to_item_in_section (GLOMenu *menu, - gint section, - gint position, - GMenuModel *submenu); - -gchar* g_lo_menu_get_action_value_from_item_in_section (GLOMenu *menu, - gint section, - gint position); +GLOMenu * g_lo_menu_new (void); + +void g_lo_menu_insert (GLOMenu *menu, + gint position, + const char *label); + +void g_lo_menu_insert_in_section (GLOMenu *menu, + gint section, + gint position, + const gchar *label); + +void g_lo_menu_new_section (GLOMenu *menu, + gint position, + const gchar *label); + +void g_lo_menu_insert_section (GLOMenu *menu, + gint position, + const gchar *label, + GMenuModel *section); + +GLOMenu * g_lo_menu_get_section (GLOMenu *menu, + gint section); + +void g_lo_menu_remove (GLOMenu *menu, + gint position); + +void g_lo_menu_remove_from_section (GLOMenu *menu, + gint section, + gint position); + +void g_lo_menu_set_label (GLOMenu *menu, + gint position, + const gchar *label); + +void g_lo_menu_set_label_to_item_in_section (GLOMenu *menu, + gint section, + gint position, + const gchar *label); + +gchar * g_lo_menu_get_label_from_item_in_section (GLOMenu *menu, + gint section, + gint position); + +void g_lo_menu_set_action_and_target_value (GLOMenu *menu, + gint position, + const gchar *command, + GVariant *target_value); + +void g_lo_menu_set_action_and_target_value_to_item_in_section (GLOMenu *menu, + gint section, + gint position, + const gchar *command, + GVariant *target_value); + +void g_lo_menu_set_submenu_to_item_in_section (GLOMenu *menu, + gint section, + gint position, + GMenuModel *submenu); G_END_DECLS diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index a517c5e..0e21313 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -52,9 +52,7 @@ private: GMenuModel* mpMenuModel; GActionGroup* mpActionGroup; - - sal_Int16 GetSectionNumber( GMenuModel* pSection ); - void GetInsertionData( unsigned nPos, unsigned *insertSection, unsigned *insertPos ); + void GetItemSectionAndPosition( unsigned nPos, unsigned *insertSection, unsigned *insertPos ); public: GtkSalMenu( sal_Bool bMenuBar ); @@ -84,7 +82,6 @@ public: virtual unsigned GetItemCount() { return maItems.size(); } virtual GtkSalMenuItem* GetItemAtPos( unsigned nPos ) { return maItems[ nPos ]; } virtual GActionGroup* GetActionGroup() { return mpActionGroup; } -// virtual GtkSalMenuItem* GetSalMenuItem( sal_uInt16 nId ); }; class GtkSalMenuItem : public SalMenuItem @@ -96,6 +93,8 @@ public: sal_uInt16 mnId; // Item ID MenuItemBits mnBits; // Item bits MenuItemType mnType; // Item type + gchar* maCommand; // Item command + gchar* maLabel; // Item label 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) diff --git a/vcl/unx/gtk/window/glomenu.cxx b/vcl/unx/gtk/window/glomenu.cxx index 989a3b3..e4122d5 100644 --- a/vcl/unx/gtk/window/glomenu.cxx +++ b/vcl/unx/gtk/window/glomenu.cxx @@ -41,7 +41,6 @@ G_DEFINE_TYPE (GLOMenu, g_lo_menu, G_TYPE_MENU_MODEL); struct item { -// GtkSalMenuItem* menu_item; // Menu item pointer. GHashTable* attributes; // Item attributes. GHashTable* links; // Item links. }; @@ -50,7 +49,6 @@ struct item static void g_lo_menu_struct_item_init (struct item *menu_item) { -// menu_item->menu_item = NULL; menu_item->attributes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); menu_item->links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } @@ -134,7 +132,6 @@ g_lo_menu_insert (GLOMenu *menu, gint position, const gchar *label) { -// puts(__FUNCTION__); g_return_if_fail (G_IS_LO_MENU (menu)); if (position < 0 || position > (gint) menu->items->len) @@ -180,7 +177,6 @@ g_lo_menu_set_attribute_value (GLOMenu *menu, const gchar *attribute, GVariant *value) { -// puts(__FUNCTION__); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (attribute != NULL); g_return_if_fail (valid_attribute_name (attribute)); @@ -194,6 +190,7 @@ g_lo_menu_set_attribute_value (GLOMenu *menu, g_hash_table_insert (menu_item.attributes, g_strdup (attribute), g_variant_ref_sink (value)); else g_hash_table_remove (menu_item.attributes, attribute); + } void @@ -201,7 +198,6 @@ g_lo_menu_set_label (GLOMenu *menu, gint position, const gchar *label) { -// puts(__FUNCTION__); g_return_if_fail (G_IS_LO_MENU (menu)); GVariant *value; @@ -215,21 +211,46 @@ g_lo_menu_set_label (GLOMenu *menu, } void -g_lo_menu_set_label_in_section (GLOMenu *menu, - gint section, - gint position, - const gchar *label) +g_lo_menu_set_label_to_item_in_section (GLOMenu *menu, + gint section, + gint position, + const gchar *label) { -// puts(__FUNCTION__); g_return_if_fail (G_IS_LO_MENU (menu)); - struct item menu_item = g_array_index (menu->items, struct item, section); - - GLOMenu *model = G_LO_MENU (g_hash_table_lookup (menu_item.links, G_MENU_LINK_SECTION)); + GLOMenu *model = G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class) + ->get_item_link (G_MENU_MODEL (menu), section, G_MENU_LINK_SECTION)); g_return_if_fail (model != NULL); g_lo_menu_set_label (model, position, label); + + // Notify the update. + g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1); +} + +gchar * +g_lo_menu_get_label_from_item_in_section (GLOMenu *menu, + gint section, + gint position) +{ + g_return_val_if_fail (G_IS_LO_MENU (menu), NULL); + + GLOMenu *model = G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class) + ->get_item_link (G_MENU_MODEL (menu), section, G_MENU_LINK_SECTION)); + + g_return_val_if_fail (model != NULL, NULL); + + struct item menu_item = g_array_index (model->items, struct item, position); + + + + GVariant *current_label = (GVariant*) g_hash_table_lookup (menu_item.attributes, G_MENU_ATTRIBUTE_LABEL); + + if (current_label) + return (gchar*) g_variant_get_string (current_label, NULL); + else + return NULL; } void @@ -238,7 +259,6 @@ g_lo_menu_set_action_and_target_value (GLOMenu *menu, const gchar *action, GVariant *target_value) { -// puts(__FUNCTION__); g_return_if_fail (G_IS_LO_MENU (menu)); GVariant *action_value; @@ -273,26 +293,9 @@ g_lo_menu_set_action_and_target_value_to_item_in_section (GLOMenu *menu, g_return_if_fail (model != NULL); g_lo_menu_set_action_and_target_value (model, position, command, target_value); -} - -gchar* -g_lo_menu_get_action_value_from_item_in_section (GLOMenu *menu, - gint section, - gint position) -{ - g_return_val_if_fail (G_IS_LO_MENU (menu), NULL); - - GMenuModel *model = G_MENU_MODEL_CLASS (g_lo_menu_parent_class) - ->get_item_link (G_MENU_MODEL (menu), section, G_MENU_LINK_SECTION); - - GVariant *action = g_menu_model_get_item_attribute_value (model, position, G_MENU_ATTRIBUTE_LABEL, NULL); - - gchar *action_name = NULL; - if (action) - action_name = g_strdup (g_variant_get_string (action, NULL)); - - return action_name; + // Notify the update. + g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1); } void @@ -301,7 +304,6 @@ g_lo_menu_set_link (GLOMenu *menu, const gchar *link, GMenuModel *model) { -// puts(__FUNCTION__); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (link != NULL); g_return_if_fail (valid_attribute_name (link)); @@ -318,11 +320,11 @@ g_lo_menu_set_link (GLOMenu *menu, } void -g_lo_menu_insert_section (GLOMenu *menu, - gint position, - const gchar *label) +g_lo_menu_insert_section (GLOMenu *menu, + gint position, + const gchar *label, + GMenuModel* section) { -// puts(__FUNCTION__); g_return_if_fail (G_IS_LO_MENU (menu)); if (position < 0 || position > (gint) menu->items->len) @@ -335,25 +337,33 @@ g_lo_menu_insert_section (GLOMenu *menu, g_array_insert_val (menu->items, position, menu_item); g_lo_menu_set_label (menu, position, label); - - GMenuModel *section = G_MENU_MODEL (g_lo_menu_new()); g_lo_menu_set_link (menu, position, G_MENU_LINK_SECTION, section); g_menu_model_items_changed (G_MENU_MODEL (menu), position, 0, 1); - -// g_lo_menu_insert (menu, position, label); -// menu_item = g_lo_menu_item_new_section (label, section); -// g_lo_menu_insert_item (menu, position, menu_item); -// g_object_unref (menu_item); } void -g_lo_menu_set_submenu (GLOMenu *menu, - gint position, - GMenuModel *submenu) +g_lo_menu_new_section (GLOMenu *menu, + gint position, + const gchar *label) { -// puts(__FUNCTION__); - g_lo_menu_set_link (menu, position, G_MENU_LINK_SUBMENU, submenu); + GMenuModel *section = G_MENU_MODEL (g_lo_menu_new()); + + g_lo_menu_insert_section (menu, position, label, section); + +// g_object_unref (section); +} + + + +GLOMenu * +g_lo_menu_get_section (GLOMenu *menu, + gint section) +{ + g_return_val_if_fail (G_IS_LO_MENU (menu), NULL); + + return G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class) + ->get_item_link (G_MENU_MODEL (menu), section, G_MENU_LINK_SECTION)); } void @@ -371,7 +381,7 @@ g_lo_menu_set_submenu_to_item_in_section (GLOMenu *menu, g_return_if_fail (model != NULL); - g_lo_menu_set_submenu (model, position, submenu); + g_lo_menu_set_link (model, position, G_MENU_LINK_SUBMENU, submenu); } static void @@ -387,7 +397,6 @@ void g_lo_menu_remove (GLOMenu *menu, gint position) { - printf("%s - %d\n", __FUNCTION__, position); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (0 <= position && position < (gint) menu->items->len); diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index 1eb32c1..5cc65eb 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -60,15 +60,15 @@ static void UpdateNativeMenu( GtkSalMenu* pMenu ) { if ( pMenu == NULL ) return; - Menu* pVCLMenu = pMenu->GetMenu(); - for ( sal_uInt16 i = 0; i < pMenu->GetItemCount(); i++ ) { - sal_uInt16 nId = pVCLMenu->GetItemId( i ); GtkSalMenuItem *pSalMenuItem = pMenu->GetItemAtPos( i ); + sal_uInt16 nId = pSalMenuItem->mnId; - if ( pVCLMenu->GetItemType( nId ) == MENUITEM_SEPARATOR ) + if ( pSalMenuItem->mnType == MENUITEM_SEPARATOR ) continue; + Menu* pVCLMenu = pSalMenuItem->mpVCLMenu; + String aText = pVCLMenu->GetItemText( nId ); String aCommand = pVCLMenu->GetItemCommand( nId ); sal_Bool itemEnabled = pVCLMenu->IsItemEnabled( nId ); @@ -76,8 +76,8 @@ static void UpdateNativeMenu( GtkSalMenu* pMenu ) { sal_Bool itemChecked = pVCLMenu->IsItemChecked( nId ); // Force updating of native menu labels. - pMenu->SetItemText( i, pSalMenuItem, aText ); pMenu->SetItemCommand( i, pSalMenuItem, aCommand ); + pMenu->SetItemText( i, pSalMenuItem, aText ); pMenu->EnableItem( i, itemEnabled ); // pMenu->SetAccelerator( i, pSalMenuItem, nAccelKey, nAccelKey.GetName( pMenu->GetFrame()->GetWindow() ) ); // pMenu->CheckItem( i, itemChecked ); @@ -86,8 +86,8 @@ static void UpdateNativeMenu( GtkSalMenu* pMenu ) { if ( pSubmenu && pSubmenu->GetMenu() ) { pSubmenu->GetMenu()->Activate(); - UpdateNativeMenu( pSubmenu ); pSubmenu->GetMenu()->Deactivate(); + UpdateNativeMenu( pSubmenu ); } } } @@ -215,7 +215,7 @@ GActionGroup* GetActionGroupFromMenubar( GtkSalMenu *pMenu ) * GtkSalMenu */ -void GtkSalMenu::GetInsertionData( unsigned nPos, unsigned *insertSection, unsigned *insertPos ) +void GtkSalMenu::GetItemSectionAndPosition( unsigned nPos, unsigned *insertSection, unsigned *insertPos ) { if ( mpVCLMenu == NULL || nPos >= mpVCLMenu->GetItemCount() ) { @@ -253,7 +253,7 @@ GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) : } mpMenuModel = G_MENU_MODEL( g_lo_menu_new() ); - g_lo_menu_insert_section( G_LO_MENU( mpMenuModel ), 0, NULL); + g_lo_menu_new_section( G_LO_MENU( mpMenuModel ), 0, NULL); } GtkSalMenu::~GtkSalMenu() @@ -276,7 +276,7 @@ GtkSalMenu::~GtkSalMenu() sal_Bool GtkSalMenu::VisibleMenuBar() { - return sal_False; + return sal_True; } void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) @@ -293,45 +293,44 @@ void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) if ( pItem->mnType != MENUITEM_SEPARATOR ) { unsigned nInsertSection, nInsertPos; - GetInsertionData( nPos, &nInsertSection, &nInsertPos ); + GetItemSectionAndPosition( nPos, &nInsertSection, &nInsertPos ); g_lo_menu_insert_in_section( G_LO_MENU( mpMenuModel ), nInsertSection, nInsertPos, "EMPTY STRING" ); } else { - g_lo_menu_insert_section( G_LO_MENU( mpMenuModel ), MENU_APPEND, NULL ); + g_lo_menu_new_section( G_LO_MENU( mpMenuModel ), MENU_APPEND, NULL ); } } void GtkSalMenu::RemoveItem( unsigned nPos ) { GLOMenu* pMenu = G_LO_MENU( mpMenuModel ); + GtkSalMenuItem *pItem = maItems[ nPos ]; // If item is a separator, the last section of the menu is removed. - if ( mpVCLMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR ) + if ( pItem->mnType != MENUITEM_SEPARATOR ) { - unsigned nSection, nItemPos; - GetInsertionData( nPos, &nSection, &nItemPos ); - -// gchar *aCommand = g_lo_menu_get_action_value_from_item_in_section( pMenu, nSection, nItemPos ); + if ( pItem->maCommand ) { + GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( GetActionGroupFromMenubar( this ) ); -// if ( aCommand ) { -// GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( GetActionGroupFromMenubar( this ) ); + if ( pActionGroup != NULL ) + g_lo_action_group_remove( pActionGroup, pItem->maCommand ); -// if ( pActionGroup != NULL ) -// g_lo_action_group_remove( pActionGroup, aCommand ); + g_free ( pItem->maCommand ); + pItem->maCommand = NULL; + } -// g_free( aCommand ); -// } + unsigned nSection, nItemPos; + GetItemSectionAndPosition( nPos, &nSection, &nItemPos ); - cout << __FUNCTION__ << " - " << nSection << " - " << nItemPos << " - " << nPos << " - " << this << endl; g_lo_menu_remove_from_section( pMenu, nSection, nItemPos ); } else { gint nSection = g_menu_model_get_n_items( mpMenuModel ) - 1; - cout << __FUNCTION__ << " - " << nSection << endl; - if ( nSection < 0 ) + + if ( nSection > 0 ) g_lo_menu_remove( pMenu, nSection ); } @@ -340,7 +339,6 @@ void GtkSalMenu::RemoveItem( unsigned nPos ) void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ) { - cout << __FUNCTION__ << endl; GtkSalMenuItem *pItem = static_cast< GtkSalMenuItem* >( pSalMenuItem ); GtkSalMenu *pGtkSubMenu = static_cast< GtkSalMenu* >( pSubMenu ); @@ -352,9 +350,8 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig // Update item in GMenuModel. unsigned nSection, nItemPos; - GetInsertionData( nPos, &nSection, &nItemPos ); + GetItemSectionAndPosition( nPos, &nSection, &nItemPos ); - cout << __FUNCTION__ << " - " << nSection << " - " << nItemPos << " - " << nPos << " - " << this << endl; g_lo_menu_set_submenu_to_item_in_section( G_LO_MENU( mpMenuModel ), nSection, nItemPos, pGtkSubMenu->mpMenuModel ); } @@ -367,12 +364,10 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) GdkWindow *gdkWindow = gtk_widget_get_window( widget ); if (gdkWindow) { - gpointer pMenu = g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ); + GLOMenu* pMainMenu = G_LO_MENU( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ) ); GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-action-group" ) ); - if ( pMenu && pActionGroup ) { -// mpMenuModel = G_MENU_MODEL( pMenu ); - + if ( pMainMenu && pActionGroup ) { // Merge current action group with the exported one g_lo_action_group_clear( pActionGroup ); g_lo_action_group_merge( G_LO_ACTION_GROUP( mpActionGroup ), pActionGroup ); @@ -381,6 +376,8 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) mpActionGroup = G_ACTION_GROUP( pActionGroup ); } else { + pMainMenu = g_lo_menu_new(); + g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-menubar", mpMenuModel, ObjectDestroyedNotify ); g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-action-group", mpActionGroup, ObjectDestroyedNotify ); @@ -414,11 +411,16 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) g_free( aDBusWindowPath ); g_free( aDBusMenubarPath ); } -// updateNativeMenu( this ); -// updateNativeMenu( this ); -// // Refresh the menu every second. -// // This code is a workaround until required modifications in Gtk+ are available. + // Menubar has only one section, so we put it on the exported menu. +// GMenuModel *pSection = G_MENU_MODEL( g_lo_menu_get_section( G_LO_MENU( mpMenuModel ), 0 ) ); +// g_lo_menu_insert_section( pMainMenu, 0, NULL, pSection ); + +// UpdateNativeMenu( this ); +// UpdateNativeMenu( this ); + + // Refresh the menu every second. + // This code is a workaround until required modifications in Gtk+ are available. g_timeout_add_seconds( 1, GenerateMenu, this ); } } @@ -433,29 +435,28 @@ const GtkSalFrame* GtkSalMenu::GetFrame() const void GtkSalMenu::CheckItem( unsigned nPos, sal_Bool bCheck ) { -// GtkSalMenuItem* pItem = maItems[ nPos ]; + GtkSalMenuItem* pItem = maItems[ nPos ]; -// if ( pItem->maCommand == NULL || g_strcmp0( pItem->maCommand, "" ) == 0 ) -// return; - -// GActionGroup* pActionGroup = GetActionGroupFromMenubar( this ); + if ( pItem->mpSubMenu ) + return; -// if ( !pActionGroup ) -// return; + if ( pItem->maCommand == NULL || g_strcmp0( pItem->maCommand, "" ) == 0 ) + return; + GActionGroup* pActionGroup = GetActionGroupFromMenubar( this ); -// if ( !pItem || pItem->mpSubMenu ) -// return; + if ( !pActionGroup ) + return; -// GVariant *pCheckValue = NULL; + GVariant *pCheckValue = NULL; -// if ( pItem->mnBits & MIB_CHECKABLE ) { -// gboolean bCheckedValue = ( bCheck == sal_True ) ? TRUE : FALSE; -// pCheckValue = g_variant_new_boolean( bCheckedValue ); -// } + if ( pItem->mnBits & MIB_CHECKABLE ) { + gboolean bCheckedValue = ( bCheck == sal_True ) ? TRUE : FALSE; + pCheckValue = g_variant_new_boolean( bCheckedValue ); + } -// if ( pCheckValue ) -// g_action_group_change_action_state( pActionGroup, pItem->maCommand, pCheckValue ); + if ( pCheckValue ) + g_action_group_change_action_state( pActionGroup, pItem->maCommand, pCheckValue ); } void GtkSalMenu::EnableItem( unsigned nPos, sal_Bool bEnable ) @@ -485,37 +486,25 @@ void GtkSalMenu::SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const rt rtl::OUString aText = rText.replace( '~', '_' ); rtl::OString aConvertedText = OUStringToOString( aText, RTL_TEXTENCODING_UTF8 ); -// GtkSalMenuItem *pItem = static_cast<GtkSalMenuItem*>( pSalMenuItem ); - unsigned nSection, nItemPos; - GetInsertionData( nPos, &nSection, &nItemPos ); + GetItemSectionAndPosition( nPos, &nSection, &nItemPos ); - cout << __FUNCTION__ << " - " << nSection << " - " << nItemPos << " - " << nPos << " - " << this << " - " << aConvertedText.getStr() << endl; + // Update item text only when necessary. + sal_Bool bSetLabel = sal_True; -// GLOMenu* pSection = G_LO_MENU( maSections[ nSection ] ); - -// GVariant* aCurrentLabel = NULL; - -// if ( g_menu_model_get_n_items( maSections[ nSection ] ) > nInsertPos ) -// aCurrentLabel = g_menu_model_get_item_attribute_value( G_MENU_MODEL( pSection ), nInsertPos, G_MENU_ATTRIBUTE_LABEL, G_VARIANT_TYPE_STRING ); - -// sal_Bool bSetLabel = sal_True; - -// if ( aCurrentLabel != NULL ) { -// if ( g_strcmp0( g_variant_get_string( aCurrentLabel, NULL ), aConvertedText.getStr() ) == 0 ) { -// bSetLabel = sal_False; -// } -// } + GtkSalMenuItem* pItem = static_cast< GtkSalMenuItem* >( pSalMenuItem ); -// if ( bSetLabel == sal_True ) { - g_lo_menu_set_label_in_section( G_LO_MENU( mpMenuModel ), nSection, nItemPos, aConvertedText.getStr() ); + // FIXME: It would be better retrieving the label from the menu itself, but this currently crashes the app. + if ( pItem->maLabel && g_strcmp0( pItem->maLabel, aConvertedText.getStr() ) == 0 ) + bSetLabel = sal_False; -//// cout << __FUNCTION__ << " - " << aConvertedText.getStr() << " - Section: " << nSection << " - Position: " << nInsertPos << " - Section size: " << g_menu_model_get_n_items( G_MENU_MODEL( pSection ) ) << endl; -// if ( g_menu_model_get_n_items( G_MENU_MODEL( pSection ) ) > nInsertPos ) -// g_lo_menu_remove( pSection, nInsertPos ); + if ( bSetLabel == sal_True ) { + if ( pItem->maLabel ) + g_free( pItem->maLabel ); -// g_lo_menu_insert_item( pSection, nInsertPos, pItem ); -// } + pItem->maLabel = g_strdup( aConvertedText.getStr() ); + g_lo_menu_set_label_to_item_in_section( G_LO_MENU( mpMenuModel ), nSection, nItemPos, pItem->maLabel ); + } } void GtkSalMenu::SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage) @@ -567,21 +556,19 @@ void GtkSalMenu::SetItemCommand( unsigned nPos, SalMenuItem* pSalMenuItem, const if ( pActionGroup == NULL ) return; -// gboolean bChecked = ( pItem->mpVCLMenu->IsItemChecked( pItem->mnId ) ) ? TRUE : FALSE; - -// if ( pItem->mnBits & MIB_CHECKABLE ) -// { -//// cout << "Item with command: " << pItem->maCommand << " is checkmark button." << endl; + gboolean bChecked = ( pItem->mpVCLMenu->IsItemChecked( pItem->mnId ) ) ? TRUE : FALSE; -// // Item is a checkmark button. -// GVariantType* pStateType = g_variant_type_new( (gchar*) G_VARIANT_TYPE_BOOLEAN ); -// GVariant* pState = g_variant_new_boolean( bChecked ); + if ( pItem->mnBits & MIB_CHECKABLE ) + { + // Item is a checkmark button. + GVariantType* pStateType = g_variant_type_new( (gchar*) G_VARIANT_TYPE_BOOLEAN ); + GVariant* pState = g_variant_new_boolean( bChecked ); -// g_lo_action_group_insert_stateful( pActionGroup, aCommand, pItem, NULL, pStateType, NULL, pState ); -// } + g_lo_action_group_insert_stateful( pActionGroup, aCommand, pItem, NULL, pStateType, NULL, pState ); + } // else if ( pItem->mnBits & MIB_RADIOCHECK ) // { -//// cout << "Item with command: " << pItem->maCommand << " is a radio button." << endl; +// cout << "Item with command: " << aCommand << " is a radio button." << endl; // // Item is a radio button. //// GVariantType* pParameterType = g_variant_type_new( (gchar*) G_VARIANT_TYPE_STRING ); @@ -591,28 +578,31 @@ void GtkSalMenu::SetItemCommand( unsigned nPos, SalMenuItem* pSalMenuItem, const //// g_lo_action_group_insert_stateful( pActionGroup, aCommand, pItem, pParameterType, pStateType, NULL, pState ); // } -// else -// { + else + { // Item is not special, so insert a stateless action. g_lo_action_group_insert( pActionGroup, aCommand, pItem ); -// } + } // Menu item is not updated unless it's necessary. -// if ( ( pItem->maCommand != NULL ) && ( g_strcmp0( pItem->maCommand, aCommand ) == 0 ) ) -// return; - -// if ( pItem->maCommand != NULL ) -// g_free( pItem->maCommand ); + if ( ( pItem->maCommand != NULL ) && ( g_strcmp0( pItem->maCommand, aCommand ) == 0 ) ) + return; -// pItem->maCommand = g_strdup( aCommand ); + if ( pItem->maCommand != NULL ) + g_free( pItem->maCommand ); - unsigned nSection, nItemPos; - GetInsertionData( nPos, &nSection, &nItemPos ); + pItem->maCommand = g_strdup( aCommand ); - cout << __FUNCTION__ << " - " << nSection << " - " << nItemPos << " - " << nPos << " - " << this << endl; + unsigned nSection, nItemPos; + GetItemSectionAndPosition( nPos, &nSection, &nItemPos ); gchar* aItemCommand = g_strconcat("win.", aCommand, NULL ); + if ( pItem->maCommand ) + g_free( pItem->maCommand ); + + pItem->maCommand = g_strdup( aCommand ); + g_lo_menu_set_action_and_target_value_to_item_in_section( G_LO_MENU( mpMenuModel ), nSection, nItemPos, aItemCommand, NULL ); g_free( aItemCommand ); @@ -636,6 +626,8 @@ GtkSalMenuItem::GtkSalMenuItem( const SalItemParams* pItemData ) : mnId( pItemData->nId ), mnBits( pItemData->nBits ), mnType( pItemData->eType ), + maCommand( NULL ), + maLabel( NULL ), mpVCLMenu( pItemData->pMenu ), mpParentMenu( NULL ), mpSubMenu( NULL ) @@ -644,7 +636,11 @@ GtkSalMenuItem::GtkSalMenuItem( const SalItemParams* pItemData ) : GtkSalMenuItem::~GtkSalMenuItem() { -// mpVCLMenu = NULL; + if ( maCommand ) + g_free( maCommand ); + + if ( maLabel ) + g_free( maLabel ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits