+ wxString result = wxCFStringRef::AsString([m_textView string], m_wxPeer->GetFont().GetEncoding());
+ wxMacConvertNewlines13To10( &result ) ;
+ return result;
+ }
+ return wxEmptyString;
+}
+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()];
+}
+
+void wxNSTextViewControl::Copy()
+{
+ if (m_textView)
+ [m_textView copy:nil];
+
+}
+
+void wxNSTextViewControl::Cut()
+{
+ if (m_textView)
+ [m_textView cut:nil];
+}
+
+void wxNSTextViewControl::Paste()
+{
+ if (m_textView)
+ [m_textView paste:nil];
+}
+
+bool wxNSTextViewControl::CanPaste() const
+{
+ return true;
+}
+
+void wxNSTextViewControl::SetEditable(bool editable)
+{
+ if (m_textView)
+ [m_textView setEditable: editable];
+}
+
+void wxNSTextViewControl::GetSelection( long* from, long* to) const
+{
+ if (m_textView)
+ {
+ NSRange range = [m_textView selectedRange];
+ *from = range.location;
+ *to = range.location + range.length;
+ }
+}
+
+void wxNSTextViewControl::SetSelection( long from , long to )
+{
+ long textLength = [[m_textView string] length];
+ if ((from == -1) && (to == -1))
+ {
+ from = 0 ;
+ to = textLength ;
+ }
+ else
+ {
+ from = wxMin(textLength,wxMax(from,0)) ;
+ if ( to == -1 )
+ to = textLength;
+ else
+ to = wxMax(0,wxMin(textLength,to)) ;
+ }
+
+ NSRange selrange = NSMakeRange(from, to-from);
+ [m_textView setSelectedRange:selrange];
+ [m_textView scrollRangeToVisible:selrange];
+}
+
+void wxNSTextViewControl::WriteText(const wxString& str)
+{
+ wxString st = str;
+ wxMacConvertNewlines10To13( &st );
+ wxMacEditHelper helper(m_textView);
+ NSEvent* formerEvent = m_lastKeyDownEvent;
+ m_lastKeyDownEvent = nil;
+ [m_textView insertText:wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
+ m_lastKeyDownEvent = formerEvent;
+}
+
+void wxNSTextViewControl::SetFont( const wxFont & font , const wxColour& WXUNUSED(foreground) , long WXUNUSED(windowStyle), bool WXUNUSED(ignoreBlack) )
+{
+ if ([m_textView respondsToSelector:@selector(setFont:)])
+ [m_textView setFont: font.OSXGetNSFont()];
+}
+
+bool wxNSTextViewControl::GetStyle(long position, wxTextAttr& style)
+{
+ if (m_textView && position >=0)
+ {
+ NSFont* font = NULL;
+ NSColor* bgcolor = NULL;
+ NSColor* fgcolor = NULL;
+ // NOTE: It appears that other platforms accept GetStyle with the position == length
+ // but that NSTextStorage does not accept length as a valid position.
+ // Therefore we return the default control style in that case.
+ if (position < [[m_textView string] length])
+ {
+ NSTextStorage* storage = [m_textView textStorage];
+ font = [[storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL] autorelease];
+ bgcolor = [[storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
+ fgcolor = [[storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];