X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4d23a0d3a040f773c1211b5e69925a8cd203dfde..95fb31530e382c4b355b0c853121441ec97aec24:/src/osx/cocoa/textctrl.mm diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 308f0b8e9c..fc2169099e 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -128,7 +128,7 @@ } -- (void)controlTextDidChange:(NSNotification *)aNotification +- (void)textDidChange:(NSNotification *)aNotification { if ( impl ) { @@ -141,6 +141,26 @@ } } } + +- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)commandSelector +{ + 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(wxpeer)->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } + } + } + + return NO; +} @end @implementation wxNSTextField @@ -165,6 +185,21 @@ 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 { @@ -180,6 +215,27 @@ } } +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(wxpeer)->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } + } + } + + return NO; +} /* - (void)controlTextDidEndEditing:(NSNotification *)aNotification { @@ -202,7 +258,7 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w) { m_scrollView = (NSScrollView*) w; - [w setImplementation: this]; + [(wxNSTextField*)w setImplementation: this]; [m_scrollView setHasVerticalScroller:YES]; [m_scrollView setHasHorizontalScroller:NO]; @@ -282,7 +338,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) @@ -290,6 +348,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 @@ -377,6 +436,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)