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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tk/] [doc/] [ConfigWidg.3] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1990-1994 The Regents of the University of California.
3
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4
'\"
5
'\" See the file "license.terms" for information on usage and redistribution
6
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7
'\"
8
'\" RCS: @(#) $Id: ConfigWidg.3,v 1.1.1.1 2002-01-16 10:25:48 markom Exp $
9
'\"
10
.so man.macros
11
.TH Tk_ConfigureWidget 3 4.1 Tk "Tk Library Procedures"
12
.BS
13
.SH NAME
14
Tk_ConfigureWidget, Tk_Offset, Tk_ConfigureInfo, Tk_ConfigureValue, Tk_FreeOptions \- process configuration options for widgets
15
.SH SYNOPSIS
16
.nf
17
\fB#include \fR
18
.sp
19
int
20
\fBTk_ConfigureWidget(\fIinterp, tkwin, specs, argc, argv, widgRec, flags\fB)\fR
21
.sp
22
int
23
\fBTk_Offset(\fItype, field\fB)\fR
24
.sp
25
int
26
\fBTk_ConfigureInfo(\fIinterp, tkwin, specs, widgRec, argvName, flags\fB)\fR
27
.sp
28
int
29
.sp
30
\fBTk_FreeOptions(\fIspecs, widgRec, display, flags\fB)\fR
31
.SH ARGUMENTS
32
.AS Tk_ConfigSpec *widgRec
33
.AP Tcl_Interp *interp in
34
Interpreter to use for returning error messages.
35
.AP Tk_Window tkwin in
36
Window used to represent widget (needed to set up X resources).
37
.AP Tk_ConfigSpec *specs in
38
Pointer to table specifying legal configuration options for this
39
widget.
40
.AP int argc in
41
Number of arguments in \fIargv\fR.
42
.AP char **argv in
43
Command-line options for configuring widget.
44
.AP char *widgRec in/out
45
Points to widget record structure.  Fields in this structure get
46
modified by \fBTk_ConfigureWidget\fR to hold configuration information.
47
.AP int flags in
48
If non-zero, then it specifies an OR-ed combination of flags that
49
control the processing of configuration information.
50
TK_CONFIG_ARGV_ONLY causes the option database and defaults to be
51
ignored, and flag bits TK_CONFIG_USER_BIT and higher are used to
52
selectively disable entries in \fIspecs\fR.
53
.AP "type name" type in
54
The name of the type of a widget record.
55
.AP "field name" field in
56
The name of a field in records of type \fItype\fR.
57
.AP char *argvName in
58
The name used on Tcl command lines to refer to a particular option
59
(e.g. when creating a widget or invoking the \fBconfigure\fR widget
60
command).  If non-NULL, then information is returned only for this
61
option.  If NULL, then information is returned for all available
62
options.
63
.AP Display *display in
64
Display containing widget whose record is being freed;  needed in
65
order to free up resources.
66
.BE
67
.SH DESCRIPTION
68
.PP
69
\fBTk_ConfigureWidget\fR is called to configure various aspects of a
70
widget, such as colors, fonts, border width, etc.
71
It is intended as a convenience procedure to reduce the amount
72
of code that must be written in individual widget managers to
73
handle configuration information.
74
It is typically
75
invoked when widgets are created, and again when the \fBconfigure\fR
76
command is invoked for a widget.
77
Although intended primarily for widgets, \fBTk_ConfigureWidget\fR
78
can be used in other situations where \fIargc-argv\fR information
79
is to be used to fill in a record structure, such as configuring
80
graphical elements for a canvas widget or entries of a menu.
81
.PP
82
\fBTk_ConfigureWidget\fR processes
83
a table specifying the configuration options that are supported
84
(\fIspecs\fR) and a collection of command-line arguments (\fIargc\fR and
85
\fIargv\fR) to fill in fields of a record (\fIwidgRec\fR).
86
It uses the option database and defaults specified in \fIspecs\fR
87
to fill in fields of \fIwidgRec\fR that are not specified in \fIargv\fR.
88
\fBTk_ConfigureWidget\fR normally returns the value TCL_OK; in this
89
case it does not modify \fIinterp\fR.
90
If an error
91
occurs then TCL_ERROR is returned and \fBTk_ConfigureWidget\fR will
92
leave an error message in \fIinterp->result\fR in the standard Tcl
93
fashion.
94
In the event of an error return, some of the fields of \fIwidgRec\fR
95
could already have been set, if configuration information for them
96
was successfully processed before the error occurred.
97
The other fields will be set to reasonable initial values so that
98
\fBTk_FreeOptions\fR can be called for cleanup.
99
.PP
100
The \fIspecs\fR array specifies the kinds of configuration options
101
expected by the widget.  Each of its entries specifies one configuration
102
option and has the following structure:
103
.CS
104
typedef struct {
105
        int \fItype\fR;
106
        char *\fIargvName\fR;
107
        char *\fIdbName\fR;
108
        char *\fIdbClass\fR;
109
        char *\fIdefValue\fR;
110
        int \fIoffset\fR;
111
        int \fIspecFlags\fR;
112
        Tk_CustomOption *\fIcustomPtr\fR;
113
} Tk_ConfigSpec;
114
.CE
115
The \fItype\fR field indicates what type of configuration option this is
116
(e.g. TK_CONFIG_COLOR for a color value, or TK_CONFIG_INT for
117
an integer value).  The \fItype\fR field indicates how to use the
118
value of the option (more on this below).
119
The \fIargvName\fR field is a string such as ``\-font'' or ``\-bg'',
120
which is compared with the values in \fIargv\fR (if \fIargvName\fR is
121
NULL it means this is a grouped entry;  see GROUPED ENTRIES below).  The
122
\fIdbName\fR and \fIdbClass\fR fields are used to look up a value
123
for this option in the option database.  The \fIdefValue\fR field
124
specifies a default value for this configuration option if no
125
value is specified in either \fIargv\fR or the option database.
126
\fIOffset\fR indicates where in \fIwidgRec\fR to store information
127
about this option, and \fIspecFlags\fR contains additional information
128
to control the processing of this configuration option (see FLAGS
129
below).
130
The last field, \fIcustomPtr\fR, is only used if \fItype\fR is
131
TK_CONFIG_CUSTOM;  see CUSTOM OPTION TYPES below.
132
.PP
133
\fBTk_ConfigureWidget\fR first processes \fIargv\fR to see which
134
(if any) configuration options are specified there.  \fIArgv\fR
135
must contain an even number of fields;  the first of each pair
136
of fields must match the \fIargvName\fR of some entry in \fIspecs\fR
137
(unique abbreviations are acceptable),
138
and the second field of the pair contains the value for that
139
configuration option.  If there are entries in \fIspec\fR for which
140
there were no matching entries in \fIargv\fR,
141
\fBTk_ConfigureWidget\fR uses the \fIdbName\fR and \fIdbClass\fR
142
fields of the \fIspecs\fR entry to probe the option database;  if
143
a value is found, then it is used as the value for the option.
144
Finally, if no entry is found in the option database, the
145
\fIdefValue\fR field of the \fIspecs\fR entry is used as the
146
value for the configuration option.  If the \fIdefValue\fR is
147
NULL, or if the TK_CONFIG_DONT_SET_DEFAULT bit is set in
148
\fIflags\fR, then there is no default value and this \fIspecs\fR entry
149
will be ignored if no value is specified in \fIargv\fR or the
150
option database.
151
.PP
152
Once a string value has been determined for a configuration option,
153
\fBTk_ConfigureWidget\fR translates the string value into a more useful
154
form, such as a color if \fItype\fR is TK_CONFIG_COLOR or an integer
155
if \fItype\fR is TK_CONFIG_INT.  This value is then stored in the
156
record pointed to by \fIwidgRec\fR.  This record is assumed to
157
contain information relevant to the manager of the widget;  its exact
158
type is unknown to \fBTk_ConfigureWidget\fR.  The \fIoffset\fR field
159
of each \fIspecs\fR entry indicates where in \fIwidgRec\fR to store
160
the information about this configuration option.  You should use the
161
\fBTk_Offset\fR macro to generate \fIoffset\fR values (see below for
162
a description of \fBTk_Offset\fR).  The location indicated by
163
\fIwidgRec\fR and \fIoffset\fR will be referred to as the ``target''
164
in the descriptions below.
165
.PP
166
The \fItype\fR field of each entry in \fIspecs\fR determines what
167
to do with the string value of that configuration option.  The
168
legal values for \fItype\fR, and the corresponding actions, are:
169
.TP
170
\fBTK_CONFIG_ACTIVE_CURSOR\fR
171
The value
172
must be an ASCII string identifying a cursor in a form
173
suitable for passing to \fBTk_GetCursor\fR.
174
The value is converted to a \fBTk_Cursor\fR by calling
175
\fBTk_GetCursor\fR and the result is stored in the target.
176
In addition, the resulting cursor is made the active cursor
177
for \fItkwin\fR by calling \fBXDefineCursor\fR.
178
If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
179
may be an empty string, in which case the target and \fItkwin\fR's
180
active cursor will be set to \fBNone\fR.
181
If the previous value of the target
182
wasn't \fBNone\fR, then it is freed by passing it to \fBTk_FreeCursor\fR.
183
.TP
184
\fBTK_CONFIG_ANCHOR\fR
185
The value must be an ASCII string identifying an anchor point in one of the ways
186
accepted by \fBTk_GetAnchor\fR.
187
The string is converted to a \fBTk_Anchor\fR by calling
188
\fBTk_GetAnchor\fR and the result is stored in the target.
189
.TP
190
\fBTK_CONFIG_BITMAP\fR
191
The value must be an ASCII string identifying a bitmap in a form
192
suitable for passing to \fBTk_GetBitmap\fR.  The value is converted
193
to a \fBPixmap\fR by calling \fBTk_GetBitmap\fR and the result
194
is stored in the target.
195
If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
196
may be an empty string, in which case the target is set to \fBNone\fR.
197
If the previous value of the target
198
wasn't \fBNone\fR, then it is freed by passing it to \fBTk_FreeBitmap\fR.
199
.TP
200
\fBTK_CONFIG_BOOLEAN\fR
201
The value must be an ASCII string specifying a boolean value.  Any
202
of the values ``true'', ``yes'', ``on'', or ``1'',
203
or an abbreviation of one of these values, means true;
204
any of the values ``false'', ``no'', ``off'', or ``0'', or an abbreviation of
205
one of these values, means false.
206
The target is expected to be an integer;  for true values it will
207
be set to 1 and for false values it will be set to 0.
208
.TP
209
\fBTK_CONFIG_BORDER\fR
210
The value must be an ASCII string identifying a border color in a form
211
suitable for passing to \fBTk_Get3DBorder\fR.  The value is converted
212
to a (\fBTk_3DBorder *\fR) by calling \fBTk_Get3DBorder\fR and the result
213
is stored in the target.
214
If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
215
may be an empty string, in which case the target will be set to NULL.
216
If the previous value of the target
217
wasn't NULL, then it is freed by passing it to \fBTk_Free3DBorder\fR.
218
.TP
219
\fBTK_CONFIG_CAP_STYLE\fR
220
The value must be
221
an ASCII string identifying a cap style in one of the ways
222
accepted by \fBTk_GetCapStyle\fR.
223
The string is converted to an integer value corresponding
224
to the cap style by calling
225
\fBTk_GetCapStyle\fR and the result is stored in the target.
226
.TP
227
\fBTK_CONFIG_COLOR\fR
228
The value must be an ASCII string identifying a color in a form
229
suitable for passing to \fBTk_GetColor\fR.  The value is converted
230
to an (\fBXColor *\fR) by calling \fBTk_GetColor\fR and the result
231
is stored in the target.
232
If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
233
may be an empty string, in which case the target will be set to \fBNone\fR.
234
If the previous value of the target
235
wasn't NULL, then it is freed by passing it to \fBTk_FreeColor\fR.
236
.TP
237
\fBTK_CONFIG_CURSOR\fR
238
This option is identical to \fBTK_CONFIG_ACTIVE_CURSOR\fR except
239
that the new cursor is not made the active one for \fItkwin\fR.
240
.TP
241
\fBTK_CONFIG_CUSTOM\fR
242
This option allows applications to define new option types.
243
The \fIcustomPtr\fR field of the entry points to a structure
244
defining the new option type.
245
See the section CUSTOM OPTION TYPES below for details.
246
.TP
247
\fBTK_CONFIG_DOUBLE\fR
248
The value must be an ASCII floating-point number in
249
the format accepted by \fBstrtol\fR.  The string is converted
250
to a \fBdouble\fR value, and the value is stored in the
251
target.
252
.TP
253
\fBTK_CONFIG_END\fR
254
Marks the end of the table.  The last entry in \fIspecs\fR
255
must have this type;  all of its other fields are ignored and it
256
will never match any arguments.
257
.TP
258
\fBTK_CONFIG_FONT\fR
259
The value must be an ASCII string identifying a font in a form
260
suitable for passing to \fBTk_GetFontStruct\fR.  The value is converted
261
to an (\fBXFontStruct *\fR) by calling \fBTk_GetFontStruct\fR and the result
262
is stored in the target.
263
If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
264
may be an empty string, in which case the target will be set to NULL.
265
If the previous value of the target
266
wasn't NULL, then it is freed by passing it to \fBTk_FreeFontStruct\fR.
267
.TP
268
\fBTK_CONFIG_INT\fR
269
The value must be an ASCII integer string
270
in the format accepted by \fBstrtol\fR (e.g. ``0''
271
and ``0x'' prefixes may be used to specify octal or hexadecimal
272
numbers, respectively).  The string is converted to an integer
273
value and the integer is stored in the target.
274
.TP
275
\fBTK_CONFIG_JOIN_STYLE\fR
276
The value must be
277
an ASCII string identifying a join style in one of the ways
278
accepted by \fBTk_GetJoinStyle\fR.
279
The string is converted to an integer value corresponding
280
to the join style by calling
281
\fBTk_GetJoinStyle\fR and the result is stored in the target.
282
.TP
283
\fBTK_CONFIG_JUSTIFY\fR
284
The value must be
285
an ASCII string identifying a justification method in one of the
286
ways accepted by \fBTk_GetJustify\fR.
287
The string is converted to a \fBTk_Justify\fR by calling
288
\fBTk_GetJustify\fR and the result is stored in the target.
289
.TP
290
\fBTK_CONFIG_MM\fR
291
The value must specify a screen distance in one of the forms acceptable
292
to \fBTk_GetScreenMM\fR.
293
The string is converted to double-precision floating-point distance
294
in millimeters and the value is stored in the target.
295
.TP
296
\fBTK_CONFIG_PIXELS\fR
297
The value must specify screen units in one of the forms acceptable
298
to \fBTk_GetPixels\fR.
299
The string is converted to an integer distance in pixels and the
300
value is stored in the target.
301
.TP
302
\fBTK_CONFIG_RELIEF\fR
303
The value must be an ASCII string identifying a relief in a form
304
suitable for passing to \fBTk_GetRelief\fR.  The value is converted
305
to an integer relief value by calling \fBTk_GetRelief\fR and the result
306
is stored in the target.
307
.TP
308
\fBTK_CONFIG_STRING\fR
309
A copy
310
of the value is made by allocating memory space with
311
\fBmalloc\fR and copying the value into the dynamically-allocated
312
space.  A pointer to the new string is stored in the target.
313
If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
314
may be an empty string, in which case the target will be set to NULL.
315
If the previous value of the target wasn't NULL, then it is
316
freed by passing it to \fBfree\fR.
317
.TP
318
\fBTK_CONFIG_SYNONYM\fR
319
This \fItype\fR value identifies special entries in \fIspecs\fR that
320
are synonyms for other entries.  If an \fIargv\fR value matches the
321
\fIargvName\fR of a TK_CONFIG_SYNONYM entry, the entry isn't used
322
directly. Instead, \fBTk_ConfigureWidget\fR searches \fIspecs\fR
323
for another entry whose \fIargvName\fR is the same as the \fIdbName\fR
324
field in the TK_CONFIG_SYNONYM entry;  this new entry is used just
325
as if its \fIargvName\fR had matched the \fIargv\fR value.  The
326
synonym mechanism allows multiple \fIargv\fR values to be used for
327
a single configuration option, such as ``\-background'' and ``\-bg''.
328
.TP
329
\fBTK_CONFIG_UID\fR
330
The value is translated to a \fBTk_Uid\fR
331
(by passing it to \fBTk_GetUid\fR).  The resulting value
332
is stored in the target.
333
If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR and the value
334
is an empty string then the target will be set to NULL.
335
.TP
336
\fBTK_CONFIG_WINDOW\fR
337
The value must be a window path name.  It is translated to a
338
\fBTk_Window\fR token and the token is stored in the target.
339
 
