+void wxNSTextViewControl::SetStyle(long start,
+ long end,
+ const wxTextAttr& style)
+{
+ if (m_textView) {
+ NSRange range = NSMakeRange(start, end-start);
+ if (start == -1 && end == -1)
+ range = [m_textView selectedRange];
+
+ NSTextStorage* storage = [m_textView textStorage];
+
+ wxFont font = style.GetFont();
+ if (style.HasFont() && font.IsOk())
+ [storage addAttribute:NSFontAttributeName value:font.OSXGetNSFont() range:range];
+
+ wxColour bgcolor = style.GetBackgroundColour();
+ if (style.HasBackgroundColour() && bgcolor.IsOk())
+ [storage addAttribute:NSBackgroundColorAttributeName value:bgcolor.OSXGetNSColor() range:range];
+
+ wxColour fgcolor = style.GetTextColour();
+ if (style.HasTextColour() && fgcolor.IsOk())
+ [storage addAttribute:NSForegroundColorAttributeName value:fgcolor.OSXGetNSColor() range:range];
+ }
+}
+
+void wxNSTextViewControl::CheckSpelling(bool check)
+{
+ if (m_textView)
+ [m_textView setContinuousSpellCheckingEnabled: check];
+}
+
+wxSize wxNSTextViewControl::GetBestSize() const
+{
+ if (m_textView && [m_textView layoutManager])
+ {
+ NSRect rect = [[m_textView layoutManager] usedRectForTextContainer: [m_textView textContainer]];
+ return wxSize((int)(rect.size.width + [m_textView textContainerInset].width),
+ (int)(rect.size.height + [m_textView textContainerInset].height));
+ }
+ return wxSize(0,0);
+}
+
+// wxNSTextFieldControl
+
+wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *text, WXWidget w )
+ : wxWidgetCocoaImpl(text, w),
+ wxTextWidgetImpl(text)
+{
+ Init(w);
+}
+
+wxNSTextFieldControl::wxNSTextFieldControl(wxWindow *wxPeer,
+ wxTextEntry *entry,
+ WXWidget w)
+ : wxWidgetCocoaImpl(wxPeer, w),
+ wxTextWidgetImpl(entry)
+{
+ Init(w);
+}
+
+void wxNSTextFieldControl::Init(WXWidget w)
+{
+ NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>) *tf = (NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)*) w;
+ m_textField = tf;
+ [m_textField setDelegate: tf];
+ m_selStart = m_selEnd = 0;
+ m_hasEditor = [w isKindOfClass:[NSTextField class]];
+}
+
+wxNSTextFieldControl::~wxNSTextFieldControl()
+{
+ if (m_textField)
+ [m_textField setDelegate: nil];
+}
+
+wxString wxNSTextFieldControl::GetStringValue() const
+{
+ return wxCFStringRef::AsString([m_textField stringValue], m_wxPeer->GetFont().GetEncoding());
+}
+
+void wxNSTextFieldControl::SetStringValue( const wxString &str)
+{
+ wxMacEditHelper helper(m_textField);
+ [m_textField setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
+}
+
+void wxNSTextFieldControl::SetMaxLength(unsigned long len)
+{
+ wxMaximumLengthFormatter* formatter = [[[wxMaximumLengthFormatter alloc] init] autorelease];
+ [formatter setMaxLength:len];
+ [m_textField setFormatter:formatter];
+}
+
+void wxNSTextFieldControl::Copy()
+{
+ NSText* editor = [m_textField currentEditor];
+ if ( editor )
+ {
+ [editor copy:nil];
+ }
+}
+
+void wxNSTextFieldControl::Cut()
+{
+ NSText* editor = [m_textField currentEditor];
+ if ( editor )
+ {
+ [editor cut:nil];
+ }
+}
+
+void wxNSTextFieldControl::Paste()
+{
+ NSText* editor = [m_textField currentEditor];
+ if ( editor )
+ {
+ [editor paste:nil];
+ }
+}
+
+bool wxNSTextFieldControl::CanPaste() const
+{
+ return true;
+}
+
+void wxNSTextFieldControl::SetEditable(bool editable)