From 8deb8b449a0f7ed9c9c78cbe94d0850573d76a95 Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Mon, 8 Apr 2024 21:33:55 +0200 Subject: [PATCH] Add DSPELLCHECK_GETLANGUAGELIST_MSG to get language list --- include/PluginMsg.h | 13 ++++++++++--- src/plugin/Plugin.cpp | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/PluginMsg.h b/include/PluginMsg.h index 1c627c9..99fc6ec 100644 --- a/include/PluginMsg.h +++ b/include/PluginMsg.h @@ -1,9 +1,16 @@ #pragma once -#define DSPELLCHECK_SETLANG_MSG 1 +#define DSPELLCHECK_SETLANG_MSG 1 // See DSpellCheckSetLangMsgInfo +#define DSPELLCHECK_GETLANGUAGELIST_MSG 2 // See DSpellCheckGetLanguageListMsgInfo -struct DSpellCheckSetLangMsgInfo -{ +// Set language to lang_name, if was_success non-zero, it will be set to true in case of success and fales in case of failure +struct DSpellCheckSetLangMsgInfo { const wchar_t *lang_name; bool *was_success; // optional out param, pointed bool set to true if language was switched }; + +// language_callback will be called once for each language with payload provided as a second struct element +struct DSpellCheckGetLanguageListMsgInfo { + void (*language_callback)(void *payload, const wchar_t *lang_name); + void *payload; +}; diff --git a/src/plugin/Plugin.cpp b/src/plugin/Plugin.cpp index e1f0f00..937672b 100644 --- a/src/plugin/Plugin.cpp +++ b/src/plugin/Plugin.cpp @@ -898,6 +898,15 @@ bool process_internal_msg(const CommunicationInfo& communication_info) { } } break; + case DSPELLCHECK_GETLANGUAGELIST_MSG: { + if (const auto info = reinterpret_cast(communication_info.info)) { + const auto lang_list = speller_container->active_speller().get_language_list(); + for (auto &lang : lang_list) { + info->language_callback(info->payload, lang.orig_name.c_str()); + } + } + } + return true; } return false; }