It is currently Tue Aug 20, 2019 10:07 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: the EditorGadget and the big Text
PostPosted: Wed Jun 19, 2019 4:57 pm 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1354
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:
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




Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Wed Jun 19, 2019 5:22 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3381
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


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Wed Jun 19, 2019 5:47 pm 
Offline
User
User

Joined: Sun Nov 26, 2017 3:13 pm
Posts: 17
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:
SendMessage_(GadgetID(#Edit), #EM_SETTEXTMODE, #TM_PLAINTEXT, 0)


Peter


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Wed Jun 19, 2019 6:06 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3381
No it will Peter ,but after creating the gadget (Change to Plain text inside the loop)
Code:
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:

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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Wed Jun 19, 2019 7:55 pm 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1354
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


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Wed Jun 19, 2019 8:04 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3381
You are welcome
And thanks for your graphics work :)

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Fri Jun 21, 2019 4:31 pm 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1354
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


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Fri Jun 21, 2019 6:13 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3381
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Fri Jun 21, 2019 8:11 pm 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1354
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:
tlen = SendMessage_(HwndEditText, #WM_GETTEXTLENGTH, 0, 0) + 1
  txt$ = Space(tlen)
  SendMessage_(HwndEditText, #WM_GETTEXT, tlen, @txt$)

look:
viewtopic.php?p=145297#p145297


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Sun Jun 23, 2019 1:01 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3381
Hi applePi
https://www.purebasic.fr/english/viewtopic.php?f=12&t=73076

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Sun Jun 23, 2019 2:03 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1842
Location: Germany
It helps if you switch off the redrawing of the gadget while inserting the text.
Code:
  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 / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: the EditorGadget and the big Text
PostPosted: Mon Jun 24, 2019 12:08 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 234
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!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye