]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/srchctrl.cpp
don't assert in SetSelection(wxNOT_FOUND), just clear text zone contents (patch 1707475)
[wxWidgets.git] / src / mac / carbon / srchctrl.cpp
index b8a450ef406b4bb1fca9b07a17e3fbdfa4719f26..3fcb8d7d6686bdb05336d56939c70c94efa45c85 100644 (file)
@@ -43,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
@@ -66,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 );
 
@@ -76,10 +82,12 @@ 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(
         &hibounds,
@@ -94,6 +102,7 @@ void wxMacSearchFieldControl::CreateControl( wxTextCtrl* /*peer*/, const Rect* b
 // search field options
 void wxMacSearchFieldControl::ShowSearchButton( bool show )
 {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
     if ( UMAGetSystemVersion() >= 0x1040 )
     {
         OptionBits set = 0;
@@ -108,13 +117,18 @@ void wxMacSearchFieldControl::ShowSearchButton( bool show )
         }
         HISearchFieldChangeAttributes( m_controlRef, set, clear );
     }
+#endif
 }
 
 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::ShowCancelButton( bool show )
@@ -157,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
 
 // ============================================================================
@@ -178,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 ;
@@ -339,6 +377,16 @@ bool wxSearchCtrl::IsCancelButtonVisible() const
     return GetPeer()->IsCancelButtonVisible();
 }
 
+void wxSearchCtrl::SetDescriptiveText(const wxString& text)
+{
+    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_BTN, m_windowId );