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