mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-22 20:41:43 +00:00
002aa905db
1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1205 lines
30 KiB
C
1205 lines
30 KiB
C
/* The GIMP -- an image manipulation program
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
*
|
|
* 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 "config.h"
|
|
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#include "appenv.h"
|
|
#include "gimpcontextpreview.h"
|
|
#include "gimpdnd.h"
|
|
#include "devices.h"
|
|
#include "interface.h"
|
|
#include "gimprc.h"
|
|
#include "gimpui.h"
|
|
#include "palette.h"
|
|
#include "session.h"
|
|
#include "tools.h"
|
|
#include "dialog_handler.h"
|
|
#include "indicator_area.h"
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
#include "libgimp/gimpenv.h"
|
|
|
|
#define CELL_SIZE 20 /* The size of the preview cells */
|
|
#define PREVIEW_EVENT_MASK GDK_BUTTON_PRESS_MASK | \
|
|
GDK_BUTTON_RELEASE_MASK | \
|
|
GDK_ENTER_NOTIFY_MASK | \
|
|
GDK_LEAVE_NOTIFY_MASK
|
|
|
|
typedef struct _DeviceInfo DeviceInfo;
|
|
|
|
struct _DeviceInfo {
|
|
guint32 device; /* device ID */
|
|
gchar *name;
|
|
|
|
short is_init; /* has the user used it? */
|
|
short is_present; /* is the device currently present */
|
|
|
|
/* gdk_input options - for not present devices */
|
|
|
|
GdkInputMode mode;
|
|
gint num_axes;
|
|
GdkAxisUse *axes;
|
|
gint num_keys;
|
|
GdkDeviceKey *keys;
|
|
|
|
GimpBrushP brush;
|
|
GPatternP pattern;
|
|
ToolType tool;
|
|
guchar foreground[3];
|
|
};
|
|
|
|
typedef struct _DeviceInfoDialog DeviceInfoDialog;
|
|
|
|
struct _DeviceInfoDialog {
|
|
int num_devices;
|
|
guint32 current;
|
|
guint32 *ids;
|
|
|
|
GtkWidget *shell;
|
|
GtkWidget *table;
|
|
|
|
GtkWidget **frames;
|
|
GtkWidget **tools;
|
|
GtkWidget **colors;
|
|
GtkWidget **brushes;
|
|
GtkWidget **patterns;
|
|
GtkWidget **eventboxes;
|
|
};
|
|
|
|
/* Local Data */
|
|
|
|
GList *devices_info = NULL;
|
|
DeviceInfoDialog *deviceD = NULL;
|
|
/* If true, don't update device information dialog */
|
|
int suppress_update = FALSE;
|
|
|
|
/* Local functions */
|
|
static void input_dialog_destroy_callback (GtkWidget *, gpointer);
|
|
void input_dialog_able_callback (GtkWidget *w, guint32 deviceid,
|
|
gpointer data);
|
|
static void devices_save_current_info (void);
|
|
static void devices_write_rc_device (DeviceInfo *device_info, FILE *fp);
|
|
static void devices_write_rc (void);
|
|
static void device_status_destroy_callback (void);
|
|
static void devices_close_callback (GtkWidget *, gpointer);
|
|
static void device_status_update_current ();
|
|
|
|
static void device_status_drag_color (GtkWidget *,
|
|
guchar *, guchar *, guchar *, gpointer);
|
|
static void device_status_drop_color (GtkWidget *,
|
|
guchar, guchar, guchar, gpointer);
|
|
static void device_status_drop_brush (GtkWidget *,
|
|
GdkDragContext *, gint, gint, guint, gpointer);
|
|
static void device_status_drop_pattern (GtkWidget *,
|
|
GdkDragContext *, gint, gint, guint, gpointer);
|
|
|
|
|
|
/* Global data */
|
|
int current_device = GDK_CORE_POINTER;
|
|
|
|
/* dnd stuff */
|
|
static GtkTargetEntry color_area_target_table[] =
|
|
{
|
|
GIMP_TARGET_COLOR
|
|
};
|
|
static guint n_color_area_targets = (sizeof (color_area_target_table) /
|
|
sizeof (color_area_target_table[0]));
|
|
static GtkTargetEntry brush_area_target_table[] =
|
|
{
|
|
GIMP_TARGET_BRUSH
|
|
};
|
|
static guint n_brush_area_targets = (sizeof (brush_area_target_table) /
|
|
sizeof (brush_area_target_table[0]));
|
|
static GtkTargetEntry pattern_area_target_table[] =
|
|
{
|
|
GIMP_TARGET_PATTERN
|
|
};
|
|
static guint n_pattern_area_targets = (sizeof (pattern_area_target_table) /
|
|
sizeof (pattern_area_target_table[0]));
|
|
|
|
|
|
void
|
|
create_input_dialog (void)
|
|
{
|
|
static GtkWidget *inputd = NULL;
|
|
GtkWidget *hbbox;
|
|
|
|
if (!inputd)
|
|
{
|
|
inputd = gtk_input_dialog_new ();
|
|
|
|
/* register this one only */
|
|
dialog_register (inputd);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (inputd)->action_area), 2);
|
|
gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (inputd)->action_area),
|
|
FALSE);
|
|
|
|
hbbox = gtk_hbutton_box_new ();
|
|
gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbbox), 4);
|
|
|
|
gtk_widget_reparent (GTK_INPUT_DIALOG (inputd)->save_button, hbbox);
|
|
GTK_WIDGET_SET_FLAGS (GTK_INPUT_DIALOG (inputd)->save_button,
|
|
GTK_CAN_DEFAULT);
|
|
gtk_widget_reparent (GTK_INPUT_DIALOG (inputd)->close_button, hbbox);
|
|
GTK_WIDGET_SET_FLAGS (GTK_INPUT_DIALOG (inputd)->close_button,
|
|
GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_end (GTK_BOX (GTK_DIALOG (inputd)->action_area), hbbox,
|
|
FALSE, FALSE, 0);
|
|
gtk_widget_grab_default (GTK_INPUT_DIALOG (inputd)->close_button);
|
|
gtk_widget_show(hbbox);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (GTK_INPUT_DIALOG (inputd)->save_button),
|
|
"clicked",
|
|
GTK_SIGNAL_FUNC (devices_write_rc), NULL);
|
|
gtk_signal_connect (GTK_OBJECT (GTK_INPUT_DIALOG (inputd)->close_button),
|
|
"clicked",
|
|
GTK_SIGNAL_FUNC (devices_close_callback), inputd);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (inputd), "destroy",
|
|
(GtkSignalFunc) input_dialog_destroy_callback,
|
|
&inputd);
|
|
gtk_signal_connect (GTK_OBJECT (inputd), "enable_device",
|
|
GTK_SIGNAL_FUNC (input_dialog_able_callback), NULL);
|
|
gtk_signal_connect (GTK_OBJECT (inputd), "disable_device",
|
|
GTK_SIGNAL_FUNC (input_dialog_able_callback), NULL);
|
|
|
|
/* Connect the "F1" help key */
|
|
gimp_help_connect_help_accel (inputd,
|
|
gimp_standard_help_func,
|
|
"dialogs/input_devices_dialog.html");
|
|
|
|
gtk_widget_show (inputd);
|
|
}
|
|
else
|
|
{
|
|
if (!GTK_WIDGET_MAPPED (inputd))
|
|
gtk_widget_show (inputd);
|
|
else
|
|
gdk_window_raise (inputd->window);
|
|
}
|
|
}
|
|
|
|
void
|
|
input_dialog_able_callback (GtkWidget *widget,
|
|
guint32 deviceid,
|
|
gpointer data)
|
|
{
|
|
device_status_update (deviceid);
|
|
}
|
|
|
|
static void
|
|
input_dialog_destroy_callback (GtkWidget *widget,
|
|
gpointer call_data)
|
|
{
|
|
*((GtkWidget **)call_data) = NULL;
|
|
}
|
|
|
|
void
|
|
devices_init (void)
|
|
{
|
|
GList *tmp_list;
|
|
|
|
/* Create device info structures for present devices */
|
|
|
|
tmp_list = gdk_input_list_devices ();
|
|
|
|
while (tmp_list)
|
|
{
|
|
GdkDeviceInfo *gdk_info = (GdkDeviceInfo *)tmp_list->data;
|
|
DeviceInfo *device_info = g_new (DeviceInfo, 1);
|
|
|
|
device_info->device = gdk_info->deviceid;
|
|
device_info->name = g_strdup (gdk_info->name);
|
|
|
|
device_info->is_init = FALSE;
|
|
device_info->is_present = TRUE;
|
|
|
|
device_info->mode = gdk_info->mode;
|
|
device_info->num_axes = gdk_info->num_axes;
|
|
device_info->axes = NULL;
|
|
|
|
device_info->brush = NULL;
|
|
device_info->pattern = NULL;
|
|
device_info->tool = RECT_SELECT;
|
|
device_info->foreground[0] = 0;
|
|
device_info->foreground[1] = 0;
|
|
device_info->foreground[2] = 0;
|
|
|
|
devices_info = g_list_append (devices_info, device_info);
|
|
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
}
|
|
|
|
void
|
|
devices_restore (void)
|
|
{
|
|
char *filename;
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info;
|
|
|
|
/* Augment with information from rc file */
|
|
filename = gimp_personal_rc_file ("devicerc");
|
|
parse_gimprc_file (filename);
|
|
g_free (filename);
|
|
|
|
tmp_list = devices_info;
|
|
device_info = NULL;
|
|
while (tmp_list)
|
|
{
|
|
if (((DeviceInfo *)tmp_list->data)->device == current_device)
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
break;
|
|
}
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
|
|
g_return_if_fail (device_info != NULL);
|
|
|
|
suppress_update = TRUE;
|
|
|
|
if (device_info->is_init)
|
|
{
|
|
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
|
|
|
palette_set_foreground (device_info->foreground[0],
|
|
device_info->foreground[1],
|
|
device_info->foreground[2]);
|
|
|
|
if (device_info->brush)
|
|
select_brush (device_info->brush);
|
|
if (device_info->pattern)
|
|
select_pattern (device_info->pattern);
|
|
}
|
|
|
|
suppress_update = FALSE;
|
|
}
|
|
|
|
void
|
|
devices_rc_update (gchar *name,
|
|
DeviceValues values,
|
|
GdkInputMode mode,
|
|
gint num_axes,
|
|
GdkAxisUse *axes,
|
|
gint num_keys,
|
|
GdkDeviceKey *keys,
|
|
gchar *brush_name,
|
|
ToolType tool,
|
|
guchar foreground[],
|
|
gchar *pattern_name)
|
|
{
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info;
|
|
|
|
/* Find device if we have it */
|
|
|
|
tmp_list = devices_info;
|
|
device_info = NULL;
|
|
while (tmp_list)
|
|
{
|
|
if (!strcmp (((DeviceInfo *)tmp_list->data)->name, name))
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
break;
|
|
}
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
|
|
if (!device_info)
|
|
{
|
|
device_info = g_new (DeviceInfo, 1);
|
|
device_info->name = g_strdup (name);
|
|
device_info->is_present = FALSE;
|
|
|
|
if (values & DEVICE_AXES)
|
|
{
|
|
device_info->num_axes = num_axes;
|
|
device_info->axes = g_new (GdkAxisUse, num_axes);
|
|
memcpy (device_info->axes, axes, num_axes * sizeof (GdkAxisUse));
|
|
}
|
|
else
|
|
{
|
|
device_info->num_axes = 0;
|
|
device_info->axes = NULL;
|
|
}
|
|
|
|
if (values & DEVICE_KEYS)
|
|
{
|
|
device_info->num_keys = num_keys;
|
|
device_info->keys = g_new (GdkDeviceKey, num_keys);
|
|
memcpy (device_info->keys, axes, num_keys * sizeof (GdkDeviceKey));
|
|
}
|
|
|
|
if (values & DEVICE_MODE)
|
|
device_info->mode = mode;
|
|
else
|
|
device_info->mode = GDK_MODE_DISABLED;
|
|
|
|
device_info->brush = NULL;
|
|
device_info->pattern = NULL;
|
|
device_info->tool = RECT_SELECT;
|
|
device_info->foreground[0] = 0;
|
|
device_info->foreground[1] = 0;
|
|
device_info->foreground[2] = 0;
|
|
|
|
devices_info = g_list_append (devices_info, device_info);
|
|
}
|
|
else
|
|
{
|
|
GdkDeviceInfo *gdk_info = NULL; /* Quiet gcc */
|
|
|
|
tmp_list = gdk_input_list_devices();
|
|
while (tmp_list)
|
|
{
|
|
GdkDeviceInfo *info = (GdkDeviceInfo *)tmp_list->data;
|
|
|
|
if (info->deviceid == device_info->device)
|
|
{
|
|
gdk_info = info;
|
|
break;
|
|
}
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
|
|
if (gdk_info != NULL)
|
|
{
|
|
if (values & DEVICE_MODE)
|
|
gdk_input_set_mode (gdk_info->deviceid, mode);
|
|
|
|
if ((values & DEVICE_AXES) && num_axes >= gdk_info->num_axes)
|
|
gdk_input_set_axes (gdk_info->deviceid, axes);
|
|
|
|
if ((values & DEVICE_KEYS) && num_keys >= gdk_info->num_keys)
|
|
{
|
|
int i;
|
|
|
|
for (i=0; i<MAX (num_keys, gdk_info->num_keys); i++)
|
|
gdk_input_set_key (gdk_info->deviceid, i,
|
|
keys[i].keyval, keys[i].modifiers);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
g_warning (_("devices_rc_update called multiple times for not present device\n"));
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (values & (DEVICE_PATTERN | DEVICE_BRUSH | DEVICE_TOOL | DEVICE_FOREGROUND))
|
|
device_info->is_init = TRUE;
|
|
|
|
|
|
if (values & DEVICE_BRUSH)
|
|
{
|
|
device_info->brush = gimp_brush_list_get_brush (brush_list, brush_name);
|
|
}
|
|
|
|
if (values & DEVICE_PATTERN)
|
|
{
|
|
device_info->pattern = pattern_list_get_pattern (pattern_list, pattern_name);
|
|
}
|
|
|
|
if (values & DEVICE_TOOL)
|
|
device_info->tool = tool;
|
|
|
|
if (values & DEVICE_FOREGROUND)
|
|
{
|
|
device_info->foreground[0] = foreground[0];
|
|
device_info->foreground[1] = foreground[1];
|
|
device_info->foreground[2] = foreground[2];
|
|
}
|
|
}
|
|
|
|
void
|
|
select_device (guint32 new_device)
|
|
{
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info;
|
|
|
|
suppress_update = TRUE;
|
|
|
|
/* store old information */
|
|
|
|
devices_save_current_info();
|
|
|
|
/* Now see if there is already information about the new device */
|
|
|
|
tmp_list = devices_info;
|
|
device_info = NULL;
|
|
while (tmp_list)
|
|
{
|
|
if (((DeviceInfo *)tmp_list->data)->device == new_device)
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
break;
|
|
}
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
|
|
current_device = new_device;
|
|
|
|
if (device_info->is_init)
|
|
{
|
|
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
|
palette_set_foreground (device_info->foreground[0],
|
|
device_info->foreground[1],
|
|
device_info->foreground[2]);
|
|
if (device_info->brush)
|
|
select_brush (device_info->brush);
|
|
if (device_info->pattern)
|
|
select_pattern (device_info->pattern);
|
|
}
|
|
|
|
suppress_update = FALSE;
|
|
|
|
device_status_update_current ();
|
|
}
|
|
|
|
gint
|
|
devices_check_change (GdkEvent *event)
|
|
{
|
|
guint32 device;
|
|
|
|
switch (event->type)
|
|
{
|
|
case GDK_MOTION_NOTIFY:
|
|
device = ((GdkEventMotion *)event)->deviceid;
|
|
break;
|
|
case GDK_BUTTON_PRESS:
|
|
case GDK_BUTTON_RELEASE:
|
|
device = ((GdkEventButton *)event)->deviceid;
|
|
break;
|
|
case GDK_PROXIMITY_OUT:
|
|
device = ((GdkEventProximity *)event)->deviceid;
|
|
break;
|
|
default:
|
|
device = current_device;
|
|
}
|
|
|
|
if (device != current_device)
|
|
{
|
|
select_device (device);
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
static void
|
|
devices_save_current_info (void)
|
|
{
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info;
|
|
|
|
tmp_list = devices_info;
|
|
device_info = NULL;
|
|
while (tmp_list)
|
|
{
|
|
if (((DeviceInfo *)tmp_list->data)->device == current_device)
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
break;
|
|
}
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
|
|
device_info->is_init = TRUE;
|
|
device_info->device = current_device;
|
|
device_info->brush = get_active_brush ();
|
|
device_info->pattern = get_active_pattern ();
|
|
if (active_tool)
|
|
device_info->tool = active_tool->type;
|
|
else
|
|
device_info->tool = RECT_SELECT;
|
|
palette_get_foreground (&device_info->foreground[0],
|
|
&device_info->foreground[1],
|
|
&device_info->foreground[2]);
|
|
}
|
|
|
|
static void
|
|
devices_write_rc_device (DeviceInfo *device_info,
|
|
FILE *fp)
|
|
{
|
|
GdkDeviceInfo *gdk_info;
|
|
GList *tmp_list;
|
|
gchar *mode = NULL; /* Quiet gcc */
|
|
int i;
|
|
|
|
gdk_info = NULL;
|
|
if (device_info->is_present)
|
|
{
|
|
/* gdk_input_list_devices returns an internal list, so we shouldn't
|
|
free it afterwards */
|
|
tmp_list = gdk_input_list_devices ();
|
|
while (tmp_list)
|
|
{
|
|
GdkDeviceInfo *info = (GdkDeviceInfo *)tmp_list->data;
|
|
|
|
if (info->deviceid == device_info->device)
|
|
{
|
|
gdk_info = info;
|
|
break;
|
|
}
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
}
|
|
|
|
fprintf (fp, "(device \"%s\"",device_info->name);
|
|
|
|
switch (gdk_info ? gdk_info->mode : device_info->mode)
|
|
{
|
|
case GDK_MODE_DISABLED:
|
|
mode = "disabled";
|
|
break;
|
|
case GDK_MODE_SCREEN:
|
|
mode = "screen";
|
|
break;
|
|
case GDK_MODE_WINDOW:
|
|
mode = "window";
|
|
break;
|
|
}
|
|
|
|
fprintf (fp, "\n (mode %s)", mode);
|
|
|
|
fprintf (fp, "\n (axes %d",
|
|
gdk_info ? gdk_info->num_axes : device_info->num_axes);
|
|
|
|
for (i=0; i<(gdk_info ? gdk_info->num_axes : device_info->num_axes); i++)
|
|
{
|
|
gchar *axis_type = NULL; /* Quiet gcc */
|
|
|
|
switch (gdk_info ? gdk_info->axes[i] : device_info->axes[i])
|
|
{
|
|
case GDK_AXIS_IGNORE:
|
|
axis_type = "ignore";
|
|
break;
|
|
case GDK_AXIS_X:
|
|
axis_type = "x";
|
|
break;
|
|
case GDK_AXIS_Y:
|
|
axis_type = "y";
|
|
break;
|
|
case GDK_AXIS_PRESSURE:
|
|
axis_type = "pressure";
|
|
break;
|
|
case GDK_AXIS_XTILT:
|
|
axis_type = "xtilt";
|
|
break;
|
|
case GDK_AXIS_YTILT:
|
|
axis_type = "ytilt";
|
|
break;
|
|
#ifdef GTK_HAVE_SIX_VALUATORS
|
|
case GDK_AXIS_WHEEL:
|
|
axis_type = "wheel";
|
|
break;
|
|
#endif /* GTK_HAVE_SIX_VALUATORS */
|
|
}
|
|
fprintf (fp, " %s",axis_type);
|
|
}
|
|
fprintf (fp,")");
|
|
|
|
fprintf (fp, "\n (keys %d",
|
|
gdk_info ? gdk_info->num_keys : device_info->num_keys);
|
|
|
|
for (i=0; i < (gdk_info ? gdk_info->num_keys : device_info->num_keys); i++)
|
|
{
|
|
GdkModifierType modifiers = gdk_info ? gdk_info->keys[i].modifiers :
|
|
device_info->keys[i].modifiers;
|
|
guint keyval = gdk_info ? gdk_info->keys[i].keyval :
|
|
device_info->keys[i].keyval;
|
|
|
|
if (keyval)
|
|
{
|
|
/* FIXME: integrate this back with menus_install_accelerator */
|
|
char accel[64];
|
|
char t2[2];
|
|
|
|
accel[0] = '\0';
|
|
if (modifiers & GDK_CONTROL_MASK)
|
|
strcat (accel, "<control>");
|
|
if (modifiers & GDK_SHIFT_MASK)
|
|
strcat (accel, "<shift>");
|
|
if (modifiers & GDK_MOD1_MASK)
|
|
strcat (accel, "<alt>");
|
|
|
|
t2[0] = keyval;
|
|
t2[1] = '\0';
|
|
strcat (accel, t2);
|
|
fprintf (fp, " \"%s\"",accel);
|
|
}
|
|
else
|
|
fprintf (fp, " \"\"");
|
|
}
|
|
fprintf (fp,")");
|
|
|
|
if (device_info->is_init)
|
|
{
|
|
if (device_info->brush)
|
|
fprintf (fp, "\n (brush \"%s\")",device_info->brush->name);
|
|
if (device_info->pattern)
|
|
fprintf (fp, "\n (pattern \"%s\")",device_info->pattern->name);
|
|
/* Fixme: hard coded last tool.... see gimprc */
|
|
if (device_info->tool && device_info->tool <= LAST_TOOLBOX_TOOL)
|
|
fprintf (fp, "\n (tool \"%s\")",
|
|
tool_info[device_info->tool].tool_name);
|
|
fprintf (fp, "\n (foreground %d %d %d)",
|
|
device_info->foreground[0],
|
|
device_info->foreground[1],
|
|
device_info->foreground[2]);
|
|
}
|
|
fprintf(fp,")\n");
|
|
|
|
}
|
|
|
|
static void
|
|
devices_write_rc (void)
|
|
{
|
|
char *filename;
|
|
FILE *fp;
|
|
|
|
devices_save_current_info ();
|
|
|
|
filename = gimp_personal_rc_file ("devicerc");
|
|
fp = fopen (filename, "wb");
|
|
g_free (filename);
|
|
|
|
if (!fp)
|
|
return;
|
|
|
|
g_list_foreach (devices_info, (GFunc)devices_write_rc_device, fp);
|
|
|
|
fclose (fp);
|
|
}
|
|
|
|
void
|
|
create_device_status (void)
|
|
{
|
|
GtkWidget *label;
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info;
|
|
int i;
|
|
|
|
if (deviceD == NULL)
|
|
{
|
|
deviceD = g_new (DeviceInfoDialog, 1);
|
|
|
|
deviceD->shell =
|
|
gimp_dialog_new (_("Device Status"), "device_status",
|
|
gimp_standard_help_func,
|
|
"dialogs/device_status_dialog.html",
|
|
GTK_WIN_POS_NONE,
|
|
FALSE, FALSE, TRUE,
|
|
|
|
_("Save"), (GtkSignalFunc) devices_write_rc,
|
|
NULL, NULL, FALSE, FALSE,
|
|
_("Close"), devices_close_callback,
|
|
NULL, NULL, TRUE, TRUE,
|
|
|
|
NULL);
|
|
|
|
/* register this one only */
|
|
dialog_register (deviceD->shell);
|
|
session_set_window_geometry (deviceD->shell, &device_status_session_info,
|
|
FALSE);
|
|
|
|
deviceD->num_devices = 0;
|
|
tmp_list = devices_info;
|
|
while (tmp_list)
|
|
{
|
|
if (((DeviceInfo *)tmp_list->data)->is_present)
|
|
deviceD->num_devices++;
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
/* devices table */
|
|
deviceD->table = gtk_table_new (deviceD->num_devices, 5, FALSE);
|
|
gtk_container_set_border_width (GTK_CONTAINER (deviceD->table), 3);
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (deviceD->shell)->vbox),
|
|
deviceD->table);
|
|
gtk_widget_realize (deviceD->table);
|
|
gtk_widget_show (deviceD->table);
|
|
|
|
deviceD->ids = g_new (guint32, deviceD->num_devices);
|
|
deviceD->frames = g_new (GtkWidget *, deviceD->num_devices);
|
|
deviceD->tools = g_new (GtkWidget *, deviceD->num_devices);
|
|
deviceD->colors = g_new (GtkWidget *, deviceD->num_devices);
|
|
deviceD->brushes = g_new (GtkWidget *, deviceD->num_devices);
|
|
deviceD->patterns = g_new (GtkWidget *, deviceD->num_devices);
|
|
deviceD->eventboxes = g_new (GtkWidget *, deviceD->num_devices);
|
|
|
|
tmp_list = devices_info;
|
|
i=0;
|
|
while (tmp_list)
|
|
{
|
|
if (!((DeviceInfo *)tmp_list->data)->is_present)
|
|
{
|
|
tmp_list = tmp_list->next;
|
|
i++;
|
|
continue;
|
|
}
|
|
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
|
|
deviceD->ids[i] = device_info->device;
|
|
|
|
deviceD->frames[i] = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME(deviceD->frames[i]), GTK_SHADOW_OUT);
|
|
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->frames[i],
|
|
0, 1, i, i+1,
|
|
GTK_FILL, GTK_FILL, 2, 0);
|
|
|
|
label = gtk_label_new (device_info->name);
|
|
gtk_misc_set_padding (GTK_MISC(label), 2, 0);
|
|
gtk_container_add (GTK_CONTAINER(deviceD->frames[i]), label);
|
|
gtk_widget_show(label);
|
|
|
|
deviceD->eventboxes[i] = gtk_event_box_new();
|
|
|
|
deviceD->tools[i] = gtk_pixmap_new (create_tool_pixmap(deviceD->table,
|
|
RECT_SELECT),
|
|
NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (deviceD->eventboxes[i]),deviceD->tools[i]);
|
|
|
|
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->eventboxes[i],
|
|
1, 2, i, i+1,
|
|
0, 0, 2, 2);
|
|
|
|
deviceD->colors[i] = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
gtk_widget_set_events (deviceD->colors[i], PREVIEW_EVENT_MASK);
|
|
gtk_preview_size (GTK_PREVIEW (deviceD->colors[i]), CELL_SIZE, CELL_SIZE);
|
|
/* dnd stuff */
|
|
gtk_drag_source_set (deviceD->colors[i],
|
|
GDK_BUTTON1_MASK,
|
|
color_area_target_table, n_color_area_targets,
|
|
GDK_ACTION_COPY);
|
|
gimp_dnd_color_source_set (deviceD->colors[i], device_status_drag_color,
|
|
GUINT_TO_POINTER (device_info->device));
|
|
gtk_drag_dest_set (deviceD->colors[i],
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
GTK_DEST_DEFAULT_DROP,
|
|
color_area_target_table, n_color_area_targets,
|
|
GDK_ACTION_COPY);
|
|
gimp_dnd_color_dest_set (deviceD->colors[i], device_status_drop_color,
|
|
GUINT_TO_POINTER (device_info->device));
|
|
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->colors[i],
|
|
2, 3, i, i+1,
|
|
0, 0, 2, 2);
|
|
|
|
deviceD->brushes[i] = gimp_context_preview_new (GCP_BRUSH,
|
|
CELL_SIZE, CELL_SIZE,
|
|
FALSE, TRUE, TRUE);
|
|
gtk_drag_dest_set (deviceD->brushes[i],
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
GTK_DEST_DEFAULT_DROP,
|
|
brush_area_target_table, n_brush_area_targets,
|
|
GDK_ACTION_COPY);
|
|
gtk_signal_connect (GTK_OBJECT (deviceD->brushes[i]), "drag_drop",
|
|
GTK_SIGNAL_FUNC (device_status_drop_brush),
|
|
GUINT_TO_POINTER (device_info->device));
|
|
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->brushes[i],
|
|
3, 4, i, i+1,
|
|
0, 0, 2, 2);
|
|
|
|
deviceD->patterns[i] = gimp_context_preview_new (GCP_PATTERN,
|
|
CELL_SIZE, CELL_SIZE,
|
|
FALSE, TRUE, TRUE);
|
|
gtk_drag_dest_set (deviceD->patterns[i],
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
GTK_DEST_DEFAULT_DROP,
|
|
pattern_area_target_table, n_pattern_area_targets,
|
|
GDK_ACTION_COPY);
|
|
gtk_signal_connect (GTK_OBJECT (deviceD->patterns[i]), "drag_drop",
|
|
GTK_SIGNAL_FUNC (device_status_drop_pattern),
|
|
GUINT_TO_POINTER (device_info->device));
|
|
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->patterns[i],
|
|
4, 5, i, i+1,
|
|
0, 0, 2, 2);
|
|
|
|
|
|
if (device_info->is_present)
|
|
device_status_update (device_info->device);
|
|
|
|
|
|
tmp_list = tmp_list->next;
|
|
i++;
|
|
}
|
|
|
|
deviceD->current = 0xffffffff; /* random, but doesn't matter */
|
|
device_status_update_current ();
|
|
|
|
gtk_widget_show (deviceD->shell);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (deviceD->shell), "destroy",
|
|
GTK_SIGNAL_FUNC(device_status_destroy_callback),
|
|
NULL);
|
|
}
|
|
else
|
|
{
|
|
if (!GTK_WIDGET_MAPPED(deviceD->shell))
|
|
gtk_widget_show(deviceD->shell);
|
|
else
|
|
gdk_window_raise(deviceD->shell->window);
|
|
}
|
|
}
|
|
|
|
static void
|
|
device_status_destroy_callback (void)
|
|
{
|
|
g_free(deviceD->ids);
|
|
g_free(deviceD->frames);
|
|
g_free(deviceD->tools);
|
|
g_free(deviceD->eventboxes);
|
|
g_free(deviceD->colors);
|
|
g_free(deviceD->brushes);
|
|
g_free(deviceD->patterns);
|
|
|
|
g_free(deviceD);
|
|
deviceD = NULL;
|
|
}
|
|
|
|
static void
|
|
devices_close_callback (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
gtk_widget_hide (GTK_WIDGET(data));
|
|
}
|
|
|
|
void
|
|
device_status_free (void)
|
|
{
|
|
/* Save device status on exit */
|
|
if(save_device_status)
|
|
devices_write_rc();
|
|
|
|
if (deviceD)
|
|
{
|
|
session_get_window_info (deviceD->shell, &device_status_session_info);
|
|
device_status_destroy_callback ();
|
|
}
|
|
}
|
|
|
|
static void
|
|
device_status_update_current ()
|
|
{
|
|
int i;
|
|
|
|
if (deviceD)
|
|
{
|
|
for (i=0; i<deviceD->num_devices; i++)
|
|
{
|
|
if (deviceD->ids[i] == deviceD->current)
|
|
gtk_frame_set_shadow_type (GTK_FRAME(deviceD->frames[i]),
|
|
GTK_SHADOW_OUT);
|
|
else if (deviceD->ids[i] == current_device)
|
|
gtk_frame_set_shadow_type (GTK_FRAME(deviceD->frames[i]),
|
|
GTK_SHADOW_IN);
|
|
}
|
|
deviceD->current = current_device;
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
device_status_update (guint32 deviceid)
|
|
{
|
|
int i, j;
|
|
guchar buffer[CELL_SIZE*3];
|
|
gchar ttbuf[20]; /* [xxx,xxx,xxx] + null */
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info;
|
|
GdkDeviceInfo *gdk_info;
|
|
|
|
if (deviceD && !suppress_update)
|
|
{
|
|
if (deviceid == current_device)
|
|
{
|
|
devices_save_current_info();
|
|
}
|
|
|
|
tmp_list = devices_info;
|
|
while (tmp_list)
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
|
|
if (device_info->device == deviceid)
|
|
break;
|
|
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
|
|
g_return_if_fail (tmp_list != NULL);
|
|
|
|
tmp_list = gdk_input_list_devices();
|
|
while (tmp_list)
|
|
{
|
|
gdk_info = (GdkDeviceInfo *)tmp_list->data;
|
|
|
|
if (gdk_info->deviceid == deviceid)
|
|
break;
|
|
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
|
|
g_return_if_fail (tmp_list != NULL);
|
|
|
|
for (i=0; i<deviceD->num_devices; i++)
|
|
{
|
|
if (deviceD->ids[i] == deviceid)
|
|
break;
|
|
}
|
|
|
|
g_return_if_fail (i<deviceD->num_devices);
|
|
|
|
if (gdk_info->mode == GDK_MODE_DISABLED)
|
|
{
|
|
gtk_widget_hide (deviceD->frames[i]);
|
|
gtk_widget_hide (deviceD->tools[i]);
|
|
gtk_widget_hide (deviceD->eventboxes[i]);
|
|
gtk_widget_hide (deviceD->colors[i]);
|
|
gtk_widget_hide (deviceD->brushes[i]);
|
|
gtk_widget_hide (deviceD->patterns[i]);
|
|
}
|
|
else
|
|
{
|
|
gtk_widget_show (deviceD->frames[i]);
|
|
|
|
gtk_pixmap_set (GTK_PIXMAP (deviceD->tools[i]),
|
|
create_tool_pixmap (deviceD->table,
|
|
device_info->tool),
|
|
NULL);
|
|
|
|
gtk_widget_draw (deviceD->tools[i], NULL);
|
|
gtk_widget_show (deviceD->tools[i]);
|
|
gtk_widget_show (deviceD->eventboxes[i]);
|
|
|
|
gtk_tooltips_set_tip(tool_tips,deviceD->eventboxes[i],
|
|
tool_info[(int) device_info->tool].tool_desc,
|
|
NULL);
|
|
|
|
if(!device_info->is_init)
|
|
return; /* None of the entries have been set */
|
|
|
|
for (j=0;j<CELL_SIZE*3;j+=3)
|
|
{
|
|
buffer[j] = device_info->foreground[0];
|
|
buffer[j+1] = device_info->foreground[1];
|
|
buffer[j+2] = device_info->foreground[2];
|
|
}
|
|
|
|
for (j=0;j<CELL_SIZE;j++)
|
|
gtk_preview_draw_row (GTK_PREVIEW(deviceD->colors[i]), buffer,
|
|
0, j, CELL_SIZE);
|
|
gtk_widget_draw (deviceD->colors[i], NULL);
|
|
gtk_widget_show (deviceD->colors[i]);
|
|
|
|
/* Set the tip to be the RGB value */
|
|
sprintf(ttbuf,"[%3d,%3d,%3d]",
|
|
device_info->foreground[0],
|
|
device_info->foreground[1],
|
|
device_info->foreground[2]);
|
|
|
|
gtk_tooltips_set_tip(tool_tips, deviceD->colors[i], ttbuf, NULL);
|
|
|
|
if (device_info->brush)
|
|
{
|
|
gimp_context_preview_update (GIMP_CONTEXT_PREVIEW (deviceD->brushes[i]),
|
|
device_info->brush);
|
|
gtk_widget_show (deviceD->brushes[i]);
|
|
}
|
|
if (device_info->pattern)
|
|
{
|
|
gimp_context_preview_update (GIMP_CONTEXT_PREVIEW (deviceD->patterns[i]),
|
|
device_info->pattern);
|
|
gtk_widget_show (deviceD->patterns[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (show_indicators)
|
|
{
|
|
brush_area_update();
|
|
pattern_area_update();
|
|
}
|
|
}
|
|
|
|
|
|
/* dnd stuff */
|
|
static void
|
|
device_status_drag_color (GtkWidget *widget,
|
|
guchar *r,
|
|
guchar *g,
|
|
guchar *b,
|
|
gpointer data)
|
|
{
|
|
guint32 deviceid;
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info = NULL;
|
|
|
|
deviceid = GPOINTER_TO_UINT (data);
|
|
|
|
tmp_list = devices_info;
|
|
while (tmp_list)
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
|
|
if (device_info->device == deviceid)
|
|
break;
|
|
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
|
|
if (device_info)
|
|
{
|
|
*r = device_info->foreground[0];
|
|
*g = device_info->foreground[1];
|
|
*b = device_info->foreground[2];
|
|
}
|
|
else
|
|
{
|
|
*r = *g = *b = 0;
|
|
}
|
|
}
|
|
|
|
static void
|
|
device_status_drop_color (GtkWidget *widget,
|
|
guchar r,
|
|
guchar g,
|
|
guchar b,
|
|
gpointer data)
|
|
{
|
|
guint32 deviceid;
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info = NULL;
|
|
|
|
deviceid = GPOINTER_TO_UINT (data);
|
|
|
|
tmp_list = devices_info;
|
|
while (tmp_list)
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
|
|
if (device_info->device == deviceid)
|
|
break;
|
|
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
if (device_info && device_info->is_present)
|
|
{
|
|
if (device_info->device == current_device)
|
|
{
|
|
palette_set_foreground (r, g, b);
|
|
}
|
|
else
|
|
{
|
|
device_info->foreground[0] = r;
|
|
device_info->foreground[1] = g;
|
|
device_info->foreground[2] = b;
|
|
device_status_update (device_info->device);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void
|
|
device_status_drop_brush (GtkWidget *widget,
|
|
GdkDragContext *context,
|
|
gint x,
|
|
gint y,
|
|
guint time,
|
|
gpointer data)
|
|
{
|
|
GtkWidget *src;
|
|
GimpBrush *brush;
|
|
guint32 deviceid;
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info = NULL;
|
|
|
|
src = gtk_drag_get_source_widget (context);
|
|
if (!GIMP_IS_CONTEXT_PREVIEW (src) || !GIMP_CONTEXT_PREVIEW (src)->data)
|
|
return;
|
|
brush = GIMP_BRUSH (GIMP_CONTEXT_PREVIEW (src)->data);
|
|
deviceid = GPOINTER_TO_UINT (data);
|
|
|
|
tmp_list = devices_info;
|
|
while (tmp_list)
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
|
|
if (device_info->device == deviceid)
|
|
break;
|
|
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
if (device_info && device_info->is_present)
|
|
{
|
|
device_info->brush = brush;
|
|
if (device_info->device == current_device)
|
|
select_brush (device_info->brush);
|
|
else
|
|
device_status_update (device_info->device);
|
|
}
|
|
}
|
|
|
|
static void
|
|
device_status_drop_pattern (GtkWidget *widget,
|
|
GdkDragContext *context,
|
|
gint x,
|
|
gint y,
|
|
guint time,
|
|
gpointer data)
|
|
{
|
|
GtkWidget *src;
|
|
GPattern *pattern;
|
|
guint32 deviceid;
|
|
GList *tmp_list;
|
|
DeviceInfo *device_info = NULL;
|
|
|
|
src = gtk_drag_get_source_widget (context);
|
|
if (!GIMP_IS_CONTEXT_PREVIEW (src) || !GIMP_CONTEXT_PREVIEW (src)->data)
|
|
return;
|
|
pattern = (GPattern *)(GIMP_CONTEXT_PREVIEW (src)->data);
|
|
deviceid = GPOINTER_TO_UINT (data);
|
|
|
|
tmp_list = devices_info;
|
|
while (tmp_list)
|
|
{
|
|
device_info = (DeviceInfo *)tmp_list->data;
|
|
|
|
if (device_info->device == deviceid)
|
|
break;
|
|
|
|
tmp_list = tmp_list->next;
|
|
}
|
|
if (device_info && device_info->is_present)
|
|
{
|
|
device_info->pattern = pattern;
|
|
if (device_info->device == current_device)
|
|
select_pattern (device_info->pattern);
|
|
else
|
|
device_status_update (device_info->device);
|
|
}
|
|
}
|