]> git.saurik.com Git - wxWidgets.git/blame - src/univ/control.cpp
renamed wxDynamicThisCast to wxDynamicCastThis, removed 1st parameter, and documented
[wxWidgets.git] / src / univ / control.cpp
CommitLineData
1e6feb95
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/univ/control.cpp
3// Purpose: universal wxControl: adds handling of mnemonics
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 14.08.00
7// RCS-ID: $Id$
442b35b5 8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
1e6feb95
VZ
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16#ifdef __GNUG__
17 #pragma implementation "control.h"
18#endif
19
20// ----------------------------------------------------------------------------
21// headers
22// ----------------------------------------------------------------------------
23
24#include "wx/wxprec.h"
25
26#ifdef __BORLANDC__
27 #pragma hdrstop
28#endif
29
30#if wxUSE_CONTROLS
31
32#ifndef WX_PRECOMP
33 #include "wx/app.h"
34 #include "wx/control.h"
35 #include "wx/dcclient.h"
36#endif
37
38#include "wx/univ/renderer.h"
39#include "wx/univ/inphand.h"
40#include "wx/univ/theme.h"
41
42// ============================================================================
43// implementation
44// ============================================================================
45
46IMPLEMENT_DYNAMIC_CLASS(wxControl, wxWindow)
47
48BEGIN_EVENT_TABLE(wxControl, wxControlBase)
49 EVT_KEY_DOWN(wxControl::OnKeyDown)
50 EVT_KEY_UP(wxControl::OnKeyUp)
51
52 EVT_MOUSE_EVENTS(wxControl::OnMouse)
53
54 EVT_SET_FOCUS(wxControl::OnFocus)
55 EVT_KILL_FOCUS(wxControl::OnFocus)
56
57 EVT_ACTIVATE(wxControl::OnActivate)
58END_EVENT_TABLE()
59
60// ----------------------------------------------------------------------------
61// creation
62// ----------------------------------------------------------------------------
63
64void wxControl::Init()
65{
66 m_indexAccel = -1;
67
68 m_handler = (wxInputHandler *)NULL;
69}
70
71bool wxControl::Create(wxWindow *parent,
72 wxWindowID id,
73 const wxPoint& pos,
74 const wxSize& size,
75 long style,
76 const wxValidator& validator,
77 const wxString& name)
78{
79 if ( !wxControlBase::Create(parent, id, pos, size, style, validator, name) )
80 return FALSE;
81
82 return TRUE;
83}
84
85// ----------------------------------------------------------------------------
86// mnemonics handling
87// ----------------------------------------------------------------------------
88
89/* static */
90int wxControl::FindAccelIndex(const wxString& label, wxString *labelOnly)
91{
92 // the character following MNEMONIC_PREFIX is the accelerator for this
93 // control unless it is MNEMONIC_PREFIX too - this allows to insert
94 // literal MNEMONIC_PREFIX chars into the label
95 static const wxChar MNEMONIC_PREFIX = _T('&');
96
97 if ( labelOnly )
98 {
99 labelOnly->Empty();
100 labelOnly->Alloc(label.length());
101 }
102
103 int indexAccel = -1;
104 for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
105 {
106 if ( *pc == MNEMONIC_PREFIX )
107 {
108 pc++; // skip it
109 if ( *pc != MNEMONIC_PREFIX )
110 {
111 if ( indexAccel == -1 )
112 {
113 // remember it (-1 is for MNEMONIC_PREFIX itself
114 indexAccel = pc - label.c_str() - 1;
115 }
116 else
117 {
118 wxFAIL_MSG(_T("duplicate accel char in control label"));
119 }
120 }
121 }
122
123 if ( labelOnly )
124 {
125 *labelOnly += *pc;
126 }
127 }
128
129 return indexAccel;
130}
131
132void wxControl::SetLabel(const wxString& label)
133{
134 wxString labelOld = m_label;
135 m_indexAccel = FindAccelIndex(label, &m_label);
136
137 if ( m_label != labelOld )
138 {
139 Refresh();
140 }
141}
142
143wxString wxControl::GetLabel() const
144{
145 return m_label;
146}
147
148// ----------------------------------------------------------------------------
149// focus/activation handling
150// ----------------------------------------------------------------------------
151
152void wxControl::OnFocus(wxFocusEvent& event)
153{
154 if ( m_handler && m_handler->HandleFocus(this, event) )
155 Refresh();
156 else
157 event.Skip();
158}
159
160void wxControl::OnActivate(wxActivateEvent& event)
161{
162 if ( m_handler && m_handler->HandleActivation(this, event.GetActive()) )
163 Refresh();
164 else
165 event.Skip();
166}
167
168// ----------------------------------------------------------------------------
169// input processing
170// ----------------------------------------------------------------------------
171
172void wxControl::CreateInputHandler(const wxString& inphandler)
173{
174 m_handler = wxTheme::Get()->GetInputHandler(inphandler);
175}
176
177void wxControl::OnKeyDown(wxKeyEvent& event)
178{
179 if ( !m_handler || !m_handler->HandleKey(this, event, TRUE) )
180 event.Skip();
181}
182
183void wxControl::OnKeyUp(wxKeyEvent& event)
184{
185 if ( !m_handler || !m_handler->HandleKey(this, event, FALSE) )
186 event.Skip();
187}
188
189void wxControl::OnMouse(wxMouseEvent& event)
190{
191 if ( m_handler )
192 {
193 if ( event.Moving() || event.Entering() || event.Leaving() )
194 {
195 if ( m_handler->HandleMouseMove(this, event) )
196 return;
197 }
198 else // a click action
199 {
200 if ( m_handler->HandleMouse(this, event) )
201 return;
202 }
203 }
204
205 event.Skip();
206}
207
208// ----------------------------------------------------------------------------
209// the actions
210// ----------------------------------------------------------------------------
211
212bool wxControl::PerformAction(const wxControlAction& action,
213 long numArg,
214 const wxString& strArg)
215{
216 return FALSE;
217}
218
219#endif // wxUSE_CONTROLS