]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/textctrl.mm
Big wxDataViewCtrl renderer classes refactoring.
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
index 13b2d9789769abd3fe80293cbd76120c557e70ed..e0bdfdfd20cb7544c0997f7a9ae7fd65d46be696 100644 (file)
@@ -59,7 +59,8 @@ class wxMacEditHelper
 public :
     wxMacEditHelper( NSView* textView )
     {
-        m_textView = textView ;
+        m_textView = textView;
+        m_formerState = YES;
         if ( textView )
         {
             m_formerState = [textView isEditable];
@@ -422,12 +423,51 @@ void wxNSTextViewControl::WriteText(const wxString& str)
     m_lastKeyDownEvent = formerEvent;
 }
 
-void wxNSTextViewControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack )
+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) {
+        NSTextStorage* storage = [m_textView textStorage];
+        NSFont* font = [storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL];
+        if (font)
+            style.SetFont(wxFont(font));
+        NSColor* bgcolor = [storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL];
+        if (bgcolor)
+            style.SetBackgroundColour(wxColour(bgcolor));
+        NSColor* fgcolor = [storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL];
+        style.SetTextColour(wxColour(fgcolor));
+        return true;
+    }
+
+    return false;
+}
+
+void wxNSTextViewControl::SetStyle(long start,
+                                long end,
+                                const wxTextAttr& style)
+{
+    if (m_textView) {
+        NSRange range = NSMakeRange(start, end-start);
+        NSTextStorage* storage = [m_textView textStorage];
+        
+        wxFont font = style.GetFont();
+        if (font.IsOk())
+            [storage addAttribute:NSFontAttributeName value:style.GetFont().OSXGetNSFont() range:range];
+        
+        wxColour bgcolor = style.GetBackgroundColour();
+        if (bgcolor.IsOk())
+            [storage addAttribute:NSBackgroundColorAttributeName value:bgcolor.OSXGetNSColor() range:range];
+        
+        wxColour fgcolor = style.GetTextColour();
+        if (fgcolor.IsOk())
+            [storage addAttribute:NSForegroundColorAttributeName value:fgcolor.OSXGetNSColor() range:range];
+    }
+}
 
 // wxNSTextFieldControl
 
@@ -581,7 +621,7 @@ void wxNSTextFieldControl::controlAction(WXWidget WXUNUSED(slf),
 wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
                                     wxWindowMac* WXUNUSED(parent),
                                     wxWindowID WXUNUSED(id),
-                                    const wxString& str,
+                                    const wxString& WXUNUSED(str),
                                     const wxPoint& pos,
                                     const wxSize& size,
                                     long style,
@@ -595,7 +635,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
         wxNSTextScrollView* v = nil;
         v = [[wxNSTextScrollView alloc] initWithFrame:r];
         c = new wxNSTextViewControl( wxpeer, v );
-        static_cast<wxNSTextViewControl*>(c)->SetStringValue(str);
     }
     else
     {
@@ -615,7 +654,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
         [v setBordered:NO];
 
         c = new wxNSTextFieldControl( wxpeer, v );
-        static_cast<wxNSTextFieldControl*>(c)->SetStringValue(str);
     }
 
     return c;