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