prop-editor.c 40 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* prop-editor.c
 * Copyright (C) 2000  Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27 28
 */

#include <string.h>

#include <gtk/gtk.h>

#include "prop-editor.h"


typedef struct
{
  gpointer instance;
  GObject *alive_object;
29
  gulong id;
30 31 32 33 34 35
} DisconnectData;

static void
disconnect_func (gpointer data)
{
  DisconnectData *dd = data;
Matthias Clasen's avatar
Matthias Clasen committed
36

37 38 39 40 41
  g_signal_handler_disconnect (dd->instance, dd->id);
}

static void
signal_removed (gpointer  data,
Matthias Clasen's avatar
Matthias Clasen committed
42
                GClosure *closure)
43 44 45 46 47 48 49
{
  DisconnectData *dd = data;

  g_object_steal_data (dd->alive_object, "alive-object-data");
  g_free (dd);
}

50 51 52 53 54 55
static gboolean
is_child_property (GParamSpec *pspec)
{
  return g_param_spec_get_qdata (pspec, g_quark_from_string ("is-child-prop")) != NULL;
}

56
static void
57 58
mark_child_property (GParamSpec *pspec)
{
Matthias Clasen's avatar
Matthias Clasen committed
59 60
  g_param_spec_set_qdata (pspec, g_quark_from_string ("is-child-prop"),
                          GINT_TO_POINTER (TRUE));
61 62 63 64
}

static void
g_object_connect_property (GObject     *object,
Matthias Clasen's avatar
Matthias Clasen committed
65
                           GParamSpec  *spec,
66 67 68
                           GCallback    func,
                           gpointer     data,
                           GObject     *alive_object)
69 70
{
  GClosure *closure;
71
  gchar *with_detail;
72 73
  DisconnectData *dd;

74 75 76 77 78
  if (is_child_property (spec))
    with_detail = g_strconcat ("child-notify::", spec->name, NULL);
  else
    with_detail = g_strconcat ("notify::", spec->name, NULL);

79 80 81 82 83 84 85
  dd = g_new (DisconnectData, 1);

  closure = g_cclosure_new (func, data, NULL);

  g_closure_add_invalidate_notifier (closure, dd, signal_removed);

  dd->id = g_signal_connect_closure (object, with_detail,
Matthias Clasen's avatar
Matthias Clasen committed
86
                                     closure, FALSE);
87 88 89

  dd->instance = object;
  dd->alive_object = alive_object;
Matthias Clasen's avatar
Matthias Clasen committed
90

91 92 93 94
  g_object_set_data_full (G_OBJECT (alive_object),
                          "alive-object-data",
                          dd,
                          disconnect_func);
Matthias Clasen's avatar
Matthias Clasen committed
95

96 97 98
  g_free (with_detail);
}

Matthias Clasen's avatar
Matthias Clasen committed
99
typedef struct
100 101
{
  GObject *obj;
102
  GParamSpec *spec;
103
  gulong modified_id;
104 105 106 107 108 109 110 111 112
} ObjectProperty;

static void
free_object_property (ObjectProperty *p)
{
  g_free (p);
}

static void
113 114 115
connect_controller (GObject     *controller,
                    const gchar *signal,
                    GObject     *model,
Matthias Clasen's avatar
Matthias Clasen committed
116
                    GParamSpec  *spec,
117
                    GCallback    func)
118 119 120 121 122
{
  ObjectProperty *p;

  p = g_new (ObjectProperty, 1);
  p->obj = model;
123
  p->spec = spec;
124

125
  p->modified_id = g_signal_connect_data (controller, signal, func, p,
Matthias Clasen's avatar
Matthias Clasen committed
126 127
                                          (GClosureNotify)free_object_property,
                                          0);
128 129 130 131 132 133 134 135
  g_object_set_data (controller, "object-property", p);
}

static void
block_controller (GObject *controller)
{
  ObjectProperty *p = g_object_get_data (controller, "object-property");

136 137
  if (p)
    g_signal_handler_block (controller, p->modified_id);
138 139 140 141 142 143 144
}

static void
unblock_controller (GObject *controller)
{
  ObjectProperty *p = g_object_get_data (controller, "object-property");

145 146
  if (p)
    g_signal_handler_unblock (controller, p->modified_id);
147 148 149 150 151 152 153
}

static void
int_modified (GtkAdjustment *adj, gpointer data)
{
  ObjectProperty *p = data;

154 155 156 157 158
  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

Matthias Clasen's avatar
Matthias Clasen committed
159 160
      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, (int) gtk_adjustment_get_value (adj), NULL);
161 162
    }
  else
163
    g_object_set (p->obj, p->spec->name, (int) gtk_adjustment_get_value (adj), NULL);
164 165 166 167 168 169 170 171 172 173 174
}

static void
get_property_value (GObject *object, GParamSpec *pspec, GValue *value)
{
  if (is_child_property (pspec))
    {
      GtkWidget *widget = GTK_WIDGET (object);
      GtkWidget *parent = gtk_widget_get_parent (widget);

      gtk_container_child_get_property (GTK_CONTAINER (parent),
Matthias Clasen's avatar
Matthias Clasen committed
175
                                        widget, pspec->name, value);
176 177 178
    }
  else
    g_object_get_property (object, pspec->name, value);
179 180 181 182 183 184
}

static void
int_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkAdjustment *adj = GTK_ADJUSTMENT (data);
Javier Jardón's avatar
Javier Jardón committed
185
  GValue val = G_VALUE_INIT;
186 187

  g_value_init (&val, G_TYPE_INT);
188 189

  get_property_value (object, pspec, &val);
190

191
  if (g_value_get_int (&val) != (int)gtk_adjustment_get_value (adj))
