WebGadget help example with nav-callback...

Mac OSX specific forum
User avatar
Shardik
Addict
Addict
Posts: 2076
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: 2158
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