#include <gtk/gtk.h>

static GtkWidget *
create_bbox1 (gint  horizontal,
             char *title,
             gint  spacing,
             gint  layout)
{
  GtkWidget *frame;
  GtkWidget *bbox;
//  GtkWidget *button;

  frame = gtk_frame_new (title);

  if (horizontal)
    bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  else
    bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);

  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_container_add (GTK_CONTAINER (frame), bbox);

  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);

  GtkWidget *label_latex = gtk_label_new(NULL);
  gtk_label_set_markup (GTK_LABEL (label_latex),    "<span foreground=\"midnightblue\"  >LaTeX</span>");
  gtk_container_add (GTK_CONTAINER (bbox), label_latex);

  GtkWidget *latex_entry = gtk_entry_new();
//gtk_entry_new_with_max_length(10);
  gtk_entry_set_placeholder_text (GTK_ENTRY (latex_entry), "latex -synctex=1 -interaction=nonstopmode %.tex"); /* imposto il testo trasparente che scompare quando clicco o scrivo */
  gtk_widget_grab_focus(latex_entry);
  gtk_container_add (GTK_CONTAINER (bbox), latex_entry);


    GtkWidget *label_pdflatex = gtk_label_new(NULL);
  gtk_label_set_markup (GTK_LABEL (label_pdflatex),    "<span foreground=\"midnightblue\"  >PdfLaTex</span>");
  gtk_container_add (GTK_CONTAINER (bbox), label_pdflatex);

  latex_entry = gtk_entry_new();
//gtk_entry_new_with_max_length(10);
  gtk_entry_set_placeholder_text (GTK_ENTRY (latex_entry), "pdflatex -synctex=1 -interaction=nonstopmode %.tex"); /* imposto il testo trasparente che scompare quando clicco o scrivo */
  gtk_widget_grab_focus(latex_entry);
  gtk_container_add (GTK_CONTAINER (bbox), latex_entry);

  GtkWidget *label_dvi2ps = gtk_label_new(NULL);
  gtk_label_set_markup (GTK_LABEL (label_dvi2ps),    "<span foreground=\"midnightblue\"  >DviPs</span>");
  gtk_container_add (GTK_CONTAINER (bbox), label_dvi2ps);

  latex_entry = gtk_entry_new();
//gtk_entry_new_with_max_length(10);
  gtk_entry_set_placeholder_text (GTK_ENTRY (latex_entry), "dvips -o %.ps %.dvi"); /* imposto il testo trasparente che scompare quando clicco o scrivo */
  gtk_widget_grab_focus(latex_entry);
  gtk_container_add (GTK_CONTAINER (bbox), latex_entry);


  return frame;
}

static GtkWidget *
create_bbox2 (gint  horizontal,
             char *title,
             gint  spacing,
             gint  layout)
{
  GtkWidget *frame;
  GtkWidget *bbox;
//  GtkWidget *button;

  frame = gtk_frame_new (title);

  if (horizontal)
    bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  else
    bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);

  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_container_add (GTK_CONTAINER (frame), bbox);

  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);

  GtkWidget *label_dvi2ps = gtk_label_new(NULL);
  gtk_label_set_markup (GTK_LABEL (label_dvi2ps),    "<span foreground=\"midnightblue\"  >DviPs</span>");
  gtk_container_add (GTK_CONTAINER (bbox), label_dvi2ps);

  GtkWidget *latex_entry = gtk_entry_new();
//gtk_entry_new_with_max_length(10);
  gtk_entry_set_placeholder_text (GTK_ENTRY (latex_entry), "dvips -o %.ps %.dvi"); /* imposto il testo trasparente che scompare quando clicco o scrivo */
  gtk_widget_grab_focus(latex_entry);
  gtk_container_add (GTK_CONTAINER (bbox), latex_entry);

  return frame;
}

static GtkWidget *
create_bbox3 (gint  horizontal,
             char *title,
             gint  spacing,
             gint  layout)
{
  GtkWidget *frame;
  GtkWidget *bbox;
//  GtkWidget *button;

  frame = gtk_frame_new (title);

  if (horizontal)
    bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  else
    bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);

  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_container_add (GTK_CONTAINER (frame), bbox);

  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);

  GtkWidget *label_latex = gtk_label_new(NULL);
  gtk_label_set_markup (GTK_LABEL (label_latex),    "<span foreground=\"midnightblue\"  >LaTeX</span>");
  gtk_container_add (GTK_CONTAINER (bbox), label_latex);

  GtkWidget *latex_entry = gtk_entry_new();
//gtk_entry_new_with_max_length(10);
  gtk_entry_set_placeholder_text (GTK_ENTRY (latex_entry), "latex -synctex=1 -interaction=nonstopmode %.tex"); /* imposto il testo trasparente che scompare quando clicco o scrivo */
  gtk_widget_grab_focus(latex_entry);
  gtk_container_add (GTK_CONTAINER (bbox), latex_entry);

  return frame;
}


static GtkWidget *
create_bbox4 (gint  horizontal,
             char *title,
             gint  spacing,
             gint  layout)
{
  GtkWidget *frame;
  GtkWidget *bbox;
   GtkWidget *radio1, *radio2, *entry ; //*label
//  GtkWidget *button;

  frame = gtk_frame_new (title);

  if (horizontal)
    bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  else
    bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);

  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_container_add (GTK_CONTAINER (frame), bbox);

  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);

   radio1 = gtk_radio_button_new (NULL);
   entry = gtk_entry_new ();
   gtk_container_add (GTK_CONTAINER (radio1), entry);
