]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/srchctrl.cpp
chain to the polling function GLib was using before we replaced it, eliminating all...
[wxWidgets.git] / src / mac / carbon / srchctrl.cpp
index 89f2e20457ed035648a8c0bd40ace40ee6f18173..223ed8fcb137d013fc56cf9abd807aeb745f707c 100644 (file)
@@ -2,25 +2,12 @@
 // Name:        src/mac/carbon/srchctrl.cpp
 // Purpose:     implements mac carbon wxSearchCtrl
 // Author:      Vince Harron
 // Name:        src/mac/carbon/srchctrl.cpp
 // Purpose:     implements mac carbon wxSearchCtrl
 // Author:      Vince Harron
-// Modified by:
 // Created:     2006-02-19
 // Created:     2006-02-19
-// RCS-ID:      
+// RCS-ID:      $Id$
 // Copyright:   Vince Harron
 // License:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 // 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"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
     #pragma hdrstop
 #endif
 
     #pragma hdrstop
 #endif
 
-#ifndef WX_PRECOMP
-    #include "wx/menu.h"
-#endif //WX_PRECOMP
-
 #if wxUSE_SEARCHCTRL
 
 #include "wx/srchctrl.h"
 
 #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"
 
 #include "wx/mac/uma.h"
 #include "wx/mac/carbon/private/mactext.h"
@@ -56,7 +43,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase)
 static const EventTypeSpec eventList[] =
 {
     { kEventClassSearchField, kEventSearchFieldCancelClicked } ,
 static const EventTypeSpec eventList[] =
 {
     { kEventClassSearchField, kEventSearchFieldCancelClicked } ,
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
     { kEventClassSearchField, kEventSearchFieldSearchClicked } ,
     { kEventClassSearchField, kEventSearchFieldSearchClicked } ,
+#endif
 };
 
 class wxMacSearchFieldControl : public wxMacUnicodeTextControl
 };
 
 class wxMacSearchFieldControl : public wxMacUnicodeTextControl
@@ -71,11 +60,11 @@ public :
     }
 
     // search field options
     }
 
     // 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 SetSearchMenu( wxMenu* menu );
     virtual wxMenu* GetSearchMenu() const;
@@ -89,24 +78,27 @@ private:
 void wxMacSearchFieldControl::CreateControl( wxTextCtrl* /*peer*/, const Rect* bounds, CFStringRef crf )
 {
     OptionBits attributes = 0;
 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 )
     {
     if ( UMAGetSystemVersion() >= 0x1040 )
     {
-               attributes = kHISearchFieldAttributesSearchIcon;
-       }
+        attributes = kHISearchFieldAttributesSearchIcon;
+    }
+#endif
     HIRect hibounds = { { bounds->left, bounds->top }, { bounds->right-bounds->left, bounds->bottom-bounds->top } };
     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
         ) );
         &hibounds,
         attributes,
         0, // MenuRef
         CFSTR("Search"),
         &m_controlRef
         ) );
-    HIViewSetVisible (m_controlRef, true); 
+    HIViewSetVisible (m_controlRef, true);
 }
 
 // search field options
 }
 
 // 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;
     if ( UMAGetSystemVersion() >= 0x1040 )
     {
         OptionBits set = 0;
@@ -121,16 +113,21 @@ void wxMacSearchFieldControl::SetSearchButtonVisible( bool show )
         }
         HISearchFieldChangeAttributes( m_controlRef, set, clear );
     }
         }
         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;
     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;
 {
     OptionBits set = 0;
     OptionBits clear = 0;
@@ -145,8 +142,8 @@ void wxMacSearchFieldControl::SetCancelButtonVisible( bool show )
     HISearchFieldChangeAttributes( m_controlRef, set, clear );
 }
 
     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;
     OptionBits attributes = 0;
     verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) );
     return ( attributes & kHISearchFieldAttributesCancel ) != 0;
@@ -184,7 +181,6 @@ static pascal OSStatus wxMacSearchControlEventHandler( EventHandlerCallRef handl
 
     ControlRef controlRef ;
     wxSearchCtrl* thisWindow = (wxSearchCtrl*) data ;
 
     ControlRef controlRef ;
     wxSearchCtrl* thisWindow = (wxSearchCtrl*) data ;
-    wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ;
     cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
 
     switch( GetEventKind( event ) )
     cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
 
     switch( GetEventKind( event ) )
@@ -192,9 +188,11 @@ static pascal OSStatus wxMacSearchControlEventHandler( EventHandlerCallRef handl
         case kEventSearchFieldCancelClicked :
             thisWindow->MacSearchFieldCancelHit( handler , event ) ;
             break ;
         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 ;
         case kEventSearchFieldSearchClicked :
             thisWindow->MacSearchFieldSearchHit( handler , event ) ;
             break ;
+#endif
     }
 
     return result ;
     }
 
     return result ;
@@ -211,7 +209,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacSearchControlEventHandler )
 // --------
 
 wxSearchCtrl::wxSearchCtrl()
 // --------
 
 wxSearchCtrl::wxSearchCtrl()
-{ 
+{
     Init();
 }
 
     Init();
 }
 
@@ -261,7 +259,34 @@ wxSearchCtrl::~wxSearchCtrl()
 
 wxSize wxSearchCtrl::DoGetBestSize() const
 {
 
 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
 }
 
 // search control specific interfaces
@@ -295,40 +320,40 @@ wxMenu* wxSearchCtrl::GetMenu()
     return m_menu;
 }
 
     return m_menu;
 }
 
-void wxSearchCtrl::SetSearchButtonVisible( bool show )
+void wxSearchCtrl::ShowSearchButton( bool show )
 {
 {
-    if ( GetSearchButtonVisible() == show )
+    if ( IsSearchButtonVisible() == show )
     {
         // no change
         return;
     }
     {
         // 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;
     }
     {
         // no change
         return;
     }
-    GetPeer()->SetCancelButtonVisible( show );
+    GetPeer()->ShowCancelButton( show );
 }
 
 }
 
-bool wxSearchCtrl::GetCancelButtonVisible() const
+bool wxSearchCtrl::IsCancelButtonVisible() const
 {
 {
-    return GetPeer()->GetCancelButtonVisible();
+    return GetPeer()->IsCancelButtonVisible();
 }
 
 wxInt32 wxSearchCtrl::MacSearchFieldSearchHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
 {
 }
 
 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 ;
     event.SetEventObject(this);
     ProcessCommand(event);
     return eventNotHandledErr ;
@@ -336,7 +361,7 @@ wxInt32 wxSearchCtrl::MacSearchFieldSearchHit(WXEVENTHANDLERREF WXUNUSED(handler
 
 wxInt32 wxSearchCtrl::MacSearchFieldCancelHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
 {
 
 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 ;
     event.SetEventObject(this);
     ProcessCommand(event);
     return eventNotHandledErr ;
@@ -362,6 +387,6 @@ void wxSearchCtrl::CreatePeer(
     }
 }
 
     }
 }
 
-#endif // USE_NATIVE_SEARCH_CONTROL
+#endif // wxUSE_NATIVE_SEARCH_CONTROL
 
 #endif // wxUSE_SEARCHCTRL
 
 #endif // wxUSE_SEARCHCTRL