]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/srchctrl.cpp
remove leading dots from .ini/.conf in AddConfFileExtIfNeeded() as this results in...
[wxWidgets.git] / src / mac / carbon / srchctrl.cpp
index 7af18fe1840a4a71375e258925ee9143d4611a14..4a786293913a22b3ef4df5c668325bd21a9f9642 100644 (file)
@@ -8,14 +8,6 @@
 // License:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
-// ============================================================================
-// declarations
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// headers
-// ----------------------------------------------------------------------------
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
     #pragma hdrstop
 #endif
 
-#ifndef WX_PRECOMP
-    #include "wx/menu.h"
-#endif //WX_PRECOMP
-
 #if wxUSE_SEARCHCTRL
 
 #include "wx/srchctrl.h"
 
+#ifndef WX_PRECOMP
+    #include "wx/menu.h"
+#endif //WX_PRECOMP
+
 #if wxUSE_NATIVE_SEARCH_CONTROL
 
 #include "wx/mac/uma.h"
@@ -45,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 } ,
@@ -74,6 +63,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 );
 
@@ -81,13 +74,12 @@ 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(
         &hibounds,
@@ -100,32 +92,29 @@ void wxMacSearchFieldControl::CreateControl( wxTextCtrl* /*peer*/, const Rect* b
 }
 
 // search field options
-void wxMacSearchFieldControl::SetSearchButtonVisible( bool show )
+void wxMacSearchFieldControl::ShowSearchButton( bool show )
 {
-    if ( UMAGetSystemVersion() >= 0x1040 )
+    OptionBits set = 0;
+    OptionBits clear = 0;
+    if ( show )
+    {
+        set |= kHISearchFieldAttributesSearchIcon;
+    }
+    else
     {
-        OptionBits set = 0;
-        OptionBits clear = 0;
-        if ( show )
-        {
-            set |= kHISearchFieldAttributesSearchIcon;
-        }
-        else
-        {
-            clear |= kHISearchFieldAttributesSearchIcon;
-        }
-        HISearchFieldChangeAttributes( m_controlRef, set, clear );
+        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;
@@ -140,7 +129,7 @@ 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 ) );
@@ -165,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
@@ -179,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 ) )
@@ -246,6 +254,8 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id,
         GetEventTypeCount(eventList), eventList, this,
         (EventHandlerRef *)&searchEventHandler);
 
+    SetValue(value);
+
     return true;
 }
 
@@ -317,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();
+}
+
+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 ;
@@ -358,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 ;
@@ -370,18 +390,7 @@ 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 // wxUSE_NATIVE_SEARCH_CONTROL