home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / FunctionPane.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  5.4 KB  |  253 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10. static char RCSId[]="$Id: FunctionPane.m,v 1.5 1993/05/30 10:01:53 davis Exp $";
  11.  
  12. #import <appkit/Application.h>
  13. #import <appkit/Cell.h>
  14. #import <appkit/View.h>
  15.  
  16. #import "DataOptionsPanel.h"
  17. #import "EditMatrix.h"
  18. #import "FunctionObject.h"
  19. #import "FunctionPane.h"
  20. #import "Status.h"
  21. #import "SubObjectCategory.h"
  22.  
  23. #define    STYLE        0
  24. #define    STYLE_LINE    1
  25. #define    STYLE_POINTS    2
  26.  
  27. @interface FunctionPane (Private)
  28. - (int)_findMultStyleType:(int)type ofMatrix:(Matrix *)aMatrix;
  29. - _setStyleType:(unsigned int)type to:(int)style;
  30. @end
  31.  
  32.  
  33. @implementation FunctionPane
  34.  
  35. - init
  36. {
  37.     [super init];
  38.  
  39.     [NXApp loadNibSection: "FunctionPane.nib"
  40.             owner: self
  41.         withNames: NO
  42.          fromZone: [self zone]];
  43.  
  44.     return self;
  45. }
  46.  
  47.  
  48.  
  49. - (BOOL)updateStatus:aStatus doc:aDoc
  50. {
  51.     /*  
  52.      *  aDoc should be the controlling object that we can query for 
  53.      *  the current function, function matrix, etc.
  54.      */
  55.     FunctionObject *f = [aDoc function];
  56.     EditMatrix    *fm = [aDoc functionsMatrix];
  57.     int        style;
  58.     BOOL    styleRight;
  59.     BOOL    isMult = [fm multipleCellsSelected];
  60.  
  61.     [super updateStatus:aStatus doc:aDoc];
  62.  
  63.     if (isMult) {        /* Multiple functions selected */
  64.  
  65.     [styleMatrix selectCellWithTag:
  66.         [self _findMultStyleType:STYLE ofMatrix:fm]];
  67.     [pointsStyleMatrix selectCellWithTag:
  68.         [self _findMultStyleType:STYLE_POINTS ofMatrix:fm]];
  69.     [lineStyleMatrix selectCellWithTag:
  70.         [self _findMultStyleType:STYLE_LINE ofMatrix:fm]];
  71.  
  72.     } else if (f) {        /* Single function selected */
  73.  
  74.     [styleMatrix selectCellWithTag: [f style]];
  75.     [pointsStyleMatrix selectCellWithTag: [f pointsStyle]];
  76.     [lineStyleMatrix selectCellWithTag: [f lineStyle]];
  77.  
  78.     } else if (!f) {        /* No selection */
  79.  
  80.     [styleMatrix selectCellWithTag: FUNCTION_NOSTYLE];
  81.     [pointsStyleMatrix selectCellWithTag: POINTS_NOSTYLE];
  82.     [lineStyleMatrix selectCellWithTag: LINE_NOSTYLE];
  83.  
  84.     }
  85.  
  86.     [styleMatrix setEnabled:isMult || f];
  87.  
  88.     if (isMult || f) {
  89.  
  90.         BOOL    isThreeD = [status isThreeD];
  91.  
  92.         [[styleMatrix findCellWithTag:FUNCTION_BOXES] setEnabled:!isThreeD];
  93.         [[styleMatrix findCellWithTag:FUNCTION_BOXERRORBARS] setEnabled:
  94.                                 !isThreeD];
  95.         [[styleMatrix findCellWithTag:FUNCTION_STEPS] setEnabled:!isThreeD];
  96.  
  97.     }
  98.  
  99.     style = [styleMatrix selectedTag];
  100.     styleRight = (isMult || f) &&
  101.         ((style == FUNCTION_POINTS) || (style == FUNCTION_LINESPOINTS));
  102.     [pointsStyleMatrix setEnabled:styleRight];
  103.     [pointsStyleLabel setEnabled:styleRight];
  104.  
  105.     styleRight = (isMult || f) &&
  106.         ((style == FUNCTION_LINES) || (style == FUNCTION_LINESPOINTS));
  107.     [lineStyleMatrix setEnabled:styleRight];
  108.     [lineStyleLabel setEnabled:styleRight];
  109.  
  110.  
  111.     /* The boxes cell should also be disabled */
  112.  
  113.     [[[[styleMatrix superview] superview] cell] setEnabled:isMult || f];
  114.  
  115.     return YES;
  116. }
  117.  
  118.  
  119.  
  120. - setFunctionStyle:sender
  121. {
  122.     [self _setStyleType:STYLE to:[sender selectedTag]];
  123.     if ([self forceUpdateStatus:status doc:doc])
  124.     [view display];
  125.     return self;
  126. }
  127.  
  128.   
  129.   
  130. - setFunctionPointsStyle:sender
  131. {
  132.     return [self _setStyleType:STYLE_POINTS to:[sender selectedTag]];
  133. }
  134.  
  135.  
  136.  
  137. - setFunctionLineStyle:sender
  138. {
  139.     return [self _setStyleType:STYLE_LINE to:[sender selectedTag]];
  140. }
  141.  
  142.  
  143.  
  144. // Shuts up the compiler about unused RCSId
  145. - (const char *) rcsid
  146. {
  147.     return RCSId;
  148. }
  149.  
  150.  
  151. @end
  152.  
  153.  
  154. @implementation FunctionPane (Private)
  155.  
  156. - (int)_findMultStyleType:(int)type ofMatrix:(Matrix *)aMatrix;
  157. {
  158.     Cell    *cell;
  159.     int        i, style = FUNCTION_NOSTYLE;
  160.     BOOL    gotStyle = NO;
  161.     int        defaultStyle;
  162.  
  163.     switch (type) {
  164.     case STYLE_LINE:    defaultStyle = POINTS_NOSTYLE; break;
  165.     case STYLE_POINTS:    defaultStyle = LINE_NOSTYLE; break;
  166.     default:        defaultStyle = FUNCTION_NOSTYLE; break;
  167.     }
  168.  
  169.     for (i = [aMatrix cellCount] - 1; i >= 0; i--) {
  170.     cell = [aMatrix cellAt:i:0];
  171.  
  172.     if ([cell isHighlighted])  {
  173.         int    cellstyle;
  174.         switch (type) {
  175.         case STYLE_LINE:
  176.         cellstyle = [[cell subObject] lineStyle]; break;
  177.         case STYLE_POINTS:
  178.         cellstyle = [[cell subObject] pointsStyle]; break;
  179.         default:
  180.         cellstyle = [[cell subObject] style]; break;
  181.         }
  182.  
  183.         if (gotStyle) {
  184.         if (cellstyle != style)
  185.             return defaultStyle;
  186.         } else {
  187.         style = cellstyle;
  188.         gotStyle = YES;
  189.         }
  190.     }
  191.     }
  192.  
  193.     return style;
  194. }
  195.  
  196.  
  197.  
  198.  
  199. - _setStyleType:(unsigned int)type to:(int)style
  200. {
  201.     BOOL        didChange = NO;
  202.     FunctionObject    *f = [doc function];
  203.  
  204.     if (f) {
  205.  
  206.     switch (type) {
  207.     case STYLE:        [f setStyle: style]; break;
  208.     case STYLE_LINE:    [f setLineStyle: style]; break;
  209.     case STYLE_POINTS:    [f setPointsStyle: style]; break;
  210.     }
  211.  
  212.     didChange = YES;
  213.  
  214.     } else {
  215.  
  216.     Cell        *cell;
  217.     EditMatrix    *fm = [doc functionsMatrix];
  218.     int        i;
  219.  
  220.     if ([fm multipleCellsSelected]) {
  221.         for (i = [fm cellCount] - 1 ; i >= 0 ; i--) {
  222.         cell = [fm cellAt:i:0];
  223.         if ([cell isHighlighted])  {
  224.  
  225.             switch (type) {
  226.             case STYLE:
  227.             [[cell subObject] setStyle: style]; break;
  228.             case STYLE_LINE:
  229.             [[cell subObject] setLineStyle: style]; break;
  230.             case STYLE_POINTS:
  231.             [[cell subObject] setPointsStyle: style]; break;
  232.             }
  233.  
  234.             didChange = YES;
  235.         }
  236.         }
  237.     }
  238.  
  239.     }
  240.  
  241.     if (didChange) {
  242.     [status reportSettingsChange:self];
  243.  
  244.     /* Setting style may affect other controls */
  245.     [self forceUpdateStatus:status doc:doc];
  246.     }
  247.  
  248.     return self;
  249. }
  250.  
  251.  
  252. @end
  253.