moved all wxDialog event handlers to wxDialogBase to avoid code duplication

(sixplication?) among ports; as a side effect added public wxDialog methods to
wxDialogBase as well and moved EndDialog() (previously implemented by wxMSW,
wxMotif, wxMac and wxCocoa but not the other ports) to wxDialogBase too


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40687 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-08-19 22:56:11 +00:00
parent 0be2741893
commit 2158f4d798
16 changed files with 101 additions and 553 deletions

View File

@@ -25,7 +25,6 @@ WXDLLEXPORT_DATA(extern const wxChar) wxDialogNameStr[];
class WXDLLEXPORT wxDialog : public wxDialogBase, protected wxCocoaNSPanel class WXDLLEXPORT wxDialog : public wxDialogBase, protected wxCocoaNSPanel
{ {
DECLARE_DYNAMIC_CLASS(wxDialog) DECLARE_DYNAMIC_CLASS(wxDialog)
DECLARE_EVENT_TABLE()
WX_DECLARE_COCOA_OWNER(NSPanel,NSWindow,NSWindow) WX_DECLARE_COCOA_OWNER(NSPanel,NSWindow,NSWindow)
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// initialization // initialization
@@ -93,20 +92,6 @@ public:
// may be called to terminate the dialog with the given return code // may be called to terminate the dialog with the given return code
virtual void EndModal(int retCode); virtual void EndModal(int retCode);
// ------------------------------------------------------------------------
// Event handlers
// ------------------------------------------------------------------------
protected:
void OnCloseWindow(wxCloseEvent& event);
// Standard buttons
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_ #endif // _WX_COCOA_DIALOG_H_

View File

@@ -41,7 +41,11 @@ public:
wxDialogBase() { Init(); } wxDialogBase() { Init(); }
virtual ~wxDialogBase() { } virtual ~wxDialogBase() { }
void Init(); // public wxDialog API, to be implemented by the derived classes
virtual int ShowModal() = 0;
virtual void EndModal(int retCode) = 0;
virtual bool IsModal() const = 0;
// Modal dialogs have a return code - usually the id of the last // Modal dialogs have a return code - usually the id of the last
// pressed button // pressed button
@@ -84,6 +88,10 @@ protected:
// could do something different if needed // could do something different if needed
virtual bool IsEscapeKey(const wxKeyEvent& event); virtual bool IsEscapeKey(const wxKeyEvent& event);
// end either modal or modeless dialog, for the modal dialog rc is used as
// the dialog return code
void EndDialog(int rc);
// The return code from modal dialog // The return code from modal dialog
int m_returnCode; int m_returnCode;
@@ -95,9 +103,24 @@ protected:
int m_escapeId; int m_escapeId;
private: private:
// common part of all ctors
void Init();
// handle Esc key presses // handle Esc key presses
void OnCharHook(wxKeyEvent& event); void OnCharHook(wxKeyEvent& event);
// handle closing the dialog window
void OnCloseWindow(wxCloseEvent& event);
// handle the standard buttons
void OnOK(wxCommandEvent& event);
void OnApply(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
// update the background colour
void OnSysColourChanged(wxSysColourChangedEvent& event);
DECLARE_NO_COPY_CLASS(wxDialogBase) DECLARE_NO_COPY_CLASS(wxDialogBase)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
WX_DECLARE_CONTROL_CONTAINER(); WX_DECLARE_CONTROL_CONTAINER();

View File

@@ -47,12 +47,6 @@ public:
const wxString &name = wxDialogNameStr ); const wxString &name = wxDialogNameStr );
~wxDialog() {} ~wxDialog() {}
void OnApply( wxCommandEvent &event );
void OnCancel( wxCommandEvent &event );
void OnOK( wxCommandEvent &event );
void OnPaint( wxPaintEvent& event );
void OnCloseWindow( wxCloseEvent& event );
virtual bool Show( bool show = TRUE ); virtual bool Show( bool show = TRUE );
virtual int ShowModal(); virtual int ShowModal();
virtual void EndModal( int retCode ); virtual void EndModal( int retCode );
@@ -64,12 +58,10 @@ public:
bool m_modalShowing; bool m_modalShowing;
protected: private:
// common part of all ctors // common part of all ctors
void Init(); void Init();
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxDialog) DECLARE_DYNAMIC_CLASS(wxDialog)
}; };

