Kaydet (Commit) 3ae6c7fc authored tarafından Caolán McNamara's avatar Caolán McNamara

gtk3: add a menubar close button

the css foo is modeled on the similiar gedit close buttons
in its tabs

Change-Id: I7af32ad0434a49c52eea215f797c502be7f96dac
üst 800704e0
...@@ -75,6 +75,7 @@ public: ...@@ -75,6 +75,7 @@ public:
virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode, const OUString& rKeyName ) = 0; virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode, const OUString& rKeyName ) = 0;
virtual void GetSystemMenuData( SystemMenuData* pData ) = 0; virtual void GetSystemMenuData( SystemMenuData* pData ) = 0;
virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, FloatWinPopupFlags nFlags); 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 bool AddMenuBarButton( const SalMenuButtonItem& ); // return false if not implemented or failure
virtual void RemoveMenuBarButton( sal_uInt16 nId ); virtual void RemoveMenuBarButton( sal_uInt16 nId );
virtual void Update() {} virtual void Update() {}
......
...@@ -46,6 +46,7 @@ private: ...@@ -46,6 +46,7 @@ private:
bool mbMenuBar; bool mbMenuBar;
bool mbUnityMode; bool mbUnityMode;
GtkWidget* mpMenuBarWidget; GtkWidget* mpMenuBarWidget;
GtkWidget* mpCloseButton;
Menu* mpVCLMenu; Menu* mpVCLMenu;
GtkSalMenu* mpParentSalMenu; GtkSalMenu* mpParentSalMenu;
GtkSalFrame* mpFrame; GtkSalFrame* mpFrame;
...@@ -106,10 +107,11 @@ public: ...@@ -106,10 +107,11 @@ public:
virtual void Update() override; // Update this menu only. virtual void Update() override; // Update this menu only.
void UpdateFull(); // Update full menu hierarchy from this menu. void UpdateFull(); // Update full menu hierarchy from this menu.
void CreateMenuWidget(); void CreateMenuBarWidget();
void DestroyMenuWidget(); 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 class GtkSalMenuItem : public SalMenuItem
......
...@@ -135,6 +135,10 @@ bool SalMenu::ShowNativePopupMenu(FloatingWindow *, const Rectangle&, FloatWinPo ...@@ -135,6 +135,10 @@ bool SalMenu::ShowNativePopupMenu(FloatingWindow *, const Rectangle&, FloatWinPo
return false; return false;
} }
void SalMenu::ShowCloseButton(bool)
{
}
bool SalMenu::AddMenuBarButton( const SalMenuButtonItem& ) bool SalMenu::AddMenuBarButton( const SalMenuButtonItem& )
{ {
return false; return false;
......
...@@ -213,6 +213,8 @@ void MenuBarWindow::ShowButtons( bool bClose, bool bFloat, bool bHide ) ...@@ -213,6 +213,8 @@ void MenuBarWindow::ShowButtons( bool bClose, bool bFloat, bool bHide )
{ {
aCloseBtn->ShowItem(IID_DOCUMENTCLOSE, bClose); aCloseBtn->ShowItem(IID_DOCUMENTCLOSE, bClose);
aCloseBtn->Show(bClose || !m_aAddButtons.empty()); aCloseBtn->Show(bClose || !m_aAddButtons.empty());
if (pMenu->mpSalMenu)
pMenu->mpSalMenu->ShowCloseButton(bClose);
aFloatBtn->Show( bFloat ); aFloatBtn->Show( bFloat );
aHideBtn->Show( bHide ); aHideBtn->Show( bHide );
Resize(); Resize();
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <sal/log.hxx> #include <sal/log.hxx>
#include <window.h> #include <window.h>
#include <svids.hrc>
// FIXME Copied from framework/inc/framework/menuconfiguration.hxx to // FIXME Copied from framework/inc/framework/menuconfiguration.hxx to
// avoid circular dependency between modules. It should be in a common // avoid circular dependency between modules. It should be in a common
...@@ -429,6 +430,7 @@ GtkSalMenu::GtkSalMenu( bool bMenuBar ) : ...@@ -429,6 +430,7 @@ GtkSalMenu::GtkSalMenu( bool bMenuBar ) :
mbMenuBar( bMenuBar ), mbMenuBar( bMenuBar ),
mbUnityMode ( false ), mbUnityMode ( false ),
mpMenuBarWidget( nullptr ), mpMenuBarWidget( nullptr ),
mpCloseButton( nullptr ),
mpVCLMenu( nullptr ), mpVCLMenu( nullptr ),
mpParentSalMenu( nullptr ), mpParentSalMenu( nullptr ),
mpFrame( nullptr ), mpFrame( nullptr ),
...@@ -450,7 +452,7 @@ GtkSalMenu::~GtkSalMenu() ...@@ -450,7 +452,7 @@ GtkSalMenu::~GtkSalMenu()
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
DestroyMenuWidget(); DestroyMenuBarWidget();
if (mpMenuModel) if (mpMenuModel)
g_object_unref(mpMenuModel); g_object_unref(mpMenuModel);
...@@ -495,7 +497,69 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig ...@@ -495,7 +497,69 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig
pItem->mpSubMenu = pGtkSubMenu; 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) #if GTK_CHECK_VERSION(3,0,0)
GtkGrid* pGrid = mpFrame->getTopLevelGridWidget(); GtkGrid* pGrid = mpFrame->getTopLevelGridWidget();
...@@ -507,13 +571,14 @@ void GtkSalMenu::CreateMenuWidget() ...@@ -507,13 +571,14 @@ void GtkSalMenu::CreateMenuWidget()
GtkWidget *pMenuBarWidget = gtk_menu_bar_new_from_model(mpMenuModel); GtkWidget *pMenuBarWidget = gtk_menu_bar_new_from_model(mpMenuModel);
gtk_widget_insert_action_group(pMenuBarWidget, "win", mpActionGroup); 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_grid_attach(GTK_GRID(mpMenuBarWidget), pMenuBarWidget, 0, 0, 1, 1);
gtk_widget_show_all(mpMenuBarWidget); gtk_widget_show_all(mpMenuBarWidget);
#endif #endif
} }
void GtkSalMenu::DestroyMenuWidget() void GtkSalMenu::DestroyMenuBarWidget()
{ {
#if GTK_CHECK_VERSION(3,0,0) #if GTK_CHECK_VERSION(3,0,0)
if (mpMenuBarWidget) if (mpMenuBarWidget)
...@@ -567,7 +632,10 @@ void GtkSalMenu::SetFrame(const SalFrame* pFrame) ...@@ -567,7 +632,10 @@ void GtkSalMenu::SetFrame(const SalFrame* pFrame)
#if GTK_CHECK_VERSION(3,0,0) #if GTK_CHECK_VERSION(3,0,0)
if (!mbUnityMode) if (!mbUnityMode)
CreateMenuWidget(); {
DestroyMenuBarWidget();
CreateMenuBarWidget();
}
#endif #endif
} }
...@@ -821,9 +889,9 @@ void GtkSalMenu::EnableUnity(bool bEnable) ...@@ -821,9 +889,9 @@ void GtkSalMenu::EnableUnity(bool bEnable)
if (bUnityMode != bEnable) if (bUnityMode != bEnable)
{ {
if (!bEnable) if (!bEnable)
CreateMenuWidget(); CreateMenuBarWidget();
else else
DestroyMenuWidget(); DestroyMenuBarWidget();
bUnityMode = bEnable; bUnityMode = bEnable;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment