From 09a1a03baff001ef9aef7310f918e79c8c1f6e97 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 22 Sep 2013 19:18:39 +0000 Subject: minor code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@6187 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/BasicHistory/src/Searcher.cpp | 143 +++++++++++----------------------- 1 file changed, 46 insertions(+), 97 deletions(-) (limited to 'plugins/BasicHistory/src/Searcher.cpp') diff --git a/plugins/BasicHistory/src/Searcher.cpp b/plugins/BasicHistory/src/Searcher.cpp index 57638e6c6d..0c9091e4f6 100644 --- a/plugins/BasicHistory/src/Searcher.cpp +++ b/plugins/BasicHistory/src/Searcher.cpp @@ -33,20 +33,17 @@ Searcher::Searcher() void Searcher::ChangeFindDirection(bool isBack) { - if (isBack != findBack) - { + if (isBack != findBack) { findBack = isBack; ClearFind(); TBBUTTONINFO tbInfo; tbInfo.cbSize = sizeof(TBBUTTONINFO); tbInfo.dwMask = TBIF_TEXT | TBIF_IMAGE; - if (isBack) - { + if (isBack) { tbInfo.pszText = TranslateT("Find Previous"); tbInfo.iImage = 1; } - else - { + else { tbInfo.pszText = TranslateT("Find Next"); tbInfo.iImage = 0; } @@ -58,8 +55,7 @@ void Searcher::ChangeFindDirection(bool isBack) void Searcher::ClearFind() { - if (lastFindSelection != -1) - { + if (lastFindSelection != -1) { SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_AND,~ECO_NOHIDESEL); lastFindSelection = -1; } @@ -77,10 +73,10 @@ bool Searcher::CompareStr(std::wstring str, TCHAR *strFind) std::transform(str.begin(), str.end(), str.begin(), std::bind2nd(std::ptr_fun(mytoupper), &loc)); if (!matchWholeWords) return str.find(strFind) < str.length(); + size_t findid = str.find(strFind); size_t findLen = _tcslen(strFind); - while(findid < str.length()) - { + while(findid < str.length()) { if ((findid == 0 || std::isspace(str[findid - 1], loc) || std::ispunct(str[findid - 1], loc)) && (findid + findLen >= str.length() || std::isspace(str[findid + findLen], loc) || std::ispunct(str[findid + findLen], loc))) return true; @@ -100,23 +96,20 @@ void Searcher::Find() ft.chrg.cpMin = 0; ft.chrg.cpMax = -1; ft.lpstrText = str; - if (context->currentGroup.size() < 1) - { + if (context->currentGroup.size() < 1) { SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_AND,~ECO_NOHIDESEL); lastFindSelection = -1; return; } GetWindowText(context->findWindow, str, 128); - if (!str[0]) - { + if (!str[0]) { TCHAR buf[256]; mir_sntprintf(buf, 256, TranslateT("\"%s\" not found"), str); MessageBox(context->hWnd, buf, TranslateT("Search"), MB_OK | MB_ICONINFORMATION); return; } - if (!matchCase) - { + if (!matchCase) { std::locale loc; std::transform(str, str + _tcslen(str), str, std::bind2nd(std::ptr_fun(mytoupper), &loc)); } @@ -126,38 +119,26 @@ void Searcher::Find() int adder1 = findBack1 ? -1 : 1; int adder2 = findBack2 ? -1 : 1; WPARAM findStyle = (findBack1 ? 0 : FR_DOWN) | (matchCase ? FR_MATCHCASE : 0) | (matchWholeWords ? FR_WHOLEWORD : 0); - if (lastFindSelection >= 0 && lastFindSelection < (int)context->currentGroup.size()) - { + if (lastFindSelection >= 0 && lastFindSelection < (int)context->currentGroup.size()) { if (onlyIn && context->currentGroup[lastFindSelection].isMe || onlyOut && !context->currentGroup[lastFindSelection].isMe) - { curSel = lastFindSelection + adder1; - } - else - { + else { SendDlgItemMessage(context->hWnd,IDC_EDIT,EM_EXGETSEL,0,(LPARAM)&ft.chrg); - if (findBack1) - { + if (findBack1) { ft.chrg.cpMin = ft.chrg.cpMin < context->currentGroup[lastFindSelection].endPos ? ft.chrg.cpMin : context->currentGroup[lastFindSelection].endPos; ft.chrg.cpMax = context->currentGroup[lastFindSelection].startPos; } - else - { + else { ft.chrg.cpMin = ft.chrg.cpMax > context->currentGroup[lastFindSelection].startPos ? ft.chrg.cpMax : context->currentGroup[lastFindSelection].startPos; ft.chrg.cpMax = context->currentGroup[lastFindSelection].endPos; } SendMessage(context->editWindow,EM_FINDTEXTEX, findStyle,(LPARAM)&ft); if (ft.chrgText.cpMin < 0 || ft.chrgText.cpMax < 0) - { curSel = lastFindSelection + adder1; - } - else - { + else { if (isFindContactChanged && startFindContact == context->hContact && isFindSelChanged && context->selected == startFindSel && ((!findBack1 && ft.chrg.cpMin >= startFindPos) || (findBack1 && ft.chrg.cpMax <= startFindPos))) - { finished = true; - } - else - { + else { curSel = lastFindSelection; SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ft.chrgText); SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL); @@ -167,8 +148,7 @@ void Searcher::Find() } } } - else - { + else { isStart = true; SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL); SendMessage(context->editWindow,EM_EXGETSEL,0,(LPARAM)&ft.chrg); @@ -179,47 +159,38 @@ void Searcher::Find() isFindSelChanged = false; startFindContact = context->hContact; isFindContactChanged = !allUsers; - if (findBack1) - for(curSel = (int)context->currentGroup.size() - 1; curSel >= 0; --curSel) - { + if (findBack1) { + for (curSel = (int)context->currentGroup.size() - 1; curSel >= 0; --curSel) if (context->currentGroup[curSel].startPos < startFindPos) break; - } + } else - for(; curSel < (int)context->currentGroup.size(); ++curSel) - { + for (; curSel < (int)context->currentGroup.size(); ++curSel) if (context->currentGroup[curSel].endPos > startFindPos) break; - } } - if (!finished) - { - for(; curSel < (int)context->currentGroup.size() && curSel >= 0; curSel += adder1) - { + if (!finished) { + for (; curSel < (int)context->currentGroup.size() && curSel >= 0; curSel += adder1) { if (onlyIn && context->currentGroup[curSel].isMe || onlyOut && !context->currentGroup[curSel].isMe) continue; - if (CompareStr(context->currentGroup[curSel].description, str)) - { - if (findBack1) - { + + if (CompareStr(context->currentGroup[curSel].description, str)) { + if (findBack1) { ft.chrg.cpMin = context->currentGroup[curSel].endPos; ft.chrg.cpMax = context->currentGroup[curSel].startPos; if (!isFindSelChanged && ft.chrg.cpMin > startFindPos) ft.chrg.cpMin = startFindPos; } - else - { + else { ft.chrg.cpMin = context->currentGroup[curSel].startPos; ft.chrg.cpMax = context->currentGroup[curSel].endPos; if (!isFindSelChanged && ft.chrg.cpMin < startFindPos) ft.chrg.cpMin = startFindPos; } SendMessage(context->editWindow,EM_FINDTEXTEX, findStyle,(LPARAM)&ft); - if (!(ft.chrgText.cpMin < 0 || ft.chrgText.cpMax < 0)) - { - if (isFindContactChanged && startFindContact == context->hContact && isFindSelChanged && context->selected == startFindSel && ((!findBack1 && ft.chrg.cpMin >= startFindPos) || (findBack1 && ft.chrg.cpMax <= startFindPos))) - { + if (!(ft.chrgText.cpMin < 0 || ft.chrgText.cpMax < 0)) { + if (isFindContactChanged && startFindContact == context->hContact && isFindSelChanged && context->selected == startFindSel && ((!findBack1 && ft.chrg.cpMin >= startFindPos) || (findBack1 && ft.chrg.cpMax <= startFindPos))) { finished = true; break; } @@ -233,17 +204,12 @@ void Searcher::Find() } if (isFindContactChanged && startFindContact == context->hContact && isFindSelChanged && context->selected == startFindSel) - { finished = true; - } - if (!finished) - { + if (!finished) { isFindSelChanged = true; - if (onlyGroup) - { - if (IsInSel(context->selected, str)) - { + if (onlyGroup) { + if (IsInSel(context->selected, str)) { CHARRANGE ch; ch.cpMin = ch.cpMax = findBack1 ? MAXLONG : 0; SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ch); @@ -252,44 +218,37 @@ void Searcher::Find() return; } } - else - { - for(int sel = context->selected + adder2; ; sel += adder2) - { - if (sel < 0) - { + else { + for (int sel = context->selected + adder2; ; sel += adder2) { + if (sel < 0) { isFindContactChanged = true; - if (allUsers) - { + if (allUsers) { HANDLE hNext = context->hContact; do { hNext = context->GetNextContact(hNext, adder2); } - while(hNext != startFindContact && !context->SearchInContact(hNext, str, this)); + while(hNext != startFindContact && !context->SearchInContact(hNext, str, this)); context->SelectContact(hNext); } sel = (int)context->eventList.size() - 1; } - else if (sel >= (int)context->eventList.size()) - { + else if (sel >= (int)context->eventList.size()) { isFindContactChanged = true; - if (allUsers) - { + if (allUsers) { HANDLE hNext = context->hContact; do { hNext = context->GetNextContact(hNext, adder2); } - while(hNext != startFindContact && !context->SearchInContact(hNext, str, this)); + while(hNext != startFindContact && !context->SearchInContact(hNext, str, this)); context->SelectContact(hNext); } sel = 0; } - if (IsInSel(sel, str)) - { + if (IsInSel(sel, str)) { LVITEM item = {0}; item.mask = LVIF_STATE; item.iItem = context->selected; @@ -316,12 +275,9 @@ void Searcher::Find() } if (startFindContact != context->hContact) - { context->SelectContact(startFindContact); - } - if (startFindSel != context->selected) - { + if (startFindSel != context->selected) { LVITEM item = {0}; item.mask = LVIF_STATE; item.iItem = context->selected; @@ -340,17 +296,13 @@ void Searcher::Find() SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ft.chrgText); SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_AND,~ECO_NOHIDESEL); lastFindSelection = -1; - if (isStart) - { + if (isStart) { TCHAR buf[256]; GetWindowText(context->findWindow, str, 128); mir_sntprintf(buf, 256, TranslateT("\"%s\" not found"), str); MessageBox(context->hWnd, buf, TranslateT("Search"), MB_OK | MB_ICONINFORMATION); } - else - { - MessageBox(context->hWnd, TranslateTS(onlyGroup ? LPGENT("You have reached the end of the group.") : LPGENT("You have reached the end of the history.")), TranslateT("Search"), MB_OK | MB_ICONINFORMATION); - } + else MessageBox(context->hWnd, TranslateTS(onlyGroup ? LPGENT("You have reached the end of the group.") : LPGENT("You have reached the end of the history.")), TranslateT("Search"), MB_OK | MB_ICONINFORMATION); } bool Searcher::IsInSel(int sel, TCHAR *strFind) @@ -360,19 +312,16 @@ bool Searcher::IsInSel(int sel, TCHAR *strFind) TCHAR str[MAXSELECTSTR + 8]; // for safety reason EventList::EventData data; - for(std::deque::iterator it = context->eventList[sel].begin(); it != context->eventList[sel].end(); ++it) - { + for (std::deque::iterator it = context->eventList[sel].begin(); it != context->eventList[sel].end(); ++it) { EventList::EventIndex hDbEvent = *it; - if (context->GetEventData(hDbEvent, data)) - { + if (context->GetEventData(hDbEvent, data)) { bool isMe = data.isMe; if (onlyIn && isMe || onlyOut && !isMe) continue; + context->GetEventMessage(hDbEvent, str); if (CompareStr(str, strFind)) - { return true; - } } } -- cgit v1.2.3