the EditorGadget and the big Text

Just starting out? Need help? Post your questions and find answers here.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

the EditorGadget and the big Text

Post by applePi »

Hi
when i pasted a 10000 lines text in the editor Gadget it takes about 5 seconds to appear in the editor gadget, in comparison with (other basic) it is displayed instantaneously in a texBox, this is just a show case i don't use other basic. is it possible to decrease the time in purebasic , the gadget should have vertical and horizontal scroll bars
use the text from here http://www.gutenberg.org/ebooks/100 download the file Plain Text UTF-8 5.5 MB, open it and search for the words " Away, my Thetis! " line 10000 copy the text from it up to the top and paste it in the editor gadget here, (i don't want to load the file just copy and paste text)
(what other possible gadgets alternatives to display big text)
thank you

tested with 5.70 LTS in XP/32b

Code: Select all

Declare DoSomething()
Enumeration
  #Edit = 0
  #Button
EndEnumeration
Global txt.s
If  OpenWindow(0,0,0,800,600,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  CreatePopupMenu(0)
  MenuItem(0, "Cut")
  MenuItem(1, "Copy")
  MenuItem(2, "Paste")
  EditorGadget(#Edit, 3, 3, 750, 550)
  SetGadgetColor(#Edit, #PB_Gadget_BackColor, RGB(248,236,190))
  ButtonGadget(#Button , 756,20,45,40,"RUN")
  LoadFont(1,"Tahoma",12)
  SetGadgetFont(0,FontID(1))
        
i=0    
Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
      Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Button
            DoSomething()
        EndSelect
      Case #PB_Event_Menu
        Select EventMenu()
          Case 0
            SendMessage_(GadgetID(0), #WM_CUT, 0, 0)
          Case 1
            SendMessage_(GadgetID(0), #WM_COPY, 0, 0)
          Case 2
            SendMessage_(GadgetID(0), #WM_PASTE, 0, 0)
        EndSelect

      Case #WM_RBUTTONDOWN
        If EventGadget() = 0
          DisplayPopupMenu(0, WindowID(0))
        EndIf
    
    EndSelect
    ForEver
Else  
  Debug "Could not Open Window!"
EndIf

End   
  

Procedure DoSomething()
  txt = GetGadgetText(0)
  
  For k = 1 To 2000
    Debug StringField(txt, k, #CRLF$)
  Next

            
EndProcedure


RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: the EditorGadget and the big Text

Post by RASHAD »

Hi applePi
PB EditorGadget() is RTF Gadget (Complicated some how)
So you can check the next options :
1- : Scintilla Gadget
2- : EditorGadget in Plain text

Edit : After checking Scintilla is your choice
Egypt my love
PeDe
Enthusiast
Enthusiast
Posts: 119
Joined: Sun Nov 26, 2017 3:13 pm
Location: Vienna
Contact:

Re: the EditorGadget and the big Text

Post by PeDe »

I tested this with a PIII 450 MHz PC with Win XP and PB5.71b1 32-bit. Inserting the 10,000 lines takes about 0.5 seconds.
It won't get any faster with the following code:

Code: Select all

SendMessage_(GadgetID(#Edit), #EM_SETTEXTMODE, #TM_PLAINTEXT, 0)
Peter
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: the EditorGadget and the big Text

Post by RASHAD »

No it will Peter ,but after creating the gadget (Change to Plain text inside the loop)

Code: Select all

If OpenWindow(0, 0, 0, 400, 290, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 10,10, 380, 240) 
  ButtonGadget(1, 10, 260, 80, 20, "RTF")
  ButtonGadget(2, 100, 260, 80, 20, "Pain Text")
Repeat

  Select WaitWindowEvent(1)
     
       Case #PB_Event_CloseWindow
          Quit = 1       
     
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
               SetGadgetText(0,"")
               SendMessage_(GadgetID(0), #EM_SETTEXTMODE, #TM_RICHTEXT, 0)
               SetActiveGadget(0)

           Case 2
               SetGadgetText(0,"")
               SendMessage_(GadgetID(0), #EM_SETTEXTMODE, #TM_PLAINTEXT, 0)
               SetActiveGadget(0)
                       
          EndSelect
  EndSelect
Until Quit = 1

EndIf
Using Windows API

Code: Select all


Procedure CreateEditText()
  hInstance = GetModuleHandle_(0) 
  HwndEditText  = CreateWindowEx_(0,"EDIT","", #WS_VISIBLE | #WS_CHILDWINDOW | #ES_AUTOHSCROLL  | #WS_VSCROLL | #ES_MULTILINE | #ES_WANTRETURN |#ES_NOHIDESEL, 10,10,780,500,WindowID(0),200,hInstance,0) 
  SendMessage_(HwndEditText,#EM_CANUNDO,0, 0)
EndProcedure

If OpenWindow(0,0,0,800,600,"Basic Text Control",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,#Gray)
  CreateEditText()
  If CreatePopupMenu(0)
      MenuItem(1, "Undo")
      MenuItem(2, "Cut")
      MenuItem(3, "Copy")
      MenuItem(4, "Paste")
      MenuBar()
      OpenSubMenu("Options")
        MenuItem(5, "Window...")
        MenuItem(6, "Gadget...")
      CloseSubMenu()
      MenuBar()
      MenuItem( 7, "Quit")
  EndIf
  
EndIf   
   
   For i = 1 To 31
     Text$="Line :"+Str(i)+Chr(13)+Chr(10)
     SendMessage_(HwndEditText,#EM_REPLACESEL,0,Text$)
   Next
   
  SendMessage_(HwndEditText, #EM_SETBKGNDCOLOR, 0, $B0B0B1)
     Repeat
      Select WaitWindowEvent()
      
        Case #PB_Event_CloseWindow
          Q = 1
                  
        Case #PB_Event_Menu
      
          Select EventMenu()
              
              Case 1
                  SendMessage_(GetFocus_(),#EM_UNDO,0,0)
                  
              Case 2
                  SendMessage_(GetFocus_(),#WM_CUT,0,0)
                  SendMessage_(GetFocus_(),#WM_CHAR,#VK_BACK,0)
    
              Case 3
                  SendMessage_(GetFocus_(),#WM_COPY,0,0)
    
              Case 4
                  SendMessage_(GetFocus_(),#WM_PASTE,0,0)
    
              Case 7
                Q = 1

               
            EndSelect
            
          Case #WM_RBUTTONDOWN
            DisplayPopupMenu(0, WindowID(0))
            
      EndSelect
    Until Q = 1
    DestroyWindow_(HwndEditText)   
    CloseLibrary(0)
  End  

Using ScintillaGadget

Code: Select all

Procedure sizeCB()
  ResizeGadget(0,10,10,WindowWidth(0)-20,WindowHeight(0)-20)
EndProcedure

If OpenWindow(0, 0, 0, 600, 400, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
   
    If InitScintilla()
      ScintillaGadget(0, 10, 10, 580, 380, 0)
      ScintillaSendMessage(0, #SCI_STYLESETFONT, 0, @"Tahoma")
      ScintillaSendMessage(0, #SCI_STYLESETSIZE, 0, 24)
      ScintillaSendMessage(0, #SCI_STYLESETFORE, 0, $00FF00)     ;Foreground Color
      ScintillaSendMessage(0, #SCI_STYLESETBACK, 0, $FFFFFF)     ;Background Color
    EndIf
    
  If CreatePopupMenu(0)
    MenuItem(1, "Undo")
    MenuItem(2, "Cut")
    MenuItem(3, "Copy")
    MenuItem(4, "Paste")
    MenuBar()
    MenuItem( 7, "Quit")
  EndIf
  
BindEvent(#PB_Event_SizeWindow,@sizeCB())
Repeat
  Select WaitWindowEvent()    
    Case #PB_Event_CloseWindow
      Q = 1
              
    Case #PB_Event_Menu  
      Select EventMenu()          
        Case 1
            SendMessage_(GetFocus_(),#EM_UNDO,0,0)
            
        Case 2
            SendMessage_(GetFocus_(),#WM_CUT,0,0)
            SendMessage_(GetFocus_(),#WM_CHAR,#VK_BACK,0)

        Case 3
            SendMessage_(GetFocus_(),#WM_COPY,0,0)

        Case 4
            SendMessage_(GetFocus_(),#WM_PASTE,0,0)

        Case 7
          Q = 1
          
        EndSelect
          
        Case #WM_RBUTTONDOWN
          DisplayPopupMenu(0, WindowID(0))
          
    EndSelect
  Until Q = 1
EndIf
Egypt my love
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: the EditorGadget and the big Text

Post by applePi »

Hi RASHAD
i have tested with your first example with plain text and it is almost instantaneous,
with the second example Using Windows API, it is also instantaneous.
with the ScintillaGadget, i think (but not completely sure) super instantaneous, this is what i feel.
this solves my problem. Thank You very much and best regards
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: the EditorGadget and the big Text

Post by RASHAD »

You are welcome
And thanks for your graphics work :)
Egypt my love
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: the EditorGadget and the big Text

Post by applePi »

Hi RASHAD
in your Windows API example, there is line
SendMessage_(HwndEditText, #EM_SETBKGNDCOLOR, 0, $B0B0B1)
but it seems this line does not change the background color of the Text box whatever the color we use, even if i moved it to inside the procedure CreateEditText() . but i can use the SendMessage_ to let the box accept text of length 1000000 characters:
SendMessage_(HwndEditText, #EM_LIMITTEXT, 1000000, 0)
inside the procedure CreateEditText()
but for the color it seems does not work
Thanks
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: the EditorGadget and the big Text

Post by RASHAD »

Hi applePi
Sorry for the inconvenient snippet
Next is able to include 2 GB file size
Speed is acceptable
Color for background and foreground
Hal & Val scroll

Code: Select all

Global HwndEditText, BColor,FColor ,brush

Bcolor = $CFFEFD
Fcolor = $FE1E0E

CreateImage(0,20,20,24,Bcolor)

brush = CreatePatternBrush_(ImageID(0))

Procedure WinProc(hWnd,uMsg,wParam,lParam)
Result = #PB_ProcessPureBasicEvents 
  Select uMsg                               
    Case #WM_CTLCOLOREDIT
      SetBkColor_(wParam,BColor)
      SetTextColor_(wParam,FColor)
      ;SetBkMode_(wParam, #OPAQUE)
      result = brush
      
    Case #WM_SIZE
      MoveWindow_(HwndEditText,10,10,WindowWidth(0)-20,WindowHeight(0)-20,1)
    EndSelect
  ProcedureReturn Result
EndProcedure

LoadFont(0,"Tahoma",16)

If OpenWindow(0,0,0,800,600,"Basic Text Control",#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
SetWindowColor(0,$868686)
hInstance = GetModuleHandle_(0)
HwndEditText  = CreateWindowEx_(0,"EDIT","", #WS_VISIBLE | #WS_CHILDWINDOW | #WS_HSCROLL  | #WS_VSCROLL | #ES_MULTILINE | #ES_NOHIDESEL | #ES_WANTRETURN, 10,10,780,580,WindowID(0),200,hInstance,0)
SendMessage_(HwndEditText,#EM_SETLIMITTEXT,0,0)
SendMessage_(HwndEditText,#EM_CANUNDO, 0, 0)
SendMessage_(HwndEditText,#WM_SETFONT,FontID(0),0)
  If CreatePopupMenu(0)
    MenuItem(1, "Undo")
    MenuItem(2, "Cut")
    MenuItem(3, "Copy")
    MenuItem(4, "Paste")
    MenuBar()
    OpenSubMenu("Options")
      MenuItem(5, "Window...")
      MenuItem(6, "Gadget...")
    CloseSubMenu()
    MenuBar()
    MenuItem( 7, "Quit")
  EndIf 
EndIf   
 
SetWindowCallback(@WinProc())

Repeat
  Select WaitWindowEvent()
 
    Case #PB_Event_CloseWindow
      Q = 1
             
    Case #PB_Event_Menu
 
      Select EventMenu()         
        Case 1
            SendMessage_(GetFocus_(),#EM_UNDO,0,0)
           
        Case 2
            SendMessage_(GetFocus_(),#WM_CUT,0,0)
            SendMessage_(GetFocus_(),#WM_CHAR,#VK_BACK,0)

        Case 3
            SendMessage_(GetFocus_(),#WM_COPY,0,0)

        Case 4
            SendMessage_(GetFocus_(),#WM_PASTE,0,0)

        Case 7
          Q = 1
           
      EndSelect
       
    Case #WM_RBUTTONDOWN
      DisplayPopupMenu(0, WindowID(0))
       
  EndSelect
Until Q = 1
DestroyWindow_(HwndEditText) 
End  
Egypt my love
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: the EditorGadget and the big Text

Post by applePi »

Thanks RASHAD
a short example but complete and a tutorial by itself
best regards

Edit:
i have used these lines with RASHAD code above to get the text from the text box for processing

Code: Select all

tlen = SendMessage_(HwndEditText, #WM_GETTEXTLENGTH, 0, 0) + 1 
  txt$ = Space(tlen) 
  SendMessage_(HwndEditText, #WM_GETTEXT, tlen, @txt$)
look:
viewtopic.php?p=145297#p145297
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: the EditorGadget and the big Text

Post by RASHAD »

Egypt my love
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: the EditorGadget and the big Text

Post by mk-soft »

It helps if you switch off the redrawing of the gadget while inserting the text.

Code: Select all

  Case 2
            SendMessage_(GadgetID(0), #WM_SETREDRAW, 0, 0)
            SendMessage_(GadgetID(0), #WM_PASTE, 0, 0)
            SendMessage_(GadgetID(0), #WM_SETREDRAW, 1, 0)
            InvalidateRect_(GadgetID(0), 0, 1)
        
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: the EditorGadget and the big Text

Post by BarryG »

I love #WM_SETREDRAW, especially for removing a large bunch of selected items in a ListIconGadget. Changes the time from 3 seconds to instant in some of my uses. A very useful Windows tool!
Post Reply