home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / include / wx / containr.h < prev    next >
C/C++ Source or Header  |  2002-08-31  |  6KB  |  171 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name:        wx/containr.h
  3. // Purpose:     wxControlContainer class declration: a "mix-in" class which
  4. //              implements the TAB navigation between the controls
  5. // Author:      Vadim Zeitlin
  6. // Modified by:
  7. // Created:     06.08.01
  8. // RCS-ID:      $Id: containr.h,v 1.9 2002/08/31 11:29:09 GD Exp $
  9. // Copyright:   (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
  10. // Licence:     wxWindows licence
  11. ///////////////////////////////////////////////////////////////////////////////
  12.  
  13. #ifndef _WX_CONTAINR_H_
  14. #define _WX_CONTAINR_H_
  15.  
  16. #if defined(__GNUG__) && !defined(__APPLE__)
  17.     #pragma interface "containr.h"
  18. #endif
  19.  
  20. class WXDLLEXPORT wxFocusEvent;
  21. class WXDLLEXPORT wxNavigationKeyEvent;
  22. class WXDLLEXPORT wxWindow;
  23. class WXDLLEXPORT wxWindowBase;
  24.  
  25. /*
  26.    Implementation note: wxControlContainer is not a real mix-in but rather
  27.    a class meant to be agregated with (and not inherited from). Although
  28.    logically it should be a mix-in, doing it like this has no advantage from
  29.    the point of view of the existing code but does have some problems (we'd
  30.    need to play tricks with event handlers which may be difficult to do
  31.    safely). The price we pay for this simplicity is the ugly macros below.
  32.  */
  33.  
  34. // ----------------------------------------------------------------------------
  35. // wxControlContainer
  36. // ----------------------------------------------------------------------------
  37.  
  38. class WXDLLEXPORT wxControlContainer
  39. {
  40. public:
  41.     // ctors and such
  42.     wxControlContainer(wxWindow *winParent = NULL);
  43.     void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; }
  44.  
  45.     // default item access: we have a permanent default item which is the one
  46.     // set by the user code but we may also have a temporary default item which
  47.     // would be chosen if the user pressed "Enter" now but the default action
  48.     // reverts to the "permanent" default as soon as this temporary default
  49.     // item lsoes focus
  50.  
  51.     // get the default item, temporary or permanent
  52.     wxWindow *GetDefaultItem() const
  53.         { return m_winTmpDefault ? m_winTmpDefault : m_winDefault; }
  54.  
  55.     // set the permanent default item, return its old value
  56.     wxWindow *SetDefaultItem(wxWindow *win)
  57.         { wxWindow *winOld = m_winDefault; m_winDefault = win; return winOld; }
  58.  
  59.     // set a temporary default item, SetTmpDefaultItem(NULL) should be called
  60.     // soon after a call to SetTmpDefaultItem(window)
  61.     void SetTmpDefaultItem(wxWindow *win) { m_winTmpDefault = win; }
  62.  
  63.     // the methods to be called from the window event handlers
  64.     void HandleOnNavigationKey(wxNavigationKeyEvent& event);
  65.     void HandleOnFocus(wxFocusEvent& event);
  66.     void HandleOnWindowDestroy(wxWindowBase *child);
  67.  
  68.     // should be called from SetFocus(), returns FALSE if we did nothing with
  69.     // the focus and the default processing should take place
  70.     bool DoSetFocus();
  71.  
  72.     // called from OnChildFocus() handler, i.e. when one of our (grand)
  73.     // children gets the focus
  74.     void SetLastFocus(wxWindow *win);
  75.  
  76. protected:
  77.     // set the focus to the child which had it the last time
  78.     bool SetFocusToChild();
  79.  
  80.     // the parent window we manage the children for
  81.     wxWindow *m_winParent;
  82.  
  83.     // the child which had the focus last time this panel was activated
  84.     wxWindow *m_winLastFocused;
  85.  
  86.     // a default window (usually a button) or NULL
  87.     wxWindow *m_winDefault;
  88.  
  89.     // a temporary override of m_winDefault, use the latter if NULL
  90.     wxWindow *m_winTmpDefault;
  91.  
  92.     DECLARE_NO_COPY_CLASS(wxControlContainer)
  93. };
  94.  
  95. // this function is for wxWindows internal use only
  96. extern bool wxSetFocusToChild(wxWindow *win, wxWindow **child);
  97.  
  98. // ----------------------------------------------------------------------------
  99. // macros which may be used by the classes wishing to implement TAB navigation
  100. // among their children
  101. // ----------------------------------------------------------------------------
  102.  
  103. // declare the methods to be forwarded
  104. #define WX_DECLARE_CONTROL_CONTAINER() \
  105. public: \
  106.     void OnNavigationKey(wxNavigationKeyEvent& event); \
  107.     void OnFocus(wxFocusEvent& event); \
  108.     virtual void OnChildFocus(wxChildFocusEvent& event); \
  109.     virtual void SetFocus(); \
  110.     virtual void RemoveChild(wxWindowBase *child); \
  111.     virtual wxWindow *GetDefaultItem() const; \
  112.     virtual wxWindow *SetDefaultItem(wxWindow *child); \
  113.     virtual void SetTmpDefaultItem(wxWindow *win); \
  114. \
  115. protected: \
  116.     wxControlContainer m_container
  117.  
  118. // implement the event table entries for wxControlContainer
  119. #define WX_EVENT_TABLE_CONTROL_CONTAINER(classname) \
  120.     EVT_SET_FOCUS(classname::OnFocus) \
  121.     EVT_CHILD_FOCUS(classname::OnChildFocus) \
  122.     EVT_NAVIGATION_KEY(classname::OnNavigationKey)
  123.  
  124. // implement the methods forwarding to the wxControlContainer
  125. #define WX_DELEGATE_TO_CONTROL_CONTAINER(classname)  \
  126. wxWindow *classname::SetDefaultItem(wxWindow *child) \
  127. { \
  128.     return m_container.SetDefaultItem(child); \
  129. } \
  130.  \
  131. void classname::SetTmpDefaultItem(wxWindow *child) \
  132. { \
  133.     m_container.SetTmpDefaultItem(child); \
  134. } \
  135.  \
  136. wxWindow *classname::GetDefaultItem() const \
  137. { \
  138.     return m_container.GetDefaultItem(); \
  139. } \
  140.  \
  141. void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
  142. { \
  143.     m_container.HandleOnNavigationKey(event); \
  144. } \
  145.  \
  146. void classname::RemoveChild(wxWindowBase *child) \
  147. { \
  148.     m_container.HandleOnWindowDestroy(child); \
  149.  \
  150.     wxWindow::RemoveChild(child); \
  151. } \
  152.  \
  153. void classname::SetFocus() \
  154. { \
  155.     if ( !m_container.DoSetFocus() ) \
  156.         wxWindow::SetFocus(); \
  157. } \
  158.  \
  159. void classname::OnChildFocus(wxChildFocusEvent& event) \
  160. { \
  161.     m_container.SetLastFocus(event.GetWindow()); \
  162. } \
  163.  \
  164. void classname::OnFocus(wxFocusEvent& event) \
  165. { \
  166.     m_container.HandleOnFocus(event); \
  167. }
  168.  
  169.  
  170. #endif // _WX_CONTAINR_H_
  171.