]> git.saurik.com Git - wxWidgets.git/blame - src/univ/control.cpp
adding protected inquiry function whether a child window belongs to the 'client'...
[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)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
14f355c2 16#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
1e6feb95
VZ
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)
23645bfa 49 WX_EVENT_TABLE_INPUT_CONSUMER(wxControl)
1e6feb95
VZ
50END_EVENT_TABLE()
51
23645bfa
VS
52WX_FORWARD_TO_INPUT_CONSUMER(wxControl)
53
1e6feb95
VZ
54// ----------------------------------------------------------------------------
55// creation
56// ----------------------------------------------------------------------------
57
58void wxControl::Init()
59{
60 m_indexAccel = -1;
61
23645bfa 62 m_inputHandler = (wxInputHandler *)NULL;
1e6feb95
VZ
63}
64
65bool wxControl::Create(wxWindow *parent,
66 wxWindowID id,
67 const wxPoint& pos,
68 const wxSize& size,
69 long style,
70 const wxValidator& validator,
71 const wxString& name)
72{
e441e1f4 73 if ( !wxControlBase::Create(parent, id, pos, size, style, validator, name) )
2387541f
VZ
74 {
75 // underlying window creation failed?
a290fa5a 76 return false;
2387541f 77 }
1e6feb95 78
a290fa5a 79 return true;
1e6feb95
VZ
80}
81
82// ----------------------------------------------------------------------------
83// mnemonics handling
84// ----------------------------------------------------------------------------
85
86/* static */
87int wxControl::FindAccelIndex(const wxString& label, wxString *labelOnly)
88{
89 // the character following MNEMONIC_PREFIX is the accelerator for this
90 // control unless it is MNEMONIC_PREFIX too - this allows to insert
91 // literal MNEMONIC_PREFIX chars into the label
92 static const wxChar MNEMONIC_PREFIX = _T('&');
93
94 if ( labelOnly )
95 {
96 labelOnly->Empty();
97 labelOnly->Alloc(label.length());
98 }
99
100 int indexAccel = -1;
101 for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
102 {
103 if ( *pc == MNEMONIC_PREFIX )
104 {
105 pc++; // skip it
106 if ( *pc != MNEMONIC_PREFIX )
107 {
108 if ( indexAccel == -1 )
109 {
110 // remember it (-1 is for MNEMONIC_PREFIX itself
111 indexAccel = pc - label.c_str() - 1;
112 }
113 else
114 {
115 wxFAIL_MSG(_T("duplicate accel char in control label"));
116 }
117 }
118 }
119
120 if ( labelOnly )
121 {
122 *labelOnly += *pc;
123 }
124 }
125
126 return indexAccel;
127}
128
129void wxControl::SetLabel(const wxString& label)
130{
131 wxString labelOld = m_label;
132 m_indexAccel = FindAccelIndex(label, &m_label);
133
134 if ( m_label != labelOld )
135 {
136 Refresh();
137 }
138}
139
140wxString wxControl::GetLabel() const
141{
142 return m_label;
143}
144
1e6feb95 145#endif // wxUSE_CONTROLS