widgets.c 58.7 KB
Newer Older
1 2
#include "config.h"

3 4 5
#define GDK_DISABLE_DEPRECATION_WARNINGS
#undef GTK_DISABLE_DEPRECATED

6
#include <gtk/gtkunixprint.h>
7
#include <gdk/gdkkeysyms.h>
8 9
#include <X11/Xatom.h>
#include <gdkx.h>
10
#include "widgets.h"
11
#include "gtkgears.h"
12

13 14 15 16 17 18 19
#define SMALL_WIDTH  240
#define SMALL_HEIGHT 75
#define MEDIUM_WIDTH 240
#define MEDIUM_HEIGHT 165
#define LARGE_WIDTH 240
#define LARGE_HEIGHT 240

20 21
static WidgetInfo *
new_widget_info (const char *name,
22 23
		 GtkWidget  *widget,
		 WidgetSize  size)
24 25 26 27 28
{
  WidgetInfo *info;

  info = g_new0 (WidgetInfo, 1);
  info->name = g_strdup (name);
29
  info->size = size;
30 31 32
  if (GTK_IS_WINDOW (widget))
    {
      info->window = widget;
33
      gtk_window_set_resizable (GTK_WINDOW (info->window), FALSE);
34 35
      info->include_decorations = TRUE;
    }
36 37 38 39 40 41
  else if (GTK_IS_POPOVER (widget))
    {
      GtkWidget *button;

      info->snapshot_popover = TRUE;
      info->window = gtk_window_new ();
42
      gtk_window_set_default_size (GTK_WINDOW (info->window), 200, 200);
43 44 45 46 47 48
      gtk_window_set_decorated (GTK_WINDOW (info->window), FALSE);
      info->include_decorations = TRUE;
      button = gtk_menu_button_new ();
      gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), widget);
      gtk_window_set_child (GTK_WINDOW (info->window), button);
    }
49 50
  else
    {
51
      info->window = gtk_window_new ();
52
      gtk_window_set_decorated (GTK_WINDOW (info->window), FALSE);
53
      info->include_decorations = FALSE;
54
      gtk_window_set_child (GTK_WINDOW (info->window), widget);
55
    }
56 57
  info->no_focus = TRUE;

58 59 60
  switch (size)
    {
    case SMALL:
61
      gtk_widget_set_size_request (info->window, 240, 75);
62 63
      break;
    case MEDIUM:
64
      gtk_widget_set_size_request (info->window, 240, 165);
65 66
      break;
    case LARGE:
67
      gtk_widget_set_size_request (info->window, 240, 240);
68 69
      break;
    default:
70
      break;
71 72
    }

73 74 75
  return info;
}

76 77 78 79 80 81 82 83 84
static void
add_margin (GtkWidget *widget)
{
  gtk_widget_set_margin_start (widget, 10);
  gtk_widget_set_margin_end (widget, 10);
  gtk_widget_set_margin_top (widget, 10);
  gtk_widget_set_margin_bottom (widget, 10);
}

85 86 87 88
static WidgetInfo *
create_button (void)
{
  GtkWidget *widget;
89

90
  widget = gtk_button_new_with_mnemonic ("_Button");
Timm Bäder's avatar
Timm Bäder committed
91 92
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
93
  add_margin (widget);
94

Timm Bäder's avatar
Timm Bäder committed
95
  return new_widget_info ("button", widget, SMALL);
96 97
}

98 99 100 101 102 103 104 105 106
static WidgetInfo *
create_switch (void)
{
  GtkWidget *widget;
  GtkWidget *sw;

  widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
  sw = gtk_switch_new ();
  gtk_switch_set_active (GTK_SWITCH (sw), TRUE);
107
  gtk_box_append (GTK_BOX (widget), sw);
108
  sw = gtk_switch_new ();
109
  gtk_box_append (GTK_BOX (widget), sw);
110

Timm Bäder's avatar
Timm Bäder committed
111 112
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
113

Timm Bäder's avatar
Timm Bäder committed
114
  return new_widget_info ("switch", widget, SMALL);
115 116
}

117 118 119 120 121 122 123
static WidgetInfo *
create_toggle_button (void)
{
  GtkWidget *widget;

  widget = gtk_toggle_button_new_with_mnemonic ("_Toggle Button");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
Timm Bäder's avatar
Timm Bäder committed
124 125
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
126

Timm Bäder's avatar
Timm Bäder committed
127
  return new_widget_info ("toggle-button", widget, SMALL);
128 129 130 131 132 133
}