192 193 194 195 196
    {
      block_controller (G_OBJECT (adj));
      gtk_adjustment_set_value (adj, g_value_get_int (&val));
      unblock_controller (G_OBJECT (adj));
    }
197 198 199 200

  g_value_unset (&val);
}

201 202 203 204 205
static void
uint_modified (GtkAdjustment *adj, gpointer data)
{
  ObjectProperty *p = data;

206 207 208 209 210
  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

Matthias Clasen's avatar
Matthias Clasen committed
211 212
      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, (guint) gtk_adjustment_get_value (adj), NULL);
213 214
    }
  else
215
    g_object_set (p->obj, p->spec->name, (guint) gtk_adjustment_get_value (adj), NULL);
216 217 218 219 220 221
}

static void
uint_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkAdjustment *adj = GTK_ADJUSTMENT (data);
Javier Jardón's avatar
Javier Jardón committed
222
  GValue val = G_VALUE_INIT;
223 224

  g_value_init (&val, G_TYPE_UINT);
225
  get_property_value (object, pspec, &val);
226

227
  if (g_value_get_uint (&val) != (guint)gtk_adjustment_get_value (adj))
228 229 230 231 232 233 234 235 236
    {
      block_controller (G_OBJECT (adj));
      gtk_adjustment_set_value (adj, g_value_get_uint (&val));
      unblock_controller (G_OBJECT (adj));
    }

  g_value_unset (&val);
}

237 238 239 240 241
static void
float_modified (GtkAdjustment *adj, gpointer data)
{
  ObjectProperty *p = data;

242 243 244 245 246
  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

Matthias Clasen's avatar
Matthias Clasen committed
247 248
      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, (float) gtk_adjustment_get_value (adj), NULL);
249 250
    }
  else
251
    g_object_set (p->obj, p->spec->name, (float) gtk_adjustment_get_value (adj), NULL);
252 253 254 255 256 257
}

static void
float_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkAdjustment *adj = GTK_ADJUSTMENT (data);
Javier Jardón's avatar
Javier Jardón committed
258
  GValue val = G_VALUE_INIT;
259 260

  g_value_init (&val, G_TYPE_FLOAT);
261
  get_property_value (object, pspec, &val);
262

263
  if (g_value_get_float (&val) != (float) gtk_adjustment_get_value (adj))
264 265 266 267 268
    {
      block_controller (G_OBJECT (adj));
      gtk_adjustment_set_value (adj, g_value_get_float (&val));
      unblock_controller (G_OBJECT (adj));
    }
269 270 271 272

  g_value_unset (&val);
}

273 274 275 276 277
static void
double_modified (GtkAdjustment *adj, gpointer data)
{
  ObjectProperty *p = data;

278 279 280 281 282
  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

Matthias Clasen's avatar
Matthias Clasen committed
283 284
      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, (double) gtk_adjustment_get_value (adj), NULL);
285 286
    }
  else
287
    g_object_set (p->obj, p->spec->name, (double) gtk_adjustment_get_value (adj), NULL);
288 289 290 291 292 293
}

static void
double_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkAdjustment *adj = GTK_ADJUSTMENT (data);
Javier Jardón's avatar
Javier Jardón committed
294
  GValue val = G_VALUE_INIT;
295 296

  g_value_init (&val, G_TYPE_DOUBLE);
297
  get_property_value (object, pspec, &val);
298

299
  if (g_value_get_double (&val) != gtk_adjustment_get_value (adj))
300 301 302 303 304 305 306 307 308
    {
      block_controller (G_OBJECT (adj));
      gtk_adjustment_set_value (adj, g_value_get_double (&val));
      unblock_controller (G_OBJECT (adj));
    }

  g_value_unset (&val);
}

309 310 311 312 313 314 315 316
static void
string_modified (GtkEntry *entry, gpointer data)
{
  ObjectProperty *p = data;
  const gchar *text;

  text = gtk_entry_get_text (entry);

317 318 319 320 321
  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

Matthias Clasen's avatar
Matthias Clasen committed
322 323
      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, text, NULL);
324 325 326
    }
  else
    g_object_set (p->obj, p->spec->name, text, NULL);
327 328 329 330 331 332
}

static void
string_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkEntry *entry = GTK_ENTRY (data);
Javier Jardón's avatar
Javier Jardón committed
333
  GValue val = G_VALUE_INIT;
334 335
  const gchar *str;
  const gchar *text;
Matthias Clasen's avatar
Matthias Clasen committed
336

337
  g_value_init (&val, G_TYPE_STRING);
338
  get_property_value (object, pspec, &val);
339 340 341 342 343 344 345

  str = g_value_get_string (&val);
  if (str == NULL)
    str = "";
  text = gtk_entry_get_text (entry);

  if (strcmp (str, text) != 0)
346 347 348 349 350
    {
      block_controller (G_OBJECT (entry));
      gtk_entry_set_text (entry, str);
      unblock_controller (G_OBJECT (entry));
    }
Matthias Clasen's avatar
Matthias Clasen committed
351

352 353 354 355 356 357 358 359
  g_value_unset (&val);
}

static void
bool_modified (GtkToggleButton *tb, gpointer data)
{
  ObjectProperty *p = data;

360 361 362 363 364
  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

365 366 367
      gtk_container_child_set (GTK_CONTAINER (parent), widget,
                               p->spec->name, (int) gtk_toggle_button_get_active (tb),
                               NULL);
368 369
    }
  else
370
    g_object_set (p->obj, p->spec->name, (int) gtk_toggle_button_get_active (tb), NULL);
371 372 373 374 375 376
}

static void
bool_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkToggleButton *tb = GTK_TOGGLE_BUTTON (data);
Javier Jardón's avatar
Javier Jardón committed
377
  GtkWidget *child;
Javier Jardón's avatar
Javier Jardón committed
378
  GValue val = G_VALUE_INIT;
