remove unneeded files

This commit is contained in:
Jonathan Blandford 2002-01-08 21:47:16 +00:00
parent 98e37477fa
commit f4c5ec56d0
16 changed files with 0 additions and 3910 deletions

View file

@ -1,297 +0,0 @@
/* -*- mode: c; style: linux -*- */
/* main.c
* Copyright (C) 2000 Helix Code, Inc.
*
* Written by Bradford Hovinen (hovinen@helixcode.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, 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., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtk.h>
#include <gnome.h>
#include <libgnomeui/gnome-window-icon.h>
#include <tree.h>
#include <parser.h>
#include <fcntl.h>
#include <glade/glade.h>
#include <capplet-widget.h>
#ifdef HAVE_XIMIAN_ARCHIVER
# include <ximian-archiver/archive.h>
# include <ximian-archiver/location.h>
#endif /* HAVE_XIMIAN_ARCHIVER */
#include "preferences.h"
#include "prefs-widget.h"
static Preferences *prefs;
static Preferences *old_prefs;
static PrefsWidget *prefs_widget;
#ifdef HAVE_XIMIAN_ARCHIVER
static Archive *archive;
static gboolean outside_location;
static void
store_archive_data (void)
{
Location *location;
xmlDocPtr xml_doc;
if (capplet_get_location () == NULL)
location = archive_get_current_location (archive);
else
location = archive_get_location (archive,
capplet_get_location ());
xml_doc = preferences_write_xml (prefs);
location_store_xml (location, "mouse-properties-capplet",
xml_doc, STORE_MASK_PREVIOUS);
xmlFreeDoc (xml_doc);
archive_close (archive);
}
#endif /* HAVE_XIMIAN_ARCHIVER */
static void
ok_cb (GtkWidget *widget)
{
#ifdef HAVE_XIMIAN_ARCHIVER
if (!outside_location) {
preferences_save (prefs);
preferences_apply_now (prefs);
}
#else /* !HAVE_XIMIAN_ARCHIVER */
preferences_save (prefs);
preferences_apply_now (prefs);
#endif /* HAVE_XIMIAN_ARCHIVER */
#ifdef HAVE_XIMIAN_ARCHIVER
store_archive_data ();
#endif /* HAVE_XIMIAN_ARCHIVER */
}
static void
cancel_cb (GtkWidget *widget)
{
#ifdef HAVE_XIMIAN_ARCHIVER
if (!outside_location) {
preferences_save (old_prefs);
preferences_apply_now (old_prefs);
}
#else /* !HAVE_XIMIAN_ARCHIVER */
preferences_save (old_prefs);
preferences_apply_now (old_prefs);
#endif /* HAVE_XIMIAN_ARCHIVER */
}
static void
setup_capplet_widget (void)
{
preferences_freeze (prefs);
prefs_widget = PREFS_WIDGET (prefs_widget_new (prefs));
gtk_signal_connect (GTK_OBJECT (prefs_widget), "ok",
GTK_SIGNAL_FUNC (ok_cb), NULL);
gtk_signal_connect (GTK_OBJECT (prefs_widget), "cancel",
GTK_SIGNAL_FUNC (cancel_cb), NULL);
gtk_widget_show_all (GTK_WIDGET (prefs_widget));
preferences_thaw (prefs);
}
#ifdef HAVE_XIMIAN_ARCHIVER
static void
do_get_xml (void)
{
Preferences *prefs;
xmlDocPtr doc;
prefs = PREFERENCES (preferences_new ());
preferences_load (prefs);
doc = preferences_write_xml (prefs);
xmlDocDump (stdout, doc);
gtk_object_destroy (GTK_OBJECT (prefs));
}
static void
do_set_xml (gboolean apply_settings)
{
xmlDocPtr doc;
char buffer[16384];
GString *doc_str;
int t = 0;
fflush (stdin);
fcntl (fileno (stdin), F_SETFL, 0);
doc_str = g_string_new ("");
while ((t = read (fileno (stdin), buffer, sizeof (buffer) - 1)) != 0) {
buffer[t] = '\0';
g_string_append (doc_str, buffer);
}
if (doc_str->len > 0) {
doc = xmlParseDoc (doc_str->str);
g_string_free (doc_str, TRUE);
if (doc != NULL) {
prefs = preferences_read_xml (doc);
if (prefs && apply_settings) {
preferences_save (prefs);
return;
}
else if (prefs != NULL) {
return;
}
xmlFreeDoc (doc);
}
} else {
g_critical ("No data to apply");
}
return;
}
#endif /* HAVE_XIMIAN_ARCHIVER */
static void
do_restore_from_defaults (void)
{
prefs = PREFERENCES (preferences_new ());
preferences_save (prefs);
preferences_apply_now (prefs);
}
int
main (int argc, char **argv)
{
GnomeClient *client;
GnomeClientFlags flags;
gint token, res;
gchar *restart_args[3];
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (PACKAGE, "UTF-8");
textdomain (PACKAGE);
glade_gnome_init ();
res = gnome_capplet_init ("mouse-properties",
VERSION, argc, argv, NULL,
0, NULL);
if (res < 0) {
g_error ("Could not initialize the capplet.");
}
else if (res == 3) {
#ifdef HAVE_XIMIAN_ARCHIVER
do_get_xml ();
#endif /* HAVE_XIMIAN_ARCHIVER */
return 0;
}
else if (res == 4) {
#ifdef HAVE_XIMIAN_ARCHIVER
do_set_xml (TRUE);
#endif /* HAVE_XIMIAN_ARCHIVER */
return 0;
}
else if (res == 5) {
do_restore_from_defaults ();
return 0;
}
client = gnome_master_client ();
flags = gnome_client_get_flags (client);
if (flags & GNOME_CLIENT_IS_CONNECTED) {
token = gnome_startup_acquire_token
("GNOME_MOUSE_PROPERTIES",
gnome_client_get_id (client));
if (token) {
gnome_client_set_priority (client, 20);
gnome_client_set_restart_style (client,
GNOME_RESTART_ANYWAY);
restart_args[0] = argv[0];
restart_args[1] = "--init-session-settings";
restart_args[2] = NULL;
gnome_client_set_restart_command (client, 2,
restart_args);
} else {
gnome_client_set_restart_style (client,
GNOME_RESTART_NEVER);
}
} else {
token = 1;
}
gnome_window_icon_set_default_from_file
(GNOMECC_ICONS_DIR"/gnome-mouse.png");
#ifdef HAVE_XIMIAN_ARCHIVER
archive = ARCHIVE (archive_load (FALSE));
if (capplet_get_location () != NULL &&
strcmp (capplet_get_location (),
archive_get_current_location_id (archive)))
{
outside_location = TRUE;
do_set_xml (FALSE);
if (prefs == NULL) return -1;
preferences_freeze (prefs);
} else {
outside_location = FALSE;
prefs = PREFERENCES (preferences_new ());
preferences_load (prefs);
}
if (!outside_location && token) {
preferences_apply_now (prefs);
}
#else /* !HAVE_XIMIAN_ARCHIVER */
prefs = PREFERENCES (preferences_new ());
preferences_load (prefs);
if (token) preferences_apply_now (prefs);
#endif /* HAVE_XIMIAN_ARCHIVER */
if (!res) {
old_prefs = PREFERENCES (preferences_clone (prefs));
setup_capplet_widget ();
capplet_gtk_main ();
}
return 0;
}

