#include "split2.hpp"

// Create a basic window class to add the splitters.
SplitterWindow::SplitterWindow(int left, int top, int width, int height) : 
	ZafWindow(left, top, width, height)
{
	// Add the normal support objects.
	AddGenericObjects(new ZafStringData("Splitter Window"));

	// Create a new ZafSplitter object and add it to the window.
	// The first splitter must have ZAF_AVAILABLE_REGION set while
	// any subsequent splitters must NOT have this set.

	// This is the horizontal splitter which will split the entire window.
	ZafSplitter *hSplit = new ZafSplitter(ZAF_HORIZONTAL_SPLITTER);
	hSplit->SetRegionType(ZAF_AVAILABLE_REGION);
	Add(hSplit);

	// This is the virtical splitter which splits the previous pane.
	ZafSplitter *vSplit = new ZafSplitter(ZAF_VERTICAL_SPLITTER, 15, false);
	Add(vSplit);
	hSplit->SetPreviousPaneObject(vSplit);

	// Add a text object to one side of the splitter by using
	// the SetPreviousPaneObject or SetNextPaneObject.  By definition
	// the top and left side of each splitter are the previous pane areas
	// while the bottom and right sides of a splitter are the next pane areas.
	ZafStringData *data = new ZafStringData("This is a text object.");
	ZafText *text = new ZafText(0, 0, 0, 0, data);
	text->SetBordered(true);
	text->Add(new ZafScrollBar(ZAF_VERTICAL_SCROLL));
	hSplit->SetNextPaneObject(text);
	Add(text);

	// Create a simple tree object to be one of the panes.
	ZafTreeList *tree = new ZafTreeList(0, 0, 0, 0);
	tree->SetBordered(true);
	tree->Add(new ZafTreeItem(ZAF_NULLP(ZafBitmapData),
		ZAF_NULLP(ZafBitmapData), ZAF_ITEXT("TreeItem")));
	vSplit->SetPreviousPaneObject(tree);
	Add(tree);

	// Create a simple vertical list object to be one of the panes.
	ZafVtList *list = new ZafVtList(0, 0, 0, 0);
	list->SetBordered(true);
	list->SetSelectionType(ZAF_EXTENDED_SELECTION);
	list->Add(new ZafScrollBar(ZAF_VERTICAL_SCROLL));
	for (int i = 0; i < 15; i++)
	{
		ZafIChar buff[50];
		sprintf(buff, ZAF_ITEXT("String %i"), i + 1);
		list->Add(new ZafString(0, 0, 0, new ZafStringData(buff)));
	}
	vSplit->SetNextPaneObject(list);
	Add(list);

	// Center the application window.
	zafWindowManager->Center(this);
}

int ZafApplication::Main()
{
	LinkMain();

	SplitterWindow *split = new SplitterWindow(0, 0, 60, 10);

	zafWindowManager->Add(split);

	Control();

	return (0);
}
