diff options
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/table/e-cell-date.c | 137 | ||||
-rw-r--r-- | widgets/table/e-cell-date.h | 28 | ||||
-rw-r--r-- | widgets/table/e-cell-size.c | 92 | ||||
-rw-r--r-- | widgets/table/e-cell-size.h | 28 | ||||
-rw-r--r-- | widgets/table/e-cell-text.c | 138 | ||||
-rw-r--r-- | widgets/table/e-cell-text.h | 10 | ||||
-rw-r--r-- | widgets/table/e-table-extras.c | 4 |
7 files changed, 366 insertions, 71 deletions
diff --git a/widgets/table/e-cell-date.c b/widgets/table/e-cell-date.c new file mode 100644 index 0000000000..e8d9d5a2bd --- /dev/null +++ b/widgets/table/e-cell-date.c @@ -0,0 +1,137 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* ECellDate - Date item for e-table. + * Copyright (C) 2001 Ximian, Inc. + * Author: Chris Lahey <clahey@ximian.com> + */ + +#include <config.h> +#include "e-cell-date.h" +#include <gnome.h> +#include <sys/time.h> +#include <unistd.h> +#include <gal/util/e-util.h> + +#define PARENT_TYPE e_cell_text_get_type () + +static ECellTextClass *parent_class; + +static char * +ecd_get_text(ECellText *cell, ETableModel *model, int col, int row) +{ + time_t date = GPOINTER_TO_INT (e_table_model_value_at(model, col, row)); + time_t nowdate = time(NULL); + time_t yesdate; + struct tm then, now, yesterday; + char buf[26]; + gboolean done = FALSE; + + if (date == 0) + return g_strdup (_("?")); + + localtime_r (&date, &then); + localtime_r (&nowdate, &now); + if (then.tm_mday == now.tm_mday && + then.tm_mon == now.tm_mon && + then.tm_year == now.tm_year) { + strftime (buf, 26, _("Today %l:%M %p"), &then); + done = TRUE; + } + if (!done) { + yesdate = nowdate - 60 * 60 * 24; + localtime_r (&yesdate, &yesterday); + if (then.tm_mday == yesterday.tm_mday && + then.tm_mon == yesterday.tm_mon && + then.tm_year == yesterday.tm_year) { + strftime (buf, 26, _("Yesterday %l:%M %p"), &then); + done = TRUE; + } + } + if (!done) { + int i; + for (i = 2; i < 7; i++) { + yesdate = nowdate - 60 * 60 * 24 * i; + localtime_r (&yesdate, &yesterday); + if (then.tm_mday == yesterday.tm_mday && + then.tm_mon == yesterday.tm_mon && + then.tm_year == yesterday.tm_year) { + strftime (buf, 26, _("%a %l:%M %p"), &then); + done = TRUE; + break; + } + } + } + if (!done) { + if (then.tm_year == now.tm_year) { + strftime (buf, 26, _("%b %d %l:%M %p"), &then); + } else { + strftime (buf, 26, _("%b %d %Y"), &then); + } + } +#if 0 +#ifdef CTIME_R_THREE_ARGS + ctime_r (&date, buf, 26); +#else + ctime_r (&date, buf); +#endif +#endif + + return g_strdup (buf); +} + +static void +ecd_free_text(ECellText *cell, char *text) +{ + g_free(text); +} + +static void +e_cell_date_class_init (GtkObjectClass *object_class) +{ + ECellTextClass *ectc = (ECellTextClass *) object_class; + + parent_class = gtk_type_class (PARENT_TYPE); + + ectc->get_text = ecd_get_text; + ectc->free_text = ecd_free_text; +} + +static void +e_cell_date_init (GtkObject *object) +{ +} + +/** + * e_cell_date_new: + * @fontname: font to be used to render on the screen + * @justify: Justification of the string in the cell. + * + * Creates a new ECell renderer that can be used to render dates that + * that come from the model. The value returned from the model is + * interpreted as being a time_t. + * + * The ECellDate object support a large set of properties that can be + * configured through the Gtk argument system and allows the user to have + * a finer control of the way the string is displayed. The arguments supported + * allow the control of strikeout, bold, color and a date filter. + * + * The arguments "strikeout_column", "bold_column" and "color_column" set + * and return an integer that points to a column in the model that controls + * these settings. So controlling the way things are rendered is achieved + * by having special columns in the model that will be used to flag whether + * the date should be rendered with strikeout, or bolded. In the case of + * the "color_column" argument, the column in the model is expected to have + * a string that can be parsed by gdk_color_parse(). + * + * Returns: an ECell object that can be used to render dates. + */ +ECell * +e_cell_date_new (const char *fontname, GtkJustification justify) +{ + ECellDate *ecd = gtk_type_new (e_cell_date_get_type ()); + + e_cell_text_construct(E_CELL_TEXT(ecd), fontname, justify); + + return (ECell *) ecd; +} + +E_MAKE_TYPE(e_cell_date, "ECellDate", ECellDate, e_cell_date_class_init, e_cell_date_init, PARENT_TYPE); diff --git a/widgets/table/e-cell-date.h b/widgets/table/e-cell-date.h new file mode 100644 index 0000000000..0dece367e3 --- /dev/null +++ b/widgets/table/e-cell-date.h @@ -0,0 +1,28 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* ECellDate - Date item for e-table. + * Copyright (C) 2001 Ximian, Inc. + * Author: Chris Lahey <clahey@ximian.com> + */ +#ifndef _E_CELL_DATE_H_ +#define _E_CELL_DATE_H_ + +#include <gal/e-table/e-cell-text.h> + +#define E_CELL_DATE_TYPE (e_cell_date_get_type ()) +#define E_CELL_DATE(o) (GTK_CHECK_CAST ((o), E_CELL_DATE_TYPE, ECellDate)) +#define E_CELL_DATE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_DATE_TYPE, ECellDateClass)) +#define E_IS_CELL_DATE(o) (GTK_CHECK_TYPE ((o), E_CELL_DATE_TYPE)) +#define E_IS_CELL_DATE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_DATE_TYPE)) + +typedef struct { + ECellText base; +} ECellDate; + +typedef struct { + ECellTextClass parent_class; +} ECellDateClass; + +GtkType e_cell_date_get_type (void); +ECell *e_cell_date_new (const char *fontname, GtkJustification justify); + +#endif /* _E_CELL_DATE_H_ */ diff --git a/widgets/table/e-cell-size.c b/widgets/table/e-cell-size.c new file mode 100644 index 0000000000..7943ad8d8a --- /dev/null +++ b/widgets/table/e-cell-size.c @@ -0,0 +1,92 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* ECellSize - Size item for e-table. + * Copyright (C) 2001 Ximian, Inc. + * Author: Chris Lahey <clahey@ximian.com> + */ + +#include <config.h> +#include "e-cell-size.h" +#include <gnome.h> +#include <sys/time.h> +#include <unistd.h> +#include <gal/util/e-util.h> + +#define PARENT_TYPE e_cell_text_get_type () + +static ECellTextClass *parent_class; + +static char * +ecd_get_text(ECellText *cell, ETableModel *model, int col, int row) +{ + gint size = GPOINTER_TO_INT(e_table_model_value_at(model, col, row)); + gfloat fsize; + + if (size < 1024) { + return g_strdup_printf ("%d", size); + } else { + fsize = ((gfloat) size) / 1024.0; + if (fsize < 1024.0) { + return g_strdup_printf ("%.2f K", fsize); + } else { + fsize /= 1024.0; + return g_strdup_printf ("%.2f M", fsize); + } + } +} + +static void +ecd_free_text(ECellText *cell, char *text) +{ + g_free(text); +} + +static void +e_cell_size_class_init (GtkObjectClass *object_class) +{ + ECellTextClass *ectc = (ECellTextClass *) object_class; + + parent_class = gtk_type_class (PARENT_TYPE); + + ectc->get_text = ecd_get_text; + ectc->free_text = ecd_free_text; +} + +static void +e_cell_size_init (GtkObject *object) +{ +} + +/** + * e_cell_size_new: + * @fontname: font to be used to render on the screen + * @justify: Justification of the string in the cell. + * + * Creates a new ECell renderer that can be used to render file sizes + * that that come from the model. The value returned from the model + * is interpreted as being a time_t. + * + * The ECellSize object support a large set of properties that can be + * configured through the Gtk argument system and allows the user to have + * a finer control of the way the string is displayed. The arguments supported + * allow the control of strikeout, bold, color and a size filter. + * + * The arguments "strikeout_column", "bold_column" and "color_column" set + * and return an integer that points to a column in the model that controls + * these settings. So controlling the way things are rendered is achieved + * by having special columns in the model that will be used to flag whether + * the size should be rendered with strikeout, or bolded. In the case of + * the "color_column" argument, the column in the model is expected to have + * a string that can be parsed by gdk_color_parse(). + * + * Returns: an ECell object that can be used to render file sizes. */ +ECell * +e_cell_size_new (const char *fontname, GtkJustification justify) +{ + ECellSize *ecd = gtk_type_new (e_cell_size_get_type ()); + + e_cell_text_construct(E_CELL_TEXT(ecd), fontname, justify); + + return (ECell *) ecd; +} + +E_MAKE_TYPE(e_cell_size, "ECellSize", ECellSize, e_cell_size_class_init, e_cell_size_init, PARENT_TYPE); diff --git a/widgets/table/e-cell-size.h b/widgets/table/e-cell-size.h new file mode 100644 index 0000000000..229d316642 --- /dev/null +++ b/widgets/table/e-cell-size.h @@ -0,0 +1,28 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* ECellSize - Size item for e-table. + * Copyright (C) 2001 Ximian, Inc. + * Author: Chris Lahey <clahey@ximian.com> + */ +#ifndef _E_CELL_SIZE_H_ +#define _E_CELL_SIZE_H_ + +#include <gal/e-table/e-cell-text.h> + +#define E_CELL_SIZE_TYPE (e_cell_size_get_type ()) +#define E_CELL_SIZE(o) (GTK_CHECK_CAST ((o), E_CELL_SIZE_TYPE, ECellSize)) +#define E_CELL_SIZE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_SIZE_TYPE, ECellSizeClass)) +#define E_IS_CELL_SIZE(o) (GTK_CHECK_TYPE ((o), E_CELL_SIZE_TYPE)) +#define E_IS_CELL_SIZE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_SIZE_TYPE)) + +typedef struct { + ECellText base; +} ECellSize; + +typedef struct { + ECellTextClass parent_class; +} ECellSizeClass; + +GtkType e_cell_size_get_type (void); +ECell *e_cell_size_new (const char *fontname, GtkJustification justify); + +#endif /* _E_CELL_SIZE_H_ */ diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c index 8b2bdb8a06..29568249cd 100644 --- a/widgets/table/e-cell-text.c +++ b/widgets/table/e-cell-text.c @@ -49,6 +49,8 @@ #include <ctype.h> #include <math.h> +#define ECT_CLASS(c) (E_CELL_TEXT_CLASS(GTK_OBJECT((c))->klass)) + /* This defines a line of text */ struct line { char *text; /* Line's text UTF-8, it is a pointer into the text->text string */ @@ -63,8 +65,6 @@ enum { ARG_STRIKEOUT_COLUMN, ARG_BOLD_COLUMN, - ARG_TEXT_FILTER_FUNC, - ARG_TEXT_FILTER_CLOSURE, ARG_COLOR_COLUMN, }; @@ -211,6 +211,33 @@ static GdkColor* e_cell_text_get_color (ECellTextView *cell_view, gchar *color_s static ECellClass *parent_class; +static char * +ect_get_text (ECellText *cell, ETableModel *model, int col, int row) +{ + if (ECT_CLASS(cell)->get_text) + return ECT_CLASS(cell)->get_text (cell, model, col, row); + else + return NULL; +} + +static void +ect_free_text (ECellText *cell, char *text) +{ + if (ECT_CLASS(cell)->free_text) + ECT_CLASS(cell)->free_text (cell, text); +} + +static char * +ect_real_get_text (ECellText *cell, ETableModel *model, int col, int row) +{ + return e_table_model_value_at(model, col, row); +} + +static void +ect_real_free_text (ECellText *cell, char *text) +{ +} + static void ect_queue_redraw (ECellTextView *text_view, int view_col, int view_row) { @@ -900,28 +927,16 @@ ect_height (ECellView *ecell_view, int model_col, int view_col, int row) ECellTextView *text_view = (ECellTextView *) ecell_view; EFont *font; ECellText *ect = E_CELL_TEXT(ecell_view->ecell); + gchar *string; + gint value; font = text_view->font; - if (ect->filter_func) { - gchar *string; - gint value; - - string = (*ect->filter_func)(NULL, e_table_model_value_at (ecell_view->e_table_model, model_col, row), ect->filter_closure); - value = e_font_height (font) * number_of_lines(string) + TEXT_PAD; - - g_free(string); - - return value; - } else { - gchar * string; - gint value; - string = e_table_model_value_at (ecell_view->e_table_model, model_col, row); + string = ect_get_text(ect, ecell_view->e_table_model, model_col, row); + value = e_font_height (font) * number_of_lines(string) + TEXT_PAD; + ect_free_text(ect, string); - value = e_font_height (font) * number_of_lines (string) + TEXT_PAD; - - return value; - } + return value; } /* @@ -933,6 +948,7 @@ ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) ECellTextView *text_view = (ECellTextView *) ecell_view; CellEdit *edit; ECellText *ect = E_CELL_TEXT(ecell_view->ecell); + char *temp; edit = g_new (CellEdit, 1); text_view->edit = edit; @@ -974,11 +990,9 @@ ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) edit->pointer_in = FALSE; edit->default_cursor_shown = TRUE; - if (ect->filter_func) { - edit->old_text = (*ect->filter_func)(NULL, e_table_model_value_at (ecell_view->e_table_model, model_col, row), ect->filter_closure); - } else { - edit->old_text = g_strdup (e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } + temp = ect_get_text(ect, ecell_view->e_table_model, model_col, row); + edit->old_text = g_strdup (temp); + ect_free_text(ect, temp); edit->cell.text = g_strdup (edit->old_text); #if 0 @@ -1025,11 +1039,7 @@ ect_print (ECellView *ecell_view, GnomePrintContext *context, GnomeFont *font = gnome_font_new ("Helvetica", 12); char *string; ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - if (ect->filter_func) { - string = (*ect->filter_func)(NULL, e_table_model_value_at (ecell_view->e_table_model, model_col, row), ect->filter_closure); - } else { - string = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - } + string = ect_get_text(ect, ecell_view->e_table_model, model_col, row); gnome_print_gsave(context); if (gnome_print_moveto(context, 2, 2) == -1) /* FIXME */; @@ -1047,9 +1057,7 @@ ect_print (ECellView *ecell_view, GnomePrintContext *context, gnome_print_setfont(context, font); gnome_print_show(context, string); gnome_print_grestore(context); - if (ect->filter_func) { - g_free(string); - } + ect_free_text(ect, string); } static gdouble @@ -1314,13 +1322,6 @@ ect_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) text->color_column = GTK_VALUE_INT (*arg); break; - case ARG_TEXT_FILTER_FUNC: - text->filter_func = GTK_VALUE_POINTER (*arg); - break; - - case ARG_TEXT_FILTER_CLOSURE: - text->filter_closure = GTK_VALUE_POINTER (*arg); - break; default: return; } @@ -1347,14 +1348,6 @@ ect_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_INT (*arg) = text->color_column; break; - case ARG_TEXT_FILTER_FUNC: - GTK_VALUE_POINTER (*arg) = text->filter_func; - break; - - case ARG_TEXT_FILTER_CLOSURE: - GTK_VALUE_POINTER (*arg) = text->filter_closure; - break; - default: arg->type = GTK_TYPE_INVALID; break; @@ -1365,6 +1358,7 @@ static void e_cell_text_class_init (GtkObjectClass *object_class) { ECellClass *ecc = (ECellClass *) object_class; + ECellTextClass *ectc = (ECellTextClass *) object_class; object_class->destroy = ect_destroy; @@ -1382,6 +1376,9 @@ e_cell_text_class_init (GtkObjectClass *object_class) ecc->max_width = ect_max_width; ecc->show_tooltip = ect_show_tooltip; + ectc->get_text = ect_real_get_text; + ectc->free_text = ect_real_free_text; + object_class->get_arg = ect_get_arg; object_class->set_arg = ect_set_arg; @@ -1393,10 +1390,6 @@ e_cell_text_class_init (GtkObjectClass *object_class) GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_BOLD_COLUMN); gtk_object_add_arg_type ("ECellText::color_column", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_COLOR_COLUMN); - gtk_object_add_arg_type ("ECellText::text_filter_func", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_TEXT_FILTER_FUNC); - gtk_object_add_arg_type ("ECellText::text_filter_closure", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_TEXT_FILTER_CLOSURE); if (!clipboard_atom) clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); @@ -1405,16 +1398,35 @@ e_cell_text_class_init (GtkObjectClass *object_class) static void e_cell_text_init (ECellText *ect) { + ect->ellipsis = NULL; + ect->use_ellipsis = TRUE; ect->strikeout_column = -1; ect->bold_column = -1; ect->color_column = -1; - ect->filter_func = NULL; - ect->filter_closure = NULL; } E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, e_cell_text_init, PARENT_TYPE); /** + * e_cell_text_construct: + * @cell: The cell to construct + * @fontname: font to be used to render on the screen + * @justify: Justification of the string in the cell + * + * constructs the ECellText. To be used by subclasses and language + * bindings. + * + * Returns: The ECellText. + */ +ECell * +e_cell_text_construct (ECellText *cell, const char *fontname, GtkJustification justify) +{ + cell->font_name = g_strdup (fontname); + cell->justify = justify; + return E_CELL(cell); +} + +/** * e_cell_text_new: * @fontname: font to be used to render on the screen * @justify: Justification of the string in the cell. @@ -1426,7 +1438,7 @@ E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, e_cell_ * The ECellText object support a large set of properties that can be * configured through the Gtk argument system and allows the user to have * a finer control of the way the string is displayed. The arguments supported - * allow the control of strikeout, bold, color and a text filter. + * allow the control of strikeout, bold, and color. * * The arguments "strikeout_column", "bold_column" and "color_column" set * and return an integer that points to a column in the model that controls @@ -1443,12 +1455,8 @@ e_cell_text_new (const char *fontname, GtkJustification justify) { ECellText *ect = gtk_type_new (e_cell_text_get_type ()); - ect->ellipsis = NULL; - ect->use_ellipsis = TRUE; + e_cell_text_construct(ect, fontname, justify); - ect->font_name = g_strdup (fontname); - ect->justify = justify; - return (ECell *) ect; } @@ -2342,6 +2350,7 @@ build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, { ECellView *ecell_view = (ECellView *) text_view; ECellText *ect = E_CELL_TEXT (ecell_view->ecell); + char *temp; cell->text_view = text_view; cell->model_col = model_col; @@ -2349,11 +2358,10 @@ build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, cell->row = row; cell->breaks = NULL; - if (ect->filter_func) { - cell->text = (*ect->filter_func)(NULL, e_table_model_value_at (ecell_view->e_table_model, model_col, row), ect->filter_closure); - } else { - cell->text = g_strdup (e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } + temp = ect_get_text(ect, ecell_view->e_table_model, model_col, row); + cell->text = g_strdup(temp); + ect_free_text(ect, temp); + cell->width = e_table_header_get_column ( ((ETableItem *)ecell_view->e_table_item_view)->header, view_col)->width - 8; diff --git a/widgets/table/e-cell-text.h b/widgets/table/e-cell-text.h index 9392e7afe3..706be9150d 100644 --- a/widgets/table/e-cell-text.h +++ b/widgets/table/e-cell-text.h @@ -27,9 +27,6 @@ #include <libgnomeui/gnome-canvas.h> #include <gal/e-table/e-cell.h> -/* Should return a malloced object. */ -typedef char *(*ECellTextFilter) (void *reserved, const void *data, gpointer closure); - #define E_CELL_TEXT_TYPE (e_cell_text_get_type ()) #define E_CELL_TEXT(o) (GTK_CHECK_CAST ((o), E_CELL_TEXT_TYPE, ECellText)) #define E_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TEXT_TYPE, ECellTextClass)) @@ -59,19 +56,20 @@ typedef struct { See the XParseColor man page for the formats available. */ int color_column; - ECellTextFilter filter_func; - gpointer filter_closure; - /* This stores the colors we have allocated. */ GHashTable *colors; } ECellText; typedef struct { ECellClass parent_class; + + char *(*get_text) (ECellText *cell, ETableModel *model, int col, int row); + void (*free_text) (ECellText *cell, char *text); } ECellTextClass; GtkType e_cell_text_get_type (void); ECell *e_cell_text_new (const char *fontname, GtkJustification justify); +ECell *e_cell_text_construct(ECellText *cell, const char *fontname, GtkJustification justify); #endif /* _E_CELL_TEXT_H_ */ diff --git a/widgets/table/e-table-extras.c b/widgets/table/e-table-extras.c index f458b9ef9d..5959a7989e 100644 --- a/widgets/table/e-table-extras.c +++ b/widgets/table/e-table-extras.c @@ -13,6 +13,8 @@ #include "gal/util/e-util.h" #include "gal/e-table/e-cell-text.h" #include "gal/e-table/e-cell-checkbox.h" +#include "gal/e-table/e-cell-date.h" +#include "gal/e-table/e-cell-size.h" #include "gal/e-table/e-cell-tree.h" #include "e-table-extras.h" @@ -79,6 +81,8 @@ ete_init (ETableExtras *extras) e_table_extras_add_compare(extras, "integer", g_int_compare); e_table_extras_add_cell(extras, "checkbox", e_cell_checkbox_new()); + e_table_extras_add_cell(extras, "date", e_cell_date_new (NULL, GTK_JUSTIFY_LEFT)); + e_table_extras_add_cell(extras, "size", e_cell_size_new (NULL, GTK_JUSTIFY_LEFT)); e_table_extras_add_cell(extras, "string", e_cell_text_new (NULL, GTK_JUSTIFY_LEFT)); e_table_extras_add_cell(extras, "tree-string", e_cell_tree_new (NULL, NULL, TRUE, e_cell_text_new (NULL, GTK_JUSTIFY_LEFT))); } |