include/sfx2/charwin.hxx        |    4 ++--
 sfx2/source/control/charwin.cxx |   31 ++++++++++++++++++-------------
 2 files changed, 20 insertions(+), 15 deletions(-)

New commits:
commit 20c86bd1059b54915190ce2e3dd39206d293aced
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Apr 22 23:33:57 2023 +0300
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Apr 23 06:20:06 2023 +0200

    tdf#153806 a11y Allow opening context menu of fav/recent char w/ keyboard
    
    This is similar to
    
        commit 1f437264084fd173116965fa4d856aeafdfe7a98
        Date:   Sun Apr 2 00:36:44 2023 +0300
    
            tdf#153806 a11y: Allow opening context menu in special char dlg 
using keyboard
    
    , but now for the character views in the "Recent Characters"
    and "Favorite Characters" sections in the special character dialog,
    and thus addresses this comment from the commit message of the
    above-mentioned commit:
    
    > 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.
    
    Turns out that the position returned by `CommandEvent::GetMousePosPixel`
    is good for the keyboard case as well, is right in the middle of the
    char view widget.
    
    Change-Id: I9f55b99398d557b19263bf531f6a857d274d3d9f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150815
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/sfx2/charwin.hxx b/include/sfx2/charwin.hxx
index 405af4bd53ad..a2beabc5b2df 100644
--- a/include/sfx2/charwin.hxx
+++ b/include/sfx2/charwin.hxx
@@ -44,6 +44,7 @@ private:
     virtual void GetFocus() override;
     virtual void LoseFocus() override;
     virtual bool KeyInput(const KeyEvent&) override;
+    virtual bool Command(const CommandEvent&) override;
     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
 public:
     SvxCharView(const VclPtr<VirtualDevice>& rVirDev);
diff --git a/sfx2/source/control/charwin.cxx b/sfx2/source/control/charwin.cxx
index f80bd30b684d..b94d2bcd1e82 100644
--- a/sfx2/source/control/charwin.cxx
+++ b/sfx2/source/control/charwin.cxx
@@ -19,6 +19,7 @@
 
 #include <vcl/settings.hxx>
 #include <vcl/virdev.hxx>
+#include <vcl/commandevent.hxx>
 #include <vcl/event.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/weldutils.hxx>
@@ -65,16 +66,10 @@ bool SvxCharView::MouseButtonDown(const MouseEvent& rMEvt)
         }
 
         maMouseClickHdl.Call(this);
+        return true;
     }
 
-    if (rMEvt.IsRight())
-    {
-        GrabFocus();
-        Invalidate();
-        createContextMenu(rMEvt.GetPosPixel());
-    }
-
-    return true;
+    return CustomWidgetController::MouseButtonDown(rMEvt);
 }
 
 bool SvxCharView::KeyInput(const KeyEvent& rKEvt)
@@ -92,6 +87,19 @@ bool SvxCharView::KeyInput(const KeyEvent& rKEvt)
     return bRet;
 }
 
+bool SvxCharView::Command(const CommandEvent& rCommandEvent)
+{
+    if (rCommandEvent.GetCommand() == CommandEventId::ContextMenu)
+    {
+        GrabFocus();
+        Invalidate();
+        createContextMenu(rCommandEvent.GetMousePosPixel());
+        return true;
+    }
+
+    return weld::CustomWidgetController::Command(rCommandEvent);
+}
+
 void SvxCharView::InsertCharToDoc()
 {
     if (GetText().isEmpty())
commit da4c97968080707c91a15f53d07e6d062977b19a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Apr 22 23:28:58 2023 +0300
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Apr 23 06:19:58 2023 +0200

    sfx2: Pass SvxCharView context menu pos as param
    
    ... and drop the `maPosition` member that was used for that
    purpose only.
    
    Change-Id: If449a12e6e8e37c28d7b2b139e20c4c307d41eb8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150814
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/sfx2/charwin.hxx b/include/sfx2/charwin.hxx
index bc482af2514f..405af4bd53ad 100644
--- a/include/sfx2/charwin.hxx
+++ b/include/sfx2/charwin.hxx
@@ -30,7 +30,6 @@ class SFX2_DLLPUBLIC SvxCharView final : public 
weld::CustomWidgetController
 private:
     VclPtr<VirtualDevice> mxVirDev;
     tools::Long            mnY;
-    Point           maPosition;
     vcl::Font       maFont;
     bool            maHasInsert;
     OUString        m_sText;
@@ -56,7 +55,7 @@ public:
     void            SetHasInsert( bool bInsert );
     void            InsertCharToDoc();
 
-    void            createContextMenu();
+    void            createContextMenu(const Point& rPosition);
 
     Size            get_preferred_size() const { return 
GetDrawingArea()->get_preferred_size(); }
 
diff --git a/sfx2/source/control/charwin.cxx b/sfx2/source/control/charwin.cxx
index f0c687082c9a..f80bd30b684d 100644
--- a/sfx2/source/control/charwin.cxx
+++ b/sfx2/source/control/charwin.cxx
@@ -33,7 +33,6 @@ using namespace com::sun::star;
 SvxCharView::SvxCharView(const VclPtr<VirtualDevice>& rVirDev)
     : mxVirDev(rVirDev)
     , mnY(0)
-    , maPosition(0, 0)
     , maHasInsert(true)
 {
 }
@@ -70,11 +69,9 @@ bool SvxCharView::MouseButtonDown(const MouseEvent& rMEvt)
 
     if (rMEvt.IsRight())
     {
-        Point aPosition(rMEvt.GetPosPixel());
-        maPosition = aPosition;
         GrabFocus();
         Invalidate();
-        createContextMenu();
+        createContextMenu(rMEvt.GetPosPixel());
     }
 
     return true;
@@ -107,14 +104,14 @@ void SvxCharView::InsertCharToDoc()
     comphelper::dispatchCommand(".uno:InsertSymbol", aArgs);
 }
 
-void SvxCharView::createContextMenu()
+void SvxCharView::createContextMenu(const Point& rPosition)
 {
     weld::DrawingArea* pDrawingArea = GetDrawingArea();
     std::unique_ptr<weld::Builder> xBuilder(
         Application::CreateBuilder(pDrawingArea, "sfx/ui/charviewmenu.ui"));
     std::unique_ptr<weld::Menu> xItemMenu(xBuilder->weld_menu("charviewmenu"));
     ContextMenuSelect(
-        xItemMenu->popup_at_rect(pDrawingArea, tools::Rectangle(maPosition, 
Size(1, 1))));
+        xItemMenu->popup_at_rect(pDrawingArea, tools::Rectangle(rPosition, 
Size(1, 1))));
     Invalidate();
 }
 

Reply via email to