]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/cocoa/srchctrl.mm
add alignment flags support to wxSpinCtrl[Double] (closes #10621)
[wxWidgets.git] / src / osx / cocoa / srchctrl.mm
... / ...
CommitLineData
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
28#include "wx/osx/private.h"
29#include "wx/osx/cocoa/private/textimpl.h"
30
31
32@interface wxNSSearchField : NSSearchField
33{
34}
35
36@end
37
38@implementation wxNSSearchField
39
40+ (void)initialize
41{
42 static BOOL initialized = NO;
43 if (!initialized)
44 {
45 initialized = YES;
46 wxOSXCocoaClassAddWXMethods( self );
47 }
48}
49
50- (id)initWithFrame:(NSRect)frame
51{
52 [super initWithFrame:frame];
53 [self setTarget: self];
54 [self setAction: @selector(searchAction:)];
55 return self;
56}
57
58- (void) searchAction: (id) sender
59{
60 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
61 if ( impl )
62 {
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 }
76 }
77}
78
79@end
80
81// ============================================================================
82// wxMacSearchFieldControl
83// ============================================================================
84
85class wxNSSearchFieldControl : public wxNSTextFieldControl, public wxSearchWidgetImpl
86{
87public :
88 wxNSSearchFieldControl( wxTextCtrl *wxPeer, wxNSSearchField* w ) : wxNSTextFieldControl(wxPeer, w)
89 {
90 m_searchFieldCell = [w cell];
91 m_searchField = w;
92 }
93 ~wxNSSearchFieldControl();
94
95 // search field options
96 virtual void ShowSearchButton( bool show )
97 {
98 if ( show )
99 [m_searchFieldCell resetSearchButtonCell];
100 else
101 [m_searchFieldCell setSearchButtonCell:nil];
102 [m_searchField setNeedsDisplay:YES];
103 }
104
105 virtual bool IsSearchButtonVisible() const
106 {
107 return [m_searchFieldCell searchButtonCell] != nil;
108 }
109
110 virtual void ShowCancelButton( bool show )
111 {
112 if ( show )
113 [m_searchFieldCell resetCancelButtonCell];
114 else
115 [m_searchFieldCell setCancelButtonCell:nil];
116 [m_searchField setNeedsDisplay:YES];
117 }
118
119 virtual bool IsCancelButtonVisible() const
120 {
121 return [m_searchFieldCell cancelButtonCell] != nil;
122 }
123
124 virtual void SetSearchMenu( wxMenu* menu )
125 {
126 if ( menu )
127 [m_searchFieldCell setSearchMenuTemplate:menu->GetHMenu()];
128 else
129 [m_searchFieldCell setSearchMenuTemplate:nil];
130 [m_searchField setNeedsDisplay:YES];
131 }
132
133 virtual void SetDescriptiveText(const wxString& text)
134 {
135 [m_searchFieldCell setPlaceholderString:
136 wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
137 }
138
139 virtual bool SetFocus()
140 {
141 return wxNSTextFieldControl::SetFocus();
142 }
143
144private:
145 wxNSSearchField* m_searchField;
146 NSSearchFieldCell* m_searchFieldCell;
147} ;
148
149wxNSSearchFieldControl::~wxNSSearchFieldControl()
150{
151}
152
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)
161{
162 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
163 wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r];
164 [[v cell] setSendsWholeSearchString:YES];
165 // per wx default cancel is not shown
166 [[v cell] setCancelButtonCell:nil];
167
168 wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
169 c->SetNeedsFrame( false );
170 c->SetStringValue( str );
171 return c;
172}
173
174#endif // wxUSE_NATIVE_SEARCH_CONTROL
175
176#endif // wxUSE_SEARCHCTRL