From 5f65ba36570e9cf4296673391472cf11b9f0c673 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 20 Apr 2009 19:23:57 +0000 Subject: [PATCH] content must be changeable by wx even though control may be disabled git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60258 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/textctrl.mm | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 32717d37d0..a8537ae536 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -49,6 +49,35 @@ #include "wx/osx/private.h" #include "wx/osx/cocoa/private/textimpl.h" +@interface NSView(EditableView) +- (BOOL)isEditable; +- (void)setEditable:(BOOL)flag; +@end + +class wxMacEditHelper +{ +public : + wxMacEditHelper( NSView* textView ) + { + m_textView = textView ; + if ( textView ) + { + m_formerState = [textView isEditable]; + [textView setEditable:YES]; + } + } + + ~wxMacEditHelper() + { + if ( m_textView ) + [m_textView setEditable:m_formerState]; + } + +protected : + BOOL m_formerState ; + NSView* m_textView; +} ; + @interface wxNSSecureTextField : NSSecureTextField { } @@ -324,6 +353,7 @@ void wxNSTextViewControl::SetStringValue( const wxString &str) { wxString st = str; wxMacConvertNewlines10To13( &st ); + wxMacEditHelper helper(m_textView); if (m_textView) [m_textView setString: wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; @@ -394,7 +424,8 @@ void wxNSTextViewControl::WriteText(const wxString& str) { wxString st = str; wxMacConvertNewlines10To13( &st ); - + wxMacEditHelper helper(m_textView); + [m_textView insertText:wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; } @@ -421,6 +452,7 @@ wxString wxNSTextFieldControl::GetStringValue() const void wxNSTextFieldControl::SetStringValue( const wxString &str) { + wxMacEditHelper helper(m_textField); [m_textField setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; } @@ -511,6 +543,7 @@ void wxNSTextFieldControl::WriteText(const wxString& str) NSText* editor = [m_textField currentEditor]; if ( editor ) { + wxMacEditHelper helper(m_textField); [editor insertText:wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; } else -- 2.47.2