]> git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlcmn.cpp
Minor cleanup
[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 // ----------------------------------------------------------------------------
128 // wxStaticBitmap
129 // ----------------------------------------------------------------------------
130
131 #if wxUSE_STATBMP
132
133 wxStaticBitmapBase::~wxStaticBitmapBase()
134 {
135 // this destructor is required for Darwin
136 }
137
138 wxSize wxStaticBitmapBase::DoGetBestSize() const
139 {
140 wxSize best;
141 wxBitmap bmp = GetBitmap();
142 if ( bmp.Ok() )
143 best = wxSize(bmp.GetWidth(), bmp.GetHeight());
144 else
145 // this is completely arbitrary
146 best = wxSize(16, 16);
147 CacheBestSize(best);
148 return best;
149 }
150
151 #endif // wxUSE_STATBMP
152
153 #endif // wxUSE_CONTROLS
154