diff options
Diffstat (limited to 'widgets/table')
118 files changed, 0 insertions, 32375 deletions
diff --git a/widgets/table/.cvsignore b/widgets/table/.cvsignore deleted file mode 100644 index b1004fee2c..0000000000 --- a/widgets/table/.cvsignore +++ /dev/null @@ -1,13 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -table-test -table-example-1 -table-example-2 -table-size-test -tree-example-1 -tree-example-2 diff --git a/widgets/table/add-col.xpm b/widgets/table/add-col.xpm deleted file mode 100644 index 9c5f314c8e..0000000000 --- a/widgets/table/add-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * add_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" .............. ", -" .++++++++++++. ", -" .++++++++++++. ", -" ....+++....... ", -" .+. ", -" . ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/table/arrow-down.xpm b/widgets/table/arrow-down.xpm deleted file mode 100644 index f1e6cb4b3c..0000000000 --- a/widgets/table/arrow-down.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * arrow_down_xpm[] = { -"13 16 2 1", -" c None", -". c #FF0000", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -".............", -" ........... ", -" ......... ", -" ....... ", -" ..... ", -" ... ", -" . "}; diff --git a/widgets/table/arrow-up.xpm b/widgets/table/arrow-up.xpm deleted file mode 100644 index 0cc5b9a00c..0000000000 --- a/widgets/table/arrow-up.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * arrow_up_xpm[] = { -"13 16 2 1", -" c None", -". c #FF0000", -" . ", -" ... ", -" ..... ", -" ....... ", -" ......... ", -" ........... ", -".............", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... "}; diff --git a/widgets/table/check-empty.xpm b/widgets/table/check-empty.xpm deleted file mode 100644 index 746b20234e..0000000000 --- a/widgets/table/check-empty.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * check_empty_xpm[] = { -"16 16 2 1", -" c None", -". c #000000", -" ", -" ", -" ............ ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" ............ ", -" ", -" "}; diff --git a/widgets/table/check-filled.xpm b/widgets/table/check-filled.xpm deleted file mode 100644 index c0468fc25b..0000000000 --- a/widgets/table/check-filled.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * check_filled_xpm[] = { -"16 16 2 1", -" c None", -". c #000000", -" ", -" ", -" ............ ", -" . . ", -" . . . ", -" . .. . ", -" . ... . ", -" . . ... . ", -" . .. ... . ", -" . ..... . ", -" . ... . ", -" . . . ", -" . . ", -" ............ ", -" ", -" "}; diff --git a/widgets/table/clip.png b/widgets/table/clip.png Binary files differdeleted file mode 100644 index 27aa5f072f..0000000000 --- a/widgets/table/clip.png +++ /dev/null diff --git a/widgets/table/e-cell-checkbox.c b/widgets/table/e-cell-checkbox.c deleted file mode 100644 index 2857388cb6..0000000000 --- a/widgets/table/e-cell-checkbox.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * e-cell-checkbox.c: Checkbox cell renderer - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999, 2000 Ximian, Inc - */ -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include "e-cell-checkbox.h" -#include "gal/util/e-util.h" -#include "e-table-item.h" - -#include "check-empty.xpm" -#include "check-filled.xpm" - -#define PARENT_TYPE e_cell_toggle_get_type () - -static GdkPixbuf *checks [2]; - -static void -e_cell_checkbox_class_init (GtkObjectClass *object_class) -{ - checks [0] = gdk_pixbuf_new_from_xpm_data (check_empty_xpm); - checks [1] = gdk_pixbuf_new_from_xpm_data (check_filled_xpm); -} - -E_MAKE_TYPE(e_cell_checkbox, "ECellCheckbox", ECellCheckbox, e_cell_checkbox_class_init, NULL, PARENT_TYPE); - -/** - * e_cell_checkbox_new: - * - * Creates a new ECell renderer that can be used to render check - * boxes. the data provided from the model is cast to an integer. - * zero is used for the off display, and non-zero for checked status. - * - * Returns: an ECell object that can be used to render checkboxes. - */ -ECell * -e_cell_checkbox_new (void) -{ - ECellCheckbox *eccb = gtk_type_new (e_cell_checkbox_get_type ()); - - e_cell_toggle_construct (E_CELL_TOGGLE (eccb), 2, 2, checks); - - return (ECell *) eccb; -} diff --git a/widgets/table/e-cell-checkbox.h b/widgets/table/e-cell-checkbox.h deleted file mode 100644 index 60c0341fe7..0000000000 --- a/widgets/table/e-cell-checkbox.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _E_CELL_CHECKBOX_H_ -#define _E_CELL_CHECKBOX_H_ - -#include <gal/e-table/e-cell-toggle.h> - -BEGIN_GNOME_DECLS - -#define E_CELL_CHECKBOX_TYPE (e_cell_checkbox_get_type ()) -#define E_CELL_CHECKBOX(o) (GTK_CHECK_CAST ((o), E_CELL_CHECKBOX_TYPE, ECellCheckbox)) -#define E_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_CHECKBOX_TYPE, ECellCheckboxClass)) -#define E_IS_CELL_CHECKBOX(o) (GTK_CHECK_TYPE ((o), E_CELL_CHECKBOX_TYPE)) -#define E_IS_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_CHECKBOX_TYPE)) - -typedef struct { - ECellToggle parent; -} ECellCheckbox; - -typedef struct { - ECellToggleClass parent_class; -} ECellCheckboxClass; - -GtkType e_cell_checkbox_get_type (void); -ECell *e_cell_checkbox_new (void); - -END_GNOME_DECLS - -#endif /* _E_CELL_CHECKBOX_H_ */ - diff --git a/widgets/table/e-cell-date.c b/widgets/table/e-cell-date.c deleted file mode 100644 index a70147f0ce..0000000000 --- a/widgets/table/e-cell-date.c +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- 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 "gal/util/e-i18n.h" -#include "e-cell-date.h" -#include <gnome.h> -#include <sys/time.h> -#include <unistd.h> -#include <gal/util/e-util.h> -#include <gal/widgets/e-unicode.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 e_utf8_from_locale_string (_("?")); - } - - 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 e_utf8_from_locale_string (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 deleted file mode 100644 index 25bde7a85a..0000000000 --- a/widgets/table/e-cell-date.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- 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> - -BEGIN_GNOME_DECLS - -#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); - -END_GNOME_DECLS - -#endif /* _E_CELL_DATE_H_ */ diff --git a/widgets/table/e-cell-number.c b/widgets/table/e-cell-number.c deleted file mode 100644 index ebac2c78ed..0000000000 --- a/widgets/table/e-cell-number.c +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellNumber - Number item for e-table. - * Copyright (C) 2001 Ximian, Inc. - * Author: Chris Lahey <clahey@ximian.com> - */ - -#include <config.h> -#include "gal/util/e-i18n.h" -#include "e-cell-number.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 * -ecn_get_text(ECellText *cell, ETableModel *model, int col, int row) -{ - return e_format_number(GPOINTER_TO_INT (e_table_model_value_at(model, col, row))); -} - -static void -ecn_free_text(ECellText *cell, char *text) -{ - g_free(text); -} - -static void -e_cell_number_class_init (GtkObjectClass *object_class) -{ - ECellTextClass *ectc = (ECellTextClass *) object_class; - - parent_class = gtk_type_class (PARENT_TYPE); - - ectc->get_text = ecn_get_text; - ectc->free_text = ecn_free_text; -} - -static void -e_cell_number_init (GtkObject *object) -{ -} - -/** - * e_cell_number_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 numbers that - * that come from the model. The value returned from the model is - * interpreted as being an int. - * - * See ECellText for other features. - * - * Returns: an ECell object that can be used to render numbers. - */ -ECell * -e_cell_number_new (const char *fontname, GtkJustification justify) -{ - ECellNumber *ecn = gtk_type_new (e_cell_number_get_type ()); - - e_cell_text_construct(E_CELL_TEXT(ecn), fontname, justify); - - return (ECell *) ecn; -} - -E_MAKE_TYPE(e_cell_number, "ECellNumber", ECellNumber, e_cell_number_class_init, e_cell_number_init, PARENT_TYPE); diff --git a/widgets/table/e-cell-number.h b/widgets/table/e-cell-number.h deleted file mode 100644 index b9124bb2b0..0000000000 --- a/widgets/table/e-cell-number.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellNumber - Number item for e-table. - * Copyright (C) 2001 Ximian, Inc. - * Author: Chris Lahey <clahey@ximian.com> - */ -#ifndef _E_CELL_NUMBER_H_ -#define _E_CELL_NUMBER_H_ - -#include <gal/e-table/e-cell-text.h> - -BEGIN_GNOME_DECLS - -#define E_CELL_NUMBER_TYPE (e_cell_number_get_type ()) -#define E_CELL_NUMBER(o) (GTK_CHECK_CAST ((o), E_CELL_NUMBER_TYPE, ECellNumber)) -#define E_CELL_NUMBER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_NUMBER_TYPE, ECellNumberClass)) -#define E_IS_CELL_NUMBER(o) (GTK_CHECK_TYPE ((o), E_CELL_NUMBER_TYPE)) -#define E_IS_CELL_NUMBER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_NUMBER_TYPE)) - -typedef struct { - ECellText base; -} ECellNumber; - -typedef struct { - ECellTextClass parent_class; -} ECellNumberClass; - -GtkType e_cell_number_get_type (void); -ECell *e_cell_number_new (const char *fontname, GtkJustification justify); - -END_GNOME_DECLS - -#endif /* _E_CELL_NUMBER_H_ */ diff --git a/widgets/table/e-cell-size.c b/widgets/table/e-cell-size.c deleted file mode 100644 index 7943ad8d8a..0000000000 --- a/widgets/table/e-cell-size.c +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- 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 deleted file mode 100644 index db976a4eb6..0000000000 --- a/widgets/table/e-cell-size.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- 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> - -BEGIN_GNOME_DECLS - -#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); - -END_GNOME_DECLS - -#endif /* _E_CELL_SIZE_H_ */ diff --git a/widgets/table/e-cell-string.c b/widgets/table/e-cell-string.c deleted file mode 100644 index 992b1bd10e..0000000000 --- a/widgets/table/e-cell-string.c +++ /dev/null @@ -1,9 +0,0 @@ -ECell * -e_cell_string_new (void) -{ - ECell *ecell; - - ecell = gtk_type_new (ecell); - - return ecell; -} diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c deleted file mode 100644 index 2db05f7320..0000000000 --- a/widgets/table/e-cell-text.c +++ /dev/null @@ -1,2418 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-cell-text.c - Text cell renderer - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Chris Lahey <clahey@ximian.com> - * - * (C) 1999, 2000 Ximian, Inc. - * - * A lot of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - * - * TODO: - * Clean up UTF-8 handling - * UTF-8 selection - */ - -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkinvisible.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include <stdio.h> -#include <unicode.h> -#include "e-cell-text.h" -#include "gal/util/e-util.h" -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-font.h" -#include "gal/widgets/e-unicode.h" -#include "e-table-item.h" -#include "gal/util/e-text-event-processor.h" -#include "gal/e-text/e-text.h" -#include "gal/util/e-text-event-processor-emacs-like.h" -#include "e-table-tooltip.h" - -#include <gdk/gdkx.h> /* for BlackPixel */ -#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 */ - int length; /* Line's length in BYTES */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis in BYTES */ -}; - -/* Object argument IDs */ -enum { - ARG_0, - - ARG_STRIKEOUT_COLUMN, - ARG_BOLD_COLUMN, - ARG_COLOR_COLUMN, -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; - -static GdkAtom clipboard_atom = GDK_NONE; - -#define PARENT_TYPE e_cell_get_type () - -#define TEXT_PAD 4 - -typedef struct { - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - int max_width; - int ref_count; -} ECellTextLineBreaks; - - -typedef struct _CellEdit CellEdit; - -typedef struct { - ECellView cell_view; - GdkGC *gc; -#if 0 - GdkFont *font; -#else - EFont *font; -#endif - GdkCursor *i_cursor; - GdkBitmap *stipple; /* Stipple for text */ - - GnomeCanvas *canvas; - - /* - * During editing. - */ - CellEdit *edit; - - - int xofs, yofs; /* This gets added to the x - and y for the cell text. */ - double ellipsis_width[2]; /* The width of the ellipsis. */ - -} ECellTextView; - -typedef struct _CurrentCell{ - ECellTextView *text_view; - int width; - char *text; - int model_col, view_col, row; - ECellTextLineBreaks *breaks; - EFontStyle style; -} CurrentCell; - -#define CURRENT_CELL(x) ((CurrentCell *)(x)) - -struct _CellEdit { - CurrentCell cell; - - char *old_text; - - /* - * Where the editing is taking place - */ - - int xofs_edit, yofs_edit; /* Offset because of editing. - This is negative compared - to the other offsets. */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection - IN BYTES */ - int selection_end; /* End of selection - IN BYTES */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - /* Cursor handling. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - - /* Hmmm... this should probably be in native encoding? */ - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length in BYTES */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length in BYTES */ - - guint pointer_in : 1; - guint default_cursor_shown : 1; - - ECellActions actions; -}; - -static void e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static void e_cell_text_view_get_selection (CellEdit *edit, GdkAtom selection, guint32 time); -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, char *data, gint length); - -static GtkWidget *e_cell_text_view_get_invisible (CellEdit *edit); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit); -static int number_of_lines (char *text); -static void split_into_lines (CurrentCell *cell); -static void unref_lines (CurrentCell *cell); -static void calc_line_widths (CurrentCell *cell); -static int get_line_ypos (CurrentCell *cell, struct line *line); -static int get_line_xpos (CurrentCell *cell, struct line *line); -static void _get_tep (CellEdit *edit); - -static gint _get_position_from_xy (CurrentCell *cell, gint x, gint y); -static void _get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp); -static gboolean _blink_scroll_timeout (gpointer data); - -static void build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row); -static void unbuild_current_cell (CurrentCell *cell); -static void calc_ellipsis (ECellTextView *text_view); -static void ect_free_color (gchar *color_spec, GdkColor *color, GdkColormap *colormap); -static GdkColor* e_cell_text_get_color (ECellTextView *cell_view, gchar *color_spec); - -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) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * Accept the currently edited text. if it's the same as what's in the cell, do nothing. - */ -static void -ect_accept_edits (ECellTextView *text_view) -{ - CurrentCell *cell = (CurrentCell *) text_view->edit; - - if (strcmp (text_view->edit->old_text, cell->text)) { - e_table_model_set_value_at (text_view->cell_view.e_table_model, - cell->model_col, cell->row, cell->text); - } -} - -/* - * Shuts down the editing process - */ -static void -ect_stop_editing (ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - int row, view_col; - - if (!edit) - return; - - row = edit->cell.row; - view_col = edit->cell.view_col; - - g_free (edit->old_text); - edit->old_text = NULL; - g_free (edit->cell.text); - edit->cell.text = NULL; - if (edit->invisible) - gtk_widget_unref (edit->invisible); - if (edit->tep) - gtk_object_unref (GTK_OBJECT(edit->tep)); - if (edit->primary_selection) - g_free (edit->primary_selection); - if (edit->clipboard_selection) - g_free (edit->clipboard_selection); - if (! edit->default_cursor_shown){ - gdk_window_set_cursor (GTK_WIDGET(text_view->canvas)->window, NULL); - edit->default_cursor_shown = TRUE; - } - if (edit->timeout_id) { - g_source_remove (edit->timeout_id); - edit->timeout_id = 0; - } - if (edit->timer) { - g_timer_stop (edit->timer); - g_timer_destroy (edit->timer); - edit->timer = NULL; - } - - g_free (edit); - - text_view->edit = NULL; - ect_queue_redraw (text_view, view_col, row); -} - -/* - * Cancels the edits - */ -static void -ect_cancel_edit (ECellTextView *text_view) -{ - ect_stop_editing (text_view); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellText *ect = E_CELL_TEXT (ecell); - ECellTextView *text_view = g_new0 (ECellTextView, 1); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (e_table_item_view)->canvas; - - text_view->cell_view.ecell = ecell; - text_view->cell_view.e_table_model = table_model; - text_view->cell_view.e_table_item_view = e_table_item_view; - - if (ect->font_name){ -#if 0 - GdkFont *f; - - f = gdk_fontset_load (ect->font_name); - text_view->font = f; -#endif - text_view->font = e_font_from_gdk_name (ect->font_name); - } - if (!text_view->font){ - gdk_font_ref (GTK_WIDGET (canvas)->style->font); - text_view->font = e_font_from_gdk_font (GTK_WIDGET (canvas)->style->font); - } - - text_view->canvas = canvas; - - text_view->xofs = 0.0; - text_view->yofs = 0.0; - - return (ECellView *)text_view; -} - -/* - * ECell::kill_view method - */ -static void -ect_kill_view (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - - g_free (text_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - - text_view->gc = gdk_gc_new (GTK_WIDGET (text_view->canvas)->window); - - text_view->i_cursor = gdk_cursor_new (GDK_XTERM); - - calc_ellipsis (text_view); - - if (parent_class->realize) - (* parent_class->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - ECellText *ect = (ECellText*) ecv->ecell; - GdkColormap *colormap; - - gdk_gc_unref (text_view->gc); - text_view->gc = NULL; - - if (text_view->edit){ - ect_cancel_edit (text_view); - } - - if (text_view->font) - e_font_unref (text_view->font); - - if (text_view->stipple) - gdk_bitmap_unref (text_view->stipple); - - gdk_cursor_destroy (text_view->i_cursor); - - if (ect->colors) { - colormap = gtk_widget_get_colormap (GTK_WIDGET (text_view->canvas)); - g_hash_table_foreach (ect->colors, (GHFunc) ect_free_color, - colormap); - g_hash_table_destroy (ect->colors); - ect->colors = NULL; - } - - if (parent_class->unrealize) - (* parent_class->unrealize) (ecv); -} - -static void -ect_free_color (gchar *color_spec, GdkColor *color, GdkColormap *colormap) -{ - - g_free (color_spec); - - /* This frees the color. Note we don't free it if it is the special - value. */ - if (color != (GdkColor*) 1) { - gdk_colors_free (colormap, &color->pixel, 1, 0); - - /* This frees the memory for the GdkColor. */ - gdk_color_free (color); - } -} - -static void -set_style(ECellView *ecell_view, CurrentCell *cell, int row) -{ - EFontStyle style = E_FONT_PLAIN; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - - if (ect->bold_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->bold_column, row)) - style = E_FONT_BOLD; - - cell->style = style; -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, ECellFlags flags, - int x1, int y1, int x2, int y2) -{ - /* New ECellText */ - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - ECellTextView *text_view = (ECellTextView *) ecell_view; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - EFont *font = text_view->font; - const int height = e_font_height (text_view->font); - CellEdit *edit = text_view->edit; - gboolean edit_display = FALSE; - ECellTextLineBreaks *linebreaks; - GdkColor *foreground, *cell_foreground, *cursor_color; - gchar *color_spec; - gboolean selected; - EFontStyle style = E_FONT_PLAIN; - - selected = flags & E_CELL_SELECTED; - - if (edit){ - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) { - edit_display = TRUE; - fg_gc = canvas->style->fg_gc[edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - } else - fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - } else { - fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - } - - /* - * Be a nice citizen: clip to the region we are supposed to draw on - */ - rect.x = x1; - rect.y = y1; - rect.width = x2 - x1; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (text_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (selected){ - if (flags & E_CELL_FOCUSED) - foreground = &canvas->style->text [GTK_STATE_SELECTED]; - else - foreground = &canvas->style->text [GTK_STATE_ACTIVE]; - } else { - foreground = &canvas->style->text [GTK_STATE_NORMAL]; - } - - cursor_color = foreground; - - if (ect->color_column != -1 && ! selected) { - color_spec = e_table_model_value_at (ecell_view->e_table_model, - ect->color_column, row); - cell_foreground = e_cell_text_get_color (text_view, - color_spec); - if (cell_foreground) - foreground = cell_foreground; - } - - gdk_gc_set_foreground (text_view->gc, foreground); - - x1 += 4; - y1 += 1; - x2 -= 4; - y2 -= 1; - - rect.x = x1; - rect.y = y1; - rect.width = x2 - x1; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (text_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (edit_display){ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - - set_style(ecell_view, cell, row); - - style = cell->style; - - cell->width = x2 - x1; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - ypos = get_line_ypos (cell, lines); - ypos += e_font_ascent (text_view->font); - ypos -= edit->yofs_edit; - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (cell, lines); - xpos -= edit->xofs_edit; - - /* start_char, end_char, sel_start and sel_end are IN BYTES */ - - start_char = lines->text - cell->text; - end_char = start_char + lines->length; - - sel_start = edit->selection_start; - sel_end = edit->selection_end; - - if (sel_start > sel_end){ - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if (sel_start < start_char) - sel_start = start_char; - if (sel_end > end_char) - sel_end = end_char; - - if (sel_start < sel_end){ - sel_rect.x = xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char); - sel_rect.y = ypos + y1 - e_font_ascent (font); - sel_rect.width = e_font_utf8_text_width (font, style, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = height; - gtk_paint_flat_box (canvas->style, - drawable, - edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - canvas, - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - - e_font_draw_utf8_text (drawable, font, style, text_view->gc, xpos + x1, ypos + y1, - lines->text, - sel_start - start_char); - e_font_draw_utf8_text (drawable, font, style, fg_gc, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char), - ypos + y1, - lines->text + sel_start - start_char, - sel_end - sel_start); - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_end - start_char), - ypos + y1, - lines->text + sel_end - start_char, - end_char - sel_end); - } else { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, ypos + y1, - lines->text, - lines->length); - } - if (edit->selection_start == edit->selection_end && - edit->selection_start >= start_char && - edit->selection_start <= end_char && - edit->show_cursor) { - gdk_gc_set_foreground (text_view->gc, cursor_color); - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char), - ypos + y1 - e_font_ascent (font), - 1, - height); - } - if (ect->strikeout_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->strikeout_column, row)) { - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - x1, ypos + y1 - (e_font_ascent (font) / 2), - x2 - x1, - 1); - } - ypos += height; - lines ++; - } - unref_lines (cell); - } else { - - ECellTextLineBreaks *linebreaks; - CurrentCell cell; - build_current_cell (&cell, text_view, model_col, view_col, row); - - set_style(ecell_view, &cell, row); - - style = cell.style; - - cell.width = x2 - x1; - - split_into_lines (&cell); - - linebreaks = cell.breaks; - lines = linebreaks->lines; - ypos = get_line_ypos (&cell, lines); - ypos += e_font_ascent (text_view->font); - - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (&cell, lines); - if (ect->use_ellipsis && lines->ellipsis_length < lines->length) { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, ypos + y1, - lines->text, - lines->ellipsis_length); - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1 + lines->width - text_view->ellipsis_width[style], - ypos + y1, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); - } else { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->length); - } - if (ect->strikeout_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->strikeout_column, row)) { - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - x1, ypos + y1 - (e_font_ascent (font) / 2), - x2 - x1, - 1); - } - ypos += height; - lines++; - } - unref_lines (&cell); - unbuild_current_cell (&cell); - } - - gdk_gc_set_clip_rectangle (text_view->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); -} - -/* - * Selects the entire string - */ -static void -ect_edit_select_all (ECellTextView *text_view) -{ - g_assert (text_view->edit); - - text_view->edit->selection_start = 0; - text_view->edit->selection_end = strlen (text_view->edit->cell.text); -} - -static gboolean -key_begins_editing (GdkEventKey *event) -{ - if (event->length == 0) - return FALSE; - - return TRUE; -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - ETextEventProcessorEvent e_tep_event; - gboolean edit_display = FALSE; - CellEdit *edit = text_view->edit; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - gint return_val = 0; - CurrentCell cell, *cellptr; - - if (flags & !E_CELL_EDITING) - return 0; - - build_current_cell (&cell, text_view, model_col, view_col, row); - - - if (edit){ - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) { - edit_display = TRUE; - cellptr = CURRENT_CELL(edit); - } else { - cellptr = &cell; - } - } else { - cellptr = &cell; - } - - set_style(ecell_view, cellptr, row); - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (event->key.keyval == GDK_Escape){ - ect_cancel_edit (text_view); - return_val = TRUE; - break; - } - - if ((!edit_display) && - e_table_model_is_cell_editable (ecell_view->e_table_model, model_col, row) && - key_begins_editing (&event->key)) { - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - ect_edit_select_all (text_view); - edit = text_view->edit; - cellptr = CURRENT_CELL(edit); - edit_display = TRUE; - } - if (edit_display) { - GdkEventKey key = event->key; - if (key.keyval == GDK_KP_Enter || key.keyval == GDK_Return){ - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); - } else { - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - - /* This is probably ugly hack, but we have to handle UTF-8 input somehow */ -#if 0 - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; -#else - e_tep_event.key.string = e_utf8_from_gtk_event_key (canvas, key.keyval, key.string); - if (e_tep_event.key.string != NULL) { - e_tep_event.key.length = strlen (e_tep_event.key.string); - } else { - e_tep_event.key.length = 0; - } -#endif - - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, &e_tep_event); - *actions = edit->actions; - if (e_tep_event.key.string) g_free (e_tep_event.key.string); - break; - } - } - - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - event->button.x -= 4; - event->button.y -= 1; - if ((!edit_display) - && e_table_model_is_cell_editable (ecell_view->e_table_model, model_col, row) - && event->type == GDK_BUTTON_RELEASE - && event->button.button == 1) { - GdkEventButton button = event->button; - - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - edit = text_view->edit; - cellptr = CURRENT_CELL(edit); - edit_display = TRUE; - - e_tep_event.button.type = GDK_BUTTON_PRESS; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy (cellptr, button.x, button.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - *actions = edit->actions; - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - edit->button_down = TRUE; - else - edit->button_down = FALSE; - } - edit->lastx = button.x; - edit->lasty = button.y; - edit->last_state = button.state; - - e_tep_event.button.type = GDK_BUTTON_RELEASE; - } - if (edit_display) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy (cellptr, button.x, button.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - *actions = edit->actions; - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - edit->button_down = TRUE; - else - edit->button_down = FALSE; - } - edit->lastx = button.x; - edit->lasty = button.y; - edit->last_state = button.state; - } - break; - case GDK_MOTION_NOTIFY: - event->motion.x -= 4; - event->motion.y -= 1; - if (edit_display) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy (cellptr, motion.x, motion.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - *actions = edit->actions; - edit->lastx = motion.x; - edit->lasty = motion.y; - edit->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: -#if 0 - edit->pointer_in = TRUE; -#endif - if (edit_display) { - if (edit->default_cursor_shown){ - gdk_window_set_cursor (canvas->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: -#if 0 - text_view->pointer_in = FALSE; -#endif - if (edit_display) { - if (! edit->default_cursor_shown){ - gdk_window_set_cursor (canvas->window, NULL); - edit->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - - unbuild_current_cell (&cell); - if (return_val) - return return_val; -#if 0 - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event (item, event); -#endif - else - return 0; - -} - -/* - * ECell::height method - */ -static int -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; - - 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); - - return value; -} - -/* - * ECellView::enter_edit method - */ -static void * -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; - - build_current_cell (CURRENT_CELL(edit), text_view, model_col, view_col, row); - - set_style(ecell_view, CURRENT_CELL(edit), row); - - edit->xofs_edit = 0.0; - edit->yofs_edit = 0.0; - - edit->selection_start = 0; - edit->selection_end = 0; - edit->select_by_word = FALSE; - - edit->timeout_id = g_timeout_add (10, _blink_scroll_timeout, text_view); - edit->timer = g_timer_new (); - g_timer_elapsed (edit->timer, &(edit->scroll_start)); - g_timer_start (edit->timer); - - edit->lastx = 0; - edit->lasty = 0; - edit->last_state = 0; - - edit->scroll_start = 0; - edit->show_cursor = TRUE; - edit->button_down = FALSE; - - edit->tep = NULL; - - edit->has_selection = FALSE; - - edit->invisible = NULL; - edit->primary_selection = NULL; - edit->primary_length = 0; - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - - edit->pointer_in = FALSE; - edit->default_cursor_shown = TRUE; - - 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 - if (edit->pointer_in){ - if (edit->default_cursor_shown){ - gdk_window_set_cursor (GTK_WIDGET(item->canvas)->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } -#endif - - ect_queue_redraw (text_view, view_col, row); - - return NULL; -} - -/* - * ECellView::leave_edit method - */ -static void -ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit = text_view->edit; - - if (edit){ - ect_accept_edits (text_view); - ect_stop_editing (text_view); - /* FIXME: edit is freed in ect_stop_editing() so I've - commented this out - Damon. */ - /*unbuild_current_cell (CURRENT_CELL(edit));*/ - } else { - /* - * We did invoke this leave edit internally - */ - } -} - -static void -ect_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height) -{ - GnomeFont *font = gnome_font_new ("Helvetica", 12); - char *string; - ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - 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 */; - if (gnome_print_lineto(context, width - 2, 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 2, height - 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 2, height - 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 2, 2) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - gnome_print_moveto(context, 2, (height - gnome_font_get_ascender(font) + gnome_font_get_descender(font)) / 2); - gnome_print_setfont(context, font); - gnome_print_show(context, string); - gnome_print_grestore(context); - ect_free_text(ect, string); -} - -static gdouble -ect_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width) -{ - return 16; -} - -static int -ect_max_width (ECellView *ecell_view, - int model_col, - int view_col) -{ - /* New ECellText */ - ECellTextView *text_view = (ECellTextView *) ecell_view; - EFont *font; - int row; - int number_of_rows; - int max_width = 0; - - font = text_view->font; - number_of_rows = e_table_model_row_count (ecell_view->e_table_model); - - for (row = 0; row < number_of_rows; row++) { - CurrentCell cell; - struct line *line; - int width; - - build_current_cell (&cell, text_view, model_col, view_col, row); - split_into_lines (&cell); - calc_line_widths (&cell); - - line = (struct line *)cell.breaks->lines; - width = e_font_utf8_text_width (font, cell.style, - line->text, line->length); - max_width = MAX (max_width, width); - unref_lines (&cell); - unbuild_current_cell (&cell); - } - - return max_width; -} - -static gint -tooltip_event (GtkWidget *window, - GdkEvent *event, - ETableTooltip *tooltip) -{ - gint ret_val = FALSE; - - switch (event->type) { - case GDK_LEAVE_NOTIFY: - if (tooltip->window) { - gtk_widget_destroy (tooltip->window); - tooltip->window = NULL; - } - break; - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - if (event->type == GDK_BUTTON_RELEASE) { - if (tooltip->window) { - gtk_widget_destroy (tooltip->window); - tooltip->window = NULL; - } - } - - event->button.x = tooltip->cx; - event->button.y = tooltip->cy; - gtk_signal_emit_by_name (GTK_OBJECT (tooltip->eti), "event", - event, &ret_val); - break; - case GDK_KEY_PRESS: - if (tooltip->window){ - gtk_widget_destroy (tooltip->window); - tooltip->window = NULL; - } - gtk_signal_emit_by_name (GTK_OBJECT (tooltip->eti), "event", - event, &ret_val); - break; - default: - break; - } - - return ret_val; -} - -static void -ect_show_tooltip (ECellView *ecell_view, - int model_col, - int view_col, - int row, - int col_width, - ETableTooltip *tooltip) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CurrentCell cell; - struct line *lines; - GtkWidget *canvas; - int i; - gdouble max_width; - gboolean cut_off; - double i2c[6]; - ArtPoint origin = {0, 0}; - ArtPoint pixel_origin; - int canvas_x, canvas_y; - GnomeCanvasItem *tooltip_text; - double tooltip_width; - double tooltip_height; - double tooltip_x; - double tooltip_y; - GnomeCanvasItem *rect; - double text_height; - - tooltip->timer = 0; - - build_current_cell (&cell, text_view, model_col, view_col, row); - - set_style(ecell_view, &cell, row); - - cell.width = col_width - 8; - split_into_lines (&cell); - calc_line_widths (&cell); - - cut_off = FALSE; - for (lines = cell.breaks->lines, i = 0; i < cell.breaks->num_lines; - lines++, i++) { - if (lines->length > lines->ellipsis_length) { - cut_off = TRUE; - break; - } - } - - if (!cut_off) { - tooltip->timer = 0; - unref_lines (&cell); - unbuild_current_cell (&cell); - return; - } - - gnome_canvas_item_i2c_affine (GNOME_CANVAS_ITEM (tooltip->eti), i2c); - art_affine_point (&pixel_origin, &origin, i2c); - - gdk_window_get_origin (GTK_WIDGET (text_view->canvas)->window, - &canvas_x, &canvas_y); - pixel_origin.x += canvas_x; - pixel_origin.y += canvas_y; - pixel_origin.x -= (int) gtk_layout_get_hadjustment (GTK_LAYOUT (text_view->canvas))->value; - pixel_origin.y -= (int) gtk_layout_get_vadjustment (GTK_LAYOUT (text_view->canvas))->value; - - tooltip->window = gtk_window_new (GTK_WINDOW_POPUP); - gtk_container_set_border_width (GTK_CONTAINER (tooltip->window), 1); - - canvas = e_canvas_new (); - gtk_container_add (GTK_CONTAINER (tooltip->window), canvas); - - max_width = 0.0; - for (lines = cell.breaks->lines, i = 0; i < cell.breaks->num_lines; - lines++, i++) { - gdouble line_width; - - line_width = e_font_utf8_text_width (text_view->font, - cell.style, lines->text, - lines->length); - max_width = MAX (max_width, line_width); - } - - text_height = e_font_height (text_view->font) * cell.breaks->num_lines + 4; - rect = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_rect_get_type (), - "x1", (double) 0.0, - "y1", (double) 0.0, - "x2", (double) max_width + 4, - "y2", (double) text_height, - "fill_color", "light gray", - NULL); - - tooltip_text = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, -/* "font_gdk", text_view->font, */ - "text", cell.text, - "editable", FALSE, - "clip_width", max_width, - "clip_height", (double) text_height, - "clip", TRUE, - "line_wrap", FALSE, - "justification", E_CELL_TEXT (text_view->cell_view.ecell)->justify, - "draw_background", FALSE, - NULL); - - tooltip_width = max_width; - tooltip_height = text_height; - tooltip_y = tooltip->y; - - switch (E_CELL_TEXT (text_view->cell_view.ecell)->justify) { - case GTK_JUSTIFY_CENTER: - tooltip_x = - tooltip_width / 2; - break; - case GTK_JUSTIFY_RIGHT: - tooltip_x = tooltip_width / 2; - break; - case GTK_JUSTIFY_FILL: - case GTK_JUSTIFY_LEFT: - tooltip_x = tooltip->x; - break; - } - - gnome_canvas_item_move (tooltip_text, 3.0, 1.0); - gnome_canvas_item_set (rect, - "x2", (double) tooltip_width + 6, - "y2", (double) tooltip->row_height + 1, - NULL); - gtk_widget_set_usize (tooltip->window, tooltip_width + 6, - tooltip->row_height + 1); - gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0.0, 0.0, - (double) tooltip_width + 6, - (double) tooltip_height); - gtk_widget_show (canvas); - gtk_widget_realize (tooltip->window); - gtk_signal_connect (GTK_OBJECT (tooltip->window), "event", - GTK_SIGNAL_FUNC (tooltip_event), tooltip); - - gtk_widget_popup (tooltip->window, pixel_origin.x + tooltip->x, - pixel_origin.y + tooltip->y + 1); - - unref_lines (&cell); - unbuild_current_cell (&cell); - - return; -} - -/* - * GtkObject::destroy method - */ -static void -ect_destroy (GtkObject *object) -{ - ECellText *ect = E_CELL_TEXT (object); - - g_free (ect->font_name); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} -/* Set_arg handler for the text item */ -static void -ect_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECellText *text; - - text = E_CELL_TEXT (object); - - switch (arg_id) { - case ARG_STRIKEOUT_COLUMN: - text->strikeout_column = GTK_VALUE_INT (*arg); - break; - - case ARG_BOLD_COLUMN: - text->bold_column = GTK_VALUE_INT (*arg); - break; - - case ARG_COLOR_COLUMN: - text->color_column = GTK_VALUE_INT (*arg); - break; - - default: - return; - } -} - -/* Get_arg handler for the text item */ -static void -ect_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECellText *text; - - text = E_CELL_TEXT (object); - - switch (arg_id) { - case ARG_STRIKEOUT_COLUMN: - GTK_VALUE_INT (*arg) = text->strikeout_column; - break; - - case ARG_BOLD_COLUMN: - GTK_VALUE_INT (*arg) = text->bold_column; - break; - - case ARG_COLOR_COLUMN: - GTK_VALUE_INT (*arg) = text->color_column; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -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; - - ecc->new_view = ect_new_view; - ecc->kill_view = ect_kill_view; - ecc->realize = ect_realize; - ecc->unrealize = ect_unrealize; - ecc->draw = ect_draw; - ecc->event = ect_event; - 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; - 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; - - parent_class = gtk_type_class (PARENT_TYPE); - - gtk_object_add_arg_type ("ECellText::strikeout_column", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_STRIKEOUT_COLUMN); - gtk_object_add_arg_type ("ECellText::bold_column", - 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); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); -} - -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; -} - -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. - * - * Creates a new ECell renderer that can be used to render strings that - * that come from the model. The value returned from the model is - * interpreted as being a char *. - * - * 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, 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 - * 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 text 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 strings. - */ -ECell * -e_cell_text_new (const char *fontname, GtkJustification justify) -{ - ECellText *ect = gtk_type_new (e_cell_text_get_type ()); - - e_cell_text_construct(ect, fontname, justify); - - return (ECell *) ect; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (CurrentCell *cell, struct line *line) -{ - int x; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - - x = text_view->xofs + ect->x; - - switch (ect->justify) { - case GTK_JUSTIFY_RIGHT: - x += cell->width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (cell->width - line->width) / 2; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_ypos (CurrentCell *cell, struct line *line) -{ - int y; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - ECellTextLineBreaks *linebreaks = cell->breaks; - - struct line *lines = linebreaks->lines; - - EFont *font; - - font = text_view->font; - - y = text_view->yofs + ect->y; - y += (line - lines) * e_font_height (font); - - return y; -} - -/* fixme: Handle Font attributes */ -/* position is in BYTES */ - -static void -_get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp) -{ - if (xp || yp) { - struct line *lines; - int x, y; - int j; - ECellTextView *text_view = cell->text_view; - ECellTextLineBreaks *linebreaks; - EFont *font; - - font = text_view->font; - - split_into_lines (cell); - - linebreaks = cell->breaks; - lines = linebreaks->lines; - - x = get_line_xpos (cell, lines); - y = get_line_ypos (cell, lines); - for (j = 0, lines = linebreaks->lines; j < linebreaks->num_lines; lines++, j++) { - if (lines->text > cell->text + position) - break; - y += e_font_height (font); - } - lines --; - y -= e_font_descent (font); - - x += e_font_utf8_text_width (font, cell->style, - lines->text, - position - (lines->text - cell->text)); - if ((CellEdit *) cell == cell->text_view->edit){ - x -= ((CellEdit *)cell)->xofs_edit; - y -= ((CellEdit *)cell)->yofs_edit; - } - if (xp) - *xp = x; - if (yp) - *yp = y; - unref_lines (cell); - } -} - -static gint -_get_position_from_xy (CurrentCell *cell, gint x, gint y) -{ - int i, j; - int xpos, ypos; - struct line *lines; - int return_val; - gchar *p; - - ECellTextView *text_view = cell->text_view; - ECellTextLineBreaks *linebreaks; - EFont *font; - - font = text_view->font; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - - if ((CellEdit *) cell == cell->text_view->edit){ - x += ((CellEdit *)cell)->xofs_edit; - y += ((CellEdit *)cell)->yofs_edit; - } - - ypos = get_line_ypos (cell, linebreaks->lines); - j = 0; - while (y > ypos) { - ypos += e_font_height (font); - j ++; - } - j--; - if (j >= linebreaks->num_lines) - j = linebreaks->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - - lines += j; - xpos = get_line_xpos (cell, lines); - - for (p = lines->text; p < lines->text + lines->length; p = unicode_next_utf8 (p)) { - gint charwidth; - - charwidth = e_font_utf8_char_width (font, cell->style, p); - - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - - return_val = p - cell->text; - - unref_lines (cell); - - return return_val; -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - ECellTextView *text_view = (ECellTextView *) data; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed (edit->timer, ¤t_time); - - if (edit->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > edit->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < edit->scroll_start) - scroll = TRUE; - } else { - if (current_time > edit->scroll_start + SCROLL_WAIT_TIME || - current_time < edit->scroll_start) - scroll = TRUE; - } - if (scroll && edit->button_down) { - /* FIXME: Copy this for y. */ - if (edit->lastx - ect->x > cell->width) { - ECellTextLineBreaks *linebreaks; - split_into_lines (cell); - linebreaks = cell->breaks; - if (edit->xofs_edit < linebreaks->max_width - cell->width) { - edit->xofs_edit += 4; - if (edit->xofs_edit > linebreaks->max_width - cell->width + 1) - edit->xofs_edit = linebreaks->max_width - cell->width + 1; - redraw = TRUE; - } - unref_lines (cell); - } - if (edit->lastx - ect->x < 0 && - edit->xofs_edit > 0) { - edit->xofs_edit -= 4; - if (edit->xofs_edit < 0) - edit->xofs_edit = 0; - redraw = TRUE; - } - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = edit->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy (cell, edit->lastx, edit->lasty); - _get_tep (edit); - e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!edit->show_cursor) - redraw = TRUE; - edit->show_cursor = TRUE; - } else { - if (edit->show_cursor) - redraw = TRUE; - edit->show_cursor = FALSE; - } - if (redraw){ - ect_queue_redraw (text_view, edit->cell.view_col, edit->cell.row); - } - return TRUE; -} - -static int -_get_position (ECellTextView *text_view, ETextEventProcessorCommand *command) -{ - int length; - int x, y; - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - EFont *font; - gchar *p; - int unival; - - font = text_view->font; - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return edit->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - - /* fixme: this probably confuses TEP */ - - case E_TEP_END_OF_BUFFER: - return strlen (cell->text); - - case E_TEP_START_OF_LINE: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == cell->text) return 0; - - p = unicode_previous_utf8 (cell->text, p); - - while (p && p > cell->text) { - if (*p == '\n') return p - cell->text + 1; - p = unicode_previous_utf8 (cell->text, p); - } - - return 0; - - case E_TEP_END_OF_LINE: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - while (*p) { - if (*p == '\n') return p - cell->text; - p = unicode_next_utf8 (p); - } - - return p - cell->text; - - case E_TEP_FORWARD_CHARACTER: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - return p - cell->text; - - case E_TEP_BACKWARD_CHARACTER: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == NULL) return 0; - - return p - cell->text; - - case E_TEP_FORWARD_WORD: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - while (*p) { - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) return p - cell->text; - p = unicode_next_utf8 (p); - } - - return p - cell->text; - - case E_TEP_BACKWARD_WORD: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == cell->text) return 0; - - p = unicode_previous_utf8 (cell->text, p); - - while (p && p > cell->text) { - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - return (unicode_next_utf8 (p) - cell->text); - } - p = unicode_previous_utf8 (cell->text, p); - } - - return 0; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position (cell, edit->selection_end, &x, &y); - y += e_font_height (font); - return _get_position_from_xy (cell, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position (cell, edit->selection_end, &x, &y); - y -= e_font_height (font); - return _get_position_from_xy (cell, x, y); - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return edit->selection_end; - default: - return edit->selection_end; - } - g_assert_not_reached (); - return 0; /* Kill warning */ -} - -static void -_delete_selection (ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - gint length; - gchar *sp, *ep; - - if (edit->selection_end == edit->selection_start) return; - - if (edit->selection_end < edit->selection_start) { - edit->selection_end ^= edit->selection_start; - edit->selection_start ^= edit->selection_end; - edit->selection_end ^= edit->selection_start; - } - - sp = cell->text + edit->selection_start; - ep = cell->text + edit->selection_end; - length = strlen (ep) + 1; - - memmove (sp, ep, length); - - edit->selection_end = edit->selection_start; -} - -/* fixme: */ -/* NB! We expect value to be length IN BYTES */ - -static void -_insert (ECellTextView *text_view, char *string, int value) -{ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - char *temp; - - if (value <= 0) return; - - temp = g_new (gchar, strlen (cell->text) + value + 1); - - strncpy (temp, cell->text, edit->selection_start); - strncpy (temp + edit->selection_start, string, value); - strcpy (temp + edit->selection_start + value, cell->text + edit->selection_end); - - g_free (cell->text); - - cell->text = temp; - - edit->selection_start += value; - edit->selection_end = edit->selection_start; -} - -static void -e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - CellEdit *edit = (CellEdit *) data; - CurrentCell *cell = CURRENT_CELL(edit); - ECellTextView *text_view = cell->text_view; - - gboolean change = FALSE; - gboolean redraw = FALSE; - - int sel_start, sel_end; - EFont *font; - - font = text_view->font; - - switch (command->action) { - case E_TEP_MOVE: - edit->selection_start = _get_position (text_view, command); - edit->selection_end = edit->selection_start; - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - break; - case E_TEP_SELECT: - edit->selection_end = _get_position (text_view, command); - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, GDK_SELECTION_PRIMARY, - cell->text + sel_start, - sel_end - sel_start); - } else if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - break; - case E_TEP_DELETE: - if (edit->selection_end == edit->selection_start) { - edit->selection_end = _get_position (text_view, command); - } - _delete_selection (text_view); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - - case E_TEP_INSERT: - if (edit->selection_end != edit->selection_start) { - _delete_selection (text_view); - } - _insert (text_view, command->string, command->value); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_COPY: - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, clipboard_atom, - cell->text + sel_start, - sel_end - sel_start); - } - if (edit->timer) { - g_timer_reset (edit->timer); - } - break; - case E_TEP_PASTE: - e_cell_text_view_get_selection (edit, clipboard_atom, command->time); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_GET_SELECTION: - e_cell_text_view_get_selection (edit, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); - break; - case E_TEP_SET_SELECT_BY_WORD: - edit->select_by_word = command->value; - break; - case E_TEP_GRAB: - edit->actions = E_CELL_GRAB; - break; - case E_TEP_UNGRAB: - edit->actions = E_CELL_UNGRAB; - break; - case E_TEP_NOP: - break; - } - - if (!edit->button_down) { - int x; - int i; - struct line *lines; - ECellTextLineBreaks *linebreaks; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - for (lines = linebreaks->lines, i = 0; i < linebreaks->num_lines ; i++, lines ++) { - if ((lines->text - cell->text) > edit->selection_end) { - break; - } - } - lines --; - x = e_font_utf8_text_width (font, cell->style, - lines->text, - edit->selection_end - (lines->text - cell->text)); - - - if (x < edit->xofs_edit) { - edit->xofs_edit = x; - redraw = TRUE; - } - - if (2 + x - cell->width > edit->xofs_edit) { - edit->xofs_edit = 2 + x - cell->width; - redraw = TRUE; - } - unref_lines (cell); - } - - if (redraw){ - ect_queue_redraw (text_view, edit->cell.view_col, edit->cell.row); - } -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif -} - -static void _invisible_destroy (GtkInvisible *invisible, - CellEdit *edit) -{ - edit->invisible = NULL; -} - -static GtkWidget *e_cell_text_view_get_invisible (CellEdit *edit) -{ - GtkWidget *invisible; - if (edit->invisible) { - invisible = edit->invisible; - } else { - invisible = gtk_invisible_new (); - edit->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - edit); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - edit); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (edit->primary_selection); - edit->primary_selection = NULL; - edit->primary_length = 0; - - edit->has_selection = FALSE; -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif - - } else if (event->selection == clipboard_atom) { - g_free (edit->clipboard_selection); - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->primary_selection, edit->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->clipboard_selection, edit->clipboard_length); - break; - } -} - -/* fixme: What happens, if delivered string is not UTF-8? */ - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_cell_text_view_command (edit->tep, &command, edit); - } -} - -static void -e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, char *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_cell_text_view_get_invisible (edit); - - if (selection == GDK_SELECTION_PRIMARY){ - if (edit->primary_selection) { - g_free (edit->primary_selection); - } - edit->primary_selection = g_strndup (data, length); - edit->primary_length = length; - } else if (selection == clipboard_atom) { - if (edit->clipboard_selection) { - g_free (edit->clipboard_selection); - } - edit->clipboard_selection = g_strndup (data, length); - edit->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - edit->has_selection = successful; -} - -static void -e_cell_text_view_get_selection (CellEdit *edit, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_cell_text_view_get_invisible (edit); - gtk_selection_convert (invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -static void -_get_tep (CellEdit *edit) -{ - if (!edit->tep) { - edit->tep = e_text_event_processor_emacs_like_new (); - gtk_object_ref (GTK_OBJECT (edit->tep)); - gtk_object_sink (GTK_OBJECT (edit->tep)); - gtk_signal_connect (GTK_OBJECT(edit->tep), - "command", - GTK_SIGNAL_FUNC(e_cell_text_view_command), - (gpointer) edit); - } -} - -static int -number_of_lines (char *text) -{ - int num_lines = 0; - gchar *p; - - if (!text) return 0; - - for (p = text; *p; p = unicode_next_utf8 (p)) { - if (*p == '\n') num_lines++; - } - - num_lines++; - return num_lines; -} - -/* Splits the text of the text item into lines */ -static void -split_into_lines (CurrentCell *cell) -{ - char *p; - struct line *lines; - gint len; - - char *text = cell->text; - ECellTextLineBreaks *linebreaks; - - if (! cell->breaks) { - cell->breaks = g_new (ECellTextLineBreaks, 1); - cell->breaks->ref_count = 1; - } else { - cell->breaks->ref_count ++; - return; - } - linebreaks = cell->breaks; - - /* Check if already split. */ - linebreaks->lines = NULL; - linebreaks->num_lines = 0; - - if (!text) - return; - - /* First, count the number of lines */ - - linebreaks->num_lines = number_of_lines(cell->text); - - /* Allocate array of lines and calculate split positions */ - - linebreaks->lines = lines = g_new0 (struct line, linebreaks->num_lines); - - len = 0; - for (p = text; *p; p = unicode_next_utf8 (p)) { - if (len == 0) lines->text = p; - if (*p == '\n') { - lines->length = p - lines->text; - lines++; - len = 0; - } else - len++; - } - - if (len == 0) - lines->text = p; - lines->length = p - lines->text; - - calc_line_widths (cell); -} - -/* Free lines structure. */ -static void -unref_lines (CurrentCell *cell) -{ - if (cell->breaks){ - cell->breaks->ref_count --; - if (cell->breaks->ref_count <= 0){ - g_free (cell->breaks->lines); - g_free (cell->breaks); - cell->breaks = NULL; - } - } -} - -static void -calc_ellipsis (ECellTextView *text_view) -{ - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - EFont *font; - - font = text_view->font; - if (font) { - text_view->ellipsis_width[E_FONT_PLAIN] = - e_font_utf8_text_width (font, E_FONT_PLAIN, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); - text_view->ellipsis_width[E_FONT_BOLD] = - e_font_utf8_text_width (font, E_FONT_BOLD, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); - } -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (CurrentCell *cell) -{ - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - ECellTextLineBreaks *linebreaks = cell->breaks; - struct line *lines; - int i; - int j; - EFont *font; - - font = text_view->font; - - lines = linebreaks->lines; - linebreaks->max_width = 0; - - if (!lines) return; - - for (i = 0; i < linebreaks->num_lines; i++) { - if (lines->length != 0) { - if (font) { - lines->width = e_font_utf8_text_width (font, cell->style, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (ect->use_ellipsis && - (!(text_view->edit && - cell->row == text_view->edit->cell.row && - cell->view_col == text_view->edit->cell.view_col)) && - lines->width > cell->width) { - if (font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++){ - if (e_font_utf8_text_width (font, cell->style, lines->text, j) + - text_view->ellipsis_width[cell->style] < cell->width) { - lines->ellipsis_length = j; - } - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = e_font_utf8_text_width (font, cell->style, lines->text, lines->ellipsis_length) + - text_view->ellipsis_width[cell->style]; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > linebreaks->max_width) - linebreaks->max_width = lines->width; - } else { - lines->width = 0; - lines->ellipsis_length = 0; - } - - lines++; - } -} - -static void -build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row) -{ - 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; - cell->view_col = view_col; - cell->row = row; - cell->breaks = NULL; - - 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; - cell->style = 0; -} - -static void -unbuild_current_cell (CurrentCell *cell) -{ - g_free(cell->text); - cell->text = NULL; -} - - -static GdkColor* -e_cell_text_get_color (ECellTextView *cell_view, gchar *color_spec) -{ - ECellText *ect = E_CELL_TEXT (((ECellView*) cell_view)->ecell); - GdkColormap *colormap; - GdkColor *color, tmp_color; - - /* If the color spec is NULL we use the default color. */ - if (color_spec == NULL) - return NULL; - - /* Create the hash table if we haven't already. */ - if (!ect->colors) - ect->colors = g_hash_table_new (g_str_hash, g_str_equal); - - /* See if we've already allocated the color. Note that we use a - special value of (GdkColor*) 1 in the hash to indicate that we've - already tried and failed to allocate the color, so we don't keep - trying to allocate it. */ - color = g_hash_table_lookup (ect->colors, color_spec); - if (color == (GdkColor*) 1) - return NULL; - if (color) - return color; - - /* Try to parse the color. */ - if (gdk_color_parse (color_spec, &tmp_color)) { - colormap = gtk_widget_get_colormap (GTK_WIDGET (cell_view->canvas)); - - /* Try to allocate the color. */ - if (gdk_color_alloc (colormap, &tmp_color)) - color = gdk_color_copy (&tmp_color); - } - - g_hash_table_insert (ect->colors, g_strdup (color_spec), - color ? color : (GdkColor*) 1); - return color; -} - diff --git a/widgets/table/e-cell-text.h b/widgets/table/e-cell-text.h deleted file mode 100644 index 78e9576a07..0000000000 --- a/widgets/table/e-cell-text.h +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellText - Text item for e-table. - * Copyright (C) 2000 Ximian, Inc. - * Author: Chris Lahey <clahey@ximian.com> - * - * Drawing and event handling from: - * - * EText - Text item for evolution. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Chris Lahey <clahey@ximian.com> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ -#ifndef _E_CELL_TEXT_H_ -#define _E_CELL_TEXT_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gal/e-table/e-cell.h> - -BEGIN_GNOME_DECLS - -#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)) -#define E_IS_CELL_TEXT(o) (GTK_CHECK_TYPE ((o), E_CELL_TEXT_TYPE)) -#define E_IS_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TEXT_TYPE)) - -typedef struct { - ECell parent; - - GtkJustification justify; - char *font_name; - - double x, y; /* Position at anchor */ - - gulong pixel; /* Fill color */ - - /* Clip handling */ - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - - guint use_ellipsis : 1; /* Whether to use the ellipsis. */ - - int strikeout_column; - int bold_column; - - /* This column in the ETable should return a string specifying a color, - either a color name like "red" or a color spec like "rgb:F/0/0". - See the XParseColor man page for the formats available. */ - int color_column; - - /* 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); - -END_GNOME_DECLS - -#endif /* _E_CELL_TEXT_H_ */ - - diff --git a/widgets/table/e-cell-toggle.c b/widgets/table/e-cell-toggle.c deleted file mode 100644 index 45971f6f18..0000000000 --- a/widgets/table/e-cell-toggle.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * e-cell-toggle.c: Multi-state image toggle cell object. - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999, 2000 Ximian, Inc - */ -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include "e-cell-toggle.h" -#include "gal/util/e-util.h" -#include "e-table-item.h" - -#define PARENT_TYPE e_cell_get_type () - -typedef struct { - ECellView cell_view; - GdkGC *gc; - GnomeCanvas *canvas; -} ECellToggleView; - -static ECellClass *parent_class; - -static void -etog_queue_redraw (ECellToggleView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * ECell::realize method - */ -static ECellView * -etog_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellToggleView *toggle_view = g_new0 (ECellToggleView, 1); - ETableItem *eti = E_TABLE_ITEM (e_table_item_view); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; - - toggle_view->cell_view.ecell = ecell; - toggle_view->cell_view.e_table_model = table_model; - toggle_view->cell_view.e_table_item_view = e_table_item_view; - toggle_view->canvas = canvas; - - return (ECellView *) toggle_view; -} - -static void -etog_kill_view (ECellView *ecell_view) -{ - g_free (ecell_view); -} - -static void -etog_realize (ECellView *ecell_view) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - - toggle_view->gc = gdk_gc_new (GTK_WIDGET (toggle_view->canvas)->window); -} - -/* - * ECell::unrealize method - */ -static void -etog_unrealize (ECellView *ecv) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecv; - - gdk_gc_unref (toggle_view->gc); - toggle_view->gc = NULL; -} - -/* - * ECell::draw method - */ -static void -etog_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, ECellFlags flags, - int x1, int y1, int x2, int y2) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - gboolean selected; -#if 0 - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; -#endif - GdkPixbuf *image; - int x, y, width, height; - - const int value = GPOINTER_TO_INT ( - e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - - selected = flags & E_CELL_SELECTED; - - if (value >= toggle->n_states){ - g_warning ("Value from the table model is %d, the states we support are [0..%d)\n", - value, toggle->n_states); - return; - } - - image = toggle->images [value]; - - if ((x2 - x1) < gdk_pixbuf_get_width (image)){ - x = x1; - width = x2 - x1; - } else { - x = x1 + ((x2 - x1) - gdk_pixbuf_get_width (image)) / 2; - width = gdk_pixbuf_get_width (image); - } - - if ((y2 - y1) < gdk_pixbuf_get_height (image)){ - y = y1; - height = y2 - y1; - } else { - y = y1 + ((y2 - y1) - gdk_pixbuf_get_height (image)) / 2; - height = gdk_pixbuf_get_height (image); - } - -#if 0 /* do alpha */ - if (gdk_pixbuf_get_has_alpha (image)) { - flat = gdk_pixbuf_composite_color_simple ( - image, - gdk_pixbuf_get_width (image), - gdk_pixbuf_get_height (image), - GDK_INTERP_NEAREST, - 255, - 32, - 0xffffff, 0xffffff); - - gdk_pixbuf_render_to_drawable (flat, drawable, - toggle_view->gc, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_NORMAL, - 0, 0); - gdk_pixbuf_unref (flat); - } else { - gdk_pixbuf_render_to_drawable (image, drawable, - toggle_view->gc, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_NORMAL, - 0, 0); - } -#else - gdk_pixbuf_render_to_drawable_alpha (image, drawable, - 0, 0, - x, y, - width, height, - GDK_PIXBUF_ALPHA_BILEVEL, - 128, - GDK_RGB_DITHER_NORMAL, - x, y); -#endif -} - -static void -etog_set_value (ECellToggleView *toggle_view, int model_col, int view_col, int row, int value) -{ - ECell *ecell = toggle_view->cell_view.ecell; - ECellToggle *toggle = E_CELL_TOGGLE (ecell); - - if (value >= toggle->n_states) - value = 0; - - e_table_model_set_value_at (toggle_view->cell_view.e_table_model, - model_col, row, GINT_TO_POINTER (value)); - etog_queue_redraw (toggle_view, view_col, row); -} - -/* - * ECell::event method - */ -static gint -etog_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - void *_value = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - const int value = GPOINTER_TO_INT (_value); - - if (flags & !E_CELL_EDITING) - return 0; - - switch (event->type){ - case GDK_BUTTON_RELEASE: - if (!e_table_model_is_cell_editable(ecell_view->e_table_model, model_col, row)) - return FALSE; - - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - - case GDK_KEY_PRESS: - if (!e_table_model_is_cell_editable(ecell_view->e_table_model, model_col, row)) - return FALSE; - - if (event->key.keyval == GDK_space){ - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - } - return FALSE; - - default: - return FALSE; - } - return TRUE; -} - -/* - * ECell::height method - */ -static int -etog_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - - return toggle->height; -} - -/* - * ECell::max_width method - */ -static int -etog_max_width (ECellView *ecell_view, int model_col, int view_col) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - void *_value = e_table_model_value_at (ecell_view->e_table_model, model_col, 0); - int max_width = gdk_pixbuf_get_width (toggle->images[GPOINTER_TO_INT (_value)]); - int number_of_rows; - int row; - - number_of_rows = e_table_model_row_count (ecell_view->e_table_model); - for (row = 1; row < number_of_rows; row++) { - void *_value = e_table_model_value_at (ecell_view->e_table_model, - model_col, row); - max_width = MAX (max_width, gdk_pixbuf_get_width (toggle->images[GPOINTER_TO_INT (_value)])); - } - - return max_width; -} - -static void -etog_destroy (GtkObject *object) -{ - ECellToggle *etog = E_CELL_TOGGLE (object); - int i; - - for (i = 0; i < etog->n_states; i++) - gdk_pixbuf_unref (etog->images [i]); - - g_free (etog->images); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_toggle_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = etog_destroy; - - ecc->new_view = etog_new_view; - ecc->kill_view = etog_kill_view; - ecc->realize = etog_realize; - ecc->unrealize = etog_unrealize; - ecc->draw = etog_draw; - ecc->event = etog_event; - ecc->height = etog_height; - ecc->max_width = etog_max_width; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_cell_toggle, "ECellToggle", ECellToggle, e_cell_toggle_class_init, NULL, PARENT_TYPE); - -/** - * e_cell_toggle_construct: - * @etog: a fresh ECellToggle object - * @border: number of pixels used as a border - * @n_states: number of states the toggle will have - * @images: a collection of @n_states images, one for each state. - * - * Constructs the @etog object with the @border, @n_staes, and @images - * arguments. - */ -void -e_cell_toggle_construct (ECellToggle *etog, int border, int n_states, GdkPixbuf **images) -{ - int max_height = 0; - int i; - - etog->border = border; - etog->n_states = n_states; - - etog->images = g_new (GdkPixbuf *, n_states); - - for (i = 0; i < n_states; i++){ - etog->images [i] = images [i]; - gdk_pixbuf_ref (images [i]); - - if (gdk_pixbuf_get_height (images [i]) > max_height) - max_height = gdk_pixbuf_get_height (images [i]); - } - - etog->height = max_height; -} - -/** - * e_cell_checkbox_new: - * @border: number of pixels used as a border - * @n_states: number of states the toggle will have - * @images: a collection of @n_states images, one for each state. - * - * Creates a new ECell renderer that can be used to render toggle - * buttons with the images specified in @images. The value returned - * by ETableModel::get_value is typecase into an integer and clamped - * to the [0..n_states) range. That will select the image rendered. - * - * Returns: an ECell object that can be used to render multi-state - * toggle cells. - */ -ECell * -e_cell_toggle_new (int border, int n_states, GdkPixbuf **images) -{ - ECellToggle *etog = gtk_type_new (e_cell_toggle_get_type ()); - - e_cell_toggle_construct (etog, border, n_states, images); - - return (ECell *) etog; -} - - diff --git a/widgets/table/e-cell-toggle.h b/widgets/table/e-cell-toggle.h deleted file mode 100644 index 0916970b00..0000000000 --- a/widgets/table/e-cell-toggle.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _E_CELL_TOGGLE_H_ -#define _E_CELL_TOGGLE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gal/e-table/e-cell.h> - -BEGIN_GNOME_DECLS - -#define E_CELL_TOGGLE_TYPE (e_cell_toggle_get_type ()) -#define E_CELL_TOGGLE(o) (GTK_CHECK_CAST ((o), E_CELL_TOGGLE_TYPE, ECellToggle)) -#define E_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TOGGLE_TYPE, ECellToggleClass)) -#define E_IS_CELL_TOGGLE(o) (GTK_CHECK_TYPE ((o), E_CELL_TOGGLE_TYPE)) -#define E_IS_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TOGGLE_TYPE)) - -typedef struct { - ECell parent; - - int border; - int n_states; - GdkPixbuf **images; - - int height; -} ECellToggle; - -typedef struct { - ECellClass parent_class; -} ECellToggleClass; - -GtkType e_cell_toggle_get_type (void); -ECell *e_cell_toggle_new (int border, int n_states, GdkPixbuf **images); -void e_cell_toggle_construct (ECellToggle *etog, int border, - int n_states, GdkPixbuf **images); - -END_GNOME_DECLS - -#endif /* _E_CELL_TOGGLE_H_ */ - - diff --git a/widgets/table/e-cell-tree.c b/widgets/table/e-cell-tree.c deleted file mode 100644 index 62c78da748..0000000000 --- a/widgets/table/e-cell-tree.c +++ /dev/null @@ -1,697 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-cell-tree.c - Tree cell renderer - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Chris Toshok <toshok@ximian.com> - * - * A majority of code taken from: - * - * the ECellText renderer. - * - * Copyright (C) 1998 The Free Software Foundation - * Copyright (C) 1999, 2000 Ximian, Inc. - */ - -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkinvisible.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include <stdio.h> -#include "e-table-sorted-variable.h" -#include "e-tree-model.h" -#include "e-cell-tree.h" -#include "gal/util/e-util.h" -#include "e-table-item.h" - -#include <gdk/gdkx.h> /* for BlackPixel */ -#include <ctype.h> -#include <math.h> - -#include "tree-expanded.xpm" -#include "tree-unexpanded.xpm" - -#define PARENT_TYPE e_cell_get_type () - -typedef struct { - ECellView cell_view; - ECellView *subcell_view; - GdkGC *gc; - - GnomeCanvas *canvas; - -} ECellTreeView; - -static ECellClass *parent_class; - -#define INDENT_AMOUNT 16 - -static int -visible_depth_of_node (ETreeModel *tree_model, ETreePath *path) -{ - return (e_tree_model_node_depth (tree_model, path) - - (e_tree_model_root_node_is_visible (tree_model) ? 0 : 1)); -} - -static gint -offset_of_node (ETreeModel *tree_model, ETreePath *path) -{ - return (visible_depth_of_node(tree_model, path) + 1) * INDENT_AMOUNT; -} - -static ETreePath* -e_cell_tree_get_node (ETableModel *table_model, int row) -{ - return (ETreePath*)e_table_model_value_at (table_model, -1, row); -} - -static ETreeModel* -e_cell_tree_get_tree_model (ETableModel *table_model, int row) -{ - return (ETreeModel*)e_table_model_value_at (table_model, -2, row); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellTree *ect = E_CELL_TREE (ecell); - ECellTreeView *tree_view = g_new0 (ECellTreeView, 1); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (e_table_item_view)->canvas; - - tree_view->cell_view.ecell = ecell; - tree_view->cell_view.e_table_model = table_model; - tree_view->cell_view.e_table_item_view = e_table_item_view; - - /* create our subcell view */ - tree_view->subcell_view = e_cell_new_view (ect->subcell, table_model, e_table_item_view /* XXX */); - - tree_view->canvas = canvas; - - return (ECellView *)tree_view; -} - -/* - * ECell::kill_view method - */ -static void -ect_kill_view (ECellView *ecv) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecv; - - /* kill our subcell view */ - e_cell_kill_view (tree_view->subcell_view); - - g_free (tree_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - /* realize our subcell view */ - e_cell_realize (tree_view->subcell_view); - - tree_view->gc = gdk_gc_new (GTK_WIDGET (tree_view->canvas)->window); - - gdk_gc_set_line_attributes (tree_view->gc, 1, - GDK_LINE_ON_OFF_DASH, None, None); - gdk_gc_set_dashes (tree_view->gc, 0, "\1\1", 2); - - if (parent_class->realize) - (* parent_class->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecv; - - /* unrealize our subcell view. */ - e_cell_unrealize (tree_view->subcell_view); - - gdk_gc_unref (tree_view->gc); - tree_view->gc = NULL; - - if (parent_class->unrealize) - (* parent_class->unrealize) (ecv); -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, ECellFlags flags, - int x1, int y1, int x2, int y2) -{ - ECellTreeView *tree_view = (ECellTreeView *)ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model(ecell_view->e_table_model, row); - ETreePath *node; - GdkRectangle rect, *clip_rect; - GtkWidget *canvas = GTK_WIDGET (tree_view->canvas); - GdkGC *fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - GdkColor *foreground; - gboolean selected; - - int offset, subcell_offset; - gboolean expanded, expandable; - - selected = flags & E_CELL_SELECTED; - - /* 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 (ecell_view->e_table_model, row); - - expandable = e_tree_model_node_is_expandable (tree_model, node); - expanded = e_tree_model_node_is_expanded (tree_model, node); - - if (visible_depth_of_node (tree_model, node) > 0 || expandable) { - offset = offset_of_node (tree_model, node); - } else { - offset = 0; - } - subcell_offset = offset; - - node_image = e_tree_model_icon_of_node (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 = subcell_offset + node_image_width; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (tree_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (selected) { - foreground = &canvas->style->text [GTK_STATE_SELECTED]; - } else { - foreground = &canvas->style->text [GTK_STATE_NORMAL]; - } - - gdk_gc_set_foreground (tree_view->gc, foreground); - - /* draw our lines */ - if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { - - if (visible_depth_of_node (tree_model, node) > 0 - || 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, - rect.x + offset - INDENT_AMOUNT / 2, - rect.y, - rect.x + offset - INDENT_AMOUNT / 2, - (e_tree_model_node_get_next (tree_model, node) - ? rect.y + rect.height - : rect.y + rect.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. */ - parent_node = e_tree_model_node_get_parent (tree_model, node); - offset -= INDENT_AMOUNT; - 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); - } - 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; - int image_width, image_height; - - 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 - 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, - node_image_width, 0); - subcell_offset += node_image_width; - } - } - - /* Now cause our subcell to draw its contents, shifted by - subcell_offset pixels */ - e_cell_draw (tree_view->subcell_view, drawable, - model_col, view_col, row, flags, - x1 + subcell_offset, y1, x2, y2); -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); - ETreePath *node = e_cell_tree_get_node (ecell_view->e_table_model, row); - int offset = offset_of_node (tree_model, node); - - switch (event->type) { - case GDK_BUTTON_PRESS: { - /* if the event happened in our area of control (and - we care about it), handle it. */ - - /* only activate the tree control if the click/release happens in the icon's area. */ - if (event->button.x > (offset - INDENT_AMOUNT) && event->button.x < offset) { - if (e_tree_model_node_is_expandable (tree_model, node)) { - e_tree_model_node_set_expanded (tree_model, - node, - !e_tree_model_node_is_expanded(tree_model, node)); - return TRUE; - } - } - else if (event->button.x < (offset - INDENT_AMOUNT)) - return FALSE; - } - default: { - gint return_value; - - /* modify the event and pass it off to our subcell_view */ - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - event->button.x -= offset; - break; - case GDK_MOTION_NOTIFY: - event->motion.x -= offset; - break; - default: - /* nada */ - } - - return_value = e_cell_event(tree_view->subcell_view, event, model_col, view_col, row, flags, actions); - - /* modify the event and pass it off to our subcell_view */ - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - event->button.x += offset; - break; - case GDK_MOTION_NOTIFY: - event->motion.x += offset; - break; - default: - /* nada */ - } - - return return_value; - } - } -} - -/* - * ECell::height method - */ -static int -ect_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - return e_cell_height (tree_view->subcell_view, model_col, view_col, row); -} - -/* - * ECell::max_width method - */ -static int -ect_max_width (ECellView *ecell_view, int model_col, int view_col) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - int row; - int number_of_rows; - int max_width = 0; - int width = 0; - int subcell_max_width; - - number_of_rows = e_table_model_row_count (ecell_view->e_table_model); - - subcell_max_width = e_cell_max_width (tree_view->subcell_view, model_col, view_col); - - for (row = 0; row < number_of_rows; row++) { - ETreeModel *tree_model = e_cell_tree_get_tree_model(ecell_view->e_table_model, row); - ETreePath *node; - GdkPixbuf *node_image; - int node_image_width = 0, node_image_height = 0; - - int offset, subcell_offset; - gboolean expanded, expandable; - - node = e_cell_tree_get_node (ecell_view->e_table_model, row); - - offset = offset_of_node (tree_model, node); - expandable = e_tree_model_node_is_expandable (tree_model, node); - expanded = e_tree_model_node_is_expanded (tree_model, node); - subcell_offset = offset; - - node_image = e_tree_model_icon_of_node (tree_model, node); - - if (node_image) { - node_image_width = gdk_pixbuf_get_width (node_image); - node_image_height = gdk_pixbuf_get_height (node_image); - } - - width = subcell_max_width + subcell_offset + node_image_width; - - if (expandable) { - GdkPixbuf *image; - - image = (expanded - ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf - : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf); - - width += gdk_pixbuf_get_width(image); - } - - max_width = MAX (max_width, width); - } - - return max_width; -} - -/* - * ECellView::show_tooltip method - */ -static void -ect_show_tooltip (ECellView *ecell_view, int model_col, int view_col, int row, - int col_width, ETableTooltip *tooltip) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); - ETreePath *node = e_cell_tree_get_node (ecell_view->e_table_model, row); - int offset = offset_of_node (tree_model, node); - GdkPixbuf *node_image; - - node_image = e_tree_model_icon_of_node (tree_model, node); - if (node_image) - offset += gdk_pixbuf_get_width (node_image); - - tooltip->x += offset; - e_cell_show_tooltip (tree_view->subcell_view, model_col, view_col, row, col_width - offset, tooltip); -} - -/* - * ECellView::enter_edit method - */ -static void * -ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - /* just defer to our subcell's view */ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - return e_cell_enter_edit (tree_view->subcell_view, model_col, view_col, row); -} - -/* - * ECellView::leave_edit method - */ -static void -ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - /* just defer to our subcell's view */ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - 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 (ecell_view->e_table_model, row); - int offset = offset_of_node (tree_model, node); - int subcell_offset = offset; - gboolean expandable = e_tree_model_node_is_expandable (tree_model, node); - gboolean expanded = e_tree_model_node_is_expanded (tree_model, node); - - /* draw our lines */ - if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { - - if (!e_tree_model_node_is_root (tree_model, node) - || e_tree_model_node_get_children (tree_model, node, NULL) > 0) { - 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; - } - } - - /* now draw our icon if we're expandable */ - if (expandable) { - double image_matrix [6] = {16, 0, 0, 16, 0, 0}; - GdkPixbuf *image = (expanded - ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf - : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf); - int image_width, image_height, image_rowstride; - guchar *image_pixels; - - image_width = gdk_pixbuf_get_width(image); - image_height = gdk_pixbuf_get_height(image); - image_pixels = gdk_pixbuf_get_pixels(image); - image_rowstride = gdk_pixbuf_get_rowstride(image); - - image_matrix [4] = subcell_offset - INDENT_AMOUNT / 2 - image_width / 2; - image_matrix [5] = height / 2 - image_height / 2; - - gnome_print_gsave (context); - gnome_print_concat (context, image_matrix); - - gnome_print_rgbaimage (context, image_pixels, image_width, image_height, image_rowstride); - gnome_print_grestore (context); - } - - 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 - */ -static void -ect_destroy (GtkObject *object) -{ - ECellTree *ect = E_CELL_TREE (object); - - /* destroy our subcell */ - if (ect->subcell) - gtk_object_unref (GTK_OBJECT (ect->subcell)); - ect->subcell = NULL; - - gdk_pixbuf_unref (ect->open_pixbuf); - gdk_pixbuf_unref (ect->closed_pixbuf); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_tree_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = ect_destroy; - - ecc->new_view = ect_new_view; - ecc->kill_view = ect_kill_view; - ecc->realize = ect_realize; - ecc->unrealize = ect_unrealize; - ecc->draw = ect_draw; - ecc->event = ect_event; - 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; - ecc->max_width = ect_max_width; - ecc->show_tooltip = ect_show_tooltip; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_cell_tree, "ECellTree", ECellTree, e_cell_tree_class_init, NULL, PARENT_TYPE); - -/** - * e_cell_tree_construct: - * @ect: the ECellTree we're constructing. - * @open_pixbuf: pixbuf to be used instead of the '-' icon. - * @closed_pixbuf: pixbuf to be used instead of the '+' icon. - * @draw_lines: whether or not to draw the lines between parents/children/siblings. - * @subcell: the ECell to render to the right of the tree effects. - * - * Constructs an ECellTree. used by subclasses that need to - * initialize a nested ECellTree. See e_cell_tree_new() for more info. - * - **/ -void -e_cell_tree_construct (ECellTree *ect, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell) -{ - ect->subcell = subcell; - if (subcell) { - gtk_object_ref (GTK_OBJECT (subcell)); - gtk_object_sink (GTK_OBJECT (subcell)); - } - if (open_pixbuf) - ect->open_pixbuf = open_pixbuf; - else - ect->open_pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **)tree_expanded_xpm); - if (closed_pixbuf) - ect->closed_pixbuf = closed_pixbuf; - else - ect->closed_pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **)tree_unexpanded_xpm); - - ect->draw_lines = draw_lines; -} - - -/** - * e_cell_tree_new: - * @open_pixbuf: pixbuf to be used instead of the '-' icon. - * @closed_pixbuf: pixbuf to be used instead of the '+' icon. - * @draw_lines: whether or not to draw the lines between parents/children/siblings. - * @subcell: the ECell to render to the right of the tree effects. - * - * Creates a new ECell renderer that can be used to render tree - * effects that come from an ETreeModel. Various assumptions are made - * as to the fact that the ETableModel the ETable this cell is - * associated with is in fact an ETreeModel. The cell uses special - * columns to get at structural information (needed to draw the - * lines/icons. - * - * Return value: an ECell object that can be used to render trees. - **/ -ECell * -e_cell_tree_new (GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell) -{ - ECellTree *ect = gtk_type_new (e_cell_tree_get_type ()); - - e_cell_tree_construct (ect, open_pixbuf, closed_pixbuf, draw_lines, subcell); - - return (ECell *) ect; -} diff --git a/widgets/table/e-cell-tree.h b/widgets/table/e-cell-tree.h deleted file mode 100644 index 7b2d007159..0000000000 --- a/widgets/table/e-cell-tree.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellTree - Tree item for e-table. - * Copyright (C) 2000 Ximian, Inc. - * Author: Chris Toshok <toshok@ximian.com> - * - */ -#ifndef _E_CELL_TREE_H_ -#define _E_CELL_TREE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gal/e-table/e-cell.h> - -BEGIN_GNOME_DECLS - -#define E_CELL_TREE_TYPE (e_cell_tree_get_type ()) -#define E_CELL_TREE(o) (GTK_CHECK_CAST ((o), E_CELL_TREE_TYPE, ECellTree)) -#define E_CELL_TREE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TREE_TYPE, ECellTreeClass)) -#define E_IS_CELL_TREE(o) (GTK_CHECK_TYPE ((o), E_CELL_TREE_TYPE)) -#define E_IS_CELL_TREE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TREE_TYPE)) - -typedef struct { - ECell parent; - - gboolean draw_lines; - - GdkPixbuf *open_pixbuf; - GdkPixbuf *closed_pixbuf; - - ECell *subcell; -} ECellTree; - -typedef struct { - ECellClass parent_class; -} ECellTreeClass; - -GtkType e_cell_tree_get_type (void); -ECell *e_cell_tree_new (GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell); -void e_cell_tree_construct (ECellTree *ect, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell); - - -END_GNOME_DECLS - -#endif /* _E_CELL_TREE_H_ */ - - diff --git a/widgets/table/e-cell.c b/widgets/table/e-cell.c deleted file mode 100644 index 2d59df19da..0000000000 --- a/widgets/table/e-cell.c +++ /dev/null @@ -1,354 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-cell.c: base class for cell renderers in e-table - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Ximian, Inc - */ -#include <config.h> -#include "e-cell.h" -#include "gal/util/e-util.h" - -#define PARENT_TYPE gtk_object_get_type () - -static ECellView * -ec_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return NULL; -} - -static void -ec_realize (ECellView *e_cell) -{ -} - -static void -ec_kill_view (ECellView *ecell_view) -{ -} - -static void -ec_unrealize (ECellView *e_cell) -{ -} - -static void -ec_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, ECellFlags flags, - int x1, int y1, int x2, int y2) -{ - g_error ("e-cell-draw invoked\n"); -} - -static gint -ec_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static gint -ec_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - g_error ("e-cell-height invoked\n"); - return 0; -} - -static void -ec_focus (ECellView *ecell_view, int model_col, int view_col, int row, int x1, int y1, int x2, int y2) -{ - ecell_view->focus_col = view_col; - ecell_view->focus_row = row; - ecell_view->focus_x1 = x1; - ecell_view->focus_y1 = y1; - ecell_view->focus_x2 = x2; - ecell_view->focus_y2 = y2; -} - -static void -ec_unfocus (ECellView *ecell_view) -{ - ecell_view->focus_col = -1; - ecell_view->focus_row = -1; - ecell_view->focus_x1 = -1; - ecell_view->focus_y1 = -1; - ecell_view->focus_x2 = -1; - ecell_view->focus_y2 = -1; -} - -static void * -ec_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return NULL; -} - -static void -ec_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *context) -{ -} - -static void -ec_show_tooltip (ECellView *ecell_view, int model_col, int view_col, int row, int col_width, ETableTooltip *tooltip) -{ - /* Do nothing */ -} - -static void -e_cell_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - ecc->realize = ec_realize; - ecc->unrealize = ec_unrealize; - ecc->new_view = ec_new_view; - ecc->kill_view = ec_kill_view; - ecc->draw = ec_draw; - ecc->event = ec_event; - ecc->focus = ec_focus; - ecc->unfocus = ec_unfocus; - ecc->height = ec_height; - ecc->enter_edit = ec_enter_edit; - ecc->leave_edit = ec_leave_edit; - ecc->print = NULL; - ecc->print_height = NULL; - ecc->max_width = NULL; - ecc->show_tooltip = ec_show_tooltip; -} - -static void -e_cell_init (GtkObject *object) -{ -} - -E_MAKE_TYPE(e_cell, "ECell", ECell, e_cell_class_init, e_cell_init, PARENT_TYPE); - -/** - * e_cell_event: - * @ecell_view: The ECellView where the event will be dispatched - * @event: The GdkEvent. - * @model_col: the column in the model - * @view_col: the column in the view - * @row: the row - * @flags: flags about the current state - * @actions: A second return value in case the cell wants to take some action (specifically grabbing & ungrabbing) - * - * Dispatches the event @event to the @ecell_view for. - * - * Returns: processing state from the GdkEvent handling. - */ -gint -e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->event ( - ecell_view, event, model_col, view_col, row, flags, actions); -} - -/** - * e_cell_new_view: - * @ecell: the Ecell that will create the new view - * @table_model: the table model the ecell is bound to - * @e_table_item_view: An ETableItem object (the CanvasItem that reprensents the view of the table) - * - * ECell renderers new to be bound to a table_model and to the actual view - * during their life time to actually render the data. This method is invoked - * by the ETableItem canvas item to instatiate a new view of the ECell. - * - * This is invoked when the ETableModel is attached to the ETableItem (a CanvasItem - * that can render ETableModels in the screen). - * - * Returns: a new ECellView for this @ecell on the @table_model displayed on the @e_table_item_view. - */ -ECellView * -e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell)->klass)->new_view ( - ecell, table_model, e_table_item_view); -} - -/** - * e_cell_realize: - * @ecell_view: The ECellView to be realized. - * - * This function is invoked to give a chance to the ECellView to allocate - * any resources it needs from Gdk, equivalent to the GtkWidget::realize - * signal. - */ -void -e_cell_realize (ECellView *ecell_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->realize (ecell_view); -} - -/** - * e_cell_kill_view: - * @ecell_view: view to be destroyed. - * - * This method it used to destroy a view of an ECell renderer - */ -void -e_cell_kill_view (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->kill_view (ecell_view); -} - -/** - * e_cell_unrealize: - * @ecell_view: The ECellView to be unrealized. - * - * This function is invoked to give a chance to the ECellView to - * release any resources it allocated during the realize method, - * equivalent to the GtkWidget::unrealize signal. - */ -void -e_cell_unrealize (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->unrealize (ecell_view); -} - -/** - * e_cell_draw: - * @ecell_view: the ECellView to redraw - * @drawable: draw desination - * @model_col: the column in the model being drawn. - * @view_col: the column in the view being drawn (what the model maps to). - * @row: the row being drawn - * @flags: rendering flags. - * @x1: boudary for the rendering - * @y1: boudary for the rendering - * @x2: boudary for the rendering - * @y2: boudary for the rendering - * - * This instructs the ECellView to render itself into the drawable. The - * region to be drawn in given by (x1,y1)-(x2,y2). - * - * The most important flags are %E_CELL_SELECTED and %E_CELL_FOCUSED, other - * flags include alignments and justifications. - */ -void -e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, ECellFlags flags, - int x1, int y1, int x2, int y2) -{ - g_return_if_fail (ecell_view != NULL); - g_return_if_fail (row >= 0); - g_return_if_fail (row < e_table_model_row_count(ecell_view->e_table_model)); - - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->draw ( - ecell_view, drawable, model_col, view_col, row, flags, x1, y1, x2, y2); -} - -/** - * e_cell_print: - * @ecell_view: the ECellView to redraw - * @context: The GnomePrintContext where we output our printed data. - * @model_col: the column in the model being drawn. - * @view_col: the column in the view being drawn (what the model maps to). - * @row: the row being drawn - * @width: width - * @height: height - * - * FIXME: - */ -void -e_cell_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print - (ecell_view, context, model_col, view_col, row, width, height); -} - -/** - * e_cell_print: - * - * FIXME: - */ -gdouble -e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width) -{ - if (E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height) - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height - (ecell_view, context, model_col, view_col, row, width); - else - return 0.0; -} - -/** - * e_cell_height: - * @ecell_view: the ECellView. - * @model_col: the column in the model - * @view_col: the column in the view. - * @row: the row to me measured - * - * Returns: the height of the cell at @model_col, @row rendered at - * @view_col, @row. - */ -int -e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height ( - ecell_view, model_col, view_col, row); -} - -/** - * e_cell_enter_edit: - * @ecell_view: the ECellView that will enter editing - * @model_col: the column in the model - * @view_col: the column in the view - * @row: the row - * - * Notifies the ECellView that it is about to enter editing mode for - * @model_col, @row rendered at @view_col, @row. - */ -void * -e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->enter_edit ( - ecell_view, model_col, view_col, row); -} - -/** - * e_cell_leave_edit: - * @ecell_view: the ECellView that will leave editing - * @model_col: the column in the model - * @view_col: the column in the view - * @row: the row - * @edit_context: the editing context - * - * Notifies the ECellView that editing is finished at @model_col, @row - * rendered at @view_col, @row. - */ -void -e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->leave_edit ( - ecell_view, model_col, view_col, row, edit_context); -} - -/** - * e_cell_max_width: - * @ecell_view: the ECellView that will leave editing - * @model_col: the column in the model - * @view_col: the column in the view. - * - * Returns: the maximum width for the ECellview at @model_col which - * is being rendered as @view_col - */ -int -e_cell_max_width (ECellView *ecell_view, int model_col, int view_col) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->max_width - (ecell_view, model_col, view_col); -} - -void -e_cell_show_tooltip (ECellView *ecell_view, int model_col, int view_col, - int row, int col_width, ETableTooltip *tooltip) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->show_tooltip - (ecell_view, model_col, view_col, row, col_width, tooltip); -} diff --git a/widgets/table/e-cell.h b/widgets/table/e-cell.h deleted file mode 100644 index b9927114bb..0000000000 --- a/widgets/table/e-cell.h +++ /dev/null @@ -1,113 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_CELL_H_ -#define _E_CELL_H_ - -#include <gdk/gdktypes.h> -#include <libgnomeprint/gnome-print.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-tooltip.h> - -BEGIN_GNOME_DECLS - -#define E_CELL_TYPE (e_cell_get_type ()) -#define E_CELL(o) (GTK_CHECK_CAST ((o), E_CELL_TYPE, ECell)) -#define E_CELL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TYPE, ECellClass)) -#define E_IS_CELL(o) (GTK_CHECK_TYPE ((o), E_CELL_TYPE)) -#define E_IS_CELL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TYPE)) - -typedef enum { - E_CELL_SELECTED = 1 << 0, - - E_CELL_JUSTIFICATION = 3 << 1, - E_CELL_JUSTIFY_CENTER = 0 << 1, - E_CELL_JUSTIFY_LEFT = 1 << 1, - E_CELL_JUSTIFY_RIGHT = 2 << 1, - E_CELL_JUSTIFY_FILL = 3 << 1, - - E_CELL_ALIGN_LEFT = 1 << 1, - E_CELL_ALIGN_RIGHT = 1 << 2, - - E_CELL_FOCUSED = 1 << 3, - - E_CELL_EDITING = 1 << 4, -} ECellFlags; - -typedef enum { - E_CELL_GRAB = 1 << 0, - E_CELL_UNGRAB = 1 << 1, -} ECellActions; - -typedef struct { - GtkObject object; -} ECell; - -typedef struct { - ECell *ecell; - ETableModel *e_table_model; - void *e_table_item_view; - - gint focus_x1, focus_y1, focus_x2, focus_y2; - gint focus_col, focus_row; -} ECellView; - -#define E_CELL_IS_FOCUSED(ecell_view) (ecell_view->focus_x1 != -1) - -typedef struct { - GtkObjectClass parent_class; - - ECellView *(*new_view) (ECell *ecell, ETableModel *table_model, void *e_table_item_view); - void (*kill_view) (ECellView *ecell_view); - - void (*realize) (ECellView *ecell_view); - void (*unrealize) (ECellView *ecell_view); - - void (*draw) (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, - ECellFlags flags, int x1, int y1, int x2, int y2); - gint (*event) (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions); - void (*focus) (ECellView *ecell_view, int model_col, int view_col, - int row, int x1, int y1, int x2, int y2); - void (*unfocus) (ECellView *ecell_view); - int (*height) (ECellView *ecell_view, int model_col, int view_col, int row); - - void *(*enter_edit) (ECellView *ecell_view, int model_col, int view_col, int row); - void (*leave_edit) (ECellView *ecell_view, int model_col, int view_col, int row, void *context); - void (*print) (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - gdouble width, gdouble height); - gdouble (*print_height) (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, gdouble width); - int (*max_width) (ECellView *ecell_view, int model_col, int view_col); - void (*show_tooltip) (ECellView *ecell_view, int model_col, int view_col, int row, int col_width, ETableTooltip *tooltip); -} ECellClass; - -GtkType e_cell_get_type (void); -ECellView *e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view); -void e_cell_kill_view (ECellView *ecell_view); - -gint e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions); - -void e_cell_realize (ECellView *ecell_view); -void e_cell_unrealize (ECellView *ecell_view); - -void e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, ECellFlags flags, - int x1, int y1, int x2, int y2); -void e_cell_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height); -gdouble e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, gdouble width); -int e_cell_max_width (ECellView *ecell_view, int model_col, int view_col); -void e_cell_show_tooltip (ECellView *ecell_view, int model_col, int view_col, int row, int col_width, ETableTooltip *tooltip); -void e_cell_focus (ECellView *ecell_view, int model_col, int view_col, int row, - int x1, int y1, int x2, int y2); -void e_cell_unfocus (ECellView *ecell_view); -int e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row); - -void *e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row); -void e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context); - -END_GNOME_DECLS - -#endif /* _E_CELL_H_ */ diff --git a/widgets/table/e-table-click-to-add.c b/widgets/table/e-table-click-to-add.c deleted file mode 100644 index 4e2d71f9d6..0000000000 --- a/widgets/table/e-table-click-to-add.c +++ /dev/null @@ -1,541 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-click-to-add.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Ximian, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "e-table-header.h" -#include "e-table-click-to-add.h" -#include "e-table-defines.h" -#include "e-table-one.h" -#include "gal/e-text/e-text.h" -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-canvas-utils.h" - -enum { - CURSOR_CHANGE, - LAST_SIGNAL -}; - -static gint etcta_signals [LAST_SIGNAL] = { 0, }; - -#define PARENT_OBJECT_TYPE gnome_canvas_group_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasGroupClass *etcta_parent_class; - -enum { - ARG_0, - ARG_HEADER, - ARG_MODEL, - ARG_MESSAGE, - ARG_WIDTH, - ARG_HEIGHT, -}; - -static void -etcta_cursor_change (GtkObject *object, gint row, gint col, ETableClickToAdd *etcta) -{ - gtk_signal_emit (GTK_OBJECT (etcta), - etcta_signals [CURSOR_CHANGE], - row, col); -} - -static void -etcta_add_table_header (ETableClickToAdd *etcta, ETableHeader *header) -{ - etcta->eth = header; - if (etcta->eth) - gtk_object_ref (GTK_OBJECT (etcta->eth)); - if (etcta->row) - gnome_canvas_item_set(GNOME_CANVAS_ITEM(etcta->row), - "ETableHeader", header, - NULL); -} - -static void -etcta_drop_table_header (ETableClickToAdd *etcta) -{ - GtkObject *header; - - if (!etcta->eth) - return; - - header = GTK_OBJECT (etcta->eth); - - gtk_object_unref (header); - etcta->eth = NULL; -} - -static void -etcta_add_one (ETableClickToAdd *etcta, ETableModel *one) -{ - etcta->one = one; - if (etcta->one) - gtk_object_ref (GTK_OBJECT(etcta->one)); - if (etcta->row) - gnome_canvas_item_set(GNOME_CANVAS_ITEM(etcta->row), - "ETableModel", one, - NULL); - gtk_object_set(GTK_OBJECT(etcta->selection), - "model", one, - NULL); -} - -static void -etcta_drop_one (ETableClickToAdd *etcta) -{ - if (!etcta->one) - return; - gtk_object_unref (GTK_OBJECT(etcta->one)); - etcta->one = NULL; - gtk_object_set(GTK_OBJECT(etcta->selection), - "model", NULL, - NULL); -} - -static void -etcta_add_model (ETableClickToAdd *etcta, ETableModel *model) -{ - etcta->model = model; - if (etcta->model) - gtk_object_ref (GTK_OBJECT(etcta->model)); -} - -static void -etcta_drop_model (ETableClickToAdd *etcta) -{ - etcta_drop_one (etcta); - if (!etcta->model) - return; - gtk_object_unref (GTK_OBJECT(etcta->model)); - etcta->model = NULL; -} - -static void -etcta_add_message (ETableClickToAdd *etcta, char *message) -{ - etcta->message = g_strdup(message); -} - -static void -etcta_drop_message (ETableClickToAdd *etcta) -{ - g_free(etcta->message); - etcta->message = NULL; -} - - -static void -etcta_destroy (GtkObject *object){ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (object); - - etcta_drop_table_header (etcta); - etcta_drop_model (etcta); - etcta_drop_message (etcta); - gtk_object_unref(GTK_OBJECT(etcta->selection)); - - if (GTK_OBJECT_CLASS (etcta_parent_class)->destroy) - (*GTK_OBJECT_CLASS (etcta_parent_class)->destroy) (object); -} - -static void -etcta_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableClickToAdd *etcta; - - item = GNOME_CANVAS_ITEM (o); - etcta = E_TABLE_CLICK_TO_ADD (o); - - switch (arg_id){ - case ARG_HEADER: - etcta_drop_table_header (etcta); - etcta_add_table_header (etcta, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - case ARG_MODEL: - etcta_drop_model (etcta); - etcta_add_model (etcta, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - case ARG_MESSAGE: - etcta_drop_message (etcta); - etcta_add_message (etcta, GTK_VALUE_STRING (*arg)); - break; - case ARG_WIDTH: - etcta->width = GTK_VALUE_DOUBLE (*arg); - if (etcta->row) - gnome_canvas_item_set(etcta->row, - "minimum_width", etcta->width, - NULL); - if (etcta->text) - gnome_canvas_item_set(etcta->text, - "width", etcta->width - 4, - NULL); - if (etcta->rect) - gnome_canvas_item_set(etcta->rect, - "x2", etcta->width - 1, - NULL); - break; - } - gnome_canvas_item_request_update(item); -} - -static void -etcta_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableClickToAdd *etcta; - - etcta = E_TABLE_CLICK_TO_ADD (o); - - switch (arg_id){ - case ARG_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etcta->eth); - break; - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etcta->model); - break; - case ARG_MESSAGE: - GTK_VALUE_STRING (*arg) = g_strdup(etcta->message); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etcta->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etcta->height; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etcta_realize (GnomeCanvasItem *item) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - etcta->rect = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) etcta->width - 1, - "y2", (double) etcta->height - 1, - "outline_color", "black", - "fill_color", "white", - NULL); - - etcta->text = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - e_text_get_type(), - "text", etcta->message ? etcta->message : "", - "anchor", GTK_ANCHOR_NW, - "width", etcta->width - 4, - "draw_background", FALSE, - NULL); - e_canvas_item_move_absolute (etcta->text, 2, 2); - - if (GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->realize)(item); -} - -static void -etcta_unrealize (GnomeCanvasItem *item) -{ - if (GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->unrealize)(item); -} - -static double -etcta_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -static void finish_editing (ETableClickToAdd *etcta); - -static int -item_key_press (ETableItem *item, int row, int col, GdkEvent *event, ETableClickToAdd *etcta) -{ - switch (event->key.keyval) { - case GDK_Return: - case GDK_KP_Enter: - case GDK_ISO_Enter: - case GDK_3270_Enter: - finish_editing(etcta); - return TRUE; - } - return FALSE; -} - -static void -finish_editing (ETableClickToAdd *etcta) -{ - if (etcta->row) { - ETableModel *one; - - e_table_one_commit(E_TABLE_ONE(etcta->one)); - etcta_drop_one (etcta); - gtk_object_destroy(GTK_OBJECT(etcta->row)); - etcta->row = NULL; - - one = e_table_one_new(etcta->model); - etcta_add_one (etcta, one); - gtk_object_unref(GTK_OBJECT(one)); - - e_table_selection_model_clear(etcta->selection); - - etcta->row = gnome_canvas_item_new(GNOME_CANVAS_GROUP(etcta), - e_table_item_get_type(), - "ETableHeader", etcta->eth, - "ETableModel", etcta->one, - "minimum_width", etcta->width, - "drawgrid", TRUE, - "table_selection_model", etcta->selection, - "cursor_mode", E_TABLE_CURSOR_SPREADSHEET, - NULL); - - gtk_signal_connect(GTK_OBJECT(etcta->row), "key_press", - GTK_SIGNAL_FUNC(item_key_press), etcta); - - e_table_item_set_cursor(E_TABLE_ITEM(etcta->row), 0, 0); - } -} - -/* - * Handles the events on the ETableClickToAdd, particularly it creates the ETableItem and passes in some events. - */ -static int -etcta_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - int ret_val = TRUE; - - switch (e->type){ - case GDK_BUTTON_PRESS: - if (etcta->text) { - gtk_object_destroy(GTK_OBJECT(etcta->text)); - etcta->text = NULL; - } - if (etcta->rect) { - gtk_object_destroy(GTK_OBJECT(etcta->rect)); - etcta->rect = NULL; - } - if (!etcta->row) { - ETableModel *one; - - one = e_table_one_new(etcta->model); - etcta_add_one (etcta, one); - gtk_object_unref(GTK_OBJECT(one)); - - e_table_selection_model_clear(etcta->selection); - - etcta->row = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - e_table_item_get_type(), - "ETableHeader", etcta->eth, - "ETableModel", etcta->one, - "minimum_width", etcta->width, - "drawgrid", TRUE, - "table_selection_model", etcta->selection, - "cursor_mode", E_TABLE_CURSOR_SPREADSHEET, - NULL); - - gtk_signal_connect(GTK_OBJECT(etcta->row), "key_press", - GTK_SIGNAL_FUNC(item_key_press), etcta); - } - /* Fall through. No break; */ - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - if (etcta->row) { - gnome_canvas_item_i2w (item, &e->button.x, &e->button.y); - gnome_canvas_item_w2i (etcta->row, &e->button.x, &e->button.y); - gtk_signal_emit_by_name(GTK_OBJECT(etcta->row), "event", e, &ret_val); - gnome_canvas_item_i2w (etcta->row, &e->button.x, &e->button.y); - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - } - break; - - case GDK_KEY_PRESS: - switch (e->key.keyval) { - case GDK_Tab: - case GDK_KP_Tab: - case GDK_ISO_Left_Tab: - finish_editing (etcta); - break; - default: - return FALSE; - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -etcta_reflow (GnomeCanvasItem *item, int flags) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - double old_height = etcta->height; - - if (etcta->text) { - gtk_object_get(GTK_OBJECT(etcta->text), - "height", &etcta->height, - NULL); - etcta->height += 6; - } - if (etcta->row) { - gtk_object_get(GTK_OBJECT(etcta->row), - "height", &etcta->height, - NULL); - } - - if (etcta->rect) { - gtk_object_set(GTK_OBJECT(etcta->rect), - "y2", etcta->height - 1, - NULL); - } - if (old_height != etcta->height) - e_canvas_item_request_parent_reflow(item); -} - -static void -etcta_class_init (ETableClickToAddClass *klass) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS(klass); - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - - etcta_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - klass->cursor_change = NULL; - - object_class->destroy = etcta_destroy; - object_class->set_arg = etcta_set_arg; - object_class->get_arg = etcta_get_arg; - - item_class->realize = etcta_realize; - item_class->unrealize = etcta_unrealize; - item_class->point = etcta_point; - item_class->event = etcta_event; - - gtk_object_add_arg_type ("ETableClickToAdd::header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_HEADER); - gtk_object_add_arg_type ("ETableClickToAdd::model", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("ETableClickToAdd::message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_MESSAGE); - gtk_object_add_arg_type ("ETableClickToAdd::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableClickToAdd::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - - etcta_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClickToAddClass, cursor_change), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, etcta_signals, LAST_SIGNAL); -} - -static void -etcta_init (GnomeCanvasItem *item) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - etcta->one = NULL; - etcta->model = NULL; - etcta->eth = NULL; - - etcta->message = NULL; - - etcta->row = NULL; - etcta->text = NULL; - etcta->rect = NULL; - - etcta->selection = e_table_selection_model_new(); - gtk_signal_connect(GTK_OBJECT(etcta->selection), "cursor_changed", - GTK_SIGNAL_FUNC(etcta_cursor_change), etcta); - - e_canvas_item_set_reflow_callback(item, etcta_reflow); -} - -GtkType -e_table_click_to_add_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableClickToAdd", - sizeof (ETableClickToAdd), - sizeof (ETableClickToAddClass), - (GtkClassInitFunc) etcta_class_init, - (GtkObjectInitFunc) etcta_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - - -/* The colors in this need to be themefied. */ -/** - * e_table_click_to_add_commit: - * @etcta: The %ETableClickToAdd to commit. - * - * This routine commits the current thing being edited and returns to - * just displaying the click to add message. - **/ -void -e_table_click_to_add_commit (ETableClickToAdd *etcta) -{ - if (etcta->row) { - e_table_one_commit(E_TABLE_ONE(etcta->one)); - etcta_drop_one (etcta); - gtk_object_destroy(GTK_OBJECT(etcta->row)); - etcta->row = NULL; - } - if (!etcta->rect) { - etcta->rect = gnome_canvas_item_new(GNOME_CANVAS_GROUP(etcta), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) etcta->width - 1, - "y2", (double) etcta->height - 1, - "outline_color", "black", - "fill_color", "white", - NULL); - } - if (!etcta->text) { - etcta->text = gnome_canvas_item_new(GNOME_CANVAS_GROUP(etcta), - e_text_get_type(), - "text", etcta->message ? etcta->message : "", - "anchor", GTK_ANCHOR_NW, - "width", etcta->width - 4, - "draw_background", FALSE, - NULL); - e_canvas_item_move_absolute (etcta->text, 3, 3); - } -} diff --git a/widgets/table/e-table-click-to-add.h b/widgets/table/e-table-click-to-add.h deleted file mode 100644 index f4412cb0ea..0000000000 --- a/widgets/table/e-table-click-to-add.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_CLICK_TO_ADD_H_ -#define _E_TABLE_CLICK_TO_ADD_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include <gal/e-table/e-table-header.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-item.h> -#include <gal/e-table/e-table-selection-model.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_CLICK_TO_ADD_TYPE (e_table_click_to_add_get_type ()) -#define E_TABLE_CLICK_TO_ADD(o) (GTK_CHECK_CAST ((o), E_TABLE_CLICK_TO_ADD_TYPE, ETableClickToAdd)) -#define E_TABLE_CLICK_TO_ADD_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_CLICK_TO_ADD_TYPE, ETableClickToAddClass)) -#define E_IS_TABLE_CLICK_TO_ADD(o) (GTK_CHECK_TYPE ((o), E_TABLE_CLICK_TO_ADD_TYPE)) -#define E_IS_TABLE_CLICK_TO_ADD_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_CLICK_TO_ADD_TYPE)) - -typedef struct { - GnomeCanvasGroup parent; - - ETableModel *one; /* The ETableOne. */ - - ETableModel *model; /* The backend model. */ - ETableHeader *eth; /* This is just to give to the ETableItem. */ - - char *message; - - GnomeCanvasItem *row; /* If row is NULL, we're sitting with no data and a "Click here" message. */ - GnomeCanvasItem *text; /* If text is NULL, row shouldn't be. */ - GnomeCanvasItem *rect; /* What the heck. Why not. */ - - gdouble width; - gdouble height; - - ETableSelectionModel *selection; -} ETableClickToAdd; - -typedef struct { - GnomeCanvasGroupClass parent_class; - - /* - * signals - */ - void (*cursor_change) (ETableClickToAdd *etcta, gint row, gint col); -} ETableClickToAddClass; - -GtkType e_table_click_to_add_get_type (void); - -void e_table_click_to_add_commit (ETableClickToAdd *etcta); - -END_GNOME_DECLS - -#endif /* _E_TABLE_CLICK_TO_ADD_H_ */ diff --git a/widgets/table/e-table-col-dnd.h b/widgets/table/e-table-col-dnd.h deleted file mode 100644 index 98b489b7c0..0000000000 --- a/widgets/table/e-table-col-dnd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _E_TABLE_COL_DND_H_ -#define _E_TABLE_COL_DND_H_ - -BEGIN_GNOME_DECLS - -#define TARGET_ETABLE_COL_TYPE "application/x-etable-column-header" - -enum { - TARGET_ETABLE_COL_HEADER -}; - -END_GNOME_DECLS - -#endif /* _E_TABLE_COL_DND_H_ */ diff --git a/widgets/table/e-table-col.c b/widgets/table/e-table-col.c deleted file mode 100644 index 38ae4a9b51..0000000000 --- a/widgets/table/e-table-col.c +++ /dev/null @@ -1,207 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-col.c: ETableCol implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc - */ -#include <config.h> -#include <gtk/gtkobject.h> -#include <gtk/gtksignal.h> -#include "e-table-col.h" -#include "gal/util/e-util.h" - -#define PARENT_TYPE (gtk_object_get_type ()) - -static GtkObjectClass *parent_class; - - -enum { - ARG_0, - ARG_SORTABLE, -}; - -static void -etc_destroy (GtkObject *object) -{ - ETableCol *etc = E_TABLE_COL (object); - - gtk_object_unref (GTK_OBJECT(etc->ecell)); - - if (etc->pixbuf) - gdk_pixbuf_unref (etc->pixbuf); - if (etc->text) - g_free (etc->text); - - (*parent_class->destroy)(object); -} - - -static void -etc_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableCol *etc = E_TABLE_COL (o); - - switch (arg_id){ - case ARG_SORTABLE: - etc->sortable = GTK_VALUE_BOOL(*arg); - break; - } -} - -static void -etc_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableCol *etc = E_TABLE_COL (o); - - switch (arg_id){ - case ARG_SORTABLE: - GTK_VALUE_BOOL(*arg) = etc->sortable; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_table_col_class_init (GtkObjectClass *object_class) -{ - parent_class = gtk_type_class (PARENT_TYPE); - object_class->destroy = etc_destroy; - object_class->get_arg = etc_get_arg; - object_class->set_arg = etc_set_arg; - - gtk_object_add_arg_type ("ETableCol::sortable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_SORTABLE); -} - -static void -e_table_col_init (ETableCol *etc) -{ - etc->width = 0; - etc->sortable = 1; - etc->groupable = 1; - etc->justification = GTK_JUSTIFY_LEFT; -} - -E_MAKE_TYPE(e_table_col, "ETableCol", ETableCol, e_table_col_class_init, e_table_col_init, PARENT_TYPE); - -/** - * e_table_col_new: - * @col_idx: the column we represent in the model - * @text: a title for this column - * @expansion: FIXME - * @min_width: minimum width in pixels for this column - * @ecell: the renderer to be used for this column - * @compare: comparision function for the elements stored in this column - * @resizable: whether the column can be resized interactively by the user - * - * The ETableCol represents a column to be used inside an ETable. The - * ETableCol objects are inserted inside an ETableHeader (which is just a collection - * of ETableCols). The ETableHeader is the definition of the order in which - * columns are shown to the user. - * - * The @text argument is the the text that will be shown as a header to the - * user. @col_idx reflects where the data for this ETableCol object will - * be fetch from an ETableModel. So even if the user changes the order - * of the columns being viewed (the ETableCols in the ETableHeader), the - * column will always point to the same column inside the ETableModel. - * - * The @ecell argument is an ECell object that needs to know how to render the - * data in the ETableModel for this specific row. - * - * Returns: the newly created ETableCol object. - */ -ETableCol * -e_table_col_new (int col_idx, const char *text, double expansion, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) -{ - ETableCol *etc; - - g_return_val_if_fail (expansion >= 0, NULL); - g_return_val_if_fail (min_width >= 0, NULL); - g_return_val_if_fail (ecell != NULL, NULL); - g_return_val_if_fail (compare != NULL, NULL); - g_return_val_if_fail (text != NULL, NULL); - - etc = gtk_type_new (E_TABLE_COL_TYPE); - - etc->is_pixbuf = FALSE; - - etc->col_idx = col_idx; - etc->text = g_strdup (text); - etc->pixbuf = NULL; - etc->expansion = expansion; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - - etc->selected = 0; - etc->resizeable = resizable; - - gtk_object_ref (GTK_OBJECT(etc->ecell)); - - return etc; -} - -/** - * e_table_col_new_with_pixbuf: - * @col_idx: the column we represent in the model - * @pixbuf: the image to be used for the header - * @expansion: FIXME - * @min_width: minimum width in pixels for this column - * @ecell: the renderer to be used for this column - * @compare: comparision function for the elements stored in this column - * @resizable: whether the column can be resized interactively by the user - * - * The ETableCol represents a column to be used inside an ETable. The - * ETableCol objects are inserted inside an ETableHeader (which is just a collection - * of ETableCols). The ETableHeader is the definition of the order in which - * columns are shown to the user. - * - * The @text argument is the the text that will be shown as a header to the - * user. @col_idx reflects where the data for this ETableCol object will - * be fetch from an ETableModel. So even if the user changes the order - * of the columns being viewed (the ETableCols in the ETableHeader), the - * column will always point to the same column inside the ETableModel. - * - * The @ecell argument is an ECell object that needs to know how to render the - * data in the ETableModel for this specific row. - * - * Returns: the newly created ETableCol object. - */ -ETableCol * -e_table_col_new_with_pixbuf (int col_idx, const char *text, GdkPixbuf *pixbuf, double expansion, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) -{ - ETableCol *etc; - - g_return_val_if_fail (expansion >= 0, NULL); - g_return_val_if_fail (min_width >= 0, NULL); - g_return_val_if_fail (ecell != NULL, NULL); - g_return_val_if_fail (compare != NULL, NULL); - g_return_val_if_fail (pixbuf != NULL, NULL); - - etc = gtk_type_new (E_TABLE_COL_TYPE); - - etc->is_pixbuf = TRUE; - - etc->col_idx = col_idx; - etc->text = g_strdup(text); - etc->pixbuf = pixbuf; - etc->expansion = expansion; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - - etc->selected = 0; - etc->resizeable = resizable; - - gtk_object_ref (GTK_OBJECT(etc->ecell)); - gdk_pixbuf_ref (etc->pixbuf); - - return etc; -} diff --git a/widgets/table/e-table-col.h b/widgets/table/e-table-col.h deleted file mode 100644 index 036b317d69..0000000000 --- a/widgets/table/e-table-col.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_COL_H_ -#define _E_TABLE_COL_H_ - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gal/e-table/e-cell.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_COL_TYPE (e_table_col_get_type ()) -#define E_TABLE_COL(o) (GTK_CHECK_CAST ((o), E_TABLE_COL_TYPE, ETableCol)) -#define E_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_COL_TYPE, ETableColClass)) -#define E_IS_TABLE_COL(o) (GTK_CHECK_TYPE ((o), E_TABLE_COL_TYPE)) -#define E_IS_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_COL_TYPE)) - -typedef enum { - E_TABLE_COL_ARROW_NONE = 0, - E_TABLE_COL_ARROW_UP, - E_TABLE_COL_ARROW_DOWN -} ETableColArrow; - -/* - * Information about a single column - */ -typedef struct { - GtkObject base; - char *text; - GdkPixbuf *pixbuf; - int min_width; - int width; - double expansion; - short x; - GCompareFunc compare; - unsigned int is_pixbuf:1; - unsigned int selected:1; - unsigned int resizeable:1; - unsigned int sortable:1; - unsigned int groupable:1; - int col_idx; - - GtkJustification justification; - - ECell *ecell; -} ETableCol; - -typedef struct { - GtkObjectClass parent_class; -} ETableColClass; - -GtkType e_table_col_get_type (void); -ETableCol *e_table_col_new (int col_idx, const char *text, - double expansion, int min_width, - ECell *ecell, GCompareFunc compare, - gboolean resizable); -ETableCol *e_table_col_new_with_pixbuf (int col_idx, const char *text, - GdkPixbuf *pixbuf, - double expansion, int min_width, - ECell *ecell, GCompareFunc compare, - gboolean resizable); -void e_table_col_destroy (ETableCol *etc); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* _E_TABLE_COL_H_ */ - diff --git a/widgets/table/e-table-column-specification.c b/widgets/table/e-table-column-specification.c deleted file mode 100644 index 68c19188b1..0000000000 --- a/widgets/table/e-table-column-specification.c +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-column-specification.c: Savable specification of a column. - * - * Author: - * Chris Lahey <clahey@ximian.com> - * - * (C) 2000 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> -#include "gal/util/e-xml-utils.h" -#include "gal/util/e-util.h" -#include "e-table-column-specification.h" - -#define PARENT_TYPE (gtk_object_get_type()) - -static GtkObjectClass *etcs_parent_class; - -static void -free_strings (ETableColumnSpecification *etcs) -{ - g_free(etcs->title); - g_free(etcs->pixbuf); - g_free(etcs->cell); - g_free(etcs->compare); -} - -static void -etcs_destroy (GtkObject *object) -{ - ETableColumnSpecification *etcs = E_TABLE_COLUMN_SPECIFICATION (object); - - free_strings(etcs); - - GTK_OBJECT_CLASS (etcs_parent_class)->destroy (object); -} - -static void -etcs_class_init (GtkObjectClass *klass) -{ - etcs_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etcs_destroy; -} - -static void -etcs_init (ETableColumnSpecification *specification) -{ - specification->model_col = 0; - specification->title = g_strdup(""); - specification->pixbuf = NULL; - - specification->expansion = 0; - specification->minimum_width = 0; - specification->resizable = FALSE; - - specification->cell = NULL; - specification->compare = NULL; -} - -E_MAKE_TYPE(e_table_column_specification, "ETableColumnSpecification", ETableColumnSpecification, etcs_class_init, etcs_init, PARENT_TYPE); - -ETableColumnSpecification * -e_table_column_specification_new (void) -{ - ETableColumnSpecification *etcs = gtk_type_new (E_TABLE_COLUMN_SPECIFICATION_TYPE); - - return (ETableColumnSpecification *) etcs; -} - -void -e_table_column_specification_load_from_node (ETableColumnSpecification *etcs, - const xmlNode *node) -{ - free_strings(etcs); - - etcs->model_col = e_xml_get_integer_prop_by_name(node, "model_col"); - etcs->title = e_xml_get_string_prop_by_name(node, "_title"); - etcs->pixbuf = e_xml_get_string_prop_by_name(node, "pixbuf"); - - etcs->expansion = e_xml_get_double_prop_by_name(node, "expansion"); - etcs->minimum_width = e_xml_get_integer_prop_by_name(node, "minimum_width"); - etcs->resizable = e_xml_get_bool_prop_by_name(node, "resizable"); - - etcs->cell = e_xml_get_string_prop_by_name(node, "cell"); - etcs->compare = e_xml_get_string_prop_by_name(node, "compare"); - - if (etcs->title == NULL) - etcs->title = g_strdup(""); -} - -xmlNode * -e_table_column_specification_save_to_node (ETableColumnSpecification *specification, - xmlNode *parent) -{ - xmlNode *node; - if (parent) - node = xmlNewChild(parent, NULL, "ETableColumn", NULL); - else - node = xmlNewNode(NULL, "ETableColumn"); - - e_xml_set_integer_prop_by_name(node, "model_col", specification->model_col); - e_xml_set_string_prop_by_name(node, "_title", specification->title); - e_xml_set_string_prop_by_name(node, "pixbuf", specification->pixbuf); - - e_xml_set_double_prop_by_name(node, "expansion", specification->expansion); - e_xml_set_integer_prop_by_name(node, "minimum_width", specification->minimum_width); - e_xml_set_bool_prop_by_name(node, "resizable", specification->resizable); - - e_xml_set_string_prop_by_name(node, "cell", specification->cell); - e_xml_set_string_prop_by_name(node, "compare", specification->compare); - - return node; -} - diff --git a/widgets/table/e-table-column-specification.h b/widgets/table/e-table-column-specification.h deleted file mode 100644 index ff334ec1b1..0000000000 --- a/widgets/table/e-table-column-specification.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_COLUMN_SPECIFICATION_H_ -#define _E_TABLE_COLUMN_SPECIFICATION_H_ - -#include <gtk/gtkobject.h> -#include <gnome-xml/tree.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_TABLE_COLUMN_SPECIFICATION_TYPE (e_table_column_specification_get_type ()) -#define E_TABLE_COLUMN_SPECIFICATION(o) (GTK_CHECK_CAST ((o), E_TABLE_COLUMN_SPECIFICATION_TYPE, ETableColumnSpecification)) -#define E_TABLE_COLUMN_SPECIFICATION_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_COLUMN_SPECIFICATION_TYPE, ETableColumnSpecificationClass)) -#define E_IS_TABLE_COLUMN_SPECIFICATION(o) (GTK_CHECK_TYPE ((o), E_TABLE_COLUMN_SPECIFICATION_TYPE)) -#define E_IS_TABLE_COLUMN_SPECIFICATION_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_COLUMN_SPECIFICATION_TYPE)) - -typedef struct { - GtkObject base; - int model_col; - char *title; - char *pixbuf; - - double expansion; - int minimum_width; - guint resizable : 1; - - char *cell; - char *compare; -} ETableColumnSpecification; - -typedef struct { - GtkObjectClass parent_class; -} ETableColumnSpecificationClass; - -GtkType e_table_column_specification_get_type (void); - -ETableColumnSpecification *e_table_column_specification_new (void); - -void e_table_column_specification_load_from_node (ETableColumnSpecification *state, - const xmlNode *node); -xmlNode *e_table_column_specification_save_to_node (ETableColumnSpecification *state, - xmlNode *parent); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_COLUMN_SPECIFICATION_H_ */ diff --git a/widgets/table/e-table-column.c b/widgets/table/e-table-column.c deleted file mode 100644 index a3d6201ffd..0000000000 --- a/widgets/table/e-table-column.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * e-table-column.c: TableColumn implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc - */ -#include <config.h> -#include "e-table-column.h" - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static guint etc_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_column_parent_class; - -static void -e_table_column_destroy (GtkObject *object) -{ - ETableColumn *etc = E_TABLE_COLUMN (object); - const int cols = etc->col_count; - - /* - * Destroy listeners - */ - for (l = etc->listeners; l; l = l->next) - g_free (l->data); - g_slist_free (etc->listeners); - etc->listeners = NULL; - - /* - * Destroy columns - */ - for (i = 0; i < cols; i++) - e_table_column_remove (etc, i); - - if (e_table_column_parent_class->destroy) - e_table_column_parent_class->destroy (object); -} - -static void -e_table_column_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = e_table_column_destroy; - - e_table_column_parent_class = (gtk_type_class (gtk_object_get_type ())); - - etc_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - etc_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, etc_signals, LAST_SIGNAL); -} - -GtkType -e_table_column_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableColumn", - sizeof (ETableColumn), - sizeof (ETableColumnClass), - (GtkClassInitFunc) e_table_column_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -static void -etc_do_insert (ETableColumn *etc, int pos, ETableCol *val) -{ - memcpy (&etc->columns [pos+1], &etc->columns [pos], - sizeof (ETableCol *) * (etc->col_count - pos)); - etc->columns [pos] = val; -} - -void -e_table_column_add_column (ETableColumn *etc, ETableCol *tc, int pos) -{ - ETableCol **new_ptr; - - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (tc != NULL); - g_return_if_fail (pos >= 0 && pos < etc->col_count); - - if (pos == -1) - pos = etc->col_count; - etc->columns = g_realloc (etc->columns, sizeof (ETableCol *) * (etc->col_count + 1)); - etc_do_insert (etc, pos, tc); - etc->col_count++; - - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -ETableCol * -e_table_column_get_column (ETableColumn *etc, int column) -{ - g_return_val_if_fail (etc != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), NULL); - - if (column < 0) - return NULL; - - if (column >= etc->col_count) - return NULL; - - return etc->columns [column]; -} - -int -e_table_column_count (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - return etc->col_count; -} - -int -e_table_column_index (ETableColumn *etc, const char *identifier) -{ - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - for (i = 0; i < etc->col_count; i++){ - ETableCol *tc = etc->columns [i]; - - if (strcmp (i->id, identifier) == 0) - return i; - } - - return -1; -} - -int -e_table_column_get_index_at (ETableColumn *etc, int x_offset) -{ - int i, total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - total = 0; - for (i = 0; i < etc->col_count; i++){ - total += etc->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_column_get_columns (ETableColumn *etc) -{ - ETableCol **ret; - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - ret = g_new (ETableCol *, etc->col_count + 1); - memcpy (ret, etc->columns, sizeof (ETableCol *) * etc->col_count); - ret [etc->col_count] = NULL; - - return ret; -} - -gboolean -e_table_column_selection_ok (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), FALSE); - - return etc->selectable; -} - -int -ve_table_column_get_selected (ETableColumn *etc) -{ - int i; - int selected = 0; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - for (i = 0; i < etc->col_count; i++){ - if (etc->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_column_total_width (ETableColumn *etc) -{ - int total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - total = 0; - for (i = 0; i < etc->col_count; i++) - total += etc->columns [i].width; - - return total; -} - -static void -etc_do_remove (ETableColumn *etc, int idx) -{ - memcpy (&etc->columns [idx], &etc->columns [idx+1], - sizeof (ETableCol *) * etc->col_count - idx); - etc->col_count--; -} - -void -e_table_column_move (ETableColumn *etc, int source_index, int target_index) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < etc->col_count); - g_return_if_fail (target_index < etc->col_count); - - old = etc->columns [source_index]; - etc_do_remove (etc, source_index); - etc_do_insert (etc, target_index, old); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_remove (ETableColumn *etc, int idx) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - - etc_do_remove (etc, idx); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_set_selection (ETableColumn *etc, gboolean allow_selection); -{ -} - -void -e_table_column_set_size (ETableColumn *etc, int idx, int size) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - g_return_if_fail (size > 0); - - etc->columns [idx]->width = size; - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [SIZE_CHANGE], idx); -} diff --git a/widgets/table/e-table-config-field.c b/widgets/table/e-table-config-field.c deleted file mode 100644 index d7f016f9c2..0000000000 --- a/widgets/table/e-table-config-field.c +++ /dev/null @@ -1,279 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-config-field.c: One field of either the sort or group dialog. - * - * Author: - * Chris Lahey <clahey@ximian.com> - * - * (C) 2000 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gnome.h> -#include "gal/util/e-util.h" -#include "e-table-config-field.h" - -#define PARENT_TYPE (gtk_vbox_get_type()) - -static GtkVBoxClass *etcf_parent_class; - -static void -etcf_destroy (GtkObject *object) -{ - ETableConfigField *etcf = E_TABLE_CONFIG_FIELD (object); - - gtk_object_unref(GTK_OBJECT(etcf->spec)); - gtk_object_unref(GTK_OBJECT(etcf->sort_info)); - - GTK_OBJECT_CLASS (etcf_parent_class)->destroy (object); -} - -static void -etcf_class_init (GtkObjectClass *klass) -{ - etcf_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etcf_destroy; -} - -static void -etcf_init (ETableConfigField *etcf) -{ - etcf->spec = NULL; - etcf->sort_info = NULL; - - etcf->combo = NULL; - etcf->radio_ascending = NULL; - etcf->radio_descending = NULL; - etcf->child_fields = NULL; -} - -E_MAKE_TYPE(e_table_config_field, "ETableConfigField", ETableConfigField, etcf_class_init, etcf_init, PARENT_TYPE); - -ETableConfigField * -e_table_config_field_new (ETableSpecification *spec, - ETableSortInfo *sort_info, - gboolean grouping) -{ - ETableConfigField *etcf = gtk_type_new (E_TABLE_CONFIG_FIELD_TYPE); - - e_table_config_field_construct (etcf, spec, sort_info, grouping); - - return (ETableConfigField *) etcf; -} - -inline static int -etcf_get_count (ETableConfigField *etcf) -{ - if (etcf->grouping) - return e_table_sort_info_grouping_get_count(etcf->sort_info); - else - return e_table_sort_info_sorting_get_count(etcf->sort_info); -} - -inline static ETableSortColumn -etcf_get_nth (ETableConfigField *etcf) -{ - if (etcf->grouping) - return e_table_sort_info_grouping_get_nth(etcf->sort_info, etcf->n); - else - return e_table_sort_info_sorting_get_nth(etcf->sort_info, etcf->n); -} - -inline static void -etcf_set_nth (ETableConfigField *etcf, ETableSortColumn column) -{ - if (etcf->grouping) - e_table_sort_info_grouping_set_nth(etcf->sort_info, etcf->n, column); - else - e_table_sort_info_sorting_set_nth(etcf->sort_info, etcf->n, column); -} - -inline static void -etcf_truncate (ETableConfigField *etcf) -{ - if (etcf->grouping) - e_table_sort_info_grouping_truncate(etcf->sort_info, etcf->n); - else - e_table_sort_info_sorting_truncate(etcf->sort_info, etcf->n); -} - -static void -etcf_set_sensitivity(ETableConfigField *etcf) -{ - int count = etcf_get_count(etcf); - - if (etcf->n >= count) { - gtk_widget_set_sensitive(etcf->radio_ascending, FALSE); - gtk_widget_set_sensitive(etcf->radio_descending, FALSE); - if (etcf->child_fields) - gtk_widget_set_sensitive(etcf->child_fields, FALSE); - } else { - gtk_widget_set_sensitive(etcf->radio_ascending, TRUE); - gtk_widget_set_sensitive(etcf->radio_descending, TRUE); - if (etcf->child_fields) - gtk_widget_set_sensitive(etcf->child_fields, TRUE); - } -} - -static void -toggled(GtkWidget *widget, ETableConfigField *etcf) -{ - int count; - - count = etcf_get_count(etcf); - if (count > etcf->n) { - ETableSortColumn sort_column; - - sort_column = etcf_get_nth(etcf); - sort_column.ascending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(etcf->radio_ascending)); - etcf_set_nth(etcf, sort_column); - } -} - -static void -changed(GtkWidget *widget, ETableConfigField *etcf) -{ - ETableColumnSpecification **column; - gchar *text; - - text = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry)); - for (column = etcf->spec->columns; *column; column++) { - if (!strcmp((*column)->title_, text)) { - ETableSortColumn sort_column; - - sort_column.ascending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(etcf->radio_ascending)); - sort_column.column = (*column)->model_col; - - etcf_set_nth(etcf, sort_column); - etcf_set_sensitivity(etcf); - return; - } - } - etcf_truncate(etcf); - etcf_set_sensitivity(etcf); -} - -static void -etcf_setup(ETableConfigField *etcf) -{ - int count; - GList *list = NULL; - ETableColumnSpecification **column; - ETableColumnSpecification *chosen_column = NULL; - int model_col = -1; - - etcf_set_sensitivity(etcf); - - count = etcf_get_count(etcf); - - if (count > etcf->n) { - ETableSortColumn sort_column; - - sort_column = etcf_get_nth(etcf); - model_col = sort_column.column; - if (sort_column.ascending) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(etcf->radio_ascending), TRUE); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(etcf->radio_descending), TRUE); - } - - for (column = etcf->spec->columns; *column; column++) { - list = g_list_prepend(list, (*column)->title_); - if (count > etcf->n && chosen_column == NULL && (*column)->model_col == model_col) { - chosen_column = *column; - } - } - list = g_list_reverse(list); - list = g_list_prepend(list, "None"); - - gtk_combo_set_popdown_strings(GTK_COMBO(etcf->combo), list); - g_list_free(list); - - if (chosen_column) { - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry), chosen_column->title_); - } else { - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry), "None"); - } - - gtk_signal_connect(GTK_OBJECT(GTK_COMBO(etcf->combo)->entry), "changed", - GTK_SIGNAL_FUNC(changed), etcf); - gtk_signal_connect(GTK_OBJECT(etcf->radio_ascending), "toggled", - GTK_SIGNAL_FUNC(toggled), etcf); - gtk_signal_connect(GTK_OBJECT(etcf->radio_descending), "toggled", - GTK_SIGNAL_FUNC(toggled), etcf); -} - -static ETableConfigField * -e_table_config_field_construct_nth (ETableConfigField *etcf, - ETableSpecification *spec, - ETableSortInfo *sort_info, - gboolean grouping, - int n) -{ - GtkWidget *frame; - GtkWidget *internal_hbox; - GtkWidget *internal_vbox1; - GtkWidget *internal_vbox2; - - etcf->spec = spec; - gtk_object_ref(GTK_OBJECT(spec)); - - etcf->sort_info = sort_info; - gtk_object_ref(GTK_OBJECT(sort_info)); - - etcf->grouping = grouping; - etcf->n = n; - - gtk_box_set_spacing(GTK_BOX(etcf), 6); - - frame = gtk_frame_new(n > 0 ? _("Then By") : (grouping ? _("Group By") : _("Sort By"))); - gtk_box_pack_start(GTK_BOX(etcf), frame, FALSE, FALSE, 0); - - internal_hbox = gtk_hbox_new(FALSE, 6); - gtk_container_add(GTK_CONTAINER(frame), internal_hbox); - gtk_container_set_border_width(GTK_CONTAINER(internal_hbox), 6); - - internal_vbox1 = gtk_vbox_new(FALSE, 6); - gtk_box_pack_start(GTK_BOX(internal_hbox), internal_vbox1, FALSE, FALSE, 0); - - etcf->combo = gtk_combo_new(); - gtk_box_pack_start(GTK_BOX(internal_vbox1), etcf->combo, FALSE, FALSE, 0); - - internal_vbox2 = gtk_vbox_new(FALSE, 6); - gtk_box_pack_start(GTK_BOX(internal_hbox), internal_vbox2, FALSE, FALSE, 0); - - etcf->radio_ascending = gtk_radio_button_new_with_label (NULL, _("Ascending")); - gtk_box_pack_start(GTK_BOX(internal_vbox2), etcf->radio_ascending, FALSE, FALSE, 0); - - etcf->radio_descending = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON(etcf->radio_ascending), _("Descending")); - gtk_box_pack_start(GTK_BOX(internal_vbox2), etcf->radio_descending, FALSE, FALSE, 0); - - if (n < 3) { - etcf->child_fields = GTK_WIDGET(gtk_type_new (E_TABLE_CONFIG_FIELD_TYPE)); - e_table_config_field_construct_nth(E_TABLE_CONFIG_FIELD(etcf->child_fields), spec, sort_info, grouping, n + 1); - gtk_box_pack_start(GTK_BOX(etcf), etcf->child_fields, FALSE, FALSE, 0); - gtk_widget_show(etcf->child_fields); - } else - etcf->child_fields = NULL; - - etcf_setup(etcf); - - gtk_widget_show(etcf->radio_descending); - gtk_widget_show(etcf->radio_ascending); - gtk_widget_show(internal_vbox2); - gtk_widget_show(etcf->combo); - gtk_widget_show(internal_vbox1); - gtk_widget_show(internal_hbox); - gtk_widget_show(frame); - return etcf; -} - -ETableConfigField * -e_table_config_field_construct (ETableConfigField *etcf, - ETableSpecification *spec, - ETableSortInfo *sort_info, - gboolean grouping) -{ - return e_table_config_field_construct_nth(etcf, spec, sort_info, grouping, 0); -} diff --git a/widgets/table/e-table-config-field.h b/widgets/table/e-table-config-field.h deleted file mode 100644 index 9df83238ee..0000000000 --- a/widgets/table/e-table-config-field.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_CONFIG_FIELD_H_ -#define _E_TABLE_CONFIG_FIELD_H_ - -#include <gtk/gtkvbox.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-specification.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_CONFIG_FIELD_TYPE (e_table_config_field_get_type ()) -#define E_TABLE_CONFIG_FIELD(o) (GTK_CHECK_CAST ((o), E_TABLE_CONFIG_FIELD_TYPE, ETableConfigField)) -#define E_TABLE_CONFIG_FIELD_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_CONFIG_FIELD_TYPE, ETableConfigFieldClass)) -#define E_IS_TABLE_CONFIG_FIELD(o) (GTK_CHECK_TYPE ((o), E_TABLE_CONFIG_FIELD_TYPE)) -#define E_IS_TABLE_CONFIG_FIELD_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_CONFIG_FIELD_TYPE)) - -typedef struct { - GtkVBox base; - - ETableSpecification *spec; - ETableSortInfo *sort_info; - guint grouping : 1; - int n; - - GtkWidget *combo; - GtkWidget *radio_ascending; - GtkWidget *radio_descending; - - GtkWidget *child_fields; -} ETableConfigField; - -typedef struct { - GtkVBoxClass parent_class; -} ETableConfigFieldClass; - -GtkType e_table_config_field_get_type (void); -ETableConfigField *e_table_config_field_new (ETableSpecification *spec, - ETableSortInfo *sort_info, - gboolean grouping); -ETableConfigField *e_table_config_field_construct (ETableConfigField *field, - ETableSpecification *spec, - ETableSortInfo *sort_info, - gboolean grouping); - -END_GNOME_DECLS - -#endif /* _E_TABLE_CONFIG_FIELD_H_ */ diff --git a/widgets/table/e-table-config.c b/widgets/table/e-table-config.c deleted file mode 100644 index f25e77245d..0000000000 --- a/widgets/table/e-table-config.c +++ /dev/null @@ -1,768 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-config.c: The ETable config dialog. - * - * Authors: - * Chris Lahey (clahey@ximian.com) - * Miguel de Icaza (miguel@ximian.com) - * - * FIXME: - * Sort Dialog: when text is selected, the toggle button switches state. - * Make Clear all work. - * - * (C) 2000, 2001 Ximian, Inc. - */ - -#include <config.h> -#include <stdlib.h> -#include "gal/util/e-i18n.h" -#include <libgnomeui/gnome-dialog.h> -#include <glade/glade.h> -#include "e-table-config.h" -#include "gal/util/e-util.h" - - -#define PARENT_TYPE (gtk_object_get_type()) - -static GtkObjectClass *config_parent_class; - -enum { - CHANGED, - LAST_SIGNAL -}; - -static guint e_table_config_signals [LAST_SIGNAL] = { 0, }; - -static void -config_destroy (GtkObject *object) -{ - ETableConfig *config = E_TABLE_CONFIG (object); - - gtk_object_destroy (GTK_OBJECT (config->state)); - gtk_object_unref (GTK_OBJECT (config->source_state)); - gtk_object_unref (GTK_OBJECT (config->source_spec)); - - g_slist_free (config->column_names); - config->column_names = NULL; - - GTK_OBJECT_CLASS (config_parent_class)->destroy (object); -} - -static void -e_table_config_changed (ETableConfig *config, ETableState *state) -{ - g_return_if_fail (config != NULL); - g_return_if_fail (E_IS_TABLE_CONFIG (config)); - - gtk_signal_emit(GTK_OBJECT(config), - e_table_config_signals [CHANGED], - state); -} - -static void -config_class_init (GtkObjectClass *object_class) -{ - ETableConfigClass *klass = E_TABLE_CONFIG_CLASS(object_class); - - config_parent_class = gtk_type_class (PARENT_TYPE); - - klass->changed = NULL; - - object_class->destroy = config_destroy; - - e_table_config_signals [CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableConfigClass, changed), - gtk_marshal_NONE__OBJECT, - GTK_TYPE_NONE, 1, E_TABLE_STATE_TYPE); - - gtk_object_class_add_signals (object_class, e_table_config_signals, LAST_SIGNAL); -} - -static ETableColumnSpecification * -find_column_in_spec (ETableSpecification *spec, int model_col) -{ - ETableColumnSpecification **column; - - for (column = spec->columns; *column; column++){ - if ((*column)->model_col != model_col) - continue; - - return *column; - } - - return NULL; -} - -static int -find_model_column_by_name (ETableSpecification *spec, const char *s) -{ - ETableColumnSpecification **column; - - for (column = spec->columns; *column; column++){ - - if (strcasecmp ((*column)->title, s) == 0) - return (*column)->model_col; - } - return -1; -} - -static void -update_sort_and_group_config_dialog (ETableConfig *config, gboolean is_sort) -{ - ETableConfigSortWidgets *widgets; - int count, i; - - if (is_sort){ - count = e_table_sort_info_sorting_get_count ( - config->temp_state->sort_info); - widgets = &config->sort [0]; - } else { - count = e_table_sort_info_grouping_get_count ( - config->temp_state->sort_info); - widgets = &config->group [0]; - } - - for (i = 0; i < 4; i++){ - gboolean sensitive = (i <= count); - - gtk_widget_set_sensitive (widgets [i].frames, sensitive); - - /* - * Sorting is set, auto select the text - */ - gtk_signal_handler_block ( - GTK_OBJECT (widgets [i].radio_ascending), - widgets [i].toggled_id); - - if (i < count){ - GtkToggleButton *a, *d; - ETableSortColumn col = - is_sort - ? e_table_sort_info_sorting_get_nth ( - config->temp_state->sort_info, - i) - : e_table_sort_info_grouping_get_nth ( - config->temp_state->sort_info, - i); - - ETableColumnSpecification *column = - find_column_in_spec (config->source_spec, col.column); - - if (!column){ - /* - * This is a bug in the programmer - * stuff, but by the time we arrive - * here, the user has been given a - * warning - */ - continue; - } - - /* - * Change the text - */ - gtk_signal_handler_block ( - GTK_OBJECT (widgets [i].combo->entry), - widgets [i].changed_id); - gtk_combo_text_set_text ( - widgets [i].combo, gettext ( - column->title)); - gtk_signal_handler_unblock ( - GTK_OBJECT (widgets [i].combo->entry), - widgets [i].changed_id); - - /* - * Update radio buttons - */ - a = GTK_TOGGLE_BUTTON ( - widgets [i].radio_ascending); - d = GTK_TOGGLE_BUTTON ( - widgets [i].radio_descending); - - gtk_toggle_button_set_active (col.ascending ? a:d, 1); - } else { - GtkToggleButton *t; - - t = GTK_TOGGLE_BUTTON ( - widgets [i].radio_ascending); - - gtk_toggle_button_set_active (t, 1); - } - gtk_signal_handler_unblock ( - GTK_OBJECT (widgets [i].radio_ascending), - widgets [i].toggled_id); - } -} - -static void -update_group_config_dialog (ETableConfig *config) -{ - g_warning ("IMPLEMENT ME\n"); -} - -static void -config_sort_info_update (ETableConfig *config) -{ - ETableSortInfo *info = config->state->sort_info; - GString *res; - int count, i; - - count = e_table_sort_info_sorting_get_count (info); - res = g_string_new (""); - - for (i = 0; i < count; i++) { - ETableSortColumn col = e_table_sort_info_sorting_get_nth (info, i); - ETableColumnSpecification *column; - - column = find_column_in_spec (config->source_spec, col.column); - if (!column){ - g_warning ("Could not find column model in specification"); - continue; - } - - g_string_append (res, gettext ((column)->title)); - g_string_append_c (res, ' '); - g_string_append ( - res, - col.ascending ? - _("(Ascending)") : _("(Descending)")); - - if ((i + 1) != count) - g_string_append (res, ", "); - } - - if (res->str [0] == 0) - g_string_append (res, _("Not sorted")); - - gtk_label_set_text (GTK_LABEL(config->sort_label), res->str); - - g_string_free (res, TRUE); -} - -static void -config_group_info_update (ETableConfig *config) -{ - ETableSortInfo *info = config->state->sort_info; - GString *res; - int count, i; - - count = e_table_sort_info_grouping_get_count (info); - printf ("Count of the grouping action: %d\n", count); - res = g_string_new (""); - - for (i = 0; i < count; i++) { - ETableSortColumn col = e_table_sort_info_grouping_get_nth (info, i); - ETableColumnSpecification *column; - - column = find_column_in_spec (config->source_spec, col.column); - if (!column){ - g_warning ("Could not find model column in specification"); - continue; - } - - g_string_append (res, gettext ((column)->title)); - g_string_append_c (res, ' '); - g_string_append ( - res, - col.ascending ? - _("(Ascending)") : _("(Descending)")); - - if ((i+1) != count) - g_string_append (res, ", "); - } - if (res->str [0] == 0) - g_string_append (res, _("No grouping")); - - gtk_label_set_text (GTK_LABEL (config->group_label), res->str); - g_string_free (res, TRUE); -} - -static void -config_fields_info_update (ETableConfig *config) -{ - ETableColumnSpecification **column; - GString *res = g_string_new (""); - int i; - - for (i = 0; i < config->state->col_count; i++){ - for (column = config->source_spec->columns; *column; column++){ - - if (config->state->columns [i] != (*column)->model_col) - continue; - - g_string_append (res, gettext ((*column)->title)); - if (column [1]) - g_string_append (res, ", "); - } - } - - gtk_label_set_text (GTK_LABEL (config->fields_label), res->str); - g_string_free (res, TRUE); -} - -static void -do_sort_and_group_config_dialog (ETableConfig *config, gboolean is_sort) -{ - GnomeDialog *dialog; - int button, running = 1; - - config->temp_state = e_table_state_duplicate (config->state); - - update_sort_and_group_config_dialog (config, is_sort); - - gtk_widget_grab_focus (GTK_WIDGET ( - is_sort - ? config->sort [0].combo - : config->group [0].combo)); - - - if (is_sort) - dialog = GNOME_DIALOG (config->dialog_sort); - else - dialog = GNOME_DIALOG (config->dialog_group_by); - - do { - button = gnome_dialog_run (dialog); - switch (button){ - case 0: - if (is_sort){ - e_table_sort_info_sorting_truncate ( - config->state->sort_info, 0); - } else { - e_table_sort_info_grouping_truncate ( - config->state->sort_info, 0); - } - update_sort_and_group_config_dialog (config, is_sort); - continue; - - /* OK */ - case 1: - gtk_object_unref (GTK_OBJECT (config->state)); - config->state = config->temp_state; - running = 0; - gnome_property_box_changed ( - GNOME_PROPERTY_BOX (config->dialog_toplevel)); - break; - - /* CANCEL */ - case 2: - gtk_object_unref (GTK_OBJECT (config->temp_state)); - config->temp_state = 0; - running = 0; - break; - } - - } while (running); - gnome_dialog_close (GNOME_DIALOG (dialog)); - - if (is_sort) - config_sort_info_update (config); - else - config_group_info_update (config); -} - -static void -config_button_sort (GtkWidget *widget, ETableConfig *config) -{ - do_sort_and_group_config_dialog (config, TRUE); -} - -static void -config_button_group (GtkWidget *widget, ETableConfig *config) -{ - do_sort_and_group_config_dialog (config, FALSE); -} - - -static void -dialog_destroyed (GtkObject *dialog, ETableConfig *config) -{ - gtk_object_destroy (GTK_OBJECT (config)); -} - -static void -dialog_apply (GnomePropertyBox *pbox, gint page_num, ETableConfig *config) -{ - if (page_num != -1) - return; - - e_table_config_changed (config, config->state); -} - -/* - * Invoked by the Glade auto-connect code - */ -GtkWidget *e_table_proxy_gtk_combo_text_new (void); -GtkWidget * -e_table_proxy_gtk_combo_text_new (void) -{ - return gtk_combo_text_new (TRUE); -} - -#if 0 -static GtkWidget * -configure_dialog (GladeXML *gui, const char *widget_name, ETableConfig *config) -{ - GtkWidget *w; - - w = glade_xml_get_widget (gui, widget_name); - - return w; -} -#endif - -static void -connect_button (ETableConfig *config, GladeXML *gui, const char *widget_name, void *cback) -{ - GtkWidget *button = glade_xml_get_widget (gui, widget_name); - - gtk_signal_connect( - GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (cback), config); -} - -static void -sort_entry_changed (GtkEntry *entry, ETableConfigSortWidgets *sort) -{ - ETableConfig *config = sort->e_table_config; - ETableSortInfo *sort_info = config->temp_state->sort_info; - ETableConfigSortWidgets *base = &config->sort[0]; - int idx = sort - base; - - char *s = gtk_entry_get_text (entry); - - if (g_hash_table_lookup (sort->combo->elements, s)){ - ETableSortColumn c; - int col; - - col = find_model_column_by_name (config->source_spec, s); - if (col == -1){ - g_warning ("This should not happen"); - return; - } - - c.ascending = GTK_TOGGLE_BUTTON ( - config->sort [idx].radio_ascending)->active; - c.column = col; - e_table_sort_info_sorting_set_nth (sort_info, idx, c); - - update_sort_and_group_config_dialog (config, TRUE); - } else { - e_table_sort_info_sorting_truncate (sort_info, idx); - update_sort_and_group_config_dialog (config, TRUE); - } -} - -static void -sort_ascending_toggled (GtkToggleButton *t, ETableConfigSortWidgets *sort) -{ - ETableConfig *config = sort->e_table_config; - ETableSortInfo *si = config->temp_state->sort_info; - ETableConfigSortWidgets *base = &config->sort[0]; - int idx = sort - base; - ETableSortColumn c; - - c = e_table_sort_info_sorting_get_nth (si, idx); - c.ascending = t->active; - e_table_sort_info_sorting_set_nth (si, idx, c); -} - -static void -configure_sort_dialog (ETableConfig *config, GladeXML *gui) -{ - GSList *l; - int i; - - for (i = 0; i < 4; i++){ - char buffer [80]; - - snprintf (buffer, sizeof (buffer), "sort-combo-%d", i + 1); - config->sort [i].combo = GTK_COMBO_TEXT ( - glade_xml_get_widget (gui, buffer)); - - gtk_combo_text_add_item (config->sort [i].combo, "", ""); - - snprintf (buffer, sizeof (buffer), "frame-sort-%d", i + 1); - config->sort [i].frames = - glade_xml_get_widget (gui, buffer); - - snprintf ( - buffer, sizeof (buffer), - "radiobutton-ascending-sort-%d", i+1); - config->sort [i].radio_ascending = glade_xml_get_widget ( - gui, buffer); - - snprintf ( - buffer, sizeof (buffer), - "radiobutton-descending-sort-%d", i+1); - config->sort [i].radio_descending = glade_xml_get_widget ( - gui, buffer); - - config->sort [i].e_table_config = config; - } - - for (l = config->column_names; l; l = l->next){ - char *label = l->data; - - for (i = 0; i < 4; i++){ - gtk_combo_text_add_item ( - config->sort [i].combo, - gettext (label), label); - } - } - - /* - * After we have runtime modified things, signal connect - */ - for (i = 0; i < 4; i++){ - config->sort [i].changed_id = gtk_signal_connect ( - GTK_OBJECT (config->sort [i].combo->entry), - "changed", sort_entry_changed, &config->sort [i]); - - config->sort [i].toggled_id = gtk_signal_connect ( - GTK_OBJECT (config->sort [i].radio_ascending), - "toggled", sort_ascending_toggled, &config->sort [i]); - } -} - -static void -group_entry_changed (GtkEntry *entry, ETableConfigSortWidgets *group) -{ - ETableConfig *config = group->e_table_config; - ETableSortInfo *sort_info = config->temp_state->sort_info; - ETableConfigSortWidgets *base = &config->group[0]; - int idx = group - base; - - char *s = gtk_entry_get_text (entry); - - if (g_hash_table_lookup (group->combo->elements, s)){ - ETableSortColumn c; - int col; - - col = find_model_column_by_name (config->source_spec, s); - if (col == -1){ - g_warning ("This should not happen"); - return; - } - - c.ascending = GTK_TOGGLE_BUTTON ( - config->group [idx].radio_ascending)->active; - c.column = col; - e_table_sort_info_grouping_set_nth (sort_info, idx, c); - - update_group_config_dialog (config); - } else { - e_table_sort_info_grouping_truncate (sort_info, idx); - update_group_config_dialog (config); - } -} - -static void -group_ascending_toggled (GtkToggleButton *t, ETableConfigSortWidgets *group) -{ - ETableConfig *config = group->e_table_config; - ETableSortInfo *si = config->temp_state->sort_info; - ETableConfigSortWidgets *base = &config->group[0]; - int idx = group - base; - ETableSortColumn c; - - c = e_table_sort_info_grouping_get_nth (si, idx); - c.ascending = t->active; - e_table_sort_info_grouping_set_nth (si, idx, c); -} - -static void -configure_group_dialog (ETableConfig *config, GladeXML *gui) -{ - GSList *l; - int i; - - for (i = 0; i < 4; i++){ - char buffer [80]; - - snprintf (buffer, sizeof (buffer), "group-combo-%d", i + 1); - config->group [i].combo = GTK_COMBO_TEXT ( - glade_xml_get_widget (gui, buffer)); - - gtk_combo_text_add_item (config->group [i].combo, "", ""); - - snprintf (buffer, sizeof (buffer), "frame-group-%d", i + 1); - config->group [i].frames = - glade_xml_get_widget (gui, buffer); - - snprintf ( - buffer, sizeof (buffer), - "radiobutton-ascending-group-%d", i+1); - config->group [i].radio_ascending = glade_xml_get_widget ( - gui, buffer); - - snprintf ( - buffer, sizeof (buffer), - "radiobutton-descending-group-%d", i+1); - config->group [i].radio_descending = glade_xml_get_widget ( - gui, buffer); - - snprintf ( - buffer, sizeof (buffer), - "checkbutton-group-%d", i+1); - config->group [i].view_check = glade_xml_get_widget ( - gui, buffer); - - config->group [i].e_table_config = config; - } - - - for (l = config->column_names; l; l = l->next){ - char *label = l->data; - - for (i = 0; i < 4; i++){ - gtk_combo_text_add_item ( - config->group [i].combo, - gettext (label), label); - } - } - - /* - * After we have runtime modified things, signal connect - */ - for (i = 0; i < 4; i++){ - config->group [i].changed_id = gtk_signal_connect ( - GTK_OBJECT (config->group [i].combo->entry), - "changed", group_entry_changed, &config->group [i]); - - config->group [i].toggled_id = gtk_signal_connect ( - GTK_OBJECT (config->group [i].radio_ascending), - "toggled", group_ascending_toggled, &config->group [i]); - } -} - -static void -setup_gui (ETableConfig *config) -{ - GladeXML *gui = glade_xml_new ( - ETABLE_GLADEDIR "/e-table-config.glade", NULL); - - config->dialog_toplevel = glade_xml_get_widget ( - gui, "e-table-config"); - - gtk_notebook_set_show_tabs ( - GTK_NOTEBOOK (GNOME_PROPERTY_BOX ( - config->dialog_toplevel)->notebook), - FALSE); - - config->dialog_show_fields = glade_xml_get_widget ( - gui, "dialog-show-fields"); - config->dialog_group_by = glade_xml_get_widget ( - gui, "dialog-group-by"); - config->dialog_sort = glade_xml_get_widget ( - gui, "dialog-sort"); - - config->sort_label = glade_xml_get_widget ( - gui, "label-sort"); - config->group_label = glade_xml_get_widget ( - gui, "label-group"); - config->fields_label = glade_xml_get_widget ( - gui, "label-fields"); - - connect_button (config, gui, "button-sort", config_button_sort); - connect_button (config, gui, "button-group", config_button_group); - - configure_sort_dialog (config, gui); - configure_group_dialog (config, gui); - - gtk_signal_connect ( - GTK_OBJECT (config->dialog_toplevel), "destroy", - GTK_SIGNAL_FUNC (dialog_destroyed), config); - - gtk_signal_connect ( - GTK_OBJECT (config->dialog_toplevel), "apply", - GTK_SIGNAL_FUNC (dialog_apply), config); - - gtk_object_unref (GTK_OBJECT (gui)); -} - -static void -config_init (ETableConfig *config) -{ - glade_gnome_init (); -} - -ETableConfig * -e_table_config_construct (ETableConfig *config, - const char *header, - ETableSpecification *spec, - ETableState *state) -{ - ETableColumnSpecification **column; - - g_return_val_if_fail (config != NULL, NULL); - g_return_val_if_fail (header != NULL, NULL); - g_return_val_if_fail (spec != NULL, NULL); - g_return_val_if_fail (state != NULL, NULL); - - config->source_spec = spec; - config->source_state = state; - - gtk_object_ref (GTK_OBJECT (config->source_spec)); - gtk_object_ref (GTK_OBJECT (config->source_state)); - - config->state = e_table_state_duplicate (state); - - for (column = config->source_spec->columns; *column; column++){ - char *label = (*column)->title; - - config->column_names = g_slist_append ( - config->column_names, label); - } - - setup_gui (config); - - config_sort_info_update (config); - config_group_info_update (config); - config_fields_info_update (config); - - return E_TABLE_CONFIG (config); -} - -/** - * e_table_config_new: - * @header: The title of the dialog for the ETableConfig. - * @spec: The specification for the columns to allow. - * @state: The current state of the configuration. - * - * Creates a new ETable config object. - * - * Returns: The config object. - */ -ETableConfig * -e_table_config_new (const char *header, - ETableSpecification *spec, - ETableState *state) -{ - ETableConfig *config = gtk_type_new (E_TABLE_CONFIG_TYPE); - - if (e_table_config_construct (config, header, spec, state) == NULL){ - gtk_object_destroy (GTK_OBJECT (config)); - return NULL; - } - - gtk_widget_show (config->dialog_toplevel); - return E_TABLE_CONFIG (config); -} - -/** - * e_table_config_raise: - * @config: The ETableConfig object. - * - * Raises the dialog associated with this ETableConfig object. - */ -void -e_table_config_raise (ETableConfig *config) -{ - gdk_window_raise (GTK_WIDGET (config->dialog_toplevel)->window); -} - -E_MAKE_TYPE(e_table_config, "ETableConfig", ETableConfig, config_class_init, config_init, PARENT_TYPE); diff --git a/widgets/table/e-table-config.glade b/widgets/table/e-table-config.glade deleted file mode 100644 index e0035daf67..0000000000 --- a/widgets/table/e-table-config.glade +++ /dev/null @@ -1,1866 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <name>E-table</name> - <program_name>e-table</program_name> - <directory></directory> - <source_directory></source_directory> - <pixmaps_directory></pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>False</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <backup_source_files>True</backup_source_files> - <main_source_file>interface.c</main_source_file> - <main_header_file>interface.h</main_header_file> - <handler_source_file>callbacks.c</handler_source_file> - <handler_header_file>callbacks.h</handler_header_file> - <support_source_file>support.c</support_source_file> - <support_header_file>support.h</support_header_file> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-config.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GnomeDialog</class> - <name>dialog-show-fields</name> - <visible>False</visible> - <title>Show Fields</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - <auto_close>False</auto_close> - <hide_on_close>False</hide_on_close> - - <widget> - <class>GtkVBox</class> - <child_name>GnomeDialog:vbox</child_name> - <name>dialog-vbox3</name> - <homogeneous>False</homogeneous> - <spacing>8</spacing> - <child> - <padding>4</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkVBox</class> - <name>vbox2</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkTable</class> - <name>table2</name> - <rows>1</rows> - <columns>5</columns> - <homogeneous>True</homogeneous> - <row_spacing>6</row_spacing> - <column_spacing>6</column_spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>label-available</name> - <label>A_vailable Fields:</label> - <justify>GTK_JUSTIFY_LEFT</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <focus_target>table-1</focus_target> - <child> - <left_attach>0</left_attach> - <right_attach>2</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label-displayed</name> - <label>Sh_ow these fields in order:</label> - <justify>GTK_JUSTIFY_LEFT</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <focus_target>table-2</focus_target> - <child> - <left_attach>3</left_attach> - <right_attach>5</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - </widget> - - <widget> - <class>GtkTable</class> - <name>table3</name> - <rows>1</rows> - <columns>5</columns> - <homogeneous>True</homogeneous> - <row_spacing>6</row_spacing> - <column_spacing>6</column_spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkVBox</class> - <name>vbox4</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - <child> - <left_attach>0</left_attach> - <right_attach>2</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>True</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow1</name> - <hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkViewport</class> - <name>viewport1</name> - <shadow_type>GTK_SHADOW_IN</shadow_type> - - <widget> - <class>GtkButton</class> - <name>table-1</name> - <can_focus>True</can_focus> - <label>Table HERE</label> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox5</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - <child> - <left_attach>3</left_attach> - <right_attach>5</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>True</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow2</name> - <hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkViewport</class> - <name>viewport2</name> - <shadow_type>GTK_SHADOW_IN</shadow_type> - - <widget> - <class>GtkButton</class> - <name>table-2</name> - <can_focus>True</can_focus> - <label>Table HERE</label> - </widget> - </widget> - </widget> - - <widget> - <class>GtkHBox</class> - <name>hbox4</name> - <homogeneous>True</homogeneous> - <spacing>6</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkButton</class> - <name>button-up</name> - <can_focus>True</can_focus> - <label>Move _Up</label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-down</name> - <can_focus>True</can_focus> - <label>Move _Down</label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - </widget> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox6</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - <child> - <left_attach>2</left_attach> - <right_attach>3</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>True</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkButton</class> - <name>button-add</name> - <can_focus>True</can_focus> - <label>_Add -></label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-remove</name> - <can_focus>True</can_focus> - <label><- _Remove</label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>Placeholder</class> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkHButtonBox</class> - <child_name>GnomeDialog:action_area</child_name> - <name>dialog-action_area3</name> - <layout_style>GTK_BUTTONBOX_END</layout_style> - <spacing>8</spacing> - <child_min_width>85</child_min_width> - <child_min_height>27</child_min_height> - <child_ipad_x>7</child_ipad_x> - <child_ipad_y>0</child_ipad_y> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - <pack>GTK_PACK_END</pack> - </child> - - <widget> - <class>GtkButton</class> - <name>button20</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_OK</stock_button> - </widget> - - <widget> - <class>GtkButton</class> - <name>button22</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button> - </widget> - </widget> - </widget> -</widget> - -<widget> - <class>GnomeDialog</class> - <name>dialog-group-by</name> - <visible>False</visible> - <title>Group</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - <auto_close>False</auto_close> - <hide_on_close>False</hide_on_close> - - <widget> - <class>GtkVBox</class> - <child_name>GnomeDialog:vbox</child_name> - <name>dialog-vbox4</name> - <homogeneous>False</homogeneous> - <spacing>8</spacing> - <child> - <padding>4</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkVBox</class> - <name>vbox24</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox13</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkFrame</class> - <name>frame-group-1</name> - <label>Group Items By</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox5</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - - <widget> - <class>GtkVBox</class> - <name>vbox7</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>group-combo-1</name> - <creation_function>e_table_proxy_gtk_combo_text_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Fri, 19 Jan 2001 04:52:09 GMT</last_modification_time> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkCheckButton</class> - <name>checkbutton-group-1</name> - <can_focus>True</can_focus> - <label>Show field in View</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox8</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-ascending-group-1</name> - <can_focus>True</can_focus> - <label>Ascending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-1</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-descending-group-1</name> - <can_focus>True</can_focus> - <label>Descending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-1</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label8</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label9</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label10</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - - <widget> - <class>GtkHBox</class> - <name>hbox14</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>label11</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame-group-2</name> - <label>Then By</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox6</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - - <widget> - <class>GtkVBox</class> - <name>vbox9</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>group-combo-2</name> - <creation_function>e_table_proxy_gtk_combo_text_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Fri, 19 Jan 2001 04:52:14 GMT</last_modification_time> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkCheckButton</class> - <name>checkbutton-group-2</name> - <can_focus>True</can_focus> - <label>Show field in View</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox10</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-ascending-group-2</name> - <can_focus>True</can_focus> - <label>Ascending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-2</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-descending-group-2</name> - <can_focus>True</can_focus> - <label>Descending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-2</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label19</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label18</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - - <widget> - <class>GtkHBox</class> - <name>hbox15</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>label13</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label12</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame-group-3</name> - <label>Then By</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox7</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - - <widget> - <class>GtkVBox</class> - <name>vbox11</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>group-combo-3</name> - <creation_function>e_table_proxy_gtk_combo_text_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Fri, 19 Jan 2001 04:52:18 GMT</last_modification_time> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkCheckButton</class> - <name>checkbutton-group-3</name> - <can_focus>True</can_focus> - <label>Show field in View</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox12</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-ascending-group-3</name> - <can_focus>True</can_focus> - <label>Ascending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-3</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-descending-group-3</name> - <can_focus>True</can_focus> - <label>Descending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-3</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label17</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - - <widget> - <class>GtkHBox</class> - <name>hbox16</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>label14</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label16</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label15</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame-group-4</name> - <label>Then By</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox8</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - - <widget> - <class>GtkVBox</class> - <name>vbox13</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>group-combo-4</name> - <creation_function>e_table_proxy_gtk_combo_text_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Fri, 19 Jan 2001 04:52:21 GMT</last_modification_time> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkCheckButton</class> - <name>checkbutton-group-4</name> - <can_focus>True</can_focus> - <label>Show field in View</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox14</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-ascending-group-4</name> - <can_focus>True</can_focus> - <label>Ascending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-4</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-descending-group-4</name> - <can_focus>True</can_focus> - <label>Descending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-4</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkHButtonBox</class> - <child_name>GnomeDialog:action_area</child_name> - <name>dialog-action_area4</name> - <layout_style>GTK_BUTTONBOX_END</layout_style> - <spacing>8</spacing> - <child_min_width>85</child_min_width> - <child_min_height>27</child_min_height> - <child_ipad_x>7</child_ipad_x> - <child_ipad_y>0</child_ipad_y> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - <pack>GTK_PACK_END</pack> - </child> - - <widget> - <class>GtkButton</class> - <name>button39</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <label>Clear All</label> - </widget> - - <widget> - <class>GtkButton</class> - <name>button41</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_OK</stock_button> - </widget> - - <widget> - <class>GtkButton</class> - <name>button42</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button> - </widget> - </widget> - </widget> -</widget> - -<widget> - <class>GnomeDialog</class> - <name>dialog-sort</name> - <visible>False</visible> - <title>Sort</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - <auto_close>False</auto_close> - <hide_on_close>True</hide_on_close> - - <widget> - <class>GtkVBox</class> - <child_name>GnomeDialog:vbox</child_name> - <name>vbox15</name> - <homogeneous>False</homogeneous> - <spacing>8</spacing> - <child> - <padding>4</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkTable</class> - <name>table5</name> - <rows>4</rows> - <columns>1</columns> - <homogeneous>False</homogeneous> - <row_spacing>6</row_spacing> - <column_spacing>6</column_spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkFrame</class> - <name>frame-sort-4</name> - <label>Then By</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>3</top_attach> - <bottom_attach>4</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox9</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - - <widget> - <class>GtkAlignment</class> - <name>alignment1</name> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xscale>1</xscale> - <yscale>0</yscale> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>sort-combo-4</name> - <creation_function>e_table_proxy_gtk_combo_text_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Tue, 16 Jan 2001 08:33:52 GMT</last_modification_time> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox17</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-ascending-sort-4</name> - <can_focus>True</can_focus> - <label>Ascending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-4</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-descending-sort-4</name> - <can_focus>True</can_focus> - <label>Descending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-4</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame-sort-3</name> - <label>Then By</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>2</top_attach> - <bottom_attach>3</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox10</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - - <widget> - <class>GtkAlignment</class> - <name>alignment2</name> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xscale>1</xscale> - <yscale>0</yscale> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>sort-combo-3</name> - <creation_function>e_table_proxy_gtk_combo_text_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Tue, 16 Jan 2001 05:22:22 GMT</last_modification_time> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox19</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-ascending-sort-3</name> - <can_focus>True</can_focus> - <label>Ascending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-3</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-descending-sort-3</name> - <can_focus>True</can_focus> - <label>Descending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-3</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame-sort-2</name> - <label>Then By</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>1</top_attach> - <bottom_attach>2</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox11</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - - <widget> - <class>GtkAlignment</class> - <name>alignment3</name> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xscale>1</xscale> - <yscale>0</yscale> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>sort-combo-2</name> - <creation_function>e_table_proxy_gtk_combo_text_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Tue, 16 Jan 2001 05:22:15 GMT</last_modification_time> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox21</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-ascending-sort-2</name> - <can_focus>True</can_focus> - <label>Ascending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-2</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-descending-sort-2</name> - <can_focus>True</can_focus> - <label>Descending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-2</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame-sort-1</name> - <label>Sort Items By</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkHBox</class> - <name>hbox12</name> - <homogeneous>False</homogeneous> - <spacing>6</spacing> - - <widget> - <class>GtkAlignment</class> - <name>alignment4</name> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xscale>1</xscale> - <yscale>0</yscale> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>sort-combo-1</name> - <can_focus>True</can_focus> - <has_focus>True</has_focus> - <creation_function>e_table_proxy_gtk_combo_text_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Tue, 16 Jan 2001 05:22:00 GMT</last_modification_time> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox23</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-ascending-sort-1</name> - <can_focus>True</can_focus> - <label>Ascending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-1</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkRadioButton</class> - <name>radiobutton-descending-sort-1</name> - <can_focus>True</can_focus> - <label>Descending</label> - <active>False</active> - <draw_indicator>True</draw_indicator> - <group>group-1</group> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkHButtonBox</class> - <child_name>GnomeDialog:action_area</child_name> - <name>hbuttonbox1</name> - <layout_style>GTK_BUTTONBOX_END</layout_style> - <spacing>8</spacing> - <child_min_width>85</child_min_width> - <child_min_height>27</child_min_height> - <child_ipad_x>7</child_ipad_x> - <child_ipad_y>0</child_ipad_y> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - <pack>GTK_PACK_END</pack> - </child> - - <widget> - <class>GtkButton</class> - <name>button43</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <label>Clear All</label> - </widget> - - <widget> - <class>GtkButton</class> - <name>button44</name> - <can_default>True</can_default> - <has_default>True</has_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_OK</stock_button> - </widget> - - <widget> - <class>GtkButton</class> - <name>button45</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button> - </widget> - </widget> - </widget> -</widget> - -<widget> - <class>GnomePropertyBox</class> - <name>e-table-config</name> - - <widget> - <class>GtkNotebook</class> - <child_name>GnomePropertyBox:notebook</child_name> - <name>notebook1</name> - <show_tabs>False</show_tabs> - <show_border>True</show_border> - <tab_pos>GTK_POS_TOP</tab_pos> - <scrollable>False</scrollable> - <tab_hborder>2</tab_hborder> - <tab_vborder>2</tab_vborder> - <popup_enable>False</popup_enable> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkFrame</class> - <name>top-frame</name> - <border_width>2</border_width> - <label>Description</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - - <widget> - <class>GtkTable</class> - <name>table1</name> - <border_width>2</border_width> - <rows>3</rows> - <columns>3</columns> - <homogeneous>False</homogeneous> - <row_spacing>2</row_spacing> - <column_spacing>4</column_spacing> - - <widget> - <class>GtkLabel</class> - <name>label2</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>2</left_attach> - <right_attach>3</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label3</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>2</left_attach> - <right_attach>3</right_attach> - <top_attach>1</top_attach> - <bottom_attach>2</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label4</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>2</left_attach> - <right_attach>3</right_attach> - <top_attach>2</top_attach> - <bottom_attach>3</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button15</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <signal> - <name>clicked</name> - <handler>on_fields_clicked</handler> - <last_modification_time>Tue, 03 Oct 2000 22:11:12 GMT</last_modification_time> - </signal> - <label>_Fields...</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-sort</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <signal> - <name>clicked</name> - <handler>on_sort_clicked</handler> - <last_modification_time>Tue, 03 Oct 2000 22:10:58 GMT</last_modification_time> - </signal> - <label>_Sort...</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>2</top_attach> - <bottom_attach>3</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-group</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <signal> - <name>clicked</name> - <handler>on_group_by_clicked</handler> - <last_modification_time>Tue, 03 Oct 2000 22:10:50 GMT</last_modification_time> - </signal> - <label>_Group By...</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>1</top_attach> - <bottom_attach>2</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label-group</name> - <label></label> - <justify>GTK_JUSTIFY_LEFT</justify> - <wrap>True</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>1</top_attach> - <bottom_attach>2</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label-sort</name> - <label></label> - <justify>GTK_JUSTIFY_LEFT</justify> - <wrap>True</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>2</top_attach> - <bottom_attach>3</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label-fields</name> - <label></label> - <justify>GTK_JUSTIFY_LEFT</justify> - <wrap>True</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - </widget> - </widget> - - <widget> - <class>GtkLabel</class> - <child_name>Notebook:tab</child_name> - <name>label20</name> - <label>label20</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/table/e-table-config.glade.h b/widgets/table/e-table-config.glade.h deleted file mode 100644 index 4218ce256a..0000000000 --- a/widgets/table/e-table-config.glade.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("Show Fields"); -gchar *s = N_("A_vailable Fields:"); -gchar *s = N_("Sh_ow these fields in order:"); -gchar *s = N_("Table HERE"); -gchar *s = N_("Table HERE"); -gchar *s = N_("Move _Up"); -gchar *s = N_("Move _Down"); -gchar *s = N_("_Add ->"); -gchar *s = N_("<- _Remove"); -gchar *s = N_("Group"); -gchar *s = N_("Group Items By"); -gchar *s = N_("Show field in View"); -gchar *s = N_("Ascending"); -gchar *s = N_("Descending"); -gchar *s = N_("Then By"); -gchar *s = N_("Show field in View"); -gchar *s = N_("Ascending"); -gchar *s = N_("Descending"); -gchar *s = N_("Then By"); -gchar *s = N_("Show field in View"); -gchar *s = N_("Ascending"); -gchar *s = N_("Descending"); -gchar *s = N_("Then By"); -gchar *s = N_("Show field in View"); -gchar *s = N_("Ascending"); -gchar *s = N_("Descending"); -gchar *s = N_("Clear All"); -gchar *s = N_("Sort"); -gchar *s = N_("Then By"); -gchar *s = N_("Ascending"); -gchar *s = N_("Descending"); -gchar *s = N_("Then By"); -gchar *s = N_("Ascending"); -gchar *s = N_("Descending"); -gchar *s = N_("Then By"); -gchar *s = N_("Ascending"); -gchar *s = N_("Descending"); -gchar *s = N_("Sort Items By"); -gchar *s = N_("Ascending"); -gchar *s = N_("Descending"); -gchar *s = N_("Clear All"); -gchar *s = N_("Description"); -gchar *s = N_("_Fields..."); -gchar *s = N_("_Sort..."); -gchar *s = N_("_Group By..."); -gchar *s = N_("label20"); diff --git a/widgets/table/e-table-config.h b/widgets/table/e-table-config.h deleted file mode 100644 index 28eb8600e2..0000000000 --- a/widgets/table/e-table-config.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_CONFIG_H_ -#define _E_TABLE_CONFIG_H_ - -#include <gnome.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-specification.h> -#include <gal/widgets/gtk-combo-text.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_CONFIG_TYPE (e_table_config_get_type ()) -#define E_TABLE_CONFIG(o) (GTK_CHECK_CAST ((o), E_TABLE_CONFIG_TYPE, ETableConfig)) -#define E_TABLE_CONFIG_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_CONFIG_TYPE, ETableConfigClass)) -#define E_IS_TABLE_CONFIG(o) (GTK_CHECK_TYPE ((o), E_TABLE_CONFIG_TYPE)) -#define E_IS_TABLE_CONFIG_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_CONFIG_TYPE)) - -typedef struct { - GtkComboText *combo; - GtkWidget *frames; - GtkWidget *radio_ascending; - GtkWidget *radio_descending; - GtkWidget *view_check; /* Only for group dialog */ - guint changed_id, toggled_id; - void *e_table_config; -} ETableConfigSortWidgets; - - -typedef struct { - GtkObject parent; - - /* - * Our various dialog boxes - */ - GtkWidget *dialog_toplevel; - GtkWidget *dialog_show_fields; - GtkWidget *dialog_group_by; - GtkWidget *dialog_sort; - - /* - * The state we manipulate - */ - ETableSpecification *source_spec; - ETableState *source_state, *state, *temp_state; - - GtkWidget *sort_label; - GtkWidget *group_label; - GtkWidget *fields_label; - - ETableConfigSortWidgets sort [4]; - ETableConfigSortWidgets group [4]; - - /* - * List of valid column names - */ - GSList *column_names; -} ETableConfig; - -typedef struct { - GtkObjectClass parent_class; - - /* Signals */ - void (*changed) (ETableConfig *config); -} ETableConfigClass; - -GtkType e_table_config_get_type (void); -ETableConfig *e_table_config_new (const char *header, - ETableSpecification *spec, - ETableState *state); -ETableConfig *e_table_config_construct (ETableConfig *etco, - const char *header, - ETableSpecification *spec, - ETableState *state); -void e_table_config_raise (ETableConfig *config); - -END_GNOME_DECLS - -#endif /* _E_TABLE_CONFIG_H */ diff --git a/widgets/table/e-table-defines.h b/widgets/table/e-table-defines.h deleted file mode 100644 index 6c01e17a69..0000000000 --- a/widgets/table/e-table-defines.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __E_TABLE_DEFINES__ -#define __E_TABLE_DEFINES__ 1 - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define BUTTON_HEIGHT 10 -#define BUTTON_PADDING 2 -#define GROUP_INDENT (BUTTON_HEIGHT + (BUTTON_PADDING * 2)) - -/* Padding around the contents of a header button */ -#define HEADER_PADDING 1 - -#define MIN_ARROW_SIZE 10 - -typedef void (*ETableForeachFunc) (int model_row, - gpointer closure); - -/* list selection modes */ -typedef enum -{ - E_TABLE_CURSOR_LINE, - E_TABLE_CURSOR_SIMPLE, - E_TABLE_CURSOR_SPREADSHEET, -} ETableCursorMode; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif diff --git a/widgets/table/e-table-example-1.c b/widgets/table/e-table-example-1.c deleted file mode 100644 index a3be8dedd0..0000000000 --- a/widgets/table/e-table-example-1.c +++ /dev/null @@ -1,287 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "gal/e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "table-test.h" - -/* - * One way in which we make it simpler to build an ETableModel is through - * the ETableSimple class. Instead of creating your own ETableModel - * class, you simply create a new object of the ETableSimple class. You - * give it a bunch of functions that act as callbacks. - * - * You also get to pass a void * to ETableSimple and it gets passed to - * your callbacks. This would be for having multiple models of the same - * type. This is just an example though, so we statically define all the - * data and ignore the void *data parameter. - * - * In our example we will be creating a table model with 6 columns and 10 - * rows. This corresponds to having 6 different types of information and - * 10 different sets of data in our database. - * - * The headers will be hard coded, as will be the example data. - * - */ - -/* - * There are two different meanings to the word "column". The first is - * the model column. A model column corresponds to a specific type of - * data. This is very much like the usage in a database table where a - * column is a field in the database. - * - * The second type of column is a view column. A view column - * corresponds to a visually displayed column. Each view column - * corresponds to a specific model column, though a model column may - * have any number of view columns associated with it, from zero to - * greater than one. - * - * Also, a view column doesn't necessarily depend on only one model - * column. In some cases, the view column renderer can be given a - * reference to another column to get extra information about its - * display. -*/ - -#define ROWS 10 -#define COLS 4 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* - * Here we define the initial layout of the table. This is an xml - * format that allows you to change the initial ordering of the - * columns or to do sorting or grouping initially. This specification - * shows all 5 columns, but moves the importance column nearer to the - * front. It also sorts by the "Full Name" column (ascending.) - * Sorting and grouping take the model column as their arguments - * (sorting is specified by the "column" argument to the leaf elemnt. - */ - -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"true\"/> </grouping> \ -</ETableSpecification>" - -char *headers [COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* - * Virtual Column list: - * 0 Email - * 1 Full Name - * 2 Address - * 3 Phone - */ - -char *table_data [ROWS] [COLS]; - -/* - * ETableSimple 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 number of rows in our ETableModel. */ -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -/* This function returns the value at a particular point in our ETableModel. */ -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - return (void *) table_data [row] [col]; -} - -/* This function sets the value at a particular point in our ETableModel. */ -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_free (table_data [row] [col]); - table_data [row] [col] = g_strdup (val); -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -/* This function duplicates the value passed to it. */ -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -/* This function frees the value passed to it. */ -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -/* This function creates an empty value. */ -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -/* This function reports if a value is empty. */ -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -/* This function reports if a value is empty. */ -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -/* We create a window containing our new table. */ -static void -create_table (void) -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ETableHeader *e_table_header; - int i, j; - ETableModel *e_table_model = NULL; - - /* First we fill in the simple data. */ - for (i = 0; i < ROWS; i++){ - for (j = 0; j < COLS; j++) - table_data [i] [j] = g_strdup (""); - } - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - * Next we create a header. The ETableHeader is used in two - * different way. The first is the full_header. This is the - * list of possible columns in the view. The second use is - * completely internal. Many of the ETableHeader functions are - * for that purpose. The only functions we really need are - * e_table_header_new and e_table_header_add_col. - * - * First we create the header. - */ - e_table_header = e_table_header_new (); - - /* - * Next we have to build renderers for all of the columns. - * Since all our columns are text columns, we can simply use - * the same renderer over and over again. If we had different - * types of columns, we could use a different renderer for - * each column. - */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* - * Next we create a column object for each view column and add - * them to the header. We don't create a column object for - * the importance column since it will not be shown. - */ - for (i = 0; i < COLS; i++) { - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Here we create a window for our new table. This window - * will get shown and the person will be able to test their - * item. - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - - /* - * Here we create the table. We give it the three pieces of - * the table we've created, the header, the model, and the - * initial layout. It does the rest. - */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 200, 200); - - /* Show it all. */ - gtk_widget_show_all (window); -} - -/* This is the main function which just initializes gnome and call our create_table function */ - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} - diff --git a/widgets/table/e-table-example-2.c b/widgets/table/e-table-example-2.c deleted file mode 100644 index dcc7e244a1..0000000000 --- a/widgets/table/e-table-example-2.c +++ /dev/null @@ -1,330 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "gal/e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "table-test.h" - -/* -One way in which we make it simpler to build an ETableModel is through -the ETableSimple class. Instead of creating your own ETableModel -class, you simply create a new object of the ETableSimple class. You -give it a bunch of functions that act as callbacks. - -You also get to pass a void * to ETableSimple and it gets passed to -your callbacks. This would be for having multiple models of the same -type. This is just an example though, so we statically define all the -data and ignore the void *data parameter. - -In our example we will be creating a table model with 6 columns and 10 -rows. This corresponds to having 6 different types of information and -10 different sets of data in our database. - -The headers will be hard coded, as will be the example data. - -*/ - -/* - There are two different meanings to the word "column". The first is - the model column. A model column corresponds to a specific type of - data. This is very much like the usage in a database table where a - column is a field in the database. - - The second type of column is a view column. A view column - corresponds to a visually displayed column. Each view column - corresponds to a specific model column, though a model column may - have any number of view columns associated with it, from zero to - greater than one. - - Also, a view column doesn't necessarily depend on only one model - column. In some cases, the view column renderer can be given a - reference to another column to get extra information about its - display. -*/ - -#define ROWS 10 -#define VIEW_COLS 4 -#define PHYSICAL_COLS 5 -#define VIRTUAL_COLS 6 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* Here we define the initial layout of the table. This is an xml - format that allows you to change the initial ordering of the - columns or to do sorting or grouping initially. This specification - shows all 5 columns, but moves the importance column nearer to the - front. It also sorts by the "Full Name" column (ascending.) - Sorting and grouping take the model column as their arguments - (sorting is specified by the "column" argument to the leaf elemnt. */ -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"true\"/> </grouping> \ -</ETableSpecification>" - -char *headers[VIEW_COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* Virtual Column list: - 0 Full Name - 1 Email - 2 Address - 3 Phone - 4 Importance field. This field will be a boolean. It also has a - special header, so doesn't appear in the headers list. - 5 Color field. This column is also not displayed. It is also - not stored in the database. It's calculated based on the - Importance field. -*/ - -char *table_data[ROWS][VIEW_COLS]; -gboolean importance_data[ROWS]; - -/* - * ETableSimple 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. */ - -static GdkColor *color1; -static GdkColor *color2; - -static int -my_col_count (ETableModel *etc, void *data) -{ - return VIRTUAL_COLS; -} - -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - if (col == COLOR_COLUMN){ - if (importance_data[row]){ - return color1; - } else { - return color2; - } - } else if (col == IMPORTANCE_COLUMN){ - return (gpointer) importance_data[row]; - } else { - return (void *) table_data [row][col]; - } -} - -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - importance_data[row] = (gboolean) val; - } else { - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - } -} - -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - if (col == IMPORTANCE_COLUMN) - return FALSE; - else - return TRUE; -} - -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return (void *) value; - } else if (col == IMPORTANCE_COLUMN){ - return (void *) value; - } else { - return g_strdup (value); - } -} - -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - } else { - g_free (value); - } -} - -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == COLOR_COLUMN){ - return NULL; - } else if (col == IMPORTANCE_COLUMN){ - return NULL; - } else { - return g_strdup (""); - } -} - -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return value == NULL; - } else if (col == IMPORTANCE_COLUMN){ - return value == NULL; - } else { - return !(value && *(char *)value); - } -} - -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return g_strdup_printf("%d", (int) value); - } else if (col == IMPORTANCE_COLUMN){ - return g_strdup_printf("%d", (int) value); - } else { - return g_strdup(value); - } -} - -/* We create a window containing our new table. */ -static void -create_table () -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ECell *cell_checkbox; - ETableHeader *e_table_header; - int i, j; - ETableModel *e_table_model = NULL; - ETableCol *ecol; - GdkPixbuf *pixbuf; - - /* First we fill in the simple data. */ - for (i = 0; i < ROWS; i++){ - for (j = 0; j < VIEW_COLS; j++){ - table_data[i][j] = g_strdup (""); - } - importance_data[i] = FALSE; - } - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - Next we create a header. The ETableHeader is used in two - different way. The first is the full_header. This is the - list of possible columns in the view. The second use is - completely internal. Many of the ETableHeader functions are - for that purpose. The only functions we really need are - e_table_header_new and e_table_header_add_col. - - First we create the header. */ - e_table_header = e_table_header_new (); - - /* Next we have to build renderers for all of the columns. - Since all our columns are text columns, we can simply use - the same renderer over and over again. If we had different - types of columns, we could use a different renderer for - each column. */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* Next we create a column object for each view column and add - them to the header. We don't create a column object for - the importance column since it will not be shown. */ - for (i = 0; i < VIEW_COLS; i++){ - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* Next we add a special column for the check box. */ - - cell_checkbox = e_cell_checkbox_new (); - pixbuf = gdk_pixbuf_new_from_file ("clip.png"); - ecol = e_table_col_new_with_pixbuf (i, pixbuf, 0.0, 18, cell_checkbox, g_int_compare, TRUE); - e_table_header_add_column (e_table_header, ecol, i); - - /* - * Setup GUI - */ - /* Here we create a window for our new table. This window - will get shown and the person will be able to test their - item. */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - /* Here we create the table. We give it the three pieces of - the table we've created, the header, the model, and the - initial layout. It does the rest. */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 200, 200); - /* Show it all. */ - gtk_widget_show_all (window); -} - - - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} diff --git a/widgets/table/e-table-extras.c b/widgets/table/e-table-extras.c deleted file mode 100644 index 6135839994..0000000000 --- a/widgets/table/e-table-extras.c +++ /dev/null @@ -1,176 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-extras.c: Pair of hash table sort of thingies. - * - * Author: - * Chris Lahey <clahey@ximian.com> - * - * (C) 2000 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#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-number.h" -#include "gal/e-table/e-cell-size.h" -#include "gal/e-table/e-cell-tree.h" -#include "e-table-extras.h" - -#define PARENT_TYPE (gtk_object_get_type()) - -static GtkObjectClass *ete_parent_class; - -static void -cell_hash_free(gchar *key, - ECell *cell, - gpointer user_data) -{ - g_free(key); - if (cell) - gtk_object_unref( GTK_OBJECT (cell)); -} - -static void -pixbuf_hash_free(gchar *key, - GdkPixbuf *pixbuf, - gpointer user_data) -{ - g_free(key); - if (pixbuf) - gdk_pixbuf_unref(pixbuf); -} - -static void -ete_destroy (GtkObject *object) -{ - ETableExtras *ete = E_TABLE_EXTRAS (object); - - g_hash_table_foreach (ete->cells, (GHFunc) cell_hash_free, NULL); - g_hash_table_foreach (ete->compares, (GHFunc) g_free, NULL); - g_hash_table_foreach (ete->pixbufs, (GHFunc) pixbuf_hash_free, NULL); - - g_hash_table_destroy (ete->cells); - g_hash_table_destroy (ete->compares); - g_hash_table_destroy (ete->pixbufs); - - ete->cells = NULL; - ete->compares = NULL; - ete->pixbufs = NULL; - - GTK_OBJECT_CLASS (ete_parent_class)->destroy (object); -} - -static void -ete_class_init (GtkObjectClass *klass) -{ - ete_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = ete_destroy; -} - -static void -ete_init (ETableExtras *extras) -{ - extras->cells = g_hash_table_new(g_str_hash, g_str_equal); - extras->compares = g_hash_table_new(g_str_hash, g_str_equal); - extras->pixbufs = g_hash_table_new(g_str_hash, g_str_equal); - - e_table_extras_add_compare(extras, "string", g_str_compare); - 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, "number", e_cell_number_new (NULL, GTK_JUSTIFY_RIGHT)); - e_table_extras_add_cell(extras, "size", e_cell_size_new (NULL, GTK_JUSTIFY_RIGHT)); - 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))); -} - -E_MAKE_TYPE(e_table_extras, "ETableExtras", ETableExtras, ete_class_init, ete_init, PARENT_TYPE); - -ETableExtras * -e_table_extras_new (void) -{ - ETableExtras *ete = gtk_type_new (E_TABLE_EXTRAS_TYPE); - - return (ETableExtras *) ete; -} - -void -e_table_extras_add_cell (ETableExtras *extras, - char *id, - ECell *cell) -{ - gchar *old_key; - ECell *old_cell; - - if (g_hash_table_lookup_extended (extras->cells, id, (gpointer *)&old_key, (gpointer *)&old_cell)) { - g_free (old_key); - if (old_cell) - gtk_object_unref (GTK_OBJECT(old_cell)); - } - - if (cell) { - gtk_object_ref (GTK_OBJECT (cell)); - gtk_object_sink (GTK_OBJECT (cell)); - } - g_hash_table_insert (extras->cells, g_strdup(id), cell); -} - -ECell * -e_table_extras_get_cell (ETableExtras *extras, - char *id) -{ - return g_hash_table_lookup(extras->cells, id); -} - -void -e_table_extras_add_compare (ETableExtras *extras, - char *id, - GCompareFunc compare) -{ - gchar *old_key; - GCompareFunc old_compare; - - if (g_hash_table_lookup_extended (extras->cells, id, (gpointer *)&old_key, (gpointer *)&old_compare)) { - g_free (old_key); - } - - g_hash_table_insert(extras->compares, g_strdup(id), compare); -} - -GCompareFunc -e_table_extras_get_compare (ETableExtras *extras, - char *id) -{ - return g_hash_table_lookup(extras->compares, id); -} - -void -e_table_extras_add_pixbuf (ETableExtras *extras, - char *id, - GdkPixbuf *pixbuf) -{ - gchar *old_key; - GdkPixbuf *old_pixbuf; - - if (g_hash_table_lookup_extended (extras->pixbufs, id, (gpointer *)&old_key, (gpointer *)&old_pixbuf)) { - g_free (old_key); - if (old_pixbuf) - gdk_pixbuf_unref (old_pixbuf); - } - - if (pixbuf) - gdk_pixbuf_ref(pixbuf); - g_hash_table_insert (extras->pixbufs, g_strdup(id), pixbuf); -} - -GdkPixbuf * -e_table_extras_get_pixbuf (ETableExtras *extras, - char *id) -{ - return g_hash_table_lookup(extras->pixbufs, id); -} diff --git a/widgets/table/e-table-extras.h b/widgets/table/e-table-extras.h deleted file mode 100644 index d39fe9066f..0000000000 --- a/widgets/table/e-table-extras.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_EXTRAS_H_ -#define _E_TABLE_EXTRAS_H_ - -#include <gtk/gtkobject.h> -#include <gal/e-table/e-cell.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_EXTRAS_TYPE (e_table_extras_get_type ()) -#define E_TABLE_EXTRAS(o) (GTK_CHECK_CAST ((o), E_TABLE_EXTRAS_TYPE, ETableExtras)) -#define E_TABLE_EXTRAS_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_EXTRAS_TYPE, ETableExtrasClass)) -#define E_IS_TABLE_EXTRAS(o) (GTK_CHECK_TYPE ((o), E_TABLE_EXTRAS_TYPE)) -#define E_IS_TABLE_EXTRAS_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_EXTRAS_TYPE)) - -typedef struct { - GtkObject base; - - GHashTable *cells; - GHashTable *compares; - GHashTable *pixbufs; -} ETableExtras; - -typedef struct { - GtkObjectClass parent_class; -} ETableExtrasClass; - -GtkType e_table_extras_get_type (void); -ETableExtras *e_table_extras_new (void); - -void e_table_extras_add_cell (ETableExtras *extras, - char *id, - ECell *cell); -ECell *e_table_extras_get_cell (ETableExtras *extras, - char *id); - -void e_table_extras_add_compare (ETableExtras *extras, - char *id, - GCompareFunc compare); -GCompareFunc e_table_extras_get_compare (ETableExtras *extras, - char *id); - -void e_table_extras_add_pixbuf (ETableExtras *extras, - char *id, - GdkPixbuf *pixbuf); -GdkPixbuf *e_table_extras_get_pixbuf (ETableExtras *extras, - char *id); - -END_GNOME_DECLS - -#endif /* _E_TABLE_EXTRAS_H_ */ diff --git a/widgets/table/e-table-field-chooser-dialog.c b/widgets/table/e-table-field-chooser-dialog.c deleted file mode 100644 index 216c582753..0000000000 --- a/widgets/table/e-table-field-chooser-dialog.c +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-field-chooser-dialog.c - * Copyright (C) 2000 Ximian, Inc. - * Author: Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU 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 <config.h> -#include <gnome.h> -#include "e-table-field-chooser-dialog.h" - -static void e_table_field_chooser_dialog_init (ETableFieldChooserDialog *card); -static void e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *klass); -static void e_table_field_chooser_dialog_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_dialog_destroy (GtkObject *object); -static void e_table_field_chooser_dialog_clicked (GnomeDialog *dialog, gint button); - -static GnomeDialogClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_DND_CODE, - ARG_FULL_HEADER, -}; - -GtkType -e_table_field_chooser_dialog_get_type (void) -{ - static GtkType table_field_chooser_dialog_type = 0; - - if (!table_field_chooser_dialog_type) - { - static const GtkTypeInfo table_field_chooser_dialog_info = - { - "ETableFieldChooserDialog", - sizeof (ETableFieldChooserDialog), - sizeof (ETableFieldChooserDialogClass), - (GtkClassInitFunc) e_table_field_chooser_dialog_class_init, - (GtkObjectInitFunc) e_table_field_chooser_dialog_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - table_field_chooser_dialog_type = gtk_type_unique (gnome_dialog_get_type (), &table_field_chooser_dialog_info); - } - - return table_field_chooser_dialog_type; -} - -static void -e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *klass) -{ - GtkObjectClass *object_class; - GnomeDialogClass *dialog_class; - - object_class = (GtkObjectClass*) klass; - dialog_class = GNOME_DIALOG_CLASS (klass); - - parent_class = gtk_type_class (gnome_dialog_get_type ()); - - object_class->destroy = e_table_field_chooser_dialog_destroy; - object_class->set_arg = e_table_field_chooser_dialog_set_arg; - object_class->get_arg = e_table_field_chooser_dialog_get_arg; - - dialog_class->clicked = e_table_field_chooser_dialog_clicked; - - gtk_object_add_arg_type ("ETableFieldChooserDialog::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooserDialog::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); -} - -static void -e_table_field_chooser_dialog_init (ETableFieldChooserDialog *e_table_field_chooser_dialog) -{ - GtkWidget *widget; - - e_table_field_chooser_dialog->etfc = NULL; - e_table_field_chooser_dialog->dnd_code = g_strdup(""); - e_table_field_chooser_dialog->full_header = NULL; - - gnome_dialog_append_buttons(GNOME_DIALOG(e_table_field_chooser_dialog), - GNOME_STOCK_BUTTON_CLOSE, - NULL); - - gtk_window_set_policy(GTK_WINDOW(e_table_field_chooser_dialog), FALSE, TRUE, FALSE); - - widget = e_table_field_chooser_new(); - e_table_field_chooser_dialog->etfc = E_TABLE_FIELD_CHOOSER(widget); - - gtk_object_set(GTK_OBJECT(widget), - "dnd_code", e_table_field_chooser_dialog->dnd_code, - "full_header", e_table_field_chooser_dialog->full_header, - NULL); - - gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(e_table_field_chooser_dialog)->vbox), - widget, TRUE, TRUE, 0); - - gtk_widget_show(GTK_WIDGET(widget)); -} - -GtkWidget* -e_table_field_chooser_dialog_new (void) -{ - GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_table_field_chooser_dialog_get_type ())); - return widget; -} - -static void -e_table_field_chooser_dialog_destroy (GtkObject *object) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object); - g_free(etfcd->dnd_code); - if (etfcd->full_header) - gtk_object_unref(GTK_OBJECT(etfcd->full_header)); -} - -static void -e_table_field_chooser_dialog_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG(object); - switch (arg_id){ - case ARG_DND_CODE: - g_free(etfcd->dnd_code); - etfcd->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - if (etfcd->etfc) - gtk_object_set(GTK_OBJECT(etfcd->etfc), - "dnd_code", etfcd->dnd_code, - NULL); - break; - case ARG_FULL_HEADER: - if (etfcd->full_header) - gtk_object_unref(GTK_OBJECT(etfcd->full_header)); - if (GTK_VALUE_OBJECT(*arg)) - etfcd->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT(*arg)); - else - etfcd->full_header = NULL; - if (etfcd->full_header) - gtk_object_ref(GTK_OBJECT(etfcd->full_header)); - if (etfcd->etfc) - gtk_object_set(GTK_OBJECT(etfcd->etfc), - "full_header", etfcd->full_header, - NULL); - break; - default: - break; - } -} - -static void -e_table_field_chooser_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG(object); - switch (arg_id) { - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfcd->dnd_code); - break; - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etfcd->full_header); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_table_field_chooser_dialog_clicked (GnomeDialog *dialog, int button) -{ - if (button == 0) - gnome_dialog_close(dialog); -} diff --git a/widgets/table/e-table-field-chooser-dialog.h b/widgets/table/e-table-field-chooser-dialog.h deleted file mode 100644 index 502db6f473..0000000000 --- a/widgets/table/e-table-field-chooser-dialog.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-table-field-chooser-dialog.h - * Copyright (C) 2000 Ximian, Inc. - * Author: Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU 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_TABLE_FIELD_CHOOSER_DIALOG_H__ -#define __E_TABLE_FIELD_CHOOSER_DIALOG_H__ - -#include <gnome.h> -#include <gal/e-table/e-table-field-chooser.h> -#include <gal/e-table/e-table-header.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETableFieldChooserDialog - A dialog displaying information about a contact. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - */ - -#define E_TABLE_FIELD_CHOOSER_DIALOG_TYPE (e_table_field_chooser_dialog_get_type ()) -#define E_TABLE_FIELD_CHOOSER_DIALOG(obj) (GTK_CHECK_CAST ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE, ETableFieldChooserDialog)) -#define E_TABLE_FIELD_CHOOSER_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE, ETableFieldChooserDialogClass)) -#define E_IS_TABLE_FIELD_CHOOSER_DIALOG(obj) (GTK_CHECK_TYPE ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE)) - - -typedef struct _ETableFieldChooserDialog ETableFieldChooserDialog; -typedef struct _ETableFieldChooserDialogClass ETableFieldChooserDialogClass; - -struct _ETableFieldChooserDialog -{ - GnomeDialog parent; - - /* item specific fields */ - ETableFieldChooser *etfc; - gchar *dnd_code; - ETableHeader *full_header; -}; - -struct _ETableFieldChooserDialogClass -{ - GnomeDialogClass parent_class; -}; - - -GtkWidget *e_table_field_chooser_dialog_new(void); -GtkType e_table_field_chooser_dialog_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TABLE_FIELD_CHOOSER_DIALOG_H__ */ diff --git a/widgets/table/e-table-field-chooser-item.c b/widgets/table/e-table-field-chooser-item.c deleted file mode 100644 index 2241f5e29f..0000000000 --- a/widgets/table/e-table-field-chooser-item.c +++ /dev/null @@ -1,560 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-column-view.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Ximian, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkdnd.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-polygon.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "gal/util/e-xml-utils.h" -#include "gal/widgets/e-canvas.h" - -#include "e-table-header.h" -#include "e-table-col-dnd.h" -#include "e-table-defines.h" -#include "e-table-header-utils.h" - -#include "e-table-field-chooser-item.h" - -#if 0 -enum { - BUTTON_PRESSED, - LAST_SIGNAL -}; - -static guint etfci_signals [LAST_SIGNAL] = { 0, }; -#endif - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasItemClass *etfci_parent_class; - -static void etfci_drop_table_header (ETableFieldChooserItem *etfci); - -enum { - ARG_0, - ARG_FULL_HEADER, - ARG_DND_CODE, - ARG_WIDTH, - ARG_HEIGHT, -}; - -static void -etfci_destroy (GtkObject *object){ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (object); - - etfci_drop_table_header (etfci); - - gdk_font_unref(etfci->font); - - if (GTK_OBJECT_CLASS (etfci_parent_class)->destroy) - (*GTK_OBJECT_CLASS (etfci_parent_class)->destroy) (object); -} - -static gint -etfci_find_button (ETableFieldChooserItem *etfci, double loc) -{ - int i; - int count; - double height = 0; - GtkStyle *style; - - style = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas)->style; - - count = e_table_header_count(etfci->full_header); - for (i = 0; i < count; i++) { - ETableCol *ecol; - - ecol = e_table_header_get_column (etfci->full_header, i); - height += e_table_header_compute_height (ecol, style, etfci->font); - if (height > loc) - return i; - } - return MAX(0, count - 1); -} - -static void -etfci_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - double old_height; - int i; - int count; - double height = 0; - GtkStyle *style; - - style = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas)->style; - - old_height = etfci->height; - - count = e_table_header_count(etfci->full_header); - for (i = 0; i < count; i++) { - ETableCol *ecol; - - ecol = e_table_header_get_column (etfci->full_header, i); - height += e_table_header_compute_height (ecol, style, etfci->font); - } - - etfci->height = height; - - if (old_height != etfci->height) - e_canvas_item_request_parent_reflow(item); - - gnome_canvas_item_request_update(item); -} - -static void -etfci_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - double i2c [6]; - ArtPoint c1, c2, i1, i2; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->update)(item, affine, clip_path, flags); - - i1.x = i1.y = 0; - i2.x = etfci->width; - i2.y = etfci->height; - - gnome_canvas_item_i2c_affine (item, i2c); - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - if (item->x1 != c1.x || - item->y1 != c1.y || - item->x2 != c2.x || - item->y2 != c2.y) - { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - item->x1 = c1.x; - item->y1 = c1.y; - item->x2 = c2.x; - item->y2 = c2.y; - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); - } - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); -} - -static void -etfci_font_load (ETableFieldChooserItem *etfci, char *font) -{ - if (etfci->font) - gdk_font_unref (etfci->font); - etfci->font = NULL; - - if (font) - etfci->font = gdk_fontset_load (font); - - if (etfci->font == NULL) { - etfci->font = GTK_WIDGET(GNOME_CANVAS_ITEM(etfci)->canvas)->style->font; - gdk_font_ref(etfci->font); - } -} - -static void -etfci_drop_table_header (ETableFieldChooserItem *etfci) -{ - GtkObject *header; - - if (!etfci->full_header) - return; - - header = GTK_OBJECT (etfci->full_header); - if (etfci->structure_change_id) - gtk_signal_disconnect (header, etfci->structure_change_id); - if (etfci->dimension_change_id) - gtk_signal_disconnect (header, etfci->dimension_change_id); - etfci->structure_change_id = 0; - etfci->dimension_change_id = 0; - - if (header) - gtk_object_unref (header); - etfci->full_header = NULL; - etfci->height = 0; - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -structure_changed (ETableHeader *header, ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -dimension_changed (ETableHeader *header, int col, ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_add_table_header (ETableFieldChooserItem *etfci, ETableHeader *header) -{ - etfci->full_header = header; - gtk_object_ref (GTK_OBJECT (etfci->full_header)); - - etfci->structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC(structure_changed), etfci); - etfci->dimension_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC(dimension_changed), etfci); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableFieldChooserItem *etfci; - - item = GNOME_CANVAS_ITEM (o); - etfci = E_TABLE_FIELD_CHOOSER_ITEM (o); - - switch (arg_id){ - case ARG_FULL_HEADER: - etfci_drop_table_header (etfci); - if (GTK_VALUE_OBJECT (*arg)) - etfci_add_table_header (etfci, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_DND_CODE: - g_free(etfci->dnd_code); - etfci->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - break; - - case ARG_WIDTH: - etfci->width = GTK_VALUE_DOUBLE (*arg); - gnome_canvas_item_request_update(item); - break; - } -} - -static void -etfci_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableFieldChooserItem *etfci; - - item = GNOME_CANVAS_ITEM (o); - etfci = E_TABLE_FIELD_CHOOSER_ITEM (o); - - switch (arg_id){ - - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfci->dnd_code); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etfci->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etfci->height; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etfci_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETableFieldChooserItem *etfci) -{ - if (etfci->drag_col != -1) { - gchar *string = g_strdup_printf("%d", etfci->drag_col); - gtk_selection_data_set(selection_data, - GDK_SELECTION_TYPE_STRING, - sizeof(string[0]), - string, - strlen(string)); - g_free(string); - } -} - -static void -etfci_drag_end (GtkWidget *canvas, - GdkDragContext *context, - ETableFieldChooserItem *etfci) -{ - etfci->drag_col = -1; -} - -static void -etfci_realize (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GdkWindow *window; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - if (!etfci->font) - etfci_font_load (etfci, NULL); - - etfci->drag_end_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_end", - GTK_SIGNAL_FUNC (etfci_drag_end), etfci); - etfci->drag_data_get_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_data_get", - GTK_SIGNAL_FUNC (etfci_drag_data_get), etfci); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_unrealize (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - - if (etfci->font) - gdk_font_unref (etfci->font); - etfci->font = NULL; - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), etfci->drag_end_id); - etfci->drag_end_id = 0; - gtk_signal_disconnect (GTK_OBJECT (item->canvas), etfci->drag_data_get_id); - etfci->drag_data_get_id = 0; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->unrealize)(item); -} - -static void -etfci_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const int rows = e_table_header_count (etfci->full_header); - int y1, y2; - int row; - GtkStyle *style; - GtkStateType state; - - style = GTK_WIDGET (canvas)->style; - state = GTK_WIDGET_STATE (canvas); - - y1 = y2 = 0; - for (row = 0; row < rows; row++, y1 = y2){ - ETableCol *ecol; - - ecol = e_table_header_get_column (etfci->full_header, row); - - y2 += e_table_header_compute_height (ecol, style, etfci->font); - - if (y1 > (y + height)) - break; - - if (y2 < y) - continue; - - e_table_header_draw_button (drawable, ecol, - style, etfci->font, state, - GTK_WIDGET (canvas), style->fg_gc[GTK_STATE_NORMAL], - -x, y1 - y, - width, height, - etfci->width, y2 - y1, - E_TABLE_COL_ARROW_NONE); - } -} - -static double -etfci_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -static gboolean -etfci_maybe_start_drag (ETableFieldChooserItem *etfci, double x, double y) -{ - if (!etfci->maybe_drag) - return FALSE; - - if (MAX (abs (etfci->click_x - x), - abs (etfci->click_y - y)) <= 3) - return FALSE; - - return TRUE; -} - -static void -etfci_start_drag (ETableFieldChooserItem *etfci, GdkEvent *event, double x, double y) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas); - GtkTargetList *list; - GdkDragContext *context; - ETableCol *ecol; - GdkPixmap *pixmap; - int drag_col; - int button_height; - - GtkTargetEntry etfci_drag_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - drag_col = etfci_find_button(etfci, y); - - if (drag_col < 0 || drag_col > e_table_header_count(etfci->full_header)) - return; - - ecol = e_table_header_get_column (etfci->full_header, drag_col); - - etfci->drag_col = ecol->col_idx; - - etfci_drag_types[0].target = g_strdup_printf("%s-%s", etfci_drag_types[0].target, etfci->dnd_code); - list = gtk_target_list_new (etfci_drag_types, ELEMENTS (etfci_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - g_free(etfci_drag_types[0].target); - - button_height = e_table_header_compute_height (ecol, widget->style, etfci->font); - pixmap = gdk_pixmap_new (widget->window, etfci->width, button_height, -1); - - e_table_header_draw_button (pixmap, e_table_header_get_column (etfci->full_header, drag_col), - widget->style, etfci->font, GTK_WIDGET_STATE (widget), - widget, widget->style->fg_gc[GTK_STATE_NORMAL], - 0, 0, - etfci->width, button_height, - etfci->width, button_height, - E_TABLE_COL_ARROW_NONE); - - gtk_drag_set_icon_pixmap (context, - gdk_window_get_colormap (widget->window), - pixmap, - NULL, - etfci->width / 2, - button_height / 2); - gdk_pixmap_unref (pixmap); - etfci->maybe_drag = FALSE; -} - -/* - * Handles the events on the ETableFieldChooserItem - */ -static int -etfci_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - int x, y; - - switch (e->type){ - case GDK_MOTION_NOTIFY: - gnome_canvas_w2c (canvas, e->motion.x, e->motion.y, &x, &y); - - if (etfci_maybe_start_drag (etfci, x, y)) - etfci_start_drag (etfci, e, x, y); - break; - - case GDK_BUTTON_PRESS: - gnome_canvas_w2c (canvas, e->button.x, e->button.y, &x, &y); - - if (e->button.button == 1){ - etfci->click_x = x; - etfci->click_y = y; - etfci->maybe_drag = TRUE; - } - break; - - case GDK_BUTTON_RELEASE: { - etfci->maybe_drag = FALSE; - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -etfci_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - etfci_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = etfci_destroy; - object_class->set_arg = etfci_set_arg; - object_class->get_arg = etfci_get_arg; - - item_class->update = etfci_update; - item_class->realize = etfci_realize; - item_class->unrealize = etfci_unrealize; - item_class->draw = etfci_draw; - item_class->point = etfci_point; - item_class->event = etfci_event; - - gtk_object_add_arg_type ("ETableFieldChooserItem::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooserItem::full_header", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_FULL_HEADER); - gtk_object_add_arg_type ("ETableFieldChooserItem::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableFieldChooserItem::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); -} - -static void -etfci_init (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - - etfci->full_header = NULL; - - etfci->height = etfci->width = 0; - - etfci->font = NULL; - - etfci->structure_change_id = 0; - etfci->dimension_change_id = 0; - - etfci->dnd_code = NULL; - - etfci->maybe_drag = 0; - etfci->drag_end_id = 0; - - e_canvas_item_set_reflow_callback(item, etfci_reflow); -} - -GtkType -e_table_field_chooser_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableFieldChooserItem", - sizeof (ETableFieldChooserItem), - sizeof (ETableFieldChooserItemClass), - (GtkClassInitFunc) etfci_class_init, - (GtkObjectInitFunc) etfci_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - diff --git a/widgets/table/e-table-field-chooser-item.h b/widgets/table/e-table-field-chooser-item.h deleted file mode 100644 index d91c36d52b..0000000000 --- a/widgets/table/e-table-field-chooser-item.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_FIELD_CHOOSER_ITEM_H_ -#define _E_TABLE_FIELD_CHOOSER_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include <gal/e-table/e-table-header.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_FIELD_CHOOSER_ITEM_TYPE (e_table_field_chooser_item_get_type ()) -#define E_TABLE_FIELD_CHOOSER_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_FIELD_CHOOSER_ITEM_TYPE, ETableFieldChooserItem)) -#define E_TABLE_FIELD_CHOOSER_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_FIELD_CHOOSER_ITEM_TYPE, ETableFieldChooserItemClass)) -#define E_IS_TABLE_FIELD_CHOOSER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_FIELD_CHOOSER_ITEM_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_FIELD_CHOOSER_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableHeader *full_header; - - double height, width; - - GdkFont *font; - - /* - * Ids - */ - int structure_change_id, dimension_change_id; - - gchar *dnd_code; - - /* - * For dragging columns - */ - guint maybe_drag:1; - int click_x, click_y; - int drag_col; - guint drag_data_get_id; - guint drag_end_id; -} ETableFieldChooserItem; - -typedef struct { - GnomeCanvasItemClass parent_class; -} ETableFieldChooserItemClass; - -GtkType e_table_field_chooser_item_get_type (void); - -END_GNOME_DECLS - -#endif /* _E_TABLE_FIELD_CHOOSER_ITEM_H_ */ diff --git a/widgets/table/e-table-field-chooser.c b/widgets/table/e-table-field-chooser.c deleted file mode 100644 index a27416a6ba..0000000000 --- a/widgets/table/e-table-field-chooser.c +++ /dev/null @@ -1,248 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-field-chooser.c - * Copyright (C) 2000 Ximian, Inc. - * Author: Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU 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 <config.h> -#include <gnome.h> -#include "e-table-field-chooser.h" -#include "e-table-field-chooser-item.h" - -static void e_table_field_chooser_init (ETableFieldChooser *card); -static void e_table_field_chooser_class_init (ETableFieldChooserClass *klass); -static void e_table_field_chooser_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_destroy (GtkObject *object); - -static GtkVBoxClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_FULL_HEADER, - ARG_DND_CODE, -}; - -GtkType -e_table_field_chooser_get_type (void) -{ - static GtkType table_field_chooser_type = 0; - - if (!table_field_chooser_type) - { - static const GtkTypeInfo table_field_chooser_info = - { - "ETableFieldChooser", - sizeof (ETableFieldChooser), - sizeof (ETableFieldChooserClass), - (GtkClassInitFunc) e_table_field_chooser_class_init, - (GtkObjectInitFunc) e_table_field_chooser_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - table_field_chooser_type = gtk_type_unique (gtk_vbox_get_type (), &table_field_chooser_info); - } - - return table_field_chooser_type; -} - -static void -e_table_field_chooser_class_init (ETableFieldChooserClass *klass) -{ - GtkObjectClass *object_class; - GtkVBoxClass *vbox_class; - - object_class = (GtkObjectClass*) klass; - vbox_class = (GtkVBoxClass *) klass; - - glade_gnome_init(); - - parent_class = gtk_type_class (gtk_vbox_get_type ()); - - object_class->set_arg = e_table_field_chooser_set_arg; - object_class->get_arg = e_table_field_chooser_get_arg; - object_class->destroy = e_table_field_chooser_destroy; - gtk_object_add_arg_type ("ETableFieldChooser::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooser::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); -} - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, ETableFieldChooser *etfc) -{ - double height; - etfc->last_alloc = *allocation; - gnome_canvas_item_set( etfc->item, - "width", (double) allocation->width, - NULL ); - gtk_object_get(GTK_OBJECT(etfc->item), - "height", &height, - NULL); - height = MAX(height, allocation->height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( etfc->canvas ), 0, 0, allocation->width - 1, height - 1); - gnome_canvas_item_set( etfc->rect, - "x2", (double) allocation->width, - "y2", (double) height, - NULL ); -} - -static void resize(GnomeCanvas *canvas, ETableFieldChooser *etfc) -{ - double height; - gtk_object_get(GTK_OBJECT(etfc->item), - "height", &height, - NULL); - - height = MAX(height, etfc->last_alloc.height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS(etfc->canvas), 0, 0, etfc->last_alloc.width - 1, height - 1); - gnome_canvas_item_set( etfc->rect, - "x2", (double) etfc->last_alloc.width, - "y2", (double) height, - NULL ); -} - -static void -e_table_field_chooser_init (ETableFieldChooser *etfc) -{ - GladeXML *gui; - GtkWidget *widget; - - gui = glade_xml_new (ETABLE_GLADEDIR "/e-table-field-chooser.glade", NULL); - etfc->gui = gui; - - widget = glade_xml_get_widget(gui, "vbox-top"); - if (!widget) { - return; - } - gtk_widget_reparent(widget, - GTK_WIDGET(etfc)); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - etfc->canvas = GNOME_CANVAS(glade_xml_get_widget(gui, "canvas-buttons")); - - etfc->rect = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS( etfc->canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - - etfc->item = gnome_canvas_item_new(gnome_canvas_root(etfc->canvas), - e_table_field_chooser_item_get_type(), - "width", (double) 100, - "full_header", etfc->full_header, - "dnd_code", etfc->dnd_code, - NULL ); - - gtk_signal_connect( GTK_OBJECT( etfc->canvas ), "reflow", - GTK_SIGNAL_FUNC( resize ), - etfc); - - gnome_canvas_set_scroll_region ( GNOME_CANVAS( etfc->canvas ), - 0, 0, - 100, 100 ); - - /* Connect the signals */ - gtk_signal_connect (GTK_OBJECT (etfc->canvas), "size_allocate", - GTK_SIGNAL_FUNC (allocate_callback), - etfc); - - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - gtk_widget_show(widget); -} - -static void -e_table_field_chooser_destroy (GtkObject *object) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - g_free(etfc->dnd_code); - if (etfc->full_header) - gtk_object_unref(GTK_OBJECT(etfc->full_header)); - - if (etfc->gui) - gtk_object_unref(GTK_OBJECT(etfc->gui)); -} - -GtkWidget* -e_table_field_chooser_new (void) -{ - GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_table_field_chooser_get_type ())); - return widget; -} - -static void -e_table_field_chooser_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - switch (arg_id){ - case ARG_DND_CODE: - g_free(etfc->dnd_code); - etfc->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - if (etfc->item) - gtk_object_set(GTK_OBJECT(etfc->item), - "dnd_code", etfc->dnd_code, - NULL); - break; - case ARG_FULL_HEADER: - if (etfc->full_header) - gtk_object_unref(GTK_OBJECT(etfc->full_header)); - if (GTK_VALUE_OBJECT(*arg)) - etfc->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT(*arg)); - else - etfc->full_header = NULL; - if (etfc->full_header) - gtk_object_ref(GTK_OBJECT(etfc->full_header)); - if (etfc->item) - gtk_object_set(GTK_OBJECT(etfc->item), - "full_header", etfc->full_header, - NULL); - break; - default: - break; - } -} - -static void -e_table_field_chooser_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - switch (arg_id) { - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfc->dnd_code); - break; - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etfc->full_header); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} diff --git a/widgets/table/e-table-field-chooser.glade b/widgets/table/e-table-field-chooser.glade deleted file mode 100644 index a5cd37c2df..0000000000 --- a/widgets/table/e-table-field-chooser.glade +++ /dev/null @@ -1,131 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <name>e-table-field-chooser</name> - <program_name>e-table-field-chooser</program_name> - <directory></directory> - <source_directory>src</source_directory> - <pixmaps_directory>pixmaps</pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>True</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <gnome_help_support>True</gnome_help_support> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-field-chooser.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GnomeDialog</class> - <name>dialog-field-chooser</name> - <visible>False</visible> - <title>Field Chooser</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - <auto_close>False</auto_close> - <hide_on_close>False</hide_on_close> - - <widget> - <class>GtkVBox</class> - <child_name>GnomeDialog:vbox</child_name> - <name>dialog-vbox1</name> - <homogeneous>False</homogeneous> - <spacing>8</spacing> - <child> - <padding>4</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkHButtonBox</class> - <child_name>GnomeDialog:action_area</child_name> - <name>dialog-action_area1</name> - <layout_style>GTK_BUTTONBOX_END</layout_style> - <spacing>8</spacing> - <child_min_width>85</child_min_width> - <child_min_height>27</child_min_height> - <child_ipad_x>7</child_ipad_x> - <child_ipad_y>0</child_ipad_y> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - <pack>GTK_PACK_END</pack> - </child> - - <widget> - <class>GtkButton</class> - <name>button3</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_CLOSE</stock_button> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox-top</name> - <homogeneous>False</homogeneous> - <spacing>4</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>label1</name> - <label>To add a column to your table, drag it into -the location in which you want it to appear.</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow1</name> - <width>200</width> - <height>200</height> - <hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>canvas-buttons</name> - <creation_function>e_canvas_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Thu, 08 Jun 2000 07:27:33 GMT</last_modification_time> - </widget> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/table/e-table-field-chooser.glade.h b/widgets/table/e-table-field-chooser.glade.h deleted file mode 100644 index a36bd6052c..0000000000 --- a/widgets/table/e-table-field-chooser.glade.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("Field Chooser"); -gchar *s = N_("To add a column to your table, drag it into\n" - "the location in which you want it to appear."); diff --git a/widgets/table/e-table-field-chooser.h b/widgets/table/e-table-field-chooser.h deleted file mode 100644 index ca9917549a..0000000000 --- a/widgets/table/e-table-field-chooser.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-contact-editor-fullname.h - * Copyright (C) 2000 Ximian, Inc. - * Author: Chris Lahey <clahey@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU 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_TABLE_FIELD_CHOOSER_H__ -#define __E_TABLE_FIELD_CHOOSER_H__ - -#include <gnome.h> -#include <glade/glade.h> -#include <gal/e-table/e-table-header.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETableFieldChooser - A dialog displaying information about a contact. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - */ - -#define E_TABLE_FIELD_CHOOSER_TYPE (e_table_field_chooser_get_type ()) -#define E_TABLE_FIELD_CHOOSER(obj) (GTK_CHECK_CAST ((obj), E_TABLE_FIELD_CHOOSER_TYPE, ETableFieldChooser)) -#define E_TABLE_FIELD_CHOOSER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TABLE_FIELD_CHOOSER_TYPE, ETableFieldChooserClass)) -#define E_IS_TABLE_FIELD_CHOOSER(obj) (GTK_CHECK_TYPE ((obj), E_TABLE_FIELD_CHOOSER_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TABLE_FIELD_CHOOSER_TYPE)) - - -typedef struct _ETableFieldChooser ETableFieldChooser; -typedef struct _ETableFieldChooserClass ETableFieldChooserClass; - -struct _ETableFieldChooser -{ - GtkVBox parent; - - /* item specific fields */ - GladeXML *gui; - GnomeCanvas *canvas; - GnomeCanvasItem *item; - - GnomeCanvasItem *rect; - GtkAllocation last_alloc; - - gchar *dnd_code; - ETableHeader *full_header; -}; - -struct _ETableFieldChooserClass -{ - GtkVBoxClass parent_class; -}; - - -GtkWidget *e_table_field_chooser_new(void); -GtkType e_table_field_chooser_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TABLE_FIELD_CHOOSER_H__ */ diff --git a/widgets/table/e-table-group-container.c b/widgets/table/e-table-group-container.c deleted file mode 100644 index b92498657e..0000000000 --- a/widgets/table/e-table-group-container.c +++ /dev/null @@ -1,1279 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Ximian, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-table-group-container.h" -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include "gal/util/e-util.h" -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-canvas-utils.h" -#include "gal/e-text/e-text.h" -#include "e-table-defines.h" - -#define TITLE_HEIGHT 16 - -#define PARENT_TYPE e_table_group_get_type () - -static GnomeCanvasGroupClass *etgc_parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_HEIGHT, - ARG_WIDTH, - ARG_MINIMUM_WIDTH, - ARG_FROZEN, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_TABLE_SELECTION_MODEL, - ARG_LENGTH_THRESHOLD, -}; - -typedef struct { - ETableGroup *child; - void *key; - char *string; - GnomeCanvasItem *text; - GnomeCanvasItem *rect; - gint count; -} ETableGroupContainerChildNode; - -static EPrintable * -etgc_get_printable (ETableGroup *etg); - - -static void -e_table_group_container_child_node_free (ETableGroupContainer *etgc, - ETableGroupContainerChildNode *child_node) -{ - ETableGroup *etg = E_TABLE_GROUP (etgc); - ETableGroup *child = child_node->child; - - gtk_object_destroy (GTK_OBJECT (child)); - e_table_model_free_value (etg->model, etgc->ecol->col_idx, - child_node->key); - g_free(child_node->string); - gtk_object_destroy (GTK_OBJECT (child_node->text)); - gtk_object_destroy (GTK_OBJECT (child_node->rect)); -} - -static void -e_table_group_container_list_free (ETableGroupContainer *etgc) -{ - ETableGroupContainerChildNode *child_node; - GList *list; - - for (list = etgc->children; list; list = g_list_next (list)) { - child_node = (ETableGroupContainerChildNode *) list->data; - e_table_group_container_child_node_free (etgc, child_node); - } - - g_list_free (etgc->children); -} - -static void -etgc_destroy (GtkObject *object) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - - if (etgc->font) - gdk_font_unref (etgc->font); - etgc->font = NULL; - - if (etgc->ecol) - gtk_object_unref (GTK_OBJECT(etgc->ecol)); - - if (etgc->sort_info) - gtk_object_unref (GTK_OBJECT(etgc->sort_info)); - - if (etgc->table_selection_model) - gtk_object_unref (GTK_OBJECT(etgc->table_selection_model)); - - if (etgc->rect) - gtk_object_destroy (GTK_OBJECT(etgc->rect)); - - e_table_group_container_list_free (etgc); - - GTK_OBJECT_CLASS (etgc_parent_class)->destroy (object); -} - -/** - * e_table_group_container_construct - * @parent: The %GnomeCanvasGroup to create a child of. - * @etgc: The %ETableGroupContainer. - * @full_header: The full header of the %ETable. - * @header: The current header of the %ETable. - * @model: The %ETableModel of the %ETable. - * @sort_info: The %ETableSortInfo of the %ETable. - * @n: Which grouping level this is (Starts at 0 and sends n + 1 to any child %ETableGroups. - * - * This routine constructs the new %ETableGroupContainer. - */ -void -e_table_group_container_construct (GnomeCanvasGroup *parent, ETableGroupContainer *etgc, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n) -{ - ETableCol *col; - ETableSortColumn column = e_table_sort_info_grouping_get_nth(sort_info, n); - - col = e_table_header_get_column_by_col_idx(full_header, column.column); - if (col == NULL) - col = e_table_header_get_column (full_header, e_table_header_count (full_header) - 1); - - e_table_group_construct (parent, E_TABLE_GROUP (etgc), full_header, header, model); - etgc->ecol = col; - gtk_object_ref (GTK_OBJECT(etgc->ecol)); - etgc->sort_info = sort_info; - gtk_object_ref (GTK_OBJECT(etgc->sort_info)); - etgc->n = n; - etgc->ascending = column.ascending; - - - etgc->font = gdk_font_load ("lucidasans-10"); - if (!etgc->font){ - etgc->font = GTK_WIDGET (GNOME_CANVAS_ITEM (etgc)->canvas)->style->font; - - gdk_font_ref (etgc->font); - } - etgc->open = TRUE; -} - -/** - * e_table_group_container_new - * @parent: The %GnomeCanvasGroup to create a child of. - * @full_header: The full header of the %ETable. - * @header: The current header of the %ETable. - * @model: The %ETableModel of the %ETable. - * @sort_info: The %ETableSortInfo of the %ETable. - * @n: Which grouping level this is (Starts at 0 and sends n + 1 to any child %ETableGroups. - * - * %ETableGroupContainer is an %ETableGroup which groups by the nth - * grouping of the %ETableSortInfo. It creates %ETableGroups as - * children. - * - * Returns: The new %ETableGroupContainer. - */ -ETableGroup * -e_table_group_container_new (GnomeCanvasGroup *parent, ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n) -{ - ETableGroupContainer *etgc; - - g_return_val_if_fail (parent != NULL, NULL); - - etgc = gtk_type_new (e_table_group_container_get_type ()); - - e_table_group_container_construct (parent, etgc, full_header, header, - model, sort_info, n); - return E_TABLE_GROUP (etgc); -} - - -static int -etgc_event (GnomeCanvasItem *item, GdkEvent *event) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(item); - gboolean return_val = TRUE; - gboolean change_focus = FALSE; - gboolean use_col = FALSE; - gint start_col = 0; - gint old_col; - EFocus direction = E_FOCUS_START; - - switch (event->type) { - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Tab || - event->key.keyval == GDK_KP_Tab || - event->key.keyval == GDK_ISO_Left_Tab) { - change_focus = TRUE; - use_col = TRUE; - start_col = (event->key.state & GDK_SHIFT_MASK) ? -1 : 0; - direction = (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START; - } else if (event->key.keyval == GDK_Left || - event->key.keyval == GDK_KP_Left) { - change_focus = TRUE; - use_col = TRUE; - start_col = -1; - direction = E_FOCUS_END; - } else if (event->key.keyval == GDK_Right || - event->key.keyval == GDK_KP_Right) { - change_focus = TRUE; - use_col = TRUE; - start_col = 0; - direction = E_FOCUS_START; - } else if (event->key.keyval == GDK_Down || - event->key.keyval == GDK_KP_Down) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_START; - } else if (event->key.keyval == GDK_Up || - event->key.keyval == GDK_KP_Up) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_END; - } else if (event->key.keyval == GDK_Return || - event->key.keyval == GDK_KP_Enter) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_START; - } - if (change_focus){ - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node; - ETableGroup *child; - - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - - if (e_table_group_get_focus (child)) { - old_col = e_table_group_get_focus_column (child); - if (old_col == -1) - old_col = 0; - if (start_col == -1) - start_col = e_table_header_count (e_table_group_get_header (child)) - 1; - - if (direction == E_FOCUS_END) - list = list->prev; - else - list = list->next; - - if (list) { - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - if (use_col) - e_table_group_set_focus (child, direction, start_col); - else - e_table_group_set_focus (child, direction, old_col); - return 1; - } else { - return 0; - } - } - } - if (direction == E_FOCUS_END) - list = g_list_last(etgc->children); - else - list = etgc->children; - if (list) { - ETableGroupContainerChildNode *child_node; - ETableGroup *child; - - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - - if (start_col == -1) - start_col = e_table_header_count (e_table_group_get_header (child)) - 1; - - e_table_group_set_focus (child, direction, start_col); - return 1; - } - } - return_val = FALSE; - break; - default: - return_val = FALSE; - break; - } - if (return_val == FALSE) { - if (GNOME_CANVAS_ITEM_CLASS(etgc_parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->event (item, event); - } - return return_val; - -} - -/* Realize handler for the text item */ -static void -etgc_realize (GnomeCanvasItem *item) -{ - ETableGroupContainer *etgc; - - if (GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->realize) (item); - - etgc = E_TABLE_GROUP_CONTAINER (item); - - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); -} - -/* Unrealize handler for the etgc item */ -static void -etgc_unrealize (GnomeCanvasItem *item) -{ - ETableGroupContainer *etgc; - - etgc = E_TABLE_GROUP_CONTAINER (item); - - if (GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->unrealize) - (* GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->unrealize) (item); -} - -static void -compute_text (ETableGroupContainer *etgc, ETableGroupContainerChildNode *child_node) -{ - gchar *text; - if (etgc->ecol->text) - text = g_strdup_printf ("%s : %s (%d item%s)", - etgc->ecol->text, - child_node->string, - (gint) child_node->count, - child_node->count == 1 ? "" : "s"); - else - text = g_strdup_printf ("%s (%d item%s)", - child_node->string, - (gint) child_node->count, - child_node->count == 1 ? "" : "s"); - gnome_canvas_item_set (child_node->text, - "text", text, - NULL); - g_free (text); -} - -static void -child_cursor_change (ETableGroup *etg, int row, - ETableGroupContainer *etgc) -{ - e_table_group_cursor_change (E_TABLE_GROUP (etgc), row); -} - -static void -child_cursor_activated (ETableGroup *etg, int row, - ETableGroupContainer *etgc) -{ - e_table_group_cursor_activated (E_TABLE_GROUP (etgc), row); -} - -static void -child_double_click (ETableGroup *etg, int row, int col, GdkEvent *event, - ETableGroupContainer *etgc) -{ - e_table_group_double_click (E_TABLE_GROUP (etgc), row, col, event); -} - -static gint -child_right_click (ETableGroup *etg, int row, int col, GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_right_click (E_TABLE_GROUP (etgc), row, col, event); -} - -static gint -child_click (ETableGroup *etg, int row, int col, GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_click (E_TABLE_GROUP (etgc), row, col, event); -} - -static gint -child_key_press (ETableGroup *etg, int row, int col, GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_key_press (E_TABLE_GROUP (etgc), row, col, event); -} - -static void -etgc_add (ETableGroup *etg, gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - void *val = e_table_model_value_at (etg->model, etgc->ecol->col_idx, row); - GCompareFunc comp = etgc->ecol->compare; - GList *list = etgc->children; - ETableGroup *child; - ETableGroupContainerChildNode *child_node; - int i = 0; - - for (; list; list = g_list_next (list), i++){ - int comp_val; - - child_node = list->data; - comp_val = (*comp)(child_node->key, val); - if (comp_val == 0) { - child = child_node->child; - child_node->count ++; - e_table_group_add (child, row); - compute_text (etgc, child_node); - return; - } - if ((comp_val > 0 && etgc->ascending) || - (comp_val < 0 && (!etgc->ascending))) - break; - } - child_node = g_new (ETableGroupContainerChildNode, 1); - child_node->rect = gnome_canvas_item_new (GNOME_CANVAS_GROUP (etgc), - gnome_canvas_rect_get_type (), - "fill_color", "grey70", - "outline_color", "grey50", - NULL); - child_node->text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (etgc), - e_text_get_type (), - "font_gdk", etgc->font, - "anchor", GTK_ANCHOR_SW, - "fill_color", "black", - "draw_background", FALSE, - NULL); - child = e_table_group_new (GNOME_CANVAS_GROUP (etgc), etg->full_header, - etg->header, etg->model, etgc->sort_info, etgc->n + 1); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(child), - "drawgrid", etgc->draw_grid, - "drawfocus", etgc->draw_focus, - "cursor_mode", etgc->cursor_mode, - "table_selection_model", etgc->table_selection_model, - "length_threshold", etgc->length_threshold, - "minimum_width", etgc->minimum_width - GROUP_INDENT, - NULL); - - gtk_signal_connect (GTK_OBJECT (child), "cursor_change", - GTK_SIGNAL_FUNC (child_cursor_change), etgc); - gtk_signal_connect (GTK_OBJECT (child), "cursor_activated", - GTK_SIGNAL_FUNC (child_cursor_activated), etgc); - gtk_signal_connect (GTK_OBJECT (child), "double_click", - GTK_SIGNAL_FUNC (child_double_click), etgc); - gtk_signal_connect (GTK_OBJECT (child), "right_click", - GTK_SIGNAL_FUNC (child_right_click), etgc); - gtk_signal_connect (GTK_OBJECT (child), "click", - GTK_SIGNAL_FUNC (child_click), etgc); - gtk_signal_connect (GTK_OBJECT (child), "key_press", - GTK_SIGNAL_FUNC (child_key_press), etgc); - child_node->child = child; - child_node->key = e_table_model_duplicate_value (etg->model, etgc->ecol->col_idx, val); - child_node->string = e_table_model_value_to_string (etg->model, etgc->ecol->col_idx, val); - child_node->count = 1; - e_table_group_add (child, row); - - if (list) - etgc->children = g_list_insert (etgc->children, child_node, i); - else - etgc->children = g_list_append (etgc->children, child_node); - - compute_text (etgc, child_node); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); -} - -static void -etgc_add_all (ETableGroup *etg) -{ - int rows = e_table_model_row_count(etg->model); - int i; - for (i = 0; i < rows; i++) - etgc_add(etg, i); -} - -static gboolean -etgc_remove (ETableGroup *etg, gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - - for (list = etgc->children ; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = list->data; - ETableGroup *child = child_node->child; - - if (e_table_group_remove (child, row)) { - child_node->count --; - if (child_node->count == 0) { - e_table_group_container_child_node_free (etgc, child_node); - etgc->children = g_list_remove (etgc->children, child_node); - g_free (child_node); - } else - compute_text (etgc, child_node); - - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); - - return TRUE; - } - } - return FALSE; -} - -static int -etgc_row_count (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - gint count = 0; - for (list = etgc->children; list; list = g_list_next(list)) { - ETableGroup *group = ((ETableGroupContainerChildNode *)list->data)->child; - gint this_count = e_table_group_row_count(group); - count += this_count; - } - return count; -} - -static void -etgc_increment (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list = etgc->children; - - for (list = etgc->children ; list; list = g_list_next (list)) - e_table_group_increment (((ETableGroupContainerChildNode *)list->data)->child, - position, amount); -} - -static void -etgc_decrement (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list = etgc->children; - - for (list = etgc->children ; list; list = g_list_next (list)) - e_table_group_decrement (((ETableGroupContainerChildNode *)list->data)->child, - position, amount); -} - -static void -etgc_set_focus (ETableGroup *etg, EFocus direction, gint view_col) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - if (etgc->children) { - if (direction == E_FOCUS_END) - e_table_group_set_focus (((ETableGroupContainerChildNode *)g_list_last (etgc->children)->data)->child, - direction, view_col); - else - e_table_group_set_focus (((ETableGroupContainerChildNode *)etgc->children->data)->child, - direction, view_col); - } -} - -static gint -etgc_get_focus_column (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - if (etgc->children) { - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - ETableGroup *child = child_node->child; - if (e_table_group_get_focus (child)) { - return e_table_group_get_focus_column (child); - } - } - } - return 0; -} - -static void -etgc_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - - if (row) - *row = -1; - if (col) - *col = -1; - - *x -= GROUP_INDENT; - *y -= TITLE_HEIGHT; - - if (*x >= 0 && *y >= 0 && etgc->children) { - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - ETableGroup *child = child_node->child; - - e_table_group_compute_location (child, x, y, row, col); - if ((*row != -1) && (*col != -1)) - return; - } - } -} - -static void etgc_thaw (ETableGroup *etg) -{ - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(etg)); -} - -static void -etgc_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - GList *list; - - switch (arg_id) { - case ARG_FROZEN: - if (GTK_VALUE_BOOL (*arg)) - etg->frozen = TRUE; - else { - etg->frozen = FALSE; - etgc_thaw (etg); - } - break; - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - etgc->minimum_width = GTK_VALUE_DOUBLE(*arg); - - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "minimum_width", etgc->minimum_width - GROUP_INDENT, - NULL); - } - break; - case ARG_LENGTH_THRESHOLD: - etgc->length_threshold = GTK_VALUE_INT (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - - case ARG_TABLE_SELECTION_MODEL: - if (etgc->table_selection_model) - gtk_object_unref(GTK_OBJECT(etgc->table_selection_model)); - etgc->table_selection_model = E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg)); - if (etgc->table_selection_model) - gtk_object_ref(GTK_OBJECT(etgc->table_selection_model)); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "table_selection_model", etgc->table_selection_model, - NULL); - } - break; - - case ARG_TABLE_DRAW_GRID: - etgc->draw_grid = GTK_VALUE_BOOL (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_FOCUS: - etgc->draw_focus = GTK_VALUE_BOOL (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_CURSOR_MODE: - etgc->cursor_mode = GTK_VALUE_INT (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - } - break; - default: - break; - } -} - -static void -etgc_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - - switch (arg_id) { - case ARG_FROZEN: - GTK_VALUE_BOOL (*arg) = etg->frozen; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etgc->height; - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgc->width; - break; - case ARG_MINIMUM_WIDTH: - etgc->minimum_width = GTK_VALUE_DOUBLE(*arg); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etgc_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *e_group_class = E_TABLE_GROUP_CLASS(object_class); - - object_class->destroy = etgc_destroy; - object_class->set_arg = etgc_set_arg; - object_class->get_arg = etgc_get_arg; - - item_class->event = etgc_event; - item_class->realize = etgc_realize; - item_class->unrealize = etgc_unrealize; - - etgc_parent_class = gtk_type_class (PARENT_TYPE); - - e_group_class->add = etgc_add; - e_group_class->add_all = etgc_add_all; - e_group_class->remove = etgc_remove; - e_group_class->increment = etgc_increment; - e_group_class->decrement = etgc_decrement; - e_group_class->row_count = etgc_row_count; - e_group_class->set_focus = etgc_set_focus; - e_group_class->get_focus_column = etgc_get_focus_column; - e_group_class->get_printable = etgc_get_printable; - e_group_class->compute_location = etgc_compute_location; - - gtk_object_add_arg_type ("ETableGroupContainer::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableGroupContainer::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableGroupContainer::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableGroupContainer::table_selection_model", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - gtk_object_add_arg_type ("ETableGroupContainer::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - - gtk_object_add_arg_type ("ETableGroupContainer::frozen", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_FROZEN); - gtk_object_add_arg_type ("ETableGroupContainer::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableGroupContainer::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableGroupContainer::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); -} - -static void -etgc_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(item); - gboolean frozen; - - gtk_object_get (GTK_OBJECT(etgc), - "frozen", &frozen, - NULL); - - if (frozen) - return; - - - if (GTK_OBJECT_FLAGS(etgc)& GNOME_CANVAS_ITEM_REALIZED){ - gdouble running_height = 0; - gdouble running_width = 0; - gdouble old_height; - gdouble old_width; - - old_height = etgc->height; - old_width = etgc->width; - if (etgc->children == NULL){ - } else { - GList *list; - gdouble extra_height = 0; - gdouble item_height = 0; - gdouble item_width = 0; - - if (etgc->font) - extra_height += etgc->font->ascent + etgc->font->descent + BUTTON_PADDING * 2; - - extra_height = MAX(extra_height, BUTTON_HEIGHT + BUTTON_PADDING * 2); - - running_height = extra_height; - - for ( list = etgc->children; list; list = g_list_next (list)){ - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - ETableGroup *child = child_node->child; - - gtk_object_get (GTK_OBJECT(child), - "width", &item_width, - NULL); - - if (item_width > running_width) - running_width = item_width; - } - for ( list = etgc->children; list; list = g_list_next (list)){ - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - ETableGroup *child = child_node->child; - gtk_object_get (GTK_OBJECT(child), - "height", &item_height, - NULL); - - e_canvas_item_move_absolute (GNOME_CANVAS_ITEM(child_node->text), - GROUP_INDENT, - running_height - BUTTON_PADDING); - - e_canvas_item_move_absolute (GNOME_CANVAS_ITEM(child), - GROUP_INDENT, - running_height); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM(child_node->rect), - "x1", (double) 0, - "x2", (double) running_width + GROUP_INDENT, - "y1", (double) running_height - extra_height, - "y2", (double) running_height + item_height, - NULL); - - running_height += item_height + extra_height; - } - running_height -= extra_height; - } - if (running_height != old_height || running_width != old_width) { - etgc->height = running_height; - etgc->width = running_width; - e_canvas_item_request_parent_reflow (item); - } - } -} - -static void -etgc_init (GtkObject *object) -{ - ETableGroupContainer *container = E_TABLE_GROUP_CONTAINER(object); - container->children = FALSE; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM(object), etgc_reflow); - - container->draw_grid = 1; - container->draw_focus = 1; - container->cursor_mode = E_TABLE_CURSOR_SIMPLE; - container->length_threshold = -1; - container->table_selection_model = NULL; -} - -E_MAKE_TYPE (e_table_group_container, "ETableGroupContainer", ETableGroupContainer, etgc_class_init, etgc_init, PARENT_TYPE); - -void -e_table_group_apply_to_leafs (ETableGroup *etg, ETableGroupLeafFn fn, void *closure) -{ - if (E_IS_TABLE_GROUP_CONTAINER (etg)){ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - GList *list = etgc->children; - - /* Protect from unrefs in the callback functions */ - gtk_object_ref (GTK_OBJECT (etg)); - - for (list = etgc->children; list; list = list->next){ - ETableGroupContainerChildNode *child_node = list->data; - - e_table_group_apply_to_leafs (child_node->child, fn, closure); - } - - gtk_object_unref (GTK_OBJECT (etg)); - } else if (E_IS_TABLE_GROUP_LEAF (etg)){ - (*fn) (E_TABLE_GROUP_LEAF (etg)->item, closure); - } else { - g_error ("Unknown ETableGroup found: %s", - gtk_type_name (GTK_OBJECT (etg)->klass->type)); - } -} - - -typedef struct { - ETableGroupContainer *etgc; - GList *child; - EPrintable *child_printable; -} ETGCPrintContext; - -#if 0 -#define CHECK(x) if((x) == -1) return -1; - -static gint -gp_draw_rect (GnomePrintContext *context, gdouble x, gdouble y, gdouble width, gdouble height, gdouble r, gdouble g, gdouble b) -{ - CHECK(gnome_print_moveto(context, x, y)); - CHECK(gnome_print_lineto(context, x + width, y)); - CHECK(gnome_print_lineto(context, x + width, y - height)); - CHECK(gnome_print_lineto(context, x, y - height)); - CHECK(gnome_print_lineto(context, x, y)); - return gnome_print_fill(context); -} -#endif - -#define CHECK(x) if((x) == -1) return -1; - -static gint -gp_draw_rect (GnomePrintContext *context, gdouble x, gdouble y, gdouble width, gdouble height) -{ - CHECK(gnome_print_moveto(context, x, y)); - CHECK(gnome_print_lineto(context, x + width, y)); - CHECK(gnome_print_lineto(context, x + width, y - height)); - CHECK(gnome_print_lineto(context, x, y - height)); - CHECK(gnome_print_lineto(context, x, y)); - return gnome_print_fill(context); -} - -#define TEXT_HEIGHT (12) -#define TEXT_AREA_HEIGHT (TEXT_HEIGHT + 4) - -static void -e_table_group_container_print_page (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gdouble yd = height; - gdouble child_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - gchar *string; - - GnomeFont *font = gnome_font_new ("Helvetica", TEXT_HEIGHT); - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) { - if (child) - child_node = child->data; - else - child_node = NULL; - gtk_object_ref(GTK_OBJECT(child_printable)); - } else { - if (!child) { - return; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd - TEXT_AREA_HEIGHT, quantize); - - if (gnome_print_gsave(context) == -1) - /* FIXME */; - if (gnome_print_moveto(context, 0, yd - child_height - TEXT_AREA_HEIGHT) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 36, yd - child_height - TEXT_AREA_HEIGHT) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 36, yd - TEXT_AREA_HEIGHT) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width, yd - TEXT_AREA_HEIGHT) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width, yd) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, yd) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, yd - child_height - TEXT_AREA_HEIGHT) == -1) - /* FIXME */; - if (gnome_print_setrgbcolor(context, .7, .7, .7) == -1) - /* FIXME */; - if (gnome_print_fill(context) == -1) - /* FIXME */; - if (gnome_print_grestore(context) == -1) - /* FIXME */; - - if (gnome_print_gsave(context) == -1) - /* FIXME */; - if (gnome_print_moveto(context, 0, yd - TEXT_AREA_HEIGHT) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width, yd - TEXT_AREA_HEIGHT) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width, yd) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, yd) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, yd - TEXT_AREA_HEIGHT) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - - if (gnome_print_moveto(context, 2, yd - (TEXT_AREA_HEIGHT + gnome_font_get_ascender(font) - gnome_font_get_descender(font)) / 2) == -1) - /* FIXME */; - if (gnome_print_setfont(context, font)) - /* FIXME */; - if (groupcontext->etgc->ecol->text) - string = g_strdup_printf ("%s : %s (%d item%s)", - groupcontext->etgc->ecol->text, - child_node->string, - (gint) child_node->count, - child_node->count == 1 ? "" : "s"); - else - string = g_strdup_printf ("%s (%d item%s)", - child_node->string, - (gint) child_node->count, - child_node->count == 1 ? "" : "s"); - if (gnome_print_show(context, string)) - /* FIXME */; - g_free(string); - if (gnome_print_grestore(context) == -1) - /* FIXME */; - - if (gnome_print_gsave(context) == -1) - /* FIXME */; - if (gnome_print_translate(context, 36, yd - TEXT_AREA_HEIGHT - child_height) == -1) - /* FIXME */; - if (gnome_print_moveto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 36, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 36, child_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, child_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - e_printable_print_page(child_printable, context, width - 36, child_height, quantize); - if (gnome_print_grestore(context) == -1) - /* FIXME */; - - gp_draw_rect(context, 0, yd - child_height - TEXT_AREA_HEIGHT + 1, width, 1); - gp_draw_rect(context, width - 1, yd, 1, yd - child_height - TEXT_AREA_HEIGHT); - gp_draw_rect(context, 0, yd, 1, yd - child_height - TEXT_AREA_HEIGHT); - - yd -= child_height + TEXT_AREA_HEIGHT; - - if (e_printable_data_left(child_printable)) - break; - - child = child->next; - if (!child) { - child_printable = NULL; - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - - gp_draw_rect(context, 0, height, width, 1); - - if (groupcontext->child_printable) - gtk_object_unref(GTK_OBJECT(groupcontext->child_printable)); - groupcontext->child_printable = child_printable; - groupcontext->child = child; - -} - -static gboolean -e_table_group_container_data_left (EPrintable *ep, - ETGCPrintContext *groupcontext) -{ - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "data_left"); - return groupcontext->child != NULL; -} - -static void -e_table_group_container_reset (EPrintable *ep, - ETGCPrintContext *groupcontext) -{ - groupcontext->child = groupcontext->etgc->children; - if (groupcontext->child_printable) - gtk_object_unref(GTK_OBJECT(groupcontext->child_printable)); - groupcontext->child_printable = NULL; -} - -static gdouble -e_table_group_container_height (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gdouble height = 0; - gdouble child_height; - gdouble yd = max_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - else { - if (!child) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return 0; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - if (yd != -1 && yd < TEXT_AREA_HEIGHT) - return 0; - - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd - (yd == -1 ? 0 : TEXT_AREA_HEIGHT), quantize); - - height += child_height + TEXT_AREA_HEIGHT; - - if (yd != -1) { - if (!e_printable_will_fit(child_printable, context, width - 36, yd - (yd == -1 ? 0 : TEXT_AREA_HEIGHT), quantize)) { - break; - } - - yd -= child_height + TEXT_AREA_HEIGHT; - } - - child = child->next; - if (!child) { - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return height; -} - -static gboolean -e_table_group_container_will_fit (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gboolean will_fit = TRUE; - gdouble child_height; - gdouble yd = max_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - else { - if (!child) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return will_fit; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - if (yd != -1 && yd < TEXT_AREA_HEIGHT) - will_fit = FALSE; - else { - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd - (yd == -1 ? 0 : TEXT_AREA_HEIGHT), quantize); - - if (yd != -1) { - if (!e_printable_will_fit(child_printable, context, width - 36, yd - (yd == -1 ? 0 : TEXT_AREA_HEIGHT), quantize)) { - will_fit = FALSE; - break; - } - - yd -= child_height + TEXT_AREA_HEIGHT; - } - - child = child->next; - if (!child) { - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return will_fit; -} - -static void -e_table_group_container_printable_destroy (GtkObject *object, - ETGCPrintContext *groupcontext) -{ - gtk_object_unref(GTK_OBJECT(groupcontext->etgc)); - if (groupcontext->child_printable) - gtk_object_ref(GTK_OBJECT(groupcontext->child_printable)); - g_free(groupcontext); -} - -static EPrintable * -etgc_get_printable (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - EPrintable *printable = e_printable_new(); - ETGCPrintContext *groupcontext; - - groupcontext = g_new(ETGCPrintContext, 1); - groupcontext->etgc = etgc; - gtk_object_ref(GTK_OBJECT(etgc)); - groupcontext->child = etgc->children; - groupcontext->child_printable = NULL; - - gtk_signal_connect (GTK_OBJECT(printable), - "print_page", - GTK_SIGNAL_FUNC(e_table_group_container_print_page), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "data_left", - GTK_SIGNAL_FUNC(e_table_group_container_data_left), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "reset", - GTK_SIGNAL_FUNC(e_table_group_container_reset), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "height", - GTK_SIGNAL_FUNC(e_table_group_container_height), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "will_fit", - GTK_SIGNAL_FUNC(e_table_group_container_will_fit), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "destroy", - GTK_SIGNAL_FUNC(e_table_group_container_printable_destroy), - groupcontext); - - return printable; -} diff --git a/widgets/table/e-table-group-container.h b/widgets/table/e-table-group-container.h deleted file mode 100644 index d273ac94b2..0000000000 --- a/widgets/table/e-table-group-container.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_CONTAINER_H_ -#define _E_TABLE_GROUP_CONTAINER_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-header.h> -#include <gal/e-table/e-table-group.h> -#include <gal/e-table/e-table-item.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_GROUP_CONTAINER_TYPE (e_table_group_container_get_type ()) -#define E_TABLE_GROUP_CONTAINER(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_CONTAINER_TYPE, ETableGroupContainer)) -#define E_TABLE_GROUP_CONTAINER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_CONTAINER_TYPE, ETableGroupContainerClass)) -#define E_IS_TABLE_GROUP_CONTAINER(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_CONTAINER_TYPE)) -#define E_IS_TABLE_GROUP_CONTAINER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_CONTAINER_TYPE)) - -typedef struct { - ETableGroup group; - - /* - * The ETableCol used to group this set - */ - ETableCol *ecol; - gint ascending; - - /* - * List of ETableGroups we stack - */ - GList *children; - - /* - * The canvas rectangle that contains the children - */ - GnomeCanvasItem *rect; - - GdkFont *font; - - gdouble width, height, minimum_width; - - ETableSortInfo *sort_info; - int n; - int length_threshold; - - ETableSelectionModel *table_selection_model; - - guint draw_grid : 1; - guint draw_focus : 1; - ETableCursorMode cursor_mode; - - /* - * State: the ETableGroup is open or closed - */ - guint open:1; -} ETableGroupContainer; - -typedef struct { - ETableGroupClass parent_class; -} ETableGroupContainerClass; - -ETableGroup *e_table_group_container_new (GnomeCanvasGroup *parent, ETableHeader *full_header, ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n); -void e_table_group_container_construct (GnomeCanvasGroup *parent, ETableGroupContainer *etgc, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n); - -GtkType e_table_group_container_get_type (void); - -END_GNOME_DECLS - -#endif /* _E_TABLE_GROUP_CONTAINER_H_ */ diff --git a/widgets/table/e-table-group-leaf.c b/widgets/table/e-table-group-leaf.c deleted file mode 100644 index 86703304b4..0000000000 --- a/widgets/table/e-table-group-leaf.c +++ /dev/null @@ -1,436 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Miguel de Icaza (miguel@gnu.org () - * - * Copyright 1999, Ximian, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include "gal/util/e-util.h" -#include "gal/widgets/e-canvas.h" - -#define PARENT_TYPE e_table_group_get_type () - -static GnomeCanvasGroupClass *etgl_parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_HEIGHT, - ARG_WIDTH, - ARG_MINIMUM_WIDTH, - ARG_FROZEN, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_TABLE_SELECTION_MODEL, -}; - -static void etgl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void etgl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void -etgl_destroy (GtkObject *object) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF(object); - if (etgl->subset) - gtk_object_unref (GTK_OBJECT(etgl->subset)); - if (etgl->item) - gtk_object_destroy (GTK_OBJECT(etgl->item)); - if (etgl->table_selection_model) - gtk_object_unref (GTK_OBJECT(etgl->table_selection_model)); - if (GTK_OBJECT_CLASS (etgl_parent_class)->destroy) - GTK_OBJECT_CLASS (etgl_parent_class)->destroy (object); -} - -static void -e_table_group_leaf_construct (GnomeCanvasGroup *parent, - ETableGroupLeaf *etgl, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info) -{ - etgl->subset = E_TABLE_SUBSET_VARIABLE(e_table_sorted_variable_new (model, full_header, sort_info)); - gtk_object_ref(GTK_OBJECT(etgl->subset)); - gtk_object_sink(GTK_OBJECT(etgl->subset)); - e_table_group_construct (parent, E_TABLE_GROUP (etgl), full_header, header, model); -} - -/** - * e_table_group_leaf_new - * @parent: The %GnomeCanvasGroup to create a child of. - * @full_header: The full header of the %ETable. - * @header: The current header of the %ETable. - * @model: The %ETableModel of the %ETable. - * @sort_info: The %ETableSortInfo of the %ETable. - * - * %ETableGroupLeaf is an %ETableGroup which simply contains an - * %ETableItem. - * - * Returns: The new %ETableGroupLeaf. - */ -ETableGroup * -e_table_group_leaf_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info) -{ - ETableGroupLeaf *etgl; - - g_return_val_if_fail (parent != NULL, NULL); - - etgl = gtk_type_new (e_table_group_leaf_get_type ()); - - e_table_group_leaf_construct (parent, etgl, full_header, - header, model, sort_info); - return E_TABLE_GROUP (etgl); -} - -static void -etgl_cursor_change (GtkObject *object, gint row, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - e_table_group_cursor_change (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row]); -} - -static void -etgl_cursor_activated (GtkObject *object, gint row, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - e_table_group_cursor_activated (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row]); -} - -static void -etgl_double_click (GtkObject *object, gint row, gint col, GdkEvent *event, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - e_table_group_double_click (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row], col, event); -} - -static gint -etgl_key_press (GtkObject *object, gint row, gint col, GdkEvent *event, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - return e_table_group_key_press (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row], col, event); - else - return 0; -} - -static gint -etgl_right_click (GtkObject *object, gint row, gint col, GdkEvent *event, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - return e_table_group_right_click (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row], col, event); - else - return 0; -} - -static gint -etgl_click (GtkObject *object, gint row, gint col, GdkEvent *event, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - return e_table_group_click (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row], col, event); - else - return 0; -} - -static void -etgl_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableGroupLeaf *leaf = E_TABLE_GROUP_LEAF(item); - gtk_object_get(GTK_OBJECT(leaf->item), - "height", &leaf->height, - NULL); - gtk_object_get(GTK_OBJECT(leaf->item), - "width", &leaf->width, - NULL); - e_canvas_item_request_parent_reflow (item); -} - -static void -etgl_realize (GnomeCanvasItem *item) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF(item); - - if (GNOME_CANVAS_ITEM_CLASS (etgl_parent_class)->realize) - GNOME_CANVAS_ITEM_CLASS (etgl_parent_class)->realize (item); - - etgl->item = E_TABLE_ITEM(gnome_canvas_item_new (GNOME_CANVAS_GROUP(etgl), - e_table_item_get_type (), - "ETableHeader", E_TABLE_GROUP(etgl)->header, - "ETableModel", etgl->subset, - "drawgrid", etgl->draw_grid, - "drawfocus", etgl->draw_focus, - "cursor_mode", etgl->cursor_mode, - "minimum_width", etgl->minimum_width, - "length_threshold", etgl->length_threshold, - "table_selection_model", etgl->table_selection_model, - NULL)); - - gtk_signal_connect (GTK_OBJECT(etgl->item), "cursor_change", - GTK_SIGNAL_FUNC(etgl_cursor_change), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "cursor_activated", - GTK_SIGNAL_FUNC(etgl_cursor_activated), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "double_click", - GTK_SIGNAL_FUNC(etgl_double_click), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "right_click", - GTK_SIGNAL_FUNC(etgl_right_click), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "click", - GTK_SIGNAL_FUNC(etgl_click), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "key_press", - GTK_SIGNAL_FUNC(etgl_key_press), etgl); - e_canvas_item_request_reflow(item); -} - -static void -etgl_add (ETableGroup *etg, gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_add (etgl->subset, row); -} - -static void -etgl_add_all (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_add_all (etgl->subset); -} - -static gboolean -etgl_remove (ETableGroup *etg, gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_subset_variable_remove (etgl->subset, row); -} - -static void -etgl_increment (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_increment (etgl->subset, position, amount); -} - -static void -etgl_decrement (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_decrement (etgl->subset, position, amount); -} - -static int -etgl_row_count (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_model_row_count(E_TABLE_MODEL(etgl->subset)); -} - -static void -etgl_set_focus (ETableGroup *etg, EFocus direction, gint view_col) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - if (direction == E_FOCUS_END) { - e_table_item_set_cursor (etgl->item, view_col, e_table_model_row_count(E_TABLE_MODEL(etgl->subset)) - 1); - } else { - e_table_item_set_cursor (etgl->item, view_col, 0); - } -} - -static gint -etgl_get_focus_column (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_item_get_focused_column (etgl->item); -} - -static EPrintable * -etgl_get_printable (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_item_get_printable (etgl->item); -} - -static void -etgl_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_item_compute_location (etgl->item, x, y, row, col); -} - -static void -etgl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - switch (arg_id) { - case ARG_FROZEN: - if (GTK_VALUE_BOOL (*arg)) - etg->frozen = TRUE; - else { - etg->frozen = FALSE; - } - break; - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - etgl->minimum_width = GTK_VALUE_DOUBLE(*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "minimum_width", etgl->minimum_width, - NULL); - } - break; - case ARG_LENGTH_THRESHOLD: - etgl->length_threshold = GTK_VALUE_INT (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - case ARG_TABLE_SELECTION_MODEL: - if (etgl->table_selection_model) - gtk_object_unref(GTK_OBJECT(etgl->table_selection_model)); - etgl->table_selection_model = E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg)); - if (etgl->table_selection_model) - gtk_object_ref(GTK_OBJECT(etgl->table_selection_model)); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "table_selection_model", etgl->table_selection_model, - NULL); - } - - case ARG_TABLE_DRAW_GRID: - etgl->draw_grid = GTK_VALUE_BOOL (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_FOCUS: - etgl->draw_focus = GTK_VALUE_BOOL (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_CURSOR_MODE: - etgl->cursor_mode = GTK_VALUE_INT (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - } - break; - default: - break; - } -} - -static void -etgl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - switch (arg_id) { - case ARG_FROZEN: - GTK_VALUE_BOOL (*arg) = etg->frozen; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etgl->height; - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgl->width; - break; - case ARG_MINIMUM_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgl->minimum_width; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etgl_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *e_group_class = E_TABLE_GROUP_CLASS(object_class); - - object_class->destroy = etgl_destroy; - object_class->set_arg = etgl_set_arg; - object_class->get_arg = etgl_get_arg; - - item_class->realize = etgl_realize; - - etgl_parent_class = gtk_type_class (PARENT_TYPE); - - e_group_class->add = etgl_add; - e_group_class->add_all = etgl_add_all; - e_group_class->remove = etgl_remove; - e_group_class->increment = etgl_increment; - e_group_class->decrement = etgl_decrement; - e_group_class->row_count = etgl_row_count; - e_group_class->set_focus = etgl_set_focus; - e_group_class->get_focus_column = etgl_get_focus_column; - e_group_class->get_printable = etgl_get_printable; - e_group_class->compute_location = etgl_compute_location; - - gtk_object_add_arg_type ("ETableGroupLeaf::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableGroupLeaf::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableGroupLeaf::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableGroupLeaf::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - gtk_object_add_arg_type ("ETableGroupLeaf::table_selection_model", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - - gtk_object_add_arg_type ("ETableGroupLeaf::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableGroupLeaf::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableGroupLeaf::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); - gtk_object_add_arg_type ("ETableGroupLeaf::frozen", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_FROZEN); -} - -static void -etgl_init (GtkObject *object) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - etgl->width = 1; - etgl->height = 1; - etgl->minimum_width = 0; - - etgl->subset = NULL; - etgl->item = NULL; - - etgl->draw_grid = 1; - etgl->draw_focus = 1; - etgl->cursor_mode = E_TABLE_CURSOR_SIMPLE; - etgl->length_threshold = -1; - - etgl->table_selection_model = NULL; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM(object), etgl_reflow); -} - -E_MAKE_TYPE (e_table_group_leaf, "ETableGroupLeaf", ETableGroupLeaf, etgl_class_init, etgl_init, PARENT_TYPE); diff --git a/widgets/table/e-table-group-leaf.h b/widgets/table/e-table-group-leaf.h deleted file mode 100644 index f941b79dcd..0000000000 --- a/widgets/table/e-table-group-leaf.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_LEAF_H_ -#define _E_TABLE_GROUP_LEAF_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gal/e-table/e-table-group.h> -#include <gal/e-table/e-table-sorted-variable.h> -#include <gal/e-table/e-table-item.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_GROUP_LEAF_TYPE (e_table_group_leaf_get_type ()) -#define E_TABLE_GROUP_LEAF(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_LEAF_TYPE, ETableGroupLeaf)) -#define E_TABLE_GROUP_LEAF_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_LEAF_TYPE, ETableGroupLeafClass)) -#define E_IS_TABLE_GROUP_LEAF(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_LEAF_TYPE)) -#define E_IS_TABLE_GROUP_LEAF_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_LEAF_TYPE)) - -typedef struct { - ETableGroup group; - - /* - * Item. - */ - ETableItem *item; - - gdouble height; - gdouble width; - gdouble minimum_width; - - ETableSubsetVariable *subset; - - int length_threshold; - - guint draw_grid : 1; - guint draw_focus : 1; - ETableCursorMode cursor_mode; - - ETableSelectionModel *table_selection_model; -} ETableGroupLeaf; - -typedef struct { - ETableGroupClass parent_class; -} ETableGroupLeafClass; - -ETableGroup *e_table_group_leaf_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info); -GtkType e_table_group_leaf_get_type (void); - - -END_GNOME_DECLS - -#endif /* _E_TABLE_GROUP_LEAF_H_ */ - diff --git a/widgets/table/e-table-group.c b/widgets/table/e-table-group.c deleted file mode 100644 index d87546db0d..0000000000 --- a/widgets/table/e-table-group.c +++ /dev/null @@ -1,603 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Miguel de Icaza (miguel@ximian.com) - * Chris Lahey (clahey@ximian.com) - * - * Copyright 1999, 2000 Ximian, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-table-group.h" -#include "e-table-group-container.h" -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include "gal/util/e-util.h" - -#define PARENT_TYPE gnome_canvas_group_get_type () - -#define ETG_CLASS(e) (E_TABLE_GROUP_CLASS(GTK_OBJECT(e)->klass)) - -static GnomeCanvasGroupClass *etg_parent_class; - -enum { - CURSOR_CHANGE, - CURSOR_ACTIVATED, - DOUBLE_CLICK, - RIGHT_CLICK, - CLICK, - KEY_PRESS, - LAST_SIGNAL -}; - -static gint etg_signals [LAST_SIGNAL] = { 0, }; - -static gboolean etg_get_focus (ETableGroup *etg); -static void etg_destroy (GtkObject *object); - -static void -etg_destroy (GtkObject *object) -{ - ETableGroup *etg = E_TABLE_GROUP(object); - if (etg->header) - gtk_object_unref (GTK_OBJECT(etg->header)); - if (etg->full_header) - gtk_object_unref (GTK_OBJECT(etg->full_header)); - if (etg->model) - gtk_object_unref (GTK_OBJECT(etg->model)); - if (GTK_OBJECT_CLASS (etg_parent_class)->destroy) - GTK_OBJECT_CLASS (etg_parent_class)->destroy (object); -} - -/** - * e_table_group_new - * @parent: The %GnomeCanvasGroup to create a child of. - * @full_header: The full header of the %ETable. - * @header: The current header of the %ETable. - * @model: The %ETableModel of the %ETable. - * @sort_info: The %ETableSortInfo of the %ETable. - * @n: The grouping information object to group by. - * - * %ETableGroup is a collection of rows of an %ETable. It's a - * %GnomeCanvasItem. There are two different forms. If n < the - * number of groupings in the given %ETableSortInfo, then the - * %ETableGroup will need to contain other %ETableGroups, thus it - * creates an %ETableGroupContainer. Otherwise, it will just contain - * an %ETableItem, and thus it creates an %ETableGroupLeaf. - * - * Returns: The new %ETableGroup. - */ -ETableGroup * -e_table_group_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - int n) -{ - g_return_val_if_fail (model != NULL, NULL); - - if (n < e_table_sort_info_grouping_get_count(sort_info)) { - return e_table_group_container_new (parent, full_header, header, model, sort_info, n); - } else { - return e_table_group_leaf_new (parent, full_header, header, model, sort_info); - } - return NULL; -} - -/** - * e_table_group_construct - * @parent: The %GnomeCanvasGroup to create a child of. - * @etg: The %ETableGroup to construct. - * @full_header: The full header of the %ETable. - * @header: The current header of the %ETable. - * @model: The %ETableModel of the %ETable. - * - * This routine does the base construction of the %ETableGroup. - */ -void -e_table_group_construct (GnomeCanvasGroup *parent, - ETableGroup *etg, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model) -{ - etg->full_header = full_header; - gtk_object_ref (GTK_OBJECT(etg->full_header)); - etg->header = header; - gtk_object_ref (GTK_OBJECT(etg->header)); - etg->model = model; - gtk_object_ref (GTK_OBJECT(etg->model)); - gnome_canvas_item_constructv (GNOME_CANVAS_ITEM (etg), parent, 0, NULL); -} - -/** - * e_table_group_add - * @etg: The %ETableGroup to add a row to - * @row: The row to add. - * - * This routine adds the given row from the %ETableModel to this set - * of rows. - */ -void -e_table_group_add (ETableGroup *etg, - gint row) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->add) - ETG_CLASS (etg)->add (etg, row); -} - -/** - * e_table_group_add_all - * @etg: The %ETableGroup to add to - * - * This routine adds all the rows from the %ETableModel to this set - * of rows. - */ -void -e_table_group_add_all (ETableGroup *etg) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->add_all) - ETG_CLASS (etg)->add_all (etg); -} - -/** - * e_table_group_remove - * @etg: The %ETableGroup to remove a row from - * @row: The row to remove. - * - * This routine removes the given row from the %ETableModel from this - * set of rows. - * - * Returns: TRUE if the row was deleted and FALSE if the row was not - * found. - */ -gboolean -e_table_group_remove (ETableGroup *etg, - gint row) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->remove) - return ETG_CLASS (etg)->remove (etg, row); - else - return FALSE; -} - -/** - * e_table_group_increment - * @etg: The %ETableGroup to increment - * @position: The position to increment from - * @amount: The amount to increment. - * - * This routine adds amount to all rows greater than or equal to - * position. This is to handle when a row gets inserted into the - * model. - */ -void -e_table_group_increment (ETableGroup *etg, - gint position, - gint amount) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->increment) - ETG_CLASS (etg)->increment (etg, position, amount); -} - -/** - * e_table_group_increment - * @etg: The %ETableGroup to decrement - * @position: The position to decrement from - * @amount: The amount to decrement - * - * This routine removes amount from all rows greater than or equal to - * position. This is to handle when a row gets deleted from the - * model. - */ -void -e_table_group_decrement (ETableGroup *etg, - gint position, - gint amount) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->decrement) - ETG_CLASS (etg)->decrement (etg, position, amount); -} - -/** - * e_table_group_increment - * @etg: The %ETableGroup to count - * - * This routine calculates the number of rows shown in this group. - * - * Returns: The number of rows. - */ -gint -e_table_group_row_count (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), 0); - - if (ETG_CLASS (etg)->row_count) - return ETG_CLASS (etg)->row_count (etg); - else - return 0; -} - -/** - * e_table_group_set_focus - * @etg: The %ETableGroup to set - * @direction: The direction the focus is coming from. - * @view_col: The column to set the focus in. - * - * Sets the focus to this widget. Places the focus in the view column - * coming from direction direction. - */ -void -e_table_group_set_focus (ETableGroup *etg, - EFocus direction, - gint view_col) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->set_focus) - ETG_CLASS (etg)->set_focus (etg, direction, view_col); -} - -/** - * e_table_group_get_focus - * @etg: The %ETableGroup to check - * - * Calculates if this group has the focus. - * - * Returns: TRUE if this group has the focus. - */ -gboolean -e_table_group_get_focus (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->get_focus) - return ETG_CLASS (etg)->get_focus (etg); - else - return FALSE; -} - -/** - * e_table_group_get_focus_column - * @etg: The %ETableGroup to check - * - * Calculates which column in this group has the focus. - * - * Returns: The column index (view column). - */ -gint -e_table_group_get_focus_column (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->get_focus_column) - return ETG_CLASS (etg)->get_focus_column (etg); - else - return -1; -} - -/** - * e_table_group_get_printable - * @etg: %ETableGroup which will be printed - * - * This routine creates and returns an %EPrintable that can be used to - * print the given %ETableGroup. - * - * Returns: The %EPrintable. - */ -EPrintable * -e_table_group_get_printable (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), NULL); - - if (ETG_CLASS (etg)->get_printable) - return ETG_CLASS (etg)->get_printable (etg); - else - return NULL; -} - -/** - * e_table_group_compute_location - * @eti: %ETableGroup to look in. - * @x: A pointer to the x location to find in the %ETableGroup. - * @y: A pointer to the y location to find in the %ETableGroup. - * @row: A pointer to the location to store the found row in. - * @col: A pointer to the location to store the found col in. - * - * This routine locates the pixel location (*x, *y) in the - * %ETableGroup. If that location is in the %ETableGroup, *row and - * *col are set to the view row and column where it was found. If - * that location is not in the %ETableGroup, the height of the - * %ETableGroup is removed from the value y points to. - */ -void -e_table_group_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->compute_location) - ETG_CLASS (etg)->compute_location (etg, x, y, row, col); -} - -/** - * e_table_group_cursor_change - * @eti: %ETableGroup to emit the signal on - * @row: The new cursor row (model row) - * - * This routine emits the "cursor_change" signal. - */ -void -e_table_group_cursor_change (ETableGroup *e_table_group, gint row) -{ - g_return_if_fail (e_table_group != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (e_table_group)); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [CURSOR_CHANGE], - row); -} - -/** - * e_table_group_cursor_activated - * @eti: %ETableGroup to emit the signal on - * @row: The cursor row (model row) - * - * This routine emits the "cursor_activated" signal. - */ -void -e_table_group_cursor_activated (ETableGroup *e_table_group, gint row) -{ - g_return_if_fail (e_table_group != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (e_table_group)); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [CURSOR_ACTIVATED], - row); -} - -/** - * e_table_group_double_click - * @eti: %ETableGroup to emit the signal on - * @row: The row clicked on (model row) - * @col: The col clicked on (model col) - * @event: The event that caused this signal - * - * This routine emits the "double_click" signal. - */ -void -e_table_group_double_click (ETableGroup *e_table_group, gint row, gint col, GdkEvent *event) -{ - g_return_if_fail (e_table_group != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (e_table_group)); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [DOUBLE_CLICK], - row, col, event); -} - -/** - * e_table_group_right_click - * @eti: %ETableGroup to emit the signal on - * @row: The row clicked on (model row) - * @col: The col clicked on (model col) - * @event: The event that caused this signal - * - * This routine emits the "right_click" signal. - */ -gint -e_table_group_right_click (ETableGroup *e_table_group, gint row, gint col, GdkEvent *event) -{ - gint return_val = 0; - - g_return_val_if_fail (e_table_group != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), 0); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [RIGHT_CLICK], - row, col, event, &return_val); - - return return_val; -} - -/** - * e_table_group_click - * @eti: %ETableGroup to emit the signal on - * @row: The row clicked on (model row) - * @col: The col clicked on (model col) - * @event: The event that caused this signal - * - * This routine emits the "click" signal. - */ -gint -e_table_group_click (ETableGroup *e_table_group, gint row, gint col, GdkEvent *event) -{ - gint return_val = 0; - - g_return_val_if_fail (e_table_group != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), 0); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [CLICK], - row, col, event, &return_val); - - return return_val; -} - -/** - * e_table_group_key_press - * @eti: %ETableGroup to emit the signal on - * @row: The cursor row (model row) - * @col: The cursor col (model col) - * @event: The event that caused this signal - * - * This routine emits the "key_press" signal. - */ -gint -e_table_group_key_press (ETableGroup *e_table_group, gint row, gint col, GdkEvent *event) -{ - gint return_val = 0; - - g_return_val_if_fail (e_table_group != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), 0); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [KEY_PRESS], - row, col, event, &return_val); - - return return_val; -} - -/** - * e_table_group_get_header - * @eti: %ETableGroup to check - * - * This routine returns the %ETableGroup's header. - * - * Returns: The %ETableHeader. - */ -ETableHeader * -e_table_group_get_header (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), NULL); - - return etg->header; -} - -static int -etg_event (GnomeCanvasItem *item, GdkEvent *event) -{ - ETableGroup *etg = E_TABLE_GROUP (item); - gboolean return_val = TRUE; - - switch (event->type) { - - case GDK_FOCUS_CHANGE: - etg->has_focus = event->focus_change.in; - return_val = FALSE; - - default: - return_val = FALSE; - } - if (return_val == FALSE){ - if (GNOME_CANVAS_ITEM_CLASS(etg_parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(etg_parent_class)->event (item, event); - } - return return_val; - -} - -static gboolean -etg_get_focus (ETableGroup *etg) -{ - return etg->has_focus; -} - -static void -etg_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *klass = (ETableGroupClass *) object_class; - - object_class->destroy = etg_destroy; - - item_class->event = etg_event; - - klass->cursor_change = NULL; - klass->cursor_activated = NULL; - klass->double_click = NULL; - klass->right_click = NULL; - klass->click = NULL; - klass->key_press = NULL; - - klass->add = NULL; - klass->add_all = NULL; - klass->remove = NULL; - klass->row_count = NULL; - klass->increment = NULL; - klass->decrement = NULL; - klass->set_focus = NULL; - klass->get_focus = etg_get_focus; - klass->get_printable = NULL; - klass->compute_location = NULL; - - etg_parent_class = gtk_type_class (PARENT_TYPE); - - etg_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - etg_signals [CURSOR_ACTIVATED] = - gtk_signal_new ("cursor_activated", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, cursor_activated), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - etg_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, double_click), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - etg_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - etg_signals [CLICK] = - gtk_signal_new ("click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - etg_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, etg_signals, LAST_SIGNAL); -} - -E_MAKE_TYPE (e_table_group, "ETableGroup", ETableGroup, etg_class_init, NULL, PARENT_TYPE); diff --git a/widgets/table/e-table-group.glade b/widgets/table/e-table-group.glade deleted file mode 100644 index 39274d3c61..0000000000 --- a/widgets/table/e-table-group.glade +++ /dev/null @@ -1,208 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <directory></directory> - <source_directory>src</source_directory> - <pixmaps_directory>pixmaps</pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>False</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <backup_source_files>False</backup_source_files> - <main_source_file>interface.c</main_source_file> - <main_header_file>interface.h</main_header_file> - <handler_source_file>callbacks.c</handler_source_file> - <handler_header_file>callbacks.h</handler_header_file> - <support_source_file>support.c</support_source_file> - <support_header_file>support.h</support_header_file> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-group.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GtkWindow</class> - <name>window1</name> - <title>window1</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - - <widget> - <class>GtkTable</class> - <name>table1</name> - <rows>3</rows> - <columns>3</columns> - <homogeneous>False</homogeneous> - <row_spacing>0</row_spacing> - <column_spacing>0</column_spacing> - - <widget> - <class>GtkFrame</class> - <name>frame1</name> - <border_width>4</border_width> - <label>Available fields</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>True</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow1</name> - <hscrollbar_policy>GTK_POLICY_ALWAYS</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - - <widget> - <class>GtkCList</class> - <name>clist1</name> - <can_focus>True</can_focus> - <columns>1</columns> - <column_widths>80</column_widths> - <selection_mode>GTK_SELECTION_SINGLE</selection_mode> - <show_titles>False</show_titles> - <shadow_type>GTK_SHADOW_NONE</shadow_type> - - <widget> - <class>GtkLabel</class> - <child_name>CList:title</child_name> - <name>label1</name> - <label>label1</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame2</name> - <border_width>4</border_width> - <label>Show in this order</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>2</left_attach> - <right_attach>3</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow2</name> - <hscrollbar_policy>GTK_POLICY_ALWAYS</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - - <widget> - <class>GtkCList</class> - <name>clist2</name> - <can_focus>True</can_focus> - <columns>1</columns> - <column_widths>80</column_widths> - <selection_mode>GTK_SELECTION_SINGLE</selection_mode> - <show_titles>False</show_titles> - <shadow_type>GTK_SHADOW_NONE</shadow_type> - - <widget> - <class>GtkLabel</class> - <child_name>CList:title</child_name> - <name>label2</name> - <label>label2</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox1</name> - <border_width>4</border_width> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>4</xpad> - <ypad>4</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>False</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkButton</class> - <name>button1</name> - <border_width>4</border_width> - <can_focus>True</can_focus> - <label>Add >></label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button2</name> - <border_width>4</border_width> - <can_focus>True</can_focus> - <label><< Remove</label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/table/e-table-group.glade.h b/widgets/table/e-table-group.glade.h deleted file mode 100644 index 3ab6304734..0000000000 --- a/widgets/table/e-table-group.glade.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("window1"); -gchar *s = N_("Available fields"); -gchar *s = N_("label1"); -gchar *s = N_("Show in this order"); -gchar *s = N_("label2"); -gchar *s = N_("Add >>"); -gchar *s = N_("<< Remove"); diff --git a/widgets/table/e-table-group.h b/widgets/table/e-table-group.h deleted file mode 100644 index 64ebc37ff0..0000000000 --- a/widgets/table/e-table-group.h +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_H_ -#define _E_TABLE_GROUP_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-header.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-defines.h> -#include <gal/util/e-util.h> -#include <gal/widgets/e-printable.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_GROUP_TYPE (e_table_group_get_type ()) -#define E_TABLE_GROUP(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_TYPE, ETableGroup)) -#define E_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_TYPE, ETableGroupClass)) -#define E_IS_TABLE_GROUP(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_TYPE)) -#define E_IS_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_TYPE)) - -typedef struct { - GnomeCanvasGroup group; - - /* - * The full header. - */ - ETableHeader *full_header; - ETableHeader *header; - - /* - * The model we pull data from. - */ - ETableModel *model; - - /* - * Whether we should add indentation and open/close markers, - * or if we just act as containers of subtables. - */ - guint transparent : 1; - - guint has_focus : 1; - - guint frozen : 1; -} ETableGroup; - -typedef struct { - GnomeCanvasGroupClass parent_class; - - /* Signals */ - void (*cursor_change) (ETableGroup *etg, int row); - void (*cursor_activated) (ETableGroup *etg, int row); - void (*double_click) (ETableGroup *etg, int row, int col, GdkEvent *event); - gint (*right_click) (ETableGroup *etg, int row, int col, GdkEvent *event); - gint (*click) (ETableGroup *etg, int row, int col, GdkEvent *event); - gint (*key_press) (ETableGroup *etg, int row, int col, GdkEvent *event); - - /* Virtual functions. */ - void (*add) (ETableGroup *etg, gint row); - void (*add_all) (ETableGroup *etg); - gboolean (*remove) (ETableGroup *etg, gint row); - gint (*row_count) (ETableGroup *etg); - void (*increment) (ETableGroup *etg, gint position, gint amount); - void (*decrement) (ETableGroup *etg, gint position, gint amount); - void (*set_focus) (ETableGroup *etg, EFocus direction, gint view_col); - gboolean (*get_focus) (ETableGroup *etg); - gint (*get_focus_column) (ETableGroup *etg); - EPrintable *(*get_printable) (ETableGroup *etg); - void (*compute_location) (ETableGroup *etg, int *x, int *y, int *row, int *col); - -} ETableGroupClass; - -/* Virtual functions */ -void e_table_group_add (ETableGroup *etg, - gint row); -void e_table_group_add_all (ETableGroup *etg); -gboolean e_table_group_remove (ETableGroup *etg, - gint row); -void e_table_group_increment (ETableGroup *etg, - gint position, - gint amount); -void e_table_group_decrement (ETableGroup *etg, - gint position, - gint amount); -gint e_table_group_row_count (ETableGroup *etg); -void e_table_group_set_focus (ETableGroup *etg, - EFocus direction, - gint view_col); -gboolean e_table_group_get_focus (ETableGroup *etg); -gint e_table_group_get_focus_column (ETableGroup *etg); -ETableHeader *e_table_group_get_header (ETableGroup *etg); -EPrintable *e_table_group_get_printable (ETableGroup *etg); -void e_table_group_compute_location (ETableGroup *etg, - int *x, - int *y, - int *row, - int *col); - -ETableGroup *e_table_group_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - int n); -void e_table_group_construct (GnomeCanvasGroup *parent, - ETableGroup *etg, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model); - -/* For emitting the signals */ -void e_table_group_cursor_change (ETableGroup *etg, - gint row); -void e_table_group_cursor_activated (ETableGroup *etg, - gint row); -void e_table_group_double_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -gint e_table_group_right_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -gint e_table_group_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -gint e_table_group_key_press (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -GtkType e_table_group_get_type (void); - -typedef void (*ETableGroupLeafFn) (void *e_table_item, void *closure); -void e_table_group_apply_to_leafs (ETableGroup *etg, - ETableGroupLeafFn fn, - void *closure); - -END_GNOME_DECLS - -#endif /* _E_TABLE_GROUP_H_ */ diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c deleted file mode 100644 index 70bdb3d698..0000000000 --- a/widgets/table/e-table-header-item.c +++ /dev/null @@ -1,1596 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-column-view.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000, 2001 Ximian, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkdnd.h> -#include "gal/util/e-i18n.h" -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-polygon.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include "gal/widgets/e-cursors.h" -#include "gal/util/e-xml-utils.h" -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-popup-menu.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-header-utils.h" -#include "e-table-col-dnd.h" -#include "e-table-defines.h" -#include "e-table-field-chooser-dialog.h" -#include "e-table-config.h" -#include "e-table.h" - -#include "add-col.xpm" -#include "remove-col.xpm" -#include "arrow-up.xpm" -#include "arrow-down.xpm" - -enum { - BUTTON_PRESSED, - LAST_SIGNAL -}; - -static guint ethi_signals [LAST_SIGNAL] = { 0, }; - -#define ARROW_DOWN_HEIGHT 16 -#define ARROW_PTR 7 - -/* Defines the tolerance for proximity of the column division to the cursor position */ -#define TOLERANCE 4 - -#define ETHI_RESIZING(x) ((x)->resize_col != -1) - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasItemClass *ethi_parent_class; - -static void ethi_drop_table_header (ETableHeaderItem *ethi); - -/* - * They display the arrows for the drop location. - */ - -static GtkWidget *arrow_up, *arrow_down; - -/* - * DnD icons - */ -static GdkColormap *dnd_colormap; -static GdkPixmap *remove_col_pixmap, *remove_col_mask; -static GdkPixmap *add_col_pixmap, *add_col_mask; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_FULL_HEADER, - ARG_DND_CODE, - ARG_TABLE_FONTSET, - ARG_SORT_INFO, - ARG_TABLE, -}; - -static void -ethi_destroy (GtkObject *object){ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (object); - - ethi_drop_table_header (ethi); - - if (ethi->dnd_code) { - g_free (ethi->dnd_code); - ethi->dnd_code = NULL; - } - - if (ethi->sort_info) { - if (ethi->sort_info_changed_id) - gtk_signal_disconnect (GTK_OBJECT(ethi->sort_info), ethi->sort_info_changed_id); - if (ethi->group_info_changed_id) - gtk_signal_disconnect (GTK_OBJECT(ethi->sort_info), ethi->group_info_changed_id); - gtk_object_unref (GTK_OBJECT(ethi->sort_info)); - ethi->sort_info = NULL; - } - - if (ethi->full_header) - gtk_object_unref (GTK_OBJECT(ethi->full_header)); - - if (ethi->config) - gtk_object_destroy (GTK_OBJECT (ethi->config)); - - if (GTK_OBJECT_CLASS (ethi_parent_class)->destroy) - (*GTK_OBJECT_CLASS (ethi_parent_class)->destroy) (object); -} - -static int -e_table_header_item_get_height (ETableHeaderItem *ethi) -{ - ETableHeader *eth; - int numcols, col; - int maxheight; - GtkStyle *style; - - g_return_val_if_fail (ethi != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER_ITEM (ethi), 0); - - eth = ethi->eth; - numcols = e_table_header_count (eth); - - maxheight = 0; - - style = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas)->style; - - for (col = 0; col < numcols; col++) { - ETableCol *ecol = e_table_header_get_column (eth, col); - int height; - - height = e_table_header_compute_height (ecol, style, ethi->font); - - if (height > maxheight) - maxheight = height; - } - - return maxheight; -} - -static void -ethi_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - double i2c [6]; - ArtPoint c1, c2, i1, i2; - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update)(item, affine, clip_path, flags); - - - if (ethi->sort_info) - ethi->group_indent_width = e_table_sort_info_grouping_get_count(ethi->sort_info) * GROUP_INDENT; - else - ethi->group_indent_width = 0; - - ethi->width = e_table_header_total_width (ethi->eth) + ethi->group_indent_width; - - i1.x = i1.y = 0; - i2.x = ethi->width; - i2.y = ethi->height; - - gnome_canvas_item_i2c_affine (item, i2c); - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - if (item->x1 != c1.x || - item->y1 != c1.y || - item->x2 != c2.x || - item->y2 != c2.y) - { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - item->x1 = c1.x; - item->y1 = c1.y; - item->x2 = c2.x; - item->y2 = c2.y; - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); - } - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); -} - -static void -ethi_font_set (ETableHeaderItem *ethi, GdkFont *font) -{ - if (ethi->font) - gdk_font_unref (ethi->font); - - ethi->font = font; - - ethi->height = e_table_header_item_get_height (ethi); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_font_load (ETableHeaderItem *ethi, char *fontname) -{ - GdkFont *font; - - font = gdk_fontset_load (fontname); - if (font == NULL) - font = gdk_font_load ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"); - - ethi_font_set (ethi, font); -} - -static void -ethi_drop_table_header (ETableHeaderItem *ethi) -{ - GtkObject *header; - - if (!ethi->eth) - return; - - header = GTK_OBJECT (ethi->eth); - gtk_signal_disconnect (header, ethi->structure_change_id); - gtk_signal_disconnect (header, ethi->dimension_change_id); - - gtk_object_unref (header); - ethi->eth = NULL; - ethi->width = 0; -} - -static void -structure_changed (ETableHeader *header, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -dimension_changed (ETableHeader *header, int col, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_add_table_header (ETableHeaderItem *ethi, ETableHeader *header) -{ - ethi->eth = header; - gtk_object_ref (GTK_OBJECT (ethi->eth)); - - ethi->height = e_table_header_item_get_height (ethi); - - ethi->structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC(structure_changed), ethi); - ethi->dimension_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC(dimension_changed), ethi); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(ethi)); - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_sort_info_changed (ETableSortInfo *sort_info, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableHeaderItem *ethi; - - item = GNOME_CANVAS_ITEM (o); - ethi = E_TABLE_HEADER_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - ethi_drop_table_header (ethi); - ethi_add_table_header (ethi, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_FULL_HEADER: - if (ethi->full_header) - gtk_object_unref(GTK_OBJECT(ethi->full_header)); - ethi->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg)); - if (ethi->full_header) - gtk_object_ref(GTK_OBJECT(ethi->full_header)); - break; - - case ARG_DND_CODE: - g_free(ethi->dnd_code); - ethi->dnd_code = g_strdup (GTK_VALUE_STRING (*arg)); - break; - - case ARG_TABLE_FONTSET: - ethi_font_load (ethi, GTK_VALUE_STRING (*arg)); - break; - - case ARG_SORT_INFO: - if (ethi->sort_info){ - if (ethi->sort_info_changed_id) - gtk_signal_disconnect ( - GTK_OBJECT(ethi->sort_info), - ethi->sort_info_changed_id); - - if (ethi->group_info_changed_id) - gtk_signal_disconnect ( - GTK_OBJECT(ethi->sort_info), - ethi->group_info_changed_id); - gtk_object_unref (GTK_OBJECT(ethi->sort_info)); - } - ethi->sort_info = GTK_VALUE_POINTER (*arg); - gtk_object_ref (GTK_OBJECT(ethi->sort_info)); - ethi->sort_info_changed_id = - gtk_signal_connect ( - GTK_OBJECT(ethi->sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC(ethi_sort_info_changed), ethi); - ethi->group_info_changed_id = - gtk_signal_connect ( - GTK_OBJECT(ethi->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC(ethi_sort_info_changed), ethi); - break; - case ARG_TABLE: - if (GTK_VALUE_OBJECT(*arg)) - ethi->table = E_TABLE(GTK_VALUE_OBJECT(*arg)); - else - ethi->table = NULL; - break; - } - gnome_canvas_item_request_update(item); -} - -static void -ethi_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableHeaderItem *ethi; - - ethi = E_TABLE_HEADER_ITEM (o); - - switch (arg_id){ - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT (ethi->full_header); - break; - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (ethi->dnd_code); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static int -ethi_find_col_by_x (ETableHeaderItem *ethi, int x) -{ - const int cols = e_table_header_count (ethi->eth); - int x1 = 0; - int col; - - if (x < x1) - return -1; - - x1 += ethi->group_indent_width; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if ((x >= x1) && (x <= x1 + ecol->width)) - return col; - - x1 += ecol->width; - } - return -1; -} - -static int -ethi_find_col_by_x_nearest (ETableHeaderItem *ethi, int x) -{ - const int cols = e_table_header_count (ethi->eth); - int x1 = 0; - int col; - - if (x < x1) - return -1; - - x1 += ethi->group_indent_width; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - x1 += (ecol->width / 2); - - if (x <= x1) - return col; - - x1 += (ecol->width + 1) / 2; - } - return col; -} - -static void -ethi_remove_drop_marker (ETableHeaderItem *ethi) -{ - if (ethi->drag_mark == -1) - return; - - gtk_widget_hide (arrow_up); - gtk_widget_hide (arrow_down); - - ethi->drag_mark = -1; -} - -static GtkWidget * -make_shaped_window_from_xpm (const char **xpm) -{ - GdkPixbuf *pixbuf; - GdkPixmap *pixmap; - GdkBitmap *bitmap; - GtkWidget *win, *pix; - - pixbuf = gdk_pixbuf_new_from_xpm_data (xpm); - gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 128); - gdk_pixbuf_unref (pixbuf); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - win = gtk_window_new (GTK_WINDOW_POPUP); - pix = gtk_pixmap_new (pixmap, bitmap); - gtk_widget_realize (win); - gtk_container_add (GTK_CONTAINER (win), pix); - gtk_widget_shape_combine_mask (win, bitmap, 0, 0); - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - gdk_pixmap_unref (pixmap); - gdk_bitmap_unref (bitmap); - - return win; -} - -static void -ethi_add_drop_marker (ETableHeaderItem *ethi, int col) -{ - int rx, ry; - int x; - - if (ethi->drag_mark == col) - return; - - ethi->drag_mark = col; - - x = e_table_header_col_diff (ethi->eth, 0, col); - if (col > 0) - x += ethi->group_indent_width; - - if (!arrow_up){ - arrow_up = make_shaped_window_from_xpm (arrow_up_xpm); - arrow_down = make_shaped_window_from_xpm (arrow_down_xpm); - } - - gdk_window_get_origin ( - GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas)->window, - &rx, &ry); - - gtk_widget_set_uposition (arrow_down, rx + x - ARROW_PTR, ry - ARROW_DOWN_HEIGHT); - gtk_widget_show_all (arrow_down); - - gtk_widget_set_uposition (arrow_up, rx + x - ARROW_PTR, ry + ethi->height); - gtk_widget_show_all (arrow_up); -} - -#define gray50_width 2 -#define gray50_height 2 -static char gray50_bits [] = { - 0x02, 0x01, }; - -static void -ethi_add_destroy_marker (ETableHeaderItem *ethi) -{ - double x1; - - if (ethi->remove_item) - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - - if (!ethi->stipple) - ethi->stipple = gdk_bitmap_create_from_data ( - NULL, gray50_bits, gray50_width, gray50_height); - - x1 = (double) e_table_header_col_diff (ethi->eth, 0, ethi->drag_col); - if (ethi->drag_col > 0) - x1 += ethi->group_indent_width; - - ethi->remove_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS_ITEM (ethi)->canvas->root), - gnome_canvas_rect_get_type (), - "x1", x1 + 1, - "y1", (double) 1, - "x2", (double) x1 + e_table_header_col_diff ( - ethi->eth, ethi->drag_col, ethi->drag_col+1) - 2, - - "y2", (double) ethi->height - 2, - "fill_color", "red", - "fill_stipple", ethi->stipple, - NULL); -} - -static void -ethi_remove_destroy_marker (ETableHeaderItem *ethi) -{ - if (!ethi->remove_item) - return; - - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - ethi->remove_item = NULL; -} - -#if 0 -static gboolean -moved (ETableHeaderItem *ethi, guint col, guint model_col) -{ - if (col == -1) - return TRUE; - ecol = e_table_header_get_column (ethi->eth, col); - if (ecol->col_idx == model_col) - return FALSE; - if (col > 0) { - ecol = e_table_header_get_column (ethi->eth, col - 1); - if (ecol->col_idx == model_col) - return FALSE; - } - return TRUE; -} -#endif - -static gboolean -ethi_drag_motion (GtkObject *canvas, GdkDragContext *context, - gint x, gint y, guint time, - ETableHeaderItem *ethi) -{ - char *droptype, *headertype; - - gdk_drag_status (context, 0, time); - - droptype = gdk_atom_name (GPOINTER_TO_INT (context->targets->data)); - headertype = g_strdup_printf ("%s-%s", TARGET_ETABLE_COL_TYPE, - ethi->dnd_code); - - if (strcmp (droptype, headertype) != 0) { - g_free (headertype); - return FALSE; - } - - g_free (headertype); - - if ((x >= 0) && (x <= (ethi->width)) && - (y >= 0) && (y <= (ethi->height))){ - int col; - - col = ethi_find_col_by_x_nearest (ethi, x); - - if (col == ethi->drag_col || col == ethi->drag_col + 1) { - if (ethi->drag_col != -1) - ethi_remove_destroy_marker (ethi); - - ethi_remove_drop_marker (ethi); - gdk_drag_status (context, context->suggested_action, time); - } - else if (col != -1){ - if (ethi->drag_col != -1) - ethi_remove_destroy_marker (ethi); - - ethi_add_drop_marker (ethi, col); - gdk_drag_status (context, context->suggested_action, time); - } else { - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); - } - } else { - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); - } - - return TRUE; -} - -static void -ethi_drag_end (GtkWidget *canvas, GdkDragContext *context, ETableHeaderItem *ethi) -{ - if (context->action == 0) { - e_table_header_remove (ethi->eth, ethi->drag_col); - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); - } - ethi_remove_drop_marker (ethi); - ethi_remove_destroy_marker (ethi); - ethi->drag_col = -1; -} - -static void -ethi_drag_data_received (GtkWidget *canvas, - GdkDragContext *drag_context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - ETableHeaderItem *ethi) -{ - int found = FALSE; - int count = e_table_header_count(ethi->eth); - int column = atoi(data->data); - int drop_col = ethi->drop_col; - int i; - ethi->drop_col = -1; - - if (column < 0) - return; - for (i = 0; i < count; i++) { - ETableCol *ecol = e_table_header_get_column (ethi->eth, i); - if (ecol->col_idx == column) { - e_table_header_move(ethi->eth, i, drop_col); - found = TRUE; - break; - } - } - if (!found) { - count = e_table_header_count(ethi->full_header); - for (i = 0; i < count; i++) { - ETableCol *ecol = e_table_header_get_column (ethi->full_header, i); - if (ecol->col_idx == column) { - e_table_header_add_column (ethi->eth, ecol, drop_col); - break; - } - } - } - ethi_remove_drop_marker (ethi); - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_drag_data_get (GtkWidget *canvas, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETableHeaderItem *ethi) -{ - if (ethi->drag_col != -1) { - ETableCol *ecol = e_table_header_get_column (ethi->eth, ethi->drag_col); - - gchar *string = g_strdup_printf("%d", ecol->col_idx); - gtk_selection_data_set(selection_data, - GDK_SELECTION_TYPE_STRING, - sizeof(string[0]), - string, - strlen(string)); - g_free(string); - } -} - -static gboolean -ethi_drag_drop (GtkWidget *canvas, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETableHeaderItem *ethi) -{ - gboolean successful = FALSE; - - if ((x >= 0) && (x <= (ethi->width)) && - (y >= 0) && (y <= (ethi->height))){ - int col; - - col = ethi_find_col_by_x_nearest (ethi, x); - - ethi_add_drop_marker (ethi, col); - - ethi->drop_col = col; - - if (col != -1) { - char *target = g_strdup_printf ("%s-%s", TARGET_ETABLE_COL_TYPE, ethi->dnd_code); - gtk_drag_get_data (canvas, context, gdk_atom_intern(target, FALSE), time); - g_free (target); - } - } - gtk_drag_finish (context, successful, successful, time); - return successful; -} - -static void -ethi_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, ETableHeaderItem *ethi) -{ - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); -} - -static void -ethi_realize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GdkWindow *window; - GdkColor c; - GtkTargetEntry ethi_drop_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - ethi->gc = gdk_gc_new (window); - gnome_canvas_get_color (item->canvas, "black", &c); - gdk_gc_set_foreground (ethi->gc, &c); - - if (!ethi->font) - ethi_font_set (ethi, GTK_WIDGET (item->canvas)->style->font); - - /* - * Now, configure DnD - */ - ethi_drop_types[0].target = g_strdup_printf("%s-%s", ethi_drop_types[0].target, ethi->dnd_code); - gtk_drag_dest_set (GTK_WIDGET (item->canvas), 0, - ethi_drop_types, ELEMENTS (ethi_drop_types), - GDK_ACTION_MOVE); - g_free(ethi_drop_types[0].target); - - /* Drop signals */ - ethi->drag_motion_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_motion", - GTK_SIGNAL_FUNC (ethi_drag_motion), ethi); - ethi->drag_leave_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_leave", - GTK_SIGNAL_FUNC (ethi_drag_leave), ethi); - ethi->drag_drop_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_drop", - GTK_SIGNAL_FUNC (ethi_drag_drop), ethi); - ethi->drag_data_received_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_data_received", - GTK_SIGNAL_FUNC (ethi_drag_data_received), ethi); - - /* Drag signals */ - ethi->drag_end_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_end", - GTK_SIGNAL_FUNC (ethi_drag_end), ethi); - ethi->drag_data_get_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_data_get", - GTK_SIGNAL_FUNC (ethi_drag_data_get), ethi); - -} - -static void -ethi_unrealize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - gdk_gc_unref (ethi->gc); - ethi->gc = NULL; - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_motion_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_leave_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_drop_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_data_received_id); - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_end_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_data_get_id); - - if (ethi->stipple){ - gdk_bitmap_unref (ethi->stipple); - ethi->stipple = NULL; - } - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); -} - -static void -ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const int cols = e_table_header_count (ethi->eth); - int x1, x2; - int col; - GHashTable *arrows = g_hash_table_new (NULL, NULL); - - - if (ethi->sort_info) { - int length = e_table_sort_info_grouping_get_count(ethi->sort_info); - int i; - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - g_hash_table_insert (arrows, - (gpointer) column.column, - (gpointer) (column.ascending ? - E_TABLE_COL_ARROW_UP : - E_TABLE_COL_ARROW_DOWN)); - } - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(ethi->sort_info, i); - g_hash_table_insert (arrows, - (gpointer) column.column, - (gpointer) (column.ascending ? - E_TABLE_COL_ARROW_UP : - E_TABLE_COL_ARROW_DOWN)); - } - } - - ethi->width = e_table_header_total_width (ethi->eth) + ethi->group_indent_width; - x1 = x2 = 0; - x2 += ethi->group_indent_width; - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - int col_width; - - col_width = ecol->width; - - x2 += col_width; - - if (x1 > (x + width)) - break; - - if (x2 < x) - continue; - - e_table_header_draw_button (drawable, ecol, - GTK_WIDGET (canvas)->style, ethi->font, - GTK_WIDGET_STATE (canvas), - GTK_WIDGET (canvas), ethi->gc, - x1 - x, -y, - width, height, - x2 - x1, ethi->height, - (ETableColArrow) g_hash_table_lookup ( - arrows, (gpointer) ecol->col_idx)); - } - - g_hash_table_destroy (arrows); -} - -static double -ethi_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -/* - * is_pointer_on_division: - * - * Returns whether @pos is a column header division; If @the_total is not NULL, - * then the actual position is returned here. If @return_ecol is not NULL, - * then the ETableCol that actually contains this point is returned here - */ -static gboolean -is_pointer_on_division (ETableHeaderItem *ethi, int pos, int *the_total, int *return_col) -{ - const int cols = e_table_header_count (ethi->eth); - int col, total; - - total = 0; - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if (col == 0) - total += ethi->group_indent_width; - - total += ecol->width; - - if ((total - TOLERANCE < pos)&& (pos < total + TOLERANCE)){ - if (return_col) - *return_col = col; - if (the_total) - *the_total = total; - - return TRUE; - } - - if (total > pos + TOLERANCE) - return FALSE; - } - - return FALSE; -} - -#define convert(c,sx,sy,x,y) gnome_canvas_w2c (c,sx,sy,x,y) - -static void -set_cursor (ETableHeaderItem *ethi, int pos) -{ - int col; - GtkWidget *canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - gboolean resizeable = FALSE; - - /* We might be invoked before we are realized */ - if (!canvas->window) - return; - - if (is_pointer_on_division (ethi, pos, NULL, &col)) { - int last_col = ethi->eth->col_count - 1; - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - /* Last column is not resizable */ - if (ecol->resizeable && col != last_col) { - int c = col + 1; - - /* Column is not resizable if all columns after it - are also not resizable */ - for (; c <= last_col; c++){ - ETableCol *ecol2; - - ecol2 = e_table_header_get_column (ethi->eth, c); - if (ecol2->resizeable) { - resizeable = TRUE; - break; - } - } - } - } - - if (resizeable) - e_cursor_set (canvas->window, E_CURSOR_SIZE_X); - else - gdk_window_set_cursor (canvas->window, NULL); - /* e_cursor_set (canvas->window, E_CURSOR_ARROW);*/ -} - -static void -ethi_end_resize (ETableHeaderItem *ethi) -{ - ethi->resize_col = -1; - ethi->resize_guide = GINT_TO_POINTER (0); - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); -} - -static gboolean -ethi_maybe_start_drag (ETableHeaderItem *ethi, GdkEventMotion *event) -{ - if (!ethi->maybe_drag) - return FALSE; - - if (ethi->eth->col_count < 2) { - ethi->maybe_drag = FALSE; - return FALSE; - } - - if (MAX (abs (ethi->click_x - event->x), - abs (ethi->click_y - event->y)) <= 3) - return FALSE; - - return TRUE; -} - -static void -ethi_start_drag (ETableHeaderItem *ethi, GdkEvent *event) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - GtkTargetList *list; - GdkDragContext *context; - ETableCol *ecol; - int col_width; - GdkPixmap *pixmap; - int group_indent = 0; - GHashTable *arrows = g_hash_table_new (NULL, NULL); - - GtkTargetEntry ethi_drag_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - ethi->drag_col = ethi_find_col_by_x (ethi, event->motion.x); - - if (ethi->drag_col == -1) - return; - - if (ethi->sort_info) { - int length = e_table_sort_info_grouping_get_count(ethi->sort_info); - int i; - for (i = 0; i < length; i++) { - ETableSortColumn column = - e_table_sort_info_grouping_get_nth( - ethi->sort_info, i); - group_indent ++; - g_hash_table_insert ( - arrows, - (gpointer) column.column, - (gpointer) (column.ascending ? - E_TABLE_COL_ARROW_UP : - E_TABLE_COL_ARROW_DOWN)); - } - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = - e_table_sort_info_sorting_get_nth ( - ethi->sort_info, i); - - g_hash_table_insert ( - arrows, - (gpointer) column.column, - (gpointer) (column.ascending ? - E_TABLE_COL_ARROW_UP : - E_TABLE_COL_ARROW_DOWN)); - } - } - - ethi_drag_types[0].target = g_strdup_printf( - "%s-%s", ethi_drag_types[0].target, ethi->dnd_code); - list = gtk_target_list_new ( - ethi_drag_types, ELEMENTS (ethi_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - g_free(ethi_drag_types[0].target); - - ecol = e_table_header_get_column (ethi->eth, ethi->drag_col); - col_width = ecol->width; - pixmap = gdk_pixmap_new (widget->window, col_width, ethi->height, -1); - - e_table_header_draw_button ( - pixmap, ecol, - widget->style, ethi->font, - GTK_WIDGET_STATE (widget), - widget, ethi->gc, - 0, 0, - col_width, ethi->height, - col_width, ethi->height, - (ETableColArrow) g_hash_table_lookup ( - arrows, (gpointer) ecol->col_idx)); - gtk_drag_set_icon_pixmap ( - context, - gdk_window_get_colormap (widget->window), - pixmap, - NULL, - col_width / 2, - ethi->height / 2); - gdk_pixmap_unref (pixmap); - - ethi->maybe_drag = FALSE; - g_hash_table_destroy (arrows); -} - -typedef struct { - ETableHeaderItem *ethi; - int col; -} EthiHeaderInfo; - -static void -ethi_popup_sort_ascending(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - int length; - int i; - int found = FALSE; - ETableHeaderItem *ethi = info->ethi; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth ( - ethi->sort_info, i); - - if (model_col == column.column){ - column.ascending = 1; - e_table_sort_info_grouping_set_nth ( - ethi->sort_info, i, column); - found = 1; - break; - } - } - if (!found) { - length = e_table_sort_info_sorting_get_count ( - ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = - e_table_sort_info_sorting_get_nth( - ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 1; - e_table_sort_info_sorting_set_nth ( - ethi->sort_info, i, column); - found = 1; - break; - } - } - } - if (!found) { - ETableSortColumn column = { model_col, 1 }; - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth(ethi->sort_info, length - 1, column); - } -} - -static void -ethi_popup_sort_descending(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - int length; - int i; - int found = FALSE; - ETableHeaderItem *ethi = info->ethi; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth( - ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 0; - e_table_sort_info_grouping_set_nth( - ethi->sort_info, i, column); - found = 1; - break; - } - } - if (!found) { - length = e_table_sort_info_sorting_get_count (ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = - e_table_sort_info_sorting_get_nth( - ethi->sort_info, i); - - if (model_col == column.column){ - column.ascending = 0; - e_table_sort_info_sorting_set_nth ( - ethi->sort_info, i, column); - found = 1; - break; - } - } - } - if (!found) { - ETableSortColumn column = { model_col, 0 }; - length = e_table_sort_info_sorting_get_count (ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth ( - ethi->sort_info, length - 1, column); - } -} - -static void -ethi_popup_unsort(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableHeaderItem *ethi = info->ethi; - - e_table_sort_info_grouping_truncate(ethi->sort_info, 0); - e_table_sort_info_sorting_truncate(ethi->sort_info, 0); -} - -static void -ethi_popup_group_field(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - ETableHeaderItem *ethi = info->ethi; - ETableSortColumn column; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - column.column = model_col; - column.ascending = 1; - e_table_sort_info_grouping_set_nth(ethi->sort_info, 0, column); - e_table_sort_info_grouping_truncate(ethi->sort_info, 1); -} - -static void -ethi_popup_group_box(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_remove_column(GtkWidget *widget, EthiHeaderInfo *info) -{ - e_table_header_remove(info->ethi->eth, info->col); -} - -static void -ethi_popup_field_chooser(GtkWidget *widget, EthiHeaderInfo *info) -{ - GtkWidget *etfcd = e_table_field_chooser_dialog_new(); - gtk_object_set(GTK_OBJECT(etfcd), - "full_header", info->ethi->full_header, - "dnd_code", info->ethi->dnd_code, - NULL); - gtk_widget_show(etfcd); -} - -static void -ethi_popup_alignment(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_best_fit(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableHeaderItem *ethi = info->ethi; - int width; - - gtk_signal_emit_by_name (GTK_OBJECT (ethi->eth), - "request_width", - info->col, &width); - /* Add 10 to stop it from "..."ing */ - e_table_header_set_size (ethi->eth, info->col, width + 10); - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); - -} - -static void -ethi_popup_format_columns(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -config_destroyed (GtkObject *object, ETableHeaderItem *ethi) -{ - ethi->config = NULL; -} - -static void -apply_changes (GnomePropertyBox *pbox, gint page_num, ETableHeaderItem *ethi) -{ - ETableConfig *config = E_TABLE_CONFIG (ethi->config); - char *state = e_table_state_save_to_string (config->state); - - if (page_num != -1) - return; - - e_table_set_state (ethi->table, state); - g_free (state); -} - -static void -ethi_popup_customize_view(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableHeaderItem *ethi = info->ethi; - ETableState *state; - - if (ethi->config) - e_table_config_raise (E_TABLE_CONFIG (ethi->config)); - else { - state = e_table_get_state_object(ethi->table); - - ethi->config = e_table_config_new ( - _("Configuring view: FIXME"), - ethi->table->spec, state); - gtk_signal_connect ( - GTK_OBJECT (ethi->config), "destroy", - GTK_SIGNAL_FUNC (config_destroyed), ethi); - gtk_signal_connect ( - GTK_OBJECT ( - E_TABLE_CONFIG (ethi->config)->dialog_toplevel), - "apply", - GTK_SIGNAL_FUNC (apply_changes), ethi); - } -} - -/* Bit 1 is always disabled. */ -/* Bit 2 is disabled if not "sortable". */ -/* Bit 4 is disabled if we don't have a pointer to our table object. */ -static EPopupMenu ethi_context_menu [] = { - { N_("Sort Ascending"), NULL, GTK_SIGNAL_FUNC(ethi_popup_sort_ascending), NULL, 2}, - { N_("Sort Descending"), NULL, GTK_SIGNAL_FUNC(ethi_popup_sort_descending), NULL, 2}, - { N_("Unsort"), NULL, GTK_SIGNAL_FUNC(ethi_popup_unsort), NULL, 0}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), NULL, 0}, - { N_("Group By This Field"), NULL, GTK_SIGNAL_FUNC(ethi_popup_group_field), NULL, 0}, - { N_("Group By Box"), NULL, GTK_SIGNAL_FUNC(ethi_popup_group_box), NULL, 1}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), NULL, 1}, - { N_("Remove This Column"), NULL, GTK_SIGNAL_FUNC(ethi_popup_remove_column), NULL, 0}, - { N_("Add a Column..."), NULL, GTK_SIGNAL_FUNC(ethi_popup_field_chooser), NULL, 0}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), NULL, 1}, - { N_("Alignment"), NULL, GTK_SIGNAL_FUNC(ethi_popup_alignment), NULL, 1}, - { N_("Best Fit"), NULL, GTK_SIGNAL_FUNC(ethi_popup_best_fit), NULL, 2}, - { N_("Format Columns..."), NULL, GTK_SIGNAL_FUNC(ethi_popup_format_columns), NULL, 1}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), NULL, 1}, - { N_("Customize Current View..."), NULL, GTK_SIGNAL_FUNC(ethi_popup_customize_view), NULL, 4}, - { NULL, NULL, NULL, NULL, 0 } -}; - -static void -ethi_header_context_menu (ETableHeaderItem *ethi, GdkEventButton *event) -{ - EthiHeaderInfo *info = g_new(EthiHeaderInfo, 1); - ETableCol *col; - info->ethi = ethi; - info->col = ethi_find_col_by_x (ethi, event->x); - col = e_table_header_get_column (ethi->eth, info->col); - e_popup_menu_run (ethi_context_menu, (GdkEvent *) event, - 1 + - (col->sortable ? 0 : 2) + - (ethi->table ? 0 : 4), 0, info); -} - -static void -ethi_button_pressed (ETableHeaderItem *ethi, GdkEventButton *event) -{ - gtk_signal_emit (GTK_OBJECT (ethi), - ethi_signals [BUTTON_PRESSED], event); -} - -static void -ethi_change_sort_state (ETableHeaderItem *ethi, gdouble x) -{ - ETableCol *col; - int model_col; - int length; - int i; - int found = FALSE; - - col = e_table_header_get_column (ethi->eth, ethi_find_col_by_x (ethi, x)); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - int ascending = column.ascending; - ascending = ! ascending; - column.ascending = ascending; - e_table_sort_info_grouping_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - - if (!col->sortable) - return; - - if (!found) { - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(ethi->sort_info, i); - - if (model_col == column.column){ - int ascending = column.ascending; - - if (ascending == 0){ - /* - * This means the user has clicked twice - * already, lets kill sorting now. - */ - e_table_sort_info_sorting_truncate (ethi->sort_info, i); - } else { - ascending = !ascending; - column.ascending = ascending; - e_table_sort_info_sorting_set_nth(ethi->sort_info, i, column); - } - found = 1; - break; - } - } - } - - if (!found) { - ETableSortColumn column = { model_col, 1 }; - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth(ethi->sort_info, length - 1, column); - } -} - -/* - * Handles the events on the ETableHeaderItem, particularly it handles resizing - */ -static int -ethi_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const gboolean resizing = ETHI_RESIZING (ethi); - int x, y, start, col; - int was_maybe_drag = 0; - - switch (e->type){ - case GDK_ENTER_NOTIFY: - convert (canvas, e->crossing.x, e->crossing.y, &x, &y); - set_cursor (ethi, x); - break; - - case GDK_LEAVE_NOTIFY: - gdk_window_set_cursor (GTK_WIDGET (canvas)->window, NULL); - /* e_cursor_set (GTK_WIDGET (canvas)->window, E_CURSOR_ARROW);*/ - break; - - case GDK_MOTION_NOTIFY: - - convert (canvas, e->motion.x, e->motion.y, &x, &y); - if (resizing){ - int new_width; - - if (ethi->resize_guide == NULL){ - /* Quick hack until I actually bind the views */ - ethi->resize_guide = GINT_TO_POINTER (1); - - gnome_canvas_item_grab (item, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - e_cursor_get (E_CURSOR_SIZE_X), - e->button.time); - } - - new_width = x - ethi->resize_start_pos; - - e_table_header_set_size (ethi->eth, ethi->resize_col, new_width); - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); - } else if (ethi_maybe_start_drag (ethi, &e->motion)){ - ethi_start_drag (ethi, e); - } else - set_cursor (ethi, x); - break; - - case GDK_BUTTON_PRESS: - if (e->button.button > 3) - return FALSE; - - convert (canvas, e->button.x, e->button.y, &x, &y); - - if (is_pointer_on_division (ethi, x, &start, &col) && e->button.button == 1){ - ETableCol *ecol; - - /* - * Record the important bits. - * - * By setting resize_pos to a non -1 value, - * we know that we are being resized (used in the - * other event handlers). - */ - ecol = e_table_header_get_column (ethi->eth, col); - - if (!ecol->resizeable) - break; - ethi->resize_col = col; - ethi->resize_start_pos = start - ecol->width; - ethi->resize_min_width = ecol->min_width; - } else { - if (e->button.button == 1){ - ethi->click_x = e->button.x; - ethi->click_y = e->button.y; - ethi->maybe_drag = TRUE; - } else if (e->button.button == 3){ - ethi_header_context_menu (ethi, &e->button); - } else - ethi_button_pressed (ethi, &e->button); - } - break; - - case GDK_2BUTTON_PRESS: - if (!resizing) - break; - - if (e->button.button != 1) - break; - else { - int width = 0; - gtk_signal_emit_by_name (GTK_OBJECT (ethi->eth), - "request_width", - (int)ethi->resize_col, &width); - /* Add 10 to stop it from "..."ing */ - e_table_header_set_size (ethi->eth, ethi->resize_col, width + 10); - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); - ethi->maybe_drag = FALSE; - } - break; - - case GDK_BUTTON_RELEASE: { - gboolean needs_ungrab = FALSE; - - was_maybe_drag = ethi->maybe_drag; - - ethi->maybe_drag = FALSE; - - if (ethi->resize_col != -1){ - needs_ungrab = (ethi->resize_guide != NULL); - ethi_end_resize (ethi); - } else if (was_maybe_drag && ethi->sort_info) - ethi_change_sort_state (ethi, e->button.x); - - if (needs_ungrab) - gnome_canvas_item_ungrab (item, e->button.time); - - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -ethi_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - ethi_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = ethi_destroy; - object_class->set_arg = ethi_set_arg; - object_class->get_arg = ethi_get_arg; - - item_class->update = ethi_update; - item_class->realize = ethi_realize; - item_class->unrealize = ethi_unrealize; - item_class->draw = ethi_draw; - item_class->point = ethi_point; - item_class->event = ethi_event; - - gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableHeaderItem::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); - gtk_object_add_arg_type ("ETableHeaderItem::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableHeaderItem::fontset", GTK_TYPE_STRING, - GTK_ARG_WRITABLE, ARG_TABLE_FONTSET); - gtk_object_add_arg_type ("ETableHeaderItem::sort_info", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_SORT_INFO); - gtk_object_add_arg_type ("ETableHeaderItem::table", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE); - - /* - * Create our pixmaps for DnD - */ - dnd_colormap = gtk_widget_get_default_colormap (); - remove_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &remove_col_mask, NULL, remove_col_xpm); - - add_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &add_col_mask, NULL, add_col_xpm); - - ethi_signals [BUTTON_PRESSED] = - gtk_signal_new ("button_pressed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderItemClass, button_pressed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, ethi_signals, LAST_SIGNAL); -} - -static void -ethi_init (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - ethi->resize_col = -1; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; - - ethi->drag_col = -1; - ethi->drag_mark = -1; - - ethi->sort_info = NULL; - - ethi->sort_info_changed_id = 0; - ethi->group_info_changed_id = 0; - - ethi->group_indent_width = 0; - ethi->table = NULL; -} - -GtkType -e_table_header_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeaderItem", - sizeof (ETableHeaderItem), - sizeof (ETableHeaderItemClass), - (GtkClassInitFunc) ethi_class_init, - (GtkObjectInitFunc) ethi_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - diff --git a/widgets/table/e-table-header-item.h b/widgets/table/e-table-header-item.h deleted file mode 100644 index 6186037d5d..0000000000 --- a/widgets/table/e-table-header-item.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_HEADER_ITEM_H_ -#define _E_TABLE_HEADER_ITEM_H_ - -#include <gal/e-table/e-table.h> -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include <gal/e-table/e-table-header.h> -#include <gal/e-table/e-table-sort-info.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_HEADER_ITEM_TYPE (e_table_header_item_get_type ()) -#define E_TABLE_HEADER_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItem)) -#define E_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItemClass)) -#define E_IS_TABLE_HEADER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_ITEM_TYPE)) -#define E_IS_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableHeader *eth; - - GdkGC *gc; - GdkCursor *change_cursor; - - short height, width; - GdkFont *font; - - /* - * Used during resizing; Could be shorts - */ - int resize_col; - int resize_start_pos; - int resize_min_width; - - GtkObject *resize_guide; - - int group_indent_width; - - /* - * Ids - */ - int structure_change_id, dimension_change_id; - - /* - * For dragging columns - */ - guint maybe_drag:1; - guint dnd_ready:1; - int click_x, click_y; - int drag_col, drop_col, drag_mark; - guint drag_motion_id, drag_end_id, drag_leave_id, drag_drop_id, drag_data_received_id, drag_data_get_id; - guint sort_info_changed_id, group_info_changed_id; - GnomeCanvasItem *remove_item; - GdkBitmap *stipple; - - gchar *dnd_code; - - /* - * For column sorting info - */ - ETableSortInfo *sort_info; - - /* For adding fields. */ - ETableHeader *full_header; - ETable *table; - void *config; -} ETableHeaderItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - /* - * signals - */ - void (*button_pressed) (ETableHeaderItem *ethi, GdkEventButton *button); -} ETableHeaderItemClass; - -GtkType e_table_header_item_get_type (void); - -END_GNOME_DECLS - -#endif /* _E_TABLE_HEADER_ITEM_H_ */ diff --git a/widgets/table/e-table-header-utils.c b/widgets/table/e-table-header-utils.c deleted file mode 100644 index 987207f588..0000000000 --- a/widgets/table/e-table-header-utils.c +++ /dev/null @@ -1,429 +0,0 @@ -/* ETable widget - utilities for drawing table header buttons - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include "e-table-defines.h" -#include "e-table-header-utils.h" - - - -/** - * e_table_header_compute_height: - * @ecol: Table column description. - * @style: Style for the button's bevel. - * @font: Font for the button's text, or NULL if no font is available. - * - * Computes the minimum height required for a table header button. - * - * Return value: The height of the button, in pixels. - **/ -double -e_table_header_compute_height (ETableCol *ecol, GtkStyle *style, GdkFont *font) -{ - int ythick; - int height; - - g_return_val_if_fail (ecol != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_COL (ecol), -1); - g_return_val_if_fail (style != NULL, -1); - - ythick = style->klass->ythickness; - - if (font) - height = font->ascent + font->descent; - else - height = 16; /* FIXME: default? */ - - if (ecol->is_pixbuf) { - g_assert (ecol->pixbuf != NULL); - height = MAX (height, gdk_pixbuf_get_height (ecol->pixbuf)); - } - - height = MAX (height, MIN_ARROW_SIZE); - - height += 2 * (ythick + HEADER_PADDING); - - return height; -} - -double -e_table_header_width_extras (GtkStyle *style) -{ - g_return_val_if_fail (style != NULL, -1); - - return 2 * (style->klass->xthickness + HEADER_PADDING); -} - -/* Creates a pixmap that is a composite of a background color and the upper-left - * corner rectangle of a pixbuf. - */ -static GdkPixmap * -make_composite_pixmap (GdkDrawable *drawable, GdkGC *gc, - GdkPixbuf *pixbuf, GdkColor *bg, int width, int height, - int dither_xofs, int dither_yofs) -{ - int pwidth, pheight; - GdkPixmap *pixmap; - GdkPixbuf *tmp; - int color; - - pwidth = gdk_pixbuf_get_width (pixbuf); - pheight = gdk_pixbuf_get_height (pixbuf); - g_assert (width <= pwidth && height <= pheight); - - color = ((bg->red & 0xff00) << 8) | (bg->green & 0xff00) | ((bg->blue & 0xff00) >> 8); - - if (width >= pwidth && height >= pheight) { - tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); - if (!tmp) - return NULL; - - gdk_pixbuf_composite_color (pixbuf, tmp, - 0, 0, - width, height, - 0, 0, - 1.0, 1.0, - GDK_INTERP_NEAREST, - 255, - 0, 0, - 16, - color, color); - } else { - int x, y, rowstride; - GdkPixbuf *fade; - guchar *pixels; - - /* Do a nice fade of the pixbuf down and to the right */ - - fade = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); - if (!fade) - return NULL; - - gdk_pixbuf_copy_area (pixbuf, - 0, 0, - width, height, - fade, - 0, 0); - - rowstride = gdk_pixbuf_get_rowstride (fade); - pixels = gdk_pixbuf_get_pixels (fade); - - for (y = 0; y < height; y++) { - guchar *p; - int yfactor; - - p = pixels + y * rowstride; - - if (height < pheight) - yfactor = height - y; - else - yfactor = height; - - for (x = 0; x < width; x++) { - int xfactor; - - if (width < pwidth) - xfactor = width - x; - else - xfactor = width; - - p[3] = ((int) p[3] * xfactor * yfactor / (width * height)); - p += 4; - } - } - - tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); - if (!tmp) { - gdk_pixbuf_unref (fade); - return NULL; - } - - gdk_pixbuf_composite_color (fade, tmp, - 0, 0, - width, height, - 0, 0, - 1.0, 1.0, - GDK_INTERP_NEAREST, - 255, - 0, 0, - 16, - color, color); - - gdk_pixbuf_unref (fade); - } - - pixmap = gdk_pixmap_new (drawable, width, height, gdk_rgb_get_visual ()->depth); - gdk_draw_rgb_image_dithalign (pixmap, gc, - 0, 0, - width, height, - GDK_RGB_DITHER_NORMAL, - gdk_pixbuf_get_pixels (tmp), - gdk_pixbuf_get_rowstride (tmp), - dither_xofs, dither_yofs); - gdk_pixbuf_unref (tmp); - - return pixmap; -} - -/** - * e_table_header_draw_button: - * @drawable: Destination drawable. - * @ecol: Table column for the header information. - * @style: Style to use for drawing the button. - * @font: Font for the button's text. - * @state: State of the table widget. - * @widget: The table widget. - * @gc: GC to use for drawing. - * @x: Leftmost coordinate of the button. - * @y: Topmost coordinate of the button. - * @width: Width of the region to draw. - * @height: Height of the region to draw. - * @button_width: Width for the complete button. - * @button_height: Height for the complete button. - * @arrow: Arrow type to use as a sort indicator. - * - * Draws a button suitable for a table header. - **/ -void -e_table_header_draw_button (GdkDrawable *drawable, ETableCol *ecol, - GtkStyle *style, GdkFont *font, GtkStateType state, - GtkWidget *widget, GdkGC *gc, - int x, int y, int width, int height, - int button_width, int button_height, - ETableColArrow arrow) -{ - int xthick, ythick; - int inner_x, inner_y; - int inner_width, inner_height; - - g_return_if_fail (drawable != NULL); - g_return_if_fail (ecol != NULL); - g_return_if_fail (E_IS_TABLE_COL (ecol)); - g_return_if_fail (style != NULL); - g_return_if_fail (font != NULL); - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (button_width > 0 && button_height > 0); - - xthick = style->klass->xthickness; - ythick = style->klass->ythickness; - - /* Button bevel */ - - gtk_paint_box (style, drawable, state, GTK_SHADOW_OUT, - NULL, widget, "button", - x, y, button_width, button_height); - - /* Inside area */ - - inner_width = button_width - 2 * (xthick + HEADER_PADDING); - inner_height = button_height - 2 * (ythick + HEADER_PADDING); - - if (inner_width < 1 || inner_height < 1) - return; /* nothing fits */ - - inner_x = x + xthick + HEADER_PADDING; - inner_y = y + ythick + HEADER_PADDING; - - /* Arrow */ - - switch (arrow) { - case E_TABLE_COL_ARROW_NONE: - break; - - case E_TABLE_COL_ARROW_UP: - case E_TABLE_COL_ARROW_DOWN: { - int arrow_width, arrow_height; - - arrow_width = MIN (MIN_ARROW_SIZE, inner_width); - arrow_height = MIN (MIN_ARROW_SIZE, inner_height); - - gtk_paint_arrow (style, drawable, state, - GTK_SHADOW_IN, NULL, widget, "header", - (arrow == E_TABLE_COL_ARROW_UP) ? GTK_ARROW_UP : GTK_ARROW_DOWN, - TRUE, - inner_x + inner_width - arrow_width, - inner_y + (inner_height - arrow_height) / 2, - arrow_width, arrow_height); - - inner_width -= arrow_width + HEADER_PADDING; - break; - } - - default: - g_assert_not_reached (); - return; - } - - if (inner_width < 1) - return; /* nothing else fits */ - - /* Pixbuf or label */ - - if (ecol->is_pixbuf) { - int pwidth, pheight; - int clip_width, clip_height; - GdkPixmap *pixmap; - - g_assert (ecol->pixbuf != NULL); - - pwidth = gdk_pixbuf_get_width (ecol->pixbuf); - pheight = gdk_pixbuf_get_height (ecol->pixbuf); - - clip_width = MIN (pwidth, inner_width); - clip_height = MIN (pheight, inner_height); - - pixmap = make_composite_pixmap (drawable, gc, - ecol->pixbuf, &style->bg[state], - clip_width, clip_height, - inner_x, - inner_y + (inner_height - clip_height) / 2); - if (pixmap) { - gdk_draw_pixmap (drawable, gc, pixmap, - 0, 0, - inner_x, - inner_y + (inner_height - clip_height) / 2, - clip_width, clip_height); - gdk_pixmap_unref (pixmap); - } - } else { - int ypos; - - ypos = inner_y + (inner_height - font->ascent - font->descent) / 2 + font->ascent; - - e_table_draw_elided_string (drawable, font, gc, - inner_x, ypos, - ecol->text, inner_width, TRUE); - } -} - -/* Computes the length of a string that needs to be trimmed for elision */ -static int -compute_elision_length (GdkFont *font, const char *str, int max_width) -{ - int len; - int l = 0, left, right; - int rbearing; - - len = strlen (str); - - if (len <= 0) - return 0; - - left = 0; - right = len; - - while (left < right) { - l = (left + right) / 2; - gdk_text_extents (font, str, l, NULL, &rbearing, NULL, NULL, NULL); - - if (rbearing < max_width) - left = l + 1; - else if (rbearing > max_width) - right = l; - else - return l; - } - - if (rbearing > max_width) - return MAX (0, l - 1); - else - return l; -} - -/* Default width of the elision arrow in pixels */ -#define ARROW_WIDTH 4 - -/** - * e_table_draw_elided_string: - * @drawable: Destination drawable. - * @font: Font for the text. - * @gc: GC to use for drawing. - * @x: X insertion point for the string. - * @y: Y insertion point for the string's baseline. - * @str: String to draw. - * @max_width: Maximum width in which the string must fit. - * @center: Whether to center the string in the available area if it does fit. - * - * Draws a string, possibly trimming it so that it fits inside the specified - * maximum width. If it does not fit, an elision indicator is drawn after the - * last character that does fit. - **/ -void -e_table_draw_elided_string (GdkDrawable *drawable, GdkFont *font, GdkGC *gc, - int x, int y, const char *str, int max_width, gboolean center) -{ - int rbearing; - int width; - - g_return_if_fail (drawable != NULL); - g_return_if_fail (font != NULL); - g_return_if_fail (gc != NULL); - g_return_if_fail (str != NULL); - g_return_if_fail (max_width >= 0); - - gdk_string_extents (font, str, NULL, &rbearing, &width, NULL, NULL); - - if (rbearing <= max_width) { - int xpos; - - if (center) - xpos = x + (max_width - width) / 2; - else - xpos = x; - - gdk_draw_string (drawable, font, gc, xpos, y, str); - } else { - int arrow_width; - int len; - int i; - - if (max_width < ARROW_WIDTH + 1) - arrow_width = max_width - 1; - else - arrow_width = ARROW_WIDTH; - - len = compute_elision_length (font, str, max_width - arrow_width - 1); - gdk_draw_text (drawable, font, gc, x, y, str, len); - - gdk_text_extents (font, str, len, NULL, &rbearing, NULL, NULL, NULL); - - y -= font->ascent; - - for (i = 0; i < arrow_width; i++) { - int h; - - h = 2 * i + 1; - - gdk_draw_line (drawable, gc, - x + rbearing + arrow_width - i, - y + (font->ascent + font->descent - h) / 2, - x + rbearing + arrow_width - i, - y + (font->ascent + font->descent - h) / 2 + h - 1); - } - } -} diff --git a/widgets/table/e-table-header-utils.h b/widgets/table/e-table-header-utils.h deleted file mode 100644 index 62f66e4bd3..0000000000 --- a/widgets/table/e-table-header-utils.h +++ /dev/null @@ -1,65 +0,0 @@ -/* ETable widget - utilities for drawing table header buttons - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef E_TABLE_HEADER_UTILS_H -#define E_TABLE_HEADER_UTILS_H - -#include <gal/e-table/e-table-col.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -double e_table_header_compute_height (ETableCol *ecol, - GtkStyle *style, - GdkFont *font); -double e_table_header_width_extras (GtkStyle *style); -void e_table_header_draw_button (GdkDrawable *drawable, - ETableCol *ecol, - GtkStyle *style, - GdkFont *font, - GtkStateType state, - GtkWidget *widget, - GdkGC *gc, - int x, - int y, - int width, - int height, - int button_width, - int button_height, - ETableColArrow arrow); -void e_table_draw_elided_string (GdkDrawable *drawable, - GdkFont *font, - GdkGC *gc, - int x, - int y, - const char *str, - int max_width, - gboolean center); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/widgets/table/e-table-header.c b/widgets/table/e-table-header.c deleted file mode 100644 index 58d60480cd..0000000000 --- a/widgets/table/e-table-header.c +++ /dev/null @@ -1,833 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-col-head.c: TableColHead implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc - */ -#include <config.h> -#include <string.h> -#include <gtk/gtkobject.h> -#include <gtk/gtksignal.h> -#include "e-table-header.h" -#include "e-table-defines.h" - -/* The arguments we take */ -enum { - ARG_0, - ARG_SORT_INFO, - ARG_WIDTH, - ARG_WIDTH_EXTRAS, -}; - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - REQUEST_WIDTH, - LAST_SIGNAL -}; - -static void eth_set_size (ETableHeader *eth, int idx, int size); -static void eth_calc_widths (ETableHeader *eth); - -static guint eth_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_header_parent_class; - -struct two_ints { - int column; - int width; -}; - -static void -eth_set_width (ETableHeader *eth, int width) -{ - eth->width = width; -} - -static void -dequeue (ETableHeader *eth, int *column, int *width) -{ - GSList *head; - struct two_ints *store; - head = eth->change_queue; - eth->change_queue = eth->change_queue->next; - if (!eth->change_queue) - eth->change_tail = NULL; - store = head->data; - g_slist_free_1(head); - if (column) - *column = store->column; - if (width) - *width = store->width; - g_free(store); -} - -static gboolean -dequeue_idle (ETableHeader *eth) -{ - int column, width; - - dequeue (eth, &column, &width); - while (eth->change_queue && ((struct two_ints *) eth->change_queue->data)->column == column) - dequeue (eth, &column, &width); - - if (column == -1) - eth_set_width (eth, width); - else if (column < eth->col_count) - eth_set_size (eth, column, width); - if (eth->change_queue) - return TRUE; - else { - eth_calc_widths (eth); - eth->idle = 0; - return FALSE; - } -} - -static void -enqueue (ETableHeader *eth, int column, int width) -{ - struct two_ints *store; - store = g_new(struct two_ints, 1); - store->column = column; - store->width = width; - - eth->change_tail = g_slist_last(g_slist_append(eth->change_tail, store)); - if (!eth->change_queue) - eth->change_queue = eth->change_tail; - - if (!eth->idle) { - eth->idle = g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc) dequeue_idle, eth, NULL); - } -} - -void -e_table_header_set_size (ETableHeader *eth, int idx, int size) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - - enqueue (eth, idx, size); -} - -static void -eth_do_remove (ETableHeader *eth, int idx, gboolean do_unref) -{ - if (do_unref) - gtk_object_unref (GTK_OBJECT (eth->columns [idx])); - - memmove (ð->columns [idx], ð->columns [idx+1], - sizeof (ETableCol *) * (eth->col_count - idx - 1)); - eth->col_count--; -} - -static void -eth_destroy (GtkObject *object) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - const int cols = eth->col_count; - int i; - - if (eth->sort_info) { - if (eth->sort_info_group_change_id) - gtk_signal_disconnect(GTK_OBJECT(eth->sort_info), - eth->sort_info_group_change_id); - gtk_object_unref(GTK_OBJECT(eth->sort_info)); - } - - if (eth->idle) - g_source_remove(eth->idle); - g_slist_foreach(eth->change_queue, (GFunc) g_free, NULL); - g_slist_free(eth->change_queue); - - /* - * Destroy columns - */ - for (i = cols - 1; i >= 0; i--){ - eth_do_remove (eth, i, TRUE); - } - - if (e_table_header_parent_class->destroy) - e_table_header_parent_class->destroy (object); -} - -static void -eth_group_info_changed(ETableSortInfo *info, ETableHeader *eth) -{ - enqueue(eth, -1, eth->nominal_width); -} - -static void -eth_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - - switch (arg_id) { - case ARG_WIDTH: - eth->nominal_width = GTK_VALUE_DOUBLE (*arg); - enqueue(eth, -1, GTK_VALUE_DOUBLE (*arg)); - break; - case ARG_WIDTH_EXTRAS: - eth->width_extras = GTK_VALUE_DOUBLE (*arg); - enqueue(eth, -1, eth->nominal_width); - break; - case ARG_SORT_INFO: - if (eth->sort_info) { - if (eth->sort_info_group_change_id) - gtk_signal_disconnect(GTK_OBJECT(eth->sort_info), eth->sort_info_group_change_id); - gtk_object_unref(GTK_OBJECT(eth->sort_info)); - } - eth->sort_info = E_TABLE_SORT_INFO(GTK_VALUE_OBJECT (*arg)); - if (eth->sort_info) { - gtk_object_ref(GTK_OBJECT(eth->sort_info)); - eth->sort_info_group_change_id - = gtk_signal_connect(GTK_OBJECT(eth->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC(eth_group_info_changed), eth); - } - enqueue(eth, -1, eth->nominal_width); - break; - default: - break; - } -} - -static void -eth_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - - switch (arg_id) { - case ARG_SORT_INFO: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(eth->sort_info); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eth->nominal_width; - break; - case ARG_WIDTH_EXTRAS: - GTK_VALUE_DOUBLE (*arg) = eth->width_extras; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_table_header_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = eth_destroy; - object_class->set_arg = eth_set_arg; - object_class->get_arg = eth_get_arg; - - - e_table_header_parent_class = (gtk_type_class (gtk_object_get_type ())); - - gtk_object_add_arg_type ("ETableHeader::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableHeader::width_extras", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH_EXTRAS); - gtk_object_add_arg_type ("ETableHeader::sort_info", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_SORT_INFO); - - eth_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - eth_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - eth_signals [REQUEST_WIDTH] = - gtk_signal_new ("request_width", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, request_width), - gtk_marshal_INT__INT, - GTK_TYPE_INT, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, eth_signals, LAST_SIGNAL); -} - -static void -e_table_header_init (ETableHeader *eth) -{ - eth->col_count = 0; - eth->width = 0; - - eth->sort_info = NULL; - eth->sort_info_group_change_id = 0; - - eth->columns = NULL; - - eth->change_queue = NULL; - eth->change_tail = NULL; - - eth->width_extras = 0; -} - -/** - * e_table_header_new: - * - * Returns: A new @ETableHeader object. - */ -ETableHeader * -e_table_header_new (void) -{ - ETableHeader *eth; - - eth = gtk_type_new (e_table_header_get_type ()); - - return eth; -} - -static void -eth_update_offsets (ETableHeader *eth) -{ - int i; - int x = 0; - - for (i = 0; i < eth->col_count; i++){ - ETableCol *etc = eth->columns [i]; - - etc->x = x; - x += etc->width; - } -} - -static void -eth_do_insert (ETableHeader *eth, int pos, ETableCol *val) -{ - memmove (ð->columns [pos+1], ð->columns [pos], - sizeof (ETableCol *) * (eth->col_count - pos)); - eth->columns [pos] = val; - eth->col_count ++; -} - -/** - * e_table_header_add_column: - * @eth: the table header to add the column to. - * @tc: the ETableCol definition - * @pos: position where the ETableCol will go. - * - * This function adds the @tc ETableCol definition into the @eth ETableHeader - * at position @pos. This is the way you add new ETableCols to the - * ETableHeader. - * - * This function will emit the "structure_change" signal on the @eth object. - * The ETableCol is assumed - */ -void -e_table_header_add_column (ETableHeader *eth, ETableCol *tc, int pos) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (tc != NULL); - g_return_if_fail (E_IS_TABLE_COL (tc)); - g_return_if_fail (pos >= -1 && pos <= eth->col_count); - - if (pos == -1) - pos = eth->col_count; - eth->columns = g_realloc (eth->columns, sizeof (ETableCol *) * (eth->col_count + 1)); - - /* - * We are the primary owners of the column - */ - gtk_object_ref (GTK_OBJECT (tc)); - gtk_object_sink (GTK_OBJECT (tc)); - - eth_do_insert (eth, pos, tc); - - enqueue(eth, -1, eth->nominal_width); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -/** - * e_table_header_get_column: - * @eth: the ETableHeader to query - * @column: the column inside the @eth. - * - * Returns: The ETableCol at @column in the @eth object - */ -ETableCol * -e_table_header_get_column (ETableHeader *eth, int column) -{ - g_return_val_if_fail (eth != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), NULL); - - if (column < 0) - return NULL; - - if (column >= eth->col_count) - return NULL; - - return eth->columns [column]; -} - -/** - * e_table_header_get_column_by_col_id: - * @eth: the ETableHeader to query - * @col_id: the col_id to search for. - * - * Returns: The ETableCol with col_idx = @col_idx in the @eth object - */ -ETableCol * -e_table_header_get_column_by_col_idx (ETableHeader *eth, int col_idx) -{ - int i; - g_return_val_if_fail (eth != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), NULL); - - for (i = 0; i < eth->col_count; i++) { - if (eth->columns[i]->col_idx == col_idx) { - return eth->columns [i]; - } - } - - return NULL; -} - -/** - * e_table_header_count: - * @eth: the ETableHeader to query - * - * Returns: the number of columns in this ETableHeader. - */ -int -e_table_header_count (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - return eth->col_count; -} - -/** - * e_table_header_index: - * @eth: the ETableHeader to query - * @col: the column to fetch. - * - * ETableHeaders contain the visual list of columns that the user will - * view. The visible columns will typically map to different columns - * in the ETableModel (because the user reordered the data for - * example). - * - * Returns: the column in the model that the @col column - * in the ETableHeader points to. */ -int -e_table_header_index (ETableHeader *eth, int col) -{ - g_return_val_if_fail (eth != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), -1); - g_return_val_if_fail (col >= 0 && col < eth->col_count, -1); - - return eth->columns [col]->col_idx; -} - -/** - * e_table_header_get_index_at: - * @eth: the ETableHeader to query - * @x_offset: a pixel count from the beginning of the ETableHeader - * - * This will return the ETableHeader column that would contain - * the @x_offset pixel. - * - * Returns: the column that contains pixel @x_offset, or -1 - * if no column inside this ETableHeader contains that pixel. - */ -int -e_table_header_get_index_at (ETableHeader *eth, int x_offset) -{ - int i, total; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++){ - total += eth->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -/** - * e_table_header_get_columns: - * @eth: The ETableHeader to query - * - * Returns: A NULL terminated array of the ETableCols - * contained in the ETableHeader @eth. Note that every - * returned ETableCol in the array has been referenced, to release - * this information you need to g_free the buffer returned - * and you need to gtk_object_unref every element returned - */ -ETableCol ** -e_table_header_get_columns (ETableHeader *eth) -{ - ETableCol **ret; - int i; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - ret = g_new (ETableCol *, eth->col_count + 1); - memcpy (ret, eth->columns, sizeof (ETableCol *) * eth->col_count); - ret [eth->col_count] = NULL; - - for (i = 0; i < eth->col_count; i++) { - gtk_object_ref(GTK_OBJECT(ret[i])); - } - - return ret; -} - -/** - * e_table_header_get_selected: - * @eth: The ETableHeader to query - * - * Returns: The number of selected columns in the @eth object. - */ -int -e_table_header_get_selected (ETableHeader *eth) -{ - int i; - int selected = 0; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - for (i = 0; i < eth->col_count; i++){ - if (eth->columns [i]->selected) - selected++; - } - - return selected; -} - -/** - * e_table_header_total_width: - * @eth: The ETableHeader to query - * - * Returns: the number of pixels used by the @eth object - * when rendered on screen - */ -int -e_table_header_total_width (ETableHeader *eth) -{ - int total, i; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++) - total += eth->columns [i]->width; - - return total; -} - -/** - * e_table_header_move: - * @eth: The ETableHeader to operate on. - * @source_index: the source column to move. - * @target_index: the target location for the column - * - * This function moves the column @source_index to @target_index - * inside the @eth ETableHeader. The signals "dimension_change" - * and "structure_change" will be emmited - */ -void -e_table_header_move (ETableHeader *eth, int source_index, int target_index) -{ - ETableCol *old; - - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < eth->col_count); - g_return_if_fail (target_index < eth->col_count + 1); /* Can be moved beyond the last item. */ - - if (source_index < target_index) - target_index --; - - old = eth->columns [source_index]; - eth_do_remove (eth, source_index, FALSE); - eth_do_insert (eth, target_index, old); - eth_update_offsets (eth); - - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -/** - * e_table_header_remove: - * @eth: The ETableHeader to operate on. - * @idx: the index to the column to be removed. - * - * Removes the column at @idx position in the ETableHeader @eth. - * This emmits the "structure_change" signal on the @eth object. - */ -void -e_table_header_remove (ETableHeader *eth, int idx) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - - eth_do_remove (eth, idx, TRUE); - enqueue(eth, -1, eth->nominal_width); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -/* - * FIXME: deprecated? - */ -void -e_table_header_set_selection (ETableHeader *eth, gboolean allow_selection) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); -} - -static void -eth_set_size (ETableHeader *eth, int idx, int size) -{ - double expansion; - double old_expansion; - int min_width; - int left_width; - int total_extra; - int expandable_count; - int usable_width; - int i; - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - - /* If this column is not resizable, don't do anything. */ - if (!eth->columns[idx]->resizeable) - return; - - expansion = 0; - min_width = 0; - left_width = 0; - expandable_count = -1; - - /* Calculate usable area. */ - for (i = 0; i < idx; i++) { - left_width += eth->columns[i]->width; - } - /* - 1 to account for the last pixel border. */ - usable_width = eth->width - left_width - 1; - - if (eth->sort_info) - usable_width -= e_table_sort_info_grouping_get_count(eth->sort_info) * GROUP_INDENT; - - /* Calculate minimum_width of stuff on the right as well as - * total usable expansion on the right. - */ - for (; i < eth->col_count; i++) { - min_width += eth->columns[i]->min_width + eth->width_extras; - if (eth->columns[i]->resizeable) { - expansion += eth->columns[i]->expansion; - expandable_count ++; - } - } - /* If there's no room for anything, don't change. */ - if (expansion == 0) - return; - - /* (1) If none of the columns to the right are expandable, use - * all the expansion space in this column. - */ - if(expandable_count == 0) { - eth->columns[idx]->expansion = expansion; - for (i = idx + 1; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - total_extra = usable_width - min_width; - /* If there's no extra space, set all expansions to 0. */ - if (total_extra <= 0) { - for (i = idx; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - /* If you try to resize smaller than the minimum width, it - * uses the minimum. */ - if (size < eth->columns[idx]->min_width + eth->width_extras) - size = eth->columns[idx]->min_width + eth->width_extras; - - /* If all the extra space will be used up in this column, use - * all the expansion and set all others to 0. - */ - if (size >= total_extra + eth->columns[idx]->min_width + eth->width_extras) { - eth->columns[idx]->expansion = expansion; - for (i = idx + 1; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - /* The old_expansion used by columns to the right. */ - old_expansion = expansion; - old_expansion -= eth->columns[idx]->expansion; - /* Set the new expansion so that it will generate the desired size. */ - eth->columns[idx]->expansion = expansion * (((double)(size - (eth->columns[idx]->min_width + eth->width_extras)))/((double)total_extra)); - /* The expansion left for the columns on the right. */ - expansion -= eth->columns[idx]->expansion; - - /* (2) If the old columns to the right didn't have any - * expansion before, expand them evenly. old_expansion > 0 by - * expansion = SUM(i=idx to col_count -1, - * columns[i]->min_width) - columns[idx]->min_width) = - * SUM(non-negatives). - */ - if (old_expansion == 0) { - for (i = idx + 1; i < eth->col_count; i++) { - if (eth->columns[idx]->resizeable) { - /* expandable_count != 0 by (1) */ - eth->columns[i]->expansion = expansion / expandable_count; - } - } - return; - } - - /* Remove from total_extra the amount used for this column. */ - total_extra -= size - (eth->columns[idx]->min_width + eth->width_extras); - for (i = idx + 1; i < eth->col_count; i++) { - if (eth->columns[idx]->resizeable) { - /* old_expansion != 0 by (2) */ - eth->columns[i]->expansion *= expansion / old_expansion; - } - } -} - -/** - * e_table_header_col_diff: - * @eth: the ETableHeader to query. - * @start_col: the starting column - * @end_col: the ending column. - * - * Computes the number of pixels between the columns @start_col and - * @end_col. - * - * Returns: the number of pixels between @start_col and @end_col on the - * @eth ETableHeader object - */ -int -e_table_header_col_diff (ETableHeader *eth, int start_col, int end_col) -{ - int total, col; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - if (start_col < 0) - start_col = 0; - if (end_col > eth->col_count) - end_col = eth->col_count; - - total = 0; - for (col = start_col; col < end_col; col++){ - - total += eth->columns [col]->width; - } - - return total; -} - -static void -eth_calc_widths (ETableHeader *eth) -{ - int i; - int extra; - double expansion; - int last_position = 0; - double next_position = 0; - int last_resizable = -1; - /* - 1 to account for the last pixel border. */ - extra = eth->width - 1; - expansion = 0; - for (i = 0; i < eth->col_count; i++) { - extra -= eth->columns[i]->min_width + eth->width_extras; - if (eth->columns[i]->resizeable && eth->columns[i]->expansion > 0) - last_resizable = i; - expansion += eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0; - eth->columns[i]->width = eth->columns[i]->min_width + eth->width_extras; - } - if (eth->sort_info) - extra -= e_table_sort_info_grouping_get_count(eth->sort_info) * GROUP_INDENT; - if (expansion == 0 || extra <= 0) - return; - for (i = 0; i < last_resizable; i++) { - next_position += extra * (eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0)/expansion; - eth->columns[i]->width += next_position - last_position; - last_position = next_position; - } - eth->columns[i]->width += extra - last_position; - - eth_update_offsets (eth); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} - -void -e_table_header_update_horizontal (ETableHeader *eth) -{ - int i; - int cols; - - cols = eth->col_count; - - for (i = 0; i < cols; i++) { - int width; - - gtk_signal_emit_by_name (GTK_OBJECT (eth), - "request_width", - i, &width); - eth->columns[i]->min_width = width + 10; - eth->columns[i]->expansion = 1; - } - enqueue(eth, -1, eth->nominal_width); -} - -GtkType -e_table_header_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeader", - sizeof (ETableHeader), - sizeof (ETableHeaderClass), - (GtkClassInitFunc) e_table_header_class_init, - (GtkObjectInitFunc) e_table_header_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} diff --git a/widgets/table/e-table-header.h b/widgets/table/e-table-header.h deleted file mode 100644 index c186a8c48c..0000000000 --- a/widgets/table/e-table-header.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_COLUMN_H_ -#define _E_TABLE_COLUMN_H_ - -#include <gtk/gtkobject.h> -#include <gdk/gdk.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-col.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef struct _ETableHeader ETableHeader; - -#define E_TABLE_HEADER_TYPE (e_table_header_get_type ()) -#define E_TABLE_HEADER(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_TYPE, ETableHeader)) -#define E_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_TYPE, ETableHeaderClass)) -#define E_IS_TABLE_HEADER(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_TYPE)) -#define E_IS_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_TYPE)) - -/* - * A Columnar header. - */ -struct _ETableHeader { - GtkObject base; - - int col_count; - int width; - int nominal_width; - int width_extras; - - ETableSortInfo *sort_info; - int sort_info_group_change_id; - - ETableCol **columns; - - GSList *change_queue, *change_tail; - gint idle; -}; - -typedef struct { - GtkObjectClass parent_class; - - void (*structure_change) (ETableHeader *eth); - void (*dimension_change) (ETableHeader *eth, int col); - int (*request_width) (ETableHeader *eth, int col); -} ETableHeaderClass; - -GtkType e_table_header_get_type (void); -ETableHeader *e_table_header_new (void); - -void e_table_header_add_column (ETableHeader *eth, - ETableCol *tc, - int pos); -ETableCol *e_table_header_get_column (ETableHeader *eth, - int column); -ETableCol *e_table_header_get_column_by_col_idx (ETableHeader *eth, - int col_idx); -int e_table_header_count (ETableHeader *eth); -int e_table_header_index (ETableHeader *eth, - int col); -int e_table_header_get_index_at (ETableHeader *eth, - int x_offset); -ETableCol **e_table_header_get_columns (ETableHeader *eth); -int e_table_header_get_selected (ETableHeader *eth); - -int e_table_header_total_width (ETableHeader *eth); -void e_table_header_move (ETableHeader *eth, - int source_index, - int target_index); -void e_table_header_remove (ETableHeader *eth, - int idx); -void e_table_header_set_size (ETableHeader *eth, - int idx, - int size); -void e_table_header_set_selection (ETableHeader *eth, - gboolean allow_selection); -int e_table_header_col_diff (ETableHeader *eth, - int start_col, - int end_col); - -void e_table_header_calc_widths (ETableHeader *eth); -GList *e_table_header_get_selected_indexes (ETableHeader *eth); - -void e_table_header_update_horizontal (ETableHeader *eth); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_HEADER_H_ */ - diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c deleted file mode 100644 index 639d8196cf..0000000000 --- a/widgets/table/e-table-item.c +++ /dev/null @@ -1,2676 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-item.c: A GnomeCanvasItem that is a view of an ETableModel. - * - * Author: - * Christopher James Lahey <clahey@ximian.com> - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000, 2001, Ximian, Inc. - * - * TODO: - * Add a border to the thing, so that focusing works properly. - * - */ -#include <config.h> -#include <stdio.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <math.h> -#include "e-table-item.h" -#include "e-table-subset.h" -#include "e-cell.h" -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-canvas-utils.h" -#include "gal/util/e-util.h" - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define FOCUSED_BORDER 2 - -static GnomeCanvasItemClass *eti_parent_class; - -enum { - CURSOR_CHANGE, - CURSOR_ACTIVATED, - DOUBLE_CLICK, - RIGHT_CLICK, - CLICK, - KEY_PRESS, - LAST_SIGNAL -}; - -static gint eti_signals [LAST_SIGNAL] = { 0, }; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_TABLE_MODEL, - ARG_TABLE_SELECTION_MODEL, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_CURSOR_ROW, - - ARG_MINIMUM_WIDTH, - ARG_WIDTH, - ARG_HEIGHT, -}; - -#define DOUBLE_CLICK_TIME 250 -#define TRIPLE_CLICK_TIME 500 - - -static int eti_get_height (ETableItem *eti); -static int eti_get_minimum_width (ETableItem *eti); -static int eti_row_height (ETableItem *eti, int row); -static void e_table_item_focus (ETableItem *eti, int col, int row, GdkModifierType state); -static void eti_cursor_change (ETableSelectionModel *selection, int row, int col, ETableItem *eti); -static void eti_cursor_activated (ETableSelectionModel *selection, int row, int col, ETableItem *eti); -static void eti_selection_change (ETableSelectionModel *selection, ETableItem *eti); -#if 0 -static void eti_request_region_show (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row); -#endif -#define ETI_ROW_HEIGHT(eti,row) ((eti)->height_cache && (eti)->height_cache[(row)] != -1 ? (eti)->height_cache[(row)] : eti_row_height((eti),(row))) - -inline static gint -model_to_view_row(ETableItem *eti, int row) -{ - int i; - if (eti->uses_source_model) { - ETableSubset *etss = E_TABLE_SUBSET(eti->table_model); - if (eti->row_guess >= 0 && eti->row_guess < etss->n_map) { - if (etss->map_table[eti->row_guess] == row) { - return eti->row_guess; - } - } - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] == row) - return i; - } - return -1; - } else - return row; -} - -inline static gint -view_to_model_row(ETableItem *eti, int row) -{ - if (eti->uses_source_model) { - ETableSubset *etss = E_TABLE_SUBSET(eti->table_model); - if (row >= 0 && row < etss->n_map) - return etss->map_table[row]; - else - return -1; - } else - return row; -} - -inline static gint -model_to_view_col(ETableItem *eti, int col) -{ - int i; - for (i = 0; i < eti->cols; i++) { - ETableCol *ecol = e_table_header_get_column (eti->header, i); - if (ecol->col_idx == col) - return i; - } - return -1; -} - -inline static gint -view_to_model_col(ETableItem *eti, int col) -{ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - return ecol ? ecol->col_idx : -1; -} - -static gboolean -eti_editing (ETableItem *eti) -{ - if (eti->editing_col == -1) - return FALSE; - else - return TRUE; -} - -/* - * During realization, we have to invoke the per-ecell realize routine - * (On our current setup, we have one e-cell per column. - * - * We might want to optimize this to only realize the unique e-cells: - * ie, a strings-only table, uses the same e-cell for every column, and - * we might want to avoid realizing each e-cell. - */ -static void -eti_realize_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++) - e_cell_realize (eti->cell_views [i]); - eti->cell_views_realized = 1; -} - -static void -eti_attach_cell_views (ETableItem *eti) -{ - int i; - - g_assert (eti->header); - g_assert (eti->table_model); - - /* - * Now realize the various ECells - */ - eti->n_cells = eti->cols; - eti->cell_views = g_new (ECellView *, eti->n_cells); - - for (i = 0; i < eti->n_cells; i++){ - ETableCol *ecol = e_table_header_get_column (eti->header, i); - - eti->cell_views [i] = e_cell_new_view (ecol->ecell, eti->table_model, eti); - } - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -/* - * During unrealization: we invoke every e-cell (one per column in the current - * setup) to dispose all X resources allocated - */ -static void -eti_unrealize_cell_views (ETableItem *eti) -{ - int i; - - if (eti->cell_views_realized == 0) - return; - - for (i = 0; i < eti->n_cells; i++) - e_cell_unrealize (eti->cell_views [i]); - eti->cell_views_realized = 0; -} - -static void -eti_detach_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++){ - e_cell_kill_view (eti->cell_views [i]); - eti->cell_views [i] = NULL; - } - - g_free (eti->cell_views); - eti->cell_views = NULL; - eti->n_cells = 0; -} - -static void -eti_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - double i2c [6]; - ArtPoint c1, c2, i1, i2; - ETableItem *eti = E_TABLE_ITEM (item); - - /* Wrong BBox's are the source of redraw nightmares */ - - gnome_canvas_item_i2c_affine (GNOME_CANVAS_ITEM (eti), i2c); - - i1.x = eti->x1; - i1.y = eti->y1; - i2.x = eti->x1 + eti->width; - i2.y = eti->y1 + eti->height; - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - *x1 = c1.x; - *y1 = c1.y; - *x2 = c2.x + 1; - *y2 = c2.y + 1; -} - -static void -eti_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - if (eti->needs_compute_height) { - int new_height = eti_get_height (eti); - - if (new_height != eti->height) { - eti->height = new_height; - e_canvas_item_request_parent_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - } - eti->needs_compute_height = 0; - } - if (eti->needs_compute_width) { - int new_width = eti_get_minimum_width (eti); - new_width = MAX(new_width, eti->minimum_width); - if (new_width != eti->width) { - eti->width = new_width; - e_canvas_item_request_parent_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - } - eti->needs_compute_width = 0; - } -} - -/* - * GnomeCanvasItem::update method - */ -static void -eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ArtPoint o1, o2; - ETableItem *eti = E_TABLE_ITEM (item); - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update)(item, affine, clip_path, flags); - - o1.x = item->x1; - o1.y = item->y1; - o2.x = item->x2; - o2.y = item->y2; - - eti_bounds (item, &item->x1, &item->y1, &item->x2, &item->y2); - if (item->x1 != o1.x || - item->y1 != o1.y || - item->x2 != o2.x || - item->y2 != o2.y) { - gnome_canvas_request_redraw (item->canvas, o1.x, o1.y, o2.x, o2.y); - eti->needs_redraw = 1; - } - - if (eti->needs_redraw) { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, - item->x2, item->y2); - eti->needs_redraw = 0; - } -} - -/* - * eti_remove_table_model: - * - * Invoked to release the table model associated with this ETableItem - */ -static void -eti_remove_table_model (ETableItem *eti) -{ - if (!eti->table_model) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_pre_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_cell_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_inserted_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_deleted_id); - gtk_object_unref (GTK_OBJECT (eti->table_model)); - if (eti->source_model) - gtk_object_unref (GTK_OBJECT (eti->source_model)); - - eti->table_model_pre_change_id = 0; - eti->table_model_change_id = 0; - eti->table_model_row_change_id = 0; - eti->table_model_cell_change_id = 0; - eti->table_model_row_inserted_id = 0; - eti->table_model_row_deleted_id = 0; - eti->table_model = NULL; - eti->source_model = NULL; - eti->uses_source_model = 0; -} - -/* - * eti_remove_table_model: - * - * Invoked to release the table model associated with this ETableItem - */ -static void -eti_remove_table_selection_model (ETableItem *eti) -{ - if (!eti->selection) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->selection), - eti->selection_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->selection), - eti->cursor_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->selection), - eti->cursor_activated_id); - gtk_object_unref (GTK_OBJECT (eti->selection)); - - eti->selection_change_id = 0; - eti->cursor_activated_id = 0; - eti->selection = NULL; -} - -/* - * eti_remove_header_model: - * - * Invoked to release the header model associated with this ETableItem - */ -static void -eti_remove_header_model (ETableItem *eti) -{ - if (!eti->header) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_structure_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_dim_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_request_width_id); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - } - gtk_object_unref (GTK_OBJECT (eti->header)); - - - eti->header_structure_change_id = 0; - eti->header_dim_change_id = 0; - eti->header_request_width_id = 0; - eti->header = NULL; -} - -/* - * eti_row_height_real: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static int -eti_row_height_real (ETableItem *eti, int row) -{ - const int cols = e_table_header_count (eti->header); - int col; - int h, max_h; - - g_assert (cols == 0 || eti->cell_views); - - max_h = 0; - - for (col = 0; col < cols; col++){ - h = e_cell_height (eti->cell_views [col], view_to_model_col(eti, col), col, row); - - if (h > max_h) - max_h = h; - } - return max_h; -} - -static gboolean -height_cache_idle(ETableItem *eti) -{ - int changed = 0; - int i; - if (!eti->height_cache) { - eti->height_cache = g_new(int, eti->rows); - } - for (i = eti->height_cache_idle_count; i < eti->rows; i++) { - if (eti->height_cache[i] == -1) { - eti_row_height(eti, i); - changed ++; - if (changed >= 20) - break; - } - } - if (changed >= 20) { - eti->height_cache_idle_count = i; - return TRUE; - } - eti->height_cache_idle_id = 0; - return FALSE; -} - -static void -free_height_cache (ETableItem *eti) -{ - if (eti->height_cache) - g_free (eti->height_cache); - eti->height_cache = NULL; - eti->height_cache_idle_count = 0; - - if (eti->height_cache_idle_id == 0) - eti->height_cache_idle_id = g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc) height_cache_idle, eti, NULL); -} - -static void -calculate_height_cache (ETableItem *eti) -{ - int i; - free_height_cache(eti); - eti->height_cache = g_new(int, eti->rows); - for (i = 0; i < eti->rows; i++) { - eti->height_cache[i] = -1; - } -} - - -/* - * eti_row_height: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static int -eti_row_height (ETableItem *eti, int row) -{ - if (!eti->height_cache) { - calculate_height_cache (eti); - } - if (eti->height_cache[row] == -1) { - eti->height_cache[row] = eti_row_height_real(eti, row); - if (row > 0 && - eti->length_threshold != -1 && - eti->rows > eti->length_threshold && - eti->height_cache[row] != eti_row_height(eti, 0)) { - eti->needs_compute_height = 1; - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(eti)); - } - } - return eti->height_cache[row]; -} - -/* - * eti_get_height: - * - * Returns the height of the ETableItem. - * - * The ETableItem might compute the whole height by asking every row its - * size. There is a special mode (designed to work when there are too - * many rows in the table that performing the previous step could take - * too long) set by the ETableItem->length_threshold that would determine - * when the height is computed by using the first row as the size for - * every other row in the ETableItem. - */ -static int -eti_get_height (ETableItem *eti) -{ - const int rows = eti->rows; - int row; - int height; - - if (rows == 0) - return 0; - - if (eti->length_threshold != -1){ - if (rows > eti->length_threshold){ - int row_height = eti_row_height(eti, 0); - if (eti->height_cache) { - height = 0; - for (row = 0; row < rows; row++) { - if (eti->height_cache[row] == -1) { - height += (row_height + 1) * (rows - row); - break; - } - else - height += eti->height_cache[row] + 1; - } - } else - height = (eti_row_height (eti, 0) + 1) * rows; - - /* - * 1 pixel at the top - */ - return height + 1; - } - } - - height = 1; - for (row = 0; row < rows; row++) - height += eti_row_height (eti, row) + 1; - - return height; -} - -static int -eti_get_minimum_width (ETableItem *eti) -{ - int width = 0; - int col; - for (col = 0; col < eti->cols; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - width += ecol->min_width; - } - return width; -} - -static void -eti_item_region_redraw (ETableItem *eti, int x0, int y0, int x1, int y1) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - ArtDRect rect; - double i2c [6]; - - rect.x0 = x0; - rect.y0 = y0; - rect.x1 = x1; - rect.y1 = y1; - - gnome_canvas_item_i2c_affine (item, i2c); - art_drect_affine_transform (&rect, &rect, i2c); - - gnome_canvas_request_redraw (item->canvas, rect.x0, rect.y0, rect.x1, rect.y1); -} - -/* - * Callback routine: invoked before the ETableModel has suffers a change - */ -static void -eti_table_model_pre_change (ETableModel *table_model, ETableItem *eti) -{ - if (eti_editing (eti)) - e_table_item_leave_edit (eti); -} - -/* - * Callback routine: invoked when the ETableModel has suffered a change - */ -static void -eti_table_model_changed (ETableModel *table_model, ETableItem *eti) -{ -#if 0 - int view_row; -#endif - - eti->rows = e_table_model_row_count (eti->table_model); - - free_height_cache(eti); - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - -#if 0 - view_row = model_to_view_row(eti, eti->cursor_row); - if (view_row >= 0 && eti->cursor_col >= 0) - eti_request_region_show (eti, eti->cursor_col, view_row, eti->cursor_col, view_row); -#endif -} - -/* - * Computes the distance between @start_row and @end_row in pixels - */ -static int -eti_row_diff (ETableItem *eti, int start_row, int end_row) -{ - int row, total; - - total = 0; - - for (row = start_row; row < end_row; row++) - total += eti_row_height (eti, row) + 1; - - return total; -} - -/* - * eti_request_region_redraw: - * - * Request a canvas redraw on the range (start_col, start_row) to (end_col, end_row). - * This is inclusive (ie, you can use: 0,0-0,0 to redraw the first cell). - * - * The @border argument is a number of pixels around the region that should also be queued - * for redraw. This is typically used by the focus routines to queue a redraw for the - * border as well. - */ -static void -eti_request_region_redraw (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row, int border) -{ - int x1, y1, width, height; - - if (eti->rows > 0) { - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = eti_row_diff (eti, 0, start_row); - width = e_table_header_col_diff (eti->header, start_col, end_col + 1); - height = eti_row_diff (eti, start_row, end_row + 1); - - eti_item_region_redraw (eti, eti->x1 + x1 - border, - eti->y1 + y1 - border, - eti->x1 + x1 + width + 1 + border, - eti->y1 + y1 + height + 1 + border); - } -} - -/* - * eti_request_region_show - * - * Request a canvas show on the range (start_col, start_row) to (end_col, end_row). - * This is inclusive (ie, you can use: 0,0-0,0 to show the first cell). - */ -static void -eti_request_region_show (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row, int delay) -{ - int x1, y1, x2, y2; - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = eti_row_diff (eti, 0, start_row); - x2 = x1 + e_table_header_col_diff (eti->header, start_col, end_col + 1); - y2 = y1 + eti_row_diff (eti, start_row, end_row + 1); - - if (delay) - e_canvas_item_show_area_delayed(GNOME_CANVAS_ITEM(eti), x1, y1, x2, y2, delay); - else - e_canvas_item_show_area(GNOME_CANVAS_ITEM(eti), x1, y1, x2, y2); -} - -static void -eti_table_model_row_changed (ETableModel *table_model, int row, ETableItem *eti) -{ - if (eti->renderers_can_change_size && - eti->height_cache && eti->height_cache[row] != -1 && - eti_row_height_real(eti, row) != eti->height_cache[row]) { - eti_table_model_changed (table_model, eti); - return; - } - - eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, 0); -} - -static void -eti_table_model_cell_changed (ETableModel *table_model, int col, int row, ETableItem *eti) -{ - if (eti->renderers_can_change_size && - eti->height_cache && eti->height_cache[row] != -1 && - eti_row_height_real(eti, row) != eti->height_cache[row]) { - eti_table_model_changed (table_model, eti); - return; - } - - eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, 0); -} - -static void -eti_table_model_row_inserted (ETableModel *table_model, int row, ETableItem *eti) -{ - eti->rows = e_table_model_row_count (eti->table_model); - - if (eti->height_cache) { - eti->height_cache = g_renew(int, eti->height_cache, eti->rows); - memmove(eti->height_cache + row + 1, eti->height_cache + row, (eti->rows - 1 - row) * sizeof(int)); - eti->height_cache[row] = -1; - } - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_table_model_row_deleted (ETableModel *table_model, int row, ETableItem *eti) -{ - eti->rows = e_table_model_row_count (eti->table_model); - - if (eti->height_cache) - memmove(eti->height_cache + row, eti->height_cache + row + 1, (eti->rows - row) * sizeof(int)); - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -/** - * e_table_item_redraw_range - * @eti: %ETableItem which will be redrawn - * @start_col: The first col to redraw. - * @start_row: The first row to redraw. - * @end_col: The last col to redraw. - * @end_row: The last row to redraw. - * - * This routine redraws the given %ETableItem in the range given. The - * range is inclusive at both ends. - */ -void -e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row) -{ - int border; - int cursor_col, cursor_row; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - if ((start_col == cursor_col) || - (end_col == cursor_col) || - (view_to_model_row(eti, start_row) == cursor_row) || - (view_to_model_row(eti, end_row) == cursor_row)) - border = 2; - else - border = 0; - - eti_request_region_redraw(eti, start_col, start_row, end_col, end_row, border); -} - -static void -eti_add_table_model (ETableItem *eti, ETableModel *table_model) -{ - g_assert (eti->table_model == NULL); - - eti->table_model = table_model; - gtk_object_ref (GTK_OBJECT (eti->table_model)); - - eti->table_model_pre_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_pre_change", - GTK_SIGNAL_FUNC (eti_table_model_pre_change), eti); - - eti->table_model_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_changed", - GTK_SIGNAL_FUNC (eti_table_model_changed), eti); - - eti->table_model_row_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_changed", - GTK_SIGNAL_FUNC (eti_table_model_row_changed), eti); - - eti->table_model_cell_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_cell_changed", - GTK_SIGNAL_FUNC (eti_table_model_cell_changed), eti); - - eti->table_model_row_inserted_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_inserted", - GTK_SIGNAL_FUNC (eti_table_model_row_inserted), eti); - - eti->table_model_row_deleted_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_deleted", - GTK_SIGNAL_FUNC (eti_table_model_row_deleted), eti); - - if (eti->header) { - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - - if (E_IS_TABLE_SUBSET(table_model)) { - eti->uses_source_model = 1; - eti->source_model = E_TABLE_SUBSET(table_model)->source; - if (eti->source_model) - gtk_object_ref(GTK_OBJECT(eti->source_model)); - } - - eti_table_model_changed (table_model, eti); -} - -static void -eti_add_table_selection_model (ETableItem *eti, ETableSelectionModel *selection) -{ - g_assert (eti->selection == NULL); - - eti->selection = selection; - gtk_object_ref (GTK_OBJECT (eti->selection)); - - eti->selection_change_id = gtk_signal_connect ( - GTK_OBJECT (selection), "selection_changed", - GTK_SIGNAL_FUNC (eti_selection_change), eti); - - eti->cursor_change_id = gtk_signal_connect ( - GTK_OBJECT (selection), "cursor_changed", - GTK_SIGNAL_FUNC (eti_cursor_change), eti); - - eti->cursor_activated_id = gtk_signal_connect ( - GTK_OBJECT (selection), "cursor_activated", - GTK_SIGNAL_FUNC (eti_cursor_activated), eti); - - eti_selection_change(selection, eti); -} - -static void -eti_header_dim_changed (ETableHeader *eth, int col, ETableItem *eti) -{ - eti->needs_compute_width = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_header_structure_changed (ETableHeader *eth, ETableItem *eti) -{ - eti->cols = e_table_header_count (eti->header); - eti->width = e_table_header_total_width (eti->header); - - /* - * There should be at least one column - * BUT: then you can't remove all columns from a header and add new ones. - */ - /*g_assert (eti->cols != 0);*/ - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - eti_realize_cell_views (eti); - } else { - if (eti->table_model) { - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - } - eti->needs_compute_width = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); -} - -static int -eti_request_column_width (ETableHeader *eth, int col, ETableItem *eti) -{ - int width = 0; - - if (eti->cell_views) { - width = e_cell_max_width (eti->cell_views[col], view_to_model_col(eti, col), col); - } - - return width; -} - -static void -eti_add_header_model (ETableItem *eti, ETableHeader *header) -{ - g_assert (eti->header == NULL); - - eti->header = header; - gtk_object_ref (GTK_OBJECT (header)); - - eti_header_structure_changed (header, eti); - - eti->header_dim_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC (eti_header_dim_changed), eti); - - eti->header_structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC (eti_header_structure_changed), eti); - - eti->header_request_width_id = gtk_signal_connect - (GTK_OBJECT (header), "request_width", - GTK_SIGNAL_FUNC (eti_request_column_width), eti); -} - -/* - * GtkObject::destroy method - */ -static void -eti_destroy (GtkObject *object) -{ - ETableItem *eti = E_TABLE_ITEM (object); - - eti_remove_header_model (eti); - eti_remove_table_model (eti); - eti_remove_table_selection_model (eti); - - if (eti->height_cache_idle_id) - g_source_remove(eti->height_cache_idle_id); - - if (eti->height_cache) - g_free (eti->height_cache); - eti->height_cache = NULL; - eti->height_cache_idle_count = 0; - - if (eti->tooltip->window) - gtk_widget_destroy (eti->tooltip->window); - if (eti->tooltip->timer) { - gtk_timeout_remove (eti->tooltip->timer); - eti->tooltip->timer = 0; - } - g_free (eti->tooltip); - - if (GTK_OBJECT_CLASS (eti_parent_class)->destroy) - (*GTK_OBJECT_CLASS (eti_parent_class)->destroy) (object); -} - -static void -eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableItem *eti; - int cursor_col; - - item = GNOME_CANVAS_ITEM (o); - eti = E_TABLE_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - eti_remove_header_model (eti); - eti_add_header_model (eti, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_TABLE_MODEL: - eti_remove_table_model (eti); - eti_add_table_model (eti, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_TABLE_SELECTION_MODEL: - eti_remove_table_selection_model (eti); - if (GTK_VALUE_OBJECT (*arg)) - eti_add_table_selection_model (eti, E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_LENGTH_THRESHOLD: - eti->length_threshold = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_DRAW_GRID: - eti->draw_grid = GTK_VALUE_BOOL (*arg); - break; - - case ARG_TABLE_DRAW_FOCUS: - eti->draw_focus = GTK_VALUE_BOOL (*arg); - break; - - case ARG_CURSOR_MODE: - eti->cursor_mode = GTK_VALUE_INT (*arg); - break; - - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - if (eti->minimum_width == eti->width && GTK_VALUE_DOUBLE (*arg) > eti->width) - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->minimum_width = GTK_VALUE_DOUBLE (*arg); - if (eti->minimum_width < eti->width) - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - break; - case ARG_CURSOR_ROW: - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - NULL); - - e_table_item_focus (eti, cursor_col != -1 ? cursor_col : 0, view_to_model_row(eti, GTK_VALUE_INT (*arg)), 0); - break; - } - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(eti)); -} - -static void -eti_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableItem *eti; - int row; - - item = GNOME_CANVAS_ITEM (o); - eti = E_TABLE_ITEM (o); - - switch (arg_id){ - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eti->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = eti->height; - break; - case ARG_MINIMUM_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eti->minimum_width; - break; - case ARG_CURSOR_ROW: - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &row, - NULL); - GTK_VALUE_INT (*arg) = model_to_view_row(eti, row); - break; - default: - arg->type = GTK_TYPE_INVALID; - } -} - -static void -eti_init (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - eti->editing_col = -1; - eti->editing_row = -1; - eti->height = 0; - eti->width = 0; - eti->minimum_width = 0; - - eti->height_cache = NULL; - eti->height_cache_idle_id = 0; - eti->height_cache_idle_count = 0; - - eti->length_threshold = -1; - eti->renderers_can_change_size = 1; - - eti->uses_source_model = 0; - eti->source_model = NULL; - - eti->row_guess = -1; - eti->cursor_mode = E_TABLE_CURSOR_SIMPLE; - - eti->selection_change_id = 0; - eti->cursor_change_id = 0; - eti->cursor_activated_id = 0; - eti->selection = NULL; - - eti->needs_redraw = 0; - eti->needs_compute_height = 0; - - eti->in_key_press = 0; - - eti->tooltip = g_new0 (ETableTooltip, 1); - eti->tooltip->timer = 0; - eti->tooltip->window = NULL; - eti->tooltip->eti = GNOME_CANVAS_ITEM (eti); - - eti->grabbed_col = -1; - eti->grabbed_row = -1; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (eti), eti_reflow); -} - -#define gray50_width 2 -#define gray50_height 2 -static const char gray50_bits[] = { - 0x02, 0x01, }; - -#if 0 -static gint -eti_visibility_notify(GtkWidget *widget, - GdkEventVisibility *event, - ETableItem *eti) -{ - if (eti->tooltip->window) { - gtk_widget_destroy (eti->tooltip->window); - eti->tooltip->window = NULL; - } - - return FALSE; -} -#endif - -static void -eti_realize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - GtkWidget *canvas_widget = GTK_WIDGET (item->canvas); - GdkWindow *window; -#if 0 - GdkEventMask mask; -#endif - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); - - /* - * Gdk Resource allocation - */ - window = canvas_widget->window; - - eti->fill_gc = gdk_gc_new (window); - - eti->grid_gc = gdk_gc_new (window); -#if 0 - /* This sets it to gray */ -/* gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); */ -#else - gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->dark [GTK_STATE_NORMAL]); -#endif - eti->focus_gc = gdk_gc_new (window); - gdk_gc_set_foreground (eti->focus_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); - gdk_gc_set_background (eti->focus_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); - eti->stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height); - gdk_gc_set_ts_origin (eti->focus_gc, 0, 0); - gdk_gc_set_stipple (eti->focus_gc, eti->stipple); - gdk_gc_set_fill (eti->focus_gc, GDK_OPAQUE_STIPPLED); - -#if 0 - mask = gtk_widget_get_events(GTK_WIDGET(item->canvas)); - mask |= GDK_VISIBILITY_NOTIFY_MASK; - gtk_widget_set_events(GTK_WIDGET(item->canvas), mask); - - gtk_signal_connect(GTK_OBJECT(item->canvas), "visibility_notify_event", - GTK_SIGNAL_FUNC(eti_visibility_notify), eti); -#endif - - if (eti->cell_views == NULL) - eti_attach_cell_views (eti); - - eti_realize_cell_views (eti); - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_unrealize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - if (eti_editing (eti)) - e_table_item_leave_edit (eti); - - gdk_gc_unref (eti->fill_gc); - eti->fill_gc = NULL; - gdk_gc_unref (eti->grid_gc); - eti->grid_gc = NULL; - gdk_gc_unref (eti->focus_gc); - eti->focus_gc = NULL; - gdk_bitmap_unref (eti->stipple); - eti->stipple = NULL; - - eti_unrealize_cell_views (eti); - - eti->height = 0; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); -} - -static void -eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableItem *eti = E_TABLE_ITEM (item); - const int rows = eti->rows; - const int cols = eti->cols; - int row, col, y1, y2; - int first_col, last_col, x_offset; - int first_row, last_row, y_offset, yd; - int x1, x2; - int f_x1, f_x2, f_y1, f_y2; - gboolean f_found; - double i2c [6]; - ArtPoint eti_base, eti_base_item, lower_right; - GtkWidget *canvas = GTK_WIDGET(item->canvas); - GdkColor *background; - - /* - * Clear the background - */ -#if 0 - gdk_draw_rectangle ( - drawable, eti->fill_gc, TRUE, - eti->x1 - x, eti->y1 - y, eti->width, eti->height); -#endif - - /* - * Find out our real position after grouping - */ - gnome_canvas_item_i2c_affine (item, i2c); - eti_base_item.x = eti->x1; - eti_base_item.y = eti->y1; - art_affine_point (&eti_base, &eti_base_item, i2c); - - eti_base_item.x = eti->x1 + eti->width; - eti_base_item.y = eti->y1 + eti->height; - art_affine_point (&lower_right, &eti_base_item, i2c); - - /* - * First column to draw, last column to draw - */ - first_col = -1; - last_col = x_offset = 0; - x1 = x2 = floor (eti_base.x); - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - x2 = x1 + ecol->width; - - if (x1 > (x + width)) - break; - if (x2 < x) - continue; - if (first_col == -1){ - x_offset = x1 - x; - first_col = col; - } - } - last_col = col; - - /* - * Nothing to paint - */ - if (first_col == -1) - return; - - /* - * Compute row span. - */ - first_row = -1; - y_offset = 0; - y1 = y2 = floor (eti_base.y) + 1; - for (row = 0; row < rows; row++, y1 = y2){ - - y2 += ETI_ROW_HEIGHT (eti, row) + 1; - - if (y1 > y + height) - break; - - if (y2 < y) - continue; - - if (first_row == -1){ - y_offset = y1 - y; - first_row = row; - } - } - last_row = row; - - if (first_row == -1) - return; - - /* - * Draw cells - */ - yd = y_offset; - f_x1 = f_x2 = f_y1 = f_y2 = -1; - f_found = FALSE; - - if (eti->draw_grid && first_row == 0){ - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - } - yd++; - - for (row = first_row; row < last_row; row++){ - int xd, height; - gboolean selected; - gint cursor_col, cursor_row; - - height = ETI_ROW_HEIGHT (eti, row); - - xd = x_offset; -/* printf ("paint: %d %d\n", yd, yd + height); */ - - selected = e_table_selection_model_is_row_selected(eti->selection, view_to_model_row(eti,row)); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - for (col = first_col; col < last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - ECellView *ecell_view = eti->cell_views [col]; - gboolean col_selected = selected; - ECellFlags flags; - switch (eti->cursor_mode) { - case E_TABLE_CURSOR_SIMPLE: - case E_TABLE_CURSOR_SPREADSHEET: - if (cursor_col == ecol->col_idx && cursor_row == view_to_model_row(eti, row)) - col_selected = !col_selected; - break; - case E_TABLE_CURSOR_LINE: - /* Nothing */ - break; - } - - if (col_selected){ - if (GTK_WIDGET_HAS_FOCUS(canvas)) - background = &canvas->style->bg [GTK_STATE_SELECTED]; - else - background = &canvas->style->bg [GTK_STATE_ACTIVE]; - } else { -#if 0 - if (row % 2) -#endif - background = &canvas->style->base [GTK_STATE_NORMAL]; -#if 0 - else - background = &canvas->style->base [GTK_STATE_SELECTED]; -#endif - } - - gdk_gc_set_foreground (eti->fill_gc, background); - gdk_draw_rectangle (drawable, eti->fill_gc, TRUE, - xd, yd, ecol->width, height); - - flags = col_selected ? E_CELL_SELECTED : 0; - flags |= GTK_WIDGET_HAS_FOCUS(canvas) ? E_CELL_FOCUSED : 0; - switch (ecol->justification) { - case GTK_JUSTIFY_LEFT: - flags |= E_CELL_JUSTIFY_LEFT; - break; - case GTK_JUSTIFY_RIGHT: - flags |= E_CELL_JUSTIFY_RIGHT; - break; - case GTK_JUSTIFY_CENTER: - flags |= E_CELL_JUSTIFY_CENTER; - break; - case GTK_JUSTIFY_FILL: - flags |= E_CELL_JUSTIFY_FILL; - break; - } - - e_cell_draw (ecell_view, drawable, ecol->col_idx, col, row, flags, - xd, yd, xd + ecol->width, yd + height); - - if (!f_found) { - switch (eti->cursor_mode) { - case E_TABLE_CURSOR_LINE: - if (view_to_model_row(eti, row) == cursor_row) { - f_x1 = floor (eti_base.x) - x; - f_x2 = floor (lower_right.x) - x; - f_y1 = yd; - f_y2 = yd + height; - f_found = TRUE; - } - break; - case E_TABLE_CURSOR_SIMPLE: - case E_TABLE_CURSOR_SPREADSHEET: - if (view_to_model_col(eti, col) == cursor_col && view_to_model_row(eti, row) == cursor_row) { - f_x1 = xd; - f_x2 = xd + ecol->width; - f_y1 = yd; - f_y2 = yd + height; - f_found = TRUE; - } - break; - } - } - - xd += ecol->width; - } - yd += height; - - if (eti->draw_grid) - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - yd++; - } - - if (eti->draw_grid){ - int xd = x_offset; - - for (col = first_col; col <= last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - gdk_draw_line ( - drawable, eti->grid_gc, - xd, y_offset, xd, yd - 1); - - /* - * This looks wierd, but it is to draw the last line - */ - if (ecol) - xd += ecol->width; - } - } - - /* - * Draw focus - */ - if (eti->draw_focus && f_found) { - gdk_gc_set_ts_origin (eti->focus_gc, f_x1, f_y1); - gdk_draw_rectangle (drawable, eti->focus_gc, FALSE, - f_x1, f_y1, f_x2 - f_x1 - 1, f_y2 - f_y1 - 1); - } -} - -static double -eti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - - return 0.0; -} - -static gboolean -find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res, double *x1_res, double *y1_res) -{ - const int cols = eti->cols; - const int rows = eti->rows; - gdouble x1, y1, x2, y2; - int col, row; - - /* FIXME: this routine is inneficient, fix later */ - - if (eti->grabbed_col >= 0 && eti->grabbed_row >= 0) { - *col_res = eti->grabbed_col; - *row_res = eti->grabbed_row; - *x1_res = x - eti->x1 - e_table_header_col_diff (eti->header, 0, eti->grabbed_col); - *y1_res = y - eti->y1 - eti_row_diff (eti, 0, eti->grabbed_row); - return TRUE; - } - - if (cols == 0 || rows == 0) - return FALSE; - - x -= eti->x1; - y -= eti->y1; - - x1 = 0; - for (col = 0; col < cols - 1; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - if (x < x1) - return FALSE; - - x2 = x1 + ecol->width; - - if (x <= x2) - break; - } - - y1 = y2 = 0; - for (row = 0; row < rows - 1; row++, y1 = y2){ - if (y < y1) - return FALSE; - - y2 += ETI_ROW_HEIGHT (eti, row) + 1; - - if (y <= y2) - break; - } - *col_res = col; - if (x1_res) - *x1_res = x - x1; - *row_res = row; - if (y1_res) - *y1_res = y - y1; - return TRUE; -} - -static void -eti_cursor_move (ETableItem *eti, gint row, gint column) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, view_to_model_col(eti, column), view_to_model_row(eti, row), 0); -} - -static void -eti_cursor_move_left (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row), model_to_view_col(eti, cursor_col) - 1); -} - -static void -eti_cursor_move_right (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row), model_to_view_col(eti, cursor_col) + 1); -} - -#if 0 -static void -eti_cursor_move_up (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) - 1, model_to_view_col(eti, cursor_col)); -} - -static void -eti_cursor_move_down (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) + 1, model_to_view_col(eti, cursor_col)); -} -#endif - -#if 0 -static int -_do_tooltip (ETableItem *eti) -{ - ECellView *ecell_view; - int x = 0, y = 0; - int i; - - if (eti->tooltip->window) { - gtk_widget_destroy (eti->tooltip->window); - eti->tooltip->window = NULL; - } - - if (eti_editing (eti)) - return FALSE; - - ecell_view = eti->cell_views[eti->tooltip->col]; - - for (i = 0; i < eti->tooltip->col; i++) - x += eti->header->columns[i]->width; - eti->tooltip->x = x; - - for (i = 0; i < eti->tooltip->row; i++) - y += (ETI_ROW_HEIGHT (eti, i) + 1); - eti->tooltip->y = y; - eti->tooltip->row_height = ETI_ROW_HEIGHT (eti, i); - - e_cell_show_tooltip (ecell_view, - view_to_model_col (eti, eti->tooltip->col), - eti->tooltip->col, - eti->tooltip->row, - eti->header->columns[eti->tooltip->col]->width, - eti->tooltip); - return FALSE; -} -#endif - -static gint -eti_e_cell_event (ETableItem *item, ECellView *ecell_view, GdkEvent *event, int time, int model_col, int view_col, int row, ECellFlags flags) -{ - ECellActions actions = 0; - gint ret_val; - - ret_val = e_cell_event (ecell_view, event, model_col, view_col, row, flags, &actions); - - if (actions & E_CELL_GRAB) { - gnome_canvas_item_grab(GNOME_CANVAS_ITEM(item), GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, time); - item->grabbed_col = view_col; - item->grabbed_row = row; - } - - if (actions & E_CELL_UNGRAB) { - gnome_canvas_item_ungrab(GNOME_CANVAS_ITEM(item), time); - item->grabbed_col = -1; - item->grabbed_row = -1; - } - - return ret_val; -} - -/* FIXME: cursor */ -static int -eti_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableItem *eti = E_TABLE_ITEM (item); - ECellView *ecell_view; - gint return_val = TRUE; - - switch (e->type){ - case GDK_BUTTON_PRESS: { - double x1, y1; - GdkEventButton button; - int col, row; - gint cursor_row, cursor_col; - - if (eti->tooltip->timer) { - gtk_timeout_remove (eti->tooltip->timer); - eti->tooltip->timer = 0; - } - - switch (e->button.button) { - case 1: /* Fall through. */ - case 2: - e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(eti)); - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) { - if (eti_editing (eti)) - e_table_item_leave_edit (eti); - return TRUE; - } - - ecell_view = eti->cell_views [col]; - button = *(GdkEventButton *)e; - button.x = x1; - button.y = y1; - - return_val = eti_e_cell_event (eti, ecell_view, (GdkEvent *) &button, button.time, view_to_model_col(eti, col), col, row, 0); - if (return_val) - return TRUE; - - return_val = FALSE; - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CLICK], - row, view_to_model_col(eti, col), &button, &return_val); - if (return_val) - return TRUE; - - e_table_selection_model_do_something(eti->selection, view_to_model_row(eti, row), view_to_model_col(eti, col), button.state); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - - if ((!eti_editing(eti)) && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, col, row); - } - - /* - * Adjust the event positions - */ - - return_val = eti_e_cell_event (eti, ecell_view, (GdkEvent *) &button, button.time, - view_to_model_col(eti, col), col, row, E_CELL_EDITING); - } - g_print("Single click\n"); - - break; - case 3: - e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(eti)); - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - e_table_selection_model_maybe_do_something(eti->selection, view_to_model_row(eti, row), view_to_model_col(eti, col), 0); - - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [RIGHT_CLICK], - row, view_to_model_col(eti, col), e, &return_val); - break; - case 4: - case 5: - return FALSE; - break; - - } - break; - } - - case GDK_BUTTON_RELEASE: { - double x1, y1; - int col, row; - gint cursor_row, cursor_col; - - if (eti->tooltip->timer) { - gtk_timeout_remove (eti->tooltip->timer); - eti->tooltip->timer = 0; - } - if (eti->tooltip->window) { - gtk_widget_destroy (eti->tooltip->window); - eti->tooltip->window = NULL; - } - switch (e->button.button) { - case 1: /* Fall through. */ - case 2: - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->button.x = x1; - e->button.y = y1; - - return_val = eti_e_cell_event (eti, ecell_view, e, e->button.time, - view_to_model_col(eti, col), col, row, E_CELL_EDITING); - } - g_print ("Release\n"); - break; - case 3: - case 4: - case 5: - return FALSE; - break; - - } - break; - } - - case GDK_2BUTTON_PRESS: { - int col, row; - GdkEventButton button; - - if (e->button.button == 5 || - e->button.button == 4) - return FALSE; - - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - -#if 0 - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; -#endif - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &row, - "cursor_col", &col, - NULL); - -#if 0 - button = *(GdkEventButton *)e; - button.x = x1; - button.y = y1; -#endif - - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [DOUBLE_CLICK], - row, col, &button); - g_print("Double click\n"); - break; - } - case GDK_MOTION_NOTIFY: { - int col, row; - double x1, y1; - gint cursor_col, cursor_row; - - gnome_canvas_item_w2i (item, &e->motion.x, &e->motion.y); - - if (!find_cell (eti, e->motion.x, e->motion.y, &col, &row, &x1, &y1)) - return TRUE; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (eti->tooltip->window) { - gtk_widget_destroy (eti->tooltip->window); - eti->tooltip->window = NULL; - } - - if (eti->tooltip->timer > 0) - gtk_timeout_remove (eti->tooltip->timer); -#if 0 - eti->tooltip->col = col; - eti->tooltip->row = row; - eti->tooltip->cx = e->motion.x; - eti->tooltip->cy = e->motion.y; - eti->tooltip->timer = gtk_timeout_add (100, (GSourceFunc)_do_tooltip, eti); -#endif - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->motion.x = x1; - e->motion.y = y1; - - return_val = eti_e_cell_event (eti, ecell_view, e, e->motion.time, - view_to_model_col(eti, col), col, row, E_CELL_EDITING); - } - break; - } - - case GDK_KEY_PRESS: { - gint cursor_row, cursor_col; - gint handled = TRUE; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (eti->tooltip->window) { - gtk_widget_destroy (eti->tooltip->window); - eti->tooltip->window = NULL; - } - - if (cursor_col == -1) - return FALSE; - - eti->in_key_press = TRUE; - - switch (e->key.keyval){ - case GDK_Left: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - if (eti->cursor_mode != E_TABLE_CURSOR_LINE && cursor_col != view_to_model_col(eti, 0)) - eti_cursor_move_left (eti); - break; - - case GDK_Right: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - if (eti->cursor_mode != E_TABLE_CURSOR_LINE && cursor_col != view_to_model_col(eti, eti->cols - 1)) - eti_cursor_move_right (eti); - break; - - case GDK_Up: - case GDK_Down: - return_val = e_table_selection_model_key_press(eti->selection, (GdkEventKey *) e); - break; -#if 0 - case GDK_Up: - if (cursor_row != view_to_model_row(eti, 0)) - eti_cursor_move_up (eti); - else - return_val = FALSE; - break; - - case GDK_Down: - if (cursor_row != view_to_model_row(eti, eti->rows - 1)) - eti_cursor_move_down (eti); - else - return_val = FALSE; - break; -#endif - case GDK_Home: - case GDK_KP_Home: - if (eti->cursor_mode != E_TABLE_CURSOR_LINE) { - eti_cursor_move (eti, model_to_view_row(eti, cursor_row), 0); - return_val = TRUE; - } else - return_val = e_table_selection_model_key_press(eti->selection, (GdkEventKey *) e); - break; - case GDK_End: - case GDK_KP_End: - if (eti->cursor_mode != E_TABLE_CURSOR_LINE) { - eti_cursor_move (eti, model_to_view_row(eti, cursor_row), eti->cols - 1); - return_val = TRUE; - } else - return_val = e_table_selection_model_key_press(eti->selection, (GdkEventKey *) e); - break; - case GDK_Tab: - case GDK_KP_Tab: - case GDK_ISO_Left_Tab: - if (eti->cursor_mode == E_TABLE_CURSOR_SPREADSHEET) { - if ((e->key.state & GDK_SHIFT_MASK) != 0){ - /* shift tab */ - if (cursor_col != view_to_model_col(eti, 0)) - eti_cursor_move_left (eti); - else if (cursor_row != view_to_model_row(eti, 0)) - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) - 1, eti->cols - 1); - else - return_val = FALSE; - } else { - if (cursor_col != view_to_model_col (eti, eti->cols - 1)) - eti_cursor_move_right (eti); - else if (cursor_row != view_to_model_row(eti, eti->rows - 1)) - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) + 1, 0); - else - return_val = FALSE; - } - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col >= 0 && cursor_row >= 0 && return_val && - (!eti_editing(eti)) && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, model_to_view_col(eti, cursor_col), model_to_view_row(eti, cursor_row)); - } - break; - } else { - /* Let tab send you to the next widget. */ - return_val = FALSE; - break; - } - - case GDK_Return: - case GDK_KP_Enter: - case GDK_ISO_Enter: - case GDK_3270_Enter: - if (eti_editing (eti)){ - e_table_item_leave_edit (eti); -#if 0 - ecell_view = eti->cell_views [eti->editing_col]; - return_val = eti_e_cell_event (eti, ecell_view, e, e->key.time, - view_to_model_col(eti, eti->editing_col), - eti->editing_col, eti->editing_row, E_CELL_EDITING); -#endif - } - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [KEY_PRESS], - model_to_view_row(eti, cursor_row), cursor_col, e, &return_val); - if (!return_val) - return_val = e_table_selection_model_key_press(eti->selection, (GdkEventKey *) e); - break; - - default: - handled = FALSE; - break; - } - if (!handled) { - if (!eti_editing (eti)){ - gint col, row; - row = model_to_view_row(eti, cursor_row); - col = model_to_view_col(eti, cursor_col); - if (col != -1 && row != -1 && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, col, row); - } - } - if (!eti_editing (eti)){ - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [KEY_PRESS], - model_to_view_row(eti, cursor_row), cursor_col, e, &return_val); - if (!return_val) - e_table_selection_model_key_press(eti->selection, (GdkEventKey *) e); - } else { - ecell_view = eti->cell_views [eti->editing_col]; - return_val = eti_e_cell_event (eti, ecell_view, e, e->key.time, - view_to_model_col(eti, eti->editing_col), - eti->editing_col, eti->editing_row, E_CELL_EDITING); - if (!return_val) - e_table_selection_model_key_press(eti->selection, (GdkEventKey *) e); - } - } - eti->in_key_press = FALSE; - break; - } - - case GDK_KEY_RELEASE: { - gint cursor_row, cursor_col; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col == -1) - return FALSE; - - if (eti_editing (eti)){ - ecell_view = eti->cell_views [eti->editing_col]; - return_val = eti_e_cell_event (eti, ecell_view, e, e->key.time, - view_to_model_col(eti, eti->editing_col), - eti->editing_col, eti->editing_row, E_CELL_EDITING); - } - break; - } - - case GDK_LEAVE_NOTIFY: - case GDK_ENTER_NOTIFY: - if (eti->tooltip->timer > 0) - gtk_timeout_remove (eti->tooltip->timer); - eti->tooltip->timer = 0; - break; - - case GDK_FOCUS_CHANGE: - if (! e->focus_change.in) { - if (eti_editing (eti)) - e_table_item_leave_edit (eti); - } - - default: - return_val = FALSE; - } - return return_val; -} - -static void -eti_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableItemClass *eti_class = (ETableItemClass *) object_class; - - eti_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = eti_destroy; - object_class->set_arg = eti_set_arg; - object_class->get_arg = eti_get_arg; - - item_class->update = eti_update; - item_class->realize = eti_realize; - item_class->unrealize = eti_unrealize; - item_class->draw = eti_draw; - item_class->point = eti_point; - item_class->event = eti_event; - - eti_class->cursor_change = NULL; - eti_class->cursor_activated = NULL; - eti_class->double_click = NULL; - eti_class->right_click = NULL; - eti_class->click = NULL; - eti_class->key_press = NULL; - - gtk_object_add_arg_type ("ETableItem::ETableHeader", E_TABLE_HEADER_TYPE, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableItem::ETableModel", E_TABLE_MODEL_TYPE, - GTK_ARG_WRITABLE, ARG_TABLE_MODEL); - gtk_object_add_arg_type ("ETableItem::table_selection_model", E_TABLE_SELECTION_MODEL_TYPE, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - gtk_object_add_arg_type ("ETableItem::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableItem::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableItem::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableItem::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - - gtk_object_add_arg_type ("ETableItem::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); - gtk_object_add_arg_type ("ETableItem::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableItem::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableItem::cursor_row", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_ROW); - - eti_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - eti_signals [CURSOR_ACTIVATED] = - gtk_signal_new ("cursor_activated", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, cursor_activated), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - eti_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, double_click), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - eti_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - eti_signals [CLICK] = - gtk_signal_new ("click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - eti_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, eti_signals, LAST_SIGNAL); - -} - -GtkType -e_table_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableItem", - sizeof (ETableItem), - sizeof (ETableItemClass), - (GtkClassInitFunc) eti_class_init, - (GtkObjectInitFunc) eti_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - -/** - * e_table_item_set_cursor: - * @eti: %ETableItem which will have the cursor set. - * @col: Column to select. -1 means the last column. - * @row: Row to select. -1 means the last row. - * - * This routine sets the cursor of the %ETableItem canvas item. - */ -void -e_table_item_set_cursor (ETableItem *eti, int col, int row) -{ - e_table_item_focus(eti, col, view_to_model_row(eti, row), 0); -} - -static void -e_table_item_focus (ETableItem *eti, int col, int row, GdkModifierType state) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (row == -1) { - row = view_to_model_row(eti, eti->rows - 1); - } - - if (col == -1) { - col = eti->cols - 1; - } - - if (row != -1) { - e_table_selection_model_do_something(eti->selection, - row, col, - state); - } -} - -/** - * e_table_item_get_focused_column: - * @eti: %ETableItem which will have the cursor retrieved. - * - * This routine gets the cursor of the %ETableItem canvas item. - * - * Returns: The current cursor column. - */ -gint -e_table_item_get_focused_column (ETableItem *eti) -{ - int cursor_col; - - g_return_val_if_fail (eti != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), -1); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - NULL); - - return cursor_col; -} - -static void -eti_cursor_change (ETableSelectionModel *selection, int row, int col, ETableItem *eti) -{ - int view_row = model_to_view_row(eti, row); - int view_col = model_to_view_col(eti, col); - - if (view_row == -1 || view_col == -1) { - e_table_item_leave_edit (eti); - return; - } - - if (!eti->in_key_press) { - eti_request_region_show (eti, view_col, view_row, view_col, view_row, DOUBLE_CLICK_TIME + 10); - } else { - eti_request_region_show (eti, view_col, view_row, view_col, view_row, 0); - } - - e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(eti)); - if (eti_editing(eti)) - e_table_item_leave_edit (eti); - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CURSOR_CHANGE], - view_row); - eti->needs_redraw = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(eti)); -} - -static void -eti_cursor_activated (ETableSelectionModel *selection, int row, int col, ETableItem *eti) -{ - int view_row = model_to_view_row(eti, row); - int view_col = model_to_view_col(eti, col); - - if (view_row == -1 || view_col == -1) { - e_table_item_leave_edit (eti); - return; - } - - if (eti_editing(eti)) - e_table_item_leave_edit (eti); - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CURSOR_ACTIVATED], - view_row); -} - -static void -eti_selection_change (ETableSelectionModel *selection, ETableItem *eti) -{ - eti->needs_redraw = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(eti)); -} - - -/** - * e_table_item_enter_edit - * @eti: %ETableItem which will start being edited - * @col: The view col to edit. - * @row: The view row to edit. - * - * This routine starts the given %ETableItem editing at the given view - * column and row. - */ -void -e_table_item_enter_edit (ETableItem *eti, int col, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (eti_editing (eti)) - e_table_item_leave_edit(eti); - - eti->editing_col = col; - eti->editing_row = row; - - eti->edit_ctx = e_cell_enter_edit (eti->cell_views [col], view_to_model_col(eti, col), col, row); -} - -/** - * e_table_item_leave_edit - * @eti: %ETableItem which will stop being edited - * - * This routine stops the given %ETableItem from editing. - */ -void -e_table_item_leave_edit (ETableItem *eti) -{ - int col, row; - void *edit_ctx; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (!eti_editing (eti)) - return; - - col = eti->editing_col; - row = eti->editing_row; - edit_ctx = eti->edit_ctx; - - eti->editing_col = -1; - eti->editing_row = -1; - eti->edit_ctx = NULL; - - e_cell_leave_edit (eti->cell_views [col], - view_to_model_col(eti, col), - col, row, edit_ctx); -} - -/** - * e_table_item_compute_location - * @eti: %ETableItem to look in. - * @x: A pointer to the x location to find in the %ETableItem. - * @y: A pointer to the y location to find in the %ETableItem. - * @row: A pointer to the location to store the found row in. - * @col: A pointer to the location to store the found col in. - * - * This routine locates the pixel location (*x, *y) in the - * %ETableItem. If that location is in the %ETableItem, *row and *col - * are set to the view row and column where it was found. If that - * location is not in the %ETableItem, the height of the %ETableItem - * is removed from the value y points to. - */ -void -e_table_item_compute_location (ETableItem *eti, - int *x, - int *y, - int *row, - int *col) -{ - /* Save the grabbed row but make sure that we don't get flawed - results because the cursor is grabbed. */ - int grabbed_row = eti->grabbed_row; - eti->grabbed_row = -1; - - if (!find_cell (eti, *x, *y, col, row, NULL, NULL)) { - *y -= eti_get_height(eti); - } - - eti->grabbed_row = grabbed_row; -} - -typedef struct { - ETableItem *item; - int rows_printed; -} ETableItemPrintContext; - -static gdouble * -e_table_item_calculate_print_widths (ETableHeader *eth, gdouble width) -{ - int i; - double extra; - double expansion; - int last_resizable = -1; - gdouble scale = 300.0L / 70.0L; - gdouble *widths = g_new(gdouble, e_table_header_count(eth)); - /* - 1 to account for the last pixel border. */ - extra = width - 1; - expansion = 0; - for (i = 0; i < eth->col_count; i++) { - extra -= eth->columns[i]->min_width * scale; - if (eth->columns[i]->resizeable && eth->columns[i]->expansion > 0) - last_resizable = i; - expansion += eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0; - widths[i] = eth->columns[i]->min_width * scale; - } - for (i = 0; i <= last_resizable; i++) { - widths[i] += extra * (eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0)/expansion; - } - - return widths; -} - -static gdouble -eti_printed_row_height (ETableItem *eti, gdouble *widths, GnomePrintContext *context, gint row) -{ - int col; - int cols = eti->cols; - gdouble height = 0; - for (col = 0; col < cols; col++) { - ECellView *ecell_view = eti->cell_views [col]; - gdouble this_height = e_cell_print_height (ecell_view, context, view_to_model_col(eti, col), col, row, - widths[col] - 1); - if (this_height > height) - height = this_height; - } - return height; -} - -#define CHECK(x) if((x) == -1) return -1; - -static gint -gp_draw_rect (GnomePrintContext *context, gdouble x, gdouble y, gdouble width, gdouble height) -{ - CHECK(gnome_print_moveto(context, x, y)); - CHECK(gnome_print_lineto(context, x + width, y)); - CHECK(gnome_print_lineto(context, x + width, y - height)); - CHECK(gnome_print_lineto(context, x, y - height)); - CHECK(gnome_print_lineto(context, x, y)); - return gnome_print_fill(context); -} - -static void -e_table_item_print_page (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *eti = itemcontext->item; - const int rows = eti->rows; - const int cols = eti->cols; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row, col; - gdouble yd = height; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - if (eti->draw_grid){ - gp_draw_rect(context, 0, yd, width, 1); - } - yd--; - - for (row = rows_printed; row < rows; row++){ - gdouble xd = 1, row_height; - - row_height = eti_printed_row_height(eti, widths, context, row); - if (quantize) { - if (yd - row_height - 1 < 0 && row != rows_printed) { - break; - } - } else { - if (yd < 0) { - break; - } - } - - for (col = 0; col < cols; col++){ - ECellView *ecell_view = eti->cell_views [col]; - - if (gnome_print_gsave(context) == -1) - /* FIXME */; - if (gnome_print_translate(context, xd, yd - row_height) == -1) - /* FIXME */; - - if (gnome_print_moveto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, widths[col] - 1, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, widths[col] - 1, row_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, row_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - - e_cell_print (ecell_view, context, view_to_model_col(eti, col), col, row, - widths[col] - 1, row_height); - - if (gnome_print_grestore(context) == -1) - /* FIXME */; - - xd += widths[col]; - } - yd -= row_height; - - if (eti->draw_grid){ - gp_draw_rect(context, 0, yd, width, 1); - } - yd--; - } - - itemcontext->rows_printed = row; - - if (eti->draw_grid){ - gdouble xd = 0; - - for (col = 0; col < cols; col++){ - gp_draw_rect(context, xd, height, 1, height - yd); - - xd += widths[col]; - } - gp_draw_rect(context, xd, height, 1, height - yd); - } - - g_free (widths); -} - -static gboolean -e_table_item_data_left (EPrintable *ep, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - int rows_printed = itemcontext->rows_printed; - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "data_left"); - return rows_printed < item->rows; -} - -static void -e_table_item_reset (EPrintable *ep, - ETableItemPrintContext *itemcontext) -{ - itemcontext->rows_printed = 0; -} - -static gdouble -e_table_item_height (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - const int rows = item->rows; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row; - gdouble yd = 0; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - yd++; - - for (row = rows_printed; row < rows; row++){ - gdouble row_height; - - row_height = eti_printed_row_height(item, widths, context, row); - if (quantize) { - if (max_height != -1 && yd + row_height + 1 > max_height && row != rows_printed) { - break; - } - } else { - if (max_height != -1 && yd > max_height) { - break; - } - } - - yd += row_height; - - yd++; - } - - g_free (widths); - - if (max_height != -1 && (!quantize) && yd > max_height) - yd = max_height; - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return yd; -} - -static gboolean -e_table_item_will_fit (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - const int rows = item->rows; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row; - gdouble yd = 0; - gboolean ret_val = TRUE; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - yd++; - - for (row = rows_printed; row < rows; row++){ - gdouble row_height; - - row_height = eti_printed_row_height(item, widths, context, row); - if (quantize) { - if (max_height != -1 && yd + row_height + 1 > max_height && row != rows_printed) { - ret_val = FALSE; - break; - } - } else { - if (max_height != -1 && yd > max_height) { - ret_val = FALSE; - break; - } - } - - yd += row_height; - - yd++; - } - - g_free (widths); - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return ret_val; -} - -static void -e_table_item_printable_destroy (GtkObject *object, - ETableItemPrintContext *itemcontext) -{ - gtk_object_unref(GTK_OBJECT(itemcontext->item)); - g_free(itemcontext); -} - -/** - * e_table_item_get_printable - * @eti: %ETableItem which will be printed - * - * This routine creates and returns an %EPrintable that can be used to - * print the given %ETableItem. - * - * Returns: The %EPrintable. - */ -EPrintable * -e_table_item_get_printable (ETableItem *item) -{ - EPrintable *printable = e_printable_new(); - ETableItemPrintContext *itemcontext; - - itemcontext = g_new(ETableItemPrintContext, 1); - itemcontext->item = item; - gtk_object_ref(GTK_OBJECT(item)); - itemcontext->rows_printed = 0; - - gtk_signal_connect (GTK_OBJECT(printable), - "print_page", - GTK_SIGNAL_FUNC(e_table_item_print_page), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "data_left", - GTK_SIGNAL_FUNC(e_table_item_data_left), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "reset", - GTK_SIGNAL_FUNC(e_table_item_reset), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "height", - GTK_SIGNAL_FUNC(e_table_item_height), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "will_fit", - GTK_SIGNAL_FUNC(e_table_item_will_fit), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "destroy", - GTK_SIGNAL_FUNC(e_table_item_printable_destroy), - itemcontext); - - return printable; -} diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h deleted file mode 100644 index 50a5849313..0000000000 --- a/widgets/table/e-table-item.h +++ /dev/null @@ -1,146 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_ITEM_H_ -#define _E_TABLE_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-header.h> -#include <gal/e-table/e-table-selection-model.h> -#include <gal/e-table/e-table-defines.h> -#include <gal/e-table/e-table-tooltip.h> -#include <gal/widgets/e-printable.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_ITEM_TYPE (e_table_item_get_type ()) -#define E_TABLE_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_ITEM_TYPE, ETableItem)) -#define E_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_ITEM_TYPE, ETableItemClass)) -#define E_IS_TABLE_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_ITEM_TYPE)) -#define E_IS_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableModel *table_model; - ETableHeader *header; - - ETableModel *source_model; - ETableSelectionModel *selection; - - int x1, y1; - int minimum_width, width, height; - - int cols, rows; - - /* - * Ids for the signals we connect to - */ - int header_dim_change_id; - int header_structure_change_id; - int header_request_width_id; - int table_model_pre_change_id; - int table_model_change_id; - int table_model_row_change_id; - int table_model_cell_change_id; - int table_model_row_inserted_id; - int table_model_row_deleted_id; - - int selection_change_id; - int cursor_change_id; - int cursor_activated_id; - - GdkGC *fill_gc; - GdkGC *grid_gc; - GdkGC *focus_gc; - GdkBitmap *stipple; - - guint draw_grid:1; - guint draw_focus:1; - guint renderers_can_change_size:1; - guint cell_views_realized:1; - - guint needs_redraw : 1; - guint needs_compute_height : 1; - guint needs_compute_width : 1; - - guint uses_source_model : 1; - - guint in_key_press : 1; - - /* - * Realized views, per column - */ - ECellView **cell_views; - int n_cells; - - int *height_cache; - int height_cache_idle_id; - int height_cache_idle_count; - - /* - * Lengh Threshold: above this, we stop computing correctly - * the size - */ - int length_threshold; - - gint row_guess; - ETableCursorMode cursor_mode; - - /* - * During editing - */ - int editing_col, editing_row; - void *edit_ctx; - - int grabbed_col, grabbed_row; - - /* - * Tooltip - */ - ETableTooltip *tooltip; - -} ETableItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - void (*cursor_change) (ETableItem *eti, int row); - void (*cursor_activated) (ETableItem *eti, int row); - void (*double_click) (ETableItem *eti, int row); - gint (*right_click) (ETableItem *eti, int row, int col, GdkEvent *event); - gint (*click) (ETableItem *eti, int row, int col, GdkEvent *event); - gint (*key_press) (ETableItem *eti, int row, int col, GdkEvent *event); -} ETableItemClass; -GtkType e_table_item_get_type (void); - - -/* - * Focus - */ -void e_table_item_set_cursor (ETableItem *eti, - int col, - int row); - -gint e_table_item_get_focused_column (ETableItem *eti); - -void e_table_item_leave_edit (ETableItem *eti); -void e_table_item_enter_edit (ETableItem *eti, - int col, - int row); - -void e_table_item_redraw_range (ETableItem *eti, - int start_col, - int start_row, - int end_col, - int end_row); - -EPrintable *e_table_item_get_printable (ETableItem *eti); -void e_table_item_compute_location (ETableItem *eti, - int *x, - int *y, - int *row, - int *col); - - -END_GNOME_DECLS - -#endif /* _E_TABLE_ITEM_H_ */ diff --git a/widgets/table/e-table-model.c b/widgets/table/e-table-model.c deleted file mode 100644 index 41a55d1a8f..0000000000 --- a/widgets/table/e-table-model.c +++ /dev/null @@ -1,492 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a Table Model - * - * Authors: - * Miguel de Icaza (miguel@gnu.org) - * Chris Lahey (clahey@ximian.com) - * - * (C) 1999, 2000 Ximian, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-model.h" - -#define ETM_CLASS(e) ((ETableModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - -#define d(x) - -d(static gint depth = 0); - - -static GtkObjectClass *e_table_model_parent_class; - -enum { - MODEL_CHANGED, - MODEL_PRE_CHANGE, - MODEL_ROW_CHANGED, - MODEL_CELL_CHANGED, - MODEL_ROW_INSERTED, - MODEL_ROW_DELETED, - ROW_SELECTION, - LAST_SIGNAL -}; - -static guint e_table_model_signals [LAST_SIGNAL] = { 0, }; - -/** - * e_table_model_column_count: - * @e_table_model: The e-table-model to operate on - * - * Returns: the number of columns in the table model. - */ -int -e_table_model_column_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->column_count (e_table_model); -} - - -/** - * e_table_model_row_count: - * @e_table_model: the e-table-model to operate on - * - * Returns: the number of rows in the Table model. - */ -int -e_table_model_row_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->row_count (e_table_model); -} - -/** - * e_table_value_at: - * @e_table_model: the e-table-model to operate on - * @col: column in the model to pull data from. - * @row: row in the model to pull data from. - * - * Return value: This function returns the value that is stored - * by the @e_table_model in column @col and row @row. The data - * returned can be a pointer or any data value that can be stored - * inside a pointer. - * - * The data returned is typically used by an ECell renderer - */ -void * -e_table_model_value_at (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - return ETM_CLASS (e_table_model)->value_at (e_table_model, col, row); -} - -/** - * e_table_model_set_value_at: - * @e_table_model: the table model to operate on. - * @col: the column where the data will be stored in the model. - * @row: the row where the data will be stored in the model. - * @value: the data to be stored. - * - * This function instructs the model to store the value in @data in the - * the @e_table_model at column @col and row @row. The @data typically - * comes from one of the ECell rendering objects. - * - * There should be an agreement between the Table Model and the user - * of this function about the data being stored. Typically it will - * be a pointer to a set of data, or a datum that fits inside a void *. - */ -void -e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *value) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - ETM_CLASS (e_table_model)->set_value_at (e_table_model, col, row, value); -} - -/** - * e_table_model_is_cell_editable: - * @e_table_model: the table model to query. - * @col: column to query. - * @row: row to query. - * - * Returns: %TRUE if the cell in @e_table_model at @col,@row can be - * edited, %FALSE otherwise - */ -gboolean -e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - return ETM_CLASS (e_table_model)->is_cell_editable (e_table_model, col, row); -} - -/** - * e_table_model_append_row: - * @e_table_model: the table model to append the a row to. - * @source: - * @row: - * - */ -void -e_table_model_append_row (ETableModel *e_table_model, ETableModel *source, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_CLASS (e_table_model)->append_row) - ETM_CLASS (e_table_model)->append_row (e_table_model, source, row); -} - -const char * -e_table_model_row_sort_group(ETableModel *e_table_model, int row) -{ - g_return_val_if_fail (e_table_model != NULL, "/"); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), "/"); - - if (ETM_CLASS (e_table_model)->row_sort_group) - return ETM_CLASS (e_table_model)->row_sort_group (e_table_model, row); - else - return "/"; -} - -gboolean -e_table_model_has_sort_group(ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - if (ETM_CLASS (e_table_model)->has_sort_group) - return ETM_CLASS (e_table_model)->has_sort_group (e_table_model); - else - return FALSE; -} - -void * -e_table_model_duplicate_value (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->duplicate_value) - return ETM_CLASS (e_table_model)->duplicate_value (e_table_model, col, value); - else - return NULL; -} - -void -e_table_model_free_value (ETableModel *e_table_model, int col, void *value) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_CLASS (e_table_model)->free_value) - ETM_CLASS (e_table_model)->free_value (e_table_model, col, value); -} - -void * -e_table_model_initialize_value (ETableModel *e_table_model, int col) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->initialize_value) - return ETM_CLASS (e_table_model)->initialize_value (e_table_model, col); - else - return NULL; -} - -gboolean -e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - if (ETM_CLASS (e_table_model)->value_is_empty) - return ETM_CLASS (e_table_model)->value_is_empty (e_table_model, col, value); - else - return FALSE; -} - -char * -e_table_model_value_to_string (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->value_to_string) - return ETM_CLASS (e_table_model)->value_to_string (e_table_model, col, value); - else - return g_strdup(""); -} - -static void -e_table_model_destroy (GtkObject *object) -{ - if (e_table_model_parent_class->destroy) - (*e_table_model_parent_class->destroy)(object); -} - -static void -e_table_model_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *klass = E_TABLE_MODEL_CLASS(object_class); - e_table_model_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = e_table_model_destroy; - - e_table_model_signals [MODEL_CHANGED] = - gtk_signal_new ("model_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_model_signals [MODEL_PRE_CHANGE] = - gtk_signal_new ("model_pre_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_pre_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_model_signals [MODEL_ROW_CHANGED] = - gtk_signal_new ("model_row_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_changed), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - e_table_model_signals [MODEL_CELL_CHANGED] = - gtk_signal_new ("model_cell_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_cell_changed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - e_table_model_signals [MODEL_ROW_INSERTED] = - gtk_signal_new ("model_row_inserted", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_inserted), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - e_table_model_signals [MODEL_ROW_DELETED] = - gtk_signal_new ("model_row_deleted", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_deleted), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_table_model_signals, LAST_SIGNAL); - - klass->column_count = NULL; - klass->row_count = NULL; - klass->value_at = NULL; - klass->set_value_at = NULL; - klass->is_cell_editable = NULL; - klass->append_row = NULL; - - klass->row_sort_group = NULL; - klass->has_sort_group = NULL; - - klass->duplicate_value = NULL; - klass->free_value = NULL; - klass->initialize_value = NULL; - klass->value_is_empty = NULL; - klass->value_to_string = NULL; - klass->model_changed = NULL; - klass->model_row_changed = NULL; - klass->model_cell_changed = NULL; - klass->model_row_inserted = NULL; - klass->model_row_deleted = NULL; -} - - -guint -e_table_model_get_type (void) -{ - static guint type = 0; - - if (!type) - { - GtkTypeInfo info = - { - "ETableModel", - sizeof (ETableModel), - sizeof (ETableModelClass), - (GtkClassInitFunc) e_table_model_class_init, - NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -#if d(!)0 -static void -print_tabs (void) -{ - int i; - for (i = 0; i < depth; i++) - g_print("\t"); -} -#endif - -void -e_table_model_pre_change (ETableModel *e_table_model) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting pre_change on model 0x%p.\n", e_table_model)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_PRE_CHANGE]); - d(depth--); -} - -/** - * e_table_model_changed: - * @e_table_model: the table model to notify of the change - * - * Use this function to notify any views of this table model that - * the contents of the table model have changed. This will emit - * the signal "model_changed" on the @e_table_model object. - * - * It is preferable to use the e_table_model_row_changed() and - * the e_table_model_cell_changed() to notify of smaller changes - * than to invalidate the entire model, as the views might have - * ways of caching the information they render from the model. - */ -void -e_table_model_changed (ETableModel *e_table_model) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting model_changed on model 0x%p.\n", e_table_model)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CHANGED]); - d(depth--); -} - -/** - * e_table_model_row_changed: - * @e_table_model: the table model to notify of the change - * @row: the row that was changed in the model. - * - * Use this function to notify any views of the table model that - * the contents of row @row have changed in model. This function - * will emit the "model_row_changed" signal on the @e_table_model - * object - */ -void -e_table_model_row_changed (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_changed on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_CHANGED], row); - d(depth--); -} - -/** - * e_table_model_cell_changed: - * @e_table_model: the table model to notify of the change - * @col: the column. - * @row: the row - * - * Use this function to notify any views of the table model that - * contents of the cell at @col,@row has changed. This will emit - * the "model_cell_changed" signal on the @e_table_model - * object - */ -void -e_table_model_cell_changed (ETableModel *e_table_model, int col, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting cell_changed on model 0x%p, row %d, col %d.\n", e_table_model, row, col)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CELL_CHANGED], col, row); - d(depth--); -} - -/** - * e_table_model_row_inserted: - * @e_table_model: the table model to notify of the change - * @row: the row that was inserted into the model. - * - * Use this function to notify any views of the table model that - * the row @row has been inserted into the model. This function - * will emit the "model_row_inserted" signal on the @e_table_model - * object - */ -void -e_table_model_row_inserted (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_inserted on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_INSERTED], row); - d(depth--); -} - -/** - * e_table_model_row_deleted: - * @e_table_model: the table model to notify of the change - * @row: the row that was deleted - * - * Use this function to notify any views of the table model that - * the row @row has been deleted from the model. This function - * will emit the "model_row_deleted" signal on the @e_table_model - * object - */ -void -e_table_model_row_deleted (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_deleted on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_DELETED], row); - d(depth--); -} diff --git a/widgets/table/e-table-model.h b/widgets/table/e-table-model.h deleted file mode 100644 index 21febaf992..0000000000 --- a/widgets/table/e-table-model.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_MODEL_H_ -#define _E_TABLE_MODEL_H_ - -#include <gtk/gtkobject.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_MODEL_TYPE (e_table_model_get_type ()) -#define E_TABLE_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_MODEL_TYPE, ETableModel)) -#define E_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_MODEL_TYPE, ETableModelClass)) -#define E_IS_TABLE_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_MODEL_TYPE)) -#define E_IS_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_MODEL_TYPE)) - -typedef struct { - GtkObject base; -} ETableModel; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Virtual methods - */ - int (*column_count) (ETableModel *etm); - int (*row_count) (ETableModel *etm); - void *(*value_at) (ETableModel *etm, int col, int row); - void (*set_value_at) (ETableModel *etm, int col, int row, const void *value); - gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - void (*append_row) (ETableModel *etm, ETableModel *source, int row); - - /* the sort group id for this row */ - const char *(*row_sort_group) (ETableModel *etm, int row); - gboolean (*has_sort_group) (ETableModel *etm); - - /* Allocate a copy of the given value. */ - void *(*duplicate_value) (ETableModel *etm, int col, const void *value); - /* Free an allocated value. */ - void (*free_value) (ETableModel *etm, int col, void *value); - /* Return an allocated empty value. */ - void *(*initialize_value) (ETableModel *etm, int col); - /* Return TRUE if value is equivalent to an empty cell. */ - gboolean (*value_is_empty) (ETableModel *etm, int col, const void *value); - /* Return an allocated string. */ - char *(*value_to_string) (ETableModel *etm, int col, const void *value); - - /* - * Signals - */ - - /* - * These all come after the change has been made. - * Major structural changes: model_changed - * Changes only in a row: row_changed - * Only changes in a cell: cell_changed - * A row inserted: row_inserted - * A row deleted: row_deleted - */ - void (*model_pre_change) (ETableModel *etm); - - void (*model_changed) (ETableModel *etm); - void (*model_row_changed) (ETableModel *etm, int row); - void (*model_cell_changed) (ETableModel *etm, int col, int row); - void (*model_row_inserted) (ETableModel *etm, int row); - void (*model_row_deleted) (ETableModel *etm, int row); -} ETableModelClass; - -GtkType e_table_model_get_type (void); - -int e_table_model_column_count (ETableModel *e_table_model); -const char *e_table_model_column_name (ETableModel *e_table_model, int col); -int e_table_model_row_count (ETableModel *e_table_model); -void *e_table_model_value_at (ETableModel *e_table_model, int col, int row); -void e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *value); -gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row); -void e_table_model_append_row (ETableModel *e_table_model, ETableModel *source, int row); - -const char *e_table_model_row_sort_group (ETableModel *e_table_model, int row); -gboolean e_table_model_has_sort_group (ETableModel *e_table_model); - -void *e_table_model_duplicate_value (ETableModel *e_table_model, int col, const void *value); -void e_table_model_free_value (ETableModel *e_table_model, int col, void *value); -void *e_table_model_initialize_value (ETableModel *e_table_model, int col); -gboolean e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value); -char *e_table_model_value_to_string (ETableModel *e_table_model, int col, const void *value); - -/* - * Routines for emitting signals on the e_table - */ -void e_table_model_pre_change (ETableModel *e_table_model); -void e_table_model_changed (ETableModel *e_table_model); -void e_table_model_row_changed (ETableModel *e_table_model, int row); -void e_table_model_cell_changed (ETableModel *e_table_model, int col, int row); -void e_table_model_row_inserted (ETableModel *e_table_model, int row); -void e_table_model_row_deleted (ETableModel *e_table_model, int row); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_MODEL_H_ */ diff --git a/widgets/table/e-table-one.c b/widgets/table/e-table-one.c deleted file mode 100644 index 524005cd6e..0000000000 --- a/widgets/table/e-table-one.c +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a one table model implementation that uses function - * pointers to simplify the creation of new, exotic and colorful tables in - * no time. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc. - */ - -#include <config.h> -#include "e-table-one.h" - -#define PARENT_TYPE e_table_model_get_type () - -static int -one_column_count (ETableModel *etm) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_column_count(one->source); - else - return 0; -} - -static int -one_row_count (ETableModel *etm) -{ - return 1; -} - -static void * -one_value_at (ETableModel *etm, int col, int row) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->data) - return one->data[col]; - else - return NULL; -} - -static void -one_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->data && one->source) { - e_table_model_free_value(one->source, col, one->data[col]); - one->data[col] = e_table_model_duplicate_value(one->source, col, val); - } -} - -static gboolean -one_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_is_cell_editable(one->source, 0, row); - else - return FALSE; -} - -/* The default for one_duplicate_value is to return the raw value. */ -static void * -one_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_duplicate_value(one->source, col, value); - else - return (void *)value; -} - -static void -one_free_value (ETableModel *etm, int col, void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - e_table_model_free_value(one->source, col, value); -} - -static void * -one_initialize_value (ETableModel *etm, int col) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_initialize_value (one->source, col); - else - return NULL; -} - -static gboolean -one_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_value_is_empty (one->source, col, value); - else - return FALSE; -} - -static char * -one_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_value_to_string (one->source, col, value); - else - return g_strdup(""); -} - -static void -one_destroy (GtkObject *object) -{ - ETableOne *one = E_TABLE_ONE(object); - - if (one->source) { - int i; - int col_count; - - col_count = e_table_model_column_count(one->source); - - if (one->data) { - for (i = 0; i < col_count; i++) { - e_table_model_free_value(one->source, i, one->data[i]); - } - } - - gtk_object_unref(GTK_OBJECT(one->source)); - } - - g_free(one->data); -} - -static void -e_table_one_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *model_class = (ETableModelClass *) object_class; - - model_class->column_count = one_column_count; - model_class->row_count = one_row_count; - model_class->value_at = one_value_at; - model_class->set_value_at = one_set_value_at; - model_class->is_cell_editable = one_is_cell_editable; - model_class->duplicate_value = one_duplicate_value; - model_class->free_value = one_free_value; - model_class->initialize_value = one_initialize_value; - model_class->value_is_empty = one_value_is_empty; - model_class->value_to_string = one_value_to_string; - - object_class->destroy = one_destroy; -} - -static void -e_table_one_init (GtkObject *object) -{ - ETableOne *one = E_TABLE_ONE(object); - - one->source = NULL; - one->data = NULL; -} - -GtkType -e_table_one_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableOne", - sizeof (ETableOne), - sizeof (ETableOneClass), - (GtkClassInitFunc) e_table_one_class_init, - (GtkObjectInitFunc) e_table_one_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -ETableModel * -e_table_one_new (ETableModel *source) -{ - ETableOne *eto; - int col_count; - int i; - - eto = gtk_type_new (e_table_one_get_type ()); - - eto->source = source; - - col_count = e_table_model_column_count(source); - eto->data = g_new(void *, col_count); - for (i = 0; i < col_count; i++) { - eto->data[i] = e_table_model_initialize_value(source, i); - } - - if (source) - gtk_object_ref(GTK_OBJECT(source)); - - return (ETableModel *) eto; -} - -void -e_table_one_commit (ETableOne *one) -{ - if (one->source) { - int empty = TRUE; - int col; - int cols = e_table_model_column_count(one->source); - for (col = 0; col < cols; col++) { - if (!e_table_model_value_is_empty(one->source, col, one->data[col])) { - empty = FALSE; - break; - } - } - if (!empty) { - e_table_model_append_row(one->source, E_TABLE_MODEL(one), 0); - } - } -} diff --git a/widgets/table/e-table-one.h b/widgets/table/e-table-one.h deleted file mode 100644 index 2636f018ab..0000000000 --- a/widgets/table/e-table-one.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_ONE_H_ -#define _E_TABLE_ONE_H_ - -#include <gal/e-table/e-table-model.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_TABLE_ONE_TYPE (e_table_one_get_type ()) -#define E_TABLE_ONE(o) (GTK_CHECK_CAST ((o), E_TABLE_ONE_TYPE, ETableOne)) -#define E_TABLE_ONE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_ONE_TYPE, ETableOneClass)) -#define E_IS_TABLE_ONE(o) (GTK_CHECK_TYPE ((o), E_TABLE_ONE_TYPE)) -#define E_IS_TABLE_ONE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_ONE_TYPE)) - -typedef struct { - ETableModel parent; - - ETableModel *source; - void **data; -} ETableOne; - -typedef struct { - ETableModelClass parent_class; -} ETableOneClass; - -GtkType e_table_one_get_type (void); - -ETableModel *e_table_one_new (ETableModel *source); -void e_table_one_commit (ETableOne *one); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_ONE_H_ */ - diff --git a/widgets/table/e-table-scrolled.c b/widgets/table/e-table-scrolled.c deleted file mode 100644 index cd816a678c..0000000000 --- a/widgets/table/e-table-scrolled.c +++ /dev/null @@ -1,208 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-scrolled.c: A graphical view of a Table. - * - * Author: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza (miguel@ximian.com) - * - * Copyright 2000, 1999, Ximian, Inc - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <stdio.h> -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> - -#include "e-table.h" -#include "e-table-scrolled.h" - -#define COLUMN_HEADER_HEIGHT 16 - -#define PARENT_TYPE e_scroll_frame_get_type () - -static GtkObjectClass *parent_class; - -enum { - ARG_0, - ARG_TABLE, -}; - -static void -e_table_scrolled_init (GtkObject *object) -{ - ETableScrolled *ets; - EScrollFrame *scroll_frame; - - ets = E_TABLE_SCROLLED (object); - scroll_frame = E_SCROLL_FRAME (object); - - GTK_WIDGET_SET_FLAGS (ets, GTK_CAN_FOCUS); - - ets->table = gtk_type_new(e_table_get_type()); - - e_scroll_frame_set_policy (scroll_frame, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - e_scroll_frame_set_shadow_type (scroll_frame, GTK_SHADOW_IN); -} - -static void -e_table_scrolled_real_construct (ETableScrolled *ets) -{ - gtk_container_add(GTK_CONTAINER(ets), GTK_WIDGET(ets->table)); - - gtk_widget_show(GTK_WIDGET(ets->table)); -} - -ETableScrolled *e_table_scrolled_construct (ETableScrolled *ets, - ETableModel *etm, - ETableExtras *ete, - const char *spec, - const char *state) -{ - g_return_val_if_fail(ets != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL); - g_return_val_if_fail(etm != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL); - g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL); - g_return_val_if_fail(spec != NULL, NULL); - - e_table_construct(ets->table, etm, ete, spec, state); - - e_table_scrolled_real_construct(ets); - - return ets; -} - -GtkWidget *e_table_scrolled_new (ETableModel *etm, - ETableExtras *ete, - const char *spec, - const char *state) -{ - ETableScrolled *ets; - - g_return_val_if_fail(etm != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL); - g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL); - g_return_val_if_fail(spec != NULL, NULL); - - ets = E_TABLE_SCROLLED (gtk_widget_new (e_table_scrolled_get_type (), - "hadjustment", NULL, - "vadjustment", NULL, - NULL)); - - ets = e_table_scrolled_construct (ets, etm, ete, spec, state); - - return GTK_WIDGET (ets); -} - -ETableScrolled *e_table_scrolled_construct_from_spec_file (ETableScrolled *ets, - ETableModel *etm, - ETableExtras *ete, - const char *spec_fn, - const char *state_fn) -{ - g_return_val_if_fail(ets != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL); - g_return_val_if_fail(etm != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL); - g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL); - g_return_val_if_fail(spec_fn != NULL, NULL); - - e_table_construct_from_spec_file(ets->table, etm, ete, spec_fn, state_fn); - - e_table_scrolled_real_construct(ets); - - return ets; -} - -GtkWidget *e_table_scrolled_new_from_spec_file (ETableModel *etm, - ETableExtras *ete, - const char *spec_fn, - const char *state_fn) -{ - ETableScrolled *ets; - - g_return_val_if_fail(etm != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL); - g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL); - g_return_val_if_fail(spec_fn != NULL, NULL); - - ets = gtk_type_new (e_table_scrolled_get_type ()); - - ets = e_table_scrolled_construct_from_spec_file (ets, etm, ete, spec_fn, state_fn); - - return GTK_WIDGET (ets); -} - -ETable * -e_table_scrolled_get_table (ETableScrolled *ets) -{ - return ets->table; -} - -static void -ets_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableScrolled *ets = E_TABLE_SCROLLED (o); - - switch (arg_id){ - case ARG_TABLE: - if (ets->table) - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(ets->table); - else - GTK_VALUE_OBJECT (*arg) = NULL; - break; - } -} - -/* Grab_focus handler for the scrolled ETable */ -static void -ets_grab_focus (GtkWidget *widget) -{ - ETableScrolled *ets; - - ets = E_TABLE_SCROLLED (widget); - - gtk_widget_grab_focus (GTK_WIDGET (ets->table)); -} - -/* Focus handler for the scrolled ETable */ -static gint -ets_focus (GtkContainer *container, GtkDirectionType direction) -{ - ETableScrolled *ets; - - ets = E_TABLE_SCROLLED (container); - - return gtk_container_focus (GTK_CONTAINER (ets->table), direction); -} - -static void -e_table_scrolled_class_init (ETableScrolledClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->get_arg = ets_get_arg; - - widget_class->grab_focus = ets_grab_focus; - - container_class->focus = ets_focus; - - gtk_object_add_arg_type ("ETableScrolled::table", GTK_TYPE_OBJECT, - GTK_ARG_READABLE, ARG_TABLE); -} - -E_MAKE_TYPE(e_table_scrolled, "ETableScrolled", ETableScrolled, e_table_scrolled_class_init, e_table_scrolled_init, PARENT_TYPE); - diff --git a/widgets/table/e-table-scrolled.h b/widgets/table/e-table-scrolled.h deleted file mode 100644 index 9b2d2a510e..0000000000 --- a/widgets/table/e-table-scrolled.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SCROLLED_H_ -#define _E_TABLE_SCROLLED_H_ - -#include <gal/widgets/e-scroll-frame.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-header.h> -#include <gal/e-table/e-table.h> -#include <gal/widgets/e-printable.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_SCROLLED_TYPE (e_table_scrolled_get_type ()) -#define E_TABLE_SCROLLED(o) (GTK_CHECK_CAST ((o), E_TABLE_SCROLLED_TYPE, ETableScrolled)) -#define E_TABLE_SCROLLED_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SCROLLED_TYPE, ETableScrolledClass)) -#define E_IS_TABLE_SCROLLED(o) (GTK_CHECK_TYPE ((o), E_TABLE_SCROLLED_TYPE)) -#define E_IS_TABLE_SCROLLED_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SCROLLED_TYPE)) - -typedef struct { - EScrollFrame parent; - - ETable *table; -} ETableScrolled; - -typedef struct { - EScrollFrameClass parent_class; -} ETableScrolledClass; - -GtkType e_table_scrolled_get_type (void); - -ETableScrolled *e_table_scrolled_construct (ETableScrolled *ets, - ETableModel *etm, - ETableExtras *ete, - const char *spec, - const char *state); -GtkWidget *e_table_scrolled_new (ETableModel *etm, - ETableExtras *ete, - const char *spec, - const char *state); - -ETableScrolled *e_table_scrolled_construct_from_spec_file (ETableScrolled *ets, - ETableModel *etm, - ETableExtras *ete, - const char *spec_fn, - const char *state_fn); -GtkWidget *e_table_scrolled_new_from_spec_file (ETableModel *etm, - ETableExtras *ete, - const char *spec_fn, - const char *state_fn); - -ETable *e_table_scrolled_get_table (ETableScrolled *ets); - -END_GNOME_DECLS - -#endif /* _E_TABLE_SCROLLED_H_ */ - diff --git a/widgets/table/e-table-selection-model.c b/widgets/table/e-table-selection-model.c deleted file mode 100644 index 42734bd74e..0000000000 --- a/widgets/table/e-table-selection-model.c +++ /dev/null @@ -1,873 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-selection-model.c: a Table Selection Model - * - * Author: - * Christopher James Lahey <clahey@ximian.com> - * - * (C) 2000, 2001 Ximian, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-selection-model.h" -#include "gal/util/e-util.h" -#include <gdk/gdkkeysyms.h> - -#define ETSM_CLASS(e) ((ETableSelectionModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - -#define ONES ((guint32) 0xffffffff) - -#define BOX(n) ((n) / 32) -#define OFFSET(n) (31 - ((n) % 32)) -#define BITMASK(n) ((guint32)(((guint32) 0x1) << OFFSET((n)))) -#define BITMASK_LEFT(n) ((((n) % 32) == 0) ? 0 : (ONES << (32 - ((n) % 32)))) -#define BITMASK_RIGHT(n) ((guint32)(((guint32) ONES) >> ((n) % 32))) - -static GtkObjectClass *e_table_selection_model_parent_class; - -static void etsm_select_single_row (ETableSelectionModel *selection, int row); - -enum { - CURSOR_CHANGED, - CURSOR_ACTIVATED, - SELECTION_CHANGED, - LAST_SIGNAL -}; - -static guint e_table_selection_model_signals [LAST_SIGNAL] = { 0, }; - -enum { - ARG_0, - ARG_MODEL, - ARG_SORTER, - ARG_CURSOR_ROW, - ARG_CURSOR_COL, - ARG_SELECTION_MODE, - ARG_CURSOR_MODE, -}; - -static void -model_changed(ETableModel *etm, ETableSelectionModel *etsm) -{ - e_table_selection_model_clear(etsm); -} - -#if 1 -static void -model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - int box; - int i; - if(etsm->row_count >= 0) { - /* Add another word if needed. */ - if ((etsm->row_count & 0x1f) == 0) { - etsm->selection = g_renew(gint, etsm->selection, (etsm->row_count >> 5) + 1); - etsm->selection[etsm->row_count >> 5] = 0; - } - - /* The box is the word that our row is in. */ - box = BOX(row); - /* Shift all words to the right of our box right one bit. */ - for (i = etsm->row_count >> 5; i > box; i--) { - etsm->selection[i] = (etsm->selection[i] >> 1) | (etsm->selection[i - 1] << 31); - } - - /* Shift right half of box one bit to the right. */ - etsm->selection[box] = (etsm->selection[box] & BITMASK_LEFT(row)) | ((etsm->selection[box] & BITMASK_RIGHT(row)) >> 1); - etsm->row_count ++; - } - if (etsm->cursor_row >= row) - etsm->cursor_row ++; -} - -static void -model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - int box; - int i; - int last; - int selected = FALSE; - if(etsm->row_count >= 0) { - guint32 bitmask; - box = row >> 5; - last = etsm->row_count >> 5; - - /* Build bitmasks for the left and right half of the box */ - bitmask = BITMASK_RIGHT(row) >> 1; - selected = e_table_selection_model_is_row_selected(etsm, row); - /* Shift right half of box one bit to the left. */ - etsm->selection[box] = (etsm->selection[box] & BITMASK_LEFT(row))| ((etsm->selection[box] & bitmask) << 1); - - /* Shift all words to the right of our box left one bit. */ - if (box < last) { - etsm->selection[box] &= etsm->selection[box + 1] >> 31; - - for (i = box + 1; i < last; i++) { - etsm->selection[i] = (etsm->selection[i] << 1) | (etsm->selection[i + 1] >> 31); - } - /* this over-runs our memory! */ - /*etsm->selection[i] = etsm->selection[i] << 1; */ - } - etsm->row_count --; - /* Remove the last word if not needed. */ - if ((etsm->row_count & 0x1f) == 0) { - etsm->selection = g_renew(gint, etsm->selection, etsm->row_count >> 5); - } - if (selected && etsm->mode == GTK_SELECTION_SINGLE) { - etsm_select_single_row (etsm, row > 0 ? row - 1 : 0); - } - } - if (etsm->cursor_row >= row && etsm->cursor_row > 0) - etsm->cursor_row --; -} - -#else - -static void -model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - model_changed(etm, etsm); -} - -static void -model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - model_changed(etm, etsm); -} -#endif - -inline static void -add_model(ETableSelectionModel *etsm, ETableModel *model) -{ - etsm->model = model; - if (model) { - gtk_object_ref(GTK_OBJECT(model)); - etsm->model_changed_id = gtk_signal_connect(GTK_OBJECT(model), "model_changed", - GTK_SIGNAL_FUNC(model_changed), etsm); - etsm->model_row_inserted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_inserted", - GTK_SIGNAL_FUNC(model_row_inserted), etsm); - etsm->model_row_deleted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_deleted", - GTK_SIGNAL_FUNC(model_row_deleted), etsm); - } -} - -inline static void -drop_model(ETableSelectionModel *etsm) -{ - if (etsm->model) { - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_changed_id); - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_row_inserted_id); - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_row_deleted_id); - gtk_object_unref(GTK_OBJECT(etsm->model)); - } - etsm->model = NULL; -} - -inline static void -add_sorter(ETableSelectionModel *etsm, ETableSorter *sorter) -{ - etsm->sorter = sorter; - if (sorter) { - gtk_object_ref(GTK_OBJECT(sorter)); - } -} - -inline static void -drop_sorter(ETableSelectionModel *etsm) -{ - if (etsm->sorter) { - gtk_object_unref(GTK_OBJECT(etsm->sorter)); - } - etsm->sorter = NULL; -} - -static void -etsm_destroy (GtkObject *object) -{ - ETableSelectionModel *etsm; - - etsm = E_TABLE_SELECTION_MODEL (object); - - drop_model(etsm); - drop_sorter(etsm); - - g_free(etsm->selection); -} - -static void -etsm_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (o); - - switch (arg_id){ - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etsm->model); - break; - - case ARG_SORTER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etsm->sorter); - break; - - case ARG_CURSOR_ROW: - GTK_VALUE_INT(*arg) = etsm->cursor_row; - break; - - case ARG_CURSOR_COL: - GTK_VALUE_INT(*arg) = etsm->cursor_col; - break; - - case ARG_SELECTION_MODE: - GTK_VALUE_ENUM(*arg) = etsm->mode; - break; - - case ARG_CURSOR_MODE: - GTK_VALUE_ENUM(*arg) = etsm->cursor_mode; - break; - } -} - -static void -etsm_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (o); - - switch (arg_id){ - case ARG_MODEL: - drop_model(etsm); - add_model(etsm, GTK_VALUE_OBJECT (*arg) ? E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg)) : NULL); - break; - - case ARG_SORTER: - drop_sorter(etsm); - add_sorter(etsm, GTK_VALUE_OBJECT (*arg) ? E_TABLE_SORTER(GTK_VALUE_OBJECT (*arg)) : NULL); - break; - - case ARG_CURSOR_ROW: - e_table_selection_model_do_something(etsm, GTK_VALUE_INT(*arg), etsm->cursor_col, 0); - break; - - case ARG_CURSOR_COL: - e_table_selection_model_do_something(etsm, etsm->cursor_row, GTK_VALUE_INT(*arg), 0); - break; - - case ARG_SELECTION_MODE: - etsm->mode = GTK_VALUE_ENUM(*arg); - if (etsm->mode == GTK_SELECTION_SINGLE) { - e_table_selection_model_do_something(etsm, etsm->cursor_row, etsm->cursor_col, 0); - } - break; - - case ARG_CURSOR_MODE: - etsm->cursor_mode = GTK_VALUE_ENUM(*arg); - break; - } -} - -static void -e_table_selection_model_init (ETableSelectionModel *selection) -{ - selection->selection = NULL; - selection->row_count = -1; - selection->model = NULL; - selection->selection_start_row = 0; - selection->cursor_row = -1; - selection->cursor_col = -1; - selection->mode = GTK_SELECTION_MULTIPLE; - selection->cursor_mode = E_TABLE_CURSOR_SIMPLE; -} - -static void -e_table_selection_model_class_init (ETableSelectionModelClass *klass) -{ - GtkObjectClass *object_class; - - e_table_selection_model_parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class = GTK_OBJECT_CLASS(klass); - - object_class->destroy = etsm_destroy; - object_class->get_arg = etsm_get_arg; - object_class->set_arg = etsm_set_arg; - - e_table_selection_model_signals [CURSOR_CHANGED] = - gtk_signal_new ("cursor_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSelectionModelClass, cursor_changed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - e_table_selection_model_signals [CURSOR_ACTIVATED] = - gtk_signal_new ("cursor_activated", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSelectionModelClass, cursor_activated), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - e_table_selection_model_signals [SELECTION_CHANGED] = - gtk_signal_new ("selection_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSelectionModelClass, selection_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - klass->cursor_changed = NULL; - klass->cursor_activated = NULL; - klass->selection_changed = NULL; - - gtk_object_class_add_signals (object_class, e_table_selection_model_signals, LAST_SIGNAL); - - gtk_object_add_arg_type ("ETableSelectionModel::model", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("ETableSelectionModel::sorter", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_SORTER); - gtk_object_add_arg_type ("ETableSelectionModel::cursor_row", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_ROW); - gtk_object_add_arg_type ("ETableSelectionModel::cursor_col", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_COL); - gtk_object_add_arg_type ("ETableSelectionModel::selection_mode", GTK_TYPE_ENUM, - GTK_ARG_READWRITE, ARG_SELECTION_MODE); - gtk_object_add_arg_type ("ETableSelectionModel::cursor_mode", GTK_TYPE_ENUM, - GTK_ARG_READWRITE, ARG_CURSOR_MODE); -} - -E_MAKE_TYPE(e_table_selection_model, "ETableSelectionModel", ETableSelectionModel, - e_table_selection_model_class_init, e_table_selection_model_init, PARENT_TYPE); - -/** - * e_table_selection_model_new - * - * This routine creates a new #ETableSelectionModel. - * - * Returns: The new #ETableSelectionModel. - */ -ETableSelectionModel * -e_table_selection_model_new (void) -{ - return gtk_type_new (e_table_selection_model_get_type ()); -} - -/** - * e_table_selection_model_is_row_selected - * @selection: #ETableSelectionModel to check - * @n: The row to check - * - * This routine calculates whether the given row is selected. - * - * Returns: %TRUE if the given row is selected - */ -gboolean -e_table_selection_model_is_row_selected (ETableSelectionModel *selection, - gint n) -{ - if (selection->row_count < n) - return 0; - else - return (selection->selection[BOX(n)] >> OFFSET(n)) & 0x1; -} - -/** - * e_table_selection_model_foreach - * @selection: #ETableSelectionModel to traverse - * @callback: The callback function to call back. - * @closure: The closure - * - * This routine calls the given callback function once for each - * selected row, passing closure as the closure. - */ -void -e_table_selection_model_foreach (ETableSelectionModel *selection, - ETableForeachFunc callback, - gpointer closure) -{ - int i; - int last = (selection->row_count + 31) / 32; - for (i = 0; i < last; i++) { - if (selection->selection[i]) { - int j; - guint32 value = selection->selection[i]; - for (j = 0; j < 32; j++) { - if (value & 0x80000000) { - callback(i * 32 + j, closure); - } - value <<= 1; - } - } - } -} - -#define OPERATE(object, i,mask,grow) ((grow) ? (((object)->selection[(i)]) |= ((guint32) ~(mask))) : (((object)->selection[(i)]) &= (mask))) - -static void -change_one_row(ETableSelectionModel *selection, int row, gboolean grow) -{ - int i; - i = BOX(row); - - OPERATE(selection, i, ~BITMASK(row), grow); -} - -static void -change_selection(ETableSelectionModel *selection, int start, int end, gboolean grow) -{ - int i, last; - if (start != end) { - if (selection->sorter && e_table_sorter_needs_sorting(selection->sorter)) { - for ( i = start; i < end; i++) { - change_one_row(selection, e_table_sorter_sorted_to_model(selection->sorter, i), grow); - } - } else { - i = BOX(start); - last = BOX(end); - - if (i == last) { - OPERATE(selection, i, BITMASK_LEFT(start) | BITMASK_RIGHT(end), grow); - } else { - OPERATE(selection, i, BITMASK_LEFT(start), grow); - if (grow) - for (i ++; i < last; i++) - selection->selection[i] = ONES; - else - for (i ++; i < last; i++) - selection->selection[i] = 0; - OPERATE(selection, i, BITMASK_RIGHT(end), grow); - } - } - } -} - -static void -etsm_select_single_row (ETableSelectionModel *selection, int row) -{ - int i; - for (i = 0; i < ((selection->row_count + 31) / 32); i++) { - if (!((i == BOX(row) && selection->selection[i] == BITMASK(row)) || - (i != BOX(row) && selection->selection[i] == 0))) { - g_free(selection->selection); - selection->selection = g_new0(gint, (selection->row_count + 31) / 32); - selection->selection[BOX(row)] = BITMASK(row); - - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); - break; - } - } - - selection->selection_start_row = row; -} - -static void -etsm_toggle_single_row (ETableSelectionModel *selection, int row) -{ - if (selection->selection[BOX(row)] & BITMASK(row)) - selection->selection[BOX(row)] &= ~BITMASK(row); - else - selection->selection[BOX(row)] |= BITMASK(row); - selection->selection_start_row = row; - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); -} - -static void -etsm_move_selection_end (ETableSelectionModel *selection, int row) -{ - int old_start; - int old_end; - int new_start; - int new_end; - if (selection->sorter && e_table_sorter_needs_sorting(selection->sorter)) { - old_start = MIN (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, selection->cursor_row)); - old_end = MAX (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, selection->cursor_row)) + 1; - new_start = MIN (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, row)); - new_end = MAX (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, row)) + 1; - } else { - old_start = MIN (selection->selection_start_row, selection->cursor_row); - old_end = MAX (selection->selection_start_row, selection->cursor_row) + 1; - new_start = MIN (selection->selection_start_row, row); - new_end = MAX (selection->selection_start_row, row) + 1; - } - /* This wouldn't work nearly so smoothly if one end of the selection weren't held in place. */ - if (old_start < new_start) - change_selection(selection, old_start, new_start, FALSE); - if (new_start < old_start) - change_selection(selection, new_start, old_start, TRUE); - if (old_end < new_end) - change_selection(selection, old_end, new_end, TRUE); - if (new_end < old_end) - change_selection(selection, new_end, old_end, FALSE); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); -} - -static void -etsm_set_selection_end (ETableSelectionModel *selection, int row) -{ - etsm_select_single_row(selection, selection->selection_start_row); - selection->cursor_row = selection->selection_start_row; - etsm_move_selection_end(selection, row); -} - -/** - * e_table_selection_model_do_something - * @selection: #ETableSelectionModel to do something to. - * @row: The row to do something in. - * @col: The col to do something in. - * @state: The state in which to do something. - * - * This routine does whatever is appropriate as if the user clicked - * the mouse in the given row and column. - */ -void -e_table_selection_model_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state) -{ - gint shift_p = state & GDK_SHIFT_MASK; - gint ctrl_p = state & GDK_CONTROL_MASK; - - if (row == -1 && col != -1) - row = 0; - if (col == -1 && row != -1) - col = 0; - - if (selection->row_count < 0) { - if (selection->model) { - selection->row_count = e_table_model_row_count(selection->model); - g_free(selection->selection); - selection->selection = g_new0(gint, (selection->row_count + 31) / 32); - } - } - if (selection->row_count >= 0 && row < selection->row_count) { - switch (selection->mode) { - case GTK_SELECTION_SINGLE: - etsm_select_single_row (selection, row); - break; - case GTK_SELECTION_BROWSE: - case GTK_SELECTION_MULTIPLE: - case GTK_SELECTION_EXTENDED: - if (shift_p) { - etsm_set_selection_end (selection, row); - } else { - if (ctrl_p) { - etsm_toggle_single_row (selection, row); - } else { - etsm_select_single_row (selection, row); - } - } - break; - } - if (selection->cursor_row != row || - selection->cursor_col != col) { - selection->cursor_row = row; - selection->cursor_col = col; - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_CHANGED], row, col); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_ACTIVATED], row, col); - } - } -} - -/** - * e_table_selection_model_maybe_do_something - * @selection: #ETableSelectionModel to do something to. - * @row: The row to do something in. - * @col: The col to do something in. - * @state: The state in which to do something. - * - * If this row is selected, this routine just moves the cursor row and - * column. Otherwise, it does the same thing as - * e_table_selection_model_do_something(). This is for being used on - * right clicks and other events where if the user hit the selection, - * they don't want it to change. - */ -void -e_table_selection_model_maybe_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state) -{ - if (e_table_selection_model_is_row_selected(selection, row)) { - selection->cursor_row = row; - selection->cursor_col = col; - } else { - e_table_selection_model_do_something(selection, row, col, state); - } -} - -static gint -move_selection (ETableSelectionModel *selection, - gboolean up, - GdkModifierType state) -{ - int row = selection->cursor_row; - int col = selection->cursor_col; - int cursor_activated = TRUE; - - gint shift_p = state & GDK_SHIFT_MASK; - gint ctrl_p = state & GDK_CONTROL_MASK; - - row = e_table_sorter_model_to_sorted(selection->sorter, row); - if (up) - row--; - else - row++; - if (row < 0) - row = 0; - if (row >= selection->row_count) - row = selection->row_count - 1; - row = e_table_sorter_sorted_to_model(selection->sorter, row); - - switch (selection->mode) { - case GTK_SELECTION_BROWSE: - if (shift_p) { - etsm_set_selection_end (selection, row); - } else if (!ctrl_p) { - etsm_select_single_row (selection, row); - } else - cursor_activated = FALSE; - break; - case GTK_SELECTION_SINGLE: - case GTK_SELECTION_MULTIPLE: - case GTK_SELECTION_EXTENDED: - etsm_select_single_row (selection, row); - break; - } - if (row != -1) { - selection->cursor_row = row; - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_CHANGED], row, col); - if (cursor_activated) - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_ACTIVATED], row, col); - } - return TRUE; -} - -/** - * e_table_selection_model_key_press - * @selection: #ETableSelectionModel to affect. - * @key: The event. - * - * This routine does whatever is appropriate as if the user pressed - * the given key. - * - * Returns: %TRUE if the #ETableSelectionModel used the key. - */ -gint -e_table_selection_model_key_press (ETableSelectionModel *selection, - GdkEventKey *key) -{ - switch (key->keyval) { - case GDK_Up: - return move_selection(selection, TRUE, key->state); - break; - case GDK_Down: - return move_selection(selection, FALSE, key->state); - break; - case GDK_space: - case GDK_KP_Space: - if (selection->mode != GTK_SELECTION_SINGLE) { - etsm_toggle_single_row (selection, selection->cursor_row); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_ACTIVATED], selection->cursor_row, selection->cursor_col); - return TRUE; - } - break; - case GDK_Return: - case GDK_KP_Enter: - if (selection->mode != GTK_SELECTION_SINGLE) { - etsm_select_single_row (selection, selection->cursor_row); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_ACTIVATED], selection->cursor_row, selection->cursor_col); - return TRUE; - } - break; - case GDK_Home: - case GDK_KP_Home: - if (selection->cursor_mode == E_TABLE_CURSOR_LINE) { - int row = 0; - - row = e_table_sorter_sorted_to_model(selection->sorter, row); - selection->cursor_row = row; - - etsm_select_single_row (selection, selection->cursor_row); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_CHANGED], selection->cursor_row, selection->cursor_col); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_ACTIVATED], selection->cursor_row, selection->cursor_col); - return TRUE; - } - break; - case GDK_End: - case GDK_KP_End: - if (selection->cursor_mode == E_TABLE_CURSOR_LINE) { - int row = selection->row_count - 1; - - row = e_table_sorter_sorted_to_model(selection->sorter, row); - selection->cursor_row = row; - - etsm_select_single_row (selection, selection->cursor_row); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_CHANGED], selection->cursor_row, selection->cursor_col); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_ACTIVATED], selection->cursor_row, selection->cursor_col); - return TRUE; - } - break; - } - return FALSE; -} - -/** - * e_table_selection_model_clear - * @selection: #ETableSelectionModel to clear - * - * This routine clears the selection to no rows selected. - */ -void -e_table_selection_model_clear(ETableSelectionModel *selection) -{ - g_free(selection->selection); - selection->selection = NULL; - selection->row_count = -1; - selection->cursor_row = -1; - selection->cursor_col = -1; - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [CURSOR_CHANGED], -1, -1); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); -} - -#define PART(x,n) (((x) & (0x01010101 << n)) >> n) -#define SECTION(x, n) (((x) >> (n * 8)) & 0xff) - -/** - * e_table_selection_model_selected_count - * @selection: #ETableSelectionModel to count - * - * This routine calculates the number of rows selected. - * - * Returns: The number of rows selected in the given model. - */ -gint -e_table_selection_model_selected_count (ETableSelectionModel *selection) -{ - gint count; - int i; - int last; - - if (!selection->selection) - return 0; - - count = 0; - - last = BOX(selection->row_count - 1); - - for (i = 0; i <= last; i++) { - int j; - guint32 thiscount = 0; - for (j = 0; j < 8; j++) - thiscount += PART(selection->selection[i], j); - for (j = 0; j < 4; j++) - count += SECTION(thiscount, j); - } - - return count; -} - -/** - * e_table_selection_model_select_all - * @selection: #ETableSelectionModel to select all - * - * This routine selects all the rows in the given - * #ETableSelectionModel. - */ -void -e_table_selection_model_select_all (ETableSelectionModel *selection) -{ - int i; - - if (selection->row_count < 0) { - if (selection->model) { - selection->row_count = e_table_model_row_count (selection->model); - g_free (selection->selection); - selection->selection = g_new0 (gint, (selection->row_count + 31) / 32); - } - } - - if (!selection->selection) - selection->selection = g_new0 (gint, (selection->row_count + 31) / 32); - - for (i = 0; i < (selection->row_count + 31) / 32; i ++) { - selection->selection[i] = ONES; - } - - /* need to zero out the bits corresponding to the rows not - selected in the last full 32 bit mask */ - if (selection->row_count % 32) { - int unselected_mask = 0; - int num_unselected_in_last_byte = 32 - selection->row_count % 32; - - for (i = 0; i < num_unselected_in_last_byte; i ++) - unselected_mask |= 1 << i; - - selection->selection[(selection->row_count + 31) / 32 - 1] &= ~unselected_mask; - } - - selection->cursor_col = 0; - selection->cursor_row = 0; - selection->selection_start_row = 0; - gtk_signal_emit (GTK_OBJECT (selection), - e_table_selection_model_signals [CURSOR_CHANGED], 0, 0); - gtk_signal_emit (GTK_OBJECT (selection), - e_table_selection_model_signals [SELECTION_CHANGED]); -} - -/** - * e_table_selection_model_invert_selection - * @selection: #ETableSelectionModel to invert - * - * This routine inverts all the rows in the given - * #ETableSelectionModel. - */ -void -e_table_selection_model_invert_selection (ETableSelectionModel *selection) -{ - int i; - - if (selection->row_count < 0) { - if (selection->model) { - selection->row_count = e_table_model_row_count (selection->model); - g_free (selection->selection); - selection->selection = g_new0 (gint, (selection->row_count + 31) / 32); - } - } - - if (!selection->selection) - selection->selection = g_new0 (gint, (selection->row_count + 31) / 32); - - for (i = 0; i < (selection->row_count + 31) / 32; i ++) { - selection->selection[i] = ~selection->selection[i]; - } - - selection->cursor_col = -1; - selection->cursor_row = -1; - selection->selection_start_row = 0; - gtk_signal_emit (GTK_OBJECT (selection), - e_table_selection_model_signals [CURSOR_CHANGED], -1, -1); - gtk_signal_emit (GTK_OBJECT (selection), - e_table_selection_model_signals [SELECTION_CHANGED]); -} diff --git a/widgets/table/e-table-selection-model.h b/widgets/table/e-table-selection-model.h deleted file mode 100644 index 2bfa5c6e7d..0000000000 --- a/widgets/table/e-table-selection-model.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SELECTION_MODEL_H_ -#define _E_TABLE_SELECTION_MODEL_H_ - -#include <gtk/gtkobject.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-defines.h> -#include <gal/e-table/e-table-sorter.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_SELECTION_MODEL_TYPE (e_table_selection_model_get_type ()) -#define E_TABLE_SELECTION_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_SELECTION_MODEL_TYPE, ETableSelectionModel)) -#define E_TABLE_SELECTION_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SELECTION_MODEL_TYPE, ETableSelectionModelClass)) -#define E_IS_TABLE_SELECTION_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_SELECTION_MODEL_TYPE)) -#define E_IS_TABLE_SELECTION_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SELECTION_MODEL_TYPE)) - -typedef struct { - GtkObject base; - - ETableModel *model; - ETableSorter *sorter; - - gint row_count; - guint32 *selection; - - gint cursor_row; - gint cursor_col; - gint selection_start_row; - - guint model_changed_id; - guint model_row_inserted_id, model_row_deleted_id; - - guint frozen : 1; - guint selection_model_changed : 1; - guint group_info_changed : 1; - - GtkSelectionMode mode; - ETableCursorMode cursor_mode; -} ETableSelectionModel; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Signals - */ - - void (*cursor_changed) (ETableSelectionModel *selection, int row, int col); - void (*cursor_activated) (ETableSelectionModel *selection, int row, int col); - void (*selection_changed) (ETableSelectionModel *selection); - -} ETableSelectionModelClass; - -GtkType e_table_selection_model_get_type (void); -gboolean e_table_selection_model_is_row_selected (ETableSelectionModel *selection, - gint n); -void e_table_selection_model_foreach (ETableSelectionModel *selection, - ETableForeachFunc callback, - gpointer closure); - -void e_table_selection_model_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state); -void e_table_selection_model_maybe_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state); -gint e_table_selection_model_key_press (ETableSelectionModel *selection, - GdkEventKey *key); -void e_table_selection_model_clear (ETableSelectionModel *selection); -gint e_table_selection_model_selected_count (ETableSelectionModel *selection); - -void e_table_selection_model_select_all (ETableSelectionModel *selection); -void e_table_selection_model_invert_selection (ETableSelectionModel *selection); - -ETableSelectionModel *e_table_selection_model_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* _E_TABLE_SELECTION_MODEL_H_ */ diff --git a/widgets/table/e-table-simple.c b/widgets/table/e-table-simple.c deleted file mode 100644 index 82d29bd6c7..0000000000 --- a/widgets/table/e-table-simple.c +++ /dev/null @@ -1,269 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a simple table model implementation that uses function - * pointers to simplify the creation of new, exotic and colorful tables in - * no time. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999, 2000 Ximian, Inc. - */ - -#include <config.h> -#include "e-table-simple.h" - -enum { - ARG_0, - ARG_APPEND_ROW, -}; - -#define PARENT_TYPE e_table_model_get_type () - -static int -simple_column_count (ETableModel *etm) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->col_count) - return simple->col_count (etm, simple->data); - else - return 0; -} - -static int -simple_row_count (ETableModel *etm) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->row_count) - return simple->row_count (etm, simple->data); - else - return 0; -} - -static void * -simple_value_at (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_at) - return simple->value_at (etm, col, row, simple->data); - else - return NULL; -} - -static void -simple_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->set_value_at) - simple->set_value_at (etm, col, row, val, simple->data); -} - -static gboolean -simple_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->is_cell_editable) - return simple->is_cell_editable (etm, col, row, simple->data); - else - return FALSE; -} - -/* The default for simple_duplicate_value is to return the raw value. */ -static void * -simple_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->duplicate_value) - return simple->duplicate_value (etm, col, value, simple->data); - else - return (void *)value; -} - -static void -simple_free_value (ETableModel *etm, int col, void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->free_value) - simple->free_value (etm, col, value, simple->data); -} - -static void * -simple_initialize_value (ETableModel *etm, int col) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->initialize_value) - return simple->initialize_value (etm, col, simple->data); - else - return NULL; -} - -static gboolean -simple_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_is_empty) - return simple->value_is_empty (etm, col, value, simple->data); - else - return FALSE; -} - -static char * -simple_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_to_string) - return simple->value_to_string (etm, col, value, simple->data); - else - return g_strdup (""); -} - -static void -simple_append_row (ETableModel *etm, ETableModel *source, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->append_row) - simple->append_row (etm, source, row, simple->data); -} - -static void -simple_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSimple *simple = E_TABLE_SIMPLE (o); - - switch (arg_id){ - case ARG_APPEND_ROW: - GTK_VALUE_POINTER(*arg) = simple->append_row; - break; - } -} - -static void -simple_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSimple *simple = E_TABLE_SIMPLE (o); - - switch (arg_id){ - case ARG_APPEND_ROW: - simple->append_row = GTK_VALUE_POINTER(*arg); - break; - default: - arg->type = GTK_TYPE_INVALID; - } -} - -static void -e_table_simple_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *model_class = (ETableModelClass *) object_class; - - object_class->set_arg = simple_set_arg; - object_class->get_arg = simple_get_arg; - - model_class->column_count = simple_column_count; - model_class->row_count = simple_row_count; - model_class->value_at = simple_value_at; - model_class->set_value_at = simple_set_value_at; - model_class->is_cell_editable = simple_is_cell_editable; - model_class->duplicate_value = simple_duplicate_value; - model_class->free_value = simple_free_value; - model_class->initialize_value = simple_initialize_value; - model_class->value_is_empty = simple_value_is_empty; - model_class->value_to_string = simple_value_to_string; - model_class->append_row = simple_append_row; - - gtk_object_add_arg_type ("ETableSimple::append_row", GTK_TYPE_POINTER, - GTK_ARG_READWRITE, ARG_APPEND_ROW); -} - -GtkType -e_table_simple_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableSimple", - sizeof (ETableSimple), - sizeof (ETableSimpleClass), - (GtkClassInitFunc) e_table_simple_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -/** - * e_table_simple_new: - * @col_count: - * @row_count: - * @value_at: - * @set_value_at: - * @is_cell_editable: - * @duplicate_value: - * @free_value: - * @initialize_value: - * @value_is_empty: - * @value_to_string: - * @data: closure pointer. - * - * This initializes a new ETableSimpleModel object. ETableSimpleModel is - * an implementaiton of the abstract class ETableModel. The ETableSimpleModel - * is designed to allow people to easily create ETableModels without having - * to create a new GtkType derived from ETableModel every time they need one. - * - * Instead, ETableSimpleModel uses a setup based in callback functions, every - * callback function signature mimics the signature of each ETableModel method - * and passes the extra @data pointer to each one of the method to provide them - * with any context they might want to use. - * - * Returns: An ETableSimpleModel object (which is also an ETableModel - * object). - */ -ETableModel * -e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleDuplicateValueFn duplicate_value, - ETableSimpleFreeValueFn free_value, - ETableSimpleInitializeValueFn initialize_value, - ETableSimpleValueIsEmptyFn value_is_empty, - ETableSimpleValueToStringFn value_to_string, - void *data) -{ - ETableSimple *et; - - et = gtk_type_new (e_table_simple_get_type ()); - - et->col_count = col_count; - et->row_count = row_count; - et->value_at = value_at; - et->set_value_at = set_value_at; - et->is_cell_editable = is_cell_editable; - et->duplicate_value = duplicate_value; - et->free_value = free_value; - et->initialize_value = initialize_value; - et->value_is_empty = value_is_empty; - et->value_to_string = value_to_string; - et->data = data; - - return (ETableModel *) et; - } diff --git a/widgets/table/e-table-simple.h b/widgets/table/e-table-simple.h deleted file mode 100644 index cf5ec6d4f2..0000000000 --- a/widgets/table/e-table-simple.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SIMPLE_H_ -#define _E_TABLE_SIMPLE_H_ - -#include <gal/e-table/e-table-model.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_SIMPLE_TYPE (e_table_simple_get_type ()) -#define E_TABLE_SIMPLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SIMPLE_TYPE, ETableSimple)) -#define E_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SIMPLE_TYPE, ETableSimpleClass)) -#define E_IS_TABLE_SIMPLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SIMPLE_TYPE)) -#define E_IS_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SIMPLE_TYPE)) - -typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); -typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); -typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); -typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleAppendRowFn) (ETableModel *etm, ETableModel *model, int row, void *data); -typedef void *(*ETableSimpleDuplicateValueFn) (ETableModel *etm, int col, const void *val, void *data); -typedef void (*ETableSimpleFreeValueFn) (ETableModel *etm, int col, void *val, void *data); -typedef void *(*ETableSimpleInitializeValueFn) (ETableModel *etm, int col, void *data); -typedef gboolean (*ETableSimpleValueIsEmptyFn) (ETableModel *etm, int col, const void *val, void *data); -typedef char *(*ETableSimpleValueToStringFn) (ETableModel *etm, int col, const void *val, void *data); - -typedef struct { - ETableModel parent; - - ETableSimpleColumnCountFn col_count; - ETableSimpleRowCountFn row_count; - ETableSimpleValueAtFn value_at; - ETableSimpleSetValueAtFn set_value_at; - ETableSimpleIsCellEditableFn is_cell_editable; - ETableSimpleDuplicateValueFn duplicate_value; - ETableSimpleFreeValueFn free_value; - ETableSimpleInitializeValueFn initialize_value; - ETableSimpleValueIsEmptyFn value_is_empty; - ETableSimpleValueToStringFn value_to_string; - ETableSimpleAppendRowFn append_row; - void *data; -} ETableSimple; - -typedef struct { - ETableModelClass parent_class; -} ETableSimpleClass; - -GtkType e_table_simple_get_type (void); - -ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleDuplicateValueFn duplicate_value, - ETableSimpleFreeValueFn free_value, - ETableSimpleInitializeValueFn initialize_value, - ETableSimpleValueIsEmptyFn value_is_empty, - ETableSimpleValueToStringFn value_to_string, - void *data); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_SIMPLE_H_ */ - diff --git a/widgets/table/e-table-size-test.c b/widgets/table/e-table-size-test.c deleted file mode 100644 index acb6e4296d..0000000000 --- a/widgets/table/e-table-size-test.c +++ /dev/null @@ -1,287 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include "gal/e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include "table-test.h" - -/* - * One way in which we make it simpler to build an ETableModel is through - * the ETableSimple class. Instead of creating your own ETableModel - * class, you simply create a new object of the ETableSimple class. You - * give it a bunch of functions that act as callbacks. - * - * You also get to pass a void * to ETableSimple and it gets passed to - * your callbacks. This would be for having multiple models of the same - * type. This is just an example though, so we statically define all the - * data and ignore the void *data parameter. - * - * In our example we will be creating a table model with 6 columns and 10 - * rows. This corresponds to having 6 different types of information and - * 10 different sets of data in our database. - * - * The headers will be hard coded, as will be the example data. - * - */ - -/* - * There are two different meanings to the word "column". The first is - * the model column. A model column corresponds to a specific type of - * data. This is very much like the usage in a database table where a - * column is a field in the database. - * - * The second type of column is a view column. A view column - * corresponds to a visually displayed column. Each view column - * corresponds to a specific model column, though a model column may - * have any number of view columns associated with it, from zero to - * greater than one. - * - * Also, a view column doesn't necessarily depend on only one model - * column. In some cases, the view column renderer can be given a - * reference to another column to get extra information about its - * display. -*/ - -#define ROWS 5000 -#define COLS 4 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* - * Here we define the initial layout of the table. This is an xml - * format that allows you to change the initial ordering of the - * columns or to do sorting or grouping initially. This specification - * shows all 5 columns, but moves the importance column nearer to the - * front. It also sorts by the "Full Name" column (ascending.) - * Sorting and grouping take the model column as their arguments - * (sorting is specified by the "column" argument to the leaf elemnt. - */ - -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"true\"/> </grouping> \ -</ETableSpecification>" - -char *headers [COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* - * Virtual Column list: - * 0 Email - * 1 Full Name - * 2 Address - * 3 Phone - */ - -/* - * ETableSimple 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 number of rows in our ETableModel. */ -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -/* This function returns the value at a particular point in our ETableModel. */ -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - static guchar t[] = {'A', 0xc3, 0x84, 0xc3, 0x95, 0xc3, 0x94, 0xc3, 0xb5, 0x00}; - -#if 0 - if (col == 1) return "toshok@ximian.com"; -#else - if (col == 1) return t; -#endif - else if (col == 2) return "Chris Toshok"; - else if (col == 3) return "43 Vicksburg, SF"; - else if (col == 4) return "415-867-5309"; - else return NULL; -} - -/* This function sets the value at a particular point in our ETableModel. */ -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return FALSE; -} - -/* This function duplicates the value passed to it. */ -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -/* This function frees the value passed to it. */ -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -/* This function creates an empty value. */ -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -/* This function reports if a value is empty. */ -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -/* This function reports if a value is empty. */ -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -/* We create a window containing our new table. */ -static void -create_table (void) -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ETableHeader *e_table_header; - ETableModel *e_table_model = NULL; - int i; - - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - * Next we create a header. The ETableHeader is used in two - * different way. The first is the full_header. This is the - * list of possible columns in the view. The second use is - * completely internal. Many of the ETableHeader functions are - * for that purpose. The only functions we really need are - * e_table_header_new and e_table_header_add_col. - * - * First we create the header. - */ - e_table_header = e_table_header_new (); - - /* - * Next we have to build renderers for all of the columns. - * Since all our columns are text columns, we can simply use - * the same renderer over and over again. If we had different - * types of columns, we could use a different renderer for - * each column. - */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* - * Next we create a column object for each view column and add - * them to the header. We don't create a column object for - * the importance column since it will not be shown. - */ - for (i = 0; i < COLS; i++) { - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Here we create a window for our new table. This window - * will get shown and the person will be able to test their - * item. - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - - /* - * Here we create the table. We give it the three pieces of - * the table we've created, the header, the model, and the - * initial layout. It does the rest. - */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 300, 200); - - /* Show it all. */ - gtk_widget_show_all (window); -} - -/* This is the main function which just initializes gnome and call our create_table function */ - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} - diff --git a/widgets/table/e-table-sort-info.c b/widgets/table/e-table-sort-info.c deleted file mode 100644 index c723ded8d8..0000000000 --- a/widgets/table/e-table-sort-info.c +++ /dev/null @@ -1,447 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-sort-info.c: a Table Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * Chris Lahey (clahey@ximian.com) - * - * (C) 1999, 2000, 2001 Ximian, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-sort-info.h" -#include "gal/util/e-util.h" -#include "gal/util/e-xml-utils.h" - -#define ETM_CLASS(e) ((ETableSortInfoClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - - -static GtkObjectClass *e_table_sort_info_parent_class; - -enum { - SORT_INFO_CHANGED, - GROUP_INFO_CHANGED, - LAST_SIGNAL -}; - -static guint e_table_sort_info_signals [LAST_SIGNAL] = { 0, }; - -static void -etsi_destroy (GtkObject *object) -{ - ETableSortInfo *etsi; - - etsi = E_TABLE_SORT_INFO (object); - - if (etsi->groupings) - g_free(etsi->groupings); - if (etsi->sortings) - g_free(etsi->sortings); -} - -static void -e_table_sort_info_init (ETableSortInfo *info) -{ - info->group_count = 0; - info->groupings = NULL; - info->sort_count = 0; - info->sortings = NULL; - info->frozen = 0; - info->sort_info_changed = 0; - info->group_info_changed = 0; -} - -static void -e_table_sort_info_class_init (ETableSortInfoClass *klass) -{ - GtkObjectClass *object_class; - - e_table_sort_info_parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class = GTK_OBJECT_CLASS(klass); - - object_class->destroy = etsi_destroy; - - e_table_sort_info_signals [SORT_INFO_CHANGED] = - gtk_signal_new ("sort_info_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSortInfoClass, sort_info_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_sort_info_signals [GROUP_INFO_CHANGED] = - gtk_signal_new ("group_info_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSortInfoClass, group_info_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - klass->sort_info_changed = NULL; - klass->group_info_changed = NULL; - - gtk_object_class_add_signals (object_class, e_table_sort_info_signals, LAST_SIGNAL); -} - -E_MAKE_TYPE(e_table_sort_info, "ETableSortInfo", ETableSortInfo, - e_table_sort_info_class_init, e_table_sort_info_init, PARENT_TYPE); - -static void -e_table_sort_info_sort_info_changed (ETableSortInfo *info) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (E_IS_TABLE_SORT_INFO (info)); - - if (info->frozen) { - info->sort_info_changed = 1; - } else { - gtk_signal_emit (GTK_OBJECT (info), - e_table_sort_info_signals [SORT_INFO_CHANGED]); - } -} - -static void -e_table_sort_info_group_info_changed (ETableSortInfo *info) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (E_IS_TABLE_SORT_INFO (info)); - - if (info->frozen) { - info->group_info_changed = 1; - } else { - gtk_signal_emit (GTK_OBJECT (info), - e_table_sort_info_signals [GROUP_INFO_CHANGED]); - } -} - -/** - * e_table_sort_info_freeze: - * @info: The ETableSortInfo object - * - * This functions allows the programmer to cluster various changes to the - * ETableSortInfo (grouping and sorting) without having the object emit - * "group_info_changed" or "sort_info_changed" signals on each change. - * - * To thaw, invoke the e_table_sort_info_thaw() function, which will - * trigger any signals that might have been queued. - */ -void -e_table_sort_info_freeze (ETableSortInfo *info) -{ - info->frozen++; -} - -/** - * e_table_sort_info_thaw: - * @info: The ETableSortInfo object - * - * This functions allows the programmer to cluster various changes to the - * ETableSortInfo (grouping and sorting) without having the object emit - * "group_info_changed" or "sort_info_changed" signals on each change. - * - * This function will flush any pending signals that might be emited by - * this object. - */ -void -e_table_sort_info_thaw (ETableSortInfo *info) -{ - info->frozen--; - if (info->frozen != 0) - return; - - if (info->sort_info_changed) { - info->sort_info_changed = 0; - e_table_sort_info_sort_info_changed(info); - } - if (info->group_info_changed) { - info->group_info_changed = 0; - e_table_sort_info_group_info_changed(info); - } -} - -/** - * e_table_sort_info_grouping_get_count: - * @info: The ETableSortInfo object - * - * Returns: the number of grouping criteria in the object. - */ -guint -e_table_sort_info_grouping_get_count (ETableSortInfo *info) -{ - return info->group_count; -} - -static void -e_table_sort_info_grouping_real_truncate (ETableSortInfo *info, int length) -{ - if (length < info->group_count) { - info->group_count = length; - } - if (length > info->group_count) { - info->groupings = g_realloc(info->groupings, length * sizeof(ETableSortColumn)); - info->group_count = length; - } -} - -/** - * e_table_sort_info_grouping_truncate: - * @info: The ETableSortInfo object - * @lenght: position where the truncation happens. - * - * This routine can be used to reduce or grow the number of grouping - * criteria in the object. - */ -void -e_table_sort_info_grouping_truncate (ETableSortInfo *info, int length) -{ - e_table_sort_info_grouping_real_truncate(info, length); - e_table_sort_info_group_info_changed(info); -} - -/** - * e_table_sort_info_grouping_get_nth: - * @info: The ETableSortInfo object - * @n: Item information to fetch. - * - * Returns: the description of the @n-th grouping criteria in the @info object. - */ -ETableSortColumn -e_table_sort_info_grouping_get_nth (ETableSortInfo *info, int n) -{ - if (n < info->group_count) { - return info->groupings[n]; - } else { - ETableSortColumn fake = {0, 0}; - return fake; - } -} - -/** - * e_table_sort_info_grouping_set_nth: - * @info: The ETableSortInfo object - * @n: Item information to fetch. - * @column: new values for the grouping - * - * Sets the grouping criteria for index @n to be given by @column (a column number and - * whether it is ascending or descending). - */ -void -e_table_sort_info_grouping_set_nth (ETableSortInfo *info, int n, ETableSortColumn column) -{ - if (n >= info->group_count) { - e_table_sort_info_grouping_real_truncate(info, n + 1); - } - info->groupings[n] = column; - e_table_sort_info_group_info_changed(info); -} - - -/** - * e_table_sort_info_get_count: - * @info: The ETableSortInfo object - * - * Returns: the number of sorting criteria in the object. - */ -guint -e_table_sort_info_sorting_get_count (ETableSortInfo *info) -{ - return info->sort_count; -} - -static void -e_table_sort_info_sorting_real_truncate (ETableSortInfo *info, int length) -{ - if (length < info->sort_count) { - info->sort_count = length; - } - if (length > info->sort_count) { - info->sortings = g_realloc(info->sortings, length * sizeof(ETableSortColumn)); - info->sort_count = length; - } -} - -/** - * e_table_sort_info_sorting_truncate: - * @info: The ETableSortInfo object - * @lenght: position where the truncation happens. - * - * This routine can be used to reduce or grow the number of sort - * criteria in the object. - */ -void -e_table_sort_info_sorting_truncate (ETableSortInfo *info, int length) -{ - e_table_sort_info_sorting_real_truncate (info, length); - e_table_sort_info_sort_info_changed(info); -} - -/** - * e_table_sort_info_sorting_get_nth: - * @info: The ETableSortInfo object - * @n: Item information to fetch. - * - * Returns: the description of the @n-th grouping criteria in the @info object. - */ -ETableSortColumn -e_table_sort_info_sorting_get_nth (ETableSortInfo *info, int n) -{ - if (n < info->sort_count) { - return info->sortings[n]; - } else { - ETableSortColumn fake = {0, 0}; - return fake; - } -} - -/** - * e_table_sort_info_sorting_get_nth: - * @info: The ETableSortInfo object - * @n: Item information to fetch. - * @column: new values for the sorting - * - * Sets the sorting criteria for index @n to be given by @column (a - * column number and whether it is ascending or descending). - */ -void -e_table_sort_info_sorting_set_nth (ETableSortInfo *info, int n, ETableSortColumn column) -{ - if (n >= info->sort_count) { - e_table_sort_info_sorting_real_truncate(info, n + 1); - } - info->sortings[n] = column; - e_table_sort_info_sort_info_changed(info); -} - -/** - * e_table_sort_info_new: - * - * This creates a new e_table_sort_info object that contains no - * grouping and no sorting defined as of yet. This object is used - * to keep track of multi-level sorting and multi-level grouping of - * the ETable. - * - * Returns: A new %ETableSortInfo object - */ -ETableSortInfo * -e_table_sort_info_new (void) -{ - return gtk_type_new (e_table_sort_info_get_type ()); -} - -/** - * e_table_sort_info_load_from_node: - * @info: The ETableSortInfo object - * @node: pointer to the xmlNode that describes the sorting and grouping information - * @state_version: - * - * This loads the state for the %ETableSortInfo object @info from the - * xml node @node. - */ -void -e_table_sort_info_load_from_node (ETableSortInfo *info, - xmlNode *node, - gdouble state_version) -{ - int i; - xmlNode *grouping; - - if (state_version <= 0.05) { - i = 0; - for (grouping = node->childs; grouping && !strcmp (grouping->name, "group"); grouping = grouping->childs) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, "column"); - column.ascending = e_xml_get_bool_prop_by_name (grouping, "ascending"); - e_table_sort_info_grouping_set_nth(info, i++, column); - } - i = 0; - for (; grouping && !strcmp (grouping->name, "leaf"); grouping = grouping->childs) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, "column"); - column.ascending = e_xml_get_bool_prop_by_name (grouping, "ascending"); - e_table_sort_info_sorting_set_nth(info, i++, column); - } - } else { - i = 0; - for (grouping = node->childs; grouping && !strcmp (grouping->name, "group"); grouping = grouping->next) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, "column"); - column.ascending = e_xml_get_bool_prop_by_name (grouping, "ascending"); - e_table_sort_info_grouping_set_nth(info, i++, column); - } - i = 0; - for (; grouping && !strcmp (grouping->name, "leaf"); grouping = grouping->next) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, "column"); - column.ascending = e_xml_get_bool_prop_by_name (grouping, "ascending"); - e_table_sort_info_sorting_set_nth(info, i++, column); - } - } - gtk_signal_emit (GTK_OBJECT (info), - e_table_sort_info_signals [SORT_INFO_CHANGED]); - -} - -/** - * e_table_sort_info_save_to_node: - * @info: The ETableSortInfo object - * @parent: xmlNode that will be hosting the saved state of the @info object. - * - * This function is used - * - * Returns: the node that has been appended to @parent as a child containing - * the sorting and grouping information for this ETableSortInfo object. - */ -xmlNode * -e_table_sort_info_save_to_node (ETableSortInfo *info, - xmlNode *parent) -{ - xmlNode *grouping; - xmlNode *node; - int i; - const int sort_count = e_table_sort_info_sorting_get_count (info); - const int group_count = e_table_sort_info_grouping_get_count (info); - - grouping = xmlNewChild (parent, NULL, "grouping", NULL); - - for (i = 0; i < group_count; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(info, i); - xmlNode *new_node = xmlNewChild(grouping, NULL, "group", NULL); - - e_xml_set_integer_prop_by_name (new_node, "column", column.column); - e_xml_set_bool_prop_by_name (new_node, "ascending", column.ascending); - node = new_node; - } - - for (i = 0; i < sort_count; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(info, i); - xmlNode *new_node = xmlNewChild(grouping, NULL, "leaf", NULL); - - e_xml_set_integer_prop_by_name (new_node, "column", column.column); - e_xml_set_bool_prop_by_name (new_node, "ascending", column.ascending); - node = new_node; - } - - return grouping; -} - -ETableSortInfo * -e_table_sort_info_duplicate (ETableSortInfo *info) -{ - ETableSortInfo *new_info; - - new_info = e_table_sort_info_new(); - - new_info->group_count = info->group_count; - new_info->groupings = g_new(ETableSortColumn, new_info->group_count); - memmove(new_info->groupings, info->groupings, sizeof (ETableSortColumn) * new_info->group_count); - - new_info->sort_count = info->sort_count; - new_info->sortings = g_new(ETableSortColumn, new_info->sort_count); - memmove(new_info->sortings, info->sortings, sizeof (ETableSortColumn) * new_info->sort_count); - - return new_info; -} diff --git a/widgets/table/e-table-sort-info.h b/widgets/table/e-table-sort-info.h deleted file mode 100644 index a2cd4f43a0..0000000000 --- a/widgets/table/e-table-sort-info.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORT_INFO_H_ -#define _E_TABLE_SORT_INFO_H_ - -#include <gtk/gtkobject.h> -#include <gnome-xml/tree.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_SORT_INFO_TYPE (e_table_sort_info_get_type ()) -#define E_TABLE_SORT_INFO(o) (GTK_CHECK_CAST ((o), E_TABLE_SORT_INFO_TYPE, ETableSortInfo)) -#define E_TABLE_SORT_INFO_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORT_INFO_TYPE, ETableSortInfoClass)) -#define E_IS_TABLE_SORT_INFO(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORT_INFO_TYPE)) -#define E_IS_TABLE_SORT_INFO_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORT_INFO_TYPE)) - -typedef struct _ETableSortColumn ETableSortColumn; - -struct _ETableSortColumn { - guint column : 31; - guint ascending : 1; -}; - -typedef struct { - GtkObject base; - - gint group_count; - ETableSortColumn *groupings; - gint sort_count; - ETableSortColumn *sortings; - - guint frozen : 1; - guint sort_info_changed : 1; - guint group_info_changed : 1; -} ETableSortInfo; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Signals - */ - void (*sort_info_changed) (ETableSortInfo *info); - void (*group_info_changed) (ETableSortInfo *info); -} ETableSortInfoClass; - -GtkType e_table_sort_info_get_type (void); - -void e_table_sort_info_freeze (ETableSortInfo *info); -void e_table_sort_info_thaw (ETableSortInfo *info); - -guint e_table_sort_info_grouping_get_count (ETableSortInfo *info); -void e_table_sort_info_grouping_truncate (ETableSortInfo *info, - int length); -ETableSortColumn e_table_sort_info_grouping_get_nth (ETableSortInfo *info, - int n); -void e_table_sort_info_grouping_set_nth (ETableSortInfo *info, - int n, - ETableSortColumn column); - -guint e_table_sort_info_sorting_get_count (ETableSortInfo *info); -void e_table_sort_info_sorting_truncate (ETableSortInfo *info, - int length); -ETableSortColumn e_table_sort_info_sorting_get_nth (ETableSortInfo *info, - int n); -void e_table_sort_info_sorting_set_nth (ETableSortInfo *info, - int n, - ETableSortColumn column); - -ETableSortInfo *e_table_sort_info_new (void); -void e_table_sort_info_load_from_node (ETableSortInfo *info, - xmlNode *node, - gdouble state_version); -xmlNode *e_table_sort_info_save_to_node (ETableSortInfo *info, - xmlNode *parent); -ETableSortInfo *e_table_sort_info_duplicate (ETableSortInfo *info); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_SORT_INFO_H_ */ diff --git a/widgets/table/e-table-sorted-variable.c b/widgets/table/e-table-sorted-variable.c deleted file mode 100644 index 94362f547c..0000000000 --- a/widgets/table/e-table-sorted-variable.c +++ /dev/null @@ -1,668 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "gal/util/e-util.h" -#include "e-table-sorted-variable.h" - -#define d(x) - -#define PARENT_TYPE E_TABLE_SUBSET_VARIABLE_TYPE - -#define INCREMENT_AMOUNT 100 - -/* maximum insertions between an idle event that we will do without scheduling an idle sort */ -#define ETSV_INSERT_MAX (4) - -static ETableSubsetVariableClass *etsv_parent_class; - -static void etsv_proxy_model_changed (ETableModel *etm, ETableSortedVariable *etsv); -#if 0 -static void etsv_proxy_model_row_changed (ETableModel *etm, int row, ETableSortedVariable *etsv); -static void etsv_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSortedVariable *etsv); -#endif -static void etsv_sort_info_changed (ETableSortInfo *info, ETableSortedVariable *etsv); -static void etsv_sort (ETableSortedVariable *etsv); -static void etsv_add (ETableSubsetVariable *etssv, gint row); -static void etsv_add_all (ETableSubsetVariable *etssv); - -static void -etsv_destroy (GtkObject *object) -{ - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (object); - ETableSubset *etss = E_TABLE_SUBSET (object); - - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_changed_id); -#if 0 - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_cell_changed_id); -#endif - gtk_signal_disconnect (GTK_OBJECT (etsv->sort_info), - etsv->sort_info_changed_id); - - if (etsv->sort_idle_id) { - g_source_remove(etsv->sort_idle_id); - } - if (etsv->insert_idle_id) { - g_source_remove(etsv->insert_idle_id); - } - - etsv->table_model_changed_id = 0; - etsv->table_model_row_changed_id = 0; - etsv->table_model_cell_changed_id = 0; - - if (etsv->sort_info) - gtk_object_unref(GTK_OBJECT(etsv->sort_info)); - if (etsv->full_header) - gtk_object_unref(GTK_OBJECT(etsv->full_header)); - - GTK_OBJECT_CLASS (etsv_parent_class)->destroy (object); -} - -static void -etsv_class_init (GtkObjectClass *object_class) -{ - ETableSubsetVariableClass *etssv_class = E_TABLE_SUBSET_VARIABLE_CLASS(object_class); - - etsv_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = etsv_destroy; - - etssv_class->add = etsv_add; - etssv_class->add_all = etsv_add_all; -} - -static void -etsv_init (ETableSortedVariable *etsv) -{ - etsv->full_header = NULL; - etsv->sort_info = NULL; - - etsv->table_model_changed_id = 0; - etsv->table_model_row_changed_id = 0; - etsv->table_model_cell_changed_id = 0; - etsv->sort_info_changed_id = 0; - - etsv->sort_idle_id = 0; - etsv->insert_count = 0; -} - -E_MAKE_TYPE(e_table_sorted_variable, "ETableSortedVariable", ETableSortedVariable, etsv_class_init, etsv_init, PARENT_TYPE); - -static gboolean -etsv_sort_idle(ETableSortedVariable *etsv) -{ - gtk_object_ref(GTK_OBJECT(etsv)); - etsv_sort(etsv); - etsv->sort_idle_id = 0; - etsv->insert_count = 0; - gtk_object_unref(GTK_OBJECT(etsv)); - return FALSE; -} - -static gboolean -etsv_insert_idle(ETableSortedVariable *etsv) -{ - etsv->insert_count = 0; - etsv->insert_idle_id = 0; - return FALSE; -} - -/* This takes source rows. */ -static int -etsv_compare(ETableSortedVariable *etsv, int row1, int row2) -{ - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv->sort_info); - int comp_val = 0; - int ascending = 1; - ETableSubset *etss = E_TABLE_SUBSET(etsv); - - for (j = 0; j < sort_count; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j); - ETableCol *col; - col = e_table_header_get_column_by_col_idx(etsv->full_header, column.column); - if (col == NULL) - col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1); - comp_val = (*col->compare)(e_table_model_value_at (etss->source, col->col_idx, row1), - e_table_model_value_at (etss->source, col->col_idx, row2)); - ascending = column.ascending; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - - -static void -etsv_add (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv); - int i; - - if (etss->n_map + 1 > etssv->n_vals_allocated) { - etssv->n_vals_allocated += INCREMENT_AMOUNT; - etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated) * sizeof(int)); - } - i = etss->n_map; - if (etsv->sort_idle_id == 0) { - /* this is to see if we're inserting a lot of things between idle loops. - If we are, we're busy, its faster to just append and perform a full sort later */ - etsv->insert_count++; - if (etsv->insert_count > ETSV_INSERT_MAX) { - /* schedule a sort, and append instead */ - etsv->sort_idle_id = g_idle_add_full(50, (GSourceFunc) etsv_sort_idle, etsv, NULL); - } else { - /* make sure we have an idle handler to reset the count every now and then */ - if (etsv->insert_idle_id == 0) { - etsv->insert_idle_id = g_idle_add_full(40, (GSourceFunc) etsv_insert_idle, etsv, NULL); - } - i = 0; - /* handle insertions when we have a 'sort group' */ - if (e_table_model_has_sort_group(etss->source)) { - /* find the row this row maps to */ - char *group = g_strdup(e_table_model_row_sort_group(etss->source, row)); - const char *newgroup; - int cmp, grouplen, newgrouplen; - - newgroup = strrchr(group, '/'); - grouplen = strlen(group); - if (newgroup) - cmp = newgroup-group; - else - cmp = grouplen; - - /* find first common parent */ - while (i<etss->n_map) { - newgroup = e_table_model_row_sort_group(etss->source, etss->map_table[i]); - if (strncmp(newgroup, group, cmp) == 0) { - break; - } - i++; - } - - /* check matching records */ - while (i<etss->n_map) { - newgroup = e_table_model_row_sort_group(etss->source, etss->map_table[i]); - newgrouplen = strlen(newgroup); - if (strncmp(newgroup, group, cmp) == 0) { - /* common parent, check for same level */ - if (grouplen == newgrouplen) { - if (etsv_compare(etsv, etss->map_table[i], row) >= 0) - break; - } else if (strncmp(newgroup + cmp, group + cmp, grouplen - cmp) == 0) - /* Found a child of the inserted node. Insert here. */ - break; - } else { - /* ran out of common parents, insert here */ - break; - } - i++; - } - g_free(group); - } else { - while (i < etss->n_map && etsv_compare(etsv, etss->map_table[i], row) < 0) - i++; - } - memmove(etss->map_table + i + 1, etss->map_table + i, (etss->n_map - i) * sizeof(int)); - } - } - etss->map_table[i] = row; - etss->n_map++; - - e_table_model_row_inserted (etm, i); -} - -static void -etsv_add_all (ETableSubsetVariable *etssv) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv); - int rows; - int i; - - e_table_model_pre_change(etm); - - rows = e_table_model_row_count(etss->source); - - if (etss->n_map + rows > etssv->n_vals_allocated){ - etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows); - etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int)); - } - for (i = 0; i < rows; i++) - etss->map_table[etss->n_map++] = i; - - if (etsv->sort_idle_id == 0) { - etsv->sort_idle_id = g_idle_add_full(50, (GSourceFunc) etsv_sort_idle, etsv, NULL); - } - - e_table_model_changed (etm); -} - -ETableModel * -e_table_sorted_variable_new (ETableModel *source, ETableHeader *full_header, ETableSortInfo *sort_info) -{ - ETableSortedVariable *etsv = gtk_type_new (E_TABLE_SORTED_VARIABLE_TYPE); - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE (etsv); - - if (e_table_subset_variable_construct (etssv, source) == NULL){ - gtk_object_unref (GTK_OBJECT (etsv)); - return NULL; - } - - etsv->sort_info = sort_info; - gtk_object_ref(GTK_OBJECT(etsv->sort_info)); - etsv->full_header = full_header; - gtk_object_ref(GTK_OBJECT(etsv->full_header)); - - etsv->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_changed), etsv); -#if 0 - etsv->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_row_changed), etsv); - etsv->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_cell_changed), etsv); -#endif - etsv->sort_info_changed_id = gtk_signal_connect (GTK_OBJECT (sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC (etsv_sort_info_changed), etsv); - - return E_TABLE_MODEL(etsv); -} - -static void -etsv_proxy_model_changed (ETableModel *etm, ETableSortedVariable *etsv) -{ - /* FIXME: do_resort (); */ -} -#if 0 -static void -etsv_proxy_model_row_changed (ETableModel *etm, int row, ETableSortedVariable *etsv) -{ - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE(etsv); - - if (e_table_subset_variable_remove(etssv, row)) - e_table_subset_variable_add (etssv, row); -} - -static void -etsv_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSortedVariable *etsv) -{ - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE(etsv); - - if (e_table_subset_variable_remove(etssv, row)) - e_table_subset_variable_add (etssv, row); -} -#endif - -static void -etsv_sort_info_changed (ETableSortInfo *info, ETableSortedVariable *etsv) -{ - etsv_sort(etsv); -} - -static ETableSortedVariable *etsv_closure; -void **vals_closure; -int cols_closure; -int *ascending_closure; -GCompareFunc *compare_closure; - -/* FIXME: Make it not cache the second and later columns (as if anyone cares.) */ - -static int -qsort_callback(const void *data1, const void *data2) -{ - gint row1 = *(int *)data1; - gint row2 = *(int *)data2; - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(compare_closure[j]))(vals_closure[cols_closure * row1 + j], vals_closure[cols_closure * row2 + j]); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - -struct _subinfo { - int start; - GArray *rowsort; /* an array of row info's */ -}; - -struct _rowinfo { - int row; - struct _subinfo *subinfo; - struct _group_info *groupinfo; -}; - -static int -qsort_callback_complex(const void *data1, const void *data2) -{ - gint row1 = ((struct _rowinfo *)data1)->row; - gint row2 = ((struct _rowinfo *)data2)->row; - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(compare_closure[j]))(vals_closure[cols_closure * row1 + j], vals_closure[cols_closure * row2 + j]); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - -/* if sortgroup is like: -0 1 1 1 -1 1 2 2 -2 2 3 2 -3 2 4 3 -4 3 5 3 -5 2 6 1 -6 1 0 1 - - Want to sort the 1's first - Then sort each group of 2's, offsetting into the output by the new root 1 location - ... Recursively ... -*/ - -struct _group_info { - char *group; - int row; -}; - -#ifdef DEBUG -#undef DEBUG -#endif -/*#define DEBUG*/ - -#ifdef DEBUG -static int total=0; -static int total_sorted=0; -#endif - -/* builds the info needed to sort everything */ -static struct _subinfo * -etsv_sort_build_subset(ETableSortedVariable *etsv, struct _group_info *groupinfo, int start, int *end) -{ -/* ETableSubset *etss = E_TABLE_SUBSET(etsv);*/ - int rows = E_TABLE_SUBSET(etsv)->n_map; - int i, lastinsert; - GArray *rowsort = g_array_new(0, 0, sizeof(struct _rowinfo)); - struct _subinfo *subinfo, *newsub; - char *id, *newid; - int idlen, newidlen; - int cmp; - int cmplen; - - subinfo = g_malloc0(sizeof(*subinfo)); - subinfo->rowsort = rowsort; - subinfo->start = start; - lastinsert = -1; - id = groupinfo[start].group; - newid = strrchr(id, '/'); - idlen = strlen(id); - if (newid) - cmplen = newid-id; - else - cmplen = idlen; - d(printf("%d scanning level %s\n", start, id)); - for (i=start;i<rows;i++) { - newid = groupinfo[i].group; - newidlen = strlen(newid); - d(printf("%d checking group %s\n", start, newid)); - cmp = strncmp(id, newid, cmplen); - /* check for common parent */ - if (idlen == newidlen && cmp == 0) { - struct _rowinfo rowinfo; - - d(printf("%d Same parent\n", start)); - rowinfo.row = groupinfo[i].row; - rowinfo.subinfo = NULL; - rowinfo.groupinfo = &groupinfo[i]; - lastinsert = rowsort->len; - g_array_append_val(rowsort, rowinfo); -#ifdef DEBUG - total++; -#endif - } else if (newidlen > idlen) { - /* must be a new subtree */ - d(printf("%d checking subtree instead\n", start)); - newsub = etsv_sort_build_subset(etsv, groupinfo, i, &i); - d(printf("found %d nodes in subtree\n", newsub->rowsort->len)); - g_array_index(rowsort, struct _rowinfo, lastinsert).subinfo = newsub; - } else { - i--; - break; - } - } - if (end) - *end = i; - d(printf("finished level %s start was %d end was %d\n", id, start, i)); - return subinfo; -} - -/* sort each level, and then sort each level below that level (once we know - where the sublevel will fit in the overall list) */ -static int -etsv_sort_subset(ETableSortedVariable *etsv, struct _subinfo *subinfo, int startoffset) -{ - GArray *rowsort = subinfo->rowsort; - ETableSubset *etss = E_TABLE_SUBSET(etsv); - int offset, i; - - d(printf("sorting subset start %d rows %d\n", startoffset, rowsort->len)); - - /* first, sort the actual data */ - qsort(rowsort->data, rowsort->len, sizeof(struct _rowinfo), qsort_callback_complex); - - /* then put it back in the map table, where appropriate */ - offset = startoffset; - for (i=0;i<rowsort->len;i++) { - struct _rowinfo *rowinfo; - - d(printf("setting offset %d\n", offset)); - - rowinfo = &g_array_index(rowsort, struct _rowinfo, i); - etss->map_table[offset] = rowinfo->row; - if (rowinfo->subinfo) { - offset = etsv_sort_subset(etsv, rowinfo->subinfo, offset+1); - } else - offset += 1; - } - d(printf("end sort subset start %d\n", startoffset)); - - return offset; -} - -static void -etsv_sort_free_subset(ETableSortedVariable *etsv, struct _subinfo *subinfo) -{ - int i; - - for (i=0;i<subinfo->rowsort->len;i++) { - struct _rowinfo *rowinfo; - - rowinfo = &g_array_index(subinfo->rowsort, struct _rowinfo, i); - if (rowinfo->subinfo) - etsv_sort_free_subset(etsv, rowinfo->subinfo); - } - g_array_free(subinfo->rowsort, TRUE); - g_free(subinfo); -} - -static int -sort_groups_compare(const void *ap, const void *bp) -{ - struct _group_info *a = (struct _group_info *)ap; - struct _group_info *b = (struct _group_info *)bp; - - return strcmp(a->group, b->group); -} - -#ifdef DEBUG -static void -print_id(int key, int val, void *data) -{ - printf("gained id %d\n", key); -} -#endif - -/* use the sort group to select subsorts */ -static void -etsv_sort_by_group(ETableSortedVariable *etsv) -{ - ETableSubset *etss = E_TABLE_SUBSET(etsv); - int rows = E_TABLE_SUBSET(etsv)->n_map; - struct _group_info *groups; - struct _subinfo *subinfo; - int i; -#ifdef DEBUG - GHashTable *members = g_hash_table_new(0, 0); - - total = 0; - total_sorted = 0; -#endif - - d(printf("sorting %d rows\n", rows)); - - if (rows == 0) - return; - - /* get the subset rows */ - groups = g_malloc(sizeof(struct _group_info) * rows); - for (i=0;i<rows;i++) { - groups[i].row = etss->map_table[i]; - groups[i].group = g_strdup(e_table_model_row_sort_group(etss->source, groups[i].row)); -#ifdef DEBUG - g_hash_table_insert(members, etss->map_table[i], 1); - etss->map_table[i] = 0; -#endif - } - - /* sort the group info */ - qsort(groups, rows, sizeof(struct _group_info), sort_groups_compare); - - d(printf("sorted groups:\n"); - for (i=0;i<rows;i++) { - printf(" %s\n", groups[i].group); - }); - - /* now sort based on the group info */ - subinfo = etsv_sort_build_subset(etsv, groups, 0, NULL); - for (i=0;i<rows;i++) { - g_free(groups[i].group); - } - g_free(groups); - etsv_sort_subset(etsv, subinfo, 0); - etsv_sort_free_subset(etsv, subinfo); -#ifdef DEBUG - for (i=0;i<rows;i++) { - if (g_hash_table_lookup(members, etss->map_table[i]) == 0) { - printf("lost id %d\n", etss->map_table[i]); - } - g_hash_table_remove(members, etss->map_table[i]); - } - g_hash_table_foreach(members, print_id, 0); - - printf("total rows = %d, total processed = %d, total sorted = %d\n", rows, total, total_sorted); -#endif - -} - -static void -etsv_sort(ETableSortedVariable *etsv) -{ - ETableSubset *etss = E_TABLE_SUBSET(etsv); - static int reentering = 0; - int rows = E_TABLE_SUBSET(etsv)->n_map; - int total_rows; - int i; - int j; - int cols; - if (reentering) - return; - reentering = 1; - - e_table_model_pre_change(E_TABLE_MODEL(etsv)); - - total_rows = e_table_model_row_count(E_TABLE_SUBSET(etsv)->source); - cols = e_table_sort_info_sorting_get_count(etsv->sort_info); - cols_closure = cols; - etsv_closure = etsv; - vals_closure = g_new(void *, total_rows * cols); - ascending_closure = g_new(int, cols); - compare_closure = g_new(GCompareFunc, cols); - for (j = 0; j < cols; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j); - ETableCol *col; - col = e_table_header_get_column_by_col_idx(etsv->full_header, column.column); - if (col == NULL) - col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1); - for (i = 0; i < rows; i++) { -#if 0 - if( !(i & 0xff) ) { - while(gtk_events_pending()) - gtk_main_iteration(); - } -#endif - vals_closure[E_TABLE_SUBSET(etsv)->map_table[i] * cols + j] = e_table_model_value_at (etss->source, col->col_idx, E_TABLE_SUBSET(etsv)->map_table[i]); - } - compare_closure[j] = col->compare; - ascending_closure[j] = column.ascending; - } - - if (e_table_model_has_sort_group(etss->source)) { - etsv_sort_by_group(etsv); - } else { - qsort(E_TABLE_SUBSET(etsv)->map_table, rows, sizeof(int), qsort_callback); - } - g_free(vals_closure); - g_free(ascending_closure); - g_free(compare_closure); - e_table_model_changed (E_TABLE_MODEL(etsv)); - reentering = 0; -} diff --git a/widgets/table/e-table-sorted-variable.h b/widgets/table/e-table-sorted-variable.h deleted file mode 100644 index a3030eb3d7..0000000000 --- a/widgets/table/e-table-sorted-variable.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORTED_VARIABLE_H_ -#define _E_TABLE_SORTED_VARIABLE_H_ - -#include <gtk/gtkobject.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-subset-variable.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-header.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_SORTED_VARIABLE_TYPE (e_table_sorted_variable_get_type ()) -#define E_TABLE_SORTED_VARIABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTED_VARIABLE_TYPE, ETableSortedVariable)) -#define E_TABLE_SORTED_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTED_VARIABLE_TYPE, ETableSortedVariableClass)) -#define E_IS_TABLE_SORTED_VARIABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTED_VARIABLE_TYPE)) -#define E_IS_TABLE_SORTED_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTED_VARIABLE_TYPE)) - -typedef struct { - ETableSubsetVariable base; - - ETableSortInfo *sort_info; - - ETableHeader *full_header; - - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; - int sort_info_changed_id; - int sort_idle_id; - int insert_idle_id; - int insert_count; - -} ETableSortedVariable; - -typedef struct { - ETableSubsetVariableClass parent_class; -} ETableSortedVariableClass; - -GtkType e_table_sorted_variable_get_type (void); -ETableModel *e_table_sorted_variable_new (ETableModel *etm, ETableHeader *header, ETableSortInfo *sort_info); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_SORTED_VARIABLE_H_ */ diff --git a/widgets/table/e-table-sorted.c b/widgets/table/e-table-sorted.c deleted file mode 100644 index e884c774f8..0000000000 --- a/widgets/table/e-table-sorted.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include "gal/util/e-util.h" -#include "e-table-sorted.h" - -#define PARENT_TYPE E_TABLE_SUBSET_TYPE - -static ETableSubsetClass *ets_parent_class; - -static void -ets_class_init (GtkObjectClass *klass) -{ - ets_parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_table_sorted, "ETableSorted", ETableSorted, ets_class_init, NULL, PARENT_TYPE); - -static ETableSorted *sort_ets; - -static int -my_sort (const void *a, const void *b) -{ - ETableModel *source = E_TABLE_SUBSET (sort_ets)->source; - const int *ia = (const int *) a; - const int *ib = (const int *) b; - void *va, *vb; - - va = e_table_model_value_at (source, sort_ets->sort_col, *ia); - vb = e_table_model_value_at (source, sort_ets->sort_col, *ib); - - return (*sort_ets->compare) (va, vb); -} - -static void -do_sort (ETableSorted *ets) -{ - ETableSubset *etss = E_TABLE_SUBSET (ets); - g_assert (sort_ets == NULL); - - sort_ets = ets; - qsort (etss->map_table, etss->n_map, sizeof (unsigned int), my_sort); - sort_ets = NULL; -} - -ETableModel * -e_table_sorted_new (ETableModel *source, int col, GCompareFunc compare) -{ - ETableSorted *ets = gtk_type_new (E_TABLE_SORTED_TYPE); - ETableSubset *etss = E_TABLE_SUBSET (ets); - const int nvals = e_table_model_row_count (source); - int i; - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_unref (GTK_OBJECT (ets)); - return NULL; - } - - ets->compare = compare; - ets->sort_col = col; - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - do_sort (ets); - - return (ETableModel *) ets; -} - -void -e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare) -{ - if (col == -1 || compare == NULL) - do_sort (ets); - else { - ets->sort_col = col; - ets->compare = compare; - do_sort (ets); - } -} - diff --git a/widgets/table/e-table-sorted.h b/widgets/table/e-table-sorted.h deleted file mode 100644 index 390141b3c1..0000000000 --- a/widgets/table/e-table-sorted.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _E_TABLE_SORTED_H_ -#define _E_TABLE_SORTED_H_ - -#include <gtk/gtkobject.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-subset.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_SORTED_TYPE (e_table_sorted_get_type ()) -#define E_TABLE_SORTED(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTED_TYPE, ETableSorted)) -#define E_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTED_TYPE, ETableSortedClass)) -#define E_IS_TABLE_SORTED(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTED_TYPE)) -#define E_IS_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTED_TYPE)) - -typedef struct { - ETableSubset base; - - short sort_col; - GCompareFunc compare; -} ETableSorted; - -typedef struct { - ETableSubsetClass parent_class; -} ETableSortedClass; - -GtkType e_table_sorted_get_type (void); -ETableModel *e_table_sorted_new (ETableModel *etm, int col, GCompareFunc compare); -void e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_SORTED_H_ */ diff --git a/widgets/table/e-table-sorter.c b/widgets/table/e-table-sorter.c deleted file mode 100644 index a103e3cd85..0000000000 --- a/widgets/table/e-table-sorter.c +++ /dev/null @@ -1,526 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "gal/util/e-util.h" -#include "e-table-sorter.h" - -#define d(x) - -/* The arguments we take */ -enum { - ARG_0, - ARG_SORT_INFO -}; - -#define PARENT_TYPE gtk_object_get_type() - -#define INCREMENT_AMOUNT 100 - -static GtkObjectClass *parent_class; - -static void ets_model_changed (ETableModel *etm, ETableSorter *ets); -static void ets_model_row_changed (ETableModel *etm, int row, ETableSorter *ets); -static void ets_model_cell_changed (ETableModel *etm, int col, int row, ETableSorter *ets); -static void ets_sort_info_changed (ETableSortInfo *info, ETableSorter *ets); -static void ets_clean (ETableSorter *ets); -static void ets_sort (ETableSorter *ets); -static void ets_backsort (ETableSorter *ets); - -static void -ets_destroy (GtkObject *object) -{ - ETableSorter *ets = E_TABLE_SORTER (object); - - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_cell_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->sort_info), - ets->sort_info_changed_id); - - ets->table_model_changed_id = 0; - ets->table_model_row_changed_id = 0; - ets->table_model_cell_changed_id = 0; - ets->sort_info_changed_id = 0; - - if (ets->sort_info) - gtk_object_unref(GTK_OBJECT(ets->sort_info)); - if (ets->full_header) - gtk_object_unref(GTK_OBJECT(ets->full_header)); - if (ets->source) - gtk_object_unref(GTK_OBJECT(ets->source)); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -ets_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableSorter *ets = E_TABLE_SORTER (object); - - switch (arg_id) { - case ARG_SORT_INFO: - if (ets->sort_info) { - if (ets->sort_info_changed_id) - gtk_signal_disconnect(GTK_OBJECT(ets->sort_info), ets->sort_info_changed_id); - gtk_object_unref(GTK_OBJECT(ets->sort_info)); - } - - ets->sort_info = E_TABLE_SORT_INFO(GTK_VALUE_OBJECT (*arg)); - gtk_object_ref(GTK_OBJECT(ets->sort_info)); - ets->sort_info_changed_id = gtk_signal_connect (GTK_OBJECT (ets->sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC (ets_sort_info_changed), ets); - - ets_clean (ets); - break; - default: - break; - } -} - -static void -ets_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableSorter *ets = E_TABLE_SORTER (object); - switch (arg_id) { - case ARG_SORT_INFO: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(ets->sort_info); - break; - } -} - -static void -ets_class_init (ETableSorterClass *klass) -{ - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = ets_destroy; - object_class->set_arg = ets_set_arg; - object_class->get_arg = ets_get_arg; - - gtk_object_add_arg_type ("ETableSorter::sort_info", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_SORT_INFO); -} - -static void -ets_init (ETableSorter *ets) -{ - ets->full_header = NULL; - ets->sort_info = NULL; - ets->source = NULL; - - ets->needs_sorting = -1; - - ets->table_model_changed_id = 0; - ets->table_model_row_changed_id = 0; - ets->table_model_cell_changed_id = 0; - ets->sort_info_changed_id = 0; -} - -E_MAKE_TYPE(e_table_sorter, "ETableSorter", ETableSorter, ets_class_init, ets_init, PARENT_TYPE); - -ETableSorter * -e_table_sorter_new (ETableModel *source, ETableHeader *full_header, ETableSortInfo *sort_info) -{ - ETableSorter *ets = gtk_type_new (E_TABLE_SORTER_TYPE); - - ets->sort_info = sort_info; - gtk_object_ref(GTK_OBJECT(ets->sort_info)); - ets->full_header = full_header; - gtk_object_ref(GTK_OBJECT(ets->full_header)); - ets->source = source; - gtk_object_ref(GTK_OBJECT(ets->source)); - - ets->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (ets_model_changed), ets); - ets->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (ets_model_row_changed), ets); - ets->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (ets_model_cell_changed), ets); - ets->sort_info_changed_id = gtk_signal_connect (GTK_OBJECT (sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC (ets_sort_info_changed), ets); - - return ets; -} - -static void -ets_model_changed (ETableModel *etm, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_model_row_changed (ETableModel *etm, int row, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_model_cell_changed (ETableModel *etm, int col, int row, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_sort_info_changed (ETableSortInfo *info, ETableSorter *ets) -{ - printf ("sort info changed\n"); - ets_clean(ets); -} - -static ETableSorter *ets_closure; -static void **vals_closure; -static int cols_closure; -static int *ascending_closure; -static GCompareFunc *compare_closure; - -/* FIXME: Make it not cache the second and later columns (as if anyone cares.) */ - -static int -qsort_callback(const void *data1, const void *data2) -{ - gint row1 = *(int *)data1; - gint row2 = *(int *)data2; - int j; - int sort_count = e_table_sort_info_sorting_get_count(ets_closure->sort_info) + e_table_sort_info_grouping_get_count(ets_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(compare_closure[j]))(vals_closure[cols_closure * row1 + j], vals_closure[cols_closure * row2 + j]); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - -static void -ets_clean(ETableSorter *ets) -{ - g_free(ets->sorted); - ets->sorted = NULL; - - g_free(ets->backsorted); - ets->backsorted = NULL; - - ets->needs_sorting = -1; -} - -struct _group_info { - char *group; - int row; -}; - -struct _rowinfo { - int row; - struct _subinfo *subinfo; - struct _group_info *groupinfo; -}; - -struct _subinfo { - int start; - GArray *rowsort; /* an array of row info's */ -}; - -/* builds the info needed to sort everything */ -static struct _subinfo * -ets_sort_build_subset(ETableSorter *ets, struct _group_info *groupinfo, int start, int *end) -{ - int rows = e_table_model_row_count (ets->source); - int i, lastinsert; - GArray *rowsort = g_array_new(0, 0, sizeof(struct _rowinfo)); - struct _subinfo *subinfo, *newsub; - char *id, *newid; - int idlen, newidlen; - int cmp; - int cmplen; - - subinfo = g_malloc0(sizeof(*subinfo)); - subinfo->rowsort = rowsort; - subinfo->start = start; - lastinsert = -1; - id = groupinfo[start].group; - newid = strrchr(id, '/'); - idlen = strlen(id); - if (newid) - cmplen = newid-id; - else - cmplen = idlen; - d(printf("%d scanning level %s\n", start, id)); - for (i=start;i<rows;i++) { - newid = groupinfo[i].group; - newidlen = strlen(newid); - d(printf("%d checking group %s\n", start, newid)); - cmp = strncmp(id, newid, cmplen); - /* check for common parent */ - if (idlen == newidlen && cmp == 0) { - struct _rowinfo rowinfo; - - d(printf("%d Same parent\n", start)); - rowinfo.row = groupinfo[i].row; - rowinfo.subinfo = NULL; - rowinfo.groupinfo = &groupinfo[i]; - lastinsert = rowsort->len; - g_array_append_val(rowsort, rowinfo); -#ifdef DEBUG - total++; -#endif - } else if (newidlen > idlen) { - /* must be a new subtree */ - d(printf("%d checking subtree instead\n", start)); - newsub = ets_sort_build_subset(ets, groupinfo, i, &i); - d(printf("found %d nodes in subtree\n", newsub->rowsort->len)); - g_array_index(rowsort, struct _rowinfo, lastinsert).subinfo = newsub; - } else { - i--; - break; - } - } - if (end) - *end = i; - d(printf("finished level %s start was %d end was %d\n", id, start, i)); - return subinfo; -} - -/* sort each level, and then sort each level below that level (once we know - where the sublevel will fit in the overall list) */ -static int -ets_sort_subset(ETableSorter *ets, struct _subinfo *subinfo, int startoffset) -{ - GArray *rowsort = subinfo->rowsort; - int offset, i; - - d(printf("sorting subset start %d rows %d\n", startoffset, rowsort->len)); - - /* first, sort the actual data */ - qsort(rowsort->data, rowsort->len, sizeof(struct _rowinfo), qsort_callback); - - /* then put it back in the map table, where appropriate */ - offset = startoffset; - for (i=0;i<rowsort->len;i++) { - struct _rowinfo *rowinfo; - - d(printf("setting offset %d\n", offset)); - - rowinfo = &g_array_index(rowsort, struct _rowinfo, i); - ets->sorted[offset] = rowinfo->row; - if (rowinfo->subinfo) { - offset = ets_sort_subset(ets, rowinfo->subinfo, offset+1); - } else - offset += 1; - } - d(printf("end sort subset start %d\n", startoffset)); - - return offset; -} - -static void -ets_sort_free_subset(ETableSorter *ets, struct _subinfo *subinfo) -{ - int i; - - for (i=0;i<subinfo->rowsort->len;i++) { - struct _rowinfo *rowinfo; - - rowinfo = &g_array_index(subinfo->rowsort, struct _rowinfo, i); - if (rowinfo->subinfo) - ets_sort_free_subset(ets, rowinfo->subinfo); - } - g_array_free(subinfo->rowsort, TRUE); - g_free(subinfo); -} - -static int -sort_groups_compare(const void *ap, const void *bp) -{ - struct _group_info *a = (struct _group_info *)ap; - struct _group_info *b = (struct _group_info *)bp; - - return strcmp(a->group, b->group); -} - -/* use the sort group to select subsorts */ -static void -ets_sort_by_group (ETableSorter *ets) -{ - int rows = e_table_model_row_count (ets->source); - struct _group_info *groups; - struct _subinfo *subinfo; - int i; - - d(printf("sorting %d rows\n", rows)); - - if (rows == 0) - return; - - /* get all the rows' sort groups */ - groups = g_new(struct _group_info, rows); - for (i=0;i<rows;i++) { - groups[i].row = i; - groups[i].group = g_strdup(e_table_model_row_sort_group(ets->source, groups[i].row)); - } - - /* sort the group info */ - qsort(groups, rows, sizeof(struct _group_info), sort_groups_compare); - - d(printf("sorted groups:\n"); - for (i=0;i<rows;i++) { - printf(" %s\n", groups[i].group); - }); - - /* now sort based on the group info */ - subinfo = ets_sort_build_subset(ets, groups, 0, NULL); - for (i=0;i<rows;i++) { - g_free(groups[i].group); - } - g_free(groups); - ets_sort_subset(ets, subinfo, 0); - ets_sort_free_subset(ets, subinfo); -} - -static void -ets_sort(ETableSorter *ets) -{ - int rows; - int i; - int j; - int cols; - int group_cols; - - if (ets->sorted) - return; - - rows = e_table_model_row_count(ets->source); - group_cols = e_table_sort_info_grouping_get_count(ets->sort_info); - cols = e_table_sort_info_sorting_get_count(ets->sort_info) + group_cols; - - ets->sorted = g_new(int, rows); - for (i = 0; i < rows; i++) - ets->sorted[i] = i; - - cols_closure = cols; - ets_closure = ets; - - vals_closure = g_new(void *, rows * cols); - ascending_closure = g_new(int, cols); - compare_closure = g_new(GCompareFunc, cols); - - for (j = 0; j < cols; j++) { - ETableSortColumn column; - ETableCol *col; - - if (j < group_cols) - column = e_table_sort_info_grouping_get_nth(ets->sort_info, j); - else - column = e_table_sort_info_sorting_get_nth(ets->sort_info, j - group_cols); - - col = e_table_header_get_column_by_col_idx(ets->full_header, column.column); - if (col == NULL) - col = e_table_header_get_column (ets->full_header, e_table_header_count (ets->full_header) - 1); - - for (i = 0; i < rows; i++) { - vals_closure[i * cols + j] = e_table_model_value_at (ets->source, col->col_idx, i); - } - - compare_closure[j] = col->compare; - ascending_closure[j] = column.ascending; - } - - if (e_table_model_has_sort_group (ets->source)) { - ets_sort_by_group (ets); - } - else { - qsort(ets->sorted, rows, sizeof(int), qsort_callback); - } - - g_free(vals_closure); - g_free(ascending_closure); - g_free(compare_closure); -} - -static void -ets_backsort(ETableSorter *ets) -{ - int i, rows; - - if (ets->backsorted) - return; - - ets_sort(ets); - - rows = e_table_model_row_count(ets->source); - ets->backsorted = g_new0(int, rows); - - for (i = 0; i < rows; i++) { - ets->backsorted[ets->sorted[i]] = i; - } -} - -gboolean -e_table_sorter_needs_sorting(ETableSorter *ets) -{ - if (ets->needs_sorting < 0) { - if (e_table_sort_info_sorting_get_count(ets->sort_info) + e_table_sort_info_grouping_get_count(ets->sort_info)) - ets->needs_sorting = 1; - else - ets->needs_sorting = 0; - } - return ets->needs_sorting; -} - - -gint -e_table_sorter_model_to_sorted (ETableSorter *sorter, int row) -{ - int rows = e_table_model_row_count(sorter->source); - - g_return_val_if_fail(row >= 0, -1); - g_return_val_if_fail(row < rows, -1); - - if (e_table_sorter_needs_sorting(sorter)) - ets_backsort(sorter); - - if (sorter->backsorted) - return sorter->backsorted[row]; - else - return row; -} - -gint -e_table_sorter_sorted_to_model (ETableSorter *sorter, int row) -{ - int rows = e_table_model_row_count(sorter->source); - - g_return_val_if_fail(row >= 0, -1); - g_return_val_if_fail(row < rows, -1); - - if (e_table_sorter_needs_sorting(sorter)) - ets_sort(sorter); - - if (sorter->sorted) - return sorter->sorted[row]; - else - return row; -} diff --git a/widgets/table/e-table-sorter.h b/widgets/table/e-table-sorter.h deleted file mode 100644 index 67c9d275d3..0000000000 --- a/widgets/table/e-table-sorter.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORTER_H_ -#define _E_TABLE_SORTER_H_ - -#include <gtk/gtkobject.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-subset-variable.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-header.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_SORTER_TYPE (e_table_sorter_get_type ()) -#define E_TABLE_SORTER(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTER_TYPE, ETableSorter)) -#define E_TABLE_SORTER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTER_TYPE, ETableSorterClass)) -#define E_IS_TABLE_SORTER(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTER_TYPE)) -#define E_IS_TABLE_SORTER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTER_TYPE)) - -typedef struct { - GtkObject base; - - ETableModel *source; - ETableHeader *full_header; - ETableSortInfo *sort_info; - - /* If needs_sorting is 0, then model_to_sorted and sorted_to_model are no-ops. */ - int needs_sorting; - - int *sorted; - int *backsorted; - - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; - int sort_info_changed_id; -} ETableSorter; - -typedef struct { - GtkObjectClass parent_class; -} ETableSorterClass; - -GtkType e_table_sorter_get_type (void); -ETableSorter *e_table_sorter_new (ETableModel *etm, ETableHeader *full_header, ETableSortInfo *sort_info); - -gint e_table_sorter_model_to_sorted (ETableSorter *sorter, int row); -gint e_table_sorter_sorted_to_model (ETableSorter *sorter, int row); - -gboolean e_table_sorter_needs_sorting (ETableSorter *sorter); - -END_GNOME_DECLS - -#endif /* _E_TABLE_SORTER_H_ */ diff --git a/widgets/table/e-table-specification.c b/widgets/table/e-table-specification.c deleted file mode 100644 index 165f17ae04..0000000000 --- a/widgets/table/e-table-specification.c +++ /dev/null @@ -1,364 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-specification.c: Implements a savable description of the inital state of a table. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza (miguel@ximian.com) - * - * (C) 2000, 2001 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> -#include "gal/util/e-util.h" -#include "gal/util/e-xml-utils.h" -#include "e-table-specification.h" - -#define PARENT_TYPE (gtk_object_get_type ()) - -static GtkObjectClass *etsp_parent_class; - -static void -etsp_destroy (GtkObject *object) -{ - ETableSpecification *etsp = E_TABLE_SPECIFICATION (object); - int i; - - if (etsp->columns) { - for (i = 0; etsp->columns[i]; i++) { - gtk_object_unref (GTK_OBJECT (etsp->columns[i])); - } - g_free (etsp->columns); - } - - if (etsp->state) - gtk_object_unref (GTK_OBJECT (etsp->state)); - g_free (etsp->click_to_add_message); - - etsp->columns = NULL; - etsp->state = NULL; - etsp->click_to_add_message = NULL; - - GTK_OBJECT_CLASS (etsp_parent_class)->destroy (object); -} - -static void -etsp_class_init (GtkObjectClass *klass) -{ - etsp_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etsp_destroy; -} - -static void -etsp_init (ETableSpecification *etsp) -{ - etsp->columns = NULL; - etsp->state = NULL; - - etsp->no_headers = FALSE; - etsp->click_to_add = FALSE; - etsp->draw_grid = FALSE; - etsp->draw_focus = TRUE; - etsp->horizontal_scrolling = FALSE; - - etsp->cursor_mode = E_TABLE_CURSOR_SIMPLE; - etsp->selection_mode = GTK_SELECTION_MULTIPLE; - - etsp->click_to_add_message = NULL; -} - -E_MAKE_TYPE (e_table_specification, "ETableSpecification", ETableSpecification, etsp_class_init, etsp_init, PARENT_TYPE); - -/** - * e_table_specification_new: - * - * Creates a new %ETableSpecification object. This object is used to hold the - * information about the rendering information for ETable. - * - * Returns: a newly created %ETableSpecification object. - */ -ETableSpecification * -e_table_specification_new (void) -{ - ETableSpecification *etsp = gtk_type_new (E_TABLE_SPECIFICATION_TYPE); - - return (ETableSpecification *) etsp; -} - -/** - * e_table_specification_load_from_file: - * @specification: An ETableSpecification that you want to modify - * @filename: a filename that contains an ETableSpecification - * - * This routine modifies @specification to reflect the state described - * by the file @filename. - * - * Returns: TRUE on success, FALSE on failure. - */ -gboolean -e_table_specification_load_from_file (ETableSpecification *specification, - const char *filename) -{ - xmlDoc *doc; - doc = xmlParseFile (filename); - if (doc) { - xmlNode *node = xmlDocGetRootElement (doc); - e_table_specification_load_from_node (specification, node); - xmlFreeDoc (doc); - return TRUE; - } - return FALSE; -} - -/** - * e_table_specification_load_from_string: - * @specification: An ETableSpecification that you want to modify - * @xml: a stringified representation of an ETableSpecification description. - * - * This routine modifies @specification to reflect the state described - * by @xml. @xml is typically returned by e_table_specification_save_to_string - * or it can be embedded in your source code. - * - * Returns: TRUE on success, FALSE on failure. - */ -gboolean -e_table_specification_load_from_string (ETableSpecification *specification, - const char *xml) -{ - xmlDoc *doc; - doc = xmlParseMemory ( (char *) xml, strlen (xml)); - if (doc) { - xmlNode *node = xmlDocGetRootElement (doc); - e_table_specification_load_from_node (specification, node); - xmlFreeDoc (doc); - return TRUE; - } - - return FALSE; -} - -/** - * e_table_specification_load_from_node: - * @specification: An ETableSpecification that you want to modify - * @node: an xmlNode with an XML ETableSpecification description. - * - * This routine modifies @specification to reflect the state described - * by @node. - */ -void -e_table_specification_load_from_node (ETableSpecification *specification, - const xmlNode *node) -{ - char *temp; - xmlNode *children; - GList *list = NULL, *list2; - int i; - - specification->no_headers = e_xml_get_bool_prop_by_name (node, "no-headers"); - specification->click_to_add = e_xml_get_bool_prop_by_name (node, "click-to-add"); - specification->draw_grid = e_xml_get_bool_prop_by_name (node, "draw-grid"); - specification->draw_focus = e_xml_get_bool_prop_by_name_with_default (node, "draw-focus", TRUE); - specification->horizontal_scrolling = e_xml_get_bool_prop_by_name_with_default (node, "horizontal-scrolling", FALSE); - - specification->selection_mode = GTK_SELECTION_MULTIPLE; - temp = e_xml_get_string_prop_by_name (node, "selection-mode"); - if (temp && !strcasecmp (temp, "single")) { - specification->selection_mode = GTK_SELECTION_SINGLE; - } else if (temp && !strcasecmp (temp, "browse")) { - specification->selection_mode = GTK_SELECTION_BROWSE; - } else if (temp && !strcasecmp (temp, "extended")) { - specification->selection_mode = GTK_SELECTION_EXTENDED; - } - g_free (temp); - - specification->cursor_mode = E_TABLE_CURSOR_SIMPLE; - temp = e_xml_get_string_prop_by_name (node, "cursor-mode"); - if (temp && !strcasecmp (temp, "line")) { - specification->cursor_mode = E_TABLE_CURSOR_LINE; - } else if (temp && !strcasecmp (temp, "spreadsheet")) { - specification->cursor_mode = E_TABLE_CURSOR_SPREADSHEET; - } - g_free (temp); - g_free (specification->click_to_add_message); - - specification->click_to_add_message = - e_xml_get_string_prop_by_name ( - node, "_click-to-add-message"); - - if (specification->state) - gtk_object_unref (GTK_OBJECT (specification->state)); - specification->state = NULL; - if (specification->columns) { - for (i = 0; specification->columns[i]; i++) { - gtk_object_unref (GTK_OBJECT (specification->columns[i])); - } - g_free (specification->columns); - } - specification->columns = NULL; - - for (children = node->xmlChildrenNode; children; children = children->next) { - if (!strcmp (children->name, "ETableColumn")) { - ETableColumnSpecification *col_spec = e_table_column_specification_new (); - - e_table_column_specification_load_from_node (col_spec, children); - list = g_list_append (list, col_spec); - } else if (specification->state == NULL && !strcmp (children->name, "ETableState")) { - specification->state = e_table_state_new (); - e_table_state_load_from_node (specification->state, children); - } - } - - specification->columns = g_new (ETableColumnSpecification *, g_list_length (list) + 1); - for (list2 = list, i = 0; list2; list2 = g_list_next (list2), i++) { - specification->columns[i] = list2->data; - } - specification->columns[i] = NULL; - g_list_free (list); -} - -/** - * e_table_specification_save_to_file: - * @specification: An %ETableSpecification that you want to save - * @filename: a file name to store the specification. - * - * This routine stores the @specification into @filename. - * - * Returns: the number of bytes written or -1 on error. - */ -int -e_table_specification_save_to_file (ETableSpecification *specification, - const char *filename) -{ - xmlDoc *doc; - - g_return_val_if_fail (specification != NULL, -1); - g_return_val_if_fail (filename != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), -1); - - doc = xmlNewDoc ("1.0"); - xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); - return xmlSaveFile (filename, doc); -} - -/** - * e_table_specification_save_to_string: - * @specification: An %ETableSpecification that you want to stringify - * - * Saves the state of @specification to a string. - * - * Returns: an g_alloc() allocated string containing the stringified - * representation of @specification. This stringified representation - * uses XML as a convenience. - */ -char * -e_table_specification_save_to_string (ETableSpecification *specification) -{ - char *ret_val; - xmlChar *string; - int length; - xmlDoc *doc; - - g_return_val_if_fail (specification != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL); - - doc = xmlNewDoc ("1.0"); - xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); - xmlDocDumpMemory (doc, &string, &length); - - ret_val = g_strdup (string); - xmlFree (string); - return ret_val; -} - -/** - * e_table_specification_save_to_node: - * @specification: An ETableSpecification that you want to store. - * @doc: Node where the specification is saved - * - * This routine saves the %ETableSpecification state in the object @specification - * into the xmlDoc represented by @doc. - * - * Returns: The node that has been attached to @doc with the contents - * of the ETableSpecification. - */ -xmlNode * -e_table_specification_save_to_node (ETableSpecification *specification, - xmlDoc *doc) -{ - xmlNode *node; - char *s; - - g_return_val_if_fail (doc != NULL, NULL); - g_return_val_if_fail (specification != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL); - - node = xmlNewNode (NULL, "ETableSpecification"); - e_xml_set_bool_prop_by_name (node, "no-headers", specification->no_headers); - e_xml_set_bool_prop_by_name (node, "click-to-add", specification->click_to_add); - e_xml_set_bool_prop_by_name (node, "draw-grid", specification->draw_grid); - e_xml_set_bool_prop_by_name (node, "draw-focus", specification->draw_focus); - e_xml_set_bool_prop_by_name (node, "horizontal-scrolling", specification->horizontal_scrolling); - - switch (specification->selection_mode){ - case GTK_SELECTION_SINGLE: - s = "single"; - break; - case GTK_SELECTION_BROWSE: - s = "browse"; - break; - default: - case GTK_SELECTION_EXTENDED: - s = "extended"; - } - xmlSetProp (node, "selection-mode", s); - if (specification->cursor_mode == E_TABLE_CURSOR_LINE) - s = "line"; - else - s = "cell"; - xmlSetProp (node, "cursor-mode", s); - - xmlSetProp (node, "_click-to-add-message", specification->click_to_add_message); - - if (specification->columns){ - int i; - - for (i = 0; specification->columns [i]; i++) - e_table_column_specification_save_to_node ( - specification->columns [i], - node); - } - - if (specification->state) - e_table_state_save_to_node (specification->state, node); - - return node; -} - -/** - * e_table_specification_duplicate: - * @spec: specification to duplicate - * - * This creates a copy of the %ETableSpecification @spec - * - * Returns: The duplicated %ETableSpecification. - */ -ETableSpecification * -e_table_specification_duplicate (ETableSpecification *spec) -{ - ETableSpecification *new_spec; - char *spec_str; - - g_return_val_if_fail (spec != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (spec), NULL); - - new_spec = e_table_specification_new (); - spec_str = e_table_specification_save_to_string (spec); - e_table_specification_load_from_string (new_spec, spec_str); - g_free (spec_str); - - return new_spec; -} diff --git a/widgets/table/e-table-specification.h b/widgets/table/e-table-specification.h deleted file mode 100644 index feba63cc7a..0000000000 --- a/widgets/table/e-table-specification.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SPECIFICATION_H_ -#define _E_TABLE_SPECIFICATION_H_ - -#include <gtk/gtkobject.h> -#include <gnome-xml/tree.h> -#include <gal/e-table/e-table-state.h> -#include <gal/e-table/e-table-column-specification.h> -#include <gal/e-table/e-table-defines.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_SPECIFICATION_TYPE (e_table_specification_get_type ()) -#define E_TABLE_SPECIFICATION(o) (GTK_CHECK_CAST ((o), E_TABLE_SPECIFICATION_TYPE, ETableSpecification)) -#define E_TABLE_SPECIFICATION_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SPECIFICATION_TYPE, ETableSpecificationClass)) -#define E_IS_TABLE_SPECIFICATION(o) (GTK_CHECK_TYPE ((o), E_TABLE_SPECIFICATION_TYPE)) -#define E_IS_TABLE_SPECIFICATION_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SPECIFICATION_TYPE)) - -typedef struct { - GtkObject base; - - ETableColumnSpecification **columns; - ETableState *state; - - guint no_headers : 1; - guint click_to_add : 1; - guint draw_grid : 1; - guint draw_focus : 1; - guint horizontal_scrolling : 1; - GtkSelectionMode selection_mode; - ETableCursorMode cursor_mode; - - char *click_to_add_message; -} ETableSpecification; - -typedef struct { - GtkObjectClass parent_class; -} ETableSpecificationClass; - -GtkType e_table_specification_get_type (void); -ETableSpecification *e_table_specification_new (void); - -gboolean e_table_specification_load_from_file (ETableSpecification *specification, - const char *filename); -gboolean e_table_specification_load_from_string (ETableSpecification *specification, - const char *xml); -void e_table_specification_load_from_node (ETableSpecification *specification, - const xmlNode *node); - -int e_table_specification_save_to_file (ETableSpecification *specification, - const char *filename); -char *e_table_specification_save_to_string (ETableSpecification *specification); -xmlNode *e_table_specification_save_to_node (ETableSpecification *specification, - xmlDoc *doc); -ETableSpecification *e_table_specification_duplicate (ETableSpecification *spec); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_SPECIFICATION_H_ */ diff --git a/widgets/table/e-table-state.c b/widgets/table/e-table-state.c deleted file mode 100644 index c978487368..0000000000 --- a/widgets/table/e-table-state.c +++ /dev/null @@ -1,232 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-state.c: Savable state of a table. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza (miguel@ximian.com) - * - * (C) 2000 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> -#include "gal/util/e-util.h" -#include "gal/util/e-xml-utils.h" -#include "e-table-state.h" - -#define PARENT_TYPE (gtk_object_get_type()) - -#define STATE_VERSION 0.1 - -static GtkObjectClass *etst_parent_class; - -static void -etst_destroy (GtkObject *object) -{ - ETableState *etst = E_TABLE_STATE (object); - - if (etst->columns) - g_free (etst->columns); - - GTK_OBJECT_CLASS (etst_parent_class)->destroy (object); -} - -static void -etst_class_init (GtkObjectClass *klass) -{ - etst_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etst_destroy; -} - -static void -etst_init (ETableState *state) -{ - state->columns = NULL; - state->expansions = NULL; - state->sort_info = e_table_sort_info_new(); -} - -E_MAKE_TYPE(e_table_state, "ETableState", ETableState, etst_class_init, etst_init, PARENT_TYPE); - -ETableState * -e_table_state_new (void) -{ - ETableState *etst = gtk_type_new (E_TABLE_STATE_TYPE); - - return (ETableState *) etst; -} - -gboolean -e_table_state_load_from_file (ETableState *state, - const char *filename) -{ - xmlDoc *doc; - doc = xmlParseFile (filename); - if (doc) { - xmlNode *node = xmlDocGetRootElement(doc); - e_table_state_load_from_node(state, node); - xmlFreeDoc(doc); - return TRUE; - } - return FALSE; -} - -void -e_table_state_load_from_string (ETableState *state, - const char *xml) -{ - xmlDoc *doc; - doc = xmlParseMemory ((char *) xml, strlen(xml)); - if (doc) { - xmlNode *node = xmlDocGetRootElement(doc); - e_table_state_load_from_node(state, node); - xmlFreeDoc(doc); - } -} - -typedef struct { - int column; - double expansion; -} int_and_double; - -void -e_table_state_load_from_node (ETableState *state, - const xmlNode *node) -{ - xmlNode *children; - GList *list = NULL, *iterator; - gdouble state_version; - int i; - - state_version = e_xml_get_double_prop_by_name_with_default ( - node, "state-version", STATE_VERSION); - - if (state->sort_info) - gtk_object_unref (GTK_OBJECT(state->sort_info)); - - state->sort_info = NULL; - children = node->xmlChildrenNode; - for (; children; children = children->next) { - if (!strcmp (children->name, "column")) { - int_and_double *column_info = g_new(int_and_double, 1); - - column_info->column = e_xml_get_integer_prop_by_name( - children, "source"); - column_info->expansion = - e_xml_get_double_prop_by_name_with_default( - children, "expansion", -2); - - list = g_list_append (list, column_info); - } else if (state->sort_info == NULL && - !strcmp (children->name, "grouping")) { - state->sort_info = e_table_sort_info_new(); - e_table_sort_info_load_from_node( - state->sort_info, children, state_version); - } - } - g_free(state->columns); - g_free(state->expansions); - state->col_count = g_list_length(list); - state->columns = g_new(int, state->col_count); - state->expansions = g_new(double, state->col_count); - - for (iterator = list, i = 0; iterator; i++) { - int_and_double *column_info = iterator->data; - - state->columns [i] = column_info->column; - state->expansions [i] = column_info->expansion; - g_free (column_info); - iterator = g_list_next (iterator); - } - g_list_free(list); -} - -void -e_table_state_save_to_file (ETableState *state, - const char *filename) -{ - xmlDoc *doc; - doc = xmlNewDoc("1.0"); - xmlDocSetRootElement(doc, e_table_state_save_to_node(state, NULL)); - xmlSaveFile(filename, doc); - xmlFreeDoc(doc); -} - -char * -e_table_state_save_to_string (ETableState *state) -{ - char *ret_val; - xmlChar *string; - int length; - xmlDoc *doc; - - doc = xmlNewDoc("1.0"); - xmlDocSetRootElement(doc, e_table_state_save_to_node(state, NULL)); - xmlDocDumpMemory(doc, &string, &length); - xmlFreeDoc(doc); - - ret_val = g_strdup(string); - xmlFree(string); - return ret_val; -} - -xmlNode * -e_table_state_save_to_node (ETableState *state, - xmlNode *parent) -{ - int i; - xmlNode *node; - - if (parent) - node = xmlNewChild (parent, NULL, "ETableState", NULL); - else - node = xmlNewNode (NULL, "ETableState"); - - e_xml_set_double_prop_by_name(node, "state-version", STATE_VERSION); - - for (i = 0; i < state->col_count; i++) { - int column = state->columns[i]; - double expansion = state->expansions[i]; - xmlNode *new_node; - - new_node = xmlNewChild(node, NULL, "column", NULL); - e_xml_set_integer_prop_by_name (new_node, "source", column); - if (expansion >= -1) - e_xml_set_double_prop_by_name(new_node, "expansion", expansion); - } - - - e_table_sort_info_save_to_node(state->sort_info, node); - - return node; -} - -/** - * e_table_state_duplicate: - * @state: The ETableState to duplicate - * - * This creates a copy of the %ETableState @state - * - * Returns: The duplicated %ETableState. - */ -ETableState * -e_table_state_duplicate (ETableState *state) -{ - ETableState *new_state; - char *copy; - - g_return_val_if_fail (state != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_STATE (state), NULL); - - new_state = e_table_state_new (); - copy = e_table_state_save_to_string (state); - e_table_state_load_from_string (new_state, copy); - g_free (copy); - - return new_state; -} - diff --git a/widgets/table/e-table-state.h b/widgets/table/e-table-state.h deleted file mode 100644 index 446d560fff..0000000000 --- a/widgets/table/e-table-state.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_STATE_H_ -#define _E_TABLE_STATE_H_ - -#include <gtk/gtkobject.h> -#include <gnome-xml/tree.h> -#include <gal/e-table/e-table-sort-info.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_TABLE_STATE_TYPE (e_table_state_get_type ()) -#define E_TABLE_STATE(o) (GTK_CHECK_CAST ((o), E_TABLE_STATE_TYPE, ETableState)) -#define E_TABLE_STATE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_STATE_TYPE, ETableStateClass)) -#define E_IS_TABLE_STATE(o) (GTK_CHECK_TYPE ((o), E_TABLE_STATE_TYPE)) -#define E_IS_TABLE_STATE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_STATE_TYPE)) - -typedef struct { - GtkObject base; - - ETableSortInfo *sort_info; - int col_count; - int *columns; - double *expansions; -} ETableState; - -typedef struct { - GtkObjectClass parent_class; -} ETableStateClass; - -GtkType e_table_state_get_type (void); -ETableState *e_table_state_new (void); - -gboolean e_table_state_load_from_file (ETableState *state, - const char *filename); -void e_table_state_load_from_string (ETableState *state, - const char *xml); -void e_table_state_load_from_node (ETableState *state, - const xmlNode *node); - -void e_table_state_save_to_file (ETableState *state, - const char *filename); -char *e_table_state_save_to_string (ETableState *state); -xmlNode *e_table_state_save_to_node (ETableState *state, - xmlNode *parent); -ETableState *e_table_state_duplicate (ETableState *state); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_STATE_H_ */ diff --git a/widgets/table/e-table-subset-variable.c b/widgets/table/e-table-subset-variable.c deleted file mode 100644 index 35b451f693..0000000000 --- a/widgets/table/e-table-subset-variable.c +++ /dev/null @@ -1,193 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-subset.c: Implements a table that contains a subset of another table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "gal/util/e-util.h" -#include "e-table-subset-variable.h" - -#define ETSSV_CLASS(e) ((ETableSubsetVariableClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE E_TABLE_SUBSET_TYPE - -#define INCREMENT_AMOUNT 10 - -static ETableSubsetClass *etssv_parent_class; - -static void -etssv_add (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - - e_table_model_pre_change(etm); - - if (etss->n_map + 1 > etssv->n_vals_allocated){ - etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated + INCREMENT_AMOUNT) * sizeof(int)); - etssv->n_vals_allocated += INCREMENT_AMOUNT; - } - - etss->map_table[etss->n_map++] = row; - - e_table_model_row_inserted (etm, etss->n_map - 1); -} - -static void -etssv_add_all (ETableSubsetVariable *etssv) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - int rows; - int i; - - e_table_model_pre_change(etm); - - rows = e_table_model_row_count(etss->source); - if (etss->n_map + rows > etssv->n_vals_allocated){ - etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows); - etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int)); - } - for (i = 0; i < rows; i++) - etss->map_table[etss->n_map++] = i; - - e_table_model_changed (etm); -} - -static gboolean -etssv_remove (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - int i; - - for (i = 0; i < etss->n_map; i++){ - if (etss->map_table[i] == row) { - e_table_model_pre_change (etm); - memmove (etss->map_table + i, etss->map_table + i + 1, (etss->n_map - i - 1) * sizeof(int)); - etss->n_map --; - - e_table_model_row_deleted (etm, i); - return TRUE; - } - } - return FALSE; -} - -static void -etssv_class_init (GtkObjectClass *object_class) -{ - ETableSubsetVariableClass *klass = E_TABLE_SUBSET_VARIABLE_CLASS(object_class); - etssv_parent_class = gtk_type_class (PARENT_TYPE); - - klass->add = etssv_add; - klass->add_all = etssv_add_all; - klass->remove = etssv_remove; -} - -E_MAKE_TYPE(e_table_subset_variable, "ETableSubsetVariable", ETableSubsetVariable, etssv_class_init, NULL, PARENT_TYPE); - -ETableModel * -e_table_subset_variable_construct (ETableSubsetVariable *etssv, - ETableModel *source) -{ - if (e_table_subset_construct (E_TABLE_SUBSET(etssv), source, 1) == NULL) - return NULL; - E_TABLE_SUBSET(etssv)->n_map = 0; - - return E_TABLE_MODEL (etssv); -} - -ETableModel * -e_table_subset_variable_new (ETableModel *source) -{ - ETableSubsetVariable *etssv = gtk_type_new (E_TABLE_SUBSET_VARIABLE_TYPE); - - if (e_table_subset_variable_construct (etssv, source) == NULL){ - gtk_object_unref (GTK_OBJECT (etssv)); - return NULL; - } - - return (ETableModel *) etssv; -} - -void -e_table_subset_variable_add (ETableSubsetVariable *etssv, - gint row) -{ - g_return_if_fail (etssv != NULL); - g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv)); - - if (ETSSV_CLASS(etssv)->add) - ETSSV_CLASS (etssv)->add (etssv, row); -} - -void -e_table_subset_variable_add_all (ETableSubsetVariable *etssv) -{ - g_return_if_fail (etssv != NULL); - g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv)); - - if (ETSSV_CLASS(etssv)->add_all) - ETSSV_CLASS (etssv)->add_all (etssv); -} - -gboolean -e_table_subset_variable_remove (ETableSubsetVariable *etssv, - gint row) -{ - g_return_val_if_fail (etssv != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv), FALSE); - - if (ETSSV_CLASS(etssv)->remove) - return ETSSV_CLASS (etssv)->remove (etssv, row); - else - return FALSE; -} - -void -e_table_subset_variable_increment (ETableSubsetVariable *etssv, - gint position, - gint amount) -{ - int i; - ETableSubset *etss = E_TABLE_SUBSET(etssv); - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] >= position) - etss->map_table[i] += amount; - } -} - -void -e_table_subset_variable_decrement (ETableSubsetVariable *etssv, - gint position, - gint amount) -{ - int i; - ETableSubset *etss = E_TABLE_SUBSET(etssv); - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] >= position) - etss->map_table[i] -= amount; - } -} - -void -e_table_subset_variable_set_allocation (ETableSubsetVariable *etssv, - gint total) -{ - ETableSubset *etss = E_TABLE_SUBSET(etssv); - if (total <= 0) - total = 1; - if (total > etss->n_map){ - etss->map_table = g_realloc (etss->map_table, total * sizeof(int)); - } -} diff --git a/widgets/table/e-table-subset-variable.h b/widgets/table/e-table-subset-variable.h deleted file mode 100644 index 5436fbb8f2..0000000000 --- a/widgets/table/e-table-subset-variable.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SUBSET_VARIABLE_H_ -#define _E_TABLE_SUBSET_VARIABLE_H_ - -#include <gtk/gtkobject.h> -#include <gal/e-table/e-table-subset.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_SUBSET_VARIABLE_TYPE (e_table_subset_variable_get_type ()) -#define E_TABLE_SUBSET_VARIABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SUBSET_VARIABLE_TYPE, ETableSubsetVariable)) -#define E_TABLE_SUBSET_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SUBSET_VARIABLE_TYPE, ETableSubsetVariableClass)) -#define E_IS_TABLE_SUBSET_VARIABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SUBSET_VARIABLE_TYPE)) -#define E_IS_TABLE_SUBSET_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SUBSET_VARIABLE_TYPE)) - -typedef struct { - ETableSubset base; - - int n_vals_allocated; -} ETableSubsetVariable; - -typedef struct { - ETableSubsetClass parent_class; - - void (*add) (ETableSubsetVariable *ets, - gint row); - void (*add_all) (ETableSubsetVariable *ets); - gboolean (*remove) (ETableSubsetVariable *ets, - gint row); -} ETableSubsetVariableClass; - -GtkType e_table_subset_variable_get_type (void); -ETableModel *e_table_subset_variable_new (ETableModel *etm); -ETableModel *e_table_subset_variable_construct (ETableSubsetVariable *etssv, - ETableModel *source); -void e_table_subset_variable_add (ETableSubsetVariable *ets, - gint row); -void e_table_subset_variable_add_all (ETableSubsetVariable *ets); -gboolean e_table_subset_variable_remove (ETableSubsetVariable *ets, - gint row); -void e_table_subset_variable_increment (ETableSubsetVariable *ets, - gint position, - gint amount); -void e_table_subset_variable_decrement (ETableSubsetVariable *ets, - gint position, - gint amount); -void e_table_subset_variable_set_allocation (ETableSubsetVariable *ets, - gint total); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* _E_TABLE_SUBSET_VARIABLE_H_ */ - diff --git a/widgets/table/e-table-subset.c b/widgets/table/e-table-subset.c deleted file mode 100644 index 88ec8e59f4..0000000000 --- a/widgets/table/e-table-subset.c +++ /dev/null @@ -1,317 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-subset.c: Implements a table that contains a subset of another table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include "gal/util/e-util.h" -#include "e-table-subset.h" - -#define PARENT_TYPE E_TABLE_MODEL_TYPE -#define d(x) - -static ETableModelClass *etss_parent_class; - -static void -etss_destroy (GtkObject *object) -{ - ETableSubset *etss = E_TABLE_SUBSET (object); - - if (etss->source) { - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_pre_change_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_cell_changed_id); - - etss->table_model_pre_change_id = 0; - etss->table_model_changed_id = 0; - etss->table_model_row_changed_id = 0; - etss->table_model_cell_changed_id = 0; - - gtk_object_unref (GTK_OBJECT (etss->source)); - etss->source = NULL; - } - - etss->table_model_pre_change_id = 0; - etss->table_model_changed_id = 0; - etss->table_model_row_changed_id = 0; - etss->table_model_cell_changed_id = 0; - - g_free (etss->map_table); - - GTK_OBJECT_CLASS (etss_parent_class)->destroy (object); -} - -static int -etss_column_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_column_count (etss->source); -} - -static int -etss_row_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return etss->n_map; -} - -static void * -etss_value_at (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - etss->last_access = row; - d(g_print("g) Setting last_access to %d\n", row)); - return e_table_model_value_at (etss->source, col, etss->map_table [row]); -} - -static void -etss_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSubset *etss = (ETableSubset *)etm; - - etss->last_access = row; - d(g_print("h) Setting last_access to %d\n", row)); - return e_table_model_set_value_at (etss->source, col, etss->map_table [row], val); -} - -static gboolean -etss_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_is_cell_editable (etss->source, col, etss->map_table [row]); -} - -static void -etss_append_row (ETableModel *etm, ETableModel *source, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - e_table_model_append_row (etss->source, source, row); -} - -static void * -etss_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_duplicate_value (etss->source, col, value); -} - -static void -etss_free_value (ETableModel *etm, int col, void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - e_table_model_free_value (etss->source, col, value); -} - -static void * -etss_initialize_value (ETableModel *etm, int col) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_initialize_value (etss->source, col); -} - -static gboolean -etss_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_is_empty (etss->source, col, value); -} - -static char * -etss_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_to_string (etss->source, col, value); -} - -static void -etss_class_init (GtkObjectClass *klass) -{ - ETableModelClass *table_class = (ETableModelClass *) klass; - - etss_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etss_destroy; - - table_class->column_count = etss_column_count; - table_class->row_count = etss_row_count; - table_class->value_at = etss_value_at; - table_class->set_value_at = etss_set_value_at; - table_class->is_cell_editable = etss_is_cell_editable; - table_class->append_row = etss_append_row; - table_class->duplicate_value = etss_duplicate_value; - table_class->free_value = etss_free_value; - table_class->initialize_value = etss_initialize_value; - table_class->value_is_empty = etss_value_is_empty; - table_class->value_to_string = etss_value_to_string; -} - -static void -etss_init (ETableSubset *etss) -{ - etss->last_access = 0; -} - -E_MAKE_TYPE(e_table_subset, "ETableSubset", ETableSubset, etss_class_init, etss_init, PARENT_TYPE); - -static void -etss_proxy_model_pre_change (ETableModel *etm, ETableSubset *etss) -{ - e_table_model_pre_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_changed (ETableModel *etm, ETableSubset *etss) -{ - e_table_model_changed (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_row_changed (ETableModel *etm, int row, ETableSubset *etss) -{ - int limit; - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - limit = MIN(n, etss->last_access + 10); - for (i = etss->last_access; i < limit; i++) { - if (map_table [i] == row){ - e_table_model_row_changed (E_TABLE_MODEL (etss), i); - d(g_print("a) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return; - } - } - - limit = MAX(0, etss->last_access - 10); - for (i = etss->last_access - 1; i >= limit; i--) { - if (map_table [i] == row){ - e_table_model_row_changed (E_TABLE_MODEL (etss), i); - d(g_print("b) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return; - } - } - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_row_changed (E_TABLE_MODEL (etss), i); - d(g_print("c) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return; - } - } -} - -static void -etss_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSubset *etss) -{ - int limit; - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - limit = MIN(n, etss->last_access + 10); - for (i = etss->last_access; i < limit; i++) { - if (map_table [i] == row){ - e_table_model_cell_changed (E_TABLE_MODEL (etss), col, i); - d(g_print("d) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return; - } - } - - limit = MAX(0, etss->last_access - 10); - for (i = etss->last_access - 1; i >= limit; i--) { - if (map_table [i] == row){ - e_table_model_cell_changed (E_TABLE_MODEL (etss), col, i); - d(g_print("e) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return; - } - } - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_cell_changed (E_TABLE_MODEL (etss), col, i); - d(g_print("f) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return; - } - } -} - -ETableModel * -e_table_subset_construct (ETableSubset *etss, ETableModel *source, int nvals) -{ - unsigned int *buffer; - int i; - - buffer = (unsigned int *) g_malloc (sizeof (unsigned int) * nvals); - if (buffer == NULL) - return NULL; - etss->map_table = buffer; - etss->n_map = nvals; - etss->source = source; - gtk_object_ref (GTK_OBJECT (source)); - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - etss->table_model_pre_change_id = gtk_signal_connect (GTK_OBJECT (source), "model_pre_change", - GTK_SIGNAL_FUNC (etss_proxy_model_pre_change), etss); - etss->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_changed), etss); - etss->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_row_changed), etss); - etss->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_cell_changed), etss); - - return E_TABLE_MODEL (etss); -} - -ETableModel * -e_table_subset_new (ETableModel *source, const int nvals) -{ - ETableSubset *etss = gtk_type_new (E_TABLE_SUBSET_TYPE); - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_unref (GTK_OBJECT (etss)); - return NULL; - } - - return (ETableModel *) etss; -} - -ETableModel * -e_table_subset_get_toplevel (ETableSubset *table) -{ - g_return_val_if_fail (table != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SUBSET (table), NULL); - - if (E_IS_TABLE_SUBSET (table->source)) - return e_table_subset_get_toplevel (E_TABLE_SUBSET (table->source)); - else - return table->source; -} diff --git a/widgets/table/e-table-subset.h b/widgets/table/e-table-subset.h deleted file mode 100644 index 6521751637..0000000000 --- a/widgets/table/e-table-subset.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SUBSET_H_ -#define _E_TABLE_SUBSET_H_ - -#include <gtk/gtkobject.h> -#include <gal/e-table/e-table-model.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TABLE_SUBSET_TYPE (e_table_subset_get_type ()) -#define E_TABLE_SUBSET(o) (GTK_CHECK_CAST ((o), E_TABLE_SUBSET_TYPE, ETableSubset)) -#define E_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SUBSET_TYPE, ETableSubsetClass)) -#define E_IS_TABLE_SUBSET(o) (GTK_CHECK_TYPE ((o), E_TABLE_SUBSET_TYPE)) -#define E_IS_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SUBSET_TYPE)) - -typedef struct { - ETableModel base; - - ETableModel *source; - int n_map; - int *map_table; - - int last_access; - - int table_model_pre_change_id; - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; -} ETableSubset; - -typedef struct { - ETableModelClass parent_class; -} ETableSubsetClass; - -GtkType e_table_subset_get_type (void); -ETableModel *e_table_subset_new (ETableModel *etm, int n_vals); -ETableModel *e_table_subset_construct (ETableSubset *ets, ETableModel *source, int nvals); - -ETableModel *e_table_subset_get_toplevel (ETableSubset *table_model); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TABLE_SUBSET_H_ */ - diff --git a/widgets/table/e-table-tooltip.h b/widgets/table/e-table-tooltip.h deleted file mode 100644 index 3a100af5ab..0000000000 --- a/widgets/table/e-table-tooltip.h +++ /dev/null @@ -1,21 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_TOOLTIP_H_ -#define _E_TABLE_TOOLTIP_H_ - -#include <libgnomeui/gnome-canvas.h> - -BEGIN_GNOME_DECLS - -typedef struct { - GtkWidget *window; - gint timer; - int col, row; - int row_height; - int x, y; - int cx, cy; - GnomeCanvasItem *eti; -} ETableTooltip; - -END_GNOME_DECLS - -#endif diff --git a/widgets/table/e-table-tree.h b/widgets/table/e-table-tree.h deleted file mode 100644 index ab0378473a..0000000000 --- a/widgets/table/e-table-tree.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _E_TABLE_TREE_H_ -#define _E_TABLE_TREE_H_ - -BEGIN_GNOME_DECLS - -typedef struct { - char *title; - - union { - ETableModel *table; - GList *children; - } u; - - guint expanded :1; - guint is_leaf :1; -} ETableGroup; - -ETableGroup *e_table_group_new (const char *title, ETableModel *table); -ETableGroup *e_table_group_new_leaf (const char *title); - -END_GNOME_DECLS - -#endif /* _E_TABLE_TREE_H_ */ diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c deleted file mode 100644 index 25922fedf7..0000000000 --- a/widgets/table/e-table.c +++ /dev/null @@ -1,2285 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@ximian.com) - * Chris Lahey <clahey@ximian.com> - * - * Copyright 1999, 2000, 2001, Ximian, Inc - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <stdio.h> -#include "gal/util/e-i18n.h" -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtksignal.h> - -#include "gal/util/e-util.h" -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-canvas-vbox.h" -#include "e-table.h" -#include "e-table-header-item.h" -#include "e-table-header-utils.h" -#include "e-table-subset.h" -#include "e-table-item.h" -#include "e-table-group.h" -#include "e-table-group-leaf.h" -#include "e-table-click-to-add.h" -#include "e-table-specification.h" -#include "e-table-state.h" -#include "e-table-column-specification.h" - -#define COLUMN_HEADER_HEIGHT 16 - -#define PARENT_TYPE gtk_table_get_type () - -static GtkObjectClass *e_table_parent_class; - -enum { - CURSOR_CHANGE, - CURSOR_ACTIVATED, - SELECTION_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - CLICK, - KEY_PRESS, - - TABLE_DRAG_BEGIN, - TABLE_DRAG_END, - TABLE_DRAG_DATA_GET, - TABLE_DRAG_DATA_DELETE, - - TABLE_DRAG_LEAVE, - TABLE_DRAG_MOTION, - TABLE_DRAG_DROP, - TABLE_DRAG_DATA_RECEIVED, - - LAST_SIGNAL -}; - -enum { - ARG_0, - ARG_LENGTH_THRESHOLD, -}; - -static gint et_signals [LAST_SIGNAL] = { 0, }; - -static void e_table_fill_table (ETable *e_table, ETableModel *model); -static gboolean changed_idle (gpointer data); - -static void et_grab_focus (GtkWidget *widget); - -static void et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETable *et); -static void et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETable *et); -static void et_drag_data_get(GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et); -static void et_drag_data_delete(GtkWidget *widget, - GdkDragContext *context, - ETable *et); - -static void et_drag_leave(GtkWidget *widget, - GdkDragContext *context, - guint time, - ETable *et); -static gboolean et_drag_motion(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et); -static gboolean et_drag_drop(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et); -static void et_drag_data_received(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et); -static gint e_table_drag_source_event_cb (GtkWidget *widget, - GdkEvent *event, - ETable *table); - -static gint et_focus (GtkContainer *container, GtkDirectionType direction); - - -static void -et_destroy (GtkObject *object) -{ - ETable *et = E_TABLE (object); - - - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_model_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_cell_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_inserted_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_deleted_id); - if (et->group_info_change_id) - gtk_signal_disconnect (GTK_OBJECT (et->sort_info), - et->group_info_change_id); - - if (et->reflow_idle_id) - g_source_remove(et->reflow_idle_id); - et->reflow_idle_id = 0; - - gtk_object_unref (GTK_OBJECT (et->model)); - gtk_object_unref (GTK_OBJECT (et->full_header)); - gtk_object_unref (GTK_OBJECT (et->header)); - gtk_object_unref (GTK_OBJECT (et->sort_info)); - gtk_object_unref (GTK_OBJECT (et->sorter)); - gtk_object_unref (GTK_OBJECT (et->selection)); - if (et->spec) - gtk_object_unref (GTK_OBJECT (et->spec)); - - if (et->header_canvas != NULL) - gtk_widget_destroy (GTK_WIDGET (et->header_canvas)); - - gtk_widget_destroy (GTK_WIDGET (et->table_canvas)); - - if (et->rebuild_idle_id) { - g_source_remove (et->rebuild_idle_id); - et->rebuild_idle_id = 0; - } - - g_free(et->click_to_add_message); - - (*e_table_parent_class->destroy)(object); -} - -static void -e_table_init (GtkObject *object) -{ - ETable *e_table = E_TABLE (object); - GtkTable *gtk_table = GTK_TABLE (object); - - GTK_WIDGET_SET_FLAGS (e_table, GTK_CAN_FOCUS); - - gtk_table->homogeneous = FALSE; - - e_table->sort_info = NULL; - e_table->group_info_change_id = 0; - e_table->reflow_idle_id = 0; - - e_table->draw_grid = 1; - e_table->draw_focus = 1; - e_table->cursor_mode = E_TABLE_CURSOR_SIMPLE; - e_table->length_threshold = 200; - - e_table->need_rebuild = 0; - e_table->rebuild_idle_id = 0; - - e_table->horizontal_scrolling = FALSE; - - e_table->click_to_add_message = NULL; - - e_table->drag_get_data_row = -1; - e_table->drag_get_data_col = -1; - e_table->drop_row = -1; - e_table->drop_col = -1; - e_table->site = NULL; - e_table->drag_source_button_press_event_id = 0; - e_table->drag_source_motion_notify_event_id = 0; - - e_table->sorter = NULL; - e_table->selection = e_table_selection_model_new(); - e_table->cursor_loc = E_TABLE_CURSOR_LOC_NONE; - e_table->spec = NULL; -} - -/* Grab_focus handler for the ETable */ -static void -et_grab_focus (GtkWidget *widget) -{ - ETable *e_table; - - e_table = E_TABLE (widget); - - gtk_widget_grab_focus (GTK_WIDGET (e_table->table_canvas)); -} - -/* Focus handler for the ETable */ -static gint -et_focus (GtkContainer *container, GtkDirectionType direction) -{ - ETable *e_table; - - e_table = E_TABLE (container); - - if (container->focus_child) { - gtk_container_set_focus_child (container, NULL); - return FALSE; - } - - return gtk_container_focus (GTK_CONTAINER (e_table->table_canvas), direction); -} - -static void -header_canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, ETable *e_table) -{ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->header_canvas), - 0, 0, alloc->width - 1, /* COLUMN_HEADER_HEIGHT - 1 */ - E_TABLE_HEADER_ITEM (e_table->header_item)->height - 1); - - /* When the header item is created ->height == 0, - as the font is only created when everything is realized. - So we set the usize here as well, so that the size of the - header is correct */ - if (GTK_WIDGET (e_table->header_canvas)->allocation.height != - E_TABLE_HEADER_ITEM (e_table->header_item)->height) - gtk_widget_set_usize (GTK_WIDGET (e_table->header_canvas), -1, - E_TABLE_HEADER_ITEM (e_table->header_item)->height); -} - -static void -sort_info_changed (ETableSortInfo *info, ETable *et) -{ - et->need_rebuild = TRUE; - if (!et->rebuild_idle_id) - et->rebuild_idle_id = g_idle_add_full (20, changed_idle, et, NULL); -} - -static void -e_table_setup_header (ETable *e_table) -{ - char *pointer; - e_table->header_canvas = GNOME_CANVAS (e_canvas_new ()); - GTK_WIDGET_UNSET_FLAGS (e_table->header_canvas, GTK_CAN_FOCUS); - - gtk_widget_show (GTK_WIDGET (e_table->header_canvas)); - - pointer = g_strdup_printf("%p", e_table); - - e_table->header_item = gnome_canvas_item_new ( - gnome_canvas_root (e_table->header_canvas), - e_table_header_item_get_type (), - "ETableHeader", e_table->header, - "full_header", e_table->full_header, - "sort_info", e_table->sort_info, - "dnd_code", pointer, - "table", e_table, - NULL); - - g_free(pointer); - - gtk_signal_connect ( - GTK_OBJECT (e_table->header_canvas), "size_allocate", - GTK_SIGNAL_FUNC (header_canvas_size_allocate), e_table); - - gtk_widget_set_usize (GTK_WIDGET (e_table->header_canvas), -1, - E_TABLE_HEADER_ITEM (e_table->header_item)->height); -} - -static gboolean -table_canvas_reflow_idle (ETable *e_table) -{ - gdouble height, width; - gdouble item_height; - GtkAllocation *alloc = &(GTK_WIDGET (e_table->table_canvas)->allocation); - - gtk_object_get (GTK_OBJECT (e_table->canvas_vbox), - "height", &height, - "width", &width, - NULL); - item_height = height; - height = MAX ((int)height, alloc->height); - width = MAX((int)width, alloc->width); - /* I have no idea why this needs to be -1, but it works. */ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->table_canvas), - 0, 0, width - 1, height - 1); - gtk_object_set (GTK_OBJECT (e_table->white_item), - "y1", item_height + 1, - "x2", width, - "y2", height, - NULL); - e_table->reflow_idle_id = 0; - return FALSE; -} - -static void -table_canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, - ETable *e_table) -{ - gdouble width; - gdouble height; - gdouble item_height; - - width = alloc->width; - gtk_object_get (GTK_OBJECT (e_table->canvas_vbox), - "height", &height, - NULL); - item_height = height; - height = MAX ((int)height, alloc->height); - - gtk_object_set (GTK_OBJECT (e_table->canvas_vbox), - "width", width, - NULL); - gtk_object_set (GTK_OBJECT (e_table->header), - "width", width, - NULL); - gtk_object_set (GTK_OBJECT (e_table->white_item), - "y1", item_height + 1, - "x2", width, - "y2", height, - NULL); - if (e_table->reflow_idle_id) - g_source_remove(e_table->reflow_idle_id); - table_canvas_reflow_idle(e_table); -} - -static void -table_canvas_reflow (GnomeCanvas *canvas, ETable *e_table) -{ - if (!e_table->reflow_idle_id) - e_table->reflow_idle_id = g_idle_add_full (400, (GSourceFunc) table_canvas_reflow_idle, e_table, NULL); -} - -static void -click_to_add_cursor_change (ETableClickToAdd *etcta, int row, int col, ETable *et) -{ - if (et->cursor_loc == E_TABLE_CURSOR_LOC_TABLE) { - e_table_selection_model_clear(et->selection); - } - et->cursor_loc = E_TABLE_CURSOR_LOC_ETCTA; -} - -static void -group_cursor_change (ETableGroup *etg, int row, ETable *et) -{ - if (et->cursor_loc == E_TABLE_CURSOR_LOC_ETCTA && et->click_to_add) { - e_table_click_to_add_commit(E_TABLE_CLICK_TO_ADD(et->click_to_add)); - } - et->cursor_loc = E_TABLE_CURSOR_LOC_TABLE; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [CURSOR_CHANGE], - row); -} - -static void -group_cursor_activated (ETableGroup *etg, int row, ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [CURSOR_ACTIVATED], - row); -} - -static void -group_double_click (ETableGroup *etg, int row, int col, GdkEvent *event, ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [DOUBLE_CLICK], - row, col, event); -} - -static gint -group_right_click (ETableGroup *etg, int row, int col, GdkEvent *event, ETable *et) -{ - int return_val = 0; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [RIGHT_CLICK], - row, col, event, &return_val); - return return_val; -} - -static gint -group_click (ETableGroup *etg, int row, int col, GdkEvent *event, ETable *et) -{ - int return_val = 0; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [CLICK], - row, col, event, &return_val); - return return_val; -} - -static gint -group_key_press (ETableGroup *etg, int row, int col, GdkEvent *event, ETable *et) -{ - int return_val = 0; - GdkEventKey *key = (GdkEventKey *) event; - GdkEventButton click; - switch (key->keyval) { - case GDK_Page_Down: - gtk_adjustment_set_value( - gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas)), - CLAMP(gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas))->value + - (gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas))->page_size - 20), - 0, - gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas))->upper - - gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas))->page_size)); - click.type = GDK_BUTTON_PRESS; - click.window = GTK_LAYOUT (et->table_canvas)->bin_window; - click.send_event = key->send_event; - click.time = key->time; - click.x = 30; - click.y = gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas))->page_size - 1; - click.state = key->state; - click.button = 1; - gtk_widget_event(GTK_WIDGET(et->table_canvas), - (GdkEvent *) &click); - return_val = 1; - break; - case GDK_Page_Up: - gtk_adjustment_set_value( - gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas)), - gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas))->value - - (gtk_layout_get_vadjustment (GTK_LAYOUT (et->table_canvas))->page_size - 20)); - click.type = GDK_BUTTON_PRESS; - click.window = GTK_LAYOUT (et->table_canvas)->bin_window; - click.send_event = key->send_event; - click.time = key->time; - click.x = 30; - click.y = 1; - click.state = key->state; - click.button = 1; - gtk_widget_event(GTK_WIDGET(et->table_canvas), - (GdkEvent *) &click); - return_val = 1; - break; - default: - gtk_signal_emit (GTK_OBJECT (et), - et_signals [KEY_PRESS], - row, col, event, &return_val); - break; - } - return return_val; -} - -static gboolean -changed_idle (gpointer data) -{ - ETable *et = E_TABLE (data); - - if (et->need_rebuild) { - gtk_object_destroy (GTK_OBJECT (et->group)); - et->group = e_table_group_new (GNOME_CANVAS_GROUP (et->canvas_vbox), - et->full_header, - et->header, - et->model, - et->sort_info, - 0); - e_canvas_vbox_add_item(E_CANVAS_VBOX(et->canvas_vbox), GNOME_CANVAS_ITEM(et->group)); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(et->group), - "drawgrid", et->draw_grid, - "drawfocus", et->draw_focus, - "cursor_mode", et->cursor_mode, - "length_threshold", et->length_threshold, - "table_selection_model", et->selection, - NULL); - gtk_signal_connect (GTK_OBJECT (et->group), "cursor_change", - GTK_SIGNAL_FUNC (group_cursor_change), et); - gtk_signal_connect (GTK_OBJECT (et->group), "cursor_activated", - GTK_SIGNAL_FUNC (group_cursor_activated), et); - gtk_signal_connect (GTK_OBJECT (et->group), "double_click", - GTK_SIGNAL_FUNC (group_double_click), et); - gtk_signal_connect (GTK_OBJECT (et->group), "right_click", - GTK_SIGNAL_FUNC (group_right_click), et); - gtk_signal_connect (GTK_OBJECT (et->group), "click", - GTK_SIGNAL_FUNC (group_click), et); - gtk_signal_connect (GTK_OBJECT (et->group), "key_press", - GTK_SIGNAL_FUNC (group_key_press), et); - e_table_fill_table (et, et->model); - - gtk_object_set (GTK_OBJECT (et->canvas_vbox), - "width", (double) GTK_WIDGET (et->table_canvas)->allocation.width, - NULL); - - if (GTK_WIDGET_REALIZED(et->table_canvas)) - table_canvas_size_allocate (GTK_WIDGET(et->table_canvas), >K_WIDGET(et->table_canvas)->allocation, et); - } - - et->need_rebuild = 0; - et->rebuild_idle_id = 0; - - if (et->horizontal_scrolling) - e_table_header_update_horizontal(et->header); - - return FALSE; -} - -static void -et_table_model_changed (ETableModel *model, ETable *et) -{ - et->need_rebuild = TRUE; - if (!et->rebuild_idle_id) - et->rebuild_idle_id = g_idle_add_full (20, changed_idle, et, NULL); -} - -static void -et_table_row_changed (ETableModel *table_model, int row, ETable *et) -{ - if (!et->need_rebuild) { - if (e_table_group_remove (et->group, row)) - e_table_group_add (et->group, row); - if (et->horizontal_scrolling) - e_table_header_update_horizontal(et->header); - } -} - -static void -et_table_cell_changed (ETableModel *table_model, int view_col, int row, ETable *et) -{ - et_table_row_changed (table_model, row, et); -} - -static void -et_table_row_inserted (ETableModel *table_model, int row, ETable *et) -{ - /* This number has already been decremented. */ - int row_count = e_table_model_row_count(table_model); - if (!et->need_rebuild) { - if (row != row_count - 1) - e_table_group_increment(et->group, row, 1); - e_table_group_add (et->group, row); - if (et->horizontal_scrolling) - e_table_header_update_horizontal(et->header); - } -} - -static void -et_table_row_deleted (ETableModel *table_model, int row, ETable *et) -{ - int row_count = e_table_model_row_count(table_model); - if (!et->need_rebuild) { - e_table_group_remove (et->group, row); - if (row != row_count) - e_table_group_decrement(et->group, row, 1); - if (et->horizontal_scrolling) - e_table_header_update_horizontal(et->header); - } -} - -static void -et_canvas_realize (GtkWidget *canvas, ETable *e_table) -{ - gnome_canvas_item_set( - e_table->white_item, - "fill_color_gdk", >K_WIDGET(e_table->table_canvas)->style->base[GTK_STATE_NORMAL], - NULL); -} - -static void -et_canvas_button_press (GtkWidget *canvas, GdkEvent *event, ETable *e_table) -{ - if (GTK_WIDGET_HAS_FOCUS(canvas)) { - GnomeCanvasItem *item = GNOME_CANVAS(canvas)->focused_item; - - if (E_IS_TABLE_ITEM(item)) { - e_table_item_leave_edit(E_TABLE_ITEM(item)); - } - } -} - -static void -e_table_setup_table (ETable *e_table, ETableHeader *full_header, ETableHeader *header, - ETableModel *model) -{ - e_table->table_canvas = GNOME_CANVAS (e_canvas_new ()); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "size_allocate", - GTK_SIGNAL_FUNC (table_canvas_size_allocate), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "focus_in_event", - GTK_SIGNAL_FUNC (gtk_widget_queue_draw), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "focus_out_event", - GTK_SIGNAL_FUNC (gtk_widget_queue_draw), e_table); - - gtk_signal_connect ( - GTK_OBJECT (e_table), "drag_begin", - GTK_SIGNAL_FUNC (et_drag_begin), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table), "drag_end", - GTK_SIGNAL_FUNC (et_drag_end), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table), "drag_data_get", - GTK_SIGNAL_FUNC (et_drag_data_get), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table), "drag_data_delete", - GTK_SIGNAL_FUNC (et_drag_data_delete), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table), "drag_motion", - GTK_SIGNAL_FUNC (et_drag_motion), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table), "drag_leave", - GTK_SIGNAL_FUNC (et_drag_leave), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table), "drag_drop", - GTK_SIGNAL_FUNC (et_drag_drop), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table), "drag_data_received", - GTK_SIGNAL_FUNC (et_drag_data_received), e_table); - - gtk_signal_connect (GTK_OBJECT(e_table->table_canvas), "reflow", - GTK_SIGNAL_FUNC (table_canvas_reflow), e_table); - - gtk_widget_show (GTK_WIDGET (e_table->table_canvas)); - - - e_table->white_item = gnome_canvas_item_new( - gnome_canvas_root(e_table->table_canvas), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color_gdk", >K_WIDGET(e_table->table_canvas)->style->base[GTK_STATE_NORMAL], - NULL); - - gtk_signal_connect ( - GTK_OBJECT(e_table->table_canvas), "realize", - GTK_SIGNAL_FUNC(et_canvas_realize), e_table); - gtk_signal_connect ( - GTK_OBJECT(e_table->table_canvas), "button_press_event", - GTK_SIGNAL_FUNC(et_canvas_button_press), e_table); - e_table->canvas_vbox = gnome_canvas_item_new( - gnome_canvas_root(e_table->table_canvas), - e_canvas_vbox_get_type(), - "spacing", 10.0, - NULL); - - if (e_table->use_click_to_add) { - e_table->click_to_add = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP(e_table->canvas_vbox), - e_table_click_to_add_get_type (), - "header", e_table->header, - "model", e_table->model, - "message", e_table->click_to_add_message, - NULL); - - e_canvas_vbox_add_item ( - E_CANVAS_VBOX(e_table->canvas_vbox), - e_table->click_to_add); - gtk_signal_connect ( - GTK_OBJECT (e_table->click_to_add), "cursor_change", - GTK_SIGNAL_FUNC(click_to_add_cursor_change), e_table); - } - - e_table->group = e_table_group_new ( - GNOME_CANVAS_GROUP (e_table->canvas_vbox), - full_header, header, - model, e_table->sort_info, 0); - e_canvas_vbox_add_item(E_CANVAS_VBOX(e_table->canvas_vbox), GNOME_CANVAS_ITEM(e_table->group)); - - gnome_canvas_item_set( - GNOME_CANVAS_ITEM(e_table->group), - "drawgrid", e_table->draw_grid, - "drawfocus", e_table->draw_focus, - "cursor_mode", e_table->cursor_mode, - "length_threshold", e_table->length_threshold, - "table_selection_model", e_table->selection, - NULL); - - gtk_signal_connect (GTK_OBJECT (e_table->group), "cursor_change", - GTK_SIGNAL_FUNC(group_cursor_change), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "cursor_activated", - GTK_SIGNAL_FUNC(group_cursor_activated), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "double_click", - GTK_SIGNAL_FUNC(group_double_click), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "right_click", - GTK_SIGNAL_FUNC(group_right_click), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "click", - GTK_SIGNAL_FUNC(group_click), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "key_press", - GTK_SIGNAL_FUNC(group_key_press), e_table); - - e_table->table_model_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_changed", - GTK_SIGNAL_FUNC (et_table_model_changed), e_table); - - e_table->table_row_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_changed", - GTK_SIGNAL_FUNC (et_table_row_changed), e_table); - - e_table->table_cell_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_cell_changed", - GTK_SIGNAL_FUNC (et_table_cell_changed), e_table); - - e_table->table_row_inserted_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_inserted", - GTK_SIGNAL_FUNC (et_table_row_inserted), e_table); - - e_table->table_row_deleted_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_deleted", - GTK_SIGNAL_FUNC (et_table_row_deleted), e_table); - -} - -static void -e_table_fill_table (ETable *e_table, ETableModel *model) -{ - e_table_group_add_all (e_table->group); -} - -static ETableCol * -et_col_spec_to_col (ETable *e_table, - ETableColumnSpecification *col_spec, - ETableExtras *ete) -{ - ETableCol *col = NULL; - ECell *cell; - GCompareFunc compare; - - cell = e_table_extras_get_cell(ete, col_spec->cell); - compare = e_table_extras_get_compare(ete, col_spec->compare); - - if (cell && compare) { - if (col_spec->pixbuf && *col_spec->pixbuf) { - GdkPixbuf *pixbuf; - - pixbuf = e_table_extras_get_pixbuf( - ete, col_spec->pixbuf); - if (pixbuf) { - col = e_table_col_new_with_pixbuf ( - col_spec->model_col, gettext (col_spec->title), - pixbuf, col_spec->expansion, - col_spec->minimum_width, - cell, compare, col_spec->resizable); - } - } - if (col == NULL && col_spec->title && *col_spec->title) { - col = e_table_col_new ( - col_spec->model_col, gettext (col_spec->title), - col_spec->expansion, col_spec->minimum_width, - cell, compare, col_spec->resizable); - } - } - return col; -} - -static ETableHeader * -et_spec_to_full_header (ETable *e_table, - ETableSpecification *spec, - ETableExtras *ete) -{ - ETableHeader *nh; - int column; - - g_return_val_if_fail (e_table, NULL); - g_return_val_if_fail (spec, NULL); - g_return_val_if_fail (ete, NULL); - - nh = e_table_header_new (); - - for (column = 0; spec->columns[column]; column++) { - ETableCol *col = et_col_spec_to_col ( - e_table, spec->columns[column], ete); - - if (col) - e_table_header_add_column (nh, col, -1); - } - - return nh; -} - -static ETableHeader * -et_state_to_header (ETable *e_table, ETableHeader *full_header, ETableState *state) -{ - ETableHeader *nh; - const int max_cols = e_table_header_count (full_header); - int column; - - g_return_val_if_fail (e_table, NULL); - g_return_val_if_fail (full_header, NULL); - g_return_val_if_fail (state, NULL); - - nh = e_table_header_new (); - - gtk_object_set(GTK_OBJECT(nh), - "width_extras", e_table_header_width_extras(GTK_WIDGET(e_table)->style), - NULL); - - for (column = 0; column < state->col_count; column++) { - int col; - double expansion; - ETableCol *table_col; - - col = state->columns[column]; - expansion = state->expansions[column]; - - if (col >= max_cols) - continue; - - table_col = e_table_header_get_column (full_header, col); - - if (expansion >= -1) - table_col->expansion = expansion; - - e_table_header_add_column (nh, table_col, -1); - } - - return nh; -} - -void -e_table_set_state_object(ETable *e_table, ETableState *state) -{ - if (e_table->header) - gtk_object_unref(GTK_OBJECT(e_table->header)); - e_table->header = et_state_to_header (e_table, e_table->full_header, state); - if (e_table->header) - gtk_object_ref(GTK_OBJECT(e_table->header)); - - if (e_table->sort_info) { - if (e_table->group_info_change_id) - gtk_signal_disconnect (GTK_OBJECT (e_table->sort_info), - e_table->group_info_change_id); - gtk_object_unref(GTK_OBJECT(e_table->sort_info)); - } - if (state->sort_info) { - e_table->sort_info = e_table_sort_info_duplicate(state->sort_info); - e_table->group_info_change_id = - gtk_signal_connect (GTK_OBJECT (e_table->sort_info), - "group_info_changed", - GTK_SIGNAL_FUNC (sort_info_changed), - e_table); - } - else - e_table->sort_info = NULL; - - if (e_table->sorter) - gtk_object_set(GTK_OBJECT(e_table->sorter), - "sort_info", e_table->sort_info, - NULL); - if (e_table->header_item) - gtk_object_set(GTK_OBJECT(e_table->header_item), - "ETableHeader", e_table->header, - "sort_info", e_table->sort_info, - NULL); - if (e_table->click_to_add) - gtk_object_set(GTK_OBJECT(e_table->click_to_add), - "header", e_table->header, - NULL); - - e_table->need_rebuild = TRUE; - if (!e_table->rebuild_idle_id) - e_table->rebuild_idle_id = g_idle_add_full (20, changed_idle, e_table, NULL); -} - -/** - * e_table_set_state: - * @e_table: %ETable object that will be modified - * @state_str: a string with the XML representation of the ETableState. - * - * This routine sets the state (as described by %ETableState) of the - * %ETable object. - */ -void -e_table_set_state (ETable *e_table, - const gchar *state_str) -{ - ETableState *state; - - g_return_if_fail(e_table != NULL); - g_return_if_fail(E_IS_TABLE(e_table)); - g_return_if_fail(state_str != NULL); - - state = e_table_state_new(); - e_table_state_load_from_string(state, state_str); - - if (state->col_count > 0) - e_table_set_state_object(e_table, state); - - gtk_object_unref(GTK_OBJECT(state)); -} - -/** - * e_table_load_state: - * @e_table: %ETable object that will be modified - * @filename: name of the file containing the state to be loaded into the %ETable - * - * An %ETableState will be loaded form the file pointed by @filename into the - * @e_table object. - */ -void -e_table_load_state (ETable *e_table, - const gchar *filename) -{ - ETableState *state; - - g_return_if_fail(e_table != NULL); - g_return_if_fail(E_IS_TABLE(e_table)); - g_return_if_fail(filename != NULL); - - state = e_table_state_new(); - e_table_state_load_from_file(state, filename); - - if (state->col_count > 0) - e_table_set_state_object(e_table, state); - - gtk_object_unref(GTK_OBJECT(state)); -} - -/** - * e_table_get_state_object: - * @e_table: %ETable object that will be modified - * - * Returns: the %ETableState object that encapsulates the current - * state of the @e_table object - */ -ETableState * -e_table_get_state_object (ETable *e_table) -{ - ETableState *state; - int full_col_count; - int i, j; - - state = e_table_state_new(); - state->sort_info = e_table->sort_info; - gtk_object_ref(GTK_OBJECT(state->sort_info)); - - - state->col_count = e_table_header_count (e_table->header); - full_col_count = e_table_header_count (e_table->full_header); - state->columns = g_new(int, state->col_count); - state->expansions = g_new(double, state->col_count); - for (i = 0; i < state->col_count; i++) { - ETableCol *col = e_table_header_get_column(e_table->header, i); - state->columns[i] = -1; - for (j = 0; j < full_col_count; j++) { - if (col->col_idx == e_table_header_index(e_table->full_header, j)) { - state->columns[i] = j; - break; - } - } - state->expansions[i] = col->expansion; - } - - return state; -} - -gchar *e_table_get_state (ETable *e_table) -{ - ETableState *state; - gchar *string; - - state = e_table_get_state_object(e_table); - string = e_table_state_save_to_string(state); - gtk_object_unref(GTK_OBJECT(state)); - return string; -} - -/** - * e_table_save_state: - * @e_table: %ETable object that will be modified - * @filename: name of the file containing the state to be loaded into the %ETable - * - * This routine saves the state of the @e_table object into the file pointed - * by @filename - */ -void -e_table_save_state (ETable *e_table, - const gchar *filename) -{ - ETableState *state; - - state = e_table_get_state_object(e_table); - e_table_state_save_to_file(state, filename); - gtk_object_unref(GTK_OBJECT(state)); -} - -static void -et_selection_model_selection_change (ETableGroup *etg, ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [SELECTION_CHANGE]); -} - -static ETable * -et_real_construct (ETable *e_table, ETableModel *etm, ETableExtras *ete, - ETableSpecification *specification, ETableState *state) -{ - int row = 0; - - if (ete) - gtk_object_ref(GTK_OBJECT(ete)); - else - ete = e_table_extras_new(); - - e_table->use_click_to_add = specification->click_to_add; - e_table->click_to_add_message = g_strdup (gettext (specification->click_to_add_message)); - e_table->draw_grid = specification->draw_grid; - e_table->draw_focus = specification->draw_focus; - e_table->cursor_mode = specification->cursor_mode; - e_table->full_header = et_spec_to_full_header(e_table, specification, ete); - - gtk_object_set(GTK_OBJECT(e_table->selection), - "selection_mode", specification->selection_mode, - "cursor_mode", specification->cursor_mode, - NULL); - - e_table->model = etm; - gtk_object_ref (GTK_OBJECT (etm)); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table->header = et_state_to_header (e_table, e_table->full_header, state); - e_table->horizontal_scrolling = specification->horizontal_scrolling; - - e_table->sort_info = state->sort_info; - - e_table->group_info_change_id = - gtk_signal_connect (GTK_OBJECT (e_table->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC (sort_info_changed), e_table); - - - gtk_object_set(GTK_OBJECT(e_table->header), - "sort_info", e_table->sort_info, - NULL); - - e_table->sorter = e_table_sorter_new(etm, e_table->full_header, e_table->sort_info); - - gtk_object_set (GTK_OBJECT (e_table->selection), - "model", etm, - "sorter", e_table->sorter, - NULL); - - gtk_signal_connect(GTK_OBJECT(e_table->selection), "selection_changed", - GTK_SIGNAL_FUNC(et_selection_model_selection_change), e_table); - - if (!specification->no_headers) { - e_table_setup_header (e_table); - } - e_table_setup_table (e_table, e_table->full_header, e_table->header, etm); - e_table_fill_table (e_table, etm); - - gtk_layout_get_vadjustment (GTK_LAYOUT (e_table->table_canvas))->step_increment = 20; - gtk_adjustment_changed(gtk_layout_get_vadjustment (GTK_LAYOUT (e_table->table_canvas))); - - if (!specification->no_headers) { - /* - * The header - */ - gtk_table_attach (GTK_TABLE (e_table), GTK_WIDGET (e_table->header_canvas), - 0, 1, 0 + row, 1 + row, - GTK_FILL | GTK_EXPAND, - GTK_FILL, 0, 0); - row ++; - } - gtk_table_attach (GTK_TABLE (e_table), GTK_WIDGET (e_table->table_canvas), - 0, 1, 0 + row, 1 + row, - GTK_FILL | GTK_EXPAND, - GTK_FILL | GTK_EXPAND, - 0, 0); - - gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); - - gtk_object_unref(GTK_OBJECT(ete)); - - return e_table; -} - -ETable * -e_table_construct (ETable *e_table, ETableModel *etm, ETableExtras *ete, - const char *spec_str, const char *state_str) -{ - ETableSpecification *specification; - ETableState *state; - - g_return_val_if_fail(e_table != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE(e_table), NULL); - g_return_val_if_fail(etm != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL); - g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL); - g_return_val_if_fail(spec_str != NULL, NULL); - - specification = e_table_specification_new(); - e_table_specification_load_from_string(specification, spec_str); - if (state_str) { - state = e_table_state_new(); - e_table_state_load_from_string(state, state_str); - if (state->col_count <= 0) { - gtk_object_unref(GTK_OBJECT(state)); - state = specification->state; - gtk_object_ref(GTK_OBJECT(state)); - } - } else { - state = specification->state; - gtk_object_ref(GTK_OBJECT(state)); - } - - e_table = et_real_construct (e_table, etm, ete, specification, state); - - e_table->spec = specification; - gtk_object_unref(GTK_OBJECT(state)); - - return e_table; -} - -ETable * -e_table_construct_from_spec_file (ETable *e_table, ETableModel *etm, ETableExtras *ete, - const char *spec_fn, const char *state_fn) -{ - ETableSpecification *specification; - ETableState *state; - - g_return_val_if_fail(e_table != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE(e_table), NULL); - g_return_val_if_fail(etm != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL); - g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL); - g_return_val_if_fail(spec_fn != NULL, NULL); - - specification = e_table_specification_new(); - if (!e_table_specification_load_from_file(specification, spec_fn)) { - gtk_object_unref(GTK_OBJECT(specification)); - return NULL; - } - - if (state_fn) { - state = e_table_state_new(); - if (!e_table_state_load_from_file(state, state_fn)) { - gtk_object_unref(GTK_OBJECT(state)); - state = specification->state; - gtk_object_ref(GTK_OBJECT(state)); - } - if (state->col_count <= 0) { - gtk_object_unref(GTK_OBJECT(state)); - state = specification->state; - gtk_object_ref(GTK_OBJECT(state)); - } - } else { - state = specification->state; - gtk_object_ref(GTK_OBJECT(state)); - } - - e_table = et_real_construct (e_table, etm, ete, specification, state); - - e_table->spec = specification; - gtk_object_unref(GTK_OBJECT(state)); - - return e_table; -} - -GtkWidget * -e_table_new (ETableModel *etm, ETableExtras *ete, const char *spec, const char *state) -{ - ETable *e_table; - - g_return_val_if_fail(etm != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL); - g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL); - g_return_val_if_fail(spec != NULL, NULL); - - e_table = gtk_type_new (e_table_get_type ()); - - e_table = e_table_construct (e_table, etm, ete, spec, state); - - return GTK_WIDGET (e_table); -} - -GtkWidget * -e_table_new_from_spec_file (ETableModel *etm, ETableExtras *ete, const char *spec_fn, const char *state_fn) -{ - ETable *e_table; - - g_return_val_if_fail(etm != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL); - g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL); - g_return_val_if_fail(spec_fn != NULL, NULL); - - e_table = gtk_type_new (e_table_get_type ()); - - e_table = e_table_construct_from_spec_file (e_table, etm, ete, spec_fn, state_fn); - - return GTK_WIDGET (e_table); -} - -#if 0 -static xmlNode * -et_build_column_spec (ETable *e_table) -{ - xmlNode *columns_shown; - gint i; - gint col_count; - - columns_shown = xmlNewNode (NULL, "columns-shown"); - - col_count = e_table_header_count (e_table->header); - for (i = 0; i < col_count; i++){ - gchar *text = g_strdup_printf ("%d", e_table_header_index(e_table->header, i)); - xmlNewChild (columns_shown, NULL, "column", text); - g_free (text); - } - - return columns_shown; -} - -static xmlNode * -et_build_grouping_spec (ETable *e_table) -{ - xmlNode *node; - xmlNode *grouping; - int i; - const int sort_count = e_table_sort_info_sorting_get_count (e_table->sort_info); - const int group_count = e_table_sort_info_grouping_get_count (e_table->sort_info); - - grouping = xmlNewNode (NULL, "grouping"); - node = grouping; - - for (i = 0; i < group_count; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(e_table->sort_info, i); - xmlNode *new_node = xmlNewChild(node, NULL, "group", NULL); - - e_xml_set_integer_prop_by_name (new_node, "column", column.column); - e_xml_set_integer_prop_by_name (new_node, "ascending", column.ascending); - node = new_node; - } - - for (i = 0; i < sort_count; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(e_table->sort_info, i); - xmlNode *new_node = xmlNewChild(node, NULL, "leaf", NULL); - - e_xml_set_integer_prop_by_name (new_node, "column", column.column); - e_xml_set_integer_prop_by_name (new_node, "ascending", column.ascending); - node = new_node; - } - - return grouping; -} - -static xmlDoc * -et_build_tree (ETable *e_table) -{ - xmlDoc *doc; - xmlNode *root; - - doc = xmlNewDoc ("1.0"); - if (doc == NULL) - return NULL; - - root = xmlNewDocNode (doc, NULL, "ETableSpecification", NULL); - xmlDocSetRootElement (doc, root); - xmlAddChild (root, et_build_column_spec (e_table)); - xmlAddChild (root, et_build_grouping_spec (e_table)); - - return doc; -} - -gchar * -e_table_get_specification (ETable *e_table) -{ - xmlDoc *doc; - xmlChar *buffer; - gint size; - - g_return_val_if_fail(e_table != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE(e_table), NULL); - - doc = et_build_tree (e_table); - xmlDocDumpMemory (doc, &buffer, &size); - xmlFreeDoc (doc); - - return buffer; -} - -int -e_table_set_specification (ETable *e_table, const char *spec) -{ - xmlDoc *xmlSpec; - int ret; - - g_return_val_if_fail(e_table != NULL, -1); - g_return_val_if_fail(E_IS_TABLE(e_table), -1); - g_return_val_if_fail(spec != NULL, -1); - - /* doesn't work yet, sigh */ - xmlSpec = xmlParseMemory ((char *)spec, strlen(spec)); - ret = et_real_set_specification(e_table, xmlSpec); - xmlFreeDoc (xmlSpec); - - return ret; -} - -void -e_table_save_specification (ETable *e_table, gchar *filename) -{ - xmlDoc *doc = et_build_tree (e_table); - - g_return_if_fail(e_table != NULL); - g_return_if_fail(E_IS_TABLE(e_table)); - g_return_if_fail(filename != NULL); - - xmlSaveFile (filename, doc); - xmlFreeDoc (doc); -} - -int -e_table_load_specification (ETable *e_table, gchar *filename) -{ - xmlDoc *xmlSpec; - int ret; - - g_return_val_if_fail(e_table != NULL, -1); - g_return_val_if_fail(E_IS_TABLE(e_table), -1); - g_return_val_if_fail(filename != NULL, -1); - - /* doesn't work yet, yay */ - xmlSpec = xmlParseFile (filename); - ret = et_real_set_specification(e_table, xmlSpec); - xmlFreeDoc (xmlSpec); - - return ret; -} -#endif - -void -e_table_set_cursor_row (ETable *e_table, int row) -{ - g_return_if_fail(e_table != NULL); - g_return_if_fail(E_IS_TABLE(e_table)); - g_return_if_fail(row >= 0); - - gtk_object_set(GTK_OBJECT(e_table->selection), - "cursor_row", row, - NULL); -} - -int -e_table_get_cursor_row (ETable *e_table) -{ - int row; - g_return_val_if_fail(e_table != NULL, -1); - g_return_val_if_fail(E_IS_TABLE(e_table), -1); - - gtk_object_get(GTK_OBJECT(e_table->selection), - "cursor_row", &row, - NULL); - return row; -} - -void -e_table_selected_row_foreach (ETable *e_table, - ETableForeachFunc callback, - gpointer closure) -{ - g_return_if_fail(e_table != NULL); - g_return_if_fail(E_IS_TABLE(e_table)); - - e_table_selection_model_foreach(e_table->selection, - callback, - closure); -} - -gint -e_table_selected_count (ETable *e_table) -{ - g_return_val_if_fail(e_table != NULL, -1); - g_return_val_if_fail(E_IS_TABLE(e_table), -1); - - return e_table_selection_model_selected_count(e_table->selection); -} - -void -e_table_select_all (ETable *table) -{ - g_return_if_fail (table != NULL); - g_return_if_fail (E_IS_TABLE (table)); - - e_table_selection_model_select_all (table->selection); -} - -void -e_table_invert_selection (ETable *table) -{ - g_return_if_fail (table != NULL); - g_return_if_fail (E_IS_TABLE (table)); - - e_table_selection_model_invert_selection (table->selection); -} - - -EPrintable * -e_table_get_printable (ETable *e_table) -{ - g_return_val_if_fail(e_table != NULL, NULL); - g_return_val_if_fail(E_IS_TABLE(e_table), NULL); - - return e_table_group_get_printable(e_table->group); -} - -static void -et_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - switch (arg_id){ - default: - break; - } -} - -typedef struct { - char *arg; - gboolean setting; -} bool_closure; - -static void -et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETable *etable = E_TABLE (o); - - switch (arg_id){ - case ARG_LENGTH_THRESHOLD: - etable->length_threshold = GTK_VALUE_INT (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - - } -} - -static void -set_scroll_adjustments (ETable *table, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment) -{ - if (vadjustment != NULL) { - vadjustment->step_increment = 20; - gtk_adjustment_changed(vadjustment); - } - - gtk_layout_set_hadjustment (GTK_LAYOUT(table->table_canvas), - hadjustment); - gtk_layout_set_vadjustment (GTK_LAYOUT(table->table_canvas), - vadjustment); - - if (table->header_canvas != NULL) - gtk_layout_set_hadjustment (GTK_LAYOUT(table->header_canvas), - hadjustment); -} - -gint -e_table_get_next_row (ETable *e_table, - gint model_row) -{ - g_return_val_if_fail(e_table != NULL, -1); - g_return_val_if_fail(E_IS_TABLE(e_table), -1); - - if (e_table->sorter) { - int i; - i = e_table_sorter_model_to_sorted(e_table->sorter, model_row); - i++; - if (i < e_table_model_row_count(e_table->model)) { - return e_table_sorter_sorted_to_model(e_table->sorter, i); - } else - return -1; - } else - if (model_row < e_table_model_row_count(e_table->model) - 1) - return model_row + 1; - else - return -1; -} - -gint -e_table_get_prev_row (ETable *e_table, - gint model_row) -{ - g_return_val_if_fail(e_table != NULL, -1); - g_return_val_if_fail(E_IS_TABLE(e_table), -1); - - if (e_table->sorter) { - int i; - i = e_table_sorter_model_to_sorted(e_table->sorter, model_row); - i--; - if (i >= 0) - return e_table_sorter_sorted_to_model(e_table->sorter, i); - else - return -1; - } else - return model_row - 1; -} - -gint -e_table_model_to_view_row (ETable *e_table, - gint model_row) -{ - g_return_val_if_fail(e_table != NULL, -1); - g_return_val_if_fail(E_IS_TABLE(e_table), -1); - - if (e_table->sorter) - return e_table_sorter_model_to_sorted(e_table->sorter, model_row); - else - return model_row; -} - -gint -e_table_view_to_model_row (ETable *e_table, - gint view_row) -{ - g_return_val_if_fail(e_table != NULL, -1); - g_return_val_if_fail(E_IS_TABLE(e_table), -1); - - if (e_table->sorter) - return e_table_sorter_sorted_to_model(e_table->sorter, view_row); - else - return view_row; -} - -struct _ETableDragSourceSite -{ - GdkModifierType start_button_mask; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction actions; /* Possible actions */ - GdkColormap *colormap; /* Colormap for drag icon */ - GdkPixmap *pixmap; /* Icon for drag data */ - GdkBitmap *mask; - - /* Stored button press information to detect drag beginning */ - gint state; - gint x, y; - gint row, col; -}; - -typedef enum -{ - GTK_DRAG_STATUS_DRAG, - GTK_DRAG_STATUS_WAIT, - GTK_DRAG_STATUS_DROP -} GtkDragStatus; - -typedef struct _GtkDragDestInfo GtkDragDestInfo; -typedef struct _GtkDragSourceInfo GtkDragSourceInfo; - -struct _GtkDragDestInfo -{ - GtkWidget *widget; /* Widget in which drag is in */ - GdkDragContext *context; /* Drag context */ - GtkDragSourceInfo *proxy_source; /* Set if this is a proxy drag */ - GtkSelectionData *proxy_data; /* Set while retrieving proxied data */ - gboolean dropped : 1; /* Set after we receive a drop */ - guint32 proxy_drop_time; /* Timestamp for proxied drop */ - gboolean proxy_drop_wait : 1; /* Set if we are waiting for a - * status reply before sending - * a proxied drop on. - */ - gint drop_x, drop_y; /* Position of drop */ -}; - -struct _GtkDragSourceInfo -{ - GtkWidget *widget; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction possible_actions; /* Actions allowed by source */ - GdkDragContext *context; /* drag context */ - GtkWidget *icon_window; /* Window for drag */ - GtkWidget *ipc_widget; /* GtkInvisible for grab, message passing */ - GdkCursor *cursor; /* Cursor for drag */ - gint hot_x, hot_y; /* Hot spot for drag */ - gint button; /* mouse button starting drag */ - - GtkDragStatus status; /* drag status */ - GdkEvent *last_event; /* motion event waiting for response */ - - gint start_x, start_y; /* Initial position */ - gint cur_x, cur_y; /* Current Position */ - - GList *selections; /* selections we've claimed */ - - GtkDragDestInfo *proxy_dest; /* Set if this is a proxy drag */ - - guint drop_timeout; /* Timeout for aborting drop */ - guint destroy_icon : 1; /* If true, destroy icon_window - */ -}; - -/* Drag & drop stuff. */ -/* Target */ -void -e_table_drag_get_data (ETable *table, - int row, - int col, - GdkDragContext *context, - GdkAtom target, - guint32 time) -{ - g_return_if_fail(table != NULL); - g_return_if_fail(E_IS_TABLE(table)); - - table->drag_get_data_row = row; - table->drag_get_data_col = col; - gtk_drag_get_data(GTK_WIDGET(table), - context, - target, - time); - -} - -/** - * e_table_drag_highlight: - * @table: - * @row: - * @col: - * - * Set col to -1 to highlight the entire row. - */ -void -e_table_drag_highlight (ETable *table, - int row, - int col) -{ - g_return_if_fail(table != NULL); - g_return_if_fail(E_IS_TABLE(table)); -} - -void -e_table_drag_unhighlight (ETable *table) -{ - g_return_if_fail(table != NULL); - g_return_if_fail(E_IS_TABLE(table)); -} - -void e_table_drag_dest_set (ETable *table, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - g_return_if_fail(table != NULL); - g_return_if_fail(E_IS_TABLE(table)); - - gtk_drag_dest_set(GTK_WIDGET(table), - flags, - targets, - n_targets, - actions); -} - -void e_table_drag_dest_set_proxy (ETable *table, - GdkWindow *proxy_window, - GdkDragProtocol protocol, - gboolean use_coordinates) -{ - g_return_if_fail(table != NULL); - g_return_if_fail(E_IS_TABLE(table)); - - gtk_drag_dest_set_proxy(GTK_WIDGET(table), - proxy_window, - protocol, - use_coordinates); -} - -/* - * There probably should be functions for setting the targets - * as a GtkTargetList - */ - -void -e_table_drag_dest_unset (GtkWidget *widget) -{ - g_return_if_fail(widget != NULL); - g_return_if_fail(E_IS_TABLE(widget)); - - gtk_drag_dest_unset(widget); -} - -/* Source side */ - -void -e_table_drag_source_set (ETable *table, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - ETableDragSourceSite *site; - GtkWidget *canvas; - - g_return_if_fail(table != NULL); - g_return_if_fail(E_IS_TABLE(table)); - - canvas = GTK_WIDGET(table->table_canvas); - site = table->site; - - gtk_widget_add_events (canvas, - gtk_widget_get_events (canvas) | - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_BUTTON_MOTION_MASK); - - if (site) { - if (site->target_list) - gtk_target_list_unref (site->target_list); - } else { - site = g_new0 (ETableDragSourceSite, 1); - - table->drag_source_button_press_event_id = - gtk_signal_connect (GTK_OBJECT (canvas), "button_press_event", - GTK_SIGNAL_FUNC (e_table_drag_source_event_cb), - table); - table->drag_source_motion_notify_event_id = - gtk_signal_connect (GTK_OBJECT (canvas), "motion_notify_event", - GTK_SIGNAL_FUNC (e_table_drag_source_event_cb), - table); - - table->site = site; - } - - site->start_button_mask = start_button_mask; - - if (targets) - site->target_list = gtk_target_list_new (targets, n_targets); - else - site->target_list = NULL; - - site->actions = actions; -} - -void -e_table_drag_source_unset (ETable *table) -{ - ETableDragSourceSite *site; - - g_return_if_fail (table != NULL); - g_return_if_fail (E_IS_TABLE(table)); - - site = table->site; - - if (site) { - gtk_signal_disconnect ( - GTK_OBJECT (table->table_canvas), - table->drag_source_button_press_event_id); - gtk_signal_disconnect ( - GTK_OBJECT (table->table_canvas), - table->drag_source_motion_notify_event_id); - g_free (site); - table->site = NULL; - } -} - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -GdkDragContext * -e_table_drag_begin (ETable *table, - int row, - int col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event) -{ - g_return_val_if_fail (table != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE(table), NULL); - - table->drag_row = row; - table->drag_col = col; - - return gtk_drag_begin(GTK_WIDGET(table), - targets, - actions, - button, - event); -} - -static void -e_table_compute_location (ETable *table, GtkWidget *widget, - int x, int y, int *row, int *col) -{ - if (!(row || col)) - return; - x += GTK_LAYOUT(table->table_canvas)->hadjustment->value; - y += GTK_LAYOUT(table->table_canvas)->vadjustment->value; - e_table_group_compute_location(table->group, &x, &y, row, col); -} - -static void -et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_BEGIN], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_END], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_data_get(GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DATA_GET], - et->drag_row, - et->drag_col, - context, - selection_data, - info, - time); -} - -static void -et_drag_data_delete(GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DATA_DELETE], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_leave(GtkWidget *widget, - GdkDragContext *context, - guint time, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - et->drop_row = -1; - et->drop_col = -1; -} - -static gboolean -et_drag_motion(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et) -{ - gboolean ret_val; - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - if (et->drop_row >= 0 && et->drop_col >= 0 && - row != et->drop_row && col != et->drop_row) { - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - } - et->drop_row = row; - et->drop_col = col; - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_MOTION], - et->drop_row, - et->drop_col, - context, - x, - y, - time, - &ret_val); - return ret_val; -} - -static gboolean -et_drag_drop(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et) -{ - gboolean ret_val; - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - if (et->drop_row >= 0 && et->drop_col >= 0 && - row != et->drop_row && col != et->drop_row) { - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_MOTION], - row, - col, - context, - x, - y, - time, - &ret_val); - } - et->drop_row = row; - et->drop_col = col; - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DROP], - et->drop_row, - et->drop_col, - context, - x, - y, - time, - &ret_val); - et->drop_row = -1; - et->drop_col = -1; - return ret_val; -} - -static void -et_drag_data_received(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et) -{ - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DATA_RECEIVED], - row, - col, - context, - x, - y, - selection_data, - info, - time); -} - -static gint -e_table_drag_source_event_cb (GtkWidget *widget, - GdkEvent *event, - ETable *table) -{ - ETableDragSourceSite *site; - site = table->site; - - switch (event->type) { - case GDK_BUTTON_PRESS: - if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask) { - int row, col; - e_table_compute_location(table, widget, event->button.x, event->button.y, &row, &col); - if (row >= 0 && col >= 0) { - site->state |= (GDK_BUTTON1_MASK << (event->button.button - 1)); - site->x = event->button.x; - site->y = event->button.y; - site->row = row; - site->col = col; - } - } - break; - - case GDK_BUTTON_RELEASE: - if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask) { - site->state &= ~(GDK_BUTTON1_MASK << (event->button.button - 1)); - } - break; - - case GDK_MOTION_NOTIFY: - if (site->state & event->motion.state & site->start_button_mask) { - /* FIXME: This is really broken and can leave us - * with a stuck grab - */ - int i; - for (i=1; i<6; i++) { - if (site->state & event->motion.state & - GDK_BUTTON1_MASK << (i - 1)) - break; - } - - if (MAX (abs (site->x - event->motion.x), - abs (site->y - event->motion.y)) > 3) { - GtkDragSourceInfo *info; - GdkDragContext *context; - - site->state = 0; - context = e_table_drag_begin (table, site->row, site->col, - site->target_list, - site->actions, - i, event); - - - info = g_dataset_get_data (context, "gtk-info"); - - if (!info->icon_window) { - if (site->pixmap) - gtk_drag_set_icon_pixmap (context, - site->colormap, - site->pixmap, - site->mask, -2, -2); - else - gtk_drag_set_icon_default (context); - } - - return TRUE; - } - } - break; - - default: /* hit for 2/3BUTTON_PRESS */ - break; - } - return FALSE; -} - -static void -e_table_class_init (ETableClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - e_table_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = et_destroy; - object_class->set_arg = et_set_arg; - object_class->get_arg = et_get_arg; - - widget_class->grab_focus = et_grab_focus; - - container_class->focus = et_focus; - - class->cursor_change = NULL; - class->cursor_activated = NULL; - class->selection_change = NULL; - class->double_click = NULL; - class->right_click = NULL; - class->click = NULL; - class->key_press = NULL; - - class->table_drag_begin = NULL; - class->table_drag_end = NULL; - class->table_drag_data_get = NULL; - class->table_drag_data_delete = NULL; - - class->table_drag_leave = NULL; - class->table_drag_motion = NULL; - class->table_drag_drop = NULL; - class->table_drag_data_received = NULL; - - et_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - et_signals [CURSOR_ACTIVATED] = - gtk_signal_new ("cursor_activated", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, cursor_activated), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - et_signals [SELECTION_CHANGE] = - gtk_signal_new ("selection_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, selection_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - et_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, double_click), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - et_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - et_signals [CLICK] = - gtk_signal_new ("click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - et_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - et_signals[TABLE_DRAG_BEGIN] = - gtk_signal_new ("table_drag_begin", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_begin), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - et_signals[TABLE_DRAG_END] = - gtk_signal_new ("table_drag_end", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_end), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - et_signals[TABLE_DRAG_DATA_GET] = - gtk_signal_new ("table_drag_data_get", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_get), - e_marshal_NONE__INT_INT_POINTER_POINTER_UINT_UINT, - GTK_TYPE_NONE, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_SELECTION_DATA, - GTK_TYPE_UINT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DATA_DELETE] = - gtk_signal_new ("table_drag_data_delete", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_delete), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - - et_signals[TABLE_DRAG_LEAVE] = - gtk_signal_new ("table_drag_leave", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_leave), - e_marshal_NONE__INT_INT_POINTER_UINT, - GTK_TYPE_NONE, 4, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_MOTION] = - gtk_signal_new ("table_drag_motion", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_motion), - e_marshal_BOOL__INT_INT_POINTER_INT_INT_UINT, - GTK_TYPE_BOOL, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DROP] = - gtk_signal_new ("table_drag_drop", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_drop), - e_marshal_BOOL__INT_INT_POINTER_INT_INT_UINT, - GTK_TYPE_BOOL, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DATA_RECEIVED] = - gtk_signal_new ("table_drag_data_received", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_received), - e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_UINT_UINT, - GTK_TYPE_NONE, 8, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_SELECTION_DATA, - GTK_TYPE_UINT, - GTK_TYPE_UINT); - - gtk_object_class_add_signals (object_class, et_signals, LAST_SIGNAL); - - class->set_scroll_adjustments = set_scroll_adjustments; - - widget_class->set_scroll_adjustments_signal = - gtk_signal_new ("set_scroll_adjustments", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, set_scroll_adjustments), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); - - gtk_object_add_arg_type ("ETable::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); -} - -E_MAKE_TYPE(e_table, "ETable", ETable, e_table_class_init, e_table_init, PARENT_TYPE); diff --git a/widgets/table/e-table.dia b/widgets/table/e-table.dia Binary files differdeleted file mode 100644 index 5aeb01228c..0000000000 --- a/widgets/table/e-table.dia +++ /dev/null diff --git a/widgets/table/e-table.h b/widgets/table/e-table.h deleted file mode 100644 index b2161dd0ef..0000000000 --- a/widgets/table/e-table.h +++ /dev/null @@ -1,281 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_H_ -#define _E_TABLE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtktable.h> -#include <gnome-xml/tree.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table-header.h> -#include <gal/e-table/e-table-group.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-item.h> -#include <gal/e-table/e-table-selection-model.h> -#include <gal/e-table/e-table-extras.h> -#include <gal/e-table/e-table-specification.h> -#include <gal/widgets/e-printable.h> -#include <gal/e-table/e-table-state.h> - -BEGIN_GNOME_DECLS - -#define E_TABLE_TYPE (e_table_get_type ()) -#define E_TABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_TYPE, ETable)) -#define E_TABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_TYPE, ETableClass)) -#define E_IS_TABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_TYPE)) -#define E_IS_TABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_TYPE)) - -typedef struct _ETableDragSourceSite ETableDragSourceSite; - -typedef enum { - E_TABLE_CURSOR_LOC_NONE = 0, - E_TABLE_CURSOR_LOC_ETCTA = 1 << 0, - E_TABLE_CURSOR_LOC_TABLE = 1 << 1, -} ETableCursorLoc; - -typedef struct { - GtkTable parent; - - ETableModel *model; - - ETableHeader *full_header, *header; - - GnomeCanvasItem *canvas_vbox; - ETableGroup *group; - - ETableSortInfo *sort_info; - ETableSorter *sorter; - - ETableSelectionModel *selection; - ETableCursorLoc cursor_loc; - ETableSpecification *spec; - - int table_model_change_id; - int table_row_change_id; - int table_cell_change_id; - int table_row_inserted_id; - int table_row_deleted_id; - - int group_info_change_id; - - int reflow_idle_id; - - GnomeCanvas *header_canvas, *table_canvas; - - GnomeCanvasItem *header_item, *root; - - GnomeCanvasItem *white_item; - - gint length_threshold; - - gint rebuild_idle_id; - guint need_rebuild:1; - - /* - * Configuration settings - */ - guint draw_grid : 1; - guint draw_focus : 1; - guint row_selection_active : 1; - - guint horizontal_scrolling : 1; - - char *click_to_add_message; - GnomeCanvasItem *click_to_add; - gboolean use_click_to_add; - - ETableCursorMode cursor_mode; - - int drag_get_data_row; - int drag_get_data_col; - - int drop_row; - int drop_col; - - int drag_row; - int drag_col; - ETableDragSourceSite *site; - - int drag_source_button_press_event_id; - int drag_source_motion_notify_event_id; -} ETable; - -typedef struct { - GtkTableClass parent_class; - - void (*cursor_change) (ETable *et, int row); - void (*cursor_activated) (ETable *et, int row); - void (*selection_change) (ETable *et); - void (*double_click) (ETable *et, int row, int col, GdkEvent *event); - gint (*right_click) (ETable *et, int row, int col, GdkEvent *event); - gint (*click) (ETable *et, int row, int col, GdkEvent *event); - gint (*key_press) (ETable *et, int row, int col, GdkEvent *event); - - void (*set_scroll_adjustments) (ETable *table, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - - /* Source side drag signals */ - void (* table_drag_begin) (ETable *table, - int row, - int col, - GdkDragContext *context); - void (* table_drag_end) (ETable *table, - int row, - int col, - GdkDragContext *context); - void (* table_drag_data_get) (ETable *table, - int row, - int col, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time); - void (* table_drag_data_delete) (ETable *table, - int row, - int col, - GdkDragContext *context); - - /* Target side drag signals */ - void (* table_drag_leave) (ETable *table, - int row, - int col, - GdkDragContext *context, - guint time); - gboolean (* table_drag_motion) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - guint time); - gboolean (* table_drag_drop) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - guint time); - void (* table_drag_data_received) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time); -} ETableClass; - -GtkType e_table_get_type (void); - -ETable *e_table_construct (ETable *e_table, - ETableModel *etm, - ETableExtras *ete, - const char *spec, - const char *state); -GtkWidget *e_table_new (ETableModel *etm, - ETableExtras *ete, - const char *spec, - const char *state); - -/* Create an ETable using files. */ -ETable *e_table_construct_from_spec_file (ETable *e_table, - ETableModel *etm, - ETableExtras *ete, - const char *spec_fn, - const char *state_fn); -GtkWidget *e_table_new_from_spec_file (ETableModel *etm, - ETableExtras *ete, - const char *spec_fn, - const char *state_fn); - -/* To save the state */ -gchar *e_table_get_state (ETable *e_table); -void e_table_save_state (ETable *e_table, - const gchar *filename); -ETableState *e_table_get_state_object (ETable *e_table); - -/* note that it is more efficient to provide the state at creation time */ -void e_table_set_state (ETable *e_table, - const gchar *state); -void e_table_set_state_object (ETable *e_table, - ETableState *state); -void e_table_load_state (ETable *e_table, - const gchar *filename); - -void e_table_set_cursor_row (ETable *e_table, - int row); - -/* -1 means we don't have the cursor. */ -int e_table_get_cursor_row (ETable *e_table); -void e_table_selected_row_foreach (ETable *e_table, - ETableForeachFunc callback, - gpointer closure); -gint e_table_selected_count (ETable *e_table); -EPrintable *e_table_get_printable (ETable *e_table); - -gint e_table_get_next_row (ETable *e_table, - gint model_row); -gint e_table_get_prev_row (ETable *e_table, - gint model_row); - -gint e_table_model_to_view_row (ETable *e_table, - gint model_row); -gint e_table_view_to_model_row (ETable *e_table, - gint view_row); - - -/* Drag & drop stuff. */ -/* Target */ -void e_table_drag_get_data (ETable *table, - int row, - int col, - GdkDragContext *context, - GdkAtom target, - guint32 time); -void e_table_drag_highlight (ETable *table, - int row, - int col); /* col == -1 to highlight entire row. */ -void e_table_drag_unhighlight (ETable *table); -void e_table_drag_dest_set (ETable *table, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions); -void e_table_drag_dest_set_proxy (ETable *table, - GdkWindow *proxy_window, - GdkDragProtocol protocol, - gboolean use_coordinates); - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ -void e_table_drag_dest_unset (GtkWidget *widget); - -/* Source side */ -void e_table_drag_source_set (ETable *table, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions); -void e_table_drag_source_unset (ETable *table); - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ -GdkDragContext *e_table_drag_begin (ETable *table, - int row, - int col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event); - -/* selection stuff */ -void e_table_select_all (ETable *table); -void e_table_invert_selection (ETable *table); - -END_GNOME_DECLS - -#endif /* _E_TABLE_H_ */ - diff --git a/widgets/table/e-tree-model.c b/widgets/table/e-tree-model.c deleted file mode 100644 index a8c0b2e0d6..0000000000 --- a/widgets/table/e-tree-model.c +++ /dev/null @@ -1,1740 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-tree-model.c: a Tree Model - * - * Author: - * Chris Toshok (toshok@ximian.com) - * - * Adapted from the gtree code and ETableModel. - * - * (C) 2000 Ximian, Inc. - */ -#include <config.h> - -#include <stdio.h> -#include <errno.h> -#include <unistd.h> -#include <fcntl.h> - -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> - -#include <gtk/gtksignal.h> -#include <stdlib.h> -#include "gal/util/e-util.h" -#include "gal/util/e-xml-utils.h" -#include "e-tree-model.h" - -#define ETM_CLASS(e) ((ETreeModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE E_TABLE_MODEL_TYPE - -#define TREEPATH_CHUNK_AREA_SIZE (30 * sizeof (ETreePath)) - -static ETableModel *e_tree_model_parent_class; - -struct ETreeModelPriv { - GMemChunk *node_chunk; - ETreePath *root; - gboolean root_visible; - GArray *row_array; /* used in the mapping between ETable and our tree */ - GHashTable *expanded_state; /* used for loading/saving expanded state */ - GString *sort_group; /* for caching the last sort group info */ - gboolean expanded_default; /* whether nodes are created expanded or collapsed by default */ - gint frozen; -}; - -struct ETreePath { - gboolean expanded; - gboolean expanded_set; - guint visible_descendents; - char *save_id; - ETreePathCompareFunc compare; - gpointer node_data; - - /* parent/child/sibling pointers */ - ETreePath *parent; - ETreePath *next_sibling; - ETreePath *prev_sibling; - ETreePath *first_child; - ETreePath *last_child; - guint32 num_children; -}; - -enum { - NODE_CHANGED, - NODE_INSERTED, - NODE_REMOVED, - NODE_COLLAPSED, - NODE_EXPANDED, - LAST_SIGNAL -}; - -static guint e_tree_model_signals [LAST_SIGNAL] = {0, }; - -static void add_visible_descendents_to_array (ETreeModel *etm, ETreePath *node, int *row, int *count); - - -/* ETreePath functions */ - -static int -e_tree_path_depth (ETreePath *path) -{ - int depth = 0; - while (path) { - depth ++; - path = path->parent; - } - return depth; -} - -static void -e_tree_path_insert (ETreePath *parent, int position, ETreePath *child) -{ - g_return_if_fail (position <= parent->num_children || position == -1); - - child->parent = parent; - - if (parent->first_child == NULL) - parent->first_child = child; - - if (position == -1 || position == parent->num_children) { - child->prev_sibling = parent->last_child; - if (parent->last_child) - parent->last_child->next_sibling = child; - parent->last_child = child; - } - else { - ETreePath *c; - for (c = parent->first_child; c; c = c->next_sibling) { - if (position == 0) { - child->next_sibling = c; - child->prev_sibling = c->prev_sibling; - - if (child->next_sibling) - child->next_sibling->prev_sibling = child; - if (child->prev_sibling) - child->prev_sibling->next_sibling = child; - - if (parent->first_child == c) - parent->first_child = child; - break; - } - position --; - } - } - - parent->num_children++; -} - -static void -e_tree_path_unlink (ETreePath *path) -{ - ETreePath *parent = path->parent; - - /* unlink first/last child if applicable */ - if (parent) { - if (path == parent->first_child) - parent->first_child = path->next_sibling; - if (path == parent->last_child) - parent->last_child = path->prev_sibling; - - parent->num_children --; - } - - /* unlink prev/next sibling links */ - if (path->next_sibling) - path->next_sibling->prev_sibling = path->prev_sibling; - if (path->prev_sibling) - path->prev_sibling->next_sibling = path->next_sibling; - - path->parent = NULL; - path->next_sibling = NULL; - path->prev_sibling = NULL; -} - -/** - * e_tree_model_node_traverse: - * @model: - * @path: - * @func: - * @data: - * - * - **/ -void -e_tree_model_node_traverse (ETreeModel *model, ETreePath *path, ETreePathFunc func, gpointer data) -{ - ETreePath *child; - - g_return_if_fail (path); - - child = path->first_child; - - while (child) { - ETreePath *next_child = child->next_sibling; - e_tree_model_node_traverse (model, child, func, data); - if (func (model, child, data) == TRUE) - return; - - child = next_child; - } -} - - - -/** - * e_tree_model_freeze: - * @etm: the ETreeModel to freeze. - * - * This function prepares an ETreeModel for a period of much change. - * All signals regarding changes to the tree are deferred until we - * thaw the tree. - * - **/ -void -e_tree_model_freeze(ETreeModel *etm) -{ - ETreeModelPriv *priv = etm->priv; - - priv->frozen ++; -} - -/** - * e_tree_model_thaw: - * @etm: the ETreeModel to thaw. - * - * This function thaws an ETreeModel. All the defered signals can add - * up to a lot, we don't know - so we just emit a model_changed - * signal. - * - **/ -void -e_tree_model_thaw(ETreeModel *etm) -{ - ETreeModelPriv *priv = etm->priv; - - if (priv->frozen > 0) - priv->frozen --; - if (priv->frozen == 0) { - e_table_model_changed(E_TABLE_MODEL(etm)); - } -} - - -/* virtual methods */ - -static void -etree_destroy (GtkObject *object) -{ - ETreeModel *etree = E_TREE_MODEL (object); - ETreeModelPriv *priv = etree->priv; - - /* XXX lots of stuff to free here */ - - if (priv->root) - e_tree_model_node_remove (etree, priv->root); - - g_array_free (priv->row_array, TRUE); - g_hash_table_destroy (priv->expanded_state); - - g_string_free(priv->sort_group, TRUE); - - g_free (priv); - - GTK_OBJECT_CLASS (e_tree_model_parent_class)->destroy (object); -} - -static ETreePath* -etree_get_root (ETreeModel *etm) -{ - ETreeModelPriv *priv = etm->priv; - return priv->root; -} - -static ETreePath* -etree_get_parent (ETreeModel *etm, ETreePath *path) -{ - g_return_val_if_fail (path, NULL); - - return path->parent; -} - -static ETreePath* -etree_get_next (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return node->next_sibling; -} - -static ETreePath* -etree_get_prev (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return node->prev_sibling; -} - -static ETreePath* -etree_get_first_child (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return node->first_child; -} - -static ETreePath* -etree_get_last_child (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return node->last_child; -} - -static guint -etree_get_children (ETreeModel *etm, ETreePath* node, ETreePath ***paths) -{ - guint n_children; - - g_return_val_if_fail (node, 0); - - n_children = node->num_children; - - if (paths) { - ETreePath *p; - int i = 0; - (*paths) = g_malloc (sizeof (ETreePath*) * n_children); - for (p = node->first_child; p; p = p->next_sibling) { - (*paths)[i++] = p; - } - } - - return n_children; -} - -static gboolean -etree_is_expanded (ETreeModel *etm, ETreePath* node) -{ - g_return_val_if_fail (node, FALSE); - - return node->expanded; -} - -static gboolean -etree_is_visible (ETreeModel *etm, ETreePath* node) -{ - g_return_val_if_fail (node, FALSE); - - for (node = node->parent; node; node = node->parent) { - if (!node->expanded) - return FALSE; - } - - return TRUE; -} - -static void -etree_set_expanded (ETreeModel *etm, ETreePath* node, gboolean expanded) -{ - ETreeModelPriv *priv = etm->priv; - ETreePath *child; - int row; - - g_return_if_fail (node); - - node->expanded_set = TRUE; - - if (node->expanded == expanded) - return; - - if (expanded) { - gboolean allow_expand = TRUE; - e_tree_model_node_expanded (etm, node, &allow_expand); - if (!allow_expand) - return; - } - - node->expanded = expanded; - if (node->save_id) { - g_hash_table_insert (priv->expanded_state, node->save_id, (gpointer)expanded); - } - - /* if the node wasn't visible at present */ - if ((row = e_tree_model_row_of_node (etm, node)) == -1) { - if (!expanded) { - e_tree_model_node_collapsed (etm, node); - } - return; - } - - row++; - - if (expanded) { - ETreePath *parent; - - if (e_tree_model_node_is_visible (etm, node)) { - node->visible_descendents = 0; - for (child = node->first_child; child; - child = child->next_sibling) { - add_visible_descendents_to_array (etm, child, &row, &node->visible_descendents); - } - } - /* now iterate back up the tree, adding to our - ancestors' visible descendents */ - - for (parent = node->parent; parent; parent = parent->parent) { - parent->visible_descendents += node->visible_descendents; - } - } - else { - int i; - ETreePath *parent; - - if (e_tree_model_node_is_visible (etm, node)) { - for (i = 0; i < node->visible_descendents; i ++) { - priv->row_array = g_array_remove_index (priv->row_array, row); - e_table_model_row_deleted (E_TABLE_MODEL (etm), row); - } - } - /* now iterate back up the tree, subtracting from our - ancestors' visible descendents */ - - for (parent = node->parent; parent; parent = parent->parent) { - parent->visible_descendents -= node->visible_descendents; - } - - node->visible_descendents = 0; - - e_tree_model_node_collapsed (etm, node); - } -} - -/** - * e_tree_model_set_expanded_default: - * @etree: The ETreeModel we're setting the default expanded behavior on. - * @expanded: Whether or not newly inserted parent nodes should be expanded by default. - * - * - **/ -void -e_tree_model_show_node (ETreeModel *etm, ETreePath* node) -{ - ETreePath *parent; - - parent = e_tree_model_node_get_parent(etm, node); - if (parent) { - e_tree_model_show_node(etm, parent); - e_tree_model_node_set_expanded(etm, parent, TRUE); - } -} - -void -e_tree_model_set_expanded_default (ETreeModel *etree, - gboolean expanded) -{ - ETreeModelPriv *priv = etree->priv; - - priv->expanded_default = expanded; -} - -/* fairly naive implementation */ -static void -etree_set_expanded_recurse (ETreeModel *etm, ETreePath* node, gboolean expanded) -{ - ETreePath *child; - - e_tree_model_node_set_expanded (etm, node, expanded); - - for (child = node->first_child; child; child = child->next_sibling) - e_tree_model_node_set_expanded_recurse (etm, child, expanded); -} - -static ETreePath * -etree_node_at_row (ETreeModel *etree, int row) -{ - ETreeModelPriv *priv = etree->priv; - - g_return_val_if_fail (row < priv->row_array->len, NULL); - - return g_array_index (priv->row_array, ETreePath*, row); -} - - -/* ETable analogs */ -static void* -etree_value_at (ETreeModel *etm, ETreePath* node, int col) -{ - /* shouldn't be called */ - g_assert (0); - return NULL; -} - -static GdkPixbuf* -etree_icon_at (ETreeModel *etm, ETreePath* node) -{ - /* shouldn't be called */ - g_assert (0); - return NULL; -} - -static void -etree_set_value_at (ETreeModel *etm, ETreePath* node, int col, const void *val) -{ - /* shouldn't be called */ - g_assert (0); -} - -static gboolean -etree_is_editable (ETreeModel *etm, ETreePath* node, int col) -{ - /* shouldn't be called */ - g_assert(0); - return FALSE; -} - - -/* ETable virtual functions we map */ -static int -etable_row_count (ETableModel *etm) -{ - ETreeModel *tree = E_TREE_MODEL (etm); - ETreeModelPriv *priv = tree->priv; - return priv->row_array->len; -} - -static void * -etable_value_at (ETableModel *etm, int col, int row) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_val_if_fail (node, NULL); - - if (col == -1) - return node; - else if (col == -2) - return etm; - else - return et_class->value_at (etree, node, col); -} - -static void -etable_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_if_fail (node); - - et_class->set_value_at (etree, node, col, val); -} - -static gboolean -etable_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_val_if_fail (node, FALSE); - - return et_class->is_editable (etree, node, col); -} - -static void -build_sort_group(GString *out, ETreePath *node) -{ - if (node->parent) { - build_sort_group(out, node->parent); - } - g_string_sprintfa(out, "/%p", node); -} - -static const char * -etable_row_sort_group(ETableModel *etm, int row) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelPriv *priv = etree->priv; - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_val_if_fail (node, ""); - - g_string_truncate(priv->sort_group, 0); - if (node) - build_sort_group(priv->sort_group, node); - - return priv->sort_group->str; -} - -static gboolean -etable_has_sort_group(ETableModel *etm) -{ - /* could optimise for the flat &/or unexpanded tree case */ - return TRUE; -} - - -static void -e_tree_model_class_init (GtkObjectClass *klass) -{ - ETableModelClass *table_class = (ETableModelClass *) klass; - ETreeModelClass *tree_class = (ETreeModelClass *) klass; - - e_tree_model_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etree_destroy; - - e_tree_model_signals [NODE_CHANGED] = - gtk_signal_new ("node_changed", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_changed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - - e_tree_model_signals [NODE_INSERTED] = - gtk_signal_new ("node_inserted", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_inserted), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); - - e_tree_model_signals [NODE_REMOVED] = - gtk_signal_new ("node_removed", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_removed), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); - - e_tree_model_signals [NODE_COLLAPSED] = - gtk_signal_new ("node_collapsed", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_collapsed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - - e_tree_model_signals [NODE_EXPANDED] = - gtk_signal_new ("node_expanded", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_expanded), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (klass, e_tree_model_signals, LAST_SIGNAL); - - table_class->row_count = etable_row_count; - table_class->value_at = etable_value_at; - table_class->set_value_at = etable_set_value_at; - table_class->is_cell_editable = etable_is_cell_editable; -#if 0 - /* XX need to pass these through */ - table_class->duplicate_value = etable_duplicate_value; - table_class->free_value = etable_free_value; - table_class->initialize_value = etable_initialize_value; - table_class->value_is_empty = etable_value_is_empty; - table_class->value_to_string = etable_value_to_string; - table_class->thaw = etable_thaw; -#endif - - table_class->row_sort_group = etable_row_sort_group; - table_class->has_sort_group = etable_has_sort_group; - - tree_class->get_root = etree_get_root; - tree_class->get_prev = etree_get_prev; - tree_class->get_next = etree_get_next; - tree_class->get_first_child = etree_get_first_child; - tree_class->get_last_child = etree_get_last_child; - tree_class->get_parent = etree_get_parent; - - tree_class->value_at = etree_value_at; - tree_class->icon_at = etree_icon_at; - tree_class->set_value_at = etree_set_value_at; - tree_class->is_editable = etree_is_editable; - - tree_class->get_children = etree_get_children; - tree_class->is_expanded = etree_is_expanded; - tree_class->is_visible = etree_is_visible; - tree_class->set_expanded = etree_set_expanded; - tree_class->set_expanded_recurse = etree_set_expanded_recurse; - tree_class->node_at_row = etree_node_at_row; -} - -static void -e_tree_init (GtkObject *object) -{ - ETreeModel *etree = (ETreeModel *)object; - e_tree_model_construct (etree); -} - -E_MAKE_TYPE(e_tree_model, "ETreeModel", ETreeModel, e_tree_model_class_init, e_tree_init, PARENT_TYPE) - - -/* signals */ - -/** - * e_tree_model_node_changed: - * @tree_model: - * @node: - * - * - * - * Return value: - **/ -void -e_tree_model_node_changed (ETreeModel *tree_model, ETreePath *node) -{ - int row; - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - row = e_tree_model_row_of_node (tree_model, node); - if (row != -1) - e_table_model_row_changed (E_TABLE_MODEL (tree_model), row); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_CHANGED], node); -} - -/** - * e_tree_model_node_inserted: - * @tree_model: - * @parent_node: - * @inserted_node: - * - * - **/ -void -e_tree_model_node_inserted (ETreeModel *tree_model, - ETreePath *parent_node, - ETreePath *inserted_node) -{ - int row; - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - row = e_tree_model_row_of_node (tree_model, inserted_node); - if (row != -1) - e_table_model_row_inserted (E_TABLE_MODEL (tree_model), row); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_INSERTED], - parent_node, inserted_node); -} - -/** - * e_tree_model_node_removed: - * @tree_model: - * @parent_node: - * @removed_node: - * - * - **/ -void -e_tree_model_node_removed (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *removed_node) -{ - int row; - - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - row = e_tree_model_row_of_node (tree_model, removed_node); - if (row != -1) - e_table_model_row_deleted (E_TABLE_MODEL (tree_model), row); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_REMOVED], - parent_node, removed_node); -} - -/** - * e_tree_model_node_collapsed: - * @tree_model: - * @node: - * - * - **/ -void -e_tree_model_node_collapsed (ETreeModel *tree_model, ETreePath *node) -{ - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_COLLAPSED], - node); -} - -/** - * e_tree_model_node_expanded: - * @tree_model: - * @node: - * @allow_expand: - * - * - **/ -void -e_tree_model_node_expanded (ETreeModel *tree_model, ETreePath *node, gboolean *allow_expand) -{ - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_EXPANDED], - node, allow_expand); -} - - - -/** - * e_tree_model_construct: - * @etree: - * - * - **/ -void -e_tree_model_construct (ETreeModel *etree) -{ - ETreeModelPriv *priv = g_new0 (ETreeModelPriv, 1); - - etree->priv = priv; - - priv->node_chunk = g_mem_chunk_create (ETreePath, TREEPATH_CHUNK_AREA_SIZE, G_ALLOC_AND_FREE); - priv->root = NULL; - priv->root_visible = TRUE; - priv->row_array = g_array_new (FALSE, FALSE, sizeof(ETreePath*)); - priv->expanded_state = g_hash_table_new (g_str_hash, g_str_equal); - priv->sort_group = g_string_new(""); - priv->frozen = 0; -} - -/** - * e_tree_model_new - * - * XXX docs here. - * - * return values: a newly constructed ETreeModel. - */ -ETreeModel * -e_tree_model_new () -{ - ETreeModel *et; - - et = gtk_type_new (e_tree_model_get_type ()); - - return et; -} - -/** - * e_tree_model_get_root - * @etree: the ETreeModel of which we want the root node. - * - * Accessor for the root node of @etree. - * - * return values: the ETreePath corresponding to the root node. - */ -ETreePath * -e_tree_model_get_root (ETreeModel *etree) -{ - return ETM_CLASS(etree)->get_root(etree); -} - -/** - * e_tree_model_node_at_row - * @etree: the ETreeModel. - * @row: - * - * XXX docs here. - * - * return values: the ETreePath corresponding to @row. - */ -ETreePath * -e_tree_model_node_at_row (ETreeModel *etree, int row) -{ - return ETM_CLASS(etree)->node_at_row (etree, row); -} - -/** - * e_tree_model_icon_of_node - * @etree: The ETreeModel. - * @path: The ETreePath to the node we're getting the icon of. - * - * XXX docs here. - * - * return values: the GdkPixbuf associated with this node. - */ -GdkPixbuf * -e_tree_model_icon_of_node (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->icon_at (etree, path); -} - -/** - * e_tree_model_row_of_node - * @etree: The ETreeModel. - * @node: The node whose row we're looking up. - * - * return values: an int. - */ -int -e_tree_model_row_of_node (ETreeModel *etree, ETreePath *node) -{ - ETreeModelPriv *priv = etree->priv; - int i; - - for (i = 0; i < priv->row_array->len; i ++) - if (g_array_index (priv->row_array, ETreePath*, i) == node) - return i; - - return -1; -} - -/** - * e_tree_model_root_node_set_visible - * - * return values: none - */ -void -e_tree_model_root_node_set_visible (ETreeModel *etm, gboolean visible) -{ - ETreeModelPriv *priv = etm->priv; - - if (visible != priv->root_visible) { - priv->root_visible = visible; - if (priv->root) { - if (visible) { - priv->row_array = g_array_insert_val (priv->row_array, 0, priv->root); - } - else { - ETreePath *root_path = e_tree_model_get_root (etm); - e_tree_model_node_set_expanded (etm, root_path, TRUE); - priv->row_array = g_array_remove_index (priv->row_array, 0); - } - - e_table_model_changed (E_TABLE_MODEL (etm)); - } - } -} - -/** - * e_tree_model_root_node_is_visible: - * @etm: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_root_node_is_visible (ETreeModel *etm) -{ - ETreeModelPriv *priv = etm->priv; - return priv->root_visible; -} - -/** - * e_tree_model_node_get_first_child: - * @etree: - * @node: - * - * - * - * Return value: - **/ -ETreePath * -e_tree_model_node_get_first_child (ETreeModel *etree, ETreePath *node) -{ - return ETM_CLASS(etree)->get_first_child(etree, node); -} - -/** - * e_tree_model_node_get_last_child: - * @etree: - * @node: - * - * - * - * Return value: - **/ -ETreePath * -e_tree_model_node_get_last_child (ETreeModel *etree, ETreePath *node) -{ - return ETM_CLASS(etree)->get_last_child(etree, node); -} - - -/** - * e_tree_model_node_get_next: - * @etree: - * @node: - * - * - * - * Return value: - **/ -ETreePath * -e_tree_model_node_get_next (ETreeModel *etree, ETreePath *node) -{ - return ETM_CLASS(etree)->get_next(etree, node); -} - -/** - * e_tree_model_node_get_prev: - * @etree: - * @node: - * - * - * - * Return value: - **/ -ETreePath * -e_tree_model_node_get_prev (ETreeModel *etree, ETreePath *node) -{ - return ETM_CLASS(etree)->get_prev(etree, node); -} - -/** - * e_tree_model_node_depth: - * @etree: - * @path: - * - * - * - * Return value: - **/ -guint -e_tree_model_node_depth (ETreeModel *etree, ETreePath *path) -{ - return e_tree_path_depth (path) - 1; -} - -/** - * e_tree_model_node_get_parent: - * @etree: - * @path: - * - * - * - * Return value: - **/ -ETreePath * -e_tree_model_node_get_parent (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->get_parent(etree, path); -} - -/** - * e_tree_model_node_is_root: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_node_is_root (ETreeModel *etree, ETreePath *path) -{ - return (e_tree_model_node_depth (etree, path) == 0); -} - -/** - * e_tree_model_node_is_expandable: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_node_is_expandable (ETreeModel *etree, ETreePath *path) -{ - return (e_tree_model_node_get_children (etree, path, NULL) > 0); -} - -/** - * e_tree_model_node_is_expanded: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_node_is_expanded (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->is_expanded (etree, path); -} - -/** - * e_tree_model_node_is_visible: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_node_is_visible (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->is_visible (etree, path); -} - -/** - * e_tree_model_node_set_expanded: - * @etree: - * @path: - * @expanded: - * - * - **/ -void -e_tree_model_node_set_expanded (ETreeModel *etree, ETreePath *path, gboolean expanded) -{ - ETM_CLASS(etree)->set_expanded (etree, path, expanded); -} - -/** - * e_tree_model_node_set_expanded_recurse: - * @etree: - * @path: - * @expanded: - * - * - **/ -void -e_tree_model_node_set_expanded_recurse (ETreeModel *etree, ETreePath *path, gboolean expanded) -{ - ETM_CLASS(etree)->set_expanded_recurse (etree, path, expanded); -} - -guint -e_tree_model_node_get_children (ETreeModel *etree, ETreePath *path, ETreePath ***paths) -{ - return ETM_CLASS(etree)->get_children (etree, path, paths); -} - -/** - * e_tree_model_node_num_visible_descendents: - * @etm: - * @node: - * - * - * - * Return value: - **/ -guint -e_tree_model_node_num_visible_descendents (ETreeModel *etm, ETreePath *node) -{ - return node->visible_descendents; -} - -/** - * e_tree_model_node_get_data: - * @etm: - * @node: - * - * - * - * Return value: - **/ -gpointer -e_tree_model_node_get_data (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return node->node_data; -} - -/** - * e_tree_model_node_set_data: - * @etm: - * @node: - * @node_data: - * - * - **/ -void -e_tree_model_node_set_data (ETreeModel *etm, ETreePath *node, gpointer node_data) -{ - g_return_if_fail (node); - - node->node_data = node_data; -} - -/** - * e_tree_model_node_insert: - * @tree_model: - * @parent_path: - * @position: - * @node_data: - * - * - * - * Return value: - **/ -ETreePath* -e_tree_model_node_insert (ETreeModel *tree_model, - ETreePath *parent_path, - int position, - gpointer node_data) -{ - ETreeModelPriv *priv; - ETreePath *new_path; - - priv = tree_model->priv; - - g_return_val_if_fail (parent_path != NULL || priv->root == NULL, NULL); - - priv = tree_model->priv; - - new_path = g_chunk_new0 (ETreePath, priv->node_chunk); - - new_path->expanded = FALSE; - new_path->node_data = node_data; - - if (parent_path != NULL) { - - if (parent_path->first_child == NULL - && !parent_path->expanded_set) { - e_tree_model_node_set_expanded (tree_model, - parent_path, - priv->expanded_default); - } - - e_tree_path_insert (parent_path, position, new_path); - - if (e_tree_model_node_is_visible (tree_model, new_path)) { - int parent_row, child_offset = 0; - ETreePath *n; - - /* we need to iterate back up to the root, incrementing the number of visible - descendents */ - for (n = parent_path; n; n = n->parent) { - n->visible_descendents ++; - } - - /* determine if we are inserting at the end of this parent */ - if (position == -1 || position == parent_path->num_children) { - position = e_tree_model_node_num_visible_descendents (tree_model, parent_path) - 1; - } else { - /* if we're not inserting at the end of the array, position is the child node we're - inserting at, not the absolute row position - need to count expanded nodes before it too */ - int i = position; - - n = e_tree_model_node_get_first_child(tree_model, parent_path); - while (n != NULL && i > 0) { - child_offset += n->visible_descendents; - n = n->next_sibling; - i--; - } - } - - - /* if the parent is the root, no need to search for its position since it aint there */ - if (parent_path->parent == NULL) { - parent_row = -1; - } else { - parent_row = e_tree_model_row_of_node (tree_model, parent_path); - } - - e_table_model_pre_change(E_TABLE_MODEL(tree_model)); - - priv->row_array = g_array_insert_val (priv->row_array, - parent_row + position + 1 + child_offset, new_path); - - /* only do this if we know a changed signal isn't coming later on */ - if (priv->frozen == 0) - e_table_model_row_inserted (E_TABLE_MODEL(tree_model), parent_row + position + 1 + child_offset); - } - - if (parent_path->compare) - e_tree_model_node_sort (tree_model, parent_path); - } - else { - priv->root = new_path; - if (priv->root_visible) { - priv->row_array = g_array_insert_val (priv->row_array, 0, priv->root); - e_table_model_row_inserted (E_TABLE_MODEL (tree_model), 0); - } - else { - /* need to mark the new node as expanded or - we'll never see it's children */ - new_path->expanded = TRUE; - new_path->expanded_set = TRUE; - } - } - - return new_path; -} - -/** - * e_tree_model_node_insert_id: - * @tree_model: - * @parent_path: - * @position: - * @node_data: - * @save_id: - * - * - * - * Return value: - **/ -ETreePath* -e_tree_model_node_insert_id (ETreeModel *tree_model, - ETreePath *parent_path, - int position, - gpointer node_data, - const char *save_id) -{ - ETreePath *path = e_tree_model_node_insert (tree_model, parent_path, position, node_data); - - e_tree_model_node_set_save_id (tree_model, path, save_id); - - return path; -} - -/** - * e_tree_model_node_insert_before: - * @etree: - * @parent: - * @sibling: - * @node_data: - * - * - * - * Return value: - **/ -ETreePath * -e_tree_model_node_insert_before (ETreeModel *etree, - ETreePath *parent, - ETreePath *sibling, - gpointer node_data) -{ - ETreePath *child; - int position = 0; - for (child = parent->first_child; child; child = child->next_sibling) { - if (child == sibling) - break; - position ++; - } - return e_tree_model_node_insert (etree, parent, position, node_data); -} - -/* just blows away child data, doesn't take into account unlinking/etc */ -static void -child_free(ETreeModel *etree, ETreePath *node) -{ - ETreePath *child, *next; - ETreeModelPriv *priv = etree->priv; - - child = node->first_child; - while (child) { - next = child->next_sibling; - child_free(etree, child); - child = next; - } - - if (node->save_id) { - g_hash_table_remove(priv->expanded_state, node->save_id); - g_free(node->save_id); - } - g_chunk_free(node, priv->node_chunk); -} - -/** - * e_tree_model_node_remove: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gpointer -e_tree_model_node_remove (ETreeModel *etree, ETreePath *path) -{ - ETreeModelPriv *priv = etree->priv; - ETreePath *parent = path->parent; - gpointer ret = path->node_data; - int row, visible = 0, base = 0; - gboolean dochanged; - - /* work out what range of visible rows to remove */ - if (parent) { - if (e_tree_model_node_is_visible(etree, path)) { - base = e_tree_model_row_of_node(etree, path); - visible = path->visible_descendents + 1; - } - } else if (path == priv->root) { - priv->root = NULL; - if (priv->root_visible) { - base = 0; - visible = path->visible_descendents + 1; - } else { - base = 0; - visible = path->visible_descendents; - } - } else { - g_warning("Trying to remove invalid path %p", path); - return NULL; - } - - /* unlink this node - we only have to unlink the root node being removed, - since the others are only references from this node */ - e_tree_path_unlink (path); - - /*printf("removing %d nodes from position %d\n", visible, base);*/ - - if (visible > 0) { - /* fix up the parent visible counts */ - for (; parent; parent = parent->parent) { - parent->visible_descendents -= visible; - } - - /* if we have a lot of nodes to remove, then we dont row_deleted each one */ - /* could probably be tuned, but this'll do, since its normally only when we - remove the whole lot do we really care */ - dochanged = (visible > 1000) || (visible > (priv->row_array->len / 4)); - - e_table_model_pre_change(E_TABLE_MODEL (etree)); - - /* and physically remove them */ - if (visible == priv->row_array->len) { - g_array_set_size(priv->row_array, 0); - } else { - memmove(&g_array_index(priv->row_array, ETreePath *, base), - &g_array_index(priv->row_array, ETreePath *, base+visible), - (priv->row_array->len - (base+visible)) * sizeof(ETreePath *)); - g_array_set_size(priv->row_array, priv->row_array->len - visible); - } - - /* tell the system we've removed (these) nodes */ - if (priv->frozen == 0) { - if (dochanged) { - e_table_model_changed(E_TABLE_MODEL(etree)); - } else { - for (row=visible-1;row>=0;row--) { - e_table_model_row_deleted(E_TABLE_MODEL(etree), row+base); - } - } - } - } - - child_free(etree, path); - - return ret; -} - -static void -add_visible_descendents_to_array (ETreeModel *etm, ETreePath *node, int *row, int *count) -{ - ETreeModelPriv *priv = etm->priv; - - /* add a row for this node */ - e_table_model_pre_change(E_TABLE_MODEL (etm)); - priv->row_array = g_array_insert_val (priv->row_array, (*row), node); - if (priv->frozen == 0) - e_table_model_row_inserted (E_TABLE_MODEL (etm), (*row)); - (*row) ++; - (*count) ++; - - /* then loop over its children, calling this routine for each - of them */ - if (node->expanded) { - ETreePath *child; - for (child = node->first_child; child; - child = child->next_sibling) { - add_visible_descendents_to_array (etm, child, row, count); - } - } -} - -static void -save_expanded_state_func (char *key, gboolean expanded, gpointer user_data) -{ - if (expanded) { - xmlNode *root = (xmlNode*)user_data; - xmlNode *node_root = xmlNewNode (NULL, (xmlChar*) "node"); - - xmlAddChild (root, node_root); - xmlNewChild (node_root, NULL, (xmlChar *) "id", (xmlChar*) key); - } -} - -/** - * e_tree_model_save_expanded_state: - * @etm: - * @filename: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_save_expanded_state (ETreeModel *etm, const char *filename) -{ - xmlDoc *doc; - xmlNode *root; - int fd, rv; - xmlChar *buf; - int buf_size; - ETreeModelPriv *priv = etm->priv; - - doc = xmlNewDoc ((xmlChar*) "1.0"); - root = xmlNewDocNode (doc, NULL, - (xmlChar *) "expanded_state", - NULL); - xmlDocSetRootElement (doc, root); - - g_hash_table_foreach (priv->expanded_state, - (GHFunc)save_expanded_state_func, - root); - - fd = open (filename, O_CREAT | O_TRUNC | O_WRONLY, 0777); - - xmlDocDumpMemory (doc, &buf, &buf_size); - - if (buf == NULL) { - g_error ("Failed to write %s: xmlBufferCreate() == NULL", filename); - return FALSE; - } - - rv = write (fd, buf, buf_size); - xmlFree (buf); - close (fd); - - if (0 > rv) { - g_error ("Failed to write new %s: %d\n", filename, errno); - unlink (filename); - return FALSE; - } - - return TRUE; -} - -static char * -get_string_value (xmlNode *node, - const char *name) -{ - xmlNode *p; - xmlChar *xml_string; - char *retval; - - p = e_xml_get_child_by_name (node, (xmlChar *) name); - if (p == NULL) - return NULL; - - p = e_xml_get_child_by_name (p, (xmlChar *) "text"); - if (p == NULL) /* there's no text between the tags, return the empty string */ - return g_strdup(""); - - xml_string = xmlNodeListGetString (node->doc, p, 1); - retval = g_strdup ((char *) xml_string); - xmlFree (xml_string); - - return retval; -} - -/** - * e_tree_model_load_expanded_state: - * @etm: - * @filename: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_load_expanded_state (ETreeModel *etm, const char *filename) -{ - ETreeModelPriv *priv = etm->priv; - xmlDoc *doc; - xmlNode *root; - xmlNode *child; - - doc = xmlParseFile (filename); - if (!doc) - return FALSE; - - root = xmlDocGetRootElement (doc); - if (root == NULL || strcmp (root->name, "expanded_state")) { - xmlFreeDoc (doc); - return FALSE; - } - - for (child = root->childs; child; child = child->next) { - char *id; - - if (strcmp (child->name, "node")) { - g_warning ("unknown node '%s' in %s", child->name, filename); - continue; - } - - id = get_string_value (child, "id"); - - g_hash_table_insert (priv->expanded_state, id, (gpointer)TRUE); - } - - xmlFreeDoc (doc); - - return TRUE; -} - - -/** - * e_tree_model_node_set_save_id: - * @etm: - * @node: - * @id: - * - * - **/ -void -e_tree_model_node_set_save_id (ETreeModel *etm, ETreePath *node, const char *id) -{ - char *key; - gboolean expanded_state; - ETreeModelPriv *priv; - - g_return_if_fail (E_TREE_MODEL (etm)); - g_return_if_fail (node); - - priv = etm->priv; - - if (g_hash_table_lookup_extended (priv->expanded_state, - id, (gpointer*)&key, (gpointer*)&expanded_state)) { - - e_tree_model_node_set_expanded (etm, node, - expanded_state); - - /* important that this comes after the e_tree_model_node_set_expanded */ - node->save_id = key; - } - else { - node->save_id = g_strdup (id); - - g_hash_table_insert (priv->expanded_state, node->save_id, (gpointer)node->expanded); - } -} - - - -/** - * e_tree_model_node_set_compare_function: - * @tree_model: - * @node: - * @compare: - * - * - **/ -void -e_tree_model_node_set_compare_function (ETreeModel *tree_model, - ETreePath *node, - ETreePathCompareFunc compare) -{ - gboolean need_sort; - - g_return_if_fail (E_TREE_MODEL (tree_model)); - g_return_if_fail (node); - - need_sort = (compare != node->compare); - - node->compare = compare; - - if (need_sort) - e_tree_model_node_sort (tree_model, node); -} - -typedef struct { - ETreeModel *model; - ETreePath *path; - ETreePathCompareFunc compare; - gboolean was_expanded; -} ETreeSortInfo; - -static gint -e_tree_model_node_compare (ETreeSortInfo *info1, ETreeSortInfo *info2) -{ - return info1->compare (info1->model, info1->path, info2->path); -} - -/** - * e_tree_model_node_sort: - * @tree_model: - * @node: - * - * - **/ -void -e_tree_model_node_sort (ETreeModel *tree_model, - ETreePath *node) -{ - int num_nodes = node->num_children; - ETreeSortInfo *sort_info; - int i; - int child_index; - gboolean node_expanded = e_tree_model_node_is_expanded (tree_model, node); - ETreeModelPriv *priv = tree_model->priv;; - - g_return_if_fail (E_TREE_MODEL (tree_model)); - g_return_if_fail (node); - - g_return_if_fail (node->compare); - - if (num_nodes == 0) - return; - - e_table_model_pre_change(E_TABLE_MODEL (tree_model)); - - sort_info = g_new (ETreeSortInfo, num_nodes); - - child_index = e_tree_model_row_of_node (tree_model, node) + 1; - - /* collect our info and remove the children */ - for (i = 0; i < num_nodes; i ++) { - sort_info[i].path = node->first_child; - sort_info[i].was_expanded = e_tree_model_node_is_expanded (tree_model, sort_info[i].path); - sort_info[i].model = tree_model; - sort_info[i].compare = node->compare; - - e_tree_model_node_set_expanded(tree_model, sort_info[i].path, FALSE); - if (node_expanded) - priv->row_array = g_array_remove_index (priv->row_array, child_index); - e_tree_path_unlink (sort_info[i].path); - } - - /* sort things */ - qsort (sort_info, num_nodes, sizeof(ETreeSortInfo), (GCompareFunc)e_tree_model_node_compare); - - /* reinsert the children nodes into the tree in the sorted order */ - for (i = 0; i < num_nodes; i ++) { - e_tree_path_insert (node, i, sort_info[i].path); - if (node_expanded) - priv->row_array = g_array_insert_val (priv->row_array, child_index + i, - sort_info[i].path); - } - - /* make another pass expanding the children as needed. - - XXX this used to be in the loop above, but a recent change - (either here or in the etable code) causes an assertion and - a crash */ - for (i = 0; i < num_nodes; i ++) { - e_tree_model_node_set_expanded (tree_model, sort_info[i].path, sort_info[i].was_expanded); - } - - g_free (sort_info); - - if (priv->frozen == 0) - e_table_model_changed (E_TABLE_MODEL (tree_model)); -} - diff --git a/widgets/table/e-tree-model.h b/widgets/table/e-tree-model.h deleted file mode 100644 index 50bd8064a5..0000000000 --- a/widgets/table/e-tree-model.h +++ /dev/null @@ -1,145 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TREE_MODEL_H_ -#define _E_TREE_MODEL_H_ - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gal/e-table/e-table-model.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_TREE_MODEL_TYPE (e_tree_model_get_type ()) -#define E_TREE_MODEL(o) (GTK_CHECK_CAST ((o), E_TREE_MODEL_TYPE, ETreeModel)) -#define E_TREE_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TREE_MODEL_TYPE, ETreeModelClass)) -#define E_IS_TREE_MODEL(o) (GTK_CHECK_TYPE ((o), E_TREE_MODEL_TYPE)) -#define E_IS_TREE_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TREE_MODEL_TYPE)) - -typedef struct ETreePath ETreePath; -typedef struct ETreeModel ETreeModel; -typedef struct ETreeModelPriv ETreeModelPriv; -typedef struct ETreeModelClass ETreeModelClass; -typedef gint (*ETreePathCompareFunc)(ETreeModel *model, ETreePath *path1, ETreePath *path2); -typedef gboolean (*ETreePathFunc)(ETreeModel *model, ETreePath *path, gpointer data); - -struct ETreeModel { - ETableModel base; - ETreeModelPriv *priv; -}; - -struct ETreeModelClass { - ETableModelClass parent_class; - - /* - * Virtual methods - */ - ETreePath *(*get_root) (ETreeModel *etm); - - ETreePath *(*get_parent) (ETreeModel *etm, ETreePath* node); - ETreePath *(*get_first_child) (ETreeModel *etm, ETreePath* node); - ETreePath *(*get_last_child) (ETreeModel *etm, ETreePath* node); - ETreePath *(*get_next) (ETreeModel *etm, ETreePath* node); - ETreePath *(*get_prev) (ETreeModel *etm, ETreePath* node); - guint (*get_children) (ETreeModel *etm, ETreePath* node, ETreePath ***paths); - - gboolean (*is_expanded) (ETreeModel *etm, ETreePath* node); - gboolean (*is_visible) (ETreeModel *etm, ETreePath* node); - void (*set_expanded) (ETreeModel *etm, ETreePath* node, gboolean expanded); - void (*set_expanded_recurse) (ETreeModel *etm, ETreePath *node, gboolean expanded); - void (*set_expanded_level) (ETreeModel *etm, ETreePath *node, gboolean expanded, int level); - - GdkPixbuf *(*icon_at) (ETreeModel *etm, ETreePath* node); - ETreePath* (*node_at_row) (ETreeModel *etm, int row); - - /* - * ETable analogs - */ - void *(*value_at) (ETreeModel *etm, ETreePath* node, int col); - void (*set_value_at) (ETreeModel *etm, ETreePath* node, int col, const void *val); - gboolean (*is_editable) (ETreeModel *etm, ETreePath* node, int col); - - - /* - * Signals - */ - void (*node_changed) (ETreeModel *etm, ETreePath *node); - void (*node_inserted) (ETreeModel *etm, ETreePath *parent, ETreePath *inserted_node); - void (*node_removed) (ETreeModel *etm, ETreePath *parent, ETreePath *removed_node); - void (*node_collapsed) (ETreeModel *etm, ETreePath *node); - void (*node_expanded) (ETreeModel *etm, ETreePath *node, gboolean *allow_expand); - -}; - -GtkType e_tree_model_get_type (void); -void e_tree_model_construct (ETreeModel *etree); -ETreeModel *e_tree_model_new (void); - -/* tree traversal operations */ -ETreePath *e_tree_model_get_root (ETreeModel *etree); -ETreePath *e_tree_model_node_get_parent (ETreeModel *etree, ETreePath *path); -ETreePath *e_tree_model_node_get_first_child (ETreeModel *etree, ETreePath *path); -ETreePath *e_tree_model_node_get_last_child (ETreeModel *etree, ETreePath *path); -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); -gpointer e_tree_model_node_remove (ETreeModel *etree, ETreePath *path); - -/* Freeze and thaw */ -void e_tree_model_freeze (ETreeModel *etree); -void e_tree_model_thaw (ETreeModel *etree); - -/* node accessors */ -gboolean e_tree_model_node_is_root (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_expandable (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_expanded (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_visible (ETreeModel *etree, ETreePath *path); -void e_tree_model_set_expanded_default (ETreeModel *etree, gboolean expanded); -void e_tree_model_node_set_expanded (ETreeModel *etree, ETreePath *path, gboolean expanded); -void e_tree_model_node_set_expanded_recurse (ETreeModel *etree, ETreePath *path, gboolean expanded); -guint e_tree_model_node_get_children (ETreeModel *etree, ETreePath *path, ETreePath ***paths); -guint e_tree_model_node_depth (ETreeModel *etree, ETreePath *path); -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); - -/* display oriented routines */ -ETreePath *e_tree_model_node_at_row (ETreeModel *etree, int row); -GdkPixbuf *e_tree_model_icon_of_node (ETreeModel *etree, ETreePath *path); -int e_tree_model_row_of_node (ETreeModel *etree, ETreePath *path); -void e_tree_model_root_node_set_visible (ETreeModel *etree, gboolean visible); -gboolean e_tree_model_root_node_is_visible (ETreeModel *etree); - -/* sort routine, analogous to gtk_ctree_node_sort */ -void e_tree_model_node_set_compare_function (ETreeModel *tree_model, ETreePath *node, ETreePathCompareFunc compare); -void e_tree_model_node_sort (ETreeModel *tree_model, ETreePath *node); - -/* -** Routines for emitting signals on the ETreeModel -*/ -void e_tree_model_node_changed (ETreeModel *tree_model, ETreePath *node); -void e_tree_model_node_inserted (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *inserted_node); -void e_tree_model_node_removed (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *removed_node); -void e_tree_model_node_collapsed (ETreeModel *tree_model, ETreePath *node); -void e_tree_model_node_expanded (ETreeModel *tree_model, ETreePath *node, gboolean *allow_expand); - -/* expanded state saving stuff */ -gboolean e_tree_model_save_expanded_state (ETreeModel *etm, const char *filename); -gboolean e_tree_model_load_expanded_state (ETreeModel *etm, const char *filename); -void e_tree_model_node_set_save_id (ETreeModel *etm, ETreePath *node, const char *id); -ETreePath* e_tree_model_node_insert_id (ETreeModel *tree_model, ETreePath *parent_path, - int position, gpointer node_data, const char *save_id); - -/* depth first traversal of path's descendents, calling func on each one */ -void e_tree_model_node_traverse (ETreeModel *model, ETreePath *path, ETreePathFunc func, gpointer data); - -void e_tree_model_show_node (ETreeModel *etm, ETreePath* node); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TREE_MODEL_H */ diff --git a/widgets/table/e-tree-simple.c b/widgets/table/e-tree-simple.c deleted file mode 100644 index 5741d1cf0f..0000000000 --- a/widgets/table/e-tree-simple.c +++ /dev/null @@ -1,202 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-tree-simple.c: a Tree Model that offers a function pointer - * interface to using ETreeModel, similar to ETableSimple. - * - * Author: - * Chris Toshok (toshok@ximian.com) - * - * (C) 2000 Ximian, Inc. */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "gal/util/e-util.h" -#include "e-tree-simple.h" - -#define PARENT_TYPE E_TREE_MODEL_TYPE - -static int -simple_column_count (ETableModel *etm) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - if (simple->col_count) - return simple->col_count (etm, simple->model_data); - else - return 0; -} - -/* The default for simple_duplicate_value is to return the raw value. */ -static void * -simple_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - if (simple->duplicate_value) - return simple->duplicate_value (etm, col, value, simple->model_data); - else - return (void *)value; -} - -static void -simple_free_value (ETableModel *etm, int col, void *value) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - if (simple->free_value) - simple->free_value (etm, col, value, simple->model_data); -} - -static void * -simple_initialize_value (ETableModel *etm, int col) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - if (simple->initialize_value) - return simple->initialize_value (etm, col, simple->model_data); - else - return NULL; -} - -static gboolean -simple_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - if (simple->value_is_empty) - return simple->value_is_empty (etm, col, value, simple->model_data); - else - return FALSE; -} - -static char * -simple_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - if (simple->value_to_string) - return simple->value_to_string (etm, col, value, simple->model_data); - else - return g_strdup (""); -} - -static void * -simple_value_at (ETreeModel *etm, ETreePath *node, int col) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->value_at (etm, node, col, simple->model_data); -} - -static GdkPixbuf * -simple_icon_at (ETreeModel *etm, ETreePath *node) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->icon_at (etm, node, simple->model_data); -} - -static void -simple_set_value_at (ETreeModel *etm, ETreePath *node, int col, const void *val) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - simple->set_value_at (etm, node, col, val, simple->model_data); -} - -static gboolean -simple_is_editable (ETreeModel *etm, ETreePath *node, int col) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->is_editable (etm, node, col, simple->model_data); -} - -static void -e_tree_simple_class_init (GtkObjectClass *object_class) -{ - ETreeModelClass *model_class = (ETreeModelClass *) object_class; - ETableModelClass *table_model_class = (ETableModelClass *) object_class; - - table_model_class->column_count = simple_column_count; - table_model_class->duplicate_value = simple_duplicate_value; - table_model_class->free_value = simple_free_value; - table_model_class->initialize_value = simple_initialize_value; - table_model_class->value_is_empty = simple_value_is_empty; - table_model_class->value_to_string = simple_value_to_string; - - model_class ->icon_at = simple_icon_at; - model_class ->value_at = simple_value_at; - model_class ->set_value_at = simple_set_value_at; - model_class ->is_editable = simple_is_editable; -} - -E_MAKE_TYPE(e_tree_simple, "ETreeSimple", ETreeSimple, e_tree_simple_class_init, NULL, PARENT_TYPE) - -/** - * e_tree_simple_new: - * @col_count: - * @duplicate_value: - * @free_value: - * @initialize_value: - * @value_is_empty: - * @value_to_string: - * @icon_at: - * @value_at: - * @set_value_at: - * @is_editable: - * @model_data: - * - * This initializes a new ETreeSimpleModel object. ETreeSimpleModel is - * an implementaiton of the abstract class ETreeModel. The ETreeSimpleModel - * is designed to allow people to easily create ETreeModels without having - * to create a new GtkType derived from ETreeModel every time they need one. - * - * Instead, ETreeSimpleModel uses a setup based in callback functions, every - * callback function signature mimics the signature of each ETreeModel method - * and passes the extra @data pointer to each one of the method to provide them - * with any context they might want to use. - * - * ETreeSimple is to ETreeModel as ETableSimple is to ETableModel. - * - * Return value: An ETreeSimple object (which is also an ETreeModel - * object). - **/ -ETreeModel * -e_tree_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleDuplicateValueFn duplicate_value, - ETableSimpleFreeValueFn free_value, - ETableSimpleInitializeValueFn initialize_value, - ETableSimpleValueIsEmptyFn value_is_empty, - ETableSimpleValueToStringFn value_to_string, - - ETreeSimpleIconAtFn icon_at, - ETreeSimpleValueAtFn value_at, - ETreeSimpleSetValueAtFn set_value_at, - ETreeSimpleIsEditableFn is_editable, - - gpointer model_data) -{ - ETreeSimple *etg; - - etg = gtk_type_new (e_tree_simple_get_type ()); - - e_tree_model_construct (E_TREE_MODEL (etg)); - - etg->col_count = col_count; - etg->duplicate_value = duplicate_value; - etg->free_value = free_value; - etg->initialize_value = initialize_value; - etg->value_is_empty = value_is_empty; - etg->value_to_string = value_to_string; - - etg->icon_at = icon_at; - etg->value_at = value_at; - etg->set_value_at = set_value_at; - etg->is_editable = is_editable; - - etg->model_data = model_data; - - return (ETreeModel*)etg; -} - diff --git a/widgets/table/e-tree-simple.h b/widgets/table/e-tree-simple.h deleted file mode 100644 index 797de7c8a7..0000000000 --- a/widgets/table/e-tree-simple.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -#ifndef _E_TREE_SIMPLE_H_ -#define _E_TREE_SIMPLE_H_ - -#include <gal/e-table/e-tree-model.h> -#include <gal/e-table/e-table-simple.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TREE_SIMPLE_TYPE (e_tree_simple_get_type ()) -#define E_TREE_SIMPLE(o) (GTK_CHECK_CAST ((o), E_TREE_SIMPLE_TYPE, ETreeSimple)) -#define E_TREE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TREE_SIMPLE_TYPE, ETreeSimpleClass)) -#define E_IS_TREE_SIMPLE(o) (GTK_CHECK_TYPE ((o), E_TREE_SIMPLE_TYPE)) -#define E_IS_TREE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TREE_SIMPLE_TYPE)) - - -typedef GdkPixbuf* (*ETreeSimpleIconAtFn) (ETreeModel *etree, ETreePath *path, void *model_data); -typedef void* (*ETreeSimpleValueAtFn) (ETreeModel *etree, ETreePath *path, int col, void *model_data); -typedef void (*ETreeSimpleSetValueAtFn) (ETreeModel *etree, ETreePath *path, int col, const void *val, void *model_data); -typedef gboolean (*ETreeSimpleIsEditableFn) (ETreeModel *etree, ETreePath *path, int col, void *model_data); - -typedef struct { - ETreeModel parent; - - /* Table methods */ - ETableSimpleColumnCountFn col_count; - ETableSimpleDuplicateValueFn duplicate_value; - ETableSimpleFreeValueFn free_value; - ETableSimpleInitializeValueFn initialize_value; - ETableSimpleValueIsEmptyFn value_is_empty; - ETableSimpleValueToStringFn value_to_string; - - /* Tree methods */ - ETreeSimpleIconAtFn icon_at; - ETreeSimpleValueAtFn value_at; - ETreeSimpleSetValueAtFn set_value_at; - ETreeSimpleIsEditableFn is_editable; - - gpointer model_data; -} ETreeSimple; - -typedef struct { - ETreeModelClass parent_class; -} ETreeSimpleClass; - -GtkType e_tree_simple_get_type (void); - -ETreeModel *e_tree_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleDuplicateValueFn duplicate_value, - ETableSimpleFreeValueFn free_value, - ETableSimpleInitializeValueFn initialize_value, - ETableSimpleValueIsEmptyFn value_is_empty, - ETableSimpleValueToStringFn value_to_string, - ETreeSimpleIconAtFn icon_at, - ETreeSimpleValueAtFn value_at, - ETreeSimpleSetValueAtFn set_value_at, - ETreeSimpleIsEditableFn is_editable, - gpointer model_data); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_TREE_SIMPLE_H_ */ diff --git a/widgets/table/e-tree-sorted-variable.c b/widgets/table/e-tree-sorted-variable.c deleted file mode 100644 index 754876de27..0000000000 --- a/widgets/table/e-tree-sorted-variable.c +++ /dev/null @@ -1,458 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-tree-sorted-variable.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "gal/util/e-util.h" -#include "e-tree-sorted-variable.h" - -#define d(x) - -#define PARENT_TYPE E_TREE_MODEL_TYPE - -#define INCREMENT_AMOUNT 100 - -/* maximum insertions between an idle event that we will do without scheduling an idle sort */ -#define ETSV_INSERT_MAX (4) - -static ETreeModelClass *etsv_parent_class; - -struct ETreePath { - GNode node; -}; - -struct ETreeSortedVariablePrivate { - GNode *root; -}; - -static void etsv_proxy_model_changed (ETableModel *etm, ETreeSortedVariable *etsv); -#if 0 -static void etsv_proxy_model_row_changed (ETableModel *etm, int row, ETreeSortedVariable *etsv); -static void etsv_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETreeSortedVariable *etsv); -#endif -static void etsv_sort_info_changed (ETableSortInfo *info, ETreeSortedVariable *etsv); -static void etsv_sort (ETreeSortedVariable *etsv); -static void etsv_add (ETreeSortedVariable *etsv, gint row); -static void etsv_add_all (ETreeSortedVariable *etsv); - -static void -etsv_destroy (GtkObject *object) -{ - ETreeSortedVariable *etsv = E_TREE_SORTED_VARIABLE (object); - - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_changed_id); -#if 0 - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_cell_changed_id); -#endif - gtk_signal_disconnect (GTK_OBJECT (etsv->sort_info), - etsv->sort_info_changed_id); - - if (etsv->sort_idle_id) { - g_source_remove(etsv->sort_idle_id); - } - if (etsv->insert_idle_id) { - g_source_remove(etsv->insert_idle_id); - } - - etsv->table_model_changed_id = 0; - etsv->table_model_row_changed_id = 0; - etsv->table_model_cell_changed_id = 0; - - if (etsv->sort_info) - gtk_object_unref(GTK_OBJECT(etsv->sort_info)); - if (etsv->full_header) - gtk_object_unref(GTK_OBJECT(etsv->full_header)); - - GTK_OBJECT_CLASS (etsv_parent_class)->destroy (object); -} - -static void -etsv_class_init (GtkObjectClass *object_class) -{ - ETreeSortedVariableClass *etsv_class = E_TREE_MODEL_CLASS(object_class); - - etsv_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = etsv_destroy; - - etsv_class->add = etsv_add; - etsv_class->add_all = etsv_add_all; -} - -static void -etsv_init (ETreeSortedVariable *etsv) -{ - etsv->full_header = NULL; - etsv->sort_info = NULL; - - etsv->table_model_changed_id = 0; - etsv->table_model_row_changed_id = 0; - etsv->table_model_cell_changed_id = 0; - etsv->sort_info_changed_id = 0; - - etsv->sort_idle_id = 0; - etsv->insert_count = 0; -} - -E_MAKE_TYPE(e_tree_sorted_variable, "ETreeSortedVariable", ETreeSortedVariable, etsv_class_init, etsv_init, PARENT_TYPE); - -static gboolean -etsv_sort_idle(ETreeSortedVariable *etsv) -{ - gtk_object_ref(GTK_OBJECT(etsv)); - etsv_sort(etsv); - etsv->sort_idle_id = 0; - etsv->insert_count = 0; - gtk_object_unref(GTK_OBJECT(etsv)); - return FALSE; -} - -static gboolean -etsv_insert_idle(ETreeSortedVariable *etsv) -{ - etsv->insert_count = 0; - etsv->insert_idle_id = 0; - return FALSE; -} - - -ETableModel * -e_tree_sorted_variable_new (ETreeModel *source, ETableHeader *full_header, ETableSortInfo *sort_info) -{ - ETreeSortedVariable *etsv = gtk_type_new (E_TREE_SORTED_VARIABLE_TYPE); - ETreeSortedVariable *etsv = E_TABLE_SUBSET_VARIABLE (etsv); - - if (e_table_subset_variable_construct (etsv, source) == NULL){ - gtk_object_unref (GTK_OBJECT (etsv)); - return NULL; - } - - etsv->sort_info = sort_info; - gtk_object_ref(GTK_OBJECT(etsv->sort_info)); - etsv->full_header = full_header; - gtk_object_ref(GTK_OBJECT(etsv->full_header)); - - etsv->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_changed), etsv); -#if 0 - etsv->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_row_changed), etsv); - etsv->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_cell_changed), etsv); -#endif - etsv->sort_info_changed_id = gtk_signal_connect (GTK_OBJECT (sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC (etsv_sort_info_changed), etsv); - - return E_TABLE_MODEL(etsv); -} - -static void -etsv_proxy_model_changed (ETableModel *etm, ETreeSortedVariable *etsv) -{ - /* FIXME: do_resort (); */ -} -#if 0 -static void -etsv_proxy_model_row_changed (ETableModel *etm, int row, ETreeSortedVariable *etsv) -{ - ETreeSortedVariable *etsv = E_TABLE_SUBSET_VARIABLE(etsv); - - if (e_table_subset_variable_remove(etsv, row)) - e_table_subset_variable_add (etsv, row); -} - -static void -etsv_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETreeSortedVariable *etsv) -{ - ETreeSortedVariable *etsv = E_TABLE_SUBSET_VARIABLE(etsv); - - if (e_table_subset_variable_remove(etsv, row)) - e_table_subset_variable_add (etsv, row); -} -#endif - -static void -etsv_sort_info_changed (ETableSortInfo *info, ETreeSortedVariable *etsv) -{ - etsv_sort(etsv); -} - -/* This takes source rows. */ -static int -etsv_compare(ETreeSortedVariable *etsv, const ETreePath *path1, const ETreePath *path2) -{ - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv->sort_info); - int comp_val = 0; - int ascending = 1; - - for (j = 0; j < sort_count; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j); - ETableCol *col; - col = e_table_header_get_column_by_col_idx(etsv->full_header, column.column); - if (col == NULL) - col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1); - comp_val = (*col->compare)(e_tree_model_value_at (etsv->source, path1, col->col_idx), - e_tree_model_value_at (etsv->source, path2, col->col_idx)); - ascending = column.ascending; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - - -static ETreeSortedVariable *etsv_closure; -int cols_closure; -int *ascending_closure; -int *col_idx_closure; -GCompareFunc *compare_closure; - -static int -etsv_compare_closure(const ETreePath *path1, const ETreePath *path2) -{ - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - - comp_val = (*(compare_closure[j]))(e_tree_model_value_at (etsv_closure->source, path1, col_idx_closure[j]), - e_tree_model_value_at (etsv_closure->source, path2, col_idx_closure[j])); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - -static int -qsort_callback(const void *data1, const void *data2) -{ - GNode *node1 = *(GNode **)data1; - GNode *node2 = *(GNode **)data2; - return etsv_compare_closure(node1->data, node2->data); -} - -static int -qsort_callback_source(const void *data1, const void *data2) -{ - return etsv_compare_closure(data1, data2); -} - -static void -etsv_setup_closures(ETreeSortedVariable *etsv) -{ - int j; - int cols; - - cols = e_table_sort_info_sorting_get_count(etsv->sort_info); - cols_closure = cols; - etsv_closure = etsv; - - ascending_closure = g_new(int, cols); - col_idx_closure = g_new(int, cols); - compare_closure = g_new(GCompareFunc, cols); - - for (j = 0; j < cols; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j); - ETableCol *col; - - col = e_table_header_get_column_by_col_idx(etsv->full_header, column.column); - if (col == NULL) { - col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1); - } - - ascending_closure[j] = column.ascending; - col_idx_closure[j] = col->col_idx; - compare_closure[j] = col->compare; - } -} - -static void -etsv_free_closures(ETreeSortedVariable *etsv) -{ - g_free(ascending_closure); - g_free(col_idx_closure); - g_free(compare_closure); - -} - -static void -etsv_sort_node(ETreeSortedVariable *etsv, GNode *node) -{ - gint n; - gint i; - GNode **children; - GNode *child; - GNode *prev; - - n = g_node_n_children(node); - children = g_new(GNode *, n); - for (i = 0, child = node->children; child && i; child = child->next, i++) { - children[i] = child; - } - qsort(children, n, sizeof(GNode *), qsort_callback); - - prev = NULL; - for (i = 0; i < n; i++) { - children[i]->prev = prev; - if (prev) prev->next = children[i]; - prev = children[i]; - children[i]->next = NULL; - } -} - -static void -etsv_sort_tree(ETreeSortedVariable *etsv, GNode *root) -{ - GNode *childr; - - etsv_sort_node(etsv, node); - - for (child = node->child; child; child = child->next) { - etsv_sort_tree(etsv, child); - } -} - -static void -etsv_sort(ETreeSortedVariable *etsv) -{ - static int reentering = 0; - if (reentering) - return; - reentering = 1; - - e_table_model_pre_change(E_TABLE_MODEL(etsv)); - - etsv_setup_closures(etsv); - - etsv_sort_tree(etsv, etsv->root); - - etsv_free_closures(etsv); - - e_table_model_changed (E_TABLE_MODEL(etsv)); - reentering = 0; -} - -static void -etsv_add_node (ETreeSortedVariable *etsv, ETreePath *path, GNode *root) -{ - GNode *node; - GNode *new_node; - for (node = root; node; node = node->next) { - if (e_tree_model_node_is_ancestor(etsv->source, path, node->data)) { - etsv_add_node(etsv, path, node->data); - return; - } - } - new_node = g_node_new(path); - for (node = root; node; ) { - if (e_tree_model_node_is_ancestor(etsv->source, node->data, path)) { - GNode *next; - next = node->next; - g_node_unlink(node); - g_node_prepend(new_node, node); - node = next; - } else - node = node->next; - } - - etsv_sort_node(etsv, new_node); - - -#if 0 - g_node_prepend(root, new_node); - etsv_sort_node(etsv, root); -#else - /* Insert sort to be a bit faster than the above prepend and then sort. */ - for (node = root; node; node = node->next) { - if (etsv_compare(etsv, path, node->data) > 0) { - g_node_insert_before (root, node, new_node); - return; - } - } - g_node_append(root, new_node); -#endif -} - -etsv_add(ETreeSortedVariable *etsv, gint row) -{ - ETreeModel *source = etsv->source; - ETreePath *path; - - path = e_table_model_value_at (E_TABLE_MODEL(source), -1, row); - etsv_add_node(etsv, path, etsv->root); -} - -/* Optimize by doing the qsorts as we build. But we'll do that later. */ -static void -etsv_add_all_node (ETreeSortedVariable *etsv, ETreePath *path, GNode *node) -{ - ETreeModel *source = etsv->source; - ETreePath **children; - int n; - int i; - - n = e_tree_model_node_get_children(source, path, &children); - qsort(children, n, sizeof(ETreePath *), qsort_callback_source); - - for (i = n - 1; i >= 0; i--) { - GNode *new_child = g_node_new(children[i]); - g_node_prepend(path, new_child); - etsv_add_all_node (etsv, children[i], new_child) - } - - g_free(children); -} - -static void -etsv_add_all (ETreeSortedVariable *etsv) -{ - GNode *node; - ETreePath *path; - - e_table_model_pre_change(etm); - - if (etsv->root) - g_node_destroy(etsv->root); - - etsv_setup_closures(etsv); - - path = e_tree_model_get_root(etsv->source); - node = g_node_new(path); - etsv_add_all_node(etsv, path, node); - etsv->root = node; - - etsv_free_closures(etsv); - - e_tree_model_node_changed (etsv, etsv->root); -} diff --git a/widgets/table/e-tree-sorted-variable.h b/widgets/table/e-tree-sorted-variable.h deleted file mode 100644 index a86ea9f602..0000000000 --- a/widgets/table/e-tree-sorted-variable.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TREE_SORTED_VARIABLE_H_ -#define _E_TREE_SORTED_VARIABLE_H_ - -#include <gtk/gtkobject.h> -#include <gal/e-tree/e-tree-model.h> -#include <gal/e-table/e-table-subset-variable.h> -#include <gal/e-table/e-table-sort-info.h> -#include <gal/e-table/e-table-header.h> - -BEGIN_GNOME_DECLS - -#define E_TREE_SORTED_VARIABLE_TYPE (e_tree_sorted_variable_get_type ()) -#define E_TREE_SORTED_VARIABLE(o) (GTK_CHECK_CAST ((o), E_TREE_SORTED_VARIABLE_TYPE, ETreeSortedVariable)) -#define E_TREE_SORTED_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TREE_SORTED_VARIABLE_TYPE, ETreeSortedVariableClass)) -#define E_IS_TREE_SORTED_VARIABLE(o) (GTK_CHECK_TYPE ((o), E_TREE_SORTED_VARIABLE_TYPE)) -#define E_IS_TREE_SORTED_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TREE_SORTED_VARIABLE_TYPE)) - -typedef struct { - ETreeModel base; - - ETableSortInfo *sort_info; - - ETableHeader *full_header; - - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; - int sort_info_changed_id; - int sort_idle_id; - int insert_idle_id; - int insert_count; - -} ETreeSortedVariable; - -typedef struct { - ETreeModelClass parent_class; -} ETreeSortedVariableClass; - -GtkType e_tree_sorted_variable_get_type (void); -ETableModel *e_tree_sorted_variable_new (ETreeModel *etm, - ETableHeader *header, - ETableSortInfo *sort_info); - -ETreeModel *e_tree_sorted_get_toplevel (ETreeSortedVariable *tree_model); - -void e_tree_sorted_variable_add (ETreeSortedVariable *ets, - gint row); -void e_tree_sorted_variable_add_all (ETreeSortedVariable *ets); -gboolean e_tree_sorted_variable_remove (ETreeSortedVariable *ets, - gint row); -void e_tree_sorted_variable_increment (ETreeSortedVariable *ets, - gint position, - gint amount); -void e_tree_sorted_variable_decrement (ETreeSortedVariable *ets, - gint position, - gint amount); -void e_tree_sorted_variable_set_allocation (ETreeSortedVariable *ets, - gint total); -END_GNOME_DECLS - -#endif /* _E_TREE_SORTED_VARIABLE_H_ */ diff --git a/widgets/table/image1.png b/widgets/table/image1.png Binary files differdeleted file mode 100644 index 8326ac241f..0000000000 --- a/widgets/table/image1.png +++ /dev/null diff --git a/widgets/table/image2.png b/widgets/table/image2.png Binary files differdeleted file mode 100644 index e6a4c75dbe..0000000000 --- a/widgets/table/image2.png +++ /dev/null diff --git a/widgets/table/image3.png b/widgets/table/image3.png Binary files differdeleted file mode 100644 index 50e16e8620..0000000000 --- a/widgets/table/image3.png +++ /dev/null diff --git a/widgets/table/remove-col.xpm b/widgets/table/remove-col.xpm deleted file mode 100644 index ff1024f0c9..0000000000 --- a/widgets/table/remove-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * remove_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FF0000", -"... ...", -".++. .++.", -".+++. .+++.", -" .+++. .+++. ", -" .+++. .+++. ", -" .+++..+++. ", -" .++++++. ", -" .++++. ", -" .++++. ", -" .++++++. ", -" .+++..+++. ", -" .+++. .+++. ", -" .+++. .+++. ", -".+++. .+++.", -".++. .++.", -"... ..."}; diff --git a/widgets/table/sample.table b/widgets/table/sample.table deleted file mode 100644 index 45c8ff0691..0000000000 --- a/widgets/table/sample.table +++ /dev/null @@ -1,11 +0,0 @@ -Col1 Col2 Address Title Dorks -c1.a c2.a a.a tit-1 DorkA -c1.b c2.b a.b tit-2 DDork -c1.c c2.c a.c tit-1 DorkB -c1.d c2.d a.d tit-2 ADork -c1.e c2.e a.e tit-1 DorkC -c1.f c2.f a.f tit-2 UDork -c1.g c2.g a.g tit-3 Dork--- -j k k tit-1 DorkA - - diff --git a/widgets/table/spec.xml b/widgets/table/spec.xml deleted file mode 100644 index a8e524484c..0000000000 --- a/widgets/table/spec.xml +++ /dev/null @@ -1,21 +0,0 @@ -<ETableSpecification no-headers="false" click-to-add="false" - draw-grid="true" cursor-mode="simple" - _click-to-add-message=""> - <ETableColumn model_col="0" _title="Email" expansion="1.0" minimum_width="20" resizable="true" cell="cell_left_just" compare="string"/> - <ETableColumn model_col="1" _title="Full Name" expansion="1.0" minimum_width="20" resizable="true" cell="cell_left_just" compare="string"/> - <ETableColumn model_col="2" _title="Address" expansion="1.0" minimum_width="20" resizable="true" cell="cell_left_just" compare="string"/> - <ETableColumn model_col="3" _title="Phone" expansion="1.0" minimum_width="20" resizable="true" cell="cell_left_just" compare="string"/> - <ETableState> - <column source="0"/> - <column source="3"/> - <column source="1"/> - <column source="2"/> - <grouping> - <group column="2" ascending="true"> - <leaf column="1" ascending="true"/> - </group> - </grouping> - <!-- Column that's been added by hand. Not implemented yet. - <ETableColumn model_col="custom-string" _title="Custom" expansion="1.0" minimum_widgth="20" resizable="true" cell="string" compare="string"/> --> - </ETableState> -</ETableSpecification> diff --git a/widgets/table/table-test.c b/widgets/table/table-test.c deleted file mode 100644 index dd0dee4d24..0000000000 --- a/widgets/table/table-test.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <gnome.h> -#include "gal/e-util/e-cursors.h" -#include "table-test.h" - -int -main (int argc, char *argv []) -{ - - if (isatty (0)){ - int fd; - - close (0); - fd = open ("sample.table", O_RDONLY); - if (fd == -1){ - fprintf (stderr, "Could not find sample.table, try feeding a table on stdin"); - exit (1); - } - dup2 (fd, 0); - } - - gnome_init ("TableTest", "TableTest", argc, argv); - e_cursors_init (); - - -/* table_browser_test (); */ -/* multi_cols_test (); */ -/* check_test (); */ - - e_table_test (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} diff --git a/widgets/table/table-test.h b/widgets/table/table-test.h deleted file mode 100644 index ad8cfcc083..0000000000 --- a/widgets/table/table-test.h +++ /dev/null @@ -1,4 +0,0 @@ -void table_browser_test (void); -void multi_cols_test (void); -void check_test (void); -void e_table_test (void); diff --git a/widgets/table/test-check.c b/widgets/table/test-check.c deleted file mode 100644 index 0cf1baf48a..0000000000 --- a/widgets/table/test-check.c +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "gal/widgets/e-cursors.h" -#include "gal/widgets/e-canvas-utils.h" -#include "gal/widgets/e-canvas.h" -#include "gal/util/e-util.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "Buy food" }, - { 1, "Breathe " }, - { 0, "Cancel gdb session with shrink" }, - { 1, "Make screenshots" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) { - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) { - return (void *) value; - } else { - return g_strdup (value); - } -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col != 0) { - g_free (value); - } -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == 0) - return NULL; - else - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return value == NULL; - else - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return g_strdup_printf("%d", (int) value); - else - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -check_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_check; - GdkPixbuf *pixbuf; - GnomeCanvasItem *item; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - cell_image_check = e_cell_checkbox_new (); - pixbuf = gdk_pixbuf_new_from_file ("clip.png"); - col_0 = e_table_col_new_with_pixbuf (0, pixbuf, 0.0, 18, cell_image_check, g_int_compare, TRUE); - gdk_pixbuf_unref (pixbuf); - e_table_header_add_column (e_table_header, col_0, 0); - - col_1 = e_table_col_new (1, "Item Name", 1.0, 20, cell_left_just, g_str_compare, TRUE); - e_table_header_add_column (e_table_header, col_1, 1); - e_table_col_set_arrow (col_1, E_TABLE_COL_ARROW_DOWN); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - "cursor_mode", E_TABLE_CURSOR_SIMPLE, - NULL); - e_canvas_item_move_absolute (item, 0, 30); -} - diff --git a/widgets/table/test-cols.c b/widgets/table/test-cols.c deleted file mode 100644 index a82dae639a..0000000000 --- a/widgets/table/test-cols.c +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "gal/widgets/e-canvas-utils.h" -#include "gal/widgets/e-canvas.h" -#include "gal/widgets/e-cursors.h" -#include "gal/util/e-util.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-toggle.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "You are not" }, - { 1, "A beautiful and unique " }, - { 0, "Snowflake" }, - { 2, "You are not your wallet" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0){ - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0){ - return (void *)value; - } else { - return g_strdup (value); - } -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col != 0){ - g_free (value); - } -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == 0) - return NULL; - else - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return value == NULL; - else - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return g_strdup_printf("%d", (int) value); - else - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -multi_cols_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header, *e_table_header_multiple; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_toggle; - GnomeCanvasItem *item; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - { - GdkPixbuf **images = g_new (GdkPixbuf *, 3); - int i; - - images [0] = gdk_pixbuf_new_from_file ("image1.png"); - images [1] = gdk_pixbuf_new_from_file ("image2.png"); - images [2] = gdk_pixbuf_new_from_file ("image3.png"); - - cell_image_toggle = e_cell_toggle_new (0, 3, images); - - for (i = 0; i < 3; i++) - gdk_pixbuf_unref (images [i]); - - g_free (images); - } - - col_1 = e_table_col_new (1, "Item Name", 1.0, 20, cell_left_just, g_str_compare, TRUE); - e_table_header_add_column (e_table_header, col_1, 0); - - col_0 = e_table_col_new (0, "A", 0.0, 48, cell_image_toggle, g_int_compare, TRUE); - e_table_header_add_column (e_table_header, col_0, 1); - - /* - * Second test - */ - e_table_header_multiple = e_table_header_new (); - e_table_header_add_column (e_table_header_multiple, col_0, 0); - e_table_header_add_column (e_table_header_multiple, col_1, 1); - e_table_header_add_column (e_table_header_multiple, col_1, 2); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, - "cursor_mode", E_TABLE_CURSOR_SIMPLE, -#if 0 - "spreadsheet", TRUE, -#endif - NULL); - - e_canvas_item_move_absolute (item, 0, 30); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header_multiple, - NULL); - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header_multiple, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - "cursor_mode", E_TABLE_CURSOR_SIMPLE, - NULL); - e_canvas_item_move_absolute (item, 300, 30); -} - - - - - diff --git a/widgets/table/test-table.c b/widgets/table/test-table.c deleted file mode 100644 index 314df1000e..0000000000 --- a/widgets/table/test-table.c +++ /dev/null @@ -1,394 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "gal/widgets/e-cursors.h" -#include "gal/widgets/e-canvas.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-table.h" -#include "e-table-config.h" - -#include "table-test.h" - -char buffer [1024]; -char **column_labels; -char ***table_data; -int cols = 0; -int lines = 0; -int lines_alloc = 0; - -static void -parse_headers () -{ - char *p, *s; - int in_value = 0, i; - - fgets (buffer, sizeof (buffer)-1, stdin); - - for (p = buffer; *p; p++){ - if (*p == ' ' || *p == '\t'){ - if (in_value){ - cols++; - in_value = 0; - } - } else - in_value = 1; - } - if (in_value) - cols++; - - if (!cols){ - fprintf (stderr, "No columns in first row\n"); - exit (1); - } - - column_labels = g_new0 (char *, cols); - - p = buffer; - for (i = 0; (s = strtok (p, " \t")) != NULL; i++){ - column_labels [i] = g_strdup (s); - if (strchr (column_labels [i], '\n')) - *strchr (column_labels [i], '\n') = 0; - p = NULL; - } - - printf ("%d headers:\n", cols); - for (i = 0; i < cols; i++){ - printf ("header %d: %s\n", i, column_labels [i]); - } -} - -static char ** -load_line (char *buffer, int cols) -{ - char **line = g_new0 (char *, cols); - char *p; - int i; - - for (i = 0; i < cols; i++){ - p = strtok (buffer, " \t\n"); - if (p == NULL){ - for (; i < cols; i++) - line [i] = g_strdup (""); - return line; - } else - line [i] = g_strdup (p); - buffer = NULL; - } - return line; -} - -static void -append_line (char **line) -{ - if (lines <= lines_alloc){ - lines_alloc = lines + 50; - table_data = g_renew (char **, table_data, lines_alloc); - } - table_data [lines] = line; - lines++; -} - -static void -load_data () -{ - int i; - - { - static int loaded; - - if (loaded) - return; - - loaded = TRUE; - } - - - parse_headers (); - - while (fgets (buffer, sizeof (buffer)-1, stdin) != NULL){ - char **line; - - if (buffer [0] == '\n') - continue; - line = load_line (buffer, cols); - append_line (line); - } - - for (i = 0; i < lines; i++){ - int j; - - printf ("Line %d: ", i); - for (j = 0; j < cols; j++) - printf ("[%s] ", table_data [i][j]); - printf ("\n"); - } -} - -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return cols; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return lines; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - return (void *) table_data [row][col]; -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -table_browser_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ECell *cell_left_just; - GnomeCanvasItem *group; - int i; - - load_data (); - - /* - * Data model - */ - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Setup GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - group = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_group_get_type (), - "x", 30.0, - "y", 30.0, - NULL); - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (group), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - NULL); -} - -static void -save_spec (GtkWidget *button, ETable *e_table) -{ - e_table_save_specification (e_table, "e-table-test.xml"); -} - -static void -row_selection_test (ETable *table, int row, gboolean selected) -{ - if (selected) - g_print ("Row %d selected\n", row); - else - g_print ("Row %d unselected\n", row); -} - -static void -toggle_grid (void *nothing, ETable *etable) -{ - static gboolean shown; - - gtk_object_get (GTK_OBJECT (etable), "drawgrid", &shown, NULL); - gtk_object_set (GTK_OBJECT (etable), "drawgrid", !shown, NULL); -} - -static void -do_e_table_demo (const char *spec) -{ - GtkWidget *e_table, *window, *frame, *vbox, *button, *bhide; - ECell *cell_left_just; - ETableHeader *full_header; - int i; - - /* - * Data model - */ - static ETableModel *e_table_model = NULL; - - if (e_table_model == NULL) - e_table_model = - e_table_simple_new (col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - full_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - - e_table_header_add_column (full_header, ecol, i); - } - - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - frame = gtk_frame_new (NULL); - e_table = e_table_new (full_header, e_table_model, spec); - gtk_signal_connect (GTK_OBJECT(e_table), "row_selection", - GTK_SIGNAL_FUNC(row_selection_test), NULL); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), e_table, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* - * gadgets - */ - button = gtk_button_new_with_label ("Save spec"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (save_spec), e_table); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - bhide = gtk_button_new_with_label ("Toggle Grid"); - gtk_signal_connect (GTK_OBJECT (bhide), "clicked", - GTK_SIGNAL_FUNC (toggle_grid), e_table); - gtk_box_pack_start (GTK_BOX (vbox), bhide, FALSE, FALSE, 0); - - gtk_widget_set_usize (window, 200, 200); - gtk_widget_show_all (window); - - if (getenv ("TEST")){ - e_table_do_gui_config (NULL, E_TABLE(e_table)); - } -} - -void -e_table_test (void) -{ - load_data (); - - if (1){/*getenv ("DO")){*/ - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <leaf column=\"3\" ascending=\"true\"/> </grouping> </ETableSpecification>"); - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"3\" ascending=\"true\"> <group column=\"4\" ascending=\"false\"> <leaf column=\"2\" ascending=\"true\"/> </group> </group> </grouping> </ETableSpecification>"); - } - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"4\" ascending=\"true\"> <leaf column=\"2\" ascending=\"true\"/> </group> </grouping> </ETableSpecification>"); - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"3\" ascending=\"true\"> <leaf column=\"2\" ascending=\"true\"/> </group> </grouping> </ETableSpecification>"); -} diff --git a/widgets/table/tree-expanded.xpm b/widgets/table/tree-expanded.xpm deleted file mode 100644 index d9bda3694d..0000000000 --- a/widgets/table/tree-expanded.xpm +++ /dev/null @@ -1,23 +0,0 @@ -/* XPM */ -static char * tree_expanded_xpm[] = { -"16 16 4 1", -" c None", -". c #FFFFFF", -"* c #000000", -"+ c #666666", -" ", -" ", -" ", -" ", -" +++++++++ ", -" +.......+ ", -" +.......+ ", -" +.......+ ", -" +.*****.+ ", -" +.......+ ", -" +.......+ ", -" +.......+ ", -" +++++++++ ", -" ", -" ", -" "}; diff --git a/widgets/table/tree-unexpanded.xpm b/widgets/table/tree-unexpanded.xpm deleted file mode 100644 index e1b48448ba..0000000000 --- a/widgets/table/tree-unexpanded.xpm +++ /dev/null @@ -1,23 +0,0 @@ -/* XPM */ -static char * tree_unexpanded_xpm[] = { -"16 16 4 1", -" c None", -". c #FFFFFF", -"* c #000000", -"+ c #666666", -" ", -" ", -" ", -" ", -" +++++++++ ", -" +.......+ ", -" +...*...+ ", -" +...*...+ ", -" +.*****.+ ", -" +...*...+ ", -" +...*...+ ", -" +.......+ ", -" +++++++++ ", -" ", -" ", -" "}; |