View File

@@ -78,24 +78,13 @@ public:
// implementation // implementation
// -------------- // --------------
// event handlers
void OnCloseWindow(wxCloseEvent& event);
// Standard buttons
void OnOK(wxCommandEvent& event);
void OnApply(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
// Responds to colour changes
void OnSysColourChanged(wxSysColourChangedEvent& event);
// show modal dialog and enter modal loop // show modal dialog and enter modal loop
void DoShowModal(); void DoShowModal();
private: private:
void Init(); void Init();
bool m_isModalStyle; bool m_isModalStyle;
DECLARE_EVENT_TABLE()
}; };
#endif #endif

View File

@@ -57,18 +57,8 @@ public:
virtual void ChangeFont(bool keepOriginalSize = true); virtual void ChangeFont(bool keepOriginalSize = true);
virtual void ChangeBackgroundColour(); virtual void ChangeBackgroundColour();
virtual void ChangeForegroundColour(); virtual void ChangeForegroundColour();
inline WXWidget GetTopWidget() const { return m_mainWidget; } WXWidget GetTopWidget() const { return m_mainWidget; }
inline WXWidget GetClientWidget() const { return m_mainWidget; } WXWidget GetClientWidget() const { return m_mainWidget; }
// Standard buttons
void OnOK(wxCommandEvent& event);
void OnApply(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
// Responds to colour changes
void OnSysColourChanged(wxSysColourChangedEvent& event);
void OnCloseWindow(wxCloseEvent& event);
private: private:
virtual bool XmDoCreateTLW(wxWindow* parent, virtual bool XmDoCreateTLW(wxWindow* parent,

View File

@@ -85,17 +85,6 @@ public:
virtual void Raise(); virtual void Raise();
// event handlers
void OnCloseWindow(wxCloseEvent& event);
// Standard buttons
void OnOK(wxCommandEvent& event);
void OnApply(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
// Responds to colour changes
void OnSysColourChanged(wxSysColourChangedEvent& event);
#ifdef __POCKETPC__ #ifdef __POCKETPC__
// Responds to the OK button in a PocketPC titlebar. This // Responds to the OK button in a PocketPC titlebar. This
// can be overridden, or you can change the id used for // can be overridden, or you can change the id used for
@@ -132,9 +121,6 @@ protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
// end either modal or modeless dialog
void EndDialog(int rc);
private: private:
wxWindow* m_oldFocus; wxWindow* m_oldFocus;
bool m_endModalCalled; // allow for closing within InitDialog bool m_endModalCalled; // allow for closing within InitDialog
@@ -147,7 +133,6 @@ private:
wxDialogModalData *m_modalData; wxDialogModalData *m_modalData;
DECLARE_DYNAMIC_CLASS(wxDialog) DECLARE_DYNAMIC_CLASS(wxDialog)
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxDialog) DECLARE_NO_COPY_CLASS(wxDialog)
}; };

View File

@@ -65,23 +65,6 @@ public:
// override some base class virtuals // override some base class virtuals
virtual bool Show(bool show = true); virtual bool Show(bool show = true);
//
// Event handlers
//
void OnCloseWindow(wxCloseEvent& rEvent);
//
// Standard buttons
//
void OnOK(wxCommandEvent& rEvent);
void OnApply(wxCommandEvent& rEvent);
void OnCancel(wxCommandEvent& rEvent);
//
// Responds to colour changes
//
void OnSysColourChanged(wxSysColourChangedEvent& rEvent);
// //
// Callbacks // Callbacks
// //
@@ -125,9 +108,6 @@ protected:
// //
void Init(void); void Init(void);
// end either modal or modeless dialog
void EndDialog(int rc);
private: private:
wxWindow* m_pOldFocus; wxWindow* m_pOldFocus;
bool m_endModalCalled; // allow for closing within InitDialog bool m_endModalCalled; // allow for closing within InitDialog

View File

@@ -63,15 +63,6 @@ public:
virtual void Raise(); virtual void Raise();
// event handlers
void OnCharHook(wxKeyEvent& event);
void OnCloseWindow(wxCloseEvent& event);
// Standard buttons
void OnOK(wxCommandEvent& event);
void OnApply(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
protected: protected:
// find the window to use as parent for this dialog if none has been // find the window to use as parent for this dialog if none has been
// specified explicitly by the user // specified explicitly by the user

View File

@@ -33,13 +33,6 @@ static wxWindowList wxModalDialogs;
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
BEGIN_EVENT_TABLE(wxDialog, wxDialogBase)
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
EVT_CLOSE(wxDialog::OnCloseWindow)
END_EVENT_TABLE()
WX_IMPLEMENT_COCOA_OWNER(wxDialog,NSPanel,NSWindow,NSWindow) WX_IMPLEMENT_COCOA_OWNER(wxDialog,NSPanel,NSWindow,NSWindow)
void wxDialog::Init() void wxDialog::Init()
@@ -177,68 +170,3 @@ void wxDialog::EndModal(int retCode)
Show(false); 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,
// which may close the dialog.
// Check for looping if the Cancel event handler calls Close().
// Note that if a cancel button and handler aren't present in the dialog,
// nothing will happen when you close the dialog via the window manager, or
// via Close().
// We wouldn't want to destroy the dialog by default, since the dialog may have been
// created on the stack.
// However, this does mean that calling dialog->Close() won't delete the dialog
// unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
// sure to destroy the dialog.
// The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
// ALWAYS VETO THIS EVENT!!!!
event.Veto();
static wxList closing;
if ( closing.Member(this) )
{
wxLogDebug(wxT("WARNING: Attempting to recursively call Close for dialog"));
return;
}
closing.Append(this);
wxLogTrace(wxTRACE_COCOA,wxT("Sending Cancel Event"));
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
closing.DeleteObject(this);
}
// Standard buttons
void wxDialog::OnOK(wxCommandEvent& event)
{
if ( Validate() && TransferDataFromWindow() )
{
EndDialog(wxID_OK);
}
}
void wxDialog::OnApply(wxCommandEvent& event)
{
if (Validate())
TransferDataFromWindow();
// TODO probably need to disable the Apply button until things change again
}
void wxDialog::OnCancel(wxCommandEvent& event)
{
wxLogTrace(wxTRACE_COCOA,wxT("Cancelled!"));
EndDialog(wxID_CANCEL);
}

View File

@@ -99,7 +99,14 @@ private:
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow) BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
EVT_BUTTON(wxID_OK, wxDialogBase::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialogBase::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialogBase::OnCancel)
EVT_CLOSE(wxDialogBase::OnCloseWindow)
EVT_CHAR_HOOK(wxDialogBase::OnCharHook) EVT_CHAR_HOOK(wxDialogBase::OnCharHook)
WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase) WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -437,6 +444,14 @@ bool wxDialogBase::EmulateButtonClickIfPresent(int id)
return true; return true;
} }
void wxDialogBase::EndDialog(int rc)
{
if ( IsModal() )
EndModal(rc);
else
Hide();
}
bool wxDialogBase::IsEscapeKey(const wxKeyEvent& event) bool wxDialogBase::IsEscapeKey(const wxKeyEvent& event)
{ {
// for most platforms, Esc key is used to close the dialogs // for most platforms, Esc key is used to close the dialogs
@@ -473,3 +488,59 @@ void wxDialogBase::OnCharHook(wxKeyEvent& event)
event.Skip(); event.Skip();
} }
void wxDialogBase::OnOK(wxCommandEvent& WXUNUSED(event))
{
if ( Validate() && TransferDataFromWindow() )
{
EndDialog(wxID_OK);
}
}
void wxDialogBase::OnApply(wxCommandEvent& WXUNUSED(event))
{
if ( Validate() )
TransferDataFromWindow();
// TODO probably need to disable the Apply button until things change again
}
void wxDialogBase::OnCancel(wxCommandEvent& WXUNUSED(event))
{
EndDialog(wxID_CANCEL);
}
void wxDialogBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
// We'll send a Cancel message by default, which may close the dialog.
// Check for looping if the Cancel event handler calls Close().
// Note that if a cancel button and handler aren't present in the dialog,
// nothing will happen when you close the dialog via the window manager, or
// via Close(). We wouldn't want to destroy the dialog by default, since
// the dialog may have been created on the stack. However, this does mean
// that calling dialog->Close() won't delete the dialog unless the handler
// for wxID_CANCEL does so. So use Destroy() if you want to be sure to
// destroy the dialog. The default OnCancel (above) simply ends a modal
// dialog, and hides a modeless dialog.
// VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
// lists here? don't dare to change it now, but should be done later!
static wxList closing;
if ( closing.Member(this) )
return;
closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
closing.DeleteObject(this);
}
void wxDialogBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
Refresh();
}

