X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/526954c5968baa29218c994ec48e476ae2bd4b9f..0afeb753e0a6a3fdba290bf3612bb2f012d44d95:/src/osx/cocoa/srchctrl.mm diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm index d19b37c564..567789a2e9 100644 --- a/src/osx/cocoa/srchctrl.mm +++ b/src/osx/cocoa/srchctrl.mm @@ -1,9 +1,9 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/osx/carbon/srchctrl.cpp +// Name: src/osx/cocoa/srchctrl.mm // Purpose: implements mac carbon wxSearchCtrl // Author: Vince Harron // Created: 2006-02-19 -// RCS-ID: $Id: srchctrl.cpp 54820 2008-07-29 20:04:11Z SC $ +// RCS-ID: $Id$ // Copyright: Vince Harron // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -49,34 +49,10 @@ - (id)initWithFrame:(NSRect)frame { - [super initWithFrame:frame]; - [self setTarget: self]; - [self setAction: @selector(searchAction:)]; + self = [super initWithFrame:frame]; return self; } - -- (void) searchAction: (id) sender -{ - (void) sender; - wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); - if ( impl ) - { - wxSearchCtrl* wxpeer = dynamic_cast( impl->GetWXPeer() ); - if ( wxpeer ) - { - NSString *searchString = [self stringValue]; - if ( searchString == nil ) - { - wxpeer->HandleSearchFieldCancelHit(); - } - else - { - wxpeer->HandleSearchFieldSearchHit(); - } - } - } -} - + - (void)controlTextDidChange:(NSNotification *)aNotification { wxUnusedVar(aNotification); @@ -85,6 +61,30 @@ impl->controlTextDidChange(); } +- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words + forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int*)index +{ + NSMutableArray* matches = NULL; + NSString* partialString; + + partialString = [[textView string] substringWithRange:charRange]; + matches = [NSMutableArray array]; + + // wxTextWidgetImpl* impl = (wxTextWidgetImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + wxArrayString completions; + + // adapt to whatever strategy we have for getting the strings + // impl->GetTextEntry()->GetCompletions(wxCFStringRef::AsString(partialString), completions); + + for (size_t i = 0; i < completions.GetCount(); ++i ) + [matches addObject: wxCFStringRef(completions[i]).AsNSString()]; + + // [matches sortUsingSelector:@selector(compare:)]; + + + return matches; +} + @end // ============================================================================ @@ -150,6 +150,23 @@ public : return wxNSTextFieldControl::SetFocus(); } + void controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender)) + { + wxSearchCtrl* wxpeer = (wxSearchCtrl*) GetWXPeer(); + if ( wxpeer ) + { + NSString *searchString = [m_searchField stringValue]; + if ( searchString == nil ) + { + wxpeer->HandleSearchFieldCancelHit(); + } + else + { + wxpeer->HandleSearchFieldSearchHit(); + } + } + } + private: wxNSSearchField* m_searchField; NSSearchFieldCell* m_searchFieldCell; @@ -159,7 +176,7 @@ wxNSSearchFieldControl::~wxNSSearchFieldControl() { } -wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer, +wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxSearchCtrl* wxpeer, wxWindowMac* WXUNUSED(parent), wxWindowID WXUNUSED(id), const wxString& str,