summaryrefslogtreecommitdiffstats
path: root/desktop/source/lib/init.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/source/lib/init.cxx')
-rw-r--r--desktop/source/lib/init.cxx3296
1 files changed, 2387 insertions, 909 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 3370779df25d..c3afbf741a37 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -7,11 +7,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <sfx2/lokhelper.hxx>
+#include <sal/types.h>
+#include <svx/sdr/contact/viewcontact.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/svdpagv.hxx>
+#include <config_buildconfig.h>
+#include <config_cairo_rgba.h>
#include <config_features.h>
+#include <editeng/unolingu.hxx>
#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
#ifdef IOS
#include <sys/mman.h>
@@ -24,10 +30,26 @@
#include <postmac.h>
#endif
+#undef HAVE_MALLOC_TRIM
+
+#ifdef UNX
+# include <fcntl.h>
+#endif
+#ifdef LINUX
+#if defined __GLIBC__
+# include <malloc.h>
+# define HAVE_MALLOC_TRIM
+#endif
+#endif
+
#ifdef ANDROID
#include <osl/detail/android-bootstrap.h>
#endif
+#ifdef EMSCRIPTEN
+#include <osl/detail/emscripten-bootstrap.h>
+#endif
+
#include <algorithm>
#include <memory>
#include <iostream>
@@ -40,16 +62,19 @@
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <sal/log.hxx>
+#include <utility>
#include <vcl/errinf.hxx>
#include <vcl/lok.hxx>
#include <o3tl/any.hxx>
#include <o3tl/unit_conversion.hxx>
+#include <o3tl/string_view.hxx>
#include <osl/file.hxx>
#include <osl/process.h>
#include <osl/thread.h>
#include <rtl/bootstrap.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/uri.hxx>
+#include <linguistic/misc.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <comphelper/base64.hxx>
#include <comphelper/dispatchcommand.hxx>
@@ -61,8 +86,10 @@
#include <comphelper/propertyvalue.hxx>
#include <comphelper/scopeguard.hxx>
#include <comphelper/threadpool.hxx>
+#include <comphelper/types.hxx>
#include <comphelper/sequenceashashmap.hxx>
+#include <com/sun/star/connection/XConnection.hpp>
#include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
@@ -84,6 +111,10 @@
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/document/XRedlinesSupplier.hpp>
#include <com/sun/star/ui/GlobalAcceleratorConfiguration.hpp>
+#include <com/sun/star/bridge/BridgeFactory.hpp>
+#include <com/sun/star/bridge/XBridgeFactory.hpp>
+#include <com/sun/star/bridge/XBridge.hpp>
+#include <com/sun/star/uno/XNamingService.hpp>
#include <com/sun/star/xml/crypto/SEInitializer.hpp>
#include <com/sun/star/xml/crypto/XSEInitializer.hpp>
@@ -91,11 +122,15 @@
#include <com/sun/star/xml/crypto/XCertificateCreator.hpp>
#include <com/sun/star/security/XCertificate.hpp>
+#include <com/sun/star/linguistic2/DictionaryList.hpp>
#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
#include <com/sun/star/linguistic2/XSpellChecker.hpp>
+#include <com/sun/star/linguistic2/XProofreader.hpp>
#include <com/sun/star/i18n/LocaleCalendar2.hpp>
#include <com/sun/star/i18n/ScriptType.hpp>
+#include <com/sun/star/i18n/BreakIterator.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <editeng/flstitem.hxx>
#ifdef IOS
@@ -108,10 +143,9 @@
#include <sfx2/viewfrm.hxx>
#include <sfx2/msgpool.hxx>
#include <sfx2/dispatch.hxx>
-#include <sfx2/lokcharthelper.hxx>
+#include <sfx2/lokcomponenthelpers.hxx>
#include <sfx2/DocumentSigner.hxx>
-#include <sfx2/sidebar/SidebarDockingWindow.hxx>
-#include <sfx2/sidebar/SidebarController.hxx>
+#include <sfx2/sidebar/Sidebar.hxx>
#include <svl/numformat.hxx>
#include <svx/dialmgr.hxx>
#include <svx/strings.hrc>
@@ -119,7 +153,7 @@
#include <svx/svxids.hrc>
#include <svx/ucsubset.hxx>
#include <vcl/vclevent.hxx>
-#include <vcl/GestureEvent.hxx>
+#include <vcl/GestureEventPan.hxx>
#include <vcl/svapp.hxx>
#include <unotools/resmgr.hxx>
#include <tools/fract.hxx>
@@ -134,6 +168,9 @@
#include <vcl/ImageTree.hxx>
#include <vcl/ITiledRenderable.hxx>
#include <vcl/dialoghelper.hxx>
+#ifdef _WIN32
+#include <vcl/BitmapReadAccess.hxx>
+#endif
#include <unicode/uchar.h>
#include <unotools/securityoptions.hxx>
#include <unotools/confignode.hxx>
@@ -150,13 +187,14 @@
#include <i18nlangtag/mslangid.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <vcl/abstdlg.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <vcl/uitest/uiobject.hxx>
#include <vcl/jsdialog/executor.hxx>
// Needed for getUndoManager()
#include <com/sun/star/document/XUndoManager.hpp>
#include <com/sun/star/document/XUndoManagerSupplier.hpp>
+#include <com/sun/star/document/XLinkTargetSupplier.hpp>
#include <editeng/sizeitem.hxx>
#include <svx/rulritem.hxx>
#include <svx/pageitem.hxx>
@@ -173,28 +211,51 @@
#include "lokclipboard.hxx"
#include <officecfg/Office/Common.hxx>
#include <officecfg/Office/Impress.hxx>
+#include <officecfg/Office/Linguistic.hxx>
+#include <officecfg/Office/UI/ToolbarMode.hxx>
#include <unotools/optionsdlg.hxx>
#include <svl/ctloptions.hxx>
-#include <svtools/accessibilityoptions.hxx>
#include <svtools/colorcfg.hxx>
#include <svtools/miscopt.hxx>
-#include <svtools/slidesorterbaropt.hxx>
#include <unotools/cmdoptions.hxx>
-#include <unotools/compatibility.hxx>
-#include <unotools/fltrcfg.hxx>
#include <unotools/lingucfg.hxx>
#include <unotools/moduleoptions.hxx>
#include <unotools/searchopt.hxx>
#include <unotools/useroptions.hxx>
-#include <unotools/viewoptions.hxx>
#include <vcl/settings.hxx>
+#include <officecfg/Setup.hxx>
+#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
+#include <svtools/acceleratorexecute.hxx>
+
+#include <tools/hostfilter.hxx>
+
using namespace css;
using namespace vcl;
using namespace desktop;
using namespace utl;
+using namespace bridge;
+using namespace uno;
+using namespace lang;
+
+#ifdef UNX
+
+static int urandom = -1;
+
+extern "C" {
+ int SAL_JNI_EXPORT lok_open_urandom()
+ {
+ return dup(urandom);
+ }
+};
+
+#endif
+
+
+using LanguageToolCfg = officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
static LibLibreOffice_Impl *gImpl = nullptr;
+static bool lok_preinit_2_called = false;
static std::weak_ptr< LibreOfficeKitClass > gOfficeClass;
static std::weak_ptr< LibreOfficeKitDocumentClass > gDocumentClass;
@@ -209,8 +270,8 @@ namespace {
struct ExtensionMap
{
- const char *extn;
- const char *filterName;
+ std::string_view extn;
+ OUString filterName;
};
class TraceEventDumper : public AutoTimer
@@ -236,8 +297,8 @@ public:
OStringBuffer aOutput;
for (const auto &s : aEvents)
{
- aOutput.append(OUStringToOString(s, RTL_TEXTENCODING_UTF8));
- aOutput.append("\n");
+ aOutput.append(OUStringToOString(s, RTL_TEXTENCODING_UTF8)
+ + "\n");
}
if (aOutput.getLength() > 0)
{
@@ -248,88 +309,81 @@ public:
}
};
-} // unnamed namespace
-
-static TraceEventDumper *traceEventDumper = nullptr;
-
-const ExtensionMap aWriterExtensionMap[] =
-{
- { "doc", "MS Word 97" },
- { "docm", "MS Word 2007 XML VBA" },
- { "docx", "MS Word 2007 XML" },
- { "fodt", "OpenDocument Text Flat XML" },
- { "html", "HTML (StarWriter)" },
- { "odt", "writer8" },
- { "ott", "writer8_template" },
- { "pdf", "writer_pdf_Export" },
- { "epub", "EPUB" },
- { "rtf", "Rich Text Format" },
- { "txt", "Text" },
- { "xhtml", "XHTML Writer File" },
- { "png", "writer_png_Export" },
- { "xml", "writer_indexing_export" },
- { nullptr, nullptr }
+TraceEventDumper *traceEventDumper = nullptr;
+
+constexpr ExtensionMap aWriterExtensionMap[] =
+{
+ { "doc", u"MS Word 97"_ustr },
+ { "docm", u"MS Word 2007 XML VBA"_ustr },
+ { "docx", u"MS Word 2007 XML"_ustr },
+ { "fodt", u"OpenDocument Text Flat XML"_ustr },
+ { "html", u"HTML (StarWriter)"_ustr },
+ { "odt", u"writer8"_ustr },
+ { "ott", u"writer8_template"_ustr },
+ { "pdf", u"writer_pdf_Export"_ustr },
+ { "epub", u"EPUB"_ustr },
+ { "rtf", u"Rich Text Format"_ustr },
+ { "txt", u"Text"_ustr },
+ { "xhtml", u"XHTML Writer File"_ustr },
+ { "png", u"writer_png_Export"_ustr },
+ { "xml", u"writer_indexing_export"_ustr },
};
-const ExtensionMap aCalcExtensionMap[] =
-{
- { "csv", "Text - txt - csv (StarCalc)" },
- { "fods", "OpenDocument Spreadsheet Flat XML" },
- { "html", "HTML (StarCalc)" },
- { "ods", "calc8" },
- { "ots", "calc8_template" },
- { "pdf", "calc_pdf_Export" },
- { "xhtml", "XHTML Calc File" },
- { "xls", "MS Excel 97" },
- { "xlsm", "Calc MS Excel 2007 VBA XML" },
- { "xlsx", "Calc MS Excel 2007 XML" },
- { "png", "calc_png_Export" },
- { nullptr, nullptr }
+constexpr ExtensionMap aCalcExtensionMap[] =
+{
+ { "csv", u"Text - txt - csv (StarCalc)"_ustr },
+ { "fods", u"OpenDocument Spreadsheet Flat XML"_ustr },
+ { "html", u"HTML (StarCalc)"_ustr },
+ { "ods", u"calc8"_ustr },
+ { "ots", u"calc8_template"_ustr },
+ { "pdf", u"calc_pdf_Export"_ustr },
+ { "xhtml", u"XHTML Calc File"_ustr },
+ { "xls", u"MS Excel 97"_ustr },
+ { "xlsm", u"Calc MS Excel 2007 VBA XML"_ustr },
+ { "xlsx", u"Calc MS Excel 2007 XML"_ustr },
+ { "png", u"calc_png_Export"_ustr },
};
-const ExtensionMap aImpressExtensionMap[] =
-{
- { "fodp", "OpenDocument Presentation Flat XML" },
- { "html", "impress_html_Export" },
- { "odg", "impress8_draw" },
- { "odp", "impress8" },
- { "otp", "impress8_template" },
- { "pdf", "impress_pdf_Export" },
- { "potm", "Impress MS PowerPoint 2007 XML Template" },
- { "pot", "MS PowerPoint 97 Vorlage" },
- { "pptm", "Impress MS PowerPoint 2007 XML VBA" },
- { "pptx", "Impress MS PowerPoint 2007 XML" },
- { "pps", "MS PowerPoint 97 Autoplay" },
- { "ppt", "MS PowerPoint 97" },
- { "svg", "impress_svg_Export" },
- { "xhtml", "XHTML Impress File" },
- { "png", "impress_png_Export"},
- { nullptr, nullptr }
+constexpr ExtensionMap aImpressExtensionMap[] =
+{
+ { "fodp", u"OpenDocument Presentation Flat XML"_ustr },
+ { "html", u"impress_html_Export"_ustr },
+ { "odg", u"impress8_draw"_ustr },
+ { "odp", u"impress8"_ustr },
+ { "otp", u"impress8_template"_ustr },
+ { "pdf", u"impress_pdf_Export"_ustr },
+ { "potm", u"Impress MS PowerPoint 2007 XML Template"_ustr },
+ { "pot", u"MS PowerPoint 97 Vorlage"_ustr },
+ { "pptm", u"Impress MS PowerPoint 2007 XML VBA"_ustr },
+ { "pptx", u"Impress MS PowerPoint 2007 XML"_ustr },
+ { "pps", u"MS PowerPoint 97 Autoplay"_ustr },
+ { "ppt", u"MS PowerPoint 97"_ustr },
+ { "svg", u"impress_svg_Export"_ustr },
+ { "xhtml", u"XHTML Impress File"_ustr },
+ { "png", u"impress_png_Export"_ustr },
};
-const ExtensionMap aDrawExtensionMap[] =
+constexpr ExtensionMap aDrawExtensionMap[] =
{
- { "fodg", "draw_ODG_FlatXML" },
- { "html", "draw_html_Export" },
- { "odg", "draw8" },
- { "pdf", "draw_pdf_Export" },
- { "svg", "draw_svg_Export" },
- { "xhtml", "XHTML Draw File" },
- { "png", "draw_png_Export"},
- { nullptr, nullptr }
+ { "fodg", u"draw_ODG_FlatXML"_ustr },
+ { "html", u"draw_html_Export"_ustr },
+ { "odg", u"draw8"_ustr },
+ { "pdf", u"draw_pdf_Export"_ustr },
+ { "svg", u"draw_svg_Export"_ustr },
+ { "xhtml", u"XHTML Draw File"_ustr },
+ { "png", u"draw_png_Export"_ustr },
};
-static OUString getUString(const char* pString)
+OUString getUString(const char* pString)
{
if (pString == nullptr)
return OUString();
- OString sString(pString, strlen(pString));
- return OStringToOUString(sString, RTL_TEXTENCODING_UTF8);
+ return OStringToOUString(pString, RTL_TEXTENCODING_UTF8);
}
// Tolerate embedded \0s etc.
-static char *convertOString(const OString &rStr)
+char *convertOString(const OString &rStr)
{
char* pMemory = static_cast<char*>(malloc(rStr.getLength() + 1));
assert(pMemory); // don't tolerate failed allocations.
@@ -337,13 +391,13 @@ static char *convertOString(const OString &rStr)
return pMemory;
}
-static char *convertOUString(std::u16string_view aStr)
+char *convertOUString(std::u16string_view aStr)
{
return convertOString(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8));
}
/// Try to convert a relative URL to an absolute one, unless it already looks like a URL.
-static OUString getAbsoluteURL(const char* pURL)
+OUString getAbsoluteURL(const char* pURL)
{
OUString aURL(getUString(pURL));
if (aURL.isEmpty())
@@ -366,6 +420,8 @@ static OUString getAbsoluteURL(const char* pURL)
return OUString();
}
+} // unnamed namespace
+
std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char* pJSON)
{
std::vector<beans::PropertyValue> aArguments;
@@ -376,18 +432,76 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char
return aArguments;
}
-static void unoAnyToJson(tools::JsonWriter& rJson, const char * pNodeName, const uno::Any& anyItem)
+static void extractLinks(const uno::Reference< container::XNameAccess >& xLinks, bool subcontent, tools::JsonWriter& aJson)
+{
+ for (const OUString& aLink : xLinks->getElementNames())
+ {
+ uno::Any aAny;
+
+ try
+ {
+ aAny = xLinks->getByName( aLink );
+ }
+ catch(const uno::Exception&)
+ {
+ // if the name of the target was invalid (like empty headings)
+ // no object can be provided
+ continue;
+ }
+
+ uno::Reference< beans::XPropertySet > xTarget;
+ if( aAny >>= xTarget )
+ {
+ try
+ {
+ // get name to display
+ aAny = xTarget->getPropertyValue(u"LinkDisplayName"_ustr);
+ OUString aStrDisplayname;
+ aAny >>= aStrDisplayname;
+
+ if (subcontent)
+ {
+ aJson.put(aStrDisplayname, aLink);
+ }
+ else
+ {
+ uno::Reference<lang::XServiceInfo> xSI(xTarget, uno::UNO_QUERY_THROW);
+ if (xSI->supportsService(u"com.sun.star.document.LinkTarget"_ustr))
+ {
+ aJson.put(aStrDisplayname, aLink);
+ continue;
+ }
+ else
+ {
+ auto aNode = aJson.startNode(
+ OUStringToOString(aStrDisplayname, RTL_TEXTENCODING_UTF8));
+
+ uno::Reference< document::XLinkTargetSupplier > xLTS( xTarget, uno::UNO_QUERY );
+ if( xLTS.is() )
+ extractLinks(xLTS->getLinks(), true, aJson);
+ }
+ }
+ }
+ catch(...)
+ {
+ SAL_WARN("lok", "extractLinks: Exception");
+ }
+ }
+ }
+}
+
+static void unoAnyToJson(tools::JsonWriter& rJson, std::string_view pNodeName, const uno::Any& anyItem)
{
auto aNode = rJson.startNode(pNodeName);
OUString aType = anyItem.getValueTypeName();
- rJson.put("type", aType.toUtf8().getStr());
+ rJson.put("type", aType);
if (aType == "string")
- rJson.put("value", anyItem.get<OUString>().toUtf8().getStr());
+ rJson.put("value", anyItem.get<OUString>());
else if (aType == "unsigned long")
- rJson.put("value", OString::number(anyItem.get<sal_uInt32>()).getStr());
+ rJson.put("value", OString::number(anyItem.get<sal_uInt32>()));
else if (aType == "long")
- rJson.put("value", OString::number(anyItem.get<sal_Int32>()).getStr());
+ rJson.put("value", OString::number(anyItem.get<sal_Int32>()));
else if (aType == "[]any")
{
uno::Sequence<uno::Any> aSeq;
@@ -397,59 +511,88 @@ static void unoAnyToJson(tools::JsonWriter& rJson, const char * pNodeName, const
for (auto i = 0; i < aSeq.getLength(); ++i)
{
- unoAnyToJson(rJson, OString::number(i).getStr(), aSeq[i]);
+ unoAnyToJson(rJson, OString::number(i), aSeq[i]);
}
}
}
}
-static int lcl_getViewId(const std::string& payload);
+static int lcl_getViewId(std::string_view payload);
namespace desktop {
-RectangleAndPart RectangleAndPart::Create(const std::string& rPayload)
+RectangleAndPart RectangleAndPart::Create(const OString& rPayload)
{
RectangleAndPart aRet;
- if (rPayload.compare(0, 5, "EMPTY") == 0) // payload starts with "EMPTY"
+ if (rPayload.startsWith("EMPTY")) // payload starts with "EMPTY"
{
aRet.m_aRectangle = tools::Rectangle(0, 0, SfxLokHelper::MaxTwips, SfxLokHelper::MaxTwips);
if (comphelper::LibreOfficeKit::isPartInInvalidation())
- aRet.m_nPart = std::stol(rPayload.substr(6));
+ {
+ int nSeparatorPos = rPayload.indexOf(',', 6);
+ bool bHasMode = nSeparatorPos > 0;
+ if (bHasMode)
+ {
+ aRet.m_nPart = o3tl::toInt32(rPayload.subView(6, nSeparatorPos - 6));
+ assert(rPayload.getLength() > nSeparatorPos);
+ aRet.m_nMode = o3tl::toInt32(rPayload.subView(nSeparatorPos + 1));
+ }
+ else
+ {
+ aRet.m_nPart = o3tl::toInt32(rPayload.subView(6));
+ aRet.m_nMode = 0;
+ }
+ }
return aRet;
}
- // Read '<left>, <top>, <width>, <height>[, <part>]'. C++ streams are simpler but slower.
- const char* pos = rPayload.c_str();
- const char* end = rPayload.c_str() + rPayload.size();
+ // Read '<left>, <top>, <width>, <height>[, <part>, <mode>]'. C++ streams are simpler but slower.
+ const char* pos = rPayload.getStr();
+ const char* end = rPayload.getStr() + rPayload.getLength();
tools::Long nLeft = rtl_str_toInt64_WithLength(pos, 10, end - pos);
- while( *pos != ',' )
+ while (pos < end && *pos != ',')
+ ++pos;
+ if (pos < end)
++pos;
- ++pos;
assert(pos < end);
tools::Long nTop = rtl_str_toInt64_WithLength(pos, 10, end - pos);
- while( *pos != ',' )
+ while (pos < end && *pos != ',')
+ ++pos;
+ if (pos < end)
++pos;
- ++pos;
assert(pos < end);
tools::Long nWidth = rtl_str_toInt64_WithLength(pos, 10, end - pos);
- while( *pos != ',' )
+ while (pos < end && *pos != ',')
+ ++pos;
+ if (pos < end)
++pos;
- ++pos;
assert(pos < end);
tools::Long nHeight = rtl_str_toInt64_WithLength(pos, 10, end - pos);
tools::Long nPart = INT_MIN;
+ tools::Long nMode = 0;
if (comphelper::LibreOfficeKit::isPartInInvalidation())
{
- while( *pos != ',' )
+ while (pos < end && *pos != ',')
+ ++pos;
+ if (pos < end)
++pos;
- ++pos;
assert(pos < end);
nPart = rtl_str_toInt64_WithLength(pos, 10, end - pos);
+
+ while (pos < end && *pos != ',')
+ ++pos;
+ if (pos < end)
+ {
+ ++pos;
+ assert(pos < end);
+ nMode = rtl_str_toInt64_WithLength(pos, 10, end - pos);
+ }
}
aRet.m_aRectangle = SanitizedRectangle(nLeft, nTop, nWidth, nHeight);
aRet.m_nPart = nPart;
+ aRet.m_nMode = nMode;
return aRet;
}
@@ -480,12 +623,12 @@ tools::Rectangle RectangleAndPart::SanitizedRectangle(tools::Long nLeft, tools::
tools::Rectangle RectangleAndPart::SanitizedRectangle(const tools::Rectangle& rect)
{
- return SanitizedRectangle(rect.Left(), rect.Top(), rect.getWidth(), rect.getHeight());
+ return SanitizedRectangle(rect.Left(), rect.Top(), rect.getOpenWidth(), rect.getOpenHeight());
}
-const std::string& CallbackFlushHandler::CallbackData::getPayload() const
+const OString& CallbackFlushHandler::CallbackData::getPayload() const
{
- if(PayloadString.empty())
+ if(PayloadString.isEmpty())
{
// Do to-string conversion on demand, as many calls will get dropped without
// needing the string.
@@ -528,7 +671,7 @@ void CallbackFlushHandler::CallbackData::setJson(const boost::property_tree::ptr
std::stringstream aJSONStream;
constexpr bool bPretty = false; // Don't waste time and bloat logs.
boost::property_tree::write_json(aJSONStream, rTree, bPretty);
- PayloadString = boost::trim_copy(aJSONStream.str());
+ PayloadString = OString(o3tl::trim(aJSONStream.str()));
PayloadObject = rTree;
}
@@ -567,7 +710,7 @@ bool CallbackFlushHandler::CallbackData::validate() const
std::stringstream aJSONStream;
boost::property_tree::write_json(aJSONStream, getJson(), false);
const std::string aExpected = boost::trim_copy(aJSONStream.str());
- return aExpected == getPayload();
+ return getPayload() == std::string_view(aExpected);
}
// View id.
@@ -625,7 +768,7 @@ static bool isUpdatedTypePerViewId(int type)
}
}
-static int lcl_getViewId(const std::string& payload)
+static int lcl_getViewId(std::string_view payload)
{
// this is a cheap way how to get the viewId from a JSON message; proper
// parsing is terribly expensive, and we just need the viewId here
@@ -644,7 +787,7 @@ static int lcl_getViewId(const std::string& payload)
}
if (numberPos < payload.length() && payload[numberPos] >= '0' && payload[numberPos] <= '9')
- return strtol(payload.substr(numberPos).c_str(), nullptr, 10);
+ return o3tl::toInt32(payload.substr(numberPos));
return 0;
}
@@ -653,8 +796,8 @@ namespace {
std::string extractCertificate(const std::string & certificate)
{
- const std::string header("-----BEGIN CERTIFICATE-----");
- const std::string footer("-----END CERTIFICATE-----");
+ static constexpr std::string_view header("-----BEGIN CERTIFICATE-----");
+ static constexpr std::string_view footer("-----END CERTIFICATE-----");
std::string result;
@@ -674,8 +817,8 @@ std::string extractCertificate(const std::string & certificate)
std::string extractPrivateKey(const std::string & privateKey)
{
- const std::string header("-----BEGIN PRIVATE KEY-----");
- const std::string footer("-----END PRIVATE KEY-----");
+ static constexpr std::string_view header("-----BEGIN PRIVATE KEY-----");
+ static constexpr std::string_view footer("-----END PRIVATE KEY-----");
std::string result;
@@ -758,6 +901,10 @@ void ExecuteMarginULChange(
// Main function which toggles page orientation of the Writer doc. Needed by ToggleOrientation
void ExecuteOrientationChange()
{
+ SfxViewFrame* pViewFrm = SfxViewFrame::Current();
+ if (!pViewFrm)
+ return;
+
std::unique_ptr<SvxPageItem> pPageItem(new SvxPageItem(SID_ATTR_PAGE));
// 1mm in twips rounded
@@ -765,23 +912,20 @@ void ExecuteOrientationChange()
constexpr tools::Long MINBODY = o3tl::toTwips(1, o3tl::Length::mm);
css::uno::Reference< css::document::XUndoManager > mxUndoManager(
- getUndoManager( SfxViewFrame::Current()->GetFrame().GetFrameInterface() ) );
+ getUndoManager( pViewFrm->GetFrame().GetFrameInterface() ) );
if ( mxUndoManager.is() )
mxUndoManager->enterUndoContext( "" );
+ SfxPoolItemHolder aResult;
+ pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, aResult);
+ std::unique_ptr<SvxSizeItem> pPageSizeItem(static_cast<const SvxSizeItem*>(aResult.getItem())->Clone());
- const SfxPoolItem* pItem;
-
-
- SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, pItem);
- std::unique_ptr<SvxSizeItem> pPageSizeItem(&pItem->Clone()->StaticWhichCast(SID_ATTR_PAGE_SIZE));
+ pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, aResult);
+ std::unique_ptr<SvxLongLRSpaceItem> pPageLRMarginItem(static_cast<const SvxLongLRSpaceItem*>(aResult.getItem())->Clone());
- SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, pItem);
- std::unique_ptr<SvxLongLRSpaceItem> pPageLRMarginItem(&pItem->Clone()->StaticWhichCast(SID_ATTR_PAGE_LRSPACE));
-
- SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, pItem);
- std::unique_ptr<SvxLongULSpaceItem> pPageULMarginItem(&pItem->Clone()->StaticWhichCast(SID_ATTR_PAGE_ULSPACE));
+ pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, aResult);
+ std::unique_ptr<SvxLongULSpaceItem> pPageULMarginItem(static_cast<const SvxLongULSpaceItem*>(aResult.getItem())->Clone());
{
bool bIsLandscape = false;
@@ -851,58 +995,14 @@ void ExecuteOrientationChange()
mxUndoManager->leaveUndoContext();
}
-void setupSidebar(std::u16string_view sidebarDeckId = u"")
-{
- SfxViewShell* pViewShell = SfxViewShell::Current();
- SfxViewFrame* pViewFrame = pViewShell ? pViewShell->GetViewFrame() : nullptr;
- if (pViewFrame)
- {
- if (!pViewFrame->GetChildWindow(SID_SIDEBAR))
- pViewFrame->SetChildWindow(SID_SIDEBAR, false /* create it */, true /* focus */);
-
- pViewFrame->ShowChildWindow(SID_SIDEBAR, true);
-
- // Force synchronous population of panels
- SfxChildWindow *pChild = pViewFrame->GetChildWindow(SID_SIDEBAR);
- if (!pChild)
- return;
-
- auto pDockingWin = dynamic_cast<sfx2::sidebar::SidebarDockingWindow *>(pChild->GetWindow());
- if (!pDockingWin)
- return;
-
- OUString currentDeckId = pDockingWin->GetSidebarController()->GetCurrentDeckId();
-
- // check if it is the chart deck id, if it is, don't switch to default deck
- bool switchToDefault = true;
-
- if (currentDeckId == "ChartDeck")
- switchToDefault = false;
-
- if (!sidebarDeckId.empty())
- {
- pDockingWin->GetSidebarController()->SwitchToDeck(sidebarDeckId);
- }
- else
- {
- if (switchToDefault)
- pDockingWin->GetSidebarController()->SwitchToDefaultDeck();
- }
-
- pDockingWin->SyncUpdate();
- }
- else
- SetLastExceptionMsg("No view shell or sidebar");
-}
-
void hideSidebar()
{
SfxViewShell* pViewShell = SfxViewShell::Current();
- SfxViewFrame* pViewFrame = pViewShell? pViewShell->GetViewFrame(): nullptr;
+ SfxViewFrame* pViewFrame = pViewShell ? &pViewShell->GetViewFrame() : nullptr;
if (pViewFrame)
pViewFrame->SetChildWindow(SID_SIDEBAR, false , false );
else
- SetLastExceptionMsg("No view shell or sidebar");
+ SetLastExceptionMsg(u"No view shell or sidebar"_ustr);
}
} // end anonymous namespace
@@ -965,21 +1065,16 @@ static void doc_selectPart(LibreOfficeKitDocument* pThis, int nPart, int nSelect
static void doc_moveSelectedParts(LibreOfficeKitDocument* pThis, int nPosition, bool bDuplicate);
static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart);
static void doc_setPartMode(LibreOfficeKitDocument* pThis, int nPartMode);
+static int doc_getEditMode(LibreOfficeKitDocument* pThis);
static void doc_paintTile(LibreOfficeKitDocument* pThis,
unsigned char* pBuffer,
const int nCanvasWidth, const int nCanvasHeight,
const int nTilePosX, const int nTilePosY,
const int nTileWidth, const int nTileHeight);
-#ifdef IOS
-static void doc_paintTileToCGContext(LibreOfficeKitDocument* pThis,
- void* rCGContext,
- const int nCanvasWidth, const int nCanvasHeight,
- const int nTilePosX, const int nTilePosY,
- const int nTileWidth, const int nTileHeight);
-#endif
static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
unsigned char* pBuffer,
const int nPart,
+ const int nMode,
const int nCanvasWidth, const int nCanvasHeight,
const int nTilePosX, const int nTilePosY,
const int nTileWidth, const int nTileHeight);
@@ -987,6 +1082,10 @@ static int doc_getTileMode(LibreOfficeKitDocument* pThis);
static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
long* pWidth,
long* pHeight);
+static void doc_getDataArea(LibreOfficeKitDocument* pThis,
+ long nTab,
+ long* pCol,
+ long* pRow);
static void doc_initializeForRendering(LibreOfficeKitDocument* pThis,
const char* pArguments);
@@ -1055,6 +1154,10 @@ static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
const char* pMimeType,
char** pUsedMimeType);
static int doc_getSelectionType(LibreOfficeKitDocument* pThis);
+static int doc_getSelectionTypeAndText(LibreOfficeKitDocument* pThis,
+ const char* pMimeType,
+ char** pText,
+ char** pUsedMimeType);
static int doc_getClipboard (LibreOfficeKitDocument* pThis,
const char **pMimeTypes,
size_t *pOutCount,
@@ -1150,6 +1253,19 @@ static bool doc_renderSearchResult(LibreOfficeKitDocument* pThis,
const char* pSearchResult, unsigned char** pBitmapBuffer,
int* pWidth, int* pHeight, size_t* pByteSize);
+static void doc_sendContentControlEvent(LibreOfficeKitDocument* pThis, const char* pArguments);
+
+static void doc_setViewTimezone(LibreOfficeKitDocument* pThis, int nId, const char* timezone);
+
+static void doc_setViewReadOnly(LibreOfficeKitDocument* pThis, int nId, const bool readonly);
+
+static void doc_setAllowChangeComments(LibreOfficeKitDocument* pThis, int nId, const bool allow);
+
+static void doc_setAccessibilityState(LibreOfficeKitDocument* pThis, int nId, bool bEnabled);
+
+static char* doc_getA11yFocusedParagraph(LibreOfficeKitDocument* pThis);
+
+static int doc_getA11yCaretPosition(LibreOfficeKitDocument* pThis);
} // extern "C"
namespace {
@@ -1180,19 +1296,21 @@ rtl::Reference<LOKClipboard> forceSetClipboardForCurrentView(LibreOfficeKitDocum
#endif
-const vcl::Font* FindFont(const OUString& rFontName)
+const vcl::Font* FindFont(std::u16string_view rFontName)
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
+ if (!pDocSh)
+ return nullptr;
const SvxFontListItem* pFonts
= static_cast<const SvxFontListItem*>(pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr;
- if (pList && !rFontName.isEmpty())
+ if (pList && !rFontName.empty())
if (sal_Handle hMetric = pList->GetFirstFontMetric(rFontName))
return &FontList::GetFontMetric(hMetric);
return nullptr;
}
-vcl::Font FindFont_FallbackToDefault(const OUString& rFontName)
+vcl::Font FindFont_FallbackToDefault(std::u16string_view rFontName)
{
if (auto pFound = FindFont(rFontName))
return *pFound;
@@ -1200,10 +1318,49 @@ vcl::Font FindFont_FallbackToDefault(const OUString& rFontName)
return OutputDevice::GetDefaultFont(DefaultFontType::SANS_UNICODE, LANGUAGE_NONE,
GetDefaultFontFlags::NONE);
}
+
+int getDocumentType (LibreOfficeKitDocument* pThis)
+{
+ SetLastExceptionMsg();
+
+ LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+
+ try
+ {
+ uno::Reference<lang::XServiceInfo> xDocument(pDocument->mxComponent, uno::UNO_QUERY_THROW);
+
+ if (xDocument->supportsService(u"com.sun.star.sheet.SpreadsheetDocument"_ustr))
+ {
+ return LOK_DOCTYPE_SPREADSHEET;
+ }
+ else if (xDocument->supportsService(u"com.sun.star.presentation.PresentationDocument"_ustr))
+ {
+ return LOK_DOCTYPE_PRESENTATION;
+ }
+ else if (xDocument->supportsService(u"com.sun.star.drawing.DrawingDocument"_ustr))
+ {
+ return LOK_DOCTYPE_DRAWING;
+ }
+ else if (xDocument->supportsService(u"com.sun.star.text.TextDocument"_ustr) || xDocument->supportsService(u"com.sun.star.text.WebDocument"_ustr))
+ {
+ return LOK_DOCTYPE_TEXT;
+ }
+ else
+ {
+ SetLastExceptionMsg(u"unknown document type"_ustr);
+ }
+ }
+ catch (const uno::Exception& exception)
+ {
+ SetLastExceptionMsg("exception: " + exception.Message);
+ }
+ return LOK_DOCTYPE_OTHER;
+}
+
} // anonymous namespace
-LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent, int nDocumentId)
- : mxComponent(xComponent)
+LibLODocument_Impl::LibLODocument_Impl(uno::Reference <css::lang::XComponent> xComponent, int nDocumentId)
+ : mxComponent(std::move(xComponent))
, mnDocumentId(nDocumentId)
{
assert(nDocumentId != -1 && "Cannot set mnDocumentId to -1");
@@ -1226,13 +1383,12 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->moveSelectedParts = doc_moveSelectedParts;
m_pDocumentClass->getPartName = doc_getPartName;
m_pDocumentClass->setPartMode = doc_setPartMode;
+ m_pDocumentClass->getEditMode = doc_getEditMode;
m_pDocumentClass->paintTile = doc_paintTile;
-#ifdef IOS
- m_pDocumentClass->paintTileToCGContext = doc_paintTileToCGContext;
-#endif
m_pDocumentClass->paintPartTile = doc_paintPartTile;
m_pDocumentClass->getTileMode = doc_getTileMode;
m_pDocumentClass->getDocumentSize = doc_getDocumentSize;
+ m_pDocumentClass->getDataArea = doc_getDataArea;
m_pDocumentClass->initializeForRendering = doc_initializeForRendering;
m_pDocumentClass->registerCallback = doc_registerCallback;
m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
@@ -1247,6 +1403,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->setWindowTextSelection = doc_setWindowTextSelection;
m_pDocumentClass->getTextSelection = doc_getTextSelection;
m_pDocumentClass->getSelectionType = doc_getSelectionType;
+ m_pDocumentClass->getSelectionTypeAndText = doc_getSelectionTypeAndText;
m_pDocumentClass->getClipboard = doc_getClipboard;
m_pDocumentClass->setClipboard = doc_setClipboard;
m_pDocumentClass->paste = doc_paste;
@@ -1293,6 +1450,19 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->setBlockedCommandList = doc_setBlockedCommandList;
+ m_pDocumentClass->sendContentControlEvent = doc_sendContentControlEvent;
+
+ m_pDocumentClass->setViewTimezone = doc_setViewTimezone;
+
+ m_pDocumentClass->setAccessibilityState = doc_setAccessibilityState;
+
+ m_pDocumentClass->getA11yFocusedParagraph = doc_getA11yFocusedParagraph;
+ m_pDocumentClass->getA11yCaretPosition = doc_getA11yCaretPosition;
+
+ m_pDocumentClass->setViewReadOnly = doc_setViewReadOnly;
+
+ m_pDocumentClass->setAllowChangeComments = doc_setAllowChangeComments;
+
gDocumentClass = m_pDocumentClass;
}
pClass = m_pDocumentClass.get();
@@ -1317,8 +1487,8 @@ LibLODocument_Impl::~LibLODocument_Impl()
static OUString getGenerator()
{
OUString sGenerator(
- Translate::ExpandVariables("%PRODUCTNAME %PRODUCTVERSION%PRODUCTEXTENSION (%1)"));
- OUString os("$_OS");
+ Translate::ExpandVariables(u"%PRODUCTNAME %PRODUCTVERSION%PRODUCTEXTENSION (%1)"_ustr));
+ OUString os(u"$_OS"_ustr);
::rtl::Bootstrap::expandMacros(os);
return sGenerator.replaceFirst("%1", os);
}
@@ -1353,20 +1523,20 @@ CallbackFlushHandler::CallbackFlushHandler(LibreOfficeKitDocument* pDocument, Li
// Add the states that are safe to skip duplicates on, even when
// not consequent (i.e. do no emit them if unchanged from last).
- m_states.emplace(LOK_CALLBACK_TEXT_SELECTION, "NIL");
- m_states.emplace(LOK_CALLBACK_GRAPHIC_SELECTION, "NIL");
- m_states.emplace(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, "NIL");
- m_states.emplace(LOK_CALLBACK_STATE_CHANGED, "NIL");
- m_states.emplace(LOK_CALLBACK_MOUSE_POINTER, "NIL");
- m_states.emplace(LOK_CALLBACK_CELL_CURSOR, "NIL");
- m_states.emplace(LOK_CALLBACK_CELL_FORMULA, "NIL");
- m_states.emplace(LOK_CALLBACK_CELL_ADDRESS, "NIL");
- m_states.emplace(LOK_CALLBACK_CURSOR_VISIBLE, "NIL");
- m_states.emplace(LOK_CALLBACK_SET_PART, "NIL");
- m_states.emplace(LOK_CALLBACK_TABLE_SELECTED, "NIL");
- m_states.emplace(LOK_CALLBACK_TAB_STOP_LIST, "NIL");
- m_states.emplace(LOK_CALLBACK_RULER_UPDATE, "NIL");
- m_states.emplace(LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE, "NIL");
+ m_states.emplace(LOK_CALLBACK_TEXT_SELECTION, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_GRAPHIC_SELECTION, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_STATE_CHANGED, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_MOUSE_POINTER, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_CELL_CURSOR, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_CELL_FORMULA, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_CELL_ADDRESS, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_CURSOR_VISIBLE, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_SET_PART, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_TABLE_SELECTED, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_TAB_STOP_LIST, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_RULER_UPDATE, "NIL"_ostr);
+ m_states.emplace(LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE, "NIL"_ostr);
}
CallbackFlushHandler::~CallbackFlushHandler()
@@ -1392,6 +1562,8 @@ void CallbackFlushHandler::setUpdatedType( int nType, bool value )
if( m_updatedTypes.size() <= o3tl::make_unsigned( nType ))
m_updatedTypes.resize( nType + 1 ); // new are default-constructed, i.e. false
m_updatedTypes[ nType ] = value;
+ if(value)
+ startTimer();
}
void CallbackFlushHandler::resetUpdatedType( int nType )
@@ -1406,6 +1578,8 @@ void CallbackFlushHandler::setUpdatedTypePerViewId( int nType, int nViewId, int
if( types.size() <= o3tl::make_unsigned( nType ))
types.resize( nType + 1 ); // new are default-constructed, i.e. 'set' is false
types[ nType ] = PerViewIdData{ value, nSourceViewId };
+ if(value)
+ startTimer();
}
void CallbackFlushHandler::resetUpdatedTypePerViewId( int nType, int nViewId )
@@ -1428,28 +1602,28 @@ void CallbackFlushHandler::resetUpdatedTypePerViewId( int nType, int nViewId )
}
}
-void CallbackFlushHandler::libreOfficeKitViewCallback(int nType, const char* pPayload)
+void CallbackFlushHandler::libreOfficeKitViewCallback(int nType, const OString& pPayload)
{
CallbackData callbackData(pPayload);
queue(nType, callbackData);
}
-void CallbackFlushHandler::libreOfficeKitViewCallbackWithViewId(int nType, const char* pPayload, int nViewId)
+void CallbackFlushHandler::libreOfficeKitViewCallbackWithViewId(int nType, const OString& pPayload, int nViewId)
{
CallbackData callbackData(pPayload, nViewId);
queue(nType, callbackData);
}
-void CallbackFlushHandler::libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, int nPart)
+void CallbackFlushHandler::libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, int nPart, int nMode)
{
- CallbackData callbackData(pRect, nPart);
+ CallbackData callbackData(pRect, nPart, nMode);
queue(LOK_CALLBACK_INVALIDATE_TILES, callbackData);
}
void CallbackFlushHandler::libreOfficeKitViewUpdatedCallback(int nType)
{
assert(isUpdatedType( nType ));
- std::unique_lock<std::mutex> lock(m_mutex);
+ std::unique_lock<std::recursive_mutex> lock(m_mutex);
SAL_INFO("lok", "Updated: [" << nType << "]");
setUpdatedType(nType, true);
}
@@ -1457,12 +1631,35 @@ void CallbackFlushHandler::libreOfficeKitViewUpdatedCallback(int nType)
void CallbackFlushHandler::libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int nViewId, int nSourceViewId)
{
assert(isUpdatedTypePerViewId( nType ));
- std::unique_lock<std::mutex> lock(m_mutex);
+ std::unique_lock<std::recursive_mutex> lock(m_mutex);
SAL_INFO("lok", "Updated: [" << nType << "]");
setUpdatedTypePerViewId(nType, nViewId, nSourceViewId, true);
}
-void CallbackFlushHandler::queue(const int type, const char* data)
+void CallbackFlushHandler::dumpState(rtl::OStringBuffer &rState)
+{
+ // NB. no locking
+ rState.append("\nView:\t");
+ rState.append(static_cast<sal_Int32>(m_viewId));
+ rState.append("\n\tDisableCallbacks:\t");
+ rState.append(static_cast<sal_Int32>(m_nDisableCallbacks));
+ rState.append("\n\tStates:\n");
+ for (const auto &i : m_states)
+ {
+ rState.append("\n\t\t");
+ rState.append(static_cast<sal_Int32>(i.first));
+ rState.append("\t");
+ rState.append(i.second);
+ }
+}
+
+void CallbackFlushHandler::libreOfficeKitViewAddPendingInvalidateTiles()
+{
+ // Invoke() will call flushPendingLOKInvalidateTiles(), so just make sure the timer is active.
+ startTimer();
+}
+
+void CallbackFlushHandler::queue(const int type, const OString& data)
{
CallbackData callbackData(data);
queue(type, callbackData);
@@ -1475,13 +1672,18 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
SAL_INFO("lok", "Queue: [" << type << "]: [" << aCallbackData.getPayload() << "] on " << m_queue1.size() << " entries.");
bool bIsChartActive = false;
+ bool bIsComment = false;
if (type == LOK_CALLBACK_GRAPHIC_SELECTION)
{
LokChartHelper aChartHelper(SfxViewShell::Current());
bIsChartActive = aChartHelper.GetWindow() != nullptr;
}
+ else if (type == LOK_CALLBACK_COMMENT)
+ {
+ bIsComment = true;
+ }
- if (callbacksDisabled() && !bIsChartActive)
+ if (callbacksDisabled() && !bIsChartActive && !bIsComment)
{
// We drop notifications when this is set, except for important ones.
// When we issue a complex command (such as .uno:InsertAnnotation)
@@ -1498,6 +1700,7 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
type != LOK_CALLBACK_TEXT_SELECTION &&
type != LOK_CALLBACK_TEXT_SELECTION_START &&
type != LOK_CALLBACK_TEXT_SELECTION_END &&
+ type != LOK_CALLBACK_MEDIA_SHAPE &&
type != LOK_CALLBACK_REFERENCE_MARKS)
{
SAL_INFO("lok", "Skipping while painting [" << type << "]: [" << aCallbackData.getPayload() << "].");
@@ -1511,9 +1714,9 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
// Suppress invalid payloads.
if (type == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR &&
- aCallbackData.getPayload().find(", 0, 0, ") != std::string::npos &&
- aCallbackData.getPayload().find("\"hyperlink\":\"\"") == std::string::npos &&
- aCallbackData.getPayload().find("\"hyperlink\": {}") == std::string::npos)
+ aCallbackData.getPayload().indexOf(", 0, 0, ") != -1 &&
+ aCallbackData.getPayload().indexOf("\"hyperlink\":\"\"") == -1 &&
+ aCallbackData.getPayload().indexOf("\"hyperlink\": {}") == -1)
{
// The cursor position is often the relative coordinates of the widget
// issuing it, instead of the absolute one that we expect.
@@ -1523,7 +1726,7 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
return;
}
- std::unique_lock<std::mutex> lock(m_mutex);
+ std::unique_lock<std::recursive_mutex> lock(m_mutex);
// Update types should be received via the updated callbacks for performance,
// getting them as normal callbacks is technically not wrong, but probably should be avoided.
@@ -1566,6 +1769,13 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
case LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY:
case LOK_CALLBACK_REFERENCE_MARKS:
case LOK_CALLBACK_CELL_AUTO_FILL_AREA:
+ case LOK_CALLBACK_A11Y_FOCUS_CHANGED:
+ case LOK_CALLBACK_A11Y_CARET_CHANGED:
+ case LOK_CALLBACK_A11Y_TEXT_SELECTION_CHANGED:
+ case LOK_CALLBACK_A11Y_FOCUSED_CELL_CHANGED:
+ case LOK_CALLBACK_COLOR_PALETTES:
+ case LOK_CALLBACK_A11Y_EDITING_IN_SELECTION_STATE:
+ case LOK_CALLBACK_A11Y_SELECTION_CHANGED:
{
const auto& pos = std::find(m_queue1.rbegin(), m_queue1.rend(), type);
auto pos2 = toQueue2(pos);
@@ -1602,6 +1812,7 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
case LOK_CALLBACK_GRAPHIC_SELECTION:
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
case LOK_CALLBACK_INVALIDATE_TILES:
+ case LOK_CALLBACK_TOOLTIP:
if (removeAll(type))
SAL_INFO("lok", "Removed dups of [" << type << "]: [" << aCallbackData.getPayload() << "].");
break;
@@ -1624,6 +1835,13 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
case LOK_CALLBACK_SET_PART:
case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
case LOK_CALLBACK_RULER_UPDATE:
+ case LOK_CALLBACK_A11Y_FOCUS_CHANGED:
+ case LOK_CALLBACK_A11Y_CARET_CHANGED:
+ case LOK_CALLBACK_A11Y_TEXT_SELECTION_CHANGED:
+ case LOK_CALLBACK_A11Y_FOCUSED_CELL_CHANGED:
+ case LOK_CALLBACK_COLOR_PALETTES:
+ case LOK_CALLBACK_TOOLTIP:
+ case LOK_CALLBACK_SHAPE_INNER_TEXT:
{
if (removeAll(type))
SAL_INFO("lok", "Removed dups of [" << type << "]: [" << aCallbackData.getPayload() << "].");
@@ -1633,28 +1851,26 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
// These are safe to use the latest state and ignore previous
// ones (if any) since the last overrides previous ones,
// but only if the view is the same.
+ case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
+ // deleting the duplicate of visible cursor message can cause hyperlink popup not to show up on second/or more click on the same place.
+ // If the hyperlink is not empty we can bypass that to show the popup
+ if (aCallbackData.getPayload().indexOf("\"hyperlink\":\"\"") == -1
+ && aCallbackData.getPayload().indexOf("\"hyperlink\": {}") == -1)
+ break;
+ [[fallthrough]];
case LOK_CALLBACK_CELL_VIEW_CURSOR:
case LOK_CALLBACK_GRAPHIC_VIEW_SELECTION:
case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
- case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
case LOK_CALLBACK_TEXT_VIEW_SELECTION:
case LOK_CALLBACK_VIEW_CURSOR_VISIBLE:
case LOK_CALLBACK_CALC_FUNCTION_LIST:
case LOK_CALLBACK_FORM_FIELD_BUTTON:
{
- // deleting the duplicate of visible cursor message can cause hyperlink popup not to show up on second/or more click on the same place.
- // If the hyperlink is not empty we can bypass that to show the popup
- const bool hyperLinkException = type == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR &&
- aCallbackData.getPayload().find("\"hyperlink\":\"\"") == std::string::npos &&
- aCallbackData.getPayload().find("\"hyperlink\": {}") == std::string::npos;
- if(!hyperLinkException)
- {
- const int nViewId = aCallbackData.getViewId();
- removeAll(type, [nViewId] (const CallbackData& elemData) {
- return (nViewId == elemData.getViewId());
- }
- );
- }
+ const int nViewId = aCallbackData.getViewId();
+ removeAll(type, [nViewId] (const CallbackData& elemData) {
+ return (nViewId == elemData.getViewId());
+ }
+ );
}
break;
@@ -1668,16 +1884,16 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
case LOK_CALLBACK_STATE_CHANGED:
{
// Compare the state name=value and overwrite earlier entries with same name.
- const auto pos = aCallbackData.getPayload().find('=');
- if (pos != std::string::npos)
+ const auto pos = aCallbackData.getPayload().indexOf('=');
+ if (pos != -1)
{
- const std::string name = aCallbackData.getPayload().substr(0, pos + 1);
+ const std::string_view name = aCallbackData.getPayload().subView(0, pos + 1);
// This is needed because otherwise it creates some problems when
// a save occurs while a cell is still edited in Calc.
if (name != ".uno:ModifiedStatus=")
{
removeAll(type, [&name] (const CallbackData& elemData) {
- return (elemData.getPayload().compare(0, name.size(), name) == 0);
+ return elemData.getPayload().startsWith(name);
}
);
}
@@ -1695,7 +1911,7 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
// remove only selection ranges and 'EMPTY' messages
// always send 'INPLACE' and 'INPLACE EXIT' messages
removeAll(type, [] (const CallbackData& elemData)
- { return (elemData.getPayload().find("INPLACE") == std::string::npos); });
+ { return (elemData.getPayload().indexOf("INPLACE") == -1); });
}
break;
}
@@ -1730,12 +1946,7 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData)
#endif
lock.unlock();
- if (!IsActive())
- {
- Start();
- }
- if (!m_TimeoutIdle.IsActive())
- m_TimeoutIdle.Start();
+ startTimer();
}
bool CallbackFlushHandler::processInvalidateTilesEvent(int type, CallbackData& aCallbackData)
@@ -1755,14 +1966,15 @@ bool CallbackFlushHandler::processInvalidateTilesEvent(int type, CallbackData& a
{
auto pos2 = toQueue2(pos);
const RectangleAndPart& rcOld = pos2->getRectangleAndPart();
- if (rcOld.isInfinite() && (rcOld.m_nPart == -1 || rcOld.m_nPart == rcNew.m_nPart))
+ if (rcOld.isInfinite() && (rcOld.m_nPart == -1 || rcOld.m_nPart == rcNew.m_nPart) &&
+ (rcOld.m_nMode == rcNew.m_nMode))
{
SAL_INFO("lok", "Skipping queue [" << type << "]: [" << aCallbackData.getPayload()
<< "] since all tiles need to be invalidated.");
return true;
}
- if (rcOld.m_nPart == -1 || rcOld.m_nPart == rcNew.m_nPart)
+ if ((rcOld.m_nPart == -1 || rcOld.m_nPart == rcNew.m_nPart) && (rcOld.m_nMode == rcNew.m_nMode))
{
// If fully overlapping.
if (rcOld.m_aRectangle.Contains(rcNew.m_aRectangle))
@@ -1780,7 +1992,8 @@ bool CallbackFlushHandler::processInvalidateTilesEvent(int type, CallbackData& a
<< "] so removing all with part " << rcNew.m_nPart << ".");
removeAll(LOK_CALLBACK_INVALIDATE_TILES, [&rcNew](const CallbackData& elemData) {
// Remove exiting if new is all-encompassing, or if of the same part.
- return (rcNew.m_nPart == -1 || rcNew.m_nPart == elemData.getRectangleAndPart().m_nPart);
+ return ((rcNew.m_nPart == -1 || rcNew.m_nPart == elemData.getRectangleAndPart().m_nPart)
+ && (rcNew.m_nMode == elemData.getRectangleAndPart().m_nMode));
});
}
else
@@ -1790,7 +2003,8 @@ bool CallbackFlushHandler::processInvalidateTilesEvent(int type, CallbackData& a
SAL_INFO("lok", "Have [" << type << "]: [" << aCallbackData.getPayload() << "] so merging overlapping.");
removeAll(LOK_CALLBACK_INVALIDATE_TILES,[&rcNew](const CallbackData& elemData) {
const RectangleAndPart& rcOld = elemData.getRectangleAndPart();
- if (rcNew.m_nPart != -1 && rcOld.m_nPart != -1 && rcOld.m_nPart != rcNew.m_nPart)
+ if (rcNew.m_nPart != -1 && rcOld.m_nPart != -1 &&
+ (rcOld.m_nPart != rcNew.m_nPart || rcOld.m_nMode != rcNew.m_nMode))
{
SAL_INFO("lok", "Nothing to merge between new: "
<< rcNew.toString() << ", and old: " << rcOld.toString());
@@ -1802,7 +2016,7 @@ bool CallbackFlushHandler::processInvalidateTilesEvent(int type, CallbackData& a
// Don't merge unless fully overlapped.
SAL_INFO("lok", "New " << rcNew.toString() << " has " << rcOld.toString()
<< "?");
- if (rcNew.m_aRectangle.Contains(rcOld.m_aRectangle))
+ if (rcNew.m_aRectangle.Contains(rcOld.m_aRectangle) && rcOld.m_nMode == rcNew.m_nMode)
{
SAL_INFO("lok", "New " << rcNew.toString() << " engulfs old "
<< rcOld.toString() << ".");
@@ -1814,7 +2028,7 @@ bool CallbackFlushHandler::processInvalidateTilesEvent(int type, CallbackData& a
// Don't merge unless fully overlapped.
SAL_INFO("lok", "Old " << rcOld.toString() << " has " << rcNew.toString()
<< "?");
- if (rcOld.m_aRectangle.Contains(rcNew.m_aRectangle))
+ if (rcOld.m_aRectangle.Contains(rcNew.m_aRectangle) && rcOld.m_nMode == rcNew.m_nMode)
{
SAL_INFO("lok", "New " << rcNew.toString() << " engulfs old "
<< rcOld.toString() << ".");
@@ -1825,7 +2039,7 @@ bool CallbackFlushHandler::processInvalidateTilesEvent(int type, CallbackData& a
{
const tools::Rectangle rcOverlap
= rcNew.m_aRectangle.GetIntersection(rcOld.m_aRectangle);
- const bool bOverlap = !rcOverlap.IsEmpty();
+ const bool bOverlap = !rcOverlap.IsEmpty() && rcOld.m_nMode == rcNew.m_nMode;
SAL_INFO("lok", "Merging " << rcNew.toString() << " & " << rcOld.toString()
<< " => " << rcOverlap.toString()
<< " Overlap: " << bOverlap);
@@ -1859,9 +2073,9 @@ bool CallbackFlushHandler::processInvalidateTilesEvent(int type, CallbackData& a
bool CallbackFlushHandler::processWindowEvent(int type, CallbackData& aCallbackData)
{
- const std::string& payload = aCallbackData.getPayload();
+ const OString& payload = aCallbackData.getPayload();
- boost::property_tree::ptree& aTree = aCallbackData.setJson(payload);
+ boost::property_tree::ptree& aTree = aCallbackData.setJson(std::string(payload));
const unsigned nLOKWindowId = aTree.get<unsigned>("id", 0);
const std::string aAction = aTree.get<std::string>("action", "");
if (aAction == "invalidate")
@@ -2000,7 +2214,7 @@ bool CallbackFlushHandler::processWindowEvent(int type, CallbackData& aCallbackD
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
if (!pWindow)
{
- gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found.";
+ SetLastExceptionMsg(u"Document doesn't support dialog rendering, or window not found."_ustr);
return false;
}
@@ -2037,7 +2251,7 @@ void CallbackFlushHandler::enqueueUpdatedTypes()
return;
assert(m_viewId >= 0);
SfxViewShell* viewShell = SfxViewShell::GetFirst( false,
- [this](const SfxViewShell* shell) { return shell->GetViewShellId().get() == m_viewId; } );
+ [this](const SfxViewShell& shell) { return shell.GetViewShellId().get() == m_viewId; } );
assert(viewShell != nullptr);
// First move data to local structures, so that callbacks don't possibly modify it.
@@ -2080,7 +2294,7 @@ void CallbackFlushHandler::enqueueUpdatedTypes()
{
assert(sourceViewId >= 0);
sourceViewShell = SfxViewShell::GetFirst( false,
- [sourceViewId](const SfxViewShell* shell) { return shell->GetViewShellId().get() == sourceViewId; } );
+ [sourceViewId](const SfxViewShell& shell) { return shell.GetViewShellId().get() == sourceViewId; } );
}
if(sourceViewShell == nullptr)
{
@@ -2095,11 +2309,15 @@ void CallbackFlushHandler::enqueueUpdatedTypes()
void CallbackFlushHandler::enqueueUpdatedType( int type, const SfxViewShell* viewShell, int viewId )
{
- bool ignore = false;
- OString payload = viewShell->getLOKPayload( type, viewId, &ignore );
- if(ignore)
+ if (type == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR)
+ {
+ if (const SfxViewShell* viewShell2 = LokStarMathHelper(viewShell).GetSmViewShell())
+ viewShell = viewShell2;
+ }
+ std::optional<OString> payload = viewShell->getLOKPayload( type, viewId );
+ if(!payload)
return; // No actual payload to send.
- CallbackData callbackData(payload.getStr(), viewId);
+ CallbackData callbackData(*payload, viewId);
m_queue1.emplace_back(type);
m_queue2.emplace_back(callbackData);
SAL_INFO("lok", "Queued updated [" << type << "]: [" << callbackData.getPayload()
@@ -2117,12 +2335,12 @@ void CallbackFlushHandler::Invoke()
// so it must be done before taking the mutex.
assert(m_viewId >= 0);
if(SfxViewShell* viewShell = SfxViewShell::GetFirst( false,
- [this](const SfxViewShell* shell) { return shell->GetViewShellId().get() == m_viewId; } ))
+ [this](const SfxViewShell& shell) { return shell.GetViewShellId().get() == m_viewId; } ))
{
viewShell->flushPendingLOKInvalidateTiles();
}
- std::scoped_lock<std::mutex> lock(m_mutex);
+ std::unique_lock<std::recursive_mutex> lock(m_mutex);
// Append messages for updated types, fetch them only now.
enqueueUpdatedTypes();
@@ -2141,13 +2359,13 @@ void CallbackFlushHandler::Invoke()
// common code-path for events on this view:
if (viewId == -1)
{
- size_t idx;
+ sal_Int32 idx;
// key-value pairs
if (type == LOK_CALLBACK_STATE_CHANGED &&
- (idx = payload.find('=')) != std::string::npos)
+ (idx = payload.indexOf('=')) != -1)
{
- std::string key = payload.substr(0, idx);
- std::string value = payload.substr(idx+1);
+ OString key = payload.copy(0, idx);
+ OString value = payload.copy(idx+1);
const auto stateIt = m_lastStateChange.find(key);
if (stateIt != m_lastStateChange.end())
{
@@ -2209,7 +2427,7 @@ void CallbackFlushHandler::Invoke()
}
}
- m_pCallback(type, payload.c_str(), m_pData);
+ m_pCallback(type, payload.getStr(), m_pData);
}
m_queue1.clear();
@@ -2218,6 +2436,14 @@ void CallbackFlushHandler::Invoke()
m_TimeoutIdle.Stop();
}
+void CallbackFlushHandler::startTimer()
+{
+ if (!IsActive())
+ Start();
+ if (!m_TimeoutIdle.IsActive())
+ m_TimeoutIdle.Start();
+}
+
bool CallbackFlushHandler::removeAll(int type)
{
bool bErased = false;
@@ -2311,6 +2537,22 @@ static bool lo_signDocument(LibreOfficeKit* pThis,
const unsigned char* pPrivateKeyBinary,
const int nPrivateKeyBinarySize);
+static char* lo_extractRequest(LibreOfficeKit* pThis,
+ const char* pFilePath);
+
+static void lo_trimMemory(LibreOfficeKit* pThis, int nTarget);
+
+static void*
+lo_startURP(LibreOfficeKit* pThis, void* pReceiveURPFromLOContext, void* pSendURPToLOContext,
+ int (*fnReceiveURPFromLO)(void* pContext, const signed char* pBuffer, int nLen),
+ int (*fnSendURPToLO)(void* pContext, signed char* pBuffer, int nLen));
+
+static void lo_stopURP(LibreOfficeKit* pThis, void* pSendURPToLOContext);
+
+static int lo_joinThreads(LibreOfficeKit* pThis);
+
+static void lo_setForkedChild(LibreOfficeKit* pThis, bool bIsChild);
+
static void lo_runLoop(LibreOfficeKit* pThis,
LibreOfficeKitPollCallback pPollCallback,
LibreOfficeKitWakeCallback pWakeCallback,
@@ -2322,6 +2564,8 @@ static void lo_sendDialogEvent(LibreOfficeKit* pThis,
static void lo_setOption(LibreOfficeKit* pThis, const char* pOption, const char* pValue);
+static void lo_dumpState(LibreOfficeKit* pThis, const char* pOptions, char** pState);
+
LibLibreOffice_Impl::LibLibreOffice_Impl()
: m_pOfficeClass( gOfficeClass.lock() )
, maThread(nullptr)
@@ -2348,6 +2592,13 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
m_pOfficeClass->runLoop = lo_runLoop;
m_pOfficeClass->sendDialogEvent = lo_sendDialogEvent;
m_pOfficeClass->setOption = lo_setOption;
+ m_pOfficeClass->dumpState = lo_dumpState;
+ m_pOfficeClass->extractRequest = lo_extractRequest;
+ m_pOfficeClass->trimMemory = lo_trimMemory;
+ m_pOfficeClass->startURP = lo_startURP;
+ m_pOfficeClass->stopURP = lo_stopURP;
+ m_pOfficeClass->joinThreads = lo_joinThreads;
+ m_pOfficeClass->setForkedChild = lo_setForkedChild;
gOfficeClass = m_pOfficeClass;
}
@@ -2362,41 +2613,6 @@ LibLibreOffice_Impl::~LibLibreOffice_Impl()
namespace
{
-#ifdef IOS
-void paintTileToCGContext(ITiledRenderable* pDocument,
- void* rCGContext, const Size nCanvasSize,
- const int nTilePosX, const int nTilePosY,
- const int nTileWidth, const int nTileHeight)
-{
- SystemGraphicsData aData;
- aData.rCGContext = reinterpret_cast<CGContextRef>(rCGContext);
-
- ScopedVclPtrInstance<VirtualDevice> pDevice(aData, Size(1, 1), DeviceFormat::DEFAULT);
- pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
- pDevice->SetOutputSizePixel(nCanvasSize);
- pDocument->paintTile(*pDevice, nCanvasSize.Width(), nCanvasSize.Height(),
- nTilePosX, nTilePosY, nTileWidth, nTileHeight);
-}
-
-void paintTileIOS(LibreOfficeKitDocument* pThis,
- unsigned char* pBuffer,
- const int nCanvasWidth, const int nCanvasHeight, const double fDPIScale,
- const int nTilePosX, const int nTilePosY,
- const int nTileWidth, const int nTileHeight)
-{
- CGContextRef pCGContext = CGBitmapContextCreate(pBuffer, nCanvasWidth, nCanvasHeight, 8,
- nCanvasWidth * 4, CGColorSpaceCreateDeviceRGB(),
- kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little);
-
- CGContextTranslateCTM(pCGContext, 0, nCanvasHeight);
- CGContextScaleCTM(pCGContext, fDPIScale, -fDPIScale);
-
- doc_paintTileToCGContext(pThis, (void*) pCGContext, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
-
- CGContextRelease(pCGContext);
-}
-#endif
-
void setLanguageAndLocale(OUString const & aLangISO)
{
SvtSysLocaleOptions aLocalOptions;
@@ -2410,7 +2626,7 @@ void setFormatSpecificFilterData(std::u16string_view sFormat, comphelper::Sequen
if (sFormat == u"pdf")
{
// always export bookmarks, which is needed for annotations
- rFilterDataMap["ExportBookmarks"] <<= true;
+ rFilterDataMap[u"ExportBookmarks"_ustr] <<= true;
}
}
@@ -2440,7 +2656,7 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
const OUString aURL(getAbsoluteURL(pURL));
if (aURL.isEmpty())
{
- pLib->maLastExceptionMsg = "Filename to load was not provided.";
+ pLib->maLastExceptionMsg = u"Filename to load was not provided."_ustr;
SAL_INFO("lok", "URL for load is empty");
return nullptr;
}
@@ -2449,7 +2665,7 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
if (!xContext.is())
{
- pLib->maLastExceptionMsg = "ComponentContext is not available";
+ pLib->maLastExceptionMsg = u"ComponentContext is not available"_ustr;
SAL_INFO("lok", "ComponentContext is not available");
return nullptr;
}
@@ -2458,7 +2674,7 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
if (!xComponentLoader.is())
{
- pLib->maLastExceptionMsg = "ComponentLoader is not available";
+ pLib->maLastExceptionMsg = u"ComponentLoader is not available"_ustr;
SAL_INFO("lok", "ComponentLoader is not available");
return nullptr;
}
@@ -2469,10 +2685,17 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
// not pass it as a parameter to the filter
OUString aOptions = getUString(pOptions);
const OUString aLanguage = extractParameter(aOptions, u"Language");
- bool isValidLangTag = LanguageTag::isValidBcp47(aLanguage, nullptr);
- if (!aLanguage.isEmpty() && isValidLangTag)
+ if (!aLanguage.isEmpty() && LanguageTag::isValidBcp47(aLanguage, nullptr))
{
+ static bool isLoading = true;
+ if (isLoading)
+ {
+ // Capture the language used to load the document.
+ SfxLokHelper::setLoadLanguage(aLanguage);
+ isLoading = false;
+ }
+
SfxLokHelper::setDefaultLanguage(aLanguage);
// Set the LOK language tag, used for dialog tunneling.
comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLanguage));
@@ -2486,6 +2709,27 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
SvNumberFormatter::resetTheCurrencyTable();
}
+ // Set the timezone, if not empty.
+ const OUString aTimezone = extractParameter(aOptions, u"Timezone");
+ if (!aTimezone.isEmpty())
+ {
+ SfxLokHelper::setDefaultTimezone(true, aTimezone);
+ }
+ else
+ {
+ // Default to the TZ envar, if set.
+ const char* tz = ::getenv("TZ");
+ if (tz)
+ {
+ SfxLokHelper::setDefaultTimezone(true,
+ OStringToOUString(tz, RTL_TEXTENCODING_UTF8));
+ }
+ else
+ {
+ SfxLokHelper::setDefaultTimezone(false, OUString());
+ }
+ }
+
const OUString aDeviceFormFactor = extractParameter(aOptions, u"DeviceFormFactor");
SfxLokHelper::setDeviceFormFactor(aDeviceFormFactor);
@@ -2495,10 +2739,8 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
Application::SetDialogCancelMode(DialogCancelMode::LOKSilent);
}
- const OUString sFilterOptions = aOptions;
-
rtl::Reference<LOKInteractionHandler> const pInteraction(
- new LOKInteractionHandler("load", pLib));
+ new LOKInteractionHandler("load"_ostr, pLib));
auto const pair(pLib->mInteractionMap.insert(std::make_pair(aURL.toUtf8(), pInteraction)));
comphelper::ScopeGuard const g([&] () {
if (pair.second)
@@ -2528,10 +2770,15 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
document::MacroExecMode::NEVER_EXECUTE;
#endif
+ // set AsTemplate explicitly false to be able to load template files
+ // as regular files, otherwise we cannot save them; it will try
+ // to bring saveas dialog which cannot work with LOK case
uno::Sequence<css::beans::PropertyValue> aFilterOptions{
- comphelper::makePropertyValue("FilterOptions", sFilterOptions),
- comphelper::makePropertyValue("InteractionHandler", xInteraction),
- comphelper::makePropertyValue("MacroExecutionMode", nMacroExecMode)
+ comphelper::makePropertyValue(u"FilterOptions"_ustr, aOptions),
+ comphelper::makePropertyValue(u"InteractionHandler"_ustr, xInteraction),
+ comphelper::makePropertyValue(u"MacroExecutionMode"_ustr, nMacroExecMode),
+ comphelper::makePropertyValue(u"AsTemplate"_ustr, false),
+ comphelper::makePropertyValue(u"Silent"_ustr, !aBatch.isEmpty())
};
/* TODO
@@ -2540,17 +2787,19 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
aFilterOptions[3].Value <<= nUpdateDoc;
*/
+ OutputDevice::StartTrackingFontMappingUse();
+
const int nThisDocumentId = nDocumentIdCounter++;
SfxViewShell::SetCurrentDocId(ViewShellDocId(nThisDocumentId));
uno::Reference<lang::XComponent> xComponent = xComponentLoader->loadComponentFromURL(
- aURL, "_blank", 0,
+ aURL, u"_blank"_ustr, 0,
aFilterOptions);
assert(!xComponent.is() || pair.second); // concurrent loading of same URL ought to fail
if (!xComponent.is())
{
- pLib->maLastExceptionMsg = "loadComponentFromURL returned an empty reference";
+ pLib->maLastExceptionMsg = u"loadComponentFromURL returned an empty reference"_ustr;
SAL_INFO("lok", "Document can't be loaded - " << pLib->maLastExceptionMsg);
return nullptr;
}
@@ -2563,6 +2812,102 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
int nState = doc_getSignatureState(pDocument);
pLib->mpCallback(LOK_CALLBACK_SIGNATURE_STATUS, OString::number(nState).getStr(), pLib->mpCallbackData);
}
+
+ auto aFontMappingUseData = OutputDevice::FinishTrackingFontMappingUse();
+
+ if (aFontMappingUseData.size() > 0)
+ {
+ SAL_INFO("lok.fontsubst", "================ Original substitutions:");
+ for (const auto &i : aFontMappingUseData)
+ {
+ SAL_INFO("lok.fontsubst", i.mOriginalFont);
+ for (const auto &j : i.mUsedFonts)
+ SAL_INFO("lok.fontsubst", " " << j);
+ }
+ }
+
+ // Filter out font substitutions that actually aren't any substitutions, like "Liberation
+ // Serif" -> "Liberation Serif/Regular". If even one of the "substitutions" of a font is to
+ // the same font, don't count that as a missing font.
+
+ std::erase_if
+ (aFontMappingUseData,
+ [](OutputDevice::FontMappingUseItem x)
+ {
+ // If the original font had an empty style and one of its
+ // replacement fonts has the same family name, we assume the font is
+ // present. The root problem here is that the code that collects
+ // font substitutions tends to get just empty styles for the font
+ // that is being substituted, as vcl::Font::GetStyleName() tends to
+ // return an empty string. (Italicness is instead indicated by what
+ // vcl::Font::GetItalic() returns and boldness by what
+ // vcl::Font::GetWeight() returns.)
+
+ if (x.mOriginalFont.indexOf('/') == -1)
+ for (const auto &j : x.mUsedFonts)
+ if (j == x.mOriginalFont ||
+ j.startsWith(Concat2View(x.mOriginalFont + "/")))
+ return true;
+
+ return false;
+ });
+
+ // Filter out substitutions where a proprietary font has been substituted by a
+ // metric-compatible one. Obviously this is just a heuristic and implemented only for some
+ // well-known cases.
+
+ std::erase_if
+ (aFontMappingUseData,
+ [](OutputDevice::FontMappingUseItem x)
+ {
+ // Again, handle only cases where the original font does not include
+ // a style. Unclear whether there ever will be a style part included
+ // in the mOriginalFont.
+
+ if (x.mOriginalFont.indexOf('/') == -1)
+ for (const auto &j : x.mUsedFonts)
+ if ((x.mOriginalFont == "Arial" &&
+ j.startsWith("Liberation Sans/")) ||
+ (x.mOriginalFont == "Times New Roman" &&
+ j.startsWith("Liberation Serif/")) ||
+ (x.mOriginalFont == "Courier New" &&
+ j.startsWith("Liberation Mono/")) ||
+ (x.mOriginalFont == "Arial Narrow" &&
+ j.startsWith("Liberation Sans Narrow/")) ||
+ (x.mOriginalFont == "Cambria" &&
+ j.startsWith("Caladea/")) ||
+ (x.mOriginalFont == "Calibri" &&
+ j.startsWith("Carlito/")) ||
+ (x.mOriginalFont == "Palatino Linotype" &&
+ j.startsWith("P052/")) ||
+ // Perhaps a risky heuristic? If some glyphs from Symbol
+ // have been mapped to ones in OpenSymbol, don't warn
+ // that Symbol is missing.
+ (x.mOriginalFont == "Symbol" &&
+ j.startsWith("OpenSymbol/")))
+ {
+ return true;
+ }
+
+ return false;
+ });
+
+ if (aFontMappingUseData.size() > 0)
+ {
+ SAL_INFO("lok.fontsubst", "================ Pruned substitutions:");
+ for (const auto &i : aFontMappingUseData)
+ {
+ SAL_INFO("lok.fontsubst", i.mOriginalFont);
+ for (const auto &j : i.mUsedFonts)
+ SAL_INFO("lok.fontsubst", " " << j);
+ }
+ }
+
+ for (std::size_t i = 0; i < aFontMappingUseData.size(); ++i)
+ {
+ pDocument->maFontsMissing.insert(aFontMappingUseData[i].mOriginalFont);
+ }
+
return pDocument;
}
catch (const uno::Exception& exception)
@@ -2586,14 +2931,14 @@ static int lo_runMacro(LibreOfficeKit* pThis, const char *pURL)
OUString sURL( pURL, strlen(pURL), RTL_TEXTENCODING_UTF8 );
if (sURL.isEmpty())
{
- pLib->maLastExceptionMsg = "Macro to run was not provided.";
+ pLib->maLastExceptionMsg = u"Macro to run was not provided."_ustr;
SAL_INFO("lok", "Macro URL is empty");
return false;
}
if (!sURL.startsWith("macro://"))
{
- pLib->maLastExceptionMsg = "This doesn't look like macro URL";
+ pLib->maLastExceptionMsg = u"This doesn't look like macro URL"_ustr;
SAL_INFO("lok", "Macro URL is invalid");
return false;
}
@@ -2602,7 +2947,7 @@ static int lo_runMacro(LibreOfficeKit* pThis, const char *pURL)
if (!xContext.is())
{
- pLib->maLastExceptionMsg = "ComponentContext is not available";
+ pLib->maLastExceptionMsg = u"ComponentContext is not available"_ustr;
SAL_INFO("lok", "ComponentContext is not available");
return false;
}
@@ -2619,7 +2964,7 @@ static int lo_runMacro(LibreOfficeKit* pThis, const char *pURL)
if (!xComponentLoader.is())
{
- pLib->maLastExceptionMsg = "ComponentLoader is not available";
+ pLib->maLastExceptionMsg = u"ComponentLoader is not available"_ustr;
SAL_INFO("lok", "ComponentLoader is not available");
return false;
}
@@ -2631,12 +2976,12 @@ static int lo_runMacro(LibreOfficeKit* pThis, const char *pURL)
uno::Reference<frame::XDispatchProvider> xDP;
xSFactory.set(xFactory, uno::UNO_QUERY_THROW);
- xDP.set( xSFactory->createInstance("com.sun.star.comp.sfx2.SfxMacroLoader"), uno::UNO_QUERY );
+ xDP.set( xSFactory->createInstance(u"com.sun.star.comp.sfx2.SfxMacroLoader"_ustr), uno::UNO_QUERY );
uno::Reference<frame::XDispatch> xD = xDP->queryDispatch( aURL, OUString(), 0);
if (!xD.is())
{
- pLib->maLastExceptionMsg = "Macro loader is not available";
+ pLib->maLastExceptionMsg = u"Macro loader is not available"_ustr;
SAL_INFO("lok", "Macro loader is not available");
return false;
}
@@ -2683,7 +3028,7 @@ static bool lo_signDocument(LibreOfficeKit* /*pThis*/,
std::string aCertificateBase64String = extractCertificate(aCertificateString);
if (!aCertificateBase64String.empty())
{
- OUString aBase64OUString = OUString::createFromAscii(aCertificateBase64String.c_str());
+ OUString aBase64OUString = OUString::createFromAscii(aCertificateBase64String);
comphelper::Base64::decode(aCertificateSequence, aBase64OUString);
}
else
@@ -2697,7 +3042,7 @@ static bool lo_signDocument(LibreOfficeKit* /*pThis*/,
std::string aPrivateKeyBase64String = extractPrivateKey(aPrivateKeyString);
if (!aPrivateKeyBase64String.empty())
{
- OUString aBase64OUString = OUString::createFromAscii(aPrivateKeyBase64String.c_str());
+ OUString aBase64OUString = OUString::createFromAscii(aPrivateKeyBase64String);
comphelper::Base64::decode(aPrivateKeySequence, aBase64OUString);
}
else
@@ -2729,6 +3074,288 @@ static bool lo_signDocument(LibreOfficeKit* /*pThis*/,
return true;
}
+
+static char* lo_extractRequest(LibreOfficeKit* /*pThis*/, const char* pFilePath)
+{
+ uno::Reference<frame::XDesktop2> xComponentLoader = frame::Desktop::create(xContext);
+ uno::Reference< css::lang::XComponent > xComp;
+ OUString aURL(getAbsoluteURL(pFilePath));
+ if (!aURL.isEmpty())
+ {
+ if (xComponentLoader.is())
+ {
+ try
+ {
+ uno::Sequence<css::beans::PropertyValue> aFilterOptions(comphelper::InitPropertySequence(
+ {
+ {u"Hidden"_ustr, css::uno::Any(true)},
+ {u"ReadOnly"_ustr, css::uno::Any(true)}
+ }));
+ xComp = xComponentLoader->loadComponentFromURL( aURL, u"_blank"_ustr, 0, aFilterOptions );
+ }
+ catch ( const lang::IllegalArgumentException& ex )
+ {
+ SAL_WARN("lok", "lo_extractRequest: IllegalArgumentException: " << ex.Message);
+ }
+ catch (...)
+ {
+ SAL_WARN("lok", "lo_extractRequest: Exception on loadComponentFromURL, url= " << aURL);
+ }
+
+ if (xComp.is())
+ {
+ uno::Reference< document::XLinkTargetSupplier > xLTS( xComp, uno::UNO_QUERY );
+
+ if( xLTS.is() )
+ {
+ tools::JsonWriter aJson;
+ {
+ auto aNode = aJson.startNode("Targets");
+ extractLinks(xLTS->getLinks(), false, aJson);
+ }
+ return convertOString(aJson.finishAndGetAsOString());
+ }
+ xComp->dispose();
+ }
+ }
+ }
+ return strdup("{ }");
+}
+
+static void lo_trimMemory(LibreOfficeKit* /* pThis */, int nTarget)
+{
+ vcl::lok::trimMemory(nTarget);
+
+ if (nTarget > 2000)
+ {
+ SolarMutexGuard aGuard;
+
+ // Flush all buffered VOC primitives from the pages.
+ SfxViewShell* pViewShell = SfxViewShell::Current();
+ if (pViewShell)
+ {
+ const SdrView* pView = pViewShell->GetDrawView();
+ if (pView)
+ {
+ SdrPageView* pPageView = pView->GetSdrPageView();
+ if (pPageView)
+ {
+ SdrPage* pCurPage = pPageView->GetPage();
+ if (pCurPage)
+ {
+ SdrModel& sdrModel = pCurPage->getSdrModelFromSdrPage();
+ for (sal_uInt16 i = 0; i < sdrModel.GetPageCount(); ++i)
+ {
+ SdrPage* pPage = sdrModel.GetPage(i);
+ if (pPage)
+ pPage->GetViewContact().flushViewObjectContacts();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (nTarget > 1000)
+ {
+#ifdef HAVE_MALLOC_TRIM
+ malloc_trim(0);
+#endif
+ }
+}
+
+namespace
+{
+class FunctionBasedURPInstanceProvider
+ : public ::cppu::WeakImplHelper<css::bridge::XInstanceProvider>
+{
+private:
+ css::uno::Reference<css::uno::XComponentContext> m_rContext;
+
+public:
+ FunctionBasedURPInstanceProvider(
+ const css::uno::Reference<css::uno::XComponentContext>& rxContext);
+
+ // XInstanceProvider
+ virtual css::uno::Reference<css::uno::XInterface>
+ SAL_CALL getInstance(const OUString& aName) override;
+};
+
+// InstanceProvider
+FunctionBasedURPInstanceProvider::FunctionBasedURPInstanceProvider(
+ const Reference<XComponentContext>& rxContext)
+ : m_rContext(rxContext)
+{
+}
+
+Reference<XInterface> FunctionBasedURPInstanceProvider::getInstance(const OUString& aName)
+{
+ Reference<XInterface> rInstance;
+
+ if (aName == "StarOffice.ServiceManager")
+ {
+ rInstance.set(m_rContext->getServiceManager());
+ }
+ else if (aName == "StarOffice.ComponentContext")
+ {
+ rInstance = m_rContext;
+ }
+ else if (aName == "StarOffice.NamingService")
+ {
+ Reference<XNamingService> rNamingService(
+ m_rContext->getServiceManager()->createInstanceWithContext(
+ u"com.sun.star.uno.NamingService"_ustr, m_rContext),
+ UNO_QUERY);
+ if (rNamingService.is())
+ {
+ rNamingService->registerObject(u"StarOffice.ServiceManager"_ustr,
+ m_rContext->getServiceManager());
+ rNamingService->registerObject(u"StarOffice.ComponentContext"_ustr, m_rContext);
+ rInstance = rNamingService;
+ }
+ }
+ return rInstance;
+}
+
+class FunctionBasedURPConnection : public cppu::WeakImplHelper<css::connection::XConnection>
+{
+public:
+ explicit FunctionBasedURPConnection(void*, int (*)(void* pContext, const signed char* pBuffer, int nLen),
+ void*, int (*)(void* pContext, signed char* pBuffer, int nLen));
+ ~FunctionBasedURPConnection();
+
+ // These overridden member functions use "read" and "write" from the point of view of LO,
+ // i.e. the opposite to how startURP() uses them.
+ virtual sal_Int32 SAL_CALL read(Sequence<sal_Int8>& rReadBytes,
+ sal_Int32 nBytesToRead) override;
+ virtual void SAL_CALL write(const Sequence<sal_Int8>& aData) override;
+ virtual void SAL_CALL flush() override;
+ virtual void SAL_CALL close() override;
+ virtual OUString SAL_CALL getDescription() override;
+ void setBridge(const Reference<XBridge>&);
+ void* getContext();
+ inline static int g_connectionCount = 0;
+
+private:
+ void* m_pRecieveFromLOContext;
+ void* m_pSendURPToLOContext;
+ int (*m_fnReceiveURPFromLO)(void* pContext, const signed char* pBuffer, int nLen);
+ int (*m_fnSendURPToLO)(void* pContext, signed char* pBuffer, int nLen);
+ Reference<XBridge> m_URPBridge;
+};
+
+FunctionBasedURPConnection::FunctionBasedURPConnection(
+ void* pRecieveFromLOContext,
+ int (*fnReceiveURPFromLO)(void* pContext, const signed char* pBuffer, int nLen),
+ void* pSendURPToLOContext,
+ int (*fnSendURPToLO)(void* pContext, signed char* pBuffer, int nLen))
+ : m_pRecieveFromLOContext(pRecieveFromLOContext)
+ , m_pSendURPToLOContext(pSendURPToLOContext)
+ , m_fnReceiveURPFromLO(fnReceiveURPFromLO)
+ , m_fnSendURPToLO(fnSendURPToLO)
+{
+ g_connectionCount++;
+}
+
+FunctionBasedURPConnection::~FunctionBasedURPConnection()
+{
+ Reference<XComponent> xComp(m_URPBridge, UNO_QUERY_THROW);
+ xComp->dispose(); // TODO: check this doesn't deadlock
+}
+
+void* FunctionBasedURPConnection::getContext() { return this; }
+
+sal_Int32 FunctionBasedURPConnection::read(Sequence<sal_Int8>& rReadBytes, sal_Int32 nBytesToRead)
+{
+ if (nBytesToRead < 0)
+ return 0;
+
+ if (rReadBytes.getLength() != nBytesToRead)
+ rReadBytes.realloc(nBytesToRead);
+
+ // As with osl::StreamPipe, we must always read nBytesToRead...
+ return m_fnSendURPToLO(m_pSendURPToLOContext, rReadBytes.getArray(), nBytesToRead);
+}
+
+void FunctionBasedURPConnection::write(const Sequence<sal_Int8>& rData)
+{
+ m_fnReceiveURPFromLO(m_pRecieveFromLOContext, rData.getConstArray(), rData.getLength());
+}
+
+void FunctionBasedURPConnection::flush() {}
+
+void FunctionBasedURPConnection::close()
+{
+ SAL_INFO("lok.urp", "Requested to close FunctionBasedURPConnection");
+}
+
+OUString FunctionBasedURPConnection::getDescription() { return ""; }
+
+void FunctionBasedURPConnection::setBridge(const Reference<XBridge>& xBridge) { m_URPBridge = xBridge; }
+}
+
+static void*
+lo_startURP(LibreOfficeKit* /* pThis */, void* pRecieveFromLOContext, void* pSendToLOContext,
+ int (*fnReceiveURPFromLO)(void* pContext, const signed char* pBuffer, int nLen),
+ int (*fnSendURPToLO)(void* pContext, signed char* pBuffer, int nLen))
+{
+ // Here we will roughly do what desktop LO does when one passes a command-line switch like
+ // --accept=socket,port=nnnn;urp;StarOffice.ServiceManager. Except that no listening socket will
+ // be created. The communication to the URP will be through the nReceiveURPFromLO and nSendURPToLO
+ // functions.
+
+ rtl::Reference<FunctionBasedURPConnection> connection(
+ new FunctionBasedURPConnection(pRecieveFromLOContext, fnReceiveURPFromLO,
+ pSendToLOContext, fnSendURPToLO));
+
+ Reference<XBridgeFactory> xBridgeFactory = css::bridge::BridgeFactory::create(xContext);
+
+ Reference<XInstanceProvider> xInstanceProvider(new FunctionBasedURPInstanceProvider(xContext));
+
+ Reference<XBridge> xBridge(xBridgeFactory->createBridge(
+ "functionurp" + OUString::number(FunctionBasedURPConnection::g_connectionCount), u"urp"_ustr,
+ connection, xInstanceProvider));
+
+ connection->setBridge(std::move(xBridge));
+
+ return connection->getContext();
+}
+
+/**
+ * Stop a function based URP connection that you started with lo_startURP above
+ *
+ * @param pSendToLOContext a pointer to the context returned by lo_startURP */
+static void lo_stopURP(LibreOfficeKit* /* pThis */,
+ void* pFunctionBasedURPConnection/* FunctionBasedURPConnection* */)
+{
+ static_cast<FunctionBasedURPConnection*>(pFunctionBasedURPConnection)->close();
+}
+
+
+static int lo_joinThreads(LibreOfficeKit* /* pThis */)
+{
+ comphelper::ThreadPool &pool = comphelper::ThreadPool::getSharedOptimalPool();
+ pool.joinThreadsIfIdle();
+
+// if (comphelper::getWorkerCount() > 0)
+// return 0;
+
+ // Grammar checker thread
+ css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLangSrv =
+ css::linguistic2::LinguServiceManager::create(xContext);
+
+ auto joinable = dynamic_cast<comphelper::LibreOfficeKit::ThreadJoinable *>(xLangSrv.get());
+ if (joinable && !joinable->joinThreads())
+ return 0;
+
+ return 1;
+}
+
+static void lo_setForkedChild(LibreOfficeKit* /* pThis */, bool bIsChild)
+{
+ comphelper::LibreOfficeKit::setForkedChild(bIsChild);
+}
+
static void lo_registerCallback (LibreOfficeKit* pThis,
LibreOfficeKitCallback pCallback,
void* pData)
@@ -2745,6 +3372,19 @@ static void lo_registerCallback (LibreOfficeKit* pThis,
pApp->m_pCallbackData = pLib->mpCallbackData = pData;
}
+static SfxObjectShell* getSfxObjectShell(LibreOfficeKitDocument* pThis)
+{
+ LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+ if (!pDocument)
+ return nullptr;
+
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(pDocument->mxComponent.get());
+ if (!pBaseModel)
+ return nullptr;
+
+ return pBaseModel->GetObjectShell();
+}
+
static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const char* pFormat, const char* pFilterOptions)
{
comphelper::ProfileZone aZone("doc_saveAs");
@@ -2761,14 +3401,14 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
if (aURL.isEmpty())
{
- SetLastExceptionMsg("Filename to save to was not provided.");
+ SetLastExceptionMsg(u"Filename to save to was not provided."_ustr);
SAL_INFO("lok", "URL for save is empty");
return false;
}
try
{
- const ExtensionMap* pMap;
+ std::span<const ExtensionMap> pMap;
switch (doc_getDocumentType(pThis))
{
@@ -2800,23 +3440,23 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
}
else
{
- SetLastExceptionMsg("input filename without a suffix");
+ SetLastExceptionMsg("input URL '" + aURL + "' lacks a suffix");
return false;
}
}
OUString aFilterName;
- for (sal_Int32 i = 0; pMap[i].extn; ++i)
+ for (const auto& item : pMap)
{
- if (sFormat.equalsIgnoreAsciiCaseAscii(pMap[i].extn))
+ if (sFormat.equalsIgnoreAsciiCaseAscii(item.extn))
{
- aFilterName = getUString(pMap[i].filterName);
+ aFilterName = item.filterName;
break;
}
}
if (aFilterName.isEmpty())
{
- SetLastExceptionMsg("no output filter found for provided suffix");
+ SetLastExceptionMsg(u"no output filter found for provided suffix"_ustr);
return false;
}
@@ -2824,7 +3464,8 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
// Check if watermark for pdf is passed by filteroptions...
// It is not a real filter option so it must be filtered out.
- OUString watermarkText, sFullSheetPreview;
+ OUString watermarkText;
+ std::u16string_view sFullSheetPreview;
int aIndex = -1;
if ((aIndex = aFilterOptions.indexOf(",Watermark=")) >= 0)
{
@@ -2840,7 +3481,24 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
aFilterOptions = OUString::Concat(aFilterOptions.subView(0, aIndex)) + aFilterOptions.subView(bIndex+16);
}
- bool bFullSheetPreview = sFullSheetPreview == "true";
+ bool bFullSheetPreview = sFullSheetPreview == u"true";
+
+ OUString filePassword;
+ if ((aIndex = aFilterOptions.indexOf(",Password=")) >= 0)
+ {
+ int bIndex = aFilterOptions.indexOf("PASSWORDEND");
+ filePassword = aFilterOptions.subView(aIndex + 10, bIndex - (aIndex + 10));
+ aFilterOptions = OUString::Concat(aFilterOptions.subView(0, aIndex))
+ + aFilterOptions.subView(bIndex + 11);
+ }
+ OUString filePasswordToModify;
+ if ((aIndex = aFilterOptions.indexOf(",PasswordToModify=")) >= 0)
+ {
+ int bIndex = aFilterOptions.indexOf("PASSWORDTOMODIFYEND");
+ filePassword = aFilterOptions.subView(aIndex + 18, bIndex - (aIndex + 18));
+ aFilterOptions = OUString::Concat(aFilterOptions.subView(0, aIndex))
+ + aFilterOptions.subView(bIndex + 19);
+ }
// Select a pdf version if specified a valid one. If not specified then ignore.
// If invalid then fail.
@@ -2848,23 +3506,22 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
if ((aIndex = aFilterOptions.indexOf(",PDFVer=")) >= 0)
{
int bIndex = aFilterOptions.indexOf("PDFVEREND");
- OUString sPdfVer;
- sPdfVer = aFilterOptions.subView(aIndex+8, bIndex-(aIndex+8));
+ std::u16string_view sPdfVer = aFilterOptions.subView(aIndex+8, bIndex-(aIndex+8));
aFilterOptions = OUString::Concat(aFilterOptions.subView(0, aIndex)) + aFilterOptions.subView(bIndex+9);
- if (sPdfVer.equalsIgnoreAsciiCase("PDF/A-1b"))
+ if (o3tl::equalsIgnoreAsciiCase(sPdfVer, u"PDF/A-1b"))
pdfVer = 1;
- else if (sPdfVer.equalsIgnoreAsciiCase("PDF/A-2b"))
+ else if (o3tl::equalsIgnoreAsciiCase(sPdfVer, u"PDF/A-2b"))
pdfVer = 2;
- else if (sPdfVer.equalsIgnoreAsciiCase("PDF/A-3b"))
+ else if (o3tl::equalsIgnoreAsciiCase(sPdfVer, u"PDF/A-3b"))
pdfVer = 3;
- else if (sPdfVer.equalsIgnoreAsciiCase("PDF-1.5"))
+ else if (o3tl::equalsIgnoreAsciiCase(sPdfVer, u"PDF-1.5"))
pdfVer = 15;
- else if (sPdfVer.equalsIgnoreAsciiCase("PDF-1.6"))
+ else if (o3tl::equalsIgnoreAsciiCase(sPdfVer, u"PDF-1.6"))
pdfVer = 16;
else
{
- SetLastExceptionMsg("wrong PDF version");
+ SetLastExceptionMsg(u"wrong PDF version"_ustr);
return false;
}
}
@@ -2877,19 +3534,31 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
const uno::Sequence<OUString> aOptionSeq = comphelper::string::convertCommaSeparated(aFilterOptions);
std::vector<OUString> aFilteredOptionVec;
bool bTakeOwnership = false;
+ bool bCreateFromTemplate = false;
MediaDescriptor aSaveMediaDescriptor;
for (const auto& rOption : aOptionSeq)
{
if (rOption == "TakeOwnership")
bTakeOwnership = true;
else if (rOption == "NoFileSync")
- aSaveMediaDescriptor["NoFileSync"] <<= true;
+ aSaveMediaDescriptor[u"NoFileSync"_ustr] <<= true;
+ else if (rOption == "FromTemplate")
+ bCreateFromTemplate = true;
else
aFilteredOptionVec.push_back(rOption);
}
- aSaveMediaDescriptor["Overwrite"] <<= true;
- aSaveMediaDescriptor["FilterName"] <<= aFilterName;
+ if (bCreateFromTemplate && bTakeOwnership)
+ {
+ if (SfxObjectShell* pObjectShell = getSfxObjectShell(pThis))
+ {
+ DateTime now( ::DateTime::SYSTEM );
+ pObjectShell->getDocProperties()->setCreationDate(now.GetUNODateTime());
+ }
+ }
+
+ aSaveMediaDescriptor[u"Overwrite"_ustr] <<= true;
+ aSaveMediaDescriptor[u"FilterName"_ustr] <<= aFilterName;
auto aFilteredOptionSeq = comphelper::containerToSequence<OUString>(aFilteredOptionVec);
aFilterOptions = comphelper::string::convertCommaSeparated(aFilteredOptionSeq);
@@ -2897,28 +3566,37 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
comphelper::SequenceAsHashMap aFilterDataMap;
- setFormatSpecificFilterData(sFormat, aFilterDataMap);
+ // If filter options is JSON string, then make sure aFilterDataMap stays empty, otherwise we
+ // would ignore the filter options.
+ if (!aFilterOptions.startsWith("{"))
+ {
+ setFormatSpecificFilterData(sFormat, aFilterDataMap);
+ }
if (!watermarkText.isEmpty())
- aFilterDataMap["TiledWatermark"] <<= watermarkText;
+ aFilterDataMap[u"TiledWatermark"_ustr] <<= watermarkText;
if (bFullSheetPreview)
- aFilterDataMap["SinglePageSheets"] <<= true;
+ aFilterDataMap[u"SinglePageSheets"_ustr] <<= true;
if (pdfVer)
- aFilterDataMap["SelectPdfVersion"] <<= pdfVer;
+ aFilterDataMap[u"SelectPdfVersion"_ustr] <<= pdfVer;
if (!aFilterDataMap.empty())
{
- aSaveMediaDescriptor["FilterData"] <<= aFilterDataMap.getAsConstPropertyValueList();
+ aSaveMediaDescriptor[u"FilterData"_ustr] <<= aFilterDataMap.getAsConstPropertyValueList();
}
+ if (!filePassword.isEmpty())
+ aSaveMediaDescriptor[u"Password"_ustr] <<= filePassword;
+ if (!filePasswordToModify.isEmpty())
+ aSaveMediaDescriptor[u"PasswordToModify"_ustr] <<= filePasswordToModify;
// add interaction handler too
if (gImpl)
{
// gImpl does not have to exist when running from a unit test
rtl::Reference<LOKInteractionHandler> const pInteraction(
- new LOKInteractionHandler("saveas", gImpl, pDocument));
+ new LOKInteractionHandler("saveas"_ostr, gImpl, pDocument));
uno::Reference<task::XInteractionHandler2> const xInteraction(pInteraction);
aSaveMediaDescriptor[MediaDescriptor::PROP_INTERACTIONHANDLER] <<= xInteraction;
@@ -2950,200 +3628,231 @@ static void doc_iniUnoCommands ()
SolarMutexGuard aGuard;
SetLastExceptionMsg();
- OUString sUnoCommands[] =
- {
- OUString(".uno:AlignLeft"),
- OUString(".uno:AlignHorizontalCenter"),
- OUString(".uno:AlignRight"),
- OUString(".uno:BackColor"),
- OUString(".uno:BackgroundColor"),
- OUString(".uno:TableCellBackgroundColor"),
- OUString(".uno:Bold"),
- OUString(".uno:CenterPara"),
- OUString(".uno:CharBackColor"),
- OUString(".uno:CharBackgroundExt"),
- OUString(".uno:CharFontName"),
- OUString(".uno:Color"),
- OUString(".uno:ControlCodes"),
- OUString(".uno:DecrementIndent"),
- OUString(".uno:DefaultBullet"),
- OUString(".uno:DefaultNumbering"),
- OUString(".uno:FontColor"),
- OUString(".uno:FontHeight"),
- OUString(".uno:IncrementIndent"),
- OUString(".uno:Italic"),
- OUString(".uno:JustifyPara"),
- OUString(".uno:JumpToMark"),
- OUString(".uno:OutlineFont"),
- OUString(".uno:LeftPara"),
- OUString(".uno:LanguageStatus"),
- OUString(".uno:RightPara"),
- OUString(".uno:Shadowed"),
- OUString(".uno:SubScript"),
- OUString(".uno:SuperScript"),
- OUString(".uno:Strikeout"),
- OUString(".uno:StyleApply"),
- OUString(".uno:Underline"),
- OUString(".uno:ModifiedStatus"),
- OUString(".uno:Undo"),
- OUString(".uno:Redo"),
- OUString(".uno:InsertPage"),
- OUString(".uno:DeletePage"),
- OUString(".uno:DuplicatePage"),
- OUString(".uno:InsertSlide"),
- OUString(".uno:DeleteSlide"),
- OUString(".uno:DuplicateSlide"),
- OUString(".uno:Cut"),
- OUString(".uno:Copy"),
- OUString(".uno:Paste"),
- OUString(".uno:SelectAll"),
- OUString(".uno:ReplyComment"),
- OUString(".uno:ResolveComment"),
- OUString(".uno:ResolveCommentThread"),
- OUString(".uno:InsertRowsBefore"),
- OUString(".uno:InsertRowsAfter"),
- OUString(".uno:InsertColumnsBefore"),
- OUString(".uno:InsertColumnsAfter"),
- OUString(".uno:DeleteRows"),
- OUString(".uno:DeleteColumns"),
- OUString(".uno:DeleteTable"),
- OUString(".uno:SelectTable"),
- OUString(".uno:EntireRow"),
- OUString(".uno:EntireColumn"),
- OUString(".uno:EntireCell"),
- OUString(".uno:AssignLayout"),
- OUString(".uno:StatusDocPos"),
- OUString(".uno:RowColSelCount"),
- OUString(".uno:StatusPageStyle"),
- OUString(".uno:InsertMode"),
- OUString(".uno:SpellOnline"),
- OUString(".uno:StatusSelectionMode"),
- OUString(".uno:StateTableCell"),
- OUString(".uno:StatusBarFunc"),
- OUString(".uno:StatePageNumber"),
- OUString(".uno:StateWordCount"),
- OUString(".uno:SelectionMode"),
- OUString(".uno:PageStatus"),
- OUString(".uno:LayoutStatus"),
- OUString(".uno:Scale"),
- OUString(".uno:Context"),
- OUString(".uno:WrapText"),
- OUString(".uno:ToggleMergeCells"),
- OUString(".uno:NumberFormatCurrency"),
- OUString(".uno:NumberFormatPercent"),
- OUString(".uno:NumberFormatDecimal"),
- OUString(".uno:NumberFormatDate"),
- OUString(".uno:FrameLineColor"),
- OUString(".uno:SortAscending"),
- OUString(".uno:SortDescending"),
- OUString(".uno:TrackChanges"),
- OUString(".uno:ShowTrackedChanges"),
- OUString(".uno:NextTrackedChange"),
- OUString(".uno:PreviousTrackedChange"),
- OUString(".uno:AcceptAllTrackedChanges"),
- OUString(".uno:RejectAllTrackedChanges"),
- OUString(".uno:TableDialog"),
- OUString(".uno:FormatCellDialog"),
- OUString(".uno:FontDialog"),
- OUString(".uno:ParagraphDialog"),
- OUString(".uno:OutlineBullet"),
- OUString(".uno:InsertIndexesEntry"),
- OUString(".uno:DocumentRepair"),
- OUString(".uno:TransformDialog"),
- OUString(".uno:InsertPageHeader"),
- OUString(".uno:InsertPageFooter"),
- OUString(".uno:OnlineAutoFormat"),
- OUString(".uno:InsertObjectChart"),
- OUString(".uno:InsertSection"),
- OUString(".uno:InsertAnnotation"),
- OUString(".uno:DeleteAnnotation"),
- OUString(".uno:InsertPagebreak"),
- OUString(".uno:InsertColumnBreak"),
- OUString(".uno:HyperlinkDialog"),
- OUString(".uno:InsertSymbol"),
- OUString(".uno:EditRegion"),
- OUString(".uno:ThesaurusDialog"),
- OUString(".uno:FormatArea"),
- OUString(".uno:FormatLine"),
- OUString(".uno:FormatColumns"),
- OUString(".uno:Watermark"),
- OUString(".uno:ResetAttributes"),
- OUString(".uno:Orientation"),
- OUString(".uno:ObjectAlignLeft"),
- OUString(".uno:ObjectAlignRight"),
- OUString(".uno:AlignCenter"),
- OUString(".uno:TransformPosX"),
- OUString(".uno:TransformPosY"),
- OUString(".uno:TransformWidth"),
- OUString(".uno:TransformHeight"),
- OUString(".uno:ObjectBackOne"),
- OUString(".uno:SendToBack"),
- OUString(".uno:ObjectForwardOne"),
- OUString(".uno:BringToFront"),
- OUString(".uno:WrapRight"),
- OUString(".uno:WrapThrough"),
- OUString(".uno:WrapLeft"),
- OUString(".uno:WrapIdeal"),
- OUString(".uno:WrapOn"),
- OUString(".uno:WrapOff"),
- OUString(".uno:UpdateCurIndex"),
- OUString(".uno:InsertCaptionDialog"),
- OUString(".uno:FormatGroup"),
- OUString(".uno:SplitTable"),
- OUString(".uno:MergeCells"),
- OUString(".uno:DeleteNote"),
- OUString(".uno:AcceptChanges"),
- OUString(".uno:FormatPaintbrush"),
- OUString(".uno:SetDefault"),
- OUString(".uno:ParaLeftToRight"),
- OUString(".uno:ParaRightToLeft"),
- OUString(".uno:ParaspaceIncrease"),
- OUString(".uno:ParaspaceDecrease"),
- OUString(".uno:AcceptTrackedChange"),
- OUString(".uno:RejectTrackedChange"),
- OUString(".uno:ShowResolvedAnnotations"),
- OUString(".uno:InsertBreak"),
- OUString(".uno:InsertEndnote"),
- OUString(".uno:InsertFootnote"),
- OUString(".uno:InsertReferenceField"),
- OUString(".uno:InsertBookmark"),
- OUString(".uno:InsertAuthoritiesEntry"),
- OUString(".uno:InsertMultiIndex"),
- OUString(".uno:InsertField"),
- OUString(".uno:InsertPageNumberField"),
- OUString(".uno:InsertPageCountField"),
- OUString(".uno:InsertDateField"),
- OUString(".uno:InsertTitleField"),
- OUString(".uno:InsertFieldCtrl"),
- OUString(".uno:CharmapControl"),
- OUString(".uno:EnterGroup"),
- OUString(".uno:LeaveGroup"),
- OUString(".uno:AlignUp"),
- OUString(".uno:AlignMiddle"),
- OUString(".uno:AlignDown"),
- OUString(".uno:TraceChangeMode"),
- OUString(".uno:Combine"),
- OUString(".uno:Merge"),
- OUString(".uno:Dismantle"),
- OUString(".uno:Substract"),
- OUString(".uno:DistributeSelection"),
- OUString(".uno:Intersect"),
- OUString(".uno:BorderInner"),
- OUString(".uno:BorderOuter"),
- OUString(".uno:FreezePanes"),
- OUString(".uno:FreezePanesColumn"),
- OUString(".uno:FreezePanesRow"),
- OUString(".uno:Sidebar"),
- OUString(".uno:SheetRightToLeft"),
- OUString(".uno:RunMacro"),
- OUString(".uno:SpacePara1"),
- OUString(".uno:SpacePara15"),
- OUString(".uno:SpacePara2")
+ static constexpr OUString sUnoCommands[] =
+ {
+ u".uno:AlignLeft"_ustr,
+ u".uno:AlignHorizontalCenter"_ustr,
+ u".uno:AlignRight"_ustr,
+ u".uno:BackColor"_ustr,
+ u".uno:BackgroundColor"_ustr,
+ u".uno:TableCellBackgroundColor"_ustr,
+ u".uno:Bold"_ustr,
+ u".uno:CenterPara"_ustr,
+ u".uno:CharBackColor"_ustr,
+ u".uno:CharBackgroundExt"_ustr,
+ u".uno:CharFontName"_ustr,
+ u".uno:Color"_ustr,
+ u".uno:ControlCodes"_ustr,
+ u".uno:DecrementIndent"_ustr,
+ u".uno:DefaultBullet"_ustr,
+ u".uno:DefaultNumbering"_ustr,
+ u".uno:FontColor"_ustr,
+ u".uno:FontHeight"_ustr,
+ u".uno:IncrementIndent"_ustr,
+ u".uno:Italic"_ustr,
+ u".uno:JustifyPara"_ustr,
+ u".uno:JumpToMark"_ustr,
+ u".uno:OutlineFont"_ustr,
+ u".uno:LeftPara"_ustr,
+ u".uno:LanguageStatus"_ustr,
+ u".uno:RightPara"_ustr,
+ u".uno:Shadowed"_ustr,
+ u".uno:SubScript"_ustr,
+ u".uno:SuperScript"_ustr,
+ u".uno:Strikeout"_ustr,
+ u".uno:StyleApply"_ustr,
+ u".uno:Underline"_ustr,
+ u".uno:ModifiedStatus"_ustr,
+ u".uno:Undo"_ustr,
+ u".uno:Redo"_ustr,
+ u".uno:InsertPage"_ustr,
+ u".uno:DeletePage"_ustr,
+ u".uno:DuplicatePage"_ustr,
+ u".uno:InsertSlide"_ustr,
+ u".uno:DeleteSlide"_ustr,
+ u".uno:DuplicateSlide"_ustr,
+ u".uno:ChangeTheme"_ustr,
+ u".uno:Cut"_ustr,
+ u".uno:Copy"_ustr,
+ u".uno:Paste"_ustr,
+ u".uno:SelectAll"_ustr,
+ u".uno:ReplyComment"_ustr,
+ u".uno:ResolveComment"_ustr,
+ u".uno:ResolveCommentThread"_ustr,
+ u".uno:InsertRowsBefore"_ustr,
+ u".uno:InsertRowsAfter"_ustr,
+ u".uno:InsertColumnsBefore"_ustr,
+ u".uno:InsertColumnsAfter"_ustr,
+ u".uno:DeleteRows"_ustr,
+ u".uno:DeleteColumns"_ustr,
+ u".uno:DeleteTable"_ustr,
+ u".uno:SelectTable"_ustr,
+ u".uno:EntireRow"_ustr,
+ u".uno:EntireColumn"_ustr,
+ u".uno:EntireCell"_ustr,
+ u".uno:AssignLayout"_ustr,
+ u".uno:StatusDocPos"_ustr,
+ u".uno:RowColSelCount"_ustr,
+ u".uno:StatusPageStyle"_ustr,
+ u".uno:InsertMode"_ustr,
+ u".uno:SpellOnline"_ustr,
+ u".uno:StatusSelectionMode"_ustr,
+ u".uno:StateTableCell"_ustr,
+ u".uno:StatusBarFunc"_ustr,
+ u".uno:StatePageNumber"_ustr,
+ u".uno:StateWordCount"_ustr,
+ u".uno:SelectionMode"_ustr,
+ u".uno:PageStatus"_ustr,
+ u".uno:LayoutStatus"_ustr,
+ u".uno:Scale"_ustr,
+ u".uno:Context"_ustr,
+ u".uno:WrapText"_ustr,
+ u".uno:ToggleMergeCells"_ustr,
+ u".uno:NumberFormatCurrency"_ustr,
+ u".uno:NumberFormatPercent"_ustr,
+ u".uno:NumberFormatDecimal"_ustr,
+ u".uno:NumberFormatIncDecimals"_ustr,
+ u".uno:NumberFormatDecDecimals"_ustr,
+ u".uno:NumberFormatDate"_ustr,
+ u".uno:EditHeaderAndFooter"_ustr,
+ u".uno:FrameLineColor"_ustr,
+ u".uno:SortAscending"_ustr,
+ u".uno:SortDescending"_ustr,
+ u".uno:TrackChanges"_ustr,
+ u".uno:ShowTrackedChanges"_ustr,
+ u".uno:NextTrackedChange"_ustr,
+ u".uno:PreviousTrackedChange"_ustr,
+ u".uno:AcceptAllTrackedChanges"_ustr,
+ u".uno:RejectAllTrackedChanges"_ustr,
+ u".uno:TableDialog"_ustr,
+ u".uno:FormatCellDialog"_ustr,
+ u".uno:FontDialog"_ustr,
+ u".uno:ParagraphDialog"_ustr,
+ u".uno:OutlineBullet"_ustr,
+ u".uno:InsertIndexesEntry"_ustr,
+ u".uno:DocumentRepair"_ustr,
+ u".uno:TransformDialog"_ustr,
+ u".uno:InsertPageHeader"_ustr,
+ u".uno:InsertPageFooter"_ustr,
+ u".uno:OnlineAutoFormat"_ustr,
+ u".uno:InsertObjectChart"_ustr,
+ u".uno:InsertSection"_ustr,
+ u".uno:InsertAnnotation"_ustr,
+ u".uno:DeleteAnnotation"_ustr,
+ u".uno:InsertPagebreak"_ustr,
+ u".uno:InsertColumnBreak"_ustr,
+ u".uno:HyperlinkDialog"_ustr,
+ u".uno:InsertSymbol"_ustr,
+ u".uno:EditRegion"_ustr,
+ u".uno:ThesaurusDialog"_ustr,
+ u".uno:FormatArea"_ustr,
+ u".uno:FormatLine"_ustr,
+ u".uno:FormatColumns"_ustr,
+ u".uno:Watermark"_ustr,
+ u".uno:ResetAttributes"_ustr,
+ u".uno:Orientation"_ustr,
+ u".uno:ObjectAlignLeft"_ustr,
+ u".uno:ObjectAlignRight"_ustr,
+ u".uno:AlignCenter"_ustr,
+ u".uno:TransformPosX"_ustr,
+ u".uno:TransformPosY"_ustr,
+ u".uno:TransformWidth"_ustr,
+ u".uno:TransformHeight"_ustr,
+ u".uno:ObjectBackOne"_ustr,
+ u".uno:SendToBack"_ustr,
+ u".uno:ObjectForwardOne"_ustr,
+ u".uno:BringToFront"_ustr,
+ u".uno:WrapRight"_ustr,
+ u".uno:WrapThrough"_ustr,
+ u".uno:WrapLeft"_ustr,
+ u".uno:WrapIdeal"_ustr,
+ u".uno:WrapOn"_ustr,
+ u".uno:WrapOff"_ustr,
+ u".uno:UpdateCurIndex"_ustr,
+ u".uno:InsertCaptionDialog"_ustr,
+ u".uno:FormatGroup"_ustr,
+ u".uno:SplitTable"_ustr,
+ u".uno:SplitCell"_ustr,
+ u".uno:MergeCells"_ustr,
+ u".uno:DeleteNote"_ustr,
+ u".uno:AcceptChanges"_ustr,
+ u".uno:FormatPaintbrush"_ustr,
+ u".uno:SetDefault"_ustr,
+ u".uno:ParaLeftToRight"_ustr,
+ u".uno:ParaRightToLeft"_ustr,
+ u".uno:ParaspaceIncrease"_ustr,
+ u".uno:ParaspaceDecrease"_ustr,
+ u".uno:AcceptTrackedChange"_ustr,
+ u".uno:RejectTrackedChange"_ustr,
+ u".uno:AcceptTrackedChangeToNext"_ustr,
+ u".uno:RejectTrackedChangeToNext"_ustr,
+ u".uno:ShowResolvedAnnotations"_ustr,
+ u".uno:InsertBreak"_ustr,
+ u".uno:InsertEndnote"_ustr,
+ u".uno:InsertFootnote"_ustr,
+ u".uno:InsertReferenceField"_ustr,
+ u".uno:InsertBookmark"_ustr,
+ u".uno:InsertAuthoritiesEntry"_ustr,
+ u".uno:InsertMultiIndex"_ustr,
+ u".uno:InsertField"_ustr,
+ u".uno:PageNumberWizard"_ustr,
+ u".uno:InsertPageNumberField"_ustr,
+ u".uno:InsertPageCountField"_ustr,
+ u".uno:InsertDateField"_ustr,
+ u".uno:InsertTitleField"_ustr,
+ u".uno:InsertFieldCtrl"_ustr,
+ u".uno:CharmapControl"_ustr,
+ u".uno:EnterGroup"_ustr,
+ u".uno:LeaveGroup"_ustr,
+ u".uno:AlignUp"_ustr,
+ u".uno:AlignMiddle"_ustr,
+ u".uno:AlignDown"_ustr,
+ u".uno:TraceChangeMode"_ustr,
+ u".uno:Combine"_ustr,
+ u".uno:Merge"_ustr,
+ u".uno:Dismantle"_ustr,
+ u".uno:Substract"_ustr,
+ u".uno:DistributeSelection"_ustr,
+ u".uno:Intersect"_ustr,
+ u".uno:BorderInner"_ustr,
+ u".uno:BorderOuter"_ustr,
+ u".uno:FreezePanes"_ustr,
+ u".uno:FreezePanesColumn"_ustr,
+ u".uno:FreezePanesRow"_ustr,
+ u".uno:Sidebar"_ustr,
+ u".uno:SheetRightToLeft"_ustr,
+ u".uno:RunMacro"_ustr,
+ u".uno:SpacePara1"_ustr,
+ u".uno:SpacePara15"_ustr,
+ u".uno:SpacePara2"_ustr,
+ u".uno:InsertSparkline"_ustr,
+ u".uno:DeleteSparkline"_ustr,
+ u".uno:DeleteSparklineGroup"_ustr,
+ u".uno:EditSparklineGroup"_ustr,
+ u".uno:EditSparkline"_ustr,
+ u".uno:GroupSparklines"_ustr,
+ u".uno:UngroupSparklines"_ustr,
+ u".uno:FormatSparklineMenu"_ustr,
+ u".uno:DataDataPilotRun"_ustr,
+ u".uno:RecalcPivotTable"_ustr,
+ u".uno:DeletePivotTable"_ustr,
+ u".uno:Protect"_ustr,
+ u".uno:UnsetCellsReadOnly"_ustr,
+ u".uno:ContentControlProperties"_ustr,
+ u".uno:InsertCheckboxContentControl"_ustr,
+ u".uno:InsertContentControl"_ustr,
+ u".uno:InsertDateContentControl"_ustr,
+ u".uno:InsertDropdownContentControl"_ustr,
+ u".uno:InsertPlainTextContentControl"_ustr,
+ u".uno:InsertPictureContentControl"_ustr,
+ u".uno:DataFilterAutoFilter"_ustr,
+ u".uno:CellProtection"_ustr,
+ u".uno:MoveKeepInsertMode"_ustr
};
util::URL aCommandURL;
SfxViewShell* pViewShell = SfxViewShell::Current();
- SfxViewFrame* pViewFrame = pViewShell? pViewShell->GetViewFrame(): nullptr;
+ SfxViewFrame* pViewFrame = pViewShell ? &pViewShell->GetViewFrame() : nullptr;
// check if Frame-Controller were created.
if (!pViewFrame)
@@ -3160,6 +3869,22 @@ static void doc_iniUnoCommands ()
return;
}
+#if !defined IOS && !defined ANDROID && !defined __EMSCRIPTEN__
+ uno::Reference<xml::crypto::XSEInitializer> xSEInitializer = xml::crypto::SEInitializer::create(xContext);
+ if (!xSEInitializer.is())
+ {
+ SAL_WARN("lok", "iniUnoCommands: XSEInitializer is not available");
+ return;
+ }
+
+ uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext =
+ xSEInitializer->createSecurityContext(OUString());
+ if (!xSecurityContext.is())
+ {
+ SAL_WARN("lok", "iniUnoCommands: failed to create security context");
+ }
+#endif
+
SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool(pViewFrame);
uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(xContext));
@@ -3183,40 +3908,7 @@ static int doc_getDocumentType (LibreOfficeKitDocument* pThis)
comphelper::ProfileZone aZone("doc_getDocumentType");
SolarMutexGuard aGuard;
- SetLastExceptionMsg();
-
- LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-
- try
- {
- uno::Reference<lang::XServiceInfo> xDocument(pDocument->mxComponent, uno::UNO_QUERY_THROW);
-
- if (xDocument->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
- {
- return LOK_DOCTYPE_SPREADSHEET;
- }
- else if (xDocument->supportsService("com.sun.star.presentation.PresentationDocument"))
- {
- return LOK_DOCTYPE_PRESENTATION;
- }
- else if (xDocument->supportsService("com.sun.star.drawing.DrawingDocument"))
- {
- return LOK_DOCTYPE_DRAWING;
- }
- else if (xDocument->supportsService("com.sun.star.text.TextDocument") || xDocument->supportsService("com.sun.star.text.WebDocument"))
- {
- return LOK_DOCTYPE_TEXT;
- }
- else
- {
- SetLastExceptionMsg("unknown document type");
- }
- }
- catch (const uno::Exception& exception)
- {
- SetLastExceptionMsg("exception: " + exception.Message);
- }
- return LOK_DOCTYPE_OTHER;
+ return getDocumentType(pThis);
}
static int doc_getParts (LibreOfficeKitDocument* pThis)
@@ -3228,7 +3920,7 @@ static int doc_getParts (LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return 0;
}
@@ -3245,7 +3937,7 @@ static int doc_getPart (LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return 0;
}
@@ -3262,7 +3954,7 @@ static void doc_setPartImpl(LibreOfficeKitDocument* pThis, int nPart, bool bAllo
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -3282,7 +3974,7 @@ static char* doc_getPartInfo(LibreOfficeKitDocument* pThis, int nPart)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
@@ -3292,13 +3984,12 @@ static char* doc_getPartInfo(LibreOfficeKitDocument* pThis, int nPart)
static void doc_selectPart(LibreOfficeKitDocument* pThis, int nPart, int nSelect)
{
SolarMutexGuard aGuard;
- if (gImpl)
- gImpl->maLastExceptionMsg.clear();
+ SetLastExceptionMsg();
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -3308,13 +3999,12 @@ static void doc_selectPart(LibreOfficeKitDocument* pThis, int nPart, int nSelect
static void doc_moveSelectedParts(LibreOfficeKitDocument* pThis, int nPosition, bool bDuplicate)
{
SolarMutexGuard aGuard;
- if (gImpl)
- gImpl->maLastExceptionMsg.clear();
+ SetLastExceptionMsg();
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -3331,13 +4021,53 @@ static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
return convertOUString(pDoc->getPartPageRectangles());
}
+static char* doc_getA11yFocusedParagraph(LibreOfficeKitDocument* pThis)
+{
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
+ return nullptr;
+ }
+
+ if (SfxViewShell* pViewShell = SfxViewShell::Current())
+ {
+ return convertOUString(pViewShell->getA11yFocusedParagraph());
+
+ }
+ return nullptr;
+}
+
+static int doc_getA11yCaretPosition(LibreOfficeKitDocument* pThis)
+{
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
+ return -1;
+ }
+ if (SfxViewShell* pViewShell = SfxViewShell::Current())
+ {
+ return pViewShell->getA11yCaretPosition();
+
+ }
+ return -1;
+
+}
+
static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
{
comphelper::ProfileZone aZone("doc_getPartName");
@@ -3348,7 +4078,7 @@ static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
@@ -3365,7 +4095,7 @@ static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
@@ -3383,7 +4113,7 @@ static void doc_setPartMode(LibreOfficeKitDocument* pThis,
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -3411,6 +4141,23 @@ static void doc_setPartMode(LibreOfficeKitDocument* pThis,
}
}
+static int doc_getEditMode(LibreOfficeKitDocument* pThis)
+{
+ comphelper::ProfileZone aZone("doc_getEditMode");
+
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
+ return 0;
+ }
+
+ return pDoc->getEditMode();
+}
+
static void doc_paintTile(LibreOfficeKitDocument* pThis,
unsigned char* pBuffer,
const int nCanvasWidth, const int nCanvasHeight,
@@ -3429,11 +4176,11 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
-#if defined(UNX) && !defined(MACOSX)
+#if defined(UNX) && !defined(MACOSX) || defined(_WIN32)
// Painting of zoomed or HiDPI spreadsheets is special, we actually draw everything at 100%,
// and only set cairo's (or CoreGraphic's, in the iOS case) scale factor accordingly, so that
@@ -3443,15 +4190,40 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
comphelper::ScopeGuard dpiScaleGuard([]() { comphelper::LibreOfficeKit::setDPIScale(1.0); });
#if defined(IOS)
- double fDPIScaleX = 1.0;
- paintTileIOS(pThis, pBuffer, nCanvasWidth, nCanvasHeight, fDPIScaleX, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+ double fDPIScale = 1.0;
+
+ // Onine uses the LOK_TILEMODE_RGBA by default so flip the normal flags
+ // to kCGImageAlphaPremultipliedLast | kCGImageByteOrder32Big
+ CGContextRef pCGContext = CGBitmapContextCreate(pBuffer, nCanvasWidth, nCanvasHeight, 8,
+ nCanvasWidth * 4, CGColorSpaceCreateDeviceRGB(),
+ kCGImageAlphaPremultipliedLast | kCGImageByteOrder32Big);
+
+ CGContextTranslateCTM(pCGContext, 0, nCanvasHeight);
+ CGContextScaleCTM(pCGContext, fDPIScale, -fDPIScale);
+
+ SAL_INFO( "lok.tiledrendering", "doc_paintTile: painting [" << nTileWidth << "x" << nTileHeight <<
+ "]@(" << nTilePosX << ", " << nTilePosY << ") to [" <<
+ nCanvasWidth << "x" << nCanvasHeight << "]px" );
+
+ Size aCanvasSize(nCanvasWidth, nCanvasHeight);
+
+ SystemGraphicsData aData;
+ aData.rCGContext = reinterpret_cast<CGContextRef>(pCGContext);
+
+ ScopedVclPtrInstance<VirtualDevice> pDevice(aData, Size(1, 1), DeviceFormat::WITHOUT_ALPHA);
+ pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+ pDevice->SetOutputSizePixel(aCanvasSize);
+ pDoc->paintTile(*pDevice, aCanvasSize.Width(), aCanvasSize.Height(),
+ nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+
+ CGContextRelease(pCGContext);
#else
- ScopedVclPtrInstance< VirtualDevice > pDevice(DeviceFormat::DEFAULT);
+ ScopedVclPtrInstance< VirtualDevice > pDevice(DeviceFormat::WITHOUT_ALPHA);
// Set background to transparent by default.
pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
- pDevice->SetOutputSizePixelScaleOffsetAndBuffer(
+ pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(
Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(),
pBuffer);
@@ -3470,6 +4242,36 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
pDevice->DrawRect(aRect);
pDevice->Pop();
}
+
+#ifdef _WIN32
+ // pBuffer was not used there
+ pDevice->EnableMapMode(false);
+ BitmapEx aBmpEx = pDevice->GetBitmapEx({ 0, 0 }, { nCanvasWidth, nCanvasHeight });
+ Bitmap aBmp = aBmpEx.GetBitmap();
+ AlphaMask aAlpha = aBmpEx.GetAlphaMask();
+ BitmapScopedReadAccess sraBmp(aBmp);
+ BitmapScopedReadAccess sraAlpha(aAlpha);
+
+ assert(sraBmp->Height() == nCanvasHeight);
+ assert(sraBmp->Width() == nCanvasWidth);
+ assert(!sraAlpha || sraBmp->Height() == sraAlpha->Height());
+ assert(!sraAlpha || sraBmp->Width() == sraAlpha->Width());
+ auto p = pBuffer;
+ for (tools::Long y = 0; y < sraBmp->Height(); ++y)
+ {
+ Scanline dataBmp = sraBmp->GetScanline(y);
+ Scanline dataAlpha = sraAlpha ? sraAlpha->GetScanline(y) : nullptr;
+ for (tools::Long x = 0; x < sraBmp->Width(); ++x)
+ {
+ BitmapColor color = sraBmp->GetPixelFromData(dataBmp, x);
+ sal_uInt8 alpha = dataAlpha ? sraAlpha->GetPixelFromData(dataAlpha, x).GetBlue() : 255;
+ *p++ = color.GetBlue();
+ *p++ = color.GetGreen();
+ *p++ = color.GetRed();
+ *p++ = alpha;
+ }
+ }
+#endif
#endif
#else
@@ -3477,39 +4279,10 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
#endif
}
-#ifdef IOS
-
-// This function is separate only to be used by LibreOfficeLight. If that app can be retired, this
-// function's code can be inlined.
-static void doc_paintTileToCGContext(LibreOfficeKitDocument* pThis,
- void* rCGContext,
- const int nCanvasWidth, const int nCanvasHeight,
- const int nTilePosX, const int nTilePosY,
- const int nTileWidth, const int nTileHeight)
-{
- SolarMutexGuard aGuard;
- SetLastExceptionMsg();
-
- SAL_INFO( "lok.tiledrendering", "paintTileToCGContext: painting [" << nTileWidth << "x" << nTileHeight <<
- "]@(" << nTilePosX << ", " << nTilePosY << ") to [" <<
- nCanvasWidth << "x" << nCanvasHeight << "]px" );
-
- ITiledRenderable* pDoc = getTiledRenderable(pThis);
- if (!pDoc)
- {
- SetLastExceptionMsg("Document doesn't support tiled rendering");
- return;
- }
-
- Size aCanvasSize(nCanvasWidth, nCanvasHeight);
- paintTileToCGContext(pDoc, rCGContext, aCanvasSize, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
-}
-
-#endif
-
static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
unsigned char* pBuffer,
const int nPart,
+ const int nMode,
const int nCanvasWidth, const int nCanvasHeight,
const int nTilePosX, const int nTilePosY,
const int nTileWidth, const int nTileHeight)
@@ -3519,7 +4292,7 @@ static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
SolarMutexGuard aGuard;
SetLastExceptionMsg();
- SAL_INFO( "lok.tiledrendering", "paintPartTile: painting @ " << nPart << " ["
+ SAL_INFO( "lok.tiledrendering", "paintPartTile: painting @ " << nPart << " : " << nMode << " ["
<< nTileWidth << "x" << nTileHeight << "]@("
<< nTilePosX << ", " << nTilePosY << ") to ["
<< nCanvasWidth << "x" << nCanvasHeight << "]px" );
@@ -3527,6 +4300,13 @@ static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
int nOrigViewId = doc_getView(pThis);
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
+ return;
+ }
+
if (nOrigViewId < 0)
{
// tile painting always needs a SfxViewShell::Current(), but actually
@@ -3557,43 +4337,121 @@ static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
{
// Text documents have a single coordinate system; don't change part.
int nOrigPart = 0;
- const bool isText = (doc_getDocumentType(pThis) == LOK_DOCTYPE_TEXT);
+ const int aType = doc_getDocumentType(pThis);
+ const bool isText = (aType == LOK_DOCTYPE_TEXT);
+ const bool isCalc = (aType == LOK_DOCTYPE_SPREADSHEET);
+ int nOrigEditMode = 0;
+ bool bPaintTextEdit = true;
int nViewId = nOrigViewId;
+ int nLastNonEditorView = -1;
+ int nViewMatchingMode = -1;
+ SfxViewShell* pCurrentViewShell = SfxViewShell::Current();
+
if (!isText)
{
// Check if just switching to another view is enough, that has
// less side-effects.
- if (nPart != doc_getPart(pThis))
+ if (nPart != doc_getPart(pThis) || nMode != pDoc->getEditMode())
{
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
- if (pViewShell->getPart() == nPart)
+ bool bIsInEdit = pViewShell->GetDrawView() &&
+ pViewShell->GetDrawView()->GetTextEditOutliner();
+
+ OString sCurrentViewRenderState = pDoc->getViewRenderState(pCurrentViewShell);
+ OString sNewRenderState = pDoc->getViewRenderState(pViewShell);
+
+ if (sCurrentViewRenderState == sNewRenderState && !bIsInEdit)
+ nLastNonEditorView = pViewShell->GetViewShellId().get();
+
+ if (pViewShell->getPart() == nPart &&
+ pViewShell->getEditMode() == nMode &&
+ sCurrentViewRenderState == sNewRenderState &&
+ !bIsInEdit)
{
nViewId = pViewShell->GetViewShellId().get();
+ nViewMatchingMode = nViewId;
+ nLastNonEditorView = nViewId;
doc_setView(pThis, nViewId);
break;
}
+ else if (pViewShell->getEditMode() == nMode && sCurrentViewRenderState == sNewRenderState && !bIsInEdit)
+ {
+ nViewMatchingMode = pViewShell->GetViewShellId().get();
+ }
+
pViewShell = SfxViewShell::GetNext(*pViewShell);
}
}
+ // if not found view with correct part
+ // - at least avoid rendering active textbox, This is for Impress.
+ // - prefer view with the same mode
+ if (nViewMatchingMode >= 0 && nViewMatchingMode != nViewId)
+ {
+ nViewId = nViewMatchingMode;
+ doc_setView(pThis, nViewId);
+ }
+ else if (!isCalc && nLastNonEditorView >= 0 && nLastNonEditorView != nViewId &&
+ pCurrentViewShell && pCurrentViewShell->GetDrawView() &&
+ pCurrentViewShell->GetDrawView()->GetTextEditOutliner())
+ {
+ nViewId = nLastNonEditorView;
+ doc_setView(pThis, nViewId);
+ }
+
+ // Disable callbacks while we are painting - after setting the view
+ if (nViewId != nOrigViewId && nViewId >= 0)
+ {
+ const auto handlerIt = pDocument->mpCallbackFlushHandlers.find(nViewId);
+ if (handlerIt != pDocument->mpCallbackFlushHandlers.end())
+ handlerIt->second->disableCallbacks();
+ }
+
nOrigPart = doc_getPart(pThis);
if (nPart != nOrigPart)
{
doc_setPartImpl(pThis, nPart, false);
}
+
+ nOrigEditMode = pDoc->getEditMode();
+ if (nOrigEditMode != nMode)
+ {
+ SfxLokHelper::setEditMode(nMode, pDoc);
+ }
+
+ bPaintTextEdit = (nPart == nOrigPart && nMode == nOrigEditMode);
+ pDoc->setPaintTextEdit(bPaintTextEdit);
}
doc_paintTile(pThis, pBuffer, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
- if (!isText && nPart != nOrigPart)
- {
- doc_setPartImpl(pThis, nOrigPart, false);
- }
- if (!isText && nViewId != nOrigViewId)
+ if (!isText)
{
- doc_setView(pThis, nOrigViewId);
+ pDoc->setPaintTextEdit(true);
+
+ if (nMode != nOrigEditMode)
+ {
+ SfxLokHelper::setEditMode(nOrigEditMode, pDoc);
+ }
+
+ if (nPart != nOrigPart)
+ {
+ doc_setPartImpl(pThis, nOrigPart, false);
+ }
+
+ if (nViewId != nOrigViewId)
+ {
+ if (nViewId >= 0)
+ {
+ const auto handlerIt = pDocument->mpCallbackFlushHandlers.find(nViewId);
+ if (handlerIt != pDocument->mpCallbackFlushHandlers.end())
+ handlerIt->second->enableCallbacks();
+ }
+
+ doc_setView(pThis, nOrigViewId);
+ }
}
}
catch (const std::exception&)
@@ -3612,7 +4470,11 @@ static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
static int doc_getTileMode(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis*/)
{
SetLastExceptionMsg();
+#if ENABLE_CAIRO_RGBA || defined IOS
+ return LOK_TILEMODE_RGBA;
+#else
return LOK_TILEMODE_BGRA;
+#endif
}
static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
@@ -3633,7 +4495,30 @@ static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
}
else
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
+ }
+}
+
+static void doc_getDataArea(LibreOfficeKitDocument* pThis,
+ long nTab,
+ long* pCol,
+ long* pRow)
+{
+ comphelper::ProfileZone aZone("doc_getDataArea");
+
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (pDoc)
+ {
+ Size aDocumentSize = pDoc->getDataArea(nTab);
+ *pCol = aDocumentSize.Width();
+ *pRow = aDocumentSize.Height();
+ }
+ else
+ {
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
}
}
@@ -3706,6 +4591,23 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis,
pDocument->mpCallbackFlushHandlers[nView]->setViewId(pViewShell->GetViewShellId().get());
pViewShell->setLibreOfficeKitViewCallback(pDocument->mpCallbackFlushHandlers[nView].get());
}
+
+ if (!pDocument->maFontsMissing.empty())
+ {
+ OString sPayload = "{ \"fontsmissing\": [ "_ostr;
+ bool bFirst = true;
+ for (const auto &f : pDocument->maFontsMissing)
+ {
+ if (bFirst)
+ bFirst = false;
+ else
+ sPayload += ", ";
+ sPayload += "\"" + f.toUtf8() + "\"";
+ }
+ sPayload += " ] }";
+ pCallback(LOK_CALLBACK_FONTS_MISSING, sPayload.getStr(), pData);
+ pDocument->maFontsMissing.clear();
+ }
}
else
{
@@ -3724,12 +4626,12 @@ static char* getPostIts(LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
tools::JsonWriter aJsonWriter;
pDoc->getPostIts(aJsonWriter);
- return aJsonWriter.extractData();
+ return convertOString(aJsonWriter.finishAndGetAsOString());
}
/// Returns the JSON representation of the positions of all the comments in the document
@@ -3739,12 +4641,12 @@ static char* getPostItsPos(LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
tools::JsonWriter aJsonWriter;
pDoc->getPostItsPos(aJsonWriter);
- return aJsonWriter.extractData();
+ return convertOString(aJsonWriter.finishAndGetAsOString());
}
static char* getRulerState(LibreOfficeKitDocument* pThis)
@@ -3753,12 +4655,12 @@ static char* getRulerState(LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
tools::JsonWriter aJsonWriter;
pDoc->getRulerState(aJsonWriter);
- return aJsonWriter.extractData();
+ return convertOString(aJsonWriter.finishAndGetAsOString());
}
static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode)
@@ -3771,7 +4673,7 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -3803,7 +4705,7 @@ static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis, unsig
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
pWindow = pDoc->getDocWindow();
@@ -3825,13 +4727,17 @@ static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis, unsig
static void doc_removeTextContext(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nCharBefore, int nCharAfter)
{
SolarMutexGuard aGuard;
+
+ if (SfxViewShell::IsCurrentLokViewReadOnly())
+ return;
+
VclPtr<vcl::Window> pWindow;
if (nLOKWindowId == 0)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
pWindow = pDoc->getDocWindow();
@@ -3843,7 +4749,7 @@ static void doc_removeTextContext(LibreOfficeKitDocument* pThis, unsigned nLOKWi
if (!pWindow)
{
- gImpl->maLastExceptionMsg = "No window found for window id: " + OUString::number(nLOKWindowId);
+ SetLastExceptionMsg("No window found for window id: " + OUString::number(nLOKWindowId));
return;
}
@@ -3855,12 +4761,12 @@ static void doc_removeTextContext(LibreOfficeKitDocument* pThis, unsigned nLOKWi
// backspace
if (nLOKWindowId == 0)
{
- KeyEvent aEvt(8, 1283);
+ KeyEvent aEvt(8, KEY_BACKSPACE);
for (int i = 0; i < nCharBefore; ++i)
pWindow->KeyInput(aEvt);
}
else
- SfxLokHelper::postKeyEventAsync(pWindow, LOK_KEYEVENT_KEYINPUT, 8, 1283, nCharBefore - 1);
+ SfxLokHelper::postKeyEventAsync(pWindow, LOK_KEYEVENT_KEYINPUT, 8, KEY_BACKSPACE, nCharBefore - 1);
}
if (nCharAfter > 0)
@@ -3868,12 +4774,12 @@ static void doc_removeTextContext(LibreOfficeKitDocument* pThis, unsigned nLOKWi
// delete (forward)
if (nLOKWindowId == 0)
{
- KeyEvent aEvt(46, 1286);
+ KeyEvent aEvt(46, KEY_DELETE);
for (int i = 0; i < nCharAfter; ++i)
pWindow->KeyInput(aEvt);
}
else
- SfxLokHelper::postKeyEventAsync(pWindow, LOK_KEYEVENT_KEYINPUT, 46, 1286, nCharAfter - 1);
+ SfxLokHelper::postKeyEventAsync(pWindow, LOK_KEYEVENT_KEYINPUT, 46, KEY_DELETE, nCharAfter - 1);
}
}
@@ -3887,7 +4793,7 @@ static void doc_postWindowKeyEvent(LibreOfficeKitDocument* /*pThis*/, unsigned n
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
if (!pWindow)
{
- SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
+ SetLastExceptionMsg(u"Document doesn't support dialog rendering, or window not found."_ustr);
return;
}
@@ -3907,6 +4813,37 @@ static void doc_postWindowKeyEvent(LibreOfficeKitDocument* /*pThis*/, unsigned n
}
}
+// To be an exportable selection, there must be something selected and that
+// selection can't be "ScCellObj" which doesn't can't provide a svg.
+//
+// Typically a problem arises when double clicking a shape in calc. The 1st
+// click selects the shape, triggering generation of a preview, but the second
+// shape enters into edit mode before doc_renderShapeSelection has a chance to
+// fire, at which point the shape is no longer selected. Rather than generate
+// an error just return a 0 length result if there is no shape selected, so we
+// continue to generate an error if a shape is selected, but could not provide
+// an svg.
+static bool doc_hasShapeSelection(const css::uno::Reference<css::lang::XComponent>& rComponent)
+{
+ uno::Reference<frame::XModel> xModel(rComponent, uno::UNO_QUERY);
+ if (!xModel.is())
+ return false;
+
+ uno::Reference<frame::XController> xController(xModel->getCurrentController());
+ if (!xController.is())
+ return false;
+
+ uno::Reference<view::XSelectionSupplier> xSelectionSupplier(xController, uno::UNO_QUERY);
+ if (!xSelectionSupplier.is())
+ return false;
+
+ Any selection = xSelectionSupplier->getSelection();
+ uno::Reference<lang::XServiceInfo> xSelection;
+ selection >>= xSelection;
+
+ return xSelection && xSelection->getImplementationName() != "ScCellObj";
+}
+
static size_t doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char** pOutput)
{
comphelper::ProfileZone aZone("doc_renderShapeSelection");
@@ -3923,6 +4860,9 @@ static size_t doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char** pOu
{
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+ if (!doc_hasShapeSelection(pDocument->mxComponent))
+ return 0;
+
uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW);
SvMemoryStream aOutStream;
@@ -3932,24 +4872,25 @@ static size_t doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char** pOu
switch (doc_getDocumentType(pThis))
{
case LOK_DOCTYPE_PRESENTATION:
- aMediaDescriptor["FilterName"] <<= OUString("impress_svg_Export");
+ aMediaDescriptor[u"FilterName"_ustr] <<= u"impress_svg_Export"_ustr;
break;
case LOK_DOCTYPE_DRAWING:
- aMediaDescriptor["FilterName"] <<= OUString("draw_svg_Export");
+ aMediaDescriptor[u"FilterName"_ustr] <<= u"draw_svg_Export"_ustr;
break;
case LOK_DOCTYPE_TEXT:
- aMediaDescriptor["FilterName"] <<= OUString("writer_svg_Export");
+ aMediaDescriptor[u"FilterName"_ustr] <<= u"writer_svg_Export"_ustr;
break;
case LOK_DOCTYPE_SPREADSHEET:
- aMediaDescriptor["FilterName"] <<= OUString("calc_svg_Export");
+ aMediaDescriptor[u"FilterName"_ustr] <<= u"calc_svg_Export"_ustr;
break;
default:
SAL_WARN("lok", "Failed to render shape selection: Document type is not supported");
}
- aMediaDescriptor["SelectionOnly"] <<= true;
- aMediaDescriptor["OutputStream"] <<= xOut;
+ aMediaDescriptor[u"SelectionOnly"_ustr] <<= true;
+ aMediaDescriptor[u"OutputStream"_ustr] <<= xOut;
+ aMediaDescriptor[u"IsPreview"_ustr] <<= true; // will down-scale graphics
- xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList());
+ xStorable->storeToURL(u"private:stream"_ustr, aMediaDescriptor.getAsConstPropertyValueList());
if (pOutput)
{
@@ -3983,13 +4924,17 @@ namespace {
*/
class DispatchResultListener : public cppu::WeakImplHelper<css::frame::XDispatchResultListener>
{
- OString maCommand; ///< Command for which this is the result.
- std::shared_ptr<CallbackFlushHandler> mpCallback; ///< Callback to call.
+ const OString maCommand; ///< Command for which this is the result.
+ const std::shared_ptr<CallbackFlushHandler> mpCallback; ///< Callback to call.
+ const std::chrono::steady_clock::time_point mSaveTime; //< The time we started saving.
+ const bool mbWasModified; //< Whether or not the document was modified before saving.
public:
- DispatchResultListener(const char* pCommand, std::shared_ptr<CallbackFlushHandler> const & pCallback)
+ DispatchResultListener(const char* pCommand, std::shared_ptr<CallbackFlushHandler> pCallback)
: maCommand(pCommand)
- , mpCallback(pCallback)
+ , mpCallback(std::move(pCallback))
+ , mSaveTime(std::chrono::steady_clock::now())
+ , mbWasModified(SfxObjectShell::Current()->IsModified())
{
assert(mpCallback);
}
@@ -4006,7 +4951,15 @@ public:
}
unoAnyToJson(aJson, "result", rEvent.Result);
- mpCallback->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.extractData());
+ aJson.put("wasModified", mbWasModified);
+ aJson.put("startUnixTimeMics",
+ std::chrono::time_point_cast<std::chrono::microseconds>(mSaveTime)
+ .time_since_epoch()
+ .count());
+ aJson.put("saveDurationMics", std::chrono::duration_cast<std::chrono::microseconds>(
+ std::chrono::steady_clock::now() - mSaveTime)
+ .count());
+ mpCallback->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.finishAndGetAsOString());
}
virtual void SAL_CALL disposing(const css::lang::EventObject&) override {}
@@ -4021,25 +4974,42 @@ static void lcl_sendDialogEvent(unsigned long long int nWindowId, const char* pA
StringMap aMap(jsdialog::jsonToStringMap(pArguments));
- if (aMap.find("id") == aMap.end())
+ if (aMap.find(u"id"_ustr) == aMap.end())
return;
sal_uInt64 nCurrentShellId = reinterpret_cast<sal_uInt64>(SfxViewShell::Current());
try
{
- OString sControlId = OUStringToOString(aMap["id"], RTL_TEXTENCODING_ASCII_US);
+ OUString sControlId = aMap[u"id"_ustr];
+ OUString sWindowId = OUString::number(nWindowId);
+ OUString sCurrentShellId = OUString::number(nCurrentShellId);
+
+ // special values for window id
+ if (nWindowId == static_cast<unsigned long long int>(-1))
+ sWindowId = sCurrentShellId + "sidebar";
+ if (nWindowId == static_cast<unsigned long long int>(-2))
+ sWindowId = sCurrentShellId + "notebookbar";
+ if (nWindowId == static_cast<unsigned long long int>(-3))
+ sWindowId = sCurrentShellId + "formulabar";
// dialogs send own id but notebookbar and sidebar controls are remembered by SfxViewShell id
- bool bFoundWeldedControl = jsdialog::ExecuteAction(nWindowId, sControlId, aMap);
- if (!bFoundWeldedControl)
- bFoundWeldedControl = jsdialog::ExecuteAction(nCurrentShellId, sControlId, aMap);
+ if (jsdialog::ExecuteAction(sWindowId, sControlId, aMap))
+ return;
- if (bFoundWeldedControl)
+ if (jsdialog::ExecuteAction(sCurrentShellId + "sidebar", sControlId, aMap))
+ return;
+ if (jsdialog::ExecuteAction(sCurrentShellId + "notebookbar", sControlId, aMap))
+ return;
+ if (jsdialog::ExecuteAction(sCurrentShellId + "formulabar", sControlId, aMap))
+ return;
+ // this is needed for dialogs shown before document is loaded: MacroWarning dialog, etc...
+ // these dialogs are created with WindowId "0"
+ if (!SfxViewShell::Current() && jsdialog::ExecuteAction(u"0"_ustr, sControlId, aMap))
return;
// force resend - used in mobile-wizard
- jsdialog::SendFullUpdate(nCurrentShellId, "Panel");
+ jsdialog::SendFullUpdate(sCurrentShellId + "sidebar", u"Panel"_ustr);
} catch(...) {}
}
@@ -4085,6 +5055,81 @@ static void lo_setOption(LibreOfficeKit* /*pThis*/, const char *pOption, const c
else
sal_detail_set_log_selector(pCurrentSalLogOverride);
}
+#ifdef LINUX
+ else if (strcmp(pOption, "addfont") == 0)
+ {
+ if (memcmp(pValue, "file://", 7) == 0)
+ pValue += 7;
+
+ int fd = open(pValue, O_RDONLY);
+ if (fd == -1)
+ {
+ std::cerr << "Could not open font file '" << pValue << "': " << strerror(errno) << std::endl;
+ return;
+ }
+
+ OUString sMagicFileName = "file:///:FD:/" + OUString::number(fd);
+
+ OutputDevice *pDevice = Application::GetDefaultDevice();
+ OutputDevice::ImplClearAllFontData(false);
+ pDevice->AddTempDevFont(sMagicFileName, "");
+ OutputDevice::ImplRefreshAllFontData(false);
+ }
+#endif
+}
+
+static void lo_dumpState (LibreOfficeKit* pThis, const char* /* pOptions */, char** pState)
+{
+ if (!pState)
+ return;
+
+ // NB. no SolarMutexGuard since this may be caused in some extremis / deadlock
+ SetLastExceptionMsg();
+
+ *pState = nullptr;
+ OStringBuffer aState(4096*256);
+
+ LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
+
+ pLib->dumpState(aState);
+
+ *pState = convertOString(aState.makeStringAndClear());
+}
+
+void LibLibreOffice_Impl::dumpState(rtl::OStringBuffer &rState)
+{
+ rState.append("LibreOfficeKit state:"
+ "\n\tLastExceptionMsg:\t");
+ rState.append(rtl::OUStringToOString(maLastExceptionMsg, RTL_TEXTENCODING_UTF8));
+ rState.append("\n\tUnipoll:\t");
+ rState.append(vcl::lok::isUnipoll() ? "yes" : "no: events on thread");
+ rState.append("\n\tOptionalFeatures:\t0x");
+ rState.append(static_cast<sal_Int64>(mOptionalFeatures), 16);
+ rState.append("\n\tCallbackData:\t0x");
+ rState.append(reinterpret_cast<sal_Int64>(mpCallback), 16);
+ // TODO: dump mInteractionMap
+ SfxLokHelper::dumpState(rState);
+ vcl::lok::dumpState(rState);
+}
+
+// We have special handling for some uno commands and it seems we need to check for readonly state.
+static bool isCommandAllowed(OUString& command) {
+ static constexpr OUString nonAllowedList[] = { u".uno:Save"_ustr, u".uno:TransformDialog"_ustr, u".uno:SidebarShow"_ustr, u".uno:SidebarHide"_ustr };
+
+ if (!SfxViewShell::IsCurrentLokViewReadOnly())
+ return true;
+ else
+ {
+ if (command == u".uno:Save"_ustr && SfxViewShell::Current() && SfxViewShell::Current()->IsAllowChangeComments())
+ return true;
+
+ for (size_t i = 0; i < std::size(nonAllowedList); i++)
+ {
+ if (nonAllowedList[i] == command)
+ return false;
+ }
+ return true;
+ }
}
static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished)
@@ -4096,6 +5141,10 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
SfxObjectShell* pDocSh = SfxObjectShell::Current();
OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8);
+
+ if (!isCommandAllowed(aCommand))
+ return;
+
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
std::vector<beans::PropertyValue> aPropertyValuesVector(jsonToPropertyValuesVector(pArguments));
@@ -4103,7 +5152,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
if (!vcl::lok::isUnipoll())
{
beans::PropertyValue aSynchronMode;
- aSynchronMode.Name = "SynchronMode";
+ aSynchronMode.Name = u"SynchronMode"_ustr;
aSynchronMode.Value <<= false;
aPropertyValuesVector.push_back(aSynchronMode);
}
@@ -4123,7 +5172,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
{
// Check if saving a PDF file
OUString aMimeType = lcl_getCurrentDocumentMimeType(pDocument);
- if (pDocSh->IsModified() && aMimeType == "application/pdf")
+ if (pDocSh && pDocSh->IsModified() && aMimeType == "application/pdf")
{
// If we have a PDF file (for saving annotations for example), we need
// to run save-as to the same file as the opened document. Plain save
@@ -4137,23 +5186,22 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
tools::JsonWriter aJson;
aJson.put("commandName", pCommand);
aJson.put("success", bResult);
- pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.extractData());
+ pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.finishAndGetAsOString());
return;
}
rtl::Reference<LOKInteractionHandler> const pInteraction(
- new LOKInteractionHandler("save", gImpl, pDocument));
+ new LOKInteractionHandler("save"_ostr, gImpl, pDocument));
uno::Reference<task::XInteractionHandler2> const xInteraction(pInteraction);
beans::PropertyValue aValue;
- aValue.Name = "InteractionHandler";
+ aValue.Name = u"InteractionHandler"_ustr;
aValue.Value <<= xInteraction;
aPropertyValuesVector.push_back(aValue);
bool bDontSaveIfUnmodified = false;
- aPropertyValuesVector.erase(std::remove_if(aPropertyValuesVector.begin(),
- aPropertyValuesVector.end(),
+ std::erase_if(aPropertyValuesVector,
[&bDontSaveIfUnmodified](const beans::PropertyValue& aItem){
if (aItem.Name == "DontSaveIfUnmodified")
{
@@ -4161,10 +5209,10 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
return true;
}
return false;
- }), aPropertyValuesVector.end());
+ });
// skip saving and tell the result via UNO_COMMAND_RESULT
- if (bDontSaveIfUnmodified && !pDocSh->IsModified())
+ if (bDontSaveIfUnmodified && (!pDocSh || !pDocSh->IsModified()))
{
tools::JsonWriter aJson;
aJson.put("commandName", pCommand);
@@ -4175,7 +5223,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
aJson.put("type", "string");
aJson.put("value", "unmodified");
}
- pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.extractData());
+ pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.finishAndGetAsOString());
return;
}
}
@@ -4210,7 +5258,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
|| rPropValue.Name == "TransformRotationY")
{
rPropValue.Value >>= value;
- value = OutputDevice::LogicToLogic(value, MapUnit::MapTwip, MapUnit::Map100thMM);
+ value = o3tl::convert(value, o3tl::Length::twip, o3tl::Length::mm100);
rPropValue.Value <<= value;
}
}
@@ -4240,7 +5288,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
}
}
util::URL aCommandURL;
- aCommandURL.Path = "LOKTransform";
+ aCommandURL.Path = u"LOKTransform"_ustr;
css::uno::Reference<css::frame::XDispatch>& aChartDispatcher = aChartHelper.GetXDispatcher();
aChartDispatcher->dispatch(aCommandURL, comphelper::containerToSequence(aPropertyValuesVector));
return;
@@ -4248,12 +5296,18 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
}
else if (gImpl && aCommand == ".uno:LOKSidebarWriterPage")
{
- setupSidebar(u"WriterPageDeck");
+ if (!sfx2::sidebar::Sidebar::Setup(u"WriterPageDeck"))
+ {
+ SetLastExceptionMsg(u"failed to set up sidebar"_ustr);
+ }
return;
}
else if (gImpl && aCommand == ".uno:SidebarShow")
{
- setupSidebar();
+ if (!sfx2::sidebar::Sidebar::Setup(u""))
+ {
+ SetLastExceptionMsg(u"failed to set up sidebar"_ustr);
+ }
return;
}
else if (gImpl && aCommand == ".uno:SidebarHide")
@@ -4273,7 +5327,13 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
aChartDispatcher->dispatch(aCommandURL, comphelper::containerToSequence(aPropertyValuesVector));
return;
}
- else if (bNotifyWhenFinished && pDocument->mpCallbackFlushHandlers.count(nView))
+ if (LokStarMathHelper aMathHelper(SfxViewShell::Current());
+ aMathHelper.GetGraphicWindow() && aCommand != ".uno:Save")
+ {
+ aMathHelper.Dispatch(aCommand, comphelper::containerToSequence(aPropertyValuesVector));
+ return;
+ }
+ if (bNotifyWhenFinished && pDocument->mpCallbackFlushHandlers.count(nView))
{
bResult = comphelper::dispatchCommand(aCommand, comphelper::containerToSequence(aPropertyValuesVector),
new DispatchResultListener(pCommand, pDocument->mpCallbackFlushHandlers[nView]));
@@ -4297,7 +5357,7 @@ static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX,
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
try
@@ -4321,7 +5381,7 @@ static void doc_postWindowMouseEvent(LibreOfficeKitDocument* /*pThis*/, unsigned
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
if (!pWindow)
{
- SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
+ SetLastExceptionMsg(u"Document doesn't support dialog rendering, or window not found."_ustr);
return;
}
@@ -4358,19 +5418,19 @@ static void doc_postWindowGestureEvent(LibreOfficeKitDocument* /*pThis*/, unsign
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
if (!pWindow)
{
- SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
+ SetLastExceptionMsg(u"Document doesn't support dialog rendering, or window not found."_ustr);
return;
}
OString aType(pType);
- GestureEventType eEventType = GestureEventType::PanningUpdate;
+ GestureEventPanType eEventType = GestureEventPanType::Update;
if (aType == "panBegin")
- eEventType = GestureEventType::PanningBegin;
+ eEventType = GestureEventPanType::Begin;
else if (aType == "panEnd")
- eEventType = GestureEventType::PanningEnd;
+ eEventType = GestureEventPanType::End;
- GestureEvent aEvent {
+ GestureEventPan aEvent {
sal_Int32(nX),
sal_Int32(nY),
eEventType,
@@ -4393,7 +5453,7 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -4410,7 +5470,7 @@ static void doc_setWindowTextSelection(LibreOfficeKitDocument* /*pThis*/, unsign
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
if (!pWindow)
{
- SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
+ SetLastExceptionMsg(u"Document doesn't support dialog rendering, or window not found."_ustr);
return;
}
@@ -4425,7 +5485,7 @@ static void doc_setWindowTextSelection(LibreOfficeKitDocument* /*pThis*/, unsign
Application::PostMouseEvent(VclEventId::WindowMouseButtonUp, pWindow, &aCursorEvent);
}
-static bool getFromTransferrable(
+static bool getFromTransferable(
const css::uno::Reference<css::datatransfer::XTransferable> &xTransferable,
const OString &aInMimeType, OString &aRet);
@@ -4433,13 +5493,13 @@ static bool encodeImageAsHTML(
const css::uno::Reference<css::datatransfer::XTransferable> &xTransferable,
const OString &aMimeType, OString &aRet)
{
- if (!getFromTransferrable(xTransferable, aMimeType, aRet))
+ if (!getFromTransferable(xTransferable, aMimeType, aRet))
return false;
// Encode in base64.
auto aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),
aRet.getLength());
- OUStringBuffer aBase64Data;
+ OStringBuffer aBase64Data;
comphelper::Base64::encode(aBase64Data, aSeq);
// Embed in HTML.
@@ -4450,7 +5510,7 @@ static bool encodeImageAsHTML(
+ getGenerator().toUtf8()
+ "\"/>"
"</head><body><img src=\"data:" + aMimeType + ";base64,"
- + aBase64Data.makeStringAndClear().toUtf8() + "\"/></body></html>";
+ + aBase64Data + "\"/></body></html>";
return true;
}
@@ -4459,7 +5519,7 @@ static bool encodeTextAsHTML(
const css::uno::Reference<css::datatransfer::XTransferable> &xTransferable,
const OString &aMimeType, OString &aRet)
{
- if (!getFromTransferrable(xTransferable, aMimeType, aRet))
+ if (!getFromTransferable(xTransferable, aMimeType, aRet))
return false;
// Embed in HTML - FIXME: needs some escaping.
@@ -4473,7 +5533,7 @@ static bool encodeTextAsHTML(
return true;
}
-static bool getFromTransferrable(
+static bool getFromTransferable(
const css::uno::Reference<css::datatransfer::XTransferable> &xTransferable,
const OString &aInMimeType, OString &aRet)
{
@@ -4482,17 +5542,17 @@ static bool getFromTransferrable(
// Take care of UTF-8 text here.
bool bConvert = false;
sal_Int32 nIndex = 0;
- if (aMimeType.getToken(0, ';', nIndex) == "text/plain")
+ if (o3tl::getToken(aMimeType, 0, ';', nIndex) == "text/plain")
{
- if (aMimeType.getToken(0, ';', nIndex) == "charset=utf-8")
+ if (o3tl::getToken(aMimeType, 0, ';', nIndex) == "charset=utf-8")
{
- aMimeType = "text/plain;charset=utf-16";
+ aMimeType = "text/plain;charset=utf-16"_ostr;
bConvert = true;
}
}
datatransfer::DataFlavor aFlavor;
- aFlavor.MimeType = OUString::fromUtf8(aMimeType.getStr());
+ aFlavor.MimeType = OUString::fromUtf8(aMimeType);
if (aMimeType == "text/plain;charset=utf-16")
aFlavor.DataType = cppu::UnoType<OUString>::get();
else
@@ -4504,10 +5564,10 @@ static bool getFromTransferrable(
if (aInMimeType == "text/html")
{
// Desperate measures - convert text to HTML instead.
- if (encodeTextAsHTML(xTransferable, "text/plain;charset=utf-8", aRet))
+ if (encodeTextAsHTML(xTransferable, "text/plain;charset=utf-8"_ostr, aRet))
return true;
// If html is not supported, might be a graphic-selection,
- if (encodeImageAsHTML(xTransferable, "image/png", aRet))
+ if (encodeImageAsHTML(xTransferable, "image/png"_ostr, aRet))
return true;
}
@@ -4560,23 +5620,22 @@ static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMi
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
css::uno::Reference<css::datatransfer::XTransferable> xTransferable = pDoc->getSelection();
if (!xTransferable)
{
- SetLastExceptionMsg("No selection available");
+ SetLastExceptionMsg(u"No selection available"_ustr);
return nullptr;
}
- const char *pType = pMimeType;
- if (!pType || pType[0] == '\0')
- pType = "text/plain;charset=utf-8";
+ OString aType
+ = pMimeType && pMimeType[0] != '\0' ? OString(pMimeType) : "text/plain;charset=utf-8"_ostr;
OString aRet;
- bool bSuccess = getFromTransferrable(xTransferable, OString(pType), aRet);
+ bool bSuccess = getFromTransferable(xTransferable, aType, aRet);
if (!bSuccess)
return nullptr;
@@ -4601,29 +5660,85 @@ static int doc_getSelectionType(LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
+ return LOK_SELTYPE_NONE;
+ }
+
+ css::uno::Reference<css::datatransfer::XTransferable> xTransferable = pDoc->getSelection();
+ if (!xTransferable)
+ {
+ SetLastExceptionMsg(u"No selection available"_ustr);
+ return LOK_SELTYPE_NONE;
+ }
+
+ css::uno::Reference<css::datatransfer::XTransferable2> xTransferable2(xTransferable, css::uno::UNO_QUERY);
+ if (xTransferable2.is() && xTransferable2->isComplex())
+ return LOK_SELTYPE_COMPLEX;
+
+ OString aRet;
+ bool bSuccess = getFromTransferable(xTransferable, "text/plain;charset=utf-8"_ostr, aRet);
+ if (!bSuccess)
+ return LOK_SELTYPE_NONE;
+
+ if (aRet.getLength() > 10000)
+ return LOK_SELTYPE_COMPLEX;
+
+ return !aRet.isEmpty() ? LOK_SELTYPE_TEXT : LOK_SELTYPE_NONE;
+}
+
+static int doc_getSelectionTypeAndText(LibreOfficeKitDocument* pThis, const char* pMimeType, char** pText, char** pUsedMimeType)
+{
+ // The purpose of this function is to avoid double call to pDoc->getSelection(),
+ // which may be expensive.
+ comphelper::ProfileZone aZone("doc_getSelectionTypeAndText");
+
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return LOK_SELTYPE_NONE;
}
- css::uno::Reference<css::datatransfer::XTransferable2> xTransferable(pDoc->getSelection(), css::uno::UNO_QUERY);
+ css::uno::Reference<css::datatransfer::XTransferable> xTransferable = pDoc->getSelection();
if (!xTransferable)
{
- SetLastExceptionMsg("No selection available");
+ SetLastExceptionMsg(u"No selection available"_ustr);
return LOK_SELTYPE_NONE;
}
- if (xTransferable->isComplex())
+ css::uno::Reference<css::datatransfer::XTransferable2> xTransferable2(xTransferable, css::uno::UNO_QUERY);
+ if (xTransferable2.is() && xTransferable2->isComplex())
return LOK_SELTYPE_COMPLEX;
+ OString aType
+ = pMimeType && pMimeType[0] != '\0' ? OString(pMimeType) : "text/plain;charset=utf-8"_ostr;
+
OString aRet;
- bool bSuccess = getFromTransferrable(xTransferable, "text/plain;charset=utf-8", aRet);
+ bool bSuccess = getFromTransferable(xTransferable, aType, aRet);
if (!bSuccess)
return LOK_SELTYPE_NONE;
if (aRet.getLength() > 10000)
return LOK_SELTYPE_COMPLEX;
- return aRet.getLength() ? LOK_SELTYPE_TEXT : LOK_SELTYPE_NONE;
+ if (aRet.isEmpty())
+ return LOK_SELTYPE_NONE;
+
+ if (pText)
+ *pText = convertOString(aRet);
+
+ if (pUsedMimeType) // legacy
+ {
+ if (pMimeType)
+ *pUsedMimeType = strdup(pMimeType);
+ else
+ *pUsedMimeType = nullptr;
+ }
+
+ return LOK_SELTYPE_TEXT;
}
static int doc_getClipboard(LibreOfficeKitDocument* pThis,
@@ -4663,17 +5778,17 @@ static int doc_getClipboard(LibreOfficeKitDocument* pThis,
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return 0;
}
rtl::Reference<LOKClipboard> xClip(LOKClipboardFactory::getClipboardForCurView());
css::uno::Reference<css::datatransfer::XTransferable> xTransferable = xClip->getContents();
- SAL_INFO("lok", "Got from clip: " << xClip.get() << " transferrable: " << xTransferable);
+ SAL_INFO("lok", "Got from clip: " << xClip.get() << " transferable: " << xTransferable);
if (!xTransferable)
{
- SetLastExceptionMsg("No clipboard content available");
+ SetLastExceptionMsg(u"No clipboard content available"_ustr);
return 0;
}
@@ -4683,7 +5798,7 @@ static int doc_getClipboard(LibreOfficeKitDocument* pThis,
const uno::Sequence< css::datatransfer::DataFlavor > flavors = xTransferable->getTransferDataFlavors();
if (!flavors.getLength())
{
- SetLastExceptionMsg("Flavourless selection");
+ SetLastExceptionMsg(u"Flavourless selection"_ustr);
return 0;
}
for (const auto &it : flavors)
@@ -4704,10 +5819,10 @@ static int doc_getClipboard(LibreOfficeKitDocument* pThis,
if (aMimeTypes[i] == "text/plain;charset=utf-16")
(*pOutMimeTypes)[i] = strdup("text/plain;charset=utf-8");
else
- (*pOutMimeTypes)[i] = strdup(aMimeTypes[i].getStr());
+ (*pOutMimeTypes)[i] = convertOString(aMimeTypes[i]);
OString aRet;
- bool bSuccess = getFromTransferrable(xTransferable, (*pOutMimeTypes)[i], aRet);
+ bool bSuccess = getFromTransferable(xTransferable, (*pOutMimeTypes)[i], aRet);
if (!bSuccess || aRet.getLength() < 1)
{
(*pOutSizes)[i] = 0;
@@ -4745,7 +5860,7 @@ static int doc_setClipboard(LibreOfficeKitDocument* pThis,
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return false;
}
@@ -4758,7 +5873,7 @@ static int doc_setClipboard(LibreOfficeKitDocument* pThis,
if (!pDoc->isMimeTypeSupported())
{
- SetLastExceptionMsg("Document doesn't support this mime type");
+ SetLastExceptionMsg(u"Document doesn't support this mime type"_ustr);
return false;
}
#endif
@@ -4783,12 +5898,12 @@ static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, cons
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
{
- {"AnchorType", uno::makeAny(static_cast<sal_uInt16>(css::text::TextContentAnchorType_AS_CHARACTER))},
- {"IgnoreComments", uno::makeAny(true)},
+ {"AnchorType", uno::Any(static_cast<sal_uInt16>(css::text::TextContentAnchorType_AS_CHARACTER))},
+ {"IgnoreComments", uno::Any(true)},
}));
- if (!comphelper::dispatchCommand(".uno:Paste", aPropertyValues))
+ if (!comphelper::dispatchCommand(u".uno:Paste"_ustr, aPropertyValues))
{
- SetLastExceptionMsg("Failed to dispatch the .uno: command");
+ SetLastExceptionMsg(u"Failed to dispatch the .uno: command"_ustr);
return false;
}
@@ -4805,7 +5920,7 @@ static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, in
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -4822,19 +5937,55 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
pDoc->resetSelection();
}
+static char* getDocReadOnly(LibreOfficeKitDocument* pThis)
+{
+ SfxObjectShell* pObjectShell = getSfxObjectShell(pThis);
+ if (!pObjectShell)
+ return nullptr;
+
+ boost::property_tree::ptree aTree;
+ aTree.put("commandName", ".uno:ReadOnly");
+ aTree.put("success", pObjectShell->IsLoadReadonly());
+
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
+ if (!pJson)
+ return nullptr;
+
+ strcpy(pJson, aStream.str().c_str());
+ pJson[aStream.str().size()] = '\0';
+ return pJson;
+}
+
+static void addLocale(boost::property_tree::ptree& rValues, css::lang::Locale const & rLocale)
+{
+ boost::property_tree::ptree aChild;
+ const LanguageTag aLanguageTag( rLocale );
+ OUString sLanguage = SvtLanguageTable::GetLanguageString(aLanguageTag.getLanguageType());
+ if (sLanguage.endsWith("}"))
+ return;
+
+ sLanguage += ";" + aLanguageTag.getBcp47(false);
+ aChild.put("", sLanguage.toUtf8());
+ rValues.push_back(std::make_pair("", aChild));
+}
+
static char* getLanguages(const char* pCommand)
{
css::uno::Sequence< css::lang::Locale > aLocales;
+ css::uno::Sequence< css::lang::Locale > aGrammarLocales;
if (xContext.is())
{
+ // SpellChecker
css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLangSrv = css::linguistic2::LinguServiceManager::create(xContext);
if (xLangSrv.is())
{
@@ -4842,24 +5993,25 @@ static char* getLanguages(const char* pCommand)
if (xSpell.is())
aLocales = xSpell->getLocales();
}
+
+ // LanguageTool
+ if (LanguageToolCfg::IsEnabled::get())
+ {
+ uno::Reference< linguistic2::XProofreader > xGC(
+ xContext->getServiceManager()->createInstanceWithContext(u"org.openoffice.lingu.LanguageToolGrammarChecker"_ustr, xContext),
+ uno::UNO_QUERY_THROW );
+ uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xGC, uno::UNO_QUERY_THROW );
+ aGrammarLocales = xSuppLoc->getLocales();
+ }
}
boost::property_tree::ptree aTree;
aTree.put("commandName", pCommand);
boost::property_tree::ptree aValues;
- boost::property_tree::ptree aChild;
- OUString sLanguage;
- for ( css::lang::Locale const & locale : std::as_const(aLocales) )
- {
- const LanguageTag aLanguageTag( locale );
- sLanguage = SvtLanguageTable::GetLanguageString(aLanguageTag.getLanguageType());
- if (sLanguage.startsWith("{") && sLanguage.endsWith("}"))
- continue;
-
- sLanguage += ";" + aLanguageTag.getBcp47(false);
- aChild.put("", sLanguage.toUtf8());
- aValues.push_back(std::make_pair("", aChild));
- }
+ for (css::lang::Locale const& rLocale : aLocales)
+ addLocale(aValues, rLocale);
+ for (css::lang::Locale const& rLocale : aGrammarLocales)
+ addLocale(aValues, rLocale);
aTree.add_child("commandValues", aValues);
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
@@ -4873,6 +6025,8 @@ static char* getLanguages(const char* pCommand)
static char* getFonts (const char* pCommand)
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
+ if (!pDocSh)
+ return nullptr;
const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>(
pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr;
@@ -4920,7 +6074,7 @@ static char* getFontSubset (std::string_view aFontName)
if (const vcl::Font* pFont = FindFont(aFoundFont))
{
FontCharMapRef xFontCharMap (new FontCharMap());
- auto aDevice(VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT));
+ auto aDevice(VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA));
aDevice->SetFont(*pFont);
aDevice->GetFontCharMap(xFontCharMap);
@@ -4954,15 +6108,15 @@ static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
const uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
const uno::Sequence<OUString> aStyleFamilies = xStyleFamilies->getElementNames();
- static const std::vector<OUString> aWriterStyles =
+ static constexpr OUString aWriterStyles[] =
{
- "Text body",
- "Quotations",
- "Title",
- "Subtitle",
- "Heading 1",
- "Heading 2",
- "Heading 3"
+ u"Text body"_ustr,
+ u"Quotations"_ustr,
+ u"Title"_ustr,
+ u"Subtitle"_ustr,
+ u"Heading 1"_ustr,
+ u"Heading 2"_ustr,
+ u"Heading 3"_ustr,
};
// We need to keep a list of the default style names
@@ -5012,7 +6166,7 @@ static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
{
boost::property_tree::ptree aChild;
boost::property_tree::ptree aChildren;
- static const OUStringLiteral sPageStyles(u"PageStyles");
+ static constexpr OUString sPageStyles(u"PageStyles"_ustr);
uno::Reference<beans::XPropertySet> xProperty;
uno::Reference<container::XNameContainer> xContainer;
@@ -5023,10 +6177,10 @@ static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
{
bool bIsPhysical;
xProperty.set(xContainer->getByName(sName), uno::UNO_QUERY);
- if (xProperty.is() && (xProperty->getPropertyValue("IsPhysical") >>= bIsPhysical) && bIsPhysical)
+ if (xProperty.is() && (xProperty->getPropertyValue(u"IsPhysical"_ustr) >>= bIsPhysical) && bIsPhysical)
{
OUString displayName;
- xProperty->getPropertyValue("DisplayName") >>= displayName;
+ xProperty->getPropertyValue(u"DisplayName"_ustr) >>= displayName;
aChild.put("", displayName.toUtf8());
aChildren.push_back(std::make_pair("", aChild));
}
@@ -5099,7 +6253,7 @@ static char* getUndoOrRedo(LibreOfficeKitDocument* pThis, UndoOrRedo eCommand)
aString = pUndoManager->GetUndoActionsInfo();
else
aString = pUndoManager->GetRedoActionsInfo();
- char* pJson = strdup(aString.toUtf8().getStr());
+ char* pJson = convertOUString(aString);
return pJson;
}
@@ -5124,23 +6278,23 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis)
aJson.put("index", static_cast<sal_Int32>(nIndex));
OUString sAuthor;
- xRedline->getPropertyValue("RedlineAuthor") >>= sAuthor;
+ xRedline->getPropertyValue(u"RedlineAuthor"_ustr) >>= sAuthor;
aJson.put("author", sAuthor);
OUString sType;
- xRedline->getPropertyValue("RedlineType") >>= sType;
+ xRedline->getPropertyValue(u"RedlineType"_ustr) >>= sType;
aJson.put("type", sType);
OUString sComment;
- xRedline->getPropertyValue("RedlineComment") >>= sComment;
+ xRedline->getPropertyValue(u"RedlineComment"_ustr) >>= sComment;
aJson.put("comment", sComment);
OUString sDescription;
- xRedline->getPropertyValue("RedlineDescription") >>= sDescription;
+ xRedline->getPropertyValue(u"RedlineDescription"_ustr) >>= sDescription;
aJson.put("description", sDescription);
util::DateTime aDateTime;
- xRedline->getPropertyValue("RedlineDateTime") >>= aDateTime;
+ xRedline->getPropertyValue(u"RedlineDateTime"_ustr) >>= aDateTime;
OUString sDateTime = utl::toISO8601(aDateTime);
aJson.put("dateTime", sDateTime);
}
@@ -5150,13 +6304,13 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
pDoc->getTrackedChanges(aJson);
}
- return aJson.extractData();
+ return convertOString(aJson.finishAndGetAsOString());
}
@@ -5166,12 +6320,12 @@ static char* getTrackedChangeAuthors(LibreOfficeKitDocument* pThis)
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return nullptr;
}
tools::JsonWriter aJsonWriter;
pDoc->getTrackedChangeAuthors(aJsonWriter);
- return aJsonWriter.extractData();
+ return convertOString(aJsonWriter.finishAndGetAsOString());
}
static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand)
@@ -5181,21 +6335,31 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
SolarMutexGuard aGuard;
SetLastExceptionMsg();
- OString aCommand(pCommand);
- static constexpr OStringLiteral aViewRowColumnHeaders(".uno:ViewRowColumnHeaders");
- static constexpr OStringLiteral aSheetGeometryData(".uno:SheetGeometryData");
- static constexpr OStringLiteral aCellCursor(".uno:CellCursor");
- static constexpr OStringLiteral aFontSubset(".uno:FontSubset&name=");
+ const std::string_view aCommand(pCommand);
+ static constexpr std::string_view aViewRowColumnHeaders(".uno:ViewRowColumnHeaders");
+ static constexpr std::string_view aSheetGeometryData(".uno:SheetGeometryData");
+ static constexpr std::string_view aFontSubset(".uno:FontSubset&name=");
- if (!strcmp(pCommand, ".uno:LanguageStatus"))
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
+ return nullptr;
+ }
+
+ if (aCommand == ".uno:ReadOnly")
+ {
+ return getDocReadOnly(pThis);
+ }
+ else if (aCommand == ".uno:LanguageStatus")
{
return getLanguages(pCommand);
}
- else if (!strcmp(pCommand, ".uno:CharFontName"))
+ else if (aCommand == ".uno:CharFontName")
{
return getFonts(pCommand);
}
- else if (!strcmp(pCommand, ".uno:StyleApply"))
+ else if (aCommand == ".uno:StyleApply")
{
return getStyles(pThis, pCommand);
}
@@ -5227,48 +6391,45 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
{
return getRulerState(pThis);
}
- else if (aCommand.startsWith(aViewRowColumnHeaders))
+ else if (aCommand == ".uno:ViewRenderState")
+ {
+ return convertOString(pDoc->getViewRenderState());
+ }
+ else if (aCommand.starts_with(aViewRowColumnHeaders))
{
- ITiledRenderable* pDoc = getTiledRenderable(pThis);
- if (!pDoc)
- {
- SetLastExceptionMsg("Document doesn't support tiled rendering");
- return nullptr;
- }
-
tools::Rectangle aRectangle;
- if (aCommand.getLength() > aViewRowColumnHeaders.getLength())
+ if (aCommand.size() > aViewRowColumnHeaders.size())
{
// Command has parameters.
int nX = 0;
int nY = 0;
int nWidth = 0;
int nHeight = 0;
- OString aArguments = aCommand.copy(aViewRowColumnHeaders.getLength() + 1);
+ std::string_view aArguments = aCommand.substr(aViewRowColumnHeaders.size() + 1);
sal_Int32 nParamIndex = 0;
do
{
- OString aParamToken = aArguments.getToken(0, '&', nParamIndex);
+ std::string_view aParamToken = o3tl::getToken(aArguments, 0, '&', nParamIndex);
sal_Int32 nIndex = 0;
- OString aKey;
- OString aValue;
+ std::string_view aKey;
+ std::string_view aValue;
do
{
- OString aToken = aParamToken.getToken(0, '=', nIndex);
- if (!aKey.getLength())
+ std::string_view aToken = o3tl::getToken(aParamToken, 0, '=', nIndex);
+ if (aKey.empty())
aKey = aToken;
else
aValue = aToken;
}
while (nIndex >= 0);
if (aKey == "x")
- nX = aValue.toInt32();
+ nX = o3tl::toInt32(aValue);
else if (aKey == "y")
- nY = aValue.toInt32();
+ nY = o3tl::toInt32(aValue);
else if (aKey == "width")
- nWidth = aValue.toInt32();
+ nWidth = o3tl::toInt32(aValue);
else if (aKey == "height")
- nHeight = aValue.toInt32();
+ nHeight = o3tl::toInt32(aValue);
}
while (nParamIndex >= 0);
@@ -5277,47 +6438,40 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
tools::JsonWriter aJsonWriter;
pDoc->getRowColumnHeaders(aRectangle, aJsonWriter);
- return aJsonWriter.extractData();
+ return convertOString(aJsonWriter.finishAndGetAsOString());
}
- else if (aCommand.startsWith(aSheetGeometryData))
+ else if (aCommand.starts_with(aSheetGeometryData))
{
- ITiledRenderable* pDoc = getTiledRenderable(pThis);
- if (!pDoc)
- {
- SetLastExceptionMsg("Document doesn't support tiled rendering");
- return nullptr;
- }
-
bool bColumns = true;
bool bRows = true;
bool bSizes = true;
bool bHidden = true;
bool bFiltered = true;
bool bGroups = true;
- if (aCommand.getLength() > aSheetGeometryData.getLength())
+ if (aCommand.size() > aSheetGeometryData.size())
{
bColumns = bRows = bSizes = bHidden = bFiltered = bGroups = false;
- OString aArguments = aCommand.copy(aSheetGeometryData.getLength() + 1);
+ std::string_view aArguments = aCommand.substr(aSheetGeometryData.size() + 1);
sal_Int32 nParamIndex = 0;
do
{
- OString aParamToken = aArguments.getToken(0, '&', nParamIndex);
+ std::string_view aParamToken = o3tl::getToken(aArguments, 0, '&', nParamIndex);
sal_Int32 nIndex = 0;
- OString aKey;
- OString aValue;
+ std::string_view aKey;
+ std::string_view aValue;
do
{
- OString aToken = aParamToken.getToken(0, '=', nIndex);
- if (!aKey.getLength())
+ std::string_view aToken = o3tl::getToken(aParamToken, 0, '=', nIndex);
+ if (aKey.empty())
aKey = aToken;
else
aValue = aToken;
} while (nIndex >= 0);
- bool bEnableFlag = aValue.isEmpty() ||
- aValue.equalsIgnoreAsciiCase("true") || aValue.toInt32() > 0;
+ bool bEnableFlag = aValue.empty() ||
+ o3tl::equalsIgnoreAsciiCase(aValue, "true") || o3tl::toInt32(aValue) > 0;
if (!bEnableFlag)
continue;
@@ -5345,26 +6499,26 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
return convertOString(aGeomDataStr);
}
- else if (aCommand.startsWith(aCellCursor))
+ else if (aCommand.starts_with(".uno:CellCursor"))
{
- ITiledRenderable* pDoc = getTiledRenderable(pThis);
- if (!pDoc)
- {
- SetLastExceptionMsg("Document doesn't support tiled rendering");
- return nullptr;
- }
// Ignore command's deprecated parameters.
tools::JsonWriter aJsonWriter;
pDoc->getCellCursor(aJsonWriter);
- return aJsonWriter.extractData();
+ return convertOString(aJsonWriter.finishAndGetAsOString());
+ }
+ else if (aCommand.starts_with(aFontSubset))
+ {
+ return getFontSubset(aCommand.substr(aFontSubset.size()));
}
- else if (aCommand.startsWith(aFontSubset))
+ else if (pDoc->supportsCommand(INetURLObject(OUString::fromUtf8(aCommand)).GetURLPath()))
{
- return getFontSubset(std::string_view(pCommand + aFontSubset.getLength()));
+ tools::JsonWriter aJsonWriter;
+ pDoc->getCommandValues(aJsonWriter, aCommand);
+ return convertOString(aJsonWriter.finishAndGetAsOString());
}
else
{
- SetLastExceptionMsg("Unknown command, no values returned");
+ SetLastExceptionMsg(u"Unknown command, no values returned"_ustr);
return nullptr;
}
}
@@ -5380,7 +6534,7 @@ static void doc_setClientZoom(LibreOfficeKitDocument* pThis, int nTilePixelWidth
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -5397,7 +6551,7 @@ static void doc_setClientVisibleArea(LibreOfficeKitDocument* pThis, int nX, int
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -5415,7 +6569,7 @@ static void doc_setOutlineState(LibreOfficeKitDocument* pThis, bool bColumn, int
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -5533,8 +6687,6 @@ static void doc_setViewLanguage(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*p
SfxLokHelper::setViewLocale(nId, sLanguage);
}
-
-
unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis,
const char* pFontName,
const char* pChar,
@@ -5564,7 +6716,7 @@ unsigned char* doc_renderFontOrientation(SAL_UNUSED_PARAMETER LibreOfficeKitDocu
if (aText.isEmpty())
aText = aFont.GetFamilyName();
- auto aDevice(VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT));
+ auto aDevice(VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA));
::tools::Rectangle aRect;
aFont.SetFontSize(Size(0, nDefaultFontSize));
aFont.SetOrientation(Degree10(pOrientation));
@@ -5606,7 +6758,7 @@ unsigned char* doc_renderFontOrientation(SAL_UNUSED_PARAMETER LibreOfficeKitDocu
memset(pBuffer, 0, nFontWidth * nFontHeight * 4);
aDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
- aDevice->SetOutputSizePixelScaleOffsetAndBuffer(
+ aDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(
Size(nFontWidth, nFontHeight), Fraction(1.0), Point(),
pBuffer);
@@ -5663,7 +6815,7 @@ static void doc_paintWindowForView(LibreOfficeKitDocument* pThis, unsigned nLOKW
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
if (!pWindow)
{
- SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
+ SetLastExceptionMsg(u"Document doesn't support dialog rendering, or window not found."_ustr);
return;
}
@@ -5679,8 +6831,9 @@ static void doc_paintWindowForView(LibreOfficeKitDocument* pThis, unsigned nLOKW
comphelper::LibreOfficeKit::setDPIScale(fDPIScale);
#if defined(IOS)
-
- CGContextRef cgc = CGBitmapContextCreate(pBuffer, nWidth, nHeight, 8, nWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little);
+ // Onine uses the LOK_TILEMODE_RGBA by default so flip the normal flags
+ // to kCGImageAlphaNoneSkipLast | kCGImageByteOrder32Big
+ CGContextRef cgc = CGBitmapContextCreate(pBuffer, nWidth, nHeight, 8, nWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipLast | kCGImageByteOrder32Big);
CGContextTranslateCTM(cgc, 0, nHeight);
CGContextScaleCTM(cgc, fDPIScale, -fDPIScale);
@@ -5688,7 +6841,7 @@ static void doc_paintWindowForView(LibreOfficeKitDocument* pThis, unsigned nLOKW
SystemGraphicsData aData;
aData.rCGContext = cgc;
- ScopedVclPtrInstance<VirtualDevice> pDevice(aData, Size(1, 1), DeviceFormat::DEFAULT);
+ ScopedVclPtrInstance<VirtualDevice> pDevice(aData, Size(1, 1), DeviceFormat::WITHOUT_ALPHA);
pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
pDevice->SetOutputSizePixel(Size(nWidth, nHeight));
@@ -5703,10 +6856,10 @@ static void doc_paintWindowForView(LibreOfficeKitDocument* pThis, unsigned nLOKW
#else
- ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::DEFAULT);
+ ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::WITHOUT_ALPHA);
pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
- pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nWidth, nHeight), Fraction(1.0), Point(), pBuffer);
+ pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(Size(nWidth, nHeight), Fraction(1.0), Point(), pBuffer);
MapMode aMapMode(pDevice->GetMapMode());
aMapMode.SetOrigin(Point(-(nX / fDPIScale), -(nY / fDPIScale)));
@@ -5728,7 +6881,7 @@ static void doc_postWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindo
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
if (!pWindow)
{
- SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
+ SetLastExceptionMsg(u"Document doesn't support dialog rendering, or window not found."_ustr);
return;
}
@@ -5759,7 +6912,7 @@ static void doc_postWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindo
Application::PostKeyEvent(VclEventId::WindowKeyInput, pWindow, &aEvent);
}
else
- SetLastExceptionMsg("Window command 'paste': wrong parameters.");
+ SetLastExceptionMsg(u"Window command 'paste': wrong parameters."_ustr);
#else
(void) pData;
assert(!"doc_postWindow() with LOK_WINDOW_PASTE should not be called on iOS");
@@ -5808,7 +6961,7 @@ static bool doc_insertCertificate(LibreOfficeKitDocument* pThis,
std::string aCertificateBase64String = extractCertificate(aCertificateString);
if (!aCertificateBase64String.empty())
{
- OUString aBase64OUString = OUString::createFromAscii(aCertificateBase64String.c_str());
+ OUString aBase64OUString = OUString::createFromAscii(aCertificateBase64String);
comphelper::Base64::decode(aCertificateSequence, aBase64OUString);
}
else
@@ -5822,7 +6975,7 @@ static bool doc_insertCertificate(LibreOfficeKitDocument* pThis,
std::string aPrivateKeyBase64String = extractPrivateKey(aPrivateKeyString);
if (!aPrivateKeyBase64String.empty())
{
- OUString aBase64OUString = OUString::createFromAscii(aPrivateKeyBase64String.c_str());
+ OUString aBase64OUString = OUString::createFromAscii(aPrivateKeyBase64String);
comphelper::Base64::decode(aPrivateKeySequence, aBase64OUString);
}
else
@@ -5880,7 +7033,7 @@ static bool doc_addCertificate(LibreOfficeKitDocument* pThis,
std::string aCertificateBase64String = extractCertificate(aCertificateString);
if (!aCertificateBase64String.empty())
{
- OUString aBase64OUString = OUString::createFromAscii(aCertificateBase64String.c_str());
+ OUString aBase64OUString = OUString::createFromAscii(aCertificateBase64String);
comphelper::Base64::decode(aCertificateSequence, aBase64OUString);
}
else
@@ -5889,7 +7042,7 @@ static bool doc_addCertificate(LibreOfficeKitDocument* pThis,
std::copy(pCertificateBinary, pCertificateBinary + nCertificateBinarySize, aCertificateSequence.getArray());
}
- uno::Reference<security::XCertificate> xCertificate = xCertificateCreator->addDERCertificateToTheDatabase(aCertificateSequence, "TCu,Cu,Tu");
+ uno::Reference<security::XCertificate> xCertificate = xCertificateCreator->addDERCertificateToTheDatabase(aCertificateSequence, u"TCu,Cu,Tu"_ustr);
if (!xCertificate.is())
return false;
@@ -5927,13 +7080,12 @@ static void doc_resizeWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWin
const int nWidth, const int nHeight)
{
SolarMutexGuard aGuard;
- if (gImpl)
- gImpl->maLastExceptionMsg.clear();
+ SetLastExceptionMsg();
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
if (!pWindow)
{
- gImpl->maLastExceptionMsg = "Document doesn't support dialog resizing, or window not found.";
+ SetLastExceptionMsg(u"Document doesn't support dialog resizing, or window not found."_ustr);
return;
}
@@ -5948,7 +7100,7 @@ static void doc_completeFunction(LibreOfficeKitDocument* pThis, const char* pFun
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return;
}
@@ -5968,14 +7120,14 @@ static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis, const char* pA
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering!");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering!"_ustr);
return;
}
// Sanity check
- if (aMap.find("type") == aMap.end() || aMap.find("cmd") == aMap.end())
+ if (aMap.find(u"type"_ustr) == aMap.end() || aMap.find(u"cmd"_ustr) == aMap.end())
{
- SetLastExceptionMsg("Wrong arguments for sendFormFieldEvent!");
+ SetLastExceptionMsg(u"Wrong arguments for sendFormFieldEvent!"_ustr);
return;
}
@@ -5998,7 +7150,7 @@ static bool doc_renderSearchResult(LibreOfficeKitDocument* pThis,
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
- SetLastExceptionMsg("Document doesn't support tiled rendering");
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
return false;
}
@@ -6032,6 +7184,86 @@ static bool doc_renderSearchResult(LibreOfficeKitDocument* pThis,
return true;
}
+static void doc_sendContentControlEvent(LibreOfficeKitDocument* pThis, const char* pArguments)
+{
+ SolarMutexGuard aGuard;
+
+ // Supported in Writer only
+ if (doc_getDocumentType(pThis) != LOK_DOCTYPE_TEXT)
+ {
+ return;
+ }
+
+ if (SfxViewShell::IsCurrentLokViewReadOnly())
+ return;
+
+ StringMap aMap(jsdialog::jsonToStringMap(pArguments));
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr);
+ return;
+ }
+
+ // Sanity check
+ if (aMap.find(u"type"_ustr) == aMap.end())
+ {
+ SetLastExceptionMsg(u"Missing 'type' argument for sendContentControlEvent"_ustr);
+ return;
+ }
+
+ pDoc->executeContentControlEvent(aMap);
+}
+
+static void doc_setViewTimezone(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis*/, int nId,
+ const char* pTimezone)
+{
+ comphelper::ProfileZone aZone("doc_setViewTimezone");
+
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ // Leave the default if we get a null timezone.
+ if (pTimezone)
+ {
+ OUString sTimezone = OStringToOUString(pTimezone, RTL_TEXTENCODING_UTF8);
+ SfxLokHelper::setViewTimezone(nId, true, sTimezone);
+ }
+}
+
+static void doc_setViewReadOnly(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* pThis, int nId, const bool readOnly)
+{
+ comphelper::ProfileZone aZone("doc_setViewReadOnly");
+
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ doc_setView(pThis, nId);
+ SfxViewShell::Current()->SetLokReadOnlyView(readOnly);
+}
+
+static void doc_setAllowChangeComments(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* pThis, int nId, const bool allow)
+{
+ comphelper::ProfileZone aZone("doc_setAllowChangeComments");
+
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ doc_setView(pThis, nId);
+ SfxViewShell::Current()->SetAllowChangeComments(allow);
+}
+
+static void doc_setAccessibilityState(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* pThis, int nId, bool nEnabled)
+{
+ SolarMutexGuard aGuard;
+
+ int nDocType = getDocumentType(pThis);
+ if (!(nDocType == LOK_DOCTYPE_TEXT || nDocType == LOK_DOCTYPE_PRESENTATION || nDocType == LOK_DOCTYPE_SPREADSHEET))
+ return;
+
+ SfxLokHelper::setAccessibilityState(nId, nEnabled);
+}
+
static char* lo_getError (LibreOfficeKit *pThis)
{
comphelper::ProfileZone aZone("lo_getError");
@@ -6059,11 +7291,11 @@ static char* lo_getFilterTypes(LibreOfficeKit* pThis)
if (!xSFactory.is())
{
- pImpl->maLastExceptionMsg = "Service factory is not available";
+ pImpl->maLastExceptionMsg = u"Service factory is not available"_ustr;
return nullptr;
}
- uno::Reference<container::XNameAccess> xTypeDetection(xSFactory->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xTypeDetection(xSFactory->createInstance(u"com.sun.star.document.TypeDetection"_ustr), uno::UNO_QUERY);
const uno::Sequence<OUString> aTypes = xTypeDetection->getElementNames();
tools::JsonWriter aJson;
for (const OUString& rType : aTypes)
@@ -6075,13 +7307,13 @@ static char* lo_getFilterTypes(LibreOfficeKit* pThis)
OUString aValue;
if (it != std::cend(aValues) && (it->Value >>= aValue) && !aValue.isEmpty())
{
- auto typeNode = aJson.startNode(rType.toUtf8().getStr());
+ auto typeNode = aJson.startNode(rType.toUtf8());
aJson.put("MediaType", aValue.toUtf8());
}
}
}
- return aJson.extractData();
+ return convertOString(aJson.finishAndGetAsOString());
}
static void lo_setOptionalFeatures(LibreOfficeKit* pThis, unsigned long long const features)
@@ -6122,12 +7354,15 @@ static char* lo_getVersionInfo(SAL_UNUSED_PARAMETER LibreOfficeKit* /*pThis*/)
{
SetLastExceptionMsg();
return convertOUString(ReplaceStringHookProc(
- "{ "
+ u"{ "
"\"ProductName\": \"%PRODUCTNAME\", "
"\"ProductVersion\": \"%PRODUCTVERSION\", "
"\"ProductExtension\": \"%PRODUCTEXTENSION\", "
- "\"BuildId\": \"%BUILDID\" "
- "}"));
+ "\"BuildId\": \"%BUILDID\""
+#if BUILDCONFIG_RECORDED
+ ", \"BuildConfig\": \"" BUILDCONFIG "\""
+#endif
+ " }"_ustr));
}
static void aBasicErrorFunc(const OUString& rError, const OUString& rAction)
@@ -6156,7 +7391,7 @@ static bool initialize_uno(const OUString& aAppProgramURL)
if (!xContext.is())
{
- SetLastExceptionMsg("XComponentContext could not be created");
+ SetLastExceptionMsg(u"XComponentContext could not be created"_ustr);
SAL_INFO("lok", "XComponentContext could not be created");
return false;
}
@@ -6164,7 +7399,7 @@ static bool initialize_uno(const OUString& aAppProgramURL)
xFactory = xContext->getServiceManager();
if (!xFactory.is())
{
- SetLastExceptionMsg("XMultiComponentFactory could not be created");
+ SetLastExceptionMsg(u"XMultiComponentFactory could not be created"_ustr);
SAL_INFO("lok", "XMultiComponentFactory could not be created");
return false;
}
@@ -6203,7 +7438,7 @@ static void lo_runLoop(LibreOfficeKit* /*pThis*/,
LibreOfficeKitWakeCallback pWakeCallback,
void* pData)
{
-#if defined(IOS) || defined(ANDROID)
+#if defined(IOS) || defined(ANDROID) || defined(__EMSCRIPTEN__)
Application::GetSolarMutex().acquire();
#endif
@@ -6214,7 +7449,7 @@ static void lo_runLoop(LibreOfficeKit* /*pThis*/,
Application::UpdateMainThread();
soffice_main();
}
-#if defined(IOS) || defined(ANDROID)
+#if defined(IOS) || defined(ANDROID) || defined(__EMSCRIPTEN__)
vcl::lok::unregisterPollCallbacks();
Application::ReleaseSolarMutex();
#endif
@@ -6244,6 +7479,43 @@ static void lo_status_indicator_callback(void *data, comphelper::LibreOfficeKit:
}
}
+/// Used by preloadData (LibreOfficeKit) for providing different shortcuts for different languages.
+static void preLoadShortCutAccelerators()
+{
+ std::unordered_map<OUString, css::uno::Reference<com::sun::star::ui::XAcceleratorConfiguration>>& acceleratorConfs = SfxLokHelper::getAcceleratorConfs();
+ css::uno::Sequence<OUString> installedLocales(officecfg::Setup::Office::InstalledLocales::get()->getElementNames());
+ OUString actualLang = officecfg::Setup::L10N::ooLocale::get();
+
+ for (sal_Int32 i = 0; i < installedLocales.getLength(); i++)
+ {
+ // Set the UI language to current one, before creating the accelerator.
+ std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
+ officecfg::Setup::L10N::ooLocale::set(installedLocales[i], batch);
+ batch->commit();
+
+ // Supported module names: Writer, Calc, Draw, Impress
+ static constexpr OUString supportedModuleNames[] = {
+ u"com.sun.star.text.TextDocument"_ustr,
+ u"com.sun.star.sheet.SpreadsheetDocument"_ustr,
+ u"com.sun.star.drawing.DrawingDocument"_ustr,
+ u"com.sun.star.presentation.PresentationDocument"_ustr,
+ };
+ // Create the accelerators.
+ for (const OUString& supportedModuleName : supportedModuleNames)
+ {
+ OUString key = supportedModuleName + installedLocales[i];
+ acceleratorConfs[key] = svt::AcceleratorExecute::lok_createNewAcceleratorConfiguration(::comphelper::getProcessComponentContext(), supportedModuleName);
+ }
+ }
+
+ // Set the UI language back to default one.
+ std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
+ officecfg::Setup::L10N::ooLocale::set(actualLang, batch);
+ batch->commit();
+}
+
+void setLanguageToolConfig();
+
/// Used only by LibreOfficeKit when used by Online to pre-initialize
static void preloadData()
{
@@ -6251,10 +7523,10 @@ static void preloadData()
// Create user profile in the temp directory for loading the dictionaries
OUString sUserPath;
- rtl::Bootstrap::get("UserInstallation", sUserPath);
- utl::TempFile aTempDir(nullptr, true);
+ rtl::Bootstrap::get(u"UserInstallation"_ustr, sUserPath);
+ utl::TempFileNamed aTempDir(nullptr, true);
aTempDir.EnableKillingFile();
- rtl::Bootstrap::set("UserInstallation", aTempDir.GetURL());
+ rtl::Bootstrap::set(u"UserInstallation"_ustr, aTempDir.GetURL());
// Register the bundled extensions
desktop::Desktop::SynchronizeExtensionRepositories(true);
@@ -6262,7 +7534,20 @@ static void preloadData()
if(bAbort)
std::cerr << "CheckExtensionDependencies failed" << std::endl;
+ // inhibit forced 2nd synchronization from Main
+ ::rtl::Bootstrap::set( "DISABLE_EXTENSION_SYNCHRONIZATION", "true");
+
+ std::cerr << "Preload textencodings"; // sal_textenc
+ // Use RTL_TEXTENCODING_MS_1250 to trigger Impl_getTextEncodingData
+ // to dlopen sal_textenclo
+ (void)OUStringToOString(u"arbitrary string", RTL_TEXTENCODING_MS_1250);
+ std::cerr << "\n";
+
+ // setup LanguageTool config before spell checking init
+ setLanguageToolConfig();
+
// preload all available dictionaries
+ linguistic2::DictionaryList::create(comphelper::getProcessComponentContext());
css::uno::Reference<css::linguistic2::XLinguServiceManager> xLngSvcMgr =
css::linguistic2::LinguServiceManager::create(comphelper::getProcessComponentContext());
css::uno::Reference<linguistic2::XSpellChecker> xSpellChecker(xLngSvcMgr->getSpellChecker());
@@ -6270,11 +7555,11 @@ static void preloadData()
std::cerr << "Preloading dictionaries: ";
css::uno::Reference<linguistic2::XSupportedLocales> xSpellLocales(xSpellChecker, css::uno::UNO_QUERY_THROW);
uno::Sequence< css::lang::Locale > aLocales = xSpellLocales->getLocales();
- for (auto &it : std::as_const(aLocales))
+ for (auto& it : aLocales)
{
std::cerr << LanguageTag::convertToBcp47(it) << " ";
css::beans::PropertyValues aNone;
- xSpellChecker->isValid("forcefed", it, aNone);
+ xSpellChecker->isValid(u"forcefed"_ustr, it, aNone);
}
std::cerr << "\n";
@@ -6283,7 +7568,7 @@ static void preloadData()
// will cheaply load this missing "others" locale library. Appending an Asian locale in
// LOK_ALLOWLIST_LANGUAGES env-var also works but at the cost of loading that dictionary.
css::uno::Reference< css::i18n::XCalendar4 > xCal = css::i18n::LocaleCalendar2::create(comphelper::getProcessComponentContext());
- css::lang::Locale aAsianLocale = {"hi", "IN", ""};
+ css::lang::Locale aAsianLocale = { u"hi"_ustr, u"IN"_ustr, {} };
xCal->loadDefaultCalendar(aAsianLocale);
// preload all available thesauri
@@ -6291,27 +7576,36 @@ static void preloadData()
css::uno::Reference<linguistic2::XSupportedLocales> xThesLocales(xSpellChecker, css::uno::UNO_QUERY_THROW);
aLocales = xThesLocales->getLocales();
std::cerr << "Preloading thesauri: ";
- for (auto &it : std::as_const(aLocales))
+ for (auto& it : aLocales)
{
std::cerr << LanguageTag::convertToBcp47(it) << " ";
css::beans::PropertyValues aNone;
- xThesaurus->queryMeanings("forcefed", it, aNone);
+ xThesaurus->queryMeanings(u"forcefed"_ustr, it, aNone);
}
std::cerr << "\n";
+ std::cerr << "Preloading breakiterator: ";
+ css::uno::Reference< css::i18n::XBreakIterator > xBreakIterator = css::i18n::BreakIterator::create(xContext);
+ css::i18n::LineBreakUserOptions aUserOptions;
+ css::i18n::LineBreakHyphenationOptions aHyphOptions( LinguMgr::GetHyphenator(), css::uno::Sequence<beans::PropertyValue>(), 1 );
+ xBreakIterator->getLineBreak("", /*nMaxBreakPos*/0, aLocales[0], /*nMinBreakPos*/0, aHyphOptions, aUserOptions);
+
css::uno::Reference< css::ui::XAcceleratorConfiguration > xGlobalCfg = css::ui::GlobalAcceleratorConfiguration::create(
comphelper::getProcessComponentContext());
xGlobalCfg->getAllKeyEvents();
std::cerr << "Preload icons\n";
ImageTree &images = ImageTree::get();
- images.getImageUrl("forcefed.png", "style", "FO_oo");
+ images.getImageUrl(u"forcefed.png"_ustr, u"style"_ustr, u"FO_oo"_ustr);
+
+ std::cerr << "Preload short cut accelerators\n";
+ preLoadShortCutAccelerators();
std::cerr << "Preload languages\n";
// force load language singleton
SvtLanguageTable::HasLanguageType(LANGUAGE_SYSTEM);
- (void)LanguageTag::isValidBcp47("foo", nullptr);
+ (void)LanguageTag::isValidBcp47(u"foo"_ustr, nullptr);
std::cerr << "Preload fonts\n";
@@ -6324,7 +7618,7 @@ static void preloadData()
aLocales = xSpell->getLocales();
}
- for (const auto& aLocale : std::as_const(aLocales))
+ for (const auto& aLocale : aLocales)
{
//TODO: Add more types and cache more aggressively. For now this initializes the fontcache.
using namespace ::com::sun::star::i18n::ScriptType;
@@ -6338,19 +7632,15 @@ static void preloadData()
}
std::cerr << "Preload config\n";
-#ifdef __GNUC__
+#if defined __GNUC__ || defined __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
static SvtOptionsDialogOptions aDialogOptions;
static SvtCTLOptions aSvtCTLOptions;
- static SvtAccessibilityOptions aSvtAccessibilityOptions;
static svtools::ColorConfig aColorConfig;
static SvtMiscOptions aSvtMiscOptions;
- static SvtSlideSorterBarOptions aSvtSlideSorterBarOptions;
static SvtCommandOptions aSvtCommandOptions;
- static SvtCompatibilityOptions aSvtCompatibilityOptions;
- static SvtFilterOptions aSvtFilterOptions;
static SvtLinguConfig aSvtLinguConfig;
static SvtModuleOptions aSvtModuleOptions;
static SvtPathOptions aSvtPathOptions;
@@ -6363,12 +7653,29 @@ static void preloadData()
static MiscSettings aMiscSettings;
static HelpSettings aHelpSettings;
static AllSettings aAllSettings;
-#ifdef __GNUC__
+#if defined __GNUC__ || defined __clang__
#pragma GCC diagnostic pop
#endif
+ static constexpr OUString preloadComponents[] = {
+ u"private:factory/swriter"_ustr,
+ u"private:factory/scalc"_ustr,
+ u"private:factory/simpress"_ustr,
+ u"private:factory/sdraw"_ustr
+ };
+ // getting the remote LibreOffice service manager
+ uno::Reference<frame::XDesktop2> xCompLoader(frame::Desktop::create(xContext));
+
+ // Preload and close each of the main components once to initialize global state
+ uno::Sequence<css::beans::PropertyValue> szEmptyArgs(0);
+ for (const auto& component : preloadComponents)
+ {
+ auto xComp = xCompLoader->loadComponentFromURL(component, "_blank", 0, szEmptyArgs);
+ xComp->dispose();
+ }
+
// Set user profile's path back to the original one
- rtl::Bootstrap::set("UserInstallation", sUserPath);
+ rtl::Bootstrap::set(u"UserInstallation"_ustr, sUserPath);
}
namespace {
@@ -6381,11 +7688,46 @@ static void activateNotebookbar(std::u16string_view rApp)
if (aAppNode.isValid())
{
- aAppNode.setNodeValue("Active", makeAny(OUString("notebookbar_online.ui")));
+ static constexpr OUString sNoteBookbarName(u"notebookbar_online.ui"_ustr);
+ aAppNode.setNodeValue(u"Active"_ustr, Any(sNoteBookbarName));
+
+ const utl::OConfigurationNode aImplsNode = aAppNode.openNode(u"Modes"_ustr);
+ const Sequence<OUString> aModeNodeNames( aImplsNode.getNodeNames() );
+
+ for (const auto& rModeNodeName : aModeNodeNames)
+ {
+ const utl::OConfigurationNode aImplNode(aImplsNode.openNode(rModeNodeName));
+ if (!aImplNode.isValid())
+ continue;
+
+ OUString aCommandArg = comphelper::getString(aImplNode.getNodeValue(u"CommandArg"_ustr));
+ if (aCommandArg == "notebookbar.ui")
+ aImplNode.setNodeValue(u"CommandArg"_ustr, Any(sNoteBookbarName));
+ }
+
aAppNode.commit();
}
}
+void setHelpRootURL()
+{
+ const char* pHelpRootURL = ::getenv("LOK_HELP_URL");
+ if (pHelpRootURL)
+ {
+ OUString aHelpRootURL = OStringToOUString(pHelpRootURL, RTL_TEXTENCODING_UTF8);
+ try
+ {
+ std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::Help::HelpRootURL::set(aHelpRootURL, batch);
+ batch->commit();
+ }
+ catch (uno::Exception const& rException)
+ {
+ SAL_WARN("lok", "Failed to set the help root URL: " << rException.Message);
+ }
+ }
+}
+
void setCertificateDir()
{
const char* pEnvVarString = ::getenv("LO_CERTIFICATE_DATABASE_PATH");
@@ -6406,6 +7748,102 @@ void setCertificateDir()
}
}
+void setDeeplConfig()
+{
+ const char* pAPIUrlString = ::getenv("DEEPL_API_URL");
+ const char* pAuthKeyString = ::getenv("DEEPL_AUTH_KEY");
+ if (pAPIUrlString && pAuthKeyString)
+ {
+ OUString aAPIUrl = OStringToOUString(pAPIUrlString, RTL_TEXTENCODING_UTF8);
+ OUString aAuthKey = OStringToOUString(pAuthKeyString, RTL_TEXTENCODING_UTF8);
+ try
+ {
+ std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
+ officecfg::Office::Linguistic::Translation::Deepl::ApiURL::set(aAPIUrl, batch);
+ officecfg::Office::Linguistic::Translation::Deepl::AuthKey::set(aAuthKey, batch);
+ batch->commit();
+ }
+ catch(uno::Exception const& rException)
+ {
+ SAL_WARN("lok", "Failed to set Deepl API settings: " << rException.Message);
+ }
+ }
+}
+
+void setLanguageToolConfig()
+{
+ const char* pEnabled = ::getenv("LANGUAGETOOL_ENABLED");
+ const char* pBaseUrlString = ::getenv("LANGUAGETOOL_BASEURL");
+
+ if (pEnabled && pBaseUrlString)
+ {
+ const char* pUsername = ::getenv("LANGUAGETOOL_USERNAME");
+ const char* pApikey = ::getenv("LANGUAGETOOL_APIKEY");
+ const char* pSSLVerification = ::getenv("LANGUAGETOOL_SSL_VERIFICATION");
+ const char* pRestProtocol = ::getenv("LANGUAGETOOL_RESTPROTOCOL");
+
+ OUString aEnabled = OStringToOUString(pEnabled, RTL_TEXTENCODING_UTF8);
+ if (aEnabled != "true")
+ return;
+ OUString aBaseUrl = OStringToOUString(pBaseUrlString, RTL_TEXTENCODING_UTF8);
+ try
+ {
+ using LanguageToolCfg = officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
+ auto batch(comphelper::ConfigurationChanges::create());
+
+ LanguageToolCfg::BaseURL::set(aBaseUrl, batch);
+ LanguageToolCfg::IsEnabled::set(true, batch);
+ if (pSSLVerification)
+ {
+ OUString aSSLVerification = OStringToOUString(pSSLVerification, RTL_TEXTENCODING_UTF8);
+ LanguageToolCfg::SSLCertVerify::set(aSSLVerification == "true", batch);
+ }
+ if (pRestProtocol)
+ {
+ OUString aRestProtocol = OStringToOUString(pRestProtocol, RTL_TEXTENCODING_UTF8);
+ LanguageToolCfg::RestProtocol::set(aRestProtocol, batch);
+ }
+ if (pUsername && pApikey)
+ {
+ OUString aUsername = OStringToOUString(pUsername, RTL_TEXTENCODING_UTF8);
+ OUString aApiKey = OStringToOUString(pApikey, RTL_TEXTENCODING_UTF8);
+ LanguageToolCfg::Username::set(aUsername, batch);
+ LanguageToolCfg::ApiKey::set(aApiKey, batch);
+ }
+ batch->commit();
+
+ css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLangSrv =
+ css::linguistic2::LinguServiceManager::create(xContext);
+ if (xLangSrv.is())
+ {
+ css::uno::Reference<css::linguistic2::XSpellChecker> xSpell = xLangSrv->getSpellChecker();
+ if (xSpell.is())
+ {
+ Sequence<OUString> aEmpty;
+ Sequence<css::lang::Locale> aLocales = xSpell->getLocales();
+
+ uno::Reference<linguistic2::XProofreader> xGC(
+ xContext->getServiceManager()->createInstanceWithContext(u"org.openoffice.lingu.LanguageToolGrammarChecker"_ustr, xContext),
+ uno::UNO_QUERY_THROW);
+ uno::Reference<linguistic2::XSupportedLocales> xSuppLoc(xGC, uno::UNO_QUERY_THROW);
+
+ for (int itLocale = 0; itLocale < aLocales.getLength(); itLocale++)
+ {
+ // turn off spell checker if LanguageTool supports the locale already
+ if (xSuppLoc->hasLocale(aLocales[itLocale]))
+ xLangSrv->setConfiguredServices(
+ SN_SPELLCHECKER, aLocales[itLocale], aEmpty);
+ }
+ }
+ }
+ }
+ catch(uno::Exception const& rException)
+ {
+ SAL_WARN("lok", "Failed to set LanguageTool API settings: " << rException.Message);
+ }
+ }
+}
+
}
static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char* pUserProfileUrl)
@@ -6446,9 +7884,22 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
}
}
+ char* pAllowlist = ::getenv("LOK_HOST_ALLOWLIST");
+ if (pAllowlist)
+ {
+ HostFilter::setAllowedHostsRegex(pAllowlist);
+ }
+
// What stage are we at ?
if (pThis == nullptr)
+ {
eStage = PRE_INIT;
+ if (lok_preinit_2_called)
+ {
+ SAL_INFO("lok", "Create libreoffice object");
+ gImpl = new LibLibreOffice_Impl();
+ }
+ }
else if (bPreInited)
eStage = SECOND_INIT;
else
@@ -6469,8 +7920,19 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
comphelper::ProfileZone aZone("lok-init");
if (eStage == PRE_INIT)
+ {
rtl_alloc_preInit(true);
+ // Set the default timezone to the TZ envar, if set.
+ const char* tz = ::getenv("TZ");
+ SfxLokHelper::setDefaultTimezone(!!tz, tz ? OStringToOUString(tz, RTL_TEXTENCODING_UTF8)
+ : OUString());
+#ifdef UNX
+ if (urandom < 0)
+ urandom = open("/dev/urandom", O_RDONLY);
+#endif
+ }
+
if (eStage != SECOND_INIT)
comphelper::LibreOfficeKit::setActive();
@@ -6492,7 +7954,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
else
SAL_WARN("lok", "resolving <" << url << "> failed with " << +e);
}
- rtl::Bootstrap::set("UserInstallation", url);
+ rtl::Bootstrap::set(u"UserInstallation"_ustr, url);
if (eStage == SECOND_INIT)
utl::Bootstrap::reloadData();
}
@@ -6504,7 +7966,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
}
else
{
-#ifdef ANDROID
+#if defined ANDROID || defined EMSCRIPTEN
aAppPath = OUString::fromUtf8(lo_get_app_data_dir()) + "/program";
#else
// Fun conversion dance back and forth between URLs and system paths...
@@ -6577,7 +8039,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
return false;
// Force headless -- this is only for bitmap rendering.
- rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
+ rtl::Bootstrap::set(u"SAL_USE_VCLPLUGIN"_ustr, u"svp"_ustr);
// We specifically need to make sure we have the "headless"
// command arg set (various code specifically checks via
@@ -6615,12 +8077,12 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
// pre-load all component libraries.
if (!xContext.is())
- throw css::uno::DeploymentException("preInit: XComponentContext is not created");
+ throw css::uno::DeploymentException(u"preInit: XComponentContext is not created"_ustr);
css::uno::Reference< css::uno::XInterface > xService;
- xContext->getValueByName("/singletons/com.sun.star.lang.theServiceManager") >>= xService;
+ xContext->getValueByName(u"/singletons/com.sun.star.lang.theServiceManager"_ustr) >>= xService;
if (!xService.is())
- throw css::uno::DeploymentException("preInit: XMultiComponentFactory is not created");
+ throw css::uno::DeploymentException(u"preInit: XMultiComponentFactory is not created"_ustr);
css::uno::Reference<css::lang::XInitialization> aService(
xService, css::uno::UNO_QUERY_THROW);
@@ -6633,7 +8095,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
// 3) InitVCL()
{
comphelper::ProfileZone aInit("preload");
- aService->initialize({css::uno::makeAny<OUString>("preload")});
+ aService->initialize({css::uno::Any(u"preload"_ustr)});
}
{ // Force load some modules
comphelper::ProfileZone aInit("preload modules");
@@ -6647,7 +8109,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
Application::ReleaseSolarMutex();
}
- setLanguageAndLocale("en-US");
+ setLanguageAndLocale(u"en-US"_ustr);
}
if (eStage != PRE_INIT)
@@ -6657,6 +8119,14 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
OUString aNewTemp;
osl::FileBase::getTempDirURL(aNewTemp);
aOptions.SetTempPath(aNewTemp);
+ {
+ const char *pWorkPath = getenv("LOK_WORKDIR");
+ if (pWorkPath)
+ {
+ OString sWorkPath(pWorkPath);
+ aOptions.SetWorkPath(OStringToOUString(sWorkPath, RTL_TEXTENCODING_UTF8));
+ }
+ }
desktop::Desktop::CreateTemporaryDirectory();
// The RequestHandler is specifically set to be ready when all the other
@@ -6702,8 +8172,8 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
comphelper::ThreadPool::getSharedOptimalPool().shutdown();
}
-// Turn off quick editing on IOS and ANDROID
-#if defined IOS || defined ANDROID
+// Turn off quick editing on iOS, Android and Emscripten
+#if defined IOS || defined ANDROID || defined __EMSCRIPTEN__
if (officecfg::Office::Impress::Misc::TextObject::QuickEditing::get())
{
std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
@@ -6712,10 +8182,21 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
}
#endif
+
+ setHelpRootURL();
setCertificateDir();
+ setDeeplConfig();
+ setLanguageToolConfig();
if (bNotebookbar)
{
+ std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
+ officecfg::Office::UI::ToolbarMode::ActiveWriter::set(u"notebookbar_online.ui"_ustr, batch);
+ officecfg::Office::UI::ToolbarMode::ActiveCalc::set(u"notebookbar_online.ui"_ustr, batch);
+ officecfg::Office::UI::ToolbarMode::ActiveImpress::set(u"notebookbar_online.ui"_ustr, batch);
+ officecfg::Office::UI::ToolbarMode::ActiveDraw::set(u"notebookbar_online.ui"_ustr, batch);
+ batch->commit();
+
activateNotebookbar(u"Writer");
activateNotebookbar(u"Calc");
activateNotebookbar(u"Impress");
@@ -6732,11 +8213,18 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
SAL_JNI_EXPORT
LibreOfficeKit *libreofficekit_hook_2(const char* install_path, const char* user_profile_url)
{
- if (!gImpl)
+ static bool alreadyCalled = false;
+
+ if ((!lok_preinit_2_called && !gImpl) || (lok_preinit_2_called && !alreadyCalled))
{
- SAL_INFO("lok", "Create libreoffice object");
+ alreadyCalled = true;
+
+ if (!lok_preinit_2_called)
+ {
+ SAL_INFO("lok", "Create libreoffice object");
+ gImpl = new LibLibreOffice_Impl();
+ }
- gImpl = new LibLibreOffice_Impl();
if (!lo_initialize(gImpl, install_path, user_profile_url))
{
lo_destroy(gImpl);
@@ -6757,6 +8245,16 @@ int lok_preinit(const char* install_path, const char* user_profile_url)
return lo_initialize(nullptr, install_path, user_profile_url);
}
+SAL_JNI_EXPORT
+int lok_preinit_2(const char* install_path, const char* user_profile_url, LibreOfficeKit** kit)
+{
+ lok_preinit_2_called = true;
+ int result = lo_initialize(nullptr, install_path, user_profile_url);
+ if (kit != nullptr)
+ *kit = gImpl;
+ return result;
+}
+
static void lo_destroy(LibreOfficeKit* pThis)
{
SolarMutexClearableGuard aGuard;
@@ -6792,26 +8290,6 @@ static void lo_destroy(LibreOfficeKit* pThis)
SAL_INFO("lok", "LO Destroy Done");
}
-#ifdef IOS
-
-// Used by the unmaintained LibreOfficeLight app. Once that has been retired, get rid of this, too.
-
-__attribute__((visibility("default")))
-void temporaryHackToInvokeCallbackHandlers(LibreOfficeKitDocument* pThis)
-{
- SolarMutexGuard aGuard;
- LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-
- int nOrigViewId = doc_getView(pThis);
-
- if (nOrigViewId >= 0 && pDocument->mpCallbackFlushHandlers[nOrigViewId])
- {
- pDocument->mpCallbackFlushHandlers[nOrigViewId]->Invoke();
- }
-}
-
-#endif
-
} // extern "C"
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */