diff options
author | Chris Toshok <toshok@helixcode.com> | 2000-06-14 15:07:38 +0800 |
---|---|---|
committer | Chris Toshok <toshok@src.gnome.org> | 2000-06-14 15:07:38 +0800 |
commit | 5ae693645f49b1beb1b21adfc1e50c06aa130278 (patch) | |
tree | 5df64ae7148c1bdc2dce0f5ef5c1ff09e1044750 /widgets | |
parent | fabd9d91ab1aee4a091ddcdd6e189bacfcd4a920 (diff) | |
download | gsoc2013-evolution-5ae693645f49b1beb1b21adfc1e50c06aa130278.tar gsoc2013-evolution-5ae693645f49b1beb1b21adfc1e50c06aa130278.tar.gz gsoc2013-evolution-5ae693645f49b1beb1b21adfc1e50c06aa130278.tar.bz2 gsoc2013-evolution-5ae693645f49b1beb1b21adfc1e50c06aa130278.tar.lz gsoc2013-evolution-5ae693645f49b1beb1b21adfc1e50c06aa130278.tar.xz gsoc2013-evolution-5ae693645f49b1beb1b21adfc1e50c06aa130278.tar.zst gsoc2013-evolution-5ae693645f49b1beb1b21adfc1e50c06aa130278.zip |
new function, to generate postscript so i can test tree printing.
2000-06-14 Chris Toshok <toshok@helixcode.com>
* e-tree-example-1.c (print_tree): new function, to generate
postscript so i can test tree printing.
(create_tree): add print button.
* e-cell-tree.c (ect_print_height): implement function (in a
broken way for the time being, heh).
(ect_print): implement function to draw tree controls and offset
the subcell's printing. icons aren't printed yet, just lines.
(ect_draw): remove old unnecessary comments. only draw the
horizontal line in specific instances (well, add a test so a lone
root node doesn't get the horizontal line.)
(e_cell_tree_class_init): add print/print_height methods.
svn path=/trunk/; revision=3565
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/e-table/ChangeLog | 15 | ||||
-rw-r--r-- | widgets/e-table/e-cell-tree.c | 117 | ||||
-rw-r--r-- | widgets/e-table/e-tree-example-1.c | 41 | ||||
-rw-r--r-- | widgets/table/e-cell-tree.c | 117 | ||||
-rw-r--r-- | widgets/table/e-tree-example-1.c | 41 |
5 files changed, 273 insertions, 58 deletions
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog index 91cc91a58b..e030642d5f 100644 --- a/widgets/e-table/ChangeLog +++ b/widgets/e-table/ChangeLog @@ -1,3 +1,18 @@ +2000-06-14 Chris Toshok <toshok@helixcode.com> + + * e-tree-example-1.c (print_tree): new function, to generate + postscript so i can test tree printing. + (create_tree): add print button. + + * e-cell-tree.c (ect_print_height): implement function (in a + broken way for the time being, heh). + (ect_print): implement function to draw tree controls and offset + the subcell's printing. icons aren't printed yet, just lines. + (ect_draw): remove old unnecessary comments. only draw the + horizontal line in specific instances (well, add a test so a lone + root node doesn't get the horizontal line.) + (e_cell_tree_class_init): add print/print_height methods. + 2000-06-14 Christopher James Lahey <clahey@helixcode.com> * e-cell-text.c: Request the value of e_table_is_cell_editable of diff --git a/widgets/e-table/e-cell-tree.c b/widgets/e-table/e-cell-tree.c index 28de6ff5bb..508d39e60f 100644 --- a/widgets/e-table/e-cell-tree.c +++ b/widgets/e-table/e-cell-tree.c @@ -167,13 +167,6 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, /* only draw the tree effects if we're the active sort */ if (/* XXX */ TRUE) { - /* - * need to get the following things from the model - * 1. depth of item. - * 2. whether or not it has any children. - * 3. whether the item is a toplevel item. - * 3. ... anything else? - */ node = e_cell_tree_get_node (tree_model, row); offset = offset_of_node (tree_model, node); @@ -208,11 +201,13 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, /* draw our lines */ if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { - gdk_draw_line (drawable, tree_view->gc, - rect.x + offset - INDENT_AMOUNT / 2 + 1, - rect.y + rect.height / 2, - rect.x + offset, - rect.y + rect.height / 2); + if (!e_tree_model_node_is_root (tree_model, node) + || e_tree_model_node_get_children (tree_model, node, NULL) > 0) + gdk_draw_line (drawable, tree_view->gc, + rect.x + offset - INDENT_AMOUNT / 2 + 1, + rect.y + rect.height / 2, + rect.x + offset, + rect.y + rect.height / 2); if (visible_depth_of_node (tree_model, node) != 0) { gdk_draw_line (drawable, tree_view->gc, @@ -355,6 +350,102 @@ ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, voi e_cell_leave_edit (tree_view->subcell_view, model_col, view_col, row, edit_context); } +static void +ect_print (ECellView *ecell_view, GnomePrintContext *context, + int model_col, int view_col, int row, + double width, double height) +{ + ECellTreeView *tree_view = (ECellTreeView *) ecell_view; + + if (/* XXX only if we're the active sort */ TRUE) { + ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); + ETreePath *node = e_cell_tree_get_node (tree_model, row); + int offset = offset_of_node (tree_model, node); + int subcell_offset = offset; + + /* draw our lines */ + if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { + gnome_print_moveto (context, + offset - INDENT_AMOUNT / 2, + height / 2); + + gnome_print_lineto (context, + offset, + height / 2); + + if (visible_depth_of_node (tree_model, node) != 0) { + gnome_print_moveto (context, + offset - INDENT_AMOUNT / 2, + height); + gnome_print_lineto (context, + offset - INDENT_AMOUNT / 2, + (e_tree_model_node_get_next (tree_model, node) + ? 0 + : height / 2)); + } + + /* 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); + offset -= INDENT_AMOUNT; + while (node && visible_depth_of_node (tree_model, node) != 0) { + if (e_tree_model_node_get_next(tree_model, node)) { + gnome_print_moveto (context, + offset - INDENT_AMOUNT / 2, + height); + gnome_print_lineto (context, + offset - INDENT_AMOUNT / 2, + 0); + } + node = e_tree_model_node_get_parent (tree_model, node); + offset -= INDENT_AMOUNT; + } + } + +#if 0 + /* 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; + + width = gdk_pixbuf_get_width(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, + GDK_PIXBUF_ALPHA_BILEVEL, + 128, + GDK_RGB_DITHER_NORMAL, + width, 0); + } +#endif + + gnome_print_stroke (context); + + if (gnome_print_translate(context, subcell_offset, 0) == -1) + /* FIXME */; + width -= subcell_offset; + } + + + e_cell_print (tree_view->subcell_view, context, model_col, view_col, row, width, height); +} + +static gdouble +ect_print_height (ECellView *ecell_view, GnomePrintContext *context, + int model_col, int view_col, int row, + double width) +{ + return 12; /* XXX */ +} + /* * GtkObject::destroy method */ @@ -385,6 +476,8 @@ e_cell_tree_class_init (GtkObjectClass *object_class) ecc->height = ect_height; ecc->enter_edit = ect_enter_edit; ecc->leave_edit = ect_leave_edit; + ecc->print = ect_print; + ecc->print_height = ect_print_height; parent_class = gtk_type_class (PARENT_TYPE); } diff --git a/widgets/e-table/e-tree-example-1.c b/widgets/e-table/e-tree-example-1.c index e2ba566a99..688bc735b1 100644 --- a/widgets/e-table/e-tree-example-1.c +++ b/widgets/e-table/e-tree-example-1.c @@ -12,6 +12,8 @@ #include "e-cell-checkbox.h" #include "e-table.h" #include "e-tree-simple.h" +#include "libgnomeprint/gnome-print.h" +#include "libgnomeprint/gnome-print-preview.h" #include <gdk-pixbuf/gdk-pixbuf.h> @@ -62,22 +64,10 @@ char *headers [COLS] = { GtkWidget *e_table; /* - * ETableSimple callbacks + * ETreeSimple callbacks * These are the callbacks that define the behavior of our custom model. */ -/* - * Since our model is a constant size, we can just return its size in - * the column and row count fields. - */ - -/* This function returns the number of columns in our ETableModel. */ -static int -my_col_count (ETableModel *etc, void *data) -{ - return COLS; -} - /* This function returns the value at a particular point in our ETreeModel. */ static void * my_value_at (ETreeModel *etm, ETreePath *path, int col, void *model_data) @@ -137,7 +127,7 @@ 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, "User added sibling"); + selected_node, g_strdup("User added sibling")); } @@ -156,7 +146,7 @@ add_child (GtkButton *button, gpointer data) g_assert (selected_node); e_tree_model_node_insert (e_tree_model, selected_node, - 0, "User added child"); + 0, g_strdup("User added child")); } static void @@ -216,6 +206,19 @@ collapse_all (GtkButton *button, gpointer data) e_tree_model_node_set_expanded_recurse (e_tree_model, selected_node, FALSE); } +static void +print_tree (GtkButton *button, gpointer data) +{ + EPrintable *printable = e_table_get_printable (E_TABLE (e_table)); + GnomePrintContext *gpc; + + gpc = gnome_print_context_new (gnome_printer_new_generic_ps ("tree-out.ps")); + + e_printable_print_page (printable, gpc, 8*72, 10*72, FALSE); + + gnome_print_context_close (gpc); +} + /* We create a window containing our new tree. */ static void create_tree (void) @@ -273,8 +276,8 @@ create_tree (void) /* * Create our pixbuf for expanding/unexpanding */ - tree_expanded_pixbuf = gdk_pixbuf_new_from_xpm_data(tree_expanded_xpm); - tree_unexpanded_pixbuf = gdk_pixbuf_new_from_xpm_data(tree_unexpanded_xpm); + 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 @@ -348,6 +351,10 @@ create_tree (void) button = gtk_button_new_with_label ("Collapse All Below"); gtk_signal_connect (GTK_OBJECT (button), "clicked", collapse_all, e_tree_model); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + + button = gtk_button_new_with_label ("Print Tree"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", print_tree, e_tree_model); gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (window), vbox); diff --git a/widgets/table/e-cell-tree.c b/widgets/table/e-cell-tree.c index 28de6ff5bb..508d39e60f 100644 --- a/widgets/table/e-cell-tree.c +++ b/widgets/table/e-cell-tree.c @@ -167,13 +167,6 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, /* only draw the tree effects if we're the active sort */ if (/* XXX */ TRUE) { - /* - * need to get the following things from the model - * 1. depth of item. - * 2. whether or not it has any children. - * 3. whether the item is a toplevel item. - * 3. ... anything else? - */ node = e_cell_tree_get_node (tree_model, row); offset = offset_of_node (tree_model, node); @@ -208,11 +201,13 @@ ect_draw (ECellView *ecell_view, GdkDrawable *drawable, /* draw our lines */ if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { - gdk_draw_line (drawable, tree_view->gc, - rect.x + offset - INDENT_AMOUNT / 2 + 1, - rect.y + rect.height / 2, - rect.x + offset, - rect.y + rect.height / 2); + if (!e_tree_model_node_is_root (tree_model, node) + || e_tree_model_node_get_children (tree_model, node, NULL) > 0) + gdk_draw_line (drawable, tree_view->gc, + rect.x + offset - INDENT_AMOUNT / 2 + 1, + rect.y + rect.height / 2, + rect.x + offset, + rect.y + rect.height / 2); if (visible_depth_of_node (tree_model, node) != 0) { gdk_draw_line (drawable, tree_view->gc, @@ -355,6 +350,102 @@ ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, voi e_cell_leave_edit (tree_view->subcell_view, model_col, view_col, row, edit_context); } +static void +ect_print (ECellView *ecell_view, GnomePrintContext *context, + int model_col, int view_col, int row, + double width, double height) +{ + ECellTreeView *tree_view = (ECellTreeView *) ecell_view; + + if (/* XXX only if we're the active sort */ TRUE) { + ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); + ETreePath *node = e_cell_tree_get_node (tree_model, row); + int offset = offset_of_node (tree_model, node); + int subcell_offset = offset; + + /* draw our lines */ + if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { + gnome_print_moveto (context, + offset - INDENT_AMOUNT / 2, + height / 2); + + gnome_print_lineto (context, + offset, + height / 2); + + if (visible_depth_of_node (tree_model, node) != 0) { + gnome_print_moveto (context, + offset - INDENT_AMOUNT / 2, + height); + gnome_print_lineto (context, + offset - INDENT_AMOUNT / 2, + (e_tree_model_node_get_next (tree_model, node) + ? 0 + : height / 2)); + } + + /* 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); + offset -= INDENT_AMOUNT; + while (node && visible_depth_of_node (tree_model, node) != 0) { + if (e_tree_model_node_get_next(tree_model, node)) { + gnome_print_moveto (context, + offset - INDENT_AMOUNT / 2, + height); + gnome_print_lineto (context, + offset - INDENT_AMOUNT / 2, + 0); + } + node = e_tree_model_node_get_parent (tree_model, node); + offset -= INDENT_AMOUNT; + } + } + +#if 0 + /* 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; + + width = gdk_pixbuf_get_width(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, + GDK_PIXBUF_ALPHA_BILEVEL, + 128, + GDK_RGB_DITHER_NORMAL, + width, 0); + } +#endif + + gnome_print_stroke (context); + + if (gnome_print_translate(context, subcell_offset, 0) == -1) + /* FIXME */; + width -= subcell_offset; + } + + + e_cell_print (tree_view->subcell_view, context, model_col, view_col, row, width, height); +} + +static gdouble +ect_print_height (ECellView *ecell_view, GnomePrintContext *context, + int model_col, int view_col, int row, + double width) +{ + return 12; /* XXX */ +} + /* * GtkObject::destroy method */ @@ -385,6 +476,8 @@ e_cell_tree_class_init (GtkObjectClass *object_class) ecc->height = ect_height; ecc->enter_edit = ect_enter_edit; ecc->leave_edit = ect_leave_edit; + ecc->print = ect_print; + ecc->print_height = ect_print_height; parent_class = gtk_type_class (PARENT_TYPE); } diff --git a/widgets/table/e-tree-example-1.c b/widgets/table/e-tree-example-1.c index e2ba566a99..688bc735b1 100644 --- a/widgets/table/e-tree-example-1.c +++ b/widgets/table/e-tree-example-1.c @@ -12,6 +12,8 @@ #include "e-cell-checkbox.h" #include "e-table.h" #include "e-tree-simple.h" +#include "libgnomeprint/gnome-print.h" +#include "libgnomeprint/gnome-print-preview.h" #include <gdk-pixbuf/gdk-pixbuf.h> @@ -62,22 +64,10 @@ char *headers [COLS] = { GtkWidget *e_table; /* - * ETableSimple callbacks + * ETreeSimple callbacks * These are the callbacks that define the behavior of our custom model. */ -/* - * Since our model is a constant size, we can just return its size in - * the column and row count fields. - */ - -/* This function returns the number of columns in our ETableModel. */ -static int -my_col_count (ETableModel *etc, void *data) -{ - return COLS; -} - /* This function returns the value at a particular point in our ETreeModel. */ static void * my_value_at (ETreeModel *etm, ETreePath *path, int col, void *model_data) @@ -137,7 +127,7 @@ 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, "User added sibling"); + selected_node, g_strdup("User added sibling")); } @@ -156,7 +146,7 @@ add_child (GtkButton *button, gpointer data) g_assert (selected_node); e_tree_model_node_insert (e_tree_model, selected_node, - 0, "User added child"); + 0, g_strdup("User added child")); } static void @@ -216,6 +206,19 @@ collapse_all (GtkButton *button, gpointer data) e_tree_model_node_set_expanded_recurse (e_tree_model, selected_node, FALSE); } +static void +print_tree (GtkButton *button, gpointer data) +{ + EPrintable *printable = e_table_get_printable (E_TABLE (e_table)); + GnomePrintContext *gpc; + + gpc = gnome_print_context_new (gnome_printer_new_generic_ps ("tree-out.ps")); + + e_printable_print_page (printable, gpc, 8*72, 10*72, FALSE); + + gnome_print_context_close (gpc); +} + /* We create a window containing our new tree. */ static void create_tree (void) @@ -273,8 +276,8 @@ create_tree (void) /* * Create our pixbuf for expanding/unexpanding */ - tree_expanded_pixbuf = gdk_pixbuf_new_from_xpm_data(tree_expanded_xpm); - tree_unexpanded_pixbuf = gdk_pixbuf_new_from_xpm_data(tree_unexpanded_xpm); + 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 @@ -348,6 +351,10 @@ create_tree (void) button = gtk_button_new_with_label ("Collapse All Below"); gtk_signal_connect (GTK_OBJECT (button), "clicked", collapse_all, e_tree_model); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + + button = gtk_button_new_with_label ("Print Tree"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", print_tree, e_tree_model); gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (window), vbox); |