gimppropwidgets.c 76.2 KB
Newer Older
1 2 3
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
 *
4 5 6
 * gimppropwidgets.c
 * Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
 *
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

Hans Breuer's avatar
Hans Breuer committed
24 25
#include <string.h>

26 27 28 29 30 31 32 33 34
#include <gtk/gtk.h>

#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "widgets-types.h"

#include "config/gimpconfig-params.h"
Sven Neumann's avatar
Sven Neumann committed
35
#include "config/gimpconfig-path.h"
36

37 38
#include "core/gimpviewable.h"

39
#include "gimpcolorpanel.h"
40
#include "gimpdnd.h"
41
#include "gimpenummenu.h"
42
#include "gimpfontselection.h"
43
#include "gimppreview.h"
44
#include "gimppropwidgets.h"
45
#include "gimpwidgets-constructors.h"
46

47
#include "gimp-intl.h"
48 49


50 51 52
/*  utility function prototypes  */

static void         set_param_spec   (GObject     *object,
53 54
                                      GtkWidget   *widget,
                                      GParamSpec  *param_spec);
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
static GParamSpec * get_param_spec   (GObject     *object);

static GParamSpec * find_param_spec  (GObject     *object,
                                      const gchar *property_name,
                                      const gchar *strloc);
static GParamSpec * check_param_spec (GObject     *object,
                                      const gchar *property_name,
                                      GType        type,
                                      const gchar *strloc);

static void         connect_notify   (GObject     *config,
                                      const gchar *property_name,
                                      GCallback    callback,
                                      gpointer     callback_data);


71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/******************/
/*  check button  */
/******************/

static void   gimp_prop_check_button_callback (GtkWidget  *widget,
                                               GObject    *config);
static void   gimp_prop_check_button_notify   (GObject    *config,
                                               GParamSpec *param_spec,
                                               GtkWidget  *button);

GtkWidget *
gimp_prop_check_button_new (GObject     *config,
                            const gchar *property_name,
                            const gchar *label)
{
86 87 88
  GParamSpec  *param_spec;
  GtkWidget   *button;
  gboolean     value;
89

90 91
  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_BOOLEAN, G_STRLOC);
92
  if (! param_spec)
93
    return NULL;
94 95 96 97 98

  g_object_get (config,
                property_name, &value,
                NULL);

99
  button = gtk_check_button_new_with_mnemonic (label);
100 101
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), value);

102
  set_param_spec (G_OBJECT (button), button, param_spec);
103

104
  g_signal_connect (button, "toggled",
105 106 107
		    G_CALLBACK (gimp_prop_check_button_callback),
		    config);

108 109 110
  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_check_button_notify),
                  button);
111 112 113 114 115 116 117 118 119 120

  return button;
}

static void
gimp_prop_check_button_callback (GtkWidget *widget,
                                 GObject   *config)
{
  GParamSpec *param_spec;

121
  param_spec = get_param_spec (G_OBJECT (widget));
122 123 124 125 126 127
  if (! param_spec)
    return;

  g_object_set (config,
                param_spec->name, GTK_TOGGLE_BUTTON (widget)->active,
                NULL);
128 129

  gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (widget));
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
}

static void
gimp_prop_check_button_notify (GObject    *config,
                               GParamSpec *param_spec,
                               GtkWidget  *button)
{
  gboolean value;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

  if (GTK_TOGGLE_BUTTON (button)->active != value)
    {
145
      g_signal_handlers_block_by_func (button,
146 147 148 149
                                       gimp_prop_check_button_callback,
                                       config);

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), value);
150
      gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (button));
151

152
      g_signal_handlers_unblock_by_func (button,
153 154 155 156 157 158
                                         gimp_prop_check_button_callback,
                                         config);
    }
}


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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
static void   gimp_prop_enum_check_button_callback (GtkWidget  *widget,
                                                    GObject    *config);
static void   gimp_prop_enum_check_button_notify   (GObject    *config,
                                                    GParamSpec *param_spec,
                                                    GtkWidget  *button);

GtkWidget *
gimp_prop_enum_check_button_new (GObject     *config,
                                 const gchar *property_name,
                                 const gchar *label,
                                 gint         false_value,
                                 gint         true_value)
{
  GParamSpec  *param_spec;
  GtkWidget   *button;
  gint        value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_ENUM, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

  button = gtk_check_button_new_with_mnemonic (label);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), value == true_value);

  if (value != false_value && value != true_value)
    gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);

  set_param_spec (G_OBJECT (button), button, param_spec);

  g_object_set_data (G_OBJECT (button), "false-value",
                     GINT_TO_POINTER (false_value));
  g_object_set_data (G_OBJECT (button), "true-value",
                     GINT_TO_POINTER (true_value));

  g_signal_connect (button, "toggled",
		    G_CALLBACK (gimp_prop_enum_check_button_callback),
		    config);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_enum_check_button_notify),
                  button);

  return button;
}

static void
gimp_prop_enum_check_button_callback (GtkWidget *widget,
                                      GObject   *config)
{
  GParamSpec *param_spec;
  gint        false_value;
  gint        true_value;

  param_spec = get_param_spec (G_OBJECT (widget));
  if (! param_spec)
    return;

  false_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
                                                    "false-value"));
  true_value  = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
                                                    "true-value"));

  g_object_set (config,
                param_spec->name,
                GTK_TOGGLE_BUTTON (widget)->active ? true_value : false_value,
                NULL);

  gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (widget), FALSE);

  gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (widget));
}

static void
gimp_prop_enum_check_button_notify (GObject    *config,
                                    GParamSpec *param_spec,
                                    GtkWidget  *button)
{
  gint     value;
  gint     false_value;
  gint     true_value;
  gboolean active       = FALSE;
  gboolean inconsistent = FALSE;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

  false_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
                                                    "false-value"));
  true_value  = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
                                                    "true-value"));

  if (value == true_value)
    active = TRUE;
  else if (value != false_value)
    inconsistent = TRUE;

  gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button),
                                      inconsistent);

  if (GTK_TOGGLE_BUTTON (button)->active != active)
    {
      g_signal_handlers_block_by_func (button,
                                       gimp_prop_enum_check_button_callback,
                                       config);

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active);
      gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (button));

      g_signal_handlers_unblock_by_func (button,
                                         gimp_prop_enum_check_button_callback,
                                         config);
    }
}


280 281 282 283
/******************/
/*  option menus  */
/******************/

284 285 286 287 288
static void   gimp_prop_option_menu_callback (GtkWidget   *widget,
                                              GObject     *config);
static void   gimp_prop_option_menu_notify   (GObject     *config,
                                              GParamSpec  *param_spec,
                                              GtkWidget   *menu);
289

