diff --git a/CMakeLists.txt b/CMakeLists.txt index bc521ca..c592b11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(SampleAddIn) set(CMAKE_CXX_STANDARD 17) set(TARGET SampleAddIn) +set(ATTACH_TYPE "ANY" CACHE STRING "Attach type: ISOLATED | NOT_ISOLATED | ANY (default)") option(CASE_INSENSITIVE "Case insensitive method names" OFF) option(STATIC_CRT "Static CRT linkage" OFF) @@ -27,6 +28,24 @@ endif () add_library(${TARGET} SHARED ${SOURCES}) +set(ATTACH_TYPE_ANY 0) +set(ATTACH_TYPE_ISOLATED 1) +set(ATTACH_TYPE_NOT_ISOLATED 2) + +target_compile_definitions(${TARGET} PRIVATE ATTACH_TYPE_ANY=${ATTACH_TYPE_ANY}) +target_compile_definitions(${TARGET} PRIVATE ATTACH_TYPE_ISOLATED=${ATTACH_TYPE_ISOLATED}) +target_compile_definitions(${TARGET} PRIVATE ATTACH_TYPE_NOT_ISOLATED=${ATTACH_TYPE_NOT_ISOLATED}) + +if (${ATTACH_TYPE} STREQUAL "ANY") + set(ATTACH_TYPE ${ATTACH_TYPE_ANY}) +elseif (${ATTACH_TYPE} STREQUAL "ISOLATED") + set(ATTACH_TYPE ${ATTACH_TYPE_ISOLATED}) +elseif (${ATTACH_TYPE} STREQUAL "NOT_ISOLATED") + set(ATTACH_TYPE ${ATTACH_TYPE_NOT_ISOLATED}) +else() + message(FATAL_ERROR "Unrecognized ATTACH_TYPE ${ATTACH_TYPE}") +endif () + target_compile_definitions(${TARGET} PRIVATE UNICODE _UNICODE) @@ -51,9 +70,10 @@ if (WIN32) string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") endif () + # https://stackoverflow.com/questions/11040133/what-does-defining-win32-lean-and-mean-exclude-exactly target_compile_definitions(${TARGET} PRIVATE _WINDOWS - _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) + _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING WIN32_LEAN_AND_MEAN) target_compile_options(${TARGET} PRIVATE /utf-8) endif () diff --git a/include/AddInDefBase.h b/include/AddInDefBase.h index 029d5da..ebf8e4b 100644 --- a/include/AddInDefBase.h +++ b/include/AddInDefBase.h @@ -16,18 +16,15 @@ enum Interfaces { eIMsgBox = 0, eIPlatformInfo, - #if defined(__ANDROID__) - eIAndroidComponentHelper, - -#endif - +#endif + eIAttachedInfo, }; //////////////////////////////////////////////////////////////////////////////// /** - * This class serves as representation of a platform for external + * This class serves as representation of a platform for external * components External components use it to communicate with a platform. * */ @@ -45,7 +42,7 @@ class IAddInDefBase * @return the result of */ virtual bool ADDIN_API AddError(unsigned short wcode, const WCHAR_T* source, - const WCHAR_T* descr, long scode) = 0; + const WCHAR_T* descr, long scode) = 0; /// Reads a property value /** @@ -56,9 +53,9 @@ class IAddInDefBase * @return the result of read. */ virtual bool ADDIN_API Read(WCHAR_T* wszPropName, - tVariant* pVal, - long *pErrCode, - WCHAR_T** errDescriptor) = 0; + tVariant* pVal, + long *pErrCode, + WCHAR_T** errDescriptor) = 0; /// Writes a property value /** * @param wszPropName - property name @@ -66,7 +63,7 @@ class IAddInDefBase * @return the result of write. */ virtual bool ADDIN_API Write(WCHAR_T* wszPropName, - tVariant *pVar) = 0; + tVariant *pVar) = 0; ///Registers profile components /** @@ -93,9 +90,9 @@ class IAddInDefBase * @param wszData - message parameters * @return the result of */ - virtual bool ADDIN_API ExternalEvent(WCHAR_T* wszSource, - WCHAR_T* wszMessage, - WCHAR_T* wszData) = 0; + virtual bool ADDIN_API ExternalEvent(WCHAR_T* wszSource, + WCHAR_T* wszMessage, + WCHAR_T* wszData) = 0; /// Clears event buffer /** */ @@ -115,7 +112,7 @@ class IAddInDefBase }; class IAddInDefBaseEx : - public IAddInDefBase + public IAddInDefBase { public: virtual ~IAddInDefBaseEx() {} @@ -123,8 +120,8 @@ class IAddInDefBaseEx : virtual IInterface* ADDIN_API GetInterface(Interfaces iface) = 0; }; -struct IMsgBox : - public IInterface +struct IMsgBox : + public IInterface { virtual bool ADDIN_API Confirm(const WCHAR_T* queryText, tVariant* retVal) = 0; @@ -132,10 +129,10 @@ struct IMsgBox : }; struct IPlatformInfo : - public IInterface + public IInterface { enum AppType - { + { eAppUnknown = -1, eAppThinClient = 0, eAppThickClient, @@ -155,5 +152,14 @@ struct IPlatformInfo : virtual const AppInfo* ADDIN_API GetPlatformInfo() = 0; }; - -#endif //__ADAPTER_DEF_H__ +struct IAttachedInfo : + public IInterface +{ + enum AttachedType + { + eAttachedIsolated = 0, + eAttachedNotIsolated, + }; + virtual const AttachedType ADDIN_API GetAttachedInfo() = 0; +}; +#endif //__ADAPTER_DEF_H__ \ No newline at end of file diff --git a/include/ComponentBase.h b/include/ComponentBase.h index 43199ac..f336f12 100644 --- a/include/ComponentBase.h +++ b/include/ComponentBase.h @@ -80,8 +80,8 @@ class ILanguageExtenderBase * 1 - russian alias. (International alias is required) * @return proeprty name or 0 if it is not found */ - virtual const WCHAR_T* ADDIN_API GetPropName(long lPropNum, - long lPropAlias) = 0; + virtual const WCHAR_T* ADDIN_API GetPropName(long lPropNum, + long lPropAlias) = 0; /// Returns property value /** @@ -89,8 +89,8 @@ class ILanguageExtenderBase * @param pvarPropVal - the pointer to a variable for property value * @return the result of */ - virtual bool ADDIN_API GetPropVal(const long lPropNum, - tVariant* pvarPropVal) = 0; + virtual bool ADDIN_API GetPropVal(const long lPropNum, + tVariant* pvarPropVal) = 0; /// Sets the property value /** @@ -98,8 +98,8 @@ class ILanguageExtenderBase * @param varPropVal - the pointer to a variable for property value * @return the result of */ - virtual bool ADDIN_API SetPropVal(const long lPropNum, - tVariant* varPropVal) = 0; + virtual bool ADDIN_API SetPropVal(const long lPropNum, + tVariant* varPropVal) = 0; /// Is property readable? /** @@ -121,7 +121,7 @@ class ILanguageExtenderBase */ virtual long ADDIN_API GetNMethods() = 0; - /// Finds a method by name + /// Finds a method by name /** * @param wsMethodName - method name * @return - method index @@ -135,8 +135,8 @@ class ILanguageExtenderBase * 1 - russian alias. (International alias is required) * @return method name or 0 if method is not found */ - virtual const WCHAR_T* ADDIN_API GetMethodName(const long lMethodNum, - const long lMethodAlias) = 0; + virtual const WCHAR_T* ADDIN_API GetMethodName(const long lMethodNum, + const long lMethodAlias) = 0; /// Returns number of method parameters /** @@ -152,9 +152,9 @@ class ILanguageExtenderBase * @param pvarParamDefValue - the pointer to a variable for default value * @return the result of */ - virtual bool ADDIN_API GetParamDefValue(const long lMethodNum, - const long lParamNum, - tVariant *pvarParamDefValue) = 0; + virtual bool ADDIN_API GetParamDefValue(const long lMethodNum, + const long lParamNum, + tVariant *pvarParamDefValue) = 0; /// Does the method have a return value? /** @@ -171,8 +171,8 @@ class ILanguageExtenderBase * @return the result of */ virtual bool ADDIN_API CallAsProc(const long lMethodNum, - tVariant* paParams, - const long lSizeArray) = 0; + tVariant* paParams, + const long lSizeArray) = 0; /// Calls the method as a function /** @@ -183,9 +183,9 @@ class ILanguageExtenderBase * @return the result of */ virtual bool ADDIN_API CallAsFunc(const long lMethodNum, - tVariant* pvarRetValue, - tVariant* paParams, - const long lSizeArray) = 0; + tVariant* pvarRetValue, + tVariant* paParams, + const long lSizeArray) = 0; }; /////////////////////////////////////////////////////////////////////////// /** @@ -198,22 +198,39 @@ class LocaleBase virtual ~LocaleBase(){} /// Changes component locale /** - * @param loc - new locale (for Windows - rus_RUS, + * @param loc - new locale (for Windows - rus_RUS, * for Linux - ru_RU, etc...) */ virtual void ADDIN_API SetLocale(const WCHAR_T* loc) = 0; }; +/////////////////////////////////////////////////////////////////////// +/// class UserLanguageBase- интерфейс изменения языка компоненты +/** + * Этот интерфейс предназначен для изменения локализации компоненты + */ +class UserLanguageBase +{ +public: + virtual ~UserLanguageBase() {} + /// Изменение локали компоненты + /** + * @param const char16_t* lang - устанавливаемый язык (ru, etc...) + */ + virtual void ADDIN_API SetUserInterfaceLanguageCode(const WCHAR_T* lang) = 0; +}; + /////////////////////////////////////////////////////////////////////////// /** - * The given interface is generalized, for its obligatory inheritance + * The given interface is generalized, for its obligatory inheritance * in implementing components. */ /// Base interface describing object as a set of properties and methods. class IComponentBase : -public IInitDoneBase, - public ILanguageExtenderBase, - public LocaleBase + public IInitDoneBase, + public ILanguageExtenderBase, + public LocaleBase, + public UserLanguageBase { public: virtual ~IComponentBase(){} @@ -223,21 +240,32 @@ enum AppCapabilities { eAppCapabilitiesInvalid = -1, eAppCapabilities1 = 1, - eAppCapabilitiesLast = eAppCapabilities1, + eAppCapabilities2 = 2, + eAppCapabilities3 = 3, + eAppCapabilitiesLast = eAppCapabilities3, +}; + +enum AttachType +{ + eCanAttachNotIsolated = 1, + eCanAttachIsolated, + eCanAttachAny, }; /// Announcements of exported functions /** - * These functions should be implemented that component can be loaded and created. + * These functions should be implemented that component can be loaded and created. */ extern "C" long GetClassObject(const WCHAR_T*, IComponentBase** pIntf); extern "C" long DestroyObject(IComponentBase** pIntf); extern "C" const WCHAR_T* GetClassNames(); extern "C" AppCapabilities SetPlatformCapabilities(const AppCapabilities capabilities); +extern "C" AttachType GetAttachType(); typedef long (*GetClassObjectPtr)(const WCHAR_T* wsName, IComponentBase** pIntf); typedef long (*DestroyObjectPtr)(IComponentBase** pIntf); typedef const WCHAR_T* (*GetClassNamesPtr)(); typedef AppCapabilities (*SetPlatformCapabilitiesPtr)(const AppCapabilities capabilities); +typedef AttachType (*GetAttachTypePtr)(); -#endif //__COMPONENT_BASE_H__ +#endif //__COMPONENT_BASE_H__ \ No newline at end of file diff --git a/src/Component.cpp b/src/Component.cpp index 7ffcb80..44c7181 100644 --- a/src/Component.cpp +++ b/src/Component.cpp @@ -464,3 +464,13 @@ std::u16string Component::toUTF16String(std::string_view src) { return cvt_utf8_utf16.from_bytes(src.data(), src.data() + src.size()); #endif } + +void Component::SetUserInterfaceLanguageCode(const wchar_t *lang) { +#ifdef CASE_INSENSITIVE + try { + std::locale::global(std::locale{toUTF8String(locale)}); + } catch (std::runtime_error &) { + std::locale::global(std::locale{""}); + } +#endif +} diff --git a/src/Component.h b/src/Component.h index 5797bac..302f729 100644 --- a/src/Component.h +++ b/src/Component.h @@ -96,6 +96,7 @@ class Component : public IComponentBase { bool ADDIN_API CallAsFunc(const long method_num, tVariant *ret_value, tVariant *params, const long array_size) final; + void ADDIN_API SetUserInterfaceLanguageCode(const wchar_t *lang) final; protected: virtual std::string extensionName() = 0; diff --git a/src/exports.cpp b/src/exports.cpp index f315392..f29db4c 100644 --- a/src/exports.cpp +++ b/src/exports.cpp @@ -56,3 +56,15 @@ long DestroyObject(IComponentBase **pInterface) { AppCapabilities SetPlatformCapabilities(const AppCapabilities capabilities) { return eAppCapabilitiesLast; } + +AttachType GetAttachType() { +#if ATTACH_TYPE == ATTACH_TYPE_ANY + return eCanAttachAny; +#elif ATTACH_TYPE == ATTACH_TYPE_ISOLATED + return eCanAttachIsolated; +#elif ATTACH_TYPE == ATTACH_TYPE_NOT_ISOLATED + return eCanAttachNotIsolated; +#else +#error "Unrecognized ATTACH_TYPE" +#endif +} \ No newline at end of file