include/svx/charmap.hxx | 1 + svx/source/dialog/charmap.cxx | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-)
New commits: commit 1f437264084fd173116965fa4d856aeafdfe7a98 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sun Apr 2 00:36:44 2023 +0300 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Mon Apr 3 17:01:56 2023 +0200 tdf#153806 a11y: Allow opening context menu in special char dlg using keyboard Open the context menu for the `CommandEventId::ContextMenu` command for the character table that is used in the special characters dialog, so opening the context menu is not only possible by right mouse click, but also using the keyboard (by pressing the context menu button or Shift+F10). Move the handling for the case where the context menu is activated using the mouse from `SvxShowCharSet::MouseButtonDown` to `SvxShowCharSet::Command`. When the context menu is activated using the keyboard, use the centre of the currently selected item for the context menu position. Adding support for opening the context menu for the recently used and favorite characters further down in the special characters dialog is independent of this and would have to be added separately. Change-Id: I55ef43708b95f5a90b06777a8aeb32a64609160d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149927 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/svx/charmap.hxx b/include/svx/charmap.hxx index 972659ff9f87..71999368fd4a 100644 --- a/include/svx/charmap.hxx +++ b/include/svx/charmap.hxx @@ -111,6 +111,7 @@ private: virtual bool MouseButtonUp(const MouseEvent& rMEvt) override; virtual void GetFocus() override; virtual void LoseFocus() override; + virtual bool Command(const CommandEvent& rCEvt) override; virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override; virtual FactoryFunction GetUITestFactory() const override; diff --git a/svx/source/dialog/charmap.cxx b/svx/source/dialog/charmap.cxx index 27fa8ccb2687..924838273d05 100644 --- a/svx/source/dialog/charmap.cxx +++ b/svx/source/dialog/charmap.cxx @@ -20,6 +20,7 @@ #include <config_wasm_strip.h> #include <utility> +#include <vcl/commandevent.hxx> #include <vcl/event.hxx> #include <vcl/fontcharmap.hxx> #include <vcl/svapp.hxx> @@ -135,18 +136,11 @@ bool SvxShowCharSet::MouseButtonDown(const MouseEvent& rMEvt) if ( !(rMEvt.GetClicks() % 2) ) aDoubleClkHdl.Call( this ); - } - if (rMEvt.IsRight()) - { - Point aPosition (rMEvt.GetPosPixel()); - int nIndex = PixelToMapIndex( rMEvt.GetPosPixel() ); - // Fire the focus event - SelectIndex( nIndex, true); - createContextMenu(aPosition); + return true; } - return true; + return CustomWidgetController::MouseButtonDown(rMEvt); } bool SvxShowCharSet::MouseButtonUp(const MouseEvent& rMEvt) @@ -187,6 +181,35 @@ bool SvxShowCharSet::MouseMove(const MouseEvent& rMEvt) return true; } +bool SvxShowCharSet::Command(const CommandEvent& rCEvt) +{ + if (rCEvt.GetCommand() == CommandEventId::ContextMenu) + { + Point aPosition; + if (rCEvt.IsMouseEvent()) + { + aPosition = rCEvt.GetMousePosPixel(); + int nIndex = PixelToMapIndex(aPosition); + // Fire the focus event + SelectIndex(nIndex, true); + } + else + { + svx::SvxShowCharSetItem* pItem = ImplGetItem(nSelectedIndex); + if (!pItem) + return true; + + // position context menu at centre of currently selected item + aPosition = MapIndexToPixel(nSelectedIndex); + aPosition.AdjustX(pItem->maRect.GetWidth() / 2); + aPosition.AdjustY(pItem->maRect.GetHeight() / 2); + } + createContextMenu(aPosition); + return true; + } + return weld::CustomWidgetController::Command(rCEvt); +} + sal_uInt16 SvxShowCharSet::GetRowPos(sal_uInt16 _nPos) { return _nPos / COLUMN_COUNT ;