summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2020-08-02 14:52:02 -0400
committerAshod Nakashian <ash@collabora.com>2020-08-11 17:34:47 +0200
commit4fd2679a7a2b0494da84f344ab97b835edf73377 (patch)
tree3c4c043664fbee79758870d270e458b6d378ab0a /include
parent95ba7d3eb0a1d78958d43573d73669935364f481 (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>
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 70dd8fd3b2fc..c77c2f246ad1 100644
--- a/include/editeng/outliner.hxx
+++ b/include/editeng/outliner.hxx
@@ -363,7 +363,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 e3c75b4191c3..3e37b8b68597 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 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 e9964a20adfb..e9863fd99a03 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -161,6 +161,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;
@@ -340,8 +343,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().