]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/textctrl.mm
focus handling streamlined
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
index 208d4cebd018db9af83446c68b19f8234b5cfeec..8ad2937d9771ee41ee3b8403a6ca9ba63ea2b47b 100644 (file)
 
 @interface wxNSSecureTextField : NSSecureTextField
 {
-    wxWidgetCocoaImpl* impl;
 }
-
-- (void) setImplementation:(wxWidgetCocoaImpl*) item;
-- (wxWidgetCocoaImpl*) implementation;
 @end
 
 @implementation wxNSSecureTextField 
     }
 }
 
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (void) setImplementation:(wxWidgetCocoaImpl*) item
-{
-    impl = item;
-}
-
 - (void)controlTextDidChange:(NSNotification *)aNotification
 {
+    wxUnusedVar(aNotification);
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
     if ( impl )
     {
         wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
 
 @interface wxNSTextView : NSScrollView
 {
-    wxWidgetCocoaImpl* impl;
 }
 
-- (void) setImplementation:(wxWidgetCocoaImpl*) item;
-- (wxWidgetCocoaImpl*) implementation;
 @end
 
 @implementation wxNSTextView
     }
 }
 
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (void) setImplementation:(wxWidgetCocoaImpl*) item
-{
-    impl = item;
-}
-
-
-- (void)controlTextDidChange:(NSNotification *)aNotification
+- (void)textDidChange:(NSNotification *)aNotification
 {
+    wxUnusedVar(aNotification);
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
     if ( impl )
     {
         wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
         }
     }
 }
+
+- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)commandSelector
+{
+    wxUnusedVar(aTextView);
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if ( impl  )
+    {
+        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        if (commandSelector == @selector(insertNewline:))
+        {
+            if ( wxpeer && wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER ) 
+            {
+                wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
+                event.SetEventObject( wxpeer );
+                event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
+                wxpeer->HandleWindowEvent( event );
+            }
+        }
+    }
+    
+    return NO;
+}
 @end
 
 @implementation wxNSTextField
     }
 }
 
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (void) setImplementation:(wxWidgetCocoaImpl*) item
-{
-    impl = item;
-}
-
 - (void) setEnabled:(BOOL) flag
 {
     [super setEnabled: flag];
 
 - (void)controlTextDidChange:(NSNotification *)aNotification
 {
+    wxUnusedVar(aNotification);
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
     if ( impl )
     {
         wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
@@ -199,8 +189,11 @@ typedef BOOL (*wxOSX_insertNewlineHandlerPtr)(NSView* self, SEL _cmd, NSControl
 
 - (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
 {
+    wxUnusedVar(textView);
+    wxUnusedVar(control);
     if (commandSelector == @selector(insertNewline:))
     {
+        wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
         if ( impl  )
         {
             wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
@@ -238,7 +231,6 @@ typedef BOOL (*wxOSX_insertNewlineHandlerPtr)(NSView* self, SEL _cmd, NSControl
 wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
 {
     m_scrollView = (NSScrollView*) w;
-    [(wxNSTextField*)w setImplementation: this];
     
     [m_scrollView setHasVerticalScroller:YES];
     [m_scrollView setHasHorizontalScroller:NO];
@@ -419,7 +411,8 @@ void wxNSTextFieldControl::WriteText(const wxString& str)
     SetSelection(GetStringValue().length(), GetStringValue().length());
 }
 
-void wxNSTextFieldControl::controlAction(WXWidget slf, void* _cmd, void *sender)
+void wxNSTextFieldControl::controlAction(WXWidget WXUNUSED(slf), 
+    void* WXUNUSED(_cmd), void *WXUNUSED(sender))
 {
     wxWindow* wxpeer = (wxWindow*) GetWXPeer();
     if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) ) 
@@ -436,26 +429,27 @@ void wxNSTextFieldControl::controlAction(WXWidget slf, void* _cmd, void *sender)
 //
 
 wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, 
-                                    wxWindowMac* parent
-                                    wxWindowID id
+                                    wxWindowMac* WXUNUSED(parent)
+                                    wxWindowID WXUNUSED(id)
                                     const wxString& str,
                                     const wxPoint& pos, 
                                     const wxSize& size,
                                     long style, 
-                                    long extraStyle)
+                                    long WXUNUSED(extraStyle))
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
-    NSTextField* v = nil;
     wxWidgetCocoaImpl* c = NULL;
     
     if ( style & wxTE_MULTILINE || style & wxTE_RICH || style & wxTE_RICH2 )
     {
+        wxNSTextView* v = nil;
         v = [[wxNSTextView alloc] initWithFrame:r];
         c = new wxNSTextViewControl( wxpeer, v );
         static_cast<wxNSTextViewControl*>(c)->SetStringValue(str);
     }
     else 
     {
+        NSTextField* v = nil;
         if ( style & wxTE_PASSWORD )
             v = [[wxNSSecureTextField alloc] initWithFrame:r];
         else
@@ -471,7 +465,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
         [v setBordered:NO];
         
         c = new wxNSTextFieldControl( wxpeer, v );
-        [v setImplementation: c];
         static_cast<wxNSTextFieldControl*>(c)->SetStringValue(str);
     }