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

  1. // MODateTextCellInspector.m
  2. //
  3. // by Mike Ferris
  4. // Part of MOKit - MORegexPalette
  5. // Copyright 1993, all rights reserved.
  6.  
  7. #import "MODateTextCellInspector.h"
  8. #import "MOKit/MODateTextCell.h"
  9. #import "MOKit/MOString.h"
  10. #import <objc/objc-runtime.h>
  11.  
  12. #define CLASS_VERSION    0
  13.  
  14. #define BG_NONE_TAG        0
  15. #define BG_BLACK_TAG    1
  16. #define BG_DKGRAY_TAG    2
  17. #define BG_LTGRAY_TAG    3
  18. #define BG_WHITE_TAG    4
  19.  
  20. #define TG_BLACK_TAG    0
  21. #define TG_DKGRAY_TAG    1
  22. #define TG_LTGRAY_TAG    2
  23. #define TG_WHITE_TAG    3
  24.  
  25. #define ALIGN_LEFT_TAG        0
  26. #define ALIGN_CENTER_TAG    1
  27. #define ALIGN_RIGHT_TAG        2
  28.  
  29. #define BORDER_NONE_TAG        0
  30. #define BORDER_LINE_TAG        1
  31. #define BORDER_BEZEL_TAG    2
  32.  
  33. #define EDITABLE_CB_TAG        0
  34. #define SELECTABLE_CB_TAG    1
  35. #define SCROLLABLE_CB_TAG    2
  36.  
  37. #define BUNDLE_TYPE                            "bundle"
  38. #define MODATETEXTCELL_CLASS_NAME            "MODateTextCell"
  39.  
  40. #define NIB_TYPE                            "nib"
  41. #define NIB_NAME                            "MODateTextCellInspector"
  42.  
  43. #define AMERICAN_TAG        0
  44. #define EUROPEAN_TAG        1
  45.  
  46. @implementation MODateTextCellInspector
  47.  
  48. static id MODateTextCellClass;
  49.  
  50. + MO_loadClassBundle:(const char *)className
  51. // Finds the bundle of the same name as the class, grabs it and loads the
  52. // class from it.
  53. {
  54.     char pathBuff[MAXPATHLEN+1];
  55.     
  56.     // Load the bundle
  57.     if (objc_lookUpClass(className) == nil)  {
  58.         // class is not already loaded... load it.
  59.         id classBundle;
  60.         
  61.         // Look for the bundle in the main bundle first, 
  62.         // else try in this classes bundle.
  63.         if (![[NXBundle mainBundle] getPath:pathBuff forResource:className 
  64.                     ofType:BUNDLE_TYPE])  {
  65.             if (![[NXBundle bundleForClass:[self class]] getPath:pathBuff 
  66.                         forResource:className ofType:BUNDLE_TYPE])  {
  67.                 NXLogError("[MORegexPalette loadClassBundle] failed to "
  68.                         "find %s class bundle.", className);
  69.                 return nil;
  70.             }
  71.         }
  72.         classBundle = [[NXBundle allocFromZone:[self zone]] 
  73.                     initForDirectory:pathBuff];
  74.         if (!classBundle)  {
  75.             NXLogError("[MORegexPalette loadClassBundle] failed to "
  76.                         "create bundle for class %s.", className);
  77.             return nil;
  78.         }
  79.         if (![classBundle classNamed:className])  {
  80.             NXLogError("[MORegexPalette loadClassBundle] failed to "
  81.                         "load %s class from bundle.", className);
  82.             return nil;
  83.         }
  84.     }
  85.     
  86.     return self;
  87. }
  88.  
  89. + initialize
  90. // Set the version.
  91. {
  92.     if (self == [MODateTextCellInspector class])  {
  93.         [self setVersion:CLASS_VERSION];
  94.  
  95.         // Load the MODateTextCell class if necessary
  96.         if ((MODateTextCellClass = 
  97.                     objc_lookUpClass(MODATETEXTCELL_CLASS_NAME)) == nil)  {
  98.             [self MO_loadClassBundle:MODATETEXTCELL_CLASS_NAME];
  99.             MODateTextCellClass = 
  100.                         objc_lookUpClass(MODATETEXTCELL_CLASS_NAME);
  101.             if (!MODateTextCellClass)  {
  102.                 NXLogError("[MODateTextCellInspector initialize]: "
  103.                             "failed to find MODateTextCell class.");
  104.             }
  105.         }
  106.     }
  107.     return self;
  108. }
  109.  
  110. - init
  111. // Load our nib file.
  112. {
  113.     char buf[MAXPATHLEN+1];
  114.     id bundle;
  115.     
  116.     [super init];
  117.     
  118.     // load our nib file.
  119.     bundle = [NXBundle bundleForClass:[MODateTextCellInspector class]];
  120.     [bundle getPath:buf forResource:NIB_NAME ofType:NIB_TYPE];
  121.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  122.     
  123.     return self;
  124. }
  125.  
  126. - optionsCheckboxAction:sender
  127. {
  128.     id selCell = [sender selectedCell];
  129.     int selTag = [selCell tag];
  130.     
  131.     if (selTag == EDITABLE_CB_TAG)  {
  132.         id selectableCB = [optionsCheckboxMatrix cellAt:SELECTABLE_CB_TAG:0];
  133.         if ([selCell state])  {
  134.             [selectableCB setState:YES];
  135.             [selectableCB setEnabled:NO];
  136.         }  else  {
  137.             [selectableCB setEnabled:YES];
  138.         }
  139.     }
  140.     [optionsCheckboxMatrix display];
  141.     if ([[optionsCheckboxMatrix cellAt:EDITABLE_CB_TAG:0] state])  {
  142.         [object setEditable:YES];
  143.     }  else  {
  144.         [object setEditable:NO];
  145.         if ([[optionsCheckboxMatrix cellAt:SELECTABLE_CB_TAG:0] state])  {
  146.             [object setSelectable:YES];
  147.         }  else  {
  148.             [object setSelectable:NO];
  149.         }
  150.     }
  151.     [object setScrollable:[[optionsCheckboxMatrix 
  152.                 cellAt:0:SCROLLABLE_CB_TAG] state]];
  153.     return self;
  154. }
  155.  
  156. - ok:sender
  157. // set the text field-ish stuff and the allowEmptyString attribute.  
  158. // The patternButtonAction takes care of the regex stuff.  The 
  159. // optionCheckboxAction takes care of editable, selectable, scrollable.
  160. {
  161.     int bgTag = [backgroundGrayMatrix selectedTag];
  162.     int tgTag = [textGrayMatrix selectedTag];
  163.     int alTag = [alignmentMatrix selectedTag];
  164.     int boTag = [borderMatrix selectedTag];
  165.     
  166.     if (bgTag == BG_NONE_TAG)  {
  167.         [object setBackgroundGray:-1.0];
  168.     }  else if (bgTag == BG_BLACK_TAG)  {
  169.         [object setBackgroundGray:NX_BLACK];
  170.     }  else if (bgTag == BG_DKGRAY_TAG)  {
  171.         [object setBackgroundGray:NX_DKGRAY];
  172.     }  else if (bgTag == BG_LTGRAY_TAG)  {
  173.         [object setBackgroundGray:NX_LTGRAY];
  174.     }  else  {
  175.         [object setBackgroundGray:NX_WHITE];
  176.     }
  177.     if (tgTag == TG_BLACK_TAG)  {
  178.         [object setTextGray:NX_BLACK];
  179.     }  else if (tgTag == TG_DKGRAY_TAG)  {
  180.         [object setTextGray:NX_DKGRAY];
  181.     }  else if (tgTag == TG_LTGRAY_TAG)  {
  182.         [object setTextGray:NX_LTGRAY];
  183.     }  else  {
  184.         [object setTextGray:NX_WHITE];
  185.     }
  186.     if (alTag == ALIGN_LEFT_TAG)  {
  187.         [object setAlignment:NX_LEFTALIGNED];
  188.     }  else if (alTag == ALIGN_CENTER_TAG)  {
  189.         [object setAlignment:NX_CENTERED];
  190.     }  else  {
  191.         [object setAlignment:NX_RIGHTALIGNED];
  192.     }
  193.     if (boTag == BORDER_NONE_TAG)  {
  194.         [object setBordered:NO];
  195.         [object setBezeled:NO];
  196.     }  else if (boTag == BORDER_LINE_TAG)  {
  197.         [object setBordered:YES];
  198.     }  else  {
  199.         [object setBezeled:YES];
  200.     }
  201.  
  202.     [object setTag:[tagForm intValueAt:0]];
  203.     [object setAllowEmptyString:[allowEmptyStringButton state]];
  204.     [object setEuropeanStyle:[styleRadioMatrix selectedTag]];
  205.     [object setFormatDates:[formatCheckbox state]];
  206.     [object setFormatString:[formatForm stringValueAt:0]];
  207.     return [super ok:sender];
  208. }
  209.  
  210. - revert:sender
  211. // fill in the inspector with the attributes of "object"
  212. {
  213.     float bg = [object backgroundGray], tg = [object textGray];
  214.     int alignment = [object alignment];
  215.     BOOL isBordered = [object isBordered], isBezeled = [object isBezeled];
  216.     
  217.     if (bg < 0)  {
  218.         [backgroundGrayMatrix selectCellAt:0:BG_NONE_TAG];
  219.     }  else  if ((bg >= 0) && (bg < .2))  {
  220.         [backgroundGrayMatrix selectCellAt:0:BG_BLACK_TAG];
  221.     }  else  if ((bg >= .2) && (bg < .45))  {
  222.         [backgroundGrayMatrix selectCellAt:0:BG_DKGRAY_TAG];
  223.     }  else  if ((bg >= .45) && (bg < .8))  {
  224.         [backgroundGrayMatrix selectCellAt:0:BG_LTGRAY_TAG];
  225.     }  else  if (bg >= .8)  {
  226.         [backgroundGrayMatrix selectCellAt:0:BG_WHITE_TAG];
  227.     }
  228.     [backgroundGrayMatrix display];
  229.     if (tg < .2)  {
  230.         [textGrayMatrix selectCellAt:0:TG_BLACK_TAG];
  231.     }  else  if ((tg >= .2) && (tg < .45))  {
  232.         [textGrayMatrix selectCellAt:0:TG_DKGRAY_TAG];
  233.     }  else  if ((tg >= .45) && (tg < .8))  {
  234.         [textGrayMatrix selectCellAt:0:TG_LTGRAY_TAG];
  235.     }  else  if (tg >= .8)  {
  236.         [textGrayMatrix selectCellAt:0:TG_WHITE_TAG];
  237.     }
  238.     [textGrayMatrix display];
  239.     if (alignment == NX_LEFTALIGNED)  {
  240.         [alignmentMatrix selectCellAt:0:ALIGN_LEFT_TAG];
  241.     }  else if (alignment == NX_CENTERED)  {
  242.         [alignmentMatrix selectCellAt:0:ALIGN_CENTER_TAG];
  243.     }  else  {
  244.         [alignmentMatrix selectCellAt:0:ALIGN_RIGHT_TAG];
  245.     }
  246.     [alignmentMatrix display];
  247.     if (isBezeled)  {
  248.         [borderMatrix selectCellAt:0:BORDER_BEZEL_TAG];
  249.     }  else if (isBordered)  {
  250.         [borderMatrix selectCellAt:0:BORDER_LINE_TAG];
  251.     }  else  {
  252.         [borderMatrix selectCellAt:0:BORDER_NONE_TAG];
  253.     }
  254.     [optionsCheckboxMatrix setState:[object isEditable] 
  255.                 at:EDITABLE_CB_TAG:0];
  256.     [optionsCheckboxMatrix setState:[object isSelectable] 
  257.                 at:SELECTABLE_CB_TAG:0];
  258.     [optionsCheckboxMatrix setState:[object isScrollable] 
  259.                 at:SCROLLABLE_CB_TAG:0];
  260.  
  261.     [allowEmptyStringButton setState:[object doesAllowEmptyString]];
  262.     [tagForm setIntValue:[object tag] at:0];
  263.     
  264.     if ([object isEuropeanStyle])  {
  265.         [styleRadioMatrix selectCellWithTag:EUROPEAN_TAG];
  266.     }  else  {
  267.         [styleRadioMatrix selectCellWithTag:AMERICAN_TAG];
  268.     }
  269.     
  270.     [formatCheckbox setState:[object doesFormatDates]];
  271.     [formatForm setStringValue:[object formatString] at:0];
  272.     
  273.     return [super revert:sender];
  274. }
  275.  
  276. - (BOOL)wantsButtons
  277. // Our inspector does not have OK or Revert buttons.
  278. {
  279.     return NO;
  280. }
  281.  
  282. @end
  283.