]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/textctrl.mm
restore passing WM_COMMAND messages for SC_XXX commands to DefFrameProc() in wxMDIPar...
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
index b23dfd38a2db0db4dcda3fb4cd876dcaa58ea346..208d4cebd018db9af83446c68b19f8234b5cfeec 100644 (file)
 #include "wx/osx/cocoa/private/textimpl.h"
 
 @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
+{
+    if ( impl )
+    {
+        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        if ( wxpeer ) {
+            wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
+            event.SetEventObject( wxpeer );
+            event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
+            wxpeer->HandleWindowEvent( event );
+        }
+    }
+}
+
 @end
 
 @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
+{
+    if ( impl )
+    {
+        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        if ( wxpeer ) {
+            wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
+            event.SetEventObject( wxpeer );
+            event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
+            wxpeer->HandleWindowEvent( event );
+        }
+    }
+}
 @end
 
 @implementation wxNSTextField
     }
 }
 
-/*
+- (wxWidgetCocoaImpl*) implementation
+{
+    return impl;
+}
+
+- (void) setImplementation:(wxWidgetCocoaImpl*) item
+{
+    impl = item;
+}
+
+- (void) setEnabled:(BOOL) flag
+{
+    [super setEnabled: flag];
+
+    if (![self drawsBackground]) {
+        // Static text is drawn incorrectly when disabled.
+        // For an explanation, see
+        // http://www.cocoabuilder.com/archive/message/cocoa/2006/7/21/168028
+        if (flag) {
+            [self setTextColor: [NSColor controlTextColor]];
+        } else {
+            [self setTextColor: [NSColor secondarySelectedControlColor]];
+        }
+    }
+}
+
 - (void)controlTextDidChange:(NSNotification *)aNotification
 {
     if ( impl )
     }
 }
 
+typedef BOOL (*wxOSX_insertNewlineHandlerPtr)(NSView* self, SEL _cmd, NSControl *control, NSTextView* textView, SEL commandSelector);
+
+- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
+{
+    if (commandSelector == @selector(insertNewline:))
+    {
+        if ( impl  )
+        {
+            wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+            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;
+}
+/*
 - (void)controlTextDidEndEditing:(NSNotification *)aNotification
 {
     if ( impl )
 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];
@@ -212,7 +318,9 @@ void wxNSTextViewControl::GetSelection( long* from, long* to) const
 
 void wxNSTextViewControl::SetSelection( long from , long to )
 {
-    [m_textView setSelectedRange:NSMakeRange(from, to-from)];
+    NSRange selrange = NSMakeRange(from, to-from);
+    [m_textView setSelectedRange:selrange];
+    [m_textView scrollRangeToVisible:selrange];
 }
 
 void wxNSTextViewControl::WriteText(const wxString& str) 
@@ -220,6 +328,7 @@ void wxNSTextViewControl::WriteText(const wxString& str)
     // temp hack to get logging working early
     wxString former = GetStringValue();
     SetStringValue( former + str );
+    SetSelection(GetStringValue().length(), GetStringValue().length());
 }
 
 // wxNSTextFieldControl
@@ -307,6 +416,7 @@ void wxNSTextFieldControl::WriteText(const wxString& str)
     // temp hack to get logging working early
     wxString former = GetStringValue();
     SetStringValue( former + str );
+    SetSelection(GetStringValue().length(), GetStringValue().length());
 }
 
 void wxNSTextFieldControl::controlAction(WXWidget slf, void* _cmd, void *sender)
@@ -361,6 +471,7 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
         [v setBordered:NO];
         
         c = new wxNSTextFieldControl( wxpeer, v );
+        [v setImplementation: c];
         static_cast<wxNSTextFieldControl*>(c)->SetStringValue(str);
     }