/* This demo show the different boxtypes */

#include "forms.h"

static int border = FL_TRANSIENT;

typedef struct { int mode; char *name; } Gmode;
#define VN(a) {a,#a}
static Gmode gmode[] =
{
  VN(StaticGray), VN(GrayScale), VN(StaticColor),
  VN(PseudoColor), VN(TrueColor), VN(DirectColor),
};

#include "srs.xbm"

/*************** Callback **********************/

FL_FORM *form;
FL_OBJECT *tobj[18], *exitob, *btypeob, *modeob;

void 
boxtype_cb (FL_OBJECT * ob, long arg)
{
  int i;
  fl_freeze_form (form);
  fl_redraw_form (form);
  for (i = 0; i < 18; i++)
    fl_set_object_boxtype (tobj[i], fl_get_choice (ob) - 1);
  fl_unfreeze_form (form);
}

void 
mode_cb (FL_OBJECT * ob, long arg)
{
  static int lval = -1;
  int val = fl_get_choice (ob);
  int  db = 0;

  if (val == lval || val <= 0)
    return;

  fl_hide_form (form);
  if (!fl_mode_capable (gmode[val - 1].mode, FL_MINDEPTH))
  {
      fl_set_choice(ob, lval);
      val = lval;
  }
  fl_set_graphics_mode (gmode[val - 1].mode, db);
  fl_show_form (form, FL_PLACE_POSITION, border, "Box types");
  lval = val;
}

/*************** Creation Routines *********************/

void 
create_form_form (void)
{
  FL_OBJECT *obj;

  form = fl_bgn_form(FL_NO_BOX, 720, 520);
  obj = fl_add_box(FL_UP_BOX, 0, 0, 720, 520, "");
  fl_set_object_color(obj, FL_BLUE, FL_COL1);
  obj = fl_add_box(FL_DOWN_BOX, 10, 10, 700, 420, "");
  fl_set_object_color(obj, FL_COL1, FL_COL1);
  obj = fl_add_box(FL_DOWN_BOX, 10, 440, 700, 70, "");
  fl_set_object_color(obj, FL_SLATEBLUE, FL_COL1);
  tobj[0] = obj = fl_add_box(FL_UP_BOX, 30, 300, 110, 110, "Box");
  tobj[1] = obj = fl_add_text(FL_NORMAL_TEXT, 30, 250, 110, 30, "Text");
  tobj[2] = obj = fl_add_bitmap(FL_NORMAL_BITMAP, 40, 160, 90, 80, "Bitmap");
  fl_set_object_color(obj, FL_BLUE, obj->col2);
  tobj[3] = obj = fl_add_chart(FL_BAR_CHART, 160, 300, 160, 110, "Chart");
  tobj[4] = obj = fl_add_clock(FL_ANALOG_CLOCK, 40, 40, 90, 90, "Clock");
  fl_set_object_dblbuffer(tobj[4],1);
  tobj[5]=obj=fl_add_button(FL_NORMAL_BUTTON, 340, 380, 120, 30, "Button");
  tobj[6]=obj=fl_add_lightbutton(FL_NORMAL_BUTTON,340,340,120,30,"Lightbutton");
  tobj[7]=obj=fl_add_roundbutton(FL_NORMAL_BUTTON,340,300,120,30,"Roundbutton");
  tobj[8]=obj=fl_add_slider(FL_VERT_SLIDER, 160, 40, 40, 230, "Slider");
  tobj[9]=obj=fl_add_valslider(FL_VERT_SLIDER, 220, 40, 40, 230, "Valslider");
  tobj[10]=obj=fl_add_dial (FL_LINE_DIAL, 280, 170, 100, 100, "Dial");
  tobj[11]=obj=fl_add_positioner(FL_NORMAL_POSITIONER,280,40,150,100, "Positioner");
  tobj[12]=obj=fl_add_counter (FL_NORMAL_COUNTER,480,380,210,30, "Counter");
  tobj[13]=obj=fl_add_input (FL_NORMAL_INPUT, 520,320,170,30, "Input");
  tobj[14]=obj=fl_add_menu (FL_PUSH_MENU, 400, 250, 100, 30, "Menu");
  tobj[15]=obj=fl_add_choice (FL_NORMAL_CHOICE, 580, 240, 110, 30, "Choice");
  tobj[16]=obj=fl_add_timer (FL_VALUE_TIMER, 580, 280, 110, 30, "Timer");
  tobj[17]=obj=fl_add_browser (FL_NORMAL_BROWSER,450,40,240, 180, "Browser");
  exitob=obj= fl_add_button (FL_NORMAL_BUTTON, 590, 460, 100, 30, "Exit");
  btypeob=obj= fl_add_choice (FL_NORMAL_CHOICE,110,460, 130, 30, "Boxtype");
  fl_set_object_callback (obj, boxtype_cb, 0);
  modeob = obj=fl_add_choice(FL_NORMAL_CHOICE,370,460,130,30,"Graphics mode");
  fl_set_object_callback (obj, mode_cb, 0);
  fl_end_form ();
}
/*---------------------------------------*/

