home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Source / MiscSwapKit / MiscSwapViewByPopUp.m < prev   
Encoding:
Text File  |  1994-03-08  |  2.8 KB  |  110 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:     24.02.1994
  12.  */
  13.  
  14. #import <misckit/misckit.h>
  15.  
  16. @implementation MiscSwapViewByPopUp
  17.  
  18. - setPopUpCover:anObject
  19. {
  20.     // Because it is not possible to set the popUpMenus actionMethod inside
  21.     // IB we have to do it here. But who cares. It's nicer this way anyway.
  22.     // By default there is no selectedCell inside the popUp. We will change
  23.     // that.
  24.     
  25.     int    index;
  26.     id    popUp;
  27.     id    matrix;
  28.     
  29.     popUpCover = anObject;
  30.     popUp = [popUpCover target];
  31.     [popUp setTarget:self];
  32.     [popUp setAction:@selector(swapContentView:)];
  33.     index = [popUp indexOfItem:[popUpCover title]];
  34.     
  35.     if( index > -1 )
  36.     {    
  37.         matrix = [popUp itemList];
  38.         
  39.          if( ![matrix selectedCell] )
  40.             [matrix selectCell:[[matrix cellList] objectAt:index]];
  41.     }
  42.     return self;
  43. }
  44.  
  45. - popUpCover
  46. {
  47.     return popUpCover;
  48. }
  49.  
  50. - swapContentView:sender
  51. {
  52.     // We find the right popUp item and if really have one we can simply set 
  53.     // the trigger to the right object and use the simple ..byTag/obj methods
  54.     // provided by our super-class. 
  55.     
  56.     id    aPopUpItem;
  57.  
  58.     aPopUpItem = [self realTrigger];
  59.     if( aPopUpItem ) sender = aPopUpItem;
  60.     
  61.     return [super swapContentView:sender];
  62. }
  63.  
  64. - realTrigger
  65. {
  66.     // Here we try to find the currently selected popUpItem. This is the
  67.     // real trigger of a action.
  68.     // We assume that there always is a selected cell. If this object is used
  69.     // properly this is true because setPopUpCover causes such a init!
  70.     
  71.     id    realTrigger;
  72.     id    popUpMatrix;
  73.     
  74.     popUpMatrix = [[popUpCover target] itemList];
  75.     realTrigger = [popUpMatrix selectedCell];
  76.     
  77.     // Being envoked by keyboard causes the right popUp item to be
  78.     // selected but does not change the covers title. This is what we do
  79.     // here. Maybe not always needed but who cares.
  80.     
  81.     [popUpCover setTitle:[realTrigger title]];
  82.     
  83.     return realTrigger;    
  84. }
  85.  
  86. @end
  87.  
  88. /*
  89.  * History: 24.02.94 Conform to new swapView methods.
  90.  *
  91.  *            25.01.95 Move the popUp init (selectedCell) to setPopUpCover
  92.  *
  93.  *            24.01.94 Made it MiscSwap conform.
  94.  *
  95.  *            08.01.94 Renamed it to swapPopUpController and did some real
  96.  *                     nice redesign.
  97.  *
  98.  *            20.12.93 Enlightened the controller to check the tags if they are
  99.  *                     set. This helps to localize apps.
  100.  *
  101.  *            04.12.93 Added a delegate to this class the enable better 
  102.  *                     command-key handling.
  103.  *
  104.  *            04.11.93 First steps to a general-purpose swapPopManager.
  105.  *
  106.  *
  107.  * Bugs: - does only handle real popUps. PullDowns might not realy work 
  108.  *           because I always set the title inside the trigger method. Hmm
  109.  *           Maybe its better to write a seperate pullDown Controller!
  110.  */