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 
83  void setEventLatch(const bool bEventLatch)
84  {
85  m_bEventLatch = bEventLatch;
86  }
87 
88  bool isEventLatchOn() const { return m_bEventLatch; }
89  void setPartTilePainting(const bool bPartPainting) { m_bPartTilePainting = bPartPainting; }
90  bool isPartTilePainting() const { return m_bPartTilePainting; }
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;
145  std::mutex m_mutex;
146  };
147 
148  struct DESKTOP_DLLPUBLIC LibLODocument_Impl : public _LibreOfficeKitDocument
149  {
150  css::uno::Reference<css::lang::XComponent> mxComponent;
151  std::shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass;
152  std::map<size_t, std::shared_ptr<CallbackFlushHandler>> mpCallbackFlushHandlers;
153 
154  explicit LibLODocument_Impl(const css::uno::Reference <css::lang::XComponent> &xComponent);
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: */
Type
long GetWidth() const
std::map< OString, rtl::Reference< LOKInteractionHandler > > mInteractionMap
Definition: init.hxx:166
void setEventLatch(const bool bEventLatch)
When enabled events are queued but callback not invoked.
Definition: init.hxx:83
long GetHeight() const
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: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:166
std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass
Definition: init.hxx:161
bool IsEmpty() const
void setPartTilePainting(const bool bPartPainting)
Definition: init.hxx:89
std::unordered_map< int, std::unordered_map< int, std::string > > m_viewStates
Definition: init.hxx:139
bool isEventLatchOn() const
Definition: init.hxx:88
css::uno::Reference< css::lang::XComponent > mxComponent
Definition: init.hxx:150
std::map< size_t, std::shared_ptr< CallbackFlushHandler > > mpCallbackFlushHandlers
Definition: init.hxx:152
LibreOfficeKitCallback mpCallback
Definition: init.hxx:163
bool isPartTilePainting() const
Definition: init.hxx:90
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:709
static RectangleAndPart Create(const std::string &rPayload)
Definition: init.cxx:483
bool isEmpty() const
Empty Rectangle is when it has zero dimensions.
Definition: init.hxx:65
bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
Definition: init.hxx:171
std::shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass
Definition: init.hxx:151
Represents an invalidated rectangle inside a given document part.
Definition: init.hxx:37
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
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:361
std::map< int, std::string > m_states
Definition: init.hxx:138