]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/panelg.cpp
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/object.h"
26 #include "wx/colour.h"
27 #include "wx/settings.h"
30 #include "wx/generic/panelg.h"
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS(wxPanel
, wxWindow
)
35 BEGIN_EVENT_TABLE(wxPanel
, wxWindow
)
36 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged
)
37 EVT_SET_FOCUS(wxPanel::OnFocus
)
38 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey
)
45 m_winLastFocused
= (wxWindow
*)NULL
;
46 m_btnDefault
= (wxButton
*)NULL
;
49 bool wxPanel::Create(wxWindow
*parent
, wxWindowID id
,
55 bool ret
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
60 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
61 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
68 void wxPanel::InitDialog(void)
70 wxInitDialogEvent
event(GetId());
71 event
.SetEventObject(this);
72 GetEventHandler()->ProcessEvent(event
);
75 // Responds to colour changes, and passes event on to children.
76 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent
& event
)
78 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
81 // Propagate the event to the non-top-level children
82 wxWindow::OnSysColourChanged(event
);
85 void wxPanel::OnNavigationKey( wxNavigationKeyEvent
& event
)
87 // there is not much to do if we have only one child (or not at all)
88 if (GetChildren().GetCount() < 2)
94 // don't process these ones here
95 if (event
.IsWindowChange())
101 wxWindow
*winFocus
= event
.GetCurrentFocus();
103 winFocus
= wxWindow::FindFocus();
111 wxWindowList::Node
*start_node
= GetChildren().Find( winFocus
);
113 start_node
= GetChildren().Find( m_winLastFocused
);
115 start_node
= GetChildren().GetFirst();
117 wxWindowList::Node
*node
= event
.GetDirection() ? start_node
->GetNext()
118 : start_node
->GetPrevious();
120 while ( node
!= start_node
)
124 // check if our (may be grand) parent is another panel: if this is
125 // the case, they will know what to do with this navigation key and
126 // so give them the chance to process it instead of looping inside
127 // this panel (normally, the focus will go to the next/previous
128 // item after this panel in the parent panel)
129 wxWindow
*focussed_child_of_p
= this;
130 for ( wxWindow
*p
= GetParent(); p
; p
= p
->GetParent() )
132 if ( wxDynamicCast(p
, wxPanel
) )
134 event
.SetCurrentFocus( focussed_child_of_p
);
135 if (p
->GetEventHandler()->ProcessEvent( event
))
138 focussed_child_of_p
= p
;
141 // no, we are not inside another panel so process this ourself
142 node
= event
.GetDirection() ? GetChildren().GetFirst()
143 : GetChildren().GetLast();
148 wxWindow
*child
= node
->GetData();
150 if ( child
->AcceptsFocus() )
152 // ok, event processed
157 node
= event
.GetDirection() ? node
->GetNext() : node
->GetPrevious();
160 // we cycled through all of our children and none of them wanted to accept
165 void wxPanel::OnFocus(wxFocusEvent
& event
)
167 if ( m_winLastFocused
)
169 // it might happen that the window got reparented...
170 if ( m_winLastFocused
->GetParent() != this )
171 m_winLastFocused
= (wxWindow
*)NULL
;
173 m_winLastFocused
->SetFocus();