340
.SH "GROUPED ENTRIES"
341
.PP
342
In some cases it is useful to generate multiple resources from
343
a single configuration value.  For example, a color name might
344
be used both to generate the background color for a widget (using
345
TK_CONFIG_COLOR) and to generate a 3-D border to draw around the
346
widget (using TK_CONFIG_BORDER).  In cases like this it is possible
347
to specify that several consecutive entries in \fIspecs\fR are to
348
be treated as a group.  The first entry is used to determine a value
349
(using its \fIargvName\fR, \fIdbName\fR,
350
\fIdbClass\fR, and \fIdefValue\fR fields).  The value will be processed
351
several times (one for each entry in the group), generating multiple
352
different resources and modifying multiple targets within \fIwidgRec\fR.
353
Each of the entries after the first must have a NULL value in its
354
\fIargvName\fR field;  this indicates that the entry is to be grouped
355
with the entry that precedes it.  Only the \fItype\fR and \fIoffset\fR
356
fields are used from these follow-on entries.
357
 
358
.SH "FLAGS"
359
.PP
360
The \fIflags\fR argument passed to \fBTk_ConfigureWidget\fR is used
361
in conjunction with the \fIspecFlags\fR fields in the entries of \fIspecs\fR
362
to provide additional control over the processing of configuration
363
options.  These values are used in three different ways as
364
described below.
365
.PP
366
First, if the \fIflags\fR argument to \fBTk_ConfigureWidget\fR has
367
the TK_CONFIG_ARGV_ONLY bit set (i.e., \fIflags\fR | TK_CONFIG_ARGV_ONLY != 0),
368
then the option database and
369
\fIdefValue\fR fields are not used.  In this case, if an entry in
370
\fIspecs\fR doesn't match a field in \fIargv\fR then nothing happens:
371
the corresponding target isn't modified.  This feature is useful
372
when the goal is to modify certain configuration options while
373
leaving others in their current state, such as when a \fBconfigure\fR
374
widget command is being processed.
375
.PP
376
Second, the \fIspecFlags\fR field of an entry in \fIspecs\fR may be used
377
to control the processing of that entry.  Each \fIspecFlags\fR
378
field may consists of an OR-ed combination of the following values:
379
.TP
380
\fBTK_CONFIG_COLOR_ONLY\fR
381
If this bit is set then the entry will only be considered if the
382
display for \fItkwin\fR has more than one bit plane.  If the display
383
is monochromatic then this \fIspecs\fR entry will be ignored.
384
.TP
385
\fBTK_CONFIG_MONO_ONLY\fR
386
If this bit is set then the entry will only be considered if the
387
display for \fItkwin\fR has exactly one bit plane.  If the display
388
is not monochromatic then this \fIspecs\fR entry will be ignored.
389
.TP
390
\fBTK_CONFIG_NULL_OK\fR
391
This bit is only relevant for some types of entries (see the
392
descriptions of the various entry types above).
393
If this bit is set, it indicates that an empty string value
394
for the field is acceptable and if it occurs then the
395
target should be set to NULL or \fBNone\fR, depending
396
on the type of the target.
397
This flag is typically used to allow a
398
feature to be turned off entirely, e.g. set a cursor value to
399
\fBNone\fR so that a window simply inherits its parent's cursor.
400
If this bit isn't set then empty strings are processed as strings,
401
which generally results in an error.
402
.TP
403
\fBTK_CONFIG_DONT_SET_DEFAULT\fR
404
If this bit is one, it means that the \fIdefValue\fR field of the
405
entry should only be used for returning the default value in
406
\fBTk_ConfigureInfo\fR.
407
In calls to \fBTk_ConfigureWidget\fR no default will be supplied
408
for entries with this flag set;  it is assumed that the
409
caller has already supplied a default value in the target location.
410
This flag provides a performance optimization where it is expensive
411
to process the default string:  the client can compute the default
412
once, save the value, and provide it before calling
413
\fBTk_ConfigureWidget\fR.
414
.TP
415
\fBTK_CONFIG_OPTION_SPECIFIED\fR
416
This bit is set and cleared by \fBTk_ConfigureWidget\fR.  Whenever
417
\fBTk_ConfigureWidget\fR returns, this bit will be set in all the
418
entries where a value was specified in \fIargv\fR.
419
It will be zero in all other entries.
420
This bit provides a way for clients to determine which values
421
actually changed in a call to \fBTk_ConfigureWidget\fR.
422
.PP
423
The TK_CONFIG_MONO_ONLY and TK_CONFIG_COLOR_ONLY flags are typically
424
used to specify different default values for
425
monochrome and color displays.  This is done by creating two
426
entries in \fIspecs\fR that are identical except for their
427
\fIdefValue\fR and \fIspecFlags\fR fields.  One entry should have
428
the value TK_CONFIG_MONO_ONLY in its \fIspecFlags\fR and the
429
default value for monochrome displays in its \fIdefValue\fR;  the
430
other entry entry should have the value TK_CONFIG_COLOR_ONLY in
431
its \fIspecFlags\fR and the appropriate \fIdefValue\fR for
432
color displays.
433
.PP
434
Third, it is possible to use \fIflags\fR and \fIspecFlags\fR
435
together to selectively disable some entries.  This feature is
436
not needed very often.  It is useful in cases where several
437
similar kinds of widgets are implemented in one place.  It allows
438
a single \fIspecs\fR table to be created with all the configuration
439
options for all the widget types.  When processing a particular
440
widget type, only entries relevant to that type will be used.  This
441
effect is achieved by setting the high-order bits (those in positions
442
equal to or greater than TK_CONFIG_USER_BIT) in \fIspecFlags\fR
443
values or in \fIflags\fR.  In order for a particular entry in
444
\fIspecs\fR to be used, its high-order bits must match exactly
445
the high-order bits of the \fIflags\fR value passed to
446
\fBTk_ConfigureWidget\fR.  If a \fIspecs\fR table is being used
447
for N different widget types, then N of the high-order bits will
448
be used.  Each \fIspecs\fR entry will have one of more of those
449
bits set in its \fIspecFlags\fR field to indicate the widget types
450
for which this entry is valid.  When calling \fBTk_ConfigureWidget\fR,
451
\fIflags\fR will have a single one of these bits set to select the
452
entries for the desired widget type.  For a working example of
453
this feature, see the code in tkButton.c.
454
 
