From: Kevin Ollivier Date: Mon, 11 Dec 2006 07:35:46 +0000 (+0000) Subject: Improve default wxSearchCtrl GetBestSize() width and ensure that SetFocus focuses... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/698db322d0af46ddfa0511b80c76c01f6cd6e7ef?ds=sidebyside Improve default wxSearchCtrl GetBestSize() width and ensure that SetFocus focuses in the control's text area. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43911 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/mac/carbon/srchctrl.h b/include/wx/mac/carbon/srchctrl.h index 2d521cf67f..84da5212d7 100644 --- a/include/wx/mac/carbon/srchctrl.h +++ b/include/wx/mac/carbon/srchctrl.h @@ -83,6 +83,8 @@ public: wxMacSearchFieldControl * GetPeer() const { return (wxMacSearchFieldControl*) m_peer; } + + virtual void SetFocus(); protected: diff --git a/src/mac/carbon/srchctrl.cpp b/src/mac/carbon/srchctrl.cpp index 89f2e20457..f6677c0ff8 100644 --- a/src/mac/carbon/srchctrl.cpp +++ b/src/mac/carbon/srchctrl.cpp @@ -261,7 +261,34 @@ wxSearchCtrl::~wxSearchCtrl() wxSize wxSearchCtrl::DoGetBestSize() const { - return wxWindow::DoGetBestSize(); + wxSize size = wxWindow::DoGetBestSize(); + // it seems to return a default width of about 16, which is way too small here. + if (size.GetWidth() < 100) + size.SetWidth(100); + + return size; +} + +void wxSearchCtrl::SetFocus() +{ + // NB: We have to implement SetFocus a little differently because kControlFocusNextPart + // leads to setting the focus on the search icon rather than the text area. + // We get around this by explicitly telling the control to set focus to the + // text area. + if ( !AcceptsFocus() ) + return ; + + wxWindow* former = FindFocus() ; + if ( former == this ) + return ; + + // as we cannot rely on the control features to find out whether we are in full keyboard mode, + // we can only leave in case of an error + OSStatus err = m_peer->SetFocus( kControlEditTextPart ) ; + if ( err == errCouldntSetFocus ) + return ; + + SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() ); } // search control specific interfaces