home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WWTCLKit / WWSliderCell.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  26.2 KB  |  899 lines

  1.  
  2. #import "WWSlider.h"
  3. #import "WWSliderCell.h"
  4. #import "WWTCLInterp.h"
  5. #import <dpsclient/psops.h>
  6.  
  7. #import "avoidStupidWarnings.h"
  8.  
  9. @implementation WWSliderCell
  10.  
  11.  
  12. + initialize { [WWSliderCell setVersion:5]; return self; }
  13. ////////////////////////////////////////////////////////
  14. //
  15. - init
  16. {
  17.   [super init];
  18.   controlStringSize = 32;
  19.   controlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  20.   sprintfControlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  21.   tclExpressionSize = 32;
  22.   tclExpression = (char *)NXZoneCalloc([self zone], tclExpressionSize, sizeof(char));
  23.   tclVarSize = 32;
  24.   tclVar = (char *)NXZoneCalloc([self zone], tclVarSize, sizeof(char));
  25.   tclCommandSize = 32;
  26.   tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  27.   autoSendP = YES;
  28.   interp = nil;
  29.   usingPrivateImage = NO;
  30.   color = NXConvertGrayToColor(.5);
  31.   tclCommandDirty = YES;
  32.  
  33.   return self;
  34. }
  35. //
  36. - awake
  37. {
  38.   [super awake];
  39.   usingPrivateImage = NO;
  40.   tclCommandDirty = YES;
  41.  
  42.   return self;
  43. }
  44.  
  45. - free
  46. {
  47.   if (controlString) { NXZoneFree([self zone], controlString); }
  48.   if (sprintfControlString) { NXZoneFree([self zone], sprintfControlString); }
  49.   if (tclExpression) { NXZoneFree([self zone], tclExpression); }
  50.   if (tclVar) { NXZoneFree([self zone], tclVar); }
  51.   if (tclCommand) { NXZoneFree([self zone], tclCommand); }
  52.   return [super free];
  53. }
  54.  
  55. //
  56. - awakeFromNib
  57. {
  58.   [minText setFloatValue:[self minValue]];
  59.   [maxText setFloatValue:[self maxValue]];
  60.   [valText setFloatValue:[self floatValue]];
  61.   return self;
  62. }
  63. //
  64. - setMinValue:(double)aDouble
  65. {
  66.    [minText setFloatValue:aDouble];
  67.    return [super setMinValue:aDouble];
  68. }
  69. //
  70. - setMaxValue:(double)aDouble
  71. {
  72.    [maxText setFloatValue:aDouble];
  73.    return [super setMaxValue:aDouble];
  74. }
  75.  
  76. //
  77. - setAutoSendP:(BOOL)newFlag  {  autoSendP = newFlag; return self; }
  78. - (BOOL)autoSendP { return autoSendP; }
  79.  
  80. - setStringValue:(const char *)str
  81. {
  82.   char  *theStr;
  83.  
  84.   [super setStringValue:str];
  85.  
  86.   // why am I doing this?  cause I did it in WWThumbWheel, but I don't
  87.   // remember why...
  88.   // I think maybe that if it's zero, it make the string value NULL, not "0"
  89.   [super setFloatValue:(float)atof(str)];
  90.  
  91.   theStr = (char *)[self stringValue];
  92.   [minText setStringValue:theStr];
  93.   [maxText setStringValue:theStr];
  94.   [valText setStringValue:theStr];
  95.   tclCommandDirty = YES;
  96.   return self;
  97. }
  98.  
  99. - setIntValue:(int)val
  100. {
  101.   int   theVal;
  102.  
  103.  
  104.   [super setIntValue:val];
  105.   theVal = [self intValue];
  106.   [minText setIntValue:theVal];
  107.   [maxText setIntValue:theVal];
  108.   [valText setIntValue:theVal];
  109.   tclCommandDirty = YES;
  110.   return self;
  111. }
  112.  
  113. - setFloatValue:(float)val
  114. {
  115.   float  theVal;
  116.  
  117.  
  118.   [super setFloatValue:val];
  119.   theVal = [self floatValue];
  120.   [minText setFloatValue:theVal];
  121.   [maxText setFloatValue:theVal];
  122.   [valText setFloatValue:theVal];
  123.   tclCommandDirty = YES;
  124.   return self;
  125. }
  126.  
  127. - setDoubleValue:(double)val
  128. {
  129.   double  theVal;
  130.  
  131.  
  132.   [super setDoubleValue:val];
  133.   theVal = [self doubleValue];
  134.   [minText setDoubleValue:theVal];
  135.   [maxText setDoubleValue:theVal];
  136.   [valText setDoubleValue:theVal];
  137.   tclCommandDirty = YES;
  138.   return self;
  139. }
  140.  
  141. - reinitializeControlStringAndTclVarFromZone:(NXZone *)zone
  142. {
  143.   controlString = (char *)NXZoneCalloc(zone, controlStringSize, sizeof(char));
  144.   sprintfControlString = (char *)NXZoneCalloc(zone, controlStringSize, sizeof(char));
  145.   tclExpression = (char *)NXZoneCalloc(zone, tclExpressionSize, sizeof(char));
  146.   tclVar = (char *)NXZoneCalloc(zone, tclVarSize, sizeof(char));
  147.   tclCommand = (char *)NXZoneCalloc(zone, tclCommandSize, sizeof(char));
  148.   return self;
  149. }
  150.  
  151. - copyFromZone:(NXZone *)zone
  152. {
  153.   id newCopy = [super copyFromZone:zone];
  154.  
  155.  
  156.   [newCopy reinitializeControlStringAndTclVarFromZone:zone];
  157.   [newCopy setControlString:controlString];
  158.   [newCopy setTclExpression:tclExpression];
  159.   [newCopy setTclVar:tclVar];
  160.   [newCopy setTclCommand:tclCommand];
  161.   [newCopy setColor:color];
  162.  
  163.   return newCopy;
  164. }
  165.  
  166. - setInterp:newInterp {  interp = newInterp; return self; }
  167. - interp { return interp; }
  168.  
  169. - resizeTclCommandForArgVector:(char *)argOrderVector
  170. {
  171.   BOOL    done = NO;
  172.  
  173.   // there has got to be a better, less pathological way of doing this...
  174.  
  175.   if (!done && !strcmp("d", argOrderVector))
  176.   {  while (tclCommandSize < (controlStringSize + 32))
  177.      {  if (!tclCommandSize)
  178.     {  tclCommandSize = 32;
  179.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  180.         }
  181.         else
  182.         {  tclCommandSize *= 2;
  183.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  184.         }
  185.      }
  186.      done = YES;
  187.   }
  188.   if (!done && (!strcmp("Td", argOrderVector) || !strcmp("dT", argOrderVector)))
  189.   {  while (tclCommandSize < (controlStringSize + (2 * 32)))
  190.      {  if (!tclCommandSize)
  191.     {  tclCommandSize = 32;
  192.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  193.         }
  194.         else
  195.         {  tclCommandSize *= 2;
  196.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  197.         }
  198.      }
  199.      done = YES;
  200.   }
  201.   if (!done && !strcmp("T", argOrderVector))
  202.   {  while (tclCommandSize < (controlStringSize + 32))
  203.      {  if (!tclCommandSize)
  204.     {  tclCommandSize = 32;
  205.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  206.         }
  207.         else
  208.         {  tclCommandSize *= 2;
  209.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  210.         }
  211.      }
  212.      done = YES;
  213.   }
  214.   if (!done && !strcmp("f", argOrderVector))
  215.   {  while (tclCommandSize < (controlStringSize + 32) )
  216.      {  if (!tclCommandSize)
  217.     {  tclCommandSize = 32;
  218.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  219.         }
  220.         else
  221.         {  tclCommandSize *= 2;
  222.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  223.         }
  224.      }
  225.      done = YES;
  226.   }
  227.   if (!done && (!strcmp("Tf", argOrderVector) || !strcmp("fT", argOrderVector)))
  228.   {  while (tclCommandSize < (controlStringSize + (2 * 32)))
  229.      {  if (!tclCommandSize)
  230.     {  tclCommandSize = 32;
  231.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  232.         }
  233.         else
  234.         {  tclCommandSize *= 2;
  235.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  236.         }
  237.      }
  238.      done = YES;
  239.   }
  240.   if (!done && !strcmp("fff", argOrderVector))
  241.   {  while (tclCommandSize  < (controlStringSize + (2 + (3 * 32))))
  242.      {  if (!tclCommandSize)
  243.     {  tclCommandSize = 32;
  244.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  245.         }
  246.         else
  247.         {  tclCommandSize *= 2;
  248.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  249.         }
  250.      }
  251.      done = YES;
  252.   }
  253.  
  254.   if (!done && !strcmp("RGB", argOrderVector))
  255.   {  while (tclCommandSize  < (controlStringSize + (2 + (3 * 32))))
  256.      {  if (!tclCommandSize)
  257.     {  tclCommandSize = 32;
  258.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  259.         }
  260.         else
  261.         {  tclCommandSize *= 2;
  262.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  263.         }
  264.      }
  265.      done = YES;
  266.   }
  267.   if (!done && (!strcmp("RGBf", argOrderVector) || !strcmp("fRGB", argOrderVector) || !strcmp("dRGB", argOrderVector) || !strcmp("RGBd", argOrderVector)))
  268.   {  while (tclCommandSize  < (controlStringSize + (2 + (4 * 32))))
  269.      {  if (!tclCommandSize)
  270.     {  tclCommandSize = 32;
  271.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  272.         }
  273.         else
  274.         {  tclCommandSize *= 2;
  275.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  276.         }
  277.      }
  278.      done = YES;
  279.   }
  280.  
  281.   if (!done && !strcmp("s", argOrderVector))
  282.   {  const char  *str = [self stringValue]; 
  283.      int   strLen = strlen(str);
  284.  
  285.      while (tclCommandSize < (controlStringSize + strLen))
  286.      {  if (!tclCommandSize)
  287.     {  tclCommandSize = 32;
  288.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  289.         }
  290.         else
  291.         {  tclCommandSize *= 2;
  292.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  293.         }
  294.      }
  295.      done = YES;
  296.   }
  297.   if (!done && (!strcmp("sT", argOrderVector) || !strcmp("Ts", argOrderVector)))
  298.   {  const char  *str = [self stringValue]; 
  299.      int   strLen = strlen(str);
  300.  
  301.      while (tclCommandSize < (controlStringSize + (strLen + 32)))
  302.      {  if (!tclCommandSize)
  303.     {  tclCommandSize = 32;
  304.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  305.         }
  306.         else
  307.         {  tclCommandSize *= 2;
  308.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  309.         }
  310.      }
  311.      done = YES;
  312.   }
  313.   // those were the easy ones; now for the permutations...
  314.  
  315.   return self;
  316. }
  317.  
  318.  
  319. - updateTclCommand
  320. {
  321.   char    *controlStringPtr, *sprintfControlStringPtr;
  322.   BOOL    done;
  323.   int     argOrderSize = 32;
  324.   char    *argOrderVector = (char *)NXZoneCalloc([self zone], argOrderSize, sizeof(char));
  325.   int     argOrderOffset = 0;
  326.  
  327.  
  328.   if (!controlString)
  329.   {  return nil;
  330.   }
  331.  
  332.   // we want to grovel over the controlString, 
  333.   // for right now, we really only tend to have the following patterns 
  334.   // in the controlString: 1 %f, 1 %d, 1 %s, %R, %G, %B, 1 %T
  335.   controlStringPtr = controlString;
  336.   sprintfControlStringPtr = sprintfControlString;
  337.   strcpy(sprintfControlString, controlString);
  338.   while (*controlStringPtr)
  339.   {  if (*controlStringPtr == '%')
  340.      {  sprintfControlStringPtr++;  controlStringPtr++;
  341.         if (*controlStringPtr)
  342.         {  switch (*controlStringPtr)
  343.            {  case 'd':    while (argOrderOffset >= argOrderSize)
  344.                         {  argOrderSize *= 2;
  345.                            argOrderVector = (char *)NXZoneRealloc([self zone], argOrderVector, argOrderSize);
  346.                         }
  347.                         argOrderVector[argOrderOffset++] = 'd';
  348.                         sprintfControlStringPtr++; controlStringPtr++;
  349.             break;
  350.               case 'T':    while (argOrderOffset >= argOrderSize)
  351.                         {  argOrderSize *= 2;
  352.                            argOrderVector = (char *)NXZoneRealloc([self zone], argOrderVector, argOrderSize);
  353.                         }
  354.                         argOrderVector[argOrderOffset++] = 'T';
  355.                         *sprintfControlStringPtr++ = 'd'; controlStringPtr++;
  356.             break;
  357.               case 'f':    while (argOrderOffset >= argOrderSize)
  358.                         {  argOrderSize *= 2;
  359.                            argOrderVector = (char *)NXZoneRealloc([self zone], argOrderVector, argOrderSize);
  360.                         }
  361.                         argOrderVector[argOrderOffset++] = 'f';
  362.                         sprintfControlStringPtr++; controlStringPtr++;
  363.             break;
  364.               case 's':    while (argOrderOffset >= argOrderSize)
  365.                         {  argOrderSize *= 2;
  366.                            argOrderVector = (char *)NXZoneRealloc([self zone], argOrderVector, argOrderSize);
  367.                         }
  368.                         argOrderVector[argOrderOffset++] = 's';
  369.                         sprintfControlStringPtr++; controlStringPtr++;
  370.             break;
  371.               case 'R':    while (argOrderOffset >= argOrderSize)
  372.                         {  argOrderSize *= 2;
  373.                            argOrderVector = (char *)NXZoneRealloc([self zone], argOrderVector, argOrderSize);
  374.                         }
  375.                         argOrderVector[argOrderOffset++] = 'R';
  376.                         *sprintfControlStringPtr++ = 'f'; controlStringPtr++;
  377.                         break;
  378.               case 'G':    while (argOrderOffset >= argOrderSize)
  379.                         {  argOrderSize *= 2;
  380.                            argOrderVector = (char *)NXZoneRealloc([self zone], argOrderVector, argOrderSize);
  381.                         }
  382.                         argOrderVector[argOrderOffset++] = 'G';
  383.                         *sprintfControlStringPtr++ = 'f'; controlStringPtr++;
  384.                         break;
  385.               case 'B':    while (argOrderOffset >= argOrderSize)
  386.                         {  argOrderSize *= 2;
  387.                            argOrderVector = (char *)NXZoneRealloc([self zone], argOrderVector, argOrderSize);
  388.                         }
  389.                         argOrderVector[argOrderOffset++] = 'B'; *sprintfControlStringPtr++ = 'f';
  390.                         controlStringPtr++;
  391.                         break;
  392.               case '%':    sprintfControlStringPtr++; controlStringPtr++;
  393.                         break;
  394.                default:    NXLogError("WWSliderCell: unknown specifier <%c> in controlString.\n", *controlStringPtr);
  395.                         sprintfControlStringPtr++; controlStringPtr++;
  396.             break;
  397.            }
  398.        }
  399.      }
  400.      else
  401.      {  sprintfControlStringPtr++;  controlStringPtr++;
  402.      }
  403.   }
  404.   argOrderVector[argOrderOffset] = 0;
  405.  
  406.   done = NO;
  407.  
  408.   if (!done && !strcmp("d", argOrderVector))
  409.   {  [self resizeTclCommandForArgVector:argOrderVector];
  410.      sprintf(tclCommand, sprintfControlString, [self intValue]);
  411.      done = YES;
  412.   }
  413.   if (!done && !strcmp("f", argOrderVector))
  414.   {  [self resizeTclCommandForArgVector:argOrderVector];
  415.      sprintf(tclCommand, sprintfControlString, [self floatValue]);
  416.      done = YES;
  417.   }
  418.   if (!done && !strcmp("s", argOrderVector))
  419.   {  [self resizeTclCommandForArgVector:argOrderVector];
  420.      sprintf(tclCommand, sprintfControlString, [self stringValue]);
  421.      done = YES;
  422.   }
  423.   if (!done && !strcmp("T", argOrderVector))
  424.   {  [self resizeTclCommandForArgVector:argOrderVector];
  425.      sprintf(tclCommand, sprintfControlString, [self tag]);
  426.      done = YES;
  427.   }
  428.   if (!done && !strcmp("dT", argOrderVector))
  429.   {  [self resizeTclCommandForArgVector:argOrderVector];
  430.      sprintf(tclCommand, sprintfControlString, [self intValue], [self tag]);
  431.      done = YES;
  432.   }
  433.   if (!done && !strcmp("fT", argOrderVector))
  434.   {  [self resizeTclCommandForArgVector:argOrderVector];
  435.      sprintf(tclCommand, sprintfControlString, [self floatValue], [self tag]);
  436.      done = YES;
  437.   }
  438.   if (!done && !strcmp("sT", argOrderVector))
  439.   {  [self resizeTclCommandForArgVector:argOrderVector];
  440.      sprintf(tclCommand, sprintfControlString, [self stringValue], [self tag]);
  441.      done = YES;
  442.   }
  443.   if (!done && !strcmp("Td", argOrderVector))
  444.   {  [self resizeTclCommandForArgVector:argOrderVector];
  445.      sprintf(tclCommand, sprintfControlString, [self tag], [self intValue]);
  446.      done = YES;
  447.   }
  448.   if (!done && !strcmp("Tf", argOrderVector))
  449.   {  [self resizeTclCommandForArgVector:argOrderVector];
  450.      sprintf(tclCommand, sprintfControlString, [self tag], [self floatValue]);
  451.      done = YES;
  452.   }
  453.   if (!done && !strcmp("Ts", argOrderVector))
  454.   {  [self resizeTclCommandForArgVector:argOrderVector];
  455.      sprintf(tclCommand, sprintfControlString, [self tag], [self stringValue]);
  456.      done = YES;
  457.   }
  458.   // for back compatibility
  459.   if (!done && !strcmp("fff", argOrderVector))
  460.   {  [self resizeTclCommandForArgVector:argOrderVector];
  461.      sprintf(tclCommand, sprintfControlString, NXRedComponent(color), NXGreenComponent(color), NXBlueComponent(color));
  462.      done = YES;
  463.   }
  464.   if (!done && !strcmp("RGB", argOrderVector))
  465.   {  [self resizeTclCommandForArgVector:argOrderVector];
  466.      sprintf(tclCommand, sprintfControlString, NXRedComponent(color), NXGreenComponent(color), NXBlueComponent(color));
  467.      done = YES;
  468.   }
  469.   if (!done && !strcmp("fRGB", argOrderVector))
  470.   {  [self resizeTclCommandForArgVector:argOrderVector];
  471.      sprintf(tclCommand, sprintfControlString, [self floatValue], NXRedComponent(color), NXGreenComponent(color), NXBlueComponent(color));
  472.      done = YES;
  473.   }
  474.   if (!done && !strcmp("RGBf", argOrderVector))
  475.   {  [self resizeTclCommandForArgVector:argOrderVector];
  476.      sprintf(tclCommand, sprintfControlString, NXRedComponent(color), NXGreenComponent(color), NXBlueComponent(color), [self floatValue]);
  477.      done = YES;
  478.   }
  479.   if (!done && !strcmp("dRGB", argOrderVector))
  480.   {  [self resizeTclCommandForArgVector:argOrderVector];
  481.      sprintf(tclCommand, sprintfControlString, [self intValue], NXRedComponent(color), NXGreenComponent(color), NXBlueComponent(color));
  482.      done = YES;
  483.   }
  484.   if (!done && !strcmp("RGBd", argOrderVector))
  485.   {  [self resizeTclCommandForArgVector:argOrderVector];
  486.      sprintf(tclCommand, sprintfControlString, NXRedComponent(color), NXGreenComponent(color), NXBlueComponent(color), [self intValue]);
  487.      done = YES;
  488.   }
  489.  
  490.   if (!done)
  491.   {  while (tclCommandSize < controlStringSize)
  492.      {  if (!tclCommandSize)
  493.     {  tclCommandSize = 32;
  494.            tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  495.         }
  496.         else
  497.         {  tclCommandSize *= 2;
  498.            tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  499.         }
  500.      }
  501.      strcpy(tclCommand, controlString);
  502.   }
  503.   tclCommandDirty = NO;
  504.  
  505.   NXZoneFree([self zone], argOrderVector);
  506.  
  507.   return self;
  508. }
  509.  
  510.  
  511. - evaluateSelf
  512. {
  513.    int   ret;
  514.    char  *newStringValue;
  515.    id    retID;
  516.  
  517.  
  518.   newStringValue = [interp globalEval:tclExpression :&ret];
  519.   if ((ret == TCL_OK) || (ret == TCL_RETURN))
  520.   {  //if (ret == TCL_RETURN)
  521.      //{  NXLogError("got TCL_RETURN for <%s>\n", newStringValue);
  522.      //}
  523.      [self setStringValue:newStringValue];
  524.      retID = self;
  525.   }
  526.   else
  527.   {  NXLogError("WWSliderCell: error <%s> evaluating tcl expression <%s>\n", 
  528.         newStringValue, tclExpression);
  529.      if (newStringValue) { free(newStringValue); }
  530.      retID = nil;
  531.   }
  532.   return retID;
  533. }
  534.  
  535.  
  536. - updateInterp
  537. {
  538.   if ([interp eval:[self tclCommand]])
  539.   {  return self;
  540.   }
  541.   return nil;
  542. }
  543.  
  544.  
  545. - setControlString:(const char *)str 
  546.   int   cnt;
  547.  
  548.  
  549.   if (!str) { return self; }
  550.   if (controlStringSize <= 0) 
  551.   {  controlStringSize = 32; 
  552.      controlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  553.   }
  554.   cnt = strlen(str);
  555.   while (cnt >= controlStringSize)
  556.   {  controlStringSize *= 2;
  557.      controlString = (char *)NXZoneRealloc([self zone], controlString, controlStringSize);
  558.   }
  559.   if (sprintfControlString)
  560.   {  sprintfControlString = (char *)NXZoneRealloc([self zone], sprintfControlString, controlStringSize);
  561.   }
  562.   else
  563.   {  sprintfControlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  564.   }
  565.   strcpy(controlString, str); 
  566.   tclCommandDirty = YES;
  567.   return self; 
  568. }
  569. //
  570. - (const char *)controlString { return controlString; }
  571.  
  572. - setTclExpression:(const char *)str 
  573.   int   cnt;
  574.  
  575.  
  576.   if (!str) { return self; }
  577.   if (tclExpressionSize <= 0) 
  578.   {  tclExpressionSize = 32; 
  579.      tclExpression = (char *)NXZoneCalloc([self zone], tclExpressionSize, sizeof(char));
  580.   }
  581.   cnt = strlen(str);
  582.   while (cnt >= tclExpressionSize)
  583.   {  tclExpressionSize *= 2;
  584.      tclExpression = (char *)NXZoneRealloc([self zone], tclExpression, tclExpressionSize);
  585.   }
  586.   strcpy(tclExpression, str); 
  587.   return self; 
  588. }
  589. //
  590. - (const char *)tclExpression { return tclExpression; }
  591.  
  592. - setTclVar:(const char *)str 
  593.   int   cnt;
  594.  
  595.  
  596.   if (!str) { return self; }
  597.   if (tclVarSize <= 0) 
  598.   {  tclVarSize = 32; 
  599.      tclVar = (char *)NXZoneCalloc([self zone], tclVarSize, sizeof(char));
  600.   }
  601.   cnt = strlen(str);
  602.   while (cnt >= tclVarSize)
  603.   {  tclVarSize *= 2;
  604.      tclVar = (char *)NXZoneRealloc([self zone], tclVar, tclVarSize);
  605.   }
  606.   strcpy(tclVar, str); 
  607.   return self; 
  608. }
  609. //
  610. - (const char *)tclVar { return tclVar; }
  611.  
  612. - setTclCommand:(const char *)str 
  613.   int   cnt;
  614.  
  615.  
  616.   if (!str) { return self; }
  617.   if (tclCommandSize <= 0) 
  618.   {  tclCommandSize = 32; 
  619.      tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  620.   }
  621.   cnt = strlen(str);
  622.   while (cnt >= tclCommandSize)
  623.   {  tclCommandSize *= 2;
  624.      tclCommand = (char *)NXZoneRealloc([self zone], tclCommand, tclCommandSize);
  625.   }
  626.   strcpy(tclCommand, str); 
  627.   return self; 
  628. }
  629. //
  630. - (const char *)tclCommand 
  631.   if (tclCommandDirty)
  632.   {  [self updateTclCommand];
  633.   }
  634.   return tclCommand; 
  635. }
  636.  
  637. - setMinText:sender {  minText = sender; return self;}
  638. - setMaxText:sender {  maxText = sender; return self;}
  639. - setValText:sender {  valText = sender; return self;}
  640.  
  641.  
  642. #define NOTEQUAL(a,b) (ABS((a)-(b))>0.0001)
  643.  
  644. - drawSelf:(const NXRect *)theFrame inView:view
  645. {
  646.    NXSize   imageSize;
  647.    NXImage  *oldImage;
  648.  
  649.  
  650.    if (usingPrivateImage || colorChanged)
  651.    {  oldImage = [self image];
  652.       if (oldImage)
  653.       { [oldImage getSize:&imageSize];
  654.         if(NOTEQUAL(imageSize.width,NX_WIDTH(theFrame)) || NOTEQUAL(imageSize.height,NX_HEIGHT(theFrame)) || colorChanged)
  655.         {  [self generateImage:theFrame];
  656.         }
  657.       }
  658.       else
  659.       {  [self generateImage:theFrame];
  660.       }
  661.    }
  662.    return [super drawSelf:theFrame inView:view];
  663. }
  664.  
  665.  
  666. - setColor:(NXColor)newColor { color = newColor; colorChanged = YES; tclCommandDirty = YES; return self; }
  667. - (NXColor)color { return color; }
  668.  
  669. - generateImage:(const NXRect *)theFrame
  670. {
  671.   NXImage  *oldImage, *newImage;
  672.  
  673.  
  674.   oldImage = [self image];
  675.   if (oldImage && usingPrivateImage)
  676.   {  [oldImage free];
  677.   }
  678.   newImage = [[NXImage alloc] initSize:&(theFrame->size)];
  679.   usingPrivateImage = YES;
  680.   [newImage lockFocus];
  681.   NXSetColor(color);
  682.   PSrectfill(theFrame->origin.x, theFrame->origin.y, theFrame->size.width, theFrame->size.height);
  683.   [newImage unlockFocus];
  684.   [self setImage:newImage];
  685.   colorChanged = NO;
  686.  
  687.   return self;
  688. }
  689.  
  690. - write:(NXTypedStream *)stream 
  691. {
  692.    [super write:stream];
  693.    NXWriteType(stream, "*", &controlString);
  694.    NXWriteType(stream, "*", &tclVar);
  695.    NXWriteType(stream, "*", &tclExpression);
  696.    NXWriteType(stream, "*", &tclCommand);
  697.    NXWriteType(stream, "c", &autoSendP);
  698.    NXWriteObjectReference(stream, interp);
  699.    NXWriteColor(stream, color);
  700.    return self;
  701. }
  702. //
  703. - read:(NXTypedStream *)stream 
  704. {
  705.    int version;
  706.  
  707.    [super read:stream];
  708.  
  709.    version = NXTypedStreamClassVersion(stream, "WWSliderCell");
  710.    if (version == 1)
  711.    {  NXReadType(stream, "*", &controlString);
  712.       if (controlString) 
  713.       {  controlStringSize = strlen(controlString) + 1;
  714.          sprintfControlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  715.       }
  716.       else
  717.       {  controlStringSize = 0;
  718.          sprintfControlString = NULL;
  719.       }
  720.       NXReadType(stream, "*", &tclVar);
  721.       if (tclVar) 
  722.       {  tclVarSize = strlen(tclVar) + 1;
  723.       }
  724.       else
  725.       { tclVarSize = 0;
  726.       }
  727.       autoSendP = YES;
  728.       interp = nil;
  729.       color = NX_COLORLTGRAY;
  730.       tclCommandSize = 0;
  731.       tclCommand = NULL;
  732.    }
  733.    if (version == 2)
  734.    {  NXReadType(stream, "*", &controlString);
  735.       if (controlString) 
  736.       {  controlStringSize = strlen(controlString) + 1;
  737.          sprintfControlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  738.       }
  739.       else
  740.       {  controlStringSize = 0;
  741.          sprintfControlString = NULL;
  742.       }
  743.       NXReadType(stream, "*", &tclVar);
  744.       if (tclVar) 
  745.       {  tclVarSize = strlen(tclVar) + 1;
  746.       }
  747.       else
  748.       { tclVarSize = 0;
  749.       }
  750.       NXReadType(stream, "*", &tclExpression);
  751.       if (tclExpression) 
  752.       {  tclExpressionSize = strlen(tclExpression) + 1;
  753.       }
  754.       else
  755.       {  tclExpressionSize = 0;
  756.       }
  757.       tclCommandSize = 0;
  758.       tclCommand = NULL;
  759.       autoSendP = YES;
  760.       interp = nil;
  761.       color = NX_COLORLTGRAY;
  762.    }
  763.    if (version == 3)
  764.    {  NXReadType(stream, "*", &controlString);
  765.       if (controlString) 
  766.       {  controlStringSize = strlen(controlString) + 1;
  767.          sprintfControlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  768.       }
  769.       else
  770.       {  controlStringSize = 0;
  771.          sprintfControlString = NULL;
  772.       }
  773.       NXReadType(stream, "*", &tclVar);
  774.       if (tclVar) 
  775.       {  tclVarSize = strlen(tclVar) + 1;
  776.       }
  777.       else
  778.       { tclVarSize = 0;
  779.       }
  780.       NXReadType(stream, "*", &tclExpression);
  781.       if (tclExpression) 
  782.       {  tclExpressionSize = strlen(tclExpression) + 1;
  783.       }
  784.       else
  785.       {  tclExpressionSize = 0;
  786.       }
  787.       NXReadType(stream, "*", &tclCommand);
  788.       if (tclCommand) 
  789.       {  tclCommandSize = strlen(tclCommand) + 1;
  790.       }
  791.       else
  792.       {  tclCommandSize = 0;
  793.       }
  794.       NXReadType(stream, "c", &autoSendP);
  795.       interp = NXReadObject(stream);
  796.       color = NX_COLORLTGRAY;
  797.    }
  798.    if (version == 4)
  799.    {  NXReadType(stream, "*", &controlString);
  800.       if (controlString) 
  801.       {  controlStringSize = strlen(controlString) + 1;
  802.       }
  803.       else
  804.       {  controlStringSize = 0;
  805.          sprintfControlString = NULL;
  806.       }
  807.       NXReadType(stream, "*", &tclVar);
  808.       if (tclVar) 
  809.       {  tclVarSize = strlen(tclVar) + 1;
  810.       }
  811.       else
  812.       { tclVarSize = 0;
  813.       }
  814.       NXReadType(stream, "*", &tclExpression);
  815.       if (tclExpression) 
  816.       {  tclExpressionSize = strlen(tclExpression) + 1;
  817.       }
  818.       else
  819.       {  tclExpressionSize = 0;
  820.       }
  821.       NXReadType(stream, "*", &tclCommand);
  822.       if (tclCommand) 
  823.       {  tclCommandSize = strlen(tclCommand) + 1;
  824.       }
  825.       else
  826.       {  tclCommandSize = 0;
  827.       }
  828.       NXReadType(stream, "c", &autoSendP);
  829.       interp = NXReadObject(stream);
  830.       color = NXReadColor(stream);
  831.       NXReadType(stream, "*", &sprintfControlString);
  832.       if (sprintfControlString) {  free(sprintfControlString); }
  833.       if (controlStringSize)
  834.       {  sprintfControlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  835.       }
  836.       else
  837.       {  sprintfControlString = NULL;
  838.       }
  839.    }
  840.    if (version == 5)
  841.    {  NXReadType(stream, "*", &controlString);
  842.       if (controlString) 
  843.       {  controlStringSize = strlen(controlString) + 1;
  844.          sprintfControlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  845.       }
  846.       else
  847.       {  controlStringSize = 0;
  848.          sprintfControlString = NULL;
  849.       }
  850.       NXReadType(stream, "*", &tclVar);
  851.       if (tclVar) 
  852.       {  tclVarSize = strlen(tclVar) + 1;
  853.       }
  854.       else
  855.       { tclVarSize = 0;
  856.       }
  857.       NXReadType(stream, "*", &tclExpression);
  858.       if (tclExpression) 
  859.       {  tclExpressionSize = strlen(tclExpression) + 1;
  860.       }
  861.       else
  862.       {  tclExpressionSize = 0;
  863.       }
  864.       NXReadType(stream, "*", &tclCommand);
  865.       if (tclCommand) 
  866.       {  tclCommandSize = strlen(tclCommand) + 1;
  867.       }
  868.       else
  869.       {  tclCommandSize = 0;
  870.       }
  871.       NXReadType(stream, "c", &autoSendP);
  872.       interp = NXReadObject(stream);
  873.       color = NXReadColor(stream);
  874.    }
  875.    return self;
  876. }
  877.  
  878. // IB stuff
  879. - (const char *)getInspectorClassName 
  880. {  
  881.    NXEvent  *event = [NXApp currentEvent];
  882.  
  883.    if (event->flags & NX_ALTERNATEMASK)
  884.    {  return [super getInspectorClassName];
  885.    }
  886.    
  887.    return "WWSliderCellIBInspector"; 
  888. }
  889.  
  890.  
  891.  
  892.  
  893. @end
  894.