Matthias Clasen's avatar
Matthias Clasen committed
379

380
  g_value_init (&val, G_TYPE_BOOLEAN);
381
  get_property_value (object, pspec, &val);
382

383
  if (g_value_get_boolean (&val) != gtk_toggle_button_get_active (tb))
384 385 386 387 388
    {
      block_controller (G_OBJECT (tb));
      gtk_toggle_button_set_active (tb, g_value_get_boolean (&val));
      unblock_controller (G_OBJECT (tb));
    }
389

Javier Jardón's avatar
Javier Jardón committed
390 391 392
  child = gtk_bin_get_child (GTK_BIN (tb));
  gtk_label_set_text (GTK_LABEL (child),
                      g_value_get_boolean (&val) ? "TRUE" : "FALSE");
Matthias Clasen's avatar
Matthias Clasen committed
393

394 395 396 397 398
  g_value_unset (&val);
}


static void
399
enum_modified (GtkComboBox *cb, gpointer data)
400 401 402 403
{
  ObjectProperty *p = data;
  gint i;
  GEnumClass *eclass;
Matthias Clasen's avatar
Matthias Clasen committed
404

405
  eclass = G_ENUM_CLASS (g_type_class_peek (p->spec->value_type));
406 407 408

  i = gtk_combo_box_get_active (cb);

409

410 411 412 413
  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);
414

Matthias Clasen's avatar
Matthias Clasen committed
415 416
      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, eclass->values[i].value, NULL);
417 418 419
    }
  else
    g_object_set (p->obj, p->spec->name, eclass->values[i].value, NULL);
420 421 422 423 424
}

static void
enum_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
425
  GtkComboBox *cb = GTK_COMBO_BOX (data);
Javier Jardón's avatar
Javier Jardón committed
426
  GValue val = G_VALUE_INIT;
427 428 429 430
  GEnumClass *eclass;
  gint i;

  eclass = G_ENUM_CLASS (g_type_class_peek (pspec->value_type));
Matthias Clasen's avatar
Matthias Clasen committed
431

432
  g_value_init (&val, pspec->value_type);
433
  get_property_value (object, pspec, &val);
434 435 436 437 438 439 440 441

  i = 0;
  while (i < eclass->n_values)
    {
      if (eclass->values[i].value == g_value_get_enum (&val))
        break;
      ++i;
    }
Matthias Clasen's avatar
Matthias Clasen committed
442

443
  if (gtk_combo_box_get_active (cb) != i)
444
    {
445 446 447
      block_controller (G_OBJECT (cb));
      gtk_combo_box_set_active (cb, i);
      unblock_controller (G_OBJECT (cb));
448
    }
Matthias Clasen's avatar
Matthias Clasen committed
449

450 451 452 453
  g_value_unset (&val);

}

454 455 456 457 458 459 460 461
static void
flags_modified (GtkCheckButton *button, gpointer data)
{
  ObjectProperty *p = data;
  gboolean active;
  GFlagsClass *fclass;
  guint flags;
  gint i;
Matthias Clasen's avatar
Matthias Clasen committed
462

463
  fclass = G_FLAGS_CLASS (g_type_class_peek (p->spec->value_type));
Matthias Clasen's avatar
Matthias Clasen committed
464

465 466 467 468 469 470 471 472
  active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
  i = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "index"));

  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

Matthias Clasen's avatar
Matthias Clasen committed
473 474
      gtk_container_child_get (GTK_CONTAINER (parent),
                               widget, p->spec->name, &flags, NULL);
475 476 477 478 479
      if (active)
        flags |= fclass->values[i].value;
      else
        flags &= ~fclass->values[i].value;

Matthias Clasen's avatar
Matthias Clasen committed
480 481
      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, flags, NULL);
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
    }
  else
    {
      g_object_get (p->obj, p->spec->name, &flags, NULL);

      if (active)
        flags |= fclass->values[i].value;
      else
        flags &= ~fclass->values[i].value;

      g_object_set (p->obj, p->spec->name, flags, NULL);
    }
}

static void
flags_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GList *children, *c;
Javier Jardón's avatar
Javier Jardón committed
500
  GValue val = G_VALUE_INIT;
501 502 503 504 505
  GFlagsClass *fclass;
  guint flags;
  gint i;

  fclass = G_FLAGS_CLASS (g_type_class_peek (pspec->value_type));
Matthias Clasen's avatar
Matthias Clasen committed
506

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
  g_value_init (&val, pspec->value_type);
  get_property_value (object, pspec, &val);
  flags = g_value_get_flags (&val);
  g_value_unset (&val);

  children = gtk_container_get_children (GTK_CONTAINER (data));

  for (c = children, i = 0; c; c = c->next, i++)
    {
      block_controller (G_OBJECT (c->data));
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (c->data),
                                    (fclass->values[i].value & flags) != 0);
      unblock_controller (G_OBJECT (c->data));
    }

  g_list_free (children);
}

525 526 527 528
static gunichar
unichar_get_value (GtkEntry *entry)
{
  const gchar *text = gtk_entry_get_text (entry);
Matthias Clasen's avatar
Matthias Clasen committed
529

530 531 532 533 534 535 536 537 538 539 540 541
  if (text[0])
    return g_utf8_get_char (text);
  else
    return 0;
}

static void
unichar_modified (GtkEntry *entry, gpointer data)
{
  ObjectProperty *p = data;
  gunichar val = unichar_get_value (entry);

542 543 544 545 546
  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

Matthias Clasen's avatar
Matthias Clasen committed
547 548
      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, val, NULL);
549 550 551
    }
  else
    g_object_set (p->obj, p->spec->name, val, NULL);
552 553 554 555 556 557 558 559
}

