diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-04-09 16:21:28 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-04-10 21:35:08 +0200 |
commit | aece54a415e5e35d6c5f5cfd1f6d8b3af594d272 (patch) | |
tree | cabf4fd96e97de0724cd3fa1430b129191f7d342 /vcl | |
parent | f966767e1ccfa432da33e1a0fd6de69e17a36bc3 (diff) |
weld SpacingDialog
Change-Id: Ida9077b19ad78001c632796257651e4314a9a538
Reviewed-on: https://gerrit.libreoffice.org/52676
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/app/salvtables.cxx | 43 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 134 |
2 files changed, 151 insertions, 26 deletions
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 597547b5c8e3..6ca938aea058 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -35,6 +35,7 @@ #include <vcl/lstbox.hxx> #include <vcl/dialog.hxx> #include <vcl/layout.hxx> +#include <vcl/menubtn.hxx> #include <vcl/tabctrl.hxx> #include <vcl/tabpage.hxx> #include <vcl/unowrap.hxx> @@ -396,6 +397,10 @@ public: { m_xMenu->EnableItem(rIdent, bSensitive); } + virtual void set_active(const OString& rIdent, bool bActive) override + { + m_xMenu->CheckItem(m_xMenu->GetItemId(rIdent), bActive); + } virtual void show(const OString& rIdent, bool bShow) override { m_xMenu->ShowItem(m_xMenu->GetItemId(rIdent), bShow); @@ -820,6 +825,38 @@ weld::Button* SalInstanceDialog::get_widget_for_response(int nResponse) return pButton ? new SalInstanceButton(pButton, false) : nullptr; } +class SalInstanceMenuButton : public SalInstanceButton, public virtual weld::MenuButton +{ +private: + VclPtr<::MenuButton> m_xMenuButton; + + DECL_LINK(MenuSelectHdl, ::MenuButton*, void); + +public: + SalInstanceMenuButton(::MenuButton* pButton, bool bTakeOwnership) + : SalInstanceButton(pButton, bTakeOwnership) + , m_xMenuButton(pButton) + { + m_xMenuButton->SetSelectHdl(LINK(this, SalInstanceMenuButton, MenuSelectHdl)); + } + + virtual void set_active(const OString& rIdent, bool bActive) override + { + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + pMenu->CheckItem(pMenu->GetItemId(rIdent), bActive); + } + + virtual ~SalInstanceMenuButton() override + { + m_xMenuButton->SetSelectHdl(Link<::MenuButton*, void>()); + } +}; + +IMPL_LINK_NOARG(SalInstanceMenuButton, MenuSelectHdl, ::MenuButton*, void) +{ + signal_selected(m_xMenuButton->GetCurItemIdent()); +} + class SalInstanceRadioButton : public SalInstanceButton, public virtual weld::RadioButton { private: @@ -1812,6 +1849,12 @@ public: return pButton ? new SalInstanceButton(pButton, bTakeOwnership) : nullptr; } + virtual weld::MenuButton* weld_menu_button(const OString &id, bool bTakeOwnership) override + { + MenuButton* pButton = m_xBuilder->get<MenuButton>(id); + return pButton ? new SalInstanceMenuButton(pButton, bTakeOwnership) : nullptr; + } + virtual weld::RadioButton* weld_radio_button(const OString &id, bool bTakeOwnership) override { RadioButton* pRadioButton = m_xBuilder->get<RadioButton>(id); diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index e3e961ecf4ca..59270fd994fa 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1424,14 +1424,13 @@ public: } }; -class GtkInstanceMenu : public weld::Menu +class MenuHelper { protected: GtkMenu* m_pMenu; - OString m_sActivated; + bool m_bTakeOwnership; std::map<OString, GtkMenuItem*> m_aMap; private: - bool m_bTakeOwnership; static void collect(GtkWidget* pItem, gpointer widget) { @@ -1440,7 +1439,7 @@ private: gtk_container_foreach(GTK_CONTAINER(pSubMenu), collect, widget); else { - GtkInstanceMenu* pThis = static_cast<GtkInstanceMenu*>(widget); + MenuHelper* pThis = static_cast<MenuHelper*>(widget); pThis->add_to_map(pMenuItem); } } @@ -1454,19 +1453,15 @@ private: static void signalActivate(GtkMenuItem* pItem, gpointer widget) { - GtkInstanceMenu* pThis = static_cast<GtkInstanceMenu*>(widget); + MenuHelper* pThis = static_cast<MenuHelper*>(widget); SolarMutexGuard aGuard; pThis->signal_activate(pItem); } - void signal_activate(GtkMenuItem* pItem) - { - const gchar* pStr = gtk_buildable_get_name(GTK_BUILDABLE(pItem)); - m_sActivated = OString(pStr, pStr ? strlen(pStr) : 0); - } + virtual void signal_activate(GtkMenuItem* pItem) = 0; public: - GtkInstanceMenu(GtkMenu* pMenu, bool bTakeOwnership) + MenuHelper(GtkMenu* pMenu, bool bTakeOwnership) : m_pMenu(pMenu) , m_bTakeOwnership(bTakeOwnership) { @@ -1474,6 +1469,67 @@ public: for (auto& a : m_aMap) g_signal_connect(a.second, "activate", G_CALLBACK(signalActivate), this); } + + void disable_item_notify_events() + { + for (auto& a : m_aMap) + g_signal_handlers_block_by_func(a.second, reinterpret_cast<void*>(signalActivate), this); + } + + void enable_item_notify_events() + { + for (auto& a : m_aMap) + g_signal_handlers_unblock_by_func(a.second, reinterpret_cast<void*>(signalActivate), this); + } + + void set_item_sensitive(const OString& rIdent, bool bSensitive) + { + gtk_widget_set_sensitive(GTK_WIDGET(m_aMap[rIdent]), bSensitive); + } + + void set_item_active(const OString& rIdent, bool bActive) + { + disable_item_notify_events(); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(m_aMap[rIdent]), bActive); + enable_item_notify_events(); + } + + void show_item(const OString& rIdent, bool bShow) + { + GtkWidget* pWidget = GTK_WIDGET(m_aMap[rIdent]); + if (bShow) + gtk_widget_show(pWidget); + else + gtk_widget_hide(pWidget); + } + + virtual ~MenuHelper() + { + for (auto& a : m_aMap) + g_signal_handlers_disconnect_by_data(a.second, this); + if (m_bTakeOwnership) + gtk_widget_destroy(GTK_WIDGET(m_pMenu)); + } +}; + +class GtkInstanceMenu : public MenuHelper, public virtual weld::Menu +{ +protected: + OString m_sActivated; + +private: + virtual void signal_activate(GtkMenuItem* pItem) override + { + const gchar* pStr = gtk_buildable_get_name(GTK_BUILDABLE(pItem)); + m_sActivated = OString(pStr, pStr ? strlen(pStr) : 0); + } + +public: + GtkInstanceMenu(GtkMenu* pMenu, bool bTakeOwnership) + : MenuHelper(pMenu, bTakeOwnership) + { + } + virtual OString popup_at_rect(weld::Widget* pParent, const tools::Rectangle &rRect) override { m_sActivated.clear(); @@ -1530,24 +1586,20 @@ public: return m_sActivated; } + virtual void set_sensitive(const OString& rIdent, bool bSensitive) override { - gtk_widget_set_sensitive(GTK_WIDGET(m_aMap[rIdent]), bSensitive); + set_item_sensitive(rIdent, bSensitive); } - virtual void show(const OString& rIdent, bool bShow) override + + virtual void set_active(const OString& rIdent, bool bActive) override { - GtkWidget* pWidget = GTK_WIDGET(m_aMap[rIdent]); - if (bShow) - gtk_widget_show(pWidget); - else - gtk_widget_hide(pWidget); + set_item_active(rIdent, bActive); } - virtual ~GtkInstanceMenu() override + + virtual void show(const OString& rIdent, bool bShow) override { - for (auto& a : m_aMap) - g_signal_handlers_disconnect_by_data(a.second, this); - if (m_bTakeOwnership) - gtk_widget_destroy(GTK_WIDGET(m_pMenu)); + show_item(rIdent, bShow); } }; @@ -2364,6 +2416,27 @@ bool GtkInstanceDialog::has_click_handler(int nResponse) return false; } +class GtkInstanceMenuButton : public GtkInstanceButton, public MenuHelper, public virtual weld::MenuButton +{ +public: + GtkInstanceMenuButton(GtkMenuButton* pMenuButton, bool bTakeOwnership) + : GtkInstanceButton(GTK_BUTTON(pMenuButton), bTakeOwnership) + , MenuHelper(gtk_menu_button_get_popup(pMenuButton), false) + { + } + + virtual void set_active(const OString& rIdent, bool bActive) override + { + set_item_active(rIdent, bActive); + } + + virtual void signal_activate(GtkMenuItem* pItem) override + { + const gchar* pStr = gtk_buildable_get_name(GTK_BUILDABLE(pItem)); + signal_selected(OString(pStr, pStr ? strlen(pStr) : 0)); + } +}; + class GtkInstanceToggleButton : public GtkInstanceButton, public virtual weld::ToggleButton { private: @@ -2547,7 +2620,7 @@ public: virtual void enable_notify_events() override { - GtkInstanceWidget::disable_notify_events(); + GtkInstanceWidget::enable_notify_events(); g_signal_handler_unblock(m_pEntry, m_nChangedSignalId); g_signal_handler_unblock(m_pEntry, m_nInsertTextSignalId); } @@ -2874,7 +2947,7 @@ public: virtual void enable_notify_events() override { - GtkInstanceContainer::disable_notify_events(); + GtkInstanceContainer::enable_notify_events(); g_signal_handler_unblock(m_pTreeView, m_nRowActivatedSignalId); g_signal_handler_unblock(gtk_tree_view_get_selection(m_pTreeView), m_nChangedSignalId); } @@ -3665,7 +3738,7 @@ public: virtual void enable_notify_events() override { - GtkInstanceContainer::disable_notify_events(); + GtkInstanceContainer::enable_notify_events(); g_signal_handler_unblock(m_pComboBoxText, m_nPopupShownSignalId); g_signal_handler_unblock(m_pComboBoxText, m_nChangedSignalId); if (GtkEntry* pEntry = get_entry()) @@ -3993,6 +4066,15 @@ public: return new GtkInstanceButton(pButton, bTakeOwnership); } + virtual weld::MenuButton* weld_menu_button(const OString &id, bool bTakeOwnership) override + { + GtkMenuButton* pButton = GTK_MENU_BUTTON(gtk_builder_get_object(m_pBuilder, id.getStr())); + if (!pButton) + return nullptr; + auto_add_parentless_widgets_to_container(GTK_WIDGET(pButton)); + return new GtkInstanceMenuButton(pButton, bTakeOwnership); + } + virtual weld::RadioButton* weld_radio_button(const OString &id, bool bTakeOwnership) override { GtkRadioButton* pRadioButton = GTK_RADIO_BUTTON(gtk_builder_get_object(m_pBuilder, id.getStr())); |