From 6b55490abdb56cd66acf9d965981c4bb4b5f2abb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 6 Aug 2001 12:55:04 +0000 Subject: [PATCH] 1. slightly changed how wxControlContainer is used 2. use it now for wxSplitterWindow too 3. don't compile wxIdleEvent in !wxUSE_GUI mode (why was it done?) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11301 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/containr.h | 22 ++++++++------ include/wx/event.h | 4 +-- include/wx/generic/panelg.h | 8 ++--- include/wx/generic/splitter.h | 11 +++++-- samples/splitter/splitter.cpp | 57 +++++++++++++++++------------------ src/common/event.cpp | 2 +- src/generic/panelg.cpp | 4 +-- src/generic/splitter.cpp | 7 +++++ 8 files changed, 63 insertions(+), 52 deletions(-) diff --git a/include/wx/containr.h b/include/wx/containr.h index 11a3dddf98..3e84da9384 100644 --- a/include/wx/containr.h +++ b/include/wx/containr.h @@ -80,13 +80,17 @@ extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child); // declare the methods to be forwarded #define WX_DECLARE_CONTROL_CONTAINER() \ +public: \ void OnNavigationKey(wxNavigationKeyEvent& event); \ void OnFocus(wxFocusEvent& event); \ virtual void OnChildFocus(wxChildFocusEvent& event); \ virtual void SetFocus(); \ virtual void RemoveChild(wxWindowBase *child); \ virtual wxWindow *GetDefaultItem() const; \ - virtual wxWindow *SetDefaultItem(wxWindow *child) \ + virtual wxWindow *SetDefaultItem(wxWindow *child); \ +\ +protected: \ + wxControlContainer m_container // implement the event table entries for wxControlContainer #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \ @@ -95,43 +99,43 @@ extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child); EVT_NAVIGATION_KEY(classname::OnNavigationKey) // implement the methods forwarding to the wxControlContainer -#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, container) \ +#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname) \ wxWindow *classname::SetDefaultItem(wxWindow *child) \ { \ - return container->SetDefaultItem(child); \ + return m_container.SetDefaultItem(child); \ } \ \ wxWindow *classname::GetDefaultItem() const \ { \ - return container->GetDefaultItem(); \ + return m_container.GetDefaultItem(); \ } \ \ void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \ { \ - container->HandleOnNavigationKey(event); \ + m_container.HandleOnNavigationKey(event); \ } \ \ void classname::RemoveChild(wxWindowBase *child) \ { \ - container->HandleOnWindowDestroy(child); \ + m_container.HandleOnWindowDestroy(child); \ \ wxWindow::RemoveChild(child); \ } \ \ void classname::SetFocus() \ { \ - if ( !container->DoSetFocus() ) \ + if ( !m_container.DoSetFocus() ) \ wxWindow::SetFocus(); \ } \ \ void classname::OnChildFocus(wxChildFocusEvent& event) \ { \ - container->SetLastFocus(event.GetWindow()); \ + m_container.SetLastFocus(event.GetWindow()); \ } \ \ void classname::OnFocus(wxFocusEvent& event) \ { \ - container->HandleOnFocus(event); \ + m_container.HandleOnFocus(event); \ } diff --git a/include/wx/event.h b/include/wx/event.h index 16332530aa..d3daa5b71e 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -1512,8 +1512,6 @@ private: DECLARE_DYNAMIC_CLASS(wxContextMenuEvent) }; -#endif // wxUSE_GUI - // Idle event /* wxEVT_IDLE @@ -1536,6 +1534,8 @@ protected: bool m_requestMore; }; +#endif // wxUSE_GUI + /* TODO wxEVT_POWER, wxEVT_MOUSE_CAPTURE_CHANGED, diff --git a/include/wx/generic/panelg.h b/include/wx/generic/panelg.h index a66dd5b7aa..85f91ee81a 100644 --- a/include/wx/generic/panelg.h +++ b/include/wx/generic/panelg.h @@ -23,7 +23,6 @@ #include "wx/window.h" #include "wx/containr.h" -class WXDLLEXPORT wxButton; class WXDLLEXPORT wxControlContainer; WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr; @@ -35,7 +34,7 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr; class WXDLLEXPORT wxPanel : public wxWindow { public: - wxPanel() { Init(); } + wxPanel() : m_container(this) { Init(); } // Old-style constructor (no default values for coordinates to avoid // ambiguity with the new one) @@ -43,6 +42,7 @@ public: int x, int y, int width, int height, long style = wxTAB_TRAVERSAL | wxNO_BORDER, const wxString& name = wxPanelNameStr) + : m_container(this) { Init(); @@ -56,6 +56,7 @@ public: const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL | wxNO_BORDER, const wxString& name = wxPanelNameStr) + : m_container(this) { Init(); @@ -90,9 +91,6 @@ protected: // common part of all ctors void Init(); - // the object which implements the TAB traversal logic - wxControlContainer *m_container; - private: DECLARE_DYNAMIC_CLASS(wxPanel) DECLARE_EVENT_TABLE() diff --git a/include/wx/generic/splitter.h b/include/wx/generic/splitter.h index 09fa572b01..853e75e5a1 100644 --- a/include/wx/generic/splitter.h +++ b/include/wx/generic/splitter.h @@ -37,6 +37,8 @@ enum wxSPLIT_DRAG_LEFT_DOWN }; +class WXDLLEXPORT wxControlContainer; + // --------------------------------------------------------------------------- // wxSplitterWindow maintains one or two panes, with // an optional vertical or horizontal split which @@ -60,7 +62,7 @@ public: // Public API // Default constructor - wxSplitterWindow() + wxSplitterWindow() : m_container(this) { Init(); } @@ -71,12 +73,13 @@ public: const wxSize& size = wxDefaultSize, long style = wxSP_3D, const wxString& name = "splitter") + : m_container(this) { Init(); Create(parent, id, pos, size, style, name); } - ~wxSplitterWindow(); + virtual ~wxSplitterWindow(); bool Create(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, @@ -209,9 +212,9 @@ protected: void SendUnsplitEvent(wxWindow *winRemoved); protected: + // common part of all ctors void Init(); - int m_splitMode; bool m_permitUnsplitAlways; bool m_needUpdating; // when in live mode, set this to TRUE to resize children in idle @@ -237,6 +240,8 @@ protected: wxPen* m_facePen; private: + WX_DECLARE_CONTROL_CONTAINER(); + DECLARE_DYNAMIC_CLASS(wxSplitterWindow) DECLARE_EVENT_TABLE() }; diff --git a/samples/splitter/splitter.cpp b/samples/splitter/splitter.cpp index 4bde92e99a..c7789cc0f8 100644 --- a/samples/splitter/splitter.cpp +++ b/samples/splitter/splitter.cpp @@ -79,13 +79,12 @@ public: private: void UpdatePosition(); - wxMenu* fileMenu; - wxMenuBar* menuBar; - MyCanvas* m_leftCanvas; - MyCanvas* m_rightCanvas; + wxWindow *m_left, + *m_right; + MySplitterWindow* m_splitter; -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE() }; class MyCanvas: public wxScrolledWindow @@ -154,7 +153,7 @@ MyFrame::MyFrame(wxFrame* frame, const wxString& title, CreateStatusBar(2); // Make a menubar - fileMenu = new wxMenu; + wxMenu *fileMenu = new wxMenu; fileMenu->Append(SPLIT_VERTICAL, "Split &Vertically\tCtrl-V", "Split vertically"); fileMenu->Append(SPLIT_HORIZONTAL, "Split &Horizontally\tCtrl-H", "Split horizontally"); fileMenu->Append(SPLIT_UNSPLIT, "&Unsplit\tCtrl-U", "Unsplit"); @@ -163,33 +162,33 @@ MyFrame::MyFrame(wxFrame* frame, const wxString& title, fileMenu->AppendSeparator(); fileMenu->Append(SPLIT_QUIT, "E&xit\tAlt-X", "Exit"); - menuBar = new wxMenuBar; + wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(fileMenu, "&File"); SetMenuBar(menuBar); m_splitter = new MySplitterWindow(this, SPLITTER_WINDOW); -#if 0 - wxSize sz( m_splitter->GetSize() ); - wxLogMessage( "Initial splitter size: %d %d\n", (int)sz.x, (int)sz.y ); -#endif // 0 - - m_leftCanvas = new MyCanvas(m_splitter, CANVAS1, wxPoint(0, 0), wxSize(400, 400), "Test1" ); - m_leftCanvas->SetBackgroundColour(*wxRED); - m_leftCanvas->SetScrollbars(20, 20, 50, 50); - m_leftCanvas->SetCursor(wxCursor(wxCURSOR_MAGNIFIER)); - - m_rightCanvas = new MyCanvas(m_splitter, CANVAS2, wxPoint(0, 0), wxSize(400, 400), "Test2" ); - m_rightCanvas->SetBackgroundColour(*wxCYAN); - m_rightCanvas->SetScrollbars(20, 20, 50, 50); +#if 1 + m_left = new MyCanvas(m_splitter, CANVAS1, wxPoint(0, 0), wxSize(400, 400), "Test1" ); + m_left->SetBackgroundColour(*wxRED); + m_left->SetScrollbars(20, 20, 50, 50); + m_left->SetCursor(wxCursor(wxCURSOR_MAGNIFIER)); + + m_right = new MyCanvas(m_splitter, CANVAS2, wxPoint(0, 0), wxSize(400, 400), "Test2" ); + m_right->SetBackgroundColour(*wxCYAN); + m_right->SetScrollbars(20, 20, 50, 50); +#else // for testing kbd navigation inside the splitter + m_left = new wxTextCtrl(m_splitter, -1, "first text"); + m_right = new wxTextCtrl(m_splitter, -1, "second text"); +#endif // you can also do this to start with a single window #if 0 - m_rightCanvas->Show(FALSE); - m_splitter->Initialize(m_leftCanvas); + m_right->Show(FALSE); + m_splitter->Initialize(m_left); #else - m_splitter->SplitVertically(m_leftCanvas, m_rightCanvas, 100); + m_splitter->SplitVertically(m_left, m_right, 100); #endif SetStatusText("Min pane size = 0", 1); @@ -208,9 +207,9 @@ void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) ) { if ( m_splitter->IsSplit() ) m_splitter->Unsplit(); - m_leftCanvas->Show(TRUE); - m_rightCanvas->Show(TRUE); - m_splitter->SplitHorizontally( m_leftCanvas, m_rightCanvas ); + m_left->Show(TRUE); + m_right->Show(TRUE); + m_splitter->SplitHorizontally( m_left, m_right ); UpdatePosition(); } @@ -218,9 +217,9 @@ void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) ) { if ( m_splitter->IsSplit() ) m_splitter->Unsplit(); - m_leftCanvas->Show(TRUE); - m_rightCanvas->Show(TRUE); - m_splitter->SplitVertically( m_leftCanvas, m_rightCanvas ); + m_left->Show(TRUE); + m_right->Show(TRUE); + m_splitter->SplitVertically( m_left, m_right ); UpdatePosition(); } diff --git a/src/common/event.cpp b/src/common/event.cpp index 3856f91736..e9a76b3fd2 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -52,9 +52,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) #if wxUSE_GUI + IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) diff --git a/src/generic/panelg.cpp b/src/generic/panelg.cpp index f42365f225..c36c49c46d 100644 --- a/src/generic/panelg.cpp +++ b/src/generic/panelg.cpp @@ -57,7 +57,7 @@ END_EVENT_TABLE() // implementation // ============================================================================ -WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, m_container) +WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel) // ---------------------------------------------------------------------------- // wxPanel creation @@ -65,7 +65,6 @@ WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, m_container) void wxPanel::Init() { - m_container = new wxControlContainer(this); } bool wxPanel::Create(wxWindow *parent, wxWindowID id, @@ -79,7 +78,6 @@ bool wxPanel::Create(wxWindow *parent, wxWindowID id, wxPanel::~wxPanel() { - delete m_container; } // ---------------------------------------------------------------------------- diff --git a/src/generic/splitter.cpp b/src/generic/splitter.cpp index 6ff6aa9b62..7b0a84b401 100644 --- a/src/generic/splitter.cpp +++ b/src/generic/splitter.cpp @@ -56,14 +56,21 @@ BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow) EVT_SPLITTER_SASH_POS_CHANGING(-1, wxSplitterWindow::OnSashPosChanged) EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick) EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent) + + WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow) END_EVENT_TABLE() +WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow); + bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { + // allow TABbing from one window to the other + style |= wxTAB_TRAVERSAL; + if (!wxWindow::Create(parent, id, pos, size, style, name)) return FALSE; -- 2.45.2