Skip to content

Commit

Permalink
Adding support - attach type and set language code
Browse files Browse the repository at this point in the history
Removes rarely used headers in windows.h.
  • Loading branch information
bapho-bush committed Mar 28, 2023
1 parent bba636a commit 2ee204e
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 47 deletions.
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 ()

Expand Down
48 changes: 27 additions & 21 deletions include/AddInDefBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/
Expand All @@ -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
/**
Expand All @@ -56,17 +53,17 @@ 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
* @param pVar - new property value
* @return the result of write.
*/
virtual bool ADDIN_API Write(WCHAR_T* wszPropName,
tVariant *pVar) = 0;
tVariant *pVar) = 0;

///Registers profile components
/**
Expand All @@ -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
/**
*/
Expand All @@ -115,27 +112,27 @@ class IAddInDefBase
};

class IAddInDefBaseEx :
public IAddInDefBase
public IAddInDefBase
{
public:
virtual ~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;

virtual bool ADDIN_API Alert(const WCHAR_T* text) = 0;
};

struct IPlatformInfo :
public IInterface
public IInterface
{
enum AppType
{
{
eAppUnknown = -1,
eAppThinClient = 0,
eAppThickClient,
Expand All @@ -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__
78 changes: 53 additions & 25 deletions include/ComponentBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,26 @@ 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
/**
* @param lPropNum - property index (starting with 0)
* @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
/**
* @param lPropNum - property index (starting with 0)
* @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?
/**
Expand All @@ -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
Expand All @@ -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
/**
Expand All @@ -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?
/**
Expand All @@ -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
/**
Expand All @@ -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;
};
///////////////////////////////////////////////////////////////////////////
/**
Expand All @@ -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(){}
Expand All @@ -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__
10 changes: 10 additions & 0 deletions src/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 2ee204e

Please sign in to comment.