vcl/inc/unx/gtk/gtkframe.hxx | 5 + vcl/inc/unx/gtk/gtkinst.hxx | 1 vcl/inc/unx/gtk/gtksalmenu.hxx | 8 +- vcl/unx/gtk/app/gtkinst.cxx | 5 - vcl/unx/gtk/window/gtkframe.cxx | 18 ++++- vcl/unx/gtk/window/gtksalmenu.cxx | 134 +++++++++++++++++++++++++++++--------- 6 files changed, 134 insertions(+), 37 deletions(-)
New commits: commit 2116d7fc02ac1c84e0e5b38ee641dd310d80ca38 Author: Antonio Fernandez <antonio.fernan...@aentos.es> Date: Mon Sep 10 15:29:46 2012 +0100 Menu is now shown/hidden when needed. Change-Id: I4a5d155918f7147c3c2933fedad96d959accca61 diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index 50258e0..cd080d0 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -221,6 +221,9 @@ class GtkSalFrame : public SalFrame GdkRegion* m_pRegion; #endif + SalMenu* m_pSalMenu; + sal_uInt32 m_nWatcherId; + void Init( SalFrame* pParent, sal_uLong nStyle ); void Init( SystemParentData* pSysData ); void InitCommon(); @@ -345,7 +348,9 @@ public: virtual void SetTitle( const rtl::OUString& rTitle ); virtual void SetIcon( sal_uInt16 nIcon ); virtual void SetMenu( SalMenu *pSalMenu ); + virtual SalMenu* GetMenu( void ); virtual void DrawMenuBar(); + void SetWatcherId( sal_uInt32 watcherId ); virtual void SetExtendedFrameStyle( SalExtStyle nExtStyle ); // Before the window is visible, a resize event diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx index 5ec226e..efe8f16 100644 --- a/vcl/inc/unx/gtk/gtkinst.hxx +++ b/vcl/inc/unx/gtk/gtkinst.hxx @@ -146,7 +146,6 @@ public: void subtractEvent( sal_uInt16 nMask ); boost::shared_ptr<vcl::unx::GtkPrintWrapper> getPrintWrapper() const; - private: std::vector<GtkSalTimer *> m_aTimers; bool IsTimerExpired(); diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index 38ac784..ddb6a6b 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -44,21 +44,25 @@ private: std::vector< GtkSalMenuItem* > maItems; sal_Bool mbMenuBar; + sal_Bool mbVisible; Menu* mpVCLMenu; GtkSalMenu* mpParentSalMenu; const GtkSalFrame* mpFrame; + sal_uInt32 mWatcherId; + // GMenuModel and GActionGroup attributes GMenuModel* mpMenuModel; GActionGroup* mpActionGroup; - sal_Int32 GetPositionFromItem( GtkSalMenuItem* pSalMenuItem ); - void GetItemSectionAndPosition( unsigned nPos, unsigned *insertSection, unsigned *insertPos ); + sal_Int32 GetPositionFromItem( GtkSalMenuItem* pSalMenuItem ); + void GetItemSectionAndPosition( unsigned nPos, unsigned *insertSection, unsigned *insertPos ); public: GtkSalMenu( sal_Bool bMenuBar ); virtual ~GtkSalMenu(); + virtual void SetVisibleMenuBar( sal_Bool bVisible ); virtual sal_Bool VisibleMenuBar(); // must return TRUE to actually DISPLAY native menu bars // otherwise only menu messages are processed (eg, OLE on Windows) diff --git a/vcl/unx/gtk/app/gtkinst.cxx b/vcl/unx/gtk/app/gtkinst.cxx index 6c9e198..2738e20 100644 --- a/vcl/unx/gtk/app/gtkinst.cxx +++ b/vcl/unx/gtk/app/gtkinst.cxx @@ -521,7 +521,7 @@ SalBitmap* GtkInstance::CreateSalBitmap() SalMenu* GtkInstance::CreateMenu( sal_Bool bMenuBar, Menu* pVCLMenu ) { - GtkSalMenu *pSalMenu = new GtkSalMenu( bMenuBar ); + GtkSalMenu* pSalMenu = new GtkSalMenu( bMenuBar ); pSalMenu->SetMenu( pVCLMenu ); return static_cast<SalMenu*>( pSalMenu ); @@ -536,7 +536,8 @@ void GtkInstance::DestroyMenu( SalMenu* pMenu ) SalMenuItem* GtkInstance::CreateMenuItem( const SalItemParams* pItemData ) { - GtkSalMenuItem *pMenuItem = new GtkSalMenuItem( pItemData ); + GtkSalMenuItem* pMenuItem = new GtkSalMenuItem( pItemData ); + return static_cast<SalMenuItem*>( pMenuItem ); } diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx index 36be0b2..d43371c 100644 --- a/vcl/unx/gtk/window/gtkframe.cxx +++ b/vcl/unx/gtk/window/gtkframe.cxx @@ -532,6 +532,9 @@ GtkSalFrame::~GtkSalFrame() g_object_unref( G_OBJECT( m_pForeignParent ) ); if( m_pForeignTopLevel ) g_object_unref( G_OBJECT( m_pForeignTopLevel) ); + + if ( m_nWatcherId > 0 ) + g_bus_unwatch_name( m_nWatcherId ); } void GtkSalFrame::moveWindow( long nX, long nY ) @@ -639,6 +642,8 @@ void GtkSalFrame::InitCommon() m_pRegion = NULL; m_ePointerStyle = 0xffff; m_bSetFocusOnMap = false; + m_pSalMenu = NULL; + m_nWatcherId = 0; gtk_widget_set_app_paintable( m_pWindow, TRUE ); gtk_widget_set_double_buffered( m_pWindow, FALSE ); @@ -1288,14 +1293,25 @@ void GtkSalFrame::SetIcon( sal_uInt16 nIcon ) g_list_free( pIcons ); } -void GtkSalFrame::SetMenu( SalMenu* ) +void GtkSalFrame::SetMenu( SalMenu* pSalMenu ) +{ + m_pSalMenu = pSalMenu; +} + +SalMenu* GtkSalFrame::GetMenu( void ) { + return m_pSalMenu; } void GtkSalFrame::DrawMenuBar() { } +void GtkSalFrame::SetWatcherId( sal_uInt32 watcherId ) +{ + m_nWatcherId = watcherId; +} + void GtkSalFrame::Center() { long nX, nY; diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index d6c96a4..19ca889 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -196,15 +196,97 @@ rtl::OUString GetGtkKeyName( rtl::OUString keyName ) return aGtkKeyName; } +// AppMenu watch functions. + +static sal_Bool bDBusIsAvailable = sal_False; + +static void +on_registrar_available (GDBusConnection * /*connection*/, + const gchar * /*name*/, + const gchar * /*name_owner*/, + gpointer user_data) +{ + GtkSalFrame* pSalFrame = static_cast< GtkSalFrame* >( user_data ); + GtkSalMenu* pSalMenu = static_cast< GtkSalMenu* >( pSalFrame->GetMenu() ); + + if ( pSalMenu != NULL ) + { + MenuBar* pMenuBar = static_cast< MenuBar* >( pSalMenu->GetMenu() ); + + GtkWidget *pWidget = pSalFrame->getWindow(); + GdkWindow *gdkWindow = gtk_widget_get_window( pWidget ); + + if ( gdkWindow != NULL ) + { + 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. + GDBusConnection* pSessionBus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); + + if( pSessionBus == NULL ) + return; + + // Publish the menu. + if ( aDBusMenubarPath != NULL ) + g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, pSalMenu->GetMenuModel(), NULL); + + if ( aDBusPath != NULL ) + g_dbus_connection_export_action_group( pSessionBus, aDBusPath, pSalMenu->GetActionGroup(), NULL); + + // Set window properties. + 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 ); + gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_MENUBAR_OBJECT_PATH", aDBusMenubarPath ); + + g_free( aDBusPath ); + g_free( aDBusWindowPath ); + g_free( aDBusMenubarPath ); + + bDBusIsAvailable = sal_True; + pSalMenu->SetVisibleMenuBar( sal_True ); + pMenuBar->SetDisplayable( sal_False ); + } + } + + return; +} + +//This is called when the registrar becomes unavailable. It shows the menubar. +static void +on_registrar_unavailable (GDBusConnection * /*connection*/, + const gchar * /*name*/, + gpointer user_data) +{ + GtkSalFrame* pSalFrame = static_cast< GtkSalFrame* >( user_data ); + GtkSalMenu* pSalMenu = static_cast< GtkSalMenu* >( pSalFrame->GetMenu() ); + + if ( pSalMenu ) { + MenuBar* pMenuBar = static_cast< MenuBar* >( pSalMenu->GetMenu() ); + + bDBusIsAvailable = sal_False; + pSalMenu->SetVisibleMenuBar( sal_False ); + pMenuBar->SetDisplayable( sal_True ); + } + + return; +} + /* * GtkSalMenu */ GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) : mbMenuBar( bMenuBar ), + mbVisible( sal_False ), mpVCLMenu( NULL ), mpParentSalMenu( NULL ), mpFrame( NULL ), + mWatcherId( 0 ), mpMenuModel( NULL ), mpActionGroup( NULL ) { @@ -215,6 +297,8 @@ GtkSalMenu::~GtkSalMenu() if ( mbMenuBar == sal_True ) { g_source_remove_by_user_data( this ); + ((GtkSalFrame*) mpFrame)->SetMenu( NULL ); + if ( mpActionGroup ) { g_lo_action_group_clear( G_LO_ACTION_GROUP( mpActionGroup ) ); } @@ -227,9 +311,15 @@ GtkSalMenu::~GtkSalMenu() maItems.clear(); } +void GtkSalMenu::SetVisibleMenuBar( sal_Bool bVisible ) +{ +// mbVisible = bVisible; +} + sal_Bool GtkSalMenu::VisibleMenuBar() { - return sal_False; +// return mbVisible; + return bDBusIsAvailable; } void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) @@ -263,7 +353,9 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig void GtkSalMenu::SetFrame( const SalFrame* pFrame ) { - mpFrame = static_cast<const GtkSalFrame*>( pFrame ); + mpFrame = static_cast< const GtkSalFrame* >( pFrame ); + + ( ( GtkSalFrame* ) mpFrame )->SetMenu( this ); GtkWidget *widget = GTK_WIDGET( mpFrame->getWindow() ); @@ -280,36 +372,16 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame ) g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-menubar", mpMenuModel, ObjectDestroyedNotify ); g_object_set_data_full( G_OBJECT( gdkWindow ), "g-lo-action-group", mpActionGroup, ObjectDestroyedNotify ); - 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 only if AppMenu registrar is available. + guint 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, + (gpointer) mpFrame, + NULL); - // Get a DBus session connection. - GDBusConnection* pSessionBus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); - if(!pSessionBus) puts ("Failed to get DBus session connection"); - - // Publish the menu. - if ( aDBusMenubarPath ) { - sal_uInt16 menubarId = g_dbus_connection_export_menu_model (pSessionBus, aDBusMenubarPath, mpMenuModel, NULL); - if(!menubarId) puts("Failed to export menubar"); - } - - if ( aDBusPath ) { - sal_uInt16 actionGroupId = g_dbus_connection_export_action_group( pSessionBus, aDBusPath, mpActionGroup, NULL); - if(!actionGroupId) puts("Failed to export action group"); - } - - // Set window properties. - 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 ); - gdk_x11_window_set_utf8_property ( gdkWindow, "_GTK_MENUBAR_OBJECT_PATH", aDBusMenubarPath ); - - g_free( aDBusPath ); - g_free( aDBusWindowPath ); - g_free( aDBusMenubarPath ); + ( ( GtkSalFrame* ) mpFrame )->SetWatcherId( nWatcherId ); } // Generate the main menu structure. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits