Changes from Bolliet Jerome <bolliet@in2p3.fr> to gtktree.
Corrects a bug in gtk_tree_remove_items and gtk_tree_item_destroy. Adds the possibility to connect all items by lines. This is the default now. You can overide this with the function gtk_tree_set_view_line which take a tree and a boolean. This tree widget looks way more finished with the lines. Very nice. Check it out and run gtk/testtree. -Shawn
This commit is contained in:
@ -166,9 +166,11 @@ gtk_tree_init (GtkTree *tree)
|
||||
tree->selection = NULL;
|
||||
tree->tree_owner = NULL;
|
||||
tree->selection_mode = GTK_SELECTION_SINGLE;
|
||||
tree->indent_value = 10;
|
||||
tree->indent_value = 9;
|
||||
tree->current_indent = 0;
|
||||
tree->level = 0;
|
||||
tree->view_mode = GTK_TREE_VIEW_LINE;
|
||||
tree->view_line = 1;
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
@ -523,12 +525,15 @@ gtk_tree_map (GtkWidget *widget)
|
||||
/* set root tree for this tree */
|
||||
tree->root_tree = GTK_TREE(widget->parent)->root_tree;
|
||||
|
||||
tree->level = GTK_TREE(GTK_WIDGET(tree)->parent)->level+1;
|
||||
tree->indent_value = GTK_TREE(GTK_WIDGET(tree)->parent)->indent_value;
|
||||
tree->current_indent = GTK_TREE(GTK_WIDGET(tree)->parent)->current_indent +
|
||||
tree->indent_value;
|
||||
tree->view_mode = GTK_TREE(GTK_WIDGET(tree)->parent)->view_mode;
|
||||
} else
|
||||
tree->root_tree = tree;
|
||||
tree->view_line = GTK_TREE(GTK_WIDGET(tree)->parent)->view_line;
|
||||
}
|
||||
else
|
||||
tree->root_tree = tree;
|
||||
|
||||
children = tree->children;
|
||||
while (children)
|
||||
@ -1035,3 +1040,13 @@ gtk_tree_set_view_mode (GtkTree *tree,
|
||||
|
||||
tree->view_mode = mode;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_tree_set_view_lines (GtkTree *tree,
|
||||
guint flag)
|
||||
{
|
||||
g_return_if_fail (tree != NULL);
|
||||
g_return_if_fail (GTK_IS_TREE (tree));
|
||||
|
||||
tree->view_line = flag;
|
||||
}
|
||||
|
||||
@ -54,10 +54,12 @@ struct _GtkTree
|
||||
GtkTree* root_tree; /* owner of selection list */
|
||||
GtkWidget* tree_owner;
|
||||
GList *selection;
|
||||
guint level;
|
||||
guint indent_value;
|
||||
guint current_indent;
|
||||
guint selection_mode : 2;
|
||||
guint view_mode : 1;
|
||||
guint view_line : 1;
|
||||
};
|
||||
|
||||
struct _GtkTreeClass
|
||||
@ -102,6 +104,8 @@ void gtk_tree_set_selection_mode (GtkTree *tree,
|
||||
GtkSelectionMode mode);
|
||||
void gtk_tree_set_view_mode (GtkTree *tree,
|
||||
GtkTreeViewMode mode);
|
||||
void gtk_tree_set_view_lines (GtkTree *tree,
|
||||
guint flag);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@ -448,6 +448,7 @@ gtk_tree_item_size_allocate (GtkWidget *widget,
|
||||
GtkTreeItem* item;
|
||||
GtkAllocation child_allocation;
|
||||
guint border_width;
|
||||
int temp;
|
||||
|
||||
g_return_if_fail (widget != NULL);
|
||||
g_return_if_fail (GTK_IS_TREE_ITEM (widget));
|
||||
@ -470,6 +471,7 @@ gtk_tree_item_size_allocate (GtkWidget *widget,
|
||||
child_allocation.x = border_width + GTK_TREE(widget->parent)->current_indent;
|
||||
child_allocation.y = GTK_CONTAINER (widget)->border_width;
|
||||
|
||||
#ifdef 0
|
||||
child_allocation.height = allocation->height - child_allocation.y * 2;
|
||||
child_allocation.width = item->pixmaps_box->requisition.width;
|
||||
|
||||
@ -478,6 +480,18 @@ gtk_tree_item_size_allocate (GtkWidget *widget,
|
||||
gtk_widget_size_allocate (item->pixmaps_box, &child_allocation);
|
||||
|
||||
child_allocation.height += 2;
|
||||
#else
|
||||
child_allocation.width = item->pixmaps_box->requisition.width;
|
||||
child_allocation.height = item->pixmaps_box->requisition.height;
|
||||
|
||||
temp = allocation->height - child_allocation.height;
|
||||
child_allocation.y += ( temp / 2 ) + ( temp % 2 );
|
||||
|
||||
gtk_widget_size_allocate (item->pixmaps_box, &child_allocation);
|
||||
|
||||
child_allocation.y = GTK_CONTAINER (widget)->border_width;
|
||||
child_allocation.height = allocation->height - child_allocation.y * 2;
|
||||
#endif
|
||||
child_allocation.x += item->pixmaps_box->requisition.width+DEFAULT_DELTA;
|
||||
|
||||
child_allocation.width =
|
||||
@ -488,6 +502,67 @@ gtk_tree_item_size_allocate (GtkWidget *widget,
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_tree_item_draw_lines(GtkWidget *widget)
|
||||
{
|
||||
GtkTreeItem* item;
|
||||
GtkTree* tree;
|
||||
guint lx1, ly1, lx2, ly2;
|
||||
|
||||
item = GTK_TREE_ITEM(widget);
|
||||
tree = GTK_TREE(widget->parent);
|
||||
|
||||
/* draw vertical line */
|
||||
lx1 = item->pixmaps_box->allocation.width;
|
||||
lx1 = lx2 = ( lx1 / 2 ) + ( lx1 % 2 ) +
|
||||
GTK_CONTAINER(widget)->border_width + 1 + tree->current_indent;
|
||||
ly1 = 0;
|
||||
ly2 = widget->allocation.height;
|
||||
|
||||
if(g_list_last(tree->children)->data == (gpointer)widget)
|
||||
ly2 = (ly2 / 2) + (ly2 % 2);
|
||||
|
||||
if(tree != tree->root_tree)
|
||||
gdk_draw_line(widget->window, widget->style->black_gc,
|
||||
lx1, ly1, lx2, ly2);
|
||||
|
||||
/* draw vertical line for subtree connecting */
|
||||
if(g_list_last(tree->children)->data != (gpointer)widget)
|
||||
ly2 = (ly2 / 2) + (ly2 % 2);
|
||||
|
||||
lx2 += DEFAULT_DELTA;
|
||||
|
||||
if(item->subtree && item->expanded)
|
||||
gdk_draw_line(widget->window, widget->style->black_gc,
|
||||
lx2, ly2, lx2, widget->allocation.height);
|
||||
|
||||
/* draw horizontal line */
|
||||
ly1 = ly2;
|
||||
lx2 += 2;
|
||||
|
||||
gdk_draw_line(widget->window, widget->style->black_gc,
|
||||
lx1, ly1, lx2, ly2);
|
||||
|
||||
lx2 -= DEFAULT_DELTA+2;
|
||||
ly1 = 0;
|
||||
ly2 = widget->allocation.height;
|
||||
|
||||
if(tree != tree->root_tree)
|
||||
{
|
||||
item = GTK_TREE_ITEM(tree->tree_owner);
|
||||
tree = GTK_TREE(GTK_WIDGET(tree)->parent);
|
||||
while(tree != tree->root_tree) {
|
||||
lx1 = lx2 -= tree->indent_value;
|
||||
|
||||
if(g_list_last(tree->children)->data != (gpointer)item)
|
||||
gdk_draw_line(widget->window, widget->style->black_gc,
|
||||
lx1, ly1, lx2, ly2);
|
||||
item = GTK_TREE_ITEM(tree->tree_owner);
|
||||
tree = GTK_TREE(GTK_WIDGET(tree)->parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_tree_item_draw (GtkWidget *widget,
|
||||
GdkRectangle *area)
|
||||
@ -526,6 +601,8 @@ gtk_tree_item_draw (GtkWidget *widget,
|
||||
child_area.x, child_area.y,
|
||||
child_area.width, child_area.height);
|
||||
|
||||
/* gtk_tree_item_draw_lines(widget); */
|
||||
|
||||
if (tree_item->pixmaps_box &&
|
||||
GTK_WIDGET_VISIBLE(tree_item->pixmaps_box) &&
|
||||
gtk_widget_intersect (tree_item->pixmaps_box, area, &child_area))
|
||||
@ -585,6 +662,9 @@ gtk_tree_item_draw_focus (GtkWidget *widget)
|
||||
gdk_draw_rectangle (widget->window, gc, FALSE, dx, 0,
|
||||
widget->allocation.width - 1 - dx,
|
||||
widget->allocation.height - 1);
|
||||
|
||||
if(GTK_TREE(widget->parent)->view_line)
|
||||
gtk_tree_item_draw_lines(widget);
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,11 +740,11 @@ gtk_real_tree_item_select (GtkItem *item)
|
||||
if (GTK_WIDGET (item)->state == GTK_STATE_SELECTED)
|
||||
return;
|
||||
|
||||
gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
|
||||
|
||||
if(GTK_TREE(GTK_WIDGET(item)->parent)->view_mode == GTK_TREE_VIEW_LINE)
|
||||
gtk_widget_set_state (GTK_TREE_ITEM (item)->pixmaps_box, GTK_STATE_SELECTED);
|
||||
|
||||
|
||||
gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (item));
|
||||
}
|
||||
|
||||
@ -678,12 +758,15 @@ gtk_real_tree_item_deselect (GtkItem *item)
|
||||
if (GTK_WIDGET (item)->state == GTK_STATE_NORMAL)
|
||||
return;
|
||||
|
||||
gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
|
||||
if(GTK_WIDGET_MAPPED(GTK_WIDGET (item)))
|
||||
{
|
||||
gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
|
||||
|
||||
if(GTK_TREE(GTK_WIDGET(item)->parent)->view_mode == GTK_TREE_VIEW_LINE)
|
||||
gtk_widget_set_state (GTK_TREE_ITEM (item)->pixmaps_box, GTK_STATE_NORMAL);
|
||||
|
||||
if(GTK_TREE(GTK_WIDGET(item)->parent)->view_mode == GTK_TREE_VIEW_LINE)
|
||||
gtk_widget_set_state (GTK_TREE_ITEM (item)->pixmaps_box, GTK_STATE_NORMAL);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (item));
|
||||
gtk_widget_queue_draw (GTK_WIDGET (item));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -801,6 +884,14 @@ gtk_tree_item_destroy (GtkObject *object)
|
||||
gtk_widget_destroy (child);
|
||||
}
|
||||
|
||||
/* free pixmaps box */
|
||||
if((child = item->pixmaps_box))
|
||||
{
|
||||
child->parent = NULL;
|
||||
gtk_object_unref (GTK_OBJECT (child));
|
||||
gtk_widget_destroy (child);
|
||||
}
|
||||
|
||||
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
||||
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
||||
|
||||
|
||||
@ -43,6 +43,7 @@ static void add_tree_item(GtkWidget* w, GtkTree* tree) {
|
||||
|
||||
selected = GTK_TREE_SELECTION(tree);
|
||||
nb_selected = g_list_length(selected);
|
||||
selected_item = NULL;
|
||||
|
||||
if(nb_selected > 1) return;
|
||||
|
||||
@ -110,18 +111,15 @@ void create_tree_item(GtkWidget* parent, int level, int nb_item, int level_max)
|
||||
gtk_tree_append(GTK_TREE(parent), item);
|
||||
gtk_widget_show(item);
|
||||
|
||||
/* g_print("item '%s' : 0x%x\n", buffer, (int)item); */
|
||||
|
||||
if(level < level_max) {
|
||||
tree = gtk_tree_new();
|
||||
|
||||
/* g_print("subtree '%s' : 0x%x\n", buffer, (int)tree); */
|
||||
gtk_signal_connect(GTK_OBJECT(tree), "selection_changed",
|
||||
(GtkSignalFunc)cb_tree_changed,
|
||||
(gpointer)NULL);
|
||||
create_tree_item(tree, level+1, nb_item, level_max);
|
||||
gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree);
|
||||
/* gtk_tree_item_expand(GTK_TREE_ITEM(item)); */
|
||||
/* gtk_tree_item_expand(GTK_TREE_ITEM(item)); */
|
||||
|
||||
}
|
||||
}
|
||||
@ -131,6 +129,7 @@ void create_tree_item(GtkWidget* parent, int level, int nb_item, int level_max)
|
||||
void create_tree_page(GtkWidget* parent, GtkSelectionMode mode,
|
||||
char* page_name) {
|
||||
GtkWidget *root, *scrolled_win;
|
||||
GtkWidget *root_item, *root_subtree;
|
||||
GtkWidget *box, *label;
|
||||
GtkWidget *button;
|
||||
sTreeButton* tree_buttons;
|
||||
@ -151,16 +150,25 @@ void create_tree_page(GtkWidget* parent, GtkSelectionMode mode,
|
||||
gtk_widget_show (scrolled_win);
|
||||
|
||||
root = gtk_tree_new();
|
||||
/* g_print("root: 0x%x\n", (int)root); */
|
||||
gtk_container_add(GTK_CONTAINER(scrolled_win), root);
|
||||
gtk_tree_set_selection_mode(GTK_TREE(root), mode);
|
||||
/* gtk_tree_set_view_lines(GTK_TREE(root), 0); */
|
||||
/* gtk_tree_set_view_mode(GTK_TREE(root), GTK_TREE_VIEW_ITEM); */
|
||||
gtk_signal_connect(GTK_OBJECT(root), "selection_changed",
|
||||
(GtkSignalFunc)cb_tree_changed,
|
||||
(gpointer)NULL);
|
||||
gtk_widget_show(root);
|
||||
|
||||
root_item = gtk_tree_item_new_with_label("root");
|
||||
gtk_tree_append(GTK_TREE(root), root_item);
|
||||
gtk_widget_show(root_item);
|
||||
|
||||
create_tree_item(root, 1, 3, 3);
|
||||
root_subtree = gtk_tree_new();
|
||||
gtk_signal_connect(GTK_OBJECT(root_subtree), "selection_changed",
|
||||
(GtkSignalFunc)cb_tree_changed,
|
||||
(gpointer)NULL);
|
||||
create_tree_item(root_subtree, 1, 3, 3);
|
||||
gtk_tree_item_set_subtree(GTK_TREE_ITEM(root_item), root_subtree);
|
||||
|
||||
tree_buttons = g_malloc(sizeof(sTreeButton));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user