diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-12-30 19:33:39 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-12-31 12:06:42 +0100 |
commit | 4636a07f283753a4ddac279d4ef38385219ec423 (patch) | |
tree | 7c4aa91b2c0604907e6fd4324b0b090cc1ec922e | |
parent | b6c0cad80986ddbd7e62b07c51816c1df7031831 (diff) |
separate setting toggle and showing menu for ToolbarToggleMenu buttons
Change-Id: I7989c5b85cbf4e7698c76e35a516bcc39da41897
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86038
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/vcl/weld.hxx | 2 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 4 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 66 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 32 |
4 files changed, 71 insertions, 33 deletions
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index e298a85f90c6..8c20ef58cda4 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -1964,6 +1964,8 @@ public: virtual bool get_item_sensitive(const OString& rIdent) const = 0; virtual void set_item_active(const OString& rIdent, bool bActive) = 0; virtual bool get_item_active(const OString& rIdent) const = 0; + virtual void set_menu_item_active(const OString& rIdent, bool bActive) = 0; + virtual bool get_menu_item_active(const OString& rIdent) const = 0; virtual void set_item_menu(const OString& rIdent, weld::Menu* pMenu) = 0; virtual void set_item_popover(const OString& rIdent, weld::Widget* pPopover) = 0; virtual void set_item_visible(const OString& rIdent, bool bVisible) = 0; diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 3ab6b7cc12e3..50eaa75212d1 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -4271,7 +4271,7 @@ bool MenuOrToolMenuButton::get_active() const { if (m_pMenuButton) return m_pMenuButton->get_active(); - return m_pToolbar->get_item_active(m_aIdent); + return m_pToolbar->get_menu_item_active(m_aIdent); } void MenuOrToolMenuButton::set_active(bool bActive) const @@ -4281,7 +4281,7 @@ void MenuOrToolMenuButton::set_active(bool bActive) const m_pMenuButton->set_active(bActive); return; } - m_pToolbar->set_item_active(m_aIdent, bActive); + m_pToolbar->set_menu_item_active(m_aIdent, bActive); } weld::Widget* MenuOrToolMenuButton::get_widget() const diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 33870d28111d..15630fe70503 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -952,6 +952,7 @@ private: DECL_LINK(ClickHdl, ToolBox*, void); DECL_LINK(DropdownClick, ToolBox*, void); + public: SalInstanceToolbar(ToolBox* pToolBox, SalInstanceBuilder* pBuilder, bool bTakeOwnership) : SalInstanceWidget(pToolBox, pBuilder, bTakeOwnership) @@ -985,34 +986,57 @@ public: { sal_uInt16 nItemId = m_xToolBox->GetItemId(OUString::fromUtf8(rIdent)); m_xToolBox->CheckItem(nItemId, bActive); + } + + virtual bool get_item_active(const OString& rIdent) const override + { + return m_xToolBox->IsItemChecked(m_xToolBox->GetItemId(OUString::fromUtf8(rIdent))); + } + + void set_menu_item_active(const OString& rIdent, bool bActive) override + { + sal_uInt16 nItemId = m_xToolBox->GetItemId(OUString::fromUtf8(rIdent)); + assert (m_xToolBox->GetItemBits(nItemId) & ToolBoxItemBits::DROPDOWN); - if (m_xToolBox->GetItemBits(nItemId) & ToolBoxItemBits::DROPDOWN) + auto pFloat = m_aFloats[nItemId]; + if (pFloat) { - auto pFloat = m_aFloats[nItemId]; - if (pFloat) - { - if (bActive) - vcl::Window::GetDockingManager()->StartPopupMode(m_xToolBox, pFloat, FloatWinPopupFlags::GrabFocus); - else - vcl::Window::GetDockingManager()->EndPopupMode(pFloat); - } - auto pPopup = m_aMenus[nItemId]; - if (pPopup) + if (bActive) + vcl::Window::GetDockingManager()->StartPopupMode(m_xToolBox, pFloat, FloatWinPopupFlags::GrabFocus); + else + vcl::Window::GetDockingManager()->EndPopupMode(pFloat); + } + auto pPopup = m_aMenus[nItemId]; + if (pPopup) + { + if (bActive) { - if (bActive) - { - tools::Rectangle aRect = m_xToolBox->GetItemRect(nItemId); - pPopup->Execute(m_xToolBox, aRect, PopupMenuFlags::ExecuteDown); - } - else - pPopup->EndExecute(); + tools::Rectangle aRect = m_xToolBox->GetItemRect(nItemId); + pPopup->Execute(m_xToolBox, aRect, PopupMenuFlags::ExecuteDown); } + else + pPopup->EndExecute(); } } - virtual bool get_item_active(const OString& rIdent) const override + bool get_menu_item_active(const OString& rIdent) const override { - return m_xToolBox->IsItemChecked(m_xToolBox->GetItemId(OUString::fromUtf8(rIdent))); + sal_uInt16 nItemId = m_xToolBox->GetItemId(OUString::fromUtf8(rIdent)); + assert (m_xToolBox->GetItemBits(nItemId) & ToolBoxItemBits::DROPDOWN); + + auto aFloat = m_aFloats.find(nItemId); + if (aFloat != m_aFloats.end()) + { + return vcl::Window::GetDockingManager()->IsInPopupMode(aFloat->second); + } + + auto aPopup = m_aMenus.find(nItemId); + if (aPopup != m_aMenus.end()) + { + return PopupMenu::GetActivePopupMenu() == aPopup->second;; + } + + return false; } virtual void set_item_popover(const OString& rIdent, weld::Widget* pPopover) override @@ -1113,7 +1137,7 @@ IMPL_LINK_NOARG(SalInstanceToolbar, ClickHdl, ToolBox*, void) IMPL_LINK_NOARG(SalInstanceToolbar, DropdownClick, ToolBox*, void) { sal_uInt16 nItemId = m_xToolBox->GetCurItemId(); - set_item_active(m_xToolBox->GetItemCommand(nItemId).toUtf8(), true); + set_menu_item_active(m_xToolBox->GetItemCommand(nItemId).toUtf8(), true); } namespace { diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 1f9815839f24..1addc51082d2 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -7138,16 +7138,10 @@ public: { disable_item_notify_events(); - auto aFind = m_aMenuButtonMap.find(rIdent); - if (aFind != m_aMenuButtonMap.end()) - aFind->second->set_active(bActive); - else - { - GtkToolButton* pToolButton = m_aMap.find(rIdent)->second; - assert(GTK_IS_TOGGLE_TOOL_BUTTON(pToolButton) || !bActive); - if (GTK_IS_TOGGLE_TOOL_BUTTON(pToolButton)) - gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pToolButton), bActive); - } + GtkToolButton* pToolButton = m_aMap.find(rIdent)->second; + assert(GTK_IS_TOGGLE_TOOL_BUTTON(pToolButton) || !bActive); + if (GTK_IS_TOGGLE_TOOL_BUTTON(pToolButton)) + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pToolButton), bActive); enable_item_notify_events(); } @@ -7162,6 +7156,24 @@ public: return gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pToolButton)); } + virtual void set_menu_item_active(const OString& rIdent, bool bActive) override + { + disable_item_notify_events(); + + auto aFind = m_aMenuButtonMap.find(rIdent); + assert (aFind != m_aMenuButtonMap.end()); + aFind->second->set_active(bActive); + + enable_item_notify_events(); + } + + virtual bool get_menu_item_active(const OString& rIdent) const override + { + auto aFind = m_aMenuButtonMap.find(rIdent); + assert (aFind != m_aMenuButtonMap.end()); + return aFind->second->get_active(); + } + virtual void insert_separator(int pos, const OUString& rId) override { GtkToolItem* pItem = gtk_separator_tool_item_new(); |