WebGadget help example with nav-callback...

Mac OSX specific forum
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

WebGadget help example with nav-callback...

Post by Kukulkan »

Hello,

the Example 2: (with navigation callback) from the WebGadget help page does not work:

Code: Select all

Procedure NavigationCallback(Gadget, Url$) 
  If Url$= "http://www.purebasic.com/news.php" 
    MessageRequester("", "No news today!") 
    ProcedureReturn #False 
  Else 
    ProcedureReturn #True 
  EndIf 
EndProcedure 

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com") 
  SetGadgetAttribute(0, #PB_Web_NavigationCallback, @NavigationCallback())
  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
There is nothing mentioned that this is not working on MacOS - so it is a bug?

Kukulkan
Last edited by Kukulkan on Tue Mar 12, 2013 5:53 pm, edited 1 time in total.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: WebGadget help example with nav-callback does not work

Post by jesperbrannmark »

I had that in a previous post. The callback doesn't work for webgadget for mac. no bug - its just not implemented.
You can check page by in the main loop do a getgadgettext(gadget) to see if it has changed.
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: WebGadget help example with nav-callback does not work

Post by Kukulkan »

Hi,

in this case the bug is in the documentation. There is nothing mentioned that this is not working on MacOS.

Kukulkan
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: WebGadget help example with nav-callback does not work

Post by Shardik »

Kukulkan wrote:in this case the bug is in the documentation. There is nothing mentioned that this is not working on MacOS.
PB help for WebGadget wrote:- SetGadgetAttribute(): Set the following attributes (Windows only):
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: WebGadget help example with nav-callback does not work

Post by Kukulkan »

Oh damn :oops: Sorry.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [DONE]WebGadget help example with nav-callback does not

Post by Shardik »

Since SetGadgetAttribute() is not implemented on MacOS X, you may use the following modified code taken from wilbert's nice example to intercept clicks on a hyperlink just as in the example from PB help:

Code: Select all

EnableExplicit

ImportC ""
  sel_registerName(str.p-ascii)
  class_addMethod(class, selector, imp, types.p-ascii)
EndImport

Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
Global delegateClass = CocoaMessage(0, appDelegate, "class")

ProcedureC PolicyDecisionMaker(obj, sel, webView, actionInformation, request, frameName, listener)
  Protected URL = CocoaMessage(0, request, "URL")
  Protected URLString.s = PeekS(CocoaMessage(0, CocoaMessage(0, URL, "absoluteString"), "UTF8String"), -1, #PB_UTF8)

  If URLString = "http://www.purebasic.com/news.php" 
    MessageRequester("", "No news today!")
  Else
    CocoaMessage(0, listener, "use")
  EndIf
EndProcedure

class_addMethod(delegateClass, sel_registerName("webView:decidePolicyForNavigationAction:request:frame:decisionListener:"), @PolicyDecisionMaker(), "v@:@@@@@")

If OpenWindow(0, 270, 100, 600, 300, "WebGadget")
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com") 
  CocoaMessage(0, GadgetID(0), "setPolicyDelegate:", appDelegate)
 
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
It would be nice if this thread could be moved to the MacOSX subforum.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2058
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: [DONE]WebGadget help example with nav-callback does not

Post by Andre »

I moved this topic from bug-reports to regular MacOS forum for further use, and additionally changed the thread title a bit... :-)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply