1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef INCLUDED_SFX2_LOKHELPER_HXX
11 #define INCLUDED_SFX2_LOKHELPER_HXX
13 #include <vcl/IDialogRenderable.hxx>
14 #include <vcl/ITiledRenderable.hxx>
15 #include <vcl/event.hxx>
16 #include <sfx2/dllapi.h>
17 #include <sfx2/viewsh.hxx>
18 #include <tools/gen.hxx>
20 #include <rtl/string.hxx>
23 struct SFX2_DLLPUBLIC LokMouseEventData
28 MouseEventModifiers meModifiers
;
31 std::optional
<Point
> maLogicPosition
;
33 LokMouseEventData(int nType
, Point aPosition
, int nCount
, MouseEventModifiers eModifiers
, int nButtons
, int nModifier
)
35 , maPosition(aPosition
)
37 , meModifiers(eModifiers
)
39 , mnModifier(nModifier
)
43 #include <boost/property_tree/ptree_fwd.hpp>
45 class SFX2_DLLPUBLIC SfxLokHelper
48 /// Create a new view shell from the current view frame.
49 /// This assumes a single document is ever loaded.
50 static int createView();
51 /// Create a new view shell for the given DocId, for multi-document support.
52 static int createView(int nDocId
);
53 /// Destroy a view shell from the global shell list.
54 static void destroyView(int nId
);
55 /// Set a view shell as current one.
56 static void setView(int nId
);
57 /// Get view shell with id
58 static SfxViewShell
* getViewOfId(int nId
);
59 /// Get the currently active view.
60 static int getView(const SfxViewShell
* pViewShell
= nullptr);
61 /// Get the number of views of the current DocId.
62 static std::size_t getViewsCount(int nDocId
);
63 /// Get viewIds of views of the current DocId.
64 static bool getViewIds(int nDocId
, int* pArray
, size_t nSize
);
65 /// Set View Blocked for some uno commands
66 static void setBlockedCommandList(int nViewId
, const char* bolckedCommandList
);
67 /// Get the document id for a view
68 static int getDocumentIdOfView(int nViewId
);
69 /// Get the default language that should be used for views
70 static LanguageTag
getDefaultLanguage();
71 /// Set language of the given view.
72 static void setViewLanguage(int nId
, const OUString
& rBcp47LanguageTag
);
73 /// Set the default language for views.
74 static void setDefaultLanguage(const OUString
& rBcp47LanguageTag
);
75 /// Set the locale for the given view.
76 static void setViewLocale(int nId
, const OUString
& rBcp47LanguageTag
);
77 /// Get the device form factor that should be used for a new view.
78 static LOKDeviceFormFactor
getDeviceFormFactor();
79 /// Set the device form factor that should be used for a new view.
80 static void setDeviceFormFactor(const OUString
& rDeviceFormFactor
);
82 /// Iterate over any view shell, except pThisViewShell, passing it to the f function.
83 template<typename ViewShellType
, typename FunctionType
>
84 static void forEachOtherView(ViewShellType
* pThisViewShell
, FunctionType f
);
86 /// Invoke the LOK callback of all other views showing the same document as pThisView, with a payload of rKey-rPayload.
87 static void notifyOtherViews(const SfxViewShell
* pThisView
, int nType
, const OString
& rKey
,
88 const OString
& rPayload
);
89 /// Invoke the LOK callback of all views except pThisView, with a JSON payload created from the given property tree.
90 static void notifyOtherViews(const SfxViewShell
* pThisView
, int nType
,
91 const boost::property_tree::ptree
& rTree
);
92 /// Same as notifyOtherViews(), but works on a selected "other" view, not on all of them.
93 static void notifyOtherView(const SfxViewShell
* pThisView
, SfxViewShell
const* pOtherView
,
94 int nType
, const OString
& rKey
, const OString
& rPayload
);
95 /// Same as notifyOtherViews(), the property-tree version, but works on a selected "other" view, not on all of them.
96 static void notifyOtherView(const SfxViewShell
* pThisView
, SfxViewShell
const* pOtherView
,
97 int nType
, const boost::property_tree::ptree
& rTree
);
99 /// Emits a LOK_CALLBACK_STATE_CHANGED
100 static void sendUnoStatus(const SfxViewShell
* pShell
, const SfxPoolItem
* pItem
);
101 /// Emits a LOK_CALLBACK_WINDOW
102 static void notifyWindow(const SfxViewShell
* pThisView
,
103 vcl::LOKWindowId nWindowId
,
104 const OUString
& rAction
,
105 const std::vector
<vcl::LOKPayloadItem
>& rPayload
= std::vector
<vcl::LOKPayloadItem
>());
106 /// Emits a LOK_CALLBACK_DOCUMENT_SIZE_CHANGED - if @bInvalidateAll - first invalidates all parts
107 static void notifyDocumentSizeChanged(SfxViewShell
const* pThisView
, const OString
& rPayload
, vcl::ITiledRenderable
* pDoc
, bool bInvalidateAll
= true);
108 /// Emits a LOK_CALLBACK_DOCUMENT_SIZE_CHANGED for all views of the same document - if @bInvalidateAll - first invalidates all parts
109 static void notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable
* pDoc
, bool bInvalidateAll
= true);
110 /// Emits a LOK_CALLBACK_INVALIDATE_TILES, but tweaks it according to setOptionalFeatures() if needed.
111 static void notifyInvalidation(SfxViewShell
const* pThisView
, tools::Rectangle
const *);
112 /// Notifies all views with the given type and payload.
113 static void notifyAllViews(int nType
, const OString
& rPayload
);
115 /// Notify about the editing context change.
116 static void notifyContextChange(SfxViewShell
const* pViewShell
, const OUString
& aApplication
, const OUString
& aContext
);
118 // Notify about the given type needing an update.
119 static void notifyUpdate(SfxViewShell
const* pViewShell
, int nType
);
120 // Notify about the given type needing a per-viewid update.
121 static void notifyUpdatePerViewId(SfxViewShell
const* pViewShell
, int nType
);
122 /// Same as notifyUpdatePerViewId(), pTargetShell will be notified, relevant viewId in pViewShell,
123 /// pSourceView->getLOKPayload() will be called to get the data.
124 static void notifyUpdatePerViewId(SfxViewShell
const* pTargetShell
, SfxViewShell
const* pViewShell
,
125 SfxViewShell
const* pSourceShell
, int nType
);
126 // Notify other views about the given type needing a per-viewid update.
127 static void notifyOtherViewsUpdatePerViewId(SfxViewShell
const* pViewShell
, int nType
);
129 static OString
makePayloadJSON(const SfxViewShell
* pThisView
, int nViewId
, const OString
& rKey
, const OString
& rPayload
);
130 /// Makes a LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR payload, but tweaks it according to setOptionalFeatures() if needed.
131 static OString
makeVisCursorInvalidation(int nViewId
, const OString
& rRectangle
,
132 bool bMispelledWord
= false, const OString
& rHyperlink
= "");
134 /// Helper for posting async key event
135 static void postKeyEventAsync(const VclPtr
<vcl::Window
> &xWindow
,
136 int nType
, int nCharCode
, int nKeyCode
, int nRepeat
= 0);
138 /// Helper for posting input event
139 static void postExtTextEventAsync(const VclPtr
<vcl::Window
> &xWindow
,
140 int nType
, const OUString
&rText
);
142 /// Helper for posting async mouse event
143 static void postMouseEventAsync(const VclPtr
<vcl::Window
> &xWindow
, LokMouseEventData
const & rLokMouseEventData
);
145 /// A special value to signify 'infinity'.
146 /// This value is chosen such that sal_Int32 will not overflow when manipulated.
147 static const tools::Long MaxTwips
= 1e9
;
150 static int createView(SfxViewFrame
* pViewFrame
, ViewShellDocId docId
);
153 template<typename ViewShellType
, typename FunctionType
>
154 void SfxLokHelper::forEachOtherView(ViewShellType
* pThisViewShell
, FunctionType f
)
156 SfxViewShell
* pViewShell
= SfxViewShell::GetFirst();
159 auto pOtherViewShell
= dynamic_cast<ViewShellType
*>(pViewShell
);
160 if (pOtherViewShell
!= nullptr && pOtherViewShell
!= pThisViewShell
&& pOtherViewShell
->GetDocId() == pThisViewShell
->GetDocId())
164 pViewShell
= SfxViewShell::GetNext(*pViewShell
);
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */