/* IupWebBrowser sample with Oxygenbasic */
' This program can be run anywhere on a data medium with Oxygenbasic,
' provided there is a path set for the IUP dlls: Iup.dll, Iupole.dll and Iupweb.dll
' It is assumed there exists \OxygenBasic\projectsB\IUP\IUP\ for the header files
' otherwise the includepath statement must be corrected.
' A created executable can run anywhere too, but a path for the IUP dlls must be provided also.
$ filename "webbrowser.exe"
'include "$/inc/RTL32.inc"
include "$/inc/console.inc"
includepath "$/projectsB/iup/iup/"
extern lib "iup.dll" cdecl
include "iup.h"
'extern lib "iupole.dll" cdecl
extern lib "iupweb.dll" cdecl
include "iupweb.h"
extern cdecl
function navigate_cb(Ihandle* self, char* url) as int
printl "NAVIGATE_CB: " & url
if instr(url, "download") then
printl "download ignored" & cr
return IUP_IGNORE
end if
return IUP_DEFAULT
end function
function error_cb(Ihandle* self, char* url) as int
printl "ERROR_CB: " & url & cr
return IUP_DEFAULT
end function
function completed_cb(Ihandle* self, char* url) as int
printl "COMPLETED_CB: " & url
return IUP_DEFAULT
end function
function newwindow_cb(Ihandle* self, char* url) as int
printl "NEWWINDOW_CB: " & url & cr
IupSetAttribute(self, "VALUE", url)
return IUP_DEFAULT
end function
function back_cb(Ihandle* self) as int
Ihandle* web = (Ihandle*)IupGetAttribute(self, "MY_WEB")
IupSetAttribute(web, "BACKFORWARD", "-1")
// printl "zoom=" & IupGetAttribute(web, "ZOOM") & cr
return IUP_DEFAULT
end function
function forward_cb(Ihandle* self) as int
Ihandle* web = (Ihandle*)IupGetAttribute(self, "MY_WEB")
IupSetAttribute(web, "BACKFORWARD", "1")
// IupSetAttribute(web, "ZOOM", "200")
return IUP_DEFAULT
end function
function stop_cb(Ihandle* self) as int
Ihandle* web = (Ihandle*)IupGetAttribute(self, "MY_WEB")
IupSetAttribute(web, "STOP", NULL)
return IUP_DEFAULT
end function
function reload_cb(Ihandle* self) as int
Ihandle* web = (Ihandle*)IupGetAttribute(self, "MY_WEB")
IupSetAttribute(web, "RELOAD", NULL)
//TEST:
// printl "STATUS=" & IupGetAttribute(web, "STATUS") & cr
return IUP_DEFAULT
end function
function load_cb(Ihandle* self) as int
Ihandle *txt = (Ihandle*)IupGetAttribute(self, "MY_TEXT")
Ihandle *web = (Ihandle*)IupGetAttribute(self, "MY_WEB")
IupSetAttribute(web, "VALUE", IupGetAttribute(txt, "VALUE"))
//TESTS:
// IupSetAttribute(txt, "VALUE", IupGetAttribute(web, "VALUE"))
// IupSetAttribute(web, "HTML", "<html><body><b>Hello</b>, World!</body></html>")
// IupSetAttribute(web, "VALUE", "http://www.microsoft.com")
return IUP_DEFAULT
end function
sub WebBrowserTest()
Ihandle *txt, *dlg, *web
Ihandle *btLoad, *btReload, *btBack, *btForward, *btStop
IupWebBrowserOpen()
// Creates an instance of the WebBrowser control
web = IupWebBrowser()
// Creates a dialog containing the control
'from bottom up
'controls
btBack = IupButton("Back", NULL)
btForward = IupButton("Forward", NULL)
txt = IupText("")
btLoad = IupButton("Load", NULL)
btReload = IupButton("Reload", NULL)
btStop = IupButton("Stop", NULL)
'container show horizontally
hbox = IupHbox(btBack, btForward, txt, btLoad, btReload, btStop, NULL)
'container show vertically hbox and webbrowser
vbox = IupVbox(hbox, web, NULL)
'final dialog
dlg = IupDialog(vbox)
IupSetAttribute(dlg, "TITLE", "IupWebBrowser")
zstring ptr ptxt at txt
IupSetAttribute(dlg, "MY_TEXT", ptxt)
zstring ptr pweb at web
IupSetAttribute(dlg, "MY_WEB", pweb)
IupSetAttribute(dlg, "RASTERSIZE", "800x600")
IupSetAttribute(dlg, "MARGIN", "10x10")
IupSetAttribute(dlg, "GAP", "10")
//IupSetAttribute(pweb, "HTML", "<html><body><b>Hello</b>World!</body></html>")
// IupSetAttribute(ptxt, "VALUE", "My HTML")
'' IupSetAttribute(ptxt, "VALUE", "http://www.tecgraf.puc-rio.br/iup")
IupSetAttribute(ptxt, "VALUE", "http://www.oxygenbasic.org")
// IupSetAttribute(ptxt, "VALUE", "file:///D:/tecgraf/iup/html/index.html")
IupSetAttribute(pweb, "VALUE", IupGetAttribute(ptxt, "VALUE"))
IupSetAttributeHandle(dlg, "DEFAULTENTER", btLoad)
IupSetAttribute(txt, "EXPAND", "HORIZONTAL")
IupSetCallback(btLoad, "ACTION", @load_cb)
IupSetCallback(btReload, "ACTION", @reload_cb)
IupSetCallback(btBack, "ACTION", @back_cb)
IupSetCallback(btForward, "ACTION", @forward_cb)
IupSetCallback(btStop, "ACTION", @stop_cb)
IupSetCallback(web, "NEWWINDOW_CB", @newwindow_cb)
IupSetCallback(web, "NAVIGATE_CB", @navigate_cb)
IupSetCallback(web, "ERROR_CB", @error_cb)
IupSetCallback(web, "COMPLETED_CB", @completed_cb)
// Shows dialog
IupShow(dlg)
end sub
sub main()
IupOpen(0,0)
WebBrowserTest()
IupMainLoop()
IupClose()
end sub
main()