2015-04-13 04:09:02 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
2015-03-28 06:22:15 -05:00
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_LOKITHELPER_HPP
|
|
|
|
#define INCLUDED_LOKITHELPER_HPP
|
|
|
|
|
2016-05-07 22:27:15 -05:00
|
|
|
#include <sstream>
|
2016-10-29 20:15:00 -05:00
|
|
|
#include <string>
|
2015-03-28 06:22:15 -05:00
|
|
|
|
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
|
|
|
|
|
|
|
namespace LOKitHelper
|
|
|
|
{
|
2016-10-29 20:15:00 -05:00
|
|
|
inline std::string documentTypeToString(LibreOfficeKitDocumentType type)
|
2015-03-28 06:22:15 -05:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case LOK_DOCTYPE_TEXT:
|
|
|
|
return "text";
|
|
|
|
case LOK_DOCTYPE_SPREADSHEET:
|
|
|
|
return "spreadsheet";
|
|
|
|
case LOK_DOCTYPE_PRESENTATION:
|
|
|
|
return "presentation";
|
|
|
|
case LOK_DOCTYPE_DRAWING:
|
|
|
|
return "drawing";
|
|
|
|
default:
|
|
|
|
return "other-" + std::to_string(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
inline std::string getDocumentTypeAsString(LibreOfficeKitDocument *loKitDocument)
|
2016-05-10 07:52:11 -05:00
|
|
|
{
|
|
|
|
assert(loKitDocument && "null loKitDocument");
|
|
|
|
const auto type = static_cast<LibreOfficeKitDocumentType>(loKitDocument->pClass->getDocumentType(loKitDocument));
|
|
|
|
return documentTypeToString(type);
|
|
|
|
}
|
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
inline std::string kitCallbackTypeToString(const int type)
|
2016-03-04 03:49:46 -06:00
|
|
|
{
|
|
|
|
// Keep in the same order as in LibreOfficeKitEnums.h
|
2017-01-13 06:52:08 -06:00
|
|
|
switch (type)
|
2016-03-04 03:49:46 -06:00
|
|
|
{
|
|
|
|
case LOK_CALLBACK_INVALIDATE_TILES:
|
|
|
|
return "INVALIDATE_TILES";
|
|
|
|
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
|
|
|
|
return "INVALIDATE_VISIBLE_CURSOR";
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION:
|
|
|
|
return "TEXT_SELECTION";
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_START:
|
|
|
|
return "TEXT_SELECTION_START";
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_END:
|
|
|
|
return "TEXT_SELECTION_END";
|
|
|
|
case LOK_CALLBACK_CURSOR_VISIBLE:
|
|
|
|
return "CURSOR_VISIBLE";
|
|
|
|
case LOK_CALLBACK_GRAPHIC_SELECTION:
|
|
|
|
return "GRAPHIC_SELECTION";
|
|
|
|
case LOK_CALLBACK_HYPERLINK_CLICKED:
|
|
|
|
return "HYPERLINK_CLICKED";
|
|
|
|
case LOK_CALLBACK_STATE_CHANGED:
|
|
|
|
return "STATE_CHANGED";
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_START:
|
|
|
|
return "STATUS_INDICATOR_START";
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
|
|
|
|
return "STATUS_INDICATOR_SET_VALUE";
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_FINISH:
|
|
|
|
return "STATUS_INDICATOR_FINISH";
|
|
|
|
case LOK_CALLBACK_SEARCH_NOT_FOUND:
|
|
|
|
return "SEARCH_NOT_FOUND";
|
|
|
|
case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
|
|
|
|
return "DOCUMENT_SIZE_CHANGED";
|
|
|
|
case LOK_CALLBACK_SET_PART:
|
|
|
|
return "SET_PART";
|
|
|
|
case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
|
|
|
|
return "SEARCH_RESULT_SELECTION";
|
|
|
|
case LOK_CALLBACK_UNO_COMMAND_RESULT:
|
|
|
|
return "UNO_COMMAND_RESULT";
|
|
|
|
case LOK_CALLBACK_CELL_CURSOR:
|
|
|
|
return "CELL_CURSOR";
|
|
|
|
case LOK_CALLBACK_MOUSE_POINTER:
|
|
|
|
return "MOUSE_POINTER";
|
|
|
|
case LOK_CALLBACK_CELL_FORMULA:
|
|
|
|
return "CELL_FORMULA";
|
|
|
|
case LOK_CALLBACK_DOCUMENT_PASSWORD:
|
|
|
|
return "DOCUMENT_PASSWORD";
|
|
|
|
case LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY:
|
|
|
|
return "DOCUMENT_PASSWORD_TO_MODIFY";
|
2016-04-08 12:13:19 -05:00
|
|
|
case LOK_CALLBACK_ERROR:
|
|
|
|
return "ERROR";
|
|
|
|
case LOK_CALLBACK_CONTEXT_MENU:
|
|
|
|
return "CONTEXT_MENU";
|
2016-08-03 08:37:34 -05:00
|
|
|
case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
|
|
|
|
return "INVALIDATE_VIEW_CURSOR";
|
|
|
|
case LOK_CALLBACK_TEXT_VIEW_SELECTION:
|
|
|
|
return "TEXT_VIEW_SELECTION";
|
|
|
|
case LOK_CALLBACK_CELL_VIEW_CURSOR:
|
|
|
|
return "CELL_VIEW_CURSOR";
|
|
|
|
case LOK_CALLBACK_GRAPHIC_VIEW_SELECTION:
|
|
|
|
return "GRAPHIC_VIEW_SELECTION";
|
2016-08-03 09:20:02 -05:00
|
|
|
case LOK_CALLBACK_VIEW_CURSOR_VISIBLE:
|
|
|
|
return "VIEW_CURSOR_VISIBLE";
|
2016-08-03 08:37:34 -05:00
|
|
|
case LOK_CALLBACK_VIEW_LOCK:
|
|
|
|
return "VIEW_LOCK";
|
2017-01-23 11:01:57 -06:00
|
|
|
case LOK_CALLBACK_COMMENT:
|
|
|
|
return "COMMENT";
|
2017-04-19 16:09:19 -05:00
|
|
|
case LOK_CALLBACK_INVALIDATE_HEADER:
|
|
|
|
return "INVALIDATE_HEADER";
|
2017-05-07 17:38:13 -05:00
|
|
|
case LOK_CALLBACK_CELL_ADDRESS:
|
|
|
|
return "CELL_ADDRESS";
|
|
|
|
|
2017-04-19 16:09:19 -05:00
|
|
|
}
|
2016-03-04 03:49:46 -06:00
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
return std::to_string(type);
|
2016-03-04 03:49:46 -06:00
|
|
|
}
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
inline std::string documentStatus(LibreOfficeKitDocument *loKitDocument)
|
2015-03-28 06:22:15 -05:00
|
|
|
{
|
2016-10-29 20:15:00 -05:00
|
|
|
char *ptrValue;
|
2016-05-10 07:52:11 -05:00
|
|
|
assert(loKitDocument && "null loKitDocument");
|
2016-05-07 22:27:15 -05:00
|
|
|
const auto type = static_cast<LibreOfficeKitDocumentType>(loKitDocument->pClass->getDocumentType(loKitDocument));
|
|
|
|
|
|
|
|
const auto parts = loKitDocument->pClass->getParts(loKitDocument);
|
|
|
|
std::ostringstream oss;
|
2016-05-08 08:04:25 -05:00
|
|
|
oss << "type=" << documentTypeToString(type)
|
2016-05-07 22:27:15 -05:00
|
|
|
<< " parts=" << parts
|
|
|
|
<< " current=" << loKitDocument->pClass->getPart(loKitDocument);
|
|
|
|
|
|
|
|
long width, height;
|
2015-03-28 06:22:15 -05:00
|
|
|
loKitDocument->pClass->getDocumentSize(loKitDocument, &width, &height);
|
2016-05-07 22:27:15 -05:00
|
|
|
oss << " width=" << width
|
2016-07-26 07:03:46 -05:00
|
|
|
<< " height=" << height
|
|
|
|
<< " viewid=" << loKitDocument->pClass->getView(loKitDocument);
|
2016-05-07 22:27:15 -05:00
|
|
|
|
|
|
|
if (type == LOK_DOCTYPE_SPREADSHEET || type == LOK_DOCTYPE_PRESENTATION)
|
2015-11-24 02:41:59 -06:00
|
|
|
{
|
2016-05-07 22:27:15 -05:00
|
|
|
for (auto i = 0; i < parts; ++i)
|
2015-11-24 02:41:59 -06:00
|
|
|
{
|
2016-05-07 22:27:15 -05:00
|
|
|
oss << "\n";
|
2016-05-30 19:17:08 -05:00
|
|
|
ptrValue = loKitDocument->pClass->getPartName(loKitDocument, i);
|
|
|
|
oss << ptrValue;
|
|
|
|
std::free(ptrValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == LOK_DOCTYPE_PRESENTATION)
|
|
|
|
{
|
|
|
|
for (auto i = 0; i < parts; ++i)
|
2016-05-07 22:27:15 -05:00
|
|
|
{
|
2016-05-30 19:17:08 -05:00
|
|
|
oss << "\n";
|
2016-05-24 23:32:00 -05:00
|
|
|
ptrValue = loKitDocument->pClass->getPartHash(loKitDocument, i);
|
|
|
|
oss << ptrValue;
|
|
|
|
std::free(ptrValue);
|
2016-05-07 22:27:15 -05:00
|
|
|
}
|
2015-07-15 10:31:52 -05:00
|
|
|
}
|
|
|
|
}
|
2016-05-07 22:27:15 -05:00
|
|
|
|
|
|
|
return oss.str();
|
2015-03-28 06:22:15 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|