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
This commit is contained in:
Vadim Zeitlin
2001-08-06 12:55:04 +00:00
parent a86253375b
commit 6b55490abd
8 changed files with 62 additions and 51 deletions

View File

@@ -80,13 +80,17 @@ extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
// declare the methods to be forwarded // declare the methods to be forwarded
#define WX_DECLARE_CONTROL_CONTAINER() \ #define WX_DECLARE_CONTROL_CONTAINER() \
public: \
void OnNavigationKey(wxNavigationKeyEvent& event); \ void OnNavigationKey(wxNavigationKeyEvent& event); \
void OnFocus(wxFocusEvent& event); \ void OnFocus(wxFocusEvent& event); \
virtual void OnChildFocus(wxChildFocusEvent& event); \ virtual void OnChildFocus(wxChildFocusEvent& event); \
virtual void SetFocus(); \ virtual void SetFocus(); \
virtual void RemoveChild(wxWindowBase *child); \ virtual void RemoveChild(wxWindowBase *child); \
virtual wxWindow *GetDefaultItem() const; \ 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 // implement the event table entries for wxControlContainer
#define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \ #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
@@ -95,43 +99,43 @@ extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
EVT_NAVIGATION_KEY(classname::OnNavigationKey) EVT_NAVIGATION_KEY(classname::OnNavigationKey)
// implement the methods forwarding to the wxControlContainer // 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) \ wxWindow *classname::SetDefaultItem(wxWindow *child) \
{ \ { \
return container->SetDefaultItem(child); \ return m_container.SetDefaultItem(child); \
} \ } \
\ \
wxWindow *classname::GetDefaultItem() const \ wxWindow *classname::GetDefaultItem() const \
{ \ { \
return container->GetDefaultItem(); \ return m_container.GetDefaultItem(); \
} \ } \
\ \
void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \ void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
{ \ { \
container->HandleOnNavigationKey(event); \ m_container.HandleOnNavigationKey(event); \
} \ } \
\ \
void classname::RemoveChild(wxWindowBase *child) \ void classname::RemoveChild(wxWindowBase *child) \
{ \ { \
container->HandleOnWindowDestroy(child); \ m_container.HandleOnWindowDestroy(child); \
\ \
wxWindow::RemoveChild(child); \ wxWindow::RemoveChild(child); \
} \ } \
\ \
void classname::SetFocus() \ void classname::SetFocus() \
{ \ { \
if ( !container->DoSetFocus() ) \ if ( !m_container.DoSetFocus() ) \
wxWindow::SetFocus(); \ wxWindow::SetFocus(); \
} \ } \
\ \
void classname::OnChildFocus(wxChildFocusEvent& event) \ void classname::OnChildFocus(wxChildFocusEvent& event) \
{ \ { \
container->SetLastFocus(event.GetWindow()); \ m_container.SetLastFocus(event.GetWindow()); \
} \ } \
\ \
void classname::OnFocus(wxFocusEvent& event) \ void classname::OnFocus(wxFocusEvent& event) \
{ \ { \
container->HandleOnFocus(event); \ m_container.HandleOnFocus(event); \
} }

View File

