aboutsummaryrefslogtreecommitdiffstats
path: root/lib/gs/doc/src/gs_chapter6.xmlsrc
blob: ecb891ad6f0dedee9263093cd761208dd6e554d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2000</year><year>2016</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions 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>