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

/*
 *      configuration.c -- REALmagic calibration application 
 *
 *      Copyright (C) 2000 Sigma Designs
 *                    written by Nicolas Vignal <nicolas_vignal@sdesigns.com>
 *                    modified by Emmanuel Michon <emmanuel_michon@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 <stdlib.h>
#include "define.h"

#include "configuration.h"
#include "configurationCB.h"


// sorry BOOL and BYTE conflict with FMP types
Bool XF86VidModeGetViewPort(Display *display,int screen,int *x_return,int *y_return);

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

GtkWidget*
create_Configuration (void)
{
  GtkWidget *Configuration;
  GtkWidget *vbox1;
  GtkWidget *hbox1;
  GtkWidget *vbox9;
  GtkWidget *optionmenu1;
  GtkWidget *optionmenu1_menu;
  GtkWidget *glade_menuitem;
  GtkWidget *vbox11;
  GtkWidget *Default_key_color;
  GtkWidget *optionmenu2;
  GtkWidget *optionmenu2_menu;
  GtkWidget *hbox7;
  GtkWidget *hbox8;
  GtkWidget *redpixmap;
  GtkWidget *redlabel;
  GtkWidget *hbox9;
  GtkWidget *greenpixmap;
  GtkWidget *greenlabel;
  GtkWidget *hbox10;
  GtkWidget *bleupixmap;
  GtkWidget *bleulabel;
  GtkWidget *hbox5;
  GtkWidget *frame1;
  GtkWidget *vbox10;
  GtkWidget *hbox6;
  GtkWidget *pixmap1;
  GtkWidget *volume;
  GtkWidget *pixmap2;
  GtkWidget *balance;
  GtkWidget *frame2;
  GtkWidget *table2;
  GtkWidget *pixmap5;
  GtkWidget *pixmap6;
  GtkWidget *pixmap7;
  GtkWidget *brightness;
  GtkWidget *saturation;
  GtkWidget *contrast;
  GtkWidget *vbox2;
  GtkWidget *vbuttonbox1;
  guint AdjustBorder_key;
  GtkWidget *AdjustBorder;
  guint AutoCalibration_key;
  GtkWidget *AutoCalibration;
  guint ResetDefaults_key;
  GtkWidget *ResetDefaults;
  guint Advanced_key;
  GtkWidget *Advanced;
  GtkWidget *logo_REALmagic;
  GtkWidget *hbuttonbox1;
  guint Ok_key;
  GtkWidget *Ok;
  guint Cancel_key;
  GtkWidget *Cancel;
  GtkAccelGroup *accel_group;

  accel_group = gtk_accel_group_new ();

  Configuration = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (Configuration), "Configuration", Configuration);
  gtk_widget_set_usize (Configuration, 340, 315);
  gtk_window_set_title (GTK_WINDOW (Configuration), _("REALmagic Configuration"));
  gtk_window_set_position (GTK_WINDOW (Configuration), GTK_WIN_POS_CENTER);
  gtk_window_set_policy (GTK_WINDOW (Configuration), FALSE, FALSE, FALSE);

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

  hbox1 = gtk_hbox_new (FALSE, 20);
  gtk_widget_ref (hbox1);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "hbox1", hbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox1);
  gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (hbox1), 10);

  vbox9 = gtk_vbox_new (FALSE, 11);
  gtk_widget_ref (vbox9);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "vbox9", vbox9,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox9);
  gtk_box_pack_start (GTK_BOX (hbox1), vbox9, TRUE, TRUE, 0);
  gtk_widget_set_usize (vbox9, 190, -2);

  optionmenu1 = gtk_option_menu_new ();
  gtk_widget_ref (optionmenu1);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "optionmenu1", optionmenu1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (optionmenu1);
  gtk_box_pack_start (GTK_BOX (vbox9), optionmenu1, FALSE, FALSE, 0);
  gtk_widget_set_usize (optionmenu1, -2, 24);
  optionmenu1_menu = gtk_menu_new ();
  glade_menuitem = gtk_menu_item_new_with_label (_("Modify default and current settings"));
  gtk_widget_show (glade_menuitem);
  gtk_menu_append (GTK_MENU (optionmenu1_menu), glade_menuitem);
  gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu1), optionmenu1_menu);

  vbox11 = gtk_vbox_new (FALSE, 0);
  gtk_widget_ref (vbox11);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "vbox11", vbox11,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox11);
  gtk_box_pack_start (GTK_BOX (vbox9), vbox11, FALSE, TRUE, 0);

  Default_key_color = gtk_label_new (_("Default key color"));
  gtk_widget_ref (Default_key_color);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "Default_key_color", Default_key_color,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (Default_key_color);
  gtk_box_pack_start (GTK_BOX (vbox11), Default_key_color, FALSE, FALSE, 0);
  gtk_widget_set_usize (Default_key_color, -2, 20);
  gtk_label_set_justify (GTK_LABEL (Default_key_color), GTK_JUSTIFY_LEFT);
  gtk_misc_set_alignment (GTK_MISC (Default_key_color), 2.98023e-08, 0.5);

  optionmenu2 = gtk_option_menu_new ();
  gtk_widget_ref (optionmenu2);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "optionmenu2", optionmenu2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (optionmenu2);
  gtk_box_pack_start (GTK_BOX (vbox11), optionmenu2, FALSE, FALSE, 0);
  gtk_widget_set_usize (optionmenu2, -2, 24);
  optionmenu2_menu = gtk_menu_new ();
  glade_menuitem = gtk_menu_item_new_with_label (_("000           040          000"));
  gtk_widget_show (glade_menuitem);
  gtk_menu_append (GTK_MENU (optionmenu2_menu), glade_menuitem);
  gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu2), optionmenu2_menu);

  hbox7 = gtk_hbox_new (TRUE, 0);
  gtk_widget_ref (hbox7);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "hbox7", hbox7,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox7);
  gtk_box_pack_start (GTK_BOX (vbox11), hbox7, FALSE, TRUE, 0);

  hbox8 = gtk_hbox_new (FALSE, 10);
  gtk_widget_ref (hbox8);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "hbox8", hbox8,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox8);
  gtk_box_pack_start (GTK_BOX (hbox7), hbox8, TRUE, FALSE, 0);

  redpixmap = create_pixmap (Configuration, red_xpm);
  gtk_widget_ref (redpixmap);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "redpixmap", redpixmap,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (redpixmap);
  gtk_box_pack_start (GTK_BOX (hbox8), redpixmap, TRUE, TRUE, 0);

  redlabel = gtk_label_new (_("0"));
  gtk_widget_ref (redlabel);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "redlabel", redlabel,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (redlabel);
  gtk_box_pack_start (GTK_BOX (hbox8), redlabel, FALSE, FALSE, 0);

  hbox9 = gtk_hbox_new (FALSE, 10);
  gtk_widget_ref (hbox9);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "hbox9", hbox9,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox9);
  gtk_box_pack_start (GTK_BOX (hbox7), hbox9, TRUE, FALSE, 0);

  greenpixmap = create_pixmap (Configuration, green_xpm);
  gtk_widget_ref (greenpixmap);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "greenpixmap", greenpixmap,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (greenpixmap);
  gtk_box_pack_start (GTK_BOX (hbox9), greenpixmap, TRUE, TRUE, 0);

  greenlabel = gtk_label_new (_("40"));
  gtk_widget_ref (greenlabel);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "greenlabel", greenlabel,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (greenlabel);
  gtk_box_pack_start (GTK_BOX (hbox9), greenlabel, TRUE, TRUE, 0);

  hbox10 = gtk_hbox_new (FALSE, 10);
  gtk_widget_ref (hbox10);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "hbox10", hbox10,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox10);
  gtk_box_pack_start (GTK_BOX (hbox7), hbox10, TRUE, FALSE, 0);

  bleupixmap = create_pixmap (Configuration, blue_xpm);
  gtk_widget_ref (bleupixmap);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "bleupixmap", bleupixmap,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (bleupixmap);
  gtk_box_pack_start (GTK_BOX (hbox10), bleupixmap, TRUE, TRUE, 0);

  bleulabel = gtk_label_new (_("0"));
  gtk_widget_ref (bleulabel);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "bleulabel", bleulabel,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (bleulabel);
  gtk_box_pack_start (GTK_BOX (hbox10), bleulabel, FALSE, FALSE, 0);

  hbox5 = gtk_hbox_new (TRUE, 10);
  gtk_widget_ref (hbox5);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "hbox5", hbox5,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox5);
  gtk_box_pack_start (GTK_BOX (vbox9), hbox5, TRUE, TRUE, 0);

  frame1 = gtk_frame_new (NULL);
  gtk_widget_ref (frame1);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "frame1", frame1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (frame1);
  gtk_box_pack_start (GTK_BOX (hbox5), frame1, FALSE, TRUE, 0);
  gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_IN);

  vbox10 = gtk_vbox_new (FALSE, 10);
  gtk_widget_ref (vbox10);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "vbox10", vbox10,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox10);
  gtk_container_add (GTK_CONTAINER (frame1), vbox10);
  gtk_container_set_border_width (GTK_CONTAINER (vbox10), 10);

  hbox6 = gtk_hbox_new (TRUE, 10);
  gtk_widget_ref (hbox6);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "hbox6", hbox6,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbox6);
  gtk_box_pack_start (GTK_BOX (vbox10), hbox6, TRUE, TRUE, 0);

  pixmap1 = create_pixmap (Configuration, audiol_xpm);
  gtk_widget_ref (pixmap1);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "pixmap1", pixmap1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (pixmap1);
  gtk_box_pack_start (GTK_BOX (hbox6), pixmap1, FALSE, FALSE, 0);

  volume = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (38.9, 0, 100, 1, 0, 0)));
  gtk_widget_ref (volume);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "volume", volume,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (volume);
  gtk_box_pack_start (GTK_BOX (hbox6), volume, FALSE, TRUE, 0);
  gtk_scale_set_draw_value (GTK_SCALE (volume), FALSE);

  pixmap2 = create_pixmap (Configuration, audior_xpm);
  gtk_widget_ref (pixmap2);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "pixmap2", pixmap2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (pixmap2);
  gtk_box_pack_start (GTK_BOX (hbox6), pixmap2, FALSE, FALSE, 0);

  balance = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, -100, 100, 1, 0, 0)));
  gtk_widget_ref (balance);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "balance", balance,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (balance);
  gtk_box_pack_start (GTK_BOX (vbox10), balance, FALSE, FALSE, 0);
  gtk_widget_set_usize (balance, -2, 10);
  gtk_scale_set_draw_value (GTK_SCALE (balance), FALSE);
  gtk_scale_set_value_pos (GTK_SCALE (balance), GTK_POS_LEFT);
  gtk_scale_set_digits (GTK_SCALE (balance), 0);

  frame2 = gtk_frame_new (NULL);
  gtk_widget_ref (frame2);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "frame2", frame2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (frame2);
  gtk_box_pack_start (GTK_BOX (hbox5), frame2, TRUE, TRUE, 0);
  gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);

  table2 = gtk_table_new (2, 3, FALSE);
  gtk_widget_ref (table2);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "table2", table2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (table2);
  gtk_container_add (GTK_CONTAINER (frame2), table2);
  gtk_container_set_border_width (GTK_CONTAINER (table2), 10);

  pixmap5 = create_pixmap (Configuration, brightns_xpm);
  gtk_widget_ref (pixmap5);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "pixmap5", pixmap5,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (pixmap5);
  gtk_table_attach (GTK_TABLE (table2), pixmap5, 0, 1, 0, 1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);

  pixmap6 = create_pixmap (Configuration, saturatn_xpm);
  gtk_widget_ref (pixmap6);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "pixmap6", pixmap6,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (pixmap6);
  gtk_table_attach (GTK_TABLE (table2), pixmap6, 1, 2, 0, 1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (GTK_FILL), 0, 0);

  pixmap7 = create_pixmap (Configuration, contrast_xpm);
  gtk_widget_ref (pixmap7);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "pixmap7", pixmap7,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (pixmap7);
  gtk_table_attach (GTK_TABLE (table2), pixmap7, 2, 3, 0, 1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (GTK_FILL), 0, 0);

  brightness = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 1000, 1, 0, 0)));
  gtk_widget_ref (brightness);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "brightness", brightness,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (brightness);
  gtk_table_attach (GTK_TABLE (table2), brightness, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (brightness), FALSE);

  saturation = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 1000, 1, 0, 0)));
  gtk_widget_ref (saturation);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "saturation", saturation,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (saturation);
  gtk_table_attach (GTK_TABLE (table2), saturation, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (saturation), FALSE);

  contrast = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 1000, 1, 0, 0)));
  gtk_widget_ref (contrast);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "contrast", contrast,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (contrast);
  gtk_table_attach (GTK_TABLE (table2), contrast, 2, 3, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (GTK_FILL), 0, 0);
  gtk_scale_set_draw_value (GTK_SCALE (contrast), FALSE);

  vbox2 = gtk_vbox_new (FALSE, 0);
  gtk_widget_ref (vbox2);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "vbox2", vbox2,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbox2);
  gtk_box_pack_start (GTK_BOX (hbox1), vbox2, TRUE, TRUE, 0);

  vbuttonbox1 = gtk_vbutton_box_new ();
  gtk_widget_ref (vbuttonbox1);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "vbuttonbox1", vbuttonbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (vbuttonbox1);
  gtk_box_pack_start (GTK_BOX (vbox2), vbuttonbox1, TRUE, TRUE, 0);

  AdjustBorder = gtk_button_new_with_label ("");
  AdjustBorder_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (AdjustBorder)->child),
                                   _("Adjust _border..."));
  gtk_widget_add_accelerator (AdjustBorder, "clicked", accel_group,
                              AdjustBorder_key, GDK_MOD1_MASK, 0);
  gtk_widget_ref (AdjustBorder);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "AdjustBorder", AdjustBorder,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (AdjustBorder);
  gtk_container_add (GTK_CONTAINER (vbuttonbox1), AdjustBorder);
  gtk_widget_add_accelerator (AdjustBorder, "clicked", accel_group,
                              GDK_b, GDK_MOD1_MASK,
                              GTK_ACCEL_VISIBLE);

  AutoCalibration = gtk_button_new_with_label ("");
  AutoCalibration_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (AutoCalibration)->child),
                                   _("_Auto calibration..."));
  gtk_widget_add_accelerator (AutoCalibration, "clicked", accel_group,
                              AutoCalibration_key, GDK_MOD1_MASK, 0);
  gtk_widget_ref (AutoCalibration);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "AutoCalibration", AutoCalibration,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (AutoCalibration);
  gtk_container_add (GTK_CONTAINER (vbuttonbox1), AutoCalibration);
  gtk_widget_add_accelerator (AutoCalibration, "clicked", accel_group,
                              GDK_A, GDK_MOD1_MASK,
                              GTK_ACCEL_VISIBLE);

  ResetDefaults = gtk_button_new_with_label ("");
  ResetDefaults_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (ResetDefaults)->child),
                                   _("_Reset defaults..."));
  gtk_widget_add_accelerator (ResetDefaults, "clicked", accel_group,
                              ResetDefaults_key, GDK_MOD1_MASK, 0);
  gtk_widget_ref (ResetDefaults);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "ResetDefaults", ResetDefaults,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (ResetDefaults);
  gtk_container_add (GTK_CONTAINER (vbuttonbox1), ResetDefaults);
  gtk_widget_add_accelerator (ResetDefaults, "clicked", accel_group,
                              GDK_R, GDK_MOD1_MASK,
                              GTK_ACCEL_VISIBLE);

  Advanced = gtk_button_new_with_label ("");
  Advanced_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (Advanced)->child),
                                   _("A_dvanced  >>>"));
  gtk_widget_add_accelerator (Advanced, "clicked", accel_group,
                              Advanced_key, GDK_MOD1_MASK, 0);
  gtk_widget_ref (Advanced);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "Advanced", Advanced,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (Advanced);
  gtk_container_add (GTK_CONTAINER (vbuttonbox1), Advanced);
  gtk_widget_add_accelerator (Advanced, "clicked", accel_group,
                              GDK_d, GDK_MOD1_MASK,
                              GTK_ACCEL_VISIBLE);

  logo_REALmagic = create_pixmap (Configuration, logo_xpm);
  gtk_widget_ref (logo_REALmagic);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "logo_REALmagic", logo_REALmagic,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (logo_REALmagic);
  gtk_box_pack_start (GTK_BOX (vbox2), logo_REALmagic, TRUE, TRUE, 0);

  hbuttonbox1 = gtk_hbutton_box_new ();
  gtk_widget_ref (hbuttonbox1);
  gtk_object_set_data_full (GTK_OBJECT (Configuration), "hbuttonbox1", hbuttonbox1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (hbuttonbox1);
  gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, TRUE, TRUE, 0);
  gtk_widget_set_usize (hbuttonbox1, -2, 15);
  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 (Configuration), "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_O, 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 (Configuration), "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 (Configuration), "delete_event",
                      GTK_SIGNAL_FUNC (gtk_main_quit),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (Configuration), "destroy",
                      GTK_SIGNAL_FUNC (gtk_main_quit),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (AdjustBorder), "clicked",
                      GTK_SIGNAL_FUNC (AdjustBorder_clicked),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (AutoCalibration), "clicked",
                      GTK_SIGNAL_FUNC (AutoCalibration_clicked),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (ResetDefaults), "clicked",
                      GTK_SIGNAL_FUNC (ResetDefaults_clicked),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (Advanced), "clicked",
                      GTK_SIGNAL_FUNC (Advanced_clicked),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (Ok), "clicked",
                      GTK_SIGNAL_FUNC (C_Ok_clicked),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (Cancel), "clicked",
                      GTK_SIGNAL_FUNC (gtk_main_quit),
                      NULL);

  gtk_window_add_accel_group (GTK_WINDOW (Configuration), accel_group);

/* addon*/

	/* disable some buttons */
  gtk_widget_set_sensitive(Advanced,0);
  gtk_widget_set_sensitive(optionmenu1,0);
  gtk_widget_set_sensitive(optionmenu2,0);
  gtk_widget_set_sensitive(Default_key_color,0);
  gtk_widget_set_sensitive(redlabel,0);
  gtk_widget_set_sensitive(greenlabel,0);
  gtk_widget_set_sensitive(bleulabel,0);
  gtk_widget_set_sensitive(redpixmap,0);
  gtk_widget_set_sensitive(greenpixmap,0);
  gtk_widget_set_sensitive(bleupixmap,0);


  /* connect scales with her functions */
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(volume)->adjustment),    "value_changed", GTK_SIGNAL_FUNC(volume_changed),     GTK_OBJECT(GTK_RANGE(balance)->adjustment));
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(balance)->adjustment),   "value_changed", GTK_SIGNAL_FUNC(balance_changed),    GTK_OBJECT(GTK_RANGE(volume)->adjustment));
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(brightness)->adjustment),"value_changed", GTK_SIGNAL_FUNC(brightness_changed), NULL);
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(contrast)->adjustment),  "value_changed", GTK_SIGNAL_FUNC(contrast_changed),   NULL);
  gtk_signal_connect(GTK_OBJECT(GTK_RANGE(saturation)->adjustment),"value_changed", GTK_SIGNAL_FUNC(saturation_changed), NULL);

	/* set window icon*/
	set_window_icon(Configuration,REALmagic_xpm);
	
	loadconfig(Configuration);
