/////////////////////////////////////////////////////////////////////////////
// Name:        xh_dblistc.cpp
// Purpose:     XML resource for wxDbListCtrl
// Author:      Aleksandras Gluchovas
// Created:     2000/09/09
// RCS-ID:      $Id: xh_dblistc.cpp,v 1.2 2001/04/19 21:09:25 georgetasker Exp $
// Copyright:   (c) 2000 Aleksandras Gluchovas
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////
 
#ifdef __GNUG__
#pragma implementation "xh_glistc.h"
#endif

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

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

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

#include "wx/wspp/xh_dblistc.h"
#include "wx/wspp/dblist.h"

wxDbListCtrlXmlHandler::wxDbListCtrlXmlHandler() 
	: wxXmlResourceHandler() 
{
    ADD_STYLE(wxLC_SORT_DESCENDING);
    AddWindowStyles();
}


wxObject *wxDbListCtrlXmlHandler::DoCreateResource()
{ 
	wxDbListCtrl* list = wxDynamicCast(m_Instance, wxDbListCtrl);

	if ( list )

		list->Create( m_ParentAsWindow, 
					  GetID(), GetPosition(), GetSize(),
					  GetStyle(),
					  GetName() );
	else
    list = new wxDbListCtrl( m_ParentAsWindow,
						     GetID(),
                             GetPosition(), GetSize(),
                             GetStyle(),
                             GetName() );

    SetupWindow(list);

	wxString query = GetParamValue( "query" );
	
	if ( query.Length() )
	{
		MyODBCCursor* cursor = new MyODBCCursor();
		cursor->ODBCSetup( GetParamValue( "dsn" ),
						   GetParamValue( "user" ),
						   GetParamValue( "password" ) );

		list->SetDataCursor( cursor );
		
		wxString sort = GetParamValue( "sort" );
		wxString desc = GetParamValue( "descending" );

		if ( sort.Length() )
		{
			desc = desc.MakeUpper();
			list->Sort( sort, desc != "TRUE" );
		}

		list->RunQuery( query );
	}
    
    return list;
}

bool wxDbListCtrlXmlHandler::CanHandle(wxXmlNode *node)
{
    return IsOfClass(node, wxT("wxDbListCtrl"));
}