static void
unichar_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkEntry *entry = GTK_ENTRY (data);
  gunichar new_val;
  gunichar old_val = unichar_get_value (entry);
Javier Jardón's avatar
Javier Jardón committed
560
  GValue val = G_VALUE_INIT;
561 562
  gchar buf[7];
  gint len;
Matthias Clasen's avatar
Matthias Clasen committed
563

564 565 566
  g_value_init (&val, pspec->value_type);
  get_property_value (object, pspec, &val);
  new_val = (gunichar)g_value_get_uint (&val);
567 568 569 570

  if (new_val != old_val)
    {
      if (!new_val)
Matthias Clasen's avatar
Matthias Clasen committed
571
        len = 0;
572
      else
Matthias Clasen's avatar
Matthias Clasen committed
573 574
        len = g_unichar_to_utf8 (new_val, buf);

575
      buf[len] = '\0';
Matthias Clasen's avatar
Matthias Clasen committed
576

577
      block_controller (G_OBJECT (entry));
578
      gtk_entry_set_text (entry, buf);
579
      unblock_controller (G_OBJECT (entry));
580 581 582
    }
}

583 584 585 586 587 588
static void
pointer_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkLabel *label = GTK_LABEL (data);
  gchar *str;
  gpointer ptr;
Matthias Clasen's avatar
Matthias Clasen committed
589

590 591 592 593 594 595 596
  g_object_get (object, pspec->name, &ptr, NULL);

  str = g_strdup_printf ("Pointer: %p", ptr);
  gtk_label_set_text (label, str);
  g_free (str);
}

597 598
static gchar *
object_label (GObject *obj, GParamSpec *pspec)
599 600 601 602 603
{
  const gchar *name;

  if (obj)
    name = g_type_name (G_TYPE_FROM_INSTANCE (obj));
604 605
  else if (pspec)
    name = g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec));
606 607 608 609 610
  else
    name = "unknown";
  return g_strdup_printf ("Object: %p (%s)", obj, name);
}

611 612 613
static void
object_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
614
  GtkWidget *label, *button;
615 616
  gchar *str;
  GObject *obj;
Matthias Clasen's avatar
Matthias Clasen committed
617 618

  GList *children = gtk_container_get_children (GTK_CONTAINER (data));
619 620
  label = GTK_WIDGET (children->data);
  button = GTK_WIDGET (children->next->data);
621
  g_object_get (object, pspec->name, &obj, NULL);
622
  g_list_free (children);
623

624
  str = object_label (obj, pspec);
Matthias Clasen's avatar
Matthias Clasen committed
625

626 627 628
  gtk_label_set_text (GTK_LABEL (label), str);
  gtk_widget_set_sensitive (button, G_IS_OBJECT (obj));

Morten Welinder's avatar
Morten Welinder committed
629 630 631
  if (obj)
    g_object_unref (obj);

632 633 634
  g_free (str);
}

635
static void
636 637 638 639 640 641
model_destroy (gpointer data)
{
  g_object_steal_data (data, "model-object");
  gtk_widget_destroy (data);
}

642
static void
643 644 645 646 647
window_destroy (gpointer data)
{
  g_object_steal_data (data, "prop-editor-win");
}

648
static void
Matthias Clasen's avatar
Matthias Clasen committed
649 650
object_properties (GtkWidget *button,
                   GObject   *object)
651 652 653 654 655 656
{
  gchar *name;
  GObject *obj;

  name = (gchar *) g_object_get_data (G_OBJECT (button), "property-name");
  g_object_get (object, name, &obj, NULL);
Matthias Clasen's avatar
Matthias Clasen committed
657
  if (G_IS_OBJECT (obj))
658 659
    create_prop_editor (obj, 0);
}
Matthias Clasen's avatar
Matthias Clasen committed
660

661 662 663 664 665 666
static void
rgba_modified (GtkColorButton *cb, gpointer data)
{
  ObjectProperty *p = data;
  GdkRGBA color;

667
  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cb), &color);
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692

  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, &color, NULL);
    }
  else
    g_object_set (p->obj, p->spec->name, &color, NULL);
}

static void
rgba_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkColorButton *cb = GTK_COLOR_BUTTON (data);
  GValue val = G_VALUE_INIT;
  GdkRGBA *color;
  GdkRGBA cb_color;

  g_value_init (&val, GDK_TYPE_RGBA);
  get_property_value (object, pspec, &val);

  color = g_value_get_boxed (&val);
693
  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cb), &cb_color);
694 695 696 697

  if (color != NULL && !gdk_rgba_equal (color, &cb_color))
    {
      block_controller (G_OBJECT (cb));
698
      gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cb), color);
699 700 701 702 703 704
      unblock_controller (G_OBJECT (cb));
    }

  g_value_unset (&val);
}

705 706 707 708
static void
color_modified (GtkColorButton *cb, gpointer data)
{
  ObjectProperty *p = data;
709
  GValue val = G_VALUE_INIT;
710

711 712
  g_value_init (&val, GDK_TYPE_COLOR);
  g_object_get_property (G_OBJECT (cb), "color", &val);
713 714 715 716 717 718

  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

719 720
      gtk_container_child_set_property (GTK_CONTAINER (parent),
			                widget, p->spec->name, &val);
721 722
    }
  else
723 724 725
    g_object_set_property (p->obj, p->spec->name, &val);

  g_value_unset (&val);
726 727 728 729 730 731
}

static void
color_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkColorButton *cb = GTK_COLOR_BUTTON (data);
Javier Jardón's avatar
Javier Jardón committed
732
  GValue val = G_VALUE_INIT;
733

734
  g_value_init (&val, GDK_TYPE_COLOR);
735 736
  get_property_value (object, pspec, &val);

737
  if (g_value_get_boxed (&val))
