home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / PopUpScrollView.m < prev    next >
Encoding:
Text File  |  1993-03-18  |  2.4 KB  |  145 lines

  1.  
  2. static char RCSId[]="$Id: PopUpScrollView.m,v 1.1.1.1 1993/03/18 03:35:17 davis Exp $";
  3.  
  4.  
  5. #import <appkit/Matrix.h>
  6. #import <appkit/PopUpList.h>
  7.  
  8. #import <objc/List.h>
  9.  
  10. #import "PopUpScrollView.h"
  11. #import "PlotView.h"
  12.  
  13. #define UNDEFINED    -1.0    /* See [Control selectedTag]    */
  14. #define DEFAULTTAG    100    /* Default tag upon init is 100    */
  15.  
  16.  
  17. @implementation PopUpScrollView
  18.  
  19.  
  20. - initFrame:(const NXRect *)frameRect
  21. {
  22.     [super initFrame:frameRect];
  23.     oldTag = UNDEFINED;
  24.     return self;
  25. }
  26.  
  27.  
  28. - free
  29. {
  30.     /*  
  31.      *  A pop-up button's target is a PopUpList that won't be freed 
  32.      *  when the popUpButton is freed.  So we must free it here.
  33.      */
  34.     [[popUpButton target] free];
  35.     return [super free];
  36. }
  37.  
  38.  
  39. - changeScale:sender
  40. {
  41.     int theTag = [sender selectedTag];
  42.  
  43.     if (theTag != oldTag)  {
  44.     oldTag = theTag;
  45.     return [self setCurrentTag: theTag];
  46.     } else
  47.     return nil;
  48. }
  49.  
  50.  
  51. /* 1.00 scaleFactor == 100% */
  52.  
  53. - changeScaleTo:(float)scaleFactor
  54. {
  55.     [[self docView] scale:scaleFactor];
  56.     return self;
  57. }
  58.  
  59.  
  60.  
  61. - tile
  62. {
  63.     NXRect scrollerRect, buttonRect;
  64.  
  65.     [super tile];
  66.  
  67.     if ([popUpButton superview] != self) {
  68.     [self addSubview:popUpButton];
  69.     }
  70.  
  71.     /*
  72.      *  Now make the hScroller smaller and stick the popUpButton next 
  73.      *  to it.
  74.      */
  75.     [hScroller getFrame:&scrollerRect];
  76.     NXDivideRect(&scrollerRect, &buttonRect, 90.0, 2);
  77.     [hScroller setFrame:&scrollerRect];
  78.     [popUpButton setFrame:&buttonRect];
  79.     
  80.     return self;
  81. }
  82.  
  83.  
  84.  
  85. - update
  86. {
  87.     [self setCurrentTag:[self currentTag]];
  88.     return self;
  89. }
  90.  
  91.  
  92.  
  93. - setCurrentTag:(int)aTag
  94. {
  95.     int    i, count;
  96.     id    cell, cells;
  97.     id value = nil;
  98.  
  99.     cell = [[popUpButton target] findCellWithTag:aTag];
  100.  
  101.     /* 
  102.      *  Check to make sure the tag is a valid selection (i.e. that it 
  103.      *  is in the PopUpList.  If not, we don't do anything.  (Note 
  104.      *  that we do not add aTag to the list.)
  105.      */
  106.     
  107.     cells = [[[popUpButton target] itemList] cellList];
  108.     count = [cells count];
  109.  
  110.     for(i = 0; i < count; i++)  {
  111.     if ([cells objectAt:i] == cell)  {
  112.         [popUpButton setTitle: [cell title]];
  113.         value = self;
  114.         [self changeScaleTo: [cell tag] / 100.0];
  115.         oldTag = aTag;
  116.         break;
  117.     }
  118.     }
  119.  
  120.     return value;
  121. }
  122.  
  123.  
  124. - (int)currentTag
  125. {
  126.     int aTag;
  127.  
  128.     aTag = [[[popUpButton target] itemList] selectedTag];
  129.  
  130.     if (aTag != UNDEFINED)
  131.     return aTag;
  132.     else
  133.     return DEFAULTTAG;
  134. }
  135.  
  136.  
  137. // Shuts up the compiler about unused RCSId
  138. - (const char *) rcsid
  139. {
  140.     return RCSId;
  141. }
  142.  
  143.  
  144. @end
  145.