aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/e-table
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/e-table')
-rw-r--r--widgets/e-table/ChangeLog16
-rw-r--r--widgets/e-table/e-cell-tree.c60
-rw-r--r--widgets/e-table/e-tree-example-1.c33
-rw-r--r--widgets/e-table/e-tree-model.c39
-rw-r--r--widgets/e-table/e-tree-model.h7
5 files changed, 124 insertions, 31 deletions
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog
index c8cac20b3f..f55db41bb6 100644
--- a/widgets/e-table/ChangeLog
+++ b/widgets/e-table/ChangeLog
@@ -1,3 +1,19 @@
+2000-06-23 Chris Toshok <toshok@helixcode.com>
+
+ * e-tree-example-1.c (create_tree): use the expanded/unexpanded
+ pixbufs as node pixbufs for the first level of children, to test
+ the drawing.
+
+ * e-tree-model.c (e_tree_model_node_get_closed_pixbuf): new function.
+ (e_tree_model_node_get_opened_pixbuf): same.
+ (e_tree_model_node_insert): add opened/closed pixbuf argument.
+ (e_tree_model_node_insert_before): same.
+
+ * e-tree-model.h: add prototypes for opened/closed pixbuf
+ accessors, and add them to the e_tree_model_node_insert_* calls.
+
+ * e-cell-tree.c (ect_draw): add opened/closed pixbuf drawing per node.
+
2000-06-22 Christopher James Lahey <clahey@helixcode.com>
* e-table.c: Make the table not move around as you resize.
diff --git a/widgets/e-table/e-cell-tree.c b/widgets/e-table/e-cell-tree.c
index 41eb805cdc..61c86fad2d 100644
--- a/widgets/e-table/e-cell-tree.c
+++ b/widgets/e-table/e-cell-tree.c
@@ -167,6 +167,10 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable,
/* only draw the tree effects if we're the active sort */
if (/* XXX */ TRUE) {
+ GdkPixbuf *node_image;
+ int node_image_width = 0, node_image_height = 0;
+ ETreePath *parent_node;
+
node = e_cell_tree_get_node (tree_model, row);
offset = offset_of_node (tree_model, node);
@@ -174,12 +178,22 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable,
expanded = e_tree_model_node_is_expanded (tree_model, node);
subcell_offset = offset;
+ if (expanded)
+ node_image = e_tree_model_node_get_opened_pixbuf (tree_model, node);
+ else
+ node_image = e_tree_model_node_get_closed_pixbuf (tree_model, node);
+
+ if (node_image) {
+ node_image_width = gdk_pixbuf_get_width (node_image);
+ node_image_height = gdk_pixbuf_get_height (node_image);
+ }
+
/*
* Be a nice citizen: clip to the region we are supposed to draw on
*/
rect.x = x1;
rect.y = y1;
- rect.width = offset;
+ rect.width = subcell_offset + node_image_width;
rect.height = y2 - y1;
gdk_gc_set_clip_rectangle (tree_view->gc, &rect);
@@ -222,41 +236,57 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable,
/* now traverse back up to the root of the tree, checking at
each level if the node has siblings, and drawing the
correct vertical pipe for it's configuration. */
- node = e_tree_model_node_get_parent (tree_model, node);
+ parent_node = e_tree_model_node_get_parent (tree_model, node);
offset -= INDENT_AMOUNT;
- while (node && visible_depth_of_node (tree_model, node) != 0) {
- if (e_tree_model_node_get_next(tree_model, node)) {
+ while (parent_node && visible_depth_of_node (tree_model, parent_node) != 0) {
+ if (e_tree_model_node_get_next(tree_model, parent_node)) {
gdk_draw_line (drawable, tree_view->gc,
rect.x + offset - INDENT_AMOUNT / 2,
rect.y,
rect.x + offset - INDENT_AMOUNT / 2,
rect.y + rect.height);
}
- node = e_tree_model_node_get_parent (tree_model, node);
+ parent_node = e_tree_model_node_get_parent (tree_model, parent_node);
offset -= INDENT_AMOUNT;
}
}
/* now draw our icon if we're expandable */
if (expandable) {
- GdkPixbuf *image = (expanded
- ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf
- : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf);
- int width, height;
+ GdkPixbuf *image;
+ int image_width, image_height;
- width = gdk_pixbuf_get_width(image);
- height = gdk_pixbuf_get_height(image);
+ image = (expanded
+ ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf
+ : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf);
+
+ image_width = gdk_pixbuf_get_width(image);
+ image_height = gdk_pixbuf_get_height(image);
gdk_pixbuf_render_to_drawable_alpha (image,
drawable,
0, 0,
- x1 + subcell_offset - INDENT_AMOUNT / 2 - width / 2,
- y1 + (y2 - y1) / 2 - height / 2,
- width, height,
+ x1 + subcell_offset - INDENT_AMOUNT / 2 - image_width / 2,
+ y1 + (y2 - y1) / 2 - image_height / 2,
+ image_width, image_height,
+ GDK_PIXBUF_ALPHA_BILEVEL,
+ 128,
+ GDK_RGB_DITHER_NORMAL,
+ image_width, 0);
+ }
+
+ if (node_image) {
+ gdk_pixbuf_render_to_drawable_alpha (node_image,
+ drawable,
+ 0, 0,
+ x1 + subcell_offset,
+ y1 + (y2 - y1) / 2 - node_image_height / 2,
+ node_image_width, node_image_height,
GDK_PIXBUF_ALPHA_BILEVEL,
128,
GDK_RGB_DITHER_NORMAL,
- width, 0);
+ node_image_width, 0);
+ subcell_offset += node_image_width;
}
}
diff --git a/widgets/e-table/e-tree-example-1.c b/widgets/e-table/e-tree-example-1.c
index 688bc735b1..c506faebd5 100644
--- a/widgets/e-table/e-tree-example-1.c
+++ b/widgets/e-table/e-tree-example-1.c
@@ -20,6 +20,8 @@
#include "tree-expanded.xpm"
#include "tree-unexpanded.xpm"
+GdkPixbuf *tree_expanded_pixbuf;
+GdkPixbuf *tree_unexpanded_pixbuf;
#define COLS 4
@@ -127,7 +129,9 @@ add_sibling (GtkButton *button, gpointer data)
parent_node = e_tree_model_node_get_parent (e_tree_model, selected_node);
e_tree_model_node_insert_before (e_tree_model, parent_node,
- selected_node, g_strdup("User added sibling"));
+ selected_node,
+ NULL, NULL,
+ g_strdup("User added sibling"));
}
@@ -146,7 +150,8 @@ add_child (GtkButton *button, gpointer data)
g_assert (selected_node);
e_tree_model_node_insert (e_tree_model, selected_node,
- 0, g_strdup("User added child"));
+ 0, NULL, NULL,
+ g_strdup("User added child"));
}
static void
@@ -224,7 +229,6 @@ static void
create_tree (void)
{
GtkWidget *window, *frame, *button, *vbox;
- GdkPixbuf *tree_expanded_pixbuf, *tree_unexpanded_pixbuf;
ECell *cell_left_just;
ECell *cell_tree;
ETableHeader *e_table_header;
@@ -241,14 +245,19 @@ create_tree (void)
/* create a root node with 5 children */
root_node = e_tree_model_node_insert (e_tree_model, NULL,
- 0, g_strdup("Root Node"));
+ 0, NULL, NULL,
+ g_strdup("Root Node"));
for (i = 0; i < 5; i++){
ETreePath *n = e_tree_model_node_insert (e_tree_model,
- root_node, 0, g_strdup("First level of children"));
+ root_node, 0,
+ tree_expanded_pixbuf, tree_unexpanded_pixbuf,
+ g_strdup("First level of children"));
for (j = 0; j < 5; j ++) {
e_tree_model_node_insert (e_tree_model,
- n, 0, g_strdup("Second level of children"));
+ n, 0,
+ NULL, NULL,
+ g_strdup("Second level of children"));
}
}
@@ -273,12 +282,6 @@ create_tree (void)
*/
cell_left_just = e_cell_text_new (E_TABLE_MODEL(e_tree_model), NULL, GTK_JUSTIFY_LEFT);
- /*
- * Create our pixbuf for expanding/unexpanding
- */
- tree_expanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_expanded_xpm);
- tree_unexpanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_unexpanded_xpm);
-
/*
* This renderer is used for the tree column (the leftmost one), and
* has as its subcell renderer the text renderer. this means that
@@ -377,6 +380,12 @@ main (int argc, char *argv [])
gtk_widget_push_visual (gdk_rgb_get_visual ());
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
+ /*
+ * Create our pixbuf for expanding/unexpanding
+ */
+ tree_expanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_expanded_xpm);
+ tree_unexpanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_unexpanded_xpm);
+
create_tree ();
gtk_main ();
diff --git a/widgets/e-table/e-tree-model.c b/widgets/e-table/e-tree-model.c
index 180c63bb96..47b82d3689 100644
--- a/widgets/e-table/e-tree-model.c
+++ b/widgets/e-table/e-tree-model.c
@@ -23,6 +23,8 @@ static ETableModel *e_tree_model_parent_class;
typedef struct {
gboolean expanded;
guint visible_descendents;
+ GdkPixbuf *opened_pixbuf;
+ GdkPixbuf *closed_pixbuf;
gpointer node_data;
} ENode;
@@ -552,10 +554,36 @@ e_tree_model_node_set_data (ETreeModel *etm, ETreePath *node, gpointer node_data
enode->node_data = node_data;
}
+GdkPixbuf *
+e_tree_model_node_get_opened_pixbuf (ETreeModel *etm, ETreePath *node)
+{
+ ENode *enode;
+
+ g_return_val_if_fail (node && node->data, NULL);
+
+ enode = (ENode*)node->data;
+
+ return enode->opened_pixbuf;
+}
+
+GdkPixbuf *
+e_tree_model_node_get_closed_pixbuf (ETreeModel *etm, ETreePath *node)
+{
+ ENode *enode;
+
+ g_return_val_if_fail (node && node->data, NULL);
+
+ enode = (ENode*)node->data;
+
+ return enode->closed_pixbuf;
+}
+
ETreePath*
e_tree_model_node_insert (ETreeModel *tree_model,
ETreePath *parent_path,
int position,
+ GdkPixbuf *opened_pixbuf,
+ GdkPixbuf *closed_pixbuf,
gpointer node_data)
{
ENode *node;
@@ -566,6 +594,8 @@ e_tree_model_node_insert (ETreeModel *tree_model,
node = g_new0 (ENode, 1);
node->expanded = FALSE;
+ node->closed_pixbuf = closed_pixbuf;
+ node->opened_pixbuf = opened_pixbuf;
node->node_data = node_data;
if (parent_path != NULL) {
@@ -608,11 +638,16 @@ e_tree_model_node_insert (ETreeModel *tree_model,
}
ETreePath *
-e_tree_model_node_insert_before (ETreeModel *etree, ETreePath *parent,
- ETreePath *sibling, gpointer node_data)
+e_tree_model_node_insert_before (ETreeModel *etree,
+ ETreePath *parent,
+ ETreePath *sibling,
+ GdkPixbuf *opened_pixbuf,
+ GdkPixbuf *closed_pixbuf,
+ gpointer node_data)
{
return e_tree_model_node_insert (etree, parent,
g_node_child_position (parent, sibling),
+ opened_pixbuf, closed_pixbuf,
node_data);
}
diff --git a/widgets/e-table/e-tree-model.h b/widgets/e-table/e-tree-model.h
index 45351b8f6c..0a7ecdb7ed 100644
--- a/widgets/e-table/e-tree-model.h
+++ b/widgets/e-table/e-tree-model.h
@@ -3,6 +3,7 @@
#define _E_TREE_MODEL_H_
#include "e-table-model.h"
+#include "gdk-pixbuf/gdk-pixbuf.h"
#define E_TREE_MODEL_TYPE (e_tree_model_get_type ())
#define E_TREE_MODEL(o) (GTK_CHECK_CAST ((o), E_TREE_MODEL_TYPE, ETreeModel))
@@ -68,8 +69,8 @@ ETreePath *e_tree_model_node_get_next (ETreeModel *etree, ETreePath *path);
ETreePath *e_tree_model_node_get_prev (ETreeModel *etree, ETreePath *path);
/* node operations */
-ETreePath *e_tree_model_node_insert (ETreeModel *etree, ETreePath *parent, int position, gpointer node_data);
-ETreePath *e_tree_model_node_insert_before (ETreeModel *etree, ETreePath *parent, ETreePath *sibling, gpointer node_data);
+ETreePath *e_tree_model_node_insert (ETreeModel *etree, ETreePath *parent, int position, GdkPixbuf *opened_pixbuf, GdkPixbuf *closed_pixbuf, gpointer node_data);
+ETreePath *e_tree_model_node_insert_before (ETreeModel *etree, ETreePath *parent, ETreePath *sibling, GdkPixbuf *opened_pixbuf, GdkPixbuf *closed_pixbuf, gpointer node_data);
gpointer e_tree_model_node_remove (ETreeModel *etree, ETreePath *path);
/* node accessors */
@@ -84,6 +85,8 @@ guint e_tree_model_node_depth (ETreeModel *etree, ETreePath
guint e_tree_model_node_num_visible_descendents (ETreeModel *etm, ETreePath *node);
gpointer e_tree_model_node_get_data (ETreeModel *etm, ETreePath *node);
void e_tree_model_node_set_data (ETreeModel *etm, ETreePath *node, gpointer node_data);
+GdkPixbuf *e_tree_model_node_get_opened_pixbuf (ETreeModel *etm, ETreePath *node);
+GdkPixbuf *e_tree_model_node_get_closed_pixbuf (ETreeModel *etm, ETreePath *node);
/* display oriented routines */
ETreePath *e_tree_model_node_at_row (ETreeModel *etree, int row);