View File

@@ -36,13 +36,6 @@ extern int g_openDialogs;
// wxDialog // wxDialog
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDialog,wxDialogBase)
EVT_BUTTON (wxID_OK, wxDialog::OnOK)
EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
EVT_CLOSE (wxDialog::OnCloseWindow)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow) IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
void wxDialog::Init() void wxDialog::Init()
@@ -76,75 +69,6 @@ bool wxDialog::Create( wxWindow *parent,
return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
} }
void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
{
if (Validate())
TransferDataFromWindow();
}
void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
{
if (IsModal())
{
EndModal(wxID_CANCEL);
}
else
{
SetReturnCode(wxID_CANCEL);
Show(false);
}
}
void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) )
{
if (Validate() && TransferDataFromWindow())
{
if (IsModal())
{
EndModal(wxID_OK);
}
else
{
SetReturnCode(wxID_OK);
Show(false);
}
}
}
void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
// yes
}
void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
// We'll send a Cancel message by default,
// which may close the dialog.
// Check for looping if the Cancel event handler calls Close().
// Note that if a cancel button and handler aren't present in the dialog,
// nothing will happen when you close the dialog via the window manager, or
// via Close().
// We wouldn't want to destroy the dialog by default, since the dialog may have been
// created on the stack.
// However, this does mean that calling dialog->Close() won't delete the dialog
// unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
// sure to destroy the dialog.
// The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
static wxList s_closing;
if (s_closing.Member(this))
return; // no loops
s_closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent);
s_closing.DeleteObject(this);
}
bool wxDialog::Show( bool show ) bool wxDialog::Show( bool show )
{ {
if (!show && IsModal()) if (!show && IsModal())

View File

@@ -204,58 +204,3 @@ void wxDialog::EndModal(int retCode)
SetModal(false); SetModal(false);
} }
// Standard buttons
void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
if ( Validate() && TransferDataFromWindow() )
EndModal(wxID_OK);
}
void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
{
if (Validate())
TransferDataFromWindow();
// TODO probably need to disable the Apply button until things change again
}
void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
{
EndModal(wxID_CANCEL);
}
void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
// We'll send a Cancel message by default,
// which may close the dialog.
// Check for looping if the Cancel event handler calls Close().
// Note that if a cancel button and handler aren't present in the dialog,
// nothing will happen when you close the dialog via the window manager, or
// via Close().
// We wouldn't want to destroy the dialog by default, since the dialog may have been
// created on the stack.
// However, this does mean that calling dialog->Close() won't delete the dialog
// unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
// sure to destroy the dialog.
// The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
static wxList closing;
if ( closing.Member(this) )
return;
closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
closing.DeleteObject(this);
}
void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
Refresh();
}

