Blame gtk/gtkinputdialog.c

Packit 98cdb6
/* GTK - The GIMP Toolkit
Packit 98cdb6
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Lesser General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Lesser General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Lesser General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * gtkinputdialog.c
Packit 98cdb6
 *
Packit 98cdb6
 * Copyright 1997 Owen Taylor <owt1@cornell.edu>
Packit 98cdb6
 *
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
Packit 98cdb6
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit 98cdb6
 * files for a list of changes.  These files are distributed with
Packit 98cdb6
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
Packit 98cdb6
#include <stdlib.h>
Packit 98cdb6
Packit 98cdb6
#include "gdk/gdkkeysyms.h"
Packit 98cdb6
Packit 98cdb6
#undef GTK_DISABLE_DEPRECATED /* GtkOptionMenu */
Packit 98cdb6
Packit 98cdb6
#include "gtkinputdialog.h"
Packit 98cdb6
#include "gtkbutton.h"
Packit 98cdb6
#include "gtkentry.h"
Packit 98cdb6
#include "gtkhbox.h"
Packit 98cdb6
#include "gtklabel.h"
Packit 98cdb6
#include "gtkmain.h"
Packit 98cdb6
#include "gtkmarshalers.h"
Packit 98cdb6
#include "gtkmenu.h"
Packit 98cdb6
#include "gtkmenuitem.h"
Packit 98cdb6
#include "gtknotebook.h"
Packit 98cdb6
#include "gtkoptionmenu.h"
Packit 98cdb6
#include "gtkscrolledwindow.h"
Packit 98cdb6
#include "gtkstock.h"
Packit 98cdb6
#include "gtktable.h"
Packit 98cdb6
#include "gtkvbox.h"
Packit 98cdb6
Packit 98cdb6
#include "gtkintl.h"
Packit 98cdb6
#include "gtkalias.h"
Packit 98cdb6
Packit 98cdb6
typedef struct _GtkInputDialogPrivate GtkInputDialogPrivate;
Packit 98cdb6
typedef struct _GtkInputKeyInfo       GtkInputKeyInfo;
Packit 98cdb6
Packit 98cdb6
struct _GtkInputDialogPrivate
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *device_menu;
Packit 98cdb6
  GtkWidget *device_optionmenu;
Packit 98cdb6
  GtkWidget *no_devices_label;
Packit 98cdb6
  GtkWidget *main_vbox;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
