]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlcmn.cpp
Minor source cleaning.
[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
2d61b48d
VZ
29#ifndef WX_PRECOMP
30 #include "wx/control.h"
31 #include "wx/log.h"
0e2d2986 32 #include "wx/radiobut.h"
2d61b48d
VZ
33#endif
34
1e6feb95
VZ
35#if wxUSE_STATBMP
36 #include "wx/bitmap.h"
37 #include "wx/statbmp.h"
38#endif // wxUSE_STATBMP
39
2d61b48d
VZ
40// ============================================================================
41// implementation
42// ============================================================================
43
799ea011
GD
44wxControlBase::~wxControlBase()
45{
46 // this destructor is required for Darwin
47}
48
1e6feb95
VZ
49bool wxControlBase::Create(wxWindow *parent,
50 wxWindowID id,
51 const wxPoint &pos,
52 const wxSize &size,
53 long style,
ac8d0c11 54 const wxValidator& wxVALIDATOR_PARAM(validator),
1e6feb95
VZ
55 const wxString &name)
56{
57 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
58
59#if wxUSE_VALIDATORS
60 if ( ret )
61 SetValidator(validator);
62#endif // wxUSE_VALIDATORS
63
64 return ret;
65}
66
2d61b48d
VZ
67bool wxControlBase::CreateControl(wxWindowBase *parent,
68 wxWindowID id,
69 const wxPoint& pos,
70 const wxSize& size,
71 long style,
72 const wxValidator& validator,
73 const wxString& name)
74{
75 // even if it's possible to create controls without parents in some port,
76 // it should surely be discouraged because it doesn't work at all under
77 // Windows
c9d59ee7 78 wxCHECK_MSG( parent, false, wxT("all controls must have parents") );
2d61b48d
VZ
79
80 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
c9d59ee7 81 return false;
2d61b48d
VZ
82
83 parent->AddChild(this);
84
c9d59ee7 85 return true;
2d61b48d
VZ
86}
87
2d61b48d
VZ
88void wxControlBase::Command(wxCommandEvent& event)
89{
bfbd6dc1 90 (void)GetEventHandler()->ProcessEvent(event);
2d61b48d 91}
bfbd6dc1
VZ
92
93void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
94{
95 event.SetEventObject((wxControlBase *)this); // const_cast
96
97 // event.SetId(GetId()); -- this is usuall done in the event ctor
98
99 switch ( m_clientDataType )
100 {
1e6feb95 101 case wxClientData_Void:
bfbd6dc1
VZ
102 event.SetClientData(GetClientData());
103 break;
104
1e6feb95 105 case wxClientData_Object:
bfbd6dc1
VZ
106 event.SetClientObject(GetClientObject());
107 break;
108
1e6feb95 109 case wxClientData_None:
bfbd6dc1
VZ
110 // nothing to do
111 ;
112 }
113}
114
9f884528
RD
115
116void wxControlBase::SetLabel( const wxString &label )
117{
118 InvalidateBestSize();
c9d59ee7 119 wxWindow::SetLabel(label);
9f884528
RD
120}
121
122bool wxControlBase::SetFont(const wxFont& font)
123{
124 InvalidateBestSize();
125 return wxWindow::SetFont(font);
126}
127
a3a4105d
VZ
128// wxControl-specific processing after processing the update event
129void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
130{
131 // call inherited
132 wxWindowBase::DoUpdateWindowUI(event);
133
134 // update label
135 if ( event.GetSetText() )
136 {
137 if ( event.GetText() != GetLabel() )
138 SetLabel(event.GetText());
139 }
140
141 // Unfortunately we don't yet have common base class for
142 // wxRadioButton, so we handle updates of radiobuttons here.
143 // TODO: If once wxRadioButtonBase will exist, move this code there.
144#if wxUSE_RADIOBTN
145 if ( event.GetSetChecked() )
146 {
147 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
148 if ( radiobtn )
149 radiobtn->SetValue(event.GetChecked());
150 }
151#endif // wxUSE_RADIOBTN
152}
153
1e6feb95
VZ
154// ----------------------------------------------------------------------------
155// wxStaticBitmap
156// ----------------------------------------------------------------------------
157
158#if wxUSE_STATBMP
159
799ea011
GD
160wxStaticBitmapBase::~wxStaticBitmapBase()
161{
162 // this destructor is required for Darwin
163}
164
b3fcfa4d 165wxSize wxStaticBitmapBase::DoGetBestSize() const
1e6feb95 166{
9f884528 167 wxSize best;
1e6feb95
VZ
168 wxBitmap bmp = GetBitmap();
169 if ( bmp.Ok() )
9f884528
RD
170 best = wxSize(bmp.GetWidth(), bmp.GetHeight());
171 else
172 // this is completely arbitrary
173 best = wxSize(16, 16);
174 CacheBestSize(best);
175 return best;
1e6feb95
VZ
176}
177
178#endif // wxUSE_STATBMP
179
180#endif // wxUSE_CONTROLS