3030#include " npp/NppInterface.h"
3131#include " spellers/HunspellInterface.h"
3232#include " spellers/SpellerContainer.h"
33+ #include " spellers/LanguageInfo.h"
3334#include " ui/AboutDialog.h"
3435#include " ui/AspellOptionsDialog.h"
3536#include " ui/ConnectionSettingsDialog.h"
4142#include " ui/SelectMultipleLanguagesDialog.h"
4243#include " ui/SettingsDialog.h"
4344#include " ui/SuggestionMenuButton.h"
45+ #include " PluginMsg.h"
4446
4547#include < chrono>
4648
@@ -206,6 +208,9 @@ void copy_misspellings_to_clipboard() {
206208 auto str = spell_checker->get_all_misspellings_as_string ();
207209 const size_t len = (str.length () + 1 ) * 2 ;
208210 HGLOBAL h_mem = GlobalAlloc (GMEM_MOVEABLE, len);
211+ if (!h_mem) {
212+ return ;
213+ }
209214 memcpy (GlobalLock (h_mem), str.c_str (), len);
210215 GlobalUnlock (h_mem);
211216 OpenClipboard (nullptr );
@@ -710,8 +715,10 @@ void print_to_log(std::wstring_view line, HWND parent_wnd) {
710715 MessageBox (parent_wnd, L" Error while writing to a log file" , to_wstring (strerror (err)).c_str (), MB_OK);
711716 return ;
712717 }
713- _fwprintf_p (fp, L" %.*s\n " , static_cast <int >(line.length ()), line.data ());
714- fclose (fp);
718+ if (fp) {
719+ _fwprintf_p (fp, L" %.*s\n " , static_cast <int >(line.length ()), line.data ());
720+ fclose (fp);
721+ }
715722}
716723
717724void delete_log () {
@@ -815,8 +822,8 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notify_code) {
815822 if (settings)
816823 print_to_log (L" NPPN_TBMODIFICATION" , npp->get_editor_hwnd ());
817824 add_icons ();
825+ break ;
818826 }
819-
820827 default :
821828 return ;
822829 }
@@ -857,9 +864,31 @@ void init_needed_dialogs(WPARAM w_param) {
857864 }
858865}
859866
867+ bool process_internal_msg (const CommunicationInfo& communication_info) {
868+ switch (communication_info.internalMsg ) {
869+ case DSPELLCHECK_SETLANG_MSG: {
870+ if (const auto info = reinterpret_cast <DSpellCheckSetLangMsgInfo *>(communication_info.info )) {
871+ const auto lang_list = speller_container->active_speller ().get_language_list ();
872+ const auto exists =
873+ std::ranges::find (lang_list, info->lang_name , &LanguageInfo::orig_name) != lang_list.end ();
874+ if (exists) {
875+ auto mut = settings->modify ();
876+ mut->get_active_language () = info->lang_name ;
877+ }
878+ if (info->was_success ) {
879+ *info->was_success = exists;
880+ }
881+ return true ;
882+ }
883+ }
884+ break ;
885+ }
886+ return false ;
887+ }
888+
860889extern " C" __declspec(dllexport) LRESULT
861890// ReSharper disable once CppInconsistentNaming
862- messageProc (UINT message, WPARAM w_param, LPARAM /* l_param*/ ) {
891+ messageProc (UINT message, WPARAM w_param, LPARAM l_param) {
863892 // NOLINT
864893 switch (message) {
865894 case WM_MOVE:
@@ -871,10 +900,14 @@ messageProc(UINT message, WPARAM w_param, LPARAM /*l_param*/) {
871900 init_needed_dialogs (w_param);
872901 context_menu_handler->process_menu_result (w_param);
873902 }
903+ return FALSE ;
904+ }
905+ case NPPM_MSGTOPLUGIN: {
906+ if (const auto info_ptr = reinterpret_cast <const CommunicationInfo *>(l_param))
907+ return process_internal_msg (*info_ptr) ? TRUE : FALSE ;
874908 }
875909 break ;
876910 }
877-
878911 return FALSE ;
879912}
880913
0 commit comments