#include <gtk/gtk.h>
#include <string.h>
#include <stdio.h>

#include "support.h"
#include "interface.h"

GtkWidget *create_PICTracker_Prog (void) {
    GtkWidget *PICTracker_win;
    GtkWidget *fixed1;
    GtkWidget *scrolledwindow1;
    GtkWidget *label1;
    GtkWidget *label2;
    GtkWidget *alignment1;
    GtkWidget *hbox1;
    GtkWidget *image1;
    GtkWidget *label3;
    GtkWidget *alignment2;
    GtkWidget *hbox2;
    GtkWidget *image2;
    GtkWidget *label4;
    GtkWidget *alignment3;
    GtkWidget *hbox3;
    GtkWidget *image3;
    GtkWidget *label5;

    PICTracker_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (PICTracker_win),"PICTracker Programmer - F4CTZ - Fabien PELLET");
    gtk_window_set_resizable (GTK_WINDOW (PICTracker_win), FALSE);
    gtk_window_set_icon_name (GTK_WINDOW (PICTracker_win), "gtk-convert");
    gtk_window_set_position(GTK_WINDOW(PICTracker_win),GTK_WIN_POS_CENTER);

    fixed1 = gtk_fixed_new ();
    gtk_container_add (GTK_CONTAINER(PICTracker_win), fixed1);
    gtk_widget_show (fixed1);
    gtk_widget_set_size_request (fixed1, /*367*/460, -1);

    scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
    gtk_fixed_put (GTK_FIXED(fixed1), scrolledwindow1, 0, 0);
    gtk_widget_show (scrolledwindow1);
    gtk_widget_set_size_request (scrolledwindow1, /*232*/325, 256);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_SHADOW_IN);

    OUT_Display = gtk_text_view_new();
    gtk_container_add(GTK_CONTAINER(scrolledwindow1),OUT_Display);
    gtk_widget_show(OUT_Display);
    gtk_text_view_set_editable (GTK_TEXT_VIEW (OUT_Display), FALSE);
    gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (OUT_Display), FALSE);
    gtk_text_view_set_left_margin(GTK_TEXT_VIEW (OUT_Display),2);

    label1 = gtk_label_new ("RS232 Port");
    gtk_widget_show (label1);
    gtk_fixed_put (GTK_FIXED (fixed1), label1, /*256*/345, 0);
    gtk_widget_set_size_request (label1, 56, 16);
    gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_CENTER);

    label2 = gtk_label_new ("RS232 Speed");
    gtk_widget_show (label2);
    gtk_fixed_put (GTK_FIXED (fixed1), label2, 337, 48);
    gtk_widget_set_size_request (label2, 72, 16);

    BTN_Filechoose = gtk_file_chooser_button_new ("Select file for update",GTK_FILE_CHOOSER_ACTION_OPEN);
    gtk_widget_show (BTN_Filechoose);
    gtk_fixed_put (GTK_FIXED (fixed1), BTN_Filechoose, 329, 96);
    gtk_widget_set_size_request (BTN_Filechoose, 120, 32);

    SELECT_Port = gtk_combo_box_text_new();
    gtk_widget_show (SELECT_Port);
    gtk_fixed_put (GTK_FIXED (fixed1), SELECT_Port, 329, 16);
    gtk_widget_set_size_request (SELECT_Port, 120, 22);
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM1");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM2");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM3");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM4");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM5");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM6");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM7");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM8");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(SELECT_Port), NULL, "COM9");

    SELECT_Speed = gtk_combo_box_text_new();
    gtk_widget_show (SELECT_Speed);
    gtk_fixed_put (GTK_FIXED (fixed1), SELECT_Speed, 329, 64);
    gtk_widget_set_size_request (SELECT_Speed, 120, 22);
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (SELECT_Speed), NULL, "1200");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (SELECT_Speed), NULL, "2400");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (SELECT_Speed), NULL, "4800");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (SELECT_Speed), NULL, "9600");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (SELECT_Speed), NULL, "19200");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (SELECT_Speed), NULL, "38400");
    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (SELECT_Speed), NULL, "57600");

    BTN_Load = gtk_button_new ();
    gtk_widget_show (BTN_Load);
    gtk_fixed_put (GTK_FIXED (fixed1), BTN_Load, 329, 136);
    gtk_widget_set_size_request (BTN_Load, 120, 32);
    gtk_widget_set_sensitive(BTN_Load,TRUE);

    alignment3 = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_widget_show (alignment3);
    gtk_container_add (GTK_CONTAINER (BTN_Load), alignment3);

    hbox3 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
    gtk_widget_show (hbox3);
    gtk_container_add (GTK_CONTAINER (alignment3), hbox3);

    image3 = gtk_image_new_from_stock ("gtk-network", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image3);
    gtk_box_pack_start (GTK_BOX (hbox3), image3, FALSE, FALSE, 0);

    label5 = gtk_label_new_with_mnemonic ("Load from web");
    gtk_widget_show (label5);
    gtk_box_pack_start (GTK_BOX (hbox3), label5, FALSE, FALSE, 0);

    BTN_Prog = gtk_button_new ();
    gtk_widget_show (BTN_Prog);
    gtk_fixed_put (GTK_FIXED (fixed1), BTN_Prog, 329, 176);
    gtk_widget_set_size_request (BTN_Prog, 120, 32);
    gtk_widget_set_sensitive(BTN_Prog,FALSE);

    alignment1 = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_widget_show (alignment1);
    gtk_container_add (GTK_CONTAINER (BTN_Prog), alignment1);

    hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
    gtk_widget_show (hbox1);
    gtk_container_add (GTK_CONTAINER (alignment1), hbox1);

    image1 = gtk_image_new_from_stock ("gtk-edit", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image1);
    gtk_box_pack_start (GTK_BOX (hbox1), image1, FALSE, FALSE, 0);

    label3 = gtk_label_new_with_mnemonic ("Program");
    gtk_widget_show (label3);
    gtk_box_pack_start (GTK_BOX (hbox1), label3, FALSE, FALSE, 0);

    BTN_Quit = gtk_button_new ();
    gtk_widget_show (BTN_Quit);
    gtk_fixed_put (GTK_FIXED (fixed1), BTN_Quit, 329, 216);
    gtk_widget_set_size_request (BTN_Quit, 120, 32);

    alignment2 = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_widget_show (alignment2);
    gtk_container_add (GTK_CONTAINER (BTN_Quit), alignment2);

    hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
    gtk_widget_show (hbox2);
    gtk_container_add (GTK_CONTAINER (alignment2), hbox2);

    image2 = gtk_image_new_from_stock ("gtk-quit", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show (image2);
    gtk_box_pack_start (GTK_BOX (hbox2), image2, FALSE, FALSE, 0);

    label4 = gtk_label_new_with_mnemonic ("Quit");
    gtk_widget_show (label4);
    gtk_box_pack_start (GTK_BOX (hbox2), label4, FALSE, FALSE, 0);

    return PICTracker_win;
}
