diff options
Diffstat (limited to '')
92 files changed, 12017 insertions, 0 deletions
diff --git a/include/uno/Enterable.h b/include/uno/Enterable.h new file mode 100644 index 000000000..5a4b8d33a --- /dev/null +++ b/include/uno/Enterable.h @@ -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_UNO_ENTERABLE_H +#define INCLUDED_UNO_ENTERABLE_H + +#include "uno/environment.h" + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/** Generic function type declaration for entering an Environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_enter (void * context); + + +/** Generic function type declaration for leaving an Environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_leave (void * context); + + +/** Generic function type declaration for calling into an Environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param pCallee the function to be called + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_callInto_v(void * context, uno_EnvCallee * pCallee, va_list * pParam); + + +/** Generic function type declaration for calling out of an Environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param pCallee the function to be called + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_callOut_v (void * context, uno_EnvCallee * pCallee, va_list * pParam); + + +/** Generic function type declaration for checking if calling on managed object is + valid. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param ppReason the reason, in case calling is not valid + @return 0 == calling is not valid, 1 == calling is valid + @since UDK 3.2.7 +*/ +typedef int uno_Enterable_isValid_v (void * context, rtl_uString ** ppReason); + + +/** A struct pReserved needs to point to, if implementing a purpose environment. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @since UDK 3.2.7 +*/ +typedef struct +{ + uno_Enterable_enter * m_enter; + uno_Enterable_leave * m_leave; + uno_Enterable_callInto_v * m_callInto_v; + uno_Enterable_callOut_v * m_callOut_v; + uno_Enterable_isValid_v * m_isValid; +} +uno_Enterable; + + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/EnvDcp.h b/include/uno/EnvDcp.h new file mode 100644 index 000000000..4d6f5f4a4 --- /dev/null +++ b/include/uno/EnvDcp.h @@ -0,0 +1,58 @@ +/* -*- 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_UNO_ENVDCP_H +#define INCLUDED_UNO_ENVDCP_H + +#include "cppu/cppudllapi.h" +#include "rtl/ustring.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Get the OBI type part of an environment descriptor. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Descriptor) + + @param pEnvDcp the Environment Descriptor + @param ppEnvTypeName the OBI type + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void uno_EnvDcp_getTypeName(rtl_uString const * pEnvDcp, rtl_uString ** ppEnvTypeName); + + +/** Get the purpose part of an environment descriptor. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Descriptor) + + @param pEnvDcp the Environment Descriptor + @param ppEnvPurpose the purpose + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void uno_EnvDcp_getPurpose (rtl_uString const * pEnvDcp, rtl_uString ** ppEnvPurpose); + + +#ifdef __cplusplus +} +#endif + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/any2.h b/include/uno/any2.h new file mode 100644 index 000000000..262f2441d --- /dev/null +++ b/include/uno/any2.h @@ -0,0 +1,170 @@ +/* -*- 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_UNO_ANY2_H +#define INCLUDED_UNO_ANY2_H + +#include "cppu/cppudllapi.h" +#include "uno/data.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if defined( _WIN32) +#pragma pack(push, 8) +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +struct _uno_Mapping; + +/** This is the binary specification of a UNO any. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_Any +{ + /** type of value + */ + struct _typelib_TypeDescriptionReference * pType; + /** pointer to value; this may point to pReserved and thus the uno_Any is not anytime + mem-copyable! You may have to correct the pData pointer to pReserved. Otherwise you need + not, because the data is stored in heap space. + */ + void * pData; + /** reserved space for storing value + */ + void * pReserved; +} uno_Any; + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +/** Assign an any with a given value. Interfaces are acquired or released by the given callback + functions. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_assign( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assign an any with a given value. Interfaces are acquired or released by the given callback + functions. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_any_assign( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Constructs an any with a given value. Interfaces are acquired by the given callback function. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_construct( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Constructs an any with a given value. Interfaces are acquired by the given callback function. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_any_construct( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Constructs an any with a given value and converts/ maps interfaces. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param mapping mapping to convert/ map interfaces +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_constructAndConvert( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); +/** Constructs an any with a given value and converts/ maps interfaces. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type of value; defaults (0) to void + @param mapping mapping to convert/ map interfaces +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_any_constructAndConvert( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); + +/** Destructs an any. + + @param pValue pointer to any + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_destruct( + uno_Any * pValue, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Sets value to void. + + @param pValue pointer to any + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_any_clear( + uno_Any * pValue, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/current_context.h b/include/uno/current_context.h new file mode 100644 index 000000000..edc9fe4d4 --- /dev/null +++ b/include/uno/current_context.h @@ -0,0 +1,63 @@ +/* -*- 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_UNO_CURRENT_CONTEXT_H +#define INCLUDED_UNO_CURRENT_CONTEXT_H + +#include "cppu/cppudllapi.h" +#include "rtl/ustring.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Gets the current task's context. + @attention + Don't spread the returned interface around to other threads. Every thread has its own + current context. + + @param ppCurrentContext inout param current context of type com.sun.star.uno.XCurrentContext + @param pEnvDcp descriptor of returned interface's environment + @param pEnvContext context of returned interface's environment (commonly 0) + @return true, if context ref was transferred (even if null ref) +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_getCurrentContext( + void ** ppCurrentContext, + rtl_uString * pEnvDcp, void * pEnvContext ) + SAL_THROW_EXTERN_C(); + +/** Sets the current task's context. + + @param pCurrentContext in param current context of type com.sun.star.uno.XCurrentContext + @param pEnvDcp descriptor of interface's environment + @param pEnvContext context of interface's environment (commonly 0) + @return true, if context ref was transferred (even if null ref) +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_setCurrentContext( + void * pCurrentContext, + rtl_uString * pEnvDcp, void * pEnvContext ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/current_context.hxx b/include/uno/current_context.hxx new file mode 100644 index 000000000..02169b0f6 --- /dev/null +++ b/include/uno/current_context.hxx @@ -0,0 +1,118 @@ +/* -*- 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_UNO_CURRENT_CONTEXT_HXX +#define INCLUDED_UNO_CURRENT_CONTEXT_HXX + +#include "sal/config.h" + +#include <cstddef> + +#include "uno/current_context.h" +#include "uno/lbnames.h" + +#include "com/sun/star/uno/XCurrentContext.hpp" + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** Getting the current context. + @attention + Don't spread the returned interface around to other threads. Every thread has its own + current context. + + @return current context or null ref, if none is set +*/ +inline Reference< XCurrentContext > SAL_CALL getCurrentContext() +{ + Reference< XCurrentContext > xRet; + ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + ::uno_getCurrentContext( reinterpret_cast<void **>(&xRet), aEnvTypeName.pData, NULL ); + return xRet; +} +/** Setting the current context. + + @param xContext current context to be set + @return true, if context has been successfully set +*/ +inline bool SAL_CALL setCurrentContext( + Reference< XCurrentContext > const & xContext ) +{ + ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + return ::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, NULL ); +} + +/** Objects of this class are used for applying a current context until they are destructed, i.e. + the ctor of this class saves the previous and sets the given context while the dtor restores + the previous one upon destruction. +*/ +class ContextLayer +{ + /** this C++ environment type name. + */ + ::rtl::OUString m_aEnvTypeName; + /** previous context + */ + Reference< XCurrentContext > m_xPreviousContext; + +public: + /** Constructor: Saves the previous context and sets the new (given) one. + + @param xNewContext new context to be set + */ + inline ContextLayer( + Reference< XCurrentContext > const & xNewContext = Reference< XCurrentContext >() ); + /** Destructor: restores the previous context. + */ + inline ~ContextLayer(); + + /** Gets the previously set context. + + @return the previously set context + */ + Reference< XCurrentContext > SAL_CALL getPreviousContext() const + { return m_xPreviousContext; } +}; + +inline ContextLayer::ContextLayer( Reference< XCurrentContext > const & xNewContext ) + : m_aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) +{ + ::uno_getCurrentContext( reinterpret_cast<void **>(&m_xPreviousContext), m_aEnvTypeName.pData, NULL ); + ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, NULL ); +} + +inline ContextLayer::~ContextLayer() +{ + ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, NULL ); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/data.h b/include/uno/data.h new file mode 100644 index 000000000..fa4455898 --- /dev/null +++ b/include/uno/data.h @@ -0,0 +1,251 @@ +/* -*- 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_UNO_DATA_H +#define INCLUDED_UNO_DATA_H + +#include "cppu/cppudllapi.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +struct _typelib_InterfaceTypeDescription; +struct _uno_Mapping; + +/** Generic function pointer declaration to query for an interface. + + @param pInterface interface + @param pTypedemanded interface type + @return interface pointer +*/ +typedef void * (SAL_CALL * uno_QueryInterfaceFunc)( + void * pInterface, struct _typelib_TypeDescriptionReference * pType ); +/** Generic function pointer declaration to acquire an interface. + + @param pInterface interface to be acquired +*/ +typedef void (SAL_CALL * uno_AcquireFunc)( + void * pInterface ); +/** Generic function pointer declaration to release an interface. + + @param pInterface interface to be release +*/ +typedef void (SAL_CALL * uno_ReleaseFunc)( + void * pInterface ); + +/** Tests if two values are equal. May compare different types (e.g., short to long). + + @param pVal1 pointer to a value + @param pVal1TypeDescr type description of pVal1 + @param pVal2 pointer to another value + @param pVal2TypeDescr type description of pVal2 + @param queryInterface function called each time two interfaces are tested whether they belong + to the same object; defaults (0) to uno + @param release function to release queried interfaces; defaults (0) to uno + @return true if values are equal +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_equalData( + void * pVal1, struct _typelib_TypeDescription * pVal1TypeDescr, + void * pVal2, struct _typelib_TypeDescription * pVal2TypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Tests if two values are equal. May compare different types (e.g., short to long). + + @param pVal1 pointer to a value + @param pVal1Type type of pVal1 + @param pVal2 pointer to another value + @param pVal2Type type of pVal2 + @param queryInterface function called each time two interfaces are tested whether they belong + to the same object; defaults (0) to uno + @param release function to release queried interfaces; defaults (0) to uno + @return true if values are equal +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_equalData( + void * pVal1, struct _typelib_TypeDescriptionReference * pVal1Type, + void * pVal2, struct _typelib_TypeDescriptionReference * pVal2Type, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pTypeDescr type description of source + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_copyData( + void * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pType type of source + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_copyData( + void * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. Interfaces are converted/ mapped by mapping parameter. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pTypeDescr type description of source + @param mapping mapping to convert/ map interfaces +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_copyAndConvertData( + void * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. Interfaces are converted/ mapped by mapping parameter. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pType type of source + @param mapping mapping to convert/ map interfaces +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_copyAndConvertData( + void * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); + +/** Destructs a given value; does NOT free its memory! + + @param pValue value to be destructed + @param pTypeDescr type description of value + @param release function called each time an interface pointer needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_destructData( + void * pValue, struct _typelib_TypeDescription * pTypeDescr, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Destructs a given value; does NOT free its memory! + + @param pValue value to be destructed + @param pType type of value + @param release function called each time an interface pointer needs to be released; + defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_destructData( + void * pValue, struct _typelib_TypeDescriptionReference * pType, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Default constructs a value. All simple types are set to 0, enums are set to their default value. + + @param pMem pointer to memory of value to be constructed + @param pTypeDescr type description of value to be constructed +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_constructData( + void * pMem, struct _typelib_TypeDescription * pTypeDescr ) + SAL_THROW_EXTERN_C(); +/** Default constructs a value. All simple types are set to 0, enums are set to their default value. + + @param pMem pointer to memory of value to be constructed + @param pType type of value to be constructed +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_constructData( + void * pMem, struct _typelib_TypeDescriptionReference * pType ) + SAL_THROW_EXTERN_C(); + +/** Assigns a destination value with a source value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pDest pointer to destination value + @param pDestTypeDescr type description of destination value + @param pSource pointer to source value; if 0, then destination value will be assigned + to default value + @param pSourceTypeDescr type destination of source value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if destination has been successfully assigned +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_assignData( + void * pDest, struct _typelib_TypeDescription * pDestTypeDescr, + void * pSource, struct _typelib_TypeDescription * pSourceTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assigns a destination value with a source value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pDest pointer to destination value + @param pDestType type of destination value + @param pSource pointer to source value; if 0, then destination value will be assigned + to default value + @param pSourceType type of source value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if destination has been successfully assigned +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_assignData( + void * pDest, struct _typelib_TypeDescriptionReference * pDestType, + void * pSource, struct _typelib_TypeDescriptionReference * pSourceType, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Tests whether a value of given type is assignable from given value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pAssignable type + @param pFrom pointer to value + @param pFromType type of value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if value is destination has been successfully assigned +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_isAssignableFromData( + struct _typelib_TypeDescriptionReference * pAssignable, + void * pFrom, struct _typelib_TypeDescriptionReference * pFromType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/dispatcher.h b/include/uno/dispatcher.h new file mode 100644 index 000000000..f9d1fbc31 --- /dev/null +++ b/include/uno/dispatcher.h @@ -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_UNO_DISPATCHER_H +#define INCLUDED_UNO_DISPATCHER_H + +#include "sal/types.h" +#include "uno/any2.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescription; +struct _uno_Interface; + +/** Function pointer declaration for the binary C uno dispatch function. Any pure out or return + value will be constructed by the callee, iff no exception is signalled. + If an exception is signalled, the any *ppException is properly constructed by the callee, + otherwise the pointer *ppException is set to 0. + An attribute get call is indicated by a non-null return pointer. + + @param pUnoI uno interface the call is performed on + @param pMemberType member type description of a method or attribute + @param pReturn pointer to return value memory; + pointer may be undefined if void method, null if attribute set call. + @param pArgs an array of pointers to arguments values. + (remark: the value of an interface reference stores a + uno_interface *, so you get it by *(uno_Interface **)pArgs[n]) + @param ppException pointer to pointer to unconstructed any to signal an exception. +*/ +typedef void (SAL_CALL * uno_DispatchMethod)( + struct _uno_Interface * pUnoI, + const struct _typelib_TypeDescription * pMemberType, + void * pReturn, + void * pArgs[], + uno_Any ** ppException ); + +#if defined( _WIN32) +#pragma pack(push, 8) +#endif + +/** The binary C uno interface description. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_Interface +{ + /** Acquires uno interface. + + @param pInterface uno interface + */ + void (SAL_CALL * acquire)( struct _uno_Interface * pInterface ); + /** Releases uno interface. + + @param pInterface uno interface + */ + void (SAL_CALL * release)( struct _uno_Interface * pInterface ); + /** dispatch function + */ + uno_DispatchMethod pDispatcher; +} uno_Interface; + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/dispatcher.hxx b/include/uno/dispatcher.hxx new file mode 100644 index 000000000..f23268e55 --- /dev/null +++ b/include/uno/dispatcher.hxx @@ -0,0 +1,186 @@ +/* -*- 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_UNO_DISPATCHER_HXX +#define INCLUDED_UNO_DISPATCHER_HXX + +#include "sal/config.h" + +#include <cstddef> + +#include "uno/dispatcher.h" + +/// @cond INTERNAL + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ holder reference for binary C uno_Interface. Not for public use, may be + subject to changes. + + @see uno_Interface + @attention + not for public use! +*/ +class UnoInterfaceReference +{ +public: + uno_Interface * m_pUnoI; + + bool is() const + { return m_pUnoI != NULL; } + + inline ~UnoInterfaceReference(); + inline UnoInterfaceReference(); + inline UnoInterfaceReference( uno_Interface * pUnoI, __sal_NoAcquire ); + inline UnoInterfaceReference( uno_Interface * pUnoI ); + inline UnoInterfaceReference( UnoInterfaceReference const & ref ); + +#if defined LIBO_INTERNAL_ONLY + UnoInterfaceReference(UnoInterfaceReference && other) noexcept : + m_pUnoI(other.m_pUnoI) + { other.m_pUnoI = nullptr; } +#endif + + uno_Interface * get() const + { return m_pUnoI; } + + inline UnoInterfaceReference & set( + uno_Interface * pUnoI ); + inline UnoInterfaceReference & set( + uno_Interface * pUnoI, __sal_NoAcquire ); + inline void clear(); + + UnoInterfaceReference & operator = ( + UnoInterfaceReference const & ref ) + { return set( ref.m_pUnoI ); } + UnoInterfaceReference & operator = ( + uno_Interface * pUnoI ) + { return set( pUnoI ); } + +#if defined LIBO_INTERNAL_ONLY + UnoInterfaceReference & operator =(UnoInterfaceReference && other) { + if (m_pUnoI != nullptr) { + (*m_pUnoI->release)(m_pUnoI); + } + m_pUnoI = other.m_pUnoI; + other.m_pUnoI = nullptr; + return *this; + } +#endif + + inline void dispatch( + struct _typelib_TypeDescription const * pMemberType, + void * pReturn, void * pArgs [], uno_Any ** ppException ) const; +}; + + +inline UnoInterfaceReference::~UnoInterfaceReference() +{ + if (m_pUnoI != NULL) + (*m_pUnoI->release)( m_pUnoI ); +} + + +inline UnoInterfaceReference::UnoInterfaceReference() + : m_pUnoI( NULL ) +{ +} + + +inline UnoInterfaceReference::UnoInterfaceReference( + uno_Interface * pUnoI, __sal_NoAcquire ) + : m_pUnoI( pUnoI ) +{ +} + + +inline UnoInterfaceReference::UnoInterfaceReference( uno_Interface * pUnoI ) + : m_pUnoI( pUnoI ) +{ + if (m_pUnoI != NULL) + (*m_pUnoI->acquire)( m_pUnoI ); +} + + +inline UnoInterfaceReference::UnoInterfaceReference( + UnoInterfaceReference const & ref ) + : m_pUnoI( ref.m_pUnoI ) +{ + if (m_pUnoI != NULL) + (*m_pUnoI->acquire)( m_pUnoI ); +} + + +inline UnoInterfaceReference & UnoInterfaceReference::set( + uno_Interface * pUnoI ) +{ + if (pUnoI != NULL) + (*pUnoI->acquire)( pUnoI ); + if (m_pUnoI != NULL) + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = pUnoI; + return *this; +} + + +inline UnoInterfaceReference & UnoInterfaceReference::set( + uno_Interface * pUnoI, __sal_NoAcquire ) +{ + if (m_pUnoI != NULL) + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = pUnoI; + return *this; +} + + +inline void UnoInterfaceReference::clear() +{ + if (m_pUnoI != NULL) + { + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = NULL; + } +} + + +inline void UnoInterfaceReference::dispatch( + struct _typelib_TypeDescription const * pMemberType, + void * pReturn, void * pArgs [], uno_Any ** ppException ) const +{ + (*m_pUnoI->pDispatcher)( + m_pUnoI, pMemberType, pReturn, pArgs, ppException ); +} + +} +} +} +} + +/// @endcond + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/environment.h b/include/uno/environment.h new file mode 100644 index 000000000..ce09e3ad5 --- /dev/null +++ b/include/uno/environment.h @@ -0,0 +1,385 @@ +/* -*- 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_UNO_ENVIRONMENT_H +#define INCLUDED_UNO_ENVIRONMENT_H + +#include "cppu/cppudllapi.h" +#include "rtl/ustring.h" + +#include <stdarg.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _uno_ExtEnvironment; +struct _typelib_InterfaceTypeDescription; + +#if defined( _WIN32) +#pragma pack(push, 8) +#endif + +/** The binary specification of a UNO environment. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_Environment +{ + /** reserved for future use (0 if not used) + */ + void * pReserved; + + /** type name of environment + */ + rtl_uString * pTypeName; + + /** free context pointer to be used for specific classes of environments (e.g., a jvm pointer) + */ + void * pContext; + + /** pointer to extended environment (interface registration functionality), if supported + */ + struct _uno_ExtEnvironment * pExtEnv; + + /** Acquires this environment. + + @param pEnv this environment + */ + void (SAL_CALL * acquire)( struct _uno_Environment * pEnv ); + + /** Releases this environment; last release of environment will revoke the environment from + runtime. + + @param pEnv this environment + */ + void (SAL_CALL * release)( struct _uno_Environment * pEnv ); + + /** Acquires this environment weakly. You can only harden a weakly held environment if it + is still acquired hard (acquire()). + + @param pEnv this environment + */ + void (SAL_CALL * acquireWeak)( struct _uno_Environment * pEnv ); + + /** Releases this environment weakly in correspondence to acquireWeak(). + + @param pEnv this environment + */ + void (SAL_CALL * releaseWeak)( struct _uno_Environment * pEnv ); + + /** Makes hard reference out of weak referenced environment. You can only harden a weakly + held environment if it is still acquired hard (acquire()). + + @param ppHardEnv inout hard referenced environment (has to be released via release()) + @param pEnv environment (may be weak referenced) + */ + void (SAL_CALL * harden)( + struct _uno_Environment ** ppHardEnv, + struct _uno_Environment * pEnv ); + + /** Call this function to EXPLICITLY dispose this environment (e.g., release all + interfaces). You may want to call this function before shutting down due to a runtime error. + + @param pEnv this environment + */ + void (SAL_CALL * dispose)( struct _uno_Environment * pEnv ); + + /* ===== the following part will be late initialized by a matching bridge ===== * + * ===== and is NOT for public use. ===== */ + + /** CALLBACK function pointer: Disposing callback function pointer that can be set to get + signalled before the environment is destroyed. + + @param pEnv environment that is being disposed + */ + void (SAL_CALL * environmentDisposing)( struct _uno_Environment * pEnv ); +} uno_Environment; + +/** Generic function pointer declaration to free a proxy object if it is not needed by the + environment anymore. + Any proxy object must register itself on first acquire() call and revoke itself on last + release() call. This can happen several times because the environment caches proxy objects + until the environment explicitly frees the proxy object calling this function. + + @param pEnv environment + @param pProxy proxy pointer +*/ +typedef void (SAL_CALL * uno_freeProxyFunc)( struct _uno_ExtEnvironment * pEnv, void * pProxy ); + +/** Generic function pointer declaration to allocate memory. Used with getRegisteredInterfaces(). + + @param nBytes amount of memory in bytes + @return pointer to allocated memory +*/ +typedef void * (SAL_CALL * uno_memAlloc)( sal_Size nBytes ); + +/** The binary specification of a UNO environment supporting interface registration. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_ExtEnvironment +{ + /** inherits all members of a uno_Environment + */ + uno_Environment aBase; + + /** Registers an interface of this environment. + + @param pEnv this environment + @param ppInterface inout parameter of interface to be registered + @param pOId object id of interface + @param pTypeDescr type description of interface + */ + void (SAL_CALL * registerInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppInterface, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Registers a proxy interface of this environment that can be reanimated and is freed + explicitly by this environment. + + @param pEnv this environment + @param ppInterface inout parameter of interface to be registered + @param freeProxy function to free proxy object + @param pOId object id of interface + @param pTypeDescr type description of interface + */ + void (SAL_CALL * registerProxyInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppProxy, + uno_freeProxyFunc freeProxy, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Revokes an interface from this environment. You have to revoke any interface that has + been registered via this method. + + @param pEnv this environment + @param pInterface interface to be revoked + */ + void (SAL_CALL * revokeInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + + /** Provides the object id of a given interface. + + @param ppOut inout oid + @param pInterface interface of object + */ + void (SAL_CALL * getObjectIdentifier)( + struct _uno_ExtEnvironment * pEnv, + rtl_uString ** ppOId, + void * pInterface ); + + /** Retrieves an interface identified by its object id and type from this environment. + Interfaces are retrieved in the same order as they are registered. + + @param pEnv this environment + @param ppInterface inout parameter for the registered interface; (0) if none was found + @param pOId object id of interface to be retrieved + @param pTypeDescr type description of interface to be retrieved + */ + void (SAL_CALL * getRegisteredInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppInterface, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Returns all currently registered interfaces of this environment. The memory block + allocated might be slightly larger than (*pnLen * sizeof(void *)). + + @param pEnv this environment + @param pppInterfaces out param; pointer to array of interface pointers + @param pnLen out param; length of array + @param memAlloc function for allocating memory that is passed back + */ + void (SAL_CALL * getRegisteredInterfaces)( + struct _uno_ExtEnvironment * pEnv, + void *** pppInterfaces, + sal_Int32 * pnLen, + uno_memAlloc memAlloc ); + + /* ===== the following part will be late initialized by a matching bridge ===== */ + + /** Computes an object id of the given interface; is called by the environment implementation. + + @param pEnv corresponding environment + @param ppOId out param: computed id + @param pInterface an interface + */ + void (SAL_CALL * computeObjectIdentifier)( + struct _uno_ExtEnvironment * pEnv, + rtl_uString ** ppOId, void * pInterface ); + + /** Function to acquire an interface. + + @param pEnv corresponding environment + @param pInterface an interface + */ + void (SAL_CALL * acquireInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + + /** Function to release an interface. + + @param pEnv corresponding environment + @param pInterface an interface + */ + void (SAL_CALL * releaseInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + +} uno_ExtEnvironment; + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +/** Function exported by some bridge library providing acquireInterface(), releaseInterface(); + may set a disposing callback. + + @param pEnv environment to be initialized +*/ +typedef void (SAL_CALL * uno_initEnvironmentFunc)( uno_Environment * pEnv ); +#define UNO_INIT_ENVIRONMENT "uno_initEnvironment" + +#ifdef DISABLE_DYNLOADING +/* We link statically and have just the C++ environment */ +void SAL_CALL CPPU_ENV_uno_initEnvironment( uno_Environment * Env ) + SAL_THROW_EXTERN_C(); + +/* We might also have the Java environment */ +void SAL_CALL java_uno_initEnvironment( uno_Environment * Env ) + SAL_THROW_EXTERN_C(); +#endif + +/** Gets a specific environment. If the specified environment does not exist, then a default one + is created and registered. The environment revokes itself on last release() call. + + @param ppEnv inout parameter of environment; given environment will be released + @param pEnvDcp descriptor of environment + @param pContext some context pointer (e.g., to distinguish java vm; set 0 if not needed) +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext ) + SAL_THROW_EXTERN_C(); + +/** Gets all specified environments. Caller has to release returned environments and free allocated + memory. + + @param pppEnvs out param; pointer to array of environments + @param pnLen out param; length of array + @param memAlloc function for allocating memory that is passed back + @param pEnvDcp descriptor of environments; 0 defaults to all +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getRegisteredEnvironments( + uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc, + rtl_uString * pEnvDcp ) + SAL_THROW_EXTERN_C(); + +/** Creates an environment. The new environment is anonymous (NOT publicly registered/ accessible). + + @param ppEnv out parameter of environment; given environment will be released + @param pEnvDcp descriptor of environment + @param pContext context pointer (e.g., to distinguish java vm); set 0 if not needed +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_createEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext ) + SAL_THROW_EXTERN_C(); + +/** Dumps out environment information, i.e. registered interfaces. + + @param stream output stream (FILE *) + @param pEnv environment to be dumped + @param pFilter if not null, filters output +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_dumpEnvironment( + void * stream, uno_Environment * pEnv, const sal_Char * pFilter ) + SAL_THROW_EXTERN_C(); +/** Dumps out environment information, i.e. registered interfaces. + + @param stream output stream (FILE *) + @param pEnvDcp descriptor of environment to be dumped + @param pFilter if not null, filters output +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_dumpEnvironmentByName( + void * stream, rtl_uString * pEnvDcp, const sal_Char * pFilter ) + SAL_THROW_EXTERN_C(); + + + +/** Returns the current Environment. + In case no Environment has explicitly been entered, a purpose free + default environment gets returned (e.g. the "uno" or "gcc3" Environment). + + @param ppEnv inout parameter; a given environment will be released + @param pTypeName the optional type of the environment, falls back to "uno" + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getCurrentEnvironment(uno_Environment ** ppEnv, rtl_uString * pTypeName) + SAL_THROW_EXTERN_C(); + +/** Typedef for variable argument function. + */ +typedef void SAL_CALL uno_EnvCallee(va_list * pParam); + +/** Invoke the passed function in the given environment. + + @param pEnv the target environment + @param pCallee the function to call + @param pParam the parameter pointer passed to the function + @since UDK 3.2.7 + */ +CPPU_DLLPUBLIC void SAL_CALL uno_Environment_invoke_v(uno_Environment * pEnv, uno_EnvCallee * pCallee, va_list * pParam) + SAL_THROW_EXTERN_C(); + +/** Invoke the passed function in the given environment. + + @param pEnv the target environment + @param pCallee the function to call + @param ... the parameters passed to the function + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_Environment_invoke (uno_Environment * pEnv, uno_EnvCallee * pCallee, ...) + SAL_THROW_EXTERN_C(); + +/** Enter an environment explicitly. + + @param pEnv the environment to enter; NULL leaves all environments + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_Environment_enter(uno_Environment * pEnv) + SAL_THROW_EXTERN_C(); + +/** Check if a particular environment is currently valid, so + that objects of that environment might be called. + + @param pEnv the environment + @param pReason the reason, if it is not valid + @return 1 == valid, 0 == invalid + @since UDK 3.2.7 +*/ +CPPU_DLLPUBLIC int SAL_CALL uno_Environment_isValid(uno_Environment * pEnv, rtl_uString ** pReason) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/environment.hxx b/include/uno/environment.hxx new file mode 100644 index 000000000..0484790cf --- /dev/null +++ b/include/uno/environment.hxx @@ -0,0 +1,290 @@ +/* -*- 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_UNO_ENVIRONMENT_HXX +#define INCLUDED_UNO_ENVIRONMENT_HXX + +#include "sal/config.h" + +#include <cstddef> + +#include "rtl/alloc.h" +#include "rtl/ustring.hxx" +#include "uno/environment.h" + +#include "uno/lbnames.h" + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +/** C++ wrapper for binary C uno_Environment. + + @see uno_Environment +*/ +class Environment +{ + /** binary C uno_Environment + */ + uno_Environment * _pEnv; + +public: + /** Returns the current Environment. + + @param typeName the optional type of the Environment, falls back to "uno" in case being empty, + respectively to current C++ Environment. + @since UDK 3.2.7 + */ + inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME)); + + /// @cond INTERNAL + // these are here to force memory de/allocation to sal lib. + static void * SAL_CALL operator new ( size_t nSize ) + { return ::rtl_allocateMemory( nSize ); } + static void SAL_CALL operator delete ( void * pMem ) + { ::rtl_freeMemory( pMem ); } + static void * SAL_CALL operator new ( size_t, void * pMem ) + { return pMem; } + static void SAL_CALL operator delete ( void *, void * ) + {} + /// @endcond + + /** Constructor: acquires given environment + + @param pEnv environment + */ + inline Environment( uno_Environment * pEnv = NULL ); + + /** Gets a specific environment. If the specified environment does not exist, then a default one + is created and registered. + + @param envDcp descriptor of the environment + @param pContext context pointer + */ + inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ); + + + /** Copy constructor: acquires given environment + + @param rEnv another environment + */ + inline Environment( const Environment & rEnv ); + +#if defined LIBO_INTERNAL_ONLY + Environment(Environment && other) noexcept : _pEnv(other._pEnv) + { other._pEnv = nullptr; } +#endif + + /** Destructor: releases a set environment. + */ + inline ~Environment(); + + /** Sets a given environment, i.e. acquires given one and releases a set one. + + @param pEnv another environment + @return this environment + */ + inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ); + /** Sets a given environment, i.e. acquires given one and releases a set one. + + @param rEnv another environment + @return this environment + */ + Environment & SAL_CALL operator = ( const Environment & rEnv ) + { return operator = ( rEnv._pEnv ); } + +#if defined LIBO_INTERNAL_ONLY + Environment & operator =(Environment && other) { + if (_pEnv != nullptr) { + (*_pEnv->release)(_pEnv); + } + _pEnv = other._pEnv; + other._pEnv = nullptr; + return *this; + } +#endif + + /** Provides UNacquired pointer to the set C environment. + + @return UNacquired pointer to the C environment struct + */ + uno_Environment * SAL_CALL get() const + { return _pEnv; } + + /** Gets type name of set environment. + + @return type name of set environment + */ + ::rtl::OUString SAL_CALL getTypeName() const + { return _pEnv->pTypeName; } + + /** Gets free context pointer of set environment. + + @return free context pointer of set environment + */ + void * SAL_CALL getContext() const + { return _pEnv->pContext; } + + /** Tests if an environment is set. + + @return true, if an environment is set, false otherwise + */ + bool SAL_CALL is() const + { return (_pEnv != NULL); } + + /** Releases a set environment. + */ + inline void SAL_CALL clear(); + + /** Invoke the passed function in this environment. + + @param pCallee the function to call + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 + */ + inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const; + + /** Invoke the passed function in this environment. + + @param pCallee the function to call + @param ... the parameters to be passed to the function + @since UDK 3.2.7 + */ + inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const; + + /** Enter this environment explicitly. + + @since UDK 3.2.7 + */ + inline void SAL_CALL enter() const; + + /** Checks, if it is valid to currently call objects + belonging to this environment. + + @since UDK 3.2.7 + */ + inline int SAL_CALL isValid(rtl::OUString * pReason) const; +}; + +inline Environment::Environment( uno_Environment * pEnv ) + : _pEnv( pEnv ) +{ + if (_pEnv) + (*_pEnv->acquire)( _pEnv ); +} + +inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) + : _pEnv(NULL) +{ + uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext); +} + +inline Environment::Environment( const Environment & rEnv ) + : _pEnv( rEnv._pEnv ) +{ + if (_pEnv) + (*_pEnv->acquire)( _pEnv ); +} + +inline Environment::~Environment() +{ + if (_pEnv) + (*_pEnv->release)( _pEnv ); +} + +inline void Environment::clear() +{ + if (_pEnv) + { + (*_pEnv->release)( _pEnv ); + _pEnv = NULL; + } +} + +inline Environment & Environment::operator = ( uno_Environment * pEnv ) +{ + if (pEnv != _pEnv) + { + if (pEnv) + (*pEnv->acquire)( pEnv ); + if (_pEnv) + (*_pEnv->release)( _pEnv ); + _pEnv = pEnv; + } + return *this; +} + +inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const +{ + if (_pEnv) + uno_Environment_invoke_v(_pEnv, pCallee, pParam); +} + +inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const +{ + if (_pEnv) + { + va_list param; + + va_start(param, pCallee); + uno_Environment_invoke_v(_pEnv, pCallee, ¶m); + va_end(param); + } + +} + +inline void SAL_CALL Environment::enter() const +{ + uno_Environment_enter(_pEnv); +} + +inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const +{ + return uno_Environment_isValid(_pEnv, &pReason->pData); +} + +inline Environment Environment::getCurrent(rtl::OUString const & typeName) +{ + Environment environment; + + uno_Environment * pEnv = NULL; + uno_getCurrentEnvironment(&pEnv, typeName.pData); + environment = pEnv; + if (pEnv) + pEnv->release(pEnv); + + return environment; +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/lbnames.h b/include/uno/lbnames.h new file mode 100644 index 000000000..b8f0ef758 --- /dev/null +++ b/include/uno/lbnames.h @@ -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_UNO_LBNAMES_H +#define INCLUDED_UNO_LBNAMES_H + +/* I assume "LB" means "Language Binding" */ + +#include "sal/config.h" + +#include "sal/macros.h" + +#ifdef __cplusplus + +#ifdef CPPU_ENV + +/** Name for C++ compiler/ platform, e.g. "gcc3", "msci" */ +#define CPPU_CURRENT_LANGUAGE_BINDING_NAME SAL_STRINGIFY( CPPU_ENV ) + +#else + +#error "No supported C++ compiler environment." +provoking error here, because PP ignores #error + +#endif /* CPPU_ENV */ + +#endif /* __cplusplus */ + +/** Environment type name for binary C UNO. */ +#define UNO_LB_UNO "uno" +/** Environment type name for Java 1.3.1 compatible virtual machine. */ +#define UNO_LB_JAVA "java" +/** Environment type name for CLI (Common Language Infrastructure). */ +#define UNO_LB_CLI "cli" + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/mapping.h b/include/uno/mapping.h new file mode 100644 index 000000000..cb24839eb --- /dev/null +++ b/include/uno/mapping.h @@ -0,0 +1,212 @@ +/* -*- 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_UNO_MAPPING_H +#define INCLUDED_UNO_MAPPING_H + +#include "cppu/cppudllapi.h" +#include "rtl/ustring.h" + + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_InterfaceTypeDescription; +struct _uno_Mapping; +struct _uno_Environment; + +/** + Function pointer declaration to acquire a UNO mapping. +*/ +typedef void (SAL_CALL * uno_AcquireMappingFunc)(struct _uno_Mapping *); + +/** + Function pointer declaration to release a UNO mapping. +*/ +typedef void (SAL_CALL * uno_ReleaseMappingFunc)(struct _uno_Mapping *); + +/** Function pointer declaration to map an interface from one environment to another. + + @param pMapping mapping + @param ppOut [inout] destination interface; existing interfaces are released + @param pInterface source interface + @param pInterfaceTypeDescr type description of the interface +*/ +typedef void (SAL_CALL * uno_MapInterfaceFunc)( + struct _uno_Mapping * pMapping, + void ** ppOut, void * pInterface, + struct _typelib_InterfaceTypeDescription * pInterfaceTypeDescr ); + + +#if defined( _WIN32) +#pragma pack(push, 8) +#endif + +/** This is the binary specification of a mapping. +*/ +typedef struct SAL_DLLPUBLIC_RTTI _uno_Mapping +{ + /** Acquires mapping + */ + uno_AcquireMappingFunc acquire; + + /** Releases mapping. The last release may unload bridges. + */ + uno_ReleaseMappingFunc release; + + /** mapping function + */ + uno_MapInterfaceFunc mapInterface; +} uno_Mapping; + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +/** Gets an interface mapping from one environment to another. + + @param ppMapping [inout] mapping; existing mapping will be released + @param pFrom source environment + @param pTo destination environment + (interfaces resulting in mapInterface() call can be used + in this language environment) + @param pAddPurpose additional purpose of mapping (e.g., protocolling); defaults to 0 (none) +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getMapping( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo, + rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/** Callback function pointer declaration to get a mapping. + + @param ppMapping inout mapping + @param pFrom source environment + @param pTo destination environment + @param pAddPurpose additional purpose +*/ +typedef void (SAL_CALL * uno_getMappingFunc)( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo, + rtl_uString * pAddPurpose ); + +/** Registers a callback being called each time a mapping is demanded. + + @param pCallback callback function +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_registerMappingCallback( + uno_getMappingFunc pCallback ) + SAL_THROW_EXTERN_C(); + +/** Revokes a mapping callback registration. + + @param pCallback callback function +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_revokeMappingCallback( + uno_getMappingFunc pCallback ) + SAL_THROW_EXTERN_C(); + +/** Function pointer declaration to free a mapping. + + @param pMapping mapping to be freed +*/ +typedef void (SAL_CALL * uno_freeMappingFunc)( struct _uno_Mapping * pMapping ); + +/** Registers a mapping. A mapping registers itself on first acquire and revokes itself on last + release. The given freeMapping function is called by the runtime to cleanup any resources. + + @param ppMapping inout mapping to be registered + @param freeMapping called by runtime to delete mapping + @param pFrom source environment + @param pTo destination environment + @param pAddPurpose additional purpose string; defaults to 0 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_registerMapping( + struct _uno_Mapping ** ppMapping, uno_freeMappingFunc freeMapping, + struct _uno_Environment * pFrom, struct _uno_Environment * pTo, rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/** Revokes a mapping. A mapping registers itself on first acquire and revokes itself on last + release. + + @param pMapping mapping to be revoked +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_revokeMapping( + struct _uno_Mapping * pMapping ) + SAL_THROW_EXTERN_C(); + +/** Gets an interface mapping from one language environment to another by corresponding environment + type names. + + @param ppMapping [inout] mapping; existing mapping will be released + @param pFrom source environment type name + @param pTo destination environment type name + (interfaces resulting in mapInterface() call can be used + in this language environment) + @param pAddPurpose additional purpose of mapping (e.g., protocolling); defaults to 0 (none) +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_getMappingByName( + struct _uno_Mapping ** ppMapping, + rtl_uString * pFrom, + rtl_uString * pTo, + rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/* symbol exported by each language binding library */ +#define UNO_EXT_GETMAPPING "uno_ext_getMapping" + +/** Function pointer declaration to get a mapping from a loaded bridge. Bridges export a function + called uno_ext_getMapping() of this signature. + + @param[in,out] ppMapping mapping; existing mapping will be released + @param[in] pFrom source environment + @param[in] pTo destination environment +*/ +typedef void (SAL_CALL * uno_ext_getMappingFunc)( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo ); + +#ifdef DISABLE_DYNLOADING +/* Static linking, this is the uno_ext_getMapping function in the C++/UNO bridge */ +void SAL_CALL CPPU_ENV_uno_ext_getMapping( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo ) + SAL_THROW_EXTERN_C(); + +/* This is the uno_ext_getMapping function in the Java/UNO bridge */ +void SAL_CALL java_uno_ext_getMapping( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo ) + SAL_THROW_EXTERN_C(); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/mapping.hxx b/include/uno/mapping.hxx new file mode 100644 index 000000000..be21909eb --- /dev/null +++ b/include/uno/mapping.hxx @@ -0,0 +1,356 @@ +/* -*- 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_UNO_MAPPING_HXX +#define INCLUDED_UNO_MAPPING_HXX + +#include "sal/config.h" + +#include <cstddef> + +#include "uno/lbnames.h" +#include "rtl/alloc.h" +#include "rtl/ustring.hxx" +#include "osl/diagnose.h" +#include "uno/mapping.h" +#include "com/sun/star/uno/Type.hxx" +#include "com/sun/star/uno/Reference.hxx" +#include "cppu/unotype.hxx" +#include "uno/environment.hxx" + +typedef struct _typelib_TypeDescription typelib_TypeDescription; +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; +typedef struct _uno_Interface uno_Interface; + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ wrapper for C uno_Mapping. + + @see uno_Mapping +*/ +class Mapping +{ + uno_Mapping * _pMapping; + +public: + // these are here to force memory de/allocation to sal lib. + /// @cond INTERNAL + static void * SAL_CALL operator new ( size_t nSize ) + { return ::rtl_allocateMemory( nSize ); } + static void SAL_CALL operator delete ( void * pMem ) + { ::rtl_freeMemory( pMem ); } + static void * SAL_CALL operator new ( size_t, void * pMem ) + { return pMem; } + static void SAL_CALL operator delete ( void *, void * ) + {} + /// @endcond + + /** Holds a mapping from the specified source to the specified destination by environment + type names. + + @param rFrom type name of source environment + @param rTo type name of destination environment + @param rAddPurpose additional purpose + */ + inline Mapping( + const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); + + /** Holds a mapping from the specified source to the specified destination. + + @param pFrom source environment + @param pTo destination environment + @param rAddPurpose additional purpose + */ + inline Mapping( + uno_Environment * pFrom, uno_Environment * pTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); + + /** Holds a mapping from the specified source to the specified destination + environment. + + @param rFrom source environment + @param rTo destination environment + @param rAddPurpose additional purpose + */ + inline Mapping(const Environment & rFrom, const Environment & rTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); + + /** Constructor. + + @param pMapping another mapping + */ + inline Mapping( uno_Mapping * pMapping = NULL ); + + /** Copy constructor. + + @param rMapping another mapping + */ + inline Mapping( const Mapping & rMapping ); + +#if defined LIBO_INTERNAL_ONLY + Mapping(Mapping && other) noexcept : _pMapping(other._pMapping) + { other._pMapping = nullptr; } +#endif + + /** Destructor. + */ + inline ~Mapping(); + + /** Sets a given mapping. + + @param pMapping another mapping + @return this mapping + */ + inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ); + /** Sets a given mapping. + + @param rMapping another mapping + @return this mapping + */ + Mapping & SAL_CALL operator = ( const Mapping & rMapping ) + { return operator = ( rMapping._pMapping ); } + +#if defined LIBO_INTERNAL_ONLY + Mapping & operator =(Mapping && other) noexcept { + if (_pMapping != nullptr) { + (*_pMapping->release)(_pMapping); + } + _pMapping = other._pMapping; + other._pMapping = nullptr; + return *this; + } +#endif + + /** Provides a pointer to the C mapping. The returned mapping is NOT acquired! + + @return UNacquired C mapping + */ + uno_Mapping * SAL_CALL get() const + { return _pMapping; } + + /** Tests if a mapping is set. + + @return true if a mapping is set + */ + bool SAL_CALL is() const + { return (_pMapping != NULL); } + + /** Releases a set mapping. + */ + inline void SAL_CALL clear(); + + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param pTypeDescr type description of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const; + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param pTypeDescr type description of interface + @return mapped interface + */ + void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const + { return mapInterface( pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); } + + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param rType type of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( + void * pInterface, const css::uno::Type & rType ) const; + + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param pTypeDescr type description of interface + */ + void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const + { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); } + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param pTypeDescr type description of interface + */ + void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const + { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); } + + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param rType type of interface to be mapped + */ + inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const css::uno::Type & rType ) const; +}; + +inline Mapping::Mapping( + const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose ) + : _pMapping( NULL ) +{ + uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData ); +} + +inline Mapping::Mapping( + uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose ) + : _pMapping( NULL ) +{ + uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData ); +} + +inline Mapping::Mapping( + const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose ) + : _pMapping(NULL) +{ + uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData ); +} + +inline Mapping::Mapping( uno_Mapping * pMapping ) + : _pMapping( pMapping ) +{ + if (_pMapping) + (*_pMapping->acquire)( _pMapping ); +} + +inline Mapping::Mapping( const Mapping & rMapping ) + : _pMapping( rMapping._pMapping ) +{ + if (_pMapping) + (*_pMapping->acquire)( _pMapping ); +} + +inline Mapping::~Mapping() +{ + if (_pMapping) + (*_pMapping->release)( _pMapping ); +} + +inline void Mapping::clear() +{ + if (_pMapping) + { + (*_pMapping->release)( _pMapping ); + _pMapping = NULL; + } +} + +inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) +{ + if (pMapping) + (*pMapping->acquire)( pMapping ); + if (_pMapping) + (*_pMapping->release)( _pMapping ); + _pMapping = pMapping; + return *this; +} + +inline void Mapping::mapInterface( + void ** ppOut, void * pInterface, const css::uno::Type & rType ) const +{ + typelib_TypeDescription * pTD = NULL; + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + if (pTD) + { + (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) ); + TYPELIB_DANGER_RELEASE( pTD ); + } +} + +inline void * Mapping::mapInterface( + void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const +{ + void * pOut = NULL; + (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr ); + return pOut; +} + +inline void * Mapping::mapInterface( + void * pInterface, const css::uno::Type & rType ) const +{ + void * pOut = NULL; + mapInterface( &pOut, pInterface, rType ); + return pOut; +} + +/** Deprecated. This function DOES NOT WORK with Purpose Environments + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) + + Maps a binary C UNO interface to be used in the currently used compiler environment. + + @tparam C interface type + @param ppRet inout returned interface pointer + @param pUnoI binary C UNO interface + @return true if successful, false otherwise + + @deprecated +*/ +template< class C > +SAL_DEPRECATED("use uno_Mapping") +inline bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) +{ + Mapping aMapping( UNO_LB_UNO, CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + OSL_ASSERT( aMapping.is() ); + aMapping.mapInterface( + reinterpret_cast<void **>(ppRet), pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) ); + return (0 != *ppRet); +} +/** Deprecated. This function DOES NOT WORK with Purpose Environments + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) + + Maps a UNO interface of the currently used compiler environment to binary C UNO. + + @tparam C interface type + @param ppRet inout returned interface pointer + @param x interface reference + @return true if successful, false otherwise + + @deprecated +*/ +template< class C > +SAL_DEPRECATED("use uno_Mapping") +inline bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) +{ + Mapping aMapping( CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_UNO ); + OSL_ASSERT( aMapping.is() ); + aMapping.mapInterface( + reinterpret_cast<void **>(ppRet), x.get(), ::cppu::getTypeFavourUnsigned( &x ) ); + return (NULL != *ppRet); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/sequence2.h b/include/uno/sequence2.h new file mode 100644 index 000000000..ae2cc3115 --- /dev/null +++ b/include/uno/sequence2.h @@ -0,0 +1,195 @@ +/* -*- 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_UNO_SEQUENCE2_H +#define INCLUDED_UNO_SEQUENCE2_H + +#include "cppu/cppudllapi.h" +#include "uno/data.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +typedef sal_Sequence uno_Sequence; + +/** Assigns a sequence. + + @param ppDest destinstaion sequence + @param pSource source sequence + @param pTypeDescr type description of the sequence and NOT of an element + @param release function called each time an interface needs to + be released; defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assigns a sequence. + + @param ppDest destinstaion sequence + @param pSource source sequence + @param pType type of the sequence and NOT of an element + @param release function called each time an interface needs to + be released; defaults (0) to uno +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Constructs a new sequence with given elements. + + @param ppSequence out parameter sequence; + 0 if memory allocation has failed + @param pTypeDescr type description of the sequence and NOT of an + element + @param pElements if 0, then all elements are default constructed + @param len number of elements + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_sequence_construct( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Constructs a new sequence with given elements. + + @param ppSequence out parameter sequence; + 0 if memory allocation has failed + @param pType type of the sequence and NOT of an element + @param pElements if 0, then all elements are default constructed + @param len number of elements + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_sequence_construct( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Assures that the reference count of the given sequence is one. + Otherwise a new copy of the sequence is created with a reference count + of one. + + @param ppSequence inout sequence + @param pTypeDescr type description of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_sequence_reference2One( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assures that the reference count of the given sequence is one. + Otherwise a new copy of the sequence is created with a reference count + of one. + + @param ppSequence inout sequence + @param pType type of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_sequence_reference2One( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Reallocates length of a sequence. This truncates a sequence or enlarges + it default constructing appended elements. + + @param ppSequence inout sequence + @param pTypeDescr type description of sequence + @param nSize new size of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_sequence_realloc( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + sal_Int32 nSize, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Reallocates length of a sequence. This truncates a sequence or enlarges + it default constructing appended elements. + + @param ppSequence inout sequence + @param pType type of sequence + @param nSize new size of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_type_sequence_realloc( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + sal_Int32 nSize, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Destroy a sequence whose reference count has dropped to zero. + + @param sequence must be non-null, sequence->nRefCount must be zero + @param type the type of the sequence, must be non-null + @param release function called each time an interface needs to be release, + must be non-null + + @since LibreOffice 4.4 +*/ +CPPU_DLLPUBLIC void SAL_CALL uno_type_sequence_destroy( + uno_Sequence * sequence, struct _typelib_TypeDescriptionReference * type, + uno_ReleaseFunc release) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/uno/threadpool.h b/include/uno/threadpool.h new file mode 100644 index 000000000..52bac0a4a --- /dev/null +++ b/include/uno/threadpool.h @@ -0,0 +1,190 @@ +/* -*- 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_UNO_THREADPOOL_H +#define INCLUDED_UNO_THREADPOOL_H + +#include "cppu/cppudllapi.h" +#include "sal/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*** + * Thread identifier administration. + ***/ +/** + Establishes an association between the current thread and the given thread identifier. + There can be only one association at a time. The association must be broken by + uno_releaseIdFromCurrentThread(). + This method is in general called by a bridge, that wants to bind a remote threadId + to a new thread. + + @param pThreadId a byte sequence, that contains the identifier of the current thread. + @return true, when the identifier was registered. + false, when the thread has already an identifier. The identifier was not + altered. ( This is in general a bug ). + + @see uno_releaseIdFromCurrentThread() + */ +CPPU_DLLPUBLIC sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId ) + SAL_THROW_EXTERN_C(); + + +/** + Get the identifier of the current thread. + If no id has been bound for the thread before, a new one is generated and bound + to the thread. + For each call to uno_getIdOfCurrentThread(), a call to uno_releaseIdFromCurrentThread() + must be done. + + @param ppThreadId [out] Contains the (acquired) ThreadId. + @see uno_releaseIdFromCurrentThread() + */ +CPPU_DLLPUBLIC void SAL_CALL uno_getIdOfCurrentThread( sal_Sequence **ppThreadId ) + SAL_THROW_EXTERN_C(); + + +/** + If the internal refcount drops to zero, the association between threadId and + thread is broken. + */ +CPPU_DLLPUBLIC void SAL_CALL uno_releaseIdFromCurrentThread() + SAL_THROW_EXTERN_C(); + + +struct _uno_ThreadPool; +typedef struct _uno_ThreadPool * uno_ThreadPool; + +/** + Creates a threadpool handle. Typically each remote bridge instances creates one + handle. + */ +CPPU_DLLPUBLIC uno_ThreadPool SAL_CALL +uno_threadpool_create() SAL_THROW_EXTERN_C(); + + +/** + Makes the current thread known to the threadpool. This function must be + called, BEFORE uno_threadpool_enter() is called and BEFORE a job for this + thread is put into the threadpool (avoid a race between this thread and + an incoming request/reply). + For every call to uno_threadpool_attach, a corresponding call to + uno_threadpool_detach must be done. + + @param hPool The bridge threadpool handle previously created by uno_threadpool_create. + +*/ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_attach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +/** + This method is called to wait for a reply of a previously sent request. This is a + blocking method. uno_threadpool_attach() must have been called before. + + @param hPool the handle that was previously created by uno_threadpool_create(). + @param ppJob [out] the pointer, that was given by uno_threadpool_putJob + 0, when uno_threadpool_dispose() was the reason to fall off from threadpool. + @see uno_threadpool_dispose() + **/ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_enter( uno_ThreadPool hPool , void **ppJob ) + SAL_THROW_EXTERN_C(); + +/** + Detaches the current thread from the threadpool. Must be called for + every call to uno_threadpool_attach. + @param hPool the handle that was previously created by uno_threadpool_create(). +*/ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_detach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +/** + Puts a job into the pool. A job may either be a request or a reply + (replies have a 0 in the doRequest parameter). This function is non-blocking. + + A request may either be synchronous or asynchronous. + If the request is synchronous, it is first looked up, + if there exists a handle with the given + identifier. If this is the case, the thread is woken up and the doRequest + function is called with the given pJob. If no handle exists, + a new thread is created and the given threadId is bound to the new thread. + + If the request is asynchronous, it is put into the queue of asynchronous + requests for the current threadid. The requests are always executed in a new + thread, even if the thread with the given id is waiting in the pool. No id is bound + to the newly created thread. The responsibility is left to the bridge (if it + wishes to bind a name). + + If pJob is a reply, there MUST be a thread with the given threadId waiting + for this reply. + + @param hPool the handle that was previously created by uno_threadpool_create(). + @param pThreadId The Id of the thread, that initialized this request. (In general a + remote threadid). + @param pJob The argument, that doRequest will get or that will be returned by + uno_threadpool_enter(). + @param doRequest The function, that shall be called to execute the request. + 0 if pJob is a reply. + @param bIsOneway True, if the request is asynchronous. False, if it is synchronous. + Set to sal_False, if pJob is a reply. + */ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_putJob( + uno_ThreadPool hPool, + sal_Sequence *pThreadId, + void *pJob, + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), + sal_Bool bIsOneway ) SAL_THROW_EXTERN_C(); + +/** + All threads, that are waiting on the hPool handle, are forced out of the pool. + The threads waiting with uno_threadpool_enter() will return with *ppJob == 0 + + Later calls to uno_threadpool_enter() using the hPool handle will also + return immediately with *ppJob == 0. + + @param hPool The handle to be disposed. + + This function is called i.e. by a bridge, that is forced to dispose itself. + */ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_dispose( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + + +/** Releases the previously with uno_threadpool_create() created handle. + The handle thus becomes invalid. It is an error to use the handle after + uno_threadpool_destroy(). + + A call to uno_threadpool_destroy can synchronously join on spawned worker + threads, so this function must never be called from such a worker thread. + + @see uno_threadpool_create() + */ +CPPU_DLLPUBLIC void SAL_CALL +uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif // INCLUDED_UNO_THREADPOOL_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unoidl/detail/dllapi.hxx b/include/unoidl/detail/dllapi.hxx new file mode 100644 index 000000000..c91327868 --- /dev/null +++ b/include/unoidl/detail/dllapi.hxx @@ -0,0 +1,26 @@ +/* -*- 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_UNOIDL_DETAIL_DLLAPI_HXX +#define INCLUDED_UNOIDL_DETAIL_DLLAPI_HXX + +#include <sal/config.h> + +#include <sal/types.h> + +#if defined LO_DLLIMPLEMENTATION_UNOIDL +#define LO_DLLPUBLIC_UNOIDL SAL_DLLPUBLIC_EXPORT +#else +#define LO_DLLPUBLIC_UNOIDL SAL_DLLPUBLIC_IMPORT +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unoidl/unoidl.hxx b/include/unoidl/unoidl.hxx new file mode 100644 index 000000000..9f61b68a4 --- /dev/null +++ b/include/unoidl/unoidl.hxx @@ -0,0 +1,711 @@ +/* -*- 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_UNOIDL_UNOIDL_HXX +#define INCLUDED_UNOIDL_UNOIDL_HXX + +#include <sal/config.h> + +#include <cassert> +#include <vector> + +#include <osl/mutex.hxx> +#include <rtl/ref.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <salhelper/simplereferenceobject.hxx> +#include <unoidl/detail/dllapi.hxx> + +namespace unoidl { + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL NoSuchFileException final { +public: + SAL_DLLPRIVATE NoSuchFileException(OUString const & uri): uri_(uri) {} + + SAL_DLLPRIVATE NoSuchFileException(NoSuchFileException const & other): + uri_(other.uri_) {} + + SAL_DLLPRIVATE ~NoSuchFileException() throw (); + + const OUString& getUri() const { return uri_; } + +private: + NoSuchFileException& operator =(NoSuchFileException const &) = delete; + + OUString uri_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL FileFormatException final { +public: + SAL_DLLPRIVATE FileFormatException( + OUString const & uri, OUString const & detail): + uri_(uri), detail_(detail) + {} + + SAL_DLLPRIVATE FileFormatException(FileFormatException const & other): + uri_(other.uri_), detail_(other.detail_) + {} + + SAL_DLLPRIVATE ~FileFormatException() throw (); + + const OUString& getUri() const { return uri_; } + + const OUString& getDetail() const { return detail_; } + +private: + FileFormatException& operator =(FileFormatException const &) = delete; + + OUString uri_; + OUString detail_; +}; + +struct AnnotatedReference { + AnnotatedReference( + OUString const & theName, + std::vector< OUString > const & theAnnotations): + name(theName), annotations(theAnnotations) + {} + + OUString name; + + std::vector< OUString > annotations; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL Entity: public salhelper::SimpleReferenceObject { +public: + enum Sort { + SORT_MODULE, SORT_ENUM_TYPE, SORT_PLAIN_STRUCT_TYPE, + SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE, SORT_EXCEPTION_TYPE, + SORT_INTERFACE_TYPE, SORT_TYPEDEF, SORT_CONSTANT_GROUP, + SORT_SINGLE_INTERFACE_BASED_SERVICE, SORT_ACCUMULATION_BASED_SERVICE, + SORT_INTERFACE_BASED_SINGLETON, SORT_SERVICE_BASED_SINGLETON + }; + + Sort getSort() const { return sort_; } + +protected: + explicit SAL_DLLPRIVATE Entity(Sort sort): sort_(sort) {} + + virtual SAL_DLLPRIVATE ~Entity() throw () override; + +private: + Sort sort_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL MapCursor: public salhelper::SimpleReferenceObject { +public: + // throws FileFormatException: + virtual rtl::Reference< Entity > getNext(OUString * name) = 0; + +protected: + SAL_DLLPRIVATE MapCursor() {} + + virtual SAL_DLLPRIVATE ~MapCursor() throw() override; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL ModuleEntity: public Entity { +public: + // throws FileFormatException: + virtual std::vector< OUString > getMemberNames() const = 0; + + // throws FileFormatException: + virtual rtl::Reference< MapCursor > createCursor() const = 0; + +protected: + SAL_DLLPRIVATE ModuleEntity(): Entity(SORT_MODULE) {} + + virtual SAL_DLLPRIVATE ~ModuleEntity() throw () override; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL PublishableEntity: public Entity { +public: + bool isPublished() const { return published_; } + + std::vector< OUString > const & getAnnotations() const + { return annotations_; } + +protected: + SAL_DLLPRIVATE PublishableEntity( + Sort sort, bool published, + std::vector< OUString > const & annotations): + Entity(sort), published_(published), annotations_(annotations) + {} + + virtual SAL_DLLPRIVATE ~PublishableEntity() throw () override; + +private: + bool published_; + + std::vector< OUString > annotations_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL EnumTypeEntity final : public PublishableEntity { +public: + struct Member { + Member( + OUString const & theName, sal_Int32 theValue, + std::vector< OUString > const & theAnnotations): + name(theName), value(theValue), annotations(theAnnotations) + {} + + OUString name; + + sal_Int32 value; + + std::vector< OUString > annotations; + }; + + SAL_DLLPRIVATE EnumTypeEntity( + bool published, std::vector< Member > const & members, + std::vector< OUString > const & annotations): + PublishableEntity(SORT_ENUM_TYPE, published, annotations), + members_(members) + { assert(!members.empty()); } + + std::vector< Member > const & getMembers() const { return members_; } + +private: + virtual SAL_DLLPRIVATE ~EnumTypeEntity() throw () override; + + std::vector< Member > members_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL PlainStructTypeEntity final : public PublishableEntity { +public: + struct Member { + Member(OUString const & theName, OUString const & theType, + std::vector< OUString > const & theAnnotations): + name(theName), type(theType), annotations(theAnnotations) + {} + + OUString name; + + OUString type; + + std::vector< OUString > annotations; + }; + + SAL_DLLPRIVATE PlainStructTypeEntity( + bool published, OUString const & directBase, + std::vector< Member > const & directMembers, + std::vector< OUString > const & annotations): + PublishableEntity(SORT_PLAIN_STRUCT_TYPE, published, annotations), + directBase_(directBase), directMembers_(directMembers) + {} + + const OUString& getDirectBase() const { return directBase_; } + + std::vector< Member > const & getDirectMembers() const + { return directMembers_; } + +private: + virtual SAL_DLLPRIVATE ~PlainStructTypeEntity() throw () override; + + OUString directBase_; + std::vector< Member > directMembers_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL PolymorphicStructTypeTemplateEntity final : + public PublishableEntity +{ +public: + struct Member { + Member( + OUString const & theName, OUString const & theType, + bool theParameterized, + std::vector< OUString > const & theAnnotations): + name(theName), type(theType), parameterized(theParameterized), + annotations(theAnnotations) + {} + + OUString name; + + OUString type; + + bool parameterized; + + std::vector< OUString > annotations; + }; + + SAL_DLLPRIVATE PolymorphicStructTypeTemplateEntity( + bool published, std::vector< OUString > const & typeParameters, + std::vector< Member > const & members, + std::vector< OUString > const & annotations): + PublishableEntity( + SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE, published, annotations), + typeParameters_(typeParameters), members_(members) + {} + + std::vector< OUString > const & getTypeParameters() const + { return typeParameters_; } + + std::vector< Member > const & getMembers() const { return members_; } + +private: + virtual SAL_DLLPRIVATE ~PolymorphicStructTypeTemplateEntity() throw () override; + + std::vector< OUString > typeParameters_; + std::vector< Member > members_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL ExceptionTypeEntity final : public PublishableEntity { +public: + struct Member { + Member( + OUString const & theName, OUString const & theType, + std::vector< OUString > const & theAnnotations): + name(theName), type(theType), annotations(theAnnotations) + {} + + OUString name; + + OUString type; + + std::vector< OUString > annotations; + }; + + SAL_DLLPRIVATE ExceptionTypeEntity( + bool published, OUString const & directBase, + std::vector< Member > const & directMembers, + std::vector< OUString > const & annotations): + PublishableEntity(SORT_EXCEPTION_TYPE, published, annotations), + directBase_(directBase), directMembers_(directMembers) + {} + + const OUString& getDirectBase() const { return directBase_; } + + std::vector< Member > const & getDirectMembers() const + { return directMembers_; } + +private: + virtual SAL_DLLPRIVATE ~ExceptionTypeEntity() throw () override; + + OUString directBase_; + std::vector< Member > directMembers_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL InterfaceTypeEntity final : public PublishableEntity { +public: + struct Attribute { + Attribute( + OUString const & theName, OUString const & theType, + bool theBound, bool theReadOnly, + std::vector< OUString > const & theGetExceptions, + std::vector< OUString > const & theSetExceptions, + std::vector< OUString > const & theAnnotations): + name(theName), type(theType), bound(theBound), + readOnly(theReadOnly), getExceptions(theGetExceptions), + setExceptions(theSetExceptions), annotations(theAnnotations) + { assert(!theReadOnly || theSetExceptions.empty()); } + + OUString name; + + OUString type; + + bool bound; + + bool readOnly; + + std::vector< OUString > getExceptions; + + std::vector< OUString > setExceptions; + + std::vector< OUString > annotations; + }; + + struct Method { + struct Parameter { + enum Direction { DIRECTION_IN, DIRECTION_OUT, DIRECTION_IN_OUT }; + + Parameter( + OUString const & theName, OUString const & theType, + Direction theDirection): + name(theName), type(theType), direction(theDirection) + {} + + OUString name; + + OUString type; + + Direction direction; + }; + + Method( + OUString const & theName, OUString const & theReturnType, + std::vector< Parameter > const & theParameters, + std::vector< OUString > const & theExceptions, + std::vector< OUString > const & theAnnotations): + name(theName), returnType(theReturnType), parameters(theParameters), + exceptions(theExceptions), annotations(theAnnotations) + {} + + OUString name; + + OUString returnType; + + std::vector< Parameter > parameters; + + std::vector< OUString > exceptions; + + std::vector< OUString > annotations; + }; + + SAL_DLLPRIVATE InterfaceTypeEntity( + bool published, + std::vector< AnnotatedReference > const & directMandatoryBases, + std::vector< AnnotatedReference > const & directOptionalBases, + std::vector< Attribute > const & directAttributes, + std::vector< Method > const & directMethods, + std::vector< OUString > const & annotations): + PublishableEntity(SORT_INTERFACE_TYPE, published, annotations), + directMandatoryBases_(directMandatoryBases), + directOptionalBases_(directOptionalBases), + directAttributes_(directAttributes), directMethods_(directMethods) + {} + + std::vector< AnnotatedReference > const & getDirectMandatoryBases() const + { return directMandatoryBases_; } + + std::vector< AnnotatedReference > const & getDirectOptionalBases() const + { return directOptionalBases_; } + + std::vector< Attribute > const & getDirectAttributes() const + { return directAttributes_; } + + std::vector< Method > const & getDirectMethods() const + { return directMethods_; } + +private: + virtual SAL_DLLPRIVATE ~InterfaceTypeEntity() throw () override; + + std::vector< AnnotatedReference > directMandatoryBases_; + std::vector< AnnotatedReference > directOptionalBases_; + std::vector< Attribute > directAttributes_; + std::vector< Method > directMethods_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL TypedefEntity final : public PublishableEntity { +public: + SAL_DLLPRIVATE TypedefEntity( + bool published, OUString const & type, + std::vector< OUString > const & annotations): + PublishableEntity(SORT_TYPEDEF, published, annotations), type_(type) + {} + + const OUString& getType() const { return type_; } + +private: + virtual SAL_DLLPRIVATE ~TypedefEntity() throw () override; + + OUString type_; +}; + +struct SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL ConstantValue { + enum Type { + TYPE_BOOLEAN, TYPE_BYTE, TYPE_SHORT, TYPE_UNSIGNED_SHORT, TYPE_LONG, + TYPE_UNSIGNED_LONG, TYPE_HYPER, TYPE_UNSIGNED_HYPER, TYPE_FLOAT, + TYPE_DOUBLE }; + + ConstantValue(bool value): type(TYPE_BOOLEAN), booleanValue(value) {} + + ConstantValue(sal_Int8 value): type(TYPE_BYTE), byteValue(value) {} + + ConstantValue(sal_Int16 value): type(TYPE_SHORT), shortValue(value) {} + + ConstantValue(sal_uInt16 value): + type(TYPE_UNSIGNED_SHORT), unsignedShortValue(value) + {} + + ConstantValue(sal_Int32 value): type(TYPE_LONG), longValue(value) {} + + ConstantValue(sal_uInt32 value): + type(TYPE_UNSIGNED_LONG), unsignedLongValue(value) + {} + + ConstantValue(sal_Int64 value): type(TYPE_HYPER), hyperValue(value) {} + + ConstantValue(sal_uInt64 value): + type(TYPE_UNSIGNED_HYPER), unsignedHyperValue(value) + {} + + ConstantValue(float value): type(TYPE_FLOAT), floatValue(value) {} + + ConstantValue(double value): type(TYPE_DOUBLE), doubleValue(value) {} + + Type type; + + union { + bool booleanValue; + sal_Int8 byteValue; + sal_Int16 shortValue; + sal_uInt16 unsignedShortValue; + sal_Int32 longValue; + sal_uInt32 unsignedLongValue; + sal_Int64 hyperValue; + sal_uInt64 unsignedHyperValue; + float floatValue; + double doubleValue; + }; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL ConstantGroupEntity final : public PublishableEntity { +public: + struct Member { + Member( + OUString const & theName, ConstantValue const & theValue, + std::vector< OUString > const & theAnnotations): + name(theName), value(theValue), annotations(theAnnotations) + {} + + OUString name; + + ConstantValue value; + + std::vector< OUString > annotations; + }; + + SAL_DLLPRIVATE ConstantGroupEntity( + bool published, std::vector< Member > const & members, + std::vector< OUString > const & annotations): + PublishableEntity(SORT_CONSTANT_GROUP, published, annotations), + members_(members) + {} + + std::vector< Member > const & getMembers() const { return members_; } + +private: + virtual SAL_DLLPRIVATE ~ConstantGroupEntity() throw () override; + + std::vector< Member > members_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL SingleInterfaceBasedServiceEntity final : + public PublishableEntity +{ +public: + struct Constructor { + struct Parameter { + Parameter( + OUString const & theName, OUString const & theType, + bool theRest): + name(theName), type(theType), rest(theRest) + {} + + OUString name; + + OUString type; + + bool rest; + }; + + Constructor(): + defaultConstructor(true) {} + + Constructor( + OUString const & theName, + std::vector< Parameter > const & theParameters, + std::vector< OUString > const & theExceptions, + std::vector< OUString > const & theAnnotations): + name(theName), parameters(theParameters), exceptions(theExceptions), + annotations(theAnnotations), defaultConstructor(false) + {} + + OUString name; + + std::vector< Parameter > parameters; + + std::vector< OUString > exceptions; + + std::vector< OUString > annotations; + + bool defaultConstructor; + }; + + SAL_DLLPRIVATE SingleInterfaceBasedServiceEntity( + bool published, OUString const & base, + std::vector< Constructor > const & constructors, + std::vector< OUString > const & annotations): + PublishableEntity( + SORT_SINGLE_INTERFACE_BASED_SERVICE, published, annotations), + base_(base), constructors_(constructors) + {} + + const OUString& getBase() const { return base_; } + + std::vector< Constructor > const & getConstructors() const + { return constructors_; } + +private: + virtual SAL_DLLPRIVATE ~SingleInterfaceBasedServiceEntity() throw () override; + + OUString base_; + std::vector< Constructor > constructors_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL AccumulationBasedServiceEntity final : + public PublishableEntity +{ +public: + struct Property { + enum Attributes { + ATTRIBUTE_MAYBE_VOID = 0x001, + ATTRIBUTE_BOUND = 0x002, + ATTRIBUTE_CONSTRAINED = 0x004, + ATTRIBUTE_TRANSIENT = 0x008, + ATTRIBUTE_READ_ONLY = 0x010, + ATTRIBUTE_MAYBE_AMBIGUOUS = 0x020, + ATTRIBUTE_MAYBE_DEFAULT = 0x040, + ATTRIBUTE_REMOVABLE = 0x080, + ATTRIBUTE_OPTIONAL = 0x100 + }; + + Property( + OUString const & theName, OUString const & theType, + Attributes theAttributes, + std::vector< OUString > const & theAnnotations): + name(theName), type(theType), attributes(theAttributes), + annotations(theAnnotations) + {} + + OUString name; + + OUString type; + + Attributes attributes; + + std::vector< OUString > annotations; + }; + + SAL_DLLPRIVATE AccumulationBasedServiceEntity( + bool published, + std::vector< AnnotatedReference > const & directMandatoryBaseServices, + std::vector< AnnotatedReference > const & directOptionalBaseServices, + std::vector< AnnotatedReference > const & directMandatoryBaseInterfaces, + std::vector< AnnotatedReference > const & directOptionalBaseInterfaces, + std::vector< Property > const & directProperties, + std::vector< OUString > const & annotations): + PublishableEntity( + SORT_ACCUMULATION_BASED_SERVICE, published, annotations), + directMandatoryBaseServices_(directMandatoryBaseServices), + directOptionalBaseServices_(directOptionalBaseServices), + directMandatoryBaseInterfaces_(directMandatoryBaseInterfaces), + directOptionalBaseInterfaces_(directOptionalBaseInterfaces), + directProperties_(directProperties) + {} + + std::vector< AnnotatedReference > const & getDirectMandatoryBaseServices() + const + { return directMandatoryBaseServices_; } + + std::vector< AnnotatedReference > const & getDirectOptionalBaseServices() + const + { return directOptionalBaseServices_; } + + std::vector< AnnotatedReference > const & getDirectMandatoryBaseInterfaces() + const + { return directMandatoryBaseInterfaces_; } + + std::vector< AnnotatedReference > const & getDirectOptionalBaseInterfaces() + const + { return directOptionalBaseInterfaces_; } + + std::vector< Property > const & getDirectProperties() const + { return directProperties_; } + +private: + virtual SAL_DLLPRIVATE ~AccumulationBasedServiceEntity() throw () override; + + std::vector< AnnotatedReference > directMandatoryBaseServices_; + std::vector< AnnotatedReference > directOptionalBaseServices_; + std::vector< AnnotatedReference > directMandatoryBaseInterfaces_; + std::vector< AnnotatedReference > directOptionalBaseInterfaces_; + std::vector< Property > directProperties_; +}; + +class LO_DLLPUBLIC_UNOIDL InterfaceBasedSingletonEntity final : + public PublishableEntity +{ +public: + SAL_DLLPRIVATE InterfaceBasedSingletonEntity( + bool published, OUString const & base, + std::vector< OUString > const & annotations): + PublishableEntity( + SORT_INTERFACE_BASED_SINGLETON, published, annotations), + base_(base) + {} + + const OUString& getBase() const { return base_; } + +private: + virtual SAL_DLLPRIVATE ~InterfaceBasedSingletonEntity() throw () override; + + OUString base_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL ServiceBasedSingletonEntity final : public PublishableEntity +{ +public: + SAL_DLLPRIVATE ServiceBasedSingletonEntity( + bool published, OUString const & base, + std::vector< OUString > const & annotations): + PublishableEntity(SORT_SERVICE_BASED_SINGLETON, published, annotations), + base_(base) + {} + + const OUString& getBase() const { return base_; } + +private: + virtual SAL_DLLPRIVATE ~ServiceBasedSingletonEntity() throw () override; + + OUString base_; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL Provider: public salhelper::SimpleReferenceObject { +public: + // throws FileFormatException: + virtual rtl::Reference< MapCursor > createRootCursor() const = 0; + + // throws FileFormatException: + virtual rtl::Reference< Entity > findEntity(OUString const & name) + const = 0; + +protected: + SAL_DLLPRIVATE Provider() {} + + virtual SAL_DLLPRIVATE ~Provider() throw () override; +}; + +class SAL_WARN_UNUSED LO_DLLPUBLIC_UNOIDL Manager final : public salhelper::SimpleReferenceObject { +public: + Manager() {} + + // throws FileFormatException, NoSuchFileException: + rtl::Reference< Provider > addProvider(OUString const & uri); + + // throws FileFormatException: + rtl::Reference< Entity > findEntity(OUString const & name) const; + + // throws FileFormatException: + rtl::Reference< MapCursor > createCursor(OUString const & name) const; + +private: + virtual SAL_DLLPRIVATE ~Manager() throw () override; + + SAL_DLLPRIVATE rtl::Reference< Provider > loadProvider( + OUString const & uri); + + mutable osl::Mutex mutex_; + std::vector< rtl::Reference< Provider > > providers_; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotest/bootstrapfixturebase.hxx b/include/unotest/bootstrapfixturebase.hxx new file mode 100644 index 000000000..85f270b02 --- /dev/null +++ b/include/unotest/bootstrapfixturebase.hxx @@ -0,0 +1,75 @@ +/* -*- 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_UNOTEST_BOOTSTRAPFIXTUREBASE_HXX +#define INCLUDED_UNOTEST_BOOTSTRAPFIXTUREBASE_HXX + +#include <sal/config.h> + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <unotest/detail/unotestdllapi.hxx> +#include <unotest/directories.hxx> + +// For cppunit < 1.15.0. +#ifndef CPPUNIT_TEST_FIXTURE +#define CPPUNIT_TEST_FIXTURE(TestClass, TestName) \ + class TestName : public TestClass \ + { \ + public: \ + void TestBody(); \ + CPPUNIT_TEST_SUITE(TestName); \ + CPPUNIT_TEST(TestBody); \ + CPPUNIT_TEST_SUITE_END(); \ + }; \ + CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \ + void TestName::TestBody() +#endif + +namespace test { + +// Class to do lots of heavy-lifting UNO & environment +// bootstrapping for unit tests, such that we can use +// almost an entire LibreOffice during compile - so +// that we can get pieces of code alone to beat them up. + +// NB. this class is instantiated multiple times during a +// run of unit tests ... +class OOO_DLLPUBLIC_UNOTEST BootstrapFixtureBase : public CppUnit::TestFixture +{ +protected: + Directories m_directories; + css::uno::Reference<css::uno::XComponentContext> m_xContext; + css::uno::Reference<css::lang::XMultiServiceFactory> m_xSFactory; + css::uno::Reference<css::lang::XMultiComponentFactory> m_xFactory; + +public: + BootstrapFixtureBase(); + virtual ~BootstrapFixtureBase() override; + + const css::uno::Reference<css::uno::XComponentContext>& + getComponentContext() const { return m_xContext; } + const css::uno::Reference<css::lang::XMultiServiceFactory>& + getMultiServiceFactory() const { return m_xSFactory; } + + virtual void setUp() override; + virtual void tearDown() override; + +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotest/detail/unotestdllapi.hxx b/include/unotest/detail/unotestdllapi.hxx new file mode 100644 index 000000000..b89013912 --- /dev/null +++ b/include/unotest/detail/unotestdllapi.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/. + * + * 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_UNOTEST_DETAIL_UNOTESTDLLAPI_HXX +#define INCLUDED_UNOTEST_DETAIL_UNOTESTDLLAPI_HXX + +#include <sal/config.h> +#include <sal/types.h> + +#if defined OOO_DLLIMPLEMENTATION_UNOTEST +#define OOO_DLLPUBLIC_UNOTEST SAL_DLLPUBLIC_EXPORT +#else +#define OOO_DLLPUBLIC_UNOTEST SAL_DLLPUBLIC_IMPORT +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotest/directories.hxx b/include/unotest/directories.hxx new file mode 100644 index 000000000..5a901c878 --- /dev/null +++ b/include/unotest/directories.hxx @@ -0,0 +1,50 @@ +/* -*- 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_UNOTEST_DIRECTORIES_HXX +#define INCLUDED_UNOTEST_DIRECTORIES_HXX + +#include <sal/config.h> + +#include <rtl/ustring.hxx> +#include <unotest/detail/unotestdllapi.hxx> + +namespace test { + +class OOO_DLLPUBLIC_UNOTEST Directories { +private: + OUString m_aSrcRootURL; + OUString m_aSrcRootPath; + OUString m_aWorkdirRootURL; + OUString m_aWorkdirRootPath; + +public: + Directories(); + + const OUString& getSrcRootURL() const { return m_aSrcRootURL; } + const OUString& getSrcRootPath() const { return m_aSrcRootPath; } + + // return a URL to a given path from the source directory + OUString getURLFromSrc(const OUString& rPath) const; + + // return a Path to a given path from the source directory + OUString getPathFromSrc(const OUString& rPath) const; + + // return a URL to a given path from the workdir directory + OUString getURLFromWorkdir(const OUString &rPath) const; + + // return a Path to a given path from the workdir directory + OUString getPathFromWorkdir(const OUString &rPath) const; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotest/filters-test.hxx b/include/unotest/filters-test.hxx new file mode 100644 index 000000000..5af991e04 --- /dev/null +++ b/include/unotest/filters-test.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/. + */ + +#ifndef INCLUDED_UNOTEST_FILTERS_TEST_HXX +#define INCLUDED_UNOTEST_FILTERS_TEST_HXX + +#include <comphelper/documentconstants.hxx> +#include <rtl/ustring.hxx> +#include <unotest/detail/unotestdllapi.hxx> +#include <sot/formats.hxx> + +namespace test { + +enum filterStatus +{ + fail = 0, + pass = 1, + indeterminate = 2 +}; + +/* + * NOTE, any files beginning with CVE-, BID- or EDB- will be assumed to be + * encrypted using arcfour with key 0x435645, this is to silence panicky + * virus/malware-checkers + * + * e.g. m[de]crypt --bare -a arcfour -o hex -k 435645 -s 3 + */ +/* Implementation of Filters test */ +class OOO_DLLPUBLIC_UNOTEST FiltersTest +{ +public: + void testDir( + //filter name + const OUString &rFilter, + //root dir of test files, must contain pass, fail, indeterminate + const OUString &rURL, + //additional filter data for SfxFilter + const OUString &rUserData = OUString(), + //SfxFilterFlags for SfxFilter + SfxFilterFlags nFilterFlags = SfxFilterFlags::IMPORT, + //Clipboard id for SfxFilter + SotClipboardFormatId nClipboardID = SotClipboardFormatId::NONE, + //additional filter version for SfxFilter + unsigned int nFilterVersion = 0, + //export or import? + bool bExport = false); + + virtual bool load( + const OUString &rFilter, + const OUString &rURL, + const OUString &rUserData, + SfxFilterFlags nFilterFlags, + SotClipboardFormatId nClipboardID, + unsigned int nFilterVersion) = 0; + + virtual bool save( + const OUString &/*rFilter*/, + const OUString &/*rURL*/, + const OUString &/*rUserData*/, + SfxFilterFlags /*nFilterFlags*/, + SotClipboardFormatId /*nClipboardID*/, + unsigned int /*nFilterVersion*/) + { + return true; + } + +protected: + ~FiltersTest() {} + + void recursiveScan( + filterStatus nExpected, + const OUString &rFilter, + const OUString &rURL, + const OUString &rUserData, + SfxFilterFlags nFilterFlags, + SotClipboardFormatId nClipboardID, + unsigned int nFilterVersion, + bool bExport); +}; + +} + +#endif // INCLUDED_UNOTEST_FILTERS_TEST_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotest/gettestargument.hxx b/include/unotest/gettestargument.hxx new file mode 100644 index 000000000..734b77e57 --- /dev/null +++ b/include/unotest/gettestargument.hxx @@ -0,0 +1,38 @@ +/* -*- 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_UNOTEST_GETTESTARGUMENT_HXX +#define INCLUDED_UNOTEST_GETTESTARGUMENT_HXX + +#include <rtl/ustring.hxx> +#include <unotest/detail/unotestdllapi.hxx> + + +namespace test { + +// Obtain the value of a test argument (tunneled in via an "arg-testarg.<name>" +// bootstrap variable): +OOO_DLLPUBLIC_UNOTEST bool getTestArgument( + OUString const & name, OUString * value); + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotest/macros_test.hxx b/include/unotest/macros_test.hxx new file mode 100644 index 000000000..c60ea1fe9 --- /dev/null +++ b/include/unotest/macros_test.hxx @@ -0,0 +1,57 @@ +/* -*- 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_UNOTEST_MACROS_TEST_HXX +#define INCLUDED_UNOTEST_MACROS_TEST_HXX + +#include <sal/config.h> + +#include <memory> +#include <rtl/ustring.hxx> +#include <unotest/detail/unotestdllapi.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/frame/XDesktop2.hpp> + +struct TestMacroInfo +{ + OUString sFileBaseName; + OUString sMacroUrl; +}; + +class BasicDLL; + +namespace unotest { + +class OOO_DLLPUBLIC_UNOTEST MacrosTest +{ +public: + MacrosTest(); + ~MacrosTest(); + + css::uno::Reference< css::lang::XComponent > loadFromDesktop(const OUString& rURL, const OUString& rDocService = OUString(), + const css::uno::Sequence<css::beans::PropertyValue>& rExtra_args = css::uno::Sequence<css::beans::PropertyValue>() ); + + static void + dispatchCommand(const css::uno::Reference<css::lang::XComponent>& xComponent, + const OUString& rCommand, + const css::uno::Sequence<css::beans::PropertyValue>& rPropertyValues); + +protected: + css::uno::Reference< css::frame::XDesktop2> mxDesktop; + +private: + std::unique_ptr<BasicDLL> mpDll; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotest/officeconnection.hxx b/include/unotest/officeconnection.hxx new file mode 100644 index 000000000..553f24b3c --- /dev/null +++ b/include/unotest/officeconnection.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_UNOTEST_OFFICECONNECTION_HXX +#define INCLUDED_UNOTEST_OFFICECONNECTION_HXX + +#include <sal/config.h> + +#include <com/sun/star/uno/Reference.hxx> +#include <osl/process.h> +#include <unotest/detail/unotestdllapi.hxx> + +namespace com::sun::star::uno { + class XComponentContext; +} + +namespace test { + +// Start up and shut down an OOo instance (details about the OOo instance are +// tunneled in via "arg-..." bootstrap variables): +class OOO_DLLPUBLIC_UNOTEST OfficeConnection +{ + OfficeConnection(const OfficeConnection&) = delete; + OfficeConnection& operator=( const OfficeConnection& ) = delete; +public: + OfficeConnection(); + ~OfficeConnection(); + + void setUp(); + + void tearDown(); + + const css::uno::Reference< css::uno::XComponentContext >& + getComponentContext() const { return context_;} + + // Must not be called before setUp or after tearDown: + bool isStillAlive() const; + +private: + oslProcess process_; + css::uno::Reference< css::uno::XComponentContext > + context_; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotest/toabsolutefileurl.hxx b/include/unotest/toabsolutefileurl.hxx new file mode 100644 index 000000000..5bdb7b05e --- /dev/null +++ b/include/unotest/toabsolutefileurl.hxx @@ -0,0 +1,39 @@ +/* -*- 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_UNOTEST_TOABSOLUTEFILEURL_HXX +#define INCLUDED_UNOTEST_TOABSOLUTEFILEURL_HXX + +#include <rtl/ustring.hxx> + +#include <unotest/detail/unotestdllapi.hxx> + + +namespace test { + +// Convert a pathname in system notation, potentially relative to the process's +// current working directory, to an absolute file URL: +OOO_DLLPUBLIC_UNOTEST OUString toAbsoluteFileUrl( + OUString const & relativePathname); + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/ZipPackageHelper.hxx b/include/unotools/ZipPackageHelper.hxx new file mode 100644 index 000000000..f647fed40 --- /dev/null +++ b/include/unotools/ZipPackageHelper.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_ZIPPACKAGEHELPER_HXX +#define INCLUDED_UNOTOOLS_ZIPPACKAGEHELPER_HXX + +#include <config_options.h> +#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 UNLESS_MERGELIBS(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..641740179 --- /dev/null +++ b/include/unotools/accessiblerelationsethelper.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 . + */ + +#ifndef INCLUDED_UNOTOOLS_ACCESSIBLERELATIONSETHELPER_HXX +#define INCLUDED_UNOTOOLS_ACCESSIBLERELATIONSETHELPER_HXX + +#include <unotools/unotoolsdllapi.h> + +#include <com/sun/star/accessibility/XAccessibleRelationSet.hpp> +#include <osl/mutex.hxx> +#include <cppuhelper/implbase.hxx> +#include <memory> + +class AccessibleRelationSetHelperImpl; + +//= 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. + ::osl::Mutex maMutex; + /// The implementation of this helper interface. + std::unique_ptr<AccessibleRelationSetHelperImpl> mpHelperImpl; +}; + +} +//... 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..e8277f648 --- /dev/null +++ b/include/unotools/accessiblestatesethelper.hxx @@ -0,0 +1,144 @@ +/* -*- 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 <osl/mutex.hxx> +#include <cppuhelper/implbase.hxx> +#include <memory> + +class AccessibleStateSetHelperImpl; + +//= 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. + ::osl::Mutex maMutex; + /// The implementation of this helper interface. + std::unique_ptr<AccessibleStateSetHelperImpl> mpHelperImpl; +}; + +} +//... 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..adc26a6ee --- /dev/null +++ b/include/unotools/caserotate.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/. + */ +#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..61a850da9 --- /dev/null +++ b/include/unotools/charclass.hxx @@ -0,0 +1,186 @@ +/* -*- 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 <osl/mutex.hxx> +#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; + mutable ::osl::Mutex aMutex; + + 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, + const LanguageTag& rLanguageTag ); + + /// Deprecated ctor, tries to get a process service manager or to load the + /// library directly. + CharClass( const LanguageTag& rLanguageTag ); + + ~CharClass(); + + /// set a new Locale + void setLanguageTag( const LanguageTag& rLanguageTag ); + + /// get current Locale + const LanguageTag& getLanguageTag() const; + + /// isdigit() on ascii values of entire string + static bool isAsciiNumeric( const OUString& rStr ); + + /// isalpha() on ascii values of entire string + static bool isAsciiAlpha( const OUString& 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..25bae4360 --- /dev/null +++ b/include/unotools/cmdoptions.hxx @@ -0,0 +1,123 @@ +/* -*- 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: + + /*-**************************************************************************************************** + @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(); + + 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..39674470e --- /dev/null +++ b/include/unotools/compatibility.hxx @@ -0,0 +1,238 @@ +/* -*- 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/Sequence.h> +#include <com/sun/star/uno/Any.hxx> +#include <unotools/options.hxx> +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <memory> + +namespace com::sun::star::beans { struct PropertyValue; } +namespace osl { class Mutex; } + +/*-************************************************************************************************************ + @descr Struct to hold information about one compatibility entry +*//*-*************************************************************************************************************/ +class UNOTOOLS_DLLPUBLIC 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 OUString getUserEntryName() + { + return "_user"; + } + + static OUString getDefaultEntryName() + { + return "_default"; + } + + static Index getIndex( const OUString& rName ) + { + for ( int i = static_cast<int>(Index::Name); i < static_cast<int>(Index::INVALID); ++i ) + if ( getName( Index(i) ) == rName ) + return Index(i); + + /* SvtCompatibilityEntry::getIndex() Undeclared compatibility property name */ + assert(false); + + return Index::INVALID; + } + + 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 ) + { + if ( static_cast<size_t>(rIdx) < getElementCount() ) + { + m_aPropertyValue[ static_cast<int>(rIdx) ] = css::uno::Any(rValue); + } else + { + /* Wrong index. */ + assert( false ); + } + } + + bool isDefaultEntry() const + { + return m_bDefaultEntry; + } + + void setDefaultEntry( bool rValue ) + { + m_bDefaultEntry = rValue; + } + + private: + std::vector<css::uno::Any> m_aPropertyValue; + bool m_bDefaultEntry; +}; + +/*-************************************************************************************************************ + @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. + *//*-*****************************************************************************************************/ + css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > 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/compatibilityviewoptions.hxx b/include/unotools/compatibilityviewoptions.hxx new file mode 100644 index 000000000..6030c5834 --- /dev/null +++ b/include/unotools/compatibilityviewoptions.hxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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_SVTOOLS_COMPATIBILITYVIEWOPTIONS_HXX +#define INCLUDED_SVTOOLS_COMPATIBILITYVIEWOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <unotools/options.hxx> + +namespace osl +{ +class Mutex; +} + +class SvtCompatibilityViewOptions_Impl; + +/// Compatibility settings which affects the GUI. These are not document level settings +/// (like SvtCompatibilityOptions), but global options affecting the application's +/// behavior in general. +class UNOTOOLS_DLLPUBLIC SvtCompatibilityViewOptions final : public utl::detail::Options +{ +public: + SvtCompatibilityViewOptions(); + virtual ~SvtCompatibilityViewOptions() override; + + bool HasMSOCompatibleFormsMenu() const; + void SetMSOCompatibleFormsMenu(bool bSet); + +private: + /// Return a reference to a static mutex + UNOTOOLS_DLLPRIVATE static osl::Mutex& GetOwnStaticMutex(); + + std::shared_ptr<SvtCompatibilityViewOptions_Impl> m_pImpl; +}; + +#endif // #ifndef INCLUDED_SVTOOLS_COMPATIBILITYVIEWOPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/unotools/configitem.hxx b/include/unotools/configitem.hxx new file mode 100644 index 000000000..e14aaf0f2 --- /dev/null +++ b/include/unotools/configitem.hxx @@ -0,0 +1,185 @@ +/* -*- 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" + void impl_packLocalizedProperties ( const css::uno::Sequence< OUString >& lInNames , + const css::uno::Sequence< css::uno::Any >& lInValues , + css::uno::Sequence< css::uno::Any >& lOutValues ); + 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(const OUString &rSubTree, + 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;} + }; +}//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..a4d46cb8e --- /dev/null +++ b/include/unotools/configmgr.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_CONFIGMGR_HXX +#define INCLUDED_UNOTOOLS_CONFIGMGR_HXX + +#include <sal/config.h> + +#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); + + 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..ae967660e --- /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 throw(); + + 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 throw(); + + 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 throw(); + + /** 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 throw(); + + /** 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 throw(); + + 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 throw(); + + 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 throw(); + + /// invalidate the object + virtual void clear() throw(); + + // 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 throw(); + + /// checks whether or not a descendent (no matter if direct or indirect) with the given name exists + bool hasByHierarchicalName( const OUString& _rName ) const throw(); + + /// 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() :OConfigurationNode() { } + + /** 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 throw(); + + /// invalidate the object + virtual void clear() throw() 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..d24e8537e --- /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(OUString const& _sNestedPath, + OUString const& _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, + OUString const& _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(OUString const& _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(OUString const& _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..0871edb31 --- /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(const OUString &i_rIn, css::util::DateTime& o_rDateTime); + UNOTOOLS_DLLPUBLIC bool ISO8601parseDate(const OUString &i_rIn, css::util::Date& o_rDate); + UNOTOOLS_DLLPUBLIC bool ISO8601parseTime(const OUString &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..8149361ac --- /dev/null +++ b/include/unotools/defaultoptions.hxx @@ -0,0 +1,44 @@ +/* -*- 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_DEFAULTOPTIONS_HXX +#define INCLUDED_UNOTOOLS_DEFAULTOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <unotools/options.hxx> +#include <memory> + +class SvtDefaultOptions_Impl; + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtDefaultOptions final : public utl::detail::Options +{ +private: + std::shared_ptr<SvtDefaultOptions_Impl> pImpl; + +public: + + SvtDefaultOptions(); + virtual ~SvtDefaultOptions() override; + + OUString GetDefaultPath( sal_uInt16 nId ) const; +}; + +#endif // INCLUDED_UNOTOOLS_DEFAULTOPTIONS_HXX + +/* 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..081bc3660 --- /dev/null +++ b/include/unotools/docinfohelper.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/. + * + * 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..a2bb84e0a --- /dev/null +++ b/include/unotools/dynamicmenuoptions.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_DYNAMICMENUOPTIONS_HXX +#define INCLUDED_UNOTOOLS_DYNAMICMENUOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <com/sun/star/uno/Sequence.h> +#include <unotools/options.hxx> +#include <memory> + +namespace com::sun::star::beans { struct PropertyValue; } +namespace osl { class Mutex; } + +/*-************************************************************************************************************ + @descr The method GetList() returns a list of property values. + Use follow defines to separate values by names. +*//*-*************************************************************************************************************/ +#define DYNAMICMENU_PROPERTYNAME_URL "URL" +#define DYNAMICMENU_PROPERTYNAME_TITLE "Title" +#define DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER "ImageIdentifier" +#define DYNAMICMENU_PROPERTYNAME_TARGETNAME "TargetName" + +/*-************************************************************************************************************ + @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 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 SvtDynamicMenuOptions_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 SvtDynamicMenuOptions final : public utl::detail::Options +{ + public: + SvtDynamicMenuOptions(); + virtual ~SvtDynamicMenuOptions() 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 "eMenu" select right menu. + @return A list of menu items is returned. + + @onerror We return an empty list. + *//*-*****************************************************************************************************/ + + css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > GetMenu( EDynamicMenuType eMenu ) const; + private: + + /*-**************************************************************************************************** + @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(); + + private: + std::shared_ptr<SvtDynamicMenuOptions_Impl> m_pImpl; + +}; // class 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..660ec91b0 --- /dev/null +++ b/include/unotools/eventcfg.hxx @@ -0,0 +1,86 @@ +/* -*- 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/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; + static ::osl::Mutex& GetOwnStaticMutex(); + + 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 ); + + 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..533cc8894 --- /dev/null +++ b/include/unotools/extendedsecurityoptions.hxx @@ -0,0 +1,81 @@ +/* -*- 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_EXTENDEDSECURITYOPTIONS_HXX +#define INCLUDED_UNOTOOLS_EXTENDEDSECURITYOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <unotools/options.hxx> +#include <memory> + +namespace osl { class Mutex; } + +/*-************************************************************************************************************ + @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 SvtExtendedSecurityOptions_Impl; + +/*-************************************************************************************************************ + @short collect information about security features + @ATTENTION This class is partially threadsafe. + + @devstatus ready to use +*//*-*************************************************************************************************************/ + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtExtendedSecurityOptions final : public utl::detail::Options +{ + public: + // Must be zero based! + enum OpenHyperlinkMode + { + OPEN_NEVER = 0, + OPEN_WITHSECURITYCHECK, + }; + + SvtExtendedSecurityOptions(); + virtual ~SvtExtendedSecurityOptions() override; + + OpenHyperlinkMode GetOpenHyperlinkMode() const; + + private: + + /*-**************************************************************************************************** + @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& GetInitMutex(); + + // private member + + private: + std::shared_ptr<SvtExtendedSecurityOptions_Impl> m_pImpl; + +}; // class SvtExtendedSecurityOptions + +#endif // INCLUDED_UNOTOOLS_EXTENDEDSECURITYOPTIONS_HXX + +/* 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..bf457e02b --- /dev/null +++ b/include/unotools/fontcfg.hxx @@ -0,0 +1,185 @@ +/* -*- 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/solar.h> +#include <tools/fontenum.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <o3tl/typed_flags_set.hxx> + +#include <unordered_map> +#include <unordered_set> +#include <vector> + +namespace com::sun::star::container { class XNameAccess; } +namespace com::sun::star::lang { class XMultiServiceFactory; } + +class LanguageTag; + +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_uLong +{ + 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; + + 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..7fbf2cc9c --- /dev/null +++ b/include/unotools/fontcvt.hxx @@ -0,0 +1,60 @@ +/* -*- 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 <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> + + +enum class FontToSubsFontFlags +{ + IMPORT = 0x01, + EXPORT = 0x02 +}; + +typedef void* FontToSubsFontConverter; +UNOTOOLS_DLLPUBLIC FontToSubsFontConverter CreateFontToSubsFontConverter( const OUString& 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..887041f6f --- /dev/null +++ b/include/unotools/fontdefs.hxx @@ -0,0 +1,107 @@ +/* -*- 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 <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( const OUString& rName, SubsFontFlags nFlags ); + +UNOTOOLS_DLLPUBLIC void AddTokenFontName( OUString& rName, const OUString& 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( const OUString& rOrgFontName, const OUString& 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 OUString GetNextFontToken( const OUString& rTokenStr, sal_Int32& rIndex ); +UNOTOOLS_DLLPUBLIC OUString GetEnglishSearchFontName( const OUString& 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(const OUString &rFontName); + +#endif // INCLUDED_UNOTOOLS_FONTDEFS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/fontoptions.hxx b/include/unotools/fontoptions.hxx new file mode 100644 index 000000000..96fff5327 --- /dev/null +++ b/include/unotools/fontoptions.hxx @@ -0,0 +1,86 @@ +/* -*- 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_FONTOPTIONS_HXX +#define INCLUDED_UNOTOOLS_FONTOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <unotools/options.hxx> +#include <memory> + +namespace osl { class Mutex; } + +/*-************************************************************************************************************ + @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 SvtFontOptions_Impl; + +/*-************************************************************************************************************ + @short collect information about font features + @devstatus ready to use +*//*-*************************************************************************************************************/ + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtFontOptions final : public utl::detail::Options +{ + public: + SvtFontOptions(); + virtual ~SvtFontOptions() override; + + /*-**************************************************************************************************** + @short interface methods to get and set value of config key "org.openoffice.Office.Common/Font" + @descr These values defines different states of font handling. + + ..ReplacementTable..() => Determines if the list of font replacements is applied or not. + + ..FontHistory..() => The last 5 fonts will be shown and the last one will be the + first name on the list. These will be displayed in the Font name + combo box on the Object bar. + + ..FontWYSIWYG..() => With this option the names of the selectable fonts + (for example, the fonts in the Font field in the object bar) + will be formatted as the current font. + @onerror No error should occur! + *//*-*****************************************************************************************************/ + + bool IsFontHistoryEnabled ( ) const; + + bool IsFontWYSIWYGEnabled ( ) const; + void EnableFontWYSIWYG ( bool bState ); + private: + + /*-**************************************************************************************************** + @short return a reference to a static mutex + @descr These class use his own static mutex to be threadsafe. + 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& impl_GetOwnStaticMutex(); + private: + std::shared_ptr<SvtFontOptions_Impl> m_pImpl; + +}; // class SvtFontOptions + +#endif // INCLUDED_UNOTOOLS_FONTOPTIONS_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..43c61b667 --- /dev/null +++ b/include/unotools/historyoptions.hxx @@ -0,0 +1,101 @@ +/* -*- 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_HISTORYOPTIONS_HXX +#define INCLUDED_UNOTOOLS_HISTORYOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <com/sun/star/uno/Sequence.h> +#include <rtl/ustring.hxx> +#include <unotools/options.hxx> +#include <memory> + +#include <optional> + +namespace com::sun::star::beans { struct PropertyValue; } + +// The method GetList() returns a list of property values. +// Use follow defines to separate values by names. + +#define HISTORY_PROPERTYNAME_URL "URL" +#define HISTORY_PROPERTYNAME_FILTER "Filter" +#define HISTORY_PROPERTYNAME_TITLE "Title" +#define HISTORY_PROPERTYNAME_PASSWORD "Password" +#define HISTORY_PROPERTYNAME_THUMBNAIL "Thumbnail" + +/// You can use these enum values to specify right history if you call our interface methods. +enum EHistoryType +{ + ePICKLIST = 0, + eHELPBOOKMARKS = 1 +}; + +class SvtHistoryOptions_Impl; + +/** 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. +*/ +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtHistoryOptions final : public utl::detail::Options +{ +public: + SvtHistoryOptions(); + virtual ~SvtHistoryOptions() override; + + /** Clear complete specified list. + + @param eHistory select right history. + */ + void Clear(EHistoryType eHistory); + + /** Return the complete specified history list. + + @param eHistory select right history. + @return A list of history items is returned. + */ + css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > GetList(EHistoryType eHistory) const; + + /** 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 + */ + void AppendItem(EHistoryType eHistory, + const OUString& sURL, const OUString& sFilter, const OUString& sTitle, + const std::optional<OUString>& sThumbnail); + + /** Delete item from the specified list. + */ + void DeleteItem(EHistoryType eHistory, const OUString& sURL); + +private: + std::shared_ptr<SvtHistoryOptions_Impl> m_pImpl; +}; + +#endif // INCLUDED_UNOTOOLS_HISTORYOPTIONS_HXX + +/* 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..49d1f8bf5 --- /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(const LanguageTag& rLanguageTag); + ~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..eeb5fa6ee --- /dev/null +++ b/include/unotools/itemholderbase.hxx @@ -0,0 +1,98 @@ +/* -*- 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 <osl/mutex.hxx> +#include <unotools/options.hxx> + +struct ItemHolderMutexBase +{ + ::osl::Mutex m_aLock; +}; + +enum class EItem +{ + AccessibilityOptions , // 2 + + CJKOptions , // 2 + CmdOptions , + ColorConfig , // 2 + Compatibility , + CompatibilityView , + CTLOptions , // 2 + + DefaultOptions , + DynamicMenuOptions , + + EventConfig , + ExtendedSecurityOptions , + + FontOptions , + + HelpOptions , // 2 + HistoryOptions , + + LinguConfig , + + MenuOptions , + MiscConfig , // 2 + MiscOptions , + ModuleOptions , + + OptionsDialogOptions , + + PathOptions , + PrintOptions , // 2 + PrintFileOptions , // 2 + PrintWarningOptions , + + SecurityOptions , + SysLocaleOptions , // 2 + + UserOptions , // 2 + + ViewOptionsDialog , + ViewOptionsTabDialog , + ViewOptionsTabPage , + ViewOptionsWindow +}; + +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..b586b688f --- /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( const OUString &rPropertyName ) const; + css::uno::Any + GetProperty( sal_Int32 nPropertyHandle ) const; + + bool SetProperty( const OUString &rPropertyName, + const css::uno::Any &rValue ); + bool SetProperty( sal_Int32 nPropertyHandle, + const css::uno::Any &rValue ); + + void GetOptions( SvtLinguOptions &rOptions ) const; + + bool IsReadOnly( const OUString &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( const OUString &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..23e0cdaae --- /dev/null +++ b/include/unotools/linguprops.hxx @@ -0,0 +1,107 @@ +/* -*- 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_LINGUPROPS_HXX +#define INCLUDED_UNOTOOLS_LINGUPROPS_HXX + +// UNO property names for general options +#define UPN_IS_GERMAN_PRE_REFORM "IsGermanPreReform" /*! deprecated #i91949 !*/ +#define UPN_IS_USE_DICTIONARY_LIST "IsUseDictionaryList" +#define UPN_IS_IGNORE_CONTROL_CHARACTERS "IsIgnoreControlCharacters" +#define UPN_ACTIVE_DICTIONARIES "ActiveDictionaries" + +// UNO property names for SpellChecker +#define UPN_IS_SPELL_UPPER_CASE "IsSpellUpperCase" +#define UPN_IS_SPELL_WITH_DIGITS "IsSpellWithDigits" +#define UPN_IS_SPELL_CAPITALIZATION "IsSpellCapitalization" + +// UNO property names for Hyphenator +#define UPN_HYPH_MIN_LEADING "HyphMinLeading" +#define UPN_HYPH_MIN_TRAILING "HyphMinTrailing" +#define UPN_HYPH_MIN_WORD_LENGTH "HyphMinWordLength" +#define UPN_HYPH_NO_CAPS "HyphNoCaps" + +// UNO property names for Lingu +// (those not covered by the SpellChecker and Hyphenator +// properties and more likely to be used in other modules only) +#define UPN_DEFAULT_LANGUAGE "DefaultLanguage" +#define UPN_DEFAULT_LOCALE "DefaultLocale" +#define UPN_DEFAULT_LOCALE_CJK "DefaultLocale_CJK" +#define UPN_DEFAULT_LOCALE_CTL "DefaultLocale_CTL" +#define UPN_IS_HYPH_AUTO "IsHyphAuto" +#define UPN_IS_HYPH_SPECIAL "IsHyphSpecial" +#define UPN_IS_SPELL_AUTO "IsSpellAuto" +#define UPN_IS_SPELL_HIDE "IsSpellHide" /*! deprecated #i91949 !*/ +#define UPN_IS_SPELL_IN_ALL_LANGUAGES "IsSpellInAllLanguages" /*! deprecated #i91949 !*/ +#define UPN_IS_SPELL_SPECIAL "IsSpellSpecial" +#define UPN_IS_WRAP_REVERSE "IsWrapReverse" +#define UPN_DATA_FILES_CHANGED_CHECK_VALUE "DataFilesChangedCheckValue" + +// UNO property names for text conversion options +#define UPN_ACTIVE_CONVERSION_DICTIONARIES "ActiveConversionDictionaries" +#define UPN_IS_IGNORE_POST_POSITIONAL_WORD "IsIgnorePostPositionalWord" +#define UPN_IS_AUTO_CLOSE_DIALOG "IsAutoCloseDialog" +#define UPN_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST "IsShowEntriesRecentlyUsedFirst" +#define UPN_IS_AUTO_REPLACE_UNIQUE_ENTRIES "IsAutoReplaceUniqueEntries" +#define UPN_IS_DIRECTION_TO_SIMPLIFIED "IsDirectionToSimplified" +#define UPN_IS_USE_CHARACTER_VARIANTS "IsUseCharacterVariants" +#define UPN_IS_TRANSLATE_COMMON_TERMS "IsTranslateCommonTerms" +#define UPN_IS_REVERSE_MAPPING "IsReverseMapping" + +#define UPN_IS_GRAMMAR_AUTO "IsAutoGrammarCheck" +#define UPN_IS_GRAMMAR_INTERACTIVE "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 +#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..7f393d934 --- /dev/null +++ b/include/unotools/localedatawrapper.hxx @@ -0,0 +1,413 @@ +/* -*- 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/readwritemutexguard.hxx> +#include <unotools/unotoolsdllapi.h> +#include <memory> +#include <map> + +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 MeasurementSystem { + Metric, + US +}; + +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 > aReservedWordSeq; + css::uno::Sequence< OUString > aDateAcceptancePatterns; + css::uno::Sequence< sal_Int32 > aGrouping; + // cached items + OUString aLocaleItem[css::i18n::LocaleItem::COUNT2]; + OUString aReservedWord[css::i18n::reservedWords::COUNT]; + OUString aCurrSymbol; + OUString aCurrBankSymbol; + DateOrder nDateOrder; + DateOrder nLongDateOrder; + sal_uInt16 nCurrPositiveFormat; + sal_uInt16 nCurrNegativeFormat; + sal_uInt16 nCurrDigits; + bool bLocaleDataItemValid; + bool bReservedWordValid; + bool bSecondaryCalendarValid; + mutable ::utl::ReadWriteMutex aMutex; + struct SAL_DLLPRIVATE Locale_Compare + { + bool operator()(const css::lang::Locale& rLocale1, const css::lang::Locale& rLocale2) const; + }; + mutable std::map<css::lang::Locale, css::i18n::LocaleDataItem2, Locale_Compare> maDataItemCache; + + // whenever Locale changes + void invalidateData(); + + void getOneLocaleItemImpl( sal_Int16 nItem ); + const OUString& getOneLocaleItem( sal_Int16 nItem ) const; + + void getOneReservedWordImpl( sal_Int16 nWord ); + const OUString& getOneReservedWord( sal_Int16 nWord ) const; + + void getCurrSymbolsImpl(); + void getCurrFormatsImpl(); + + void scanCurrFormatImpl( const OUString& rCode, + sal_Int32 nStart, sal_Int32& nSign, + sal_Int32& nPar, sal_Int32& nNum, + sal_Int32& nBlank, sal_Int32& nSym ) const; + + void getDateOrdersImpl(); + DateOrder scanDateOrderImpl( const OUString& rCode ) const; + + void getDefaultCalendarImpl(); + void getSecondaryCalendarImpl(); + + void ImplAddFormatNum( rtl::OUStringBuffer& rBuf, + sal_Int64 nNumber, sal_uInt16 nDecimals, + bool bUseThousandSep, bool bTrailingZeros ) const; + + void getDigitGroupingImpl(); + +public: + LocaleDataWrapper( + const css::uno::Reference< css::uno::XComponentContext > & rxContext, + const LanguageTag& rLanguageTag + ); + LocaleDataWrapper( + const LanguageTag& rLanguageTag + ); + ~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; } + + /// set a new Locale to request + void setLanguageTag( const LanguageTag& rLanguageTag ); + + /// 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; + css::uno::Sequence< OUString > getReservedWord() const; + css::uno::Sequence< css::lang::Locale > getAllInstalledLocaleNames() const; + css::uno::Sequence< OUString > getDateAcceptancePatterns() const; + + /** Override locale's date acceptance patterns. + An empty sequence resets the patterns to the locale's pattern sequence. + */ + void setDateAcceptancePatterns( const css::uno::Sequence< OUString > & rPatterns ); + + /// same as the wrapper implementation but static + static 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 std::vector< LanguageType > getInstalledLanguageTypes(); + + /// maps the LocaleData string to the International enum + MeasurementSystem mapMeasurementStringToEnum( const OUString& 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( const OUString& 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. */ + 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 rString + 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( const OUString& rString, 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; + DateOrder 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; + + /** The CalendarWrapper already <b>MUST</b> + have loaded a calendar. + @param bTwoDigitYear + <FALSE/> := full year + <TRUE/> := year % 100 + */ + OUString getLongDate( const Date& rDate, + CalendarWrapper& rCal, + bool bTwoDigitYear + ) 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, + const OUString& 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(const OUString& 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( const OUString& 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..bba9ea9a9 --- /dev/null +++ b/include/unotools/mediadescriptor.hxx @@ -0,0 +1,338 @@ +/* -*- 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 const OUString& PROP_ABORTED(); + static const OUString& PROP_ASTEMPLATE(); + static const OUString& PROP_COMPONENTDATA(); + static const OUString& PROP_DOCUMENTSERVICE(); + static const OUString& PROP_ENCRYPTIONDATA(); + static const OUString& PROP_FILENAME(); + static const OUString& PROP_FILTERNAME(); + static const OUString& PROP_FILTERPROVIDER(); + static const OUString& PROP_FILTEROPTIONS(); + static const OUString& PROP_FRAME(); + static const OUString& PROP_FRAMENAME(); + static const OUString& PROP_HIDDEN(); + static const OUString& PROP_INPUTSTREAM(); + static const OUString& PROP_INTERACTIONHANDLER(); + static const OUString& PROP_AUTHENTICATIONHANDLER(); + static const OUString& PROP_JUMPMARK(); + static const OUString& PROP_MACROEXECUTIONMODE(); + static const OUString& PROP_MEDIATYPE(); + static const OUString& PROP_MINIMIZED(); + static const OUString& PROP_NOAUTOSAVE(); + static const OUString& PROP_OPENNEWVIEW(); + static const OUString& PROP_OUTPUTSTREAM(); + static const OUString& PROP_PASSWORD(); + static const OUString& PROP_POSTDATA(); + static const OUString& PROP_PREVIEW(); + static const OUString& PROP_READONLY(); + static const OUString& PROP_REFERRER(); + static const OUString& PROP_REPLACEABLE(); + static const OUString& PROP_SALVAGEDFILE(); + static const OUString& PROP_STATUSINDICATOR(); + static const OUString& PROP_STREAM(); + static const OUString& PROP_STREAMFOROUTPUT(); + static const OUString& PROP_TEMPLATENAME(); + static const OUString& PROP_TITLE(); + static const OUString& PROP_TYPENAME(); + static const OUString& PROP_UCBCONTENT(); + static const OUString& PROP_UPDATEDOCMODE(); + static const OUString& PROP_URL(); + static const OUString& PROP_VERSION(); + static const OUString& PROP_DOCUMENTTITLE(); + static const OUString& PROP_MODEL(); + static const OUString& PROP_VIEWONLY(); + static const OUString& PROP_DOCUMENTBASEURL(); + static const OUString& PROP_SUGGESTEDSAVEASNAME(); + + // 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/misccfg.hxx b/include/unotools/misccfg.hxx new file mode 100644 index 000000000..ffc6b9f7a --- /dev/null +++ b/include/unotools/misccfg.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/. + * + * 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_MISCCFG_HXX +#define INCLUDED_UNOTOOLS_MISCCFG_HXX + +#include <unotools/unotoolsdllapi.h> +#include <unotools/options.hxx> +#include <memory> + +namespace utl +{ +class SfxMiscCfg; +class UNOTOOLS_DLLPUBLIC MiscCfg final : public detail::Options +{ +private: + std::shared_ptr<SfxMiscCfg> m_pImpl; + +public: + MiscCfg( ); + virtual ~MiscCfg( ) override; + + bool IsNotFoundWarning() const; + void SetNotFoundWarning( bool bSet); + + bool IsPaperSizeWarning() const; + void SetPaperSizeWarning(bool bSet); + + bool IsPaperOrientationWarning() const; + void SetPaperOrientationWarning( bool bSet); + + // 0 ... 99 + sal_Int32 GetYear2000() const; + void SetYear2000( sal_Int32 nSet ); +}; + +} + +#endif // _MISCCFG_HXX + +/* 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..969fac8ad --- /dev/null +++ b/include/unotools/moduleoptions.hxx @@ -0,0 +1,179 @@ +/* -*- 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 osl { class Mutex; } +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; + 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 ( const OUString& 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(const OUString& sName); + + /** @short return the corresponding application ID for the given + short name. + */ + static EFactory ClassifyFactoryByShortName(const OUString& 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: + UNOTOOLS_DLLPRIVATE static ::osl::Mutex& impl_GetOwnStaticMutex(); + + 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..f20d2aa59 --- /dev/null +++ b/include/unotools/optionsdlg.hxx @@ -0,0 +1,47 @@ +/* -*- 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_OPTIONSDLG_HXX +#define INCLUDED_UNOTOOLS_OPTIONSDLG_HXX + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> +#include <unotools/options.hxx> + +class SvtOptionsDlgOptions_Impl; + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtOptionsDialogOptions final : public utl::detail::Options +{ +private: + SvtOptionsDlgOptions_Impl* m_pImp; + +public: + SvtOptionsDialogOptions(); + virtual ~SvtOptionsDialogOptions() override; + + bool IsGroupHidden ( const OUString& _rGroup ) const; + bool IsPageHidden ( const OUString& _rPage, + const OUString& _rGroup ) const; + bool IsOptionHidden ( const OUString& _rOption, + const OUString& _rPage, + const OUString& _rGroup ) const; +}; + +#endif + +/* 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..5e68b8fe5 --- /dev/null +++ b/include/unotools/pathoptions.hxx @@ -0,0 +1,135 @@ +/* -*- 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 Paths + { + PATH_ADDIN, + PATH_AUTOCORRECT, + PATH_AUTOTEXT, + PATH_BACKUP, + PATH_BASIC, + PATH_BITMAP, + PATH_CONFIG, + PATH_DICTIONARY, + PATH_FAVORITES, + PATH_FILTER, + PATH_GALLERY, + PATH_GRAPHIC, + PATH_HELP, + PATH_ICONSET, + PATH_LINGUISTIC, + PATH_MODULE, + PATH_PALETTE, + PATH_PLUGIN, + PATH_STORAGE, + PATH_TEMP, + PATH_TEMPLATE, + PATH_USERCONFIG, + PATH_WORK, + PATH_CLASSIFICATION, + PATH_UICONFIG, + PATH_FINGERPRINT, + PATH_NUMBERTEXT, + PATH_COUNT // 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 = PATH_USERCONFIG ); +}; + +#endif // INCLUDED_UNOTOOLS_PATHOPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/unotools/printwarningoptions.hxx b/include/unotools/printwarningoptions.hxx new file mode 100644 index 000000000..176dc9243 --- /dev/null +++ b/include/unotools/printwarningoptions.hxx @@ -0,0 +1,85 @@ +/* -*- 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_PRINTWARNINGOPTIONS_HXX +#define INCLUDED_UNOTOOLS_PRINTWARNINGOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <unotools/options.hxx> +#include <memory> + +namespace osl { class Mutex; } + +/*-************************************************************************************************************ + @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 SvtPrintWarningOptions_Impl; + +/*-************************************************************************************************************ + @short collect information about startup features + @devstatus ready to use +*//*-*************************************************************************************************************/ + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtPrintWarningOptions final : public utl::detail::Options +{ + public: + SvtPrintWarningOptions(); + virtual ~SvtPrintWarningOptions() override; + + /*-**************************************************************************************************** + @short interface methods to get and set value of config key "org.openoffice.Office.Common/Print/Warning..." + @descr These options describe internal states to enable/disable features of installed office. + + @seealso configuration package "org.openoffice.Office.Common/_3D-Engine" + *//*-*****************************************************************************************************/ + + bool IsPaperSize() const; + bool IsPaperOrientation() const; + bool IsTransparency() const; + bool IsModifyDocumentOnPrintingAllowed() const; + + void SetPaperSize( bool bState ); + void SetPaperOrientation( bool bState ); + void SetTransparency( bool bState ); + void SetModifyDocumentOnPrintingAllowed( bool bState ); + + private: + + /*-**************************************************************************************************** + @short return a reference to a static mutex + @descr These class use his own static mutex to be threadsafe. + 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(); + + private: + std::shared_ptr<SvtPrintWarningOptions_Impl> m_pImpl; + +}; // class SvtPrintWarningOptions + +#endif // INCLUDED_UNOTOOLS_PRINTWARNINGOPTIONS_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..3eac0e979 --- /dev/null +++ b/include/unotools/progresshandlerwrap.hxx @@ -0,0 +1,50 @@ +/* -*- 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 > const & 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/readwritemutexguard.hxx b/include/unotools/readwritemutexguard.hxx new file mode 100644 index 000000000..a7c6d5799 --- /dev/null +++ b/include/unotools/readwritemutexguard.hxx @@ -0,0 +1,102 @@ +/* -*- 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_READWRITEMUTEXGUARD_HXX +#define INCLUDED_UNOTOOLS_READWRITEMUTEXGUARD_HXX + +#include <osl/mutex.hxx> +#include <o3tl/typed_flags_set.hxx> + +enum class ReadWriteGuardMode { + ReadOnly = 0x00, + Write = 0x01, + CriticalChange = 0x02 | Write, + BlockCritical = 0x04, // only a block, not a read, exclusive flag! +}; +namespace o3tl { + template<> struct typed_flags<ReadWriteGuardMode> : is_typed_flags<ReadWriteGuardMode, 0x7> {}; +} + +namespace utl { + +class ReadWriteMutex +{ + friend class ReadWriteGuard; + + sal_uInt32 nReadCount; + sal_uInt32 nBlockCriticalCount; + ::osl::Mutex maMutex; + ::osl::Mutex maWriteMutex; + +public: + ReadWriteMutex() + : nReadCount(0) + , nBlockCriticalCount(0) + {} +}; + +/** Enable multiple threads to read simultaneously, but a write blocks all + other reads and writes, and a read blocks any write. + Used in I18N wrappers to be able to maintain a single instance of a wrapper + for the standard Office locale. + NEVER construct a writing guard if there is already a reading guard in the + same context, the following will dead lock EVEN IN THE SAME THREAD! + void foo() + { + ReadWriteGuard aGuard1( aMutex ); + bar(); + } + void bar() + { + // waits forever for aGuard1 + ReadWriteGuard aGuard2( aMutex, ReadWriteGuardMode::nWrite ); + } + */ +class ReadWriteGuard +{ + ReadWriteMutex& rMutex; + ReadWriteGuardMode nMode; +public: + ReadWriteGuard( + ReadWriteMutex& rMutex, + ReadWriteGuardMode nRequestMode = ReadWriteGuardMode::ReadOnly // read only + ); + ~ReadWriteGuard(); + + /** Be careful with this, it does wait for ANY read to complete. + The following will dead lock EVEN IN THE SAME THREAD! + void foo() + { + ReadWriteGuard aGuard1( aMutex ); + bar(); + } + void bar() + { + ReadWriteGuard aGuard2( aMutex ); + aGuard2.changeReadToWrite(); // waits forever for aGuard1 + } + */ + void changeReadToWrite(); +}; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_READWRITEMUTEXGUARD_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..d1c64e399 --- /dev/null +++ b/include/unotools/resmgr.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_RESMGR_HXX +#define INCLUDED_UNOTOOLS_RESMGR_HXX + +#include <unotools/unotoolsdllapi.h> +#include <unotools/syslocale.hxx> +#include <rtl/ustring.hxx> + +class LanguageTag; + +typedef OUString (*ResHookProc)(const OUString& rStr); + +namespace Translate +{ + UNOTOOLS_DLLPUBLIC std::locale Create(const char* pPrefixName, const LanguageTag& rLocale = SvtSysLocale().GetUILanguageTag()); + UNOTOOLS_DLLPUBLIC OUString get(const char* pId, const std::locale &loc); + UNOTOOLS_DLLPUBLIC OUString nget(const char* pId, 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..d1e8f32af --- /dev/null +++ b/include/unotools/saveopt.hxx @@ -0,0 +1,148 @@ +/* -*- 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 <unotools/options.hxx> + +struct SvtLoadSaveOptions_Impl; +class UNOTOOLS_DLLPUBLIC SvtSaveOptions final : public utl::detail::Options +{ + SvtLoadSaveOptions_Impl* pImp; + +public: + + enum class EOption + { + AutoSaveTime, + UseUserData, + Backup, + AutoSave, + AutoSavePrompt, + DocInfSave, + SaveWorkingSet, + SaveDocView, + SaveRelInet, + SaveRelFsys, + DoPrettyPrinting, + WarnAlienFormat, + LoadDocPrinter, + OdfDefaultVersion, + UserAutoSave, + }; + + /** 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 + }; + + SvtSaveOptions(); + virtual ~SvtSaveOptions() override; + + void SetAutoSaveTime( sal_Int32 n ); + sal_Int32 GetAutoSaveTime() const; + + void SetUseUserData( bool b ); + bool IsUseUserData() const; + + void SetBackup( bool b ); + bool IsBackup() const; + + void SetAutoSave( bool b ); + bool IsAutoSave() const; + + void SetAutoSavePrompt( bool b ); + bool IsAutoSavePrompt() const; + + void SetUserAutoSave( bool b ); + bool IsUserAutoSave() const; + + void SetDocInfoSave(bool b); + bool IsDocInfoSave() const; + + void SetSaveWorkingSet( bool b ); + bool IsSaveWorkingSet() const; + + void SetSaveDocView( bool b ); + bool IsSaveDocView() const; + + void SetSaveRelINet( bool b ); + bool IsSaveRelINet() const; + + void SetSaveRelFSys( bool b ); + bool IsSaveRelFSys() const; + + void SetLoadUserSettings(bool b); + bool IsLoadUserSettings() const; + + void SetPrettyPrinting( bool _bEnable ); + bool IsPrettyPrinting( ) const; + + void SetWarnAlienFormat( bool _bEnable ); + bool IsWarnAlienFormat( ) const; + + void SetLoadDocumentPrinter( bool _bEnable ); + bool IsLoadDocumentPrinter( ) const; + + void SetODFDefaultVersion( ODFDefaultVersion eVersion ); + ODFDefaultVersion GetODFDefaultVersion() const; + ODFSaneDefaultVersion GetODFSaneDefaultVersion() const; + + bool IsReadOnly( EOption eOption ) const; +}; + +#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..44b99fdc9 --- /dev/null +++ b/include/unotools/securityoptions.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_SECURITYOPTIONS_HXX +#define INCLUDED_UNOTOOLS_SECURITYOPTIONS_HXX + +#include <unotools/unotoolsdllapi.h> +#include <sal/types.h> +#include <com/sun/star/uno/Sequence.h> +#include <rtl/ustring.hxx> +#include <unotools/options.hxx> +#include <memory> + +namespace osl { class Mutex; } + +/*-************************************************************************************************************ + @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 SvtSecurityOptions_Impl; + +/*-************************************************************************************************************ + @descr These values present modes to handle StarOffice basic scripts. + see GetBasicMode/SetBasicMode() for further information +*//*-*************************************************************************************************************/ + +enum EBasicSecurityMode +{ + eNEVER_EXECUTE = 0, + eFROM_LIST = 1, + eALWAYS_EXECUTE = 2 +}; + +/*-************************************************************************************************************ + @short collect information about security features + @ATTENTION This class is partially threadsafe. + + @devstatus ready to use +*//*-*************************************************************************************************************/ + +class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtSecurityOptions final : public utl::detail::Options +{ + public: + + enum class EOption + { + SecureUrls, + BasicMode, // xmlsec05 deprecated + ExecutePlugins, // xmlsec05 deprecated + Warning, // xmlsec05 deprecated + Confirmation, // xmlsec05 deprecated + DocWarnSaveOrSend, + DocWarnSigning, + DocWarnPrint, + DocWarnCreatePdf, + DocWarnRemovePersonalInfo, + DocWarnRecommendPassword, + MacroSecLevel, + MacroTrustedAuthors, + CtrlClickHyperlink, + BlockUntrustedRefererLinks + }; + + typedef css::uno::Sequence< OUString > Certificate; + + /* + // MT: Doesn't work for sequence... + struct Certificate + { + OUString SubjectName; + OUString SerialNumber; + OUString RawData; + }; + */ + + public: + SvtSecurityOptions(); + virtual ~SvtSecurityOptions() override; + + /*-**************************************************************************************************** + @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! + *//*-*****************************************************************************************************/ + + bool IsReadOnly( EOption eOption ) const; + + /*-**************************************************************************************************** + @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! + *//*-*****************************************************************************************************/ + + css::uno::Sequence< OUString > GetSecureURLs( ) const; + void SetSecureURLs( const css::uno::Sequence< 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! + *//*-*****************************************************************************************************/ + + sal_Int32 GetMacroSecurityLevel ( ) const; + void SetMacroSecurityLevel ( sal_Int32 _nLevel ); + + bool IsMacroDisabled ( ) const; + + /** + Check whether the given uri is either no dangerous macro-execution + URI at all or else the given referer is a trusted source. + */ + bool isSecureMacroUri(OUString const & uri, OUString const & referer) + const; + + /** + Check whether the given referer URI is untrusted, and links + originating from it should not be accessed. + */ + bool isUntrustedReferer(OUString const & referer) const; + + /** + Check whether the given uri is a trusted location. + */ + bool isTrustedLocationUri(OUString const & uri) const; + + bool isTrustedLocationUriForUpdatingLinks(OUString const & uri) const; + + css::uno::Sequence< Certificate > GetTrustedAuthors ( ) const; + void SetTrustedAuthors ( const css::uno::Sequence< Certificate >& rAuthors ); + + // for bool options only! + bool IsOptionSet ( EOption eOption ) const; + void SetOption ( EOption eOption, bool bValue ); + bool IsOptionEnabled ( EOption eOption ) const; + + // xmlsec05 deprecated methods + bool IsExecutePlugins() const; + void SetExecutePlugins( bool bSet ); + EBasicSecurityMode GetBasicMode( ) const; + void SetBasicMode( EBasicSecurityMode eMode ); + bool IsWarningEnabled() const; + void SetWarningEnabled( bool bSet ); + bool IsConfirmationEnabled() const; + void SetConfirmationEnabled( bool bSet ); + + // private methods + + private: + + /*-**************************************************************************************************** + @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& GetInitMutex(); + + // private member + + private: + std::shared_ptr<SvtSecurityOptions_Impl> m_pImpl; + +}; // class SvtSecurityOptions + +#endif // INCLUDED_UNOTOOLS_SECURITYOPTIONS_HXX + +/* 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..169e899ca --- /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 makeAny( 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..05c5a5b45 --- /dev/null +++ b/include/unotools/streamhelper.hxx @@ -0,0 +1,66 @@ +/* -*- 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 <osl/mutex.hxx> +#include <cppuhelper/implbase.hxx> +#include <tools/stream.hxx> + +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> +{ + ::osl::Mutex m_aMutex; + SvLockBytesRef m_xLockBytes; + sal_uInt64 m_nActPos; + sal_Int32 m_nAvailable; // this is typically the chunk(buffer) size + +public: + OInputStreamHelper(const SvLockBytesRef& _xLockBytes, + sal_uInt32 _nAvailable) + :m_xLockBytes(_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; +}; + +} // 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..363c0d69d --- /dev/null +++ b/include/unotools/streamwrap.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_STREAMWRAP_HXX +#define INCLUDED_UNOTOOLS_STREAMWRAP_HXX + +#include <unotools/unotoolsdllapi.h> +#include <osl/mutex.hxx> +#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 <cppuhelper/implbase.hxx> +#include <cppuhelper/implbase1.hxx> +#include <memory> + +class SvStream; + +namespace utl +{ + +// workaround for incremental linking bugs in MSVC2015 +class SAL_DLLPUBLIC_TEMPLATE OInputStreamWrapper_Base : public cppu::WeakImplHelper< css::io::XInputStream > {}; + +/// helper class for wrapping an SvStream into a com.sun.star.io::XInputStream +class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public OInputStreamWrapper_Base +{ +protected: + ::osl::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; + +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( ) throw () override + { OOutputStreamWrapper::acquire(); } + virtual void SAL_CALL release( ) throw () 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..31ca65281 --- /dev/null +++ b/include/unotools/syslocale.hxx @@ -0,0 +1,79 @@ +/* -*- 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; + +namespace osl { class Mutex; } + +/** + 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; + + UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetMutex(); + +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! + */ + const LocaleDataWrapper* GetLocaleDataPtr() const; + const CharClass* GetCharClassPtr() const; + 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..60ae7710c --- /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( const OUString& 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..04a25a1a3 --- /dev/null +++ b/include/unotools/textsearch.hxx @@ -0,0 +1,234 @@ +/* -*- 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 { + namespace sun { + namespace star { + namespace 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, + - pStart 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, const OUString &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..b00248011 --- /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, + const OUString& rFolder, ucbhelper::Content & result) throw(); + +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..fd7bd08cc --- /dev/null +++ b/include/unotools/ucbstreamhelper.hxx @@ -0,0 +1,63 @@ +/* -*- 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 +{ + namespace sun + { + namespace star + { + namespace 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..88f426b2f --- /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..adc5f5055 --- /dev/null +++ b/include/unotools/useroptions.hxx @@ -0,0 +1,102 @@ +/* -*- 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; + + static osl::Mutex& GetInitMutex (); + + // 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..c4e6a38e5 --- /dev/null +++ b/include/unotools/viewoptions.hxx @@ -0,0 +1,261 @@ +/* -*- 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> +#include <unotools/options.hxx> + +namespace com::sun::star::beans { struct NamedValue; } +namespace osl { class Mutex; } + +class SvtViewOptionsBase_Impl; + +/*-************************************************************************************************************ + @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 utl::detail::Options +{ + + // 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 , + const OUString& sViewName ); + virtual ~SvtViewOptions() override; + + /*-**************************************************************************************************** + @short support preload of these config item + @descr Sometimes we need preloading of these configuration data without real using of it. + *//*-*****************************************************************************************************/ + + static void AcquireOptions(); + static void ReleaseOptions(); + + // 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(const OString& 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 methods + + private: + + /*-**************************************************************************************************** + @short return a reference to a static mutex + @descr These class is threadsafe. + We create a static mutex only for one time and use it to protect our refcount and container + member! + @return A reference to a static mutex member. + *//*-*****************************************************************************************************/ + + UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetOwnStaticMutex(); + + // private member + + private: + + /// 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; + + /*Attention + + Don't initialize these static members in these headers! + a) Double defined symbols will be detected ... + b) and unresolved externals exist at linking time. + Do it in your source only. + */ + + static SvtViewOptionsBase_Impl* m_pDataContainer_Dialogs; /// hold data for all dialogs + static sal_Int32 m_nRefCount_Dialogs; + static SvtViewOptionsBase_Impl* m_pDataContainer_TabDialogs; /// hold data for all tab-dialogs + static sal_Int32 m_nRefCount_TabDialogs; + static SvtViewOptionsBase_Impl* m_pDataContainer_TabPages; /// hold data for all tab-pages + static sal_Int32 m_nRefCount_TabPages; + static SvtViewOptionsBase_Impl* m_pDataContainer_Windows; /// hold data for all windows + static sal_Int32 m_nRefCount_Windows; + +}; // class SvtViewOptions + +#endif // INCLUDED_UNOTOOLS_VIEWOPTIONS_HXX + +/* 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: */ |