View File

@@ -71,15 +71,6 @@ extern wxList wxModelessWindows; // Frames and modeless dialogs
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
BEGIN_EVENT_TABLE(wxDialog, wxTopLevelWindow)
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
EVT_CLOSE(wxDialog::OnCloseWindow)
END_EVENT_TABLE()
wxDialog::wxDialog() wxDialog::wxDialog()
{ {
m_modalShowing = false; m_modalShowing = false;
@@ -347,69 +338,6 @@ void wxDialog::EndModal(int retCode)
SetModal(false); SetModal(false);
} }
// Standard buttons
void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
if ( Validate() && TransferDataFromWindow() )
{
if ( IsModal() )
EndModal(wxID_OK);
else
{
SetReturnCode(wxID_OK);
this->Show(false);
}
}
}
void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
{
if (Validate())
TransferDataFromWindow();
// TODO probably need to disable the Apply button until things change again
}
void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
{
if ( IsModal() )
EndModal(wxID_CANCEL);
else
{
SetReturnCode(wxID_CANCEL);
this->Show(false);
}
}
void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
// We'll send a Cancel message by default,
// which may close the dialog.
// Check for looping if the Cancel event handler calls Close().
// Note that if a cancel button and handler aren't present in the dialog,
// nothing will happen when you close the dialog via the window manager, or
// via Close().
// We wouldn't want to destroy the dialog by default, since the dialog may have been
// created on the stack.
// However, this does mean that calling dialog->Close() won't delete the dialog
// unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
// sure to destroy the dialog.
// The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
static wxList closing;
if ( closing.Member(this) )
return;
closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
closing.DeleteObject(this);
}
// Destroy the window (delayed, if a managed window) // Destroy the window (delayed, if a managed window)
bool wxDialog::Destroy() bool wxDialog::Destroy()
{ {
@@ -418,12 +346,6 @@ bool wxDialog::Destroy()
return true; return true;
} }
void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
Refresh();
}
void wxDialog::ChangeFont(bool keepOriginalSize) void wxDialog::ChangeFont(bool keepOriginalSize)
{ {
wxWindow::ChangeFont(keepOriginalSize); wxWindow::ChangeFont(keepOriginalSize);

View File

@@ -109,16 +109,6 @@ wxCONSTRUCTOR_6( wxDialog , wxWindow* , Parent , wxWindowID , Id , wxString , Ti
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
#endif #endif
BEGIN_EVENT_TABLE(wxDialog, wxDialogBase)
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
EVT_CLOSE(wxDialog::OnCloseWindow)
END_EVENT_TABLE()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDialogModalData // wxDialogModalData
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -377,76 +367,10 @@ void wxDialog::EndModal(int retCode)
Hide(); Hide();
} }
void wxDialog::EndDialog(int rc)
{
if ( IsModal() )
EndModal(rc);
else
Hide();
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxWin event handlers // wxWin event handlers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Standard buttons
void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
if ( Validate() && TransferDataFromWindow() )
{
EndDialog(wxID_OK);
}
}
void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
{
if ( Validate() )
TransferDataFromWindow();
// TODO probably need to disable the Apply button until things change again
}
void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
{
EndDialog(wxID_CANCEL);
}
void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
// We'll send a Cancel message by default, which may close the dialog.
// Check for looping if the Cancel event handler calls Close().
// Note that if a cancel button and handler aren't present in the dialog,
// nothing will happen when you close the dialog via the window manager, or
// via Close(). We wouldn't want to destroy the dialog by default, since
// the dialog may have been created on the stack. However, this does mean
// that calling dialog->Close() won't delete the dialog unless the handler
// for wxID_CANCEL does so. So use Destroy() if you want to be sure to
// destroy the dialog. The default OnCancel (above) simply ends a modal
// dialog, and hides a modeless dialog.
// VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
// lists here? don't dare to change it now, but should be done later!
static wxList closing;
if ( closing.Member(this) )
return;
closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
closing.DeleteObject(this);
}
void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
Refresh();
}
#ifdef __POCKETPC__ #ifdef __POCKETPC__
// Responds to the OK button in a PocketPC titlebar. This // Responds to the OK button in a PocketPC titlebar. This
// can be overridden, or you can change the id used for // can be overridden, or you can change the id used for

