devices.c 35.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* 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.
 */
18 19 20

#include "config.h"

21
#include <string.h>
Chris Lahey's avatar
Chris Lahey committed
22
#include <stdio.h>
23 24 25

#include "appenv.h"
#include "actionarea.h"
26
#include "gimpbrushlist.h"
27 28 29
#include "devices.h"
#include "interface.h"
#include "gimprc.h"
30
#include "patterns.h"
31
#include "palette.h"
32
#include "session.h"
33
#include "tools.h"
34
#include "dialog_handler.h"
35

36
#include "libgimp/gimpintl.h"
37
#include "libgimp/gimpenv.h"
38

39 40 41 42 43 44 45 46 47 48 49
#define CELL_SIZE 20 /* The size of the preview cells */
#define PREVIEW_EVENT_MASK  GDK_EXPOSURE_MASK | \
                          GDK_BUTTON_PRESS_MASK | \
			  GDK_BUTTON_RELEASE_MASK | \
                          GDK_BUTTON1_MOTION_MASK | \
			  GDK_ENTER_NOTIFY_MASK | \
                          GDK_LEAVE_NOTIFY_MASK

#define BRUSH_PREVIEW 1
#define PATTERN_PREVIEW 2

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
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;

67
  GimpBrushP brush;
68
  GPatternP pattern;
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  ToolType tool;
  unsigned char 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;
87
  GtkWidget **patterns;
88
  GtkWidget **eventboxes;
89 90 91 92 93 94 95

};

/* Local Data */

GList *devices_info = NULL;
DeviceInfoDialog *deviceD = NULL;
96 97 98 99
GtkWidget *device_bpopup = NULL; /* Can't share since differnt depths */
GtkWidget *device_bpreview = NULL;
GtkWidget *device_patpopup = NULL; 
GtkWidget *device_patpreview = NULL;
100 101 102 103 104 105 106 107 108 109 110 111 112
/* 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 ();
113 114
static gint brush_preview_events (GtkWidget *, GdkEvent *, int);
static gint pattern_preview_events (GtkWidget *, GdkEvent *, int);
115 116 117 118 119 120 121

/* Global data */
int current_device = GDK_CORE_POINTER;

/*  the action area structure  */
static ActionAreaItem action_items[] =
{
122
  { N_("Save"), (ActionCallback)devices_write_rc, NULL, NULL },
123
  { N_("Close"), devices_close_callback, NULL, NULL }
124 125 126 127 128 129
};

void 
create_input_dialog (void)
{
  static GtkWidget *inputd = NULL;
Michael Natterer's avatar
Michael Natterer committed
130
  GtkWidget        *hbbox;
131 132 133 134

  if (!inputd)
    {
      inputd = gtk_input_dialog_new();
135 136 137 138

      /* register this one only */
      dialog_register(inputd);

Michael Natterer's avatar
Michael Natterer committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
      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);
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220

      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);
      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 *w, guint32 deviceid, gpointer data)
{
  device_status_update (deviceid);
}

static void
input_dialog_destroy_callback (GtkWidget *w, 
			       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;
221
      device_info->pattern = NULL;
222 223 224 225 226 227 228 229 230
      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;
    }
231 232 233 234 235
}

void
devices_restore()
{  
236
  char *filename;
237 238 239
  GList *tmp_list;
  DeviceInfo *device_info;

240
  /* Augment with information from rc file */
241 242 243
  filename = gimp_personal_rc_file ("devicerc");
  parse_gimprc_file (filename);
  g_free (filename);
244 245 246 247 248 249 250 251 252 253 254 255 256

  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;
    }

257
  g_return_if_fail (device_info != NULL);
258

259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
  suppress_update = TRUE;

  if (device_info->is_init)
    {
      if (device_info->brush)
	select_brush (device_info->brush);
      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->pattern)
	select_pattern(device_info->pattern);
    }
  
  suppress_update = FALSE;
276 277 278 279 280 281 282
}

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,
283
		   guchar foreground[],gchar *pattern_name)
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
{
  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;
333
      device_info->pattern = NULL;
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
      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
	{
377
	  g_warning (_("devices_rc_update called multiple times for not present device\n"));
378 379 380 381
	  return;
	}
    }

382
  if (values & (DEVICE_PATTERN | DEVICE_BRUSH | DEVICE_TOOL | DEVICE_FOREGROUND))
