home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / Utilities / Unix / aa_m68k_Intel_Only / UNIX-HatersTool.0.1 / Source / MiscSwapKit.subproj / MiscSwapViewByPopUp.m < prev    next >
Encoding:
Text File  |  1994-09-25  |  4.1 KB  |  166 lines

  1. /* MiscSwapViewByPopUp.m                 
  2.  *
  3.  * This is a SwapView that can handle popUps either by tag or by title.
  4.  * If a tag is not 0 it will try to choose the viewController by title.
  5.  *
  6.  * For more interface-info see the header file. More in depth information
  7.  * can be found here in the source-code.
  8.  *
  9.  * Written by:         Thomas Engel
  10.  * Created:            24.01.1994 (Copyleft)
  11.  * Last modified:     25.09.1994
  12.  */
  13.  
  14. //#import <misckit/misckit.h>
  15. #import "MiscSwapViewByPopUp.h"
  16.  
  17. // The following are for keeping track of versions when archiving instances
  18. // of MiscSwapViewByPopUp. If you change the write: method, make sure to
  19. // bump up the version below and make the appropriate changes to the read:
  20. // method so all previously archived instances will be unarchivable.
  21.  
  22. #define MISC_SVBP_VERSION 0
  23. #define MISC_SVBP_CLASSNAME "MiscSwapViewByPopUp"
  24.  
  25.  
  26. @implementation MiscSwapViewByPopUp
  27.  
  28. + initialize 
  29. {
  30.     // Sets the class version for archiving purposes.
  31.     
  32.     if (self == [MiscSwapViewByPopUp class])
  33.         [self setVersion: MISC_SVBP_VERSION];
  34.     
  35.     return self;
  36. }
  37.  
  38. - setPopUpCover:anObject
  39. {
  40.     // Because it is not possible to set the popUpMenus actionMethod inside
  41.     // IB we have to do it here. But who cares. It's nicer this way anyway.
  42.     // By default there is no selectedCell inside the popUp. We will change
  43.     // that.
  44.     
  45.     int    index;
  46.     id    popUp;
  47.     id    matrix;
  48.     
  49.     popUpCover = anObject;
  50.     popUp = [popUpCover target];
  51.     [popUp setTarget:self];
  52.     [popUp setAction:@selector(swapContentView:)];
  53.     index = [popUp indexOfItem:[popUpCover title]];
  54.     
  55.     if( index > -1 )
  56.     {    
  57.         matrix = [popUp itemList];
  58.         
  59.          if( ![matrix selectedCell] )
  60.             [matrix selectCell:[[matrix cellList] objectAt:index]];
  61.     }
  62.     return self;
  63. }
  64.  
  65. - popUpCover
  66. {
  67.     return popUpCover;
  68. }
  69.  
  70. - swapContentView:sender
  71. {
  72.     // We find the right popUp item and if really have one we can simply set 
  73.     // the trigger to the right object and use the simple ..byTag/obj methods
  74.     // provided by our super-class. 
  75.     
  76.     id    aPopUpItem;
  77.  
  78.     aPopUpItem = [self realTrigger];
  79.     if( aPopUpItem ) sender = aPopUpItem;
  80.     
  81.     return [super swapContentView:sender];
  82. }
  83.  
  84. - realTrigger
  85. {
  86.     // Here we try to find the currently selected popUpItem. This is the
  87.     // real trigger of a action.
  88.     // We assume that there always is a selected cell. If this object is used
  89.     // properly this is true because setPopUpCover causes such a init!
  90.     
  91.     id    realTrigger;
  92.     id    popUpMatrix;
  93.     
  94.     popUpMatrix = [[popUpCover target] itemList];
  95.     realTrigger = [popUpMatrix selectedCell];
  96.     
  97.     // Being envoked by keyboard causes the right popUp item to be
  98.     // selected but does not change the covers title. This is what we do
  99.     // here. Maybe not always needed but who cares.
  100.     
  101.     [popUpCover setTitle:[realTrigger title]];
  102.     
  103.     return realTrigger;    
  104. }
  105.  
  106. - read: (NXTypedStream *)stream
  107. {
  108.   int  version;
  109.   
  110.     [super read: stream];
  111.  
  112.     // If you add or remove archived variables, you'll have to
  113.     // change this method so it will be able to read all previous
  114.     // versions. Just add a case for your new version and leave
  115.     // the rest of the switch statement alone.
  116.      
  117.     version = NXTypedStreamClassVersion (stream, MISC_SVBP_CLASSNAME);
  118.     
  119.     switch (version)
  120.     {
  121.       case 0:
  122.           popUpCover = NXReadObject (stream);
  123.           break;
  124.         
  125.       default:
  126.           break;
  127.     }
  128.             
  129.     return self;
  130. }
  131.  
  132. - write: (NXTypedStream *)stream
  133. {
  134.     [super write: stream];
  135.     NXWriteObjectReference (stream, popUpCover);
  136.  
  137.     return self;
  138. }
  139.  
  140. @end
  141.  
  142. /*
  143.  * History: 25.09.94 Added archiving (read:, write:, +initialize)
  144.  *
  145.  *            24.02.94 Conform to new swapView methods.
  146.  *
  147.  *            25.01.95 Move the popUp init (selectedCell) to setPopUpCover
  148.  *
  149.  *            24.01.94 Made it MiscSwap conform.
  150.  *
  151.  *            08.01.94 Renamed it to swapPopUpController and did some real
  152.  *                     nice redesign.
  153.  *
  154.  *            20.12.93 Enlightened the controller to check the tags if they are
  155.  *                     set. This helps to localize apps.
  156.  *
  157.  *            04.12.93 Added a delegate to this class the enable better 
  158.  *                     command-key handling.
  159.  *
  160.  *            04.11.93 First steps to a general-purpose swapPopManager.
  161.  *
  162.  *
  163.  * Bugs: - does only handle real popUps. PullDowns might not realy work 
  164.  *           because I always set the title inside the trigger method. Hmm
  165.  *           Maybe its better to write a seperate pullDown Controller!
  166.  */