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

  1.  
  2. static char RCSId[]="$Id: Inspector.m,v 1.1.1.1 1993/03/18 03:33:50 davis Exp $";
  3.  
  4.  
  5. #import <appkit/Application.h>
  6. #import <appkit/Button.h>
  7. #import <appkit/Matrix.h>
  8. #import <appkit/Panel.h>
  9. #import <appkit/Pasteboard.h>
  10. #import <appkit/publicWraps.h>    /* NXBeep()        */
  11.  
  12. #import <dpsclient/wraps.h>
  13.  
  14. #import <objc/NXStringTable.h>
  15.  
  16. #import "GnuplotPlot.h"
  17. #import "Inspector.h"
  18. #import "Pane.h"
  19. #import "Status.h"
  20.  
  21.  
  22. @interface Inspector (Private)
  23.  
  24. - _swapPane:new;
  25. - _determineNewStatusAndDoc;
  26. - _updateForce:(BOOL)force all:(BOOL)all;
  27.  
  28. @end
  29.  
  30.  
  31.  
  32. @implementation Inspector
  33.  
  34.  
  35. - init
  36. {
  37.     const char *validSend[] = {NXAsciiPboardType, NULL};
  38.     const char *validReturn[] = {NXAsciiPboardType, NULL};
  39.     NXRect frame;
  40.  
  41.     [super init];
  42.  
  43.     [NXApp loadNibSection: "Inspector.nib" 
  44.             owner: self
  45.         withNames: NO
  46.          fromZone: [self zone]];
  47.  
  48.     status = nil;
  49.     gnuplotPlot = nil;
  50.  
  51.     [window setFrameUsingName:"InspectorPanel"];
  52.     [window setFrameAutosaveName:"InspectorPanel"];
  53.  
  54.     [noPane setTitle:[stringSet valueForStringKey:"inspectorNone"]];
  55.     [generalPane setTitle:[stringSet valueForStringKey:"inspectorGeneral"]];
  56.     [dataPane setTitle:[stringSet valueForStringKey:"inspectorData"]];
  57.     [axesPane setTitle:[stringSet valueForStringKey:"inspectorAxes"]];
  58.     [threeDPane setTitle:[stringSet valueForStringKey:"inspectorThreeD"]];
  59.  
  60.     [NXApp registerServicesMenuSendTypes: validSend
  61.                           andReturnTypes: validReturn];
  62.  
  63.     [window getFrame:&frame];
  64.     windowWidth = frame.size.width;
  65.  
  66.     noView = [noPane view];
  67.     generalView = [generalPane view];
  68.     dataView = [dataPane view];
  69.     axesView = [axesPane view];
  70.     threeDView = [threeDPane view];
  71.  
  72.     [[window contentView] allocateGState];
  73.  
  74.     [[window contentView] addSubview: noView];
  75.     [[noView allocateGState] lockFocus];
  76.     [noView unlockFocus];
  77.     [noView moveTo:frame.size.width:30];
  78.  
  79.     [[window contentView] addSubview: generalView];
  80.     [[generalView allocateGState] lockFocus];
  81.     [generalView unlockFocus];
  82.     [generalView moveTo:frame.size.width:30];
  83.  
  84.     [[window contentView] addSubview: dataView];
  85.     [[dataView allocateGState] lockFocus];
  86.     [dataView allocateGState];
  87.     [dataView moveTo:frame.size.width:30];
  88.  
  89.     [[window contentView] addSubview: axesView];
  90.     [[axesView allocateGState] lockFocus];
  91.     [axesView unlockFocus];
  92.     [axesView moveTo:frame.size.width:30];
  93.  
  94.     [[window contentView] addSubview: threeDView];
  95.     [[threeDView allocateGState] lockFocus];
  96.     [threeDView unlockFocus];
  97.     [threeDView moveTo:frame.size.width:30];
  98.  
  99.     [noView moveTo:0:30];
  100.  
  101.     currentPane = noPane;
  102.     currentView = noView;
  103.     [window setMiniwindowIcon: [currentPane icon]];
  104.  
  105.     [window display];
  106.  
  107.     return self;
  108. }
  109.  
  110.  
  111.  
  112. - window
  113. {
  114.     return window;
  115. }
  116.  
  117.  
  118.  
  119. - showNoPane:sender
  120. {
  121.     if (status)
  122.     [self _swapPane:noPane];
  123.     return self;
  124. }
  125.  
  126.  
  127. - showGeneralPane:sender
  128. {
  129.     if (status)
  130.     [self _swapPane:generalPane];
  131.     return self;
  132. }
  133.  
  134.  
  135. - showDataPane:sender
  136. {
  137.     if (status)
  138.     [self _swapPane:dataPane];
  139.     return self;
  140. }
  141.  
  142.  
  143. - showAxesPane:sender
  144. {
  145.     if (status)
  146.     [self _swapPane:axesPane];
  147.     return self;
  148. }
  149.  
  150.  
  151. - showThreeDPane:sender
  152. {
  153.     if (status)
  154.     [self _swapPane:threeDPane];
  155.     return self;
  156. }
  157.  
  158.  
  159.  
  160. /* 
  161.  *  Services.  The Inspector instance is the inspector panel's 
  162.  *  delegate, so these methods work when the inspector panel is the 
  163.  *  key window.  We pass service requests on to the current 
  164.  *  GnuplotPlot so that the filename of the current doc can always be 
  165.  *  offered to servers, even when the inspector is the key window.
  166.  */
  167. - validRequestorForSendType:(NXAtom)sendType andReturnType:(NXAtom) returnType
  168. {
  169.     return [gnuplotPlot validRequestorForSendType:sendType 
  170.                     andReturnType:returnType];
  171. }
  172.  
  173.  
  174. - (BOOL)writeSelectionToPasteboard:pboard types:(NXAtom *)types
  175. {
  176.     return [gnuplotPlot writeSelectionToPasteboard:pboard types:types];
  177. }
  178.  
  179.  
  180.  
  181. /* 
  182.  *  This method is similar to -windowDidUpdate except that it forces 
  183.  *  ALL panes to update instead of just allowing the current pane to 
  184.  *  possibly update.  This is necessary to keep a pane's OptionsPanels 
  185.  *  up-to-date even when that pane is not selected.  (This is only a 
  186.  *  problem after such operations as "Revert to Saved" when NXApp's 
  187.  *  delegate must send this method.
  188.  */
  189. - update
  190. {
  191.     return [self _updateForce:YES all:YES];
  192. }
  193.  
  194.  
  195.  
  196. /*  
  197.  *  The user can force a plot by pressing the Plot button in the 
  198.  *  Inspector. 
  199.  */
  200. - doPlot:sender
  201. {
  202.     if (gnuplotPlot)
  203.     [gnuplotPlot plot:self];
  204.     else
  205.     NXBeep();
  206.  
  207.     return self;
  208. }
  209.  
  210.  
  211.  
  212. /*  
  213.  *  This method is similar to -update except that it updates only the 
  214.  *  current pane, and allows it to decide whether or not it should 
  215.  *  update itself instead of forcing it to update.
  216.  */
  217. - windowDidUpdate:sender
  218. {
  219.     return [self _updateForce:NO all:NO];
  220. }
  221.  
  222.  
  223. - selectPane:(int)aPane
  224. {
  225.     [buttonMatrix selectCellWithTag:aPane];
  226.  
  227.     if (status)
  228.     switch (aPane) {
  229.     case NO_INSPECTOR:        [self _swapPane:noPane];    break;
  230.     case GENERAL_INSPECTOR:        [self _swapPane:generalPane];    break;
  231.     case DATA_INSPECTOR:        [self _swapPane:dataPane];    break;
  232.     case AXES_INSPECTOR:        [self _swapPane:axesPane];    break;
  233.     case THREED_INSPECTOR:        [self _swapPane:threeDPane];    break;
  234.     }
  235.     else
  236.     [self _swapPane:noPane];
  237.  
  238.     return self;
  239. }
  240.  
  241.  
  242. // Shuts up the compiler about unused RCSId
  243. - (const char *) rcsid
  244. {
  245.     return RCSId;
  246. }
  247.  
  248.  
  249. @end
  250.  
  251.  
  252. @implementation Inspector (Private)
  253.  
  254. - _swapPane:new
  255. {
  256.     /*  
  257.      *  If "new" is nil, we look at the button matrix to determine 
  258.      *  which inspector to swap in.
  259.      */
  260.     if (!new) {
  261.         switch ([buttonMatrix selectedTag]) {
  262.         case NO_INSPECTOR:
  263.         new = noPane;
  264.             break;
  265.         case GENERAL_INSPECTOR:
  266.             new = generalPane;
  267.             break;
  268.         case DATA_INSPECTOR:
  269.             new = dataPane;
  270.             break;
  271.         case AXES_INSPECTOR:
  272.             new = axesPane;
  273.             break;
  274.         case THREED_INSPECTOR:
  275.             new = threeDPane;
  276.             break;
  277.         }
  278.     }
  279.  
  280.  
  281.     /*  
  282.      *  Now, if the new pane is not already visible, move it into the 
  283.      *  inspector panel.
  284.      */
  285.  
  286.     if (new != currentPane) {
  287.  
  288.     NXRect frame;
  289.     View *newView = [new view];
  290.  
  291.     [[window contentView] getFrame:&frame];
  292.  
  293.     [currentPane didSwapOut:self];
  294.     [[new didSwapIn:self] updateStatus:status doc:gnuplotPlot];
  295.     [currentView moveTo:NX_WIDTH(&frame):30];
  296.     [newView moveTo:0:30];
  297.     [window display];
  298.  
  299.     [window setTitle:[new title]];
  300.     [window setMiniwindowIcon:[new icon]];
  301.  
  302.     currentView = newView;
  303.     currentPane = new;
  304.  
  305.     }
  306.  
  307.     return self;
  308. }
  309.  
  310.  
  311. - _determineNewStatusAndDoc
  312. {
  313.     Window *mainWindow = [NXApp mainWindow];
  314.  
  315.     /*  Set instance variables that indicate the current doc.  */
  316.  
  317.     if (mainWindow)  {
  318.  
  319.     gnuplotPlot = [mainWindow delegate];
  320.     status = [gnuplotPlot status];
  321.  
  322.     } else {
  323.  
  324.     gnuplotPlot = nil;
  325.     status = nil;
  326.  
  327.     }
  328.  
  329.     return self;
  330. }
  331.  
  332.  
  333. - _updateForce:(BOOL)force all:(BOOL)all
  334. {
  335.     BOOL needsRedisplay = NO;
  336.  
  337.     [self _determineNewStatusAndDoc];
  338.     [window disableDisplay];
  339.  
  340.     if (!status) {            /* No current selection        */
  341.  
  342.     [self _swapPane:noPane];
  343.     needsRedisplay = YES;
  344.  
  345.     } else {                /* Update/replace controls    */
  346.  
  347.     if (force) {
  348.  
  349.         if (all) {
  350.  
  351.         needsRedisplay = [noPane forceUpdateStatus:status
  352.                            doc:gnuplotPlot]? YES :NO;
  353.  
  354.         needsRedisplay = ([generalPane forceUpdateStatus:status
  355.                   doc:gnuplotPlot]? YES :NO) || needsRedisplay;
  356.  
  357.         needsRedisplay = ([dataPane forceUpdateStatus:status
  358.                   doc:gnuplotPlot]? YES :NO) || needsRedisplay;
  359.  
  360.         needsRedisplay = ([axesPane forceUpdateStatus:status
  361.                   doc:gnuplotPlot]? YES :NO) || needsRedisplay;
  362.  
  363.         needsRedisplay = ([threeDPane forceUpdateStatus:status
  364.                   doc:gnuplotPlot]? YES :NO) || needsRedisplay;
  365.  
  366.         } else
  367.  
  368.         needsRedisplay = [currentPane forceUpdateStatus:status
  369.                   doc:gnuplotPlot]? YES :NO;
  370.  
  371.     } else
  372.  
  373.         needsRedisplay = [currentPane updateStatus:status doc:gnuplotPlot]?
  374.                                 YES :NO;
  375.     if (currentPane == noPane)
  376.         [self _swapPane:nil];    /* Get current pane from button */
  377.  
  378.     }
  379.  
  380.     [window reenableDisplay];
  381.     if (needsRedisplay)
  382.     [window display];
  383.  
  384.     /* 
  385.      *  We disable the plot button if
  386.      *         1) No current status, or
  387.      *         2) Current plot's status reports that it can't plot
  388.      */
  389.     [plotButton setEnabled:status && [status canPlot]];
  390.     
  391.     return self;
  392.  
  393.  
  394.  
  395. }
  396.  
  397. @end
  398.