]> git.saurik.com Git - wxWidgets.git/blame - src/univ/control.cpp
Separated wxImage::FloodFill from image.cpp
[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)
1e6feb95
VZ
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16#ifdef __GNUG__
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{
5268c5a3 73 // Ee use wxNO_FULL_REPAINT_ON_RESIZE by default as it results in much
2387541f 74 // less flicker and none of the standard controls needs to be entirely
5268c5a3 75 // repainted after resize anyhow.
2387541f 76 if ( !wxControlBase::Create(parent, id, pos, size,
ec47a147 77 style | wxNO_FULL_REPAINT_ON_RESIZE ,
2387541f
VZ
78 validator, name) )
79 {
80 // underlying window creation failed?
1e6feb95 81 return FALSE;
2387541f 82 }
1e6feb95
VZ
83
84 return TRUE;
85}
86
87// ----------------------------------------------------------------------------
88// mnemonics handling
89// ----------------------------------------------------------------------------
90
91/* static */
92int wxControl::FindAccelIndex(const wxString& label, wxString *labelOnly)
93{
94 // the character following MNEMONIC_PREFIX is the accelerator for this
95 // control unless it is MNEMONIC_PREFIX too - this allows to insert
96 // literal MNEMONIC_PREFIX chars into the label
97 static const wxChar MNEMONIC_PREFIX = _T('&');
98
99 if ( labelOnly )
100 {
101 labelOnly->Empty();
102 labelOnly->Alloc(label.length());
103 }
104
105 int indexAccel = -1;
106 for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
107 {
108 if ( *pc == MNEMONIC_PREFIX )
109 {
110 pc++; // skip it
111 if ( *pc != MNEMONIC_PREFIX )
112 {
113 if ( indexAccel == -1 )
114 {
115 // remember it (-1 is for MNEMONIC_PREFIX itself
116 indexAccel = pc - label.c_str() - 1;
117 }
118 else
119 {
120 wxFAIL_MSG(_T("duplicate accel char in control label"));
121 }
122 }
123 }
124
125 if ( labelOnly )
126 {
127 *labelOnly += *pc;
128 }
129 }
130
131 return indexAccel;
132}
133
134void wxControl::SetLabel(const wxString& label)
135{
136 wxString labelOld = m_label;
137 m_indexAccel = FindAccelIndex(label, &m_label);
138
139 if ( m_label != labelOld )
140 {
141 Refresh();
142 }
143}
144
145wxString wxControl::GetLabel() const
146{
147 return m_label;
148}
149
1e6feb95 150#endif // wxUSE_CONTROLS