]> git.saurik.com Git - wxWidgets.git/blame - src/univ/control.cpp
made GetColourFromGTKWidget() more general, it is now used for all colours
[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{
2387541f
VZ
79 // we use wxNO_FULL_REPAINT_ON_RESIZE by default as it results in much
80 // less flicker and none of the standard controls needs to be entirely
81 // repainted after resize anyhow
82 if ( !wxControlBase::Create(parent, id, pos, size,
83 style | wxNO_FULL_REPAINT_ON_RESIZE,
84 validator, name) )
85 {
86 // underlying window creation failed?
1e6feb95 87 return FALSE;
2387541f 88 }
1e6feb95
VZ
89
90 return TRUE;
91}
92
93// ----------------------------------------------------------------------------
94// mnemonics handling
95// ----------------------------------------------------------------------------
96
97/* static */
98int wxControl::FindAccelIndex(const wxString& label, wxString *labelOnly)
99{
100 // the character following MNEMONIC_PREFIX is the accelerator for this
101 // control unless it is MNEMONIC_PREFIX too - this allows to insert
102 // literal MNEMONIC_PREFIX chars into the label
103 static const wxChar MNEMONIC_PREFIX = _T('&');
104
105 if ( labelOnly )
106 {
107 labelOnly->Empty();
108 labelOnly->Alloc(label.length());
109 }
110
111 int indexAccel = -1;
112 for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
113 {
114 if ( *pc == MNEMONIC_PREFIX )
115 {
116 pc++; // skip it
117 if ( *pc != MNEMONIC_PREFIX )
118 {
119 if ( indexAccel == -1 )
120 {
121 // remember it (-1 is for MNEMONIC_PREFIX itself
122 indexAccel = pc - label.c_str() - 1;
123 }
124 else
125 {
126 wxFAIL_MSG(_T("duplicate accel char in control label"));
127 }
128 }
129 }
130
131 if ( labelOnly )
132 {
133 *labelOnly += *pc;
134 }
135 }
136
137 return indexAccel;
138}
139
140void wxControl::SetLabel(const wxString& label)
141{
142 wxString labelOld = m_label;
143 m_indexAccel = FindAccelIndex(label, &m_label);
144
145 if ( m_label != labelOld )
146 {
147 Refresh();
148 }
149}
150
151wxString wxControl::GetLabel() const
152{
153 return m_label;
154}
155
156// ----------------------------------------------------------------------------
157// focus/activation handling
158// ----------------------------------------------------------------------------
159
160void wxControl::OnFocus(wxFocusEvent& event)
161{
162 if ( m_handler && m_handler->HandleFocus(this, event) )
163 Refresh();
164 else
165 event.Skip();
166}
167
168void wxControl::OnActivate(wxActivateEvent& event)
169{
170 if ( m_handler && m_handler->HandleActivation(this, event.GetActive()) )
171 Refresh();
172 else
173 event.Skip();
174}
175
176// ----------------------------------------------------------------------------
177// input processing
178// ----------------------------------------------------------------------------
179
180void wxControl::CreateInputHandler(const wxString& inphandler)
181{
182 m_handler = wxTheme::Get()->GetInputHandler(inphandler);
183}
184
185void wxControl::OnKeyDown(wxKeyEvent& event)
186{
187 if ( !m_handler || !m_handler->HandleKey(this, event, TRUE) )
188 event.Skip();
189}
190
191void wxControl::OnKeyUp(wxKeyEvent& event)
192{
193 if ( !m_handler || !m_handler->HandleKey(this, event, FALSE) )
194 event.Skip();
195}
196
197void wxControl::OnMouse(wxMouseEvent& event)
198{
199 if ( m_handler )
200 {
201 if ( event.Moving() || event.Entering() || event.Leaving() )
202 {
203 if ( m_handler->HandleMouseMove(this, event) )
204 return;
205 }
206 else // a click action
207 {
208 if ( m_handler->HandleMouse(this, event) )
209 return;
210 }
211 }
212
213 event.Skip();
214}
215
216// ----------------------------------------------------------------------------
217// the actions
218// ----------------------------------------------------------------------------
219
220bool wxControl::PerformAction(const wxControlAction& action,
221 long numArg,
222 const wxString& strArg)
223{
224 return FALSE;
225}
226
227#endif // wxUSE_CONTROLS