]>
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
)
39 EVT_SIZE(wxPanel::OnSize
)
46 m_winLastFocused
= (wxWindow
*)NULL
;
47 m_btnDefault
= (wxButton
*)NULL
;
50 bool wxPanel::Create(wxWindow
*parent
, wxWindowID id
,
56 bool ret
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
61 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
62 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
69 void wxPanel::InitDialog(void)
71 wxInitDialogEvent
event(GetId());
72 event
.SetEventObject(this);
73 GetEventHandler()->ProcessEvent(event
);
76 // Responds to colour changes, and passes event on to children.
77 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent
& event
)
79 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
82 // Propagate the event to the non-top-level children
83 wxWindow::OnSysColourChanged(event
);
86 void wxPanel::OnNavigationKey( wxNavigationKeyEvent
& event
)
88 // there is not much to do if we have only one child (or not at all)
89 if (GetChildren().GetCount() < 2)
95 // don't process these ones here
96 if (event
.IsWindowChange())
102 // Did the event emitter tell us where the last focus was?
103 // wxGTK does this in wxWindow, but wxMSW does not. It is
104 // also done in wxPanel if the event is propagated up.
105 wxWindow
*winFocus
= event
.GetCurrentFocus();
107 // Do we know where the focus was ourselves, then?
109 winFocus
= m_winLastFocused
;
112 winFocus
= wxWindow::FindFocus();
120 wxWindowList::Node
*start_node
= GetChildren().Find( winFocus
);
122 start_node
= GetChildren().Find( m_winLastFocused
);
124 start_node
= GetChildren().GetFirst();
126 wxWindowList::Node
*node
= event
.GetDirection() ? start_node
->GetNext()
127 : start_node
->GetPrevious();
129 while ( node
!= start_node
)
131 // Have we come to the last or first item on the panel?
134 // Check if our (may be grand) parent is another panel: if this is
135 // the case, they will know what to do with this navigation key and
136 // so give them the chance to process it instead of looping inside
137 // this panel (normally, the focus will go to the next/previous
138 // item after this panel in the parent panel).
139 wxWindow
*focussed_child_of_parent
= this;
140 for ( wxWindow
*parent
= GetParent(); parent
; parent
= parent
->GetParent() )
142 // we don't want to tab into a different dialog or frame
143 if ( focussed_child_of_parent
->IsTopLevel() )
146 // is the parent a panel?
147 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
150 event
.SetCurrentFocus( focussed_child_of_parent
);
151 if (parent
->GetEventHandler()->ProcessEvent( event
))
155 focussed_child_of_parent
= parent
;
158 // no, we are not inside another panel so process this ourself
159 node
= event
.GetDirection() ? GetChildren().GetFirst()
160 : GetChildren().GetLast();
165 wxWindow
*child
= node
->GetData();
167 if ( child
->AcceptsFocus() )
169 m_winLastFocused
= child
; // should be redundant, but it is not
174 node
= event
.GetDirection() ? node
->GetNext() : node
->GetPrevious();
177 // we cycled through all of our children and none of them wanted to accept
183 void wxPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
185 #if wxUSE_CONSTRAINTS
186 if (GetAutoLayout()) Layout();
190 void wxPanel::SetFocus()
192 // If the panel gets the focus *by way of getting it set directly*
193 // we move it to the first window that can get it.
195 wxNode
*node
= GetChildren().First();
198 wxWindow
*child
= (wxWindow
*) node
->Data();
199 if (child
->AcceptsFocus())
201 m_winLastFocused
= child
; // should be redundant, but it is not
208 m_winLastFocused
= (wxWindow
*) NULL
;
210 wxWindow::SetFocus();
213 void wxPanel::OnFocus(wxFocusEvent
& event
)
215 // If the panel gets the focus *by way of getting clicked on*
216 // we move it to either the last window that had the focus or
217 // the first one that can get it.
219 if (m_winLastFocused
)
221 // it might happen that the window got reparented...
222 if ( m_winLastFocused
->GetParent() == this )
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
;