;fromfreak ;these are functions provided by freak in his ;example on the use of a rich edit gadget. ;basically, its useing the standard editorgadget ;with some extra SendMessage_ calls. ; ; Selects Text inside an EditorGadget ; Line numbers range from 0 to CountGadgetItems(#Gadget)-1 ; Char numbers range from 1 to the length of a line ; Set Line numbers to -1 to indicate the last line, and Char ; numbers to -1 to indicate the end of a line ; selecting from 0,1 to -1, -1 selects all. Procedure Editor_Select(Gadget, LineStart.l, CharStart.l, LineEnd.l, CharEnd.l) sel.CHARRANGE sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineStart, 0) + CharStart - 1 If LineEnd = -1 LineEnd = SendMessage_(GadgetID(Gadget), #EM_GETLINECOUNT, 0, 0)-1 EndIf sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineEnd, 0) If CharEnd = -1 sel\cpMax + SendMessage_(GadgetID(Gadget), #EM_LINELENGTH, sel\cpMax, 0) Else sel\cpMax + CharEnd - 1 EndIf SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel) EndProcedure ; Set the Text color for the Selection ; in RGB format Procedure Editor_Color(Gadget, Color.l) format.CHARFORMAT format\cbSize = SizeOf(CHARFORMAT) format\dwMask = #CFM_COLOR format\crTextColor = Color SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) EndProcedure ; Set Font Size for the Selection ; in pt Procedure Editor_FontSize(Gadget, Fontsize.l) format.CHARFORMAT format\cbSize = SizeOf(CHARFORMAT) format\dwMask = #CFM_SIZE format\yHeight = FontSize*20 SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) EndProcedure ; Set Font for the Selection ; You must specify a font name, the font doesn't need ; to be loaded Procedure Editor_Font(Gadget, FontName.s) format.CHARFORMAT format\cbSize = SizeOf(CHARFORMAT) format\dwMask = #CFM_FACE PokeS(@format\szFaceName, FontName) SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) EndProcedure ; Set Format of the Selection. This can be a combination of ; the following values: ; #CFM_BOLD ; #CFM_ITALIC ; #CFM_UNDERLINE ; #CFM_STRIKEOUT Procedure Editor_Format(Gadget, Flags.l) format.CHARFORMAT format\cbSize = SizeOf(CHARFORMAT) format\dwMask = #CFM_ITALIC|#CFM_BOLD|#CFM_STRIKEOUT|#CFM_UNDERLINE format\dwEffects = Flags SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) EndProcedure Procedure Editor_SetColor(Gadget, LineStart.l, CharStart.l, LineEnd.l, CharEnd.l,Color.l,CP.l) ;insure that target text is visible ;TopLine.l= SendMessage_(GadgetID(gadget), #EM_GETFIRSTVISIBLELINE,0,0) ;If TopLine<>LineStart ; dl.l=LineStart-TopLine ; SendMessage_(GadgetID(gadget),#EM_LINESCROLL,0,LineStart-dl) ; dl=SendMessage_(GadgetID(EditFocus), #EM_GETFIRSTVISIBLELINE,0,0) ;EndIf ;editor_select sel.CHARRANGE sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineStart, 0) + CharStart - 1 If LineEnd = -1 LineEnd = SendMessage_(GadgetID(Gadget), #EM_GETLINECOUNT, 0, 0)-1 EndIf sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineEnd, 0) If CharEnd = -1 sel\cpMax + SendMessage_(GadgetID(Gadget), #EM_LINELENGTH, sel\cpMax, 0) Else sel\cpMax + CharEnd EndIf SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel) ;edior_color format.CHARFORMAT format\cbSize = SizeOf(CHARFORMAT) format\dwMask = #CFM_COLOR format\crTextColor = Color SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) ;editor_select again to deselect If CP sel\cpmin=CP sel\cpMax=CP Else sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineStart, 0) ;sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, 0, 0) sel\cpMax=sel\cpMin EndIf SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel) EndProcedure ; IDE Options = PureBasic v4.02 (Windows - x86) ; Folding = --