struct _GtkInputKeyInfo
Packit 98cdb6
{
Packit 98cdb6
  gint       index;
Packit 98cdb6
  GtkWidget *entry;
Packit 98cdb6
  GtkInputDialog *inputd;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
enum
Packit 98cdb6
{
Packit 98cdb6
  ENABLE_DEVICE,
Packit 98cdb6
  DISABLE_DEVICE,
Packit 98cdb6
  LAST_SIGNAL
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
#define AXIS_LIST_WIDTH 160
Packit 98cdb6
#define AXIS_LIST_HEIGHT 175
Packit 98cdb6
Packit 98cdb6
#define KEYS_LIST_WIDTH 200
Packit 98cdb6
#define KEYS_LIST_HEIGHT 175
Packit 98cdb6
Packit 98cdb6
/* Forward declarations */
Packit 98cdb6
Packit 98cdb6
static void gtk_input_dialog_screen_changed   (GtkWidget           *widget,
Packit 98cdb6
					       GdkScreen           *previous_screen);
Packit 98cdb6
static void gtk_input_dialog_set_device       (GtkWidget           *widget,
Packit 98cdb6
					       gpointer             data);
Packit 98cdb6
static void gtk_input_dialog_set_mapping_mode (GtkWidget           *w,
Packit 98cdb6
					       gpointer             data);
Packit 98cdb6
static void gtk_input_dialog_set_axis         (GtkWidget           *widget,
Packit 98cdb6
					       gpointer             data);
Packit 98cdb6
static void gtk_input_dialog_fill_axes        (GtkInputDialog      *inputd,
Packit 98cdb6
					       GdkDevice           *info);
Packit 98cdb6
static void gtk_input_dialog_set_key          (GtkInputKeyInfo     *key,
Packit 98cdb6
					       guint                keyval,
Packit 98cdb6
					       GdkModifierType      modifiers);
Packit 98cdb6
static gboolean gtk_input_dialog_key_press    (GtkWidget           *widget,
Packit 98cdb6
					       GdkEventKey         *event,
Packit 98cdb6
					       GtkInputKeyInfo     *key);
Packit 98cdb6
static void gtk_input_dialog_clear_key        (GtkWidget           *widget,
Packit 98cdb6
					       GtkInputKeyInfo     *key);
Packit 98cdb6
static void gtk_input_dialog_destroy_key      (GtkWidget           *widget,
Packit 98cdb6
					       GtkInputKeyInfo     *key);
Packit 98cdb6
static void gtk_input_dialog_fill_keys        (GtkInputDialog      *inputd,
Packit 98cdb6
					       GdkDevice           *info);
Packit 98cdb6
Packit 98cdb6
static guint input_dialog_signals[LAST_SIGNAL] = { 0 };
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE (GtkInputDialog, gtk_input_dialog, GTK_TYPE_DIALOG)
Packit 98cdb6
Packit 98cdb6
static GtkInputDialogPrivate *
Packit 98cdb6
gtk_input_dialog_get_private (GtkInputDialog *input_dialog)
Packit 98cdb6
{
Packit 98cdb6
  return G_TYPE_INSTANCE_GET_PRIVATE (input_dialog, 
Packit 98cdb6
				      GTK_TYPE_INPUT_DIALOG, 
Packit 98cdb6
				      GtkInputDialogPrivate);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static GtkInputDialog *
Packit 98cdb6
input_dialog_from_widget (GtkWidget *widget)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *toplevel;
Packit 98cdb6
  
Packit 98cdb6
  if (GTK_IS_MENU_ITEM (widget))
Packit 98cdb6
    {
Packit 98cdb6
      GtkMenu *menu = GTK_MENU (widget->parent);
Packit 98cdb6
      widget = gtk_menu_get_attach_widget (menu);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  toplevel = gtk_widget_get_toplevel (widget);
Packit 98cdb6
  return GTK_INPUT_DIALOG (toplevel);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_input_dialog_class_init (GtkInputDialogClass *klass)
Packit 98cdb6
{
Packit 98cdb6
  GObjectClass *object_class = (GObjectClass *) klass;
Packit 98cdb6
  GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
Packit 98cdb6
  
Packit 98cdb6
  widget_class->screen_changed = gtk_input_dialog_screen_changed;
Packit 98cdb6
  
Packit 98cdb6
  klass->enable_device = NULL;
Packit 98cdb6
  klass->disable_device = NULL;
Packit 98cdb6
Packit 98cdb6
  input_dialog_signals[ENABLE_DEVICE] =
Packit 98cdb6
    g_signal_new (I_("enable-device"),
Packit 98cdb6
		  G_OBJECT_CLASS_TYPE (klass),
Packit 98cdb6
		  G_SIGNAL_RUN_LAST,
Packit 98cdb6
		  G_STRUCT_OFFSET (GtkInputDialogClass, enable_device),
Packit 98cdb6
		  NULL, NULL,
Packit 98cdb6
		  _gtk_marshal_VOID__OBJECT,
Packit 98cdb6
		  G_TYPE_NONE, 1,
Packit 98cdb6
		  GDK_TYPE_DEVICE);
Packit 98cdb6
Packit 98cdb6
  input_dialog_signals[DISABLE_DEVICE] =
Packit 98cdb6
    g_signal_new (I_("disable-device"),
Packit 98cdb6
		  G_OBJECT_CLASS_TYPE (klass),
Packit 98cdb6
		  G_SIGNAL_RUN_LAST,
Packit 98cdb6
		  G_STRUCT_OFFSET (GtkInputDialogClass, disable_device),
Packit 98cdb6
		  NULL, NULL,
Packit 98cdb6
		  _gtk_marshal_VOID__OBJECT,
Packit 98cdb6
		  G_TYPE_NONE, 1,
Packit 98cdb6
		  GDK_TYPE_DEVICE);
Packit 98cdb6
Packit 98cdb6
  g_type_class_add_private (object_class, sizeof (GtkInputDialogPrivate));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_input_dialog_init (GtkInputDialog *inputd)
Packit 98cdb6
{
Packit 98cdb6
  GtkInputDialogPrivate *private = gtk_input_dialog_get_private (inputd);
Packit 98cdb6
  GtkDialog *dialog = GTK_DIALOG (inputd);
Packit 98cdb6
  GtkWidget *util_box;
Packit 98cdb6
  GtkWidget *label;
Packit 98cdb6
  GtkWidget *mapping_menu;
Packit 98cdb6
  GtkWidget *menuitem;
Packit 98cdb6
  GtkWidget *notebook;
Packit 98cdb6
Packit 98cdb6
  gtk_widget_push_composite_child ();
Packit 98cdb6
Packit 98cdb6
  gtk_window_set_title (GTK_WINDOW (inputd), _("Input"));
Packit 98cdb6
Packit 98cdb6
  gtk_dialog_set_has_separator (dialog, FALSE);
Packit 98cdb6
  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
Packit 98cdb6
  gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
Packit 98cdb6
  gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
Packit 98cdb6
  gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
Packit 98cdb6
Packit 98cdb6
  /* main vbox */
Packit 98cdb6
Packit 98cdb6
  private->main_vbox = gtk_vbox_new (FALSE, 12);
Packit 98cdb6
  gtk_container_set_border_width (GTK_CONTAINER (private->main_vbox), 5);
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (inputd)->vbox), private->main_vbox,
Packit 98cdb6
		      TRUE, TRUE, 0);
Packit 98cdb6
Packit 98cdb6
  private->no_devices_label = gtk_label_new (_("No extended input devices"));
Packit 98cdb6
  gtk_container_set_border_width (GTK_CONTAINER (private->main_vbox), 5);
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (inputd)->vbox),
Packit 98cdb6
		      private->no_devices_label,
Packit 98cdb6
		      TRUE, TRUE, 0);
Packit 98cdb6
Packit 98cdb6
  /* menu for selecting device */
Packit 98cdb6
Packit 98cdb6
  private->device_menu = gtk_menu_new ();
Packit 98cdb6
Packit 98cdb6
  util_box = gtk_hbox_new (FALSE, 12);
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (private->main_vbox), util_box, FALSE, FALSE, 0);
Packit 98cdb6
Packit 98cdb6
  label = gtk_label_new_with_mnemonic (_("_Device:"));
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 0);
Packit 98cdb6
Packit 98cdb6
  private->device_optionmenu = gtk_option_menu_new ();
