]> git.saurik.com Git - wxWidgets.git/blob - src/univ/control.cpp
reSWIGged
[wxWidgets.git] / src / univ / control.cpp
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$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
46 IMPLEMENT_DYNAMIC_CLASS(wxControl, wxWindow)
47
48 BEGIN_EVENT_TABLE(wxControl, wxControlBase)
49 WX_EVENT_TABLE_INPUT_CONSUMER(wxControl)
50 END_EVENT_TABLE()
51
52 WX_FORWARD_TO_INPUT_CONSUMER(wxControl)
53
54 // ----------------------------------------------------------------------------
55 // creation
56 // ----------------------------------------------------------------------------
57
58 wxControl::wxControl()
59 {
60 Init();
61 }
62
63 wxControl::wxControl(wxWindow *parent,
64 wxWindowID id,
65 const wxPoint& pos,
66 const wxSize& size,
67 long style,
68 const wxValidator& validator,
69 const wxString& name)
70 {
71 Init();
72
73 Create(parent, id, pos, size, style, validator, name);
74 }
75
76 void wxControl::Init()
77 {
78 m_indexAccel = -1;
79
80 m_inputHandler = (wxInputHandler *)NULL;
81 }
82
83 bool wxControl::Create(wxWindow *parent,
84 wxWindowID id,
85 const wxPoint& pos,
86 const wxSize& size,
87 long style,
88 const wxValidator& validator,
89 const wxString& name)
90 {
91 if ( !wxControlBase::Create(parent, id, pos, size, style, validator, name) )
92 {
93 // underlying window creation failed?
94 return FALSE;
95 }
96
97 return TRUE;
98 }
99
100 // ----------------------------------------------------------------------------
101 // mnemonics handling
102 // ----------------------------------------------------------------------------
103
104 /* static */
105 int wxControl::FindAccelIndex(const wxString& label, wxString *labelOnly)
106 {
107 // the character following MNEMONIC_PREFIX is the accelerator for this
108 // control unless it is MNEMONIC_PREFIX too - this allows to insert
109 // literal MNEMONIC_PREFIX chars into the label
110 static const wxChar MNEMONIC_PREFIX = _T('&');
111
112 if ( labelOnly )
113 {
114 labelOnly->Empty();
115 labelOnly->Alloc(label.length());
116 }
117
118 int indexAccel = -1;
119 for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
120 {
121 if ( *pc == MNEMONIC_PREFIX )
122 {
123 pc++; // skip it
124 if ( *pc != MNEMONIC_PREFIX )
125 {
126 if ( indexAccel == -1 )
127 {
128 // remember it (-1 is for MNEMONIC_PREFIX itself
129 indexAccel = pc - label.c_str() - 1;
130 }
131 else
132 {
133 wxFAIL_MSG(_T("duplicate accel char in control label"));
134 }
135 }
136 }
137
138 if ( labelOnly )
139 {
140 *labelOnly += *pc;
141 }
142 }
143
144 return indexAccel;
145 }
146
147 void wxControl::SetLabel(const wxString& label)
148 {
149 wxString labelOld = m_label;
150 m_indexAccel = FindAccelIndex(label, &m_label);
151
152 if ( m_label != labelOld )
153 {
154 Refresh();
155 }
156 }
157
158 wxString wxControl::GetLabel() const
159 {
160 return m_label;
161 }
162
163 #endif // wxUSE_CONTROLS