/*****************************************************************************/

/*
 *      optionswin.c -- REALmagic simple windowing application in GTK
 *
 *      Copyright (C) 2001 Sigma Designs
 *                    written by Pascal Cannenterre <pascal_cannenterre@sdesigns.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*****************************************************************************/
#include "define.h"
#include "gtk_callbacks.h"
#include "interface.h"

/* include pixmaps */
#include "../pixmaps/REALmagic.xpm"
#include "../pixmaps/audiol.xpm"
#include "../pixmaps/audior.xpm"
#include "../pixmaps/brightns.xpm"
#include "../pixmaps/contrast.xpm"
#include "../pixmaps/saturatn.xpm"
#include "../pixmaps/logo.xpm"


GtkWidget * create_Volume_frame(void)
{
  GtkWidget *frame;
  GtkWidget *table;

  GtkWidget *audiol_pixmap, *audior_pixmap;
  GtkWidget *volume_scale, *balance_scale;

/* Create a Frame */
  frame = gtk_frame_new(NULL);
  /* Set the frame's label */
  gtk_frame_set_label( GTK_FRAME(frame), "Volume" );
  /* Align the label at the right of the frame */
  gtk_frame_set_label_align( GTK_FRAME(frame), 0.5, 0.0);
  /* Set the style of the frame */
  gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT);

  table = gtk_table_new (2, 3, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_container_set_border_width (GTK_CONTAINER (table), 5);

  audiol_pixmap = create_pixmap (frame, audiol_xpm);
  gtk_widget_show (audiol_pixmap);
  gtk_table_attach (GTK_TABLE (table), audiol_pixmap, 0, 1, 0, 1,
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
  
  volume_scale = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new ( (VOL_MIN+VOL_MAX)-VOL_RESET, VOL_MIN, VOL_MAX, 1, 0, 0)));
  gtk_widget_ref ( volume_scale);
  gtk_object_set_data_full (GTK_OBJECT (frame), "volume_scale", volume_scale,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (volume_scale);
  gtk_table_attach (GTK_TABLE (table), volume_scale, 1, 2, 0, 1,
		    (GtkAttachOptions) (GTK_FILL),
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (volume_scale), FALSE);
  
  audior_pixmap = create_pixmap (frame, audior_xpm);
  gtk_widget_show (audior_pixmap);
  gtk_table_attach (GTK_TABLE (table), audior_pixmap, 2, 3, 0, 1,
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);

  balance_scale = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new ( BAL_RESET, 
								       VOL_MIN-VOL_MAX, 
								       VOL_MAX-VOL_MIN, 1, 0, 0)));
  gtk_widget_ref (balance_scale);
  gtk_object_set_data_full (GTK_OBJECT (frame), "balance_scale", balance_scale,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (balance_scale);
  gtk_table_attach (GTK_TABLE (table), balance_scale, 0, 3, 1, 2,
		    (GtkAttachOptions) (GTK_FILL),
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (balance_scale), FALSE);


  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(volume_scale)->adjustment),    "value_changed", 
		     GTK_SIGNAL_FUNC(volume_changed), GTK_OBJECT(GTK_RANGE(balance_scale)->adjustment));
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(balance_scale)->adjustment),   "value_changed", 
		     GTK_SIGNAL_FUNC(balance_changed),GTK_OBJECT(GTK_RANGE(volume_scale)->adjustment));

  return frame;
}

