Page 1 of 1
WebGadget help example with nav-callback...
Posted: Tue Mar 12, 2013 11:37 am
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
Re: WebGadget help example with nav-callback does not work
Posted: Tue Mar 12, 2013 1:22 pm
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.
Re: WebGadget help example with nav-callback does not work
Posted: Tue Mar 12, 2013 1:30 pm
by Kukulkan
Hi,
in this case the bug is in the documentation. There is nothing mentioned that this is not working on MacOS.
Kukulkan
Re: WebGadget help example with nav-callback does not work
Posted: Tue Mar 12, 2013 5:31 pm
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):
Re: WebGadget help example with nav-callback does not work
Posted: Tue Mar 12, 2013 5:53 pm
by Kukulkan
Oh damn

Sorry.
Re: [DONE]WebGadget help example with nav-callback does not
Posted: Tue Mar 12, 2013 6:14 pm
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.
Re: [DONE]WebGadget help example with nav-callback does not
Posted: Tue Mar 19, 2013 11:47 pm
by Andre
I moved this topic from bug-reports to regular MacOS forum for further use, and additionally changed the thread title a bit...
