+ 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 < (long) [[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];
+ }
+ else
+ {
+ NSDictionary* attrs = [m_textView typingAttributes];
+ font = [[attrs objectForKey:NSFontAttributeName] autorelease];
+ bgcolor = [[attrs objectForKey:NSBackgroundColorAttributeName] autorelease];
+ fgcolor = [[attrs objectForKey:NSForegroundColorAttributeName] autorelease];
+ }
+
+ if (font)
+ style.SetFont(wxFont(font));
+
+ if (bgcolor)
+ style.SetBackgroundColour(wxColour(bgcolor));
+
+ if (fgcolor)
+ style.SetTextColour(wxColour(fgcolor));
+ return true;
+ }
+
+ return false;
+}
+
+void wxNSTextViewControl::SetStyle(long start,
+ long end,
+ const wxTextAttr& style)
+{
+ if ( !m_textView )
+ return;
+
+ if ( start == -1 && end == -1 )
+ {
+ NSMutableDictionary* const
+ attrs = [NSMutableDictionary dictionaryWithCapacity:3];
+ if ( style.HasFont() )
+ [attrs setValue:style.GetFont().OSXGetNSFont() forKey:NSFontAttributeName];
+ if ( style.HasBackgroundColour() )
+ [attrs setValue:style.GetBackgroundColour().OSXGetNSColor() forKey:NSBackgroundColorAttributeName];
+ if ( style.HasTextColour() )
+ [attrs setValue:style.GetTextColour().OSXGetNSColor() forKey:NSForegroundColorAttributeName];
+
+ [m_textView setTypingAttributes:attrs];
+ }
+ else // Set the attributes just for this range.
+ {
+ NSRange range = NSMakeRange(start, end-start);
+
+ NSTextStorage* storage = [m_textView textStorage];
+ if ( style.HasFont() )
+ [storage addAttribute:NSFontAttributeName value:style.GetFont().OSXGetNSFont() range:range];
+
+ if ( style.HasBackgroundColour() )
+ [storage addAttribute:NSBackgroundColorAttributeName value:style.GetBackgroundColour().OSXGetNSColor() range:range];
+
+ if ( style.HasTextColour() )
+ [storage addAttribute:NSForegroundColorAttributeName value:style.GetTextColour().OSXGetNSColor() range:range];
+ }
+}
+
+void wxNSTextViewControl::CheckSpelling(bool check)
+{
+ if (m_textView)
+ [m_textView setContinuousSpellCheckingEnabled: check];