]>
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 char wxControlNameStr
[] = "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 wxBorder
wxControlBase::GetDefaultBorder() const
163 return wxBORDER_THEME
;
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
173 wxStaticBitmapBase::~wxStaticBitmapBase()
175 // this destructor is required for Darwin
178 wxSize
wxStaticBitmapBase::DoGetBestSize() const
181 wxBitmap bmp
= GetBitmap();
183 best
= wxSize(bmp
.GetWidth(), bmp
.GetHeight());
185 // this is completely arbitrary
186 best
= wxSize(16, 16);
191 #endif // wxUSE_STATBMP
193 #endif // wxUSE_CONTROLS