Session management changes for wxMSW.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@820 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1998-10-12 19:45:24 +00:00
parent 03f38c58fd
commit 387a3b02e0
15 changed files with 317 additions and 73 deletions

View File

@@ -41,6 +41,7 @@ IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame)
BEGIN_EVENT_TABLE(wxDocMDIParentFrame, wxMDIParentFrame)
EVT_MENU(wxID_EXIT, wxDocMDIParentFrame::OnExit)
EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocMDIParentFrame::OnMRUFile)
EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow)
END_EVENT_TABLE()
wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
@@ -72,11 +73,14 @@ bool wxDocMDIParentFrame::ProcessEvent(wxEvent& event)
return TRUE;
}
// Define the behaviour for the frame closing
// - must delete all frames except for the main one.
bool wxDocMDIParentFrame::OnClose(void)
void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
{
return m_docManager->Clear(FALSE);
if (m_docManager->Clear(!event.CanVeto()))
{
this->Destroy();
}
else
event.Veto();
}
@@ -88,6 +92,7 @@ IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow)
END_EVENT_TABLE()
wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
@@ -128,24 +133,32 @@ void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
m_childView->Activate(event.GetActive());
}
bool wxDocMDIChildFrame::OnClose(void)
void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
{
// Close view but don't delete the frame while doing so!
// ...since it will be deleted by wxWindows if we return TRUE.
if (m_childView)
{
bool ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
bool ans = FALSE;
if (!event.CanVeto())
ans = TRUE; // Must delete.
else
ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
if (ans)
{
m_childView->Activate(FALSE);
delete m_childView;
m_childView = (wxView *) NULL;
m_childDocument = (wxDocument *) NULL;
this->Destroy();
}
return ans;
else
event.Veto();
}
else return TRUE;
else
event.Veto();
}
#endif

View File

