vcl/inc/unx/gtk/gtkframe.hxx | 5 +- vcl/unx/gtk/window/gtkframe.cxx | 68 +++++++++++++++++++------------------- vcl/unx/gtk/window/gtksalmenu.cxx | 56 ++++++++++++++++--------------- 3 files changed, 67 insertions(+), 62 deletions(-)
New commits: commit 84d1e66ce5a6dec71d62e31c3fe650a220df0f9d Author: Antonio Fernandez <antonio.fernan...@aentos.es> Date: Mon Oct 15 16:03:26 2012 +0100 Added a hack to make "Slide Show" menu item on "Slide Show" menu work. Change-Id: I6c3865227702325e7f1545be893eb05b19c2e09f diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index 13afb2b..2dfed29 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -39,17 +39,29 @@ static sal_Bool bMenuVisibility = sal_False; +/* + * This function generates an alternative command name to avoid name collisions + * or to give a valid command name to certain menu items. + */ static gchar* GetCommandForSpecialItem( GtkSalMenuItem* pSalMenuItem ) { gchar* aCommand = NULL; sal_uInt16 nId = pSalMenuItem->mnId; + Menu* pMenu = pSalMenuItem->mpVCLMenu; // If item belongs to window list, generate a command with "window-(id)" format. if ( ( nId >= START_ITEMID_WINDOWLIST ) && ( nId <= END_ITEMID_WINDOWLIST ) ) - { aCommand = g_strdup_printf( "window-%d", nId ); - } + else + if ( pMenu ) + { + rtl::OUString aMenuCommand = pMenu->GetItemCommand( nId ); + MenuItemBits nBits = pMenu->GetItemBits( nId ); + + if ( aMenuCommand.equalsAscii(".uno:Presentation") && nBits == 0 ) + aCommand = g_strdup(".uno:Presentation2"); + } return aCommand; } @@ -303,7 +315,8 @@ void GtkSalMenu::UpdateNativeMenu() // Convert internal values to native values. gboolean bChecked = ( itemChecked == sal_True ) ? TRUE : FALSE; gboolean bEnabled = ( itemEnabled == sal_True ) ? TRUE : FALSE; - gchar* aNativeCommand = g_strdup( rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() ); +// gchar* aNativeCommand = g_strdup( rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() ); + gchar* aNativeCommand = GetCommandForSpecialItem( pSalMenuItem ); // Store current item command in command list. gchar *aCurrentCommand = g_lo_menu_get_command_from_item_in_section( pLOMenu, nSection, nItemPos ); @@ -316,15 +329,17 @@ void GtkSalMenu::UpdateNativeMenu() NativeSetAccelerator( nSection, nItemPos, nAccelKey, nAccelKey.GetName( GetFrame()->GetWindow() ) ); // Some items are special, so they have different commands. - if ( g_strcmp0( aNativeCommand, "" ) == 0 ) +// if ( g_strcmp0( aNativeCommand, "" ) == 0 ) + if ( !aNativeCommand ) { - gchar *aSpecialItemCmd = GetCommandForSpecialItem( pSalMenuItem ); - - if ( aSpecialItemCmd != NULL ) - { - g_free( aNativeCommand ); - aNativeCommand = aSpecialItemCmd; - } +// gchar *aSpecialItemCmd = GetCommandForSpecialItem( pSalMenuItem ); + aNativeCommand = g_strdup( rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() ); + +// if ( aSpecialItemCmd != NULL ) +// { +// g_free( aNativeCommand ); +// aNativeCommand = aSpecialItemCmd; +// } } if ( g_strcmp0( aNativeCommand, "" ) != 0 && pSalMenuItem->mpSubMenu == NULL ) commit ea007a0422c18c12b4476533a985abd7f19da935 Author: Antonio Fernandez <antonio.fernan...@aentos.es> Date: Mon Oct 15 11:13:35 2012 +0100 Menu is always visible now. Change-Id: Ia6153c6630af2b04f3b022051aa1f7c48e2bfc1e diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index 96a7399..93b043d 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -226,8 +226,6 @@ class GtkSalFrame : public SalFrame friend void on_registrar_available (GDBusConnection*, const gchar*, const gchar*, gpointer); friend void on_registrar_unavailable (GDBusConnection*, const gchar*, gpointer); guint m_nWatcherId; - guint m_nMenuExportId; - guint m_nActionGroupExportId; void Init( SalFrame* pParent, sal_uLong nStyle ); void Init( SystemParentData* pSysData ); @@ -312,6 +310,9 @@ public: GtkSalFrame( SalFrame* pParent, sal_uLong nStyle ); GtkSalFrame( SystemParentData* pSysData ); + guint m_nMenuExportId; + guint m_nActionGroupExportId; + // dispatches an event, returns true if dispatched // and false else; if true was returned the event should // be swallowed diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx index 7e944c6..ab8b9c1 100644 --- a/vcl/unx/gtk/window/gtkframe.cxx +++ b/vcl/unx/gtk/window/gtkframe.cxx @@ -521,15 +521,18 @@ static void ObjectDestroyedNotify( gpointer data ) } } -void ensure_dbus_setup( GdkWindow* gdkWindow, GtkSalFrame* pSalFrame ) +gboolean ensure_dbus_setup( gpointer data ) { + GtkSalFrame* pSalFrame = reinterpret_cast< GtkSalFrame* >( data ); + GdkWindow* gdkWindow = gtk_widget_get_window( pSalFrame->getWindow() ); + if ( gdkWindow != NULL && g_object_get_data( G_OBJECT( gdkWindow ), "g-lo-menubar" ) == NULL ) { // Get a DBus session connection. if(!pSessionBus) pSessionBus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); - if( pSessionBus == NULL ) - return; + if( !pSessionBus ) + return FALSE; // Create menu model and action group attached to this frame. GMenuModel* pMenuModel = G_MENU_MODEL( g_lo_menu_new() ); @@ -541,11 +544,6 @@ void ensure_dbus_setup( GdkWindow* gdkWindow, GtkSalFrame* pSalFrame ) 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); @@ -555,10 +553,17 @@ void ensure_dbus_setup( GdkWindow* gdkWindow, GtkSalFrame* pSalFrame ) gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_WINDOW_OBJECT_PATH", aDBusWindowPath ); gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_MENUBAR_OBJECT_PATH", aDBusMenubarPath ); + // 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); + g_free( aDBusPath ); g_free( aDBusWindowPath ); g_free( aDBusMenubarPath ); } + + return FALSE; } void on_registrar_available( GDBusConnection * /*connection*/, @@ -569,9 +574,6 @@ void on_registrar_available( GDBusConnection * /*connection*/, SolarMutexGuard aGuard; GtkSalFrame* pSalFrame = reinterpret_cast< GtkSalFrame* >( user_data ); - GdkWindow* gdkWindow = gtk_widget_get_window( pSalFrame->getWindow() ); - - ensure_dbus_setup(gdkWindow, pSalFrame); SalMenu* pSalMenu = pSalFrame->GetMenu(); @@ -606,32 +608,28 @@ void on_registrar_unavailable( GDBusConnection * /*connection*/, void GtkSalFrame::EnsureAppMenuWatch() { - SolarMutexGuard aGuard; - - if ( m_nWatcherId ) - //g_bus_unwatch_name( m_nWatcherId ); - return; - - - // Get a DBus session connection. - if ( pSessionBus == NULL ) + if ( !m_nWatcherId ) { - pSessionBus = g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, NULL ); - + // Get a DBus session connection. if ( pSessionBus == NULL ) - return; - } + { + 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_on_connection( pSessionBus, - "com.canonical.AppMenu.Registrar", - G_BUS_NAME_WATCHER_FLAGS_NONE, - on_registrar_available, - on_registrar_unavailable, - static_cast<GtkSalFrame*>(this), - NULL ); + // Publish the menu only if AppMenu registrar is available. + 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) ); + ensure_dbus_setup( this ); } GtkSalFrame::~GtkSalFrame() @@ -1129,6 +1127,10 @@ void GtkSalFrame::Init( SalFrame* pParent, sal_uLong nStyle ) #if !GTK_CHECK_VERSION(3,0,0) if( eWinType == GTK_WINDOW_TOPLEVEL ) { + // Enable DBus native menu if available. +// ensure_dbus_setup( this ); + EnsureAppMenuWatch(); + guint32 nUserTime = 0; if( (nStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION|SAL_FRAME_STYLE_TOOLWINDOW)) == 0 ) { diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index 65ee72b..13afb2b 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -244,10 +244,10 @@ void RemoveUnusedCommands( GLOActionGroup* pActionGroup, GList* pOldCommandList, void GtkSalMenu::UpdateNativeMenu() { SolarMutexGuard aGuard; + if( !PrepUpdate() ) return; - Menu* pVCLMenu = mpVCLMenu; GLOMenu* pLOMenu = G_LO_MENU( mpMenuModel ); GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP( mpActionGroup ); @@ -431,7 +431,7 @@ void GtkSalMenu::RemoveItem( unsigned nPos ) maItems.erase( maItems.begin() + nPos ); } -void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ) +void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned ) { SolarMutexGuard aGuard; GtkSalMenuItem *pItem = static_cast< GtkSalMenuItem* >( pSalMenuItem ); @@ -455,23 +455,11 @@ 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 -// 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() ) ) ); + GObject* pWindow = G_OBJECT( 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" ) ); @@ -481,7 +469,6 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) if ( pActionGroup ) g_lo_action_group_clear( pActionGroup ); - // Generate the main menu structure. UpdateNativeMenu(); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits