~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to demos/gtk-demo/iconview_edit.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Icon View/Editing and Drag-and-Drop
 
2
 *
 
3
 * The GtkIconView widget supports Editing and Drag-and-Drop.
 
4
 * This example also demonstrates using the generic GtkCellLayout
 
5
 * interface to set up cell renderers in an icon view.
 
6
 */
 
7
 
 
8
#include <gtk/gtk.h>
 
9
#include <string.h>
 
10
#include "demo-common.h"
 
11
 
 
12
static GtkWidget *window = NULL;
 
13
 
 
14
enum
 
15
{
 
16
  COL_TEXT,
 
17
  NUM_COLS
 
18
};
 
19
 
 
20
 
 
21
static void
 
22
fill_store (GtkListStore *store)
 
23
{
 
24
  GtkTreeIter iter;
 
25
  const gchar *text[] = { "Red", "Green", "Blue", "Yellow" };
 
26
  gint i;
 
27
 
 
28
  /* First clear the store */
 
29
  gtk_list_store_clear (store);
 
30
 
 
31
  for (i = 0; i < 4; i++)
 
32
    {
 
33
      gtk_list_store_append (store, &iter);
 
34
      gtk_list_store_set (store, &iter, COL_TEXT, text[i], -1);
 
35
    }
 
36
}
 
37
 
 
38
static GtkListStore *
 
39
create_store (void)
 
40
{
 
41
  GtkListStore *store;
 
42
 
 
43
  store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING);
 
44
 
 
45
  return store;
 
46
}
 
47
 
 
48
static void
 
49
set_cell_color (GtkCellLayout   *cell_layout,
 
50
                GtkCellRenderer *cell,
 
51
                GtkTreeModel    *tree_model,
 
52
                GtkTreeIter     *iter,
 
53
                gpointer         data)
 
54
{
 
55
  gchar *text;
 
56
  GdkColor color;
 
57
  guint32 pixel = 0;
 
58
  GdkPixbuf *pixbuf;
 
59
 
 
60
  gtk_tree_model_get (tree_model, iter, COL_TEXT, &text, -1);
 
61
  if (gdk_color_parse (text, &color))
 
62
    pixel =
 
63
      (color.red   >> 8) << 24 |
 
64
      (color.green >> 8) << 16 |
 
65
      (color.blue  >> 8) << 8;
 
66
 
 
67
  g_free (text);
 
68
 
 
69
  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 24, 24);
 
70
  gdk_pixbuf_fill (pixbuf, pixel);
 
71
 
 
72
  g_object_set (cell, "pixbuf", pixbuf, NULL);
 
73
 
 
74
  g_object_unref (pixbuf);
 
75
}
 
76
 
 
77
static void
 
78
edited (GtkCellRendererText *cell,
 
79
        gchar               *path_string,
 
80
        gchar               *text,
 
81
        gpointer             data)
 
82
{
 
83
  GtkTreeModel *model;
 
84
  GtkTreeIter iter;
 
85
  GtkTreePath *path;
 
86
 
 
87
  model = gtk_icon_view_get_model (GTK_ICON_VIEW (data));
 
88
  path = gtk_tree_path_new_from_string (path_string);
 
89
 
 
90
  gtk_tree_model_get_iter (model, &iter, path);
 
91
  gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
92
                      COL_TEXT, text, -1);
 
93
 
 
94
  gtk_tree_path_free (path);
 
95
}
 
96
 
 
97
GtkWidget *
 
98
do_iconview_edit (GtkWidget *do_widget)
 
99
{
 
100
  if (!window)
 
101
    {
 
102
      GtkWidget *icon_view;
 
103
      GtkListStore *store;
 
104
      GtkCellRenderer *renderer;
 
105
 
 
106
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
107
 
 
108
      gtk_window_set_screen (GTK_WINDOW (window),
 
109
                             gtk_widget_get_screen (do_widget));
 
110
      gtk_window_set_title (GTK_WINDOW (window), "Editing and Drag-and-Drop");
 
111
 
 
112
      g_signal_connect (window, "destroy",
 
113
                        G_CALLBACK (gtk_widget_destroyed), &window);
 
114
 
 
115
      store = create_store ();
 
116
      fill_store (store);
 
117
 
 
118
      icon_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (store));
 
119
      g_object_unref (store);
 
120
 
 
121
      gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
 
122
                                        GTK_SELECTION_SINGLE);
 
123
      gtk_icon_view_set_orientation (GTK_ICON_VIEW (icon_view),
 
124
                                     GTK_ORIENTATION_HORIZONTAL);
 
125
      gtk_icon_view_set_columns (GTK_ICON_VIEW (icon_view), 2);
 
126
      gtk_icon_view_set_reorderable (GTK_ICON_VIEW (icon_view), TRUE);
 
127
 
 
128
      renderer = gtk_cell_renderer_pixbuf_new ();
 
129
      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
 
130
                                  renderer, TRUE);
 
131
      gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (icon_view),
 
132
                                          renderer,
 
133
                                          set_cell_color,
 
134
                                          NULL, NULL);
 
135
 
 
136
      renderer = gtk_cell_renderer_text_new ();
 
137
      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
 
138
                                  renderer, TRUE);
 
139
      g_object_set (renderer, "editable", TRUE, NULL);
 
140
      g_signal_connect (renderer, "edited", G_CALLBACK (edited), icon_view);
 
141
      gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
 
142
                                      renderer,
 
143
                                      "text", COL_TEXT,
 
144
                                      NULL);
 
145
 
 
146
      gtk_container_add (GTK_CONTAINER (window), icon_view);
 
147
    }
 
148
 
 
149
  if (!GTK_WIDGET_VISIBLE (window))
 
150
    gtk_widget_show_all (window);
 
151
  else
 
152
    {
 
153
      gtk_widget_destroy (window);
 
154
      window = NULL;
 
155
    }
 
156
 
 
157
  return window;
 
158
}
 
159