I have found a workaround to make the non-native combo box look native.
I overrode the OnPaintEvent. Example:
Code: Select all
BEGIN_EVENT_TABLE(MyComboBoxCtrl, wxOwnerDrawnComboBox)
#ifdef __WXMAC__
EVT_PAINT(MyComboBoxCtrl::OnPaintEvent)
#endif
END_EVENT_TABLE()
#ifdef __WXMAC__
void MyComboBoxCtrl::OnPaintEvent(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
wxRect clientRect = GetClientRect();
wxWindow* pWindow = this;
int flags = wxCONTROL_NONE;
if (pWindow->IsEnabled() == false)
flags |= wxCONTROL_DISABLED;
wxRendererNative& renderer = wxRendererNative::GetDefault();
renderer.DrawComboBox(pWindow, dc, clientRect, flags);
}
#endif
You may also need a PositionTextCtrl() to get the inner text box lined up close to how the native control does it:
Code: Select all
#if defined(__WXMAC__)
// in class declaration in MyComboBoxCtrl.h: virtual void PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust );
void MyComboBoxCtrl::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust )
{
wxTextCtrl* textCtrl = GetTextCtrl();
if ( !textCtrl )
return;
textCtrl->SetSize(m_tcArea.x + textCtrlXAdjust,
m_tcArea.y + textCtrlYAdjust,
m_tcArea.width,
m_tcArea.height - 6);
textCtrl->Move(3, 6);
}
#endif
I hope this is helpful to anyone else finding they need a Mac-native-looking owner-drawn combo box!