From e4bdc1e6a762058e4e289d6d7710dcadda1caca1 Mon Sep 17 00:00:00 2001 From: Srinivasa Ragavan Date: Fri, 2 Jun 2006 18:12:08 +0000 Subject: Added support for Vertical View in Evolution Mailer with custom message list. svn path=/trunk/; revision=32071 --- widgets/table/Makefile.am | 2 + widgets/table/e-cell-hbox.c | 323 ++++++++++++++++++++++++++++++++++++ widgets/table/e-cell-hbox.h | 74 +++++++++ widgets/table/e-cell-text.c | 21 +++ widgets/table/e-cell-tree.c | 7 + widgets/table/e-table-header-item.c | 76 ++++++++- 6 files changed, 500 insertions(+), 3 deletions(-) create mode 100644 widgets/table/e-cell-hbox.c create mode 100644 widgets/table/e-cell-hbox.h (limited to 'widgets/table') diff --git a/widgets/table/Makefile.am b/widgets/table/Makefile.am index 2732ee6c6c..72a804a445 100644 --- a/widgets/table/Makefile.am +++ b/widgets/table/Makefile.am @@ -35,6 +35,7 @@ libetable_la_SOURCES = \ e-cell-toggle.c \ e-cell-tree.c \ e-cell-vbox.c \ + e-cell-hbox.c \ e-table-click-to-add.c \ e-table-col.c \ e-table-column-specification.c \ @@ -98,6 +99,7 @@ libetableinclude_HEADERS = \ e-cell-toggle.h \ e-cell-tree.h \ e-cell-vbox.h \ + e-cell-hbox.h \ e-table-click-to-add.h \ e-table-col-dnd.h \ e-table-col.h \ diff --git a/widgets/table/e-cell-hbox.c b/widgets/table/e-cell-hbox.c new file mode 100644 index 0000000000..722f1eb507 --- /dev/null +++ b/widgets/table/e-cell-hbox.c @@ -0,0 +1,323 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-cell-hbox.c - Hbox cell object. + * Copyright 2006 Novell, Inc. + * + * Authors: + * Srinivasa Ragavan + * + * A majority of code taken from: + * + * the ECellText renderer. + * Copyright 1999, 2000, Ximian, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License, version 2, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include + +#include +#include +#include + +#include + +/* #include "a11y/e-table/gal-a11y-e-cell-registry.h" */ +/* #include "a11y/e-table/gal-a11y-e-cell-vbox.h" */ +#include "e-util/e-util.h" + +#include "e-cell-hbox.h" +#include "e-table-item.h" + +#define PARENT_TYPE e_cell_get_type () + +static ECellClass *parent_class; + +#define INDENT_AMOUNT 16 +#define MAX_CELL_SIZE 25 + +/* + * ECell::new_view method + */ +static ECellView * +ecv_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) +{ + ECellHbox *ecv = E_CELL_HBOX (ecell); + ECellHboxView *hbox_view = g_new0 (ECellHboxView, 1); + int i; + + hbox_view->cell_view.ecell = ecell; + hbox_view->cell_view.e_table_model = table_model; + hbox_view->cell_view.e_table_item_view = e_table_item_view; + + /* create our subcell view */ + hbox_view->subcell_view_count = ecv->subcell_count; + hbox_view->subcell_views = g_new (ECellView *, hbox_view->subcell_view_count); + hbox_view->model_cols = g_new (int, hbox_view->subcell_view_count); + hbox_view->def_size_cols = g_new (int, hbox_view->subcell_view_count); + + for (i = 0; i < hbox_view->subcell_view_count; i++) { + hbox_view->subcell_views[i] = e_cell_new_view (ecv->subcells[i], table_model, e_table_item_view /* XXX */); + hbox_view->model_cols[i] = ecv->model_cols[i]; + hbox_view->def_size_cols[i] = ecv->def_size_cols[i]; + } + + return (ECellView *)hbox_view; +} + +/* + * ECell::kill_view method + */ +static void +ecv_kill_view (ECellView *ecv) +{ + ECellHboxView *hbox_view = (ECellHboxView *) ecv; + int i; + + /* kill our subcell view */ + for (i = 0; i < hbox_view->subcell_view_count; i++) + e_cell_kill_view (hbox_view->subcell_views[i]); + + g_free (hbox_view->model_cols); + g_free (hbox_view->def_size_cols); + g_free (hbox_view->subcell_views); + g_free (hbox_view); +} + +/* + * ECell::realize method + */ +static void +ecv_realize (ECellView *ecell_view) +{ + ECellHboxView *hbox_view = (ECellHboxView *) ecell_view; + int i; + + /* realize our subcell view */ + for (i = 0; i < hbox_view->subcell_view_count; i++) + e_cell_realize (hbox_view->subcell_views[i]); + + if (parent_class->realize) + (* parent_class->realize) (ecell_view); +} + +/* + * ECell::unrealize method + */ +static void +ecv_unrealize (ECellView *ecv) +{ + ECellHboxView *hbox_view = (ECellHboxView *) ecv; + int i; + + /* unrealize our subcell view. */ + for (i = 0; i < hbox_view->subcell_view_count; i++) + e_cell_unrealize (hbox_view->subcell_views[i]); + + if (parent_class->unrealize) + (* parent_class->unrealize) (ecv); +} + +/* + * ECell::draw method + */ +static void +ecv_draw (ECellView *ecell_view, GdkDrawable *drawable, + int model_col, int view_col, int row, ECellFlags flags, + int x1, int y1, int x2, int y2) +{ + ECellHboxView *hbox_view = (ECellHboxView *)ecell_view; + + int subcell_offset = 0; + int i; + int allotted_width = x2-x1; + + for (i = 0; i < hbox_view->subcell_view_count; i++) { + /* Now cause our subcells to draw their contents, + shifted by subcell_offset pixels */ + int width = allotted_width * hbox_view->def_size_cols[i] / 100; + //e_cell_max_width_by_row (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col, row); +// if (width < hbox_view->def_size_cols[i]) + // width = hbox_view->def_size_cols[i]; +// printf("width of %d %d of %d\n", width,hbox_view->def_size_cols[i], allotted_width ); + e_cell_draw (hbox_view->subcell_views[i], drawable, + hbox_view->model_cols[i], view_col, row, flags, + x1 + subcell_offset , y1, x1 + subcell_offset + width, y2); + + subcell_offset += width; //e_cell_max_width_by_row (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col, row); + } +} + +/* + * ECell::event method + */ +static gint +ecv_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions) +{ + ECellHboxView *hbox_view = (ECellHboxView *)ecell_view; + int y = 0; + int i; + int subcell_offset = 0; + + switch (event->type) { + case GDK_BUTTON_PRESS: + case GDK_BUTTON_RELEASE: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + y = event->button.y; + break; + case GDK_MOTION_NOTIFY: + y = event->motion.y; + break; + default: + /* nada */ + break; + } + + for (i = 0; i < hbox_view->subcell_view_count; i++) { + int width = e_cell_max_width_by_row (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col, row); + if (width < hbox_view->def_size_cols[i]) + width = hbox_view->def_size_cols[i]; + if (y < subcell_offset + width) + return e_cell_event(hbox_view->subcell_views[i], event, hbox_view->model_cols[i], view_col, row, flags, actions); + subcell_offset += width; + } + return 0; +} + +/* + * ECell::height method + */ +static int +ecv_height (ECellView *ecell_view, int model_col, int view_col, int row) +{ + ECellHboxView *hbox_view = (ECellHboxView *)ecell_view; + int height = 0, max_height = 0; + int i; + + for (i = 0; i < hbox_view->subcell_view_count; i++) { + height = e_cell_height (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col, row); + max_height = MAX(max_height, height); + } + return max_height; +} + +/* + * ECell::max_width method + */ +static int +ecv_max_width (ECellView *ecell_view, int model_col, int view_col) +{ + ECellHboxView *hbox_view = (ECellHboxView *)ecell_view; + int width = 0; + int i; + + for (i = 0; i < hbox_view->subcell_view_count; i++) { + int cell_width = e_cell_max_width (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col); + + if (cell_width < hbox_view->def_size_cols[i]) + cell_width = hbox_view->def_size_cols[i]; + width += cell_width; + } + + return width; +} + +/* + * GObject::dispose method + */ +static void +ecv_dispose (GObject *object) +{ + ECellHbox *ecv = E_CELL_HBOX (object); + int i; + + /* destroy our subcell */ + for (i = 0; i < ecv->subcell_count; i++) + if (ecv->subcells[i]) + g_object_unref (ecv->subcells[i]); + g_free (ecv->subcells); + ecv->subcells = NULL; + ecv->subcell_count = 0; + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +e_cell_hbox_class_init (GObjectClass *object_class) +{ + ECellClass *ecc = (ECellClass *) object_class; + + object_class->dispose = ecv_dispose; + + ecc->new_view = ecv_new_view; + ecc->kill_view = ecv_kill_view; + ecc->realize = ecv_realize; + ecc->unrealize = ecv_unrealize; + ecc->draw = ecv_draw; + ecc->event = ecv_event; + ecc->height = ecv_height; + + ecc->max_width = ecv_max_width; + + parent_class = g_type_class_ref (PARENT_TYPE); + +/* gal_a11y_e_cell_registry_add_cell_type (NULL, E_CELL_HBOX_TYPE, gal_a11y_e_cell_hbox_new); */ +} + +static void +e_cell_hbox_init (GtkObject *object) +{ + ECellHbox *ecv = E_CELL_HBOX (object); + + ecv->subcells = NULL; + ecv->subcell_count = 0; +} + +E_MAKE_TYPE(e_cell_hbox, "ECellHbox", ECellHbox, e_cell_hbox_class_init, e_cell_hbox_init, PARENT_TYPE) + +/** + * e_cell_hbox_new: + * + * Creates a new ECell renderer that can be used to render multiple + * child cells. + * + * Return value: an ECell object that can be used to render multiple + * child cells. + **/ +ECell * +e_cell_hbox_new (void) +{ + ECellHbox *ecv = g_object_new (E_CELL_HBOX_TYPE, NULL); + + return (ECell *) ecv; +} + +void +e_cell_hbox_append (ECellHbox *hbox, ECell *subcell, int model_col, int size) +{ + hbox->subcell_count ++; + + hbox->subcells = g_renew (ECell *, hbox->subcells, hbox->subcell_count); + hbox->model_cols = g_renew (int, hbox->model_cols, hbox->subcell_count); + hbox->def_size_cols = g_renew (int, hbox->def_size_cols, hbox->subcell_count); + + hbox->subcells[hbox->subcell_count - 1] = subcell; + hbox->model_cols[hbox->subcell_count - 1] = model_col; + hbox->def_size_cols[hbox->subcell_count - 1] = size; + + if (subcell) + g_object_ref (subcell); +} diff --git a/widgets/table/e-cell-hbox.h b/widgets/table/e-cell-hbox.h new file mode 100644 index 0000000000..9a5148d3f2 --- /dev/null +++ b/widgets/table/e-cell-hbox.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-cell-hbox.h - Hbox cell object. + * Copyright 2006, Novell, Inc. + * + * Authors: + * Srinivasa Ragavan + * + * A majority of code taken from: + * + * the ECellText renderer. + * Copyright 1999, 2000, Ximian, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License, version 2, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef _E_CELL_HBOX_H_ +#define _E_CELL_HBOX_H_ + +#include +#include + +G_BEGIN_DECLS + +#define E_CELL_HBOX_TYPE (e_cell_hbox_get_type ()) +#define E_CELL_HBOX(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), E_CELL_HBOX_TYPE, ECellHbox)) +#define E_CELL_HBOX_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), E_CELL_HBOX_TYPE, ECellHboxClass)) +#define E_IS_CELL_HBOX(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_CELL_HBOX_TYPE)) +#define E_IS_CELL_HBOX_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), E_CELL_HBOX_TYPE)) + +typedef struct { + ECell parent; + + int subcell_count; + ECell **subcells; + int *model_cols; + int *def_size_cols; +} ECellHbox; + +typedef struct { + ECellView cell_view; + int subcell_view_count; + ECellView **subcell_views; + int *model_cols; + int *def_size_cols; +} ECellHboxView; + +typedef struct { + ECellClass parent_class; +} ECellHboxClass; + +GType e_cell_hbox_get_type (void); +ECell *e_cell_hbox_new (void); +void e_cell_hbox_append (ECellHbox *vbox, + ECell *subcell, + int model_col, + int size); + + +G_END_DECLS + +#endif /* _E_CELL_HBOX_H_ */ diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c index a446a69522..6a3ec19945 100644 --- a/widgets/table/e-cell-text.c +++ b/widgets/table/e-cell-text.c @@ -581,6 +581,27 @@ build_layout (ECellTextView *text_view, int row, const char *text, gint width) if (text_view->edit || width <= 0) return layout; + if (ect->font_name) + { + PangoFontDescription *desc = NULL, *fixed_desc = NULL; + char *fixed_family = NULL; + gint fixed_size; + + fixed_desc = pango_font_description_from_string (ect->font_name); + if (fixed_desc) { + fixed_family = pango_font_description_get_family (fixed_desc); + fixed_size = pango_font_description_get_size (fixed_desc); + } + + desc = pango_font_description_copy (gtk_widget_get_style (GTK_WIDGET (((GnomeCanvasItem *)ecell_view->e_table_item_view)->canvas))->font_desc); + pango_font_description_set_family (desc, fixed_family); + pango_font_description_set_size (desc, fixed_size); +/* pango_font_description_set_style (desc, PANGO_STYLE_OBLIQUE); */ + pango_layout_set_font_description (layout, desc); + pango_font_description_free (desc); + pango_font_description_free (fixed_desc); + } + pango_layout_set_width (layout, width * PANGO_SCALE); pango_layout_set_wrap (layout, PANGO_WRAP_CHAR); diff --git a/widgets/table/e-cell-tree.c b/widgets/table/e-cell-tree.c index d42a067931..133254dd4b 100644 --- a/widgets/table/e-cell-tree.c +++ b/widgets/table/e-cell-tree.c @@ -483,9 +483,16 @@ ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, gint tmp_row = row; GdkRectangle area; animate_closure_t *closure = g_new0 (animate_closure_t, 1); + int hgt; + e_table_item_get_cell_geometry (tree_view->cell_view.e_table_item_view, &tmp_row, &view_col, &area.x, &area.y, NULL, &area.height); area.width = offset - 2; + hgt = e_cell_height (ecell_view, model_col, view_col, row); + + if (hgt != area.height) /* Composite cells */ + area.height += hgt; + draw_expander (tree_view, GTK_LAYOUT (tree_view->canvas)->bin_window, expanded ? GTK_EXPANDER_SEMI_EXPANDED : GTK_EXPANDER_SEMI_COLLAPSED, GTK_STATE_NORMAL, &area); diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c index 7f340f990a..74332dc61c 100644 --- a/widgets/table/e-table-header-item.c +++ b/widgets/table/e-table-header-item.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -1449,7 +1450,7 @@ ethi_popup_customize_view(GtkWidget *widget, EthiHeaderInfo *info) ETableHeaderItem *ethi = info->ethi; ETableState *state; ETableSpecification *spec; - + if (ethi->config) e_table_config_raise (E_TABLE_CONFIG (ethi->config)); else { @@ -1501,12 +1502,38 @@ static EPopupMenu ethi_context_menu [] = { E_POPUP_TERMINATOR }; +static void +sort_by_id (GtkWidget *menu_item, ETableHeaderItem *ethi) +{ + int col = GPOINTER_TO_INT (g_object_get_data(menu_item, "col-number")); + ETableCol *ecol; + + if (!gtk_check_menu_item_get_active(menu_item)) + return; + + ecol = e_table_header_get_column (ethi->full_header, col); + ethi_change_sort_state (ethi, ecol); +} + +static void +popup_custom (GtkWidget *menu_item, EthiHeaderInfo *info) +{ + if (!gtk_check_menu_item_get_active(menu_item)) + return; + + ethi_popup_customize_view(menu_item, info); +} static void ethi_header_context_menu (ETableHeaderItem *ethi, GdkEventButton *event) { EthiHeaderInfo *info = g_new(EthiHeaderInfo, 1); ETableCol *col; - GtkMenu *popup; + GtkMenu *popup, *sub_menu;; + int ncol, sort_count, sort_col; + GtkWidget *menu_item; + GSList *group = NULL; + ETableSortColumn column; + info->ethi = ethi; info->col = ethi_find_col_by_x (ethi, event->x); col = e_table_header_get_column (ethi->eth, info->col); @@ -1518,6 +1545,49 @@ ethi_header_context_menu (ETableHeaderItem *ethi, GdkEventButton *event) ((e_table_header_count (ethi->eth) > 1) ? 0 : 8), ((e_table_sort_info_get_can_group (ethi->sort_info)) ? 0 : 16) + 128, info, E_I18N_DOMAIN); + + menu_item = gtk_menu_item_new_with_label (_("Sort By")); + gtk_widget_show (menu_item); + sub_menu = gtk_menu_new (); + gtk_widget_show (sub_menu); + gtk_menu_item_set_submenu (menu_item, sub_menu); + gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), menu_item); + + sort_count = e_table_sort_info_sorting_get_count(ethi->sort_info); + + if (sort_count > 1 || sort_count < 1) + sort_col = -1; /* Custom sorting */ + else { + column = e_table_sort_info_sorting_get_nth(ethi->sort_info, 0); + sort_col = column.column; + } + + /* Custom */ + menu_item = gtk_radio_menu_item_new_with_label (group, _("Custom")); + group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menu_item)); + gtk_widget_show (menu_item); + gtk_menu_shell_prepend (GTK_MENU_SHELL (sub_menu), menu_item); + if (sort_col == -1) + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), TRUE); + g_signal_connect (menu_item, "toggled", G_CALLBACK (popup_custom), info); + + /* Show a seperator */ + menu_item = gtk_separator_menu_item_new (); + gtk_widget_show (menu_item); + gtk_menu_shell_prepend (GTK_MENU_SHELL (sub_menu), menu_item); + /* Headers */ + for (ncol = 0; ncolfull_header->col_count; ncol++) + { + menu_item = gtk_radio_menu_item_new_with_label (group, ethi->full_header->columns[ncol]->text); + gtk_widget_show (menu_item); + gtk_menu_shell_prepend (GTK_MENU_SHELL (sub_menu), menu_item); + + if (ncol == sort_col) + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), TRUE); + g_object_set_data (menu_item, "col-number", GINT_TO_POINTER (ncol)); + g_signal_connect (menu_item, "toggled", G_CALLBACK (sort_by_id), ethi); + } + g_object_ref (popup); gtk_object_sink (GTK_OBJECT (popup)); g_signal_connect (popup, "selection-done", @@ -1718,7 +1788,7 @@ ethi_event (GnomeCanvasItem *item, GdkEvent *e) ethi_end_resize (ethi); } else if (was_maybe_drag && ethi->sort_info) { ETableCol *ecol; - + ecol = e_table_header_get_column (ethi->eth, ethi_find_col_by_x (ethi, e->button.x)); ethi_change_sort_state (ethi, ecol); } -- cgit