summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Fernandez <antonio.fernandez@aentos.es>2012-10-04 16:48:04 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2012-11-14 13:52:55 +0100
commit668e03678313a57e1c7ecbe2f73e2bf8a6215c69 (patch)
tree50f4fcf77f0ac78e5625a3b0524a826a6603e1ef
parent7dd3bb2cc6e0a72090ff3ac7a3e3824effa498e8 (diff)
Menus are now correctly built.
Change-Id: I1a4f5750c37ddfc4b4949033138efbd2372f01c5
-rw-r--r--vcl/unx/gtk/window/gtkframe.cxx81
-rw-r--r--vcl/unx/gtk/window/gtksalmenu.cxx83
2 files changed, 90 insertions, 74 deletions
diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx
index 6eb294a18be4..2bf92c75fdef 100644
--- a/vcl/unx/gtk/window/gtkframe.cxx
+++ b/vcl/unx/gtk/window/gtkframe.cxx
@@ -512,36 +512,35 @@ static void ObjectDestroyedNotify( gpointer data )
}
}
-void ensure_dbus_setup(GdkWindow* gdkWindow, GtkSalFrame* pSalFrame)
+void ensure_dbus_setup( GdkWindow* gdkWindow, GtkSalFrame* pSalFrame )
{
if ( gdkWindow != NULL && g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ) == NULL )
{
- GMenuModel* pMenuModel = G_MENU_MODEL(g_lo_menu_new());
- GActionGroup* pActionGroup = ((GActionGroup*)g_lo_action_group_new(reinterpret_cast<gpointer>(pSalFrame)));
- XLIB_Window windowId = GDK_WINDOW_XID( gdkWindow );
- gchar* aDBusPath = g_strdup_printf("/window/%lu", windowId);
- gchar* aDBusWindowPath = g_strdup_printf( "/window/%lu", windowId );
- gchar* aDBusMenubarPath = g_strdup_printf( "/window/%lu/menus/menubar", windowId );
// Get a DBus session connection.
if(!pSessionBus)
pSessionBus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
if( pSessionBus == NULL )
return;
+
+ // Create menu model and action group attached to this frame.
+ GMenuModel* pMenuModel = G_MENU_MODEL( g_lo_menu_new() );
+ GActionGroup* pActionGroup = ( ( GActionGroup* ) g_lo_action_group_new( reinterpret_cast< gpointer >( pSalFrame ) ) );
+
+ // Generate menu paths.
+ XLIB_Window windowId = GDK_WINDOW_XID( gdkWindow );
+ gchar* aDBusPath = g_strdup_printf("/window/%lu", windowId);
+ gchar* aDBusWindowPath = g_strdup_printf( "/window/%lu", windowId );
+ gchar* aDBusMenubarPath = g_strdup_printf( "/window/%lu/menus/menubar", windowId );
+
+ // Publish the menu model and the action group.
SAL_INFO("vcl.unity", "exporting menu model at " << pMenuModel << " for window " << windowId);
pSalFrame->m_nMenuExportId = g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, pMenuModel, NULL);
pSalFrame->m_nActionGroupExportId = g_dbus_connection_export_action_group( pSessionBus, aDBusPath, pActionGroup, NULL);
// Set window properties.
- g_object_set_data_full(
- G_OBJECT(gdkWindow),
- "g-lo-menubar",
- pMenuModel,
- ObjectDestroyedNotify);
- g_object_set_data_full(
- G_OBJECT(gdkWindow),
- "g-lo-action-group",
- pActionGroup,
- ObjectDestroyedNotify);
+ g_object_set_data_full( G_OBJECT(gdkWindow), "g-lo-menubar", pMenuModel, ObjectDestroyedNotify);
+ g_object_set_data_full( G_OBJECT(gdkWindow), "g-lo-action-group", pActionGroup, ObjectDestroyedNotify);
+
gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_UNIQUE_BUS_NAME", g_dbus_connection_get_unique_name( pSessionBus ) );
gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_APPLICATION_OBJECT_PATH", "" );
gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_WINDOW_OBJECT_PATH", aDBusWindowPath );
@@ -553,10 +552,10 @@ void ensure_dbus_setup(GdkWindow* gdkWindow, GtkSalFrame* pSalFrame)
}
}
-void on_registrar_available (GDBusConnection * /*connection*/,
- const gchar * /*name*/,
- const gchar * /*name_owner*/,
- gpointer user_data)
+void on_registrar_available( GDBusConnection * /*connection*/,
+ const gchar * /*name*/,
+ const gchar * /*name_owner*/,
+ gpointer user_data )
{
SolarMutexGuard aGuard;
GtkSalFrame* pSalFrame = reinterpret_cast< GtkSalFrame* >( user_data );
@@ -595,17 +594,31 @@ void on_registrar_unavailable (GDBusConnection * /*connection*/,
void GtkSalFrame::EnsureAppMenuWatch()
{
SolarMutexGuard aGuard;
- if(m_nWatcherId)
- g_bus_unwatch_name(m_nWatcherId);
+
+ if ( m_nWatcherId )
+ //g_bus_unwatch_name( m_nWatcherId );
+ return;
+
+
+ // Get a DBus session connection.
+ if ( pSessionBus == NULL )
+ {
+ pSessionBus = g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, NULL );
+
+ if ( pSessionBus == NULL )
+ return;
+ }
+
// Publish the menu only if AppMenu registrar is available.
- m_nWatcherId = g_bus_watch_name(G_BUS_TYPE_SESSION,
- "com.canonical.AppMenu.Registrar",
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- on_registrar_available,
- on_registrar_unavailable,
- static_cast<GtkSalFrame*>(this),
- NULL);
- ensure_dbus_setup(gtk_widget_get_window(GTK_WIDGET(m_pWindow)), static_cast<GtkSalFrame*>(this));
+ m_nWatcherId = g_bus_watch_name_on_connection( pSessionBus,
+ "com.canonical.AppMenu.Registrar",
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ on_registrar_available,
+ on_registrar_unavailable,
+ static_cast<GtkSalFrame*>(this),
+ NULL );
+
+ ensure_dbus_setup( gtk_widget_get_window(GTK_WIDGET(m_pWindow)), static_cast<GtkSalFrame*>(this) );
}
GtkSalFrame::~GtkSalFrame()
@@ -664,7 +677,8 @@ GtkSalFrame::~GtkSalFrame()
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_lo_menu_remove(pMenuModel,0);
+ g_object_unref( pMenuModel );
}
if(m_nActionGroupExportId)
{
@@ -672,7 +686,8 @@ GtkSalFrame::~GtkSalFrame()
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_lo_action_group_clear( pActionGroup );
+ g_object_unref( pActionGroup );
}
gtk_widget_destroy( m_pWindow );
}
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx
index 43f04f51dd76..1fd2e6f19ec4 100644
--- a/vcl/unx/gtk/window/gtksalmenu.cxx
+++ b/vcl/unx/gtk/window/gtksalmenu.cxx
@@ -246,9 +246,9 @@ void GtkSalMenu::UpdateNativeMenu()
// SolarMutexGuard aGuard;
- Menu* pVCLMenu = mpVCLMenu; // pMenu->GetMenu();
- GLOMenu* pLOMenu = G_LO_MENU( mpMenuModel ); // G_LO_MENU( pMenu->GetMenuModel() );
- GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( mpActionGroup ); // G_LO_ACTION_GROUP( pMenu->GetActionGroup() );
+ Menu* pVCLMenu = mpVCLMenu;
+ GLOMenu* pLOMenu = G_LO_MENU( mpMenuModel );
+ GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( mpActionGroup );
GList *pOldCommandList = NULL;
GList *pNewCommandList = NULL;
@@ -335,14 +335,13 @@ void GtkSalMenu::UpdateNativeMenu()
}
GtkSalMenu* pSubmenu = pSalMenuItem->mpSubMenu;
- GLOMenu* pSubMenuModel = g_lo_menu_get_submenu_from_item_in_section( pLOMenu, nSection, nItemPos );
if ( pSubmenu && pSubmenu->GetMenu() )
{
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 );
+ GLOMenu* pSubMenuModel = g_lo_menu_get_submenu_from_item_in_section( pLOMenu, nSection, nItemPos );
if ( pSubMenuModel == NULL )
{
@@ -360,24 +359,16 @@ void GtkSalMenu::UpdateNativeMenu()
pSubmenu->UpdateNativeMenu();
}
- else if (pSubMenuModel)
- {
- g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, NULL );
- };
+// else if (pSubMenuModel)
+// {
+// g_lo_menu_set_submenu_to_item_in_section( pLOMenu, nSection, nItemPos, NULL );
+// };
g_free( aNativeCommand );
++nItemPos;
++validItems;
}
-// while ( nItemPos < g_lo_menu_get_n_items_from_section( pLOMenu, nSection ) )
-// g_lo_menu_remove_from_section( pLOMenu, nSection, nItemPos );
-// ++nSection;
-// if ( nSection < g_menu_model_get_n_items( G_MENU_MODEL( pLOMenu ) ) )
-// {
-// SAL_INFO("vcl.unity", "nSection " << nSection << " model sections " << g_menu_model_get_n_items( G_MENU_MODEL( pLOMenu ) ));
-// g_lo_menu_remove(pLOMenu, nSection );
-// }
// Delete extra items in last section.
RemoveSpareItemsFromNativeMenu( pLOMenu, &pOldCommandList, nSection, validItems );
@@ -404,11 +395,6 @@ void GtkSalMenu::DisconnectFrame()
* GtkSalMenu
*/
-//void GtkSalMenu::UpdateNativeMenu()
-//{
-// UpdateNativeSubMenu();
-//}
-
GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) :
mbMenuBar( bMenuBar ),
mpVCLMenu( NULL ),
@@ -421,9 +407,8 @@ GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) :
GtkSalMenu::~GtkSalMenu()
{
- if ( mbMenuBar == sal_True ) {
+ if ( mbMenuBar == sal_True )
((GtkSalFrame*) mpFrame)->SetMenu( NULL );
- }
maItems.clear();
}
@@ -469,24 +454,40 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
SAL_INFO("vcl.unity", "GtkSalMenu set to frame");
mpFrame = static_cast< const GtkSalFrame* >( pFrame );
GtkSalFrame* pFrameNonConst = const_cast<GtkSalFrame*>(mpFrame);
+
// 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
- if(mpMenuModel)
- {
- g_object_unref(G_OBJECT(mpMenuModel));
- mpMenuModel = NULL;
- }
- if(mpActionGroup)
- {
- g_object_unref(G_OBJECT(mpActionGroup));
- mpActionGroup = NULL;
- }
+// if(mpMenuModel)
+// {
+// g_object_unref(G_OBJECT(mpMenuModel));
+// mpMenuModel = NULL;
+// }
+
+// if(mpActionGroup)
+// {
+// g_object_unref(G_OBJECT(mpActionGroup));
+// mpActionGroup = NULL;
+// }
pFrameNonConst->SetMenu( this );
mpFrame = static_cast< const GtkSalFrame* >( pFrame );
pFrameNonConst->EnsureAppMenuWatch();
+
+ // Clean menu model and action group if needed.
+ GObject* pWindow = G_OBJECT( gtk_widget_get_window( GTK_WIDGET( pFrameNonConst->getWindow() ) ) );
+ GLOMenu* pMenuModel = G_LO_MENU( g_object_get_data( pWindow, "g-lo-menubar" ) );
+ GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( g_object_get_data( pWindow, "g-lo-action-group" ) );
+
+ if ( pMenuModel && g_menu_model_get_n_items( G_MENU_MODEL( pMenuModel ) ) > 0 )
+ g_lo_menu_remove( pMenuModel, 0 );
+
+ if ( pActionGroup )
+ g_lo_action_group_clear( pActionGroup );
+
+
// Generate the main menu structure.
UpdateNativeMenu();
+
}
const GtkSalFrame* GtkSalMenu::GetFrame() const
@@ -723,11 +724,11 @@ sal_Bool GtkSalMenu::IsItemVisible( unsigned nPos )
return bVisible;
}
-void GtkSalMenu::CheckItem( unsigned nPos, sal_Bool bCheck )
+void GtkSalMenu::CheckItem( unsigned, sal_Bool )
{
}
-void GtkSalMenu::EnableItem( unsigned nPos, sal_Bool bEnable )
+void GtkSalMenu::EnableItem( unsigned, sal_Bool )
{
}
@@ -738,23 +739,23 @@ void GtkSalMenu::ShowItem( unsigned nPos, sal_Bool bShow )
}
-void GtkSalMenu::SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& rText )
+void GtkSalMenu::SetItemText( unsigned, SalMenuItem*, const rtl::OUString& )
{
}
-void GtkSalMenu::SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage)
+void GtkSalMenu::SetItemImage( unsigned, SalMenuItem*, const Image& )
{
}
-void GtkSalMenu::SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const rtl::OUString& rKeyName )
+void GtkSalMenu::SetAccelerator( unsigned, SalMenuItem*, const KeyCode&, const rtl::OUString& )
{
}
-void GtkSalMenu::SetItemCommand( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& aCommandStr )
+void GtkSalMenu::SetItemCommand( unsigned, SalMenuItem*, const rtl::OUString& )
{
}
-void GtkSalMenu::GetSystemMenuData( SystemMenuData* pData )
+void GtkSalMenu::GetSystemMenuData( SystemMenuData* )
{
}