OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tcl8.6.12 / pkgs / itcl4.2.2 / doc / itcloption.n
1 '\"
2 '\" Copyright (c) 2008 Arnulf Wiedemann
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH option n 4.0 itcl "[incr\ Tcl]"
8 .so man.macros
9 .BS
10 '\" Note:  do not modify the .SH NAME line immediately below!
11 .SH NAME
12 itcl::option \- define options for extendedclass, widget or widgetadaptor
13 .PP
14 Parts of this description are "borrowed" from Tcl extension [snit], as the functionality is mostly identical.
15 .SH WARNING!
16 This is new functionality in [incr Tcl] where the API can still change!!
17 .SH SYNOPSIS
18 .nf
19 \fBoption \fIoptionSpec\fR ?\fIdefaultValue\fR?
20 \fBoption \fIoptionSpec\fR ?\fIoptions\fR?
21 .fi
22 .BE
23
24 .SH DESCRIPTION
25 .PP
26 The \fBoption\fR command is used inside an \fB[incr\ Tcl]\fR
27 extendedclass/widget/widgetadaptor definition to define options.
28 .PP
29 In the first form defines an option for instances of this type, and optionally
30 gives it an initial value. The initial value defaults to the empty string if
31 no defaultValue is specified.
32 .PP
33 An option defined in this way is said to be locally defined.
34 The optionSpec is a list defining the option's name, resource name, and class
35 name, e.g.:
36 .PP
37 .CS
38     option {-font font Font} {Courier 12}
39 .CE
40 .PP
41 The option name must begin with a hyphen, and must not contain any upper case
42 letters. The resource name and class name are optional; if not specified,
43 the resource name defaults to the option name, minus the hyphen, and the class
44 name defaults to the resource name with the first letter capitalized. Thus, the
45 following statement is equivalent to the previous example:
46 .PP
47 .CS
48     option -font {Courier 12}
49 .CE
50 .PP
51 See The Tk Option Database for more information about resource and class names.
52 .PP
53 Options are normally set and retrieved using the standard instance methods
54 configure and cget; within instance code (method bodies, etc.), option values
55 are available through the options array:
56 .PP
57 .CS
58     set myfont $itcl_options(-font)
59 .CE
60 .PP
61 In the second form you can define option handlers (e.g., -configuremethod),
62 then it should probably use configure and cget to access its options to avoid
63 subtle errors.
64 .PP
65 The option statement may include the following options:
66 .TP
67 \fB-default\fI defvalue\fR
68 .
69 Defines the option's default value; the option's default value will be ""
70 otherwise.
71 .TP
72 \fB-readonly\fR
73 .
74 The option is handled read-only -- it can only be set using configure at
75 creation time, i.e., in the type's constructor.
76 .TP
77 \fB-cgetmethod\fI methodName\fR
78 .
79 Every locally-defined option may define a -cgetmethod; it is called when the
80 option's value is retrieved using the cget method. Whatever the method's body
81 returns will be the return value of the call to cget.
82 .RS
83 .PP
84 The named method must take one argument, the option name. For example, this
85 code is equivalent to (though slower than) Itcl's default handling of cget:
86 .PP
87 .CS
88         option -font -cgetmethod GetOption
89         method GetOption {option} {
90             return $itcl_options($option)
91         }
92 .CE
93 .PP
94 Note that it's possible for any number of options to share a -cgetmethod.
95 .RE
96 .TP
97 \fB-cgetmethodvar\fI varName\fR
98 .
99 That is very similar to -cgetmethod, the only difference is, one can define
100 a variable, where to find the cgetmethod during runtime.
101 .TP
102 \fB-configuremethod\fI methodName\fR
103 .
104 Every locally-defined option may define a -configuremethod; it is called
105 when the option's value is set using the configure or configurelist
106 methods. It is the named method's responsibility to save the option's
107 value; in other words, the value will not be saved to the itcl_options()
108 array unless the method saves it there.
109 .RS
110 .PP
111 The named method must take two arguments, the option name and its new value.
112 For example, this code is equivalent to (though slower than) Itcl's default
113 handling of configure:
114 .PP
115 .CS
116         option -font -configuremethod SetOption
117         method SetOption {option value} {
118             set itcl_options($option) $value
119         }
120 .CE
121 .PP
122 Note that it's possible for any number of options to share a single -configuremethod.
123 .RE
124 .TP
125 \fB-configuremethodvar\fI varName\fR
126 .
127 That is very similar to -configuremethod, the only difference is, one can define
128 a variable, where to find the configuremethod during runtime.
129 .TP
130 \fB-validatemethod\fI methodName\fR
131 .
132 Every locally-defined option may define a -validatemethod; it is called when
133 the option's value is set using the configure or configurelist methods, just
134 before the -configuremethod (if any). It is the named method's responsibility
135 to validate the option's new value, and to throw an error if the value is
136 invalid.
137 .RS
138 .PP
139 The named method must take two arguments, the option name and its new value.
140 For example, this code verifies that -flag's value is a valid Boolean value:
141 .PP
142 .CS
143         option -font -validatemethod CheckBoolean
144         method CheckBoolean {option value} {
145             if {![string is boolean -strict $value]} {
146                 error "option $option must have a boolean value."
147             }
148         }
149 .CE
150 .PP
151 Note that it's possible for any number of options to share a single -validatemethod.
152 .RE
153 .TP
154 \fB-validatemethodvar\fI varName\fR
155 .
156 That is very similar to -validatemethod, the only difference is, one can define
157 a variable, where to find the validatemethod during runtime.
158
159 .SH KEYWORDS
160 option, widget, widgetadaptor, extendedclass