/* 
 * Thomas Pantzer: xdemo.cc, v0.4.7  8.6.99 16:32 
 * 
 * 
 * Copyright 1999 by Thomas Pantzer
 * 
 * Permission to use, copy, modify, and distribute this software for noncommercial 
 * use and without fee is hereby granted, provided that the above copyright notice 
 * appear in all copies and that both that copyright notice and this permission 
 * notice appear in supporting documentation, and that the name of the Author not be 
 * used in advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission. The Author makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is" 
 * without expressed or implied warranty. 
 * 
 * 
 * pantec@isys2.informatik.uni-leipzig.de   (Thomas Pantzer) 
 * 
 */

/* Form definition file generated with fdesign. */

#include "copyright.h"


#include "forms.h"
#include <stdlib.h>
#include "xdemo.h"
#include "new_panel.h"
#include "t_runtime_obj.h"


#include "utils.h"

FD_demo *create_form_demo(char *name, int id, 
		int nsliders, int ncboxes, int nchoices,
		char **sliderName, char **BoxName, char **ChoiceName)
{
  FL_OBJECT *obj;
  FD_demo *fdui = (FD_demo *) fl_calloc(1, sizeof(*fdui));

  int width,height;

	width = 200 + ((nsliders) * 50);
	height = 70 + ((ncboxes+_bt_num) * 30);


	if (height < 260)
	   {
	    if (nsliders > 0)
	       height = 260;	 	
	   }

	
	if (nchoices > 0)
	   {
	    height = __max(height,310);	
	   }		


	fdui->demo = fl_bgn_form(FL_NO_BOX, width, height);

	int bw = fl_get_border_width();
	fl_set_border_width(2);
	obj = fl_add_box(FL_UP_BOX,0,0,width,height,"");


//	if (nsliders > 0)
	   fdui->slider = new FL_OBJECT *[nsliders];	

//	if ((ncboxes+_bt_num) > 0)
	   fdui->cbox = new FL_OBJECT *[ncboxes+_bt_num];	

//	if (nchoices > 0)
	   fdui->choice = new FL_OBJECT *[nchoices];	

/*
     fdui->slider[_sl_logival] = obj = fl_add_valslider(FL_VERT_NICE_SLIDER,30+(0*50),20,30,200,"L.Interval");
       fl_set_object_boxtype(obj,FL_FLAT_BOX);
       fl_set_object_color(obj,FL_COL1,FL_YELLOW);
       fl_set_object_lsize(obj,FL_DEFAULT_SIZE);
       fl_set_object_callback(obj,demo_slider_cb,(id*1000)+_sl_logival);
       fl_set_slider_bounds(obj, 1.00, 0.00);

     fdui->slider[_sl_logavg] = obj = fl_add_valslider(FL_VERT_NICE_SLIDER,30+(1*50),20,30,200,"Log-Avg.");
       fl_set_object_boxtype(obj,FL_FLAT_BOX);
       fl_set_object_color(obj,FL_COL1,FL_YELLOW);
       fl_set_object_lsize(obj,FL_DEFAULT_SIZE);
       fl_set_object_callback(obj,demo_slider_cb,(id*1000)+_sl_logavg);
       fl_set_slider_bounds(obj, 1.00, 0.00);
*/
  for (int i=0; i<(nsliders); i++)
    { 		
#ifdef DEBUG
     fprintf(stderr,"slider[%d]:0x%lx/0x%lx\t%s\n",i,(long)sliderName,(long)sliderName[i],sliderName[i]);	
     fflush(stderr);
#endif
     fdui->slider[i] = obj = fl_add_valslider(FL_VERT_NICE_SLIDER,30+(i*50),20,30,200,sliderName[i]);
       fl_set_object_boxtype(obj,FL_FLAT_BOX);
       fl_set_object_color(obj,FL_COL1,FL_YELLOW);
       fl_set_object_lsize(obj,FL_DEFAULT_SIZE);
       fl_set_object_callback(obj,demo_slider_cb,(id*1000)+i);
       fl_set_slider_bounds(obj, 1.00, 0.00);
    }


	int old_bw = fl_get_border_width();
	fl_set_border_width(1);

	for (int i=0; i<nchoices; i++)
	  { 		
#ifdef DEBUG
	   fprintf(stderr,"choice[%d]:0x%lx/0x%lx\t%s\n",i,(long)ChoiceName,(long)ChoiceName[i],ChoiceName[i]);	
	   fflush(stderr);
#endif
	   char *entries = strchr(ChoiceName[i],'@');

//	   fprintf(stderr,"choice %s %d 0x%08lx\n",st,i,(long)entries);

	   if (entries == NULL)
	      continue;
	
	   *entries = '\0';
	   entries++;
	 		   
	   fdui->choice[i] = obj = fl_add_choice(FL_NORMAL_CHOICE,20+(i*110),height - 45,100,30,ChoiceName[i]);
	   fl_addto_choice(obj,entries);
	   fl_set_object_lalign(obj,FL_ALIGN_TOP);	
           fprintf(stderr,"choice %d %s\n",i,entries);
	   fl_set_object_color(obj,FL_GREEN,FL_BLACK);

//	   fl_set_object_boxtype(obj,FL_UP_BOX);
//       fl_set_object_color(obj,FL_COL1,FL_YELLOW);
//       fl_set_object_lsize(obj,FL_DEFAULT_SIZE);

//	   fl_set_object_callback(obj,demo_choice_cb,(id*1000)+i);
//       fl_set_slider_bounds(obj, 1.00, 0.00);
	  }

	fl_set_border_width(old_bw);


  fdui->cbox[_bt_load] = obj = fl_add_checkbutton(FL_PUSH_BUTTON,width - 150,30,140,20,"Load on Start");
    fl_set_object_boxtype(obj,FL_FLAT_BOX);
    fl_set_object_lcolor(obj,FL_BOTTOM_BCOL);
    fl_set_object_lsize(obj,FL_NORMAL_SIZE);
    fl_set_object_callback(obj,do_nothing,(id*1000));

  fdui->cbox[_bt_save] = obj = fl_add_checkbutton(FL_PUSH_BUTTON,width - 150,60,140,20,"Save on Stop");
    fl_set_object_boxtype(obj,FL_FLAT_BOX);
    fl_set_object_lcolor(obj,FL_BOTTOM_BCOL);
    fl_set_object_lsize(obj,FL_NORMAL_SIZE);
    fl_set_object_callback(obj,do_nothing,(id*1000)+1);

  fdui->cbox[_bt_reset] = obj = fl_add_checkbutton(FL_TOUCH_BUTTON,width - 150,90,140,20,"Reset Params");
    fl_set_object_boxtype(obj,FL_FLAT_BOX);
    fl_set_object_lcolor(obj,FL_BOTTOM_BCOL);
    fl_set_object_lsize(obj,FL_NORMAL_SIZE);
    fl_set_object_callback(obj,demo_button_cb,(id*1000)+2);

  fdui->cbox[_bt_pause] = obj = fl_add_checkbutton(FL_PUSH_BUTTON,width - 150,120,140,20,"pause");
    fl_set_object_boxtype(obj,FL_FLAT_BOX);
    fl_set_object_lcolor(obj,FL_BOTTOM_BCOL);
    fl_set_object_lsize(obj,FL_NORMAL_SIZE);
    fl_set_object_callback(obj,demo_button_cb,(id*1000)+3);

  for (int i=_bt_num; i<(ncboxes+_bt_num); i++)
    {	 	
     fdui->cbox[i] = obj = fl_add_checkbutton(FL_PUSH_BUTTON,width - 150,40+(i*30),140,20,BoxName[i-_bt_num]);
       fl_set_object_boxtype(obj,FL_FLAT_BOX);
       fl_set_object_lcolor(obj,FL_BOTTOM_BCOL);
       fl_set_object_lsize(obj,FL_NORMAL_SIZE);
       fl_set_object_callback(obj,demo_button_cb,(id*1000)+i);
    } 	

  fl_end_form();
  fl_set_border_width(bw);

  fdui->demo->fdui = fdui;

  return fdui;
}


void done_form_demo(FD_demo *demo)
{
	delete [] demo->cbox;
	delete [] demo->slider;
	delete [] demo->choice;
}


/*---------------------------------------*/








/**/
/**/
/**/
/**/
/**/
/**/
/**/
/**/
/*****  End Of File  ****************************/