455
.SH TK_OFFSET
456
.PP
457
The \fBTk_Offset\fR macro is provided as a safe way of generating
458
the \fIoffset\fR values for entries in Tk_ConfigSpec structures.
459
It takes two arguments:  the name of a type of record, and the
460
name of a field in that record.  It returns the byte offset of
461
the named field in records of the given type.
462
 
463
.SH TK_CONFIGUREINFO
464
.PP
465
The \fBTk_ConfigureInfo\fR procedure may be used to obtain
466
information about one or all of the options for a given widget.
467
Given a token for a window (\fItkwin\fR), a table describing the
468
configuration options for a class of widgets (\fIspecs\fR), a
469
pointer to a widget record containing the current information for
470
a widget (\fIwidgRec\fR), and a NULL \fIargvName\fR argument,
471
\fBTk_ConfigureInfo\fR generates a string describing all of the
472
configuration options for the window.  The string is placed
473
in \fIinterp->result\fR.  Under normal circumstances
474
it returns TCL_OK;  if an error occurs then it returns TCL_ERROR
475
and \fIinterp->result\fR contains an error message.
476
.PP
477
If \fIargvName\fR is NULL, then the value left in
478
\fIinterp->result\fR by \fBTk_ConfigureInfo\fR
479
consists of a list of one or more entries, each of which describes
480
one configuration option (i.e. one entry in \fIspecs\fR).  Each
481
entry in the list will contain either two or five values.  If the
482
corresponding entry in \fIspecs\fR has type TK_CONFIG_SYNONYM, then
483
the list will contain two values:  the \fIargvName\fR for the entry
484
and the \fIdbName\fR (synonym name).  Otherwise the list will contain
485
five values:  \fIargvName\fR, \fIdbName\fR, \fIdbClass\fR, \fIdefValue\fR,
486
and current value.  The current value is computed from the appropriate
487
field of \fIwidgRec\fR by calling procedures like \fBTk_NameOfColor\fR.
488
.PP
489
If the \fIargvName\fR argument to \fBTk_ConfigureInfo\fR is non-NULL,
490
then it indicates a single option, and information is returned only
491
for that option.  The string placed in \fIinterp->result\fR will be
492
a list containing two or five values as described above;  this will
493
be identical to the corresponding sublist that would have been returned
494
if \fIargvName\fR had been NULL.
495
.PP
496
The \fIflags\fR argument to \fBTk_ConfigureInfo\fR is used to restrict
497
the \fIspecs\fR entries to consider, just as for \fBTk_ConfigureWidget\fR.
498
 
