[solved]PB_Web_NavigationCallback

Just starting out? Need help? Post your questions and find answers here.
quasiperfect
Enthusiast
Enthusiast
Posts: 157
Joined: Tue Feb 13, 2007 6:16 pm
Location: Romania
Contact:

[solved]PB_Web_NavigationCallback

Post by quasiperfect »

can someone post a example using #PB_Web_NavigationCallback to disable drag and drop on a web gadget ?

i tried to use it like this but dosen't work if i drag a page from a browser to the app window it loads the url and i don't want that

Code: Select all

Global Window_Main
Global Gadget_Web
Global appdir$
a$=Space(999) : GetModuleFileName_(0,@a$,999) : appdir$=GetPathPart(a$) 

Procedure NavigationCallback(Gadget, Url$)
    ;
    ; Return #True to allow this navigation or #False to deny it.
    ;
    Debug "called"
    ProcedureReturn #False
  EndProcedure

Procedure OpenWindow_Window_Main()
  ExamineDesktops()
  Window_Main = OpenWindow(#PB_Any, 0, 0, 780,560, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_Maximize)
  If Window_Main
    If CreateGadgetList(WindowID(Window_Main))
      Gadget_Web = WebGadget(#PB_Any, 0, 0, WindowWidth(Window_Main),WindowHeight(Window_Main),appdir$+"library\index.html",#PB_Web_NavigationCallback)
      PureRESIZE_SetGadgetResize(Gadget_Web, 1, 1, 1, 1)
      SetGadgetAttribute(Gadget_Web, #PB_Web_BlockPopupMenu ,1)
      PureRESIZE_SetWindowMinimumSize(Window_Main, 780, 560)
    EndIf
  EndIf
EndProcedure

OpenWindow_Window_Main()
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Gadget_Web
          NavigationCallback(Gadget_Web,"")
      EndSelect
    Case #PB_Event_CloseWindow
     Select EventWindow()
      Case Window_Main
        CloseWindow(Window_Main)
        Window_Main = 0
        Break
     EndSelect
  EndSelect
ForEver
Last edited by quasiperfect on Sat Mar 15, 2008 5:23 pm, edited 1 time in total.
Registered user of PureBasic
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Post by mrjiles »

You have to use SetGadgetAttribute to actually use the callback procedure, such as:

Code: Select all

SetGadgetAttribute(#Browser, #PB_Web_NavigationCallback, @NavigationCallback())

So here's a fully functional sample I wrote:

Code: Select all

#Window = 1
#Browser = 2

Procedure NavigationCallback(Gadget, Url$)
     If Url$ <> "http://www.google.com/"
          ProcedureReturn #False
     Else
          ProcedureReturn #True
     EndIf
EndProcedure

OpenWindow(#Window, 0, 0, 500, 400, "Disable drag and drop (and all other navigation)", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(#Window))
WebGadget(#Browser, 0, 0, 500, 400, "http://www.google.com/", #PB_Web_NavigationCallback)
SetGadgetAttribute(#Browser, #PB_Web_NavigationCallback, @NavigationCallback())


Repeat
     Event = WaitWindowEvent()
     If Event = #PB_Event_CloseWindow
          Quit = #True
     EndIf
Until Quit = #True
End
quasiperfect
Enthusiast
Enthusiast
Posts: 157
Joined: Tue Feb 13, 2007 6:16 pm
Location: Romania
Contact:

Post by quasiperfect »

thanks a lot that was a easy to understand example that solved my problem
Registered user of PureBasic
Post Reply