]>
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 IMPLEMENT_DYNAMIC_CLASS(wxPanel
, wxWindow
)
34 BEGIN_EVENT_TABLE(wxPanel
, wxWindow
)
35 EVT_SYS_COLOUR_CHANGED(wxPanel::OnSysColourChanged
)
36 EVT_SET_FOCUS(wxPanel::OnFocus
)
37 EVT_NAVIGATION_KEY(wxPanel::OnNavigationKey
)
38 EVT_SIZE(wxPanel::OnSize
)
44 m_winLastFocused
= (wxWindow
*)NULL
;
45 m_btnDefault
= (wxButton
*)NULL
;
48 bool wxPanel::Create(wxWindow
*parent
, wxWindowID id
,
54 bool ret
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
58 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
59 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
65 void wxPanel::InitDialog(void)
67 wxInitDialogEvent
event(GetId());
68 event
.SetEventObject(this);
69 GetEventHandler()->ProcessEvent(event
);
72 // Responds to colour changes, and passes event on to children.
73 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent
& event
)
75 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
78 // Propagate the event to the non-top-level children
79 wxWindow::OnSysColourChanged(event
);
82 void wxPanel::OnNavigationKey( wxNavigationKeyEvent
& event
)
84 // there is not much to do if we have only one child (or not at all)
85 if (GetChildren().GetCount() < 2)
91 // don't process these ones here
92 if (event
.IsWindowChange())
98 // Did the event emitter tell us where the last focus was?
99 // wxGTK does this in wxWindow, but wxMSW does not. It is
100 // also done in wxPanel if the event is propagated up.
101 wxWindow
*winFocus
= event
.GetCurrentFocus();
103 // Do we know where the focus was ourselves, then?
105 winFocus
= m_winLastFocused
;
108 winFocus
= wxWindow::FindFocus();
116 wxWindowList::Node
*start_node
= GetChildren().Find( winFocus
);
118 start_node
= GetChildren().Find( m_winLastFocused
);
120 start_node
= GetChildren().GetFirst();
122 wxWindowList::Node
*node
= event
.GetDirection() ? start_node
->GetNext()
123 : start_node
->GetPrevious();
125 while ( node
!= start_node
)
127 // Have we come to the last or first item on the panel?
130 // Check if our (may be grand) parent is another panel: if this is
131 // the case, they will know what to do with this navigation key and
132 // so give them the chance to process it instead of looping inside
133 // this panel (normally, the focus will go to the next/previous
134 // item after this panel in the parent panel).
135 wxWindow
*focussed_child_of_parent
= this;
136 for ( wxWindow
*parent
= GetParent(); parent
; parent
= parent
->GetParent() )
138 // we don't want to tab into a different dialog or frame
139 if ( focussed_child_of_parent
->IsTopLevel() )
142 // is the parent a panel?
143 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
146 event
.SetCurrentFocus( focussed_child_of_parent
);
147 if (parent
->GetEventHandler()->ProcessEvent( event
))
151 focussed_child_of_parent
= parent
;
154 // no, we are not inside another panel so process this ourself
155 node
= event
.GetDirection() ? GetChildren().GetFirst()
156 : GetChildren().GetLast();
161 wxWindow
*child
= node
->GetData();
163 if ( child
->AcceptsFocus() )
165 m_winLastFocused
= child
; // should be redundant, but it is not
170 node
= event
.GetDirection() ? node
->GetNext() : node
->GetPrevious();
173 // we cycled through all of our children and none of them wanted to accept
179 void wxPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
181 #if wxUSE_CONSTRAINTS
187 void wxPanel::SetFocus()
189 // If the panel gets the focus *by way of getting it set directly*
190 // we move the focus to the first window that can get it.
192 wxNode
*node
= GetChildren().First();
195 wxWindow
*child
= (wxWindow
*) node
->Data();
196 if (child
->AcceptsFocus())
198 m_winLastFocused
= child
; // should be redundant, but it is not
205 m_winLastFocused
= (wxWindow
*) NULL
;
207 wxWindow::SetFocus();
210 void wxPanel::OnFocus(wxFocusEvent
& event
)
212 // If the panel gets the focus *by way of getting clicked on*
213 // we move the focus to either the last window that had the
214 // focus or the first one that can get it.
216 if (m_winLastFocused
)
218 // It might happen that the window got reparented or no longer
219 // accepts the focus.
220 if ((m_winLastFocused
->GetParent() == this) &&
221 (m_winLastFocused
->AcceptsFocus()))
223 m_winLastFocused
->SetFocus();
228 wxNode
*node
= GetChildren().First();
231 wxWindow
*child
= (wxWindow
*) node
->Data();
232 if (child
->AcceptsFocus())
234 m_winLastFocused
= child
; // should be redundant, but it is not
241 m_winLastFocused
= (wxWindow
*) NULL
;