X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3f7f284d555df50912037296c5d74a2911975bce..bbd92d1dbea02db8c28e9c17bfacc0563d855b25:/src/mac/carbon/srchctrl.cpp diff --git a/src/mac/carbon/srchctrl.cpp b/src/mac/carbon/srchctrl.cpp index 89f2e20457..4a78629391 100644 --- a/src/mac/carbon/srchctrl.cpp +++ b/src/mac/carbon/srchctrl.cpp @@ -2,25 +2,12 @@ // Name: src/mac/carbon/srchctrl.cpp // Purpose: implements mac carbon wxSearchCtrl // Author: Vince Harron -// Modified by: // Created: 2006-02-19 -// RCS-ID: +// RCS-ID: $Id$ // Copyright: Vince Harron // License: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "srchctrl.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -28,15 +15,15 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/menu.h" -#endif //WX_PRECOMP - #if wxUSE_SEARCHCTRL #include "wx/srchctrl.h" -#if USE_NATIVE_SEARCH_CONTROL +#ifndef WX_PRECOMP + #include "wx/menu.h" +#endif //WX_PRECOMP + +#if wxUSE_NATIVE_SEARCH_CONTROL #include "wx/mac/uma.h" #include "wx/mac/carbon/private/mactext.h" @@ -50,9 +37,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) // wxMacSearchFieldControl // ============================================================================ -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 - - static const EventTypeSpec eventList[] = { { kEventClassSearchField, kEventSearchFieldCancelClicked } , @@ -71,14 +55,18 @@ public : } // search field options - virtual void SetSearchButtonVisible( bool show ); - virtual bool GetSearchButtonVisible() const; + virtual void ShowSearchButton( bool show ); + virtual bool IsSearchButtonVisible() const; - virtual void SetCancelButtonVisible( bool show ); - virtual bool GetCancelButtonVisible() const; + virtual void ShowCancelButton( bool show ); + virtual bool IsCancelButtonVisible() const; virtual void SetSearchMenu( wxMenu* menu ); virtual wxMenu* GetSearchMenu() const; + + virtual void SetDescriptiveText(const wxString& text); + virtual wxString GetDescriptiveText() const; + protected : virtual void CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef crf ); @@ -86,51 +74,47 @@ private: wxMenu* m_menu; } ; -void wxMacSearchFieldControl::CreateControl( wxTextCtrl* /*peer*/, const Rect* bounds, CFStringRef crf ) +void wxMacSearchFieldControl::CreateControl(wxTextCtrl* WXUNUSED(peer), + const Rect* bounds, + CFStringRef WXUNUSED(crf)) { - OptionBits attributes = 0; - if ( UMAGetSystemVersion() >= 0x1040 ) - { - attributes = kHISearchFieldAttributesSearchIcon; - } + OptionBits attributes = kHISearchFieldAttributesSearchIcon; + HIRect hibounds = { { bounds->left, bounds->top }, { bounds->right-bounds->left, bounds->bottom-bounds->top } }; - verify_noerr( HISearchFieldCreate( + verify_noerr( HISearchFieldCreate( &hibounds, attributes, 0, // MenuRef CFSTR("Search"), &m_controlRef ) ); - HIViewSetVisible (m_controlRef, true); + HIViewSetVisible (m_controlRef, true); } // search field options -void wxMacSearchFieldControl::SetSearchButtonVisible( bool show ) +void wxMacSearchFieldControl::ShowSearchButton( bool show ) { - if ( UMAGetSystemVersion() >= 0x1040 ) + OptionBits set = 0; + OptionBits clear = 0; + if ( show ) { - OptionBits set = 0; - OptionBits clear = 0; - if ( show ) - { - set |= kHISearchFieldAttributesSearchIcon; - } - else - { - clear |= kHISearchFieldAttributesSearchIcon; - } - HISearchFieldChangeAttributes( m_controlRef, set, clear ); + set |= kHISearchFieldAttributesSearchIcon; } + else + { + clear |= kHISearchFieldAttributesSearchIcon; + } + HISearchFieldChangeAttributes( m_controlRef, set, clear ); } -bool wxMacSearchFieldControl::GetSearchButtonVisible() const -{ +bool wxMacSearchFieldControl::IsSearchButtonVisible() const +{ OptionBits attributes = 0; verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) ); return ( attributes & kHISearchFieldAttributesSearchIcon ) != 0; } -void wxMacSearchFieldControl::SetCancelButtonVisible( bool show ) +void wxMacSearchFieldControl::ShowCancelButton( bool show ) { OptionBits set = 0; OptionBits clear = 0; @@ -145,8 +129,8 @@ void wxMacSearchFieldControl::SetCancelButtonVisible( bool show ) HISearchFieldChangeAttributes( m_controlRef, set, clear ); } -bool wxMacSearchFieldControl::GetCancelButtonVisible() const -{ +bool wxMacSearchFieldControl::IsCancelButtonVisible() const +{ OptionBits attributes = 0; verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) ); return ( attributes & kHISearchFieldAttributesCancel ) != 0; @@ -170,7 +154,27 @@ wxMenu* wxMacSearchFieldControl::GetSearchMenu() const return m_menu; } -#endif + +void wxMacSearchFieldControl::SetDescriptiveText(const wxString& text) +{ + verify_noerr( HISearchFieldSetDescriptiveText( + m_controlRef, + wxCFStringRef( text, wxFont::GetDefaultEncoding() ))); +} + +wxString wxMacSearchFieldControl::GetDescriptiveText() const +{ + CFStringRef cfStr; + verify_noerr( HISearchFieldCopyDescriptiveText( m_controlRef, &cfStr )); + if ( cfStr ) + { + return wxCFStringRef(cfStr).AsString(); + } + else + { + return wxEmptyString; + } +} // ============================================================================ // implementation @@ -184,7 +188,6 @@ static pascal OSStatus wxMacSearchControlEventHandler( EventHandlerCallRef handl ControlRef controlRef ; wxSearchCtrl* thisWindow = (wxSearchCtrl*) data ; - wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ; cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; switch( GetEventKind( event ) ) @@ -211,7 +214,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacSearchControlEventHandler ) // -------- wxSearchCtrl::wxSearchCtrl() -{ +{ Init(); } @@ -251,6 +254,8 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&searchEventHandler); + SetValue(value); + return true; } @@ -261,7 +266,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 @@ -295,40 +327,50 @@ wxMenu* wxSearchCtrl::GetMenu() return m_menu; } -void wxSearchCtrl::SetSearchButtonVisible( bool show ) +void wxSearchCtrl::ShowSearchButton( bool show ) { - if ( GetSearchButtonVisible() == show ) + if ( IsSearchButtonVisible() == show ) { // no change return; } - GetPeer()->SetSearchButtonVisible( show ); + GetPeer()->ShowSearchButton( show ); } -bool wxSearchCtrl::GetSearchButtonVisible() const +bool wxSearchCtrl::IsSearchButtonVisible() const { - return GetPeer()->GetSearchButtonVisible(); + return GetPeer()->IsSearchButtonVisible(); } -void wxSearchCtrl::SetCancelButtonVisible( bool show ) +void wxSearchCtrl::ShowCancelButton( bool show ) { - if ( GetCancelButtonVisible() == show ) + if ( IsCancelButtonVisible() == show ) { // no change return; } - GetPeer()->SetCancelButtonVisible( show ); + GetPeer()->ShowCancelButton( show ); +} + +bool wxSearchCtrl::IsCancelButtonVisible() const +{ + return GetPeer()->IsCancelButtonVisible(); } -bool wxSearchCtrl::GetCancelButtonVisible() const +void wxSearchCtrl::SetDescriptiveText(const wxString& text) { - return GetPeer()->GetCancelButtonVisible(); + GetPeer()->SetDescriptiveText(text); +} + +wxString wxSearchCtrl::GetDescriptiveText() const +{ + return GetPeer()->GetDescriptiveText(); } wxInt32 wxSearchCtrl::MacSearchFieldSearchHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { - wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH, m_windowId ); + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId ); event.SetEventObject(this); ProcessCommand(event); return eventNotHandledErr ; @@ -336,7 +378,7 @@ wxInt32 wxSearchCtrl::MacSearchFieldSearchHit(WXEVENTHANDLERREF WXUNUSED(handler wxInt32 wxSearchCtrl::MacSearchFieldCancelHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { - wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL, m_windowId ); + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId ); event.SetEventObject(this); ProcessCommand(event); return eventNotHandledErr ; @@ -348,20 +390,9 @@ void wxSearchCtrl::CreatePeer( const wxPoint& pos, const wxSize& size, long style ) { -#ifdef __WXMAC_OSX__ -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 - if ( UMAGetSystemVersion() >= 0x1030 ) - { - m_peer = new wxMacSearchFieldControl( this , str , pos , size , style ); - } -#endif -#endif - if ( !m_peer ) - { - wxTextCtrl::CreatePeer( str, pos, size, style ); - } + m_peer = new wxMacSearchFieldControl( this , str , pos , size , style ); } -#endif // USE_NATIVE_SEARCH_CONTROL +#endif // wxUSE_NATIVE_SEARCH_CONTROL #endif // wxUSE_SEARCHCTRL