X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c824c165b17ef3f87d44236c86c1013276da5498..aa6208d975c3757d75d780c661b4d7918236f4fb:/src/osx/cocoa/textctrl.mm diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index b23dfd38a2..8ad2937d97 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -50,7 +50,8 @@ #include "wx/osx/cocoa/private/textimpl.h" @interface wxNSSecureTextField : NSSecureTextField - +{ +} @end @implementation wxNSSecureTextField @@ -65,9 +66,27 @@ } } +- (void)controlTextDidChange:(NSNotification *)aNotification +{ + wxUnusedVar(aNotification); + wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if ( impl ) + { + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); + if ( wxpeer ) { + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + event.SetString( static_cast(wxpeer)->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } + } +} + @end @interface wxNSTextView : NSScrollView +{ +} @end @@ -83,6 +102,43 @@ } } +- (void)textDidChange:(NSNotification *)aNotification +{ + wxUnusedVar(aNotification); + wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if ( impl ) + { + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); + if ( wxpeer ) { + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + event.SetString( static_cast(wxpeer)->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } + } +} + +- (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(wxpeer)->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } + } + } + + return NO; +} @end @implementation wxNSTextField @@ -97,9 +153,26 @@ } } -/* +- (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 { + wxUnusedVar(aNotification); + wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if ( impl ) { wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); @@ -112,6 +185,31 @@ } } +typedef BOOL (*wxOSX_insertNewlineHandlerPtr)(NSView* self, SEL _cmd, NSControl *control, NSTextView* textView, SEL commandSelector); + +- (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(); + 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 { if ( impl ) @@ -212,7 +310,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 +320,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,9 +408,11 @@ 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) +void wxNSTextFieldControl::controlAction(WXWidget WXUNUSED(slf), + void* WXUNUSED(_cmd), void *WXUNUSED(sender)) { wxWindow* wxpeer = (wxWindow*) GetWXPeer(); if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) ) @@ -326,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(c)->SetStringValue(str); } else { + NSTextField* v = nil; if ( style & wxTE_PASSWORD ) v = [[wxNSSecureTextField alloc] initWithFrame:r]; else