diff options
author | Dmitry Kuzkin <bio@ktaspb.ru> | 2015-06-18 12:36:07 +0000 |
---|---|---|
committer | Dmitry Kuzkin <bio@ktaspb.ru> | 2015-06-18 12:36:07 +0000 |
commit | 1bb9a86b26d3a9964844d42fa25690ce0a028258 (patch) | |
tree | 6c0645ade07ec6b4d36e38a1ba77e457e8cf6ade /plugins/DbEditorPP/src/moduletree.cpp | |
parent | a27ae3e0c1f1f17596db3abeae16ec3fc4b4ba80 (diff) |
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
Diffstat (limited to 'plugins/DbEditorPP/src/moduletree.cpp')
-rw-r--r-- | plugins/DbEditorPP/src/moduletree.cpp | 802 |
1 files changed, 338 insertions, 464 deletions
diff --git a/plugins/DbEditorPP/src/moduletree.cpp b/plugins/DbEditorPP/src/moduletree.cpp index 151a081de3..5aaf0b7616 100644 --- a/plugins/DbEditorPP/src/moduletree.cpp +++ b/plugins/DbEditorPP/src/moduletree.cpp @@ -1,41 +1,56 @@ #include "headers.h"
-static BOOL populating = 0;
-int Select = 0;
+HWND hwnd2Tree = 0;
+
+volatile BOOL populating = 0;
+volatile int Select = 0;
+
static ModuleTreeInfoStruct contacts_mtis = { CONTACT_ROOT_ITEM, 0 };
static ModuleTreeInfoStruct settings_mtis = { CONTACT, 0 };
-int doContacts(HWND hwnd2Tree, HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelectedContact, char *SelectedModule, char *SelectedSetting)
+
+void insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent)
+{
+ _A2T text(module);
+
+ TVINSERTSTRUCT tvi;
+ tvi.hParent = hParent;
+ tvi.hInsertAfter = TVI_SORT;
+ tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
+ tvi.item.pszText = text;
+
+ ModuleTreeInfoStruct *lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
+ lParam->hContact = hContact;
+
+ tvi.item.iImage = IMAGE_CLOSED;
+ tvi.item.iSelectedImage = IMAGE_OPENED;
+ lParam->type = MODULE;
+
+ tvi.item.lParam = (LPARAM)lParam;
+ TreeView_InsertItem(hwnd2Tree, &tvi);
+}
+
+
+int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelectedContact, const char *selectedModule, const char *selectedSetting)
{
TVINSERTSTRUCT tvi;
HTREEITEM contact;
ModuleTreeInfoStruct *lParam;
- ModSetLinkLinkItem *module;
int itemscount = 0;
- int loaded, i = 0, icon = 0;
- int hItem = -1;
+ int i = 0, icon = 0;
+ HTREEITEM hItem = 0;
- SetWindowText(hwnd2mainWindow, Translate("Loading contacts..."));
+ SetWindowText(hwnd2mainWindow, TranslateT("Loading contacts..."));
tvi.hInsertAfter = TVI_SORT;
tvi.item.cChildren = 1;
+
+ char szProto[FLD_SIZE];
+ TCHAR name[NAME_SIZE];
for (MCONTACT hContact = db_find_first(); hContact && hwnd2mainWindow; hContact = db_find_next(hContact)) {
- char szProto[100];
- if (DBGetContactSettingStringStatic(hContact, "Protocol", "p", szProto, SIZEOF(szProto))) {
- icon = GetProtoIcon(szProto);
- loaded = (icon != DEF_ICON);
- }
- else {
- icon = DEF_ICON;
- loaded = 0;
- }
-
- i++;
-
- // filter
- if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED))
- continue;
+
+ if (ApplyProtoFilter(hContact)) continue;
// add the contact
lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
@@ -48,82 +63,50 @@ int doContacts(HWND hwnd2Tree, HTREEITEM contactsRoot, ModuleSettingLL *modlist, if (hSelectedContact != hContact)
lParam->type |= EMPTY;
- // contacts name
- WCHAR nick[256];
- WCHAR protoW[256]; // unicode proto
+ if (db_get_static(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
+ szProto[0] = 0;
- if (szProto)
- a2u(szProto, protoW, SIZEOF(protoW));
- else
- protoW[0] = 0;
+ icon = GetProtoIconIndex(szProto);
- if (!szProto || !loaded) {
- tvi.item.iSelectedImage = (tvi.item.iImage = 4);
+ GetContactName(hContact, szProto, name, SIZEOF(name));
- if (protoW) {
- if (Order)
- mir_snwprintf(nick, SIZEOF(nick), L"(%s) %s %s", protoW, GetContactName(hContact, szProto, 1), L"(UNLOADED)");
- else
- mir_snwprintf(nick, SIZEOF(nick), L"%s (%s) %s", GetContactName(hContact, szProto, 1), protoW, L"(UNLOADED)");
- }
- else
- mir_wstrcpy(nick, nick_unknownW);
- }
- else {
- tvi.item.iSelectedImage = (tvi.item.iImage = icon); //GetProtoIcon(szProto, 7));
- if (Order)
- mir_snwprintf(nick, SIZEOF(nick), L"(%s) %s", protoW, GetContactName(hContact, szProto, 1));
- else
- mir_snwprintf(nick, SIZEOF(nick), L"%s (%s)", GetContactName(hContact, szProto, 1), protoW);
- }
+ tvi.item.pszText = name;
+ tvi.item.iImage = icon;
+ tvi.item.iSelectedImage = icon;
- tvi.item.pszText = (char *)nick;
- contact = TreeView_InsertItemW(hwnd2Tree, &tvi);
+ contact = TreeView_InsertItem(hwnd2Tree, &tvi);
itemscount++;
if (hSelectedContact == hContact) {
- module = modlist->first;
- while (module && hwnd2mainWindow) {
- if (module->name[0] && !IsModuleEmpty(hContact, module->name)) {
- tvi.hParent = contact;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = module->name;
-
- lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- lParam->hContact = hContact;
-
- tvi.item.iImage = 1;
- tvi.item.iSelectedImage = 2;
- lParam->type = KNOWN_MODULE;
-
- tvi.item.lParam = (LPARAM)lParam;
- TreeView_InsertItem(hwnd2Tree, &tvi);
- }
- module = (ModSetLinkLinkItem *)module->next;
+
+ for (ModSetLinkLinkItem *module = modlist->first; module && hwnd2mainWindow; module = module->next) {
+ if (!module->name[0] || IsModuleEmpty(hContact, module->name))
+ continue;
+ insertItem(hContact, module->name, contact);
}
- hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule);
+ hItem = findItemInTree(hSelectedContact, selectedModule);
}
}
- if (hItem != -1) {
- TreeView_SelectItem(hwnd2Tree, (HTREEITEM)hItem);
+ if (hItem) {
+ TreeView_SelectItem(hwnd2Tree, hItem);
TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
- if (SelectedSetting[0])
- SelectSetting(SelectedSetting);
+ if (selectedSetting && selectedSetting[0])
+ SelectSetting(selectedSetting);
}
return itemscount;
}
-void doItems(HWND hwnd2Tree, ModuleSettingLL *modlist, int count)
+
+void doItems(ModuleSettingLL* modlist, int count)
{
- HWND hwnd = GetParent(hwnd2Tree);
+ HWND hwnd = GetParent(hwnd2Tree); //!!!
- char percent[96], title[64];
- mir_snprintf(title, SIZEOF(title), Translate("Loading modules..."));
+ TCHAR percent[128], title[96];
+ mir_sntprintf(title, TranslateT("Loading modules..."));
TVITEM item = { 0 };
item.mask = TVIF_STATE | TVIF_PARAM;
@@ -148,45 +131,34 @@ void doItems(HWND hwnd2Tree, ModuleSettingLL *modlist, int count) continue;
// Caption
- mir_snprintf(percent, SIZEOF(percent), "%s %d%%", title, (int)(100 * i / count));
+ mir_sntprintf(percent, _T("%s %d%%"), title, (int)(100 * i / count));
SetWindowText(hwnd, percent);
for (ModSetLinkLinkItem *module = modlist->first; module && hwnd2mainWindow; module = module->next) {
if (!module->name[0] || IsModuleEmpty(hContact, module->name))
continue;
- TVINSERTSTRUCT tvi;
- tvi.hParent = item.hItem;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = module->name;
-
- ModuleTreeInfoStruct *lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- lParam->hContact = hContact;
-
- tvi.item.iImage = 1;
- tvi.item.iSelectedImage = 2;
- lParam->type = KNOWN_MODULE;
-
- tvi.item.lParam = (LPARAM)lParam;
- TreeView_InsertItem(hwnd2Tree, &tvi);
+ insertItem(hContact, module->name, item.hItem);
}
}
- SetWindowText(hwnd, TranslateT("Database Editor++"));
+ SetWindowText(hwnd2mainWindow, 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
-int findItemInTree(HWND hwnd2Tree, MCONTACT hContact, char *module)
+HTREEITEM findItemInTree(MCONTACT hContact, const char* module)
{
TVITEM item;
- char text[265];
HTREEITEM lastItem;
+ TCHAR text[FLD_SIZE];
+
if (!TreeView_GetCount(hwnd2Tree))
return 0;
+ _A2T szModule(module);
+
item.mask = TVIF_STATE | TVIF_PARAM | TVIF_TEXT;
item.hItem = TVI_ROOT;
item.pszText = text;
@@ -197,9 +169,9 @@ int findItemInTree(HWND hwnd2Tree, MCONTACT hContact, char *module) if (lastItem != TVI_ROOT) {
/* these next 2 lines are not from code guru..... */
if (TreeView_GetItem(hwnd2Tree, &item) && item.lParam) {
- if ((hContact == ((ModuleTreeInfoStruct *)item.lParam)->hContact) && (!module[0] || !mir_strcmp(module, text))) {
- //TreeView_SelectItem(hwnd2Tree,item.hItem);
- return (int)item.hItem;
+ if ((hContact == ((ModuleTreeInfoStruct *)item.lParam)->hContact) && (!module || !module[0] || !mir_tstrcmp(szModule, text))) {
+ return item.hItem;
+
}
}
/* back to coduguru's code*/
@@ -209,13 +181,14 @@ int findItemInTree(HWND hwnd2Tree, MCONTACT hContact, char *module) while ((!(item.hItem = TreeView_GetNextSibling(hwnd2Tree, lastItem))) && (lastItem = item.hItem = TreeView_GetParent(hwnd2Tree, lastItem)));
} while (item.hItem);
- return -1;
+
+ return 0;
}
// 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(HWND hwnd2Tree, MCONTACT hContact)
+void freeTree(MCONTACT hContact)
{
TVITEM item;
HTREEITEM lastItem;
@@ -251,17 +224,20 @@ void freeTree(HWND hwnd2Tree, MCONTACT hContact) } while (item.hItem);
}
-BOOL findAndRemoveDuplicates(HWND hwnd2Tree, MCONTACT hContact, char *module)
+BOOL findAndRemoveDuplicates(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 */
{
TVITEM item;
HTREEITEM lastItem, prelastItem;
BOOL Result = 0;
- char text[265];
+ TCHAR text[FLD_SIZE];
+
if (!TreeView_GetCount(hwnd2Tree))
return Result;
+ _A2T szModule(module);
+
item.mask = TVIF_STATE | TVIF_PARAM | TVIF_TEXT;
item.hItem = TVI_ROOT;
item.pszText = text;
@@ -276,7 +252,7 @@ http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?t /* these next lines are not from code guru..... */
if (item.lParam) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)item.lParam;
- if (hContact == mtis->hContact && !mir_strcmp(text, module)) {
+ if (hContact == mtis->hContact && !mir_tstrcmp(text, szModule)) {
mir_free(mtis);
TreeView_DeleteItem(hwnd2Tree, item.hItem);
lastItem = prelastItem;
@@ -298,89 +274,63 @@ http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?t }
-void replaceTreeItem(HWND hwnd, MCONTACT hContact, const char *module, const char *newModule)
+void replaceTreeItem(MCONTACT hContact, const char* module, const char* newModule)
{
- int hItem = findItemInTree(hwnd, hContact, (char *)module);
- HTREEITEM hParent;
+ HTREEITEM hItem = findItemInTree(hContact, module);
- if (hItem == -1)
+ if (!hItem)
return;
- hParent = TreeView_GetParent(hwnd, (HTREEITEM)hItem);
-
- {
- TVITEM item;
- item.mask = TVIF_PARAM;
- item.hItem = (HTREEITEM)hItem;
-
- if (TreeView_GetItem(hwnd, &item))
- mir_free((ModuleTreeInfoStruct *)item.lParam);
- TreeView_DeleteItem(hwnd, item.hItem);
- }
+ TVITEM item;
+ item.mask = TVIF_PARAM;
+ item.hItem = hItem;
- if (hParent && newModule) {
- TVINSERTSTRUCT tvi = { 0 };
- ModuleTreeInfoStruct *lParam;
+ HTREEITEM hParent = TreeView_GetParent(hwnd2Tree, hItem);
- tvi.hParent = hParent;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = (char *)newModule;
+ if (TreeView_GetItem(hwnd2Tree, &item))
+ mir_free((ModuleTreeInfoStruct *)item.lParam);
- lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- lParam->hContact = hContact;
- lParam->type = KNOWN_MODULE;
- tvi.item.iImage = 1;
- tvi.item.iSelectedImage = 2;
+ TreeView_DeleteItem(hwnd2Tree, item.hItem);
- tvi.item.lParam = (LPARAM)lParam;
+ if (!newModule)
+ return;
- TreeView_InsertItem(hwnd, &tvi);
+ if (hParent) {
+ replaceTreeItem(hContact, newModule, NULL);
+ insertItem(hContact, newModule, hParent);
}
}
-void refreshTree(int restore)
-{
- if (populating)
- return;
- populating = 1;
- forkthread(PopulateModuleTreeThreadFunc, 0, (HWND)restore);
-}
-void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
+void __cdecl PopulateModuleTreeThreadFunc(LPVOID param)
{
TVINSERTSTRUCT tvi;
- HWND hwnd2Tree = GetDlgItem(hwnd2mainWindow, IDC_MODULES);
- char SelectedModule[256] = { 0 };
- char SelectedSetting[256] = { 0 };
+ char SelectedModule[FLD_SIZE] = "";
+ char SelectedSetting[FLD_SIZE] = "";
+
MCONTACT hSelectedContact = hRestore;
MCONTACT hContact;
HTREEITEM contact, contactsRoot;
int count;
- // item lParams
- ModuleTreeInfoStruct *lParam;
-
// module list
- ModSetLinkLinkItem *module;
ModuleSettingLL modlist;
hRestore = NULL;
- if (!hwnd2Tree) {
- msg(Translate("Module tree not found"), modFullname);
+ if (!hwnd2Tree)
return;
- }
Select = 0;
- switch ((int)di) {
+ switch ((int)param) {
case 1: // restore after rebuild
if (HTREEITEM item = TreeView_GetSelection(hwnd2Tree)) {
+ TCHAR text[FLD_SIZE];
TVITEM tvi = { 0 };
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
- tvi.pszText = SelectedModule;
- tvi.cchTextMax = SIZEOF(SelectedModule);
+ tvi.pszText = text;
+ tvi.cchTextMax = SIZEOF(text);
tvi.hItem = item;
TreeView_GetItem(hwnd2Tree, &tvi);
@@ -389,17 +339,19 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) hSelectedContact = mtis->hContact;
if (mtis->type == CONTACT)
SelectedModule[0] = 0;
+ else
+ mir_strncpy(SelectedModule, _T2A(text), SIZEOF(SelectedModule));
Select = 1;
}
}
break;
case 2: // restore saved
- if (GetValue(NULL, modname, "LastModule", SelectedModule, SIZEOF(SelectedModule))) {
+ if (GetValueA(NULL, modname, "LastModule", SelectedModule, SIZEOF(SelectedModule))) {
hSelectedContact = db_get_dw(NULL, modname, "LastContact", INVALID_CONTACT_ID);
if (hSelectedContact != INVALID_CONTACT_ID)
Select = 1;
- GetValue(NULL, modname, "LastSetting", SelectedSetting, SIZEOF(SelectedSetting));
+ GetValueA(NULL, modname, "LastSetting", SelectedSetting, SIZEOF(SelectedSetting));
}
break;
@@ -410,20 +362,15 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) break;
}
- if ((int)di != 4) { // do not rebuild on just going to another setting
- if (!EnumModules(&modlist)) {
- msg(Translate("Error loading module list"), modFullname);
+ if ((int)param != 4) { // do not rebuild on just going to another setting
+ if (!EnumModules(&modlist))
return;
- }
// remove all items (incase there are items there...
- freeTree(hwnd2Tree, 0);
+ freeTree(0);
TreeView_DeleteAllItems(hwnd2Tree);
TreeView_SelectItem(hwnd2Tree, 0);
- //image list
- TreeView_SetImageList(hwnd2Tree, himl, TVSIL_NORMAL);
-
/// contact root item
contacts_mtis.type = CONTACT_ROOT_ITEM;
tvi.item.lParam = (LPARAM)&contacts_mtis;
@@ -434,9 +381,9 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) tvi.item.cChildren = 1;
tvi.hInsertAfter = TVI_FIRST;
- tvi.item.pszText = Translate("Contacts");
- tvi.item.iImage = 3;
- tvi.item.iSelectedImage = 3;
+ tvi.item.pszText = TranslateT("Contacts");
+ tvi.item.iImage = IMAGE_CONTACTS;
+ tvi.item.iSelectedImage = IMAGE_CONTACTS;
contactsRoot = TreeView_InsertItem(hwnd2Tree, &tvi);
// add the settings item
@@ -446,9 +393,9 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) tvi.item.cChildren = 1;
tvi.hParent = NULL;
tvi.hInsertAfter = TVI_FIRST;
- tvi.item.pszText = Translate("Settings");
- tvi.item.iImage = 0;
- tvi.item.iSelectedImage = 0;
+ tvi.item.pszText = TranslateT("Settings");
+ tvi.item.iImage = IMAGE_SETTINGS;
+ tvi.item.iSelectedImage = IMAGE_SETTINGS;
contact = TreeView_InsertItem(hwnd2Tree, &tvi);
// to fix bug with CHANGE NOTIFY on window activation
@@ -456,34 +403,19 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) settings_mtis.type = CONTACT;
hContact = 0;
- module = modlist.first;
- while (module) {
- if (!IsModuleEmpty(hContact, module->name)) {
- tvi.hParent = contact;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = module->name;
-
- lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- lParam->hContact = hContact;
- tvi.item.iImage = 1;
- tvi.item.iSelectedImage = 2;
- lParam->type = KNOWN_MODULE;
-
- tvi.item.lParam = (LPARAM)lParam;
-
- TreeView_InsertItem(hwnd2Tree, &tvi);
- }
- module = (ModSetLinkLinkItem *)module->next;
+ for (ModSetLinkLinkItem *module = modlist.first; module && hwnd2mainWindow; module = module->next) {
+ if (!module->name[0] || IsModuleEmpty(hContact, module->name))
+ continue;
+ insertItem(hContact, module->name, contact);
}
if (db_get_b(NULL, modname, "ExpandSettingsOnOpen", 0))
TreeView_Expand(hwnd2Tree, contact, TVE_EXPAND);
if (Select && hSelectedContact == NULL) {
- int hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule);
- if (hItem != -1) {
- TreeView_SelectItem(hwnd2Tree, (HTREEITEM)hItem);
+ HTREEITEM hItem = findItemInTree(hSelectedContact, SelectedModule);
+ if (hItem) {
+ TreeView_SelectItem(hwnd2Tree, hItem);
TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
if (SelectedSetting[0])
SelectSetting(SelectedSetting);
@@ -491,17 +423,17 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) Select = 0;
}
- count = doContacts(hwnd2Tree, contactsRoot, &modlist, Select ? hSelectedContact : NULL, SelectedModule, SelectedSetting);
+ count = doContacts(contactsRoot, &modlist, Select ? hSelectedContact : NULL, SelectedModule, SelectedSetting);
Select = 0;
- doItems(hwnd2Tree, &modlist, count);
+ doItems(&modlist, count);
FreeModuleSettingLL(&modlist);
}
if (Select) {
- int hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule);
- if (hItem != -1) {
- TreeView_SelectItem(hwnd2Tree, (HTREEITEM)hItem);
+ HTREEITEM hItem = findItemInTree(hSelectedContact, SelectedModule);
+ if (hItem) {
+ TreeView_SelectItem(hwnd2Tree, hItem);
TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
if (SelectedSetting[0])
SelectSetting(SelectedSetting);
@@ -512,6 +444,15 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) }
+void refreshTree(int restore)
+{
+ if (populating)
+ return;
+ populating = 1;
+ mir_forkthread(PopulateModuleTreeThreadFunc, (HWND)restore);
+}
+
+
static LRESULT CALLBACK ModuleTreeLabelEditSubClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
@@ -534,42 +475,21 @@ void moduleListRightClick(HWND hwnd, WPARAM wParam, LPARAM lParam); void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd here is to the main window, NOT the treview
{
switch (((NMHDR *)lParam)->code) {
- case TVN_ITEMEXPANDINGA:
- case TVN_ITEMEXPANDINGW:
+ case TVN_ITEMEXPANDING:
if (populating && ((LPNMTREEVIEW)lParam)->action == TVE_EXPAND) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)((LPNMTREEVIEW)lParam)->itemNew.lParam;
if (mtis && (mtis->type == (CONTACT | EMPTY))) {
- TVINSERTSTRUCT tvi;
- ModuleTreeInfoStruct *_lParam;
- HWND hwnd2Tree = GetDlgItem(hwnd2mainWindow, IDC_MODULES);
- ModSetLinkLinkItem *module;
- ModuleSettingLL modlist;
MCONTACT hContact = mtis->hContact;
-
mtis->type = CONTACT;
- if (!EnumModules(&modlist)) {
- msg(Translate("Error loading module list"), modFullname);
+ ModuleSettingLL modlist;
+ if (!EnumModules(&modlist))
break;
- }
- module = modlist.first;
+ ModSetLinkLinkItem *module = modlist.first;
while (module && hwnd2mainWindow) {
if (module->name[0] && !IsModuleEmpty(hContact, module->name)) {
- tvi.hParent = ((LPNMTREEVIEW)lParam)->itemNew.hItem;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = module->name;
-
- _lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- _lParam->hContact = hContact;
-
- tvi.item.iImage = 5;
- tvi.item.iSelectedImage = 6;
- _lParam->type = KNOWN_MODULE;
-
- tvi.item.lParam = (LPARAM)_lParam;
- TreeView_InsertItem(hwnd2Tree, &tvi);
+ insertItem(hContact, module->name, ((LPNMTREEVIEW)lParam)->itemNew.hItem);
}
module = (ModSetLinkLinkItem *)module->next;
}
@@ -579,23 +499,22 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h }
break;
- case TVN_SELCHANGEDA:
- case TVN_SELCHANGEDW:
+ case TVN_SELCHANGED:
{
- ModuleTreeInfoStruct *mtis;
LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
TVITEM tvi = { 0 };
- char text[264];
+ TCHAR text[FLD_SIZE];
MCONTACT hContact;
- HWND hwnd2Settings = GetDlgItem(hwnd, IDC_SETTINGS);
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
tvi.hItem = pnmtv->itemNew.hItem;
tvi.pszText = text;
tvi.cchTextMax = SIZEOF(text);
TreeView_GetItem(pnmtv->hdr.hwndFrom, &tvi);
+
+ ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
- if (tvi.lParam) {
- mtis = (ModuleTreeInfoStruct *)tvi.lParam;
+ if (mtis) {
+
hContact = mtis->hContact;
if (mtis->type == STUB)
@@ -605,28 +524,14 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h Select = 0;
if (mtis->type == MODULE) {
- SettingListInfo *info = (SettingListInfo *)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA);
- BOOL refresh = 1;
-
- if (info) {
- if (info->hContact == hContact && !mir_strcmp(info->module, text))
- refresh = 0;
- }
-
- if (refresh)
- PopulateSettings(hwnd2Settings, hContact, text);
+ _T2A module(text);
+ PopulateSettings(hContact, module);
}
- else if (((mtis->type & CONTACT) == CONTACT && hContact) || (mtis->type == CONTACT_ROOT_ITEM && !hContact)) {
- char data[32], szProto[256];
- int index, loaded, multi = 0;
- LVITEM lvi = { 0 };
- lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
- lvi.iImage = 6;
-
- ClearListview(hwnd2Settings);
- SetWindowLongPtr(hwnd2Settings, GWLP_USERDATA, 0);
- if (himl2)
- ListView_SetImageList(hwnd2Settings, himl2, LVSIL_SMALL);
+ else
+ if (((mtis->type & CONTACT) == CONTACT && hContact) || (mtis->type == CONTACT_ROOT_ITEM && !hContact)) {
+ int multi = 0;
+
+ ClearListView();
if (mtis->type == CONTACT_ROOT_ITEM && !hContact) {
multi = 1;
@@ -634,41 +539,26 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h }
while (hContact && hwnd2mainWindow) {
- if (multi) {
- // filter
- if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
- loaded = IsProtocolLoaded(szProto);
- else
- loaded = 0;
-
- if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED)) {
- hContact = db_find_next(hContact);
- continue;
- }
- }
-
- lvi.iItem = 0;
- lvi.pszText = (char *)GetContactName(hContact, NULL, FALSE);
-
- index = ListView_InsertItem(hwnd2Settings, &lvi);
- mir_snprintf(data, SIZEOF(data), "0x%08X (%ld)", hContact, hContact);
+ if (multi && ApplyProtoFilter(hContact)) {
+ hContact = db_find_next(hContact);
+ continue;
+ }
- ListView_SetItemText(hwnd2Settings, index, 1, data);
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("HANDLE"));
- ListView_SetItemText(hwnd2Settings, index, 3, "0x0004 (4)");
+ addListHandle(hContact);
- if (!multi)
+ if (!multi) {
break;
+ }
hContact = db_find_next(hContact);
}
}
else
- ClearListview(hwnd2Settings);
+ ClearListView();
}
- else // clear any settings that may be there...
- ClearListview(hwnd2Settings);
+ else
+ ClearListView();
}
break; //TVN_SELCHANGED:
@@ -677,12 +567,11 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h moduleListRightClick(hwnd, wParam, lParam);
break;
- case TVN_BEGINLABELEDITA: // subclass it..
- case TVN_BEGINLABELEDITW:
+ case TVN_BEGINLABELEDIT: // subclass it..
{
LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam;
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)ptvdi->item.lParam;
- HWND hwnd2Edit = TreeView_GetEditControl(GetDlgItem(hwnd, IDC_MODULES));
+ HWND hwnd2Edit = TreeView_GetEditControl(hwnd2Tree);
if (!mtis->type || (mtis->type == CONTACT)) {
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE);
break;
@@ -692,12 +581,10 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h }
break;
- case TVN_ENDLABELEDITA:
- case TVN_ENDLABELEDITW:
+ case TVN_ENDLABELEDIT:
LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam;
TVITEM tvi = { 0 };
- char text[264];
- char *newtext;
+ TCHAR text[FLD_SIZE];
ModuleTreeInfoStruct *mtis;
tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM;
tvi.hItem = ptvdi->item.hItem;
@@ -706,32 +593,23 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
mtis = (ModuleTreeInfoStruct *)ptvdi->item.lParam;
- newtext = u2a((WCHAR *)ptvdi->item.pszText);
+ _T2A newtext(ptvdi->item.pszText);
+ _T2A oldtext(tvi.pszText);
if (!newtext // edit control failed
|| !mtis->type // its a root item
|| mtis->type == CONTACT // its a contact
- || *newtext == 0) // empty string
+ || newtext[0] == 0) // empty string
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, FALSE);
else {
- if (mir_strcmp(tvi.pszText, newtext)) {
- renameModule(tvi.pszText, newtext, mtis->hContact);
-
- findAndRemoveDuplicates(((LPNMHDR)lParam)->hwndFrom, mtis->hContact, newtext);
-
- if (TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi)) {
- tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
- tvi.iImage = 1;
- tvi.iSelectedImage = 2;
- TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
-
- PopulateSettings(GetDlgItem(hwnd, IDC_SETTINGS), mtis->hContact, newtext);
- }
+ if (mir_strcmp(oldtext, newtext)) {
+ renameModule(mtis->hContact, oldtext, newtext);
+ findAndRemoveDuplicates(mtis->hContact, newtext);
+ if (TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi))
+ PopulateSettings(mtis->hContact, newtext);
}
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE);
}
-
- mir_free(newtext);
break;
}
}
@@ -743,177 +621,173 @@ void moduleListRightClick(HWND hwnd, WPARAM, LPARAM lParam) // hwnd here is to t hti.pt.y = (short)HIWORD(GetMessagePos());
ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
- if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) {
- if (hti.flags & TVHT_ONITEM) {
- TVITEM tvi = { 0 };
- HMENU hMenu, hSubMenu;
- int menuNumber;
- char module[256];
- tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
- tvi.hItem = hti.hItem;
- tvi.pszText = module;
- tvi.cchTextMax = SIZEOF(module);
- TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
- if (tvi.lParam) {
- ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
- MCONTACT hContact = mtis->hContact;
- GetCursorPos(&hti.pt);
- hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXTMENU));
- TranslateMenu(hMenu);
- if (mtis->type == CONTACT && hContact)
- menuNumber = 2;
- else if ((mtis->type == MODULE) && !hContact)
- menuNumber = 1;
- else if (mtis->type == CONTACT && !hContact)
- menuNumber = 3;
- else if (mtis->type == CONTACT_ROOT_ITEM && !hContact)
- menuNumber = 4;
- else if ((mtis->type == MODULE) && hContact)
- menuNumber = 5;
- else return;
- hSubMenu = GetSubMenu(hMenu, menuNumber);
-
- TranslateMenu(hSubMenu);
- switch (menuNumber) {
- case 1: // null module
- case 5: // contact module
- {
- // check if we r already watching the module
- int i = 0, watching = 0;
- // check if the setting is being watched and if it is then check the menu item
- if (WatchListArray.item)
- for (i = 0; i < WatchListArray.count; i++)
- if (WatchListArray.item[i].module && (hContact == WatchListArray.item[i].hContact)) {
- if (!mir_strcmp(module, WatchListArray.item[i].module) && !WatchListArray.item[i].setting) {
- // yes so uncheck it
- CheckMenuItem(hSubMenu, MENU_WATCH_ITEM, MF_CHECKED | MF_BYCOMMAND);
- watching = 1;
- break;
- }
- }
-
- switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
- case MENU_RENAME_MOD:
- TreeView_EditLabel(GetDlgItem(hwnd, IDC_MODULES), tvi.hItem);
- break;
-
- case MENU_DELETE_MOD:
- if (deleteModule(module, hContact, 0)) {
- TreeView_DeleteItem(((LPNMHDR)lParam)->hwndFrom, hti.hItem);
- mir_free(mtis);
- }
- break;
+ if (!TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti) || !(hti.flags & TVHT_ONITEM)) return;
- case MENU_COPY_MOD:
- copyModuleMenuItem(module, hContact);
- break;
+ TVITEM tvi = { 0 };
+ HMENU hMenu, hSubMenu;
+ int menuNumber;
+ TCHAR text[FLD_SIZE];
- ////////////////////////////////////////////////////////////////////// divider
- case MENU_WATCH_ITEM:
- if (!watching)
- addSettingToWatchList(hContact, module, 0);
- else
- freeWatchListItem(i);
- if (hwnd2watchedVarsWindow)
- PopulateWatchedWindow(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS));
- break;
-
- case MENU_EXPORTMODULE:
- exportDB(hContact, module);
- break;
-
- case MENU_EXPORTDB:
- exportDB(INVALID_CONTACT_ID, module);
- break;
- }
- }
- break;
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
+ tvi.hItem = hti.hItem;
+ tvi.pszText = text;
+ tvi.cchTextMax = SIZEOF(text);
+ TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
- case 2: // contact
- switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
- case MENU_CLONE_CONTACT:
- if (CloneContact(hContact))
- refreshTree(1);
- break;
-
- case MENU_DELETE_CONTACT:
- if (db_get_b(NULL, "CList", "ConfirmDelete", 1)) {
- char msg[1024];
- mir_snprintf(msg, SIZEOF(msg), Translate("Are you sure you want to delete contact \"%s\"?"), module);
- if (MessageBox(0, msg, Translate("Confirm contact delete"), MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
- CallService(MS_DB_CONTACT_DELETE, hContact, 0);
- freeTree(((LPNMHDR)lParam)->hwndFrom, hContact);
- TreeView_DeleteItem(((LPNMHDR)lParam)->hwndFrom, tvi.hItem);
- }
- }
- else {
- CallService(MS_DB_CONTACT_DELETE, hContact, 0);
- freeTree(((LPNMHDR)lParam)->hwndFrom, hContact);
- TreeView_DeleteItem(((LPNMHDR)lParam)->hwndFrom, tvi.hItem);
- }
- break;
-
- ////////////////////////////////////////////////////////////////////// divider
- case MENU_EXPORTCONTACT:
- exportDB(hContact, 0);
- break;
- case MENU_IMPORTFROMTEXT:
- ImportSettingsMenuItem(hContact);
- break;
- case MENU_IMPORTFROMFILE:
- ImportSettingsFromFileMenuItem(hContact, "");
- break;
-
- ////////////////////////////////////////////////////////////////////// divider
- case MENU_ADD_MODULE:
- {
- HWND AddModhwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADD_MODULE), hwnd, AddModDlgProc, hContact);
- char msg[1024];
- mir_snprintf(msg, SIZEOF(msg), Translate("Add module to contact \"%s\""), module);
- SetWindowText(AddModhwnd, module);
- }
- break;
- }
- break;
+ if (!tvi.lParam) return;
- case 3: // NULL contact
- switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
- case MENU_ADD_MODULE:
- {
- HWND AddModhwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADD_MODULE), hwnd, AddModDlgProc, hContact);
- char msg[1024];
- mir_snprintf(msg, SIZEOF(msg), Translate("Add module to contact \"%s\""), module);
- SetWindowText(AddModhwnd, module);
- }
- break;
- case MENU_EXPORTCONTACT:
- exportDB(NULL, 0);
- break;
- case MENU_IMPORTFROMTEXT:
- ImportSettingsMenuItem(NULL);
- break;
- case MENU_IMPORTFROMFILE:
- ImportSettingsFromFileMenuItem(NULL, "");
- break;
- }
- break;
+ _T2A module(text);
+ ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
- case 4: // Contacts root
- switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
- case MENU_EXPORTCONTACT:
- exportDB(INVALID_CONTACT_ID, "");
- break;
- case MENU_IMPORTFROMTEXT:
- ImportSettingsMenuItem(NULL);
- break;
- case MENU_IMPORTFROMFILE:
- ImportSettingsFromFileMenuItem(NULL, "");
- break;
- }
+ MCONTACT hContact = mtis->hContact;
+ GetCursorPos(&hti.pt);
+
+ hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXTMENU));
+ TranslateMenu(hMenu);
+
+ if (mtis->type == CONTACT && hContact)
+ menuNumber = 2;
+ else if ((mtis->type == MODULE) && !hContact)
+ menuNumber = 1;
+ else if (mtis->type == CONTACT && !hContact)
+ menuNumber = 3;
+ else if (mtis->type == CONTACT_ROOT_ITEM && !hContact)
+ menuNumber = 4;
+ else if ((mtis->type == MODULE) && hContact)
+ menuNumber = 5;
+ else return;
+
+ hSubMenu = GetSubMenu(hMenu, menuNumber);
+
+ TranslateMenu(hSubMenu);
+ switch (menuNumber) {
+ case 1: // null module
+ case 5: // contact module
+ {
+ // check if the setting is being watched and if it is then check the menu item
+ int watchIdx = WatchedArrayIndex(hContact, module, NULL, 1);
+ if (watchIdx >= 0)
+ CheckMenuItem(hSubMenu, MENU_WATCH_ITEM, MF_CHECKED | MF_BYCOMMAND);
+
+ switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
+ case MENU_RENAME_MOD:
+ TreeView_EditLabel(hwnd2Tree, tvi.hItem);
+ break;
+
+ case MENU_DELETE_MOD:
+ if (deleteModule(hContact, module, 1)) {
+ TreeView_DeleteItem(((LPNMHDR)lParam)->hwndFrom, hti.hItem);
+ mir_free(mtis);
+ }
+ break;
+
+ case MENU_COPY_MOD:
+ copyModuleMenuItem(hContact, module);
+ break;
+
+ ////////////////////////////////////////////////////////////////////// divider
+ case MENU_WATCH_ITEM:
+ if (watchIdx < 0)
+ addSettingToWatchList(hContact, module, 0);
+ else
+ freeWatchListItem(watchIdx);
+ PopulateWatchedWindow();
+ break;
+
+ case MENU_REFRESH:
+ refreshTree(1);
+ break;
+
+ case MENU_EXPORTMODULE:
+ exportDB(hContact, module);
+ break;
+
+ case MENU_EXPORTDB:
+ exportDB(INVALID_CONTACT_ID, module);
+ break;
+ }
+ }
+ break;
+
+ case 2: // contact
+ switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
+ case MENU_CLONE_CONTACT:
+ if (CloneContact(hContact))
+ refreshTree(1);
+ break;
+
+ case MENU_DELETE_CONTACT:
+ if (db_get_b(NULL, "CList", "ConfirmDelete", 1)) {
+ TCHAR str[MSG_SIZE];
+ mir_sntprintf(str, TranslateT("Are you sure you want to delete contact \"%s\"?"), text);
+ if (dlg(str, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
break;
- }
- DestroyMenu(hMenu);
}
+ CallService(MS_DB_CONTACT_DELETE, hContact, 0);
+ freeTree(hContact);
+ TreeView_DeleteItem(hwnd2Tree, tvi.hItem);
+ break;
+
+ ////////////////////////////////////////////////////////////////////// divider
+ case MENU_EXPORTCONTACT:
+ exportDB(hContact, 0);
+ break;
+ case MENU_IMPORTFROMTEXT:
+ ImportSettingsMenuItem(hContact);
+ break;
+ case MENU_IMPORTFROMFILE:
+ ImportSettingsFromFileMenuItem(hContact, NULL);
+ break;
+
+ ////////////////////////////////////////////////////////////////////// divider
+ case MENU_ADD_MODULE:
+ addModuleDlg(hContact);
+ break;
+
+ case MENU_REFRESH:
+ refreshTree(1);
+ break;
+
}
+ break;
+
+ case 3: // NULL contact
+ switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
+ case MENU_ADD_MODULE:
+ addModuleDlg(hContact);
+ break;
+ case MENU_EXPORTCONTACT:
+ exportDB(NULL, 0);
+ break;
+ case MENU_IMPORTFROMTEXT:
+ ImportSettingsMenuItem(NULL);
+ break;
+ case MENU_IMPORTFROMFILE:
+ ImportSettingsFromFileMenuItem(NULL, NULL);
+ break;
+ case MENU_REFRESH:
+ refreshTree(1);
+ break;
+ }
+ break;
+
+ case 4: // Contacts root
+ switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
+ case MENU_EXPORTCONTACT:
+ exportDB(INVALID_CONTACT_ID, 0);
+ break;
+ case MENU_IMPORTFROMTEXT:
+ ImportSettingsMenuItem(NULL);
+ break;
+ case MENU_IMPORTFROMFILE:
+ ImportSettingsFromFileMenuItem(NULL, NULL);
+ break;
+ case MENU_REFRESH:
+ refreshTree(1);
+ break;
+ }
+ break;
}
+ DestroyMenu(hMenu);
+
}
|