HTML label
Posted: Sun May 13, 2012 7:33 am
Hi folks,
the webgadget is very helpful to create a nice GUI. To faciliate this, I wrote this small procedure.
You can use a standard template (CSS/HTML) that may be included as binary file.
The sample template below is very poor, someone surely has some better and more impressive styles
CA
Oli
template.htm:
the webgadget is very helpful to create a nice GUI. To faciliate this, I wrote this small procedure.
You can use a standard template (CSS/HTML) that may be included as binary file.
The sample template below is very poor, someone surely has some better and more impressive styles
CA
Oli
Code: Select all
Global HTMLStyle$
Procedure NavigationCallback(Gadget, Url$)
Protected slnk$, bRet
If FindString(url$,"#")>0
slnk$=StringField(URL$,2,"#")
Else
slnk$=Url$
EndIf
Debug slnk$
Select UCase(slnk$)
Case "COMMAND1"
ProcedureReturn #False
Default
EndSelect
ProcedureReturn #True
EndProcedure
Procedure SetHTML (iGadget,sText$,sTemplate$="", bNoScroll=1,AltNavCallback=0)
Protected st$, stmp$
Protected Browser.iwebbrowser2
; iGadget: Webgadget
; sText$: text to display
; sTemplate$: HTML/CSS template
; bNoScroll: disable scrollbar
; AltNavCallback: Alternative callback
If IsGadget(iGadget)
Browser.iwebbrowser2=GetWindowLongPtr_(GadgetID(iGadget),#GWL_USERDATA)
If browser
browser\put_Silent(#True)
EndIf
If sTemplate$=""
st$=HTMLStyle$
Else
st$=sTemplate$
EndIf
If bNoScroll=1: stmp$="scroll='no'":EndIf
st$=ReplaceString(st$,"[SCROLL]",stmp$)
st$=ReplaceString(st$,"[TEXT]",sText$)
SetGadgetItemText(iGadget,#PB_Web_HtmlCode,st$)
If AltNavCallback=0
SetGadgetAttribute(iGadget, #PB_Web_NavigationCallback, @NavigationCallback())
Else
SetGadgetAttribute(iGadget, #PB_Web_NavigationCallback, AltNavCallback)
EndIf
EndIf
EndProcedure
DataSection
HTML_Template:
IncludeBinary "template.htm"
HTML_Template_End:
EndDataSection
HTMLStyle$=PeekS(?HTML_Template,?HTML_Template_End-?HTML_Template)
; Sample
If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
id=WebGadget(#PB_Any, 10, 10, 580, 280, "")
sSampletext$= "<b>Hello World!</b> <p id='infobox'>a box</p>"
sSampletext$+"<h1>here a link</h1><a href='#command1'>command 1</a>"
sSampletext$+ "<hr id='line'>"
sSampletext$+"<h1>And now a list with links</h1><p id='box' width='150'><a class='link' href='#command2'>Command 2</a><a class='link' href='#command3'>Command 3</a></p>"
sethtml(id,sSampletext$)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Select all
<html>
<body [SCROLL] oncontextmenu = 'javascript:return false;'>
<style type="text/css">
body { background-color:#FFFFFF;
*
{
font-family:helvetica;
font-size:10pt;
}
h1 {
font-family:helvetica;
font-size:12pt;
font-weight:bold
}
#rahmen {
border-width:1.5px;
border-style:solid;
border-color:#c0c0c0;
background-color:#e0e0e0;
padding:0.5em;
text-align:justify;
font-family:helvetica;
font-size:small;
width: 200px;
}
#box {
border-width:1.5px;
border-style:solid;
border-color:#c0c0c0;
text-align:justify;
font-family:helvetica;
font-size:10pt;
padding: 0px 0px 0px 0px;
margin-left: 0px;
width:120px;
}
#infobox {
border-width:1.5px;
border-style:solid;
border-color:#c0c0c0;
background-color:#E0E0E0;
text-align:justify;
font-family:helvetica;
font-size:10pt;
margin-left: 0px;
}
#line {
border-width:0.2pt;
border-style:solid;
border-color:blue;
}
a.link{
display:block;
width: 120px;
color:#000000;
text-align:center;
text-decoration:none;
}
a.link:hover{
color:#ffffff;
text-decoration:none;
background-color:#006699;
}
</style>
[TEXT]
</body<
</html>