290 291 292 293 294 295 296
GtkWidget *
gimp_prop_boolean_option_menu_new (GObject     *config,
                                   const gchar *property_name,
                                   const gchar *true_text,
                                   const gchar *false_text)
{
  GParamSpec *param_spec;
297
  GtkWidget  *menu;
298 299 300 301 302 303 304 305 306 307 308
  gboolean    value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_BOOLEAN, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

309 310 311 312 313 314 315 316 317
  menu = gimp_option_menu_new2 (FALSE,
                                G_CALLBACK (gimp_prop_option_menu_callback),
                                config,
                                GINT_TO_POINTER (value),
                                
                                true_text,  GINT_TO_POINTER (TRUE),  NULL,
                                false_text, GINT_TO_POINTER (FALSE), NULL,
                                
                                NULL);
318

319
  set_param_spec (G_OBJECT (menu), menu, param_spec);
320 321 322

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_option_menu_notify),
323
                  menu);
324

325
  return menu;
326 327
}

328 329 330 331 332 333 334
GtkWidget *
gimp_prop_enum_option_menu_new (GObject     *config,
                                const gchar *property_name,
                                gint         minimum,
                                gint         maximum)
{
  GParamSpec *param_spec;
335
  GtkWidget  *menu;
336 337
  gint        value;

338 339
  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_ENUM, G_STRLOC);
340
  if (! param_spec)
341
    return NULL;
342 343 344 345 346

  g_object_get (config,
                property_name, &value,
                NULL);

347
  if (minimum != maximum)
348
    {
349 350 351 352
      menu = gimp_enum_option_menu_new_with_range (param_spec->value_type,
                                                   minimum, maximum,
                                                   G_CALLBACK (gimp_prop_option_menu_callback),
                                                   config);
353 354 355
    }
  else
    {
356 357 358
      menu = gimp_enum_option_menu_new (param_spec->value_type,
                                        G_CALLBACK (gimp_prop_option_menu_callback),
                                        config);
359 360
    }

361
  gimp_option_menu_set_history (GTK_OPTION_MENU (menu),
362 363
                                GINT_TO_POINTER (value));

364
  set_param_spec (G_OBJECT (menu), menu, param_spec);
365

366 367
  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_option_menu_notify),
368
                  menu);
369

370
  return menu;
371 372
}

373 374 375 376 377 378
GtkWidget *
gimp_prop_paint_mode_menu_new (GObject     *config,
                               const gchar *property_name,
                               gboolean     with_behind_mode)
{
  GParamSpec *param_spec;
379
  GtkWidget  *menu;
380 381 382 383 384 385 386 387 388 389 390
  gint        value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_ENUM, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

391 392 393 394
  menu = gimp_paint_mode_menu_new (G_CALLBACK (gimp_prop_option_menu_callback),
                                   config,
                                   with_behind_mode,
                                   value);
395

396
  set_param_spec (G_OBJECT (menu), menu, param_spec);
397 398 399

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_option_menu_notify),
400
                  menu);
401

402
  return menu;
403 404
}

405
static void
406 407
gimp_prop_option_menu_callback (GtkWidget *widget,
                                GObject   *config)
408 409 410
{
  if (GTK_IS_MENU (widget->parent))
    {
411
      GtkWidget *menu;
412

413
      menu = gtk_menu_get_attach_widget (GTK_MENU (widget->parent));
414

415
      if (menu)
416 417
        {
          GParamSpec *param_spec;
418
          gint        value;
419

420
          param_spec = get_param_spec (G_OBJECT (menu));
421 422
          if (! param_spec)
            return;
423

424 425
          value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
                                                      "gimp-item-data"));
426

427 428 429
          g_object_set (config,
                        param_spec->name, value,
                        NULL);
430 431 432 433 434
        }
    }
}

static void
435 436 437
gimp_prop_option_menu_notify (GObject    *config,
                              GParamSpec *param_spec,
                              GtkWidget  *menu)
438 439 440 441 442 443 444 445 446 447 448 449
{
  gint value;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

  gimp_option_menu_set_history (GTK_OPTION_MENU (menu),
                                GINT_TO_POINTER (value));
}


450 451 452
/*****************/
/*  radio boxes  */
/*****************/
453 454 455 456 457 458 459 460

static void  gimp_prop_radio_button_callback (GtkWidget   *widget,
                                              GObject     *config);
static void  gimp_prop_radio_button_notify   (GObject     *config,
                                              GParamSpec  *param_spec,
                                              GtkWidget   *button);


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 503 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
GtkWidget *
gimp_prop_enum_radio_frame_new (GObject     *config,
                                const gchar *property_name,
                                const gchar *label,
                                gint         minimum,
                                gint         maximum)
{
  GParamSpec *param_spec;
  GtkWidget  *frame;
  GtkWidget  *button;
  gint        value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_ENUM, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

  if (minimum != maximum)
    {
      frame = gimp_enum_radio_frame_new_with_range (param_spec->value_type,
                                                    minimum, maximum,
                                                    gtk_label_new (label),
                                                    2,
                                                    G_CALLBACK (gimp_prop_radio_button_callback),
                                                    config,
                                                    &button);
    }
  else
    {
      frame = gimp_enum_radio_frame_new (param_spec->value_type,
                                         gtk_label_new (label),
                                         2,
                                         G_CALLBACK (gimp_prop_radio_button_callback),
                                         config,
                                         &button);
    }

  gimp_radio_group_set_active (GTK_RADIO_BUTTON (button),
                               GINT_TO_POINTER (value));

  set_param_spec (G_OBJECT (GTK_BIN (frame)->child), NULL, param_spec);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_radio_button_notify),
                  button);

  return frame;
}

GtkWidget *
gimp_prop_boolean_radio_frame_new (GObject     *config,
                                   const gchar *property_name,
                                   const gchar *title,
                                   const gchar *true_text,
                                   const gchar *false_text)
{
  GParamSpec *param_spec;
  GtkWidget  *frame;
  GtkWidget  *button;
  gboolean    value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_BOOLEAN, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

  frame = gimp_radio_group_new2 (TRUE, title,
                                 G_CALLBACK (gimp_prop_radio_button_callback),
                                 config,
                                 GINT_TO_POINTER (value),

                                 false_text, GINT_TO_POINTER (FALSE), &button,
                                 true_text,  GINT_TO_POINTER (TRUE),  NULL,

                                 NULL);

  set_param_spec (G_OBJECT (GTK_BIN (frame)->child), NULL, param_spec);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_radio_button_notify),
                  button);

  return frame;
}

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
GtkWidget *
gimp_prop_enum_stock_box_new (GObject     *config,
                              const gchar *property_name,
                              const gchar *stock_prefix,
                              gint         minimum,
                              gint         maximum)
{
  GParamSpec *param_spec;
  GtkWidget  *box;
  GtkWidget  *button;
  gint        value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_ENUM, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

  if (minimum != maximum)
    {
      box = gimp_enum_stock_box_new_with_range (param_spec->value_type,
                                                minimum, maximum,
                                                stock_prefix,
580
                                                GTK_ICON_SIZE_MENU,
581 582 583 584 585 586 587 588
                                                G_CALLBACK (gimp_prop_radio_button_callback),
                                                config,
                                                &button);
    }
  else
    {
      box = gimp_enum_stock_box_new (param_spec->value_type,
                                     stock_prefix,
589
                                     GTK_ICON_SIZE_MENU,
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
                                     G_CALLBACK (gimp_prop_radio_button_callback),
                                     config,
                                     &button);
    }
    
  gimp_radio_group_set_active (GTK_RADIO_BUTTON (button),
                               GINT_TO_POINTER (value));

  set_param_spec (G_OBJECT (box), NULL, param_spec);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_radio_button_notify),
                  button);

  return box;
}

