gtdc/variable_tab.c
2008-03-17 18:36:41 +01:00

148 lines
4.1 KiB
C

#include <gtk/gtk.h>
#include "tdc_store.h"
#include "tdcproto.h"
enum {
COL_ID = 0, /* UINT */
COL_GRAPH, /* BOOLEAN */
COL_VALUE, /* PTR?, with cell_data_func */
COL_VALUE_EDIT, /* BOOLEAN */
COL_TYPE, /* STRING */
COL_NAME, /* STRING */
};
static GtkListStore *list_store;
static void cell_graph_toggle(GtkCellRendererToggle *cell, gchar *path_string, gpointer user_data)
{
GtkTreeIter it;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(user_data), &it, path_string);
gboolean toggle;
gtk_tree_model_get(GTK_TREE_MODEL(user_data), &it,
COL_GRAPH, &toggle,
-1);
gtk_list_store_set(GTK_LIST_STORE(user_data), &it,
COL_GRAPH, !toggle,
-1);
}
static void cell_value_edited(GtkCellRendererText *cell, gchar *path_string, gchar *new_text, gpointer user_data)
{
printf("cell_value_edited\n");
}
gint variable_tab_init(GtkNotebook *notebook)
{
list_store = gtk_list_store_new(6,
G_TYPE_UINT, G_TYPE_BOOLEAN,
G_TYPE_STRING, G_TYPE_BOOLEAN,
G_TYPE_STRING, G_TYPE_STRING);
GtkWidget *view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store));
g_object_unref(list_store);
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Graph");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_toggle_new();
g_object_set(renderer, "activatable", TRUE, NULL);
g_signal_connect(renderer, "toggled", (GCallback)cell_graph_toggle, list_store);
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "active", COL_GRAPH);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Value");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
// gtk_tree_view_column_set_cell_data_func(col, renderer, cell_value_func, NULL, NULL);
g_signal_connect(renderer, "edited", (GCallback)cell_value_edited, NULL);
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_VALUE);
gtk_tree_view_column_add_attribute(col, renderer, "editable", COL_VALUE_EDIT);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Type");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_TYPE);
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Name");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_NAME);
GtkWidget *scrollbar = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(scrollbar), view);
GtkWidget *label = gtk_label_new(" Variables ");
return gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrollbar, label);
}
void vartab_add_var(struct tdc_var *var)
{
GtkTreeIter it;
gtk_list_store_append(list_store, &it);
char typestr[16];
int size = (var->flags & TDC_SIZEMASK);
switch (var->flags & TDC_TYPEMASK) {
case TDC_UNSIGNED:
snprintf(typestr, sizeof(typestr), "uint%d_t", size * 8);
break;
case TDC_SIGNED:
snprintf(typestr, sizeof(typestr), "int%d_t", size * 8);
break;
case TDC_FP:
if (size == sizeof(float))
snprintf(typestr, sizeof(typestr), "float");
else if (size == sizeof(double))
snprintf(typestr, sizeof(typestr), "double");
else
snprintf(typestr, sizeof(typestr), "float(%d)", size * 8);
break;
case TDC_FIXED:
snprintf(typestr, sizeof(typestr), "fixed(%d)", size * 8);
break;
}
gtk_list_store_set(list_store, &it,
COL_ID, var->id,
COL_GRAPH, FALSE,
COL_VALUE, "none",
COL_VALUE_EDIT, !(var->flags & TDC_READONLY),
COL_TYPE, typestr,
COL_NAME, var->name,
-1);
}
void vartab_update_var(struct tdc_var *var)
{
}
void vartab_remove_var(struct tdc_var *var)
{
}