Page 1 of 2
Webgadget and links
Posted: Fri Mar 18, 2005 1:50 am
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

Posted: Fri Mar 18, 2005 3:24 pm
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
Posted: Sat Mar 19, 2005 12:38 am
by Le Soldat Inconnu

cool
Posted: Mon Mar 21, 2005 12:21 am
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
Thanks in advance

Posted: Mon Mar 21, 2005 3:30 am
by Sparkie
Awwww CRAP

Now I gotta go back into those #@$*!% VARIANT filled Interfaces again
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.
I'm curently working on a project with the WebGadget and it's
precious Interfaces once AGAIN

If I come across the
proper method for trapping links, I'll be sure to come back here and post my findings.

Posted: Mon Mar 21, 2005 4:02 am
by Kaiser
Pardon??
Posted: Mon Mar 21, 2005 4:17 am
by Fangbeast
"damn-fangled" ??? That's what my wife says to me sometimes.
Fang.
Posted: Sun Mar 27, 2005 1:12 am
by Kaiser
Lol xD
Could do anything o_o?

Posted: Sun Mar 27, 2005 1:25 am
by Sparkie
Posted: Fri Apr 08, 2005 5:54 am
by Kaiser
Aw I'm sorry
That code is hard though >:/ I would help but know none about it

wish it was possible, heh

Posted: Fri Apr 15, 2005 12:57 am
by Kaiser
*pokes the post*

?
Posted: Tue May 24, 2005 9:24 pm
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 (

sorry, i thought Basic was supposed to be easy) is the only way.
Posted: Thu May 26, 2005 6:11 pm
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
Posted: Thu May 26, 2005 8:14 pm
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
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/
Posted: Thu May 26, 2005 8:55 pm
by Blade
Looks great, but I don't see CSS(2) support.
With it we could really create cool interfaces. Simple HTML is too boring...