static void
gimp_prop_radio_button_callback (GtkWidget *widget,
                                 GObject   *config)
{
611 612 613 614
  if (GTK_TOGGLE_BUTTON (widget)->active)
    {
      GParamSpec *param_spec;
      gint        value;
615

616 617 618
      param_spec = get_param_spec (G_OBJECT (widget->parent));
      if (! param_spec)
        return;
619

620 621 622 623 624 625 626
      value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
                                                  "gimp-item-data"));

      g_object_set (config,
                    param_spec->name, value,
                    NULL);
    }
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
}

static void
gimp_prop_radio_button_notify (GObject    *config,
                               GParamSpec *param_spec,
                               GtkWidget  *button)
{
  gint value;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

  gimp_radio_group_set_active (GTK_RADIO_BUTTON (button),
                               GINT_TO_POINTER (value));
}


645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
/*****************/
/*  adjustments  */
/*****************/

static void   gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
                                             GObject       *config);
static void   gimp_prop_adjustment_notify   (GObject       *config,
                                             GParamSpec    *param_spec,
                                             GtkAdjustment *adjustment);

GtkWidget *
gimp_prop_spin_button_new (GObject     *config,
                           const gchar *property_name,
                           gdouble      step_increment,
                           gdouble      page_increment,
                           gint         digits)
{
  GParamSpec *param_spec;
  GtkWidget  *spinbutton;
  GtkObject  *adjustment;

666
  param_spec = find_param_spec (config, property_name, G_STRLOC);
667
  if (! param_spec)
668
    return NULL;
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719

  if (G_IS_PARAM_SPEC_INT (param_spec))
    {
      GParamSpecInt *int_spec;
      gint           value;

      int_spec = G_PARAM_SPEC_INT (param_spec);

      g_object_get (config, property_name, &value, NULL);

      spinbutton = gimp_spin_button_new (&adjustment, value,
                                         int_spec->minimum,
                                         int_spec->maximum,
                                         step_increment,
                                         page_increment,
                                         0.0, 1.0, 0);
    }
  else if (G_IS_PARAM_SPEC_UINT (param_spec))
    {
      GParamSpecUInt *uint_spec;
      guint           value;

      uint_spec = G_PARAM_SPEC_UINT (param_spec);

      g_object_get (config, property_name, &value, NULL);

      spinbutton = gimp_spin_button_new (&adjustment, value,
                                         uint_spec->minimum,
                                         uint_spec->maximum,
                                         step_increment,
                                         page_increment,
                                         0.0, 1.0, 0);
    }
  else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
    {
      GParamSpecDouble *double_spec;
      gdouble           value;

      double_spec = G_PARAM_SPEC_DOUBLE (param_spec);

      g_object_get (config, property_name, &value, NULL);

      spinbutton = gimp_spin_button_new (&adjustment, value,
                                         double_spec->minimum,
                                         double_spec->maximum,
                                         step_increment,
                                         page_increment,
                                         0.0, 1.0, digits);
    }
  else
    {
720 721
      g_warning ("%s: property '%s' of %s is not numeric",
                 G_STRLOC, property_name,
722 723 724 725
                 g_type_name (G_TYPE_FROM_INSTANCE (config)));
      return NULL;
    }

726
  set_param_spec (G_OBJECT (adjustment), spinbutton, param_spec);
727

728
  g_signal_connect (adjustment, "value_changed",
729 730 731
		    G_CALLBACK (gimp_prop_adjustment_callback),
		    config);

732 733 734
  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_adjustment_notify),
                  adjustment);
735 736 737 738

  return spinbutton;
}

739 740 741 742 743 744 745 746 747 748 749 750 751 752
GtkObject *
gimp_prop_scale_entry_new (GObject     *config,
                           const gchar *property_name,
                           GtkTable    *table,
                           gint         column,
                           gint         row,
                           const gchar *label,
                           gdouble      step_increment,
                           gdouble      page_increment,
                           gint         digits,
                           gboolean     restrict_scale,
                           gdouble      restricted_lower,
                           gdouble      restricted_upper)
{
753 754 755 756 757 758
  GParamSpec  *param_spec;
  GtkObject   *adjustment;
  const gchar *tooltip;
  gdouble      value;
  gdouble      lower;
  gdouble      upper;
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802

  param_spec = find_param_spec (config, property_name, G_STRLOC);
  if (! param_spec)
    return NULL;

  if (G_IS_PARAM_SPEC_INT (param_spec))
    {
      GParamSpecInt *int_spec;
      gint           int_value;

      int_spec = G_PARAM_SPEC_INT (param_spec);

      g_object_get (config, property_name, &int_value, NULL);

      value = int_value;
      lower = int_spec->minimum;
      upper = int_spec->maximum;
    }
  else if (G_IS_PARAM_SPEC_UINT (param_spec))
    {
      GParamSpecUInt *uint_spec;
      guint           uint_value;

      uint_spec = G_PARAM_SPEC_UINT (param_spec);

      g_object_get (config, property_name, &uint_value, NULL);

      value = uint_value;
      lower = uint_spec->minimum;
      upper = uint_spec->maximum;
    }
  else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
    {
      GParamSpecDouble *double_spec;

      double_spec = G_PARAM_SPEC_DOUBLE (param_spec);

      g_object_get (config, property_name, &value, NULL);

      lower = double_spec->minimum;
      upper = double_spec->maximum;
    }
  else
    {
803 804
      g_warning ("%s: property '%s' of %s is not numeric",
                 G_STRLOC, property_name,
805 806 807 808
                 g_type_name (G_TYPE_FROM_INSTANCE (config)));
      return NULL;
    }

809 810
  tooltip = gettext (g_param_spec_get_blurb (param_spec));

811 812 813 814 815 816 817
  if (! restrict_scale)
    {
      adjustment = gimp_scale_entry_new (table, column, row,
                                         label, -1, -1,
                                         value, lower, upper,
                                         step_increment, page_increment, digits,
                                         TRUE, 0.0, 0.0,
818
                                         tooltip,
819 820 821 822 823 824 825 826 827 828 829
                                         NULL);
    }
  else
    {
      adjustment = gimp_scale_entry_new (table, column, row,
                                         label, -1, -1,
                                         value,
                                         restricted_lower,
                                         restricted_upper,
                                         step_increment, page_increment, digits,
                                         FALSE, lower, upper,
830
                                         tooltip,
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
                                         NULL);
    }

  set_param_spec (G_OBJECT (adjustment), NULL,  param_spec);

  g_signal_connect (adjustment, "value_changed",
		    G_CALLBACK (gimp_prop_adjustment_callback),
		    config);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_adjustment_notify),
                  adjustment);

  return adjustment;
}

