home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Connectivity / GateKeeper-2.1 / IconView.m < prev    next >
Encoding:
Text File  |  1996-10-25  |  4.6 KB  |  162 lines

  1. //************************************************************************
  2. //
  3. //    IconView.m.      
  4. //
  5. //        Displays an image in the app Icon
  6. //
  7. //        by    Felipe A. Rodriguez
  8. //
  9. //    This code is supplied "as is" the author makes no warranty as to its 
  10. //    suitability for any purpose.  This code is free and may be distributed 
  11. //    in accordance with the terms of the:
  12. //        
  13. //            GNU GENERAL PUBLIC LICENSE
  14. //            Version 2, June 1991
  15. //            copyright (C) 1989, 1991 Free Software Foundation, Inc.
  16. //             675 Mass Ave, Cambridge, MA 02139, USA
  17. //
  18. //************************************************************************
  19.  
  20.  
  21. #import "IconView.h"
  22.  
  23.  
  24. @implementation IconView
  25.  
  26. //*****************************************************************************
  27. //
  28. //         init the appIconView
  29. //
  30. //*****************************************************************************
  31.  
  32. - initFrame:(const NXRect *)bRect 
  33. {
  34.     [super initFrame:bRect];
  35.     [super setAutodisplay:YES];
  36.     [super notifyAncestorWhenFrameChanged:YES];
  37.     appTile = [NXImage findImageNamed: "NXAppTile"];
  38.     [self getFrame:&aRect];                                        // setup a 
  39.     timeCell = [[TextFieldCell alloc] initTextCell:"    "];        // transparent
  40.     [timeCell setBackgroundTransparent:YES];                    // textcell
  41.     [timeCell setTextColor:NX_COLORGREEN];                        // for display
  42.     timeFont = [Font newFont:"Ohlfs" size:14];                    // of time in
  43.     [timeCell setFont:timeFont];                                // appIcon
  44.     [timeCell setAlignment:NX_CENTERED];    // center text horiz
  45.     NXOffsetRect(&aRect, 0, -22);            // magic number center text vert
  46.     mailIcon = [NXImage findImageNamed: "mailq"];
  47.     Image = [NXImage findImageNamed: "GateKeeper"];
  48.     
  49.     return self;
  50. }
  51. //************************************************************************
  52. //
  53. //             app Icon handling Methods
  54. //
  55. //************************************************************************
  56.  
  57. - (NXPoint) _centerPoint:anImage
  58. {
  59. NXSize    appTileSize;
  60. NXSize    imageSize;
  61. NXPoint    centerPoint;
  62.  
  63.         //  You must center the composited image within the contentView of the
  64.         //  appIcon window.
  65.     [appTile getSize: &appTileSize];
  66.     [anImage getSize: &imageSize];
  67.         // center image and add offset to compensate for location of subview
  68.     if( imageSize.width < appTileSize.width ) 
  69.         centerPoint.x += ((appTileSize.width - imageSize.width ) / 2.0) - 1.0;
  70.     
  71.     if( imageSize.height < appTileSize.height ) 
  72.         centerPoint.y += ((appTileSize.height - imageSize.height) / 2.0) - 1.0;
  73.         
  74.     return centerPoint;
  75. }
  76. //************************************************************************
  77. //
  78. //     NXAppTile is composited first at 0,0 of the icon window's content view
  79. //    (this is required in order to maintain the NeXT icon look).  'anImage'
  80. //    is then composited at center (centering is also a requirement).
  81. //
  82. //************************************************************************
  83.  
  84. - _display:anImage
  85. {
  86. NXPoint    contentViewOrigin = {-1.0, -1.0 };
  87. NXPoint    centerPoint = [self _centerPoint: anImage];
  88.     
  89.     [appTile composite:NX_SOVER toPoint:&contentViewOrigin];
  90.     [anImage composite:NX_SOVER toPoint:¢erPoint];
  91.     [timeCell drawSelf:&aRect inView:self];    // draw 1st
  92.     NXOffsetRect(&aRect, 1, 0);                // offset trick to make font BOLD
  93.     [timeCell drawSelf:&aRect inView:self];    // draw 2nd w/off
  94.     NXOffsetRect(&aRect, -1, 0);                    // return offset to orginal
  95.     if(mailFlag)
  96.         [mailIcon composite:NX_SOVER toPoint:¢erPoint];
  97.  
  98.     return self;
  99. }
  100.  
  101. - drawSelf:(const NXRect *)rects :(int)rectCount 
  102. {
  103.     [self _display:Image]; 
  104.  
  105.     return self;
  106. }
  107. //*****************************************************************************
  108. //
  109. //         we will display the NXImage we are passed  
  110. //
  111. //*****************************************************************************
  112.  
  113. - setImage:theImage 
  114. {
  115.     oldImage = Image; 
  116.     Image = theImage; 
  117.     [self display];
  118.  
  119.     return oldImage; 
  120. }
  121. //*****************************************************************************
  122. //
  123. //         set whether we will display mail icon in corner of app icon  
  124. //
  125. //*****************************************************************************
  126.  
  127. - setMailFlag:(BOOL)flag 
  128. {
  129.     if(mailFlag != flag)
  130.         {
  131.         mailFlag = flag;
  132.         [self display];
  133.         } 
  134.  
  135.     return self; 
  136. }
  137. //*****************************************************************************
  138. //
  139. //         return the text Cell within the app Icon Tile 
  140. //
  141. //*****************************************************************************
  142.  
  143. - getTextCell 
  144. {
  145.     return timeCell; 
  146. }
  147. //************************************************************************
  148. //
  149. //     free simply gets rid of everything we created
  150. //     This is how nice objects clean up.
  151. //
  152. //************************************************************************
  153.  
  154. - free
  155. {
  156.     [timeCell free];
  157.  
  158.     return [super free];
  159. }
  160.  
  161. @end
  162.