extensions/source/bibliography/framectr.cxx |   21 +++++++++++----------
 extensions/source/bibliography/framectr.hxx |    2 ++
 2 files changed, 13 insertions(+), 10 deletions(-)

New commits:
commit 918316ba57230b1eaaf5138507546f743687e52b
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Fri Aug 28 15:58:11 2020 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Fri Aug 28 22:01:14 2020 +0200

    bibliography copy and paste doesn't work from menus
    
    when using native gtk menubar and menus because the focus
    isn't in the bibliography window at that stage. Just remember
    who had the focus when enabling/disabling the copy/paste entries.
    
    Change-Id: I52e907725691932bdc61e0774ef5d2a50f0eb8cf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101555
    Tested-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/extensions/source/bibliography/framectr.cxx 
b/extensions/source/bibliography/framectr.cxx
index 6e70479e20d2..d41b7c78c9b7 100644
--- a/extensions/source/bibliography/framectr.cxx
+++ b/extensions/source/bibliography/framectr.cxx
@@ -225,7 +225,8 @@ void BibFrameController_Impl::dispose()
     mxImpl->aLC.disposeAndClear(aObject);
     m_xDatMan.clear();
     aStatusListeners.clear();
- }
+    m_xLastQueriedFocusWin.clear();
+}
 
 void BibFrameController_Impl::addEventListener( const uno::Reference< 
lang::XEventListener > & aListener )
 {
@@ -560,7 +561,7 @@ void BibFrameController_Impl::dispatch(const util::URL& 
_rURL, const uno::Sequen
     }
     else if(aCommand == "Cut")
     {
-        vcl::Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
+        vcl::Window* pChild = m_xLastQueriedFocusWin.get();
         if(pChild)
         {
             KeyEvent aEvent( 0, KeyFuncType::CUT );
@@ -569,7 +570,7 @@ void BibFrameController_Impl::dispatch(const util::URL& 
_rURL, const uno::Sequen
     }
     else if(aCommand == "Copy")
     {
-        vcl::Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
+        vcl::Window* pChild = m_xLastQueriedFocusWin.get();
         if(pChild)
         {
             KeyEvent aEvent( 0, KeyFuncType::COPY );
@@ -578,7 +579,7 @@ void BibFrameController_Impl::dispatch(const util::URL& 
_rURL, const uno::Sequen
     }
     else if(aCommand == "Paste")
     {
-        vcl::Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
+        vcl::Window* pChild = m_xLastQueriedFocusWin.get();
         if(pChild)
         {
             KeyEvent aEvent( 0, KeyFuncType::PASTE );
@@ -648,21 +649,21 @@ void BibFrameController_Impl::addStatusListener(
     }
     else if(aURL.Path == "Cut")
     {
-        vcl::Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
-        Edit* pEdit = dynamic_cast<Edit*>( pChild );
+        m_xLastQueriedFocusWin = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
+        Edit* pEdit = dynamic_cast<Edit*>(m_xLastQueriedFocusWin.get());
         aEvent.IsEnabled = pEdit && !pEdit->IsReadOnly() && 
pEdit->GetSelection().Len();
     }
     if(aURL.Path == "Copy")
     {
-        vcl::Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
-        Edit* pEdit = dynamic_cast<Edit*>( pChild );
+        m_xLastQueriedFocusWin = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
+        Edit* pEdit = dynamic_cast<Edit*>(m_xLastQueriedFocusWin.get());
         aEvent.IsEnabled = pEdit && pEdit->GetSelection().Len();
     }
     else if(aURL.Path == "Paste" )
     {
         aEvent.IsEnabled = false;
-        vcl::Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
-        Edit* pEdit = dynamic_cast<Edit*>( pChild );
+        m_xLastQueriedFocusWin = lcl_GetFocusChild( VCLUnoHelper::GetWindow( 
xWindow ) );
+        Edit* pEdit = dynamic_cast<Edit*>(m_xLastQueriedFocusWin.get());
         if (pEdit && !pEdit->IsReadOnly())
         {
             uno::Reference< datatransfer::clipboard::XClipboard > xClip = 
pEdit->GetClipboard();
diff --git a/extensions/source/bibliography/framectr.hxx 
b/extensions/source/bibliography/framectr.hxx
index 50bf20cfd057..75c336c763f0 100644
--- a/extensions/source/bibliography/framectr.hxx
+++ b/extensions/source/bibliography/framectr.hxx
@@ -28,6 +28,7 @@
 #include <cppuhelper/implbase.hxx>
 #include <rtl/ref.hxx>
 #include <tools/link.hxx>
+#include <vcl/window.hxx>
 #include <vector>
 #include <memory>
 
@@ -67,6 +68,7 @@ friend class BibFrameCtrl_Impl;
     css::uno::Reference< css::frame::XFrame >                 xFrame;
     bool                        bDisposing;
     rtl::Reference<BibDataManager>                            m_xDatMan;
+    VclPtr<vcl::Window> m_xLastQueriedFocusWin;
 
     DECL_LINK( DisposeHdl, void*, void );
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to