847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 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
GtkObject *
gimp_prop_opacity_entry_new (GObject     *config,
                             const gchar *property_name,
                             GtkTable    *table,
                             gint         column,
                             gint         row,
                             const gchar *label)
{
  GParamSpec  *param_spec;
  GtkObject   *adjustment;
  const gchar *tooltip;
  gdouble      lower;
  gdouble      upper;
  gdouble      value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_DOUBLE, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config, property_name, &value, NULL);

  tooltip = gettext (g_param_spec_get_blurb (param_spec));
  
  value *= 100.0;
  lower = G_PARAM_SPEC_DOUBLE (param_spec)->minimum * 100.0;
  upper = G_PARAM_SPEC_DOUBLE (param_spec)->maximum * 100.0;

  adjustment = gimp_scale_entry_new (table, column, row,
                                     label, -1, -1,
                                     value, lower, upper,
                                     1.0, 10.0, 1,
                                     TRUE, 0.0, 0.0,
                                     tooltip,
                                     NULL);

  set_param_spec (G_OBJECT (adjustment), NULL,  param_spec);
  g_object_set_data (G_OBJECT (adjustment),
                     "opacity-scale", GINT_TO_POINTER (TRUE));

  g_signal_connect (adjustment, "value_changed",
		    G_CALLBACK (gimp_prop_adjustment_callback),
		    config);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_adjustment_notify),
                  adjustment);

  return adjustment;
}


899 900 901 902 903 904
static void
gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
                               GObject       *config)
{
  GParamSpec *param_spec;

905
  param_spec = get_param_spec (G_OBJECT (adjustment));
906 907 908 909 910
  if (! param_spec)
    return;

  if (G_IS_PARAM_SPEC_INT (param_spec))
    {
911
      g_object_set (config, param_spec->name, (gint) adjustment->value, NULL);
912 913 914
    }
  else if (G_IS_PARAM_SPEC_UINT (param_spec))
    {
915
      g_object_set (config, param_spec->name, (guint) adjustment->value, NULL);
916 917 918
    }
  else if (G_IS_PARAM_SPEC_LONG (param_spec))
    {
919
      g_object_set (config, param_spec->name, (glong) adjustment->value, NULL);
920 921 922
    }
  else if (G_IS_PARAM_SPEC_ULONG (param_spec))
    {
923
      g_object_set (config, param_spec->name, adjustment->value, NULL);
924 925 926
    }
  else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
    {
927 928 929 930 931 932 933 934 935
      gdouble value;

      if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
                                              "opacity-scale")))
        value = adjustment->value / 100.0;
      else
        value = adjustment->value;

      g_object_set (config, param_spec->name, value, NULL);
936 937 938 939 940 941 942 943 944 945 946 947 948 949
    }
}

static void
gimp_prop_adjustment_notify (GObject       *config,
                             GParamSpec    *param_spec,
                             GtkAdjustment *adjustment)
{
  gdouble value;

  if (G_IS_PARAM_SPEC_INT (param_spec))
    {
      gint int_value;

950
      g_object_get (config, param_spec->name, &int_value, NULL);
951 952 953 954 955 956 957

      value = int_value;
    }
  else if (G_IS_PARAM_SPEC_UINT (param_spec))
    {
      guint uint_value;

958
      g_object_get (config, param_spec->name, &uint_value, NULL);
959 960 961 962 963 964 965

      value = uint_value;
    }
  else if (G_IS_PARAM_SPEC_LONG (param_spec))
    {
      glong long_value;

966
      g_object_get (config, param_spec->name, &long_value, NULL);
967 968 969 970 971 972 973

      value = long_value;
    }
  else if (G_IS_PARAM_SPEC_ULONG (param_spec))
    {
      gulong ulong_value;

974
      g_object_get (config, param_spec->name, &ulong_value, NULL);
975 976 977 978 979

      value = ulong_value;
    }
  else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
    {
980 981 982 983 984
      g_object_get (config, param_spec->name, &value, NULL);

      if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
                                              "opacity-scale")))
        value *= 100.0;
985 986 987 988 989 990 991 992
    }
  else
    {
      return;
    }

  if (adjustment->value != value)
    {
993
      g_signal_handlers_block_by_func (adjustment,
994 995 996 997 998
                                       gimp_prop_adjustment_callback,
                                       config);

      gtk_adjustment_set_value (adjustment, value);

999
      g_signal_handlers_unblock_by_func (adjustment,
1000 1001
                                         gimp_prop_adjustment_callback,
                                         config);
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
    }
}


/*************/
/*  memsize  */
/*************/

static void   gimp_prop_memsize_callback (GimpMemsizeEntry *entry,
					  GObject          *config);
static void   gimp_prop_memsize_notify   (GObject          *config,
					  GParamSpec       *param_spec,
					  GimpMemsizeEntry *entry);

GtkWidget *
gimp_prop_memsize_entry_new (GObject     *config,
                             const gchar *property_name)
{
  GParamSpec      *param_spec;
  GParamSpecULong *ulong_spec;
  GtkWidget       *entry;
  gulong           value;

  param_spec = check_param_spec (config, property_name,
                                 GIMP_TYPE_PARAM_MEMSIZE, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

  ulong_spec = G_PARAM_SPEC_ULONG (param_spec);

  entry = gimp_memsize_entry_new (value,
				  ulong_spec->minimum,
				  ulong_spec->maximum);

1040 1041 1042
  set_param_spec (G_OBJECT (entry),
                  GIMP_MEMSIZE_ENTRY (entry)->spinbutton,
                  param_spec);
1043

1044
  g_signal_connect (entry, "value_changed",
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
		    G_CALLBACK (gimp_prop_memsize_callback),
		    config);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_memsize_notify),
                  entry);

  return entry;
}