View file

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<bonobo-config>
<section path="main">
<entry name="right-to-left" type="ulong" value="0"/>
<entry name="acceleration" type="ulong" value="3"/>
<entry name="threshold" type="ulong" value="3"/>
</section>
</bonobo-config>

View file

@ -1,441 +0,0 @@
/* -*- mode: c; style: linux -*- */
/* preferences.c
* Copyright (C) 2000 Helix Code, Inc.
* Copyright (C) 1998, 1999 Red Hat, Inc., Tom Tromey
*
* Written by Bradford Hovinen <hovinen@helixcode.com>,
* Jonathan Blandford <jrb@redhat.com>,
* Tom Tromey <tromey@cygnus.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, 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., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <gnome.h>
#include <X11/Xlib.h>
#include <gdk/gdkx.h>
#include "preferences.h"
/* Maximum number of mouse buttons we handle. */
#define MAX_BUTTONS 10
/* Half the number of acceleration levels we support. */
#define MAX_ACCEL 3
/* Maximum threshold we support. */
#define MAX_THRESH 7
static GtkObjectClass *parent_class;
static void preferences_init (Preferences *prefs);
static void preferences_class_init (PreferencesClass *class);
static gint xml_read_int (xmlNodePtr node);
static xmlNodePtr xml_write_int (gchar *name,
gint number);
static gboolean xml_read_bool (xmlNodePtr node);
static xmlNodePtr xml_write_bool (gchar *name,
gboolean value);
static gint apply_timeout_cb (Preferences *prefs);
guint
preferences_get_type (void)
{
static guint preferences_type = 0;
if (!preferences_type) {
GtkTypeInfo preferences_info = {
"Preferences",
sizeof (Preferences),
sizeof (PreferencesClass),
(GtkClassInitFunc) preferences_class_init,
(GtkObjectInitFunc) preferences_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL
};
preferences_type =
gtk_type_unique (gtk_object_get_type (),
&preferences_info);
}
return preferences_type;
}
static void
preferences_init (Preferences *prefs)
{
unsigned char buttons[MAX_BUTTONS];
int acc_num, acc_den, thresh;
prefs->frozen = FALSE;
/* Load default values */
prefs->nbuttons = XGetPointerMapping (GDK_DISPLAY (), buttons,
MAX_BUTTONS);
g_assert (prefs->nbuttons <= MAX_BUTTONS);
XGetPointerControl (GDK_DISPLAY (), &acc_num, &acc_den, &thresh);
prefs->threshold = thresh;
if (acc_num != 1 && acc_den != 1) {
if (acc_num > acc_den) {
acc_num = (int) ((double) acc_num / acc_den);
acc_den = 1;
} else {
acc_den = (int) ((double) acc_den / acc_num);
acc_num = 1;
}
}
if (acc_num > MAX_ACCEL)
acc_num = MAX_ACCEL;
if (acc_den > MAX_ACCEL)
acc_den = MAX_ACCEL;
if (acc_den == 1)
prefs->acceleration = acc_num + MAX_ACCEL - 1;
else
prefs->acceleration = MAX_ACCEL - acc_den;
}
static void
preferences_class_init (PreferencesClass *class)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass *) class;
object_class->destroy = preferences_destroy;
parent_class =
GTK_OBJECT_CLASS (gtk_type_class (gtk_object_get_type ()));
}
GtkObject *
preferences_new (void)
{
GtkObject *object;
object = gtk_type_new (preferences_get_type ());
return object;
}
GtkObject *
preferences_clone (Preferences *prefs)
{
GtkObject *object;
Preferences *new_prefs;
g_return_val_if_fail (prefs != NULL, NULL);
g_return_val_if_fail (IS_PREFERENCES (prefs), NULL);
object = preferences_new ();
new_prefs = PREFERENCES (object);
new_prefs->rtol = prefs->rtol;
new_prefs->acceleration = prefs->acceleration;
new_prefs->threshold = prefs->threshold;
new_prefs->nbuttons = prefs->nbuttons;
return object;
}
void
preferences_destroy (GtkObject *object)
{
Preferences *prefs;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_PREFERENCES (object));
prefs = PREFERENCES (object);
parent_class->destroy (object);
}
void
preferences_load (Preferences *prefs)
{
unsigned char buttons[MAX_BUTTONS];
int acc_num, acc_den, thresh;
gboolean rtol_default;
g_return_if_fail (prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs));
prefs->nbuttons = XGetPointerMapping (GDK_DISPLAY (), buttons,
MAX_BUTTONS);
g_assert (prefs->nbuttons <= MAX_BUTTONS);
/* Note that we only handle right-to-left and left-to-right.
Most weird mappings are treated as l-to-r.
We could handle this by showing the mouse buttons and letting the
user drag-and-drop them to reorder. But I'm not convinced this
is worth it. */
/* FIXME: this ignores the fact that a mouse with the weird little
roller generates B4 and B5 when the roller is moved. That
shouldn't change when we remap the other mouse buttons. */
prefs->rtol = gnome_config_get_bool_with_default
("/Desktop/Mouse/right-to-left=false", &rtol_default);
if (rtol_default)
prefs->rtol = (buttons[prefs->nbuttons - 1] == 1);
prefs->threshold = gnome_config_get_int ("/Desktop/Mouse/threshold=-1");
prefs->acceleration = gnome_config_get_int
("/Desktop/Mouse/acceleration=-1");
if (prefs->threshold == -1 || prefs->acceleration == -1) {
XGetPointerControl (GDK_DISPLAY (), &acc_num,
&acc_den, &thresh);
if (prefs->threshold == -1)
prefs->threshold = thresh;
if (prefs->acceleration == -1) {
/* Only support cases in our range. If neither the
* numerator nor denominator is 1, then rescale. */
if (acc_num != 1 && acc_den != 1) {
if (acc_num > acc_den) {
acc_num = (int)
((double) acc_num / acc_den);
acc_den = 1;
} else {
acc_den = (int)
((double) acc_den / acc_num);
acc_num = 1;
}
}
if (acc_num > MAX_ACCEL)
acc_num = MAX_ACCEL;
if (acc_den > MAX_ACCEL)
acc_den = MAX_ACCEL;
if (acc_den == 1)
prefs->acceleration = acc_num + MAX_ACCEL - 1;
else
prefs->acceleration = MAX_ACCEL - acc_den;
}
}
}
void
preferences_save (Preferences *prefs)
{
g_return_if_fail (prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs));
gnome_config_set_int ("/Desktop/Mouse/acceleration",
prefs->acceleration);
gnome_config_set_int ("/Desktop/Mouse/threshold", prefs->threshold);
gnome_config_set_bool ("/Desktop/Mouse/right-to-left", prefs->rtol);
gnome_config_sync ();
}
void
preferences_changed (Preferences *prefs)
{
if (prefs->frozen) return;
if (prefs->timeout_id)
gtk_timeout_remove (prefs->timeout_id);
/* Live update in this case could be very problematic, so we're going
* to disable it */
/* preferences_apply_now (prefs); */
}
void
preferences_apply_now (Preferences *prefs)
{
unsigned char buttons[MAX_BUTTONS], i;
int num, den, max;
g_return_if_fail (prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs));
if (prefs->timeout_id)
gtk_timeout_remove (prefs->timeout_id);
prefs->timeout_id = 0;
g_assert (prefs->nbuttons <= MAX_BUTTONS);
/* Ignore buttons above 3 -- these are assumed to be a wheel. If we
* have a non-wheeled mouse, this may do weird things */
XGetPointerMapping(GDK_DISPLAY (), buttons, MAX_BUTTONS);
max = MIN (prefs->nbuttons, 3);
for (i = 0; i < max; ++i)
buttons[i] = prefs->rtol ? (max - i) : (i + 1);
XSetPointerMapping (GDK_DISPLAY (), buttons, prefs->nbuttons);
if (prefs->acceleration < MAX_ACCEL) {
num = 1;
den = MAX_ACCEL - prefs->acceleration;
} else {
num = prefs->acceleration - MAX_ACCEL + 1;
den = 1;
}
XChangePointerControl (GDK_DISPLAY (), True, True,
num, den, prefs->threshold);
}
void preferences_freeze (Preferences *prefs)
{
prefs->frozen++;
}
void preferences_thaw (Preferences *prefs)
{
if (prefs->frozen > 0) prefs->frozen--;
}
Preferences *
preferences_read_xml (xmlDocPtr xml_doc)
{
Preferences *prefs;
xmlNodePtr root_node, node;
prefs = PREFERENCES (preferences_new ());
root_node = xmlDocGetRootElement (xml_doc);
if (strcmp (root_node->name, "mouse-properties"))
return NULL;
for (node = root_node->childs; node; node = node->next) {
if (!strcmp (node->name, "acceleration"))
prefs->acceleration = xml_read_int (node);
else if (!strcmp (node->name, "threshold"))
prefs->threshold = xml_read_int (node);
else if (!strcmp (node->name, "right-to-left"))
prefs->rtol = xml_read_bool (node);
}
return prefs;
}
xmlDocPtr
preferences_write_xml (Preferences *prefs)
{
xmlDocPtr doc;
xmlNodePtr node;
char *tmp;
doc = xmlNewDoc ("1.0");
node = xmlNewDocNode (doc, NULL, "mouse-properties", NULL);
xmlAddChild (node, xml_write_int ("acceleration",
prefs->acceleration));
xmlAddChild (node, xml_write_int ("threshold",
prefs->threshold));
xmlAddChild (node, xml_write_bool ("right-to-left", prefs->rtol));
xmlDocSetRootElement (doc, node);
return doc;
}
/* Read a numeric value from a node */
static gint
xml_read_int (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (text == NULL)
return 0;
else
return atoi (text);
}
/* Write out a numeric value in a node */
static xmlNodePtr
xml_write_int (gchar *name, gint number)
{
xmlNodePtr node;
gchar *str;
g_return_val_if_fail (name != NULL, NULL);
str = g_strdup_printf ("%d", number);
node = xmlNewNode (NULL, name);
xmlNodeSetContent (node, str);
g_free (str);
return node;
}
/* Read a boolean value from a node */
static gboolean
xml_read_bool (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (!g_strcasecmp (text, "true"))
return TRUE;
else
return FALSE;
}
/* Write out a boolean value in a node */
static xmlNodePtr
xml_write_bool (gchar *name, gboolean value)
{
xmlNodePtr node;
g_return_val_if_fail (name != NULL, NULL);
node = xmlNewNode (NULL, name);
if (value)
xmlNodeSetContent (node, "true");
else
xmlNodeSetContent (node, "false");
return node;
}
static gint
apply_timeout_cb (Preferences *prefs)
{
preferences_apply_now (prefs);
return TRUE;
}

