]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/srchctrl.mm
Add wxDataViewCtrl::SetRowHeight() and provide its generic implementation.
[wxWidgets.git] / src / osx / cocoa / srchctrl.mm
index 0ed85e50f37c82a9fa5c8b81f993942cfcf19b0e..e665167688ed04deecc7c221eb190d7b9159e91e 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".
@@ -40,7 +40,7 @@
 + (void)initialize
 {
     static BOOL initialized = NO;
 + (void)initialize
 {
     static BOOL initialized = NO;
-    if (!initialized) 
+    if (!initialized)
     {
         initialized = YES;
         wxOSXCocoaClassAddWXMethods( self );
     {
         initialized = YES;
         wxOSXCocoaClassAddWXMethods( self );
 - (id)initWithFrame:(NSRect)frame
 {
     [super initWithFrame:frame];
 - (id)initWithFrame:(NSRect)frame
 {
     [super initWithFrame:frame];
-    [self setTarget: self];
-    [self setAction: @selector(searchAction:)];
     return self;
 }
     return self;
 }
-
-- (void) searchAction: (id) sender
+- (void)controlTextDidChange:(NSNotification *)aNotification
 {
 {
+    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
@@ -101,7 +110,7 @@ public :
             [m_searchFieldCell setSearchButtonCell:nil];
         [m_searchField setNeedsDisplay:YES];
     }
             [m_searchFieldCell setSearchButtonCell:nil];
         [m_searchField setNeedsDisplay:YES];
     }
-    
+
     virtual bool IsSearchButtonVisible() const
     {
         return [m_searchFieldCell searchButtonCell] != nil;
     virtual bool IsSearchButtonVisible() const
     {
         return [m_searchFieldCell searchButtonCell] != nil;
@@ -115,7 +124,7 @@ public :
             [m_searchFieldCell setCancelButtonCell:nil];
         [m_searchField setNeedsDisplay:YES];
     }
             [m_searchFieldCell setCancelButtonCell:nil];
         [m_searchField setNeedsDisplay:YES];
     }
-    
+
     virtual bool IsCancelButtonVisible() const
     {
         return [m_searchFieldCell cancelButtonCell] != nil;
     virtual bool IsCancelButtonVisible() const
     {
         return [m_searchFieldCell cancelButtonCell] != nil;
@@ -135,12 +144,29 @@ public :
         [m_searchFieldCell setPlaceholderString:
             wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
     }
         [m_searchFieldCell setPlaceholderString:
             wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
     }
-        
+
     virtual bool SetFocus()
     {
        return  wxNSTextFieldControl::SetFocus();
     }
 
     virtual bool 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;
@@ -150,14 +176,14 @@ wxNSSearchFieldControl::~wxNSSearchFieldControl()
 {
 }
 
 {
 }
 
-wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer, 
-                                    wxWindowMac* parent, 
-                                    wxWindowID id, 
+wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxSearchCtrl* wxpeer,
+                                    wxWindowMac* WXUNUSED(parent),
+                                    wxWindowID WXUNUSED(id),
                                     const wxString& str,
                                     const wxString& str,
-                                    const wxPoint& pos, 
+                                    const wxPoint& pos,
                                     const wxSize& size,
                                     const wxSize& size,
-                                    long style, 
-                                    long extraStyle)
+                                    long WXUNUSED(style),
+                                    long WXUNUSED(extraStyle))
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r];
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r];
@@ -165,10 +191,8 @@ wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer,
     // per wx default cancel is not shown
     [[v cell] setCancelButtonCell:nil];
 
     // per wx default cancel is not shown
     [[v cell] setCancelButtonCell:nil];
 
-    [v setBezeled:NO];
-    [v setBordered:NO];
-
     wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
     wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
+    c->SetNeedsFrame( false );
     c->SetStringValue( str );
     return c;
 }
     c->SetStringValue( str );
     return c;
 }