static void
gimp_prop_memsize_callback (GimpMemsizeEntry *entry,
			    GObject          *config)
{
  GParamSpec *param_spec;

  param_spec = get_param_spec (G_OBJECT (entry));
  if (! param_spec)
    return;

  g_return_if_fail (G_IS_PARAM_SPEC_ULONG (param_spec));

  g_object_set (config,
		param_spec->name, gimp_memsize_entry_get_value (entry),
		NULL);
}

static void
gimp_prop_memsize_notify (GObject          *config,
			  GParamSpec       *param_spec,
			  GimpMemsizeEntry *entry)
{
  gulong value;

  g_return_if_fail (G_IS_PARAM_SPEC_ULONG (param_spec));

  g_object_get (config,
		param_spec->name, &value,
		NULL);

  if (entry->value != value)
    {
1088
      g_signal_handlers_block_by_func (entry,
1089 1090 1091 1092 1093
                                       gimp_prop_memsize_callback,
                                       config);

      gimp_memsize_entry_set_value (entry, value);

1094
      g_signal_handlers_unblock_by_func (entry,
1095 1096
                                         gimp_prop_memsize_callback,
                                         config);
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
/***********/
/*  entry  */
/***********/

static void   gimp_prop_entry_callback (GtkWidget  *entry,
                                        GObject    *config);
static void   gimp_prop_entry_notify   (GObject    *config,
                                        GParamSpec *param_spec,
                                        GtkWidget  *entry);

GtkWidget *
gimp_prop_entry_new (GObject     *config,
                     const gchar *property_name,
                     gint         max_len)
{
  GParamSpec *param_spec;
  GtkWidget  *entry;
  gchar      *value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_STRING, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), value);

  g_free (value);

  if (max_len > 0)
    gtk_entry_set_max_length (GTK_ENTRY (entry), max_len);

1137
  set_param_spec (G_OBJECT (entry), entry, param_spec);
1138

1139
  g_signal_connect (entry, "changed",
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
		    G_CALLBACK (gimp_prop_entry_callback),
		    config);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_entry_notify),
                  entry);

  return entry;
}

static void
gimp_prop_entry_callback (GtkWidget *entry,
                          GObject   *config)
{
  GParamSpec  *param_spec;
  const gchar *text;

  param_spec = get_param_spec (G_OBJECT (entry));
  if (! param_spec)
    return;

  text = gtk_entry_get_text (GTK_ENTRY (entry));

1163
  g_signal_handlers_block_by_func (config,
1164 1165 1166 1167 1168 1169 1170
                                   gimp_prop_entry_notify,
                                   entry);

  g_object_set (config,
                param_spec->name, text,
                NULL);

1171
  g_signal_handlers_unblock_by_func (config,
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
                                     gimp_prop_entry_notify,
                                     entry);
}

static void
gimp_prop_entry_notify (GObject    *config,
                        GParamSpec *param_spec,
                        GtkWidget  *entry)
{
  gchar *value;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

1187
  g_signal_handlers_block_by_func (entry,
1188 1189 1190 1191 1192
                                   gimp_prop_entry_callback,
                                   config);

  gtk_entry_set_text (GTK_ENTRY (entry), value);

1193
  g_signal_handlers_unblock_by_func (entry,
1194 1195 1196 1197 1198 1199 1200
                                     gimp_prop_entry_callback,
                                     config);

  g_free (value);
}


1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
/*****************/
/*  text buffer  */
/*****************/

static void   gimp_prop_text_buffer_callback (GtkTextBuffer *text_buffer,
                                              GObject       *config);
static void   gimp_prop_text_buffer_notify   (GObject       *config,
                                              GParamSpec    *param_spec,
                                              GtkTextBuffer *text_buffer);

GtkTextBuffer *
gimp_prop_text_buffer_new (GObject     *config,
                           const gchar *property_name,
                           gint         max_len)
{
  GParamSpec    *param_spec;
  GtkTextBuffer *text_buffer;
  gchar         *value;

1220 1221
  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_STRING, G_STRLOC);
1222
  if (! param_spec)
1223
    return NULL;
1224 1225 1226 1227 1228 1229

  g_object_get (config,
                property_name, &value,
                NULL);

  text_buffer = gtk_text_buffer_new (NULL);
1230
  gtk_text_buffer_set_text (text_buffer, value ? value : "", -1);
1231 1232 1233 1234 1235 1236 1237

  g_free (value);

  if (max_len > 0)
    g_object_set_data (G_OBJECT (text_buffer), "max-len",
                       GINT_TO_POINTER (max_len));

1238
  set_param_spec (G_OBJECT (text_buffer), NULL, param_spec);
1239

1240
  g_signal_connect (text_buffer, "changed",
1241 1242 1243
		    G_CALLBACK (gimp_prop_text_buffer_callback),
		    config);

1244 1245 1246
  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_text_buffer_notify),
                  text_buffer);
1247 1248 1249 1250 1251 1252 1253 1254

  return text_buffer;
}

static void
gimp_prop_text_buffer_callback (GtkTextBuffer *text_buffer,
                                GObject       *config)
{
1255 1256 1257 1258 1259
  GParamSpec  *param_spec;
  GtkTextIter  start_iter;
  GtkTextIter  end_iter;
  gchar       *text;
  gint         max_len;
1260

1261 1262 1263
  param_spec = get_param_spec (G_OBJECT (text_buffer));
  if (! param_spec)
    return;
1264

1265 1266
  gtk_text_buffer_get_bounds (text_buffer, &start_iter, &end_iter);
  text = gtk_text_buffer_get_text (text_buffer, &start_iter, &end_iter, FALSE);
1267

1268 1269
  max_len = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (text_buffer),
                                                "max-length"));
1270

1271 1272 1273 1274
  if (max_len > 0 && strlen (text) > max_len)
    {
      g_message (_("This text input field is limited to %d characters."), 
                 max_len);
1275

1276 1277 1278
      gtk_text_buffer_get_iter_at_offset (text_buffer, &start_iter,
                                          max_len - 1);
      gtk_text_buffer_get_end_iter (text_buffer, &end_iter);
1279

1280 1281 1282 1283 1284
      /*  this calls us recursivaly, but in the else branch  */
      gtk_text_buffer_delete (text_buffer, &start_iter, &end_iter);
    }
  else
    {
1285
      g_signal_handlers_block_by_func (config,
1286 1287
                                       gimp_prop_text_buffer_notify,
                                       text_buffer);
1288

1289 1290 1291
      g_object_set (config,
                    param_spec->name, text,
                    NULL);
1292

1293
      g_signal_handlers_unblock_by_func (config,
1294 1295
                                         gimp_prop_text_buffer_notify,
                                         text_buffer);
1296
    }