//   gtk_entry_set_inner_border  (entry, 2);

   /* Create a radio button with a label */
   radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1),
                                                         "Embeded Viewer.");
   /* Pack them into a box, then show all the widgets */
   gtk_box_pack_start (GTK_BOX (bbox), radio1, TRUE, TRUE, 2);
   gtk_box_pack_start (GTK_BOX (bbox), radio2, TRUE, TRUE, 2);

  return frame;
}

static GtkWidget *
create_bbox5 (gint  horizontal,
             char *title,
             gint  spacing,
             gint  layout)
{
  GtkWidget *frame;
  GtkWidget *bbox;
GtkWidget  *button,  *fixed;  // *separator,

  frame = gtk_frame_new (title);

  if (horizontal)
    bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  else
    bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);

  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_container_add (GTK_CONTAINER (frame), bbox);

  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);

              fixed = gtk_fixed_new();
         gtk_container_add(GTK_CONTAINER(bbox), fixed);
         //gtk_box_pack_start (GTK_BOX (box0), fixed, TRUE, TRUE, 0);
         gtk_widget_show(fixed);

        button=gtk_check_button_new_with_label("Dvi Viewer");
        gtk_fixed_put (GTK_FIXED (fixed), button, 15, 10);


        button=gtk_check_button_new_with_label("Ps Viewer");
    gtk_fixed_put (GTK_FIXED (fixed), button, 15, 40);

    button=gtk_check_button_new_with_label("Pdf Viewer \042evince\042");
    gtk_fixed_put (GTK_FIXED (fixed), button, 15, 70);

  return frame;
}


static GtkWidget *
create_bbox6 (gint  horizontal,
             char *title,
             gint  spacing,
             gint  layout)
{
  GtkWidget *frame;
  GtkWidget *bbox;
 GtkWidget *button;

  frame = gtk_frame_new (title);

  if (horizontal)
    bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  else
    bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);

  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_container_add (GTK_CONTAINER (frame), bbox);

  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);

    button=gtk_check_button_new_with_label("state1/2");
    gtk_container_add (GTK_CONTAINER (bbox), button);
    g_signal_connect (button, "toggled",
                      (GCallback)togg,
                     (gpointer *)button);

  return frame;
}

GtkWidget *
do_button_box (GtkWidget *do_widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *main_vbox;
  GtkWidget *vbox;
  GtkWidget *hbox;
  GtkWidget *frame_horz;
  GtkWidget *frame_vert;

  if (!window)
  {
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_screen (GTK_WINDOW (window),
                           gtk_widget_get_screen (do_widget));
    gtk_window_set_title (GTK_WINDOW (window), "»» I '♥''♥'♥...  A.r.a.b.T.e.X ««");

  /*  g_signal_connect (window, "destroy",
                      G_CALLBACK (gtk_widget_destroyed),
                      &window);
*/
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

	gtk_widget_set_size_request(window, 700, 50);
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
    gtk_window_set_icon_name (GTK_WINDOW (window), SELIMB/*selim2.png"*/);
    gtk_window_set_default_icon_name(SELIMB/*selim2.png"*/);
    gtk_window_set_icon_from_file(GTK_WINDOW(window), SELIMB/*selim2.png"*/, NULL);
	g_signal_connect(G_OBJECT(window), "delete_event",
			 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
	g_signal_connect(G_OBJECT(window), "key_press_event",
			 G_CALLBACK(key_pressed), NULL);    /** voir "gboolean  key_pressed" dans action.c ligne 351 en bas*/
	gtk_widget_realize(window);
    /**...............................  H E A D E R   B A R ..........................................*/

/**........................................... H E A D E R      B A R     E N D   ................................*/

    main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
    gtk_container_add (GTK_CONTAINER (window), main_vbox);

    frame_horz = gtk_frame_new ("Commands (% : filename witout extension - @ : line number )");
    gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);

    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
    gtk_container_add (GTK_CONTAINER (frame_horz), vbox);

    gtk_box_pack_start (GTK_BOX (vbox),
                        create_bbox1 (TRUE, "LaTeX", 40, GTK_BUTTONBOX_SPREAD),
                        TRUE, TRUE, 0);

    gtk_box_pack_start (GTK_BOX (vbox),
                        create_bbox2 (TRUE, "PdfLaTeX", 40, GTK_BUTTONBOX_EDGE),
                        TRUE, TRUE, 5);

    gtk_box_pack_start (GTK_BOX (vbox),
                        create_bbox3 (TRUE, "View", 40, GTK_BUTTONBOX_START),
                        TRUE, TRUE, 5);

    gtk_box_pack_start (GTK_BOX (vbox),
                        create_bbox4 (TRUE, "Preferences", 40, GTK_BUTTONBOX_END),
                        TRUE, TRUE, 5);

    frame_vert = gtk_frame_new ("Options");
    gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);

    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
    gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
    gtk_box_pack_start (GTK_BOX (hbox),
                        create_bbox5 (FALSE, "Viewer", 30, GTK_BUTTONBOX_EDGE),
                        TRUE, TRUE, 5);

    gtk_box_pack_start (GTK_BOX (hbox),
                        create_bbox4 (FALSE, "Externel Viewer", 30, GTK_BUTTONBOX_SPREAD),
                        TRUE, TRUE, 0);



    gtk_box_pack_start (GTK_BOX (hbox),
                        create_bbox5 (FALSE, "Settings", 30, GTK_BUTTONBOX_START),
                        TRUE, TRUE, 5);

    gtk_box_pack_start (GTK_BOX (hbox),
                        create_bbox6 (FALSE, "Interface Appearance", 30, GTK_BUTTONBOX_END),
                        TRUE, TRUE, 5);
  }

  if (!gtk_widget_get_visible (window))
    {
      gtk_widget_show_all (window);
    }
  else
    {
      gtk_widget_destroy (window);
      window = NULL;
    }

  return window;
}

