From acb96ac277797a4b40d05264f088ee0693382f4b Mon Sep 17 00:00:00 2001 From: David Elliott Date: Mon, 26 Sep 2005 15:42:42 +0000 Subject: [PATCH] Add EndDialog helper which calls EndModal with the given return code if the dialog is modal, and Show(false) if the dialog is not modal. This allows the default handlers for OK and Cancel to function without assertions. This code is copied more or less directly from src/msw/dialog.cpp. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/dialog.h | 4 ++++ src/cocoa/dialog.mm | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/wx/cocoa/dialog.h b/include/wx/cocoa/dialog.h index b4e0145e91..a9e793a22d 100644 --- a/include/wx/cocoa/dialog.h +++ b/include/wx/cocoa/dialog.h @@ -102,6 +102,10 @@ protected: void OnOK(wxCommandEvent& event); void OnApply(wxCommandEvent& event); void OnCancel(wxCommandEvent& event); + + // end either modal or modeless dialog + void EndDialog(int rc); + }; #endif // _WX_COCOA_DIALOG_H_ diff --git a/src/cocoa/dialog.mm b/src/cocoa/dialog.mm index e15c2937aa..d18483cc86 100644 --- a/src/cocoa/dialog.mm +++ b/src/cocoa/dialog.mm @@ -175,6 +175,14 @@ void wxDialog::EndModal(int retCode) Show(false); } +void wxDialog::EndDialog(int retCode) +{ + if(IsModal()) + EndModal(retCode); + else + Show(false); +} + void wxDialog::OnCloseWindow(wxCloseEvent& event) { // We'll send a Cancel message by default, @@ -216,7 +224,7 @@ void wxDialog::OnOK(wxCommandEvent& event) { if ( Validate() && TransferDataFromWindow() ) { - EndModal(wxID_OK); + EndDialog(wxID_OK); } } @@ -230,6 +238,6 @@ void wxDialog::OnApply(wxCommandEvent& event) void wxDialog::OnCancel(wxCommandEvent& event) { wxLogTrace(wxTRACE_COCOA,wxT("Cancelled!")); - EndModal(wxID_CANCEL); + EndDialog(wxID_CANCEL); } -- 2.47.2