OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itk/] [doc/] [Archetype.n] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1993-1998  Lucent Technologies, Inc.
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
'\" RCS: $Id: Archetype.n,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
8
'\"
9
.so man.macros
10
.TH Archetype n 3.0 itk "[incr\ Tk]"
11
.BS
12
'\" Note:  do not modify the .SH NAME line immediately below!
13
.SH NAME
14
Archetype \- base class for all [incr\ Tk] mega-widgets
15
.SH "INHERITANCE"
16
none
17
.ta 4c 8c 12c
18
.SH "WIDGET-SPECIFIC OPTIONS"
19
.LP
20
.nf
21
Name:   \fBclientData\fR
22
Class:  \fBClientData\fR
23
Command-Line Switch:    \fB-clientdata\fR
24
.fi
25
.IP
26
This does not affect the widget operation in any way.  It is
27
simply a hook that clients can use to store a bit of data with
28
each widget.  This can come in handy when using widgets to
29
build applications.
30
.BE
31
 
32
.SH DESCRIPTION
33
.PP
34
The \fBArchetype\fR class is the basis for all \fB[incr\ Tk]\fR
35
mega-widgets.  It keeps track of component widgets and provides
36
methods like "configure" and "cget" that are used to access
37
the composite configuration options.  Each component widget
38
must be registered with the \fBArchetype\fR base class using
39
the "\fBitk_component add\fR" method.  When the component
40
is registered, its configuration options are integrated into
41
the composite option list.  Configuring a composite option
42
like "-background" causes all of the internal components
43
to change their background color.
44
.PP
45
It is not used as a widget by itself, but is used as a base
46
class for more specialized widgets.  The \fBWidget\fR base class
47
inherits from \fBArchetype\fR, and adds a Tk frame which acts as
48
the "hull" for the mega-widget.  The \fBToplevel\fR base class
49
inherits from \fBArchetype\fR, but adds a Tk toplevel which acts
50
as the "hull".
51
.PP
52
\fIEach derived class must invoke the \fBitk_initialize\fP method
53
within its constructor\fR, so that all options are properly
54
integrated and initialized in the composite list.
55
 
56
 
57
.SH "PUBLIC METHODS"
58
.PP
59
The following methods are provided to support the public
60
interface of the mega-widget.
61
.TP
62
\fIpathName \fBcget\fR \fIoption\fR
63
Returns the current value of the configuration option given
64
by \fIoption\fR.
65
.sp
66
In this case, \fIoption\fR refers to a composite configuration
67
option for the mega-widget.  Individual components integrate
68
their own configuration options onto the composite list when
69
they are registered by the "\fBitk_component add\fR" method.
70
.TP
71
\fIpathName\fR \fBcomponent\fR ?\fIname\fR? ?\fIcommand arg arg ...\fR?
72
Used to query or access component widgets within a mega-widget.
73
With no arguments, this returns a list of symbolic names for
74
component widgets that are accessible in the current scope.
75
The symbolic name for a component is established when it is
76
registered by the "\fBitk_component add\fR" method.  Note that
77
component widgets obey any public/protected/private access
78
restriction that is in force when the component is created.
79
.sp
80
If a symbolic \fIname\fR is specified, this method returns the
81
window path name for that component.
82
.sp
83
Otherwise, the \fIcommand\fR and any remaining \fIarg\fR arguments
84
are invoked as a method on the component with the symbolic
85
name \fIname\fR.  This provides a well-defined way of accessing
86
internal components without relying on specific window path
87
names, which are really details of the implementation.
88
.TP
89
\fIpathName\fR \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
90
Query or modify the configuration options of the widget.
91
If no \fIoption\fR is specified, returns a list describing all of
92
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
93
information on the format of this list).  If \fIoption\fR is specified
94
with no \fIvalue\fR, then the command returns a list describing the
95
one named option (this list will be identical to the corresponding
96
sublist of the value returned if no \fIoption\fR is specified).  If
97
one or more \fIoption\-value\fR pairs are specified, then the command
98
modifies the given widget option(s) to have the given value(s);  in
99
this case the command returns an empty string.
100
.sp
101
In this case, the \fIoptions\fR refer to composite configuration
102
options for the mega-widget.  Individual components integrate their
103
own configuration options onto the composite list when they are
104
registered by the "\fBitk_component add\fR" method.
105
 
