Webgadget and links

Windows specific forum
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Webgadget and links

Post by Kaiser »

Yeah I was wondering if there was a way to catch the links that are clicked on a Webgadget and act in consequence? but blocking the action that the Webgadget is going to do?

Thanks in advance, you guys are really awesome :D
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

This certainly isn't the prettiest/best/most efficient method, but it may well be the easiest. ;)

Code: Select all

#READYSTATE_UNINITIALIZED = 0 
#READYSTATE_LOADING = 1 
#READYSTATE_LOADED = 2 
#READYSTATE_INTERACTIVE = 3 
#READYSTATE_COMPLETE = 4 
If OpenWindow(0, 10, 10, 700, 500, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "WebGadget ReadyState") And CreateGadgetList(WindowID())
  WebGadget(0, 10, 10, 680, 460, "http://www.purearea.net/pb/CodeArchiv/English.html") 
  ;--> Expose the IWebBrowser2 object so we can catch the load state
  WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA) ; needed for accessing IWebBrowser interface 
  CreateStatusBar(0, WindowID()) 
  StatusBarText(0, 0, "") 
  Repeat 
    event = WaitWindowEvent() 
    ;--> If WebGadget is busy loading a page
    If isBusy 
      WebObject\get_ReadyState(@isReady) 
      ;--> Determine the load state
      Select isReady 
        Case 1 
          StatusBarText(0, 0, "Page Loading") 
        Case 2 
          StatusBarText(0, 0, "Page Loaded") 
        Case 3 
          StatusBarText(0, 0, "Page is interactive with some data missing") 
        Case 4 
          StatusBarText(0, 0, "Page finished loading") 
      EndSelect 
    EndIf
    ;--> If page is loaded
    If isReady > 1
      webURL$ = GetGadgetText(0)
      ;--> and the url is not "http://www.purearea.net/pb/CodeArchiv/English.html"
      If  webURL$ <> "http://www.purearea.net/pb/CodeArchiv/English.html"
        ;--> Go back to "http://www.purearea.net/pb/CodeArchiv/English.html"
        SetGadgetState(0, #PB_Web_Back)
        MessageRequester("Info", webURL$ + " has been blocked")
      EndIf
    EndIf 
    ;--> Get the load state of WebGadget
    WebObject\get_busy(@isBusy) 
  Until event = #PB_Event_CloseWindow 
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Le Soldat Inconnu
Enthusiast
Enthusiast
Posts: 306
Joined: Wed Jul 09, 2003 11:33 am
Location: France

Post by Le Soldat Inconnu »

:D cool
LSI
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

Wow, nice example there Sparkie :) and thanks for it :) though, it doesn't seems to get the link for a file to download. For example, I tried with the links of the zip files in http://www.furcadia.com/patches/ and it still opens the explorer download manager. Your example is exactly what I want, just need to see how to make it work with the files to download.. if so, it would be awesome :D

Thanks in advance :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Awwww CRAP :!: Now I gotta go back into those #@$*!% VARIANT filled Interfaces again :twisted:

I got brain freeze last summer from working with WebGdaget's and all those damn-fangled Interfaces. The code I posted above was the Sparkie cop-out from Interfaces method. :P

I'm curently working on a project with the WebGadget and it's precious Interfaces once AGAIN :shock: :? If I come across the proper method for trapping links, I'll be sure to come back here and post my findings. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

Hehe x) I feel your pain, but you have more experience than me :shock: anyways, good luck on that :D YAY you rock :D :D :D
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Pardon??

Post by Fangbeast »

"damn-fangled" ??? That's what my wife says to me sometimes.


Fang.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

Lol xD

Could do anything o_o? :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

:lol: @Fang

@Kaiser - I'm still trying. Here's a link to the code I'm attempting to convert to PB-speak...
http://msdn.microsoft.com/library/defau ... s/sink.asp

Still no luck. :evil: :? :shock: :(
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

Aw I'm sorry :(

That code is hard though >:/ I would help but know none about it :( wish it was possible, heh :P
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

*pokes the post* :shock: ?
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Sparkie, I requested this particular feature, and was pointed to the IWebBrowser2 interface
by Fred, and this post is the closest I got to an answer.

What is probably needed in order to catch a link is to trap an 'about to navigate' event, get
the url it is about to navigate to (which is the link), and cancel the navigation, which means
the Web Gadget continue to display the page containing the link.

If WebObject\get_ReadyState(@isReady) returns a 'Page about to load' maybe it's possible to use

Url.s=GetGadgetText() ;Got the link
SetGadgetState(#PBB_Web_Stop)

in response. I still evaluate PureBasic so I cant't check out any of this, though. Have you done
any prograss on this.??

From the response to my request it seems this isn't going to be built into the language any time
soon, and that this mess ( :wink: sorry, i thought Basic was supposed to be easy) is the only way.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Sorry for the post above, I didn't have the registered version then and misunderstood the whole thing.

It do capture links in the html, simple and to the point! Thanks! :). Below is a simplified template I used to check it out:

Code: Select all

Flags=#PB_Window_ScreenCentered|#PB_Window_SystemMenu
OpenWindow(0,0,0,600,400,Flags,"Html UI")
CreateGadgetList(WindowID()) 

WebGadget(1,0,0,600,400,"file://c:\page.html")
;page.html:
; <html><body scroll=no>
; <a href="Download">Get Pictures</a></body></html>

;Expose the IWebBrowser2 object
WebObject.IWebBrowser2=GetWindowLong_(GadgetID(1),#GWL_USERDATA)

Repeat 
  Event=WaitWindowEvent() 
  ;If busy loading a page 
  If isBusy 
    WebObject\get_ReadyState(@isReady)
    If isReady
      Url$=GetGadgetText(1) 
      If FindString(Url$,"Download",1)
        ;Link clicked, cancel navigation
        SetGadgetState(1,#PB_Web_Back)
        ;Process the link event
        MessageRequester("Link",Url$)
      EndIf
    EndIf
  EndIf 
  WebObject\get_busy(@isBusy)
Until Event=#PB_Event_CloseWindow 
End
Last edited by utopiomania on Thu May 26, 2005 10:56 pm, edited 1 time in total.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

This only works *after* you leave the page you wanted to catch...

I would like it to catch the clicked link and give it to me *before* the control is sent to the clicked page.

For example, i wanna capture custom control switches, like this:

Code: Select all

<a href="command:executequery01" title="Get Bank Account">See Bank Account</a>
I just want the webgadget to report "command:executequery01", and then i generate the output html and pass it to the webgadget :P

I guess this is what is needed:

Code: Select all


  If Event=#PB_Event_Gadget   
    If EventGadgetID()=#mywebgadget
          If EventType() = #PB_EventType_LinkPressed ;intercept links before they get executed by the webgadget
            command.s=WebGadgetGetLink(#mywebgadget)
            ;do stuff
            ;generate return webpage
            SetGadgetText(#mywebgadget,"aaaa.htm")
            SetGadgetState(#mywebgadget, #PB_Web_Refresh)
            
           or ; if command existed
           WebGadgetSetHTM(#mywebgadget,buffer, bufferlenght)
           SetGadgetState(#mywebgadget, #PB_Web_Refresh)

          EndIf
    Endif   
  EndIf

Take a look at this neat HTML renderer, so you can understand the power behind this:

http://www.gipsysoft.com/
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Num3 wrote: Take a look at this neat HTML renderer, so you can understand the power behind this:
http://www.gipsysoft.com/
Looks great, but I don't see CSS(2) support.
With it we could really create cool interfaces. Simple HTML is too boring...
Post Reply