summaryrefslogtreecommitdiff
path: root/plugins/DbEditorPP
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/DbEditorPP')
-rw-r--r--plugins/DbEditorPP/src/copymodule.cpp5
-rw-r--r--plugins/DbEditorPP/src/deletemodule.cpp18
-rw-r--r--plugins/DbEditorPP/src/exportimport.cpp8
-rw-r--r--plugins/DbEditorPP/src/findwindow.cpp31
-rw-r--r--plugins/DbEditorPP/src/main.cpp18
-rw-r--r--plugins/DbEditorPP/src/main_window.cpp96
-rw-r--r--plugins/DbEditorPP/src/modsettingenum.cpp4
-rw-r--r--plugins/DbEditorPP/src/moduletree.cpp185
-rw-r--r--plugins/DbEditorPP/src/renamemodule.cpp4
-rw-r--r--plugins/DbEditorPP/src/settinglist.cpp217
-rw-r--r--plugins/DbEditorPP/src/settingsdlg.cpp37
-rw-r--r--plugins/DbEditorPP/src/stdafx.h110
-rw-r--r--plugins/DbEditorPP/src/utils.cpp21
-rw-r--r--plugins/DbEditorPP/src/version.h6
-rw-r--r--plugins/DbEditorPP/src/watchedvars.cpp11
15 files changed, 378 insertions, 393 deletions
diff --git a/plugins/DbEditorPP/src/copymodule.cpp b/plugins/DbEditorPP/src/copymodule.cpp
index 00fe3d5ef7..b4b3bb10e9 100644
--- a/plugins/DbEditorPP/src/copymodule.cpp
+++ b/plugins/DbEditorPP/src/copymodule.cpp
@@ -79,16 +79,15 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
return 0;
}
-void copyModuleMenuItem(MCONTACT hContact, const char *module)
+void copyModuleMenuItem(HWND hwndParent, MCONTACT hContact, const char *module)
{
ModuleAndContact *mac = (ModuleAndContact *)mir_calloc(sizeof(ModuleAndContact));
mac->hContact = hContact;
mir_strncpy(mac->module, module, sizeof(mac->module));
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_COPY_MOD), hwnd2mainWindow, copyModDlgProc, (LPARAM)mac);
+ CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_COPY_MOD), hwndParent, copyModDlgProc, (LPARAM)mac);
}
-
int CloneContact(MCONTACT hContact)
{
MCONTACT newContact = db_add_contact();
diff --git a/plugins/DbEditorPP/src/deletemodule.cpp b/plugins/DbEditorPP/src/deletemodule.cpp
index 7c0eea7c2f..61d06228d1 100644
--- a/plugins/DbEditorPP/src/deletemodule.cpp
+++ b/plugins/DbEditorPP/src/deletemodule.cpp
@@ -3,15 +3,15 @@
volatile BOOL working;
static HWND hwnd2Delete = nullptr;
-int deleteModule(MCONTACT hContact, const char *module, int confirm)
+int deleteModule(HWND hwndParent, MCONTACT hContact, const char *module, int confirm)
{
if (!module || IsModuleEmpty(hContact, module))
return 0;
- if (confirm && g_plugin.bWarnOnDelete) {
+ if (confirm && g_plugin.bWarnOnDelete) {
wchar_t text[MSG_SIZE];
- mir_snwprintf(text, TranslateT("Are you sure you want to delete module \"%s\"?"), _A2T(module).get());
- if (dlg(text, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
+ mir_snwprintf(text, TranslateT("Are you sure you want to delete module \"%S\"?"), module);
+ if (MessageBoxW(hwndParent, text, modFullnameW, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
return 0;
}
@@ -94,10 +94,10 @@ INT_PTR CALLBACK DeleteModuleDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
GetDlgItemTextA(hwnd, IDC_CONTACTS, module, _countof(module));
SetCursor(LoadCursor(nullptr, IDC_WAIT));
for (auto &hContact : Contacts())
- deleteModule(hContact, module, 0);
+ deleteModule(0, hContact, module, 0);
// do the null
- deleteModule(NULL, module, 0);
+ deleteModule(0, NULL, module, 0);
SetCursor(LoadCursor(nullptr, IDC_ARROW));
refreshTree(1);
__fallthrough;
@@ -118,10 +118,10 @@ INT_PTR CALLBACK DeleteModuleDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
return 0;
}
-void deleteModuleDlg()
+void CMainDlg::deleteModuleDlg()
{
if (!hwnd2Delete)
- hwnd2Delete = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_COPY_MOD), hwnd2mainWindow, DeleteModuleDlgProc);
+ hwnd2Delete = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_COPY_MOD), m_hwnd, DeleteModuleDlgProc);
else
- SetForegroundWindow(hwnd2Delete);
+ ::SetForegroundWindow(hwnd2Delete);
}
diff --git a/plugins/DbEditorPP/src/exportimport.cpp b/plugins/DbEditorPP/src/exportimport.cpp
index 4ae33f26d1..8408a23215 100644
--- a/plugins/DbEditorPP/src/exportimport.cpp
+++ b/plugins/DbEditorPP/src/exportimport.cpp
@@ -153,7 +153,7 @@ void exportDB(MCONTACT hContact, const char *module)
if (Openfile(fileName, (hContact == INVALID_CONTACT_ID) ? nullptr : module, MAX_PATH)) {
FILE *file = _wfopen(fileName, L"wt");
if (!file) {
- msg(TranslateT("Couldn't open file for writing"));
+ g_pMainWindow->msg(TranslateT("Couldn't open file for writing"));
return;
}
@@ -331,7 +331,7 @@ void importSettings(MCONTACT hContact, char *utf8)
if (end = strpbrk(&importstring[i + 2], "]")) {
*end = '\0';
mir_strcpy(module, &importstring[i + 2]);
- deleteModule(hContact, module, 0);
+ deleteModule(0, hContact, module, 0);
}
}
else if (strchr(&importstring[i], '=') && module[0]) { // get the setting
@@ -445,9 +445,9 @@ INT_PTR CALLBACK ImportDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPara
return 0;
}
-void ImportSettingsMenuItem(MCONTACT hContact)
+void CMainDlg::ImportSettingsMenuItem(MCONTACT hContact)
{
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_IMPORT), hwnd2mainWindow, ImportDlgProc, hContact);
+ CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_IMPORT), m_hwnd, ImportDlgProc, hContact);
}
int Openfile2Import(wchar_t *outputFiles, int maxlen)
diff --git a/plugins/DbEditorPP/src/findwindow.cpp b/plugins/DbEditorPP/src/findwindow.cpp
index b2eb901ff5..45716efdd2 100644
--- a/plugins/DbEditorPP/src/findwindow.cpp
+++ b/plugins/DbEditorPP/src/findwindow.cpp
@@ -324,14 +324,14 @@ class CFindWindowDlg : public CDlgBase
if (replace) {
newModule = (fi->options & F_ENTIRE) ? replace : ptr = multiReplaceA(module->name, search, replace, fi->options & F_CASE);
if (!newModule[0]) {
- deleteModule(hContact, module->name, 0);
- replaceTreeItem(hContact, module->name, nullptr);
+ deleteModule(g_pMainWindow->GetHwnd(), hContact, module->name, 0);
+ g_pMainWindow->replaceTreeItem(hContact, module->name, nullptr);
flag |= F_DELETED;
newModule = module->name;
deleteCount++;
}
else if (renameModule(hContact, module->name, newModule)) {
- replaceTreeItem(hContact, module->name, nullptr);
+ g_pMainWindow->replaceTreeItem(hContact, module->name, nullptr);
flag |= F_REPLACED;
replaceCount++;
}
@@ -400,18 +400,15 @@ class CFindWindowDlg : public CDlgBase
void OpenSettings(int iItem)
{
- ItemInfo ii = {};
- ii.hContact = (MCONTACT)m_results.GetItemData(iItem);
- if (ii.hContact == -1)
+ MCONTACT hContact = (MCONTACT)m_results.GetItemData(iItem);
+ if (hContact == INVALID_CONTACT_ID)
return;
- ListView_GetItemTextA(m_results.GetHwnd(), iItem, 2, ii.module, _countof(ii.module));
- ListView_GetItemTextA(m_results.GetHwnd(), iItem, 3, ii.setting, _countof(ii.setting));
- if (ii.setting[0])
- ii.type = FW_SETTINGNAME;
- else if (ii.module[0])
- ii.type = FW_MODULE;
- SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0);
+ char szModule[NAME_SIZE], szSetting[NAME_SIZE];
+ ListView_GetItemTextA(m_results.GetHwnd(), iItem, 2, szModule, _countof(szModule));
+ ListView_GetItemTextA(m_results.GetHwnd(), iItem, 3, szSetting, _countof(szSetting));
+
+ g_pMainWindow->FindItem((szSetting[0]) ? FW_SETTINGNAME : FW_MODULE, hContact, szModule, szSetting);
}
CCtrlBase m_sb;
@@ -420,7 +417,7 @@ class CFindWindowDlg : public CDlgBase
CCtrlListView m_results;
public:
- CFindWindowDlg(HWND hwndParent) :
+ CFindWindowDlg() :
CDlgBase(g_plugin, IDD_FIND),
m_sb(this, IDC_SBAR),
m_results(this, IDC_LIST),
@@ -433,7 +430,7 @@ public:
chkReplaceAll(this, IDC_ENTIRELY),
chkCaseSensitive(this, IDC_CASESENSITIVE)
{
- SetParent(hwndParent);
+ SetParent(g_pMainWindow->GetHwnd());
SetMinSize(610, 300);
CreateLink(chkModules, g_bSearchModule);
@@ -555,12 +552,12 @@ public:
params.hList = m_results.GetHwnd();
params.column = ev->nmlv->iSubItem;
params.last = lastColumn;
- ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)&params);
+ m_results.SortItemsEx(ColumnsCompare, (LPARAM)&params);
lastColumn = (params.column == lastColumn) ? -1 : params.column;
}
};
void newFindWindow()
{
- (new CFindWindowDlg(hwnd2mainWindow))->Create();
+ (new CFindWindowDlg())->Create();
}
diff --git a/plugins/DbEditorPP/src/main.cpp b/plugins/DbEditorPP/src/main.cpp
index b7c9c4fc6b..feade7ed71 100644
--- a/plugins/DbEditorPP/src/main.cpp
+++ b/plugins/DbEditorPP/src/main.cpp
@@ -55,8 +55,8 @@ static int DBSettingChanged(WPARAM hContact, LPARAM lParam)
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam;
// setting list
- if (hwnd2mainWindow)
- settingChanged(hContact, cws->szModule, cws->szSetting, &(cws->value));
+ if (g_pMainWindow)
+ g_pMainWindow->onSettingChanged(hContact, cws);
// watch list
if (!hwnd2watchedVarsWindow && !g_bUsePopups)
@@ -72,13 +72,13 @@ static int DBSettingChanged(WPARAM hContact, LPARAM lParam)
INT_PTR DBEditorppMenuCommand(WPARAM wParam, LPARAM)
{
- if (!hwnd2mainWindow) { // so only opens 1 at a time
+ if (!g_pMainWindow) { // so only opens 1 at a time
hRestore = wParam;
(new CMainDlg())->Create();
}
else {
- ShowWindow(hwnd2mainWindow, SW_RESTORE);
- SetForegroundWindow(hwnd2mainWindow);
+ ShowWindow(g_pMainWindow->GetHwnd(), SW_RESTORE);
+ SetForegroundWindow(g_pMainWindow->GetHwnd());
if (!hRestore && wParam) {
hRestore = wParam;
refreshTree(4);
@@ -140,8 +140,10 @@ static int ModulesLoaded(WPARAM, LPARAM)
static int PreShutdown(WPARAM, LPARAM)
{
- if (hwnd2watchedVarsWindow) DestroyWindow(hwnd2watchedVarsWindow);
- if (hwnd2mainWindow) DestroyWindow(hwnd2mainWindow);
+ if (hwnd2watchedVarsWindow)
+ DestroyWindow(hwnd2watchedVarsWindow);
+ if (g_pMainWindow)
+ g_pMainWindow->Close();
return 0;
}
@@ -163,8 +165,6 @@ static INT_PTR ImportFromFile(WPARAM wParam, LPARAM lParam)
int CMPlugin::Load()
{
- hwnd2mainWindow = nullptr;
-
hRestore = NULL;
g_db = db_get_current();
diff --git a/plugins/DbEditorPP/src/main_window.cpp b/plugins/DbEditorPP/src/main_window.cpp
index 4eb8e0e128..4c1b9af097 100644
--- a/plugins/DbEditorPP/src/main_window.cpp
+++ b/plugins/DbEditorPP/src/main_window.cpp
@@ -1,7 +1,5 @@
#include "stdafx.h"
-HWND hwnd2mainWindow;
-
static HIMAGELIST hImg = nullptr;
int g_Hex;
@@ -9,13 +7,12 @@ int g_Mode;
int g_Order;
int g_Inline;
+CMainDlg *g_pMainWindow = nullptr;
+
extern volatile BOOL populating, skipEnter;
extern volatile int Select;
extern SettingListInfo info;
-extern struct ColumnsSettings csSettingList[];
-extern HWND hwnd2List;
-extern HWND hwnd2Tree;
void EditFinish(int selected);
void EditLabel(int item, int subitem);
@@ -55,7 +52,7 @@ static LRESULT CALLBACK ModuleTreeSubclassProc(HWND hwnd, UINT msg, WPARAM wPara
MCONTACT hContact = mtis->hContact;
if (wParam == VK_DELETE) {
if ((mtis->type) & MODULE) {
- if (deleteModule(hContact, _T2A(text), 1)) {
+ if (deleteModule(g_pMainWindow->GetHwnd(), hContact, _T2A(text), 1)) {
mir_free(mtis);
TreeView_DeleteItem(hwnd, tvi.hItem);
}
@@ -64,11 +61,11 @@ static LRESULT CALLBACK ModuleTreeSubclassProc(HWND hwnd, UINT msg, WPARAM wPara
if (db_get_b(0, "CList", "ConfirmDelete", 1)) {
wchar_t str[MSG_SIZE];
mir_snwprintf(str, TranslateT("Are you sure you want to delete contact \"%s\"?"), text);
- if (dlg(str, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
+ if (g_pMainWindow->dlg(str, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
break;
}
db_delete_contact(hContact);
- freeTree(mtis->hContact);
+ g_pMainWindow->freeTree(mtis->hContact);
TreeView_DeleteItem(hwnd, tvi.hItem);
}
}
@@ -99,7 +96,7 @@ static LRESULT CALLBACK SettingListSubclassProc(HWND hwnd, UINT msg, WPARAM wPar
case WM_KEYDOWN:
if (wParam == VK_F5)
- PopulateSettings(info.hContact, info.module);
+ g_pMainWindow->PopulateSettings(info.hContact, info.module);
else if (wParam == VK_F3)
newFindWindow();
else if (wParam == VK_DELETE || (wParam == VK_F2 && ListView_GetSelectedCount(hwnd) == 1)) {
@@ -109,9 +106,9 @@ static LRESULT CALLBACK SettingListSubclassProc(HWND hwnd, UINT msg, WPARAM wPar
ListView_GetItemTextA(hwnd, idx, 0, setting, _countof(setting));
if (wParam == VK_F2)
- editSetting(info.hContact, info.module, setting);
+ g_pMainWindow->editSetting(info.hContact, info.module, setting);
else if (wParam == VK_DELETE)
- DeleteSettingsFromList(info.hContact, info.module, setting);
+ g_pMainWindow->DeleteSettingsFromList(info.hContact, info.module, setting);
return 0;
}
@@ -168,11 +165,19 @@ CMainDlg::CMainDlg() :
m_settings.OnBuildMenu = Callback(this, &CMainDlg::onContextMenu_Settings);
}
+static ColumnsSettings csSettingList[] =
+{
+ { LPGENW("Name"), 0, "Column0width", 180 },
+ { LPGENW("Value"), 1, "Column1width", 250 },
+ { LPGENW("Type"), 2, "Column2width", 60 },
+ { LPGENW("Size"), 3, "Column3width", 80 },
+ { LPGENW("#"), 4, "Column4width", 30 },
+ { nullptr }
+};
+
bool CMainDlg::OnInitDialog()
{
- hwnd2mainWindow = m_hwnd;
- hwnd2Tree = GetDlgItem(m_hwnd, IDC_MODULES);
- hwnd2List = GetDlgItem(m_hwnd, IDC_SETTINGS);
+ g_pMainWindow = this;
LoadResidentSettings();
@@ -184,13 +189,13 @@ bool CMainDlg::OnInitDialog()
SetWindowText(m_hwnd, TranslateT("Database Editor++"));
// module tree
- mir_subclassWindow(hwnd2Tree, ModuleTreeSubclassProc);
+ mir_subclassWindow(m_modules.GetHwnd(), ModuleTreeSubclassProc);
m_modules.SetImageList(hImg, TVSIL_NORMAL);
//setting list
- mir_subclassWindow(hwnd2List, SettingListSubclassProc);
+ mir_subclassWindow(m_settings.GetHwnd(), SettingListSubclassProc);
m_settings.SetExtendedListViewStyle(32 | LVS_EX_SUBITEMIMAGES | LVS_EX_LABELTIP); //LVS_EX_GRIDLINES
- loadListSettings(hwnd2List, csSettingList);
+ loadListSettings(m_settings.GetHwnd(), csSettingList);
m_settings.SetImageList(hImg, LVSIL_SMALL);
HMENU hMenu = GetMenu(m_hwnd);
@@ -236,14 +241,14 @@ void CMainDlg::OnDestroy()
if (g_plugin.bRestoreOnOpen) {
HTREEITEM item;
- if (item = TreeView_GetSelection(hwnd2Tree)) {
+ if (item = m_modules.GetSelection()) {
int type = MODULE;
- TVITEM tvi = {};
+ TVITEMEX tvi = {};
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
tvi.pszText = text;
tvi.cchTextMax = _countof(text);
tvi.hItem = item;
- if (TreeView_GetItem(hwnd2Tree, &tvi)) {
+ if (m_modules.GetItem(&tvi)) {
MCONTACT hContact = 0;
if (tvi.lParam) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
@@ -263,11 +268,11 @@ void CMainDlg::OnDestroy()
g_plugin.delSetting("LastModule");
}
- int pos = ListView_GetSelectionMark(hwnd2List);
+ int pos = m_settings.GetSelectionMark();
if (pos != -1) {
char data[FLD_SIZE];
- ListView_GetItemTextA(hwnd2List, pos, 0, data, _countof(data));
+ ListView_GetItemTextA(m_settings.GetHwnd(), pos, 0, data, _countof(data));
g_plugin.setString("LastSetting", data);
}
else
@@ -291,14 +296,12 @@ void CMainDlg::OnDestroy()
Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, "Main_");
ShowWindow(m_hwnd, SW_HIDE);
- saveListSettings(hwnd2List, csSettingList);
+ saveListSettings(m_settings.GetHwnd(), csSettingList);
ClearListView();
freeTree(0);
- hwnd2mainWindow = nullptr;
- hwnd2Tree = nullptr;
- hwnd2List = nullptr;
+ g_pMainWindow = nullptr;
if (hImg) {
ImageList_Destroy(hImg);
@@ -366,16 +369,14 @@ void CMainDlg::onChange_Splitter(CSplitter *)
PostMessage(m_hwnd, WM_SIZE, 0, 0);
}
-LRESULT CMainDlg::OnFindItem(UINT, WPARAM wParam, LPARAM)
+void CMainDlg::FindItem(int type, MCONTACT hContact, const char *szModule, const char *szSetting)
{
- ItemInfo *ii = (ItemInfo *)wParam;
- if (HTREEITEM hItem = findItemInTree(ii->hContact, ii->module)) {
+ if (HTREEITEM hItem = findItemInTree(hContact, szModule)) {
m_modules.SelectItem(hItem);
m_modules.Expand(hItem, TVE_EXPAND);
- if (ii->type != FW_MODULE)
- SelectSetting(ii->setting);
+ if (type != FW_MODULE)
+ SelectSetting(szSetting);
}
- return 0;
}
LRESULT CMainDlg::OnCommand(UINT, WPARAM wParam, LPARAM)
@@ -391,12 +392,12 @@ LRESULT CMainDlg::OnCommand(UINT, WPARAM wParam, LPARAM)
break;
case MENU_REFRESH_SETS:
- TVITEM tvi;
+ TVITEMEX tvi;
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
- tvi.hItem = TreeView_GetSelection(hwnd2Tree);
+ tvi.hItem = m_modules.GetSelection();
tvi.pszText = text; // modulename
tvi.cchTextMax = _countof(text);
- if (TreeView_GetItem(hwnd2Tree, &tvi)) {
+ if (m_modules.GetItem(&tvi)) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
if (mtis && (mtis->type == MODULE))
PopulateSettings(mtis->hContact, _T2A(text));
@@ -438,10 +439,10 @@ LRESULT CMainDlg::OnCommand(UINT, WPARAM wParam, LPARAM)
newFindWindow();
break;
case MENU_FIX_RESIDENT:
- if (dlg(TranslateT("Delete resident settings from database?"), MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
+ if (g_pMainWindow->dlg(TranslateT("Delete resident settings from database?"), MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
int cnt = fixResidentSettings();
mir_snwprintf(text, TranslateT("%d items deleted."), cnt);
- msg(text);
+ g_pMainWindow->msg(text);
}
break;
case MENU_FILTER_ALL:
@@ -522,10 +523,10 @@ void CMainDlg::onItemExpand_Modules(CCtrlTreeView::TEventInfo *ev)
return;
ModSetLinkLinkItem *module = modlist.first;
- while (module && hwnd2mainWindow) {
- if (module->name[0] && !IsModuleEmpty(hContact, module->name)) {
+ while (module && g_pMainWindow) {
+ if (module->name[0] && !IsModuleEmpty(hContact, module->name))
insertItem(hContact, module->name, ev->nmtv->itemNew.hItem);
- }
+
module = (ModSetLinkLinkItem *)module->next;
}
@@ -567,7 +568,7 @@ void CMainDlg::onSelChanged_Modules(CCtrlTreeView::TEventInfo *ev)
hContact = db_find_first();
}
- while (hContact && hwnd2mainWindow) {
+ while (hContact && g_pMainWindow) {
if (multi && ApplyProtoFilter(hContact)) {
hContact = db_find_next(hContact);
continue;
@@ -653,18 +654,15 @@ void CMainDlg::onDblClick_Settings(CCtrlListView::TEventInfo *ev)
LVITEM lvi = {};
lvi.mask = LVIF_PARAM;
lvi.iItem = hti.iItem;
- if (m_settings.GetItem(&lvi)) {
- ItemInfo ii = {};
- ii.hContact = (MCONTACT)lvi.lParam;
- OnFindItem(0, (WPARAM)&ii, 0);
- }
+ if (m_settings.GetItem(&lvi))
+ FindItem(FW_MODULE, (MCONTACT)lvi.lParam, "", "");
return;
}
if (!g_Inline || hti.iSubItem > 1 || hti.flags == LVHT_ONITEMICON) {
char setting[FLD_SIZE];
EditFinish(hti.iItem);
- if (ListView_GetItemTextA(hwnd2List, hti.iItem, 0, setting, _countof(setting)))
+ if (ListView_GetItemTextA(m_settings.GetHwnd(), hti.iItem, 0, setting, _countof(setting)))
editSetting(info.hContact, info.module, setting);
}
else EditLabel(hti.iItem, hti.iSubItem);
@@ -673,9 +671,9 @@ void CMainDlg::onDblClick_Settings(CCtrlListView::TEventInfo *ev)
void CMainDlg::onColumnClick_Settings(CCtrlListView::TEventInfo *ev)
{
ColumnsSortParams params = {};
- params.hList = hwnd2List;
+ params.hList = m_settings.GetHwnd();
params.column = ev->nmlv->iSubItem;
params.last = lastColumn;
- ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)&params);
+ m_settings.SortItemsEx(ColumnsCompare, (LPARAM)&params);
lastColumn = (params.column == lastColumn) ? -1 : params.column;
}
diff --git a/plugins/DbEditorPP/src/modsettingenum.cpp b/plugins/DbEditorPP/src/modsettingenum.cpp
index 630096c738..0a693640fa 100644
--- a/plugins/DbEditorPP/src/modsettingenum.cpp
+++ b/plugins/DbEditorPP/src/modsettingenum.cpp
@@ -48,7 +48,7 @@ int EnumModules(ModuleSettingLL *msll) // 1 = success, 0 = fail
msll->first = nullptr;
msll->last = nullptr;
if (db_enum_modules(enumModulesSettingsProc, msll)) {
- msg(TranslateT("Error loading module list"));
+ g_pMainWindow->msg(TranslateT("Error loading module list"));
return 0;
}
return 1;
@@ -65,7 +65,7 @@ int EnumSettings(MCONTACT hContact, const char *module, ModuleSettingLL *msll)
msll->first = nullptr;
msll->last = nullptr;
if (db_enum_settings(hContact, enumSettingsProc, module, msll)) {
- msg(TranslateT("Error loading setting list"));
+ g_pMainWindow->msg(TranslateT("Error loading setting list"));
return 0;
}
return 1;
diff --git a/plugins/DbEditorPP/src/moduletree.cpp b/plugins/DbEditorPP/src/moduletree.cpp
index 1cf5248935..28a11910fc 100644
--- a/plugins/DbEditorPP/src/moduletree.cpp
+++ b/plugins/DbEditorPP/src/moduletree.cpp
@@ -1,14 +1,12 @@
#include "stdafx.h"
-HWND hwnd2Tree = nullptr;
-
volatile BOOL populating = 0, skipEnter = 0;
volatile int Select = 0;
static ModuleTreeInfoStruct contacts_mtis = { CONTACT_ROOT_ITEM, 0 };
static ModuleTreeInfoStruct settings_mtis = { CONTACT, 0 };
-void insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent)
+void CMainDlg::insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent)
{
_A2T text(module);
@@ -26,10 +24,10 @@ void insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent)
lParam->type = MODULE;
tvi.item.lParam = (LPARAM)lParam;
- TreeView_InsertItem(hwnd2Tree, &tvi);
+ m_modules.InsertItem(&tvi);
}
-int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelectedContact, const char *selectedModule, const char *selectedSetting)
+int CMainDlg::doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelectedContact, const char *selectedModule, const char *selectedSetting)
{
TVINSERTSTRUCT tvi;
HTREEITEM contact;
@@ -38,7 +36,7 @@ int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelec
int icon = 0;
HTREEITEM hItem = nullptr;
- SetWindowText(hwnd2mainWindow, TranslateT("Loading contacts..."));
+ SetCaption(TranslateT("Loading contacts..."));
tvi.hInsertAfter = TVI_SORT;
tvi.item.cChildren = 1;
@@ -71,13 +69,12 @@ int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelec
tvi.item.pszText = name;
tvi.item.iImage = icon;
tvi.item.iSelectedImage = icon;
-
- contact = TreeView_InsertItem(hwnd2Tree, &tvi);
+ contact = m_modules.InsertItem(&tvi);
itemscount++;
if (hSelectedContact == hContact) {
- for (ModSetLinkLinkItem *module = modlist->first; module && hwnd2mainWindow; module = module->next) {
+ for (ModSetLinkLinkItem *module = modlist->first; module && g_pMainWindow; module = module->next) {
if (!module->name[0] || IsModuleEmpty(hContact, module->name))
continue;
insertItem(hContact, module->name, contact);
@@ -88,8 +85,8 @@ int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelec
}
if (hItem) {
- TreeView_SelectItem(hwnd2Tree, hItem);
- TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
+ m_modules.SelectItem(hItem);
+ m_modules.Expand(hItem, TVE_EXPAND);
if (selectedSetting && selectedSetting[0])
SelectSetting(selectedSetting);
}
@@ -97,26 +94,24 @@ int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelec
return itemscount;
}
-void doItems(ModuleSettingLL* modlist, int count)
+void CMainDlg::doItems(ModuleSettingLL *modlist, int count)
{
- HWND hwnd = GetParent(hwnd2Tree); //!!!
-
- wchar_t percent[128], title[96];
+ wchar_t title[96];
mir_snwprintf(title, TranslateT("Loading modules..."));
- TVITEM item = {};
+ TVITEMEX item = {};
item.mask = TVIF_STATE | TVIF_PARAM;
- HTREEITEM contact = TreeView_GetChild(hwnd2Tree, TVI_ROOT);
- contact = TreeView_GetNextSibling(hwnd2Tree, contact);
- contact = TreeView_GetChild(hwnd2Tree, contact);
+ HTREEITEM contact = m_modules.GetChild(TVI_ROOT);
+ contact = m_modules.GetNextSibling(contact);
+ contact = m_modules.GetChild(contact);
MCONTACT hContact = 0;
- for (int i = 1; contact && hwnd2mainWindow; i++) {
+ for (int i = 1; contact && g_pMainWindow; i++) {
item.hItem = contact;
- contact = TreeView_GetNextSibling(hwnd2Tree, contact);
+ contact = m_modules.GetNextSibling(contact);
- if (TreeView_GetItem(hwnd2Tree, &item) && item.lParam) {
+ if (m_modules.GetItem(&item) && item.lParam) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)item.lParam;
hContact = mtis->hContact;
if (hContact == NULL || mtis->type != (CONTACT | EMPTY))
@@ -127,10 +122,11 @@ void doItems(ModuleSettingLL* modlist, int count)
continue;
// Caption
+ wchar_t percent[128];
mir_snwprintf(percent, L"%s %d%%", title, (int)(100 * i / count));
- SetWindowText(hwnd, percent);
+ SetCaption(percent);
- for (ModSetLinkLinkItem *module = modlist->first; module && hwnd2mainWindow; module = module->next) {
+ for (ModSetLinkLinkItem *module = modlist->first; module && g_pMainWindow; module = module->next) {
if (!module->name[0] || IsModuleEmpty(hContact, module->name))
continue;
@@ -138,34 +134,34 @@ void doItems(ModuleSettingLL* modlist, int count)
}
}
- SetWindowText(hwnd2mainWindow, TranslateT("Database Editor++"));
+ SetCaption(TranslateT("Database Editor++"));
}
/////////////////////////////////////////////////////////////////////////////////////////
// the following code to go through the whole tree is nicked from codeguru..
// http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?thread=7680
-HTREEITEM findItemInTree(MCONTACT hContact, const char* module)
+HTREEITEM CMainDlg::findItemInTree(MCONTACT hContact, const char *module)
{
- TVITEM item;
- HTREEITEM lastItem;
- wchar_t text[FLD_SIZE];
-
- if (!TreeView_GetCount(hwnd2Tree))
+ if (!m_modules.GetCount())
return nullptr;
_A2T szModule(module);
+ wchar_t text[FLD_SIZE];
+ TVITEMEX item;
item.mask = TVIF_STATE | TVIF_PARAM | TVIF_TEXT;
item.hItem = TVI_ROOT;
item.pszText = text;
item.cchTextMax = _countof(text);
+
+ HTREEITEM lastItem;
do {
do {
lastItem = item.hItem;
if (lastItem != TVI_ROOT) {
/* these next 2 lines are not from code guru..... */
- if (TreeView_GetItem(hwnd2Tree, &item) && item.lParam) {
+ if (m_modules.GetItem(&item) && item.lParam) {
if ((hContact == ((ModuleTreeInfoStruct *)item.lParam)->hContact) && (!module || !module[0] || !mir_wstrcmp(szModule, text))) {
return item.hItem;
@@ -173,9 +169,9 @@ HTREEITEM findItemInTree(MCONTACT hContact, const char* module)
}
/* back to coduguru's code*/
}
- } while ((item.hItem = TreeView_GetChild(hwnd2Tree, lastItem)));
+ } while ((item.hItem = m_modules.GetChild(lastItem)));
- while ((!(item.hItem = TreeView_GetNextSibling(hwnd2Tree, lastItem))) && (lastItem = item.hItem = TreeView_GetParent(hwnd2Tree, lastItem)));
+ while ((!(item.hItem = m_modules.GetNextSibling(lastItem))) && (lastItem = item.hItem = m_modules.GetParent(lastItem)));
} while (item.hItem);
@@ -186,27 +182,28 @@ HTREEITEM findItemInTree(MCONTACT hContact, const char* module)
// the following code to go through the whole tree is nicked from codeguru..
// http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?thread=7680
-void freeTree(MCONTACT hContact)
+void CMainDlg::freeTree(MCONTACT hContact)
{
- TVITEM item;
- HTREEITEM lastItem;
- if (!TreeView_GetCount(hwnd2Tree))
+ if (!m_modules.GetCount())
return;
+ TVITEMEX item;
item.mask = TVIF_STATE | TVIF_PARAM;
item.hItem = TVI_ROOT;
+
+ HTREEITEM lastItem;
do {
do {
lastItem = item.hItem;
if (lastItem != TVI_ROOT) {
- TreeView_GetItem(hwnd2Tree, &item);
+ m_modules.GetItem(&item);
/* these next 2 lines are not from code guru..... */
if (item.lParam) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)item.lParam;
if (!hContact || (hContact == mtis->hContact)) {
if (hContact != NULL) {
- TreeView_DeleteItem(hwnd2Tree, item.hItem);
+ m_modules.DeleteItem(item.hItem);
mir_free(mtis);
}
else
@@ -215,25 +212,27 @@ void freeTree(MCONTACT hContact)
}
/* back to coduguru's code*/
}
- } while (item.hItem = TreeView_GetChild(hwnd2Tree, lastItem));
-
- while (!(item.hItem = TreeView_GetNextSibling(hwnd2Tree, lastItem)) && (lastItem = item.hItem = TreeView_GetParent(hwnd2Tree, lastItem))) {}
+ }
+ while (item.hItem = m_modules.GetChild(lastItem));
- } while (item.hItem);
+ while (!(item.hItem = m_modules.GetNextSibling(lastItem)) && (lastItem = item.hItem = m_modules.GetParent(lastItem)))
+ ;
+ }
+ while (item.hItem);
}
/////////////////////////////////////////////////////////////////////////////////////////
// the following code to go through the whole tree is nicked from codeguru..
// http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?thread=7680
-BOOL findAndRemoveDuplicates(MCONTACT hContact, const char *module)
+BOOL CMainDlg::findAndRemoveDuplicates(MCONTACT hContact, const char *module)
{
- TVITEM item;
+ TVITEMEX item;
HTREEITEM lastItem, prelastItem;
BOOL Result = 0;
wchar_t text[FLD_SIZE];
- if (!TreeView_GetCount(hwnd2Tree))
+ if (!m_modules.GetCount())
return Result;
_A2T szModule(module);
@@ -248,13 +247,13 @@ BOOL findAndRemoveDuplicates(MCONTACT hContact, const char *module)
do {
lastItem = item.hItem;
if (lastItem != TVI_ROOT) {
- TreeView_GetItem(hwnd2Tree, &item);
+ m_modules.GetItem(&item);
/* these next lines are not from code guru..... */
if (item.lParam) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)item.lParam;
if (hContact == mtis->hContact && !mir_wstrcmp(text, szModule)) {
mir_free(mtis);
- TreeView_DeleteItem(hwnd2Tree, item.hItem);
+ m_modules.DeleteItem(item.hItem);
lastItem = prelastItem;
Result = 1;
}
@@ -263,9 +262,9 @@ BOOL findAndRemoveDuplicates(MCONTACT hContact, const char *module)
}
/* back to coduguru's code*/
}
- } while (item.hItem = TreeView_GetChild(hwnd2Tree, lastItem));
+ } while (item.hItem = m_modules.GetChild(lastItem));
- while (!(item.hItem = TreeView_GetNextSibling(hwnd2Tree, lastItem)) && (lastItem = item.hItem = TreeView_GetParent(hwnd2Tree, lastItem))) {}
+ while (!(item.hItem = m_modules.GetNextSibling(lastItem)) && (lastItem = item.hItem = m_modules.GetParent(lastItem))) {}
} while (item.hItem);
/*****************************************************************************/
@@ -273,23 +272,22 @@ BOOL findAndRemoveDuplicates(MCONTACT hContact, const char *module)
return Result;
}
-void replaceTreeItem(MCONTACT hContact, const char* module, const char* newModule)
+void CMainDlg::replaceTreeItem(MCONTACT hContact, const char* module, const char* newModule)
{
HTREEITEM hItem = findItemInTree(hContact, module);
-
if (!hItem)
return;
- TVITEM item;
+ TVITEMEX item;
item.mask = TVIF_PARAM;
item.hItem = hItem;
- HTREEITEM hParent = TreeView_GetParent(hwnd2Tree, hItem);
+ HTREEITEM hParent = m_modules.GetParent(hItem);
- if (TreeView_GetItem(hwnd2Tree, &item))
+ if (m_modules.GetItem(&item))
mir_free((ModuleTreeInfoStruct *)item.lParam);
- TreeView_DeleteItem(hwnd2Tree, item.hItem);
+ m_modules.DeleteItem(item.hItem);
if (!newModule)
return;
@@ -300,37 +298,31 @@ void replaceTreeItem(MCONTACT hContact, const char* module, const char* newModul
}
}
-void __cdecl PopulateModuleTreeThreadFunc(LPVOID param)
+void __cdecl CMainDlg::PopulateModuleTreeThreadFunc(void *param)
{
char SelectedModule[FLD_SIZE] = "";
char SelectedSetting[FLD_SIZE] = "";
MCONTACT hSelectedContact = hRestore;
- MCONTACT hContact;
- HTREEITEM contact, contactsRoot;
- int count;
-
- // module list
- ModuleSettingLL modlist;
-
+
hRestore = NULL;
- if (!hwnd2Tree)
+ if (!g_pMainWindow)
return;
Select = 0;
switch ((INT_PTR)param) {
case 1: // restore after rebuild
- if (HTREEITEM item = TreeView_GetSelection(hwnd2Tree)) {
+ if (HTREEITEM item = g_pMainWindow->m_modules.GetSelection()) {
wchar_t text[FLD_SIZE];
- TVITEM tvi = {};
+ TVITEMEX tvi = {};
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
tvi.pszText = text;
tvi.cchTextMax = _countof(text);
tvi.hItem = item;
- TreeView_GetItem(hwnd2Tree, &tvi);
+ g_pMainWindow->m_modules.GetItem(&tvi);
if (tvi.lParam) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
hSelectedContact = mtis->hContact;
@@ -360,17 +352,19 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID param)
}
if ((INT_PTR)param != 4) { // do not rebuild on just going to another setting
- TVINSERTSTRUCT tvi;
+ ModuleSettingLL modlist;
if (!EnumModules(&modlist))
return;
// remove all items (incase there are items there...
- freeTree(0);
- TreeView_DeleteAllItems(hwnd2Tree);
- TreeView_SelectItem(hwnd2Tree, 0);
+ g_pMainWindow->freeTree(0);
+ g_pMainWindow->m_modules.DeleteAllItems();
+ g_pMainWindow->m_modules.SelectItem(0);
/// contact root item
contacts_mtis.type = CONTACT_ROOT_ITEM;
+
+ TVINSERTSTRUCT tvi;
tvi.item.lParam = (LPARAM)&contacts_mtis;
tvi.hParent = nullptr;
tvi.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_STATE | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
@@ -382,7 +376,7 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID param)
tvi.item.pszText = TranslateT("Contacts");
tvi.item.iImage = IMAGE_CONTACTS;
tvi.item.iSelectedImage = IMAGE_CONTACTS;
- contactsRoot = TreeView_InsertItem(hwnd2Tree, &tvi);
+ HTREEITEM contactsRoot = g_pMainWindow->m_modules.InsertItem(&tvi);
// add the settings item
settings_mtis.type = STUB;
@@ -394,60 +388,59 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID param)
tvi.item.pszText = TranslateT("Settings");
tvi.item.iImage = IMAGE_SETTINGS;
tvi.item.iSelectedImage = IMAGE_SETTINGS;
- contact = TreeView_InsertItem(hwnd2Tree, &tvi);
+ HTREEITEM contact = g_pMainWindow->m_modules.InsertItem(&tvi);
// to fix bug with CHANGE NOTIFY on window activation
- TreeView_SelectItem(hwnd2Tree, contact);
+ g_pMainWindow->m_modules.SelectItem(contact);
settings_mtis.type = CONTACT;
- hContact = 0;
- for (ModSetLinkLinkItem *module = modlist.first; module && hwnd2mainWindow; module = module->next) {
+ MCONTACT hContact = 0;
+ for (ModSetLinkLinkItem *module = modlist.first; module && g_pMainWindow; module = module->next) {
if (!module->name[0] || IsModuleEmpty(hContact, module->name))
continue;
- insertItem(hContact, module->name, contact);
+ g_pMainWindow->insertItem(hContact, module->name, contact);
}
if (g_plugin.bExpandSettingsOnOpen)
- TreeView_Expand(hwnd2Tree, contact, TVE_EXPAND);
+ g_pMainWindow->m_modules.Expand(contact, TVE_EXPAND);
if (Select && hSelectedContact == NULL) {
- HTREEITEM hItem = findItemInTree(hSelectedContact, SelectedModule);
+ HTREEITEM hItem = g_pMainWindow->findItemInTree(hSelectedContact, SelectedModule);
if (hItem) {
- TreeView_SelectItem(hwnd2Tree, hItem);
- TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
+ g_pMainWindow->m_modules.SelectItem(hItem);
+ g_pMainWindow->m_modules.Expand(hItem, TVE_EXPAND);
if (SelectedSetting[0])
- SelectSetting(SelectedSetting);
+ g_pMainWindow->SelectSetting(SelectedSetting);
}
Select = 0;
}
- count = doContacts(contactsRoot, &modlist, Select ? hSelectedContact : NULL, SelectedModule, SelectedSetting);
+ int count = g_pMainWindow->doContacts(contactsRoot, &modlist, Select ? hSelectedContact : NULL, SelectedModule, SelectedSetting);
Select = 0;
- doItems(&modlist, count);
+ g_pMainWindow->doItems(&modlist, count);
FreeModuleSettingLL(&modlist);
}
if (Select) {
- HTREEITEM hItem = findItemInTree(hSelectedContact, SelectedModule);
+ HTREEITEM hItem = g_pMainWindow->findItemInTree(hSelectedContact, SelectedModule);
if (hItem) {
- TreeView_SelectItem(hwnd2Tree, hItem);
- TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
+ g_pMainWindow->m_modules.SelectItem(hItem);
+ g_pMainWindow->m_modules.Expand(hItem, TVE_EXPAND);
if (SelectedSetting[0])
- SelectSetting(SelectedSetting);
+ g_pMainWindow->SelectSetting(SelectedSetting);
}
}
populating = 0;
-
}
-void refreshTree(int restore)
+void refreshTree(BOOL restore)
{
if (populating)
return;
populating = 1;
- mir_forkthread(PopulateModuleTreeThreadFunc, (HWND)restore);
+ mir_forkthread(&CMainDlg::PopulateModuleTreeThreadFunc, (HWND)restore);
}
// hwnd here is to the main window, NOT the treview
@@ -503,14 +496,14 @@ void CMainDlg::onContextMenu_Modules(CContextMenuPos *pos)
break;
case MENU_DELETE_MOD:
- if (deleteModule(hContact, module, 1)) {
+ if (deleteModule(m_hwnd, hContact, module, 1)) {
m_modules.DeleteItem(pos->hItem);
mir_free(mtis);
}
break;
case MENU_COPY_MOD:
- copyModuleMenuItem(hContact, module);
+ copyModuleMenuItem(m_hwnd, hContact, module);
break;
////////////////////////////////////////////////////////////////////// divider
@@ -548,7 +541,7 @@ void CMainDlg::onContextMenu_Modules(CContextMenuPos *pos)
if (db_get_b(0, "CList", "ConfirmDelete", 1)) {
wchar_t str[MSG_SIZE];
mir_snwprintf(str, TranslateT("Are you sure you want to delete contact \"%s\"?"), text);
- if (dlg(str, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
+ if (g_pMainWindow->dlg(str, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
break;
}
db_delete_contact(hContact);
diff --git a/plugins/DbEditorPP/src/renamemodule.cpp b/plugins/DbEditorPP/src/renamemodule.cpp
index cb0359d930..0c08ca0690 100644
--- a/plugins/DbEditorPP/src/renamemodule.cpp
+++ b/plugins/DbEditorPP/src/renamemodule.cpp
@@ -61,7 +61,7 @@ static INT_PTR CALLBACK AddModDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
return 0;
}
-void addModuleDlg(MCONTACT hContact)
+void CMainDlg::addModuleDlg(MCONTACT hContact)
{
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ADD_MODULE), hwnd2mainWindow, AddModDlgProc, hContact);
+ CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ADD_MODULE), m_hwnd, AddModDlgProc, hContact);
}
diff --git a/plugins/DbEditorPP/src/settinglist.cpp b/plugins/DbEditorPP/src/settinglist.cpp
index 7e83cb9373..4a54f42e24 100644
--- a/plugins/DbEditorPP/src/settinglist.cpp
+++ b/plugins/DbEditorPP/src/settinglist.cpp
@@ -1,34 +1,6 @@
#include "stdafx.h"
SettingListInfo info = {};
-HWND hwnd2List = nullptr;
-
-struct ColumnsSettings csSettingList[] =
-{
- { LPGENW("Name"), 0, "Column0width", 180 },
- { LPGENW("Value"), 1, "Column1width", 250 },
- { LPGENW("Type"), 2, "Column2width", 60 },
- { LPGENW("Size"), 3, "Column3width", 80 },
- { LPGENW("#"), 4, "Column4width", 30 },
- { nullptr }
-};
-
-int ListView_GetItemTextA(HWND hwndLV, int i, int iSubItem, char *pszText, int cchTextMax)
-{
- LV_ITEMA lvi;
- lvi.iSubItem = iSubItem;
- lvi.cchTextMax = cchTextMax;
- lvi.pszText = pszText;
- return SendMessageA(hwndLV, LVM_GETITEMTEXTA, (WPARAM)(i), (LPARAM)(LV_ITEMA *)&lvi);
-}
-
-int ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, const char *pszText)
-{
- LV_ITEMA lvi;
- lvi.iSubItem = iSubItem;
- lvi.pszText = (char*)pszText;
- return SendMessageA(hwndLV, LVM_SETITEMTEXTA, (WPARAM)(i), (LPARAM)(LV_ITEMA *)&lvi);
-}
int convertSetting(MCONTACT hContact, const char *module, const char *setting, int toType)
{
@@ -90,7 +62,7 @@ int convertSetting(MCONTACT hContact, const char *module, const char *setting, i
}
if (!res)
- msg(TranslateT("Unable to store value in this data type!"));
+ g_pMainWindow->msg(TranslateT("Unable to store value in this data type!"));
db_free(&dbv);
@@ -106,19 +78,19 @@ void EditFinish(int selected)
info.selectedItem = selected;
}
-void ClearListView()
+void CMainDlg::ClearListView()
{
EditFinish(0);
info.module[0] = 0;
info.setting[0] = 0;
info.hContact = 0;
- ListView_DeleteAllItems(hwnd2List);
+ m_settings.DeleteAllItems();
}
-void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *setting)
+void CMainDlg::DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *setting)
{
- int count = ListView_GetSelectedCount(hwnd2List);
+ int count = m_settings.GetSelectedCount();
if (!count)
return;
@@ -128,20 +100,20 @@ void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *s
mir_snwprintf(text, TranslateT("Are you sure you want to delete %d contact(s)?"), count);
else
mir_snwprintf(text, TranslateT("Are you sure you want to delete %d setting(s)?"), count);
- if (dlg(text, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
+ if (g_pMainWindow->dlg(text, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
return;
}
if (hContact == 0) {
- int items = ListView_GetItemCount(hwnd2List);
+ int items = m_settings.GetItemCount();
for (int i = 0; i < items;) {
- if (ListView_GetItemState(hwnd2List, i, LVIS_SELECTED)) {
+ if (m_settings.GetItemState(i, LVIS_SELECTED)) {
LVITEM lvi = {};
lvi.mask = LVIF_PARAM;
lvi.iItem = i;
- if (ListView_GetItem(hwnd2List, &lvi)) {
+ if (m_settings.GetItem(&lvi)) {
db_delete_contact(MCONTACT(lvi.lParam));
- ListView_DeleteItem(hwnd2List, i);
+ m_settings.DeleteItem(i);
}
items--;
}
@@ -152,11 +124,11 @@ void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *s
if (count == 1)
db_unset(hContact, module, setting);
else {
- int items = ListView_GetItemCount(hwnd2List);
+ int items = m_settings.GetItemCount();
for (int i = 0; i < items;) {
- if (ListView_GetItemState(hwnd2List, i, LVIS_SELECTED)) {
+ if (m_settings.GetItemState(i, LVIS_SELECTED)) {
char text[FLD_SIZE];
- if (ListView_GetItemTextA(hwnd2List, i, 0, text, _countof(text)))
+ if (ListView_GetItemTextA(m_settings.GetHwnd(), i, 0, text, _countof(text)))
db_unset(hContact, module, text);
items--;
}
@@ -165,19 +137,19 @@ void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *s
}
}
- if (ListView_GetItemCount(hwnd2List) == 0)
+ if (m_settings.GetItemCount() == 0)
replaceTreeItem(hContact, module, nullptr);
}
-int findListItem(const char *setting)
+int CMainDlg::findListItem(const char *setting)
{
if (!setting || !setting[0])
return -1;
- int items = ListView_GetItemCount(hwnd2List);
+ int items = m_settings.GetItemCount();
for (int i = 0; i < items; i++) {
char text[FLD_SIZE];
- if (ListView_GetItemTextA(hwnd2List, i, 0, text, _countof(text)))
+ if (ListView_GetItemTextA(m_settings.GetHwnd(), i, 0, text, _countof(text)))
if (!strcmp(setting, text))
return i;
}
@@ -185,17 +157,17 @@ int findListItem(const char *setting)
return -1;
}
-void deleteListItem(const char *setting)
+void CMainDlg::deleteListItem(const char *setting)
{
int item = findListItem(setting);
if (item > -1)
- ListView_DeleteItem(hwnd2List, item);
+ m_settings.DeleteItem(item);
}
-void updateListItem(int index, const char *setting, DBVARIANT *dbv, int resident)
+void CMainDlg::updateListItem(int index, const char *setting, DBVARIANT *dbv, int resident)
{
if (!dbv || !dbv->type) {
- ListView_DeleteItem(hwnd2List, index);
+ m_settings.DeleteItem(index);
return;
}
@@ -206,15 +178,15 @@ void updateListItem(int index, const char *setting, DBVARIANT *dbv, int resident
lvi.mask = LVIF_IMAGE;
lvi.iItem = index;
- ListView_SetItemText(hwnd2List, index, 4, resident ? L"[R]" : L"");
+ m_settings.SetItemText(index, 4, resident ? L"[R]" : L"");
if (g_db && g_db->IsSettingEncrypted(info.module, setting)) {
lvi.iImage = IMAGE_UNICODE;
- ListView_SetItem(hwnd2List, &lvi);
- ListView_SetItemTextA(hwnd2List, index, 0, setting);
- ListView_SetItemText(hwnd2List, index, 1, TranslateT("*** encrypted ***"));
- ListView_SetItemText(hwnd2List, index, 2, L"UNICODE");
- ListView_SetItemText(hwnd2List, index, 3, L"");
+ m_settings.SetItem(&lvi);
+ m_settings.SetItemText(index, 0, _A2T(setting));
+ m_settings.SetItemText(index, 1, TranslateT("*** encrypted ***"));
+ m_settings.SetItemText(index, 2, L"UNICODE");
+ m_settings.SetItemText(index, 3, L"");
return;
}
@@ -224,84 +196,84 @@ void updateListItem(int index, const char *setting, DBVARIANT *dbv, int resident
switch (dbv->type) {
case DBVT_BLOB:
lvi.iImage = IMAGE_BINARY;
- ListView_SetItem(hwnd2List, &lvi);
+ m_settings.SetItem(&lvi);
- ListView_SetItemTextA(hwnd2List, index, 1, ptrA(StringFromBlob(dbv->pbVal, dbv->cpbVal)));
+ m_settings.SetItemText(index, 1, _A2T(ptrA(StringFromBlob(dbv->pbVal, dbv->cpbVal))));
mir_snwprintf(data, L"0x%04X (%u)", dbv->cpbVal, dbv->cpbVal);
- ListView_SetItemText(hwnd2List, index, 3, data);
+ m_settings.SetItemText(index, 3, data);
break;
case DBVT_BYTE:
lvi.iImage = IMAGE_BYTE;
- ListView_SetItem(hwnd2List, &lvi);
+ m_settings.SetItem(&lvi);
mir_snwprintf(data, L"0x%02X (%u)", dbv->bVal, dbv->bVal);
- ListView_SetItemText(hwnd2List, index, 1, data);
+ m_settings.SetItemText(index, 1, data);
- ListView_SetItemText(hwnd2List, index, 3, L"0x0001 (1)");
+ m_settings.SetItemText(index, 3, L"0x0001 (1)");
break;
case DBVT_WORD:
lvi.iImage = IMAGE_WORD;
- ListView_SetItem(hwnd2List, &lvi);
+ m_settings.SetItem(&lvi);
mir_snwprintf(data, L"0x%04X (%u)", dbv->wVal, dbv->wVal);
- ListView_SetItemText(hwnd2List, index, 1, data);
+ m_settings.SetItemText(index, 1, data);
- ListView_SetItemText(hwnd2List, index, 3, L"0x0002 (2)");
+ m_settings.SetItemText(index, 3, L"0x0002 (2)");
break;
case DBVT_DWORD:
lvi.iImage = IMAGE_DWORD;
- ListView_SetItem(hwnd2List, &lvi);
+ m_settings.SetItem(&lvi);
mir_snwprintf(data, L"0x%08X (%u)", dbv->dVal, dbv->dVal);
- ListView_SetItemText(hwnd2List, index, 1, data);
+ m_settings.SetItemText(index, 1, data);
- ListView_SetItemText(hwnd2List, index, 3, L"0x0004 (4)");
+ m_settings.SetItemText(index, 3, L"0x0004 (4)");
break;
case DBVT_ASCIIZ:
lvi.iImage = IMAGE_STRING;
- ListView_SetItem(hwnd2List, &lvi);
- ListView_SetItemTextA(hwnd2List, index, 1, dbv->pszVal);
+ m_settings.SetItem(&lvi);
+ m_settings.SetItemText(index, 1, _A2T(dbv->pszVal));
length = (int)mir_strlen(dbv->pszVal) + 1;
mir_snwprintf(data, L"0x%04X (%u)", length, length);
- ListView_SetItemText(hwnd2List, index, 3, data);
+ m_settings.SetItemText(index, 3, data);
break;
case DBVT_WCHAR:
lvi.iImage = IMAGE_UNICODE;
- ListView_SetItem(hwnd2List, &lvi);
- ListView_SetItemText(hwnd2List, index, 1, dbv->pwszVal);
+ m_settings.SetItem(&lvi);
+ m_settings.SetItemText(index, 1, dbv->pwszVal);
length = (int)mir_wstrlen(dbv->pwszVal) + 1;
mir_snwprintf(data, L"0x%04X (%u)", length, length);
- ListView_SetItemText(hwnd2List, index, 3, data);
+ m_settings.SetItemText(index, 3, data);
break;
case DBVT_UTF8:
lvi.iImage = IMAGE_UNICODE;
- ListView_SetItem(hwnd2List, &lvi);
+ m_settings.SetItem(&lvi);
{
ptrW wszText(mir_utf8decodeW(dbv->pszVal));
- ListView_SetItemText(hwnd2List, index, 1, wszText);
+ m_settings.SetItemText(index, 1, wszText);
}
length = (int)mir_strlen(dbv->pszVal) + 1;
mir_snwprintf(data, L"0x%04X (%u)", length, length);
- ListView_SetItemText(hwnd2List, index, 3, data);
+ m_settings.SetItemText(index, 3, data);
break;
default:
return;
}
- ListView_SetItemText(hwnd2List, index, 2, DBVType(dbv->type));
+ m_settings.SetItemText(index, 2, DBVType(dbv->type));
}
-void addListHandle(MCONTACT hContact)
+void CMainDlg::addListHandle(MCONTACT hContact)
{
wchar_t name[NAME_SIZE], data[32];
LVITEM lvi = {};
@@ -312,31 +284,31 @@ void addListHandle(MCONTACT hContact)
GetContactName(hContact, nullptr, name, _countof(name));
lvi.pszText = name;
- int index = ListView_InsertItem(hwnd2List, &lvi);
+ int index = m_settings.InsertItem(&lvi);
mir_snwprintf(data, L"0x%08X (%ld)", hContact, hContact);
- ListView_SetItemText(hwnd2List, index, 1, data);
- ListView_SetItemText(hwnd2List, index, 2, L"HANDLE");
- ListView_SetItemText(hwnd2List, index, 3, L"0x0004 (4)");
+ m_settings.SetItemText(index, 1, data);
+ m_settings.SetItemText(index, 2, L"HANDLE");
+ m_settings.SetItemText(index, 3, L"0x0004 (4)");
if (db_mc_isEnabled()) {
if (db_mc_isSub(hContact)) {
- ListView_SetItemText(hwnd2List, index, 4, L"[S]");
+ m_settings.SetItemText(index, 4, L"[S]");
}
else if (db_mc_isMeta(hContact)) {
- ListView_SetItemText(hwnd2List, index, 4, L"[M]");
+ m_settings.SetItemText(index, 4, L"[M]");
}
}
}
-void addListItem(const char *setting, int resident)
+void CMainDlg::addListItem(const char *setting, int resident)
{
DBVARIANT dbv;
if (!db_get_s(info.hContact, info.module, setting, &dbv, 0)) {
LVITEMA lvi = {};
lvi.mask = LVIF_TEXT;
lvi.pszText = (char *)setting;
- int index = SendMessageA(hwnd2List, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
+ int index = SendMessageA(m_settings.GetHwnd(), LVM_INSERTITEMA, 0, (LPARAM)&lvi);
updateListItem(index, setting, &dbv, resident);
db_free(&dbv);
}
@@ -344,12 +316,12 @@ void addListItem(const char *setting, int resident)
LVITEMA lvi = {};
lvi.mask = LVIF_TEXT;
lvi.pszText = (char *)setting;
- int index = SendMessageA(hwnd2List, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
- ListView_SetItemText(hwnd2List, index, 1, TranslateT("*** buggy resident ***"));
+ int index = SendMessageA(m_settings.GetHwnd(), LVM_INSERTITEMA, 0, (LPARAM)&lvi);
+ m_settings.SetItemText(index, 1, TranslateT("*** buggy resident ***"));
}
}
-void PopulateSettings(MCONTACT hContact, const char *module)
+void CMainDlg::PopulateSettings(MCONTACT hContact, const char *module)
{
// save module as it can be erased by ClearListView()
char tmp[FLD_SIZE];
@@ -380,56 +352,52 @@ void PopulateSettings(MCONTACT hContact, const char *module)
FreeModuleSettingLL(&setlist);
}
-void SelectSetting(const char *setting)
+void CMainDlg::SelectSetting(const char *setting)
{
LVITEM lvItem = {};
lvItem.mask = LVIF_STATE;
lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
- int items = ListView_GetItemCount(hwnd2List);
+ int items = m_settings.GetItemCount();
for (int i = 0; i < items; i++)
- if (ListView_GetItemState(hwnd2List, i, lvItem.stateMask))
- ListView_SetItemState(hwnd2List, i, 0, lvItem.stateMask);
+ if (m_settings.GetItemState(i, lvItem.stateMask))
+ m_settings.SetItemState(i, 0, lvItem.stateMask);
lvItem.iItem = findListItem(setting);
if (lvItem.iItem != -1) {
EditFinish(lvItem.iItem);
lvItem.state = LVIS_SELECTED | LVIS_FOCUSED;
- ListView_SetItem(hwnd2List, &lvItem);
+ m_settings.SetItem(&lvItem);
- ListView_EnsureVisible(hwnd2List, lvItem.iItem, false);
+ m_settings.EnsureVisible(lvItem.iItem, false);
}
}
-void settingChanged(MCONTACT hContact, const char *module, const char *setting, DBVARIANT *dbv)
+void CMainDlg::onSettingChanged(MCONTACT hContact, DBCONTACTWRITESETTING *cws)
{
// modules tree
- if (dbv->type != DBVT_DELETED) {
- HTREEITEM hItem = findItemInTree(hContact, module);
+ if (cws->value.type != DBVT_DELETED) {
+ HTREEITEM hItem = findItemInTree(hContact, cws->szModule);
if (!hItem) {
HTREEITEM hParent = findItemInTree(hContact, nullptr);
if (hParent)
- insertItem(hContact, module, hParent);
+ insertItem(hContact, cws->szModule, hParent);
}
}
// settings list
- if (hContact != info.hContact || mir_strcmp(info.module, module))
+ if (hContact != info.hContact || mir_strcmp(info.module, cws->szModule))
return;
- if (dbv->type != DBVT_DELETED) {
- LVITEMA lvi = {};
- lvi.iItem = findListItem(setting);
- if (lvi.iItem == -1) {
- lvi.iItem = 0;
- lvi.mask = LVIF_TEXT;
- lvi.pszText = (char *)setting;
- lvi.iItem = SendMessageA(hwnd2List, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
- }
- updateListItem(lvi.iItem, setting, dbv, IsResidentSetting(module, setting));
+ if (cws->value.type != DBVT_DELETED) {
+ int iItem = findListItem(cws->szSetting);
+ if (iItem == -1)
+ iItem = m_settings.AddItem(_A2T(cws->szSetting), 0);
+
+ updateListItem(iItem, cws->szSetting, &cws->value, IsResidentSetting(cws->szModule, cws->szSetting));
}
- else deleteListItem(setting);
+ else deleteListItem(cws->szSetting);
}
static LRESULT CALLBACK SettingLabelEditSubClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -493,7 +461,7 @@ static LRESULT CALLBACK SettingLabelEditSubClassProc(HWND hwnd, UINT msg, WPARAM
break;
res = 1;
db_unset(info.hContact, info.module, info.setting);
- deleteListItem(info.setting);
+ g_pMainWindow->deleteListItem(info.setting);
break;
case 1: // value
@@ -592,7 +560,7 @@ static LRESULT CALLBACK SettingLabelEditSubClassProc(HWND hwnd, UINT msg, WPARAM
db_free(&dbv);
if (!res) {
- msg(TranslateT("Unable to store value in this data type!"));
+ g_pMainWindow->msg(TranslateT("Unable to store value in this data type!"));
break;
}
}
@@ -613,21 +581,22 @@ static LRESULT CALLBACK SettingLabelEditSubClassProc(HWND hwnd, UINT msg, WPARAM
return mir_callNextSubclass(hwnd, SettingLabelEditSubClassProc, msg, wParam, lParam);
}
-void EditLabel(int item, int subitem)
+void CMainDlg::EditLabel(int item, int subitem)
{
- RECT rc;
- char setting[FLD_SIZE];
- DBVARIANT dbv;
-
if (info.hwnd2Edit) {
SendMessage(info.hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0); // ignore the new value of the last edit
info.hwnd2Edit = nullptr;
}
- if (!ListView_GetItemTextA(hwnd2List, item, 0, setting, _countof(setting))) return;
- if (!setting[0] || !ListView_GetSubItemRect(hwnd2List, item, subitem, LVIR_LABEL, &rc))
+ char setting[FLD_SIZE];
+ if (!ListView_GetItemTextA(m_settings.GetHwnd(),item, 0, setting, _countof(setting)))
+ return;
+
+ RECT rc;
+ if (!setting[0] || !m_settings.GetSubItemRect(item, subitem, LVIR_LABEL, &rc))
return;
+ DBVARIANT dbv;
if (db_get_s(info.hContact, info.module, setting, &dbv, 0))
return;
@@ -635,7 +604,7 @@ void EditLabel(int item, int subitem)
info.subitem = subitem;
if (!subitem)
- info.hwnd2Edit = CreateWindow(L"EDIT", _A2T(setting), WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, nullptr, g_plugin.getInst(), nullptr);
+ info.hwnd2Edit = CreateWindowW(L"EDIT", _A2T(setting), WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), m_settings.GetHwnd(), nullptr, g_plugin.getInst(), nullptr);
else {
wchar_t *str = nullptr, value[16] = {};
@@ -666,14 +635,14 @@ void EditLabel(int item, int subitem)
if (str) {
int height = (rc.bottom - rc.top) * 4;
RECT rclist;
- GetClientRect(hwnd2List, &rclist);
+ GetClientRect(m_settings.GetHwnd(), &rclist);
if (rc.top + height > rclist.bottom &&rclist.bottom - rclist.top > height)
rc.top = rc.bottom - height;
- info.hwnd2Edit = CreateWindow(L"EDIT", str, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL, rc.left, rc.top, rc.right - rc.left, height, hwnd2List, nullptr, g_plugin.getInst(), nullptr);
+ info.hwnd2Edit = CreateWindow(L"EDIT", str, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL, rc.left, rc.top, rc.right - rc.left, height, m_settings.GetHwnd(), nullptr, g_plugin.getInst(), nullptr);
mir_free(str);
}
else if (dbv.type == DBVT_BYTE || dbv.type == DBVT_WORD || dbv.type == DBVT_DWORD)
- info.hwnd2Edit = CreateWindow(L"EDIT", value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, nullptr, g_plugin.getInst(), nullptr);
+ info.hwnd2Edit = CreateWindow(L"EDIT", value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), m_settings.GetHwnd(), nullptr, g_plugin.getInst(), nullptr);
}
db_free(&dbv);
diff --git a/plugins/DbEditorPP/src/settingsdlg.cpp b/plugins/DbEditorPP/src/settingsdlg.cpp
index 49a52e443c..f54c307a1a 100644
--- a/plugins/DbEditorPP/src/settingsdlg.cpp
+++ b/plugins/DbEditorPP/src/settingsdlg.cpp
@@ -74,7 +74,7 @@ INT_PTR CALLBACK EditSettingDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
break;
default:
- msg(TranslateT("Unknown DBVariant type!"));
+ g_pMainWindow->msg(TranslateT("Unknown DBVariant type!"));
DestroyWindow(hwnd);
return TRUE;
}
@@ -238,7 +238,7 @@ INT_PTR CALLBACK EditSettingDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
mir_free(value);
if (!res) {
- msg(TranslateT("Unable to store value in this data type!"));
+ g_pMainWindow->msg(TranslateT("Unable to store value in this data type!"));
break;
}
@@ -263,26 +263,25 @@ INT_PTR CALLBACK EditSettingDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
return 0;
}
-void editSetting(MCONTACT hContact, const char *module, const char *setting)
+void CMainDlg::editSetting(MCONTACT hContact, const char *module, const char *setting)
{
DBVARIANT dbv = {};
- if (!db_get_s(hContact, module, setting, &dbv, 0) || IsResidentSetting(module, setting)) {
- // gets free()ed in the window proc
- struct DBsetting *dbsetting = (struct DBsetting *)mir_calloc(sizeof(struct DBsetting));
+ if (db_get_s(hContact, module, setting, &dbv, 0) || IsResidentSetting(module, setting))
+ return;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_strdup(module);
- dbsetting->setting = mir_strdup(setting);
-
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd2mainWindow, EditSettingDlgProc, (LPARAM)dbsetting);
- }
+ struct DBsetting *dbsetting = (struct DBsetting *)mir_calloc(sizeof(struct DBsetting));
+ dbsetting->dbv = dbv;
+ dbsetting->hContact = hContact;
+ dbsetting->module = mir_strdup(module);
+ dbsetting->setting = mir_strdup(setting);
+ CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EDIT_SETTING), m_hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
}
-void copySetting(MCONTACT hContact, const char *module, const char *setting)
+void CMainDlg::copySetting(MCONTACT hContact, const char *module, const char *setting)
{
DBVARIANT dbv = {}, dbv2;
- if (db_get_s(hContact, module, setting, &dbv, 0)) return;
+ if (db_get_s(hContact, module, setting, &dbv, 0))
+ return;
char tmp[FLD_SIZE];
@@ -291,21 +290,19 @@ void copySetting(MCONTACT hContact, const char *module, const char *setting)
if (!db_get_s(hContact, module, tmp, &dbv2, 0))
db_free(&dbv2);
else {
- // gets free()ed in the window proc
struct DBsetting *dbsetting = (struct DBsetting *)mir_calloc(sizeof(struct DBsetting));
-
dbsetting->dbv = dbv;
dbsetting->hContact = hContact;
dbsetting->module = mir_strdup(module);
dbsetting->setting = mir_strdup(tmp);
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd2mainWindow, EditSettingDlgProc, (LPARAM)dbsetting);
+ CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EDIT_SETTING), m_hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
return;
}
}
db_free(&dbv);
}
-void newSetting(MCONTACT hContact, const char *module, int type)
+void CMainDlg::newSetting(MCONTACT hContact, const char *module, int type)
{
// gets safe_free()ed in the window proc
DBsetting *dbsetting = (DBsetting*)mir_calloc(sizeof(DBsetting));
@@ -313,5 +310,5 @@ void newSetting(MCONTACT hContact, const char *module, int type)
dbsetting->hContact = hContact;
dbsetting->module = mir_strdup(module);
dbsetting->setting = nullptr;
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd2mainWindow, EditSettingDlgProc, (LPARAM)dbsetting);
+ CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EDIT_SETTING), m_hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
}
diff --git a/plugins/DbEditorPP/src/stdafx.h b/plugins/DbEditorPP/src/stdafx.h
index 6926963818..d49c239bfc 100644
--- a/plugins/DbEditorPP/src/stdafx.h
+++ b/plugins/DbEditorPP/src/stdafx.h
@@ -44,6 +44,7 @@
#define MODULENAME "DBEditorpp"
#define modFullname "Database Editor++"
+#define modFullnameW L"Database Editor++"
struct CMPlugin : public PLUGIN<CMPlugin>
{
@@ -57,15 +58,10 @@ struct CMPlugin : public PLUGIN<CMPlugin>
int Unload() override;
};
-#define msg(a) MessageBox(hwnd2mainWindow,a,_A2T(modFullname),MB_OK)
-#define dlg(a,b) MessageBox(hwnd2mainWindow,a,_A2T(modFullname),b)
-
#define FLD_SIZE 256
#define MSG_SIZE 256
#define NAME_SIZE 128
-#define WM_FINDITEM (WM_USER + 1) // onyl for the main window, wparam is ItemIfno* lparam is 0
-
/***********************
ModuleTreeInfoStruct
this gets dumped as the lparam for each module tree item
@@ -109,19 +105,6 @@ struct ModuleAndContact
MCONTACT hContact;
};
-// find window
-#define FW_MODULE 0
-#define FW_SETTINGNAME 1
-#define FW_SETTINGVALUE 2
-
-struct ItemInfo
-{
- int type; // above types
- MCONTACT hContact;
- char module[FLD_SIZE];
- char setting[FLD_SIZE];
-};
-
// watchwindow
struct WatchListArrayStruct
{
@@ -179,7 +162,6 @@ enum ICONS
//=======================================================
// Variables
//=======================================================
-extern HWND hwnd2mainWindow;
extern int g_Mode;
extern int g_Hex;
@@ -217,7 +199,7 @@ int GetContactName(MCONTACT hContact, const char *proto, wchar_t *value, int max
int ApplyProtoFilter(MCONTACT hContact);
void loadListSettings(HWND hwnd, ColumnsSettings *cs);
void saveListSettings(HWND hwnd, ColumnsSettings *cs);
-INT_PTR CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam);
+int CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam);
// main_window
@@ -230,77 +212,106 @@ class CMainDlg : public CDlgBase
CCtrlTreeView m_modules;
CCtrlListView m_settings;
+ void addModuleDlg(MCONTACT hContact);
+ void deleteModuleDlg();
+
+ int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelectedContact, const char *selectedModule, const char *selectedSetting);
+ void doItems(ModuleSettingLL *modlist, int count);
+
+ void ImportSettingsMenuItem(MCONTACT hContact);
+
UI_MESSAGE_MAP(CMainDlg, CDlgBase);
- UI_MESSAGE(WM_FINDITEM, OnFindItem);
UI_MESSAGE(WM_COMMAND, OnCommand);
UI_MESSAGE_MAP_END();
public:
CMainDlg();
+ __forceinline void msg(const wchar_t *pwszMessage) {
+ MessageBoxW((this != nullptr) ? m_hwnd : 0, pwszMessage, modFullnameW, MB_OK);
+ }
+
+ __forceinline int dlg(const wchar_t *pwszMessage, int code) {
+ return MessageBoxW((this != nullptr) ? m_hwnd : 0, pwszMessage, modFullnameW, code);
+ }
+
bool OnInitDialog() override;
void OnDestroy() override;
int Resizer(UTILRESIZECONTROL *urc) override;
- LRESULT OnFindItem(UINT, WPARAM, LPARAM);
LRESULT OnCommand(UINT, WPARAM, LPARAM);
void onChange_Splitter(CSplitter*);
+ // find window
+ #define FW_MODULE 0
+ #define FW_SETTINGNAME 1
+ #define FW_SETTINGVALUE 2
+ void FindItem(int type, MCONTACT, const char *szModule, const char *szSetting);
+
+ ////////////////////////////////////////////////////////////////////////////////////////
+ // module tree
+
+ HTREEITEM findItemInTree(MCONTACT hContact, const char *module);
+ BOOL findAndRemoveDuplicates(MCONTACT hContact, const char *module);
+ void freeTree(MCONTACT hContact);
+ void insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent);
+ void replaceTreeItem(MCONTACT hContact, const char *module, const char *newModule);
+
void onItemExpand_Modules(CCtrlTreeView::TEventInfo *ev);
void onSelChanged_Modules(CCtrlTreeView::TEventInfo *ev);
void onBeginLabelEdit_Modules(CCtrlTreeView::TEventInfo *ev);
void onEndLabelEdit_Modules(CCtrlTreeView::TEventInfo *ev);
void onContextMenu_Modules(CContextMenuPos *pos);
+ static void __cdecl PopulateModuleTreeThreadFunc(void *param);
+
+ ////////////////////////////////////////////////////////////////////////////////////////
+ // settings list
+
+ void ClearListView();
+ void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *setting);
+ void EditLabel(int item, int subitem);
+ void PopulateSettings(MCONTACT hContact, const char *module);
+ void SelectSetting(const char *setting);
+
+ void addListHandle(MCONTACT hContact);
+ void addListItem(const char *setting, int resident);
+ void deleteListItem(const char *setting);
+ int findListItem(const char *setting);
+ void updateListItem(int index, const char *setting, DBVARIANT *dbv, int resident);
+
+ void editSetting(MCONTACT hContact, const char *module, const char *setting);
+ void copySetting(MCONTACT hContact, const char *module, const char *setting);
+ void newSetting(MCONTACT hContact, const char *module, int type);
+
+ void onSettingChanged(MCONTACT hContact, DBCONTACTWRITESETTING *cws);
void onClick_Settings(CCtrlListView::TEventInfo *ev);
void onDblClick_Settings(CCtrlListView::TEventInfo *ev);
void onColumnClick_Settings(CCtrlListView::TEventInfo *ev);
void onContextMenu_Settings(CContextMenuPos *pos);
};
+extern CMainDlg *g_pMainWindow;
+
// deletemodules
-int deleteModule(MCONTACT hContact, const char *module, int confirm);
-void deleteModuleDlg();
+int deleteModule(HWND hwndParent, MCONTACT hContact, const char *module, int confirm);
// renamemodule
int renameModule(MCONTACT hContact, const char *oldName, const char *newName);
-void renameModuleDlg();
-void addModuleDlg(MCONTACT hContact);
// moduletree
-void insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent);
-HTREEITEM findItemInTree(MCONTACT hContact, const char *module);
-BOOL findAndRemoveDuplicates(MCONTACT hContact, const char *module);
-void replaceTreeItem(MCONTACT hContact, const char *module, const char *newModule);
void refreshTree(BOOL restore);
-void freeTree(MCONTACT hContact);
-
-// settinglist
-int ListView_GetItemTextA(HWND hwndLV, int i, int iSubItem, char *pszText, int cchTextMax);
-int ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, const char *pszText);
-void ClearListView();
-void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *setting);
-void addListHandle(MCONTACT hContact);
-void PopulateSettings(MCONTACT hContact, const char *module);
-void SelectSetting(const char *setting);
-void settingChanged(MCONTACT hContact, const char *module, const char *setting, DBVARIANT *dbv);
-
-// settingsdlg
-void editSetting(MCONTACT hContact, const char *module, const char *setting);
-void copySetting(MCONTACT hContact, const char *module, const char *setting);
-void newSetting(MCONTACT hContact, const char *module, int type);
// exportimport
void exportDB(MCONTACT hContact, const char *module); // hContact == -1 export entire db. module == NULL export entire contact
-void ImportSettingsMenuItem(MCONTACT hContact);
void ImportSettingsFromFileMenuItem(MCONTACT hContact, const char *filePath); // ansi!
// find window
void newFindWindow();
// copymodule
-void copyModuleMenuItem(MCONTACT hContact, const char *module);
+void copyModuleMenuItem(HWND hwndParent, MCONTACT hContact, const char *module);
void copyModule(const char *module, MCONTACT hContactFrom, MCONTACT hContactTo);
int CloneContact(MCONTACT hContact);
@@ -333,4 +344,7 @@ HICON LoadSkinnedDBEIcon(int icon);
HIMAGELIST LoadIcons();
int GetProtoIconIndex(const char *proto);
+int ListView_GetItemTextA(HWND hwndLV, int i, int iSubItem, char *pszText, int cchTextMax);
+int ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, const char *pszText);
+
#endif //_COMMONHEADERS_H
diff --git a/plugins/DbEditorPP/src/utils.cpp b/plugins/DbEditorPP/src/utils.cpp
index f6d394c8bf..5b93ac8ad1 100644
--- a/plugins/DbEditorPP/src/utils.cpp
+++ b/plugins/DbEditorPP/src/utils.cpp
@@ -21,6 +21,25 @@ extern BYTE nameOrder[NAMEORDERCOUNT];
/////////////////////////////////////////////////////////////////////////////////////////
+int ListView_GetItemTextA(HWND hwndLV, int i, int iSubItem, char *pszText, int cchTextMax)
+{
+ LV_ITEMA lvi;
+ lvi.iSubItem = iSubItem;
+ lvi.cchTextMax = cchTextMax;
+ lvi.pszText = pszText;
+ return SendMessageA(hwndLV, LVM_GETITEMTEXTA, (WPARAM)(i), (LPARAM)(LV_ITEMA *)&lvi);
+}
+
+int ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, const char *pszText)
+{
+ LV_ITEMA lvi;
+ lvi.iSubItem = iSubItem;
+ lvi.pszText = (char*)pszText;
+ return SendMessageA(hwndLV, LVM_SETITEMTEXTA, (WPARAM)(i), (LPARAM)(LV_ITEMA *)&lvi);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
char* StringFromBlob(BYTE *blob, WORD len)
{
int j;
@@ -353,7 +372,7 @@ void saveListSettings(HWND hwnd, ColumnsSettings *cs)
}
}
-INT_PTR CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam)
+int CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam)
{
ColumnsSortParams params = *(ColumnsSortParams *)myParam;
const int maxSize = 1024;
diff --git a/plugins/DbEditorPP/src/version.h b/plugins/DbEditorPP/src/version.h
index 0c5cea7c4e..3883913a11 100644
--- a/plugins/DbEditorPP/src/version.h
+++ b/plugins/DbEditorPP/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 4
-#define __MINOR_VERSION 0
-#define __RELEASE_NUM 2
-#define __BUILD_NUM 3
+#define __MINOR_VERSION 1
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
diff --git a/plugins/DbEditorPP/src/watchedvars.cpp b/plugins/DbEditorPP/src/watchedvars.cpp
index 85cb2cac5e..0155f5551e 100644
--- a/plugins/DbEditorPP/src/watchedvars.cpp
+++ b/plugins/DbEditorPP/src/watchedvars.cpp
@@ -295,12 +295,11 @@ INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
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, _countof(ii.module));
- ListView_GetItemTextA(hwndVars, hti.iItem, 2, ii.setting, _countof(ii.setting));
- ii.type = FW_SETTINGNAME;
- SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0);
+ char szModule[NAME_SIZE], szSetting[NAME_SIZE];
+ ListView_GetItemTextA(hwndVars, hti.iItem, 1, szModule, _countof(szModule));
+ ListView_GetItemTextA(hwndVars, hti.iItem, 2, szSetting, _countof(szSetting));
+ if (g_pMainWindow)
+ g_pMainWindow->FindItem(FW_SETTINGNAME, (MCONTACT)lvi.lParam, szModule, szSetting);
}
}
}