]>
git.saurik.com Git - wxWidgets.git/blob - src/univ/control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/control.cpp
3 // Purpose: universal wxControl: adds handling of mnemonics
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma implementation "control.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 #include "wx/wxprec.h"
34 #include "wx/control.h"
35 #include "wx/dcclient.h"
38 #include "wx/univ/renderer.h"
39 #include "wx/univ/inphand.h"
40 #include "wx/univ/theme.h"
42 // ============================================================================
44 // ============================================================================
46 IMPLEMENT_DYNAMIC_CLASS(wxControl
, wxWindow
)
48 BEGIN_EVENT_TABLE(wxControl
, wxControlBase
)
49 WX_EVENT_TABLE_INPUT_CONSUMER(wxControl
)
52 WX_FORWARD_TO_INPUT_CONSUMER(wxControl
)
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 wxControl::wxControl()
63 wxControl::wxControl(wxWindow
*parent
,
68 const wxValidator
& validator
,
73 Create(parent
, id
, pos
, size
, style
, validator
, name
);
76 void wxControl::Init()
80 m_inputHandler
= (wxInputHandler
*)NULL
;
83 bool wxControl::Create(wxWindow
*parent
,
88 const wxValidator
& validator
,
91 if ( !wxControlBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
93 // underlying window creation failed?
100 // ----------------------------------------------------------------------------
101 // mnemonics handling
102 // ----------------------------------------------------------------------------
105 int wxControl::FindAccelIndex(const wxString
& label
, wxString
*labelOnly
)
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('&');
115 labelOnly
->Alloc(label
.length());
119 for ( const wxChar
*pc
= label
; *pc
!= wxT('\0'); pc
++ )
121 if ( *pc
== MNEMONIC_PREFIX
)
124 if ( *pc
!= MNEMONIC_PREFIX
)
126 if ( indexAccel
== -1 )
128 // remember it (-1 is for MNEMONIC_PREFIX itself
129 indexAccel
= pc
- label
.c_str() - 1;
133 wxFAIL_MSG(_T("duplicate accel char in control label"));
147 void wxControl::SetLabel(const wxString
& label
)
149 wxString labelOld
= m_label
;
150 m_indexAccel
= FindAccelIndex(label
, &m_label
);
152 if ( m_label
!= labelOld
)
158 wxString
wxControl::GetLabel() const
163 #endif // wxUSE_CONTROLS