1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* Copyright (c) 2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#include "data-list.h"
enum
{
COLUMN_NUMBER,
COLUMN_TYPE
};
struct _GtkInspectorDataListPrivate
{
GtkListStore *model;
GtkTreeViewColumn *number_column;
GtkCellRenderer *number_renderer;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorDataList, gtk_inspector_data_list, GTK_TYPE_BOX)
static void
render_number (GtkTreeViewColumn *column,
GtkCellRenderer *renderer,
GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
gint number;
gchar text[100];
gtk_tree_model_get (model, iter, COLUMN_NUMBER, &number, -1);
g_snprintf (text, 100, "%d", number);
g_object_set (renderer, "text", text, NULL);
}
static void
gtk_inspector_data_list_init (GtkInspectorDataList *sl)
{
sl->priv = gtk_inspector_data_list_get_instance_private (sl);
gtk_widget_init_template (GTK_WIDGET (sl));
gtk_tree_view_column_set_cell_data_func (sl->priv->number_column,
sl->priv->number_renderer,
render_number,
NULL, NULL);
}
void
gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
GObject *object)
{
GtkTreeIter iter;
gint i;
gtk_list_store_clear (sl->priv->model);
if (!GTK_IS_TREE_MODEL (object))
{
gtk_widget_hide (GTK_WIDGET (sl));
return;
}
gtk_widget_show (GTK_WIDGET (sl));
for (i = 0; i < gtk_tree_model_get_n_columns (GTK_TREE_MODEL (object)); i++)
{
GType type;
type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (object), i);
gtk_list_store_append (sl->priv->model, &iter);
gtk_list_store_set (sl->priv->model, &iter,
COLUMN_NUMBER, i,
COLUMN_TYPE, g_type_name (type),
-1);
}
}
static void
gtk_inspector_data_list_class_init (GtkInspectorDataListClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/data-list.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, model);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, number_column);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorDataList, number_renderer);
}
GtkWidget *
gtk_inspector_data_list_new (void)
{
return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_DATA_LIST, NULL));
}
// vim: set et sw=2 ts=2:
|