static WidgetInfo *
create_check_button (void)
{
  GtkWidget *widget;
134 135
  GtkWidget *button;
  GtkWidget *group;
136

137
  widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
Timm Bäder's avatar
Timm Bäder committed
138 139
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
140

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
  button = gtk_check_button_new_with_mnemonic ("_Check Button");
  gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE);
  gtk_box_append (GTK_BOX (widget), button);

  button = gtk_check_button_new_with_mnemonic ("_Check Button");
  gtk_box_append (GTK_BOX (widget), button);

  button = gtk_check_button_new_with_mnemonic ("Radio Button");
  gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE);
  gtk_box_append (GTK_BOX (widget), button);
  group = button;

  button = gtk_check_button_new_with_mnemonic ("Radio Button");
  gtk_box_append (GTK_BOX (widget), button);
  gtk_check_button_set_group (GTK_CHECK_BUTTON (button), GTK_CHECK_BUTTON (group));

  return new_widget_info ("check-button", widget, MEDIUM);
158 159
}

Matthias Clasen's avatar
Matthias Clasen committed
160 161 162 163 164 165
static WidgetInfo *
create_link_button (void)
{
  GtkWidget *widget;

  widget = gtk_link_button_new_with_label ("http://www.gtk.org", "Link Button");
Timm Bäder's avatar
Timm Bäder committed
166 167
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
Matthias Clasen's avatar
Matthias Clasen committed
168

Timm Bäder's avatar
Timm Bäder committed
169
  return new_widget_info ("link-button", widget, SMALL);
Matthias Clasen's avatar
Matthias Clasen committed
170 171
}

172 173 174 175 176
static WidgetInfo *
create_menu_button (void)
{
  GtkWidget *widget;
  GtkWidget *menu;
177
  GtkWidget *vbox;
178 179

  widget = gtk_menu_button_new ();
180
  gtk_menu_button_set_icon_name (GTK_MENU_BUTTON (widget), "emblem-system-symbolic");
Matthias Clasen's avatar
Matthias Clasen committed
181
  menu = gtk_popover_new ();
182
  gtk_menu_button_set_popover (GTK_MENU_BUTTON (widget), menu);
183

184
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
185
  gtk_box_append (GTK_BOX (vbox), widget);
186 187 188
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);

189
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Menu Button"));
190

191 192
  add_margin (vbox);

193
  return new_widget_info ("menu-button", vbox, SMALL);
194 195
}

Matthias Clasen's avatar
Matthias Clasen committed
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
#define G_TYPE_TEST_PERMISSION      (g_test_permission_get_type ())
#define G_TEST_PERMISSION(inst)     (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
                                     G_TYPE_TEST_PERMISSION,             \
                                     GTestPermission))
#define G_IS_TEST_PERMISSION(inst)  (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
                                     G_TYPE_TEST_PERMISSION))

typedef struct _GTestPermission GTestPermission;
typedef struct _GTestPermissionClass GTestPermissionClass;

struct _GTestPermission
{
  GPermission parent;

  gboolean success;
};

struct _GTestPermissionClass
{
  GPermissionClass parent_class;
};

G_DEFINE_TYPE (GTestPermission, g_test_permission, G_TYPE_PERMISSION)

static void
g_test_permission_init (GTestPermission *test)
{
  g_permission_impl_update (G_PERMISSION (test), FALSE, TRUE, TRUE);
}

static void
g_test_permission_class_init (GTestPermissionClass *class)
{
}

static WidgetInfo *
create_lockbutton (void)
{
234
  GtkWidget *vbox;
Matthias Clasen's avatar
Matthias Clasen committed
235 236 237 238
  GtkWidget *widget;

  widget = gtk_lock_button_new (g_object_new (G_TYPE_TEST_PERMISSION, NULL));

239
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
240
  gtk_box_append (GTK_BOX (vbox), widget);
241
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Lock Button"));
242 243 244 245
  gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER);

  return new_widget_info ("lock-button", vbox, SMALL);
Matthias Clasen's avatar
Matthias Clasen committed
246 247
}

248 249 250 251
static WidgetInfo *
create_entry (void)
{
  GtkWidget *widget;
252

253
  widget = gtk_entry_new ();
Timm Bäder's avatar
Timm Bäder committed
254 255
  gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
256
  gtk_editable_set_text (GTK_EDITABLE (widget), "Entry");
257
  gtk_editable_set_position (GTK_EDITABLE (widget), -1);
258

259 260
  add_margin (widget);

Timm Bäder's avatar
Timm Bäder committed
261
  return  new_widget_info ("entry", widget, SMALL);
262 263
}

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
static WidgetInfo *
create_password_entry (void)
{
  GtkWidget *widget;

  widget = gtk_password_entry_new ();
  gtk_password_entry_set_show_peek_icon (GTK_PASSWORD_ENTRY (widget), TRUE);
  gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
  gtk_editable_set_text (GTK_EDITABLE (widget), "Entry");
  gtk_editable_set_position (GTK_EDITABLE (widget), -1);

  add_margin (widget);

  return  new_widget_info ("password-entry", widget, SMALL);
}

