]>
Commit | Line | Data |
---|---|---|
2d61b48d VZ |
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$ | |
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 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
1b68e0b5 | 21 | #pragma implementation "controlbase.h" |
1e6feb95 | 22 | #pragma implementation "statbmpbase.h" |
2d61b48d VZ |
23 | #endif |
24 | ||
25 | // For compilers that support precompilation, includes "wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
29 | #pragma hdrstop | |
30 | #endif | |
31 | ||
1e6feb95 VZ |
32 | #if wxUSE_CONTROLS |
33 | ||
2d61b48d VZ |
34 | #ifndef WX_PRECOMP |
35 | #include "wx/control.h" | |
36 | #include "wx/log.h" | |
37 | #endif | |
38 | ||
1e6feb95 VZ |
39 | #if wxUSE_STATBMP |
40 | #include "wx/bitmap.h" | |
41 | #include "wx/statbmp.h" | |
42 | #endif // wxUSE_STATBMP | |
43 | ||
2d61b48d VZ |
44 | // ============================================================================ |
45 | // implementation | |
46 | // ============================================================================ | |
47 | ||
799ea011 GD |
48 | wxControlBase::~wxControlBase() |
49 | { | |
50 | // this destructor is required for Darwin | |
51 | } | |
52 | ||
1e6feb95 VZ |
53 | bool wxControlBase::Create(wxWindow *parent, |
54 | wxWindowID id, | |
55 | const wxPoint &pos, | |
56 | const wxSize &size, | |
57 | long style, | |
ac8d0c11 | 58 | const wxValidator& wxVALIDATOR_PARAM(validator), |
1e6feb95 VZ |
59 | const wxString &name) |
60 | { | |
61 | bool ret = wxWindow::Create(parent, id, pos, size, style, name); | |
62 | ||
63 | #if wxUSE_VALIDATORS | |
64 | if ( ret ) | |
65 | SetValidator(validator); | |
66 | #endif // wxUSE_VALIDATORS | |
67 | ||
68 | return ret; | |
69 | } | |
70 | ||
fe161a26 RD |
71 | |
72 | void wxControlBase::Init() | |
73 | { | |
74 | m_adjustMinSize = true; | |
75 | } | |
76 | ||
77 | ||
2d61b48d VZ |
78 | bool wxControlBase::CreateControl(wxWindowBase *parent, |
79 | wxWindowID id, | |
80 | const wxPoint& pos, | |
81 | const wxSize& size, | |
82 | long style, | |
83 | const wxValidator& validator, | |
84 | const wxString& name) | |
85 | { | |
86 | // even if it's possible to create controls without parents in some port, | |
87 | // it should surely be discouraged because it doesn't work at all under | |
88 | // Windows | |
223d09f6 | 89 | wxCHECK_MSG( parent, FALSE, wxT("all controls must have parents") ); |
2d61b48d VZ |
90 | |
91 | if ( !CreateBase(parent, id, pos, size, style, validator, name) ) | |
92 | return FALSE; | |
93 | ||
94 | parent->AddChild(this); | |
95 | ||
96 | return TRUE; | |
97 | } | |
98 | ||
2d61b48d VZ |
99 | void wxControlBase::Command(wxCommandEvent& event) |
100 | { | |
bfbd6dc1 | 101 | (void)GetEventHandler()->ProcessEvent(event); |
2d61b48d | 102 | } |
bfbd6dc1 VZ |
103 | |
104 | void wxControlBase::InitCommandEvent(wxCommandEvent& event) const | |
105 | { | |
106 | event.SetEventObject((wxControlBase *)this); // const_cast | |
107 | ||
108 | // event.SetId(GetId()); -- this is usuall done in the event ctor | |
109 | ||
110 | switch ( m_clientDataType ) | |
111 | { | |
1e6feb95 | 112 | case wxClientData_Void: |
bfbd6dc1 VZ |
113 | event.SetClientData(GetClientData()); |
114 | break; | |
115 | ||
1e6feb95 | 116 | case wxClientData_Object: |
bfbd6dc1 VZ |
117 | event.SetClientObject(GetClientObject()); |
118 | break; | |
119 | ||
1e6feb95 | 120 | case wxClientData_None: |
bfbd6dc1 VZ |
121 | // nothing to do |
122 | ; | |
123 | } | |
124 | } | |
125 | ||
fe161a26 RD |
126 | void wxControlBase::SetLabel(const wxString& label) |
127 | { | |
128 | wxWindow::SetLabel(label); | |
129 | if (GetAdjustMinSizeFlag()) | |
130 | SetBestSize(wxDefaultSize); | |
131 | } | |
132 | ||
133 | ||
134 | bool wxControlBase::SetFont(const wxFont& font) | |
135 | { | |
136 | bool ret = wxWindow::SetFont(font); | |
137 | ||
138 | if (GetAdjustMinSizeFlag()) | |
139 | SetBestSize(wxDefaultSize); | |
140 | ||
141 | return ret; | |
142 | } | |
143 | ||
1e6feb95 VZ |
144 | // ---------------------------------------------------------------------------- |
145 | // wxStaticBitmap | |
146 | // ---------------------------------------------------------------------------- | |
147 | ||
148 | #if wxUSE_STATBMP | |
149 | ||
799ea011 GD |
150 | wxStaticBitmapBase::~wxStaticBitmapBase() |
151 | { | |
152 | // this destructor is required for Darwin | |
153 | } | |
154 | ||
b3fcfa4d | 155 | wxSize wxStaticBitmapBase::DoGetBestSize() const |
1e6feb95 VZ |
156 | { |
157 | wxBitmap bmp = GetBitmap(); | |
158 | if ( bmp.Ok() ) | |
159 | return wxSize(bmp.GetWidth(), bmp.GetHeight()); | |
160 | ||
161 | // this is completely arbitrary | |
162 | return wxSize(16, 16); | |
163 | } | |
164 | ||
165 | #endif // wxUSE_STATBMP | |
166 | ||
167 | #endif // wxUSE_CONTROLS | |
168 |