]>
cvs.zerfleddert.de Git - micropolis/blob - src/tk/tkget.c
4 * This file contains a number of "Tk_GetXXX" procedures, which
5 * parse text strings into useful forms for Tk. This file has
6 * the simpler procedures, like Tk_GetDirection and Tk_GetUid.
7 * The more complex procedures like Tk_GetColor are in separate
10 * Copyright 1991 Regents of the University of California
11 * Permission to use, copy, modify, and distribute this
12 * software and its documentation for any purpose and without
13 * fee is hereby granted, provided that the above copyright
14 * notice appear in all copies. The University of California
15 * makes no representations about the suitability of this
16 * software for any purpose. It is provided "as is" without
17 * express or implied warranty.
21 static char rcsid
[] = "$Header: /user6/ouster/wish/RCS/tkGet.c,v 1.5 92/08/10 09:02:46 ouster Exp $ SPRITE (Berkeley)";
28 * The hash table below is used to keep track of all the Tk_Uids created
32 static Tcl_HashTable uidTable
;
33 static int initialized
= 0;
36 *--------------------------------------------------------------
40 * Given a string, return the corresponding Tk_Anchor.
43 * The return value is a standard Tcl return result. If
44 * TCL_OK is returned, then everything went well and the
45 * position is stored at *anchorPtr; otherwise TCL_ERROR
46 * is returned and an error message is left in
52 *--------------------------------------------------------------
57 Tcl_Interp
*interp
, /* Use this for error reporting. */
58 char *string
, /* String describing a direction. */
59 Tk_Anchor
*anchorPtr
/* Where to store Tk_Anchor corresponding
66 *anchorPtr
= TK_ANCHOR_N
;
68 } else if ((string
[1] == 'e') && (string
[2] == 0)) {
69 *anchorPtr
= TK_ANCHOR_NE
;
71 } else if ((string
[1] == 'w') && (string
[2] == 0)) {
72 *anchorPtr
= TK_ANCHOR_NW
;
78 *anchorPtr
= TK_ANCHOR_S
;
80 } else if ((string
[1] == 'e') && (string
[2] == 0)) {
81 *anchorPtr
= TK_ANCHOR_SE
;
83 } else if ((string
[1] == 'w') && (string
[2] == 0)) {
84 *anchorPtr
= TK_ANCHOR_SW
;
91 *anchorPtr
= TK_ANCHOR_E
;
97 *anchorPtr
= TK_ANCHOR_W
;
102 if (strncmp(string
, "center", strlen(string
)) == 0) {
103 *anchorPtr
= TK_ANCHOR_CENTER
;
110 Tcl_AppendResult(interp
, "bad anchor position \"", string
,
111 "\": must be n, ne, e, se, s, sw, w, nw, or center",
117 *--------------------------------------------------------------
121 * Given a Tk_Anchor, return the string that corresponds
130 *--------------------------------------------------------------
135 Tk_Anchor anchor
/* Anchor for which identifying string
140 case TK_ANCHOR_N
: return "n";
141 case TK_ANCHOR_NE
: return "ne";
142 case TK_ANCHOR_E
: return "e";
143 case TK_ANCHOR_SE
: return "se";
144 case TK_ANCHOR_S
: return "s";
145 case TK_ANCHOR_SW
: return "sw";
146 case TK_ANCHOR_W
: return "w";
147 case TK_ANCHOR_NW
: return "nw";
148 case TK_ANCHOR_CENTER
: return "center";
150 return "unknown anchor position";
154 *--------------------------------------------------------------
158 * Given a string, return the corresponding Tk_JoinStyle.
161 * The return value is a standard Tcl return result. If
162 * TCL_OK is returned, then everything went well and the
163 * justification is stored at *joinPtr; otherwise
164 * TCL_ERROR is returned and an error message is left in
170 *--------------------------------------------------------------
175 Tcl_Interp
*interp
, /* Use this for error reporting. */
176 char *string
, /* String describing a justification style. */
177 int *joinPtr
/* Where to store join style corresponding
184 length
= strlen(string
);
186 if ((c
== 'b') && (strncmp(string
, "bevel", length
) == 0)) {
187 *joinPtr
= JoinBevel
;
190 if ((c
== 'm') && (strncmp(string
, "miter", length
) == 0)) {
191 *joinPtr
= JoinMiter
;
194 if ((c
== 'r') && (strncmp(string
, "round", length
) == 0)) {
195 *joinPtr
= JoinRound
;
199 Tcl_AppendResult(interp
, "bad join style \"", string
,
200 "\": must be bevel, miter, or round",
206 *--------------------------------------------------------------
208 * Tk_NameOfJoinStyle --
210 * Given a Tk_JoinStyle, return the string that corresponds
219 *--------------------------------------------------------------
224 int join
/* Join style for which identifying string
229 case JoinBevel
: return "bevel";
230 case JoinMiter
: return "miter";
231 case JoinRound
: return "round";
233 return "unknown join style";
237 *--------------------------------------------------------------
241 * Given a string, return the corresponding Tk_CapStyle.
244 * The return value is a standard Tcl return result. If
245 * TCL_OK is returned, then everything went well and the
246 * justification is stored at *capPtr; otherwise
247 * TCL_ERROR is returned and an error message is left in
253 *--------------------------------------------------------------
258 Tcl_Interp
*interp
, /* Use this for error reporting. */
259 char *string
, /* String describing a justification style. */
260 int *capPtr
/* Where to store cap style corresponding
267 length
= strlen(string
);
269 if ((c
== 'b') && (strncmp(string
, "butt", length
) == 0)) {
273 if ((c
== 'p') && (strncmp(string
, "projecting", length
) == 0)) {
274 *capPtr
= CapProjecting
;
277 if ((c
== 'r') && (strncmp(string
, "round", length
) == 0)) {
282 Tcl_AppendResult(interp
, "bad cap style \"", string
,
283 "\": must be butt, projecting, or round",
289 *--------------------------------------------------------------
291 * Tk_NameOfCapStyle --
293 * Given a Tk_CapStyle, return the string that corresponds
302 *--------------------------------------------------------------
307 int cap
/* Cap style for which identifying string
312 case CapButt
: return "butt";
313 case CapProjecting
: return "projecting";
314 case CapRound
: return "round";
316 return "unknown cap style";
320 *--------------------------------------------------------------
324 * Given a string, return the corresponding Tk_Justify.
327 * The return value is a standard Tcl return result. If
328 * TCL_OK is returned, then everything went well and the
329 * justification is stored at *justifyPtr; otherwise
330 * TCL_ERROR is returned and an error message is left in
336 *--------------------------------------------------------------
341 Tcl_Interp
*interp
, /* Use this for error reporting. */
342 char *string
, /* String describing a justification style. */
343 Tk_Justify
*justifyPtr
/* Where to store Tk_Justify corresponding
350 length
= strlen(string
);
352 if ((c
== 'l') && (strncmp(string
, "left", length
) == 0)) {
353 *justifyPtr
= TK_JUSTIFY_LEFT
;
356 if ((c
== 'r') && (strncmp(string
, "right", length
) == 0)) {
357 *justifyPtr
= TK_JUSTIFY_RIGHT
;
360 if ((c
== 'c') && (strncmp(string
, "center", length
) == 0)) {
361 *justifyPtr
= TK_JUSTIFY_CENTER
;
364 if ((c
== 'f') && (strncmp(string
, "fill", length
) == 0)) {
365 *justifyPtr
= TK_JUSTIFY_FILL
;
369 Tcl_AppendResult(interp
, "bad justification \"", string
,
370 "\": must be left, right, center, or fill",
376 *--------------------------------------------------------------
378 * Tk_NameOfJustify --
380 * Given a Tk_Justify, return the string that corresponds
389 *--------------------------------------------------------------
394 Tk_Justify justify
/* Justification style for which
395 * identifying string is desired. */
399 case TK_JUSTIFY_LEFT
: return "left";
400 case TK_JUSTIFY_RIGHT
: return "right";
401 case TK_JUSTIFY_CENTER
: return "center";
402 case TK_JUSTIFY_FILL
: return "fill";
404 return "unknown justification style";
408 *----------------------------------------------------------------------
412 * Given a string, this procedure returns a unique identifier
416 * This procedure returns a Tk_Uid corresponding to the "string"
417 * argument. The Tk_Uid has a string value identical to string
418 * (strcmp will return 0), but it's guaranteed that any other
419 * calls to this procedure with a string equal to "string" will
420 * return exactly the same result (i.e. can compare Tk_Uid
421 * *values* directly, without having to call strcmp on what they
425 * New information may be entered into the identifier table.
427 *----------------------------------------------------------------------
432 char *string
/* String to convert. */
438 Tcl_InitHashTable(&uidTable
, TCL_STRING_KEYS
);
441 return (Tk_Uid
) Tcl_GetHashKey(&uidTable
,
442 Tcl_CreateHashEntry(&uidTable
, string
, &dummy
));
446 *--------------------------------------------------------------
450 * Given a string, returns the number of screen millimeters
451 * corresponding to that string.
454 * The return value is a standard Tcl return result. If
455 * TCL_OK is returned, then everything went well and the
456 * screen distance is stored at *doublePtr; otherwise
457 * TCL_ERROR is returned and an error message is left in
463 *--------------------------------------------------------------
468 Tcl_Interp
*interp
, /* Use this for error reporting. */
469 Tk_Window tkwin
, /* Window whose screen determines conversion
470 * from centimeters and other absolute
472 char *string
, /* String describing a screen distance. */
473 double *doublePtr
/* Place to store converted result. */
479 d
= strtod(string
, &end
);
482 Tcl_AppendResult(interp
, "bad screen distance \"", string
,
483 "\"", (char *) NULL
);
486 while ((*end
!= '\0') && isspace(*end
)) {
491 d
/= WidthOfScreen(Tk_Screen(tkwin
));
492 d
*= WidthMMOfScreen(Tk_Screen(tkwin
));
512 while ((*end
!= '\0') && isspace(*end
)) {
523 *--------------------------------------------------------------
527 * Given a string, returns the number of pixels corresponding
531 * The return value is a standard Tcl return result. If
532 * TCL_OK is returned, then everything went well and the
533 * rounded pixel distance is stored at *intPtr; otherwise
534 * TCL_ERROR is returned and an error message is left in
540 *--------------------------------------------------------------
545 Tcl_Interp
*interp
, /* Use this for error reporting. */
546 Tk_Window tkwin
, /* Window whose screen determines conversion
547 * from centimeters and other absolute
549 char *string
, /* String describing a justification style. */
550 int *intPtr
/* Place to store converted result. */
556 d
= strtod(string
, &end
);
559 Tcl_AppendResult(interp
, "bad screen distance \"", string
,
560 "\"", (char *) NULL
);
563 while ((*end
!= '\0') && isspace(*end
)) {
570 d
*= 10*WidthOfScreen(Tk_Screen(tkwin
));
571 d
/= WidthMMOfScreen(Tk_Screen(tkwin
));
575 d
*= 25.4*WidthOfScreen(Tk_Screen(tkwin
));
576 d
/= WidthMMOfScreen(Tk_Screen(tkwin
));
580 d
*= WidthOfScreen(Tk_Screen(tkwin
));
581 d
/= WidthMMOfScreen(Tk_Screen(tkwin
));
585 d
*= (25.4/72.0)*WidthOfScreen(Tk_Screen(tkwin
));
586 d
/= WidthMMOfScreen(Tk_Screen(tkwin
));
592 while ((*end
!= '\0') && isspace(*end
)) {
599 *intPtr
= (int) (d
- 0.5);
601 *intPtr
= (int) (d
+ 0.5);