]>
git.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 *--------------------------------------------------------------
56 Tk_GetAnchor(interp
, string
, anchorPtr
)
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
65 *anchorPtr
= TK_ANCHOR_N
;
67 } else if ((string
[1] == 'e') && (string
[2] == 0)) {
68 *anchorPtr
= TK_ANCHOR_NE
;
70 } else if ((string
[1] == 'w') && (string
[2] == 0)) {
71 *anchorPtr
= TK_ANCHOR_NW
;
77 *anchorPtr
= TK_ANCHOR_S
;
79 } else if ((string
[1] == 'e') && (string
[2] == 0)) {
80 *anchorPtr
= TK_ANCHOR_SE
;
82 } else if ((string
[1] == 'w') && (string
[2] == 0)) {
83 *anchorPtr
= TK_ANCHOR_SW
;
90 *anchorPtr
= TK_ANCHOR_E
;
96 *anchorPtr
= TK_ANCHOR_W
;
101 if (strncmp(string
, "center", strlen(string
)) == 0) {
102 *anchorPtr
= TK_ANCHOR_CENTER
;
109 Tcl_AppendResult(interp
, "bad anchor position \"", string
,
110 "\": must be n, ne, e, se, s, sw, w, nw, or center",
116 *--------------------------------------------------------------
120 * Given a Tk_Anchor, return the string that corresponds
129 *--------------------------------------------------------------
133 Tk_NameOfAnchor(anchor
)
134 Tk_Anchor anchor
; /* Anchor for which identifying string
138 case TK_ANCHOR_N
: return "n";
139 case TK_ANCHOR_NE
: return "ne";
140 case TK_ANCHOR_E
: return "e";
141 case TK_ANCHOR_SE
: return "se";
142 case TK_ANCHOR_S
: return "s";
143 case TK_ANCHOR_SW
: return "sw";
144 case TK_ANCHOR_W
: return "w";
145 case TK_ANCHOR_NW
: return "nw";
146 case TK_ANCHOR_CENTER
: return "center";
148 return "unknown anchor position";
152 *--------------------------------------------------------------
156 * Given a string, return the corresponding Tk_JoinStyle.
159 * The return value is a standard Tcl return result. If
160 * TCL_OK is returned, then everything went well and the
161 * justification is stored at *joinPtr; otherwise
162 * TCL_ERROR is returned and an error message is left in
168 *--------------------------------------------------------------
172 Tk_GetJoinStyle(interp
, string
, joinPtr
)
173 Tcl_Interp
*interp
; /* Use this for error reporting. */
174 char *string
; /* String describing a justification style. */
175 int *joinPtr
; /* Where to store join style corresponding
181 length
= strlen(string
);
183 if ((c
== 'b') && (strncmp(string
, "bevel", length
) == 0)) {
184 *joinPtr
= JoinBevel
;
187 if ((c
== 'm') && (strncmp(string
, "miter", length
) == 0)) {
188 *joinPtr
= JoinMiter
;
191 if ((c
== 'r') && (strncmp(string
, "round", length
) == 0)) {
192 *joinPtr
= JoinRound
;
196 Tcl_AppendResult(interp
, "bad join style \"", string
,
197 "\": must be bevel, miter, or round",
203 *--------------------------------------------------------------
205 * Tk_NameOfJoinStyle --
207 * Given a Tk_JoinStyle, return the string that corresponds
216 *--------------------------------------------------------------
220 Tk_NameOfJoinStyle(join
)
221 int join
; /* Join style for which identifying string
225 case JoinBevel
: return "bevel";
226 case JoinMiter
: return "miter";
227 case JoinRound
: return "round";
229 return "unknown join style";
233 *--------------------------------------------------------------
237 * Given a string, return the corresponding Tk_CapStyle.
240 * The return value is a standard Tcl return result. If
241 * TCL_OK is returned, then everything went well and the
242 * justification is stored at *capPtr; otherwise
243 * TCL_ERROR is returned and an error message is left in
249 *--------------------------------------------------------------
253 Tk_GetCapStyle(interp
, string
, capPtr
)
254 Tcl_Interp
*interp
; /* Use this for error reporting. */
255 char *string
; /* String describing a justification style. */
256 int *capPtr
; /* Where to store cap style corresponding
262 length
= strlen(string
);
264 if ((c
== 'b') && (strncmp(string
, "butt", length
) == 0)) {
268 if ((c
== 'p') && (strncmp(string
, "projecting", length
) == 0)) {
269 *capPtr
= CapProjecting
;
272 if ((c
== 'r') && (strncmp(string
, "round", length
) == 0)) {
277 Tcl_AppendResult(interp
, "bad cap style \"", string
,
278 "\": must be butt, projecting, or round",
284 *--------------------------------------------------------------
286 * Tk_NameOfCapStyle --
288 * Given a Tk_CapStyle, return the string that corresponds
297 *--------------------------------------------------------------
301 Tk_NameOfCapStyle(cap
)
302 int cap
; /* Cap style for which identifying string
306 case CapButt
: return "butt";
307 case CapProjecting
: return "projecting";
308 case CapRound
: return "round";
310 return "unknown cap style";
314 *--------------------------------------------------------------
318 * Given a string, return the corresponding Tk_Justify.
321 * The return value is a standard Tcl return result. If
322 * TCL_OK is returned, then everything went well and the
323 * justification is stored at *justifyPtr; otherwise
324 * TCL_ERROR is returned and an error message is left in
330 *--------------------------------------------------------------
334 Tk_GetJustify(interp
, string
, justifyPtr
)
335 Tcl_Interp
*interp
; /* Use this for error reporting. */
336 char *string
; /* String describing a justification style. */
337 Tk_Justify
*justifyPtr
; /* Where to store Tk_Justify corresponding
343 length
= strlen(string
);
345 if ((c
== 'l') && (strncmp(string
, "left", length
) == 0)) {
346 *justifyPtr
= TK_JUSTIFY_LEFT
;
349 if ((c
== 'r') && (strncmp(string
, "right", length
) == 0)) {
350 *justifyPtr
= TK_JUSTIFY_RIGHT
;
353 if ((c
== 'c') && (strncmp(string
, "center", length
) == 0)) {
354 *justifyPtr
= TK_JUSTIFY_CENTER
;
357 if ((c
== 'f') && (strncmp(string
, "fill", length
) == 0)) {
358 *justifyPtr
= TK_JUSTIFY_FILL
;
362 Tcl_AppendResult(interp
, "bad justification \"", string
,
363 "\": must be left, right, center, or fill",
369 *--------------------------------------------------------------
371 * Tk_NameOfJustify --
373 * Given a Tk_Justify, return the string that corresponds
382 *--------------------------------------------------------------
386 Tk_NameOfJustify(justify
)
387 Tk_Justify justify
; /* Justification style for which
388 * identifying string is desired. */
391 case TK_JUSTIFY_LEFT
: return "left";
392 case TK_JUSTIFY_RIGHT
: return "right";
393 case TK_JUSTIFY_CENTER
: return "center";
394 case TK_JUSTIFY_FILL
: return "fill";
396 return "unknown justification style";
400 *----------------------------------------------------------------------
404 * Given a string, this procedure returns a unique identifier
408 * This procedure returns a Tk_Uid corresponding to the "string"
409 * argument. The Tk_Uid has a string value identical to string
410 * (strcmp will return 0), but it's guaranteed that any other
411 * calls to this procedure with a string equal to "string" will
412 * return exactly the same result (i.e. can compare Tk_Uid
413 * *values* directly, without having to call strcmp on what they
417 * New information may be entered into the identifier table.
419 *----------------------------------------------------------------------
424 char *string
; /* String to convert. */
429 Tcl_InitHashTable(&uidTable
, TCL_STRING_KEYS
);
432 return (Tk_Uid
) Tcl_GetHashKey(&uidTable
,
433 Tcl_CreateHashEntry(&uidTable
, string
, &dummy
));
437 *--------------------------------------------------------------
441 * Given a string, returns the number of screen millimeters
442 * corresponding to that string.
445 * The return value is a standard Tcl return result. If
446 * TCL_OK is returned, then everything went well and the
447 * screen distance is stored at *doublePtr; otherwise
448 * TCL_ERROR is returned and an error message is left in
454 *--------------------------------------------------------------
458 Tk_GetScreenMM(interp
, tkwin
, string
, doublePtr
)
459 Tcl_Interp
*interp
; /* Use this for error reporting. */
460 Tk_Window tkwin
; /* Window whose screen determines conversion
461 * from centimeters and other absolute
463 char *string
; /* String describing a screen distance. */
464 double *doublePtr
; /* Place to store converted result. */
469 d
= strtod(string
, &end
);
472 Tcl_AppendResult(interp
, "bad screen distance \"", string
,
473 "\"", (char *) NULL
);
476 while ((*end
!= '\0') && isspace(*end
)) {
481 d
/= WidthOfScreen(Tk_Screen(tkwin
));
482 d
*= WidthMMOfScreen(Tk_Screen(tkwin
));
502 while ((*end
!= '\0') && isspace(*end
)) {
513 *--------------------------------------------------------------
517 * Given a string, returns the number of pixels corresponding
521 * The return value is a standard Tcl return result. If
522 * TCL_OK is returned, then everything went well and the
523 * rounded pixel distance is stored at *intPtr; otherwise
524 * TCL_ERROR is returned and an error message is left in
530 *--------------------------------------------------------------
534 Tk_GetPixels(interp
, tkwin
, string
, intPtr
)
535 Tcl_Interp
*interp
; /* Use this for error reporting. */
536 Tk_Window tkwin
; /* Window whose screen determines conversion
537 * from centimeters and other absolute
539 char *string
; /* String describing a justification style. */
540 int *intPtr
; /* Place to store converted result. */
545 d
= strtod(string
, &end
);
548 Tcl_AppendResult(interp
, "bad screen distance \"", string
,
549 "\"", (char *) NULL
);
552 while ((*end
!= '\0') && isspace(*end
)) {
559 d
*= 10*WidthOfScreen(Tk_Screen(tkwin
));
560 d
/= WidthMMOfScreen(Tk_Screen(tkwin
));
564 d
*= 25.4*WidthOfScreen(Tk_Screen(tkwin
));
565 d
/= WidthMMOfScreen(Tk_Screen(tkwin
));
569 d
*= WidthOfScreen(Tk_Screen(tkwin
));
570 d
/= WidthMMOfScreen(Tk_Screen(tkwin
));
574 d
*= (25.4/72.0)*WidthOfScreen(Tk_Screen(tkwin
));
575 d
/= WidthMMOfScreen(Tk_Screen(tkwin
));
581 while ((*end
!= '\0') && isspace(*end
)) {
588 *intPtr
= (int) (d
- 0.5);
590 *intPtr
= (int) (d
+ 0.5);