GtkWidget * create_BrSaCo_frame(void)
{
  GtkWidget *frame;
  GtkWidget *table;

  GtkWidget *brightness_pixmap, *saturation_pixmap, *contrast_pixmap;
  GtkWidget *brightness_scale, *saturation_scale, *contrast_scale;

  /* Create a Frame */
  frame = gtk_frame_new(NULL);
  /* Set the frame's label */
  gtk_frame_set_label( GTK_FRAME(frame), "Image Br/Sa/Co" );
  /* Align the label at the right of the frame */
  gtk_frame_set_label_align( GTK_FRAME(frame), 0.5, 0.0);
  /* Set the style of the frame */
  gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT);

  table = gtk_table_new (2, 3, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_container_set_border_width (GTK_CONTAINER (table), 5);
     
  brightness_pixmap = create_pixmap (frame, brightns_xpm);
  gtk_widget_show (brightness_pixmap);
  gtk_table_attach (GTK_TABLE (table), brightness_pixmap, 0, 1, 0, 1,
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
  
  saturation_pixmap = create_pixmap (frame, saturatn_xpm);
  gtk_widget_show (saturation_pixmap);
  gtk_table_attach (GTK_TABLE (table), saturation_pixmap, 1, 2, 0, 1,
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);
  
  contrast_pixmap = create_pixmap (frame, contrast_xpm);
  gtk_widget_show (contrast_pixmap);
  gtk_table_attach (GTK_TABLE (table), contrast_pixmap, 2, 3, 0, 1,
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);
  
  brightness_scale = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new ( (BRT_MIN+BRT_MAX)-BRT_RESET, 
									  BRT_MIN, 
									  BRT_MAX, 1, 0, 0)));
  gtk_widget_ref (brightness_scale);
  gtk_object_set_data_full (GTK_OBJECT (frame), "brightness_scale", brightness_scale,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (brightness_scale);
  gtk_table_attach (GTK_TABLE (table), brightness_scale, 0, 1, 1, 2,
		    (GtkAttachOptions) (GTK_FILL),
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (brightness_scale), FALSE);
  
  saturation_scale = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new ( (CSC_MIN+CSC_MAX)-CSC_RESET, 
									  CSC_MIN, 
									  CSC_MAX, 1, 0, 0)));
  gtk_widget_ref (saturation_scale);
  gtk_object_set_data_full (GTK_OBJECT (frame), "saturation_scale", saturation_scale,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (saturation_scale);
  gtk_table_attach (GTK_TABLE (table), saturation_scale, 1, 2, 1, 2,
		    (GtkAttachOptions) (GTK_FILL),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (saturation_scale), FALSE);
      
  contrast_scale = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new ( (CON_MIN+CON_MAX)-CON_RESET, 
									CON_MIN, 
									CON_MAX, 1, 0, 0)));
  gtk_widget_ref (contrast_scale);
  gtk_object_set_data_full (GTK_OBJECT (frame), "contrast_scale", contrast_scale,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (contrast_scale);
  gtk_table_attach (GTK_TABLE (table), contrast_scale, 2, 3, 1, 2,
		    (GtkAttachOptions) (GTK_FILL),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (contrast_scale), FALSE);
  
  /* connect scales with her functions */
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(brightness_scale)->adjustment),"value_changed", 
		     GTK_SIGNAL_FUNC(brightness_changed), NULL);
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(contrast_scale)->adjustment),  "value_changed", 
		     GTK_SIGNAL_FUNC(contrast_changed),   NULL);
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(saturation_scale)->adjustment),"value_changed", 
		     GTK_SIGNAL_FUNC(saturation_changed), NULL);
  
  return frame;
}


static GtkRadioFrameEntry tvcomponent_entry[] = {
  {"Composite","radioCOMPOSITE",
   GTK_SIGNAL_FUNC(switch_TVcomponent_cb),
   GUINT_TO_POINTER(FMPV_VIDEOOUT_COMPOSITE)},
  {"RGB","radioRGB",
   GTK_SIGNAL_FUNC(switch_TVcomponent_cb),
   GUINT_TO_POINTER(FMPV_VIDEOOUT_COMPONENT_RGB) },
  {"YUV","radioYUV",
   GTK_SIGNAL_FUNC(switch_TVcomponent_cb),
   GUINT_TO_POINTER(FMPV_VIDEOOUT_COMPONENT_YUV) },
};
static GtkRadioFrameEntry tvstandard_entry[] = {
  {"NTSC","radioNTSC",
   GTK_SIGNAL_FUNC(switch_TVout_cb),
   GUINT_TO_POINTER(FMPV_VIDEOOUT_NTSC)},
  {"PAL","radioPAL",
   GTK_SIGNAL_FUNC(switch_TVout_cb),
   GUINT_TO_POINTER(FMPV_VIDEOOUT_PAL)},
  {"PAL60","radioPAL60",
   GTK_SIGNAL_FUNC(switch_TVout_cb),
   GUINT_TO_POINTER(FMPV_VIDEOOUT_PAL60)}, 
  {"PALM","radioPALM",
   GTK_SIGNAL_FUNC(switch_TVout_cb),
   GUINT_TO_POINTER(FMPV_VIDEOOUT_PALM)},
  {"VGA", "radioVGA",
   GTK_SIGNAL_FUNC(switch_VGAout_cb),
   NULL},
};

