home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Programming / GDBbundle-1.0-MIS / src / TextEdit / GdbBundle.bproj / GdbBrowserCell.m < prev    next >
Encoding:
Text File  |  1997-04-14  |  5.8 KB  |  206 lines

  1. /* GdbBrowserCell.m created by ovidiu on Sat 05-Apr-1997 */
  2.  
  3. #import <AppKit/AppKit.h>
  4. #import "GdbBrowserCell.h"
  5.  
  6. @implementation GdbBrowserCell
  7.  
  8. static NSImage* squareImage = nil;
  9. static NSImage* squareHImage = nil;
  10. static NSImage* dotImage = nil;
  11. static NSImage* dotHImage = nil;
  12.  
  13. static NSCell* titleCell = nil;
  14. static NSCell* valueCell = nil;
  15. static NSCell* imageCell = nil;
  16.  
  17. + (void)initialize
  18. {
  19.   NSBundle* bundle = [NSBundle bundleForClass:self];
  20.   NSString* path;
  21.  
  22.   path = [bundle pathForResource:@"square" ofType:@"tiff"];
  23.   squareImage = [[NSImage alloc] initWithContentsOfFile:path];
  24.  
  25.   path = [bundle pathForResource:@"squareH" ofType:@"tiff"];
  26.   squareHImage = [[NSImage alloc] initWithContentsOfFile:path];
  27.  
  28.   path = [bundle pathForResource:@"dotImage" ofType:@"tiff"];
  29.   dotImage = [[NSImage alloc] initWithContentsOfFile:path];
  30.  
  31.   path = [bundle pathForResource:@"dotImageH" ofType:@"tiff"];
  32.   dotHImage = [[NSImage alloc] initWithContentsOfFile:path];
  33.  
  34.   titleCell = [[NSCell alloc] initTextCell:@""];
  35.   [titleCell setAlignment:NSLeftTextAlignment];
  36.  
  37.   valueCell = [[NSCell alloc] initTextCell:@""];
  38.   [valueCell setAlignment:NSLeftTextAlignment];
  39.  
  40.   imageCell = [[NSCell alloc] initImageCell:nil];
  41. }
  42.  
  43. - (void)setObjectToDisplay:(id<GdbDisplayValue,NSObject>)anObject
  44. {
  45.   Value* value;
  46.   Type* type;
  47.   tTypeKind typeKind;
  48.  
  49.   [anObject retain];
  50.   [displayableObject release];
  51.   displayableObject = anObject;
  52.  
  53.   value = [displayableObject value];
  54.   type = [value type];
  55.   typeKind = [type typeKind];
  56.  
  57.   if (typeKind == kVoid || typeKind == kScalar || typeKind == kEnum
  58.       || typeKind == kCString)
  59.     [self setLeaf:YES];
  60.   else
  61.     [self setLeaf:NO];
  62. }
  63.  
  64. - (void)drawInteriorWithFrame:(NSRect)cellFrame
  65.                        inView:(NSView*)view
  66.                backgroundGray:(float)backgroundGray
  67. {
  68.   Value* value = [displayableObject value];
  69.   Type* type = [value type];
  70.   NSRect valueFrame, imageRect;
  71.   NSString* title = [displayableObject title];
  72.   float titleWidth = 0, valueWidth = 0;
  73.   NSString* valueString = nil;
  74.  
  75.   if (!title)
  76.     title = @"";
  77.   if ([title isEqual:@""] && objectIsArrayComponent) {
  78.     int row, column;
  79.  
  80.     [(NSMatrix*)view getRow:&row column:&column ofCell:self];
  81.     title = [NSString stringWithFormat:@"[%d]", row];
  82.   }
  83.  
  84.   [titleCell setStringValue:title];
  85.   [valueCell setStringValue:@""];
  86.   [imageCell setImage:nil];
  87.  
  88.   switch ([type typeKind]) {
  89.     case kVoid:
  90.       break;
  91.     case kScalar:
  92.     case kEnum:
  93.       if (!(valueString = [value additionalDescription]))
  94.         valueString = [value stringValue];
  95.       [valueCell setStringValue:valueString ? valueString : @""];
  96.       break;
  97.     case kStructure:
  98.       [imageCell setImage:backgroundGray == NSWhite ? dotHImage : dotImage];
  99.       break;
  100.     case kClass:
  101.       [imageCell setImage:backgroundGray == NSWhite ? dotHImage : dotImage];
  102.       if (!(valueString = [value additionalDescription]))
  103.         valueString = [value stringValue];
  104.       [valueCell setStringValue:valueString ? valueString : @""];
  105.       break;
  106.     case kUnion:
  107.       [imageCell setImage:backgroundGray == NSWhite ? dotHImage : dotImage];
  108.       break;
  109.     case kArray:
  110.       [imageCell setImage:backgroundGray == NSWhite
  111.                             ? squareHImage : squareImage];
  112.       break;
  113.     case kPointer:
  114.     case kVoidPointer:
  115.       [imageCell setImage:backgroundGray == NSWhite
  116.                                     ? [isa highlightedBranchImage]
  117.                                     : [isa branchImage]];
  118.       /* Fall through */
  119.     case kCString:
  120.       /* If the value has a description associated with it then display it
  121.          rather than the address. Also make the cell a leaf cell. */
  122.       if (!(valueString = [value additionalDescription]))
  123.         valueString = [value stringValue];
  124.       else
  125.         [self setLeaf:YES];
  126.       [valueCell setStringValue:valueString ? valueString : @""];
  127.       break;
  128.   }
  129.  
  130.   if (title && ![title isEqual:@""])
  131.     titleWidth = [[titleCell font] widthOfString:title];
  132.   if (valueString && ![valueString isEqual:@""])
  133.     valueWidth = [[valueCell font] widthOfString:valueString];
  134.  
  135.   [titleCell drawInteriorWithFrame:cellFrame inView:view];
  136.  
  137.   if (![self isLeaf]) {
  138.     imageRect.size.width = 16;
  139.     imageRect.size.height = cellFrame.size.height;
  140.     imageRect.origin.x = cellFrame.origin.x + cellFrame.size.width
  141.                         - imageRect.size.width;
  142.     imageRect.origin.y = cellFrame.origin.y;
  143.     [imageCell drawInteriorWithFrame:imageRect inView:view];
  144.   }
  145.  
  146.   if (valueString) {
  147.     valueFrame.size.width = valueWidth + 8;
  148.     valueFrame.size.height = cellFrame.size.height;
  149.     valueFrame.origin.x = cellFrame.origin.x + cellFrame.size.width
  150.         - valueFrame.size.width - ([self isLeaf] ? 0 : imageRect.size.width);
  151.     valueFrame.origin.y = cellFrame.origin.y;
  152.     [valueCell drawInteriorWithFrame:valueFrame inView:view];
  153.   }
  154. }
  155.  
  156. - (void)drawWithFrame:(NSRect)cellFrame
  157.                inView:(NSView *)controlView
  158. {
  159.   float backgroundGray = NSLightGray;
  160.  
  161.   PSgsave();
  162.  
  163.   if (state)
  164.     backgroundGray = NSWhite;
  165.   if (isHighlighted) {
  166.     if (backgroundGray == NSLightGray)
  167.       backgroundGray = NSWhite;
  168.   }
  169.  
  170.   /* Clear the cell frame */
  171.   PSsetgray (backgroundGray);
  172.   PSrectfill (cellFrame.origin.x, cellFrame.origin.y,
  173.               cellFrame.size.width, cellFrame.size.height);
  174.  
  175.   [self drawInteriorWithFrame:cellFrame
  176.                        inView:controlView
  177.                backgroundGray:backgroundGray];
  178.   PSgrestore();
  179. }
  180.  
  181. - (void)highlight:(BOOL)flag
  182.         withFrame:(NSRect)cellFrame
  183.            inView:(NSView*)controlView
  184. {
  185.   isHighlighted = flag;
  186. }
  187.  
  188. - (void)setState:(int)_state
  189. {
  190.   state = _state;
  191. }
  192.  
  193. /* Implement stringValue to return a useful string to be shown as title of a
  194.   column in the stack browser. */
  195. - (NSString*)stringValue
  196. {
  197.   return [displayableObject title];
  198. }
  199.  
  200. - (void)setObjectIsArrayComponent:(BOOL)flag
  201. {
  202.   objectIsArrayComponent = flag;
  203. }
  204.  
  205. @end
  206.