1297 1298

  g_free (text);
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
}

static void
gimp_prop_text_buffer_notify (GObject       *config,
                              GParamSpec    *param_spec,
                              GtkTextBuffer *text_buffer)
{
  gchar *value;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

1312
  g_signal_handlers_block_by_func (text_buffer,
1313 1314 1315
                                   gimp_prop_text_buffer_callback,
                                   config);

1316
  gtk_text_buffer_set_text (text_buffer, value ? value : "", -1);
1317

1318
  g_signal_handlers_unblock_by_func (text_buffer,
1319 1320 1321 1322 1323 1324 1325
                                     gimp_prop_text_buffer_callback,
                                     config);

  g_free (value);
}


1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
/********************/
/*  font selection  */
/********************/

static void  gimp_prop_fontsel_callback (GtkWidget  *fontsel,
                                         GObject    *config);
static void  gimp_prop_fontsel_notify   (GObject    *config,
                                         GParamSpec *param_spec,
                                         GtkWidget  *fontsel);


GtkWidget *
gimp_prop_font_selection_new (GObject     *config,
                              const gchar *property_name)
{
  GParamSpec *param_spec;
  GtkWidget  *fontsel;
  gchar      *value;

  param_spec = check_param_spec (config, property_name,
                                 G_TYPE_PARAM_STRING, G_STRLOC);
  if (! param_spec)
    return NULL;

  g_object_get (config,
                property_name, &value,
                NULL);

  fontsel = gimp_font_selection_new (NULL);

  if (value)
    {
      gimp_font_selection_set_fontname (GIMP_FONT_SELECTION (fontsel), value);
      g_free (value);
    }

  set_param_spec (G_OBJECT (fontsel),
                  GIMP_FONT_SELECTION (fontsel)->entry, param_spec);

  g_signal_connect (fontsel, "font_changed",
		    G_CALLBACK (gimp_prop_fontsel_callback),
		    config);

  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_fontsel_notify),
                  fontsel);

  return fontsel;
}

static void
gimp_prop_fontsel_callback (GtkWidget *fontsel,
                            GObject   *config)
{
  GParamSpec  *param_spec;
  const gchar *name;

  param_spec = get_param_spec (G_OBJECT (fontsel));
  if (! param_spec)
    return;

  name = gimp_font_selection_get_fontname (GIMP_FONT_SELECTION (fontsel));

  g_signal_handlers_block_by_func (config,
                                   gimp_prop_fontsel_notify,
                                   fontsel);

  g_object_set (config,
                param_spec->name, name,
                NULL);

  g_signal_handlers_unblock_by_func (config,
                                     gimp_prop_fontsel_notify,
                                     fontsel);
}

static void
gimp_prop_fontsel_notify (GObject    *config,
                          GParamSpec *param_spec,
                          GtkWidget  *fontsel)
{
  gchar *value;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

  g_signal_handlers_block_by_func (fontsel,
                                   gimp_prop_fontsel_callback,
                                   config);

  gimp_font_selection_set_fontname (GIMP_FONT_SELECTION (fontsel), value);

  g_signal_handlers_unblock_by_func (fontsel,
                                     gimp_prop_fontsel_callback,
                                     config);

  g_free (value);
}


1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
/****************/
/*  file entry  */
/****************/


static void   gimp_prop_file_entry_callback (GimpFileSelection *entry,
                                             GObject           *config);
static void   gimp_prop_file_entry_notify   (GObject           *config,
                                             GParamSpec        *param_spec,
                                             GimpFileSelection *entry);

GtkWidget *
gimp_prop_file_entry_new (GObject     *config,
                          const gchar *property_name,
                          const gchar *filesel_title,
                          gboolean     dir_only,
                          gboolean     check_valid)
{
  GParamSpec *param_spec;
  GtkWidget  *entry;
Sven Neumann's avatar
Sven Neumann committed
1447
  gchar      *filename;
1448 1449
  gchar      *value;

1450 1451
  param_spec = check_param_spec (config, property_name,
                                 GIMP_TYPE_PARAM_PATH, G_STRLOC);
1452
  if (! param_spec)
1453
    return NULL;
1454 1455 1456 1457 1458

  g_object_get (config,
                property_name, &value,
                NULL);

Sven Neumann's avatar
Sven Neumann committed
1459 1460 1461 1462
  filename = value ? gimp_config_path_expand (value, FALSE, NULL) : NULL;

  entry = gimp_file_selection_new (filesel_title,
                                   filename, dir_only, check_valid);
1463 1464

  g_free (value);
Sven Neumann's avatar
Sven Neumann committed
1465
  g_free (filename);
1466

1467 1468 1469
  set_param_spec (G_OBJECT (entry),
                  GIMP_FILE_SELECTION (entry)->entry,
                  param_spec);
1470

1471
  g_signal_connect (entry, "filename_changed",
1472 1473 1474
		    G_CALLBACK (gimp_prop_file_entry_callback),
		    config);

1475 1476 1477
  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_file_entry_notify),
                  entry);
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488

  return entry;
}

static void
gimp_prop_file_entry_callback (GimpFileSelection *entry,
                               GObject           *config)
{
  GParamSpec *param_spec;
  gchar      *value;

1489
  param_spec = get_param_spec (G_OBJECT (entry));
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
  if (! param_spec)
    return;

  value = gimp_file_selection_get_filename (entry);

  g_object_set (config,
                param_spec->name, value,
                NULL);

  g_free (value);
}

static void
gimp_prop_file_entry_notify (GObject           *config,
                             GParamSpec        *param_spec,
                             GimpFileSelection *entry)
{
  gchar *value;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

1513
  g_signal_handlers_block_by_func (entry,
1514 1515 1516 1517 1518
                                   gimp_prop_file_entry_callback,
                                   config);

  gimp_file_selection_set_filename (entry, value);

1519
  g_signal_handlers_unblock_by_func (entry,
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544
                                     gimp_prop_file_entry_callback,
                                     config);

  g_free (value);
}


/*****************/
/*  path editor  */
/*****************/

static void   gimp_prop_path_editor_callback (GimpPathEditor *editor,
                                              GObject        *config);
static void   gimp_prop_path_editor_notify   (GObject        *config,
                                              GParamSpec     *param_spec,
                                              GimpPathEditor *editor);