281 282 283 284 285 286
static WidgetInfo *
create_search_entry (void)
{
  GtkWidget *widget;

  widget = gtk_search_entry_new ();
Timm Bäder's avatar
Timm Bäder committed
287 288
  gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
289 290 291
  g_object_set (widget, "placeholder-text", "Search…", NULL);

  add_margin (widget);
292

Timm Bäder's avatar
Timm Bäder committed
293
  return  new_widget_info ("search-entry", widget, SMALL);
294 295
}

296 297 298 299 300 301
static WidgetInfo *
create_label (void)
{
  GtkWidget *widget;

  widget = gtk_label_new ("Label");
Timm Bäder's avatar
Timm Bäder committed
302 303
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
304

Timm Bäder's avatar
Timm Bäder committed
305
  return new_widget_info ("label", widget, SMALL);
306 307 308 309 310 311
}

static WidgetInfo *
create_combo_box_entry (void)
{
  GtkWidget *widget;
Javier Jardón's avatar
Javier Jardón committed
312
  GtkWidget *child;
313 314 315 316
  GtkTreeModel *model;

  model = (GtkTreeModel *)gtk_list_store_new (1, G_TYPE_STRING);
  widget = g_object_new (GTK_TYPE_COMBO_BOX,
317 318 319 320
                         "has-entry", TRUE,
                         "model", model,
                         "entry-text-column", 0,
                         NULL);
321 322
  g_object_unref (model);

323
  child = gtk_combo_box_get_child (GTK_COMBO_BOX (widget));
324
  gtk_editable_set_text (GTK_EDITABLE (child), "Combo Box Entry");
Timm Bäder's avatar
Timm Bäder committed
325 326
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
327

Timm Bäder's avatar
Timm Bäder committed
328
  return new_widget_info ("combo-box-entry", widget, SMALL);
329 330
}

Matthias Clasen's avatar
Matthias Clasen committed
331 332 333 334
static WidgetInfo *
create_combo_box (void)
{
  GtkWidget *widget;
Matthias Clasen's avatar
Matthias Clasen committed
335 336 337 338 339 340 341
  GtkCellRenderer *cell;
  GtkListStore *store;

  widget = gtk_combo_box_new ();
  gtk_cell_layout_clear (GTK_CELL_LAYOUT (widget));
  cell = gtk_cell_renderer_text_new ();
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), cell, FALSE);
342
  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), cell, "text", 0, NULL);
Matthias Clasen's avatar
Matthias Clasen committed
343

344 345
  store = gtk_list_store_new (1, G_TYPE_STRING);
  gtk_list_store_insert_with_values (store, NULL, -1, 0, "Combo Box", -1);
Matthias Clasen's avatar
Matthias Clasen committed
346
  gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
Matthias Clasen's avatar
Matthias Clasen committed
347 348

  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
Timm Bäder's avatar
Timm Bäder committed
349 350
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
Matthias Clasen's avatar
Matthias Clasen committed
351

Timm Bäder's avatar
Timm Bäder committed
352
  return new_widget_info ("combo-box", widget, SMALL);
Matthias Clasen's avatar
Matthias Clasen committed
353 354
}

Matthias Clasen's avatar
Matthias Clasen committed
355 356 357 358 359 360 361 362 363
static WidgetInfo *
create_combo_box_text (void)
{
  GtkWidget *widget;

  widget = gtk_combo_box_text_new ();

  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Combo Box Text");
  gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
Timm Bäder's avatar
Timm Bäder committed
364 365
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
Matthias Clasen's avatar
Matthias Clasen committed
366

Timm Bäder's avatar
Timm Bäder committed
367
  return new_widget_info ("combo-box-text", widget, SMALL);
Matthias Clasen's avatar
Matthias Clasen committed
368 369
}

370 371 372 373 374 375 376 377 378 379 380 381 382
static WidgetInfo *
create_drop_down (void)
{
  GtkWidget *widget;

  widget = gtk_drop_down_new_from_strings ((const char * const []){"Drop Down", "Almost a combo", NULL});

  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);

  return new_widget_info ("drop-down", widget, SMALL);
}

Matthias Clasen's avatar
Matthias Clasen committed
383 384 385 386
static WidgetInfo *
create_info_bar (void)
{
  GtkWidget *widget;
387
  WidgetInfo *info;
Matthias Clasen's avatar
Matthias Clasen committed
388

389 390
  widget = gtk_info_bar_new ();
  gtk_info_bar_set_show_close_button (GTK_INFO_BAR (widget), TRUE);
Matthias Clasen's avatar
Matthias Clasen committed
391
  gtk_info_bar_set_message_type (GTK_INFO_BAR (widget), GTK_MESSAGE_INFO);
392
  gtk_info_bar_add_child (GTK_INFO_BAR (widget), gtk_label_new ("Info Bar"));
Matthias Clasen's avatar
Matthias Clasen committed
393

Timm Bäder's avatar
Timm Bäder committed
394 395
  gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
Matthias Clasen's avatar
Matthias Clasen committed
396

397 398
  add_margin (widget);

Timm Bäder's avatar
Timm Bäder committed
399
  info = new_widget_info ("info-bar", widget, SMALL);
400 401

  return info;
Matthias Clasen's avatar
Matthias Clasen committed
402
}
403 404 405 406 407 408 409 410 411 412 413 414 415 416

