Blame SOURCES/0141-gtktiledviewer-use-setView-before-postKeyEvent.patch

135360
From 3206f71ad36da6453801b4e3105f9968944f1aec Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Wed, 16 Sep 2015 12:30:25 +0200
135360
Subject: [PATCH 141/398] gtktiledviewer: use setView() before postKeyEvent()
135360
135360
Also in SfxLokHelper::setView() set the current view shell directly,
135360
GetFocus() in VCL may be a NOP for hidden windows.
135360
135360
With this, the Writer layout dump shows that two Gtk windows can have
135360
different cursor positions correctly.
135360
135360
Change-Id: I81890c1d8ad7972f1194db3d5f2e9d8a39fc2f87
135360
(cherry picked from commit f2e55ea10676d14c6564696a0648c0edbe4bd36d)
135360
---
135360
 libreofficekit/source/gtk/lokdocview.cxx | 21 +++++++++++++--------
135360
 sfx2/source/view/lokhelper.cxx           |  2 +-
135360
 2 files changed, 14 insertions(+), 9 deletions(-)
135360
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index 92095f2d9707..e84939e0da46 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -106,6 +106,9 @@ struct _LOKDocViewPrivate
135360
     /// If we are in the middle of a drag of a graphic selection handle.
135360
     gboolean m_bInDragGraphicHandles[8];
135360
     ///@}
135360
+
135360
+    /// View ID, returned by createView() or 0 by default.
135360
+    int m_nViewId;
135360
 };
135360
 
135360
 enum
135360
@@ -240,6 +243,7 @@ postKeyEventInThread(gpointer data)
135360
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
135360
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
135360
 
135360
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
135360
     priv->m_pDocument->pClass->postKeyEvent(priv->m_pDocument,
135360
                                             pLOEvent->m_nKeyEvent,
135360
                                             pLOEvent->m_nCharCode,
135360
@@ -1847,18 +1851,19 @@ lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
135360
     return GTK_WIDGET (g_initable_new (LOK_TYPE_DOC_VIEW, cancellable, error, "lopath", pPath, NULL));
135360
 }
135360
 
135360
-SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pLOKDocView)
135360
+SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOKDocView)
135360
 {
135360
-    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView));
135360
-    GtkWidget* pDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
135360
-                                                    "lopath", priv->m_aLOPath, "lopointer", priv->m_pOffice, "docpointer", priv->m_pDocument, NULL));
135360
+    LOKDocViewPrivate* pOldPriv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pOldLOKDocView));
135360
+    GtkWidget* pNewDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
135360
+                                                       "lopath", pOldPriv->m_aLOPath, "lopointer", pOldPriv->m_pOffice, "docpointer", pOldPriv->m_pDocument, NULL));
135360
 
135360
     // No documentLoad(), just a createView().
135360
-    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pDocView));
135360
-    pDocument->pClass->createView(pDocument);
135360
+    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pNewDocView));
135360
+    LOKDocViewPrivate* pNewPriv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(LOK_DOC_VIEW(pNewDocView)));
135360
+    pNewPriv->m_nViewId = pDocument->pClass->createView(pDocument);
135360
 
135360
-    postDocumentLoad(pDocView);
135360
-    return pDocView;
135360
+    postDocumentLoad(pNewDocView);
135360
+    return pNewDocView;
135360
 }
135360
 
135360
 /**
135360
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
135360
index f53d2b35b1bd..0beb06ddd956 100644
135360
--- a/sfx2/source/view/lokhelper.cxx
135360
+++ b/sfx2/source/view/lokhelper.cxx
135360
@@ -46,7 +46,7 @@ void SfxLokHelper::setView(size_t nId)
135360
 
135360
     SfxViewShell* pViewShell = rViewArr[nId];
135360
     if (SfxViewFrame* pViewFrame = pViewShell->GetViewFrame())
135360
-        pViewFrame->GetWindow().GrabFocus();
135360
+        pViewFrame->MakeActive_Impl(false);
135360
 }
135360
 
135360
 size_t SfxLokHelper::getView()
135360
-- 
135360
2.12.0
135360