Debian Codegraph @

pod/pTk/ConfigWidg.pod

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