static WidgetInfo *
create_search_bar (void)
{
  GtkWidget *widget;
  GtkWidget *entry;
  WidgetInfo *info;
  GtkWidget *view;
  GtkWidget *box;

  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  widget = gtk_search_bar_new ();

  entry = gtk_search_entry_new ();
417
  gtk_editable_set_text (GTK_EDITABLE (entry), "Search Bar");
418
  gtk_search_bar_set_child (GTK_SEARCH_BAR (widget), entry);
419 420 421 422

  gtk_search_bar_set_show_close_button (GTK_SEARCH_BAR (widget), TRUE);
  gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (widget), TRUE);

423
  gtk_box_append (GTK_BOX (box), widget);
424 425

  view = gtk_text_view_new ();
426
  gtk_box_append (GTK_BOX (box), view);
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443

  info = new_widget_info ("search-bar", box, SMALL);

  return info;
}

static WidgetInfo *
create_action_bar (void)
{
  GtkWidget *widget;
  GtkWidget *button;
  WidgetInfo *info;
  GtkWidget *view;
  GtkWidget *box;

  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  view = gtk_text_view_new ();
444
  gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
445
  gtk_box_append (GTK_BOX (box), view);
446 447 448

  widget = gtk_action_bar_new ();

Benjamin Otte's avatar
Benjamin Otte committed
449
  button = gtk_button_new_from_icon_name ("object-select-symbolic");
450
  gtk_action_bar_pack_start (GTK_ACTION_BAR (widget), button);
Benjamin Otte's avatar
Benjamin Otte committed
451
  button = gtk_button_new_from_icon_name ("call-start-symbolic");
452
  gtk_action_bar_pack_start (GTK_ACTION_BAR (widget), button);
Matthias Clasen's avatar
Matthias Clasen committed
453 454 455 456 457 458 459
  g_object_set (gtk_widget_get_parent (button),
                "margin-start", 6,
                "margin-end", 6,
                "margin-top", 6,
                "margin-bottom", 6,
                "spacing", 6,
                NULL);
460

461
  gtk_box_append (GTK_BOX (box), widget);
462 463 464 465 466 467

  info = new_widget_info ("action-bar", box, SMALL);

  return info;
}

468 469 470 471 472 473 474 475
static WidgetInfo *
create_text_view (void)
{
  GtkWidget *widget;
  GtkWidget *text_view;

  widget = gtk_frame_new (NULL);
  text_view = gtk_text_view_new ();
476
  gtk_frame_set_child (GTK_FRAME (widget), text_view);
477
  gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)),
478
                            "Multiline\nText\n\n", -1);
479
  gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE);
480 481 482
  gtk_widget_set_size_request (text_view, 100, -1);

  add_margin (widget);
483 484

  return new_widget_info ("multiline-text", widget, MEDIUM);
485 486 487 488 489 490 491
}

static WidgetInfo *
create_tree_view (void)
{
  GtkWidget *widget;
  GtkWidget *tree_view;
492
  GtkTreeStore *store;
493 494 495 496
  GtkTreeIter iter;
  WidgetInfo *info;

  widget = gtk_frame_new (NULL);
497 498 499 500 501 502 503 504 505 506
  store = gtk_tree_store_new (3, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
  gtk_tree_store_append (store, &iter, NULL);
  gtk_tree_store_set (store, &iter, 0, "Line One", 1, FALSE, 2, "A", -1);
  gtk_tree_store_append (store, &iter, NULL);
  gtk_tree_store_set (store, &iter, 0, "Line Two", 1, TRUE, 2, "B", -1);
  gtk_tree_store_append (store, &iter, &iter);
  gtk_tree_store_set (store, &iter, 0, "Line Three", 1, FALSE, 2, "C", -1);

  tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
  gtk_tree_view_set_enable_tree_lines (GTK_TREE_VIEW (tree_view), TRUE);
507
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
508
					       0, "List",
509 510
					       gtk_cell_renderer_text_new (),
					       "text", 0, NULL);
511 512 513 514 515 516 517 518 519
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       1, "and",
					       gtk_cell_renderer_toggle_new (),
                                               "active", 1, NULL);
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       2, "Tree",
					       g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, "xalign", 0.5, NULL),
					       "text", 2, NULL);
  gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
520
  gtk_frame_set_child (GTK_FRAME (widget), tree_view);
521 522

  info = new_widget_info ("list-and-tree", widget, MEDIUM);
523 524 525 526 527
  info->no_focus = FALSE;

  return info;
}

