Page 1 of 1

EditorGadget mouse cursor blink

Posted: Sun Oct 20, 2024 4:21 pm
by le_magn
Hello everyone, I have a problem with the mouse cursor, basically I have an app with an editorgadget that is updated very quickly with the addition of text, the problem is that while the editor is being updated with the addition of new text, if I leave the mouse cursor still on the window, the cursor disappears, while if I move it it blinks, the procedure I use to update the editorgadget is this(which also allows me to scroll automatically)

Code: Select all

Procedure Mia_AddGadgetItem(gadget, Posizione, Stringa.s, acapo = 1)
  AddGadgetItem(gadget, posizione, Stringa)
  SendMessage_(GadgetID(gadget), #EM_SETSEL, $fffffff, $fffffff)
EndProcedure

Re: EditorGadget mouse cursor blink

Posted: Sun Oct 20, 2024 10:07 pm
by BarryG
Need more code than that to see the problem. Something runnable would help.

Re: EditorGadget mouse cursor blink

Posted: Sun Oct 20, 2024 10:09 pm
by ChrisR
2 tries to prevent the cursor from disappearing, but it flickers a little.

Code: Select all

EnableExplicit

Procedure Mia_AddGadgetItem2(gadget, Posizione, Stringa.s, acapo = 1)
  AddGadgetItem(gadget, posizione, Stringa)
  SendMessage_(GadgetID(gadget), #EM_SETSEL, $fffffff, $fffffff)
EndProcedure

Procedure Mia_AddGadgetItem1(gadget, Posizione, Stringa.s, acapo = 1)
  Protected cPoint.Point, rc.Rect
  GetCursorPos_(@cPoint)
  rc\left   = cPoint\x
  rc\top    = cPoint\y
  rc\right  = cPoint\x + 1
  rc\bottom = cPoint\y + 1
  ClipCursor_(@rc)
  AddGadgetItem(gadget, posizione, Stringa)
  SendMessage_(GadgetID(gadget), #EM_SETSEL, $fffffff, $fffffff)
  ClipCursor_(#Null)
EndProcedure

Procedure Mia_AddGadgetItem(gadget, Posizione, Stringa.s, acapo = 1)
  Protected cPoint.Point
  GetCursorPos_(@cPoint)
  AddGadgetItem(gadget, posizione, Stringa)
  SendMessage_(GadgetID(gadget), #EM_SETSEL, $fffffff, $fffffff)
  SetCursorPos_(cPoint\x, cPoint\y)
EndProcedure

Define i
If OpenWindow(0, 0, 0, 330, 290, "Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 40, 20, 250, 250)
  AddWindowTimer(0, 1, 600)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Timer
        If EventTimer() = 1
          i + 1
          Mia_AddGadgetItem(0, -1, "Editor Line " + Str(i))
        EndIf
    EndSelect
  ForEver
EndIf

Re: EditorGadget mouse cursor blink

Posted: Sun Oct 20, 2024 10:42 pm
by RASHAD
Hi

Code: Select all

If OpenWindow(0, 0, 0, 330, 290, "Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 40, 20, 250, 250)
  AddWindowTimer(0, 1, 100)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
        
      Case #PB_Event_Timer      
        If EventTimer() = 1
          LockWindowUpdate_(GadgetID(0))
          i + 1
          AddGadgetItem(0, -1, "Editor Line " + Str(i)) 
          SendMessage_(GadgetID(0), #EM_SETSEL, $fffffff, $fffffff)
          LockWindowUpdate_(0)
        EndIf
    EndSelect
  ForEver
EndIf

Re: EditorGadget mouse cursor blink

Posted: Sun Oct 20, 2024 10:55 pm
by le_magn
i tried both codes but at high speed cursor continue to disappear or blink very fast..

Code: Select all

AddWindowTimer(0, 1, 5)
try this and you see the cursor disappear, in my app text in editor gadget scroll very fast

Re: EditorGadget mouse cursor blink

Posted: Mon Oct 21, 2024 1:54 am
by RASHAD

Code: Select all

Global hEdit

LoadFont(0,"Tahoma",12)

If OpenWindow(0, 0, 0, 330, 290, "Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  hInstance = GetModuleHandle_(0) 
  If OpenLibrary(0,"msftedit.dll")
    Class_Name$ = "RichEdit50W"
    hEdit  = CreateWindowEx_(0,Class_Name$,"", #WS_VISIBLE | #WS_CHILDWINDOW |  #WS_HSCROLL | #WS_VSCROLL|  #ES_MULTILINE | #ES_WANTRETURN |#ES_NOHIDESEL, 10,10,300,270,WindowID(0),100,hInstance,0) 
  EndIf
  SendMessage_(hEdit ,#WM_SETFONT,FontID(0),0)
  AddWindowTimer(0,125,5) 
  Repeat
    Select WaitWindowEvent(1)
      Case #PB_Event_CloseWindow
        Break
        
      Case #PB_Event_Timer
        i + 1
        text$ = "Editor Line " + Str(i) + #CRLF$
        SendMessage_(hEdit, #EM_REPLACESEL, i, @text$)
        
    EndSelect
  ForEver
EndIf

Re: EditorGadget mouse cursor blink

Posted: Mon Oct 21, 2024 2:43 am
by RASHAD
Using ScintillaGadget()

Code: Select all

If OpenWindow(0, 0, 0, 330, 290, "Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    ScintillaGadget(0, 10, 10, 320, 270, 0)    
    ScintillaSendMessage(0, #SCI_STYLESETFORE, 0, RGB(255, 0, 0))
    
    AddWindowTimer(0,125,5)
    Repeat
      Select WaitWindowEvent(1) 
        Case #PB_Event_CloseWindow
          Quit = 1
          
        Case #PB_Event_Timer
          i + 1
          text$ = "Editor Line " + Str(i) + #CRLF$
          *Text=UTF8(Text$)
          ScintillaSendMessage(0, #SCI_APPENDTEXT, Len(Text$), *Text)
          ScintillaSendMessage(0, #SCI_SCROLLTOEND,0,0)
          FreeMemory(*Text)
        
    EndSelect
  Until Quit = 1          
  EndIf

Re: EditorGadget mouse cursor blink

Posted: Mon Oct 21, 2024 12:17 pm
by le_magn
Thanks to all, Rashad your solution works and I will probably replace the standard purebasic editorgadget with your code, but it seems strange to me that it is not possible to avoid that annoying flicker in the native purebasic editorgadget, thanks

Re: EditorGadget mouse cursor blink

Posted: Mon Oct 21, 2024 2:02 pm
by breeze4me
There doesn't seem to be any flicker when just using the API.

Code: Select all

If OpenWindow(0, 0, 0, 330, 290, "Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 40, 20, 250, 250)
  AddWindowTimer(0, 1, 5)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
        
      Case #PB_Event_Timer      
        If EventTimer() = 1
          i + 1
          ;AddGadgetItem(0, -1, "Editor Line " + Str(i)) 
          
          text$ = "Editor Line " + Str(i) + #LF$
          SendMessage_(GadgetID(0), #EM_REPLACESEL, i, @text$)
        EndIf
    EndSelect
  ForEver
EndIf
Edit:
After some investigation, it seems that the flicker occurs when the #LF$ character is added.
The code below also has no flicker.

Code: Select all


Global old

Procedure EdWProc(hWnd, uMsg, wParam, lParam) 
  Protected s.s
  
  If uMsg = #EM_REPLACESEL
    If lParam
      s = PeekS(lParam)
      If s = #LF$
        ProcedureReturn 0
      EndIf
    EndIf
  EndIf
  ProcedureReturn CallWindowProc_(old, hWnd, uMsg, wParam, lParam) 
EndProcedure 


If OpenWindow(0, 0, 0, 330, 290, "Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 40, 20, 250, 250)
  AddWindowTimer(0, 1, 5 )
  
  old = SetWindowLongPtr_(GadgetID(0), #GWLP_WNDPROC, @EdWProc())
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
        
      Case #PB_Event_Timer      
        If EventTimer() = 1
          
          i + 1
          AddGadgetItem(0, -1, "Editor Line " + Str(i) + #LF$)
          
          SendMessage_(GadgetID(0), #EM_SETSEL, $fffffff, $fffffff)
          
        EndIf
    EndSelect
  ForEver
EndIf
Edit 2:
Interestingly, passing two characters(#CRLF$) instead of one(#LF$) works just fine.

Code: Select all

Global old
Global CRLF$ = #CRLF$

Procedure EdWProc(hWnd, uMsg, wParam, lParam) 
  If uMsg = #EM_REPLACESEL
    If lParam
      If PeekC(lParam) = #LF
        ProcedureReturn CallWindowProc_(old, hWnd, uMsg, wParam, @CRLF$)
      EndIf
    EndIf
  EndIf
  ProcedureReturn CallWindowProc_(old, hWnd, uMsg, wParam, lParam) 
EndProcedure 

If OpenWindow(0, 0, 0, 330, 290, "Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 40, 20, 250, 250)
  AddWindowTimer(0, 1, 5 )
  
  old = SetWindowLongPtr_(GadgetID(0), #GWLP_WNDPROC, @EdWProc())
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
        
      Case #PB_Event_Timer      
        If EventTimer() = 1
          
          i + 1
          AddGadgetItem(0, -1, "Editor Line " + Str(i))
          
          SendMessage_(GadgetID(0), #EM_SETSEL, $fffffff, $fffffff)
          
        EndIf
    EndSelect
  ForEver
EndIf

Re: EditorGadget mouse cursor blink

Posted: Mon Oct 21, 2024 2:46 pm
by RASHAD
Well it seems that the problem is with AddGadgetItem() only
I just checked with GetGadgetItemText() and RemoveGadgetItem() all works fine
Hi Fred :)

Re: EditorGadget mouse cursor blink

Posted: Tue Oct 22, 2024 11:54 am
by ChrisR
Good catch for the AddGadgetItem #LF$ to #CRLF$ :)
If useful, note also that it seems to work well also with #CRLF$ or #LF$ included in the text, rather than 2 EM_REPLACESEL message #LF$ (if not 1st item) and text

Code: Select all

AddGadgetItem(0, -1, "Editor Line " + Str(i) + " (0)" + #CRLF$ + "Editor Line " + Str(i) + " (1)" + #LF$ + "Editor Line " + Str(i) + " (2)" + #CR$ + "Editor Line " + Str(i) + " (3)")
;AddGadgetItem(0, -1, "Editor Line " + Str(i) + ~" (0)\r\nEditor Line " + Str(i) + ~" (1)\nEditor Line " + Str(i) + ~" (2)\rEditor Line " + Str(i) + " (3)")
It should be moved to the Bug section