]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/srchctrl.mm
build fix
[wxWidgets.git] / src / osx / cocoa / srchctrl.mm
CommitLineData
524c47aa
SC
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/carbon/srchctrl.cpp
3// Purpose: implements mac carbon wxSearchCtrl
4// Author: Vince Harron
5// Created: 2006-02-19
6// RCS-ID: $Id: srchctrl.cpp 54820 2008-07-29 20:04:11Z SC $
7// Copyright: Vince Harron
8// License: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#if wxUSE_SEARCHCTRL
19
20#include "wx/srchctrl.h"
21
22#ifndef WX_PRECOMP
23 #include "wx/menu.h"
24#endif //WX_PRECOMP
25
26#if wxUSE_NATIVE_SEARCH_CONTROL
27
1e181c7a
SC
28#include "wx/osx/private.h"
29#include "wx/osx/cocoa/private/textimpl.h"
524c47aa 30
524c47aa 31
1e181c7a 32@interface wxNSSearchField : NSSearchField
524c47aa 33{
524c47aa
SC
34}
35
1e181c7a 36@end
524c47aa 37
1e181c7a 38@implementation wxNSSearchField
524c47aa 39
4dd9fdf8
SC
40+ (void)initialize
41{
42 static BOOL initialized = NO;
43 if (!initialized)
44 {
45 initialized = YES;
46 wxOSXCocoaClassAddWXMethods( self );
47 }
48}
49
1e181c7a 50- (id)initWithFrame:(NSRect)frame
524c47aa 51{
1e181c7a 52 [super initWithFrame:frame];
1e181c7a
SC
53 [self setTarget: self];
54 [self setAction: @selector(searchAction:)];
55 return self;
524c47aa
SC
56}
57
1e181c7a 58- (void) searchAction: (id) sender
524c47aa 59{
4dd9fdf8 60 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
1e181c7a 61 if ( impl )
524c47aa 62 {
1e181c7a
SC
63 wxSearchCtrl* wxpeer = dynamic_cast<wxSearchCtrl*>( impl->GetWXPeer() );
64 if ( wxpeer )
65 {
66 NSString *searchString = [self stringValue];
67 if ( searchString == nil )
68 {
69 wxpeer->HandleSearchFieldCancelHit();
70 }
71 else
72 {
73 wxpeer->HandleSearchFieldSearchHit();
74 }
75 }
524c47aa
SC
76 }
77}
78
1e181c7a 79@end
524c47aa
SC
80
81// ============================================================================
1e181c7a 82// wxMacSearchFieldControl
524c47aa
SC
83// ============================================================================
84
1e181c7a 85class wxNSSearchFieldControl : public wxNSTextFieldControl, public wxSearchWidgetImpl
524c47aa 86{
1e181c7a
SC
87public :
88 wxNSSearchFieldControl( wxTextCtrl *wxPeer, wxNSSearchField* w ) : wxNSTextFieldControl(wxPeer, w)
524c47aa 89 {
1e181c7a
SC
90 m_searchFieldCell = [w cell];
91 m_searchField = w;
524c47aa 92 }
1e181c7a 93 ~wxNSSearchFieldControl();
524c47aa 94
1e181c7a
SC
95 // search field options
96 virtual void ShowSearchButton( bool show )
524c47aa 97 {
1e181c7a
SC
98 if ( show )
99 [m_searchFieldCell resetSearchButtonCell];
100 else
101 [m_searchFieldCell setSearchButtonCell:nil];
102 [m_searchField setNeedsDisplay:YES];
524c47aa 103 }
1e181c7a
SC
104
105 virtual bool IsSearchButtonVisible() const
524c47aa 106 {
1e181c7a 107 return [m_searchFieldCell searchButtonCell] != nil;
524c47aa
SC
108 }
109
1e181c7a 110 virtual void ShowCancelButton( bool show )
524c47aa 111 {
1e181c7a
SC
112 if ( show )
113 [m_searchFieldCell resetCancelButtonCell];
114 else
115 [m_searchFieldCell setCancelButtonCell:nil];
116 [m_searchField setNeedsDisplay:YES];
524c47aa 117 }
1e181c7a
SC
118
119 virtual bool IsCancelButtonVisible() const
524c47aa 120 {
1e181c7a 121 return [m_searchFieldCell cancelButtonCell] != nil;
524c47aa
SC
122 }
123
1e181c7a 124 virtual void SetSearchMenu( wxMenu* menu )
524c47aa 125 {
1e181c7a
SC
126 if ( menu )
127 [m_searchFieldCell setSearchMenuTemplate:menu->GetHMenu()];
128 else
129 [m_searchFieldCell setSearchMenuTemplate:nil];
130 [m_searchField setNeedsDisplay:YES];
524c47aa 131 }
524c47aa 132
1e181c7a 133 virtual void SetDescriptiveText(const wxString& text)
524c47aa 134 {
1e181c7a
SC
135 [m_searchFieldCell setPlaceholderString:
136 wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
137 }
138
139 virtual bool SetFocus()
140 {
141 return wxNSTextFieldControl::SetFocus();
524c47aa 142 }
524c47aa 143
1e181c7a
SC
144private:
145 wxNSSearchField* m_searchField;
146 NSSearchFieldCell* m_searchFieldCell;
147} ;
524c47aa 148
1e181c7a 149wxNSSearchFieldControl::~wxNSSearchFieldControl()
524c47aa 150{
524c47aa
SC
151}
152
1e181c7a
SC
153wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer,
154 wxWindowMac* parent,
155 wxWindowID id,
156 const wxString& str,
157 const wxPoint& pos,
158 const wxSize& size,
159 long style,
160 long extraStyle)
524c47aa 161{
1e181c7a
SC
162 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
163 wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r];
1e181c7a
SC
164 [[v cell] setSendsWholeSearchString:YES];
165 // per wx default cancel is not shown
166 [[v cell] setCancelButtonCell:nil];
167
98978a10
KO
168 [v setBezeled:NO];
169 [v setBordered:NO];
170
1e181c7a
SC
171 wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
172 c->SetStringValue( str );
1e181c7a 173 return c;
524c47aa
SC
174}
175
176#endif // wxUSE_NATIVE_SEARCH_CONTROL
177
178#endif // wxUSE_SEARCHCTRL