summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2020-08-02 14:52:02 -0400
committerTor Lillqvist <tml@collabora.com>2020-11-21 22:26:19 +0100
commite82335afd6e3e9a75275865661cf14a0a2959603 (patch)
tree8d2ff36b57485bc9e3244073f7741784e6743a32 /include
parent23951bdc3836b252aab0e7628d8839e89b5a9f6d (diff)
sfx2: lok: reliably support multi-documents
Instead of using the current view to set the DocId, we instead make sure that the ShellView object has the DocId set at construction time. This turned out to be necessary in at least one case (which has a unit-test that failed), which is when events fired during the creation of a new view. The cursor position is notified before we have a chance to set the DocId and because of that we miss the notifications (or worse, we end up sending them to all other documents' views in an effort to fix this bug). This approach is clean and always guarantees that all views have the correct DocId set as soon as possible and that all notifications are sent as expected. A unit-test is added to exercise mult-document usage, which exposed a number of bugs and issues that have been addressed in this patch. Change-Id: Icf5145fb1dabd0d029368310c2b9bf73ae927ccc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99975 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Reviewed-by: Ashod Nakashian <ash@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106252 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'include')
-rw-r--r--include/editeng/outliner.hxx1
-rw-r--r--include/sfx2/lokhelper.hxx17
-rw-r--r--include/sfx2/viewsh.hxx15
3 files changed, 25 insertions, 8 deletions
diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx
index f06bd9a7448d..a6bc9fbd7ff2 100644
--- a/include/editeng/outliner.hxx
+++ b/include/editeng/outliner.hxx
@@ -365,7 +365,6 @@ class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI OutlinerViewShell
public:
virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) const = 0;
virtual ViewShellId GetViewShellId() const = 0;
- virtual void SetDocId(ViewShellDocId nId) = 0;
virtual ViewShellDocId GetDocId() const = 0;
/// Wrapper around SfxLokHelper::notifyOtherViews().
virtual void NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload) = 0;
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 2aad968681b8..521bf4207458 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -45,19 +45,21 @@ class SFX2_DLLPUBLIC SfxLokHelper
{
public:
/// Create a new view shell from the current view frame.
+ /// This assumes a single document is ever loaded.
static int createView();
+ /// Create a new view shell for the given DocId, for multi-document support.
+ static int createView(int nDocId);
/// Destroy a view shell from the global shell list.
static void destroyView(int nId);
/// Set a view shell as current one.
static void setView(int nId);
/// Get the currently active view.
static int getView(const SfxViewShell* pViewShell = nullptr);
- /// Get the number of views of the current object shell.
- static std::size_t getViewsCount();
- /// Get viewIds of views of the current object shell.
- static bool getViewIds(int* pArray, size_t nSize);
- /// Set the document id of the currently active view
- static void setDocumentIdOfView(int nId);
+ /// Get the number of views of the current DocId.
+ static std::size_t getViewsCount(int nDocId);
+ /// Get viewIds of views of the current DocId.
+ static bool getViewIds(int nDocId, int* pArray, size_t nSize);
+
/// Get the document id for a view
static int getDocumentIdOfView(int nViewId);
/// Get the default language that should be used for views
@@ -125,6 +127,9 @@ public:
/// A special value to signify 'infinity'.
/// This value is chosen such that sal_Int32 will not overflow when manipulated.
static const tools::Long MaxTwips = 1e9;
+
+private:
+ static int createView(SfxViewFrame* pViewFrame, ViewShellDocId docId);
};
template<typename ViewShellType, typename FunctionType>
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 7965cb79dfc4..67671a6a678b 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -165,6 +165,9 @@ friend class SfxPrinterController;
LanguageTag maLOKLocale;
LOKDeviceFormFactor maLOKDeviceFormFactor;
+ /// Used to set the DocId at construction time. See SetCurrentDocId.
+ static ViewShellDocId mnCurrentDocId;
+
protected:
virtual void Activate(bool IsMDIActivate) override;
virtual void Deactivate(bool IsMDIActivate) override;
@@ -339,8 +342,18 @@ public:
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
/// See OutlinerViewShell::GetViewShellId().
ViewShellId GetViewShellId() const override;
- void SetDocId(ViewShellDocId nId) override;
+
+ /// Set the current DocId, which is used by Mobile LOKit to
+ /// load multiple documents and yet identify the views of each.
+ /// There are events that are fired while creating a new view,
+ /// and if we don't have a DocId, we can't know which other views
+ /// within the same document (if any) should get those events.
+ /// By setting this static value, we are able to set the DocId
+ /// of each SfxViewShell at construction time.
+ static void SetCurrentDocId(ViewShellDocId nId);
+ /// Get the DocId used by Mobile LOKit to load multiple documents.
ViewShellDocId GetDocId() const override;
+
/// See OutlinerViewShell::NotifyOtherViews().
void NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload) override;
/// See OutlinerViewShell::NotifyOtherView().