diff options
Diffstat (limited to 'lib/gs/doc/src/gs_chapter6.xmlsrc')
-rw-r--r-- | lib/gs/doc/src/gs_chapter6.xmlsrc | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/gs/doc/src/gs_chapter6.xmlsrc b/lib/gs/doc/src/gs_chapter6.xmlsrc new file mode 100644 index 0000000000..9fd9fdc414 --- /dev/null +++ b/lib/gs/doc/src/gs_chapter6.xmlsrc @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="latin1" ?> +<!DOCTYPE chapter SYSTEM "chapter.dtd"> + +<chapter> + <header> + <copyright> + <year>2000</year><year>2009</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + </legalnotice> + + <title>Default Values</title> + <prepared></prepared> + <docno></docno> + <date></date> + <rev></rev> + <file>gs_chapter6.xml</file> + </header> + + <section> + <title>The Default Value Model</title> + <p>When a new object is created, a set of options is provided by the application. Options which are not explicitly given are taken care of by the parent (the container object).</p> + <code type="none"><![CDATA[ +B=gs:create(button,Win,[{x,0},{label,{text,"press Me"}}]). + ]]></code> + <p>In the example shown above, the window provides default values for options like location and background color. If an application cannot use the default values provided by GS, new ones can be configured. For example, the following code creates a red button at location y=30.</p> + <code type="none"><![CDATA[ +gs:config(Win,[{default,button,{y,30}}, +{default,button,{font,{courier,18}}}]), +B=gs:create(button,Win,[{x,0},{label,{text,"press Me"}}]). + ]]></code> + <p>The syntax for the default option is <c><![CDATA[{default,Objecttype,{Option,DefaultValue}}]]></c>, where <c><![CDATA[Objecttype]]></c> is the name of any GS object. The special keywords <c><![CDATA[all]]></c> or <c><![CDATA[buttons]]></c> which denote button, radio button, and check button can be used.</p> + <p>The semantics for the default option can be expressed as follows: If an object of kind <c><![CDATA[Objecttype]]></c> is created and no value for <c><![CDATA[Option]]></c> is given, then use <c><![CDATA[DefaultValue]]></c> as the value. Only options of <c><![CDATA[{Key,Value}]]></c> syntax can be given a default values. Default values may be inherited in several steps. In the following example, the button will show the text "Cancel".</p> + <code type="none"><![CDATA[ +gs:config(Win,[{default,button,{label,{text,"Cancel"}}}]), +F=gs:create(frame,Win,[]), +B=gs:create(button,F,[]). + ]]></code> + <p>Default values are inherited so that changed default values only affect new objects, not existing objects.</p> + <p>Default values only have meaning when creating child objects, since objects which cannot have children cannot have default options. An example is buttons.</p> + <p>The following example illustrates how default options can be used:</p> + <marker id="gs_fig7"></marker> + <image file="images/ex16.gif"> + <icaption>Example of Default Options</icaption> + </image> + <codeinclude file="examples/ex16.erl" tag="" type="erl"></codeinclude> + </section> +</chapter> + |