]> git.saurik.com Git - wxWidgets.git/blob - src/univ/control.cpp
More RTL fixes.
[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 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_CONTROLS
27
28 #include "wx/control.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/app.h"
32 #include "wx/dcclient.h"
33 #endif
34
35 #include "wx/univ/renderer.h"
36 #include "wx/univ/inphand.h"
37 #include "wx/univ/theme.h"
38
39 // ============================================================================
40 // implementation
41 // ============================================================================
42
43 IMPLEMENT_DYNAMIC_CLASS(wxControl, wxWindow)
44
45 BEGIN_EVENT_TABLE(wxControl, wxControlBase)
46 WX_EVENT_TABLE_INPUT_CONSUMER(wxControl)
47 END_EVENT_TABLE()
48
49 WX_FORWARD_TO_INPUT_CONSUMER(wxControl)
50
51 // ----------------------------------------------------------------------------
52 // creation
53 // ----------------------------------------------------------------------------
54
55 void wxControl::Init()
56 {
57 m_indexAccel = -1;
58
59 m_inputHandler = (wxInputHandler *)NULL;
60 }
61
62 bool wxControl::Create(wxWindow *parent,
63 wxWindowID id,
64 const wxPoint& pos,
65 const wxSize& size,
66 long style,
67 const wxValidator& validator,
68 const wxString& name)
69 {
70 if ( !wxControlBase::Create(parent, id, pos, size, style, validator, name) )
71 {
72 // underlying window creation failed?
73 return false;
74 }
75
76 return true;
77 }
78
79 // ----------------------------------------------------------------------------
80 // mnemonics handling
81 // ----------------------------------------------------------------------------
82
83 /* static */
84 int wxControl::FindAccelIndex(const wxString& label, wxString *labelOnly)
85 {
86 // the character following MNEMONIC_PREFIX is the accelerator for this
87 // control unless it is MNEMONIC_PREFIX too - this allows to insert
88 // literal MNEMONIC_PREFIX chars into the label
89 static const wxChar MNEMONIC_PREFIX = _T('&');
90
91 if ( labelOnly )
92 {
93 labelOnly->Empty();
94 labelOnly->Alloc(label.length());
95 }
96
97 int indexAccel = -1;
98 for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
99 {
100 if ( *pc == MNEMONIC_PREFIX )
101 {
102 pc++; // skip it
103 if ( *pc != MNEMONIC_PREFIX )
104 {
105 if ( indexAccel == -1 )
106 {
107 // remember it (-1 is for MNEMONIC_PREFIX itself
108 indexAccel = pc - label.c_str() - 1;
109 }
110 else
111 {
112 wxFAIL_MSG(_T("duplicate accel char in control label"));
113 }
114 }
115 }
116
117 if ( labelOnly )
118 {
119 *labelOnly += *pc;
120 }
121 }
122
123 return indexAccel;
124 }
125
126 void wxControl::SetLabel(const wxString& label)
127 {
128 wxString labelOld = m_label;
129 m_indexAccel = FindAccelIndex(label, &m_label);
130
131 if ( m_label != labelOld )
132 {
133 Refresh();
134 }
135 }
136
137 wxString wxControl::GetLabel() const
138 {
139 return m_label;
140 }
141
142 #endif // wxUSE_CONTROLS