home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Connectivity / GateKeeper-2.1 / SwapView.m < prev    next >
Encoding:
Text File  |  1996-11-18  |  6.3 KB  |  237 lines

  1. //*****************************************************************************
  2. //
  3. //    SwapView.m.  
  4. //
  5. //    I have condensed, optimized and reformatted the code so that a swapview
  6. //    can be implemented with this source file and a nib.  Added initPopUp 
  7. //     method.  
  8. //
  9. //        changes 5/25/95    by Felipe A. Rodriguez
  10. //        changes 7/29/95    by Felipe A. Rodriguez
  11. //            -- replaced addSubview in SwapIt method with replaceSubview.  This
  12. //                corrected a bug where textfields remained active after swap
  13. //        changes 3/14/96    by Felipe A. Rodriguez
  14. //            -- optimized class to support more inspectors
  15. //
  16. //    Most of this file was derived from:
  17. //    
  18. //            SwapView.m and InspectorController.m
  19. //            by Greg Burd
  20. //            SwapItDemo, ver 2.0
  21. //
  22. //    This code is supplied "as is" the author's makes no warranty as to its 
  23. //    suitability for any purpose.  This code is free and may be distributed 
  24. //    in accordance with the terms of the:
  25. //        
  26. //            GNU GENERAL PUBLIC LICENSE
  27. //            Version 2, June 1991
  28. //            copyright (C) 1989, 1991 Free Software Foundation, Inc.
  29. //             675 Mass Ave, Cambridge, MA 02139, USA
  30. //
  31. //*****************************************************************************
  32.  
  33. #import "SwapView.h"
  34. #import "Coordinator.h"
  35. #import <appkit/Window.h>
  36. #import <appkit/Application.h>
  37. #import <dpsclient/psops.h>
  38. #import <dpsclient/wraps.h>
  39. #import <dpsclient/dpsNeXT.h>
  40. #import <appkit/graphics.h>
  41. #import <objc/List.h>
  42. #import <objc/objc.h>
  43. #import <appkit/PopUpList.h>
  44. #import <apps/InterfaceBuilder.h>
  45.  
  46.  
  47. @implementation SwapView
  48.  
  49. //*****************************************************************************
  50. //
  51. //         attach popup to popUpList 
  52. //
  53. //        popUpCover must be attached to the trigger Button of a popUpList in IB
  54. //
  55. //*****************************************************************************
  56.  
  57. - initPopUp
  58. {
  59.     if(popUpCover)        // if popUpCover s/b hooked to a trigger button in IB
  60.         popup = [popUpCover target];    // popup should point to its popUpList
  61.     [popup setTarget:self];
  62.     [popup setAction:@selector(popUpAction:)];
  63.  
  64.     return self;
  65. }
  66. //*****************************************************************************
  67. //
  68. //         designated initilizer for swapviews
  69. //
  70. //*****************************************************************************
  71.  
  72. - initFrame:(NXRect *)theFrame
  73. {
  74. char title[] = {"FirstInspector"};
  75.  
  76.     [super initFrame:theFrame];
  77.     
  78.     lastInspector = NULL;
  79.     currentInspector = NULL;
  80.     backgroundGray = NX_LTGRAY;
  81.     theTitle = title;    
  82.     [self setBackgroundGray:NX_LTGRAY];        // default
  83.  
  84.     return self;
  85. }
  86. //*****************************************************************************
  87. //
  88. //         swaps views in and out of inspector's swapview
  89. //
  90. //*****************************************************************************
  91.  
  92. - swapIt
  93. {
  94.     if([self whatPanel])            
  95.         {                            // make sure this is a new view to swap in
  96.         if(lastInspector != inspector)        
  97.             {                                         
  98.             if(lastInspector)                        // swap 
  99.                 [self replaceSubview:[lastInspector contentView] 
  100.                                                 with:[inspector contentView]];
  101.             else
  102.                 [self addSubview:[inspector contentView]];
  103.             [self display];
  104.             lastInspector = inspector;        // remember the panel it came from     
  105.             }
  106.         }
  107.     else
  108.         {                            // no inspector so clean up the background
  109.         [self lockFocus];
  110.         PSsetgray(backgroundGray);            // use the backgroundGray
  111.         NXRectFill(&bounds);
  112.         [self unlockFocus];
  113.         lastInspector = (id)NULL;            // now the last inspector is NULL 
  114.         NXPing();                // let the window server cetch up... (yawn...)
  115.         }                            
  116.  
  117.     return self;
  118. }
  119. //*****************************************************************************
  120. //
  121. //         This should return the id of a panel, which is off screen, and 
  122. //        buffered, but not defered (SwapView needs its gstate).  SwapView will 
  123. //        take the contentView of the panel and swap it in while also removing 
  124. //        the old view, if any, and placing it back into its old panel.
  125. //
  126. //     WARNING!!!!
  127. //    Don't forget to make sure that the off screen windows are NOT deferred!!!
  128. //    This means make sure that you turn the Deffered switch OFF in IB when
  129. //    looking at the Atributes inspector.  This allows offscreen drawing.  
  130. //    If it was on, then the gstate will be zero!!!!
  131. //
  132. //         Ideally::  these panels should all be nibs so they have controllers
  133. //                   and the above code should load the nib section if it
  134. //                   already isn't loaded.  It should load here because you only
  135. //                   want to take up memory when it is demanded. 
  136. //
  137. //*****************************************************************************
  138.  
  139. - whatPanel
  140. {
  141.     if(theTitle)         // find out what panel to give to the SwapView
  142.         {
  143.         if (!strcmp(theTitle,"FirstInspector"))            // for use by swapViews
  144.             return inspector = firstInspectorPanel;        // w/o a popUpList
  145.         
  146.         if (!strcmp(theTitle,"SecondInspector"))        // for use by swapViews
  147.             return inspector = secondInspectorPanel;    // w/o a popUpList
  148.  
  149.         switch([popup indexOfItem:theTitle])
  150.             {
  151.             case 0:
  152.             default:
  153.                 inspector = firstInspectorPanel;
  154.                 break;
  155.                 
  156.             case 1:                  
  157.                 inspector = secondInspectorPanel;
  158.                 break;
  159.  
  160.             case 2:                  
  161.                 inspector = thirdInspectorPanel;
  162.                 break;
  163.  
  164.             case 3:                  
  165.                 inspector = fourthInspectorPanel;
  166.                 break;
  167.  
  168.             case 4: 
  169.                 inspector = fifthInspectorPanel;
  170.                 break;
  171.  
  172.             case 5: 
  173.                 inspector = sixthInspectorPanel;
  174.                 break;
  175.             }
  176.         return inspector;
  177.         }
  178.                                 // the button title has no related inspector, 
  179.     return (id)NULL;            // this should never happen.    
  180. }
  181. //*****************************************************************************
  182. //
  183. //         this is to allow us to junp to any inspector given its key name 
  184. //
  185. //*****************************************************************************
  186.  
  187. - inspectName:(const char *)str
  188. {
  189.     if (str) 
  190.         theTitle = str; 
  191.     [self swapIt];
  192.     
  193.     return self;
  194. }
  195. //*****************************************************************************
  196. //
  197. //         target of pop up list button 
  198. //
  199. //*****************************************************************************
  200.  
  201. - popUpAction:sender
  202. {
  203.             // set up a pointer to the selectedCell of the matrix 
  204.     theTitle = [[sender selectedCell] title];
  205.     [self swapIt];                                         // swap out the view
  206.  
  207.     return self;
  208. }
  209. - currentInspector
  210. {
  211.     return currentInspector;
  212. }
  213.  
  214. - lastInspector
  215. {
  216.     return lastInspector;
  217. }
  218.  
  219. - (float)backgroundGray
  220.     return backgroundGray; 
  221. }
  222.  
  223. - setBackgroundGray:(float)aGray
  224. {
  225.     backgroundGray = aGray;
  226.     return self;
  227. }
  228.  
  229. - free
  230. {
  231.     return [super free];
  232. }
  233.  
  234. @end
  235.  
  236.