]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlcmn.cpp
mac cleanup, pure cgcolor
[wxWidgets.git] / src / common / ctrlcmn.cpp
CommitLineData
2d61b48d 1/////////////////////////////////////////////////////////////////////////////
0e2d2986 2// Name: src/common/ctrlcmn.cpp
2d61b48d
VZ
3// Purpose: wxControl common interface
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 26.07.99
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
2d61b48d
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2d61b48d
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
1e6feb95
VZ
27#if wxUSE_CONTROLS
28
93fbbe07
WS
29#include "wx/control.h"
30
2d61b48d 31#ifndef WX_PRECOMP
2d61b48d 32 #include "wx/log.h"
0e2d2986 33 #include "wx/radiobut.h"
e267406e 34 #include "wx/statbmp.h"
1e6feb95 35 #include "wx/bitmap.h"
74639764 36 #include "wx/utils.h" // for wxStripMenuCodes()
0bca0373 37#endif
1e6feb95 38
f36e602b 39const char wxControlNameStr[] = "control";
e7445ff8 40
2d61b48d
VZ
41// ============================================================================
42// implementation
43// ============================================================================
44
799ea011
GD
45wxControlBase::~wxControlBase()
46{
47 // this destructor is required for Darwin
48}
49
1e6feb95
VZ
50bool wxControlBase::Create(wxWindow *parent,
51 wxWindowID id,
52 const wxPoint &pos,
53 const wxSize &size,
54 long style,
ac8d0c11 55 const wxValidator& wxVALIDATOR_PARAM(validator),
1e6feb95
VZ
56 const wxString &name)
57{
58 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
59
60#if wxUSE_VALIDATORS
61 if ( ret )
62 SetValidator(validator);
63#endif // wxUSE_VALIDATORS
64
65 return ret;
66}
67
2d61b48d
VZ
68bool wxControlBase::CreateControl(wxWindowBase *parent,
69 wxWindowID id,
70 const wxPoint& pos,
71 const wxSize& size,
72 long style,
73 const wxValidator& validator,
74 const wxString& name)
75{
76 // even if it's possible to create controls without parents in some port,
77 // it should surely be discouraged because it doesn't work at all under
78 // Windows
c9d59ee7 79 wxCHECK_MSG( parent, false, wxT("all controls must have parents") );
2d61b48d
VZ
80
81 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
c9d59ee7 82 return false;
2d61b48d
VZ
83
84 parent->AddChild(this);
85
c9d59ee7 86 return true;
2d61b48d
VZ
87}
88
74639764
VZ
89/* static */
90wxString wxControlBase::GetLabelText(const wxString& label)
91{
92 // we don't want strip the TABs here, just the mnemonics
93 return wxStripMenuCodes(label, wxStrip_Mnemonics);
94}
95
2d61b48d
VZ
96void wxControlBase::Command(wxCommandEvent& event)
97{
bfbd6dc1 98 (void)GetEventHandler()->ProcessEvent(event);
2d61b48d 99}
bfbd6dc1
VZ
100
101void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
102{
103 event.SetEventObject((wxControlBase *)this); // const_cast
104
105 // event.SetId(GetId()); -- this is usuall done in the event ctor
106
107 switch ( m_clientDataType )
108 {
1e6feb95 109 case wxClientData_Void:
bfbd6dc1
VZ
110 event.SetClientData(GetClientData());
111 break;
112
1e6feb95 113 case wxClientData_Object:
bfbd6dc1
VZ
114 event.SetClientObject(GetClientObject());
115 break;
116
1e6feb95 117 case wxClientData_None:
bfbd6dc1
VZ
118 // nothing to do
119 ;
120 }
121}
122
9f884528
RD
123bool wxControlBase::SetFont(const wxFont& font)
124{
125 InvalidateBestSize();
126 return wxWindow::SetFont(font);
127}
128
a3a4105d
VZ
129// wxControl-specific processing after processing the update event
130void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
131{
132 // call inherited
133 wxWindowBase::DoUpdateWindowUI(event);
134
135 // update label
136 if ( event.GetSetText() )
137 {
138 if ( event.GetText() != GetLabel() )
139 SetLabel(event.GetText());
140 }
141
142 // Unfortunately we don't yet have common base class for
143 // wxRadioButton, so we handle updates of radiobuttons here.
144 // TODO: If once wxRadioButtonBase will exist, move this code there.
145#if wxUSE_RADIOBTN
146 if ( event.GetSetChecked() )
147 {
148 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
149 if ( radiobtn )
150 radiobtn->SetValue(event.GetChecked());
151 }
152#endif // wxUSE_RADIOBTN
153}
154
39bc0347
VZ
155/* static */
156wxString wxControlBase::RemoveMnemonics(const wxString& str)
157{
158 return wxStripMenuCodes(str, wxStrip_Mnemonics);
159}
160
dc797d8e
JS
161wxBorder wxControlBase::GetDefaultBorder() const
162{
163 return wxBORDER_THEME;
164}
165
166
1e6feb95
VZ
167// ----------------------------------------------------------------------------
168// wxStaticBitmap
169// ----------------------------------------------------------------------------
170
171#if wxUSE_STATBMP
172
799ea011
GD
173wxStaticBitmapBase::~wxStaticBitmapBase()
174{
175 // this destructor is required for Darwin
176}
177
b3fcfa4d 178wxSize wxStaticBitmapBase::DoGetBestSize() const
1e6feb95 179{
9f884528 180 wxSize best;
1e6feb95
VZ
181 wxBitmap bmp = GetBitmap();
182 if ( bmp.Ok() )
9f884528
RD
183 best = wxSize(bmp.GetWidth(), bmp.GetHeight());
184 else
185 // this is completely arbitrary
186 best = wxSize(16, 16);
187 CacheBestSize(best);
188 return best;
1e6feb95
VZ
189}
190
191#endif // wxUSE_STATBMP
192
193#endif // wxUSE_CONTROLS