#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
//#include <stdio.h>
//#include <string.h>
//#include <glib/gi18n.h>
//#include "colors.c"
//#include "menu_pop_up.c"
//static GtkWidget *window = NULL;
/*......................................................*/
/** ..http://stuff.mit.edu/afs/athena/astaff/source/src-9.2/third/gtk2/examples/entry/  **/

void enter_callback( GtkWidget *widget,
                     GtkWidget *entry )
{
  ;
  //const gchar *entry_text;
  //entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
//  printf("Entry contents: %s\n", entry_text);
}
/*
void entry_toggle_editable( GtkWidget *checkbutton,
                            GtkWidget *entry )
{
  gtk_editable_set_editable (GTK_EDITABLE (entry),
                             GTK_TOGGLE_BUTTON (checkbutton)->activate);
}

void entry_toggle_visibility( GtkWidget *checkbutton,
                              GtkWidget *entry )
{
  gtk_entry_set_visibility (GTK_ENTRY (entry),
			    GTK_TOGGLE_BUTTON (checkbutton)->activate);
}
*/
/*......................................................*/



void about_show_configure(void)
{
	if (!window)
		about_create2();
	else
		gtk_window_present(GTK_WINDOW(window));
}
//#include </usr/include/vte-0.0/vte/vte.h>
static void
response_cb (GtkWidget *dialog,
             gint       response_id,
             gpointer   data)
{
  gtk_widget_destroy (dialog);
}

static gboolean
activate_link (GtkWidget   *label,
               const gchar *uri,
               gpointer     data)
{
  if (g_strcmp0 (uri, "keynav") == 0)
    {
      GtkWidget *dialog;
      GtkWidget *parent;

      parent = gtk_widget_get_toplevel (label);
      dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (parent),
                 GTK_DIALOG_DESTROY_WITH_PARENT,
                 GTK_MESSAGE_INFO,
                 GTK_BUTTONS_OK,
                 HOMEPAGE_URI);

      gtk_window_present (GTK_WINDOW (dialog));
      g_signal_connect (dialog, "response", (GCallback)response_cb, NULL);

      return TRUE;
    }

  return FALSE;
}
/*..............................................*/
typedef struct sdata {
  GtkWidget *entree;
  GtkWidget *label;
} tdata;
/*
gint copy(GtkWidget *widg, tdata *pdata)
{
  //  gchar *s,
  char *s;
  s = gtk_entry_get_text(GTK_ENTRY(pdata->entree));
  gtk_label_set_text( GTK_LABEL(pdata->label), s);

  return FALSE;
}
*/
//////////////////////////////////////////

gboolean callback_key_press_event_signal(GtkWidget *entry, GdkEvent  *event, gpointer user_data)
{
	g_printerr ("La fonction callback est bien appelée à chaque saisie d'un caractère dans le GtkEntry !\n");

	/* On récupère le GtkEntry dans le pointeur entry1. Tu peux en faire ce que tu veux à partir de là */

	return FALSE;
}

GtkWidget *create_conf1(void)
{
   GtkWidget  *page, *entry, *button, *label;
   tdata* pdata;
   page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 3);
  // gtk_window_set_title(GTK_WINDOW (window), "Configure guiTeX");
   gtk_container_set_border_width(GTK_CONTAINER(page), 250);
/*.........................................................*/
    label = gtk_label_new (NULL);
    gtk_label_set_markup (GTK_LABEL (label), "Quick LaTeX:");
    gtk_box_pack_start (GTK_BOX (page), label, FALSE, FALSE, 0);

        /* Create a buffer */
      GtkEntryBuffer *buffer = gtk_entry_buffer_new (NULL, 0);
    /* Create the second entry */
    entry = gtk_entry_new_with_buffer (buffer);
    gtk_entry_set_visibility (GTK_ENTRY (entry), TRUE);
    gtk_box_pack_start (GTK_BOX (page), entry, TRUE, TRUE, 40);
    //gtk_box_pack_start (GTK_BOX (page), entry, FALSE, FALSE, 0);
    GtkClipboard *clipboard = gtk_widget_get_clipboard (entry, GDK_SELECTION_CLIPBOARD);
    /* Connexion des signaux */
    gtk_clipboard_set_text (clipboard, gtk_entry_get_text (GTK_ENTRY (entry)), -1);
    g_signal_connect(G_OBJECT(entry), "key-press-event", G_CALLBACK(callback_key_press_event_signal), NULL);

    g_object_unref (buffer);