@@ -1512,8 +1512,6 @@ private:
DECLARE_DYNAMIC_CLASS(wxContextMenuEvent) DECLARE_DYNAMIC_CLASS(wxContextMenuEvent)
}; };
#endif // wxUSE_GUI
// Idle event // Idle event
/* /*
wxEVT_IDLE wxEVT_IDLE
@@ -1536,6 +1534,8 @@ protected:
bool m_requestMore; bool m_requestMore;
}; };
#endif // wxUSE_GUI
/* TODO /* TODO
wxEVT_POWER, wxEVT_POWER,
wxEVT_MOUSE_CAPTURE_CHANGED, wxEVT_MOUSE_CAPTURE_CHANGED,

View File

@@ -23,7 +23,6 @@
#include "wx/window.h" #include "wx/window.h"
#include "wx/containr.h" #include "wx/containr.h"
class WXDLLEXPORT wxButton;
class WXDLLEXPORT wxControlContainer; class WXDLLEXPORT wxControlContainer;
WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr; WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
@@ -35,7 +34,7 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
class WXDLLEXPORT wxPanel : public wxWindow class WXDLLEXPORT wxPanel : public wxWindow
{ {
public: public:
wxPanel() { Init(); } wxPanel() : m_container(this) { Init(); }
// Old-style constructor (no default values for coordinates to avoid // Old-style constructor (no default values for coordinates to avoid
// ambiguity with the new one) // ambiguity with the new one)
@@ -43,6 +42,7 @@ public:
int x, int y, int width, int height, int x, int y, int width, int height,
long style = wxTAB_TRAVERSAL | wxNO_BORDER, long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = wxPanelNameStr) const wxString& name = wxPanelNameStr)
: m_container(this)
{ {
Init(); Init();
@@ -56,6 +56,7 @@ public:
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL | wxNO_BORDER, long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = wxPanelNameStr) const wxString& name = wxPanelNameStr)
: m_container(this)
{ {
Init(); Init();
@@ -90,9 +91,6 @@ protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
// the object which implements the TAB traversal logic
wxControlContainer *m_container;
private: private:
DECLARE_DYNAMIC_CLASS(wxPanel) DECLARE_DYNAMIC_CLASS(wxPanel)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@@ -37,6 +37,8 @@ enum
wxSPLIT_DRAG_LEFT_DOWN wxSPLIT_DRAG_LEFT_DOWN
}; };
class WXDLLEXPORT wxControlContainer;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// wxSplitterWindow maintains one or two panes, with // wxSplitterWindow maintains one or two panes, with
// an optional vertical or horizontal split which // an optional vertical or horizontal split which
@@ -60,7 +62,7 @@ public:
// Public API // Public API
// Default constructor // Default constructor
wxSplitterWindow() wxSplitterWindow() : m_container(this)
{ {
Init(); Init();
} }
@@ -71,12 +73,13 @@ public:
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = wxSP_3D, long style = wxSP_3D,
const wxString& name = "splitter") const wxString& name = "splitter")
: m_container(this)
{ {
Init(); Init();
Create(parent, id, pos, size, style, name); Create(parent, id, pos, size, style, name);
} }
~wxSplitterWindow(); virtual ~wxSplitterWindow();
bool Create(wxWindow *parent, wxWindowID id = -1, bool Create(wxWindow *parent, wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
@@ -209,9 +212,9 @@ protected:
void SendUnsplitEvent(wxWindow *winRemoved); void SendUnsplitEvent(wxWindow *winRemoved);
protected: protected:
// common part of all ctors
void Init(); void Init();
int m_splitMode; int m_splitMode;
bool m_permitUnsplitAlways; bool m_permitUnsplitAlways;
bool m_needUpdating; // when in live mode, set this to TRUE to resize children in idle bool m_needUpdating; // when in live mode, set this to TRUE to resize children in idle
@@ -237,6 +240,8 @@ protected:
wxPen* m_facePen; wxPen* m_facePen;
private: private:
WX_DECLARE_CONTROL_CONTAINER();
DECLARE_DYNAMIC_CLASS(wxSplitterWindow) DECLARE_DYNAMIC_CLASS(wxSplitterWindow)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -79,13 +79,12 @@ public:
private: private:
void UpdatePosition(); void UpdatePosition();
wxMenu* fileMenu; wxWindow *m_left,
wxMenuBar* menuBar; *m_right;
MyCanvas* m_leftCanvas;
MyCanvas* m_rightCanvas;
MySplitterWindow* m_splitter; MySplitterWindow* m_splitter;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
class MyCanvas: public wxScrolledWindow class MyCanvas: public wxScrolledWindow
@@ -154,7 +153,7 @@ MyFrame::MyFrame(wxFrame* frame, const wxString& title,
CreateStatusBar(2); CreateStatusBar(2);
// Make a menubar // Make a menubar
fileMenu = new wxMenu; wxMenu *fileMenu = new wxMenu;
fileMenu->Append(SPLIT_VERTICAL, "Split &Vertically\tCtrl-V", "Split vertically"); fileMenu->Append(SPLIT_VERTICAL, "Split &Vertically\tCtrl-V", "Split vertically");
fileMenu->Append(SPLIT_HORIZONTAL, "Split &Horizontally\tCtrl-H", "Split horizontally"); fileMenu->Append(SPLIT_HORIZONTAL, "Split &Horizontally\tCtrl-H", "Split horizontally");
fileMenu->Append(SPLIT_UNSPLIT, "&Unsplit\tCtrl-U", "Unsplit"); fileMenu->Append(SPLIT_UNSPLIT, "&Unsplit\tCtrl-U", "Unsplit");
@@ -163,33 +162,33 @@ MyFrame::MyFrame(wxFrame* frame, const wxString& title,
fileMenu->AppendSeparator(); fileMenu->AppendSeparator();
fileMenu->Append(SPLIT_QUIT, "E&xit\tAlt-X", "Exit"); fileMenu->Append(SPLIT_QUIT, "E&xit\tAlt-X", "Exit");
menuBar = new wxMenuBar; wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(fileMenu, "&File"); menuBar->Append(fileMenu, "&File");
SetMenuBar(menuBar); SetMenuBar(menuBar);
m_splitter = new MySplitterWindow(this, SPLITTER_WINDOW); m_splitter = new MySplitterWindow(this, SPLITTER_WINDOW);
#if 0 #if 1
wxSize sz( m_splitter->GetSize() ); m_left = new MyCanvas(m_splitter, CANVAS1, wxPoint(0, 0), wxSize(400, 400), "Test1" );
wxLogMessage( "Initial splitter size: %d %d\n", (int)sz.x, (int)sz.y ); m_left->SetBackgroundColour(*wxRED);
#endif // 0 m_left->SetScrollbars(20, 20, 50, 50);
m_left->SetCursor(wxCursor(wxCURSOR_MAGNIFIER));
m_leftCanvas = new MyCanvas(m_splitter, CANVAS1, wxPoint(0, 0), wxSize(400, 400), "Test1" ); m_right = new MyCanvas(m_splitter, CANVAS2, wxPoint(0, 0), wxSize(400, 400), "Test2" );
m_leftCanvas->SetBackgroundColour(*wxRED); m_right->SetBackgroundColour(*wxCYAN);
m_leftCanvas->SetScrollbars(20, 20, 50, 50); m_right->SetScrollbars(20, 20, 50, 50);
m_leftCanvas->SetCursor(wxCursor(wxCURSOR_MAGNIFIER)); #else // for testing kbd navigation inside the splitter
m_left = new wxTextCtrl(m_splitter, -1, "first text");
m_rightCanvas = new MyCanvas(m_splitter, CANVAS2, wxPoint(0, 0), wxSize(400, 400), "Test2" ); m_right = new wxTextCtrl(m_splitter, -1, "second text");
m_rightCanvas->SetBackgroundColour(*wxCYAN); #endif
m_rightCanvas->SetScrollbars(20, 20, 50, 50);
// you can also do this to start with a single window // you can also do this to start with a single window
#if 0 #if 0
m_rightCanvas->Show(FALSE); m_right->Show(FALSE);
m_splitter->Initialize(m_leftCanvas); m_splitter->Initialize(m_left);
#else #else
m_splitter->SplitVertically(m_leftCanvas, m_rightCanvas, 100); m_splitter->SplitVertically(m_left, m_right, 100);
#endif #endif
SetStatusText("Min pane size = 0", 1); SetStatusText("Min pane size = 0", 1);
@@ -208,9 +207,9 @@ void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
{ {
if ( m_splitter->IsSplit() ) if ( m_splitter->IsSplit() )
m_splitter->Unsplit(); m_splitter->Unsplit();
m_leftCanvas->Show(TRUE); m_left->Show(TRUE);
m_rightCanvas->Show(TRUE); m_right->Show(TRUE);
m_splitter->SplitHorizontally( m_leftCanvas, m_rightCanvas ); m_splitter->SplitHorizontally( m_left, m_right );
UpdatePosition(); UpdatePosition();
} }
@@ -218,9 +217,9 @@ void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
{ {
if ( m_splitter->IsSplit() ) if ( m_splitter->IsSplit() )
m_splitter->Unsplit(); m_splitter->Unsplit();
m_leftCanvas->Show(TRUE); m_left->Show(TRUE);
m_rightCanvas->Show(TRUE); m_right->Show(TRUE);
m_splitter->SplitVertically( m_leftCanvas, m_rightCanvas ); m_splitter->SplitVertically( m_left, m_right );
UpdatePosition(); UpdatePosition();
} }

View File

@@ -52,9 +52,9 @@
IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
#if wxUSE_GUI #if wxUSE_GUI
IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)

View File

@@ -57,7 +57,7 @@ END_EVENT_TABLE()
// implementation // implementation
// ============================================================================ // ============================================================================
WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, m_container) WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxPanel creation // wxPanel creation
@@ -65,7 +65,6 @@ WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, m_container)
void wxPanel::Init() void wxPanel::Init()
{ {
m_container = new wxControlContainer(this);
} }
bool wxPanel::Create(wxWindow *parent, wxWindowID id, bool wxPanel::Create(wxWindow *parent, wxWindowID id,
@@ -79,7 +78,6 @@ bool wxPanel::Create(wxWindow *parent, wxWindowID id,
wxPanel::~wxPanel() wxPanel::~wxPanel()
{ {
delete m_container;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -56,14 +56,21 @@ BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
EVT_SPLITTER_SASH_POS_CHANGING(-1, wxSplitterWindow::OnSashPosChanged) EVT_SPLITTER_SASH_POS_CHANGING(-1, wxSplitterWindow::OnSashPosChanged)
EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick) EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick)
EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent) EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent)
WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow);
bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id, bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
const wxString& name) const wxString& name)
{ {
// allow TABbing from one window to the other
style |= wxTAB_TRAVERSAL;
if (!wxWindow::Create(parent, id, pos, size, style, name)) if (!wxWindow::Create(parent, id, pos, size, style, name))
return FALSE; return FALSE;