GtkWidget *
gimp_prop_path_editor_new (GObject     *config,
                           const gchar *property_name,
                           const gchar *filesel_title)
{
  GParamSpec *param_spec;
  GtkWidget  *editor;
  gchar      *value;
Sven Neumann's avatar
Sven Neumann committed
1545
  gchar      *filename;
1546

1547 1548
  param_spec = check_param_spec (config, property_name,
                                 GIMP_TYPE_PARAM_PATH, G_STRLOC);
1549
  if (! param_spec)
1550
    return NULL;
1551 1552 1553 1554 1555

  g_object_get (config,
                property_name, &value,
                NULL);

Sven Neumann's avatar
Sven Neumann committed
1556 1557 1558
  filename = value ? gimp_config_path_expand (value, FALSE, NULL) : NULL;

  editor = gimp_path_editor_new (filesel_title, filename);
1559

Sven Neumann's avatar
Sven Neumann committed
1560
  g_free (filename);
1561 1562
  g_free (value);

1563
  set_param_spec (G_OBJECT (editor), NULL, param_spec);
1564

1565
  g_signal_connect (editor, "path_changed",
1566 1567 1568
		    G_CALLBACK (gimp_prop_path_editor_callback),
		    config);

1569 1570 1571
  connect_notify (config, property_name,
                  G_CALLBACK (gimp_prop_path_editor_notify),
                  editor);
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582

  return editor;
}

static void
gimp_prop_path_editor_callback (GimpPathEditor *editor,
                                GObject        *config)
{
  GParamSpec *param_spec;
  gchar      *value;

1583
  param_spec = get_param_spec (G_OBJECT (editor));
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
  if (! param_spec)
    return;

  value = gimp_path_editor_get_path (editor);

  g_object_set (config,
                param_spec->name, value,
                NULL);

  g_free (value);
}

static void
gimp_prop_path_editor_notify (GObject        *config,
                              GParamSpec     *param_spec,
                              GimpPathEditor *editor)
{
  gchar *value;

  g_object_get (config,
                param_spec->name, &value,
                NULL);

1607
  g_signal_handlers_block_by_func (editor,
1608 1609 1610 1611 1612
                                   gimp_prop_path_editor_callback,
                                   config);

  gimp_path_editor_set_path (editor, value);

1613
  g_signal_handlers_unblock_by_func (editor,
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646
                                     gimp_prop_path_editor_callback,
                                     config);

  g_free (value);
}


/*****************/
/*  coordinates  */
/*****************/

static void   gimp_prop_coordinates_callback    (GimpSizeEntry *sizeentry,
                                                 GObject       *config);
static void   gimp_prop_coordinates_notify_x    (GObject       *config,
                                                 GParamSpec    *param_spec,
                                                 GimpSizeEntry *sizeentry);
static void   gimp_prop_coordinates_notify_y    (GObject       *config,
                                                 GParamSpec    *param_spec,
                                                 GimpSizeEntry *sizeentry);
static void   gimp_prop_coordinates_notify_unit (GObject       *config,
                                                 GParamSpec    *param_spec,
                                                 GimpSizeEntry *sizeentry);

GtkWidget *
gimp_prop_coordinates_new (GObject                   *config,
                           const gchar               *x_property_name,
                           const gchar               *y_property_name,
                           const gchar               *unit_property_name,
                           const gchar               *unit_format,
                           GimpSizeEntryUpdatePolicy  update_policy,
                           gdouble                    xresolution,
                           gdouble                    yresolution,
                           gboolean                   has_chainbutton)
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
{
  GtkWidget *sizeentry;
  GtkWidget *chainbutton = NULL;

  sizeentry = gimp_size_entry_new (2, GIMP_UNIT_INCH, unit_format,
                                   FALSE, FALSE, TRUE, 10,
                                   update_policy);

  if (has_chainbutton)
    {
      chainbutton = gimp_chain_button_new (GIMP_CHAIN_BOTTOM);

      gtk_table_attach_defaults (GTK_TABLE (sizeentry), chainbutton,
                                 1, 3, 3, 4);
      gtk_widget_show (chainbutton);
    }

  if (! gimp_prop_size_entry_connect (config,
                                      x_property_name,
                                      y_property_name,
                                      unit_property_name,
                                      sizeentry,
                                      chainbutton,
                                      xresolution,
                                      yresolution))
    {
      gtk_widget_destroy (sizeentry);
      return NULL;
    }

  return sizeentry;
}

gboolean
gimp_prop_size_entry_connect (GObject     *config,
                              const gchar *x_property_name,
                              const gchar *y_property_name,
                              const gchar *unit_property_name,
                              GtkWidget   *sizeentry,
                              GtkWidget   *chainbutton,
                              gdouble      xresolution,
                              gdouble      yresolution)
1689 1690 1691 1692 1693 1694
{
  GParamSpec *x_param_spec;
  GParamSpec *y_param_spec;
  GParamSpec *unit_param_spec;
  gdouble     x_value;
  gdouble     y_value;
1695
  GimpUnit    unit_value;
1696 1697
  gdouble    *old_x_value;
  gdouble    *old_y_value;
1698
  GimpUnit   *old_unit_value;
1699 1700
  gboolean    chain_checked = FALSE;

1701 1702 1703 1704 1705 1706
  g_return_val_if_fail (GIMP_IS_SIZE_ENTRY (sizeentry), FALSE);
  g_return_val_if_fail (GIMP_SIZE_ENTRY (sizeentry)->number_of_fields == 2,
                        FALSE);
  g_return_val_if_fail (chainbutton == NULL ||
                        GIMP_IS_CHAIN_BUTTON (chainbutton), FALSE);

1707
  x_param_spec = find_param_spec (config, x_property_name, G_STRLOC);
1708
  if (! x_param_spec)
1709
    return FALSE;
1710

1711
  y_param_spec = find_param_spec (config, y_property_name, G_STRLOC);
1712
  if (! y_param_spec)
1713
    return FALSE;
1714 1715 1716

  if (unit_property_name)
    {
1717 1718
      unit_param_spec = check_param_spec (config, unit_property_name,
                                          GIMP_TYPE_PARAM_UNIT, G_STRLOC);
1719
      if (! unit_param_spec)
1720
        return FALSE;
1721 1722 1723 1724 1725 1726 1727 1728

      g_object_get (config,
                    unit_property_name, &unit_value,
                    NULL);
    }
  else
    {
      unit_param_spec = NULL;
1729
      unit_value      = GIMP_UNIT_INCH;
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
    }

  if (G_IS_PARAM_SPEC_INT (x_param_spec) &&
      G_IS_PARAM_SPEC_INT (y_param_spec))
    {
      gint int_x;
      gint int_y;

      g_object_get (config,
                    x_property_name, &int_x,
                    y_property_name, &int_y,
                    NULL);

      x_value = int_x;
      y_value = int_y;
    }
  else if (G_IS_PARAM_SPEC_DOUBLE (x_param_spec) &&
           G_IS_PARAM_SPEC_DOUBLE (y_param_spec))
    {
      g_object_get (config,
                    x_property_name, &x_value,
                    y_property_name, &y_value,
                    NULL);
    }
  else
    {
1756
      g_warning ("%s: properties '%s' and '%s' of %s are not either "
1757
                 " both int or both double",
1758
                 G_STRLOC, x_property_name, y_property_name,
1759
                 g_type_name (G_TYPE_FROM_INSTANCE (config)));
1760
      return FALSE;
1761 1762
    }

1763
  switch (GIMP_SIZE_ENTRY (sizeentry)->update_policy)
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
    {
    case GIMP_SIZE_ENTRY_UPDATE_SIZE:
      gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
                                      xresolution, FALSE);
      gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
                                      yresolution, FALSE);

      gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
                                             GIMP_MIN_IMAGE_SIZE,
                                             GIMP_MAX_IMAGE_SIZE);
      gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
                                             GIMP_MIN_IMAGE_SIZE,
                                             GIMP_MAX_IMAGE_SIZE);

      if (ABS (x_value - y_value) < 1)
        chain_checked = TRUE;
      break;

    case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
      gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
                                             GIMP_MIN_RESOLUTION,
                                             GIMP_MAX_RESOLUTION);
      gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
                                             GIMP_MIN_RESOLUTION,
                                             GIMP_MAX_RESOLUTION);

      if (ABS (x_value - y_value) < GIMP_MIN_RESOLUTION)
        chain_checked = TRUE;
      break;

    default:
      break;
    }

  gimp_size_entry_set_unit   (GIMP_SIZE_ENTRY (sizeentry), unit_value);
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, x_value);
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, y_value);

  g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec-x",
                     x_param_spec);
  g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec-y",
                     y_param_spec);
  g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec-unit",
                     unit_param_spec);

