]>
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 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/control.h"
32 #include "wx/dcclient.h"
35 #include "wx/univ/renderer.h"
36 #include "wx/univ/inphand.h"
37 #include "wx/univ/theme.h"
39 // ============================================================================
41 // ============================================================================
43 IMPLEMENT_DYNAMIC_CLASS(wxControl
, wxWindow
)
45 BEGIN_EVENT_TABLE(wxControl
, wxControlBase
)
46 WX_EVENT_TABLE_INPUT_CONSUMER(wxControl
)
49 WX_FORWARD_TO_INPUT_CONSUMER(wxControl
)
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 void wxControl::Init()
59 m_inputHandler
= (wxInputHandler
*)NULL
;
62 bool wxControl::Create(wxWindow
*parent
,
67 const wxValidator
& validator
,
70 if ( !wxControlBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
72 // underlying window creation failed?
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
84 int wxControl::FindAccelIndex(const wxString
& label
, wxString
*labelOnly
)
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('&');
94 labelOnly
->Alloc(label
.length());
98 for ( const wxChar
*pc
= label
; *pc
!= wxT('\0'); pc
++ )
100 if ( *pc
== MNEMONIC_PREFIX
)
103 if ( *pc
!= MNEMONIC_PREFIX
)
105 if ( indexAccel
== -1 )
107 // remember it (-1 is for MNEMONIC_PREFIX itself
108 indexAccel
= pc
- label
.c_str() - 1;
112 wxFAIL_MSG(_T("duplicate accel char in control label"));
126 void wxControl::SetLabel(const wxString
& label
)
128 wxString labelOld
= m_label
;
129 m_indexAccel
= FindAccelIndex(label
, &m_label
);
131 if ( m_label
!= labelOld
)
137 wxString
wxControl::GetLabel() const
142 #endif // wxUSE_CONTROLS