]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/srchctrl.mm
guarding open combo box against AppDefined NSEvents issued by wxEventLoop::WakeUp...
[wxWidgets.git] / src / osx / cocoa / srchctrl.mm
index 399729c1832fccec8b4e55530a4e015c769b39b6..567789a2e988fc4a4483d50691e8c05987826d3b 100644 (file)
@@ -1,11 +1,11 @@
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        src/osx/carbon/srchctrl.cpp
+// Name:        src/osx/cocoa/srchctrl.mm
 // Purpose:     implements mac carbon wxSearchCtrl
 // Author:      Vince Harron
 // Created:     2006-02-19
 // 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
 // Copyright:   Vince Harron
-// License:     wxWindows licence
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx.h".
 ///////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx.h".
 
 - (id)initWithFrame:(NSRect)frame
 {
 
 - (id)initWithFrame:(NSRect)frame
 {
-    [super initWithFrame:frame];
-    [self setTarget: self];
-    [self setAction: @selector(searchAction:)];
+    self = [super initWithFrame:frame];
     return self;
 }
     return self;
 }
-
-- (void) searchAction: (id) sender
+- (void)controlTextDidChange:(NSNotification *)aNotification
 {
 {
-    (void) sender;
+    wxUnusedVar(aNotification);
     wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
     if ( impl )
     wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
     if ( impl )
-    {
-        wxSearchCtrl* wxpeer = dynamic_cast<wxSearchCtrl*>( impl->GetWXPeer() );
-        if ( wxpeer )
-        {
-            NSString *searchString = [self stringValue];
-            if ( searchString == nil )
-            {
-                wxpeer->HandleSearchFieldCancelHit();
-            }
-            else
-            {
-                wxpeer->HandleSearchFieldSearchHit();
-            }
-        }
-    }
+        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
 }
 
 @end
@@ -142,6 +150,23 @@ public :
        return  wxNSTextFieldControl::SetFocus();
     }
 
        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;
 private:
     wxNSSearchField* m_searchField;
     NSSearchFieldCell* m_searchFieldCell;
@@ -151,7 +176,7 @@ wxNSSearchFieldControl::~wxNSSearchFieldControl()
 {
 }
 
 {
 }
 
-wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer,
+wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxSearchCtrl* wxpeer,
                                     wxWindowMac* WXUNUSED(parent),
                                     wxWindowID WXUNUSED(id),
                                     const wxString& str,
                                     wxWindowMac* WXUNUSED(parent),
                                     wxWindowID WXUNUSED(id),
                                     const wxString& str,