View file

@ -1,73 +0,0 @@
/* -*- mode: c; style: linux -*- */
/* preferences.h
* Copyright (C) 2000 Helix Code, Inc.
*
* Written by Bradford Hovinen <hovinen@helixcode.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, 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., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef __PREFERENCES_H
#define __PREFERENCES_H
#include <gtk/gtk.h>
#include <tree.h>
#define PREFERENCES(obj) GTK_CHECK_CAST (obj, preferences_get_type (), Preferences)
#define PREFERENCES_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, preferences_get_type (), PreferencesClass)
#define IS_PREFERENCES(obj) GTK_CHECK_TYPE (obj, preferences_get_type ())
typedef struct _Preferences Preferences;
typedef struct _PreferencesClass PreferencesClass;
struct _Preferences
{
GtkObject object;
gint frozen;
guint timeout_id;
gboolean rtol;
gint nbuttons;
gint acceleration;
gint threshold;
};
struct _PreferencesClass
{
GtkObjectClass klass;
};
guint preferences_get_type (void);
GtkObject *preferences_new (void);
GtkObject *preferences_clone (Preferences *prefs);
void preferences_destroy (GtkObject *object);
void preferences_load (Preferences *prefs);
void preferences_save (Preferences *prefs);
void preferences_changed (Preferences *prefs);
void preferences_apply_now (Preferences *prefs);
void preferences_freeze (Preferences *prefs);
void preferences_thaw (Preferences *prefs);
Preferences *preferences_read_xml (xmlDocPtr xml_doc);
xmlDocPtr preferences_write_xml (Preferences *prefs);
#endif /* __PREFERENCES_H */

