#ifdef __cplusplus
extern "C"
{
#endif

/* Libraries */
#include <libraries/mui.h>
#include <libraries/gadtools.h> /* for BARLABEL in MenuItem */

/* Prototypes */
#ifdef __GNUC__
#include <proto/muimaster.h>
#include <proto/exec.h>
#include <proto/alib.h>
#include <proto/dos.h>
#else
#include <clib/muimaster_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#include <pragmas/muimaster_pragmas.h>
#endif /* __GNUC__ */

/*  Ansi  */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#ifdef __cplusplus
}
#endif

/* Include generated by GenCodeC */
#include <SearchGUI.h>


long __saveds SearchGUI::ads_RecordFillFunc(register __a0 Hook *hook,register __a2 char **c,register __a1 DataRecord* record)
{
	 register int n = 0;
	 register char *cc;

    if (record)
    {
		/*
			This is pretty easy, isn't it ;)
			the []-operator is overloaded in the DataRecord-class
			and returns a char* Value of the field with index i.
		*/

		while (cc = (*record)[n++]) *c++ = cc;
    }
    else
    {
    	/*
    		Column Names are generated from a global list. There is no
    		way to deliver data sources if the datapointer (in our case
    		a DataRecord) is NULL.
    		The column list (gl_CycleFields) is a char** array where
    		the last one contains char[n] = NULL;
    	*/

		// cy_FieldName is a global const right now,
		// because I can't access class private members here.
		if (cy_FieldNames)
		{
			while (cc = cy_FieldNames[n++]) *c++ = cc;
		}

/*    hook->Data doesn't work, either.

		char **col_Title = (char**)hook->h_Data;
		if (col_Title)
		{
			printf("%d ****",n);
			while (cc = col_Title[n++])
			{
				printf("%s ",cc);
				*c++ = cc;
			}
			puts("****");
		}
*/
    }
    return(0);
}

long SearchGUI::ads_RecordConstructFunc(register __a0 Hook *hook,register __a2 char **c,register __a1 DataRecord* record)
{
	DataRecord *data_record = NULL;

	/*
		A DataRecord can easily be generated from a DataTable.
		In this case it generates a clone of the actual DataRecord.
		This clone is hooked into the list.
	*/
	data_record = new DataRecord((DataTable*)record);

	return (long)data_record;
}

long SearchGUI::ads_RecordDestructFunc(register __a0 Hook *hook,register __a2 char **c,register __a1 DataRecord* record)
{
	/*
		Now, the list contains a DataRecord object, and
		if there is one, it is simple "destructed" here.
	*/

	if (record) delete record;

	return NULL;
}

long SearchGUI::ads_RecordCompareFunc(register __a0 Hook *hook,register __a2 char **r1,register __a1 DataRecord* r2)
{
	/*
		This is the compare hook to sort DataRecords into
		the NList. Currently only the first field is used to sort.
		Later the column is selected by clicking on the column header
		in the list.
	*/

	if (r1 && r2)
	{
		register char *s1,*s2;
		s1 = (*(DataRecord*)r1)[0];
		s2 = (*r2)[0];

		return strcmp(s1,s2);
	}
	else
		return 0;
}