738 739
    {
      block_controller (G_OBJECT (cb));
740
      g_object_set_property (G_OBJECT (cb), "color", &val);
741 742 743 744 745 746
      unblock_controller (G_OBJECT (cb));
    }

  g_value_unset (&val);
}

747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
static void
font_modified (GtkFontChooser *fb, GParamSpec *pspec, gpointer data)
{
  ObjectProperty *p = data;
  PangoFontDescription *font_desc;

  font_desc = gtk_font_chooser_get_font_desc (fb);

  if (is_child_property (p->spec))
    {
      GtkWidget *widget = GTK_WIDGET (p->obj);
      GtkWidget *parent = gtk_widget_get_parent (widget);

      gtk_container_child_set (GTK_CONTAINER (parent),
                               widget, p->spec->name, font_desc, NULL);
    }
  else
    g_object_set (p->obj, p->spec->name, font_desc, NULL);

  pango_font_description_free (font_desc);
}

static void
font_changed (GObject *object, GParamSpec *pspec, gpointer data)
{
  GtkFontChooser *fb = GTK_FONT_CHOOSER (data);
Javier Jardón's avatar
Javier Jardón committed
773
  GValue val = G_VALUE_INIT;
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
  const PangoFontDescription *font_desc;
  PangoFontDescription *fb_font_desc;

  g_value_init (&val, PANGO_TYPE_FONT_DESCRIPTION);
  get_property_value (object, pspec, &val);

  font_desc = g_value_get_boxed (&val);
  fb_font_desc = gtk_font_chooser_get_font_desc (fb);

  if (font_desc == NULL ||
      (fb_font_desc != NULL &&
       !pango_font_description_equal (fb_font_desc, font_desc)))
    {
      block_controller (G_OBJECT (fb));
      gtk_font_chooser_set_font_desc (fb, font_desc);
      unblock_controller (G_OBJECT (fb));
    }

  g_value_unset (&val);
  pango_font_description_free (fb_font_desc);
}


797
static GtkWidget *
Matthias Clasen's avatar
Matthias Clasen committed
798 799 800
property_widget (GObject    *object,
                 GParamSpec *spec,
                 gboolean    can_modify)
801 802
{
  GtkWidget *prop_edit;
803 804
  GtkAdjustment *adj;
  gchar *msg;
805 806 807
  GType type = G_PARAM_SPEC_TYPE (spec);

  if (type == G_TYPE_PARAM_INT)
808
    {
Javier Jardón's avatar
Javier Jardón committed
809 810 811 812 813 814 815
      adj = gtk_adjustment_new (G_PARAM_SPEC_INT (spec)->default_value,
                                G_PARAM_SPEC_INT (spec)->minimum,
                                G_PARAM_SPEC_INT (spec)->maximum,
                                1,
                                MAX ((G_PARAM_SPEC_INT (spec)->maximum - G_PARAM_SPEC_INT (spec)->minimum) / 10, 1),
                                0.0);

816
      prop_edit = gtk_spin_button_new (adj, 1.0, 0);
Matthias Clasen's avatar
Matthias Clasen committed
817 818 819 820 821

      g_object_connect_property (object, spec,
                                 G_CALLBACK (int_changed),
                                 adj, G_OBJECT (adj));

822
      if (can_modify)
Matthias Clasen's avatar
Matthias Clasen committed
823 824
        connect_controller (G_OBJECT (adj), "value_changed",
                            object, spec, G_CALLBACK (int_modified));
825 826 827
    }
  else if (type == G_TYPE_PARAM_UINT)
    {
Javier Jardón's avatar
Javier Jardón committed
828 829 830 831 832 833 834
      adj = gtk_adjustment_new (G_PARAM_SPEC_UINT (spec)->default_value,
                                G_PARAM_SPEC_UINT (spec)->minimum,
                                G_PARAM_SPEC_UINT (spec)->maximum,
                                1,
                                MAX ((G_PARAM_SPEC_UINT (spec)->maximum - G_PARAM_SPEC_UINT (spec)->minimum) / 10, 1),
                                0.0);

835
      prop_edit = gtk_spin_button_new (adj, 1.0, 0);
Matthias Clasen's avatar
Matthias Clasen committed
836 837 838 839 840

      g_object_connect_property (object, spec,
                                 G_CALLBACK (uint_changed),
                                 adj, G_OBJECT (adj));

841
      if (can_modify)
Matthias Clasen's avatar
Matthias Clasen committed
842 843
        connect_controller (G_OBJECT (adj), "value_changed",
                            object, spec, G_CALLBACK (uint_modified));
844 845 846
    }
  else if (type == G_TYPE_PARAM_FLOAT)
    {
Javier Jardón's avatar
Javier Jardón committed
847 848 849 850 851 852
      adj = gtk_adjustment_new (G_PARAM_SPEC_FLOAT (spec)->default_value,
                                G_PARAM_SPEC_FLOAT (spec)->minimum,
                                G_PARAM_SPEC_FLOAT (spec)->maximum,
                                0.1,
                                MAX ((G_PARAM_SPEC_FLOAT (spec)->maximum - G_PARAM_SPEC_FLOAT (spec)->minimum) / 10, 0.1),
                                0.0);
853

854
      prop_edit = gtk_spin_button_new (adj, 0.1, 2);
Matthias Clasen's avatar
Matthias Clasen committed
855 856 857 858 859

      g_object_connect_property (object, spec,
                                 G_CALLBACK (float_changed),
                                 adj, G_OBJECT (adj));

860
      if (can_modify)
Matthias Clasen's avatar
Matthias Clasen committed
861 862
        connect_controller (G_OBJECT (adj), "value_changed",
                            object, spec, G_CALLBACK (float_modified));
863 864 865
    }
  else if (type == G_TYPE_PARAM_DOUBLE)
    {
Javier Jardón's avatar
Javier Jardón committed
866 867 868 869 870 871 872
      adj = gtk_adjustment_new (G_PARAM_SPEC_DOUBLE (spec)->default_value,
                                G_PARAM_SPEC_DOUBLE (spec)->minimum,
                                G_PARAM_SPEC_DOUBLE (spec)->maximum,
                                0.1,
                                MAX ((G_PARAM_SPEC_DOUBLE (spec)->maximum - G_PARAM_SPEC_DOUBLE (spec)->minimum) / 10, 0.1),
                                0.0);

873
      prop_edit = gtk_spin_button_new (adj, 0.1, 2);
Matthias Clasen's avatar
Matthias Clasen committed
874 875 876 877 878

      g_object_connect_property (object, spec,
                                 G_CALLBACK (double_changed),
                                 adj, G_OBJECT (adj));

879
      if (can_modify)
Matthias Clasen's avatar
Matthias Clasen committed
880 881
        connect_controller (G_OBJECT (adj), "value_changed",
                            object, spec, G_CALLBACK (double_modified));
882 883 884
    }
  else if (type == G_TYPE_PARAM_STRING)
    {
885
      prop_edit = gtk_entry_new ();
Matthias Clasen's avatar
Matthias Clasen committed
886 887 888 889 890

      g_object_connect_property (object, spec,
                                 G_CALLBACK (string_changed),
                                 prop_edit, G_OBJECT (prop_edit));

891
      if (can_modify)
Matthias Clasen's avatar
Matthias Clasen committed
892 893
        connect_controller (G_OBJECT (prop_edit), "changed",
                            object, spec, G_CALLBACK (string_modified));
894 895 896
    }
  else if (type == G_TYPE_PARAM_BOOLEAN)
    {
897
      prop_edit = gtk_toggle_button_new_with_label ("");
Matthias Clasen's avatar
Matthias Clasen committed
898 899 900 901 902

      g_object_connect_property (object, spec,
                                 G_CALLBACK (bool_changed),
                                 prop_edit, G_OBJECT (prop_edit));

903
      if (can_modify)
Matthias Clasen's avatar
Matthias Clasen committed
904 905
        connect_controller (G_OBJECT (prop_edit), "toggled",
                            object, spec, G_CALLBACK (bool_modified));
906 907 908
    }
  else if (type == G_TYPE_PARAM_ENUM)
    {
909
      {
Matthias Clasen's avatar
Matthias Clasen committed
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
        GEnumClass *eclass;
        gint j;

        prop_edit = gtk_combo_box_text_new ();

        eclass = G_ENUM_CLASS (g_type_class_ref (spec->value_type));

        j = 0;
        while (j < eclass->n_values)
          {
            gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (prop_edit),
                                            eclass->values[j].value_name);
            ++j;
          }

        g_type_class_unref (eclass);

        g_object_connect_property (object, spec,
                                   G_CALLBACK (enum_changed),
                                   prop_edit, G_OBJECT (prop_edit));

        if (can_modify)
          connect_controller (G_OBJECT (prop_edit), "changed",
                              object, spec, G_CALLBACK (enum_modified));
934
      }
935
    }
