/*	XGGrowIcon.cpp
 *
 *		Provides a Win95-style grow icon. This has been superceeded by
 *	modifications to XGWindow, XGAppCore_win.cpp, which provide a real
 *	grow icon instead.
 */

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

  XGGrowIcon.cpp is Copyright 1998 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 <XScroll.h>
#include <XDraw.h>
#include <XWindow.h>
#include <XCursorUtil.h>
#include <XGrowIcon.h>

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

/*$	XGGrowIcon::XGGrowIcon
 *
 *		Build me
 */

XGGrowIcon::XGGrowIcon (XGView *owner, XGArgStream &stream) : XGView(owner,stream)
{

}

XGGrowIcon::XGGrowIcon (XGView *parent, XGGrowIconInitRecord &init) : XGView(parent, init.v)
{

}

XGGrowIcon::~XGGrowIcon (void)
{

}
		
void
XGGrowIcon::DoDrawView(XRect)
{
#if OPT_WINOS
	XGDraw draw(this);

	XRect r = GetContentRect();
	draw.Draw3DRect(r, KXGEBackground);

	draw.SetForeColor(KXGColorBlack);
	draw.MoveTo(r.right - 4, r.bottom - 2);
	draw.LineTo(r.right - 2, r.bottom - 4);
	draw.MoveTo(r.right - 8, r.bottom - 2);
	draw.LineTo(r.right - 2, r.bottom - 8);
	draw.MoveTo(r.right - 12, r.bottom - 2);
	draw.LineTo(r.right - 2, r.bottom - 12);

	draw.SetForeColor(KXGColorWhite);
	draw.MoveTo(r.right - 5, r.bottom - 2);
	draw.LineTo(r.right - 2, r.bottom - 5);
	draw.MoveTo(r.right - 9, r.bottom - 2);
	draw.LineTo(r.right - 2, r.bottom - 9);
	draw.MoveTo(r.right - 13, r.bottom - 2);
	draw.LineTo(r.right - 2, r.bottom - 13);
#endif
}

#if OPT_WINOS
bool
XGGrowIcon::DoMouseDown (XPoint where, short)
{
	fLastPos.h = where.h;
	fLastPos.v = where.v;
	return true;
}

void
XGGrowIcon::DoMouseMove (XPoint where, short flags)
{
	if (!(flags & KCapturedMouse)) {
		XGView::DoMouseMove(where,flags);
	} else {
		if (where.h != fLastPos.h
			|| where.v != fLastPos.v)
		{
			XPoint pos = GetWindow()->GetWindowSize();
			pos.h += where.h - fLastPos.h;
			pos.v += where.v - fLastPos.v;
			GetWindow()->SetWindowSize(pos);
			GetParent()->UpdateView();
		}
	}
	::SetCursor(::LoadCursor(NULL, IDC_SIZENWSE));
}
#endif

void
XGGrowIcon::RecalcAutoLocation (XGView *below, XGView *beside, XRect *r)
{
	XRect tr;

	if (!r) {
		r = &tr;
		tr.top = -GetHeight();
		tr.left = -XGScrollBar::GetDefaultSize().h + 1;
		tr.bottom = 0;
		tr.right = 0;
	}
	XGView::RecalcAutoLocation(below, beside, r);
}

long
XGGrowIcon::GetHeight (void)
{
	return(XGScrollBar::GetDefaultSize().v - 2);
}
