]>
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
);
59 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
60 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
67 void wxPanel::InitDialog(void)
69 wxInitDialogEvent
event(GetId());
70 event
.SetEventObject(this);
71 GetEventHandler()->ProcessEvent(event
);
74 // Responds to colour changes, and passes event on to children.
75 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent
& event
)
77 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
80 // Propagate the event to the non-top-level children
81 wxWindow::OnSysColourChanged(event
);
84 void wxPanel::OnNavigationKey( wxNavigationKeyEvent
& event
)
86 // there is not much to do if we have only one child (or not at all)
87 if (GetChildren().GetCount() < 2)
93 // don't process these ones here
94 if (event
.IsWindowChange())
100 // Did the event emitter tell us where the last focus was?
101 // wxGTK does this in wxWindow, but wxMSW does not. It is
102 // also done in wxPanel if the event is propagated up.
103 wxWindow
*winFocus
= event
.GetCurrentFocus();
105 // Do we know where the focus was ourselves, then?
107 winFocus
= m_winLastFocused
;
110 winFocus
= wxWindow::FindFocus();
118 wxWindowList::Node
*start_node
= GetChildren().Find( winFocus
);
120 start_node
= GetChildren().Find( m_winLastFocused
);
122 start_node
= GetChildren().GetFirst();
124 wxWindowList::Node
*node
= event
.GetDirection() ? start_node
->GetNext()
125 : start_node
->GetPrevious();
127 while ( node
!= start_node
)
129 // Have we come to the last or first item on the panel?
132 // Check if our (may be grand) parent is another panel: if this is
133 // the case, they will know what to do with this navigation key and
134 // so give them the chance to process it instead of looping inside
135 // this panel (normally, the focus will go to the next/previous
136 // item after this panel in the parent panel).
137 wxWindow
*focussed_child_of_parent
= this;
138 for ( wxWindow
*parent
= GetParent(); parent
; parent
= parent
->GetParent() )
140 // we don't want to tab into a different dialog or frame
141 if ( focussed_child_of_parent
->IsTopLevel() )
144 // is the parent a panel?
145 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
148 event
.SetCurrentFocus( focussed_child_of_parent
);
149 if (parent
->GetEventHandler()->ProcessEvent( event
))
153 focussed_child_of_parent
= parent
;
156 // no, we are not inside another panel so process this ourself
157 node
= event
.GetDirection() ? GetChildren().GetFirst()
158 : GetChildren().GetLast();
163 wxWindow
*child
= node
->GetData();
165 if ( child
->AcceptsFocus() )
167 m_winLastFocused
= child
; // should be redundant, but it is not
172 node
= event
.GetDirection() ? node
->GetNext() : node
->GetPrevious();
175 // we cycled through all of our children and none of them wanted to accept
181 void wxPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
183 #if wxUSE_CONSTRAINTS
184 if (GetAutoLayout()) Layout();
188 void wxPanel::SetFocus()
190 // If the panel gets the focus *by way of getting it set directly*
191 // we move the focus to the first window that can get it.
193 wxNode
*node
= GetChildren().First();
196 wxWindow
*child
= (wxWindow
*) node
->Data();
197 if (child
->AcceptsFocus())
199 m_winLastFocused
= child
; // should be redundant, but it is not
206 m_winLastFocused
= (wxWindow
*) NULL
;
208 wxWindow::SetFocus();
211 void wxPanel::OnFocus(wxFocusEvent
& event
)
213 // If the panel gets the focus *by way of getting clicked on*
214 // we move the focus to either the last window that had the
215 // focus or the first one that can get it.
217 if (m_winLastFocused
)
219 // It might happen that the window got reparented or no longer
220 // accepts the focus.
221 if ((m_winLastFocused
->GetParent() == this) &&
222 (m_winLastFocused
->AcceptsFocus()))
224 m_winLastFocused
->SetFocus();
229 wxNode
*node
= GetChildren().First();
232 wxWindow
*child
= (wxWindow
*) node
->Data();
233 if (child
->AcceptsFocus())
235 m_winLastFocused
= child
; // should be redundant, but it is not
242 m_winLastFocused
= (wxWindow
*) NULL
;