
///////////////////////////////////////////////
//											 //
// All files in X-framework are Copyright    //
// of Aleksandras Gluchovas 				 //
// 											 //
// e-mail: alex@soften.ktu.lt                //
//											 //
///////////////////////////////////////////////

#ifdef __GNUG__
#pragma implementation "XPageFrame.h"
#pragma interface
#endif


// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif


#include "XPageFrame.h"

/*** Implementation for class XPageFrame ***/

XPageFrame::XPageFrame( const XRect& bounds,
						bool isTransparent,
						const wxColour& bkCol,
						const wxColour& shadeCol,
						const wxColour& outlineCol,
						int shadeWidth, int outlineWidth )

	: mBounds       ( bounds ),
	  mBkBrush      ( bkCol,      wxSOLID ),
	  mShadeBrush   ( shadeCol,   wxSOLID ),
	  mOutlineBrush ( outlineCol, wxSOLID ),
	  mIsTransparent( isTransparent ),
	  mShadeWidth   ( shadeWidth ),
	  mOutlineWidth ( outlineWidth )
{
	CalcRects();
}

void XPageFrame::SetTransparent( bool transparent )
{
	mIsTransparent = transparent;

	InvalidateRect( mOutterBounds );
	RefreshNow();
}

void XPageFrame::Draw( wxDC& canvas )
{
	XRect area = XObject::GetUpdateRegion( canvas );

	canvas.SetPen( *wxTRANSPARENT_PEN );

	DrawRect( canvas, mR1, area, mOutlineBrush );
	DrawRect( canvas, mR2, area, mOutlineBrush );
	DrawRect( canvas, mR3, area, mOutlineBrush );
	DrawRect( canvas, mR4, area, mOutlineBrush );
	DrawRect( canvas, mR5, area, mShadeBrush );
	DrawRect( canvas, mR6, area, mShadeBrush );

	if ( !mIsTransparent )

		DrawRect( canvas, mR7, area, mBkBrush );
}

void XPageFrame::SetBounds( const XRect& bounds )
{
	mBounds = bounds;

	CalcRects();
}

void XPageFrame::DrawRect( wxDC& dc, XRect& rect, XRect& area, wxBrush& br )
{
	XRect interSect = rect.InsersectionWith( area );

	if ( interSect.IsEmpty() ) return;

	dc.SetBrush( br );
	dc.DrawRectangle( rect.x, rect.y, rect.width, rect.height );
}

XRect XPageFrame::GetBounds()
{
	return mOutterBounds;
}

void XPageFrame::CalcRects()
{
	mOutterBounds = mBounds;
	mOutterBounds.width  += mShadeWidth;
	mOutterBounds.height += mShadeWidth;

	XRect& r = mBounds;

	mOutlineWidth += 1;

	mR1.x = r.x; mR1.width  = r.width;
	mR1.y = r.y; mR1.height = mOutlineWidth;

	mR2.x = r.x + r.width - mOutlineWidth; mR2.width  = mOutlineWidth + 1;
	mR2.y = r.y;                           mR2.height = r.height;

	mR3.x = r.x; mR3.width  = r.width + 1;
	mR3.y = r.y + r.height - mOutlineWidth; mR3.height = mOutlineWidth + 1;
	
	mR4.x = r.x;  mR4.width  = mOutlineWidth;
	mR4.y = r.y;  mR4.height = r.height;

	mOutlineWidth -= 1;

	// shades

	mR5.x = r.x + r.width;      mR5.width  = mShadeWidth;
	mR5.y = r.y + mShadeWidth;  mR5.height = r.height;

	mR6.x = r.x + mShadeWidth;  mR6.width  = r.width;
	mR6.y = r.y + r.height;     mR6.height = mShadeWidth;

	// interior

	mR7.x = r.x + mOutlineWidth;  mR7.width  = r.width  - mOutlineWidth - mOutlineWidth;
	mR7.y = r.y + mOutlineWidth;  mR7.height = r.height - mOutlineWidth - mOutlineWidth;
}