View File

@@ -328,79 +328,6 @@ void wxDialog::EndModal(
Hide(); Hide();
} // end of wxDialog::EndModal } // end of wxDialog::EndModal
void wxDialog::EndDialog(int rc)
{
if ( IsModal() )
EndModal(rc);
else
Hide();
}
// ----------------------------------------------------------------------------
// wxWin event handlers
// ----------------------------------------------------------------------------
void wxDialog::OnApply( wxCommandEvent& WXUNUSED(rEvent) )
{
if (Validate())
TransferDataFromWindow();
} // end of wxDialog::OnApply
// Standard buttons
void wxDialog::OnOK( wxCommandEvent& WXUNUSED(rEvent) )
{
if ( Validate() && TransferDataFromWindow() )
{
EndDialog(wxID_OK);
}
} // end of wxDialog::OnOK
void wxDialog::OnCancel( wxCommandEvent& WXUNUSED(rEvent) )
{
EndDialog(wxID_CANCEL);
} // end of wxDialog::OnCancel
void wxDialog::OnCloseWindow( wxCloseEvent& WXUNUSED(rEvent) )
{
//
// We'll send a Cancel message by default, which may close the dialog.
// Check for looping if the Cancel event handler calls Close().
//
// Note that if a cancel button and handler aren't present in the dialog,
// nothing will happen when you close the dialog via the window manager, or
// via Close().
// We wouldn't want to destroy the dialog by default, since the dialog may have been
// created on the stack.
// However, this does mean that calling dialog->Close() won't delete the dialog
// unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
// sure to destroy the dialog.
// The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
//
//
// Ugh??? This is not good but until I figure out a global list it'll have to do
//
static wxList closing;
if ( closing.Member(this) )
return;
closing.Append(this);
wxCommandEvent vCancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
vCancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(vCancelEvent); // This may close the dialog
closing.DeleteObject(this);
} // end of wxDialog::OnCloseWindow
void wxDialog::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(rEvent) )
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
Refresh();
} // end of wxDialog::OnSysColourChanged
MRESULT wxDialog::OS2WindowProc( WXUINT uMessage, WXWPARAM wParam, WXLPARAM lParam ) MRESULT wxDialog::OS2WindowProc( WXUINT uMessage, WXWPARAM wParam, WXLPARAM lParam )
{ {
MRESULT rc = 0; MRESULT rc = 0;

View File

@@ -100,14 +100,6 @@ wxCONSTRUCTOR_6( wxDialog , wxWindow* , Parent , wxWindowID , Id , wxString , Ti
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
#endif #endif
BEGIN_EVENT_TABLE(wxDialog, wxDialogBase)
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
EVT_CLOSE(wxDialog::OnCloseWindow)
END_EVENT_TABLE()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDialogModalData // wxDialogModalData
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -190,23 +182,3 @@ void wxDialog::EndModal(int retCode)
{ {
} }
// ----------------------------------------------------------------------------
// wxWin event handlers
// ----------------------------------------------------------------------------
// Standard buttons
void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
}
void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
{
}
void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
{
}
void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
}