home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Kits / MiscTableScroll-138.1 / Palettes / MiscTableScroll / Framework / MiscTableConnector.M < prev    next >
Encoding:
Text File  |  1998-03-31  |  7.0 KB  |  191 lines

  1. //=============================================================================
  2. //
  3. //    Copyright (C) 1996-1997 by Paul S. McCarthy and Eric Sunshine.
  4. //        Written by Paul S. McCarthy and Eric Sunshine.
  5. //                All Rights Reserved.
  6. //
  7. //    This notice may not be removed from this source code.
  8. //
  9. //    This object is included in the MiscKit by permission from the authors
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "License.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //    
  14. //=============================================================================
  15. //-----------------------------------------------------------------------------
  16. // MiscTableConnector.M
  17. //
  18. //    A custom sublcass of the internal Interface Builder
  19. //    IBControlConnector class that works for doubleTarget / doubleAction.
  20. //
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. // $Id: MiscTableConnector.M,v 1.7 97/06/18 10:21:04 sunshine Exp $
  24. // $Log:    MiscTableConnector.M,v $
  25. //  Revision 1.7  97/06/18  10:21:04  sunshine
  26. //  v125.9: Worked around Objective-C++ compiler crash in OPENSTEP 4.2 for NT
  27. //  when sending message to 'super' from within a category in a permanent
  28. //  fashion.
  29. //  
  30. //  Revision 1.6  97/04/15  09:06:59  sunshine
  31. //  v0.125.8: Hacked around OPENSTEP 4.2 (prerelease) compiler bug.  Compiler
  32. //  crashes if a message is sent to 'super' from within a category.
  33. //  Temporarily moved affected code from MiscTableConnector.M to this file.
  34. //  
  35. //  Revision 1.5  97/03/23  05:46:54  sunshine
  36. //  v125.4: Ditched the computation of a setter function for an outlet (i.e.
  37. //  outlet='foo', construct '-setFoo:').  Now uses object_setInstanceVariable()
  38. //  exclusively.
  39. //-----------------------------------------------------------------------------
  40. #import    "MiscTableConnector.h"
  41. extern "Objective-C" {
  42. #import <objc/objc-class.h>
  43. Ivar object_setInstanceVariable( id, char const* name, void const* );
  44. }
  45.  
  46. int const MISC_CONN_VERSION_0    = 0;     // First NEXTSTEP 3.3 version.
  47. int const MISC_CONN_VERSION_1000 = 1000; // First OpenStep version (4.0 PR2)
  48. int const MISC_CONN_VERSION      = MISC_CONN_VERSION_1000;
  49.  
  50. @interface NSIBConnector(MiscTableConnector_42NT)
  51. // See *FIXME* OPENSTEP 4.2 for NT at bottom of file.
  52. - (id)initSource:(id)src destination:(id)dst label:(id)lbl;
  53. @end
  54.  
  55. @interface NSIBConnector(MiscTableConnector)
  56. - (NSString*) label;
  57. @end
  58. @implementation NSIBConnector(MiscTableConnector)
  59. - (NSString*) label { return label; }
  60. @end
  61.  
  62. //=============================================================================
  63. // IMPLEMENTATION
  64. //=============================================================================
  65. @implementation MiscTableConnector
  66.  
  67. //-----------------------------------------------------------------------------
  68. // +initialize
  69. //-----------------------------------------------------------------------------
  70. + (void)initialize
  71.     {
  72.     if (self == [MiscTableConnector class])
  73.     [self setVersion:MISC_CONN_VERSION];
  74.     }
  75.  
  76.  
  77. //-----------------------------------------------------------------------------
  78. // -dealloc
  79. //-----------------------------------------------------------------------------
  80. - (void)dealloc
  81.     {
  82.     [outletName release];
  83.     [actionName release];
  84.     [super dealloc];
  85.     }
  86.  
  87.  
  88. //-----------------------------------------------------------------------------
  89. // -readCStringWithCoder:
  90. //-----------------------------------------------------------------------------
  91. - (NSString*)readCStringWithCoder:(NSCoder*)decoder
  92.     {
  93.     NSString* ret = @"";
  94.     char* s = 0;
  95.     [decoder decodeValueOfObjCType:@encode(char*) at:&s];
  96.     if (s != 0)
  97.     {
  98.     ret = [NSString stringWithCString:s];
  99.     NSZoneFree( [decoder objectZone], s );
  100.     }
  101.     return ret;
  102.     }
  103.  
  104.  
  105. //-----------------------------------------------------------------------------
  106. // -initWithCoder_v0:
  107. //-----------------------------------------------------------------------------
  108. - (void)initWithCoder_v0:(NSCoder*)decoder
  109.     {
  110.     outletName = [[self readCStringWithCoder:decoder] retain];
  111.     actionName = [[self readCStringWithCoder:decoder] retain];
  112.     [self readCStringWithCoder:decoder]; // Duplicate "label" no longer needed.
  113.     }
  114.  
  115.  
  116. //-----------------------------------------------------------------------------
  117. // -initWithCoder_v1000:
  118. //-----------------------------------------------------------------------------
  119. - (void)initWithCoder_v1000:(NSCoder*)decoder
  120.     {
  121.     outletName = [[decoder decodeObject] retain];
  122.     actionName = [[decoder decodeObject] retain];
  123.     }
  124.  
  125.  
  126. //-----------------------------------------------------------------------------
  127. // -initWithCoder:
  128. //-----------------------------------------------------------------------------
  129. - (id)initWithCoder:(NSCoder*)decoder
  130.     {
  131.     [super initWithCoder:decoder];
  132.     unsigned int const ver = [decoder versionForClassName:
  133.                 [[MiscTableConnector class] description]];
  134.     switch (ver)
  135.     {
  136.     case MISC_CONN_VERSION_0:    [self initWithCoder_v0:   decoder]; break;
  137.     case MISC_CONN_VERSION_1000: [self initWithCoder_v1000:decoder]; break;
  138.     default:
  139.         [NSException raise:NSGenericException
  140.             format:@"Cannot read: unknown version %d", ver];
  141.         break;
  142.     }
  143.     return self;
  144.     }
  145.  
  146.  
  147. //-----------------------------------------------------------------------------
  148. // -setInstanceVariable:of:to:
  149. //-----------------------------------------------------------------------------
  150. - (void)setInstanceVariable:(NSString*)var of:(id)obj to:(id)val
  151.     {
  152.     if (var != 0 && [var length] > 0)
  153.     object_setInstanceVariable( obj, [var cString], val );
  154.     }
  155.  
  156.  
  157. //-----------------------------------------------------------------------------
  158. // -establishConnection
  159. //-----------------------------------------------------------------------------
  160. - (void)establishConnection
  161.     {
  162.     if (source != 0 && destination != 0 && [outletName length] > 0)
  163.     {
  164.     [self setInstanceVariable:outletName of:source to:destination];
  165.     if ([actionName length] > 0 && [[self label] length] > 0)
  166.         {
  167.         SEL aSel = NSSelectorFromString([self label]);
  168.         if (aSel != 0)
  169.         [self setInstanceVariable:actionName of:source to:(id)aSel];
  170.         }
  171.     } 
  172.     }
  173.  
  174.  
  175. //-----------------------------------------------------------------------------
  176. // *FIXME*
  177. //    OPENSTEP 4.2 Objective-C++ compiler for NT (final release) crashes 
  178. //    whenever a message is sent to 'super' from within a category.  This 
  179. //    bug also afflicts the 4.2 (prerelease) compiler for Mach and NT.  
  180. //    Work around it by providing stub methods in the main (non-category) 
  181. //    implementation which merely forward the appropriate message to 'super' 
  182. //    on behalf of the categories.  Though ugly, it works, is very 
  183. //    localized, and simple to remove when the bug is finally fixed.  
  184. //-----------------------------------------------------------------------------
  185. - (id)superInitSource:(id)s destination:(id)d label:(NSString*)l
  186.     { return [super initSource:s destination:d label:l]; }
  187. - (void)superEncodeWithCoder:(NSCoder*)c
  188.     { [super encodeWithCoder:c]; }
  189.  
  190. @end
  191.