/*	XGIcon.cpp
 *
 *		A simple icon view.  Could be smarter.
 */

/**********************************************************************

  XGIcon.cpp Copyright 1998-1999 Sassafras Software Inc.
  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#include <XConfig.h>			// must be first to optimize compile on MSVC++
#include <XDraw.h>
#include <XIcon.h>

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

/*$	XGIcon::XGIcon
 *
 *		Construction
 */

XGIcon::XGIcon (XGView *parent, XGArgStream &init) : XGView(parent,init)
{
	fIcon = init.ReadInteger();
	fWidth = init.ReadInteger();
	fHeight = init.ReadInteger();
}

XGIcon::XGIcon (XGView *parent, XGIconInitRecord &init) : XGView(parent,init.v)
{
	fIcon = init.icon;
	fWidth = init.width;
	fHeight = init.height;
}

/*$	XGIcon::~XGIcon
 *
 *		Destruction
 */

XGIcon::~XGIcon (void)
{
}

/************************************************************************/
/*																		*/
/*	Events																*/
/*																		*/
/************************************************************************/

/*$	XGIcon::DoDrawView
 *
 *		Draw the current view
 */

void XGIcon::DoDrawView(XRect u)
{
	XGDraw draw(this);
	XRect r;
	
	draw.Draw3DRect(u,KXGEBackground);
	
	r = GetContentRect();
	if (fWidth > 0) {
		r.left = (r.left + r.right - fWidth) / 2;
		r.right = r.left + fWidth;
	}
	if (fHeight > 0) {
		r.top = (r.top + r.bottom - fHeight) / 2;
		r.bottom = r.top + fHeight;
	}
	
	::InsetRect(&r, -1, -1);
	draw.Draw3DRect(r, KXGEInset);
	::InsetRect(&r, 1, 1);
	
	draw.DrawIcon(fIcon, r.left, r.top);
}
