Thanks in advance, you guys are really awesome
Webgadget and links
Webgadget and links
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
			
			
									
									
						Thanks in advance, you guys are really awesome
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
EndWhat goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
						PB 5.21 LTS (x86) - Windows 8.1
- Le Soldat Inconnu
 - Enthusiast

 - Posts: 306
 - Joined: Wed Jul 09, 2003 11:33 am
 - Location: France
 
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
			
			
									
									
						Thanks in advance
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. 
			
			
									
									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
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
						PB 5.21 LTS (x86) - Windows 8.1
@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.
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
						PB 5.21 LTS (x86) - Windows 8.1
- utopiomania
 - Addict

 - Posts: 1655
 - Joined: Tue May 10, 2005 10:00 pm
 - Location: Norway
 
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.
			
			
									
									
						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 (
- utopiomania
 - Addict

 - Posts: 1655
 - Joined: Tue May 10, 2005 10:00 pm
 - Location: Norway
 
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:
			
			
													It do capture links in the html, simple and to the point! Thanks!
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

 - Posts: 2812
 - Joined: Fri Apr 25, 2003 4:51 pm
 - Location: Portugal, Lisbon
 - Contact:
 
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:
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:
Take a look at this neat HTML renderer, so you can understand the power behind this:
http://www.gipsysoft.com/
			
			
									
									
						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 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
http://www.gipsysoft.com/
- 
				Blade
 - Enthusiast

 - Posts: 362
 - Joined: Wed Aug 06, 2003 2:49 pm
 - Location: Venice - Italy, Japan when possible.
 - Contact:
 
Looks great, but I don't see CSS(2) support.Num3 wrote: Take a look at this neat HTML renderer, so you can understand the power behind this:
http://www.gipsysoft.com/
With it we could really create cool interfaces. Simple HTML is too boring...