home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Connectivity / GateKeeper-2.1 / ToolIconView.m < prev    next >
Encoding:
Text File  |  1997-02-28  |  3.3 KB  |  130 lines

  1. //************************************************************************
  2. //
  3. //    ToolIconView.m.  
  4. //
  5. //    by    Felipe A. Rodriguez        
  6. //
  7. //
  8. //    This code is supplied "as is" the author makes no warranty as to its 
  9. //    suitability for any purpose.  This code is free and may be distributed 
  10. //    in accordance with the terms of the:
  11. //        
  12. //            GNU GENERAL PUBLIC LICENSE
  13. //            Version 2, June 1991
  14. //            copyright (C) 1989, 1991 Free Software Foundation, Inc.
  15. //             675 Mass Ave, Cambridge, MA 02139, USA
  16. //
  17. //************************************************************************
  18.  
  19.  
  20. #import "ToolIconView.h"
  21.  
  22.  
  23. @implementation ToolIconView
  24.  
  25. //*****************************************************************************
  26. //
  27. //         init the appIconView
  28. //
  29. //*****************************************************************************
  30.  
  31. - initFrame:(const NXRect *)bRect 
  32. {
  33.     [super initFrame:bRect];
  34.     [super setAutodisplay:YES];
  35.     [super notifyAncestorWhenFrameChanged:YES];
  36.     FrameImage = [NXImage findImageNamed: "frame"];
  37.     FrameBkImage = [NXImage findImageNamed: "frameBk"];
  38.  
  39.     return self;
  40. }
  41. //************************************************************************
  42. //
  43. //             app Icon handling Methods
  44. //
  45. //************************************************************************
  46.  
  47. - (NXPoint) _centerPoint:anImage
  48. {
  49. NXSize    appTileSize;
  50. NXSize    imageSize;
  51. NXPoint    centerPoint = {0,0};
  52.  
  53.         //  You must center the composited image within the contentView of the
  54.         //  appIcon window.
  55.     [FrameImage getSize: &appTileSize];
  56.     [anImage getSize: &imageSize];
  57.         // center image and add offset to compensate for location of subview
  58.     if( imageSize.width < appTileSize.width ) 
  59.         centerPoint.x += ((appTileSize.width - imageSize.width ) / 2.0) ;
  60.     
  61.     if( imageSize.height < appTileSize.height ) 
  62.         centerPoint.y += ((appTileSize.height - imageSize.height) / 2.0) ;
  63.         
  64.     return centerPoint;
  65. }
  66. //************************************************************************
  67. //
  68. //     NXAppTile is composited first at 0,0 of the icon window's content view
  69. //    (this is required in order to maintain the NeXT icon look).  'anImage'
  70. //    is then composited at center (centering is also a requirement).
  71. //
  72. //************************************************************************
  73.  
  74. - _display:anImage
  75. {
  76. NXPoint contentViewOrigin = {0.0, 0.0 };
  77. NXPoint    centerPoint = [self _centerPoint: anImage];
  78.     
  79.     [FrameBkImage composite:NX_SOVER toPoint:&contentViewOrigin];
  80.     [anImage composite:NX_SOVER toPoint:¢erPoint];
  81.     [FrameImage composite:NX_SOVER toPoint:&contentViewOrigin];
  82.  
  83.     return self;
  84. }
  85.  
  86. - drawSelf:(const NXRect *)rects :(int)rectCount 
  87. {
  88.     [self _display:Image]; 
  89.  
  90.     return self;
  91. }
  92. - (BOOL)acceptsFirstMouse
  93. {
  94.     return YES;
  95. }
  96. - (BOOL)acceptsFirstResponder
  97. {
  98.     return YES;
  99. }
  100. - resignFirstResponder
  101. {
  102.     return nil;
  103. }
  104. //*****************************************************************************
  105. //
  106. //         we will display the NXImage we are passed  
  107. //
  108. //*****************************************************************************
  109.  
  110. - setImage:theImage 
  111. {
  112.     Image = theImage; 
  113.     [self display];
  114.  
  115.     return     self; 
  116. }
  117. //************************************************************************
  118. //
  119. //     free simply gets rid of everything we created
  120. //     This is how nice objects clean up.
  121. //
  122. //************************************************************************
  123.  
  124. - free
  125. {
  126.     return [super free];
  127. }
  128.  
  129. @end
  130.