diff options
author | George Hazan <ghazan@miranda.im> | 2022-06-16 14:05:32 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-06-16 14:05:32 +0300 |
commit | 5a2aee11f0dcdee550c49e6b28d919c026278070 (patch) | |
tree | f4c3f22631798dc74f2912b3ff40c206568bf46f | |
parent | 2893a08123145b216404cb9691850ebaf11c7fe6 (diff) |
UInfoEx: get rid of those dialog procedures + country flags working again
-rw-r--r-- | plugins/UserInfoEx/src/ctrl_edit.cpp | 25 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/ctrl_edit.h | 1 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/psp_base.cpp | 23 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/psp_base.h | 4 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/psp_contact.cpp | 110 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/psp_origin.cpp | 20 |
6 files changed, 66 insertions, 117 deletions
diff --git a/plugins/UserInfoEx/src/ctrl_edit.cpp b/plugins/UserInfoEx/src/ctrl_edit.cpp index 99d8f22b75..75a82e7a37 100644 --- a/plugins/UserInfoEx/src/ctrl_edit.cpp +++ b/plugins/UserInfoEx/src/ctrl_edit.cpp @@ -268,31 +268,6 @@ void CEditCtrl::OnChangedByUser(uint16_t wChangedMsg) } } -/** - * Opens the url given in a editbox in the users default browser - **/ -void CEditCtrl::OpenUrl() -{ - int lenUrl = 1 + Edit_GetTextLength(_hwnd); - LPTSTR szUrl; - uint8_t need_free = 0; - - __try { - szUrl = (LPTSTR)alloca((8 + lenUrl) * sizeof(wchar_t)); - } - __except (EXCEPTION_EXECUTE_HANDLER) - { - szUrl = (LPTSTR)mir_alloc((8 + lenUrl) * sizeof(wchar_t)); - need_free = 1; - } - - if (szUrl && (GetWindowText(_hwnd, szUrl, lenUrl) > 0)) - Utils_OpenUrlW(szUrl); - - if (need_free) - MIR_FREE(szUrl); -} - LRESULT CEditCtrl::LinkNotificationHandler(ENLINK* lnk) { if (lnk == nullptr) diff --git a/plugins/UserInfoEx/src/ctrl_edit.h b/plugins/UserInfoEx/src/ctrl_edit.h index 89daafc727..d0864c1d01 100644 --- a/plugins/UserInfoEx/src/ctrl_edit.h +++ b/plugins/UserInfoEx/src/ctrl_edit.h @@ -61,7 +61,6 @@ public: virtual void OnApply(MCONTACT hContact, LPCSTR pszProto);
virtual void OnChangedByUser(uint16_t wChangedMsg);
- void OpenUrl();
LRESULT LinkNotificationHandler(ENLINK* lnk);
};
diff --git a/plugins/UserInfoEx/src/psp_base.cpp b/plugins/UserInfoEx/src/psp_base.cpp index 91a07e4957..8b42524e17 100644 --- a/plugins/UserInfoEx/src/psp_base.cpp +++ b/plugins/UserInfoEx/src/psp_base.cpp @@ -21,14 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
-void UpDate_CountryIcon(HWND hCtrl, int countryID)
-{
- HICON hIcon = LoadFlagIcon(countryID);
- HICON hOld = Static_SetIcon(hCtrl, hIcon);
- ShowWindow(hCtrl, hIcon ? SW_SHOW : SW_HIDE);
- IcoLib_ReleaseIcon(hOld);
-}
-
PSPBaseDlg::PSPBaseDlg(int idDialog) :
CUserInfoPageDlg(g_plugin, idDialog),
m_ctrlList(nullptr)
@@ -47,7 +39,7 @@ bool PSPBaseDlg::OnInitDialog() bool PSPBaseDlg::OnRefresh()
{
if (auto *pszProto = GetBaseProto())
- return (GetWindowLongPtr(m_hwnd, DWLP_MSGRESULT) & PSP_CHANGED) | m_ctrlList->OnInfoChanged(m_hContact, pszProto);
+ return m_ctrlList->OnInfoChanged(m_hContact, pszProto);
return false;
}
@@ -112,3 +104,16 @@ const char *PSPBaseDlg::GetBaseProto() const const char *res = "";
return (SendMessage(m_hwndParent, PSM_GETBASEPROTO, INDEX_CURPAGE, LPARAM(&res)) && *res) ? res : nullptr;
}
+
+void PSPBaseDlg::UpdateCountryIcon(CCtrlCombo &pCombo)
+{
+ LPIDSTRLIST pd = (LPIDSTRLIST)pCombo.GetCurData();
+ if (pd == nullptr)
+ return;
+
+ auto *pCtrl = FindControl(ICO_COUNTRY);
+ HICON hIcon = LoadFlagIcon(pd->nID);
+ HICON hOld = Static_SetIcon(pCtrl->GetHwnd(), hIcon);
+ pCtrl->Show(hIcon != 0);
+ IcoLib_ReleaseIcon(hOld);
+}
diff --git a/plugins/UserInfoEx/src/psp_base.h b/plugins/UserInfoEx/src/psp_base.h index 109b751c6e..87e034560c 100644 --- a/plugins/UserInfoEx/src/psp_base.h +++ b/plugins/UserInfoEx/src/psp_base.h @@ -43,6 +43,8 @@ protected: INT_PTR DlgProc(UINT uMsg, WPARAM, LPARAM) override;
+ void UpdateCountryIcon(CCtrlCombo &pCombo);
+
HFONT GetBoldFont() const;
MCONTACT GetContact() const;
const char* GetBaseProto() const;
@@ -58,6 +60,4 @@ void InitAnniversaryDlg(WPARAM wParam, USERINFOPAGE &uip); void InitOriginDlg(WPARAM wParam, USERINFOPAGE &uip, bool bReadOnly);
void InitProfileDlg(WPARAM wParam, USERINFOPAGE &uip);
-void UpDate_CountryIcon(HWND hCtrl, int countryID);
-
#endif /* _UI_PSP_BASE_INCLUDE_ */
diff --git a/plugins/UserInfoEx/src/psp_contact.cpp b/plugins/UserInfoEx/src/psp_contact.cpp index 6ab73aaf49..dceaefc121 100644 --- a/plugins/UserInfoEx/src/psp_contact.cpp +++ b/plugins/UserInfoEx/src/psp_contact.cpp @@ -21,25 +21,59 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
+class PSPContactDlgBase : public PSPBaseDlg
+{
+ CCtrlEdit homePage;
+ CCtrlCombo cmbCountry;
+ CCtrlButton btnGoto;
+
+public:
+ PSPContactDlgBase() :
+ PSPBaseDlg(IDD_CONTACT_ADDRESS),
+ btnGoto(this, BTN_GOTO),
+ homePage(this, EDIT_HOMEPAGE),
+ cmbCountry(this, EDIT_COUNTRY)
+ {
+ btnGoto.OnClick = Callback(this, &PSPContactDlgBase::onClick_Goto);
+ homePage.OnChange = Callback(this, &PSPContactDlgBase::onChange_HomePage);
+ cmbCountry.OnSelChanged = Callback(this, &PSPContactDlgBase::onSelChanged_Country);
+ }
+
+ bool OnInitDialog() override
+ {
+ btnGoto.SendMsg(BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open in browser"), MBBF_TCHAR);
+ return PSPBaseDlg::OnInitDialog();
+ }
+
+ void onClick_Goto(CCtrlButton *)
+ {
+ Utils_OpenUrlW(ptrW(homePage.GetText()));
+ }
+
+ void onChange_HomePage(CCtrlEdit *)
+ {
+ btnGoto.Enable(mir_wstrlen(ptrW(homePage.GetText())) > 0);
+ }
+
+ void onSelChanged_Country(CCtrlCombo *)
+ {
+ UpdateCountryIcon(cmbCountry);
+ }
+};
+
/////////////////////////////////////////////////////////////////////////////////////////
// Home contact info
-struct PSPContactHomeDlg : public PSPBaseDlg
+struct PSPContactHomeDlg : public PSPContactDlgBase
{
- PSPContactHomeDlg() :
- PSPBaseDlg(IDD_CONTACT_ADDRESS)
- {}
-
bool OnInitDialog() override
{
- PSPBaseDlg::OnInitDialog();
+ PSPContactDlgBase::OnInitDialog();
wchar_t szAddr[MAX_PATH];
mir_snwprintf(szAddr, L"%s (%s)", TranslateT("Address"), TranslateT("home"));
SetDlgItemText(m_hwnd, IDC_PAGETITLE, szAddr);
- SendDlgItemMessage(m_hwnd, BTN_GOTO, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open in browser"), MBBF_TCHAR);
-
m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STREET, SET_CONTACT_STREET, DBVT_WCHAR));
m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_CITY, SET_CONTACT_CITY, DBVT_WCHAR));
m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_ZIP, SET_CONTACT_ZIP, DBVT_WCHAR));
@@ -117,51 +151,20 @@ struct PSPContactHomeDlg : public PSPBaseDlg SendDlgItemMessage(m_hwnd, EDIT_PHONE, WM_SETICON, NULL, NULL);
SendDlgItemMessage(m_hwnd, EDIT_EMAIL, WM_SETICON, NULL, NULL);
}
-
- INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override
- {
- if (uMsg == WM_COMMAND) {
- switch (LOWORD(wParam)) {
- case EDIT_HOMEPAGE:
- if (HIWORD(wParam) == EN_UPDATE)
- EnableWindow(GetDlgItem(m_hwnd, BTN_GOTO), GetWindowTextLength((HWND)lParam) > 0);
- break;
-
- case BTN_GOTO:
- CEditCtrl::GetObj(m_hwnd, EDIT_HOMEPAGE)->OpenUrl();
- break;
-
- case EDIT_COUNTRY:
- if (HIWORD(wParam) == CBN_SELCHANGE) {
- LPIDSTRLIST pd = (LPIDSTRLIST)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
- UpDate_CountryIcon(GetDlgItem(m_hwnd, ICO_COUNTRY), pd->nID);
- }
- break;
- }
- }
-
- return PSPBaseDlg::DlgProc(uMsg, wParam, lParam);
- }
};
/////////////////////////////////////////////////////////////////////////////////////////
// Work contact info
-struct PSPContactWorkDlg : public PSPBaseDlg
+struct PSPContactWorkDlg : public PSPContactDlgBase
{
- PSPContactWorkDlg() :
- PSPBaseDlg(IDD_CONTACT_ADDRESS)
- {}
-
bool OnInitDialog() override
{
- PSPBaseDlg::OnInitDialog();
+ PSPContactDlgBase::OnInitDialog();
wchar_t szAddr[MAX_PATH];
mir_snwprintf(szAddr, L"%s (%s)", TranslateT("Address and contact"), TranslateT("company"));
SetDlgItemText(m_hwnd, IDC_PAGETITLE, szAddr);
- SendDlgItemMessage(m_hwnd, BTN_GOTO, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open in browser"), MBBF_TCHAR);
- TranslateDialogDefault(m_hwnd);
m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STREET, SET_CONTACT_COMPANY_STREET, DBVT_WCHAR));
m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_CITY, SET_CONTACT_COMPANY_CITY, DBVT_WCHAR));
@@ -240,31 +243,6 @@ struct PSPContactWorkDlg : public PSPBaseDlg SendDlgItemMessage(m_hwnd, EDIT_PHONE, WM_SETICON, NULL, NULL);
SendDlgItemMessage(m_hwnd, EDIT_EMAIL, WM_SETICON, NULL, NULL);
}
-
- INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override
- {
- if (uMsg == WM_COMMAND) {
- switch (LOWORD(wParam)) {
- case EDIT_HOMEPAGE:
- if (HIWORD(wParam) == EN_UPDATE)
- EnableWindow(GetDlgItem(m_hwnd, BTN_GOTO), GetWindowTextLength((HWND)lParam) > 0);
- break;
-
- case BTN_GOTO:
- CEditCtrl::GetObj(m_hwnd, EDIT_HOMEPAGE)->OpenUrl();
- break;
-
- case EDIT_COUNTRY:
- if (HIWORD(wParam) == CBN_SELCHANGE) {
- LPIDSTRLIST pd = (LPIDSTRLIST)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
- UpDate_CountryIcon(GetDlgItem(m_hwnd, ICO_COUNTRY), pd->nID);
- }
- break;
- }
- }
-
- return PSPBaseDlg::DlgProc(uMsg, wParam, lParam);
- }
};
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/UserInfoEx/src/psp_origin.cpp b/plugins/UserInfoEx/src/psp_origin.cpp index e9558e058e..771bc54d27 100644 --- a/plugins/UserInfoEx/src/psp_origin.cpp +++ b/plugins/UserInfoEx/src/psp_origin.cpp @@ -24,13 +24,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. class PSPOriginDlg : public PSPBaseDlg
{
CTimer timer;
+ CCtrlCombo cmbCountry;
public:
PSPOriginDlg() :
PSPBaseDlg(IDD_CONTACT_ORIGIN),
- timer(this, 1)
+ timer(this, 1),
+ cmbCountry(this, EDIT_COUNTRY)
{
timer.OnEvent = Callback(this, &PSPOriginDlg::onTimer);
+ cmbCountry.OnSelChanged = Callback(this, &PSPOriginDlg::onSelChanged_Country);
}
bool OnInitDialog() override
@@ -100,20 +103,9 @@ public: SetDlgItemText(m_hwnd, TXT_TIME, szTime);
}
- INT_PTR DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) override
+ void onSelChanged_Country(CCtrlCombo *)
{
- if (uMsg == WM_COMMAND) {
- switch (LOWORD(wParam)) {
- case EDIT_COUNTRY:
- if (HIWORD(wParam) == CBN_SELCHANGE) {
- LPIDSTRLIST pd = (LPIDSTRLIST)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
- UpDate_CountryIcon(GetDlgItem(m_hwnd, ICO_COUNTRY), pd->nID);
- }
- break;
- }
- }
-
- return PSPBaseDlg::DlgProc(uMsg, wParam, lParam);
+ UpdateCountryIcon(cmbCountry);
}
};
|