#include "EZ.h" 

static void button_callback(EZ_Widget *button);
static void hack(EZ_Widget *button);

EZ_Widget *buttons[300];

main(int argc, char **argv)
{
  EZ_Widget *frame, *tmp;
  int i, j, k,m,n;
  char label[128];

  EZ_Initialize(argc,argv,0);       /* initialize EZWGL    */
  srand(getpid());
  frame = EZ_CreateFrame(NULL, NULL);
  EZ_ConfigureWidget(frame,
        EZ_WIDTH, 300, EZ_HEIGHT, 300, 0);

  for(i = 0; i < 200; i++)
    {
      k = (rand() >> 5) % 10;
      for(j = 0; j < k; j++)
	label[j] = 'a' + ((rand() >> 5) % 26);
      label[j] = 0;
      sprintf(label+j, "%d", i);
      tmp = EZ_CreateFreeLabel(frame, label);
      EZ_SetWidgetIntData(tmp, i);
      EZ_ConfigureWidget(tmp, 
			 EZ_CALL_BACK, button_callback, NULL,
			 EZ_BORDER_TYPE, EZ_BORDER_RAISED,
			 EZ_BORDER_WIDTH, 2,
			 EZ_PROPAGATE, 0,
			 EZ_X, ( (rand()>>5) % 280),
			 EZ_Y, ( (rand()>>5) % 280), 0);
      if(i > 197)
	{
	  EZ_Widget *aaa;
	  if(i == 198) EZ_ConfigureWidget(tmp,EZ_ORIENTATION, EZ_VERTICAL,
					  EZ_FILL_MODE, EZ_FILL_BOTH,0);
	  for(m = 0; m < 5; m++)
	    {
	      k = (rand() >> 5) % 10;
	      for(j = 0; j < k; j++)
		label[j] = 'a' + ((rand() >> 5) % 26);
	      label[j] = 0;
	      sprintf(label+j, "%d", i);
	      aaa = EZ_CreateButton(tmp, label, 0);
	      EZ_ConfigureWidget(aaa, EZ_FOREGROUND, "red",
				 EZ_CALL_BACK, hack, NULL,0);
	      if(m == 3)
		EZ_ConfigureWidget(aaa, EZ_PIXMAP_FILE,
				   "PIXMAPS/circle_weave.xpm", 0);
	    }
	}
    }
  EZ_DisplayWidget(frame);           /* show the button     */
  EZ_EventMainLoop();               /* handle mouse inputs */
}

static void button_callback(EZ_Widget *button)
{
  int i = (rand() >>5) % 3;
  if( i == 0)
    EZ_ConfigureWidget(button, EZ_PIXMAP_FILE, "fish/f01.h.gif_1.xpm", 0);
  else
    EZ_DestroyWidget(button);
}

static void hack(EZ_Widget *button)
{
  EZ_ConfigureWidget(button, EZ_PIXMAP_FILE, "PIXMAPS/marbled.xpm",0);
}