528 529 530 531 532 533 534 535 536 537
static WidgetInfo *
create_icon_view (void)
{
  GtkWidget *widget;
  GtkWidget *vbox;
  GtkWidget *icon_view;
  GtkListStore *list_store;
  GtkTreeIter iter;
  GdkPixbuf *pixbuf;
  WidgetInfo *info;
538
  GtkWidget *sw;
539 540 541 542

  widget = gtk_frame_new (NULL);
  list_store = gtk_list_store_new (2, G_TYPE_STRING, GDK_TYPE_PIXBUF);
  gtk_list_store_append (list_store, &iter);
Matthias Clasen's avatar
Matthias Clasen committed
543
  pixbuf = gdk_pixbuf_new_from_file ("folder.png", NULL);
544 545
  gtk_list_store_set (list_store, &iter, 0, "One", 1, pixbuf, -1);
  gtk_list_store_append (list_store, &iter);
Matthias Clasen's avatar
Matthias Clasen committed
546
  pixbuf = gdk_pixbuf_new_from_file ("gnome.png", NULL);
547 548
  gtk_list_store_set (list_store, &iter, 0, "Two", 1, pixbuf, -1);

549 550 551 552
  icon_view = gtk_icon_view_new ();

  gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (icon_view), GTK_ORIENTATION_HORIZONTAL);
  gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (icon_view), 0);
553 554 555 556 557

  gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), GTK_TREE_MODEL (list_store));
  gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_view), 0);
  gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), 1);

558 559 560 561 562 563
  sw = gtk_scrolled_window_new ();
  gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), icon_view);

  gtk_frame_set_child (GTK_FRAME (widget), sw);

  gtk_widget_set_size_request (widget, 96, 128);
564

565
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
566
  gtk_box_append (GTK_BOX (vbox), widget);
567 568 569
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Icon View"));

  add_margin (vbox);
570

571
  info = new_widget_info ("icon-view", vbox, MEDIUM);
572 573 574 575 576
  info->no_focus = FALSE;

  return info;
}

577 578 579 580 581
static WidgetInfo *
create_color_button (void)
{
  GtkWidget *vbox;
  GtkWidget *picker;
Timm Bäder's avatar
Timm Bäder committed
582
  GdkRGBA color;
583

584
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
585
  color.red = 0x1e<<8;
586 587
  color.green = 0x90<<8;
  color.blue = 0xff<<8;
588
  color.alpha = 0xffff;
Timm Bäder's avatar
Timm Bäder committed
589
  picker = gtk_color_button_new_with_rgba (&color);
Timm Bäder's avatar
Timm Bäder committed
590 591
  gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
592
  gtk_box_append (GTK_BOX (vbox), picker);
593 594 595
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Color Button"));

  add_margin (vbox);
596

597
  return new_widget_info ("color-button", vbox, SMALL);
598 599 600 601 602 603 604 605
}

static WidgetInfo *
create_font_button (void)
{
  GtkWidget *vbox;
  GtkWidget *picker;

606
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
607
  picker = gtk_font_button_new_with_font ("Sans Serif 10");
Timm Bäder's avatar
Timm Bäder committed
608 609
  gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
610
  gtk_box_append (GTK_BOX (vbox), picker);
611 612 613
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Font Button"));

  add_margin (vbox);
614

615
  return new_widget_info ("font-button", vbox, SMALL);
616 617
}

