diff options
author | Antonio Fernandez <antonio.fernandez@aentos.es> | 2012-10-17 20:06:11 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2012-11-14 13:52:57 +0100 |
commit | 34504e4af678b52b6d6cfe7519ee1934f89c95dd (patch) | |
tree | c55a3767f9912d8cac1eac5a84a29a972e044953 | |
parent | 4e112800895748775a4e3d194985f3baa78f1270 (diff) |
Chart menu works now.
Change-Id: I95861a5af8b9c72c74840868d0530d5855b87785
-rw-r--r-- | vcl/inc/unx/gtk/glomenu.h | 4 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtkframe.hxx | 1 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtksalmenu.hxx | 3 | ||||
-rw-r--r-- | vcl/unx/gtk/window/gloactiongroup.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/gtk/window/glomenu.cxx | 114 | ||||
-rw-r--r-- | vcl/unx/gtk/window/gtkframe.cxx | 48 | ||||
-rw-r--r-- | vcl/unx/gtk/window/gtksalmenu.cxx | 143 |
7 files changed, 221 insertions, 94 deletions
diff --git a/vcl/inc/unx/gtk/glomenu.h b/vcl/inc/unx/gtk/glomenu.h index 4c7c3e568ecb..a1a615b3ba19 100644 --- a/vcl/inc/unx/gtk/glomenu.h +++ b/vcl/inc/unx/gtk/glomenu.h @@ -125,6 +125,10 @@ void g_lo_menu_set_submenu_to_item_in_section (GLOMenu gint position, GMenuModel *submenu); +void g_lo_menu_new_submenu_in_item_in_section (GLOMenu *menu, + gint section, + gint position); + GLOMenu * g_lo_menu_get_submenu_from_item_in_section (GLOMenu *menu, gint section, gint position); diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index cc4451a1e331..b382e7e6d19d 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -303,6 +303,7 @@ public: guint m_nMenuExportId; guint m_nActionGroupExportId; + void FlushConnection(); // dispatches an event, returns true if dispatched // and false else; if true was returned the event should diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index 6e7084bdc3e9..46ba21547339 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -45,6 +45,7 @@ private: sal_Bool mbMenuBar; Menu* mpVCLMenu; + GtkSalMenu* mpOldSalMenu; GtkSalMenu* mpParentSalMenu; const GtkSalFrame* mpFrame; @@ -102,7 +103,7 @@ public: void DispatchCommand( gint itemId, const gchar* aCommand ); void Activate( const gchar* aMenuCommand ); void Deactivate( const gchar* aMenuCommand ); - void DisconnectFrame(); +// void DisconnectFrame(); void Display( sal_Bool bVisible ); void UpdateNativeMenu(); // void UpdateNativeSubMenu(); diff --git a/vcl/unx/gtk/window/gloactiongroup.cxx b/vcl/unx/gtk/window/gloactiongroup.cxx index 756779a559ca..9f65f37cd4d5 100644 --- a/vcl/unx/gtk/window/gloactiongroup.cxx +++ b/vcl/unx/gtk/window/gloactiongroup.cxx @@ -255,6 +255,8 @@ g_lo_action_group_activate (GActionGroup *group, { GTK_YIELD_GRAB(); + printf("%s\n", __FUNCTION__); + GLOActionGroup *lo_group = G_LO_ACTION_GROUP (group); GtkSalFrame *pFrame = lo_group->priv->frame; diff --git a/vcl/unx/gtk/window/glomenu.cxx b/vcl/unx/gtk/window/glomenu.cxx index 2ecf23a24471..cc8488911923 100644 --- a/vcl/unx/gtk/window/glomenu.cxx +++ b/vcl/unx/gtk/window/glomenu.cxx @@ -91,7 +91,7 @@ valid_attribute_name (const gchar *name) */ static gboolean -g_lo_menu_is_mutable (GMenuModel *model) +g_lo_menu_is_mutable (GMenuModel*) { // Menu is always mutable. return TRUE; @@ -100,8 +100,12 @@ g_lo_menu_is_mutable (GMenuModel *model) static gint g_lo_menu_get_n_items (GMenuModel *model) { + //printf("[%p] %s\n", model, __FUNCTION__); + g_return_val_if_fail (model != NULL, 0); GLOMenu *menu = G_LO_MENU (model); + g_return_val_if_fail (menu->items != NULL, 0); + //printf("[%p] %s - length: %d\n", model, __FUNCTION__, menu->items->len); return menu->items->len; } @@ -109,16 +113,18 @@ gint g_lo_menu_get_n_items_from_section (GLOMenu *menu, gint section) { - g_return_val_if_fail (0 <= section && section < (gint) menu->items->len, -1); + //printf("[%p] %s - section: %d\n", menu, __FUNCTION__, section); + g_return_val_if_fail (0 <= section && section < (gint) menu->items->len, 0); GLOMenu *model = g_lo_menu_get_section (menu, section); - g_return_val_if_fail (model != NULL, -1); + g_return_val_if_fail (model != NULL, 0); gint length = model->items->len; g_object_unref (model); + //printf("[%p] %s - section: %d - length: %d\n", menu, __FUNCTION__, section, length); return length; } @@ -130,6 +136,7 @@ g_lo_menu_get_item_attributes (GMenuModel *model, GLOMenu *menu = G_LO_MENU (model); *table = g_hash_table_ref (g_array_index (menu->items, struct item, position).attributes); + //printf("[%p] %s - position: %d - table: %p - *table: %p\n", model, __FUNCTION__, position, table, ((table) ? *table : NULL)); } static void @@ -140,6 +147,7 @@ g_lo_menu_get_item_links (GMenuModel *model, GLOMenu *menu = G_LO_MENU (model); *table = g_hash_table_ref (g_array_index (menu->items, struct item, position).links); + //printf("[%p] %s - position: %d - table: %p - *table: %p - items: %p\n", model, __FUNCTION__, position, table, ((table) ? *table : NULL), ((menu) ? menu->items : NULL)); } void @@ -147,20 +155,7 @@ g_lo_menu_insert (GLOMenu *menu, gint position, const gchar *label) { - g_return_if_fail (G_IS_LO_MENU (menu)); - - if (position < 0 || position > (gint) menu->items->len) - position = menu->items->len; - - struct item menu_item; - - g_lo_menu_struct_item_init(&menu_item); - - g_array_insert_val (menu->items, position, menu_item); - - g_lo_menu_set_label (menu, position, label); - - g_menu_model_items_changed (G_MENU_MODEL (menu), position, 0, 1); + g_lo_menu_insert_section (menu, position, label, NULL); } void @@ -169,6 +164,7 @@ g_lo_menu_insert_in_section (GLOMenu *menu, gint position, const gchar *label) { + //printf("[%p] %s - section: %d - position: %d - label: %s\n", menu, __FUNCTION__, section, position, label); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (0 <= section && section < (gint) menu->items->len); @@ -193,6 +189,7 @@ g_lo_menu_set_attribute_value (GLOMenu *menu, const gchar *attribute, GVariant *value) { + //printf("[%p] %s - position: %d - attribute: %s - value: %p\n", menu, __FUNCTION__, position, attribute, value); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (attribute != NULL); g_return_if_fail (valid_attribute_name (attribute)); @@ -215,6 +212,7 @@ g_lo_menu_get_attribute_value_from_item_in_section (GLOMenu *menu, const gchar *attribute, const GVariantType *type) { + //printf("[%p] %s - section: %d - position: %d - attribute: %s - type: %p\n", menu, __FUNCTION__, section, position, attribute, type); GMenuModel *model = G_MENU_MODEL (g_lo_menu_get_section (menu, section)); g_return_val_if_fail (model != NULL, NULL); @@ -234,6 +232,7 @@ g_lo_menu_set_label (GLOMenu *menu, gint position, const gchar *label) { + //printf("[%p] %s - position: %d - label: %s\n", menu, __FUNCTION__, position, label); g_return_if_fail (G_IS_LO_MENU (menu)); GVariant *value; @@ -252,16 +251,19 @@ g_lo_menu_set_label_to_item_in_section (GLOMenu *menu, gint position, const gchar *label) { + //printf("[%p] %s - section: %d - position: %d - label: %s\n", menu, __FUNCTION__, section, position, label); g_return_if_fail (G_IS_LO_MENU (menu)); GLOMenu *model = g_lo_menu_get_section (menu, section); g_return_if_fail (model != NULL); + g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0); + g_lo_menu_set_label (model, position, label); // Notify the update. - g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1); + g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1); g_object_unref (model); } @@ -271,6 +273,7 @@ g_lo_menu_get_label_from_item_in_section (GLOMenu *menu, gint section, gint position) { + //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position); g_return_val_if_fail (G_IS_LO_MENU (menu), NULL); GVariant *label_value = g_lo_menu_get_attribute_value_from_item_in_section (menu, @@ -296,6 +299,7 @@ g_lo_menu_set_action_and_target_value (GLOMenu *menu, const gchar *action, GVariant *target_value) { + //printf("[%p] %s - position: %d - action: %s - target value: %p\n", menu, __FUNCTION__, position, action, target_value); g_return_if_fail (G_IS_LO_MENU (menu)); GVariant *action_value; @@ -323,6 +327,7 @@ g_lo_menu_set_action_and_target_value_to_item_in_section (GLOMenu *menu, const gchar *command, GVariant *target_value) { + //printf("[%p] %s - section: %d - position: %d - command: %s - target value: %p\n", menu, __FUNCTION__, section, position, command, target_value); g_return_if_fail (G_IS_LO_MENU (menu)); GLOMenu *model = g_lo_menu_get_section (menu, section); @@ -340,12 +345,15 @@ g_lo_menu_set_accelerator_to_item_in_section (GLOMenu *menu, gint position, const gchar *accelerator) { + //printf("[%p] %s - section: %d - position: %d - accelerator: %s\n", menu, __FUNCTION__, section, position, accelerator); g_return_if_fail (G_IS_LO_MENU (menu)); GLOMenu *model = g_lo_menu_get_section (menu, section); g_return_if_fail (model != NULL); + g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0); + GVariant *value; if (accelerator != NULL) @@ -356,7 +364,7 @@ g_lo_menu_set_accelerator_to_item_in_section (GLOMenu *menu, g_lo_menu_set_attribute_value (model, position, G_LO_MENU_ATTRIBUTE_ACCELERATOR, value); // Notify the update. - g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1); + g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1); g_object_unref (model); } @@ -366,6 +374,7 @@ g_lo_menu_get_accelerator_from_item_in_section (GLOMenu *menu, gint section, gint position) { + //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position); g_return_val_if_fail (G_IS_LO_MENU (menu), NULL); GVariant *accel_value = g_lo_menu_get_attribute_value_from_item_in_section (menu, @@ -391,12 +400,15 @@ g_lo_menu_set_command_to_item_in_section (GLOMenu *menu, gint position, const gchar *command) { + //printf("[%p] %s - section: %d - position: %d - command: %s\n", menu, __FUNCTION__, section, position, command); g_return_if_fail (G_IS_LO_MENU (menu)); GLOMenu *model = g_lo_menu_get_section (menu, section); g_return_if_fail (model != NULL); + g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 0); + GVariant *value; if (command != NULL) @@ -407,7 +419,7 @@ g_lo_menu_set_command_to_item_in_section (GLOMenu *menu, g_lo_menu_set_attribute_value (model, position, G_LO_MENU_ATTRIBUTE_COMMAND, value); // Notify the update. - g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1); + g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1); g_object_unref (model); } @@ -417,6 +429,7 @@ g_lo_menu_get_command_from_item_in_section (GLOMenu *menu, gint section, gint position) { + //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position); g_return_val_if_fail (G_IS_LO_MENU (menu), NULL); GVariant *command_value = g_lo_menu_get_attribute_value_from_item_in_section (menu, @@ -442,6 +455,7 @@ g_lo_menu_set_link (GLOMenu *menu, const gchar *link, GMenuModel *model) { + //printf("[%p] %s - position: %d - link: %s - model: %p\n", menu, __FUNCTION__, position, link, model); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (link != NULL); g_return_if_fail (valid_attribute_name (link)); @@ -449,6 +463,8 @@ g_lo_menu_set_link (GLOMenu *menu, if (position < 0 || position >= (gint) menu->items->len) position = menu->items->len - 1; +// printf ("%s - position: %d\n", __FUNCTION__, position); + struct item menu_item = g_array_index (menu->items, struct item, position); if (model != NULL) @@ -463,6 +479,7 @@ g_lo_menu_insert_section (GLOMenu *menu, const gchar *label, GMenuModel *section) { + //printf("[%p] %s - position: %d - label: %s - section: %p\n", menu, __FUNCTION__, position, label, section); g_return_if_fail (G_IS_LO_MENU (menu)); if (position < 0 || position > (gint) menu->items->len) @@ -470,7 +487,7 @@ g_lo_menu_insert_section (GLOMenu *menu, struct item menu_item; - g_lo_menu_struct_item_init (&menu_item); + g_lo_menu_struct_item_init(&menu_item); g_array_insert_val (menu->items, position, menu_item); @@ -485,19 +502,19 @@ g_lo_menu_new_section (GLOMenu *menu, gint position, const gchar *label) { + //printf("[%p] %s - position: %d - label: %s\n", menu, __FUNCTION__, position, label); GMenuModel *section = G_MENU_MODEL (g_lo_menu_new()); g_lo_menu_insert_section (menu, position, label, section); -// g_object_unref (section); + g_object_unref (section); } - - GLOMenu * g_lo_menu_get_section (GLOMenu *menu, gint section) { + //printf("[%p] %s - section: %d\n", menu, __FUNCTION__, 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) @@ -505,11 +522,39 @@ g_lo_menu_get_section (GLOMenu *menu, } void +g_lo_menu_new_submenu_in_item_in_section (GLOMenu *menu, + gint section, + gint position) +{ + g_return_if_fail (G_IS_LO_MENU (menu)); + g_return_if_fail (0 <= section && section < (gint) menu->items->len); + + GLOMenu* model = g_lo_menu_get_section (menu, section); + + g_return_if_fail (model != NULL); + g_return_if_fail (0 <= position && position < model->items->len); + + struct item menu_item = g_array_index (model->items, struct item, position); + + GMenuModel* submenu = G_MENU_MODEL (g_lo_menu_new()); + + g_lo_menu_set_link (model, position, G_MENU_LINK_SUBMENU, submenu); + + g_object_unref (submenu); + + g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1); + + g_object_unref (model); +} + + +void g_lo_menu_set_submenu_to_item_in_section (GLOMenu *menu, gint section, gint position, GMenuModel *submenu) { + printf("[%p] %s (begin) - section: %d - position: %d - submenu: %p\n", menu, __FUNCTION__, section, position, submenu); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (0 <= section && section < (gint) menu->items->len); @@ -523,6 +568,7 @@ g_lo_menu_set_submenu_to_item_in_section (GLOMenu *menu, g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1); g_object_unref (model); + printf("[%p] %s (end) - section: %d - position: %d - submenu: %p\n", menu, __FUNCTION__, section, position, submenu); } GLOMenu * @@ -530,6 +576,7 @@ g_lo_menu_get_submenu_from_item_in_section (GLOMenu *menu, gint section, gint position) { + //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position); g_return_val_if_fail (G_IS_LO_MENU (menu), NULL); g_return_val_if_fail (0 <= section && section < (gint) menu->items->len, NULL); @@ -537,14 +584,17 @@ g_lo_menu_get_submenu_from_item_in_section (GLOMenu *menu, g_return_val_if_fail (model != NULL, NULL); - GMenuModel *submenu = NULL; + GLOMenu *submenu = NULL; if (0 <= position && position < (gint) model->items->len) - submenu = g_menu_model_get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU); + + submenu = G_LO_MENU (G_MENU_MODEL_CLASS (g_lo_menu_parent_class) + ->get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU)); + //submenu = g_menu_model_get_item_link (G_MENU_MODEL (model), position, G_MENU_LINK_SUBMENU); g_object_unref (model); - return G_LO_MENU (submenu); + return submenu; } void @@ -553,12 +603,15 @@ g_lo_menu_set_submenu_action_to_item_in_section (GLOMenu *menu, gint position, const gchar *action) { + //printf("[%p] %s - section: %d - position: %d - action: %s\n", menu, __FUNCTION__, section, position, action); g_return_if_fail (G_IS_LO_MENU (menu)); GMenuModel *model = G_MENU_MODEL (g_lo_menu_get_section (menu, section)); g_return_if_fail (model != NULL); + g_menu_model_items_changed (model, position, 1, 0); + GVariant *value; if (action != NULL) @@ -569,7 +622,7 @@ g_lo_menu_set_submenu_action_to_item_in_section (GLOMenu *menu, g_lo_menu_set_attribute_value (G_LO_MENU (model), position, G_LO_MENU_ATTRIBUTE_SUBMENU_ACTION, value); // Notify the update. - g_menu_model_items_changed (model, position, 1, 1); + g_menu_model_items_changed (model, position, 0, 1); g_object_unref (model); } @@ -587,12 +640,13 @@ void g_lo_menu_remove (GLOMenu *menu, gint position) { + //printf("[%p] %s - position: %d\n", menu, __FUNCTION__, position); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (0 <= position && position < (gint) menu->items->len); - g_menu_model_items_changed (G_MENU_MODEL (menu), position, 1, 0); g_lo_menu_clear_item (&g_array_index (menu->items, struct item, position)); g_array_remove_index (menu->items, position); + g_menu_model_items_changed (G_MENU_MODEL (menu), position, 1, 0); } void @@ -600,6 +654,7 @@ g_lo_menu_remove_from_section (GLOMenu *menu, gint section, gint position) { + //printf("[%p] %s - section: %d - position: %d\n", menu, __FUNCTION__, section, position); g_return_if_fail (G_IS_LO_MENU (menu)); g_return_if_fail (0 <= section && section < (gint) menu->items->len); @@ -615,6 +670,7 @@ g_lo_menu_remove_from_section (GLOMenu *menu, static void g_lo_menu_finalize (GObject *object) { + //printf("[%p] %s\n", object, __FUNCTION__); GLOMenu *menu = G_LO_MENU (object); struct item *items; gint n_items; diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx index cf86115e0754..24ddc20dccf7 100644 --- a/vcl/unx/gtk/window/gtkframe.cxx +++ b/vcl/unx/gtk/window/gtkframe.cxx @@ -571,7 +571,7 @@ void on_registrar_available( GDBusConnection * /*connection*/, if ( pSalMenu != NULL ) { GtkSalMenu* pGtkSalMenu = static_cast<GtkSalMenu*>(pSalMenu); - pGtkSalMenu->UpdateNativeMenu(); + //pGtkSalMenu->UpdateNativeMenu(); pGtkSalMenu->Display( sal_True ); } } @@ -592,11 +592,17 @@ void on_registrar_unavailable( GDBusConnection * /*connection*/, if ( pSalMenu ) { GtkSalMenu* pGtkSalMenu = static_cast< GtkSalMenu* >( pSalMenu ); - pGtkSalMenu->DisconnectFrame(); +// pGtkSalMenu->DisconnectFrame(); pGtkSalMenu->Display( sal_False ); } } +void GtkSalFrame::FlushConnection() +{ + if (pSessionBus) + g_dbus_connection_flush_sync( pSessionBus, NULL, NULL ); +} + void GtkSalFrame::EnsureAppMenuWatch() { if ( !m_nWatcherId ) @@ -668,28 +674,26 @@ GtkSalFrame::~GtkSalFrame() SolarMutexGuard aGuard; if(m_nWatcherId) g_bus_unwatch_name(m_nWatcherId); - if(m_pSalMenu) - static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame(); +// if(m_pSalMenu) +// static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame(); if( m_pWindow ) { g_object_set_data( G_OBJECT( m_pWindow ), "SalFrame", NULL ); - if(m_nMenuExportId) + + if ( pSessionBus ) { - if(pSessionBus) + if(m_nMenuExportId) g_dbus_connection_unexport_menu_model(pSessionBus, m_nMenuExportId); - GLOMenu* pMenuModel = G_LO_MENU(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-menubar" )); - if(pMenuModel) - //g_lo_menu_remove(pMenuModel,0); - g_object_unref( pMenuModel ); - } - if(m_nActionGroupExportId) - { - if(pSessionBus) + //GLOMenu* pMenuModel = G_LO_MENU(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-menubar" )); + //if(pMenuModel) + //g_lo_menu_remove(pMenuModel,0); + //g_object_unref( pMenuModel ); + if(m_nActionGroupExportId) g_dbus_connection_unexport_action_group(pSessionBus, m_nActionGroupExportId); - GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-action-group" )); - if(pActionGroup) - //g_lo_action_group_clear( pActionGroup ); - g_object_unref( pActionGroup ); + //GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP(g_object_get_data( G_OBJECT( m_pWindow ), "g-lo-action-group" )); + //if(pActionGroup) + //g_lo_action_group_clear( pActionGroup ); + //g_object_unref( pActionGroup ); } gtk_widget_destroy( m_pWindow ); } @@ -1462,10 +1466,10 @@ void GtkSalFrame::SetIcon( sal_uInt16 nIcon ) void GtkSalFrame::SetMenu( SalMenu* pSalMenu ) { - if(m_pSalMenu) - { - static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame(); - } +// if(m_pSalMenu) +// { +// static_cast<GtkSalMenu*>(m_pSalMenu)->DisconnectFrame(); +// } m_pSalMenu = pSalMenu; } diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index b9d9325e3f7f..3c6ee28640ca 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -152,25 +152,33 @@ bool GtkSalMenu::PrepUpdate() const GtkSalFrame* pFrame = GetFrame(); if (pFrame) { - const GObject* pWindow = G_OBJECT(gtk_widget_get_window( GTK_WIDGET(pFrame->getWindow()) )); - if(!pWindow) - { - SAL_INFO("vcl.unity", "not updating menu model, I have no frame " << mpMenuModel); +// const GObject* pWindow = G_OBJECT(gtk_widget_get_window( GTK_WIDGET(pFrame->getWindow()) )); +// if(!pWindow) +// { +// SAL_INFO("vcl.unity", "not updating menu model, I have no frame " << mpMenuModel); +// return false; +// } +// +// // the root menu does not have its own model and has to use the one owned by the frame +// if(mbMenuBar) +// { +// mpMenuModel = G_MENU_MODEL( g_object_get_data( G_OBJECT( pWindow ), "g-lo-menubar" ) ); +// mpActionGroup = G_ACTION_GROUP( g_object_get_data( G_OBJECT( pWindow ), "g-lo-action-group" ) ); +// +// if(!mpMenuModel || !mpActionGroup) +// return false; +// } +// +// SAL_INFO("vcl.unity", "updating menu model" << mpMenuModel); + GtkSalFrame* pNonConstFrame = ( GtkSalFrame* ) pFrame; + GtkSalMenu* pSalMenu = ((GtkSalMenu*) this); + + if ( !pNonConstFrame->GetMenu() ) + pNonConstFrame->SetMenu( pSalMenu ); + + if ( /*!bMenuVisibility ||*/ !mpMenuModel || !mpActionGroup ) return false; - } - - // the root menu does not have its own model and has to use the one owned by the frame - if(mbMenuBar) - { - mpMenuModel = G_MENU_MODEL( g_object_get_data( G_OBJECT( pWindow ), "g-lo-menubar" ) ); - mpActionGroup = G_ACTION_GROUP( g_object_get_data( G_OBJECT( pWindow ), "g-lo-action-group" ) ); - - if(!mpMenuModel || !mpActionGroup) - return false; - } - - SAL_INFO("vcl.unity", "updating menu model" << mpMenuModel); - + return true; } @@ -256,6 +264,7 @@ void RemoveUnusedCommands( GLOActionGroup* pActionGroup, GList* pOldCommandList, void GtkSalMenu::UpdateNativeMenu() { SolarMutexGuard aGuard; + //GTK_YIELD_GRAB(); if( !PrepUpdate() ) return; @@ -357,16 +366,20 @@ void GtkSalMenu::UpdateNativeMenu() { 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 ); +// printf("%s (begin) - submenumodel: %p\n", __FUNCTION__, pSubMenuModel); if ( pSubMenuModel == NULL ) { - pSubMenuModel = g_lo_menu_new(); - g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, G_MENU_MODEL( pSubMenuModel ) ); + //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 ); +// printf("%s (end) - submenumodel: %p\n", __FUNCTION__, pSubMenuModel); pSubmenu->SetMenuModel( G_MENU_MODEL( pSubMenuModel ) ); pSubmenu->SetActionGroup( G_ACTION_GROUP( pActionGroup ) ); @@ -375,11 +388,10 @@ void GtkSalMenu::UpdateNativeMenu() pSubmenu->GetMenu()->Deactivate(); pSubmenu->UpdateNativeMenu(); + + //pSubmenu->SetMenuModel( NULL ); + //pSubmenu->SetActionGroup( NULL ); } -// else if (pSubMenuModel) -// { -// g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, NULL ); -// }; g_free( aNativeCommand ); @@ -405,26 +417,49 @@ void GtkSalMenu::UpdateNativeMenu() GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) : mbMenuBar( bMenuBar ), mpVCLMenu( NULL ), + mpOldSalMenu( NULL ), mpParentSalMenu( NULL ), mpFrame( NULL ), mpMenuModel( NULL ), mpActionGroup( NULL ) { + if (mbMenuBar) + printf("[%p] %s\n", this, __FUNCTION__); } GtkSalMenu::~GtkSalMenu() { SolarMutexGuard aGuard; + //GTK_YIELD_GRAB(); + if ( mbMenuBar == sal_True ) - if ( mpFrame ) - ((GtkSalFrame*) mpFrame)->SetMenu( NULL ); + { + printf("[%p] %s\n", this, __FUNCTION__); + //if ( mpFrame ) + // ((GtkSalFrame*) mpFrame)->SetMenu( NULL ); + + if ( mpMenuModel ) + { + g_lo_menu_remove( G_LO_MENU( mpMenuModel ), 0 ); + g_object_unref( mpMenuModel ); + } + + //if ( mpActionGroup ) + //{ + //g_lo_action_group_clear( G_LO_ACTION_GROUP( mpActionGroup ) ); + //g_object_unref( mpActionGroup ); + //} + //if ( mpFrame ) + // ((GtkSalFrame*) mpFrame)->FlushConnection(); + } maItems.clear(); } sal_Bool GtkSalMenu::VisibleMenuBar() { - return bMenuVisibility; + //return bMenuVisibility; + return sal_False; } void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) @@ -462,6 +497,8 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig void GtkSalMenu::SetFrame( const SalFrame* pFrame ) { SolarMutexGuard aGuard; + GTK_YIELD_GRAB(); + assert(mbMenuBar); SAL_INFO("vcl.unity", "GtkSalMenu set to frame"); mpFrame = static_cast< const GtkSalFrame* >( pFrame ); @@ -470,25 +507,44 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) // if we had a menu on the GtkSalMenu we have to free it as we generate a // full menu anyway and we might need to reuse an existing model and // actiongroup + mpOldSalMenu = static_cast< GtkSalMenu* >( pFrameNonConst->GetMenu() ); pFrameNonConst->SetMenu( this ); - mpFrame = static_cast< const GtkSalFrame* >( pFrame ); // Clean menu model and action group if needed. -// GObject* pWindow = G_OBJECT( pFrameNonConst->getWindow() ); GtkWidget* pWidget = pFrameNonConst->getWindow(); GdkWindow* gdkWindow = gtk_widget_get_window( pWidget ); + printf("[%p] %s - window: %p\n", this, __FUNCTION__, gdkWindow); + GLOMenu* pMenuModel = 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 ( pMenuModel && g_menu_model_get_n_items( G_MENU_MODEL( pMenuModel ) ) > 0 ) - g_lo_menu_remove( pMenuModel, 0 ); + if ( pMenuModel ) + { + if ( g_menu_model_get_n_items( G_MENU_MODEL( pMenuModel ) ) > 0 ) + g_lo_menu_remove( pMenuModel, 0 ); + + //g_lo_menu_new_section( pMenuModel, 0, NULL ); + //mpMenuModel = G_MENU_MODEL( g_lo_menu_get_section( pMenuModel, 0 ) ); + mpMenuModel = G_MENU_MODEL( g_lo_menu_new() ); + //g_lo_menu_insert_section( pMenuModel, 0, NULL, mpMenuModel ); + } if ( pActionGroup ) + { g_lo_action_group_clear( pActionGroup ); + mpActionGroup = G_ACTION_GROUP( pActionGroup ); + } + + //pFrameNonConst->FlushConnection(); // Generate the main menu structure. UpdateNativeMenu(); + g_lo_menu_insert_section( pMenuModel, 0, NULL, mpMenuModel ); + + //pFrameNonConst->FlushConnection(); + + printf("[%p] %s - frame: %p - menu export id: %d - action group export id: %d\n", this, __FUNCTION__, pFrame, pFrameNonConst->m_nMenuExportId, pFrameNonConst->m_nActionGroupExportId); } const GtkSalFrame* GtkSalMenu::GetFrame() const @@ -503,7 +559,7 @@ const GtkSalFrame* GtkSalMenu::GetFrame() const void GtkSalMenu::NativeCheckItem( unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck ) { SolarMutexGuard aGuard; - + if ( mpActionGroup == NULL ) return; @@ -681,6 +737,8 @@ void GtkSalMenu::DispatchCommand( gint itemId, const gchar *aCommand ) if ( mbMenuBar != TRUE ) return; + printf("[%p] %s - item id: %d - command: %s\n", this, __FUNCTION__, itemId, aCommand); + GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( (gchar*) aCommand, FALSE ); Menu* pSubMenu = ( pSalSubMenu != NULL ) ? pSalSubMenu->GetMenu() : NULL; @@ -700,6 +758,7 @@ void GtkSalMenu::Activate( const gchar* aMenuCommand ) MenuBar* pMenuBar = static_cast< MenuBar* >( mpVCLMenu ); pMenuBar->HandleMenuActivateEvent( pSalSubMenu->mpVCLMenu ); pSalSubMenu->UpdateNativeMenu(); + //((GtkSalFrame*) mpFrame)->FlushConnection(); } } @@ -716,15 +775,15 @@ void GtkSalMenu::Deactivate( const gchar* aMenuCommand ) } } -void GtkSalMenu::DisconnectFrame() -{ - if( mbMenuBar == sal_True ) - { - mpMenuModel = NULL; - mpActionGroup = NULL; - mpFrame = NULL; - } -} +//void GtkSalMenu::DisconnectFrame() +//{ +// if( mbMenuBar == sal_True ) +// { +// mpMenuModel = NULL; +// mpActionGroup = NULL; +// mpFrame = NULL; +// } +//} void GtkSalMenu::Display( sal_Bool bVisible ) { |