499
.SH TK_CONFIGUREVALUE
500
.PP
501
\fBTk_ConfigureValue\fR takes arguments similar to \fBTk_ConfigureInfo\fR;
502
instead of returning a list of values, it just returns the current value
503
of the option given by \fIargvName\fR (\fIargvName\fR must not be NULL).
504
The value is returned in \fIinterp->result\fR and TCL_OK is
505
normally returned as the procedure's result.
506
If an error occurs in \fBTk_ConfigureValue\fR (e.g., \fIargvName\fR is
507
not a valid option name), TCL_ERROR is returned and an error message
508
is left in \fIinterp->result\fR.
509
This procedure is typically called to implement \fBcget\fR widget
510
commands.
511
 
512
.SH TK_FREEOPTIONS
513
.PP
514
The \fBTk_FreeOptions\fR procedure may be invoked during widget cleanup
515
to release all of the resources associated with configuration options.
516
It scans through \fIspecs\fR and for each entry corresponding to a
517
resource that must be explicitly freed (e.g. those with
518
type TK_CONFIG_COLOR), it frees the resource in the widget record.
519
If the field in the widget record doesn't refer to a resource (e.g.
520
it contains a null pointer) then no resource is freed for that
521
entry.
522
After freeing a resource, \fBTk_FreeOptions\fR sets the
523
corresponding field of the widget record to null.
524
 
