1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/srchctrl.cpp
3 // Purpose: implements mac carbon wxSearchCtrl
4 // Author: Vince Harron
6 // RCS-ID: $Id: srchctrl.cpp 54820 2008-07-29 20:04:11Z SC $
7 // Copyright: Vince Harron
8 // License: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/srchctrl.h"
26 #if wxUSE_NATIVE_SEARCH_CONTROL
28 #include "wx/osx/private.h"
29 #include "wx/osx/cocoa/private/textimpl.h"
32 @interface wxNSSearchField : NSSearchField
34 WXCOCOAIMPL_COMMON_MEMBERS
37 WXCOCOAIMPL_COMMON_INTERFACE
41 @implementation wxNSSearchField
43 - (id)initWithFrame:(NSRect)frame
45 [super initWithFrame:frame];
47 [self setTarget: self];
48 [self setAction: @selector(searchAction:)];
52 WXCOCOAIMPL_COMMON_IMPLEMENTATION
54 // use our common calls
55 - (void) setTitle:(NSString *) title
57 [self setStringValue: title];
60 - (void) searchAction: (id) sender
64 wxSearchCtrl* wxpeer = dynamic_cast<wxSearchCtrl*>( impl->GetWXPeer() );
67 NSString *searchString = [self stringValue];
68 if ( searchString == nil )
70 wxpeer->HandleSearchFieldCancelHit();
74 wxpeer->HandleSearchFieldSearchHit();
82 // ============================================================================
83 // wxMacSearchFieldControl
84 // ============================================================================
86 class wxNSSearchFieldControl : public wxNSTextFieldControl, public wxSearchWidgetImpl
89 wxNSSearchFieldControl( wxTextCtrl *wxPeer, wxNSSearchField* w ) : wxNSTextFieldControl(wxPeer, w)
91 m_searchFieldCell = [w cell];
94 ~wxNSSearchFieldControl();
96 // search field options
97 virtual void ShowSearchButton( bool show )
100 [m_searchFieldCell resetSearchButtonCell];
102 [m_searchFieldCell setSearchButtonCell:nil];
103 [m_searchField setNeedsDisplay:YES];
106 virtual bool IsSearchButtonVisible() const
108 return [m_searchFieldCell searchButtonCell] != nil;
111 virtual void ShowCancelButton( bool show )
114 [m_searchFieldCell resetCancelButtonCell];
116 [m_searchFieldCell setCancelButtonCell:nil];
117 [m_searchField setNeedsDisplay:YES];
120 virtual bool IsCancelButtonVisible() const
122 return [m_searchFieldCell cancelButtonCell] != nil;
125 virtual void SetSearchMenu( wxMenu* menu )
128 [m_searchFieldCell setSearchMenuTemplate:menu->GetHMenu()];
130 [m_searchFieldCell setSearchMenuTemplate:nil];
131 [m_searchField setNeedsDisplay:YES];
134 virtual void SetDescriptiveText(const wxString& text)
136 [m_searchFieldCell setPlaceholderString:
137 wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
140 virtual bool SetFocus()
142 return wxNSTextFieldControl::SetFocus();
146 wxNSSearchField* m_searchField;
147 NSSearchFieldCell* m_searchFieldCell;
150 wxNSSearchFieldControl::~wxNSSearchFieldControl()
154 wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer,
163 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
164 wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r];
165 [[v cell] setSendsWholeSearchString:YES];
166 // per wx default cancel is not shown
167 [[v cell] setCancelButtonCell:nil];
169 wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
170 c->SetStringValue( str );
171 [v setImplementation:c];
175 #endif // wxUSE_NATIVE_SEARCH_CONTROL
177 #endif // wxUSE_SEARCHCTRL