1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "panelg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/settings.h"
27 #include "wx/generic/panelg.h"
29 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_DYNAMIC_CLASS(wxPanel
, wxWindow
)
32 BEGIN_EVENT_TABLE(wxPanel
, wxWindow
)
33 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged
)
34 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey
)
43 bool wxPanel::Create(wxWindow
*parent
, wxWindowID id
,
49 bool ret
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
53 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
54 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
61 void wxPanel::InitDialog(void)
63 wxInitDialogEvent
event(GetId());
64 event
.SetEventObject(this);
65 GetEventHandler()->ProcessEvent(event
);
68 void wxPanel::SetFocus()
70 SetFocusToNextChild();
73 // Responds to colour changes, and passes event on to children.
74 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent
& event
)
76 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
79 // Propagate the event to the non-top-level children
80 wxWindow::OnSysColourChanged(event
);
83 void wxPanel::OnNavigationKey(wxNavigationKeyEvent
& event
)
85 // don't process these ones here
86 if ( event
.IsWindowChange() ) {
91 // first of all, find the window which currently has the focus
92 wxNode
*node
= GetChildren().First();
93 wxWindow
*winFocus
= event
.GetCurrentFocus();
95 // @@@ no FindFocus() in wxGTK
97 if ( winFocus
== NULL
)
98 winFocus
= wxWindow::FindFocus();
101 while ( node
!= NULL
) {
102 if ( node
->Data() == winFocus
)
108 if ( !SetFocusToNextChild(node
, event
.GetDirection()) )
112 // set focus to the next child which accepts it (or first/last if node == NULL)
113 bool wxPanel::SetFocusToNextChild(wxNode
*node
, bool bForward
)
115 // @@ using typed list would be better...
116 #define WIN(node) ((wxWindow *)(node->Data()))
118 bool bFound
= FALSE
; // have we found a window we will set focus to?
120 wxList
*children
= & GetChildren();
121 if ( node
== NULL
) {
122 // we've never had focus before
123 node
= bForward
? children
->First() : children
->Last();
124 if ( node
== NULL
) {
129 bFound
= WIN(node
)->AcceptsFocus();
131 #if 0 // to restore when it will really work (now it's triggered all the time)
133 // just to be sure it's the right one
134 wxASSERT( WIN(node
)->AcceptsFocus() );
138 // find the next child which accepts focus
139 bool bParentWantsIt
= TRUE
;
141 node
= bForward
? node
->Next() : node
->Previous();
142 if ( node
== NULL
) {
143 if ( !bParentWantsIt
) {
144 // we've already been here which means that we've done a whole
145 // cycle without success - get out from the infinite loop
149 // ask parent if he doesn't want to advance focus to the next panel
150 if ( GetParent() != NULL
) {
151 wxNavigationKeyEvent event
;
152 event
.SetDirection(bForward
);
153 event
.SetWindowChange(FALSE
);
154 event
.SetCurrentFocus(this);
156 if ( GetParent()->ProcessEvent(event
) )
160 // a sentinel to avoid infinite loops
161 bParentWantsIt
= FALSE
;
164 node
= bForward
? children
->First() : children
->Last();
167 bFound
= WIN(node
)->AcceptsFocus();
170 WIN(node
)->SetFocus();