summaryrefslogtreecommitdiff
path: root/vcl/unx/gtk/window
diff options
context:
space:
mode:
authorAntonio Fernandez <antonio.fernandez@aentos.es>2012-09-12 16:33:13 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2012-11-14 13:52:48 +0100
commitb789263fb7bf537cc85d3df3022282ab8f32bccb (patch)
tree89edaefde8a2577589cbf558fd774534e7e7e764 /vcl/unx/gtk/window
parentcfc3eded6233996ad7103d256b8a36e8d31df3b9 (diff)
Initial integration with Gtk+/Unity menus about-to-show feature.
Change-Id: I064cf73e23b175140bdac2616ac922c349f0f051
Diffstat (limited to 'vcl/unx/gtk/window')
-rw-r--r--vcl/unx/gtk/window/glomenu.cxx28
-rw-r--r--vcl/unx/gtk/window/gtksalmenu.cxx39
2 files changed, 49 insertions, 18 deletions
diff --git a/vcl/unx/gtk/window/glomenu.cxx b/vcl/unx/gtk/window/glomenu.cxx
index 9c0f835f67d3..36a70d18366e 100644
--- a/vcl/unx/gtk/window/glomenu.cxx
+++ b/vcl/unx/gtk/window/glomenu.cxx
@@ -189,7 +189,7 @@ g_lo_menu_set_attribute_value (GLOMenu *menu,
g_return_if_fail (attribute != NULL);
g_return_if_fail (valid_attribute_name (attribute));
- if (position >= menu->items->len)
+ if (position >= (gint) menu->items->len)
return;
struct item menu_item = g_array_index (menu->items, struct item, position);
@@ -512,6 +512,32 @@ g_lo_menu_get_submenu_from_item_in_section (GLOMenu *menu,
return G_LO_MENU (submenu);
}
+void
+g_lo_menu_set_submenu_action_to_item_in_section (GLOMenu *menu,
+ gint section,
+ gint position,
+ const gchar *action)
+{
+ g_return_if_fail (G_IS_LO_MENU (menu));
+
+ GMenuModel *model = 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);
+
+ GVariant *value;
+
+ if (action != NULL)
+ value = g_variant_new_string (action);
+ else
+ value = NULL;
+
+ 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);
+}
+
static void
g_lo_menu_clear_item (struct item *menu_item)
{
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx
index 594d9ac30cbc..98c52e5786e7 100644
--- a/vcl/unx/gtk/window/gtksalmenu.cxx
+++ b/vcl/unx/gtk/window/gtksalmenu.cxx
@@ -121,13 +121,11 @@ static void UpdateNativeMenu( GtkSalMenu* pMenu )
if ( g_strcmp0( aNativeCommand, "" ) != 0 && pSalMenuItem->mpSubMenu == NULL )
{
- pMenu->NativeSetItemCommand( nSection, nItemPos, pSalMenuItem, aNativeCommand );
+ pMenu->NativeSetItemCommand( nSection, nItemPos, nId, aNativeCommand, itemBits, bChecked, FALSE );
pMenu->NativeCheckItem( nSection, nItemPos, itemBits, bChecked );
pMenu->NativeSetEnableItem( aNativeCommand, bEnabled );
}
- g_free( aNativeCommand );
-
GtkSalMenu* pSubmenu = pSalMenuItem->mpSubMenu;
if ( pSubmenu && pSubmenu->GetMenu() )
@@ -140,6 +138,8 @@ static void UpdateNativeMenu( GtkSalMenu* pMenu )
g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, G_MENU_MODEL( pSubMenuModel ) );
}
+ pMenu->NativeSetItemCommand( nSection, nItemPos, nId, aNativeCommand, itemBits, FALSE, TRUE );
+
pSubmenu->GetMenu()->Activate();
pSubmenu->GetMenu()->Deactivate();
@@ -148,6 +148,8 @@ static void UpdateNativeMenu( GtkSalMenu* pMenu )
UpdateNativeMenu( pSubmenu );
}
+ g_free( aNativeCommand );
+
nItemPos++;
validItems++;
}
@@ -403,7 +405,7 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
}
// Generate the main menu structure.
-// GenerateMenu( this );
+ GenerateMenu( this );
// Refresh the menu every second.
// This code is a workaround until required modifications in Gtk+ are available.
@@ -490,27 +492,28 @@ void GtkSalMenu::NativeSetAccelerator( unsigned nSection, unsigned nItemPos, con
g_free( aCurrentAccel );
}
-void GtkSalMenu::NativeSetItemCommand( unsigned nSection, unsigned nItemPos, GtkSalMenuItem* pItem, const gchar* aCommand )
+void GtkSalMenu::NativeSetItemCommand( unsigned nSection,
+ unsigned nItemPos,
+ sal_uInt16 nId,
+ const gchar* aCommand,
+ MenuItemBits nBits,
+ gboolean bChecked,
+ gboolean bIsSubmenu )
{
GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( mpActionGroup );
GVariant *pTarget = NULL;
if ( g_action_group_has_action( mpActionGroup, aCommand ) == FALSE ) {
- gboolean bChecked = ( pItem->mpVCLMenu->IsItemChecked( pItem->mnId ) ) ? TRUE : FALSE;
-
- // FIXME: Why pItem->mnBits differs from GetItemBits value?
- MenuItemBits bits = pItem->mpVCLMenu->GetItemBits( pItem->mnId );
-
- if ( bits & MIB_CHECKABLE )
+ if ( ( nBits & MIB_CHECKABLE ) || ( bIsSubmenu == TRUE ) )
{
// 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->mnId, NULL, pStateType, NULL, pState );
+ g_lo_action_group_insert_stateful( pActionGroup, aCommand, nId, NULL, pStateType, NULL, pState );
}
- else if ( bits & MIB_RADIOCHECK )
+ else if ( nBits & MIB_RADIOCHECK )
{
// Item is a radio button.
GVariantType* pParameterType = g_variant_type_new( (gchar*) G_VARIANT_TYPE_STRING );
@@ -518,12 +521,12 @@ void GtkSalMenu::NativeSetItemCommand( unsigned nSection, unsigned nItemPos, Gtk
GVariant* pState = g_variant_new_string( "" );
pTarget = g_variant_new_string( aCommand );
- g_lo_action_group_insert_stateful( pActionGroup, aCommand, pItem->mnId, pParameterType, pStateType, NULL, pState );
+ g_lo_action_group_insert_stateful( pActionGroup, aCommand, nId, pParameterType, pStateType, NULL, pState );
}
else
{
// Item is not special, so insert a stateless action.
- g_lo_action_group_insert( pActionGroup, aCommand, pItem->mnId );
+ g_lo_action_group_insert( pActionGroup, aCommand, nId );
}
}
@@ -538,7 +541,10 @@ void GtkSalMenu::NativeSetItemCommand( unsigned nSection, unsigned nItemPos, Gtk
gchar* aItemCommand = g_strconcat("win.", aCommand, NULL );
- g_lo_menu_set_action_and_target_value_to_item_in_section( pMenu, nSection, nItemPos, aItemCommand, pTarget );
+ if ( bIsSubmenu == TRUE )
+ g_lo_menu_set_submenu_action_to_item_in_section( pMenu, nSection, nItemPos, aItemCommand );
+ else
+ g_lo_menu_set_action_and_target_value_to_item_in_section( pMenu, nSection, nItemPos, aItemCommand, pTarget );
g_free( aItemCommand );
}
@@ -556,7 +562,6 @@ GtkSalMenu* GtkSalMenu::GetMenuForItemCommand( gchar* aCommand )
GtkSalMenuItem *pSalItem = maItems[ nPos ];
String aItemCommand = mpVCLMenu->GetItemCommand( pSalItem->mnId );
-
gchar* aItemCommandStr = (gchar*) rtl::OUStringToOString( aItemCommand, RTL_TEXTENCODING_UTF8 ).getStr();
if ( g_strcmp0( aItemCommandStr, aCommand ) == 0 )