383 384
    device_info->is_init = TRUE;

385

386 387
  if (values & DEVICE_BRUSH)
    {
388
      device_info->brush = gimp_brush_list_get_brush(brush_list, brush_name);
389 390
    }

391 392 393 394 395
  if (values & DEVICE_PATTERN)
    {
      device_info->pattern = pattern_list_get_pattern(pattern_list,pattern_name);
    }

396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
  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)
    {
      if (device_info->brush)
	select_brush (device_info->brush);
439
      gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
440 441 442
      palette_set_foreground (device_info->foreground[0], 
			      device_info->foreground[1], 
			      device_info->foreground[2]);
443 444
      if (device_info->pattern)
	select_pattern(device_info->pattern);
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
    }

  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 ();
503
  device_info->pattern = get_active_pattern();
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
  if (active_tool_type >= 0)
    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;
	}
      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)
    {
623 624 625 626
      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);
627 628
      /* Fixme: hard coded last tool....  see gimprc */
      if (device_info->tool && device_info->tool <= LAST_TOOLBOX_TOOL)
629
        fprintf(fp, "\n        (tool \"%s\")",
630 631 632 633 634 635 636 637 638 639 640 641 642
	      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)
{
643
  char *filename;
644 645
  FILE *fp;

646 647
  devices_save_current_info ();

648 649 650
  filename = gimp_personal_rc_file ("devicerc");
  fp = fopen (filename, "wb");
  g_free (filename);
651

652 653
  if (!fp)
    return;
654

655
  g_list_foreach (devices_info, (GFunc)devices_write_rc_device, fp);
656

657
  fclose (fp);
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
}

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 = gtk_dialog_new ();

673 674 675
      /* register this one only */
      dialog_register(deviceD->shell);

676
      gtk_window_set_title (GTK_WINDOW(deviceD->shell), _("Device Status"));
677
      gtk_window_set_policy (GTK_WINDOW (deviceD->shell), FALSE, FALSE, TRUE);
678 679 680 681 682
      /*  don't set the dialog's size, as the number of devices may have
       *  changed since the last session
       */
      session_set_window_geometry (deviceD->shell,
				   &device_status_session_info, FALSE);
683 684 685 686 687 688 689 690 691 692

      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;
	}

693
      deviceD->table = gtk_table_new (deviceD->num_devices, 5, FALSE);
694 695 696 697 698 699 700 701 702 703 704
      gtk_container_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);
705
      deviceD->patterns = g_new (GtkWidget *, deviceD->num_devices);
706
      deviceD->eventboxes = g_new (GtkWidget *, deviceD->num_devices);
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734

      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);

735 736
	  deviceD->eventboxes[i] = gtk_event_box_new();

737 738 739
	  deviceD->tools[i] = gtk_pixmap_new (create_tool_pixmap(deviceD->table,
								 RECT_SELECT),
					      NULL);
740 741 742 743

	  gtk_container_add (GTK_CONTAINER (deviceD->eventboxes[i]),deviceD->tools[i]);

	  gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->eventboxes[i],
744 745 746 747
			    1, 2, i, i+1,
			    0, 0, 2, 2);

	  deviceD->colors[i] = gtk_preview_new (GTK_PREVIEW_COLOR);
748
	  gtk_widget_set_events (deviceD->colors[i], PREVIEW_EVENT_MASK);
749
	  gtk_preview_size (GTK_PREVIEW (deviceD->colors[i]), CELL_SIZE, CELL_SIZE);
750 751 752 753
	  gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->colors[i],
			    2, 3, i, i+1,
			    0, 0, 2, 2);

754 755 756 757 758 759 760
	  deviceD->brushes[i] = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
          gtk_preview_size (GTK_PREVIEW (deviceD->brushes[i]), CELL_SIZE, CELL_SIZE); 
	  gtk_widget_set_events (deviceD->brushes[i], PREVIEW_EVENT_MASK);
	  gtk_signal_connect (GTK_OBJECT (deviceD->brushes[i]), "event",
			      (GtkSignalFunc) brush_preview_events,
			      (gpointer)i);

761 762 763 764
	  gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->brushes[i],
			    3, 4, i, i+1,
			    0, 0, 2, 2);

