summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Fernandez <antonio.fernandez@aentos.es>2012-09-17 14:43:03 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2012-11-14 13:52:48 +0100
commitc8367ada13be4f3c0994ad032c09ea475e02a19a (patch)
tree793849d7b989a88291c85e69486647a6f3559e17
parentc1bf7fd49db152b16cf07e7060338a6bc27d9e0d (diff)
Improved memory management of GLOActionGroup.
Change-Id: Iaeee32c2990cb6514605d3f7bc959682d87d5d38
-rw-r--r--vcl/unx/gtk/window/gloactiongroup.cxx56
-rw-r--r--vcl/unx/gtk/window/gtksalmenu.cxx22
2 files changed, 46 insertions, 32 deletions
diff --git a/vcl/unx/gtk/window/gloactiongroup.cxx b/vcl/unx/gtk/window/gloactiongroup.cxx
index 11173880774e..12670ced12a1 100644
--- a/vcl/unx/gtk/window/gloactiongroup.cxx
+++ b/vcl/unx/gtk/window/gloactiongroup.cxx
@@ -204,33 +204,38 @@ g_lo_action_group_change_state (GActionGroup *group,
const gchar *action_name,
GVariant *value)
{
- if (!action_name || !value)
- return;
-
- GLOActionGroup* lo_group = G_LO_ACTION_GROUP (group);
- GLOAction* action = G_LO_ACTION (g_hash_table_lookup (lo_group->priv->table, action_name));
+ g_return_if_fail (value != NULL);
- if (action == NULL)
- return;
+ g_variant_ref_sink (value);
- if (action->submenu == TRUE)
- {
-// g_action_group_action_state_changed(group, action_name, value);
- g_lo_action_group_perform_submenu_action (lo_group, action_name, value);
- }
- else
+ if (action_name != NULL)
{
- if (action->state_type == NULL)
- action->state_type = g_variant_type_copy(g_variant_get_type(value));
-
- g_return_if_fail (g_variant_is_of_type(value, action->state_type) == TRUE);
-
- if (action->state)
- g_variant_unref(action->state);
+ GLOActionGroup* lo_group = G_LO_ACTION_GROUP (group);
+ GLOAction* action = G_LO_ACTION (g_hash_table_lookup (lo_group->priv->table, action_name));
- action->state = g_variant_take_ref(value);
- g_action_group_action_state_changed(group, action_name, value);
+ if (action != NULL)
+ {
+ if (action->submenu == TRUE)
+ g_lo_action_group_perform_submenu_action (lo_group, action_name, value);
+ else
+ {
+ if (action->state_type == NULL)
+ action->state_type = g_variant_type_copy (g_variant_get_type(value));
+
+ if (g_variant_is_of_type (value, action->state_type) == TRUE)
+ {
+ if (action->state)
+ g_variant_unref(action->state);
+
+ action->state = g_variant_ref (value);
+
+ g_action_group_action_state_changed (group, action_name, value);
+ }
+ }
+ }
}
+
+ g_variant_unref (value);
}
static void
@@ -281,7 +286,8 @@ g_lo_action_group_insert_stateful (GLOActionGroup *group,
if (old_action == NULL || old_action->item_id != item_id)
{
if (old_action != NULL)
- g_action_group_action_removed (G_ACTION_GROUP (group), action_name);
+ g_lo_action_group_remove (group, action_name);
+// g_action_group_action_removed (G_ACTION_GROUP (group), action_name);
GLOAction* action = g_lo_action_new();
@@ -297,10 +303,10 @@ g_lo_action_group_insert_stateful (GLOActionGroup *group,
action->state_type = (GVariantType*) state_type;
if (state_hint)
- action->state_hint = g_variant_take_ref (state_hint);
+ action->state_hint = g_variant_ref_sink (state_hint);
if (state)
- action->state = g_variant_take_ref (state);
+ action->state = g_variant_ref_sink (state);
g_action_group_action_added (G_ACTION_GROUP (group), action_name);
}
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx
index 94e13a1dba07..ad77c624bd61 100644
--- a/vcl/unx/gtk/window/gtksalmenu.cxx
+++ b/vcl/unx/gtk/window/gtksalmenu.cxx
@@ -346,6 +346,9 @@ on_registrar_available (GDBusConnection * /*connection*/,
if ( gdkWindow != NULL )
{
+ GMenuModel* pMenuModel = G_MENU_MODEL( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ) );
+ GActionGroup* pActionGroup = G_ACTION_GROUP( g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-action-group" ) );
+
XLIB_Window windowId = GDK_WINDOW_XID( gdkWindow );
gchar* aDBusPath = g_strdup_printf("/window/%lu", windowId);
@@ -359,11 +362,11 @@ on_registrar_available (GDBusConnection * /*connection*/,
return;
// Publish the menu.
- if ( aDBusMenubarPath != NULL )
- g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, pSalMenu->GetMenuModel(), NULL);
+ if ( aDBusMenubarPath != NULL && pMenuModel != NULL )
+ g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, pMenuModel, NULL);
- if ( aDBusPath != NULL )
- g_dbus_connection_export_action_group( pSessionBus, aDBusPath, pSalMenu->GetActionGroup(), NULL);
+ if ( aDBusPath != NULL && pActionGroup != NULL )
+ g_dbus_connection_export_action_group( pSessionBus, aDBusPath, pActionGroup, NULL);
// Set window properties.
gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name( pSessionBus ) );
@@ -376,7 +379,9 @@ on_registrar_available (GDBusConnection * /*connection*/,
g_free( aDBusMenubarPath );
bDBusIsAvailable = sal_True;
- pMenuBar->SetDisplayable( sal_False );
+
+ if ( pMenuBar )
+ pMenuBar->SetDisplayable( sal_False );
}
}
@@ -545,8 +550,11 @@ void GtkSalMenu::NativeCheckItem( unsigned nSection, unsigned nItemPos, MenuItem
pCheckValue = g_variant_new_boolean( bCheck );
}
- if ( pCheckValue != NULL && ( pCurrentState == NULL || g_variant_equal( pCurrentState, pCheckValue) == FALSE ) )
+ if ( pCheckValue != NULL && ( pCurrentState == NULL || g_variant_equal( pCurrentState, pCheckValue ) == FALSE ) )
g_action_group_change_action_state( mpActionGroup, aCommand, pCheckValue );
+
+ if ( pCurrentState )
+ g_variant_unref( pCurrentState );
}
if ( aCommand )
@@ -563,7 +571,7 @@ void GtkSalMenu::NativeSetEnableItem( gchar* aCommand, gboolean bEnable )
void GtkSalMenu::NativeSetItemText( unsigned nSection, unsigned nItemPos, const rtl::OUString& rText )
{
- // Replace the "~" character with "_".
+ // Replace the '~' character with '_'.
rtl::OUString aText = rText.replace( '~', '_' );
rtl::OString aConvertedText = OUStringToOString( aText, RTL_TEXTENCODING_UTF8 );