vcl/inc/salmenu.hxx | 1 vcl/inc/unx/gtk/gtkframe.hxx | 3 vcl/inc/unx/gtk/gtksalmenu.hxx | 12 ++ vcl/source/app/salvtables.cxx | 4 vcl/source/window/menubarwindow.cxx | 2 vcl/unx/gtk/a11y/atklistener.cxx | 1 vcl/unx/gtk/gtksalframe.cxx | 4 vcl/unx/gtk/gtksalmenu.cxx | 159 ++++++++++++++++++++++++++++++------ vcl/unx/gtk3/gtk3gtkframe.cxx | 6 - 9 files changed, 159 insertions(+), 33 deletions(-)
New commits: commit 1724081f6363fb2b97523a2c5edb1424d7959f8b Author: Caolán McNamara <caol...@redhat.com> Date: Fri Feb 26 21:34:57 2016 +0000 gtk3+wayland: gnome#762756 hack around keyboard focus Change-Id: I6be61592a16660d62be583e082ffcf5b1907770f diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index 0220aa4..f3ec501 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -559,6 +559,22 @@ void GtkSalMenu::ShowCloseButton(bool bShow) #endif } +#if GTK_CHECK_VERSION(3,0,0) +//hack-around https://bugzilla.gnome.org/show_bug.cgi?id=762756 +static void ReturnFocus(GtkMenuShell *, gpointer pWidget) +{ + GtkWidget* pTopLevel = static_cast<GtkWidget*>(pWidget); + GdkWindow *window = gtk_widget_get_window(pTopLevel); + GdkEvent *fevent = gdk_event_new(GDK_FOCUS_CHANGE); + + fevent->focus_change.type = GDK_FOCUS_CHANGE; + fevent->focus_change.window = GDK_WINDOW(g_object_ref(window)); + fevent->focus_change.in = TRUE; + gtk_widget_send_focus_change(pTopLevel, fevent); + gdk_event_free(fevent); +} +#endif + void GtkSalMenu::CreateMenuBarWidget() { #if GTK_CHECK_VERSION(3,0,0) @@ -573,6 +589,7 @@ void GtkSalMenu::CreateMenuBarWidget() gtk_widget_insert_action_group(pMenuBarWidget, "win", mpActionGroup); gtk_widget_set_hexpand(GTK_WIDGET(pMenuBarWidget), true); gtk_grid_attach(GTK_GRID(mpMenuBarWidget), pMenuBarWidget, 0, 0, 1, 1); + g_signal_connect(G_OBJECT(pMenuBarWidget), "deactivate", G_CALLBACK(ReturnFocus), mpFrame->getWindow()); gtk_widget_show_all(mpMenuBarWidget); #endif commit 3ae6c7fcbe14f7a425fa1db2cb388b12848be65b Author: Caolán McNamara <caol...@redhat.com> Date: Thu Feb 25 13:42:02 2016 +0000 gtk3: add a menubar close button the css foo is modeled on the similiar gedit close buttons in its tabs Change-Id: I7af32ad0434a49c52eea215f797c502be7f96dac diff --git a/vcl/inc/salmenu.hxx b/vcl/inc/salmenu.hxx index d7930bb..0145547 100644 --- a/vcl/inc/salmenu.hxx +++ b/vcl/inc/salmenu.hxx @@ -75,6 +75,7 @@ public: virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode, const OUString& rKeyName ) = 0; virtual void GetSystemMenuData( SystemMenuData* pData ) = 0; virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, FloatWinPopupFlags nFlags); + virtual void ShowCloseButton(bool bShow); virtual bool AddMenuBarButton( const SalMenuButtonItem& ); // return false if not implemented or failure virtual void RemoveMenuBarButton( sal_uInt16 nId ); virtual void Update() {} diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index 0309058..b88aec8 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -46,6 +46,7 @@ private: bool mbMenuBar; bool mbUnityMode; GtkWidget* mpMenuBarWidget; + GtkWidget* mpCloseButton; Menu* mpVCLMenu; GtkSalMenu* mpParentSalMenu; GtkSalFrame* mpFrame; @@ -106,10 +107,11 @@ public: virtual void Update() override; // Update this menu only. void UpdateFull(); // Update full menu hierarchy from this menu. - void CreateMenuWidget(); - void DestroyMenuWidget(); + void CreateMenuBarWidget(); + void DestroyMenuBarWidget(); - virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, FloatWinPopupFlags nFlags) override; + virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, FloatWinPopupFlags nFlags) override; + virtual void ShowCloseButton(bool bShow) override; }; class GtkSalMenuItem : public SalMenuItem diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index c540eef5..c135cdf 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -135,6 +135,10 @@ bool SalMenu::ShowNativePopupMenu(FloatingWindow *, const Rectangle&, FloatWinPo return false; } +void SalMenu::ShowCloseButton(bool) +{ +} + bool SalMenu::AddMenuBarButton( const SalMenuButtonItem& ) { return false; diff --git a/vcl/source/window/menubarwindow.cxx b/vcl/source/window/menubarwindow.cxx index 8954513..99daa75 100644 --- a/vcl/source/window/menubarwindow.cxx +++ b/vcl/source/window/menubarwindow.cxx @@ -213,6 +213,8 @@ void MenuBarWindow::ShowButtons( bool bClose, bool bFloat, bool bHide ) { aCloseBtn->ShowItem(IID_DOCUMENTCLOSE, bClose); aCloseBtn->Show(bClose || !m_aAddButtons.empty()); + if (pMenu->mpSalMenu) + pMenu->mpSalMenu->ShowCloseButton(bClose); aFloatBtn->Show( bFloat ); aHideBtn->Show( bHide ); Resize(); diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index f2c50c4..0220aa4 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -26,6 +26,7 @@ #include <sal/log.hxx> #include <window.h> +#include <svids.hrc> // FIXME Copied from framework/inc/framework/menuconfiguration.hxx to // avoid circular dependency between modules. It should be in a common @@ -429,6 +430,7 @@ GtkSalMenu::GtkSalMenu( bool bMenuBar ) : mbMenuBar( bMenuBar ), mbUnityMode ( false ), mpMenuBarWidget( nullptr ), + mpCloseButton( nullptr ), mpVCLMenu( nullptr ), mpParentSalMenu( nullptr ), mpFrame( nullptr ), @@ -450,7 +452,7 @@ GtkSalMenu::~GtkSalMenu() { SolarMutexGuard aGuard; - DestroyMenuWidget(); + DestroyMenuBarWidget(); if (mpMenuModel) g_object_unref(mpMenuModel); @@ -495,7 +497,69 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig pItem->mpSubMenu = pGtkSubMenu; } -void GtkSalMenu::CreateMenuWidget() +#if GTK_CHECK_VERSION(3,0,0) +static void CloseMenuBar(GtkWidget *, gpointer pMenu) +{ + Application::PostUserEvent(static_cast<MenuBar*>(pMenu)->GetCloseButtonClickHdl()); +} +#endif + +void GtkSalMenu::ShowCloseButton(bool bShow) +{ +#if GTK_CHECK_VERSION(3,0,0) + assert(mbMenuBar); + MenuBar *pVclMenuBar = static_cast<MenuBar*>(mpVCLMenu); + if (!bShow) + { + if (mpCloseButton) + gtk_widget_destroy(mpCloseButton); + return; + } + + mpCloseButton = gtk_button_new(); + g_signal_connect(mpCloseButton, "clicked", G_CALLBACK(CloseMenuBar), pVclMenuBar); + + gtk_button_set_relief(GTK_BUTTON(mpCloseButton), GTK_RELIEF_NONE); + gtk_button_set_focus_on_click(GTK_BUTTON(mpCloseButton), false); + + GtkStyleContext *pButtonContext = gtk_widget_get_style_context(GTK_WIDGET(mpCloseButton)); + + GtkCssProvider *pProvider = gtk_css_provider_new(); + const gchar data[] = "* { " + "padding: 0;" + "margin-left: 8px;" + "margin-right: 8px;" + "min-width: 18px;" + "min-height: 18px;" + "}"; + gtk_css_provider_load_from_data(pProvider, data, -1, nullptr); + gtk_style_context_add_provider(pButtonContext, + GTK_STYLE_PROVIDER(pProvider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + gtk_style_context_add_class(pButtonContext, "flat"); + gtk_style_context_add_class(pButtonContext, "small-button"); + + GIcon* icon = g_themed_icon_new_with_default_fallbacks("window-close-symbolic"); + GtkWidget* image = gtk_image_new_from_gicon(icon, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + g_object_unref(icon); + + OUString sToolTip(VclResId(SV_HELPTEXT_CLOSEDOCUMENT)); + gtk_widget_set_tooltip_text(mpCloseButton, + OUStringToOString(sToolTip, RTL_TEXTENCODING_UTF8).getStr()); + + gtk_widget_set_valign(mpCloseButton, GTK_ALIGN_CENTER); + + gtk_container_add(GTK_CONTAINER(mpCloseButton), image); + gtk_grid_attach(GTK_GRID(mpMenuBarWidget), GTK_WIDGET(mpCloseButton), 1, 0, 1, 1); + gtk_widget_show_all(mpCloseButton); +#else + (void)bShow; +#endif +} + +void GtkSalMenu::CreateMenuBarWidget() { #if GTK_CHECK_VERSION(3,0,0) GtkGrid* pGrid = mpFrame->getTopLevelGridWidget(); @@ -507,13 +571,14 @@ void GtkSalMenu::CreateMenuWidget() GtkWidget *pMenuBarWidget = gtk_menu_bar_new_from_model(mpMenuModel); gtk_widget_insert_action_group(pMenuBarWidget, "win", mpActionGroup); + gtk_widget_set_hexpand(GTK_WIDGET(pMenuBarWidget), true); gtk_grid_attach(GTK_GRID(mpMenuBarWidget), pMenuBarWidget, 0, 0, 1, 1); gtk_widget_show_all(mpMenuBarWidget); #endif } -void GtkSalMenu::DestroyMenuWidget() +void GtkSalMenu::DestroyMenuBarWidget() { #if GTK_CHECK_VERSION(3,0,0) if (mpMenuBarWidget) @@ -567,7 +632,10 @@ void GtkSalMenu::SetFrame(const SalFrame* pFrame) #if GTK_CHECK_VERSION(3,0,0) if (!mbUnityMode) - CreateMenuWidget(); + { + DestroyMenuBarWidget(); + CreateMenuBarWidget(); + } #endif } @@ -821,9 +889,9 @@ void GtkSalMenu::EnableUnity(bool bEnable) if (bUnityMode != bEnable) { if (!bEnable) - CreateMenuWidget(); + CreateMenuBarWidget(); else - DestroyMenuWidget(); + DestroyMenuBarWidget(); bUnityMode = bEnable; } } commit 800704e0c46f6f86f6a18a477ba4b6f313c5693a Author: Caolán McNamara <caol...@redhat.com> Date: Thu Feb 25 12:48:54 2016 +0000 gtk3: native gtk menubar Change-Id: Ibb75aa3eae99e499e1c2026c41b0bf51d7f8cf31 diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index a530214..cf97011 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -376,6 +376,9 @@ public: GtkWidget* getWindow() const { return m_pWindow; } GtkFixed* getFixedContainer() const { return m_pFixedContainer; } GtkWidget* getMouseEventWidget() const; +#if GTK_CHECK_VERSION(3,0,0) + GtkGrid* getTopLevelGridWidget() const { return m_pTopLevelGrid; } +#endif GdkWindow* getForeignParent() const { return m_pForeignParent; } GdkNativeWindow getForeignParentWindow() const { return m_aForeignParentWindow; } GdkWindow* getForeignTopLevel() const { return m_pForeignTopLevel; } diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index 1697d0b..0309058 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -44,7 +44,8 @@ private: std::vector< GtkSalMenuItem* > maItems; bool mbMenuBar; - bool mbMenuVisibility; + bool mbUnityMode; + GtkWidget* mpMenuBarWidget; Menu* mpVCLMenu; GtkSalMenu* mpParentSalMenu; GtkSalFrame* mpFrame; @@ -100,11 +101,14 @@ public: void DispatchCommand( gint itemId, const gchar* aCommand ); void Activate( const gchar* aMenuCommand = nullptr ); void Deactivate( const gchar* aMenuCommand ); - void Display( bool bVisible ); + void EnableUnity(bool bEnable); bool PrepUpdate(); virtual void Update() override; // Update this menu only. void UpdateFull(); // Update full menu hierarchy from this menu. + void CreateMenuWidget(); + void DestroyMenuWidget(); + virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, FloatWinPopupFlags nFlags) override; }; diff --git a/vcl/unx/gtk/a11y/atklistener.cxx b/vcl/unx/gtk/a11y/atklistener.cxx index 86b663a..d94970e 100644 --- a/vcl/unx/gtk/a11y/atklistener.cxx +++ b/vcl/unx/gtk/a11y/atklistener.cxx @@ -143,7 +143,6 @@ void AtkListener::updateChildList( m_aChildList.resize(std::min(nChildren2, n)); break; } - OSL_ASSERT(m_aChildList[n].is()); } } } diff --git a/vcl/unx/gtk/gtksalframe.cxx b/vcl/unx/gtk/gtksalframe.cxx index a0a7e58..3e9d51a 100644 --- a/vcl/unx/gtk/gtksalframe.cxx +++ b/vcl/unx/gtk/gtksalframe.cxx @@ -721,7 +721,7 @@ void on_registrar_available( GDBusConnection * /*connection*/, if ( pSalMenu != nullptr ) { GtkSalMenu* pGtkSalMenu = static_cast<GtkSalMenu*>(pSalMenu); - pGtkSalMenu->Display( true ); + pGtkSalMenu->EnableUnity(true); pGtkSalMenu->UpdateFull(); } } @@ -742,7 +742,7 @@ void on_registrar_unavailable( GDBusConnection * /*connection*/, if ( pSalMenu ) { GtkSalMenu* pGtkSalMenu = static_cast< GtkSalMenu* >( pSalMenu ); - pGtkSalMenu->Display( false ); + pGtkSalMenu->EnableUnity(false); } } #endif diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index 92f32b9..f2c50c4 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -33,6 +33,8 @@ const sal_uInt16 START_ITEMID_WINDOWLIST = 4600; const sal_uInt16 END_ITEMID_WINDOWLIST = 4699; +static bool bUnityMode = false; + /* * This function generates the proper command name for all actions, including * duplicated or special ones. @@ -77,17 +79,7 @@ static gchar* GetCommandForItem( GtkSalMenuItem* pSalMenuItem, gchar* aCurrentCo bool GtkSalMenu::PrepUpdate() { - bool bMenuVisibility; - - //get top level visibility - const GtkSalMenu* pMenu = this; - do - { - bMenuVisibility = pMenu->mbMenuVisibility; - pMenu = pMenu->mpParentSalMenu; - } while (pMenu); - - return bMenuVisibility && mpMenuModel && mpActionGroup; + return mpMenuModel && mpActionGroup; } /* @@ -386,8 +378,6 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const Rectangle& /*rR nTime = gtk_get_current_event_time(); } - Display(true); - mpFrame = static_cast<GtkSalFrame*>(pWin->ImplGetWindowImpl()->mpRealParent->ImplGetFrame()); GLOActionGroup* pActionGroup = g_lo_action_group_new(static_cast<gpointer>(mpFrame)); @@ -437,7 +427,8 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const Rectangle& /*rR GtkSalMenu::GtkSalMenu( bool bMenuBar ) : mbMenuBar( bMenuBar ), - mbMenuVisibility( false ), + mbUnityMode ( false ), + mpMenuBarWidget( nullptr ), mpVCLMenu( nullptr ), mpParentSalMenu( nullptr ), mpFrame( nullptr ), @@ -459,6 +450,8 @@ GtkSalMenu::~GtkSalMenu() { SolarMutexGuard aGuard; + DestroyMenuWidget(); + if (mpMenuModel) g_object_unref(mpMenuModel); @@ -467,7 +460,7 @@ GtkSalMenu::~GtkSalMenu() bool GtkSalMenu::VisibleMenuBar() { - return mbMenuBar && mbMenuVisibility; + return mbMenuBar; } void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) @@ -502,6 +495,35 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig pItem->mpSubMenu = pGtkSubMenu; } +void GtkSalMenu::CreateMenuWidget() +{ +#if GTK_CHECK_VERSION(3,0,0) + GtkGrid* pGrid = mpFrame->getTopLevelGridWidget(); + mpMenuBarWidget = gtk_grid_new(); + + gtk_widget_set_hexpand(GTK_WIDGET(mpMenuBarWidget), true); + gtk_grid_insert_row(pGrid, 0); + gtk_grid_attach(pGrid, mpMenuBarWidget, 0, 0, 1, 1); + + GtkWidget *pMenuBarWidget = gtk_menu_bar_new_from_model(mpMenuModel); + gtk_widget_insert_action_group(pMenuBarWidget, "win", mpActionGroup); + gtk_grid_attach(GTK_GRID(mpMenuBarWidget), pMenuBarWidget, 0, 0, 1, 1); + + gtk_widget_show_all(mpMenuBarWidget); +#endif +} + +void GtkSalMenu::DestroyMenuWidget() +{ +#if GTK_CHECK_VERSION(3,0,0) + if (mpMenuBarWidget) + { + gtk_widget_destroy(mpMenuBarWidget); + mpMenuBarWidget = nullptr; + } +#endif +} + void GtkSalMenu::SetFrame(const SalFrame* pFrame) { SolarMutexGuard aGuard; @@ -539,10 +561,14 @@ void GtkSalMenu::SetFrame(const SalFrame* pFrame) } // Generate the main menu structure. - if (mbMenuVisibility) - UpdateFull(); + UpdateFull(); g_lo_menu_insert_section( pMenuModel, 0, nullptr, mpMenuModel ); + +#if GTK_CHECK_VERSION(3,0,0) + if (!mbUnityMode) + CreateMenuWidget(); +#endif } const GtkSalFrame* GtkSalMenu::GetFrame() const @@ -790,15 +816,15 @@ void GtkSalMenu::Deactivate( const gchar* aMenuCommand ) } } -void GtkSalMenu::Display( bool bVisible ) +void GtkSalMenu::EnableUnity(bool bEnable) { - mbMenuVisibility = bVisible; - - if (mbMenuBar) + if (bUnityMode != bEnable) { - bool bVCLMenuVisible = !bVisible; - MenuBar* pMenuBar = static_cast<MenuBar*>(mpVCLMenu); - pMenuBar->SetDisplayable(bVCLMenuVisible); + if (!bEnable) + CreateMenuWidget(); + else + DestroyMenuWidget(); + bUnityMode = bEnable; } } diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx index 3322b2a..d340c50 100644 --- a/vcl/unx/gtk3/gtk3gtkframe.cxx +++ b/vcl/unx/gtk3/gtk3gtkframe.cxx @@ -734,7 +734,7 @@ void on_registrar_available( GDBusConnection * /*connection*/, if ( pSalMenu != nullptr ) { GtkSalMenu* pGtkSalMenu = static_cast<GtkSalMenu*>(pSalMenu); - pGtkSalMenu->Display( true ); + pGtkSalMenu->EnableUnity(true); pGtkSalMenu->UpdateFull(); } } @@ -755,7 +755,7 @@ void on_registrar_unavailable( GDBusConnection * /*connection*/, if ( pSalMenu ) { GtkSalMenu* pGtkSalMenu = static_cast< GtkSalMenu* >( pSalMenu ); - pGtkSalMenu->Display( false ); + pGtkSalMenu->EnableUnity(false); } } #endif @@ -3068,7 +3068,7 @@ gboolean GtkSalFrame::signalKey( GtkWidget*, GdkEventKey* pEvent, gpointer frame if( !aDel.isDeleted() && pThis->m_pIMHandler ) pThis->m_pIMHandler->updateIMSpotLocation(); - return true; + return false; } gboolean GtkSalFrame::signalDelete( GtkWidget*, GdkEvent*, gpointer frame )
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits