moved knd handling logic from wxPanel to wxControlContainer (sorry for

the dull name Julian ;-)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11289 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-08-06 00:49:59 +00:00
parent ec4f95c40f
commit 456bc6d9b8
12 changed files with 592 additions and 421 deletions

135
include/wx/containr.h Normal file
View File

@@ -0,0 +1,135 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/containr.h
// Purpose: wxControlContainer class declration: a "mix-in" class which
// implements the TAB navigation between the controls
// Author: Vadim Zeitlin
// Modified by:
// Created: 06.08.01
// RCS-ID: $Id$
// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_CONTAINR_H_
#define _WX_CONTAINR_H_
#ifdef __GNUG__
#pragma implementation "containr.h"
#endif
class WXDLLEXPORT wxFocusEvent;
class WXDLLEXPORT wxNavigationKeyEvent;
class WXDLLEXPORT wxWindow;
/*
Implementation note: wxControlContainer is not a real mix-in but rather
a class meant to be agregated with (and not inherited from). Although
logically it should be a mix-in, doing it like this has no advantage from
the point of view of the existing code but does have some problems (we'd
need to play tricks with event handlers which may be difficult to do
safely). The price we pay for this simplicity is the ugly macros below.
*/
// ----------------------------------------------------------------------------
// wxControlContainer
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxControlContainer
{
public:
// ctors and such
wxControlContainer(wxWindow *winParent);
wxWindow *GetDefaultItem() const { return m_winDefault; }
wxWindow *SetDefaultItem(wxWindow *win)
{ wxWindow *winOld = m_winDefault; m_winDefault = win; return winOld; }
void SetLastFocus(wxWindow *win);
// the methods to be called from the window event handlers
void HandleOnNavigationKey(wxNavigationKeyEvent& event);
void HandleOnFocus(wxFocusEvent& event);
void HandleOnWindowDestroy(wxWindowBase *child);
// should be called from SetFocus()
void DoSetFocus();
protected:
// set the focus to the child which had it the last time
bool SetFocusToChild();
// the parent window we manage the children for
wxWindow *m_winParent;
// the child which had the focus last time this panel was activated
wxWindow *m_winLastFocused;
// a default window (e.g. a button) or NULL
wxWindow *m_winDefault;
};
// this function is for wxWindows internal use only
extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
// ----------------------------------------------------------------------------
// macros which may be used by the classes wishing to implement TAB navigation
// among their children
// ----------------------------------------------------------------------------
// declare the methods to be forwarded
#define WX_DECLARE_CONTROL_CONTAINER() \
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) \
// implement the event table entries for wxControlContainer
#define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
EVT_SET_FOCUS(classname::OnFocus) \
EVT_CHILD_FOCUS(classname::OnChildFocus) \
EVT_NAVIGATION_KEY(classname::OnNavigationKey)
// implement the methods forwarding to the wxControlContainer
#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, container) \
wxWindow *classname::SetDefaultItem(wxWindow *child) \
{ \
return container->SetDefaultItem(child); \
} \
\
wxWindow *classname::GetDefaultItem() const \
{ \
return container->GetDefaultItem(); \
} \
\
void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
{ \
container->HandleOnNavigationKey(event); \
} \
\
void classname::RemoveChild(wxWindowBase *child) \
{ \
container->HandleOnWindowDestroy(child); \
\
wxWindow::RemoveChild(child); \
} \
\
void classname::SetFocus() \
{ \
container->DoSetFocus(); \
} \
\
void classname::OnChildFocus(wxChildFocusEvent& event) \
{ \
container->SetLastFocus(event.GetWindow()); \
} \
\
void classname::OnFocus(wxFocusEvent& event) \
{ \
container->HandleOnFocus(event); \
}
#endif // _WX_CONTAINR_H_

View File