Packit 98cdb6
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), private->device_optionmenu);
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (util_box), private->device_optionmenu, TRUE, TRUE, 0);
Packit 98cdb6
  gtk_widget_show (private->device_optionmenu);
Packit 98cdb6
  gtk_option_menu_set_menu (GTK_OPTION_MENU (private->device_optionmenu), private->device_menu);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_show (label);
Packit 98cdb6
Packit 98cdb6
  /* Device options */
Packit 98cdb6
Packit 98cdb6
  /* mapping mode option menu */
Packit 98cdb6
Packit 98cdb6
  mapping_menu = gtk_menu_new ();
Packit 98cdb6
Packit 98cdb6
  menuitem = gtk_menu_item_new_with_label(_("Disabled"));
Packit 98cdb6
  gtk_menu_shell_append (GTK_MENU_SHELL (mapping_menu), menuitem);
Packit 98cdb6
  gtk_widget_show (menuitem);
Packit 98cdb6
  g_signal_connect (menuitem, "activate",
Packit 98cdb6
		    G_CALLBACK (gtk_input_dialog_set_mapping_mode),
Packit 98cdb6
		    GINT_TO_POINTER (GDK_MODE_DISABLED));
Packit 98cdb6
Packit 98cdb6
  menuitem = gtk_menu_item_new_with_label(_("Screen"));
Packit 98cdb6
  gtk_menu_shell_append (GTK_MENU_SHELL (mapping_menu), menuitem);
Packit 98cdb6
  gtk_widget_show (menuitem);
Packit 98cdb6
  g_signal_connect (menuitem, "activate",
Packit 98cdb6
		    G_CALLBACK (gtk_input_dialog_set_mapping_mode),
Packit 98cdb6
		    GINT_TO_POINTER (GDK_MODE_SCREEN));
Packit 98cdb6
Packit 98cdb6
  menuitem = gtk_menu_item_new_with_label(_("Window"));
Packit 98cdb6
  gtk_menu_shell_append (GTK_MENU_SHELL (mapping_menu), menuitem);
Packit 98cdb6
  gtk_widget_show (menuitem);
Packit 98cdb6
  g_signal_connect (menuitem, "activate",
Packit 98cdb6
		    G_CALLBACK (gtk_input_dialog_set_mapping_mode),
Packit 98cdb6
		    GINT_TO_POINTER (GDK_MODE_WINDOW));
Packit 98cdb6
Packit 98cdb6
  label = gtk_label_new_with_mnemonic (_("_Mode:"));
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 0);
Packit 98cdb6
  
Packit 98cdb6
  inputd->mode_optionmenu = gtk_option_menu_new ();
Packit 98cdb6
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), inputd->mode_optionmenu);
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (util_box), inputd->mode_optionmenu, FALSE, FALSE, 0);
Packit 98cdb6
  gtk_widget_show (inputd->mode_optionmenu);
Packit 98cdb6
  gtk_option_menu_set_menu (GTK_OPTION_MENU (inputd->mode_optionmenu), mapping_menu);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_show(label);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_show (util_box);
Packit 98cdb6
Packit 98cdb6
  /* Notebook */
Packit 98cdb6
Packit 98cdb6
  notebook = gtk_notebook_new ();
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (private->main_vbox), notebook, TRUE, TRUE, 0);
Packit 98cdb6
  gtk_widget_show (notebook);
Packit 98cdb6
      
Packit 98cdb6
  /*  The axis listbox  */
Packit 98cdb6
Packit 98cdb6
  label = gtk_label_new (_("Axes"));
Packit 98cdb6
Packit 98cdb6
  inputd->axis_listbox = gtk_scrolled_window_new (NULL, NULL);
Packit 98cdb6
  gtk_container_set_border_width (GTK_CONTAINER (inputd->axis_listbox), 12);
Packit 98cdb6
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(inputd->axis_listbox),
Packit 98cdb6
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
Packit 98cdb6
      
Packit 98cdb6
  gtk_widget_set_size_request (inputd->axis_listbox,
Packit 98cdb6
			       AXIS_LIST_WIDTH, AXIS_LIST_HEIGHT);