765 766 767 768 769 770 771 772 773 774 775 776 777

	  deviceD->patterns[i] = gtk_preview_new (GTK_PREVIEW_COLOR);
          gtk_preview_size (GTK_PREVIEW (deviceD->patterns[i]), CELL_SIZE, CELL_SIZE); 
	  gtk_widget_set_events (deviceD->patterns[i], PREVIEW_EVENT_MASK);
	  gtk_signal_connect (GTK_OBJECT (deviceD->patterns[i]), "event",
			      (GtkSignalFunc) pattern_preview_events,
			      (gpointer)i);

	  gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->patterns[i],
			    4, 5, i, i+1,
			    0, 0, 2, 2);


778 779 780 781 782 783 784 785
	  if (device_info->is_present)
	    device_status_update (device_info->device);

	  
	  tmp_list = tmp_list->next;
	  i++;
	}

786 787
      action_items[1].user_data = deviceD->shell;
      build_action_area (GTK_DIALOG (deviceD->shell), action_items, 2, 1);
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812

      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);
813
  g_free(deviceD->eventboxes);
814 815
  g_free(deviceD->colors);
  g_free(deviceD->brushes);
816
  g_free(deviceD->patterns);
817 818 819 820 821 822 823 824 825 826 827 828

  g_free(deviceD);
  deviceD = NULL;
}

static void
devices_close_callback (GtkWidget *w,
			gpointer data)
{
  gtk_widget_hide (GTK_WIDGET(data));
}

829 830 831
void
device_status_free (void)
{                                     
832 833 834 835
  /* Save device status on exit */
  if(save_device_status)
    devices_write_rc();

836 837 838 839 840 841 842
  if (deviceD)
    {
      session_get_window_info (deviceD->shell, &device_status_session_info);
      device_status_destroy_callback (); 
    }
}

843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
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;
    }
}

863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
static void
brush_popup_open (int preview_id,
		  int          x,
		  int          y,
		  GimpBrushP   brush)
{
  gint x_org, y_org;
  gint scr_w, scr_h;
  gchar *src, *buf;

  /* make sure the popup exists and is not visible */
  if (device_bpopup == NULL)
    {
      GtkWidget *frame;

      device_bpopup = gtk_window_new (GTK_WINDOW_POPUP);
      gtk_window_set_policy (GTK_WINDOW (device_bpopup), FALSE, FALSE, TRUE);

      frame = gtk_frame_new (NULL);
      gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
      gtk_container_add (GTK_CONTAINER (device_bpopup), frame);
      gtk_widget_show (frame);
      device_bpreview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
      gtk_container_add (GTK_CONTAINER (frame), device_bpreview);
      gtk_widget_show (device_bpreview);
    }
  else
    {
      gtk_widget_hide (device_bpopup);
    }

  /* decide where to put the popup */
  gdk_window_get_origin (deviceD->brushes[preview_id]->window, &x_org, &y_org);
  scr_w = gdk_screen_width ();
  scr_h = gdk_screen_height ();
  x = x_org + x - (brush->mask->width >> 1);
  y = y_org + y - (brush->mask->height >> 1);
  x = (x < 0) ? 0 : x;
  y = (y < 0) ? 0 : y;
  x = (x + brush->mask->width > scr_w) ? scr_w - brush->mask->width : x;
  y = (y + brush->mask->height > scr_h) ? scr_h - brush->mask->height : y;
  gtk_preview_size (GTK_PREVIEW (device_bpreview), brush->mask->width, brush->mask->height);

  gtk_widget_popup (device_bpopup, x, y);
  
  /*  Draw the brush  */
  buf = g_new (gchar, brush->mask->width);
  src = (gchar *)temp_buf_data (brush->mask);
  for (y = 0; y < brush->mask->height; y++)
    {
      /*  Invert the mask for display.  We're doing this because
       *  a value of 255 in the  mask means it is full intensity.
       *  However, it makes more sense for full intensity to show
       *  up as black in this brush preview window...
       */
      for (x = 0; x < brush->mask->width; x++)
	buf[x] = 255 - src[x];
      gtk_preview_draw_row (GTK_PREVIEW (device_bpreview), (guchar *)buf, 0, y, brush->mask->width);
      src += brush->mask->width;
    }
  g_free(buf);
  
  /*  Draw the brush preview  */
  gtk_widget_draw (device_bpreview, NULL);
}

