//	Zinc Application Framework - D_MIN.CPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#include <z_min.hpp>
#include <z_title.hpp>
#define ZAF_MINIMIZE_BUTTON_INFO
#include "img_def.cpp"

// ----- ZafMinimizeButton ------------------------------------------------

#if defined(ZAF_DEFAULT_DRAW)
ZafEventType ZafMinimizeButton::Draw(const ZafEventStruct &, ZafEventType ccode)
{
	// Compute the actual draw region.
	ZafPaletteState state = PaletteState();
	ZafRegionStruct drawRegion = BeginDraw();

	ZafPaletteStruct palette;
	ZafWindow *parentWindow = DynamicPtrCast(parent, ZafWindow);
	ZafWindowObject *title = DynamicPtrCast(parent, ZafWindow)->Title();
	if (title)
		palette = title->LogicalPalette(ZAF_PM_TEXT, state);
	else
		palette = LogicalPalette(ZAF_PM_TEXT, state);

	display->SetPalette(palette);

	// Draw the bitmap.
	automaticUpdate = false;
	if (Depressed())
		SetBitmapData(parentWindow->Minimized() ? minimizedDepressedBitmap : minDepressedBitmap);
	else
		SetBitmapData(parentWindow->Minimized() ? minimizedBitmap : minBitmap);
	automaticUpdate = true;

	int bitmapWidth = bitmapData->Width();
	int bitmapHeight = bitmapData->Height();
	int fieldHeight = zafRegion.Height();
	int left = zafRegion.Width() - bitmapWidth;
	int top = (fieldHeight - bitmapHeight) / 2;
	int bottom = top + bitmapHeight;

	display->Bitmap(left, top, *bitmapData);

	display->Rectangle(0, 0, zafRegion.Width() - 1,	top - 1, 0, true);
	display->Rectangle(0, bottom, zafRegion.Width() - 1, zafRegion.Height() - 1, 0, true);
	display->Rectangle(0, top, left - 1, bottom, 0, true);

	EndDraw();

	// Return the control code.
	return (ccode);
}
#endif

ZafEventType ZafMinimizeButton::Event(const ZafEventStruct &event)
{
	// Check for zinc events.
	ZafEventType ccode = LogicalEvent(event);
	switch (ccode)
	{
	case S_COMPUTE_SIZE:
		ccode = ZafWindowObject::Event(event);
#if defined(ZAF_GRAPHICS_MODE)
		zafRegion.bottom = zafRegion.top + (display->cellHeight - display->preSpace - display->postSpace - 3);
		zafRegion.left = zafRegion.right - (display->cellHeight - display->preSpace - display->postSpace - 2);
#elif defined(ZAF_TEXT_MODE)
		zafRegion.bottom = zafRegion.top;
		zafRegion.left = zafRegion.right - 2;
#endif
		break;

	// ----- Unknown or error messages -----
	default:
		ccode = ZafButton::Event(event);
		break;
	}

	// Return the control code.
	return (ccode);
}

// ----- OS Specific Functions ----------------------------------------------

void ZafMinimizeButton::OSRegisterObject(void)
{
	ZafButton::OSRegisterObject();
}

void ZafMinimizeButton::OSSize(void)
{
	ZafWindowObject::OSSize();
}

ZafError ZafMinimizeButton::OSUpdatePalettes(ZafPaletteType zafTypes, ZafPaletteType osTypes)
{
	// Skip the button level.
	return (ZafWindowObject::OSUpdatePalettes(zafTypes, osTypes));
}

