]> git.saurik.com Git - wxWidgets.git/blob - src/generic/panelg.cpp
OnEnter/OnDragOver API update (compiles, links, somewhat runs under wxGTK)
[wxWidgets.git] / src / generic / panelg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: panelg.cpp
3 // Purpose: wxPanel
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "panelg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/object.h"
25 #include "wx/font.h"
26 #include "wx/colour.h"
27 #include "wx/settings.h"
28 #endif
29
30 #include "wx/generic/panelg.h"
31
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow)
34
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)
40 END_EVENT_TABLE()
41
42 #endif
43
44 void wxPanel::Init()
45 {
46 m_winLastFocused = (wxWindow *)NULL;
47 m_btnDefault = (wxButton *)NULL;
48 }
49
50 bool wxPanel::Create(wxWindow *parent, wxWindowID id,
51 const wxPoint& pos,
52 const wxSize& size,
53 long style,
54 const wxString& name)
55 {
56 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
57
58 if ( ret )
59 {
60 #ifndef __WXGTK__
61 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
62 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
63 #endif
64 }
65
66 return ret;
67 }
68
69 void wxPanel::InitDialog(void)
70 {
71 wxInitDialogEvent event(GetId());
72 event.SetEventObject(this);
73 GetEventHandler()->ProcessEvent(event);
74 }
75
76 // Responds to colour changes, and passes event on to children.
77 void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
78 {
79 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
80 Refresh();
81
82 // Propagate the event to the non-top-level children
83 wxWindow::OnSysColourChanged(event);
84 }
85
86 void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
87 {
88 // there is not much to do if we have only one child (or not at all)
89 if (GetChildren().GetCount() < 2)
90 {
91 event.Skip();
92 return;
93 }
94
95 // don't process these ones here
96 if (event.IsWindowChange())
97 {
98 event.Skip();
99 return;
100 }
101
102 wxWindow *winFocus = event.GetCurrentFocus();
103 if (!winFocus)
104 winFocus = wxWindow::FindFocus();
105
106 if (!winFocus)
107 {
108 event.Skip();
109 return;
110 }
111
112 wxWindowList::Node *start_node = GetChildren().Find( winFocus );
113 if ( !start_node )
114 start_node = GetChildren().Find( m_winLastFocused );
115 if ( !start_node )
116 start_node = GetChildren().GetFirst();
117
118 wxWindowList::Node *node = event.GetDirection() ? start_node->GetNext()
119 : start_node->GetPrevious();
120
121 while ( node != start_node )
122 {
123 if ( !node )
124 {
125 // check if our (may be grand) parent is another panel: if this is
126 // the case, they will know what to do with this navigation key and
127 // so give them the chance to process it instead of looping inside
128 // this panel (normally, the focus will go to the next/previous
129 // item after this panel in the parent panel)
130 wxWindow *focussed_child_of_p = this;
131 for ( wxWindow *p = GetParent(); p; p = p->GetParent() )
132 {
133 // we don't want to tab into a different dialog or frame
134 if ( focussed_child_of_p->IsTopLevel() )
135 break;
136
137 if ( wxDynamicCast(p, wxPanel) )
138 {
139 event.SetCurrentFocus( focussed_child_of_p );
140 if (p->GetEventHandler()->ProcessEvent( event ))
141 return;
142 }
143 focussed_child_of_p = p;
144 }
145
146 // no, we are not inside another panel so process this ourself
147 node = event.GetDirection() ? GetChildren().GetFirst()
148 : GetChildren().GetLast();
149
150 continue;
151 }
152
153 wxWindow *child = node->GetData();
154
155 if ( child->AcceptsFocus() )
156 {
157 // ok, event processed
158 child->SetFocus();
159 return;
160 }
161
162 node = event.GetDirection() ? node->GetNext() : node->GetPrevious();
163 }
164
165 // we cycled through all of our children and none of them wanted to accept
166 // focus
167 event.Skip();
168 }
169
170
171 void wxPanel::OnSize(wxSizeEvent& WXUNUSED(event))
172 {
173 #if wxUSE_CONSTRAINTS
174 if (GetAutoLayout()) Layout();
175 #endif
176 }
177
178 void wxPanel::OnFocus(wxFocusEvent& event)
179 {
180 if ( m_winLastFocused )
181 {
182 // it might happen that the window got reparented...
183 if ( m_winLastFocused->GetParent() != this )
184 m_winLastFocused = (wxWindow *)NULL;
185 else
186 m_winLastFocused->SetFocus();
187 }
188 else
189 event.Skip();
190 }