static GtkRadioFrameEntry audiomode_entry[] = {
  {"Stereo","radioSTEREO",
   GTK_SIGNAL_FUNC(switch_audio_channel_mode),
   GUINT_TO_POINTER(FMPV_AUDIO_MODE_STEREO)},
  {"Mono","radioMONO",
   GTK_SIGNAL_FUNC(switch_audio_channel_mode),
   GUINT_TO_POINTER(FMPV_AUDIO_MODE_MONOMIX)},
  {"Mono Left","radioMONOLEFT",
   GTK_SIGNAL_FUNC(switch_audio_channel_mode),
   GUINT_TO_POINTER(FMPV_AUDIO_MODE_LEFT_ONLY)},
  {"Mono Right","radioMONORIGHT",
   GTK_SIGNAL_FUNC(switch_audio_channel_mode),
   GUINT_TO_POINTER(FMPV_AUDIO_MODE_RIGHT_ONLY) },
  {"Mute", "radioMUTE",
   GTK_SIGNAL_FUNC(switch_to_mute_mode),
   GUINT_TO_POINTER(TRUE)},
};

static GtkRadioFrameEntry digitalout_entry[] = {
  {"AC3/DTS","radioAC3DTS",
   GTK_SIGNAL_FUNC(switch_digital_out_mode_cb),
   GUINT_TO_POINTER(AC3DTS)},
  {"Analogic", "radioPCM",
   GTK_SIGNAL_FUNC(switch_digital_out_mode_cb), 
   GUINT_TO_POINTER(PCM)},
};

GtkWidget * create_radio_frame(guint nradio, GtkRadioFrameEntry *tab, gchar *frame_name, gboolean vertical)
{
  guint i=0;
  GtkWidget ** radio_array;
  GtkWidget *frame;
  GtkWidget *box1;
  GSList *group;

  group = NULL;

  radio_array = (GtkWidget**)g_new(GtkWidget*,nradio);
  
  frame = gtk_frame_new(NULL);

  gtk_frame_set_label( GTK_FRAME(frame), frame_name);
  gtk_frame_set_label_align( GTK_FRAME(frame), 0.5, 0.0);
  gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT);
  if(vertical)
    box1 = gtk_vbox_new (FALSE, 5);
  else
    box1 = gtk_hbox_new (FALSE, 5);
  gtk_container_set_border_width (GTK_CONTAINER (box1), 5);
  gtk_container_add(GTK_CONTAINER(frame), box1);
  gtk_widget_show (box1);
  
  for(i=0;i<nradio;i++)
    {
      radio_array[i] = gtk_radio_button_new_with_label (group, (tab[i]).label);
      gtk_widget_ref (radio_array[i]);
      gtk_object_set_data_full (GTK_OBJECT (frame), (tab[i]).radio_name, radio_array[i],
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_box_pack_start (GTK_BOX (box1), radio_array[i], TRUE, TRUE, 0);
      gtk_widget_show (radio_array[i]);
      
      if(i<nradio-1)
	group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio_array[i]));
      
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_array[i]), FALSE);
    }

  for(i=0;i<nradio;i++)
    {
      gtk_signal_connect(GTK_OBJECT (radio_array[i]), "toggled",
			 (tab[i]).func_cb,
			 (tab[i]).data);
    }
  
  g_free(radio_array);
  
  return frame;
}