Packit 98cdb6
  gtk_notebook_append_page (GTK_NOTEBOOK(notebook), 
Packit 98cdb6
			    inputd->axis_listbox, label);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_show (inputd->axis_listbox);
Packit 98cdb6
Packit 98cdb6
  inputd->axis_list = NULL;
Packit 98cdb6
Packit 98cdb6
  /* Keys listbox */
Packit 98cdb6
Packit 98cdb6
  label = gtk_label_new (_("Keys"));
Packit 98cdb6
Packit 98cdb6
  inputd->keys_listbox = gtk_scrolled_window_new (NULL, NULL);
Packit 98cdb6
  gtk_container_set_border_width (GTK_CONTAINER (inputd->keys_listbox), 12);
Packit 98cdb6
  gtk_widget_set_size_request (inputd->keys_listbox,
Packit 98cdb6
			       KEYS_LIST_WIDTH, KEYS_LIST_HEIGHT);
Packit 98cdb6
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (inputd->keys_listbox),
Packit 98cdb6
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
Packit 98cdb6
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), 
Packit 98cdb6
			    inputd->keys_listbox, label);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_show (inputd->keys_listbox);
Packit 98cdb6
Packit 98cdb6
  inputd->keys_list = NULL;
Packit 98cdb6
Packit 98cdb6
  inputd->save_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
Packit 98cdb6
  gtk_widget_set_can_default (inputd->save_button, TRUE);
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG(inputd)->action_area),
Packit 98cdb6
		      inputd->save_button, TRUE, TRUE, 0);
Packit 98cdb6
  gtk_widget_show (inputd->save_button);
Packit 98cdb6
Packit 98cdb6
  inputd->close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
Packit 98cdb6
  gtk_widget_set_can_default (inputd->close_button, TRUE);
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG(inputd)->action_area),
Packit 98cdb6
		      inputd->close_button, TRUE, TRUE, 0);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_show (inputd->close_button);
Packit 98cdb6
  gtk_widget_grab_default (inputd->close_button);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_pop_composite_child ();
Packit 98cdb6
Packit 98cdb6
  gtk_input_dialog_screen_changed (GTK_WIDGET (inputd), NULL);
Packit 98cdb6
Packit 98cdb6
  _gtk_dialog_set_ignore_separator (dialog, TRUE);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_input_dialog_screen_changed (GtkWidget *widget,
Packit 98cdb6
				 GdkScreen *previous_screen)
