2015-10-18 12:59:38 -05:00
|
|
|
// 18 october 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
struct uiTable {
|
|
|
|
uiUnixControl c;
|
|
|
|
GtkWidget *widget;
|
2015-10-18 17:55:06 -05:00
|
|
|
GtkContainer *scontainer;
|
2015-10-18 12:59:38 -05:00
|
|
|
GtkScrolledWindow *sw;
|
|
|
|
GtkWidget *treeWidget;
|
|
|
|
GtkTreeView *treeview;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
uiTableModel *model;
|
|
|
|
};
|
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
uiUnixDefineControl(
|
2016-04-24 14:04:36 -05:00
|
|
|
uiTable // type name
|
2015-10-18 17:55:06 -05:00
|
|
|
)
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
void uiTableSetModel(uiTable *t, uiTableModel *m)
|
2015-10-18 12:59:38 -05:00
|
|
|
{
|
2015-10-18 17:55:06 -05:00
|
|
|
t->model = m;
|
2015-10-19 09:52:36 -05:00
|
|
|
gtk_tree_view_set_model(t->treeview, GTK_TREE_MODEL(t->model));
|
2015-10-18 12:59:38 -05:00
|
|
|
}
|
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
void uiTableAppendColumn(uiTable *t, uiTableColumnParams *p)
|
2015-10-18 12:59:38 -05:00
|
|
|
{
|
2015-10-18 17:55:06 -05:00
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
GtkCellRenderer *r;
|
|
|
|
const char *attribute;
|
|
|
|
const char *mutableAttr;
|
|
|
|
gboolean mutable;
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
switch (p->Type) {
|
2015-10-18 12:59:38 -05:00
|
|
|
case uiTableColumnText:
|
2015-10-18 17:55:06 -05:00
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
attribute = "text";
|
|
|
|
mutableAttr = "editable";
|
|
|
|
break;
|
2015-10-18 12:59:38 -05:00
|
|
|
//TODO case uiTableColumnImage:
|
|
|
|
// TODO
|
|
|
|
case uiTableColumnCheckbox:
|
2015-10-18 17:55:06 -05:00
|
|
|
r = gtk_cell_renderer_toggle_new();
|
|
|
|
attribute = "active";
|
|
|
|
mutableAttr = "activatable";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
complain("unknown table column type %d in uiTableAppendColumn()", p->Type);
|
2015-10-18 12:59:38 -05:00
|
|
|
}
|
2015-10-18 17:55:06 -05:00
|
|
|
mutable = FALSE;
|
|
|
|
if (p->Mutable)
|
|
|
|
mutable = TRUE;
|
|
|
|
g_object_set(r,
|
|
|
|
mutableAttr, mutable,
|
|
|
|
NULL);
|
|
|
|
col = gtk_tree_view_column_new_with_attributes(p->Name, r,
|
|
|
|
attribute, p->ValueColumn,
|
|
|
|
NULL);
|
|
|
|
// allow columns to be resized
|
|
|
|
gtk_tree_view_column_set_resizable(col, TRUE);
|
2015-10-19 09:52:36 -05:00
|
|
|
gtk_tree_view_append_column(t->treeview, col);
|
2015-10-18 12:59:38 -05:00
|
|
|
}
|
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
uiTable *uiNewTable(void)
|
2015-10-18 12:59:38 -05:00
|
|
|
{
|
2015-10-18 17:55:06 -05:00
|
|
|
uiTable *t;
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
t = (uiTable *) uiNewControl(uiTableType());
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
t->widget = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
t->scontainer = GTK_CONTAINER(t->widget);
|
|
|
|
t->sw = GTK_SCROLLED_WINDOW(t->widget);
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
t->treeWidget = gtk_tree_view_new();
|
|
|
|
t->treeview = GTK_TREE_VIEW(t->treeWidget);
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
t->selection = gtk_tree_view_get_selection(t->treeview);
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
// give a border and add the table
|
|
|
|
gtk_scrolled_window_set_shadow_type(t->sw, GTK_SHADOW_IN);
|
|
|
|
gtk_container_add(t->scontainer, t->treeWidget);
|
|
|
|
// and make the table visible; only the scrolled window's visibility is controlled by libui
|
|
|
|
gtk_widget_show(t->treeWidget);
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
uiUnixFinishNewControl(t, uiTable);
|
2015-10-18 12:59:38 -05:00
|
|
|
|
2015-10-18 17:55:06 -05:00
|
|
|
return t;
|
2015-10-18 12:59:38 -05:00
|
|
|
}
|