diff options
author | George Hazan <ghazan@miranda.im> | 2020-02-24 20:59:33 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-02-24 20:59:33 +0300 |
commit | 9de717660e3965fac37428abb0bc9ffaae6f2061 (patch) | |
tree | aba6c71e0c81c6c488c622b48fd5fa1afb3fef0f /plugins/IEHistory/src/utils.cpp | |
parent | 979a7ee9bea1ec5a9f911cf6ed50a3c6051f055c (diff) |
IEHistory: some old trash removed
Diffstat (limited to 'plugins/IEHistory/src/utils.cpp')
-rw-r--r-- | plugins/IEHistory/src/utils.cpp | 164 |
1 files changed, 33 insertions, 131 deletions
diff --git a/plugins/IEHistory/src/utils.cpp b/plugins/IEHistory/src/utils.cpp index d1699bdb45..4497163ab4 100644 --- a/plugins/IEHistory/src/utils.cpp +++ b/plugins/IEHistory/src/utils.cpp @@ -33,22 +33,19 @@ int Log(char *format, ...) va_list vararg; int tBytes; FILE *fout = fopen("IEHistory.log", "at"); - if (!fout) - { + if (!fout) { // MessageBox(0, "can't open file", NULL, MB_OK); } va_start(vararg, format); - tBytes = _vsnprintf(str, sizeof(str), format, vararg); - if (tBytes > 0) - { + tBytes = _vsnprintf_s(str, sizeof(str), format, vararg); + if (tBytes > 0) { str[tBytes] = 0; } va_end(vararg); - if (str[mir_strlen(str) - 1] != '\n') - { + if (str[mir_strlen(str) - 1] != '\n') { mir_strcat(str, "\n"); } fputs(str, fout); @@ -65,9 +62,8 @@ int Info(char *title, char *format, ...) va_list vararg; int tBytes; va_start(vararg, format); - tBytes = snprintf(str, sizeof(str), format, vararg); - if (tBytes > 0) - { + tBytes = _snprintf_s(str, sizeof(str), format, vararg); + if (tBytes > 0) { str[tBytes] = 0; } va_end(vararg); @@ -93,69 +89,6 @@ void ScreenToClient(HWND hWnd, LPRECT rect) rect->bottom = pt.y + cy; } -void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors) -{ - RECT rParent; - RECT rChild; - - if (parentPos->flags & SWP_NOSIZE) - { - return; - } - GetWindowRect(parentPos->hwnd, &rParent); - rChild = AnchorCalcPos(window, &rParent, parentPos, anchors); - MoveWindow(window, rChild.left, rChild.top, rChild.right - rChild.left, rChild.bottom - rChild.top, FALSE); -} - -RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int anchors) -{ - RECT rChild; - RECT rTmp; - - GetWindowRect(window, &rChild); - ScreenToClient(parentPos->hwnd, &rChild); - - int cx = rParent->right - rParent->left; - int cy = rParent->bottom - rParent->top; - if ((cx == parentPos->cx) && (cy == parentPos->cy)) - { - return rChild; - } - if (parentPos->flags & SWP_NOSIZE) - { - return rChild; - } - - rTmp.left = parentPos->x - rParent->left; - rTmp.right = (parentPos->x + parentPos->cx) - rParent->right; - rTmp.bottom = (parentPos->y + parentPos->cy) - rParent->bottom; - rTmp.top = parentPos->y - rParent->top; - - cx = (rTmp.left) ? -rTmp.left : rTmp.right; - cy = (rTmp.top) ? -rTmp.top : rTmp.bottom; - - rChild.right += cx; - rChild.bottom += cy; - //expanded the window accordingly, now we need to enforce the anchors - if ((anchors & ANCHOR_LEFT) && (!(anchors & ANCHOR_RIGHT))) - { - rChild.right -= cx; - } - if ((anchors & ANCHOR_TOP) && (!(anchors & ANCHOR_BOTTOM))) - { - rChild.bottom -= cy; - } - if ((anchors & ANCHOR_RIGHT) && (!(anchors & ANCHOR_LEFT))) - { - rChild.left += cx; - } - if ((anchors & ANCHOR_BOTTOM) && (!(anchors & ANCHOR_TOP))) - { - rChild.top += cy; - } - return rChild; -} - void UnixTimeToFileTime(time_t t, LPFILETIME pft) { // Note that LONGLONG is a 64-bit value @@ -175,94 +108,63 @@ void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst) SystemTimeToTzSpecificLocalTime(nullptr, &st, pst); } -MEVENT GetNeededEvent(MEVENT hEvent, int num, int direction) +MEVENT GetNeededEvent(MCONTACT contact, MEVENT hEvent, int num, int direction) { - int i; - typedef MEVENT(__stdcall *db_event_step_t)(MCONTACT hContact, MEVENT hDbEvent); - db_event_step_t db_event_step; - if (direction == DIRECTION_BACK) - db_event_step = db_event_prev; - else - db_event_step = db_event_next; - - for (i = 0; i < num; ++i) - hEvent = db_event_step(0, hEvent); + for (int i = 0; i < num; ++i) + hEvent = (direction == DIRECTION_BACK) ? db_event_prev(contact, hEvent) : db_event_next(contact, hEvent); return hEvent; } SearchResult SearchHistory(MCONTACT contact, MEVENT hFirstEvent, void *searchData, int direction, int type) { - if (hFirstEvent == NULL){ - typedef MEVENT(__stdcall *db_event_start_t)(MCONTACT contact); - db_event_start_t db_event_start = (direction == DIRECTION_BACK) ? db_event_last : db_event_first; - hFirstEvent = db_event_start(contact); - } + if (hFirstEvent == NULL) + hFirstEvent = (direction == DIRECTION_BACK) ? db_event_last(contact) : db_event_first(contact); + int index = 0; MEVENT hEvent = hFirstEvent; void *buffer = nullptr; - wchar_t *search; bool found = false; int oldSize, newSize; oldSize = newSize = 0; DBEVENTINFO dbEvent = {}; - while ((!found) && (hEvent)){ + while ((!found) && (hEvent)) { newSize = db_event_getBlobSize(hEvent); - if (newSize > oldSize) - { + if (newSize > oldSize) { buffer = (wchar_t *)realloc(buffer, newSize); oldSize = newSize; } dbEvent.pBlob = (PBYTE)buffer; dbEvent.cbBlob = newSize; - if (db_event_get(hEvent, &dbEvent) == 0){ //successful - switch (type) - { + if (db_event_get(hEvent, &dbEvent) == 0) { //successful + switch (type) { case SEARCH_TEXT: - { -#ifdef _UNICODE - wchar_t TEMP[2048]; - size_t size = mir_strlen((char *)dbEvent.pBlob) + 1; - if (size < dbEvent.cbBlob) { - search = (wchar_t *)&dbEvent.pBlob[size]; - } - else{ - MultiByteToWideChar(CP_ACP, 0, (char *)buffer, (int)size, TEMP, 2048); - search = TEMP; - } -#else - search = (char *) buffer; -#endif - wchar_t *data = (wchar_t *)searchData; - wchar_t *tmp = wcsstr(search, data); - if (tmp) - { - found = true; + ptrW data(DbEvent_GetTextW(&dbEvent, CP_UTF8)); + wchar_t *tmp = wcsstr(data, (wchar_t *)searchData); + if (tmp) + found = true; } break; - } + case SEARCH_TIME: - { - SYSTEMTIME time; - TimeSearchData *data = (TimeSearchData *)searchData; - UnixTimeToSystemTime((time_t)dbEvent.timestamp, &time); - found = ((data->flags & TSDF_DATE_SET) || (data->flags & TSDF_TIME_SET)) ? true : false; - if (data->flags & TSDF_DATE_SET) { - found = ((time.wYear == data->time.wYear) && (time.wMonth == data->time.wMonth) && (time.wDay == data->time.wDay)); + SYSTEMTIME time; + TimeSearchData *data = (TimeSearchData *)searchData; + UnixTimeToSystemTime((time_t)dbEvent.timestamp, &time); + found = ((data->flags & TSDF_DATE_SET) || (data->flags & TSDF_TIME_SET)) ? true : false; + if (data->flags & TSDF_DATE_SET) + found = ((time.wYear == data->time.wYear) && (time.wMonth == data->time.wMonth) && (time.wDay == data->time.wDay)); + + if (data->flags & TSDF_TIME_SET) + found = found & ((time.wHour == data->time.wHour) && (time.wMinute == data->time.wMinute)); + break; } - if (data->flags & TSDF_TIME_SET) - { - found = found & ((time.wHour == data->time.wHour) && (time.wMinute == data->time.wMinute)); - } - break; - } } } - if (!found){ - hEvent = GetNeededEvent(hEvent, 1, direction); + if (!found) { + hEvent = GetNeededEvent(contact, hEvent, 1, direction); index++; } } |