@@ -1313,6 +1313,7 @@ void wxDocManager::ActivateView(wxView *view, bool activate, bool WXUNUSED(delet
BEGIN_EVENT_TABLE(wxDocChildFrame, wxFrame)
EVT_ACTIVATE(wxDocChildFrame::OnActivate)
EVT_CLOSE(wxDocChildFrame::OnCloseWindow)
END_EVENT_TABLE()
wxDocChildFrame::wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *frame, wxWindowID id, const wxString& title,
@@ -1355,24 +1356,30 @@ void wxDocChildFrame::OnActivate(wxActivateEvent& event)
m_childView->Activate(event.GetActive());
}
bool wxDocChildFrame::OnClose(void)
void wxDocChildFrame::OnCloseWindow(wxCloseEvent& event)
{
// Close view but don't delete the frame while doing so!
// ...since it will be deleted by wxWindows if we return TRUE.
if (m_childView)
{
bool ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
bool ans = FALSE;
if (!event.CanVeto())
ans = TRUE; // Must delete.
else
ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
if (ans)
{
m_childView->Activate(FALSE);
delete m_childView;
m_childView = (wxView *) NULL;
m_childDocument = (wxDocument *) NULL;
this->Destroy();
}
return ans;
else
event.Veto();
}
else return TRUE;
else
event.Veto();
}
/*
@@ -1382,6 +1389,7 @@ bool wxDocChildFrame::OnClose(void)
BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame)
EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit)
EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocParentFrame::OnMRUFile)
EVT_CLOSE(wxDocParentFrame::OnCloseWindow)
END_EVENT_TABLE()
wxDocParentFrame::wxDocParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
@@ -1415,9 +1423,14 @@ bool wxDocParentFrame::ProcessEvent(wxEvent& event)
// Define the behaviour for the frame closing
// - must delete all frames except for the main one.
bool wxDocParentFrame::OnClose(void)
void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event)
{
return m_docManager->Clear(FALSE);
if (m_docManager->Clear(!event.CanVeto()))
{
this->Destroy();
}
else
event.Veto();
}
#if wxUSE_PRINTING_ARCHITECTURE

View File

@@ -97,6 +97,8 @@ LRESULT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM);
BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
EVT_IDLE(wxApp::OnIdle)
EVT_END_SESSION(wxApp::OnEndSession)
EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
END_EVENT_TABLE()
#endif
@@ -892,6 +894,23 @@ void wxApp::DeletePendingObjects()
}
}
void wxApp::OnEndSession(wxCloseEvent& event)
{
if (GetTopWindow())
GetTopWindow()->Close(TRUE);
}
// Default behaviour: close the application with prompts. The
// user can veto the close, and therefore the end session.
void wxApp::OnQueryEndSession(wxCloseEvent& event)
{
if (GetTopWindow())
{
if (!GetTopWindow()->Close(!event.CanVeto()))
event.Veto(TRUE);
}
}
wxLog* wxApp::CreateLogTarget()
{
return new wxLogGui;

View File

@@ -521,8 +521,8 @@ void wxDialog::OnOK(wxCommandEvent& event)
EndModal(wxID_OK);
else
{
SetReturnCode(wxID_OK);
this->Show(FALSE);
SetReturnCode(wxID_OK);
this->Show(FALSE);
}
}
}
@@ -547,7 +547,7 @@ void wxDialog::OnCancel(wxCommandEvent& event)
bool wxDialog::OnClose(void)
{
// Behaviour changed in 2.0: we'll send a Cancel message by default,
// Behaviour changed in 2.0: we'll send a Cancel message by default,
// which may close the dialog.
// Check for looping if the Cancel event handler calls Close()
@@ -558,13 +558,13 @@ bool wxDialog::OnClose(void)
closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent);
closing.DeleteObject(this);
return FALSE;
return FALSE;
}
void wxDialog::OnCloseWindow(wxCloseEvent& event)
@@ -574,6 +574,8 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event)
{
this->Destroy();
}
else
event.Veto(TRUE);
}
// Destroy the window (delayed, if a managed window)

View File

@@ -869,6 +869,8 @@ void wxFrame::OnCloseWindow(wxCloseEvent& event)
{
this->Destroy();
}
else
event.Veto(TRUE);
}
bool wxFrame::OnClose(void)

View File

@@ -1415,7 +1415,16 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
case WM_QUERYENDSESSION:
{
// Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
return MSWOnClose();
// return MSWOnClose();
return MSWOnQueryEndSession(lParam);
break;
}
case WM_ENDSESSION:
{
// Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
MSWOnEndSession((wParam != 0), lParam);
return 0L;
break;
}
case WM_CLOSE:
@@ -1583,6 +1592,38 @@ bool wxWindow::MSWOnClose(void)
return FALSE;
}
// Return TRUE to end session, FALSE to veto end session.
bool wxWindow::MSWOnQueryEndSession(long logOff)
{
wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1);
event.SetEventObject(wxTheApp);
event.SetCanVeto(TRUE);
event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) );
if ((this == wxTheApp->GetTopWindow()) && // Only send once
wxTheApp->ProcessEvent(event) && event.GetVeto())
{
return FALSE; // Veto!
}
else
{
return TRUE; // Don't veto
}
}
bool wxWindow::MSWOnEndSession(bool endSession, long logOff)
{
wxCloseEvent event(wxEVT_END_SESSION, -1);
event.SetEventObject(wxTheApp);
event.SetCanVeto(FALSE);
event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) );
if (endSession && // No need to send if the session isn't ending
(this == wxTheApp->GetTopWindow()) && // Only send once
wxTheApp->ProcessEvent(event))
{
}
return TRUE;
}
bool wxWindow::MSWOnDestroy(void)
{
#if WXDEBUG > 1
@@ -4102,32 +4143,12 @@ void wxWindow::GetPositionConstraint(int *x, int *y) const
bool wxWindow::Close(bool force)
{
// Let's generalise it to work the same for any window.
/*
if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
{
this->Destroy();
return TRUE;
}
*/
wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
event.SetEventObject(this);
event.SetForce(force);
event.SetCanVeto(!force);
return GetEventHandler()->ProcessEvent(event);
/*
if ( !force && event.GetVeto() )
return FALSE;
Show(FALSE);
if (!wxPendingDelete.Member(this))
wxPendingDelete.Append(this);
return TRUE;
*/
return (GetEventHandler()->ProcessEvent(event) && !event.GetVeto());
}
wxObject* wxWindow::GetChild(int number) const