]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlcmn.cpp
added GetWindowSizeForVirtualSize() virtual hook for wxScrolledWindow (cuts down...
[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$
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
2d61b48d
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
1e6feb95
VZ
27#if wxUSE_CONTROLS
28
2d61b48d
VZ
29#ifndef WX_PRECOMP
30 #include "wx/control.h"
31 #include "wx/log.h"
32#endif
33
1e6feb95
VZ
34#if wxUSE_STATBMP
35 #include "wx/bitmap.h"
36 #include "wx/statbmp.h"
37#endif // wxUSE_STATBMP
38
2d61b48d
VZ
39// ============================================================================
40// implementation
41// ============================================================================
42
799ea011
GD
43wxControlBase::~wxControlBase()
44{
45 // this destructor is required for Darwin
46}
47
1e6feb95
VZ
48bool wxControlBase::Create(wxWindow *parent,
49 wxWindowID id,
50 const wxPoint &pos,
51 const wxSize &size,
52 long style,
ac8d0c11 53 const wxValidator& wxVALIDATOR_PARAM(validator),
1e6feb95
VZ
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
2d61b48d
VZ
66bool 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
c9d59ee7 77 wxCHECK_MSG( parent, false, wxT("all controls must have parents") );
2d61b48d
VZ
78
79 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
c9d59ee7 80 return false;
2d61b48d
VZ
81
82 parent->AddChild(this);
83
c9d59ee7 84 return true;
2d61b48d
VZ
85}
86
2d61b48d
VZ
87void wxControlBase::Command(wxCommandEvent& event)
88{
bfbd6dc1 89 (void)GetEventHandler()->ProcessEvent(event);
2d61b48d 90}
bfbd6dc1
VZ
91
92void 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 {
1e6feb95 100 case wxClientData_Void:
bfbd6dc1
VZ
101 event.SetClientData(GetClientData());
102 break;
103
1e6feb95 104 case wxClientData_Object:
bfbd6dc1
VZ
105 event.SetClientObject(GetClientObject());
106 break;
107
1e6feb95 108 case wxClientData_None:
bfbd6dc1
VZ
109 // nothing to do
110 ;
111 }
112}
113
9f884528
RD
114
115void wxControlBase::SetLabel( const wxString &label )
116{
117 InvalidateBestSize();
c9d59ee7 118 wxWindow::SetLabel(label);
9f884528
RD
119}
120
121bool wxControlBase::SetFont(const wxFont& font)
122{
123 InvalidateBestSize();
124 return wxWindow::SetFont(font);
125}
126
1e6feb95
VZ
127// ----------------------------------------------------------------------------
128// wxStaticBitmap
129// ----------------------------------------------------------------------------
130
131#if wxUSE_STATBMP
132
799ea011
GD
133wxStaticBitmapBase::~wxStaticBitmapBase()
134{
135 // this destructor is required for Darwin
136}
137
b3fcfa4d 138wxSize wxStaticBitmapBase::DoGetBestSize() const
1e6feb95 139{
9f884528 140 wxSize best;
1e6feb95
VZ
141 wxBitmap bmp = GetBitmap();
142 if ( bmp.Ok() )
9f884528
RD
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;
1e6feb95
VZ
149}
150
151#endif // wxUSE_STATBMP
152
153#endif // wxUSE_CONTROLS
154