X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ec184e324214ea06f0c056ab626de5f32bcdad3b..ca86035f16f071d3f6b987bbac9fab174c6079c4:/src/mac/carbon/srchctrl.cpp diff --git a/src/mac/carbon/srchctrl.cpp b/src/mac/carbon/srchctrl.cpp index 90a889170b..3fcb8d7d66 100644 --- a/src/mac/carbon/srchctrl.cpp +++ b/src/mac/carbon/srchctrl.cpp @@ -2,21 +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 -// ---------------------------------------------------------------------------- - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -24,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" @@ -52,7 +43,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) static const EventTypeSpec eventList[] = { { kEventClassSearchField, kEventSearchFieldCancelClicked } , +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 { kEventClassSearchField, kEventSearchFieldSearchClicked } , +#endif }; class wxMacSearchFieldControl : public wxMacUnicodeTextControl @@ -75,6 +68,10 @@ public : 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 ); @@ -85,24 +82,27 @@ private: void wxMacSearchFieldControl::CreateControl( wxTextCtrl* /*peer*/, const Rect* bounds, CFStringRef crf ) { OptionBits attributes = 0; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 if ( UMAGetSystemVersion() >= 0x1040 ) { attributes = kHISearchFieldAttributesSearchIcon; } +#endif 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 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 if ( UMAGetSystemVersion() >= 0x1040 ) { OptionBits set = 0; @@ -117,16 +117,21 @@ void wxMacSearchFieldControl::SetSearchButtonVisible( bool show ) } HISearchFieldChangeAttributes( m_controlRef, set, clear ); } +#endif } -bool wxMacSearchFieldControl::GetSearchButtonVisible() const -{ +bool wxMacSearchFieldControl::IsSearchButtonVisible() const +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 OptionBits attributes = 0; verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) ); return ( attributes & kHISearchFieldAttributesSearchIcon ) != 0; +#else + return false; +#endif } -void wxMacSearchFieldControl::SetCancelButtonVisible( bool show ) +void wxMacSearchFieldControl::ShowCancelButton( bool show ) { OptionBits set = 0; OptionBits clear = 0; @@ -141,8 +146,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; @@ -166,6 +171,28 @@ wxMenu* wxMacSearchFieldControl::GetSearchMenu() const return m_menu; } + +void wxMacSearchFieldControl::SetDescriptiveText(const wxString& text) +{ + verify_noerr( HISearchFieldSetDescriptiveText( + m_controlRef, + wxMacCFStringHolder( text, wxFont::GetDefaultEncoding() ))); +} + +wxString wxMacSearchFieldControl::GetDescriptiveText() const +{ + CFStringRef cfStr; + verify_noerr( HISearchFieldCopyDescriptiveText( m_controlRef, &cfStr )); + if ( cfStr ) + { + return wxMacCFStringHolder(cfStr).AsString(); + } + else + { + return wxEmptyString; + } +} + #endif // ============================================================================ @@ -180,7 +207,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 ) ) @@ -188,9 +214,11 @@ static pascal OSStatus wxMacSearchControlEventHandler( EventHandlerCallRef handl case kEventSearchFieldCancelClicked : thisWindow->MacSearchFieldCancelHit( handler , event ) ; break ; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 case kEventSearchFieldSearchClicked : thisWindow->MacSearchFieldSearchHit( handler , event ) ; break ; +#endif } return result ; @@ -207,7 +235,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacSearchControlEventHandler ) // -------- wxSearchCtrl::wxSearchCtrl() -{ +{ Init(); } @@ -261,7 +289,7 @@ wxSize wxSearchCtrl::DoGetBestSize() const // 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; } @@ -318,40 +346,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(); +} + +void wxSearchCtrl::SetDescriptiveText(const wxString& text) +{ + GetPeer()->SetDescriptiveText(text); } -bool wxSearchCtrl::GetCancelButtonVisible() const +wxString wxSearchCtrl::GetDescriptiveText() const { - return GetPeer()->GetCancelButtonVisible(); + 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 ; @@ -359,7 +397,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 ; @@ -385,6 +423,6 @@ void wxSearchCtrl::CreatePeer( } } -#endif // USE_NATIVE_SEARCH_CONTROL +#endif // wxUSE_NATIVE_SEARCH_CONTROL #endif // wxUSE_SEARCHCTRL