]>
git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/ctrlcmn.cpp
3 // Purpose: wxControl common interface
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/control.h"
33 #include "wx/radiobut.h"
34 #include "wx/statbmp.h"
35 #include "wx/bitmap.h"
36 #include "wx/utils.h" // for wxStripMenuCodes()
39 const wxChar wxControlNameStr
[] = wxT("control");
41 // ============================================================================
43 // ============================================================================
45 wxControlBase::~wxControlBase()
47 // this destructor is required for Darwin
50 bool wxControlBase::Create(wxWindow
*parent
,
55 const wxValidator
& wxVALIDATOR_PARAM(validator
),
58 bool ret
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
62 SetValidator(validator
);
63 #endif // wxUSE_VALIDATORS
68 bool wxControlBase::CreateControl(wxWindowBase
*parent
,
73 const wxValidator
& validator
,
76 // even if it's possible to create controls without parents in some port,
77 // it should surely be discouraged because it doesn't work at all under
79 wxCHECK_MSG( parent
, false, wxT("all controls must have parents") );
81 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
84 parent
->AddChild(this);
90 wxString
wxControlBase::GetLabelText(const wxString
& label
)
92 // we don't want strip the TABs here, just the mnemonics
93 return wxStripMenuCodes(label
, wxStrip_Mnemonics
);
96 void wxControlBase::Command(wxCommandEvent
& event
)
98 (void)GetEventHandler()->ProcessEvent(event
);
101 void wxControlBase::InitCommandEvent(wxCommandEvent
& event
) const
103 event
.SetEventObject((wxControlBase
*)this); // const_cast
105 // event.SetId(GetId()); -- this is usuall done in the event ctor
107 switch ( m_clientDataType
)
109 case wxClientData_Void
:
110 event
.SetClientData(GetClientData());
113 case wxClientData_Object
:
114 event
.SetClientObject(GetClientObject());
117 case wxClientData_None
:
124 void wxControlBase::SetLabel( const wxString
&label
)
126 InvalidateBestSize();
127 wxWindow::SetLabel(label
);
130 bool wxControlBase::SetFont(const wxFont
& font
)
132 InvalidateBestSize();
133 return wxWindow::SetFont(font
);
136 // wxControl-specific processing after processing the update event
137 void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
140 wxWindowBase::DoUpdateWindowUI(event
);
143 if ( event
.GetSetText() )
145 if ( event
.GetText() != GetLabel() )
146 SetLabel(event
.GetText());
149 // Unfortunately we don't yet have common base class for
150 // wxRadioButton, so we handle updates of radiobuttons here.
151 // TODO: If once wxRadioButtonBase will exist, move this code there.
153 if ( event
.GetSetChecked() )
155 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
157 radiobtn
->SetValue(event
.GetChecked());
159 #endif // wxUSE_RADIOBTN
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
168 wxStaticBitmapBase::~wxStaticBitmapBase()
170 // this destructor is required for Darwin
173 wxSize
wxStaticBitmapBase::DoGetBestSize() const
176 wxBitmap bmp
= GetBitmap();
178 best
= wxSize(bmp
.GetWidth(), bmp
.GetHeight());
180 // this is completely arbitrary
181 best
= wxSize(16, 16);
186 #endif // wxUSE_STATBMP
188 #endif // wxUSE_CONTROLS