static void
pattern_popup_open (int preview_id,
		  int          x,
		  int          y,
		  GPatternP   pattern)
{
  gint x_org, y_org;
  gint scr_w, scr_h;
  gchar *src, *buf;

  /* make sure the popup exists and is not visible */
  if (device_patpopup == NULL)
    {
      GtkWidget *frame;

      device_patpopup = gtk_window_new (GTK_WINDOW_POPUP);
      gtk_window_set_policy (GTK_WINDOW (device_patpopup), FALSE, FALSE, TRUE);

      frame = gtk_frame_new (NULL);
      gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
      gtk_container_add (GTK_CONTAINER (device_patpopup), frame);
      gtk_widget_show (frame);
      device_patpreview = gtk_preview_new (GTK_PREVIEW_COLOR);
      gtk_container_add (GTK_CONTAINER (frame), device_patpreview);
      gtk_widget_show (device_patpreview);
    }
  else
    {
      gtk_widget_hide (device_patpopup);
    }

  /* decide where to put the popup */
  gdk_window_get_origin (deviceD->patterns[preview_id]->window, &x_org, &y_org);
  scr_w = gdk_screen_width ();
  scr_h = gdk_screen_height ();
  x = x_org + x - (pattern->mask->width >> 1);
  y = y_org + y - (pattern->mask->height >> 1);
  x = (x < 0) ? 0 : x;
  y = (y < 0) ? 0 : y;
  x = (x + pattern->mask->width > scr_w) ? scr_w - pattern->mask->width : x;
  y = (y + pattern->mask->height > scr_h) ? scr_h - pattern->mask->height : y;
  gtk_preview_size (GTK_PREVIEW (device_patpreview), pattern->mask->width, pattern->mask->height);

  gtk_widget_popup (device_patpopup, x, y);
  
  /*  Draw the pattern  */
  buf = g_new (gchar, pattern->mask->width * 3);
  src = (gchar *)temp_buf_data (pattern->mask);
  for (y = 0; y < pattern->mask->height; y++)
    {
      if (pattern->mask->bytes == 1)
	for (x = 0; x < pattern->mask->width; x++)
	  {
	    buf[x*3+0] = src[x];
	    buf[x*3+1] = src[x];
	    buf[x*3+2] = src[x];
	  }
      else
	for (x = 0; x < pattern->mask->width; x++)
	  {
	    buf[x*3+0] = src[x*3+0];
	    buf[x*3+1] = src[x*3+1];
	    buf[x*3+2] = src[x*3+2];
	  }
      gtk_preview_draw_row (GTK_PREVIEW (device_patpreview), (guchar *)buf, 0, y, pattern->mask->width);
      src += pattern->mask->width * pattern->mask->bytes;
    }
  g_free(buf);
  
  /*  Draw the brush preview  */
  gtk_widget_draw (device_patpreview, NULL);
}

static void
device_popup_close (int type)
{
  if(type == BRUSH_PREVIEW)
    {
      if (device_bpopup != NULL)
	gtk_widget_hide (device_bpopup);
    }
  else if (type == PATTERN_PREVIEW)
    {
      if (device_patpopup != NULL)
	gtk_widget_hide (device_patpopup);
    }
}

