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