added EVT_AUI_PANECLOSE and updated sample accordingly

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40009 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Benjamin Williams
2006-07-05 16:38:02 +00:00
parent 17d4f7aca8
commit 5875464394
5 changed files with 106 additions and 73 deletions

View File

@@ -15,6 +15,7 @@
#include "wx/aui/framemanager.h" #include "wx/aui/framemanager.h"
#include "wx/aui/dockart.h" #include "wx/aui/dockart.h"
#include "wx/aui/floatpane.h" #include "wx/aui/floatpane.h"
#include "wx/aui/notebook.h"
#endif #endif
// _WX_AUI_H_ // _WX_AUI_H_

View File

@@ -436,7 +436,7 @@ protected:
void OnFloatingPaneMoving(wxWindow* window); void OnFloatingPaneMoving(wxWindow* window);
void OnFloatingPaneMoved(wxWindow* window); void OnFloatingPaneMoved(wxWindow* window);
void OnFloatingPaneActivated(wxWindow* window); void OnFloatingPaneActivated(wxWindow* window);
void OnFloatingPaneClosed(wxWindow* window); void OnFloatingPaneClosed(wxWindow* window, wxCloseEvent& evt);
void OnFloatingPaneResized(wxWindow* window, const wxSize& size); void OnFloatingPaneResized(wxWindow* window, const wxSize& size);
void Render(wxDC* dc); void Render(wxDC* dc);
void Repaint(wxDC* dc = NULL); void Repaint(wxDC* dc = NULL);
@@ -514,12 +514,16 @@ public:
{ {
pane = NULL; pane = NULL;
button = 0; button = 0;
veto_flag = false;
canveto_flag = true;
} }
wxFrameManagerEvent(const wxFrameManagerEvent& c) : wxEvent(c) wxFrameManagerEvent(const wxFrameManagerEvent& c) : wxEvent(c)
{ {
pane = c.pane; pane = c.pane;
button = c.button; button = c.button;
veto_flag = c.veto_flag;
canveto_flag = c.canveto_flag;
} }
wxEvent *Clone() const { return new wxFrameManagerEvent(*this); } wxEvent *Clone() const { return new wxFrameManagerEvent(*this); }
@@ -529,9 +533,16 @@ public:
wxPaneInfo* GetPane() { return pane; } wxPaneInfo* GetPane() { return pane; }
int GetButton() { return button; } int GetButton() { return button; }
void Veto(bool veto = true) { veto_flag = veto; }
bool GetVeto() const { return veto_flag; }
void SetCanVeto(bool can_veto) { canveto_flag = can_veto; }
bool CanVeto() const { return canveto_flag && veto_flag; }
public: public:
wxPaneInfo* pane; wxPaneInfo* pane;
int button; int button;
bool veto_flag;
bool canveto_flag;
}; };
@@ -638,12 +649,9 @@ public:
// wx event machinery // wx event machinery
// right now the only event that works is wxEVT_AUI_PANEBUTTON. A full
// spectrum of events will be implemented in the next incremental version
BEGIN_DECLARE_EVENT_TYPES() BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON, 0) DECLARE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON, 0)
DECLARE_EVENT_TYPE(wxEVT_AUI_PANECLOSE, 0)
END_DECLARE_EVENT_TYPES() END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*wxFrameManagerEventFunction)(wxFrameManagerEvent&); typedef void (wxEvtHandler::*wxFrameManagerEventFunction)(wxFrameManagerEvent&);
@@ -653,6 +661,9 @@ typedef void (wxEvtHandler::*wxFrameManagerEventFunction)(wxFrameManagerEvent&);
#define EVT_AUI_PANEBUTTON(func) \ #define EVT_AUI_PANEBUTTON(func) \
wx__DECLARE_EVT0(wxEVT_AUI_PANEBUTTON, wxFrameManagerEventHandler(func)) wx__DECLARE_EVT0(wxEVT_AUI_PANEBUTTON, wxFrameManagerEventHandler(func))
#define EVT_AUI_PANECLOSE(func) \
wx__DECLARE_EVT0(wxEVT_AUI_PANECLOSE, wxFrameManagerEventHandler(func))
#endif // wxUSE_AUI #endif // wxUSE_AUI
#endif //_WX_FRAMEMANAGER_H_ #endif //_WX_FRAMEMANAGER_H_

View File

