LibreOffice Module sfx2 (master) 1
lokhelper.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#ifndef INCLUDED_SFX2_LOKHELPER_HXX
11#define INCLUDED_SFX2_LOKHELPER_HXX
12
15#include <vcl/event.hxx>
16#include <vcl/vclptr.hxx>
17#include <vcl/window.hxx>
18#include <sfx2/dllapi.h>
19#include <sfx2/viewsh.hxx>
20#include <tools/gen.hxx>
21#include <cstddef>
22#include <rtl/strbuf.hxx>
23#include <rtl/string.hxx>
24#include <optional>
25#include <string_view>
26#include <sfx2/app.hxx>
27
29{
30 int mnType;
36 std::optional<Point> maLogicPosition;
37
38 LokMouseEventData(int nType, Point aPosition, int nCount, MouseEventModifiers eModifiers, int nButtons, int nModifier)
39 : mnType(nType)
40 , maPosition(aPosition)
42 , meModifiers(eModifiers)
43 , mnButtons(nButtons)
44 , mnModifier(nModifier)
45 {}
46};
47
48#include <boost/property_tree/ptree_fwd.hpp>
49
50namespace com::sun::star::ui { struct ContextChangeEventObject; };
51
53{
54public:
56 static std::unordered_map<OUString, css::uno::Reference<com::sun::star::ui::XAcceleratorConfiguration>>& getAcceleratorConfs();
59 static int createView();
61 static int createView(int nDocId);
63 static void destroyView(int nId);
65 static void setView(int nId);
67 static void setEditMode(int nMode, vcl::ITiledRenderable* pDoc);
69 static SfxViewShell* getViewOfId(int nId);
71 static int getView(const SfxViewShell* pViewShell = nullptr);
73 static std::size_t getViewsCount(int nDocId);
75 static bool getViewIds(int nDocId, int* pArray, size_t nSize);
77 static void setBlockedCommandList(int nViewId, const char* blockedCommandList);
79 static int getDocumentIdOfView(int nViewId);
81 static const LanguageTag & getDefaultLanguage();
83 static void setViewLanguage(int nId, const OUString& rBcp47LanguageTag);
85 static void setDefaultLanguage(const OUString& rBcp47LanguageTag);
87 static void setAccessibilityState(int nId, bool nEnabled);
89 static const LanguageTag & getLoadLanguage();
91 static void setLoadLanguage(const OUString& rBcp47LanguageTag);
93 static void setViewLocale(int nId, const OUString& rBcp47LanguageTag);
95 static LOKDeviceFormFactor getDeviceFormFactor();
97 static void setDeviceFormFactor(std::u16string_view rDeviceFormFactor);
98
102 static void setDefaultTimezone(bool isSet, const OUString& rTimezone);
104 static std::pair<bool, OUString> getDefaultTimezone();
106 static void setViewTimezone(int nId, bool isSet, const OUString& rTimezone);
108 static std::pair<bool, OUString> getViewTimezone(int nId);
109
111 template<typename ViewShellType, typename FunctionType>
112 static void forEachOtherView(ViewShellType* pThisViewShell, FunctionType f);
113
115 static void notifyOtherViews(const SfxViewShell* pThisView, int nType, std::string_view rKey,
116 const OString& rPayload);
118 static void notifyOtherViews(const SfxViewShell* pThisView, int nType,
119 const boost::property_tree::ptree& rTree);
121 static void notifyOtherView(const SfxViewShell* pThisView, SfxViewShell const* pOtherView,
122 int nType, std::string_view rKey, const OString& rPayload);
124 static void notifyOtherView(const SfxViewShell* pThisView, SfxViewShell const* pOtherView,
125 int nType, const boost::property_tree::ptree& rTree);
126
128 static void sendUnoStatus(const SfxViewShell* pShell, const SfxPoolItem* pItem);
130 static void notifyWindow(const SfxViewShell* pThisView,
131 vcl::LOKWindowId nWindowId,
132 std::u16string_view rAction,
133 const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>());
135 static void notifyDocumentSizeChanged(SfxViewShell const* pThisView, const OString& rPayload, vcl::ITiledRenderable* pDoc, bool bInvalidateAll = true);
137 static void notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable* pDoc, bool bInvalidateAll = true);
139 static void notifyPartSizeChangedAllViews(vcl::ITiledRenderable* pDoc, int nPart);
141 static void notifyInvalidation(SfxViewShell const* pThisView, tools::Rectangle const *);
143 static void notifyAllViews(int nType, const OString& rPayload);
144
146 static void notifyContextChange(const css::ui::ContextChangeEventObject& rEvent);
147
149 static void notifyViewRenderState(SfxViewShell const* pViewShell, vcl::ITiledRenderable* pDoc);
150
151 // Notify about the given type needing an update.
152 static void notifyUpdate(SfxViewShell const* pViewShell, int nType);
153 // Notify about the given type needing a per-viewid update.
154 static void notifyUpdatePerViewId(SfxViewShell const* pViewShell, int nType);
157 static void notifyUpdatePerViewId(SfxViewShell const* pTargetShell, SfxViewShell const* pViewShell,
158 SfxViewShell const* pSourceShell, int nType);
159 // Notify other views about the given type needing a per-viewid update.
160 static void notifyOtherViewsUpdatePerViewId(SfxViewShell const* pViewShell, int nType);
161
162 static OString makePayloadJSON(const SfxViewShell* pThisView, int nViewId, std::string_view rKey, const OString& rPayload);
164 static OString makeVisCursorInvalidation(int nViewId, const OString& rRectangle,
165 bool bMispelledWord = false, const OString& rHyperlink = "");
166
168 static void postKeyEventAsync(const VclPtr<vcl::Window> &xWindow,
169 int nType, int nCharCode, int nKeyCode, int nRepeat = 0);
170
172 static void postExtTextEventAsync(const VclPtr<vcl::Window> &xWindow,
173 int nType, const OUString &rText);
174
176 static void postMouseEventAsync(const VclPtr<vcl::Window> &xWindow, LokMouseEventData const & rLokMouseEventData);
177
180 static const tools::Long MaxTwips = 1e9;
181
183 static void dumpState(rtl::OStringBuffer &rState);
184
187 static bool testInPlaceComponentMouseEventHit(SfxViewShell* pViewShell, int nType, int nX,
188 int nY, int nCount, int nButtons, int nModifier,
189 double fScaleX, double fScaleY,
190 bool bNegativeX = false);
191
192 static VclPtr<vcl::Window> getInPlaceDocWindow(SfxViewShell* pViewShell);
193
194private:
195 static int createView(SfxViewFrame& rViewFrame, ViewShellDocId docId);
196};
197
198template<typename ViewShellType, typename FunctionType>
199void SfxLokHelper::forEachOtherView(ViewShellType* pThisViewShell, FunctionType f)
200{
201 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
202 while (pViewShell)
203 {
204 auto pOtherViewShell = dynamic_cast<ViewShellType*>(pViewShell);
205 if (pOtherViewShell != nullptr && pOtherViewShell != pThisViewShell && pOtherViewShell->GetDocId() == pThisViewShell->GetDocId())
206 {
207 f(pOtherViewShell);
208 }
209 pViewShell = SfxViewShell::GetNext(*pViewShell);
210 }
211}
212
213#endif
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
geometry::RealPoint2D maPosition
static void forEachOtherView(ViewShellType *pThisViewShell, FunctionType f)
Iterate over any view shell, except pThisViewShell, passing it to the f function.
Definition: lokhelper.hxx:199
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
Definition: viewsh.hxx:165
static SAL_WARN_UNUSED_RESULT SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
Definition: viewsh.cxx:2046
static SAL_WARN_UNUSED_RESULT SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
Definition: viewsh.cxx:2017
int nCount
#define SFX2_DLLPUBLIC
Definition: dllapi.h:29
std::size_t mnCount
MouseEventModifiers
COMPHELPER_DLLPUBLIC void setBlockedCommandList(const char *blockedCommandList)
css::uno::Reference< css::beans::XPropertySet > createView(const OUString &_sName, const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const css::uno::Reference< css::beans::XPropertySet > &_xSourceObject)
SwView * getView(const uno::Reference< frame::XModel > &xModel)
long Long
void dumpState(rtl::OStringBuffer &rState)
sal_uInt32 LOKWindowId
sal_Int16 nId
QPRO_FUNC_TYPE nType
sal_Int32 mnType
std::optional< Point > maLogicPosition
Definition: lokhelper.hxx:36
MouseEventModifiers meModifiers
Definition: lokhelper.hxx:33
LokMouseEventData(int nType, Point aPosition, int nCount, MouseEventModifiers eModifiers, int nButtons, int nModifier)
Definition: lokhelper.hxx:38
LOKDeviceFormFactor
Definition: viewsh.hxx:122