diff options
author | George Hazan <ghazan@miranda.im> | 2020-06-04 17:03:28 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-06-04 17:03:28 +0300 |
commit | f531ff887729783a7fe7a3e12ad12f658eefc7b0 (patch) | |
tree | 9e1844429448b6527ef7ca87163e44eafce250d8 /src | |
parent | 1c2e5d128a7176ae827dda1e2a8fcc64e772a148 (diff) |
UI classes:
- CDlgBase::m_bSucceeded variable introduced to check whether IDOK was pressed or not;
- unused/useless buttons with id=IDOK or IDCANCEL removed;
- brnOk.OnClick replaced with OnApply calls;
- unused/useless calls of EndDialog/EndModal removed;
- minor code cleaning
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/addcontact.cpp | 48 | ||||
-rw-r--r-- | src/mir_app/src/auth.cpp | 53 | ||||
-rw-r--r-- | src/mir_app/src/db_ini.cpp | 14 | ||||
-rw-r--r-- | src/mir_app/src/menu_options.cpp | 4 | ||||
-rw-r--r-- | src/mir_app/src/profilemanager.cpp | 6 | ||||
-rw-r--r-- | src/mir_core/src/CDlgBase.cpp | 21 |
6 files changed, 66 insertions, 80 deletions
diff --git a/src/mir_app/src/addcontact.cpp b/src/mir_app/src/addcontact.cpp index aa76957656..f9128bdcb6 100644 --- a/src/mir_app/src/addcontact.cpp +++ b/src/mir_app/src/addcontact.cpp @@ -39,7 +39,6 @@ class CAddContactDlg : public CDlgBase {
CCtrlEdit m_authReq, m_myHandle;
CCtrlCheck m_chkAuth, m_chkOpen;
- CCtrlButton m_btnOk;
CCtrlCombo m_group;
protected:
@@ -54,14 +53,12 @@ public: CDlgBase(g_plugin, IDD_ADDCONTACT),
m_chkAuth(this, IDC_AUTH),
m_chkOpen(this, IDC_OPEN_WINDOW),
- m_btnOk(this, IDOK),
m_group(this, IDC_GROUP),
m_authReq(this, IDC_AUTHREQ),
m_myHandle(this, IDC_MYHANDLE)
{
m_chkAuth.OnChange = Callback(this, &CAddContactDlg::OnAuthClicked);
m_chkOpen.OnChange = Callback(this, &CAddContactDlg::OnOpenClicked);
- m_btnOk.OnClick = Callback(this, &CAddContactDlg::OnOk);
}
bool OnInitDialog() override
@@ -105,27 +102,7 @@ public: return true;
}
- void OnDestroy()
- {
- Window_FreeIcon_IcoLib(m_hwnd);
- }
-
- void OnAuthClicked(CCtrlButton*)
- {
- DWORD flags = CallProtoServiceInt(0, m_szProto, PS_GETCAPS, PFLAGNUM_4, 0);
- if (flags & PF4_NOCUSTOMAUTH)
- m_authReq.Enable(false);
- else
- m_authReq.Enable(m_chkAuth.Enabled());
- }
-
- void OnOpenClicked(CCtrlButton*)
- {
- // Remember this choice
- db_set_b(0, "Miranda", "AuthOpenWindow", m_chkOpen.Enabled());
- }
-
- void OnOk(CCtrlButton*)
+ bool OnApply() override
{
MCONTACT hContact = 0;
if (m_hDbEvent)
@@ -136,7 +113,7 @@ public: hContact = m_hContact;
if (hContact == 0) // something went wrong
- return;
+ return false;
ptrW szHandle(m_myHandle.GetText());
if (mir_wstrlen(szHandle))
@@ -158,6 +135,27 @@ public: if (m_chkOpen.GetState())
Clist_ContactDoubleClicked(hContact);
+ return true;
+ }
+
+ void OnDestroy()
+ {
+ Window_FreeIcon_IcoLib(m_hwnd);
+ }
+
+ void OnAuthClicked(CCtrlButton*)
+ {
+ DWORD flags = CallProtoServiceInt(0, m_szProto, PS_GETCAPS, PFLAGNUM_4, 0);
+ if (flags & PF4_NOCUSTOMAUTH)
+ m_authReq.Enable(false);
+ else
+ m_authReq.Enable(m_chkAuth.Enabled());
+ }
+
+ void OnOpenClicked(CCtrlButton*)
+ {
+ // Remember this choice
+ db_set_b(0, "Miranda", "AuthOpenWindow", m_chkOpen.Enabled());
}
};
diff --git a/src/mir_app/src/auth.cpp b/src/mir_app/src/auth.cpp index ce3daa9cbc..10b11f783a 100644 --- a/src/mir_app/src/auth.cpp +++ b/src/mir_app/src/auth.cpp @@ -34,20 +34,16 @@ class CAuthReqDlg : public CDlgBase const char *m_szProto; CCtrlCheck chkAdd; - CCtrlButton btnDetails, btnLater, btnOk, btnCancel; + CCtrlButton btnDetails, btnLater; public: CAuthReqDlg(MEVENT hEvent) : CDlgBase(g_plugin, IDD_AUTHREQ), m_hDbEvent(hEvent), - btnOk(this, IDOK), - btnCancel(this, IDCANCEL), btnLater(this, IDC_DECIDELATER), btnDetails(this, IDC_DETAILS), chkAdd(this, IDC_ADDCHECK) { - btnOk.OnClick = Callback(this, &CAuthReqDlg::onClick_OK); - btnCancel.OnClick = Callback(this, &CAuthReqDlg::onClick_Cancel); btnLater.OnClick = Callback(this, &CAuthReqDlg::onClick_Later); btnDetails.OnClick = Callback(this, &CAuthReqDlg::onClick_Details); } @@ -134,30 +130,30 @@ public: return true; } - void OnDestroy() override - { - Button_FreeIcon_IcoLib(m_hwnd, IDC_ADD); - Button_FreeIcon_IcoLib(m_hwnd, IDC_DETAILS); - DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_BIG, 0)); - DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, 0)); - } - - void onClick_OK(CCtrlButton*) + bool OnApply() override { CallProtoService(m_szProto, PS_AUTHALLOW, m_hDbEvent, 0); if (chkAdd.GetState()) Contact_AddByEvent(m_hDbEvent, m_hwnd); + return true; } - void onClick_Cancel(CCtrlButton*) + void OnDestroy() override { - if (IsWindowEnabled(GetDlgItem(m_hwnd, IDC_DENYREASON))) { - wchar_t tszReason[256]; - GetDlgItemText(m_hwnd, IDC_DENYREASON, tszReason, _countof(tszReason)); - CallProtoService(m_szProto, PS_AUTHDENY, m_hDbEvent, (LPARAM)tszReason); + if (!m_bSucceeded) { + if (IsWindowEnabled(GetDlgItem(m_hwnd, IDC_DENYREASON))) { + wchar_t tszReason[256]; + GetDlgItemText(m_hwnd, IDC_DENYREASON, tszReason, _countof(tszReason)); + CallProtoService(m_szProto, PS_AUTHDENY, m_hDbEvent, (LPARAM)tszReason); + } + else CallProtoService(m_szProto, PS_AUTHDENY, m_hDbEvent, 0); } - else CallProtoService(m_szProto, PS_AUTHDENY, m_hDbEvent, 0); + + Button_FreeIcon_IcoLib(m_hwnd, IDC_ADD); + Button_FreeIcon_IcoLib(m_hwnd, IDC_DETAILS); + DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_BIG, 0)); + DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, 0)); } void onClick_Later(CCtrlButton*) @@ -184,17 +180,15 @@ class CAddedDlg : public CDlgBase MEVENT m_hDbEvent; MCONTACT m_hContact; - CCtrlButton btnDetails, btnAdd, btnOk; + CCtrlButton btnDetails, btnAdd; public: CAddedDlg(MEVENT hEvent) : CDlgBase(g_plugin, IDD_ADDED), m_hDbEvent(hEvent), - btnOk(this, IDOK), btnAdd(this, IDC_ADD), btnDetails(this, IDC_DETAILS) { - btnOk.OnClick = Callback(this, &CAddedDlg::onClick_OK); btnAdd.OnClick = Callback(this, &CAddedDlg::onClick_Add); btnDetails.OnClick = Callback(this, &CAddedDlg::onClick_Details); } @@ -258,7 +252,13 @@ public: ShowWindow(GetDlgItem(m_hwnd, IDC_ADD), FALSE); return true; } - + + bool OnApply() + { + Contact_AddByEvent(m_hDbEvent, m_hwnd); + return true; + } + void OnDestroy() override { Button_FreeIcon_IcoLib(m_hwnd, IDC_ADD); @@ -267,11 +267,6 @@ public: DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, 0)); } - void onClick_OK(CCtrlButton*) - { - Contact_AddByEvent(m_hDbEvent, m_hwnd); - } - void onClick_Add(CCtrlButton*) { Contact_AddByEvent(m_hDbEvent, m_hwnd); diff --git a/src/mir_app/src/db_ini.cpp b/src/mir_app/src/db_ini.cpp index f558f1fb83..f2702e1928 100644 --- a/src/mir_app/src/db_ini.cpp +++ b/src/mir_app/src/db_ini.cpp @@ -123,7 +123,6 @@ class CWarnIniChangeDlg : public CDlgBase CCtrlButton m_yes;
CCtrlButton m_no;
- CCtrlButton m_cancel;
CCtrlCheck m_noWarn;
@@ -153,23 +152,23 @@ protected: return true;
}
- void YesNo_OnClick(CCtrlBase*)
+ bool OnClose() override
{
+ m_warnInfo->cancel = !m_bSucceeded;
m_warnInfo->warnNoMore = m_noWarn.GetState();
- Close();
+ return true;
}
- void Cancel_OnClick(CCtrlBase*)
+ void YesNo_OnClick(CCtrlBase*)
{
- m_warnInfo->cancel = 1;
- m_warnInfo->warnNoMore = m_noWarn.GetState();
+ Close();
}
public:
CWarnIniChangeDlg(warnSettingChangeInfo_t *warnInfo) :
CDlgBase(g_plugin, IDD_WARNINICHANGE),
m_yes(this, IDYES), m_no(this, IDNO),
- m_cancel(this, IDCANCEL), m_noWarn(this, IDC_WARNNOMORE),
+ m_noWarn(this, IDC_WARNNOMORE),
m_iniName(this, IDC_ININAME), m_settingName(this, IDC_SETTINGNAME),
m_newValue(this, IDC_NEWVALUE), m_securityInfo(this, IDC_SECURITYINFO)
{
@@ -177,7 +176,6 @@ public: m_yes.OnClick = Callback(this, &CWarnIniChangeDlg::YesNo_OnClick);
m_no.OnClick = Callback(this, &CWarnIniChangeDlg::YesNo_OnClick);
- m_cancel.OnClick = Callback(this, &CWarnIniChangeDlg::Cancel_OnClick);
}
};
diff --git a/src/mir_app/src/menu_options.cpp b/src/mir_app/src/menu_options.cpp index 61ea371933..fa8330a13e 100644 --- a/src/mir_app/src/menu_options.cpp +++ b/src/mir_app/src/menu_options.cpp @@ -485,9 +485,9 @@ public: void onMenuObjectChanged(void*) { - m_initialized = false; + m_bInitialized = false; RebuildCurrent(); - m_initialized = true; + m_bInitialized = true; } void onMenuItemChanged(void*) diff --git a/src/mir_app/src/profilemanager.cpp b/src/mir_app/src/profilemanager.cpp index 6491bc4578..93c4130c8a 100644 --- a/src/mir_app/src/profilemanager.cpp +++ b/src/mir_app/src/profilemanager.cpp @@ -588,7 +588,6 @@ public: m_servicePlugs(this, IDC_SM_COMBO), m_chkSmEnabled(this, IDC_SM_ENABLED) { - m_btnOk.OnClick = Callback(this, &CProfileManager::onOk); m_chkSmEnabled.OnChange = Callback(this, &CProfileManager::onChanged); m_tab.AddPage(LPGENW("My profiles"), nullptr, new CChooseProfileDlg(m_btnOk, m_pd)); @@ -637,11 +636,6 @@ public: DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_BIG, 0)); } - void onOk(CCtrlButton*) - { - EndDialog(m_hwnd, 1); - } - void onChanged(CCtrlCheck*) { m_servicePlugs.Enable(m_chkSmEnabled.GetState()); diff --git a/src/mir_core/src/CDlgBase.cpp b/src/mir_core/src/CDlgBase.cpp index 4ac2d5751d..f89f68139c 100644 --- a/src/mir_core/src/CDlgBase.cpp +++ b/src/mir_core/src/CDlgBase.cpp @@ -56,7 +56,7 @@ CDlgBase::CDlgBase(CMPluginBase &pPlug, int idDialog) CDlgBase::~CDlgBase() { - m_initialized = false; // prevent double call of destructor + m_bInitialized = false; // prevent double call of destructor if (m_hwnd) DestroyWindow(m_hwnd); } @@ -117,7 +117,7 @@ void CDlgBase::EndModal(INT_PTR nResult) void CDlgBase::NotifyChange(void) { - if (!m_initialized) + if (!m_bInitialized) return; OnChange(); @@ -202,7 +202,7 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: - m_initialized = false; + m_bInitialized = false; TranslateDialog_LP(m_hwnd, &m_pPlugin); ::EnumChildWindows(m_hwnd, &GlobalFieldEnum, LPARAM(this)); @@ -211,7 +211,7 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) if (!OnInitDialog()) return FALSE; - m_initialized = true; + m_bInitialized = true; return TRUE; case WM_CTLCOLOREDIT: @@ -285,10 +285,11 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) m_bExiting = true; // everything ok? good, let's close it - if (OnApply()) + if (OnApply()) { + m_bSucceeded = true; PostMessage(m_hwnd, WM_CLOSE, 0, 0); - else - m_bExiting = false; + } + else m_bExiting = false; } } } @@ -328,7 +329,7 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) return FALSE; case PSM_CHANGED: - if (m_initialized) + if (m_bInitialized) OnChange(); break; @@ -351,7 +352,7 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) if (OnClose()) { m_bExiting = true; if (m_isModal) - EndModal(0); + EndModal(m_bSucceeded ? IDOK : IDCANCEL); else DestroyWindow(m_hwnd); } @@ -368,7 +369,7 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) arDialogs.remove(idx); } m_hwnd = nullptr; - if (m_initialized) { + if (m_bInitialized) { if (m_isModal) m_isModal = false; else // modeless dialogs MUST be allocated with 'new' |