Page 1 of 1

Scrolling the WebGadget

Posted: Sat Jul 20, 2019 11:58 pm
by shadowvox
I have a webgadget load a weather map, and a timer is used to wait for it to load.
I have it scroll x 150, works
Then a delay just so I can watch and make sure it's working (will be removed)
Then it scrolls y 250, works, but now the x is back at 0

Code: Select all

;Wait for weather to finish
  If event = #PB_Event_Timer And EventTimer() = 1
    SetGadgetAttribute(WeatherWindow,#PB_Web_ScrollX,150)
    Delay(1000)
    SetGadgetAttribute(WeatherWindow,#PB_Web_ScrollY,250)
    RemoveWindowTimer(0,1)    ;Remove timer as it's no longer needed, or wanted, like your momma
  EndIf

I have reversed x and y, and the last one always sets the other to 0. What am I doing wrong?

Re: Scrolling the WebGadget

Posted: Sun Jul 21, 2019 8:23 am
by mk-soft
Never use delay in an event loop.
This will block the GUI update.

Use AddWindowTimer or AddGadgetTimer (Link)

Re: Scrolling the WebGadget

Posted: Sun Jul 21, 2019 1:35 pm
by shadowvox
Like I said above, I'm only using it to observe the behavior. It will be taken out as soon as I figure out why this is not working. I put it in there trying to figure out why the second scroll is making the first one reset to 0.
So even with the delay out, it's still not acting correctly.

Re: Scrolling the WebGadget

Posted: Wed Jul 24, 2019 7:43 pm
by shadowvox
Still unable to get it working properly. Anyone? Beuller?

Re: Scrolling the WebGadget

Posted: Wed Jul 24, 2019 7:56 pm
by kenmo
Hi. You'll get much better response if you post a working code example.

Looks like a bug to me. X resets Y to 0, and Y resets X to 0.

Somebody probably has a clever API fix though..?

Code: Select all

OpenWindow(0, 0, 0, 480, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 20, 480, 460, "http://en.wikipedia.org")
ButtonGadget(1, 0, 0, 100, 20, "Scroll X 250")
ButtonGadget(2, 100, 0, 100, 20, "Scroll Y 250")
ButtonGadget(3, 200, 0, 100, 20, "Scroll X, Y")
ButtonGadget(4, 300, 0, 100, 20, "Scroll Y, X")

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    Select (EventGadget())
      Case 1
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
      Case 2
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
      Case 3
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250)
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
      Case 4
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250)
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
    EndSelect
  EndIf
Until (Event = #PB_Event_CloseWindow)

Re: Scrolling the WebGadget

Posted: Wed Jul 24, 2019 10:46 pm
by shadowvox
kenmo wrote:Hi. You'll get much better response if you post a working code example.

Looks like a bug to me. X resets Y to 0, and Y resets X to 0.

Somebody probably has a clever API fix though..?

Code: Select all

OpenWindow(0, 0, 0, 480, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 20, 480, 460, "http://en.wikipedia.org")
ButtonGadget(1, 0, 0, 100, 20, "Scroll X 250")
ButtonGadget(2, 100, 0, 100, 20, "Scroll Y 250")
ButtonGadget(3, 200, 0, 100, 20, "Scroll X, Y")
ButtonGadget(4, 300, 0, 100, 20, "Scroll Y, X")

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    Select (EventGadget())
      Case 1
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
      Case 2
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
      Case 3
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250)
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
      Case 4
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250)
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
    EndSelect
  EndIf
