/*****************************************************************************/
/*
 *      ns2ktvgui.c -- REALmagic NS2000TV setting application
 *
 *      Copyright (C) 2000 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 "ns2ktvgui.h"
#include "ns2ktvgui_cb.h"

/* include pixmaps*/
#include"./pixmaps/venlarge.xpm"
#include"./pixmaps/henlarge.xpm"
#include"./pixmaps/vreduce.xpm"
#include"./pixmaps/hreduce.xpm"
#include"./pixmaps/down.xpm"
#include"./pixmaps/left.xpm"
#include"./pixmaps/right.xpm"
#include"./pixmaps/up.xpm"
#include "./pixmaps/brightns.xpm"
#include "./pixmaps/contrast.xpm"
#include "./pixmaps/saturatn.xpm"
#include "./pixmaps/sharpnss.xpm"
#include "./pixmaps/flicker.xpm"
#include"./pixmaps/REALmagic.xpm"
#include"./pixmaps/logo.xpm"

void my_gtk_widget_destroy(GtkWidget ** widget)
{
  gtk_widget_destroy(*widget);
}

GtkWidget* create_pixmap(GtkWidget *widget, char ** filename)
{
  GtkWidget *pixmap;
  GdkPixmap *gdkpixmap;
  GdkBitmap *mask;
  GdkColormap *colormap;
  
  colormap = gtk_widget_get_colormap (widget);
  gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask, NULL, filename );
  pixmap = gtk_pixmap_new (gdkpixmap, mask);
  
  return pixmap;
}

void set_window_icon(GtkWidget *widget, char ** pixmap_data)
{
	GdkPixmap *gdk_pixmap;
	GdkBitmap *gdk_mask;
      
 	gtk_widget_realize(widget);

	gdk_pixmap = gdk_pixmap_create_from_xpm_d (widget->window, &gdk_mask, NULL,pixmap_data);

	gdk_window_set_icon(widget->window, NULL, gdk_pixmap, gdk_mask);
}


