From 1bb9a86b26d3a9964844d42fa25690ce0a028258 Mon Sep 17 00:00:00 2001 From: Dmitry Kuzkin Date: Thu, 18 Jun 2015 12:36:07 +0000 Subject: true unicode build (ansi build is possible but useless) new search/replace dialog edit improvements (type check) resident settings support (fully resident modules are still invisible) remove obsolete things code cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@14243 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/DbEditorPP/src/watchedvars.cpp | 372 +++++++++++++++++++-------------- 1 file changed, 213 insertions(+), 159 deletions(-) (limited to 'plugins/DbEditorPP/src/watchedvars.cpp') diff --git a/plugins/DbEditorPP/src/watchedvars.cpp b/plugins/DbEditorPP/src/watchedvars.cpp index 4059035738..3b4f9a3c9b 100644 --- a/plugins/DbEditorPP/src/watchedvars.cpp +++ b/plugins/DbEditorPP/src/watchedvars.cpp @@ -1,153 +1,203 @@ #include "headers.h" -int addSettingToWatchList(MCONTACT hContact, char* module, char* setting) +HWND hwnd2watchedVarsWindow = NULL; + +static WatchListArrayStruct WatchListArray = {0}; + +static int lastColumn = -1; + +ColumnsSettings csWatchList[] = { + { LPGENT("Contact"), 0, "Watch0width", 100 }, + { LPGENT("Module"), 1, "Watch1width", 100 }, + { LPGENT("Setting"), 2, "Watch2width", 100 }, + { LPGENT("Value"), 3, "Watch3width", 200 }, + { LPGENT("Type"), 4, "Watch4width", 75 }, + {0} +}; + + + +int WatchedArrayIndex(MCONTACT hContact, const char *module, const char *setting, int strict) { + for (int i = 0; i < WatchListArray.count; i++) { + if (hContact == WatchListArray.item[i].hContact) + if (!mir_strcmp(module, WatchListArray.item[i].module)) + // empty setting = module watching + if ((!strict && !WatchListArray.item[i].setting) || !mir_strcmp(setting, WatchListArray.item[i].setting)) + return i; + } + return -1; +} + + +int addSettingToWatchList(MCONTACT hContact, const char *module, const char *setting) { if (WatchListArray.count == WatchListArray.size) { WatchListArray.size += 32; WatchListArray.item = (struct DBsetting*)mir_realloc(WatchListArray.item, sizeof(struct DBsetting)*WatchListArray.size); } - if (!WatchListArray.item) return 0; - if (setting && db_get(hContact, module, setting, &(WatchListArray.item[WatchListArray.count].dbv))) return 0; + if (!WatchListArray.item) + return 0; + + db_get_s(hContact, module, setting, &(WatchListArray.item[WatchListArray.count].dbv), 0); + WatchListArray.item[WatchListArray.count].hContact = hContact; - WatchListArray.item[WatchListArray.count].module = mir_tstrdup(module); - if (setting) WatchListArray.item[WatchListArray.count].setting = mir_tstrdup(setting); - else WatchListArray.item[WatchListArray.count].setting = 0; + WatchListArray.item[WatchListArray.count].module = mir_strdup(module); + + if (setting) + WatchListArray.item[WatchListArray.count].setting = mir_strdup(setting); + else + WatchListArray.item[WatchListArray.count].setting = 0; - WatchListArray.item[WatchListArray.count].WatchModule = setting ? WATCH_SETTING : WATCH_MODULE; WatchListArray.count++; return 1; } + void freeWatchListItem(int item) { - if (WatchListArray.item[item].module) mir_free(WatchListArray.item[item].module); + if (item < 0 || item >= WatchListArray.count) return; + + if (WatchListArray.item[item].module) + mir_free(WatchListArray.item[item].module); + WatchListArray.item[item].module = 0; - if (WatchListArray.item[item].setting) mir_free(WatchListArray.item[item].setting); + + if (WatchListArray.item[item].setting) + mir_free(WatchListArray.item[item].setting); + WatchListArray.item[item].setting = 0; db_free(&(WatchListArray.item[item].dbv)); WatchListArray.item[item].hContact = 0; } -void addwatchtolist(HWND hwnd2list, struct DBsetting *lParam) +void addwatchtolist(HWND hwnd, struct DBsetting *lParam) { LVITEM lvItem; int index; - char data[32], tmp[32]; + DBVARIANT *dbv = &(lParam->dbv); MCONTACT hContact = lParam->hContact; + char *module = lParam->module; char *setting = lParam->setting; + if (!module) return; + lvItem.lParam = (LPARAM)lParam->hContact; lvItem.mask = LVIF_TEXT | LVIF_PARAM; lvItem.iItem = 0; lvItem.iSubItem = 0; - if (!setting || (int)(lParam->setting) == WATCH_MODULE) // add every item in the module and return + if (!setting) // add every item in the module and return { ModuleSettingLL settinglist; - struct DBsetting dummy; + struct DBsetting dummy = {0}; ModSetLinkLinkItem *setting; - if (!EnumSettings(hContact, module, &settinglist)) return; + if (IsModuleEmpty(hContact, module) || !EnumSettings(hContact, module, &settinglist)) return; + dummy.hContact = hContact; - dummy.module = mir_tstrdup(module); + dummy.module = module; setting = settinglist.first; while (setting) { dummy.setting = setting->name; - addwatchtolist(hwnd2list, &dummy); + addwatchtolist(hwnd, &dummy); setting = (ModSetLinkLinkItem *)setting->next; } - mir_free(dummy.module); FreeModuleSettingLL(&settinglist); return; } + db_free(&(lParam->dbv)); - if (GetSetting(hContact, module, setting, &(lParam->dbv))) return; - if (!hContact) - lvItem.pszText = "NULL"; - else - lvItem.pszText = (char*)GetContactName(hContact, NULL, 1); + db_get_s(hContact, module, setting, &(lParam->dbv), 0); - index = ListView_InsertItem(hwnd2list, &lvItem); + TCHAR data[32], tmp[16], name[NAME_SIZE]; - WCHAR* ptszText = mir_a2u(lvItem.pszText); - ListView_SetItemTextW(hwnd2list, index, 0, ptszText); - mir_free(ptszText); + GetContactName(hContact, NULL, name, SIZEOF(name)); + lvItem.pszText = name; - ListView_SetItemText(hwnd2list, index, 1, module); - ListView_SetItemText(hwnd2list, index, 2, setting); + index = ListView_InsertItem(hwnd, &lvItem); + + ListView_SetItemText(hwnd, index, 0, lvItem.pszText); + ListView_SetItemTextA(hwnd, index, 1, module); + ListView_SetItemTextA(hwnd, index, 2, setting); + ListView_SetItemText(hwnd, index, 4, DBVType(dbv->type)); + + data[0] = 0; switch (dbv->type) { case DBVT_BLOB: { - int j; - char *data = NULL; - if (!(data = (char*)mir_realloc(data, 3 * (dbv->cpbVal + 1)))) - return; - data[0] = '\0'; - for (j = 0; j < dbv->cpbVal; j++) - { - char tmp[16]; - mir_snprintf(tmp, "%02X ", (BYTE)dbv->pbVal[j]); - mir_strcat(data, tmp); - } - ListView_SetItemText(hwnd2list, index, 4, data); - ListView_SetItemText(hwnd2list, index, 3, "BLOB"); - mir_free(data); + ptrA str(StringFromBlob(dbv->pbVal, dbv->cpbVal)); + ListView_SetItemTextA(hwnd, index, 3, str); + break; } - break; - case DBVT_BYTE: - mir_snprintf(data, SIZEOF(data), "0x%02X (%s)", dbv->bVal, itoa(dbv->bVal, tmp, 10)); - ListView_SetItemText(hwnd2list, index, 4, data); - ListView_SetItemText(hwnd2list, index, 3, "BYTE"); + mir_sntprintf(data, _T("0x%02X (%s)"), dbv->bVal, _ultot(dbv->bVal, tmp, 10)); + ListView_SetItemText(hwnd, index, 3, data); break; - case DBVT_WORD: - mir_snprintf(data, SIZEOF(data), "0x%04X (%s)", dbv->wVal, itoa(dbv->wVal, tmp, 10)); - ListView_SetItemText(hwnd2list, index, 4, data); - ListView_SetItemText(hwnd2list, index, 3, "WORD"); + mir_sntprintf(data, _T("0x%04X (%s)"), dbv->wVal, _ultot(dbv->wVal, tmp, 10)); + ListView_SetItemText(hwnd, index, 3, data); break; case DBVT_DWORD: - mir_snprintf(data, SIZEOF(data), "0x%08X (%s)", dbv->dVal, itoa(dbv->dVal, tmp, 10)); - ListView_SetItemText(hwnd2list, index, 4, data); - ListView_SetItemText(hwnd2list, index, 3, "DWORD"); + mir_sntprintf(data, _T("0x%08X (%s)"), dbv->dVal, _ultot(dbv->dVal, tmp, 10)); + ListView_SetItemText(hwnd, index, 3, data); break; case DBVT_ASCIIZ: - ListView_SetItemText(hwnd2list, index, 4, dbv->pszVal); - ListView_SetItemText(hwnd2list, index, 3, "STRING"); + ListView_SetItemTextA(hwnd, index, 3, dbv->pszVal); break; + case DBVT_WCHAR: + { + ptrT str(mir_u2t(dbv->pwszVal)); + ListView_SetItemText(hwnd, index, 3, str); + break; + } + case DBVT_UTF8: - int length = (int)mir_strlen(dbv->pszVal) + 1; - WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR)); - MultiByteToWideChar(CP_UTF8, 0, dbv->pszVal, -1, wc, length); - ListView_SetItemTextW(hwnd2list, index, 4, wc); - ListView_SetItemText(hwnd2list, index, 3, "UNICODE"); + { + ptrT str(mir_utf8decodeT(dbv->pszVal)); + ListView_SetItemText(hwnd, index, 3, str); break; } + case DBVT_DELETED: + if (IsResidentSetting(module, setting)) + ListView_SetItemText(hwnd, index, 3, TranslateT("*** resident ***")); + break; + } // switch + } -void PopulateWatchedWindow(HWND hwnd) + +void PopulateWatchedWindow() { - int i; + if (!hwnd2watchedVarsWindow) return; + HWND hwnd = GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS); ListView_DeleteAllItems(hwnd); - for (i = 0; i < WatchListArray.count; i++) - { + for (int i = 0; i < WatchListArray.count; i++) { addwatchtolist(hwnd, &(WatchListArray.item[i])); } + + if (lastColumn != -1) { + ColumnsSortParams params; + params.hList = hwnd; + params.column = lastColumn; + params.last = -1; + ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)¶ms); + } } + void freeAllWatches() { - int i; - for (i = 0; i < WatchListArray.count; i++) + ListView_DeleteAllItems(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS)); + for (int i = 0; i < WatchListArray.count; i++) { freeWatchListItem(i); } @@ -156,6 +206,7 @@ void freeAllWatches() WatchListArray.count = 0; } + int WatchDialogResize(HWND, LPARAM, UTILRESIZECONTROL *urc) { switch (urc->wId) @@ -170,45 +221,52 @@ int WatchDialogResize(HWND, LPARAM, UTILRESIZECONTROL *urc) return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; } + +LRESULT CALLBACK WatchSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + + case WM_KEYUP: + if (wParam == VK_F5) { + PopulateWatchedWindow(); + } + break; + } + return mir_callNextSubclass(hwnd, WatchSubclassProc, msg, wParam, lParam); +} + + INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: { - // setup the list... - LVCOLUMN sLC; - - sLC.fmt = LVCFMT_LEFT; - ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_VARS), 32 | LVS_EX_SUBITEMIMAGES); //LVS_EX_FULLROWSELECT - sLC.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH; - - sLC.pszText = Translate("Contact"); sLC.cx = 80; - ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 0, &sLC); - sLC.pszText = Translate("Module"); sLC.cx = 80; - ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 1, &sLC); - sLC.pszText = Translate("Setting"); sLC.cx = 80; - ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 2, &sLC); - sLC.pszText = Translate("Type"); sLC.cx = 60; - ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 3, &sLC); - sLC.pszText = Translate("Data"); sLC.cx = 300; - ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 4, &sLC); - - PopulateWatchedWindow(GetDlgItem(hwnd, IDC_VARS)); - + hwnd2watchedVarsWindow = hwnd; + // do the icon + SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT))); TranslateMenu(GetMenu(hwnd)); TranslateMenu(GetSubMenu(GetMenu(hwnd), 0)); TranslateDialogDefault(hwnd); - // do the icon - SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT))); + + SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_APPWINDOW); // taskbar icon + + ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_VARS), 32 | LVS_EX_LABELTIP); // LVS_EX_GRIDLINES + + loadListSettings(GetDlgItem(hwnd, IDC_VARS), csWatchList); + Utils_RestoreWindowPositionNoMove(hwnd, NULL, modname, "Watch_"); + + mir_subclassWindow(GetDlgItem(hwnd, IDC_VARS), WatchSubclassProc); + + PopulateWatchedWindow(); } return TRUE; // for the resize case WM_GETMINMAXINFO: { MINMAXINFO *mmi = (MINMAXINFO*)lParam; - mmi->ptMinTrackSize.x = 200; - mmi->ptMinTrackSize.y = 90; + mmi->ptMinTrackSize.x = 500; + mmi->ptMinTrackSize.y = 300; return 0; } case WM_SIZE: @@ -219,26 +277,25 @@ INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) urd.hInstance = hInst; urd.hwndDlg = hwnd; urd.lParam = 0; - urd.lpTemplate = MAKEINTRESOURCE(IDD_WATCH_DIAG); + urd.lpTemplate = MAKEINTRESOURCEA(IDD_WATCH_DIAG); urd.pfnResizer = WatchDialogResize; CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); break; - } + case WM_COMMAND: switch (LOWORD(wParam)) { case MENU_REMALL_WATCHES: freeAllWatches(); - ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_VARS)); break; case MENU_EXIT: case IDCANCEL: - hwnd2watchedVarsWindow = 0; + hwnd2watchedVarsWindow = NULL; DestroyWindow(hwnd); break; case MENU_REFRESH: - PopulateWatchedWindow(GetDlgItem(hwnd, IDC_VARS)); + PopulateWatchedWindow(); } break; @@ -246,95 +303,92 @@ INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) switch (LOWORD(wParam)) { case IDC_VARS: - switch (((NMHDR*)lParam)->code) - { + switch (((NMHDR*)lParam)->code) { case NM_DBLCLK: - { - LVHITTESTINFO hti; - LVITEM lvi; - hti.pt = ((NMLISTVIEW*)lParam)->ptAction; - if (ListView_SubItemHitTest(GetDlgItem(hwnd, IDC_VARS), &hti) > -1) { - if (hti.flags&LVHT_ONITEM) + LVHITTESTINFO hti; + LVITEM lvi; + HWND hwndVars = GetDlgItem(hwnd, IDC_VARS); + hti.pt = ((NMLISTVIEW*)lParam)->ptAction; + if (ListView_SubItemHitTest(hwndVars, &hti) > -1) { - lvi.mask = LVIF_PARAM; - lvi.iItem = hti.iItem; - lvi.iSubItem = 0; - if (ListView_GetItem(GetDlgItem(hwnd, IDC_VARS), &lvi)) + if (hti.flags&LVHT_ONITEM) { - ItemInfo ii; - ii.hContact = (MCONTACT)lvi.lParam; - ListView_GetItemText(GetDlgItem(hwnd, IDC_VARS), hti.iItem, 1, ii.module, SIZEOF(ii.module)); - ListView_GetItemText(GetDlgItem(hwnd, IDC_VARS), hti.iItem, 2, ii.setting, SIZEOF(ii.setting)); - ii.type = FW_SETTINGNAME; - SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0); + lvi.mask = LVIF_PARAM; + lvi.iItem = hti.iItem; + lvi.iSubItem = 0; + if (ListView_GetItem(hwndVars, &lvi)) + { + ItemInfo ii; + ii.hContact = (MCONTACT)lvi.lParam; + ListView_GetItemTextA(hwndVars, hti.iItem, 1, ii.module, SIZEOF(ii.module)); + ListView_GetItemTextA(hwndVars, hti.iItem, 2, ii.setting, SIZEOF(ii.setting)); + ii.type = FW_SETTINGNAME; + SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0); + } } } } - } - break; + break; + case LVN_COLUMNCLICK: + { + LPNMLISTVIEW lv = (LPNMLISTVIEW)lParam; + ColumnsSortParams params; + params.hList = GetDlgItem(hwnd, IDC_VARS); + params.column = lv->iSubItem; + params.last = lastColumn; + ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)¶ms); + lastColumn = (params.column == lastColumn) ? -1 : params.column; + break; + } } break; } break; + case WM_DESTROY: + ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_VARS)); + saveListSettings(GetDlgItem(hwnd, IDC_VARS), csWatchList); + Utils_SaveWindowPosition(hwnd, NULL, modname, "Watch_"); + hwnd2watchedVarsWindow = NULL; + break; } return 0; } -void popupWatchedVar(MCONTACT hContact, const char* module, const char* setting) +void openWatchedVarWindow() { + + if (!hwnd2watchedVarsWindow) + CreateDialog(hInst, MAKEINTRESOURCE(IDD_WATCH_DIAG), NULL, WatchDlgProc); + else + SetForegroundWindow(hwnd2watchedVarsWindow); +} + + +void popupWatchedVar(MCONTACT hContact, const char *module, const char *setting) { - HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT)); - char lpzContactName[MAX_CONTACTNAME]; - char lpzText[MAX_SECONDLINE]; COLORREF colorBack = db_get_dw(NULL, modname, "PopupColour", RGB(255, 0, 0)); - COLORREF colorText = RGB(0, 0, 0); + COLORREF colorText = db_get_dw(NULL, modname, "PopupTextColour", RGB(0, 0, 0)); int timeout = db_get_b(NULL, modname, "PopupDelay", 3); - if (hContact) { - // contacts nick - char szProto[256]; - if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto))) - mir_snprintf(lpzContactName, SIZEOF(lpzContactName), "%s (%s)", (char*)GetContactName(hContact, szProto, 0), szProto); - else - mir_snprintf(lpzContactName, SIZEOF(lpzContactName), nick_unknown); - } - else mir_strcpy(lpzContactName, Translate("Settings")); + TCHAR name[NAME_SIZE], text[MAX_SECONDLINE], value[MAX_SECONDLINE]; + int res = 0; - // 2nd line - DBVARIANT dbv; - if (GetSetting(hContact, module, setting, &dbv)) - return; + GetContactName(hContact, NULL, name, SIZEOF(name)); - switch (dbv.type) { - case DBVT_BYTE: - mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (BYTE) %d"), module, setting, dbv.bVal); - break; - case DBVT_WORD: - mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (WORD) %d"), module, setting, dbv.wVal); - break; - case DBVT_DWORD: - mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (DWORD) 0x%X"), module, setting, dbv.dVal); - break; - case DBVT_ASCIIZ: - mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: \"%s\""), module, setting, dbv.pszVal); - break; - case DBVT_UTF8: - mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value (UTF8): \"%s\""), module, setting, dbv.pszVal); - break; - default: - return; - } + // 2nd line + int type = GetValue(hContact, module, setting, value, SIZEOF(value)); +// if (!type) value = _T("NULL"); - db_free(&dbv); + mir_sntprintf(text, TranslateT("Database Setting Changed: \nModule: \"%s\", Setting: \"%s\"\nNew Value (%s): \"%s\""), _A2T(module), _A2T(setting), DBVType(type), value); - POPUPDATA ppd = { 0 }; + POPUPDATAT ppd = { 0 }; ppd.lchContact = (MCONTACT)hContact; - ppd.lchIcon = hIcon; - mir_tstrncpy(ppd.lpzContactName, lpzContactName, SIZEOF(ppd.lpzContactName)); - mir_tstrncpy(ppd.lpzText, lpzText, SIZEOF(ppd.lpzText)); + ppd.lchIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT)); + mir_tstrncpy(ppd.lptzContactName, name, SIZEOF(ppd.lptzContactName)); + mir_tstrncpy(ppd.lptzText, text, SIZEOF(ppd.lptzText)); ppd.colorBack = colorBack; ppd.colorText = colorText; ppd.iSeconds = timeout ? timeout : -1; - PUAddPopup(&ppd); + PUAddPopupT(&ppd); } -- cgit v1.2.3