home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / MiscKit1.2.6 / Palettes / MiscTeePalette / MiscDimpleCell.m < prev    next >
Encoding:
Text File  |  1994-06-10  |  2.5 KB  |  136 lines

  1. //
  2. //    MiscDimpleCell.m -- An NXBrowserCell subclass that adds a mark image so
  3. //                        a list can have an appearance similar to the IB
  4. //                        connection inspector list.
  5. //
  6. //        Written by David Fedchenko.  Copyright 1994 by David Fedchenko.
  7. //                Version 1.0  All rights reserved.
  8. //
  9. //        This notice may not be removed from this source code.
  10. //
  11. //    This object is included in the MiscKit by permission from the author
  12. //    and its use is governed by the MiscKit license, found in the file
  13. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  14. //    for a list of all applicable permissions and restrictions.
  15. //    
  16.  
  17. #import "MiscDimpleCell.h"
  18.  
  19. @implementation MiscDimpleCell
  20.  
  21. static id MDMarkImage;
  22. static id MDAltMarkImage;
  23.  
  24. + initialize
  25.     {
  26.     id    idBundle;
  27.     char buf[MAXPATHLEN + 1];
  28.     
  29.     [super initialize];
  30.     
  31.     idBundle = [NXBundle bundleForClass:[self class]];
  32.     [idBundle getPath:buf forResource:"Dimple" ofType:"tiff"];
  33.     MDMarkImage = [[NXImage alloc] initFromFile:buf];
  34.     
  35.     [idBundle getPath:buf forResource:"DimpleH" ofType:"tiff"];
  36.     MDAltMarkImage = [[NXImage alloc] initFromFile:buf];
  37.     
  38.     return self;
  39.     }
  40.  
  41. + setMarkImage:anImage
  42.     {
  43.     id idT = MDMarkImage;
  44.     
  45.     MDMarkImage = anImage;
  46.     
  47.     return idT;
  48.     }
  49.  
  50. + markImage
  51.     {
  52.     return MDMarkImage;
  53.     }
  54.  
  55. + setAltMarkImage:anImage
  56.     {
  57.     id idT = MDAltMarkImage;
  58.     
  59.     MDAltMarkImage = anImage;
  60.     
  61.     return idT;
  62.     }
  63.  
  64. + altMarkImage
  65.     {
  66.     return MDAltMarkImage;
  67.     }
  68.  
  69. - setMarked:(BOOL)flag
  70.     {
  71.     fMarked = flag;
  72.     
  73.     if (fMarked)
  74.         {
  75.         [self setLeaf:YES];
  76.         }
  77.     
  78.     return self;
  79.     }
  80.  
  81. -(BOOL) marked
  82.     {
  83.     return fMarked;
  84.     }
  85.  
  86. - drawInside:(const NXRect *)cellFrame inView:controlView
  87.     {
  88.     [super drawInside:cellFrame inView:controlView];
  89.     
  90.     [self drawMark:cellFrame];
  91.     
  92.     return self;
  93.     }
  94.  
  95. - highlight:(const NXRect *)cellFrame inView:aView lit:(BOOL)lit
  96.     {
  97.     [super highlight:cellFrame inView:aView lit:lit];
  98.     
  99.     [self drawMark:cellFrame];
  100.     
  101.     return self;
  102.     }
  103.  
  104. - drawMark:(const NXRect *)cellFrame
  105.     {
  106.     NXRect    rect;
  107.     id        idImage;
  108.     
  109.      if ([self isLeaf])
  110.          {
  111.         idImage = ([self state] || [self isHighlighted])
  112.                     ? [[self class] altMarkImage]
  113.                     : [[self class] markImage];
  114.         [idImage getSize:&rect.size];
  115.         rect.origin.x = NX_WIDTH(cellFrame) - rect.size.width - 5.0;
  116.         rect.origin.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame)
  117.                         - ((NX_HEIGHT(cellFrame) - rect.size.height) / 2);
  118.         
  119.         if (fMarked)
  120.             {
  121.             [idImage composite:NX_SOVER toPoint:&rect.origin];
  122.             }
  123.         else
  124.             {
  125.             PSsetgray(([self state] || [self isHighlighted])
  126.                         ? NX_WHITE : NX_LTGRAY);
  127.             rect.origin.y -= rect.size.height;
  128.             NXRectFill(&rect);
  129.             }
  130.         }
  131.     
  132.     return self;
  133.     }
  134.  
  135. @end
  136.