]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlcmn.cpp
applied patch 432814: saving BMP in 1, 4 and 8 bpp
[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
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
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
1e6feb95
VZ
48bool wxControlBase::Create(wxWindow *parent,
49 wxWindowID id,
50 const wxPoint &pos,
51 const wxSize &size,
52 long style,
53 const wxValidator& 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
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
223d09f6 77 wxCHECK_MSG( parent, FALSE, wxT("all controls must have parents") );
2d61b48d
VZ
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// inherit colour and font settings from the parent window
88void wxControlBase::InheritAttributes()
89{
90 SetBackgroundColour(GetParent()->GetBackgroundColour());
91 SetForegroundColour(GetParent()->GetForegroundColour());
92 SetFont(GetParent()->GetFont());
93}
94
95void wxControlBase::Command(wxCommandEvent& event)
96{
bfbd6dc1 97 (void)GetEventHandler()->ProcessEvent(event);
2d61b48d 98}
bfbd6dc1
VZ
99
100void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
101{
102 event.SetEventObject((wxControlBase *)this); // const_cast
103
104 // event.SetId(GetId()); -- this is usuall done in the event ctor
105
106 switch ( m_clientDataType )
107 {
1e6feb95 108 case wxClientData_Void:
bfbd6dc1
VZ
109 event.SetClientData(GetClientData());
110 break;
111
1e6feb95 112 case wxClientData_Object:
bfbd6dc1
VZ
113 event.SetClientObject(GetClientObject());
114 break;
115
1e6feb95 116 case wxClientData_None:
bfbd6dc1
VZ
117 // nothing to do
118 ;
119 }
120}
121
1e6feb95
VZ
122// ----------------------------------------------------------------------------
123// wxStaticBitmap
124// ----------------------------------------------------------------------------
125
126#if wxUSE_STATBMP
127
128wxSize wxStaticBitmapBase::DoGetBestClientSize() const
129{
130 wxBitmap bmp = GetBitmap();
131 if ( bmp.Ok() )
132 return wxSize(bmp.GetWidth(), bmp.GetHeight());
133
134 // this is completely arbitrary
135 return wxSize(16, 16);
136}
137
138#endif // wxUSE_STATBMP
139
140#endif // wxUSE_CONTROLS
141