desktop/source/lib/init.cxx | 3 ++- include/sfx2/lokhelper.hxx | 2 ++ sfx2/source/view/frmload.cxx | 30 ++++++++++++++++++++++++++++++ sfx2/source/view/lokhelper.cxx | 15 +++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-)
New commits: commit 1d7ee6942f1f1ccdb8aeb253c1cf8ce0c5f63421 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Tue Feb 20 16:09:13 2024 -0400 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Fri Mar 22 10:29:55 2024 +0100 lok: add property descriptor "Theme" Add option to load the document with a "theme" property name. Format: "document:theme_name" Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: Iaef3d2e8962af526496e5cc95021fa94dca17939 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163671 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 9288a67c2181..323d0751cb6d 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2784,7 +2784,8 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, comphelper::makePropertyValue("InteractionHandler", xInteraction), comphelper::makePropertyValue("MacroExecutionMode", nMacroExecMode), comphelper::makePropertyValue("AsTemplate", false), - comphelper::makePropertyValue("Silent", !aBatch.isEmpty()) + comphelper::makePropertyValue("Silent", !aBatch.isEmpty()), + comphelper::makePropertyValue("Theme", extractParameter(aOptions, u"Theme")) }; /* TODO diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index e8904d013f75..35ed5109f5c0 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -131,6 +131,8 @@ public: static LOKDeviceFormFactor getDeviceFormFactor(); /// Set the device form factor that should be used for a new view. static void setDeviceFormFactor(std::u16string_view rDeviceFormFactor); + /// Get the document type + static OUString getDocumentType(const OUString& sDocumentService); /// Set timezone of the given view. /// @isSet true to use @rTimezone, even if it's empty. Otherwise, no timezone. diff --git a/sfx2/source/view/frmload.cxx b/sfx2/source/view/frmload.cxx index f03b08fe5886..e4acd00ffa37 100644 --- a/sfx2/source/view/frmload.cxx +++ b/sfx2/source/view/frmload.cxx @@ -26,6 +26,7 @@ #include <sfx2/doctempl.hxx> #include <sfx2/fcontnr.hxx> #include <sfx2/frame.hxx> +#include <sfx2/lokhelper.hxx> #include <sfx2/objsh.hxx> #include <sfx2/request.hxx> #include <sfx2/sfxsids.hrc> @@ -48,6 +49,7 @@ #include <com/sun/star/util/XCloseable.hpp> #include <comphelper/interaction.hxx> +#include <comphelper/lok.hxx> #include <comphelper/namedvaluecollection.hxx> #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/implbase.hxx> @@ -57,6 +59,7 @@ #include <sal/log.hxx> #include <svl/eitem.hxx> #include <svl/stritem.hxx> +#include <svtools/colorcfg.hxx> #include <unotools/fcm.hxx> #include <unotools/moduleoptions.hxx> #include <comphelper/diagnose_ex.hxx> @@ -708,6 +711,7 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const Sequence< PropertyValue >& rA const OUString sServiceName = aDescriptor.getOrDefault( "DocumentService", OUString() ); xModel.set( m_aContext->getServiceManager()->createInstanceWithContext(sServiceName, m_aContext), UNO_QUERY_THROW ); + // load resp. init it const Reference< XLoadable > xLoadable( xModel, UNO_QUERY_THROW ); if ( bInitNewModel ) @@ -766,6 +770,32 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const Sequence< PropertyValue >& rA } bLoadSuccess = true; + + const OUString sThemes = aDescriptor.getOrDefault("Theme", OUString()); + if (comphelper::LibreOfficeKit::isActive() && !sThemes.isEmpty()) + { + const OUString sServiceName = aDescriptor.getOrDefault("DocumentService", OUString()); + OUString sTheme, sType, sName; + sal_Int32 nTheme = 0, nIndex = 0; + do + { + sTheme = sThemes.getToken(0, ';', nTheme); + sType = sTheme.getToken(0, ':', nIndex); + sName = sTheme.getToken(0, ':', nIndex); + if (sType == SfxLokHelper::getDocumentType(sServiceName)) + { + svtools::EditableColorConfig aConfig; + if (aConfig.GetCurrentSchemeName() != sName) + { + aConfig.LoadScheme(sName); + break; + } + } + nIndex = 0; + + } + while ( nTheme >= 0 ); + } } catch ( Exception& ) { diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index e6fc7e8c7114..b22d1e488283 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -388,6 +388,21 @@ void SfxLokHelper::setDeviceFormFactor(std::u16string_view rDeviceFormFactor) g_deviceFormFactor = LOKDeviceFormFactor::UNKNOWN; } +OUString SfxLokHelper::getDocumentType(const OUString& sDocumentService) +{ + if (sDocumentService == "com.sun.star.sheet.SpreadsheetDocument") + return "spreadsheet"; + else if (sDocumentService == "com.sun.star.presentation.PresentationDocument") + return "presentation"; + else if (sDocumentService == "com.sun.star.drawing.DrawingDocument") + return "drawing"; + else if (sDocumentService == "com.sun.star.text.TextDocument" || + sDocumentService == "com.sun.star.text.WebDocument") + return "text"; + + return OUString(); +} + void SfxLokHelper::setDefaultTimezone(bool isSet, const OUString& rTimezone) { g_isDefaultTimezoneSet = isSet;