LibreOffice Module desktop (master)  1
init.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_DESKTOP_INC_LIB_INIT_HXX
11 #define INCLUDED_DESKTOP_INC_LIB_INIT_HXX
12 
13 #include <map>
14 #include <unordered_map>
15 #include <memory>
16 #include <mutex>
17 
18 #include <boost/variant.hpp>
19 
20 #include <osl/thread.h>
21 #include <rtl/ref.hxx>
22 #include <vcl/idle.hxx>
23 #include <LibreOfficeKit/LibreOfficeKit.h>
24 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/lang/XComponent.hpp>
27 #include <tools/gen.hxx>
28 #include <sfx2/lokhelper.hxx>
29 
30 #include <desktop/dllapi.h>
31 
33 
34 namespace desktop {
35 
38  {
40  int m_nPart;
41 
43  : m_nPart(INT_MIN) // -1 is reserved to mean "all parts".
44  {
45  }
46 
47  OString toString() const
48  {
49  std::stringstream ss;
50  ss << m_aRectangle.toString();
51  if (m_nPart >= -1)
52  ss << ", " << m_nPart;
53  return ss.str().c_str();
54  }
55 
58  bool isInfinite() const
59  {
60  return m_aRectangle.GetWidth() >= SfxLokHelper::MaxTwips &&
61  m_aRectangle.GetHeight() >= SfxLokHelper::MaxTwips;
62  }
63 
65  bool isEmpty() const
66  {
67  return m_aRectangle.IsEmpty();
68  }
69 
70  static RectangleAndPart Create(const std::string& rPayload);
71  };
72 
74  {
75  public:
76  explicit CallbackFlushHandler(LibreOfficeKitDocument* pDocument, LibreOfficeKitCallback pCallback, void* pData);
77  virtual ~CallbackFlushHandler() override;
78  virtual void Invoke() override;
79  static void callback(const int type, const char* payload, void* data);
80  void queue(const int type, const char* data);
81 
84  void disableCallbacks() { ++m_nDisableCallbacks; }
87  void enableCallbacks() { --m_nDisableCallbacks; }
89  bool callbacksDisabled() const { return m_nDisableCallbacks != 0; }
90 
91  void addViewStates(int viewId);
92  void removeViewStates(int viewId);
93 
94  struct CallbackData
95  {
96  CallbackData(int type, const std::string& payload)
97  : Type(type)
98  , PayloadString(payload)
99  {
100  }
101 
103  RectangleAndPart& setRectangleAndPart(const std::string& payload);
105  void setRectangleAndPart(const RectangleAndPart& rRectAndPart);
107  const RectangleAndPart& getRectangleAndPart() const;
109  boost::property_tree::ptree& setJson(const std::string& payload);
111  void setJson(const boost::property_tree::ptree& rTree);
113  const boost::property_tree::ptree& getJson() const;
114 
116  bool validate() const;
117 
119  bool isCached() const { return PayloadObject.which() != 0; }
120 
121  int Type;
122  std::string PayloadString;
123 
124  private:
126  boost::variant<boost::blank, RectangleAndPart, boost::property_tree::ptree> PayloadObject;
127  };
128 
129  typedef std::vector<CallbackData> queue_type;
130 
131  private:
132  bool removeAll(const std::function<bool (const queue_type::value_type&)>& rTestFunc);
133  bool processInvalidateTilesEvent(CallbackData& aCallbackData);
134  bool processWindowEvent(CallbackData& aCallbackData);
135 
136  queue_type m_queue;
137  std::map<int, std::string> m_states;
138  std::unordered_map<int, std::unordered_map<int, std::string>> m_viewStates;
139  LibreOfficeKitDocument* m_pDocument;
140  LibreOfficeKitCallback m_pCallback;
141  void *m_pData;
143  std::mutex m_mutex;
144  };
145 
146  struct DESKTOP_DLLPUBLIC LibLODocument_Impl : public _LibreOfficeKitDocument
147  {
148  css::uno::Reference<css::lang::XComponent> mxComponent;
149  std::shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass;
150  std::map<size_t, std::shared_ptr<CallbackFlushHandler>> mpCallbackFlushHandlers;
151 
152  explicit LibLODocument_Impl(const css::uno::Reference <css::lang::XComponent> &xComponent);
154  };
155 
156  struct DESKTOP_DLLPUBLIC LibLibreOffice_Impl : public _LibreOfficeKit
157  {
159  std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
160  oslThread maThread;
161  LibreOfficeKitCallback mpCallback;
164  std::map<OString, rtl::Reference<LOKInteractionHandler>> mInteractionMap;
165 
168 
169  bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
170  {
171  return (mOptionalFeatures & feature) != 0;
172  }
173  };
174 
178  DESKTOP_DLLPUBLIC OUString extractParameter(OUString& aOptions, const OUString& rName);
179 
182  DESKTOP_DLLPUBLIC std::vector<com::sun::star::beans::PropertyValue> jsonToPropertyValuesVector(const char* pJSON);
183 }
184 
185 #endif
186 
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void disableCallbacks()
Disables callbacks on this handler.
Definition: init.hxx:84
Type
long GetWidth() const
std::map< OString, rtl::Reference< LOKInteractionHandler > > mInteractionMap
Definition: init.hxx:164
long GetHeight() const
std::unique_ptr< ContentProperties > pData
std::vector< CallbackData > queue_type
Definition: init.hxx:129
#define DESKTOP_DLLPUBLIC
Definition: dllapi.h:19
boost::variant< boost::blank, RectangleAndPart, boost::property_tree::ptree > PayloadObject
The parsed payload cache. Update validate() when changing this.
Definition: init.hxx:126
tools::Rectangle m_aRectangle
Definition: init.hxx:39
InteractionHandler is an interface that provides the user with various dialogs / error messages...
bool isInfinite() const
Infinite Rectangle is both sides are equal or longer than SfxLokHelper::MaxTwips. ...
Definition: init.hxx:58
OString toString() const
Definition: init.hxx:47
Definition: app.cxx:168
bool callbacksDisabled() const
Returns true iff callbacks are disabled.
Definition: init.hxx:89
std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass
Definition: init.hxx:159
bool IsEmpty() const
std::unordered_map< int, std::unordered_map< int, std::string > > m_viewStates
Definition: init.hxx:138
css::uno::Reference< css::lang::XComponent > mxComponent
Definition: init.hxx:148
std::map< size_t, std::shared_ptr< CallbackFlushHandler > > mpCallbackFlushHandlers
Definition: init.hxx:150
LibreOfficeKitCallback mpCallback
Definition: init.hxx:161
void enableCallbacks()
Enables callbacks on this handler.
Definition: init.hxx:87
static const long MaxTwips
LibreOfficeKitDocument * m_pDocument
Definition: init.hxx:139
DESKTOP_DLLPUBLIC OUString extractParameter(OUString &aOptions, const OUString &rName)
Helper function to extract the value from parameters delimited by comma, like: Name1=Value1,Name2=Value2,Name3=Value3.
Definition: init.cxx:920
static RectangleAndPart Create(const std::string &rPayload)
Definition: init.cxx:499
bool isEmpty() const
Empty Rectangle is when it has zero dimensions.
Definition: init.hxx:65
bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
Definition: init.hxx:169
std::shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass
Definition: init.hxx:149
Represents an invalidated rectangle inside a given document part.
Definition: init.hxx:37
CallbackData(int type, const std::string &payload)
Definition: init.hxx:96
bool isCached() const
Returns true iff there is cached data.
Definition: init.hxx:119
LibreOfficeKitCallback m_pCallback
Definition: init.hxx:140
ResultType type
rtl::OString toString() const
DESKTOP_DLLPUBLIC std::vector< com::sun::star::beans::PropertyValue > jsonToPropertyValuesVector(const char *pJSON)
Helper function to convert JSON to a vector of PropertyValues.
Definition: init.cxx:377
std::map< int, std::string > m_states
Definition: init.hxx:137