Hey, spacebuddy, do you have a small example of selecting, bolding and coloring? (reset would be interesting too)
lets see... I've got this from wilbert (I think), it appears that the colors can be simplified and bolding added.
This is what I've go so far - it is a short form to do background,text color, and bold text.
Code: Select all
Procedure SetTextColor(EditorGadget, TextColor$, StartPosition, Length, BackColor$)
Protected.CGFloat r,g,b,a
Protected range.NSRange, textStorage.i
If StartPosition > 0
textStorage = CocoaMessage(0, GadgetID(EditorGadget), "textStorage")
range\location = StartPosition - 1
range\length = CocoaMessage(0, textStorage, "length") - range\location
If range\length > 0
If Length >= 0 And Length < range\length
range\length = Length
EndIf
;background color
BckColor.i = CocoaMessage(0, 0, BackColor$)
CocoaMessage(0, TextStorage, "addAttribute:$", @"NSBackgroundColor", "value:", BckColor, "range:@", @Range)
;set selection text color
ForeColor.i=CocoaMessage(0,0,TextColor$)
CocoaMessage(0,TextStorage,"addAttribute:$",@"NSColor","value:",ForeColor,"range:@",@Range)
;bold
FontSize.CGFloat = 12.0
BoldSystemFont.i = CocoaMessage(0, 0, "NSFont boldSystemFontOfSize:@", @FontSize)
CocoaMessage(0, TextStorage, "addAttribute:$", @"NSFont", "value:", BoldSystemFont, "range:@", @Range)
EndIf
EndIf
EndProcedure
Procedure ResetAttribute(EditorGadget,StartPosition, Length)
Protected.CGFloat r,g,b,a
Protected range.NSRange, textStorage.i
If StartPosition > 0
textStorage = CocoaMessage(0, GadgetID(EditorGadget), "textStorage")
range\location = StartPosition - 1
range\length = CocoaMessage(0, textStorage, "length") - range\location
If range\length > 0
If Length >= 0 And Length < range\length
range\length = Length
EndIf
CocoaMessage(0, TextStorage, "removeAttribute:$", @"NSFont", "range:@", @Range) ; remove bold
CocoaMessage(0, TextStorage, "removeAttribute:$", @"NSColor", "range:@", @range) ; remove color
CocoaMessage(0, TextStorage, "removeAttribute:$", @"NSBackgroundColor", "range:@", @range) ; remove background color
EndIf
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 28, 306, 113)
SetGadgetText(0, "This is a test string to test if coloring" + #CRLF$ + "specific areas will work")
SetTextColor(0,"NSColor redColor", 1,7,"NSColor yellowColor"); make selection red with yellow background with bold text
ButtonGadget(1,10,2,80,20,"Deselect")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1 ; : Debug "Button 1 clicked!"
resetAttribute(0,1,7)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf