/////////////////////////////////////////////////////////////////////////////
// Name:        dbsequence.cc
// Purpose:     Database Objects
// Author:      Daniel Horak
// Modified by:
// RCS-ID:      $Id: dbsequence.cc,v 1.2 2004/01/01 13:56:19 horakdan Exp $
// Copyright:   (c) Daniel Horak
// Licence:     GPL
/////////////////////////////////////////////////////////////////////////////

// ============================================================================
// declarations
// ============================================================================

// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------

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

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include "config.h"
#include "xml.h"
#include "dbobject.h"
#include "dbsequence.h"


DBSequence::DBSequence(DataDesignerProject *project, DataDesignerContainer *container)
	:DBObject(DBSequenceType, "sequence", project, container), m_cycle(FALSE)
{
}

wxDialog *DBSequence::Editor(bool edit)
{
	return new DBSequenceEditor(this, edit);
}

void DBSequence::LoadXmlNode(wxXmlNode *node)
{
	if (node->GetName() == m_typestr) {
		DBObject::LoadXmlNode(node);
		
		m_increment	= node->GetPropVal("increment", wxEmptyString);
		m_minvalue	= node->GetPropVal("minvalue", wxEmptyString);
		m_maxvalue	= node->GetPropVal("maxvalue", wxEmptyString);
		m_start		= node->GetPropVal("start", wxEmptyString);
		m_cache		= node->GetPropVal("cache", wxEmptyString);
		LoadBoolProperty(node, "cycle", m_cycle, FALSE);
		
		wxXmlNode *child = node->GetChildren();
		wxString name;
		
		while (child) {
			name = child->GetName();
			if (name == "increment")
				LoadTextNode(child, "increment", m_increment);
			else if (name == "minvalue")
				LoadTextNode(child, "minvalue", m_minvalue);
			else if (name == "maxvalue")
				LoadTextNode(child, "maxvalue", m_maxvalue);
			else if (name == "start")
				LoadTextNode(child, "start", m_start);
			else if (name == "cache")
				LoadTextNode(child, "cache", m_cache);
			else if (name == "cycle")
				LoadBoolNode(child, "cycle", m_cycle, FALSE);
			
			child = child->GetNext();
		}
	} else {
		wxLogMessage("wrong type '%s'", node->GetName().c_str());
	}
}

wxXmlNode *DBSequence::GetXmlNode()
{
	wxXmlNode *node = DBObject::GetXmlNode();
	
	node->AddChild(GetTextNode("increment", m_increment));
	node->AddChild(GetTextNode("minvalue", m_minvalue));
	node->AddChild(GetTextNode("maxvalue", m_maxvalue));
	node->AddChild(GetTextNode("start", m_start));
	node->AddChild(GetTextNode("cache", m_cache));
	node->AddChild(GetBoolNode("cycle", m_cycle));
	
	return node;
}

/*
 * Editor
 */
DBSequenceEditor::DBSequenceEditor(DBObject *object, bool edit)
	: DBObjectEditor(_("Sequence"), wxSize(500,300), object, edit)
{
	new wxStaticText(m_page_general, -1, _("Increment"), wxPoint(10,60), wxSize(80,-1), wxALIGN_RIGHT);
	t1 = new wxTextCtrl(m_page_general, -1, wxEmptyString, wxPoint(100,60), wxSize(50,-1));
	
	c6 = new wxCheckBox(m_page_general, -1, _("Cycle"), wxPoint(210,60), wxSize(100,-1));

	new wxStaticText(m_page_general, -1, _("Minimal value"), wxPoint(10,85), wxSize(80,-1), wxALIGN_RIGHT);
	t2 = new wxTextCtrl(m_page_general, -1, wxEmptyString, wxPoint(100,85), wxSize(50,-1));

	new wxStaticText(m_page_general, -1, _("Maximal value"), wxPoint(210,85), wxSize(80,-1), wxALIGN_RIGHT);
	t3 = new wxTextCtrl(m_page_general, -1, wxEmptyString, wxPoint(320,85), wxSize(50,-1));

	new wxStaticText(m_page_general, -1, _("Start value"), wxPoint(10,110), wxSize(80,-1), wxALIGN_RIGHT);
	t4 = new wxTextCtrl(m_page_general, -1, wxEmptyString, wxPoint(100,110), wxSize(50,-1));

	new wxStaticText(m_page_general, -1, _("Cache"), wxPoint(210,110), wxSize(80,-1), wxALIGN_RIGHT);
	t5 = new wxTextCtrl(m_page_general, -1, wxEmptyString, wxPoint(320,110), wxSize(50,-1));
}

DBSequenceEditor::~DBSequenceEditor()
{
}

bool DBSequenceEditor::TransferDataFromWindow()
{
	DBSequence	*object = (DBSequence *)GetObject();

	DBObjectEditor::TransferDataFromWindow();
	
	object->m_increment	= t1->GetValue();
	object->m_minvalue	= t2->GetValue();
	object->m_maxvalue	= t3->GetValue();
	object->m_start		= t4->GetValue();
	object->m_cache		= t5->GetValue();
	object->m_cycle		= c6->GetValue();

	return TRUE;
}

bool DBSequenceEditor::TransferDataToWindow()
{
	DBSequence	*object = (DBSequence *)GetObject();
	
	DBObjectEditor::TransferDataToWindow();
	
	t1->SetValue(object->m_increment);
	t2->SetValue(object->m_minvalue);
	t3->SetValue(object->m_maxvalue);
	t4->SetValue(object->m_start);
	t5->SetValue(object->m_cache);
	c6->SetValue(object->m_cycle);
	
	return TRUE;
}

/*
 * Container
 */
DBSequenceContainer::DBSequenceContainer(DataDesignerProject *project, const wxTreeItemId& parent)
	: DataDesignerContainer(project, parent, "sequences")
{
}

DBObject *DBSequenceContainer::CreateObject()
{
	return new DBSequence(GetProject(), this);
}

void DBSequenceContainer::ShowList()
{
	SetList(new DBSequenceListCtrl(GetProject()->GetSplitter(), this));
	
	DataDesignerContainer::AddObjectsToListAndShow();
}

/*
 * ObjectList
 */
DBSequenceListCtrl::DBSequenceListCtrl(wxWindow *parent, DataDesignerContainer *container)
	: DBObjectListCtrl(parent, container)
{
}

DBSequenceListCtrl::~DBSequenceListCtrl()
{
}

void DBSequenceListCtrl::SetObject(long item, DBObject *object)
{
	DBSequence *sequence = (DBSequence *)object;
}


syntax highlighted by Code2HTML, v. 0.9.1