MacOSLib has this as a TextArea extension so it’s just
myTextArea.FontBackgroundColor(1, 2, &cFF0000)
I think that’ll only work for 32bit, untested.
Here’s a self standing extension method, also 32bit but can easily be made for 64bit.
[code]Module TextAreaAddition
Sub setTextBGColor(extends ta As TextArea, start As integer, length As integer, bgColor As Color)
declare function NSClassFromString lib “Cocoa” (aClassName as CFStringRef) as Ptr
declare function docView lib “Cocoa” selector “documentView” (id As Ptr) as Ptr
declare function textStore lib “Cocoa” selector “textStorage” (id As Ptr) as Ptr
declare function colRGBA lib “Cocoa” selector “colorWithCalibratedRed:green:blue:alpha:” _
(cls As Ptr, r As single, g As single, b As single, a As single) as Ptr
declare sub addAttrib lib “Cocoa” selector “addAttribute:value:range:” _
(id As Ptr, name As CFStringRef, value As Ptr, aRange As NSRange32)
declare sub release lib “Cocoa” selector “release” (id As Ptr)
dim ts As Ptr = textStore(docView(Ptr(ta.Handle)))
dim range As NSRange32
range.location = start
range.length = length
dim col As Ptr = colRGBA(NSClassFromString("NSColor"), _
bgColor.Red/255, bgColor.Green/255, bgColor.Blue/255, 1-bgColor.Alpha/255)
addAttrib(ts, "NSBackgroundColor", col, range)
release(col)
End Sub
Private Structure NSRange32
location As UInt32
length As UInt32
End Structure
End Module[/code]
myTextArea.setTextBGColor(5, 6, &c00FF00)
(edited to release col)