618 619 620 621
static WidgetInfo *
create_file_button (void)
{
  GtkWidget *vbox;
622
  GtkWidget *vbox2;
623
  GtkWidget *picker;
624
  char *path;
Matthias Clasen's avatar
Matthias Clasen committed
625
  GFile *file;
626

627 628
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
  vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
629 630
  picker = gtk_file_chooser_button_new ("File Chooser Button",
		  			GTK_FILE_CHOOSER_ACTION_OPEN);
631
  gtk_widget_set_size_request (picker, 150, -1);
Timm Bäder's avatar
Timm Bäder committed
632 633
  gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
634 635
  gtk_box_append (GTK_BOX (vbox2), picker);
  gtk_box_append (GTK_BOX (vbox2),
Timm Bäder's avatar
Timm Bäder committed
636
		      gtk_label_new ("File Button (Files)"));
637

638
  gtk_box_append (GTK_BOX (vbox),
Timm Bäder's avatar
Timm Bäder committed
639
		      vbox2);
640
  gtk_box_append (GTK_BOX (vbox),
Timm Bäder's avatar
Timm Bäder committed
641
		      gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
642

643
  vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
644 645
  picker = gtk_file_chooser_button_new ("File Chooser Button",
		  			GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
646
  gtk_widget_set_size_request (picker, 150, -1);
647
  path = g_build_filename (g_get_home_dir (), "Documents", NULL);
Matthias Clasen's avatar
Matthias Clasen committed
648 649
  file = g_file_new_for_path (path);
  gtk_file_chooser_set_file (GTK_FILE_CHOOSER (picker), file, NULL);
650
  g_free (path);
Matthias Clasen's avatar
Matthias Clasen committed
651
  g_object_unref (file);
Timm Bäder's avatar
Timm Bäder committed
652 653
  gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
654
  gtk_box_append (GTK_BOX (vbox2), picker);
655 656 657 658
  gtk_box_append (GTK_BOX (vbox2), gtk_label_new ("File Button (Select Folder)"));
  gtk_box_append (GTK_BOX (vbox), vbox2);

  add_margin (vbox);
659 660

  return new_widget_info ("file-button", vbox, MEDIUM);
661 662
}

663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
static WidgetInfo *
create_editable_label (void)
{
  GtkWidget *vbox;
  GtkWidget *widget;

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
  widget = gtk_editable_label_new ("Editable Label");
  gtk_box_append (GTK_BOX (vbox), widget);
  gtk_box_append (GTK_BOX (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
  widget = gtk_editable_label_new ("Editable Label");
  gtk_editable_label_start_editing (GTK_EDITABLE_LABEL (widget));
  gtk_widget_add_css_class (widget, "frame");
  gtk_box_append (GTK_BOX (vbox), widget);

  gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER);

  add_margin (vbox);

682
  return new_widget_info ("editable-label", vbox, SMALL);
683
}
684 685 686 687 688
static WidgetInfo *
create_separator (void)
{
  GtkWidget *hbox;
  GtkWidget *vbox;
689
  GtkWidget *widget;
690

691
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
692 693 694 695 696 697 698 699 700
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
  widget = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_widget_set_size_request (widget, 100, -1);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
  gtk_box_append (GTK_BOX (hbox), widget);
  widget = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
  gtk_widget_set_size_request (widget, -1, 100);
  gtk_box_append (GTK_BOX (hbox), widget);
701
  gtk_box_append (GTK_BOX (vbox), hbox);
702 703 704 705 706 707
  gtk_box_append (GTK_BOX (vbox), g_object_new (GTK_TYPE_LABEL,
                                                "label", "Horizontal and Vertical\nSeparators",
                                                "justify", GTK_JUSTIFY_CENTER,
                                                NULL));
  add_margin (vbox);

708
  return new_widget_info ("separator", vbox, MEDIUM);
709 710 711 712 713 714 715 716
}

static WidgetInfo *
create_panes (void)
{
  GtkWidget *hbox;
  GtkWidget *vbox;
  GtkWidget *pane;
Matthias Clasen's avatar
Matthias Clasen committed
717
  GtkWidget *frame;
718

719 720 721
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
722
  pane = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
Matthias Clasen's avatar
Matthias Clasen committed
723 724 725 726 727 728 729 730 731 732 733

  frame = gtk_frame_new ("");
  gtk_paned_set_start_child (GTK_PANED (pane), frame);
  gtk_paned_set_resize_start_child (GTK_PANED (pane), FALSE);
  gtk_paned_set_shrink_start_child (GTK_PANED (pane), FALSE);

  frame = gtk_frame_new ("");
  gtk_paned_set_end_child (GTK_PANED (pane), frame);
  gtk_paned_set_resize_end_child (GTK_PANED (pane), FALSE);
  gtk_paned_set_shrink_end_child (GTK_PANED (pane), FALSE);

734 735
  gtk_widget_set_size_request (pane, 96, 96);

736
  gtk_box_append (GTK_BOX (hbox), pane);
737
  pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
Matthias Clasen's avatar
Matthias Clasen committed
738 739 740 741 742 743 744 745 746 747 748

  frame = gtk_frame_new ("");
  gtk_paned_set_start_child (GTK_PANED (pane), frame);
  gtk_paned_set_resize_start_child (GTK_PANED (pane), FALSE);
  gtk_paned_set_shrink_start_child (GTK_PANED (pane), FALSE);

  frame = gtk_frame_new ("");
  gtk_paned_set_end_child (GTK_PANED (pane), frame);
  gtk_paned_set_resize_end_child (GTK_PANED (pane), FALSE);
  gtk_paned_set_shrink_end_child (GTK_PANED (pane), FALSE);

749 750
  gtk_widget_set_size_request (pane, 96, 96);

751
  gtk_box_append (GTK_BOX (hbox), pane);
Matthias Clasen's avatar
Matthias Clasen committed
752

753
  gtk_box_append (GTK_BOX (vbox), hbox);
754 755 756 757 758 759 760
  gtk_box_append (GTK_BOX (vbox), g_object_new (GTK_TYPE_LABEL,
                                                "label", "Horizontal and Vertical\nPanes",
                                                "justify", GTK_JUSTIFY_CENTER,
                                                NULL));

  add_margin (vbox);

761
  return new_widget_info ("panes", vbox, MEDIUM);
762 763 764 765 766 767 768 769
}

static WidgetInfo *
create_frame (void)
{
  GtkWidget *widget;

  widget = gtk_frame_new ("Frame");
770 771 772
  gtk_widget_set_size_request (widget, 96, 96);

  add_margin (widget);
773

774
  return new_widget_info ("frame", widget, MEDIUM);
775 776 777 778 779 780 781 782
}

static WidgetInfo *
create_window (void)
{
  WidgetInfo *info;
  GtkWidget *widget;

783
  widget = gtk_window_new ();
784
  info = new_widget_info ("window", widget, MEDIUM);
785 786 787 788 789 790
  info->include_decorations = TRUE;
  gtk_window_set_title (GTK_WINDOW (info->window), "Window");

  return info;
}

791 792 793 794 795 796 797 798 799
static WidgetInfo *
create_filesel (void)
{
  WidgetInfo *info;
  GtkWidget *widget;

  widget = gtk_file_chooser_dialog_new ("File Chooser Dialog",
					NULL,
					GTK_FILE_CHOOSER_ACTION_OPEN,
800 801
					"Cancel", GTK_RESPONSE_CANCEL,
					"Open", GTK_RESPONSE_ACCEPT,
802 803 804 805 806 807 808 809 810
					NULL); 
  gtk_window_set_default_size (GTK_WINDOW (widget), 505, 305);
  
  info = new_widget_info ("filechooser", widget, ASIS);
  info->include_decorations = TRUE;

  return info;
}

811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
static WidgetInfo *
create_print_dialog (void)
{
  WidgetInfo *info;
  GtkWidget *widget;

  widget = gtk_print_unix_dialog_new ("Print Dialog", NULL);   
  gtk_widget_set_size_request (widget, 505, 350);
  info = new_widget_info ("printdialog", widget, ASIS);
  info->include_decorations = TRUE;

  return info;
}

static WidgetInfo *
create_page_setup_dialog (void)
{
  WidgetInfo *info;
  GtkWidget *widget;
  GtkPageSetup *page_setup;
  GtkPrintSettings *settings;

  page_setup = gtk_page_setup_new ();
  settings = gtk_print_settings_new ();
  widget = gtk_page_setup_unix_dialog_new ("Page Setup Dialog", NULL);   
  gtk_page_setup_unix_dialog_set_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (widget),
					     page_setup);
  gtk_page_setup_unix_dialog_set_print_settings (GTK_PAGE_SETUP_UNIX_DIALOG (widget),
						 settings);

  info = new_widget_info ("pagesetupdialog", widget, ASIS);
  info->include_decorations = TRUE;

  return info;
}

847 848 849 850 851 852 853 854 855 856
static WidgetInfo *
create_message_dialog (void)
{
  GtkWidget *widget;

  widget = gtk_message_dialog_new (NULL,
				   0,
				   GTK_MESSAGE_INFO,
				   GTK_BUTTONS_OK,
				   NULL);
857
  gtk_window_set_icon_name (GTK_WINDOW (widget), "edit-copy");
858 859
  gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), "Message Dialog");
  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (widget), "%s", "With secondary text");
