]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/textctrl.mm
making sure creation is setup correctly for wx-frame coordinates into cocoa-content...
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
index 2c91b8bc273ad330a84d536e67fc3548220d4f3e..3a0f1c19790c44b67ddbcb3bf3fbd666d644b8d5 100644 (file)
@@ -429,6 +429,45 @@ void wxNSTextViewControl::SetFont( const wxFont & font , const wxColour& WXUNUSE
         [m_textView setFont: font.OSXGetNSFont()];
 }
 
+bool wxNSTextViewControl::GetStyle(long position, wxTextAttr& style)
+{
+    if (m_textView && position >=0 && position < [[m_textView string] length]) {
+        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