follow org.freedesktop.appearance.color-scheme setting
[LibreOffice.git] / include / sfx2 / lokhelper.hxx
blob4ac50a19cc691015be8eba40be5b999fbbf4040c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
19 #include <cstddef>
20 #include <rtl/string.hxx>
21 #include <optional>
22 #include <string_view>
24 struct SFX2_DLLPUBLIC LokMouseEventData
26 int mnType;
27 Point maPosition;
28 int mnCount;
29 MouseEventModifiers meModifiers;
30 int mnButtons;
31 int mnModifier;
32 std::optional<Point> maLogicPosition;
34 LokMouseEventData(int nType, Point aPosition, int nCount, MouseEventModifiers eModifiers, int nButtons, int nModifier)
35 : mnType(nType)
36 , maPosition(aPosition)
37 , mnCount(nCount)
38 , meModifiers(eModifiers)
39 , mnButtons(nButtons)
40 , mnModifier(nModifier)
44 #include <boost/property_tree/ptree_fwd.hpp>
46 class SFX2_DLLPUBLIC SfxLokHelper
48 public:
49 /// Create a new view shell from the current view frame.
50 /// This assumes a single document is ever loaded.
51 static int createView();
52 /// Create a new view shell for the given DocId, for multi-document support.
53 static int createView(int nDocId);
54 /// Destroy a view shell from the global shell list.
55 static void destroyView(int nId);
56 /// Set a view shell as current one.
57 static void setView(int nId);
58 /// Get view shell with id
59 static SfxViewShell* getViewOfId(int nId);
60 /// Get the currently active view.
61 static int getView(const SfxViewShell* pViewShell = nullptr);
62 /// Get the number of views of the current DocId.
63 static std::size_t getViewsCount(int nDocId);
64 /// Get viewIds of views of the current DocId.
65 static bool getViewIds(int nDocId, int* pArray, size_t nSize);
66 /// Set View Blocked for some uno commands
67 static void setBlockedCommandList(int nViewId, const char* blockedCommandList);
68 /// Get the document id for a view
69 static int getDocumentIdOfView(int nViewId);
70 /// Get the default language that should be used for views
71 static const LanguageTag & getDefaultLanguage();
72 /// Set language of the given view.
73 static void setViewLanguage(int nId, const OUString& rBcp47LanguageTag);
74 /// Set the default language for views.
75 static void setDefaultLanguage(const OUString& rBcp47LanguageTag);
76 /// Set the locale for the given view.
77 static void setViewLocale(int nId, const OUString& rBcp47LanguageTag);
78 /// Get the device form factor that should be used for a new view.
79 static LOKDeviceFormFactor getDeviceFormFactor();
80 /// Set the device form factor that should be used for a new view.
81 static void setDeviceFormFactor(std::u16string_view rDeviceFormFactor);
83 /// Iterate over any view shell, except pThisViewShell, passing it to the f function.
84 template<typename ViewShellType, typename FunctionType>
85 static void forEachOtherView(ViewShellType* pThisViewShell, FunctionType f);
87 /// Invoke the LOK callback of all other views showing the same document as pThisView, with a payload of rKey-rPayload.
88 static void notifyOtherViews(const SfxViewShell* pThisView, int nType, std::string_view rKey,
89 const OString& rPayload);
90 /// Invoke the LOK callback of all views except pThisView, with a JSON payload created from the given property tree.
91 static void notifyOtherViews(const SfxViewShell* pThisView, int nType,
92 const boost::property_tree::ptree& rTree);
93 /// Same as notifyOtherViews(), but works on a selected "other" view, not on all of them.
94 static void notifyOtherView(const SfxViewShell* pThisView, SfxViewShell const* pOtherView,
95 int nType, std::string_view rKey, const OString& rPayload);
96 /// Same as notifyOtherViews(), the property-tree version, but works on a selected "other" view, not on all of them.
97 static void notifyOtherView(const SfxViewShell* pThisView, SfxViewShell const* pOtherView,
98 int nType, const boost::property_tree::ptree& rTree);
100 /// Emits a LOK_CALLBACK_STATE_CHANGED
101 static void sendUnoStatus(const SfxViewShell* pShell, const SfxPoolItem* pItem);
102 /// Emits a LOK_CALLBACK_WINDOW
103 static void notifyWindow(const SfxViewShell* pThisView,
104 vcl::LOKWindowId nWindowId,
105 std::u16string_view rAction,
106 const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>());
107 /// Emits a LOK_CALLBACK_DOCUMENT_SIZE_CHANGED - if @bInvalidateAll - first invalidates all parts
108 static void notifyDocumentSizeChanged(SfxViewShell const* pThisView, const OString& rPayload, vcl::ITiledRenderable* pDoc, bool bInvalidateAll = true);
109 /// Emits a LOK_CALLBACK_DOCUMENT_SIZE_CHANGED for all views of the same document - if @bInvalidateAll - first invalidates all parts
110 static void notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable* pDoc, bool bInvalidateAll = true);
111 /// Emits a LOK_CALLBACK_INVALIDATE_TILES, but tweaks it according to setOptionalFeatures() if needed.
112 static void notifyInvalidation(SfxViewShell const* pThisView, tools::Rectangle const *);
113 /// Notifies all views with the given type and payload.
114 static void notifyAllViews(int nType, const OString& rPayload);
116 /// Notify about the editing context change.
117 static void notifyContextChange(SfxViewShell const* pViewShell, const OUString& aApplication, const OUString& aContext);
119 // Notify about the given type needing an update.
120 static void notifyUpdate(SfxViewShell const* pViewShell, int nType);
121 // Notify about the given type needing a per-viewid update.
122 static void notifyUpdatePerViewId(SfxViewShell const* pViewShell, int nType);
123 /// Same as notifyUpdatePerViewId(), pTargetShell will be notified, relevant viewId in pViewShell,
124 /// pSourceView->getLOKPayload() will be called to get the data.
125 static void notifyUpdatePerViewId(SfxViewShell const* pTargetShell, SfxViewShell const* pViewShell,
126 SfxViewShell const* pSourceShell, int nType);
127 // Notify other views about the given type needing a per-viewid update.
128 static void notifyOtherViewsUpdatePerViewId(SfxViewShell const* pViewShell, int nType);
130 static OString makePayloadJSON(const SfxViewShell* pThisView, int nViewId, std::string_view rKey, const OString& rPayload);
131 /// Makes a LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR payload, but tweaks it according to setOptionalFeatures() if needed.
132 static OString makeVisCursorInvalidation(int nViewId, const OString& rRectangle,
133 bool bMispelledWord = false, const OString& rHyperlink = "");
135 /// Helper for posting async key event
136 static void postKeyEventAsync(const VclPtr<vcl::Window> &xWindow,
137 int nType, int nCharCode, int nKeyCode, int nRepeat = 0);
139 /// Helper for posting input event
140 static void postExtTextEventAsync(const VclPtr<vcl::Window> &xWindow,
141 int nType, const OUString &rText);
143 /// Helper for posting async mouse event
144 static void postMouseEventAsync(const VclPtr<vcl::Window> &xWindow, LokMouseEventData const & rLokMouseEventData);
146 /// A special value to signify 'infinity'.
147 /// This value is chosen such that sal_Int32 will not overflow when manipulated.
148 static const tools::Long MaxTwips = 1e9;
150 private:
151 static int createView(SfxViewFrame* pViewFrame, ViewShellDocId docId);
154 template<typename ViewShellType, typename FunctionType>
155 void SfxLokHelper::forEachOtherView(ViewShellType* pThisViewShell, FunctionType f)
157 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
158 while (pViewShell)
160 auto pOtherViewShell = dynamic_cast<ViewShellType*>(pViewShell);
161 if (pOtherViewShell != nullptr && pOtherViewShell != pThisViewShell && pOtherViewShell->GetDocId() == pThisViewShell->GetDocId())
163 f(pOtherViewShell);
165 pViewShell = SfxViewShell::GetNext(*pViewShell);
169 #endif
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */