From a664f6673ee9030c8aa2d7d36d760543753cbb2b Mon Sep 17 00:00:00 2001
From: George Hazan <ghazan@miranda.im>
Date: Mon, 19 Oct 2020 14:30:41 +0300
Subject:  SeenPlugin: tree control replaced with a list in options

---
 plugins/SeenPlugin/res/resource.rc | 15 +++++++--
 plugins/SeenPlugin/src/options.cpp | 68 +++++++++++++++-----------------------
 plugins/SeenPlugin/src/resource.h  | 11 ++----
 plugins/SeenPlugin/src/version.h   |  2 +-
 4 files changed, 44 insertions(+), 52 deletions(-)

diff --git a/plugins/SeenPlugin/res/resource.rc b/plugins/SeenPlugin/res/resource.rc
index 4b6fbc1394..41ee25ec08 100644
--- a/plugins/SeenPlugin/res/resource.rc
+++ b/plugins/SeenPlugin/res/resource.rc
@@ -73,7 +73,7 @@ BEGIN
     CONTROL         "Enable 'Missed Ones' feature",IDC_MISSEDONES,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,6,200,149,10
     CONTROL         "Count times",IDC_COUNT,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,16,212,139,10
     LTEXT           "Accounts to watch:",IDC_MAINGROUP,162,144,138,9
-    CONTROL         "Tree1",IDC_PROTOCOLLIST,"SysTreeView32",TVS_NOTOOLTIPS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,162,154,138,77
+    CONTROL         "",IDC_PROTOCOLLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,162,154,138,77
 END
 
 IDD_POPUPS DIALOGEX 0, 0, 280, 208
@@ -161,7 +161,7 @@ BEGIN
         RIGHTMARGIN, 300
         VERTGUIDE, 6
         VERTGUIDE, 16
-        VERTGUIDE, 155
+        VERTGUIDE, 156
         VERTGUIDE, 162
         BOTTOMMARGIN, 228
     END
@@ -196,6 +196,17 @@ BEGIN
 END
 #endif    // APSTUDIO_INVOKED
 
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// AFX_DIALOG_LAYOUT
+//
+
+IDD_SETTINGS AFX_DIALOG_LAYOUT
+BEGIN
+    0
+END
+
 #endif    // German (Germany) resources
 /////////////////////////////////////////////////////////////////////////////
 
diff --git a/plugins/SeenPlugin/src/options.cpp b/plugins/SeenPlugin/src/options.cpp
index 9c387d1c83..faff6c7ee3 100644
--- a/plugins/SeenPlugin/src/options.cpp
+++ b/plugins/SeenPlugin/src/options.cpp
@@ -210,7 +210,7 @@ class CMainOptsDlg : public CDlgBase
 {
 	CCtrlCheck chkFile, chkMissed, chkHistory, chkMenuItem, chkUserInfo;
 	CCtrlButton btnVariables;
-	CCtrlTreeView protocols;
+	CCtrlListView protocols;
 
 public:
 	CMainOptsDlg() :
@@ -223,8 +223,6 @@ public:
 		protocols(this, IDC_PROTOCOLLIST),
 		btnVariables(this, IDC_VARIABLES)
 	{
-		protocols.SetFlags(MTREE_CHECKBOX);
-
 		btnVariables.OnClick = Callback(this, &CMainOptsDlg::onClick_Variables);
 
 		chkFile.OnChange = Callback(this, &CMainOptsDlg::onChanged_File);
@@ -256,20 +254,24 @@ public:
 		SetDlgItemInt(m_hwnd, IDC_HISTORYSIZE, g_plugin.getWord("HistoryMax", 10 - 1) - 1, FALSE);
 
 		// load protocol list
-		TVINSERTSTRUCT tvis;
-		tvis.hParent = nullptr;
-		tvis.hInsertAfter = TVI_LAST;
-		tvis.item.mask = TVIF_TEXT | TVIF_HANDLE | TVIF_PARAM | TVIF_IMAGE;
-		tvis.item.stateMask = TVIS_STATEIMAGEMASK;
+		protocols.SetExtendedListViewStyle(LVS_EX_CHECKBOXES);
+
+		RECT rc;
+		GetClientRect(protocols.GetHwnd(), &rc);
+
+		LVCOLUMN lvc = {};
+		lvc.mask = LVCF_FMT | LVCF_WIDTH;
+		lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT;
+		lvc.cx = 120;
+		protocols.InsertColumn(0, &lvc);
 
 		for (auto &pa : Accounts()) {
 			if (CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0) == 0)
 				continue;
 
-			tvis.item.pszText = pa->tszAccountName;
-			tvis.item.lParam = (LPARAM)mir_strdup(pa->szModuleName);
-			tvis.item.iImage = IsWatchedProtocol(pa->szModuleName);
-			protocols.InsertItem(&tvis);
+			int idx = protocols.AddItem(pa->tszAccountName, 0, (LPARAM)mir_strdup(pa->szModuleName));
+			if (IsWatchedProtocol(pa->szModuleName))
+				protocols.SetCheckState(idx, true);
 		}
 		return true;
 	}