936 937 938
  else if (type == G_TYPE_PARAM_FLAGS)
    {
      {
Matthias Clasen's avatar
Matthias Clasen committed
939 940 941 942 943 944 945 946 947 948 949 950
        GFlagsClass *fclass;
        gint j;

        prop_edit = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);

        fclass = G_FLAGS_CLASS (g_type_class_ref (spec->value_type));

        for (j = 0; j < fclass->n_values; j++)
          {
            GtkWidget *b;

            b = gtk_check_button_new_with_label (fclass->values[j].value_name);
951
            g_object_set_data (G_OBJECT (b), "index", GINT_TO_POINTER (j));
Matthias Clasen's avatar
Matthias Clasen committed
952 953 954 955 956 957 958 959 960 961 962 963
            gtk_widget_show (b);
            gtk_box_pack_start (GTK_BOX (prop_edit), b, FALSE, FALSE, 0);
            if (can_modify)
              connect_controller (G_OBJECT (b), "toggled",
                                  object, spec, G_CALLBACK (flags_modified));
          }

        g_type_class_unref (fclass);

        g_object_connect_property (object, spec,
                                   G_CALLBACK (flags_changed),
                                   prop_edit, G_OBJECT (prop_edit));
964 965
      }
    }
966 967
  else if (type == G_TYPE_PARAM_UNICHAR)
    {
968 969
      prop_edit = gtk_entry_new ();
      gtk_entry_set_max_length (GTK_ENTRY (prop_edit), 1);
Matthias Clasen's avatar
Matthias Clasen committed
970

971
      g_object_connect_property (object, spec,
Matthias Clasen's avatar
Matthias Clasen committed
972 973 974
                                 G_CALLBACK (unichar_changed),
                                 prop_edit, G_OBJECT (prop_edit));

975
      if (can_modify)
Matthias Clasen's avatar
Matthias Clasen committed
976 977
        connect_controller (G_OBJECT (prop_edit), "changed",
                            object, spec, G_CALLBACK (unichar_modified));
978 979 980
    }
  else if (type == G_TYPE_PARAM_POINTER)
    {
981
      prop_edit = gtk_label_new ("");
Matthias Clasen's avatar
Matthias Clasen committed
982 983 984 985

      g_object_connect_property (object, spec,
                                 G_CALLBACK (pointer_changed),
                                 prop_edit, G_OBJECT (prop_edit));
986 987 988
    }
  else if (type == G_TYPE_PARAM_OBJECT)
    {
989 990
      GtkWidget *label, *button;

991
      prop_edit = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
992 993 994

      label = gtk_label_new ("");
      button = gtk_button_new_with_label ("Properties");
995 996 997 998
      g_object_set_data (G_OBJECT (button), "property-name", (gpointer) spec->name);
      g_signal_connect (button, "clicked",
                        G_CALLBACK (object_properties),
                        object);
999 1000 1001

      gtk_container_add (GTK_CONTAINER (prop_edit), label);
      gtk_container_add (GTK_CONTAINER (prop_edit), button);
1002

1003
      g_object_connect_property (object, spec,
Matthias Clasen's avatar
Matthias Clasen committed
1004 1005
                                 G_CALLBACK (object_changed),
                                 prop_edit, G_OBJECT (label));
1006 1007 1008

      /* The Properties button is not really modifying, anyway */
      can_modify = TRUE;
1009
    }
