Blob Blame History Raw
From 3206f71ad36da6453801b4e3105f9968944f1aec Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Wed, 16 Sep 2015 12:30:25 +0200
Subject: [PATCH 141/398] gtktiledviewer: use setView() before postKeyEvent()

Also in SfxLokHelper::setView() set the current view shell directly,
GetFocus() in VCL may be a NOP for hidden windows.

With this, the Writer layout dump shows that two Gtk windows can have
different cursor positions correctly.

Change-Id: I81890c1d8ad7972f1194db3d5f2e9d8a39fc2f87
(cherry picked from commit f2e55ea10676d14c6564696a0648c0edbe4bd36d)
---
 libreofficekit/source/gtk/lokdocview.cxx | 21 +++++++++++++--------
 sfx2/source/view/lokhelper.cxx           |  2 +-
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 92095f2d9707..e84939e0da46 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -106,6 +106,9 @@ struct _LOKDocViewPrivate
     /// If we are in the middle of a drag of a graphic selection handle.
     gboolean m_bInDragGraphicHandles[8];
     ///@}
+
+    /// View ID, returned by createView() or 0 by default.
+    int m_nViewId;
 };
 
 enum
@@ -240,6 +243,7 @@ postKeyEventInThread(gpointer data)
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     priv->m_pDocument->pClass->postKeyEvent(priv->m_pDocument,
                                             pLOEvent->m_nKeyEvent,
                                             pLOEvent->m_nCharCode,
@@ -1847,18 +1851,19 @@ lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
     return GTK_WIDGET (g_initable_new (LOK_TYPE_DOC_VIEW, cancellable, error, "lopath", pPath, NULL));
 }
 
-SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pLOKDocView)
+SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOKDocView)
 {
-    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView));
-    GtkWidget* pDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
-                                                    "lopath", priv->m_aLOPath, "lopointer", priv->m_pOffice, "docpointer", priv->m_pDocument, NULL));
+    LOKDocViewPrivate* pOldPriv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pOldLOKDocView));
+    GtkWidget* pNewDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
+                                                       "lopath", pOldPriv->m_aLOPath, "lopointer", pOldPriv->m_pOffice, "docpointer", pOldPriv->m_pDocument, NULL));
 
     // No documentLoad(), just a createView().
-    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pDocView));
-    pDocument->pClass->createView(pDocument);
+    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pNewDocView));
+    LOKDocViewPrivate* pNewPriv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(LOK_DOC_VIEW(pNewDocView)));
+    pNewPriv->m_nViewId = pDocument->pClass->createView(pDocument);
 
-    postDocumentLoad(pDocView);
-    return pDocView;
+    postDocumentLoad(pNewDocView);
+    return pNewDocView;
 }
 
 /**
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index f53d2b35b1bd..0beb06ddd956 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -46,7 +46,7 @@ void SfxLokHelper::setView(size_t nId)
 
     SfxViewShell* pViewShell = rViewArr[nId];
     if (SfxViewFrame* pViewFrame = pViewShell->GetViewFrame())
-        pViewFrame->GetWindow().GrabFocus();
+        pViewFrame->MakeActive_Impl(false);
 }
 
 size_t SfxLokHelper::getView()
-- 
2.12.0