]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlcmn.cpp
A little clarification
[wxWidgets.git] / src / common / ctrlcmn.cpp
CommitLineData
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$
8// Copyright: (c) wxWindows team
55d99c7a 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
1169a919
JS
48wxControlBase::wxControlBase()
49{
50}
51
799ea011
GD
52wxControlBase::~wxControlBase()
53{
54 // this destructor is required for Darwin
55}
56
1e6feb95
VZ
57bool wxControlBase::Create(wxWindow *parent,
58 wxWindowID id,
59 const wxPoint &pos,
60 const wxSize &size,
61 long style,
ac8d0c11 62 const wxValidator& wxVALIDATOR_PARAM(validator),
1e6feb95
VZ
63 const wxString &name)
64{
65 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
66
67#if wxUSE_VALIDATORS
68 if ( ret )
69 SetValidator(validator);
70#endif // wxUSE_VALIDATORS
71
72 return ret;
73}
74
2d61b48d
VZ
75bool wxControlBase::CreateControl(wxWindowBase *parent,
76 wxWindowID id,
77 const wxPoint& pos,
78 const wxSize& size,
79 long style,
80 const wxValidator& validator,
81 const wxString& name)
82{
83 // even if it's possible to create controls without parents in some port,
84 // it should surely be discouraged because it doesn't work at all under
85 // Windows
223d09f6 86 wxCHECK_MSG( parent, FALSE, wxT("all controls must have parents") );
2d61b48d
VZ
87
88 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
89 return FALSE;
90
91 parent->AddChild(this);
92
93 return TRUE;
94}
95
96// inherit colour and font settings from the parent window
97void wxControlBase::InheritAttributes()
98{
230205ae
VZ
99 if ( ShouldInheritColours() )
100 {
101 wxWindow *parent = GetParent();
102
103 wxCHECK_RET( parent, _T("a control without parent?") );
104
105 SetBackgroundColour(parent->GetBackgroundColour());
106 SetForegroundColour(parent->GetForegroundColour());
107 }
92b0a2a1 108
344e7ee2
DW
109#ifdef __WXPM__
110 //
111 // All OS/2 ctrls use the small font
112 //
113 SetFont(*wxSMALL_FONT);
114#else
2d61b48d 115 SetFont(GetParent()->GetFont());
344e7ee2 116#endif
2d61b48d
VZ
117}
118
119void wxControlBase::Command(wxCommandEvent& event)
120{
bfbd6dc1 121 (void)GetEventHandler()->ProcessEvent(event);
2d61b48d 122}
bfbd6dc1
VZ
123
124void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
125{
126 event.SetEventObject((wxControlBase *)this); // const_cast
127
128 // event.SetId(GetId()); -- this is usuall done in the event ctor
129
130 switch ( m_clientDataType )
131 {
1e6feb95 132 case wxClientData_Void:
bfbd6dc1
VZ
133 event.SetClientData(GetClientData());
134 break;
135
1e6feb95 136 case wxClientData_Object:
bfbd6dc1
VZ
137 event.SetClientObject(GetClientObject());
138 break;
139
1e6feb95 140 case wxClientData_None:
bfbd6dc1
VZ
141 // nothing to do
142 ;
143 }
144}
145
1e6feb95
VZ
146// ----------------------------------------------------------------------------
147// wxStaticBitmap
148// ----------------------------------------------------------------------------
149
150#if wxUSE_STATBMP
151
799ea011
GD
152wxStaticBitmapBase::~wxStaticBitmapBase()
153{
154 // this destructor is required for Darwin
155}
156
1e6feb95
VZ
157wxSize wxStaticBitmapBase::DoGetBestClientSize() const
158{
159 wxBitmap bmp = GetBitmap();
160 if ( bmp.Ok() )
161 return wxSize(bmp.GetWidth(), bmp.GetHeight());
162
163 // this is completely arbitrary
164 return wxSize(16, 16);
165}
166
167#endif // wxUSE_STATBMP
168
169#endif // wxUSE_CONTROLS
170