1010 1011 1012 1013
  else if (type == G_TYPE_PARAM_BOXED &&
           G_PARAM_SPEC_VALUE_TYPE (spec) == GDK_TYPE_RGBA)
    {
      prop_edit = gtk_color_button_new ();
1014
      gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (prop_edit), TRUE);
1015 1016 1017 1018 1019 1020 1021 1022 1023

      g_object_connect_property (object, spec,
                                 G_CALLBACK (rgba_changed),
                                 prop_edit, G_OBJECT (prop_edit));

      if (can_modify)
        connect_controller (G_OBJECT (prop_edit), "color-set",
                            object, spec, G_CALLBACK (rgba_modified));
    }
1024 1025 1026 1027 1028 1029
  else if (type == G_TYPE_PARAM_BOXED &&
           G_PARAM_SPEC_VALUE_TYPE (spec) == GDK_TYPE_COLOR)
    {
      prop_edit = gtk_color_button_new ();

      g_object_connect_property (object, spec,
Matthias Clasen's avatar
Matthias Clasen committed
1030 1031
                                 G_CALLBACK (color_changed),
                                 prop_edit, G_OBJECT (prop_edit));
1032 1033

      if (can_modify)
Matthias Clasen's avatar
Matthias Clasen committed
1034 1035
        connect_controller (G_OBJECT (prop_edit), "color-set",
                            object, spec, G_CALLBACK (color_modified));
1036
    }
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
  else if (type == G_TYPE_PARAM_BOXED &&
           G_PARAM_SPEC_VALUE_TYPE (spec) == PANGO_TYPE_FONT_DESCRIPTION)
    {
      prop_edit = gtk_font_button_new ();

      g_object_connect_property (object, spec,
                                 G_CALLBACK (font_changed),
                                 prop_edit, G_OBJECT (prop_edit));

      if (can_modify)
        connect_controller (G_OBJECT (prop_edit), "notify::font-desc",
                            object, spec, G_CALLBACK (font_modified));
    }
1050
  else
Matthias Clasen's avatar
Matthias Clasen committed
1051
    {
1052
      msg = g_strdup_printf ("uneditable property type: %s",
Matthias Clasen's avatar
Matthias Clasen committed
1053 1054
                             g_type_name (G_PARAM_SPEC_TYPE (spec)));
      prop_edit = gtk_label_new (msg);
1055
      g_free (msg);
1056 1057
      gtk_widget_set_halign (prop_edit, GTK_ALIGN_START);
      gtk_widget_set_valign (prop_edit, GTK_ALIGN_CENTER);
1058
    }
Matthias Clasen's avatar
Matthias Clasen committed
1059

1060 1061 1062 1063 1064 1065
  if (!can_modify)
    gtk_widget_set_sensitive (prop_edit, FALSE);

  if (g_param_spec_get_blurb (spec))
    gtk_widget_set_tooltip_text (prop_edit, g_param_spec_get_blurb (spec));

1066 1067 1068 1069
  return prop_edit;
}

static GtkWidget *
1070
properties_from_type (GObject *object,
Matthias Clasen's avatar
Matthias Clasen committed
1071
                      GType    type)
1072 1073 1074
{
  GtkWidget *prop_edit;
  GtkWidget *label;
1075
  GtkWidget *sw;
1076
  GtkWidget *vbox;
1077
  GtkWidget *grid;
1078
  GParamSpec **specs;
1079
  guint n_specs;
1080
  int i;
1081

1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
  if (G_TYPE_IS_INTERFACE (type))
    {
      gpointer vtable = g_type_default_interface_peek (type);
      specs = g_object_interface_list_properties (vtable, &n_specs);
    }
  else
    {
      GObjectClass *class = G_OBJECT_CLASS (g_type_class_peek (type));
      specs = g_object_class_list_properties (class, &n_specs);
    }
Matthias Clasen's avatar
Matthias Clasen committed
1092

1093 1094
  if (n_specs == 0) {
    g_free (specs);
1095
    return NULL;
1096
  }
Matthias Clasen's avatar
Matthias Clasen committed
1097

1098 1099 1100
  grid = gtk_grid_new ();
  gtk_grid_set_column_spacing (GTK_GRID (grid), 10);
  gtk_grid_set_row_spacing (GTK_GRID (grid), 3);
1101 1102 1103 1104 1105 1106

  i = 0;
  while (i < n_specs)
    {
      GParamSpec *spec = specs[i];
      gboolean can_modify;
Matthias Clasen's avatar
Matthias Clasen committed
1107

1108 1109 1110 1111
      prop_edit = NULL;

      can_modify = ((spec->flags & G_PARAM_WRITABLE) != 0 &&
                    (spec->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
Matthias Clasen's avatar
Matthias Clasen committed
1112

1113 1114 1115 1116 1117 1118
      if ((spec->flags & G_PARAM_READABLE) == 0)
        {
          /* can't display unreadable properties */
          ++i;
          continue;
        }
Matthias Clasen's avatar
Matthias Clasen committed
1119

1120
      if (spec->owner_type != type)
Matthias Clasen's avatar
Matthias Clasen committed
1121 1122 1123 1124 1125
        {
          /* we're only interested in params of type */
          ++i;
          continue;
        }
1126

Tim Janik's avatar
Tim Janik committed
1127
      label = gtk_label_new (g_param_spec_get_nick (spec));
1128 1129
      gtk_widget_set_halign (label, GTK_ALIGN_START);
      gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1130
      gtk_grid_attach (GTK_GRID (grid), label, 0, i, 1, 1);
Matthias Clasen's avatar
Matthias Clasen committed
1131

1132
      prop_edit = property_widget (object, spec, can_modify);
1133
      gtk_grid_attach (GTK_GRID (grid), prop_edit, 1, i, 1, 1);
1134

1135 1136
      /* set initial value */
      g_object_notify (object, spec->name);
1137

1138 1139 1140
      ++i;
    }

1141

1142
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1143
  gtk_box_pack_start (GTK_BOX (vbox), grid, FALSE, FALSE, 0);
1144 1145 1146 1147

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
Matthias Clasen's avatar
Matthias Clasen committed
1148

1149
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), vbox);
1150 1151 1152

  g_free (specs);

1153 1154 1155
  return sw;
}

