Page 1 of 1

EditorGadget problem

Posted: Sun Jan 22, 2006 10:04 pm
by Kaiser
See... I'm using these Editor functions for coloring the text of a chat program I've been working on for months...

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 
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?)

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
OR alternatively (fast as hell) I can use just...

Code: Select all

m$=GetGadgetText(#editor_0)
WriteString(m$)
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 :D

Posted: Sun Jan 22, 2006 10:17 pm
by Trond
The transcript was longer than 64 kb, that's why the logfile was empty?

Edit: Yes, that's the problem, GetGadgetText returns empty string if the content is larger than a PB string.

Posted: Sun Jan 22, 2006 10:23 pm
by Kaiser
So it's a bug then - any fast workaround other than the one I'm using? :/

Posted: Sun Jan 22, 2006 11:29 pm
by blueznl
not a bug, a limitation, pb 3.94 cannot handle too large strings, i think these are fixed for v4

Posted: Sun Jan 22, 2006 11:44 pm
by HeX0R
You can also do it through streaming.

Posted: Mon Jan 23, 2006 3:34 am
by Kaiser
Streaming as in?

Posted: Mon Jan 23, 2006 3:45 am
by Sparkie
freak posted an example of #EM_STREAMIN and #EM_STREAMOUT here. 8)

Posted: Mon Jan 23, 2006 9:05 am
by HeX0R
This theme is not really the best, as i posted the exact same link as Sparkie (but i guess you've overread it as it is not underlined...)

Posted: Mon Jan 23, 2006 2:21 pm
by Sparkie
Sorry HeX0R, you are right, your link didn't stand out with the subSiler theme I was using. I just changed themes and now I must go back and re-read all 104780 posts to see how many other links I have missed out on. :shock: :)

Posted: Tue Jan 24, 2006 5:43 am
by Kaiser
This theme's screwed up o_O... Sparkie's right lol, then again, thanks you two :D I'm gonna see how it goes ^^;

Posted: Thu Jan 26, 2006 6:44 am
by Kaiser
Well, for not making another thread (and this one has a nice name xD), I keep up with my chat program, going really nice, now it saves correctly :D thanks heXOR and Sparkie ^^... anyways, I'm using the functions in the first post for selecting the text and formatting it, and also I'm using this every new line is created:

Code: Select all

    ;Don't know how does this works, but it goes to the last line, so it works!
    Gadget=#editor_0
    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)    
Now, I know it's possible because I've seen another program (not made in PB though) do it, but how can I keep the EditorGadget un-scroll-able no matter where the selection is? like, let the function add as much lines as it wants, but to not to scroll to the last line until I want to? I know the selection functions for formatting the text also affect it, but how can I make them so they don't scroll to the last line, either?... eh, I'm not sure if I explained myself correctly :/

Anyways, thanks in advance ^^

Posted: Thu Jan 26, 2006 8:50 am
by blueznl
haven't tried it, but i think what they do is disable updates, then every time jump back to the original line, no clue how to do it though :-)

Posted: Thu Jan 26, 2006 2:04 pm
by HeX0R
You can use

Code: Select all

SendMessage_(GadgetID(Gadget), #EM_HIDESELECTION, #True, 0)
to NOT scroll to the selection.
(This makes it also much faster)

Afterwards just replace the #True with #False.