EditorGadget problem

Everything else that doesn't fall into one of the other PB categories.
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

EditorGadget problem

Post 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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

So it's a bug then - any fast workaround other than the one I'm using? :/
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

not a bug, a limitation, pb 3.94 cannot handle too large strings, i think these are fixed for v4
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
HeX0R
Addict
Addict
Posts: 1219
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post by HeX0R »

You can also do it through streaming.
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

Streaming as in?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

freak posted an example of #EM_STREAMIN and #EM_STREAMOUT here. 8)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
HeX0R
Addict
Addict
Posts: 1219
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post 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...)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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: :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post 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 ^^;
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post 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 ^^
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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 :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
HeX0R
Addict
Addict
Posts: 1219
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post 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.
Post Reply