summaryrefslogtreecommitdiff
path: root/app/wlib/gtklib/treeview.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/wlib/gtklib/treeview.c')
-rw-r--r--app/wlib/gtklib/treeview.c424
1 files changed, 212 insertions, 212 deletions
diff --git a/app/wlib/gtklib/treeview.c b/app/wlib/gtklib/treeview.c
index 2b743cb..b3f2d77 100644
--- a/app/wlib/gtklib/treeview.c
+++ b/app/wlib/gtklib/treeview.c
@@ -53,7 +53,7 @@
int
wTreeViewGetCount(wList_p b)
{
- return b->count;
+ return b->count;
}
/**
@@ -65,9 +65,9 @@ wTreeViewGetCount(wList_p b)
void
wTreeViewClear(wList_p b)
{
- assert(b != NULL);
+ assert(b != NULL);
- wlibListStoreClear(b->listStore);
+ wlibListStoreClear(b->listStore);
}
/**
@@ -81,15 +81,15 @@ wTreeViewClear(wList_p b)
void *
wTreeViewGetItemContext(wList_p b, int row)
{
- wListItem_p id_p;
+ wListItem_p id_p;
- id_p = wlibListItemGet(b->listStore, row, NULL);
+ id_p = wlibListItemGet(b->listStore, row, NULL);
- if (id_p) {
- return id_p->itemData;
- } else {
- return NULL;
- }
+ if (id_p) {
+ return id_p->itemData;
+ } else {
+ return NULL;
+ }
}
/**
@@ -101,11 +101,11 @@ wTreeViewGetItemContext(wList_p b, int row)
*/
wIndex_t wListGetIndex(
- wList_p b)
+ wList_p b)
{
- assert(b!=NULL);
+ assert(b!=NULL);
- return b->last;
+ return b->last;
}
/**
@@ -119,48 +119,48 @@ wIndex_t wListGetIndex(
void
wlibTreeViewSetSelected(wList_p b, int index)
{
- GtkTreeSelection *sel;
- GtkTreeIter iter;
+ GtkTreeSelection *sel;
+ GtkTreeIter iter;
- wListItem_p id_p;
+ wListItem_p id_p;
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(b->treeView));
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(b->treeView));
- if (gtk_tree_selection_count_selected_rows(sel)) {
+ if (gtk_tree_selection_count_selected_rows(sel)) {
int inx;
-
- gtk_tree_selection_unselect_all(sel);
- // and synchronize the internal data structures
- wTreeViewGetCount(b);
+ gtk_tree_selection_unselect_all(sel);
- for (inx=0; inx<b->count; inx++) {
- id_p = wlibListItemGet(b->listStore, inx, NULL);
- id_p->selected = FALSE;
- }
- }
+ // and synchronize the internal data structures
+ wTreeViewGetCount(b);
- if (index != -1) {
+ for (inx=0; inx<b->count; inx++) {
+ id_p = wlibListItemGet(b->listStore, inx, NULL);
+ id_p->selected = FALSE;
+ }
+ }
+
+ if (index != -1) {
gint childs;
-
+
childs = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(b->listStore),
- NULL );
+ NULL );
if(index < childs) {
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore),
- &iter,
- NULL,
- index);
+ &iter,
+ NULL,
+ index);
gtk_tree_selection_select_iter(sel,
- &iter);
+ &iter);
id_p = wlibListItemGet(b->listStore, index, NULL);
-
+
if (id_p) {
id_p->selected = TRUE;
}
- }
- }
+ }
+ }
}
/**
@@ -175,35 +175,37 @@ wlibTreeViewSetSelected(wList_p b, int index)
GtkWidget *
wlibNewTreeView(GtkListStore *ls, int showTitles, int multiSelection)
{
- GtkWidget *treeView;
- GtkTreeSelection *sel;
- assert(ls != NULL);
+ GtkWidget *treeView;
+ GtkTreeSelection *sel;
+ assert(ls != NULL);
- /* create and configure the tree view */
- treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls));
- gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), showTitles);
+ /* create and configure the tree view */
+ treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls));
+ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), showTitles);
- /* set up selection handling */
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
- gtk_tree_selection_set_mode(sel,
- (multiSelection)?GTK_SELECTION_MULTIPLE:GTK_SELECTION_BROWSE);
+ /* set up selection handling */
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
+ gtk_tree_selection_set_mode(sel,
+ (multiSelection)?GTK_SELECTION_MULTIPLE:GTK_SELECTION_BROWSE);
- return (treeView);
+ return (treeView);
}
+#if 0
static int changeListColumnWidth(
- GtkTreeViewColumn * column,
- void * width)
+ GtkTreeViewColumn * column,
+ void * width)
{
- //wList_p bl = (wList_p)data;
+ //wList_p bl = (wList_p)data;
- //if (bl->recursion)
- //return 0;
- //if ( col >= 0 && col < bl->colCnt )
- //bl->colWidths[col] = width;
- return 0;
+ //if (bl->recursion)
+ //return 0;
+ //if ( col >= 0 && col < bl->colCnt )
+ //bl->colWidths[col] = width;
+ return 0;
}
+#endif
/**
* Create and initialize a column in treeview. Initially all columns are
@@ -220,17 +222,17 @@ static void
wlibAddColumn(GtkWidget *tv, int visibility, GtkCellRenderer *renderer,
char *attribute, int value)
{
- GtkTreeViewColumn *column;
+ GtkTreeViewColumn *column;
- column = gtk_tree_view_column_new();
- gtk_tree_view_column_pack_start(column,
- renderer,
- TRUE);
- gtk_tree_view_column_add_attribute(column, renderer, attribute, value);
- gtk_tree_view_column_set_visible(column, visibility);
- gtk_tree_view_column_set_resizable(column, TRUE);
+ column = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start(column,
+ renderer,
+ TRUE);
+ gtk_tree_view_column_add_attribute(column, renderer, attribute, value);
+ gtk_tree_view_column_set_visible(column, visibility);
+ gtk_tree_view_column_set_resizable(column, TRUE);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
// g_signal_connect( column, "notify::width", G_CALLBACK(changeListColumnWidth), tv );
}
@@ -247,22 +249,22 @@ wlibAddColumn(GtkWidget *tv, int visibility, GtkCellRenderer *renderer,
int
wlibTreeViewAddColumns(GtkWidget *tv, int count)
{
- GtkCellRenderer *renderer;
- int i;
+ GtkCellRenderer *renderer;
+ int i;
- assert(tv != NULL);
- renderer = gtk_cell_renderer_pixbuf_new();
- /* first visible column is used for bitmaps */
- wlibAddColumn(tv, FALSE, renderer, "pixbuf", LISTCOL_BITMAP);
+ assert(tv != NULL);
+ renderer = gtk_cell_renderer_pixbuf_new();
+ /* first visible column is used for bitmaps */
+ wlibAddColumn(tv, FALSE, renderer, "pixbuf", LISTCOL_BITMAP);
- renderer = gtk_cell_renderer_text_new();
+ renderer = gtk_cell_renderer_text_new();
- /* add renderers to all columns */
- for (i = 0; i < count; i++) {
- wlibAddColumn(tv, TRUE, renderer, "text", i + LISTCOL_TEXT);
- }
+ /* add renderers to all columns */
+ for (i = 0; i < count; i++) {
+ wlibAddColumn(tv, TRUE, renderer, "text", i + LISTCOL_TEXT);
+ }
- return i;
+ return i;
}
/**
@@ -276,26 +278,26 @@ wlibTreeViewAddColumns(GtkWidget *tv, int count)
int
wlibAddColumnTitles(GtkWidget *tv, const char **titles)
{
- int i = 0;
-
- assert(tv != NULL);
-
- if (titles) {
- while (*titles) {
- GtkTreeViewColumn *column;
-
- column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), i + 1);
-
- if (column) {
- gtk_tree_view_column_set_title(column, titles[ i ]);
- i++;
- } else {
- break;
- }
- }
- }
-
- return i;
+ int i = 0;
+
+ assert(tv != NULL);
+
+ if (titles) {
+ while (*titles) {
+ GtkTreeViewColumn *column;
+
+ column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), i + 1);
+
+ if (column) {
+ gtk_tree_view_column_set_title(column, titles[ i ]);
+ i++;
+ } else {
+ break;
+ }
+ }
+ }
+
+ return i;
}
/**
@@ -313,20 +315,20 @@ int
wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf,
wListItem_p userData)
{
- GtkListStore *listStore = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(
- tv)));
+ GtkListStore *listStore = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(
+ tv)));
+
+ wlibListStoreAddData(listStore, pixbuf, cols, userData);
- wlibListStoreAddData(listStore, pixbuf, cols, userData);
+ if (pixbuf) {
+ GtkTreeViewColumn *column;
- if (pixbuf) {
- GtkTreeViewColumn *column;
-
- // first column in list store has pixbuf
- column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), 0);
- gtk_tree_view_column_set_visible(column,
- TRUE);
- }
- return 0;
+ // first column in list store has pixbuf
+ column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), 0);
+ gtk_tree_view_column_set_visible(column,
+ TRUE);
+ }
+ return 0;
}
@@ -344,28 +346,28 @@ wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf,
void
wlibTreeViewAddRow(wList_p b, char *label, wIcon_p bm, wListItem_p id_p)
{
- GtkAdjustment *adj;
- GdkPixbuf *pixbuf = NULL;
+ GtkAdjustment *adj;
+ GdkPixbuf *pixbuf = NULL;
- if (bm) {
- pixbuf = wlibMakePixbuf(bm);
- }
+ if (bm) {
+ pixbuf = wlibMakePixbuf(bm);
+ }
- wlibTreeViewAddData(b->treeView, b->colCnt, (char *)label, pixbuf, id_p);
+ wlibTreeViewAddData(b->treeView, b->colCnt, (char *)label, pixbuf, id_p);
- adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(b->widget));
+ adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(b->widget));
- if (gtk_adjustment_get_upper(adj) < gtk_adjustment_get_step_increment(adj) *
- (b->count+1)) {
- gtk_adjustment_set_upper(adj,
- gtk_adjustment_get_upper(adj) +
- gtk_adjustment_get_step_increment(adj));
- gtk_adjustment_changed(adj);
- }
+ if (gtk_adjustment_get_upper(adj) < gtk_adjustment_get_step_increment(adj) *
+ (b->count+1)) {
+ gtk_adjustment_set_upper(adj,
+ gtk_adjustment_get_upper(adj) +
+ gtk_adjustment_get_step_increment(adj));
+ gtk_adjustment_changed(adj);
+ }
- b->last = gtk_tree_model_iter_n_children(gtk_tree_view_get_model(GTK_TREE_VIEW(
- b->treeView)),
- NULL);
+ b->last = gtk_tree_model_iter_n_children(gtk_tree_view_get_model(GTK_TREE_VIEW(
+ b->treeView)),
+ NULL);
}
@@ -390,36 +392,34 @@ changeSelection(GtkTreeSelection *selection,
gboolean path_currently_selected,
gpointer data)
{
- GtkTreeIter iter;
- GValue value = { 0 };
- wListItem_p id_p = NULL;
- wList_p bl = (wList_p)data;
- int row;
- char *text;
+ GtkTreeIter iter;
+ GValue value = { 0 };
+ wListItem_p id_p = NULL;
+ wList_p bl = (wList_p)data;
+ int row;
+ char *text;
- text = gtk_tree_path_to_string(path);
- row = atoi(text);
- g_free(text);
+ text = gtk_tree_path_to_string(path);
+ row = atoi(text);
+ g_free(text);
- gtk_tree_model_get_iter(model, &iter, path);
- gtk_tree_model_get_value(model, &iter, LISTCOL_DATA, &value);
+ gtk_tree_model_get_iter(model, &iter, path);
+ gtk_tree_model_get_value(model, &iter, LISTCOL_DATA, &value);
- id_p = g_value_get_pointer(&value);
- id_p->selected = !path_currently_selected;
+ id_p = g_value_get_pointer(&value);
+ id_p->selected = !path_currently_selected;
- if (id_p->selected) {
- bl->last = row;
+ bl->last = row;
- if (bl->valueP) {
- *bl->valueP = row;
- }
+ if (bl->valueP) {
+ *bl->valueP = row;
+ }
- if (bl->action) {
- bl->action(row, id_p->label, 1, bl->data, id_p->itemData);
- }
- }
+ if (bl->action) {
+ bl->action(row, id_p->label, id_p->selected, bl->data, id_p->itemData);
+ }
- return TRUE;
+ return TRUE;
}
/**
@@ -444,88 +444,88 @@ changeSelection(GtkTreeSelection *selection,
*/
wList_p wListCreate(
- wWin_p parent,
- wPos_t x,
- wPos_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- wPos_t width,
- int colCnt,
- wPos_t * colWidths,
- wBool_t * colRightJust,
- const char ** colTitles,
- long *valueP,
- wListCallBack_p action,
- void *data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ long number,
+ wWinPix_t width,
+ int colCnt,
+ wWinPix_t * colWidths,
+ wBool_t * colRightJust,
+ const char ** colTitles,
+ long *valueP,
+ wListCallBack_p action,
+ void *data)
{
- GtkTreeSelection *sel;
- wList_p bl;
- static wPos_t zeroPos = 0;
+ GtkTreeSelection *sel;
+ wList_p bl;
+ static wWinPix_t zeroPos = 0;
- assert(width != 0);
+ assert(width != 0);
- bl = (wList_p)wlibAlloc(parent, B_LIST, x, y, labelStr, sizeof *bl, data);
- bl->option = option;
- bl->number = number;
- bl->count = 0;
- bl->last = -1;
- bl->valueP = valueP;
- bl->action = action;
- bl->listX = bl->realX;
+ bl = (wList_p)wlibAlloc(parent, B_LIST, x, y, labelStr, sizeof *bl, data);
+ bl->option = option;
+ bl->number = number;
+ bl->count = 0;
+ bl->last = -1;
+ bl->valueP = valueP;
+ bl->action = action;
+ bl->listX = bl->realX;
- if (colCnt <= 0) {
- colCnt = 1;
- colWidths = &zeroPos;
- }
+ if (colCnt <= 0) {
+ colCnt = 1;
+ colWidths = &zeroPos;
+ }
- bl->colCnt = colCnt;
- bl->colWidths = (wPos_t*)malloc(colCnt * sizeof *(wPos_t*)0);
- memcpy(bl->colWidths, colWidths, colCnt * sizeof *(wPos_t*)0);
+ bl->colCnt = colCnt;
+ bl->colWidths = (wWinPix_t*)malloc(colCnt * sizeof *(wWinPix_t*)0);
+ memcpy(bl->colWidths, colWidths, colCnt * sizeof *(wWinPix_t*)0);
- /* create the data structure for data */
- bl->listStore = wlibNewListStore(colCnt);
- /* create the widget for the list store */
- bl->treeView = wlibNewTreeView(bl->listStore,
- colTitles != NULL,
- option & BL_MANY);
+ /* create the data structure for data */
+ bl->listStore = wlibNewListStore(colCnt);
+ /* create the widget for the list store */
+ bl->treeView = wlibNewTreeView(bl->listStore,
+ colTitles != NULL,
+ option & BL_MANY);
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView));
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView));
- gtk_tree_selection_set_select_function(sel,
- changeSelection,
- bl,
- NULL);
+ gtk_tree_selection_set_select_function(sel,
+ changeSelection,
+ bl,
+ NULL);
- wlibTreeViewAddColumns(bl->treeView, colCnt);
+ wlibTreeViewAddColumns(bl->treeView, colCnt);
- wlibAddColumnTitles(bl->treeView, colTitles);
+ wlibAddColumnTitles(bl->treeView, colTitles);
- wlibComputePos((wControl_p)bl);
+ wlibComputePos((wControl_p)bl);
- bl->widget = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bl->widget),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(bl->widget),
- bl->treeView);
+ bl->widget = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bl->widget),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(bl->widget),
+ bl->treeView);
- gtk_widget_set_size_request(bl->widget, width, (number+1)*ROW_HEIGHT);
+ gtk_widget_set_size_request(bl->widget, width, (number+1)*ROW_HEIGHT);
/// g_signal_connect( GTK_OBJECT(bl->list), "resize_column", G_CALLBACK(changeListColumnWidth), bl );
- gtk_widget_show_all(bl->widget);
+ gtk_widget_show_all(bl->widget);
- gtk_fixed_put(GTK_FIXED(parent->widget), bl->widget, bl->realX, bl->realY);
- wlibControlGetSize((wControl_p)bl);
+ gtk_fixed_put(GTK_FIXED(parent->widget), bl->widget, bl->realX, bl->realY);
+ wlibControlGetSize((wControl_p)bl);
- if (labelStr) {
- bl->labelW = wlibAddLabel((wControl_p)bl, labelStr);
- }
+ if (labelStr) {
+ bl->labelW = wlibAddLabel((wControl_p)bl, labelStr);
+ }
- wlibAddButton((wControl_p)bl);
- wlibAddHelpString(bl->widget, helpStr);
+ wlibAddButton((wControl_p)bl);
+ wlibAddHelpString(bl->widget, helpStr);
- return bl;
+ return bl;
}