860 861 862 863 864 865 866
  return new_widget_info ("messagedialog", widget, ASIS);
}

static WidgetInfo *
create_about_dialog (void)
{
  GtkWidget *widget;
Benjamin Otte's avatar
Benjamin Otte committed
867
  const char *authors[] = {
868 869 870 871 872 873 874 875 876
    "Peter Mattis",
    "Spencer Kimball",
    "Josh MacDonald",
    "and many more...",
    NULL
  };

  widget = gtk_about_dialog_new ();
  g_object_set (widget,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
877
                "program-name", "GTK Code Demos",
878
                "version", PACKAGE_VERSION,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
879
                "copyright", "© 1997-2013 The GTK Team",
880
                "website", "http://www.gtk.org",
Emmanuele Bassi's avatar
Emmanuele Bassi committed
881
                "comments", "Program to demonstrate GTK functions.",
882
                "logo-icon-name", "help-about",
Emmanuele Bassi's avatar
Emmanuele Bassi committed
883
                "title", "About GTK Code Demos",
884 885
                "authors", authors,
		NULL);
886
  gtk_window_set_icon_name (GTK_WINDOW (widget), "help-about");
887
  return new_widget_info ("aboutdialog", widget, ASIS);
888 889 890 891 892 893 894 895 896 897 898 899
}

static WidgetInfo *
create_notebook (void)
{
  GtkWidget *widget;

  widget = gtk_notebook_new ();

  gtk_notebook_append_page (GTK_NOTEBOOK (widget), 
			    gtk_label_new ("Notebook"),
			    NULL);
Benjamin Otte's avatar
Benjamin Otte committed
900 901 902 903 904 905
  gtk_notebook_append_page (GTK_NOTEBOOK (widget),
			    gtk_label_new ("Notebook"),
			    NULL);
  gtk_notebook_append_page (GTK_NOTEBOOK (widget),
			    gtk_label_new ("Notebook"),
			    NULL);
906 907 908 909 910 911 912 913 914 915 916 917

  return new_widget_info ("notebook", widget, MEDIUM);
}

