home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / Palettes / Clocks / Inspectors.subproj / SoundWell.m < prev   
Text File  |  1992-12-09  |  3KB  |  119 lines

  1. //------------------------------------------------------------------------------------------------
  2. //
  3. //    SoundWell
  4. //    
  5. //    Inherits From:    View
  6. //
  7. //    Declared In:    SoundWell.h
  8. //
  9. //    Disclaimer
  10. //
  11. //        You may freely copy, distribute and reuse this software and its
  12. //        associated documentation. I disclaim any warranty of any kind, 
  13. //        expressed or implied, as to its fitness for any particular use.
  14. //
  15. //------------------------------------------------------------------------------------------------
  16. #import "SoundWell.h"
  17.  
  18.  
  19. @implementation SoundWell
  20.  
  21. //------------------------------------------------------------------------------------------------
  22. //    Initialization and Freeing
  23. //------------------------------------------------------------------------------------------------
  24. - initFrame: (const NXRect*) frameRect
  25.     [super initFrame:frameRect];
  26.     [self setCell: [[ActionCell allocFromZone:[self zone]] init]];
  27.     [self registerForDraggedTypes:&NXFilenamePboardType count:1];
  28.     return self;
  29. }
  30.  
  31.  
  32. - free
  33. {
  34.     if (sound) [sound free];
  35.     return [super free];
  36. }
  37.  
  38.  
  39. //------------------------------------------------------------------------------------------------
  40. //    Accessing Image
  41. //------------------------------------------------------------------------------------------------
  42. - sound: aSound
  43. {
  44.     sound = aSound;
  45.     return self;
  46. }
  47.  
  48.  
  49. - sound
  50. {
  51.     return sound;
  52. }
  53.  
  54.  
  55. //------------------------------------------------------------------------------------------------
  56. //    Action Methods
  57. //------------------------------------------------------------------------------------------------
  58. - play: sender
  59. {
  60.     [sound play];
  61.     return self;
  62. }
  63.  
  64.  
  65. //------------------------------------------------------------------------------------------------
  66. //    Drawing
  67. //------------------------------------------------------------------------------------------------
  68. - drawSelf: (const NXRect *)rects :(int)count
  69. {
  70.     NXSetColor ([[self window] backgroundColor]);
  71.     NXRectFill (&bounds);
  72.     return self;
  73. }
  74.  
  75.  
  76. //------------------------------------------------------------------------------------------------
  77. //    Dragging
  78. //------------------------------------------------------------------------------------------------
  79. - (NXDragOperation) draggingEntered:dragSource
  80. {
  81.     return NX_DragOperationCopy;
  82. }
  83.  
  84.  
  85. - (BOOL) performDragOperation:dragSource
  86. {
  87.     char*    pathString;
  88.     char*    data;
  89.     int         length;
  90.     
  91.     id aPboard = [dragSource draggingPasteboard];
  92.     [aPboard readType:NXFilenamePboardType data:&data length:&length];
  93.  
  94.     if ((pathString = index (data, '\t'))) *pathString = '\0';
  95.  
  96.     if ((pathString = rindex (data, '.')))
  97.         if (NXOrderStrings (pathString + 1, "snd", YES, -1, NULL) == 0)
  98.             {
  99.             sound = [[Sound allocFromZone: [self zone]] initFromSoundfile: data];
  100.             [sound play];
  101.             [aPboard deallocatePasteboardData:data length:length];
  102.             return YES;
  103.             }
  104.             
  105.     [aPboard deallocatePasteboardData:data length:length];
  106.     return NO;
  107. }
  108.  
  109.  
  110. - concludeDragOperation:dragSource
  111. {
  112.     [[self target] perform:[self action] with:self];
  113.     return self;
  114. }
  115.  
  116.  
  117.  
  118. @end