static gint 
device_preview_events (GtkWidget    *widget,
		       GdkEvent     *event,
		       int deviceid,
		       int type)
{
  GList *tmp_list;
  DeviceInfo *device_info;
  GdkEventButton *bevent;
  GimpBrushP brush;
  GPatternP pattern;

  switch (event->type)
    {
    case GDK_EXPOSE:
      break;

    case GDK_BUTTON_PRESS:
      bevent = (GdkEventButton *) event;

      if (bevent->button == 1)
	{
	  tmp_list = devices_info;
	  while (tmp_list)
	    {
	      device_info = (DeviceInfo *)tmp_list->data;
	      
	      if (device_info->device == deviceD->ids[deviceid])
		break;
	      
	      tmp_list = tmp_list->next;
	    }

	  if(tmp_list == NULL)
	    {
1052
	      g_message(_("Failed to find device_info\n"));
1053 1054 1055
	      break; /* Error no device info */
	    }
	    
Michael Natterer's avatar
Michael Natterer committed
1056 1057 1058 1059 1060 1061 1062
	  /*  Grab the pointer  */
	  gdk_pointer_grab (widget->window, FALSE,
			    (GDK_POINTER_MOTION_HINT_MASK |
			     GDK_BUTTON1_MOTION_MASK |
			     GDK_BUTTON_RELEASE_MASK),
			    NULL, NULL, bevent->time);

1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
	  if(type == BRUSH_PREVIEW)
	    {
	      brush = device_info->brush;
	      
	      /*  Show the brush popup window if the brush is too large  */
	      if (brush->mask->width > CELL_SIZE ||
		  brush->mask->height > CELL_SIZE)
		brush_popup_open (deviceid, bevent->x, bevent->y, brush);
	    }
	  else if(type == PATTERN_PREVIEW)
	    {
	      pattern = device_info->pattern;
	      
1076
	      /*  Show the pattern popup window if the pattern is too large  */
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
	      if (pattern->mask->width > CELL_SIZE ||
		  pattern->mask->height > CELL_SIZE)
		pattern_popup_open (deviceid, bevent->x, bevent->y, pattern);
	    }
	}
      break;

    case GDK_BUTTON_RELEASE:
      bevent = (GdkEventButton *) event;

      if (bevent->button == 1)
	{
	  /*  Ungrab the pointer  */
	  gdk_pointer_ungrab (bevent->time);

	  /*  Close the device preview popup window  */
	  device_popup_close (type);
	}
      break;
    case GDK_DELETE:
      break;

    default:
      break;
    }

  return FALSE;
}

static gint
brush_preview_events (GtkWidget    *widget,
		     GdkEvent     *event,
		     int deviceid)
{
  return(device_preview_events(widget,event,deviceid,BRUSH_PREVIEW));
}

static gint
pattern_preview_events (GtkWidget    *widget,
		     GdkEvent     *event,
		     int deviceid)
{
  return(device_preview_events(widget,event,deviceid,PATTERN_PREVIEW));
}

static void
device_update_brush(GimpBrushP brush,int preview_id)
{
  guchar buffer[CELL_SIZE]; 
  TempBuf * brush_buf;
  unsigned char * src, *s = NULL;
  unsigned char *b;
  int width,height;
  int offset_x, offset_y;
  int yend;
  int ystart;
  int i, j;

  /* Set the tip to be the name of the brush */
  gtk_tooltips_set_tip(tool_tips,deviceD->brushes[preview_id],brush->name,NULL);

  brush_buf = brush->mask;

  /*  Get the pointer into the brush mask data  */
  src = mask_buf_data (brush_buf);

  /* Limit to cell size */
  width = (brush_buf->width > CELL_SIZE) ? CELL_SIZE: brush_buf->width;
  height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;

  /* Set buffer to white */  
  memset(buffer, 255, sizeof(buffer));
  for (i = 0; i < CELL_SIZE; i++)
    gtk_preview_draw_row (GTK_PREVIEW(deviceD->brushes[preview_id]), buffer, 0, i, CELL_SIZE);

  offset_x = ((CELL_SIZE - width) >> 1);
  offset_y = ((CELL_SIZE - height) >> 1);

  ystart = BOUNDS (offset_y, 0, CELL_SIZE);
  yend = BOUNDS (offset_y + height, 0, CELL_SIZE);

  for (i = ystart; i < yend; i++)
    {
      /*  Invert the mask for display.  We're doing this because
       *  a value of 255 in the  mask means it is full intensity.
       *  However, it makes more sense for full intensity to show
       *  up as black in this brush preview window...
       */
      s = src;
      b = buffer;
      for (j = 0; j < width ; j++)
	*b++ = 255 - *s++;

      gtk_preview_draw_row (GTK_PREVIEW(deviceD->brushes[preview_id]), 
			    buffer, 
			    offset_x, i, width);

      src += brush_buf->width;
    }
}

