summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-02-25 13:42:02 +0000
committerCaolán McNamara <caolanm@redhat.com>2016-02-26 21:38:25 +0000
commit3ae6c7fcbe14f7a425fa1db2cb388b12848be65b (patch)
tree38928b81d974eff095a2235f1c30c05e40790d60 /vcl
parent800704e0c46f6f86f6a18a477ba4b6f313c5693a (diff)
gtk3: add a menubar close button
the css foo is modeled on the similiar gedit close buttons in its tabs Change-Id: I7af32ad0434a49c52eea215f797c502be7f96dac
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/salmenu.hxx1
-rw-r--r--vcl/inc/unx/gtk/gtksalmenu.hxx8
-rw-r--r--vcl/source/app/salvtables.cxx4
-rw-r--r--vcl/source/window/menubarwindow.cxx2
-rw-r--r--vcl/unx/gtk/gtksalmenu.cxx80
5 files changed, 86 insertions, 9 deletions
diff --git a/vcl/inc/salmenu.hxx b/vcl/inc/salmenu.hxx
index d7930bbc39fe..014554723c18 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 030905862597..b88aec85e64e 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 c540eef538f3..c135cdf42294 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 89545139b8fd..99daa750b94f 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 f2c50c4f25ad..0220aa44b2cc 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;
}
}