]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/ctrlcmn.cpp
Using buffered drawing won't let the themed background show through,
[wxWidgets.git] / src / common / ctrlcmn.cpp
... / ...
CommitLineData
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#endif
36
37#if wxUSE_STATBMP
38 #include "wx/bitmap.h"
39#endif // wxUSE_STATBMP
40
41const wxChar wxControlNameStr[] = wxT("control");
42
43// ============================================================================
44// implementation
45// ============================================================================
46
47wxControlBase::~wxControlBase()
48{
49 // this destructor is required for Darwin
50}
51
52bool wxControlBase::Create(wxWindow *parent,
53 wxWindowID id,
54 const wxPoint &pos,
55 const wxSize &size,
56 long style,
57 const wxValidator& wxVALIDATOR_PARAM(validator),
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
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
81 wxCHECK_MSG( parent, false, wxT("all controls must have parents") );
82
83 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
84 return false;
85
86 parent->AddChild(this);
87
88 return true;
89}
90
91void wxControlBase::Command(wxCommandEvent& event)
92{
93 (void)GetEventHandler()->ProcessEvent(event);
94}
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 {
104 case wxClientData_Void:
105 event.SetClientData(GetClientData());
106 break;
107
108 case wxClientData_Object:
109 event.SetClientObject(GetClientObject());
110 break;
111
112 case wxClientData_None:
113 // nothing to do
114 ;
115 }
116}
117
118
119void wxControlBase::SetLabel( const wxString &label )
120{
121 InvalidateBestSize();
122 wxWindow::SetLabel(label);
123}
124
125bool wxControlBase::SetFont(const wxFont& font)
126{
127 InvalidateBestSize();
128 return wxWindow::SetFont(font);
129}
130
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
157// ----------------------------------------------------------------------------
158// wxStaticBitmap
159// ----------------------------------------------------------------------------
160
161#if wxUSE_STATBMP
162
163wxStaticBitmapBase::~wxStaticBitmapBase()
164{
165 // this destructor is required for Darwin
166}
167
168wxSize wxStaticBitmapBase::DoGetBestSize() const
169{
170 wxSize best;
171 wxBitmap bmp = GetBitmap();
172 if ( bmp.Ok() )
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;
179}
180
181#endif // wxUSE_STATBMP
182
183#endif // wxUSE_CONTROLS