Include wx/control.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / common / ctrlcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/ctrlcmn.cpp
3 // Purpose: wxControl common interface
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 26.07.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_CONTROLS
28
29 #include "wx/control.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/log.h"
33 #include "wx/radiobut.h"
34 #endif
35
36 #if wxUSE_STATBMP
37 #include "wx/bitmap.h"
38 #include "wx/statbmp.h"
39 #endif // wxUSE_STATBMP
40
41 // ============================================================================
42 // implementation
43 // ============================================================================
44
45 wxControlBase::~wxControlBase()
46 {
47 // this destructor is required for Darwin
48 }
49
50 bool wxControlBase::Create(wxWindow *parent,
51 wxWindowID id,
52 const wxPoint &pos,
53 const wxSize &size,
54 long style,
55 const wxValidator& wxVALIDATOR_PARAM(validator),
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
68 bool 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
79 wxCHECK_MSG( parent, false, wxT("all controls must have parents") );
80
81 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
82 return false;
83
84 parent->AddChild(this);
85
86 return true;
87 }
88
89 void wxControlBase::Command(wxCommandEvent& event)
90 {
91 (void)GetEventHandler()->ProcessEvent(event);
92 }
93
94 void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
95 {
96 event.SetEventObject((wxControlBase *)this); // const_cast
97
98 // event.SetId(GetId()); -- this is usuall done in the event ctor
99
100 switch ( m_clientDataType )
101 {
102 case wxClientData_Void:
103 event.SetClientData(GetClientData());
104 break;
105
106 case wxClientData_Object:
107 event.SetClientObject(GetClientObject());
108 break;
109
110 case wxClientData_None:
111 // nothing to do
112 ;
113 }
114 }
115
116
117 void wxControlBase::SetLabel( const wxString &label )
118 {
119 InvalidateBestSize();
120 wxWindow::SetLabel(label);
121 }
122
123 bool wxControlBase::SetFont(const wxFont& font)
124 {
125 InvalidateBestSize();
126 return wxWindow::SetFont(font);
127 }
128
129 // wxControl-specific processing after processing the update event
130 void 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
155 // ----------------------------------------------------------------------------
156 // wxStaticBitmap
157 // ----------------------------------------------------------------------------
158
159 #if wxUSE_STATBMP
160
161 wxStaticBitmapBase::~wxStaticBitmapBase()
162 {
163 // this destructor is required for Darwin
164 }
165
166 wxSize wxStaticBitmapBase::DoGetBestSize() const
167 {
168 wxSize best;
169 wxBitmap bmp = GetBitmap();
170 if ( bmp.Ok() )
171 best = wxSize(bmp.GetWidth(), bmp.GetHeight());
172 else
173 // this is completely arbitrary
174 best = wxSize(16, 16);
175 CacheBestSize(best);
176 return best;
177 }
178
179 #endif // wxUSE_STATBMP
180
181 #endif // wxUSE_CONTROLS