106
.SH "PROTECTED METHODS"
107
.PP
108
The following methods are used in derived classes as part of
109
the implementation for a mega-widget.
110
.TP
111
\fBitk_component add\fR ?\fB-protected\fR? ?\fB-private\fR? ?\fB--\fR? \fIname createCmds\fR ?\fIoptionCmds\fR?
112
Creates a component widget by executing the \fIcreateCmds\fR
113
argument and registers the new component with the symbolic
114
name \fIname\fR.  The \fB-protected\fR and \fB-private\fR options
115
can be used to keep the component hidden from the outside world.
116
These options have a similar effect on component visibility as
117
they have on class members.
118
.sp
119
The \fIcreateCmds\fR code can contain any
120
number of commands, but it must return the window path name
121
for the new component widget.
122
.sp
123
The \fIoptionCmds\fR script contains commands that describe
124
how the configuration options for the new component should
125
be integrated into the composite list for the mega-widget.
126
It can contain any of the following commands:
127
.RS
128
.TP
129
\fBignore \fIoption\fR ?\fIoption option ...\fR?
130
Removes one or more configuration \fIoptions\fR from the
131
composite list.  All options are ignored by default,
132
so the \fBignore\fR command is only used to negate the
133
effect of a previous \fBkeep\fR or \fBrename\fR command.
134
This is useful, for example, when the some of the options
135
added by the \fBusual\fR command should not apply to
136
a particular component, and need to be ignored.
137
.TP
138
\fBkeep \fIoption\fR ?\fIoption option ...\fR?
139
Integrates one or more configuration \fIoptions\fR into the
140
composite list, keeping the name the same.  Whenever the
141
mega-widget option is configured, the new value is also
142
applied to the current component.  Options like "-background"
143
and "-cursor" are commonly found on the \fBkeep\fR list.
144
.TP
145
\fBrename \fIoption switchName resourceName resourceClass\fR
146
Integrates the configuration \fIoption\fR into the composite
147
list with a different name.  The option will be called
148
\fIswitchName\fR on the composite list.  It will also be
149
modified by setting values for \fIresourceName\fR and \fIresourceClass\fR
150
in the X11 resource database.  The "-highlightbackground"
151
option is commonly renamed to "-background", so that when
152
the mega-widget background changes, the background of the
153
focus ring will change as well.
154
.TP
155
\fBusual ?\fItag\fR?
156
Finds the usual option-handling commands for the specified
157
\fItag\fR name and executes them.  If the \fItag\fR is
158
not specified, then the widget class name is used as the
159
\fItag\fR name.  The "usual" option-handling commands
160
are registered via the \fBusual\fR command.
161
.RE
162
.sp
163
If the \fIoptionCmds\fR script is not specified, the usual
164
option-handling commands associated with the class of the
165
component widget are used by default.
166
 
167
.TP
168
\fBitk_component delete\fR \fIname\fR ?\fIname name ...\fR?
169
Removes the component widget with the symbolic name \fIname\fR
170
from the mega-widget.  The component widget will still exist,
171
but it will no longer be accessible as a component of the
172
mega-widget.  Also, any options associated with the component
173
are removed from the composite option list.
174
.sp
175
Note that you can destroy a component using the \fBdestroy\fR
176
command, just as you would destroy any Tk widget.  Components
177
automatically detach themselves from their mega-widget parent
178
when destroyed, so "\fBitk_component delete\fR" is rarely used.
179
 
180
.TP
181
\fBitk_initialize ?\fIoption value option value...\fR?
182
\fIThis method must be invoked within the constructor for
183
each class in a mega-widget hierarchy.\fR  It makes sure
184
that all options are properly integrated into the composite
185
option list, and synchronizes all components to the initial
186
option values.  It is usually invoked near the bottom of
187
the constructor, after all component widgets have been
188
added.
189
.sp
190
If any \fIoption\fR/\fIvalue\fR pairs are specified, they
191
override settings determined from the X11 resource database.
192
The arguments to the constructor are usually passed along
193
to this method as follows:
194
.CS
195
class MyWidget {
196
    inherit Widget
197
 
198
    constructor {args} {
199
        .
200
        .
201
        .
202
        eval itk_initialize $args
203
    }
204
}
205
.CE
206
 
207
.TP
208
\fBitk_option add\fR \fIoptName\fR ?\fIoptName optName ...\fR?
209
Adds one or more options to the composite option list for
210
a mega-widget.  Here, \fIoptName\fR can have one of the
211
following forms:
212
.RS
213
.TP
214
\fIcomponent\fR.\fIoption\fR
215
Accesses an \fIoption\fR belonging to a component with the
216
symbolic name \fIcomponent\fR.  The \fIoption\fR name is
217
specified without a leading "\fB-\fR" sign.
218
.TP
219
\fIclassName\fR::\fIoption\fR
220
Accesses an \fIoption\fR defined by the "\fBitk_option define\fR"
221
command in class \fIclassName\fR.  The \fIoption\fR name is
222
specified without a leading "\fB-\fR" sign.
223
.RE
224
.PP
225
Options are normally integrated into the composite option list
226
when a component widget is first created.  This method can be
227
used to add options at a later time.  For example, the \fBWidget\fR
228
and \fBToplevel\fR base classes keep only the bare minimum options
229
for their "hull" component:  -background and -cursor.  A derived
230
class can override this decision, and add options that control
231
the border of the "hull" component as well:
232
.CS
233
class MyWidget {
234
    inherit Widget
235
 
236
    constructor {args} {
237
        itk_option add hull.borderwidth hull.relief
238
 
239
        itk_component add label {
240
            label $itk_interior.l1 -text "Hello World!"
241
        }
242
        pack $itk_component(label)
243
 
244
        eval itk_initialize $args
245
    }
246
}
247
.CE
248
 