@@ -341,26 +343,17 @@ public:
 		g_plugin.setByte("IdleSupport", IsDlgButtonChecked(m_hwnd, IDC_IDLESUPPORT));
 
 		// save protocol list
-		int size = 1;
-
 		CMStringA watchedProtocols;
-		HTREEITEM hItem = protocols.GetRoot();
-
-		TVITEMEX tvItem;
-		tvItem.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_PARAM;
-		tvItem.stateMask = TVIS_STATEIMAGEMASK;
-
-		while (hItem != nullptr) {
-			tvItem.hItem = hItem;
-			protocols.GetItem(&tvItem);
-			char *protocol = (char *)tvItem.lParam;
-			if (tvItem.iImage) {
-				size += (int)mir_strlen(protocol) + 2;
-				if (!watchedProtocols.IsEmpty())
-					watchedProtocols.AppendChar('\n');
-				watchedProtocols.Append(protocol);
-			}
-			hItem = protocols.GetNextSibling(hItem);
+
+		int nItems = protocols.GetItemCount();
+		for (int i=0; i < nItems; i++) {
+			if (!protocols.GetCheckState(i))
+				continue;
+
+			char *szProto = (char *)protocols.GetItemData(i);
+			if (!watchedProtocols.IsEmpty())
+				watchedProtocols.AppendChar('\n');
+			watchedProtocols.Append(szProto);
 		}
 		g_plugin.setString("WatchedAccounts", watchedProtocols);
 
@@ -372,16 +365,9 @@ public:
 	void OnDestroy() override
 	{
 		// free protocol list 
-		HTREEITEM hItem = protocols.GetRoot();
-		TVITEMEX tvItem;
-		tvItem.mask = TVIF_HANDLE | TVIF_PARAM;
-
-		while (hItem != nullptr) {
-			tvItem.hItem = hItem;
-			protocols.GetItem(&tvItem);
-			mir_free((void *)tvItem.lParam);
-			hItem = protocols.GetNextSibling(hItem);
-		}
+		int nItems = protocols.GetItemCount();
+		for (int i = 0; i < nItems; i++)
+			mir_free((void *)(char *)protocols.GetItemData(i));
 	}
 
 	void onChanged_MenuItem(CCtrlCheck *)
diff --git a/plugins/SeenPlugin/src/resource.h b/plugins/SeenPlugin/src/resource.h
index 049fbe8011..f3a5d84aec 100644
--- a/plugins/SeenPlugin/src/resource.h
+++ b/plugins/SeenPlugin/src/resource.h
@@ -2,11 +2,6 @@
 // Microsoft Developer Studio generated include file.
 // Used by resource.rc
 //
-
-#ifndef TVS_NOTOOLTIPS
-#define TVS_NOTOOLTIPS 0x0080
-#endif
-
 #define IDD_SETTINGS                    101
 #define IDD_USERINFO                    102
 #define IDD_MISSED                      103
@@ -61,16 +56,16 @@
 #define IDC_SENDMSG                     1044
 #define IDC_LABTTITLE                   1045
 #define IDC_OPTIONSTAB                  1046
-#define IDC_IDLESUPPORT					1047
+#define IDC_IDLESUPPORT                 1047
 #define IDC_MAINGROUP                   -1
 #define IDC_INFO                        -1
 #define IDC_TEXT                        -1
 
 // Next default values for new objects
-//
+// 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        107
+#define _APS_NEXT_RESOURCE_VALUE        108
 #define _APS_NEXT_COMMAND_VALUE         40001
 #define _APS_NEXT_CONTROL_VALUE         1048
 #define _APS_NEXT_SYMED_VALUE           101
diff --git a/plugins/SeenPlugin/src/version.h b/plugins/SeenPlugin/src/version.h
index 4cad78a115..c9985ea465 100644
--- a/plugins/SeenPlugin/src/version.h
+++ b/plugins/SeenPlugin/src/version.h
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define __MAJOR_VERSION          5
 #define __MINOR_VERSION          0
 #define __RELEASE_NUM            5
-#define __BUILD_NUM              5
+#define __BUILD_NUM              6
 
 #include <stdver.h>
 
-- 
cgit v1.2.3