1156
static GtkWidget *
1157
child_properties_from_object (GObject *object)
1158 1159 1160 1161 1162
{
  GtkWidget *prop_edit;
  GtkWidget *label;
  GtkWidget *sw;
  GtkWidget *vbox;
1163
  GtkWidget *grid;
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
  GtkWidget *parent;
  GParamSpec **specs;
  guint n_specs;
  gint i;

  if (!GTK_IS_WIDGET (object))
    return NULL;

  parent = gtk_widget_get_parent (GTK_WIDGET (object));

  if (!parent)
    return NULL;

  specs = gtk_container_class_list_child_properties (G_OBJECT_GET_CLASS (parent), &n_specs);

1179 1180 1181
  grid = gtk_grid_new ();
  gtk_grid_set_column_spacing (GTK_GRID (grid), 10);
  gtk_grid_set_row_spacing (GTK_GRID (grid), 3);
1182 1183 1184 1185 1186 1187

  i = 0;
  while (i < n_specs)
    {
      GParamSpec *spec = specs[i];
      gboolean can_modify;
Matthias Clasen's avatar
Matthias Clasen committed
1188

1189 1190 1191 1192
      prop_edit = NULL;

      can_modify = ((spec->flags & G_PARAM_WRITABLE) != 0 &&
                    (spec->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
Matthias Clasen's avatar
Matthias Clasen committed
1193

1194 1195 1196 1197 1198 1199
      if ((spec->flags & G_PARAM_READABLE) == 0)
        {
          /* can't display unreadable properties */
          ++i;
          continue;
        }
Matthias Clasen's avatar
Matthias Clasen committed
1200

1201
      label = gtk_label_new (g_param_spec_get_nick (spec));
1202 1203
      gtk_widget_set_halign (label, GTK_ALIGN_START);
      gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1204
      gtk_grid_attach (GTK_GRID (grid), label, 0, i, 1, 1);
Matthias Clasen's avatar
Matthias Clasen committed
1205

1206 1207
      mark_child_property (spec);
      prop_edit = property_widget (object, spec, can_modify);
1208
      gtk_grid_attach (GTK_GRID (grid), prop_edit, 1, i, 1, 1);
1209

1210 1211
      /* set initial value */
      gtk_widget_child_notify (GTK_WIDGET (object), spec->name);
1212

1213 1214 1215
      ++i;
    }

1216
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1217
  gtk_box_pack_start (GTK_BOX (vbox), grid, FALSE, FALSE, 0);
1218 1219 1220 1221

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
Matthias Clasen's avatar
Matthias Clasen committed
1222

1223 1224 1225 1226 1227 1228 1229
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), vbox);

  g_free (specs);

  return sw;
}

1230
static void
Matthias Clasen's avatar
Matthias Clasen committed
1231 1232
child_properties (GtkWidget *button,
                  GObject   *object)
1233 1234 1235 1236 1237
{
  create_prop_editor (object, 0);
}

static GtkWidget *
1238
children_from_object (GObject *object)
1239 1240
{
  GList *children, *c;
1241
  GtkWidget *grid, *label, *prop_edit, *button, *vbox, *sw;
1242 1243 1244 1245 1246 1247 1248 1249
  gchar *str;
  gint i;

  if (!GTK_IS_CONTAINER (object))
    return NULL;

  children = gtk_container_get_children (GTK_CONTAINER (object));

1250 1251 1252
  grid = gtk_grid_new ();
  gtk_grid_set_column_spacing (GTK_GRID (grid), 10);
  gtk_grid_set_row_spacing (GTK_GRID (grid), 3);
Matthias Clasen's avatar
Matthias Clasen committed
1253

1254 1255 1256 1257 1258
  for (c = children, i = 0; c; c = c->next, i++)
    {
      object = c->data;

      label = gtk_label_new ("Child");
1259 1260
      gtk_widget_set_halign (label, GTK_ALIGN_START);
      gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1261
      gtk_grid_attach (GTK_GRID (grid), label, 0, i, 1, 1);
1262

1263
      prop_edit = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
1264

1265
      str = object_label (object, NULL);
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
      label = gtk_label_new (str);
      g_free (str);
      button = gtk_button_new_with_label ("Properties");
      g_signal_connect (button, "clicked",
                        G_CALLBACK (child_properties),
                        object);

      gtk_container_add (GTK_CONTAINER (prop_edit), label);
      gtk_container_add (GTK_CONTAINER (prop_edit), button);

1276
      gtk_grid_attach (GTK_GRID (grid), prop_edit, 1, i, 1, 1);