void 
create_the_forms (void)
{
  create_form_form ();
}

/*************** Main Routine ***********************/

char *browserlines[] = {
   " ", "@C1@c@l@bObjects Demo",   " ",
   "This demo shows you all",      "objects that currently",
   "exist in the Forms Library.",  " ",
   "You can change the boxtype",   "of the different objects",
   "using the buttons at the",     "top of the form. Note that",
   "some combinations might not",  "look too good. Also realize",
   "that for all object classes",  "many different types are",
   "available with different",     "behaviour.", " ",
   "With this demo you can also",  "see the effect of the drawing",
   "mode on the appearance of the","objects.",
   0
};

char *btypetext[] = {
   "no box", "up box", "down box",
   "flat box", "border box", "shadow box",
   "frame box", "rounded box", "rflat box",
   "rshadow box", /*  "oval box", */
    0
};

int
main (int argc, char *argv[])
{
  FL_OBJECT *ob;
  FL_COLOR c = FL_BLACK;
  char **p;

  fl_initialize(argv[0], "FormDemo", 0, 0 ,&argc, argv);
  create_the_forms ();
  fl_set_bitmap_data (tobj[2], sorceress_width, sorceress_height, sorceress_bits);
  fl_add_chart_value (tobj[3], 15, "item 1", c++);
  fl_add_chart_value (tobj[3], 5, "item 2", c++);
  fl_add_chart_value (tobj[3], -10, "item 3", c++);
  fl_add_chart_value (tobj[3], 25, "item 4", c++);
  fl_set_menu (tobj[14], "item 1|item 2|item 3|item 4|item 5");
  fl_addto_choice (tobj[15], "item 1");
  fl_addto_choice (tobj[15], "item 2");
  fl_addto_choice (tobj[15], "item 3");
  fl_addto_choice (tobj[15], "item 4");
  fl_addto_choice (tobj[15], "item 5");
  fl_set_timer (tobj[16], 1000);

  for ( p = browserlines; *p; p++)
     fl_add_browser_line (tobj[17], *p);

  for ( p = btypetext; *p; p++)
     fl_addto_choice(btypeob, *p);

  {
    int i;
    Gmode *g = gmode, *gs = g + sizeof (gmode) / sizeof (gmode[0]);
    for (i = 1; g < gs; g++, i++)
    {
      fl_addto_choice (modeob, g->name);
      if(!fl_mode_capable(g->mode, FL_MINDEPTH))
        fl_set_choice_item_mode(modeob, i, FL_PUP_GRAY);
    }
  }
  fl_set_choice (modeob, fl_vmode+1);

  fl_show_form (form, FL_PLACE_MOUSE, border, "Box types");
  while((ob = fl_do_forms ()) != exitob)
     ;
  fl_hide_form (form);
  return 0;
}
