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/property_tree/ptree.hpp>
19 #include <boost/variant.hpp>
20 
21 #include <osl/thread.h>
22 #include <rtl/ref.hxx>
23 #include <vcl/idle.hxx>
24 #include <LibreOfficeKit/LibreOfficeKit.h>
25 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/lang/XComponent.hpp>
28 #include <tools/gen.hxx>
29 #include <sfx2/lokhelper.hxx>
30 
31 #include <desktop/dllapi.h>
32 
34 
35 namespace desktop {
36 
39  {
41  int m_nPart;
42 
44  : m_nPart(INT_MIN) // -1 is reserved to mean "all parts".
45  {
46  }
47 
48  OString toString() const
49  {
50  std::stringstream ss;
51  ss << m_aRectangle.toString();
52  if (m_nPart >= -1)
53  ss << ", " << m_nPart;
54  return ss.str().c_str();
55  }
56 
59  bool isInfinite() const
60  {
61  return m_aRectangle.GetWidth() >= SfxLokHelper::MaxTwips &&
62  m_aRectangle.GetHeight() >= SfxLokHelper::MaxTwips;
63  }
64 
66  bool isEmpty() const
67  {
68  return m_aRectangle.IsEmpty();
69  }
70 
71  static RectangleAndPart Create(const std::string& rPayload);
72  };
73 
75  {
76  public:
77  explicit CallbackFlushHandler(LibreOfficeKitDocument* pDocument, LibreOfficeKitCallback pCallback, void* pData);
78  virtual ~CallbackFlushHandler() override;
79  virtual void Invoke() override;
80  static void callback(const int type, const char* payload, void* data);
81  void queue(const int type, const char* data);
82 
85  void disableCallbacks() { ++m_nDisableCallbacks; }
88  void enableCallbacks() { --m_nDisableCallbacks; }
90  bool callbacksDisabled() const { return m_nDisableCallbacks != 0; }
91 
92  void addViewStates(int viewId);
93  void removeViewStates(int viewId);
94 
95  struct CallbackData
96  {
97  CallbackData(int type, const std::string& payload)
98  : Type(type)
99  , PayloadString(payload)
100  {
101  }
102 
104  RectangleAndPart& setRectangleAndPart(const std::string& payload);
106  void setRectangleAndPart(const RectangleAndPart& rRectAndPart);
108  const RectangleAndPart& getRectangleAndPart() const;
110  boost::property_tree::ptree& setJson(const std::string& payload);
112  void setJson(const boost::property_tree::ptree& rTree);
114  const boost::property_tree::ptree& getJson() const;
115 
117  bool validate() const;
118 
120  bool isCached() const { return PayloadObject.which() != 0; }
121 
122  int Type;
123  std::string PayloadString;
124 
125  private:
127  boost::variant<boost::blank, RectangleAndPart, boost::property_tree::ptree> PayloadObject;
128  };
129 
130  typedef std::vector<CallbackData> queue_type;
131 
132  private:
133  bool removeAll(const std::function<bool (const queue_type::value_type&)>& rTestFunc);
134  bool processInvalidateTilesEvent(CallbackData& aCallbackData);
135  bool processWindowEvent(CallbackData& aCallbackData);
136 
137  queue_type m_queue;
138  std::map<int, std::string> m_states;
139  std::unordered_map<int, std::unordered_map<int, std::string>> m_viewStates;
140  LibreOfficeKitDocument* m_pDocument;
141  LibreOfficeKitCallback m_pCallback;
142  void *m_pData;
144  std::mutex m_mutex;
145  };
146 
147  struct DESKTOP_DLLPUBLIC LibLODocument_Impl : public _LibreOfficeKitDocument
148  {
149  css::uno::Reference<css::lang::XComponent> mxComponent;
150  std::shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass;
151  std::map<size_t, std::shared_ptr<CallbackFlushHandler>> mpCallbackFlushHandlers;
152  const int mnDocumentId;
153 
154  explicit LibLODocument_Impl(const css::uno::Reference <css::lang::XComponent> &xComponent, int nDocumentId = -1);
156  };
157 
158  struct DESKTOP_DLLPUBLIC LibLibreOffice_Impl : public _LibreOfficeKit
159  {
161  std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
162  oslThread maThread;
163  LibreOfficeKitCallback mpCallback;
166  std::map<OString, rtl::Reference<LOKInteractionHandler>> mInteractionMap;
167 
170 
171  bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
172  {
173  return (mOptionalFeatures & feature) != 0;
174  }
175  };
176 
180  DESKTOP_DLLPUBLIC OUString extractParameter(OUString& aOptions, const OUString& rName);
181 
184  DESKTOP_DLLPUBLIC std::vector<com::sun::star::beans::PropertyValue> jsonToPropertyValuesVector(const char* pJSON);
185 }
186 
187 #endif
188 
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void disableCallbacks()
Disables callbacks on this handler.
Definition: init.hxx:85
Type
long GetWidth() const
std::map< OString, rtl::Reference< LOKInteractionHandler > > mInteractionMap
Definition: init.hxx:166
long GetHeight() const
std::unique_ptr< ContentProperties > pData
std::vector< CallbackData > queue_type
Definition: init.hxx:130
#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:127
tools::Rectangle m_aRectangle
Definition: init.hxx:40
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:59
OString toString() const
Definition: init.hxx:48
Definition: app.cxx:161
bool callbacksDisabled() const
Returns true iff callbacks are disabled.
Definition: init.hxx:90
std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass
Definition: init.hxx:161
bool IsEmpty() const
std::unordered_map< int, std::unordered_map< int, std::string > > m_viewStates
Definition: init.hxx:139
css::uno::Reference< css::lang::XComponent > mxComponent
Definition: init.hxx:149
std::map< size_t, std::shared_ptr< CallbackFlushHandler > > mpCallbackFlushHandlers
Definition: init.hxx:151
LibreOfficeKitCallback mpCallback
Definition: init.hxx:163
void enableCallbacks()
Enables callbacks on this handler.
Definition: init.hxx:88
exports com.sun.star.chart2. data
static const long MaxTwips
LibreOfficeKitDocument * m_pDocument
Definition: init.hxx:140
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:971
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:66
bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
Definition: init.hxx:171
std::shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass
Definition: init.hxx:150
Represents an invalidated rectangle inside a given document part.
Definition: init.hxx:38
CallbackData(int type, const std::string &payload)
Definition: init.hxx:97
bool isCached() const
Returns true iff there is cached data.
Definition: init.hxx:120
LibreOfficeKitCallback m_pCallback
Definition: init.hxx:141
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:138