/* end of addon*/


  return Configuration;
}

Display *dpy;
int scr;

int main( int   argc,
          char *argv[] )
{
  GtkWidget *Configuration;
  DWORD FMPreturn;
  int scrcount;


  dpy = XOpenDisplay (NULL);
  if (!dpy) exit(1);
  
  scrcount=ScreenCount(dpy);
  if (scrcount!=1)
	  fprintf(stderr,"Warning: screen count is %d. Continuing anyways.\n",scrcount);

  scr=DefaultScreen(dpy);

  {
	  DWORD x,y,depth,freq,rootx,rooty;
	  int xof,yof;

	  // don't mismatch Screen *Scr and int scr.
	  Screen *Scr=DefaultScreenOfDisplay(dpy);
	  
	  rootx=WidthOfScreen(Scr);
	  rooty=HeightOfScreen(Scr);
	  
	  if (!XF86VidModeGetViewPort(dpy,scr,&xof,&yof)) exit(1);
	  
	  getres(&x,&y,&depth,&freq);
	  
	  if ((x!=rootx)||(y!=rooty)) 
		  fprintf(stderr,"Warning: you are using a viewport.\n"
			  "         (root window is %ldx%ld on actual monitor %ldx%ld, offset is (%d,%d)).\n"
			  "         Let's try to keep the offset to (0,0).\n",
			  rootx,rooty,x,y,xof,yof);
  }
  
  /* Initialize the toolkit */
  
  gtk_init (&argc, &argv);

  // Connect to the server
	FMPConnectToMSGQUEUE();
	FMPOpen(FMPF_SYSTEM,32*1024,8,NULL,0);
	waitForAnalogOverlayAccess();

	// Test the VGA cable
	if (!FMPAnalogOverlay(FMP_ANALOG_OVERLAY_GET,FMP_ANALOG_OVERLAY_ATTRIBUTE_OVERLAY_CABLE_PRESENT,
			     UNUSED_ARG,UNUSED_ARG,UNUSED_ARG,UNUSED_ARG)) {
	
	G_MESSAGE("Please attach VGA cable.\n");
	exit(1);
	}

	// Set mode to none
	FMPreturn=FMPAnalogOverlay(FMP_ANALOG_OVERLAY_SET,FMP_ANALOG_OVERLAY_ATTRIBUTE_MODE,0,UNUSED_ARG,UNUSED_ARG,UNUSED_ARG);
	G_MESSAGE("set mode to none return: %ld",FMPreturn);	

  /* Create a new window */
  Configuration = create_Configuration();

  gtk_widget_show (Configuration);

  /* Rest in gtk_main and wait for the fun to begin! */
  gtk_main ();
  FMPClose();
  MPEGDriverUnload();
  return 0;
}

