Include wx/bitmap.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 #include "wx/statbmp.h"
35 #include "wx/bitmap.h"
36 #endif
37
38 const wxChar wxControlNameStr[] = wxT("control");
39
40 // ============================================================================
41 // implementation
42 // ============================================================================
43
44 wxControlBase::~wxControlBase()
45 {
46 // this destructor is required for Darwin
47 }
48
49 bool wxControlBase::Create(wxWindow *parent,
50 wxWindowID id,
51 const wxPoint &pos,
52 const wxSize &size,
53 long style,
54 const wxValidator& wxVALIDATOR_PARAM(validator),
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
67 bool 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
78 wxCHECK_MSG( parent, false, wxT("all controls must have parents") );
79
80 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
81 return false;
82
83 parent->AddChild(this);
84
85 return true;
86 }
87
88 void wxControlBase::Command(wxCommandEvent& event)
89 {
90 (void)GetEventHandler()->ProcessEvent(event);
91 }
92
93 void 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 {
101 case wxClientData_Void:
102 event.SetClientData(GetClientData());
103 break;
104
105 case wxClientData_Object:
106 event.SetClientObject(GetClientObject());
107 break;
108
109 case wxClientData_None:
110 // nothing to do
111 ;
112 }
113 }
114
115
116 void wxControlBase::SetLabel( const wxString &label )
117 {
118 InvalidateBestSize();
119 wxWindow::SetLabel(label);
120 }
121
122 bool wxControlBase::SetFont(const wxFont& font)
123 {
124 InvalidateBestSize();
125 return wxWindow::SetFont(font);
126 }
127
128 // wxControl-specific processing after processing the update event
129 void 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
154 // ----------------------------------------------------------------------------
155 // wxStaticBitmap
156 // ----------------------------------------------------------------------------
157
158 #if wxUSE_STATBMP
159
160 wxStaticBitmapBase::~wxStaticBitmapBase()
161 {
162 // this destructor is required for Darwin
163 }
164
165 wxSize wxStaticBitmapBase::DoGetBestSize() const
166 {
167 wxSize best;
168 wxBitmap bmp = GetBitmap();
169 if ( bmp.Ok() )
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;
176 }
177
178 #endif // wxUSE_STATBMP
179
180 #endif // wxUSE_CONTROLS