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 license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
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 EVT_KEY_DOWN(wxControl::OnKeyDown
)
50 EVT_KEY_UP(wxControl::OnKeyUp
)
52 EVT_MOUSE_EVENTS(wxControl::OnMouse
)
54 EVT_SET_FOCUS(wxControl::OnFocus
)
55 EVT_KILL_FOCUS(wxControl::OnFocus
)
57 EVT_ACTIVATE(wxControl::OnActivate
)
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 void wxControl::Init()
68 m_handler
= (wxInputHandler
*)NULL
;
71 bool wxControl::Create(wxWindow
*parent
,
76 const wxValidator
& validator
,
79 // we use wxNO_FULL_REPAINT_ON_RESIZE by default as it results in much
80 // less flicker and none of the standard controls needs to be entirely
81 // repainted after resize anyhow
82 if ( !wxControlBase::Create(parent
, id
, pos
, size
,
83 style
| wxNO_FULL_REPAINT_ON_RESIZE
,
86 // underlying window creation failed?
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
98 int wxControl::FindAccelIndex(const wxString
& label
, wxString
*labelOnly
)
100 // the character following MNEMONIC_PREFIX is the accelerator for this
101 // control unless it is MNEMONIC_PREFIX too - this allows to insert
102 // literal MNEMONIC_PREFIX chars into the label
103 static const wxChar MNEMONIC_PREFIX
= _T('&');
108 labelOnly
->Alloc(label
.length());
112 for ( const wxChar
*pc
= label
; *pc
!= wxT('\0'); pc
++ )
114 if ( *pc
== MNEMONIC_PREFIX
)
117 if ( *pc
!= MNEMONIC_PREFIX
)
119 if ( indexAccel
== -1 )
121 // remember it (-1 is for MNEMONIC_PREFIX itself
122 indexAccel
= pc
- label
.c_str() - 1;
126 wxFAIL_MSG(_T("duplicate accel char in control label"));
140 void wxControl::SetLabel(const wxString
& label
)
142 wxString labelOld
= m_label
;
143 m_indexAccel
= FindAccelIndex(label
, &m_label
);
145 if ( m_label
!= labelOld
)
151 wxString
wxControl::GetLabel() const
156 // ----------------------------------------------------------------------------
157 // focus/activation handling
158 // ----------------------------------------------------------------------------
160 void wxControl::OnFocus(wxFocusEvent
& event
)
162 if ( m_handler
&& m_handler
->HandleFocus(this, event
) )
168 void wxControl::OnActivate(wxActivateEvent
& event
)
170 if ( m_handler
&& m_handler
->HandleActivation(this, event
.GetActive()) )
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 void wxControl::CreateInputHandler(const wxString
& inphandler
)
182 m_handler
= wxTheme::Get()->GetInputHandler(inphandler
);
185 void wxControl::OnKeyDown(wxKeyEvent
& event
)
187 if ( !m_handler
|| !m_handler
->HandleKey(this, event
, TRUE
) )
191 void wxControl::OnKeyUp(wxKeyEvent
& event
)
193 if ( !m_handler
|| !m_handler
->HandleKey(this, event
, FALSE
) )
197 void wxControl::OnMouse(wxMouseEvent
& event
)
201 if ( event
.Moving() || event
.Entering() || event
.Leaving() )
203 if ( m_handler
->HandleMouseMove(this, event
) )
206 else // a click action
208 if ( m_handler
->HandleMouse(this, event
) )
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 bool wxControl::PerformAction(const wxControlAction
& action
,
222 const wxString
& strArg
)
227 #endif // wxUSE_CONTROLS