@@ -155,7 +155,8 @@ BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_RIGHT_DCLICK, 111)
DECLARE_EVENT_TYPE(wxEVT_SET_FOCUS, 112)
DECLARE_EVENT_TYPE(wxEVT_KILL_FOCUS, 113)
DECLARE_EVENT_TYPE(wxEVT_MOUSEWHEEL, 114)
DECLARE_EVENT_TYPE(wxEVT_CHILD_FOCUS, 114)
DECLARE_EVENT_TYPE(wxEVT_MOUSEWHEEL, 115)
// Non-client mouse events
DECLARE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN, 200)
@@ -959,6 +960,18 @@ private:
DECLARE_DYNAMIC_CLASS(wxFocusEvent)
};
// wxChildFocusEvent notifies the parent that a child has got the focus: unlike
// wxFocusEvent it is propgated upwards the window chain
class WXDLLEXPORT wxChildFocusEvent : public wxCommandEvent
{
public:
wxChildFocusEvent(wxWindow *win = NULL);
wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
DECLARE_DYNAMIC_CLASS(wxChildFocusEvent)
};
// Activate event class
/*
wxEVT_ACTIVATE
@@ -1759,6 +1772,7 @@ typedef void (wxEvtHandler::*wxEraseEventFunction)(wxEraseEvent&);
typedef void (wxEvtHandler::*wxMouseEventFunction)(wxMouseEvent&);
typedef void (wxEvtHandler::*wxCharEventFunction)(wxKeyEvent&);
typedef void (wxEvtHandler::*wxFocusEventFunction)(wxFocusEvent&);
typedef void (wxEvtHandler::*wxChildFocusEventFunction)(wxChildFocusEvent&);
typedef void (wxEvtHandler::*wxActivateEventFunction)(wxActivateEvent&);
typedef void (wxEvtHandler::*wxMenuEventFunction)(wxMenuEvent&);
typedef void (wxEvtHandler::*wxJoystickEventFunction)(wxJoystickEvent&);
@@ -1826,6 +1840,7 @@ typedef void (wxEvtHandler::*wxContextMenuEventFunction)(wxContextMenuEvent&);
#define EVT_MENU_HIGHLIGHT_ALL(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MENU_HIGHLIGHT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMenuEventFunction) & func, (wxObject *) NULL ),
#define EVT_SET_FOCUS(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_SET_FOCUS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxFocusEventFunction) & func, (wxObject *) NULL ),
#define EVT_KILL_FOCUS(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_KILL_FOCUS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxFocusEventFunction) & func, (wxObject *) NULL ),
#define EVT_CHILD_FOCUS(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_CHILD_FOCUS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxChildFocusEventFunction) & func, (wxObject *) NULL ),
#define EVT_ACTIVATE(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_ACTIVATE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxActivateEventFunction) & func, (wxObject *) NULL ),
#define EVT_ACTIVATE_APP(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_ACTIVATE_APP, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxActivateEventFunction) & func, (wxObject *) NULL ),
#define EVT_END_SESSION(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_END_SESSION, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCloseEventFunction) & func, (wxObject *) NULL ),

View File

@@ -21,8 +21,10 @@
// ----------------------------------------------------------------------------
#include "wx/window.h"
#include "wx/containr.h"
class WXDLLEXPORT wxButton;
class WXDLLEXPORT wxControlContainer;
WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
@@ -67,62 +69,34 @@ public:
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = wxPanelNameStr);
// Sends an OnInitDialog event, which in turns transfers data to
// to the dialog via validators.
virtual void InitDialog();
#if wxUSE_BUTTON
// a default button is activated when Enter is pressed
wxButton *GetDefaultItem() const { return m_btnDefault; }
void SetDefaultItem(wxButton *btn) { m_btnDefault = btn; }
#endif // wxUSE_BUTTON
virtual ~wxPanel();
// implementation from now on
// --------------------------
// Sends an OnInitDialog event, which in turns transfers data to
// to the dialog via validators.
virtual void InitDialog();
// responds to colour changes
void OnSysColourChanged(wxSysColourChangedEvent& event);
// process a keyboard navigation message (Tab traversal)
void OnNavigationKey(wxNavigationKeyEvent& event);
// set the focus to the first child if we get it
void OnFocus(wxFocusEvent& event);
// calls layout for layout constraints and sizers
void OnSize(wxSizeEvent& event);
// overridden to tab move focus into first focusable child
virtual void SetFocus();
// called by wxWindow whenever it gets focus
void SetLastFocus(wxWindow *win) { m_winLastFocused = win; }
wxWindow *GetLastFocus() const { return m_winLastFocused; }
virtual void RemoveChild(wxWindowBase *child);
WX_DECLARE_CONTROL_CONTAINER();
protected:
// common part of all ctors
void Init();
// set the focus to the child which had it the last time
bool SetFocusToChild();
// the child which had the focus last time this panel was activated
wxWindow *m_winLastFocused;
#if wxUSE_BUTTON
// a default button or NULL
wxButton *m_btnDefault;
#endif // wxUSE_BUTTON
// the object which implements the TAB traversal logic
wxControlContainer *m_container;
private:
DECLARE_DYNAMIC_CLASS(wxPanel)
DECLARE_EVENT_TABLE()
};
// this function is for wxWindows use only
extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
#endif
// _WX_GENERIC_PANEL_H_

View File

@@ -170,6 +170,10 @@ public:
// window attributes
// -----------------
// NB: in future versions of wxWindows Set/GetTitle() will only work
// with the top level windows (such as dialogs and frames) and
// Set/GetLabel() only with the other ones (i.e. all controls).
// the title (or label, see below) of the window: the text which the
// window shows
virtual void SetTitle( const wxString& WXUNUSED(title) ) {}
@@ -361,8 +365,8 @@ public:
virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
virtual bool GetThemeEnabled() const { return m_themeEnabled; }
// focus handling
// --------------
// focus and keyboard handling
// ---------------------------
// set focus to this window
virtual void SetFocus() = 0;
@@ -378,6 +382,17 @@ public:
// click it
virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
// NB: these methods really don't belong here but with the current
// class hierarchy there is no other place for them :-(
// get the default child of this parent, i.e. the one which is
// activated by pressing <Enter>
virtual wxWindow *GetDefaultItem() const { return NULL; }
// set this child as default, return the old default
virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child))
{ return NULL; }
// parent/children relations
// -------------------------
@@ -786,7 +801,7 @@ protected:
// the window id - a number which uniquely identifies a window among
// its siblings unless it is -1
wxWindowID m_windowId;
// the parent window of this window (or NULL) and the list of the children
// of this window
wxWindow *m_parent;