home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / Utilities / Desktop / PasteboardInspector / Source / GCell.m < prev    next >
Encoding:
Text File  |  1991-08-16  |  2.5 KB  |  144 lines

  1.  
  2.  
  3.  
  4. #import <libc.h>
  5. #import    <stdio.h>
  6. #import <strings.h>
  7.  
  8. #import <appkit/Application.h>
  9. #import <appkit/Listener.h>
  10. #import <appkit/Speaker.h>
  11. #import <appkit/View.h>
  12.  
  13. #import    <appkit/NXImage.h>
  14. #import <appkit/NXBitmapImageRep.h>
  15. #import <appkit/NXEPSImageRep.h>
  16. #import <appkit/tiff.h>    
  17.  
  18. #import    <dpsclient/dpsNeXT.h>
  19. #import <streams/streams.h>
  20. #import <sys/types.h>
  21.  
  22.  
  23. #import "GCell.h"
  24.  
  25. @implementation GCell
  26.  
  27. - initFromFile:(char *)file 
  28. {
  29.     char *tiff = NULL;
  30.     int length;
  31.     int    okFlag;
  32.     NXStream *stream;
  33.     id speaker;
  34.     
  35.        self = [super init];
  36.     speaker = [NXApp appSpeaker];
  37.     [speaker setSendPort:NXPortFromName(NX_WORKSPACEREQUEST, NULL)];
  38.     [speaker     getFileIconFor: file
  39.                 TIFF: &tiff 
  40.                 TIFFLength: &length 
  41.                 ok: &okFlag];
  42.     if(okFlag || tiff)
  43.     {
  44.         stream = NXOpenMemory(tiff, length, NX_READONLY);
  45.         theImage = [[NXImage alloc] initFromStream: stream ];
  46.         NXCloseMemory(stream, NX_FREEBUFFER);
  47.     }
  48.     else
  49.     {
  50.         theImage = [[NXImage alloc] 
  51.             initFromFile: "/usr/lib/nib/default_app_icon.tiff" ];
  52.     }
  53.     
  54.     if(file != NULL)
  55.         strcpy(name, file);
  56.     else
  57.     {
  58.         strcpy(name, "FooFile");
  59.     }
  60.     return self;
  61. }
  62.     
  63. - calcCellSize:(NXSize *)theSize
  64. {
  65.     NXSize s;
  66.     [theImage getSize: &s];
  67.     s.height += 4.0;
  68.     s.width += 4.0;
  69.     *theSize = s;
  70.     return self;
  71. }
  72.  
  73. - highlight:(const NXRect *)cellFrame inView:controlView lit:(BOOL)flag;
  74. {
  75.     return self;
  76. }
  77.  
  78. - (BOOL)trackMouse:(NXEvent *)theEvent 
  79.     inRect:(const NXRect *)cellFrame 
  80.     ofView:controlView;
  81. {    
  82.     int    aFlag;
  83.     
  84.     if(theEvent->data.mouse.click > 1)
  85.     {
  86.         if(lastmouse)
  87.         {
  88.             id    speaker = [NXApp appSpeaker];
  89.             [speaker setSendPort: 
  90.                 NXPortFromName(NX_WORKSPACEREQUEST, NULL)];
  91.             [speaker openFile: name ok:&aFlag];
  92.             lastmouse = NO;
  93.         }
  94.         else
  95.         {
  96.             lastmouse = YES;
  97.         }
  98.         
  99.     }
  100.     else
  101.     {
  102.         NXEvent *e;
  103.         NXRect dragRect;
  104.         e = [NXApp     getNextEvent: NX_MOUSEUPMASK
  105.                     waitFor: .25
  106.                     threshold: NX_MODALRESPTHRESHOLD];
  107.         if(e != NULL)
  108.             return YES;
  109.             
  110.         dragRect.origin = cellFrame->origin;
  111.         dragRect.size.height = 48.0;
  112.         dragRect.size.width = 48.0;
  113.         [controlView dragFile: name
  114.             fromRect: &dragRect
  115.             slideBack: YES
  116.             event: theEvent];
  117.     }
  118.     return YES;
  119. }
  120.   
  121. - drawInside: (const NXRect *)cellFrame inView:controlView
  122. {
  123.     NXPoint    compositePlace;
  124.     compositePlace.x = cellFrame->origin.x+2.0;
  125.     compositePlace.y = NX_MAXY(cellFrame)+ 2.0;
  126.     [theImage composite:NX_COPY toPoint:&compositePlace];
  127.     return self;
  128. }
  129.  
  130. - writeRichText:(NXStream *)stream forView:view
  131. {    
  132.     return self;
  133. }
  134.  
  135.  
  136. - readRichText:(NXStream *)stream forView:view
  137. {    
  138.     return self;
  139. }
  140.  
  141.  
  142.  
  143. @end
  144.