525
.SH "CUSTOM OPTION TYPES"
526
.PP
527
Applications can extend the built-in configuration types with additional
528
configuration types by writing procedures to parse and print options
529
of the a type and creating a structure pointing to those procedures:
530
.CS
531
typedef struct Tk_CustomOption {
532
        Tk_OptionParseProc *\fIparseProc\fR;
533
        Tk_OptionPrintProc *\fIprintProc\fR;
534
        ClientData \fIclientData\fR;
535
} Tk_CustomOption;
536
 
537
typedef int Tk_OptionParseProc(
538
        ClientData \fIclientData\fR,
539
        Tcl_Interp *\fIinterp\fR,
540
        Tk_Window \fItkwin\fR,
541
        char *\fIvalue\fR,
542
        char *\fIwidgRec\fR,
543
        int \fIoffset\fR);
544
 
545
typedef char *Tk_OptionPrintProc(
546
        ClientData \fIclientData\fR,
547
        Tk_Window \fItkwin\fR,
548
        char *\fIwidgRec\fR,
549
        int \fIoffset\fR,
550
        Tcl_FreeProc **\fIfreeProcPtr\fR);
551
.CE
552
The Tk_CustomOption structure contains three fields, which are pointers
553
to the two procedures and a \fIclientData\fR value to be passed to those
554
procedures when they are invoked.  The \fIclientData\fR value typically
555
points to a structure containing information that is needed by the
556
procedures when they are parsing and printing options.
557
.PP
558
The \fIparseProc\fR procedure is invoked by
559
\fBTk_ConfigureWidget\fR to parse a string and store the resulting
560
value in the widget record.
561
The \fIclientData\fR argument is a copy of the \fIclientData\fR
562
field in the Tk_CustomOption structure.
563
The \fIinterp\fR argument points to a Tcl interpreter used for
564
error reporting.  \fITkwin\fR is a copy of the \fItkwin\fR argument
565
to \fBTk_ConfigureWidget\fR.  The \fIvalue\fR argument is a string
566
describing the value for the option;  it could have been specified
567
explicitly in the call to \fBTk_ConfigureWidget\fR or it could
568
come from the option database or a default.
569
\fIValue\fR will never be a null pointer but it may point to
570
an empty string.
571
\fIRecordPtr\fR is the same as the \fIwidgRec\fR argument to
572
\fBTk_ConfigureWidget\fR;  it points to the start of the widget
573
record to modify.
574
The last argument, \fIoffset\fR, gives the offset in bytes from the start
575
of the widget record to the location where the option value is to
576
be placed.  The procedure should translate the string to whatever
577
form is appropriate for the option and store the value in the widget
578
record.  It should normally return TCL_OK, but if an error occurs
579
in translating the string to a value then it should return TCL_ERROR
580
and store an error message in \fIinterp->result\fR.
581
.PP
582
The \fIprintProc\fR procedure is called
583
by \fBTk_ConfigureInfo\fR to produce a string value describing an
584
existing option.
585
Its \fIclientData\fR, \fItkwin\fR, \fIwidgRec\fR, and \fIoffset\fR
586
arguments all have the same meaning as for Tk_OptionParseProc
587
procedures.
588
The \fIprintProc\fR procedure should examine the option whose value
589
is stored at \fIoffset\fR in \fIwidgRec\fR, produce a string describing
590
that option, and return a pointer to the string.
591
If the string is stored in dynamically-allocated memory, then
592
the procedure must set \fI*freeProcPtr\fR to the address of
593
a procedure to call to free the string's memory;  \fBTk_ConfigureInfo\fR
594
will call this procedure when it is finished with the string.
595
If the result string is stored in static memory then \fIprintProc\fR
596
need not do anything with the \fIfreeProcPtr\fR argument.
597
.PP
598
Once \fIparseProc\fR and \fIprintProc\fR have been defined and a
599
Tk_CustomOption structure has been created for them, options of this
600
new type may be manipulated with Tk_ConfigSpec entries whose \fItype\fR
601
fields are TK_CONFIG_CUSTOM and whose \fIcustomPtr\fR fields point
602
to the Tk_CustomOption structure.
603
 
604
.SH EXAMPLES
605
.PP
606
Although the explanation of \fBTk_ConfigureWidget\fR is fairly
607
complicated, its actual use is pretty straightforward.
608
The easiest way to get started is to copy the code
609
from an existing widget.
610
The library implementation of frames
611
(tkFrame.c) has a simple configuration table, and the library
612
implementation of buttons (tkButton.c) has a much more complex
613
table that uses many of the fancy \fIspecFlags\fR mechanisms.
614
 
615
.SH KEYWORDS
616
anchor, bitmap, boolean, border, cap style, color, configuration options,
617
cursor, custom, double, font, integer, join style, justify, millimeters,
618
pixels, relief, synonym, uid

powered by: WebSVN 2.1.0

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