void get_options_window()
{
  GtkAccelGroup *accel_group;
  GtkWidget *vbox1, *table, *hbuttonbox1;
  GtkWidget *logo_REALmagic;
  GtkWidget *tvvol_frame, *channel_frame, *digital_frame;
  GtkWidget *tvBSC_frame, *tvstd_frame, *tvcomponent_frame;
  guint Refresh_key, OK_key, Cancel_key;
  GtkWidget *Refresh, *OK, *Cancel;

  if (GUI.options!= NULL && GUI.options->window != NULL)
    {
      gdk_window_show(GUI.options->window);
      gdk_window_raise(GUI.options->window);
    }
  else
    {
      accel_group = gtk_accel_group_new ();
      
      GUI.options = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_realize(GUI.options);

      gtk_window_set_title (GTK_WINDOW (GUI.options), _("Options ..."));
      gtk_window_set_position (GTK_WINDOW (GUI.options), GTK_WIN_POS_CENTER);
      gtk_window_set_policy (GTK_WINDOW (GUI.options), FALSE, FALSE, TRUE);

      vbox1 = gtk_vbox_new (FALSE, 0);
      gtk_widget_show (vbox1);
      gtk_container_add (GTK_CONTAINER (GUI.options), vbox1);
      gtk_container_set_border_width (GTK_CONTAINER (GUI.options), 5);
      
      table = gtk_table_new (2, 3, TRUE);
      gtk_widget_show (table);
      gtk_box_pack_start (GTK_BOX (vbox1), table, TRUE, TRUE, 5);
      GTK_WIDGET_SET_FLAGS (table, GTK_CAN_FOCUS);
      GTK_WIDGET_SET_FLAGS (table, GTK_CAN_DEFAULT);
      gtk_table_set_row_spacings (GTK_TABLE (table), 5);
      gtk_table_set_col_spacings (GTK_TABLE (table), 5);

      tvvol_frame = create_Volume_frame();
      gtk_widget_ref (tvvol_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "tvvol_frame", tvvol_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (tvvol_frame);
      gtk_table_attach (GTK_TABLE (table), tvvol_frame, 0, 1, 0, 1,
			GTK_FILL|GTK_EXPAND,
			GTK_FILL|GTK_EXPAND,5, 5);
      GTK_WIDGET_UNSET_FLAGS (tvvol_frame, GTK_CAN_FOCUS);

      channel_frame = create_radio_frame(5, audiomode_entry, 
					 "Channel Mode", TRUE);
      gtk_widget_ref (channel_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "channel_frame", channel_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (channel_frame);
      gtk_table_attach (GTK_TABLE (table),channel_frame, 1, 2, 0, 1,
			GTK_FILL|GTK_EXPAND,
			GTK_FILL|GTK_EXPAND, 5, 5);
      GTK_WIDGET_UNSET_FLAGS (channel_frame, GTK_CAN_FOCUS);

      digital_frame = create_radio_frame(2, digitalout_entry, 
					 "Digital Out", TRUE);
      gtk_widget_ref (digital_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "digital_frame", digital_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (digital_frame);
      gtk_table_attach (GTK_TABLE (table),digital_frame, 2, 3, 0, 1,
			GTK_FILL|GTK_EXPAND,
			GTK_FILL|GTK_EXPAND, 5, 5);
      GTK_WIDGET_UNSET_FLAGS (digital_frame, GTK_CAN_FOCUS);

      tvBSC_frame = create_BrSaCo_frame(); 
      gtk_widget_ref (tvBSC_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "tvBSC_frame", tvBSC_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (tvBSC_frame);
      gtk_table_attach (GTK_TABLE (table),tvBSC_frame, 0, 1, 1, 2,
			GTK_FILL|GTK_EXPAND,
			GTK_FILL|GTK_EXPAND, 5, 5);
      GTK_WIDGET_UNSET_FLAGS (tvBSC_frame, GTK_CAN_FOCUS);

      tvstd_frame = create_radio_frame(5, tvstandard_entry, 
				       "TV/VGA Output", TRUE);
					 
      gtk_widget_ref (tvstd_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "tvstd_frame", tvstd_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (tvstd_frame);
      gtk_table_attach (GTK_TABLE (table), tvstd_frame, 1, 2, 1, 2,
			GTK_FILL|GTK_EXPAND,
			GTK_FILL|GTK_EXPAND,5, 5);
      GTK_WIDGET_UNSET_FLAGS (tvstd_frame, GTK_CAN_FOCUS);

      tvcomponent_frame = create_radio_frame(3, tvcomponent_entry, 
					     "Component", TRUE);
      gtk_widget_ref (tvcomponent_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "tvcomponent_frame", tvcomponent_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show(tvcomponent_frame);
      gtk_table_attach (GTK_TABLE (table), tvcomponent_frame, 2, 3, 1, 2,
			GTK_FILL|GTK_EXPAND,
			GTK_FILL|GTK_EXPAND,5, 5);
      GTK_WIDGET_UNSET_FLAGS (tvcomponent_frame, GTK_CAN_FOCUS);

      logo_REALmagic = create_pixmap (GUI.options, logo_xpm);
      gtk_widget_ref (logo_REALmagic);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "logo_REALmagic", logo_REALmagic,
			    (GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (logo_REALmagic);
      gtk_box_pack_start (GTK_BOX (vbox1), logo_REALmagic , TRUE, FALSE, 0 );
      
      hbuttonbox1 = gtk_hbutton_box_new ();
      gtk_widget_ref (hbuttonbox1);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "hbuttonbox1", hbuttonbox1,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (hbuttonbox1);
      gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, TRUE, FALSE,10);
      gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_SPREAD);
      
      OK = gtk_button_new_with_label ("");
      OK_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (OK)->child),
					_("_OK"));
      gtk_widget_add_accelerator (OK, "clicked", accel_group,
				  OK_key, GDK_MOD1_MASK, 0);
      gtk_widget_ref (OK);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "OK", OK,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (OK);
      
      gtk_container_add (GTK_CONTAINER (hbuttonbox1), OK);
      gtk_widget_add_accelerator (OK, "clicked", accel_group,
				  GDK_K, GDK_MOD1_MASK,
				  GTK_ACCEL_VISIBLE);
      
      
      Refresh = gtk_button_new_with_label ("");
      Refresh_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (Refresh)->child),
					   _("_Refresh"));
      gtk_widget_add_accelerator (Refresh, "clicked", accel_group,
				  Refresh_key, GDK_MOD1_MASK, 0);
      gtk_widget_ref (Refresh);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "Refresh", Refresh,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (Refresh);
      gtk_widget_hide (Refresh);

      gtk_container_add (GTK_CONTAINER (hbuttonbox1), Refresh);
      gtk_widget_add_accelerator (Refresh, "clicked", accel_group,
				  GDK_R, GDK_MOD1_MASK,
				  GTK_ACCEL_VISIBLE);

      Cancel = gtk_button_new_with_label ("");
      Cancel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (Cancel)->child),
					   _("_Cancel"));
      gtk_widget_add_accelerator (Cancel, "clicked", accel_group,
				  Cancel_key, GDK_MOD1_MASK, 0);
      gtk_widget_ref (Cancel);
      gtk_object_set_data_full (GTK_OBJECT (GUI.options), "Cancel", Cancel,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (Cancel);
      gtk_container_add (GTK_CONTAINER (hbuttonbox1), Cancel);
      gtk_widget_add_accelerator (Cancel, "clicked", accel_group,
				  GDK_C, GDK_MOD1_MASK,
				  GTK_ACCEL_VISIBLE);
      
      gtk_signal_connect(GTK_OBJECT (GUI.options), "delete_event",
			 GTK_SIGNAL_FUNC (C_Cancel_clicked),
			 NULL);
      
      gtk_signal_connect(GTK_OBJECT (GUI.options), "destroy",
			 GTK_SIGNAL_FUNC (C_Cancel_clicked),
			 NULL);
      
      gtk_signal_connect(GTK_OBJECT (Refresh), "clicked",
			 GTK_SIGNAL_FUNC (refresh_all_cb),
			 GTK_WIDGET(GUI.options));
      
      gtk_signal_connect(GTK_OBJECT (Cancel), "clicked",
			 GTK_SIGNAL_FUNC (C_Cancel_clicked),
			 NULL);
      
      gtk_signal_connect (GTK_OBJECT (OK), "clicked",
			  GTK_SIGNAL_FUNC (C_Ok_clicked),
			  NULL); // save_options
      
      gtk_window_add_accel_group (GTK_WINDOW (GUI.options), accel_group);
      set_window_icon(GUI.options,REALmagic_xpm);
      
      gtk_widget_show(GUI.options);
      refresh_all_cb(NULL,GUI.options);
    }
}
