Annotation of Examples/AppKit/ScrollDoodScroll/CustomCell.m, revision 1.1.1.1

1.1       root        1: // CustomCell.m
                      2: // By Jayson Adams, NeXT Developer Support Team
                      3: // You may freely copy, distribute and reuse the code in this example.
                      4: // NeXT disclaims any warranty of any kind, expressed or implied, as to its
                      5: // fitness for any particular use.
                      6: 
                      7: // This subclass of cell draws a dot image to the right of the text
                      8: // and provides fancy, printable highlighting.
                      9: 
                     10: #import <appkit/appkit.h>
                     11: #import "CustomCell.h"
                     12: 
                     13: @implementation CustomCell
                     14: 
                     15:   
                     16: #define IMAGEMARGIN 4.0
                     17:   
                     18: - drawInside:(const NXRect *)cellFrame inView:controlView
                     19: {
                     20:     /* every CustomCell needs these two */
                     21:     static id dotImage = nil;
                     22:     static id sharedTextCell = nil;
                     23: 
                     24:     NXRect rect = *cellFrame;
                     25:     NXPoint imageOrigin;
                     26:     NXSize dotSize;
                     27:         
                     28:     if (!dotImage) {
                     29:        dotImage = [NXImage findImageNamed:"Dot"];
                     30:     }
                     31:     [dotImage getSize:&dotSize];
                     32: 
                     33:   /* erase the cell */
                     34:     PSsetgray((cFlags1.state || cFlags1.highlighted) ? NX_WHITE : NX_LTGRAY);
                     35:     NXRectFill(cellFrame);
                     36: 
                     37:   /* draw the "attachment" image */
                     38:     imageOrigin.x = NX_X(cellFrame) + IMAGEMARGIN;
                     39:     imageOrigin.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame) -
                     40:                    (NX_HEIGHT(cellFrame) - dotSize.height) / 2.0;
                     41: 
                     42:     [dotImage composite:NX_SOVER toPoint:&imageOrigin];
                     43:       
                     44:     NX_WIDTH(&rect) -= (dotSize.width + IMAGEMARGIN * 2.0 - NX_X(&rect));
                     45:     NX_X(&rect) += dotSize.width + IMAGEMARGIN * 2.0;
                     46: 
                     47:     if (!sharedTextCell) {
                     48:         sharedTextCell = [[Cell alloc] init];
                     49:        [sharedTextCell setWrap:NO];
                     50:     }
                     51:     [sharedTextCell setFont:[self font]];
                     52:     [sharedTextCell setStringValue:[self stringValue]];
                     53:     [sharedTextCell drawInside:&rect inView:controlView];
                     54:     
                     55:   /* all drawing from now on will be in dark gray */
                     56:     PSsetgray(NX_DKGRAY);
                     57:     
                     58:   /* draw the two dark gray lines above and below the cell */
                     59:     if (cFlags1.state || cFlags1.highlighted) {
                     60:         NXRect rectArray[2];
                     61:       /*
                     62:        * draw 1-pixel tall rectangles instead of lines (this is faster than
                     63:        * PSmoveto(); PSlineto()).
                     64:        */
                     65:        NXSetRect(&(rectArray[0]), NX_X(cellFrame), NX_Y(cellFrame),
                     66:                NX_WIDTH(cellFrame), 1.0);
                     67:        NXSetRect(&(rectArray[1]), NX_X(cellFrame), NX_MAXY(cellFrame) - 1.0,
                     68:                NX_WIDTH(cellFrame), 1.0);
                     69: 
                     70:       /* using NXRectFillList is faster than separate calls to NXRectFill */
                     71:        NXRectFillList(rectArray, 2);
                     72:     }
                     73: 
                     74:     return self;
                     75: }
                     76: 
                     77: - highlight:(const NXRect *)cellFrame inView:controlView lit:(BOOL)flag
                     78: {
                     79:     if (cFlags1.highlighted != flag) {
                     80:        cFlags1.highlighted = flag;
                     81:        [self drawInside:cellFrame inView:controlView];
                     82:     }
                     83:     return self;
                     84: }
                     85: 
                     86: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.