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 | |
parent | 979a7ee9bea1ec5a9f911cf6ed50a3c6051f055c (diff) |
IEHistory: some old trash removed
Diffstat (limited to 'plugins/IEHistory/src')
-rw-r--r-- | plugins/IEHistory/src/dlgHandlers.cpp | 87 | ||||
-rw-r--r-- | plugins/IEHistory/src/stdafx.h | 14 | ||||
-rw-r--r-- | plugins/IEHistory/src/utils.cpp | 164 | ||||
-rw-r--r-- | plugins/IEHistory/src/utils.h | 22 |
4 files changed, 65 insertions, 222 deletions
diff --git a/plugins/IEHistory/src/dlgHandlers.cpp b/plugins/IEHistory/src/dlgHandlers.cpp index fbd1ca7583..181d636d4c 100644 --- a/plugins/IEHistory/src/dlgHandlers.cpp +++ b/plugins/IEHistory/src/dlgHandlers.cpp @@ -35,7 +35,6 @@ struct WorkerThreadData{ void LoadName(HWND hWnd);
int CalcIEViewPos(IEVIEWWINDOW *ieWnd, HWND hMainWindow);
int LoadIEView(HWND hWnd);
-int MoveIEView(HWND hWnd);
int DestroyIEView(HWND hWnd);
int LoadEvents(HWND hWnd);
int LoadPage(HWND hWnd, MEVENT hFirstEvent, long index, long shiftCount, long readCount, int direction);
@@ -45,8 +44,6 @@ int ScrollToBottom(HWND hWnd); void RefreshButtonStates(HWND hWnd);
-MEVENT GetNeededEvent(MEVENT hLastFirstEvent, int num, int direction);
-
int CalcIEViewPos(IEVIEWWINDOW *ieWnd, HWND hMainWindow)
{
RECT rect;
@@ -71,7 +68,7 @@ void LoadName(HWND hWnd) }
wchar_t buffer[1024];
- sntprintf(buffer, 1024, L"'%s' - IEHistory", ptrW(Contact_GetInfo(CNF_DISPLAY, data->contact)).get());
+ mir_snwprintf(buffer, L"'%s' - IEHistory", ptrW(Contact_GetInfo(CNF_DISPLAY, data->contact)).get());
SetWindowText(hWnd, buffer);
}
@@ -184,7 +181,6 @@ DWORD WINAPI WorkerThread(LPVOID lpvData) memcpy(messages[i], dbInfo.pBlob, newSize);
FillIEViewInfo(&ieData[i], dbInfo, messages[i]);
}
- //FillIEViewEventData(&ieData[i], dbEvent);
dbEvent = db_event_next(0, dbEvent);
}
ieData[cLoad - 1].next = nullptr; //cLoad < LOAD_COUNT will only happen once, at the end
@@ -197,7 +193,7 @@ DWORD WINAPI WorkerThread(LPVOID lpvData) free(buffer);
EnableWindow(GetDlgItem(data->hWnd, IDC_CLOSE), TRUE);
free(data);
- //RefreshButtonStates(data->hWnd);
+
Log("%s", "WorkerThread finished ... returning");
return 0;
}
@@ -219,11 +215,11 @@ int DoLoadEvents(HWND hWnd, HistoryWindowData *data, IEVIEWEVENT ieEvent) ScrollToBottom(hWnd);
wchar_t buffer[256];
- itot(data->index + 1, buffer, 10);
+ _itow(data->index + 1, buffer, 10);
SendDlgItemMessage(hWnd, IDC_STATUSBAR, SB_SETTEXT, 0 | SBT_POPOUT, (LPARAM)buffer);
- itot(data->index + ieEvent.count, buffer, 10);
+ _itow(data->index + ieEvent.count, buffer, 10);
SendDlgItemMessage(hWnd, IDC_STATUSBAR, SB_SETTEXT, 1 | SBT_POPOUT, (LPARAM)buffer);
- itot(data->count, buffer, 10);
+ _itow(data->count, buffer, 10);
SendDlgItemMessage(hWnd, IDC_STATUSBAR, SB_SETTEXT, 3 | SBT_POPOUT, (LPARAM)buffer);
RefreshButtonStates(hWnd);
}
@@ -251,9 +247,10 @@ int LoadEvents(HWND hWnd) int num = 0;
if ((data->itemsPerPage > 0) && (bLastFirst)) {
num = data->count - data->itemsPerPage;
- hFirstEvent = GetNeededEvent(hFirstEvent, num, DIRECTION_FORWARD);
+ hFirstEvent = GetNeededEvent(data->contact, hFirstEvent, num, DIRECTION_FORWARD);
}
data->index = num;
+
data->hLastFirstEvent = hFirstEvent;
ieEvent.hDbEventFirst = hFirstEvent;
if (data->bEnableRTL)
@@ -287,7 +284,7 @@ int LoadPage(HWND hWnd, MEVENT hFirstEvent, long index, long shiftCount, long re }
}
data->index = newIndex;
- MEVENT hEvent = GetNeededEvent(hFirstEvent, count, direction);
+ MEVENT hEvent = GetNeededEvent(data->contact, hFirstEvent, count, direction);
data->hLastFirstEvent = hEvent;
ieEvent.hDbEventFirst = hEvent;
ieEvent.count = readCount;
@@ -306,6 +303,23 @@ int LoadPrev(HWND hWnd) return finish;
}
+int Resizer(HWND, LPARAM, UTILRESIZECONTROL *urc)
+{
+ switch (urc->wId) {
+ case IDC_CLOSE:
+ case IDC_SEARCH:
+ return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
+
+ case IDC_IEVIEW_PLACEHOLDER:
+ return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
+
+ case IDC_STATUSBAR:
+ return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM;
+ }
+
+ return RD_ANCHORX_LEFT | RD_ANCHORY_BOTTOM;
+}
+
int LoadNext(HWND hWnd)
{
HistoryWindowData *data = (HistoryWindowData *)GetWindowLongPtr(hWnd, DWLP_USER);
@@ -325,14 +339,6 @@ int ScrollToBottom(HWND hWnd) return 0;
}
-void AddAnchorWindowToDeferList(HDWP &hdWnds, HWND window, RECT *rParent, WINDOWPOS *wndPos, int anchors)
-{
- if (nullptr == window) /* Wine fix. */
- return;
- RECT rChild = AnchorCalcPos(window, rParent, wndPos, anchors);
- hdWnds = DeferWindowPos(hdWnds, window, HWND_NOTOPMOST, rChild.left, rChild.top, rChild.right - rChild.left, rChild.bottom - rChild.top, SWP_NOZORDER);
-}
-
void RefreshButtonStates(HWND hWnd)
{
HistoryWindowData *data = (HistoryWindowData *)GetWindowLongPtr(hWnd, DWLP_USER);
@@ -342,9 +348,7 @@ void RefreshButtonStates(HWND hWnd) EnableWindow(GetDlgItem(hWnd, IDC_NEXT), bNext);
}
-
-
-INT_PTR CALLBACK HistoryDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK HistoryDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM)
{
HistoryWindowData *data = (HistoryWindowData *)GetWindowLongPtr(hWnd, DWLP_USER);
@@ -393,7 +397,6 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara EnableWindow(GetDlgItem(hWnd, IDC_PREV), !bAll);
EnableWindow(GetDlgItem(hWnd, IDC_NEXT), FALSE);
}
- EnableWindow(GetDlgItem(hWnd, IDC_SEARCH), !bAll);
}
break;
@@ -411,34 +414,9 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara break;
case WM_WINDOWPOSCHANGING:
- {
- HDWP hdWnds = BeginDeferWindowPos(6);
- RECT rParent;
- HWND hStatusBar = GetDlgItem(hWnd, IDC_STATUSBAR);
- WINDOWPOS *wndPos = (WINDOWPOS *)lParam;
- GetWindowRect(hWnd, &rParent);
-
- // if (NULL != hStatusBar) /* Wine fix. */
- // hdWnds = DeferWindowPos(hdWnds, hStatusBar, HWND_NOTOPMOST, wndPos->x, wndPos->y + wndPos->cy - statusHeight, statusWidth, statusHeight, SWP_NOZORDER);
- SendMessage(hStatusBar, WM_SIZE, 0, 0);
- if (wndPos->cx < MIN_HISTORY_WIDTH)
- wndPos->cx = MIN_HISTORY_WIDTH;
- if (wndPos->cy < MIN_HISTORY_HEIGHT)
- wndPos->cy = MIN_HISTORY_HEIGHT;
-
- //MoveWindow(hStatusBar, wndPos->x, wndPos->y + wndPos->cy - statusHeight - 2, statusWidth - 2, statusHeight, TRUE);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_STATUSBAR), &rParent, wndPos, ANCHOR_BOTTOM);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_CLOSE), &rParent, wndPos, ANCHOR_RIGHT | ANCHOR_BOTTOM);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_IEVIEW_PLACEHOLDER), &rParent, wndPos, ANCHOR_ALL);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_PREV), &rParent, wndPos, ANCHOR_LEFT | ANCHOR_BOTTOM);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_NEXT), &rParent, wndPos, ANCHOR_LEFT | ANCHOR_BOTTOM);
- //AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_PAGE_NUMBER), &rParent, wndPos, ANCHOR_LEFT | ANCHOR_BOTTOM);
- AddAnchorWindowToDeferList(hdWnds, GetDlgItem(hWnd, IDC_SEARCH), &rParent, wndPos, ANCHOR_RIGHT | ANCHOR_BOTTOM);
-
- EndDeferWindowPos(hdWnds);
+ Utils_ResizeDialog(hWnd, g_plugin.getInst(), MAKEINTRESOURCEA(IDD_HISTORY), &Resizer);
MoveIeView(hWnd);
- }
- break;
+ break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
@@ -458,7 +436,7 @@ INT_PTR CALLBACK HistoryDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara HWND hSearch = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SEARCH), hWnd, SearchDlgProc);
if (hSearch == nullptr) {
char buffer[1024];
- sprintf(buffer, "Error #%d", GetLastError());
+ sprintf_s(buffer, "Error #%d", GetLastError());
MessageBoxA(nullptr, buffer, "Error", MB_OK);
}
SearchWindowData *searchData = (SearchWindowData *)malloc(sizeof(SearchWindowData));
@@ -553,7 +531,7 @@ INT_PTR CALLBACK SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam if (data->hLastFoundEvent == NULL)
data->index = (direction == DIRECTION_FORWARD) ? 0 : histData->count;
else
- data->hLastFoundEvent = GetNeededEvent(data->hLastFoundEvent, 1, direction);
+ data->hLastFoundEvent = GetNeededEvent(data->contact, data->hLastFoundEvent, 1, direction);
if (type == SEARCH_TEXT) { //text search
wchar_t text[2048]; //TODO buffer overrun
@@ -578,11 +556,8 @@ INT_PTR CALLBACK SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam }
if (searchResult.hEvent) {
- //char buffer[1024];
- //sprintf(buffer, "Found it: index = %ld hEvent = %p", searchResult.index, searchResult.hEvent);
- //MessageBox(0, buffer, "Yupppi", 0);
data->index += (direction == DIRECTION_BACK) ? -searchResult.index : searchResult.index;
- LoadPage(data->hHistoryWindow, searchResult.hEvent, data->index, histData->itemsPerPage / 2, histData->itemsPerPage, DIRECTION_BACK);
+ LoadPage(data->hHistoryWindow, searchResult.hEvent, data->index, 5, 10, DIRECTION_BACK);
}
else MessageBox(nullptr, TranslateT("Search finished. No more entries..."), TranslateT("Information"), MB_OK | MB_ICONINFORMATION);
diff --git a/plugins/IEHistory/src/stdafx.h b/plugins/IEHistory/src/stdafx.h index 19aadb42a5..5dc6758e3a 100644 --- a/plugins/IEHistory/src/stdafx.h +++ b/plugins/IEHistory/src/stdafx.h @@ -56,20 +56,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "utils.h" #include "dlgHandlers.h" -#define _strcat strcat_s -#define _vsnprintf _vsnprintf_s -#define snprintf _snprintf_s -#define snwprintf _snwprintf_s -#define sprintf sprintf_s -#define itow _itow_s -#ifndef _UNICODE -# define itot itoa -# define sntprintf snprintf -#else -# define itot itow -# define sntprintf snwprintf -#endif - struct CMPlugin : public PLUGIN<CMPlugin> { CMOption<BYTE> bEnableRtl, bShowLastFirst, bUseWorker; 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++; } } diff --git a/plugins/IEHistory/src/utils.h b/plugins/IEHistory/src/utils.h index 55c076a475..0b336364e5 100644 --- a/plugins/IEHistory/src/utils.h +++ b/plugins/IEHistory/src/utils.h @@ -21,12 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef M_IEHISTORY_UTILS_H #define M_IEHISTORY_UTILS_H -#define ANCHOR_LEFT 0x000001 -#define ANCHOR_RIGHT 0x000002 -#define ANCHOR_TOP 0x000004 -#define ANCHOR_BOTTOM 0x000008 -#define ANCHOR_ALL ANCHOR_LEFT | ANCHOR_RIGHT | ANCHOR_TOP | ANCHOR_BOTTOM - #define DIRECTION_BACK 0x000001 #define DIRECTION_FORWARD 0x000002 @@ -68,25 +62,11 @@ int Log(char *format, ...); void ScreenToClient(HWND hWnd, LPRECT rect); int Info(char *title, char *format, ...); -void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors); -RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int anchors); void UnixTimeToFileTime(time_t t, LPFILETIME pft); void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst); -MEVENT GetNeededEvent(MEVENT hLastFirstEvent, int num, int direction); +MEVENT GetNeededEvent(MCONTACT contact, MEVENT hLastFirstEvent, int num, int direction); SearchResult SearchHistory(MCONTACT contact, MEVENT hFirstEvent, void *searchData, int direction, int type); -/* -static __inline int mir_snprintf(char *buffer, size_t count, const char* fmt, ...) { - va_list va; - int len; - - va_start(va, fmt); - len = _vsnprintf(buffer, count-1, fmt, va); - va_end(va); - buffer[count-1] = 0; - return len; -} -*/ #endif |