home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Utilities / WindowDepth.bproj / MyNXBrowserCell.m < prev    next >
Encoding:
Text File  |  1997-11-10  |  5.5 KB  |  196 lines

  1.  
  2. #import "MyNXBrowserCell.h"
  3. #import "common.h"
  4.  
  5. #define FIRST_COLUMN_START 5.0
  6. #define SECOND_COLUMN_START 45.0
  7.  
  8. @implementation MyNXBrowserCell
  9.  
  10. static id     twoImage;
  11. static id    eightImage;
  12. static id     twelveImage;
  13. static id    twentyfourImage;
  14. static NXSize    imageSize;        // All assumed to be same size
  15.  
  16. /*=========================================================================
  17.  * NAME        : initTextCell:
  18.  * DESCRIPTION : Initialize a cell.
  19.  *=========================================================================*/
  20. - initTextCell:(const char *)aString
  21. {
  22.     id bundle = [NXBundle bundleForClass:[self class]];
  23.     char buf[MAXPATHLEN+1];
  24.     
  25.     [super initTextCell:aString];
  26.     
  27.     if (!twoImage) {
  28.         if ([bundle getPath:buf forResource:"2" ofType:"tiff"]) {
  29.             twoImage = [[NXImage alloc] initFromFile:buf];
  30.         }
  31.     [twoImage getSize:&imageSize];
  32.     }
  33.     if (!eightImage) {
  34.         if ([bundle getPath:buf forResource:"8" ofType:"tiff"]) {
  35.             eightImage = [[NXImage alloc] initFromFile:buf];
  36.         }
  37.     }
  38.     if (!twelveImage) {
  39.         if ([bundle getPath:buf forResource:"12" ofType:"tiff"]) {
  40.             twelveImage = [[NXImage alloc] initFromFile:buf];
  41.         }
  42.     }
  43.     if (!twentyfourImage) {
  44.         if ([bundle getPath:buf forResource:"24" ofType:"tiff"]) {
  45.             twentyfourImage = [[NXImage alloc] initFromFile:buf];
  46.         }
  47.     }
  48.     return self;
  49. }
  50.  
  51. /*=========================================================================
  52.  * NAME        : setTag:
  53.  * DESCRIPTION : Sets the cell's integer tag.
  54.  *=========================================================================*/
  55. - setTag:(int)aTag
  56. {
  57.     tag = aTag;
  58.     return self;
  59. }
  60.  
  61. /*=========================================================================
  62.  * NAME        : tag
  63.  * DESCRIPTION : Returns the cell's integer tag.
  64.  *=========================================================================*/
  65. - (int)tag
  66. {
  67.     return tag;
  68. }
  69.  
  70. /*=========================================================================
  71.  * NAME        : setOwner:
  72.  * DESCRIPTION : Set the owner attribute.
  73.  *=========================================================================*/
  74. - setOwner:(NXAtom)theOwner
  75. {
  76.     owner = theOwner;
  77.     return self;
  78. }
  79.  
  80. /*=========================================================================
  81.  * NAME        : owner
  82.  * DESCRIPTION : Return the owner attribute.
  83.  *=========================================================================*/
  84. - (NXAtom)owner
  85. {
  86.     return owner;
  87. }
  88.  
  89. /*=========================================================================
  90.  * NAME        : setDepth:
  91.  * DESCRIPTION : Set the WindowDepthLimit attribute.
  92.  *=========================================================================*/
  93. - setDepth:(int)theDepth;
  94. {
  95.     depth = theDepth;
  96.     switch (depth) {
  97.         case USE_2_BIT:
  98.         depthImage = twoImage;
  99.         break;
  100.     case USE_8_BIT:
  101.             depthImage = eightImage;
  102.         break;
  103.     case USE_12_BIT:
  104.             depthImage = twelveImage;
  105.         break;
  106.     case USE_24_BIT:
  107.         depthImage = twentyfourImage;
  108.         break;
  109.     default:
  110.         depthImage = nil;
  111.         break;
  112.     }
  113.     return self;
  114. }
  115.  
  116. /*=========================================================================
  117.  * NAME        : depth
  118.  * DESCRIPTION : Return the WindowDepthLimit.
  119.  *=========================================================================*/
  120. - (int)depth
  121. {
  122.     return depth;
  123. }
  124.  
  125. /*=========================================================================
  126.  * NAME        : setTestMode:
  127.  * DESCRIPTION : Sets the test flag.
  128.  *=========================================================================*/
  129. - setTestMode:(BOOL)flag
  130. {
  131.     test = flag;
  132.     return self;
  133. }
  134.  
  135. /*=========================================================================
  136.  * NAME        : testMode
  137.  * DESCRIPTION : Returns the state of the test mode flag.
  138.  *=========================================================================*/
  139. - (BOOL)testMode
  140. {
  141.     return test;
  142. }
  143.  
  144. // [TRH 10-Nov-97] Access methods for nextstep/openstep defaults flags.
  145. - setNextstep:(BOOL)flag    { nextstep = flag;  return self; }
  146. - (BOOL)nextstep        { return nextstep; }
  147. - setOpenstep:(BOOL)flag    { openstep = flag;  return self; }
  148. - (BOOL)openstep        { return openstep; }
  149.  
  150. /*===========================================================================
  151.  * NAME        : - setFont:
  152.  * DESCRIPTION : Set the cell font.
  153.  *===========================================================================*/
  154. - setFont:fontObj
  155. {
  156.     [super setFont:fontObj];
  157.     NXTextFontInfo(support, &ascender, &descender, &lineHeight);
  158.     return self;
  159. }    
  160.  
  161. /*===========================================================================
  162.  * NAME        : - drawInside:inView:
  163.  * DESCRIPTION : Draw the custom cell.
  164.  *===========================================================================*/
  165. - drawInside:(const NXRect *)cellFrame inView:controlView
  166. {
  167.     NXPoint    imageOrigin;
  168.     
  169.     [super drawInside:cellFrame inView:controlView];
  170.     
  171.     /* erase the cell */
  172.     PSsetgray((cFlags1.state || cFlags1.highlighted) ? NX_WHITE : NX_LTGRAY);
  173.     NXRectFill(cellFrame);
  174.     
  175.     /* draw the depth tiff */
  176.     if (depthImage) {
  177.         imageOrigin.x = FIRST_COLUMN_START;
  178.     imageOrigin.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame) -
  179.                     (NX_HEIGHT(cellFrame) - imageSize.height) / 2.0;
  180.     [depthImage composite:NX_SOVER toPoint:&imageOrigin];
  181.     }
  182.     
  183.     /* draw the text */
  184.     if (depth != USE_DEFAULT)
  185.         PSsetgray(NX_BLACK);
  186.     else
  187.         PSsetgray(NX_DKGRAY);
  188.     PSmoveto(NX_X(cellFrame) + SECOND_COLUMN_START,
  189.              NX_Y(cellFrame) + lineHeight - descender);
  190.     PSshow(contents);
  191.     
  192.     return self;
  193. }
  194.  
  195. @end
  196.