Until (Event = #PB_Event_CloseWindow)
I did, but forgot to flag it as code, fixed.
Oh great, my first real prject and I find a bug :D

Re: Scrolling the WebGadget

Posted: Thu Jul 25, 2019 3:19 am
by normeus
Using @kenmos sample code and @Freaks code:
(this one scrolls by the number of pixels )

Code: Select all

; Freak from German forum
Enumeration
  #Web_0
  #Window_0
  #String_0
  #Button_0
EndEnumeration
Procedure WebGadget_Scroll(Gadget.l, x.l, y.l)
   Protected Browser.IWebBrowser2
   Protected Window.IHTMLWindow2
   Protected DocumentDispatch.IDispatch
   Protected Document.IHTMLDocument2
 ;  Protected Element.IHTMLElement2
   
   Browser.IWebBrowser2 = GetWindowLong_(GadgetID(Gadget), #GWL_USERDATA)
   If Browser
      If Browser\get_Document(@DocumentDispatch.IDispatch) = #S_OK
         If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @Document.IHTMLDocument2) = #S_OK           
      If Document\get_parentWindow(@Window.IHTMLWindow2) = #S_OK
            While WindowEvent(): Wend ; wichtig!
            If x=-1
               window\scrollBY(0,y)
            ElseIf y=-1 
               window\scrollBY(x,0)
               Else
                  Window\ScrollTo(x, y) 
           EndIf
            Window\Release()
         EndIf                   
         Document\Release()
      EndIf         
      DocumentDispatch\Release()
   EndIf
EndIf   
EndProcedure



   
OpenWindow(0, 0, 0, 480, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 20, 480, 460, "http://en.wikipedia.org")
ButtonGadget(1, 0, 0, 100, 20, "Scroll X by 250")
ButtonGadget(2, 100, 0, 100, 20, "Scroll Y by 250")
ButtonGadget(3, 200, 0, 100, 20, "Scroll to 200,200")
ButtonGadget(4, 300, 0, 100, 20, "Scroll to 300,300")

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
     Select (EventGadget())

       Case 1
        ;
          WebGadget_Scroll(0, 250, -1) ; resets Y
           Debug "-------1-------"
          Debug GetGadgetAttribute(0, #PB_Web_ScrollY)
          Debug GetGadgetAttribute(0, #PB_Web_ScrollX)
      Case 2

         WebGadget_Scroll(0, -1,250) ; resets X
                 Debug "-------2-------"
          Debug GetGadgetAttribute(0, #PB_Web_ScrollY)
          Debug GetGadgetAttribute(0, #PB_Web_ScrollX)   
      Case 3
       ; SetGadgetAttribute(0, #PB_Web_ScrollX, 250)
       ; SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
        WebGadget_Scroll(0,200,200)
                Debug "-------3-------"
          Debug GetGadgetAttribute(0, #PB_Web_ScrollY)
          Debug GetGadgetAttribute(0, #PB_Web_ScrollX)   
     Case 4
        ;SetGadgetAttribute(0, #PB_Web_ScrollY, 250)
        ;SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
          WebGadget_Scroll(0,300,300)
               Debug "-------4-------"
          Debug GetGadgetAttribute(0, #PB_Web_ScrollY)
          Debug GetGadgetAttribute(0, #PB_Web_ScrollX)      
    EndSelect

  EndIf
Until (Event = #PB_Event_CloseWindow)


DataSection
  IID_IHTMLDocument2:
  Data.l $332C4425
  Data.w $26CB, $11D0
  Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19
  IID_IHTMLElement2:
  Data.l $3050F434
  Data.w $98B5, $11CF
  Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
EndDataSection
or use @RSBasic excellent webgadget
viewtopic.php?p=535740#p535740
also the mighty @JHPJHP has an HTML5 library that works great



Norm

Re: Scrolling the WebGadget

Posted: Sat Jul 27, 2019 2:31 am
by shadowvox
normeus wrote:Using @kenmos sample code and @Freaks code:
(this one scrolls by the number of pixels )

Code: Select all

;edited for clarity :)
or use @RSBasic excellent webgadget
viewtopic.php?p=535740#p535740
also the mighty @JHPJHP has an HTML5 library that works great



Norm
Thank you. I will try this when I get back to my PC.

Re: Scrolling the WebGadget

Posted: Tue Jul 30, 2019 6:49 pm
by shadowvox
I found a simple way, and it works great.

Code: Select all

Macro Click()
  mouse_event_(#MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  mouse_event_(#MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
EndMacro
 
; Click at the current location
Click()
 
Delay(1000) ; Wait a second
 
; Move to a new location and click it
SetCursorPos_(50, 50)
Click()

Re: Scrolling the WebGadget

Posted: Tue Jul 30, 2019 8:26 pm
by RSBasic
@shadowvox
It would work, but it's not recommended. A program should not change or abuse the mouse.

Re: Scrolling the WebGadget

Posted: Thu Aug 01, 2019 3:58 am
by kenmo
Yeah, please don't scroll a webgadget by moving the user's cursor and simulating mouse clicks!

Use the proper code in this thread or RASHAD's post:
viewtopic.php?f=12&t=73261

Re: Scrolling the WebGadget

Posted: Sun Aug 04, 2019 11:56 am
by shadowvox
@RSBasic and @kenmo
Message received and understood.
Mouse abuse is real.
Many have not even heard of it.
There could be a mouse in your house being abused.
Please help. Your donation will go a long way to help stop mouse abuse.
This message paid for by the Speedy Gonzales Memorial Foundation.

But no, I get it.

Re: Scrolling the WebGadget

Posted: Mon Aug 05, 2019 9:02 am
by RSBasic
:D