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