]>
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
:
123 bool wxControlBase::SetFont(const wxFont
& font
)
125 InvalidateBestSize();
126 return wxWindow::SetFont(font
);
129 // wxControl-specific processing after processing the update event
130 void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
133 wxWindowBase::DoUpdateWindowUI(event
);
136 if ( event
.GetSetText() )
138 if ( event
.GetText() != GetLabel() )
139 SetLabel(event
.GetText());
142 // Unfortunately we don't yet have common base class for
143 // wxRadioButton, so we handle updates of radiobuttons here.
144 // TODO: If once wxRadioButtonBase will exist, move this code there.
146 if ( event
.GetSetChecked() )
148 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
150 radiobtn
->SetValue(event
.GetChecked());
152 #endif // wxUSE_RADIOBTN
156 wxString
wxControlBase::RemoveMnemonics(const wxString
& str
)
158 return wxStripMenuCodes(str
, wxStrip_Mnemonics
);
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
167 wxStaticBitmapBase::~wxStaticBitmapBase()
169 // this destructor is required for Darwin
172 wxSize
wxStaticBitmapBase::DoGetBestSize() const
175 wxBitmap bmp
= GetBitmap();
177 best
= wxSize(bmp
.GetWidth(), bmp
.GetHeight());
179 // this is completely arbitrary
180 best
= wxSize(16, 16);
185 #endif // wxUSE_STATBMP
187 #endif // wxUSE_CONTROLS