]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/srchctrl.mm
define MIIM_BITMAP &c in wx/msw/missing.h instead of msw/menu.cpp as menuitem.cpp...
[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{
b466e85a 34 WXCOCOAIMPL_COMMON_MEMBERS
524c47aa
SC
35}
36
b466e85a
SC
37WXCOCOAIMPL_COMMON_INTERFACE
38
1e181c7a 39@end
524c47aa 40
1e181c7a 41@implementation wxNSSearchField
524c47aa 42
1e181c7a 43- (id)initWithFrame:(NSRect)frame
524c47aa 44{
1e181c7a
SC
45 [super initWithFrame:frame];
46 impl = NULL;
47 [self setTarget: self];
48 [self setAction: @selector(searchAction:)];
49 return self;
524c47aa
SC
50}
51
b466e85a 52WXCOCOAIMPL_COMMON_IMPLEMENTATION
524c47aa 53
1e181c7a
SC
54// use our common calls
55- (void) setTitle:(NSString *) title
524c47aa 56{
1e181c7a 57 [self setStringValue: title];
524c47aa
SC
58}
59
1e181c7a 60- (void) searchAction: (id) sender
524c47aa 61{
1e181c7a 62 if ( impl )
524c47aa 63 {
1e181c7a
SC
64 wxSearchCtrl* wxpeer = dynamic_cast<wxSearchCtrl*>( impl->GetWXPeer() );
65 if ( wxpeer )
66 {
67 NSString *searchString = [self stringValue];
68 if ( searchString == nil )
69 {
70 wxpeer->HandleSearchFieldCancelHit();
71 }
72 else
73 {
74 wxpeer->HandleSearchFieldSearchHit();
75 }
76 }
524c47aa
SC
77 }
78}
79
1e181c7a 80@end
524c47aa
SC
81
82// ============================================================================
1e181c7a 83// wxMacSearchFieldControl
524c47aa
SC
84// ============================================================================
85
1e181c7a 86class wxNSSearchFieldControl : public wxNSTextFieldControl, public wxSearchWidgetImpl
524c47aa 87{
1e181c7a
SC
88public :
89 wxNSSearchFieldControl( wxTextCtrl *wxPeer, wxNSSearchField* w ) : wxNSTextFieldControl(wxPeer, w)
524c47aa 90 {
1e181c7a
SC
91 m_searchFieldCell = [w cell];
92 m_searchField = w;
524c47aa 93 }
1e181c7a 94 ~wxNSSearchFieldControl();
524c47aa 95
1e181c7a
SC
96 // search field options
97 virtual void ShowSearchButton( bool show )
524c47aa 98 {
1e181c7a
SC
99 if ( show )
100 [m_searchFieldCell resetSearchButtonCell];
101 else
102 [m_searchFieldCell setSearchButtonCell:nil];
103 [m_searchField setNeedsDisplay:YES];
524c47aa 104 }
1e181c7a
SC
105
106 virtual bool IsSearchButtonVisible() const
524c47aa 107 {
1e181c7a 108 return [m_searchFieldCell searchButtonCell] != nil;
524c47aa
SC
109 }
110
1e181c7a 111 virtual void ShowCancelButton( bool show )
524c47aa 112 {
1e181c7a
SC
113 if ( show )
114 [m_searchFieldCell resetCancelButtonCell];
115 else
116 [m_searchFieldCell setCancelButtonCell:nil];
117 [m_searchField setNeedsDisplay:YES];
524c47aa 118 }
1e181c7a
SC
119
120 virtual bool IsCancelButtonVisible() const
524c47aa 121 {
1e181c7a 122 return [m_searchFieldCell cancelButtonCell] != nil;
524c47aa
SC
123 }
124
1e181c7a 125 virtual void SetSearchMenu( wxMenu* menu )
524c47aa 126 {
1e181c7a
SC
127 if ( menu )
128 [m_searchFieldCell setSearchMenuTemplate:menu->GetHMenu()];
129 else
130 [m_searchFieldCell setSearchMenuTemplate:nil];
131 [m_searchField setNeedsDisplay:YES];
524c47aa 132 }
524c47aa 133
1e181c7a 134 virtual void SetDescriptiveText(const wxString& text)
524c47aa 135 {
1e181c7a
SC
136 [m_searchFieldCell setPlaceholderString:
137 wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
138 }
139
140 virtual bool SetFocus()
141 {
142 return wxNSTextFieldControl::SetFocus();
524c47aa 143 }
524c47aa 144
1e181c7a
SC
145private:
146 wxNSSearchField* m_searchField;
147 NSSearchFieldCell* m_searchFieldCell;
148} ;
524c47aa 149
1e181c7a 150wxNSSearchFieldControl::~wxNSSearchFieldControl()
524c47aa 151{
524c47aa
SC
152}
153
1e181c7a
SC
154wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer,
155 wxWindowMac* parent,
156 wxWindowID id,
157 const wxString& str,
158 const wxPoint& pos,
159 const wxSize& size,
160 long style,
161 long extraStyle)
524c47aa 162{
1e181c7a
SC
163 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
164 wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r];
1e181c7a
SC
165 [[v cell] setSendsWholeSearchString:YES];
166 // per wx default cancel is not shown
167 [[v cell] setCancelButtonCell:nil];
168
169 wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
170 c->SetStringValue( str );
171 [v setImplementation:c];
172 return c;
524c47aa
SC
173}
174
175#endif // wxUSE_NATIVE_SEARCH_CONTROL
176
177#endif // wxUSE_SEARCHCTRL