2015-09-09 15:08:26 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
2015-09-24 07:39:16 +02:00
|
|
|
|
|
|
|
#ifndef INCLUDED_DESKTOP_INC_LIB_INIT_HXX
|
|
|
|
#define INCLUDED_DESKTOP_INC_LIB_INIT_HXX
|
|
|
|
|
2016-04-19 21:26:42 -04:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
#include <osl/thread.h>
|
|
|
|
#include <vcl/idle.hxx>
|
2015-09-09 15:08:26 +03:00
|
|
|
#include <LibreOfficeKit/LibreOfficeKit.h>
|
2016-01-26 15:35:42 +01:00
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
2015-09-09 15:08:26 +03:00
|
|
|
#include <com/sun/star/frame/XStorable.hpp>
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
2016-04-19 21:26:42 -04:00
|
|
|
|
2015-11-25 16:50:22 +01:00
|
|
|
#include <desktop/dllapi.h>
|
2015-09-09 15:08:26 +03:00
|
|
|
|
2016-01-25 12:29:16 +01:00
|
|
|
class LOKInteractionHandler;
|
|
|
|
|
2015-09-09 15:08:26 +03:00
|
|
|
namespace desktop {
|
2016-04-19 21:26:42 -04:00
|
|
|
|
|
|
|
class CallbackFlushHandler : public Idle
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CallbackFlushHandler(LibreOfficeKitCallback pCallback, void* pData)
|
|
|
|
: Idle( "lokit timer callback" ),
|
|
|
|
m_pCallback(pCallback),
|
|
|
|
m_pData(pData)
|
|
|
|
{
|
|
|
|
SetPriority(SchedulerPriority::POST_PAINT);
|
|
|
|
|
|
|
|
// Add the states that are safe to skip duplicates on,
|
|
|
|
// even when not consequent.
|
2016-04-23 14:06:22 -04:00
|
|
|
m_states.emplace(LOK_CALLBACK_TEXT_SELECTION_START, "NIL");
|
|
|
|
m_states.emplace(LOK_CALLBACK_TEXT_SELECTION_END, "NIL");
|
2016-04-19 21:26:42 -04:00
|
|
|
m_states.emplace(LOK_CALLBACK_TEXT_SELECTION, "NIL");
|
|
|
|
m_states.emplace(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, "NIL");
|
|
|
|
m_states.emplace(LOK_CALLBACK_STATE_CHANGED, "NIL");
|
2016-04-23 10:23:48 -04:00
|
|
|
m_states.emplace(LOK_CALLBACK_MOUSE_POINTER, "NIL");
|
2016-04-19 21:26:42 -04:00
|
|
|
|
|
|
|
Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CallbackFlushHandler()
|
|
|
|
{
|
|
|
|
Stop();
|
|
|
|
|
|
|
|
// We might have important notification (.uno:save?).
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Invoke() override
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void callback(const int type, const char* payload, void* data)
|
|
|
|
{
|
2016-05-08 09:07:10 +03:00
|
|
|
CallbackFlushHandler* self = static_cast<CallbackFlushHandler*>(data);
|
2016-04-19 21:26:42 -04:00
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
self->queue(type, payload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void queue(const int type, const char* data)
|
|
|
|
{
|
|
|
|
const std::string payload(data ? data : "(nil)");
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
|
|
|
const auto stateIt = m_states.find(type);
|
|
|
|
if (stateIt != m_states.end())
|
|
|
|
{
|
|
|
|
// If the state didn't change, it's safe to ignore.
|
|
|
|
if (stateIt->second == payload)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stateIt->second = payload;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == LOK_CALLBACK_INVALIDATE_TILES &&
|
|
|
|
!m_queue.empty() && std::get<0>(m_queue.back()) == type && std::get<1>(m_queue.back()) == payload)
|
|
|
|
{
|
|
|
|
// Supress duplicate invalidation only when they are in sequence.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-23 14:06:22 -04:00
|
|
|
if (type == LOK_CALLBACK_TEXT_SELECTION && payload.empty())
|
|
|
|
{
|
|
|
|
// Removing text selection invalidates the start and end as well.
|
|
|
|
m_states[LOK_CALLBACK_TEXT_SELECTION_START] = "";
|
|
|
|
m_states[LOK_CALLBACK_TEXT_SELECTION_END] = "";
|
|
|
|
}
|
|
|
|
|
2016-04-19 21:26:42 -04:00
|
|
|
m_queue.emplace_back(type, payload);
|
|
|
|
|
|
|
|
lock.unlock();
|
|
|
|
if (!IsActive())
|
|
|
|
{
|
|
|
|
Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void flush()
|
|
|
|
{
|
|
|
|
if (m_pCallback)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
for (auto& pair : m_queue)
|
|
|
|
{
|
|
|
|
m_pCallback(std::get<0>(pair), std::get<1>(pair).c_str(), m_pData);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_queue.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<std::tuple<int, std::string>> m_queue;
|
|
|
|
std::map<int, std::string> m_states;
|
|
|
|
LibreOfficeKitCallback m_pCallback;
|
|
|
|
void *m_pData;
|
|
|
|
std::mutex m_mutex;
|
|
|
|
};
|
|
|
|
|
2015-09-09 15:08:26 +03:00
|
|
|
struct DESKTOP_DLLPUBLIC LibLODocument_Impl : public _LibreOfficeKitDocument
|
|
|
|
{
|
2015-09-23 07:48:10 +02:00
|
|
|
css::uno::Reference<css::lang::XComponent> mxComponent;
|
2015-09-17 09:21:43 +01:00
|
|
|
std::shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass;
|
2016-04-19 21:26:42 -04:00
|
|
|
std::shared_ptr<CallbackFlushHandler> mpCallbackFlushHandler;
|
2015-09-09 15:08:26 +03:00
|
|
|
|
2015-09-23 07:48:10 +02:00
|
|
|
explicit LibLODocument_Impl(const css::uno::Reference <css::lang::XComponent> &xComponent);
|
2015-09-09 15:08:26 +03:00
|
|
|
~LibLODocument_Impl();
|
|
|
|
};
|
2015-09-25 01:06:31 +02:00
|
|
|
|
|
|
|
struct DESKTOP_DLLPUBLIC LibLibreOffice_Impl : public _LibreOfficeKit
|
|
|
|
{
|
|
|
|
OUString maLastExceptionMsg;
|
|
|
|
std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
|
|
|
|
oslThread maThread;
|
|
|
|
LibreOfficeKitCallback mpCallback;
|
|
|
|
void *mpCallbackData;
|
2016-01-26 15:35:42 +01:00
|
|
|
int64_t mOptionalFeatures;
|
2016-01-25 12:29:16 +01:00
|
|
|
std::map<OString, rtl::Reference<LOKInteractionHandler>> mInteractionMap;
|
2015-09-25 01:06:31 +02:00
|
|
|
|
|
|
|
LibLibreOffice_Impl();
|
2016-01-25 12:29:16 +01:00
|
|
|
~LibLibreOffice_Impl();
|
2016-01-26 15:35:42 +01:00
|
|
|
|
|
|
|
bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
|
|
|
|
{
|
|
|
|
return (mOptionalFeatures & feature) != 0;
|
|
|
|
}
|
2015-09-25 01:06:31 +02:00
|
|
|
};
|
2015-09-09 15:08:26 +03:00
|
|
|
}
|
2015-09-23 07:48:10 +02:00
|
|
|
|
2015-09-24 07:39:16 +02:00
|
|
|
#endif
|
|
|
|
|
2015-09-23 07:48:10 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|