View file

@ -1,337 +0,0 @@
/* -*- mode: c; style: linux -*- */
/* prefs-widget.c
* Copyright (C) 2000 Helix Code, Inc.
*
* Written by Bradford Hovinen <hovinen@helixcode.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, 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., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "prefs-widget.h"
#define WID(str) (glade_xml_get_widget (prefs_widget->dialog_data, str))
#define THRESHOLD_CONVERT(t) (7 - t)
enum {
ARG_0,
ARG_PREFERENCES
};
static CappletWidgetClass *parent_class;
static void prefs_widget_init (PrefsWidget *prefs_widget);
static void prefs_widget_class_init (PrefsWidgetClass *class);
static void prefs_widget_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void prefs_widget_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void read_preferences (PrefsWidget *prefs_widget,
Preferences *prefs);
static void left_handed_selected_cb (GtkToggleButton *tb,
PrefsWidget *prefs_widget);
static void right_handed_selected_cb (GtkToggleButton *tb,
PrefsWidget *prefs_widget);
static void acceleration_changed_cb (GtkAdjustment *adjustment,
PrefsWidget *prefs_widget);
static void threshold_changed_cb (GtkAdjustment *adjustment,
PrefsWidget *prefs_widget);
static void set_pixmap_file (PrefsWidget *prefs_widget,
const gchar *widget_name,
const gchar *filename);
guint
prefs_widget_get_type (void)
{
static guint prefs_widget_type = 0;
if (!prefs_widget_type) {
GtkTypeInfo prefs_widget_info = {
"PrefsWidget",
sizeof (PrefsWidget),
sizeof (PrefsWidgetClass),
(GtkClassInitFunc) prefs_widget_class_init,
(GtkObjectInitFunc) prefs_widget_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL
};
prefs_widget_type =
gtk_type_unique (capplet_widget_get_type (),
&prefs_widget_info);
}
return prefs_widget_type;
}
static void
prefs_widget_init (PrefsWidget *prefs_widget)
{
GtkWidget *widget;
GtkAdjustment *adjustment;
prefs_widget->dialog_data =
glade_xml_new (GNOMECC_GLADE_DIR "/mouse-properties.glade",
"prefs_widget");
widget = glade_xml_get_widget (prefs_widget->dialog_data,
"prefs_widget");
gtk_container_add (GTK_CONTAINER (prefs_widget), widget);
set_pixmap_file (prefs_widget, "mouse_left_pixmap", GNOMECC_PIXMAPS_DIR "/mouse-left.png");
set_pixmap_file (prefs_widget, "mouse_right_pixmap", GNOMECC_PIXMAPS_DIR "/mouse-right.png");
glade_xml_signal_connect_data
(prefs_widget->dialog_data, "left_handed_selected_cb",
left_handed_selected_cb, prefs_widget);
glade_xml_signal_connect_data
(prefs_widget->dialog_data, "right_handed_selected_cb",
right_handed_selected_cb, prefs_widget);
adjustment = gtk_range_get_adjustment
(GTK_RANGE (WID ("acceleration_entry")));
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
acceleration_changed_cb, prefs_widget);
adjustment = gtk_range_get_adjustment
(GTK_RANGE (WID ("sensitivity_entry")));
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
threshold_changed_cb, prefs_widget);
}
static void
prefs_widget_class_init (PrefsWidgetClass *class)
{
GtkObjectClass *object_class;
gtk_object_add_arg_type ("PrefsWidget::preferences",
GTK_TYPE_POINTER,
GTK_ARG_READWRITE,
ARG_PREFERENCES);
object_class = GTK_OBJECT_CLASS (class);
object_class->set_arg = prefs_widget_set_arg;
object_class->get_arg = prefs_widget_get_arg;
parent_class = CAPPLET_WIDGET_CLASS
(gtk_type_class (capplet_widget_get_type ()));
}
static void
prefs_widget_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
PrefsWidget *prefs_widget;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_PREFS_WIDGET (object));
prefs_widget = PREFS_WIDGET (object);
switch (arg_id) {
case ARG_PREFERENCES:
if (prefs_widget->prefs)
gtk_object_unref (GTK_OBJECT (prefs_widget->prefs));
prefs_widget->prefs = GTK_VALUE_POINTER (*arg);
if (prefs_widget->prefs) {
gtk_object_ref (GTK_OBJECT (prefs_widget->prefs));
read_preferences (prefs_widget, prefs_widget->prefs);
}
break;
default:
g_warning ("Bad argument set");
break;
}
}
static void
prefs_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
PrefsWidget *prefs_widget;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_PREFS_WIDGET (object));
prefs_widget = PREFS_WIDGET (object);
switch (arg_id) {
case ARG_PREFERENCES:
GTK_VALUE_POINTER (*arg) = prefs_widget->prefs;
break;
default:
g_warning ("Bad argument get");
break;
}
}
GtkWidget *
prefs_widget_new (Preferences *prefs)
{
g_return_val_if_fail (prefs == NULL || IS_PREFERENCES (prefs), NULL);
return gtk_widget_new (prefs_widget_get_type (),
"preferences", prefs,
NULL);
}
void
prefs_widget_set_preferences (PrefsWidget *prefs_widget, Preferences *prefs)
{
g_return_if_fail (prefs_widget != NULL);
g_return_if_fail (IS_PREFS_WIDGET (prefs_widget));
g_return_if_fail (prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs));
gtk_object_set (GTK_OBJECT (prefs_widget), "preferences", prefs, NULL);
}
static void
read_preferences (PrefsWidget *prefs_widget, Preferences *prefs)
{
GtkAdjustment *adjustment;
g_return_if_fail (prefs_widget != NULL);
g_return_if_fail (IS_PREFS_WIDGET (prefs_widget));
g_return_if_fail (prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs));
if (!prefs->rtol) {
gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON (WID ("right_handed_select")),
TRUE);
} else {
gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON (WID ("left_handed_select")),
TRUE);
}
adjustment = gtk_range_get_adjustment
(GTK_RANGE (WID ("acceleration_entry")));
gtk_adjustment_set_value (adjustment, prefs->acceleration);
adjustment = gtk_range_get_adjustment
(GTK_RANGE (WID ("sensitivity_entry")));
gtk_adjustment_set_value (adjustment, THRESHOLD_CONVERT (prefs->threshold));
}
static void
left_handed_selected_cb (GtkToggleButton *tb, PrefsWidget *prefs_widget)
{
g_return_if_fail (prefs_widget != NULL);
g_return_if_fail (IS_PREFS_WIDGET (prefs_widget));
g_return_if_fail (prefs_widget->prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs_widget->prefs));
if (gtk_toggle_button_get_active (tb)) {
prefs_widget->prefs->rtol = TRUE;
preferences_changed (prefs_widget->prefs);
}
capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE);
}
static void
right_handed_selected_cb (GtkToggleButton *tb, PrefsWidget *prefs_widget)
{
g_return_if_fail (prefs_widget != NULL);
g_return_if_fail (IS_PREFS_WIDGET (prefs_widget));
g_return_if_fail (prefs_widget->prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs_widget->prefs));
if (gtk_toggle_button_get_active (tb)) {
prefs_widget->prefs->rtol = FALSE;
preferences_changed (prefs_widget->prefs);
}
capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE);
}
static void
acceleration_changed_cb (GtkAdjustment *adjustment, PrefsWidget *prefs_widget)
{
g_return_if_fail (prefs_widget != NULL);
g_return_if_fail (IS_PREFS_WIDGET (prefs_widget));
g_return_if_fail (prefs_widget->prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs_widget->prefs));
g_return_if_fail (adjustment != NULL);
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
prefs_widget->prefs->acceleration = adjustment->value;
preferences_changed (prefs_widget->prefs);
capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE);
}
static void
threshold_changed_cb (GtkAdjustment *adjustment, PrefsWidget *prefs_widget)
{
g_return_if_fail (prefs_widget != NULL);
g_return_if_fail (IS_PREFS_WIDGET (prefs_widget));
g_return_if_fail (prefs_widget->prefs != NULL);
g_return_if_fail (IS_PREFERENCES (prefs_widget->prefs));
g_return_if_fail (adjustment != NULL);
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
prefs_widget->prefs->threshold = THRESHOLD_CONVERT (adjustment->value);
preferences_changed (prefs_widget->prefs);
capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE);
}
static void
set_pixmap_file (PrefsWidget *prefs_widget, const gchar *widget_name, const gchar *filename)
{
GtkWidget *widget;
GdkPixbuf *pixbuf;
GdkPixmap *pixmap;
GdkBitmap *mask;
g_return_if_fail (IS_PREFS_WIDGET (prefs_widget));
g_return_if_fail (widget_name != NULL);
g_return_if_fail (filename != NULL);
widget = WID (widget_name);
g_return_if_fail (widget != NULL);
pixbuf = gdk_pixbuf_new_from_file (filename);
if (pixbuf) {
gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask,
100);
gtk_pixmap_set (GTK_PIXMAP (widget),
pixmap, mask);
gdk_pixbuf_unref (pixbuf);
}
}

View file

@ -1,60 +0,0 @@
/* -*- mode: c; style: linux -*- */
/* prefs-widget.h
* Copyright (C) 2000 Helix Code, Inc.
*
* Written by Bradford Hovinen <hovinen@helixcode.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, 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., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef __PREFS_WIDGET_H
#define __PREFS_WIDGET_H
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <capplet-widget.h>
#include "preferences.h"
#define PREFS_WIDGET(obj) GTK_CHECK_CAST (obj, prefs_widget_get_type (), PrefsWidget)
#define PREFS_WIDGET_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, prefs_widget_get_type (), PrefsWidgetClass)
#define IS_PREFS_WIDGET(obj) GTK_CHECK_TYPE (obj, prefs_widget_get_type ())
typedef struct _PrefsWidget PrefsWidget;
typedef struct _PrefsWidgetClass PrefsWidgetClass;
struct _PrefsWidget
{
CappletWidget capplet_widget;
Preferences *prefs;
GladeXML *dialog_data;
};
struct _PrefsWidgetClass
{
CappletWidgetClass parent_class;
};
guint prefs_widget_get_type (void);
GtkWidget *prefs_widget_new (Preferences *prefs);
void prefs_widget_set_preferences (PrefsWidget *prefs_widget,
Preferences *prefs);
#endif /* __PREFS_WIDGET_H */