Skip to content

Commit b2c4b73

Browse files
committed
Adding support - attach type and set language code
Removes rarely used headers in windows.h.
1 parent bba636a commit b2c4b73

File tree

6 files changed

+89
-12
lines changed

6 files changed

+89
-12
lines changed

CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ project(SampleAddIn)
33

44
set(CMAKE_CXX_STANDARD 17)
55
set(TARGET SampleAddIn)
6+
set(ATTACH_TYPE "ANY" CACHE STRING "Attach type: ISOLATED | NOT_ISOLATED | ANY (default)")
67

78
option(CASE_INSENSITIVE "Case insensitive method names" OFF)
89
option(STATIC_CRT "Static CRT linkage" OFF)
@@ -27,6 +28,24 @@ endif ()
2728
add_library(${TARGET} SHARED
2829
${SOURCES})
2930

31+
set(ATTACH_TYPE_ANY 0)
32+
set(ATTACH_TYPE_ISOLATED 1)
33+
set(ATTACH_TYPE_NOT_ISOLATED 2)
34+
35+
target_compile_definitions(${TARGET} PRIVATE ATTACH_TYPE_ANY=${ATTACH_TYPE_ANY})
36+
target_compile_definitions(${TARGET} PRIVATE ATTACH_TYPE_ISOLATED=${ATTACH_TYPE_ISOLATED})
37+
target_compile_definitions(${TARGET} PRIVATE ATTACH_TYPE_NOT_ISOLATED=${ATTACH_TYPE_NOT_ISOLATED})
38+
39+
if (${ATTACH_TYPE} STREQUAL "ANY")
40+
set(ATTACH_TYPE ${ATTACH_TYPE_ANY})
41+
elseif (${ATTACH_TYPE} STREQUAL "ISOLATED")
42+
set(ATTACH_TYPE ${ATTACH_TYPE_ISOLATED})
43+
elseif (${ATTACH_TYPE} STREQUAL "NOT_ISOLATED")
44+
set(ATTACH_TYPE ${ATTACH_TYPE_NOT_ISOLATED})
45+
else()
46+
message(FATAL_ERROR "Unrecognized ATTACH_TYPE ${ATTACH_TYPE}")
47+
endif ()
48+
3049
target_compile_definitions(${TARGET} PRIVATE
3150
UNICODE
3251
_UNICODE)
@@ -51,9 +70,10 @@ if (WIN32)
5170
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
5271
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
5372
endif ()
73+
# https://stackoverflow.com/questions/11040133/what-does-defining-win32-lean-and-mean-exclude-exactly
5474
target_compile_definitions(${TARGET} PRIVATE
5575
_WINDOWS
56-
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
76+
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING WIN32_LEAN_AND_MEAN)
5777
target_compile_options(${TARGET} PRIVATE /utf-8)
5878
endif ()
5979

include/AddInDefBase.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ enum Interfaces
1616
{
1717
eIMsgBox = 0,
1818
eIPlatformInfo,
19-
2019
#if defined(__ANDROID__)
21-
2220
eIAndroidComponentHelper,
23-
24-
#endif
25-
21+
#endif
22+
eIAttachedInfo,
2623
};
2724

2825
////////////////////////////////////////////////////////////////////////////////
@@ -155,5 +152,14 @@ struct IPlatformInfo :
155152

156153
virtual const AppInfo* ADDIN_API GetPlatformInfo() = 0;
157154
};
158-
159-
#endif //__ADAPTER_DEF_H__
155+
struct IAttachedInfo :
156+
public IInterface
157+
{
158+
enum AttachedType
159+
{
160+
eAttachedIsolated = 0,
161+
eAttachedNotIsolated,
162+
};
163+
virtual const AttachedType ADDIN_API GetAttachedInfo() = 0;
164+
};
165+
#endif //__ADAPTER_DEF_H__

include/ComponentBase.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,33 @@ class LocaleBase
204204
virtual void ADDIN_API SetLocale(const WCHAR_T* loc) = 0;
205205
};
206206

