]> git.saurik.com Git - wxWidgets.git/commitdiff
implemented page close event for wxAuiNotebook
authorBenjamin Williams <bwilliams@kirix.com>
Mon, 6 Nov 2006 15:05:08 +0000 (15:05 +0000)
committerBenjamin Williams <bwilliams@kirix.com>
Mon, 6 Nov 2006 15:05:08 +0000 (15:05 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/aui/auibook.h
samples/aui/auidemo.cpp
src/aui/auibook.cpp

index cbb43cfcd5c86dd4e201953c964441ad64169053..54048a9955be194020d74723aa5c897a23958317 100644 (file)
@@ -463,6 +463,7 @@ protected:
 #ifndef SWIG
 
 BEGIN_DECLARE_EVENT_TYPES()
 #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)
     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 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) \
 #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
 #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;
 %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 {
 %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 )
     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 )
index a531dc033ff491de40efc3c787e09a8a4377c4b1..dec7f39bdd1823cea26e7f64c9a0e7f29b5d6fb3 100644 (file)
@@ -138,6 +138,7 @@ private:
     void OnRestorePerspective(wxCommandEvent& evt);
     void OnSettings(wxCommandEvent& evt);
     void OnAllowNotebookDnD(wxAuiNotebookEvent& evt);
     void OnRestorePerspective(wxCommandEvent& evt);
     void OnSettings(wxCommandEvent& evt);
     void OnAllowNotebookDnD(wxAuiNotebookEvent& evt);
+    void OnNotebookPageClose(wxAuiNotebookEvent& evt);
     void OnExit(wxCommandEvent& evt);
     void OnAbout(wxCommandEvent& 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)
                    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()
 
 
 END_EVENT_TABLE()
 
 
@@ -1208,6 +1210,20 @@ void MyFrame::OnRestorePerspective(wxCommandEvent& evt)
     m_mgr.LoadPerspective(m_perspectives.Item(evt.GetId() - ID_FirstPerspective));
 }
 
     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
 void MyFrame::OnAllowNotebookDnD(wxAuiNotebookEvent& evt)
 {    
     // for the purpose of this test application, explicitly
index bc7f8fb218abde90295cecb68d420d74d8a10312..82d4a4717c67d8b2ebc989333d48529b2d061260 100644 (file)
@@ -35,6 +35,7 @@
 WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray)
 WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray)
 
 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)
 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);
 
         {
             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();
             if (close_wnd->IsKindOf(CLASSINFO(wxAuiMDIChildFrame)))
             {
                 close_wnd->Close();