Page 1 of 1

EditorGadget clearing bug

Posted: Wed Jul 05, 2023 12:45 pm
by marcoagpinto
Heya,

If I write a ton of text into an editor gadget and then scroll down to the bottom, the scroll bar moves along.

If I then press a button which I created to remove all the text, the scroll bar continues as it was.

The scroll bar should disappear if I do a SETGADGETTEXT(#EDITORGADGET,"").

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Wed Jul 05, 2023 10:16 pm
by BarryG
marcoagpinto wrote: Wed Jul 05, 2023 12:45 pmThe scroll bar should disappear if I do a SETGADGETTEXT(#EDITORGADGET,"").
It disappears here when I do that. You need to post a runnable snippet to show the problem you're getting.

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Wed Jul 05, 2023 10:38 pm
by marcoagpinto
BarryG wrote: Wed Jul 05, 2023 10:16 pm
marcoagpinto wrote: Wed Jul 05, 2023 12:45 pmThe scroll bar should disappear if I do a SETGADGETTEXT(#EDITORGADGET,"").
It disappears here when I do that. You need to post a runnable snippet to show the problem you're getting.
@BarryG

You can reproduce it with this code (remember to scroll down to the bottom before pressing the CLEAR button).

NOTICE: for the bug to happen, you can't click inside the editor gadget, use ONLY THE SCROLL BAR TO SCROLL TO THE BOTTOM.

Code: Select all

Enumeration 1
  #EDITOR_BATTLE_DESCRIPTION
  #IMAGE_BATTLE_DESCRIPTION_TRASHCAN
  #TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS
EndEnumeration

OpenWindow(0,0,0,800,600,"Test",#PB_Window_SystemMenu|#PB_Window_WindowCentered)

x=10
y=10
w=600

EditorGadget(#EDITOR_BATTLE_DESCRIPTION,x,y,w,200+200,#PB_Editor_WordWrap)

t$="Scroll to the button and press the CLEAR button!!!! Test Test Test"+#LF$
For f=1 To 10
  t$+t$
Next f

SetGadgetText(#EDITOR_BATTLE_DESCRIPTION,t$)

y=GadgetY(#EDITOR_BATTLE_DESCRIPTION)+GadgetHeight(#EDITOR_BATTLE_DESCRIPTION)+10

TextGadget(#TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS,x,y,200,24,"Characters:"+Str(Len(GetGadgetText(#EDITOR_BATTLE_DESCRIPTION))))

y+24+10

ButtonGadget(#IMAGE_BATTLE_DESCRIPTION_TRASHCAN,x,y,90,24,"Clear")

Repeat
  
  event=WaitWindowEvent()
  
      Select Event 
        Case #PB_Event_Gadget
          Select EventGadget() 
              
            ; Clear the editor gadget
            Case #IMAGE_BATTLE_DESCRIPTION_TRASHCAN
              SetGadgetText(#EDITOR_BATTLE_DESCRIPTION,"")
              t$="Characters:"+Str(Len(GetGadgetText(#EDITOR_BATTLE_DESCRIPTION)))
              If GetGadgetText(#TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS)<>t$
                SetGadgetText(#TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS,t$)
              EndIf
              
         EndSelect
     EndSelect
     
Until okay=#True   
QUICK EDIT: If I change the constant numbers to become shorter, it works okay.

QUICK EDIT2: Sometimes it happens, other time it doesn't. Please try a few times.

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Thu Jul 06, 2023 8:24 am
by BarryG
marcoagpinto wrote: Wed Jul 05, 2023 10:38 pmYou can reproduce it with this code (remember to scroll down to the bottom before pressing the CLEAR button)
Tried it over and over and it always removes the scroll bar here. Using v6.03 beta 1 (x64). Can anyone else confirm?

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Thu Jul 06, 2023 8:33 am
by marcoagpinto
Well, from now on, I will place YouTube videos of bugs happening.

Here it is the video of it happening:

https://www.youtube.com/watch?v=4QYZ2VUHSA0

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Thu Jul 06, 2023 9:26 am
by BarryG
Videos are not always necessary, and it wasn't that I didn't believe you. What version of PureBasic are you using?

Here's an animated gif of what it does for me:

Image

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Thu Jul 06, 2023 9:32 am
by marcoagpinto
Heya,

As the topic of the post mentions:
PB 6.03 beta 2 x64.

Windows 10 x64.

But notice that the bug doesn't continually happen, so there must some sort of thing happening that only now and then triggers the issue.

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Thu Jul 06, 2023 9:42 am
by BarryG
I just tried it with the same version as you, and no bug here. I don't know why.

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Thu Jul 06, 2023 10:51 am
by Fred
I can see it here as well, not everytime but it happens. I will take a look

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Thu Jul 06, 2023 11:42 am
by RASHAD
I think that the EditorGadget needed to be refreshed after SetGadgetText()
Try

Code: Select all

           Case #IMAGE_BATTLE_DESCRIPTION_TRASHCAN
              SetGadgetText(#EDITOR_BATTLE_DESCRIPTION,"")
              HideGadget(#EDITOR_BATTLE_DESCRIPTION,0)
              t$="Characters:"+Str(Len(GetGadgetText(#EDITOR_BATTLE_DESCRIPTION)))
              If GetGadgetText(#TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS)<>t$
                SetGadgetText(#TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS,t$)
              EndIf

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Fri Mar 14, 2025 6:39 pm
by Fred
I tried to fix it but it seems like to be a Windows glitch here as we use the standard WM_SETTEXT message to clear the text

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Sun Apr 13, 2025 3:34 pm
by breeze4me
This issue is caused by a system global setting. (Animate controls and elements inside windows)
After some experimentation, the most obvious solution to this issue seems to be to intercept the GetThemeTransitionDuration API and return 0 as the time value.

The MS Detours files are in the link in the post below.
https://www.purebasic.fr/english/viewtopic.php?t=83878

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  #Lib_x86x64 = "86"
CompilerElse
  #Lib_x86x64 = "64"
CompilerEndIf

Import "detours_x" + #Lib_x86x64 + ".lib"
  DetourTransactionBegin.l()
  DetourTransactionCommit.l()
  DetourUpdateThread.l(hThread)
  DetourAttach.l(*ppPointer, pDetour)
  DetourDetach.l(*ppPointer, pDetour)
EndImport

Import "uxtheme.lib"
  GetThemeTransitionDuration.l(hTheme, iPartId.l, iStateIdFrom.l, iStateIdTo.l, iPropId.l, *pdwDuration.Long)
EndImport

Prototype.l ptGetThemeTransitionDuration(hTheme, iPartId.l, iStateIdFrom.l, iStateIdTo.l, iPropId.l, *pdwDuration.Long)
Global GetThemeTransitionDuration__.ptGetThemeTransitionDuration = @GetThemeTransitionDuration()


#SBP_ARROWBTN = 1
#SBP_THUMBBTNVERT = 3
#TMT_TRANSITIONDURATIONS = 6000
Procedure.l My_GetThemeTransitionDuration(hTheme, iPartId.l, iStateIdFrom.l, iStateIdTo.l, iPropId.l, *pdwDuration.Long)
  
  Debug #PB_Compiler_Procedure
  
  ;Debug "" + iPartId + " " + iStateIdFrom + " " + iStateIdTo + " " + iPropId
  If iPropId = #TMT_TRANSITIONDURATIONS And (iPartId = #SBP_ARROWBTN Or iPartId = #SBP_THUMBBTNVERT)
    *pdwDuration\l = 0
    ProcedureReturn #S_OK
  EndIf
  
  ProcedureReturn GetThemeTransitionDuration__(hTheme, iPartId.l, iStateIdFrom.l, iStateIdTo.l, iPropId.l, *pdwDuration.Long)
EndProcedure

If DetourTransactionBegin() = #NO_ERROR
  If DetourUpdateThread(GetCurrentThread_()) = #NO_ERROR
    
    If GetThemeTransitionDuration__
      If DetourAttach(@GetThemeTransitionDuration__, @My_GetThemeTransitionDuration()) <> #NO_ERROR
          Debug "Detours Error: GetThemeTransitionDuration"
        Else
          Debug "GetThemeTransitionDuration OK"
      EndIf
    EndIf
    
    DetourTransactionCommit()
  EndIf
EndIf




Enumeration 1
  #EDITOR_BATTLE_DESCRIPTION
  #IMAGE_BATTLE_DESCRIPTION_TRASHCAN
  #TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS
EndEnumeration

OpenWindow(0,0,0,800,600,"Test",#PB_Window_SystemMenu|#PB_Window_WindowCentered)

x=10
y=10
w=600

EditorGadget(#EDITOR_BATTLE_DESCRIPTION,x,y,w,200+200,#PB_Editor_WordWrap)

t$="Scroll to the button and press the CLEAR button!!!! Test Test Test"+#LF$
For f=1 To 10
  t$+t$
Next f

SetGadgetText(#EDITOR_BATTLE_DESCRIPTION,t$)

y=GadgetY(#EDITOR_BATTLE_DESCRIPTION)+GadgetHeight(#EDITOR_BATTLE_DESCRIPTION)+10

TextGadget(#TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS,x,y,200,24,"Characters:"+Str(Len(GetGadgetText(#EDITOR_BATTLE_DESCRIPTION))))

y+24+10

ButtonGadget(#IMAGE_BATTLE_DESCRIPTION_TRASHCAN,x,y,90,24,"Clear")

Repeat
  
  event=WaitWindowEvent()
  
      Select Event 
        Case #PB_Event_Gadget
          Select EventGadget() 
              
            ; Clear the editor gadget
            Case #IMAGE_BATTLE_DESCRIPTION_TRASHCAN
              SetGadgetText(#EDITOR_BATTLE_DESCRIPTION,"")
              t$="Characters:"+Str(Len(GetGadgetText(#EDITOR_BATTLE_DESCRIPTION)))
              If GetGadgetText(#TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS)<>t$
                SetGadgetText(#TEXT_BATTLE_DESCRIPTION_NUMBER_CHRS,t$)
              EndIf
              
         EndSelect
     EndSelect
     
Until event=#PB_Event_CloseWindow

Re: [PB6.03b2] EditorGadget clearing bug

Posted: Mon Apr 14, 2025 6:13 pm
by Fred
So it looks like a Windows 'feature'. We won't try to patch such behaviour anymore as it can introduce more unexpected oddities later.