diff options
Diffstat (limited to '')
64 files changed, 7625 insertions, 0 deletions
diff --git a/include/unotools/VersionConfig.hxx b/include/unotools/VersionConfig.hxx new file mode 100644 index 000000000..6142f5548 --- /dev/null +++ b/include/unotools/VersionConfig.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ +#pragma once + +#include <officecfg/Setup.hxx> +#include <unotools/configmgr.hxx> +#include <o3tl/string_view.hxx> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +namespace utl +{ +/** This method is called when there's a need to determine if the + * current version of LibreOffice has been upgraded to a newer one. + + @param aUpdateVersion This variable is used to determine if + LibreOffice's previous version should be updated. + */ +static bool isProductVersionUpgraded(bool aUpdateVersion) +{ + OUString sSetupVersion = utl::ConfigManager::getProductVersion(); + sal_Int32 iCurrent = o3tl::toInt32(o3tl::getToken(sSetupVersion, 0, '.')) * 10 + + o3tl::toInt32(o3tl::getToken(sSetupVersion, 1, '.')); + OUString sLastVersion = officecfg::Setup::Product::ooSetupLastVersion::get().value_or("0.0"); + sal_Int32 iLast = o3tl::toInt32(o3tl::getToken(sLastVersion, 0, '.')) * 10 + + o3tl::toInt32(o3tl::getToken(sLastVersion, 1, '.')); + if (iCurrent > iLast) + { + if (aUpdateVersion) + { //update lastversion + try + { + std::shared_ptr<comphelper::ConfigurationChanges> batch( + comphelper::ConfigurationChanges::create()); + officecfg::Setup::Product::ooSetupLastVersion::set(sSetupVersion, batch); + batch->commit(); + } + catch (css::lang::IllegalArgumentException&) + { //If the value was readOnly. + SAL_WARN("desktop.updater", "Updating property ooSetupLastVersion to version " + << sSetupVersion + << " failed (read-only property?)"); + } + } + return true; + } + return false; +} +} diff --git a/include/unotools/ZipPackageHelper.hxx b/include/unotools/ZipPackageHelper.hxx new file mode 100644 index 000000000..7ac35b801 --- /dev/null +++ b/include/unotools/ZipPackageHelper.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_ZIPPACKAGEHELPER_HXX +#define INCLUDED_UNOTOOLS_ZIPPACKAGEHELPER_HXX + +#include <unotools/unotoolsdllapi.h> + +#include <com/sun/star/uno/XInterface.hpp> + +namespace com::sun::star::container { class XHierarchicalNameAccess; } +namespace com::sun::star::lang { class XSingleServiceFactory; } +namespace com::sun::star::uno { class XComponentContext; } + +namespace utl { + +class UNOTOOLS_DLLPUBLIC ZipPackageHelper +{ +public: + ZipPackageHelper( const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const OUString& sPackageURL); + + void savePackage(); + + /// @throws css::uno::Exception + void addFile( css::uno::Reference< css::uno::XInterface > const & xRootFolder, + const OUString& rSourceFile ); + + /// @throws css::uno::Exception + css::uno::Reference< css::uno::XInterface > addFolder( css::uno::Reference< css::uno::XInterface > const & xRootFolder, + const OUString& rName ); + + void addFolderWithContent( css::uno::Reference< css::uno::XInterface > const & xRootFolder, + const OUString& rDirURL ); + + css::uno::Reference< css::uno::XInterface >& getRootFolder(); + +private: + css::uno::Reference< css::uno::XComponentContext > mxContext; + css::uno::Reference< css::container::XHierarchicalNameAccess > mxHNameAccess; + css::uno::Reference< css::lang::XSingleServiceFactory > mxFactory; + css::uno::Reference< css::uno::XInterface > mxRootFolder; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/accessiblerelationsethelper.hxx b/include/unotools/accessiblerelationsethelper.hxx new file mode 100644 index 000000000..35277ae5b --- /dev/null +++ b/include/unotools/accessiblerelationsethelper.hxx @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_ACCESSIBLERELATIONSETHELPER_HXX +#define INCLUDED_UNOTOOLS_ACCESSIBLERELATIONSETHELPER_HXX + +#include <unotools/unotoolsdllapi.h> + +#include <com/sun/star/accessibility/XAccessibleRelationSet.hpp> +#include <cppuhelper/implbase.hxx> +#include <mutex> +#include <vector> + +//= XAccessibleRelationSet helper classes + +//... namespace utl ....................................................... +namespace utl +{ +/** @descr + This base class provides an implementation of the + <code>AccessibleRelationSet</code> service. +*/ +class UNOTOOLS_DLLPUBLIC AccessibleRelationSetHelper final + : public cppu::WeakImplHelper<css::accessibility::XAccessibleRelationSet> +{ +public: + //===== internal ======================================================== + AccessibleRelationSetHelper(); + AccessibleRelationSetHelper(const AccessibleRelationSetHelper& rHelper); + +private: + virtual ~AccessibleRelationSetHelper() override; + +public: + //===== XAccessibleRelationSet ========================================== + + /** Returns the number of relations in this relation set. + + @return + Returns the number of relations or zero if there are none. + */ + virtual sal_Int32 SAL_CALL getRelationCount() override; + + /** Returns the relation of this relation set that is specified by + the given index. + + @param nIndex + This index specifies the relatio to return. + + @return + For a valid index, i.e. inside the range 0 to the number of + relations minus one, the returned value is the requested + relation. If the index is invalid then the returned relation + has the type INVALID. + + */ + virtual css::accessibility::AccessibleRelation SAL_CALL getRelation(sal_Int32 nIndex) override; + + /** Tests whether the relation set contains a relation matching the + specified key. + + @param aRelationType + The type of relation to look for in this set of relations. This + has to be one of the constants of + AccessibleRelationType. + + @return + Returns <TRUE/> if there is a (at least one) relation of the + given type and <FALSE/> if there is no such relation in the set. + */ + virtual sal_Bool SAL_CALL containsRelation(sal_Int16 aRelationType) override; + + /** Retrieve and return the relation with the given relation type. + + @param aRelationType + The type of the relation to return. This has to be one of the + constants of AccessibleRelationType. + + @return + If a relation with the given type could be found than (a copy + of) this relation is returned. Otherwise a relation with the + type INVALID is returned. + */ + virtual css::accessibility::AccessibleRelation SAL_CALL + getRelationByType(sal_Int16 aRelationType) override; + + /// @throws uno::RuntimeException + void AddRelation(const css::accessibility::AccessibleRelation& rRelation); + + //===== XTypeProvider =================================================== + + /** Returns a sequence of all supported interfaces. + */ + virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override; + + /** Returns an implementation id. + */ + virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override; + +private: + /// Mutex guarding this object. + std::mutex maMutex; + /// The implementation of this helper interface. + std::vector<css::accessibility::AccessibleRelation> maRelations; +}; +} +//... namespace utl ....................................................... +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/accessiblestatesethelper.hxx b/include/unotools/accessiblestatesethelper.hxx new file mode 100644 index 000000000..b1e5644f1 --- /dev/null +++ b/include/unotools/accessiblestatesethelper.hxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_ACCESSIBLESTATESETHELPER_HXX +#define INCLUDED_UNOTOOLS_ACCESSIBLESTATESETHELPER_HXX + +#include <unotools/unotoolsdllapi.h> + +#include <com/sun/star/accessibility/XAccessibleStateSet.hpp> +#include <cppuhelper/implbase.hxx> +#include <mutex> + +//= XAccessibleStateSet helper classes + +//... namespace utl ....................................................... +namespace utl +{ +/** @descr + This base class provides an implementation of the + <code>AccessibleStateSet</code> service. +*/ +class UNOTOOLS_DLLPUBLIC AccessibleStateSetHelper final + : public cppu::WeakImplHelper<css::accessibility::XAccessibleStateSet> +{ +public: + //===== internal ======================================================== + + AccessibleStateSetHelper(); + /** constructs an object with some states initially set + + <p>This ctor is compatible with + <method scope="comphelper">OAccessibleImplementationAccess::implGetForeignControlledStates</method></p> + + @param _nInitialStates + is a bit mask. Every bit 2^n means that the state number n (as got from the + AccessibleStateType constants) should be set initially. + */ + AccessibleStateSetHelper(const sal_Int64 _nInitialStates); + + AccessibleStateSetHelper(const AccessibleStateSetHelper& rHelper); + +private: + virtual ~AccessibleStateSetHelper() override; + +public: + //===== XAccessibleStateSet ============================================== + + /** Checks whether the current state set is empty. + + @return + Returns <TRUE/> if there is no state in this state set and + <FALSE/> if there is at least one state set in it. + */ + virtual sal_Bool SAL_CALL isEmpty() override; + + /** Checks if the given state is a member of the state set of this + object. + + @param aState + The state for which to check membership. This has to be one of + the constants of AccessibleStateType. + + @return + Returns <TRUE/> if the given state is a member of this object's + state set and <FALSE/> otherwise. + */ + virtual sal_Bool SAL_CALL contains(sal_Int16 aState) override; + + /** Checks if all of the given states are in this object's state + set. + + @param aStateSet + This sequence of states is interpreted as set and every of its + members, duplicates are ignored, is checked for membership in + this object's state set. Each state has to be one of the + constants of AccessibleStateType. + + @return + Returns <TRUE/> if all states of the given state set are members + of this object's state set. <FALSE/> is returned if at least + one of the states in the given state is not a member of this + object's state set. + */ + virtual sal_Bool SAL_CALL containsAll(const css::uno::Sequence<sal_Int16>& rStateSet) override; + + /** Returns a sequence of all states. + */ + virtual css::uno::Sequence<sal_Int16> SAL_CALL getStates() override; + + /** Adds a state to the set. + + @throws css::uno::RuntimeException + */ + void AddState(sal_Int16 aState); + + /** Removes a state from the set if the set contains the state, otherwise nothing is done. + + @throws css::uno::RuntimeException + */ + void RemoveState(sal_Int16 aState); + + //===== XTypeProvider =================================================== + + /** Returns a sequence of all supported interfaces. + */ + virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override; + + /** Returns an implementation id. + */ + virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override; + +private: + /// Mutex guarding this object. + std::mutex maMutex; + /// The implementation of this helper interface. + sal_uInt64 maStates; +}; +} +//... namespace utl ....................................................... +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/bootstrap.hxx b/include/unotools/bootstrap.hxx new file mode 100644 index 000000000..3f8774140 --- /dev/null +++ b/include/unotools/bootstrap.hxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_BOOTSTRAP_HXX +#define INCLUDED_UNOTOOLS_BOOTSTRAP_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> + +namespace utl +{ + /** provides configuration information needed for application startup. + + This class handles the startup information for the office application. + It encapsulates knowledge of how to retrieve such information and how + to diagnose failures to retrieve required data. + + */ + class UNOTOOLS_DLLPUBLIC Bootstrap + { + // the static interface + public: // some common information items + + /// retrieve the product key; defaults to executable name (without extension) + static OUString getProductKey(); + + /// retrieve the product key; uses the given default, if not found + static OUString getProductKey(OUString const& _sDefault); + + /// retrieve the BUILDID information item; uses the given default, if not found + static OUString getBuildIdData(OUString const& _sDefault); + + /// reload cached data + static void reloadData(); + + public: // retrieve path information about the installation location + enum PathStatus + { + PATH_EXISTS, // Success: Found a path to an existing file or directory + PATH_VALID, // Found a valid path, but the file or directory does not exist + DATA_INVALID, // Retrieved a string for this path, that is not a valid file url or system path + DATA_MISSING, // Could not retrieve any data for this path + DATA_UNKNOWN // No attempt to retrieve data for this path was made + }; + + /// get a file URL to the common base installation [${insturl}] + static PathStatus locateBaseInstallation(OUString& _rURL); + + /// get a file URL to the user installation [${userurl}] + static PathStatus locateUserInstallation(OUString& _rURL); + + /// get a file URL to the user data directory [default is ${userurl}/user] + static PathStatus locateUserData(OUString& _rURL); + + // the next two items are mainly supported for diagnostic purposes. both items may be unused + /// get a file URL to the bootstrap INI file used [e.g. ${insturl}/program/bootraprc] + static PathStatus locateBootstrapFile(OUString& _rURL); + /// get a file URL to the version locator INI file used [e.g. ${SYSUSERCONFIG}/sversion.ini] + static PathStatus locateVersionFile(OUString& _rURL); + + public: // evaluate the validity of the installation + /// high-level status of bootstrap success + enum Status + { + DATA_OK, /// user-dir and share-dir do exist, product key found or can be defaulted to exe-name + MISSING_USER_INSTALL, /// ${userurl} does not exist; or version-file cannot be found or is invalid + INVALID_USER_INSTALL, /// can locate ${userurl}, but user-dir is missing + INVALID_BASE_INSTALL /// other failure: e.g. cannot locate share-dir; bootstraprc missing or invalid; no product key + }; + + /// error code for detailed diagnostics of bootstrap failures + enum FailureCode + { + NO_FAILURE, /// bootstrap was successful + MISSING_INSTALL_DIRECTORY, /// the shared installation directory could not be located + MISSING_BOOTSTRAP_FILE, /// the bootstrap INI file could not be found or read + MISSING_BOOTSTRAP_FILE_ENTRY, /// the bootstrap INI is missing a required entry + INVALID_BOOTSTRAP_FILE_ENTRY, /// the bootstrap INI contains invalid data + MISSING_VERSION_FILE, /// the version locator INI file could not be found or read + MISSING_VERSION_FILE_ENTRY, /// the version locator INI has no entry for this version + INVALID_VERSION_FILE_ENTRY, /// the version locator INI entry is not a valid directory URL + MISSING_USER_DIRECTORY, /// the user installation directory does not exist + INVALID_BOOTSTRAP_DATA /// some bootstrap data was invalid in unexpected ways + }; + + /** Evaluates the status of the installation and returns a diagnostic + message and error code corresponding to this status + */ + static Status checkBootstrapStatus(OUString& _rDiagnosticMessage, FailureCode& _rErrCode); + + public: + /// get the working directory of the process + static bool getProcessWorkingDir(OUString &rUrl); + + public: + // singleton impl-class + class UNOTOOLS_DLLPRIVATE Impl; + static const Impl& data(); // the data related to the bootstrap.ini file + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/calendarwrapper.hxx b/include/unotools/calendarwrapper.hxx new file mode 100644 index 000000000..aa0bb345c --- /dev/null +++ b/include/unotools/calendarwrapper.hxx @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_CALENDARWRAPPER_HXX +#define INCLUDED_UNOTOOLS_CALENDARWRAPPER_HXX + +#include <tools/datetime.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/i18n/Calendar2.hpp> +#include <unotools/unotoolsdllapi.h> + +namespace com::sun::star::uno { class XComponentContext; } +namespace com::sun::star::i18n { class XCalendar4; } +namespace com::sun::star::lang { struct Locale; } + +class UNOTOOLS_DLLPUBLIC CalendarWrapper +{ + css::uno::Reference< css::i18n::XCalendar4 > xC; + + const DateTime aEpochStart; // 1Jan1970 + +public: + CalendarWrapper( + const css::uno::Reference< css::uno::XComponentContext > & rxContext + ); + ~CalendarWrapper(); + + // wrapper implementations of XCalendar + + /** Load the default calendar of a locale. + + This adds a bool bTimeZoneUTC parameter which is not part of the UNO API to + facilitate handling of non time zone aware data. + + @param bTimeZoneUTC + Default <TRUE/>. If <FALSE/>, the system's timezone is assigned + to the calendar, including all DST quirks like not existing + times on DST transition dates when switching to/from DST. As + current implementations and number parser/formatter don't store + or convert or calculate with time zones it is safer to use UTC, + which is not DST afflicted, otherwise surprises are lurking + (for example tdf#92503). + */ + void loadDefaultCalendar( const css::lang::Locale& rLocale, bool bTimeZoneUTC = true ); + /// This adds a bTimeZoneUTC parameter which is not part of the API. + void loadCalendar( const OUString& rUniqueID, const css::lang::Locale& rLocale, bool bTimeZoneUTC = true ); + + /* XXX NOTE: the time zone taking UNO API functions are not implemented as + * wrapper interface as they are not necessary/used so far. These are: + void loadDefaultCalendarTZ( const css::lang::Locale& rLocale, const OUString& rTimeZone ); + void loadCalendarTZ( const OUString& rUniqueID, const css::lang::Locale& rLocale, const OUString& rTimeZone ); + */ + + css::uno::Sequence< OUString > getAllCalendars( const css::lang::Locale& rLocale ) const; + OUString getUniqueID() const; + /// set UTC date/time + void setDateTime( double fTimeInDays ); + /// get UTC date/time + double getDateTime() const; + + // For local setDateTime() and getDateTime() see further down at wrapper + // implementations of XCalendar4. + + // wrapper implementations of XCalendar + + void setValue( sal_Int16 nFieldIndex, sal_Int16 nValue ); + bool isValid() const; + sal_Int16 getValue( sal_Int16 nFieldIndex ) const; + sal_Int16 getFirstDayOfWeek() const; + sal_Int16 getNumberOfMonthsInYear() const; + sal_Int16 getNumberOfDaysInWeek() const; + OUString getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const; + + // wrapper implementations of XExtendedCalendar + + OUString getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const; + + // wrapper implementations of XCalendar3 + + css::i18n::Calendar2 getLoadedCalendar() const; + css::uno::Sequence< css::i18n::CalendarItem2 > getDays() const; + css::uno::Sequence< css::i18n::CalendarItem2 > getMonths() const; + css::uno::Sequence< css::i18n::CalendarItem2 > getGenitiveMonths() const; + css::uno::Sequence< css::i18n::CalendarItem2 > getPartitiveMonths() const; + + // wrapper implementations of XCalendar4 + + /// set local date/time + void setLocalDateTime( double fTimeInDays ); + /// get local date/time + double getLocalDateTime() const; + + // convenience methods + + /// get epoch start (should be 01Jan1970) + const DateTime& getEpochStart() const + { return aEpochStart; } + + /// set a local (!) Gregorian DateTime + void setGregorianDateTime( const DateTime& rDateTime ) + { setLocalDateTime( rDateTime - aEpochStart ); } + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/caserotate.hxx b/include/unotools/caserotate.hxx new file mode 100644 index 000000000..6e61785be --- /dev/null +++ b/include/unotools/caserotate.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef INCLUDED_UNOTOOLS_CASEROTATE_HXX +#define INCLUDED_UNOTOOLS_CASEROTATE_HXX + +#include <sal/config.h> +#include <unotools/unotoolsdllapi.h> + +enum class TransliterationFlags; + +//TODO Use XCharacterClassification::getStringType to determine the current +//(possibly mixed) case type and rotate to the next one + +class UNOTOOLS_DLLPUBLIC RotateTransliteration +{ +private: + int nF3ShiftCounter; + +public: + RotateTransliteration() + : nF3ShiftCounter(0) + { + } + TransliterationFlags getNextMode(); +}; + +#endif +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/charclass.hxx b/include/unotools/charclass.hxx new file mode 100644 index 000000000..c76c7ae35 --- /dev/null +++ b/include/unotools/charclass.hxx @@ -0,0 +1,181 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_CHARCLASS_HXX +#define INCLUDED_UNOTOOLS_CHARCLASS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <i18nlangtag/languagetag.hxx> +#include <com/sun/star/i18n/DirectionProperty.hpp> +#include <com/sun/star/i18n/KCharacterType.hpp> +#include <com/sun/star/i18n/ParseResult.hpp> +#include <com/sun/star/i18n/UnicodeScript.hpp> +#include <com/sun/star/uno/Reference.hxx> + +namespace com::sun::star::uno { class XComponentContext; } +namespace com::sun::star::i18n { class XCharacterClassification; } + +const sal_Int32 nCharClassAlphaType = + css::i18n::KCharacterType::UPPER | + css::i18n::KCharacterType::LOWER | + css::i18n::KCharacterType::TITLE_CASE; + +const sal_Int32 nCharClassAlphaTypeMask = + nCharClassAlphaType | + css::i18n::KCharacterType::PRINTABLE | + css::i18n::KCharacterType::BASE_FORM; + +const sal_Int32 nCharClassLetterType = + nCharClassAlphaType | + css::i18n::KCharacterType::LETTER; + +const sal_Int32 nCharClassLetterTypeMask = + nCharClassAlphaTypeMask | + css::i18n::KCharacterType::LETTER; + +const sal_Int32 nCharClassNumericType = + css::i18n::KCharacterType::DIGIT; + +const sal_Int32 nCharClassNumericTypeMask = + nCharClassNumericType | + css::i18n::KCharacterType::PRINTABLE | + css::i18n::KCharacterType::BASE_FORM; + +class UNOTOOLS_DLLPUBLIC CharClass +{ + LanguageTag maLanguageTag; + css::uno::Reference< css::i18n::XCharacterClassification > xCC; + + CharClass(const CharClass&) = delete; + CharClass& operator=(const CharClass&) = delete; + +public: + /// Preferred ctor with service manager specified + CharClass( + const css::uno::Reference< css::uno::XComponentContext > & rxContext, + LanguageTag aLanguageTag ); + + /// Deprecated ctor, tries to get a process service manager or to load the + /// library directly. + CharClass( LanguageTag aLanguageTag ); + + ~CharClass(); + + /// get current Locale + const LanguageTag& getLanguageTag() const; + + /// isdigit() on ascii values of entire string + static bool isAsciiNumeric( std::u16string_view rStr ); + + /// isalpha() on ascii values of entire string + static bool isAsciiAlpha( std::u16string_view rStr ); + + /// whether type is pure numeric or not, e.g. return of getStringType + static bool isNumericType( sal_Int32 nType ) + { + return ((nType & nCharClassNumericType) != 0) && + ((nType & ~nCharClassNumericTypeMask) == 0); + } + + /// whether type is pure alphanumeric or not, e.g. return of getStringType + static bool isAlphaNumericType( sal_Int32 nType ) + { + return ((nType & (nCharClassAlphaType | + nCharClassNumericType)) != 0) && + ((nType & ~(nCharClassAlphaTypeMask | + nCharClassNumericTypeMask)) == 0); + } + + /// whether type is pure letter or not, e.g. return of getStringType + static bool isLetterType( sal_Int32 nType ) + { + return ((nType & nCharClassLetterType) != 0) && + ((nType & ~nCharClassLetterTypeMask) == 0); + } + + /// whether type is pure letternumeric or not, e.g. return of getStringType + static bool isLetterNumericType( sal_Int32 nType ) + { + return ((nType & (nCharClassLetterType | + nCharClassNumericType)) != 0) && + ((nType & ~(nCharClassLetterTypeMask | + nCharClassNumericTypeMask)) == 0); + } + + // Wrapper implementations of class CharacterClassification + + OUString uppercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const; + OUString lowercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const; + OUString titlecase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const; + + OUString uppercase( const OUString& _rStr ) const + { + return uppercase(_rStr, 0, _rStr.getLength()); + } + OUString lowercase( const OUString& _rStr ) const + { + return lowercase(_rStr, 0, _rStr.getLength()); + } + OUString titlecase( const OUString& _rStr ) const + { + return titlecase(_rStr, 0, _rStr.getLength()); + } + + sal_Int16 getType( const OUString& rStr, sal_Int32 nPos ) const; + css::i18n::DirectionProperty getCharacterDirection( const OUString& rStr, sal_Int32 nPos ) const; + css::i18n::UnicodeScript getScript( const OUString& rStr, sal_Int32 nPos ) const; + sal_Int32 getCharacterType( const OUString& rStr, sal_Int32 nPos ) const; + sal_Int32 getStringType( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const; + + css::i18n::ParseResult parseAnyToken( + const OUString& rStr, + sal_Int32 nPos, + sal_Int32 nStartCharFlags, + const OUString& userDefinedCharactersStart, + sal_Int32 nContCharFlags, + const OUString& userDefinedCharactersCont ) const; + + css::i18n::ParseResult parsePredefinedToken( + sal_Int32 nTokenType, + const OUString& rStr, + sal_Int32 nPos, + sal_Int32 nStartCharFlags, + const OUString& userDefinedCharactersStart, + sal_Int32 nContCharFlags, + const OUString& userDefinedCharactersCont ) const; + + // Functionality of class International methods + + bool isAlpha( const OUString& rStr, sal_Int32 nPos ) const; + bool isLetter( const OUString& rStr, sal_Int32 nPos ) const; + bool isDigit( const OUString& rStr, sal_Int32 nPos ) const; + bool isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const; + bool isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const; + bool isLetter( const OUString& rStr ) const; + bool isNumeric( const OUString& rStr ) const; + bool isLetterNumeric( const OUString& rStr ) const; + +private: + + const css::lang::Locale & getMyLocale() const; +}; + +#endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/closeveto.hxx b/include/unotools/closeveto.hxx new file mode 100644 index 000000000..bcc56766f --- /dev/null +++ b/include/unotools/closeveto.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_CLOSEVETO_HXX +#define INCLUDED_UNOTOOLS_CLOSEVETO_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/uno/Reference.hxx> +#include <memory> + +namespace com::sun::star::uno { class XInterface; } + +namespace utl +{ + + //= CloseVeto + struct CloseVeto_Data; + /** will add a XCloseListener to a given component, and veto its closing as long as the <code>CloseVeto</code> + instance is alive. + + If closing has been requested and vetoed while the <code>CloseVeto</code> instance is alive, and the ownership + went to the <code>CloseVeto</code> instance, then it will close the component in its dtor. + */ + class UNOTOOLS_DLLPUBLIC CloseVeto + { + public: + CloseVeto( const css::uno::Reference< css::uno::XInterface >& i_closeable, + bool bHasOwnership = false); + ~CloseVeto(); + + private: + std::unique_ptr< CloseVeto_Data > m_xData; + }; + +} // namespace dbaui + +#endif // INCLUDED_UNOTOOLS_CLOSEVETO_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/cmdoptions.hxx b/include/unotools/cmdoptions.hxx new file mode 100644 index 000000000..bb3414f8f --- /dev/null +++ b/include/unotools/cmdoptions.hxx @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_CMDOPTIONS_HXX +#define INCLUDED_UNOTOOLS_CMDOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <unotools/options.hxx> +#include <memory> + +namespace com::sun::star::uno +{ +template <typename> class Reference; +} + +namespace com::sun::star::frame +{ +class XFrame; +} +namespace osl +{ +class Mutex; +} + +/*-************************************************************************************************************ + @descr The method GetList() returns a list of property values. + Use follow defines to separate values by names. +**-***********************************************************************************************************/ + +/*-************************************************************************************************************ + @short forward declaration to our private date container implementation + @descr We use these class as internal member to support small memory requirements. + You can create the container if it is necessary. The class which use these mechanism + is faster and smaller then a complete implementation! +**-***********************************************************************************************************/ + +class SvtCommandOptions_Impl; + +/*-************************************************************************************************************ + @short collect information about dynamic menus + @descr Make it possible to configure dynamic menu structures of menus like "new" or "wizard". + @devstatus ready to use +**-***********************************************************************************************************/ + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtCommandOptions final : public utl::detail::Options +{ + friend class SvtCommandOptions_Impl; + +public: + enum CmdOption + { + CMDOPTION_DISABLED, + CMDOPTION_NONE + }; + + SvtCommandOptions(); + virtual ~SvtCommandOptions() override; + + /*-**************************************************************************************************** + @short return complete specified list + @descr Call it to get all entries of an dynamic menu. + We return a list of all nodes with its names and properties. + @param "eOption" select the list to retrieve. + @return A list of command strings is returned. + + @onerror We return an empty list. + **-***************************************************************************************************/ + + bool HasEntries(CmdOption eOption) const; + + /*-**************************************************************************************************** + @short Lookup if a command URL is inside a given list + @descr Lookup if a command URL is inside a given lst + @param "eOption" select right command list + @param "aCommandURL" a command URL that is used for the look up + @return "sal_True" if the command is inside the list otherwise "sal_False" + **-***************************************************************************************************/ + + bool Lookup(CmdOption eOption, const OUString& aCommandURL) const; + + /*-**************************************************************************************************** + @short register an office frame, which must update its dispatches if + the underlying configuration was changed. + + @descr To avoid using of "dead" frame objects or implementing + deregistration mechanism too, we use weak references to + the given frames. + + @param "xFrame" points to the frame, which wishes to be + notified, if configuration was changed. + **-***************************************************************************************************/ + + void EstablishFrameCallback(const css::uno::Reference<css::frame::XFrame>& xFrame); + +private: + std::shared_ptr<SvtCommandOptions_Impl> m_pImpl; + +}; // class SvtCmdOptions + +#endif // INCLUDED_UNOTOOLS_CMDOPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/collatorwrapper.hxx b/include/unotools/collatorwrapper.hxx new file mode 100644 index 000000000..595d9ccf4 --- /dev/null +++ b/include/unotools/collatorwrapper.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_COLLATORWRAPPER_HXX +#define INCLUDED_UNOTOOLS_COLLATORWRAPPER_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +namespace com::sun::star::uno { + class XComponentContext; +} + +namespace com::sun::star::i18n { class XCollator; } +namespace com::sun::star::lang { struct Locale; } + +class UNOTOOLS_DLLPUBLIC CollatorWrapper +{ + private: + css::uno::Reference< css::i18n::XCollator > mxInternationalCollator; + + public: + + CollatorWrapper ( + const css::uno::Reference< css::uno::XComponentContext > &rxContext); + + sal_Int32 + compareString ( + const OUString& s1, const OUString& s2) const; + + css::uno::Sequence< OUString > + listCollatorAlgorithms ( + const css::lang::Locale& rLocale) const; + + sal_Int32 + loadDefaultCollator ( + const css::lang::Locale& rLocale, sal_Int32 nOption); + + void + loadCollatorAlgorithm ( + const OUString& rAlgorithm, + const css::lang::Locale& rLocale, sal_Int32 nOption); +}; + +#endif // INCLUDED_UNOTOOLS_COLLATORWRAPPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/compatibility.hxx b/include/unotools/compatibility.hxx new file mode 100644 index 000000000..b929771b5 --- /dev/null +++ b/include/unotools/compatibility.hxx @@ -0,0 +1,200 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_COMPATIBILITY_HXX +#define INCLUDED_UNOTOOLS_COMPATIBILITY_HXX + +#include <com/sun/star/uno/Any.hxx> +#include <unotools/options.hxx> +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <memory> +#include <vector> + +namespace osl { class Mutex; } + +/*-************************************************************************************************************ + @descr Struct to hold information about one compatibility entry +*//*-*************************************************************************************************************/ +class SvtCompatibilityEntry +{ + public: + /*-************************************************************************************************************ + @descr The method SvtCompatibilityOptions::GetList() returns a list of property values. + Use follow enum class to separate values by names. + Sync it with sPropertyName in SvtCompatibilityEntry::getName() + *//*-*************************************************************************************************************/ + enum class Index + { + /* Should be in the start. Do not remove it. */ + Name, + Module, + + /* Editable list of compatibility options. */ + UsePrtMetrics, + AddSpacing, + AddSpacingAtPages, + UseOurTabStops, + NoExtLeading, + UseLineSpacing, + AddTableSpacing, + UseObjectPositioning, + UseOurTextWrapping, + ConsiderWrappingStyle, + ExpandWordSpace, + ProtectForm, + MsWordTrailingBlanks, + SubtractFlysAnchoredAtFlys, + EmptyDbFieldHidesPara, + /// special entry: optcomp.cxx converts the other values to + /// integers but not this one because it doesn't have its own + /// checkbox, so keep it at the end! + AddTableLineSpacing, + + /* Should be at the end. Do not remove it. */ + INVALID + }; + + SvtCompatibilityEntry(); + + static OUString getName( const Index rIdx ); + + static constexpr OUStringLiteral USER_ENTRY_NAME = u"_user"; + static constexpr OUStringLiteral DEFAULT_ENTRY_NAME = u"_default"; + + static size_t getElementCount() + { + return static_cast<size_t>(Index::INVALID); + } + + css::uno::Any getValue( const Index rIdx ) const + { + if ( static_cast<size_t>(rIdx) < getElementCount() ) + { + return m_aPropertyValue[ static_cast<int>(rIdx) ]; + } else + { + /* Wrong index. */ + assert( false ); + return css::uno::Any(); + } + } + + template<typename T> + T getValue( const Index rIdx ) const + { + T aValue = T(); + + if ( static_cast<size_t>(rIdx) < getElementCount() ) + { + m_aPropertyValue[ static_cast<int>(rIdx) ] >>= aValue; + } else + { + /* Wrong index. */ + assert( false ); + } + + return aValue; + } + + void setValue( const Index rIdx, css::uno::Any const & rValue ) + { + if ( static_cast<size_t>(rIdx) < getElementCount() ) + { + m_aPropertyValue[ static_cast<int>(rIdx) ] = rValue; + } else + { + /* Wrong index. */ + assert( false ); + } + } + + template<typename T> + void setValue( const Index rIdx, T rValue ) + { + setValue(rIdx, css::uno::Any(rValue)); + } + + private: + std::vector<css::uno::Any> m_aPropertyValue; +}; + +/*-************************************************************************************************************ + @short forward declaration to our private date container implementation + @descr We use these class as internal member to support small memory requirements. + You can create the container if it is necessary. The class which use these mechanism + is faster and smaller then a complete implementation! +*//*-*************************************************************************************************************/ +class SvtCompatibilityOptions_Impl; + +/*-************************************************************************************************************ + @short collect information about dynamic menus + @descr Make it possible to configure dynamic menu structures of menus like "new" or "wizard". + @devstatus ready to use +*//*-*************************************************************************************************************/ +class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions final : public utl::detail::Options +{ + public: + SvtCompatibilityOptions(); + virtual ~SvtCompatibilityOptions() override; + + /*-**************************************************************************************************** + @short append a new item + @descr + + @seealso method Clear() + + @param "aItem" SvtCompatibilityEntry + *//*-*****************************************************************************************************/ + void AppendItem( const SvtCompatibilityEntry& aItem ); + + /*-**************************************************************************************************** + @short clear complete specified list + @descr Call this methods to clear the whole list. + *//*-*****************************************************************************************************/ + void Clear(); + + void SetDefault( SvtCompatibilityEntry::Index rIdx, bool rValue ); + bool GetDefault( SvtCompatibilityEntry::Index rIdx ) const; + + /*-**************************************************************************************************** + @short return complete specified list + @descr Call it to get all entries of compatibility options. + We return a list of all nodes with its names and properties. + @return A list of compatibility options is returned. + + @onerror We return an empty list. + *//*-*****************************************************************************************************/ + std::vector< SvtCompatibilityEntry > GetList() const; + + private: + std::shared_ptr<SvtCompatibilityOptions_Impl> m_pImpl; + + /*-**************************************************************************************************** + @short return a reference to a static mutex + @descr These class is partially threadsafe (for de-/initialization only). + All access methods aren't safe! + We create a static mutex only for one ime and use at different times. + @return A reference to a static mutex member. + *//*-*****************************************************************************************************/ + UNOTOOLS_DLLPRIVATE static osl::Mutex& GetOwnStaticMutex(); +}; + +#endif // INCLUDED_UNOTOOLS_COMPATIBILITY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/configitem.hxx b/include/unotools/configitem.hxx new file mode 100644 index 000000000..7692bd3d6 --- /dev/null +++ b/include/unotools/configitem.hxx @@ -0,0 +1,215 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_CONFIGITEM_HXX +#define INCLUDED_UNOTOOLS_CONFIGITEM_HXX + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/uno/Reference.h> +#include <unotools/unotoolsdllapi.h> +#include <unotools/options.hxx> +#include <o3tl/typed_flags_set.hxx> + +namespace com::sun::star { + namespace uno{ + class Any; + } + namespace beans{ + struct PropertyValue; + } + namespace container{ + class XHierarchicalNameAccess; + } + namespace util{ + class XChangesListener; + } +} + +enum class ConfigItemMode +{ + NONE = 0x00, + AllLocales = 0x02, + ReleaseTree = 0x04, +}; + +namespace o3tl +{ + template<> struct typed_flags<ConfigItemMode> : is_typed_flags<ConfigItemMode, 0x06> {}; +} + +namespace utl +{ + + enum class ConfigNameFormat + { + LocalNode, // local node name, for use in XNameAccess etc. ("Item", "Q & A") + LocalPath, // one-level relative path, for use when building paths etc. ("Item", "Typ['Q & A']") + }; + + class UNOTOOLS_DLLPUBLIC ConfigItem : public ConfigurationBroadcaster + { + friend class ConfigChangeListener_Impl; + friend class ConfigManager; + + const OUString sSubTree; + css::uno::Reference< css::container::XHierarchicalNameAccess> + m_xHierarchyAccess; + css::uno::Reference< css::util::XChangesListener > + xChangeLstnr; + ConfigItemMode m_nMode; + bool m_bIsModified; + bool m_bEnableInternalNotification; + sal_Int16 m_nInValueChange; + + void RemoveChangesListener(); + void CallNotify( + const css::uno::Sequence<OUString>& aPropertyNames); + + // In special mode ALL_LOCALES we must support reading/writing of localized cfg entries as Sequence< PropertyValue >. + // These methods are helper to convert given lists of names and Any-values. + // format: PropertyValue.Name = <locale as ISO string> + // PropertyValue.Value = <value; type depends from cfg entry!> + // e.g. + // LOCALIZED NODE + // "UIName" + // LOCALE VALUE + // "de" "Mein Name" + // "en-US" "my name" + static void impl_packLocalizedProperties ( const css::uno::Sequence< OUString >& lInNames , + const css::uno::Sequence< css::uno::Any >& lInValues , + css::uno::Sequence< css::uno::Any >& lOutValues ); + static void impl_unpackLocalizedProperties ( + const css::uno::Sequence< OUString >& lInNames , + const css::uno::Sequence< css::uno::Any >& lInValues , + css::uno::Sequence< OUString >& lOutNames , + css::uno::Sequence< css::uno::Any >& lOutValues); + + css::uno::Reference< css::container::XHierarchicalNameAccess> + GetTree(); + /** writes the changed values into the sub tree. + Private and only called from non-virtual public Commit(). */ + virtual void ImplCommit() = 0; + + protected: + explicit ConfigItem(OUString aSubTree, + ConfigItemMode nMode = ConfigItemMode::NONE); + + void SetModified (); // mark item as modified + void ClearModified(); // reset state after commit! + + css::uno::Sequence< css::uno::Any> + GetProperties(const css::uno::Sequence< OUString >& rNames); + + css::uno::Sequence< sal_Bool > + GetReadOnlyStates(const css::uno::Sequence< OUString >& rNames); + + bool PutProperties( + const css::uno::Sequence< OUString >& rNames, + const css::uno::Sequence< css::uno::Any>& rValues); + + /** enables notifications about changes on selected sub nodes/values + + Before calling this method a second time for a possibly changed node/value set, + you must disable the current notifications by calling DisableNotification. + + @see Notify + @see DisableNotification + */ + bool EnableNotification(const css::uno::Sequence< OUString >& rNames, + bool bEnableInternalNotification = false); + /** disables notifications about changes on sub nodes/values, which previously had + been enabled with EnableNotification + @see Notify + @see EnableNotification + */ + void DisableNotification(); + + //returns all members of a node in a specific format + css::uno::Sequence< OUString > + GetNodeNames(const OUString& rNode); + //returns all members of a node in a specific format + css::uno::Sequence< OUString > + GetNodeNames(const OUString& rNode, ConfigNameFormat eFormat); + // remove all members of a set + bool ClearNodeSet(const OUString& rNode); + // remove selected members of a set + bool ClearNodeElements(const OUString& rNode, + css::uno::Sequence< OUString > const & rElements); + // change or add members to a set + bool SetSetProperties(const OUString& rNode, const css::uno::Sequence< css::beans::PropertyValue >& rValues); + // remove, change or add members of a set + bool ReplaceSetProperties(const OUString& rNode, const css::uno::Sequence< css::beans::PropertyValue >& rValues); + // add a new node without setting any properties + bool AddNode(const OUString& rNode, const OUString& rNewNode); + + public: + virtual ~ConfigItem() override; + + ConfigItem(ConfigItem const &) = default; + ConfigItem(ConfigItem &&) = default; + ConfigItem & operator =(ConfigItem const &) = delete; // due to const sSubTree + ConfigItem & operator =(ConfigItem &&) = delete; // due to const sSubTree + + /** is called from the ConfigManager before application ends of from the + PropertyChangeListener if the sub tree broadcasts changes. */ + virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames)=0; + + const OUString& GetSubTreeName() const {return sSubTree;} + + bool IsModified() const { return m_bIsModified;} + + void Commit(); + + ConfigItemMode GetMode() const { return m_nMode;} + + //returns all members of a node in a specific format + static css::uno::Sequence< OUString > GetNodeNames( + css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess, + const OUString& rNode, ConfigNameFormat eFormat); + static css::uno::Sequence< css::uno::Any> GetProperties( + css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess, + const css::uno::Sequence< OUString >& rNames, + bool bAllLocales); + static bool PutProperties( + css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess, + const css::uno::Sequence< OUString >& rNames, + const css::uno::Sequence< css::uno::Any>& rValues, + bool bAllLocales); + // remove all members of a set + static bool ClearNodeSet( + css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess, + const OUString& rNode); + // remove, change or add members of a set + static bool ReplaceSetProperties( + css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess, + const OUString& rNode, + const css::uno::Sequence< css::beans::PropertyValue >& rValues, + bool bAllLocales); + // change or add members to a set + static bool SetSetProperties( + css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess, + const OUString& rNode, + const css::uno::Sequence< css::beans::PropertyValue >& rValues); + }; +}//namespace utl +#endif // INCLUDED_UNOTOOLS_CONFIGITEM_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/configmgr.hxx b/include/unotools/configmgr.hxx new file mode 100644 index 000000000..e8d42a28f --- /dev/null +++ b/include/unotools/configmgr.hxx @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_CONFIGMGR_HXX +#define INCLUDED_UNOTOOLS_CONFIGMGR_HXX + +#include <sal/config.h> + +#include <string_view> +#include <vector> + +#include <com/sun/star/uno/Reference.hxx> +#include <sal/types.h> +#include <unotools/unotoolsdllapi.h> + +namespace com::sun::star::container { + class XHierarchicalNameAccess; +} +namespace utl { class ConfigItem; } + +namespace utl { + +class UNOTOOLS_DLLPUBLIC ConfigManager { +public: + static OUString getAboutBoxProductVersion(); + + static OUString getAboutBoxProductVersionSuffix(); + + static OUString getDefaultCurrency(); + + static OUString getUILocale(); + + static OUString getWorkLocale(); + + static OUString getProductExtension(); + + static OUString getProductName(); + + static OUString getProductVersion(); + + static OUString getVendor(); + + static void storeConfigItems(); + + SAL_DLLPRIVATE static ConfigManager & getConfigManager(); + + SAL_DLLPRIVATE static css::uno::Reference< css::container::XHierarchicalNameAccess> + acquireTree(utl::ConfigItem const & item); + + static css::uno::Reference< css::container::XHierarchicalNameAccess> + acquireTree(std::u16string_view rSubTreeName); + + SAL_DLLPRIVATE ConfigManager(); + + SAL_DLLPRIVATE ~ConfigManager(); + + SAL_DLLPRIVATE css::uno::Reference< css::container::XHierarchicalNameAccess > + addConfigItem(utl::ConfigItem & item); + + SAL_DLLPRIVATE void removeConfigItem(utl::ConfigItem & item); + + SAL_DLLPRIVATE void registerConfigItem(utl::ConfigItem * item); + + // Avoid using the config layer and rely on defaults which is only useful + // for special test tool targets (typically fuzzing) where start-up speed + // is of the essence +#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) + static constexpr bool IsFuzzing() { return true; } +#else + static bool IsFuzzing(); +#endif + static void EnableFuzzing(); + +private: + + ConfigManager(const ConfigManager&) = delete; + ConfigManager& operator=(const ConfigManager&) = delete; + + void doStoreConfigItems(); + + std::vector< ConfigItem * > items_; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/confignode.hxx b/include/unotools/confignode.hxx new file mode 100644 index 000000000..f334aa149 --- /dev/null +++ b/include/unotools/confignode.hxx @@ -0,0 +1,272 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_CONFIGNODE_HXX +#define INCLUDED_UNOTOOLS_CONFIGNODE_HXX + +#include <unotools/unotoolsdllapi.h> +#include <unotools/eventlisteneradapter.hxx> + +namespace com::sun::star::container { class XHierarchicalNameAccess; } +namespace com::sun::star::container { class XNameAccess; } +namespace com::sun::star::container { class XNameContainer; } +namespace com::sun::star::container { class XNameReplace; } +namespace com::sun::star::lang { class XMultiServiceFactory; } +namespace com::sun::star::uno { class XComponentContext; } +namespace com::sun::star::util { class XChangesBatch; } + +namespace utl +{ + + /** a small wrapper around a configuration node.<p/> + Nodes in the terminology used herein are <em>inner</em> nodes of a configuration + tree, which means <em>no leafs</em>. + */ + class UNOTOOLS_DLLPUBLIC OConfigurationNode : public ::utl::OEventListenerAdapter + { + private: + css::uno::Reference< css::container::XHierarchicalNameAccess > + m_xHierarchyAccess; /// accessing children grandchildren (mandatory interface of our UNO object) + css::uno::Reference< css::container::XNameAccess > + m_xDirectAccess; /// accessing children (mandatory interface of our UNO object) + css::uno::Reference< css::container::XNameReplace > + m_xReplaceAccess; /// replacing child values + css::uno::Reference< css::container::XNameContainer > + m_xContainerAccess; /// modifying set nodes (optional interface of our UNO object) + bool m_bEscapeNames; /// escape names before accessing children ? + + OConfigurationNode insertNode(const OUString& _rName,const css::uno::Reference< css::uno::XInterface >& _xNode) const noexcept; + + protected: + /// constructs a node object with an interface representing a node + OConfigurationNode( + const css::uno::Reference< css::uno::XInterface >& _rxNode + ); + + const css::uno::Reference< css::container::XNameAccess >& + getUNONode() const { return m_xDirectAccess; } + + public: + /// constructs an empty and invalid node object + OConfigurationNode() :m_bEscapeNames(false) { } + /// copy ctor + OConfigurationNode(const OConfigurationNode& _rSource); + /// move ctor + OConfigurationNode(OConfigurationNode&& _rSource); + + /// assignment + OConfigurationNode& operator=(const OConfigurationNode& _rSource); + OConfigurationNode& operator=(OConfigurationNode&& _rSource); + + /// returns the local name of the node + OUString getLocalName() const; + + /** open a sub node + @param _rPath access path of the to-be-opened sub node. May be a hierarchical path. + */ + OConfigurationNode openNode(const OUString& _rPath) const noexcept; + + OConfigurationNode openNode( const char* _pAsciiPath ) const + { + return openNode( OUString::createFromAscii( _pAsciiPath ) ); + } + + /** create a new child node + + If the object represents a set node, this method may be used to create a new child. For non-set-nodes, the + method will fail.<br/> + Unless the respective operations on the pure configuration API, the to-be-created node immediately + becomes a part of its hierarchy, no explicit insertion is necessary. + @param _rName name for the new child. Must be level-1-depth. + */ + OConfigurationNode createNode(const OUString& _rName) const noexcept; + + /** remove an existent child nod + + If the object represents a set node, this method may be used to delete an existent child. For non-set-nodes, + the method will fail. + */ + bool removeNode(const OUString& _rName) const noexcept; + + /** retrieves the content of a descendant + + the returned value may contain anything from an interface (if <arg>_rPath</arg> refers to inner node of + the configuration tree) to any explicit value (e.g. string, integer) or even void.<br/> + Unfortunately, this implies that if a void value is returned, you won't have a clue if this means + "the path does not exist" (besides the assertion made :), or if the value is really void. + */ + css::uno::Any getNodeValue(const OUString& _rPath) const noexcept; + + css::uno::Any getNodeValue( const char* _pAsciiPath ) const + { + return getNodeValue( OUString::createFromAscii( _pAsciiPath ) ); + } + + /** write a node value<p/> + The value given is written into the node specified by the given relative path.<br/> + In opposite to <method>getNodeValue</method>, _rName must refer to a leaf in the configuration tree, not an inner + node. + @return sal_True if and only if the write was successful. + */ + bool setNodeValue(const OUString& _rPath, const css::uno::Any& _rValue) const noexcept; + + bool setNodeValue( const char* _pAsciiPath, const css::uno::Any& _rValue ) const + { + return setNodeValue( OUString::createFromAscii( _pAsciiPath ), _rValue ); + } + + /// return the names of the existing children + css::uno::Sequence< OUString > + getNodeNames() const noexcept; + + /// invalidate the object + virtual void clear() noexcept; + + // meta information about the node + + /// checks whether or not the object represents a set node. + bool isSetNode() const; + + /// checks whether or not a direct child with a given name exists + bool hasByName(const OUString& _rName) const noexcept; + + /// checks whether or not a descendent (no matter if direct or indirect) with the given name exists + bool hasByHierarchicalName( const OUString& _rName ) const noexcept; + + /// check if the objects represents a valid configuration node + bool isValid() const { return m_xHierarchyAccess.is(); } + + /// check whether the object is read-only of updatable + bool isReadonly() const { return !m_xReplaceAccess.is(); } + + protected: + // OEventListenerAdapter + virtual void _disposing( const css::lang::EventObject& _rSource ) override; + + protected: + enum NAMEORIGIN + { + NO_CONFIGURATION, /// the name came from a configuration node + NO_CALLER /// the name came from a client of this class + }; + OUString normalizeName(const OUString& _rName, NAMEORIGIN _eOrigin) const; + }; + + //= OConfigurationTreeRoot + + /** a specialized version of an OConfigurationNode, representing the root + of a configuration sub tree<p/> + Only this class is able to commit any changes made any any OConfigurationNode + objects. + */ + class UNOTOOLS_DLLPUBLIC OConfigurationTreeRoot final : public OConfigurationNode + { + css::uno::Reference< css::util::XChangesBatch > + m_xCommitter; + /** ctor for a readonly node + */ + OConfigurationTreeRoot( + const css::uno::Reference< css::uno::XInterface >& _rxRootNode + ); + + public: + /// modes to use when creating a top-level node object + enum CREATION_MODE + { + /// open the node (i.e. sub tree) for read access only + CM_READONLY, + /// open the node (i.e. sub tree) for read and write access, fall back to read-only if write access is not possible + CM_UPDATABLE + }; + + public: + /** default ctor<p/> + The object constructed here is invalid (i.e. <method>isValid</method> will return sal_False). + */ + OConfigurationTreeRoot() {} + + /** creates a configuration tree for the given path in the given mode + */ + OConfigurationTreeRoot( + const css::uno::Reference<css::uno::XComponentContext> & i_rContext, + const OUString& i_rNodePath, + const bool i_bUpdatable + ); + + /** open a new top-level configuration node + + opens a new node which is the root if an own configuration sub tree. This is what "top level" means: The + node does not have a parent. It does not mean that the node represents a module tree (like org.openoffice.Office.Writer + or such).<br/> + In opposite to <method>createWithServiceFactory</method>, createWithProvider expects a configuration provider + to work with. + + @param _rxConfProvider configuration provider to use when retrieving the node. + @param _rPath path to the node the object should represent + @param _nDepth depth for node retrieval + @param _eMode specifies which privileges should be applied when retrieving the node + + @see createWithServiceFactory + */ + static OConfigurationTreeRoot createWithProvider( + const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxConfProvider, + const OUString& _rPath, + sal_Int32 _nDepth, + CREATION_MODE _eMode + ); + + /** open a new top-level configuration node<p/> + opens a new node which is the root if an own configuration sub tree. This is what "top level" means: The + node does not have a parent. It does not mean that the node represents a module tree (like org.openoffice.Office.Writer + or such).<br/> + In opposite to <method>createWithProvider</method>, createWithProvider expects a service factory. This factory + is used to create a configuration provider, and this provider is used to retrieve the node + @see createWithProvider + @param _rxContext service factory to use to create the configuration provider. + @param _rPath path to the node the object should represent + @param _nDepth depth for node retrieval + @param _eMode specifies which privileges should be applied when retrieving the node + */ + static OConfigurationTreeRoot createWithComponentContext(const css::uno::Reference< css::uno::XComponentContext >& _rxContext, + const OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_UPDATABLE); + + /** tolerant version of the <member>createWithServiceFactory</member> + + <p>No assertions are thrown in case of a failure to initialize the configuration service, but once + the configuration could be initialized, errors in the creation of the specific node (e.g. because the + given node path does not exist) are still asserted.</p> + */ + static OConfigurationTreeRoot tryCreateWithComponentContext( const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_UPDATABLE ); + + /** commit all changes made on the subtree the object is the root for<p/> + All changes made on any OConfigurationNode object retrieved (maybe indirect) from this root + object are committed when calling this method. + @return sal_True if and only if the commit was successful + */ + bool commit() const noexcept; + + /// invalidate the object + virtual void clear() noexcept override; + }; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_CONFIGNODE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/configpaths.hxx b/include/unotools/configpaths.hxx new file mode 100644 index 000000000..119733a47 --- /dev/null +++ b/include/unotools/configpaths.hxx @@ -0,0 +1,162 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_CONFIGPATHS_HXX +#define INCLUDED_UNOTOOLS_CONFIGPATHS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> + +namespace utl +{ + + /** extract the local nodename and the parent nodepath + from a configuration path. + + @param _sInPath + A configuration path that is not an empty or root path.<BR/> + If this is not a valid configuration path, it is interpreted as + local name of a node. + + @param _rsOutPath + On exit: The configuration path obtained by dropping + the last level off <var>_sInPath</var>.<BR/> + If <var>_sInPath</var> could not be parsed as a valid + configuration path, this is set to an empty string. + + @param _rsLocalName + On exit: The plain (non-escaped) name of the node identified by + <var>_sInPath</var>. <BR/> + If <var>_sInPath</var> could not be parsed as a valid + configuration path, this is set to <var>_sInPath</var>. + + @returns + <TRUE/>, if a parent path could be set + <FALSE/>, if the path was a one-level path or an invalid path + + */ + UNOTOOLS_DLLPUBLIC bool splitLastFromConfigurationPath(OUString const& _sInPath, + OUString& _rsOutPath, + OUString& _rsLocalName); + + /** extract the first nodename from a configuration path. + + @param _sInPath + A relative configuration path that is not empty.<BR/> + If this is not a valid configuration path, it is interpreted as + a single name of a node. + + @param _sOutPath + If non-null, contains the remainder of the path upon return. + + @returns + The plain (non-escaped) name of the node that is the first step + when traversing <var>_sInPath</var>.<BR/> + If <var>_sInPath</var> could not be parsed as a valid + configuration path, it is returned unaltered. + + */ + UNOTOOLS_DLLPUBLIC OUString extractFirstFromConfigurationPath( + OUString const& _sInPath, OUString* _sOutPath = nullptr); + + /** check whether a path is to a nested node with respect to a parent path. + + @param _sNestedPath + A configuration path that maybe points to a descendant of the node + identified by <var>_sPrefixPath</var>, with both paths starting + from the same node (or both being absolute). + + @param _sPrefixPath + A configuration path.<BR/> + If this path is absolute, <var>_sNestedPath</var> should be absolute; + If this path is relative, <var>_sNestedPath</var> should be relative; + If this path is empty, <var>_sNestedPath</var> may start with a '/', + which is disregarded. + + @returns + <TRUE/>, if <var>_sPrefixPath</var> is a prefix of <var>_sNestedPath</var>; + <FALSE/> otherwise.<BR/> + If both paths are equal <TRUE/> is returned. + + */ + bool isPrefixOfConfigurationPath(std::u16string_view _sNestedPath, + std::u16string_view _sPrefixPath); + + /** get the relative path to a nested node with respect to a parent path. + + @param _sNestedPath + A configuration path that points to a descendant of the node + identified by <var>_sPrefixPath</var>, with both paths starting + from the same node (or both being absolute). + + @param _sPrefixPath + A configuration path.<BR/> + If this path is absolute, <var>_sNestedPath</var> must be absolute; + If this path is relative, <var>_sNestedPath</var> must be relative; + If this path is empty, <var>_sNestedPath</var> may start with a '/', + which is stripped. + + @returns + The remaining relative path from the target of <var>_sPrefixPath</var> + to the target of <var>_sNestedPath</var>.<BR/> + If <var>_sPrefixPath</var> is not a prefix of <var>_sNestedPath</var>, + <var>_sNestedPath</var> is returned unaltered. + + */ + UNOTOOLS_DLLPUBLIC OUString dropPrefixFromConfigurationPath(OUString const& _sNestedPath, + std::u16string_view _sPrefixPath); + + /** Create a one-level relative configuration path from a set element name + without a known set element type. + + @param _sElementName + An arbitrary string that is to be interpreted as + name of a configuration set element. + + @returns + A one-level relative path to the element, of the form + "*['<Name>']", where <Name> is properly escaped. + + */ + UNOTOOLS_DLLPUBLIC OUString wrapConfigurationElementName(std::u16string_view _sElementName); + + /** Create a one-level relative configuration path from a set element name + and a known set element type. + + @param _sElementName + An arbitrary string that is to be interpreted as + name of a configuration set element. + + @param _sTypeName + An string identifying the type of the element. Usually this is be + the name of the element-template of the set.<BR/> + + @returns + A one-level relative path to the element, of the form + "<Type>['<Name>']", where <Name> is properly escaped. + + */ + OUString wrapConfigurationElementName(std::u16string_view _sElementName, + OUString const& _sTypeName); + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_CONFIGPATHS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/configvaluecontainer.hxx b/include/unotools/configvaluecontainer.hxx new file mode 100644 index 000000000..c4447fca2 --- /dev/null +++ b/include/unotools/configvaluecontainer.hxx @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX +#define INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX + +#include <config_options.h> +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/uno/Type.hxx> +#include <memory> + + +namespace com::sun::star::uno { template <typename > class Reference; } +namespace com::sun::star::uno { class XComponentContext; } +namespace osl { class Mutex; } + +namespace utl +{ + + struct OConfigurationValueContainerImpl; + struct NodeValueAccessor; + + //= OConfigurationValueContainer + + /** allows simple access to static configuration structures. + + <p>The basic idea of this class is that it's clients (usually derived classes) simply register an + address in memory and a node path, and upon explicit request, the configuration value and the memory + are synchronized.<br/> + This means that when calling <method>read</method>, the current configuration values are copied into + the memory registered for them, and upon calling <method>write</method> the current values in memory + are set in the configuration nodes.</p> + + <p>This way, the usage of this class is pretty straight forward: derive your own class, spend some members + to it, and bind these members to configuration node (usually done in the ctor of the derived class).<br/> + In the dtor, simply call <method>write</method> and <method>commit</method>.</p> + + <p>There is no auto-commit mechanism in the dtor: In the usual scenario, when you derive from this class + and bind some members of your derived class to config nodes, this means that your members will be destroyed + before your base class' dtor is called, so accessing the memory during such a theoretical auto-commit would + yield undefined behaviour.</p> + */ + class UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) OConfigurationValueContainer + { + private: + std::unique_ptr<OConfigurationValueContainerImpl> m_pImpl; + + protected: + + // construction/destruction + + /** constructs the object + + @param _rxORB + specifies the service factory which should be used to access the configuration + @param _rAccessSafety + As this class is intended to manipulate objects it does not hold itself (see the various + registerXXX methods), it needs to guard these access for multi threading safety.<br/> + The mutex given here is locked whenever such an access occurs. + @param _pConfigLocation + is an ASCII string describing the configurations node path + @param _nAccessFlags + specifies different aspects of the configuration aspect to be created, e.g. it's update mode etc.<br/> + See the CVC_xxx constants for what you can use here. + @param _nLevels + specifies the number of levels to access under the node given by <arg>_pConfigLocation</arg> + */ + OConfigurationValueContainer( + const css::uno::Reference< css::uno::XComponentContext >& _rxORB, + ::osl::Mutex& _rAccessSafety, + const char* _pConfigLocation, + const sal_Int32 _nLevels + ); + + /// dtor + ~OConfigurationValueContainer(); + + // registering data containers + + /** registers a data accessor of an arbitrary type. + + <p>Usually, in your derived class you simply add a member of the correct type of the configuration + value, and then call this method with the address of this member.</p> + + @param _pRelativePathAscii + is a relative (ASCII) path of the node which should be "mirrored" into the accessor. + @param _pContainer + points to the accessors location in memory. Usually, this is simply an address of your derived class + @param _rValueType + is the type of your accessor. This type must be supported by the configuration. + */ + void registerExchangeLocation( + const char* _pRelativePathAscii, + void* _pContainer, + const css::uno::Type& _rValueType + ); + + public: + /** reads the configuration data + + <p>The current values of the nodes bound (using the registerXXX methods) is copied into their + respective exchange locations.</p> + + <p>Please note that any changes done to your exchange locations are overridden with the current config + values.</p> + + @see write + */ + void read( ); + + /** commits any changes done + + <p>Note that calling <method>write</method>(<sal_True/) is the same as calling <method>commit</method>(<TRUE/>).</p> + + The current values in the exchange locations are written to the configuration nodes + before the changes are committed.<br/> + + @precond + The access must have been created for update access + */ + void commit(); + + private: + /// implements the ctors + void implConstruct( + const OUString& _rConfigLocation, + const sal_Int32 _nLevels + ); + + /// registers a value container + void implRegisterExchangeLocation( const NodeValueAccessor& _rAccessor ); + }; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/datetime.hxx b/include/unotools/datetime.hxx new file mode 100644 index 000000000..368ffcb39 --- /dev/null +++ b/include/unotools/datetime.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#ifndef INCLUDED_UNOTOOLS_DATETIME_HXX +#define INCLUDED_UNOTOOLS_DATETIME_HXX + +//= conversions UNO3.TimeClass <-> Tools.TimeClass (Date/Time/DateTime) +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> + +namespace com::sun::star::util { struct Date; } +namespace com::sun::star::util { struct DateTime; } +namespace com::sun::star::util { struct Time; } + +class Date; +class DateTime; +class LocaleDataWrapper; + +namespace utl +{ + UNOTOOLS_DLLPUBLIC const LocaleDataWrapper& GetLocaleData(); + UNOTOOLS_DLLPUBLIC DateTime GetDateTime(const css::util::DateTime& _rDT); + UNOTOOLS_DLLPUBLIC OUString GetDateTimeString(const css::util::DateTime& _rDT); + UNOTOOLS_DLLPUBLIC OUString GetDateTimeString(sal_Int32 _nDate, sal_Int32 _nTime); + UNOTOOLS_DLLPUBLIC OUString GetDateString(const css::util::DateTime& _rDT); + + UNOTOOLS_DLLPUBLIC void typeConvert(const Date& _rDate, css::util::Date& _rOut); + UNOTOOLS_DLLPUBLIC void typeConvert(const css::util::Date& _rDate, Date& _rOut); + + UNOTOOLS_DLLPUBLIC void typeConvert(const DateTime& _rDateTime, css::util::DateTime& _rOut); + UNOTOOLS_DLLPUBLIC void typeConvert(const css::util::DateTime& _rDateTime, DateTime& _rOut); + + UNOTOOLS_DLLPUBLIC OUString toISO8601(const css::util::DateTime& _rDateTime); + UNOTOOLS_DLLPUBLIC bool ISO8601parseDateTime(std::u16string_view i_rIn, css::util::DateTime& o_rDateTime); + UNOTOOLS_DLLPUBLIC bool ISO8601parseDate(std::u16string_view i_rIn, css::util::Date& o_rDate); + UNOTOOLS_DLLPUBLIC bool ISO8601parseTime(std::u16string_view i_rIn, css::util::Time& o_Time); + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_DATETIME_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/defaultencoding.hxx b/include/unotools/defaultencoding.hxx new file mode 100644 index 000000000..8cde4bccb --- /dev/null +++ b/include/unotools/defaultencoding.hxx @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_UNOTOOLS_DEFAULTENCODING_HXX +#define INCLUDED_UNOTOOLS_DEFAULTENCODING_HXX + +#include <sal/config.h> + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> + +/** Determines which locale should be used by default in filters when importing non-unicode strings. +This value should be used when the file does not explicitly define encoding of 8-bit strings. It is +defined by officecfg::Office::Linguistic::General::DefaultLocale, or when it's not set, +officecfg::Setup::L10N::ooSetupSystemLocale, and is typically mapped to a corresponding Windows +codepage by filters. + +@return +A BCP-47 language tag string. +*/ +UNOTOOLS_DLLPUBLIC OUString utl_getLocaleForGlobalDefaultEncoding(); + +#endif // INCLUDED_UNOTOOLS_DEFAULTENCODING_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/defaultoptions.hxx b/include/unotools/defaultoptions.hxx new file mode 100644 index 000000000..dfa07fb5e --- /dev/null +++ b/include/unotools/defaultoptions.hxx @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <unotools/pathoptions.hxx> + +namespace SvtDefaultOptions +{ +UNOTOOLS_DLLPUBLIC OUString GetDefaultPath(SvtPathOptions::Paths nId); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/desktopterminationobserver.hxx b/include/unotools/desktopterminationobserver.hxx new file mode 100644 index 000000000..0d230d357 --- /dev/null +++ b/include/unotools/desktopterminationobserver.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_DESKTOPTERMINATIONOBSERVER_HXX +#define INCLUDED_UNOTOOLS_DESKTOPTERMINATIONOBSERVER_HXX + +#include <config_options.h> +#include <unotools/unotoolsdllapi.h> + +namespace utl +{ + + //= ITerminationListener + + /** non-UNO version of the com.sun.star.frame::XTerminateListener + */ + class ITerminationListener + { + public: + virtual bool queryTermination() const = 0; + virtual void notifyTermination() = 0; + + protected: + ~ITerminationListener() {} + }; + + //= DesktopTerminationObserver + + /** a class which allows non-UNO components to observe the desktop (aka application) + for its shutdown + */ + namespace DesktopTerminationObserver + { + /** registers a listener which should be notified when the desktop terminates + (which means the application is shutting down) + */ + UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) void registerTerminationListener( ITerminationListener* _pListener ); + + /** revokes a termination listener + */ + UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) void revokeTerminationListener( ITerminationListener const * _pListener ); + } + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_DESKTOPTERMINATIONOBSERVER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/digitgroupingiterator.hxx b/include/unotools/digitgroupingiterator.hxx new file mode 100644 index 000000000..7206f72f1 --- /dev/null +++ b/include/unotools/digitgroupingiterator.hxx @@ -0,0 +1,194 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_DIGITGROUPINGITERATOR_HXX +#define INCLUDED_UNOTOOLS_DIGITGROUPINGITERATOR_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include <sal/log.hxx> + +namespace utl { + +/** Iterator to be used with a digit grouping as obtained through + LocaleDataWrapper::getDigitGrouping(). + + The iterator advances over the digit groupings, returning the number of + digits per group. If the last group was encountered the iterator will + always return the last grouping. + + Grouping values are sanitized to be >= 0, even if originally signed + sal_Int32. + + Usage example with a string buffer containing a decimal representation of + an integer number. Note that of course this loop could be optimized to not + count single characters but hunks of groups instead using the get() method, + this is just for illustrating usage. Anyway, for double values it is highly + more efficient to use ::rtl::math::doubleToString() and pass the grouping + sequence, instead of using this iterator and inserting characters into + strings. + + DigitGroupingIterator aGrouping(...) + sal_Int32 nCount = 0; + sal_Int32 n = aBuffer.getLength(); + // >1 because we don't want to insert a separator if there is no leading digit. + while (n-- > 1) + { + if (++nCount >= aGrouping.getPos()) + { + aBuffer.insert( n, cSeparator); + nGroupDigits = aGrouping.advance(); + } + } + + */ + +class DigitGroupingIterator +{ + const css::uno::Sequence< sal_Int32 > maGroupings; + + sal_Int32 mnGroup; // current active grouping + sal_Int32 mnDigits; // current active digits per group + sal_Int32 mnNextPos; // position (in digits) of next grouping + + void setInfinite() + { + mnGroup = maGroupings.getLength(); + } + + bool isInfinite() const + { + return mnGroup >= maGroupings.getLength(); + } + + sal_Int32 getGrouping() const + { + if (mnGroup < maGroupings.getLength()) + { + sal_Int32 n = maGroupings[mnGroup]; + SAL_WARN_IF( n < 0, "unotools.i18n", "DigitGroupingIterator::getGrouping: negative grouping"); + if (n < 0) + n = 0; // sanitize ... + return n; + } + return 0; + } + + void setPos() + { + // someone might be playing jokes on us, so check for overflow + if (mnNextPos <= SAL_MAX_INT32 - mnDigits) + mnNextPos += mnDigits; + } + + void setDigits() + { + sal_Int32 nPrev = mnDigits; + mnDigits = getGrouping(); + if (!mnDigits) + { + mnDigits = nPrev; + setInfinite(); + } + setPos(); + } + + void initGrouping() + { + mnDigits = 3; // just in case of constructed with empty grouping + mnGroup = 0; + mnNextPos = 0; + setDigits(); + } + + DigitGroupingIterator( const DigitGroupingIterator & ) = delete; + DigitGroupingIterator & operator=( const DigitGroupingIterator & ) = delete; + +public: + + explicit DigitGroupingIterator( const css::uno::Sequence< sal_Int32 > & rGroupings ) + : maGroupings( rGroupings) + { + initGrouping(); + } + + /** Advance iterator to next grouping. */ + DigitGroupingIterator & advance() + { + if (isInfinite()) + setPos(); + else + { + ++mnGroup; + setDigits(); + } + return *this; + } + + /** Obtain current grouping. Always > 0. */ + sal_Int32 get() const + { + return mnDigits; + } + + /** The next position (in integer digits) from the right where to insert a + group separator. */ + sal_Int32 getPos() const + { + return mnNextPos; + } + + /** Reset iterator to start again from the right beginning. */ + void reset() + { + initGrouping(); + } + + /** Create a sequence of bool values containing positions where to add a + separator when iterating forward over a string and copying digit per + digit. For example, for grouping in thousands and nIntegerDigits==7 the + sequence returned would be {1,0,0,1,0,0,0} so the caller would add a + separator after the 1st and the 4th digit. */ + static css::uno::Sequence< sal_Bool > createForwardSequence( + sal_Int32 nIntegerDigits, + const css::uno::Sequence< sal_Int32 > & rGroupings ) + { + if (nIntegerDigits <= 0) + return css::uno::Sequence< sal_Bool >(); + DigitGroupingIterator aIterator( rGroupings); + css::uno::Sequence< sal_Bool > aSeq( nIntegerDigits); + sal_Bool* pArr = aSeq.getArray(); + for (sal_Int32 j = 0; --nIntegerDigits >= 0; ++j) + { + if (j == aIterator.getPos()) + { + pArr[nIntegerDigits] = true; + aIterator.advance(); + } + else + pArr[nIntegerDigits] = false; + } + return aSeq; + } +}; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_DIGITGROUPINGITERATOR_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/docinfohelper.hxx b/include/unotools/docinfohelper.hxx new file mode 100644 index 000000000..d6323cc9b --- /dev/null +++ b/include/unotools/docinfohelper.hxx @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> + +namespace utl +{ +class UNOTOOLS_DLLPUBLIC DocInfoHelper +{ +public: + static OUString GetGeneratorString(); +}; + +} // namespace utl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/dynamicmenuoptions.hxx b/include/unotools/dynamicmenuoptions.hxx new file mode 100644 index 000000000..b046f7dbd --- /dev/null +++ b/include/unotools/dynamicmenuoptions.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_DYNAMICMENUOPTIONS_HXX +#define INCLUDED_UNOTOOLS_DYNAMICMENUOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <vector> + +/*-**************************************************************************************************************** + @descr struct to hold information about one menu entry. +****************************************************************************************************************-*/ +struct SvtDynMenuEntry +{ + OUString sURL; + OUString sTitle; + OUString sImageIdentifier; + OUString sTargetName; +}; + +/*-************************************************************************************************************ + @descr You can use these enum values to specify right menu if you call our interface methods. +*//*-*************************************************************************************************************/ +enum class EDynamicMenuType +{ + NewMenu = 0, + WizardMenu = 1 +}; + + +/*-************************************************************************************************************ + @short collect information about dynamic menus + @descr Make it possible to configure dynamic menu structures of menus like "new" or "wizard". + @devstatus ready to use +*//*-*************************************************************************************************************/ + +namespace SvtDynamicMenuOptions +{ + + /*-**************************************************************************************************** + @short return complete specified list + @descr Call it to get all entries of an dynamic menu. + We return a list of all nodes with its names and properties. + @param "eMenu" select right menu. + @return A list of menu items is returned. + + @onerror We return an empty list. + *//*-*****************************************************************************************************/ + + UNOTOOLS_DLLPUBLIC std::vector< SvtDynMenuEntry > GetMenu( EDynamicMenuType eMenu ); + + +}; // namespace SvtDynamicMenuOptions + +#endif // INCLUDED_UNOTOOLS_DYNAMICMENUOPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/eventcfg.hxx b/include/unotools/eventcfg.hxx new file mode 100644 index 000000000..7ddca4a96 --- /dev/null +++ b/include/unotools/eventcfg.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_EVENTCFG_HXX +#define INCLUDED_UNOTOOLS_EVENTCFG_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <cppuhelper/implbase.hxx> + +enum class GlobalEventId +{ + STARTAPP, + CLOSEAPP, + DOCCREATED, + CREATEDOC, + LOADFINISHED, + OPENDOC, + PREPARECLOSEDOC, + CLOSEDOC, + SAVEDOC, + SAVEDOCDONE, + SAVEDOCFAILED, + SAVEASDOC, + SAVEASDOCDONE, + SAVEASDOCFAILED, + SAVETODOC, + SAVETODOCDONE, + SAVETODOCFAILED, + ACTIVATEDOC, + DEACTIVATEDOC, + PRINTDOC, + VIEWCREATED, + PREPARECLOSEVIEW, + CLOSEVIEW, + MODIFYCHANGED, + TITLECHANGED, + VISAREACHANGED, + MODECHANGED, + STORAGECHANGED, + LAST = STORAGECHANGED +}; + +class GlobalEventConfig_Impl; + +class UNOTOOLS_DLLPUBLIC GlobalEventConfig final : + public cppu::WeakImplHelper< css::document::XEventsSupplier, css::container::XNameReplace > +{ + public: + GlobalEventConfig( ); + virtual ~GlobalEventConfig( ) override; + + css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override; + void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override; + css::uno::Any SAL_CALL getByName( const OUString& aName ) override; + css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override; + sal_Bool SAL_CALL hasByName( const OUString& aName ) override; + css::uno::Type SAL_CALL getElementType( ) override; + sal_Bool SAL_CALL hasElements( ) override; + static OUString GetEventName( GlobalEventId nID ); + + css::uno::Sequence < css::beans::PropertyValue > getByName2( const OUString& aName ); + + private: + static GlobalEventConfig_Impl* m_pImpl; + static sal_Int32 m_nRefCount; +}; + +#endif // INCLUDED_UNOTOOLS_EVENTCFG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/eventlisteneradapter.hxx b/include/unotools/eventlisteneradapter.hxx new file mode 100644 index 000000000..92fbe212c --- /dev/null +++ b/include/unotools/eventlisteneradapter.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_EVENTLISTENERADAPTER_HXX +#define INCLUDED_UNOTOOLS_EVENTLISTENERADAPTER_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/lang/EventObject.hpp> +#include <memory> + +namespace com::sun::star::uno { template <typename > class Reference; } +namespace com::sun::star::lang { class XComponent; } + +namespace utl +{ + + struct OEventListenerAdapterImpl; + + //= OEventListenerAdapter + + /** base class for non-UNO dispose listeners + */ + class UNOTOOLS_DLLPUBLIC OEventListenerAdapter + { + friend class OEventListenerImpl; + + private: + OEventListenerAdapter( const OEventListenerAdapter& _rSource ) = delete; + const OEventListenerAdapter& operator=( const OEventListenerAdapter& _rSource ) = delete; + + protected: + std::unique_ptr<OEventListenerAdapterImpl> m_pImpl; + + protected: + OEventListenerAdapter(); + virtual ~OEventListenerAdapter(); + + void startComponentListening( const css::uno::Reference< css::lang::XComponent >& _rxComp ); + void stopComponentListening( const css::uno::Reference< css::lang::XComponent >& _rxComp ); + void stopAllComponentListening( ); + + virtual void _disposing( const css::lang::EventObject& _rSource ) = 0; + }; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_EVENTLISTENERADAPTER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/extendedsecurityoptions.hxx b/include/unotools/extendedsecurityoptions.hxx new file mode 100644 index 000000000..4a2b493e8 --- /dev/null +++ b/include/unotools/extendedsecurityoptions.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +namespace SvtExtendedSecurityOptions +{ + // Must be zero based! + enum OpenHyperlinkMode + { + OPEN_NEVER = 0, + OPEN_WITHSECURITYCHECK, + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/fltrcfg.hxx b/include/unotools/fltrcfg.hxx new file mode 100644 index 000000000..bac46c03c --- /dev/null +++ b/include/unotools/fltrcfg.hxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_FLTRCFG_HXX +#define INCLUDED_UNOTOOLS_FLTRCFG_HXX + +#include <o3tl/deleter.hxx> +#include <unotools/unotoolsdllapi.h> +#include <unotools/configitem.hxx> +#include <memory> + +struct SvtFilterOptions_Impl; +class UNOTOOLS_DLLPUBLIC SvtFilterOptions final : public utl::ConfigItem +{ +private: + std::unique_ptr<SvtFilterOptions_Impl, o3tl::default_delete<SvtFilterOptions_Impl>> pImpl; + + virtual void ImplCommit() override; + +public: + SvtFilterOptions(); + virtual ~SvtFilterOptions() override; + + virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames) override; + void Load(); + + void SetLoadWordBasicCode( bool bFlag ); + bool IsLoadWordBasicCode() const; + void SetLoadWordBasicExecutable( bool bFlag ); + bool IsLoadWordBasicExecutable() const; + void SetLoadWordBasicStorage( bool bFlag ); + bool IsLoadWordBasicStorage() const; + + void SetLoadExcelBasicCode( bool bFlag ); + bool IsLoadExcelBasicCode() const; + void SetLoadExcelBasicExecutable( bool bFlag ); + bool IsLoadExcelBasicExecutable() const; + void SetLoadExcelBasicStorage( bool bFlag ); + bool IsLoadExcelBasicStorage() const; + + void SetLoadPPointBasicCode( bool bFlag ); + bool IsLoadPPointBasicCode() const; + void SetLoadPPointBasicStorage( bool bFlag ); + bool IsLoadPPointBasicStorage() const; + + bool IsMathType2Math() const; + void SetMathType2Math( bool bFlag ); + bool IsMath2MathType() const; + void SetMath2MathType( bool bFlag ); + + bool IsWinWord2Writer() const; + void SetWinWord2Writer( bool bFlag ); + bool IsWriter2WinWord() const; + void SetWriter2WinWord( bool bFlag ); + + bool IsUseEnhancedFields() const; + + bool IsExcel2Calc() const; + void SetExcel2Calc( bool bFlag ); + bool IsCalc2Excel() const; + void SetCalc2Excel( bool bFlag ); + + bool IsPowerPoint2Impress() const; + void SetPowerPoint2Impress( bool bFlag ); + bool IsImpress2PowerPoint() const; + void SetImpress2PowerPoint( bool bFlag ); + + bool IsSmartArt2Shape() const; + void SetSmartArt2Shape( bool bFlag ); + + bool IsEnablePPTPreview() const; + bool IsEnableCalcPreview() const; + bool IsEnableWordPreview() const; + + bool IsCharBackground2Highlighting() const; + bool IsCharBackground2Shading() const; + void SetCharBackground2Highlighting(); + void SetCharBackground2Shading(); + + bool IsMSOLockFileCreationIsEnabled() const; + void EnableMSOLockFileCreation(bool bEnable); + + bool IsVisio2Draw() const; + void SetVisio2Draw(bool bFlag); + + static SvtFilterOptions& Get(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/fontcfg.hxx b/include/unotools/fontcfg.hxx new file mode 100644 index 000000000..1f77d4845 --- /dev/null +++ b/include/unotools/fontcfg.hxx @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_FONTCFG_HXX +#define INCLUDED_UNOTOOLS_FONTCFG_HXX + +#include <config_options.h> +#include <unotools/unotoolsdllapi.h> +#include <tools/fontenum.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <o3tl/typed_flags_set.hxx> +#include <i18nlangtag/languagetag.hxx> + +#include <unordered_map> +#include <unordered_set> +#include <vector> + +namespace com::sun::star::container { class XNameAccess; } +namespace com::sun::star::lang { class XMultiServiceFactory; } + +enum class DefaultFontType; + +// If you think the below concept of classifying a font (typeface) as possibly being one or several +// of "Default", "Standard", and "Normal", etc, is madness, you are probably right. On the other +// hand we have in officecfg/registry/data/org/openoffice/VCL.xcu carefully (or not) assigned to +// each font mentioned in that file what its attributes are, so it is quite possible that touching +// this would cause a regression that nobody would notice until after many years. + +// Note that the bit flags must match the entries in the pAttribNames array in +// unotools/source/config/fontcfg.cxx. + +enum class ImplFontAttrs : sal_uInt32 +{ + None = 0x00000000, + Default = 0x00000001, ///< Default-Font like Andale Sans UI, Palace Script, Albany, Thorndale, Cumberland, ... + Standard = 0x00000002, ///< Standard-Font like Arial, Times, Courier, ... + Normal = 0x00000004, ///< Normal Font for writing text like Arial, Verdana, Arial Narrow, Trebuchet, Times, Courier, ... + Symbol = 0x00000008, ///< Font with symbols + Fixed = 0x00000010, + SansSerif = 0x00000020, + Serif = 0x00000040, + Decorative = 0x00000080, ///< Readable and normally used for drawings + Special = 0x00000100, ///< Very special design + Italic = 0x00000200, + Titling = 0x00000400, ///< Only uppercase characters + Capitals = 0x00000800, ///< Only uppercase characters, but lowercase characters smaller as the uppercase characters + CJK = 0x00001000, + CJK_JP = 0x00002000, + CJK_SC = 0x00004000, + CJK_TC = 0x00008000, + CJK_KR = 0x00010000, + CTL = 0x00020000, + NoneLatin = 0x00040000, + Full = 0x00080000, ///< Font with normally all characters + Outline = 0x00100000, + Shadow = 0x00200000, + Rounded = 0x00400000, + Typewriter = 0x00800000, ///< Like a typewriter: Courier, ... + Script = 0x01000000, ///< Handwriting or Script + Handwriting = 0x02000000, ///< More Handwriting with normal letters + Chancery = 0x04000000, ///< Like Zapf Chancery + Comic = 0x08000000, ///< Like Comic Sans MS + BrushScript = 0x10000000, ///< More Script + Gothic = 0x20000000, + Schoolbook = 0x40000000, + OtherStyle = 0x80000000, ///< OldStyle, ... so negative points + CJK_AllLang = CJK_JP | CJK_SC | CJK_TC | CJK_KR, + AllScript = Script | Handwriting | Chancery | Comic | BrushScript, + AllSubscript = Handwriting | Chancery | Comic | BrushScript, + AllSerifStyle = AllScript | SansSerif | Serif | Fixed | Italic | Gothic | Schoolbook | Shadow | Outline, +}; +namespace o3tl +{ + template<> struct typed_flags<ImplFontAttrs> : is_typed_flags<ImplFontAttrs, 0xffffffff> {}; +} + + +namespace utl +{ + +class UNOTOOLS_DLLPUBLIC DefaultFontConfiguration +{ + css::uno::Reference< css::lang::XMultiServiceFactory > + m_xConfigProvider; + css::uno::Reference< css::container::XNameAccess > + m_xConfigAccess; + + struct LocaleAccess + { + // the real string used in the configuration + // used to get rid of upper/lower case problems + OUString aConfigLocaleString; + // xAccess is mutable to be able to be filled on demand + mutable css::uno::Reference< css::container::XNameAccess > xAccess; + }; + + std::unordered_map< OUString, LocaleAccess > m_aConfig; + + OUString tryLocale( const OUString& rBcp47, const OUString& rType ) const; + + public: + DefaultFontConfiguration(); + ~DefaultFontConfiguration(); + + static DefaultFontConfiguration& get(); + + OUString getDefaultFont( const LanguageTag& rLanguageTag, DefaultFontType nType ) const; + OUString getUserInterfaceFont( const LanguageTag& rLanguageTag ) const; +}; + +struct UNOTOOLS_DLLPUBLIC FontNameAttr +{ + OUString Name; + ::std::vector< OUString > Substitutions; + ::std::vector< OUString > MSSubstitutions; + FontWeight Weight; + FontWidth Width; + ImplFontAttrs Type; +}; + +class UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) FontSubstConfiguration +{ +private: + css::uno::Reference< css::lang::XMultiServiceFactory > + m_xConfigProvider; + css::uno::Reference< css::container::XNameAccess > + m_xConfigAccess; + struct LocaleSubst + { + OUString aConfigLocaleString; + mutable bool bConfigRead; + // note: aSubstAttributes must be sorted alphabetically by Name + // searches on the substitutes are done with Name as key, where + // a minimal match is sufficient (that is e.g. "Thorndale" will match + // "Thorndale BlaBlub"). Also names must be lower case. + mutable std::vector< FontNameAttr > aSubstAttributes; + + LocaleSubst() : bConfigRead( false ) {} + }; + std::unordered_map< OUString, LocaleSubst > m_aSubst; + typedef std::unordered_set< OUString > UniqueSubstHash; + mutable UniqueSubstHash maSubstHash; + LanguageTag maLanguageTag; + + void fillSubstVector( const css::uno::Reference< css::container::XNameAccess >& rFont, + const OUString& rType, + std::vector< OUString >& rSubstVector ) const; + FontWeight getSubstWeight( const css::uno::Reference< css::container::XNameAccess >& rFont, + const OUString& rType ) const; + FontWidth getSubstWidth( const css::uno::Reference< css::container::XNameAccess >& rFont, + const OUString& rType ) const; + ImplFontAttrs getSubstType( const css::uno::Reference< css::container::XNameAccess >& rFont, + const OUString& rType ) const; + void readLocaleSubst( const OUString& rBcp47 ) const; +public: + FontSubstConfiguration(); + ~FontSubstConfiguration(); + + static FontSubstConfiguration& get(); + + const FontNameAttr* getSubstInfo( const OUString& rFontName ) const; + static void getMapName( const OUString& rOrgName, OUString& rShortName, OUString& rFamilyName, FontWeight& rWeight, FontWidth& rWidth, ImplFontAttrs& rType ); +}; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_FONTCFG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/fontcvt.hxx b/include/unotools/fontcvt.hxx new file mode 100644 index 000000000..979183746 --- /dev/null +++ b/include/unotools/fontcvt.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_FONTCVT_HXX +#define INCLUDED_UNOTOOLS_FONTCVT_HXX + +#include <sal/config.h> + +#include <string_view> + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> + + +enum class FontToSubsFontFlags +{ + IMPORT = 0x01, + EXPORT = 0x02 +}; + +typedef void* FontToSubsFontConverter; +UNOTOOLS_DLLPUBLIC FontToSubsFontConverter CreateFontToSubsFontConverter( std::u16string_view rFontName, FontToSubsFontFlags nFlags ); +UNOTOOLS_DLLPUBLIC sal_Unicode ConvertFontToSubsFontChar( FontToSubsFontConverter hConverter, sal_Unicode c ); +UNOTOOLS_DLLPUBLIC OUString GetFontToSubsFontName( FontToSubsFontConverter hConverter ); + + +class UNOTOOLS_DLLPUBLIC StarSymbolToMSMultiFont +{ +public: + // Returns the name of the best windows symbol font which this char can be + // mapped to. Sets rChar to the correct position for that font. If no + // match found, then no name is returned, and rChar is unchanged. If you + // want to convert a string, you don't want to use this. + virtual OUString ConvertChar(sal_Unicode &rChar) = 0; + + virtual ~StarSymbolToMSMultiFont() {} +}; + + +// The converter will allow somewhat dubious mappings to the windows symbols fonts, +// that are nevertheless recognizably similar. Even in this mode there will be characters that fail. +// The users of this might want to make a distinction between failed characters +// which were inside and those outside the unicode private area. +UNOTOOLS_DLLPUBLIC StarSymbolToMSMultiFont *CreateStarSymbolToMSMultiFont(); + +#endif // INCLUDED_UNOTOOLS_FONTCVT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/fontdefs.hxx b/include/unotools/fontdefs.hxx new file mode 100644 index 000000000..aff10c860 --- /dev/null +++ b/include/unotools/fontdefs.hxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_FONTDEFS_HXX +#define INCLUDED_UNOTOOLS_FONTDEFS_HXX + +#include <sal/config.h> + +#include <string_view> + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <o3tl/typed_flags_set.hxx> +#include <config_options.h> + +enum class SubsFontFlags +{ + ONLYONE = 0x01, + MS = 0x02 +}; + +namespace o3tl +{ + template<> struct typed_flags<SubsFontFlags> : is_typed_flags<SubsFontFlags, 0x03> {}; +} + +UNOTOOLS_DLLPUBLIC OUString GetSubsFontName( std::u16string_view rName, SubsFontFlags nFlags ); + +UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) void AddTokenFontName( OUString& rName, std::u16string_view rNewToken ); + + +class UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) ConvertChar +{ +public: + const sal_Unicode* mpCvtTab; + const char* mpSubsFontName; + sal_Unicode (*mpCvtFunc)( sal_Unicode ); + sal_Unicode RecodeChar( sal_Unicode c ) const; + void RecodeString( OUString& rStra, sal_Int32 nIndex, sal_Int32 nLen ) const; + static const ConvertChar* GetRecodeData( std::u16string_view rOrgFontName, std::u16string_view rMapFontName ); +}; + + +enum class DefaultFontType +{ + SANS_UNICODE = 1, + SANS = 2, + SERIF = 3, + FIXED = 4, + SYMBOL = 5, + UI_SANS = 1000, + UI_FIXED = 1001, + LATIN_TEXT = 2000, + LATIN_PRESENTATION = 2001, + LATIN_SPREADSHEET = 2002, + LATIN_HEADING = 2003, + LATIN_DISPLAY = 2004, + LATIN_FIXED = 2005, + CJK_TEXT = 3000, + CJK_PRESENTATION = 3001, + CJK_SPREADSHEET = 3002, + CJK_HEADING = 3003, + CJK_DISPLAY = 3004, + CTL_TEXT = 4000, + CTL_PRESENTATION = 4001, + CTL_SPREADSHEET = 4002, + CTL_HEADING = 4003, + CTL_DISPLAY = 4004, +}; + +UNOTOOLS_DLLPUBLIC std::u16string_view GetNextFontToken( std::u16string_view rTokenStr, sal_Int32& rIndex ); +UNOTOOLS_DLLPUBLIC OUString GetEnglishSearchFontName( std::u16string_view rName ); + +/** Strip any "script font suffix" from the font name + + Related: fdo#49271 RTF files often contain weird-ass + Win 3.1/Win95 style fontnames which attempt to put the + charset encoding into the filename + http://www.webcenter.ru/~kazarn/eng/fonts_ttf.htm +*/ +UNOTOOLS_DLLPUBLIC OUString StripScriptFromName(const OUString& rName); + +/** Determine if the font is the special Star|Open Symbol font + + @param rFontName + The FontName to test for being Star|Open Symbol + + @return true if this is Star|Open Symbol +*/ +// FIXME It's quite possible that code using this should instead check for RTL_TEXTENCODING_SYMBOL. +UNOTOOLS_DLLPUBLIC bool IsStarSymbol(std::u16string_view rFontName); + +#endif // INCLUDED_UNOTOOLS_FONTDEFS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/historyoptions.hxx b/include/unotools/historyoptions.hxx new file mode 100644 index 000000000..1f743e062 --- /dev/null +++ b/include/unotools/historyoptions.hxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <vector> +#include <optional> + +/// You can use these enum values to specify right history if you call our interface methods. +enum class EHistoryType +{ + PickList, + HelpBookmarks +}; + +/** Collect information about history features. + + Interface methods to get and set value of config key "org.openoffice.Office.Common/History/..." + + key "PickList": The last used documents displayed in the file menu. + key "History": The last opened documents general. +*/ +namespace SvtHistoryOptions +{ + + /** Clear complete specified list. + + @param eHistory select right history. + */ + UNOTOOLS_DLLPUBLIC void Clear(EHistoryType eHistory); + + /** Return the complete specified history list. + + @param eHistory select right history. + @return A list of history items is returned. + */ + struct HistoryItem + { + OUString sURL; + OUString sFilter; + OUString sTitle; + OUString sPassword; + OUString sThumbnail; + bool isReadOnly = false; + }; + UNOTOOLS_DLLPUBLIC std::vector< HistoryItem > GetList(EHistoryType eHistory); + + /** Append a new item to the specified list. + + The oldest entry is deleted automatically when the size reaches the maximum. + + @param eHistory select right history. + @param sURL URL to save in history + @param sFilter filter name to save in history + @param sTitle document title to save in history + */ + UNOTOOLS_DLLPUBLIC void AppendItem(EHistoryType eHistory, + const OUString& sURL, const OUString& sFilter, const OUString& sTitle, + const std::optional<OUString>& sThumbnail, std::optional<bool> oIsReadOnly); + + /** Delete item from the specified list. + */ + UNOTOOLS_DLLPUBLIC void DeleteItem(EHistoryType eHistory, const OUString& sURL); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/intlwrapper.hxx b/include/unotools/intlwrapper.hxx new file mode 100644 index 000000000..e86346a95 --- /dev/null +++ b/include/unotools/intlwrapper.hxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_INTLWRAPPER_HXX +#define INCLUDED_UNOTOOLS_INTLWRAPPER_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/uno/Reference.h> + +#include <i18nlangtag/languagetag.hxx> +#include <memory> + +namespace com::sun::star::uno { class XComponentContext; } + +class CollatorWrapper; +class LocaleDataWrapper; + +/** + A wrapper of I18N wrappers. Using this is more expensive than using some + single wrapper classes so use it only if you must pass a single pointer + without knowing in advance what is needed, e.g. for + SfxPoolItem::GetPresentation(). Remember that this wrapper was only created + for convenience to bypass some oddities, if possible don't use it. <p> + + Implemented are only the const get...() methods of the wrappers, which are + loaded on demand, for consistency reasons no change of locale is possible. + Only default calendar and default collator are supported. <p> + + One exception though is the calendar wrapper: to be able to set a value and + retrieve calendar values it is not const, so methods using this should + reset the calendar to the previous value if it isn't sure where the + IntlWrapper did come from. <p> + */ +class UNOTOOLS_DLLPUBLIC IntlWrapper +{ +private: + LanguageTag maLanguageTag; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + + std::unique_ptr<LocaleDataWrapper> pLocaleData; + std::unique_ptr<CollatorWrapper> pCollator; + std::unique_ptr<CollatorWrapper> pCaseCollator; + + void ImplNewLocaleData() const; + void ImplNewCollator( bool bCaseSensitive ) const; + +public: + IntlWrapper(LanguageTag aLanguageTag); + ~IntlWrapper(); + + const LocaleDataWrapper* getLocaleData() const + { + if ( !pLocaleData ) + ImplNewLocaleData(); + return pLocaleData.get(); + } + /// case insensitive collator, simple IGNORE_CASE + const CollatorWrapper* getCollator() const + { + if ( !pCollator ) + ImplNewCollator( false ); + return pCollator.get(); + } + /// case sensitive collator + const CollatorWrapper* getCaseCollator() const + { + if ( !pCaseCollator ) + ImplNewCollator( true ); + return pCaseCollator.get(); + } +}; + +#endif // INCLUDED_UNOTOOLS_INTLWRAPPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/itemholderbase.hxx b/include/unotools/itemholderbase.hxx new file mode 100644 index 000000000..9ce013162 --- /dev/null +++ b/include/unotools/itemholderbase.hxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_ITEMHOLDERBASE_HXX +#define INCLUDED_UNOTOOLS_ITEMHOLDERBASE_HXX + +#include <memory> +#include <unotools/options.hxx> + +enum class EItem +{ + AccessibilityOptions , // 2 + + CmdOptions , + ColorConfig , // 2 + Compatibility , + CTLOptions , // 2 + + EventConfig , + + LinguConfig , + + MiscOptions , + ModuleOptions , + + PathOptions , + + SysLocaleOptions , // 2 + + UserOptions , // 2 +}; + +struct TItemInfo +{ + TItemInfo() + : eItem(EItem::UserOptions) + { + } + + TItemInfo(TItemInfo&& other) noexcept + : pItem(std::move(other.pItem)) + , eItem(other.eItem) + { + } + + std::unique_ptr<utl::detail::Options> pItem; + EItem eItem; +}; + +#endif // INCLUDED_UNOTOOLS_ITEMHOLDERBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/lingucfg.hxx b/include/unotools/lingucfg.hxx new file mode 100644 index 000000000..b4a0b824e --- /dev/null +++ b/include/unotools/lingucfg.hxx @@ -0,0 +1,209 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_LINGUCFG_HXX +#define INCLUDED_UNOTOOLS_LINGUCFG_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Any.h> +#include <rtl/ustring.hxx> +#include <unotools/options.hxx> +#include <i18nlangtag/lang.h> +#include <vector> + +namespace com::sun::star::beans { struct PropertyValue; } +namespace com::sun::star::util { class XChangesBatch; } + +class SvtLinguConfigItem; + +struct UNOTOOLS_DLLPUBLIC SvtLinguOptions +{ + css::uno::Sequence< OUString > aActiveDics; + css::uno::Sequence< OUString > aActiveConvDics; + + bool bROActiveDics; + bool bROActiveConvDics; + + // Hyphenator service specific options + sal_Int16 nHyphMinLeading, + nHyphMinTrailing, + nHyphMinWordLength; + + bool bROHyphMinLeading, + bROHyphMinTrailing, + bROHyphMinWordLength; + + // misc options (non-service specific) + LanguageType nDefaultLanguage; + LanguageType nDefaultLanguage_CJK; + LanguageType nDefaultLanguage_CTL; + + bool bRODefaultLanguage; + bool bRODefaultLanguage_CJK; + bool bRODefaultLanguage_CTL; + + // spelling options (non-service specific) + bool bIsSpellSpecial; + bool bIsSpellAuto; + bool bIsSpellReverse; + + bool bROIsSpellSpecial; + bool bROIsSpellAuto; + bool bROIsSpellReverse; + + // hyphenation options (non-service specific) + bool bIsHyphSpecial; + bool bIsHyphAuto; + + bool bROIsHyphSpecial; + bool bROIsHyphAuto; + + // common to SpellChecker, Hyphenator and Thesaurus service + bool bIsUseDictionaryList; + bool bIsIgnoreControlCharacters; + + bool bROIsUseDictionaryList; + bool bROIsIgnoreControlCharacters; + + // SpellChecker service specific options + bool bIsSpellWithDigits, + bIsSpellUpperCase, + bIsSpellCapitalization; + + bool bROIsSpellWithDigits, + bROIsSpellUpperCase, + bROIsSpellCapitalization; + + // text conversion specific options + bool bIsIgnorePostPositionalWord; + bool bIsAutoCloseDialog; + bool bIsShowEntriesRecentlyUsedFirst; + bool bIsAutoReplaceUniqueEntries; + bool bIsDirectionToSimplified; + bool bIsUseCharacterVariants; + bool bIsTranslateCommonTerms; + bool bIsReverseMapping; + + bool bROIsIgnorePostPositionalWord; + bool bROIsAutoCloseDialog; + bool bROIsShowEntriesRecentlyUsedFirst; + bool bROIsAutoReplaceUniqueEntries; + bool bROIsDirectionToSimplified; + bool bROIsUseCharacterVariants; + bool bROIsTranslateCommonTerms; + bool bROIsReverseMapping; + + // check value need to determine if the configuration needs to be updated + // or not (used for a quick check if data files have been changed/added + // or deleted + sal_Int32 nDataFilesChangedCheckValue; + bool bRODataFilesChangedCheckValue; + + bool bIsGrammarAuto; + bool bIsGrammarInteractive; + + bool bROIsGrammarAuto; + bool bROIsGrammarInteractive; + + SvtLinguOptions(); +}; + +struct UNOTOOLS_DLLPUBLIC SvtLinguConfigDictionaryEntry +{ + // the URL's pointing to the location of the files the dictionary consists of + css::uno::Sequence< OUString > aLocations; + // the name of the dictionary format implement + OUString aFormatName; + // the list of languages (ISO names) the dictionary can be used for + css::uno::Sequence< OUString > aLocaleNames; +}; + +class UNOTOOLS_DLLPUBLIC SvtLinguConfig final : public utl::detail::Options +{ + // returns static object + UNOTOOLS_DLLPRIVATE static SvtLinguConfigItem & GetConfigItem(); + + // configuration update access for the 'Linguistic' main node + mutable css::uno::Reference< css::util::XChangesBatch > m_xMainUpdateAccess; + + css::uno::Reference< css::util::XChangesBatch > const & GetMainUpdateAccess() const; + + OUString GetVendorImageUrl_Impl( const OUString &rServiceImplName, const OUString &rImageName ) const; + + SvtLinguConfig( const SvtLinguConfig & ) = delete; + SvtLinguConfig & operator = ( const SvtLinguConfig & ) = delete; + +public: + SvtLinguConfig(); + virtual ~SvtLinguConfig() override; + + // borrowed from utl::ConfigItem + + css::uno::Sequence< OUString > + GetNodeNames( const OUString &rNode ) const; + + css::uno::Sequence< css::uno::Any > + GetProperties( + const css::uno::Sequence< OUString > &rNames ) const; + + bool + ReplaceSetProperties( + const OUString &rNode, + const css::uno::Sequence< css::beans::PropertyValue >& rValues ); + + css::uno::Any + GetProperty( std::u16string_view rPropertyName ) const; + css::uno::Any + GetProperty( sal_Int32 nPropertyHandle ) const; + + bool SetProperty( std::u16string_view rPropertyName, + const css::uno::Any &rValue ); + bool SetProperty( sal_Int32 nPropertyHandle, + const css::uno::Any &rValue ); + + void GetOptions( SvtLinguOptions &rOptions ) const; + + bool IsReadOnly( std::u16string_view rPropertyName ) const; + + //! + //! the following functions work on the 'ServiceManager' sub node of the + //! linguistic configuration only + //! + bool GetElementNamesFor( const OUString &rNodeName, css::uno::Sequence< OUString > &rElementNames ) const; + + bool GetSupportedDictionaryFormatsFor( const OUString &rSetName, const OUString &rSetEntry, css::uno::Sequence< OUString > &rFormatList ) const; + + bool GetDictionaryEntry( const OUString &rNodeName, SvtLinguConfigDictionaryEntry &rDicEntry ) const; + + css::uno::Sequence< OUString > GetDisabledDictionaries() const; + + std::vector< SvtLinguConfigDictionaryEntry > GetActiveDictionariesByFormat( std::u16string_view rFormatName ) const; + + // functions returning file URLs to the respective images (if found) and empty string otherwise + OUString GetSpellAndGrammarContextSuggestionImage( const OUString &rServiceImplName ) const; + OUString GetSpellAndGrammarContextDictionaryImage( const OUString &rServiceImplName ) const; + OUString GetSynonymsContextImage( const OUString &rServiceImplName ) const; + + bool HasGrammarChecker() const; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/linguprops.hxx b/include/unotools/linguprops.hxx new file mode 100644 index 000000000..971c02804 --- /dev/null +++ b/include/unotools/linguprops.hxx @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <rtl/ustring.hxx> + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif + +// UNO property names for general options +inline constexpr OUStringLiteral UPN_IS_GERMAN_PRE_REFORM = u"IsGermanPreReform"; /*! deprecated #i91949 !*/ +inline constexpr OUStringLiteral UPN_IS_USE_DICTIONARY_LIST = u"IsUseDictionaryList"; +inline constexpr OUStringLiteral UPN_IS_IGNORE_CONTROL_CHARACTERS = u"IsIgnoreControlCharacters"; +inline constexpr OUStringLiteral UPN_ACTIVE_DICTIONARIES = u"ActiveDictionaries"; + +// UNO property names for SpellChecker +inline constexpr OUStringLiteral UPN_IS_SPELL_UPPER_CASE = u"IsSpellUpperCase"; +inline constexpr OUStringLiteral UPN_IS_SPELL_WITH_DIGITS = u"IsSpellWithDigits"; +inline constexpr OUStringLiteral UPN_IS_SPELL_CAPITALIZATION = u"IsSpellCapitalization"; + +// UNO property names for Hyphenator +inline constexpr OUStringLiteral UPN_HYPH_MIN_LEADING = u"HyphMinLeading"; +inline constexpr OUStringLiteral UPN_HYPH_MIN_TRAILING = u"HyphMinTrailing"; +inline constexpr OUStringLiteral UPN_HYPH_MIN_WORD_LENGTH = u"HyphMinWordLength"; +inline constexpr OUStringLiteral UPN_HYPH_NO_CAPS = u"HyphNoCaps"; +inline constexpr OUStringLiteral UPN_HYPH_NO_LAST_WORD = u"HyphNoLastWord"; +inline constexpr OUStringLiteral UPN_HYPH_ZONE = u"HyphZone"; + +// UNO property names for Lingu +// (those not covered by the SpellChecker and Hyphenator +// properties and more likely to be used in other modules only) +inline constexpr OUStringLiteral UPN_DEFAULT_LANGUAGE = u"DefaultLanguage"; +inline constexpr OUStringLiteral UPN_DEFAULT_LOCALE = u"DefaultLocale"; +inline constexpr OUStringLiteral UPN_DEFAULT_LOCALE_CJK = u"DefaultLocale_CJK"; +inline constexpr OUStringLiteral UPN_DEFAULT_LOCALE_CTL = u"DefaultLocale_CTL"; +inline constexpr OUStringLiteral UPN_IS_HYPH_AUTO = u"IsHyphAuto"; +inline constexpr OUStringLiteral UPN_IS_HYPH_SPECIAL = u"IsHyphSpecial"; +inline constexpr OUStringLiteral UPN_IS_SPELL_AUTO = u"IsSpellAuto"; +inline constexpr OUStringLiteral UPN_IS_SPELL_HIDE = u"IsSpellHide"; /*! deprecated #i91949 !*/ +inline constexpr OUStringLiteral UPN_IS_SPELL_IN_ALL_LANGUAGES = u"IsSpellInAllLanguages"; /*! deprecated #i91949 !*/ +inline constexpr OUStringLiteral UPN_IS_SPELL_SPECIAL = u"IsSpellSpecial"; +inline constexpr OUStringLiteral UPN_IS_WRAP_REVERSE = u"IsWrapReverse"; +inline constexpr OUStringLiteral UPN_DATA_FILES_CHANGED_CHECK_VALUE = u"DataFilesChangedCheckValue"; + +// UNO property names for text conversion options +inline constexpr OUStringLiteral UPN_ACTIVE_CONVERSION_DICTIONARIES = u"ActiveConversionDictionaries"; +inline constexpr OUStringLiteral UPN_IS_IGNORE_POST_POSITIONAL_WORD = u"IsIgnorePostPositionalWord"; +inline constexpr OUStringLiteral UPN_IS_AUTO_CLOSE_DIALOG = u"IsAutoCloseDialog"; +inline constexpr OUStringLiteral UPN_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST = u"IsShowEntriesRecentlyUsedFirst"; +inline constexpr OUStringLiteral UPN_IS_AUTO_REPLACE_UNIQUE_ENTRIES = u"IsAutoReplaceUniqueEntries"; +inline constexpr OUStringLiteral UPN_IS_DIRECTION_TO_SIMPLIFIED = u"IsDirectionToSimplified"; +inline constexpr OUStringLiteral UPN_IS_USE_CHARACTER_VARIANTS = u"IsUseCharacterVariants"; +inline constexpr OUStringLiteral UPN_IS_TRANSLATE_COMMON_TERMS = u"IsTranslateCommonTerms"; +inline constexpr OUStringLiteral UPN_IS_REVERSE_MAPPING = u"IsReverseMapping"; + +inline constexpr OUStringLiteral UPN_IS_GRAMMAR_AUTO = u"IsAutoGrammarCheck"; +inline constexpr OUStringLiteral UPN_IS_GRAMMAR_INTERACTIVE = u"IsInteractiveGrammarCheck"; + +// uno property handles +#define UPH_IS_GERMAN_PRE_REFORM 0 +#define UPH_IS_USE_DICTIONARY_LIST 1 +#define UPH_IS_IGNORE_CONTROL_CHARACTERS 2 +#define UPH_IS_SPELL_UPPER_CASE 3 +#define UPH_IS_SPELL_WITH_DIGITS 4 +#define UPH_IS_SPELL_CAPITALIZATION 5 +#define UPH_HYPH_MIN_LEADING 6 +#define UPH_HYPH_MIN_TRAILING 7 +#define UPH_HYPH_MIN_WORD_LENGTH 8 +#define UPH_DEFAULT_LOCALE 9 +#define UPH_IS_SPELL_AUTO 10 +#define UPH_IS_SPELL_HIDE 11 +#define UPH_IS_SPELL_IN_ALL_LANGUAGES 12 +#define UPH_IS_SPELL_SPECIAL 13 +#define UPH_IS_HYPH_AUTO 14 +#define UPH_IS_HYPH_SPECIAL 15 +#define UPH_IS_WRAP_REVERSE 16 +#define UPH_DATA_FILES_CHANGED_CHECK_VALUE 17 +#define UPH_DEFAULT_LANGUAGE 21 +#define UPH_DEFAULT_LOCALE_CJK 22 +#define UPH_DEFAULT_LOCALE_CTL 23 +#define UPH_ACTIVE_DICTIONARIES 24 +#define UPH_ACTIVE_CONVERSION_DICTIONARIES 25 +#define UPH_IS_IGNORE_POST_POSITIONAL_WORD 26 +#define UPH_IS_AUTO_CLOSE_DIALOG 27 +#define UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST 28 +#define UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES 29 +#define UPH_IS_DIRECTION_TO_SIMPLIFIED 30 +#define UPH_IS_USE_CHARACTER_VARIANTS 31 +#define UPH_IS_TRANSLATE_COMMON_TERMS 32 +#define UPH_IS_REVERSE_MAPPING 33 +#define UPH_IS_GRAMMAR_AUTO 34 +#define UPH_IS_GRAMMAR_INTERACTIVE 35 +#define UPH_HYPH_NO_CAPS 36 +#define UPH_HYPH_NO_LAST_WORD 37 +#define UPH_HYPH_ZONE 38 + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/localedatawrapper.hxx b/include/unotools/localedatawrapper.hxx new file mode 100644 index 000000000..5fbdcd078 --- /dev/null +++ b/include/unotools/localedatawrapper.hxx @@ -0,0 +1,394 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_LOCALEDATAWRAPPER_HXX +#define INCLUDED_UNOTOOLS_LOCALEDATAWRAPPER_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/i18n/LocaleItem.hpp> +#include <com/sun/star/i18n/LocaleDataItem2.hpp> +#include <com/sun/star/i18n/LanguageCountryInfo.hpp> +#include <com/sun/star/i18n/ForbiddenCharacters.hpp> +#include <com/sun/star/i18n/reservedWords.hpp> +#include <rtl/ustring.hxx> +#include <rtl/math.h> +#include <i18nlangtag/languagetag.hxx> +#include <unotools/unotoolsdllapi.h> +#include <memory> +#include <string_view> + +namespace com::sun::star::uno { class XComponentContext; } +namespace com::sun::star::i18n { class XLocaleData5; } +namespace com::sun::star::i18n { struct Calendar2; } +namespace com::sun::star::i18n { struct Currency2; } +namespace com::sun::star::i18n { struct FormatElement; } +namespace com::sun::star::i18n { struct CalendarItem2; } + +class Date; +namespace tools { class Time; } +class CalendarWrapper; + +enum class DateOrder { + Invalid = -1, + MDY = 0, + DMY, + YMD, +}; + +enum class LongDateOrder { + Invalid = -1, + MDY = 0, + DMY, + YMD, + YDM +}; + +enum class MeasurementSystem { + Metric, + US +}; + +/** + * This class can be accessed without locking because we load + * all of the data in the constructor. + */ +class UNOTOOLS_DLLPUBLIC LocaleDataWrapper +{ + static sal_uInt8 nLocaleDataChecking; // 0:=dontknow, 1:=yes, 2:=no + + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::i18n::XLocaleData5 > xLD; + LanguageTag maLanguageTag; + std::shared_ptr< css::i18n::Calendar2 > xDefaultCalendar; + std::shared_ptr< css::i18n::Calendar2 > xSecondaryCalendar; + css::i18n::LocaleDataItem2 aLocaleDataItem; + css::uno::Sequence< OUString > aDateAcceptancePatterns; + css::uno::Sequence< sal_Int32 > aGrouping; + // cached items + OUString aLocaleItem[css::i18n::LocaleItem::COUNT2]; + std::vector<OUString> aReservedWords; + OUString aCurrSymbol; + OUString aCurrBankSymbol; + DateOrder nDateOrder; + LongDateOrder nLongDateOrder; + sal_uInt16 nCurrPositiveFormat; + sal_uInt16 nCurrNegativeFormat; + sal_uInt16 nCurrDigits; + + void loadData(); + void loadDateAcceptancePatterns(const std::vector<OUString> & rOverrideDateAcceptancePatterns); + + const OUString& getOneLocaleItem( sal_Int16 nItem ) const; + + const OUString& getOneReservedWord( sal_Int16 nWord ) const; + + void loadCurrencyFormats(); + + void scanCurrFormatImpl( std::u16string_view rCode, + sal_Int32 nStart, sal_Int32& nSign, + sal_Int32& nPar, sal_Int32& nNum, + sal_Int32& nBlank, sal_Int32& nSym ) const; + + void loadDateOrders(); + LongDateOrder scanDateOrderImpl( std::u16string_view rCode ) const; + + void ImplAddFormatNum( rtl::OUStringBuffer& rBuf, + sal_Int64 nNumber, sal_uInt16 nDecimals, + bool bUseThousandSep, bool bTrailingZeros ) const; + + void loadDigitGrouping(); + +public: + LocaleDataWrapper( + const css::uno::Reference< css::uno::XComponentContext > & rxContext, + LanguageTag aLanguageTag + ); + /** + @param rOverrideDateAcceptancePatterns Override locale's date acceptance patterns. + An empty sequence resets the patterns to the locale's pattern sequence. + */ + LocaleDataWrapper( + LanguageTag aLanguageTag, + const std::vector<OUString> & rOverrideDateAcceptancePatterns = {} + ); + ~LocaleDataWrapper(); + + /** Get the service factory, meant to be able to create a CalendarWrapper + from a LocaleDataWrapper. Note that the service factory may be + non-existent if this LocaleDataWrapper was created without one and + lives "on the grassland". The CalendarWrapper ctor can handle that + though. */ + const css::uno::Reference< + css::uno::XComponentContext > & getComponentContext() + const { return m_xContext; } + + /// get current requested Locale + const LanguageTag& getLanguageTag() const; + + /// get current loaded Locale, which might differ from the requested Locale + LanguageTag getLoadedLanguageTag() const; + + // Wrapper implementations of service LocaleData + + css::i18n::LanguageCountryInfo getLanguageCountryInfo() const; + /// NOTE: this wraps XLocaleData5::getLocaleItem2() in fact. + const css::i18n::LocaleDataItem2& getLocaleItem() const; + /// NOTE: this wraps XLocaleData3::getAllCalendars2() in fact. + css::uno::Sequence< css::i18n::Calendar2 > getAllCalendars() const; + /// NOTE: this wraps XLocaleData2::getAllCurrencies2() in fact. + css::uno::Sequence< css::i18n::Currency2 > getAllCurrencies() const; + css::uno::Sequence< css::i18n::FormatElement > getAllFormats() const; + css::i18n::ForbiddenCharacters getForbiddenCharacters() const; + const css::uno::Sequence< css::lang::Locale > & getAllInstalledLocaleNames() const; + const css::uno::Sequence< OUString > & getDateAcceptancePatterns() const; + + + /// same as the wrapper implementation but static + static const css::uno::Sequence< css::lang::Locale > & getInstalledLocaleNames(); + + /** Get LanguageTypes for all installed locales which are unambiguous + convertible back and forth between locale ISO strings and MS-LCID + LanguageType. Upon the first time the function is called when + locale data checking is enabled, messages are shown for locales not + matching, excluding already known problems. + (e.g. used in number formatter dialog init) + */ + static const std::vector< LanguageType > & getInstalledLanguageTypes(); + + /// maps the LocaleData string to the International enum + MeasurementSystem mapMeasurementStringToEnum( std::u16string_view rMS ) const; + + /// Convenience method to obtain the default calendar. + const std::shared_ptr< css::i18n::Calendar2 >& getDefaultCalendar() const; + + /// Convenience method to obtain the day names of the default calendar. + css::uno::Sequence< css::i18n::CalendarItem2 > const & getDefaultCalendarDays() const; + + /// Convenience method to obtain the month names of the default calendar. + css::uno::Sequence< css::i18n::CalendarItem2 > const & getDefaultCalendarMonths() const; + + /** If the secondary calendar, if any, is of the name passed AND number + formats using it usually use the E or EE keyword (EC|EEC). */ + bool doesSecondaryCalendarUseEC( std::u16string_view rName ) const; + + /** Obtain digit grouping. The usually known grouping by thousands (#,###) + is actually only one of possible groupings. Another one, for example, + used in India is group by 3 and then by 2 indefinitely (#,##,###). The + integer sequence returned here specifies grouping from right to left + (!), with a 0 entry designating the end of rules and the previous value + to be repeated indefinitely. Hence the sequence {3,0} specifies the + usual grouping by thousands, whereas the sequence {3,2,0} specifies + Indian grouping. The sal_Int32* getConstArray() can be passed directly + to the ::rtl::math::doubleToString() methods as argument for the + pGroups parameter. */ + const css::uno::Sequence< sal_Int32 >& getDigitGrouping() const; + + // Functionality of class International methods, LocaleItem + + const OUString& getDateSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::DATE_SEPARATOR ); } + const OUString& getNumThousandSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::THOUSAND_SEPARATOR ); } + const OUString& getNumDecimalSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::DECIMAL_SEPARATOR ); } + const OUString& getNumDecimalSepAlt() const + { return getOneLocaleItem( css::i18n::LocaleItem::DECIMAL_SEPARATOR_ALTERNATIVE ); } + const OUString& getTimeSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::TIME_SEPARATOR ); } + const OUString& getTime100SecSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::TIME_100SEC_SEPARATOR ); } + const OUString& getListSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::LIST_SEPARATOR ); } + const OUString& getQuotationMarkStart() const + { return getOneLocaleItem( css::i18n::LocaleItem::SINGLE_QUOTATION_START ); } + const OUString& getQuotationMarkEnd() const + { return getOneLocaleItem( css::i18n::LocaleItem::SINGLE_QUOTATION_END ); } + const OUString& getDoubleQuotationMarkStart() const + { return getOneLocaleItem( css::i18n::LocaleItem::DOUBLE_QUOTATION_START ); } + const OUString& getDoubleQuotationMarkEnd() const + { return getOneLocaleItem( css::i18n::LocaleItem::DOUBLE_QUOTATION_END ); } + MeasurementSystem getMeasurementSystemEnum() const + { return mapMeasurementStringToEnum( getOneLocaleItem( css::i18n::LocaleItem::MEASUREMENT_SYSTEM ) ); } + const OUString& getTimeAM() const + { return getOneLocaleItem( css::i18n::LocaleItem::TIME_AM ); } + const OUString& getTimePM() const + { return getOneLocaleItem( css::i18n::LocaleItem::TIME_PM ); } + const OUString& getLongDateDayOfWeekSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::LONG_DATE_DAY_OF_WEEK_SEPARATOR ); } + const OUString& getLongDateDaySep() const + { return getOneLocaleItem( css::i18n::LocaleItem::LONG_DATE_DAY_SEPARATOR ); } + const OUString& getLongDateMonthSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::LONG_DATE_MONTH_SEPARATOR ); } + const OUString& getLongDateYearSep() const + { return getOneLocaleItem( css::i18n::LocaleItem::LONG_DATE_YEAR_SEPARATOR ); } + + /** A wrapper around rtl::math::stringToDouble() using the locale dependent + decimal separator, group separator, and if needed decimal separator + alternative. + + The decimal separator is tried first, if the conversion does not match + the entire string then the decimal separator alternative is tried if it + occurs in the string and was the reason to stop. + + Leading blanks are skipped, trailing blanks are not skipped. The number + is parsed up to the first non-floating point number character, same as + rtl::math::stringToDouble() does. The caller is responsible for proper + error checking and end comparison. + + @param aString + The string to parse as floating point number. + @param bUseGroupSep + Whether group separator is used/accepted during parsing. + @param pStatus + Pointer to receive the conversion status as in + rtl::math::stringToDouble(). + @param pParseEnd + Pointer to receive the parse end (exclusive) as in + rtl::math::stringToDouble(). + @return The floating point number as parsed. + */ + double stringToDouble( std::u16string_view aString, bool bUseGroupSep, + rtl_math_ConversionStatus* pStatus, sal_Int32* pParseEnd ) const; + + /** A wrapper around rtl_math_uStringToDouble() using the locale dependent + decimal separator, group separator, and if needed decimal separator + alternative. + + The decimal separator is tried first, if the conversion does not match + the entire string then the decimal separator alternative is tried if it + occurs in the string and was the reason to stop. + + Leading blanks are skipped, trailing blanks are not skipped. The number + is parsed up to the first non-floating point number character, same as + rtl_math_uStringToDouble() does. The caller is responsible for proper + error checking and end comparison. + + @param pBegin + The string position to start parsing a floating point number. + @param pEnd + The string position to stop parsing, exclusive. + @param bUseGroupSep + Whether group separator is used/accepted during parsing. + @param pStatus + Pointer to receive the conversion status as in + rtl_math_uStringToDouble(). + @param pParseEnd + Pointer to receive the parse end (exclusive) as in + rtl_math_uStringToDouble(). + @return The floating point number as parsed. + */ + double stringToDouble( const sal_Unicode* pBegin, const sal_Unicode* pEnd, bool bUseGroupSep, + rtl_math_ConversionStatus* pStatus, const sal_Unicode** ppParseEnd ) const; + + // currency + const OUString& getCurrSymbol() const; + const OUString& getCurrBankSymbol() const; + sal_uInt16 getCurrPositiveFormat() const; + sal_uInt16 getCurrNegativeFormat() const; + sal_uInt16 getCurrDigits() const; + + // simple date and time formatting + DateOrder getDateOrder() const; + LongDateOrder getLongDateOrder() const; + /// only numerical values of Gregorian calendar + OUString getDate( const Date& rDate ) const; + OUString getTime( const tools::Time& rTime, bool bSec = true, + bool b100Sec = false ) const; + OUString getDuration( const tools::Time& rTime, + bool bSec = true, bool b100Sec = false ) const; + + /** Simple number formatting + @param nNumber + value * 10**nDecimals + @param bTrailingZeros + </sal_True> := always display trailing zeros in + decimal places, even if integer value. + </sal_False> := trailing zeros are only displayed + if the value is not an integer value. + */ + OUString getNum( sal_Int64 nNumber, sal_uInt16 nDecimals, + bool bUseThousandSep = true, + bool bTrailingZeros = true ) const; + + /// "Secure" currency formatted string. + OUString getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals, + std::u16string_view rCurrencySymbol, + bool bUseThousandSep = true ) const; + + // dummy returns, to be implemented + sal_Unicode getCurrZeroChar() const + { return '0'; } + static bool isNumLeadingZero() + { return true; } + /// standard decimal places + static sal_uInt16 getNumDigits() + { return 2; } + static bool isNumTrailingZeros() + { return true; } + + // reserved words + + const OUString& getTrueWord() const + { return getOneReservedWord( css::i18n::reservedWords::TRUE_WORD ); } + const OUString& getFalseWord() const + { return getOneReservedWord( css::i18n::reservedWords::FALSE_WORD ); } + const OUString& getAboveWord() const + { return getOneReservedWord( css::i18n::reservedWords::ABOVE_WORD ); } + const OUString& getBelowWord() const + { return getOneReservedWord( css::i18n::reservedWords::BELOW_WORD ); } + /// return a quarter abbreviation string matching nQuarter (0..3) => "Q1" .. "Q2" + const OUString& getQuarterAbbreviation( sal_Int16 nQuarter ) const + { return getOneReservedWord( css::i18n::reservedWords::QUARTER1_ABBREVIATION + nQuarter ); } + + /** Return whether locale data checks are enabled. + Checks are enabled if the environment variable + OOO_ENABLE_LOCALE_DATA_CHECKS is set to 'Y' or 'Yes' (or any other + string starting with 'Y') or '1'. + Also used in conjunction with the number formatter. */ + static bool areChecksEnabled() + { + if (nLocaleDataChecking == 0) + evaluateLocaleDataChecking(); + return nLocaleDataChecking == 1; + } + + /** Append locale info to string, used with locale data checking. + A string similar to "de_DE requested\n en_US loaded" is appended. */ + OUString appendLocaleInfo(std::u16string_view rDebugMsg) const; + + /** Output a message during locale data checking. The (UTF-8) string is + written to stderr and in a non-product build or if DBG_UTIL is enabled + also raised as an assertion message box. */ + static void outputCheckMessage( std::u16string_view rMsg ); + static void outputCheckMessage( const char* pStr); + + LocaleDataWrapper(const LocaleDataWrapper&) = delete; + LocaleDataWrapper& operator=(const LocaleDataWrapper&) = delete; + +private: + + const css::lang::Locale & getMyLocale() const; + + static void evaluateLocaleDataChecking(); +}; + +#endif // INCLUDED_UNOTOOLS_LOCALEDATAWRAPPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/localfilehelper.hxx b/include/unotools/localfilehelper.hxx new file mode 100644 index 000000000..e96b5a571 --- /dev/null +++ b/include/unotools/localfilehelper.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_LOCALFILEHELPER_HXX +#define INCLUDED_UNOTOOLS_LOCALFILEHELPER_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include <unotools/unotoolsdllapi.h> + +#include <rtl/ustring.hxx> + +namespace utl +{ + class UNOTOOLS_DLLPUBLIC LocalFileHelper + { + public: + static css::uno::Sequence< OUString > + GetFolderContents( const OUString& rFolder, bool bFolder ); + }; + + /// recursively remove directory and all contents + UNOTOOLS_DLLPUBLIC void removeTree(OUString const & url); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/mediadescriptor.hxx b/include/unotools/mediadescriptor.hxx new file mode 100644 index 000000000..92728fa51 --- /dev/null +++ b/include/unotools/mediadescriptor.hxx @@ -0,0 +1,339 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_MEDIADESCRIPTOR_HXX +#define INCLUDED_UNOTOOLS_MEDIADESCRIPTOR_HXX + +#include <sal/config.h> + +#include <vector> + +#include <comphelper/docpasswordrequest.hxx> +#include <comphelper/sequenceashashmap.hxx> +#include <rtl/ustring.hxx> +#include <unotools/unotoolsdllapi.h> + +namespace com::sun::star::io { + class XInputStream; +} +namespace comphelper { class IDocPasswordVerifier; } + +namespace utl { + +/** @short can be used to work with a css::document::MediaDescriptor + struct. + + @descr It wraps an unordered_map around the Sequence< css::beans::PropertyValue >, which + represent the MediaDescriptor item. + Further this helper defines often used functions (as e.g. open of the required streams, + consistent checks etcpp.) and it defines all usable property names. + + @attention This class isn't threadsafe and must be guarded from outside! + */ +class UNOTOOLS_DLLPUBLIC MediaDescriptor : public comphelper::SequenceAsHashMap +{ + public: + + /** @short these methods can be used to get the different property names + as static const OUString values. + + @descr Because definition and declaration of static const class members + does not work as expected under windows (under unix it works as well) + these way must be used :-( + */ + static constexpr OUStringLiteral PROP_ABORTED = u"Aborted"; + static constexpr OUStringLiteral PROP_ASTEMPLATE = u"AsTemplate"; + static constexpr OUStringLiteral PROP_COMPONENTDATA = u"ComponentData"; + static constexpr OUStringLiteral PROP_DOCUMENTSERVICE = u"DocumentService"; + static constexpr OUStringLiteral PROP_ENCRYPTIONDATA = u"EncryptionData"; + static constexpr OUStringLiteral PROP_FILENAME = u"FileName"; + static constexpr OUStringLiteral PROP_FILTERNAME = u"FilterName"; + static constexpr OUStringLiteral PROP_FILTERPROVIDER = u"FilterProvider"; + static constexpr OUStringLiteral PROP_FILTEROPTIONS = u"FilterOptions"; + static constexpr OUStringLiteral PROP_FRAME = u"Frame"; + static constexpr OUStringLiteral PROP_FRAMENAME = u"FrameName"; + static constexpr OUStringLiteral PROP_HIDDEN = u"Hidden"; + static constexpr OUStringLiteral PROP_INPUTSTREAM = u"InputStream"; + static constexpr OUStringLiteral PROP_INTERACTIONHANDLER = u"InteractionHandler"; + static constexpr OUStringLiteral PROP_AUTHENTICATIONHANDLER = u"AuthenticationHandler"; + static constexpr OUStringLiteral PROP_JUMPMARK = u"JumpMark"; + static constexpr OUStringLiteral PROP_MACROEXECUTIONMODE = u"MacroExecutionMode"; + static constexpr OUStringLiteral PROP_MEDIATYPE = u"MediaType"; + static constexpr OUStringLiteral PROP_MINIMIZED = u"Minimized"; + static constexpr OUStringLiteral PROP_NOAUTOSAVE = u"NoAutoSave"; + static constexpr OUStringLiteral PROP_OPENNEWVIEW = u"OpenNewView"; + static constexpr OUStringLiteral PROP_OUTPUTSTREAM = u"OutputStream"; + static constexpr OUStringLiteral PROP_PASSWORD = u"Password"; + static constexpr OUStringLiteral PROP_POSTDATA = u"PostData"; + static constexpr OUStringLiteral PROP_PREVIEW = u"Preview"; + static constexpr OUStringLiteral PROP_READONLY = u"ReadOnly"; + static constexpr OUStringLiteral PROP_REFERRER = u"Referer"; + static constexpr OUStringLiteral PROP_REPLACEABLE = u"Replaceable"; + static constexpr OUStringLiteral PROP_SALVAGEDFILE = u"SalvagedFile"; + static constexpr OUStringLiteral PROP_STATUSINDICATOR = u"StatusIndicator"; + static constexpr OUStringLiteral PROP_STREAM = u"Stream"; + static constexpr OUStringLiteral PROP_STREAMFOROUTPUT = u"StreamForOutput"; + static constexpr OUStringLiteral PROP_TEMPLATENAME = u"TemplateName"; + static constexpr OUStringLiteral PROP_TITLE = u"Title"; + static constexpr OUStringLiteral PROP_TYPENAME = u"TypeName"; + static constexpr OUStringLiteral PROP_UCBCONTENT = u"UCBContent"; + static constexpr OUStringLiteral PROP_UPDATEDOCMODE = u"UpdateDocMode"; + static constexpr OUStringLiteral PROP_URL = u"URL"; + static constexpr OUStringLiteral PROP_VERSION = u"Version"; + static constexpr OUStringLiteral PROP_DOCUMENTTITLE = u"DocumentTitle"; + static constexpr OUStringLiteral PROP_MODEL = u"Model"; + static constexpr OUStringLiteral PROP_VIEWONLY = u"ViewOnly"; + static constexpr OUStringLiteral PROP_DOCUMENTBASEURL = u"DocumentBaseURL"; + static constexpr OUStringLiteral PROP_SUGGESTEDSAVEASNAME = u"SuggestedSaveAsName"; + static constexpr OUStringLiteral PROP_AUTOSAVEEVENT = u"AutoSaveEvent"; + + // interface + public: + + /** @short these ctors do nothing - excepting that they forward + the given parameters to the base class ctors. + + @descr The ctors must be overwritten to resolve conflicts with + the default ctors of the compiler :-(. + */ + MediaDescriptor(); + MediaDescriptor(const css::uno::Sequence< css::beans::PropertyValue >& lSource); + + /** @short it checks if the descriptor already has a valid + InputStream item and creates a new one, if not. + + @descr This method uses the current items of this MediaDescriptor, + to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). + It creates a seekable stream and put it into the descriptor. + + A might existing InteractionHandler will be used automatically, + to solve problems! + + In case of local file the system file locking is used. + + @return TRUE, if the stream was already part of the descriptor or could + be created as new item. FALSE otherwise. + */ + bool addInputStream(); + + /** @short it checks if the descriptor already has a valid + InputStream item and creates a new one, if not. + + @descr This method uses the current items of this MediaDescriptor, + to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). + It creates a seekable stream and put it into the descriptor. + + A might existing InteractionHandler will be used automatically, + to solve problems! + + In case of local file the system file locking is used based on + configuration settings. + + @return TRUE, if the stream was already part of the descriptor or could + be created as new item. FALSE otherwise. + */ + bool addInputStreamOwnLock(); + + /** @short it checks if the descriptor describes a readonly stream. + + @descr The descriptor itself isn't changed doing so. + It's only checked if the stream seems to be based + of a real readonly file. + + @Attention + We don't check the property "ReadOnly" here. Because + this property can be set from outside and overwrites + the readonly state of the stream. + If e.g. the stream could be opened read/write ... + but "ReadOnly" property is set to TRUE, this means: + show a readonly UI on top of this read/write stream. + + @return TRUE, if the stream must be interpreted as readonly ... + FALSE otherwise. + */ + bool isStreamReadOnly() const; + + /** Returns a value from the sequence contained in the property + 'ComponentData' of this media descriptor. + + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. + + @return The value with the specified name, if existing in the + sequence of the 'ComponentData' property, otherwise an empty + Any. + */ + css::uno::Any getComponentDataEntry( + const OUString& rName ) const; + + /** Inserts a value into the sequence contained in the property + 'ComponentData' of the media descriptor. + + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. The passed value + will be inserted into the sequence, or, if already existing, + will be overwritten. + + @param rName The name of the value to be inserted into the + sequence of the 'ComponentData' property. + + @param rValue The value to be inserted into the sequence of the + 'ComponentData' property. + */ + void setComponentDataEntry( + const OUString& rName, + const css::uno::Any& rValue ); + + /** Removes a value from the sequence contained in the property + 'ComponentData' of the media descriptor. + + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. The value with + the passed name will be removed from the sequence, if existing. + + @param rName The name of the value to be removed from the sequence + of the 'ComponentData' property. + */ + void clearComponentDataEntry( + const OUString& rName ); + + /** This helper function tries to find a password for the document + described by this media descriptor. + + First, the list of default passwords will be tried if provided. This + is needed by import filters for external file formats that have to + check a predefined password in some cases without asking the user + for a password. Every password is checked using the passed password + verifier. + + If not successful, this media descriptor is asked for a password, + that has been set e.g. by an API call to load a document. If + existing, the password is checked using the passed password + verifier. + + If still not successful, the interaction handler contained in this + media descriptor is used to request a password from the user. This + will be repeated until the passed password verifier validates the + entered password, or if the user chooses to cancel password input. + + If a valid password (that is not contained in the passed list of + default passwords) was found, it will be inserted into the + "Password" property of this descriptor. + + @param rVerifier + The password verifier used to check every processed password. + + @param eRequestType + The password request type that will be passed to the + DocPasswordRequest object created internally. See + docpasswordrequest.hxx for more details. + + @param pDefaultPasswords + If not null, contains default passwords that will be tried before a + password will be requested from the media descriptor or the user. + + @return + If not empty, contains the password that has been validated by the + passed password verifier. If empty, no valid password has been + found, or the user has chosen to cancel password input. + */ + css::uno::Sequence< css::beans::NamedValue > requestAndVerifyDocPassword( + comphelper::IDocPasswordVerifier& rVerifier, + comphelper::DocPasswordRequestType eRequestType, + const ::std::vector< OUString >* pDefaultPasswords ); + + // helper + private: + + /** @short tries to open a stream by using the given PostData stream. + + @descr The stream is used directly ... + + The MediaDescriptor itself is changed inside this method. + Means: the stream is added internal and not returned by a value. + + @param _rxPostData + the PostData stream. + + @return TRUE if the stream could be added successfully. + Note: If FALSE is returned, the error was already handled inside! + + @throw [css::uno::RuntimeException] + if the MediaDescriptor seems to be invalid! + + @throw [css::lang::IllegalArgumentException] + if the given PostData stream is <NULL/>. + */ + SAL_DLLPRIVATE bool impl_openStreamWithPostData( + const css::uno::Reference< css::io::XInputStream >& _rxPostData + ); + + /** @short tries to open a stream by using the given URL. + + @descr First it tries to open the content in r/w mode (if its + allowed to do so). Only in case it's not allowed or it failed + the stream will be tried to open in readonly mode. + + The MediaDescriptor itself is changed inside this method. + Means: the stream is added internal and not returned by a value. + + @param sURL + the URL for open. + + @param bLockFile + specifies whether the file should be locked + + @return TRUE if the stream could be added successfully. + Note: If FALSE is returned, the error was already handled inside! + + @throw [css::uno::RuntimeException] + if the MediaDescriptor seems to be invalid! + */ + SAL_DLLPRIVATE bool impl_openStreamWithURL( + const OUString& sURL, + bool bLockFile + ); + + /** @short it checks if the descriptor already has a valid + InputStream item and creates a new one, if not. + + @descr This method uses the current items of this MediaDescriptor, + to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). + It creates a seekable stream and put it into the descriptor. + + A might existing InteractionHandler will be used automatically, + to solve problems! + + @param bLockFile + specifies whether the file should be locked + + @return TRUE, if the stream was already part of the descriptor or could + be created as new item. FALSE otherwise. + */ + SAL_DLLPRIVATE bool impl_addInputStream( bool bLockFile ); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/moduleoptions.hxx b/include/unotools/moduleoptions.hxx new file mode 100644 index 000000000..8aa9860ce --- /dev/null +++ b/include/unotools/moduleoptions.hxx @@ -0,0 +1,176 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_MODULEOPTIONS_HXX +#define INCLUDED_UNOTOOLS_MODULEOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/uno/Sequence.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <unotools/options.hxx> +#include <memory> + +namespace com::sun::star::frame { class XModel; } +namespace com::sun::star::beans { struct PropertyValue; } + +/*-************************************************************************************************************ + @short forward declaration to our private date container implementation + @descr We use these class as internal member to support small memory requirements. + You can create the container if it is necessary. The class which use these mechanism + is faster and smaller then a complete implementation! +*//*-*************************************************************************************************************/ +class SvtModuleOptions_Impl; + +/*-************************************************************************************************************ + @short collect information about installation state of modules + @descr Use these class to get installation state of different office modules like writer, calc etc + Further you can ask for additional information; e.g. name of standard template file, which + should be used by corresponding module; or short/long name of these module factory. + @devstatus ready to use + @threadsafe yes +*//*-*************************************************************************************************************/ +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtModuleOptions final : public utl::detail::Options +{ + public: + + enum class EModule + { + WRITER = 0, + CALC = 1, + DRAW = 2, + IMPRESS = 3, + MATH = 4, + CHART = 5, + STARTMODULE = 6, + BASIC = 7, + DATABASE = 8, + WEB = 9, + GLOBAL = 10 + }; + + /*ATTENTION: + If you change these enum ... don't forget to change reading/writing and order of configuration values too! + See "SvtModuleOptions_Impl::impl_GetSetNames()" and his ctor for further information. + */ + enum class EFactory + { + UNKNOWN_FACTORY = -1, + WRITER = 0, + WRITERWEB = 1, + WRITERGLOBAL = 2, + CALC = 3, + DRAW = 4, + IMPRESS = 5, + MATH = 6, + CHART = 7, + STARTMODULE = 8, + DATABASE = 9, + BASIC = 10, + LAST = BASIC + }; + + public: + SvtModuleOptions(); + virtual ~SvtModuleOptions() override; + + bool IsModuleInstalled ( EModule eModule ) const; + OUString GetModuleName ( EModule eModule ) const; + const OUString & GetFactoryName ( EFactory eFactory ) const; + OUString GetFactoryStandardTemplate( EFactory eFactory ) const; + OUString GetFactoryEmptyDocumentURL( EFactory eFactory ) const; + OUString GetFactoryDefaultFilter ( EFactory eFactory ) const; + bool IsDefaultFilterReadonly ( EFactory eFactory ) const; + sal_Int32 GetFactoryIcon ( EFactory eFactory ) const; + static bool ClassifyFactoryByName ( std::u16string_view sName , + EFactory& eFactory ); + void SetFactoryStandardTemplate( EFactory eFactory , + const OUString& sTemplate ); + void SetFactoryDefaultFilter ( EFactory eFactory , + const OUString& sFilter ); + + /** @short return the corresponding application ID for the given + document service name. + */ + static EFactory ClassifyFactoryByServiceName(std::u16string_view sName); + + /** @short return the corresponding application ID for the given + short name. + */ + static EFactory ClassifyFactoryByShortName(std::u16string_view sName); + + /** @short return the corresponding application ID for the given properties. + + @descr Because this search base on filters currently (till we have a better solution) + a result is not guaranteed every time. May a filter does not exists for the specified + content (but a FrameLoader which is not bound to any application!) ... or + the given properties describe a stream (and we make no deep detection inside here!). + + @attention The module BASIC can't be detected here. Because it does not + has an own URL schema. + + @param sURL + the complete URL! + + @param lMediaDescriptor + additional information + + @return A suitable enum value. See EFactory above. + */ + static EFactory ClassifyFactoryByURL(const OUString& sURL , + const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor); + + /** @short return the corresponding application ID for the given properties. + + @descr Here we try to use the list of supported service names of the given model + to find out the right application module. + + @attention The module BASIC can't be detected here. Because it does not + support any model/ctrl/view paradigm. + + @param xModel + the document model + + @return A suitable enum value. See EFactory above. + */ + static EFactory ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel >& xModel); + + static OUString GetFactoryShortName(EFactory eFactory); + + OUString GetDefaultModuleName() const; + + bool IsMath () const; + bool IsChart () const; + bool IsCalc () const; + bool IsDraw () const; + bool IsWriter () const; + bool IsImpress () const; + static bool IsBasicIDE () { return true; } + bool IsDataBase () const; + + css::uno::Sequence < OUString > GetAllServiceNames(); + + private: + std::shared_ptr<SvtModuleOptions_Impl> m_pImpl; + +}; // class SvtModuleOptions + +#endif // INCLUDED_UNOTOOLS_MODULEOPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/nativenumberwrapper.hxx b/include/unotools/nativenumberwrapper.hxx new file mode 100644 index 000000000..9f632f1f6 --- /dev/null +++ b/include/unotools/nativenumberwrapper.hxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_NATIVENUMBERWRAPPER_HXX +#define INCLUDED_UNOTOOLS_NATIVENUMBERWRAPPER_HXX + +#include <config_options.h> +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/i18n/NativeNumberXmlAttributes.hpp> +#include <com/sun/star/uno/Reference.hxx> + +namespace com::sun::star::uno { class XComponentContext; } +namespace com::sun::star::i18n { class XNativeNumberSupplier2; } + +class UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) NativeNumberWrapper +{ + css::uno::Reference< css::i18n::XNativeNumberSupplier2 > xNNS; + NativeNumberWrapper( const NativeNumberWrapper& ) = delete; + NativeNumberWrapper& operator=( const NativeNumberWrapper& ) = delete; + +public: + NativeNumberWrapper( + const css::uno::Reference< css::uno::XComponentContext > & rxContext + ); + + ~NativeNumberWrapper(); + + // Wrapper implementations of XNativeNumberSupplier + + OUString getNativeNumberString( + const OUString& rNumberString, + const css::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode) const; + + OUString getNativeNumberStringParams( + const OUString& rNumberString, + const css::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode, + const OUString& rNativeNumberParams) const; + + css::i18n::NativeNumberXmlAttributes convertToXmlAttributes( + const css::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode ) const; + + sal_Int16 convertFromXmlAttributes( + const css::i18n::NativeNumberXmlAttributes& rAttr ) const; + +}; + +#endif // INCLUDED_UNOTOOLS_NATIVENUMBERWRAPPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/options.hxx b/include/unotools/options.hxx new file mode 100644 index 000000000..4e0206ace --- /dev/null +++ b/include/unotools/options.hxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_OPTIONS_HXX +#define INCLUDED_UNOTOOLS_OPTIONS_HXX + +#include <sal/config.h> +#include <unotools/unotoolsdllapi.h> +#include <o3tl/typed_flags_set.hxx> +#include <vector> +#include <memory> + +// bits for broadcasting hints of changes in ConfigurationListener::ConfigurationChanged, may be combined +enum class ConfigurationHints { + NONE = 0x0000, + Locale = 0x0001, + Currency = 0x0002, + UiLocale = 0x0004, + DecSep = 0x0008, + DatePatterns = 0x0010, + IgnoreLang = 0x0020, + CtlSettingsChanged = 0x2000, +}; +namespace o3tl { + template<> struct typed_flags<ConfigurationHints> : is_typed_flags<ConfigurationHints, 0x203f> {}; +} + +/* + The class utl::detail::Options provides a kind of multiplexer. It implements a ConfigurationListener + that is usually registered at a ConfigItem class. At the same time it implements a ConfigurationBroadcaster + that allows further ("external") listeners to register. + Once the class deriving from Options is notified about + configuration changes by the ConfigItem if its content has been changed by calling some of its methods, + a call of the Options::NotifyListeners() method will send out notifications to all external listeners. +*/ + +namespace utl { + + class ConfigurationBroadcaster; + + // interface for configuration listener + class UNOTOOLS_DLLPUBLIC ConfigurationListener + { + public: + virtual ~ConfigurationListener(); + + virtual void ConfigurationChanged( ConfigurationBroadcaster* p, ConfigurationHints nHint ) = 0; + }; + typedef ::std::vector< ConfigurationListener* > IMPL_ConfigurationListenerList; + + // complete broadcasting implementation + class UNOTOOLS_DLLPUBLIC ConfigurationBroadcaster + { + std::unique_ptr<IMPL_ConfigurationListenerList> mpList; + sal_Int32 m_nBroadcastBlocked; // broadcast only if this is 0 + ConfigurationHints m_nBlockedHint; + + public: + void AddListener( utl::ConfigurationListener* pListener ); + void RemoveListener( utl::ConfigurationListener const * pListener ); + + // notify listeners; nHint is an implementation detail of the particular class deriving from ConfigurationBroadcaster + void NotifyListeners( ConfigurationHints nHint ); + ConfigurationBroadcaster(); + ConfigurationBroadcaster(ConfigurationBroadcaster const & ); + virtual ~ConfigurationBroadcaster(); + ConfigurationBroadcaster & operator =(ConfigurationBroadcaster const & other); + virtual void BlockBroadcasts( bool bBlock ); + }; + +namespace detail { + +// A base class for the various option classes supported by +// unotools/source/config/itemholderbase.hxx (which must be public, as it is +// shared between unotools, svl and svt) +// It also provides an implementation for a Configuration Listener and inherits a broadcaster implementation + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC Options + : public utl::ConfigurationBroadcaster, public utl::ConfigurationListener +{ +public: + Options(); + + virtual ~Options() override = 0; + +private: + Options(Options const &) = delete; + Options& operator =(Options const &) = delete; + +protected: + virtual void ConfigurationChanged( ::utl::ConfigurationBroadcaster* p, ConfigurationHints nHint ) override; +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/optionsdlg.hxx b/include/unotools/optionsdlg.hxx new file mode 100644 index 000000000..4e0d78245 --- /dev/null +++ b/include/unotools/optionsdlg.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <unordered_map> +#include <string_view> + +// Loads the dialog options from config +class UNOTOOLS_DLLPUBLIC SvtOptionsDialogOptions +{ +public: + + typedef std::unordered_map< OUString, bool > OptionNodeList; + + SvtOptionsDialogOptions(); + + bool IsGroupHidden ( std::u16string_view _rGroup ) const; + bool IsPageHidden ( std::u16string_view _rPage, + std::u16string_view _rGroup ) const; + bool IsOptionHidden ( std::u16string_view _rOption, + std::u16string_view _rPage, + std::u16string_view _rGroup ) const; +private: + bool IsHidden( const OUString& _rPath ) const; + + OptionNodeList m_aOptionNodeList; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/pathoptions.hxx b/include/unotools/pathoptions.hxx new file mode 100644 index 000000000..6388a54bc --- /dev/null +++ b/include/unotools/pathoptions.hxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_PATHOPTIONS_HXX +#define INCLUDED_UNOTOOLS_PATHOPTIONS_HXX + +#include <rtl/ustring.hxx> +#include <unotools/unotoolsdllapi.h> +#include <unotools/options.hxx> + +#define SVT_SEARCHPATH_DELIMITER ';' + +class SvtPathOptions_Impl; + +/*! Handle various defined paths + + All path functions return URLs! +*/ +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtPathOptions final : public utl::detail::Options +{ +private: + std::shared_ptr<SvtPathOptions_Impl> pImpl; + +public: + + enum class Paths : sal_uInt16 + { + AddIn, + AutoCorrect, + AutoText, + Backup, + Basic, + Bitmap, + Config, + Dictionary, + Favorites, + Filter, + Gallery, + Graphic, + Help, + IconSet, + Linguistic, + Module, + Palette, + Plugin, + Storage, + Temp, + Template, + UserConfig, + Work, + Classification, + UIConfig, + Fingerprint, + NumberText, + LAST // should always be the last element + }; + + + SvtPathOptions(); + virtual ~SvtPathOptions() override; + + // get the paths, not const because of using a mutex + const OUString& GetAddinPath() const; + const OUString& GetAutoCorrectPath() const; + const OUString& GetAutoTextPath() const; + const OUString& GetBackupPath() const; + const OUString& GetBasicPath() const; + const OUString& GetBitmapPath() const; + const OUString& GetConfigPath() const; + const OUString& GetDictionaryPath() const; + const OUString& GetFavoritesPath() const; + const OUString& GetFilterPath() const; + const OUString& GetGalleryPath() const; + const OUString& GetGraphicPath() const; + const OUString& GetHelpPath() const; + const OUString& GetLinguisticPath() const; + const OUString& GetModulePath() const; + const OUString& GetIconsetPath() const; + const OUString& GetPalettePath() const; + const OUString& GetPluginPath() const; + const OUString& GetStoragePath() const; + const OUString& GetTempPath() const; + const OUString& GetTemplatePath() const; + const OUString& GetUserConfigPath() const; + const OUString& GetWorkPath() const; + const OUString& GetFingerprintPath() const; + const OUString& GetNumbertextPath() const; + const OUString& GetClassificationPath() const; + + // set the paths + void SetAddinPath( const OUString& rPath ); + void SetAutoCorrectPath( const OUString& rPath ); + void SetAutoTextPath( const OUString& rPath ); + void SetBackupPath( const OUString& rPath ); + void SetBasicPath( const OUString& rPath ); + void SetBitmapPath( const OUString& rPath ); + void SetConfigPath( const OUString& rPath ); + void SetDictionaryPath( const OUString& rPath ); + void SetFavoritesPath( const OUString& rPath ); + void SetFilterPath( const OUString& rPath ); + void SetGalleryPath( const OUString& rPath ); + void SetGraphicPath( const OUString& rPath ); + void SetHelpPath( const OUString& rPath ); + void SetLinguisticPath( const OUString& rPath ); + void SetModulePath( const OUString& rPath ); + void SetPalettePath( const OUString& rPath ); + void SetPluginPath( const OUString& rPath ); + void SetStoragePath( const OUString& rPath ); + void SetTempPath( const OUString& rPath ); + void SetTemplatePath( const OUString& rPath ); + void SetUserConfigPath( const OUString& rPath ); + void SetWorkPath( const OUString& rPath ); + + OUString SubstituteVariable( const OUString& rVar ) const; + OUString ExpandMacros( const OUString& rPath ) const; + OUString UseVariable( const OUString& rVar ) const; + bool SearchFile( OUString& rIniFile, Paths ePath = Paths::UserConfig ); +}; + +#endif // INCLUDED_UNOTOOLS_PATHOPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/progresshandlerwrap.hxx b/include/unotools/progresshandlerwrap.hxx new file mode 100644 index 000000000..4fcfd36da --- /dev/null +++ b/include/unotools/progresshandlerwrap.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_PROGRESSHANDLERWRAP_HXX +#define INCLUDED_UNOTOOLS_PROGRESSHANDLERWRAP_HXX + +#include <config_options.h> +#include <unotools/unotoolsdllapi.h> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/ucb/XProgressHandler.hpp> + +namespace com::sun::star::task +{ +class XStatusIndicator; +} + +namespace utl +{ +class UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) ProgressHandlerWrap final + : public ::cppu::WeakImplHelper<css::ucb::XProgressHandler> +{ + css::uno::Reference<css::task::XStatusIndicator> m_xStatusIndicator; + +public: + ProgressHandlerWrap(css::uno::Reference<css::task::XStatusIndicator> xSI); + + // XProgressHandler + virtual void SAL_CALL push(const css::uno::Any& Status) override; + virtual void SAL_CALL update(const css::uno::Any& Status) override; + virtual void SAL_CALL pop() override; +}; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_PROGRESSHANDLERWRAP_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/resmgr.hxx b/include/unotools/resmgr.hxx new file mode 100644 index 000000000..142ec2de5 --- /dev/null +++ b/include/unotools/resmgr.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_RESMGR_HXX +#define INCLUDED_UNOTOOLS_RESMGR_HXX + +#include <unotools/unotoolsdllapi.h> +#include <unotools/syslocale.hxx> +#include <rtl/ustring.hxx> +#include <string_view> + +class LanguageTag; + +typedef OUString (*ResHookProc)(const OUString& rStr); + +struct UNOTOOLS_DLLPUBLIC TranslateId +{ + const char* mpContext; + const char* mpId; + + inline constexpr TranslateId() + : mpContext(nullptr), mpId(nullptr) {} + inline constexpr TranslateId(const char* pContext, const char* pId) + : mpContext(pContext), mpId(pId) {} + + inline operator bool() const { return mpId != nullptr; } + + bool operator==(const TranslateId& other) const; + inline bool operator!=(const TranslateId& other) const { return !operator==(other); } +}; + +struct UNOTOOLS_DLLPUBLIC TranslateNId +{ + const char* mpContext; + const char* mpSingular; + const char* mpPlural; + + inline TranslateNId() + : mpContext(nullptr), mpSingular(nullptr), mpPlural(nullptr) {} + inline TranslateNId(const char* pContext, const char* pSingular, const char* pPlural) + : mpContext(pContext), mpSingular(pSingular), mpPlural(pPlural) {} + + inline operator bool() const { return mpContext != nullptr; } + + bool operator==(const TranslateNId& other) const; + inline bool operator!=(const TranslateNId& other) const { return !operator==(other); } +}; + +namespace Translate +{ + UNOTOOLS_DLLPUBLIC std::locale Create(std::string_view aPrefixName, const LanguageTag& rLocale = SvtSysLocale().GetUILanguageTag()); + UNOTOOLS_DLLPUBLIC OUString get(TranslateId sContextAndId, const std::locale &loc); + UNOTOOLS_DLLPUBLIC OUString nget(TranslateNId aContextSingularPlural, int n, const std::locale &loc); + UNOTOOLS_DLLPUBLIC void SetReadStringHook( ResHookProc pProc ); + UNOTOOLS_DLLPUBLIC ResHookProc GetReadStringHook(); + UNOTOOLS_DLLPUBLIC OUString ExpandVariables(const OUString& rString); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/saveopt.hxx b/include/unotools/saveopt.hxx new file mode 100644 index 000000000..9cd636761 --- /dev/null +++ b/include/unotools/saveopt.hxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_SAVEOPT_HXX +#define INCLUDED_UNOTOOLS_SAVEOPT_HXX + +#include <unotools/unotoolsdllapi.h> +#include <memory> + +namespace comphelper { class ConfigurationChanges; } + +namespace SvtSaveOptions +{ + /** Keep enum values sorted that a less or greater compare maps to older + and newer versions. + Do not change values, they are stored in the configuration. + ODFVER_LATEST designates the "current greatest and latest". + When adding a new value or ODFVER_LATEST designates a new real version + (plus extensions) adjust the mapping in + SvtSaveOptions::GetODFSaneDefaultVersion(). + */ + enum ODFDefaultVersion + { + ODFVER_UNKNOWN = 0, // unknown - very dubious, avoid using + ODFVER_010 = 1, // ODF 1.0 + ODFVER_011 = 2, // ODF 1.1 + DO_NOT_USE = 3, // Do not use this, only here for compatibility with pre OOo 3.2 configuration + ODFVER_012 = 4, // ODF 1.2 + ODFVER_012_EXT_COMPAT = 8, // ODF 1.2 extended, but with compatibility fallbacks + ODFVER_012_EXTENDED = 9, // ODF 1.2 extended + ODFVER_013 = 10, // ODF 1.3 + + ODFVER_LATEST = SAL_MAX_ENUM, // ODF latest version with enhancements + }; + + /// Enums that allow a sane comparison of versions, without LATEST. + enum ODFSaneDefaultVersion + { + ODFSVER_EXTENDED = 1, ///< bit designating extensions are allowed + ODFSVER_010 = 2, ///< ODF 1.0 + ODFSVER_011 = 4, ///< ODF 1.1 + ODFSVER_012 = 6, ///< ODF 1.2 + ODFSVER_012_EXT_COMPAT = 9, ///< ODF 1.2 extended, but with compatibility fallbacks + ODFSVER_012_EXTENDED = 11, ///< ODF 1.2 extended + ODFSVER_013 = 12, ///< ODF 1.3 + ODFSVER_013_EXTENDED = 13, ///< ODF 1.3 extended + ODFSVER_FUTURE_EXTENDED = 1000 | ODFSVER_EXTENDED, ///< current extension, unknown future ODF version + + // The latest defined standard. Adapt when a new one is published. + ODFSVER_LATEST = ODFSVER_013, ///< @internal DO NOT USE in comparisons + ODFSVER_LATEST_EXTENDED = ODFSVER_013_EXTENDED ///< @internal DO NOT USE in comparisons + }; + +}; + +UNOTOOLS_DLLPUBLIC void SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion ); +UNOTOOLS_DLLPUBLIC void SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion, const std::shared_ptr<comphelper::ConfigurationChanges>& ); + +UNOTOOLS_DLLPUBLIC SvtSaveOptions::ODFDefaultVersion GetODFDefaultVersion(); +UNOTOOLS_DLLPUBLIC SvtSaveOptions::ODFSaneDefaultVersion GetODFSaneDefaultVersion(); + +/** gets a sane default from the currently configured default */ +UNOTOOLS_DLLPUBLIC SvtSaveOptions::ODFSaneDefaultVersion GetODFSaneDefaultVersion(SvtSaveOptions::ODFDefaultVersion eDefaultVersion); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/searchopt.hxx b/include/unotools/searchopt.hxx new file mode 100644 index 000000000..6b4321909 --- /dev/null +++ b/include/unotools/searchopt.hxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_SEARCHOPT_HXX +#define INCLUDED_UNOTOOLS_SEARCHOPT_HXX + +#include <unotools/unotoolsdllapi.h> +#include <memory> + +class SvtSearchOptions_Impl; +enum class TransliterationFlags; + +class UNOTOOLS_DLLPUBLIC SvtSearchOptions +{ + std::unique_ptr<SvtSearchOptions_Impl> pImpl; + + SvtSearchOptions( const SvtSearchOptions & ) = delete; + SvtSearchOptions & operator = ( const SvtSearchOptions & ) = delete; + +public: + SvtSearchOptions(); + ~SvtSearchOptions(); + + void Commit(); + + TransliterationFlags GetTransliterationFlags() const; + + // General Options + + bool IsWholeWordsOnly() const; + bool IsBackwards() const; + bool IsUseRegularExpression() const; + bool IsUseWildcard() const; + bool IsSimilaritySearch() const; + bool IsUseAsianOptions() const; + bool IsMatchCase() const; // also Japanese search option + bool IsSearchFormatted() const; + bool IsNotes() const; + + void SetWholeWordsOnly( bool bVal ); + void SetBackwards( bool bVal ); + void SetUseRegularExpression( bool bVal ); + void SetUseWildcard( bool bVal ); + void SetSearchForStyles( bool bVal ); + void SetSimilaritySearch( bool bVal ); + void SetUseAsianOptions( bool bVal ); + void SetMatchCase( bool bVal ); // also Japanese search option + void SetSearchFormatted( bool bVal ); + void SetNotes( bool bVal); + + // Japanese search options + + bool IsMatchFullHalfWidthForms() const; + bool IsMatchHiraganaKatakana() const; + bool IsMatchContractions() const; + bool IsMatchMinusDashChoon() const; + bool IsMatchRepeatCharMarks() const; + bool IsMatchVariantFormKanji() const; + bool IsMatchOldKanaForms() const; + bool IsMatchDiziDuzu() const; + bool IsMatchBavaHafa() const; + bool IsMatchTsithichiDhizi() const; + bool IsMatchHyuiyuByuvyu() const; + bool IsMatchSesheZeje() const; + bool IsMatchIaiya() const; + bool IsMatchKiku() const; + bool IsIgnorePunctuation() const; + bool IsIgnoreWhitespace() const; + bool IsIgnoreProlongedSoundMark() const; + bool IsIgnoreMiddleDot() const; + bool IsIgnoreDiacritics_CTL() const; + bool IsIgnoreKashida_CTL() const; + + void SetMatchFullHalfWidthForms( bool bVal ); + void SetMatchHiraganaKatakana( bool bVal ); + void SetMatchContractions( bool bVal ); + void SetMatchMinusDashChoon( bool bVal ); + void SetMatchRepeatCharMarks( bool bVal ); + void SetMatchVariantFormKanji( bool bVal ); + void SetMatchOldKanaForms( bool bVal ); + void SetMatchDiziDuzu( bool bVal ); + void SetMatchBavaHafa( bool bVal ); + void SetMatchTsithichiDhizi( bool bVal ); + void SetMatchHyuiyuByuvyu( bool bVal ); + void SetMatchSesheZeje( bool bVal ); + void SetMatchIaiya( bool bVal ); + void SetMatchKiku( bool bVal ); + void SetIgnorePunctuation( bool bVal ); + void SetIgnoreWhitespace( bool bVal ); + void SetIgnoreProlongedSoundMark( bool bVal ); + void SetIgnoreMiddleDot( bool bVal ); + void SetIgnoreDiacritics_CTL( bool bVal ); + void SetIgnoreKashida_CTL( bool bVal ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/securityoptions.hxx b/include/unotools/securityoptions.hxx new file mode 100644 index 000000000..0cae239c1 --- /dev/null +++ b/include/unotools/securityoptions.hxx @@ -0,0 +1,157 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <vector> +#include <unordered_map> + +/*-************************************************************************************************************ + @short collect information about security features + @ATTENTION This class is partially threadsafe. + + @devstatus ready to use +*//*-*************************************************************************************************************/ + +namespace SvtSecurityOptions +{ + enum class EOption + { + SecureUrls, + DocWarnSaveOrSend, + DocWarnSigning, + DocWarnPrint, + DocWarnCreatePdf, + DocWarnRemovePersonalInfo, + DocWarnRecommendPassword, + MacroSecLevel, + MacroTrustedAuthors, + CtrlClickHyperlink, + BlockUntrustedRefererLinks + }; + + struct Certificate + { + OUString SubjectName; + OUString SerialNumber; + OUString RawData; + + bool operator==(const Certificate& other) const + { + return SubjectName == other.SubjectName && SerialNumber == other.SerialNumber && RawData == other.RawData; + } + }; + + + /*-**************************************************************************************************** + @short returns readonly state + @descr It can be called to get information about the readonly state of a provided item. + @param "eOption", specify, which item is queried + @return <TRUE/> if item is readonly; <FALSE/> otherwise + + @onerror No error should occur! + *//*-*****************************************************************************************************/ + + UNOTOOLS_DLLPUBLIC bool IsReadOnly( EOption eOption ); + + /*-**************************************************************************************************** + @short interface methods to get and set value of config key "org.openoffice.Office.Common/Security/Scripting/SecureURL" + @descr These value displays the list of all trustworthy URLs. + zB.: file:/ => All scripts from the local file system including a LAN; + private:explorer => Scripts from the Explorer; + private:help => Scripts in the help system; + private:newmenu => Scripts that are executed by the commands File-New and AutoPilot; + private:schedule => Scripts of the scheduler; + private:searchfolder => Scripts of the searchfolder; + private:user => Scripts that are entered in the URL field. + @param "seqURLList", new values to set it in configuration. + @return The values which represent current state of internal variable. + + @onerror No error should occur! + *//*-*****************************************************************************************************/ + + UNOTOOLS_DLLPUBLIC std::vector< OUString > GetSecureURLs(); + UNOTOOLS_DLLPUBLIC void SetSecureURLs( std::vector< OUString >&& seqURLList ); + + /*-**************************************************************************************************** + @short interface methods to get and set value of config key "org.openoffice.Office.Common/Security/Scripting/StarOfficeBasic" + @descr These value determines how StarOffice Basic scripts should be handled. + It exist 3 different modes: + 0 = never execute + 1 = from list + 2 = always execute + + @ATTENTION These methods don't check for valid or invalid values! + Our configuration server can do it ... but these implementation don't get any notifications + about wrong commits ...! + => If you set an invalid value - nothing will be changed. The information will lost. + + @seealso enum EBasicSecurityMode + + @param "eMode" to set new mode ... Value must defined as an enum of type EBasicSecurityMode! + @return An enum value, which present current mode. + + @onerror No error should occur! + *//*-*****************************************************************************************************/ + + UNOTOOLS_DLLPUBLIC sal_Int32 GetMacroSecurityLevel(); + UNOTOOLS_DLLPUBLIC void SetMacroSecurityLevel( sal_Int32 _nLevel ); + + UNOTOOLS_DLLPUBLIC bool IsMacroDisabled(); + + /** + Check whether the given uri is either no dangerous macro-execution + URI at all or else the given referer is a trusted source. + */ + UNOTOOLS_DLLPUBLIC bool isSecureMacroUri(OUString const & uri, OUString const & referer); + + /** + Check whether the given referer URI is untrusted, and links + originating from it should not be accessed. + */ + UNOTOOLS_DLLPUBLIC bool isUntrustedReferer(OUString const & referer); + + /** + Check whether the given uri is a trusted location. + */ + UNOTOOLS_DLLPUBLIC bool isTrustedLocationUri(OUString const & uri); + + UNOTOOLS_DLLPUBLIC bool isTrustedLocationUriForUpdatingLinks(OUString const & uri); + + UNOTOOLS_DLLPUBLIC std::vector< Certificate > GetTrustedAuthors(); + UNOTOOLS_DLLPUBLIC void SetTrustedAuthors( const std::vector< Certificate >& rAuthors ); + + // for bool options only! + UNOTOOLS_DLLPUBLIC bool IsOptionSet ( EOption eOption ); + UNOTOOLS_DLLPUBLIC void SetOption ( EOption eOption, bool bValue ); + +} // namespace SvtSecurityOptions + +// map personal info strings, e.g. authors to 1, 2, 3... for removing personal info + +class UNOTOOLS_DLLPUBLIC SvtSecurityMapPersonalInfo +{ + std::unordered_map< OUString, size_t > aInfoIDs; +public: + size_t GetInfoID( const OUString sPersonalInfo ); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/sharedunocomponent.hxx b/include/unotools/sharedunocomponent.hxx new file mode 100644 index 000000000..8acc64b1f --- /dev/null +++ b/include/unotools/sharedunocomponent.hxx @@ -0,0 +1,269 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_SHAREDUNOCOMPONENT_HXX +#define INCLUDED_UNOTOOLS_SHAREDUNOCOMPONENT_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/uno/Reference.hxx> +#include <rtl/ref.hxx> +#include <memory> + +namespace com::sun::star { + namespace lang { + class XComponent; + } +} + +namespace utl +{ + + //= DisposableComponent + + /** is a class which controls lifetime of a UNO component via ->XComponent::dispose + + You'll usually never use this class directly, but only as parameter for a + ->SharedUNOComponent class. + */ + class UNOTOOLS_DLLPUBLIC DisposableComponent + { + css::uno::Reference< css::lang::XComponent > m_xComponent; + + public: + /** constructs a ->DisposableComponent instance + + @param _rxComponent + the component whose life time should be controlled by the instance. Must not be <NULL/>. + */ + DisposableComponent( const css::uno::Reference< css::uno::XInterface >& _rxComponent ); + + /** disposes the component represented by the instance + + The component is queried for ->XComponent(which <em>must</em> be supported), + and ->XComponent::dispose is invoked. A failure of this invocation (e.g. a thrown + exception) is silenced in release builds, and reported in debug builds. + */ + ~DisposableComponent(); + + private: + DisposableComponent( const DisposableComponent& ) = delete; + DisposableComponent& operator=( const DisposableComponent& ) = delete; + }; + + //= CloseableComponent + + class CloseableComponentImpl; + /** is a class which controls lifetime of a UNO component via ->XCloseable::close + + You'll usually never use this class directly, but only as parameter for a + ->SharedUNOComponent class. + */ + class UNOTOOLS_DLLPUBLIC CloseableComponent + { + private: + /** Our IMPL class. + */ + ::rtl::Reference< CloseableComponentImpl > m_pImpl; + + public: + /** constructs a ->CloseableComponent instance + + @param _rxComponent + the component whose life time should be controlled by the instance. Must not be <NULL/>. + */ + CloseableComponent( const css::uno::Reference< css::uno::XInterface >& _rxComponent ); + + /** destroys resources associated with this instance, and disposes the component + + The component is queried for ->XCloseable (which <em>must</em> be supported), + and ->XCloseable::close is invoked, with delivering the ownership. + If the invocation fails with a ->CloseVetoException, this is ignored, since in + this case the vetoing instance took the ownership. + + Any other failure will be reported in a debug version via assertion mechanisms, + and silenced in release builds. + */ + ~CloseableComponent(); + + private: + CloseableComponent( const CloseableComponent& ) = delete; + CloseableComponent& operator=( const CloseableComponent& ) = delete; + }; + + //= SharedUNOComponent + + /** is a helper class for sharing ownership of a UNO component + + If you need to share a UNO component, which normally needs a dedicated owner, + and is lifetime controlled by an explicit disposal action (not necessarily ->XComponent::dispose, + but <em>any</em> explicit method call, after which the object is considered + to be disposed), between different classes, ->SharedUNOComponent is what you need. + + Instead of passing around a <code>Reference< XFoo ></code>, and bothering + with ownership and disposal, you just use a <code>SharedUNOComponent< XFoo ></code>. + This instance can be passed around, including copying, and in nearly all respects behaves + like the original <code>Reference< XFoo ></code>. However, when the last + ->SharedUNOComponent referencing a certain <code>Reference< XFoo ></code> dies, it + will automatically get rid of the object held by this reference. + + @param INTERFACE + the UNO interface type as which the component should be held + + @param COMPONENT_HOLDER + a class which can be used to represent and dispose a UNO component. + The class must support (maybe explicit only) construction from a + <code>Reference< INTERFACE ></code>, and destruction. Upon destruction, + the class must dispose (by any suitable means) the component instance it was + constructed with. + */ + template < class INTERFACE, class COMPONENT = DisposableComponent > + class SharedUNOComponent + { + private: + typedef COMPONENT Component; + + private: + std::shared_ptr<Component> m_xComponent; + css::uno::Reference< INTERFACE > m_xTypedComponent; + + public: + enum AssignmentMode + { + TakeOwnership, + NoTakeOwnership + }; + + public: + SharedUNOComponent() + { + } + + explicit SharedUNOComponent( const css::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode eMode = TakeOwnership ) + { + reset( _rxComponent, eMode ); + } + + SharedUNOComponent( const css::uno::BaseReference & _rRef, css::uno::UnoReference_QueryThrow _queryThrow ) + { + set( _rRef, _queryThrow ); + } + +// SharedUNOComponent& operator=( const css::uno::Reference< INTERFACE >& _rxComponent ); + // This operator is intentionally not implemented. There is no canonic ownership after this operator + // would have been applied: Should the SharedUNOComponent have the ownership of the component, + // or shouldn't it? Hard to guess, and probably wrong in 50 percent of all cases, anyway. So, + // instead of tempting clients of this class to use such a dangerous operator, we do + // not offer it at all. If you need to assign a Reference< INTERFACE > to your SharedUNOComponent, + // use the ->reset method. + + /** assigns a new component, and releases the old one + */ + void reset( const css::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode _eMode = TakeOwnership ); + + inline bool set( const css::uno::BaseReference& _rRef, css::uno::UnoReference_Query _query ); + + inline void set( const css::uno::BaseReference & _rRef, css::uno::UnoReference_QueryThrow _queryThrow ); + + inline void set( const css::uno::Reference< INTERFACE >& _rRef, css::uno::UnoReference_SetThrow _setThrow ); + inline void set( const SharedUNOComponent& _rComp, css::uno::UnoReference_SetThrow _setThrow ); + + INTERFACE* SAL_CALL operator->() const; + + operator const css::uno::Reference< INTERFACE >&() const + { + return m_xTypedComponent; + } + + const css::uno::Reference< INTERFACE >& getTyped() const + { + return m_xTypedComponent; + } + + bool is() const + { + return m_xTypedComponent.is(); + } + + void clear() + { + m_xComponent.reset(); + m_xTypedComponent.clear(); + } + }; + + template < class INTERFACE, class COMPONENT > + INTERFACE* SAL_CALL SharedUNOComponent< INTERFACE, COMPONENT >::operator->() const + { + return m_xTypedComponent.operator->(); + } + + // assignments + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::reset( const css::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode _eMode ) + { + m_xComponent.reset(_eMode == TakeOwnership ? new COMPONENT( _rxComponent ) : nullptr); + m_xTypedComponent = _rxComponent; + } + + // comparison operators + + template < class INTERFACE, class COMPONENT > + bool operator==( const SharedUNOComponent< INTERFACE, COMPONENT >& _rLHS, const css::uno::Reference< INTERFACE >& _rRHS ) + { + return _rLHS.getTyped() == _rRHS; + } + + template < class INTERFACE, class COMPONENT > + inline css::uno::Any SAL_CALL makeAny( const SharedUNOComponent< INTERFACE, COMPONENT >& value ) + { + return css::uno::Any( value.getTyped() ); + } + + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const css::uno::BaseReference & _rRef, css::uno::UnoReference_QueryThrow _queryThrow ) + { + reset( css::uno::Reference< INTERFACE >( _rRef, _queryThrow ), TakeOwnership ); + } + + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const css::uno::Reference< INTERFACE >& _rRef, css::uno::UnoReference_SetThrow _setThrow ) + { + reset( css::uno::Reference< INTERFACE >( _rRef, _setThrow ), TakeOwnership ); + } + + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const SharedUNOComponent& _rComp, css::uno::UnoReference_SetThrow _setThrow ) + { + *this = _rComp; + // provoke an exception in case the component is NULL + m_xTypedComponent.set( m_xTypedComponent, _setThrow ); + } + + template < class INTERFACE, class COMPONENT > + bool SharedUNOComponent< INTERFACE, COMPONENT >::set( const css::uno::BaseReference& _rRef, css::uno::UnoReference_Query _query ) + { + reset( css::uno::Reference< INTERFACE >( _rRef, _query ) ); + return is(); + } + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_SHAREDUNOCOMPONENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/streamhelper.hxx b/include/unotools/streamhelper.hxx new file mode 100644 index 000000000..a727869bf --- /dev/null +++ b/include/unotools/streamhelper.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_STREAMHELPER_HXX +#define INCLUDED_UNOTOOLS_STREAMHELPER_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <cppuhelper/implbase.hxx> +#include <tools/stream.hxx> +#include <mutex> +#include <utility> + +namespace utl +{ + +/** + * The helper implementation for a using input streams based on SvLockBytes. + */ +class UNOTOOLS_DLLPUBLIC OInputStreamHelper final : public cppu::WeakImplHelper<css::io::XInputStream, css::io::XSeekable> +{ + std::mutex m_aMutex; + SvLockBytesRef m_xLockBytes; + sal_uInt64 m_nActPos; + sal_Int32 m_nAvailable; // this is typically the chunk(buffer) size + +public: + OInputStreamHelper(SvLockBytesRef _xLockBytes, + sal_uInt32 _nAvailable) + :m_xLockBytes(std::move(_xLockBytes)) + ,m_nActPos(0) + ,m_nAvailable(_nAvailable){} + +// css::io::XInputStream + virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) override; + virtual sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) override; + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) override; + virtual sal_Int32 SAL_CALL available( ) override; + virtual void SAL_CALL closeInput( ) override; + + virtual void SAL_CALL seek( sal_Int64 location ) override; + virtual sal_Int64 SAL_CALL getPosition( ) override; + virtual sal_Int64 SAL_CALL getLength( ) override; + + // workaround for Ubuntu 18.04 / Fedora 31 (Coverity VM) build with std::mutex; must not be inline! + virtual void SAL_CALL acquire() SAL_NOEXCEPT override; +}; + +} // namespace utl + +#endif // _UNOTOOLS_STREAM_WRAPPER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/streamwrap.hxx b/include/unotools/streamwrap.hxx new file mode 100644 index 000000000..dc4c51807 --- /dev/null +++ b/include/unotools/streamwrap.hxx @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_STREAMWRAP_HXX +#define INCLUDED_UNOTOOLS_STREAMWRAP_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <comphelper/bytereader.hxx> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/implbase1.hxx> +#include <memory> +#include <mutex> + +class SvStream; + +namespace utl +{ + +// workaround for incremental linking bugs in MSVC2015 +class SAL_DLLPUBLIC_TEMPLATE OInputStreamWrapper_Base : public cppu::WeakImplHelper< css::io::XInputStream, css::lang::XUnoTunnel > {}; + +/// helper class for wrapping an SvStream into a com.sun.star.io::XInputStream +class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public OInputStreamWrapper_Base, public comphelper::ByteReader +{ +protected: + std::mutex m_aMutex; + SvStream* m_pSvStream; + bool m_bSvStreamOwner : 1; + OInputStreamWrapper() + { m_pSvStream = nullptr; m_bSvStreamOwner = false; } + void SetStream(SvStream* _pStream, bool bOwner ) + { m_pSvStream = _pStream; m_bSvStreamOwner = bOwner; } + +public: + OInputStreamWrapper(SvStream& _rStream); + OInputStreamWrapper(SvStream* pStream, bool bOwner=false); + OInputStreamWrapper(std::unique_ptr<SvStream> pStream); + virtual ~OInputStreamWrapper() override; + +// css::io::XInputStream + virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) override; + virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) override; + virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override; + virtual sal_Int32 SAL_CALL available() override; + virtual void SAL_CALL closeInput() override; + +// css::lang::XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& _rIdentifier ) override; + +// utl::ByteReader + virtual sal_Int32 readSomeBytes( sal_Int8* aData, sal_Int32 nMaxBytesToRead ) final override; + +protected: + /// throws a NotConnectedException if the object is not connected anymore + void checkConnected() const; + /// throws an exception according to the error flag of m_pSvStream + void checkError() const; +}; + +//= OSeekableInputStreamWrapper + +/** helper class for wrapping an SvStream into a com.sun.star.io::XInputStream + which is seekable (i.e. supports the com.sun.star.io::XSeekable interface). +*/ +class UNOTOOLS_DLLPUBLIC OSeekableInputStreamWrapper + : public cppu::ImplInheritanceHelper< OInputStreamWrapper, css::io::XSeekable > +{ +protected: + OSeekableInputStreamWrapper() {} + ~OSeekableInputStreamWrapper() override; + +public: + OSeekableInputStreamWrapper(SvStream& _rStream); + OSeekableInputStreamWrapper(SvStream* _pStream, bool _bOwner = false); + + // XSeekable + virtual void SAL_CALL seek( sal_Int64 _nLocation ) override; + virtual sal_Int64 SAL_CALL getPosition( ) override; + virtual sal_Int64 SAL_CALL getLength( ) override; +}; + +//= OOutputStreamWrapper + +class OOutputStreamWrapper : public cppu::WeakImplHelper<css::io::XOutputStream> +{ +public: + UNOTOOLS_DLLPUBLIC OOutputStreamWrapper(SvStream& _rStream); + +protected: + virtual ~OOutputStreamWrapper() override; + +// css::io::XOutputStream + virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) override; + virtual void SAL_CALL flush() override; + virtual void SAL_CALL closeOutput() override; + + /// throws an exception according to the error flag of m_pSvStream + void checkError() const; + + // TODO: thread safety! + SvStream& rStream; +}; + +//= OSeekableOutputStreamWrapper + +typedef ::cppu::ImplHelper1 < css::io::XSeekable + > OSeekableOutputStreamWrapper_Base; +/** helper class for wrapping an SvStream into a com.sun.star.io::XOutputStream + which is seekable (i.e. supports the com.sun.star.io::XSeekable interface). +*/ +class UNOTOOLS_DLLPUBLIC OSeekableOutputStreamWrapper final + :public OOutputStreamWrapper + ,public OSeekableOutputStreamWrapper_Base +{ +public: + OSeekableOutputStreamWrapper(SvStream& _rStream); + +private: + virtual ~OSeekableOutputStreamWrapper() override; + + // disambiguate XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) override; + virtual void SAL_CALL acquire( ) noexcept override + { OOutputStreamWrapper::acquire(); } + virtual void SAL_CALL release( ) noexcept override + { OOutputStreamWrapper::release(); } + + // XSeekable + virtual void SAL_CALL seek( sal_Int64 _nLocation ) override; + virtual sal_Int64 SAL_CALL getPosition( ) override; + virtual sal_Int64 SAL_CALL getLength( ) override; +}; + +class UNOTOOLS_DLLPUBLIC OStreamWrapper final + : public cppu::ImplInheritanceHelper<OSeekableInputStreamWrapper, + css::io::XStream, + css::io::XOutputStream, + css::io::XTruncate> +{ + ~OStreamWrapper() override; + +public: + OStreamWrapper(SvStream& _rStream); + OStreamWrapper(std::unique_ptr<SvStream> _rStream); + +// css::io::XStream + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override; + virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream( ) override; + +// css::io::XOutputStream + virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) override; + virtual void SAL_CALL flush() override; + virtual void SAL_CALL closeOutput() override; + virtual void SAL_CALL truncate() override; +}; + +} +// namespace utl + +#endif // INCLUDED_UNOTOOLS_STREAMWRAP_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/syslocale.hxx b/include/unotools/syslocale.hxx new file mode 100644 index 000000000..e5bc9dd85 --- /dev/null +++ b/include/unotools/syslocale.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_SYSLOCALE_HXX +#define INCLUDED_UNOTOOLS_SYSLOCALE_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/textenc.h> + +#include <memory> + +class CharClass; +class LanguageTag; +class LocaleDataWrapper; +class SvtSysLocale_Impl; +class SvtSysLocaleOptions; + +/** + SvtSysLocale provides a refcounted single instance of an application wide + LocaleDataWrapper and <type>CharClass</type> which always + follow the locale as it is currently configured by the user. You may use + it anywhere to access the locale data elements like decimal separator and + simple date formatting and so on. Constructing and destructing a + SvtSysLocale is not expensive as long as there is at least one instance + left. + */ +class UNOTOOLS_DLLPUBLIC SvtSysLocale +{ + friend class SvtSysLocale_Impl; // access to mutex + + std::shared_ptr<SvtSysLocale_Impl> pImpl; + +public: + SvtSysLocale(); + ~SvtSysLocale(); + + const LocaleDataWrapper& GetLocaleData() const; + const CharClass& GetCharClass() const; + + /** It is safe to store the pointers locally and use them AS LONG AS THE + INSTANCE OF SvtSysLocale LIVES! + It is a faster access but be sure what you do! + */ + SvtSysLocaleOptions& GetOptions() const; + const LanguageTag& GetLanguageTag() const; + const LanguageTag& GetUILanguageTag() const; + + /** Get the best MIME encoding matching the system locale, or if that isn't + determinable one that matches the UI locale, or UTF8 if everything else + fails. + */ + static rtl_TextEncoding GetBestMimeEncoding(); +}; + +#endif // INCLUDED_SVTOOLS_SYSLOCALE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/syslocaleoptions.hxx b/include/unotools/syslocaleoptions.hxx new file mode 100644 index 000000000..5f5e57540 --- /dev/null +++ b/include/unotools/syslocaleoptions.hxx @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_SYSLOCALEOPTIONS_HXX +#define INCLUDED_UNOTOOLS_SYSLOCALEOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <i18nlangtag/lang.h> +#include <i18nlangtag/languagetag.hxx> +#include <unotools/options.hxx> + +class SvtSysLocaleOptions_Impl; +class LinkParamNone; +template <typename Arg, typename Ret> class Link; + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtSysLocaleOptions final : public utl::detail::Options +{ + std::shared_ptr<SvtSysLocaleOptions_Impl> pImpl; + + virtual void ConfigurationChanged( utl::ConfigurationBroadcaster* p, ConfigurationHints nHint ) override; + +public: + + enum class EOption + { + Locale, + Currency, + DatePatterns + }; + SvtSysLocaleOptions(); + virtual ~SvtSysLocaleOptions() override; + + // ConfigItem methods + + bool IsModified() const; + void Commit(); + + /** Add a listener to react on config changes + which are broadcasted in a SfxSimpleHint + @return + <TRUE/> if added + <FALSE/> if not added + */ + + /** Block broadcasts and accumulate hints. This may be useful if, for + example, the locale and currency are changed and the currency was + empty before, since changing the locale with an empty currency does + also broadcast a change hint for the currency which would result in + two currency changes broadcasted. + + @param bBlock + <TRUE/>: broadcasts are blocked until reversed. + <FALSE/>: broadcasts are not blocked anymore. Pending hints are + broadcasted if no other instance blocks the broadcast. + + @ATTENTION + All SvtSysLocaleOptions instances point to exactly one refcounted + internal representation instance and broadcast blocks are counted. + Thus if you issue a BlockBroadcasts(true) you MUST issue a matching + BlockBroadcasts(false) or otherwise pending hints would never be + broadcasted again. + */ + virtual void BlockBroadcasts( bool bBlock ) override; + + // config value access methods + + /// The config string may be empty to denote the SYSTEM locale + void SetLocaleConfigString( const OUString& rStr ); + /** Get locale set, not resolved to the real locale. */ + LanguageTag GetLanguageTag() const; + /** Get locale set, always resolved to the real locale. */ + const LanguageTag& GetRealLanguageTag() const; + + /// The config string may be empty to denote the SYSTEM locale + void SetUILocaleConfigString( const OUString& rStr ); + /** Get UI locale set, always resolved to the real locale. */ + const LanguageTag& GetRealUILanguageTag() const; + + /// The config string may be empty to denote the default currency of the locale + const OUString& GetCurrencyConfigString() const; + void SetCurrencyConfigString( const OUString& rStr ); + + /** The config string may be empty to denote the default + DateAcceptancePatterns of the locale */ + const OUString& GetDatePatternsConfigString() const; + void SetDatePatternsConfigString( const OUString& rStr ); + + // determine whether the decimal separator defined in the keyboard layout is used + // or the one appropriate to the locale + bool IsDecimalSeparatorAsLocale() const; + void SetDecimalSeparatorAsLocale( bool bSet); + + // determine whether to ignore changes to the system keyboard/locale/language when + // determining the language for newly entered text + bool IsIgnoreLanguageChange() const; + void SetIgnoreLanguageChange( bool bSet); + + // convenience methods + + /// Get currency abbreviation and locale from an USD-en-US or EUR-de-DE string + static void GetCurrencyAbbrevAndLanguage( + OUString& rAbbrev, + LanguageType& eLang, + const OUString& rConfigString ); + + /// Create an USD-en-US or EUR-de-DE string + static OUString CreateCurrencyConfigString( + const OUString& rAbbrev, + LanguageType eLang ); + + void GetCurrencyAbbrevAndLanguage( + OUString& rAbbrev, + LanguageType& eLang ) const + { + GetCurrencyAbbrevAndLanguage( rAbbrev, + eLang, GetCurrencyConfigString() ); + } + + /** Set a link to a method to be called whenever the default currency + changes. This can be only one method, and normally it is the static + link method which calls SvNumberFormatter::SetDefaultSystemCurrency(). + This is needed because the number formatter isn't part of the svl light + library, otherwise we could call SetDefaultSystemCurrency() directly. + */ + static void SetCurrencyChangeLink( const Link<LinkParamNone*,void>& rLink ); + static const Link<LinkParamNone*,void>& GetCurrencyChangeLink(); + + /** return the readonly state of the queried option. */ + bool IsReadOnly( EOption eOption ) const; +}; + +#endif // INCLUDED_UNOTOOLS_SYSLOCALEOPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/tempfile.hxx b/include/unotools/tempfile.hxx new file mode 100644 index 000000000..b7f691abb --- /dev/null +++ b/include/unotools/tempfile.hxx @@ -0,0 +1,145 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_TEMPFILE_HXX +#define INCLUDED_UNOTOOLS_TEMPFILE_HXX + +#include <unotools/unotoolsdllapi.h> +#include <tools/stream.hxx> +#include <memory> + +namespace utl +{ + +/** + The class TempFile gives access to temporary files in the local file system. Sometimes they are needed because a 3rd party + code has a file name based interface, or some file access has to be done locally without transferring tons of bytes to or + from a remote system. + Creating a UCB content on a TempFile is only possible if a UCP for the local file system is present. + TempFiles can always be accessed by SvFileStreams or Sot/SvStorages using the "physical" file name ( not the URL, because + this may be a non-file URL, see below ), but if a UCB content can be created, it is also possible to take the URL and use + the UCB helper classes for streams. For convenience use UcbStreamHelper. + A Tempfile always has a "physical" file name ( a file name in the local computers host notation ) but it has a + "UCB compatible" URL only if a UCP for the local file system exists. This URL may have its own URL scheme + ( not necessarily "file://" ! ). The TempFile class methods take this into account, but other simple conversions like + the osl functions do not. + So it is a potential error to convert between the filename and the URL of a TempFile object using functions or methods + outside this class. +*/ + +class UNOTOOLS_DLLPUBLIC TempFile +{ + OUString aName; + std::unique_ptr<SvStream> + pStream; + bool bIsDirectory; + bool bKillingFileEnabled; + +public: + /** + Create a temporary file or directory, in the default tempfile folder or if possible in a given folder. + This given folder ( the "parent" parameter ( if not NULL ) ) must be a "UCB compatible" URL. + The temporary object is created in the local file system, even if there is no UCB that can access it. + If the given folder is part of the local file system, the TempFile is created in this folder. + */ + TempFile( const OUString* pParent=nullptr, bool bDirectory=false ); + + /** + Same as above; additionally the name starts with some given characters followed by a counter ( example: + rLeadingChars="abc" means "abc0","abc1" and so on, depending on existing files in the folder ). + The extension string may be f.e. ".txt" or "", if no extension string is given, ".tmp" is used + @param _bStartWithZero If set to false names will be generated like "abc","abc0","abc1" + @param bCreateParentDirs If rLeadingChars contains a slash, this will create the required + parent directories. + */ + TempFile( std::u16string_view rLeadingChars, bool _bStartWithZero=true, const OUString* pExtension=nullptr, + const OUString* pParent=nullptr, bool bCreateParentDirs=false ); + + TempFile(TempFile && other) noexcept; + + /** + TempFile will be removed from disk in dtor if EnableKillingFile(true) was called before. + Temporary directories will be removed recursively in that case. + */ + ~TempFile(); + + /** + Returns sal_True if it has a valid file name. + */ + bool IsValid() const; + + /** + Returns the URL of the tempfile object. + If you want to have the system path file name, use the GetFileName() method of this object + */ + OUString const & GetURL() const; + + /** + Returns the system path name of the tempfile in host notation + If you want to have the URL, use the GetURL() method of this object. + */ + OUString GetFileName() const; + + /** + Returns a stream to the tempfiles data; the stream is owned by the tempfile object, so you have to keep this + alive as long as you want to use the stream. If the TempFile object is destroyed, it also destroys the + stream object, the underlying file is only deleted if EnableKillingFile(true) has been called before! + */ + SvStream* GetStream( StreamMode eMode ); + + /** + Let the TempFile object close and destroy the owned stream object if any. + */ + void CloseStream(); + + /** + If enabled the file will be removed from disk when the dtor is called ( default is not enabled ) + */ + void EnableKillingFile( bool bEnable=true ) + { bKillingFileEnabled = bEnable; } + + /** + Only create a "physical" file name for a temporary file that would be valid at that moment. + Should only be used for 3rd party code with a file name interface that wants to create the file by itself. + If you want to convert file name into a URL, always use class LocalFileHelper, but never use any + conversion functions of osl. + */ + static OUString CreateTempName(); + + /** + The TempNameBaseDirectory is a subfolder in the folder that is passed as a "physical" file name in the + SetTempNameBaseDirectory method. + This subfolder will be used if a TempFile or TempName is created without a parent name or a parent name + that does not belong to the local file system. + The caller of the SetTempNameBase is responsible for deleting this folder and all temporary files in it. + The return value of both methods is the complete "physical" name of the tempname base folder. + It is not a URL because all URLs must be "UCB compatible", so there may be no suitable URL at all. + */ + static OUString SetTempNameBaseDirectory( const OUString &rBaseName ); + + // Return the URL of the temp directory (the one set with SetTempNameBaseDirectory or the + // default tempfile folder): + static OUString GetTempNameBaseDirectory(); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/textsearch.hxx b/include/unotools/textsearch.hxx new file mode 100644 index 000000000..140200fec --- /dev/null +++ b/include/unotools/textsearch.hxx @@ -0,0 +1,225 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_TEXTSEARCH_HXX +#define INCLUDED_UNOTOOLS_TEXTSEARCH_HXX + +#include <unotools/unotoolsdllapi.h> +#include <i18nlangtag/lang.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Reference.h> + +#include <ostream> + +class CharClass; + +namespace com::sun::star::lang { struct Locale; } +namespace com::sun::star::util { class XTextSearch2; } +namespace com::sun::star::util { struct SearchResult; } +namespace i18nutil { + struct SearchOptions; + struct SearchOptions2; +} +enum class TransliterationFlags; + +namespace utl +{ + +// Utility class for searching +class UNOTOOLS_DLLPUBLIC SearchParam +{ +public: + enum class SearchType { Normal, Regexp, Wildcard, Unknown = -1 }; + + /** Convert configuration and document boolean settings to SearchType. + If bWildcard is true it takes precedence over rbRegExp. + @param rbRegExp + If true and bWildcard is also true, rbRegExp is set to false to + adapt the caller's settings. + */ + static SearchType ConvertToSearchType( bool bWildcard, bool & rbRegExp ) + { + if (bWildcard) + { + if (rbRegExp) + rbRegExp = false; + return SearchType::Wildcard; + } + return rbRegExp ? SearchType::Regexp : SearchType::Normal; + } + + /** Convert SearchType to configuration and document boolean settings. + */ + static void ConvertToBool( const SearchType eSearchType, bool& rbWildcard, bool& rbRegExp ) + { + switch (eSearchType) + { + case SearchType::Wildcard: + rbWildcard = true; + rbRegExp = false; + break; + case SearchType::Regexp: + rbWildcard = false; + rbRegExp = true; + break; + default: + rbWildcard = false; + rbRegExp = false; + break; + } + } + +private: + OUString sSrchStr; // the search string + + SearchType m_eSrchType; // search normal/regular/LevDist + + sal_uInt32 m_cWildEscChar; // wildcard escape character + + bool m_bCaseSense : 1; + bool m_bWildMatchSel : 1; // wildcard pattern must match entire selection + +public: + SearchParam( const OUString &rText, + SearchType eSrchType, + bool bCaseSensitive = true, + sal_uInt32 cWildEscChar = '\\', + bool bWildMatchSel = false ); + + SearchParam( const SearchParam& ); + + ~SearchParam(); + + const OUString& GetSrchStr() const { return sSrchStr; } + SearchType GetSrchType() const { return m_eSrchType; } + + bool IsCaseSensitive() const { return m_bCaseSense; } + bool IsWildMatchSel() const { return m_bWildMatchSel; } + + // signed return for API use + sal_Int32 GetWildEscChar() const { return static_cast<sal_Int32>(m_cWildEscChar); } +}; + +// For use in SAL_DEBUG etc. Output format not guaranteed to be stable. +template<typename charT, typename traits> +inline std::basic_ostream<charT, traits> & operator <<(std::basic_ostream<charT, traits> & stream, const SearchParam::SearchType& eType) +{ + switch (eType) + { + case SearchParam::SearchType::Normal: + stream << "N"; + break; + case SearchParam::SearchType::Regexp: + stream << "RE"; + break; + case SearchParam::SearchType::Wildcard: + stream << "WC"; + break; + case SearchParam::SearchType::Unknown: + stream << "UNK"; + break; + default: + stream << static_cast<int>(eType) << '?'; + break; + } + + return stream; +} + +// Utility class for searching a substring in a string. +// The following metrics are supported +// - ordinary text (Bayer/Moore) +// - regular expressions +// - weighted Levenshtein distance +// - wildcards '*' and '?' + +// This class allows forward and backward searching! + +class UNOTOOLS_DLLPUBLIC TextSearch +{ + static css::uno::Reference< css::util::XTextSearch2 > + getXTextSearch( const i18nutil::SearchOptions2& rPara ); + + css::uno::Reference < css::util::XTextSearch2 > + xTextSearch; + + void Init( const SearchParam & rParam, + const css::lang::Locale& rLocale ); + +public: + // rText is the string being searched for + // this first two CTORs are deprecated! + TextSearch( const SearchParam & rPara, LanguageType nLanguage ); + TextSearch( const SearchParam & rPara, const CharClass& rCClass ); + + TextSearch( const i18nutil::SearchOptions2& rPara ); + ~TextSearch(); + + /* search in the (selected) text the search string: + rScrTxt - the text, in which we search + pStart - start position for the search + pEnd - end position for the search + + RETURN values == true: something is found + - pStart start pos of the found text, + - pEnd end pos of the found text, + - pSrchResult - the search result with all found + positions. Is only filled with more positions + if the regular expression handles groups. + + == false: nothing found, pStart, pEnd unchanged. + + Definitions: start pos always inclusive, end pos always exclusive! + The position must always in the right direction! + search forward: start <= end + search backward: end <= start + */ + bool SearchForward( const OUString &rStr, + sal_Int32* pStart, sal_Int32* pEnd, + css::util::SearchResult* pRes = nullptr ); + /** + * @brief searchForward Search forward beginning from the start to the end + * of the given text + * @param rStr The text in which we search + * @return True if the search term is found in the text + */ + bool searchForward( const OUString &rStr ); + bool SearchBackward( const OUString &rStr, + sal_Int32* pStart, sal_Int32* pEnd, + css::util::SearchResult* pRes = nullptr ); + + void SetLocale( const i18nutil::SearchOptions2& rOpt, + const css::lang::Locale& rLocale ); + + /* replace back references in the replace string by the sub expressions from the search result */ + void ReplaceBackReferences( OUString& rReplaceStr, std::u16string_view rStr, const css::util::SearchResult& rResult ) const; + + /** Upgrade SearchOptions to SearchOptions2 for places that don't handle + SearchOptions2 yet. Better fix your module if you want to support + wildcard search. + */ + static i18nutil::SearchOptions2 UpgradeToSearchOptions2( const i18nutil::SearchOptions& rOptions ); + +}; + +} // namespace utl + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/transliterationwrapper.hxx b/include/unotools/transliterationwrapper.hxx new file mode 100644 index 000000000..138c1e8d1 --- /dev/null +++ b/include/unotools/transliterationwrapper.hxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_TRANSLITERATIONWRAPPER_HXX +#define INCLUDED_UNOTOOLS_TRANSLITERATIONWRAPPER_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <i18nlangtag/languagetag.hxx> +#include <i18nlangtag/lang.h> +#include <com/sun/star/uno/Reference.hxx> + +namespace com::sun::star::uno { template <typename > class Sequence; } +namespace com::sun::star::i18n { class XExtendedTransliteration; } +namespace com::sun::star::uno { class XComponentContext; } +enum class TransliterationFlags; + +namespace utl +{ + +class UNOTOOLS_DLLPUBLIC TransliterationWrapper +{ + css::uno::Reference< css::i18n::XExtendedTransliteration > xTrans; + LanguageTag aLanguageTag; + TransliterationFlags nType; + mutable bool bFirstCall; + + TransliterationWrapper( const TransliterationWrapper& ) = delete; + TransliterationWrapper& operator=( const TransliterationWrapper& ) = delete; + + void loadModuleImpl() const; + void setLanguageLocaleImpl( LanguageType nLang ); + +public: + TransliterationWrapper( const css::uno::Reference< css::uno::XComponentContext > & rxContext, + TransliterationFlags nType ); + + ~TransliterationWrapper(); + + TransliterationFlags getType() const { return nType; } + + bool needLanguageForTheMode() const; + + /** set a new language and load the corresponding transliteration module if + needed for the mode set with nType in the ctor */ + void loadModuleIfNeeded( LanguageType nLang ); + + /** Load the transliteration module specified by rModuleName, which has to + be the UNO service implementation name that is expanded to the full UNO + service implementation name, for example, "NumToCharKanjiShort_ja_JP" + expands to + "com.sun.star.i18n.Transliteration.NumToCharKanjiShort_ja_JP". + @ATTENTION! + This method ignores the mode type set with the constructor and + interferes with the loadModuleIfNeeded() method and the transliterate() + method that gets a LanguageType passed as parameter. Using one of + those may load a different module and overwrite this setting. Only the + transliterate() method that takes no LanguageType parameter may be used + for a specific module loaded with this method. */ + void loadModuleByImplName( const OUString& rModuleName, LanguageType nLang ); + + /** This transliteration method corresponds with the loadModuleByImplName() + method. It relies on a module being loaded and does not try load one. + If for any reason the string can't be transliterated the original + string is returned. */ + OUString transliterate( const OUString& rStr, + sal_Int32 nStart, sal_Int32 nLen ) const; + + // Wrapper implementations of class Transliteration + OUString transliterate( const OUString& rStr, LanguageType nLanguage, + sal_Int32 nStart, sal_Int32 nLen, + css::uno::Sequence <sal_Int32>* pOffset ); + + /** If two strings are equal per this transliteration. + Returns the number of matched code points in any case, even if strings + are not equal, for example: + equals( "a", 0, 1, nMatch1, "aaa", 0, 3, nMatch2 ) + returns false and nMatch:=1 and nMatch2:=1 + equals( "aab", 0, 3, nMatch1, "aaa", 0, 3, nMatch2 ) + returns false and nMatch:=2 and nMatch2:=2 + */ + bool equals( + const OUString& rStr1, sal_Int32 nPos1, sal_Int32 nCount1, sal_Int32& nMatch1, + const OUString& rStr2, sal_Int32 nPos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) const; + + sal_Int32 compareString( const OUString& rStr1, const OUString& rStr2 ) const; + + // helpers + + /** If two strings are really equal as per this translation, and not just + one string is matching the start of the other. Use this method instead + of compareString()==0 because it is much faster. + */ + bool isEqual( const OUString& rStr1, const OUString& rStr2 ) const; + + /** If string rStr1 matches the start of string rStr2, i.e. "a" in "aaa" + */ + bool isMatch( const OUString& rStr1, const OUString& rStr2 ) const; + +}; + +} // namespace utl + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/ucbhelper.hxx b/include/unotools/ucbhelper.hxx new file mode 100644 index 000000000..76168e1f7 --- /dev/null +++ b/include/unotools/ucbhelper.hxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_UCBHELPER_HXX +#define INCLUDED_UNOTOOLS_UCBHELPER_HXX + +#include <sal/config.h> + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Reference.hxx> + +namespace com::sun::star { + namespace uno { + class Any; + class XComponentContext; + } + namespace ucb{ + class XCommandEnvironment; + } +} +namespace ucbhelper { class Content; } + +namespace utl::UCBContentHelper { + +UNOTOOLS_DLLPUBLIC bool IsDocument(OUString const & url); + +UNOTOOLS_DLLPUBLIC bool IsFolder(OUString const & url); + +/// @param title must not be null +/// @return true iff title has been set (i.e., if obtaining the "Title" property +/// of the given content yields a non-void value without raising a +/// non-RuntimeException; RuntimeExceptions are passed through) +UNOTOOLS_DLLPUBLIC bool GetTitle( + OUString const & url, OUString * title); + +UNOTOOLS_DLLPUBLIC bool Kill(OUString const & url); + +UNOTOOLS_DLLPUBLIC css::uno::Any GetProperty( + OUString const & url, OUString const & property); + +UNOTOOLS_DLLPUBLIC bool MakeFolder( + ucbhelper::Content & parent, OUString const & title, + ucbhelper::Content & result); + +/// like mkdir -p +UNOTOOLS_DLLPUBLIC bool ensureFolder( + const css::uno::Reference< css::uno::XComponentContext >& xCtx, + const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv, + std::u16string_view rFolder, ucbhelper::Content & result) noexcept; + +UNOTOOLS_DLLPUBLIC bool IsYounger( + OUString const & younger, OUString const & older); + +UNOTOOLS_DLLPUBLIC bool Exists(OUString const & url); + +UNOTOOLS_DLLPUBLIC bool IsSubPath( + OUString const & parent, OUString const & child); + +UNOTOOLS_DLLPUBLIC bool EqualURLs( + OUString const & url1, OUString const & url2); + +/** +* Returns a default XCommandEnvironment to be used +* when creating a ucbhelper::Content. +* +* Due to the way the WebDAV UCP provider works, an interaction handler +* is always needed: +* 1) to activate the credential dialog or to provide the cached credentials +* whenever the server requests them; +* +* 2) in case of ssl connection (https) to activate the dialog to show the +* certificate if said certificate looks wrong or dubious. +* +* This helper provides the XCommandEnvironment with an interaction +* handler that intercepts: +* 1) css::ucb::AuthenticationRequest() +* 2) css::ucb::CertificateValidationRequest() +* 3) css::ucb::InteractiveIOException() +* 4) css::ucb::UnsupportedDataSinkException() +* +* Exception 1) and 2) will be passed to the UI handler, e.g. shown to +* the user for interaction. +* +* Exception 3) and 4) will be have a default 'Abort' result. +* See comphelper::StillReadWriteInteraction for details. +* comphelper::StillReadWriteInteraction was introduced in +* commit bbe51f039dffca2506ea542feb78571b6358b981. +*/ +UNOTOOLS_DLLPUBLIC + css::uno::Reference< css::ucb::XCommandEnvironment > getDefaultCommandEnvironment(); + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/ucbstreamhelper.hxx b/include/unotools/ucbstreamhelper.hxx new file mode 100644 index 000000000..69bae538b --- /dev/null +++ b/include/unotools/ucbstreamhelper.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_UCBSTREAMHELPER_HXX +#define INCLUDED_UNOTOOLS_UCBSTREAMHELPER_HXX + +#include <com/sun/star/uno/Reference.hxx> + +#include <unotools/unotoolsdllapi.h> + +#include <tools/stream.hxx> +#include <memory> + +namespace com::sun::star::io + { + class XStream; + class XInputStream; + } + +namespace com::sun::star::awt { class XWindow; } + +namespace utl +{ + class UNOTOOLS_DLLPUBLIC UcbStreamHelper + { + public: + static std::unique_ptr<SvStream> CreateStream(const OUString& rFileName, StreamMode eOpenMode, css::uno::Reference<css::awt::XWindow> xParentWin = nullptr); + static std::unique_ptr<SvStream> CreateStream(const OUString& rFileName, StreamMode eOpenMode, + bool bFileExists, css::uno::Reference<css::awt::XWindow> xParentWin = nullptr); + static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream ); + static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XStream >& xStream ); + static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream, bool bCloseStream ); + static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XStream >& xStream, bool bCloseStream ); + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/unotoolsdllapi.h b/include/unotools/unotoolsdllapi.h new file mode 100644 index 000000000..86864b3f0 --- /dev/null +++ b/include/unotools/unotoolsdllapi.h @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_UNOTOOLS_UNOTOOLSDLLAPI_H +#define INCLUDED_UNOTOOLS_UNOTOOLSDLLAPI_H + +#include <sal/types.h> + +#if defined(UNOTOOLS_DLLIMPLEMENTATION) +#define UNOTOOLS_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define UNOTOOLS_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define UNOTOOLS_DLLPRIVATE SAL_DLLPRIVATE + +#endif // INCLUDED_UNOTOOLS_UNOTOOLSDLLAPI_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/useroptions.hxx b/include/unotools/useroptions.hxx new file mode 100644 index 000000000..d21482dcc --- /dev/null +++ b/include/unotools/useroptions.hxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_USEROPTIONS_HXX +#define INCLUDED_UNOTOOLS_USEROPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <unotools/options.hxx> +#include <memory> + +namespace osl { class Mutex; } + +// define ---------------------------------------------------------------- +enum class UserOptToken +{ + City = 0, + Company = 1, + Country = 2, + Email = 3, + Fax = 4, + FirstName = 5, + LastName = 6, + Position = 7, + State = 8, + Street = 9, + TelephoneHome = 10, + TelephoneWork = 11, + Title = 12, + ID = 13, + Zip = 14, + FathersName = 15, + Apartment = 16, + SigningKey = 17, + EncryptionKey = 18, + EncryptToSelf = 19, + LAST = EncryptToSelf, +}; + +// class SvtUserOptions -------------------------------------------------- + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtUserOptions final : public utl::detail::Options +{ +public: + SvtUserOptions (); + virtual ~SvtUserOptions () override; + + // get the address token + OUString GetCompany () const; + OUString GetFirstName () const; + OUString GetLastName () const; + OUString GetID () const; + OUString GetStreet () const; + OUString GetCity () const; + OUString GetState () const; + OUString GetZip () const; + OUString GetCountry () const; + OUString GetPosition () const; + OUString GetTitle () const; + OUString GetTelephoneHome () const; + OUString GetTelephoneWork () const; + OUString GetFax () const; + OUString GetEmail () const; + OUString GetSigningKey () const; + OUString GetEncryptionKey () const; + bool GetEncryptToSelf () const; + + OUString GetFullName () const; + + bool IsTokenReadonly (UserOptToken nToken) const; + OUString GetToken (UserOptToken nToken) const; + void SetToken (UserOptToken nToken, OUString const& rNewToken); + void SetBoolValue (UserOptToken nToken, bool bNewValue); + +private: + class SAL_DLLPRIVATE Impl; + std::shared_ptr<Impl> xImpl; + static std::weak_ptr<Impl> xSharedImpl; +private: + class SAL_DLLPRIVATE ChangeListener; +}; + +#endif // INCLUDED_UNOTOOLS_USEROPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/viewoptions.hxx b/include/unotools/viewoptions.hxx new file mode 100644 index 000000000..273e38817 --- /dev/null +++ b/include/unotools/viewoptions.hxx @@ -0,0 +1,223 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_UNOTOOLS_VIEWOPTIONS_HXX +#define INCLUDED_UNOTOOLS_VIEWOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <com/sun/star/uno/Sequence.hxx> +#include <sal/types.h> +#include <rtl/ustring.hxx> + +namespace com::sun::star::beans { struct NamedValue; } +namespace com::sun::star::container { class XNameAccess; } + +/*-************************************************************************************************************ + @descr Use these enum values to specify right list in configuration in which your view data are saved. +*//*-*************************************************************************************************************/ + +enum class EViewType +{ + Dialog = 0, + TabDialog = 1, + TabPage = 2, + Window = 3 +}; + +/*-************************************************************************************************************ + @short collect information about view features + @descr We support different basetypes of views like dialogs, tab-dialogs, tab-pages and normal windows. + You must specify your basetype by using right enum value and must give us a valid name for your + subkey in registry! We support some fix features for some bastypes and user data as string for all! + see also configuration package "org.openoffice.Office.Views/..." for further information. + + template of configuration: + DialogType + /WindowState [string] + /UserData [set of any scalar types] + TabDialogType + /WindowState [string] + /UserData [set of any scalar types] + /PageID [int] + TabPageType + /WindowState [string] + /UserData [set of any scalar types] + WindowType + /WindowState [string] + /UserData [set of any scalar types] + /Visible [boolean] + + structure of configuration: + + org.openoffice.Office.Views [package] + /Dialogs [set] + /Dialog_FileOpen [DialogType] + /Dialog_ImportGraphics [DialogType] + ... + /Dialog_<YourName> [DialogType] + + /TabDialogs [set] + /TabDialog_001 [TabDialogType] + /TabDialog_Blubber [TabDialogType] + ... + /TabDialog_<YourName> [TabDialogType] + + /TabPages [set] + /TabPage_XXX [TabPageType] + /TabPage_Date [TabPageType] + ... + /TabPage_<YourName> [TabPageType] + + /Windows [set] + /Window_User [WindowType] + /Window_Options [WindowType] + ... + /Window_<YourName> [WindowType] + @devstatus ready to use +*//*-*************************************************************************************************************/ + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtViewOptions final +{ + + // public methods + + public: + + // constructor / destructor + + /*-**************************************************************************************************** + @short standard constructor and destructor + @descr This will de-/initialize an instance with default values. + You must give us the basic type of your view and a name which specify right entry + in dynamical configuration list. If entry not exist, we create a new one! + + @seealso enum EViewType + + @param "eType" specify type of your view and is used to use right data container! + @param "sViewName" specify the name of your view and is the key name in data list too. + @onerror An assertion is thrown in debug version. Otherwise we do nothing! + *//*-*****************************************************************************************************/ + + SvtViewOptions( EViewType eType, OUString sViewName ); + + // interface + + /*-**************************************************************************************************** + @short use it to get information about existing entries in configuration + @descr The methods to set/get the position or size will create a new entry automatically if + it not already exist and work with default values! + If this a problem for you - you MUST call these method before and + you must make up your own mind about that. + @onerror No error should occur. + *//*-*****************************************************************************************************/ + + bool Exists() const; + + /*-**************************************************************************************************** + @short use it to delete an entry of dynamic view set + @descr You can use this method to delete an existing node in configuration. + But if you call a Set- or Get- method again on this instance + the item is created again! If you do nothing after this call + your view will die relay in configuration... + + @seealso method Exist() + *//*-*****************************************************************************************************/ + + void Delete(); + + /*-**************************************************************************************************** + @short use it to set/get the window state of your view + @descr These value describe position/size and some other states of a window. + Use it with right vcl methods directly. Normally it's not necessary to + parse given string! + + @seealso vcl methods + *//*-*****************************************************************************************************/ + + OUString GetWindowState( ) const; + void SetWindowState( const OUString& sState ); + + /*-**************************************************************************************************** + @short use it to set/get the page number which was the last active one + @descr It's only supported for: - tab-dialogs + If you call it for other ones you will get an assertion in debug version. + In a product version we do nothing! + @onerror An assertion is thrown in debug version. Otherwise we do nothing! + *//*-*****************************************************************************************************/ + + OString GetPageID() const; + void SetPageID(std::string_view rID); + + /*-**************************************************************************************************** + @short use it to set/get the visual state of a window + @descr It's only supported for: - windows + If you call it for other ones you will get an assertion in debug version. + In a product version we do nothing! + @onerror An assertion is thrown in debug version. Otherwise we do nothing! + *//*-*****************************************************************************************************/ + + bool IsVisible ( ) const; + void SetVisible( bool bState ); + + /** Return true if the "Visible" property actually has a non-nil value + + (IsVisible will somewhat arbitrarily return false if the property is + nil.) + */ + bool HasVisible() const; + + /*-**************************************************************************************************** + @short use it to set/get the extended user data (consisting of a set of named scalar values) + @descr It's supported for ALL types! + Every view can handle its own user defined data set. + @onerror In the non-product version, an assertion is made. In a product version, errors are silently ignored. + *//*-*****************************************************************************************************/ + css::uno::Sequence< css::beans::NamedValue > GetUserData( ) const; + void SetUserData( const css::uno::Sequence< css::beans::NamedValue >& lData ); + + /*-**************************************************************************************************** + @short use it to set/get ONE special user data item directly + @descr Normally you can work on full user data list by using "Set/GetUserData()". + With this function you have an access on special list entries directly without any + @onerror In the non-product version, an assertion is made. In a product version, errors are silently ignored. + *//*-*****************************************************************************************************/ + + css::uno::Any GetUserItem( const OUString& sName ) const; + void SetUserItem( const OUString& sName , + const css::uno::Any& aValue ); + + private: + enum State { STATE_NONE, STATE_FALSE, STATE_TRUE }; + + css::uno::Reference< css::uno::XInterface > impl_getSetNode( const OUString& sNode , + bool bCreateIfMissing) const; + State GetVisible() const; + + /// specify which list of views in configuration is used! This can't be a static value!!! + /// ... because we need this value to work with right static data container. + EViewType m_eViewType; + OUString m_sViewName; + + OUString m_sListName; + css::uno::Reference< css::container::XNameAccess > m_xRoot; + css::uno::Reference< css::container::XNameAccess > m_xSet; +}; // class SvtViewOptions + +#endif // INCLUDED_UNOTOOLS_VIEWOPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/weakref.hxx b/include/unotools/weakref.hxx new file mode 100644 index 000000000..104737404 --- /dev/null +++ b/include/unotools/weakref.hxx @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#pragma once + +#include <sal/config.h> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <cppuhelper/weakref.hxx> +#include <cppuhelper/weak.hxx> +#include <rtl/ref.hxx> + +namespace cppu +{ +class OWeakObject; +} + +namespace unotools +{ +/** The WeakReference<> holds a weak reference to an object. + + That object must implement the css::uno::XWeak interface. + + The WeakReference itself is *not* thread safe, just as + Reference itself isn't, but the implementation of the listeners etc. + behind it *is* thread-safe, so multiple threads can have their own + WeakReferences to the same XWeak object. + + @tparam interface_type type of interface +*/ +template <class interface_type> +class SAL_WARN_UNUSED WeakReference : public com::sun::star::uno::WeakReferenceHelper +{ +public: + /** Default ctor. Creates an empty weak reference. + */ + WeakReference() + : WeakReferenceHelper() + { + } + + /** Copy ctor. Initialize this reference with a hard reference. + + @param rRef another hard ref + */ + WeakReference(const rtl::Reference<interface_type>& rRef) + : WeakReferenceHelper(rRef) + { + } + + /** Copy ctor. Initialize this reference with a hard reference. + + @param rRef another hard ref + */ + WeakReference(interface_type& rRef) + : WeakReferenceHelper(&rRef) + { + } + + /** Copy ctor. Initialize this reference with a hard reference. + + @param rRef another hard ref + */ + WeakReference(interface_type* pRef) + : WeakReferenceHelper( + css::uno::Reference<css::uno::XWeak>(static_cast<cppu::OWeakObject*>(pRef))) + { + } + + /** Releases this reference and takes over hard reference xInt. + If the implementation behind xInt does not support XWeak + or XInt is null, then this reference is null. + + @param xInt another hard reference + */ + WeakReference& operator=(const rtl::Reference<interface_type>& xInt) + { + WeakReferenceHelper::operator=(xInt); + return *this; + } + + WeakReference& operator=(rtl::Reference<interface_type>&& xInt) + { + WeakReferenceHelper::operator=(std::move(xInt)); + return *this; + } + + WeakReference& operator=(interface_type* pInt) + { + WeakReferenceHelper::operator=( + css::uno::Reference<css::uno::XWeak>(static_cast<::cppu::OWeakObject*>(pInt))); + return *this; + } + + /** Gets a hard reference to the object. + + @return hard reference or null, if the weakly referenced interface has gone + */ + rtl::Reference<interface_type> SAL_CALL get() const + { + css::uno::Reference<css::uno::XInterface> xInterface = WeakReferenceHelper::get(); + return dynamic_cast<interface_type*>(xInterface.get()); + } + + /** Gets a hard reference to the object. + + @return hard reference or null, if the weakly referenced interface has gone + */ + operator ::rtl::Reference<interface_type>() const { return get(); } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/wincodepage.hxx b/include/unotools/wincodepage.hxx new file mode 100644 index 000000000..4ec808e5c --- /dev/null +++ b/include/unotools/wincodepage.hxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_UNOTOOLS_WINCODEPAGE_HXX +#define INCLUDED_UNOTOOLS_WINCODEPAGE_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/textenc.h> +#include <rtl/ustring.hxx> + +/** Map from an ISO-639 language code (and optionally ISO-3166 country/region code) +to a text encoding of corresponding Windows ANSI or OEM codepage. + +@param sLanguage +Any language-country string. Must not be null. + +@param bOEM +If true, OEM codepage is returned, otherwise ANSI. + +@return +The corresponding rtl_TextEncoding value. +If no mapping is found, RTL_TEXTENCODING_IBM_850 is returned when bOEM is true, +RTL_TEXTENCODING_MS_1252 otherwise. +*/ +UNOTOOLS_DLLPUBLIC rtl_TextEncoding utl_getWinTextEncodingFromLangStr( + const OUString& sLanguage, bool bOEM = false); + +#endif // INCLUDED_UNOTOOLS_WINCODEPAGE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |