home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / Palettes / MORegex / MODateFormCellInspector.m < prev    next >
Encoding:
Text File  |  1993-10-03  |  3.5 KB  |  140 lines

  1. // MODateFormCellInspector.h
  2. //
  3. // by Mike Ferris
  4. // Part of MOKit - MORegexPalette
  5. // Copyright 1993, all rights reserved.
  6.  
  7. #import "MODateFormCellInspector.h"
  8. #import "MOKit/MODateFormCell.h"
  9. #import "MOKit/MOString.h"
  10. #import <objc/objc-runtime.h>
  11.  
  12. #define CLASS_VERSION    0
  13.  
  14. #define BUNDLE_TYPE                            "bundle"
  15. #define MODATEFORMCELL_CLASS_NAME            "MODateFormCell"
  16.  
  17. #define NIB_TYPE                            "nib"
  18. #define NIB_NAME                            "MODateFormCellInspector"
  19.  
  20. #define AMERICAN_TAG        0
  21. #define EUROPEAN_TAG        1
  22.  
  23. @implementation MODateFormCellInspector
  24.  
  25. static id MODateFormCellClass;
  26.  
  27. + MO_loadClassBundle:(const char *)className
  28. // Finds the bundle of the same name as the class, grabs it and loads the
  29. // class from it.
  30. {
  31.     char pathBuff[MAXPATHLEN+1];
  32.     
  33.     // Load the bundle
  34.     if (objc_lookUpClass(className) == nil)  {
  35.         // class is not already loaded... load it.
  36.         id classBundle;
  37.         
  38.         // Look for the bundle in the main bundle first, 
  39.         // else try in this classes bundle.
  40.         if (![[NXBundle mainBundle] getPath:pathBuff forResource:className 
  41.                     ofType:BUNDLE_TYPE])  {
  42.             if (![[NXBundle bundleForClass:[self class]] getPath:pathBuff 
  43.                         forResource:className ofType:BUNDLE_TYPE])  {
  44.                 NXLogError("[MORegexPalette loadClassBundle] failed to "
  45.                         "find %s class bundle.", className);
  46.                 return nil;
  47.             }
  48.         }
  49.         classBundle = [[NXBundle allocFromZone:[self zone]] 
  50.                     initForDirectory:pathBuff];
  51.         if (!classBundle)  {
  52.             NXLogError("[MORegexPalette loadClassBundle] failed to "
  53.                         "create bundle for class %s.", className);
  54.             return nil;
  55.         }
  56.         if (![classBundle classNamed:className])  {
  57.             NXLogError("[MORegexPalette loadClassBundle] failed to "
  58.                         "load %s class from bundle.", className);
  59.             return nil;
  60.         }
  61.     }
  62.     
  63.     return self;
  64. }
  65.  
  66. + initialize
  67. // Set the version.
  68. {
  69.     if (self == [MODateFormCellInspector class])  {
  70.         [self setVersion:CLASS_VERSION];
  71.  
  72.         // Load the MODateFormCell class if necessary
  73.         [self MO_loadClassBundle:MODATEFORMCELL_CLASS_NAME];
  74.         MODateFormCellClass = 
  75.                     objc_lookUpClass(MODATEFORMCELL_CLASS_NAME);
  76.         if (!MODateFormCellClass)  {
  77.             NXLogError("[MODateFormCellInspector initialize]: failed to find "
  78.                         "MODateFormCell class.");
  79.         }
  80.     }
  81.     return self;
  82. }
  83.  
  84. - init
  85. // Load our nib file.
  86. {
  87.     char buf[MAXPATHLEN+1];
  88.     id bundle;
  89.     
  90.     [super init];
  91.     
  92.     // load our nib file.
  93.     bundle = [NXBundle bundleForClass:[MODateFormCellInspector class]];
  94.     [bundle getPath:buf forResource:NIB_NAME ofType:NIB_TYPE];
  95.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  96.     
  97.     return self;
  98. }
  99.  
  100. - ok:sender
  101. // set the tag and enabled flag.  The patternButtonAction takes care of the
  102. // other stuff.
  103. {
  104.     [object setTag:[tagForm intValueAt:0]];
  105.     [object setEnabled:![[checkboxMatrix cellAt:0:0] state]];
  106.     [object setAllowEmptyString:[[checkboxMatrix cellAt:1:0] state]];
  107.     [object setEuropeanStyle:[styleRadioMatrix selectedTag]];
  108.     [object setFormatDates:[formatCheckbox state]];
  109.     [object setFormatString:[formatForm stringValueAt:0]];
  110.     return [super ok:sender];
  111. }
  112.  
  113. - revert:sender
  114. // fill in the inspector with the attributes of "object"
  115. {
  116.     [checkboxMatrix setState:![object isEnabled] at:0:0];
  117.     [checkboxMatrix setState:[object doesAllowEmptyString] at:1:0];
  118.     [tagForm setIntValue:[object tag] at:0];
  119.     
  120.     if ([object isEuropeanStyle])  {
  121.         [styleRadioMatrix selectCellWithTag:EUROPEAN_TAG];
  122.     }  else  {
  123.         [styleRadioMatrix selectCellWithTag:AMERICAN_TAG];
  124.     }
  125.     
  126.     [formatCheckbox setState:[object doesFormatDates]];
  127.     [formatForm setStringValue:[object formatString] at:0];
  128.     
  129.     return [super revert:sender];
  130. }
  131.  
  132. - (BOOL)wantsButtons
  133. // Our inspector does not have OK or Revert buttons.
  134. {
  135.     return NO;
  136. }
  137.  
  138.  
  139. @end
  140.