+// wxNSTextViewControl
+
+wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w )
+ : wxWidgetCocoaImpl(wxPeer, w),
+ wxTextWidgetImpl(wxPeer)
+{
+ wxNSTextScrollView* sv = (wxNSTextScrollView*) w;
+ m_scrollView = sv;
+
+ [m_scrollView setHasVerticalScroller:YES];
+ [m_scrollView setHasHorizontalScroller:NO];
+ [m_scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+ NSSize contentSize = [m_scrollView contentSize];
+
+ wxNSTextView* tv = [[wxNSTextView alloc] initWithFrame: NSMakeRect(0, 0,
+ contentSize.width, contentSize.height)];
+ m_textView = tv;
+ [tv setVerticallyResizable:YES];
+ [tv setHorizontallyResizable:NO];
+ [tv setAutoresizingMask:NSViewWidthSizable];
+
+ [m_scrollView setDocumentView: tv];
+
+ [tv setDelegate: tv];
+
+ InstallEventHandler(tv);
+}
+
+wxNSTextViewControl::~wxNSTextViewControl()
+{
+ if (m_textView)
+ [m_textView setDelegate: nil];
+}
+
+bool wxNSTextViewControl::CanFocus() const
+{
+ // since this doesn't work (return false), we hardcode
+ // if (m_textView)
+ // return [m_textView canBecomeKeyView];
+ return true;
+}
+
+wxString wxNSTextViewControl::GetStringValue() const
+{
+ if (m_textView)
+ {
+ 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) )