gui_canvas
Returns or sets the GUI canvas data for the specified canvas.
Available in:
Apps (win) |
Apps (char) |
Reportwriter |
RPC |
Standalone PL |
X |
|
|
|
|
Syntax
string gui_canvas(canvas_name[,data_string])
string canvas_name
string data_string
Description
The canvas_name parameter is the name of the canvas object.
In WPF, if data_string is not specified, then the data values of all the
modifiable named obects in the canvas are returned in an XML string.
data_string has four options:
<DATA object_name='value'>
|
object_name matches the object's name in the string that
defines it in the canvas. Multiple object_name='value' pairs can be
passed at one time.
|
<EXEC object_name='JavaScriptFncName parms'>
|
object_name is the name of a previously loaded HTML browser object.
JavaScriptFncName is the name of a JavaScript function in
object_name.
value is a parameter to pass into the JavaScript function.
Multiple object_name='JavaScriptFncName parms' pairs can be
passed at one time.
|
<HTML object_name='value'>
|
object_name matches the object's name in the string that
defines it in the canvas.
value the HTML code to assign to object_name
|
URL
|
Fills the canvas with a web browser opened to the URL.
|
There are two ways to load the HTML/XAML canvas definition. The first is using
dvApp to insert the definition which is then stored as part of the
design however the WPF client expects XAML and will fail if HTML
is found in the canvas. Thus if the goal is to have a shared WPF and HTML5
browser project, then it is better to leave the dvApp canvas object definition
empty and dynamically load it using gui_canvas() at
runtime. The gui_id() function returns the type of the client being
used.
WPF
WPF applications use XAML to define the canvas. While any valid XAML may be
used, only the following object types and values can be read or written
by gui_canvas():
Control |
Write |
Read |
Format |
Button |
Button name |
N/A |
Text |
CheckBox |
State |
State |
"": null, 0: unchecked, non-zero: checked |
Image |
URI |
URI |
URI. |
ProgressBar |
Progress |
Progress |
nn.nn, the value between the miminum (default 0)
and maximum (default 100). |
Slider |
Position |
Position |
nn.nn, the value between the miminum (default 0) and maximum (default 10). |
TextBlock |
Content |
N/A |
Text |
TextBox |
Content |
Content |
Text |
WebBrowser |
URL |
URL |
URL. |
HTML5 Browser
HTML5 browser applications use any well-formed HTML to define the canvas.
gui_canvas() cannot return any values from HTML except via the
EXEC method.
WPF examples
A canvas object named CV has the following definition in the gap file:
<StackPanel>
<TextBlock Name="TITLE">A Sample Canvas</TextBlock>
<Button Name="B1" Tag="A909">Press Me</Button>
<Button Name="B2" Tag="A808">And me!</Button>
<StackPanel Orientation="Horizontal">
<TextBox Name="FNAME"/>
<Separator/>
<TextBox Name="LNAME"/>
<Separator/>
<CheckBox Name="CB"/>
<Separator/>
<ProgressBar Name="PB" Width="200"/>
</StackPanel>
<Slider Name="SL"/>
<WebBrowser Name="WB" Width="580" Height="300" Source="http://www.trifox.com"/>
<Image Name="IM" Width="100" Height="100" Source="run.png"/>
</StackPanel>
To set the FNAME, LNAME, and CB values, use
gui_canvas("CV","<DATA LNAME='Doe' FNAME='John' CB='1'/>");
and these values will appear in the respective canvas objects with the
checkbox showing checked. To read the current values,
buf = gui_canvas("CV");
and buf will contain
<DATA LNAME='Doe' FNAME='John' CB='1'/>
HTML5 examples
A canvas object named CV has the following definition in the gap file:
<iframe id='WB1' src='http://www.trifox.com'></iframe>
<iframe id='WB2'></iframe>
<iframe id='WB3'></iframe>
<iframe id='WB4' src='http://www.aptean.com'></iframe>
To set the FNAME, LNAME, and CB values, use
gui_canvas("CV","<DATA WB2='http://www.expressen.se' WB3='http://www.oracle.com'>");
and these values will appear in the respective canvas browser objects.
To read the current values,
buf = gui_canvas("CV");
and buf will contain
<DATA WB1='http://www.trifox.com' WB2='http://www.expressen.se'
WB3='http://www.oracle.com' WD4='http://www.aptean.com'/>
As a shortcut, if you want to simply fill the canvas with a URL, you can just
send
gui_canvas("CV","http://www.trifox.com");
EXEC example
EXEC is used to execute JavaScript functions. This HTML creates a
JavaScript function called WB_EXE and an iframe:
HL = list_open("80",0);
list_mod(HL,1,"<html><head>");
list_mod(HL,1,"<script type='text/javascript'>");
list_mod(HL,1,"var what = 'World';");
list_mod(HL,1,"function WB_EX(parmOne) {");
list_mod(HL,1,"alert(parmOne);");
list_mod(HL,1,"return(what); }");
list_mod(HL,1,"</script></head>");
list_mod(HL,1,"<iframe width='600' height='500'");
list_mod(HL,1," src='http://www.trifox.com'></iframe>");
list_mod(HL,1,"</html>");
list_view(HL,0);
gui_canvas("CV","<HTML WB='" ^^ xml(xml_esc,list2str(HL)) ^^ "'/>");
The xml() function is used to escape the special HTML characters. Once
the string is loaded, execute the function:
LL = list_open("select name,id from staff",99);
list_file(LL,"clipboard!","j");
gui_canvas("CV","<EXEC WB='WB_EX "^^ xml(xml_esc,clipboard(cb_extract)) ^^ "'/>");
and get the return value:
buf = gui_canvas("CV");
and buf will contain
World