static WidgetInfo *
create_progressbar (void)
{
  GtkWidget *vbox;
  GtkWidget *widget;

  widget = gtk_progress_bar_new ();
  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (widget), 0.5);
918

919
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
Timm Bäder's avatar
Timm Bäder committed
920 921
  gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
922
  gtk_box_append (GTK_BOX (vbox), widget);
923 924 925
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Progress Bar"));

  add_margin (vbox);
926 927 928 929

  return new_widget_info ("progressbar", vbox, SMALL);
}

930 931 932 933 934 935 936 937 938 939
static WidgetInfo *
create_level_bar (void)
{
  GtkWidget *vbox;
  GtkWidget *widget;

  widget = gtk_level_bar_new ();
  gtk_level_bar_set_value (GTK_LEVEL_BAR (widget), 0.333);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
940
  gtk_box_append (GTK_BOX (vbox), widget);
941 942 943
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Level Bar"));

  add_margin (vbox);
944 945 946 947

  return new_widget_info ("levelbar", vbox, SMALL);
}

948 949 950 951 952
static WidgetInfo *
create_scrolledwindow (void)
{
  GtkWidget *scrolledwin, *label;

953
  scrolledwin = gtk_scrolled_window_new ();
Matthias Clasen's avatar
Matthias Clasen committed
954
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
955
                                  GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
956
  gtk_scrolled_window_set_overlay_scrolling (GTK_SCROLLED_WINDOW (scrolledwin), FALSE);
957 958
  label = gtk_label_new ("Scrolled Window");

959
  gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolledwin), label);
960 961 962 963

  return new_widget_info ("scrolledwindow", scrolledwin, MEDIUM);
}

Matthias Clasen's avatar
Matthias Clasen committed
964 965 966 967
static WidgetInfo *
create_scrollbar (void)
{
  GtkWidget *widget;
Timm Bäder's avatar
Timm Bäder committed
968
  GtkWidget *vbox;
Matthias Clasen's avatar
Matthias Clasen committed
969 970 971 972 973

  widget = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, NULL);
  gtk_widget_set_size_request (widget, 100, -1);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
Timm Bäder's avatar
Timm Bäder committed
974 975
  gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
976
  gtk_box_append (GTK_BOX (vbox), widget);
977 978 979
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Scrollbar"));

  add_margin (vbox);
Matthias Clasen's avatar
Matthias Clasen committed
980 981 982 983

  return new_widget_info ("scrollbar", vbox, SMALL);
}

984 985 986 987
static WidgetInfo *
create_spinbutton (void)
{
  GtkWidget *widget;
Timm Bäder's avatar
Timm Bäder committed
988
  GtkWidget *vbox;
989 990 991

  widget = gtk_spin_button_new_with_range (0.0, 100.0, 1.0);

992
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
Timm Bäder's avatar
Timm Bäder committed
993 994
  gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
995
  gtk_box_append (GTK_BOX (vbox), widget);
996 997 998
  gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Spin Button"));

  add_margin (vbox);
999 1000 1001 1002 1003 1004 1005

  return new_widget_info ("spinbutton", vbox, SMALL);
}

static WidgetInfo *
create_statusbar (void)
{
1006
  WidgetInfo *info;
1007
  GtkWidget *widget;
Timm Bäder's avatar
Timm Bäder committed
1008
  GtkWidget *vbox;
1009

1010
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1011
  gtk_box_append (GTK_BOX (vbox),
Timm Bäder's avatar
Timm Bäder committed
1012
                      gtk_label_new ("Status Bar"));
1013
  widget = gtk_statusbar_new ();
Timm Bäder's avatar
Timm Bäder committed
1014
  gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
1015 1016
  gtk_statusbar_push (GTK_STATUSBAR (widget), 0, "Hold on...");

1017
  gtk_box_append (GTK_BOX (vbox), widget);
1018

1019 1020
  add_margin (vbox);

1021
  info = new_widget_info ("statusbar", vbox, SMALL);
1022

1023
  return info;
1024 1025
}

Matthias Clasen's avatar
Matthias Clasen committed
1026 1027 1028 1029 1030
static WidgetInfo *
create_scales (void)
{
  GtkWidget *hbox;
  GtkWidget *vbox;
1031
  GtkWidget *widget;
Matthias Clasen's avatar
Matthias Clasen committed
1032

1033 1034 1035
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
  widget = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0.0, 100.0, 1.0);
  gtk_scale_set_draw_value (GTK_SCALE (widget), FALSE);
  gtk_range_set_value (GTK_RANGE (widget), 50.);
  gtk_widget_set_size_request (widget, 100, -1);
  gtk_box_append (GTK_BOX (hbox), widget);
  widget = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL, 0.0, 100.0, 1.0);
  gtk_scale_set_draw_value (GTK_SCALE (widget), FALSE);
  gtk_widget_set_size_request (widget, -1, 100);
  gtk_range_set_value (GTK_RANGE (widget), 50.);
  gtk_box_append (GTK_BOX (hbox), widget);