EditorGadget problem
Posted: Sun Jan 22, 2006 10:04 pm
See... I'm using these Editor functions for coloring the text of a chat program I've been working on for months...
Thus at each new line that arrives, I execute almost 2 or 3 of these for coloring the user name & text correctly. Now, when I choose to save it... I can do this (sure way, but SLOW as hell - any way to speed it up?)
OR alternatively (fast as hell) I can use just...
But it doesn't always gets the text, I've got several logfiles in blank because the function returns nothing... any way to skip or make that bulletproof? :-/.. or to make the first method faster?
Thanks in advance
Code: Select all
Procedure Editor_Select1(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
Procedure Editor_Select2(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 - 2
EndIf
SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel)
EndProcedure
; Set the Text color for the Selection
; in RGB format
Procedure Editor_Color1(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_FontSize1(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_Font1(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_Format1(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
Code: Select all
Procedure SaveLog()
If b$<>""
b$=SaveFileRequester("Save Logfile","Logfile.txt","Text files (*.txt)|*.txt|All files (*.*)|*.*",0)
OpenWindow(100,0,0,200,30,#PB_Window_ScreenCentered,AppTitle)
CreateGadgetList(WindowID(100))
TextGadget(100,0,10,200,20,"Creating file...",#PB_Text_Center)
WindowEvent()
If LCase(Right(b$,4))<>".txt"
b$=b$+".txt"
EndIf
CreateFile(1,b$)
For a=0 To CountGadgetItems(#editor_0)
s$=GetGadgetItemText(#editor_0,a,0)
WriteStringN(s$)
Percent=(a*100)/CountGadgetItems(#editor_0)
b=Percent/10
If b<>c
UseWindow(100)
WindowEvent()
SetGadgetText(100,"Saving... "+Str(Percent)+"%")
c=b
UseWindow(#Window_0)
DoGUI() ;/ this only executes windowevents of the main window
WindowEvent()
UseWindow(100)
WindowEvent()
EndIf
Next a
CloseFile(1)
MessageRequester(AppTitle,"Logfile saved: "+b$)
CloseWindow(100)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Code: Select all
m$=GetGadgetText(#editor_0)
WriteString(m$)
Thanks in advance