/*********************************************************
 *
 * Test EZ_WIDGET_ROW_COLUMN, (gridbag geometry manager)
 *
 *********************************************************/

#include "EZ.h"
void my_exit(void *a, void *b)
{
  EZ_Shutdown();
  exit(0);
}

main(ac,av)
     int ac; char **av;
{
  EZ_Widget *gb, *tmp;
  char str[128];
  int i, j, xx,yy;

  EZ_Initialize(ac,av,0);
  srand(getpid());

  gb = EZ_CreateWidget(EZ_WIDGET_ROW_COLUMN, NULL,
		       EZ_GRID_CONSTRAINS, EZ_ROW, 1, 0, 10, 20,		       
		       0);


  EZ_ConfigureWidget(gb, 
		     /* EZ_PADX, 0, EZ_PADY, 0,*/
		     EZ_BORDER_TYPE, EZ_BORDER_SUNKEN,
		     EZ_BORDER_WIDTH, 5,
		     EZ_IPADX, 40, 
		     EZ_IPADY, 40, 
		     EZ_EMBEDER,1,
		     /* EZ_WIDTH, 300, EZ_HEIGHT, 400, */
		     EZ_GRID_CONSTRAINS, EZ_ROW, 1, 0, 10, 20,
		     EZ_GRID_CONSTRAINS, EZ_ROW, 6, 0, 10, 0,
		     EZ_GRID_CONSTRAINS, EZ_ROW, 4, 0, 20, 30,
		     EZ_GRID_CONSTRAINS, EZ_COLUMN, 7, 0, 10, 30,
		     EZ_GRID_CONSTRAINS, EZ_COLUMN, 3, 0, 10, 40,
		     0);

  for(xx=0,i = 0; i < 8; i++,xx++)
    {
      if(xx == 5) xx++; /* save the 5th row */
      for(yy=0,j = 0; j < 7; j++,yy++)
	{
	  if( yy == 6) yy++; /* save the 2nd column */
	  if(i ==3 && j == 4)
	    {
	      tmp = EZ_CreateLabel(gb,"The grid bag geometry manager");
	      EZ_ConfigureWidget(tmp,
				 EZ_EXPAND, 1,
				 EZ_GRID_CELL_PLACEMENT, EZ_FILL_BOTH,0,
				 EZ_BACKGROUND, "green",
				 /*EZ_WIDTH, 400,*/
				 EZ_GRID_CELL_GEOMETRY, xx,yy, 1, 1,
				 0);
	    }
	  else
	    {
	      sprintf(str, "B[%d %d]", j,i);		    
	      tmp =EZ_CreateWidget(EZ_WIDGET_NORMAL_BUTTON, gb,
				   EZ_LABEL_STRING, str,
				   EZ_GRID_CELL_GEOMETRY, xx,yy, 1, 1,
				   /* EZ_EXPAND,1,*/
				   EZ_GRID_CELL_PLACEMENT, EZ_FILL_BOTH,0,
				   0);
				   
	      if(i==0 && j == 0)
		EZ_ConfigureWidget(tmp, EZ_CALLBACK, my_exit, NULL,
				   EZ_IMAGE_FILE, "brick.jpg",
				   0);
	    }				    

	}
    }
  {
    tmp = EZ_CreateLabel(gb,"test");
    EZ_ConfigureWidget(tmp,
		       EZ_BACKGROUND, "red",
		       EZ_EXPAND, 1,
		       EZ_GRID_CELL_PLACEMENT, EZ_FILL_VERTICALLY,0,
		       EZ_GRID_CELL_GEOMETRY, 5,1, 1, 5,
		       0);
    {
      EZ_Widget *ggg, *gb1 = EZ_CreateRowColumn(gb);
      int k,l;
      EZ_ConfigureWidget(gb1, EZ_GRID_CELL_GEOMETRY, 2,6, 6, 1,
			 EZ_BORDER_WIDTH, 4, 
			 EZ_BORDER_TYPE, EZ_BORDER_RIDGE,
			 EZ_BACKGROUND,"bisque",
			 EZ_GRID_CONSTRAINS, EZ_COLUMN, 1, 0, 100, 0,
			 EZ_GRID_CONSTRAINS, EZ_ROW, 1, 0, 100, 0,
			 EZ_GRID_CELL_PLACEMENT, EZ_FILL_BOTH, EZ_TOP_LEFT,
			 0);
      for(k = 0; k < 4; k++)
	for(l = 0; l < 3; l++)
	  {
	    sprintf(str, "A[%d %d]", l,k);		    
	    ggg = EZ_CreateWidget(EZ_WIDGET_NORMAL_BUTTON, gb1, 
				  EZ_LABEL_STRING, str,
				  EZ_EXPAND, 1,
				  EZ_GRID_CELL_GEOMETRY, k,l, 1, 1,
				  EZ_GRID_CELL_PLACEMENT, 0,0,
				  0);
	  }
    }
  }
  tmp = EZ_CreateFreeLabel(gb, "get out of here ");
  EZ_ConfigureWidget(tmp, EZ_BORDER_TYPE, EZ_BORDER_RIDGE,
		     EZ_BORDER_WIDTH, 2, EZ_BACKGROUND, "#af00af",0);
  tmp = EZ_CreateEntry(tmp, "this is a test");
  EZ_DisplayWidget(gb);
  EZ_EventMainLoop();
}
