misc: refactor, take 2

add byte array literals handling

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-04-01 15:18:44 +08:00
parent bde9c85cd9
commit 5c7434ea35
3 changed files with 23 additions and 10 deletions

View File

@ -90,21 +90,34 @@ using NATIVE_EVENT_RESULT_TYPE = long;
# define QUtf8String(str) QString::fromUtf8(str) # define QUtf8String(str) QString::fromUtf8(str)
#endif #endif
#ifndef QU8Str #ifndef FRAMELESSHELPER_BYTEARRAY_LITERAL
# define QU8Str(str) QUtf8String(str) # if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
# define FRAMELESSHELPER_BYTEARRAY_LITERAL(ba) ba##_qba
# else
# define FRAMELESSHELPER_BYTEARRAY_LITERAL(ba) QByteArrayLiteral(ba)
# endif
#endif #endif
#ifndef FRAMELESSHELPER_STRING_LITERAL #ifndef FRAMELESSHELPER_STRING_LITERAL
# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
# define FRAMELESSHELPER_STRING_LITERAL(str) u##str##_qs # define FRAMELESSHELPER_STRING_LITERAL(str) u##str##_qs
# else # else
# define FRAMELESSHELPER_STRING_LITERAL(str) QStringLiteral(str) # define FRAMELESSHELPER_STRING_LITERAL(str) QStringLiteral(str)
# endif # endif
#endif #endif
#ifndef FRAMELESSHELPER_BYTEARRAY_CONSTANT2
# define FRAMELESSHELPER_BYTEARRAY_CONSTANT2(name, ba) \
[[maybe_unused]] static const auto k##name = FRAMELESSHELPER_BYTEARRAY_LITERAL(ba);
#endif
#ifndef FRAMELESSHELPER_STRING_CONSTANT2 #ifndef FRAMELESSHELPER_STRING_CONSTANT2
# define FRAMELESSHELPER_STRING_CONSTANT2(name, str) \ # define FRAMELESSHELPER_STRING_CONSTANT2(name, str) \
[[maybe_unused]] static const QString k##name = FRAMELESSHELPER_STRING_LITERAL(str); [[maybe_unused]] static const auto k##name = FRAMELESSHELPER_STRING_LITERAL(str);
#endif
#ifndef FRAMELESSHELPER_BYTEARRAY_CONSTANT
# define FRAMELESSHELPER_BYTEARRAY_CONSTANT(ba) FRAMELESSHELPER_BYTEARRAY_CONSTANT2(ba, #ba)
#endif #endif
#ifndef FRAMELESSHELPER_STRING_CONSTANT #ifndef FRAMELESSHELPER_STRING_CONSTANT
@ -112,7 +125,7 @@ using NATIVE_EVENT_RESULT_TYPE = long;
#endif #endif
#ifndef FRAMELESSHELPER_NAMESPACE #ifndef FRAMELESSHELPER_NAMESPACE
# define FRAMELESSHELPER_NAMESPACE __flh_ns # define FRAMELESSHELPER_NAMESPACE __wwx190_flh_ns
#endif #endif
#ifndef FRAMELESSHELPER_BEGIN_NAMESPACE #ifndef FRAMELESSHELPER_BEGIN_NAMESPACE

View File

@ -52,8 +52,8 @@ struct Win32Helper
Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
static const QByteArray kWin32MessageTypeName = QByteArrayLiteral("windows_generic_MSG"); FRAMELESSHELPER_BYTEARRAY_CONSTANT2(Win32MessageTypeName, "windows_generic_MSG")
static const QString qThemeSettingChangeEventName = QU8Str(kThemeSettingChangeEventName); static const QString qThemeSettingChangeEventName = QUtf8String(kThemeSettingChangeEventName);
FRAMELESSHELPER_STRING_CONSTANT(MonitorFromWindow) FRAMELESSHELPER_STRING_CONSTANT(MonitorFromWindow)
FRAMELESSHELPER_STRING_CONSTANT(GetMonitorInfoW) FRAMELESSHELPER_STRING_CONSTANT(GetMonitorInfoW)
FRAMELESSHELPER_STRING_CONSTANT(ScreenToClient) FRAMELESSHELPER_STRING_CONSTANT(ScreenToClient)

View File

@ -70,9 +70,9 @@ struct Win32UtilsHelper
Q_GLOBAL_STATIC(Win32UtilsHelper, g_utilsHelper) Q_GLOBAL_STATIC(Win32UtilsHelper, g_utilsHelper)
static const QString qDwmRegistryKey = QU8Str(kDwmRegistryKey); static const QString qDwmRegistryKey = QUtf8String(kDwmRegistryKey);
static const QString qPersonalizeRegistryKey = QU8Str(kPersonalizeRegistryKey); static const QString qPersonalizeRegistryKey = QUtf8String(kPersonalizeRegistryKey);
static const QString qDwmColorKeyName = QU8Str(kDwmColorKeyName); static const QString qDwmColorKeyName = QUtf8String(kDwmColorKeyName);
FRAMELESSHELPER_STRING_CONSTANT2(SuccessMessageText, "The operation completed successfully.") FRAMELESSHELPER_STRING_CONSTANT2(SuccessMessageText, "The operation completed successfully.")
FRAMELESSHELPER_STRING_CONSTANT2(FormatMessageEmptyResult, "\"FormatMessageW()\" returned empty string.") FRAMELESSHELPER_STRING_CONSTANT2(FormatMessageEmptyResult, "\"FormatMessageW()\" returned empty string.")
FRAMELESSHELPER_STRING_CONSTANT2(ErrorMessageTemplate, "Function \"%1()\" failed with error code %2: %3.") FRAMELESSHELPER_STRING_CONSTANT2(ErrorMessageTemplate, "Function \"%1()\" failed with error code %2: %3.")