EditorGadget clearing bug

Windows specific forum
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

EditorGadget clearing bug

Post 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,"").
BarryG
Addict
Addict
Posts: 4138
Joined: Thu Apr 18, 2019 8:17 am

Re: [PB6.03b2] EditorGadget clearing bug

Post 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.
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB6.03b2] EditorGadget clearing bug

Post 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.
BarryG
Addict
Addict
Posts: 4138
Joined: Thu Apr 18, 2019 8:17 am

Re: [PB6.03b2] EditorGadget clearing bug

Post 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?
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB6.03b2] EditorGadget clearing bug

Post 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
BarryG
Addict
Addict
Posts: 4138
Joined: Thu Apr 18, 2019 8:17 am

Re: [PB6.03b2] EditorGadget clearing bug

Post 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
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB6.03b2] EditorGadget clearing bug

Post 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.
BarryG
Addict
Addict
Posts: 4138
Joined: Thu Apr 18, 2019 8:17 am

Re: [PB6.03b2] EditorGadget clearing bug

Post by BarryG »

I just tried it with the same version as you, and no bug here. I don't know why.
Last edited by BarryG on Thu Jul 06, 2023 11:02 am, edited 1 time in total.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [PB6.03b2] EditorGadget clearing bug

Post by Fred »

I can see it here as well, not everytime but it happens. I will take a look
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: [PB6.03b2] EditorGadget clearing bug

Post 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
Egypt my love
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [PB6.03b2] EditorGadget clearing bug

Post 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
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: [PB6.03b2] EditorGadget clearing bug

Post 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
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [PB6.03b2] EditorGadget clearing bug

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