summaryrefslogtreecommitdiff
path: root/src/mir_core
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-07-11 17:09:17 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-07-11 17:09:17 +0300
commitb2c91edc9646daa331de71d589e4fec6bdef4945 (patch)
tree847a77d0686d26e25b126313fbaa8262c81f8d1a /src/mir_core
parentae081843e9663b3cb36b17309fbce1d2967315f1 (diff)
GUI change:
- methods OnInitDialog, OnApply & OnClose of CDlgBase now return true if successful. return of false prevents a dialog from being loaded or left respectively; - massive code cleaning considering the 'virtual' attribute of overridden methods; - also fixes #1476 (Don't close "Create new account" window if user not set account name)
Diffstat (limited to 'src/mir_core')
-rw-r--r--src/mir_core/src/CCtrlBase.cpp3
-rw-r--r--src/mir_core/src/CCtrlCheck.cpp3
-rw-r--r--src/mir_core/src/CCtrlCombo.cpp3
-rw-r--r--src/mir_core/src/CCtrlEdit.cpp3
-rw-r--r--src/mir_core/src/CCtrlPages.cpp12
-rw-r--r--src/mir_core/src/CCtrlSpin.cpp3
-rw-r--r--src/mir_core/src/CDlgBase.cpp78
-rw-r--r--src/mir_core/src/mir_core.def20
-rw-r--r--src/mir_core/src/mir_core64.def20
9 files changed, 91 insertions, 54 deletions
diff --git a/src/mir_core/src/CCtrlBase.cpp b/src/mir_core/src/CCtrlBase.cpp
index 9901ce0c68..87f59e77c8 100644
--- a/src/mir_core/src/CCtrlBase.cpp
+++ b/src/mir_core/src/CCtrlBase.cpp
@@ -67,9 +67,10 @@ void CCtrlBase::OnDestroy()
m_hwnd = nullptr;
}
-void CCtrlBase::OnApply()
+bool CCtrlBase::OnApply()
{
m_bChanged = false;
+ return true;
}
void CCtrlBase::OnReset()
diff --git a/src/mir_core/src/CCtrlCheck.cpp b/src/mir_core/src/CCtrlCheck.cpp
index 5f220c6eba..3fe7fe2b15 100644
--- a/src/mir_core/src/CCtrlCheck.cpp
+++ b/src/mir_core/src/CCtrlCheck.cpp
@@ -35,12 +35,13 @@ BOOL CCtrlCheck::OnCommand(HWND, WORD, WORD)
return TRUE;
}
-void CCtrlCheck::OnApply()
+bool CCtrlCheck::OnApply()
{
CSuper::OnApply();
if (m_dbLink != nullptr)
SaveInt(GetState());
+ return true;
}
void CCtrlCheck::OnReset()
diff --git a/src/mir_core/src/CCtrlCombo.cpp b/src/mir_core/src/CCtrlCombo.cpp
index d8877ac82b..6854e841c3 100644
--- a/src/mir_core/src/CCtrlCombo.cpp
+++ b/src/mir_core/src/CCtrlCombo.cpp
@@ -51,7 +51,7 @@ void CCtrlCombo::OnInit()
OnReset();
}
-void CCtrlCombo::OnApply()
+bool CCtrlCombo::OnApply()
{
CSuper::OnApply();
@@ -64,6 +64,7 @@ void CCtrlCombo::OnApply()
else if (GetDataType() != DBVT_DELETED) {
SaveInt(GetInt());
}
+ return true;
}
void CCtrlCombo::OnReset()
diff --git a/src/mir_core/src/CCtrlEdit.cpp b/src/mir_core/src/CCtrlEdit.cpp
index 7b821c2de2..1d08d665ac 100644
--- a/src/mir_core/src/CCtrlEdit.cpp
+++ b/src/mir_core/src/CCtrlEdit.cpp
@@ -36,7 +36,7 @@ BOOL CCtrlEdit::OnCommand(HWND, WORD, WORD idCode)
return TRUE;
}
-void CCtrlEdit::OnApply()
+bool CCtrlEdit::OnApply()
{
CSuper::OnApply();
@@ -49,6 +49,7 @@ void CCtrlEdit::OnApply()
else if (GetDataType() != DBVT_DELETED) {
SaveInt(GetInt());
}
+ return true;
}
void CCtrlEdit::OnReset()
diff --git a/src/mir_core/src/CCtrlPages.cpp b/src/mir_core/src/CCtrlPages.cpp
index d56231b796..39efe9e997 100644
--- a/src/mir_core/src/CCtrlPages.cpp
+++ b/src/mir_core/src/CCtrlPages.cpp
@@ -353,7 +353,7 @@ void CCtrlPages::OnReset()
}
}
-void CCtrlPages::OnApply()
+bool CCtrlPages::OnApply()
{
PSHNOTIFY pshn;
pshn.hdr.idFrom = 0;
@@ -362,10 +362,8 @@ void CCtrlPages::OnApply()
if (m_pActivePage != nullptr) {
pshn.hdr.code = PSN_KILLACTIVE;
pshn.hdr.hwndFrom = m_pActivePage->GetHwnd();
- if (SendMessage(pshn.hdr.hwndFrom, WM_NOTIFY, 0, (LPARAM)&pshn)) {
- m_parentWnd->Fail();
- return;
- }
+ if (SendMessage(pshn.hdr.hwndFrom, WM_NOTIFY, 0, (LPARAM)&pshn))
+ return false;
}
pshn.hdr.code = PSN_APPLY;
@@ -383,12 +381,12 @@ void CCtrlPages::OnApply()
m_pActivePage->Hide();
m_pActivePage = p->m_pDlg;
m_pActivePage->Show();
- m_parentWnd->Fail();
- return;
+ return false;
}
}
CSuper::OnApply();
+ return true;
}
void CCtrlPages::OnDestroy()
diff --git a/src/mir_core/src/CCtrlSpin.cpp b/src/mir_core/src/CCtrlSpin.cpp
index f0af3c9609..a348b5c5e4 100644
--- a/src/mir_core/src/CCtrlSpin.cpp
+++ b/src/mir_core/src/CCtrlSpin.cpp
@@ -38,12 +38,13 @@ BOOL CCtrlSpin::OnNotify(int, NMHDR *pnmh)
return FALSE;
}
-void CCtrlSpin::OnApply()
+bool CCtrlSpin::OnApply()
{
CSuper::OnApply();
if (m_dbLink != nullptr)
SaveInt(GetPosition());
+ return true;
}
void CCtrlSpin::OnReset()
diff --git a/src/mir_core/src/CDlgBase.cpp b/src/mir_core/src/CDlgBase.cpp
index a92012e996..6bf0b703b4 100644
--- a/src/mir_core/src/CDlgBase.cpp
+++ b/src/mir_core/src/CDlgBase.cpp
@@ -51,10 +51,7 @@ CDlgBase::CDlgBase(CMPluginBase &pPlug, int idDialog)
m_pPlugin(pPlug)
{
m_idDialog = idDialog;
- m_hwnd = m_hwndParent = nullptr;
- m_isModal = m_initialized = m_bExiting = false;
m_autoClose = CLOSE_ON_OK | CLOSE_ON_CANCEL;
- m_forceResizable = false;
}
CDlgBase::~CDlgBase()
@@ -65,6 +62,36 @@ CDlgBase::~CDlgBase()
}
/////////////////////////////////////////////////////////////////////////////////////////
+// events
+
+bool CDlgBase::OnInitDialog()
+{
+ return true;
+}
+
+bool CDlgBase::OnClose()
+{
+ return true;
+}
+
+bool CDlgBase::OnApply()
+{
+ return true;
+}
+
+void CDlgBase::OnChange()
+{}
+
+void CDlgBase::OnDestroy()
+{}
+
+void CDlgBase::OnReset()
+{}
+
+void CDlgBase::OnTimer(CTimer*)
+{}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// methods
void CDlgBase::Close()
@@ -181,7 +208,8 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
::EnumChildWindows(m_hwnd, &GlobalFieldEnum, LPARAM(this));
NotifyControls(&CCtrlBase::OnInit);
- OnInitDialog();
+ if (!OnInitDialog())
+ return FALSE;
m_initialized = true;
return TRUE;
@@ -244,16 +272,15 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
// close dialog automatically if 'OK' button is pressed
if (idCtrl == IDOK && (m_autoClose & CLOSE_ON_OK)) {
// validate dialog data first
- m_bExiting = true;
- m_lresult = TRUE;
- NotifyControls(&CCtrlBase::OnApply);
- OnApply();
-
- // everything ok? good, let's close it
- if (m_lresult == TRUE)
- PostMessage(m_hwnd, WM_CLOSE, 0, 0);
- else
- m_bExiting = false;
+ if (VerifyControls(&CCtrlBase::OnApply)) {
+ m_bExiting = true;
+
+ // everything ok? good, let's close it
+ if (OnApply())
+ PostMessage(m_hwnd, WM_CLOSE, 0, 0);
+ else
+ m_bExiting = false;
+ }
}
}
}
@@ -269,10 +296,10 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
if (LPPSHNOTIFY(lParam)->lParam != 3) // IDC_APPLY
m_bExiting = true;
- m_lresult = true;
- NotifyControls(&CCtrlBase::OnApply);
- if (m_lresult)
- OnApply();
+ if (!VerifyControls(&CCtrlBase::OnApply))
+ m_bExiting = false;
+ else if (!OnApply())
+ m_bExiting = false;
break;
case PSN_RESET:
@@ -312,10 +339,8 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
return FALSE;
case WM_CLOSE:
- m_bExiting = true;
- m_lresult = FALSE;
- OnClose();
- if (!m_lresult) {
+ if (OnClose()) {
+ m_bExiting = true;
if (m_isModal)
EndModal(0);
else
@@ -384,6 +409,15 @@ void CDlgBase::NotifyControls(void (CCtrlBase::*fn)())
(it->*fn)();
}
+bool CDlgBase::VerifyControls(bool (CCtrlBase::*fn)())
+{
+ for (auto &it : m_controls)
+ if (!(it->*fn)())
+ return false;
+
+ return true;
+}
+
CCtrlBase* CDlgBase::FindControl(int idCtrl)
{
CCtrlBase search(nullptr, idCtrl);
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def
index 678e5453e5..3c0afec46b 100644
--- a/src/mir_core/src/mir_core.def
+++ b/src/mir_core/src/mir_core.def
@@ -738,13 +738,13 @@ mir_wstrcmpi @280
?MapIndexToID@CCtrlListView@@QAEII@Z @909 NONAME
?NotifyChange@CCtrlBase@@QAEXXZ @910 NONAME
?NotifyControls@CDlgBase@@AAEXP8CCtrlBase@@AEXXZ@Z @911 NONAME
-?OnApply@CCtrlBase@@UAEXXZ @912 NONAME
-?OnApply@CCtrlCheck@@UAEXXZ @913 NONAME
-?OnApply@CCtrlCombo@@UAEXXZ @914 NONAME
-?OnApply@CCtrlEdit@@UAEXXZ @915 NONAME
-?OnApply@CDlgBase@@MAEXXZ @916 NONAME
+?OnApply@CCtrlBase@@UAE_NXZ @912 NONAME
+?OnApply@CCtrlCheck@@UAE_NXZ @913 NONAME
+?OnApply@CCtrlCombo@@UAE_NXZ @914 NONAME
+?OnApply@CCtrlEdit@@UAE_NXZ @915 NONAME
+?OnApply@CDlgBase@@MAE_NXZ @916 NONAME
?OnChange@CDlgBase@@MAEXXZ @917 NONAME
-?OnClose@CDlgBase@@MAEXXZ @918 NONAME
+?OnClose@CDlgBase@@MAE_NXZ @918 NONAME
?OnCommand@CCtrlBase@@UAEHPAUHWND__@@GG@Z @919 NONAME
?OnCommand@CCtrlButton@@UAEHPAUHWND__@@GG@Z @920 NONAME
?OnCommand@CCtrlCheck@@UAEHPAUHWND__@@GG@Z @921 NONAME
@@ -762,7 +762,7 @@ mir_wstrcmpi @280
?OnInit@CCtrlData@@UAEXXZ @934 NONAME
?OnInit@CCtrlMButton@@UAEXXZ @936 NONAME
?OnInit@CCtrlPages@@MAEXXZ @937 NONAME
-?OnInitDialog@CDlgBase@@MAEXXZ @938 NONAME
+?OnInitDialog@CDlgBase@@MAE_NXZ @938 NONAME
?OnMeasureItem@CCtrlBase@@UAEHPAUtagMEASUREITEMSTRUCT@@@Z @939 NONAME
?OnNotify@CCtrlBase@@UAEHHPAUtagNMHDR@@@Z @940 NONAME
?OnNotify@CCtrlClc@@MAEHHPAUtagNMHDR@@@Z @941 NONAME
@@ -907,8 +907,7 @@ mir_wstrcmpi @280
?UnselectAll@CCtrlTreeView@@QAEXXZ @1093 NONAME
?MoveItemAbove@CCtrlTreeView@@AAEPAU_TREEITEM@@PAU2@00@Z @1094 NONAME
?GetCurrPage@CCtrlPages@@AAEPAUTPageInfo@1@XZ @1095 NONAME
-?Fail@CDlgBase@@QAEXXZ @1096 NONAME
-?OnApply@CCtrlPages@@MAEXXZ @1097 NONAME
+?OnApply@CCtrlPages@@MAE_NXZ @1097 NONAME
?OnReset@CCtrlPages@@MAEXXZ @1098 NONAME
Bitmap_GetFilter @1099
Bitmap_Load @1100
@@ -1055,7 +1054,7 @@ IsTerminalDisconnected @1245
?OnDestroy@CCtrlTreeView@@MAEXXZ @1249 NONAME
?GetUrl@CCtrlHyperlink@@QAEPBDXZ @1250 NONAME
?IsChecked@CCtrlCheck@@QAE_NXZ @1251 NONAME
-?OnApply@CCtrlSpin@@UAEXXZ @1252 NONAME
+?OnApply@CCtrlSpin@@UAE_NXZ @1252 NONAME
?OnReset@CCtrlSpin@@UAEXXZ @1253 NONAME
?SetUrl@CCtrlHyperlink@@QAEXPBD@Z @1254 NONAME
?Default_OnClick@CCtrlHyperlink@@IAEXPAV1@@Z @1255 NONAME
@@ -1068,3 +1067,4 @@ CallObjectEventHook @1259
?CreateLink@CDlgBase@@IAEXAAVCCtrlData@@PBDEK@Z @1262 NONAME
?CreateLink@CDlgBase@@IAEXAAVCCtrlData@@PBDPA_W@Z @1263 NONAME
?CheckRowCount@CCtrlPages@@AAEXXZ @1264 NONAME
+?VerifyControls@CDlgBase@@AAE_NP8CCtrlBase@@AE_NXZ@Z @1265 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def
index f84202ff91..05064e9e3b 100644
--- a/src/mir_core/src/mir_core64.def
+++ b/src/mir_core/src/mir_core64.def
@@ -738,13 +738,13 @@ mir_wstrcmpi @280
?MapIndexToID@CCtrlListView@@QEAAII@Z @909 NONAME
?NotifyChange@CCtrlBase@@QEAAXXZ @910 NONAME
?NotifyControls@CDlgBase@@AEAAXP8CCtrlBase@@EAAXXZ@Z @911 NONAME
-?OnApply@CCtrlBase@@UEAAXXZ @912 NONAME
-?OnApply@CCtrlCheck@@UEAAXXZ @913 NONAME
-?OnApply@CCtrlCombo@@UEAAXXZ @914 NONAME
-?OnApply@CCtrlEdit@@UEAAXXZ @915 NONAME
-?OnApply@CDlgBase@@MEAAXXZ @916 NONAME
+?OnApply@CCtrlBase@@UEAA_NXZ @912 NONAME
+?OnApply@CCtrlCheck@@UEAA_NXZ @913 NONAME
+?OnApply@CCtrlCombo@@UEAA_NXZ @914 NONAME
+?OnApply@CCtrlEdit@@UEAA_NXZ @915 NONAME
+?OnApply@CDlgBase@@MEAA_NXZ @916 NONAME
?OnChange@CDlgBase@@MEAAXXZ @917 NONAME
-?OnClose@CDlgBase@@MEAAXXZ @918 NONAME
+?OnClose@CDlgBase@@MEAA_NXZ @918 NONAME
?OnCommand@CCtrlBase@@UEAAHPEAUHWND__@@GG@Z @919 NONAME
?OnCommand@CCtrlButton@@UEAAHPEAUHWND__@@GG@Z @920 NONAME
?OnCommand@CCtrlCheck@@UEAAHPEAUHWND__@@GG@Z @921 NONAME
@@ -762,7 +762,7 @@ mir_wstrcmpi @280
?OnInit@CCtrlData@@UEAAXXZ @934 NONAME
?OnInit@CCtrlMButton@@UEAAXXZ @936 NONAME
?OnInit@CCtrlPages@@MEAAXXZ @937 NONAME
-?OnInitDialog@CDlgBase@@MEAAXXZ @938 NONAME
+?OnInitDialog@CDlgBase@@MEAA_NXZ @938 NONAME
?OnMeasureItem@CCtrlBase@@UEAAHPEAUtagMEASUREITEMSTRUCT@@@Z @939 NONAME
?OnNotify@CCtrlBase@@UEAAHHPEAUtagNMHDR@@@Z @940 NONAME
?OnNotify@CCtrlClc@@MEAAHHPEAUtagNMHDR@@@Z @941 NONAME
@@ -907,8 +907,7 @@ mir_wstrcmpi @280
?UnselectAll@CCtrlTreeView@@QEAAXXZ @1093 NONAME
?MoveItemAbove@CCtrlTreeView@@AEAAPEAU_TREEITEM@@PEAU2@00@Z @1094 NONAME
?GetCurrPage@CCtrlPages@@AEAAPEAUTPageInfo@1@XZ @1095 NONAME
-?Fail@CDlgBase@@QEAAXXZ @1096 NONAME
-?OnApply@CCtrlPages@@MEAAXXZ @1097 NONAME
+?OnApply@CCtrlPages@@MEAA_NXZ @1097 NONAME
?OnReset@CCtrlPages@@MEAAXXZ @1098 NONAME
Bitmap_GetFilter @1099
Bitmap_Load @1100
@@ -1056,7 +1055,7 @@ IsTerminalDisconnected @1245
?Default_OnClick@CCtrlHyperlink@@IEAAXPEAV1@@Z @1250 NONAME
?GetUrl@CCtrlHyperlink@@QEAAPEBDXZ @1251 NONAME
?IsChecked@CCtrlCheck@@QEAA_NXZ @1252 NONAME
-?OnApply@CCtrlSpin@@UEAAXXZ @1253 NONAME
+?OnApply@CCtrlSpin@@UEAA_NXZ @1253 NONAME
?OnReset@CCtrlSpin@@UEAAXXZ @1254 NONAME
?SetUrl@CCtrlHyperlink@@QEAAXPEBD@Z @1255 NONAME
??0CCtrlLabel@@QEAA@PEAVCDlgBase@@H@Z @1256 NONAME
@@ -1068,3 +1067,4 @@ CallObjectEventHook @1259
?CreateLink@CDlgBase@@IEAAXAEAVCCtrlData@@PEBDEK@Z @1262 NONAME
?CreateLink@CDlgBase@@IEAAXAEAVCCtrlData@@PEBDPEA_W@Z @1263 NONAME
?CheckRowCount@CCtrlPages@@AEAAXXZ @1264 NONAME
+?VerifyControls@CDlgBase@@AEAA_NP8CCtrlBase@@EAA_NXZ@Z @1265 NONAME