/*
 * DO NOT EDIT THIS FILE - it is generated by Glade.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include "iol.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

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

GtkWidget*
create_iol_window (void)
{
  GtkWidget *iol_window;
  GtkWidget *vbox1;
  GtkWidget *scrolledwindow1;
  GtkWidget *script_text;
  GtkWidget *hbuttonbox1;
  GtkWidget *load_button;
  GtkWidget *save_button;
  GtkWidget *go_button;
  GtkWidget *help_button;
  GtkWidget *hbox1;
  GtkWidget *keepopen_check_button;

  iol_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (iol_window), "iol_window", iol_window);
  gtk_window_set_title (GTK_WINDOW (iol_window), _("IOL - Image Operation Language"));

  vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_widget_ref (vbox1);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "vbox1", vbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox1);
  gtk_container_add (GTK_CONTAINER (iol_window), vbox1);

  scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_ref (scrolledwindow1);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "scrolledwindow1", scrolledwindow1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (scrolledwindow1);
  gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);

  script_text = gtk_text_new (NULL, NULL);
  gtk_widget_ref (script_text);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "script_text", script_text,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (script_text);
  gtk_container_add (GTK_CONTAINER (scrolledwindow1), script_text);
  gtk_widget_set_usize (script_text, 640, 440);
  gtk_text_set_editable (GTK_TEXT (script_text), TRUE);

  hbuttonbox1 = gtk_hbutton_box_new ();
  gtk_widget_ref (hbuttonbox1);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "hbuttonbox1", hbuttonbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbuttonbox1);
  gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, TRUE, TRUE, 0);

  load_button = gtk_button_new_with_label (_("Load..."));
  gtk_widget_ref (load_button);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "load_button", load_button,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (load_button);
  gtk_container_add (GTK_CONTAINER (hbuttonbox1), load_button);
  GTK_WIDGET_SET_FLAGS (load_button, GTK_CAN_DEFAULT);

  save_button = gtk_button_new_with_label (_("Save..."));
  gtk_widget_ref (save_button);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "save_button", save_button,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (save_button);
  gtk_container_add (GTK_CONTAINER (hbuttonbox1), save_button);
  GTK_WIDGET_SET_FLAGS (save_button, GTK_CAN_DEFAULT);

  go_button = gtk_button_new_with_label (_("Go!"));
  gtk_widget_ref (go_button);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "go_button", go_button,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (go_button);
  gtk_container_add (GTK_CONTAINER (hbuttonbox1), go_button);
  GTK_WIDGET_SET_FLAGS (go_button, GTK_CAN_DEFAULT);

  help_button = gtk_button_new_with_label (_("Help..."));
  gtk_widget_ref (help_button);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "help_button", help_button,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (help_button);
  gtk_container_add (GTK_CONTAINER (hbuttonbox1), help_button);
  GTK_WIDGET_SET_FLAGS (help_button, GTK_CAN_DEFAULT);

  hbox1 = gtk_hbox_new (FALSE, 0);
  gtk_widget_ref (hbox1);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "hbox1", hbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox1);
  gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);

  keepopen_check_button = gtk_check_button_new_with_label (_("Stay Open"));
  gtk_widget_ref (keepopen_check_button);
  gtk_object_set_data_full (GTK_OBJECT (iol_window), "keepopen_check_button", keepopen_check_button,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (keepopen_check_button);
  gtk_box_pack_end (GTK_BOX (hbox1), keepopen_check_button, FALSE, FALSE, 0);

  gtk_signal_connect (GTK_OBJECT (iol_window), "delete_event",
                      GTK_SIGNAL_FUNC (on_iol_window_delete_event),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (iol_window), "show",
                      GTK_SIGNAL_FUNC (on_iol_window_show),
                      script_text);
  gtk_signal_connect (GTK_OBJECT (load_button), "clicked",
                      GTK_SIGNAL_FUNC (on_load_button_clicked),
                      script_text);
  gtk_signal_connect (GTK_OBJECT (save_button), "clicked",
                      GTK_SIGNAL_FUNC (on_save_button_clicked),
                      script_text);
  gtk_signal_connect (GTK_OBJECT (go_button), "clicked",
                      GTK_SIGNAL_FUNC (on_go_button_clicked),
                      iol_window);
  gtk_signal_connect (GTK_OBJECT (help_button), "clicked",
                      GTK_SIGNAL_FUNC (on_help_button_clicked),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (keepopen_check_button), "toggled",
                      GTK_SIGNAL_FUNC (on_keepopen_check_button_toggled),
                      NULL);

  gtk_widget_grab_default (load_button);
  return iol_window;
}

GtkWidget*
create_load_file_select (void)
{
  GtkWidget *load_file_select;
  GtkWidget *load_ok_button;
  GtkWidget *load_cancel_button;

  load_file_select = gtk_file_selection_new (_("Load File..."));
  gtk_object_set_data (GTK_OBJECT (load_file_select), "load_file_select", load_file_select);
  gtk_container_set_border_width (GTK_CONTAINER (load_file_select), 10);

  load_ok_button = GTK_FILE_SELECTION (load_file_select)->ok_button;
  gtk_object_set_data (GTK_OBJECT (load_file_select), "load_ok_button", load_ok_button);
  gtk_widget_show (load_ok_button);
  GTK_WIDGET_SET_FLAGS (load_ok_button, GTK_CAN_DEFAULT);

  load_cancel_button = GTK_FILE_SELECTION (load_file_select)->cancel_button;
  gtk_object_set_data (GTK_OBJECT (load_file_select), "load_cancel_button", load_cancel_button);
  gtk_widget_show (load_cancel_button);
  GTK_WIDGET_SET_FLAGS (load_cancel_button, GTK_CAN_DEFAULT);

  gtk_signal_connect (GTK_OBJECT (load_ok_button), "clicked",
                      GTK_SIGNAL_FUNC (on_load_ok_button_clicked),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (load_cancel_button), "clicked",
                      GTK_SIGNAL_FUNC (on_load_cancel_button_clicked),
                      NULL);

  return load_file_select;
}

GtkWidget*
create_save_file_selection (void)
{
  GtkWidget *save_file_selection;
  GtkWidget *save_ok_button;
  GtkWidget *save_cancel_button;

  save_file_selection = gtk_file_selection_new (_("Save File..."));
  gtk_object_set_data (GTK_OBJECT (save_file_selection), "save_file_selection", save_file_selection);
  gtk_container_set_border_width (GTK_CONTAINER (save_file_selection), 10);

  save_ok_button = GTK_FILE_SELECTION (save_file_selection)->ok_button;
  gtk_object_set_data (GTK_OBJECT (save_file_selection), "save_ok_button", save_ok_button);
  gtk_widget_show (save_ok_button);
  GTK_WIDGET_SET_FLAGS (save_ok_button, GTK_CAN_DEFAULT);

  save_cancel_button = GTK_FILE_SELECTION (save_file_selection)->cancel_button;
  gtk_object_set_data (GTK_OBJECT (save_file_selection), "save_cancel_button", save_cancel_button);
  gtk_widget_show (save_cancel_button);
  GTK_WIDGET_SET_FLAGS (save_cancel_button, GTK_CAN_DEFAULT);

  gtk_signal_connect (GTK_OBJECT (save_ok_button), "clicked",
                      GTK_SIGNAL_FUNC (on_save_ok_button_clicked),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (save_cancel_button), "clicked",
                      GTK_SIGNAL_FUNC (on_save_cancel_button_clicked),
                      NULL);

  return save_file_selection;
}

GtkWidget*
create_iol_help_window (void)
{
  GtkWidget *iol_help_window;
  GtkWidget *vbox2;
  GtkWidget *help_notebook;
  GtkWidget *variable_tidbits_frame;
  GtkWidget *scrolledwindow2;
  GtkWidget *variable_tidbits_text;
  GtkWidget *variables_help_label;
  GtkWidget *keywords_help_frame;
  GtkWidget *scrolledwindow3;
  GtkWidget *keywords_help_text;
  GtkWidget *keywords_help_label;
  GtkWidget *misc_help_frame;
  GtkWidget *misc_text_label;
  GtkWidget *misc_help_label;
  GtkWidget *hbuttonbox2;
  GtkWidget *help_close_button;

  iol_help_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (iol_help_window), "iol_help_window", iol_help_window);
  gtk_window_set_title (GTK_WINDOW (iol_help_window), _("IOL Help"));

  vbox2 = gtk_vbox_new (FALSE, 0);
  gtk_widget_ref (vbox2);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "vbox2", vbox2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox2);
  gtk_container_add (GTK_CONTAINER (iol_help_window), vbox2);

  help_notebook = gtk_notebook_new ();
  gtk_widget_ref (help_notebook);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "help_notebook", help_notebook,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (help_notebook);
  gtk_box_pack_start (GTK_BOX (vbox2), help_notebook, TRUE, TRUE, 0);

  variable_tidbits_frame = gtk_frame_new (_("Some Information About Variables"));
  gtk_widget_ref (variable_tidbits_frame);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "variable_tidbits_frame", variable_tidbits_frame,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (variable_tidbits_frame);
  gtk_container_add (GTK_CONTAINER (help_notebook), variable_tidbits_frame);

  scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_ref (scrolledwindow2);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "scrolledwindow2", scrolledwindow2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (scrolledwindow2);
  gtk_container_add (GTK_CONTAINER (variable_tidbits_frame), scrolledwindow2);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

  variable_tidbits_text = gtk_text_new (NULL, NULL);
  gtk_widget_ref (variable_tidbits_text);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "variable_tidbits_text", variable_tidbits_text,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (variable_tidbits_text);
  gtk_container_add (GTK_CONTAINER (scrolledwindow2), variable_tidbits_text);
  gtk_widget_set_usize (variable_tidbits_text, 400, -2);
  gtk_text_insert (GTK_TEXT (variable_tidbits_text), NULL, NULL, NULL,
                   _("There can be up to 50 variables.\n\nVariables are always 32-bit floating-point.\n\nVariables can have any name of any length, as long as its name\na)Does not have spaces in it, and contains only alphanumeric\n   characters\nb)Starts with a letter\nc)Is not already used by a keyword\n\nVariables do not have to be declared before they can be used.\n\nVariable names are case sensitive"), -1);

  variables_help_label = gtk_label_new (_("Variables"));
  gtk_widget_ref (variables_help_label);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "variables_help_label", variables_help_label,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (variables_help_label);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (help_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (help_notebook), 0), variables_help_label);

  keywords_help_frame = gtk_frame_new (_("IOL Keywords"));
  gtk_widget_ref (keywords_help_frame);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "keywords_help_frame", keywords_help_frame,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (keywords_help_frame);
  gtk_container_add (GTK_CONTAINER (help_notebook), keywords_help_frame);

  scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_ref (scrolledwindow3);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "scrolledwindow3", scrolledwindow3,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (scrolledwindow3);
  gtk_container_add (GTK_CONTAINER (keywords_help_frame), scrolledwindow3);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);

  keywords_help_text = gtk_text_new (NULL, NULL);
  gtk_widget_ref (keywords_help_text);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "keywords_help_text", keywords_help_text,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (keywords_help_text);
  gtk_container_add (GTK_CONTAINER (scrolledwindow3), keywords_help_text);
  gtk_text_insert (GTK_TEXT (keywords_help_text), NULL, NULL, NULL,
                   _("There are two kinds of keywords: those that return a floating-point\nnumber and can therefor be used in mathematical expressions (such\nas sqrt, clip, etc.), and those that do not (input, output, and size).\n\nIF...ELSE statements must be in the form of:\n\tif condition { statements } else { statements }\nor\n\tif condition { statements }\n\n*** Keywords that _can't_ be used in expressions ***\n\ninput\nParameters: red green blue alpha\nFetch the image's red, green, blue, and alpha values, convert\nthem to floating-point if necessary, and then stick them in their\nrespective variables.\n\noutput\nParameters: red green blue alpha\nTake the parameters and use their values for the image's\nrespective channels.\n\nsize\nParameters: x y\nLoad the image's width and height into the x and y\nvariables, respectively.\n\npos\nParameters: x y\nFetches the coordinates of the current pixel; the X axis goes in x,\nthe Y axis goes in y.\n\n*** Keywords that _can_ be used in expressions ***\n\nclip\nParameters: val\nIf val is less than 0.0, clip returns 0.0. If val is greater than 1.0,\nval returns 1.0. Otherwise, clip returns val.\n\nsqrt\nParameters: val\nCompute the square root of val, and then return it.\n\nabs\nParameters: val\nCalculates the absolute value of val, and then returns it.\n\nsin\nParameters: val\nReturn the sine of val.\n\ncos\nParameters: val\nReturn the cosine of val\n\ntan\nParameters: val\nReturn the tangent of val\n\nlog\nParameters: val\nReturn the natural logarithm of val\n\nlog10\nParameters: val\nReturn the base-10 logarithm of val\n\npow\nParameters: x y\nReturn the value of x raised to the power of y\n\nmin\nParameters: x y\nIf x is less than y, returns x. If y is less than x, returns y. If x and y\nare the same, returns x.\n\nmax\nParameters: x y\nIf x is greater than y, returns x. If y is greater than x, returns y. If x\nand y are the same, returns x."), -1);

  keywords_help_label = gtk_label_new (_("Keywords"));
  gtk_widget_ref (keywords_help_label);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "keywords_help_label", keywords_help_label,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (keywords_help_label);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (help_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (help_notebook), 1), keywords_help_label);

  misc_help_frame = gtk_frame_new (_("Miscellaneous"));
  gtk_widget_ref (misc_help_frame);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "misc_help_frame", misc_help_frame,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (misc_help_frame);
  gtk_container_add (GTK_CONTAINER (help_notebook), misc_help_frame);

  misc_text_label = gtk_label_new ("");
  gtk_label_parse_uline (GTK_LABEL (misc_text_label),
                         _("IOL - Image Operation Language\n\nAuthor: Sean Ridenour <s__ridenour@distortedpictures.com>\n\nWebsite: http://iol.kewlpc.org\n\nCopyright (C) 2003 Sean Ridenour. Released under the terms of the GNU General Public License. Read the included file COPYING for more information."));
  gtk_widget_ref (misc_text_label);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "misc_text_label", misc_text_label,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (misc_text_label);
  gtk_container_add (GTK_CONTAINER (misc_help_frame), misc_text_label);
  gtk_label_set_justify (GTK_LABEL (misc_text_label), GTK_JUSTIFY_LEFT);
  gtk_label_set_line_wrap (GTK_LABEL (misc_text_label), TRUE);

  misc_help_label = gtk_label_new (_("Misc."));
  gtk_widget_ref (misc_help_label);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "misc_help_label", misc_help_label,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (misc_help_label);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (help_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (help_notebook), 2), misc_help_label);

  hbuttonbox2 = gtk_hbutton_box_new ();
  gtk_widget_ref (hbuttonbox2);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "hbuttonbox2", hbuttonbox2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbuttonbox2);
  gtk_box_pack_start (GTK_BOX (vbox2), hbuttonbox2, FALSE, FALSE, 0);

  help_close_button = gtk_button_new_with_label (_("Close"));
  gtk_widget_ref (help_close_button);
  gtk_object_set_data_full (GTK_OBJECT (iol_help_window), "help_close_button", help_close_button,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (help_close_button);
  gtk_container_add (GTK_CONTAINER (hbuttonbox2), help_close_button);
  GTK_WIDGET_SET_FLAGS (help_close_button, GTK_CAN_DEFAULT);

  gtk_signal_connect (GTK_OBJECT (help_close_button), "clicked",
                      GTK_SIGNAL_FUNC (on_help_close_button_clicked),
                      NULL);

  gtk_widget_grab_default (help_close_button);
  return iol_help_window;
}

