[SOLVED] EditorGadget and line colorization
Posted: Sat Jun 15, 2024 3:00 pm
Hello,
In other codes, coloring the lines of an EditorGadget works in this way :
but not in the following and I don't understand why (it must be so big that I finally can't see it!
).
In other codes, coloring the lines of an EditorGadget works in this way :
Code: Select all
Format.CHARFORMAT
Format\cbSize=SizeOf(CHARFORMAT)
Format\dwMask=#CFM_COLOR
Format\crTextColor=Color
SendMessage_(GadgetID(EditorGadget),#EM_SETCHARFORMAT,#SCF_SELECTION,@Format)
Code: Select all
Procedure Pc_SelectAndColorize(ArgGadget.u,ArgLine.l,ArgColor.l=-1)
Protected.CHARRANGE Range
Protected.CHARFORMAT Format
Protected.l LineStart,TextLength
Protected.s Text
; ******* These lines are here for debugging
Static.l Line=-1
Line+1
If Line>5:Line=0:EndIf
ArgLine=Line
; *******************************************
LineStart=SendMessage_(GadgetID(ArgGadget),#EM_LINEINDEX,ArgLine,0)
With Range
\cpMin=LineStart
\cpMax=LineStart+Len(GetGadgetItemText(ArgGadget,ArgLine))
EndWith
SendMessage_(GadgetID(ArgGadget),#EM_EXSETSEL,0,@Range)
; The code below doesn't work !!!
If ArgColor>=0
With Format
\cbSize=SizeOf(CHARFORMAT)
\dwMask=#CFM_COLOR
\crTextColor=ArgColor
SendMessage_(GadgetID(ArgGadget),#EM_SETCHARFORMAT,#SCF_SELECTION,@Format)
EndWith
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 322, 180, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 306, 133)
ButtonGadget(1, 121, 150, 80, 24,"Test")
SendMessage_(GadgetID(0),#EM_SETTEXTMODE,#TM_RICHTEXT,0)
For a = 0 To 5
AddGadgetItem(0, a, "Line "+Str(a))
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
Case #PB_EventType_LeftClick
;Pc_SelectAndColorize(0,2,#Blue)
Pc_SelectAndColorize(0,0,#Blue)
EndSelect
EndSelect
EndSelect
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf