home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / Database / OTC_EOFBetaExamples_V1.0 / EOFramework / EOModelInspector / EOModelBrowserCell.m < prev    next >
Encoding:
Text File  |  1994-07-31  |  4.9 KB  |  230 lines

  1. /*--------------------------------------------------------------------------
  2.  *
  3.  *     You may freely copy, distribute, and reuse the code in this example.
  4.  *     SHL Systemhouse disclaims any warranty of any kind, expressed or
  5.  *    implied, as to its fitness for any particular use.
  6.  *
  7.  *
  8.  *    EOModelBrowserCell
  9.  *
  10.  *    Inherits From:        NXBrowserCell
  11.  *
  12.  *    Conforms To:        None
  13.  *
  14.  *    Declared In:        EOModelBrowserCell.h
  15.  *
  16.  *------------------------------------------------------------------------*/
  17.  
  18. #import "EOModelBrowserCell.h"
  19.  
  20.  
  21. #define IMAGEMARGIN        4.0
  22.  
  23.  
  24. @implementation EOModelBrowserCell
  25.  
  26. /*--------------------------------------------------------------------------
  27.  *    Initialization
  28.  *------------------------------------------------------------------------*/
  29.  
  30. - initTextCell: (const char *) aString
  31. {
  32.     [super initTextCell:aString];
  33.     [self setTextColor:NX_COLORBLACK];
  34.     isRelationship = NO;
  35.     isToManyRelationship = NO;
  36.     return self;
  37. }
  38.  
  39.  
  40.  
  41. /*--------------------------------------------------------------------------
  42.  *    Drawing
  43.  *------------------------------------------------------------------------*/
  44.  
  45. - drawInside: (const NXRect *) cellFrame
  46.     inView: controlView;
  47. {
  48.     /*
  49.      * every CustomCell needs these
  50.      */
  51.     static id
  52.         arrowImage = nil,
  53.         doubleArrowImage = nil,
  54.         sharedTextCell = nil;
  55.     id
  56.         theImage = nil;
  57.     NXRect
  58.         rect = *cellFrame;
  59.     NXPoint
  60.         imageOrigin;
  61.     NXSize
  62.         imageSize;
  63.  
  64.     if (arrowImage == nil)
  65.         {
  66.         char
  67.             myPath[MAXPATHLEN+1];
  68.             
  69.         [[NXBundle bundleForClass:[self class]] getPath:myPath forResource:"arrow" ofType:"tiff"];
  70.         arrowImage = [[NXImage alloc] initFromFile:myPath];
  71.         }
  72.         
  73.     if (doubleArrowImage == nil)
  74.         {
  75.         char
  76.             myPath[MAXPATHLEN+1];
  77.             
  78.         [[NXBundle bundleForClass:[self class]] getPath:myPath forResource:"double_arrow" ofType:"tiff"];
  79.         doubleArrowImage = [[NXImage alloc] initFromFile:myPath];
  80.         }
  81.  
  82.     /*
  83.      * erase the cell
  84.      */
  85.     PSsetgray ((cFlags1.state || cFlags1.highlighted) ? NX_WHITE : NX_LTGRAY);
  86.     NXRectFill (cellFrame);
  87.  
  88.     /*
  89.      * draw the right image
  90.      */
  91.     if (([self isLeaf] == NO) || isRelationship)
  92.         {
  93.         theImage = arrowImage;
  94.  
  95.         if (isToManyRelationship)
  96.             {
  97.             theImage = doubleArrowImage;
  98.             }
  99.         
  100.         [theImage getSize:&imageSize];
  101.         imageOrigin.x = NX_X (cellFrame) + NX_WIDTH (cellFrame) - IMAGEMARGIN - imageSize.width;
  102.         imageOrigin.y = NX_Y (cellFrame) + NX_HEIGHT (cellFrame) - (NX_HEIGHT(cellFrame) - imageSize.height) / 2.0;
  103.         [theImage composite:NX_SOVER toPoint:&imageOrigin];
  104.         NX_WIDTH (&rect) -= (imageSize.width + IMAGEMARGIN * 2.0 - NX_X (&rect));
  105.         }
  106.     
  107.     if (sharedTextCell == nil)
  108.         {
  109.         sharedTextCell = [[Cell alloc] init];
  110.         [sharedTextCell setWrap:NO];
  111.         }
  112.     
  113.     [sharedTextCell setFont:[self font]];
  114.     [sharedTextCell setStringValue:[self stringValue]];
  115.     [sharedTextCell setEnabled:[self isEnabled]];
  116.     [sharedTextCell drawInside:&rect inView:controlView];
  117.     
  118.     /*
  119.      * all drawing from now on will be in dark gray
  120.      */
  121.     PSsetgray (NX_DKGRAY);
  122.     
  123.     /*
  124.      * draw the two dark gray lines above and below the cell
  125.      */
  126.     if (cFlags1.state || cFlags1.highlighted)
  127.         {
  128.         NXRect
  129.             rectArray[2];
  130.         
  131.         /*
  132.          * draw 1-pixel tall rectangles instead of lines (this is faster than
  133.          * PSmoveto(); PSlineto()).
  134.          */
  135.         NXSetRect (&(rectArray[0]), NX_X (cellFrame), NX_Y (cellFrame), NX_WIDTH (cellFrame), 1.0);
  136.         NXSetRect (&(rectArray[1]), NX_X (cellFrame), NX_MAXY (cellFrame) - 1.0, NX_WIDTH(cellFrame), 1.0);
  137.         
  138.         /*
  139.          * using NXRectFillList is faster than separate calls to NXRectFill
  140.          */
  141.         NXRectFillList (rectArray, 2);
  142.         }
  143.  
  144.     return self;
  145. }
  146.  
  147.  
  148. - highlight: (const NXRect *) cellFrame
  149.     inView: controlView
  150.     lit: (BOOL) flag
  151. {
  152.     if (cFlags1.highlighted != flag)
  153.         {
  154.         cFlags1.highlighted = flag;
  155.         [self drawInside:cellFrame inView:controlView];
  156.         }
  157.     
  158.     return self;
  159. }
  160.  
  161.  
  162.  
  163. /*--------------------------------------------------------------------------
  164.  *    Accessors
  165.  *------------------------------------------------------------------------*/
  166.  
  167. - (NXColor) textColor
  168. {
  169.     return textColor;
  170. }
  171.  
  172.  
  173. - setTextColor: (NXColor) aColor
  174. {
  175.     textColor = aColor;
  176.     return self;
  177. }
  178.  
  179.  
  180. - setTag: (int) theTag
  181. {
  182.     tag = theTag;
  183.     return self;
  184. }
  185.  
  186.  
  187. - (int) tag
  188. {
  189.     return tag;
  190. }
  191.  
  192.  
  193.  
  194. /*--------------------------------------------------------------------------
  195.  *    Setting Relationship Degree
  196.  *------------------------------------------------------------------------*/
  197.  
  198. - setIsRelationship: (BOOL) flag
  199. {
  200.     isRelationship = flag;
  201.     return self;
  202. }
  203.  
  204.  
  205. - setIsToManyRelationship: (BOOL) flag
  206. {
  207.     isToManyRelationship = flag;
  208.     return self;
  209. }
  210.  
  211.  
  212.  
  213. /*--------------------------------------------------------------------------
  214.  *    Setting Text Attributes
  215.  *------------------------------------------------------------------------*/
  216.  
  217. - setTextAttributes: aTextObject
  218. {
  219.     //  This method is called during every drawInside: inView call.
  220.     //  It asks for the current Text object.  This determines how the 
  221.     //  Cell's text will be displayed.  Subclasses of Cell override 
  222.     //  this method to get unique characteristics. 
  223.     
  224.     [super setTextAttributes:aTextObject];
  225.     [aTextObject setTextColor:textColor];
  226.     return aTextObject;
  227. }    
  228.  
  229. @end
  230.