// COPYRIGHT (C) 1990-1999.  All Rights Reserved. - GMGRWIN.CPP
// Zinc Software Incorporated.  Pleasant Grove, Utah  USA
// May be freely copied, used and distributed.

#include "gmgrwin.hpp"

void MainWindow::SetUpTexts(void)
{
	gmgr = new ZafGeometryManager;
	Add(gmgr);

	ZafPrompt *prompt1 = new ZafPrompt(1, 1, 20, ZAF_ITEXT("No Attachment"));
	ZafText *text1 = new ZafText(0, 0, 20, 3,
		new ZafStringData("Right attachment to the window and top alignment with the prompt."));

	ZafPrompt *prompt2 = new ZafPrompt(1, 3, 20, ZAF_ITEXT("Attached to status bar"));
	ZafText *text2 = new ZafText(0, 0, 20, 3,
		new ZafStringData("Right attachment to the window and bottom alignment with the prompt."));

	ZafAttachment *attach;
	// Attach the prompt to the status bar.
	attach = new ZafAttachment(prompt2, ZAF_ATCF_BOTTOM);
	attach->SetOppositeSide(true);
	attach->SetReference(statusBar);
	attach->SetOffset(1);
	gmgr->Add(attach);

	// Attach the string to the prompt so their tops are aligned.
	attach = new ZafAttachment(text1, ZAF_ATCF_TOP);
	attach->SetReference(prompt1);
	attach->SetOffset(0);
	gmgr->Add(attach);

	// Attach the string to the right side of the window.
	attach = new ZafAttachment(text1, ZAF_ATCF_RIGHT);
	attach->SetOffset(2);
	gmgr->Add(attach);

	// Attach the string to the right side of the window.
	attach = new ZafAttachment(text2, ZAF_ATCF_RIGHT);
	attach->SetOffset(2);
	gmgr->Add(attach);

	// Attach the string to the prompt so their bottoms are aligned.
	attach = new ZafAttachment(text2, ZAF_ATCF_BOTTOM);
	attach->SetReference(prompt2);
	attach->SetOffset(0);
	gmgr->Add(attach);

	// Complete the task by adding all the objects to the window.
	Add(prompt1);
	Add(prompt2);
	Add(text1);
	Add(text2);
}

void MainWindow::SetUpButton(void)
{
	ZafButton *button =
		new ZafButton(0, 0, 30, 1, ZAF_ITEXT("Centered, Stretched, Constrained"));

	// Set up a relative constraint to center the button vertically.
	ZafRelativeConstraint *relConst = 
		new ZafRelativeConstraint(button, ZAF_RLCF_TOP);
	relConst->SetCenter(true);
	relConst->SetRatio(50);
	gmgr->Add(relConst);

	// Set up a relative constraint to center the button horizontally.
	relConst = new ZafRelativeConstraint(button, ZAF_RLCF_LEFT);
	relConst->SetCenter(true);
	relConst->SetRatio(50);
	gmgr->Add(relConst);

	// Set up an attachment to stretch the button horizontally to the left.
	ZafAttachment *attach = new ZafAttachment(button, ZAF_ATCF_LEFT);
	attach->SetOffset(10);
	attach->SetStretch(true);
	gmgr->Add(attach);

	// Set up an attachment to stretch the button horizontally to the right.
	attach = new ZafAttachment(button, ZAF_ATCF_RIGHT);
	attach->SetOffset(10);
	attach->SetStretch(true);
	gmgr->Add(attach);

	// Set up a dimension constraint so the button has a minimum and maximum width.
	ZafDimensionConstraint *dim = new ZafDimensionConstraint(button, ZAF_DNCF_WIDTH);
	dim->SetMinimum(20);
	dim->SetMaximum(50);
	gmgr->Add(dim);

	Add(button);
}

void MainWindow::SetUpStatusBar(void)
{
	// Create the status bar.
	statusBar = new ZafStatusBar(0, 0, 0, 1);

	// Create a separate geometry manager for the status bar.
	ZafGeometryManager *statusGmgr = new ZafGeometryManager;
	statusBar->Add(statusGmgr);

	ZafString *string = new ZafString(0, 0, 10,
		new ZafStringData("Right, stretching attachment to the date.  Date is attached at right."));
	statusBar->Add(string);

	ZafDate *date = new ZafDate(12, 0, 12);
	date->SetAutoClear(false);
	date->SetViewOnly(true);
	date->SetNoncurrent(true);
	statusBar->Add(date);

	// The date is attached to the right side of the window.
	ZafAttachment *attach = new ZafAttachment(date, ZAF_ATCF_RIGHT);
	attach->SetOffset(0);
	statusGmgr->Add(attach);

	// The string has its right side attached to the date and is stretched.
	attach = new ZafAttachment(string, ZAF_ATCF_RIGHT);
	attach->SetOppositeSide(true);
	attach->SetStretch(true);
	attach->SetReference(date);
	attach->SetOffset(1);
	statusGmgr->Add(attach);

	Add(statusBar);
}

MainWindow::MainWindow(ZafIChar *name, ZafObjectPersistence &persist) :
	ZafWindow(name, persist)
{
	SetUpStatusBar();
	SetUpTexts();
	SetUpButton();

	zafWindowManager->Center(this);
}