@@ -90,7 +90,7 @@ public:
void DoUpdate(); void DoUpdate();
private: private:
wxTextCtrl* CreateTextCtrl(); wxTextCtrl* CreateTextCtrl(const wxString& text = wxEmptyString);
wxGrid* CreateGrid(); wxGrid* CreateGrid();
wxTreeCtrl* CreateTreeCtrl(); wxTreeCtrl* CreateTreeCtrl();
wxSizeReportCtrl* CreateSizeReportCtrl(int width = 80, int height = 80); wxSizeReportCtrl* CreateSizeReportCtrl(int width = 80, int height = 80);
@@ -101,25 +101,27 @@ private:
private: private:
void OnEraseBackground(wxEraseEvent& event); void OnEraseBackground(wxEraseEvent& evt);
void OnSize(wxSizeEvent& event); void OnSize(wxSizeEvent& evt);
void OnCreateTree(wxCommandEvent& event); void OnCreateTree(wxCommandEvent& evt);
void OnCreateGrid(wxCommandEvent& event); void OnCreateGrid(wxCommandEvent& evt);
void OnCreateHTML(wxCommandEvent& event); void OnCreateHTML(wxCommandEvent& evt);
void OnCreateText(wxCommandEvent& event); void OnCreateText(wxCommandEvent& evt);
void OnCreateSizeReport(wxCommandEvent& event); void OnCreateSizeReport(wxCommandEvent& evt);
void OnChangeContentPane(wxCommandEvent& event); void OnChangeContentPane(wxCommandEvent& evt);
void OnCreatePerspective(wxCommandEvent& event); void OnCreatePerspective(wxCommandEvent& evt);
void OnCopyPerspectiveCode(wxCommandEvent& event); void OnCopyPerspectiveCode(wxCommandEvent& evt);
void OnRestorePerspective(wxCommandEvent& event); void OnRestorePerspective(wxCommandEvent& evt);
void OnSettings(wxCommandEvent& event); void OnSettings(wxCommandEvent& evt);
void OnExit(wxCommandEvent& event); void OnExit(wxCommandEvent& evt);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& evt);
void OnGradient(wxCommandEvent& event); void OnGradient(wxCommandEvent& evt);
void OnManagerFlag(wxCommandEvent& event); void OnManagerFlag(wxCommandEvent& evt);
void OnUpdateUI(wxUpdateUIEvent& event); void OnUpdateUI(wxUpdateUIEvent& evt);
void OnPaneClose(wxFrameManagerEvent& evt);
private: private:
@@ -573,6 +575,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_UPDATE_UI(ID_HorizontalGradient, MyFrame::OnUpdateUI) EVT_UPDATE_UI(ID_HorizontalGradient, MyFrame::OnUpdateUI)
EVT_MENU_RANGE(MyFrame::ID_FirstPerspective, MyFrame::ID_FirstPerspective+1000, EVT_MENU_RANGE(MyFrame::ID_FirstPerspective, MyFrame::ID_FirstPerspective+1000,
MyFrame::OnRestorePerspective) MyFrame::OnRestorePerspective)
EVT_AUI_PANECLOSE(MyFrame::OnPaneClose)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -765,8 +768,9 @@ MyFrame::MyFrame(wxWindow* parent,
BestSize(wxSize(200,100)).MinSize(wxSize(200,100)). BestSize(wxSize(200,100)).MinSize(wxSize(200,100)).
Bottom().Layer(1)); Bottom().Layer(1));
m_mgr.AddPane(CreateTextCtrl(), wxPaneInfo(). wxWindow* wnd10 = CreateTextCtrl(wxT("This pane will prompt the user before hiding."));
Name(wxT("test10")).Caption(wxT("Text Pane")). m_mgr.AddPane(wnd10, wxPaneInfo().
Name(wxT("test10")).Caption(wxT("Text Pane with Hide Prompt")).
Bottom().Layer(1).Position(1)); Bottom().Layer(1).Position(1));
m_mgr.AddPane(CreateSizeReportCtrl(), wxPaneInfo(). m_mgr.AddPane(CreateSizeReportCtrl(), wxPaneInfo().
@@ -829,7 +833,6 @@ MyFrame::MyFrame(wxWindow* parent,
LeftDockable(false).RightDockable(false)); LeftDockable(false).RightDockable(false));
// make some default perspectives // make some default perspectives
wxString perspective_all = m_mgr.SavePerspective(); wxString perspective_all = m_mgr.SavePerspective();
@@ -962,6 +965,21 @@ void MyFrame::OnUpdateUI(wxUpdateUIEvent& event)
} }
} }
void MyFrame::OnPaneClose(wxFrameManagerEvent& evt)
{
if (evt.pane->name == wxT("test10"))
{
int res = wxMessageBox(wxT("Are you sure you want to close/hide this pane?"),
wxT("wxAUI"),
wxYES_NO,
this);
if (res != wxYES)
evt.Veto();
}
}
void MyFrame::OnCreatePerspective(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnCreatePerspective(wxCommandEvent& WXUNUSED(event))
{ {
wxTextEntryDialog dlg(this, wxT("Enter a name for the new perspective:"), wxTextEntryDialog dlg(this, wxT("Enter a name for the new perspective:"),
@@ -1070,11 +1088,14 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
wxMessageBox(_("wxAUI Demo\nAn advanced window management library for wxWidgets\n(c) Copyright 2005-2006, Kirix Corporation"), _("About wxAUI Demo"), wxOK, this); wxMessageBox(_("wxAUI Demo\nAn advanced window management library for wxWidgets\n(c) Copyright 2005-2006, Kirix Corporation"), _("About wxAUI Demo"), wxOK, this);
} }
wxTextCtrl* MyFrame::CreateTextCtrl() wxTextCtrl* MyFrame::CreateTextCtrl(const wxString& ctrl_text)
{ {
wxString text;
static int n = 0; static int n = 0;
wxString text;
if (ctrl_text.Length() > 0)
text = ctrl_text;
else
text.Printf(wxT("This is text box %d"), ++n); text.Printf(wxT("This is text box %d"), ++n);
return new wxTextCtrl(this,wxID_ANY, text, return new wxTextCtrl(this,wxID_ANY, text,

View File

@@ -112,28 +112,11 @@ void wxFloatingPane::OnSize(wxSizeEvent& event)
m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize()); m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());
} }
void wxFloatingPane::OnClose(wxCloseEvent& WXUNUSED(event)) void wxFloatingPane::OnClose(wxCloseEvent& evt)
{ {
static wxList s_closing; m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt);
if (!evt.GetVeto())
if (!s_closing.Member(this))
{
s_closing.Append(this);
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( m_pane_window );
m_pane_window->GetEventHandler()->ProcessEvent(cancelEvent);
s_closing.DeleteObject(this);
// we should really return here without doing anything if the close was vetoed
}
// The problem here is that the above can cause the window itself to be destroyed
if (!IsBeingDeleted() && m_pane_window && !m_pane_window->IsBeingDeleted()
&& (m_pane_window->GetParent()==this))
{
m_owner_mgr->OnFloatingPaneClosed(m_pane_window);
Destroy(); Destroy();
}
} }
void wxFloatingPane::OnMoveEvent(wxMoveEvent& event) void wxFloatingPane::OnMoveEvent(wxMoveEvent& event)

View File

@@ -52,6 +52,7 @@ WX_DEFINE_OBJARRAY(wxPaneInfoArray)
wxPaneInfo wxNullPaneInfo; wxPaneInfo wxNullPaneInfo;
wxDockInfo wxNullDockInfo; wxDockInfo wxNullDockInfo;
DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON) DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON)
DEFINE_EVENT_TYPE(wxEVT_AUI_PANECLOSE)
#ifdef __WXMAC__ #ifdef __WXMAC__
// a few defines to avoid nameclashes // a few defines to avoid nameclashes
@@ -2771,20 +2772,38 @@ void wxFrameManager::OnFloatingPaneResized(wxWindow* wnd, const wxSize& size)
pane.floating_size = size; pane.floating_size = size;
} }
void wxFrameManager::OnFloatingPaneClosed(wxWindow* wnd)
void wxFrameManager::OnFloatingPaneClosed(wxWindow* wnd, wxCloseEvent& evt)
{ {
// try to find the pane // try to find the pane
wxPaneInfo& pane = GetPane(wnd); wxPaneInfo& pane = GetPane(wnd);
wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found")); wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
// fire pane close event
wxFrameManagerEvent e(wxEVT_AUI_PANECLOSE);
e.SetPane(&pane);
e.SetCanVeto(evt.CanVeto());
ProcessMgrEvent(e);
if (e.GetVeto())
{
evt.Veto();
return;
}
else
{
// reparent the pane window back to us and // reparent the pane window back to us and
// prepare the frame window for destruction // prepare the frame window for destruction
pane.window->Show(false); pane.window->Show(false);
pane.window->Reparent(m_frame); pane.window->Reparent(m_frame);
pane.frame = NULL; pane.frame = NULL;
pane.Hide(); pane.Hide();
}
} }
void wxFrameManager::OnFloatingPaneActivated(wxWindow* wnd) void wxFrameManager::OnFloatingPaneActivated(wxWindow* wnd)
{ {
if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE) if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
@@ -3480,28 +3499,26 @@ void wxFrameManager::OnChildFocus(wxChildFocusEvent& event)
// OnPaneButton() is an event handler that is called // OnPaneButton() is an event handler that is called
// when a pane button has been pressed. // when a pane button has been pressed.
void wxFrameManager::OnPaneButton(wxFrameManagerEvent& event) void wxFrameManager::OnPaneButton(wxFrameManagerEvent& evt)
{ {
wxPaneInfo& pane = *(event.pane); wxASSERT_MSG(evt.pane, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
if (event.button == wxPaneInfo::buttonClose) wxPaneInfo& pane = *(evt.pane);
{
if (pane.IsOk())
{
wxWindow * pane_window = pane.window;
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( pane_window );
pane_window->GetEventHandler()->ProcessEvent(cancelEvent);
// The problem here is that the above can cause the window itself to be destroyed if (evt.button == wxPaneInfo::buttonClose)
if (!pane_window->IsBeingDeleted() && pane.IsOk()) {
// fire button-click event
wxFrameManagerEvent e(wxEVT_AUI_PANECLOSE);
e.SetPane(evt.pane);
ProcessMgrEvent(e);
if (!e.GetVeto())
{ {
pane.Hide(); pane.Hide();
Update(); Update();
} }
} }
} else if (evt.button == wxPaneInfo::buttonPin)
else if (event.button == wxPaneInfo::buttonPin)
{ {
if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) && if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
pane.IsFloatable()) pane.IsFloatable())