/*$Copyright:
 * Copyright (C) 1992.5.22. Recruit Co.,Ltd. 
 * Institute for Supercomputing Research
 * All rights reserved.
 * NewsBase  by ISR, Kazuto MIYAI, Gary ARAKAKI, Katsunori SUZUKI, Kok-meng Lue
 *
 * You may freely copy, distribute and reuse the code in this program under 
 * following conditions.
 * - to include this notice in the source code, if it is to be distributed 
 *   with source code.
 * - to add the file named "COPYING" within the code, which shall include 
 *   GNU GENERAL PUBLIC LICENSE(*).
 * - to display an acknowledgement in binary code as follows: "This product
 *   includes software developed by Recruit Co.,Ltd., ISR."
 * - to display a notice which shall state that the users may freely copy,
 *   distribute and reuse the code in this program under GNU GENERAL PUBLIC
 *   LICENSE(*)
 * - to indicate the way to access the copy of GNU GENERAL PUBLIC LICENSE(*)
 *
 *   (*)GNU GENERAL PUBLIC LICENSE is stored in the file named COPYING
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
$*/

#import "IPostButton.h"
#import "IReceiveSpeaker.h"
#import "IReceiveListener.h"
#import "Localization.h"

#import <appkit/NXImage.h>
#import <appkit/Panel.h>
#import <dpsclient/psops.h>

#define LoStr(key)      doLocalString(NULL,key,NULL)
#define	MIMEDOCICON	"mimeDocIcon"

@implementation IPostButton

- initFrame:(NXRect *)frameRect
{
    [super initFrame:frameRect];
    [self setIcon:MIMEDOCICON];
    [self setBordered:YES];
    return self;
}

- mouseDown:(NXEvent *)theEvent
{
    port_t      port;
    int         returnCode;
    NXPoint	hitPoint, mousePoint;
    unsigned int	gwinNum;
    
    // compute frame origin point to convert to base screen coord.
    mousePoint = theEvent->location;
    [window convertBaseToScreen:&mousePoint];
    
    // compute offset of mouse down point
    hitPoint = theEvent->location;
    [self convertPoint:&hitPoint fromView:nil];
    if([self isFlipped] == YES) {
	hitPoint.y = frame.size.height - hitPoint.y;
    }
    
    NXConvertWinNumToGlobal([window windowNum], &gwinNum);
    
    port = NXPortFromName("NewsBase", NULL);
    [[NXApp appSpeaker] setSendPort:port];
    if ((returnCode = [[NXApp appSpeaker] 
    		makeMimeIconWindowAtpointX:(int)mousePoint.x 
			pointY:(int)mousePoint.y
			offsetX:(int)hitPoint.x
			offsetY:(int)hitPoint.y
			sourceWindow:(int)gwinNum]) != 0) {
        NXRunAlertPanel([self name],LoStr("cannot contact NewsBase"),
            LoStr("OK"),NULL,NULL);
    }
    return(self);
}

@end