249
.TP
250
\fBitk_option define\fR \fIswitchName resourceName resourceClass init\fR ?\fIconfig\fR?
251
This command is used at the level of the class definition to
252
define a synthetic mega-widget option.  Within the \fBconfigure\fR
253
and \fBcget\fR methods, this option is referenced by \fIswitchName\fR,
254
which must start with a "\fB-\fR" sign.  It can also be
255
modified by setting values for \fIresourceName\fR and \fIresourceClass\fR
256
in the X11 resource database.  The \fIinit\fR value string is used
257
as a last resort to initialize the option if no other value can
258
be used from an existing option, or queried from the X11 resource
259
database.  If any \fIconfig\fR code is specified, it is executed
260
whenever the option is modified via the \fBconfigure\fR method.
261
The \fIconfig\fR code can also be specified outside of the class
262
definition via the \fBconfigbody\fR command.
263
.sp
264
In the following example, a synthetic "-background" option is
265
added to the class, so that whenever the background changes, the
266
new value is reported to standard output.  Note that this synthetic
267
option is integrated with the rest of the "-background" options
268
that have been kept from component widgets:
269
.CS
270
class MyWidget {
271
    inherit Widget
272
    constructor {args} {
273
        itk_component add label {
274
            label $itk_interior.l1 -text "Hello World!"
275
        }
276
        pack $itk_component(label)
277
 
278
        eval itk_initialize $args
279
    }
280
    itk_option define -background background Background #d9d9d9 {
281
        puts "new background: $itk_option(-background)"
282
    }
283
}
284
.CE
285
 
286
.TP
287
\fBitk_option remove\fR \fIoptName\fR ?\fIoptName optName ...\fR?
288
Removes one or more options from the composite option list for
289
a mega-widget.  Here, \fIoptName\fR can have one of the forms
290
described above for the "\fBitk_option add\fR" command.
291
.sp
292
Options are normally integrated into the composite option list
293
when a component widget is first created.  This method can be
294
used to remove options at a later time.  For example, a derived
295
class can override an option defined in a base class by removing
296
and redefining the option:
297
.CS
298
class Base {
299
    inherit Widget
300
    constructor {args} {
301
        eval itk_initialize $args
302
    }
303
 
304
    itk_option define -foo foo Foo "" {
305
        puts "Base: $itk_option(-foo)"
306
    }
307
}
308
 
309
class Derived {
310
    inherit Base
311
 
312
    constructor {args} {
313
        itk_option remove Base::foo
314
        eval itk_initialize $args
315
    }
316
    itk_option define -foo foo Foo "" {
317
        puts "Derived: $itk_option(-foo)"
318
    }
319
}
320
.CE
321
Without the "\fBitk_option remove\fR" command, the code fragments
322
for both of the "-foo" options would be executed each time the
323
composite "-foo" option is configured.  In the example above,
324
the \fCBase::foo\fR option is suppressed in all Derived class
325
widgets, so only the \fCDerived::foo\fR option remains.
326
 
327
.SH "PROTECTED VARIABLES"
328
Derived classes can find useful information in the following
329
protected variables.
330
.TP
331
itk_component(\fIname\fR)
332
The "itk_component" array returns the real window path name
333
for a component widget with the symbolic name \fIname\fR.
334
The same information can be queried using the \fBcomponent\fR
335
method, but accessing this array is faster and more convenient.
336
.TP
337
itk_interior
338
This variable contains the name of the window that acts as
339
a parent for internal components.  It is initialized to the
340
name of the "hull" component provided by the \fBWidget\fR
341
and \fBToplevel\fR classes.  Derived classes can override
342
the initial setting to point to another interior window
343
to be used for further-derived classes.
344
.TP
345
itk_option(\fIoption\fR)
346
The "itk_option" array returns the current option value
347
for the composite widget option named \fIoption\fR.  Here,
348
the \fIoption\fR name should include a leading "\fB-\fR" sign.
349
The same information can be queried using the \fBcget\fR
350
method, but accessing this array is faster and more convenient.
351
 
352
.SH KEYWORDS
353
itk, Widget, Toplevel, mega-widget

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.