/* -----------------------------------------------------------------------------------	*/
/* ShowIconPath.m -- Copyright (c) 1990 Charlie Lindahl <lindahl@evax.arl.utexas.edu>  */
/*											                         */
/*   This program is free software; you can redistribute it and/or modify it under the 	*/		
/*   terms of the GNU General Public License as published by the Free Software		*/		
/*   Foundation; either version 1, or (at your option) any later option.		*/		
/*											*/										
/*   This program is distributed in the hope that it will be useful, but WITHOUT ANY	*/
/*   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A	*/		
/*   PARTICULAR PURPOSE.  See the GNU General Public License for more details.		*/			
/*											*/
/*   You should have received a copy of the GNU General Public License along with this 	*/	
/*   this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, 	*/
/*   Cambridge, MA 02139, USA, or send electronic mail to the author.			*/	
/* ------------------------------------------------------------------------------------	*/
/*  										 	*/
/* ------------------------------------------------------------------------------------	*/
/* Credit is due to Ed Hill <edhill@shumun.weeg.uiowa.edu>, author of FrontEnd, */
/* a Macintosh to NeXT sound conversion program. His was the code I started with */
/* to figure out the details of the icon dragging code. */
/* ------------------------------------------------------------------------------------	*/

/******************************************************************
 *
 * Various .h files: 
 *
 * ShowIconApp.h		: Generated by IB
 * appkit/appkit.h		: Needed for standard appKit stuff
 * appkit/publicWraps.h	: Needed for Speaker/Listener stuff
 * appkit/nextstd.h		: Needed for NX_MALLOC defs
 * string.h				: Needed for string functions
 *
 ******************************************************************/
#import "ShowIconApp.h"
#import <appkit/appkit.h>
#import <appkit/publicWraps.h>	
#import <appkit/nextstd.h>
#import <string.h>		

@implementation ShowIconApp

- setIconTextField:anObject
{
    IconTextField = anObject;
    return self;
}

- setMainWindow:anObject
{
    MainWindow = anObject;
    return self;
}

- setIconButton:anObject
{
    IconButton = anObject;
    return self;
}

/************************************************************************
 *  The following  method takes over after the application has 
 * been started by the workspace manager. 
 * It is setting up the window to display an icon which is dragged
 * within it. 
 ************************************************************************/
 - appDidInit:sender
{
    id		 	theListener;
    id		 	theSpeaker;
    unsigned int	windowNum;
    
    theSpeaker = [NXApp appSpeaker];
    NXConvertWinNumToGlobal([MainWindow windowNum], &windowNum);
    theListener = [NXApp appListener];
    [theListener setDelegate:self];
    [theListener privatePort];
    [theListener addPort];
    [theSpeaker setSendPort: NXPortFromName(NX_WORKSPACEREQUEST, NULL)];
    [theSpeaker registerWindow: windowNum toPort:[theListener listenPort]];
    NX_FREE( iconPath );
    NX_MALLOC( iconPath, char, strlen( "" ) + 1 );
    strcpy( iconPath, "" );
     return self;
}

/************************************************************************
  *  The following  method is invoked when an icon is dragged within
  *  the main window of this application. 
  ************************************************************************/
- (int)iconEntered:(int)windowNum 
	at:(double)x 
	:(double)y 
	iconWindow:(int)iconWindowNum 
	iconX:(double)iconX 
	iconY:(double)iconY 
	iconWidth:(double)iconWidth 
	iconHeight:(double)iconHeight 
	pathList:(const char *)pathList
{
    NX_FREE( iconPath );
    NX_MALLOC( iconPath, char, strlen( pathList ) + 1 );
    strcpy( iconPath, pathList );
    [IconTextField setStringValue:iconPath];
    return 0;
}

@end