/*..........................................*/
// http://stuff.mit.edu/afs/athena/astaff/source/src-9.2/third/gtk2/examples/entry/entry.c
    GtkWidget *hbox;
    GtkWidget *check;
   gint tmp_pos;
//      gint text_length;
entry = gtk_entry_new();
gtk_entry_set_max_length (GTK_ENTRY (entry), 50);

  g_signal_connect (G_OBJECT (entry), "activate",
		      G_CALLBACK (enter_callback),
		      (gpointer) entry);

gtk_entry_set_text (GTK_ENTRY (entry), "latex -interaction=nonstopmode ");  // 0, GTK_ENTRY(entry)->text_length);
//   tmp_pos = GTK_ENTRY (entry)->text_length;
    gtk_editable_insert_text (GTK_EDITABLE (entry), " %.tex", -1, &tmp_pos);
    /*gtk_editable_select_region (GTK_EDITABLE (entry),
			        0, GTK_ENTRY (entry)->text_length);
			        */

//gtk_entry_append_text (GTK_ENTRY (entry), " world");
//  gtk_entry_set_editable(GTK_ENTRY(entry));
//gtk_box_pack_start (GTK_BOX (page), entry, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (page), entry, FALSE, FALSE, 0);
gtk_widget_show (entry);


    hbox = gtk_box_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (page), hbox);
    //gtk_box_pack_start (GTK_BOX (page), hbox, FALSE, FALSE, 0);
    gtk_widget_show (hbox);
   check = gtk_check_button_new_with_label ("Editable");
    gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
   /* g_signal_connect (G_OBJECT (check), "toggled",
	              G_CALLBACK (entry_toggle_editable), (gpointer) entry);
	              */
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
    gtk_widget_show (check);


      check = gtk_check_button_new_with_label ("Visible");
    gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
    /*g_signal_connect (G_OBJECT (check), "toggled",
	              G_CALLBACK (entry_toggle_visibility), (gpointer) entry);
	              */
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
    gtk_widget_show (check);

/**.............................................................*/
label = gtk_label_new("");
gtk_box_pack_end(GTK_BOX(page), label, TRUE, TRUE, 0);
//gtk_widget_set_usize(label, 250, 15);
gtk_widget_show(label);

pdata = g_malloc( sizeof(tdata) );
pdata->entree = entry;
pdata->label = label;

button = gtk_button_new_with_label("-->");
      gtk_widget_set_halign (button, GTK_ALIGN_END);
      gtk_widget_set_valign (button, GTK_ALIGN_CENTER);

gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0);
// GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
//gtk_signal_connect(button, "clicked", G_CALLBACK(copy), (gpointer)pdata);
gtk_widget_grab_default (button);
//gtk_widget_set_usize(button, 30, 15);
gtk_widget_show(button);

/*........................ COLORs.......................*/
// GdkRGBA color;  //<----- voir     "color.c "  ligne 6
/*
      color.red = 0.0;
      color.blue = 0.0;
      color.green = 0.0;
      color.alpha = 1.;
*/

      frame = gtk_frame_new (NULL);     //<----- voir     "color.c "  ligne 7.24
      gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
      gtk_box_pack_start (GTK_BOX(page), frame, TRUE, TRUE, 0);

      label = gtk_label_new ("See  <a href=\"http://s.bouras.free.fr/arabtex\""
                             "title=\"Get it !!..\">arabtex</a> . \n"
                             "Or search on <a href=\"http://www.google.com/\">"
                             "<span color=\"#0266C8\">G</span><span color=\"#F90101\">o</span>"
                             "<span color=\"#F2B50F\">o</span><span color=\"#0266C8\">g</span>"
                             "<span color=\"#00933B\">l</span><span color=\"#F90101\">e</span>"
                             "</a>.");
      gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
      g_signal_connect (label, "activate-link", (GCallback)activate_link, NULL);
   //   gtk_container_add (GTK_CONTAINER (page), label);
      gtk_box_pack_start (GTK_BOX (page), label, TRUE, TRUE, 0);
      gtk_widget_show (label);
/*.....................................*/
gtk_widget_show(page);
//gtk_widget_show(fenetre);
gtk_widget_show_all(page);

   return page;
}


