]>
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 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 if ( !wxControlBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
90 int wxControl::FindAccelIndex(const wxString
& label
, wxString
*labelOnly
)
92 // the character following MNEMONIC_PREFIX is the accelerator for this
93 // control unless it is MNEMONIC_PREFIX too - this allows to insert
94 // literal MNEMONIC_PREFIX chars into the label
95 static const wxChar MNEMONIC_PREFIX
= _T('&');
100 labelOnly
->Alloc(label
.length());
104 for ( const wxChar
*pc
= label
; *pc
!= wxT('\0'); pc
++ )
106 if ( *pc
== MNEMONIC_PREFIX
)
109 if ( *pc
!= MNEMONIC_PREFIX
)
111 if ( indexAccel
== -1 )
113 // remember it (-1 is for MNEMONIC_PREFIX itself
114 indexAccel
= pc
- label
.c_str() - 1;
118 wxFAIL_MSG(_T("duplicate accel char in control label"));
132 void wxControl::SetLabel(const wxString
& label
)
134 wxString labelOld
= m_label
;
135 m_indexAccel
= FindAccelIndex(label
, &m_label
);
137 if ( m_label
!= labelOld
)
143 wxString
wxControl::GetLabel() const
148 // ----------------------------------------------------------------------------
149 // focus/activation handling
150 // ----------------------------------------------------------------------------
152 void wxControl::OnFocus(wxFocusEvent
& event
)
154 if ( m_handler
&& m_handler
->HandleFocus(this, event
) )
160 void wxControl::OnActivate(wxActivateEvent
& event
)
162 if ( m_handler
&& m_handler
->HandleActivation(this, event
.GetActive()) )
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 void wxControl::CreateInputHandler(const wxString
& inphandler
)
174 m_handler
= wxTheme::Get()->GetInputHandler(inphandler
);
177 void wxControl::OnKeyDown(wxKeyEvent
& event
)
179 if ( !m_handler
|| !m_handler
->HandleKey(this, event
, TRUE
) )
183 void wxControl::OnKeyUp(wxKeyEvent
& event
)
185 if ( !m_handler
|| !m_handler
->HandleKey(this, event
, FALSE
) )
189 void wxControl::OnMouse(wxMouseEvent
& event
)
193 if ( event
.Moving() || event
.Entering() || event
.Leaving() )
195 if ( m_handler
->HandleMouseMove(this, event
) )
198 else // a click action
200 if ( m_handler
->HandleMouse(this, event
) )
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 bool wxControl::PerformAction(const wxControlAction
& action
,
214 const wxString
& strArg
)
219 #endif // wxUSE_CONTROLS