Kaydet (Commit) 4bddfc00 authored tarafından Miklos Vajna's avatar Miklos Vajna

lok::Document::initializeForRendering: support init. arguments

Change-Id: I8aaf19a50f25f495cb87fba7ff6a4b0f56ed7d80
üst 0a779d1d
......@@ -283,7 +283,7 @@ void DesktopLOKTest::testSearchCalc()
LibLibreOffice_Impl aOffice;
comphelper::LibreOfficeKit::setActive();
LibLODocument_Impl* pDocument = loadDoc("search.ods");
pDocument->pClass->initializeForRendering(pDocument);
pDocument->pClass->initializeForRendering(pDocument, nullptr);
pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
......@@ -406,7 +406,7 @@ void DesktopLOKTest::testRowColumnHeaders()
*/
LibLODocument_Impl* pDocument = loadDoc("search.ods");
pDocument->pClass->initializeForRendering(pDocument);
pDocument->pClass->initializeForRendering(pDocument, nullptr);
boost::property_tree::ptree aTree;
char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:ViewRowColumnHeaders");
......
......@@ -261,6 +261,40 @@ static OUString getAbsoluteURL(const char* pURL)
return OUString();
}
static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::PropertyValue>& rPropertyValues)
{
std::vector<beans::PropertyValue> aArguments;
if (pJSON)
{
boost::property_tree::ptree aTree;
std::stringstream aStream(pJSON);
boost::property_tree::read_json(aStream, aTree);
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree)
{
const std::string& rType = rPair.second.get<std::string>("type");
const std::string& rValue = rPair.second.get<std::string>("value");
beans::PropertyValue aValue;
aValue.Name = OUString::fromUtf8(rPair.first.c_str());
if (rType == "string")
aValue.Value <<= OUString::fromUtf8(rValue.c_str());
else if (rType == "boolean")
aValue.Value <<= OString(rValue.c_str()).toBoolean();
else if (rType == "float")
aValue.Value <<= OString(rValue.c_str()).toFloat();
else if (rType == "long")
aValue.Value <<= OString(rValue.c_str()).toInt32();
else if (rType == "unsigned short")
aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32());
else
SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'");
aArguments.push_back(aValue);
}
}
rPropertyValues = comphelper::containerToSequence(aArguments);
}
extern "C"
{
......@@ -281,7 +315,8 @@ void doc_paintTile(LibreOfficeKitDocument* pThis,
static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
long* pWidth,
long* pHeight);
static void doc_initializeForRendering(LibreOfficeKitDocument* pThis);
static void doc_initializeForRendering(LibreOfficeKitDocument* pThis,
const char* pArguments);
static void doc_registerCallback(LibreOfficeKitDocument* pThis,
LibreOfficeKitCallback pCallback,
......@@ -939,12 +974,15 @@ static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
}
}
static void doc_initializeForRendering(LibreOfficeKitDocument* pThis)
static void doc_initializeForRendering(LibreOfficeKitDocument* pThis,
const char* pArguments)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (pDoc)
{
doc_iniUnoCommands();
uno::Sequence<beans::PropertyValue> aPropertyValues;
jsonToPropertyValues(pArguments, aPropertyValues);
pDoc->initializeForTiledRendering();
}
}
......@@ -988,40 +1026,6 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar
pDoc->postKeyEvent(nType, nCharCode, nKeyCode);
}
static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::PropertyValue>& rPropertyValues)
{
std::vector<beans::PropertyValue> aArguments;
if (pJSON)
{
boost::property_tree::ptree aTree;
std::stringstream aStream(pJSON);
boost::property_tree::read_json(aStream, aTree);
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree)
{
const std::string& rType = rPair.second.get<std::string>("type");
const std::string& rValue = rPair.second.get<std::string>("value");
beans::PropertyValue aValue;
aValue.Name = OUString::fromUtf8(rPair.first.c_str());
if (rType == "string")
aValue.Value <<= OUString::fromUtf8(rValue.c_str());
else if (rType == "boolean")
aValue.Value <<= OString(rValue.c_str()).toBoolean();
else if (rType == "float")
aValue.Value <<= OString(rValue.c_str()).toFloat();
else if (rType == "long")
aValue.Value <<= OString(rValue.c_str()).toInt32();
else if (rType == "unsigned short")
aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32());
else
SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'");
aArguments.push_back(aValue);
}
}
rPropertyValues = comphelper::containerToSequence(aArguments);
}
/** Class to react on finishing of a dispatched command.
This will call a LOK_COMMAND_FINISHED callback when postUnoCommand was
......
......@@ -256,7 +256,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_initial
(JNIEnv* pEnv, jobject aObject)
{
LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
pDocument->pClass->initializeForRendering(pDocument);
pDocument->pClass->initializeForRendering(pDocument, NULL);
}
extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs
......
......@@ -124,7 +124,8 @@ struct _LibreOfficeKitDocumentClass
long* pHeight);
/// @see lok::Document::initializeForRendering().
void (*initializeForRendering) (LibreOfficeKitDocument* pThis);
void (*initializeForRendering) (LibreOfficeKitDocument* pThis,
const char* pArguments);
/// @see lok::Document::registerCallback().
void (*registerCallback) (LibreOfficeKitDocument* pThis,
......
......@@ -156,10 +156,22 @@ public:
* needed to render the document correctly using tiled rendering. This
* method has to be called right after documentLoad() in case any of the
* tiled rendering methods are to be used later.
*
* Example argument string for text documents:
*
* {
* ".uno:HideWhitespace":
* {
* "type": "boolean",
* "value": "true"
* }
* }
*
* @param pArguments arguments of the rendering
*/
inline void initializeForRendering()
inline void initializeForRendering(const char* pArguments = NULL)
{
mpDoc->pClass->initializeForRendering(mpDoc);
mpDoc->pClass->initializeForRendering(mpDoc, pArguments);
}
/**
......
......@@ -530,7 +530,7 @@ static gboolean postDocumentLoad(gpointer pData)
LOKDocViewPrivate& priv = getPrivate(pLOKDocView);
priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument);
priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument, nullptr);
priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pLOKDocView);
priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips);
g_timeout_add(600, handleTimeout, pLOKDocView);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment