diff options
Diffstat (limited to 'plugins/SpellChecker/src/utils.cpp')
-rw-r--r-- | plugins/SpellChecker/src/utils.cpp | 255 |
1 files changed, 115 insertions, 140 deletions
diff --git a/plugins/SpellChecker/src/utils.cpp b/plugins/SpellChecker/src/utils.cpp index d9a73daeec..6661274c21 100644 --- a/plugins/SpellChecker/src/utils.cpp +++ b/plugins/SpellChecker/src/utils.cpp @@ -19,7 +19,7 @@ Boston, MA 02111-1307, USA. #include "commons.h" -typedef void (*FoundWrongWordCallback)(TCHAR *word, CHARRANGE pos, void *param); +typedef void(*FoundWrongWordCallback)(TCHAR *word, CHARRANGE pos, void *param); typedef map<HWND, Dialog *> DialogMapType; DialogMapType dialogs; @@ -34,7 +34,7 @@ void SetUnderline(Dialog *dlg, int pos_start, int pos_end) cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = CFE_UNDERLINE; cf.bUnderlineType = ((opts.underline_type + CFU_UNDERLINEDOUBLE) | 0x50); - dlg->re->SendMessage(EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM)&cf); + dlg->re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); dlg->markedSomeWord = TRUE; } @@ -42,20 +42,20 @@ void SetUnderline(Dialog *dlg, int pos_start, int pos_end) BOOL IsMyUnderline(const CHARFORMAT2 &cf) { return (cf.dwEffects & CFE_UNDERLINE) - && (cf.bUnderlineType & 0x0F) >= CFU_UNDERLINEDOUBLE - && (cf.bUnderlineType & 0x0F) <= CFU_UNDERLINETHICK - && (cf.bUnderlineType & ~0x0F) == 0x50; + && (cf.bUnderlineType & 0x0F) >= CFU_UNDERLINEDOUBLE + && (cf.bUnderlineType & 0x0F) <= CFU_UNDERLINETHICK + && (cf.bUnderlineType & ~0x0F) == 0x50; } void SetNoUnderline(RichEdit *re, int pos_start, int pos_end) { if (opts.handle_underscore) { - for(int i = pos_start; i <= pos_end; i++) { - re->SetSel(i, min(i+1, pos_end)); + for (int i = pos_start; i <= pos_end; i++) { + re->SetSel(i, min(i + 1, pos_end)); CHARFORMAT2 cf; cf.cbSize = sizeof(CHARFORMAT2); - re->SendMessage(EM_GETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM)&cf); + re->SendMessage(EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); BOOL mine = IsMyUnderline(cf); if (mine) { @@ -63,7 +63,7 @@ void SetNoUnderline(RichEdit *re, int pos_start, int pos_end) cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = 0; cf.bUnderlineType = CFU_UNDERLINE; - re->SendMessage(EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM)&cf); + re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); } } } @@ -75,7 +75,7 @@ void SetNoUnderline(RichEdit *re, int pos_start, int pos_end) cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = 0; cf.bUnderlineType = CFU_UNDERLINE; - re->SendMessage(EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM)&cf); + re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); } } @@ -158,10 +158,10 @@ public: virtual ~TextParser() {} /// @return true when finished an word - virtual bool feed(int pos, TCHAR c) =0; - virtual int getFirstCharPos() =0; - virtual void reset() =0; - virtual void deal(const TCHAR *text, bool *mark, bool *replace, TCHAR **replacement) =0; + virtual bool feed(int pos, TCHAR c) = 0; + virtual int getFirstCharPos() = 0; + virtual void reset() = 0; + virtual void deal(const TCHAR *text, bool *mark, bool *replace, TCHAR **replacement) = 0; }; class SpellParser : public TextParser @@ -270,8 +270,8 @@ public: }; int CheckTextLine(Dialog *dlg, int line, TextParser *parser, - BOOL ignore_upper, BOOL ignore_with_numbers, BOOL test_urls, - const CHARRANGE &ignored, FoundWrongWordCallback callback, void *param) + BOOL ignore_upper, BOOL ignore_with_numbers, BOOL test_urls, + const CHARRANGE &ignored, FoundWrongWordCallback callback, void *param) { int errors = 0; TCHAR text[1024]; @@ -296,7 +296,7 @@ int CheckTextLine(Dialog *dlg, int line, TextParser *parser, parser->reset(); BOOL feed = FALSE; - for(int j = pos; !feed && j <= url_end; j++) + for (int j = pos; !feed && j <= url_end; j++) feed = parser->feed(j, text[j]); if (feed || parser->getFirstCharPos() != pos) @@ -316,7 +316,7 @@ int CheckTextLine(Dialog *dlg, int line, TextParser *parser, BOOL feed = parser->feed(pos, c); if (!feed) { - if (pos >= len-1) + if (pos >= len - 1) pos = len; // To check the last block else continue; @@ -338,7 +338,7 @@ int CheckTextLine(Dialog *dlg, int line, TextParser *parser, if (ignore_upper) { BOOL upper = TRUE; - for(int i = last_pos; i < pos && upper; i++) + for (int i = last_pos; i < pos && upper; i++) upper = !IsCharLower(text[i]); if (upper) continue; @@ -346,7 +346,7 @@ int CheckTextLine(Dialog *dlg, int line, TextParser *parser, if (ignore_with_numbers) { BOOL hasNumbers = FALSE; - for(int i = last_pos; i < pos && !hasNumbers; i++) + for (int i = last_pos; i < pos && !hasNumbers; i++) hasNumbers = IsNumber(text[i]); if (hasNumbers) continue; @@ -413,14 +413,14 @@ int CheckText(Dialog *dlg, BOOL check_all, FoundWrongWordCallback callback = NUL SetNoUnderline(dlg->re, first_char, first_char + dlg->re->GetLineLength(line)); - if (opts.auto_replace_user) + if (opts.auto_replace_user) errors += CheckTextLine(dlg, line, &AutoReplaceParser(dlg->lang->autoReplace), - FALSE, FALSE, TRUE, - cur_sel, callback, param); + FALSE, FALSE, TRUE, + cur_sel, callback, param); errors += CheckTextLine(dlg, line, &SpellParser(dlg->lang), - opts.ignore_uppercase, opts.ignore_with_numbers, FALSE, - cur_sel, callback, param); + opts.ignore_uppercase, opts.ignore_with_numbers, FALSE, + cur_sel, callback, param); } } @@ -435,7 +435,7 @@ int CheckText(Dialog *dlg, BOOL check_all, FoundWrongWordCallback callback = NUL void ToLocaleID(TCHAR *szKLName, size_t size) { TCHAR *stopped = NULL; - USHORT langID = (USHORT) _tcstol(szKLName, &stopped, 16); + USHORT langID = (USHORT)_tcstol(szKLName, &stopped, 16); TCHAR ini[32], end[32]; GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SISO639LANGNAME, ini, SIZEOF(ini)); @@ -450,7 +450,7 @@ void LoadDictFromKbdl(Dialog *dlg) // Use default input language HKL hkl = GetKeyboardLayout(0); - mir_sntprintf(szKLName, SIZEOF(szKLName), _T("%x"), (int) LOWORD(hkl)); + mir_sntprintf(szKLName, SIZEOF(szKLName), _T("%x"), (int)LOWORD(hkl)); ToLocaleID(szKLName, SIZEOF(szKLName)); int d = GetClosestLanguage(szKLName); @@ -502,8 +502,8 @@ LRESULT CALLBACK OwnerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) int errors = TimerCheck(dlg, TRUE); if (errors > 0) { TCHAR text[500]; - mir_sntprintf(text,SIZEOF(text),TranslateT("There are %d spelling errors. Are you sure you want to send this message?"),errors); - if (MessageBox(hwnd,text,TranslateT("Spell Checker"), MB_ICONQUESTION | MB_YESNO) == IDNO) + mir_sntprintf(text, SIZEOF(text), TranslateT("There are %d spelling errors. Are you sure you want to send this message?"), errors); + if (MessageBox(hwnd, text, TranslateT("Spell Checker"), MB_ICONQUESTION | MB_YESNO) == IDNO) return TRUE; } } @@ -553,13 +553,13 @@ LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return -1; // Hotkey support - MSG msgData = {0}; + MSG msgData = { 0 }; msgData.hwnd = hwnd; msgData.message = msg; msgData.wParam = wParam; msgData.lParam = lParam; - int action = CallService(MS_HOTKEY_CHECK, (WPARAM) &msgData, (LPARAM) "Spell Checker"); + int action = CallService(MS_HOTKEY_CHECK, (WPARAM)&msgData, (LPARAM)"Spell Checker"); if (action == HOTKEY_ACTION_TOGGLE) { ToggleEnabled(dlg); return 1; @@ -569,7 +569,7 @@ LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if ((dlgit = dialogs.find(hwnd)) == dialogs.end()) return ret; - switch(msg) { + switch (msg) { case WM_KEYDOWN: if (wParam != VK_DELETE) break; @@ -581,11 +581,11 @@ LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if (lParam & (1 << 28)) // ALT key break; - if ( GetKeyState(VK_CONTROL) & 0x8000) // CTRL key + if (GetKeyState(VK_CONTROL) & 0x8000) // CTRL key break; { - TCHAR c = (TCHAR) wParam; + TCHAR c = (TCHAR)wParam; BOOL deleting = (c == VK_BACK || c == VK_DELETE); // Need to do that to avoid changing the word while typing @@ -610,9 +610,9 @@ LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) // Remove underline of current word CHARFORMAT2 cf; cf.cbSize = sizeof(CHARFORMAT2); - dlg->re->SendMessage(EM_GETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM)&cf); + dlg->re->SendMessage(EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf); - if ( IsMyUnderline(cf)) { + if (IsMyUnderline(cf)) { dlg->re->Stop(); CHARRANGE sel = dlg->re->GetSel(); @@ -717,10 +717,10 @@ int GetClosestLanguage(TCHAR *lang_name) void GetUserProtoLanguageSetting(Dialog *dlg, MCONTACT hContact, char *group, char *setting, BOOL isProtocol = TRUE) { - DBVARIANT dbv = {0}; + DBVARIANT dbv = { 0 }; dbv.type = DBVT_TCHAR; - DBCONTACTGETSETTING cgs = {0}; + DBCONTACTGETSETTING cgs = { 0 }; cgs.szModule = group; cgs.szSetting = setting; cgs.pValue = &dbv; @@ -729,7 +729,7 @@ void GetUserProtoLanguageSetting(Dialog *dlg, MCONTACT hContact, char *group, ch int caps = (isProtocol ? CallProtoService(group, PS_GETCAPS, PFLAGNUM_4, 0) : 0); if (caps & PF4_INFOSETTINGSVC) - rc = CallProtoService(group, PS_GETINFOSETTING, hContact, (LPARAM) &cgs); + rc = CallProtoService(group, PS_GETINFOSETTING, hContact, (LPARAM)&cgs); else { rc = CallService(MS_DB_CONTACT_GETSETTING_STR_EX, hContact, (LPARAM)&cgs); if (rc == CALLSERVICE_NOTFOUND) @@ -742,9 +742,8 @@ void GetUserProtoLanguageSetting(Dialog *dlg, MCONTACT hContact, char *group, ch for (int i = 0; i < languages.getCount(); i++) { Dictionary *dict = languages[i]; if (lstrcmpi(dict->localized_name, lang) == 0 - || lstrcmpi(dict->english_name, lang) == 0 - || lstrcmpi(dict->language, lang) == 0) - { + || lstrcmpi(dict->english_name, lang) == 0 + || lstrcmpi(dict->language, lang) == 0) { lstrcpyn(dlg->lang_name, dict->language, SIZEOF(dlg->lang_name)); break; } @@ -782,12 +781,12 @@ void GetUserLanguageSetting(Dialog *dlg, char *setting) void GetContactLanguage(Dialog *dlg) { - DBVARIANT dbv = {0}; + DBVARIANT dbv = { 0 }; dlg->lang_name[0] = _T('\0'); if (dlg->hContact == NULL) { - if ( !db_get_ts(NULL, MODULE_NAME, dlg->name, &dbv)) { + if (!db_get_ts(NULL, MODULE_NAME, dlg->name, &dbv)) { lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name)); db_free(&dbv); } @@ -867,26 +866,13 @@ void ModifyIcon(Dialog *dlg) INT_PTR AddContactTextBoxService(WPARAM wParam, LPARAM lParam) { - SPELLCHECKER_ITEM *sci = (SPELLCHECKER_ITEM *) wParam; + SPELLCHECKER_ITEM *sci = (SPELLCHECKER_ITEM *)wParam; if (sci == NULL || sci->cbSize != sizeof(SPELLCHECKER_ITEM)) return -1; return AddContactTextBox(sci->hContact, sci->hwnd, sci->window_name, FALSE, NULL); } -void NotifyWrongSRMM() -{ - static BOOL notified = FALSE; - if (notified) - return; - - MessageBox(NULL, - TranslateT("Your message window does not support SpellChecker Plugin.\nIf you use SRMM, TabSRMM or Scriver, please update them to the latest version,\notherwise ask the author of your message window plugin to add support for Spell Checker."), - TranslateT("Spell Checker"), MB_ICONERROR | MB_OK); - - notified = TRUE; -} - int AddContactTextBox(MCONTACT hContact, HWND hwnd, char *name, BOOL srmm, HWND hwndOwner) { if (languages.getCount() <= 0) @@ -894,17 +880,13 @@ int AddContactTextBox(MCONTACT hContact, HWND hwnd, char *name, BOOL srmm, HWND if (dialogs.find(hwnd) == dialogs.end()) { // Fill dialog data - Dialog *dlg = (Dialog *) malloc(sizeof(Dialog)); + Dialog *dlg = (Dialog *)malloc(sizeof(Dialog)); ZeroMemory(dlg, sizeof(Dialog)); dlg->re = new RichEdit(hwnd); if (!dlg->re->IsValid()) { delete dlg->re; free(dlg); - - if (srmm) - NotifyWrongSRMM(); - return 0; } @@ -943,16 +925,16 @@ int AddContactTextBox(MCONTACT hContact, HWND hwnd, char *name, BOOL srmm, HWND void FreePopupData(Dialog *dlg) { - DESTROY_MENY(dlg->hLanguageSubMenu) - DESTROY_MENY(dlg->hWrongWordsSubMenu) + DESTROY_MENY(dlg->hLanguageSubMenu); + DESTROY_MENY(dlg->hWrongWordsSubMenu); if (dlg->wrong_words != NULL) { for (unsigned i = 0; i < dlg->wrong_words->size(); i++) { - FREE((*dlg->wrong_words)[i].word) + FREE((*dlg->wrong_words)[i].word); - DESTROY_MENY((*dlg->wrong_words)[i].hMeSubMenu) - DESTROY_MENY((*dlg->wrong_words)[i].hCorrectSubMenu) - DESTROY_MENY((*dlg->wrong_words)[i].hReplaceSubMenu) + DESTROY_MENY((*dlg->wrong_words)[i].hMeSubMenu); + DESTROY_MENY((*dlg->wrong_words)[i].hCorrectSubMenu); + DESTROY_MENY((*dlg->wrong_words)[i].hReplaceSubMenu); FreeSuggestions((*dlg->wrong_words)[i].suggestions); } @@ -964,7 +946,7 @@ void FreePopupData(Dialog *dlg) INT_PTR RemoveContactTextBoxService(WPARAM wParam, LPARAM lParam) { - HWND hwnd = (HWND) wParam; + HWND hwnd = (HWND)wParam; if (hwnd == NULL) return -1; @@ -1005,12 +987,12 @@ BOOL GetWordCharRange(Dialog *dlg, CHARRANGE &sel, TCHAR *text, size_t text_len, // Find the word sel.cpMin--; while (sel.cpMin >= first_char && (dlg->lang->isWordChar(text[sel.cpMin - first_char]) - || IsNumber(text[sel.cpMin - first_char]))) + || IsNumber(text[sel.cpMin - first_char]))) sel.cpMin--; sel.cpMin++; while (text[sel.cpMax - first_char] != _T('\0') && (dlg->lang->isWordChar(text[sel.cpMax - first_char]) - || IsNumber(text[sel.cpMax - first_char]))) + || IsNumber(text[sel.cpMax - first_char]))) sel.cpMax++; // Has a word? @@ -1020,7 +1002,7 @@ BOOL GetWordCharRange(Dialog *dlg, CHARRANGE &sel, TCHAR *text, size_t text_len, // See if it has only '-'s BOOL has_valid_char = FALSE; for (int i = sel.cpMin; i < sel.cpMax && !has_valid_char; i++) - has_valid_char = ( text[i - first_char] != _T('-')); + has_valid_char = (text[i - first_char] != _T('-')); return has_valid_char; } @@ -1049,7 +1031,7 @@ TCHAR *GetWordUnderPoint(Dialog *dlg, POINT pt, CHARRANGE &sel) void AppendSubmenu(HMENU hMenu, HMENU hSubMenu, TCHAR *name) { - MENUITEMINFO mii = {0}; + MENUITEMINFO mii = { sizeof(mii) }; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_SUBMENU | MIIM_TYPE; mii.fType = MFT_STRING; @@ -1062,10 +1044,9 @@ void AppendSubmenu(HMENU hMenu, HMENU hSubMenu, TCHAR *name) void AppendMenuItem(HMENU hMenu, int id, TCHAR *name, HICON hIcon, BOOL checked) { ICONINFO iconInfo; - GetIconInfo(hIcon, & iconInfo); + GetIconInfo(hIcon, &iconInfo); - MENUITEMINFO mii = {0}; - mii.cbSize = sizeof(MENUITEMINFO); + MENUITEMINFO mii = { sizeof(mii) }; mii.fMask = MIIM_CHECKMARKS | MIIM_TYPE | MIIM_STATE; mii.fType = MFT_STRING; mii.fState = (checked ? MFS_CHECKED : 0); @@ -1109,7 +1090,7 @@ void AddMenuForWord(Dialog *dlg, TCHAR *word, CHARRANGE &pos, HMENU hMenu, BOOL InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION, base + AUTOREPLACE_MENU_ID_BASE + suggestions.count, TranslateT("Other...")); if (suggestions.count > 0) { InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0); - for (int i = (int)suggestions.count-1; i >= 0; i--) + for (int i = (int)suggestions.count - 1; i >= 0; i--) InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION, base + AUTOREPLACE_MENU_ID_BASE + i, suggestions.words[i]); } @@ -1142,16 +1123,17 @@ void AddMenuForWord(Dialog *dlg, TCHAR *word, CHARRANGE &pos, HMENU hMenu, BOOL } } -struct FoundWrongWordParam { +struct FoundWrongWordParam +{ Dialog *dlg; int count; }; void FoundWrongWord(TCHAR *word, CHARRANGE pos, void *param) { - FoundWrongWordParam *p = (FoundWrongWordParam*) param; + FoundWrongWordParam *p = (FoundWrongWordParam*)param; - p->count ++; + p->count++; AddMenuForWord(p->dlg, _tcsdup(word), pos, p->dlg->hWrongWordsSubMenu, TRUE, WORD_MENU_ID_BASE * p->count); } @@ -1179,7 +1161,7 @@ void AddItemsToMenu(Dialog *dlg, HMENU hMenu, POINT pt, HWND hwndOwner) // First add languages for (int i = 0; i < languages.getCount(); i++) AppendMenu(dlg->hLanguageSubMenu, MF_STRING | (languages[i] == dlg->lang ? MF_CHECKED : 0), - LANGUAGE_MENU_ID_BASE + i, languages[i]->full_name); + LANGUAGE_MENU_ID_BASE + i, languages[i]->full_name); AppendSubmenu(hMenu, dlg->hLanguageSubMenu, TranslateT("Language")); } @@ -1211,15 +1193,15 @@ void AddItemsToMenu(Dialog *dlg, HMENU hMenu, POINT pt, HWND hwndOwner) static void AddWordToDictCallback(BOOL canceled, Dictionary *dict, - const TCHAR *find, const TCHAR *replace, BOOL useVariables, - const TCHAR *original_find, void *param) + const TCHAR *find, const TCHAR *replace, BOOL useVariables, + const TCHAR *original_find, void *param) { if (canceled) return; dict->autoReplace->add(find, replace, useVariables); - HWND hwndParent = (HWND) param; + HWND hwndParent = (HWND)param; if (hwndParent != NULL) PostMessage(hwndParent, WMU_DICT_CHANGED, 0, 0); } @@ -1233,15 +1215,15 @@ BOOL HandleMenuSelection(Dialog *dlg, POINT pt, unsigned selection) ToggleEnabled(dlg); ret = TRUE; } - else if (selection >= LANGUAGE_MENU_ID_BASE && selection < LANGUAGE_MENU_ID_BASE + (unsigned) languages.getCount()) { + else if (selection >= LANGUAGE_MENU_ID_BASE && selection < LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount()) { SetNoUnderline(dlg); if (dlg->hContact == NULL) db_set_ts(NULL, MODULE_NAME, dlg->name, - languages[selection - LANGUAGE_MENU_ID_BASE]->language); + languages[selection - LANGUAGE_MENU_ID_BASE]->language); else db_set_ts(dlg->hContact, MODULE_NAME, "TalkLanguage", - languages[selection - LANGUAGE_MENU_ID_BASE]->language); + languages[selection - LANGUAGE_MENU_ID_BASE]->language); GetContactLanguage(dlg); @@ -1251,11 +1233,10 @@ BOOL HandleMenuSelection(Dialog *dlg, POINT pt, unsigned selection) ret = TRUE; } else if (selection > 0 && dlg->wrong_words != NULL - && selection >= WORD_MENU_ID_BASE - && selection < (dlg->wrong_words->size() + 1) * WORD_MENU_ID_BASE) - { + && selection >= WORD_MENU_ID_BASE + && selection < (dlg->wrong_words->size() + 1) * WORD_MENU_ID_BASE) { int pos = selection / WORD_MENU_ID_BASE; - selection -= pos * WORD_MENU_ID_BASE; + selection -= pos * WORD_MENU_ID_BASE; pos--; // 0 based WrongWordPopupMenuData &data = (*dlg->wrong_words)[pos]; @@ -1276,8 +1257,8 @@ BOOL HandleMenuSelection(Dialog *dlg, POINT pt, unsigned selection) selection -= AUTOREPLACE_MENU_ID_BASE; if (selection == data.suggestions.count) { ShowAutoReplaceDialog(dlg->hwnd_owner != NULL ? dlg->hwnd_owner : dlg->hwnd, FALSE, - dlg->lang, data.word, NULL, FALSE, - TRUE, &AddWordToDictCallback, dlg->hwnd); + dlg->lang, data.word, NULL, FALSE, + TRUE, &AddWordToDictCallback, dlg->hwnd); } else { // TODO Assert that text hasn't changed @@ -1301,7 +1282,7 @@ BOOL HandleMenuSelection(Dialog *dlg, POINT pt, unsigned selection) int MsgWindowPopup(WPARAM wParam, LPARAM lParam) { - MessageWindowPopupData *mwpd = (MessageWindowPopupData *) lParam; + MessageWindowPopupData *mwpd = (MessageWindowPopupData *)lParam; if (mwpd == NULL || mwpd->cbSize < sizeof(MessageWindowPopupData) || mwpd->uFlags != MSG_WINDOWPOPUP_INPUT) return 0; @@ -1324,7 +1305,7 @@ int MsgWindowPopup(WPARAM wParam, LPARAM lParam) INT_PTR ShowPopupMenuService(WPARAM wParam, LPARAM lParam) { - SPELLCHECKER_POPUPMENU *scp = (SPELLCHECKER_POPUPMENU *) wParam; + SPELLCHECKER_POPUPMENU *scp = (SPELLCHECKER_POPUPMENU *)wParam; if (scp == NULL || scp->cbSize != sizeof(SPELLCHECKER_POPUPMENU)) return -1; @@ -1341,10 +1322,10 @@ int ShowPopupMenu(HWND hwnd, HMENU hMenu, POINT pt, HWND hwndOwner) if (pt.x == 0xFFFF && pt.y == 0xFFFF) { CHARRANGE sel; - SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM) &sel); + SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); // Get current cursor pos - SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM) sel.cpMax); + SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM)sel.cpMax); } else ScreenToClient(hwnd, &pt); @@ -1390,7 +1371,7 @@ int MsgWindowEvent(WPARAM wParam, LPARAM lParam) int IconPressed(WPARAM hContact, LPARAM lParam) { - StatusIconClickData *sicd = (StatusIconClickData *) lParam; + StatusIconClickData *sicd = (StatusIconClickData *)lParam; if (sicd == NULL || strcmp(sicd->szModule, MODULE_NAME) != 0) return 0; @@ -1400,7 +1381,7 @@ int IconPressed(WPARAM hContact, LPARAM lParam) // Find the dialog HWND hwnd = NULL; Dialog *dlg; - for(DialogMapType::iterator it = dialogs.begin(); it != dialogs.end(); it++) { + for (DialogMapType::iterator it = dialogs.begin(); it != dialogs.end(); it++) { dlg = it->second; if (dlg->srmm && dlg->hContact == hContact) { hwnd = it->first; @@ -1408,10 +1389,8 @@ int IconPressed(WPARAM hContact, LPARAM lParam) } } - if (hwnd == NULL) { - NotifyWrongSRMM(); + if (hwnd == NULL) return 0; - } if ((sicd->flags & MBCF_RIGHTBUTTON) == 0) { FreePopupData(dlg); @@ -1428,8 +1407,7 @@ int IconPressed(WPARAM hContact, LPARAM lParam) // First add languages for (int i = 0; i < languages.getCount(); i++) - AppendMenu(hMenu, MF_STRING | (languages[i] == dlg->lang ? MF_CHECKED : 0), - LANGUAGE_MENU_ID_BASE + i, languages[i]->full_name); + AppendMenu(hMenu, MF_STRING | (languages[i] == dlg->lang ? MF_CHECKED : 0), LANGUAGE_MENU_ID_BASE + i, languages[i]->full_name); InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0); } @@ -1461,15 +1439,15 @@ LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) switch (msg) { case WM_INITMENUPOPUP: { - HMENU hMenu = (HMENU) wParam; + HMENU hMenu = (HMENU)wParam; int count = GetMenuItemCount(hMenu); - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { unsigned id = GetMenuItemID(hMenu, i); - if (id < LANGUAGE_MENU_ID_BASE || id >= LANGUAGE_MENU_ID_BASE + (unsigned) languages.getCount()) + if (id < LANGUAGE_MENU_ID_BASE || id >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount()) continue; - MENUITEMINFO mii = {0}; + MENUITEMINFO mii = { 0 }; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_STATE; GetMenuItemInfo(hMenu, id, FALSE, &mii); @@ -1483,7 +1461,7 @@ LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_DRAWITEM: { LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam; - if (lpdis->CtlType != ODT_MENU || lpdis->itemID < LANGUAGE_MENU_ID_BASE || lpdis->itemID >= LANGUAGE_MENU_ID_BASE + (unsigned) languages.getCount()) + if (lpdis->CtlType != ODT_MENU || lpdis->itemID < LANGUAGE_MENU_ID_BASE || lpdis->itemID >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount()) break; int pos = lpdis->itemID - LANGUAGE_MENU_ID_BASE; @@ -1491,9 +1469,9 @@ LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) Dictionary *dict = languages[pos]; COLORREF clrfore = SetTextColor(lpdis->hDC, - GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT)); + GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT)); COLORREF clrback = SetBkColor(lpdis->hDC, - GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_MENU)); + GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_MENU)); FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_MENU)); @@ -1508,7 +1486,7 @@ LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) rc.bottom = rc.top + bmpChecked.bmHeight; HDC hdcTemp = CreateCompatibleDC(lpdis->hDC); - HBITMAP oldBmp = (HBITMAP) SelectObject(hdcTemp, hCheckedBmp); + HBITMAP oldBmp = (HBITMAP)SelectObject(hdcTemp, hCheckedBmp); BitBlt(lpdis->hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hdcTemp, 0, 0, SRCCOPY); @@ -1542,60 +1520,57 @@ LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) // Restore old colors SetTextColor(lpdis->hDC, clrfore); SetBkColor(lpdis->hDC, clrback); - - return TRUE; } + return TRUE; case WM_MEASUREITEM: - { - LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam; - if (lpmis->CtlType != ODT_MENU || lpmis->itemID < LANGUAGE_MENU_ID_BASE || lpmis->itemID >= LANGUAGE_MENU_ID_BASE + (unsigned) languages.getCount()) - break; + LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam; + if (lpmis->CtlType != ODT_MENU || lpmis->itemID < LANGUAGE_MENU_ID_BASE || lpmis->itemID >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount()) + break; - int pos = lpmis->itemID - LANGUAGE_MENU_ID_BASE; + int pos = lpmis->itemID - LANGUAGE_MENU_ID_BASE; - Dictionary *dict = languages[pos]; + Dictionary *dict = languages[pos]; - HDC hdc = GetDC(hwnd); + HDC hdc = GetDC(hwnd); - NONCLIENTMETRICS info; - ZeroMemory(&info, sizeof(info)); - info.cbSize = sizeof(info); - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0); - HFONT hFont = CreateFontIndirect(&info.lfMenuFont); - HFONT hFontOld = (HFONT) SelectObject(hdc, hFont); + NONCLIENTMETRICS info; + ZeroMemory(&info, sizeof(info)); + info.cbSize = sizeof(info); + SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0); + HFONT hFont = CreateFontIndirect(&info.lfMenuFont); + HFONT hFontOld = (HFONT)SelectObject(hdc, hFont); - RECT rc = { 0, 0, 0xFFFF, 0xFFFF }; + RECT rc = { 0, 0, 0xFFFF, 0xFFFF }; - DrawText(hdc, dict->full_name, lstrlen(dict->full_name), &rc, DT_NOPREFIX | DT_SINGLELINE | DT_LEFT | DT_TOP | DT_CALCRECT); + DrawText(hdc, dict->full_name, lstrlen(dict->full_name), &rc, DT_NOPREFIX | DT_SINGLELINE | DT_LEFT | DT_TOP | DT_CALCRECT); - lpmis->itemHeight = max(ICON_SIZE, max(bmpChecked.bmHeight, rc.bottom)); - lpmis->itemWidth = 2 + bmpChecked.bmWidth + 2 + ICON_SIZE + 4 + rc.right + 2; + lpmis->itemHeight = max(ICON_SIZE, max(bmpChecked.bmHeight, rc.bottom)); + lpmis->itemWidth = 2 + bmpChecked.bmWidth + 2 + ICON_SIZE + 4 + rc.right + 2; - SelectObject(hdc, hFontOld); - DeleteObject(hFont); - ReleaseDC(hwnd, hdc); + SelectObject(hdc, hFontOld); + DeleteObject(hFont); + ReleaseDC(hwnd, hdc); - return TRUE; - } + return TRUE; } return mir_callNextSubclass(hwnd, MenuWndProc, msg, wParam, lParam); } -TCHAR *lstrtrim(TCHAR *str) +TCHAR* lstrtrim(TCHAR *str) { int len = lstrlen(str); int i; - for(i = len - 1; i >= 0 && (str[i] == ' ' || str[i] == '\t'); --i) ; + for (i = len - 1; i >= 0 && (str[i] == ' ' || str[i] == '\t'); --i); if (i < len - 1) { ++i; str[i] = _T('\0'); len = i; } - for(i = 0; i < len && (str[i] == ' ' || str[i] == '\t'); ++i) ; + for (i = 0; i < len && (str[i] == ' ' || str[i] == '\t'); ++i); if (i > 0) memmove(str, &str[i], (len - i + 1) * sizeof(TCHAR)); |