Posted to tcl by kevin_walzer at Mon Aug 02 14:29:15 GMT 2010view raw

  1. int
  2. TkStateParseProc(clientData, interp, tkwin, value, widgRec, offset)
  3. ClientData clientData; /* some flags.*/
  4. Tcl_Interp *interp; /* Used for reporting errors. */
  5. Tk_Window tkwin; /* Window containing canvas widget. */
  6. CONST char *value; /* Value of option. */
  7. char *widgRec; /* Pointer to record for item. */
  8. int offset; /* Offset into item. */
  9. {
  10. int c;
  11. int flags = (int)clientData;
  12. size_t length;
  13.  
  14. register Tk_State *statePtr = (Tk_State *) (widgRec + offset);
  15.  
  16. if(value == NULL || *value == 0) {
  17. *statePtr = TK_STATE_NULL;
  18. return TCL_OK;
  19. }
  20.  
  21. c = value[0];
  22. length = strlen(value);
  23.  
  24. if ((c == 'n') && (strncmp(value, "normal", length) == 0)) {
  25. *statePtr = TK_STATE_NORMAL;
  26. return TCL_OK;
  27. }
  28. if ((c == 'd') && (strncmp(value, "disabled", length) == 0)) {
  29. *statePtr = TK_STATE_DISABLED;
  30. return TCL_OK;
  31. }
  32. if ((c == 'a') && (flags&1) && (strncmp(value, "active", length) == 0)) {
  33. *statePtr = TK_STATE_ACTIVE;
  34. return TCL_OK;
  35. }
  36. if ((c == 'h') && (flags&2) && (strncmp(value, "hidden", length) == 0)) {
  37. *statePtr = TK_STATE_HIDDEN;
  38. return TCL_OK;
  39. }
  40.  
  41. Tcl_AppendResult(interp, "bad ", (flags&4)?"-default" : "state",
  42. " value \"", value, "\": must be normal",
  43. (char *) NULL);
  44. if (flags&1) {
  45. Tcl_AppendResult(interp, ", active",(char *) NULL);
  46. }
  47. if (flags&2) {
  48. Tcl_AppendResult(interp, ", hidden",(char *) NULL);
  49. }
  50. if (flags&3) {
  51. Tcl_AppendResult(interp, ",",(char *) NULL);
  52. }
  53. Tcl_AppendResult(interp, " or disabled",(char *) NULL);
  54. *statePtr = TK_STATE_NORMAL;
  55. return TCL_ERROR;
  56. }