1809 1810 1811 1812 1813
  old_x_value  = g_new0 (gdouble, 1);
  *old_x_value = x_value;
  g_object_set_data_full (G_OBJECT (sizeentry), "old-x-value",
                          old_x_value,
                          (GDestroyNotify) g_free);
1814

1815 1816 1817 1818 1819
  old_y_value  = g_new0 (gdouble, 1);
  *old_y_value = y_value;
  g_object_set_data_full (G_OBJECT (sizeentry), "old-y-value",
                          old_y_value,
                          (GDestroyNotify) g_free);
1820

1821 1822 1823 1824 1825 1826 1827 1828 1829
  if (unit_property_name)
    {
      old_unit_value  = g_new0 (GimpUnit, 1);
      *old_unit_value = unit_value;
      g_object_set_data_full (G_OBJECT (sizeentry), "old-unit-value",
                              old_unit_value,
                              (GDestroyNotify) g_free);
    }

1830 1831
  if (chainbutton)
    {
1832
      if (chain_checked)
1833
        gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chainbutton), TRUE);
1834

1835
      g_object_set_data (G_OBJECT (sizeentry), "chainbutton", chainbutton);
1836 1837
    }

1838
  g_signal_connect (sizeentry, "value_changed",
1839 1840
		    G_CALLBACK (gimp_prop_coordinates_callback),
		    config);
1841
  g_signal_connect (sizeentry, "refval_changed",
1842 1843
		    G_CALLBACK (gimp_prop_coordinates_callback),
		    config);
1844 1845 1846

  if (unit_property_name)
    {
1847
      g_signal_connect (sizeentry, "unit_changed",
1848 1849 1850
                        G_CALLBACK (gimp_prop_coordinates_callback),
                        config);
    }
1851

1852 1853 1854 1855 1856 1857
  connect_notify (config, x_property_name,
                  G_CALLBACK (gimp_prop_coordinates_notify_x),
                  sizeentry);
  connect_notify (config, y_property_name,
                  G_CALLBACK (gimp_prop_coordinates_notify_y),
                  sizeentry);
1858 1859 1860

  if (unit_property_name)
    {
1861 1862 1863
      connect_notify (config, unit_property_name,
                      G_CALLBACK (gimp_prop_coordinates_notify_unit),
                      sizeentry);
1864 1865
    }

1866
  return TRUE;
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878
}

static void
gimp_prop_coordinates_callback (GimpSizeEntry *sizeentry,
                                GObject       *config)
{
  GParamSpec *x_param_spec;
  GParamSpec *y_param_spec;
  GParamSpec *unit_param_spec;
  gdouble     x_value;
  gdouble     y_value;
  GimpUnit    unit_value;
1879 1880
  gdouble    *old_x_value;
  gdouble    *old_y_value;
1881
  GimpUnit   *old_unit_value;
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896

  x_param_spec = g_object_get_data (G_OBJECT (sizeentry),
                                    "gimp-config-param-spec-x");
  y_param_spec = g_object_get_data (G_OBJECT (sizeentry),
                                    "gimp-config-param-spec-y");
  unit_param_spec = g_object_get_data (G_OBJECT (sizeentry),
                                       "gimp-config-param-spec-unit");

  if (! x_param_spec || ! y_param_spec)
    return;

  x_value    = gimp_size_entry_get_refval (sizeentry, 0);
  y_value    = gimp_size_entry_get_refval (sizeentry, 1);
  unit_value = gimp_size_entry_get_unit (sizeentry);

1897 1898 1899
  old_x_value    = g_object_get_data (G_OBJECT (sizeentry), "old-x-value");
  old_y_value    = g_object_get_data (G_OBJECT (sizeentry), "old-y-value");
  old_unit_value = g_object_get_data (G_OBJECT (sizeentry), "old-unit-value");
1900

1901
  if (! old_x_value || ! old_y_value || (unit_param_spec && ! old_unit_value))
1902
    return;
1903

1904 1905 1906
  if (x_value != y_value)
    {
      GtkWidget *chainbutton;
1907

1908
      chainbutton = g_object_get_data (G_OBJECT (sizeentry), "chainbutton");
1909

1910 1911
      if (chainbutton &&
          gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (chainbutton)))
1912 1913
        {
          if (x_value != *old_x_value)
1914 1915 1916
            y_value = x_value;
          else if (y_value != *old_y_value)
            x_value = y_value;
1917 1918 1919
        }
    }

1920 1921 1922
  if (*old_x_value == x_value &&
      *old_y_value == y_value &&
      (old_unit_value == NULL || *old_unit_value == unit_value))
1923 1924 1925 1926 1927
    return;

  *old_x_value = x_value;
  *old_y_value = y_value;

1928 1929 1930
  if (old_unit_value)
    *old_unit_value = unit_value;

1931 1932 1933 1934
  if (G_IS_PARAM_SPEC_INT (x_param_spec) &&
      G_IS_PARAM_SPEC_INT (y_param_spec))
    {
      g_object_set (config,
1935 1936
                    x_param_spec->name, ROUND (x_value),
                    y_param_spec->name, ROUND (y_value),
1937