home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tk3.3b1 / doc / ConfigWidg.3 < prev    next >
Encoding:
Text File  |  1993-04-30  |  28.2 KB  |  653 lines

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