207+
///////////////////////////////////////////////////////////////////////
208+
/// class UserLanguageBase- интерфейс изменения языка компоненты
209+
/**
210+
* Этот интерфейс предназначен для изменения локализации компоненты
211+
*/
212+
class UserLanguageBase
213+
{
214+
public:
215+
virtual ~UserLanguageBase() {}
216+
/// Изменение локали компоненты
217+
/**
218+
* @param const char16_t* lang - устанавливаемый язык (ru, etc...)
219+
*/
220+
virtual void ADDIN_API SetUserInterfaceLanguageCode(const WCHAR_T* lang) = 0;
221+
};
222+
207223
///////////////////////////////////////////////////////////////////////////
208224
/**
209225
* The given interface is generalized, for its obligatory inheritance
210226
* in implementing components.
211227
*/
212228
/// Base interface describing object as a set of properties and methods.
213229
class IComponentBase :
214-
public IInitDoneBase,
215-
public ILanguageExtenderBase,
216-
public LocaleBase
230+
public IInitDoneBase,
231+
public ILanguageExtenderBase,
232+
public LocaleBase,
233+
public UserLanguageBase
217234
{
218235
public:
219236
virtual ~IComponentBase(){}
@@ -223,7 +240,16 @@ enum AppCapabilities
223240
{
224241
eAppCapabilitiesInvalid = -1,
225242
eAppCapabilities1 = 1,
226-
eAppCapabilitiesLast = eAppCapabilities1,
243+
eAppCapabilities2 = 2,
244+
eAppCapabilities3 = 3,
245+
eAppCapabilitiesLast = eAppCapabilities3,
246+
};
247+
248+
enum AttachType
249+
{
250+
eCanAttachNotIsolated = 1,
251+
eCanAttachIsolated,
252+
eCanAttachAny,
227253
};
228254

229255
/// Announcements of exported functions
@@ -234,10 +260,12 @@ extern "C" long GetClassObject(const WCHAR_T*, IComponentBase** pIntf);
234260
extern "C" long DestroyObject(IComponentBase** pIntf);
235261
extern "C" const WCHAR_T* GetClassNames();
236262
extern "C" AppCapabilities SetPlatformCapabilities(const AppCapabilities capabilities);
263+
extern "C" AttachType GetAttachType();
237264

238265
typedef long (*GetClassObjectPtr)(const WCHAR_T* wsName, IComponentBase** pIntf);
239266
typedef long (*DestroyObjectPtr)(IComponentBase** pIntf);
240267
typedef const WCHAR_T* (*GetClassNamesPtr)();
241268
typedef AppCapabilities (*SetPlatformCapabilitiesPtr)(const AppCapabilities capabilities);
269+
typedef AttachType (*GetAttachTypePtr)();
242270

243271
#endif //__COMPONENT_BASE_H__

src/Component.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,13 @@ std::u16string Component::toUTF16String(std::string_view src) {
464464
return cvt_utf8_utf16.from_bytes(src.data(), src.data() + src.size());
465465
#endif
466466
}
467+
468+
void Component::SetUserInterfaceLanguageCode(const wchar_t *lang) {
469+
#ifdef CASE_INSENSITIVE
470+
try {
471+
std::locale::global(std::locale{toUTF8String(locale)});
472+
} catch (std::runtime_error &) {
473+
std::locale::global(std::locale{""});
474+
}
475+
#endif
476+
}

src/Component.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class Component : public IComponentBase {
9696

9797
bool ADDIN_API CallAsFunc(const long method_num, tVariant *ret_value, tVariant *params,
9898
const long array_size) final;
99+
void ADDIN_API SetUserInterfaceLanguageCode(const wchar_t *lang) final;
99100

100101
protected:
101102
virtual std::string extensionName() = 0;

src/exports.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@ long DestroyObject(IComponentBase **pInterface) {
5656
AppCapabilities SetPlatformCapabilities(const AppCapabilities capabilities) {
5757
return eAppCapabilitiesLast;
5858
}
59+
60+
AttachType GetAttachType() {
61+
#if ATTACH_TYPE == ATTACH_TYPE_ANY
62+
return eCanAttachAny;
63+
#elif ATTACH_TYPE == ATTACH_TYPE_ISOLATED
64+
return eCanAttachIsolated;
65+
#elif ATTACH_TYPE == ATTACH_TYPE_NOT_ISOLATED
66+
return eCanAttachNotIsolated;
67+
#else
68+
#error "Unrecognized ATTACH_TYPE"
69+
#endif
70+
}

0 commit comments

Comments
 (0)