From 5017c16a40fec1dfb507a2cdc09bc588c324661e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 25 Sep 2023 14:22:41 +0300 Subject: SmileyAdd: emoji smile pack to be used in parallel to any other smile pack --- plugins/SmileyAdd/src/services.cpp | 2 +- plugins/SmileyAdd/src/smileyroutines.cpp | 14 +++++++++++++- plugins/SmileyAdd/src/smileyroutines.h | 6 ++---- plugins/SmileyAdd/src/smileys.cpp | 27 +++++++++++++++------------ plugins/SmileyAdd/src/smileys.h | 5 +++-- plugins/SmileyAdd/src/stdafx.h | 2 +- 6 files changed, 35 insertions(+), 21 deletions(-) (limited to 'plugins/SmileyAdd/src') diff --git a/plugins/SmileyAdd/src/services.cpp b/plugins/SmileyAdd/src/services.cpp index 4a89feff26..fbbc9398a7 100644 --- a/plugins/SmileyAdd/src/services.cpp +++ b/plugins/SmileyAdd/src/services.cpp @@ -20,7 +20,7 @@ along with this program. If not, see . #include "stdafx.h" -LIST menuHandleArray(5); +static LIST menuHandleArray(5); ///////////////////////////////////////////////////////////////////////////////////////// // Service functions diff --git a/plugins/SmileyAdd/src/smileyroutines.cpp b/plugins/SmileyAdd/src/smileyroutines.cpp index b3b5137712..8e4445796f 100644 --- a/plugins/SmileyAdd/src/smileyroutines.cpp +++ b/plugins/SmileyAdd/src/smileyroutines.cpp @@ -30,7 +30,12 @@ bool g_HiddenTextSupported = true; const GUID IID_ITextDocument = { 0x8CC497C0, 0xA1DF, 0x11CE, { 0x80,0x98,0x00,0xAA,0x00,0x47,0xBE,0x5D } }; -void LookupAllSmileys(SmileyPackType *smileyPack, SmileyPackCType *smileyCPack, const wchar_t *lpstrText, SmileysQueueType &smllist, const bool firstOnly) +static void LookupAllSmileysWorker( + SmileyPackType *smileyPack, + SmileyPackCType *smileyCPack, + const wchar_t *lpstrText, + SmileysQueueType &smllist, + const bool firstOnly) { if (lpstrText == nullptr || *lpstrText == 0) return; @@ -144,6 +149,13 @@ void LookupAllSmileys(SmileyPackType *smileyPack, SmileyPackCType *smileyCPack, delete[] smileys; } +void LookupAllSmileys(SmileyPackType *smileyPack, SmileyPackCType *smileyCPack, const wchar_t *lpstrText, SmileysQueueType &smllist, const bool firstOnly) +{ + LookupAllSmileysWorker(smileyPack, smileyCPack, lpstrText, smllist, firstOnly); + + if (g_pEmoji && smileyPack != g_pEmoji) + LookupAllSmileys(g_pEmoji, smileyCPack, lpstrText, smllist, firstOnly); +} void FindSmileyInText(SmileyPackType *smp, const wchar_t *str, unsigned &first, unsigned &size, SmileyType **sml) { diff --git a/plugins/SmileyAdd/src/smileyroutines.h b/plugins/SmileyAdd/src/smileyroutines.h index 2507afc11e..3fa846c054 100644 --- a/plugins/SmileyAdd/src/smileyroutines.h +++ b/plugins/SmileyAdd/src/smileyroutines.h @@ -20,20 +20,18 @@ along with this program. If not, see . #ifndef _SMILEYROUTINES_ #define _SMILEYROUTINES_ -typedef struct ReplaceSmileyType_tag +struct ReplaceSmileyType { CHARRANGE loc; SmileyType *sml; SmileyCType *smlc; bool ldspace; bool trspace; -} ReplaceSmileyType; +}; // Queue to store smileys found typedef SMOBJLIST SmileysQueueType; - - void LookupAllSmileys(SmileyPackType *smileyPack, SmileyPackCType *smileyCPack, const wchar_t *lpstrText, SmileysQueueType &smllist, const bool firstOnly); void ReplaceSmileys(HWND hwnd, SmileyPackType *smp, SmileyPackCType *smcp, const CHARRANGE &sel, bool useHidden, bool ignoreLast, bool unFreeze, bool fireView = 0); void ReplaceSmileysWithText(HWND hwnd, CHARRANGE &sel, bool keepFrozen); diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index 480cc67db0..6b018f0d8e 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -20,6 +20,7 @@ along with this program. If not, see . #include "stdafx.h" +SmileyPackType *g_pEmoji = nullptr; SmileyPackListType g_SmileyPacks; SmileyCategoryListType g_SmileyCategories; @@ -700,8 +701,11 @@ void SmileyCategoryListType::ClearAndLoadAll(void) { m_pSmileyPackStore->ClearAndFreeAll(); - for (auto &it : m_SmileyCategories) + for (auto &it : m_SmileyCategories) { it->Load(); + if (it->GetName() == L"Emoji") + g_pEmoji = it->GetSmileyPack(); + } } SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(const wchar_t *pwszName) @@ -743,20 +747,19 @@ void SmileyCategoryListType::SaveSettings(void) void SmileyCategoryListType::AddAndLoad(const wchar_t *name, const wchar_t *displayName) { - if (GetSmileyCategory(name) != nullptr) - return; - - AddCategory(name, displayName, smcExt); - - // Load only if other smileys have been loaded already - if (m_SmileyCategories.getCount() > 1) - m_SmileyCategories[m_SmileyCategories.getCount() - 1].Load(); + if (auto *pCategory = AddCategory(name, displayName, smcExt)) + pCategory->Load(); } -void SmileyCategoryListType::AddCategory(const wchar_t *name, const wchar_t *displayName, SmcType typ, const wchar_t *defaultFilename) +SmileyCategoryType* SmileyCategoryListType::AddCategory(const wchar_t *name, const wchar_t *displayName, SmcType typ, const wchar_t *defaultFilename) { - if (GetSmileyCategory(name) == nullptr) - m_SmileyCategories.insert(new SmileyCategoryType(m_pSmileyPackStore, name, displayName, defaultFilename, typ)); + auto *pCategory = GetSmileyCategory(name); + if (pCategory == nullptr) { + pCategory = new SmileyCategoryType(m_pSmileyPackStore, name, displayName, defaultFilename, typ); + m_SmileyCategories.insert(pCategory); + } + + return pCategory; } bool SmileyCategoryListType::DeleteCustomCategory(int index) diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h index e4a45095b7..56a93ab605 100644 --- a/plugins/SmileyAdd/src/smileys.h +++ b/plugins/SmileyAdd/src/smileys.h @@ -283,14 +283,15 @@ class SmileyCategoryListType public: void SetSmileyPackStore(SmileyPackListType *pSPS) { m_pSmileyPackStore = pSPS; } + SmileyCategoryType* AddCategory(const wchar_t *name, const wchar_t *displayName, SmcType typ, const wchar_t *defaultFilename = L""); SmileyCategoryType* GetSmileyCategory(const wchar_t *pwszName); SmileyCategoryType* GetSmileyCategory(unsigned index); - SmileyPackType* GetSmileyPack(const CMStringW &name); + SmileyPackType* GetSmileyPack(const CMStringW &name); + SmileyCategoryVectorType& GetSmileyCategoryList(void) { return m_SmileyCategories; } int NumberOfSmileyCategories(void) { return m_SmileyCategories.getCount(); } - void AddCategory(const wchar_t *name, const wchar_t *displayName, SmcType typ, const wchar_t *defaultFilename = L""); void AddAndLoad(const wchar_t *name, const wchar_t *displayName); void AddAllProtocolsAsCategory(void); void AddAccountAsCategory(PROTOACCOUNT *acc, const CMStringW &defaultFile); diff --git a/plugins/SmileyAdd/src/stdafx.h b/plugins/SmileyAdd/src/stdafx.h index e71104068e..909d296f38 100644 --- a/plugins/SmileyAdd/src/stdafx.h +++ b/plugins/SmileyAdd/src/stdafx.h @@ -90,7 +90,7 @@ extern HANDLE g_hevOptionsChanged; extern HGENMENU hContactMenuItem; extern SmileyCategoryListType g_SmileyCategories; extern SmileyPackListType g_SmileyPacks; -extern LIST menuHandleArray; +extern SmileyPackType *g_pEmoji; #define MODULENAME "SmileyAdd" -- cgit v1.2.3