Page 1 of 1

Mac WebGadget callback ?

Posted: Fri Jul 10, 2015 1:05 am
by kenmo
The WebGadget "navigation callback" only works on Windows (see example below) despite the #PB_Web_NavigationCallback constant being present on Mac OS X.

Is there any CocoaMessage magic I could possibly use to intercept/prevent WebGadget navigation when the user clicks a link?

Code: Select all

  ; This example does display the PureBasic.com website. Inside the callback procedure
  ; the navigation to the 'News' site will be avoided (#False returned), but allowed
  ; for all other sites (#True returned).    
  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

I am looking to intercept links to certain filetypes and open them in a different part of my program.

Thanks!

Re: Mac WebGadget callback ?

Posted: Fri Jul 10, 2015 7:38 am
by Shardik
Did you already take a look into my navigation callback example for MacOS?

I also demonstrated here how to do it in Linux.

Re: Mac WebGadget callback ?

Posted: Fri Jul 10, 2015 1:18 pm
by kenmo
Hello Shardik!

No I did not see that post. I will try it on my Mac tonight. Thank you!

I did some forum searches and did not find anything... but now I realize I should have checked the big list of Cocoa tips... or Google search (your posts are the top results).

Re: Mac WebGadget callback ?

Posted: Sat Jul 11, 2015 4:51 am
by kenmo
Your solution seems to work perfectly! Thank you!

My only remaining Mac WebGadget issue is unrelated to this thread: the cursor icon seems unreliable. Sometimes when hovering over links it shows the "pointing finger" icon (correct) but often it shows the "I-beam" text cursor (incorrect). If I can reproduce this issue in a small example code, I might post a bug report...