From 550c3e26b321ffb138d02f02c22e64f3e3044767 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 19 Nov 2014 21:57:43 +0000 Subject: fix for cleaning [u] in release version git-svn-id: http://svn.miranda-ng.org/main/trunk@11024 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SpellChecker/src/RichEdit.cpp | 78 +++++++++++++------------------ plugins/SpellChecker/src/spellchecker.cpp | 34 +++++++------- plugins/SpellChecker/src/utils.cpp | 12 +++-- 3 files changed, 56 insertions(+), 68 deletions(-) diff --git a/plugins/SpellChecker/src/RichEdit.cpp b/plugins/SpellChecker/src/RichEdit.cpp index 53ed48ca30..c76391620a 100644 --- a/plugins/SpellChecker/src/RichEdit.cpp +++ b/plugins/SpellChecker/src/RichEdit.cpp @@ -29,13 +29,11 @@ HWND RichEdit::GetHWND() const void RichEdit::SetHWND(HWND hwnd) { - if (textDocument != NULL) - { + if (textDocument != NULL) { textDocument->Release(); textDocument = NULL; } - if (ole != NULL) - { + if (ole != NULL) { ole->Release(); ole = NULL; } @@ -49,7 +47,7 @@ void RichEdit::SetHWND(HWND hwnd) if (ole == NULL) return; - if (ole->QueryInterface(IID_ITextDocument, (void**) &textDocument) != S_OK) + if (ole->QueryInterface(IID_ITextDocument, (void**)&textDocument) != S_OK) textDocument = NULL; } @@ -65,8 +63,7 @@ bool RichEdit::IsReadOnly() const void RichEdit::SuspendUndo() { - if (textDocument != NULL) - { + if (textDocument != NULL) { textDocument->Undo(tomSuspend, NULL); undoEnabled = FALSE; } @@ -74,8 +71,7 @@ void RichEdit::SuspendUndo() void RichEdit::ResumeUndo() { - if (textDocument != NULL) - { + if (textDocument != NULL) { textDocument->Undo(tomResume, NULL); undoEnabled = TRUE; } @@ -105,16 +101,14 @@ void RichEdit::Start() { stopped--; - if (stopped < 0) - { + if (stopped < 0) { stopped = 0; return; } else if (stopped > 0) return; - if (inverse) - { + if (inverse) { LONG tmp = old_sel.cpMin; old_sel.cpMin = old_sel.cpMax; old_sel.cpMax = tmp; @@ -126,7 +120,6 @@ void RichEdit::Start() SendMessage(WM_SETREDRAW, TRUE, 0); InvalidateRect(hwnd, NULL, FALSE); -// ShowCaret(hwnd); ResumeUndo(); } @@ -149,11 +142,12 @@ int RichEdit::GetLineCount() const void RichEdit::GetLine(int line, TCHAR *text, size_t text_len) const { *((WORD*)text) = WORD(text_len - 1); - unsigned size = (unsigned) SendMessage(EM_GETLINE, (WPARAM) line, (LPARAM)text); + unsigned size = (unsigned)SendMessage(EM_GETLINE, (WPARAM)line, (LPARAM)text); + // Sometimes it likes to return size = lineLen+1, adding an \n at the end, so we remove it here // to make both implementations return same size int lineLen = GetLineLength(line); - size = (unsigned) max(0, min((int)text_len - 1, min((int) size, lineLen))); + size = (unsigned)max(0, min((int)text_len - 1, min((int)size, lineLen))); text[size] = _T('\0'); } @@ -164,7 +158,7 @@ int RichEdit::GetLineLength(int line) const int RichEdit::GetFirstCharOfLine(int line) const { - return SendMessage(EM_LINEINDEX, (WPARAM) line, 0); + return SendMessage(EM_LINEINDEX, (WPARAM)line, 0); } int RichEdit::GetLineFromChar(int charPos) const @@ -200,15 +194,13 @@ TCHAR *RichEdit::GetText(int start, int end) const if (end <= start) end = GetTextLength(); - if (textDocument != NULL) - { + if (textDocument != NULL) { ITextRange *range; - if (textDocument->Range(start, end, &range) != S_OK) + if (textDocument->Range(start, end, &range) != S_OK) return mir_tstrdup(_T("")); BSTR text = NULL; - if (range->GetText(&text) != S_OK || text == NULL) - { + if (range->GetText(&text) != S_OK || text == NULL) { range->Release(); return mir_tstrdup(_T("")); } @@ -221,26 +213,23 @@ TCHAR *RichEdit::GetText(int start, int end) const return ret; } - else - { - int len = GetTextLength(); - TCHAR *tmp = (TCHAR *) mir_alloc(len * sizeof(TCHAR)); - GetWindowText(hwnd, tmp, len); - tmp[len] = 0; - - TCHAR *ret = (TCHAR *) mir_alloc((end - start + 1) * sizeof(TCHAR)); - memmove(ret, &tmp[start], (end - start) * sizeof(TCHAR)); - ret[end - start] = 0; - - mir_free(tmp); - return ret; - } + + int len = GetTextLength(); + TCHAR *tmp = (TCHAR *)mir_alloc(len * sizeof(TCHAR)); + GetWindowText(hwnd, tmp, len); + tmp[len] = 0; + + TCHAR *ret = (TCHAR *)mir_alloc((end - start + 1) * sizeof(TCHAR)); + memmove(ret, &tmp[start], (end - start) * sizeof(TCHAR)); + ret[end - start] = 0; + + mir_free(tmp); + return ret; } void RichEdit::ReplaceSel(const TCHAR *new_text) { - if (stopped) - { + if (stopped) { CHARRANGE sel = GetSel(); ResumeUndo(); @@ -254,10 +243,7 @@ void RichEdit::ReplaceSel(const TCHAR *new_text) SendMessage(WM_SETREDRAW, FALSE, 0); SendMessage(EM_SETEVENTMASK, 0, old_mask & ~ENM_CHANGE); } - else - { - SendMessage(EM_REPLACESEL, undoEnabled, (LPARAM)new_text); - } + else SendMessage(EM_REPLACESEL, undoEnabled, (LPARAM)new_text); } int RichEdit::Replace(int start, int end, const TCHAR *new_text) @@ -265,7 +251,7 @@ int RichEdit::Replace(int start, int end, const TCHAR *new_text) CHARRANGE sel = GetSel(); CHARRANGE replace_sel = { start, end }; SetSel(replace_sel); - + ReplaceSel(new_text); int dif = FixSel(&sel, replace_sel, lstrlen(new_text)); @@ -278,7 +264,7 @@ int RichEdit::Insert(int pos, const TCHAR *text) CHARRANGE sel = GetSel(); CHARRANGE replace_sel = { pos, pos }; SetSel(replace_sel); - + ReplaceSel(text); int dif = FixSel(&sel, replace_sel, lstrlen(text)); @@ -291,7 +277,7 @@ int RichEdit::Delete(int start, int end) CHARRANGE sel = GetSel(); CHARRANGE replace_sel = { start, end }; SetSel(replace_sel); - + ReplaceSel(_T("")); int dif = FixSel(&sel, replace_sel, 0); @@ -302,7 +288,7 @@ int RichEdit::Delete(int start, int end) int RichEdit::FixSel(CHARRANGE *to_fix, CHARRANGE sel_changed, int new_len) { int dif = new_len - (sel_changed.cpMax - sel_changed.cpMin); - + if (to_fix->cpMax <= sel_changed.cpMin) return dif; diff --git a/plugins/SpellChecker/src/spellchecker.cpp b/plugins/SpellChecker/src/spellchecker.cpp index 5884840395..1027a2a732 100644 --- a/plugins/SpellChecker/src/spellchecker.cpp +++ b/plugins/SpellChecker/src/spellchecker.cpp @@ -58,7 +58,7 @@ LIST languages(1); // Functions //////////////////////////////////////////////////////////////////////////// -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { hInst = hinstDLL; return TRUE; @@ -69,7 +69,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD miranda return &pluginInfo; } -static int IconsChanged(WPARAM, LPARAM) +static int IconsChanged(WPARAM, LPARAM) { StatusIconData sid = { sizeof(sid) }; sid.szModule = MODULE_NAME; @@ -103,31 +103,31 @@ static int PreShutdown(WPARAM, LPARAM) } // Called when all the modules are loaded -static int ModulesLoaded(WPARAM, LPARAM) +static int ModulesLoaded(WPARAM, LPARAM) { variables_enabled = ServiceExists(MS_VARS_FORMATSTRING); // Folders plugin support if (hDictionariesFolder = FoldersRegisterCustomPathT(LPGEN("Spell Checker"), LPGEN("Dictionaries"), DICTIONARIES_FOLDER)) { - dictionariesFolder = (TCHAR *) mir_alloc(sizeof(TCHAR) * MAX_PATH); + dictionariesFolder = (TCHAR *)mir_alloc(sizeof(TCHAR) * MAX_PATH); FoldersGetCustomPathT(hDictionariesFolder, dictionariesFolder, MAX_PATH, _T(".")); } else dictionariesFolder = Utils_ReplaceVarsT(DICTIONARIES_FOLDER); if (hCustomDictionariesFolder = FoldersRegisterCustomPathT(LPGEN("Spell Checker"), LPGEN("Custom Dictionaries"), CUSTOM_DICTIONARIES_FOLDER)) { - customDictionariesFolder = (TCHAR *) mir_alloc(sizeof(TCHAR) * MAX_PATH); + customDictionariesFolder = (TCHAR *)mir_alloc(sizeof(TCHAR) * MAX_PATH); FoldersGetCustomPathT(hCustomDictionariesFolder, customDictionariesFolder, MAX_PATH, _T(".")); } else customDictionariesFolder = Utils_ReplaceVarsT(CUSTOM_DICTIONARIES_FOLDER); - + if (hFlagsDllFolder = FoldersRegisterCustomPathT(LPGEN("Spell Checker"), LPGEN("Flags DLL"), FLAGS_DLL_FOLDER)) { - flagsDllFolder = (TCHAR *) mir_alloc(sizeof(TCHAR) * MAX_PATH); + flagsDllFolder = (TCHAR *)mir_alloc(sizeof(TCHAR) * MAX_PATH); FoldersGetCustomPathT(hFlagsDllFolder, flagsDllFolder, MAX_PATH, _T(".")); } else flagsDllFolder = Utils_ReplaceVarsT(FLAGS_DLL_FOLDER); InitOptions(); - + GetAvaibleDictionaries(languages, dictionariesFolder, customDictionariesFolder); LoadOptions(); @@ -146,7 +146,7 @@ static int ModulesLoaded(WPARAM, LPARAM) sid.ptszSection = LPGENT("Spell Checker")_T("/")LPGENT("Flags"); // Get language flags - for(int i = 0; i < languages.getCount(); i++) { + for (int i = 0; i < languages.getCount(); i++) { Dictionary *p = languages[i]; sid.ptszDescription = p->full_name; @@ -172,7 +172,7 @@ static int ModulesLoaded(WPARAM, LPARAM) // Oki, lets add to IcoLib, then p->hIcolib = Skin_AddIcon(&sid); - + if (hFlag != NULL) DestroyIcon(hFlag); else @@ -206,7 +206,7 @@ static int ModulesLoaded(WPARAM, LPARAM) sid.dwId = i; TCHAR tmp[128]; - mir_sntprintf(tmp, SIZEOF(tmp), _T("%s - %s"), + mir_sntprintf(tmp, SIZEOF(tmp), _T("%s - %s"), TranslateT("Spell Checker"), languages[i]->full_name); sid.tszTooltip = tmp; sid.hIcon = (opts.use_flags) ? Skin_GetIconByHandle(languages[i]->hIcolib) : Skin_GetIcon("spellchecker_enabled"); @@ -217,9 +217,9 @@ static int ModulesLoaded(WPARAM, LPARAM) hkd.pszName = "Spell Checker/Toggle"; hkd.pszSection = LPGEN("Spell Checker"); hkd.pszDescription = LPGEN("Enable/disable spell checker"); - hkd.DefHotKey = HOTKEYCODE(HOTKEYF_SHIFT|HOTKEYF_ALT, 'S'); + hkd.DefHotKey = HOTKEYCODE(HOTKEYF_SHIFT | HOTKEYF_ALT, 'S'); hkd.lParam = HOTKEY_ACTION_TOGGLE; - Hotkey_Register( &hkd); + Hotkey_Register(&hkd); loaded = TRUE; @@ -230,12 +230,12 @@ static int ModulesLoaded(WPARAM, LPARAM) static IconItem iconList[] = { - { LPGEN("Enabled"), "spellchecker_enabled", IDI_CHECK }, + { LPGEN("Enabled"), "spellchecker_enabled", IDI_CHECK }, { LPGEN("Disabled"), "spellchecker_disabled", IDI_NO_CHECK }, { LPGEN("Unknown"), "spellchecker_unknown", IDI_UNKNOWN_FLAG } }; -extern "C" int __declspec(dllexport) Load(void) +extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); @@ -249,7 +249,7 @@ extern "C" int __declspec(dllexport) Load(void) CreateServiceFunction(MS_SPELLCHECKER_ADD_RICHEDIT, AddContactTextBoxService); CreateServiceFunction(MS_SPELLCHECKER_REMOVE_RICHEDIT, RemoveContactTextBoxService); CreateServiceFunction(MS_SPELLCHECKER_SHOW_POPUP_MENU, ShowPopupMenuService); - + hCheckedBmp = LoadBitmap(NULL, MAKEINTRESOURCE(OBM_CHECK)); if (GetObject(hCheckedBmp, sizeof(bmpChecked), &bmpChecked) == 0) bmpChecked.bmHeight = bmpChecked.bmWidth = 10; @@ -259,7 +259,7 @@ extern "C" int __declspec(dllexport) Load(void) //////////////////////////////////////////////////////////////////////////////////////// -extern "C" int __declspec(dllexport) Unload(void) +extern "C" int __declspec(dllexport) Unload(void) { DeleteObject(hCheckedBmp); FreeDictionaries(languages); diff --git a/plugins/SpellChecker/src/utils.cpp b/plugins/SpellChecker/src/utils.cpp index 854ff61146..d4b3fa7138 100644 --- a/plugins/SpellChecker/src/utils.cpp +++ b/plugins/SpellChecker/src/utils.cpp @@ -30,7 +30,7 @@ void SetUnderline(Dialog *dlg, int pos_start, int pos_end) dlg->re->SetSel(pos_start, pos_end); CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); + cf.cbSize = sizeof(cf); cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = CFE_UNDERLINE; cf.bUnderlineType = opts.underline_type + CFU_UNDERLINEDOUBLE; @@ -55,15 +55,16 @@ void SetNoUnderline(RichEdit *re, int pos_start, int pos_end) re->SetSel(i, min(i + 1, pos_end)); CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); + cf.cbSize = sizeof(cf); re->SendMessage(EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); BOOL mine = IsMyUnderline(cf); if (mine) { - cf.cbSize = sizeof(CHARFORMAT2); + cf.cbSize = sizeof(cf); cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = 0; cf.bUnderlineType = CFU_UNDERLINE; + cf.bUnderlineColor = 0; re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); } } @@ -72,10 +73,11 @@ void SetNoUnderline(RichEdit *re, int pos_start, int pos_end) re->SetSel(pos_start, pos_end); CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); + cf.cbSize = sizeof(cf); cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = 0; cf.bUnderlineType = CFU_UNDERLINE; + cf.bUnderlineColor = 0; re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); } } @@ -610,7 +612,7 @@ LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) else { // Remove underline of current word CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); + cf.cbSize = sizeof(cf); dlg->re->SendMessage(EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); if (IsMyUnderline(cf)) { -- cgit v1.2.3