static void
device_update_pattern(GPatternP pattern,int preview_id)
{
1181
  guchar *buffer = NULL; 
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
  TempBuf * pattern_buf;
  unsigned char * src, *s = NULL;
  unsigned char *b;
  int rowstride;
  int width,height;
  int offset_x, offset_y;
  int yend;
  int ystart;
  int i, j;

  /* Set the tip to be the name of the brush */
  gtk_tooltips_set_tip(tool_tips,deviceD->patterns[preview_id],pattern->name,NULL);

1195
  buffer = g_new (guchar, pattern->mask->width * 3);
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
  pattern_buf = pattern->mask;

  /* Limit to cell size */
  width = (pattern_buf->width > CELL_SIZE) ? CELL_SIZE: pattern_buf->width;
  height = (pattern_buf->height > CELL_SIZE) ? CELL_SIZE: pattern_buf->height;

  /* Set buffer to white */  
  memset(buffer, 255, sizeof(buffer));
  for (i = 0; i < CELL_SIZE; i++)
    gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]), buffer, 0, i, CELL_SIZE);

  offset_x = ((CELL_SIZE - width) >> 1);
  offset_y = ((CELL_SIZE - height) >> 1);

  ystart = BOUNDS (offset_y, 0, CELL_SIZE);
  yend = BOUNDS (offset_y + height, 0, CELL_SIZE);

  /*  Get the pointer into the brush mask data  */
  rowstride = pattern_buf->width * pattern_buf->bytes;
  src = mask_buf_data (pattern_buf)  + (ystart - offset_y) * rowstride;

  for (i = ystart; i < yend; i++)
    {
      /*  Invert the mask for display.  We're doing this because
       *  a value of 255 in the  mask means it is full intensity.
       *  However, it makes more sense for full intensity to show
       *  up as black in this brush preview window...
       */
      s = src;
      b = buffer;

      if (pattern_buf->bytes == 1)
	for (j = 0; j < width; j++)
	  {
	    *b++ = *s;
	    *b++ = *s;
	    *b++ = *s++;
	  }
      else
	for (j = 0; j < width; j++)
	  {
	    *b++ = *s++;
	    *b++ = *s++;
	    *b++ = *s++;
	  }

      gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]), 
			    buffer, 
			    offset_x, i, width);

      src += rowstride;
    }
  g_free(buffer);
}

1251 1252 1253 1254
void 
device_status_update (guint32 deviceid)
{
  int i, j;
1255
  guchar buffer[CELL_SIZE*3];
1256
  gchar ttbuf[20]; /* [xxx,xxx,xxx] + null */
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
  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]);
1306
	  gtk_widget_hide (deviceD->eventboxes[i]);
1307 1308
	  gtk_widget_hide (deviceD->colors[i]);
	  gtk_widget_hide (deviceD->brushes[i]);
1309
	  gtk_widget_hide (deviceD->patterns[i]);
1310 1311 1312 1313 1314 1315 1316 1317 1318
	}
      else
	{
	  gtk_widget_show (deviceD->frames[i]);

	  gtk_pixmap_set (GTK_PIXMAP (deviceD->tools[i]),
			  create_tool_pixmap (deviceD->table, 
					      device_info->tool),
			  NULL);
1319
	  
1320
	  gtk_widget_draw (deviceD->tools[i], NULL);
1321
	  gtk_widget_show (deviceD->tools[i]);
1322
	  gtk_widget_show (deviceD->eventboxes[i]);
1323
	  
1324 1325 1326 1327 1328 1329 1330
	  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 */

1331
	  for (j=0;j<CELL_SIZE*3;j+=3)
1332 1333 1334 1335 1336 1337
	    {
	      buffer[j] = device_info->foreground[0];
	      buffer[j+1] = device_info->foreground[1];
	      buffer[j+2] = device_info->foreground[2];
	    }
	  
1338
	  for (j=0;j<CELL_SIZE;j++)
1339
	    gtk_preview_draw_row (GTK_PREVIEW(deviceD->colors[i]), buffer, 
1340
				  0, j, CELL_SIZE);
1341 1342 1343
	  gtk_widget_draw (deviceD->colors[i], NULL);
	  gtk_widget_show (deviceD->colors[i]);

1344 1345 1346 1347 1348 1349 1350 1351 1352
	  /* 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);


1353 1354
	  device_update_brush(device_info->brush,i);
	  gtk_widget_draw (deviceD->brushes[i],NULL);
1355
	  gtk_widget_show (deviceD->brushes[i]);
1356 1357 1358 1359

	  device_update_pattern(device_info->pattern,i);
	  gtk_widget_draw (deviceD->patterns[i],NULL);
	  gtk_widget_show (deviceD->patterns[i]);
1360 1361 1362
	}
    }
}
1363 1364 1365 1366