Packit 98cdb6
{
Packit 98cdb6
  GtkInputDialog *inputd = GTK_INPUT_DIALOG (widget);
Packit 98cdb6
  GtkInputDialogPrivate *private = gtk_input_dialog_get_private (inputd);
Packit 98cdb6
  
Packit 98cdb6
  GList *device_info = NULL;
Packit 98cdb6
  GdkDevice *core_pointer = NULL;
Packit 98cdb6
  GList *tmp_list;
Packit 98cdb6
Packit 98cdb6
  if (gtk_widget_has_screen (widget))
Packit 98cdb6
    {
Packit 98cdb6
      GdkDisplay *display;
Packit 98cdb6
      
Packit 98cdb6
      display = gtk_widget_get_display (widget);
Packit 98cdb6
      device_info = gdk_display_list_devices (display);
Packit 98cdb6
      core_pointer = gdk_display_get_core_pointer (display);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  inputd->current_device = NULL;
Packit 98cdb6
  gtk_container_foreach (GTK_CONTAINER (private->device_menu),
Packit 98cdb6
			 (GtkCallback)gtk_widget_destroy, NULL);
Packit 98cdb6
  
Packit 98cdb6
  if (g_list_length(device_info) <= 1) /* only core device */
Packit 98cdb6
    {
Packit 98cdb6
      gtk_widget_hide (private->main_vbox);
Packit 98cdb6
      gtk_widget_show (private->no_devices_label);
Packit 98cdb6
      gtk_widget_set_sensitive(inputd->save_button, FALSE);
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      gtk_widget_show (private->main_vbox);
Packit 98cdb6
      gtk_widget_hide (private->no_devices_label);
Packit 98cdb6
      gtk_widget_set_sensitive(inputd->save_button, TRUE);
Packit 98cdb6
Packit 98cdb6
      for (tmp_list = device_info; tmp_list; tmp_list = tmp_list->next)
Packit 98cdb6
	{
Packit 98cdb6
	  GdkDevice *info = tmp_list->data;
Packit 98cdb6
	  if (info != core_pointer)
Packit 98cdb6
	    {
Packit 98cdb6
	      GtkWidget *menuitem;
Packit 98cdb6
	      
Packit 98cdb6
	      menuitem = gtk_menu_item_new_with_label (info->name);
Packit 98cdb6
	      
Packit 98cdb6
	      gtk_menu_shell_append (GTK_MENU_SHELL (private->device_menu),
Packit 98cdb6
				     menuitem);
Packit 98cdb6
	      gtk_widget_show (menuitem);
Packit 98cdb6
	      g_signal_connect (menuitem, "activate",
Packit 98cdb6
				G_CALLBACK (gtk_input_dialog_set_device),
Packit 98cdb6
				info);
Packit 98cdb6
	    }
Packit 98cdb6
	}
Packit 98cdb6
      
Packit 98cdb6
      gtk_input_dialog_set_device (widget, device_info->data);
Packit 98cdb6
      gtk_option_menu_set_history (GTK_OPTION_MENU (private->device_optionmenu), 0);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
     
Packit 98cdb6
GtkWidget*
Packit 98cdb6
gtk_input_dialog_new (void)
Packit 98cdb6
{
Packit 98cdb6
  GtkInputDialog *inputd;
Packit 98cdb6
Packit 98cdb6
  inputd = g_object_new (GTK_TYPE_INPUT_DIALOG, NULL);
Packit 98cdb6
Packit 98cdb6
  return GTK_WIDGET (inputd);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_input_dialog_set_device (GtkWidget *w,
Packit 98cdb6
			     gpointer   data)
Packit 98cdb6
{
Packit 98cdb6
  GdkDevice *device = data;
Packit 98cdb6
  GtkInputDialog *inputd = input_dialog_from_widget (w);
Packit 98cdb6
Packit 98cdb6
  inputd->current_device = device;
Packit 98cdb6
Packit 98cdb6
  gtk_input_dialog_fill_axes (inputd, device);
Packit 98cdb6
  gtk_input_dialog_fill_keys (inputd, device);
Packit 98cdb6
Packit 98cdb6
  gtk_option_menu_set_history (GTK_OPTION_MENU (inputd->mode_optionmenu),
Packit 98cdb6
			       device->mode);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_input_dialog_set_mapping_mode (GtkWidget *w,
Packit 98cdb6
				   gpointer   data)
Packit 98cdb6
{
Packit 98cdb6
  GtkInputDialog *inputd = input_dialog_from_widget (w);
Packit 98cdb6
  GdkDevice *info = inputd->current_device;
Packit 98cdb6
  GdkInputMode old_mode;
Packit 98cdb6
  GdkInputMode mode = GPOINTER_TO_INT (data);
Packit 98cdb6
Packit 98cdb6
  if (!info)
Packit 98cdb6
    return;
Packit 98cdb6
  
Packit 98cdb6
  old_mode = info->mode;
Packit 98cdb6
Packit 98cdb6
  if (mode != old_mode)
Packit 98cdb6
    {
Packit 98cdb6
      if (gdk_device_set_mode (info, mode))
Packit 98cdb6
	{
Packit 98cdb6
	  if (mode == GDK_MODE_DISABLED)
Packit 98cdb6
	    g_signal_emit (inputd,
Packit 98cdb6
			   input_dialog_signals[DISABLE_DEVICE],
Packit 98cdb6
			   0,
Packit 98cdb6
			   info);
Packit 98cdb6
	  else
Packit 98cdb6
	    g_signal_emit (inputd,
Packit 98cdb6
			   input_dialog_signals[ENABLE_DEVICE],
Packit 98cdb6
			   0,
Packit 98cdb6
			   info);
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	gtk_option_menu_set_history (GTK_OPTION_MENU (inputd->mode_optionmenu),
Packit 98cdb6
				     old_mode);
Packit 98cdb6
Packit 98cdb6
      /* FIXME: error dialog ? */
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_input_dialog_set_axis (GtkWidget *w,
Packit 98cdb6
			   gpointer   data)
Packit 98cdb6
{
Packit 98cdb6
  GdkAxisUse use = GPOINTER_TO_INT(data) & 0xFFFF;
Packit 98cdb6
  GdkAxisUse old_use;
Packit 98cdb6
  GdkAxisUse *new_axes;
Packit 98cdb6
  GtkInputDialog *inputd = input_dialog_from_widget (w);
Packit 98cdb6
  GdkDevice *info = inputd->current_device;
Packit 98cdb6
Packit 98cdb6
  gint axis = (GPOINTER_TO_INT(data) >> 16) - 1;
Packit 98cdb6
  gint old_axis;
Packit 98cdb6
  int i;
Packit 98cdb6
Packit 98cdb6
  if (!info)
Packit 98cdb6
    return;
Packit 98cdb6
Packit 98cdb6
  new_axes = g_new (GdkAxisUse, info->num_axes);
Packit 98cdb6
  old_axis = -1;
Packit 98cdb6
  for (i=0;i<info->num_axes;i++)
Packit 98cdb6
    {
Packit 98cdb6
      new_axes[i] = info->axes[i].use;
Packit 98cdb6
      if (info->axes[i].use == use)
Packit 98cdb6
	old_axis = i;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (axis != -1)
Packit 98cdb6
    old_use = info->axes[axis].use;
Packit 98cdb6
  else
Packit 98cdb6
    old_use = GDK_AXIS_IGNORE;
Packit 98cdb6
Packit 98cdb6
  if (axis == old_axis) {
Packit 98cdb6
    g_free (new_axes);
Packit 98cdb6
    return;
Packit 98cdb6
  }
Packit 98cdb6
Packit 98cdb6
  /* we must always have an x and a y axis */
Packit 98cdb6
  if ((axis == -1 && (use == GDK_AXIS_X || use == GDK_AXIS_Y)) ||
Packit 98cdb6
      (old_axis == -1 && (old_use == GDK_AXIS_X || old_use == GDK_AXIS_Y)))
Packit 98cdb6
    {
Packit 98cdb6
      gtk_option_menu_set_history (
Packit 98cdb6
	        GTK_OPTION_MENU (inputd->axis_items[use]),
Packit 98cdb6
		old_axis + 1);
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      if (axis != -1)
Packit 98cdb6
	gdk_device_set_axis_use (info, axis, use);
Packit 98cdb6
Packit 98cdb6
      if (old_axis != -1)
Packit 98cdb6
	gdk_device_set_axis_use (info, old_axis, old_use);
Packit 98cdb6
Packit 98cdb6
      if (old_use != GDK_AXIS_IGNORE)
Packit 98cdb6
	{
Packit 98cdb6
	  gtk_option_menu_set_history (
Packit 98cdb6
		GTK_OPTION_MENU (inputd->axis_items[old_use]),
Packit 98cdb6
		old_axis + 1);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  g_free (new_axes);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_input_dialog_fill_axes(GtkInputDialog *inputd, GdkDevice *info)
Packit 98cdb6
{
Packit 98cdb6
  static const char *const axis_use_strings[GDK_AXIS_LAST] =
Packit 98cdb6
  {
Packit 98cdb6
    "",
Packit 98cdb6
    N_("_X:"),
Packit 98cdb6
    N_("_Y:"),
Packit 98cdb6
    N_("_Pressure:"),
Packit 98cdb6
    N_("X _tilt:"),
Packit 98cdb6
    N_("Y t_ilt:"),
Packit 98cdb6
    N_("_Wheel:")
Packit 98cdb6
  };
Packit 98cdb6
Packit 98cdb6
  int i,j;
Packit 98cdb6
  GtkWidget *menu;
Packit 98cdb6
  GtkWidget *option_menu;
Packit 98cdb6
  GtkWidget *label;
Packit 98cdb6
  GtkWidget *viewport;
Packit 98cdb6
  GtkWidget *old_child;
Packit 98cdb6
Packit 98cdb6
  /* remove all the old items */
Packit 98cdb6
  if (inputd->axis_list)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_widget_hide (inputd->axis_list);	/* suppress resizes (or get warnings) */
Packit 98cdb6
      gtk_widget_destroy (inputd->axis_list);
Packit 98cdb6
    }
Packit 98cdb6
  inputd->axis_list = gtk_table_new (GDK_AXIS_LAST, 2, 0);
Packit 98cdb6
  gtk_table_set_row_spacings (GTK_TABLE (inputd->axis_list), 6);
Packit 98cdb6
  gtk_table_set_col_spacings (GTK_TABLE (inputd->axis_list), 12);
Packit 98cdb6
  
Packit 98cdb6
  viewport = gtk_viewport_new (NULL, NULL);
Packit 98cdb6
  old_child = gtk_bin_get_child (GTK_BIN (inputd->axis_listbox));
Packit 98cdb6
  if (old_child != NULL)
Packit 98cdb6
    gtk_widget_destroy (old_child);
Packit 98cdb6
  gtk_container_add (GTK_CONTAINER (inputd->axis_listbox), viewport);
Packit 98cdb6
  gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
Packit 98cdb6
  gtk_widget_show (viewport);
Packit 98cdb6
  gtk_container_add (GTK_CONTAINER (viewport), inputd->axis_list);
Packit 98cdb6
  gtk_widget_show (inputd->axis_list);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_realize (inputd->axis_list);
Packit 98cdb6
  gdk_window_set_background (inputd->axis_list->window,
Packit 98cdb6
			     &inputd->axis_list->style->base[GTK_STATE_NORMAL]);
Packit 98cdb6
Packit 98cdb6
  for (i=GDK_AXIS_X;i
Packit 98cdb6
    {
Packit 98cdb6
      /* create the label */
Packit 98cdb6
Packit 98cdb6
      label = gtk_label_new_with_mnemonic (_(axis_use_strings[i]));
Packit 98cdb6
      gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
Packit 98cdb6
      gtk_table_attach (GTK_TABLE (inputd->axis_list), label, 0, 1, i, i+1, 
Packit 98cdb6
                        GTK_FILL, 0, 2, 2);
Packit 98cdb6
Packit 98cdb6
      /* and the use option menu */
Packit 98cdb6
      menu = gtk_menu_new();
Packit 98cdb6
Packit 98cdb6
      for (j = -1; j < info->num_axes; j++)
Packit 98cdb6
	{
Packit 98cdb6
	  char buffer[16];
Packit 98cdb6
	  GtkWidget *menu_item;
Packit 98cdb6
Packit 98cdb6
	  if (j == -1)
Packit 98cdb6
	    menu_item = gtk_menu_item_new_with_label (_("none"));
Packit 98cdb6
	  else
Packit 98cdb6
	    {
Packit 98cdb6
	      g_snprintf (buffer, sizeof (buffer), "%d", j+1);
Packit 98cdb6
	      menu_item = gtk_menu_item_new_with_label (buffer);
Packit 98cdb6
	    }
Packit 98cdb6
	  g_signal_connect (menu_item, "activate",
Packit 98cdb6
			    G_CALLBACK (gtk_input_dialog_set_axis),
Packit 98cdb6
			    GINT_TO_POINTER (0x10000 * (j + 1) + i));
Packit 98cdb6
	  gtk_widget_show (menu_item);
Packit 98cdb6
	  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      inputd->axis_items[i] = option_menu = gtk_option_menu_new ();
Packit 98cdb6
      gtk_label_set_mnemonic_widget (GTK_LABEL (label), option_menu);
Packit 98cdb6
      gtk_table_attach (GTK_TABLE (inputd->axis_list), option_menu, 
Packit 98cdb6
			1, 2, i, i+1, GTK_EXPAND | GTK_FILL, 0, 2, 2);
Packit 98cdb6
Packit 98cdb6
      gtk_widget_show (option_menu);
Packit 98cdb6
      gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
Packit 98cdb6
      for (j = 0; j < info->num_axes; j++)
Packit 98cdb6
	if (info->axes[j].use == (GdkAxisUse) i)
Packit 98cdb6
	  {
Packit 98cdb6
	    gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), j+1);
Packit 98cdb6
	    break;
Packit 98cdb6
	  }
Packit 98cdb6
Packit 98cdb6
      gtk_widget_show (label);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void 
Packit 98cdb6
gtk_input_dialog_clear_key (GtkWidget *widget, GtkInputKeyInfo *key)
Packit 98cdb6
{
Packit 98cdb6
  if (!key->inputd->current_device)
Packit 98cdb6
    return;
Packit 98cdb6
  
Packit 98cdb6
  gtk_entry_set_text (GTK_ENTRY(key->entry), _("(disabled)"));
Packit 98cdb6
  gdk_device_set_key (key->inputd->current_device, key->index, 0, 0);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void 
Packit 98cdb6
gtk_input_dialog_set_key (GtkInputKeyInfo *key,
Packit 98cdb6
			  guint keyval, GdkModifierType modifiers)
Packit 98cdb6
{
Packit 98cdb6
  GString *str;
Packit 98cdb6
  gchar chars[2];
Packit 98cdb6
Packit 98cdb6
  if (keyval)
Packit 98cdb6
    {
Packit 98cdb6
      str = g_string_new (NULL);
Packit 98cdb6
      
Packit 98cdb6
      if (modifiers & GDK_SHIFT_MASK)
Packit 98cdb6
	g_string_append (str, "Shift+");
Packit 98cdb6
      if (modifiers & GDK_CONTROL_MASK)
Packit 98cdb6
	g_string_append (str, "Ctrl+");
Packit 98cdb6
      if (modifiers & GDK_MOD1_MASK)
Packit 98cdb6
	g_string_append (str, "Alt+");
Packit 98cdb6
      
Packit 98cdb6
      if ((keyval >= 0x20) && (keyval <= 0xFF))
Packit 98cdb6
	{
Packit 98cdb6
	  chars[0] = keyval;
Packit 98cdb6
	  chars[1] = 0;
Packit 98cdb6
	  g_string_append (str, chars);
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	g_string_append (str, _("(unknown)"));
Packit 98cdb6
      gtk_entry_set_text (GTK_ENTRY(key->entry), str->str);
Packit 98cdb6
Packit 98cdb6
      g_string_free (str, TRUE);
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      gtk_entry_set_text (GTK_ENTRY(key->entry), _("(disabled)"));
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_input_dialog_key_press (GtkWidget *widget, 
Packit 98cdb6
			    GdkEventKey *event,
Packit 98cdb6
			    GtkInputKeyInfo *key)
Packit 98cdb6
{
Packit 98cdb6
  if (!key->inputd->current_device)
Packit 98cdb6
    return FALSE;
Packit 98cdb6
  
Packit 98cdb6
  gtk_input_dialog_set_key (key, event->keyval, event->state & 0xFF);
Packit 98cdb6
  gdk_device_set_key (key->inputd->current_device, key->index, 
Packit 98cdb6
		      event->keyval, event->state & 0xFF);
Packit 98cdb6
Packit 98cdb6
  g_signal_stop_emission_by_name (widget, "key-press-event");
Packit 98cdb6
  
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void 
Packit 98cdb6
gtk_input_dialog_destroy_key (GtkWidget *widget, GtkInputKeyInfo *key)
Packit 98cdb6
{
Packit 98cdb6
  g_free (key);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_input_dialog_fill_keys(GtkInputDialog *inputd, GdkDevice *info)
Packit 98cdb6
{
Packit 98cdb6
  int i;
Packit 98cdb6
  GtkWidget *label;
Packit 98cdb6
  GtkWidget *button;
Packit 98cdb6
  GtkWidget *hbox;
Packit 98cdb6
  GtkWidget *viewport;
Packit 98cdb6
  GtkWidget *old_child;
Packit 98cdb6
Packit 98cdb6
  char buffer[32];
Packit 98cdb6
  
Packit 98cdb6
  /* remove all the old items */
Packit 98cdb6
  if (inputd->keys_list)
Packit 98cdb6
    {
Packit 98cdb6
      gtk_widget_hide (inputd->keys_list);	/* suppress resizes (or get warnings) */
Packit 98cdb6
      gtk_widget_destroy (inputd->keys_list);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  inputd->keys_list = gtk_table_new (info->num_keys, 2, FALSE);
Packit 98cdb6
  gtk_table_set_row_spacings (GTK_TABLE (inputd->keys_list), 6);
Packit 98cdb6
  gtk_table_set_col_spacings (GTK_TABLE (inputd->keys_list), 12);
Packit 98cdb6
  
Packit 98cdb6
  viewport = gtk_viewport_new (NULL, NULL);
Packit 98cdb6
  old_child = gtk_bin_get_child (GTK_BIN (inputd->keys_listbox));
Packit 98cdb6
  if (old_child != NULL)
Packit 98cdb6
    gtk_widget_destroy (old_child);
Packit 98cdb6
  gtk_container_add (GTK_CONTAINER (inputd->keys_listbox), viewport);
Packit 98cdb6
  gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
Packit 98cdb6
  gtk_widget_show (viewport);
Packit 98cdb6
  gtk_container_add (GTK_CONTAINER (viewport), inputd->keys_list);
Packit 98cdb6
  gtk_widget_show (inputd->keys_list);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_realize (inputd->keys_list);
Packit 98cdb6
  gdk_window_set_background (inputd->keys_list->window,
Packit 98cdb6
			     &inputd->keys_list->style->base[GTK_STATE_NORMAL]);
Packit 98cdb6
Packit 98cdb6
  for (i=0;i<info->num_keys;i++)
Packit 98cdb6
    {
Packit 98cdb6
      GtkInputKeyInfo *key = g_new (GtkInputKeyInfo, 1);
Packit 98cdb6
      key->index = i;
Packit 98cdb6
      key->inputd = inputd;
Packit 98cdb6
Packit 98cdb6
      /* create the label */
Packit 98cdb6
Packit 98cdb6
      g_snprintf (buffer, sizeof (buffer), "_%d:", i+1);
Packit 98cdb6
      label = gtk_label_new_with_mnemonic (buffer);
Packit 98cdb6
      gtk_table_attach (GTK_TABLE (inputd->keys_list), label, 0, 1, i, i+1, 
Packit 98cdb6
			GTK_FILL, 0, 2, 2);
Packit 98cdb6
      gtk_widget_show (label);
Packit 98cdb6
Packit 98cdb6
      /* the entry */
Packit 98cdb6
Packit 98cdb6
      hbox = gtk_hbox_new (FALSE, 6);
Packit 98cdb6
      gtk_table_attach (GTK_TABLE (inputd->keys_list), hbox, 1, 2, i, i+1, 
Packit 98cdb6
                        GTK_EXPAND | GTK_FILL, 0, 2, 2);
Packit 98cdb6
      gtk_widget_show (hbox);
Packit 98cdb6
Packit 98cdb6
      key->entry = gtk_entry_new ();
Packit 98cdb6
      gtk_label_set_mnemonic_widget (GTK_LABEL (label), key->entry);
Packit 98cdb6
      gtk_box_pack_start (GTK_BOX (hbox), key->entry, TRUE, TRUE, 0);
Packit 98cdb6
      gtk_widget_show (key->entry);
Packit 98cdb6
Packit 98cdb6
      g_signal_connect (key->entry, "key-press-event",
Packit 98cdb6
			G_CALLBACK (gtk_input_dialog_key_press), key);
Packit 98cdb6
      g_signal_connect (key->entry, "destroy",
Packit 98cdb6
			G_CALLBACK (gtk_input_dialog_destroy_key), key);
Packit 98cdb6
      
Packit 98cdb6
      /* and clear button */
Packit 98cdb6
Packit 98cdb6
      button = gtk_button_new_with_mnemonic (_("Cl_ear"));
Packit 98cdb6
      gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
Packit 98cdb6
      gtk_widget_show (button);
Packit 98cdb6
Packit 98cdb6
      g_signal_connect (button, "clicked",
Packit 98cdb6
			G_CALLBACK (gtk_input_dialog_clear_key), key);
Packit 98cdb6
Packit 98cdb6
      gtk_input_dialog_set_key (key, info->keys[i].keyval,
Packit 98cdb6
				info->keys[i].modifiers);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GTK_INPUTDIALOG_C__
Packit 98cdb6
#include "gtkaliasdef.c"