GtkWidget * create_TV_standard_frame(void)
{
  GtkWidget *frame;
  GtkWidget *vbox1;
  GSList *group;
  GtkWidget *radioNTSC, *radioNTSCjapan, *radioPAL, *radioHDTV480;


  /* Create a Frame */
  frame = gtk_frame_new(NULL);
 
  /* Set the frame's label */
  gtk_frame_set_label( GTK_FRAME(frame), "TV Standard" );
  /* 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);
  
  vbox1 = gtk_vbox_new (FALSE, 5);
  gtk_container_set_border_width (GTK_CONTAINER (vbox1), 5);
  gtk_container_add(GTK_CONTAINER(frame), vbox1);
  gtk_widget_show (vbox1);

  radioNTSC = gtk_radio_button_new_with_label (NULL, "NTSC");
  gtk_widget_ref (radioNTSC);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioNTSC", radioNTSC,
			    (GtkDestroyNotify) gtk_widget_unref);

  gtk_box_pack_start (GTK_BOX (vbox1), radioNTSC, TRUE, TRUE, 0);
  gtk_widget_show (radioNTSC);
  group = gtk_radio_button_group (GTK_RADIO_BUTTON (radioNTSC));
      
  radioNTSCjapan = gtk_radio_button_new_with_label (group, "NTSC Japan");
  gtk_widget_ref (radioNTSCjapan);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioNTSCjapan", radioNTSCjapan,
			    (GtkDestroyNotify) gtk_widget_unref);

  gtk_box_pack_start (GTK_BOX (vbox1), radioNTSCjapan, TRUE, TRUE, 0);
  gtk_widget_show (radioNTSCjapan);

  radioPAL = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radioNTSCjapan)), "PAL");
  gtk_widget_ref (radioPAL);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioPAL", radioPAL,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_box_pack_start (GTK_BOX (vbox1), radioPAL, TRUE, TRUE, 0);
  gtk_widget_show (radioPAL);
  
  radioHDTV480 = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radioPAL)), "HDTV 480");
  gtk_widget_ref (radioHDTV480);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioHDTV480", radioHDTV480,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_box_pack_start (GTK_BOX (vbox1), radioHDTV480, TRUE, TRUE, 0);
  gtk_widget_show (radioHDTV480);

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioNTSC), FALSE);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioNTSCjapan), FALSE);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioPAL), FALSE);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioHDTV480), FALSE);


  gtk_signal_connect(GTK_OBJECT (radioNTSC), "toggled",
		     GTK_SIGNAL_FUNC(switch_TVstandard_cb),
		     GUINT_TO_POINTER(SET_NTSC));
      
  gtk_signal_connect(GTK_OBJECT (radioNTSCjapan), "toggled",
		     GTK_SIGNAL_FUNC(switch_TVstandard_cb),
		     GUINT_TO_POINTER(escNtscPedestal));
  
  gtk_signal_connect(GTK_OBJECT (radioPAL), "toggled",
		     GTK_SIGNAL_FUNC(switch_TVstandard_cb),
		     GUINT_TO_POINTER(SET_PAL));
  
  gtk_signal_connect(GTK_OBJECT (radioHDTV480), "toggled",
		     GTK_SIGNAL_FUNC(switch_TVstandard_cb),
		     GUINT_TO_POINTER(SET_480P));
  return frame;
}

GtkWidget * create_Output_Mode_frame(void)
{
  GtkWidget *frame;
  GtkWidget *vbox1;
  GSList *group;
  GtkWidget *radioOFF, *radioCOMPOSITE, *radioRGB, *radioYUV;


  /* Create a Frame */
  frame = gtk_frame_new(NULL);
 
  /* Set the frame's label */
  gtk_frame_set_label( GTK_FRAME(frame), "Output Mode" );
  /* 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);
  
  vbox1 = gtk_vbox_new (FALSE, 5);
  gtk_container_set_border_width (GTK_CONTAINER (vbox1), 5);
  gtk_container_add(GTK_CONTAINER(frame), vbox1);
  gtk_widget_show (vbox1);

  radioOFF = gtk_radio_button_new_with_label (NULL, "Disable (Off)");
  gtk_widget_ref (radioOFF);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioOFF", radioOFF,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_box_pack_start (GTK_BOX (vbox1), radioOFF, TRUE, TRUE, 0);
  gtk_widget_show (radioOFF);
  group = gtk_radio_button_group (GTK_RADIO_BUTTON (radioOFF));
      
  radioCOMPOSITE = gtk_radio_button_new_with_label (group, "Composite/S-Video");
  gtk_widget_ref (radioCOMPOSITE);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioCOMPOSITE", radioCOMPOSITE,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_box_pack_start (GTK_BOX (vbox1), radioCOMPOSITE, TRUE, TRUE, 0);
  gtk_widget_show (radioCOMPOSITE);

  radioRGB = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radioCOMPOSITE)), "RGB");
  gtk_widget_ref (radioRGB);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioRGB", radioRGB,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_box_pack_start (GTK_BOX (vbox1), radioRGB, TRUE, TRUE, 0);
  gtk_widget_show (radioRGB);
  
  radioYUV = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radioRGB)), "YUV");
  gtk_widget_ref (radioYUV);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioYUV", radioYUV,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_box_pack_start (GTK_BOX (vbox1), radioYUV, TRUE, TRUE, 0);
  gtk_widget_show (radioYUV);

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioOFF), FALSE);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioCOMPOSITE), FALSE);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioRGB), FALSE);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioYUV), FALSE);


  gtk_signal_connect(GTK_OBJECT (radioOFF), "toggled",
		     GTK_SIGNAL_FUNC(switch_TVoutput_mode_cb),
		     GUINT_TO_POINTER(OUTPUT_OFF));
      
  gtk_signal_connect(GTK_OBJECT (radioCOMPOSITE), "toggled",
		     GTK_SIGNAL_FUNC(switch_TVoutput_mode_cb),
		     GUINT_TO_POINTER(COMPOSITE));
  
  gtk_signal_connect(GTK_OBJECT (radioRGB), "toggled",
		     GTK_SIGNAL_FUNC(switch_TVoutput_mode_cb),
		     GUINT_TO_POINTER(COMPONENT_RGB));
  
  gtk_signal_connect(GTK_OBJECT (radioYUV), "toggled",
		     GTK_SIGNAL_FUNC(switch_TVoutput_mode_cb),
		     GUINT_TO_POINTER(COMPONENT_YUV));
  return frame;
}

GtkWidget * create_Scart_RF_frame(void)
{
  GtkWidget *frame;
  GtkWidget *vbox1;
  GSList *group;
  GtkWidget *radioON, *radioOFF;
 /* Create a Frame */
  frame = gtk_frame_new(NULL);
 
  /* Set the frame's label */
  gtk_frame_set_label( GTK_FRAME(frame), "Scart" );
  /* 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);
  
  vbox1 = gtk_vbox_new (FALSE, 5);
  gtk_container_set_border_width (GTK_CONTAINER (vbox1), 5);
  gtk_container_add(GTK_CONTAINER(frame), vbox1);
  gtk_widget_show (vbox1);

  radioON = gtk_radio_button_new_with_label (NULL, "Enabled");
  gtk_widget_ref (radioON);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioON", radioON,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_box_pack_start (GTK_BOX (vbox1), radioON, TRUE, TRUE, 0);
  gtk_widget_show (radioON);
  group = gtk_radio_button_group (GTK_RADIO_BUTTON (radioON));
      
  radioOFF = gtk_radio_button_new_with_label (group, "Disabled");
  gtk_widget_ref (radioOFF);
  gtk_object_set_data_full (GTK_OBJECT (frame), "radioOFF", radioOFF,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_box_pack_start (GTK_BOX (vbox1), radioOFF, TRUE, TRUE, 0);
  gtk_widget_show (radioOFF);

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioON), FALSE);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radioOFF), FALSE);

  gtk_signal_connect(GTK_OBJECT (radioON), "toggled",
		     GTK_SIGNAL_FUNC(switch_Scart_RF_cb),
		     GUINT_TO_POINTER(SCART_COMPOSITE));
  
  gtk_signal_connect(GTK_OBJECT (radioOFF), "toggled",
		     GTK_SIGNAL_FUNC(switch_Scart_RF_cb),
		     GUINT_TO_POINTER(SCART_DISABLE));
  return frame;
}

GtkWidget * create_TVposition_frame(void)
{
  GtkWidget *frame;
  GtkWidget *position;
  GtkWidget *left, *right, *up, *down;
  GtkWidget *left_pixmap, *right_pixmap, *up_pixmap, *down_pixmap;
  GtkAccelGroup *accel_group;

  accel_group = gtk_accel_group_new ();
  
  frame = gtk_frame_new ("TV Position");
  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);

  /* a 3 x 3 table --> 9 boxes */
  position = gtk_table_new (3, 3, TRUE);
  
  gtk_widget_show (position);
  gtk_container_add (GTK_CONTAINER (frame), position);
  gtk_container_set_border_width (GTK_CONTAINER (position), 5);
  GTK_WIDGET_SET_FLAGS (position, GTK_CAN_FOCUS);
  GTK_WIDGET_SET_FLAGS (position, GTK_CAN_DEFAULT);
  gtk_table_set_row_spacings (GTK_TABLE (position),1);
  gtk_table_set_col_spacings (GTK_TABLE (position),1);
  
  /* left arrow */
  left = gtk_button_new ();
  gtk_widget_ref (left);
  gtk_object_set_data_full (GTK_OBJECT (frame), "left", left,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (left);
  gtk_table_attach (GTK_TABLE (position), left, 0, 1, 1, 2,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (left, GTK_CAN_FOCUS);
  gtk_widget_add_accelerator (left, "pressed", accel_group,
                              GDK_KP_4, 0,
                              GTK_ACCEL_VISIBLE);
  left_pixmap = create_pixmap (frame, left_xpm);
  gtk_widget_show (left_pixmap);
  gtk_container_add (GTK_CONTAINER (left), left_pixmap);

  /* right arrow */
  right = gtk_button_new ();
  gtk_widget_ref (right);
  gtk_object_set_data_full (GTK_OBJECT (frame), "right", right,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (right);
  gtk_table_attach (GTK_TABLE (position), right, 2, 3, 1, 2,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (right, GTK_CAN_FOCUS);
  gtk_widget_add_accelerator (right, "pressed", accel_group,
                              GDK_KP_6, 0,
                              GTK_ACCEL_VISIBLE);
  right_pixmap = create_pixmap (frame, right_xpm);
  gtk_widget_show (right_pixmap);
  gtk_container_add (GTK_CONTAINER (right), right_pixmap);

  /* up arrow */
  up = gtk_button_new ();
  gtk_widget_ref (up);
  gtk_object_set_data_full (GTK_OBJECT (frame), "up", up,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (up);
  gtk_table_attach (GTK_TABLE (position), up, 1, 2, 0, 1,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (up, GTK_CAN_FOCUS);
  gtk_widget_add_accelerator (up, "pressed", accel_group,
                              GDK_KP_8, 0,
                              GTK_ACCEL_VISIBLE);
  up_pixmap = create_pixmap (frame, up_xpm);
  gtk_widget_show (up_pixmap);
  gtk_container_add (GTK_CONTAINER (up), up_pixmap);
  
  /* down arrow */
  down = gtk_button_new ();
  gtk_widget_ref (down);
  gtk_object_set_data_full (GTK_OBJECT (frame), "down", down,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (down);
  gtk_table_attach (GTK_TABLE (position), down, 1, 2, 2, 3,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (down, GTK_CAN_FOCUS);
  gtk_widget_add_accelerator (down, "pressed", accel_group,
                              GDK_KP_2, 0,
                              GTK_ACCEL_VISIBLE);
  down_pixmap = create_pixmap (frame, down_xpm);
  gtk_widget_show (down_pixmap);
  gtk_container_add (GTK_CONTAINER (down), down_pixmap);
  
  gtk_signal_connect_after (GTK_OBJECT (left), "pressed",
			    GTK_SIGNAL_FUNC (position_left_pressed),
			    NULL);
  gtk_signal_connect (GTK_OBJECT (right), "pressed",
                      GTK_SIGNAL_FUNC (position_right_pressed),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (down), "pressed",
		      GTK_SIGNAL_FUNC (position_down_pressed),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (up), "pressed",
                      GTK_SIGNAL_FUNC (position_up_pressed),
                      NULL);
  return frame;
}

GtkWidget * create_TVsize_frame(void)
{
  GtkWidget *frame;
  GtkWidget *size;
  GtkWidget *henlarge, *hreduce, *venlarge, *vreduce;
  GtkWidget *henlarge_pixmap, *venlarge_pixmap, *hreduce_pixmap, *vreduce_pixmap;
  GtkAccelGroup *accel_group;

  accel_group = gtk_accel_group_new ();
  
  frame = gtk_frame_new ("TV Size");
  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);

  /* a 2 x 2 table --> 4 boxes */
  size = gtk_table_new (2, 2, TRUE);
  
  gtk_widget_show (size);
  gtk_container_add (GTK_CONTAINER (frame), size);
  gtk_container_set_border_width (GTK_CONTAINER (size), 5);
  GTK_WIDGET_SET_FLAGS (size, GTK_CAN_FOCUS);
  GTK_WIDGET_SET_FLAGS (size, GTK_CAN_DEFAULT);
  gtk_table_set_row_spacings (GTK_TABLE (size), 5);
  gtk_table_set_col_spacings (GTK_TABLE (size), 5);

  /* henlarge */
  henlarge = gtk_button_new ();
  gtk_widget_ref (henlarge);
  gtk_object_set_data_full (GTK_OBJECT (frame), "henlarge", henlarge,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (henlarge);
  gtk_table_attach (GTK_TABLE (size), henlarge, 0, 1, 0, 1,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 12, 12);
  GTK_WIDGET_UNSET_FLAGS (henlarge, GTK_CAN_FOCUS);
  gtk_widget_add_accelerator (henlarge, "pressed", accel_group,
                              GDK_KP_7, 0,
                              GTK_ACCEL_VISIBLE);
  henlarge_pixmap = create_pixmap (frame, henlarge_xpm);
  gtk_widget_show (henlarge_pixmap);
  gtk_container_add (GTK_CONTAINER (henlarge), henlarge_pixmap);

  /* venlarge */
  venlarge = gtk_button_new ();
  gtk_widget_ref (venlarge);
  gtk_object_set_data_full (GTK_OBJECT (frame), "venlarge", venlarge,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (venlarge);
  gtk_table_attach (GTK_TABLE (size), venlarge, 1, 2, 0, 1,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 12, 12);
  GTK_WIDGET_UNSET_FLAGS (venlarge, GTK_CAN_FOCUS);
  gtk_widget_add_accelerator (venlarge, "pressed", accel_group,
                              GDK_KP_9, 0,
                              GTK_ACCEL_VISIBLE);
  venlarge_pixmap = create_pixmap (frame, venlarge_xpm);
  gtk_widget_show (venlarge_pixmap);
  gtk_container_add (GTK_CONTAINER (venlarge), venlarge_pixmap);

  /* hreduce */
  hreduce = gtk_button_new ();
  gtk_widget_ref (hreduce);
  gtk_object_set_data_full (GTK_OBJECT (frame), "hreduce", hreduce,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hreduce);
  gtk_table_attach (GTK_TABLE (size), hreduce, 0, 1, 1, 2,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 12, 12);
  GTK_WIDGET_UNSET_FLAGS (hreduce, GTK_CAN_FOCUS);
  gtk_widget_add_accelerator (hreduce, "pressed", accel_group,
                              GDK_KP_1, 0,
                              GTK_ACCEL_VISIBLE);
  hreduce_pixmap = create_pixmap (frame, hreduce_xpm);
  gtk_widget_show (hreduce_pixmap);
  gtk_container_add (GTK_CONTAINER (hreduce), hreduce_pixmap);
  
  /* vreduce */
  vreduce = gtk_button_new ();
  gtk_widget_ref (vreduce);
  gtk_object_set_data_full (GTK_OBJECT (frame), "vreduce", vreduce,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vreduce);
  gtk_table_attach (GTK_TABLE (size), vreduce, 1, 2, 1, 2,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 12, 12);
  GTK_WIDGET_UNSET_FLAGS (vreduce, GTK_CAN_FOCUS);
  gtk_widget_add_accelerator (vreduce, "pressed", accel_group,
                              GDK_KP_3, 0,
                              GTK_ACCEL_VISIBLE);
  vreduce_pixmap = create_pixmap (frame, vreduce_xpm);
  gtk_widget_show (vreduce_pixmap);
  gtk_container_add (GTK_CONTAINER (vreduce), vreduce_pixmap);
  
  gtk_signal_connect_after (GTK_OBJECT (henlarge), "pressed",
			    GTK_SIGNAL_FUNC (size_henlarge_pressed),
			    NULL);
  gtk_signal_connect (GTK_OBJECT (venlarge), "pressed",
                      GTK_SIGNAL_FUNC (size_venlarge_pressed),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (vreduce), "pressed",
		      GTK_SIGNAL_FUNC (size_vreduce_pressed),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (hreduce), "pressed",
                      GTK_SIGNAL_FUNC (size_hreduce_pressed),
                      NULL);
  return frame;
}

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

  GtkWidget *brightness_pixmap, *saturation_pixmap, *contrast_pixmap, *sharpness_pixmap, *flicker_pixmap;
  GtkWidget *brightness_scale, *saturation_scale, *contrast_scale, *sharpness_scale, *flicker_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/Sh/Fl" );
  /* 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, 5, 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);
  
  sharpness_pixmap = create_pixmap (frame, sharpnss_xpm);
  gtk_widget_show (sharpness_pixmap);
  gtk_table_attach (GTK_TABLE (table), sharpness_pixmap, 3, 4, 0, 1,
		    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);

  flicker_pixmap = create_pixmap (frame, flicker_xpm);
  gtk_widget_show (flicker_pixmap);
  gtk_table_attach (GTK_TABLE (table), flicker_pixmap, 4, 5, 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);
  
  sharpness_scale = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new ( (SHP_MIN+SHP_MAX)-SHP_RESET, SHP_MIN, SHP_MAX, 1, 0, 0)));
  gtk_widget_ref (sharpness_scale);
  gtk_object_set_data_full (GTK_OBJECT (frame), "sharpness_scale", sharpness_scale,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (sharpness_scale);
  gtk_table_attach (GTK_TABLE (table), sharpness_scale, 3, 4, 1, 2,
		   (GtkAttachOptions) (GTK_FILL),
		   (GtkAttachOptions) (GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (sharpness_scale), FALSE);
  
  flicker_scale = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new ( (FLICKER_MIN+FLICKER_MAX)-FLICKER_RESET, FLICKER_MIN, FLICKER_MAX, 1, 0, 0)));
  gtk_widget_ref (flicker_scale);
  gtk_object_set_data_full (GTK_OBJECT (frame), "flicker_scale", flicker_scale,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (flicker_scale);
  gtk_table_attach (GTK_TABLE (table), flicker_scale, 4, 5, 1, 2,
		   (GtkAttachOptions) (GTK_FILL),
		   (GtkAttachOptions) (GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (flicker_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);
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(sharpness_scale)->adjustment),"value_changed", GTK_SIGNAL_FUNC(sharpness_changed), NULL);
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(flicker_scale)->adjustment),"value_changed", GTK_SIGNAL_FUNC(flicker_changed), NULL);

  return frame;
}


GtkWidget * get_ns2ktv_setting_panel(void)
{
  GtkWidget *setting_panel;

  GtkWidget *vbox1, *table, *hbuttonbox1;
  GtkWidget *logo_REALmagic;
  GtkWidget *tvstd_frame, *tvoutmode_frame, *scart_rf_frame;
  GtkWidget *tvpos_frame, *tvsize_frame, *tvBSC_frame;
  guint Save_key;
  GtkWidget *Save;
  guint Refresh_key;
  GtkWidget *Refresh;
  guint Reset_key;
  GtkWidget *Reset;
  guint Quit_key;
  GtkWidget *Quit;

  GtkAccelGroup *accel_group;

  accel_group = gtk_accel_group_new ();

  setting_panel = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_realize (setting_panel);
  
  gtk_window_set_title (GTK_WINDOW (setting_panel), _("NetStream 2000 TV Panel Setting"));
  gtk_window_set_position (GTK_WINDOW (setting_panel), GTK_WIN_POS_CENTER);
  gtk_window_set_policy (GTK_WINDOW (setting_panel), FALSE, FALSE, TRUE);

  vbox1 = gtk_vbox_new (FALSE, 0);
  
  gtk_widget_show (vbox1);
  gtk_container_add (GTK_CONTAINER (setting_panel), vbox1);
  gtk_container_set_border_width (GTK_CONTAINER (setting_panel), 5);
  /* a 2 x 3 table --> 6 boxes */
  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);

  tvstd_frame = create_TV_standard_frame(); 
  gtk_widget_ref (tvstd_frame);
  gtk_object_set_data_full (GTK_OBJECT (setting_panel), "tvstd_frame", tvstd_frame,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (tvstd_frame);
  gtk_table_attach (GTK_TABLE (table), tvstd_frame, 0, 1, 0, 1,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND,5, 5);
  GTK_WIDGET_UNSET_FLAGS (tvstd_frame, GTK_CAN_FOCUS);

  tvoutmode_frame = create_Output_Mode_frame(); 
  gtk_widget_ref (tvoutmode_frame);
  gtk_object_set_data_full (GTK_OBJECT (setting_panel), "tvoutmode_frame", tvoutmode_frame,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show(tvoutmode_frame); 
  gtk_table_attach (GTK_TABLE (table),tvoutmode_frame, 1, 2, 0, 1,
                   GTK_FILL|GTK_EXPAND,
                   GTK_FILL|GTK_EXPAND, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (tvoutmode_frame, GTK_CAN_FOCUS);

  scart_rf_frame = create_Scart_RF_frame(); 
  gtk_widget_ref (scart_rf_frame);
  gtk_object_set_data_full (GTK_OBJECT (setting_panel), "scart_rf_frame", scart_rf_frame,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (scart_rf_frame);
  gtk_table_attach (GTK_TABLE (table), scart_rf_frame, 2, 3, 0, 1,
                    GTK_FILL|GTK_EXPAND,
		    GTK_FILL|GTK_EXPAND, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (scart_rf_frame, GTK_CAN_FOCUS);
  
  tvBSC_frame = create_BrSaCoShFl_frame(); 
  gtk_widget_ref (tvBSC_frame);
  gtk_object_set_data_full (GTK_OBJECT (setting_panel), "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);

  tvpos_frame = create_TVposition_frame(); gtk_widget_show (tvpos_frame);
  gtk_table_attach (GTK_TABLE (table),tvpos_frame, 1, 2, 1, 2,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (tvpos_frame, GTK_CAN_FOCUS);
  
  tvsize_frame = create_TVsize_frame(); gtk_widget_show (tvsize_frame);
  gtk_table_attach (GTK_TABLE (table), tvsize_frame, 2, 3, 1, 2,
                    GTK_FILL|GTK_EXPAND,
                    GTK_FILL|GTK_EXPAND, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (tvsize_frame, GTK_CAN_FOCUS);
  

  logo_REALmagic = create_pixmap (setting_panel, logo_xpm);
  gtk_widget_ref (logo_REALmagic);
  gtk_object_set_data_full (GTK_OBJECT (setting_panel), "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 (setting_panel), "hbuttonbox1", hbuttonbox1,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbuttonbox1);
  gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, TRUE, FALSE,10);
  // gtk_widget_set_usize (hbuttonbox1, -2, 15);
  gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_SPREAD);
  Save = gtk_button_new_with_label ("");
  Save_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (Save)->child),
				  _("_Save"));
  gtk_widget_add_accelerator (Save, "clicked", accel_group,
			      Save_key, GDK_MOD1_MASK, 0);
  gtk_widget_ref (Save);
  gtk_object_set_data_full (GTK_OBJECT (setting_panel), "Save", Save,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (Save);

  gtk_container_add (GTK_CONTAINER (hbuttonbox1), Save);
  gtk_widget_add_accelerator (Save, "clicked", accel_group,
				  GDK_S, 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 (setting_panel), "Refresh", Refresh,
				(GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (Refresh);
  gtk_container_add (GTK_CONTAINER (hbuttonbox1), Refresh);
  gtk_widget_add_accelerator (Refresh, "clicked", accel_group,
				  GDK_R, GDK_MOD1_MASK,
				  GTK_ACCEL_VISIBLE);
  
  Reset = gtk_button_new_with_label ("");
  Reset_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (Reset)->child),
				     _("_Default"));
  gtk_widget_add_accelerator (Reset, "clicked", accel_group,
			      Reset_key, GDK_MOD1_MASK, 0);
  gtk_widget_ref (Reset);
  gtk_object_set_data_full (GTK_OBJECT (setting_panel), "Reset", Reset,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (Reset);
  gtk_container_add (GTK_CONTAINER (hbuttonbox1), Reset);
  gtk_widget_add_accelerator (Reset, "clicked", accel_group,
			      GDK_D, GDK_MOD1_MASK,
			      GTK_ACCEL_VISIBLE);
  
  Quit = gtk_button_new_with_label ("");
  Quit_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (Quit)->child),
				      _("_Quit"));
  gtk_widget_add_accelerator (Quit, "clicked", accel_group,
			      Quit_key, GDK_MOD1_MASK, 0);
  gtk_widget_ref (Quit);
  gtk_object_set_data_full (GTK_OBJECT (setting_panel), "Quit", Quit,
				(GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (Quit);
  gtk_container_add (GTK_CONTAINER (hbuttonbox1), Quit);
  gtk_widget_add_accelerator (Quit, "clicked", accel_group,
				  GDK_Q, GDK_MOD1_MASK,
				  GTK_ACCEL_VISIBLE);

  gtk_signal_connect_object (GTK_OBJECT (setting_panel), "delete_event",
			     GTK_SIGNAL_FUNC (gtk_main_quit),
			     setting_panel);
  
  gtk_signal_connect_object (GTK_OBJECT (setting_panel), "destroy",
			     GTK_SIGNAL_FUNC (gtk_main_quit),
			     setting_panel);
  
  gtk_signal_connect (GTK_OBJECT (Save), "clicked",
		      GTK_SIGNAL_FUNC (Save_clicked),
		      NULL); // save_options
  
  gtk_signal_connect(GTK_OBJECT (Reset), "clicked",
		     GTK_SIGNAL_FUNC (Reset_clicked),
		     GTK_WIDGET(setting_panel));

  gtk_signal_connect(GTK_OBJECT (Refresh), "clicked",
		     GTK_SIGNAL_FUNC (refresh_all_cb),
		     GTK_WIDGET(setting_panel));
  
  gtk_signal_connect (GTK_OBJECT (Quit), "clicked",
		      GTK_SIGNAL_FUNC (gtk_main_quit),
		      NULL);
  
  
  gtk_window_add_accel_group (GTK_WINDOW (setting_panel), accel_group);

  set_window_icon(setting_panel,REALmagic_xpm);
  
  /* Refresh all */

  refresh_all_cb(NULL,setting_panel);
  
  return setting_panel;
}





