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.