home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / UserTicsPane.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  5.1 KB  |  231 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.  
  11. static char RCSId[]="$Id: UserTicsPane.m,v 1.4 1993/05/04 16:23:15 davis Exp $";
  12.  
  13. #import <appkit/Application.h>
  14. #import <appkit/Form.h>
  15. #import <appkit/FormCell.h>
  16. #import <appkit/publicWraps.h>        /* NXBeep() */
  17. #import <appkit/View.h>
  18.  
  19. #import "CellScrollView.h"
  20. #import "DoubleValueSortedList.h"
  21. #import "EditMatrix.h"
  22. #import "Status.h"
  23. #import "StatusTics.h"
  24. #import "TicCell.h"
  25. #import "TicObject.h"
  26. #import "TicOptionsPanel.h"
  27. #import "UserTicsPane.h"
  28.  
  29. @interface UserTicsPane (Private)
  30. - _updateControlsForSelectedTic;
  31. @end
  32.  
  33.  
  34. @implementation UserTicsPane
  35.  
  36.  
  37. - init
  38. {
  39.     [super init];
  40.  
  41.     [NXApp loadNibSection: "UserTicsPane.nib"
  42.             owner: self
  43.         withNames: NO
  44.          fromZone: [self zone]];
  45.  
  46.     /*  Initialize custom tics CellScrollView  */
  47.  
  48.     [userScrollView initMatrixCellClass:[TicCell class] cols:1];
  49.     userMatrix = [userScrollView cellMatrix];
  50.     [[userMatrix setAction:@selector(selectTic:)] setTarget:self];
  51.  
  52.     return self;
  53. }
  54.  
  55.  
  56. - (BOOL)updateStatus:aStatus doc:aDoc
  57. {
  58.     BOOL    isEnabled;
  59.  
  60.     if ([super updateStatus:aStatus doc:aDoc]) {
  61.     int        i;
  62.     int        coord = [doc coord];
  63.  
  64.     for (i = 0; i < 3; i++)
  65.         ticsList[i] = [status ticDefsCoord:i];
  66.  
  67.     [userScrollView loadCol:0 from:ticsList[coord]];
  68.  
  69.     } else
  70.     [userScrollView loadCol:0 from:nil];
  71.  
  72.     [self selectTic:self];
  73.     [addTicButton setEnabled:isEnabled = (status? YES:NO)];
  74.     [userTitleForm setEnabled:isEnabled];
  75.     [userValueForm setEnabled:isEnabled];
  76.     [userMatrix setEnabled:isEnabled];
  77.     [deleteTicButton setEnabled:isEnabled = (status &&
  78.                          [userMatrix selectedCell])];
  79.     [modifyTicButton setEnabled:isEnabled];
  80.  
  81.     return YES;
  82. }
  83.  
  84.  
  85. - addTic:sender
  86. {
  87.     int        coord = [doc coord];
  88.     TicObject    *ticObject;
  89.     int        location;
  90.     BOOL    changed = YES;
  91.  
  92.     ticObject = [[TicObject allocFromZone:[status zone]]
  93.                initFromString:[userTitleForm stringValueAt:0]
  94.                   doubleValue:[userValueForm doubleValueAt:0]];
  95.     location = [ticsList[coord] addObjectIfDoubleAbsent:ticObject];
  96.  
  97.     if (location == NX_NOT_IN_LIST) {
  98.     [ticObject free];
  99.     location = [userMatrix selectedRow];
  100.     changed = NO;
  101.     NXBeep();
  102.     }
  103.  
  104.     [userScrollView loadCol:0 from:ticsList[coord]];
  105.     [userMatrix scrollCellToVisible:location :0];
  106.     [userMatrix selectCellAt:location :0];
  107.  
  108.     [self selectTic:self];
  109.     if (changed)
  110.     [status reportSettingsChange:self];
  111.  
  112.     return self;
  113. }
  114.  
  115.  
  116. - deleteTics:sender
  117. {
  118.     int        coord = [doc coord];
  119.     int        i;
  120.     int        maxrow = [userMatrix cellCount] - 1;
  121.     int        row = maxrow;
  122.     BOOL    gotRow = NO;
  123.  
  124.     for (i = maxrow; i >= 0; i--) {
  125.     TicCell *cell = [userMatrix cellAt:i:0];
  126.     if ([cell isHighlighted]) {
  127.         /*
  128.          *  If a cell is highlighted, remove (and free) the
  129.          *  corresponding item from the list of TicObjects.
  130.          */
  131.         [[ticsList[coord] removeObject:[cell subObject]] free];
  132.  
  133.         if (!gotRow) {
  134.         row = (i == maxrow)? i - 1 :i;
  135.         gotRow = YES;
  136.         } else
  137.         row--;
  138.     }
  139.     }
  140.  
  141.     [userScrollView loadCol:0 from:ticsList[coord]];
  142.  
  143.     [userMatrix selectCellAt: row:0];
  144.     [userMatrix scrollCellToVisible: row:0];
  145.     [self selectTic:self];
  146.  
  147.     [status reportSettingsChange:self];
  148.     return self;
  149. }
  150.  
  151.  
  152. - modifyTic:sender
  153. {
  154.     int        coord = [doc coord];
  155.     TicObject    *tic = [[userMatrix selectedCell] subObject];
  156.     int        location;
  157.  
  158.     [tic setStringValue:[userTitleForm stringValueAt:0]];
  159.     [tic setDoubleValue:[userValueForm doubleValueAt:0]];
  160.  
  161.     /*
  162.      *  Remove the tic from the list and reinsert
  163.      *  it, to maintain the sort order of the list.
  164.      */
  165.     location = [ticsList[coord] addObject:[ticsList[coord] removeObject:tic]];
  166.     [userScrollView loadCol:0 from:ticsList[coord]];
  167.     [userMatrix scrollCellToVisible: location:0];
  168.     [userMatrix selectCellAt: location:0];
  169.     [self selectTic:self];
  170.  
  171.     [status reportSettingsChange:self];
  172.     return self;
  173. }
  174.  
  175.  
  176. /*
  177.  *  Make other controls in the window reflect the currently selected
  178.  *  tic.  Assumes that the current tic type is TIC_USER.
  179.  */
  180. - selectTic:sender
  181. {
  182.     if (![userMatrix selectedCell]
  183.     && ![userMatrix multipleCellsSelected]) {
  184.  
  185.     [userMatrix selectCellAt:0:0];
  186.       }
  187.  
  188.     [self _updateControlsForSelectedTic];
  189.     return self;
  190. }
  191.  
  192.  
  193. // Shuts up the compiler about unused RCSId
  194. - (const char *) rcsid
  195. {
  196.     return RCSId;
  197. }
  198.  
  199.  
  200. @end
  201.  
  202.  
  203. @implementation UserTicsPane (Private)
  204.  
  205. - _updateControlsForSelectedTic
  206. {
  207.     TicCell    *singleCell = [userMatrix selectedCell];
  208.     BOOL    enabled = (singleCell || [userMatrix multipleCellsSelected]);
  209.  
  210.     if (singleCell) {
  211.     TicObject *tic = [singleCell subObject];
  212.  
  213.     [userTitleForm setStringValue:[tic stringValue] at:0];
  214.     [userValueForm setDoubleValue:[tic doubleValue] at:0];
  215.  
  216.     } else {
  217.  
  218.     [userTitleForm setStringValue:"" at:0];
  219.     [userValueForm setStringValue:"" at:0];
  220.     }
  221.  
  222.     [deleteTicButton setEnabled:enabled];
  223.     [modifyTicButton setEnabled:singleCell? YES:NO];
  224.     [userValueForm selectTextAt:0];
  225.  
  226.     return self;
  227. }
  228.  
  229.  
  230. @end
  231.