From ffdd43398c6beebd3eaeb8a3b8d0722f90c470ba Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 21 Sep 2022 22:12:40 +0300 Subject: =?UTF-8?q?fixes=20#3202=20(StdUserInfo:=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BA=D0=BE=D1=88=D0=B5=D0=BD=D1=8B=20=D1=8D=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D1=8B=20=D0=BD=D0=B0=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5=20"=D0=90=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=D1=80")?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/AVS/src/main.cpp | 3 +- plugins/AVS/src/stdafx.h | 4 + plugins/AVS/src/userInfo.cpp | 202 +++++++++++++++++++++---------------------- plugins/AVS/src/version.h | 2 +- 4 files changed, 104 insertions(+), 107 deletions(-) (limited to 'plugins/AVS/src') diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index 4dacf724bb..2ad7a85047 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -56,7 +56,8 @@ static PLUGININFOEX pluginInfoEx = }; CMPlugin::CMPlugin() : - PLUGIN("AVS_Settings", pluginInfoEx) + PLUGIN(MODULENAME, pluginInfoEx), + bPerProto(MODULENAME, "PerProtocolUserAvatars", 1) {} ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/AVS/src/stdafx.h b/plugins/AVS/src/stdafx.h index 7325135953..c43d83e32a 100644 --- a/plugins/AVS/src/stdafx.h +++ b/plugins/AVS/src/stdafx.h @@ -52,6 +52,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "poll.h" #include "acc.h" +#define MODULENAME "AVS_Settings" + #ifndef SHVIEW_THUMBNAIL #define SHVIEW_THUMBNAIL 0x702D #endif @@ -62,6 +64,8 @@ struct CMPlugin : public PLUGIN { CMPlugin(); + CMOption bPerProto; + int Load() override; int Unload() override; }; diff --git a/plugins/AVS/src/userInfo.cpp b/plugins/AVS/src/userInfo.cpp index 2a90f55e27..88be8bd99d 100644 --- a/plugins/AVS/src/userInfo.cpp +++ b/plugins/AVS/src/userInfo.cpp @@ -242,109 +242,68 @@ public: ///////////////////////////////////////////////////////////////////////////////////////// // Protocol avatar dialog -static char* GetSelectedProtocol(HWND hwndDlg) +class AvatarProtoInfoDlg : public CUserInfoPageDlg { - HWND hwndList = GetDlgItem(hwndDlg, IDC_PROTOCOLS); - - // Get selection - int iItem = ListView_GetSelectionMark(hwndList); - if (iItem < 0) - return nullptr; - - // Get protocol name - LVITEM item = { 0 }; - item.mask = LVIF_PARAM; - item.iItem = iItem; - SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&item); - return (char*)item.lParam; -} + char* GetSelectedProtocol() + { + // Get selection + int iItem = protocols.GetSelectionMark(); + if (iItem < 0) + return nullptr; + + // Get protocol name + LVITEM item = {0}; + item.mask = LVIF_PARAM; + item.iItem = iItem; + SendMessage(protocols.GetHwnd(), LVM_GETITEMA, 0, (LPARAM)&item); + return (char *)item.lParam; + } -static void EnableDisableControls(HWND hwndDlg, char *proto) -{ - if (IsDlgButtonChecked(hwndDlg, IDC_PER_PROTO)) { - if (proto == nullptr) { - EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE); - } - else { - if (!ProtoServiceExists(proto, PS_SETMYAVATAR)) { - EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE); + void OffsetWindow(int iCtrlId, int dx) + { + HWND hwnd = GetDlgItem(m_hwnd, iCtrlId); + + RECT rc; + GetWindowRect(hwnd, &rc); + ScreenToClient(m_hwnd, &rc); + OffsetRect(&rc, dx, 0); + MoveWindow(hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); + } + + void EnableDisableControls(char *proto) + { + if (chkPerProto.IsChecked()) { + if (proto == nullptr) { + EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), FALSE); + EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), FALSE); } else { - EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE), TRUE); - - int width, height; - SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height); - EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), (LPARAM)width != 0 || height != 0); + if (!ProtoServiceExists(proto, PS_SETMYAVATAR)) { + EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), FALSE); + EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), FALSE); + } + else { + EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), TRUE); + + int width, height; + SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height); + EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), (LPARAM)width != 0 || height != 0); + } } } - } - else { - EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE), TRUE); - - if (g_plugin.getByte("GlobalUserAvatarNotConsistent", 1)) - EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE); else { - int width, height; - SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height); - EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), (LPARAM)width != 0 || height != 0); - } - } -} + EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), TRUE); -static void OffsetWindow(HWND parent, HWND hwnd, int dx, int dy) -{ - RECT rc; - GetWindowRect(hwnd, &rc); - ScreenToClient(parent, &rc); - OffsetRect(&rc, dx, dy); - MoveWindow(hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); -} - -static void EnableDisableProtocols(HWND hwndDlg, BOOL init) -{ - int diff = 147; // Pre-calc - BOOL perProto = IsDlgButtonChecked(hwndDlg, IDC_PER_PROTO); - HWND hwndList = GetDlgItem(hwndDlg, IDC_PROTOCOLS); - - if (perProto) { - if (!init && !IsWindowVisible(hwndList)) { - // Show list of protocols - ShowWindow(hwndList, SW_SHOW); - - // Move controls - OffsetWindow(hwndDlg, GetDlgItem(hwndDlg, IDC_PROTOPIC), diff, 0); - OffsetWindow(hwndDlg, GetDlgItem(hwndDlg, IDC_CHANGE), diff, 0); - OffsetWindow(hwndDlg, GetDlgItem(hwndDlg, IDC_DELETE), diff, 0); - } - - char * proto = GetSelectedProtocol(hwndDlg); - if (proto == nullptr) { - ListView_SetItemState(hwndList, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x0F); - } - else { - SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, (LPARAM)proto); - EnableDisableControls(hwndDlg, proto); + if (g_plugin.getByte("GlobalUserAvatarNotConsistent", 1)) + EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), TRUE); + else { + int width, height; + SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height); + EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), (LPARAM)width != 0 || height != 0); + } } } - else { - if (init || IsWindowVisible(hwndList)) { - // Show list of protocols - ShowWindow(hwndList, SW_HIDE); - - // Move controls - OffsetWindow(hwndDlg, GetDlgItem(hwndDlg, IDC_PROTOPIC), -diff, 0); - OffsetWindow(hwndDlg, GetDlgItem(hwndDlg, IDC_CHANGE), -diff, 0); - OffsetWindow(hwndDlg, GetDlgItem(hwndDlg, IDC_DELETE), -diff, 0); - } - SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, NULL); - } -} - -class AvatarProtoInfoDlg : public CUserInfoPageDlg -{ CCtrlCheck chkPerProto; CCtrlButton btnChange, btnDelete; CCtrlListView protocols; @@ -360,6 +319,7 @@ public: btnChange.OnClick = Callback(this, &AvatarProtoInfoDlg::onClick_Change); btnDelete.OnClick = Callback(this, &AvatarProtoInfoDlg::onClick_Delete); + CreateLink(chkPerProto, g_plugin.bPerProto); chkPerProto.OnChange = Callback(this, &AvatarProtoInfoDlg::onChange_PerProto); } @@ -403,10 +363,6 @@ public: protocols.SetColumnWidth(0, LVSCW_AUTOSIZE); protocols.Arrange(LVA_ALIGNLEFT | LVA_ALIGNTOP); - - // Check if should show per protocol avatars - CheckDlgButton(m_hwnd, IDC_PER_PROTO, g_plugin.getByte("PerProtocolUserAvatars", 1) ? BST_CHECKED : BST_UNCHECKED); - EnableDisableProtocols(m_hwnd, TRUE); return true; } @@ -415,7 +371,7 @@ public: LPNMLISTVIEW li = ev->nmlv; if (li->uNewState & LVIS_SELECTED) { SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, li->lParam); - EnableDisableControls(m_hwnd, (char*)li->lParam); + EnableDisableControls((char*)li->lParam); } } @@ -424,17 +380,17 @@ public: if (msg == WM_NOTIFY) { LPNMHDR hdr = (LPNMHDR)lParam; if (hdr->idFrom == IDC_PROTOPIC && hdr->code == NM_AVATAR_CHANGED) - EnableDisableControls(m_hwnd, GetSelectedProtocol(m_hwnd)); + EnableDisableControls(GetSelectedProtocol()); } return CDlgBase::DlgProc(msg, wParam, lParam); } void onClick_Change(CCtrlButton *) { - if (BST_UNCHECKED == IsDlgButtonChecked(m_hwnd, IDC_PER_PROTO)) + if (!chkPerProto.IsChecked()) SetMyAvatar(NULL, NULL); else { - char *proto = GetSelectedProtocol(m_hwnd); + char *proto = GetSelectedProtocol(); if (proto != nullptr) SetMyAvatar((WPARAM)proto, NULL); } @@ -442,12 +398,12 @@ public: void onClick_Delete(CCtrlButton *) { - if (BST_UNCHECKED == IsDlgButtonChecked(m_hwnd, IDC_PER_PROTO)) { + if (!chkPerProto.IsChecked()) { if (MessageBox(m_hwnd, TranslateT("Are you sure you want to remove your avatar?"), TranslateT("Global avatar"), MB_YESNO) == IDYES) SetMyAvatar(NULL, (LPARAM)L""); } else { - if (char *proto = GetSelectedProtocol(m_hwnd)) { + if (char *proto = GetSelectedProtocol()) { char description[256]; CallProtoService(proto, PS_GETNAME, _countof(description), (LPARAM)description); wchar_t *descr = mir_a2u(description); @@ -458,10 +414,46 @@ public: } } - void onChange_PerProto(CCtrlCheck*) + void onChange_PerProto(CCtrlCheck *pCheck) { - g_plugin.setByte("PerProtocolUserAvatars", IsDlgButtonChecked(m_hwnd, IDC_PER_PROTO) ? 1 : 0); - EnableDisableProtocols(m_hwnd, FALSE); + int diff = 147; // Pre-calc + + if (chkPerProto.IsChecked()) { + if (!IsWindowVisible(protocols.GetHwnd())) { + // Show list of protocols + protocols.Show(); + + // Move controls + OffsetWindow(IDC_PROTOPIC, diff); + OffsetWindow(IDC_CHANGE, diff); + OffsetWindow(IDC_DELETE, diff); + } + + char *proto = GetSelectedProtocol(); + if (proto == nullptr) { + protocols.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, 0x0F); + } + else { + SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, (LPARAM)proto); + EnableDisableControls(proto); + } + } + else { + if (!m_bInitialized) { + PostMessage(m_hwnd, WM_COMMAND, IDC_PER_PROTO, 0); + } + else if (!pCheck || IsWindowVisible(protocols.GetHwnd())) { + // Hide list of protocols + protocols.Hide(); + + // Move controls + OffsetWindow(IDC_PROTOPIC, -diff); + OffsetWindow(IDC_CHANGE, -diff); + OffsetWindow(IDC_DELETE, -diff); + } + + SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, NULL); + } } }; diff --git a/plugins/AVS/src/version.h b/plugins/AVS/src/version.h index 311e8f193b..6b3a39b15b 100644 --- a/plugins/AVS/src/version.h +++ b/plugins/AVS/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 98 #define __RELEASE_NUM 1 -#define __BUILD_NUM 5 +#define __BUILD_NUM 6 #include -- cgit v1.2.3