From 3fd8c9885425ab527572a74d16badc913dfba53c Mon Sep 17 00:00:00 2001 From: Benjamin Williams Date: Mon, 6 Nov 2006 15:05:08 +0000 Subject: [PATCH] implemented page close event for wxAuiNotebook git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/aui/auibook.h | 7 ++++++- samples/aui/auidemo.cpp | 16 ++++++++++++++++ src/aui/auibook.cpp | 12 ++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/wx/aui/auibook.h b/include/wx/aui/auibook.h index cbb43cfcd5..54048a9955 100644 --- a/include/wx/aui/auibook.h +++ b/include/wx/aui/auibook.h @@ -463,6 +463,7 @@ protected: #ifndef SWIG BEGIN_DECLARE_EVENT_TYPES() + DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, 0) DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 0) DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 0) DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 0) @@ -476,7 +477,9 @@ typedef void (wxEvtHandler::*wxAuiNotebookEventFunction)(wxAuiNotebookEvent&); #define wxAuiNotebookEventHandler(func) \ (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiNotebookEventFunction, &func) - + +#define EVT_AUINOTEBOOK_PAGE_CLOSE(winid, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, winid, wxAuiNotebookEventHandler(fn)) #define EVT_AUINOTEBOOK_PAGE_CHANGED(winid, fn) \ wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, winid, wxAuiNotebookEventHandler(fn)) #define EVT_AUINOTEBOOK_PAGE_CHANGING(winid, fn) \ @@ -495,6 +498,7 @@ typedef void (wxEvtHandler::*wxAuiNotebookEventFunction)(wxAuiNotebookEvent&); #else // wxpython/swig event work +%constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE; %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED; %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING; %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_BUTTON; @@ -504,6 +508,7 @@ typedef void (wxEvtHandler::*wxAuiNotebookEventFunction)(wxAuiNotebookEvent&); %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND; %pythoncode { + EVT_AUINOTEBOOK_PAGE_CLOSE = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, 1 ) EVT_AUINOTEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 1 ) EVT_AUINOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 1 ) EVT_AUINOTEBOOK_BUTTON = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 1 ) diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp index a531dc033f..dec7f39bdd 100644 --- a/samples/aui/auidemo.cpp +++ b/samples/aui/auidemo.cpp @@ -138,6 +138,7 @@ private: void OnRestorePerspective(wxCommandEvent& evt); void OnSettings(wxCommandEvent& evt); void OnAllowNotebookDnD(wxAuiNotebookEvent& evt); + void OnNotebookPageClose(wxAuiNotebookEvent& evt); void OnExit(wxCommandEvent& evt); void OnAbout(wxCommandEvent& evt); @@ -619,6 +620,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) MyFrame::OnRestorePerspective) EVT_AUI_PANECLOSE(MyFrame::OnPaneClose) EVT_AUINOTEBOOK_ALLOW_DND(wxID_ANY, MyFrame::OnAllowNotebookDnD) + EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, MyFrame::OnNotebookPageClose) END_EVENT_TABLE() @@ -1208,6 +1210,20 @@ void MyFrame::OnRestorePerspective(wxCommandEvent& evt) m_mgr.LoadPerspective(m_perspectives.Item(evt.GetId() - ID_FirstPerspective)); } +void MyFrame::OnNotebookPageClose(wxAuiNotebookEvent& evt) +{ + wxAuiNotebook* ctrl = (wxAuiNotebook*)evt.GetEventObject(); + if (ctrl->GetPage(evt.GetSelection())->IsKindOf(CLASSINFO(wxHtmlWindow))) + { + int res = wxMessageBox(wxT("Are you sure you want to close/hide this notebook page?"), + wxT("wxAUI"), + wxYES_NO, + this); + if (res != wxYES) + evt.Veto(); + } +} + void MyFrame::OnAllowNotebookDnD(wxAuiNotebookEvent& evt) { // for the purpose of this test application, explicitly diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index bc7f8fb218..82d4a4717c 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -35,6 +35,7 @@ WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray) WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE) DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING) DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_BUTTON) @@ -2533,6 +2534,17 @@ void wxAuiNotebook::OnTabButton(wxCommandEvent& command_evt) { wxWindow* close_wnd = tabs->GetWindowFromIdx(selection); + + // ask owner if it's ok to close the tab + wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, m_windowId); + e.SetSelection(m_tabs.GetIdxFromWindow(close_wnd)); + e.SetOldSelection(evt.GetSelection()); + e.SetEventObject(this); + GetEventHandler()->ProcessEvent(e); + if (!e.IsAllowed()) + return; + + if (close_wnd->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) { close_wnd->Close(); -- 2.45.2