]> git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlcmn.cpp
fix printf() argument type in GetOsInfo()
[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 #include "wx/utils.h" // for wxStripMenuCodes()
37 #endif
38
39 const wxChar wxControlNameStr[] = wxT("control");
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 /* static */
90 wxString 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
96 void wxControlBase::Command(wxCommandEvent& event)
97 {
98 (void)GetEventHandler()->ProcessEvent(event);
99 }
100
101 void 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 {
109 case wxClientData_Void:
110 event.SetClientData(GetClientData());
111 break;
112
113 case wxClientData_Object:
114 event.SetClientObject(GetClientObject());
115 break;
116
117 case wxClientData_None:
118 // nothing to do
119 ;
120 }
121 }
122
123
124 void wxControlBase::SetLabel( const wxString &label )
125 {
126 InvalidateBestSize();
127 wxWindow::SetLabel(label);
128 }
129
130 bool wxControlBase::SetFont(const wxFont& font)
131 {
132 InvalidateBestSize();
133 return wxWindow::SetFont(font);
134 }
135
136 // wxControl-specific processing after processing the update event
137 void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
138 {
139 // call inherited
140 wxWindowBase::DoUpdateWindowUI(event);
141
142 // update label
143 if ( event.GetSetText() )
144 {
145 if ( event.GetText() != GetLabel() )
146 SetLabel(event.GetText());
147 }
148
149 // Unfortunately we don't yet have common base class for
150 // wxRadioButton, so we handle updates of radiobuttons here.
151 // TODO: If once wxRadioButtonBase will exist, move this code there.
152 #if wxUSE_RADIOBTN
153 if ( event.GetSetChecked() )
154 {
155 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
156 if ( radiobtn )
157 radiobtn->SetValue(event.GetChecked());
158 }
159 #endif // wxUSE_RADIOBTN
160 }
161
162 // ----------------------------------------------------------------------------
163 // wxStaticBitmap
164 // ----------------------------------------------------------------------------
165
166 #if wxUSE_STATBMP
167
168 wxStaticBitmapBase::~wxStaticBitmapBase()
169 {
170 // this destructor is required for Darwin
171 }
172
173 wxSize wxStaticBitmapBase::DoGetBestSize() const
174 {
175 wxSize best;
176 wxBitmap bmp = GetBitmap();
177 if ( bmp.Ok() )
178 best = wxSize(bmp.GetWidth(), bmp.GetHeight());
179 else
180 // this is completely arbitrary
181 best = wxSize(16, 16);
182 CacheBestSize(best);
183 return best;
184 }
185
186 #endif // wxUSE_STATBMP
187
188 #endif // wxUSE_CONTROLS