]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/srchctrl.mm
Correctly align background brush when erasing owner drawn bitmaps in wxMSW.
[wxWidgets.git] / src / osx / cocoa / srchctrl.mm
index 0c33e9859943fb46c37892f1b5ddc60622387443..c9b722d727ecfe248468a5534d045b33f8f0c60c 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
-// RCS-ID:      $Id: srchctrl.cpp 54820 2008-07-29 20:04:11Z SC $
+// RCS-ID:      $Id$
 // Copyright:   Vince Harron
-// License:     wxWindows licence
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx.h".
 
 @interface wxNSSearchField : NSSearchField
 {
-    wxWidgetImpl* impl;
 }
 
 @end
 
 @implementation wxNSSearchField
 
-- (id)initWithFrame:(NSRect)frame
++ (void)initialize
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(searchAction:)];
-    return self;
-}
-
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
+    static BOOL initialized = NO;
+    if (!initialized)
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
 }
 
-// use our common calls
-- (void) setTitle:(NSString *) title
+- (id)initWithFrame:(NSRect)frame
 {
-    [self setStringValue: title];
+    [super initWithFrame:frame];
+    return self;
 }
-
-- (void) searchAction: (id) sender
+- (void)controlTextDidChange:(NSNotification *)aNotification
 {
+    wxUnusedVar(aNotification);
+    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();
 }
 
 @end
@@ -113,7 +86,7 @@ public :
             [m_searchFieldCell setSearchButtonCell:nil];
         [m_searchField setNeedsDisplay:YES];
     }
-    
+
     virtual bool IsSearchButtonVisible() const
     {
         return [m_searchFieldCell searchButtonCell] != nil;
@@ -127,7 +100,7 @@ public :
             [m_searchFieldCell setCancelButtonCell:nil];
         [m_searchField setNeedsDisplay:YES];
     }
-    
+
     virtual bool IsCancelButtonVisible() const
     {
         return [m_searchFieldCell cancelButtonCell] != nil;
@@ -147,12 +120,29 @@ public :
         [m_searchFieldCell setPlaceholderString:
             wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
     }
-        
+
     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;
@@ -162,27 +152,24 @@ 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 wxPoint& pos, 
+                                    const wxPoint& pos,
                                     const wxSize& size,
-                                    long style, 
-                                    long extraStyle)
+                                    long WXUNUSED(style),
+                                    long WXUNUSED(extraStyle))
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r];
-    [sv addSubview:v];
     [[v cell] setSendsWholeSearchString:YES];
     // per wx default cancel is not shown
     [[v cell] setCancelButtonCell:nil];
 
     wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
+    c->SetNeedsFrame( false );
     c->SetStringValue( str );
-    [v setImplementation:c];
     return c;
 }